@modelstudio/modelstudio-memory-for-openclaw 1.0.1 → 1.0.3
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/README.md +4 -2
- package/index.ts +54 -11
- package/openclaw.plugin.json +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ openclaw modelstudio-memory stats
|
|
|
58
58
|
config: {
|
|
59
59
|
// 必需配置
|
|
60
60
|
"apiKey": "your-dashscope-api-key",
|
|
61
|
-
"userId": "
|
|
61
|
+
"userId": "openclaw_memory",
|
|
62
62
|
|
|
63
63
|
// 可选配置(以下为默认值)
|
|
64
64
|
"baseUrl": "https://dashscope.aliyuncs.com/api/v2/apps/memory",
|
|
@@ -81,7 +81,7 @@ openclaw modelstudio-memory stats
|
|
|
81
81
|
| 配置项 | 类型 | 必需 | 默认值 | 说明 |
|
|
82
82
|
|--------|------|------|--------|------|
|
|
83
83
|
| `apiKey` | `string` | ✅ | - | DashScope API Key(在 openclaw.json 中配置) |
|
|
84
|
-
| `userId` | `string` |
|
|
84
|
+
| `userId` | `string` | ❌ | `openclaw_memory` | 用户 ID,用于隔离不同用户的记忆 |
|
|
85
85
|
| `baseUrl` | `string` | ❌ | `https://dashscope.aliyuncs.com/api/v2/apps/memory` | API endpoint(私有部署时填写完整 URL) |
|
|
86
86
|
| `autoCapture` | `boolean` | ❌ | `true` | 是否自动捕获对话 |
|
|
87
87
|
| `autoRecall` | `boolean` | ❌ | `true` | 是否自动召回记忆 |
|
|
@@ -95,6 +95,8 @@ openclaw modelstudio-memory stats
|
|
|
95
95
|
|
|
96
96
|
在 [阿里云百炼控制台](https://help.aliyun.com/zh/model-studio/get-api-key) 获取 DashScope API Key,并在 `openclaw.json` 的 `config.apiKey` 中配置。
|
|
97
97
|
|
|
98
|
+
**提示**:若安装后未配置 apiKey,插件仍会加载。当用户使用记忆功能(如询问「我之前说过什么」)时,Agent 会提示用户配置 apiKey。
|
|
99
|
+
|
|
98
100
|
## 使用方法
|
|
99
101
|
|
|
100
102
|
### 自动记忆(推荐)
|
package/index.ts
CHANGED
|
@@ -98,17 +98,9 @@ const modelstudioMemoryConfigSchema = {
|
|
|
98
98
|
const cfg = value as Record<string, unknown>;
|
|
99
99
|
assertAllowedKeys(cfg, ALLOWED_KEYS, "modelstudio-memory-for-openclaw config");
|
|
100
100
|
|
|
101
|
-
// apiKey
|
|
101
|
+
// apiKey: allow empty at parse time; tools return config prompt when missing
|
|
102
102
|
const apiKey = typeof cfg.apiKey === "string" ? cfg.apiKey : "";
|
|
103
|
-
|
|
104
|
-
throw new Error("apiKey is required for modelstudio-memory-for-openclaw");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// userId is required
|
|
108
|
-
const userId = typeof cfg.userId === "string" ? cfg.userId : "";
|
|
109
|
-
if (!userId) {
|
|
110
|
-
throw new Error("userId is required for modelstudio-memory-for-openclaw");
|
|
111
|
-
}
|
|
103
|
+
const userId = typeof cfg.userId === "string" && cfg.userId ? cfg.userId : "openclaw_memory";
|
|
112
104
|
|
|
113
105
|
return {
|
|
114
106
|
apiKey,
|
|
@@ -365,6 +357,9 @@ function stripInjectedContext(text: string): string {
|
|
|
365
357
|
return text.replace(/<relevant-memories>[\s\S]*?<\/relevant-memories>\s*/g, "").trim();
|
|
366
358
|
}
|
|
367
359
|
|
|
360
|
+
const CONFIG_REQUIRED_MESSAGE =
|
|
361
|
+
"Memory plugin is not configured. Please add apiKey and userId to ~/.openclaw/openclaw.json under plugins.entries.modelstudio-memory-for-openclaw.config";
|
|
362
|
+
|
|
368
363
|
// ============================================================================
|
|
369
364
|
// Plugin Definition
|
|
370
365
|
// ============================================================================
|
|
@@ -385,6 +380,12 @@ const modelstudioMemoryPlugin = {
|
|
|
385
380
|
api.logger
|
|
386
381
|
);
|
|
387
382
|
|
|
383
|
+
if (!cfg.apiKey) {
|
|
384
|
+
const msg =
|
|
385
|
+
"[modelstudio-memory] apiKey not configured. Memory features disabled. Add apiKey to ~/.openclaw/openclaw.json under plugins.entries.modelstudio-memory-for-openclaw.config";
|
|
386
|
+
api.logger.warn(msg);
|
|
387
|
+
console.warn(msg);
|
|
388
|
+
}
|
|
388
389
|
api.logger.info(
|
|
389
390
|
`modelstudio-memory: registered (user: ${cfg.userId}, autoCapture: ${cfg.autoCapture}, autoRecall: ${cfg.autoRecall})`
|
|
390
391
|
);
|
|
@@ -405,6 +406,12 @@ const modelstudioMemoryPlugin = {
|
|
|
405
406
|
),
|
|
406
407
|
}),
|
|
407
408
|
async execute(_id, params) {
|
|
409
|
+
if (!cfg.apiKey) {
|
|
410
|
+
return {
|
|
411
|
+
content: [{ type: "text", text: CONFIG_REQUIRED_MESSAGE }],
|
|
412
|
+
isError: true,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
408
415
|
try {
|
|
409
416
|
const limit = Math.min(
|
|
410
417
|
Math.max(1, params.limit ?? cfg.topK),
|
|
@@ -476,6 +483,12 @@ const modelstudioMemoryPlugin = {
|
|
|
476
483
|
content: Type.String({ description: "Content to store" }),
|
|
477
484
|
}),
|
|
478
485
|
async execute(_id, params) {
|
|
486
|
+
if (!cfg.apiKey) {
|
|
487
|
+
return {
|
|
488
|
+
content: [{ type: "text", text: CONFIG_REQUIRED_MESSAGE }],
|
|
489
|
+
isError: true,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
479
492
|
try {
|
|
480
493
|
const result = await client.addCustomContent(params.content);
|
|
481
494
|
|
|
@@ -521,6 +534,12 @@ const modelstudioMemoryPlugin = {
|
|
|
521
534
|
),
|
|
522
535
|
}),
|
|
523
536
|
async execute(_id, params) {
|
|
537
|
+
if (!cfg.apiKey) {
|
|
538
|
+
return {
|
|
539
|
+
content: [{ type: "text", text: CONFIG_REQUIRED_MESSAGE }],
|
|
540
|
+
isError: true,
|
|
541
|
+
};
|
|
542
|
+
}
|
|
524
543
|
try {
|
|
525
544
|
const page = Math.max(1, params.page ?? 1);
|
|
526
545
|
const pageSize = Math.min(100, Math.max(1, params.pageSize ?? 10));
|
|
@@ -581,6 +600,12 @@ const modelstudioMemoryPlugin = {
|
|
|
581
600
|
index: Type.Optional(Type.Number({ description: "Delete Nth memory (1-based)" })),
|
|
582
601
|
}),
|
|
583
602
|
async execute(_id, params) {
|
|
603
|
+
if (!cfg.apiKey) {
|
|
604
|
+
return {
|
|
605
|
+
content: [{ type: "text", text: CONFIG_REQUIRED_MESSAGE }],
|
|
606
|
+
isError: true,
|
|
607
|
+
};
|
|
608
|
+
}
|
|
584
609
|
try {
|
|
585
610
|
let targetId = params.memoryId;
|
|
586
611
|
|
|
@@ -698,6 +723,12 @@ const modelstudioMemoryPlugin = {
|
|
|
698
723
|
// ========== autoRecall ==========
|
|
699
724
|
if (cfg.autoRecall) {
|
|
700
725
|
api.on("before_agent_start", async (event) => {
|
|
726
|
+
if (!cfg.apiKey) {
|
|
727
|
+
return {
|
|
728
|
+
prependSystemContext:
|
|
729
|
+
"Note: Memory plugin is not configured (apiKey missing). Long-term memory is disabled. Ask the user to add apiKey to ~/.openclaw/openclaw.json under plugins.entries.modelstudio-memory-for-openclaw.config and restart the gateway.",
|
|
730
|
+
};
|
|
731
|
+
}
|
|
701
732
|
const prompt = extractTextContent(event.prompt);
|
|
702
733
|
if (!prompt || prompt.length < cfg.recallMinPromptLength) {
|
|
703
734
|
return;
|
|
@@ -731,7 +762,7 @@ const modelstudioMemoryPlugin = {
|
|
|
731
762
|
// ========== autoCapture ==========
|
|
732
763
|
if (cfg.autoCapture) {
|
|
733
764
|
api.on("agent_end", async (event) => {
|
|
734
|
-
if (!event.success || !event.messages) {
|
|
765
|
+
if (!cfg.apiKey || !event.success || !event.messages) {
|
|
735
766
|
return;
|
|
736
767
|
}
|
|
737
768
|
|
|
@@ -806,6 +837,10 @@ const modelstudioMemoryPlugin = {
|
|
|
806
837
|
.argument("<query>", "Search query")
|
|
807
838
|
.option("--limit <n>", "Max results", String(cfg.topK))
|
|
808
839
|
.action(async (query: string, opts: { limit: string }) => {
|
|
840
|
+
if (!cfg.apiKey) {
|
|
841
|
+
console.error(CONFIG_REQUIRED_MESSAGE);
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
809
844
|
try {
|
|
810
845
|
const limit = Math.min(100, Math.max(1, parseInt(opts.limit, 10) || cfg.topK));
|
|
811
846
|
const cleanQuery = extractTextContent(query) || query.trim();
|
|
@@ -840,6 +875,10 @@ const modelstudioMemoryPlugin = {
|
|
|
840
875
|
.command("stats")
|
|
841
876
|
.description("Show memory statistics")
|
|
842
877
|
.action(async () => {
|
|
878
|
+
if (!cfg.apiKey) {
|
|
879
|
+
console.error(CONFIG_REQUIRED_MESSAGE);
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
843
882
|
try {
|
|
844
883
|
const result = await client.listMemory(1, 1);
|
|
845
884
|
console.log(`User: ${cfg.userId}`);
|
|
@@ -859,6 +898,10 @@ const modelstudioMemoryPlugin = {
|
|
|
859
898
|
.option("--page <n>", "Page number", "1")
|
|
860
899
|
.option("--size <n>", "Page size", "10")
|
|
861
900
|
.action(async (opts: { page: string; size: string }) => {
|
|
901
|
+
if (!cfg.apiKey) {
|
|
902
|
+
console.error(CONFIG_REQUIRED_MESSAGE);
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
862
905
|
try {
|
|
863
906
|
const page = Math.max(1, parseInt(opts.page, 10) || 1);
|
|
864
907
|
const size = Math.min(100, Math.max(1, parseInt(opts.size, 10) || 10));
|
package/openclaw.plugin.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "modelstudio-memory-for-openclaw",
|
|
4
4
|
"description": "阿里云百炼长期记忆服务,提供自动记忆捕获和召回能力",
|
|
5
5
|
"kind": "memory",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.3",
|
|
7
7
|
"configSchema": {
|
|
8
8
|
"type": "object",
|
|
9
9
|
"additionalProperties": false,
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"userId": {
|
|
16
16
|
"type": "string",
|
|
17
|
-
"description": "用户 ID
|
|
17
|
+
"description": "用户 ID,用于隔离不同用户的记忆(默认 'openclaw_memory')"
|
|
18
18
|
},
|
|
19
19
|
"baseUrl": {
|
|
20
20
|
"type": "string",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"userId": {
|
|
68
68
|
"label": "用户 ID",
|
|
69
|
-
"placeholder": "
|
|
69
|
+
"placeholder": "openclaw_memory"
|
|
70
70
|
},
|
|
71
71
|
"baseUrl": {
|
|
72
72
|
"label": "API Endpoint",
|