@privateclaw/privateclaw 0.1.4 → 0.1.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/dist/bridges/openclaw-agent-bridge.d.ts +3 -1
- package/dist/bridges/openclaw-agent-bridge.js +231 -48
- package/dist/bridges/openclaw-agent-bridge.js.map +1 -1
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -1
- package/dist/openclaw-plugin.js +5 -3
- package/dist/openclaw-plugin.js.map +1 -1
- package/dist/provider.d.ts +2 -0
- package/dist/provider.js +94 -7
- package/dist/provider.js.map +1 -1
- package/dist/text.d.ts +1 -0
- package/dist/text.js +1 -0
- package/dist/text.js.map +1 -1
- package/dist/types.d.ts +4 -2
- package/openclaw.plugin.json +13 -3
- package/package.json +11 -2
- package/src/bridges/openclaw-agent-bridge.test.ts +180 -2
- package/src/bridges/openclaw-agent-bridge.ts +335 -63
- package/src/cli.ts +3 -0
- package/src/openclaw-plugin.ts +8 -3
- package/src/provider.test.ts +130 -0
- package/src/provider.ts +142 -5
- package/src/text.ts +5 -0
- package/src/types.ts +6 -1
- package/dist/qr-terminal-render.d.ts +0 -7
- package/dist/qr-terminal-render.js +0 -44
- package/dist/qr-terminal-render.js.map +0 -1
|
@@ -51,6 +51,48 @@ test("parseOpenClawAgentOutput accepts alternate text-bearing payload fields", (
|
|
|
51
51
|
});
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
+
test("parseOpenClawAgentOutput accepts top-level payload arrays from alternate OpenClaw JSON shapes", () => {
|
|
55
|
+
const result = parseOpenClawAgentOutput(
|
|
56
|
+
JSON.stringify({
|
|
57
|
+
payloads: [{ text: "pong-from-top-level" }],
|
|
58
|
+
meta: {
|
|
59
|
+
durationMs: 123,
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
assert.equal(result, "pong-from-top-level");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("parseOpenClawAgentOutput prefers tagged structured PrivateClaw responses", () => {
|
|
68
|
+
const result = parseOpenClawAgentOutput(
|
|
69
|
+
JSON.stringify({
|
|
70
|
+
status: "ok",
|
|
71
|
+
result: {
|
|
72
|
+
payloads: [
|
|
73
|
+
{
|
|
74
|
+
text: [
|
|
75
|
+
"Draft text that should not be shown.",
|
|
76
|
+
"<privateclaw-response>",
|
|
77
|
+
JSON.stringify({
|
|
78
|
+
version: 1,
|
|
79
|
+
messages: [{ text: "first-structured" }, { text: "second-structured" }],
|
|
80
|
+
data: { intent: "future-file-pipeline" },
|
|
81
|
+
}),
|
|
82
|
+
"</privateclaw-response>",
|
|
83
|
+
].join("\n"),
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
assert.deepEqual(result, {
|
|
91
|
+
messages: [{ text: "first-structured" }, { text: "second-structured" }],
|
|
92
|
+
data: { intent: "future-file-pipeline" },
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
54
96
|
test("OpenClawAgentBridge invokes openclaw agent with session-aware arguments", async () => {
|
|
55
97
|
let invokedFile = "";
|
|
56
98
|
let invokedArgs: string[] = [];
|
|
@@ -91,12 +133,17 @@ test("OpenClawAgentBridge invokes openclaw agent with session-aware arguments",
|
|
|
91
133
|
});
|
|
92
134
|
|
|
93
135
|
assert.equal(invokedFile, "openclaw-custom");
|
|
94
|
-
|
|
136
|
+
const prompt = invokedArgs[4] ?? "";
|
|
137
|
+
assert.deepEqual(invokedArgs.slice(0, 4), [
|
|
95
138
|
"agent",
|
|
96
139
|
"--session-id",
|
|
97
140
|
"privateclaw-session",
|
|
98
141
|
"--message",
|
|
99
|
-
|
|
142
|
+
]);
|
|
143
|
+
assert.match(prompt, /^hello\b/u);
|
|
144
|
+
assert.match(prompt, /PrivateClaw response contract:/u);
|
|
145
|
+
assert.match(prompt, /<privateclaw-response>/u);
|
|
146
|
+
assert.deepEqual(invokedArgs.slice(5), [
|
|
100
147
|
"--json",
|
|
101
148
|
"--agent",
|
|
102
149
|
"ops",
|
|
@@ -191,6 +238,135 @@ test("OpenClawAgentBridge converts side-effect-only slash commands into a friend
|
|
|
191
238
|
);
|
|
192
239
|
});
|
|
193
240
|
|
|
241
|
+
test("OpenClawAgentBridge recovers assistant text from the session log when agent stdout is incomplete", async (t) => {
|
|
242
|
+
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "privateclaw-openclaw-state-"));
|
|
243
|
+
const workspaceDir = path.join(stateDir, "workspace");
|
|
244
|
+
const sessionLogPath = path.join(
|
|
245
|
+
stateDir,
|
|
246
|
+
"agents",
|
|
247
|
+
"main",
|
|
248
|
+
"sessions",
|
|
249
|
+
"privateclaw-session.jsonl",
|
|
250
|
+
);
|
|
251
|
+
await fs.mkdir(workspaceDir, { recursive: true });
|
|
252
|
+
t.after(async () => {
|
|
253
|
+
await fs.rm(stateDir, { recursive: true, force: true });
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
const bridge = new OpenClawAgentBridge({
|
|
257
|
+
stateDir,
|
|
258
|
+
workspaceDir,
|
|
259
|
+
execFileImpl: (_file, _args, _options, callback) => {
|
|
260
|
+
void (async () => {
|
|
261
|
+
await fs.mkdir(path.dirname(sessionLogPath), { recursive: true });
|
|
262
|
+
await fs.writeFile(
|
|
263
|
+
sessionLogPath,
|
|
264
|
+
`${JSON.stringify({
|
|
265
|
+
type: "message",
|
|
266
|
+
message: {
|
|
267
|
+
role: "assistant",
|
|
268
|
+
content: [{ type: "text", text: "pixel.png" }],
|
|
269
|
+
isError: false,
|
|
270
|
+
},
|
|
271
|
+
})}\n`,
|
|
272
|
+
"utf8",
|
|
273
|
+
);
|
|
274
|
+
callback(
|
|
275
|
+
null,
|
|
276
|
+
JSON.stringify({
|
|
277
|
+
result: {
|
|
278
|
+
payloads: [],
|
|
279
|
+
},
|
|
280
|
+
}),
|
|
281
|
+
"",
|
|
282
|
+
);
|
|
283
|
+
})().catch((error) => {
|
|
284
|
+
callback(error instanceof Error ? error : new Error(String(error)), "", "");
|
|
285
|
+
});
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
const result = await bridge.handleUserMessage({
|
|
290
|
+
sessionId: "privateclaw-session",
|
|
291
|
+
message: "Reply with the exact filename.",
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
assert.equal(result, "pixel.png");
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
test("OpenClawAgentBridge recovers structured assistant text from the session log", async (t) => {
|
|
298
|
+
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "privateclaw-openclaw-state-"));
|
|
299
|
+
const workspaceDir = path.join(stateDir, "workspace");
|
|
300
|
+
const sessionLogPath = path.join(
|
|
301
|
+
stateDir,
|
|
302
|
+
"agents",
|
|
303
|
+
"main",
|
|
304
|
+
"sessions",
|
|
305
|
+
"privateclaw-session.jsonl",
|
|
306
|
+
);
|
|
307
|
+
await fs.mkdir(workspaceDir, { recursive: true });
|
|
308
|
+
t.after(async () => {
|
|
309
|
+
await fs.rm(stateDir, { recursive: true, force: true });
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
const bridge = new OpenClawAgentBridge({
|
|
313
|
+
stateDir,
|
|
314
|
+
workspaceDir,
|
|
315
|
+
execFileImpl: (_file, _args, _options, callback) => {
|
|
316
|
+
void (async () => {
|
|
317
|
+
await fs.mkdir(path.dirname(sessionLogPath), { recursive: true });
|
|
318
|
+
await fs.writeFile(
|
|
319
|
+
sessionLogPath,
|
|
320
|
+
`${JSON.stringify({
|
|
321
|
+
type: "message",
|
|
322
|
+
message: {
|
|
323
|
+
role: "assistant",
|
|
324
|
+
content: [
|
|
325
|
+
{
|
|
326
|
+
type: "text",
|
|
327
|
+
text: [
|
|
328
|
+
"Interim text that should be ignored.",
|
|
329
|
+
"<privateclaw-response>",
|
|
330
|
+
JSON.stringify({
|
|
331
|
+
version: 1,
|
|
332
|
+
messages: [{ text: "pixel.png" }],
|
|
333
|
+
data: { filename: "pixel.png" },
|
|
334
|
+
}),
|
|
335
|
+
"</privateclaw-response>",
|
|
336
|
+
].join("\n"),
|
|
337
|
+
},
|
|
338
|
+
],
|
|
339
|
+
isError: false,
|
|
340
|
+
},
|
|
341
|
+
})}\n`,
|
|
342
|
+
"utf8",
|
|
343
|
+
);
|
|
344
|
+
callback(
|
|
345
|
+
null,
|
|
346
|
+
JSON.stringify({
|
|
347
|
+
result: {
|
|
348
|
+
payloads: [],
|
|
349
|
+
},
|
|
350
|
+
}),
|
|
351
|
+
"",
|
|
352
|
+
);
|
|
353
|
+
})().catch((error) => {
|
|
354
|
+
callback(error instanceof Error ? error : new Error(String(error)), "", "");
|
|
355
|
+
});
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
const result = await bridge.handleUserMessage({
|
|
360
|
+
sessionId: "privateclaw-session",
|
|
361
|
+
message: "Reply with the exact filename.",
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
assert.deepEqual(result, {
|
|
365
|
+
messages: [{ text: "pixel.png" }],
|
|
366
|
+
data: { filename: "pixel.png" },
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
|
|
194
370
|
test("OpenClawAgentBridge bridges TTS audio artifacts from the session log", async (t) => {
|
|
195
371
|
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "privateclaw-openclaw-state-"));
|
|
196
372
|
const workspaceDir = path.join(stateDir, "workspace");
|
|
@@ -342,6 +518,8 @@ test("OpenClawAgentBridge stages image and PDF attachments with tool hints", asy
|
|
|
342
518
|
assert.match(prompt ?? "", /PrivateClaw staged the attachments into the OpenClaw workspace\./u);
|
|
343
519
|
assert.match(prompt ?? "", /Use the image tool with "privateclaw\/privateclaw-session\//u);
|
|
344
520
|
assert.match(prompt ?? "", /Use the pdf tool with "privateclaw\/privateclaw-session\//u);
|
|
521
|
+
assert.match(prompt ?? "", /PrivateClaw response contract:/u);
|
|
522
|
+
assert.match(prompt ?? "", /<privateclaw-response>/u);
|
|
345
523
|
assert.equal(result, "attachment-ok");
|
|
346
524
|
|
|
347
525
|
const stagedDir = path.join(workspaceDir, "privateclaw", "privateclaw-session");
|