@openviking/openclaw-plugin 2026.7.11 → 2026.8.6-1
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/INSTALL-ZH.md +39 -0
- package/INSTALL.md +39 -0
- package/README.md +5 -0
- package/auto-recall.ts +5 -4
- package/config.ts +121 -6
- package/context-engine.ts +0 -1
- package/dist/auto-recall.js +4 -4
- package/dist/config.js +78 -4
- package/dist/context-engine.js +0 -1
- package/dist/index.js +13 -4
- package/dist/plugin/openviking-archive-tools.js +1 -2
- package/dist/plugin/openviking-command-definitions.js +3 -3
- package/dist/plugin/openviking-experience-tools.js +105 -0
- package/dist/plugin/openviking-import-tools.js +2 -2
- package/dist/plugin/openviking-memory-recall-tools.js +4 -4
- package/dist/plugin/openviking-memory-tools.js +11 -6
- package/dist/plugin/openviking-query-runtime.js +1 -1
- package/dist/plugin/openviking-query-tools.js +4 -4
- package/dist/plugin/openviking-recall-trace-runtime.js +3 -3
- package/dist/plugin/openviking-session-routing-runtime.js +9 -2
- package/dist/plugin/openviking-tool-result-tools.js +3 -3
- package/dist/routing/identity-routing.js +27 -0
- package/dist/routing/memory-uri.js +1 -0
- package/dist/services/context-lifecycle-service.js +21 -16
- package/dist/services/context-message-adapter.js +2 -9
- package/index.ts +13 -3
- package/install-manifest.json +1 -0
- package/openclaw.plugin.json +34 -3
- package/package.json +1 -1
- package/plugin/command-registration.ts +2 -0
- package/plugin/openviking-archive-tools.ts +1 -4
- package/plugin/openviking-command-definitions.ts +4 -3
- package/plugin/openviking-experience-tools.ts +160 -0
- package/plugin/openviking-import-tools.ts +4 -2
- package/plugin/openviking-memory-recall-tools.ts +6 -4
- package/plugin/openviking-memory-tools.ts +18 -10
- package/plugin/openviking-query-runtime.ts +1 -1
- package/plugin/openviking-query-tools.ts +6 -4
- package/plugin/openviking-recall-trace-runtime.ts +4 -3
- package/plugin/openviking-recall-trace-tools.ts +2 -0
- package/plugin/openviking-session-routing-runtime.ts +15 -1
- package/plugin/openviking-tool-result-tools.ts +0 -6
- package/registries/openviking-tools.ts +6 -0
- package/routing/identity-routing.ts +41 -0
- package/routing/memory-uri.ts +1 -0
- package/services/context-lifecycle-service.ts +27 -18
- package/services/context-message-adapter.ts +2 -9
- package/skills/ov-experience-memory/SKILL.md +156 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
const EXPERIENCE_TARGET_URI = "viking://user/memories/experiences/";
|
|
3
|
+
const DEFAULT_LIMIT = 5;
|
|
4
|
+
const MAX_LIMIT = 20;
|
|
5
|
+
const EXPERIENCE_SIDECAR_FILENAMES = new Set([".abstract.md", ".overview.md", ".relations.json"]);
|
|
6
|
+
function clampLimit(value) {
|
|
7
|
+
const parsed = Number.isFinite(Number(value)) ? Math.trunc(Number(value)) : DEFAULT_LIMIT;
|
|
8
|
+
return Math.max(1, Math.min(MAX_LIMIT, parsed));
|
|
9
|
+
}
|
|
10
|
+
function experienceRelativePath(uri) {
|
|
11
|
+
return uri.match(/^viking:\/\/user\/[^/]+\/memories\/experiences\/(.+)$/)?.[1] ?? "";
|
|
12
|
+
}
|
|
13
|
+
export function isCanonicalExperienceUri(uri, expectedUserId) {
|
|
14
|
+
const value = typeof uri === "string" ? uri.trim() : "";
|
|
15
|
+
if (!value || value.includes("?") || value.includes("#")) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const owner = value.match(/^viking:\/\/user\/([^/]+)\//)?.[1] ?? "";
|
|
19
|
+
if (expectedUserId?.trim() && owner !== expectedUserId.trim()) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
const relative = experienceRelativePath(value);
|
|
23
|
+
const segments = relative.split("/");
|
|
24
|
+
const basename = segments.at(-1) ?? "";
|
|
25
|
+
return Boolean(relative
|
|
26
|
+
&& segments.every((segment) => segment && segment !== "." && segment !== "..")
|
|
27
|
+
&& !EXPERIENCE_SIDECAR_FILENAMES.has(basename));
|
|
28
|
+
}
|
|
29
|
+
function titleFromUri(uri) {
|
|
30
|
+
const basename = uri.split("/").at(-1) ?? uri;
|
|
31
|
+
const title = basename.replace(/\.md$/i, "");
|
|
32
|
+
try {
|
|
33
|
+
return decodeURIComponent(title);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return title;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function jsonToolResult(payload) {
|
|
40
|
+
return {
|
|
41
|
+
content: [{ type: "text", text: JSON.stringify(payload) }],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function registerOpenVikingExperienceTools(deps) {
|
|
45
|
+
deps.registerTool((ctx) => ({
|
|
46
|
+
name: "search_experience",
|
|
47
|
+
label: "Search Experience (OpenViking)",
|
|
48
|
+
description: "Search reusable task-execution experiences for the current OpenViking user. " +
|
|
49
|
+
"Use before executing operational or multi-step tasks, then call read_experience for selected results.",
|
|
50
|
+
parameters: Type.Object({
|
|
51
|
+
query: Type.String({ description: "Current task, situation, or execution problem to search for" }),
|
|
52
|
+
limit: Type.Optional(Type.Integer({
|
|
53
|
+
description: `Maximum results to return. Default: ${DEFAULT_LIMIT}; maximum: ${MAX_LIMIT}`,
|
|
54
|
+
minimum: 1,
|
|
55
|
+
maximum: MAX_LIMIT,
|
|
56
|
+
})),
|
|
57
|
+
}, { additionalProperties: false }),
|
|
58
|
+
async execute(_toolCallId, params) {
|
|
59
|
+
if (deps.isBypassedSession(ctx)) {
|
|
60
|
+
return deps.makeBypassedToolResult("search_experience");
|
|
61
|
+
}
|
|
62
|
+
const query = typeof params.query === "string" ? params.query.trim() : "";
|
|
63
|
+
if (!query) {
|
|
64
|
+
throw new Error("query is required");
|
|
65
|
+
}
|
|
66
|
+
const session = deps.resolvePluginSessionRouting(ctx);
|
|
67
|
+
const client = await deps.getClient();
|
|
68
|
+
const result = await client.find(query, {
|
|
69
|
+
targetUri: EXPERIENCE_TARGET_URI,
|
|
70
|
+
limit: clampLimit(params.limit),
|
|
71
|
+
}, session.actorPeerId);
|
|
72
|
+
const results = (result.memories ?? [])
|
|
73
|
+
.filter((item) => isCanonicalExperienceUri(item.uri, deps.userId))
|
|
74
|
+
.map((item) => ({
|
|
75
|
+
uri: item.uri,
|
|
76
|
+
title: titleFromUri(item.uri),
|
|
77
|
+
score: typeof item.score === "number" ? item.score : 0,
|
|
78
|
+
snippet: item.abstract || item.overview || "",
|
|
79
|
+
}));
|
|
80
|
+
return jsonToolResult({ results });
|
|
81
|
+
},
|
|
82
|
+
}), { name: "search_experience" });
|
|
83
|
+
deps.registerTool((ctx) => ({
|
|
84
|
+
name: "read_experience",
|
|
85
|
+
label: "Read Experience (OpenViking)",
|
|
86
|
+
description: "Read the complete Markdown body of one Experience returned by search_experience and use it as execution guidance.",
|
|
87
|
+
parameters: Type.Object({
|
|
88
|
+
uri: Type.String({ description: "Exact canonical Experience URI returned by search_experience" }),
|
|
89
|
+
}, { additionalProperties: false }),
|
|
90
|
+
async execute(_toolCallId, params) {
|
|
91
|
+
if (deps.isBypassedSession(ctx)) {
|
|
92
|
+
return deps.makeBypassedToolResult("read_experience");
|
|
93
|
+
}
|
|
94
|
+
const uri = typeof params.uri === "string" ? params.uri.trim() : "";
|
|
95
|
+
if (!isCanonicalExperienceUri(uri, deps.userId)) {
|
|
96
|
+
throw new Error("uri must be a canonical OpenViking Experience URI returned by search_experience");
|
|
97
|
+
}
|
|
98
|
+
const session = deps.resolvePluginSessionRouting(ctx);
|
|
99
|
+
const client = await deps.getClient();
|
|
100
|
+
const content = await client.read(uri, session.actorPeerId);
|
|
101
|
+
const text = typeof content === "string" ? content : JSON.stringify(content, null, 2);
|
|
102
|
+
return jsonToolResult({ uri, content: text });
|
|
103
|
+
},
|
|
104
|
+
}), { name: "read_experience" });
|
|
105
|
+
}
|
|
@@ -40,7 +40,7 @@ export function registerOpenVikingImportTools(deps) {
|
|
|
40
40
|
instruction: typeof params.instruction === "string" ? params.instruction : undefined,
|
|
41
41
|
wait: typeof params.wait === "boolean" ? params.wait : undefined,
|
|
42
42
|
timeout: typeof params.timeout === "number" ? params.timeout : undefined,
|
|
43
|
-
}, session.
|
|
43
|
+
}, session.actorPeerId);
|
|
44
44
|
return {
|
|
45
45
|
content: [{ type: "text", text: formatResourceImportText(result) }],
|
|
46
46
|
details: {
|
|
@@ -73,7 +73,7 @@ export function registerOpenVikingImportTools(deps) {
|
|
|
73
73
|
data: params.data,
|
|
74
74
|
wait: typeof params.wait === "boolean" ? params.wait : undefined,
|
|
75
75
|
timeout: typeof params.timeout === "number" ? params.timeout : undefined,
|
|
76
|
-
}, session.
|
|
76
|
+
}, session.actorPeerId);
|
|
77
77
|
return {
|
|
78
78
|
content: [{ type: "text", text: formatSkillImportText(result) }],
|
|
79
79
|
details: {
|
|
@@ -47,7 +47,7 @@ export function registerOpenVikingMemoryRecallTools(deps) {
|
|
|
47
47
|
const requestLimit = queryConfig.candidateLimit;
|
|
48
48
|
const recallClient = await deps.getClient();
|
|
49
49
|
if (deps.cfg.logFindRequests) {
|
|
50
|
-
deps.logger.info?.(`openviking: memory_recall X-OpenViking-Actor-Peer="${session.
|
|
50
|
+
deps.logger.info?.(`openviking: memory_recall X-OpenViking-Actor-Peer="${session.actorPeerId ?? "none"}" ` +
|
|
51
51
|
`(plugin defaultAgentId="${recallClient.getDefaultAgentId()}" is unused when session context is present)`);
|
|
52
52
|
}
|
|
53
53
|
let result;
|
|
@@ -57,7 +57,7 @@ export function registerOpenVikingMemoryRecallTools(deps) {
|
|
|
57
57
|
targetUri,
|
|
58
58
|
limit: requestLimit,
|
|
59
59
|
scoreThreshold: 0,
|
|
60
|
-
actorPeerId: session.
|
|
60
|
+
actorPeerId: session.actorPeerId,
|
|
61
61
|
});
|
|
62
62
|
const traceResults = [
|
|
63
63
|
...(result.memories ?? []).map((item) => toTraceResult(item, "memory", deps)),
|
|
@@ -84,7 +84,7 @@ export function registerOpenVikingMemoryRecallTools(deps) {
|
|
|
84
84
|
limit: requestLimit,
|
|
85
85
|
scoreThreshold: 0,
|
|
86
86
|
contextType: search.contextType,
|
|
87
|
-
actorPeerId: session.
|
|
87
|
+
actorPeerId: session.actorPeerId,
|
|
88
88
|
})));
|
|
89
89
|
const allMemories = [];
|
|
90
90
|
for (let index = 0; index < settled.length; index += 1) {
|
|
@@ -188,7 +188,7 @@ export function registerOpenVikingMemoryRecallTools(deps) {
|
|
|
188
188
|
details: { count: 0, total: result.total ?? 0, scoreThreshold },
|
|
189
189
|
};
|
|
190
190
|
}
|
|
191
|
-
const { lines: memoryLines } = await deps.buildMemoryLinesWithBudget(memories, (uri) => recallClient.read(uri, session.
|
|
191
|
+
const { lines: memoryLines } = await deps.buildMemoryLinesWithBudget(memories, (uri) => recallClient.read(uri, session.actorPeerId), {
|
|
192
192
|
recallPreferAbstract: false,
|
|
193
193
|
recallMaxInjectedChars: queryConfig.maxInjectedChars,
|
|
194
194
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Type } from "@sinclair/typebox";
|
|
2
2
|
import { clampScore, postProcessMemories } from "../memory-ranking.js";
|
|
3
|
+
import { resolveOpenVikingMessagePeerId, } from "../routing/identity-routing.js";
|
|
3
4
|
import { isMemoryUri } from "../routing/memory-uri.js";
|
|
4
5
|
function totalCommitMemories(r) {
|
|
5
6
|
const m = r.memories_extracted;
|
|
@@ -41,11 +42,15 @@ export function registerOpenVikingMemoryTools(deps) {
|
|
|
41
42
|
sessionId = deps.createTempSessionId();
|
|
42
43
|
usedTempSession = true;
|
|
43
44
|
}
|
|
44
|
-
const
|
|
45
|
-
|
|
45
|
+
const peerId = resolveOpenVikingMessagePeerId({
|
|
46
|
+
peerRole: deps.peerRole,
|
|
47
|
+
role,
|
|
48
|
+
personPeerId: session.actorPeerId,
|
|
49
|
+
assistantPeerId: session.actorPeerId,
|
|
50
|
+
});
|
|
51
|
+
await client.addSessionMessage(sessionId, role, [{ type: "text", text }], undefined, undefined, peerId);
|
|
46
52
|
const commitResult = await client.commitSession(sessionId, {
|
|
47
53
|
wait: true,
|
|
48
|
-
agentId: session.agentId,
|
|
49
54
|
keepRecentCount: 0,
|
|
50
55
|
});
|
|
51
56
|
const memoriesCount = totalCommitMemories(commitResult);
|
|
@@ -130,7 +135,7 @@ export function registerOpenVikingMemoryTools(deps) {
|
|
|
130
135
|
details: { action: "rejected", uri },
|
|
131
136
|
};
|
|
132
137
|
}
|
|
133
|
-
await client.deleteUri(uri, session.
|
|
138
|
+
await client.deleteUri(uri, session.actorPeerId);
|
|
134
139
|
return {
|
|
135
140
|
content: [{ type: "text", text: `Forgotten: ${uri}` }],
|
|
136
141
|
details: { action: "deleted", uri },
|
|
@@ -157,7 +162,7 @@ export function registerOpenVikingMemoryTools(deps) {
|
|
|
157
162
|
targetUri,
|
|
158
163
|
limit: requestLimit,
|
|
159
164
|
scoreThreshold: 0,
|
|
160
|
-
}, session.
|
|
165
|
+
}, session.actorPeerId);
|
|
161
166
|
const candidates = postProcessMemories(result.memories ?? [], {
|
|
162
167
|
limit: requestLimit,
|
|
163
168
|
scoreThreshold,
|
|
@@ -176,7 +181,7 @@ export function registerOpenVikingMemoryTools(deps) {
|
|
|
176
181
|
}
|
|
177
182
|
const top = candidates[0];
|
|
178
183
|
if (candidates.length === 1 && clampScore(top.score) >= 0.85) {
|
|
179
|
-
await client.deleteUri(top.uri, session.
|
|
184
|
+
await client.deleteUri(top.uri, session.actorPeerId);
|
|
180
185
|
return {
|
|
181
186
|
content: [{ type: "text", text: `Forgotten: ${top.uri}` }],
|
|
182
187
|
details: { action: "deleted", uri: top.uri, score: top.score ?? 0 },
|
|
@@ -337,7 +337,7 @@ export function createOpenVikingQueryRuntime(deps) {
|
|
|
337
337
|
sessionId: traceCtx?.sessionId,
|
|
338
338
|
sessionKey: traceCtx?.sessionKey,
|
|
339
339
|
ovSessionId: traceCtx?.ovSessionId,
|
|
340
|
-
agentId,
|
|
340
|
+
agentId: traceCtx?.agentId,
|
|
341
341
|
source: "ov_search",
|
|
342
342
|
operationType: "semantic_find",
|
|
343
343
|
resourceTypes: [...new Set(searches.map((search) => search.resourceType).filter((resourceType) => resourceType !== "archive"))],
|
|
@@ -21,7 +21,7 @@ export function registerOpenVikingQueryTools(deps) {
|
|
|
21
21
|
query: String(params.query ?? ""),
|
|
22
22
|
uri: typeof params.uri === "string" ? params.uri : undefined,
|
|
23
23
|
limit: typeof params.limit === "number" ? params.limit : undefined,
|
|
24
|
-
}, session.
|
|
24
|
+
}, session.actorPeerId, session);
|
|
25
25
|
},
|
|
26
26
|
}), { name: "ov_search" });
|
|
27
27
|
deps.registerTool((ctx) => ({
|
|
@@ -41,7 +41,7 @@ export function registerOpenVikingQueryTools(deps) {
|
|
|
41
41
|
const session = deps.resolvePluginSessionRouting(ctx);
|
|
42
42
|
return deps.readOpenVikingContent({
|
|
43
43
|
uri: String(params.uri ?? ""),
|
|
44
|
-
}, session.
|
|
44
|
+
}, session.actorPeerId);
|
|
45
45
|
},
|
|
46
46
|
}), { name: "ov_read" });
|
|
47
47
|
deps.registerTool((ctx) => ({
|
|
@@ -62,7 +62,7 @@ export function registerOpenVikingQueryTools(deps) {
|
|
|
62
62
|
const uris = Array.isArray(params.uris)
|
|
63
63
|
? params.uris.map((uri) => String(uri))
|
|
64
64
|
: [];
|
|
65
|
-
return deps.multiReadOpenVikingContent({ uris }, session.
|
|
65
|
+
return deps.multiReadOpenVikingContent({ uris }, session.actorPeerId);
|
|
66
66
|
},
|
|
67
67
|
}), { name: "ov_multi_read" });
|
|
68
68
|
deps.registerTool((ctx) => ({
|
|
@@ -85,7 +85,7 @@ export function registerOpenVikingQueryTools(deps) {
|
|
|
85
85
|
recursive: typeof params.recursive === "boolean" ? params.recursive : undefined,
|
|
86
86
|
simple: typeof params.simple === "boolean" ? params.simple : undefined,
|
|
87
87
|
limit: typeof params.limit === "number" ? params.limit : undefined,
|
|
88
|
-
}, session.
|
|
88
|
+
}, session.actorPeerId);
|
|
89
89
|
},
|
|
90
90
|
}), { name: "ov_list" });
|
|
91
91
|
}
|
|
@@ -157,11 +157,11 @@ export function createOpenVikingRecallTraceRuntime(deps) {
|
|
|
157
157
|
for (const fallbackQuery of fallbackIdentities) {
|
|
158
158
|
const fallback = await deps.traceRecorder.queryWithFallback(fallbackQuery);
|
|
159
159
|
if (fallback.entries.length > 0) {
|
|
160
|
-
return enrichTraceEntriesWithContent(fallback, shouldIncludeTraceContent(input), session.
|
|
160
|
+
return enrichTraceEntriesWithContent(fallback, shouldIncludeTraceContent(input), session.actorPeerId);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
return enrichTraceEntriesWithContent(base, shouldIncludeTraceContent(input), session.
|
|
164
|
+
return enrichTraceEntriesWithContent(base, shouldIncludeTraceContent(input), session.actorPeerId);
|
|
165
165
|
};
|
|
166
166
|
const handleUriDetail = async (request) => {
|
|
167
167
|
const query = toQueryObject(request);
|
|
@@ -206,7 +206,7 @@ export function createOpenVikingRecallTraceRuntime(deps) {
|
|
|
206
206
|
}
|
|
207
207
|
try {
|
|
208
208
|
const client = await deps.getClient();
|
|
209
|
-
const content = await client.read(uri,
|
|
209
|
+
const content = await client.read(uri, session.actorPeerId);
|
|
210
210
|
const text = typeof content === "string" ? content : JSON.stringify(content, null, 2);
|
|
211
211
|
const chars = Array.from(text);
|
|
212
212
|
const slice = chars.slice(offset, offset + contentLimit).join("");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createSessionAgentResolver, openClawSessionToOvStorageId, } from "../routing/identity-routing.js";
|
|
1
|
+
import { createSessionAgentResolver, openClawSessionToOvStorageId, resolveOpenVikingActorPeerId, sanitizeOpenVikingPeerId, } from "../routing/identity-routing.js";
|
|
2
2
|
export function createOpenVikingSessionRoutingRuntime(options) {
|
|
3
|
+
const peerRole = options.peerRole ?? "assistant";
|
|
3
4
|
const sessionAgentResolver = createSessionAgentResolver(options.peerPrefix);
|
|
4
5
|
const rememberSessionAgentId = (ctx) => {
|
|
5
6
|
sessionAgentResolver.remember(ctx);
|
|
@@ -39,11 +40,17 @@ export function createOpenVikingSessionRoutingRuntime(options) {
|
|
|
39
40
|
ovSessionId: ovSessionId || undefined,
|
|
40
41
|
};
|
|
41
42
|
rememberSessionAgentId(session);
|
|
43
|
+
const agentId = resolveAgentId(session.sessionId, session.sessionKey, session.ovSessionId);
|
|
42
44
|
return {
|
|
43
45
|
sessionId: session.sessionId,
|
|
44
46
|
sessionKey: session.sessionKey,
|
|
45
47
|
ovSessionId: session.ovSessionId,
|
|
46
|
-
agentId
|
|
48
|
+
agentId,
|
|
49
|
+
actorPeerId: resolveOpenVikingActorPeerId({
|
|
50
|
+
peerRole,
|
|
51
|
+
personPeerId: sanitizeOpenVikingPeerId(ctx?.requesterSenderId ?? ctx?.senderId),
|
|
52
|
+
assistantPeerId: agentId,
|
|
53
|
+
}),
|
|
47
54
|
};
|
|
48
55
|
};
|
|
49
56
|
const toQueryConfigContext = (session) => ({
|
|
@@ -83,7 +83,7 @@ export function registerOpenVikingToolResultTools({ registerTool, getClient, res
|
|
|
83
83
|
}
|
|
84
84
|
try {
|
|
85
85
|
const client = await getClient();
|
|
86
|
-
const result = await client.readToolResult(session.ovSessionId, parsed.toolResultId, { offset, limit, includeMetadata: true }
|
|
86
|
+
const result = await client.readToolResult(session.ovSessionId, parsed.toolResultId, { offset, limit, includeMetadata: true });
|
|
87
87
|
const returnedChars = result.content.length;
|
|
88
88
|
const nextOffset = result.offset + returnedChars;
|
|
89
89
|
const text = result.content || "(empty tool result chunk)";
|
|
@@ -167,7 +167,7 @@ export function registerOpenVikingToolResultTools({ registerTool, getClient, res
|
|
|
167
167
|
const contextChars = Math.max(0, getOptionalInteger(params.context_chars ?? params.contextChars, 300));
|
|
168
168
|
try {
|
|
169
169
|
const client = await getClient();
|
|
170
|
-
const result = await client.searchToolResult(session.ovSessionId, parsed.toolResultId, query, { limit, contextChars }
|
|
170
|
+
const result = await client.searchToolResult(session.ovSessionId, parsed.toolResultId, query, { limit, contextChars });
|
|
171
171
|
const matches = result.matches ?? [];
|
|
172
172
|
const text = matches.length
|
|
173
173
|
? [
|
|
@@ -227,7 +227,7 @@ export function registerOpenVikingToolResultTools({ registerTool, getClient, res
|
|
|
227
227
|
const limit = getPositiveInteger(params.limit, 50);
|
|
228
228
|
try {
|
|
229
229
|
const client = await getClient();
|
|
230
|
-
const result = await client.listToolResults(session.ovSessionId, { toolName, limit }
|
|
230
|
+
const result = await client.listToolResults(session.ovSessionId, { toolName, limit });
|
|
231
231
|
const items = result.tool_results ?? [];
|
|
232
232
|
const text = items.length
|
|
233
233
|
? [
|
|
@@ -3,6 +3,33 @@ const DEFAULT_OPENCLAW_AGENT_ID = "main";
|
|
|
3
3
|
/** OpenClaw session UUID (path-safe on Windows). */
|
|
4
4
|
const OPENVIKING_OV_SESSION_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
5
5
|
const WINDOWS_BAD_SESSION_SEGMENT = /[:<>"\\/|?\u0000-\u001f]/;
|
|
6
|
+
export function sanitizeOpenVikingPeerId(raw) {
|
|
7
|
+
const normalized = raw
|
|
8
|
+
?.trim()
|
|
9
|
+
.replace(/[^a-zA-Z0-9_-]+/g, "_")
|
|
10
|
+
.replace(/^_+|_+$/g, "")
|
|
11
|
+
.replace(/_+/g, "_");
|
|
12
|
+
return normalized || undefined;
|
|
13
|
+
}
|
|
14
|
+
export function resolveOpenVikingMessagePeerId(params) {
|
|
15
|
+
if (params.peerRole === "person" && params.role === "user") {
|
|
16
|
+
return params.personPeerId;
|
|
17
|
+
}
|
|
18
|
+
if (params.peerRole === "assistant" && params.role === "assistant") {
|
|
19
|
+
return params.assistantPeerId;
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
export function resolveOpenVikingActorPeerId(params) {
|
|
24
|
+
const actorPeerId = resolveOpenVikingMessagePeerId({
|
|
25
|
+
...params,
|
|
26
|
+
role: params.peerRole === "person" ? "user" : "assistant",
|
|
27
|
+
});
|
|
28
|
+
if (params.peerRole === "person" && !actorPeerId) {
|
|
29
|
+
throw new Error("openviking: peer_role=person requires a sender identity");
|
|
30
|
+
}
|
|
31
|
+
return actorPeerId;
|
|
32
|
+
}
|
|
6
33
|
/**
|
|
7
34
|
* Map OpenClaw session identity to an OpenViking session_id that is safe as a single
|
|
8
35
|
* AGFS path segment on Windows (no `:` etc.). Prefer UUID sessionId when present;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const MEMORY_URI_PATTERNS = [
|
|
2
2
|
/^viking:\/\/user\/(?:[^/]+(?:\/agent\/[^/]+)?\/)?memories(?:\/|$)/,
|
|
3
|
+
/^viking:\/\/user\/[^/]+\/peers\/[^/]+\/memories(?:\/|$)/,
|
|
3
4
|
/^viking:\/\/agent\/(?:[^/]+(?:\/user\/[^/]+)?\/)?memories(?:\/|$)/,
|
|
4
5
|
];
|
|
5
6
|
export function isMemoryUri(uri) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { DEFAULT_PHASE2_POLL_TIMEOUT_MS } from "../client.js";
|
|
3
3
|
import { buildAutoRecallContext, prepareRecallQuery } from "../auto-recall.js";
|
|
4
4
|
import { toJsonLog } from "../memory-ranking.js";
|
|
5
|
-
import { openClawSessionToOvStorageId } from "../routing/identity-routing.js";
|
|
5
|
+
import { openClawSessionToOvStorageId, resolveOpenVikingActorPeerId, resolveOpenVikingMessagePeerId, sanitizeOpenVikingPeerId, } from "../routing/identity-routing.js";
|
|
6
6
|
import { extractNewTurnMessages } from "../text-utils.js";
|
|
7
7
|
import { estimateAgentMessageTokens, estimateTextTokens } from "../token-estimator.js";
|
|
8
8
|
import { convertToAgentMessages, mergeConsecutiveAssistants, sanitizeAgentMessagesForProvider, toRoleId, } from "./context-message-adapter.js";
|
|
@@ -26,12 +26,12 @@ function sleep(ms) {
|
|
|
26
26
|
* After wait=false commit, Phase2 runs on the server. Poll task until completed/failed/timeout
|
|
27
27
|
* so logs show memories_extracted (otherwise it looks like "nothing was saved").
|
|
28
28
|
*/
|
|
29
|
-
async function pollPhase2ExtractionOutcome(client, taskId,
|
|
29
|
+
async function pollPhase2ExtractionOutcome(client, taskId, logger, sessionLabel) {
|
|
30
30
|
const deadline = Date.now() + PHASE2_POLL_MAX_MS;
|
|
31
31
|
try {
|
|
32
32
|
while (Date.now() < deadline) {
|
|
33
33
|
await sleep(PHASE2_POLL_INTERVAL_MS);
|
|
34
|
-
const task = await client.getTask(taskId
|
|
34
|
+
const task = await client.getTask(taskId).catch((e) => {
|
|
35
35
|
logger.warn?.(`openviking: phase2 getTask failed task_id=${taskId}: ${String(e)}`);
|
|
36
36
|
return null;
|
|
37
37
|
});
|
|
@@ -141,7 +141,7 @@ function buildAssembledContext(overview, preAbstracts, ovMessages, tokenBudget,
|
|
|
141
141
|
const sanitized = sanitizeAgentMessagesForProvider(assembled);
|
|
142
142
|
return { sanitized, archive, session, budgets, instruction };
|
|
143
143
|
}
|
|
144
|
-
export async function commitOpenVikingSession({ sessionId, sessionKey, getClient, logger,
|
|
144
|
+
export async function commitOpenVikingSession({ sessionId, sessionKey, getClient, logger, rememberSessionAgentId, isBypassedSession, }) {
|
|
145
145
|
const ovId = openClawSessionToOvStorageId(sessionId, sessionKey);
|
|
146
146
|
if (isBypassedSession({ sessionId, sessionKey })) {
|
|
147
147
|
logger.warn?.(`openviking: commit skipped because session is bypassed (sessionId=${sessionId}, sessionKey=${sessionKey ?? "none"})`);
|
|
@@ -154,10 +154,8 @@ export async function commitOpenVikingSession({ sessionId, sessionKey, getClient
|
|
|
154
154
|
sessionKey,
|
|
155
155
|
ovSessionId: ovId,
|
|
156
156
|
});
|
|
157
|
-
const agentId = resolveAgentId(sessionId, sessionKey, ovId);
|
|
158
157
|
const commitResult = await client.commitSession(ovId, {
|
|
159
158
|
wait: true,
|
|
160
|
-
agentId,
|
|
161
159
|
keepRecentCount: 0,
|
|
162
160
|
});
|
|
163
161
|
const memCount = totalExtractedMemories(commitResult.memories_extracted);
|
|
@@ -248,6 +246,11 @@ export async function assembleOpenVikingSession({ sessionId, sessionKey, message
|
|
|
248
246
|
const client = await getClient();
|
|
249
247
|
const routingRef = sessionId ?? sessionKey ?? ovSessionId;
|
|
250
248
|
const agentId = resolveAgentId(routingRef, sessionKey, ovSessionId);
|
|
249
|
+
const actorPeerId = resolveOpenVikingActorPeerId({
|
|
250
|
+
peerRole: cfg.peer_role ?? "assistant",
|
|
251
|
+
personPeerId: sanitizeOpenVikingPeerId(sender.senderId),
|
|
252
|
+
assistantPeerId: agentId,
|
|
253
|
+
});
|
|
251
254
|
const queryConfig = await queryConfigStore?.getEffective({
|
|
252
255
|
agentId,
|
|
253
256
|
sessionId,
|
|
@@ -259,6 +262,7 @@ export async function assembleOpenVikingSession({ sessionId, sessionKey, message
|
|
|
259
262
|
queryConfig,
|
|
260
263
|
client,
|
|
261
264
|
agentId,
|
|
265
|
+
actorPeerId,
|
|
262
266
|
queryText: recallQuery.query,
|
|
263
267
|
logger,
|
|
264
268
|
verbose: (message) => logger.info(message),
|
|
@@ -307,9 +311,7 @@ export async function assembleOpenVikingSession({ sessionId, sessionKey, message
|
|
|
307
311
|
}
|
|
308
312
|
try {
|
|
309
313
|
const client = await getClient();
|
|
310
|
-
const
|
|
311
|
-
const agentId = resolveAgentId(routingRef, sessionKey, ovSessionId);
|
|
312
|
-
const ctx = await client.getSessionContext(ovSessionId, tokenBudget, agentId);
|
|
314
|
+
const ctx = await client.getSessionContext(ovSessionId, tokenBudget);
|
|
313
315
|
const preAbstracts = ctx?.pre_archive_abstracts ?? [];
|
|
314
316
|
const hasArchives = !!ctx?.latest_archive_overview || preAbstracts.length > 0;
|
|
315
317
|
const activeCount = ctx?.messages?.length ?? 0;
|
|
@@ -596,10 +598,15 @@ export async function afterTurnOpenVikingSession({ sessionId, sessionKey, messag
|
|
|
596
598
|
};
|
|
597
599
|
});
|
|
598
600
|
if (ovParts.length > 0) {
|
|
599
|
-
await client.addSessionMessage(ovSessionId, msg.role, ovParts,
|
|
601
|
+
await client.addSessionMessage(ovSessionId, msg.role, ovParts, undefined, createdAt, resolveOpenVikingMessagePeerId({
|
|
602
|
+
peerRole: cfg.peer_role ?? "assistant",
|
|
603
|
+
role: msg.role,
|
|
604
|
+
personPeerId: senderRoleId,
|
|
605
|
+
assistantPeerId: agentId,
|
|
606
|
+
}));
|
|
600
607
|
}
|
|
601
608
|
}
|
|
602
|
-
const session = await client.getSession(ovSessionId
|
|
609
|
+
const session = await client.getSession(ovSessionId);
|
|
603
610
|
const pendingTokens = session.pending_tokens ?? 0;
|
|
604
611
|
const commitTokenThreshold = Math.floor(tokenBudget * cfg.commitTokenThresholdRatio);
|
|
605
612
|
if (pendingTokens < commitTokenThreshold) {
|
|
@@ -616,7 +623,6 @@ export async function afterTurnOpenVikingSession({ sessionId, sessionKey, messag
|
|
|
616
623
|
}
|
|
617
624
|
const commitResult = await client.commitSession(ovSessionId, {
|
|
618
625
|
wait: false,
|
|
619
|
-
agentId,
|
|
620
626
|
keepRecentCount: cfg.commitKeepRecentCount,
|
|
621
627
|
});
|
|
622
628
|
logger.info(`openviking: committed session=${ovSessionId}, ` +
|
|
@@ -637,7 +643,7 @@ export async function afterTurnOpenVikingSession({ sessionId, sessionKey, messag
|
|
|
637
643
|
if (commitResult.task_id && cfg.logFindRequests) {
|
|
638
644
|
logger.info(`openviking: Phase2 memory extraction runs asynchronously on the server (task_id=${commitResult.task_id}). ` +
|
|
639
645
|
"memories_extracted appears only after that task completes — not in this immediate response.");
|
|
640
|
-
void pollPhase2ExtractionOutcome(client, commitResult.task_id,
|
|
646
|
+
void pollPhase2ExtractionOutcome(client, commitResult.task_id, logger, ovSessionId);
|
|
641
647
|
}
|
|
642
648
|
}
|
|
643
649
|
catch (err) {
|
|
@@ -697,7 +703,7 @@ export async function compactOpenVikingSession({ sessionId, sessionKey, tokenBud
|
|
|
697
703
|
let preCommitEstimatedTokens;
|
|
698
704
|
if (typeof tokensBeforeOriginal !== "number") {
|
|
699
705
|
try {
|
|
700
|
-
const preCtx = await client.getSessionContext(ovSessionId, tokenBudget
|
|
706
|
+
const preCtx = await client.getSessionContext(ovSessionId, tokenBudget);
|
|
701
707
|
if (typeof preCtx.estimatedTokens === "number" && Number.isFinite(preCtx.estimatedTokens)) {
|
|
702
708
|
preCommitEstimatedTokens = preCtx.estimatedTokens;
|
|
703
709
|
}
|
|
@@ -712,7 +718,6 @@ export async function compactOpenVikingSession({ sessionId, sessionKey, tokenBud
|
|
|
712
718
|
logger.info(`openviking: compact committing session=${ovSessionId} (wait=true, tokenBudget=${tokenBudget})`);
|
|
713
719
|
const commitResult = await client.commitSession(ovSessionId, {
|
|
714
720
|
wait: true,
|
|
715
|
-
agentId,
|
|
716
721
|
keepRecentCount: 0,
|
|
717
722
|
});
|
|
718
723
|
const memCount = totalExtractedMemories(commitResult.memories_extracted);
|
|
@@ -774,7 +779,7 @@ export async function compactOpenVikingSession({ sessionId, sessionKey, tokenBud
|
|
|
774
779
|
let tokensAfter;
|
|
775
780
|
let contextFetchError;
|
|
776
781
|
try {
|
|
777
|
-
const ctx = await client.getSessionContext(ovSessionId, tokenBudget
|
|
782
|
+
const ctx = await client.getSessionContext(ovSessionId, tokenBudget);
|
|
778
783
|
logger.info(`openviking: compact getSessionContext raw result for ${ovSessionId}: ` +
|
|
779
784
|
JSON.stringify(ctx, null, 2));
|
|
780
785
|
if (typeof ctx.latest_archive_overview === "string") {
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
+
import { sanitizeOpenVikingPeerId } from "../routing/identity-routing.js";
|
|
1
2
|
import { sanitizeToolUseResultPairing } from "../session-transcript-repair.js";
|
|
2
3
|
export function toRoleId(senderId) {
|
|
3
|
-
|
|
4
|
-
return undefined;
|
|
5
|
-
}
|
|
6
|
-
const normalized = senderId
|
|
7
|
-
.trim()
|
|
8
|
-
.replace(/[^a-zA-Z0-9_-]+/g, "_")
|
|
9
|
-
.replace(/^_+|_+$/g, "")
|
|
10
|
-
.replace(/_+/g, "_");
|
|
11
|
-
return normalized || undefined;
|
|
4
|
+
return sanitizeOpenVikingPeerId(senderId);
|
|
12
5
|
}
|
|
13
6
|
/**
|
|
14
7
|
* Convert an OpenViking stored message (parts-based format) into one or more
|
package/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { registerOpenVikingCommands } from "./plugin/command-registration.js";
|
|
|
19
19
|
import { registerRecallTraceRoutes as registerRecallTraceRouteAdapters } from "./plugin/recall-trace-routes.js";
|
|
20
20
|
import { createOpenVikingService } from "./plugin/openviking-services.js";
|
|
21
21
|
import { registerOpenVikingArchiveTools } from "./plugin/openviking-archive-tools.js";
|
|
22
|
+
import { registerOpenVikingExperienceTools } from "./plugin/openviking-experience-tools.js";
|
|
22
23
|
import { createOpenVikingImportRuntime } from "./plugin/openviking-import-runtime.js";
|
|
23
24
|
import { registerOpenVikingImportTools } from "./plugin/openviking-import-tools.js";
|
|
24
25
|
import { registerOpenVikingLifecycleHooks } from "./plugin/openviking-lifecycle-hooks.js";
|
|
@@ -41,7 +42,7 @@ import {
|
|
|
41
42
|
import type { CommandDefinition } from "./plugin/command-registration.js";
|
|
42
43
|
|
|
43
44
|
import type { HttpTransport } from "./adapters/http-transport.js";
|
|
44
|
-
import { formatMessageFaithful
|
|
45
|
+
import { formatMessageFaithful } from "./services/context-message-adapter.js";
|
|
45
46
|
import {
|
|
46
47
|
clampScore,
|
|
47
48
|
postProcessMemories,
|
|
@@ -212,6 +213,7 @@ const contextEnginePlugin = {
|
|
|
212
213
|
resolvePluginSessionRouting,
|
|
213
214
|
toQueryConfigContext,
|
|
214
215
|
} = createOpenVikingSessionRoutingRuntime({
|
|
216
|
+
peerRole: cfg.peer_role,
|
|
215
217
|
peerPrefix: cfg.peer_prefix,
|
|
216
218
|
logFindRequests: cfg.logFindRequests,
|
|
217
219
|
logger: api.logger,
|
|
@@ -279,6 +281,15 @@ const contextEnginePlugin = {
|
|
|
279
281
|
makeBypassedToolResult,
|
|
280
282
|
});
|
|
281
283
|
|
|
284
|
+
registerOpenVikingExperienceTools({
|
|
285
|
+
registerTool: registerOpenVikingTool,
|
|
286
|
+
getClient,
|
|
287
|
+
resolvePluginSessionRouting,
|
|
288
|
+
isBypassedSession,
|
|
289
|
+
makeBypassedToolResult,
|
|
290
|
+
userId: cfg.userId,
|
|
291
|
+
});
|
|
292
|
+
|
|
282
293
|
registerOpenVikingMemoryRecallTools({
|
|
283
294
|
registerTool: registerOpenVikingTool,
|
|
284
295
|
getClient,
|
|
@@ -329,8 +340,7 @@ const contextEnginePlugin = {
|
|
|
329
340
|
getClient,
|
|
330
341
|
normalizeSessionId: openClawSessionRefToOvStorageId,
|
|
331
342
|
createTempSessionId: createMemoryStoreTempSessionId,
|
|
332
|
-
|
|
333
|
-
toRoleId,
|
|
343
|
+
peerRole: cfg.peer_role,
|
|
334
344
|
resolvePluginSessionRouting,
|
|
335
345
|
isBypassedSession,
|
|
336
346
|
makeBypassedToolResult,
|