@ai-setting/roy-agent-core 1.5.14-test → 1.5.15-test
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/package.json +1 -1
- package/dist/config/index.d.ts +0 -1250
- package/dist/config/index.js +0 -32
- package/dist/env/agent/index.d.ts +0 -2279
- package/dist/env/agent/index.js +0 -24
- package/dist/env/commands/index.d.ts +0 -1131
- package/dist/env/commands/index.js +0 -14
- package/dist/env/debug/formatters/index.d.ts +0 -236
- package/dist/env/debug/formatters/index.js +0 -11
- package/dist/env/debug/index.d.ts +0 -1652
- package/dist/env/debug/index.js +0 -26
- package/dist/env/hook/index.d.ts +0 -279
- package/dist/env/hook/index.js +0 -29
- package/dist/env/index.d.ts +0 -3481
- package/dist/env/index.js +0 -82
- package/dist/env/llm/index.d.ts +0 -1760
- package/dist/env/llm/index.js +0 -40
- package/dist/env/log-trace/index.d.ts +0 -1574
- package/dist/env/log-trace/index.js +0 -83
- package/dist/env/mcp/index.d.ts +0 -1331
- package/dist/env/mcp/index.js +0 -39
- package/dist/env/mcp/tool/index.d.ts +0 -183
- package/dist/env/mcp/tool/index.js +0 -14
- package/dist/env/memory/built-in/index.d.ts +0 -232
- package/dist/env/memory/built-in/index.js +0 -11
- package/dist/env/memory/index.d.ts +0 -1799
- package/dist/env/memory/index.js +0 -56
- package/dist/env/memory/plugin/index.d.ts +0 -747
- package/dist/env/memory/plugin/index.js +0 -36
- package/dist/env/prompt/index.d.ts +0 -1164
- package/dist/env/prompt/index.js +0 -20
- package/dist/env/session/index.d.ts +0 -1908
- package/dist/env/session/index.js +0 -25
- package/dist/env/session/storage/index.d.ts +0 -564
- package/dist/env/session/storage/index.js +0 -18
- package/dist/env/skill/index.d.ts +0 -1266
- package/dist/env/skill/index.js +0 -34
- package/dist/env/skill/tool/index.d.ts +0 -193
- package/dist/env/skill/tool/index.js +0 -9
- package/dist/env/task/delegate/index.d.ts +0 -1612
- package/dist/env/task/delegate/index.js +0 -18
- package/dist/env/task/events/index.d.ts +0 -171
- package/dist/env/task/events/index.js +0 -7
- package/dist/env/task/hooks/index.d.ts +0 -624
- package/dist/env/task/hooks/index.js +0 -7
- package/dist/env/task/index.d.ts +0 -1553
- package/dist/env/task/index.js +0 -34
- package/dist/env/task/plugins/index.d.ts +0 -466
- package/dist/env/task/plugins/index.js +0 -23
- package/dist/env/task/storage/index.d.ts +0 -241
- package/dist/env/task/storage/index.js +0 -14
- package/dist/env/task/tools/index.d.ts +0 -1485
- package/dist/env/task/tools/index.js +0 -17
- package/dist/env/task/tools/operation/index.d.ts +0 -1484
- package/dist/env/task/tools/operation/index.js +0 -15
- package/dist/env/tool/built-in/index.d.ts +0 -218
- package/dist/env/tool/built-in/index.js +0 -25
- package/dist/env/tool/index.d.ts +0 -1396
- package/dist/env/tool/index.js +0 -39
- package/dist/env/workflow/decorators/index.d.ts +0 -2161
- package/dist/env/workflow/decorators/index.js +0 -27
- package/dist/env/workflow/engine/index.d.ts +0 -3453
- package/dist/env/workflow/engine/index.js +0 -28
- package/dist/env/workflow/index.d.ts +0 -3546
- package/dist/env/workflow/index.js +0 -136
- package/dist/env/workflow/nodes/index.d.ts +0 -2092
- package/dist/env/workflow/nodes/index.js +0 -19
- package/dist/env/workflow/service/index.d.ts +0 -227
- package/dist/env/workflow/service/index.js +0 -13
- package/dist/env/workflow/storage/index.d.ts +0 -165
- package/dist/env/workflow/storage/index.js +0 -27
- package/dist/env/workflow/tools/index.d.ts +0 -416
- package/dist/env/workflow/tools/index.js +0 -159
- package/dist/env/workflow/types/index.d.ts +0 -2255
- package/dist/env/workflow/types/index.js +0 -98
- package/dist/env/workflow/utils/index.d.ts +0 -2031
- package/dist/env/workflow/utils/index.js +0 -637
- package/dist/index.d.ts +0 -7858
- package/dist/index.js +0 -399
- package/dist/shared/@ai-setting/roy-agent-core-0rtxwr28.js +0 -258
- package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +0 -36
- package/dist/shared/@ai-setting/roy-agent-core-1akcqxj9.js +0 -349
- package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +0 -117
- package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +0 -11
- package/dist/shared/@ai-setting/roy-agent-core-3jywqmdd.js +0 -393
- package/dist/shared/@ai-setting/roy-agent-core-3rr5k71j.js +0 -200
- package/dist/shared/@ai-setting/roy-agent-core-44hnfb02.js +0 -299
- package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +0 -206
- package/dist/shared/@ai-setting/roy-agent-core-4txzpsbt.js +0 -393
- package/dist/shared/@ai-setting/roy-agent-core-5x94xmt6.js +0 -350
- package/dist/shared/@ai-setting/roy-agent-core-69jskqjg.js +0 -180
- package/dist/shared/@ai-setting/roy-agent-core-6kvtahqv.js +0 -408
- package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +0 -284
- package/dist/shared/@ai-setting/roy-agent-core-81w1963m.js +0 -762
- package/dist/shared/@ai-setting/roy-agent-core-8gxth0eh.js +0 -10
- package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +0 -14
- package/dist/shared/@ai-setting/roy-agent-core-93zfb3r1.js +0 -922
- package/dist/shared/@ai-setting/roy-agent-core-9yxb3ty9.js +0 -15
- package/dist/shared/@ai-setting/roy-agent-core-b0x5dda6.js +0 -1130
- package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +0 -14
- package/dist/shared/@ai-setting/roy-agent-core-bvr1761x.js +0 -653
- package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +0 -93
- package/dist/shared/@ai-setting/roy-agent-core-d7cyjkf7.js +0 -872
- package/dist/shared/@ai-setting/roy-agent-core-dh9d7a3m.js +0 -11
- package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +0 -64
- package/dist/shared/@ai-setting/roy-agent-core-eajcvp4e.js +0 -378
- package/dist/shared/@ai-setting/roy-agent-core-f7q2x5z6.js +0 -492
- package/dist/shared/@ai-setting/roy-agent-core-fs0mn2jk.js +0 -52
- package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +0 -171
- package/dist/shared/@ai-setting/roy-agent-core-g99pxzn5.js +0 -862
- package/dist/shared/@ai-setting/roy-agent-core-gbqcyegm.js +0 -1387
- package/dist/shared/@ai-setting/roy-agent-core-gjq1yk68.js +0 -208
- package/dist/shared/@ai-setting/roy-agent-core-gq20wsgv.js +0 -139
- package/dist/shared/@ai-setting/roy-agent-core-gwc4h96n.js +0 -534
- package/dist/shared/@ai-setting/roy-agent-core-jfh9q2qh.js +0 -204
- package/dist/shared/@ai-setting/roy-agent-core-jvatggbb.js +0 -603
- package/dist/shared/@ai-setting/roy-agent-core-kkbwepqb.js +0 -97
- package/dist/shared/@ai-setting/roy-agent-core-pjr12nnd.js +0 -587
- package/dist/shared/@ai-setting/roy-agent-core-psv4v63c.js +0 -176
- package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +0 -60
- package/dist/shared/@ai-setting/roy-agent-core-qqceba6k.js +0 -442
- package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +0 -57
- package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +0 -66
- package/dist/shared/@ai-setting/roy-agent-core-r9ezzemr.js +0 -10
- package/dist/shared/@ai-setting/roy-agent-core-rhmtwnw1.js +0 -267
- package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +0 -584
- package/dist/shared/@ai-setting/roy-agent-core-rvxg1wps.js +0 -102
- package/dist/shared/@ai-setting/roy-agent-core-satmq6sh.js +0 -549
- package/dist/shared/@ai-setting/roy-agent-core-sx7wsvnn.js +0 -15
- package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +0 -213
- package/dist/shared/@ai-setting/roy-agent-core-vf215qfv.js +0 -812
- package/dist/shared/@ai-setting/roy-agent-core-vkz81f7v.js +0 -1316
- package/dist/shared/@ai-setting/roy-agent-core-vn2bc59q.js +0 -1205
- package/dist/shared/@ai-setting/roy-agent-core-wa1kzqky.js +0 -328
- package/dist/shared/@ai-setting/roy-agent-core-wft9ra24.js +0 -20
- package/dist/shared/@ai-setting/roy-agent-core-wrcy0h6z.js +0 -2098
- package/dist/shared/@ai-setting/roy-agent-core-xq8hhqb8.js +0 -419
- package/dist/shared/@ai-setting/roy-agent-core-xs5rsgat.js +0 -368
- package/dist/shared/@ai-setting/roy-agent-core-zbkpc41z.js +0 -377
- package/dist/shared/@ai-setting/roy-agent-core-zgypchmt.js +0 -172
- package/dist/shared/@ai-setting/roy-agent-core-zpn0bqa8.js +0 -103
|
@@ -1,393 +0,0 @@
|
|
|
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-kkbwepqb.js";
|
|
10
|
-
import {
|
|
11
|
-
createLogger,
|
|
12
|
-
init_logger
|
|
13
|
-
} from "./roy-agent-core-44hnfb02.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 };
|