@plimsollmark/client 0.21.0 → 0.22.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 CHANGED
@@ -236,6 +236,13 @@ The digest names that record; it is not a signature or a proof that the guest
236
236
  computed honestly. See the [Trigger.dev feature and deployment guide](https://github.com/plimsollmark/plimsoll/blob/main/docs/trigger-dev.md)
237
237
  for the three properties together.
238
238
 
239
+ The model sees only a run record's digest (`recordSha256`). The record itself, checked by
240
+ the client, goes to `onRecord(record, key)`, once for every call that ran: an answered call's,
241
+ and the version 3 record a session call that may have run carries on its error. That is where an
242
+ application keeps receipts (a store, or a signer such as plimsoll's `attest` harness); a refusal
243
+ calls nothing, since nothing ran. An `onRecord` that throws, or returns a promise that rejects, is
244
+ logged and never changes the result the model gets.
245
+
239
246
  Closing a sandbox checks the daemon's count of calls against the chain the client saw; a
240
247
  mismatch means the daemon counted a call the client has no answer for (one that ended in an
241
248
  abort, a timeout, a dropped connection or a proxy's error), or, if none did, that someone
@@ -1,4 +1,5 @@
1
1
  import { PlimsollClient, type Isolation, type Language } from "./client.ts";
2
+ import type { RunRecord } from "./record.ts";
2
3
  export type SessionMode = "auto" | "always" | "never";
3
4
  /** The languages a tool offers, the first being the default. */
4
5
  export type ToolLanguages = readonly [Language, ...Language[]];
@@ -76,6 +77,14 @@ export type CodeSandboxesOptions = {
76
77
  * rejects, is logged the same way; it never stops a close or the next open.
77
78
  */
78
79
  onCloseError?: (key: SandboxKey, err: unknown) => void;
80
+ /**
81
+ * Called with every run record this instance checked: an answered call's, and the one
82
+ * a session call that may have run carries on its error. The tool's result gives the
83
+ * model only the record's digest, so this is where an application keeps the receipt
84
+ * (a store, a signer). Never called for a refusal: nothing ran. A callback that
85
+ * throws, or returns a promise that rejects, is logged; it never changes the result.
86
+ */
87
+ onRecord?: (record: RunRecord, key: SandboxKey | undefined) => void | Promise<void>;
79
88
  };
80
89
  /** What the executeCode tool takes. */
81
90
  export type ExecuteCodeInput = {
package/dist/sandboxes.js CHANGED
@@ -305,7 +305,7 @@ export class CodeSandboxes {
305
305
  });
306
306
  const opts = { timeoutMs: this.#opts.timeoutMs, minimumIsolation: this.#floor, signal };
307
307
  if (key === undefined || !persistent) {
308
- return this.#fresh(info, language, input.code, files, opts);
308
+ return this.#fresh(key, info, language, input.code, files, opts);
309
309
  }
310
310
  let retried = false;
311
311
  for (;;) {
@@ -324,6 +324,7 @@ export class CodeSandboxes {
324
324
  session = await beforeDispatch(() => untilAborted(entry.session, signal));
325
325
  // From here the cell may have been sent: an unmarked error stays unmarked.
326
326
  const r = await session.runCell({ language, code: input.code, files }, opts);
327
+ this.#record(r.record, key);
327
328
  // Read once the call has answered: the session runs its calls in order, so of
328
329
  // calls made at once only the first to answer finds the sandbox new.
329
330
  const first = !entry.answered;
@@ -345,6 +346,8 @@ export class CodeSandboxes {
345
346
  };
346
347
  }
347
348
  catch (e) {
349
+ if (e instanceof PlimsollError && e.record)
350
+ this.#record(e.record, key);
348
351
  // Aborted while its sandbox opened: nothing was sent, and a sandbox no call has
349
352
  // used is not kept for a call that has gone (the open finishes, then closes).
350
353
  if (!session && signal?.aborted) {
@@ -400,7 +403,7 @@ export class CodeSandboxes {
400
403
  }
401
404
  // A fresh sandbox for one call: the files, the code and a runner that prints the
402
405
  // last expression, as one project.
403
- async #fresh(info, language, code, files, opts) {
406
+ async #fresh(key, info, language, code, files, opts) {
404
407
  if (!info.supportsProject) {
405
408
  // A snippet is all this daemon runs (wasm): JavaScript, without files.
406
409
  if (language !== "javascript") {
@@ -414,6 +417,7 @@ export class CodeSandboxes {
414
417
  });
415
418
  }
416
419
  const r = await this.client.runJavaScript(snippetRunner(code), opts);
420
+ this.#record(r.record, key);
417
421
  return {
418
422
  ...this.#cut(language, r.exitCode, r.timedOut, r.stdout, r.stderr, r.stdoutTruncated || r.stderrTruncated),
419
423
  stateKept: false,
@@ -427,6 +431,7 @@ export class CodeSandboxes {
427
431
  files: [...files, { path: runner.file, content: code }, { path: runner.path, content: runner.source }],
428
432
  steps: [runner.step],
429
433
  }, opts);
434
+ this.#record(r.record, key);
430
435
  const step = r.steps[0];
431
436
  if (!step) {
432
437
  // No step report: the outcome says what ended the run (a timeout, a lost report),
@@ -555,6 +560,20 @@ export class CodeSandboxes {
555
560
  callbackFailed(e);
556
561
  }
557
562
  }
563
+ // Never throws, for the same reason: a receipt store's failure must not turn a
564
+ // result the model should see into an error.
565
+ #record(record, key) {
566
+ const callback = this.#opts.onRecord;
567
+ if (!callback)
568
+ return;
569
+ const failed = (e) => console.warn(`plimsoll: onRecord failed for record ${record.sha256}:`, errorText(e));
570
+ try {
571
+ void Promise.resolve(callback(record, key)).catch(failed);
572
+ }
573
+ catch (e) {
574
+ failed(e);
575
+ }
576
+ }
558
577
  #touch(id) {
559
578
  const entry = this.#entries.get(id);
560
579
  const ms = this.#opts.idleCloseMs ?? 10 * 60_000;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plimsollmark/client",
3
- "version": "0.21.0",
3
+ "version": "0.22.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",