@privateclaw/privateclaw 0.1.0 → 0.1.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/README.md +88 -6
- package/dist/bridges/openclaw-agent-bridge.d.ts +5 -0
- package/dist/bridges/openclaw-agent-bridge.js +228 -15
- package/dist/bridges/openclaw-agent-bridge.js.map +1 -1
- package/dist/cli.js +11 -19
- package/dist/cli.js.map +1 -1
- package/dist/compat/openclaw.d.ts +18 -1
- package/dist/compat/openclaw.js +3 -1
- package/dist/compat/openclaw.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/openclaw-plugin.js +90 -15
- package/dist/openclaw-plugin.js.map +1 -1
- package/dist/pair-session.d.ts +12 -0
- package/dist/pair-session.js +63 -0
- package/dist/pair-session.js.map +1 -0
- package/dist/provider.d.ts +22 -1
- package/dist/provider.js +613 -60
- package/dist/provider.js.map +1 -1
- package/dist/qr-options.d.ts +5 -0
- package/dist/qr-options.js +6 -0
- package/dist/qr-options.js.map +1 -0
- package/dist/relay-defaults.d.ts +1 -0
- package/dist/relay-defaults.js +2 -0
- package/dist/relay-defaults.js.map +1 -0
- package/dist/relay-provider-client.d.ts +2 -2
- package/dist/relay-provider-client.js +9 -3
- package/dist/relay-provider-client.js.map +1 -1
- package/dist/text.d.ts +22 -0
- package/dist/text.js +32 -0
- package/dist/text.js.map +1 -0
- package/dist/types.d.ts +14 -1
- package/openclaw.plugin.json +3 -2
- package/package.json +1 -1
- package/src/bridges/openclaw-agent-bridge.test.ts +141 -0
- package/src/bridges/openclaw-agent-bridge.ts +302 -16
- package/src/cli.ts +14 -22
- package/src/compat/openclaw.ts +30 -1
- package/src/index.ts +1 -0
- package/src/openclaw-plugin.test.ts +139 -0
- package/src/openclaw-plugin.ts +137 -15
- package/src/pair-session.ts +100 -0
- package/src/provider.test.ts +704 -1
- package/src/provider.ts +933 -60
- package/src/qr-options.ts +5 -0
- package/src/relay-defaults.ts +1 -0
- package/src/relay-provider-client.ts +13 -2
- package/src/text.ts +108 -0
- package/src/types.ts +15 -0
|
@@ -4,6 +4,7 @@ import { randomUUID } from "node:crypto";
|
|
|
4
4
|
import fs from "node:fs/promises";
|
|
5
5
|
import os from "node:os";
|
|
6
6
|
import path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
7
8
|
import { unzipSync } from "fflate";
|
|
8
9
|
import type { BridgeResponse, PrivateClawAgentBridge } from "../types.js";
|
|
9
10
|
|
|
@@ -22,6 +23,8 @@ type OpenClawAgentExecFile = (
|
|
|
22
23
|
|
|
23
24
|
interface OpenClawAgentPayload {
|
|
24
25
|
text?: string | null;
|
|
26
|
+
message?: string | null;
|
|
27
|
+
summary?: string | null;
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
interface OpenClawAgentJsonResult {
|
|
@@ -32,6 +35,38 @@ interface OpenClawAgentJsonResult {
|
|
|
32
35
|
};
|
|
33
36
|
}
|
|
34
37
|
|
|
38
|
+
interface OpenClawSessionLogCursor {
|
|
39
|
+
readonly path?: string;
|
|
40
|
+
readonly sizeBytes: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface OpenClawSessionLogEntry {
|
|
44
|
+
type?: string;
|
|
45
|
+
message?: {
|
|
46
|
+
role?: string;
|
|
47
|
+
toolName?: string;
|
|
48
|
+
content?: Array<{
|
|
49
|
+
type?: string;
|
|
50
|
+
text?: string | null;
|
|
51
|
+
}>;
|
|
52
|
+
details?: {
|
|
53
|
+
audioPath?: string | null;
|
|
54
|
+
};
|
|
55
|
+
isError?: boolean;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface NormalizedBridgeMessage {
|
|
60
|
+
readonly text: string;
|
|
61
|
+
readonly attachments?: PrivateClawAttachment[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
class OpenClawAgentNoDisplayPayloadError extends Error {
|
|
65
|
+
constructor(readonly parsed: OpenClawAgentJsonResult) {
|
|
66
|
+
super("OpenClaw agent bridge returned no displayable payloads.");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
35
70
|
interface StagedAttachment {
|
|
36
71
|
readonly name: string;
|
|
37
72
|
readonly effectiveMimeType: string;
|
|
@@ -51,6 +86,7 @@ export interface OpenClawAgentBridgeOptions {
|
|
|
51
86
|
local?: boolean;
|
|
52
87
|
thinking?: OpenClawThinkingLevel;
|
|
53
88
|
timeoutSeconds?: number;
|
|
89
|
+
stateDir?: string;
|
|
54
90
|
workspaceDir?: string;
|
|
55
91
|
execFileImpl?: OpenClawAgentExecFile;
|
|
56
92
|
}
|
|
@@ -77,11 +113,20 @@ const TEXT_LIKE_MIME_TYPES = new Set<string>([
|
|
|
77
113
|
]);
|
|
78
114
|
|
|
79
115
|
export function parseOpenClawAgentOutput(stdout: string): BridgeResponse {
|
|
80
|
-
const parsed =
|
|
116
|
+
const parsed = parseOpenClawAgentJson(stdout);
|
|
81
117
|
return parseOpenClawAgentResult(parsed);
|
|
82
118
|
}
|
|
83
119
|
|
|
120
|
+
function parseOpenClawAgentJson(stdout: string): OpenClawAgentJsonResult {
|
|
121
|
+
return JSON.parse(stdout) as OpenClawAgentJsonResult;
|
|
122
|
+
}
|
|
123
|
+
|
|
84
124
|
function parseOpenClawAgentResult(parsed: OpenClawAgentJsonResult): BridgeResponse {
|
|
125
|
+
const messages = extractDisplayMessages(parsed);
|
|
126
|
+
return toBridgeResponse(messages);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function extractDisplayMessages(parsed: OpenClawAgentJsonResult): NormalizedBridgeMessage[] {
|
|
85
130
|
if (parsed.status !== "ok") {
|
|
86
131
|
throw new Error(
|
|
87
132
|
`OpenClaw agent bridge returned status ${parsed.status ?? "unknown"}${parsed.summary ? ` (${parsed.summary})` : ""}.`,
|
|
@@ -91,35 +136,31 @@ function parseOpenClawAgentResult(parsed: OpenClawAgentJsonResult): BridgeRespon
|
|
|
91
136
|
const messages =
|
|
92
137
|
parsed.result?.payloads
|
|
93
138
|
?.flatMap((payload) =>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
139
|
+
[payload.text, payload.message, payload.summary].flatMap((candidate) =>
|
|
140
|
+
typeof candidate === "string" && candidate.trim() !== ""
|
|
141
|
+
? [{ text: candidate }]
|
|
142
|
+
: [],
|
|
143
|
+
),
|
|
97
144
|
) ?? [];
|
|
98
145
|
|
|
99
146
|
if (messages.length === 0) {
|
|
100
|
-
throw new
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (messages.length === 1) {
|
|
104
|
-
const [message] = messages;
|
|
105
|
-
if (!message) {
|
|
106
|
-
throw new Error("OpenClaw agent bridge returned no text payloads.");
|
|
107
|
-
}
|
|
108
|
-
return message.text;
|
|
147
|
+
throw new OpenClawAgentNoDisplayPayloadError(parsed);
|
|
109
148
|
}
|
|
110
149
|
|
|
111
|
-
return
|
|
150
|
+
return messages;
|
|
112
151
|
}
|
|
113
152
|
|
|
114
153
|
export class OpenClawAgentBridge implements PrivateClawAgentBridge {
|
|
115
154
|
private readonly executable: string;
|
|
116
155
|
private readonly execFileImpl: OpenClawAgentExecFile;
|
|
156
|
+
private readonly stateDir: string;
|
|
117
157
|
private readonly workspaceDir: string;
|
|
118
158
|
|
|
119
159
|
constructor(private readonly options: OpenClawAgentBridgeOptions = {}) {
|
|
120
160
|
this.executable = options.executable ?? "openclaw";
|
|
121
161
|
this.execFileImpl = options.execFileImpl ?? execFile;
|
|
122
|
-
this.
|
|
162
|
+
this.stateDir = options.stateDir ?? DEFAULT_STATE_DIR;
|
|
163
|
+
this.workspaceDir = options.workspaceDir ?? path.join(this.stateDir, "workspace");
|
|
123
164
|
}
|
|
124
165
|
|
|
125
166
|
async handleUserMessage(params: {
|
|
@@ -133,8 +174,112 @@ export class OpenClawAgentBridge implements PrivateClawAgentBridge {
|
|
|
133
174
|
params.attachments,
|
|
134
175
|
);
|
|
135
176
|
const args = this.buildArgs(params.sessionId, promptMessage);
|
|
177
|
+
const sessionLogCursor = await this.captureSessionLogCursor(params.sessionId);
|
|
136
178
|
const stdout = await this.execOpenClaw(args);
|
|
137
|
-
|
|
179
|
+
const parsed = parseOpenClawAgentJson(stdout);
|
|
180
|
+
const artifactMessages = await this.collectArtifactMessages(
|
|
181
|
+
params.sessionId,
|
|
182
|
+
sessionLogCursor,
|
|
183
|
+
);
|
|
184
|
+
try {
|
|
185
|
+
const response = parseOpenClawAgentResult(parsed);
|
|
186
|
+
return mergeBridgeResponses(response, artifactMessages);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
if (error instanceof OpenClawAgentNoDisplayPayloadError) {
|
|
189
|
+
if (artifactMessages.length > 0) {
|
|
190
|
+
return toBridgeResponse(artifactMessages);
|
|
191
|
+
}
|
|
192
|
+
return buildNoDisplayPayloadNotice(params.message, error.parsed);
|
|
193
|
+
}
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private async captureSessionLogCursor(sessionId: string): Promise<OpenClawSessionLogCursor> {
|
|
199
|
+
const sessionLogPath = await this.resolveSessionLogPath(sessionId);
|
|
200
|
+
if (!sessionLogPath) {
|
|
201
|
+
return { sizeBytes: 0 };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const stat = await fs.stat(sessionLogPath);
|
|
205
|
+
return {
|
|
206
|
+
path: sessionLogPath,
|
|
207
|
+
sizeBytes: stat.size,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private async collectArtifactMessages(
|
|
212
|
+
sessionId: string,
|
|
213
|
+
cursor: OpenClawSessionLogCursor,
|
|
214
|
+
): Promise<NormalizedBridgeMessage[]> {
|
|
215
|
+
const sessionLogPath = cursor.path ?? (await this.resolveSessionLogPath(sessionId));
|
|
216
|
+
if (!sessionLogPath) {
|
|
217
|
+
return [];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const sessionLogBuffer = await fs.readFile(sessionLogPath);
|
|
221
|
+
const deltaBuffer =
|
|
222
|
+
cursor.path === sessionLogPath
|
|
223
|
+
? sessionLogBuffer.subarray(Math.min(cursor.sizeBytes, sessionLogBuffer.length))
|
|
224
|
+
: sessionLogBuffer;
|
|
225
|
+
if (deltaBuffer.length === 0) {
|
|
226
|
+
return [];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const entries = deltaBuffer
|
|
230
|
+
.toString("utf8")
|
|
231
|
+
.split(/\r?\n/gu)
|
|
232
|
+
.map((line) => line.trim())
|
|
233
|
+
.filter((line) => line !== "")
|
|
234
|
+
.map((line) => JSON.parse(line) as OpenClawSessionLogEntry);
|
|
235
|
+
|
|
236
|
+
const seenPaths = new Set<string>();
|
|
237
|
+
const attachments: PrivateClawAttachment[] = [];
|
|
238
|
+
for (const entry of entries) {
|
|
239
|
+
for (const mediaPath of extractMediaPaths(entry)) {
|
|
240
|
+
const normalizedPath = normalizeMediaPath(mediaPath);
|
|
241
|
+
if (seenPaths.has(normalizedPath)) {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
attachments.push(await buildAttachmentFromMediaPath(normalizedPath));
|
|
245
|
+
seenPaths.add(normalizedPath);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (attachments.length === 0) {
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return [{ text: "", attachments }];
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
private async resolveSessionLogPath(sessionId: string): Promise<string | undefined> {
|
|
257
|
+
const agentsDir = path.join(this.stateDir, "agents");
|
|
258
|
+
try {
|
|
259
|
+
const agentEntries = await fs.readdir(agentsDir, { withFileTypes: true });
|
|
260
|
+
for (const entry of agentEntries) {
|
|
261
|
+
if (!entry.isDirectory()) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
const candidate = path.join(agentsDir, entry.name, "sessions", `${sessionId}.jsonl`);
|
|
265
|
+
try {
|
|
266
|
+
await fs.access(candidate);
|
|
267
|
+
return candidate;
|
|
268
|
+
} catch (error) {
|
|
269
|
+
if (isNodeError(error) && error.code === "ENOENT") {
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
throw error;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
} catch (error) {
|
|
276
|
+
if (isNodeError(error) && error.code === "ENOENT") {
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return undefined;
|
|
138
283
|
}
|
|
139
284
|
|
|
140
285
|
private async buildPromptMessage(
|
|
@@ -277,6 +422,128 @@ export class OpenClawAgentBridge implements PrivateClawAgentBridge {
|
|
|
277
422
|
}
|
|
278
423
|
}
|
|
279
424
|
|
|
425
|
+
function buildNoDisplayPayloadNotice(
|
|
426
|
+
message: string,
|
|
427
|
+
parsed: OpenClawAgentJsonResult,
|
|
428
|
+
): string {
|
|
429
|
+
const command = message.trim().match(/^\/[A-Za-z0-9_-]+/u)?.[0];
|
|
430
|
+
const summary = parsed.summary?.trim();
|
|
431
|
+
const extraSummary =
|
|
432
|
+
summary && summary !== "" && !/^(completed|ok)$/iu.test(summary)
|
|
433
|
+
? ` Summary: ${summary}.`
|
|
434
|
+
: "";
|
|
435
|
+
|
|
436
|
+
if (command === "/tts") {
|
|
437
|
+
return `OpenClaw completed ${command}, but it did not return a text reply through the agent bridge. If the command generated audio, the current PrivateClaw bridge does not surface that audio back into the chat yet.${extraSummary}`;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (command) {
|
|
441
|
+
return `OpenClaw completed ${command}, but it did not return a text reply through the agent bridge.${extraSummary}`;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return `OpenClaw completed the request, but it did not return a text reply through the agent bridge.${extraSummary}`;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function mergeBridgeResponses(
|
|
448
|
+
primary: BridgeResponse,
|
|
449
|
+
supplemental: NormalizedBridgeMessage[],
|
|
450
|
+
): BridgeResponse {
|
|
451
|
+
if (supplemental.length === 0) {
|
|
452
|
+
return primary;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return toBridgeResponse([
|
|
456
|
+
...normalizeBridgeResponse(primary),
|
|
457
|
+
...supplemental,
|
|
458
|
+
]);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function normalizeBridgeResponse(response: BridgeResponse): NormalizedBridgeMessage[] {
|
|
462
|
+
if (typeof response === "string") {
|
|
463
|
+
return [{ text: response }];
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return response.messages.map((message) =>
|
|
467
|
+
typeof message === "string"
|
|
468
|
+
? { text: message }
|
|
469
|
+
: {
|
|
470
|
+
text: message.text,
|
|
471
|
+
...(message.attachments ? { attachments: message.attachments } : {}),
|
|
472
|
+
},
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function toBridgeResponse(messages: NormalizedBridgeMessage[]): BridgeResponse {
|
|
477
|
+
if (messages.length === 1) {
|
|
478
|
+
const [message] = messages;
|
|
479
|
+
if (!message) {
|
|
480
|
+
throw new Error("Bridge response did not contain any messages.");
|
|
481
|
+
}
|
|
482
|
+
if (!message.attachments || message.attachments.length === 0) {
|
|
483
|
+
return message.text;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return {
|
|
488
|
+
messages: messages.map((message) =>
|
|
489
|
+
message.attachments && message.attachments.length > 0
|
|
490
|
+
? message
|
|
491
|
+
: { text: message.text },
|
|
492
|
+
),
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function extractMediaPaths(entry: OpenClawSessionLogEntry): string[] {
|
|
497
|
+
if (entry.type !== "message" || entry.message?.role !== "toolResult" || entry.message.isError) {
|
|
498
|
+
return [];
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
const mediaPaths = new Set<string>();
|
|
502
|
+
const detailsAudioPath = entry.message.details?.audioPath?.trim();
|
|
503
|
+
if (detailsAudioPath) {
|
|
504
|
+
mediaPaths.add(detailsAudioPath);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
for (const contentItem of entry.message.content ?? []) {
|
|
508
|
+
if (contentItem.type !== "text" || typeof contentItem.text !== "string") {
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
for (const match of contentItem.text.matchAll(/^MEDIA:(.+)$/gmu)) {
|
|
512
|
+
const mediaPath = match[1]?.trim();
|
|
513
|
+
if (mediaPath) {
|
|
514
|
+
mediaPaths.add(mediaPath);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return [...mediaPaths];
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
async function buildAttachmentFromMediaPath(mediaPath: string): Promise<PrivateClawAttachment> {
|
|
523
|
+
const filePath = normalizeMediaPath(mediaPath);
|
|
524
|
+
const fileBytes = await fs.readFile(filePath);
|
|
525
|
+
const fileName = path.basename(filePath) || `media-${randomUUID()}`;
|
|
526
|
+
return {
|
|
527
|
+
id: `bridge-attachment-${randomUUID()}`,
|
|
528
|
+
name: fileName,
|
|
529
|
+
mimeType: inferMimeTypeFromFileName(fileName) ?? GENERIC_BINARY_MIME,
|
|
530
|
+
sizeBytes: fileBytes.byteLength,
|
|
531
|
+
dataBase64: fileBytes.toString("base64"),
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function normalizeMediaPath(mediaPath: string): string {
|
|
536
|
+
const trimmed = mediaPath.trim();
|
|
537
|
+
if (trimmed.startsWith("file://")) {
|
|
538
|
+
return fileURLToPath(trimmed);
|
|
539
|
+
}
|
|
540
|
+
return path.isAbsolute(trimmed) ? trimmed : path.resolve(trimmed);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function isNodeError(error: unknown): error is NodeJS.ErrnoException {
|
|
544
|
+
return error instanceof Error && "code" in error;
|
|
545
|
+
}
|
|
546
|
+
|
|
280
547
|
function buildAttachmentInstruction(params: {
|
|
281
548
|
kind: StagedAttachment["kind"];
|
|
282
549
|
workspacePath: string;
|
|
@@ -341,6 +608,25 @@ function inferMimeTypeFromFileName(fileName: string): string | undefined {
|
|
|
341
608
|
return "image/webp";
|
|
342
609
|
case "svg":
|
|
343
610
|
return "image/svg+xml";
|
|
611
|
+
case "mp3":
|
|
612
|
+
return "audio/mpeg";
|
|
613
|
+
case "wav":
|
|
614
|
+
return "audio/wav";
|
|
615
|
+
case "m4a":
|
|
616
|
+
return "audio/mp4";
|
|
617
|
+
case "aac":
|
|
618
|
+
return "audio/aac";
|
|
619
|
+
case "ogg":
|
|
620
|
+
case "opus":
|
|
621
|
+
return "audio/ogg";
|
|
622
|
+
case "caf":
|
|
623
|
+
return "audio/x-caf";
|
|
624
|
+
case "mp4":
|
|
625
|
+
return "video/mp4";
|
|
626
|
+
case "mov":
|
|
627
|
+
return "video/quicktime";
|
|
628
|
+
case "webm":
|
|
629
|
+
return "video/webm";
|
|
344
630
|
case "pdf":
|
|
345
631
|
return "application/pdf";
|
|
346
632
|
case "doc":
|
package/src/cli.ts
CHANGED
|
@@ -4,7 +4,9 @@ import { EchoBridge } from "./bridges/echo-bridge.js";
|
|
|
4
4
|
import { OpenClawAgentBridge } from "./bridges/openclaw-agent-bridge.js";
|
|
5
5
|
import { OpenAICompatibleBridge } from "./bridges/openai-compatible-bridge.js";
|
|
6
6
|
import { WebhookBridge } from "./bridges/webhook-bridge.js";
|
|
7
|
-
import {
|
|
7
|
+
import { runPairSession } from "./pair-session.js";
|
|
8
|
+
import { DEFAULT_SESSION_TTL_MS, PrivateClawProvider } from "./provider.js";
|
|
9
|
+
import { DEFAULT_RELAY_BASE_URL } from "./relay-defaults.js";
|
|
8
10
|
import { resolveRelayEndpoints } from "./relay-endpoints.js";
|
|
9
11
|
|
|
10
12
|
function parsePositiveInteger(value: string | undefined, fallback: number): number {
|
|
@@ -32,7 +34,7 @@ function resolveChatCompletionsUrl(baseUrl: string): string {
|
|
|
32
34
|
return url.toString();
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
const relayBaseUrl = process.env.PRIVATECLAW_RELAY_BASE_URL?.trim() ||
|
|
37
|
+
const relayBaseUrl = process.env.PRIVATECLAW_RELAY_BASE_URL?.trim() || DEFAULT_RELAY_BASE_URL;
|
|
36
38
|
const { providerWsUrl, appWsUrl } = resolveRelayEndpoints(relayBaseUrl);
|
|
37
39
|
const webhookUrl = process.env.PRIVATECLAW_WEBHOOK_URL?.trim();
|
|
38
40
|
const webhookToken = process.env.PRIVATECLAW_WEBHOOK_TOKEN?.trim();
|
|
@@ -56,7 +58,10 @@ const openClawAgentLocal = parseBooleanFlag(process.env.PRIVATECLAW_OPENCLAW_AGE
|
|
|
56
58
|
const openClawAgentTimeoutSeconds = process.env.PRIVATECLAW_OPENCLAW_AGENT_TIMEOUT_SECONDS
|
|
57
59
|
? parsePositiveInteger(process.env.PRIVATECLAW_OPENCLAW_AGENT_TIMEOUT_SECONDS, 600)
|
|
58
60
|
: undefined;
|
|
59
|
-
const ttlMs = parsePositiveInteger(
|
|
61
|
+
const ttlMs = parsePositiveInteger(
|
|
62
|
+
process.env.PRIVATECLAW_SESSION_TTL_MS,
|
|
63
|
+
DEFAULT_SESSION_TTL_MS,
|
|
64
|
+
);
|
|
60
65
|
const providerLabel = process.env.PRIVATECLAW_PROVIDER_LABEL?.trim() || "PrivateClaw";
|
|
61
66
|
const welcomeMessage = process.env.PRIVATECLAW_WELCOME_MESSAGE?.trim();
|
|
62
67
|
|
|
@@ -93,23 +98,10 @@ const provider = new PrivateClawProvider({
|
|
|
93
98
|
},
|
|
94
99
|
});
|
|
95
100
|
|
|
96
|
-
await
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
console.log(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
async function shutdown(signal: string): Promise<void> {
|
|
104
|
-
console.log(`[privateclaw-provider] received ${signal}, shutting down`);
|
|
105
|
-
await provider.dispose();
|
|
106
|
-
process.exit(0);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
process.on("SIGINT", () => {
|
|
110
|
-
void shutdown("SIGINT");
|
|
111
|
-
});
|
|
112
|
-
process.on("SIGTERM", () => {
|
|
113
|
-
void shutdown("SIGTERM");
|
|
101
|
+
await runPairSession({
|
|
102
|
+
provider,
|
|
103
|
+
ttlMs,
|
|
104
|
+
writeLine: (line) => {
|
|
105
|
+
console.log(line);
|
|
106
|
+
},
|
|
114
107
|
});
|
|
115
|
-
process.stdin.resume();
|
package/src/compat/openclaw.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { DEFAULT_RELAY_BASE_URL } from "../relay-defaults.js";
|
|
2
|
+
|
|
1
3
|
export const privateClawConfigSchema = {
|
|
2
4
|
type: "object",
|
|
3
5
|
additionalProperties: false,
|
|
4
6
|
properties: {
|
|
5
7
|
relayBaseUrl: {
|
|
6
8
|
type: "string",
|
|
7
|
-
description:
|
|
9
|
+
description: `Relay base URL used to derive /ws/provider and /ws/app endpoints. Defaults to ${DEFAULT_RELAY_BASE_URL}.`,
|
|
10
|
+
default: DEFAULT_RELAY_BASE_URL,
|
|
8
11
|
},
|
|
9
12
|
sessionTtlMs: {
|
|
10
13
|
type: "number",
|
|
@@ -121,12 +124,38 @@ export interface OpenClawPluginServiceCompat {
|
|
|
121
124
|
}): Promise<void> | void;
|
|
122
125
|
}
|
|
123
126
|
|
|
127
|
+
export interface OpenClawCliCommandCompat {
|
|
128
|
+
command(name: string): OpenClawCliCommandCompat;
|
|
129
|
+
description(text: string): OpenClawCliCommandCompat;
|
|
130
|
+
option(
|
|
131
|
+
flags: string,
|
|
132
|
+
description?: string,
|
|
133
|
+
defaultValue?: string | boolean,
|
|
134
|
+
): OpenClawCliCommandCompat;
|
|
135
|
+
action(handler: (...args: unknown[]) => void | Promise<void>): OpenClawCliCommandCompat;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface OpenClawPluginCliContextCompat {
|
|
139
|
+
program: OpenClawCliCommandCompat;
|
|
140
|
+
config: unknown;
|
|
141
|
+
workspaceDir?: string;
|
|
142
|
+
logger: OpenClawPluginLoggerCompat;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type OpenClawPluginCliRegistrarCompat = (
|
|
146
|
+
ctx: OpenClawPluginCliContextCompat,
|
|
147
|
+
) => Promise<void> | void;
|
|
148
|
+
|
|
124
149
|
export interface OpenClawPluginApiCompat {
|
|
125
150
|
runtime: unknown;
|
|
126
151
|
pluginConfig?: Record<string, unknown>;
|
|
127
152
|
logger: OpenClawPluginLoggerCompat;
|
|
128
153
|
registerChannel?(params: { plugin: unknown }): void;
|
|
129
154
|
registerCommand(command: OpenClawPluginCommandDefinitionCompat): void;
|
|
155
|
+
registerCli?(
|
|
156
|
+
registrar: OpenClawPluginCliRegistrarCompat,
|
|
157
|
+
opts?: { commands?: string[] },
|
|
158
|
+
): void;
|
|
130
159
|
registerService?(service: OpenClawPluginServiceCompat): void;
|
|
131
160
|
}
|
|
132
161
|
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./compat/openclaw.js";
|
|
|
6
6
|
export { default } from "./openclaw-plugin.js";
|
|
7
7
|
export * from "./openclaw-plugin.js";
|
|
8
8
|
export * from "./provider.js";
|
|
9
|
+
export * from "./relay-defaults.js";
|
|
9
10
|
export * from "./relay-endpoints.js";
|
|
10
11
|
export * from "./relay-provider-client.js";
|
|
11
12
|
export * from "./types.js";
|