@plimsollmark/client 0.27.2 → 0.29.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/dist/client.d.ts CHANGED
@@ -1,12 +1,17 @@
1
1
  import { type RunRecord } from "./record.ts";
2
- import { LANGUAGES, OUTCOME_NAMES, TIERS } from "./tables.gen.ts";
2
+ import { LANGUAGES, OUTCOME_NAMES, PROTOCOL, TIERS } from "./tables.gen.ts";
3
+ import { type SessionCheckpoint } from "./checkpoint.ts";
3
4
  import { type SessionEnd } from "./errors.ts";
4
- import type { WireCellRun, WireEnvelope, WireOpenSessionResponse, WireSoftwareRule } from "./wire.ts";
5
- /** The wire protocol number this client speaks (protocol.Number in Go). */
6
- export declare const PROTOCOL = 5;
5
+ import type { WireAttachSessionResponse, WireCellRun, WireEnvelope, WireOpenSessionResponse, WireSoftwareRule } from "./wire.ts";
6
+ export { PROTOCOL };
7
7
  /** How strong the boundary is, weakest first. */
8
8
  export type Isolation = (typeof TIERS)[number];
9
- /** Whether a tier the daemon reported meets a floor. An unknown tier meets nothing. */
9
+ /**
10
+ * Whether a tier the daemon reported is at least `floor`, as the Go client's
11
+ * IsolationClass.Meets and the Python client's meets. A tier or floor this client does
12
+ * not know (including an empty one) meets nothing; every known tier meets "none". A
13
+ * request cannot state "none" as its floor (minimumIsolation), which is a separate rule.
14
+ */
10
15
  export declare function meets(actual: string, floor: Isolation): boolean;
11
16
  /** A caller's rule for the selected software: one exact identity, or 1 to 32 approved ones. */
