@aiaiaichain/agent 0.1.5 → 0.1.7
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/dist/api/ExtensionAPI.d.ts +0 -1
- package/dist/api/ExtensionAPI.js +3 -7
- package/dist/api/Registry.d.ts +0 -1
- package/dist/api/Registry.js +54 -57
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +684 -685
- package/dist/core/AgentDir.d.ts +1 -1
- package/dist/core/AgentDir.js +45 -39
- package/dist/core/ChainConfig.d.ts +0 -1
- package/dist/core/ChainConfig.js +51 -55
- package/dist/core/EnvLoader.d.ts +4 -1
- package/dist/core/EnvLoader.js +97 -84
- package/dist/core/SystemMonitor.d.ts +0 -1
- package/dist/core/SystemMonitor.js +72 -85
- package/dist/index.d.ts +0 -1
- package/dist/index.js +19 -26
- package/dist/loader.d.ts +0 -1
- package/dist/loader.js +64 -67
- package/dist/mcp/entry.d.ts +0 -1
- package/dist/mcp/entry.js +3 -6
- package/dist/mcp/server.d.ts +0 -1
- package/dist/mcp/server.js +152 -156
- package/dist/models/CostTracker.d.ts +0 -1
- package/dist/models/CostTracker.js +58 -61
- package/dist/models/ModelRegistry.d.ts +0 -1
- package/dist/models/ModelRegistry.js +195 -155
- package/dist/providers/ProviderRegistry.d.ts +0 -1
- package/dist/providers/ProviderRegistry.js +33 -36
- package/dist/runner/AgentRunner.d.ts +0 -1
- package/dist/runner/AgentRunner.js +180 -184
- package/dist/runner/ModelClient.d.ts +0 -1
- package/dist/runner/ModelClient.js +133 -134
- package/dist/runner/SwarmRouter.d.ts +0 -1
- package/dist/runner/SwarmRouter.js +18 -22
- package/dist/runner/ToolDispatcher.d.ts +0 -1
- package/dist/runner/ToolDispatcher.js +30 -33
- package/dist/scheduler/AgentScheduler.d.ts +0 -1
- package/dist/scheduler/AgentScheduler.js +99 -103
- package/dist/session/ContextStore.d.ts +1 -1
- package/dist/session/ContextStore.js +76 -78
- package/dist/session/GoalManager.d.ts +0 -1
- package/dist/session/GoalManager.js +96 -100
- package/dist/session/MemoryStore.d.ts +2 -1
- package/dist/session/MemoryStore.js +108 -87
- package/dist/session/SessionManager.d.ts +5 -4
- package/dist/session/SessionManager.js +83 -62
- package/dist/session/SessionStore.d.ts +0 -1
- package/dist/session/SessionStore.js +112 -116
- package/dist/setup/SetupWizard.d.ts +0 -1
- package/dist/setup/SetupWizard.js +61 -64
- package/dist/tools/CrossTools.d.ts +0 -1
- package/dist/tools/CrossTools.js +140 -144
- package/dist/tools/GmgnIntegration.d.ts +0 -1
- package/dist/tools/GmgnIntegration.js +220 -230
- package/dist/tools/MarketSentiment.d.ts +0 -1
- package/dist/tools/MarketSentiment.js +213 -195
- package/dist/tools/NewsSentiment.d.ts +0 -1
- package/dist/tools/NewsSentiment.js +126 -130
- package/dist/tools/PriceFeed.d.ts +6 -1
- package/dist/tools/PriceFeed.js +201 -133
- package/dist/tools/TechnicalAnalysis.d.ts +1 -2
- package/dist/tools/TechnicalAnalysis.js +248 -216
- package/dist/tools/TechnicalAnalysis.worker.d.ts +25 -0
- package/dist/tools/TechnicalAnalysis.worker.js +92 -0
- package/dist/tools/TokenCalendar.d.ts +0 -1
- package/dist/tools/TokenCalendar.js +63 -68
- package/dist/tools/TokenSecurityScanner.d.ts +0 -1
- package/dist/tools/TokenSecurityScanner.js +93 -96
- package/dist/tools/TransactionSim.d.ts +0 -1
- package/dist/tools/TransactionSim.js +65 -71
- package/dist/tui/App.d.ts +0 -1
- package/dist/tui/App.js +895 -824
- package/dist/tui/ModelSelector.d.ts +0 -1
- package/dist/tui/ModelSelector.js +46 -49
- package/dist/tui/REPL.d.ts +0 -1
- package/dist/tui/REPL.js +222 -210
- package/dist/tui/Sparkline.d.ts +0 -1
- package/dist/tui/Sparkline.js +36 -37
- package/dist/tui/StatusBar.d.ts +0 -1
- package/dist/tui/StatusBar.js +9 -10
- package/dist/tui/ThemePresets.d.ts +0 -1
- package/dist/tui/ThemePresets.js +99 -103
- package/dist/tui/theme.d.ts +0 -1
- package/dist/tui/theme.js +50 -31
- package/dist/util/clipboard.d.ts +0 -1
- package/dist/util/clipboard.js +16 -20
- package/dist/util/commandSuggest.d.ts +0 -1
- package/dist/util/commandSuggest.js +34 -38
- package/dist/util/confirmation.d.ts +0 -1
- package/dist/util/confirmation.js +8 -11
- package/dist/util/errorHandler.d.ts +0 -1
- package/dist/util/errorHandler.js +20 -23
- package/dist/util/errors.d.ts +59 -0
- package/dist/util/errors.js +93 -0
- package/dist/util/logger.d.ts +0 -1
- package/dist/util/logger.js +30 -33
- package/dist/util/processManager.d.ts +0 -1
- package/dist/util/processManager.js +33 -36
- package/dist/util/resilientFetch.d.ts +6 -1
- package/dist/util/resilientFetch.js +134 -80
- package/dist/util/responseCache.d.ts +0 -1
- package/dist/util/responseCache.js +36 -45
- package/dist/util/rpc.d.ts +16 -0
- package/dist/util/rpc.js +69 -0
- package/dist/util/safeLog.d.ts +0 -1
- package/dist/util/safeLog.js +52 -53
- package/dist/util/scheduler.d.ts +0 -1
- package/dist/util/scheduler.js +53 -58
- package/dist/util/webhooks.d.ts +0 -1
- package/dist/util/webhooks.js +54 -58
- package/dist/wallet/ActionFeed.d.ts +3 -3
- package/dist/wallet/ActionFeed.js +189 -187
- package/dist/wallet/AgentWallet.d.ts +9 -7
- package/dist/wallet/AgentWallet.js +121 -141
- package/dist/wallet/ProfitTracker.d.ts +0 -1
- package/dist/wallet/ProfitTracker.js +71 -74
- package/package.json +12 -7
- package/scripts/build-esbuild.mjs +40 -0
- package/scripts/bundle-dts.mjs +58 -0
- package/scripts/minify.mjs +44 -0
- package/scripts/postinstall.js +27 -0
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
* SwarmRouter — parallel sub-agent orchestration.
|
|
3
|
-
* Routes tasks to appropriate model tiers for parallel execution.
|
|
4
|
-
*/
|
|
1
|
+
|
|
5
2
|
export class SwarmRouter {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
registry;
|
|
4
|
+
constructor(registry) {
|
|
5
|
+
this.registry = registry;
|
|
6
|
+
}
|
|
7
|
+
async runConcurrent(tasks, _sessionCtx) {
|
|
8
|
+
return Promise.all(tasks.map(t => this.runSingle(t)));
|
|
9
|
+
}
|
|
10
|
+
async runSingle(task) {
|
|
11
|
+
try {
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
return { taskId: task.id, output: `[${task.tier}] ${task.prompt}` };
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
return { taskId: task.id, output: "", error: e instanceof Error ? e.message : String(e) };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
23
20
|
}
|
|
24
|
-
//# sourceMappingURL=SwarmRouter.js.map
|
|
@@ -1,34 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
* ToolDispatcher — dispatches tool calls from the AI to registered tool handlers.
|
|
3
|
-
*/
|
|
1
|
+
|
|
4
2
|
export class ToolDispatcher {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=ToolDispatcher.js.map
|
|
3
|
+
registry;
|
|
4
|
+
constructor(registry) {
|
|
5
|
+
this.registry = registry;
|
|
6
|
+
}
|
|
7
|
+
async dispatch(toolName, params) {
|
|
8
|
+
const tool = this.registry.getTool(toolName);
|
|
9
|
+
if (!tool) {
|
|
10
|
+
return {
|
|
11
|
+
content: [{ type: "text", text: `Unknown tool: "${toolName}"` }],
|
|
12
|
+
isError: true,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
return await tool.execute(`invoke-${Date.now()}`, params);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
return {
|
|
20
|
+
content: [{ type: "text", text: `Tool "${toolName}" error: ${e instanceof Error ? e.message : String(e)}` }],
|
|
21
|
+
isError: true,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
listTools() {
|
|
26
|
+
return this.registry.listTools();
|
|
27
|
+
}
|
|
28
|
+
getTool(name) {
|
|
29
|
+
return this.registry.getTool(name);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,111 +1,107 @@
|
|
|
1
|
-
|
|
2
|
-
* AgentScheduler — cron and price-triggered scheduled tasks.
|
|
3
|
-
* Persisted to ~/.aiaiai/memory/schedule.json
|
|
4
|
-
*/
|
|
1
|
+
|
|
5
2
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
3
|
import { resolve } from "node:path";
|
|
7
4
|
import { Type } from "@sinclair/typebox";
|
|
8
5
|
import { AgentDir } from "../core/AgentDir.js";
|
|
9
6
|
const SCHEDULE_PATH = resolve(AgentDir.getHome(), "memory", "schedule.json");
|
|
10
7
|
export class AgentScheduler {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
8
|
+
tasks = [];
|
|
9
|
+
interval = null;
|
|
10
|
+
onTask;
|
|
11
|
+
constructor() {
|
|
12
|
+
this.load();
|
|
13
|
+
}
|
|
14
|
+
load() {
|
|
15
|
+
try {
|
|
16
|
+
if (existsSync(SCHEDULE_PATH)) {
|
|
17
|
+
this.tasks = JSON.parse(readFileSync(SCHEDULE_PATH, "utf-8"));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
this.tasks = [];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
save() {
|
|
25
|
+
try {
|
|
26
|
+
writeFileSync(SCHEDULE_PATH, JSON.stringify(this.tasks, null, 2), "utf-8");
|
|
27
|
+
}
|
|
28
|
+
catch { }
|
|
29
|
+
}
|
|
30
|
+
addTask(name, prompt, intervalSeconds) {
|
|
31
|
+
const task = {
|
|
32
|
+
id: `task-${Date.now()}-${Math.random().toString(36).slice(2, 5)}`,
|
|
33
|
+
name,
|
|
34
|
+
prompt,
|
|
35
|
+
cron: intervalSeconds ? String(intervalSeconds) : undefined,
|
|
36
|
+
enabled: true,
|
|
37
|
+
createdAt: Date.now(),
|
|
38
|
+
};
|
|
39
|
+
this.tasks.push(task);
|
|
40
|
+
this.save();
|
|
41
|
+
return task;
|
|
42
|
+
}
|
|
43
|
+
removeTask(id) {
|
|
44
|
+
const idx = this.tasks.findIndex(t => t.id === id);
|
|
45
|
+
if (idx === -1)
|
|
46
|
+
return false;
|
|
47
|
+
this.tasks.splice(idx, 1);
|
|
48
|
+
this.save();
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
listTasks() {
|
|
52
|
+
return [...this.tasks];
|
|
53
|
+
}
|
|
54
|
+
start(onTask) {
|
|
55
|
+
this.onTask = onTask;
|
|
56
|
+
if (this.interval)
|
|
57
|
+
clearInterval(this.interval);
|
|
58
|
+
this.interval = setInterval(() => {
|
|
59
|
+
const now = Date.now();
|
|
60
|
+
for (const task of this.tasks) {
|
|
61
|
+
if (!task.enabled || !task.cron)
|
|
62
|
+
continue;
|
|
63
|
+
const interval = parseInt(task.cron) * 1000;
|
|
64
|
+
if (!task.lastRun || (now - task.lastRun) >= interval) {
|
|
65
|
+
task.lastRun = now;
|
|
66
|
+
this.save();
|
|
67
|
+
this.onTask?.(task);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}, 10_000);
|
|
71
|
+
}
|
|
72
|
+
stop() {
|
|
73
|
+
if (this.interval) {
|
|
74
|
+
clearInterval(this.interval);
|
|
75
|
+
this.interval = null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
addTaskParams = Type.Object({
|
|
80
|
+
name: Type.String({ description: "Task name" }),
|
|
81
|
+
prompt: Type.String({ description: "Prompt to run when task fires" }),
|
|
82
|
+
interval: Type.Optional(Type.Number({ description: "Run every N seconds" })),
|
|
83
|
+
});
|
|
84
|
+
listTasksParams = Type.Object({
|
|
85
|
+
enabled_only: Type.Optional(Type.Boolean({ default: false })),
|
|
86
|
+
});
|
|
87
|
+
removeTaskParams = Type.Object({
|
|
88
|
+
id: Type.String({ description: "Task ID to remove" }),
|
|
89
|
+
});
|
|
90
|
+
async addTaskTool(_id, params) {
|
|
91
|
+
const task = this.addTask(params.name, params.prompt, params.interval);
|
|
92
|
+
return { content: [{ type: "text", text: `Task "${task.name}" created (${task.id})` }] };
|
|
93
|
+
}
|
|
94
|
+
async listTasksTool(_id, params) {
|
|
95
|
+
const enabledOnly = params.enabled_only || false;
|
|
96
|
+
const tasks = enabledOnly ? this.tasks.filter(t => t.enabled) : this.tasks;
|
|
97
|
+
if (tasks.length === 0)
|
|
98
|
+
return { content: [{ type: "text", text: "No scheduled tasks." }] };
|
|
99
|
+
const lines = tasks.map(t => ` ${t.enabled ? "🟢" : "⏸️"} ${t.id} — ${t.name}${t.cron ? ` (every ${t.cron}s)` : ""}`);
|
|
100
|
+
return { content: [{ type: "text", text: `Scheduled Tasks (${tasks.length}):\n${lines.join("\n")}` }] };
|
|
101
|
+
}
|
|
102
|
+
async removeTaskTool(_id, params) {
|
|
103
|
+
const ok = this.removeTask(params.id);
|
|
104
|
+
return { content: [{ type: "text", text: ok ? `Task ${params.id} removed` : `Task ${params.id} not found` }] };
|
|
105
|
+
}
|
|
109
106
|
}
|
|
110
107
|
export const agentScheduler = new AgentScheduler();
|
|
111
|
-
//# sourceMappingURL=AgentScheduler.js.map
|
|
@@ -12,6 +12,7 @@ export interface TaskContext {
|
|
|
12
12
|
}
|
|
13
13
|
export declare class ContextStore {
|
|
14
14
|
private basePath;
|
|
15
|
+
private activeContexts;
|
|
15
16
|
constructor();
|
|
16
17
|
saveTask(taskId: string, data: Record<string, unknown>): void;
|
|
17
18
|
readTask(taskId: string): TaskContext | null;
|
|
@@ -25,4 +26,3 @@ export declare class ContextStore {
|
|
|
25
26
|
listTasksTool(): Promise<ToolResult>;
|
|
26
27
|
}
|
|
27
28
|
export declare const contextStore: ContextStore;
|
|
28
|
-
//# sourceMappingURL=ContextStore.d.ts.map
|
|
@@ -1,85 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
* ContextStore — persistent task context folders.
|
|
3
|
-
* Allows multi-step operations to store and retrieve intermediate state.
|
|
4
|
-
*/
|
|
1
|
+
|
|
5
2
|
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from "node:fs";
|
|
6
3
|
import { resolve } from "node:path";
|
|
7
4
|
import { Type } from "@sinclair/typebox";
|
|
8
5
|
import { AgentDir } from "../core/AgentDir.js";
|
|
9
6
|
export class ContextStore {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
7
|
+
basePath;
|
|
8
|
+
|
|
9
|
+
activeContexts = new Map();
|
|
10
|
+
constructor() {
|
|
11
|
+
this.basePath = resolve(AgentDir.getHome(), "sessions", "tasks");
|
|
12
|
+
if (!existsSync(this.basePath))
|
|
13
|
+
mkdirSync(this.basePath, { recursive: true });
|
|
14
|
+
}
|
|
15
|
+
saveTask(taskId, data) {
|
|
16
|
+
const ctx = {
|
|
17
|
+
taskId,
|
|
18
|
+
data,
|
|
19
|
+
createdAt: Date.now(),
|
|
20
|
+
updatedAt: Date.now(),
|
|
21
|
+
};
|
|
22
|
+
writeFileSync(resolve(this.basePath, `${taskId}.json`), JSON.stringify(ctx, null, 2), "utf-8");
|
|
23
|
+
}
|
|
24
|
+
readTask(taskId) {
|
|
25
|
+
const p = resolve(this.basePath, `${taskId}.json`);
|
|
26
|
+
if (!existsSync(p))
|
|
27
|
+
return null;
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(readFileSync(p, "utf-8"));
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
listTasks() {
|
|
36
|
+
if (!existsSync(this.basePath))
|
|
37
|
+
return [];
|
|
38
|
+
try {
|
|
39
|
+
return readdirSync(this.basePath)
|
|
40
|
+
.filter(f => f.endsWith(".json"))
|
|
41
|
+
.map(f => {
|
|
42
|
+
try {
|
|
43
|
+
return JSON.parse(readFileSync(resolve(this.basePath, f), "utf-8"));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
.filter(Boolean);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
keepTask(taskId) {
|
|
56
|
+
const ctx = this.readTask(taskId);
|
|
57
|
+
if (!ctx)
|
|
58
|
+
return false;
|
|
59
|
+
ctx.keep = true;
|
|
60
|
+
ctx.updatedAt = Date.now();
|
|
61
|
+
writeFileSync(resolve(this.basePath, `${taskId}.json`), JSON.stringify(ctx, null, 2), "utf-8");
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
readContextParams = Type.Object({
|
|
66
|
+
taskId: Type.String({ description: "Task ID from a previous multi-step operation" }),
|
|
67
|
+
});
|
|
68
|
+
listTasksParams = Type.Object({});
|
|
69
|
+
async readContextTool(_id, params) {
|
|
70
|
+
const ctx = this.readTask(params.taskId);
|
|
71
|
+
if (!ctx)
|
|
72
|
+
return { content: [{ type: "text", text: `Task "${params.taskId}" not found.` }] };
|
|
73
|
+
return { content: [{ type: "text", text: JSON.stringify(ctx.data, null, 2) }] };
|
|
74
|
+
}
|
|
75
|
+
async listTasksTool() {
|
|
76
|
+
const tasks = this.listTasks();
|
|
77
|
+
if (tasks.length === 0)
|
|
78
|
+
return { content: [{ type: "text", text: "No saved tasks." }] };
|
|
79
|
+
const lines = tasks.map(t => ` ${t.taskId} — ${Object.keys(t.data).length} keys (${new Date(t.updatedAt).toLocaleString()})${t.keep ? " 🔒" : ""}`);
|
|
80
|
+
return { content: [{ type: "text", text: `Tasks (${tasks.length}):\n${lines.join("\n")}` }] };
|
|
81
|
+
}
|
|
83
82
|
}
|
|
84
83
|
export const contextStore = new ContextStore();
|
|
85
|
-
//# sourceMappingURL=ContextStore.js.map
|