@plimsollmark/client 0.24.0 → 0.25.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/README.md +16 -2
- package/dist/client.d.ts +43 -1
- package/dist/client.js +36 -1
- package/dist/sandboxes.d.ts +1 -16
- package/dist/sandboxes.js +14 -119
- package/dist/wire.d.ts +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -177,8 +177,22 @@ exists, and `freshSandbox` whenever the call is the first answered one in a newl
|
|
|
177
177
|
sandbox, so no earlier file is there either. That covers a sandbox that `dispose`, the
|
|
178
178
|
idle close or a session cap (below) let go, one that ended by itself (its lifetime, its disk
|
|
179
179
|
budget), and a conversation resumed in another process, which this instance cannot tell
|
|
180
|
-
from a first call. A call without a key (no thread, no run)
|
|
181
|
-
shared across conversations would show one user another's files.
|
|
180
|
+
from a first call. A call without a key (no thread, no run) never shares a sandbox: one
|
|
181
|
+
sandbox shared across conversations would show one user another's files. It is one cell
|
|
182
|
+
the daemon runs by itself (`client.runCell(cell, { preferWarm: true })`; no `preferWarm`
|
|
183
|
+
with `sessions: "never"`): on a daemon that keeps a warm pool (`describe()` states
|
|
184
|
+
`sessionPool`, the operator's `SANDBOX_SESSION_POOL`) a waiting sandbox that has run only
|
|
185
|
+
plimsoll's own programs answers it and is deleted after, so the call is as alone as a
|
|
186
|
+
fresh one and answers without a sandbox being made for it; with no pool, or none waiting
|
|
187
|
+
(a burst larger than the pool), the daemon runs it in a sandbox made for it, and a miss
|
|
188
|
+
costs nothing more. Measured on one laptop on 2026-10-28 for the client-side form this
|
|
189
|
+
replaced (an open, the cell, a close; plimsolld on docker under runc, a pool of 2): 38 ms
|
|
190
|
+
(Python) and 43 ms (JavaScript) against 651 and 631 ms fresh (medians of 15 calls, 3 s
|
|
191
|
+
apart); the daemon's form sends one request instead of two and was not measured
|
|
192
|
+
separately. The answer reads as a fresh run's: `stateKept` and `filesPersist` false, and
|
|
193
|
+
`runCell`'s result says `warm`. What it costs: a pool sandbox runs the cell in the session's
|
|
194
|
+
image (on docker the project image, which a fresh cell uses too); the run record is a
|
|
195
|
+
single run's either way and does not cover `warm`. A language the daemon's
|
|
182
196
|
image cannot run is refused before anything is sent. Output past `maxOutputChars` (each of
|
|
183
197
|
stdout and stderr) is cut and marked truncated, and a cut never ends on the first half of a
|
|
184
198
|
surrogate pair (the two UTF-16 code units that encode one character such as an emoji): a
|
package/dist/client.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { LANGUAGES, OUTCOME_NAMES, TIERS } from "./tables.gen.ts";
|
|
|
3
3
|
import { type SessionEnd } from "./errors.ts";
|
|
4
4
|
import type { WireCellRun, WireEnvelope, WireOpenSessionResponse, WireSoftwareRule } from "./wire.ts";
|
|
5
5
|
/** The wire protocol number this client speaks (protocol.Number in Go). */
|
|
6
|
-
export declare const PROTOCOL =
|
|
6
|
+
export declare const PROTOCOL = 5;
|
|
7
7
|
/** How strong the boundary is, weakest first. */
|
|
8
8
|
export type Isolation = (typeof TIERS)[number];
|
|
9
9
|
/** Whether a tier the daemon reported meets a floor. An unknown tier meets nothing. */
|
|
@@ -153,6 +153,13 @@ export type CellResult = Evidence & {
|
|
|
153
153
|
interpreterStarted: boolean;
|
|
154
154
|
/** The interpreter ended during this call; the next cell starts a fresh one. */
|
|
155
155
|
interpreterEnded: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* A waiting pool member ran the cell: a sandbox made before the call that had run only
|
|
158
|
+
* plimsoll's own programs, handed to this call alone and deleted after it (runCell with
|
|
159
|
+
* preferWarm). False for a session's cell and for one run in a sandbox made for it. The
|
|
160
|
+
* record does not cover it.
|
|
161
|
+
*/
|
|
162
|
+
warm: boolean;
|
|
156
163
|
};
|
|
157
164
|
export type Info = {
|
|
158
165
|
sandbox: string;
|
|
@@ -174,6 +181,12 @@ export type Info = {
|
|
|
174
181
|
*/
|
|
175
182
|
maxSessionsPerCaller: number;
|
|
176
183
|
maxSessionsPerOwner: number;
|
|
184
|
+
/**
|
|
185
|
+
* How many sandboxes the daemon keeps ready for sessions, 0 when it keeps none: with
|
|
186
|
+
* one, a cell run with runCell's preferWarm, or a session opened with warmOnly, can
|
|
187
|
+
* answer without a sandbox being made for it. Stated with supportsSessions.
|
|
188
|
+
*/
|
|
189
|
+
sessionPool: number;
|
|
177
190
|
environments: {
|
|
178
191
|
javascript: PayloadEnvironment;
|
|
179
192
|
project: PayloadEnvironment;
|
|
@@ -209,6 +222,15 @@ export type SessionOptions = {
|
|
|
209
222
|
* refused before anything is sent.
|
|
210
223
|
*/
|
|
211
224
|
owner?: string;
|
|
225
|
+
/**
|
|
226
|
+
* A waiting pool member or nothing: on a daemon with none to hand over the open is
|
|
227
|
+
* refused, not dispatched, reason capacity, and no sandbox is made, so the caller can
|
|
228
|
+
* run fresh instead. It never closes another session of the owner to make room. A
|
|
229
|
+
* daemon that predates the field would have ignored it and made a sandbox, so it came
|
|
230
|
+
* with protocol 5, which such a daemon refuses before reading the open. A cell for one
|
|
231
|
+
* call needs no session of its own: runCell with preferWarm.
|
|
232
|
+
*/
|
|
233
|
+
warmOnly?: boolean;
|
|
212
234
|
signal?: AbortSignal;
|
|
213
235
|
};
|
|
214
236
|
/**
|
|
@@ -266,6 +288,26 @@ export declare class PlimsollClient {
|
|
|
266
288
|
runJavaScript(code: string, opts?: RunOptions): Promise<JavaScriptResult>;
|
|
267
289
|
/** Writes a multi-file project into a fresh sandbox and runs its steps in order. */
|
|
268
290
|
runProject(req: ProjectRequest, opts?: RunOptions): Promise<ProjectResult>;
|
|
291
|
+
/**
|
|
292
|
+
* Runs a cell by itself: code for an interpreter of its language, its files written
|
|
293
|
+
* into the work directory first, its final expression's value printed, in a sandbox
|
|
294
|
+
* of its own that keeps nothing after the call (interpreterStarted and
|
|
295
|
+
* interpreterEnded are both true). Files under .plimsoll/, where the code and its
|
|
296
|
+
* runner go, are refused.
|
|
297
|
+
*
|
|
298
|
+
* preferWarm lets the daemon run it in a sandbox it keeps ready for sessions
|
|
299
|
+
* (Info.sessionPool): one that has run only plimsoll's own programs, with the
|
|
300
|
+
* interpreter already running, claimed for this call alone and deleted after it, so
|
|
301
|
+
* the call answers without a sandbox being made for it. When none fits the cell runs
|
|
302
|
+
* in a sandbox made for it, as without the flag: a miss is never a refusal. The
|
|
303
|
+
* result's warm says which ran. What it costs: a pool member runs the cell in the
|
|
304
|
+
* session image (on docker the project image, which a fresh cell uses too), in a
|
|
305
|
+
* sandbox that waited with plimsoll's interpreters in it. The record is a single
|
|
306
|
+
* run's either way, and does not cover warm.
|
|
307
|
+
*/
|
|
308
|
+
runCell(req: CellRequest, opts?: RunOptions & {
|
|
309
|
+
preferWarm?: boolean;
|
|
310
|
+
}): Promise<CellResult>;
|
|
269
311
|
/**
|
|
270
312
|
* Opens a session: one sandbox kept for many calls, files persisting, and of
|
|
271
313
|
* processes only the interpreters runCell keeps. Only on a daemon whose Describe
|
package/dist/client.js
CHANGED
|
@@ -11,7 +11,7 @@ import { LANGUAGES, OUTCOME_NAMES, TIERS } from "./tables.gen.js";
|
|
|
11
11
|
import { errorFromWire, NOT_DISPATCHED_HEADER, PlimsollError, REQUEST_ID_HEADER, sessionEndFromWire, unboundSuccess } from "./errors.js";
|
|
12
12
|
import { wireBytes } from "./wire.js";
|
|
13
13
|
/** The wire protocol number this client speaks (protocol.Number in Go). */
|
|
14
|
-
export const PROTOCOL =
|
|
14
|
+
export const PROTOCOL = 5;
|
|
15
15
|
const SERVICE = "plimsoll.v1.SandboxService";
|
|
16
16
|
// Above the largest legitimate project response, so a misbehaving daemon cannot
|
|
17
17
|
// make the client buffer without bound (the Go client's maxResponseBytes).
|
|
@@ -187,6 +187,7 @@ function cellResult(resp, record) {
|
|
|
187
187
|
stderrTruncated: c.stderrTruncated ?? false,
|
|
188
188
|
interpreterStarted: c.interpreterStarted ?? false,
|
|
189
189
|
interpreterEnded: c.interpreterEnded ?? false,
|
|
190
|
+
warm: resp.warm ?? false,
|
|
190
191
|
};
|
|
191
192
|
}
|
|
192
193
|
// A lone surrogate has no UTF-8 form, so no protobuf string can hold one, though JSON
|
|
@@ -355,6 +356,7 @@ export class PlimsollClient {
|
|
|
355
356
|
sessionEnvironment: env(m.sessionEnvironment),
|
|
356
357
|
maxSessionsPerCaller: m.maxSessionsPerCaller ?? 0,
|
|
357
358
|
maxSessionsPerOwner: m.maxSessionsPerOwner ?? 0,
|
|
359
|
+
sessionPool: m.sessionPool ?? 0,
|
|
358
360
|
environments: {
|
|
359
361
|
javascript: env(m.javascriptEnvironment),
|
|
360
362
|
project: env(m.projectEnvironment),
|
|
@@ -379,6 +381,35 @@ export class PlimsollClient {
|
|
|
379
381
|
const resp = await this.exchange("Run", this.envelope(opts, validateRule(opts.software)), projectPayload(req, this.projectGrant), opts);
|
|
380
382
|
return decoded(() => finish(resp.run, resp.record, projectResult, "project", opts.minimumIsolation));
|
|
381
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* Runs a cell by itself: code for an interpreter of its language, its files written
|
|
386
|
+
* into the work directory first, its final expression's value printed, in a sandbox
|
|
387
|
+
* of its own that keeps nothing after the call (interpreterStarted and
|
|
388
|
+
* interpreterEnded are both true). Files under .plimsoll/, where the code and its
|
|
389
|
+
* runner go, are refused.
|
|
390
|
+
*
|
|
391
|
+
* preferWarm lets the daemon run it in a sandbox it keeps ready for sessions
|
|
392
|
+
* (Info.sessionPool): one that has run only plimsoll's own programs, with the
|
|
393
|
+
* interpreter already running, claimed for this call alone and deleted after it, so
|
|
394
|
+
* the call answers without a sandbox being made for it. When none fits the cell runs
|
|
395
|
+
* in a sandbox made for it, as without the flag: a miss is never a refusal. The
|
|
396
|
+
* result's warm says which ran. What it costs: a pool member runs the cell in the
|
|
397
|
+
* session image (on docker the project image, which a fresh cell uses too), in a
|
|
398
|
+
* sandbox that waited with plimsoll's interpreters in it. The record is a single
|
|
399
|
+
* run's either way, and does not cover warm.
|
|
400
|
+
*/
|
|
401
|
+
async runCell(req, opts = {}) {
|
|
402
|
+
if (req.language !== "javascript" && req.language !== "python") {
|
|
403
|
+
throw new PlimsollError("invalid_argument", `plimsoll: unknown cell language ${JSON.stringify(req.language)}`, { notDispatched: "request" });
|
|
404
|
+
}
|
|
405
|
+
if (opts.preferWarm !== undefined && typeof opts.preferWarm !== "boolean") {
|
|
406
|
+
throw new PlimsollError("invalid_argument", "plimsoll: preferWarm must be a boolean", { notDispatched: "request" });
|
|
407
|
+
}
|
|
408
|
+
const files = (req.files ?? []).map((f) => ({ path: f.path, content: f.content }));
|
|
409
|
+
const env = { ...this.envelope(opts, validateRule(opts.software)), preferWarm: opts.preferWarm || undefined };
|
|
410
|
+
const resp = await this.exchange("Run", env, { cell: { language: req.language, code: req.code, files } }, opts);
|
|
411
|
+
return decoded(() => finish(resp.run, resp.record, cellResult, "cell", opts.minimumIsolation));
|
|
412
|
+
}
|
|
382
413
|
/**
|
|
383
414
|
* Opens a session: one sandbox kept for many calls, files persisting, and of
|
|
384
415
|
* processes only the interpreters runCell keeps. Only on a daemon whose Describe
|
|
@@ -396,6 +427,9 @@ export class PlimsollClient {
|
|
|
396
427
|
if (opts.owner !== undefined && (typeof opts.owner !== "string" || opts.owner === "")) {
|
|
397
428
|
throw new PlimsollError("invalid_argument", "plimsoll: owner must be a nonempty string, or omitted for none", { notDispatched: "request" });
|
|
398
429
|
}
|
|
430
|
+
if (opts.warmOnly !== undefined && typeof opts.warmOnly !== "boolean") {
|
|
431
|
+
throw new PlimsollError("invalid_argument", "plimsoll: warmOnly must be a boolean", { notDispatched: "request" });
|
|
432
|
+
}
|
|
399
433
|
const m = await this.call("OpenSession", {
|
|
400
434
|
protocol: PROTOCOL,
|
|
401
435
|
minimumIsolation: opts.minimumIsolation,
|
|
@@ -405,6 +439,7 @@ export class PlimsollClient {
|
|
|
405
439
|
softwareRule: rule,
|
|
406
440
|
languages: opts.languages?.length ? [...new Set(opts.languages)] : undefined,
|
|
407
441
|
owner: opts.owner === undefined ? undefined : ownerDigest(this.token, opts.owner),
|
|
442
|
+
warmOnly: opts.warmOnly || undefined,
|
|
408
443
|
}, opts.signal);
|
|
409
444
|
const s = decoded(() => new Session(this, m, rule, opts.minimumIsolation));
|
|
410
445
|
if (decoded(() => s.fingerprint !== sessionFingerprint(m.sessionId ?? ""))) {
|
package/dist/sandboxes.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export type CodeSandboxesOptions = {
|
|
|
26
26
|
/**
|
|
27
27
|
* "auto" (default) keeps a session per key when the daemon supports sessions,
|
|
28
28
|
* else runs each call fresh. "always" fails when it does not; "never" always
|
|
29
|
-
* runs fresh.
|
|
29
|
+
* runs fresh, and never in a sandbox the daemon kept ready (no preferWarm).
|
|
30
30
|
*/
|
|
31
31
|
sessions?: SessionMode;
|
|
32
32
|
/** The languages the tool offers, the first being the default. Default python, then javascript. */
|
|
@@ -133,21 +133,6 @@ export type ExecuteCodeOutput = {
|
|
|
133
133
|
/** SHA-256 of the run record checked by the client before this result was returned. */
|
|
134
134
|
recordSha256: string;
|
|
135
135
|
};
|
|
136
|
-
/** @internal A fresh call on a daemon without projects: the code as a snippet, its last value printed. Node and QuickJS alike. */
|
|
137
|
-
export declare function snippetRunner(code: string): string;
|
|
138
|
-
/**
|
|
139
|
-
* @internal A fresh run prints its last expression as a cell does, through these
|
|
140
|
-
* runners, and takes what a cell takes: top-level await, and imports from the work
|
|
141
|
-
* directory (Python's own imports first, in isolated mode, as the session kernel
|
|
142
|
-
* does; Node's require resolving from the work directory, and the image's baked
|
|
143
|
-
* packages above it).
|
|
144
|
-
*/
|
|
145
|
-
export declare const RUNNERS: Record<Language, {
|
|
146
|
-
path: string;
|
|
147
|
-
file: string;
|
|
148
|
-
step: string;
|
|
149
|
-
source: string;
|
|
150
|
-
}>;
|
|
151
136
|
export declare class CodeSandboxes {
|
|
152
137
|
#private;
|
|
153
138
|
constructor(opts: CodeSandboxesOptions);
|
package/dist/sandboxes.js
CHANGED
|
@@ -9,11 +9,15 @@
|
|
|
9
9
|
// cell: code run in an interpreter the session keeps alive, so variables and
|
|
10
10
|
// loaded data survive between calls as they do in a notebook, and the files a call
|
|
11
11
|
// is given or writes stay in the work directory. On any other daemon, and for a
|
|
12
|
-
// call without a key, each call
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
12
|
+
// call without a key, each call is one cell the daemon runs by itself (runCell), in a
|
|
13
|
+
// sandbox of its own: nothing persists. The tool's output says which, so the model is
|
|
14
|
+
// never told state survived when it did not. The call asks for a sandbox the daemon
|
|
15
|
+
// keeps ready (preferWarm, unless sessions is "never"): on a daemon with a warm pool a
|
|
16
|
+
// waiting one that has run nothing answers it and is deleted after; otherwise, and
|
|
17
|
+
// when none is waiting, the daemon runs it in a sandbox made for it, through a runner
|
|
18
|
+
// that prints the last expression the same way. A daemon without projects (wasm) runs
|
|
19
|
+
// it as a JavaScript snippet, and this instance refuses Python and files there before
|
|
20
|
+
// sending anything.
|
|
17
21
|
//
|
|
18
22
|
// Whether earlier state exists is something only the sandbox knows: this instance
|
|
19
23
|
// forgets a key when it is disposed or idles out, and a conversation that resumes
|
|
@@ -98,96 +102,6 @@ function untilAborted(p, signal) {
|
|
|
98
102
|
export function keyDigest(key) {
|
|
99
103
|
return createHash("sha256").update(keyId(key), "utf8").digest("hex").slice(0, 12);
|
|
100
104
|
}
|
|
101
|
-
/** @internal A fresh call on a daemon without projects: the code as a snippet, its last value printed. Node and QuickJS alike. */
|
|
102
|
-
export function snippetRunner(code) {
|
|
103
|
-
return [
|
|
104
|
-
"(() => {",
|
|
105
|
-
" const show = (v) => {",
|
|
106
|
-
' if (typeof require === "function") { try { return require("node:util").inspect(v, { depth: 4 }); } catch (_) {} }',
|
|
107
|
-
" try { const s = JSON.stringify(v); if (s !== undefined) return s; } catch (_) {}",
|
|
108
|
-
" return String(v);",
|
|
109
|
-
" };",
|
|
110
|
-
` const v = (0, eval)(${JSON.stringify(code)});`,
|
|
111
|
-
" Promise.resolve(v).then((v) => { if (v !== undefined) console.log(show(v)); });",
|
|
112
|
-
"})();",
|
|
113
|
-
"",
|
|
114
|
-
].join("\n");
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* @internal A fresh run prints its last expression as a cell does, through these
|
|
118
|
-
* runners, and takes what a cell takes: top-level await, and imports from the work
|
|
119
|
-
* directory (Python's own imports first, in isolated mode, as the session kernel
|
|
120
|
-
* does; Node's require resolving from the work directory, and the image's baked
|
|
121
|
-
* packages above it).
|
|
122
|
-
*/
|
|
123
|
-
export const RUNNERS = {
|
|
124
|
-
python: {
|
|
125
|
-
path: ".plimsoll/run.py",
|
|
126
|
-
file: ".plimsoll/cell.py",
|
|
127
|
-
step: "python3 -I .plimsoll/run.py",
|
|
128
|
-
// As the session kernel runs a cell: at module level, an event loop only for code
|
|
129
|
-
// that awaits at the top level, so the cell's own asyncio.run works.
|
|
130
|
-
source: [
|
|
131
|
-
"import ast, asyncio, inspect, linecache, sys",
|
|
132
|
-
"sys.path.insert(0, '')",
|
|
133
|
-
// UTF-8, as the client wrote it: the guest gets the image's environment, and an
|
|
134
|
-
// image whose locale is not UTF-8 would otherwise misread non-ASCII code.
|
|
135
|
-
"src = open('.plimsoll/cell.py', encoding='utf-8').read()",
|
|
136
|
-
"linecache.cache['cell'] = (len(src), None, src.splitlines(True), 'cell')",
|
|
137
|
-
"tree = ast.parse(src, 'cell', 'exec')",
|
|
138
|
-
"last = ast.Expression(tree.body.pop().value) if tree.body and isinstance(tree.body[-1], ast.Expr) else None",
|
|
139
|
-
"ns = {'__name__': '__main__', '__builtins__': __builtins__}",
|
|
140
|
-
"flags = ast.PyCF_ALLOW_TOP_LEVEL_AWAIT",
|
|
141
|
-
"loop = asyncio.new_event_loop()",
|
|
142
|
-
"def settle(r):",
|
|
143
|
-
" return loop.run_until_complete(r) if inspect.isawaitable(r) else r",
|
|
144
|
-
"settle(eval(compile(tree, 'cell', 'exec', flags=flags), ns))",
|
|
145
|
-
"if last is not None:",
|
|
146
|
-
" value = settle(eval(compile(last, 'cell', 'eval', flags=flags), ns))",
|
|
147
|
-
" if value is not None:",
|
|
148
|
-
" print(repr(value))",
|
|
149
|
-
"",
|
|
150
|
-
].join("\n"),
|
|
151
|
-
},
|
|
152
|
-
javascript: {
|
|
153
|
-
path: ".plimsoll/run.cjs",
|
|
154
|
-
file: ".plimsoll/cell.js",
|
|
155
|
-
step: "node --expose-internals .plimsoll/run.cjs",
|
|
156
|
-
source: [
|
|
157
|
-
"const fs = require('node:fs'), util = require('node:util'), vm = require('node:vm');",
|
|
158
|
-
// The names a cell in the session's `node -e` interpreter sees as globals.
|
|
159
|
-
"globalThis.require = require('node:module').createRequire(process.cwd() + '/');",
|
|
160
|
-
"globalThis.module = { exports: {} }; globalThis.exports = globalThis.module.exports;",
|
|
161
|
-
"globalThis.__dirname = '.'; globalThis.__filename = '[eval]';",
|
|
162
|
-
// Top-level await comes from Node's private module internal/repl/await (the
|
|
163
|
-
// REPL's own rewrite of a cell), which only --expose-internals makes loadable. It
|
|
164
|
-
// is not a public API. The suite runs this runner on the node that runs the suite:
|
|
165
|
-
// 22.18.0 in CI, the line of the project image's node:22 base; it also passed on
|
|
166
|
-
// 26.3.1 on 2026-10-07. If a Node release moves or removes it, the require below
|
|
167
|
-
// fails and the cell runs without the rewrite: a cell that awaits at the top level
|
|
168
|
-
// then fails visibly (a SyntaxError on stderr, exit code 1), and so does the runner
|
|
169
|
-
// test "imports from the work directory and awaits at the top level"; a cell
|
|
170
|
-
// without top-level await runs as before.
|
|
171
|
-
"let tla = null;",
|
|
172
|
-
"try { tla = require('internal/repl/await').processTopLevelAwait; } catch {}",
|
|
173
|
-
"const src = fs.readFileSync('.plimsoll/cell.js', 'utf8');",
|
|
174
|
-
"let wrapped = null;",
|
|
175
|
-
"if (tla) { try { wrapped = tla(src); } catch {} }",
|
|
176
|
-
"(async () => {",
|
|
177
|
-
" let v;",
|
|
178
|
-
" if (wrapped) {",
|
|
179
|
-
" const out = await vm.runInThisContext(wrapped, { filename: 'cell.js' });",
|
|
180
|
-
" v = out === undefined ? undefined : out.value;",
|
|
181
|
-
" } else {",
|
|
182
|
-
" v = vm.runInThisContext(src, { filename: 'cell.js' });",
|
|
183
|
-
" if (v instanceof Promise) v = await v;",
|
|
184
|
-
" }",
|
|
185
|
-
" if (v !== undefined) console.log(util.inspect(v, { depth: 4 }));",
|
|
186
|
-
"})().catch((e) => { console.error(e); process.exitCode = 1; });",
|
|
187
|
-
"",
|
|
188
|
-
].join("\n"),
|
|
189
|
-
},
|
|
190
|
-
};
|
|
191
105
|
export class CodeSandboxes {
|
|
192
106
|
#opts;
|
|
193
107
|
#entries = new Map();
|
|
@@ -404,8 +318,8 @@ export class CodeSandboxes {
|
|
|
404
318
|
get #floor() {
|
|
405
319
|
return this.#opts.minimumIsolation ?? "kernel";
|
|
406
320
|
}
|
|
407
|
-
// A
|
|
408
|
-
//
|
|
321
|
+
// A sandbox of its own for one call: one cell the daemon runs by itself, in a sandbox
|
|
322
|
+
// it kept ready when one is waiting (preferWarm), else in one made for it.
|
|
409
323
|
async #fresh(key, info, language, code, files, opts) {
|
|
410
324
|
if (!info.supportsProject) {
|
|
411
325
|
// A snippet is all this daemon runs (wasm): JavaScript, without files.
|
|
@@ -419,31 +333,12 @@ export class CodeSandboxes {
|
|
|
419
333
|
notDispatched: "unsupported",
|
|
420
334
|
});
|
|
421
335
|
}
|
|
422
|
-
const r = await this.client.runJavaScript(snippetRunner(code), opts);
|
|
423
|
-
this.#record(r.record, key);
|
|
424
|
-
return {
|
|
425
|
-
...this.#cut(language, r.exitCode, r.timedOut, r.stdout, r.stderr, r.stdoutTruncated || r.stderrTruncated),
|
|
426
|
-
stateKept: false,
|
|
427
|
-
filesPersist: false,
|
|
428
|
-
isolation: r.isolation,
|
|
429
|
-
recordSha256: r.record.sha256,
|
|
430
|
-
};
|
|
431
336
|
}
|
|
432
|
-
const
|
|
433
|
-
const r = await this.client.
|
|
434
|
-
files: [...files, { path: runner.file, content: code }, { path: runner.path, content: runner.source }],
|
|
435
|
-
steps: [runner.step],
|
|
436
|
-
}, opts);
|
|
337
|
+
const preferWarm = (this.#opts.sessions ?? "auto") !== "never";
|
|
338
|
+
const r = await this.client.runCell({ language, code, files }, { ...opts, preferWarm });
|
|
437
339
|
this.#record(r.record, key);
|
|
438
|
-
const step = r.steps[0];
|
|
439
|
-
if (!step) {
|
|
440
|
-
// No step report: the outcome says what ended the run (a timeout, a lost report),
|
|
441
|
-
// not whether the code had started, so there is no exit code to give. Unmarked,
|
|
442
|
-
// as anything that may have run is; the checked result rides on the error.
|
|
443
|
-
throw new PlimsollError("unknown", `plimsoll: the run ended ${r.outcome} without a step report (${r.detail}). It was not retried; running it again could repeat what it did.`, { result: r });
|
|
444
|
-
}
|
|
445
340
|
return {
|
|
446
|
-
...this.#cut(language,
|
|
341
|
+
...this.#cut(language, r.exitCode, r.timedOut, r.stdout, r.stderr, r.stdoutTruncated || r.stderrTruncated),
|
|
447
342
|
stateKept: false,
|
|
448
343
|
filesPersist: false,
|
|
449
344
|
isolation: r.isolation,
|
package/dist/wire.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export type WireEnvelope = {
|
|
|
21
21
|
traceId?: string;
|
|
22
22
|
timeoutMs?: number;
|
|
23
23
|
softwareRule?: WireSoftwareRule;
|
|
24
|
+
/** Run only, with a cell: the daemon may run it in a waiting pool member. */
|
|
25
|
+
preferWarm?: boolean;
|
|
24
26
|
};
|
|
25
27
|
/** A session's call to its interpreter (sessions.md, "Interpreters"). */
|
|
26
28
|
export type WireCellRun = {
|
|
@@ -34,6 +36,7 @@ export type WireCellRun = {
|
|
|
34
36
|
export type WireRunRequest = WireEnvelope & {
|
|
35
37
|
javascript?: WireJavaScriptRun;
|
|
36
38
|
project?: WireProjectRun;
|
|
39
|
+
cell?: WireCellRun;
|
|
37
40
|
};
|
|
38
41
|
export type WireSessionRunRequest = WireRunRequest & {
|
|
39
42
|
sessionId: string;
|
|
@@ -118,6 +121,7 @@ export type WireRunResponse = {
|
|
|
118
121
|
softwareIdentity?: string;
|
|
119
122
|
environment?: string;
|
|
120
123
|
instance?: string;
|
|
124
|
+
warm?: boolean;
|
|
121
125
|
javascript?: WireJavaScriptResult;
|
|
122
126
|
project?: WireProjectResult;
|
|
123
127
|
module?: unknown;
|
|
@@ -158,6 +162,7 @@ export type WireDescribeResponse = {
|
|
|
158
162
|
maxSessionsPerCaller?: number;
|
|
159
163
|
maxSessionsPerOwner?: number;
|
|
160
164
|
sessionEnvironment?: WirePayloadEnvironment;
|
|
165
|
+
sessionPool?: number;
|
|
161
166
|
};
|
|
162
167
|
export type WireOpenSessionRequest = {
|
|
163
168
|
protocol: number;
|
|
@@ -167,6 +172,8 @@ export type WireOpenSessionRequest = {
|
|
|
167
172
|
idleTimeoutMs?: number;
|
|
168
173
|
softwareRule?: WireSoftwareRule;
|
|
169
174
|
languages?: string[];
|
|
175
|
+
owner?: string;
|
|
176
|
+
warmOnly?: boolean;
|
|
170
177
|
};
|
|
171
178
|
export type WireOpenSessionResponse = {
|
|
172
179
|
sessionId?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plimsollmark/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "TypeScript client for plimsolld, with AI SDK, Trigger.dev and Mastra executeCode add-ons",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/plimsollmark/plimsoll/tree/main/clients/typescript#readme",
|