@sideboard-ai/core 0.1.262 → 0.1.263
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/{abletime-OQ4PC52L.js → abletime-6AOJI2YZ.js} +4 -4
- package/dist/{abletime-CDGINDXG.js → abletime-U75ZGDIX.js} +5 -5
- package/dist/{abletime-oauth-KX2TDFTE.js → abletime-oauth-LOAHGG4X.js} +3 -3
- package/dist/{abletime-oauth-5A5EOH2A.js → abletime-oauth-TA2YDCYX.js} +4 -4
- package/dist/{abletime-rest-UEHOBLXD.js → abletime-rest-CTA5WV26.js} +4 -4
- package/dist/{abletime-rest-PUGKYTRR.js → abletime-rest-YZPFM6IY.js} +3 -3
- package/dist/agents/claude-runner.cjs +463 -0
- package/dist/agents/claude-runner.d.cts +1 -0
- package/dist/agents/claude-runner.d.ts +1 -0
- package/dist/agents/claude-runner.js +134 -0
- package/dist/agents/cursor-runner.cjs +388 -7
- package/dist/agents/cursor-runner.js +34 -7
- package/dist/{agents-J2P4KNEY.js → agents-3TUMFSMH.js} +10 -9
- package/dist/{agents-IKVUGW5H.js → agents-6FWDRVA2.js} +4 -4
- package/dist/{app-settings-OM7H64YM.js → app-settings-MVZPM6WW.js} +1 -1
- package/dist/{app-settings-VQEUCONM.js → app-settings-RKFFUIFQ.js} +2 -2
- package/dist/{chunk-6PFZ6XO7.js → chunk-2QUQH2SZ.js} +81 -6
- package/dist/{chunk-VIC6TDYT.js → chunk-36FOBJBF.js} +76 -3
- package/dist/{chunk-ABPNIYRS.js → chunk-3H7O27X2.js} +389 -102
- package/dist/{chunk-FSZ7YYFQ.js → chunk-4ALDX5IO.js} +5 -3
- package/dist/{chunk-5OKJDCBK.js → chunk-5PK53SAP.js} +5 -5
- package/dist/{chunk-U3AOJLH3.js → chunk-5ZPT5YAV.js} +8 -6
- package/dist/{chunk-YFTO7U2A.js → chunk-6YOXQVJ7.js} +3 -3
- package/dist/{chunk-J6ONZP74.js → chunk-6YY7XPPL.js} +5 -5
- package/dist/{chunk-WV7KJH2E.js → chunk-A5SAYFJ4.js} +1 -0
- package/dist/{chunk-B6XFBNYM.js → chunk-BOMSJUXW.js} +2 -2
- package/dist/{chunk-S7VDDJ34.js → chunk-CEOTK5GZ.js} +3 -3
- package/dist/{chunk-4F7J6UWD.js → chunk-EK3KVT7I.js} +515 -139
- package/dist/{chunk-HHEKVR6C.js → chunk-F5MFNUAA.js} +40 -2
- package/dist/{chunk-KVQX62XI.js → chunk-K7B25HO4.js} +3 -3
- package/dist/{chunk-JTNY5CK4.js → chunk-L5WGAIL2.js} +46 -46
- package/dist/chunk-NYBFYFK7.js +415 -0
- package/dist/{chunk-GIZQAOHZ.js → chunk-QX6QUZVD.js} +121 -91
- package/dist/{chunk-X2OTZ36G.js → chunk-RKPBIB2U.js} +52 -52
- package/dist/{chunk-W5PWGEKS.js → chunk-T3AYRQJZ.js} +107 -77
- package/dist/{chunk-D554YCHG.js → chunk-YKYEHDMX.js} +2 -2
- package/dist/connected-teams-RU6VATCM.js +1 -1
- package/dist/{coordinator-prompt-VQHQ3RIX.js → coordinator-prompt-HZCQZ6C5.js} +6 -6
- package/dist/{coordinator-prompt-TU6656OK.js → coordinator-prompt-J7DKHOCH.js} +3 -3
- package/dist/{global-workspace-PHF2MOGW.js → global-workspace-6LDUZ2NF.js} +3 -3
- package/dist/{global-workspace-47NZVA44.js → global-workspace-TI26K25J.js} +6 -6
- package/dist/index.cjs +1712 -721
- package/dist/index.d.cts +181 -41
- package/dist/index.d.ts +181 -41
- package/dist/index.js +693 -285
- package/dist/mcp/run-stdio.cjs +10469 -9896
- package/dist/mcp/run-stdio.js +193 -168
- package/dist/{orchestrator-VLTO5JBR.js → orchestrator-4JSG7BWC.js} +5 -5
- package/dist/{orchestrator-OCG4QVA5.js → orchestrator-5YU46YNS.js} +11 -10
- package/dist/{workspaces-I7TWFTJM.js → workspaces-QJ3XIPUJ.js} +6 -6
- package/dist/{workspaces-2XTDS7N2.js → workspaces-WOQHJFRQ.js} +3 -3
- package/dist/{worktree-DDDF3WHV.js → worktree-6U2FA5LO.js} +2 -2
- package/dist/{worktree-YASFE65H.js → worktree-KQA4ON2G.js} +5 -5
- package/package.json +4 -3
- /package/dist/{chunk-LDXSAVWO.js → chunk-GWFVCCJZ.js} +0 -0
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import {
|
|
2
|
+
appDataDir
|
|
3
|
+
} from "./chunk-EHT2DRT4.js";
|
|
4
|
+
|
|
5
|
+
// src/agent-rpc/protocol.ts
|
|
6
|
+
var AGENT_RPC_PROTOCOL_VERSION = 1;
|
|
7
|
+
var AGENT_RPC_PATH = "/agent-rpc";
|
|
8
|
+
var AGENT_RPC_JOB_HOLD_MAX_MS = 12e4;
|
|
9
|
+
var AGENT_RPC_JOB_SLICE_MS = 1e4;
|
|
10
|
+
var AGENT_RPC_TOKEN_QUERY = "authToken";
|
|
11
|
+
var AGENT_RPC_NATIVE_ENV = "SIDEBOARD_AGENT_RPC_NATIVE";
|
|
12
|
+
var AGENT_RPC_URL_ENV = "SIDEBOARD_AGENT_RPC_URL";
|
|
13
|
+
var AGENT_RPC_TOKEN_ENV = "SIDEBOARD_AGENT_RPC_TOKEN";
|
|
14
|
+
var AGENT_RPC_CWD_ENV = "SIDEBOARD_AGENT_RPC_CWD";
|
|
15
|
+
var AGENT_RPC_CLAUDE_SDK_SERVER = "sideboard_rpc";
|
|
16
|
+
var RPC_PARSE_ERROR = -32700;
|
|
17
|
+
var RPC_INVALID_REQUEST = -32600;
|
|
18
|
+
var RPC_METHOD_NOT_FOUND = -32601;
|
|
19
|
+
var RPC_UNAUTHORIZED = -32001;
|
|
20
|
+
var RPC_INTERNAL_ERROR = -32603;
|
|
21
|
+
function isJsonRpcRequest(value) {
|
|
22
|
+
if (!value || typeof value !== "object") return false;
|
|
23
|
+
const rec = value;
|
|
24
|
+
if (rec.jsonrpc !== "2.0") return false;
|
|
25
|
+
if (typeof rec.method !== "string" || !rec.method.trim()) return false;
|
|
26
|
+
if (rec.id === void 0 || rec.id === null) return false;
|
|
27
|
+
if (typeof rec.id !== "string" && typeof rec.id !== "number") return false;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
function isJsonRpcNotification(value) {
|
|
31
|
+
if (!value || typeof value !== "object") return false;
|
|
32
|
+
const rec = value;
|
|
33
|
+
if (rec.jsonrpc !== "2.0") return false;
|
|
34
|
+
if (typeof rec.method !== "string" || !rec.method.trim()) return false;
|
|
35
|
+
if ("id" in rec && rec.id !== void 0) return false;
|
|
36
|
+
if ("error" in rec || "result" in rec) return false;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
function rpcError(id, code, message, data) {
|
|
40
|
+
return {
|
|
41
|
+
jsonrpc: "2.0",
|
|
42
|
+
id,
|
|
43
|
+
error: data === void 0 ? { code, message } : { code, message, data }
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function rpcResult(id, result) {
|
|
47
|
+
return { jsonrpc: "2.0", id, result };
|
|
48
|
+
}
|
|
49
|
+
function rpcNotify(method, params) {
|
|
50
|
+
return params === void 0 ? { jsonrpc: "2.0", method } : { jsonrpc: "2.0", method, params };
|
|
51
|
+
}
|
|
52
|
+
function parseRpcFrame(raw) {
|
|
53
|
+
try {
|
|
54
|
+
return JSON.parse(raw);
|
|
55
|
+
} catch {
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/agent-rpc/metadata.ts
|
|
61
|
+
import { existsSync, readFileSync, unlinkSync, writeFileSync } from "fs";
|
|
62
|
+
import { join } from "path";
|
|
63
|
+
function agentRuntimeMetadataPath() {
|
|
64
|
+
return join(appDataDir(), "agent-runtime.json");
|
|
65
|
+
}
|
|
66
|
+
function writeAgentRuntimeMetadata(meta) {
|
|
67
|
+
writeFileSync(agentRuntimeMetadataPath(), `${JSON.stringify(meta)}
|
|
68
|
+
`, {
|
|
69
|
+
encoding: "utf8",
|
|
70
|
+
mode: 384
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function readAgentRuntimeMetadata() {
|
|
74
|
+
try {
|
|
75
|
+
const raw = JSON.parse(readFileSync(agentRuntimeMetadataPath(), "utf8"));
|
|
76
|
+
if (!raw || typeof raw !== "object") return null;
|
|
77
|
+
const rec = raw;
|
|
78
|
+
if (typeof rec.runtimeId !== "string" || !rec.runtimeId.trim()) return null;
|
|
79
|
+
if (typeof rec.authToken !== "string" || !rec.authToken.trim()) return null;
|
|
80
|
+
const pid = Number(rec.pid);
|
|
81
|
+
if (!Number.isInteger(pid) || pid <= 0) return null;
|
|
82
|
+
const transports = Array.isArray(rec.transports) ? rec.transports : [];
|
|
83
|
+
const ws = transports.filter((t) => {
|
|
84
|
+
if (!t || typeof t !== "object") return false;
|
|
85
|
+
const row = t;
|
|
86
|
+
return row.kind === "websocket" && typeof row.url === "string" && Boolean(row.url.trim());
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
runtimeId: rec.runtimeId.trim(),
|
|
90
|
+
pid,
|
|
91
|
+
protocolVersion: Number(rec.protocolVersion) || AGENT_RPC_PROTOCOL_VERSION,
|
|
92
|
+
authToken: rec.authToken,
|
|
93
|
+
startedAt: Number(rec.startedAt) || 0,
|
|
94
|
+
transports: ws
|
|
95
|
+
};
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function websocketUrlFromMetadata(meta) {
|
|
101
|
+
const url = meta?.transports.find((t) => t.kind === "websocket")?.url?.trim();
|
|
102
|
+
return url || null;
|
|
103
|
+
}
|
|
104
|
+
function agentRpcConnectFromMetadata(meta = readAgentRuntimeMetadata()) {
|
|
105
|
+
if (!agentRuntimeLooksLive(meta)) return null;
|
|
106
|
+
const url = websocketUrlFromMetadata(meta);
|
|
107
|
+
const authToken = meta?.authToken;
|
|
108
|
+
if (!url || !authToken) return null;
|
|
109
|
+
return { url, authToken };
|
|
110
|
+
}
|
|
111
|
+
function pidAlive(pid) {
|
|
112
|
+
try {
|
|
113
|
+
process.kill(pid, 0);
|
|
114
|
+
return true;
|
|
115
|
+
} catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function clearAgentRuntimeMetadataIfOwned(pid = process.pid) {
|
|
120
|
+
const current = readAgentRuntimeMetadata();
|
|
121
|
+
if (!current || current.pid !== pid) return;
|
|
122
|
+
try {
|
|
123
|
+
unlinkSync(agentRuntimeMetadataPath());
|
|
124
|
+
} catch {
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function agentRuntimeLooksLive(meta = readAgentRuntimeMetadata()) {
|
|
128
|
+
if (!meta) return false;
|
|
129
|
+
return pidAlive(meta.pid);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/agent-rpc/client.ts
|
|
133
|
+
import { WebSocket } from "ws";
|
|
134
|
+
var AgentRpcClient = class {
|
|
135
|
+
ws = null;
|
|
136
|
+
pending = /* @__PURE__ */ new Map();
|
|
137
|
+
nextId = 1;
|
|
138
|
+
url;
|
|
139
|
+
authToken;
|
|
140
|
+
notifyListeners = /* @__PURE__ */ new Set();
|
|
141
|
+
constructor(opts = {}) {
|
|
142
|
+
const connect = opts.url && opts.authToken ? { url: opts.url, authToken: opts.authToken } : agentRpcConnectFromMetadata();
|
|
143
|
+
if (!connect) throw new Error("Agent RPC runtime is not running (no live agent-runtime.json)");
|
|
144
|
+
this.url = connect.url;
|
|
145
|
+
this.authToken = connect.authToken;
|
|
146
|
+
}
|
|
147
|
+
onNotify(fn) {
|
|
148
|
+
this.notifyListeners.add(fn);
|
|
149
|
+
return () => this.notifyListeners.delete(fn);
|
|
150
|
+
}
|
|
151
|
+
async call(method, params) {
|
|
152
|
+
const ws = await this.ensureSocket();
|
|
153
|
+
const id = this.nextId;
|
|
154
|
+
this.nextId += 1;
|
|
155
|
+
const key = String(id);
|
|
156
|
+
const payload = {
|
|
157
|
+
jsonrpc: "2.0",
|
|
158
|
+
id,
|
|
159
|
+
method,
|
|
160
|
+
params,
|
|
161
|
+
authToken: this.authToken
|
|
162
|
+
};
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
this.pending.set(key, { resolve, reject });
|
|
165
|
+
try {
|
|
166
|
+
ws.send(JSON.stringify(payload));
|
|
167
|
+
} catch (err) {
|
|
168
|
+
this.pending.delete(key);
|
|
169
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
socketUrl() {
|
|
174
|
+
const url = new URL(this.url);
|
|
175
|
+
url.searchParams.set(AGENT_RPC_TOKEN_QUERY, this.authToken);
|
|
176
|
+
return url.toString();
|
|
177
|
+
}
|
|
178
|
+
async ensureSocket() {
|
|
179
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN) return this.ws;
|
|
180
|
+
const ws = new WebSocket(this.socketUrl());
|
|
181
|
+
this.ws = ws;
|
|
182
|
+
ws.on("message", (data) => this.onFrame(data.toString()));
|
|
183
|
+
ws.on("error", (err) => this.drop(ws, err));
|
|
184
|
+
ws.on("close", () => this.drop(ws, new Error("Agent RPC socket closed")));
|
|
185
|
+
ws.on("unexpected-response", (_req, res) => {
|
|
186
|
+
res.resume();
|
|
187
|
+
this.drop(
|
|
188
|
+
ws,
|
|
189
|
+
new Error(
|
|
190
|
+
res.statusCode === 401 ? "Unauthorized" : `Unexpected server response: ${res.statusCode}`
|
|
191
|
+
)
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
await new Promise((resolve, reject) => {
|
|
195
|
+
const fail = (err) => {
|
|
196
|
+
const message = err.message.includes("401") ? "Unauthorized" : err.message;
|
|
197
|
+
reject(message === err.message ? err : new Error(message));
|
|
198
|
+
};
|
|
199
|
+
ws.once("unexpected-response", (_req, res) => {
|
|
200
|
+
fail(
|
|
201
|
+
new Error(
|
|
202
|
+
res.statusCode === 401 ? "Unauthorized" : `Unexpected server response: ${res.statusCode}`
|
|
203
|
+
)
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
ws.once("error", fail);
|
|
207
|
+
ws.once("open", () => {
|
|
208
|
+
ws.off("error", fail);
|
|
209
|
+
resolve();
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
return ws;
|
|
213
|
+
}
|
|
214
|
+
drop(ws, err) {
|
|
215
|
+
if (this.ws === ws) this.ws = null;
|
|
216
|
+
if (this.pending.size === 0) return;
|
|
217
|
+
this.failAll(err);
|
|
218
|
+
}
|
|
219
|
+
onFrame(raw) {
|
|
220
|
+
const parsed = parseRpcFrame(raw);
|
|
221
|
+
if (parsed === void 0) return;
|
|
222
|
+
if (isJsonRpcNotification(parsed)) {
|
|
223
|
+
for (const fn of this.notifyListeners) fn(parsed);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (!parsed || typeof parsed !== "object") return;
|
|
227
|
+
const rec = parsed;
|
|
228
|
+
if (rec.id === void 0 || rec.id === null) return;
|
|
229
|
+
const key = String(rec.id);
|
|
230
|
+
const waiter = this.pending.get(key);
|
|
231
|
+
if (!waiter) return;
|
|
232
|
+
this.pending.delete(key);
|
|
233
|
+
if (rec.error && typeof rec.error === "object") {
|
|
234
|
+
const err = rec.error;
|
|
235
|
+
waiter.reject(new Error(err.message || "Agent RPC error"));
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
waiter.resolve(rec.result);
|
|
239
|
+
}
|
|
240
|
+
failAll(err) {
|
|
241
|
+
for (const waiter of this.pending.values()) waiter.reject(err);
|
|
242
|
+
this.pending.clear();
|
|
243
|
+
}
|
|
244
|
+
close() {
|
|
245
|
+
const ws = this.ws;
|
|
246
|
+
this.ws = null;
|
|
247
|
+
this.failAll(new Error("Agent RPC client closed"));
|
|
248
|
+
if (ws) {
|
|
249
|
+
try {
|
|
250
|
+
ws.close();
|
|
251
|
+
} catch {
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// src/agent-rpc/pilot-tools.ts
|
|
258
|
+
var PILOT_TOOL_NAMES = [
|
|
259
|
+
"present_artifact",
|
|
260
|
+
"wait_for_job",
|
|
261
|
+
"stop_job"
|
|
262
|
+
];
|
|
263
|
+
var PILOT_TOOL_DESCRIPTIONS = {
|
|
264
|
+
present_artifact: "Show a document or live log in Sideboard\u2019s side column. For html/svg/markdown/react, pass the FULL document and do not also fence that same body in chat. For type=log, pass only NEW lines (same artifact_id appends). Prefer type=log for long-running job output \u2014 do not resend HTML. type=react is a single default-export component (JSX/TSX); only react/react-dom imports.",
|
|
265
|
+
wait_for_job: "Wait until a detached long job (tests, pack, deploy, connector CLI) finishes. This call stays open for up to ~2 minutes. stillRunning true means the runtime hit the max hold; call wait_for_job again immediately. If the job is hanging, producing no useful output, or doing the wrong thing, call stop_job instead. Do not end the turn or tell the user you will let them know later.",
|
|
266
|
+
stop_job: "Stop a detached job you started with detached-job.cjs when it is hanging, producing no useful output, buffering forever, or doing the wrong thing (wrong project, infinite watch, huge dump). Do not stop a pack/test/deploy that is clearly making progress."
|
|
267
|
+
};
|
|
268
|
+
var WAIT_FOR_TURN_DESCRIPTION = "Wait until the chat finishes its current/queued turn, or return early with a live progress snapshot. This call stays open for up to ~2 minutes. taskState is the A2A-style lifecycle: submitted (queued, not started), working, input-required (ask_user), completed, failed, canceled. stillRunning is true only for submitted/working. If stillRunning, text and usage are empty (they would be the previous turn) \u2014 read progress and call wait_for_turn again. Do not send_to_chat a check-in (that steers / interrupts). On failed, lastError/text is the failure. On canceled, the child did not finish \u2014 resume with send_to_chat or tell the user. On input-required, wait for the user in that chat. When finished, text is this turn\u2019s assistant reply and usage is that turn\u2019s tokens + costUsd (this turn, not the Claude session total; sessionCostUsd is the provider session total when present). lastActivityAt is the latest transcript/live stamp \u2014 present after the turn completes, not only while it is running.";
|
|
269
|
+
var WAIT_FOR_TURN_SCHEMA = {
|
|
270
|
+
type: "object",
|
|
271
|
+
properties: {
|
|
272
|
+
ref: {
|
|
273
|
+
type: "string",
|
|
274
|
+
description: "Worktree thread id or ref to wait on (not the orchestrator)"
|
|
275
|
+
},
|
|
276
|
+
timeoutMs: {
|
|
277
|
+
type: "number",
|
|
278
|
+
description: "Optional cap for this hold (ms). Ignored above the runtime max (~2 minutes)."
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
required: ["ref"]
|
|
282
|
+
};
|
|
283
|
+
var PILOT_TOOL_SCHEMAS = {
|
|
284
|
+
present_artifact: {
|
|
285
|
+
type: "object",
|
|
286
|
+
properties: {
|
|
287
|
+
title: {
|
|
288
|
+
type: "string",
|
|
289
|
+
description: "Short title shown in the artifact pane header"
|
|
290
|
+
},
|
|
291
|
+
type: {
|
|
292
|
+
type: "string",
|
|
293
|
+
enum: ["html", "svg", "markdown", "react", "log"],
|
|
294
|
+
description: "html/svg/markdown/react replace the pane. log appends content to the same artifact_id (new lines only)."
|
|
295
|
+
},
|
|
296
|
+
content: {
|
|
297
|
+
type: "string",
|
|
298
|
+
description: "html/svg/markdown/react: full document. log: only the new lines since the last call (empty is ok for a status-only update)."
|
|
299
|
+
},
|
|
300
|
+
artifact_id: {
|
|
301
|
+
type: "string",
|
|
302
|
+
description: "Stable id. Required for type=log so later calls append to the same pane."
|
|
303
|
+
},
|
|
304
|
+
status: {
|
|
305
|
+
type: "string",
|
|
306
|
+
enum: ["running", "ok", "failed", "idle"]
|
|
307
|
+
},
|
|
308
|
+
phase: { type: "string" },
|
|
309
|
+
mode: { type: "string", enum: ["append", "replace"] }
|
|
310
|
+
},
|
|
311
|
+
required: ["title", "type", "content"]
|
|
312
|
+
},
|
|
313
|
+
wait_for_job: {
|
|
314
|
+
type: "object",
|
|
315
|
+
properties: {
|
|
316
|
+
id: {
|
|
317
|
+
type: "string",
|
|
318
|
+
description: "Detached job id (same kebab-case id passed to detached-job.cjs start)"
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
required: ["id"]
|
|
322
|
+
},
|
|
323
|
+
stop_job: {
|
|
324
|
+
type: "object",
|
|
325
|
+
properties: {
|
|
326
|
+
id: {
|
|
327
|
+
type: "string",
|
|
328
|
+
description: "Detached job id (same kebab-case id passed to detached-job.cjs start)"
|
|
329
|
+
},
|
|
330
|
+
reason: { type: "string" }
|
|
331
|
+
},
|
|
332
|
+
required: ["id"]
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
function jsonToolResult(value) {
|
|
336
|
+
return JSON.stringify(value);
|
|
337
|
+
}
|
|
338
|
+
function jsonToolError(err) {
|
|
339
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
340
|
+
return jsonToolResult({ ok: false, error: message });
|
|
341
|
+
}
|
|
342
|
+
function createPilotRpcExecutors(opts) {
|
|
343
|
+
const client = new AgentRpcClient(opts.rpc);
|
|
344
|
+
let waitToolCallId;
|
|
345
|
+
if (opts.onProgress) {
|
|
346
|
+
const onProgress = opts.onProgress;
|
|
347
|
+
client.onNotify((msg) => {
|
|
348
|
+
if (msg.method === "runtime.progress") onProgress(msg.params, waitToolCallId);
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
const call = async (method, args) => {
|
|
352
|
+
try {
|
|
353
|
+
return jsonToolResult(await client.call(method, args));
|
|
354
|
+
} catch (err) {
|
|
355
|
+
return jsonToolError(err);
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
const callJob = (method, args) => call(method, { ...args, cwd: opts.cwd });
|
|
359
|
+
return {
|
|
360
|
+
present_artifact: (args) => call("ui.presentArtifact", args),
|
|
361
|
+
wait_for_job: async (args, context) => {
|
|
362
|
+
const prev = waitToolCallId;
|
|
363
|
+
waitToolCallId = typeof context?.toolCallId === "string" ? context.toolCallId : void 0;
|
|
364
|
+
try {
|
|
365
|
+
return await callJob("job.wait", args);
|
|
366
|
+
} finally {
|
|
367
|
+
waitToolCallId = prev;
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
stop_job: (args) => callJob("job.stop", args),
|
|
371
|
+
wait_for_turn: async (args, context) => {
|
|
372
|
+
const prev = waitToolCallId;
|
|
373
|
+
waitToolCallId = typeof context?.toolCallId === "string" ? context.toolCallId : void 0;
|
|
374
|
+
try {
|
|
375
|
+
return await call("turn.wait", args);
|
|
376
|
+
} finally {
|
|
377
|
+
waitToolCallId = prev;
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
close: () => client.close()
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export {
|
|
385
|
+
AGENT_RPC_PROTOCOL_VERSION,
|
|
386
|
+
AGENT_RPC_PATH,
|
|
387
|
+
AGENT_RPC_JOB_HOLD_MAX_MS,
|
|
388
|
+
AGENT_RPC_JOB_SLICE_MS,
|
|
389
|
+
AGENT_RPC_TOKEN_QUERY,
|
|
390
|
+
AGENT_RPC_NATIVE_ENV,
|
|
391
|
+
AGENT_RPC_URL_ENV,
|
|
392
|
+
AGENT_RPC_TOKEN_ENV,
|
|
393
|
+
AGENT_RPC_CWD_ENV,
|
|
394
|
+
AGENT_RPC_CLAUDE_SDK_SERVER,
|
|
395
|
+
RPC_PARSE_ERROR,
|
|
396
|
+
RPC_INVALID_REQUEST,
|
|
397
|
+
RPC_METHOD_NOT_FOUND,
|
|
398
|
+
RPC_UNAUTHORIZED,
|
|
399
|
+
RPC_INTERNAL_ERROR,
|
|
400
|
+
isJsonRpcRequest,
|
|
401
|
+
rpcError,
|
|
402
|
+
rpcResult,
|
|
403
|
+
rpcNotify,
|
|
404
|
+
parseRpcFrame,
|
|
405
|
+
writeAgentRuntimeMetadata,
|
|
406
|
+
readAgentRuntimeMetadata,
|
|
407
|
+
agentRpcConnectFromMetadata,
|
|
408
|
+
clearAgentRuntimeMetadataIfOwned,
|
|
409
|
+
PILOT_TOOL_NAMES,
|
|
410
|
+
PILOT_TOOL_DESCRIPTIONS,
|
|
411
|
+
WAIT_FOR_TURN_DESCRIPTION,
|
|
412
|
+
WAIT_FOR_TURN_SCHEMA,
|
|
413
|
+
PILOT_TOOL_SCHEMAS,
|
|
414
|
+
createPilotRpcExecutors
|
|
415
|
+
};
|