@tonyclaw/agent-inspector 2.0.0 → 2.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/.output/cli.js +353 -54
- package/.output/nitro.json +1 -1
- package/.output/public/assets/{CompareDrawer-CU5ZrWcL.js → CompareDrawer-Bp7_x-5N.js} +1 -1
- package/.output/public/assets/{ProxyViewerContainer-pEBqVp1d.js → ProxyViewerContainer-USuxPy-K.js} +13 -13
- package/.output/public/assets/{ReplayDialog-F58yNg5j.js → ReplayDialog-DFHCd0yx.js} +1 -1
- package/.output/public/assets/{RequestAnatomy-C9lT0qE_.js → RequestAnatomy-ehyrskxt.js} +1 -1
- package/.output/public/assets/{ResponseView-DHJq6bnz.js → ResponseView-BNGyc8e_.js} +1 -1
- package/.output/public/assets/{StreamingChunkSequence-BTgfpFUT.js → StreamingChunkSequence-Bjs4Lqwn.js} +1 -1
- package/.output/public/assets/_sessionId-D_SeK_qp.js +1 -0
- package/.output/public/assets/index-BGGOWR7A.js +1 -0
- package/.output/public/assets/index-CIL46Z2y.css +1 -0
- package/.output/public/assets/{json-viewer-CZVYLR8j.js → json-viewer-6uV_YXws.js} +1 -1
- package/.output/public/assets/{main-DHs7FBK3.js → main-FSGUGtEL.js} +2 -2
- package/.output/server/{_sessionId-wMLPvC5g.mjs → _sessionId-_bf9vUww.mjs} +2 -2
- package/.output/server/_ssr/{CompareDrawer-BU4V0uVf.mjs → CompareDrawer-DIth2DQM.mjs} +3 -3
- package/.output/server/_ssr/{ProxyViewerContainer-BnRwFEnn.mjs → ProxyViewerContainer-249bTH-T.mjs} +24 -30
- package/.output/server/_ssr/{ReplayDialog-C7dn9pd_.mjs → ReplayDialog-C1aGx0y1.mjs} +4 -4
- package/.output/server/_ssr/{RequestAnatomy-C1rWpe9-.mjs → RequestAnatomy-D2bCiEJn.mjs} +2 -2
- package/.output/server/_ssr/{ResponseView-hGpPaYsf.mjs → ResponseView-DP6k4Xs_.mjs} +3 -3
- package/.output/server/_ssr/{StreamingChunkSequence-BRWI1r_G.mjs → StreamingChunkSequence-HyXZV-b5.mjs} +3 -3
- package/.output/server/_ssr/{index-BKURLVPz.mjs → index-Bt47f9pn.mjs} +2 -2
- package/.output/server/_ssr/index.mjs +2 -2
- package/.output/server/_ssr/{json-viewer-BBd2DtQP.mjs → json-viewer-Co-YRwUP.mjs} +2 -2
- package/.output/server/_ssr/{router-BcZ0D6AB.mjs → router-to_OJirX.mjs} +383 -43
- package/.output/server/{_tanstack-start-manifest_v-1y8ZVxRI.mjs → _tanstack-start-manifest_v-Bd-2YRWo.mjs} +1 -1
- package/.output/server/index.mjs +64 -64
- package/README.md +57 -4
- package/package.json +9 -2
- package/scripts/setup-codex-skill.mjs +38 -0
- package/scripts/setup-windows-runtime.mjs +74 -0
- package/src/assets/agent-inspector.ico +0 -0
- package/src/cli/onboard.ts +175 -68
- package/src/cli/templates/codex-skill-onboard.ts +210 -0
- package/src/cli.ts +18 -2
- package/src/components/providers/ProviderCard.tsx +2 -27
- package/src/components/providers/ProvidersPanel.tsx +16 -0
- package/src/knowledge/openclawClient.ts +34 -5
- package/src/knowledge/openclawGatewayClient.ts +237 -0
- package/src/knowledge/openclawMarkdown.ts +146 -0
- package/src/lib/providerTestPrompt.ts +78 -0
- package/src/routes/api/providers.$providerId.test.log.ts +9 -22
- package/.output/public/assets/_sessionId-DsNRbnNm.js +0 -1
- package/.output/public/assets/index-CpWG2hFn.css +0 -1
- package/.output/public/assets/index-DmBV8Gve.js +0 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { KnowledgeCandidate, KnowledgeSearchResponse, OpenClawMemoryPayload } from "./types";
|
|
3
3
|
import { KnowledgeSearchResponseSchema, KnowledgeSearchResultSchema } from "./types";
|
|
4
|
+
import { isOpenClawGatewayConfigured, searchOpenClawGateway } from "./openclawGatewayClient";
|
|
5
|
+
import { isOpenClawFileBridgeConfigured, writeCandidateToOpenClawMemory } from "./openclawMarkdown";
|
|
4
6
|
import { redactCandidate } from "./redactor";
|
|
5
7
|
|
|
6
8
|
const OpenClawWriteResponseSchema = z.object({
|
|
@@ -18,12 +20,16 @@ export type PromoteResult =
|
|
|
18
20
|
error: string;
|
|
19
21
|
};
|
|
20
22
|
|
|
21
|
-
function
|
|
23
|
+
function getLegacyEndpoint(): string | null {
|
|
22
24
|
const endpoint = process.env["OPENCLAW_MEMORY_URL"] ?? process.env["OPENCLAW_API_URL"];
|
|
23
25
|
if (endpoint === undefined || endpoint.trim() === "") return null;
|
|
24
26
|
return endpoint.trim();
|
|
25
27
|
}
|
|
26
28
|
|
|
29
|
+
function isLegacyBackendConfigured(): boolean {
|
|
30
|
+
return getLegacyEndpoint() !== null;
|
|
31
|
+
}
|
|
32
|
+
|
|
27
33
|
function buildMemoryUrl(endpoint: string): string {
|
|
28
34
|
return endpoint.endsWith("/memories") ? endpoint : `${endpoint.replace(/\/$/, "")}/memories`;
|
|
29
35
|
}
|
|
@@ -61,11 +67,21 @@ export function buildOpenClawPayload(candidate: KnowledgeCandidate): OpenClawMem
|
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
export async function promoteToOpenClaw(candidate: KnowledgeCandidate): Promise<PromoteResult> {
|
|
64
|
-
|
|
70
|
+
if (isOpenClawFileBridgeConfigured()) {
|
|
71
|
+
const result = await writeCandidateToOpenClawMemory(candidate);
|
|
72
|
+
if (result.success) {
|
|
73
|
+
return { success: true, memoryId: result.memoryId };
|
|
74
|
+
}
|
|
75
|
+
return { success: false, error: result.error };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const endpoint = getLegacyEndpoint();
|
|
65
79
|
if (endpoint === null) {
|
|
66
80
|
return {
|
|
67
81
|
success: false,
|
|
68
|
-
error:
|
|
82
|
+
error:
|
|
83
|
+
"OpenClaw memory backend is not configured. Set OPENCLAW_WORKSPACE_DIR " +
|
|
84
|
+
"for file-backed memory or OPENCLAW_MEMORY_URL for a legacy HTTP backend.",
|
|
69
85
|
};
|
|
70
86
|
}
|
|
71
87
|
|
|
@@ -91,11 +107,20 @@ export async function searchOpenClaw(
|
|
|
91
107
|
query: string,
|
|
92
108
|
project?: string,
|
|
93
109
|
): Promise<KnowledgeSearchResponse> {
|
|
94
|
-
|
|
110
|
+
if (isOpenClawGatewayConfigured()) {
|
|
111
|
+
return await searchOpenClawGateway(query, project);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const endpoint = getLegacyEndpoint();
|
|
95
115
|
if (endpoint === null) {
|
|
116
|
+
const workspaceHint = isOpenClawFileBridgeConfigured()
|
|
117
|
+
? " OPENCLAW_WORKSPACE_DIR is configured for writes, but search requires OPENCLAW_GATEWAY_URL."
|
|
118
|
+
: "";
|
|
96
119
|
return {
|
|
97
120
|
results: [],
|
|
98
|
-
warning:
|
|
121
|
+
warning:
|
|
122
|
+
"OpenClaw search backend is not configured. Set OPENCLAW_GATEWAY_URL " +
|
|
123
|
+
`or OPENCLAW_MEMORY_URL.${workspaceHint}`,
|
|
99
124
|
};
|
|
100
125
|
}
|
|
101
126
|
|
|
@@ -116,3 +141,7 @@ export async function searchOpenClaw(
|
|
|
116
141
|
}
|
|
117
142
|
return { results: [], warning: "OpenClaw search returned an unparseable response." };
|
|
118
143
|
}
|
|
144
|
+
|
|
145
|
+
export function isOpenClawPromotionConfigured(): boolean {
|
|
146
|
+
return isOpenClawFileBridgeConfigured() || isLegacyBackendConfigured();
|
|
147
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { KnowledgeSearchResponse, KnowledgeSearchResult } from "./types";
|
|
3
|
+
|
|
4
|
+
const OpenClawGatewayErrorSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
type: z.string().optional(),
|
|
7
|
+
message: z.string().optional(),
|
|
8
|
+
})
|
|
9
|
+
.passthrough();
|
|
10
|
+
|
|
11
|
+
const OpenClawGatewayInvokeResponseSchema = z
|
|
12
|
+
.object({
|
|
13
|
+
ok: z.boolean().optional(),
|
|
14
|
+
result: z.unknown().optional(),
|
|
15
|
+
error: OpenClawGatewayErrorSchema.optional(),
|
|
16
|
+
})
|
|
17
|
+
.passthrough();
|
|
18
|
+
|
|
19
|
+
const OpenClawGatewayContentItemSchema = z
|
|
20
|
+
.object({
|
|
21
|
+
type: z.string().optional(),
|
|
22
|
+
text: z.string().optional(),
|
|
23
|
+
})
|
|
24
|
+
.passthrough();
|
|
25
|
+
|
|
26
|
+
const OpenClawMemoryHitSchema = z
|
|
27
|
+
.object({
|
|
28
|
+
id: z.string().optional(),
|
|
29
|
+
path: z.string().optional(),
|
|
30
|
+
title: z.string().optional(),
|
|
31
|
+
kind: z.string().optional(),
|
|
32
|
+
corpus: z.string().optional(),
|
|
33
|
+
score: z.number().nullable().optional(),
|
|
34
|
+
snippet: z.string().optional(),
|
|
35
|
+
content: z.string().optional(),
|
|
36
|
+
source: z.string().nullable().optional(),
|
|
37
|
+
startLine: z.number().optional(),
|
|
38
|
+
endLine: z.number().optional(),
|
|
39
|
+
})
|
|
40
|
+
.passthrough();
|
|
41
|
+
|
|
42
|
+
const OpenClawToolResultDetailsSchema = z
|
|
43
|
+
.object({
|
|
44
|
+
results: z.array(OpenClawMemoryHitSchema).optional(),
|
|
45
|
+
})
|
|
46
|
+
.passthrough();
|
|
47
|
+
|
|
48
|
+
const OpenClawToolResultSchema = z
|
|
49
|
+
.object({
|
|
50
|
+
results: z.array(OpenClawMemoryHitSchema).optional(),
|
|
51
|
+
details: OpenClawToolResultDetailsSchema.optional(),
|
|
52
|
+
content: z.array(OpenClawGatewayContentItemSchema).optional(),
|
|
53
|
+
})
|
|
54
|
+
.passthrough();
|
|
55
|
+
|
|
56
|
+
type OpenClawMemoryHit = z.infer<typeof OpenClawMemoryHitSchema>;
|
|
57
|
+
|
|
58
|
+
export function getOpenClawGatewayUrl(): string | null {
|
|
59
|
+
const value = process.env["OPENCLAW_GATEWAY_URL"];
|
|
60
|
+
if (value === undefined || value.trim() === "") {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return value.trim();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function isOpenClawGatewayConfigured(): boolean {
|
|
67
|
+
return getOpenClawGatewayUrl() !== null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function buildToolInvokeUrl(gatewayUrl: string): string {
|
|
71
|
+
return `${gatewayUrl.replace(/\/$/, "")}/tools/invoke`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getOpenClawSessionKey(): string {
|
|
75
|
+
const value = process.env["OPENCLAW_SESSION_KEY"];
|
|
76
|
+
return value === undefined || value.trim() === "" ? "main" : value.trim();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function getGatewayToken(): string | null {
|
|
80
|
+
const token =
|
|
81
|
+
process.env["OPENCLAW_GATEWAY_TOKEN"] ??
|
|
82
|
+
process.env["OPENCLAW_GATEWAY_PASSWORD"] ??
|
|
83
|
+
process.env["OPENCLAW_API_KEY"];
|
|
84
|
+
if (token === undefined || token.trim() === "") {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return token.trim();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function gatewayHeaders(): Headers {
|
|
91
|
+
const headers = new Headers({ "content-type": "application/json" });
|
|
92
|
+
const token = getGatewayToken();
|
|
93
|
+
if (token !== null) {
|
|
94
|
+
headers.set("authorization", `Bearer ${token}`);
|
|
95
|
+
}
|
|
96
|
+
return headers;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function buildSearchQuery(query: string, project?: string): string {
|
|
100
|
+
if (project === undefined || project === "") {
|
|
101
|
+
return query;
|
|
102
|
+
}
|
|
103
|
+
return `${query}\nProject: ${project}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function formatHitTitle(hit: OpenClawMemoryHit, index: number): string {
|
|
107
|
+
if (hit.title !== undefined && hit.title !== "") {
|
|
108
|
+
return hit.title;
|
|
109
|
+
}
|
|
110
|
+
if (hit.path !== undefined && hit.path !== "") {
|
|
111
|
+
return hit.path;
|
|
112
|
+
}
|
|
113
|
+
if (hit.id !== undefined && hit.id !== "") {
|
|
114
|
+
return hit.id;
|
|
115
|
+
}
|
|
116
|
+
return `OpenClaw memory result ${String(index + 1)}`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function formatHitId(hit: OpenClawMemoryHit, index: number): string {
|
|
120
|
+
const base = hit.id ?? hit.path ?? `result-${String(index + 1)}`;
|
|
121
|
+
const start = hit.startLine === undefined ? "" : `:${String(hit.startLine)}`;
|
|
122
|
+
const end = hit.endLine === undefined ? "" : `-${String(hit.endLine)}`;
|
|
123
|
+
return `openclaw:${base}${start}${end}`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function formatHitContent(hit: OpenClawMemoryHit): string {
|
|
127
|
+
if (hit.snippet !== undefined && hit.snippet !== "") {
|
|
128
|
+
return hit.snippet;
|
|
129
|
+
}
|
|
130
|
+
if (hit.content !== undefined && hit.content !== "") {
|
|
131
|
+
return hit.content;
|
|
132
|
+
}
|
|
133
|
+
return "";
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function formatHitType(hit: OpenClawMemoryHit): string {
|
|
137
|
+
if (hit.kind !== undefined && hit.kind !== "") {
|
|
138
|
+
return hit.kind;
|
|
139
|
+
}
|
|
140
|
+
if (hit.corpus !== undefined && hit.corpus !== "") {
|
|
141
|
+
return hit.corpus;
|
|
142
|
+
}
|
|
143
|
+
return "openclaw-memory";
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function mapGatewayHit(
|
|
147
|
+
hit: OpenClawMemoryHit,
|
|
148
|
+
index: number,
|
|
149
|
+
project?: string,
|
|
150
|
+
): KnowledgeSearchResult {
|
|
151
|
+
return {
|
|
152
|
+
id: formatHitId(hit, index),
|
|
153
|
+
type: formatHitType(hit),
|
|
154
|
+
title: formatHitTitle(hit, index),
|
|
155
|
+
content: formatHitContent(hit),
|
|
156
|
+
score: hit.score ?? null,
|
|
157
|
+
source: hit.source ?? "openclaw",
|
|
158
|
+
project: project ?? null,
|
|
159
|
+
evidence: hit,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function extractGatewayHits(result: unknown): OpenClawMemoryHit[] | null {
|
|
164
|
+
const parsed = OpenClawToolResultSchema.safeParse(result);
|
|
165
|
+
if (!parsed.success) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
return parsed.data.details?.results ?? parsed.data.results ?? [];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function formatGatewayError(raw: unknown): string {
|
|
172
|
+
const parsed = OpenClawGatewayInvokeResponseSchema.safeParse(raw);
|
|
173
|
+
if (!parsed.success) {
|
|
174
|
+
return "OpenClaw Gateway returned an unparseable response.";
|
|
175
|
+
}
|
|
176
|
+
const message = parsed.data.error?.message;
|
|
177
|
+
if (message !== undefined && message !== "") {
|
|
178
|
+
return message;
|
|
179
|
+
}
|
|
180
|
+
return "OpenClaw Gateway tool invocation failed.";
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export async function searchOpenClawGateway(
|
|
184
|
+
query: string,
|
|
185
|
+
project?: string,
|
|
186
|
+
): Promise<KnowledgeSearchResponse> {
|
|
187
|
+
const gatewayUrl = getOpenClawGatewayUrl();
|
|
188
|
+
if (gatewayUrl === null) {
|
|
189
|
+
return {
|
|
190
|
+
results: [],
|
|
191
|
+
warning: "OpenClaw Gateway is not configured. Set OPENCLAW_GATEWAY_URL.",
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const response = await fetch(buildToolInvokeUrl(gatewayUrl), {
|
|
196
|
+
method: "POST",
|
|
197
|
+
headers: gatewayHeaders(),
|
|
198
|
+
body: JSON.stringify({
|
|
199
|
+
tool: "memory_search",
|
|
200
|
+
args: {
|
|
201
|
+
query: buildSearchQuery(query, project),
|
|
202
|
+
maxResults: 10,
|
|
203
|
+
corpus: "all",
|
|
204
|
+
},
|
|
205
|
+
sessionKey: getOpenClawSessionKey(),
|
|
206
|
+
}),
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
const raw: unknown = await response.json().catch(() => null);
|
|
210
|
+
if (!response.ok) {
|
|
211
|
+
return {
|
|
212
|
+
results: [],
|
|
213
|
+
warning: `OpenClaw Gateway search failed with ${response.status}: ${formatGatewayError(raw)}`,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const parsed = OpenClawGatewayInvokeResponseSchema.safeParse(raw);
|
|
218
|
+
if (!parsed.success) {
|
|
219
|
+
return { results: [], warning: "OpenClaw Gateway returned an unparseable response." };
|
|
220
|
+
}
|
|
221
|
+
if (parsed.data.ok === false) {
|
|
222
|
+
return { results: [], warning: formatGatewayError(raw) };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const hits = extractGatewayHits(parsed.data.result);
|
|
226
|
+
if (hits === null) {
|
|
227
|
+
return {
|
|
228
|
+
results: [],
|
|
229
|
+
warning: "OpenClaw memory_search returned an unparseable tool result.",
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
results: hits.map((hit, index) => mapGatewayHit(hit, index, project)),
|
|
235
|
+
warning: null,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import type { KnowledgeCandidate } from "./types";
|
|
4
|
+
import { redactCandidate } from "./redactor";
|
|
5
|
+
|
|
6
|
+
export type OpenClawFilePromotionResult =
|
|
7
|
+
| {
|
|
8
|
+
success: true;
|
|
9
|
+
memoryId: string;
|
|
10
|
+
relativePath: string;
|
|
11
|
+
absolutePath: string;
|
|
12
|
+
}
|
|
13
|
+
| {
|
|
14
|
+
success: false;
|
|
15
|
+
error: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function getOpenClawWorkspaceDir(): string | null {
|
|
19
|
+
const value = process.env["OPENCLAW_WORKSPACE_DIR"];
|
|
20
|
+
if (value === undefined || value.trim() === "") {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return value.trim();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isOpenClawFileBridgeConfigured(): boolean {
|
|
27
|
+
return getOpenClawWorkspaceDir() !== null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function normalizeDatePrefix(value: string): string {
|
|
31
|
+
const date = value.slice(0, 10);
|
|
32
|
+
return /^\d{4}-\d{2}-\d{2}$/.test(date) ? date : "undated";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function normalizePathSegment(value: string, fallback: string): string {
|
|
36
|
+
const segment = value
|
|
37
|
+
.toLowerCase()
|
|
38
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
39
|
+
.replace(/^-+|-+$/g, "")
|
|
40
|
+
.slice(0, 96);
|
|
41
|
+
return segment === "" ? fallback : segment;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function formatNullable(value: string | null): string {
|
|
45
|
+
return value === null || value === "" ? "unknown" : value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function formatList(values: string[]): string {
|
|
49
|
+
return values.length === 0 ? "none" : values.join(", ");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function buildEvidenceLink(candidate: KnowledgeCandidate): string {
|
|
53
|
+
return `agent-inspector:session:${candidate.sessionId}:candidate:${candidate.id}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function buildOpenClawMemoryRelativePath(candidate: KnowledgeCandidate): string {
|
|
57
|
+
const date = normalizeDatePrefix(candidate.updatedAt);
|
|
58
|
+
const slug = normalizePathSegment(candidate.id, "candidate");
|
|
59
|
+
return path.join("memory", "agent-inspector", date, `${slug}.md`).replace(/\\/g, "/");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function buildOpenClawMemoryMarkdown(candidate: KnowledgeCandidate): string {
|
|
63
|
+
const sanitized = redactCandidate(candidate);
|
|
64
|
+
return [
|
|
65
|
+
"# Agent Inspector Memory Candidate",
|
|
66
|
+
"",
|
|
67
|
+
"Layer: L3 memory candidate for OpenClaw L4 durable recall",
|
|
68
|
+
"Source: agent-inspector",
|
|
69
|
+
"",
|
|
70
|
+
"## Metadata",
|
|
71
|
+
"",
|
|
72
|
+
`- Type: ${sanitized.type}`,
|
|
73
|
+
`- Status: ${sanitized.status}`,
|
|
74
|
+
`- Project: ${formatNullable(sanitized.evidence.project)}`,
|
|
75
|
+
`- Session: ${sanitized.sessionId}`,
|
|
76
|
+
`- Log IDs: ${sanitized.logIds.join(", ")}`,
|
|
77
|
+
`- Models: ${formatList(sanitized.evidence.models)}`,
|
|
78
|
+
`- Tags: ${formatList(sanitized.tags)}`,
|
|
79
|
+
`- Created: ${sanitized.createdAt}`,
|
|
80
|
+
`- Updated: ${sanitized.updatedAt}`,
|
|
81
|
+
`- Evidence: ${buildEvidenceLink(sanitized)}`,
|
|
82
|
+
`- Redacted: ${String(sanitized.redaction.redacted)}`,
|
|
83
|
+
`- Redaction patterns: ${formatList(sanitized.redaction.patterns)}`,
|
|
84
|
+
"",
|
|
85
|
+
"## Durable Knowledge Candidate",
|
|
86
|
+
"",
|
|
87
|
+
sanitized.content,
|
|
88
|
+
"",
|
|
89
|
+
"## Recall Guidance",
|
|
90
|
+
"",
|
|
91
|
+
[
|
|
92
|
+
"- Treat this as reviewed Agent Inspector knowledge extracted from LLM interaction traces.",
|
|
93
|
+
"- Use the evidence id to return to Agent Inspector when raw proof is needed.",
|
|
94
|
+
"- Do not treat this file as raw logs; sensitive values were redacted before export.",
|
|
95
|
+
].join("\n"),
|
|
96
|
+
"",
|
|
97
|
+
].join("\n");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function resolveTargetPath(workspaceDir: string, relativePath: string): string | null {
|
|
101
|
+
const root = path.resolve(workspaceDir);
|
|
102
|
+
const target = path.resolve(root, relativePath);
|
|
103
|
+
const relative = path.relative(root, target);
|
|
104
|
+
if (relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return target;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function writeCandidateToOpenClawMemory(
|
|
111
|
+
candidate: KnowledgeCandidate,
|
|
112
|
+
): Promise<OpenClawFilePromotionResult> {
|
|
113
|
+
const workspaceDir = getOpenClawWorkspaceDir();
|
|
114
|
+
if (workspaceDir === null) {
|
|
115
|
+
return {
|
|
116
|
+
success: false,
|
|
117
|
+
error: "OpenClaw workspace is not configured. Set OPENCLAW_WORKSPACE_DIR.",
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const relativePath = buildOpenClawMemoryRelativePath(candidate);
|
|
122
|
+
const target = resolveTargetPath(workspaceDir, relativePath);
|
|
123
|
+
if (target === null) {
|
|
124
|
+
return {
|
|
125
|
+
success: false,
|
|
126
|
+
error: "OpenClaw memory target resolved outside OPENCLAW_WORKSPACE_DIR.",
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
132
|
+
await fs.writeFile(target, buildOpenClawMemoryMarkdown(candidate), "utf8");
|
|
133
|
+
} catch (error) {
|
|
134
|
+
return {
|
|
135
|
+
success: false,
|
|
136
|
+
error: `OpenClaw memory file write failed: ${String(error)}`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
success: true,
|
|
142
|
+
memoryId: `openclaw-file:${relativePath}`,
|
|
143
|
+
relativePath,
|
|
144
|
+
absolutePath: target,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export type ProviderTestMode = "non-streaming" | "streaming";
|
|
2
|
+
|
|
3
|
+
export type ProviderTestMessage = {
|
|
4
|
+
role: "user";
|
|
5
|
+
content: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type ProviderTestRequestBody = {
|
|
9
|
+
model: string;
|
|
10
|
+
messages: ProviderTestMessage[];
|
|
11
|
+
max_tokens: number;
|
|
12
|
+
stream?: true;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const MEMORY_PROBE_FACTS = [
|
|
16
|
+
"Project fact: Agent Inspector captures LLM traffic and turns it into Raw Trace, Session Episode, and Memory Candidate layers.",
|
|
17
|
+
"Procedure: before release, run bun test, npm run typecheck, npm run lint, npm run build, and openspec validate --all --strict.",
|
|
18
|
+
"Preference: the user prefers Chinese summaries, explicit verification, and commit/push/release closure when requested.",
|
|
19
|
+
"Pitfall: preserve .llm-inspector config compatibility; do not write raw logs or secrets into durable memory.",
|
|
20
|
+
"OpenClaw boundary: Agent Inspector owns L1-L3; OpenClaw owns durable indexing, retrieval, and recall.",
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
function modeInstruction(mode: ProviderTestMode): string {
|
|
24
|
+
switch (mode) {
|
|
25
|
+
case "non-streaming":
|
|
26
|
+
return "Reply in four concise bullets.";
|
|
27
|
+
case "streaming":
|
|
28
|
+
return "Reply in three concise bullets.";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function maxTokensForMode(mode: ProviderTestMode): number {
|
|
33
|
+
switch (mode) {
|
|
34
|
+
case "non-streaming":
|
|
35
|
+
return 1024;
|
|
36
|
+
case "streaming":
|
|
37
|
+
return 384;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function buildProviderTestUserPrompt(mode: ProviderTestMode): string {
|
|
42
|
+
return [
|
|
43
|
+
"You are validating an LLM provider connection for Agent Inspector.",
|
|
44
|
+
"This request includes a synthetic memory probe so Agent Inspector can verify its three Inspector-owned memory layers.",
|
|
45
|
+
"",
|
|
46
|
+
"Synthetic memory probe:",
|
|
47
|
+
...MEMORY_PROBE_FACTS.map((fact) => `- ${fact}`),
|
|
48
|
+
"",
|
|
49
|
+
"Return:",
|
|
50
|
+
"1. connection status",
|
|
51
|
+
"2. one project fact",
|
|
52
|
+
"3. one reusable procedure",
|
|
53
|
+
"4. one caution",
|
|
54
|
+
"",
|
|
55
|
+
modeInstruction(mode),
|
|
56
|
+
].join("\n");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function buildProviderTestMessages(mode: ProviderTestMode): ProviderTestMessage[] {
|
|
60
|
+
return [{ role: "user", content: buildProviderTestUserPrompt(mode) }];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function buildProviderTestRequestBody(
|
|
64
|
+
model: string,
|
|
65
|
+
mode: ProviderTestMode,
|
|
66
|
+
): ProviderTestRequestBody {
|
|
67
|
+
const base = {
|
|
68
|
+
model,
|
|
69
|
+
messages: buildProviderTestMessages(mode),
|
|
70
|
+
max_tokens: maxTokensForMode(mode),
|
|
71
|
+
};
|
|
72
|
+
switch (mode) {
|
|
73
|
+
case "non-streaming":
|
|
74
|
+
return base;
|
|
75
|
+
case "streaming":
|
|
76
|
+
return { ...base, stream: true };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -2,6 +2,7 @@ import { createFileRoute } from "@tanstack/react-router";
|
|
|
2
2
|
import { getProvider, getModelUsageName } from "../../proxy/providers";
|
|
3
3
|
import { appendLogEntry } from "../../proxy/logger";
|
|
4
4
|
import { addTestLogEntry } from "../../proxy/store";
|
|
5
|
+
import { buildProviderTestRequestBody } from "../../lib/providerTestPrompt";
|
|
5
6
|
import {
|
|
6
7
|
ProviderTestResultsSchema,
|
|
7
8
|
type ProviderTestResult as TestResult,
|
|
@@ -63,11 +64,7 @@ async function logModelResults(
|
|
|
63
64
|
const nonStreamingResult = nsResult;
|
|
64
65
|
const streamingResult = sResult;
|
|
65
66
|
|
|
66
|
-
const requestBody = JSON.stringify(
|
|
67
|
-
model: usageModel,
|
|
68
|
-
messages: [{ role: "user", content: "say hello and briefly introduce yourself" }],
|
|
69
|
-
max_tokens: 1024,
|
|
70
|
-
});
|
|
67
|
+
const requestBody = JSON.stringify(buildProviderTestRequestBody(usageModel, "non-streaming"));
|
|
71
68
|
const upstreamUrl = `${anthropicUrl}/v1/messages`;
|
|
72
69
|
|
|
73
70
|
await addTestLogEntry({
|
|
@@ -104,12 +101,9 @@ async function logModelResults(
|
|
|
104
101
|
),
|
|
105
102
|
);
|
|
106
103
|
|
|
107
|
-
const streamingRequestBody = JSON.stringify(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
max_tokens: 256,
|
|
111
|
-
stream: true,
|
|
112
|
-
});
|
|
104
|
+
const streamingRequestBody = JSON.stringify(
|
|
105
|
+
buildProviderTestRequestBody(usageModel, "streaming"),
|
|
106
|
+
);
|
|
113
107
|
|
|
114
108
|
await addTestLogEntry({
|
|
115
109
|
timestamp: new Date().toISOString(),
|
|
@@ -155,11 +149,7 @@ async function logModelResults(
|
|
|
155
149
|
const nonStreamingResult = nsResult;
|
|
156
150
|
const streamingResult = sResult;
|
|
157
151
|
|
|
158
|
-
const requestBody = JSON.stringify(
|
|
159
|
-
model: usageModel,
|
|
160
|
-
messages: [{ role: "user", content: "say hello and briefly introduce yourself" }],
|
|
161
|
-
max_tokens: 1024,
|
|
162
|
-
});
|
|
152
|
+
const requestBody = JSON.stringify(buildProviderTestRequestBody(usageModel, "non-streaming"));
|
|
163
153
|
const upstreamUrl = `${openaiUrl}/v1/chat/completions`;
|
|
164
154
|
|
|
165
155
|
await addTestLogEntry({
|
|
@@ -196,12 +186,9 @@ async function logModelResults(
|
|
|
196
186
|
),
|
|
197
187
|
);
|
|
198
188
|
|
|
199
|
-
const streamingRequestBody = JSON.stringify(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
max_tokens: 256,
|
|
203
|
-
stream: true,
|
|
204
|
-
});
|
|
189
|
+
const streamingRequestBody = JSON.stringify(
|
|
190
|
+
buildProviderTestRequestBody(usageModel, "streaming"),
|
|
191
|
+
);
|
|
205
192
|
|
|
206
193
|
await addTestLogEntry({
|
|
207
194
|
timestamp: new Date().toISOString(),
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{R as s,j as e}from"./main-DHs7FBK3.js";import{P as i}from"./ProxyViewerContainer-pEBqVp1d.js";function t(){const{sessionId:o}=s.useParams();return e.jsx(i,{initialSessionId:o},o)}export{t as component};
|