feat: add canonical typed tool outputs

This commit is contained in:
Tianyi Cui
2026-07-21 03:08:35 +08:00
parent 8500974fd4
commit 66c36e7325
173 changed files with 3298 additions and 954 deletions
+43 -6
View File
@@ -6,7 +6,6 @@
*/
import type { Context } from 'cordis'
import type { ContentBlock } from '@deepseek-ai/dsh-llm'
import { defineTool } from '@deepseek-ai/dsh-tools'
import type { TodoItem } from '@deepseek-ai/dsh-session'
@@ -80,7 +79,41 @@ export function apply(ctx: Context): void {
},
},
},
execute(args, exec): Promise<ContentBlock[]> {
output: {
schema: {
type: 'object',
additionalProperties: false,
properties: {
todos: {
type: 'array',
required: true,
items: {
type: 'object',
additionalProperties: false,
properties: {
content: { type: 'string', required: true },
status: { type: 'string', required: true, enum: [...STATUSES] },
},
},
},
counts: {
type: 'object',
additionalProperties: false,
required: true,
properties: {
pending: { type: 'integer', required: true },
inProgress: { type: 'integer', required: true },
completed: { type: 'integer', required: true },
},
},
},
},
render: (_args, value) => [{
type: 'text',
text: `Updated todo list: ${value.counts.pending} pending, ${value.counts.inProgress} in progress, ${value.counts.completed} completed.`,
}],
},
execute(args, exec) {
const todos = toTodoList(args.todos)
if (!exec.agent) {
// The list is per-agent-session state; a non-agent caller (no owning
@@ -89,10 +122,14 @@ export function apply(ctx: Context): void {
}
exec.agent.session.append('todo/write', { todos })
const count = (status: TodoItem['status']): number => todos.filter(t => t.status === status).length
return Promise.resolve([{
type: 'text',
text: `Updated todo list: ${count('pending')} pending, ${count('in_progress')} in progress, ${count('completed')} completed.`,
}])
return Promise.resolve({
todos: todos.map(todo => ({ content: todo.content, status: todo.status })),
counts: {
pending: count('pending'),
inProgress: count('in_progress'),
completed: count('completed'),
},
})
},
presentCall: args => ({ card: 'generic', title: 'Update todo list', kind: 'other', rawInput: args.todos }),
}))