@ai-setting/roy-agent-core 1.4.13 → 1.4.15
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/config/index.js +32 -0
- package/dist/env/agent/index.js +24 -0
- package/dist/env/commands/index.js +14 -0
- package/dist/env/debug/formatters/index.js +11 -0
- package/dist/env/debug/index.js +26 -0
- package/dist/env/hook/index.js +29 -0
- package/dist/env/index.js +81 -0
- package/dist/env/llm/index.js +40 -0
- package/dist/env/log-trace/index.js +83 -0
- package/dist/env/mcp/index.js +39 -0
- package/dist/env/mcp/tool/index.js +14 -0
- package/dist/env/memory/built-in/index.js +11 -0
- package/dist/env/memory/index.js +56 -0
- package/dist/env/memory/plugin/index.js +36 -0
- package/dist/env/prompt/index.js +20 -0
- package/dist/env/session/index.js +25 -0
- package/dist/env/session/storage/index.js +18 -0
- package/dist/env/skill/index.js +34 -0
- package/dist/env/skill/tool/index.js +9 -0
- package/dist/env/task/delegate/index.js +18 -0
- package/dist/env/task/hooks/index.js +7 -0
- package/dist/env/task/index.js +30 -0
- package/dist/env/task/plugins/index.js +23 -0
- package/dist/env/task/storage/index.js +14 -0
- package/dist/env/task/tools/index.js +17 -0
- package/dist/env/task/tools/operation/index.js +15 -0
- package/dist/{shared/chunk-1d4rwms4.js → env/tool/built-in/index.js} +4 -4
- package/dist/env/tool/index.js +39 -0
- package/dist/env/workflow/decorators/index.js +27 -0
- package/dist/env/workflow/engine/index.js +28 -0
- package/dist/env/workflow/index.js +132 -0
- package/dist/env/workflow/nodes/index.js +19 -0
- package/dist/env/workflow/service/index.js +13 -0
- package/dist/env/workflow/storage/index.js +27 -0
- package/dist/env/workflow/tools/index.js +159 -0
- package/dist/env/workflow/types/index.js +94 -0
- package/dist/env/workflow/utils/index.js +637 -0
- package/dist/index.js +233 -16386
- package/dist/shared/{chunk-2b5kbhx3.js → @ai-setting/roy-agent-core-0rtxwr28.js} +6 -114
- package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +36 -0
- package/dist/shared/@ai-setting/roy-agent-core-12zkpda2.js +393 -0
- package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +117 -0
- package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +11 -0
- package/dist/shared/@ai-setting/roy-agent-core-2kg2wma8.js +620 -0
- package/dist/shared/@ai-setting/roy-agent-core-2x0m2p66.js +851 -0
- package/dist/shared/@ai-setting/roy-agent-core-35x0wrtt.js +172 -0
- package/dist/shared/{chunk-1pf5mfgd.js → @ai-setting/roy-agent-core-37e4tep3.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-3agad0d9.js +603 -0
- package/dist/shared/@ai-setting/roy-agent-core-4arba14a.js +419 -0
- package/dist/shared/@ai-setting/roy-agent-core-4rqmfr7t.js +266 -0
- package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +206 -0
- package/dist/shared/@ai-setting/roy-agent-core-561b1c4p.js +377 -0
- package/dist/shared/@ai-setting/roy-agent-core-5xf65pz6.js +1305 -0
- package/dist/shared/@ai-setting/roy-agent-core-6a72jfdy.js +303 -0
- package/dist/shared/{chunk-1aakcfp1.js → @ai-setting/roy-agent-core-7f303ffd.js} +3 -3
- package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +284 -0
- package/dist/shared/{chunk-t1rh6jtm.js → @ai-setting/roy-agent-core-7n436rb4.js} +7 -12
- package/dist/shared/@ai-setting/roy-agent-core-7r85t0qn.js +492 -0
- package/dist/shared/@ai-setting/roy-agent-core-7rewcey6.js +862 -0
- package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +14 -0
- package/dist/shared/@ai-setting/roy-agent-core-9qwp5qkz.js +1387 -0
- package/dist/shared/{chunk-mf5xqbdh.js → @ai-setting/roy-agent-core-9yxb3ty9.js} +3 -2
- package/dist/shared/@ai-setting/roy-agent-core-anwsxdds.js +1205 -0
- package/dist/shared/{chunk-1qwabsm0.js → @ai-setting/roy-agent-core-bncgx3gb.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-cd00w5mb.js +762 -0
- package/dist/shared/@ai-setting/roy-agent-core-cgs0j60t.js +442 -0
- package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +93 -0
- package/dist/shared/@ai-setting/roy-agent-core-dbsk841j.js +286 -0
- package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +64 -0
- package/dist/shared/{chunk-yqmx37vm.js → @ai-setting/roy-agent-core-e5jcp24a.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-e62e2a5a.js +204 -0
- package/dist/shared/{chunk-g6j5n3gv.js → @ai-setting/roy-agent-core-ewrj1c4k.js} +2 -2
- package/dist/shared/{chunk-rncy3rtd.js → @ai-setting/roy-agent-core-fdb6m4e4.js} +119 -1113
- package/dist/shared/{chunk-q9j99fsm.js → @ai-setting/roy-agent-core-fv32jaa8.js} +3 -3
- package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +171 -0
- package/dist/shared/@ai-setting/roy-agent-core-gmnkza34.js +202 -0
- package/dist/shared/@ai-setting/roy-agent-core-hz7rr4yx.js +513 -0
- package/dist/shared/@ai-setting/roy-agent-core-j3bbr2n0.js +378 -0
- package/dist/shared/{chunk-a9qmy3sc.js → @ai-setting/roy-agent-core-j3wc4465.js} +6 -3
- package/dist/shared/@ai-setting/roy-agent-core-jj79gszx.js +1130 -0
- package/dist/shared/@ai-setting/roy-agent-core-mwwk6req.js +913 -0
- package/dist/shared/{chunk-0q6s9wm6.js → @ai-setting/roy-agent-core-pc9g3962.js} +6 -50
- package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +60 -0
- package/dist/shared/@ai-setting/roy-agent-core-pzsg9pvf.js +393 -0
- package/dist/shared/{chunk-91bas8w5.js → @ai-setting/roy-agent-core-q779wnwm.js} +5 -5
- package/dist/shared/{chunk-25x2pdtp.js → @ai-setting/roy-agent-core-qw0ebh1d.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +57 -0
- package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +66 -0
- package/dist/shared/@ai-setting/roy-agent-core-qya7seh6.js +408 -0
- package/dist/shared/@ai-setting/roy-agent-core-rbetrphj.js +97 -0
- package/dist/shared/@ai-setting/roy-agent-core-re1wjfw7.js +587 -0
- package/dist/shared/@ai-setting/roy-agent-core-rft3fmp0.js +14 -0
- package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +584 -0
- package/dist/shared/{chunk-ze20rksg.js → @ai-setting/roy-agent-core-rvxg1wps.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-rzp9kxne.js +341 -0
- package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +213 -0
- package/dist/shared/@ai-setting/roy-agent-core-w78syn7w.js +788 -0
- package/dist/shared/{chunk-9qzt1v1p.js → @ai-setting/roy-agent-core-z2t8hse8.js} +3 -2
- package/package.json +8 -7
- package/dist/index.d.ts +0 -7825
- package/dist/shared/chunk-hs7tbmje.js +0 -24
- /package/dist/shared/{chunk-wbkh7wat.js → @ai-setting/roy-agent-core-fs0mn2jk.js} +0 -0
|
@@ -1,54 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AskUserError,
|
|
3
|
+
init_workflow_hil
|
|
4
|
+
} from "./roy-agent-core-e25xkv53.js";
|
|
1
5
|
import {
|
|
2
6
|
__esm
|
|
3
|
-
} from "./
|
|
4
|
-
|
|
5
|
-
// src/env/workflow/types/workflow-hil.ts
|
|
6
|
-
function createNodeInterruptEvent(runId, nodeId, nodeType, query, agentSessionId) {
|
|
7
|
-
return {
|
|
8
|
-
type: "node.interrupt",
|
|
9
|
-
run_id: runId,
|
|
10
|
-
timestamp: Date.now(),
|
|
11
|
-
node_id: nodeId,
|
|
12
|
-
node_type: nodeType,
|
|
13
|
-
query,
|
|
14
|
-
...agentSessionId ? { agent_session_id: agentSessionId } : {}
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
var AskUserError;
|
|
18
|
-
var init_workflow_hil = __esm(() => {
|
|
19
|
-
AskUserError = class AskUserError extends Error {
|
|
20
|
-
runId;
|
|
21
|
-
sessionId;
|
|
22
|
-
nodeId;
|
|
23
|
-
nodeType;
|
|
24
|
-
query;
|
|
25
|
-
agentSessionId;
|
|
26
|
-
timestamp;
|
|
27
|
-
type = "ask-user";
|
|
28
|
-
name = "AskUserError";
|
|
29
|
-
constructor(runId, sessionId, nodeId, nodeType, query, agentSessionId, timestamp = Date.now()) {
|
|
30
|
-
super(`[${nodeType}:${nodeId}] Ask user: ${query}`);
|
|
31
|
-
this.runId = runId;
|
|
32
|
-
this.sessionId = sessionId;
|
|
33
|
-
this.nodeId = nodeId;
|
|
34
|
-
this.nodeType = nodeType;
|
|
35
|
-
this.query = query;
|
|
36
|
-
this.agentSessionId = agentSessionId;
|
|
37
|
-
this.timestamp = timestamp;
|
|
38
|
-
}
|
|
39
|
-
toEvent() {
|
|
40
|
-
return {
|
|
41
|
-
type: "workflow.ask-user",
|
|
42
|
-
run_id: this.runId,
|
|
43
|
-
timestamp: this.timestamp,
|
|
44
|
-
session_id: this.sessionId,
|
|
45
|
-
node_id: this.nodeId,
|
|
46
|
-
node_type: this.nodeType,
|
|
47
|
-
query: this.query
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
});
|
|
7
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
52
8
|
|
|
53
9
|
// src/env/workflow/nodes/agent-component-adapter.ts
|
|
54
10
|
class AgentComponentAdapter {
|
|
@@ -246,4 +202,4 @@ var init_agent_component_adapter = __esm(() => {
|
|
|
246
202
|
init_workflow_hil();
|
|
247
203
|
});
|
|
248
204
|
|
|
249
|
-
export {
|
|
205
|
+
export { AgentComponentAdapter, init_agent_component_adapter };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/env/skill/types.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var SkillToolSchema = z.object({
|
|
4
|
+
skill: z.string().describe("Skill name to load")
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
// src/env/skill/tool/skill-tool.ts
|
|
8
|
+
function buildSkillDescription(items) {
|
|
9
|
+
const lines = [
|
|
10
|
+
"Load a skill by name. Available skills:",
|
|
11
|
+
"",
|
|
12
|
+
"## Available Skills",
|
|
13
|
+
""
|
|
14
|
+
];
|
|
15
|
+
if (items.length === 0) {
|
|
16
|
+
lines.push("No skills available.");
|
|
17
|
+
} else {
|
|
18
|
+
for (const item of items) {
|
|
19
|
+
lines.push(`- **${item.name}**: "${item.description}"`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
lines.push("");
|
|
23
|
+
lines.push("Use the 'skill' parameter to specify which skill to load.");
|
|
24
|
+
return lines.join(`
|
|
25
|
+
`);
|
|
26
|
+
}
|
|
27
|
+
function createSkillTool(getSkillList, getSkill) {
|
|
28
|
+
return {
|
|
29
|
+
name: "skill",
|
|
30
|
+
description: buildSkillDescription(getSkillList()),
|
|
31
|
+
parameters: SkillToolSchema,
|
|
32
|
+
execute: async (args, ctx) => {
|
|
33
|
+
const params = SkillToolSchema.parse(args);
|
|
34
|
+
try {
|
|
35
|
+
const entry = getSkill(params.skill);
|
|
36
|
+
if (!entry) {
|
|
37
|
+
return {
|
|
38
|
+
success: false,
|
|
39
|
+
output: "",
|
|
40
|
+
error: `Skill not found: ${params.skill}`,
|
|
41
|
+
metadata: { execution_time_ms: 0 }
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
success: true,
|
|
46
|
+
output: entry.content,
|
|
47
|
+
metadata: { execution_time_ms: 0 }
|
|
48
|
+
};
|
|
49
|
+
} catch (error) {
|
|
50
|
+
return {
|
|
51
|
+
success: false,
|
|
52
|
+
output: "",
|
|
53
|
+
error: error instanceof Error ? error.message : String(error),
|
|
54
|
+
metadata: { execution_time_ms: 0 }
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export { SkillToolSchema, buildSkillDescription, createSkillTool };
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMemoryTools
|
|
3
|
+
} from "./roy-agent-core-g1s2h0e5.js";
|
|
4
|
+
import {
|
|
5
|
+
envKeyToConfigKey
|
|
6
|
+
} from "./roy-agent-core-qxhq8ven.js";
|
|
7
|
+
import {
|
|
8
|
+
BaseComponent
|
|
9
|
+
} from "./roy-agent-core-rbetrphj.js";
|
|
10
|
+
import {
|
|
11
|
+
createLogger,
|
|
12
|
+
init_logger
|
|
13
|
+
} from "./roy-agent-core-j3wc4465.js";
|
|
14
|
+
|
|
15
|
+
// 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
|
+
// 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
|
+
// src/env/memory/memory-component.ts
|
|
52
|
+
init_logger();
|
|
53
|
+
|
|
54
|
+
// 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
|
+
// 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 };
|
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
initDatabase,
|
|
6
6
|
initializeTables,
|
|
7
7
|
resetDatabase
|
|
8
|
-
} from "./
|
|
9
|
-
import"./
|
|
10
|
-
import"./
|
|
11
|
-
import"./
|
|
12
|
-
import"./
|
|
8
|
+
} from "./roy-agent-core-37e4tep3.js";
|
|
9
|
+
import"./roy-agent-core-j3wc4465.js";
|
|
10
|
+
import"./roy-agent-core-fv32jaa8.js";
|
|
11
|
+
import"./roy-agent-core-bncgx3gb.js";
|
|
12
|
+
import"./roy-agent-core-fs0mn2jk.js";
|
|
13
13
|
export {
|
|
14
14
|
resetDatabase,
|
|
15
15
|
initializeTables,
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/config/env-key.ts
|
|
2
|
+
function toEnvKey(key, prefix) {
|
|
3
|
+
let keyNormalized = key.replace(/[.-]/g, "_");
|
|
4
|
+
keyNormalized = keyNormalized.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/_+/g, "_").toUpperCase();
|
|
5
|
+
if (prefix) {
|
|
6
|
+
const separator = prefix.endsWith("_") ? "" : "_";
|
|
7
|
+
return `${prefix}${separator}${keyNormalized}`;
|
|
8
|
+
}
|
|
9
|
+
return keyNormalized;
|
|
10
|
+
}
|
|
11
|
+
function fromEnvKey(envKey, prefix) {
|
|
12
|
+
if (!prefix) {
|
|
13
|
+
return envKey;
|
|
14
|
+
}
|
|
15
|
+
if (envKey.startsWith(prefix)) {
|
|
16
|
+
const afterPrefix = envKey.slice(prefix.length);
|
|
17
|
+
if (afterPrefix.startsWith("_")) {
|
|
18
|
+
return afterPrefix.slice(1);
|
|
19
|
+
}
|
|
20
|
+
return afterPrefix;
|
|
21
|
+
}
|
|
22
|
+
return envKey;
|
|
23
|
+
}
|
|
24
|
+
function envKeyToConfigKey(envKey, prefix, componentName) {
|
|
25
|
+
const prefixUpper = prefix.toUpperCase();
|
|
26
|
+
if (!envKey.startsWith(prefixUpper)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const componentUpperNormalized = componentName.replace(/-/g, "_").toUpperCase();
|
|
30
|
+
let keyPart = envKey.slice(prefixUpper.length);
|
|
31
|
+
if (keyPart.startsWith("_")) {
|
|
32
|
+
keyPart = keyPart.slice(1);
|
|
33
|
+
}
|
|
34
|
+
if (!keyPart) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const firstUnderscore = keyPart.indexOf("_");
|
|
38
|
+
let restPart;
|
|
39
|
+
if (firstUnderscore === -1) {
|
|
40
|
+
restPart = keyPart;
|
|
41
|
+
} else {
|
|
42
|
+
const firstPart = keyPart.slice(0, firstUnderscore);
|
|
43
|
+
const remaining = keyPart.slice(firstUnderscore + 1);
|
|
44
|
+
if (firstPart === componentUpperNormalized) {
|
|
45
|
+
restPart = remaining;
|
|
46
|
+
} else {
|
|
47
|
+
restPart = keyPart;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!restPart) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const restPartConverted = restPart.replace(/_/g, ".");
|
|
54
|
+
return `${componentName}.${restPartConverted.toLowerCase()}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { toEnvKey, fromEnvKey, envKeyToConfigKey };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__require
|
|
3
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
4
|
+
|
|
5
|
+
// src/env/paths.ts
|
|
6
|
+
import os from "os";
|
|
7
|
+
import path from "path";
|
|
8
|
+
var APP_NAME = "roy-agent";
|
|
9
|
+
function getXdgBase() {
|
|
10
|
+
const home = os.homedir();
|
|
11
|
+
try {
|
|
12
|
+
const xdg = __require("xdg-basedir");
|
|
13
|
+
return {
|
|
14
|
+
config: xdg.xdgConfig || path.join(home, ".config"),
|
|
15
|
+
state: xdg.xdgState || path.join(home, ".local", "state"),
|
|
16
|
+
data: xdg.xdgData || path.join(home, ".local", "share"),
|
|
17
|
+
cache: xdg.xdgCache || path.join(home, ".cache")
|
|
18
|
+
};
|
|
19
|
+
} catch {
|
|
20
|
+
return {
|
|
21
|
+
config: path.join(home, ".config"),
|
|
22
|
+
state: path.join(home, ".local", "state"),
|
|
23
|
+
data: path.join(home, ".local", "share"),
|
|
24
|
+
cache: path.join(home, ".cache")
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function computeXDGPaths() {
|
|
29
|
+
const home = os.homedir();
|
|
30
|
+
const xdg = getXdgBase();
|
|
31
|
+
return {
|
|
32
|
+
home,
|
|
33
|
+
config: path.join(xdg.config, APP_NAME),
|
|
34
|
+
state: path.join(xdg.state, APP_NAME),
|
|
35
|
+
data: path.join(xdg.data, APP_NAME),
|
|
36
|
+
cache: path.join(xdg.cache, APP_NAME)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class XDGPathsCalculator {
|
|
41
|
+
_paths;
|
|
42
|
+
get paths() {
|
|
43
|
+
if (!this._paths) {
|
|
44
|
+
this._paths = computeXDGPaths();
|
|
45
|
+
}
|
|
46
|
+
return this._paths;
|
|
47
|
+
}
|
|
48
|
+
getPath(type) {
|
|
49
|
+
return this.paths[type];
|
|
50
|
+
}
|
|
51
|
+
getComponentPath(base, subPath) {
|
|
52
|
+
return path.join(this.paths[base], subPath);
|
|
53
|
+
}
|
|
54
|
+
reset() {
|
|
55
|
+
this._paths = undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
var XDG_PATHS = new XDGPathsCalculator;
|
|
59
|
+
function getXDGPaths() {
|
|
60
|
+
return XDG_PATHS.paths;
|
|
61
|
+
}
|
|
62
|
+
function getXDGPath(type) {
|
|
63
|
+
return XDG_PATHS.getPath(type);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { XDG_PATHS, getXDGPaths, getXDGPath };
|