-
Notifications
You must be signed in to change notification settings - Fork 10
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
Refactor loadMessage
function in room resource.
#2047
Changes from 10 commits
f5a17ea
1f6b2d5
271130b
aac6021
63ed09a
4d2bcb3
45b2521
2b66af7
c47aeab
f7e5cdd
e11a312
43de05a
a9af19c
3d48ea2
5919f9a
6c63903
967a7b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,11 +110,7 @@ export default class MessageBuilder { | |
return errorMessage; | ||
} | ||
|
||
get formattedMessageForCommand() { | ||
return `<p data-test-command-message class="command-message">${this.event.content.formatted_body}</p>`; | ||
} | ||
|
||
async buildMessage(): Promise<Message> { | ||
buildMessage(): Message { | ||
let { event } = this; | ||
let message = this.coreMessageArgs; | ||
message.errorMessage = this.errorMessage; | ||
|
@@ -127,16 +123,17 @@ export default class MessageBuilder { | |
event.content.msgtype === APP_BOXEL_COMMAND_MSGTYPE && | ||
event.content.data.toolCall | ||
) { | ||
message.formattedMessage = this.formattedMessageForCommand; | ||
message.command = await this.buildMessageCommand(message); | ||
message.formattedMessage = formattedMessageForCommand( | ||
event.content.formatted_body, | ||
); | ||
message.command = this.buildMessageCommand(message); | ||
message.isStreamingFinished = true; | ||
} | ||
return message; | ||
} | ||
|
||
private async buildMessageCommand(message: Message) { | ||
private buildMessageCommand(message: Message) { | ||
let event = this.event as CommandEvent; | ||
let command = event.content.data.toolCall; | ||
let commandResultEvent = this.builderContext.events.find((e: any) => { | ||
let r = e.content['m.relates_to']; | ||
return ( | ||
|
@@ -147,23 +144,51 @@ export default class MessageBuilder { | |
r.event_id === this.builderContext.effectiveEventId) | ||
); | ||
}) as CommandResultEvent | undefined; | ||
let status = (commandResultEvent?.content?.['m.relates_to']?.key || | ||
'ready') as CommandStatus; | ||
let commandResultCardEventId = | ||
commandResultEvent?.content?.msgtype === | ||
APP_BOXEL_COMMAND_RESULT_WITH_OUTPUT_MSGTYPE | ||
? commandResultEvent.content.data.cardEventId | ||
: undefined; | ||
let messageCommand = new MessageCommand( | ||
|
||
return buildMessageCommand({ | ||
effectiveEventId: this.builderContext.effectiveEventId, | ||
owner: getOwner(this)!, | ||
message, | ||
command.id, | ||
command.name, | ||
command.arguments, | ||
this.builderContext.effectiveEventId, | ||
status, | ||
commandResultCardEventId, | ||
getOwner(this)!, | ||
); | ||
return messageCommand; | ||
commandEvent: event, | ||
commandResultEvent, | ||
}); | ||
} | ||
} | ||
|
||
export function buildMessageCommand({ | ||
effectiveEventId, | ||
commandEvent, | ||
commandResultEvent, | ||
message, | ||
owner, | ||
}: { | ||
effectiveEventId: string; | ||
commandEvent: CommandEvent; | ||
commandResultEvent?: CommandResultEvent; | ||
message: Message; | ||
owner: Owner; | ||
}) { | ||
let status = (commandResultEvent?.content['m.relates_to']?.key || | ||
'ready') as CommandStatus; | ||
let commandResultCardEventId = | ||
commandResultEvent?.content.msgtype === | ||
APP_BOXEL_COMMAND_RESULT_WITH_OUTPUT_MSGTYPE | ||
? commandResultEvent.content.data.cardEventId | ||
: undefined; | ||
let command = commandEvent.content.data.toolCall; | ||
let messageCommand = new MessageCommand( | ||
message, | ||
command.id, | ||
command.name, | ||
command.arguments, | ||
effectiveEventId, | ||
status, | ||
commandResultCardEventId, | ||
owner, | ||
); | ||
return messageCommand; | ||
} | ||
|
||
export function formattedMessageForCommand(formattedBody: string) { | ||
return `<p data-test-command-message class="command-message">${formattedBody}</p>`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is just copied from a different position but does anyone know if we have XSS protection or the like for this? Or is it a safe assumption that malicious messages of this event type can’t be produced? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just added this 43de05a. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!