@modelstudio/modelstudio-memory-for-openclaw 1.0.1 → 1.0.2

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 CHANGED
@@ -58,7 +58,7 @@ openclaw modelstudio-memory stats
58
58
  config: {
59
59
  // 必需配置
60
60
  "apiKey": "your-dashscope-api-key",
61
- "userId": "user_001",
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` | | - | 用户 ID,用于隔离不同用户的记忆 |
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 is required (plain text in openclaw.json)
101
+ // apiKey: allow empty at parse time; tools return config prompt when missing
102
102
  const apiKey = typeof cfg.apiKey === "string" ? cfg.apiKey : "";
103
- if (!apiKey) {
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. Get API Key: https://help.aliyun.com/zh/model-studio/get-api-key";
362
+
368
363
  // ============================================================================
369
364
  // Plugin Definition
370
365
  // ============================================================================
@@ -385,6 +380,11 @@ const modelstudioMemoryPlugin = {
385
380
  api.logger
386
381
  );
387
382
 
383
+ if (!cfg.apiKey) {
384
+ api.logger.warn(
385
+ "modelstudio-memory: apiKey not configured. Memory features disabled until config is added to openclaw.json."
386
+ );
387
+ }
388
388
  api.logger.info(
389
389
  `modelstudio-memory: registered (user: ${cfg.userId}, autoCapture: ${cfg.autoCapture}, autoRecall: ${cfg.autoRecall})`
390
390
  );
@@ -405,6 +405,12 @@ const modelstudioMemoryPlugin = {
405
405
  ),
406
406
  }),
407
407
  async execute(_id, params) {
408
+ if (!cfg.apiKey) {
409
+ return {
410
+ content: [{ type: "text", text: CONFIG_REQUIRED_MESSAGE }],
411
+ isError: true,
412
+ };
413
+ }
408
414
  try {
409
415
  const limit = Math.min(
410
416
  Math.max(1, params.limit ?? cfg.topK),
@@ -476,6 +482,12 @@ const modelstudioMemoryPlugin = {
476
482
  content: Type.String({ description: "Content to store" }),
477
483
  }),
478
484
  async execute(_id, params) {
485
+ if (!cfg.apiKey) {
486
+ return {
487
+ content: [{ type: "text", text: CONFIG_REQUIRED_MESSAGE }],
488
+ isError: true,
489
+ };
490
+ }
479
491
  try {
480
492
  const result = await client.addCustomContent(params.content);
481
493
 
@@ -521,6 +533,12 @@ const modelstudioMemoryPlugin = {
521
533
  ),
522
534
  }),
523
535
  async execute(_id, params) {
536
+ if (!cfg.apiKey) {
537
+ return {
538
+ content: [{ type: "text", text: CONFIG_REQUIRED_MESSAGE }],
539
+ isError: true,
540
+ };
541
+ }
524
542
  try {
525
543
  const page = Math.max(1, params.page ?? 1);
526
544
  const pageSize = Math.min(100, Math.max(1, params.pageSize ?? 10));
@@ -581,6 +599,12 @@ const modelstudioMemoryPlugin = {
581
599
  index: Type.Optional(Type.Number({ description: "Delete Nth memory (1-based)" })),
582
600
  }),
583
601
  async execute(_id, params) {
602
+ if (!cfg.apiKey) {
603
+ return {
604
+ content: [{ type: "text", text: CONFIG_REQUIRED_MESSAGE }],
605
+ isError: true,
606
+ };
607
+ }
584
608
  try {
585
609
  let targetId = params.memoryId;
586
610
 
@@ -698,6 +722,7 @@ const modelstudioMemoryPlugin = {
698
722
  // ========== autoRecall ==========
699
723
  if (cfg.autoRecall) {
700
724
  api.on("before_agent_start", async (event) => {
725
+ if (!cfg.apiKey) return;
701
726
  const prompt = extractTextContent(event.prompt);
702
727
  if (!prompt || prompt.length < cfg.recallMinPromptLength) {
703
728
  return;
@@ -731,7 +756,7 @@ const modelstudioMemoryPlugin = {
731
756
  // ========== autoCapture ==========
732
757
  if (cfg.autoCapture) {
733
758
  api.on("agent_end", async (event) => {
734
- if (!event.success || !event.messages) {
759
+ if (!cfg.apiKey || !event.success || !event.messages) {
735
760
  return;
736
761
  }
737
762
 
@@ -806,6 +831,10 @@ const modelstudioMemoryPlugin = {
806
831
  .argument("<query>", "Search query")
807
832
  .option("--limit <n>", "Max results", String(cfg.topK))
808
833
  .action(async (query: string, opts: { limit: string }) => {
834
+ if (!cfg.apiKey) {
835
+ console.error(CONFIG_REQUIRED_MESSAGE);
836
+ return;
837
+ }
809
838
  try {
810
839
  const limit = Math.min(100, Math.max(1, parseInt(opts.limit, 10) || cfg.topK));
811
840
  const cleanQuery = extractTextContent(query) || query.trim();
@@ -840,6 +869,10 @@ const modelstudioMemoryPlugin = {
840
869
  .command("stats")
841
870
  .description("Show memory statistics")
842
871
  .action(async () => {
872
+ if (!cfg.apiKey) {
873
+ console.error(CONFIG_REQUIRED_MESSAGE);
874
+ return;
875
+ }
843
876
  try {
844
877
  const result = await client.listMemory(1, 1);
845
878
  console.log(`User: ${cfg.userId}`);
@@ -859,6 +892,10 @@ const modelstudioMemoryPlugin = {
859
892
  .option("--page <n>", "Page number", "1")
860
893
  .option("--size <n>", "Page size", "10")
861
894
  .action(async (opts: { page: string; size: string }) => {
895
+ if (!cfg.apiKey) {
896
+ console.error(CONFIG_REQUIRED_MESSAGE);
897
+ return;
898
+ }
862
899
  try {
863
900
  const page = Math.max(1, parseInt(opts.page, 10) || 1);
864
901
  const size = Math.min(100, Math.max(1, parseInt(opts.size, 10) || 10));
@@ -3,7 +3,7 @@
3
3
  "name": "modelstudio-memory-for-openclaw",
4
4
  "description": "阿里云百炼长期记忆服务,提供自动记忆捕获和召回能力",
5
5
  "kind": "memory",
6
- "version": "1.0.1",
6
+ "version": "1.0.2",
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": "user_001"
69
+ "placeholder": "openclaw_memory"
70
70
  },
71
71
  "baseUrl": {
72
72
  "label": "API Endpoint",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelstudio/modelstudio-memory-for-openclaw",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "description": "阿里云百炼长期记忆服务 OpenClaw 插件",
6
6
  "license": "Apache-2.0",