@privateclaw/privateclaw 0.1.31 → 0.1.33
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 +14 -9
- package/dist/audio-transcriber.js +98 -20
- package/dist/audio-transcriber.js.map +1 -1
- package/dist/bridges/openclaw-agent-bridge.d.ts +7 -0
- package/dist/bridges/openclaw-agent-bridge.js +71 -25
- package/dist/bridges/openclaw-agent-bridge.js.map +1 -1
- package/dist/channel.d.ts +14 -0
- package/dist/channel.js +103 -0
- package/dist/channel.js.map +1 -0
- package/dist/cli.js +16 -2
- package/dist/cli.js.map +1 -1
- package/dist/compat/openclaw.d.ts +231 -2
- package/dist/compat/openclaw.js +1 -0
- package/dist/compat/openclaw.js.map +1 -1
- package/dist/openclaw-plugin.js +199 -4
- package/dist/openclaw-plugin.js.map +1 -1
- package/dist/pair-session.d.ts +32 -0
- package/dist/pair-session.js +115 -41
- package/dist/pair-session.js.map +1 -1
- package/dist/provider.d.ts +4 -1
- package/dist/provider.js +109 -4
- package/dist/provider.js.map +1 -1
- package/dist/session-control.d.ts +15 -1
- package/dist/session-control.js +184 -5
- package/dist/session-control.js.map +1 -1
- package/dist/types.d.ts +20 -1
- package/openclaw.plugin.json +3 -2
- package/package.json +1 -1
- package/src/audio-transcriber.test.ts +152 -0
- package/src/audio-transcriber.ts +116 -23
- package/src/bridges/openclaw-agent-bridge.test.ts +154 -0
- package/src/bridges/openclaw-agent-bridge.ts +97 -27
- package/src/channel.ts +130 -0
- package/src/cli.ts +17 -1
- package/src/compat/openclaw.ts +282 -2
- package/src/openclaw-plugin.test.ts +392 -3
- package/src/openclaw-plugin.ts +262 -3
- package/src/pair-session.test.ts +119 -0
- package/src/pair-session.ts +144 -47
- package/src/provider.test.ts +266 -0
- package/src/provider.ts +133 -4
- package/src/session-control.test.ts +87 -0
- package/src/session-control.ts +252 -5
- package/src/types.ts +23 -0
|
@@ -62,6 +62,7 @@ export declare const privateClawConfigSchema: {
|
|
|
62
62
|
readonly openclawAgentChannel: {
|
|
63
63
|
readonly type: "string";
|
|
64
64
|
readonly description: "Optional OpenClaw channel id forwarded to `openclaw agent`.";
|
|
65
|
+
readonly default: "privateclaw";
|
|
65
66
|
};
|
|
66
67
|
readonly openclawAgentLocal: {
|
|
67
68
|
readonly type: "boolean";
|
|
@@ -83,9 +84,11 @@ export interface ReplyPayloadCompat {
|
|
|
83
84
|
text?: string;
|
|
84
85
|
mediaUrl?: string;
|
|
85
86
|
mediaUrls?: string[];
|
|
87
|
+
replyToId?: string | null;
|
|
86
88
|
isError?: boolean;
|
|
87
89
|
channelData?: Record<string, unknown>;
|
|
88
90
|
}
|
|
91
|
+
export type OpenClawConfigCompat = Record<string, unknown>;
|
|
89
92
|
export interface OpenClawPluginCommandContextCompat {
|
|
90
93
|
senderId?: string;
|
|
91
94
|
channel: string;
|
|
@@ -115,6 +118,232 @@ export interface OpenClawPluginLoggerCompat {
|
|
|
115
118
|
warn(message: string): void;
|
|
116
119
|
error(message: string): void;
|
|
117
120
|
}
|
|
121
|
+
export interface OpenClawMsgContextCompat {
|
|
122
|
+
Body?: string;
|
|
123
|
+
BodyForAgent?: string;
|
|
124
|
+
RawBody?: string;
|
|
125
|
+
CommandBody?: string;
|
|
126
|
+
BodyForCommands?: string;
|
|
127
|
+
From?: string;
|
|
128
|
+
To?: string;
|
|
129
|
+
SessionKey?: string;
|
|
130
|
+
ParentSessionKey?: string;
|
|
131
|
+
AccountId?: string;
|
|
132
|
+
MessageSid?: string;
|
|
133
|
+
MessageSidFull?: string;
|
|
134
|
+
ReplyToId?: string | null;
|
|
135
|
+
Timestamp?: number;
|
|
136
|
+
ChatType?: string;
|
|
137
|
+
ConversationLabel?: string;
|
|
138
|
+
SenderName?: string;
|
|
139
|
+
SenderId?: string;
|
|
140
|
+
Provider?: string;
|
|
141
|
+
Surface?: string;
|
|
142
|
+
CommandAuthorized?: boolean;
|
|
143
|
+
MessageThreadId?: string | number;
|
|
144
|
+
NativeChannelId?: string;
|
|
145
|
+
OriginatingChannel?: string;
|
|
146
|
+
OriginatingTo?: string;
|
|
147
|
+
ExplicitDeliverRoute?: boolean;
|
|
148
|
+
}
|
|
149
|
+
export interface OpenClawFinalizedMsgContextCompat extends Omit<OpenClawMsgContextCompat, "CommandAuthorized"> {
|
|
150
|
+
CommandAuthorized: boolean;
|
|
151
|
+
}
|
|
152
|
+
export interface OpenClawResolvedAgentRouteCompat {
|
|
153
|
+
agentId: string;
|
|
154
|
+
sessionKey: string;
|
|
155
|
+
mainSessionKey: string;
|
|
156
|
+
lastRoutePolicy?: "main" | "current" | string;
|
|
157
|
+
}
|
|
158
|
+
export interface OpenClawReplyDispatchInfoCompat {
|
|
159
|
+
kind: "tool" | "block" | "final";
|
|
160
|
+
}
|
|
161
|
+
export interface OpenClawReplyDispatcherOptionsCompat {
|
|
162
|
+
deliver(payload: ReplyPayloadCompat, info: OpenClawReplyDispatchInfoCompat): Promise<void>;
|
|
163
|
+
onError?(error: unknown, info: OpenClawReplyDispatchInfoCompat): void;
|
|
164
|
+
onSkip?(payload: ReplyPayloadCompat, info: OpenClawReplyDispatchInfoCompat & {
|
|
165
|
+
reason: string;
|
|
166
|
+
}): void;
|
|
167
|
+
}
|
|
168
|
+
export interface OpenClawPluginRuntimeChannelCompat {
|
|
169
|
+
reply: {
|
|
170
|
+
finalizeInboundContext<T extends Record<string, unknown>>(ctx: T, opts?: {
|
|
171
|
+
forceBodyForAgent?: boolean;
|
|
172
|
+
forceBodyForCommands?: boolean;
|
|
173
|
+
forceChatType?: boolean;
|
|
174
|
+
forceConversationLabel?: boolean;
|
|
175
|
+
}): T & OpenClawFinalizedMsgContextCompat;
|
|
176
|
+
dispatchReplyWithBufferedBlockDispatcher(params: {
|
|
177
|
+
ctx: OpenClawMsgContextCompat | OpenClawFinalizedMsgContextCompat;
|
|
178
|
+
cfg: OpenClawConfigCompat;
|
|
179
|
+
dispatcherOptions: OpenClawReplyDispatcherOptionsCompat;
|
|
180
|
+
replyOptions?: Record<string, unknown>;
|
|
181
|
+
}): Promise<unknown>;
|
|
182
|
+
};
|
|
183
|
+
routing: {
|
|
184
|
+
resolveAgentRoute(params: {
|
|
185
|
+
cfg: OpenClawConfigCompat;
|
|
186
|
+
ctx: OpenClawMsgContextCompat | OpenClawFinalizedMsgContextCompat;
|
|
187
|
+
agentId?: string;
|
|
188
|
+
}): OpenClawResolvedAgentRouteCompat;
|
|
189
|
+
};
|
|
190
|
+
session: {
|
|
191
|
+
resolveStorePath(store?: string, opts?: {
|
|
192
|
+
agentId?: string;
|
|
193
|
+
env?: NodeJS.ProcessEnv;
|
|
194
|
+
}): string;
|
|
195
|
+
recordInboundSession(params: {
|
|
196
|
+
storePath: string;
|
|
197
|
+
sessionKey: string;
|
|
198
|
+
ctx: OpenClawMsgContextCompat | OpenClawFinalizedMsgContextCompat;
|
|
199
|
+
groupResolution?: unknown;
|
|
200
|
+
createIfMissing?: boolean;
|
|
201
|
+
updateLastRoute?: {
|
|
202
|
+
sessionKey: string;
|
|
203
|
+
channel?: string;
|
|
204
|
+
to: string;
|
|
205
|
+
accountId?: string;
|
|
206
|
+
threadId?: string | number;
|
|
207
|
+
};
|
|
208
|
+
onRecordError(error: unknown): void;
|
|
209
|
+
}): Promise<void> | void;
|
|
210
|
+
updateLastRoute?(params: {
|
|
211
|
+
storePath: string;
|
|
212
|
+
sessionKey: string;
|
|
213
|
+
channel?: string;
|
|
214
|
+
to?: string;
|
|
215
|
+
accountId?: string;
|
|
216
|
+
threadId?: string | number;
|
|
217
|
+
deliveryContext?: {
|
|
218
|
+
channel?: string;
|
|
219
|
+
to?: string;
|
|
220
|
+
accountId?: string;
|
|
221
|
+
threadId?: string | number;
|
|
222
|
+
};
|
|
223
|
+
ctx?: OpenClawMsgContextCompat | OpenClawFinalizedMsgContextCompat;
|
|
224
|
+
groupResolution?: unknown;
|
|
225
|
+
}): Promise<void> | void;
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
export interface OpenClawPluginRuntimeCompat {
|
|
229
|
+
channel?: OpenClawPluginRuntimeChannelCompat;
|
|
230
|
+
}
|
|
231
|
+
export interface OpenClawChannelMetaCompat {
|
|
232
|
+
id: string;
|
|
233
|
+
label: string;
|
|
234
|
+
selectionLabel: string;
|
|
235
|
+
docsPath: string;
|
|
236
|
+
blurb: string;
|
|
237
|
+
docsLabel?: string;
|
|
238
|
+
order?: number;
|
|
239
|
+
aliases?: string[];
|
|
240
|
+
selectionDocsPrefix?: string;
|
|
241
|
+
selectionDocsOmitLabel?: boolean;
|
|
242
|
+
selectionExtras?: string[];
|
|
243
|
+
detailLabel?: string;
|
|
244
|
+
systemImage?: string;
|
|
245
|
+
showConfigured?: boolean;
|
|
246
|
+
quickstartAllowFrom?: boolean;
|
|
247
|
+
forceAccountBinding?: boolean;
|
|
248
|
+
preferSessionLookupForAnnounceTarget?: boolean;
|
|
249
|
+
preferOver?: string[];
|
|
250
|
+
}
|
|
251
|
+
export interface OpenClawChannelCapabilitiesCompat {
|
|
252
|
+
chatTypes: Array<"direct" | "group" | "thread">;
|
|
253
|
+
polls?: boolean;
|
|
254
|
+
reactions?: boolean;
|
|
255
|
+
edit?: boolean;
|
|
256
|
+
unsend?: boolean;
|
|
257
|
+
reply?: boolean;
|
|
258
|
+
effects?: boolean;
|
|
259
|
+
groupManagement?: boolean;
|
|
260
|
+
threads?: boolean;
|
|
261
|
+
media?: boolean;
|
|
262
|
+
nativeCommands?: boolean;
|
|
263
|
+
blockStreaming?: boolean;
|
|
264
|
+
}
|
|
265
|
+
export interface OpenClawChannelAccountSnapshotCompat {
|
|
266
|
+
accountId: string;
|
|
267
|
+
name?: string;
|
|
268
|
+
enabled?: boolean;
|
|
269
|
+
configured?: boolean;
|
|
270
|
+
linked?: boolean;
|
|
271
|
+
running?: boolean;
|
|
272
|
+
connected?: boolean;
|
|
273
|
+
lastError?: string | null;
|
|
274
|
+
lastInboundAt?: number | null;
|
|
275
|
+
lastOutboundAt?: number | null;
|
|
276
|
+
}
|
|
277
|
+
export interface OpenClawChannelConfigAdapterCompat<ResolvedAccount = unknown> {
|
|
278
|
+
listAccountIds(cfg: OpenClawConfigCompat): string[];
|
|
279
|
+
resolveAccount(cfg: OpenClawConfigCompat, accountId?: string | null): ResolvedAccount;
|
|
280
|
+
inspectAccount?(cfg: OpenClawConfigCompat, accountId?: string | null): unknown;
|
|
281
|
+
defaultAccountId?(cfg: OpenClawConfigCompat): string;
|
|
282
|
+
isEnabled?(account: ResolvedAccount, cfg: OpenClawConfigCompat): boolean;
|
|
283
|
+
isConfigured?(account: ResolvedAccount, cfg: OpenClawConfigCompat): boolean | Promise<boolean>;
|
|
284
|
+
describeAccount?(account: ResolvedAccount, cfg: OpenClawConfigCompat): OpenClawChannelAccountSnapshotCompat;
|
|
285
|
+
resolveAllowFrom?(params: {
|
|
286
|
+
cfg: OpenClawConfigCompat;
|
|
287
|
+
accountId?: string | null;
|
|
288
|
+
}): Array<string | number> | undefined;
|
|
289
|
+
resolveDefaultTo?(params: {
|
|
290
|
+
cfg: OpenClawConfigCompat;
|
|
291
|
+
accountId?: string | null;
|
|
292
|
+
}): string | undefined;
|
|
293
|
+
}
|
|
294
|
+
export interface OpenClawOutboundDeliveryResultCompat {
|
|
295
|
+
channel: string;
|
|
296
|
+
messageId: string;
|
|
297
|
+
chatId?: string;
|
|
298
|
+
channelId?: string;
|
|
299
|
+
roomId?: string;
|
|
300
|
+
conversationId?: string;
|
|
301
|
+
timestamp?: number;
|
|
302
|
+
toJid?: string;
|
|
303
|
+
pollId?: string;
|
|
304
|
+
meta?: Record<string, unknown>;
|
|
305
|
+
}
|
|
306
|
+
export interface OpenClawChannelOutboundContextCompat {
|
|
307
|
+
cfg: OpenClawConfigCompat;
|
|
308
|
+
to: string;
|
|
309
|
+
text: string;
|
|
310
|
+
mediaUrl?: string;
|
|
311
|
+
mediaLocalRoots?: readonly string[];
|
|
312
|
+
gifPlayback?: boolean;
|
|
313
|
+
replyToId?: string | null;
|
|
314
|
+
threadId?: string | number | null;
|
|
315
|
+
accountId?: string | null;
|
|
316
|
+
identity?: unknown;
|
|
317
|
+
deps?: unknown;
|
|
318
|
+
silent?: boolean;
|
|
319
|
+
}
|
|
320
|
+
export interface OpenClawChannelOutboundPayloadContextCompat extends OpenClawChannelOutboundContextCompat {
|
|
321
|
+
payload: ReplyPayloadCompat;
|
|
322
|
+
}
|
|
323
|
+
export interface OpenClawChannelOutboundAdapterCompat {
|
|
324
|
+
deliveryMode: "direct" | "gateway" | "hybrid";
|
|
325
|
+
sendPayload?(ctx: OpenClawChannelOutboundPayloadContextCompat): Promise<OpenClawOutboundDeliveryResultCompat>;
|
|
326
|
+
sendText?(ctx: OpenClawChannelOutboundContextCompat): Promise<OpenClawOutboundDeliveryResultCompat>;
|
|
327
|
+
sendMedia?(ctx: OpenClawChannelOutboundContextCompat): Promise<OpenClawOutboundDeliveryResultCompat>;
|
|
328
|
+
}
|
|
329
|
+
export interface OpenClawChannelThreadingAdapterCompat {
|
|
330
|
+
resolveReplyToMode?(params: {
|
|
331
|
+
cfg: OpenClawConfigCompat;
|
|
332
|
+
accountId?: string | null;
|
|
333
|
+
chatType?: string | null;
|
|
334
|
+
}): "off" | "first" | "all";
|
|
335
|
+
}
|
|
336
|
+
export interface OpenClawChannelPluginCompat<ResolvedAccount = unknown> {
|
|
337
|
+
id: string;
|
|
338
|
+
meta: OpenClawChannelMetaCompat;
|
|
339
|
+
capabilities: OpenClawChannelCapabilitiesCompat;
|
|
340
|
+
config: OpenClawChannelConfigAdapterCompat<ResolvedAccount>;
|
|
341
|
+
outbound?: OpenClawChannelOutboundAdapterCompat;
|
|
342
|
+
threading?: OpenClawChannelThreadingAdapterCompat;
|
|
343
|
+
commands?: {
|
|
344
|
+
skipWhenConfigEmpty?: boolean;
|
|
345
|
+
};
|
|
346
|
+
}
|
|
118
347
|
export interface OpenClawPluginServiceCompat {
|
|
119
348
|
id: string;
|
|
120
349
|
start(params: {
|
|
@@ -145,11 +374,11 @@ export interface OpenClawPluginCliContextCompat {
|
|
|
145
374
|
}
|
|
146
375
|
export type OpenClawPluginCliRegistrarCompat = (ctx: OpenClawPluginCliContextCompat) => Promise<void> | void;
|
|
147
376
|
export interface OpenClawPluginApiCompat {
|
|
148
|
-
runtime: unknown;
|
|
377
|
+
runtime: OpenClawPluginRuntimeCompat | unknown;
|
|
149
378
|
pluginConfig?: Record<string, unknown>;
|
|
150
379
|
logger: OpenClawPluginLoggerCompat;
|
|
151
380
|
registerChannel?(params: {
|
|
152
|
-
plugin: unknown;
|
|
381
|
+
plugin: OpenClawChannelPluginCompat | unknown;
|
|
153
382
|
}): void;
|
|
154
383
|
registerCommand(command: OpenClawPluginCommandDefinitionCompat): void;
|
|
155
384
|
registerCli?(registrar: OpenClawPluginCliRegistrarCompat, opts?: {
|
package/dist/compat/openclaw.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openclaw.js","sourceRoot":"","sources":["../../src/compat/openclaw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,YAAY,EAAE;YACZ,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,iFAAiF,sBAAsB,GAAG;YACvH,OAAO,EAAE,sBAAsB;SAChC;QACD,YAAY,EAAE;YACZ,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,6DAA6D;YAC1E,OAAO,EAAE,IAAI;SACd;QACD,cAAc,EAAE;YACd,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,+DAA+D;SAC7E;QACD,OAAO,EAAE;YACP,IAAI,EAAE,SAAS;YACf,WAAW,EACT,6HAA6H;SAChI;QACD,wBAAwB,EAAE;YACxB,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,iFAAiF;YAC9F,OAAO,EAAE,CAAC;SACX;QACD,kB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AAE;YAC3B,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,+DAA+D;YAC5E,OAAO,EAAE,CAAC;SACX;KACF;CACO,CAAC"}
|
package/dist/openclaw-plugin.js
CHANGED
|
@@ -7,14 +7,16 @@ import { loadAvailableOpenClawCommands } from "./openclaw-command-discovery.js";
|
|
|
7
7
|
import { openInBrowserPreview, parsePositiveIntegerFlag, printPairInviteBundle, renderInviteBundleOutput, runPairSession, } from "./pair-session.js";
|
|
8
8
|
import { handoffForegroundPairToBackground, spawnBackgroundPairDaemon, } from "./pair-daemon.js";
|
|
9
9
|
import { WebhookBridge } from "./bridges/webhook-bridge.js";
|
|
10
|
+
import { createPrivateClawChannelPlugin, PRIVATECLAW_OPENCLAW_ACCOUNT_ID, PRIVATECLAW_OPENCLAW_CHANNEL_ID, } from "./channel.js";
|
|
10
11
|
import { privateClawConfigSchema, } from "./compat/openclaw.js";
|
|
11
12
|
import { DEFAULT_SESSION_TTL_MS, PrivateClawProvider } from "./provider.js";
|
|
12
13
|
import { DEFAULT_RELAY_BASE_URL } from "./relay-defaults.js";
|
|
13
14
|
import { resolveRelayEndpoints } from "./relay-endpoints.js";
|
|
14
|
-
import { buildManagedSessionQrLegacyLines, followManagedSessionLogFromStateDir, buildManagedSessionsReportLines, closeManagedSessionsFromStateDir, closeManagedSessionFromStateDir, getManagedSessionQrBundleFromStateDir, isManagedSessionQrLegacyResult, kickManagedParticipantFromStateDir, listManagedSessionsFromStateDir, PrivateClawSessionControlServer, resolvePrivateClawStateDir, } from "./session-control.js";
|
|
15
|
+
import { buildManagedSessionQrLegacyLines, followManagedSessionLogFromStateDir, buildManagedSessionsReportLines, closeManagedSessionsFromStateDir, closeManagedSessionFromStateDir, deliverManagedSessionOutboundFromStateDir, dispatchRoutedAppMessageToPluginServiceFromStateDir, getManagedSessionQrBundleFromStateDir, isManagedSessionQrLegacyResult, kickManagedParticipantFromStateDir, listManagedSessionsFromStateDir, PrivateClawSessionControlServer, resolvePrivateClawStateDir, } from "./session-control.js";
|
|
15
16
|
import { appendPrivateClawAppInstallFooter, buildPrivateClawBackgroundDaemonReminder, buildPrivateClawCommandErrorMessage, formatBilingualInline, PRIVATECLAW_CLI_FOREGROUND_OPTION_DESCRIPTION, PRIVATECLAW_CLI_GROUP_OPTION_DESCRIPTION, PRIVATECLAW_CLI_KICK_DESCRIPTION, PRIVATECLAW_CLI_LABEL_OPTION_DESCRIPTION, PRIVATECLAW_CLI_NOTIFY_OPTION_DESCRIPTION, PRIVATECLAW_CLI_OPEN_OPTION_DESCRIPTION, PRIVATECLAW_CLI_PAIR_DESCRIPTION, PRIVATECLAW_CLI_PRINT_ONLY_OPTION_DESCRIPTION, PRIVATECLAW_CLI_RELAY_OPTION_DESCRIPTION, PRIVATECLAW_CLI_ROOT_DESCRIPTION, PRIVATECLAW_CLI_SESSIONS_DESCRIPTION, PRIVATECLAW_CLI_SESSIONS_FOLLOW_DESCRIPTION, PRIVATECLAW_CLI_SESSIONS_KILL_DESCRIPTION, PRIVATECLAW_CLI_SESSIONS_KILLALL_DESCRIPTION, PRIVATECLAW_CLI_SESSIONS_QR_DESCRIPTION, PRIVATECLAW_CLI_TTL_OPTION_DESCRIPTION, PRIVATECLAW_CLI_VERBOSE_OPTION_DESCRIPTION, PRIVATECLAW_COMMAND_DESCRIPTION, PRIVATECLAW_INVITE_URI_LABEL, PRIVATECLAW_PLUGIN_DESCRIPTION, writePrivateClawAppInstallFooter, } from "./text.js";
|
|
16
17
|
const DEFAULT_PROVIDER_LABEL = "PrivateClaw";
|
|
17
18
|
const DEFAULT_BRIDGE_MODE = "openclaw-agent";
|
|
19
|
+
const DEFAULT_OPENCLAW_AGENT_CHANNEL = "privateclaw";
|
|
18
20
|
const QQ_INLINE_IMAGE_REPLY_CHANNELS = new Set(["qqbot", "qq", "qqguild", "qq-guild"]);
|
|
19
21
|
const ALLOWED_THINKING_LEVELS = new Set([
|
|
20
22
|
"off",
|
|
@@ -116,7 +118,8 @@ function resolvePluginConfig(pluginConfig) {
|
|
|
116
118
|
const openclawAgentId = readString(pluginConfig?.openclawAgentId) ??
|
|
117
119
|
readString(process.env.PRIVATECLAW_OPENCLAW_AGENT_ID);
|
|
118
120
|
const openclawAgentChannel = readString(pluginConfig?.openclawAgentChannel) ??
|
|
119
|
-
readString(process.env.PRIVATECLAW_OPENCLAW_AGENT_CHANNEL)
|
|
121
|
+
readString(process.env.PRIVATECLAW_OPENCLAW_AGENT_CHANNEL) ??
|
|
122
|
+
DEFAULT_OPENCLAW_AGENT_CHANNEL;
|
|
120
123
|
const openclawAgentLocal = readBoolean(pluginConfig?.openclawAgentLocal) ??
|
|
121
124
|
readBoolean(process.env.PRIVATECLAW_OPENCLAW_AGENT_LOCAL);
|
|
122
125
|
const openclawAgentThinking = readThinkingLevel(pluginConfig?.openclawAgentThinking) ??
|
|
@@ -407,6 +410,67 @@ function buildDaemonEnvFromPluginConfig(pluginConfig) {
|
|
|
407
410
|
: {}),
|
|
408
411
|
};
|
|
409
412
|
}
|
|
413
|
+
function isOpenClawPluginRuntimeCompatible(runtime) {
|
|
414
|
+
if (!runtime || typeof runtime !== "object") {
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
const channel = runtime.channel;
|
|
418
|
+
const reply = channel && typeof channel === "object"
|
|
419
|
+
? channel.reply
|
|
420
|
+
: undefined;
|
|
421
|
+
const routing = channel && typeof channel === "object"
|
|
422
|
+
? channel.routing
|
|
423
|
+
: undefined;
|
|
424
|
+
const session = channel && typeof channel === "object"
|
|
425
|
+
? channel.session
|
|
426
|
+
: undefined;
|
|
427
|
+
return (typeof reply?.dispatchReplyWithBufferedBlockDispatcher === "function" &&
|
|
428
|
+
typeof reply.finalizeInboundContext === "function" &&
|
|
429
|
+
typeof routing?.resolveAgentRoute === "function" &&
|
|
430
|
+
typeof session?.resolveStorePath === "function" &&
|
|
431
|
+
typeof session.recordInboundSession === "function");
|
|
432
|
+
}
|
|
433
|
+
function buildBasePrivateClawInboundContext(message) {
|
|
434
|
+
const rawText = readString(message.payload.text) ?? "";
|
|
435
|
+
const senderId = readString(message.participant?.appId) ??
|
|
436
|
+
readString(message.payload.appId) ??
|
|
437
|
+
message.sessionId;
|
|
438
|
+
const senderName = readString(message.participant?.displayName) ??
|
|
439
|
+
readString(message.payload.displayName) ??
|
|
440
|
+
"PrivateClaw user";
|
|
441
|
+
return {
|
|
442
|
+
Body: rawText,
|
|
443
|
+
BodyForAgent: message.groupMode && message.participant
|
|
444
|
+
? `${message.participant.displayName}: ${rawText}`
|
|
445
|
+
: rawText,
|
|
446
|
+
RawBody: rawText,
|
|
447
|
+
CommandBody: rawText,
|
|
448
|
+
BodyForCommands: rawText,
|
|
449
|
+
From: `${PRIVATECLAW_OPENCLAW_CHANNEL_ID}:${senderId}`,
|
|
450
|
+
To: message.sessionId,
|
|
451
|
+
AccountId: PRIVATECLAW_OPENCLAW_ACCOUNT_ID,
|
|
452
|
+
MessageSid: message.payload.clientMessageId,
|
|
453
|
+
MessageSidFull: message.payload.clientMessageId,
|
|
454
|
+
Timestamp: Number.isNaN(Date.parse(message.payload.sentAt))
|
|
455
|
+
? Date.now()
|
|
456
|
+
: Date.parse(message.payload.sentAt),
|
|
457
|
+
ChatType: message.groupMode ? "group" : "direct",
|
|
458
|
+
ConversationLabel: readString(message.sessionLabel) ?? "PrivateClaw",
|
|
459
|
+
SenderId: senderId,
|
|
460
|
+
SenderName: senderName,
|
|
461
|
+
Provider: PRIVATECLAW_OPENCLAW_CHANNEL_ID,
|
|
462
|
+
Surface: PRIVATECLAW_OPENCLAW_CHANNEL_ID,
|
|
463
|
+
CommandAuthorized: true,
|
|
464
|
+
NativeChannelId: message.sessionId,
|
|
465
|
+
OriginatingChannel: PRIVATECLAW_OPENCLAW_CHANNEL_ID,
|
|
466
|
+
OriginatingTo: message.sessionId,
|
|
467
|
+
ExplicitDeliverRoute: true,
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
function readConfiguredSessionStorePath(cfg) {
|
|
471
|
+
const rawStore = cfg.session?.store;
|
|
472
|
+
return readString(rawStore);
|
|
473
|
+
}
|
|
410
474
|
class PrivateClawPluginRuntime {
|
|
411
475
|
providerOptions;
|
|
412
476
|
defaultTtlMs;
|
|
@@ -417,6 +481,8 @@ class PrivateClawPluginRuntime {
|
|
|
417
481
|
controlServer;
|
|
418
482
|
defaultRelayBaseUrl;
|
|
419
483
|
verboseController;
|
|
484
|
+
openClawRuntime;
|
|
485
|
+
channelPlugin;
|
|
420
486
|
constructor(providerOptions, defaultTtlMs = DEFAULT_SESSION_TTL_MS, daemonEnv, defaultRelayBaseUrl, verboseController) {
|
|
421
487
|
this.providerOptions = providerOptions;
|
|
422
488
|
this.defaultTtlMs = defaultTtlMs;
|
|
@@ -425,6 +491,11 @@ class PrivateClawPluginRuntime {
|
|
|
425
491
|
readString(defaultRelayBaseUrl) ??
|
|
426
492
|
inferRelayBaseUrlFromAppWsUrl(providerOptions.appWsUrl);
|
|
427
493
|
this.verboseController = verboseController ?? providerOptions.verboseController;
|
|
494
|
+
this.channelPlugin = createPrivateClawChannelPlugin({
|
|
495
|
+
deliverOutboundMessage: async (sessionId, payload) => {
|
|
496
|
+
await this.deliverOpenClawOutboundMessage(sessionId, payload);
|
|
497
|
+
},
|
|
498
|
+
});
|
|
428
499
|
}
|
|
429
500
|
async withVerboseLogging(verbose, action) {
|
|
430
501
|
if (!verbose || !this.verboseController) {
|
|
@@ -445,6 +516,14 @@ class PrivateClawPluginRuntime {
|
|
|
445
516
|
setRootConfig(config) {
|
|
446
517
|
this.rootConfig = config;
|
|
447
518
|
}
|
|
519
|
+
setOpenClawRuntime(runtime) {
|
|
520
|
+
this.openClawRuntime = isOpenClawPluginRuntimeCompatible(runtime)
|
|
521
|
+
? runtime
|
|
522
|
+
: undefined;
|
|
523
|
+
}
|
|
524
|
+
getChannelPlugin() {
|
|
525
|
+
return this.channelPlugin;
|
|
526
|
+
}
|
|
448
527
|
ensureStateDir() {
|
|
449
528
|
this.stateDir = resolvePrivateClawStateDir(this.stateDir);
|
|
450
529
|
return this.stateDir;
|
|
@@ -472,6 +551,7 @@ class PrivateClawPluginRuntime {
|
|
|
472
551
|
...this.providerOptions,
|
|
473
552
|
providerWsUrl: relay.providerWsUrl,
|
|
474
553
|
appWsUrl: relay.appWsUrl,
|
|
554
|
+
appMessageRouter: async (message) => this.routeOrForwardAppMessage(message),
|
|
475
555
|
...(audioTranscriber ? { audioTranscriber } : {}),
|
|
476
556
|
},
|
|
477
557
|
};
|
|
@@ -486,6 +566,111 @@ class PrivateClawPluginRuntime {
|
|
|
486
566
|
}
|
|
487
567
|
return entry.provider;
|
|
488
568
|
}
|
|
569
|
+
findLocalProviderBySession(sessionId) {
|
|
570
|
+
for (const entry of this.providerEntries.values()) {
|
|
571
|
+
if (entry.provider?.hasManagedSession(sessionId)) {
|
|
572
|
+
return entry.provider;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return undefined;
|
|
576
|
+
}
|
|
577
|
+
async deliverOpenClawOutboundMessage(sessionId, payload) {
|
|
578
|
+
const provider = this.findLocalProviderBySession(sessionId);
|
|
579
|
+
if (provider) {
|
|
580
|
+
await provider.deliverOpenClawOutboundMessage(sessionId, payload);
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
await deliverManagedSessionOutboundFromStateDir({
|
|
584
|
+
stateDir: this.ensureStateDir(),
|
|
585
|
+
sessionId,
|
|
586
|
+
payload,
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
async routeAppMessageToOpenClaw(message) {
|
|
590
|
+
const runtime = this.openClawRuntime?.channel;
|
|
591
|
+
if (!runtime) {
|
|
592
|
+
throw new Error("The active PrivateClaw host does not expose OpenClaw channel runtime helpers.");
|
|
593
|
+
}
|
|
594
|
+
const cfg = (this.rootConfig ?? {});
|
|
595
|
+
const baseCtx = buildBasePrivateClawInboundContext(message);
|
|
596
|
+
const route = runtime.routing.resolveAgentRoute({
|
|
597
|
+
cfg,
|
|
598
|
+
ctx: baseCtx,
|
|
599
|
+
});
|
|
600
|
+
const finalizedCtx = runtime.reply.finalizeInboundContext({
|
|
601
|
+
...baseCtx,
|
|
602
|
+
SessionKey: route.sessionKey,
|
|
603
|
+
...(route.mainSessionKey !== route.sessionKey
|
|
604
|
+
? { ParentSessionKey: route.mainSessionKey }
|
|
605
|
+
: {}),
|
|
606
|
+
}, {
|
|
607
|
+
forceBodyForAgent: true,
|
|
608
|
+
forceBodyForCommands: true,
|
|
609
|
+
forceChatType: true,
|
|
610
|
+
forceConversationLabel: true,
|
|
611
|
+
});
|
|
612
|
+
const storePath = runtime.session.resolveStorePath(readConfiguredSessionStorePath(cfg), {
|
|
613
|
+
agentId: route.agentId,
|
|
614
|
+
});
|
|
615
|
+
await runtime.session.recordInboundSession({
|
|
616
|
+
storePath,
|
|
617
|
+
sessionKey: route.sessionKey,
|
|
618
|
+
ctx: finalizedCtx,
|
|
619
|
+
createIfMissing: true,
|
|
620
|
+
updateLastRoute: {
|
|
621
|
+
sessionKey: route.lastRoutePolicy === "main"
|
|
622
|
+
? route.mainSessionKey
|
|
623
|
+
: route.sessionKey,
|
|
624
|
+
channel: PRIVATECLAW_OPENCLAW_CHANNEL_ID,
|
|
625
|
+
to: message.sessionId,
|
|
626
|
+
accountId: PRIVATECLAW_OPENCLAW_ACCOUNT_ID,
|
|
627
|
+
},
|
|
628
|
+
onRecordError: (error) => {
|
|
629
|
+
this.providerOptions.onLog?.(`[privateclaw] runtime_session_record_error session=${message.sessionId} message=${formatCommandError(error)}`);
|
|
630
|
+
},
|
|
631
|
+
});
|
|
632
|
+
await runtime.reply.dispatchReplyWithBufferedBlockDispatcher({
|
|
633
|
+
ctx: finalizedCtx,
|
|
634
|
+
cfg,
|
|
635
|
+
dispatcherOptions: {
|
|
636
|
+
deliver: async (payload) => {
|
|
637
|
+
const replyToId = typeof payload.replyToId === "string" && payload.replyToId.trim() !== ""
|
|
638
|
+
? payload.replyToId
|
|
639
|
+
: message.payload.clientMessageId;
|
|
640
|
+
await this.deliverOpenClawOutboundMessage(message.sessionId, {
|
|
641
|
+
...(payload.text?.trim() ? { text: payload.text.trim() } : {}),
|
|
642
|
+
...(payload.mediaUrl?.trim()
|
|
643
|
+
? { mediaUrl: payload.mediaUrl.trim() }
|
|
644
|
+
: {}),
|
|
645
|
+
...(payload.mediaUrls?.length
|
|
646
|
+
? { mediaUrls: payload.mediaUrls }
|
|
647
|
+
: {}),
|
|
648
|
+
replyToId,
|
|
649
|
+
});
|
|
650
|
+
},
|
|
651
|
+
onError: (error, info) => {
|
|
652
|
+
this.providerOptions.onLog?.(`[privateclaw] runtime_dispatch_error kind=${info.kind} message=${formatCommandError(error)}`);
|
|
653
|
+
},
|
|
654
|
+
},
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
async routeOrForwardAppMessage(message) {
|
|
658
|
+
if (this.openClawRuntime?.channel) {
|
|
659
|
+
await this.routeAppMessageToOpenClaw(message);
|
|
660
|
+
return true;
|
|
661
|
+
}
|
|
662
|
+
try {
|
|
663
|
+
await dispatchRoutedAppMessageToPluginServiceFromStateDir({
|
|
664
|
+
stateDir: this.ensureStateDir(),
|
|
665
|
+
message,
|
|
666
|
+
});
|
|
667
|
+
return true;
|
|
668
|
+
}
|
|
669
|
+
catch (error) {
|
|
670
|
+
this.providerOptions.onLog?.(`[privateclaw] runtime routing unavailable, falling back to bridge for ${message.sessionId}: ${formatCommandError(error)}`);
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
489
674
|
listLocalManagedSessions() {
|
|
490
675
|
return [...this.providerEntries.values()].flatMap((entry) => entry.provider?.listManagedSessions() ?? []);
|
|
491
676
|
}
|
|
@@ -541,6 +726,8 @@ class PrivateClawPluginRuntime {
|
|
|
541
726
|
getSessionQrBundle: (sessionId, params) => this.getLocalManagedSessionQrBundle(sessionId, params),
|
|
542
727
|
closeManagedSession: (sessionId, reason) => this.closeLocalManagedSession(sessionId, reason),
|
|
543
728
|
kickGroupParticipant: (sessionId, appId, reason) => this.kickLocalManagedParticipant(sessionId, appId, reason),
|
|
729
|
+
deliverOpenClawOutboundMessage: (sessionId, payload) => this.deliverOpenClawOutboundMessage(sessionId, payload),
|
|
730
|
+
routeAppMessageToOpenClaw: (message) => this.routeAppMessageToOpenClaw(message),
|
|
544
731
|
},
|
|
545
732
|
stateDir: this.ensureStateDir(),
|
|
546
733
|
kind,
|
|
@@ -550,8 +737,11 @@ class PrivateClawPluginRuntime {
|
|
|
550
737
|
});
|
|
551
738
|
await this.controlServer.start();
|
|
552
739
|
}
|
|
553
|
-
async
|
|
740
|
+
async ensurePluginServiceControl() {
|
|
554
741
|
await this.ensureControlServer("plugin-service");
|
|
742
|
+
}
|
|
743
|
+
async createInviteBundle(params) {
|
|
744
|
+
await this.ensurePluginServiceControl();
|
|
555
745
|
return this.getProvider(params?.relayBaseUrl).createInviteBundle({
|
|
556
746
|
...(typeof params?.ttlMs === "number"
|
|
557
747
|
? { ttlMs: params.ttlMs }
|
|
@@ -740,16 +930,21 @@ function createPluginDefinition(runtimeFactory) {
|
|
|
740
930
|
configSchema: privateClawConfigSchema,
|
|
741
931
|
register(api) {
|
|
742
932
|
const runtime = runtimeFactory(api);
|
|
933
|
+
runtime.setOpenClawRuntime(api.runtime);
|
|
743
934
|
api.registerService?.({
|
|
744
935
|
id: "privateclaw-provider",
|
|
745
|
-
start: ({ stateDir, config }) => {
|
|
936
|
+
start: async ({ stateDir, config }) => {
|
|
746
937
|
runtime.setStateDir(stateDir);
|
|
747
938
|
runtime.setRootConfig(config);
|
|
939
|
+
await runtime.ensurePluginServiceControl();
|
|
748
940
|
},
|
|
749
941
|
stop: async () => {
|
|
750
942
|
await runtime.dispose();
|
|
751
943
|
},
|
|
752
944
|
});
|
|
945
|
+
api.registerChannel?.({
|
|
946
|
+
plugin: runtime.getChannelPlugin(),
|
|
947
|
+
});
|
|
753
948
|
api.registerCommand({
|
|
754
949
|
name: "privateclaw",
|
|
755
950
|
description: PRIVATECLAW_COMMAND_DESCRIPTION,
|