@privateclaw/privateclaw 0.1.16 → 0.1.18

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.
Files changed (42) hide show
  1. package/README.md +44 -1
  2. package/dist/audio-transcriber.d.ts +46 -0
  3. package/dist/audio-transcriber.js +433 -0
  4. package/dist/audio-transcriber.js.map +1 -0
  5. package/dist/bridges/openai-compatible-bridge.js +1 -0
  6. package/dist/bridges/openai-compatible-bridge.js.map +1 -1
  7. package/dist/bridges/openclaw-agent-bridge.d.ts +10 -2
  8. package/dist/bridges/openclaw-agent-bridge.js +632 -73
  9. package/dist/bridges/openclaw-agent-bridge.js.map +1 -1
  10. package/dist/cli.js +57 -6
  11. package/dist/cli.js.map +1 -1
  12. package/dist/openclaw-plugin.js +150 -51
  13. package/dist/openclaw-plugin.js.map +1 -1
  14. package/dist/pair-daemon.d.ts +2 -0
  15. package/dist/pair-daemon.js +2 -0
  16. package/dist/pair-daemon.js.map +1 -1
  17. package/dist/provider.d.ts +14 -1
  18. package/dist/provider.js +262 -20
  19. package/dist/provider.js.map +1 -1
  20. package/dist/session-control.d.ts +7 -0
  21. package/dist/session-control.js +122 -0
  22. package/dist/session-control.js.map +1 -1
  23. package/dist/text.d.ts +2 -0
  24. package/dist/text.js +3 -1
  25. package/dist/text.js.map +1 -1
  26. package/dist/types.d.ts +21 -2
  27. package/package.json +2 -2
  28. package/src/audio-transcriber.test.ts +299 -0
  29. package/src/audio-transcriber.ts +615 -0
  30. package/src/bridges/openai-compatible-bridge.ts +1 -0
  31. package/src/bridges/openclaw-agent-bridge.test.ts +644 -7
  32. package/src/bridges/openclaw-agent-bridge.ts +817 -81
  33. package/src/cli.ts +73 -5
  34. package/src/openclaw-plugin.test.ts +12 -2
  35. package/src/openclaw-plugin.ts +191 -54
  36. package/src/pair-daemon.ts +4 -0
  37. package/src/provider.test.ts +679 -0
  38. package/src/provider.ts +349 -28
  39. package/src/session-control.test.ts +80 -0
  40. package/src/session-control.ts +151 -0
  41. package/src/text.ts +12 -2
  42. package/src/types.ts +29 -1
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { PrivateClawAttachment, PrivateClawInvite, PrivateClawParticipant, PrivateClawSlashCommand } from "@privateclaw/protocol";
1
+ import type { PrivateClawAttachment, PrivateClawInvite, PrivateClawParticipant, PrivateClawSlashCommand, PrivateClawThinkingEntry, PrivateClawThinkingStatus } from "@privateclaw/protocol";
2
2
  export interface PrivateClawConversationTurn {
3
3
  messageId: string;
4
- role: "user" | "assistant" | "system";
4
+ role: "user" | "assistant" | "system" | "thinking";
5
5
  text: string;
6
6
  sentAt: string;
7
7
  bridgeText?: string;
@@ -10,6 +10,9 @@ export interface PrivateClawConversationTurn {
10
10
  replyTo?: string;
11
11
  severity?: "info" | "error";
12
12
  attachments?: PrivateClawAttachment[];
13
+ thinkingStatus?: PrivateClawThinkingStatus;
14
+ thinkingSummary?: string;
15
+ thinkingEntries?: PrivateClawThinkingEntry[];
13
16
  }
14
17
  export type BridgeMessage = string | {
15
18
  text: string;
@@ -25,13 +28,26 @@ export interface PrivateClawAudioTranscriptionRequest {
25
28
  requestId: string;
26
29
  attachments: ReadonlyArray<PrivateClawAttachment>;
27
30
  }
31
+ export interface PrivateClawAudioTranscriber {
32
+ transcribeAudioAttachments(params: PrivateClawAudioTranscriptionRequest): Promise<string>;
33
+ }
34
+ export interface PrivateClawVerboseController {
35
+ enabled: boolean;
36
+ }
37
+ export interface PrivateClawThinkingTraceSnapshot {
38
+ entries: ReadonlyArray<PrivateClawThinkingEntry>;
39
+ sentAt: string;
40
+ summary: string;
41
+ }
28
42
  export interface PrivateClawAgentBridge {
43
+ supportsThinkingTrace?: boolean;
29
44
  handleUserMessage(params: {
30
45
  sessionId: string;
31
46
  invite: PrivateClawInvite;
32
47
  message: string;
33
48
  attachments?: ReadonlyArray<PrivateClawAttachment>;
34
49
  history: ReadonlyArray<PrivateClawConversationTurn>;
50
+ onThinkingTrace?: (snapshot: PrivateClawThinkingTraceSnapshot) => void | Promise<void>;
35
51
  }): Promise<BridgeResponse>;
36
52
  transcribeAudioAttachments?(params: PrivateClawAudioTranscriptionRequest): Promise<string>;
37
53
  }
@@ -39,15 +55,18 @@ export interface PrivateClawProviderOptions {
39
55
  providerWsUrl: string;
40
56
  appWsUrl: string;
41
57
  bridge: PrivateClawAgentBridge;
58
+ audioTranscriber?: PrivateClawAudioTranscriber;
42
59
  providerId?: string;
43
60
  defaultTtlMs?: number;
44
61
  providerLabel?: string;
45
62
  welcomeMessage?: string;
46
63
  commandsProvider?: () => Promise<PrivateClawSlashCommand[]>;
64
+ verboseController?: PrivateClawVerboseController;
47
65
  onLog?: (message: string) => void;
48
66
  }
49
67
  export interface ProviderParticipantState extends PrivateClawParticipant {
50
68
  lastSeenAt: string;
69
+ supportsThinkingTrace?: boolean;
51
70
  }
52
71
  export interface PrivateClawManagedSession {
53
72
  sessionId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privateclaw/privateclaw",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "PrivateClaw provider runtime and OpenClaw-compatible plugin adapter. iOS public beta: https://testflight.apple.com/join/XvgJ9c33 ; Android closed alpha requires joining https://groups.google.com/g/gg-studio-ai-products before installing https://play.google.com/store/apps/details?id=gg.ai.privateclaw",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -46,7 +46,7 @@
46
46
  "test": "node --import tsx --test src/*.test.ts src/**/*.test.ts"
47
47
  },
48
48
  "dependencies": {
49
- "@privateclaw/protocol": "^0.1.2",
49
+ "@privateclaw/protocol": "^0.1.3",
50
50
  "fflate": "^0.8.2",
51
51
  "qrcode": "^1.5.4",
52
52
  "ws": "^8.18.3"
@@ -0,0 +1,299 @@
1
+ import assert from "node:assert/strict";
2
+ import { createServer } from "node:http";
3
+ import { once } from "node:events";
4
+ import { writeFile } from "node:fs/promises";
5
+ import path from "node:path";
6
+ import test from "node:test";
7
+ import {
8
+ buildPreferredAudioTranscriber,
9
+ createOpenAICompatibleAudioTranscriber,
10
+ resolvePrivateClawSttConfig,
11
+ } from "./audio-transcriber.js";
12
+
13
+ test("resolvePrivateClawSttConfig reads the default OpenClaw audio model config", () => {
14
+ const resolved = resolvePrivateClawSttConfig({
15
+ rootConfig: {
16
+ tools: {
17
+ media: {
18
+ audio: {
19
+ models: [{ provider: "openai", model: "gpt-4o-mini-transcribe" }],
20
+ },
21
+ },
22
+ },
23
+ models: {
24
+ providers: {
25
+ openai: {
26
+ baseUrl: "https://api.example.com/v1/",
27
+ apiKey: "test-key",
28
+ },
29
+ },
30
+ },
31
+ },
32
+ });
33
+
34
+ assert.deepEqual(resolved, {
35
+ baseUrl: "https://api.example.com/v1",
36
+ apiKey: "test-key",
37
+ headers: {
38
+ Authorization: "Bearer test-key",
39
+ },
40
+ model: "gpt-4o-mini-transcribe",
41
+ });
42
+ });
43
+
44
+ test("resolvePrivateClawSttConfig accepts inline audio-model headers", () => {
45
+ const resolved = resolvePrivateClawSttConfig({
46
+ rootConfig: {
47
+ tools: {
48
+ media: {
49
+ audio: {
50
+ models: [
51
+ {
52
+ baseUrl: "http://127.0.0.1:8090/",
53
+ model: "whisper-1",
54
+ headers: {
55
+ Authorization: "Bearer local",
56
+ "X-PrivateClaw-Test": "enabled",
57
+ },
58
+ },
59
+ ],
60
+ },
61
+ },
62
+ },
63
+ },
64
+ });
65
+
66
+ assert.deepEqual(resolved, {
67
+ baseUrl: "http://127.0.0.1:8090",
68
+ model: "whisper-1",
69
+ headers: {
70
+ Authorization: "Bearer local",
71
+ "X-PrivateClaw-Test": "enabled",
72
+ },
73
+ });
74
+ });
75
+
76
+ test("OpenAI-compatible audio transcriber posts audio attachments to /audio/transcriptions", async (t) => {
77
+ const requests: Array<{
78
+ url: string;
79
+ authorization: string | undefined;
80
+ privateClawTestHeader: string | undefined;
81
+ contentType: string | undefined;
82
+ body: string;
83
+ }> = [];
84
+ const server = createServer((request, response) => {
85
+ void (async () => {
86
+ const bodyChunks: Buffer[] = [];
87
+ for await (const chunk of request) {
88
+ bodyChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
89
+ }
90
+ requests.push({
91
+ url: request.url ?? "",
92
+ authorization: request.headers.authorization,
93
+ privateClawTestHeader: request.headers["x-privateclaw-test"] as
94
+ | string
95
+ | undefined,
96
+ contentType: request.headers["content-type"],
97
+ body: Buffer.concat(bodyChunks).toString("utf8"),
98
+ });
99
+ response.statusCode = 200;
100
+ response.setHeader("content-type", "application/json; charset=utf-8");
101
+ response.end(JSON.stringify({ text: `transcript-${requests.length}` }));
102
+ })().catch((error) => {
103
+ response.statusCode = 500;
104
+ response.end(String(error));
105
+ });
106
+ });
107
+ server.listen(0, "127.0.0.1");
108
+ await once(server, "listening");
109
+ const address = server.address();
110
+ if (!address || typeof address === "string") {
111
+ throw new Error("Expected an AddressInfo from the test server.");
112
+ }
113
+ t.after(() => {
114
+ server.close();
115
+ });
116
+
117
+ const transcriber = createOpenAICompatibleAudioTranscriber({
118
+ baseUrl: `http://127.0.0.1:${address.port}`,
119
+ apiKey: "audio-key",
120
+ headers: {
121
+ Authorization: "Bearer audio-key",
122
+ "X-PrivateClaw-Test": "enabled",
123
+ },
124
+ model: "whisper-1",
125
+ });
126
+ const transcript = await transcriber.transcribeAudioAttachments({
127
+ sessionId: "privateclaw-session",
128
+ requestId: "voice-request",
129
+ attachments: [
130
+ {
131
+ id: "voice-1",
132
+ name: "voice-a.m4a",
133
+ mimeType: "audio/mp4",
134
+ sizeBytes: 4,
135
+ dataBase64: Buffer.from("AAAA").toString("base64"),
136
+ },
137
+ {
138
+ id: "voice-2",
139
+ name: "voice-b.mp3",
140
+ mimeType: "audio/mpeg",
141
+ sizeBytes: 4,
142
+ dataBase64: Buffer.from("BBBB").toString("base64"),
143
+ },
144
+ ],
145
+ });
146
+
147
+ assert.equal(transcript, "transcript-1\n\ntranscript-2");
148
+ assert.equal(requests.length, 2);
149
+ assert.equal(requests[0]?.url, "/audio/transcriptions");
150
+ assert.equal(requests[0]?.authorization, "Bearer audio-key");
151
+ assert.equal(requests[0]?.privateClawTestHeader, "enabled");
152
+ assert.match(requests[0]?.contentType ?? "", /^multipart\/form-data; boundary=/u);
153
+ assert.match(requests[0]?.body ?? "", /name="model"\r\n\r\nwhisper-1/u);
154
+ assert.match(requests[0]?.body ?? "", /filename="voice-a\.m4a"/u);
155
+ assert.match(requests[1]?.body ?? "", /filename="voice-b\.mp3"/u);
156
+ });
157
+
158
+ test("buildPreferredAudioTranscriber prefers whisper CLI over configured direct STT", async (t) => {
159
+ let directRequestCount = 0;
160
+ const server = createServer((request, response) => {
161
+ void (async () => {
162
+ directRequestCount += 1;
163
+ response.statusCode = 200;
164
+ response.setHeader("content-type", "application/json; charset=utf-8");
165
+ response.end(JSON.stringify({ text: "direct transcript" }));
166
+ })().catch((error) => {
167
+ response.statusCode = 500;
168
+ response.end(String(error));
169
+ });
170
+ });
171
+ server.listen(0, "127.0.0.1");
172
+ await once(server, "listening");
173
+ const address = server.address();
174
+ if (!address || typeof address === "string") {
175
+ throw new Error("Expected an AddressInfo from the whisper-preference test server.");
176
+ }
177
+ t.after(() => {
178
+ server.close();
179
+ });
180
+
181
+ const transcriber = buildPreferredAudioTranscriber({
182
+ env: {
183
+ PRIVATECLAW_STT_BASE_URL: `http://127.0.0.1:${address.port}`,
184
+ PRIVATECLAW_STT_MODEL: "whisper-1",
185
+ },
186
+ whisperSpawnSyncImpl: (() =>
187
+ ({
188
+ pid: 123,
189
+ output: [null, "usage: whisper\n", ""],
190
+ stdout: "usage: whisper\n",
191
+ stderr: "",
192
+ status: 0,
193
+ signal: null,
194
+ }) as ReturnType<typeof import("node:child_process").spawnSync>),
195
+ whisperExecFileImpl: (_file, args, _options, callback) => {
196
+ const inputPath = args[0];
197
+ const outputDirIndex = args.indexOf("--output_dir");
198
+ const outputDir = outputDirIndex >= 0 ? args[outputDirIndex + 1] : undefined;
199
+ if (!inputPath || !outputDir) {
200
+ callback(new Error("Missing whisper CLI arguments."));
201
+ return;
202
+ }
203
+ const outputPath = path.join(
204
+ outputDir,
205
+ `${path.basename(inputPath, path.extname(inputPath))}.json`,
206
+ );
207
+ void writeFile(outputPath, JSON.stringify({ text: "whisper transcript" }), "utf8")
208
+ .then(() => {
209
+ callback(null, "", "");
210
+ })
211
+ .catch((error) => {
212
+ callback(error as Error, "", "");
213
+ });
214
+ },
215
+ });
216
+ assert.ok(transcriber);
217
+
218
+ const transcript = await transcriber.transcribeAudioAttachments({
219
+ sessionId: "privateclaw-session",
220
+ requestId: "voice-request-whisper",
221
+ attachments: [
222
+ {
223
+ id: "voice-1",
224
+ name: "voice-a.m4a",
225
+ mimeType: "audio/mp4",
226
+ sizeBytes: 4,
227
+ dataBase64: Buffer.from("AAAA").toString("base64"),
228
+ },
229
+ ],
230
+ });
231
+
232
+ assert.equal(transcript, "whisper transcript");
233
+ assert.equal(directRequestCount, 0);
234
+ });
235
+
236
+ test("buildPreferredAudioTranscriber falls back from whisper CLI to configured direct STT", async (t) => {
237
+ let directRequestCount = 0;
238
+ const server = createServer((request, response) => {
239
+ void (async () => {
240
+ const bodyChunks: Buffer[] = [];
241
+ for await (const chunk of request) {
242
+ bodyChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
243
+ }
244
+ directRequestCount += 1;
245
+ response.statusCode = 200;
246
+ response.setHeader("content-type", "application/json; charset=utf-8");
247
+ response.end(JSON.stringify({ text: "direct transcript" }));
248
+ })().catch((error) => {
249
+ response.statusCode = 500;
250
+ response.end(String(error));
251
+ });
252
+ });
253
+ server.listen(0, "127.0.0.1");
254
+ await once(server, "listening");
255
+ const address = server.address();
256
+ if (!address || typeof address === "string") {
257
+ throw new Error("Expected an AddressInfo from the whisper-fallback test server.");
258
+ }
259
+ t.after(() => {
260
+ server.close();
261
+ });
262
+
263
+ const transcriber = buildPreferredAudioTranscriber({
264
+ env: {
265
+ PRIVATECLAW_STT_BASE_URL: `http://127.0.0.1:${address.port}`,
266
+ PRIVATECLAW_STT_MODEL: "whisper-1",
267
+ },
268
+ whisperSpawnSyncImpl: (() =>
269
+ ({
270
+ pid: 123,
271
+ output: [null, "usage: whisper\n", ""],
272
+ stdout: "usage: whisper\n",
273
+ stderr: "",
274
+ status: 0,
275
+ signal: null,
276
+ }) as ReturnType<typeof import("node:child_process").spawnSync>),
277
+ whisperExecFileImpl: (_file, _args, _options, callback) => {
278
+ callback(new Error("whisper crashed"), "", "whisper crashed");
279
+ },
280
+ });
281
+ assert.ok(transcriber);
282
+
283
+ const transcript = await transcriber.transcribeAudioAttachments({
284
+ sessionId: "privateclaw-session",
285
+ requestId: "voice-request-fallback",
286
+ attachments: [
287
+ {
288
+ id: "voice-1",
289
+ name: "voice-a.m4a",
290
+ mimeType: "audio/mp4",
291
+ sizeBytes: 4,
292
+ dataBase64: Buffer.from("AAAA").toString("base64"),
293
+ },
294
+ ],
295
+ });
296
+
297
+ assert.equal(transcript, "direct transcript");
298
+ assert.equal(directRequestCount, 1);
299
+ });