@tickernelz/paperclip-pro-adapter-openclaw-gateway 2026.925.0

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 (55) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +85 -0
  3. package/dist/cli/format-event.d.ts +2 -0
  4. package/dist/cli/format-event.d.ts.map +1 -0
  5. package/dist/cli/format-event.js +20 -0
  6. package/dist/cli/format-event.js.map +1 -0
  7. package/dist/cli/index.d.ts +2 -0
  8. package/dist/cli/index.d.ts.map +1 -0
  9. package/dist/cli/index.js +2 -0
  10. package/dist/cli/index.js.map +1 -0
  11. package/dist/index.d.ts +8 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +52 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/server/execute-dispatch.test.d.ts +2 -0
  16. package/dist/server/execute-dispatch.test.d.ts.map +1 -0
  17. package/dist/server/execute-dispatch.test.js +192 -0
  18. package/dist/server/execute-dispatch.test.js.map +1 -0
  19. package/dist/server/execute.d.ts +21 -0
  20. package/dist/server/execute.d.ts.map +1 -0
  21. package/dist/server/execute.js +1209 -0
  22. package/dist/server/execute.js.map +1 -0
  23. package/dist/server/execute.test.d.ts +2 -0
  24. package/dist/server/execute.test.d.ts.map +1 -0
  25. package/dist/server/execute.test.js +101 -0
  26. package/dist/server/execute.test.js.map +1 -0
  27. package/dist/server/index.d.ts +3 -0
  28. package/dist/server/index.d.ts.map +1 -0
  29. package/dist/server/index.js +3 -0
  30. package/dist/server/index.js.map +1 -0
  31. package/dist/server/test.d.ts +3 -0
  32. package/dist/server/test.d.ts.map +1 -0
  33. package/dist/server/test.js +290 -0
  34. package/dist/server/test.js.map +1 -0
  35. package/dist/shared/stream.d.ts +5 -0
  36. package/dist/shared/stream.d.ts.map +1 -0
  37. package/dist/shared/stream.js +13 -0
  38. package/dist/shared/stream.js.map +1 -0
  39. package/dist/ui/build-config.d.ts +3 -0
  40. package/dist/ui/build-config.d.ts.map +1 -0
  41. package/dist/ui/build-config.js +85 -0
  42. package/dist/ui/build-config.js.map +1 -0
  43. package/dist/ui/build-config.test.d.ts +2 -0
  44. package/dist/ui/build-config.test.d.ts.map +1 -0
  45. package/dist/ui/build-config.test.js +49 -0
  46. package/dist/ui/build-config.test.js.map +1 -0
  47. package/dist/ui/index.d.ts +3 -0
  48. package/dist/ui/index.d.ts.map +1 -0
  49. package/dist/ui/index.js +3 -0
  50. package/dist/ui/index.js.map +1 -0
  51. package/dist/ui/parse-stdout.d.ts +3 -0
  52. package/dist/ui/parse-stdout.d.ts.map +1 -0
  53. package/dist/ui/parse-stdout.js +64 -0
  54. package/dist/ui/parse-stdout.js.map +1 -0
  55. package/package.json +59 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Paperclip AI
