mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 23:01:56 +00:00
Add agent state methods to CustomToolContext and fix abort signature
CustomToolContext now has: - isIdle() - check if agent is streaming - hasQueuedMessages() - check if user has queued messages - abort() - abort current operation (fire-and-forget) Changed abort() signature from Promise<void> to void in both HookContext and CustomToolContext. The abort is fire-and-forget: it calls session.abort() without awaiting, so the abort signal is set immediately while waitForIdle() runs in the background. Fixes #388
This commit is contained in:
parent
0d9fddec1e
commit
03159d2f4b
10 changed files with 68 additions and 9 deletions
|
|
@ -567,12 +567,18 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|||
}
|
||||
}
|
||||
|
||||
// Wrap custom tools with context getter (agent is assigned below, accessed at execute time)
|
||||
// Wrap custom tools with context getter (agent/session assigned below, accessed at execute time)
|
||||
let agent: Agent;
|
||||
let session: AgentSession;
|
||||
const wrappedCustomTools = wrapCustomTools(customToolsResult.tools, () => ({
|
||||
sessionManager,
|
||||
modelRegistry,
|
||||
model: agent.state.model,
|
||||
isIdle: () => !session.isStreaming,
|
||||
hasQueuedMessages: () => session.queuedMessageCount > 0,
|
||||
abort: () => {
|
||||
session.abort();
|
||||
},
|
||||
}));
|
||||
|
||||
let allToolsArray: Tool[] = [...builtInTools, ...wrappedCustomTools];
|
||||
|
|
@ -646,7 +652,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|||
sessionManager.appendThinkingLevelChange(thinkingLevel);
|
||||
}
|
||||
|
||||
const session = new AgentSession({
|
||||
session = new AgentSession({
|
||||
agent,
|
||||
sessionManager,
|
||||
settingsManager,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue