@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,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key-value store task implementation.
|
|
3
|
+
*
|
|
4
|
+
* Stores tasks in a key-value store (Redis, DynamoDB, etc.).
|
|
5
|
+
* Provides persistence with fast access.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { isBackgroundTask, shouldExpireTask } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Key-value store implementation of the task store.
|
|
12
|
+
*
|
|
13
|
+
* Stores tasks in a key-value store (Redis, DynamoDB, etc.).
|
|
14
|
+
* Requires a KeyValueStore implementation.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Using Redis
|
|
19
|
+
* import { createClient } from "redis";
|
|
20
|
+
*
|
|
21
|
+
* const redisClient = createClient();
|
|
22
|
+
* await redisClient.connect();
|
|
23
|
+
*
|
|
24
|
+
* const kvStore: KeyValueStore = {
|
|
25
|
+
* async get(key) {
|
|
26
|
+
* return redisClient.get(key);
|
|
27
|
+
* },
|
|
28
|
+
* async set(key, value, options) {
|
|
29
|
+
* if (options?.ttl) {
|
|
30
|
+
* await redisClient.setEx(key, options.ttl, value);
|
|
31
|
+
* } else {
|
|
32
|
+
* await redisClient.set(key, value);
|
|
33
|
+
* }
|
|
34
|
+
* },
|
|
35
|
+
* async delete(key) {
|
|
36
|
+
* const result = await redisClient.del(key);
|
|
37
|
+
* return result > 0;
|
|
38
|
+
* },
|
|
39
|
+
* async exists(key) {
|
|
40
|
+
* const result = await redisClient.exists(key);
|
|
41
|
+
* return result > 0;
|
|
42
|
+
* },
|
|
43
|
+
* async keys(pattern) {
|
|
44
|
+
* return redisClient.keys(pattern);
|
|
45
|
+
* },
|
|
46
|
+
* };
|
|
47
|
+
*
|
|
48
|
+
* const store = new KVTaskStore(kvStore, {
|
|
49
|
+
* namespace: "myapp",
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @category TaskStore
|
|
54
|
+
*/
|
|
55
|
+
export class KVTaskStore {
|
|
56
|
+
kv;
|
|
57
|
+
namespace;
|
|
58
|
+
expirationMs;
|
|
59
|
+
/**
|
|
60
|
+
* Create a new KV-based task store.
|
|
61
|
+
*
|
|
62
|
+
* @param kv - The key-value store implementation
|
|
63
|
+
* @param options - Configuration options
|
|
64
|
+
*/
|
|
65
|
+
constructor(kv, options = {}) {
|
|
66
|
+
this.kv = kv;
|
|
67
|
+
this.namespace = options.namespace;
|
|
68
|
+
this.expirationMs = options.expirationMs ?? 86400000; // 24 hours default
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get the storage key for a task ID.
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
getKey(taskId) {
|
|
75
|
+
return this.namespace ? `${this.namespace}:task:${taskId}` : `task:${taskId}`;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get the task ID from a storage key.
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
getTaskIdFromKey(key) {
|
|
82
|
+
const prefix = this.namespace ? `${this.namespace}:task:` : "task:";
|
|
83
|
+
if (key.startsWith(prefix)) {
|
|
84
|
+
return key.slice(prefix.length);
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get the key pattern for listing tasks.
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
getKeyPattern() {
|
|
93
|
+
return this.namespace ? `${this.namespace}:task:*` : "task:*";
|
|
94
|
+
}
|
|
95
|
+
async save(task) {
|
|
96
|
+
const key = this.getKey(task.id);
|
|
97
|
+
const data = JSON.stringify(task);
|
|
98
|
+
await this.kv.set(key, data);
|
|
99
|
+
}
|
|
100
|
+
async load(taskId) {
|
|
101
|
+
const key = this.getKey(taskId);
|
|
102
|
+
const data = await this.kv.get(key);
|
|
103
|
+
if (!data) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const task = JSON.parse(data);
|
|
108
|
+
if (!isBackgroundTask(task)) {
|
|
109
|
+
console.warn(`Invalid task data for key ${key}, skipping`);
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
return task;
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.warn(`Failed to parse task data for key ${key}:`, error);
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async list(filter) {
|
|
120
|
+
const tasks = await this.listTasks(filter);
|
|
121
|
+
return tasks.map((t) => t.id);
|
|
122
|
+
}
|
|
123
|
+
async listTasks(filter) {
|
|
124
|
+
const pattern = this.getKeyPattern();
|
|
125
|
+
const keys = await this.kv.keys(pattern);
|
|
126
|
+
const tasks = [];
|
|
127
|
+
for (const key of keys) {
|
|
128
|
+
const taskId = this.getTaskIdFromKey(key);
|
|
129
|
+
if (!taskId) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const task = await this.load(taskId);
|
|
133
|
+
if (!task) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
// Apply status filter if provided
|
|
137
|
+
if (filter?.status) {
|
|
138
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
139
|
+
if (!statuses.includes(task.status)) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
tasks.push(task);
|
|
144
|
+
}
|
|
145
|
+
return tasks;
|
|
146
|
+
}
|
|
147
|
+
async delete(taskId) {
|
|
148
|
+
const key = this.getKey(taskId);
|
|
149
|
+
return this.kv.delete(key);
|
|
150
|
+
}
|
|
151
|
+
async exists(taskId) {
|
|
152
|
+
const key = this.getKey(taskId);
|
|
153
|
+
return this.kv.exists(key);
|
|
154
|
+
}
|
|
155
|
+
async cleanup() {
|
|
156
|
+
const allTasks = await this.listTasks({
|
|
157
|
+
status: ["completed", "failed"],
|
|
158
|
+
});
|
|
159
|
+
let cleaned = 0;
|
|
160
|
+
for (const task of allTasks) {
|
|
161
|
+
if (shouldExpireTask(task, this.expirationMs)) {
|
|
162
|
+
await this.delete(task.id);
|
|
163
|
+
cleaned++;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return cleaned;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=kv-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kv-store.js","sourceRoot":"","sources":["../../src/task-store/kv-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAoDhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,OAAO,WAAW;IACd,EAAE,CAAgB;IAClB,SAAS,CAAU;IACnB,YAAY,CAAS;IAE7B;;;;;OAKG;IACH,YAAY,EAAiB,EAAE,UAA4B,EAAE;QAC3D,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,QAAQ,CAAC,CAAC,mBAAmB;IAC3E,CAAC;IAED;;;OAGG;IACK,MAAM,CAAC,MAAc;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,MAAM,EAAE,CAAC;IAChF,CAAC;IAED;;;OAGG;IACK,gBAAgB,CAAC,GAAW;QAClC,MAAM,MAAM,GAAG,IAAI,CAAC,SA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I,CAAC,CAAC;QACnB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAc;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAc;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC;YACpC,MAAM,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;SAChC,CAAC,CAAC;QAEH,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;YAC5B,IAAI,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC9C,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAC3B,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory task store implementation.
|
|
3
|
+
*
|
|
4
|
+
* Stores tasks in a Map. Tasks are lost when the process exits.
|
|
5
|
+
* Useful for development, testing, or scenarios where persistence isn't needed.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import type { BackgroundTask, BackgroundTaskStatus, BaseTaskStore, TaskStoreOptions } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* In-memory implementation of the task store.
|
|
12
|
+
*
|
|
13
|
+
* Stores tasks in a Map in memory. All tasks are lost when the process exits.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const store = new MemoryTaskStore();
|
|
18
|
+
*
|
|
19
|
+
* await store.save({
|
|
20
|
+
* id: "task-123",
|
|
21
|
+
* subagentType: "researcher",
|
|
22
|
+
* description: "Research topic",
|
|
23
|
+
* status: "running",
|
|
24
|
+
* createdAt: new Date().toISOString(),
|
|
25
|
+
* updatedAt: new Date().toISOString(),
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const task = await store.load("task-123");
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @category TaskStore
|
|
32
|
+
*/
|
|
33
|
+
export declare class MemoryTaskStore implements BaseTaskStore {
|
|
34
|
+
private tasks;
|
|
35
|
+
private namespace?;
|
|
36
|
+
private expirationMs;
|
|
37
|
+
/**
|
|
38
|
+
* Create a new in-memory task store.
|
|
39
|
+
*
|
|
40
|
+
* @param options - Configuration options
|
|
41
|
+
*/
|
|
42
|
+
constructor(options?: TaskStoreOptions);
|
|
43
|
+
/**
|
|
44
|
+
* Get the storage key for a task ID.
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
private getKey;
|
|
48
|
+
save(task: BackgroundTask): Promise<void>;
|
|
49
|
+
load(taskId: string): Promise<BackgroundTask | undefined>;
|
|
50
|
+
list(filter?: {
|
|
51
|
+
status?: BackgroundTaskStatus | BackgroundTaskStatus[];
|
|
52
|
+
}): Promise<string[]>;
|
|
53
|
+
listTasks(filter?: {
|
|
54
|
+
status?: BackgroundTaskStatus | BackgroundTaskStatus[];
|
|
55
|
+
}): Promise<BackgroundTask[]>;
|
|
56
|
+
delete(taskId: string): Promise<boolean>;
|
|
57
|
+
exists(taskId: string): Promise<boolean>;
|
|
58
|
+
cleanup(): Promise<number>;
|
|
59
|
+
/**
|
|
60
|
+
* Clear all tasks from the store.
|
|
61
|
+
*
|
|
62
|
+
* Useful for testing.
|
|
63
|
+
*/
|
|
64
|
+
clear(): void;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=memory-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-store.d.ts","sourceRoot":"","sources":["../../src/task-store/memory-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAGpB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,eAAgB,YAAW,aAAa;IACnD,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,YAAY,CAAS;IAE7B;;;;OAIG;gBACS,OAAO,GAAE,gBAAqB;IAK1C;;;OAGG;IACH,OAAO,CAAC,MAAM;IAIR,IAAI,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;IAMzD,IAAI,CAAC,MAAM,CAAC,EAAE;QAClB,MAAM,CAAC,EAAE,oBAAoB,GAAG,oBAAoB,EAAE,CAAC;KACxD,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAKf,SAAS,CAAC,MAAM,CAAC,EAAE;QACvB,MAAM,CAAC,EAAE,oBAAoB,GAAG,oBAAoB,EAAE,CAAC;KACxD,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAwBvB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAgBhC;;;;OAIG;IACH,KAAK,IAAI,IAAI;CAYd"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory task store implementation.
|
|
3
|
+
*
|
|
4
|
+
* Stores tasks in a Map. Tasks are lost when the process exits.
|
|
5
|
+
* Useful for development, testing, or scenarios where persistence isn't needed.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { shouldExpireTask } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* In-memory implementation of the task store.
|
|
12
|
+
*
|
|
13
|
+
* Stores tasks in a Map in memory. All tasks are lost when the process exits.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const store = new MemoryTaskStore();
|
|
18
|
+
*
|
|
19
|
+
* await store.save({
|
|
20
|
+
* id: "task-123",
|
|
21
|
+
* subagentType: "researcher",
|
|
22
|
+
* description: "Research topic",
|
|
23
|
+
* status: "running",
|
|
24
|
+
* createdAt: new Date().toISOString(),
|
|
25
|
+
* updatedAt: new Date().toISOString(),
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const task = await store.load("task-123");
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @category TaskStore
|
|
32
|
+
*/
|
|
33
|
+
export class MemoryTaskStore {
|
|
34
|
+
tasks = new Map();
|
|
35
|
+
namespace;
|
|
36
|
+
expirationMs;
|
|
37
|
+
/**
|
|
38
|
+
* Create a new in-memory task store.
|
|
39
|
+
*
|
|
40
|
+
* @param options - Configuration options
|
|
41
|
+
*/
|
|
42
|
+
constructor(options = {}) {
|
|
43
|
+
this.namespace = options.namespace;
|
|
44
|
+
this.expirationMs = options.expirationMs ?? 86400000; // 24 hours default
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get the storage key for a task ID.
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
getKey(taskId) {
|
|
51
|
+
return this.namespace ? `${this.namespace}:${taskId}` : taskId;
|
|
52
|
+
}
|
|
53
|
+
async save(task) {
|
|
54
|
+
const key = this.getKey(task.id);
|
|
55
|
+
this.tasks.set(key, { ...task });
|
|
56
|
+
}
|
|
57
|
+
async load(taskId) {
|
|
58
|
+
const key = this.getKey(taskId);
|
|
59
|
+
const task = this.tasks.get(key);
|
|
60
|
+
return task ? { ...task } : undefined;
|
|
61
|
+
}
|
|
62
|
+
async list(filter) {
|
|
63
|
+
const tasks = await this.listTasks(filter);
|
|
64
|
+
return tasks.map((t) => t.id);
|
|
65
|
+
}
|
|
66
|
+
async listTasks(filter) {
|
|
67
|
+
const prefix = this.namespace ? `${this.namespace}:` : "";
|
|
68
|
+
const tasks = [];
|
|
69
|
+
for (const [key, task] of this.tasks) {
|
|
70
|
+
// Skip if not in our namespace
|
|
71
|
+
if (prefix && !key.startsWith(prefix)) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
// Apply status filter if provided
|
|
75
|
+
if (filter?.status) {
|
|
76
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
77
|
+
if (!statuses.includes(task.status)) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
tasks.push({ ...task });
|
|
82
|
+
}
|
|
83
|
+
return tasks;
|
|
84
|
+
}
|
|
85
|
+
async delete(taskId) {
|
|
86
|
+
const key = this.getKey(taskId);
|
|
87
|
+
return this.tasks.delete(key);
|
|
88
|
+
}
|
|
89
|
+
async exists(taskId) {
|
|
90
|
+
const key = this.getKey(taskId);
|
|
91
|
+
return this.tasks.has(key);
|
|
92
|
+
}
|
|
93
|
+
async cleanup() {
|
|
94
|
+
const allTasks = await this.listTasks({
|
|
95
|
+
status: ["completed", "failed"],
|
|
96
|
+
});
|
|
97
|
+
let cleaned = 0;
|
|
98
|
+
for (const task of allTasks) {
|
|
99
|
+
if (shouldExpireTask(task, this.expirationMs)) {
|
|
100
|
+
await this.delete(task.id);
|
|
101
|
+
cleaned++;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return cleaned;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Clear all tasks from the store.
|
|
108
|
+
*
|
|
109
|
+
* Useful for testing.
|
|
110
|
+
*/
|
|
111
|
+
clear() {
|
|
112
|
+
if (this.namespace) {
|
|
113
|
+
const prefix = `${this.namespace}:`;
|
|
114
|
+
for (const key of this.tasks.keys()) {
|
|
115
|
+
if (key.startsWith(prefix)) {
|
|
116
|
+
this.tasks.delete(key);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
this.tasks.clear();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=memory-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-store.js","sourceRoot":"","sources":["../../src/task-store/memory-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,eAAe;IAClB,KAAK,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC1C,SAAS,CAAU;IACnB,YAAY,CAAS;IAE7B;;;;OAIG;IACH,YAAY,UAA4B,EAAE;QACxC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,QAAQ,CAAC,CAAC,mBAAmB;IAC3E,CAAC;IAED;;;OAGG;IACK,MAAM,CAAC,MAAc;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IACjE,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAoB;QAC7B,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,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AC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;gBACpC,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC3B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACzB,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the task store system.
|
|
3
|
+
*
|
|
4
|
+
* Task stores provide persistence for background task state, allowing tasks
|
|
5
|
+
* to survive process restarts and be recovered when the agent resumes.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Status of a background task.
|
|
11
|
+
*
|
|
12
|
+
* - `pending`: Task created but not yet started
|
|
13
|
+
* - `running`: Task is currently executing
|
|
14
|
+
* - `completed`: Task finished successfully
|
|
15
|
+
* - `failed`: Task encountered an error
|
|
16
|
+
*
|
|
17
|
+
* @category TaskStore
|
|
18
|
+
*/
|
|
19
|
+
export type BackgroundTaskStatus = "pending" | "running" | "completed" | "failed";
|
|
20
|
+
/**
|
|
21
|
+
* Complete snapshot of a background task's state.
|
|
22
|
+
*
|
|
23
|
+
* A background task captures the execution state of an async subagent,
|
|
24
|
+
* including:
|
|
25
|
+
* - Task metadata (ID, type, description)
|
|
26
|
+
* - Current status and timestamps
|
|
27
|
+
* - Result or error information
|
|
28
|
+
* - Optional metadata for custom data
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const task: BackgroundTask = {
|
|
33
|
+
* id: "task-123",
|
|
34
|
+
* subagentType: "researcher",
|
|
35
|
+
* description: "Research TypeScript history",
|
|
36
|
+
* status: "running",
|
|
37
|
+
* createdAt: "2026-01-30T10:00:00Z",
|
|
38
|
+
* updatedAt: "2026-01-30T10:05:00Z",
|
|
39
|
+
* };
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @category TaskStore
|
|
43
|
+
*/
|
|
44
|
+
export interface BackgroundTask {
|
|
45
|
+
/** Unique identifier for this task */
|
|
46
|
+
id: string;
|
|
47
|
+
/** Type of subagent handling this task */
|
|
48
|
+
subagentType: string;
|
|
49
|
+
/** Task description/prompt */
|
|
50
|
+
description: string;
|
|
51
|
+
/** Current status */
|
|
52
|
+
status: BackgroundTaskStatus;
|
|
53
|
+
/** ISO 8601 timestamp when this task was created */
|
|
54
|
+
createdAt: string;
|
|
55
|
+
/** ISO 8601 timestamp when this task was last updated */
|
|
56
|
+
updatedAt: string;
|
|
57
|
+
/** ISO 8601 timestamp when this task completed (if completed/failed) */
|
|
58
|
+
completedAt?: string;
|
|
59
|
+
/** Result text (when completed) */
|
|
60
|
+
result?: string;
|
|
61
|
+
/** Error message (when failed) */
|
|
62
|
+
error?: string;
|
|
63
|
+
/** Optional metadata for custom data */
|
|
64
|
+
metadata?: Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Options for creating a task store.
|
|
68
|
+
*
|
|
69
|
+
* @category TaskStore
|
|
70
|
+
*/
|
|
71
|
+
export interface TaskStoreOptions {
|
|
72
|
+
/**
|
|
73
|
+
* Namespace for isolating tasks.
|
|
74
|
+
*
|
|
75
|
+
* Useful for multi-tenant scenarios where different users or sessions
|
|
76
|
+
* need separate task storage.
|
|
77
|
+
*
|
|
78
|
+
* @defaultValue undefined (no namespace)
|
|
79
|
+
*/
|
|
80
|
+
namespace?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Task expiration time in milliseconds.
|
|
83
|
+
*
|
|
84
|
+
* Completed/failed tasks older than this will be automatically cleaned up.
|
|
85
|
+
*
|
|
86
|
+
* @defaultValue 86400000 (24 hours)
|
|
87
|
+
*/
|
|
88
|
+
expirationMs?: number;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Abstract storage interface for background tasks.
|
|
92
|
+
*
|
|
93
|
+
* Implement this interface to create custom task storage backends
|
|
94
|
+
* such as Redis, SQLite, cloud storage, or any other persistence layer.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* class RedisTaskStore implements BaseTaskStore {
|
|
99
|
+
* constructor(private redis: RedisClient) {}
|
|
100
|
+
*
|
|
101
|
+
* async save(task: BackgroundTask): Promise<void> {
|
|
102
|
+
* const key = `task:${task.id}`;
|
|
103
|
+
* await this.redis.set(key, JSON.stringify(task));
|
|
104
|
+
* }
|
|
105
|
+
*
|
|
106
|
+
* async load(taskId: string): Promise<BackgroundTask | undefined> {
|
|
107
|
+
* const key = `task:${taskId}`;
|
|
108
|
+
* const data = await this.redis.get(key);
|
|
109
|
+
* return data ? JSON.parse(data) : undefined;
|
|
110
|
+
* }
|
|
111
|
+
*
|
|
112
|
+
* // ... other methods
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @category TaskStore
|
|
117
|
+
*/
|
|
118
|
+
export interface BaseTaskStore {
|
|
119
|
+
/**
|
|
120
|
+
* Save a task.
|
|
121
|
+
*
|
|
122
|
+
* If a task with the same `id` exists, it should be updated.
|
|
123
|
+
*
|
|
124
|
+
* @param task - The task to save
|
|
125
|
+
*/
|
|
126
|
+
save(task: BackgroundTask): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Load a task by ID.
|
|
129
|
+
*
|
|
130
|
+
* @param taskId - The unique task identifier
|
|
131
|
+
* @returns The task if found, undefined otherwise
|
|
132
|
+
*/
|
|
133
|
+
load(taskId: string): Promise<BackgroundTask | undefined>;
|
|
134
|
+
/**
|
|
135
|
+
* List all task IDs.
|
|
136
|
+
*
|
|
137
|
+
* @param filter - Optional filter by status
|
|
138
|
+
* @returns Array of task IDs
|
|
139
|
+
*/
|
|
140
|
+
list(filter?: {
|
|
141
|
+
status?: BackgroundTaskStatus | BackgroundTaskStatus[];
|
|
142
|
+
}): Promise<string[]>;
|
|
143
|
+
/**
|
|
144
|
+
* List all tasks.
|
|
145
|
+
*
|
|
146
|
+
* @param filter - Optional filter by status
|
|
147
|
+
* @returns Array of tasks
|
|
148
|
+
*/
|
|
149
|
+
listTasks(filter?: {
|
|
150
|
+
status?: BackgroundTaskStatus | BackgroundTaskStatus[];
|
|
151
|
+
}): Promise<BackgroundTask[]>;
|
|
152
|
+
/**
|
|
153
|
+
* Delete a task.
|
|
154
|
+
*
|
|
155
|
+
* @param taskId - The task ID to delete
|
|
156
|
+
* @returns True if a task was deleted, false if not found
|
|
157
|
+
*/
|
|
158
|
+
delete(taskId: string): Promise<boolean>;
|
|
159
|
+
/**
|
|
160
|
+
* Check if a task exists.
|
|
161
|
+
*
|
|
162
|
+
* @param taskId - The task ID to check
|
|
163
|
+
* @returns True if the task exists
|
|
164
|
+
*/
|
|
165
|
+
exists(taskId: string): Promise<boolean>;
|
|
166
|
+
/**
|
|
167
|
+
* Clean up expired tasks.
|
|
168
|
+
*
|
|
169
|
+
* Removes completed/failed tasks older than the expiration time.
|
|
170
|
+
*
|
|
171
|
+
* @returns Number of tasks cleaned up
|
|
172
|
+
*/
|
|
173
|
+
cleanup(): Promise<number>;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Create a new background task with the given data.
|
|
177
|
+
*
|
|
178
|
+
* This is a convenience function that ensures timestamps are set correctly.
|
|
179
|
+
*
|
|
180
|
+
* @param data - Partial task data (id, subagentType, description required)
|
|
181
|
+
* @returns A complete task object
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* const task = createBackgroundTask({
|
|
186
|
+
* id: "task-123",
|
|
187
|
+
* subagentType: "researcher",
|
|
188
|
+
* description: "Research topic X",
|
|
189
|
+
* });
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @category TaskStore
|
|
193
|
+
*/
|
|
194
|
+
export declare function createBackgroundTask(data: Pick<BackgroundTask, "id" | "subagentType" | "description"> & Partial<Omit<BackgroundTask, "id" | "subagentType" | "description">>): BackgroundTask;
|
|
195
|
+
/**
|
|
196
|
+
* Update an existing task with new data.
|
|
197
|
+
*
|
|
198
|
+
* Automatically updates the `updatedAt` timestamp.
|
|
199
|
+
*
|
|
200
|
+
* @param task - The existing task
|
|
201
|
+
* @param updates - Partial updates to apply
|
|
202
|
+
* @returns A new task object with updates applied
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const updated = updateBackgroundTask(task, {
|
|
207
|
+
* status: "completed",
|
|
208
|
+
* result: "Task completed successfully",
|
|
209
|
+
* completedAt: new Date().toISOString(),
|
|
210
|
+
* });
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* @category TaskStore
|
|
214
|
+
*/
|
|
215
|
+
export declare function updateBackgroundTask(task: BackgroundTask, updates: Partial<Omit<BackgroundTask, "id" | "createdAt">>): BackgroundTask;
|
|
216
|
+
/**
|
|
217
|
+
* Type guard to check if an object is a valid BackgroundTask.
|
|
218
|
+
*
|
|
219
|
+
* @param value - The value to check
|
|
220
|
+
* @returns True if the value is a valid BackgroundTask
|
|
221
|
+
*
|
|
222
|
+
* @category TaskStore
|
|
223
|
+
*/
|
|
224
|
+
export declare function isBackgroundTask(value: unknown): value is BackgroundTask;
|
|
225
|
+
/**
|
|
226
|
+
* Check if a task should be expired based on age and status.
|
|
227
|
+
*
|
|
228
|
+
* @param task - The task to check
|
|
229
|
+
* @param expirationMs - Expiration time in milliseconds
|
|
230
|
+
* @returns True if the task should be expired
|
|
231
|
+
*
|
|
232
|
+
* @category TaskStore
|
|
233
|
+
*/
|
|
234
|
+
export declare function shouldExpireTask(task: BackgroundTask, expirationMs: number): boolean;
|
|
235
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/task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