MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / getCancelledSessionState

Function getCancelledSessionState

sdk/src/run.ts:303–324  ·  view source on GitHub ↗

Calculates the current session state if cancelled. * * This is used when callMainPrompt throws an error. If the agent runtime made * any progress (replaced the shared messageHistory), those messages are * preserved. Otherwise the user's message is added so it isn't lost.

(message: string)

Source from the content-addressed store, hash-verified

301 * preserved. Otherwise the user's message is added so it isn't lost.
302 */
303 function getCancelledSessionState(message: string): SessionState {
304 const runtimeMadeProgress =
305 sessionState.mainAgentState.messageHistory !== initialMessageHistory
306
307 const state = cloneDeep(sessionState)
308
309 // Only add the user's message if the runtime didn't get a chance to add it.
310 if (!runtimeMadeProgress && (prompt || preparedContent)) {
311 state.mainAgentState.messageHistory.push({
312 role: 'user' as const,
313 content: buildUserMessageContent(prompt, params, preparedContent),
314 tags: ['USER_PROMPT'] as string[],
315 })
316 }
317
318 // Add error context message
319 state.mainAgentState.messageHistory.push({
320 role: 'user' as const,
321 content: [{ type: 'text' as const, text: withSystemTags(message) }],
322 })
323 return state
324 }
325 function getCancelledRunState(message?: string): RunState {
326 message = message ?? 'Run cancelled by user.'
327 return {

Callers 2

getCancelledRunStateFunction · 0.85
runOnceFunction · 0.85

Calls 2

buildUserMessageContentFunction · 0.90
withSystemTagsFunction · 0.90

Tested by

no test coverage detected