feat(ai): stream tool execution progress

This commit is contained in:
digua committed 2026-08-18 17:27:48 +08:00
1 parent cf1aee9e5b
commit 2e624f6beb
21 files changed
+227 -15

No files matched your search

+21
View File
@@ -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' } } }])
})
})
+3 -1
View File
@@ -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,