@tonyclaw/agent-inspector 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.output/cli.js +344 -53
- package/.output/nitro.json +1 -1
- package/.output/public/assets/{CompareDrawer-sVLGhCO3.js → CompareDrawer-D5A4bTfV.js} +1 -1
- package/.output/public/assets/ProxyViewerContainer-Da0jpBkp.js +101 -0
- package/.output/public/assets/{ReplayDialog-DxbFUqNW.js → ReplayDialog-CxUk_TF0.js} +1 -1
- package/.output/public/assets/{RequestAnatomy-CSmGQa_g.js → RequestAnatomy-DIlzjgjJ.js} +1 -1
- package/.output/public/assets/ResponseView-DQCuKJ1G.js +1 -0
- package/.output/public/assets/{StreamingChunkSequence-BzqpY0TN.js → StreamingChunkSequence-DHk4SGGL.js} +1 -1
- package/.output/public/assets/_sessionId-dY1TTl7N.js +1 -0
- package/.output/public/assets/index-D7wwbwly.css +1 -0
- package/.output/public/assets/index-FqQZbfl2.js +1 -0
- package/.output/public/assets/{json-viewer-CKNMihlh.js → json-viewer-BbU0n8eM.js} +1 -1
- package/.output/public/assets/{main-yWf8dv9w.js → main-CZT_F-gu.js} +2 -2
- package/.output/server/_libs/lucide-react.mjs +8 -8
- package/.output/server/{_sessionId-DfHd0gd8.mjs → _sessionId-B-s9P7fJ.mjs} +2 -2
- package/.output/server/_ssr/{CompareDrawer-DGYAUWgF.mjs → CompareDrawer-C08L3UOO.mjs} +4 -4
- package/.output/server/_ssr/{ProxyViewerContainer-fawglkTo.mjs → ProxyViewerContainer-CMWl3Ijy.mjs} +414 -70
- package/.output/server/_ssr/{ReplayDialog-B4vlKa2W.mjs → ReplayDialog-CPDo9_G5.mjs} +4 -4
- package/.output/server/_ssr/{RequestAnatomy-BNQvEIZK.mjs → RequestAnatomy-D9wt_K1E.mjs} +3 -3
- package/.output/server/_ssr/{ResponseView-X6X6G16_.mjs → ResponseView-DXaL7nY3.mjs} +4 -4
- package/.output/server/_ssr/{StreamingChunkSequence-BPVN3MnF.mjs → StreamingChunkSequence-B_hudZyb.mjs} +3 -3
- package/.output/server/_ssr/{index-CXmpc2X5.mjs → index-CuE_BN86.mjs} +2 -2
- package/.output/server/_ssr/index.mjs +2 -2
- package/.output/server/_ssr/{json-viewer-3XC3eq4R.mjs → json-viewer-Ci6kkjde.mjs} +2 -2
- package/.output/server/_ssr/{router-C0B2qvIM.mjs → router-BemxgIg7.mjs} +402 -131
- package/.output/server/{_tanstack-start-manifest_v-7tfsmd2I.mjs → _tanstack-start-manifest_v--L1_b4sd.mjs} +1 -1
- package/.output/server/index.mjs +62 -62
- package/README.md +50 -7
- package/package.json +3 -2
- package/scripts/setup-codex-skill.mjs +38 -0
- package/scripts/setup-windows-runtime.mjs +4 -3
- package/src/cli/onboard.ts +175 -68
- package/src/cli/templates/codex-skill-onboard.ts +210 -0
- package/src/components/providers/ProviderCard.tsx +2 -27
- package/src/components/providers/ProvidersPanel.tsx +16 -0
- package/src/components/proxy-viewer/AgentTraceSummary.tsx +218 -0
- package/src/components/proxy-viewer/ConversationGroup.tsx +6 -0
- package/src/components/proxy-viewer/ToolTraceEvents.tsx +33 -0
- package/src/components/proxy-viewer/TurnGroup.tsx +11 -1
- package/src/components/proxy-viewer/viewerState.ts +177 -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/proxy/chunkStorage.ts +3 -4
- package/src/proxy/logger.ts +8 -15
- package/src/proxy/store.ts +8 -16
- package/src/routes/api/providers.$providerId.test.log.ts +7 -99
- package/.output/public/assets/ProxyViewerContainer-p9QvzZ6U.js +0 -101
- package/.output/public/assets/ResponseView-B5f89c8Z.js +0 -1
- package/.output/public/assets/_sessionId-BF7ftHV3.js +0 -1
- package/.output/public/assets/index-BU0PpLby.js +0 -1
- package/.output/public/assets/index-CpWG2hFn.css +0 -1
|
@@ -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
|
+
}
|
|
@@ -30,11 +30,10 @@ const StreamingChunksDataSchema = z.object({
|
|
|
30
30
|
truncated: z.boolean().optional(),
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
const CHUNKS_DIR_ENV = process.env["CHUNKS_DIR"];
|
|
34
|
-
|
|
35
33
|
export function getChunksDir(): string {
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
const chunksDirEnv = process.env["CHUNKS_DIR"];
|
|
35
|
+
if (chunksDirEnv !== undefined && chunksDirEnv !== "") {
|
|
36
|
+
return isAbsolute(chunksDirEnv) ? chunksDirEnv : join(getDataDir(), chunksDirEnv);
|
|
38
37
|
}
|
|
39
38
|
return join(getDataDir(), "chunks");
|
|
40
39
|
}
|
package/src/proxy/logger.ts
CHANGED
|
@@ -3,23 +3,14 @@ import { writeFileSync, mkdirSync } from "node:fs";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { getDataDir } from "./dataDir";
|
|
5
5
|
|
|
6
|
-
const LOG_DIR_ENV = process.env["LOG_DIR"];
|
|
7
6
|
const RETENTION_DAYS = Number(process.env["LOG_RETENTION_DAYS"] ?? "7");
|
|
8
|
-
const LOG_FILE_ENV = process.env["AGENT_INSPECTOR_LOG_FILE"];
|
|
9
|
-
|
|
10
|
-
let resolvedLogDir: string | null = null;
|
|
11
7
|
|
|
12
8
|
export function resolveLogDir(): string {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
resolvedLogDir = path.isAbsolute(LOG_DIR_ENV)
|
|
17
|
-
? LOG_DIR_ENV
|
|
18
|
-
: path.join(getDataDir(), LOG_DIR_ENV);
|
|
19
|
-
} else {
|
|
20
|
-
resolvedLogDir = path.join(getDataDir(), "logs");
|
|
9
|
+
const logDirEnv = process.env["LOG_DIR"];
|
|
10
|
+
if (logDirEnv !== undefined && logDirEnv !== "") {
|
|
11
|
+
return path.isAbsolute(logDirEnv) ? logDirEnv : path.join(getDataDir(), logDirEnv);
|
|
21
12
|
}
|
|
22
|
-
return
|
|
13
|
+
return path.join(getDataDir(), "logs");
|
|
23
14
|
}
|
|
24
15
|
|
|
25
16
|
export function getLogFilePath(): string {
|
|
@@ -31,8 +22,9 @@ export function getLogFilePath(): string {
|
|
|
31
22
|
}
|
|
32
23
|
|
|
33
24
|
function getInspectorLogPath(): string {
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
const logFileEnv = process.env["AGENT_INSPECTOR_LOG_FILE"];
|
|
26
|
+
if (logFileEnv !== undefined && logFileEnv !== "") {
|
|
27
|
+
return logFileEnv;
|
|
36
28
|
}
|
|
37
29
|
return path.join(getDataDir(), "logs", "inspector.log");
|
|
38
30
|
}
|
|
@@ -43,6 +35,7 @@ export async function initLogger(): Promise<void> {
|
|
|
43
35
|
const cutoff = Date.now() - retentionMs;
|
|
44
36
|
|
|
45
37
|
try {
|
|
38
|
+
await mkdir(dir, { recursive: true });
|
|
46
39
|
const entries = await readdir(dir);
|
|
47
40
|
for (const entry of entries) {
|
|
48
41
|
if (!entry.endsWith(".jsonl")) continue;
|
package/src/proxy/store.ts
CHANGED
|
@@ -5,14 +5,7 @@ import { createInterface } from "node:readline";
|
|
|
5
5
|
import { Buffer } from "node:buffer";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { appendLogEntry, resolveLogDir, logger } from "./logger";
|
|
8
|
-
import {
|
|
9
|
-
addToIndex,
|
|
10
|
-
findInIndex,
|
|
11
|
-
getNextLogId,
|
|
12
|
-
getCurrentLogFile,
|
|
13
|
-
saveIndex,
|
|
14
|
-
loadIndex,
|
|
15
|
-
} from "./logIndex";
|
|
8
|
+
import { addToIndex, findInIndex, getNextLogId, getCurrentLogFile } from "./logIndex";
|
|
16
9
|
import { writeChunks } from "./chunkStorage";
|
|
17
10
|
import type { CapturedLog } from "./schemas";
|
|
18
11
|
import { CapturedLogSchema } from "./schemas";
|
|
@@ -67,17 +60,11 @@ function removeFromCache(id: number): void {
|
|
|
67
60
|
}
|
|
68
61
|
|
|
69
62
|
/**
|
|
70
|
-
* Add a test log entry
|
|
71
|
-
* This is used by the provider test endpoint
|
|
63
|
+
* Add a test log entry to the in-memory store and persistent log file.
|
|
64
|
+
* This is used by the provider test endpoint to seed the provider-test session.
|
|
72
65
|
*/
|
|
73
66
|
export async function addTestLogEntry(entry: Omit<CapturedLog, "id">): Promise<CapturedLog> {
|
|
74
67
|
const id = await getNextLogId();
|
|
75
|
-
// Update the index with the new maxId so subsequent calls get unique IDs
|
|
76
|
-
const index = await loadIndex();
|
|
77
|
-
if (id > index.maxId) {
|
|
78
|
-
index.maxId = id;
|
|
79
|
-
await saveIndex(index);
|
|
80
|
-
}
|
|
81
68
|
|
|
82
69
|
// Persist streaming chunks to disk if present
|
|
83
70
|
let streamingChunksPath: string | null = null;
|
|
@@ -100,6 +87,11 @@ export async function addTestLogEntry(entry: Omit<CapturedLog, "id">): Promise<C
|
|
|
100
87
|
sessionId: session.id,
|
|
101
88
|
streamingChunksPath,
|
|
102
89
|
};
|
|
90
|
+
|
|
91
|
+
const logFile = getCurrentLogFile();
|
|
92
|
+
appendLogEntry(log);
|
|
93
|
+
await addToIndex(id, logFile, -1, -1);
|
|
94
|
+
|
|
103
95
|
addToCache(log);
|
|
104
96
|
observeSessionLog(log, session.source);
|
|
105
97
|
emitLogUpdate(log);
|