@memtensor/memos-local-openclaw-plugin 1.0.4-beta.6 → 1.0.4-beta.8
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 +38 -21
- package/dist/capture/index.d.ts +1 -1
- package/dist/capture/index.d.ts.map +1 -1
- package/dist/capture/index.js +29 -3
- package/dist/capture/index.js.map +1 -1
- package/dist/client/connector.d.ts +29 -0
- package/dist/client/connector.d.ts.map +1 -0
- package/dist/client/connector.js +231 -0
- package/dist/client/connector.js.map +1 -0
- package/dist/client/hub.d.ts +61 -0
- package/dist/client/hub.d.ts.map +1 -0
- package/dist/client/hub.js +170 -0
- package/dist/client/hub.js.map +1 -0
- package/dist/client/skill-sync.d.ts +36 -0
- package/dist/client/skill-sync.d.ts.map +1 -0
- package/dist/client/skill-sync.js +226 -0
- package/dist/client/skill-sync.js.map +1 -0
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +70 -3
- package/dist/config.js.map +1 -1
- package/dist/embedding/index.d.ts +4 -2
- package/dist/embedding/index.d.ts.map +1 -1
- package/dist/embedding/index.js +17 -1
- package/dist/embedding/index.js.map +1 -1
- package/dist/hub/auth.d.ts +19 -0
- package/dist/hub/auth.d.ts.map +1 -0
- package/dist/hub/auth.js +70 -0
- package/dist/hub/auth.js.map +1 -0
- package/dist/hub/server.d.ts +48 -0
- package/dist/hub/server.d.ts.map +1 -0
- package/dist/hub/server.js +922 -0
- package/dist/hub/server.js.map +1 -0
- package/dist/hub/user-manager.d.ts +31 -0
- package/dist/hub/user-manager.d.ts.map +1 -0
- package/dist/hub/user-manager.js +129 -0
- package/dist/hub/user-manager.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/ingest/providers/index.d.ts +10 -2
- package/dist/ingest/providers/index.d.ts.map +1 -1
- package/dist/ingest/providers/index.js +203 -6
- package/dist/ingest/providers/index.js.map +1 -1
- package/dist/ingest/providers/openai.d.ts +1 -0
- package/dist/ingest/providers/openai.d.ts.map +1 -1
- package/dist/ingest/providers/openai.js +1 -0
- package/dist/ingest/providers/openai.js.map +1 -1
- package/dist/ingest/task-processor.js +1 -1
- package/dist/ingest/task-processor.js.map +1 -1
- package/dist/openclaw-api.d.ts +53 -0
- package/dist/openclaw-api.d.ts.map +1 -0
- package/dist/openclaw-api.js +189 -0
- package/dist/openclaw-api.js.map +1 -0
- package/dist/recall/engine.js +1 -1
- package/dist/recall/engine.js.map +1 -1
- package/dist/shared/llm-call.d.ts +4 -1
- package/dist/shared/llm-call.d.ts.map +1 -1
- package/dist/shared/llm-call.js +14 -1
- package/dist/shared/llm-call.js.map +1 -1
- package/dist/sharing/types.contract.d.ts +2 -0
- package/dist/sharing/types.contract.d.ts.map +1 -0
- package/dist/sharing/types.contract.js +3 -0
- package/dist/sharing/types.contract.js.map +1 -0
- package/dist/sharing/types.d.ts +80 -0
- package/dist/sharing/types.d.ts.map +1 -0
- package/dist/sharing/types.js +3 -0
- package/dist/sharing/types.js.map +1 -0
- package/dist/skill/evaluator.d.ts.map +1 -1
- package/dist/skill/evaluator.js +2 -2
- package/dist/skill/evaluator.js.map +1 -1
- package/dist/skill/generator.d.ts.map +1 -1
- package/dist/skill/generator.js +4 -4
- package/dist/skill/generator.js.map +1 -1
- package/dist/skill/upgrader.js +1 -1
- package/dist/skill/upgrader.js.map +1 -1
- package/dist/skill/validator.js +1 -1
- package/dist/skill/validator.js.map +1 -1
- package/dist/storage/ensure-binding.d.ts.map +1 -1
- package/dist/storage/ensure-binding.js +3 -1
- package/dist/storage/ensure-binding.js.map +1 -1
- package/dist/storage/sqlite.d.ts +332 -1
- package/dist/storage/sqlite.d.ts.map +1 -1
- package/dist/storage/sqlite.js +913 -4
- package/dist/storage/sqlite.js.map +1 -1
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +3 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/memory-search.d.ts +5 -2
- package/dist/tools/memory-search.d.ts.map +1 -1
- package/dist/tools/memory-search.js +50 -7
- package/dist/tools/memory-search.js.map +1 -1
- package/dist/tools/network-memory-detail.d.ts +4 -0
- package/dist/tools/network-memory-detail.d.ts.map +1 -0
- package/dist/tools/network-memory-detail.js +34 -0
- package/dist/tools/network-memory-detail.js.map +1 -0
- package/dist/types.d.ts +48 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/viewer/html.d.ts.map +1 -1
- package/dist/viewer/html.js +4299 -511
- package/dist/viewer/html.js.map +1 -1
- package/dist/viewer/server.d.ts +65 -0
- package/dist/viewer/server.d.ts.map +1 -1
- package/dist/viewer/server.js +1844 -90
- package/dist/viewer/server.js.map +1 -1
- package/index.ts +767 -41
- package/openclaw.plugin.json +3 -2
- package/package.json +3 -3
- package/scripts/postinstall.cjs +282 -45
- package/skill/memos-memory-guide/SKILL.md +82 -20
- package/src/capture/index.ts +30 -2
- package/src/client/connector.ts +225 -0
- package/src/client/hub.ts +207 -0
- package/src/client/skill-sync.ts +216 -0
- package/src/config.ts +92 -3
- package/src/embedding/index.ts +21 -1
- package/src/hub/auth.ts +78 -0
- package/src/hub/server.ts +906 -0
- package/src/hub/user-manager.ts +143 -0
- package/src/index.ts +13 -5
- package/src/ingest/providers/index.ts +240 -6
- package/src/ingest/providers/openai.ts +1 -1
- package/src/ingest/task-processor.ts +1 -1
- package/src/openclaw-api.ts +287 -0
- package/src/recall/engine.ts +1 -1
- package/src/shared/llm-call.ts +18 -2
- package/src/sharing/types.contract.ts +40 -0
- package/src/sharing/types.ts +102 -0
- package/src/skill/evaluator.ts +3 -2
- package/src/skill/generator.ts +6 -4
- package/src/skill/upgrader.ts +1 -1
- package/src/skill/validator.ts +1 -1
- package/src/storage/ensure-binding.ts +3 -1
- package/src/storage/sqlite.ts +1164 -4
- package/src/tools/index.ts +1 -0
- package/src/tools/memory-search.ts +58 -8
- package/src/tools/network-memory-detail.ts +34 -0
- package/src/types.ts +43 -2
- package/src/viewer/html.ts +4299 -511
- package/src/viewer/server.ts +1688 -73
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { randomUUID, createHash } from "crypto";
|
|
2
|
+
import { issueUserToken, verifyUserToken } from "./auth";
|
|
3
|
+
import type { Logger } from "../types";
|
|
4
|
+
import type { UserInfo } from "../sharing/types";
|
|
5
|
+
import type { SqliteStore } from "../storage/sqlite";
|
|
6
|
+
|
|
7
|
+
type ManagedHubUser = UserInfo & { tokenHash: string; createdAt: number; approvedAt: number | null; lastIp: string; lastActiveAt: number | null };
|
|
8
|
+
|
|
9
|
+
export class HubUserManager {
|
|
10
|
+
constructor(private store: SqliteStore, private log: Logger) {}
|
|
11
|
+
|
|
12
|
+
createPendingUser(input: { username: string; deviceName?: string }): ManagedHubUser {
|
|
13
|
+
const user = {
|
|
14
|
+
id: randomUUID(),
|
|
15
|
+
username: input.username,
|
|
16
|
+
deviceName: input.deviceName,
|
|
17
|
+
role: "member" as const,
|
|
18
|
+
status: "pending" as const,
|
|
19
|
+
groups: [],
|
|
20
|
+
tokenHash: "",
|
|
21
|
+
createdAt: Date.now(),
|
|
22
|
+
approvedAt: null,
|
|
23
|
+
lastIp: "",
|
|
24
|
+
lastActiveAt: null,
|
|
25
|
+
};
|
|
26
|
+
this.store.upsertHubUser(user);
|
|
27
|
+
return user;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
listPendingUsers(): ManagedHubUser[] {
|
|
31
|
+
return this.store.listHubUsers("pending");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
approveUser(userId: string, token: string): ManagedHubUser | null {
|
|
35
|
+
const user = this.store.getHubUser(userId);
|
|
36
|
+
if (!user) return null;
|
|
37
|
+
const updated = {
|
|
38
|
+
...user,
|
|
39
|
+
status: "active" as const,
|
|
40
|
+
tokenHash: createHash("sha256").update(token).digest("hex"),
|
|
41
|
+
approvedAt: Date.now(),
|
|
42
|
+
};
|
|
43
|
+
this.store.upsertHubUser(updated);
|
|
44
|
+
return updated;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
ensureBootstrapAdmin(secret: string, username = "admin", bootstrapUserId?: string, bootstrapToken?: string): { user: ManagedHubUser; token: string } {
|
|
48
|
+
if (bootstrapUserId) {
|
|
49
|
+
const bootstrapUser = this.store.getHubUser(bootstrapUserId);
|
|
50
|
+
if (bootstrapUser && bootstrapUser.role === "admin" && bootstrapUser.status === "active") {
|
|
51
|
+
if (bootstrapToken && bootstrapUser.tokenHash === createHash("sha256").update(bootstrapToken).digest("hex") && verifyUserToken(bootstrapToken, secret)) {
|
|
52
|
+
return { user: bootstrapUser, token: bootstrapToken };
|
|
53
|
+
}
|
|
54
|
+
const refreshedToken = issueUserToken(
|
|
55
|
+
{ userId: bootstrapUser.id, username: bootstrapUser.username, role: bootstrapUser.role, status: bootstrapUser.status },
|
|
56
|
+
secret,
|
|
57
|
+
3650 * 24 * 60 * 60 * 1000,
|
|
58
|
+
);
|
|
59
|
+
const refreshedUser: ManagedHubUser = {
|
|
60
|
+
...bootstrapUser,
|
|
61
|
+
tokenHash: createHash("sha256").update(refreshedToken).digest("hex"),
|
|
62
|
+
};
|
|
63
|
+
this.store.upsertHubUser(refreshedUser);
|
|
64
|
+
return { user: refreshedUser, token: refreshedToken };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const existing = this.store.listHubUsers().find((user) => user.role === "admin" && user.status === "active");
|
|
69
|
+
if (existing) {
|
|
70
|
+
const refreshedToken = issueUserToken(
|
|
71
|
+
{ userId: existing.id, username: existing.username, role: existing.role, status: existing.status },
|
|
72
|
+
secret,
|
|
73
|
+
3650 * 24 * 60 * 60 * 1000,
|
|
74
|
+
);
|
|
75
|
+
const refreshedUser: ManagedHubUser = {
|
|
76
|
+
...existing,
|
|
77
|
+
tokenHash: createHash("sha256").update(refreshedToken).digest("hex"),
|
|
78
|
+
};
|
|
79
|
+
this.store.upsertHubUser(refreshedUser);
|
|
80
|
+
return { user: refreshedUser, token: refreshedToken };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const user: ManagedHubUser = {
|
|
84
|
+
id: randomUUID(),
|
|
85
|
+
username,
|
|
86
|
+
deviceName: "hub",
|
|
87
|
+
role: "admin",
|
|
88
|
+
status: "active",
|
|
89
|
+
groups: [],
|
|
90
|
+
tokenHash: "",
|
|
91
|
+
createdAt: Date.now(),
|
|
92
|
+
approvedAt: Date.now(),
|
|
93
|
+
lastIp: "",
|
|
94
|
+
lastActiveAt: null,
|
|
95
|
+
};
|
|
96
|
+
const token = issueUserToken(
|
|
97
|
+
{ userId: user.id, username: user.username, role: user.role, status: user.status },
|
|
98
|
+
secret,
|
|
99
|
+
3650 * 24 * 60 * 60 * 1000,
|
|
100
|
+
);
|
|
101
|
+
user.tokenHash = createHash("sha256").update(token).digest("hex");
|
|
102
|
+
this.store.upsertHubUser(user);
|
|
103
|
+
return { user, token };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
isUsernameTaken(username: string, excludeUserId?: string): boolean {
|
|
107
|
+
const users = this.store.listHubUsers();
|
|
108
|
+
return users.some(u => u.username === username && u.id !== excludeUserId);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
updateUsername(userId: string, newUsername: string): ManagedHubUser | null {
|
|
112
|
+
const user = this.store.getHubUser(userId);
|
|
113
|
+
if (!user) return null;
|
|
114
|
+
const updated = { ...user, username: newUsername };
|
|
115
|
+
this.store.upsertHubUser(updated);
|
|
116
|
+
return updated;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
rejectUser(userId: string): ManagedHubUser | null {
|
|
120
|
+
const user = this.store.getHubUser(userId);
|
|
121
|
+
if (!user) return null;
|
|
122
|
+
const updated = {
|
|
123
|
+
...user,
|
|
124
|
+
status: "rejected" as const,
|
|
125
|
+
approvedAt: Date.now(),
|
|
126
|
+
};
|
|
127
|
+
this.store.upsertHubUser(updated);
|
|
128
|
+
return updated;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
resetToPending(userId: string): ManagedHubUser | null {
|
|
132
|
+
const user = this.store.getHubUser(userId);
|
|
133
|
+
if (!user) return null;
|
|
134
|
+
const updated = {
|
|
135
|
+
...user,
|
|
136
|
+
status: "pending" as const,
|
|
137
|
+
tokenHash: "",
|
|
138
|
+
approvedAt: null,
|
|
139
|
+
};
|
|
140
|
+
this.store.upsertHubUser(updated);
|
|
141
|
+
return updated;
|
|
142
|
+
}
|
|
143
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,8 +6,9 @@ import { Embedder } from "./embedding";
|
|
|
6
6
|
import { IngestWorker } from "./ingest/worker";
|
|
7
7
|
import { RecallEngine } from "./recall/engine";
|
|
8
8
|
import { captureMessages } from "./capture";
|
|
9
|
-
import { createMemorySearchTool, createMemoryTimelineTool, createMemoryGetTool } from "./tools";
|
|
9
|
+
import { createMemorySearchTool, createMemoryTimelineTool, createMemoryGetTool, createNetworkMemoryDetailTool } from "./tools";
|
|
10
10
|
import type { MemosLocalConfig, ToolDefinition, Logger } from "./types";
|
|
11
|
+
import type { HostModelsConfig } from "./openclaw-api";
|
|
11
12
|
|
|
12
13
|
export interface MemosLocalPlugin {
|
|
13
14
|
id: string;
|
|
@@ -23,6 +24,7 @@ export interface PluginInitOptions {
|
|
|
23
24
|
workspaceDir?: string;
|
|
24
25
|
config?: Partial<MemosLocalConfig>;
|
|
25
26
|
log?: Logger;
|
|
27
|
+
hostModels?: HostModelsConfig;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
/**
|
|
@@ -51,21 +53,24 @@ export interface PluginInitOptions {
|
|
|
51
53
|
export function initPlugin(opts: PluginInitOptions = {}): MemosLocalPlugin {
|
|
52
54
|
const stateDir = opts.stateDir ?? defaultStateDir();
|
|
53
55
|
const workspaceDir = opts.workspaceDir ?? process.cwd();
|
|
54
|
-
const ctx = buildContext(stateDir, workspaceDir, opts.config, opts.log);
|
|
56
|
+
const ctx = buildContext(stateDir, workspaceDir, opts.config, opts.log, opts.hostModels);
|
|
55
57
|
|
|
56
58
|
ctx.log.info("Initializing memos-local plugin...");
|
|
57
59
|
|
|
58
60
|
ensureSqliteBinding(ctx.log);
|
|
59
61
|
|
|
60
62
|
const store = new SqliteStore(ctx.config.storage!.dbPath!, ctx.log);
|
|
61
|
-
const embedder = new Embedder(ctx.config.embedding, ctx.log);
|
|
63
|
+
const embedder = new Embedder(ctx.config.embedding, ctx.log, ctx.openclawAPI);
|
|
62
64
|
const worker = new IngestWorker(store, embedder, ctx);
|
|
63
65
|
const engine = new RecallEngine(store, embedder, ctx);
|
|
64
66
|
|
|
67
|
+
const sharedState = { lastSearchTime: 0 };
|
|
68
|
+
|
|
65
69
|
const tools: ToolDefinition[] = [
|
|
66
|
-
createMemorySearchTool(engine),
|
|
70
|
+
createMemorySearchTool(engine, store, ctx, sharedState),
|
|
67
71
|
createMemoryTimelineTool(store),
|
|
68
72
|
createMemoryGetTool(store),
|
|
73
|
+
createNetworkMemoryDetailTool(store, ctx),
|
|
69
74
|
];
|
|
70
75
|
|
|
71
76
|
ctx.log.info(`Plugin ready. DB: ${ctx.config.storage!.dbPath}, Embedding: ${embedder.provider}`);
|
|
@@ -84,7 +89,10 @@ export function initPlugin(opts: PluginInitOptions = {}): MemosLocalPlugin {
|
|
|
84
89
|
const turnId = uuid();
|
|
85
90
|
const tag = ctx.config.capture?.evidenceWrapperTag ?? "STORED_MEMORY";
|
|
86
91
|
|
|
87
|
-
const
|
|
92
|
+
const userSearchTime = sharedState.lastSearchTime || 0;
|
|
93
|
+
sharedState.lastSearchTime = 0;
|
|
94
|
+
|
|
95
|
+
const captured = captureMessages(messages, session, turnId, tag, ctx.log, owner, userSearchTime);
|
|
88
96
|
if (captured.length > 0) {
|
|
89
97
|
worker.enqueue(captured);
|
|
90
98
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import * as path from "path";
|
|
3
|
-
import type { SummarizerConfig, SummaryProvider, Logger } from "../../types";
|
|
4
|
-
import { summarizeOpenAI, summarizeTaskOpenAI, generateTaskTitleOpenAI, judgeNewTopicOpenAI, filterRelevantOpenAI, judgeDedupOpenAI } from "./openai";
|
|
3
|
+
import type { SummarizerConfig, SummaryProvider, Logger, OpenClawAPI } from "../../types";
|
|
4
|
+
import { summarizeOpenAI, summarizeTaskOpenAI, generateTaskTitleOpenAI, judgeNewTopicOpenAI, filterRelevantOpenAI, judgeDedupOpenAI, parseFilterResult, parseDedupResult } from "./openai";
|
|
5
5
|
import type { FilterResult, DedupResult } from "./openai";
|
|
6
6
|
export type { FilterResult, DedupResult } from "./openai";
|
|
7
7
|
import { summarizeAnthropic, summarizeTaskAnthropic, generateTaskTitleAnthropic, judgeNewTopicAnthropic, filterRelevantAnthropic, judgeDedupAnthropic } from "./anthropic";
|
|
@@ -154,6 +154,7 @@ export class Summarizer {
|
|
|
154
154
|
constructor(
|
|
155
155
|
private cfg: SummarizerConfig | undefined,
|
|
156
156
|
private log: Logger,
|
|
157
|
+
private openclawAPI?: OpenClawAPI,
|
|
157
158
|
strongCfg?: SummarizerConfig,
|
|
158
159
|
) {
|
|
159
160
|
this.strongCfg = strongCfg;
|
|
@@ -163,11 +164,20 @@ export class Summarizer {
|
|
|
163
164
|
/**
|
|
164
165
|
* Ordered config chain: strongCfg → cfg → fallbackCfg (OpenClaw native model).
|
|
165
166
|
* Returns configs that are defined, in priority order.
|
|
167
|
+
* Openclaw configs without hostCompletion capability or without openclawAPI are excluded.
|
|
166
168
|
*/
|
|
167
169
|
private getConfigChain(): SummarizerConfig[] {
|
|
168
170
|
const chain: SummarizerConfig[] = [];
|
|
169
171
|
if (this.strongCfg) chain.push(this.strongCfg);
|
|
170
|
-
if (this.cfg)
|
|
172
|
+
if (this.cfg) {
|
|
173
|
+
if (this.cfg.provider === "openclaw") {
|
|
174
|
+
if (this.cfg.capabilities?.hostCompletion === true && this.openclawAPI) {
|
|
175
|
+
chain.push(this.cfg);
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
chain.push(this.cfg);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
171
181
|
if (this.fallbackCfg) chain.push(this.fallbackCfg);
|
|
172
182
|
return chain;
|
|
173
183
|
}
|
|
@@ -251,7 +261,9 @@ export class Summarizer {
|
|
|
251
261
|
return taskFallback(text);
|
|
252
262
|
}
|
|
253
263
|
|
|
254
|
-
const result = await this.tryChain("summarizeTask", (cfg) =>
|
|
264
|
+
const result = await this.tryChain("summarizeTask", (cfg) =>
|
|
265
|
+
cfg.provider === "openclaw" ? this.summarizeTaskOpenClaw(text) : callSummarizeTask(cfg, text, this.log),
|
|
266
|
+
);
|
|
255
267
|
return result ?? taskFallback(text);
|
|
256
268
|
}
|
|
257
269
|
|
|
@@ -290,7 +302,11 @@ export class Summarizer {
|
|
|
290
302
|
if (!this.cfg && !this.fallbackCfg) return null;
|
|
291
303
|
if (candidates.length === 0) return { relevant: [], sufficient: true };
|
|
292
304
|
|
|
293
|
-
const result = await this.tryChain("filterRelevant", (cfg) =>
|
|
305
|
+
const result = await this.tryChain("filterRelevant", (cfg) =>
|
|
306
|
+
cfg.provider === "openclaw"
|
|
307
|
+
? this.filterRelevantOpenClaw(query, candidates)
|
|
308
|
+
: callFilterRelevant(cfg, query, candidates, this.log),
|
|
309
|
+
);
|
|
294
310
|
return result ?? null;
|
|
295
311
|
}
|
|
296
312
|
|
|
@@ -301,13 +317,144 @@ export class Summarizer {
|
|
|
301
317
|
if (!this.cfg && !this.fallbackCfg) return null;
|
|
302
318
|
if (candidates.length === 0) return null;
|
|
303
319
|
|
|
304
|
-
const result = await this.tryChain("judgeDedup", (cfg) =>
|
|
320
|
+
const result = await this.tryChain("judgeDedup", (cfg) =>
|
|
321
|
+
cfg.provider === "openclaw"
|
|
322
|
+
? this.judgeDedupOpenClaw(newSummary, candidates)
|
|
323
|
+
: callJudgeDedup(cfg, newSummary, candidates, this.log),
|
|
324
|
+
);
|
|
305
325
|
return result ?? { action: "NEW", reason: "all_models_failed" };
|
|
306
326
|
}
|
|
307
327
|
|
|
308
328
|
getStrongConfig(): SummarizerConfig | undefined {
|
|
309
329
|
return this.strongCfg;
|
|
310
330
|
}
|
|
331
|
+
|
|
332
|
+
// ─── OpenClaw API Implementation ───
|
|
333
|
+
|
|
334
|
+
private requireOpenClawAPI(): void {
|
|
335
|
+
if (!this.openclawAPI) {
|
|
336
|
+
throw new Error(
|
|
337
|
+
"OpenClaw API not available. Ensure sharing.capabilities.hostCompletion is enabled in config."
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
private async summarizeOpenClaw(text: string): Promise<string> {
|
|
343
|
+
this.requireOpenClawAPI();
|
|
344
|
+
const prompt = [
|
|
345
|
+
`Summarize the text in ONE concise sentence (max 120 characters). IMPORTANT: Use the SAME language as the input text — if the input is Chinese, write Chinese; if English, write English. Preserve exact names, commands, error codes. No bullet points, no preamble — output only the sentence.`,
|
|
346
|
+
``,
|
|
347
|
+
text.slice(0, 2000),
|
|
348
|
+
].join("\n");
|
|
349
|
+
|
|
350
|
+
const response = await this.openclawAPI!.complete({
|
|
351
|
+
prompt,
|
|
352
|
+
maxTokens: 100,
|
|
353
|
+
temperature: 0,
|
|
354
|
+
model: this.cfg?.model,
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
return response.text.trim().slice(0, 200);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
private async summarizeTaskOpenClaw(text: string): Promise<string> {
|
|
361
|
+
this.requireOpenClawAPI();
|
|
362
|
+
const prompt = [
|
|
363
|
+
OPENCLAW_TASK_SUMMARY_PROMPT,
|
|
364
|
+
``,
|
|
365
|
+
text,
|
|
366
|
+
].join("\n");
|
|
367
|
+
|
|
368
|
+
const response = await this.openclawAPI!.complete({
|
|
369
|
+
prompt,
|
|
370
|
+
maxTokens: 4096,
|
|
371
|
+
temperature: 0.1,
|
|
372
|
+
model: this.cfg?.model,
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
return response.text.trim();
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
private async judgeNewTopicOpenClaw(currentContext: string, newMessage: string): Promise<boolean> {
|
|
379
|
+
this.requireOpenClawAPI();
|
|
380
|
+
const prompt = [
|
|
381
|
+
OPENCLAW_TOPIC_JUDGE_PROMPT,
|
|
382
|
+
``,
|
|
383
|
+
`CURRENT CONVERSATION SUMMARY:`,
|
|
384
|
+
currentContext,
|
|
385
|
+
``,
|
|
386
|
+
`NEW USER MESSAGE:`,
|
|
387
|
+
newMessage,
|
|
388
|
+
].join("\n");
|
|
389
|
+
|
|
390
|
+
const response = await this.openclawAPI!.complete({
|
|
391
|
+
prompt,
|
|
392
|
+
maxTokens: 10,
|
|
393
|
+
temperature: 0,
|
|
394
|
+
model: this.cfg?.model,
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
const answer = response.text.trim().toUpperCase();
|
|
398
|
+
this.log.debug(`Topic judge result: "${answer}"`);
|
|
399
|
+
return answer.startsWith("NEW");
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
private async filterRelevantOpenClaw(
|
|
403
|
+
query: string,
|
|
404
|
+
candidates: Array<{ index: number; role: string; content: string; time?: string }>,
|
|
405
|
+
): Promise<FilterResult> {
|
|
406
|
+
this.requireOpenClawAPI();
|
|
407
|
+
const candidateText = candidates
|
|
408
|
+
.map((c) => `${c.index}. [${c.role}] ${c.content}`)
|
|
409
|
+
.join("\n");
|
|
410
|
+
|
|
411
|
+
const prompt = [
|
|
412
|
+
OPENCLAW_FILTER_RELEVANT_PROMPT,
|
|
413
|
+
``,
|
|
414
|
+
`QUERY: ${query}`,
|
|
415
|
+
``,
|
|
416
|
+
`CANDIDATES:`,
|
|
417
|
+
candidateText,
|
|
418
|
+
].join("\n");
|
|
419
|
+
|
|
420
|
+
const response = await this.openclawAPI!.complete({
|
|
421
|
+
prompt,
|
|
422
|
+
maxTokens: 200,
|
|
423
|
+
temperature: 0,
|
|
424
|
+
model: this.cfg?.model,
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
return parseFilterResult(response.text.trim(), this.log);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
private async judgeDedupOpenClaw(
|
|
431
|
+
newSummary: string,
|
|
432
|
+
candidates: Array<{ index: number; summary: string; chunkId: string }>,
|
|
433
|
+
): Promise<DedupResult> {
|
|
434
|
+
this.requireOpenClawAPI();
|
|
435
|
+
const candidateText = candidates
|
|
436
|
+
.map((c) => `${c.index}. ${c.summary}`)
|
|
437
|
+
.join("\n");
|
|
438
|
+
|
|
439
|
+
const prompt = [
|
|
440
|
+
OPENCLAW_DEDUP_JUDGE_PROMPT,
|
|
441
|
+
``,
|
|
442
|
+
`NEW MEMORY:`,
|
|
443
|
+
newSummary,
|
|
444
|
+
``,
|
|
445
|
+
`EXISTING MEMORIES:`,
|
|
446
|
+
candidateText,
|
|
447
|
+
].join("\n");
|
|
448
|
+
|
|
449
|
+
const response = await this.openclawAPI!.complete({
|
|
450
|
+
prompt,
|
|
451
|
+
maxTokens: 300,
|
|
452
|
+
temperature: 0,
|
|
453
|
+
model: this.cfg?.model,
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
return parseDedupResult(response.text.trim(), this.log);
|
|
457
|
+
}
|
|
311
458
|
}
|
|
312
459
|
|
|
313
460
|
// ─── Dispatch helpers ───
|
|
@@ -483,3 +630,90 @@ function wordCount(text: string): number {
|
|
|
483
630
|
return count;
|
|
484
631
|
}
|
|
485
632
|
|
|
633
|
+
// ─── OpenClaw Prompt Templates ───
|
|
634
|
+
|
|
635
|
+
const OPENCLAW_TASK_SUMMARY_PROMPT = `You create a DETAILED task summary from a multi-turn conversation. This summary will be the ONLY record of this conversation, so it must preserve ALL important information.
|
|
636
|
+
|
|
637
|
+
CRITICAL LANGUAGE RULE: You MUST write in the SAME language as the user's messages. Chinese input → Chinese output. English input → English output. NEVER mix languages.
|
|
638
|
+
|
|
639
|
+
Output EXACTLY this structure:
|
|
640
|
+
|
|
641
|
+
📌 Title
|
|
642
|
+
A short, descriptive title (10-30 characters). Like a chat group name.
|
|
643
|
+
|
|
644
|
+
🎯 Goal
|
|
645
|
+
One sentence: what the user wanted to accomplish.
|
|
646
|
+
|
|
647
|
+
📋 Key Steps
|
|
648
|
+
- Describe each meaningful step in detail
|
|
649
|
+
- Include the ACTUAL content produced: code snippets, commands, config blocks, formulas, key paragraphs
|
|
650
|
+
- For code: include the function signature and core logic (up to ~30 lines per block), use fenced code blocks
|
|
651
|
+
- For configs: include the actual config values and structure
|
|
652
|
+
- For lists/instructions: include the actual items, not just "provided a list"
|
|
653
|
+
- Merge only truly trivial back-and-forth (like "ok" / "sure")
|
|
654
|
+
- Do NOT over-summarize: "provided a function" is BAD; show the actual function
|
|
655
|
+
|
|
656
|
+
✅ Result
|
|
657
|
+
What was the final outcome? Include the final version of any code/config/content produced.
|
|
658
|
+
|
|
659
|
+
💡 Key Details
|
|
660
|
+
- Decisions made, trade-offs discussed, caveats noted, alternative approaches mentioned
|
|
661
|
+
- Specific values: numbers, versions, thresholds, URLs, file paths, model names
|
|
662
|
+
- Omit this section only if there truly are no noteworthy details
|
|
663
|
+
|
|
664
|
+
RULES:
|
|
665
|
+
- This summary is a KNOWLEDGE BASE ENTRY, not a brief note. Be thorough.
|
|
666
|
+
- PRESERVE verbatim: code, commands, URLs, file paths, error messages, config values, version numbers, names, amounts
|
|
667
|
+
- DISCARD only: greetings, filler, the assistant explaining what it will do before doing it
|
|
668
|
+
- Replace secrets (API keys, tokens, passwords) with [REDACTED]
|
|
669
|
+
- Target length: 30-50% of the original conversation length. Longer conversations need longer summaries.
|
|
670
|
+
- Output summary only, no preamble.`;
|
|
671
|
+
|
|
672
|
+
const OPENCLAW_TOPIC_JUDGE_PROMPT = `You are a conversation topic boundary detector. Given a summary of the CURRENT conversation and a NEW user message, determine if the new message starts a DIFFERENT topic/task.
|
|
673
|
+
|
|
674
|
+
Answer ONLY "NEW" or "SAME".
|
|
675
|
+
|
|
676
|
+
Rules:
|
|
677
|
+
- "NEW" = the new message is about a completely different subject, project, or task
|
|
678
|
+
- "SAME" = the new message continues, follows up on, or is closely related to the current topic
|
|
679
|
+
- Follow-up questions, clarifications, refinements, bug fixes, or next steps on the same task = SAME
|
|
680
|
+
- Greetings or meta-questions like "你好" or "谢谢" without new substance = SAME
|
|
681
|
+
- A clearly unrelated request (e.g., current topic is deployment, new message asks about cooking) = NEW
|
|
682
|
+
|
|
683
|
+
Output exactly one word: NEW or SAME`;
|
|
684
|
+
|
|
685
|
+
const OPENCLAW_FILTER_RELEVANT_PROMPT = `You are a memory relevance judge. Given a user's QUERY and a list of CANDIDATE memory summaries, do two things:
|
|
686
|
+
|
|
687
|
+
1. Select ALL candidates that could be useful for answering the query. When in doubt, INCLUDE the candidate.
|
|
688
|
+
- For questions about lists, history, or "what/where/who" across multiple items, include ALL matching items.
|
|
689
|
+
- For factual lookups, a single direct answer is enough.
|
|
690
|
+
2. Judge whether the selected memories are SUFFICIENT to fully answer the query WITHOUT fetching additional context.
|
|
691
|
+
|
|
692
|
+
IMPORTANT for "sufficient" judgment:
|
|
693
|
+
- sufficient=true ONLY when the memories contain a concrete ANSWER, fact, decision, or actionable information that directly addresses the query.
|
|
694
|
+
- sufficient=false when the memories only repeat the question, show related topics but lack the specific detail, or contain partial information.
|
|
695
|
+
|
|
696
|
+
Output a JSON object with exactly two fields:
|
|
697
|
+
{"relevant":[1,3,5],"sufficient":true}
|
|
698
|
+
|
|
699
|
+
- "relevant": array of candidate numbers that are useful. Empty array [] if none are relevant.
|
|
700
|
+
- "sufficient": true ONLY if the memories contain a direct answer; false otherwise.
|
|
701
|
+
|
|
702
|
+
Output ONLY the JSON object, nothing else.`;
|
|
703
|
+
|
|
704
|
+
const OPENCLAW_DEDUP_JUDGE_PROMPT = `You are a memory deduplication system. Given a NEW memory summary and several EXISTING memory summaries, determine the relationship.
|
|
705
|
+
|
|
706
|
+
For each EXISTING memory, the NEW memory is either:
|
|
707
|
+
- "DUPLICATE": NEW is fully covered by an EXISTING memory — no new information at all
|
|
708
|
+
- "UPDATE": NEW contains information that supplements or updates an EXISTING memory (new data, status change, additional detail)
|
|
709
|
+
- "NEW": NEW is a different topic/event despite surface similarity
|
|
710
|
+
|
|
711
|
+
Pick the BEST match among all candidates. If none match well, choose "NEW".
|
|
712
|
+
|
|
713
|
+
Output a single JSON object:
|
|
714
|
+
- If DUPLICATE: {"action":"DUPLICATE","targetIndex":2,"reason":"..."}
|
|
715
|
+
- If UPDATE: {"action":"UPDATE","targetIndex":3,"reason":"...","mergedSummary":"a combined summary preserving all info from both old and new, same language as input"}
|
|
716
|
+
- If NEW: {"action":"NEW","reason":"..."}
|
|
717
|
+
|
|
718
|
+
CRITICAL: mergedSummary must use the SAME language as the input. Output ONLY the JSON object.`;
|
|
719
|
+
|
|
@@ -316,7 +316,7 @@ export async function filterRelevantOpenAI(
|
|
|
316
316
|
return parseFilterResult(raw, log);
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
-
function parseFilterResult(raw: string, log: Logger): FilterResult {
|
|
319
|
+
export function parseFilterResult(raw: string, log: Logger): FilterResult {
|
|
320
320
|
try {
|
|
321
321
|
const match = raw.match(/\{[\s\S]*\}/);
|
|
322
322
|
if (match) {
|
|
@@ -39,7 +39,7 @@ export class TaskProcessor {
|
|
|
39
39
|
private ctx: PluginContext,
|
|
40
40
|
) {
|
|
41
41
|
const strongCfg = ctx.config.skillEvolution?.summarizer;
|
|
42
|
-
this.summarizer = new Summarizer(ctx.config.summarizer, ctx.log, strongCfg);
|
|
42
|
+
this.summarizer = new Summarizer(ctx.config.summarizer, ctx.log, ctx.openclawAPI, strongCfg);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
onTaskCompleted(cb: (task: Task) => void): void {
|