@downcity/plugins 1.0.252 → 1.0.254
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/bin/memory/Action.d.ts +27 -36
- package/bin/memory/Action.d.ts.map +1 -1
- package/bin/memory/Action.js +71 -311
- package/bin/memory/Action.js.map +1 -1
- package/bin/memory/Index.d.ts +3 -1
- package/bin/memory/Index.d.ts.map +1 -1
- package/bin/memory/Index.js +3 -1
- package/bin/memory/Index.js.map +1 -1
- package/bin/memory/MemoryPlugin.d.ts +20 -37
- package/bin/memory/MemoryPlugin.d.ts.map +1 -1
- package/bin/memory/MemoryPlugin.js +231 -233
- package/bin/memory/MemoryPlugin.js.map +1 -1
- package/bin/memory/adapters/FileMemoryStorageAdapter.d.ts +43 -0
- package/bin/memory/adapters/FileMemoryStorageAdapter.d.ts.map +1 -0
- package/bin/memory/adapters/FileMemoryStorageAdapter.js +163 -0
- package/bin/memory/adapters/FileMemoryStorageAdapter.js.map +1 -0
- package/bin/memory/providers/BuiltinMemoryProvider.d.ts +63 -0
- package/bin/memory/providers/BuiltinMemoryProvider.d.ts.map +1 -0
- package/bin/memory/providers/BuiltinMemoryProvider.js +772 -0
- package/bin/memory/providers/BuiltinMemoryProvider.js.map +1 -0
- package/bin/memory/runtime/SystemProvider.d.ts +7 -12
- package/bin/memory/runtime/SystemProvider.d.ts.map +1 -1
- package/bin/memory/runtime/SystemProvider.js +30 -89
- package/bin/memory/runtime/SystemProvider.js.map +1 -1
- package/bin/memory/types/BuiltinMemoryProvider.d.ts +88 -0
- package/bin/memory/types/BuiltinMemoryProvider.d.ts.map +1 -0
- package/bin/memory/types/BuiltinMemoryProvider.js +9 -0
- package/bin/memory/types/BuiltinMemoryProvider.js.map +1 -0
- package/bin/memory/types/Memory.d.ts +249 -408
- package/bin/memory/types/Memory.d.ts.map +1 -1
- package/bin/memory/types/Memory.js +4 -4
- package/bin/memory/types/MemoryStorage.d.ts +35 -0
- package/bin/memory/types/MemoryStorage.d.ts.map +1 -0
- package/bin/memory/types/MemoryStorage.js +10 -0
- package/bin/memory/types/MemoryStorage.js.map +1 -0
- package/bin/memory.d.ts +6 -2
- package/bin/memory.d.ts.map +1 -1
- package/bin/memory.js +3 -1
- package/bin/memory.js.map +1 -1
- package/package.json +4 -3
- package/scripts/memory-plugin.test.mjs +227 -0
- package/scripts/plugin-subpaths.test.mjs +8 -0
- package/src/memory/Action.ts +106 -377
- package/src/memory/Index.ts +6 -1
- package/src/memory/MemoryPlugin.ts +254 -246
- package/src/memory/adapters/FileMemoryStorageAdapter.ts +197 -0
- package/src/memory/providers/BuiltinMemoryProvider.ts +905 -0
- package/src/memory/runtime/SystemProvider.ts +32 -95
- package/src/memory/types/BuiltinMemoryProvider.ts +121 -0
- package/src/memory/types/Memory.ts +322 -456
- package/src/memory/types/MemoryStorage.ts +44 -0
- package/src/memory.ts +48 -24
- package/bin/memory/runtime/Search.d.ts +0 -19
- package/bin/memory/runtime/Search.d.ts.map +0 -1
- package/bin/memory/runtime/Search.js +0 -262
- package/bin/memory/runtime/Search.js.map +0 -1
- package/bin/memory/runtime/Store.d.ts +0 -42
- package/bin/memory/runtime/Store.d.ts.map +0 -1
- package/bin/memory/runtime/Store.js +0 -94
- package/bin/memory/runtime/Store.js.map +0 -1
- package/bin/memory/runtime/Writer.d.ts +0 -61
- package/bin/memory/runtime/Writer.d.ts.map +0 -1
- package/bin/memory/runtime/Writer.js +0 -274
- package/bin/memory/runtime/Writer.js.map +0 -1
- package/src/memory/runtime/Search.ts +0 -327
- package/src/memory/runtime/Store.ts +0 -158
- package/src/memory/runtime/Writer.ts +0 -351
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryPlugin.d.ts","sourceRoot":"","sources":["../../src/memory/MemoryPlugin.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"MemoryPlugin.d.ts","sourceRoot":"","sources":["../../src/memory/MemoryPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,UAAU,EAAiB,MAAM,iBAAiB,CAAC;AAC5D,OAAO,KAAK,EAGV,aAAa,EACb,aAAa,EACd,MAAM,iBAAiB,CAAC;AAYzB,OAAO,KAAK,EACV,mBAAmB,EACnB,cAAc,EAEf,MAAM,0BAA0B,CAAC;AA+DlC,yBAAyB;AACzB,qBAAa,YAAa,SAAQ,UAAU;IAC1C,mBAAmB;IACnB,QAAQ,CAAC,IAAI,YAAY;IAEzB,uCAAuC;IACvC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;gBAEtB,OAAO,EAAE,mBAAmB;IAQxC,4CAA4C;IACtC,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC;IAIrD,4CAA4C;IAC5C,QAAQ,CAAC,SAAS;yBACO,aAAa,KAAG,OAAO,CAAC,IAAI,CAAC;oBAKpC,OAAO,CAAC,IAAI,CAAC;MAG7B;IAEF,sCAAsC;IACtC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAsS7B;CACH"}
|
|
@@ -1,395 +1,393 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* MemoryPlugin:
|
|
2
|
+
* MemoryPlugin:Agent 长期记忆的 provider-neutral facade。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
4
|
+
* 职责说明(中文)
|
|
5
|
+
* - 对 Agent 暴露稳定的 Memory actions 与 system 使用约束。
|
|
6
|
+
* - 把 Agent/Session 上下文映射为结构化 Memory scope。
|
|
7
|
+
* - 将记忆形成、存储、召回、修订和删除委托给唯一 MemoryProvider。
|
|
8
|
+
*
|
|
9
|
+
* 边界说明(中文)
|
|
10
|
+
* - 不读取或拼接任何物理存储路径。
|
|
11
|
+
* - 不依赖 Workspace FileSystem,也不规定 Markdown、SQLite 或远程服务。
|
|
12
|
+
* - Provider 生命周期跟随当前 Plugin 实例,由 Agent 统一启动和释放。
|
|
8
13
|
*/
|
|
9
|
-
import { BasePlugin } from "@downcity/agent";
|
|
10
|
-
import { create_action } from "@downcity/agent";
|
|
14
|
+
import { BasePlugin, create_action } from "@downcity/agent";
|
|
11
15
|
import { z } from "zod";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
import { digest_memory_action, forget_memory_action, read_memory_action, remember_memory_action, revise_memory_action, search_memory_action, status_memory_action, } from "../memory/Action.js";
|
|
17
|
+
import { build_memory_plugin_system_text } from "../memory/runtime/SystemProvider.js";
|
|
18
|
+
const memory_type_schema = z.enum([
|
|
19
|
+
"fact",
|
|
20
|
+
"preference",
|
|
21
|
+
"decision",
|
|
22
|
+
"episode",
|
|
23
|
+
"procedure",
|
|
24
|
+
"document",
|
|
25
|
+
]);
|
|
26
|
+
/** 解析正整数 CLI 参数。 */
|
|
27
|
+
function parse_positive_integer(value) {
|
|
17
28
|
const text = String(value || "").trim();
|
|
18
|
-
if (!/^\d
|
|
29
|
+
if (!/^\d+$/u.test(text))
|
|
19
30
|
throw new Error(`Invalid positive integer: ${value}`);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (!Number.isFinite(num) || num < 1) {
|
|
31
|
+
const number_value = Number(text);
|
|
32
|
+
if (!Number.isFinite(number_value) || number_value < 1) {
|
|
23
33
|
throw new Error(`Invalid positive integer: ${value}`);
|
|
24
34
|
}
|
|
25
|
-
return
|
|
35
|
+
return number_value;
|
|
26
36
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
const num = Number(text);
|
|
33
|
-
if (!Number.isFinite(num)) {
|
|
37
|
+
/** 解析任意有限数值 CLI 参数。 */
|
|
38
|
+
function parse_number(value) {
|
|
39
|
+
const number_value = Number(String(value || "").trim());
|
|
40
|
+
if (!Number.isFinite(number_value))
|
|
34
41
|
throw new Error(`Invalid number: ${value}`);
|
|
35
|
-
|
|
36
|
-
return num;
|
|
42
|
+
return number_value;
|
|
37
43
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
/** 把 Action JSON 输入归一化为普通对象。 */
|
|
45
|
+
function read_body_object(raw_body) {
|
|
46
|
+
return raw_body && typeof raw_body === "object" && !Array.isArray(raw_body)
|
|
47
|
+
? raw_body
|
|
48
|
+
: {};
|
|
43
49
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return typeof
|
|
50
|
+
/** 读取必填或可选字符串字段。 */
|
|
51
|
+
function read_string(body, key) {
|
|
52
|
+
return typeof body[key] === "string" ? String(body[key]) : "";
|
|
47
53
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
/** 读取可选字符串字段。 */
|
|
55
|
+
function read_optional_string(body, key) {
|
|
56
|
+
const value = read_string(body, key).trim();
|
|
57
|
+
return value || undefined;
|
|
51
58
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return typeof
|
|
59
|
+
/** 读取可选数值字段。 */
|
|
60
|
+
function read_optional_number(body, key) {
|
|
61
|
+
return typeof body[key] === "number" ? Number(body[key]) : undefined;
|
|
55
62
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return typeof
|
|
63
|
+
/** 读取可选布尔字段。 */
|
|
64
|
+
function read_optional_boolean(body, key) {
|
|
65
|
+
return typeof body[key] === "boolean" ? Boolean(body[key]) : undefined;
|
|
59
66
|
}
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
/** 读取可选 MemoryType 字段。 */
|
|
68
|
+
function read_optional_memory_type(body) {
|
|
69
|
+
const result = memory_type_schema.safeParse(body.memory_type);
|
|
70
|
+
return result.success ? result.data : undefined;
|
|
71
|
+
}
|
|
72
|
+
/** Agent 长期记忆 Plugin。 */
|
|
63
73
|
export class MemoryPlugin extends BasePlugin {
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* plugin 名称。
|
|
67
|
-
*/
|
|
74
|
+
/** Plugin 稳定名称。 */
|
|
68
75
|
name = "memory";
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
runtimeState = null;
|
|
73
|
-
/**
|
|
74
|
-
* 创建 MemoryPlugin。
|
|
75
|
-
*/
|
|
76
|
-
constructor(options = {}) {
|
|
76
|
+
/** 当前 Plugin 唯一绑定的 Memory Provider。 */
|
|
77
|
+
provider;
|
|
78
|
+
constructor(options) {
|
|
77
79
|
super();
|
|
78
|
-
|
|
80
|
+
if (!options?.provider)
|
|
81
|
+
throw new Error("MemoryPlugin requires provider");
|
|
82
|
+
const provider_name = String(options.provider.name || "").trim();
|
|
83
|
+
if (!provider_name)
|
|
84
|
+
throw new Error("MemoryPlugin provider requires name");
|
|
85
|
+
this.provider = options.provider;
|
|
79
86
|
}
|
|
80
|
-
/**
|
|
81
|
-
* 当前 plugin 的 system 文本提供器。
|
|
82
|
-
*/
|
|
87
|
+
/** 构建 provider-neutral Memory system 内容。 */
|
|
83
88
|
async system(context) {
|
|
84
|
-
return await
|
|
89
|
+
return await build_memory_plugin_system_text(context, this.provider);
|
|
85
90
|
}
|
|
86
|
-
/**
|
|
87
|
-
* 当前 plugin 生命周期。
|
|
88
|
-
*/
|
|
91
|
+
/** Provider 生命周期与当前 Agent Plugin 实例保持一致。 */
|
|
89
92
|
lifecycle = {
|
|
90
93
|
start: async (context) => {
|
|
91
|
-
await
|
|
92
|
-
|
|
94
|
+
await this.provider.initialize({
|
|
95
|
+
agent_id: context.agent_id,
|
|
96
|
+
});
|
|
93
97
|
},
|
|
94
98
|
stop: async () => {
|
|
95
|
-
this.
|
|
99
|
+
await this.provider.dispose();
|
|
96
100
|
},
|
|
97
101
|
};
|
|
98
|
-
/**
|
|
99
|
-
* 当前 plugin action 定义表。
|
|
100
|
-
*/
|
|
102
|
+
/** Memory 对 Agent 暴露的稳定 Action 集合。 */
|
|
101
103
|
actions = {
|
|
102
104
|
status: create_action({
|
|
103
|
-
description: "
|
|
105
|
+
description: "Inspect the active Memory Provider and its capabilities.",
|
|
104
106
|
input_schema: {
|
|
105
107
|
zod: z.object({}).passthrough(),
|
|
106
|
-
json_schema: { type: "object", properties: {} },
|
|
108
|
+
json_schema: { type: "object", additionalProperties: false, properties: {} },
|
|
107
109
|
},
|
|
108
|
-
examples: [{ title: "View status", payload: {} }],
|
|
110
|
+
examples: [{ title: "View Memory Provider status", payload: {} }],
|
|
109
111
|
command: {
|
|
110
|
-
description: "
|
|
111
|
-
map_input() {
|
|
112
|
-
return {};
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
execute: async (params) => {
|
|
116
|
-
const state = this.getOrCreateRuntimeState(params.context);
|
|
117
|
-
return await statusMemoryAction(params.context, state);
|
|
112
|
+
description: "Inspect the active Memory Provider.",
|
|
113
|
+
map_input: () => ({}),
|
|
118
114
|
},
|
|
115
|
+
execute: async () => await status_memory_action(this.provider),
|
|
119
116
|
}),
|
|
120
117
|
search: create_action({
|
|
121
|
-
description: "
|
|
118
|
+
description: "Recall scoped long-term memories for a focused query.",
|
|
122
119
|
input_schema: {
|
|
123
120
|
zod: z.object({
|
|
124
121
|
query: z.string(),
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
max_results: z.number().optional(),
|
|
123
|
+
min_score: z.number().optional(),
|
|
124
|
+
include_evidence: z.boolean().optional(),
|
|
128
125
|
}),
|
|
129
126
|
json_schema: {
|
|
130
127
|
type: "object",
|
|
128
|
+
additionalProperties: false,
|
|
131
129
|
required: ["query"],
|
|
132
130
|
properties: {
|
|
133
|
-
query: { type: "string", description: "
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
query: { type: "string", description: "Focused recall query." },
|
|
132
|
+
max_results: { type: "number", description: "Maximum result count." },
|
|
133
|
+
min_score: { type: "number", minimum: 0, maximum: 1 },
|
|
134
|
+
include_evidence: { type: "boolean", description: "Include raw evidence records." },
|
|
137
135
|
},
|
|
138
136
|
},
|
|
139
137
|
},
|
|
140
|
-
examples: [
|
|
141
|
-
{ title: "Search memory", payload: { query: "user preferences" } },
|
|
142
|
-
],
|
|
138
|
+
examples: [{ title: "Recall preferences", payload: { query: "user preferences" } }],
|
|
143
139
|
command: {
|
|
144
|
-
description: "
|
|
140
|
+
description: "Recall scoped long-term memories.",
|
|
145
141
|
configure(command) {
|
|
146
142
|
command
|
|
147
143
|
.argument("<query>")
|
|
148
|
-
.option("--max-results <number>", "Maximum
|
|
149
|
-
.option("--min-score <number>", "Minimum relevance score.",
|
|
150
|
-
.option("--include-
|
|
144
|
+
.option("--max-results <number>", "Maximum result count.", parse_positive_integer)
|
|
145
|
+
.option("--min-score <number>", "Minimum relevance score.", parse_number)
|
|
146
|
+
.option("--include-evidence", "Include raw evidence records.");
|
|
151
147
|
},
|
|
152
148
|
map_input({ args, opts }) {
|
|
153
|
-
|
|
149
|
+
return {
|
|
154
150
|
query: String(args[0] || ""),
|
|
151
|
+
...(typeof opts.maxResults === "number" ? { max_results: opts.maxResults } : {}),
|
|
152
|
+
...(typeof opts.minScore === "number" ? { min_score: opts.minScore } : {}),
|
|
153
|
+
...(opts.includeEvidence === true ? { include_evidence: true } : {}),
|
|
155
154
|
};
|
|
156
|
-
if (typeof opts.maxResults === "number") {
|
|
157
|
-
payload.maxResults = opts.maxResults;
|
|
158
|
-
}
|
|
159
|
-
if (typeof opts.minScore === "number") {
|
|
160
|
-
payload.minScore = opts.minScore;
|
|
161
|
-
}
|
|
162
|
-
if (opts.includeSources === true) {
|
|
163
|
-
payload.includeSources = true;
|
|
164
|
-
}
|
|
165
|
-
return payload;
|
|
166
155
|
},
|
|
167
156
|
},
|
|
168
|
-
execute: async (
|
|
169
|
-
const body =
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
includeSources: readOptionalBoolean(body, "includeSources"),
|
|
157
|
+
execute: async ({ context, input }) => {
|
|
158
|
+
const body = read_body_object(input);
|
|
159
|
+
return await search_memory_action(context, this.provider, {
|
|
160
|
+
query: read_string(body, "query"),
|
|
161
|
+
max_results: read_optional_number(body, "max_results"),
|
|
162
|
+
min_score: read_optional_number(body, "min_score"),
|
|
163
|
+
include_evidence: read_optional_boolean(body, "include_evidence"),
|
|
176
164
|
});
|
|
177
165
|
},
|
|
178
166
|
}),
|
|
179
167
|
read: create_action({
|
|
180
|
-
description: "Read
|
|
168
|
+
description: "Read one exact memory by memory_id.",
|
|
181
169
|
input_schema: {
|
|
182
170
|
zod: z.object({
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
171
|
+
memory_id: z.string(),
|
|
172
|
+
from_line: z.number().optional(),
|
|
173
|
+
line_count: z.number().optional(),
|
|
186
174
|
}),
|
|
187
175
|
json_schema: {
|
|
188
176
|
type: "object",
|
|
189
|
-
|
|
177
|
+
additionalProperties: false,
|
|
178
|
+
required: ["memory_id"],
|
|
190
179
|
properties: {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
180
|
+
memory_id: { type: "string", description: "Stable logical memory identifier." },
|
|
181
|
+
from_line: { type: "number", minimum: 1 },
|
|
182
|
+
line_count: { type: "number", minimum: 1 },
|
|
194
183
|
},
|
|
195
184
|
},
|
|
196
185
|
},
|
|
197
|
-
examples: [
|
|
198
|
-
{ title: "Read full page", payload: { path: ".downcity/memory/wiki/index.md" } },
|
|
199
|
-
],
|
|
186
|
+
examples: [{ title: "Read a memory", payload: { memory_id: "wiki/user-preferences" } }],
|
|
200
187
|
command: {
|
|
201
|
-
description: "Read
|
|
188
|
+
description: "Read one exact memory.",
|
|
202
189
|
configure(command) {
|
|
203
190
|
command
|
|
204
|
-
.argument("<
|
|
205
|
-
.option("--from <number>", "Starting line, 1-based.",
|
|
206
|
-
.option("--
|
|
191
|
+
.argument("<memory_id>")
|
|
192
|
+
.option("--from-line <number>", "Starting line, 1-based.", parse_positive_integer)
|
|
193
|
+
.option("--line-count <number>", "Maximum line count.", parse_positive_integer);
|
|
207
194
|
},
|
|
208
195
|
map_input({ args, opts }) {
|
|
209
|
-
|
|
210
|
-
|
|
196
|
+
return {
|
|
197
|
+
memory_id: String(args[0] || ""),
|
|
198
|
+
...(typeof opts.fromLine === "number" ? { from_line: opts.fromLine } : {}),
|
|
199
|
+
...(typeof opts.lineCount === "number" ? { line_count: opts.lineCount } : {}),
|
|
211
200
|
};
|
|
212
|
-
if (typeof opts.from === "number") {
|
|
213
|
-
payload.from = opts.from;
|
|
214
|
-
}
|
|
215
|
-
if (typeof opts.lines === "number") {
|
|
216
|
-
payload.lines = opts.lines;
|
|
217
|
-
}
|
|
218
|
-
return payload;
|
|
219
201
|
},
|
|
220
202
|
},
|
|
221
|
-
execute: async (
|
|
222
|
-
const body =
|
|
223
|
-
return await
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
203
|
+
execute: async ({ context, input }) => {
|
|
204
|
+
const body = read_body_object(input);
|
|
205
|
+
return await read_memory_action(context, this.provider, {
|
|
206
|
+
memory_id: read_string(body, "memory_id"),
|
|
207
|
+
from_line: read_optional_number(body, "from_line"),
|
|
208
|
+
line_count: read_optional_number(body, "line_count"),
|
|
227
209
|
});
|
|
228
210
|
},
|
|
229
211
|
}),
|
|
230
212
|
remember: create_action({
|
|
231
|
-
description: "
|
|
213
|
+
description: "Store a durable fact, preference, decision, episode, procedure, or document.",
|
|
232
214
|
input_schema: {
|
|
233
215
|
zod: z.object({
|
|
234
216
|
content: z.string(),
|
|
235
217
|
topic: z.string().optional(),
|
|
236
|
-
|
|
218
|
+
memory_type: memory_type_schema.optional(),
|
|
237
219
|
source: z.string().optional(),
|
|
238
220
|
}),
|
|
239
221
|
json_schema: {
|
|
240
222
|
type: "object",
|
|
223
|
+
additionalProperties: false,
|
|
241
224
|
required: ["content"],
|
|
242
225
|
properties: {
|
|
243
226
|
content: { type: "string", description: "Content to remember." },
|
|
244
|
-
topic: { type: "string", description: "
|
|
245
|
-
|
|
246
|
-
|
|
227
|
+
topic: { type: "string", description: "Optional organization hint." },
|
|
228
|
+
memory_type: {
|
|
229
|
+
type: "string",
|
|
230
|
+
enum: ["fact", "preference", "decision", "episode", "procedure", "document"],
|
|
231
|
+
},
|
|
232
|
+
source: { type: "string", description: "Optional evidence label." },
|
|
247
233
|
},
|
|
248
234
|
},
|
|
249
235
|
},
|
|
250
|
-
examples: [
|
|
251
|
-
|
|
252
|
-
|
|
236
|
+
examples: [{
|
|
237
|
+
title: "Remember a preference",
|
|
238
|
+
payload: {
|
|
239
|
+
content: "User prefers concise answers.",
|
|
240
|
+
topic: "user-preferences",
|
|
241
|
+
memory_type: "preference",
|
|
242
|
+
},
|
|
243
|
+
}],
|
|
253
244
|
command: {
|
|
254
|
-
description: "
|
|
245
|
+
description: "Store a durable memory.",
|
|
255
246
|
configure(command) {
|
|
256
247
|
command
|
|
257
248
|
.requiredOption("--content <text>", "Content to remember.")
|
|
258
|
-
.option("--topic <topic>", "
|
|
259
|
-
.option("--
|
|
260
|
-
.option("--source <source>", "
|
|
249
|
+
.option("--topic <topic>", "Optional organization hint.")
|
|
250
|
+
.option("--memory-type <type>", "Memory type.")
|
|
251
|
+
.option("--source <source>", "Optional evidence label.");
|
|
261
252
|
},
|
|
262
253
|
map_input({ opts }) {
|
|
263
|
-
|
|
254
|
+
return {
|
|
264
255
|
content: String(opts.content || ""),
|
|
256
|
+
...(typeof opts.topic === "string" ? { topic: opts.topic } : {}),
|
|
257
|
+
...(typeof opts.memoryType === "string" ? { memory_type: opts.memoryType } : {}),
|
|
258
|
+
...(typeof opts.source === "string" ? { source: opts.source } : {}),
|
|
265
259
|
};
|
|
266
|
-
if (typeof opts.topic === "string") {
|
|
267
|
-
payload.topic = String(opts.topic).trim();
|
|
268
|
-
}
|
|
269
|
-
if (typeof opts.wikiPath === "string") {
|
|
270
|
-
payload.path = String(opts.wikiPath).trim();
|
|
271
|
-
}
|
|
272
|
-
if (typeof opts.source === "string") {
|
|
273
|
-
payload.source = String(opts.source).trim();
|
|
274
|
-
}
|
|
275
|
-
return payload;
|
|
276
260
|
},
|
|
277
261
|
},
|
|
278
|
-
execute: async (
|
|
279
|
-
const body =
|
|
280
|
-
return await
|
|
281
|
-
content:
|
|
282
|
-
topic:
|
|
283
|
-
|
|
284
|
-
source:
|
|
262
|
+
execute: async ({ context, input }) => {
|
|
263
|
+
const body = read_body_object(input);
|
|
264
|
+
return await remember_memory_action(context, this.provider, {
|
|
265
|
+
content: read_string(body, "content"),
|
|
266
|
+
topic: read_optional_string(body, "topic"),
|
|
267
|
+
memory_type: read_optional_memory_type(body),
|
|
268
|
+
source: read_optional_string(body, "source"),
|
|
285
269
|
});
|
|
286
270
|
},
|
|
287
271
|
}),
|
|
288
272
|
digest: create_action({
|
|
289
|
-
description: "Digest a
|
|
273
|
+
description: "Digest a canonical Session transcript into long-term memory.",
|
|
290
274
|
input_schema: {
|
|
291
275
|
zod: z.object({
|
|
292
276
|
session_id: z.string(),
|
|
293
|
-
|
|
277
|
+
max_messages: z.number().optional(),
|
|
294
278
|
}),
|
|
295
279
|
json_schema: {
|
|
296
280
|
type: "object",
|
|
281
|
+
additionalProperties: false,
|
|
297
282
|
required: ["session_id"],
|
|
298
283
|
properties: {
|
|
299
|
-
session_id: { type: "string"
|
|
300
|
-
|
|
284
|
+
session_id: { type: "string" },
|
|
285
|
+
max_messages: { type: "number", minimum: 1 },
|
|
301
286
|
},
|
|
302
287
|
},
|
|
303
288
|
},
|
|
304
|
-
examples: [
|
|
305
|
-
{ title: "Digest session", payload: { session_id: "sess-1" } },
|
|
306
|
-
],
|
|
289
|
+
examples: [{ title: "Digest a Session", payload: { session_id: "sess-1" } }],
|
|
307
290
|
command: {
|
|
308
|
-
description: "Digest a
|
|
291
|
+
description: "Digest a canonical Session transcript.",
|
|
309
292
|
configure(command) {
|
|
310
293
|
command
|
|
311
|
-
.requiredOption("--session-id <session_id>", "Session
|
|
312
|
-
.option("--max-messages <number>", "
|
|
294
|
+
.requiredOption("--session-id <session_id>", "Session identifier.")
|
|
295
|
+
.option("--max-messages <number>", "Maximum message count.", parse_positive_integer);
|
|
313
296
|
},
|
|
314
297
|
map_input({ opts }) {
|
|
315
|
-
|
|
316
|
-
session_id: String(opts.
|
|
298
|
+
return {
|
|
299
|
+
session_id: String(opts.sessionId || ""),
|
|
300
|
+
...(typeof opts.maxMessages === "number" ? { max_messages: opts.maxMessages } : {}),
|
|
317
301
|
};
|
|
318
|
-
if (typeof opts.maxMessages === "number") {
|
|
319
|
-
payload.maxMessages = opts.maxMessages;
|
|
320
|
-
}
|
|
321
|
-
return payload;
|
|
322
302
|
},
|
|
323
303
|
},
|
|
324
|
-
execute: async (
|
|
325
|
-
const body =
|
|
326
|
-
return await
|
|
327
|
-
session_id:
|
|
328
|
-
|
|
304
|
+
execute: async ({ context, input }) => {
|
|
305
|
+
const body = read_body_object(input);
|
|
306
|
+
return await digest_memory_action(context, this.provider, {
|
|
307
|
+
session_id: read_string(body, "session_id"),
|
|
308
|
+
max_messages: read_optional_number(body, "max_messages"),
|
|
329
309
|
});
|
|
330
310
|
},
|
|
331
311
|
}),
|
|
332
312
|
revise: create_action({
|
|
333
|
-
description: "Revise
|
|
313
|
+
description: "Revise one memory using new evidence.",
|
|
334
314
|
input_schema: {
|
|
335
315
|
zod: z.object({
|
|
336
|
-
|
|
316
|
+
memory_id: z.string(),
|
|
337
317
|
instruction: z.string(),
|
|
338
318
|
evidence: z.string().optional(),
|
|
339
319
|
}),
|
|
340
320
|
json_schema: {
|
|
341
321
|
type: "object",
|
|
342
|
-
|
|
322
|
+
additionalProperties: false,
|
|
323
|
+
required: ["memory_id", "instruction"],
|
|
343
324
|
properties: {
|
|
344
|
-
|
|
345
|
-
instruction: { type: "string"
|
|
346
|
-
evidence: { type: "string"
|
|
325
|
+
memory_id: { type: "string" },
|
|
326
|
+
instruction: { type: "string" },
|
|
327
|
+
evidence: { type: "string" },
|
|
347
328
|
},
|
|
348
329
|
},
|
|
349
330
|
},
|
|
350
|
-
examples: [
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
331
|
+
examples: [{
|
|
332
|
+
title: "Revise a preference",
|
|
333
|
+
payload: {
|
|
334
|
+
memory_id: "wiki/user-preferences",
|
|
335
|
+
instruction: "Replace the old preference with the latest one.",
|
|
336
|
+
},
|
|
337
|
+
}],
|
|
356
338
|
command: {
|
|
357
|
-
description: "Revise
|
|
339
|
+
description: "Revise one memory using new evidence.",
|
|
358
340
|
configure(command) {
|
|
359
341
|
command
|
|
360
|
-
.argument("<
|
|
342
|
+
.argument("<memory_id>")
|
|
361
343
|
.requiredOption("--instruction <text>", "Revision instruction.")
|
|
362
344
|
.option("--evidence <text>", "New evidence.");
|
|
363
345
|
},
|
|
364
346
|
map_input({ args, opts }) {
|
|
365
|
-
|
|
366
|
-
|
|
347
|
+
return {
|
|
348
|
+
memory_id: String(args[0] || ""),
|
|
367
349
|
instruction: String(opts.instruction || ""),
|
|
350
|
+
...(typeof opts.evidence === "string" ? { evidence: opts.evidence } : {}),
|
|
368
351
|
};
|
|
369
|
-
if (typeof opts.evidence === "string") {
|
|
370
|
-
payload.evidence = String(opts.evidence).trim();
|
|
371
|
-
}
|
|
372
|
-
return payload;
|
|
373
352
|
},
|
|
374
353
|
},
|
|
375
|
-
execute: async (
|
|
376
|
-
const body =
|
|
377
|
-
return await
|
|
378
|
-
|
|
379
|
-
instruction:
|
|
380
|
-
evidence:
|
|
354
|
+
execute: async ({ context, input }) => {
|
|
355
|
+
const body = read_body_object(input);
|
|
356
|
+
return await revise_memory_action(context, this.provider, {
|
|
357
|
+
memory_id: read_string(body, "memory_id"),
|
|
358
|
+
instruction: read_string(body, "instruction"),
|
|
359
|
+
evidence: read_optional_string(body, "evidence"),
|
|
360
|
+
});
|
|
361
|
+
},
|
|
362
|
+
}),
|
|
363
|
+
forget: create_action({
|
|
364
|
+
description: "Delete or invalidate one memory by memory_id.",
|
|
365
|
+
input_schema: {
|
|
366
|
+
zod: z.object({ memory_id: z.string() }),
|
|
367
|
+
json_schema: {
|
|
368
|
+
type: "object",
|
|
369
|
+
additionalProperties: false,
|
|
370
|
+
required: ["memory_id"],
|
|
371
|
+
properties: { memory_id: { type: "string" } },
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
examples: [{ title: "Forget a memory", payload: { memory_id: "wiki/obsolete" } }],
|
|
375
|
+
command: {
|
|
376
|
+
description: "Delete or invalidate one memory.",
|
|
377
|
+
configure(command) {
|
|
378
|
+
command.argument("<memory_id>");
|
|
379
|
+
},
|
|
380
|
+
map_input({ args }) {
|
|
381
|
+
return { memory_id: String(args[0] || "") };
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
execute: async ({ context, input }) => {
|
|
385
|
+
const body = read_body_object(input);
|
|
386
|
+
return await forget_memory_action(context, this.provider, {
|
|
387
|
+
memory_id: read_string(body, "memory_id"),
|
|
381
388
|
});
|
|
382
389
|
},
|
|
383
390
|
}),
|
|
384
391
|
};
|
|
385
|
-
/**
|
|
386
|
-
* 获取或创建当前实例绑定的 memory plugin state。
|
|
387
|
-
*/
|
|
388
|
-
getOrCreateRuntimeState(context) {
|
|
389
|
-
if (!this.runtimeState) {
|
|
390
|
-
this.runtimeState = createMemoryRuntimeState(context);
|
|
391
|
-
}
|
|
392
|
-
return this.runtimeState;
|
|
393
|
-
}
|
|
394
392
|
}
|
|
395
393
|
//# sourceMappingURL=MemoryPlugin.js.map
|