Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow macro prompt to remain open even if the events were more than 100 events ago #2045

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 60 additions & 15 deletions src/components/dialogs/TheMacroPrompt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,72 @@ export default class TheMacroPrompt extends Mixins(BaseMixin) {
mdiCloseThick = mdiCloseThick

private internalCloseCommand: number | null = null
private checkpointEvent: ServerStateEvent | null = null
private currentPrompt: ServerStateEventPrompt[] = []
// regex that extracts the type and message, omitting the wrapping double quotes of the message (if any)
private promptMessageExp =
/^\/\/ action:prompt_(?<type>[^\s]+) *(?:(?<quote>['"])(?<msg1>.*)\k<quote>|(?<msg2>.*))\s*$/

get events() {
return this.$store.state.server.events.slice(-100)
return this.$store.state.server.events
}

get macroPromptEvents() {
return this.events
.filter((event: ServerStateEvent) => event.type === 'action')
.filter((event: ServerStateEvent) => event.message.startsWith('// action:prompt_'))
.map((event: ServerStateEvent) => {
const type = (event.message ?? '').replace('// action:prompt_', '').split(' ')[0].trim()
const message = (event.message ?? '').replace(`// action:prompt_${type}`, '').replace(/"/g, '').trim()

const promptContent: ServerStateEventPrompt = {
date: event.date,
type,
message,
}

return promptContent
const events: ServerStateEvent[] = this.events
const promptEvents: ServerStateEventPrompt[] = []
// process events from most recent (end of array) to oldest (beginning of array) event until we reach
// the events we have already processed
for (let i = events.length - 1; i >= 0; i--) {
const event = events[i]
// if we've reached the checkpoint event (i.e. the point where we know there are no earlier prompts to process)
if (event === this.checkpointEvent) {
// break the loop
break
}

// not a prompt action, skip it
if (event.type !== 'action' || !event.message?.startsWith('// action:prompt_')) {
continue
}

const type = (event.message ?? '').replace('// action:prompt_', '').split(' ')[0].trim()

// stop processing and clear events once we find a end action
if (type === 'end') {
this.currentPrompt = []
break
}

console.log(event.message)

// extract our message from the action event
// supports no quote, double quote, and single quote wrapped messages
const { groups: { msg1, msg2, msg3 } = {} } = event.message.match(this.promptMessageExp) ?? {}
const message = (msg1 ?? msg2 ?? msg3 ?? '').trim()

// prepend the event to prompt events found in this chunk
promptEvents.unshift({
date: event.date,
type,
message,
})

// stop processing events once we find a begin action
if (type === 'begin') {
this.currentPrompt = []
break
}
}

// save our checkpoint event...we'll never have to look at messages prior to the checkpoint again
this.checkpointEvent = events[events.length - 1]

// if we found new prompt events in this chunk, let's append them
if (promptEvents.length > 0) {
this.currentPrompt = [...this.currentPrompt, ...promptEvents]
}

return this.currentPrompt
}

get lastPromptBeginPos() {
Expand Down
Loading