@lleverage-ai/agent-sdk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2321 -0
- package/dist/agent.d.ts +52 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +2122 -0
- package/dist/agent.js.map +1 -0
- package/dist/backend.d.ts +378 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +71 -0
- package/dist/backend.js.map +1 -0
- package/dist/backends/composite.d.ts +258 -0
- package/dist/backends/composite.d.ts.map +1 -0
- package/dist/backends/composite.js +437 -0
- package/dist/backends/composite.js.map +1 -0
- package/dist/backends/filesystem.d.ts +268 -0
- package/dist/backends/filesystem.d.ts.map +1 -0
- package/dist/backends/filesystem.js +623 -0
- package/dist/backends/filesystem.js.map +1 -0
- package/dist/backends/index.d.ts +14 -0
- package/dist/backends/index.d.ts.map +1 -0
- package/dist/backends/index.js +14 -0
- package/dist/backends/index.js.map +1 -0
- package/dist/backends/persistent.d.ts +312 -0
- package/dist/backends/persistent.d.ts.map +1 -0
- package/dist/backends/persistent.js +519 -0
- package/dist/backends/persistent.js.map +1 -0
- package/dist/backends/sandbox.d.ts +315 -0
- package/dist/backends/sandbox.d.ts.map +1 -0
- package/dist/backends/sandbox.js +490 -0
- package/dist/backends/sandbox.js.map +1 -0
- package/dist/backends/state.d.ts +225 -0
- package/dist/backends/state.d.ts.map +1 -0
- package/dist/backends/state.js +396 -0
- package/dist/backends/state.js.map +1 -0
- package/dist/checkpointer/file-saver.d.ts +182 -0
- package/dist/checkpointer/file-saver.d.ts.map +1 -0
- package/dist/checkpointer/file-saver.js +298 -0
- package/dist/checkpointer/file-saver.js.map +1 -0
- package/dist/checkpointer/index.d.ts +40 -0
- package/dist/checkpointer/index.d.ts.map +1 -0
- package/dist/checkpointer/index.js +40 -0
- package/dist/checkpointer/index.js.map +1 -0
- package/dist/checkpointer/kv-saver.d.ts +142 -0
- package/dist/checkpointer/kv-saver.d.ts.map +1 -0
- package/dist/checkpointer/kv-saver.js +176 -0
- package/dist/checkpointer/kv-saver.js.map +1 -0
- package/dist/checkpointer/memory-saver.d.ts +158 -0
- package/dist/checkpointer/memory-saver.d.ts.map +1 -0
- package/dist/checkpointer/memory-saver.js +222 -0
- package/dist/checkpointer/memory-saver.js.map +1 -0
- package/dist/checkpointer/types.d.ts +353 -0
- package/dist/checkpointer/types.d.ts.map +1 -0
- package/dist/checkpointer/types.js +159 -0
- package/dist/checkpointer/types.js.map +1 -0
- package/dist/context-manager.d.ts +627 -0
- package/dist/context-manager.d.ts.map +1 -0
- package/dist/context-manager.js +1039 -0
- package/dist/context-manager.js.map +1 -0
- package/dist/context.d.ts +57 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +76 -0
- package/dist/context.js.map +1 -0
- package/dist/errors/index.d.ts +611 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +1023 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/generation-helpers.d.ts +126 -0
- package/dist/generation-helpers.d.ts.map +1 -0
- package/dist/generation-helpers.js +181 -0
- package/dist/generation-helpers.js.map +1 -0
- package/dist/hooks/audit.d.ts +210 -0
- package/dist/hooks/audit.d.ts.map +1 -0
- package/dist/hooks/audit.js +305 -0
- package/dist/hooks/audit.js.map +1 -0
- package/dist/hooks/cache.d.ts +180 -0
- package/dist/hooks/cache.d.ts.map +1 -0
- package/dist/hooks/cache.js +273 -0
- package/dist/hooks/cache.js.map +1 -0
- package/dist/hooks/guardrails.d.ts +145 -0
- package/dist/hooks/guardrails.d.ts.map +1 -0
- package/dist/hooks/guardrails.js +326 -0
- package/dist/hooks/guardrails.js.map +1 -0
- package/dist/hooks/index.d.ts +18 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +32 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/logging.d.ts +193 -0
- package/dist/hooks/logging.d.ts.map +1 -0
- package/dist/hooks/logging.js +345 -0
- package/dist/hooks/logging.js.map +1 -0
- package/dist/hooks/parallel-guardrails.d.ts +268 -0
- package/dist/hooks/parallel-guardrails.d.ts.map +1 -0
- package/dist/hooks/parallel-guardrails.js +416 -0
- package/dist/hooks/parallel-guardrails.js.map +1 -0
- package/dist/hooks/rate-limit.d.ts +305 -0
- package/dist/hooks/rate-limit.d.ts.map +1 -0
- package/dist/hooks/rate-limit.js +372 -0
- package/dist/hooks/rate-limit.js.map +1 -0
- package/dist/hooks/retry.d.ts +144 -0
- package/dist/hooks/retry.d.ts.map +1 -0
- package/dist/hooks/retry.js +210 -0
- package/dist/hooks/retry.js.map +1 -0
- package/dist/hooks/secrets.d.ts +174 -0
- package/dist/hooks/secrets.d.ts.map +1 -0
- package/dist/hooks/secrets.js +306 -0
- package/dist/hooks/secrets.js.map +1 -0
- package/dist/hooks.d.ts +229 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +352 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +182 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/env.d.ts +25 -0
- package/dist/mcp/env.d.ts.map +1 -0
- package/dist/mcp/env.js +18 -0
- package/dist/mcp/env.js.map +1 -0
- package/dist/mcp/index.d.ts +16 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +17 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/manager.d.ts +184 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +446 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/types.d.ts +58 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +7 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/mcp/validation.d.ts +119 -0
- package/dist/mcp/validation.d.ts.map +1 -0
- package/dist/mcp/validation.js +407 -0
- package/dist/mcp/validation.js.map +1 -0
- package/dist/mcp/virtual-server.d.ts +78 -0
- package/dist/mcp/virtual-server.d.ts.map +1 -0
- package/dist/mcp/virtual-server.js +137 -0
- package/dist/mcp/virtual-server.js.map +1 -0
- package/dist/memory/filesystem-store.d.ts +217 -0
- package/dist/memory/filesystem-store.d.ts.map +1 -0
- package/dist/memory/filesystem-store.js +343 -0
- package/dist/memory/filesystem-store.js.map +1 -0
- package/dist/memory/index.d.ts +46 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +46 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/loader.d.ts +396 -0
- package/dist/memory/loader.d.ts.map +1 -0
- package/dist/memory/loader.js +419 -0
- package/dist/memory/loader.js.map +1 -0
- package/dist/memory/permissions.d.ts +282 -0
- package/dist/memory/permissions.d.ts.map +1 -0
- package/dist/memory/permissions.js +297 -0
- package/dist/memory/permissions.js.map +1 -0
- package/dist/memory/rules.d.ts +249 -0
- package/dist/memory/rules.d.ts.map +1 -0
- package/dist/memory/rules.js +362 -0
- package/dist/memory/rules.js.map +1 -0
- package/dist/memory/store.d.ts +286 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +263 -0
- package/dist/memory/store.js.map +1 -0
- package/dist/middleware/apply.d.ts +73 -0
- package/dist/middleware/apply.d.ts.map +1 -0
- package/dist/middleware/apply.js +219 -0
- package/dist/middleware/apply.js.map +1 -0
- package/dist/middleware/context.d.ts +33 -0
- package/dist/middleware/context.d.ts.map +1 -0
- package/dist/middleware/context.js +176 -0
- package/dist/middleware/context.js.map +1 -0
- package/dist/middleware/index.d.ts +31 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +32 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/logging.d.ts +137 -0
- package/dist/middleware/logging.d.ts.map +1 -0
- package/dist/middleware/logging.js +374 -0
- package/dist/middleware/logging.js.map +1 -0
- package/dist/middleware/types.d.ts +183 -0
- package/dist/middleware/types.d.ts.map +1 -0
- package/dist/middleware/types.js +11 -0
- package/dist/middleware/types.js.map +1 -0
- package/dist/observability/events.d.ts +183 -0
- package/dist/observability/events.d.ts.map +1 -0
- package/dist/observability/events.js +305 -0
- package/dist/observability/events.js.map +1 -0
- package/dist/observability/index.d.ts +55 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +87 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/logger.d.ts +318 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +436 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/metrics.d.ts +341 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +490 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/observability/preset.d.ts +161 -0
- package/dist/observability/preset.d.ts.map +1 -0
- package/dist/observability/preset.js +133 -0
- package/dist/observability/preset.js.map +1 -0
- package/dist/observability/streaming.d.ts +113 -0
- package/dist/observability/streaming.d.ts.map +1 -0
- package/dist/observability/streaming.js +114 -0
- package/dist/observability/streaming.js.map +1 -0
- package/dist/observability/tracing.d.ts +378 -0
- package/dist/observability/tracing.d.ts.map +1 -0
- package/dist/observability/tracing.js +539 -0
- package/dist/observability/tracing.js.map +1 -0
- package/dist/plugins.d.ts +55 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/plugins.js +63 -0
- package/dist/plugins.js.map +1 -0
- package/dist/presets/index.d.ts +7 -0
- package/dist/presets/index.d.ts.map +1 -0
- package/dist/presets/index.js +7 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/presets/production.d.ts +262 -0
- package/dist/presets/production.d.ts.map +1 -0
- package/dist/presets/production.js +295 -0
- package/dist/presets/production.js.map +1 -0
- package/dist/security/index.d.ts +179 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +323 -0
- package/dist/security/index.js.map +1 -0
- package/dist/subagents/advanced.d.ts +413 -0
- package/dist/subagents/advanced.d.ts.map +1 -0
- package/dist/subagents/advanced.js +396 -0
- package/dist/subagents/advanced.js.map +1 -0
- package/dist/subagents/index.d.ts +14 -0
- package/dist/subagents/index.d.ts.map +1 -0
- package/dist/subagents/index.js +15 -0
- package/dist/subagents/index.js.map +1 -0
- package/dist/subagents.d.ts +73 -0
- package/dist/subagents.d.ts.map +1 -0
- package/dist/subagents.js +213 -0
- package/dist/subagents.js.map +1 -0
- package/dist/task-store/file-store.d.ts +76 -0
- package/dist/task-store/file-store.d.ts.map +1 -0
- package/dist/task-store/file-store.js +190 -0
- package/dist/task-store/file-store.js.map +1 -0
- package/dist/task-store/index.d.ts +11 -0
- package/dist/task-store/index.d.ts.map +1 -0
- package/dist/task-store/index.js +10 -0
- package/dist/task-store/index.js.map +1 -0
- package/dist/task-store/kv-store.d.ts +140 -0
- package/dist/task-store/kv-store.d.ts.map +1 -0
- package/dist/task-store/kv-store.js +169 -0
- package/dist/task-store/kv-store.js.map +1 -0
- package/dist/task-store/memory-store.d.ts +66 -0
- package/dist/task-store/memory-store.d.ts.map +1 -0
- package/dist/task-store/memory-store.js +125 -0
- package/dist/task-store/memory-store.js.map +1 -0
- package/dist/task-store/types.d.ts +235 -0
- package/dist/task-store/types.d.ts.map +1 -0
- package/dist/task-store/types.js +110 -0
- package/dist/task-store/types.js.map +1 -0
- package/dist/testing/assertions.d.ts +401 -0
- package/dist/testing/assertions.d.ts.map +1 -0
- package/dist/testing/assertions.js +630 -0
- package/dist/testing/assertions.js.map +1 -0
- package/dist/testing/index.d.ts +343 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +360 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mock-agent.d.ts +214 -0
- package/dist/testing/mock-agent.d.ts.map +1 -0
- package/dist/testing/mock-agent.js +448 -0
- package/dist/testing/mock-agent.js.map +1 -0
- package/dist/testing/recorder.d.ts +288 -0
- package/dist/testing/recorder.d.ts.map +1 -0
- package/dist/testing/recorder.js +499 -0
- package/dist/testing/recorder.js.map +1 -0
- package/dist/tools/execute.d.ts +104 -0
- package/dist/tools/execute.d.ts.map +1 -0
- package/dist/tools/execute.js +191 -0
- package/dist/tools/execute.js.map +1 -0
- package/dist/tools/factory.d.ts +260 -0
- package/dist/tools/factory.d.ts.map +1 -0
- package/dist/tools/factory.js +241 -0
- package/dist/tools/factory.js.map +1 -0
- package/dist/tools/filesystem.d.ts +215 -0
- package/dist/tools/filesystem.d.ts.map +1 -0
- package/dist/tools/filesystem.js +311 -0
- package/dist/tools/filesystem.js.map +1 -0
- package/dist/tools/index.d.ts +33 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +33 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/search.d.ts +59 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +94 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/skills.d.ts +354 -0
- package/dist/tools/skills.d.ts.map +1 -0
- package/dist/tools/skills.js +413 -0
- package/dist/tools/skills.js.map +1 -0
- package/dist/tools/task.d.ts +272 -0
- package/dist/tools/task.d.ts.map +1 -0
- package/dist/tools/task.js +521 -0
- package/dist/tools/task.js.map +1 -0
- package/dist/tools/todos.d.ts +131 -0
- package/dist/tools/todos.d.ts.map +1 -0
- package/dist/tools/todos.js +120 -0
- package/dist/tools/todos.js.map +1 -0
- package/dist/tools/tool-registry.d.ts +424 -0
- package/dist/tools/tool-registry.d.ts.map +1 -0
- package/dist/tools/tool-registry.js +607 -0
- package/dist/tools/tool-registry.js.map +1 -0
- package/dist/tools/user-interaction.d.ts +116 -0
- package/dist/tools/user-interaction.d.ts.map +1 -0
- package/dist/tools/user-interaction.js +147 -0
- package/dist/tools/user-interaction.js.map +1 -0
- package/dist/tools/utils.d.ts +124 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +189 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/tools.d.ts +74 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +73 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +2421 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +55 -0
- package/dist/types.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task tool for delegating work to specialized subagents.
|
|
3
|
+
*
|
|
4
|
+
* Provides a single `task` tool for spawning subagents, similar to Claude Code's
|
|
5
|
+
* Task tool. Supports both foreground and background execution, as well as
|
|
6
|
+
* streaming subagents that can write to the parent's data stream.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
import { tool } from "ai";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { createSubagent } from "../subagents.js";
|
|
13
|
+
import { createBackgroundTask, updateBackgroundTask } from "../task-store/index.js";
|
|
14
|
+
// =============================================================================
|
|
15
|
+
// Internal Task Tracking
|
|
16
|
+
// =============================================================================
|
|
17
|
+
/** Task ID counter for uniqueness */
|
|
18
|
+
let taskIdCounter = 0;
|
|
19
|
+
/** Internal storage for background tasks (fallback when no task store) */
|
|
20
|
+
const backgroundTasks = new Map();
|
|
21
|
+
/** Task store instance (if configured) */
|
|
22
|
+
let globalTaskStore;
|
|
23
|
+
/**
|
|
24
|
+
* Set the global task store for background task persistence.
|
|
25
|
+
*
|
|
26
|
+
* @param store - The task store to use
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
function setGlobalTaskStore(store) {
|
|
30
|
+
globalTaskStore = store;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get a background task by ID.
|
|
34
|
+
*
|
|
35
|
+
* @param taskId - The task ID
|
|
36
|
+
* @returns The tracked task or undefined
|
|
37
|
+
*
|
|
38
|
+
* @category Subagents
|
|
39
|
+
*/
|
|
40
|
+
export async function getBackgroundTask(taskId) {
|
|
41
|
+
if (globalTaskStore) {
|
|
42
|
+
return globalTaskStore.load(taskId);
|
|
43
|
+
}
|
|
44
|
+
return backgroundTasks.get(taskId);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* List all background tasks.
|
|
48
|
+
*
|
|
49
|
+
* @param filter - Optional filter by status
|
|
50
|
+
* @returns Array of all tracked tasks
|
|
51
|
+
*
|
|
52
|
+
* @category Subagents
|
|
53
|
+
*/
|
|
54
|
+
export async function listBackgroundTasks(filter) {
|
|
55
|
+
if (globalTaskStore) {
|
|
56
|
+
return globalTaskStore.listTasks(filter);
|
|
57
|
+
}
|
|
58
|
+
// In-memory fallback
|
|
59
|
+
const tasks = Array.from(backgroundTasks.values());
|
|
60
|
+
if (!filter?.status) {
|
|
61
|
+
return tasks;
|
|
62
|
+
}
|
|
63
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
64
|
+
return tasks.filter((t) => statuses.includes(t.status));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Clear completed/failed background tasks.
|
|
68
|
+
*
|
|
69
|
+
* Removes tasks older than the expiration time (if using task store)
|
|
70
|
+
* or all completed/failed tasks (if using in-memory storage).
|
|
71
|
+
*
|
|
72
|
+
* @returns Number of tasks cleared
|
|
73
|
+
*
|
|
74
|
+
* @category Subagents
|
|
75
|
+
*/
|
|
76
|
+
export async function clearCompletedTasks() {
|
|
77
|
+
if (globalTaskStore) {
|
|
78
|
+
return globalTaskStore.cleanup();
|
|
79
|
+
}
|
|
80
|
+
// In-memory fallback
|
|
81
|
+
let cleared = 0;
|
|
82
|
+
for (const [id, task] of backgroundTasks) {
|
|
83
|
+
if (task.status === "completed" || task.status === "failed") {
|
|
84
|
+
backgroundTasks.delete(id);
|
|
85
|
+
cleared++;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return cleared;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Recover running tasks on agent restart.
|
|
92
|
+
*
|
|
93
|
+
* When using a task store, this function loads all "running" tasks
|
|
94
|
+
* and marks them as "failed" since they were interrupted by the restart.
|
|
95
|
+
*
|
|
96
|
+
* Call this function when initializing your agent to handle crashed tasks.
|
|
97
|
+
*
|
|
98
|
+
* @param store - Optional task store to use. If not provided, uses the global task store.
|
|
99
|
+
* @returns Number of tasks recovered
|
|
100
|
+
*
|
|
101
|
+
* @category Subagents
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* // On agent startup
|
|
105
|
+
* const recovered = await recoverRunningTasks();
|
|
106
|
+
* console.log(`Recovered ${recovered} interrupted tasks`);
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export async function recoverRunningTasks(store) {
|
|
110
|
+
const taskStore = store ?? globalTaskStore;
|
|
111
|
+
if (!taskStore) {
|
|
112
|
+
return 0; // No recovery needed for in-memory tasks
|
|
113
|
+
}
|
|
114
|
+
const runningTasks = await taskStore.listTasks({ status: "running" });
|
|
115
|
+
let recovered = 0;
|
|
116
|
+
for (const task of runningTasks) {
|
|
117
|
+
const updated = updateBackgroundTask(task, {
|
|
118
|
+
status: "failed",
|
|
119
|
+
error: "Task interrupted by agent restart",
|
|
120
|
+
completedAt: new Date().toISOString(),
|
|
121
|
+
});
|
|
122
|
+
await taskStore.save(updated);
|
|
123
|
+
recovered++;
|
|
124
|
+
}
|
|
125
|
+
return recovered;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Recover failed tasks for retry.
|
|
129
|
+
*
|
|
130
|
+
* Loads all "failed" tasks from the store and returns them for inspection
|
|
131
|
+
* or automatic retry. Applications can decide which tasks to retry based
|
|
132
|
+
* on error type, retry count, or other criteria.
|
|
133
|
+
*
|
|
134
|
+
* To retry a task, update its status back to "pending" and process it
|
|
135
|
+
* through your task execution logic.
|
|
136
|
+
*
|
|
137
|
+
* @param store - The task store to query
|
|
138
|
+
* @param options - Optional filter options
|
|
139
|
+
* @returns Array of failed tasks
|
|
140
|
+
*
|
|
141
|
+
* @category Subagents
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* // Load failed tasks and retry those with transient errors
|
|
145
|
+
* const failedTasks = await recoverFailedTasks(taskStore);
|
|
146
|
+
*
|
|
147
|
+
* for (const task of failedTasks) {
|
|
148
|
+
* // Check if error is retryable
|
|
149
|
+
* if (task.error?.includes("timeout") || task.error?.includes("network")) {
|
|
150
|
+
* // Mark for retry
|
|
151
|
+
* const retryTask = updateBackgroundTask(task, {
|
|
152
|
+
* status: "pending",
|
|
153
|
+
* error: undefined,
|
|
154
|
+
* });
|
|
155
|
+
* await taskStore.save(retryTask);
|
|
156
|
+
* }
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export async function recoverFailedTasks(store, options) {
|
|
161
|
+
const failedTasks = await store.listTasks({ status: "failed" });
|
|
162
|
+
let filtered = failedTasks;
|
|
163
|
+
// Apply error pattern filter
|
|
164
|
+
if (options?.errorPattern) {
|
|
165
|
+
filtered = filtered.filter((task) => task.error && options.errorPattern.test(task.error));
|
|
166
|
+
}
|
|
167
|
+
// Apply date range filters
|
|
168
|
+
if (options?.minCreatedAt) {
|
|
169
|
+
const minTime = options.minCreatedAt.getTime();
|
|
170
|
+
filtered = filtered.filter((task) => new Date(task.createdAt).getTime() >= minTime);
|
|
171
|
+
}
|
|
172
|
+
if (options?.maxCreatedAt) {
|
|
173
|
+
const maxTime = options.maxCreatedAt.getTime();
|
|
174
|
+
filtered = filtered.filter((task) => new Date(task.createdAt).getTime() <= maxTime);
|
|
175
|
+
}
|
|
176
|
+
return filtered;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Clean up stale tasks from the task store.
|
|
180
|
+
*
|
|
181
|
+
* Removes tasks that have been in a terminal state (completed or failed)
|
|
182
|
+
* for longer than the specified age. This prevents unbounded storage growth
|
|
183
|
+
* and maintains system health.
|
|
184
|
+
*
|
|
185
|
+
* @param store - The task store to clean
|
|
186
|
+
* @param maxAge - Maximum age in milliseconds for terminal tasks
|
|
187
|
+
* @returns Number of tasks cleaned up
|
|
188
|
+
*
|
|
189
|
+
* @category Subagents
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* // Clean up tasks older than 7 days
|
|
193
|
+
* const sevenDays = 7 * 24 * 60 * 60 * 1000;
|
|
194
|
+
* const cleaned = await cleanupStaleTasks(taskStore, sevenDays);
|
|
195
|
+
* console.log(`Cleaned up ${cleaned} stale tasks`);
|
|
196
|
+
*
|
|
197
|
+
* // Or use a shorter retention for testing
|
|
198
|
+
* const oneHour = 60 * 60 * 1000;
|
|
199
|
+
* await cleanupStaleTasks(taskStore, oneHour);
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
export async function cleanupStaleTasks(store, maxAge) {
|
|
203
|
+
const terminalTasks = await store.listTasks({
|
|
204
|
+
status: ["completed", "failed"],
|
|
205
|
+
});
|
|
206
|
+
let cleaned = 0;
|
|
207
|
+
const now = Date.now();
|
|
208
|
+
for (const task of terminalTasks) {
|
|
209
|
+
// Use completedAt if available, otherwise use updatedAt
|
|
210
|
+
const timestampStr = task.completedAt ?? task.updatedAt;
|
|
211
|
+
const taskTime = new Date(timestampStr).getTime();
|
|
212
|
+
const age = now - taskTime;
|
|
213
|
+
if (age > maxAge) {
|
|
214
|
+
await store.delete(task.id);
|
|
215
|
+
cleaned++;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return cleaned;
|
|
219
|
+
}
|
|
220
|
+
// =============================================================================
|
|
221
|
+
// Helper Functions
|
|
222
|
+
// =============================================================================
|
|
223
|
+
/**
|
|
224
|
+
* Default general-purpose subagent definition.
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
227
|
+
function createGeneralPurposeSubagent(parentAgent, model, systemPrompt) {
|
|
228
|
+
return {
|
|
229
|
+
type: "general-purpose",
|
|
230
|
+
description: "General-purpose agent for diverse tasks. Use when no specialized agent fits.",
|
|
231
|
+
model: model, // Will use context.model if not specified
|
|
232
|
+
create: (ctx) => createSubagent(parentAgent, {
|
|
233
|
+
name: "general-purpose",
|
|
234
|
+
description: "General-purpose subagent",
|
|
235
|
+
model: ctx.model,
|
|
236
|
+
allowedTools: ctx.allowedTools,
|
|
237
|
+
systemPrompt: systemPrompt ??
|
|
238
|
+
`You are a general-purpose assistant. Complete the requested task thoroughly and return a clear summary of what was accomplished.`,
|
|
239
|
+
}),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
// =============================================================================
|
|
243
|
+
// Task Tool
|
|
244
|
+
// =============================================================================
|
|
245
|
+
/**
|
|
246
|
+
* Creates the task tool for delegating work to specialized subagents.
|
|
247
|
+
*
|
|
248
|
+
* This tool delegates tasks to subagents with isolated context. It supports
|
|
249
|
+
* both foreground (blocking) and background execution.
|
|
250
|
+
*
|
|
251
|
+
* @param options - Configuration options
|
|
252
|
+
* @returns An AI SDK tool for task delegation
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* import { createTaskTool } from "@lleverage-ai/agent-sdk";
|
|
257
|
+
*
|
|
258
|
+
* const task = createTaskTool({
|
|
259
|
+
* subagents: [
|
|
260
|
+
* {
|
|
261
|
+
* type: "researcher",
|
|
262
|
+
* description: "Searches for information",
|
|
263
|
+
* create: () => createSubagent(parentAgent, { ... }),
|
|
264
|
+
* },
|
|
265
|
+
* {
|
|
266
|
+
* type: "coder",
|
|
267
|
+
* description: "Writes and modifies code",
|
|
268
|
+
* create: () => createSubagent(parentAgent, { ... }),
|
|
269
|
+
* },
|
|
270
|
+
* ],
|
|
271
|
+
* defaultModel: anthropic("claude-sonnet-4-20250514"),
|
|
272
|
+
* parentAgent,
|
|
273
|
+
* includeGeneralPurpose: true,
|
|
274
|
+
* });
|
|
275
|
+
*
|
|
276
|
+
* const agent = createAgent({
|
|
277
|
+
* model,
|
|
278
|
+
* tools: { task },
|
|
279
|
+
* });
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* @category Subagents
|
|
283
|
+
*/
|
|
284
|
+
export function createTaskTool(options) {
|
|
285
|
+
const { subagents: userSubagents, defaultModel, parentAgent, defaultMaxTurns = 10, includeGeneralPurpose = false, generalPurposeModel, generalPurposePrompt, streamingContext, taskStore, parentSpanContext, } = options;
|
|
286
|
+
// Set the global task store for persistence
|
|
287
|
+
setGlobalTaskStore(taskStore);
|
|
288
|
+
// Build subagent list (optionally include general-purpose)
|
|
289
|
+
const subagents = [...userSubagents];
|
|
290
|
+
if (includeGeneralPurpose) {
|
|
291
|
+
subagents.push(createGeneralPurposeSubagent(parentAgent, generalPurposeModel, generalPurposePrompt));
|
|
292
|
+
}
|
|
293
|
+
// Build subagent type enum and descriptions
|
|
294
|
+
const subagentTypes = subagents.map((s) => s.type);
|
|
295
|
+
const subagentDescriptions = subagents.map((s) => `- ${s.type}: ${s.description}`).join("\n");
|
|
296
|
+
const toolDescription = options.description ??
|
|
297
|
+
`Delegate a task to a specialized subagent. Each subagent runs with isolated context.\n\nAvailable subagent types:\n${subagentDescriptions}`;
|
|
298
|
+
return tool({
|
|
299
|
+
description: toolDescription,
|
|
300
|
+
inputSchema: z.object({
|
|
301
|
+
description: z.string().describe("The task description for the subagent"),
|
|
302
|
+
subagent_type: z
|
|
303
|
+
.enum(subagentTypes)
|
|
304
|
+
.describe("The type of subagent to use"),
|
|
305
|
+
max_turns: z
|
|
306
|
+
.number()
|
|
307
|
+
.optional()
|
|
308
|
+
.describe(`Maximum turns for the subagent (default: ${defaultMaxTurns})`),
|
|
309
|
+
run_in_background: z
|
|
310
|
+
.boolean()
|
|
311
|
+
.optional()
|
|
312
|
+
.describe("Run the task in background without blocking. Returns task ID for later retrieval via get_task_result action."),
|
|
313
|
+
}),
|
|
314
|
+
execute: async (params) => {
|
|
315
|
+
const { description, subagent_type, max_turns, run_in_background } = params;
|
|
316
|
+
// Find the subagent definition
|
|
317
|
+
const subagentDef = subagents.find((s) => s.type === subagent_type);
|
|
318
|
+
if (!subagentDef) {
|
|
319
|
+
return { error: `Unknown subagent type: ${subagent_type}` };
|
|
320
|
+
}
|
|
321
|
+
// Create task entry
|
|
322
|
+
const taskId = `task-${++taskIdCounter}-${Date.now()}`;
|
|
323
|
+
const task = createBackgroundTask({
|
|
324
|
+
id: taskId,
|
|
325
|
+
subagentType: subagent_type,
|
|
326
|
+
description,
|
|
327
|
+
});
|
|
328
|
+
// Check if this is a streaming subagent
|
|
329
|
+
const isStreamingSubagent = subagentDef.streaming === true && streamingContext?.writer != null;
|
|
330
|
+
// Execute task function
|
|
331
|
+
const executeTask = async () => {
|
|
332
|
+
const startTime = Date.now();
|
|
333
|
+
// Update task status to running
|
|
334
|
+
const runningTask = updateBackgroundTask(task, { status: "running" });
|
|
335
|
+
if (taskStore) {
|
|
336
|
+
await taskStore.save(runningTask);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
backgroundTasks.set(taskId, runningTask);
|
|
340
|
+
}
|
|
341
|
+
Object.assign(task, runningTask);
|
|
342
|
+
// Determine the model to use
|
|
343
|
+
// Priority: subagentDef.model > defaultModel > parentAgent.model
|
|
344
|
+
let subagentModel = defaultModel;
|
|
345
|
+
if (subagentDef.model && subagentDef.model !== "inherit") {
|
|
346
|
+
subagentModel = subagentDef.model;
|
|
347
|
+
}
|
|
348
|
+
// Build streaming metadata for this subagent
|
|
349
|
+
const subagentMetadata = {
|
|
350
|
+
agentType: subagent_type,
|
|
351
|
+
agentId: taskId,
|
|
352
|
+
parentAgentId: streamingContext?.metadata?.agentId,
|
|
353
|
+
};
|
|
354
|
+
// Build context for the subagent factory
|
|
355
|
+
const createContext = {
|
|
356
|
+
model: subagentModel,
|
|
357
|
+
allowedTools: subagentDef.allowedTools,
|
|
358
|
+
plugins: subagentDef.plugins,
|
|
359
|
+
// Only pass streaming context if this is a streaming subagent
|
|
360
|
+
streamingContext: isStreamingSubagent
|
|
361
|
+
? {
|
|
362
|
+
writer: streamingContext.writer,
|
|
363
|
+
metadata: subagentMetadata,
|
|
364
|
+
}
|
|
365
|
+
: undefined,
|
|
366
|
+
// Pass parent span context for distributed tracing
|
|
367
|
+
parentSpanContext,
|
|
368
|
+
};
|
|
369
|
+
// Create the subagent with resolved context
|
|
370
|
+
const subagent = await subagentDef.create(createContext);
|
|
371
|
+
// Wait for subagent's async initialization (MCP connections, plugin setup)
|
|
372
|
+
await subagent.ready;
|
|
373
|
+
let resultText;
|
|
374
|
+
if (isStreamingSubagent) {
|
|
375
|
+
// Streaming execution - send subagent output as data chunks
|
|
376
|
+
// This keeps the output separate from the assistant message content
|
|
377
|
+
// Signal subagent start to client
|
|
378
|
+
streamingContext.writer.write({
|
|
379
|
+
type: "data-subagent-stream",
|
|
380
|
+
data: {
|
|
381
|
+
event: "start",
|
|
382
|
+
...subagentMetadata,
|
|
383
|
+
prompt: description,
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
// Stream the subagent's response
|
|
387
|
+
const streamResult = await subagent.streamRaw({
|
|
388
|
+
prompt: description,
|
|
389
|
+
maxTokens: (max_turns ?? defaultMaxTurns) * 4096,
|
|
390
|
+
});
|
|
391
|
+
// Stream text chunks as data instead of merging into message
|
|
392
|
+
// This allows the client to handle them separately from assistant text
|
|
393
|
+
let fullText = "";
|
|
394
|
+
for await (const chunk of streamResult.textStream) {
|
|
395
|
+
fullText += chunk;
|
|
396
|
+
// Send each chunk as a data annotation
|
|
397
|
+
streamingContext.writer.write({
|
|
398
|
+
type: "data-subagent-stream",
|
|
399
|
+
data: {
|
|
400
|
+
event: "chunk",
|
|
401
|
+
...subagentMetadata,
|
|
402
|
+
chunk,
|
|
403
|
+
},
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
resultText = fullText;
|
|
407
|
+
// Signal subagent completion to client
|
|
408
|
+
streamingContext.writer.write({
|
|
409
|
+
type: "data-subagent-stream",
|
|
410
|
+
data: {
|
|
411
|
+
event: "complete",
|
|
412
|
+
...subagentMetadata,
|
|
413
|
+
text: resultText,
|
|
414
|
+
duration: Date.now() - startTime,
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
// Non-streaming execution - use generate() as before
|
|
420
|
+
const result = await subagent.generate({
|
|
421
|
+
prompt: description,
|
|
422
|
+
maxTokens: (max_turns ?? defaultMaxTurns) * 4096,
|
|
423
|
+
});
|
|
424
|
+
resultText =
|
|
425
|
+
result.status === "complete" ? result.text : `Interrupted: ${result.interrupt.type}`;
|
|
426
|
+
}
|
|
427
|
+
return resultText;
|
|
428
|
+
};
|
|
429
|
+
// Background execution
|
|
430
|
+
if (run_in_background) {
|
|
431
|
+
// Streaming subagents cannot run in background
|
|
432
|
+
if (isStreamingSubagent) {
|
|
433
|
+
return {
|
|
434
|
+
error: true,
|
|
435
|
+
taskId,
|
|
436
|
+
message: `Streaming subagent "${subagent_type}" cannot run in background. Remove run_in_background or use a non-streaming subagent.`,
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
// Save initial task state
|
|
440
|
+
if (taskStore) {
|
|
441
|
+
await taskStore.save(task);
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
backgroundTasks.set(taskId, task);
|
|
445
|
+
}
|
|
446
|
+
// Start execution without awaiting
|
|
447
|
+
executeTask()
|
|
448
|
+
.then(async (resultText) => {
|
|
449
|
+
const completedTask = updateBackgroundTask(task, {
|
|
450
|
+
status: "completed",
|
|
451
|
+
result: resultText,
|
|
452
|
+
completedAt: new Date().toISOString(),
|
|
453
|
+
});
|
|
454
|
+
if (taskStore) {
|
|
455
|
+
await taskStore.save(completedTask);
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
backgroundTasks.set(taskId, completedTask);
|
|
459
|
+
}
|
|
460
|
+
Object.assign(task, completedTask);
|
|
461
|
+
})
|
|
462
|
+
.catch(async (error) => {
|
|
463
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
464
|
+
const failedTask = updateBackgroundTask(task, {
|
|
465
|
+
status: "failed",
|
|
466
|
+
error: errorMessage,
|
|
467
|
+
completedAt: new Date().toISOString(),
|
|
468
|
+
});
|
|
469
|
+
if (taskStore) {
|
|
470
|
+
await taskStore.save(failedTask);
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
backgroundTasks.set(taskId, failedTask);
|
|
474
|
+
}
|
|
475
|
+
Object.assign(task, failedTask);
|
|
476
|
+
});
|
|
477
|
+
return {
|
|
478
|
+
taskId,
|
|
479
|
+
status: "running",
|
|
480
|
+
message: `Task started in background. Use task tool with action "get_result" and taskId "${taskId}" to retrieve the result later.`,
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
// Foreground execution (blocking)
|
|
484
|
+
try {
|
|
485
|
+
const resultText = await executeTask();
|
|
486
|
+
const completedTask = updateBackgroundTask(task, {
|
|
487
|
+
status: "completed",
|
|
488
|
+
result: resultText,
|
|
489
|
+
completedAt: new Date().toISOString(),
|
|
490
|
+
});
|
|
491
|
+
// Optional persistence for foreground tasks
|
|
492
|
+
if (taskStore) {
|
|
493
|
+
await taskStore.save(completedTask);
|
|
494
|
+
}
|
|
495
|
+
return {
|
|
496
|
+
success: true,
|
|
497
|
+
taskId,
|
|
498
|
+
text: resultText,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
catch (error) {
|
|
502
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
503
|
+
const failedTask = updateBackgroundTask(task, {
|
|
504
|
+
status: "failed",
|
|
505
|
+
error: errorMessage,
|
|
506
|
+
completedAt: new Date().toISOString(),
|
|
507
|
+
});
|
|
508
|
+
// Optional persistence for foreground tasks
|
|
509
|
+
if (taskStore) {
|
|
510
|
+
await taskStore.save(failedTask);
|
|
511
|
+
}
|
|
512
|
+
return {
|
|
513
|
+
error: true,
|
|
514
|
+
taskId,
|
|
515
|
+
message: errorMessage,
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
},
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
//# sourceMappingURL=task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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AAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAE5E,MAAM,UAAU,GAAG,oBAAoB,CAAC,IAAI,EAAE;oBAC5C,MAAM,EAAE,QAAQ;oBAChB,KAAK,EAAE,YAAY;oBACnB,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;iBACtC,CAAC,CAAC;gBAEH,4CAA4C;gBAC5C,IAAI,SAAS,EAAE,CAAC;oBACd,MAAM,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBACnC,CAAC;gBAED,OAAO;oBACL,KAAK,EAAE,IAAI;oBACX,MAAM;oBACN,OAAO,EAAE,YAAY;iBACtB,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Todo tool for task planning and tracking.
|
|
3
|
+
*
|
|
4
|
+
* Provides a single `todo_write` tool for managing task lists, similar to
|
|
5
|
+
* Claude Code's TodoWrite. Agents replace the entire todo list with each call.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import type { AgentState, TodoStatus } from "../backends/state.js";
|
|
10
|
+
/**
|
|
11
|
+
* Type of change that occurred to the todo list.
|
|
12
|
+
*
|
|
13
|
+
* @category Tools
|
|
14
|
+
*/
|
|
15
|
+
export type TodoChangeType = "replaced" | "cleared";
|
|
16
|
+
/**
|
|
17
|
+
* Data for todo change events.
|
|
18
|
+
*
|
|
19
|
+
* @category Tools
|
|
20
|
+
*/
|
|
21
|
+
export interface TodosChangedData {
|
|
22
|
+
/** Discriminator type */
|
|
23
|
+
type: "todosChanged";
|
|
24
|
+
/** Type of change */
|
|
25
|
+
changeType: TodoChangeType;
|
|
26
|
+
/** IDs of affected todos */
|
|
27
|
+
affectedIds: string[];
|
|
28
|
+
/** Total count of todos */
|
|
29
|
+
totalCount: number;
|
|
30
|
+
/** Summary of current todos */
|
|
31
|
+
summary: {
|
|
32
|
+
pending: number;
|
|
33
|
+
inProgress: number;
|
|
34
|
+
completed: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Callback type for todo change events.
|
|
39
|
+
*
|
|
40
|
+
* When provided to the todo tool, this callback is invoked whenever the todo list changes.
|
|
41
|
+
* This enables integration with the hook system for emitting `todos:changed` events.
|
|
42
|
+
*
|
|
43
|
+
* @param data - The change event data
|
|
44
|
+
*
|
|
45
|
+
* @category Tools
|
|
46
|
+
*/
|
|
47
|
+
export type OnTodosChanged = (data: TodosChangedData) => void | Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Input for a todo item.
|
|
50
|
+
*
|
|
51
|
+
* @category Tools
|
|
52
|
+
*/
|
|
53
|
+
export interface TodoInput {
|
|
54
|
+
/** Description of the task */
|
|
55
|
+
content: string;
|
|
56
|
+
/** Current status of the task */
|
|
57
|
+
status: TodoStatus;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Options for creating the todo_write tool.
|
|
61
|
+
*
|
|
62
|
+
* @category Tools
|
|
63
|
+
*/
|
|
64
|
+
export interface TodoWriteToolOptions {
|
|
65
|
+
/** The agent state containing the todo list */
|
|
66
|
+
state: AgentState;
|
|
67
|
+
/**
|
|
68
|
+
* Callback invoked when todos change.
|
|
69
|
+
*
|
|
70
|
+
* Use this to integrate with the hook system for emitting `todos:changed` events.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const todoWrite = createTodoWriteTool({
|
|
75
|
+
* state,
|
|
76
|
+
* onTodosChanged: (data) => {
|
|
77
|
+
* console.log("Todos changed:", data);
|
|
78
|
+
* },
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
onTodosChanged?: OnTodosChanged;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Creates the todo_write tool for managing task lists.
|
|
86
|
+
*
|
|
87
|
+
* This tool replaces the entire todo list with the provided items. It's designed
|
|
88
|
+
* to match Claude Code's TodoWrite behavior where the agent always provides the
|
|
89
|
+
* complete list state.
|
|
90
|
+
*
|
|
91
|
+
* @param options - Configuration options
|
|
92
|
+
* @returns An AI SDK compatible tool for writing todos
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* import { createTodoWriteTool, createAgentState } from "@lleverage-ai/agent-sdk";
|
|
97
|
+
*
|
|
98
|
+
* const state = createAgentState();
|
|
99
|
+
* const todoWrite = createTodoWriteTool({ state });
|
|
100
|
+
*
|
|
101
|
+
* const agent = createAgent({
|
|
102
|
+
* model,
|
|
103
|
+
* tools: { todo_write: todoWrite },
|
|
104
|
+
* });
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* // With change callback for UI integration
|
|
110
|
+
* const todoWrite = createTodoWriteTool({
|
|
111
|
+
* state,
|
|
112
|
+
* onTodosChanged: (data) => {
|
|
113
|
+
* console.log(`Todos updated: ${data.summary.completed}/${data.totalCount} completed`);
|
|
114
|
+
* },
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @category Tools
|
|
119
|
+
*/
|
|
120
|
+
export declare function createTodoWriteTool(options: TodoWriteToolOptions): import("ai").Tool<{
|
|
121
|
+
todos: TodoInput[];
|
|
122
|
+
}, {
|
|
123
|
+
success: boolean;
|
|
124
|
+
count: number;
|
|
125
|
+
summary: {
|
|
126
|
+
pending: number;
|
|
127
|
+
inProgress: number;
|
|
128
|
+
completed: number;
|
|
129
|
+
};
|
|
130
|
+
}>;
|
|
131
|
+
//# sourceMappingURL=todos.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"todos.d.ts","sourceRoot":"","sources":["../../src/tools/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