723
* to avoid a session trivially messaging itself in a loop.
724
*/
725
>
export async function applySendMessageTool(accessor: ISessionServerToolAccessor, rawArgs: unknown, currentChannel?: ProtocolURI): Promise<string> {
sessionServerTools.ts
726
>
const sessions = await accessor.listSessions();
727
>
const { session, chat, chatId, message } = getSendMessageArgs(rawArgs, sessions);
728
>
if (currentChannel && chat.toString() === URI.parse(currentChannel).toString()) {
729
>
throw new Error(`Invalid ${sendMessageToolName} input: refusing to send a message to the current chat.`);
730
>
}
731
>
await accessor.startPrompt(session, chat, message);
732
>
return formatSendMessageResult(buildOpenSessionLinkUri(session, chatId));
733
>
}
734
735
/** Builds the model-facing `send_message` result. */
736
export function formatSendMessageResult(openLink: string): string {
737
>
return `Message sent (${openLink}). Reply with one short sentence confirming the message was sent; do not print the URL or mention a button.`;
sessionServerTools.ts
738
>
}
739
740
// --- get_session_context -----------------------------------------------------