@@ -51,6 +51,76 @@ import { appendUntrustedContext } from "./untrusted-context.js";
5151type AgentDefaults = NonNullable < OpenClawConfig [ "agents" ] > [ "defaults" ] ;
5252type ExecOverrides = Pick < ExecToolDefaults , "host" | "security" | "ask" | "node" > ;
5353
54+ function buildResetSessionNoticeText ( params : {
55+ provider : string ;
56+ model : string ;
57+ defaultProvider : string ;
58+ defaultModel : string ;
59+ } ) : string {
60+ const modelLabel = `${ params . provider } /${ params . model } ` ;
61+ const defaultLabel = `${ params . defaultProvider } /${ params . defaultModel } ` ;
62+ return modelLabel === defaultLabel
63+ ? `✅ New session started · model: ${ modelLabel } `
64+ : `✅ New session started · model: ${ modelLabel } (default: ${ defaultLabel } )` ;
65+ }
66+
67+ function resolveResetSessionNoticeRoute ( params : {
68+ ctx : MsgContext ;
69+ command : ReturnType < typeof buildCommandContext > ;
70+ } ) : {
71+ channel : Parameters < typeof routeReply > [ 0 ] [ "channel" ] ;
72+ to : string ;
73+ } | null {
74+ const commandChannel = params . command . channel ?. trim ( ) . toLowerCase ( ) ;
75+ const fallbackChannel =
76+ commandChannel && commandChannel !== "webchat"
77+ ? ( commandChannel as Parameters < typeof routeReply > [ 0 ] [ "channel" ] )
78+ : undefined ;
79+ const channel = params . ctx . OriginatingChannel ?? fallbackChannel ;
80+ const to = params . ctx . OriginatingTo ?? params . command . from ?? params . command . to ;
81+ if ( ! channel || channel === "webchat" || ! to ) {
82+ return null ;
83+ }
84+ return { channel, to } ;
85+ }
86+
87+ async function sendResetSessionNotice ( params : {
88+ ctx : MsgContext ;
89+ command : ReturnType < typeof buildCommandContext > ;
90+ sessionKey : string ;
91+ cfg : OpenClawConfig ;
92+ accountId : string | undefined ;
93+ threadId : string | number | undefined ;
94+ provider : string ;
95+ model : string ;
96+ defaultProvider : string ;
97+ defaultModel : string ;
98+ } ) : Promise < void > {
99+ const route = resolveResetSessionNoticeRoute ( {
100+ ctx : params . ctx ,
101+ command : params . command ,
102+ } ) ;
103+ if ( ! route ) {
104+ return ;
105+ }
106+ await routeReply ( {
107+ payload : {
108+ text : buildResetSessionNoticeText ( {
109+ provider : params . provider ,
110+ model : params . model ,
111+ defaultProvider : params . defaultProvider ,
112+ defaultModel : params . defaultModel ,
113+ } ) ,
114+ } ,
115+ channel : route . channel ,
116+ to : route . to ,
117+ sessionKey : params . sessionKey ,
118+ accountId : params . accountId ,
119+ threadId : params . threadId ,
120+ cfg : params . cfg ,
121+ } ) ;
122+ }
123+
54124type RunPreparedReplyParams = {
55125 ctx : MsgContext ;
56126 sessionCtx : TemplateContext ;
@@ -318,26 +388,18 @@ export async function runPreparedReply(
318388 }
319389 }
320390 if ( resetTriggered && command . isAuthorizedSender ) {
321- // oxlint-disable-next-line typescript/no-explicit-any
322- const channel = ctx . OriginatingChannel || ( command . channel as any ) ;
323- const to = ctx . OriginatingTo || command . from || command . to ;
324- if ( channel && to ) {
325- const modelLabel = `${ provider } /${ model } ` ;
326- const defaultLabel = `${ defaultProvider } /${ defaultModel } ` ;
327- const text =
328- modelLabel === defaultLabel
329- ? `✅ New session started · model: ${ modelLabel } `
330- : `✅ New session started · model: ${ modelLabel } (default: ${ defaultLabel } )` ;
331- await routeReply ( {
332- payload : { text } ,
333- channel,
334- to,
335- sessionKey,
336- accountId : ctx . AccountId ,
337- threadId : ctx . MessageThreadId ,
338- cfg,
339- } ) ;
340- }
391+ await sendResetSessionNotice ( {
392+ ctx,
393+ command,
394+ sessionKey,
395+ cfg,
396+ accountId : ctx . AccountId ,
397+ threadId : ctx . MessageThreadId ,
398+ provider,
399+ model,
400+ defaultProvider,
401+ defaultModel,
402+ } ) ;
341403 }
342404 const sessionIdFinal = sessionId ?? crypto . randomUUID ( ) ;
343405 const sessionFile = resolveSessionFilePath (
0 commit comments