4
+ Copyright (c) 2026 Zhafron Adani Kautsar (paperclip-pro fork modifications)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # OpenClaw Gateway Adapter
2
+
3
+ This document describes how `@tickernelz/paperclip-pro-adapter-openclaw-gateway` invokes OpenClaw over the Gateway protocol.
4
+
5
+ ## Transport
6
+
7
+ This adapter always uses WebSocket gateway transport.
8
+
9
+ - URL must be `ws://` or `wss://`
10
+ - Connect flow follows gateway protocol:
11
+ 1. receive `connect.challenge`
12
+ 2. send `req connect` (protocol/client/auth/device payload)
13
+ 3. send `req agent`
14
+ 4. wait for completion via `req agent.wait`
15
+ 5. stream `event agent` frames into Paperclip logs/transcript parsing
16
+
17
+ ## Auth Modes
18
+
19
+ Gateway credentials can be provided in any of these ways:
20
+
21
+ - `authToken` / `token` in adapter config
22
+ - `headers.x-openclaw-token`
23
+ - `headers.x-openclaw-auth` (legacy)
24
+ - `password` (shared password mode)
25
+
26
+ When a token is present and `authorization` header is missing, the adapter derives `Authorization: Bearer <token>`.
27
+
28
+ ## Device Auth
29
+
30
+ By default the adapter sends a signed `device` payload in `connect` params.
31
+
32
+ - set `disableDeviceAuth=true` to omit device signing
33
+ - set `devicePrivateKeyPem` to pin a stable signing key
34
+ - without `devicePrivateKeyPem`, the adapter generates an ephemeral Ed25519 keypair per run
35
+ - when `autoPairOnFirstConnect` is enabled (default), the adapter handles one initial `pairing required` by calling `device.pair.list` + `device.pair.approve` over shared auth, then retries once.
36
+
37
+ ## Session Strategy
38
+
39
+ The adapter supports the same session routing model as HTTP OpenClaw mode:
40
+
41
+ - `sessionKeyStrategy=issue|fixed|run`
42
+ - `sessionKey` is used when strategy is `fixed`
43
+
44
+ Resolved session key is sent as `agent.sessionKey`.
45
+
46
+ ## Payload Mapping
47
+
48
+ The agent request is built as:
49
+
50
+ - required fields:
51
+ - `message` (wake text plus optional `payloadTemplate.message`/`payloadTemplate.text` prefix)
52
+ - `idempotencyKey` (Paperclip `runId`)
53
+ - `sessionKey` (resolved strategy)
54
+ - optional additions:
55
+ - all `payloadTemplate` fields merged in
56
+ - `agentId` from config if set and not already in template
57
+
58
+ ## Timeouts
59
+
60
+ - `timeoutSec` controls adapter-level request budget
61
+ - `waitTimeoutMs` controls `agent.wait.timeoutMs`
62
+
63
+ If `agent.wait` returns `timeout`, adapter returns `openclaw_gateway_wait_timeout`.
64
+
65
+ ## Log Format
66
+
67
+ Structured gateway event logs use:
68
+
69
+ - `[openclaw-gateway] ...` for lifecycle/system logs
70
+ - `[openclaw-gateway:event] run=<id> stream=<stream> data=<json>` for `event agent` frames
71
+
72
+ UI/CLI parsers consume these lines to render transcript updates.
73
+
74
+ ## No-remote-git contract
75
+
76
+ Like every Paperclip adapter, this one must treat the local execution-workspace
77
+ cwd as the only persistence boundary across runs — no `git push` from runtime
78
+ code, no assuming a `git remote` exists. The gateway transport here doesn't
79
+ touch the workspace directly, but if you extend the adapter to ship code to
80
+ the OpenClaw side, use the round-trip helpers in `@tickernelz/paperclip-pro-adapter-utils`
81
+ (`prepareWorkspaceForSshExecution` → `restoreWorkspaceFromSshExecution`)
82
+ rather than reaching for a git remote. See
83
+ [`packages/adapters/AUTHORING.md`](../AUTHORING.md#no-remote-git-contract-cross-run-persistence)
84
+ for the full contract and the pinning test at
85
+ [`packages/adapter-utils/src/ssh-fixture.test.ts`](../../adapter-utils/src/ssh-fixture.test.ts).
@@ -0,0 +1,2 @@
1
+ export declare function printOpenClawGatewayStreamEvent(raw: string, debug: boolean): void;
2
+ //# sourceMappingURL=format-event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-event.d.ts","sourceRoot":"","sources":["../../src/cli/format-event.ts"],"names":[],"mappings":"AAEA,wBAAgB,+BAA+B,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAoBjF"}
@@ -0,0 +1,20 @@
1
+ import pc from "picocolors";
2
+ export function printOpenClawGatewayStreamEvent(raw, debug) {
3
+ const line = raw.trim();
4
+ if (!line)
5
+ return;
6
+ if (!debug) {
7
+ console.log(line);
8
+ return;
9
+ }
10
+ if (line.startsWith("[openclaw-gateway:event]")) {
11
+ console.log(pc.cyan(line));
12
+ return;
13
+ }
14
+ if (line.startsWith("[openclaw-gateway]")) {
15
+ console.log(pc.blue(line));
16
+ return;
17
+ }
18
+ console.log(pc.gray(line));
19
+ }
20
+ //# sourceMappingURL=format-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-event.js","sourceRoot":"","sources":["../../src/cli/format-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,UAAU,+BAA+B,CAAC,GAAW,EAAE,KAAc;IACzE,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IACxB,IAAI,CAAC,IAAI;QAAE,OAAO;IAElB,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClB,OAAO;IACT,CAAC;IAED,IAAI,IAAI,CAAC,UAAU,CAAC,0BAA0B,CAAC,EAAE,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3B,OAAO;IACT,CAAC;IAED,IAAI,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC,EAAE,CAAC;QAC1C,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3B,OAAO;IACT,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { printOpenClawGatewayStreamEvent } from "./format-event.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { printOpenClawGatewayStreamEvent } from "./format-event.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare const type = "openclaw_gateway";
2
+ export declare const label = "OpenClaw Gateway";
3
+ export declare const models: {
4
+ id: string;
5
+ label: string;
6
+ }[];
7
+ export declare const agentConfigurationDoc = "# openclaw_gateway agent configuration\n\nAdapter: openclaw_gateway\n\nUse when:\n- You want Paperclip to invoke OpenClaw over the Gateway WebSocket protocol.\n- You want native gateway auth/connect semantics instead of HTTP /v1/responses or /hooks/*.\n\nDon't use when:\n- You only expose OpenClaw HTTP endpoints.\n- Your deployment does not permit outbound WebSocket access from the Paperclip server.\n\nCore fields:\n- url (string, required): OpenClaw gateway WebSocket URL (ws:// or wss://)\n- headers (object, optional): handshake headers; supports x-openclaw-token / x-openclaw-auth\n- authToken (string, optional): shared gateway token override\n- password (string, optional): gateway shared password, if configured\n\nGateway connect identity fields:\n- clientId (string, optional): gateway client id (default gateway-client)\n- clientMode (string, optional): gateway client mode (default backend)\n- clientVersion (string, optional): client version string\n- role (string, optional): gateway role (default operator)\n- scopes (string[] | comma string, optional): gateway scopes (default [\"operator.admin\"])\n- disableDeviceAuth (boolean, optional): disable signed device payload in connect params (default false)\n\nRequest behavior fields:\n- payloadTemplate (object, optional): additional fields merged into gateway agent params\n- workspaceRuntime (object, optional): reserved workspace runtime metadata; workspace runtime services are manually controlled from the workspace UI and are not auto-started by heartbeats\n- timeoutSec (number, optional): adapter timeout in seconds (default 120)\n- waitTimeoutMs (number, optional): agent.wait timeout override (default timeoutSec * 1000)\n- autoPairOnFirstConnect (boolean, optional): on first \"pairing required\", attempt device.pair.list/device.pair.approve via shared auth, then retry once (default true)\n- paperclipApiUrl (string, optional): absolute Paperclip base URL advertised in wake text\n- claimedApiKeyPath (string, optional): path to the claimed API key JSON file read by the agent at wake time (default ~/.openclaw/workspace/paperclip-claimed-api-key.json)\n\nSession routing fields:\n- sessionKeyStrategy (string, optional): issue (default), fixed, or run\n- sessionKey (string, optional): fixed session key when strategy=fixed (default paperclip)\n\nWake payload notes:\n- Paperclip wake context is embedded into the generated message text\n- No top-level paperclip field is sent; the gateway agent schema rejects unknown root params\n\nStandard result metadata supported:\n- meta.runtimeServices (array, optional): normalized adapter-managed runtime service reports\n- meta.previewUrl (string, optional): shorthand single preview URL\n- meta.previewUrls (string[], optional): shorthand multiple preview URLs\n";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,qBAAqB,CAAC;AACvC,eAAO,MAAM,KAAK,qBAAqB,CAAC;AAExC,eAAO,MAAM,MAAM,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAO,CAAC;AAE1D,eAAO,MAAM,qBAAqB,0uFA+CjC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ export const type = "openclaw_gateway";
2
+ export const label = "OpenClaw Gateway";
3
+ export const models = [];
4
+ export const agentConfigurationDoc = `# openclaw_gateway agent configuration
5
+
6
+ Adapter: openclaw_gateway
7
+
8
+ Use when:
9
+ - You want Paperclip to invoke OpenClaw over the Gateway WebSocket protocol.
10
+ - You want native gateway auth/connect semantics instead of HTTP /v1/responses or /hooks/*.
11
+
12
+ Don't use when:
13
+ - You only expose OpenClaw HTTP endpoints.
14
+ - Your deployment does not permit outbound WebSocket access from the Paperclip server.
15
+
16
+ Core fields:
17
+ - url (string, required): OpenClaw gateway WebSocket URL (ws:// or wss://)
18
+ - headers (object, optional): handshake headers; supports x-openclaw-token / x-openclaw-auth
19
+ - authToken (string, optional): shared gateway token override
20
+ - password (string, optional): gateway shared password, if configured
21
+
22
+ Gateway connect identity fields:
23
+ - clientId (string, optional): gateway client id (default gateway-client)
24
+ - clientMode (string, optional): gateway client mode (default backend)
25
+ - clientVersion (string, optional): client version string
26
+ - role (string, optional): gateway role (default operator)
27
+ - scopes (string[] | comma string, optional): gateway scopes (default ["operator.admin"])
28
+ - disableDeviceAuth (boolean, optional): disable signed device payload in connect params (default false)
29
+
30
+ Request behavior fields:
31
+ - payloadTemplate (object, optional): additional fields merged into gateway agent params
32
+ - workspaceRuntime (object, optional): reserved workspace runtime metadata; workspace runtime services are manually controlled from the workspace UI and are not auto-started by heartbeats
33
+ - timeoutSec (number, optional): adapter timeout in seconds (default 120)
34
+ - waitTimeoutMs (number, optional): agent.wait timeout override (default timeoutSec * 1000)
35
+ - autoPairOnFirstConnect (boolean, optional): on first "pairing required", attempt device.pair.list/device.pair.approve via shared auth, then retry once (default true)
36
+ - paperclipApiUrl (string, optional): absolute Paperclip base URL advertised in wake text
37
+ - claimedApiKeyPath (string, optional): path to the claimed API key JSON file read by the agent at wake time (default ~/.openclaw/workspace/paperclip-claimed-api-key.json)
38
+
39
+ Session routing fields:
40
+ - sessionKeyStrategy (string, optional): issue (default), fixed, or run
41
+ - sessionKey (string, optional): fixed session key when strategy=fixed (default paperclip)
42
+
43
+ Wake payload notes:
44
+ - Paperclip wake context is embedded into the generated message text
45
+ - No top-level paperclip field is sent; the gateway agent schema rejects unknown root params
46
+
47
+ Standard result metadata supported:
48
+ - meta.runtimeServices (array, optional): normalized adapter-managed runtime service reports
49
+ - meta.previewUrl (string, optional): shorthand single preview URL
50
+ - meta.previewUrls (string[], optional): shorthand multiple preview URLs
51
+ `;
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG,kBAAkB,CAAC;AACvC,MAAM,CAAC,MAAM,KAAK,GAAG,kBAAkB,CAAC;AAExC,MAAM,CAAC,MAAM,MAAM,GAAoC,EAAE,CAAC;AAE1D,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+CpC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=execute-dispatch.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-dispatch.test.d.ts","sourceRoot":"","sources":["../../src/server/execute-dispatch.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,192 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+ const websocketState = vi.hoisted(() => ({
3
+ connectionAttempts: 0,
4
+ failConnectAttempts: 0,
5
+ failAgentRequests: 0,
6
+ events: [],
7
+ messages: [],
8
+ }));
9
+ vi.mock("ws", async () => {
10
+ const { EventEmitter } = await import("node:events");
11
+ class FakeWebSocket extends EventEmitter {
12
+ static OPEN = 1;
13
+ readyState = FakeWebSocket.OPEN;
14
+ attempt;
15
+ constructor() {
16
+ super();
17
+ this.attempt = ++websocketState.connectionAttempts;
18
+ websocketState.events.push(`construct:${this.attempt}`);
19
+ queueMicrotask(() => {
20
+ if (this.attempt <= websocketState.failConnectAttempts) {
21
+ this.emit("error", new Error("ECONNREFUSED"));
22
+ return;
23
+ }
24
+ this.emit("open");
25
+ this.emit("message", JSON.stringify({
26
+ type: "event",
27
+ event: "connect.challenge",
28
+ payload: { nonce: "test-nonce" },
29
+ }));
30
+ });
31
+ }
32
+ send(payload) {
33
+ const request = JSON.parse(payload);
34
+ if (request.method === "agent")
35
+ websocketState.messages.push(request.params?.message ?? "");
36
+ websocketState.events.push(`send:${request.method}`);
37
+ if (request.method === "agent" && websocketState.failAgentRequests > 0) {
38
+ websocketState.failAgentRequests--;
39
+ queueMicrotask(() => {
40
+ this.emit("close", 1006, Buffer.from("ECONNRESET"));
41
+ });
42
+ return;
43
+ }
44
+ const responsePayload = request.method === "connect"
45
+ ? { protocol: 3 }
46
+ : { status: "ok", runId: "remote-run-1", summary: "done" };
47
+ queueMicrotask(() => {
48
+ this.emit("message", JSON.stringify({
49
+ type: "res",
50
+ id: request.id,
51
+ ok: true,
52
+ payload: responsePayload,
53
+ }));
54
+ });
55
+ }
56
+ close() { }
57
+ }
58
+ return { WebSocket: FakeWebSocket };
59
+ });
60
+ import { execute } from "./execute.js";
61
+ function createContext(input = {}) {
62
+ return {
63
+ runId: "run-1",
64
+ agent: {
65
+ id: "agent-1",
66
+ companyId: "company-1",
67
+ name: "OpenClaw Agent",
68
+ adapterType: "openclaw_gateway",
69
+ adapterConfig: {},
70
+ },
71
+ runtime: {
72
+ sessionId: null,
73
+ sessionParams: null,
74
+ sessionDisplayId: null,
75
+ taskKey: null,
76
+ },
77
+ config: {
78
+ url: "ws://127.0.0.1:18789",
79
+ disableDeviceAuth: true,
80
+ timeoutSec: 1,
81
+ },
82
+ context: {
83
+ issueId: "issue-1",
84
+ taskId: "issue-1",
85
+ wakeReason: "interaction_resolved",
86
+ },
87
+ onLog: input.onLog ?? (async () => { }),
88
+ onDispatch: input.onDispatch,
89
+ };
90
+ }
91
+ describe("openclaw_gateway execute dispatch boundary", () => {
92
+ beforeEach(() => {
93
+ websocketState.connectionAttempts = 0;
94
+ websocketState.failConnectAttempts = 0;
95
+ websocketState.failAgentRequests = 0;
96
+ websocketState.events = [];
97
+ websocketState.messages = [];
98
+ });
99
+ afterEach(() => {
100
+ vi.useRealTimers();
101
+ });
102
+ it.each([false, true])("sends conversation policy without the issue-completion workflow (resumed=%s)", async (resumed) => {
103
+ const ctx = createContext();
104
+ const directive = "Chat directive: clarify goals and hand plans off to project tasks.";
105
+ ctx.context = {
106
+ ...ctx.context,
107
+ conversationMode: true,
108
+ paperclipTaskMarkdown: directive,
109
+ paperclipTaskMarkdownCompact: directive,
110
+ paperclipWake: {
111
+ reason: "issue_commented",
112
+ issue: { id: "issue-1", workMode: "planning", status: "in_progress" },
113
+ interactionKind: "request_confirmation",
114
+ interactionStatus: "accepted",
115
+ },
116
+ };
117
+ if (resumed)
118
+ ctx.runtime.sessionId = "prior-session";
119
+ const result = await execute(ctx);
120
+ expect(result.exitCode).toBe(0);
121
+ expect(websocketState.messages).toHaveLength(1);
122
+ const prompt = websocketState.messages[0];
123
+ expect(prompt).toContain(directive);
124
+ expect(prompt).toContain("X-Paperclip-Run-Id");
125
+ expect(prompt).not.toContain("Execution contract:");
126
+ expect(prompt).not.toContain("Create child issues");
127
+ expect(prompt).not.toContain('"status":"done"');
128
+ expect(prompt).not.toContain("GET /api/issues/{issueId}/comments");
129
+ });
130
+ it("reports dispatch after transport setup and before the remote agent request", async () => {
131
+ const onDispatch = vi.fn(() => {
132
+ websocketState.events.push("dispatch");
133
+ });
134
+ const result = await execute(createContext({ onDispatch }));
135
+ expect(result).toMatchObject({ exitCode: 0 });
136
+ expect(onDispatch).toHaveBeenCalledTimes(1);
137
+ expect(websocketState.events).toEqual([
138
+ "construct:1",
139
+ "send:connect",
140
+ "dispatch",
141
+ "send:agent",
142
+ ]);
143
+ });
144
+ it("retains the continuation gate through transient connection backoff", async () => {
145
+ vi.useFakeTimers();
146
+ websocketState.failConnectAttempts = 1;
147
+ let resolveBackoff;
148
+ const backoffReached = new Promise((resolve) => {
149
+ resolveBackoff = resolve;
150
+ });
151
+ let resolveAuthorityChange;
152
+ const authorityChange = new Promise((resolve) => {
153
+ resolveAuthorityChange = resolve;
154
+ });
155
+ const onDispatch = vi.fn(resolveAuthorityChange);
156
+ const resultPromise = execute(createContext({
157
+ onDispatch,
158
+ onLog: async (_stream, chunk) => {
159
+ if (chunk.includes("transient error, retry"))
160
+ resolveBackoff();
161
+ },
162
+ }));
163
+ await backoffReached;
164
+ expect(websocketState.connectionAttempts).toBe(1);
165
+ expect(onDispatch).not.toHaveBeenCalled();
166
+ let authorityChangeSettled = false;
167
+ void authorityChange.then(() => {
168
+ authorityChangeSettled = true;
169
+ });
170
+ await vi.advanceTimersByTimeAsync(0);
171
+ expect(authorityChangeSettled).toBe(false);
172
+ await vi.advanceTimersByTimeAsync(2_000);
173
+ const result = await resultPromise;
174
+ await authorityChange;
175
+ expect(result).toMatchObject({ exitCode: 0 });
176
+ expect(websocketState.connectionAttempts).toBe(2);
177
+ expect(onDispatch).toHaveBeenCalledTimes(1);
178
+ expect(authorityChangeSettled).toBe(true);
179
+ });
180
+ it("does not retry after the remote-work boundary has been crossed", async () => {
181
+ websocketState.failAgentRequests = 1;
182
+ const onDispatch = vi.fn();
183
+ const result = await execute(createContext({ onDispatch }));
184
+ expect(result).toMatchObject({
185
+ exitCode: 1,
186
+ errorCode: "openclaw_gateway_request_failed",
187
+ });
188
+ expect(websocketState.connectionAttempts).toBe(1);
189
+ expect(onDispatch).toHaveBeenCalledTimes(1);
190
+ });
191
+ });
192
+ //# sourceMappingURL=execute-dispatch.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-dispatch.test.js","sourceRoot":"","sources":["../../src/server/execute-dispatch.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEzE,MAAM,cAAc,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACvC,kBAAkB,EAAE,CAAC;IACrB,mBAAmB,EAAE,CAAC;IACtB,iBAAiB,EAAE,CAAC;IACpB,MAAM,EAAE,EAAc;IACtB,QAAQ,EAAE,EAAc;CACzB,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;IACvB,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;IAErD,MAAM,aAAc,SAAQ,YAAY;QACtC,MAAM,CAAU,IAAI,GAAG,CAAC,CAAC;QAChB,UAAU,GAAG,a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C,sBAAsB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAE3C,MAAM,EAAE,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC;QACnC,MAAM,eAAe,CAAC;QAEtB,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;QAC9C,MAAM,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,CAAC,UAAU,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAC5C,MAAM,CAAC,sBAAsB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gEAAgE,EAAE,KAAK,IAAI,EAAE;QAC9E,cAAc,CAAC,iBAAiB,GAAG,CAAC,CAAC;QACrC,MAAM,UAAU,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAE3B,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;QAE5D,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC;YAC3B,QAAQ,EAAE,CAAC;YACX,SAAS,EAAE,iCAAiC;SAC7C,CAAC,CAAC;QACH,MAAM,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,CAAC,UAAU,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { AdapterExecutionContext, AdapterExecutionResult } from "@tickernelz/paperclip-pro-adapter-utils";
2
+ type SessionKeyStrategy = "fixed" | "issue" | "run";
3
+ export declare function resolveSessionKey(input: {
4
+ strategy: SessionKeyStrategy;
5
+ configuredSessionKey: string | null;
6
+ agentId: string | null;
7
+ runId: string;
8
+ issueId: string | null;
9
+ }): string;
10
+ export declare function resolveClaimedApiKeyPath(value: unknown): string;
11
+ export declare function buildAgentParams(input: {
12
+ payloadTemplate: Record<string, unknown>;
13
+ message: string;
14
+ sessionKey: string;
15
+ runId: string;
16
+ configuredAgentId: string | null;
17
+ waitTimeoutMs: number;
18
+ }): Record<string, unknown>;
19
+ export declare function execute(ctx: AdapterExecutionContext): Promise<AdapterExecutionResult>;
20
+ export {};
21
+ //# sourceMappingURL=execute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/server/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,sBAAsB,EAEvB,MAAM,yCAAyC,CAAC;AAiBjD,KAAK,kBAAkB,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;AA4HpD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,GAAG,MAAM,CAST;AAuLD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE/D;AAmJD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,aAAa,EAAE,MAAM,CAAC;CACvB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAmB1B;AAghBD,wBAAsB,OAAO,CAAC,GAAG,EAAE,uBAAuB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAoe3F"}