pi-roundtable 0.53.6 → 0.54.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.
- package/CHANGELOG.md +12 -0
- package/README.md +6 -2
- package/README.zh-TW.md +6 -2
- package/docs/plugins.md +199 -7
- package/package.json +3 -1
- package/runner/Dockerfile +46 -0
- package/runner/Dockerfile.dockerignore +5 -0
- package/src/cli/checks/images.ts +3 -2
- package/src/cli/checks/preset.ts +20 -0
- package/src/cli/checks/runner.ts +45 -0
- package/src/cli/doctor.ts +7 -1
- package/src/core/agents/agent-claim.ts +7 -4
- package/src/core/agents/agent-prompt.ts +11 -2
- package/src/core/agents/helper-workspace.ts +72 -0
- package/src/core/agents/team-options.ts +2 -0
- package/src/core/agents/team-prompt.ts +12 -1
- package/src/core/builtin/agent-server.ts +8 -0
- package/src/core/builtin/polls.ts +67 -0
- package/src/core/builtin/runner.ts +139 -0
- package/src/core/config/config-schema.ts +4 -0
- package/src/core/config/config.ts +49 -185
- package/src/core/config/preset.ts +51 -0
- package/src/core/config/resolve-config.ts +175 -0
- package/src/core/config/runner-config.ts +80 -0
- package/src/core/contract/polls.ts +71 -0
- package/src/core/contract/runtime.ts +12 -0
- package/src/core/contract/surface.ts +13 -0
- package/src/core/discord/discord-polls.ts +156 -0
- package/src/core/discord/discord-replies.ts +55 -0
- package/src/core/discord/discord-surface.ts +13 -43
- package/src/core/domain/errors.ts +5 -0
- package/src/core/domain/sessions.ts +8 -1
- package/src/core/host/define-roundtable.ts +8 -0
- package/src/core/host/host-registration.ts +7 -0
- package/src/core/host/host.ts +8 -0
- package/src/core/i18n/schedules.ts +2 -0
- package/src/core/modules/polls/poll-result-turns.ts +124 -0
- package/src/core/modules/polls/poll-rules.ts +108 -0
- package/src/core/modules/polls/poll-service.ts +477 -0
- package/src/core/modules/polls/poll-store.ts +336 -0
- package/src/core/modules/polls/poll-tools.ts +118 -0
- package/src/core/modules/polls/poll-turn-text.ts +60 -0
- package/src/core/plugin-api/define.ts +9 -2
- package/src/core/plugin-api/holds.ts +2 -0
- package/src/core/plugin-api/plugin.ts +8 -0
- package/src/core/runner/protocol.ts +456 -0
- package/src/core/runner/runner-client.ts +450 -0
- package/src/core/runner/runner-drivers.ts +356 -0
- package/src/core/runner/runner-files.ts +102 -0
- package/src/core/runner/runner-holds.ts +76 -0
- package/src/core/runner/runner-port.ts +77 -0
- package/src/core/runner/runner-probe.ts +53 -0
- package/src/core/runner/runner-prompt.ts +36 -0
- package/src/core/runner/runner-session.ts +131 -0
- package/src/core/runner/runner-tiers.ts +20 -0
- package/src/core/runner/runner-tools.ts +325 -0
- package/src/core/runner/settings.ts +108 -0
- package/src/core/runtime/conversation-sessions.ts +73 -15
- package/src/core/runtime/extensions/approval-card.ts +29 -2
- package/src/core/runtime/extensions/confirmation-gate.ts +24 -63
- package/src/core/runtime/extensions/gate-card.ts +105 -0
- package/src/core/runtime/extensions/yolo.ts +17 -3
- package/src/core/runtime/pi-agent-runtime.ts +37 -68
- package/src/core/runtime/runtime-plugin.ts +9 -0
- package/src/core/runtime/runtime-types.ts +29 -1
- package/src/core/runtime/session-factory.ts +59 -62
- package/src/core/runtime/session-shell.ts +43 -0
- package/src/core/runtime/session-tool-names.ts +78 -0
- package/src/core/runtime/turn-selection.ts +97 -0
- package/src/core/shared/generate-image-tool.ts +4 -4
- package/src/core/shared/poll-target.ts +14 -0
- package/src/core/shared/workspace-files.ts +42 -4
- package/src/core/testing/fake-polls.ts +131 -0
- package/src/core/testing/fake-runner.ts +146 -0
- package/src/core/testing/surface-contract-approvals.ts +215 -0
- package/src/core/testing/surface-contract-polls.ts +142 -0
- package/src/core/testing/surface-contract.ts +32 -208
- package/src/core/tool-set.snapshot.json +8 -0
- package/src/index.ts +17 -0
- package/src/kit/index.ts +6 -0
- package/src/kit/polls.ts +8 -0
- package/src/runner-server/exec.ts +174 -0
- package/src/runner-server/file-helper.ts +208 -0
- package/src/runner-server/files.ts +93 -0
- package/src/runner-server/host.ts +65 -0
- package/src/runner-server/main.ts +89 -0
- package/src/runner-server/server.ts +318 -0
- package/src/runner-server/shared-dirs.ts +45 -0
- package/src/runner-server/state.ts +293 -0
- package/src/runner-server/transports.ts +187 -0
- package/src/testing.ts +7 -0
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AccessMode,
|
|
3
|
+
encodeFrame,
|
|
4
|
+
FrameError,
|
|
5
|
+
FrameReader,
|
|
6
|
+
parseServerFrame,
|
|
7
|
+
RUNNER_PROTOCOL_VERSION,
|
|
8
|
+
type RunnerRequest,
|
|
9
|
+
type RunnerResults,
|
|
10
|
+
type RunnerStat,
|
|
11
|
+
type ServerFrame,
|
|
12
|
+
} from "./protocol.ts";
|
|
13
|
+
import {
|
|
14
|
+
type RunnerCommand,
|
|
15
|
+
RunnerError,
|
|
16
|
+
type RunnerExit,
|
|
17
|
+
type RunnerPort,
|
|
18
|
+
} from "./runner-port.ts";
|
|
19
|
+
|
|
20
|
+
/** A byte stream to the runner server, as a driver opens it. */
|
|
21
|
+
export interface RunnerStream {
|
|
22
|
+
write(text: string): void;
|
|
23
|
+
end(): void;
|
|
24
|
+
onData(listener: (chunk: Uint8Array) => void): void;
|
|
25
|
+
/** Called once, when the stream ends or fails, with what is known of why. */
|
|
26
|
+
onClose(listener: (reason?: string) => void): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** How a host reaches its runner server. */
|
|
30
|
+
export interface RunnerDriver {
|
|
31
|
+
/** What the driver reaches, for logs and `roundtable doctor`: the image or the socket. */
|
|
32
|
+
readonly target: string;
|
|
33
|
+
/**
|
|
34
|
+
* Opens a new stream and gives the token its hello carries, if any. `fresh` asks again for a
|
|
35
|
+
* token that may have changed, after the runner refused the last one.
|
|
36
|
+
*/
|
|
37
|
+
connect(fresh: boolean): Promise<{ stream: RunnerStream; token?: string }>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** How long a new stream may take to be welcomed. */
|
|
41
|
+
const HELLO_TIMEOUT_MS = 30_000;
|
|
42
|
+
|
|
43
|
+
const unreachable = (detail: string) =>
|
|
44
|
+
new RunnerError("unreachable", `the runner is not reachable: ${detail}`);
|
|
45
|
+
|
|
46
|
+
/** A request in flight: the frames that answer it go to `frame`, a broken stream to `fail`. */
|
|
47
|
+
interface Pending {
|
|
48
|
+
frame(frame: ServerFrame): void;
|
|
49
|
+
fail(error: RunnerError): void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** One open stream, welcomed by the server. */
|
|
53
|
+
class Connection {
|
|
54
|
+
readonly #stream: RunnerStream;
|
|
55
|
+
readonly #pending = new Map<number, Pending>();
|
|
56
|
+
readonly #reader = new FrameReader();
|
|
57
|
+
#nextId = 1;
|
|
58
|
+
#closed: RunnerError | undefined;
|
|
59
|
+
#greeted: Pending | undefined;
|
|
60
|
+
|
|
61
|
+
constructor(stream: RunnerStream) {
|
|
62
|
+
this.#stream = stream;
|
|
63
|
+
stream.onData((chunk) => {
|
|
64
|
+
try {
|
|
65
|
+
for (const value of this.#reader.push(chunk))
|
|
66
|
+
this.#receive(parseServerFrame(value));
|
|
67
|
+
} catch (error) {
|
|
68
|
+
const message =
|
|
69
|
+
error instanceof FrameError ? error.message : String(error);
|
|
70
|
+
this.#close(`the runner sent a bad frame (${message})`);
|
|
71
|
+
stream.end();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
stream.onClose((reason) =>
|
|
75
|
+
this.#close(reason ?? "the runner closed the connection"),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get closed(): boolean {
|
|
80
|
+
return this.#closed !== undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Says hello and waits for the welcome; rejects with the runner's refusal or a broken stream. */
|
|
84
|
+
hello(token: string | undefined): Promise<void> {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
const timer = setTimeout(() => {
|
|
87
|
+
this.#close("the runner did not answer the hello");
|
|
88
|
+
this.#stream.end();
|
|
89
|
+
}, HELLO_TIMEOUT_MS);
|
|
90
|
+
this.#greeted = {
|
|
91
|
+
frame: (frame) => {
|
|
92
|
+
clearTimeout(timer);
|
|
93
|
+
this.#greeted = undefined;
|
|
94
|
+
if (frame.type === "welcome") return resolve();
|
|
95
|
+
if (frame.type === "error")
|
|
96
|
+
return reject(new RunnerError(frame.code, frame.message));
|
|
97
|
+
reject(
|
|
98
|
+
unreachable(`the runner answered the hello with ${frame.type}`),
|
|
99
|
+
);
|
|
100
|
+
},
|
|
101
|
+
fail: (error) => {
|
|
102
|
+
clearTimeout(timer);
|
|
103
|
+
reject(error);
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
this.#send({
|
|
107
|
+
type: "hello",
|
|
108
|
+
version: RUNNER_PROTOCOL_VERSION,
|
|
109
|
+
...(token === undefined ? {} : { token }),
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Sends a request built for its id; `pending` hears every frame that answers it. */
|
|
115
|
+
request(build: (id: number) => RunnerRequest, pending: Pending): number {
|
|
116
|
+
if (this.#closed) throw this.#closed;
|
|
117
|
+
const id = this.#nextId++;
|
|
118
|
+
this.#pending.set(id, pending);
|
|
119
|
+
try {
|
|
120
|
+
this.#send(build(id));
|
|
121
|
+
} catch (error) {
|
|
122
|
+
this.#pending.delete(id);
|
|
123
|
+
throw error instanceof RunnerError
|
|
124
|
+
? error
|
|
125
|
+
: new RunnerError("failed", (error as Error).message);
|
|
126
|
+
}
|
|
127
|
+
return id;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** The request is answered: no more frames go to it. */
|
|
131
|
+
done(id: number): void {
|
|
132
|
+
this.#pending.delete(id);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
abort(id: number): void {
|
|
136
|
+
if (!this.#closed && this.#pending.has(id))
|
|
137
|
+
this.#send({ type: "abort", id });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
end(): void {
|
|
141
|
+
this.#close("the host closed the runner client");
|
|
142
|
+
this.#stream.end();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
#send(frame: object): void {
|
|
146
|
+
this.#stream.write(encodeFrame(frame));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
#receive(frame: ServerFrame): void {
|
|
150
|
+
if (this.#greeted) {
|
|
151
|
+
this.#greeted.frame(frame);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (!("id" in frame) || frame.id === undefined) {
|
|
155
|
+
// An error for no request: the server gave up on the stream.
|
|
156
|
+
const message = frame.type === "error" ? frame.message : frame.type;
|
|
157
|
+
this.#close(`the runner ended the connection (${message})`);
|
|
158
|
+
this.#stream.end();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this.#pending.get(frame.id)?.frame(frame);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
#close(reason: string): void {
|
|
165
|
+
if (this.#closed) return;
|
|
166
|
+
const error = unreachable(reason);
|
|
167
|
+
this.#closed = error;
|
|
168
|
+
this.#greeted?.fail(error);
|
|
169
|
+
this.#greeted = undefined;
|
|
170
|
+
for (const pending of this.#pending.values()) pending.fail(error);
|
|
171
|
+
this.#pending.clear();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const isObject = (value: unknown): value is Record<string, unknown> =>
|
|
176
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
177
|
+
|
|
178
|
+
function checkStat(value: unknown): RunnerStat {
|
|
179
|
+
if (
|
|
180
|
+
!isObject(value) ||
|
|
181
|
+
(value.kind !== "file" &&
|
|
182
|
+
value.kind !== "directory" &&
|
|
183
|
+
value.kind !== "other") ||
|
|
184
|
+
typeof value.size !== "number" ||
|
|
185
|
+
typeof value.mtimeMs !== "number" ||
|
|
186
|
+
typeof value.path !== "string"
|
|
187
|
+
)
|
|
188
|
+
throw new RunnerError("failed", "the runner answered stat with no stat");
|
|
189
|
+
return value as unknown as RunnerStat;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function field<T>(
|
|
193
|
+
value: unknown,
|
|
194
|
+
key: string,
|
|
195
|
+
is: (item: unknown) => item is T,
|
|
196
|
+
what: string,
|
|
197
|
+
): T {
|
|
198
|
+
const item = isObject(value) ? value[key] : undefined;
|
|
199
|
+
if (!is(item))
|
|
200
|
+
throw new RunnerError(
|
|
201
|
+
"failed",
|
|
202
|
+
`the runner answered ${what} without ${key}`,
|
|
203
|
+
);
|
|
204
|
+
return item;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const isString = (item: unknown): item is string => typeof item === "string";
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The runner protocol's client: one stream at a time, opened on the first call and again after it
|
|
211
|
+
* breaks, with any number of requests in flight on it. A call made while no runner answers fails
|
|
212
|
+
* with a `RunnerError` of code `unreachable`; the next call tries again.
|
|
213
|
+
*/
|
|
214
|
+
export class RunnerClient implements RunnerPort {
|
|
215
|
+
readonly #driver: RunnerDriver;
|
|
216
|
+
#open: Promise<Connection> | undefined;
|
|
217
|
+
#ended = false;
|
|
218
|
+
|
|
219
|
+
constructor(driver: RunnerDriver) {
|
|
220
|
+
this.#driver = driver;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
get target(): string {
|
|
224
|
+
return this.#driver.target;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** Closes the stream; a later call opens a new one. */
|
|
228
|
+
close(): void {
|
|
229
|
+
const open = this.#open;
|
|
230
|
+
this.#open = undefined;
|
|
231
|
+
void open?.then((connection) => connection.end()).catch(() => undefined);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Closes the stream for good: every later call fails. */
|
|
235
|
+
end(): void {
|
|
236
|
+
this.#ended = true;
|
|
237
|
+
this.close();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async #connection(): Promise<Connection> {
|
|
241
|
+
if (this.#ended) throw unreachable("the host is stopping");
|
|
242
|
+
const current = this.#open;
|
|
243
|
+
if (current) {
|
|
244
|
+
const connection = await current.catch(() => undefined);
|
|
245
|
+
if (connection && !connection.closed) return connection;
|
|
246
|
+
if (this.#open === current) this.#open = undefined;
|
|
247
|
+
}
|
|
248
|
+
const opening = this.#handshake(false).catch((error: unknown) =>
|
|
249
|
+
error instanceof RunnerError && error.code === "auth"
|
|
250
|
+
? this.#handshake(true)
|
|
251
|
+
: Promise.reject(error),
|
|
252
|
+
);
|
|
253
|
+
this.#open = opening;
|
|
254
|
+
opening.catch(() => {
|
|
255
|
+
if (this.#open === opening) this.#open = undefined;
|
|
256
|
+
});
|
|
257
|
+
return opening;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
async #handshake(fresh: boolean): Promise<Connection> {
|
|
261
|
+
let link: Awaited<ReturnType<RunnerDriver["connect"]>>;
|
|
262
|
+
try {
|
|
263
|
+
link = await this.#driver.connect(fresh);
|
|
264
|
+
} catch (error) {
|
|
265
|
+
throw error instanceof RunnerError
|
|
266
|
+
? error
|
|
267
|
+
: unreachable((error as Error).message ?? String(error));
|
|
268
|
+
}
|
|
269
|
+
const connection = new Connection(link.stream);
|
|
270
|
+
try {
|
|
271
|
+
await connection.hello(link.token);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
connection.end();
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
return connection;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** Sends a request and resolves with its `ok` result. */
|
|
280
|
+
async #call(build: (id: number) => RunnerRequest): Promise<unknown> {
|
|
281
|
+
const connection = await this.#connection();
|
|
282
|
+
return new Promise((resolve, reject) => {
|
|
283
|
+
const id = connection.request(build, {
|
|
284
|
+
frame: (frame) => {
|
|
285
|
+
connection.done(id);
|
|
286
|
+
if (frame.type === "ok") resolve(frame.result);
|
|
287
|
+
else if (frame.type === "error")
|
|
288
|
+
reject(new RunnerError(frame.code, frame.message));
|
|
289
|
+
else
|
|
290
|
+
reject(
|
|
291
|
+
new RunnerError("failed", `the runner answered ${frame.type}`),
|
|
292
|
+
);
|
|
293
|
+
},
|
|
294
|
+
fail: reject,
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async exec(command: RunnerCommand): Promise<RunnerExit> {
|
|
300
|
+
const { signal } = command;
|
|
301
|
+
if (signal?.aborted) throw new RunnerError("aborted", "aborted");
|
|
302
|
+
const connection = await this.#connection();
|
|
303
|
+
return new Promise((resolve, reject) => {
|
|
304
|
+
let id = 0;
|
|
305
|
+
const abort = () => connection.abort(id);
|
|
306
|
+
const finish = () => {
|
|
307
|
+
connection.done(id);
|
|
308
|
+
signal?.removeEventListener("abort", abort);
|
|
309
|
+
};
|
|
310
|
+
id = connection.request(
|
|
311
|
+
(requestId) => ({
|
|
312
|
+
type: "exec",
|
|
313
|
+
id: requestId,
|
|
314
|
+
conversation: command.conversation,
|
|
315
|
+
command: command.command,
|
|
316
|
+
cwd: command.cwd,
|
|
317
|
+
timeoutMs: command.timeoutMs,
|
|
318
|
+
maxOutputBytes: command.maxOutputBytes,
|
|
319
|
+
}),
|
|
320
|
+
{
|
|
321
|
+
frame: (frame) => {
|
|
322
|
+
if (frame.type === "data")
|
|
323
|
+
return command.onData(Buffer.from(frame.data, "base64"));
|
|
324
|
+
finish();
|
|
325
|
+
if (frame.type === "exit")
|
|
326
|
+
resolve({
|
|
327
|
+
code: frame.code,
|
|
328
|
+
cut: frame.cut,
|
|
329
|
+
timedOut: frame.timedOut,
|
|
330
|
+
});
|
|
331
|
+
else if (frame.type === "error")
|
|
332
|
+
reject(new RunnerError(frame.code, frame.message));
|
|
333
|
+
else
|
|
334
|
+
reject(
|
|
335
|
+
new RunnerError("failed", `the runner answered ${frame.type}`),
|
|
336
|
+
);
|
|
337
|
+
},
|
|
338
|
+
fail: (error) => {
|
|
339
|
+
finish();
|
|
340
|
+
reject(error);
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
);
|
|
344
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async read(
|
|
349
|
+
conversation: string,
|
|
350
|
+
path: string,
|
|
351
|
+
maxBytes: number,
|
|
352
|
+
): Promise<Buffer> {
|
|
353
|
+
const result = await this.#call((id) => ({
|
|
354
|
+
type: "read",
|
|
355
|
+
id,
|
|
356
|
+
conversation,
|
|
357
|
+
path,
|
|
358
|
+
maxBytes,
|
|
359
|
+
}));
|
|
360
|
+
return Buffer.from(field(result, "data", isString, "read"), "base64");
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
async write(
|
|
364
|
+
conversation: string,
|
|
365
|
+
path: string,
|
|
366
|
+
data: Uint8Array,
|
|
367
|
+
maxBytes: number,
|
|
368
|
+
): Promise<void> {
|
|
369
|
+
if (data.byteLength > maxBytes)
|
|
370
|
+
throw new RunnerError(
|
|
371
|
+
"too-large",
|
|
372
|
+
`the content is over ${maxBytes} bytes`,
|
|
373
|
+
);
|
|
374
|
+
await this.#call((id) => ({
|
|
375
|
+
type: "write",
|
|
376
|
+
id,
|
|
377
|
+
conversation,
|
|
378
|
+
path,
|
|
379
|
+
data: Buffer.from(data).toString("base64"),
|
|
380
|
+
maxBytes,
|
|
381
|
+
}));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
async mkdir(conversation: string, path: string): Promise<void> {
|
|
385
|
+
await this.#call((id) => ({ type: "mkdir", id, conversation, path }));
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
async access(
|
|
389
|
+
conversation: string,
|
|
390
|
+
path: string,
|
|
391
|
+
mode: AccessMode,
|
|
392
|
+
): Promise<void> {
|
|
393
|
+
await this.#call((id) => ({
|
|
394
|
+
type: "access",
|
|
395
|
+
id,
|
|
396
|
+
conversation,
|
|
397
|
+
path,
|
|
398
|
+
mode,
|
|
399
|
+
}));
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
async stat(conversation: string, path: string): Promise<RunnerStat> {
|
|
403
|
+
return checkStat(
|
|
404
|
+
await this.#call((id) => ({ type: "stat", id, conversation, path })),
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
async detectImage(
|
|
409
|
+
conversation: string,
|
|
410
|
+
path: string,
|
|
411
|
+
): Promise<string | null> {
|
|
412
|
+
const result = await this.#call((id) => ({
|
|
413
|
+
type: "detect-image",
|
|
414
|
+
id,
|
|
415
|
+
conversation,
|
|
416
|
+
path,
|
|
417
|
+
}));
|
|
418
|
+
const mimeType = isObject(result) ? result.mimeType : undefined;
|
|
419
|
+
return typeof mimeType === "string" ? mimeType : null;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
async removeWorkspace(conversation: string): Promise<boolean> {
|
|
423
|
+
const result = await this.#call((id) => ({
|
|
424
|
+
type: "remove-workspace",
|
|
425
|
+
id,
|
|
426
|
+
conversation,
|
|
427
|
+
}));
|
|
428
|
+
return isObject(result) && result.removed === true;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
async sweep(keepDays: number): Promise<string[]> {
|
|
432
|
+
const result = await this.#call((id) => ({ type: "sweep", id, keepDays }));
|
|
433
|
+
const removed = isObject(result) ? result.removed : undefined;
|
|
434
|
+
return Array.isArray(removed) ? removed.filter(isString) : [];
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
async ping(): Promise<RunnerResults["ping"]> {
|
|
438
|
+
const result = await this.#call((id) => ({ type: "ping", id }));
|
|
439
|
+
if (
|
|
440
|
+
!isObject(result) ||
|
|
441
|
+
typeof result.version !== "number" ||
|
|
442
|
+
typeof result.uptimeMs !== "number"
|
|
443
|
+
)
|
|
444
|
+
throw new RunnerError(
|
|
445
|
+
"failed",
|
|
446
|
+
"the runner answered ping without its version",
|
|
447
|
+
);
|
|
448
|
+
return { version: result.version, uptimeMs: result.uptimeMs };
|
|
449
|
+
}
|
|
450
|
+
}
|