@h-rig/cli 0.0.6-alpha.3 → 0.0.6-alpha.31
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/bin/rig.js +3562 -1125
- package/dist/src/commands/_authority-runs.js +1 -0
- package/dist/src/commands/_cli-format.js +369 -0
- package/dist/src/commands/_connection-state.js +1 -3
- package/dist/src/commands/_doctor-checks.js +13 -27
- package/dist/src/commands/_help-catalog.js +388 -0
- package/dist/src/commands/_operator-surface.js +204 -0
- package/dist/src/commands/_operator-view.js +861 -56
- package/dist/src/commands/_parsers.js +0 -2
- package/dist/src/commands/_pi-frontend.js +841 -0
- package/dist/src/commands/_pi-install.js +4 -3
- package/dist/src/commands/_pi-worker-bridge-extension.js +759 -0
- package/dist/src/commands/_policy.js +0 -2
- package/dist/src/commands/_preflight.js +32 -109
- package/dist/src/commands/_run-driver-helpers.js +0 -2
- package/dist/src/commands/_server-client.js +161 -31
- package/dist/src/commands/_snapshot-upload.js +8 -23
- package/dist/src/commands/_task-picker.js +44 -16
- package/dist/src/commands/agent.js +9 -9
- package/dist/src/commands/browser.js +4 -6
- package/dist/src/commands/connect.js +132 -25
- package/dist/src/commands/dist.js +4 -6
- package/dist/src/commands/doctor.js +13 -27
- package/dist/src/commands/github.js +10 -25
- package/dist/src/commands/inbox.js +351 -31
- package/dist/src/commands/init.js +298 -71
- package/dist/src/commands/inspect.js +10 -12
- package/dist/src/commands/inspector.js +2 -4
- package/dist/src/commands/plugin.js +81 -22
- package/dist/src/commands/profile-and-review.js +8 -10
- package/dist/src/commands/queue.js +2 -3
- package/dist/src/commands/remote.js +18 -20
- package/dist/src/commands/repo-git-harness.js +6 -8
- package/dist/src/commands/run.js +1157 -122
- package/dist/src/commands/server.js +217 -33
- package/dist/src/commands/setup.js +17 -37
- package/dist/src/commands/task-report-bug.js +5 -7
- package/dist/src/commands/task-run-driver.js +660 -73
- package/dist/src/commands/task.js +1542 -252
- package/dist/src/commands/test.js +3 -5
- package/dist/src/commands/workspace.js +4 -6
- package/dist/src/commands.js +3548 -1105
- package/dist/src/index.js +3562 -1128
- package/dist/src/launcher.js +5 -3
- package/dist/src/report-bug.js +3 -3
- package/dist/src/runner.js +5 -19
- package/package.json +6 -4
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/cli/src/commands/_server-client.ts
|
|
3
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
4
|
+
import { resolve as resolve2 } from "path";
|
|
5
|
+
|
|
6
|
+
// packages/cli/src/runner.ts
|
|
7
|
+
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
8
|
+
import { CliError } from "@rig/runtime/control-plane/errors";
|
|
9
|
+
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
10
|
+
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
11
|
+
import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
|
|
12
|
+
|
|
13
|
+
// packages/cli/src/commands/_server-client.ts
|
|
14
|
+
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
15
|
+
|
|
16
|
+
// packages/cli/src/commands/_connection-state.ts
|
|
17
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
18
|
+
import { homedir } from "os";
|
|
19
|
+
import { dirname, resolve } from "path";
|
|
20
|
+
function resolveGlobalConnectionsPath(env = process.env) {
|
|
21
|
+
const explicit = env.RIG_CONNECTIONS_FILE?.trim();
|
|
22
|
+
if (explicit)
|
|
23
|
+
return resolve(explicit);
|
|
24
|
+
const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
|
|
25
|
+
if (stateDir)
|
|
26
|
+
return resolve(stateDir, "connections.json");
|
|
27
|
+
return resolve(homedir(), ".rig", "connections.json");
|
|
28
|
+
}
|
|
29
|
+
function resolveRepoConnectionPath(projectRoot) {
|
|
30
|
+
return resolve(projectRoot, ".rig", "state", "connection.json");
|
|
31
|
+
}
|
|
32
|
+
function readJsonFile(path) {
|
|
33
|
+
if (!existsSync(path))
|
|
34
|
+
return null;
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function normalizeConnection(value) {
|
|
42
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
43
|
+
return null;
|
|
44
|
+
const record = value;
|
|
45
|
+
if (record.kind === "local")
|
|
46
|
+
return { kind: "local", mode: "auto" };
|
|
47
|
+
if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
|
|
48
|
+
const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
|
|
49
|
+
return { kind: "remote", baseUrl };
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function readGlobalConnections(options = {}) {
|
|
54
|
+
const path = resolveGlobalConnectionsPath(options.env ?? process.env);
|
|
55
|
+
const payload = readJsonFile(path);
|
|
56
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
57
|
+
return { connections: {} };
|
|
58
|
+
}
|
|
59
|
+
const rawConnections = payload.connections;
|
|
60
|
+
const connections = {};
|
|
61
|
+
if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
|
|
62
|
+
for (const [alias, raw] of Object.entries(rawConnections)) {
|
|
63
|
+
const connection = normalizeConnection(raw);
|
|
64
|
+
if (connection)
|
|
65
|
+
connections[alias] = connection;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { connections };
|
|
69
|
+
}
|
|
70
|
+
function readRepoConnection(projectRoot) {
|
|
71
|
+
const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
|
|
72
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
73
|
+
return null;
|
|
74
|
+
const record = payload;
|
|
75
|
+
const selected = typeof record.selected === "string" ? record.selected.trim() : "";
|
|
76
|
+
if (!selected)
|
|
77
|
+
return null;
|
|
78
|
+
return {
|
|
79
|
+
selected,
|
|
80
|
+
project: typeof record.project === "string" ? record.project : undefined,
|
|
81
|
+
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
85
|
+
const repo = readRepoConnection(projectRoot);
|
|
86
|
+
if (!repo)
|
|
87
|
+
return null;
|
|
88
|
+
if (repo.selected === "local")
|
|
89
|
+
return { alias: "local", connection: { kind: "local", mode: "auto" } };
|
|
90
|
+
const global = readGlobalConnections(options);
|
|
91
|
+
const connection = global.connections[repo.selected];
|
|
92
|
+
if (!connection) {
|
|
93
|
+
throw new CliError2(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
94
|
+
}
|
|
95
|
+
return { alias: repo.selected, connection };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// packages/cli/src/commands/_server-client.ts
|
|
99
|
+
var scopedGitHubBearerTokens = new Map;
|
|
100
|
+
function cleanToken(value) {
|
|
101
|
+
const trimmed = value?.trim();
|
|
102
|
+
return trimmed ? trimmed : null;
|
|
103
|
+
}
|
|
104
|
+
function readPrivateRemoteSessionToken(projectRoot) {
|
|
105
|
+
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
106
|
+
if (!existsSync2(path))
|
|
107
|
+
return null;
|
|
108
|
+
try {
|
|
109
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
110
|
+
return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
|
|
111
|
+
} catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function readGitHubBearerTokenForRemote(projectRoot) {
|
|
116
|
+
const scopedKey = resolve2(projectRoot);
|
|
117
|
+
if (scopedGitHubBearerTokens.has(scopedKey))
|
|
118
|
+
return scopedGitHubBearerTokens.get(scopedKey) ?? null;
|
|
119
|
+
const privateSession = readPrivateRemoteSessionToken(projectRoot);
|
|
120
|
+
if (privateSession)
|
|
121
|
+
return privateSession;
|
|
122
|
+
return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
123
|
+
}
|
|
124
|
+
async function ensureServerForCli(projectRoot) {
|
|
125
|
+
try {
|
|
126
|
+
const selected = resolveSelectedConnection(projectRoot);
|
|
127
|
+
if (selected?.connection.kind === "remote") {
|
|
128
|
+
return {
|
|
129
|
+
baseUrl: selected.connection.baseUrl,
|
|
130
|
+
authToken: readGitHubBearerTokenForRemote(projectRoot),
|
|
131
|
+
connectionKind: "remote"
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const connection = await ensureLocalRigServerConnection(projectRoot);
|
|
135
|
+
return {
|
|
136
|
+
baseUrl: connection.baseUrl,
|
|
137
|
+
authToken: connection.authToken,
|
|
138
|
+
connectionKind: "local"
|
|
139
|
+
};
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (error instanceof Error) {
|
|
142
|
+
throw new CliError2(error.message, 1);
|
|
143
|
+
}
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function mergeHeaders(headers, authToken) {
|
|
148
|
+
const merged = new Headers(headers);
|
|
149
|
+
if (authToken) {
|
|
150
|
+
merged.set("authorization", `Bearer ${authToken}`);
|
|
151
|
+
}
|
|
152
|
+
return merged;
|
|
153
|
+
}
|
|
154
|
+
function diagnosticMessage(payload) {
|
|
155
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
156
|
+
return null;
|
|
157
|
+
const record = payload;
|
|
158
|
+
const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
|
|
159
|
+
const messages = diagnostics.flatMap((entry) => {
|
|
160
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
161
|
+
return [];
|
|
162
|
+
const diagnostic = entry;
|
|
163
|
+
const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
|
|
164
|
+
const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
|
|
165
|
+
return message ? [`${kind}: ${message}`] : [];
|
|
166
|
+
});
|
|
167
|
+
return messages.length > 0 ? messages.join("; ") : null;
|
|
168
|
+
}
|
|
169
|
+
async function requestServerJson(context, pathname, init = {}) {
|
|
170
|
+
const server = await ensureServerForCli(context.projectRoot);
|
|
171
|
+
const response = await fetch(`${server.baseUrl}${pathname}`, {
|
|
172
|
+
...init,
|
|
173
|
+
headers: mergeHeaders(init.headers, server.authToken)
|
|
174
|
+
});
|
|
175
|
+
const text = await response.text();
|
|
176
|
+
const payload = text.trim().length > 0 ? (() => {
|
|
177
|
+
try {
|
|
178
|
+
return JSON.parse(text);
|
|
179
|
+
} catch {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
})() : null;
|
|
183
|
+
if (!response.ok) {
|
|
184
|
+
const diagnostics = diagnosticMessage(payload);
|
|
185
|
+
const detail = diagnostics ?? (text || response.statusText);
|
|
186
|
+
throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
|
|
187
|
+
}
|
|
188
|
+
return payload;
|
|
189
|
+
}
|
|
190
|
+
async function getRunPiSessionViaServer(context, runId) {
|
|
191
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi`);
|
|
192
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
193
|
+
}
|
|
194
|
+
async function getRunPiMessagesViaServer(context, runId) {
|
|
195
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/messages`);
|
|
196
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { messages: [] };
|
|
197
|
+
}
|
|
198
|
+
async function getRunPiStatusViaServer(context, runId) {
|
|
199
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/status`);
|
|
200
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
201
|
+
}
|
|
202
|
+
async function getRunPiCommandsViaServer(context, runId) {
|
|
203
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/commands`);
|
|
204
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { commands: [] };
|
|
205
|
+
}
|
|
206
|
+
async function sendRunPiPromptViaServer(context, runId, text, streamingBehavior) {
|
|
207
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/prompt`, {
|
|
208
|
+
method: "POST",
|
|
209
|
+
headers: { "content-type": "application/json" },
|
|
210
|
+
body: JSON.stringify({ text, streamingBehavior })
|
|
211
|
+
});
|
|
212
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
|
|
213
|
+
}
|
|
214
|
+
async function sendRunPiShellViaServer(context, runId, text) {
|
|
215
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/shell`, {
|
|
216
|
+
method: "POST",
|
|
217
|
+
headers: { "content-type": "application/json" },
|
|
218
|
+
body: JSON.stringify({ text })
|
|
219
|
+
});
|
|
220
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
|
|
221
|
+
}
|
|
222
|
+
async function runRunPiCommandViaServer(context, runId, text) {
|
|
223
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/commands/run`, {
|
|
224
|
+
method: "POST",
|
|
225
|
+
headers: { "content-type": "application/json" },
|
|
226
|
+
body: JSON.stringify({ text })
|
|
227
|
+
});
|
|
228
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { type: "done" };
|
|
229
|
+
}
|
|
230
|
+
async function respondRunPiExtensionUiViaServer(context, runId, requestId, valueOrCancel) {
|
|
231
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/extension-ui/respond`, {
|
|
232
|
+
method: "POST",
|
|
233
|
+
headers: { "content-type": "application/json" },
|
|
234
|
+
body: JSON.stringify({ requestId, ...valueOrCancel })
|
|
235
|
+
});
|
|
236
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
|
|
237
|
+
}
|
|
238
|
+
async function abortRunPiViaServer(context, runId) {
|
|
239
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/abort`, { method: "POST" });
|
|
240
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { aborted: true };
|
|
241
|
+
}
|
|
242
|
+
async function buildRunPiEventsWebSocketUrl(context, runId) {
|
|
243
|
+
const server = await ensureServerForCli(context.projectRoot);
|
|
244
|
+
const url = new URL(`${server.baseUrl.replace(/\/+$/, "")}/api/runs/${encodeURIComponent(runId)}/pi/events`);
|
|
245
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
246
|
+
if (server.authToken)
|
|
247
|
+
url.searchParams.set("token", server.authToken);
|
|
248
|
+
return url.toString();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// packages/cli/src/commands/_pi-worker-bridge-extension.ts
|
|
252
|
+
var TERMINAL_RUN_STATUSES = new Set(["completed", "failed", "stopped", "cancelled", "canceled", "closed", "merged", "needs_attention", "needs-attention"]);
|
|
253
|
+
var MAX_TRANSCRIPT_LINES = 120;
|
|
254
|
+
function recordOf(value) {
|
|
255
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
256
|
+
}
|
|
257
|
+
function asText(value) {
|
|
258
|
+
if (typeof value === "string")
|
|
259
|
+
return value;
|
|
260
|
+
if (value === null || value === undefined)
|
|
261
|
+
return "";
|
|
262
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
263
|
+
return String(value);
|
|
264
|
+
try {
|
|
265
|
+
return JSON.stringify(value);
|
|
266
|
+
} catch {
|
|
267
|
+
return String(value);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function textFromContent(content) {
|
|
271
|
+
if (typeof content === "string")
|
|
272
|
+
return content;
|
|
273
|
+
if (!Array.isArray(content))
|
|
274
|
+
return asText(content);
|
|
275
|
+
return content.flatMap((part) => {
|
|
276
|
+
const item = recordOf(part);
|
|
277
|
+
if (!item)
|
|
278
|
+
return [];
|
|
279
|
+
if (typeof item.text === "string")
|
|
280
|
+
return [item.text];
|
|
281
|
+
if (typeof item.content === "string")
|
|
282
|
+
return [item.content];
|
|
283
|
+
if (item.type === "toolCall")
|
|
284
|
+
return [`\u23FA ${String(item.name ?? "tool")} ${asText(item.arguments ?? "")}`.trim()];
|
|
285
|
+
if (item.type === "toolResult")
|
|
286
|
+
return [`\u21B3 ${asText(item.content ?? item.result ?? "")}`.trim()];
|
|
287
|
+
return [];
|
|
288
|
+
}).join(`
|
|
289
|
+
`);
|
|
290
|
+
}
|
|
291
|
+
function appendTranscript(state, label, text) {
|
|
292
|
+
const trimmed = text.trimEnd();
|
|
293
|
+
if (!trimmed)
|
|
294
|
+
return;
|
|
295
|
+
const lines = trimmed.split(/\r?\n/);
|
|
296
|
+
state.transcript.push(`${label}: ${lines[0] ?? ""}`);
|
|
297
|
+
for (const line of lines.slice(1))
|
|
298
|
+
state.transcript.push(` ${line}`);
|
|
299
|
+
if (state.transcript.length > MAX_TRANSCRIPT_LINES) {
|
|
300
|
+
state.transcript.splice(0, state.transcript.length - MAX_TRANSCRIPT_LINES);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function nativePiUi(ctx) {
|
|
304
|
+
const ui = ctx.ui;
|
|
305
|
+
return typeof ui.emitSessionEvent === "function" && typeof ui.appendSessionMessages === "function" ? ui : null;
|
|
306
|
+
}
|
|
307
|
+
function syncNativeDisplayCwd(ctx, state) {
|
|
308
|
+
const ui = nativePiUi(ctx);
|
|
309
|
+
if (ui?.setDisplayCwd && state.cwd)
|
|
310
|
+
ui.setDisplayCwd(state.cwd);
|
|
311
|
+
}
|
|
312
|
+
function parseExtensionUiRequest(value) {
|
|
313
|
+
const request = recordOf(value) ?? {};
|
|
314
|
+
const requestId = String(request.requestId ?? request.id ?? `ui-${Date.now()}`);
|
|
315
|
+
const method = String(request.method ?? request.type ?? "input");
|
|
316
|
+
const prompt = asText(request.prompt ?? request.message ?? request.title ?? method);
|
|
317
|
+
const rawOptions = Array.isArray(request.options) ? request.options : Array.isArray(request.items) ? request.items : [];
|
|
318
|
+
const options = rawOptions.map((option) => {
|
|
319
|
+
const record = recordOf(option);
|
|
320
|
+
return record ? asText(record.label ?? record.value ?? record.name ?? option) : asText(option);
|
|
321
|
+
}).filter(Boolean);
|
|
322
|
+
return { requestId, method, prompt, options };
|
|
323
|
+
}
|
|
324
|
+
function renderBridgeWidget(state) {
|
|
325
|
+
const statusParts = [
|
|
326
|
+
state.wsConnected ? "live WS" : "WS pending",
|
|
327
|
+
state.status,
|
|
328
|
+
state.model,
|
|
329
|
+
state.cwd
|
|
330
|
+
].filter(Boolean);
|
|
331
|
+
const lines = [`Worker Pi daemon bridge \xB7 ${statusParts.join(" \xB7 ")}`];
|
|
332
|
+
if (state.activity)
|
|
333
|
+
lines.push(state.activity);
|
|
334
|
+
if (state.commands.length > 0) {
|
|
335
|
+
lines.push(`Worker commands: ${state.commands.slice(0, 10).join(", ")}${state.commands.length > 10 ? ", \u2026" : ""}`);
|
|
336
|
+
}
|
|
337
|
+
lines.push("");
|
|
338
|
+
if (state.transcript.length > 0) {
|
|
339
|
+
lines.push(...state.transcript.slice(-MAX_TRANSCRIPT_LINES));
|
|
340
|
+
} else {
|
|
341
|
+
lines.push("Waiting for worker Pi daemon transcript\u2026");
|
|
342
|
+
}
|
|
343
|
+
if (state.pendingUi) {
|
|
344
|
+
lines.push("");
|
|
345
|
+
lines.push(`Extension UI request \xB7 ${state.pendingUi.method}`);
|
|
346
|
+
lines.push(state.pendingUi.prompt);
|
|
347
|
+
state.pendingUi.options.forEach((option, index) => lines.push(`${index + 1}. ${option}`));
|
|
348
|
+
lines.push("Reply in the Pi editor. /cancel cancels this request.");
|
|
349
|
+
}
|
|
350
|
+
return lines;
|
|
351
|
+
}
|
|
352
|
+
function updatePiUi(ctx, state) {
|
|
353
|
+
ctx.ui.setTitle("Pi \xB7 Rig worker daemon");
|
|
354
|
+
ctx.ui.setStatus("rig-worker-pi", state.wsConnected ? "worker Pi WS live" : state.status);
|
|
355
|
+
syncNativeDisplayCwd(ctx, state);
|
|
356
|
+
if (state.nativeStream && nativePiUi(ctx)) {
|
|
357
|
+
ctx.ui.setWidget("rig-worker-pi-transcript", undefined);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
ctx.ui.setWorkingVisible(false);
|
|
361
|
+
ctx.ui.setWidget("rig-worker-pi-transcript", [`Worker Pi daemon bridge \xB7 degraded widget transcript`, ...renderBridgeWidget(state)], { placement: "aboveEditor" });
|
|
362
|
+
}
|
|
363
|
+
function applyStatus(state, payload) {
|
|
364
|
+
const status = recordOf(payload.status) ?? payload;
|
|
365
|
+
state.streaming = status.isStreaming === true || status.isCompacting === true || status.isBashRunning === true;
|
|
366
|
+
state.cwd = typeof status.cwd === "string" ? status.cwd : state.cwd;
|
|
367
|
+
state.model = typeof status.model === "string" ? status.model : state.model;
|
|
368
|
+
const pending = typeof status.pendingMessageCount === "number" ? status.pendingMessageCount : 0;
|
|
369
|
+
state.status = `${state.streaming ? "streaming" : "idle"}${pending ? ` \xB7 ${pending} queued` : ""}`;
|
|
370
|
+
}
|
|
371
|
+
function applyMessage(state, message) {
|
|
372
|
+
const record = recordOf(message);
|
|
373
|
+
if (!record)
|
|
374
|
+
return;
|
|
375
|
+
const role = String(record.role ?? "system");
|
|
376
|
+
const label = role === "assistant" ? "Pi" : role === "user" ? "You" : role === "tool" || role === "toolResult" ? "Tool" : "System";
|
|
377
|
+
appendTranscript(state, label, textFromContent(record.content ?? record.message ?? record.text ?? ""));
|
|
378
|
+
}
|
|
379
|
+
function applyPiEvent(ctx, state, eventValue) {
|
|
380
|
+
const event = recordOf(eventValue);
|
|
381
|
+
if (!event)
|
|
382
|
+
return;
|
|
383
|
+
const type = String(event.type ?? "event");
|
|
384
|
+
if (type === "agent_start") {
|
|
385
|
+
state.streaming = true;
|
|
386
|
+
state.status = "streaming";
|
|
387
|
+
} else if (type === "agent_end") {
|
|
388
|
+
state.streaming = false;
|
|
389
|
+
state.status = "idle";
|
|
390
|
+
} else if (type === "queue_update") {
|
|
391
|
+
const steering = Array.isArray(event.steering) ? event.steering.length : 0;
|
|
392
|
+
const followUp = Array.isArray(event.followUp) ? event.followUp.length : 0;
|
|
393
|
+
state.status = `queued \xB7 steer ${steering} \xB7 follow-up ${followUp}`;
|
|
394
|
+
}
|
|
395
|
+
const native = nativePiUi(ctx);
|
|
396
|
+
if (state.nativeStream && native?.emitSessionEvent) {
|
|
397
|
+
native.emitSessionEvent(eventValue);
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (type === "agent_end") {
|
|
401
|
+
appendTranscript(state, "System", "Agent turn complete.");
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
if (type === "message_start" || type === "message_end" || type === "turn_end") {
|
|
405
|
+
applyMessage(state, event.message);
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (type === "message_update") {
|
|
409
|
+
const assistantEvent = recordOf(event.assistantMessageEvent);
|
|
410
|
+
const delta = typeof assistantEvent?.delta === "string" ? assistantEvent.delta : typeof assistantEvent?.text === "string" ? assistantEvent.text : "";
|
|
411
|
+
if (delta)
|
|
412
|
+
appendTranscript(state, assistantEvent?.type === "thinking_delta" ? "Thinking" : "Pi", delta);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (type === "tool_execution_start") {
|
|
416
|
+
appendTranscript(state, "Tool", `${String(event.toolName ?? "tool")} ${asText(event.args ?? "")}`.trim());
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
if (type === "tool_execution_update") {
|
|
420
|
+
appendTranscript(state, "Tool", asText(event.partialResult ?? ""));
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
if (type === "tool_execution_end") {
|
|
424
|
+
appendTranscript(state, event.isError === true ? "Error" : "Tool", asText(event.result ?? `${String(event.toolName ?? "tool")} complete`));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
function firstPendingShell(state) {
|
|
428
|
+
return state.pendingShells[0];
|
|
429
|
+
}
|
|
430
|
+
function finishPendingShell(state, shell, result) {
|
|
431
|
+
const index = state.pendingShells.indexOf(shell);
|
|
432
|
+
if (index !== -1)
|
|
433
|
+
state.pendingShells.splice(index, 1);
|
|
434
|
+
shell.resolve(result);
|
|
435
|
+
}
|
|
436
|
+
function failPendingShell(state, shell, error) {
|
|
437
|
+
const index = state.pendingShells.indexOf(shell);
|
|
438
|
+
if (index !== -1)
|
|
439
|
+
state.pendingShells.splice(index, 1);
|
|
440
|
+
shell.reject(error);
|
|
441
|
+
}
|
|
442
|
+
function applyUiEvent(state, value) {
|
|
443
|
+
const event = recordOf(value);
|
|
444
|
+
if (!event)
|
|
445
|
+
return;
|
|
446
|
+
const type = String(event.type ?? "ui");
|
|
447
|
+
if (type === "shell.chunk") {
|
|
448
|
+
const pending = firstPendingShell(state);
|
|
449
|
+
const chunk = asText(event.chunk);
|
|
450
|
+
if (pending) {
|
|
451
|
+
pending.sawChunk = true;
|
|
452
|
+
pending.onData(Buffer.from(chunk));
|
|
453
|
+
} else {
|
|
454
|
+
appendTranscript(state, "Tool", chunk);
|
|
455
|
+
}
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (type === "shell.end") {
|
|
459
|
+
const pending = firstPendingShell(state);
|
|
460
|
+
const output = asText(event.output ?? "");
|
|
461
|
+
const exitCode = typeof event.exitCode === "number" ? event.exitCode : event.isError === true ? 1 : 0;
|
|
462
|
+
if (pending) {
|
|
463
|
+
if (output && !pending.sawChunk)
|
|
464
|
+
pending.onData(Buffer.from(output));
|
|
465
|
+
finishPendingShell(state, pending, { exitCode });
|
|
466
|
+
} else {
|
|
467
|
+
appendTranscript(state, event.isError === true ? "Error" : "Tool", output || `exit ${String(exitCode)}`);
|
|
468
|
+
}
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
if (type === "shell.start") {
|
|
472
|
+
if (!firstPendingShell(state))
|
|
473
|
+
appendTranscript(state, "Tool", `$ ${asText(event.command)}`);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
appendTranscript(state, "System", `${type}: ${asText(event)}`);
|
|
477
|
+
}
|
|
478
|
+
function applyEnvelope(ctx, state, envelopeValue) {
|
|
479
|
+
const envelope = recordOf(envelopeValue);
|
|
480
|
+
if (!envelope)
|
|
481
|
+
return;
|
|
482
|
+
const type = String(envelope.type ?? "");
|
|
483
|
+
if (type === "ready") {
|
|
484
|
+
const metadata = recordOf(envelope.metadata);
|
|
485
|
+
state.cwd = typeof metadata?.cwd === "string" ? metadata.cwd : state.cwd;
|
|
486
|
+
state.status = "worker Pi daemon ready";
|
|
487
|
+
if (!state.nativeStream)
|
|
488
|
+
appendTranscript(state, "System", "Connected to worker Pi daemon.");
|
|
489
|
+
} else if (type === "status.update") {
|
|
490
|
+
applyStatus(state, envelope);
|
|
491
|
+
} else if (type === "activity.update") {
|
|
492
|
+
const activity = recordOf(envelope.activity);
|
|
493
|
+
state.activity = [activity?.label, activity?.detail].map(asText).filter(Boolean).join(" \u2014 ");
|
|
494
|
+
} else if (type === "extension_ui_request") {
|
|
495
|
+
state.pendingUi = parseExtensionUiRequest(envelope.request);
|
|
496
|
+
appendTranscript(state, "System", `Extension UI request: ${state.pendingUi.prompt}`);
|
|
497
|
+
} else if (type === "pi.ui_event") {
|
|
498
|
+
applyUiEvent(state, envelope.event);
|
|
499
|
+
} else if (type === "pi.event") {
|
|
500
|
+
applyPiEvent(ctx, state, envelope.event);
|
|
501
|
+
} else if (type === "error") {
|
|
502
|
+
appendTranscript(state, "Error", asText(envelope.message ?? envelope.detail ?? "unknown error"));
|
|
503
|
+
}
|
|
504
|
+
syncNativeDisplayCwd(ctx, state);
|
|
505
|
+
}
|
|
506
|
+
async function waitForWorkerReady(options, ctx, state) {
|
|
507
|
+
while (true) {
|
|
508
|
+
const session = await getRunPiSessionViaServer(options.context, options.runId).catch((error) => ({
|
|
509
|
+
ready: false,
|
|
510
|
+
status: error instanceof Error ? error.message : String(error),
|
|
511
|
+
retryAfterMs: 1000
|
|
512
|
+
}));
|
|
513
|
+
if (session.ready === false) {
|
|
514
|
+
const status = String(session.status ?? "starting");
|
|
515
|
+
state.status = `waiting for worker Pi daemon \xB7 ${status}`;
|
|
516
|
+
updatePiUi(ctx, state);
|
|
517
|
+
if (TERMINAL_RUN_STATUSES.has(status.toLowerCase())) {
|
|
518
|
+
appendTranscript(state, "Error", `Run ended before worker Pi daemon became ready: ${status}`);
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
await Bun.sleep(typeof session.retryAfterMs === "number" ? session.retryAfterMs : 750);
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
const sessionRecord = recordOf(session) ?? {};
|
|
525
|
+
applyEnvelope(ctx, state, { type: "ready", metadata: sessionRecord.metadata ?? sessionRecord });
|
|
526
|
+
updatePiUi(ctx, state);
|
|
527
|
+
return true;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
function parseWsPayload(message) {
|
|
531
|
+
if (typeof message.data === "string")
|
|
532
|
+
return JSON.parse(message.data);
|
|
533
|
+
return JSON.parse(Buffer.from(message.data).toString("utf8"));
|
|
534
|
+
}
|
|
535
|
+
async function connectWorkerStream(options, ctx, state) {
|
|
536
|
+
const ready = await waitForWorkerReady(options, ctx, state);
|
|
537
|
+
if (!ready)
|
|
538
|
+
return;
|
|
539
|
+
let catchupDone = false;
|
|
540
|
+
const buffered = [];
|
|
541
|
+
const wsUrl = await buildRunPiEventsWebSocketUrl(options.context, options.runId);
|
|
542
|
+
const socket = new WebSocket(wsUrl);
|
|
543
|
+
const closePromise = new Promise((resolve3) => {
|
|
544
|
+
socket.onopen = () => {
|
|
545
|
+
state.wsConnected = true;
|
|
546
|
+
state.status = "live worker Pi WebSocket connected";
|
|
547
|
+
updatePiUi(ctx, state);
|
|
548
|
+
};
|
|
549
|
+
socket.onmessage = (message) => {
|
|
550
|
+
try {
|
|
551
|
+
const payload = parseWsPayload(message);
|
|
552
|
+
if (!catchupDone)
|
|
553
|
+
buffered.push(payload);
|
|
554
|
+
else {
|
|
555
|
+
applyEnvelope(ctx, state, payload);
|
|
556
|
+
updatePiUi(ctx, state);
|
|
557
|
+
}
|
|
558
|
+
} catch (error) {
|
|
559
|
+
appendTranscript(state, "Error", `Unparseable worker Pi event: ${error instanceof Error ? error.message : String(error)}`);
|
|
560
|
+
updatePiUi(ctx, state);
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
socket.onerror = () => socket.close();
|
|
564
|
+
socket.onclose = () => {
|
|
565
|
+
state.wsConnected = false;
|
|
566
|
+
state.status = "worker Pi WebSocket disconnected";
|
|
567
|
+
updatePiUi(ctx, state);
|
|
568
|
+
resolve3();
|
|
569
|
+
};
|
|
570
|
+
});
|
|
571
|
+
try {
|
|
572
|
+
const [messagesPayload, statusPayload, commandsPayload] = await Promise.all([
|
|
573
|
+
getRunPiMessagesViaServer(options.context, options.runId),
|
|
574
|
+
getRunPiStatusViaServer(options.context, options.runId),
|
|
575
|
+
getRunPiCommandsViaServer(options.context, options.runId)
|
|
576
|
+
]);
|
|
577
|
+
const messages = Array.isArray(messagesPayload.messages) ? messagesPayload.messages : [];
|
|
578
|
+
const native = nativePiUi(ctx);
|
|
579
|
+
if (state.nativeStream && native?.appendSessionMessages)
|
|
580
|
+
native.appendSessionMessages(messages);
|
|
581
|
+
else
|
|
582
|
+
for (const message of messages)
|
|
583
|
+
applyMessage(state, message);
|
|
584
|
+
applyStatus(state, statusPayload);
|
|
585
|
+
const commands = Array.isArray(commandsPayload.commands) ? commandsPayload.commands : [];
|
|
586
|
+
state.commands = commands.flatMap((command) => {
|
|
587
|
+
const record = recordOf(command);
|
|
588
|
+
return typeof record?.name === "string" ? [`/${record.name}`] : [];
|
|
589
|
+
});
|
|
590
|
+
catchupDone = true;
|
|
591
|
+
for (const payload of buffered.splice(0))
|
|
592
|
+
applyEnvelope(ctx, state, payload);
|
|
593
|
+
updatePiUi(ctx, state);
|
|
594
|
+
} catch (error) {
|
|
595
|
+
appendTranscript(state, "Error", `Worker Pi catch-up failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
596
|
+
catchupDone = true;
|
|
597
|
+
updatePiUi(ctx, state);
|
|
598
|
+
}
|
|
599
|
+
await closePromise;
|
|
600
|
+
}
|
|
601
|
+
function createRemoteBashOperations(options, state, excludeFromContext) {
|
|
602
|
+
return {
|
|
603
|
+
exec(command, _cwd, execOptions) {
|
|
604
|
+
return new Promise((resolve3, reject) => {
|
|
605
|
+
const pending = {
|
|
606
|
+
command,
|
|
607
|
+
onData: execOptions.onData,
|
|
608
|
+
resolve: resolve3,
|
|
609
|
+
reject,
|
|
610
|
+
sawChunk: false
|
|
611
|
+
};
|
|
612
|
+
const cleanup = () => {
|
|
613
|
+
execOptions.signal?.removeEventListener("abort", onAbort);
|
|
614
|
+
if (timer)
|
|
615
|
+
clearTimeout(timer);
|
|
616
|
+
};
|
|
617
|
+
const onAbort = () => {
|
|
618
|
+
cleanup();
|
|
619
|
+
failPendingShell(state, pending, new Error("Remote worker shell command aborted locally."));
|
|
620
|
+
};
|
|
621
|
+
const timeoutMs = typeof execOptions.timeout === "number" && execOptions.timeout > 0 ? execOptions.timeout : 0;
|
|
622
|
+
const timer = timeoutMs > 0 ? setTimeout(() => {
|
|
623
|
+
cleanup();
|
|
624
|
+
failPendingShell(state, pending, new Error(`Remote worker shell command timed out after ${timeoutMs}ms.`));
|
|
625
|
+
}, timeoutMs) : null;
|
|
626
|
+
const wrappedResolve = pending.resolve;
|
|
627
|
+
const wrappedReject = pending.reject;
|
|
628
|
+
pending.resolve = (result) => {
|
|
629
|
+
cleanup();
|
|
630
|
+
wrappedResolve(result);
|
|
631
|
+
};
|
|
632
|
+
pending.reject = (error) => {
|
|
633
|
+
cleanup();
|
|
634
|
+
wrappedReject(error);
|
|
635
|
+
};
|
|
636
|
+
execOptions.signal?.addEventListener("abort", onAbort, { once: true });
|
|
637
|
+
state.pendingShells.push(pending);
|
|
638
|
+
sendRunPiShellViaServer(options.context, options.runId, `${excludeFromContext ? "!!" : "!"}${command}`).catch((error) => {
|
|
639
|
+
cleanup();
|
|
640
|
+
failPendingShell(state, pending, error instanceof Error ? error : new Error(String(error)));
|
|
641
|
+
});
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
async function answerPendingUi(options, state, line) {
|
|
647
|
+
const pending = state.pendingUi;
|
|
648
|
+
if (!pending)
|
|
649
|
+
return false;
|
|
650
|
+
if (line === "/cancel") {
|
|
651
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, pending.requestId, { cancelled: true });
|
|
652
|
+
} else if (pending.method === "confirm") {
|
|
653
|
+
const confirmed = /^(y|yes|true|1)$/i.test(line);
|
|
654
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, pending.requestId, { value: confirmed, confirmed });
|
|
655
|
+
} else if (pending.options.length > 0 && /^\d+$/.test(line)) {
|
|
656
|
+
const selected = pending.options[Math.max(0, Number(line) - 1)] ?? line;
|
|
657
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, pending.requestId, { value: selected });
|
|
658
|
+
} else {
|
|
659
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, pending.requestId, { value: line });
|
|
660
|
+
}
|
|
661
|
+
appendTranscript(state, "System", `Responded to extension UI request ${pending.requestId}.`);
|
|
662
|
+
state.pendingUi = null;
|
|
663
|
+
return true;
|
|
664
|
+
}
|
|
665
|
+
async function routeInput(options, ctx, state, line) {
|
|
666
|
+
const text = line.trim();
|
|
667
|
+
if (!text)
|
|
668
|
+
return;
|
|
669
|
+
if (await answerPendingUi(options, state, text)) {
|
|
670
|
+
updatePiUi(ctx, state);
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
if (text === "/detach" || text === "/quit" || text === "/q") {
|
|
674
|
+
appendTranscript(state, "System", "Detached locally; worker Pi daemon continues.");
|
|
675
|
+
updatePiUi(ctx, state);
|
|
676
|
+
ctx.shutdown();
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
if (text === "/stop") {
|
|
680
|
+
await abortRunPiViaServer(options.context, options.runId);
|
|
681
|
+
appendTranscript(state, "System", "Stop requested for worker Pi daemon.");
|
|
682
|
+
updatePiUi(ctx, state);
|
|
683
|
+
ctx.shutdown();
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
if (text.startsWith("!")) {
|
|
687
|
+
appendTranscript(state, "You", text);
|
|
688
|
+
await sendRunPiShellViaServer(options.context, options.runId, text);
|
|
689
|
+
} else if (text.startsWith("/")) {
|
|
690
|
+
appendTranscript(state, "You", text);
|
|
691
|
+
const result = await runRunPiCommandViaServer(options.context, options.runId, text);
|
|
692
|
+
const message = typeof result.message === "string" ? result.message : "worker command accepted";
|
|
693
|
+
appendTranscript(state, "System", message);
|
|
694
|
+
} else {
|
|
695
|
+
appendTranscript(state, "You", text);
|
|
696
|
+
await sendRunPiPromptViaServer(options.context, options.runId, text, state.streaming ? "steer" : undefined);
|
|
697
|
+
}
|
|
698
|
+
updatePiUi(ctx, state);
|
|
699
|
+
}
|
|
700
|
+
function createRigWorkerPiBridgeExtension(options) {
|
|
701
|
+
return (pi) => {
|
|
702
|
+
const state = {
|
|
703
|
+
transcript: [],
|
|
704
|
+
status: "starting worker Pi daemon bridge",
|
|
705
|
+
activity: "",
|
|
706
|
+
cwd: "",
|
|
707
|
+
model: "",
|
|
708
|
+
commands: [],
|
|
709
|
+
streaming: false,
|
|
710
|
+
pendingUi: null,
|
|
711
|
+
pendingShells: [],
|
|
712
|
+
wsConnected: false,
|
|
713
|
+
nativeStream: false
|
|
714
|
+
};
|
|
715
|
+
if (options.initialMessageSent)
|
|
716
|
+
appendTranscript(state, "System", "Initial message sent to worker Pi daemon.");
|
|
717
|
+
let nativePiUiContextAvailable = false;
|
|
718
|
+
pi.on("user_bash", (event) => {
|
|
719
|
+
state.nativeStream = Boolean(state.nativeStream || nativePiUiContextAvailable);
|
|
720
|
+
return { operations: createRemoteBashOperations(options, state, event.excludeFromContext === true) };
|
|
721
|
+
});
|
|
722
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
723
|
+
nativePiUiContextAvailable = Boolean(nativePiUi(ctx));
|
|
724
|
+
state.nativeStream = nativePiUiContextAvailable;
|
|
725
|
+
updatePiUi(ctx, state);
|
|
726
|
+
ctx.ui.notify(nativePiUiContextAvailable ? "Rig worker Pi native stream bridge loaded" : "Rig worker Pi bridge extension loaded (degraded widget fallback)", "info");
|
|
727
|
+
ctx.ui.onTerminalInput((data) => {
|
|
728
|
+
if (data.includes("\x04")) {
|
|
729
|
+
ctx.shutdown();
|
|
730
|
+
return { consume: true };
|
|
731
|
+
}
|
|
732
|
+
if (!data.includes("\r") && !data.includes(`
|
|
733
|
+
`))
|
|
734
|
+
return;
|
|
735
|
+
const inlineText = data.replace(/[\r\n]+/g, "").trim();
|
|
736
|
+
const editorText = ctx.ui.getEditorText().trim();
|
|
737
|
+
const text = [editorText, inlineText].filter(Boolean).join(" ").trim();
|
|
738
|
+
if (!text)
|
|
739
|
+
return;
|
|
740
|
+
if (text.startsWith("!"))
|
|
741
|
+
return;
|
|
742
|
+
ctx.ui.setEditorText("");
|
|
743
|
+
routeInput(options, ctx, state, text).catch((error) => {
|
|
744
|
+
appendTranscript(state, "Error", error instanceof Error ? error.message : String(error));
|
|
745
|
+
updatePiUi(ctx, state);
|
|
746
|
+
});
|
|
747
|
+
return { consume: true };
|
|
748
|
+
});
|
|
749
|
+
connectWorkerStream(options, ctx, state).catch((error) => {
|
|
750
|
+
appendTranscript(state, "Error", error instanceof Error ? error.message : String(error));
|
|
751
|
+
updatePiUi(ctx, state);
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
pi.on("session_shutdown", () => {});
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
export {
|
|
758
|
+
createRigWorkerPiBridgeExtension
|
|
759
|
+
};
|