12
17
  export type SoftwareRule = {
@@ -31,6 +36,13 @@ export type ClientOptions = {
31
36
  * earlier one may have delivered the code.
32
37
  */
33
38
  fetch?: typeof fetch;
39
+ /**
40
+ * The application's own name for this daemon, never a URL: 1 to 64 of [A-Za-z0-9._-]. A
41
+ * session's checkpoint states it, and attachSession takes only a checkpoint that names
42
+ * it, so a checkpoint read from the application's store can only reach a daemon the
43
+ * application configured. Without it, sessions cannot be checkpointed or attached.
44
+ */
45
+ daemonName?: string;
34
46
  /**
35
47
  * Bounds each HTTP exchange, sending and reading the answer, in milliseconds.
36
48
  * Default 6 minutes, as the Go and Python clients. A run's timeoutMs bounds what
@@ -48,10 +60,25 @@ export type RunOptions = {
48
60
  traceId?: string;
49
61
  signal?: AbortSignal;
50
62
  };
63
+ /**
64
+ * A run of a snippet or a project, with the grant profile it selects for this call alone:
65
+ * it replaces the client's javascriptGrantProfile or projectGrantProfile, and "" selects
66
+ * none. A cell carries no grant, so runCell takes RunOptions.
67
+ */
68
+ export type GrantRunOptions = RunOptions & {
69
+ grantProfile?: string;
70
+ };
51
71
  /** Evidence every answered run carries: configuration and provider evidence, never attestation. */
52
72
  export type Evidence = {
53
73
  sandbox: string;
54
74
  isolation: string;
75
+ /**
76
+ * The sentence the provider's vendor or design requires beside `isolation`, as the daemon
77
+ * states it (only the WSL containers provider states one so far: Microsoft's statement that
78
+ * WSL is not a security sandbox for running untrusted code), or "" when it states none. Show
79
+ * it wherever you show the tier. The record repeats it, signed.
80
+ */
81
+ isolationQualification: string;
55
82
  softwareIdentity: string;
56
83
  environment: string;
57
84
  /** The sandbox instance that ran it, as a typed reference (`k8s-pod-uid:` and a pod's UID), or "" when the provider names none. */
@@ -237,8 +264,52 @@ export type SessionOptions = {
237
264
  * call needs no session of its own: runCell with preferWarm.
238
265
  */
239
266
  warmOnly?: boolean;
267
+ /**
268
+ * Ask the daemon to keep no call's answer. By default it keeps the last answered call's
269
+ * answer in memory, until the next call starts or the session suspends or ends, so that
270
+ * a worker taking the session over across that call's lost answer gets it back
271
+ * (session.lostCall.answer). Set it when the application promises its users that the
272
+ * daemon retains no output; it holds for the whole session.
273
+ */
274
+ keepNoAnswer?: boolean;
240
275
  signal?: AbortSignal;
241
276
  };
277
+ /**
278
+ * A call that was sent once and whose answer never reached the worker that sent it, as a
279
+ * session taken over across it knows it (session.lostCall; Go: client.LostCall).
280
+ */
281
+ export type LostCall = {
282
+ /** The lost call's request digest. */
283
+ requestSha256: string;
284
+ /**
285
+ * The lost call's record, as the attach returned it and this client checked it, or
286
+ * undefined on a session attached from a checkpoint saved while recovering, which carries
287
+ * the request digest alone. It says whether the daemon answered the call: a result digest
288
+ * when it answered, which does not show that the call ran to its end (a step stopped at
289
+ * its time limit and a setup that failed are answers too), or an unanswered code when it
290
+ * ended without an answer, so that it may have done none, part or all of its work.
291
+ */
292
+ record?: RunRecord;
293
+ /**
294
+ * The lost call's answer when the daemon kept it and the attach returned it, checked
295
+ * against record (the same record, its result digest recomputed), or undefined: the call
296
+ * ended unanswered, the answer was above the daemon's cap, the session was opened with
297
+ * keepNoAnswer, or the daemon dropped it (a call started, or the session suspended,
298
+ * after the lost one).
299
+ */
300
+ answer?: LostAnswer;
301
+ };
302
+ /** A lost call's answer, by the kind of call it was: the result that call would have returned. */
303
+ export type LostAnswer = {
304
+ kind: "javascript";
305
+ result: JavaScriptResult;
306
+ } | {
307
+ kind: "project";
308
+ result: ProjectResult;
309
+ } | {
310
+ kind: "cell";
311
+ result: CellResult;
312
+ };
242
313
  /**
243
314
  * What an owner is sent as: hex(HMAC-SHA256(key = SHA-256("plimsoll session owner key
244
315
  * v2\n" + the client's token), message = "plimsoll session owner v2\n" + owner)), the
@@ -284,6 +355,7 @@ export declare class PlimsollClient {
284
355
  private readonly requestTimeoutMs;
285
356
  /** @internal */ readonly jsGrant: string;
286
357
  /** @internal */ readonly projectGrant: string;
358
+ /** @internal */ readonly daemonName: string | undefined;
287
359
  constructor(opts: ClientOptions);
288
360
  /** @internal One unary Connect call with the JSON codec. */
289
361
  call<T>(method: string, body: unknown, signal?: AbortSignal): Promise<T>;
@@ -291,9 +363,9 @@ export declare class PlimsollClient {
291
363
  describe(signal?: AbortSignal): Promise<Info>;
292
364
  private info;
293
365
  /** Runs a JavaScript snippet in a fresh sandbox. */
294
- runJavaScript(code: string, opts?: RunOptions): Promise<JavaScriptResult>;
366
+ runJavaScript(code: string, opts?: GrantRunOptions): Promise<JavaScriptResult>;
295
367
  /** Writes a multi-file project into a fresh sandbox and runs its steps in order. */
296
- runProject(req: ProjectRequest, opts?: RunOptions): Promise<ProjectResult>;
368
+ runProject(req: ProjectRequest, opts?: GrantRunOptions): Promise<ProjectResult>;
297
369
  /**
298
370
  * Runs a cell by itself: code for an interpreter of its language, its files written
299
371
  * into the work directory first, its final expression's value printed, in a sandbox
@@ -320,12 +392,55 @@ export declare class PlimsollClient {
320
392
  * states supportsSessions.
321
393
  */
322
394
  openSession(opts?: SessionOptions): Promise<Session>;
395
+ /**
396
+ * Takes over the session `cp` names and carries its chain on from cp's head (Go:
397
+ * Remote.AttachSession): the daemon raises the session's ownership generation by one, and
398
+ * every call or close a worker holding an older one sends is refused before it runs
399
+ * (StaleOwnerError).
400
+ *
401
+ * Refused here, with nothing sent, when cp does not validate, when it names another daemon
402
+ * than this client's daemonName, or when the client has none. The daemon refuses an
403
+ * unknown, ended or another caller's session as not found, a stale generation as
404
+ * StaleOwnerError and a checkpoint that is not its head (a call ran after cp was saved)
405
+ * as CheckpointMismatchError; open development mode refuses every attach.
406
+ *
407
+ * The answer must repeat cp exactly, else data_loss, and the session is not closed: a bad
408
+ * answer gives this client no right to destroy a session another worker may be using. A
409
+ * transport failure or an abort after sending is thrown as it is and never retried: the
410
+ * daemon may have raised the generation, so cp may already be stale.
411
+ *
412
+ * opts.lostRequestSha256 names the call this application believes ran after cp with no
413
+ * answer reaching it (session.lostRequestSha256 gives it for a call of this process).
414
+ * With it, the daemon takes the session over from a checkpoint exactly one call behind
415
+ * its head when its last record is that call, following cp (the explained gap), and
416
+ * returns the record, and the call's answer when the daemon still keeps it. The record
417
+ * must check on its own, be the call named, at cp's next place, stating the evidence the
418
+ * session stated at open, and be the new head; the answer must carry that same record
419
+ * and a result whose digest is the record's. A lost call's record the attach did not
420
+ * name, and a lost answer with no lost record, are refused as data_loss.
421
+ *
422
+ * A session attached across a lost call, or from a checkpoint saved while recovering, is
423
+ * recovering: session.lostCall says what it knows of the lost call, and every call is
424
+ * refused before it is sent (RecoveringError) until session.resolveLostCall().
425
+ */
426
+ attachSession(cp: SessionCheckpoint, opts?: {
427
+ traceId?: string;
428
+ signal?: AbortSignal;
429
+ lostRequestSha256?: string;
430
+ }): Promise<Session>;
431
+ private attached;
323
432
  /** @internal */
324
433
  envelope(opts: RunOptions, rule: WireSoftwareRule | undefined): WireEnvelope;
325
434
  private exchange;
326
435
  private checked;
327
436
  }
328
437
  /** @internal */
438
+ export declare function lostRecord(cp: SessionCheckpoint, lost: string, m: NonNullable<WireAttachSessionResponse["lostRecord"]>): {
439
+ record: RunRecord;
440
+ } | {
441
+ problem: string;
442
+ };
443
+ /** @internal */
329
444
  export declare function projectPayload(req: ProjectRequest, grantProfile: string): Payload;
330
445
  /**
331
446
  * An open session. Calls are serialized here as they are on the daemon, so the
@@ -340,18 +455,55 @@ export declare class Session {
340
455
  readonly fingerprint: string;
341
456
  /** The tier the daemon measured when the session opened. */
342
457
  readonly isolation: string;
458
+ /** The sentence the provider states beside that tier, "" when it states none. Every call's record states it too. */
459
+ readonly isolationQualification: string;
343
460
  readonly sandbox: string;
344
461
  /** The selected software the daemon stated at open. */
345
462
  readonly softwareIdentity: string;
346
463
  readonly expiresAtMs: number;
347
464
  readonly idleTimeoutMs: number;
348
465
  /** @internal */
349
- constructor(client: PlimsollClient, m: WireOpenSessionResponse, rule: WireSoftwareRule | undefined, floor?: Exclude<Isolation, "none">);
466
+ constructor(client: PlimsollClient, m: WireOpenSessionResponse, rule: WireSoftwareRule | undefined, floor?: Exclude<Isolation, "none">, attached?: {
467
+ generation: bigint;
468
+ calls: bigint;
469
+ last: string;
470
+ recovering: LostCall | undefined;
471
+ });
350
472
  /**
351
473
  * Why this client sends nothing more on the session, once a call ended without an
352
474
  * answer it could check (the call may have run); undefined while it is usable.
353
475
  */
354
476
  get stopped(): string | undefined;
477
+ /**
478
+ * The request digest of the call after which this session stopped with no answer it could
479
+ * check, or "": the call that may have run, for another worker's attachSession to name
480
+ * (lostRequestSha256) together with a checkpoint saved before it.
481
+ */
482
+ get lostRequestSha256(): string;
483
+ /**
484
+ * The call this session is recovering from, or undefined when it is not recovering: after
485
+ * an attach across an explained gap (attachSession with lostRequestSha256), or from a
486
+ * checkpoint saved while recovering, until resolveLostCall(). While it is defined every
487
+ * call is refused before it is sent (RecoveringError). Its record says whether the daemon
488
+ * answered the call, and its answer, when the daemon kept it, is that call's result.
489
+ */
490
+ get lostCall(): LostCall | undefined;
491
+ /**
492
+ * Ends the recovering state: the application has read the lost call (lostCall) and
493
+ * handled its outcome, or accepts it as unknown, and the session's calls are sent again.
494
+ * Taking the session over, or copying its head, does not resolve it. On a session that is
495
+ * not recovering it does nothing (Go: Session.ResolveLostCall).
496
+ */
497
+ resolveLostCall(): void;
498
+ /**
499
+ * The session's checkpoint (Go: Session.Checkpoint), for the application to save where
500
+ * only it can write, so another process can attachSession. It waits for a call in
501
+ * flight, so the head it states follows that call. Refused when the client has no
502
+ * daemonName and when the session is stopped, closed or ended. A session recovering from
503
+ * a lost call saves that state (recoveringRequestSha256), so the worker that attaches
504
+ * from it is recovering too.
505
+ */
506
+ checkpoint(): Promise<SessionCheckpoint>;
355
507
  /** The session's end once a response reported it, else undefined. */
356
508
  get ended(): {
357
509
  reason: SessionEnd;
@@ -374,13 +526,15 @@ export declare class Session {
374
526
  runCell(req: CellRequest, opts?: RunOptions): Promise<CellResult>;
375
527
  /**
376
528
  * Ends the session (or collects one that ended by itself) and checks the
377
- * daemon's count of executed calls against the chain this client saw. Every
378
- * later call returns the first one's promise, so its summary or its error, without
379
- * another request: the daemon forgets a session at its first close, and a second
380
- * CloseSession would be answered NotFound. The one exception is a close refused
381
- * not dispatched (its signal aborted before it was sent, say): it closed nothing,
382
- * so the next call tries again. The first call's signal is the one that applies.
529
+ * daemon's count of executed calls against the chain this client saw. Once the
530
+ * daemon has answered a close with its count, every later call returns that
531
+ * close's promise, so its summary or its error (a count that differs from this
532
+ * client's chain included), without another request: the daemon forgets a session
533
+ * at its first close, and a second CloseSession would be answered NotFound. A close
534
+ * that ended any other way (lost in transit, timed out, its signal aborted, refused
535
+ * by the daemon, as with "the session is still ending; close it again") is sent
536
+ * again by the next call (finding hunt-quality-90). A call made while a close is in
537
+ * flight shares it, and that close's signal is the one that applies.
383
538
  */
384
539
  close(signal?: AbortSignal): Promise<SessionSummary>;
385
540
  }
386
- export {};