mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-25 17:54:34 +08:00
feat(ai): stream tool execution progress
This commit is contained in:
1 parent
cf1aee9e5b
commit
2e624f6beb
21 files changed
+227
-15
No files matched your search
@@ -123,4 +123,25 @@ describe('adaptToolsForAgent', () => {
|
||||
assert.ok(text.includes('hello world'))
|
||||
assert.ok(text.includes('hi there'))
|
||||
})
|
||||
|
||||
it('bridges shared tool progress to Pi tool updates', async () => {
|
||||
const tool: ToolDefinition = {
|
||||
name: 'slow_tool',
|
||||
description: 'Slow tool',
|
||||
inputSchema: { type: 'object', properties: {} },
|
||||
async handler(_params, context) {
|
||||
context.reportProgress?.({ phase: 'searching' })
|
||||
return { content: 'Done' }
|
||||
},
|
||||
}
|
||||
const [agentTool] = adaptToolsForAgent([tool], () => ({
|
||||
db: {} as DatabaseAdapter,
|
||||
sessionId: 'session-1',
|
||||
}))
|
||||
const updates: unknown[] = []
|
||||
|
||||
await agentTool.execute('call-progress', {}, undefined, (update) => updates.push(update))
|
||||
|
||||
assert.deepEqual(updates, [{ content: [], details: { progress: { phase: 'searching' } } }])
|
||||
})
|
||||
})
|
||||
@@ -74,13 +74,15 @@ export function adaptToolsForAgent(
|
||||
description: tool.description,
|
||||
parameters: toAgentToolParameters(tool.inputSchema) as any,
|
||||
executionMode: tool.executionMode,
|
||||
async execute(_toolCallId: string, params: unknown) {
|
||||
async execute(_toolCallId: string, params: unknown, signal, onUpdate) {
|
||||
const ctx = getContext()
|
||||
const execCtx: ToolExecutionContext = {
|
||||
db: ctx.db,
|
||||
dataProvider: new CoreDataProvider(ctx.db),
|
||||
sessionId: ctx.sessionId,
|
||||
locale: ctx.locale,
|
||||
abortSignal: signal,
|
||||
reportProgress: (progress) => onUpdate?.({ content: [], details: { progress } }),
|
||||
semanticIndexService: ctx.semanticIndexService,
|
||||
preprocessConfig: ctx.preprocessConfig,
|
||||
ownerPlatformId: ctx.ownerPlatformId,
|
||||
|
||||
Reference in new issue
Block a user