@ai-setting/roy-agent-core 1.4.13 → 1.4.14
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/packages/core/src/config/index.js +32 -0
- package/dist/packages/core/src/env/agent/index.js +24 -0
- package/dist/packages/core/src/env/commands/index.js +14 -0
- package/dist/packages/core/src/env/debug/formatters/index.js +11 -0
- package/dist/packages/core/src/env/debug/index.js +26 -0
- package/dist/packages/core/src/env/hook/index.js +29 -0
- package/dist/packages/core/src/env/index.js +81 -0
- package/dist/packages/core/src/env/llm/index.js +40 -0
- package/dist/packages/core/src/env/log-trace/index.js +83 -0
- package/dist/packages/core/src/env/mcp/index.js +39 -0
- package/dist/packages/core/src/env/mcp/tool/index.js +14 -0
- package/dist/packages/core/src/env/memory/built-in/index.js +11 -0
- package/dist/packages/core/src/env/memory/index.js +56 -0
- package/dist/packages/core/src/env/memory/plugin/index.js +36 -0
- package/dist/packages/core/src/env/prompt/index.js +20 -0
- package/dist/packages/core/src/env/session/index.js +25 -0
- package/dist/packages/core/src/env/session/storage/index.js +18 -0
- package/dist/packages/core/src/env/skill/index.js +34 -0
- package/dist/packages/core/src/env/skill/tool/index.js +9 -0
- package/dist/packages/core/src/env/task/delegate/index.js +18 -0
- package/dist/packages/core/src/env/task/hooks/index.js +7 -0
- package/dist/packages/core/src/env/task/index.js +30 -0
- package/dist/packages/core/src/env/task/plugins/index.js +23 -0
- package/dist/packages/core/src/env/task/storage/index.js +14 -0
- package/dist/packages/core/src/env/task/tools/index.js +17 -0
- package/dist/packages/core/src/env/task/tools/operation/index.js +15 -0
- package/dist/{shared/chunk-1d4rwms4.js → packages/core/src/env/tool/built-in/index.js} +4 -4
- package/dist/packages/core/src/env/tool/index.js +39 -0
- package/dist/packages/core/src/env/workflow/decorators/index.js +27 -0
- package/dist/packages/core/src/env/workflow/engine/index.js +28 -0
- package/dist/packages/core/src/env/workflow/index.js +132 -0
- package/dist/packages/core/src/env/workflow/nodes/index.js +19 -0
- package/dist/packages/core/src/env/workflow/service/index.js +13 -0
- package/dist/packages/core/src/env/workflow/storage/index.js +27 -0
- package/dist/packages/core/src/env/workflow/tools/index.js +159 -0
- package/dist/packages/core/src/env/workflow/types/index.js +94 -0
- package/dist/packages/core/src/env/workflow/utils/index.js +637 -0
- package/dist/packages/core/src/index.js +398 -0
- package/dist/shared/@ai-setting/roy-agent-core-04fm8177.js +393 -0
- package/dist/shared/@ai-setting/roy-agent-core-04qgbjbe.js +172 -0
- package/dist/shared/@ai-setting/roy-agent-core-084qqd7t.js +11 -0
- package/dist/shared/@ai-setting/roy-agent-core-0gekht4e.js +1130 -0
- package/dist/shared/@ai-setting/roy-agent-core-0hdry23r.js +419 -0
- package/dist/shared/{chunk-ze20rksg.js → @ai-setting/roy-agent-core-0sgn3de4.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-12x57kf1.js +286 -0
- package/dist/shared/@ai-setting/roy-agent-core-1f3xrrm6.js +393 -0
- package/dist/shared/{chunk-q9j99fsm.js → @ai-setting/roy-agent-core-1k28kg7h.js} +6 -6
- package/dist/shared/{chunk-2b5kbhx3.js → @ai-setting/roy-agent-core-1z1zv5g8.js} +9 -117
- package/dist/shared/@ai-setting/roy-agent-core-2hqxnaf3.js +851 -0
- package/dist/shared/@ai-setting/roy-agent-core-3dfq8awb.js +587 -0
- package/dist/shared/@ai-setting/roy-agent-core-3takar0s.js +93 -0
- package/dist/shared/@ai-setting/roy-agent-core-3tnb2005.js +117 -0
- package/dist/shared/@ai-setting/roy-agent-core-4vmcvkav.js +14 -0
- package/dist/shared/{chunk-25x2pdtp.js → @ai-setting/roy-agent-core-4ws8atva.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-5fbp24se.js +603 -0
- package/dist/shared/@ai-setting/roy-agent-core-5my94ywp.js +66 -0
- package/dist/shared/{chunk-rncy3rtd.js → @ai-setting/roy-agent-core-6j0zcmwk.js} +128 -1122
- package/dist/shared/@ai-setting/roy-agent-core-6w4pmxc7.js +266 -0
- package/dist/shared/{chunk-yqmx37vm.js → @ai-setting/roy-agent-core-7vrk3add.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-8dvbn7tw.js +64 -0
- package/dist/shared/@ai-setting/roy-agent-core-8mbmrwzs.js +171 -0
- package/dist/shared/@ai-setting/roy-agent-core-8wzz66qe.js +620 -0
- package/dist/shared/@ai-setting/roy-agent-core-9ykq91jc.js +762 -0
- package/dist/shared/@ai-setting/roy-agent-core-dde19zke.js +1305 -0
- package/dist/shared/@ai-setting/roy-agent-core-f7g67gce.js +913 -0
- package/dist/shared/@ai-setting/roy-agent-core-fq5mtxsy.js +341 -0
- package/dist/shared/@ai-setting/roy-agent-core-fvd9g6k8.js +1205 -0
- package/dist/shared/@ai-setting/roy-agent-core-gv1hrn3x.js +378 -0
- package/dist/shared/@ai-setting/roy-agent-core-gy0wp5h7.js +213 -0
- package/dist/shared/{chunk-mf5xqbdh.js → @ai-setting/roy-agent-core-hyza1gm7.js} +3 -2
- package/dist/shared/{chunk-1qwabsm0.js → @ai-setting/roy-agent-core-j8zx62zr.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-jb2exr0d.js +442 -0
- package/dist/shared/@ai-setting/roy-agent-core-jv3b7v9w.js +57 -0
- package/dist/shared/@ai-setting/roy-agent-core-k1rxf9ya.js +513 -0
- package/dist/shared/@ai-setting/roy-agent-core-kydc9nwb.js +60 -0
- package/dist/shared/@ai-setting/roy-agent-core-m2x48hw6.js +97 -0
- package/dist/shared/@ai-setting/roy-agent-core-m6y668cc.js +377 -0
- package/dist/shared/{chunk-1aakcfp1.js → @ai-setting/roy-agent-core-nczzf0ms.js} +3 -3
- package/dist/shared/@ai-setting/roy-agent-core-nfj6knp5.js +36 -0
- package/dist/shared/@ai-setting/roy-agent-core-ntrp979d.js +204 -0
- package/dist/shared/@ai-setting/roy-agent-core-pd7g8z5v.js +1387 -0
- package/dist/shared/@ai-setting/roy-agent-core-pzk1syce.js +14 -0
- package/dist/shared/@ai-setting/roy-agent-core-q50tg9m2.js +862 -0
- package/dist/shared/{chunk-9qzt1v1p.js → @ai-setting/roy-agent-core-qg9tcaph.js} +3 -2
- package/dist/shared/{chunk-91bas8w5.js → @ai-setting/roy-agent-core-qhyerewk.js} +5 -5
- package/dist/shared/{chunk-1pf5mfgd.js → @ai-setting/roy-agent-core-qxybm159.js} +3 -3
- package/dist/shared/{chunk-g6j5n3gv.js → @ai-setting/roy-agent-core-rh9dpkpw.js} +10 -10
- package/dist/shared/{chunk-0q6s9wm6.js → @ai-setting/roy-agent-core-rr9p1g43.js} +7 -51
- package/dist/shared/@ai-setting/roy-agent-core-sbzvpfn7.js +284 -0
- package/dist/shared/@ai-setting/roy-agent-core-t22nqt4d.js +788 -0
- package/dist/shared/{chunk-t1rh6jtm.js → @ai-setting/roy-agent-core-tkr5ynkh.js} +8 -13
- package/dist/shared/@ai-setting/roy-agent-core-v4aabsf0.js +303 -0
- package/dist/shared/@ai-setting/roy-agent-core-w75rafhy.js +202 -0
- package/dist/shared/@ai-setting/roy-agent-core-w76hqkmg.js +584 -0
- package/dist/shared/@ai-setting/roy-agent-core-yfbgwes2.js +408 -0
- package/dist/shared/{chunk-a9qmy3sc.js → @ai-setting/roy-agent-core-yn761yve.js} +7 -4
- package/dist/shared/@ai-setting/roy-agent-core-yrzmn4m1.js +492 -0
- package/dist/shared/@ai-setting/roy-agent-core-yt8wdh2w.js +206 -0
- package/package.json +8 -7
- package/dist/index.d.ts +0 -7825
- package/dist/index.js +0 -16551
- package/dist/shared/chunk-hs7tbmje.js +0 -24
- /package/dist/shared/{chunk-wbkh7wat.js → @ai-setting/roy-agent-core-fs0mn2jk.js} +0 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
// packages/core/src/env/task/tools/task-types.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var CreateTaskToolSchema = z.object({
|
|
4
|
+
title: z.string().describe("Task title"),
|
|
5
|
+
description: z.string().optional().describe("Task description"),
|
|
6
|
+
priority: z.enum(["low", "medium", "high"]).optional().describe("Task priority"),
|
|
7
|
+
goals_and_expected_deliverables: z.string().optional().describe("Goals and expected deliverables"),
|
|
8
|
+
due_date: z.string().optional().describe("Due date (ISO format)"),
|
|
9
|
+
tags: z.array(z.string()).optional().describe("Task tags (for search, stored in task.tags JSON field)")
|
|
10
|
+
});
|
|
11
|
+
var GetTaskToolSchema = z.object({
|
|
12
|
+
task_id: z.number().describe("Task ID"),
|
|
13
|
+
include_operations: z.boolean().optional().default(false).describe("Include operation records")
|
|
14
|
+
});
|
|
15
|
+
var ListTasksToolSchema = z.object({
|
|
16
|
+
status: z.enum(["todo", "active", "completed", "paused", "cancelled"]).optional(),
|
|
17
|
+
priority: z.enum(["low", "medium", "high"]).optional(),
|
|
18
|
+
limit: z.number().optional().default(20),
|
|
19
|
+
offset: z.number().optional().default(0)
|
|
20
|
+
});
|
|
21
|
+
var UpdateTaskToolSchema = z.object({
|
|
22
|
+
task_id: z.number().describe("Task ID"),
|
|
23
|
+
title: z.string().optional(),
|
|
24
|
+
description: z.string().optional(),
|
|
25
|
+
status: z.enum(["todo", "active", "completed", "paused", "cancelled"]).optional(),
|
|
26
|
+
priority: z.enum(["low", "medium", "high"]).optional(),
|
|
27
|
+
progress: z.number().min(0).max(100).optional(),
|
|
28
|
+
current_status: z.string().optional(),
|
|
29
|
+
goals_and_expected_deliverables: z.string().optional(),
|
|
30
|
+
due_date: z.string().optional(),
|
|
31
|
+
tags: z.array(z.string()).optional()
|
|
32
|
+
});
|
|
33
|
+
var DeleteTaskToolSchema = z.object({
|
|
34
|
+
task_id: z.number().describe("Task ID")
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// packages/core/src/env/task/tools/create-tool.ts
|
|
38
|
+
function createTaskTool(taskComponent) {
|
|
39
|
+
return {
|
|
40
|
+
name: "task_create",
|
|
41
|
+
description: "Create a new task. The task will be associated with the current session.",
|
|
42
|
+
parameters: CreateTaskToolSchema,
|
|
43
|
+
execute: async (args, ctx) => {
|
|
44
|
+
const params = CreateTaskToolSchema.parse(args);
|
|
45
|
+
const sessionId = ctx.session_id || "unknown";
|
|
46
|
+
try {
|
|
47
|
+
const task = await taskComponent.createTask({
|
|
48
|
+
title: params.title,
|
|
49
|
+
description: params.description,
|
|
50
|
+
priority: params.priority,
|
|
51
|
+
goals_and_expected_deliverables: params.goals_and_expected_deliverables,
|
|
52
|
+
due_date: params.due_date,
|
|
53
|
+
tags: params.tags,
|
|
54
|
+
sessionId
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
success: true,
|
|
58
|
+
output: `Task created successfully: #${task.id} - ${task.title}`,
|
|
59
|
+
metadata: {
|
|
60
|
+
execution_time_ms: 0,
|
|
61
|
+
task_id: task.id,
|
|
62
|
+
status: task.status,
|
|
63
|
+
createdAt: task.createdAt
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
} catch (error) {
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
output: "",
|
|
70
|
+
error: error instanceof Error ? error.message : String(error),
|
|
71
|
+
metadata: { execution_time_ms: 0 }
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// packages/core/src/env/task/tools/get-tool.ts
|
|
78
|
+
function getTaskTool(taskComponent) {
|
|
79
|
+
return {
|
|
80
|
+
name: "task_get",
|
|
81
|
+
description: "Get task details by ID. Optionally include operation records.",
|
|
82
|
+
parameters: GetTaskToolSchema,
|
|
83
|
+
execute: async (args, ctx) => {
|
|
84
|
+
const params = GetTaskToolSchema.parse(args);
|
|
85
|
+
try {
|
|
86
|
+
if (params.include_operations) {
|
|
87
|
+
const result = await taskComponent.getTaskWithOperations(params.task_id);
|
|
88
|
+
if (!result) {
|
|
89
|
+
return {
|
|
90
|
+
success: false,
|
|
91
|
+
output: "",
|
|
92
|
+
error: `Task not found: ${params.task_id}`,
|
|
93
|
+
metadata: { execution_time_ms: 0 }
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
success: true,
|
|
98
|
+
output: JSON.stringify(result, null, 2),
|
|
99
|
+
metadata: { execution_time_ms: 0 }
|
|
100
|
+
};
|
|
101
|
+
} else {
|
|
102
|
+
const task = await taskComponent.getTask(params.task_id);
|
|
103
|
+
if (!task) {
|
|
104
|
+
return {
|
|
105
|
+
success: false,
|
|
106
|
+
output: "",
|
|
107
|
+
error: `Task not found: ${params.task_id}`,
|
|
108
|
+
metadata: { execution_time_ms: 0 }
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
success: true,
|
|
113
|
+
output: JSON.stringify(task, null, 2),
|
|
114
|
+
metadata: { execution_time_ms: 0 }
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
return {
|
|
119
|
+
success: false,
|
|
120
|
+
output: "",
|
|
121
|
+
error: error instanceof Error ? error.message : String(error),
|
|
122
|
+
metadata: { execution_time_ms: 0 }
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
// packages/core/src/env/task/tools/list-tool.ts
|
|
129
|
+
function listTasksTool(taskComponent) {
|
|
130
|
+
return {
|
|
131
|
+
name: "task_list",
|
|
132
|
+
description: "List tasks with optional filters for status and priority.",
|
|
133
|
+
parameters: ListTasksToolSchema,
|
|
134
|
+
execute: async (args, ctx) => {
|
|
135
|
+
const params = ListTasksToolSchema.parse(args);
|
|
136
|
+
try {
|
|
137
|
+
const tasks = await taskComponent.listTasks({
|
|
138
|
+
status: params.status,
|
|
139
|
+
priority: params.priority,
|
|
140
|
+
limit: params.limit,
|
|
141
|
+
offset: params.offset
|
|
142
|
+
});
|
|
143
|
+
return {
|
|
144
|
+
success: true,
|
|
145
|
+
output: JSON.stringify({ tasks, count: tasks.length }),
|
|
146
|
+
metadata: { execution_time_ms: 0 }
|
|
147
|
+
};
|
|
148
|
+
} catch (error) {
|
|
149
|
+
return {
|
|
150
|
+
success: false,
|
|
151
|
+
output: "",
|
|
152
|
+
error: error instanceof Error ? error.message : String(error),
|
|
153
|
+
metadata: { execution_time_ms: 0 }
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
// packages/core/src/env/task/tools/update-tool.ts
|
|
160
|
+
function updateTaskTool(taskComponent) {
|
|
161
|
+
return {
|
|
162
|
+
name: "task_update",
|
|
163
|
+
description: "Update an existing task's properties. Status and progress changes will create operation records.",
|
|
164
|
+
parameters: UpdateTaskToolSchema,
|
|
165
|
+
execute: async (args, ctx) => {
|
|
166
|
+
const params = UpdateTaskToolSchema.parse(args);
|
|
167
|
+
const sessionId = ctx.session_id || "unknown";
|
|
168
|
+
try {
|
|
169
|
+
const task = await taskComponent.updateTask(params.task_id, {
|
|
170
|
+
title: params.title,
|
|
171
|
+
description: params.description,
|
|
172
|
+
status: params.status,
|
|
173
|
+
priority: params.priority,
|
|
174
|
+
progress: params.progress,
|
|
175
|
+
current_status: params.current_status,
|
|
176
|
+
goals_and_expected_deliverables: params.goals_and_expected_deliverables,
|
|
177
|
+
due_date: params.due_date,
|
|
178
|
+
tags: params.tags
|
|
179
|
+
});
|
|
180
|
+
if (!task) {
|
|
181
|
+
return {
|
|
182
|
+
success: false,
|
|
183
|
+
output: "",
|
|
184
|
+
error: `Task not found: ${params.task_id}`,
|
|
185
|
+
metadata: { execution_time_ms: 0 }
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
if (params.status || params.progress !== undefined || params.current_status) {
|
|
189
|
+
await taskComponent.createOperation({
|
|
190
|
+
taskId: params.task_id,
|
|
191
|
+
sessionId,
|
|
192
|
+
actionType: "progress",
|
|
193
|
+
actionTitle: params.current_status || `Updated: ${params.status || `${params.progress}%`}`,
|
|
194
|
+
actionDescription: JSON.stringify({
|
|
195
|
+
status: params.status,
|
|
196
|
+
progress: params.progress,
|
|
197
|
+
current_status: params.current_status
|
|
198
|
+
})
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
success: true,
|
|
203
|
+
output: `Task updated: #${task.id} - ${task.title}`,
|
|
204
|
+
metadata: { execution_time_ms: 0, task }
|
|
205
|
+
};
|
|
206
|
+
} catch (error) {
|
|
207
|
+
return {
|
|
208
|
+
success: false,
|
|
209
|
+
output: "",
|
|
210
|
+
error: error instanceof Error ? error.message : String(error),
|
|
211
|
+
metadata: { execution_time_ms: 0 }
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
// packages/core/src/env/task/tools/delete-tool.ts
|
|
218
|
+
function deleteTaskTool(taskComponent) {
|
|
219
|
+
return {
|
|
220
|
+
name: "task_delete",
|
|
221
|
+
description: "Delete a task and all its operation records.",
|
|
222
|
+
parameters: DeleteTaskToolSchema,
|
|
223
|
+
execute: async (args, ctx) => {
|
|
224
|
+
const params = DeleteTaskToolSchema.parse(args);
|
|
225
|
+
try {
|
|
226
|
+
const deleted = await taskComponent.deleteTask(params.task_id);
|
|
227
|
+
if (!deleted) {
|
|
228
|
+
return {
|
|
229
|
+
success: false,
|
|
230
|
+
output: "",
|
|
231
|
+
error: `Task not found: ${params.task_id}`,
|
|
232
|
+
metadata: { execution_time_ms: 0 }
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
success: true,
|
|
237
|
+
output: `Task deleted: #${params.task_id}`,
|
|
238
|
+
metadata: { execution_time_ms: 0 }
|
|
239
|
+
};
|
|
240
|
+
} catch (error) {
|
|
241
|
+
return {
|
|
242
|
+
success: false,
|
|
243
|
+
output: "",
|
|
244
|
+
error: error instanceof Error ? error.message : String(error),
|
|
245
|
+
metadata: { execution_time_ms: 0 }
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
// packages/core/src/env/task/tools/complete-tool.ts
|
|
252
|
+
function completeTaskTool(taskComponent) {
|
|
253
|
+
return {
|
|
254
|
+
name: "task_complete",
|
|
255
|
+
description: "Mark a task as completed (progress=100, status=completed). Creates an operation record.",
|
|
256
|
+
parameters: DeleteTaskToolSchema,
|
|
257
|
+
execute: async (args, ctx) => {
|
|
258
|
+
const params = DeleteTaskToolSchema.parse(args);
|
|
259
|
+
const sessionId = ctx.session_id || "unknown";
|
|
260
|
+
try {
|
|
261
|
+
const task = await taskComponent.completeTask(params.task_id, sessionId);
|
|
262
|
+
if (!task) {
|
|
263
|
+
return {
|
|
264
|
+
success: false,
|
|
265
|
+
output: "",
|
|
266
|
+
error: `Task not found: ${params.task_id}`,
|
|
267
|
+
metadata: { execution_time_ms: 0 }
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
success: true,
|
|
272
|
+
output: `Task completed: #${task.id} - ${task.title}`,
|
|
273
|
+
metadata: { execution_time_ms: 0, task }
|
|
274
|
+
};
|
|
275
|
+
} catch (error) {
|
|
276
|
+
return {
|
|
277
|
+
success: false,
|
|
278
|
+
output: "",
|
|
279
|
+
error: error instanceof Error ? error.message : String(error),
|
|
280
|
+
metadata: { execution_time_ms: 0 }
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
export { createTaskTool, getTaskTool, listTasksTool, updateTaskTool, deleteTaskTool, completeTaskTool };
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import {
|
|
2
|
+
envKeyToConfigKey
|
|
3
|
+
} from "./roy-agent-core-jv3b7v9w.js";
|
|
4
|
+
import {
|
|
5
|
+
BaseComponent
|
|
6
|
+
} from "./roy-agent-core-m2x48hw6.js";
|
|
7
|
+
import {
|
|
8
|
+
createMemoryTools
|
|
9
|
+
} from "./roy-agent-core-8mbmrwzs.js";
|
|
10
|
+
import {
|
|
11
|
+
createLogger,
|
|
12
|
+
init_logger
|
|
13
|
+
} from "./roy-agent-core-yn761yve.js";
|
|
14
|
+
|
|
15
|
+
// packages/core/src/env/memory/types.ts
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
var RecordMemorySchema = z.object({
|
|
18
|
+
scope: z.enum(["project", "global"]).describe("作用域: project/global"),
|
|
19
|
+
mode: z.enum(["append", "prepend", "overwrite", "delete"]).describe("模式: append(追加)/prepend(插入)/overwrite(覆盖)/delete(删除)"),
|
|
20
|
+
content: z.string().optional().describe("记忆内容"),
|
|
21
|
+
title: z.string().optional().describe("章节标题")
|
|
22
|
+
});
|
|
23
|
+
var RecallMemorySchema = z.object({
|
|
24
|
+
scope: z.enum(["project", "global"]).optional().describe("作用域(可选,不传则读取所有)")
|
|
25
|
+
});
|
|
26
|
+
// packages/core/src/env/memory/memory-config.ts
|
|
27
|
+
import path from "path";
|
|
28
|
+
import os from "os";
|
|
29
|
+
var DEFAULT_MEMORY_CONFIG = {
|
|
30
|
+
memoryPaths: [
|
|
31
|
+
{
|
|
32
|
+
type: "global",
|
|
33
|
+
path: path.join(os.homedir(), ".config", "roy-agent", "memory")
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: "project",
|
|
37
|
+
path: ".roy/memory"
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
recursive: true,
|
|
41
|
+
cacheEnabled: true,
|
|
42
|
+
cacheTTL: 5 * 60 * 1000
|
|
43
|
+
};
|
|
44
|
+
var SOURCE_PRIORITY = {
|
|
45
|
+
global: 0,
|
|
46
|
+
project: 1
|
|
47
|
+
};
|
|
48
|
+
function getSourcePriority(source) {
|
|
49
|
+
return SOURCE_PRIORITY[source] ?? 0;
|
|
50
|
+
}
|
|
51
|
+
// packages/core/src/env/memory/memory-component.ts
|
|
52
|
+
init_logger();
|
|
53
|
+
|
|
54
|
+
// packages/core/src/env/memory/memory-config-registration.ts
|
|
55
|
+
import path2 from "path";
|
|
56
|
+
import os2 from "os";
|
|
57
|
+
var MEMORY_DEFAULTS = {
|
|
58
|
+
"memory.recursive": true,
|
|
59
|
+
"memory.cacheEnabled": true,
|
|
60
|
+
"memory.cacheTTL": 300000,
|
|
61
|
+
"memory.memoryFile": "memory.md",
|
|
62
|
+
"memory.memoryPaths": [
|
|
63
|
+
{ type: "global", path: path2.join(os2.homedir(), ".config", "roy-agent", "memory") },
|
|
64
|
+
{ type: "project", path: ".roy/memory" }
|
|
65
|
+
]
|
|
66
|
+
};
|
|
67
|
+
var MEMORY_CONFIG_REGISTRATION = {
|
|
68
|
+
name: "memory",
|
|
69
|
+
sources: [
|
|
70
|
+
{ type: "env", envPrefix: "MEMORY", priority: 20, watch: false }
|
|
71
|
+
],
|
|
72
|
+
keys: [
|
|
73
|
+
{ key: "memory.recursive", sources: ["env", "file"] },
|
|
74
|
+
{ key: "memory.cacheEnabled", sources: ["env", "file"] },
|
|
75
|
+
{ key: "memory.cacheTTL", sources: ["env", "file"] },
|
|
76
|
+
{ key: "memory.memoryPaths", sources: ["env", "file"] },
|
|
77
|
+
{ key: "memory.memoryFile", sources: ["env", "file"] }
|
|
78
|
+
]
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// packages/core/src/env/memory/memory-component.ts
|
|
82
|
+
import path3 from "path";
|
|
83
|
+
import fs from "fs/promises";
|
|
84
|
+
var logger = createLogger("memory");
|
|
85
|
+
|
|
86
|
+
class MemoryComponent extends BaseComponent {
|
|
87
|
+
name = "memory";
|
|
88
|
+
version = "2.0.0";
|
|
89
|
+
config;
|
|
90
|
+
toolComponent;
|
|
91
|
+
configComponent;
|
|
92
|
+
cache = new Map;
|
|
93
|
+
configWatcher;
|
|
94
|
+
async init(config) {
|
|
95
|
+
await super.init(config);
|
|
96
|
+
const options = config?.options;
|
|
97
|
+
if (!options?.configComponent) {
|
|
98
|
+
throw new Error("ConfigComponent is required for MemoryComponent initialization");
|
|
99
|
+
}
|
|
100
|
+
this.configComponent = options.configComponent;
|
|
101
|
+
await this.registerConfig(options);
|
|
102
|
+
logger.info("[MemoryComponent] Initialized (simplified)");
|
|
103
|
+
}
|
|
104
|
+
async registerConfig(options) {
|
|
105
|
+
const configComponent = this.configComponent;
|
|
106
|
+
if (!configComponent)
|
|
107
|
+
return;
|
|
108
|
+
const { configPath, envPrefix, config } = options;
|
|
109
|
+
const prefix = envPrefix ?? "MEMORY";
|
|
110
|
+
configComponent.registerComponent(MEMORY_CONFIG_REGISTRATION);
|
|
111
|
+
if (configPath) {
|
|
112
|
+
configComponent.registerSource({
|
|
113
|
+
type: "file",
|
|
114
|
+
relativePath: configPath,
|
|
115
|
+
optional: true,
|
|
116
|
+
watch: false
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
configComponent.registerSource({
|
|
120
|
+
type: "env",
|
|
121
|
+
envPrefix: prefix,
|
|
122
|
+
priority: 20,
|
|
123
|
+
watch: false
|
|
124
|
+
});
|
|
125
|
+
await configComponent.load("memory");
|
|
126
|
+
for (const envKey of Object.keys(process.env)) {
|
|
127
|
+
const configKey = envKeyToConfigKey(envKey, prefix, "memory");
|
|
128
|
+
if (!configKey)
|
|
129
|
+
continue;
|
|
130
|
+
const value = process.env[envKey];
|
|
131
|
+
if (value !== undefined) {
|
|
132
|
+
await configComponent.set(configKey, value);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
for (const [key, value] of Object.entries(MEMORY_DEFAULTS)) {
|
|
136
|
+
if (configComponent.get(key) === undefined) {
|
|
137
|
+
await configComponent.set(key, value);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (config) {
|
|
141
|
+
const flatConfig = this.flattenConfig(config);
|
|
142
|
+
for (const [key, value] of Object.entries(flatConfig)) {
|
|
143
|
+
await configComponent.set(key, value);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
this.registerConfigWatcher(configComponent);
|
|
147
|
+
this.buildConfig(configComponent);
|
|
148
|
+
}
|
|
149
|
+
buildConfig(configComponent) {
|
|
150
|
+
const recursive = configComponent.get("memory.recursive") ?? true;
|
|
151
|
+
const cacheEnabled = configComponent.get("memory.cacheEnabled") ?? true;
|
|
152
|
+
const cacheTTL = configComponent.get("memory.cacheTTL") ?? 300000;
|
|
153
|
+
const memoryFile = configComponent.get("memory.memoryFile") ?? "memory.md";
|
|
154
|
+
const memoryPathsConfig = configComponent.get("memory.memoryPaths");
|
|
155
|
+
let memoryPaths = [];
|
|
156
|
+
if (Array.isArray(memoryPathsConfig)) {
|
|
157
|
+
memoryPaths = memoryPathsConfig;
|
|
158
|
+
} else if (typeof memoryPathsConfig === "string") {
|
|
159
|
+
try {
|
|
160
|
+
memoryPaths = JSON.parse(memoryPathsConfig);
|
|
161
|
+
} catch {
|
|
162
|
+
memoryPaths = DEFAULT_MEMORY_CONFIG.memoryPaths;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (memoryPaths.length === 0) {
|
|
166
|
+
memoryPaths = DEFAULT_MEMORY_CONFIG.memoryPaths;
|
|
167
|
+
}
|
|
168
|
+
this.config = {
|
|
169
|
+
memoryPaths,
|
|
170
|
+
recursive,
|
|
171
|
+
cacheEnabled,
|
|
172
|
+
cacheTTL,
|
|
173
|
+
memoryFile
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
flattenConfig(obj, prefix = "memory") {
|
|
177
|
+
const result = {};
|
|
178
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
179
|
+
const fullKey = `${prefix}.${key}`;
|
|
180
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
181
|
+
Object.assign(result, this.flattenConfig(value, fullKey));
|
|
182
|
+
} else {
|
|
183
|
+
result[fullKey] = value;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
registerConfigWatcher(configComponent) {
|
|
189
|
+
if (typeof configComponent.watch !== "function") {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
this.configWatcher = configComponent.watch("memory.*", (event) => {
|
|
193
|
+
this.onConfigChange(event);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
onConfigChange(event) {
|
|
197
|
+
logger.info(`[MemoryComponent] Config changed: ${event.key}`, {
|
|
198
|
+
oldValue: event.oldValue,
|
|
199
|
+
newValue: event.newValue
|
|
200
|
+
});
|
|
201
|
+
if (this.configComponent) {
|
|
202
|
+
this.buildConfig(this.configComponent);
|
|
203
|
+
}
|
|
204
|
+
this.cache.clear();
|
|
205
|
+
}
|
|
206
|
+
async start() {
|
|
207
|
+
await super.start();
|
|
208
|
+
this.toolComponent = this.env?.getComponent("tool");
|
|
209
|
+
if (!this.toolComponent) {
|
|
210
|
+
logger.warn("[MemoryComponent] ToolComponent not found, skipping tool registration");
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
await this.registerTools();
|
|
214
|
+
this.setStatus("running");
|
|
215
|
+
logger.info(`[MemoryComponent] Started with ${this.toolComponent.getToolCount()} tools`);
|
|
216
|
+
}
|
|
217
|
+
async stop() {
|
|
218
|
+
if (this.configWatcher) {
|
|
219
|
+
this.configWatcher();
|
|
220
|
+
this.configWatcher = undefined;
|
|
221
|
+
}
|
|
222
|
+
if (this.toolComponent) {
|
|
223
|
+
this.toolComponent.unregister("record_memory");
|
|
224
|
+
this.toolComponent.unregister("recall_memory");
|
|
225
|
+
}
|
|
226
|
+
this.cache.clear();
|
|
227
|
+
await super.stop();
|
|
228
|
+
logger.info("[MemoryComponent] Stopped");
|
|
229
|
+
}
|
|
230
|
+
async registerTools() {
|
|
231
|
+
if (!this.toolComponent)
|
|
232
|
+
return;
|
|
233
|
+
const tools = createMemoryTools((args) => this.recordMemory(args), (scope) => this.recallMemory(scope), {
|
|
234
|
+
getMemoryPaths: () => this.getMemoryPaths(),
|
|
235
|
+
getMemoryFile: () => this.getMemoryFile()
|
|
236
|
+
});
|
|
237
|
+
for (const tool of tools) {
|
|
238
|
+
this.toolComponent.register(tool);
|
|
239
|
+
}
|
|
240
|
+
logger.info("[MemoryComponent] Registered memory tools");
|
|
241
|
+
}
|
|
242
|
+
getMemoryPaths() {
|
|
243
|
+
return this.config.memoryPaths;
|
|
244
|
+
}
|
|
245
|
+
updateMemoryPaths(paths) {
|
|
246
|
+
this.config.memoryPaths = paths;
|
|
247
|
+
this.clearCache();
|
|
248
|
+
}
|
|
249
|
+
getMemoryFile() {
|
|
250
|
+
return this.config.memoryFile ?? "memory.md";
|
|
251
|
+
}
|
|
252
|
+
async recordMemory(args) {
|
|
253
|
+
const { mode, content, title, filename, scope } = args;
|
|
254
|
+
const memoryFile = filename ?? this.getMemoryFile();
|
|
255
|
+
const paths = this.config.memoryPaths;
|
|
256
|
+
if (paths.length === 0) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
let basePath;
|
|
260
|
+
if (scope) {
|
|
261
|
+
const targetPath = paths.find((p) => p.type === scope);
|
|
262
|
+
if (!targetPath) {
|
|
263
|
+
logger.warn(`[recordMemory] No ${scope} path configured, using first available path`);
|
|
264
|
+
basePath = paths[0].path;
|
|
265
|
+
} else {
|
|
266
|
+
basePath = targetPath.path;
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
basePath = paths[0].path;
|
|
270
|
+
}
|
|
271
|
+
const filePath = path3.join(basePath, memoryFile);
|
|
272
|
+
try {
|
|
273
|
+
let existingContent = "";
|
|
274
|
+
let fileExists = false;
|
|
275
|
+
try {
|
|
276
|
+
existingContent = await fs.readFile(filePath, "utf-8");
|
|
277
|
+
fileExists = true;
|
|
278
|
+
} catch {}
|
|
279
|
+
let newContent;
|
|
280
|
+
let action;
|
|
281
|
+
switch (mode) {
|
|
282
|
+
case "delete":
|
|
283
|
+
if (fileExists) {
|
|
284
|
+
await fs.unlink(filePath);
|
|
285
|
+
this.clearCache();
|
|
286
|
+
return { path: filePath, action: "delete" };
|
|
287
|
+
}
|
|
288
|
+
return null;
|
|
289
|
+
case "overwrite":
|
|
290
|
+
if (title && content) {
|
|
291
|
+
newContent = `## ${title}
|
|
292
|
+
|
|
293
|
+
${content}
|
|
294
|
+
`;
|
|
295
|
+
} else {
|
|
296
|
+
newContent = content ?? "";
|
|
297
|
+
}
|
|
298
|
+
action = fileExists ? "overwrite" : "created";
|
|
299
|
+
break;
|
|
300
|
+
case "append":
|
|
301
|
+
if (!content) {
|
|
302
|
+
throw new Error("content is required for append mode");
|
|
303
|
+
}
|
|
304
|
+
if (title) {
|
|
305
|
+
newContent = existingContent + `
|
|
306
|
+
## ${title}
|
|
307
|
+
|
|
308
|
+
${content}
|
|
309
|
+
`;
|
|
310
|
+
} else {
|
|
311
|
+
newContent = existingContent + `
|
|
312
|
+
${content}
|
|
313
|
+
`;
|
|
314
|
+
}
|
|
315
|
+
action = fileExists ? "append" : "created";
|
|
316
|
+
break;
|
|
317
|
+
case "prepend":
|
|
318
|
+
if (!content) {
|
|
319
|
+
throw new Error("content is required for prepend mode");
|
|
320
|
+
}
|
|
321
|
+
if (title) {
|
|
322
|
+
newContent = `## ${title}
|
|
323
|
+
|
|
324
|
+
${content}
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
${existingContent}`;
|
|
329
|
+
} else {
|
|
330
|
+
newContent = `${content}
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
${existingContent}`;
|
|
335
|
+
}
|
|
336
|
+
action = fileExists ? "prepend" : "created";
|
|
337
|
+
break;
|
|
338
|
+
default:
|
|
339
|
+
throw new Error(`Unknown mode: ${mode}`);
|
|
340
|
+
}
|
|
341
|
+
await fs.mkdir(basePath, { recursive: true });
|
|
342
|
+
await fs.writeFile(filePath, newContent, "utf-8");
|
|
343
|
+
this.clearCache();
|
|
344
|
+
return { path: filePath, action };
|
|
345
|
+
} catch (error) {
|
|
346
|
+
logger.error(`[recordMemory] Failed: ${error}`);
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
async recallMemory(scope) {
|
|
351
|
+
const memoryFile = this.getMemoryFile();
|
|
352
|
+
const paths = this.config.memoryPaths;
|
|
353
|
+
const results = [];
|
|
354
|
+
for (const memoryPath of paths) {
|
|
355
|
+
if (scope && memoryPath.type !== scope) {
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
const filePath = path3.join(memoryPath.path, memoryFile);
|
|
359
|
+
try {
|
|
360
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
361
|
+
if (content.trim()) {
|
|
362
|
+
results.push(`## [${memoryPath.type}] ${memoryFile}
|
|
363
|
+
${content}`);
|
|
364
|
+
}
|
|
365
|
+
} catch {}
|
|
366
|
+
}
|
|
367
|
+
return results.join(`
|
|
368
|
+
|
|
369
|
+
`);
|
|
370
|
+
}
|
|
371
|
+
clearCache() {
|
|
372
|
+
this.cache.clear();
|
|
373
|
+
}
|
|
374
|
+
getCache(key) {
|
|
375
|
+
if (!this.config.cacheEnabled)
|
|
376
|
+
return;
|
|
377
|
+
const entry = this.cache.get(key);
|
|
378
|
+
if (!entry)
|
|
379
|
+
return;
|
|
380
|
+
const age = Date.now() - entry.timestamp;
|
|
381
|
+
if (age > (this.config.cacheTTL ?? 300000)) {
|
|
382
|
+
this.cache.delete(key);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
return entry.data;
|
|
386
|
+
}
|
|
387
|
+
setCache(key, data) {
|
|
388
|
+
if (!this.config.cacheEnabled)
|
|
389
|
+
return;
|
|
390
|
+
this.cache.set(key, { data, timestamp: Date.now() });
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
export { DEFAULT_MEMORY_CONFIG, SOURCE_PRIORITY, getSourcePriority, MemoryComponent };
|