@coolclaw/clawtopia-connector 0.1.0 → 0.2.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/dist/index.d.ts DELETED
@@ -1,384 +0,0 @@
1
- declare const PROTOCOL_VERSION: 1;
2
- declare const EXACT_ACK_CAPABILITY = "EXACT_MESSAGE_ACK_V1";
3
- declare const RECEIPT_CAPABILITY = "MESSAGE_PROCESSING_RECEIPT_V1";
4
- declare const MEDIA_INPUT_CAPABILITY = "MEDIA_INPUT_V1";
5
- declare const GAME_CAPABILITY = "WEREWOLF_STRUCTURED_JSON_MESSAGE_V1";
6
- declare const PROMPT_PASSTHROUGH_CAPABILITY = "AGENT_TASK_PROMPT_PASSTHROUGH_V1";
7
- declare const DEFAULT_CAPABILITIES: readonly ["WEREWOLF_STRUCTURED_JSON_MESSAGE_V1", "EXACT_MESSAGE_ACK_V1", "MESSAGE_PROCESSING_RECEIPT_V1", "AGENT_TASK_PROMPT_PASSTHROUGH_V1", "MEDIA_INPUT_V1"];
8
- type Frame<T = unknown> = {
9
- v: typeof PROTOCOL_VERSION;
10
- type: string;
11
- id: string;
12
- ack?: string;
13
- ts: number;
14
- payload?: T;
15
- };
16
- declare function createFrame<T>(type: string, payload?: T, ack?: string): Frame<T>;
17
- declare function respondFrame<T>(type: string, ack: Frame, payload?: T): Frame<T>;
18
- declare function encodeFrame(frame: Frame): string;
19
- declare class FrameDecodeError extends Error {
20
- constructor(message: string);
21
- }
22
- declare function decodeFrame<T = unknown>(raw: string | Buffer): Frame<T>;
23
- type MessageFrame = Frame<{
24
- seq: number;
25
- messageId: string;
26
- conversationId?: string;
27
- groupId?: string;
28
- sender?: Record<string, unknown>;
29
- recipient?: Record<string, unknown>;
30
- messageType: string;
31
- content: string;
32
- mentioned?: boolean;
33
- [key: string]: unknown;
34
- }>;
35
- type GameEventFrame = Frame<{
36
- seq: number;
37
- eventId: string;
38
- eventRecordId?: number;
39
- gameId: number;
40
- roomId: number;
41
- turnSeq: number;
42
- eventType: string;
43
- eventData?: unknown;
44
- agentTask: {
45
- requiresReply: boolean;
46
- renderedPrompt: string;
47
- actionContract?: Record<string, unknown>;
48
- outputSchema?: Record<string, unknown>;
49
- retryPolicy?: {
50
- maxRetries?: number;
51
- shareDeadline?: boolean;
52
- rejectedOutputActionType?: string;
53
- };
54
- fallbackAction?: Record<string, unknown> | null;
55
- promptPolicyVersion?: string;
56
- renderedPromptHash?: string;
57
- actionProtocolVersion?: string;
58
- conversationKey?: string;
59
- };
60
- deadlineEpochMs?: number;
61
- traceId: string;
62
- }>;
63
- declare function isRecord(value: unknown): value is Record<string, unknown>;
64
- declare function isInboundMessage(frame: Frame): frame is MessageFrame;
65
- declare function isGameEvent(frame: Frame): frame is GameEventFrame;
66
- declare function readSeq(frame: Frame): number | undefined;
67
- declare function readMessageId(frame: Frame): string | undefined;
68
-
69
- type ConnectorState = {
70
- version: 1;
71
- processedMessageIds: string[];
72
- processedEventIds: string[];
73
- sessionIds: Record<string, string>;
74
- /** Upstream Claude/Codex session ids; sessionIds remains the worker-local key. */
75
- agentSessionIds: Record<string, string>;
76
- inflight: Record<string, {
77
- messageId: string;
78
- serverSeq: number;
79
- }>;
80
- updatedAt: number;
81
- };
82
- interface StateStore {
83
- load(): Promise<ConnectorState>;
84
- save(state: ConnectorState): Promise<void>;
85
- }
86
- declare class MemoryStateStore implements StateStore {
87
- private state;
88
- load(): Promise<ConnectorState>;
89
- save(state: ConnectorState): Promise<void>;
90
- }
91
- declare class JsonFileStateStore implements StateStore {
92
- private readonly filePath;
93
- private writeTail;
94
- constructor(filePath: string);
95
- load(): Promise<ConnectorState>;
96
- save(state: ConnectorState): Promise<void>;
97
- }
98
- declare function normalizeState(value: Partial<ConnectorState> | undefined): ConnectorState;
99
- declare function cloneState(state: ConnectorState): ConnectorState;
100
-
101
- type ChannelState = "connecting" | "connected" | "reconnecting" | "disconnected";
102
- type ChannelClientOptions = {
103
- gatewayUrl: string;
104
- agentId: string;
105
- token: string;
106
- connectorVersion: string;
107
- capabilities?: string[];
108
- heartbeatIntervalMs?: number;
109
- reconnectDelayMs?: number;
110
- requestTimeoutMs?: number;
111
- onFrame?: (frame: Frame, client: ChannelClient) => Promise<void> | void;
112
- onStateChange?: (state: ChannelState) => void;
113
- onError?: (error: Error) => void;
114
- };
115
- declare class ChannelClient {
116
- private readonly options;
117
- private socket?;
118
- private heartbeat?;
119
- private reconnectTimer?;
120
- private readonly pending;
121
- private stopped;
122
- private reconnectAttempt;
123
- private helloPayload;
124
- private frameHandler?;
125
- constructor(options: ChannelClientOptions);
126
- setFrameHandler(handler: (frame: Frame, client: ChannelClient) => Promise<void> | void): void;
127
- start(): Promise<void>;
128
- stop(): Promise<void>;
129
- isConnected(): boolean;
130
- getHelloPayload(): unknown;
131
- getGatewayUrl(): string;
132
- request<T>(frame: Frame): Promise<T>;
133
- send(frame: Frame): void;
134
- ack(serverSeq: number, messageId?: string): Promise<void>;
135
- receipt(payload: {
136
- messageId: string;
137
- serverSeq: number;
138
- status: "PROCESSING" | "COMPLETED";
139
- outcome?: "REPLIED" | "NO_REPLY" | "FAILED";
140
- errorCode?: string;
141
- errorMessage?: string;
142
- retryable?: boolean;
143
- }): Promise<void>;
144
- private connect;
145
- private handleRaw;
146
- private handleFrame;
147
- private startHeartbeat;
148
- private handleClose;
149
- private scheduleReconnect;
150
- private rejectPending;
151
- private clearHeartbeat;
152
- private clearReconnect;
153
- private notify;
154
- }
155
-
156
- type WorkerEvent = {
157
- event: "text" | "thinking" | "tool_use" | "tool_result" | "permission" | "result" | "error";
158
- sessionId?: string;
159
- agentSessionId?: string;
160
- content?: string;
161
- done?: boolean;
162
- error?: string;
163
- requestId?: string;
164
- data?: unknown;
165
- type?: string;
166
- [key: string]: unknown;
167
- };
168
- type WorkerTransport = {
169
- write(line: string): void;
170
- onLine(listener: (line: string) => void): void;
171
- onExit?(listener: (error: Error) => void): void;
172
- close(): Promise<void>;
173
- };
174
- type WorkerClientOptions = {
175
- executable: string;
176
- args?: string[];
177
- cwd?: string;
178
- env?: NodeJS.ProcessEnv;
179
- requestTimeoutMs?: number;
180
- onEvent?: (event: WorkerEvent) => void | Promise<void>;
181
- onStderr?: (line: string) => void;
182
- transportFactory?: (options: WorkerClientOptions) => WorkerTransport;
183
- };
184
- /** Runtime executor contract shared by the bundled worker and OpenClaw adapter. */
185
- interface RuntimeExecutor {
186
- setEventHandler?(handler: (event: WorkerEvent) => void | Promise<void>): void;
187
- initialize(runtime: string, connectorVersion: string): Promise<WorkerInitializeResult>;
188
- startSession(input: WorkerStartSessionInput): Promise<WorkerSessionResult>;
189
- resumeSession(input: WorkerResumeSessionInput): Promise<WorkerSessionResult>;
190
- send(input: WorkerSendInput): Promise<{
191
- accepted: boolean;
192
- }>;
193
- respondPermission(input: WorkerPermissionResponse): Promise<{
194
- accepted: boolean;
195
- }>;
196
- cancel(sessionId: string, reason?: string): Promise<{
197
- accepted: boolean;
198
- }>;
199
- closeSession(sessionId: string): Promise<{
200
- accepted: boolean;
201
- }>;
202
- health(): Promise<WorkerHealthResult>;
203
- shutdown(): Promise<void>;
204
- }
205
- declare class WorkerClient {
206
- private readonly options;
207
- private transport?;
208
- private readonly pending;
209
- private started;
210
- private closed;
211
- private eventHandler?;
212
- constructor(options: WorkerClientOptions);
213
- setEventHandler(handler: (event: WorkerEvent) => void | Promise<void>): void;
214
- start(): Promise<void>;
215
- initialize(runtime: string, connectorVersion: string): Promise<WorkerInitializeResult>;
216
- startSession(input: WorkerStartSessionInput): Promise<WorkerSessionResult>;
217
- resumeSession(input: WorkerResumeSessionInput): Promise<WorkerSessionResult>;
218
- send(input: WorkerSendInput): Promise<{
219
- accepted: boolean;
220
- }>;
221
- respondPermission(input: WorkerPermissionResponse): Promise<{
222
- accepted: boolean;
223
- }>;
224
- cancel(sessionId: string, reason?: string): Promise<{
225
- accepted: boolean;
226
- }>;
227
- closeSession(sessionId: string): Promise<{
228
- accepted: boolean;
229
- }>;
230
- health(): Promise<WorkerHealthResult>;
231
- shutdown(): Promise<void>;
232
- private request;
233
- private handleLine;
234
- private rejectAll;
235
- }
236
- type WorkerInitializeResult = {
237
- workerVersion: string;
238
- protocolVersion: number | string;
239
- runtime: string;
240
- agents?: string[];
241
- capabilities: string[] | Record<string, boolean>;
242
- };
243
- type WorkerStartSessionInput = {
244
- sessionId?: string;
245
- agentSessionId?: string;
246
- runtime: string;
247
- runtimePath?: string;
248
- workDir?: string;
249
- mode?: string;
250
- backend?: string;
251
- appServerUrl?: string;
252
- timeoutMs?: number;
253
- };
254
- type WorkerResumeSessionInput = WorkerStartSessionInput & {
255
- sessionId: string;
256
- };
257
- type WorkerSessionResult = {
258
- sessionId: string;
259
- agentSessionId?: string;
260
- runtime: string;
261
- alive?: boolean;
262
- resumed?: boolean;
263
- };
264
- type WorkerAttachment = {
265
- path: string;
266
- mimeType?: string;
267
- fileName?: string;
268
- sha256?: string;
269
- size?: number;
270
- };
271
- type WorkerSendInput = {
272
- sessionId: string;
273
- messageId: string;
274
- prompt: string;
275
- images?: WorkerAttachment[];
276
- files?: WorkerAttachment[];
277
- timeoutMs?: number;
278
- };
279
- type WorkerPermissionResponse = {
280
- sessionId: string;
281
- requestId: string;
282
- behavior: "allow" | "deny";
283
- updatedInput?: Record<string, unknown>;
284
- message?: string;
285
- };
286
- type WorkerHealthResult = {
287
- ok: boolean;
288
- sessions?: number;
289
- runtime?: string;
290
- version?: string;
291
- };
292
-
293
- type Diagnostic = {
294
- event: string;
295
- phase?: string;
296
- messageId?: string;
297
- serverSeq?: number;
298
- sessionId?: string;
299
- error?: string;
300
- home?: string;
301
- inherited?: string;
302
- };
303
-
304
- type RuntimeConnectorOptions = {
305
- channel: ChannelClient;
306
- worker: RuntimeExecutor;
307
- stateStore?: StateStore;
308
- runtime: string;
309
- runtimePath?: string;
310
- backend?: "exec" | "app_server";
311
- appServerUrl?: string;
312
- connectorVersion: string;
313
- taskTimeoutMs?: number;
314
- attachmentDir?: string;
315
- workDir?: string;
316
- onStateChange?: (state: string) => void;
317
- onDiagnostic?: (entry: Diagnostic) => void;
318
- onPermission?: (request: {
319
- sessionId: string;
320
- requestId: string;
321
- data?: unknown;
322
- }) => Promise<WorkerPermissionResponse["behavior"]> | WorkerPermissionResponse["behavior"];
323
- };
324
- declare class RuntimeConnector {
325
- private readonly options;
326
- private readonly stateStore;
327
- private state;
328
- private readonly queues;
329
- private readonly contexts;
330
- private readonly activeMessages;
331
- private readonly activeEvents;
332
- private started;
333
- constructor(options: RuntimeConnectorOptions);
334
- start(): Promise<void>;
335
- stop(): Promise<void>;
336
- /** Attach the callback after constructing a ChannelClient without relying on a global runtime. */
337
- handleFrame(frame: Frame): Promise<void>;
338
- private handleMessage;
339
- private handleGameEvent;
340
- private enqueue;
341
- private dispatchMessage;
342
- private sendReceipt;
343
- private dispatchGameEvent;
344
- private getOrCreateSession;
345
- private runTask;
346
- private prepareMessageInput;
347
- private sendReply;
348
- private handleWorkerEvent;
349
- private remember;
350
- private diagnose;
351
- private persist;
352
- }
353
-
354
- type ConnectorConfig = {
355
- schemaVersion: number;
356
- profileId: string;
357
- gatewayUrl: string;
358
- environment: string;
359
- agentId: string;
360
- token: string;
361
- runtime: "claudecode" | "codex" | "openclaw";
362
- workerPath: string;
363
- /** Expected SHA-256 of the pinned worker binary, populated by upgrade. */
364
- workerSha256?: string;
365
- /** Optional explicit local runtime executable (defaults to claude/codex). */
366
- runtimePath?: string;
367
- workDir: string;
368
- connectorVersion: string;
369
- backend?: "exec" | "app_server";
370
- appServerUrl?: string;
371
- permissionPolicy?: "allow" | "deny";
372
- pairingEndpoint?: string;
373
- };
374
- declare function configRoot(): string;
375
- declare function normalizeProfileId(value: string): string;
376
- declare function profileConfigPath(profileId?: string): string;
377
- declare const defaultConfigPath: typeof profileConfigPath;
378
- declare function bundledWorkerPath(): string;
379
- declare function defaultConfig(profileId?: string): ConnectorConfig;
380
- declare function loadConfig(path?: string): Promise<ConnectorConfig>;
381
- declare function saveConfig(config: ConnectorConfig, path?: string): Promise<void>;
382
- declare function profileEnvironment(config: ConnectorConfig, configPath?: string): NodeJS.ProcessEnv;
383
-
384
- export { ChannelClient, type ChannelClientOptions, type ChannelState, type ConnectorConfig, type ConnectorState, DEFAULT_CAPABILITIES, EXACT_ACK_CAPABILITY, type Frame, FrameDecodeError, GAME_CAPABILITY, type GameEventFrame, JsonFileStateStore, MEDIA_INPUT_CAPABILITY, MemoryStateStore, type MessageFrame, PROMPT_PASSTHROUGH_CAPABILITY, PROTOCOL_VERSION, RECEIPT_CAPABILITY, RuntimeConnector, type RuntimeConnectorOptions, type RuntimeExecutor, type StateStore, type WorkerAttachment, WorkerClient, type WorkerClientOptions, type WorkerEvent, type WorkerHealthResult, type WorkerInitializeResult, type WorkerPermissionResponse, type WorkerResumeSessionInput, type WorkerSendInput, type WorkerSessionResult, type WorkerStartSessionInput, type WorkerTransport, bundledWorkerPath, cloneState, configRoot, createFrame, decodeFrame, defaultConfig, defaultConfigPath, encodeFrame, isGameEvent, isInboundMessage, isRecord, loadConfig, normalizeProfileId, normalizeState, profileConfigPath, profileEnvironment, readMessageId, readSeq, respondFrame, saveConfig };
package/dist/index.js DELETED
@@ -1,70 +0,0 @@
1
- import {
2
- ChannelClient,
3
- DEFAULT_CAPABILITIES,
4
- EXACT_ACK_CAPABILITY,
5
- FrameDecodeError,
6
- GAME_CAPABILITY,
7
- JsonFileStateStore,
8
- MEDIA_INPUT_CAPABILITY,
9
- MemoryStateStore,
10
- PROMPT_PASSTHROUGH_CAPABILITY,
11
- PROTOCOL_VERSION,
12
- RECEIPT_CAPABILITY,
13
- RuntimeConnector,
14
- WorkerClient,
15
- bundledWorkerPath,
16
- cloneState,
17
- configRoot,
18
- createFrame,
19
- decodeFrame,
20
- defaultConfig,
21
- defaultConfigPath,
22
- encodeFrame,
23
- isGameEvent,
24
- isInboundMessage,
25
- isRecord,
26
- loadConfig,
27
- normalizeProfileId,
28
- normalizeState,
29
- profileConfigPath,
30
- profileEnvironment,
31
- readMessageId,
32
- readSeq,
33
- respondFrame,
34
- saveConfig
35
- } from "./chunk-5OV44BPP.js";
36
- export {
37
- ChannelClient,
38
- DEFAULT_CAPABILITIES,
39
- EXACT_ACK_CAPABILITY,
40
- FrameDecodeError,
41
- GAME_CAPABILITY,
42
- JsonFileStateStore,
43
- MEDIA_INPUT_CAPABILITY,
44
- MemoryStateStore,
45
- PROMPT_PASSTHROUGH_CAPABILITY,
46
- PROTOCOL_VERSION,
47
- RECEIPT_CAPABILITY,
48
- RuntimeConnector,
49
- WorkerClient,
50
- bundledWorkerPath,
51
- cloneState,
52
- configRoot,
53
- createFrame,
54
- decodeFrame,
55
- defaultConfig,
56
- defaultConfigPath,
57
- encodeFrame,
58
- isGameEvent,
59
- isInboundMessage,
60
- isRecord,
61
- loadConfig,
62
- normalizeProfileId,
63
- normalizeState,
64
- profileConfigPath,
65
- profileEnvironment,
66
- readMessageId,
67
- readSeq,
68
- respondFrame,
69
- saveConfig
70
- };
package/flavor.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "key": "coolclaw",
3
- "packageName": "@coolclaw/clawtopia-connector",
4
- "environment": "test",
5
- "defaultGatewayUrl": "https://agits-xa.baidu.com/riddle"
6
- }