@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/README.md +113 -4
- package/dist/ai-sdk.d.ts +20 -1
- package/dist/ai-sdk.js +28 -1
- package/dist/checkpoint.d.ts +42 -0
- package/dist/checkpoint.js +132 -0
- package/dist/client.d.ts +169 -15
- package/dist/client.js +395 -41
- package/dist/errors.d.ts +47 -4
- package/dist/errors.js +153 -10
- package/dist/granted.gen.d.ts +32 -0
- package/dist/granted.gen.js +33 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -1
- package/dist/mastra.d.ts +38 -1
- package/dist/mastra.js +23 -1
- package/dist/record.d.ts +62 -2
- package/dist/record.js +212 -49
- package/dist/sandboxes.d.ts +59 -1
- package/dist/sandboxes.js +179 -0
- package/dist/tables.gen.d.ts +76 -0
- package/dist/tables.gen.js +85 -2
- package/dist/tool.d.ts +13 -4
- package/dist/tool.js +57 -9
- package/dist/trigger.js +4 -1
- package/dist/wire.d.ts +72 -1
- package/dist/wire.js +52 -2
- package/package.json +2 -2
package/dist/tables.gen.d.ts
CHANGED
|
@@ -11,3 +11,79 @@ export declare const REFUSAL_NAMES: readonly ["unknown", "request", "permission"
|
|
|
11
11
|
export declare const TIERS: readonly ["none", "process", "container", "kernel", "vm"];
|
|
12
12
|
/** The languages plimsoll keeps an interpreter for (sandbox.Languages). */
|
|
13
13
|
export declare const LANGUAGES: readonly ["javascript", "python"];
|
|
14
|
+
/** The wire protocol number a client states on every request (protocol.Number). */
|
|
15
|
+
export declare const PROTOCOL = 8;
|
|
16
|
+
/** The header carrying a client's ID for one request, which the daemon echoes (protocol.RequestIDHeader). */
|
|
17
|
+
export declare const REQUEST_ID_HEADER = "Plimsoll-Request-Id";
|
|
18
|
+
/** The daemon's mark on an answer written before any handler ran (protocol.NotDispatchedHeader). */
|
|
19
|
+
export declare const NOT_DISPATCHED_HEADER = "Plimsoll-Not-Dispatched";
|
|
20
|
+
/** A correlation id's grammar; the daemon drops one outside it (protocol.TraceIDPattern). */
|
|
21
|
+
export declare const TRACE_ID_PATTERN = "^[A-Za-z0-9._:-]{1,64}$";
|
|
22
|
+
/** The text of a session call, close or attach refused because another worker attached (protocol.StaleOwnerText). */
|
|
23
|
+
export declare const STALE_OWNER_TEXT = "session ownership generation is stale";
|
|
24
|
+
/** The text of an attach refused because its checkpoint is not the session's head, and of a call refused because its head is not (protocol.CheckpointMismatchText). */
|
|
25
|
+
export declare const CHECKPOINT_MISMATCH_TEXT = "session checkpoint does not match";
|
|
26
|
+
/** The tiers a request may state as its floor, weakest first: every tier but none. */
|
|
27
|
+
export declare const FLOORS: readonly ["process", "container", "kernel", "vm"];
|
|
28
|
+
/** The record version a live answer carries (record.Version). */
|
|
29
|
+
export declare const RECORD_VERSION = 5;
|
|
30
|
+
/** Each published record version's digest fields, in order (record.PublishedLayouts). */
|
|
31
|
+
export declare const RECORD_FIELDS: Readonly<Record<number, readonly string[]>>;
|
|
32
|
+
/** The last record version whose daemons stamped both times from the wall clock; reading such a record that ends before it starts is retired (record.LastWallClockEndVersion). */
|
|
33
|
+
export declare const LAST_WALL_CLOCK_END_VERSION = 2;
|
|
34
|
+
/** The refusal of a version 1 or 2 record that ends before it starts: a retired reading, not a forgery (record.RetiredEndBeforeStartText). */
|
|
35
|
+
export declare const RETIRED_END_BEFORE_START_TEXT = "the record ends before it starts, and that reading is retired by the decision of 2026-11-21: records of versions 1 and 2 that end before they start are no longer read; daemons v0.10.0 to v0.12.0 could write one during a clock step";
|
|
36
|
+
/** The codes an unanswered call's record may name (record.UnansweredCodes). */
|
|
37
|
+
export declare const UNANSWERED_CODES: readonly ["aborted", "already_exists", "canceled", "data_loss", "deadline_exceeded", "failed_precondition", "internal", "invalid_argument", "not_found", "out_of_range", "permission_denied", "resource_exhausted", "unauthenticated", "unavailable", "unimplemented", "unknown"];
|
|
38
|
+
/** The most bytes an isolation qualification may take (record.MaxQualificationBytes). */
|
|
39
|
+
export declare const MAX_QUALIFICATION_BYTES = 1024;
|
|
40
|
+
/** The code points a qualification may not hold, as inclusive ranges (record.QualificationForbidden). */
|
|
41
|
+
export declare const QUALIFICATION_FORBIDDEN: readonly (readonly [number, number])[];
|
|
42
|
+
/** The most bytes a record's daemon version may take (record.MaxDaemonVersionBytes). */
|
|
43
|
+
export declare const MAX_DAEMON_VERSION_BYTES = 128;
|
|
44
|
+
/** A daemon version's grammar, when it is not empty (record.DaemonVersionPattern). */
|
|
45
|
+
export declare const DAEMON_VERSION_PATTERN = "^(?:\\(devel\\)|v[0-9]+\\.[0-9]+\\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?)$";
|
|
46
|
+
/** A typed instance reference's grammar, when it is not empty (sandbox.InstancePattern). */
|
|
47
|
+
export declare const INSTANCE_PATTERN = "^[a-z][a-z0-9-]{0,31}:[A-Za-z0-9._:-]{1,127}$";
|
|
48
|
+
/** The most bytes of code a snippet or a cell may carry (sandbox.MaxCodeBytes). */
|
|
49
|
+
export declare const MAX_CODE_BYTES = 262144;
|
|
50
|
+
/** The most bytes a request's files may hold together (sandbox.MaxProjectBytes). */
|
|
51
|
+
export declare const MAX_PROJECT_BYTES = 4194304;
|
|
52
|
+
/** The most files a request may write (sandbox.MaxProjectFiles). */
|
|
53
|
+
export declare const MAX_PROJECT_FILES = 200;
|
|
54
|
+
/** The most steps a project may run (sandbox.MaxProjectSteps). */
|
|
55
|
+
export declare const MAX_PROJECT_STEPS = 20;
|
|
56
|
+
/** The most artifacts a project may ask for (sandbox.MaxProjectArtifacts). */
|
|
57
|
+
export declare const MAX_PROJECT_ARTIFACTS = 100;
|
|
58
|
+
/** The most bytes a file or artifact path may take (sandbox.MaxProjectPathBytes). */
|
|
59
|
+
export declare const MAX_PROJECT_PATH_BYTES = 1024;
|
|
60
|
+
/** The most bytes one step's command may take (sandbox.MaxProjectStepBytes). */
|
|
61
|
+
export declare const MAX_PROJECT_STEP_BYTES = 16384;
|
|
62
|
+
/** The most parameter rows a module run may carry (sandbox.MaxModuleRows). */
|
|
63
|
+
export declare const MAX_MODULE_ROWS = 100000;
|
|
64
|
+
/** The most values one module row may carry (sandbox.MaxModuleRowWidth). */
|
|
65
|
+
export declare const MAX_MODULE_ROW_WIDTH = 64;
|
|
66
|
+
/** The most steps one module instance may take (sandbox.MaxModuleSteps). */
|
|
67
|
+
export declare const MAX_MODULE_STEPS = 1000000;
|
|
68
|
+
/** The most bytes a module run's results may take (sandbox.MaxModuleResultBytes). */
|
|
69
|
+
export declare const MAX_MODULE_RESULT_BYTES = 8388608;
|
|
70
|
+
/** The bytes a module run's results start with before the rows (sandbox.ModuleResultHeaderBytes). */
|
|
71
|
+
export declare const MODULE_RESULT_HEADER_BYTES = 20;
|
|
72
|
+
/** A model id's grammar (sandbox.ModuleIDPattern). */
|
|
73
|
+
export declare const MODULE_ID_PATTERN = "^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$";
|
|
74
|
+
/** The most identities an approved software rule may name (sandbox.MaxSoftwareIdentities). */
|
|
75
|
+
export declare const MAX_SOFTWARE_IDENTITIES = 32;
|
|
76
|
+
/** The most bytes one software identity may take (sandbox.MaxSoftwareIdentityBytes). */
|
|
77
|
+
export declare const MAX_SOFTWARE_IDENTITY_BYTES = 256;
|
|
78
|
+
/** The characters a software identity may hold (sandbox.SoftwareIdentityPattern). */
|
|
79
|
+
export declare const SOFTWARE_IDENTITY_PATTERN = "^[A-Za-z0-9._:/@+-]+$";
|
|
80
|
+
/** The largest answer a client reads (client.MaxResponseBytes). */
|
|
81
|
+
export declare const MAX_RESPONSE_BYTES = 33554432;
|
|
82
|
+
/** The one version of a session checkpoint the clients write and read (client.CheckpointVersion). */
|
|
83
|
+
export declare const CHECKPOINT_VERSION = 2;
|
|
84
|
+
/** A daemon name's grammar: the application's own name for a daemon, never a URL (client.DaemonNamePattern). */
|
|
85
|
+
export declare const DAEMON_NAME_PATTERN = "^[A-Za-z0-9._-]{1,64}$";
|
|
86
|
+
/** A software rule's ID as a checkpoint states it (client.SoftwareRuleIDPattern). */
|
|
87
|
+
export declare const SOFTWARE_RULE_ID_PATTERN = "^(?:exact:[A-Za-z0-9._:/@+-]{1,256}|approved:sha256:[0-9a-f]{64})$";
|
|
88
|
+
/** What a client says when it refuses a call on a session recovering from a call lost across a takeover (client.RecoveringText). */
|
|
89
|
+
export declare const RECOVERING_TEXT = "this session is recovering from a call whose answer was lost: read the lost call and resolve it before sending another call";
|
package/dist/tables.gen.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Code generated by internal/wiretables (make generate). DO NOT EDIT.
|
|
2
|
-
// The protocol's enums and
|
|
3
|
-
//
|
|
2
|
+
// The protocol's enums and the wire rules every client checks, from
|
|
3
|
+
// proto/plimsoll/v1/sandbox.proto and the Go packages that enforce them (protocol, record,
|
|
4
|
+
// sandbox, client), so this client and the Go and Python ones cannot drift apart.
|
|
4
5
|
/** plimsoll.v1.ProjectOutcome, by number. */
|
|
5
6
|
export const OUTCOMES = {
|
|
6
7
|
PROJECT_OUTCOME_UNSPECIFIED: 0,
|
|
@@ -42,3 +43,85 @@ export const REFUSAL_NAMES = ["unknown", "request", "permission", "protocol", "u
|
|
|
42
43
|
export const TIERS = ["none", "process", "container", "kernel", "vm"];
|
|
43
44
|
/** The languages plimsoll keeps an interpreter for (sandbox.Languages). */
|
|
44
45
|
export const LANGUAGES = ["javascript", "python"];
|
|
46
|
+
/** The wire protocol number a client states on every request (protocol.Number). */
|
|
47
|
+
export const PROTOCOL = 8;
|
|
48
|
+
/** The header carrying a client's ID for one request, which the daemon echoes (protocol.RequestIDHeader). */
|
|
49
|
+
export const REQUEST_ID_HEADER = "Plimsoll-Request-Id";
|
|
50
|
+
/** The daemon's mark on an answer written before any handler ran (protocol.NotDispatchedHeader). */
|
|
51
|
+
export const NOT_DISPATCHED_HEADER = "Plimsoll-Not-Dispatched";
|
|
52
|
+
/** A correlation id's grammar; the daemon drops one outside it (protocol.TraceIDPattern). */
|
|
53
|
+
export const TRACE_ID_PATTERN = "^[A-Za-z0-9._:-]{1,64}$";
|
|
54
|
+
/** The text of a session call, close or attach refused because another worker attached (protocol.StaleOwnerText). */
|
|
55
|
+
export const STALE_OWNER_TEXT = "session ownership generation is stale";
|
|
56
|
+
/** The text of an attach refused because its checkpoint is not the session's head, and of a call refused because its head is not (protocol.CheckpointMismatchText). */
|
|
57
|
+
export const CHECKPOINT_MISMATCH_TEXT = "session checkpoint does not match";
|
|
58
|
+
/** The tiers a request may state as its floor, weakest first: every tier but none. */
|
|
59
|
+
export const FLOORS = ["process", "container", "kernel", "vm"];
|
|
60
|
+
/** The record version a live answer carries (record.Version). */
|
|
61
|
+
export const RECORD_VERSION = 5;
|
|
62
|
+
/** Each published record version's digest fields, in order (record.PublishedLayouts). */
|
|
63
|
+
export const RECORD_FIELDS = {
|
|
64
|
+
1: ["request_sha256", "result_sha256", "provider", "isolation", "environment", "policy", "started_unix_ms", "ended_unix_ms", "session", "sequence", "previous_sha256"],
|
|
65
|
+
2: ["request_sha256", "result_sha256", "provider", "isolation", "environment", "policy", "software_identity", "software_rule_id", "started_unix_ms", "ended_unix_ms", "session", "sequence", "previous_sha256"],
|
|
66
|
+
3: ["request_sha256", "result_sha256", "unanswered", "provider", "isolation", "environment", "policy", "software_identity", "software_rule_id", "started_unix_ms", "ended_unix_ms", "session", "sequence", "previous_sha256"],
|
|
67
|
+
4: ["request_sha256", "result_sha256", "unanswered", "provider", "isolation", "environment", "policy", "software_identity", "software_rule_id", "instance", "started_unix_ms", "ended_unix_ms", "session", "sequence", "previous_sha256"],
|
|
68
|
+
5: ["request_sha256", "result_sha256", "unanswered", "provider", "isolation", "isolation_qualification", "environment", "policy", "software_identity", "software_rule_id", "instance", "warm", "daemon_version", "started_unix_ms", "ended_unix_ms", "session", "sequence", "previous_sha256"],
|
|
69
|
+
};
|
|
70
|
+
/** The last record version whose daemons stamped both times from the wall clock; reading such a record that ends before it starts is retired (record.LastWallClockEndVersion). */
|
|
71
|
+
export const LAST_WALL_CLOCK_END_VERSION = 2;
|
|
72
|
+
/** The refusal of a version 1 or 2 record that ends before it starts: a retired reading, not a forgery (record.RetiredEndBeforeStartText). */
|
|
73
|
+
export const RETIRED_END_BEFORE_START_TEXT = "the record ends before it starts, and that reading is retired by the decision of 2026-11-21: records of versions 1 and 2 that end before they start are no longer read; daemons v0.10.0 to v0.12.0 could write one during a clock step";
|
|
74
|
+
/** The codes an unanswered call's record may name (record.UnansweredCodes). */
|
|
75
|
+
export const UNANSWERED_CODES = ["aborted", "already_exists", "canceled", "data_loss", "deadline_exceeded", "failed_precondition", "internal", "invalid_argument", "not_found", "out_of_range", "permission_denied", "resource_exhausted", "unauthenticated", "unavailable", "unimplemented", "unknown"];
|
|
76
|
+
/** The most bytes an isolation qualification may take (record.MaxQualificationBytes). */
|
|
77
|
+
export const MAX_QUALIFICATION_BYTES = 1024;
|
|
78
|
+
/** The code points a qualification may not hold, as inclusive ranges (record.QualificationForbidden). */
|
|
79
|
+
export const QUALIFICATION_FORBIDDEN = [[0x0000, 0x001F], [0x007F, 0x009F], [0x061C, 0x061C], [0x200E, 0x200E], [0x200F, 0x200F], [0x2028, 0x2028], [0x2029, 0x2029], [0x202A, 0x202E], [0x2066, 0x2069]];
|
|
80
|
+
/** The most bytes a record's daemon version may take (record.MaxDaemonVersionBytes). */
|
|
81
|
+
export const MAX_DAEMON_VERSION_BYTES = 128;
|
|
82
|
+
/** A daemon version's grammar, when it is not empty (record.DaemonVersionPattern). */
|
|
83
|
+
export const DAEMON_VERSION_PATTERN = "^(?:\\(devel\\)|v[0-9]+\\.[0-9]+\\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?)$";
|
|
84
|
+
/** A typed instance reference's grammar, when it is not empty (sandbox.InstancePattern). */
|
|
85
|
+
export const INSTANCE_PATTERN = "^[a-z][a-z0-9-]{0,31}:[A-Za-z0-9._:-]{1,127}$";
|
|
86
|
+
/** The most bytes of code a snippet or a cell may carry (sandbox.MaxCodeBytes). */
|
|
87
|
+
export const MAX_CODE_BYTES = 262144;
|
|
88
|
+
/** The most bytes a request's files may hold together (sandbox.MaxProjectBytes). */
|
|
89
|
+
export const MAX_PROJECT_BYTES = 4194304;
|
|
90
|
+
/** The most files a request may write (sandbox.MaxProjectFiles). */
|
|
91
|
+
export const MAX_PROJECT_FILES = 200;
|
|
92
|
+
/** The most steps a project may run (sandbox.MaxProjectSteps). */
|
|
93
|
+
export const MAX_PROJECT_STEPS = 20;
|
|
94
|
+
/** The most artifacts a project may ask for (sandbox.MaxProjectArtifacts). */
|
|
95
|
+
export const MAX_PROJECT_ARTIFACTS = 100;
|
|
96
|
+
/** The most bytes a file or artifact path may take (sandbox.MaxProjectPathBytes). */
|
|
97
|
+
export const MAX_PROJECT_PATH_BYTES = 1024;
|
|
98
|
+
/** The most bytes one step's command may take (sandbox.MaxProjectStepBytes). */
|
|
99
|
+
export const MAX_PROJECT_STEP_BYTES = 16384;
|
|
100
|
+
/** The most parameter rows a module run may carry (sandbox.MaxModuleRows). */
|
|
101
|
+
export const MAX_MODULE_ROWS = 100000;
|
|
102
|
+
/** The most values one module row may carry (sandbox.MaxModuleRowWidth). */
|
|
103
|
+
export const MAX_MODULE_ROW_WIDTH = 64;
|
|
104
|
+
/** The most steps one module instance may take (sandbox.MaxModuleSteps). */
|
|
105
|
+
export const MAX_MODULE_STEPS = 1000000;
|
|
106
|
+
/** The most bytes a module run's results may take (sandbox.MaxModuleResultBytes). */
|
|
107
|
+
export const MAX_MODULE_RESULT_BYTES = 8388608;
|
|
108
|
+
/** The bytes a module run's results start with before the rows (sandbox.ModuleResultHeaderBytes). */
|
|
109
|
+
export const MODULE_RESULT_HEADER_BYTES = 20;
|
|
110
|
+
/** A model id's grammar (sandbox.ModuleIDPattern). */
|
|
111
|
+
export const MODULE_ID_PATTERN = "^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$";
|
|
112
|
+
/** The most identities an approved software rule may name (sandbox.MaxSoftwareIdentities). */
|
|
113
|
+
export const MAX_SOFTWARE_IDENTITIES = 32;
|
|
114
|
+
/** The most bytes one software identity may take (sandbox.MaxSoftwareIdentityBytes). */
|
|
115
|
+
export const MAX_SOFTWARE_IDENTITY_BYTES = 256;
|
|
116
|
+
/** The characters a software identity may hold (sandbox.SoftwareIdentityPattern). */
|
|
117
|
+
export const SOFTWARE_IDENTITY_PATTERN = "^[A-Za-z0-9._:/@+-]+$";
|
|
118
|
+
/** The largest answer a client reads (client.MaxResponseBytes). */
|
|
119
|
+
export const MAX_RESPONSE_BYTES = 33554432;
|
|
120
|
+
/** The one version of a session checkpoint the clients write and read (client.CheckpointVersion). */
|
|
121
|
+
export const CHECKPOINT_VERSION = 2;
|
|
122
|
+
/** A daemon name's grammar: the application's own name for a daemon, never a URL (client.DaemonNamePattern). */
|
|
123
|
+
export const DAEMON_NAME_PATTERN = "^[A-Za-z0-9._-]{1,64}$";
|
|
124
|
+
/** A software rule's ID as a checkpoint states it (client.SoftwareRuleIDPattern). */
|
|
125
|
+
export const SOFTWARE_RULE_ID_PATTERN = "^(?:exact:[A-Za-z0-9._:/@+-]{1,256}|approved:sha256:[0-9a-f]{64})$";
|
|
126
|
+
/** What a client says when it refuses a call on a session recovering from a call lost across a takeover (client.RecoveringText). */
|
|
127
|
+
export const RECOVERING_TEXT = "this session is recovering from a call whose answer was lost: read the lost call and resolve it before sending another call";
|
package/dist/tool.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import type { Language } from "./client.ts";
|
|
3
|
+
import { type GrantPlan, type ToolLanguages } from "./sandboxes.ts";
|
|
4
|
+
/**
|
|
5
|
+
* What a granted tool tells its model about the API, in the same words as the Python
|
|
6
|
+
* kits' (plimsoll_client._code_tool.api_text): the routes are the only requests sent, the
|
|
7
|
+
* credential is added outside, the budget, what a call that changes data means, and how
|
|
8
|
+
* each offered language calls it; then the API's description as the application gave it.
|
|
9
|
+
*/
|
|
10
|
+
export declare function apiText(languages: readonly Language[], plan: GrantPlan): string;
|
|
11
|
+
/** The tool's description for the languages it offers, and with a grant plan what its code can call. */
|
|
12
|
+
export declare function executeCodeDescription(languages?: ToolLanguages, scope?: "fresh" | "conversation", plan?: GrantPlan): string;
|
|
5
13
|
/** The tool's input schema for the languages it offers. */
|
|
6
|
-
export declare function executeCodeInput(languages?: ToolLanguages): z.ZodObject<{
|
|
14
|
+
export declare function executeCodeInput(languages?: ToolLanguages, granted?: boolean): z.ZodObject<{
|
|
7
15
|
code: z.ZodString;
|
|
8
16
|
language: z.ZodDefault<z.ZodEnum<{
|
|
9
17
|
javascript: "javascript";
|
|
@@ -28,5 +36,6 @@ export declare const executeCodeOutput: z.ZodObject<{
|
|
|
28
36
|
filesPersist: z.ZodBoolean;
|
|
29
37
|
freshSandbox: z.ZodOptional<z.ZodLiteral<true>>;
|
|
30
38
|
isolation: z.ZodString;
|
|
39
|
+
isolationQualification: z.ZodOptional<z.ZodString>;
|
|
31
40
|
recordSha256: z.ZodString;
|
|
32
41
|
}, z.core.$strip>;
|
package/dist/tool.js
CHANGED
|
@@ -2,12 +2,59 @@
|
|
|
2
2
|
// tools describe the same thing in the same words, with explicit fresh-call scope.
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { DEFAULT_LANGUAGES } from "./sandboxes.js";
|
|
5
|
+
import { MAX_PROJECT_FILES } from "./tables.gen.js";
|
|
5
6
|
const NAMES = { python: "Python", javascript: "JavaScript (Node.js)" };
|
|
6
|
-
// The daemon accepts
|
|
7
|
-
// files, so the shared tool schema
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
// The daemon accepts MAX_PROJECT_FILES project files. A fresh call adds its runner and
|
|
8
|
+
// code files, so the shared tool schema leaves those two slots available; a granted
|
|
9
|
+
// tool one more, for the plimsoll_host module a granted Python call carries.
|
|
10
|
+
const MAX_INPUT_FILES = MAX_PROJECT_FILES - 2;
|
|
11
|
+
// How JavaScript calls the API: in a granted project's cell form, top-level await works; in
|
|
12
|
+
// the snippet form a daemon that runs snippets only gets (sandbox.SnippetCell, evaluated as a
|
|
13
|
+
// script), it does not, and a final promise is printed once it settles.
|
|
14
|
+
const CELL_JS = "In JavaScript, call it through the global client the description names, as it shows; each call returns a promise, so await it.";
|
|
15
|
+
const SNIPPET_JS = "In JavaScript, call it through the global client the description names, as it shows; each call returns a promise. " +
|
|
16
|
+
"Top-level await does not work in this sandbox: put the calls in an async function and end the code with its call, " +
|
|
17
|
+
"(async () => { ... return value; })(), whose value is printed once it settles.";
|
|
18
|
+
/**
|
|
19
|
+
* What a granted tool tells its model about the API, in the same words as the Python
|
|
20
|
+
* kits' (plimsoll_client._code_tool.api_text): the routes are the only requests sent, the
|
|
21
|
+
* credential is added outside, the budget, what a call that changes data means, and how
|
|
22
|
+
* each offered language calls it; then the API's description as the application gave it.
|
|
23
|
+
*/
|
|
24
|
+
export function apiText(languages, plan) {
|
|
25
|
+
const lines = [
|
|
26
|
+
"This tool's code can call one web API, described below, from inside the sandbox. Only its routes listed below " +
|
|
27
|
+
"(each a method and a path) are sent to it: any other request is refused before it leaves, and so is a call " +
|
|
28
|
+
"past the run's call budget (status 429). plimsoll adds the API's key outside the sandbox; the code never needs " +
|
|
29
|
+
"one. A call that changes data takes effect even if the program fails afterwards, and a run is never retried.",
|
|
30
|
+
];
|
|
31
|
+
if (languages.includes("javascript")) {
|
|
32
|
+
lines.push(plan.snippets ? SNIPPET_JS : CELL_JS);
|
|
33
|
+
}
|
|
34
|
+
if (languages.includes("python")) {
|
|
35
|
+
lines.push("In Python, import plimsoll_host and call plimsoll_host.get(path), post(path, body), put(path, body), " +
|
|
36
|
+
"patch(path, body), delete(path) or call(method, path, body) with a route's method and path from the " +
|
|
37
|
+
"list below; each returns the answer's parsed JSON and raises plimsoll_host.HostAPIError, which has " +
|
|
38
|
+
".status and .body, for any other status.");
|
|
39
|
+
}
|
|
40
|
+
else if (!plan.languages.includes("python")) {
|
|
41
|
+
lines.push(`Python code cannot call the API on this sandbox (its provider, ${plan.provider}, gives a Python step no way to reach it).`);
|
|
42
|
+
}
|
|
43
|
+
lines.push("The API:\n" + plan.apiDescription);
|
|
44
|
+
return lines.join("\n");
|
|
45
|
+
}
|
|
46
|
+
/** The tool's description for the languages it offers, and with a grant plan what its code can call. */
|
|
47
|
+
export function executeCodeDescription(languages = DEFAULT_LANGUAGES, scope = "conversation", plan) {
|
|
48
|
+
if (plan) {
|
|
49
|
+
const names = languages.map((l) => NAMES[l]).join(" or ");
|
|
50
|
+
return (`Run ${names} in an isolated sandbox with no network access except the one web API described below, and return its exit code, stdout and stderr. ` +
|
|
51
|
+
"The value of the code's last expression is printed, as in a notebook, so the last line can simply name what you want to see. " +
|
|
52
|
+
"Every call uses a fresh sandbox and interpreter: no earlier variable, import or file is retained, because a call that can reach the API never runs in a kept sandbox, so kept state between calls is not available to this tool. stateKept and filesPersist are false. " +
|
|
53
|
+
"To give the code data, such as another tool's output, pass it in files rather than pasting it into the code; the code reads each file by its relative path. " +
|
|
54
|
+
"The result also reports the isolation tier, the sentence its provider requires beside that tier when it states one (isolationQualification), and the SHA-256 of the run record the client checked." +
|
|
55
|
+
"\n\n" +
|
|
56
|
+
apiText(languages, plan));
|
|
57
|
+
}
|
|
11
58
|
const names = languages.map((l) => NAMES[l]).join(" or ");
|
|
12
59
|
const state = scope === "fresh"
|
|
13
60
|
? "Every call uses a fresh sandbox and interpreter: no earlier variable, import or file is retained. stateKept and filesPersist are false. "
|
|
@@ -17,14 +64,14 @@ export function executeCodeDescription(languages = DEFAULT_LANGUAGES, scope = "c
|
|
|
17
64
|
"this call's interpreter had just started, so nothing earlier calls defined exists and has to be rebuilt; freshSandbox means no file from " +
|
|
18
65
|
"earlier calls is there either. " +
|
|
19
66
|
"Files written to the working directory can still be there on the next call when filesPersist is true; freshSandbox on that call says they are not. ";
|
|
20
|
-
return (`Run ${names} in an isolated sandbox with no network access
|
|
67
|
+
return (`Run ${names} in an isolated sandbox with no network access and return its exit code, stdout and stderr. ` +
|
|
21
68
|
"The value of the code's last expression is printed, as in a notebook, so the last line can simply name what you want to see. " +
|
|
22
69
|
state +
|
|
23
70
|
"To give the code data, such as another tool's output, pass it in files rather than pasting it into the code; the code reads each file by its relative path. " +
|
|
24
|
-
"The result also reports the isolation tier and the SHA-256 of the run record the client checked.");
|
|
71
|
+
"The result also reports the isolation tier, the sentence its provider requires beside that tier when it states one (isolationQualification), and the SHA-256 of the run record the client checked.");
|
|
25
72
|
}
|
|
26
73
|
/** The tool's input schema for the languages it offers. */
|
|
27
|
-
export function executeCodeInput(languages = DEFAULT_LANGUAGES) {
|
|
74
|
+
export function executeCodeInput(languages = DEFAULT_LANGUAGES, granted = false) {
|
|
28
75
|
return z.object({
|
|
29
76
|
code: z.string().min(1).describe("The source code to run. Print what you need, or end with an expression to show its value."),
|
|
30
77
|
language: z
|
|
@@ -36,7 +83,7 @@ export function executeCodeInput(languages = DEFAULT_LANGUAGES) {
|
|
|
36
83
|
path: z.string().min(1).describe("A relative path, such as data/orders.csv."),
|
|
37
84
|
content: z.string().describe("The file's text."),
|
|
38
85
|
}))
|
|
39
|
-
.max(MAX_INPUT_FILES)
|
|
86
|
+
.max(granted ? MAX_INPUT_FILES - 1 : MAX_INPUT_FILES)
|
|
40
87
|
.optional()
|
|
41
88
|
.describe("Text files written into the working directory before the code runs, for data the code should read."),
|
|
42
89
|
});
|
|
@@ -53,5 +100,6 @@ export const executeCodeOutput = z.object({
|
|
|
53
100
|
filesPersist: z.boolean(),
|
|
54
101
|
freshSandbox: z.literal(true).optional(),
|
|
55
102
|
isolation: z.string(),
|
|
103
|
+
isolationQualification: z.string().optional(),
|
|
56
104
|
recordSha256: z.string().regex(/^[0-9a-f]{64}$/),
|
|
57
105
|
});
|
package/dist/trigger.js
CHANGED
|
@@ -9,9 +9,12 @@
|
|
|
9
9
|
// stay in this process, and the owner is a user's identity.
|
|
10
10
|
import { chat } from "@trigger.dev/sdk/ai";
|
|
11
11
|
import { tool } from "ai";
|
|
12
|
-
import { CodeSandboxes } from "./sandboxes.js";
|
|
12
|
+
import { CodeSandboxes, refuseGrant } from "./sandboxes.js";
|
|
13
13
|
import { executeCodeDescription, executeCodeInput } from "./tool.js";
|
|
14
14
|
export function plimsollCodeSandbox(opts) {
|
|
15
|
+
// A granted call cannot keep the run's sandbox; a chat that calls the operator's API
|
|
16
|
+
// builds the AI SDK add-on's plimsollGrantedCodeTool inside its run instead.
|
|
17
|
+
refuseGrant(opts, "plimsollGrantedCodeTool from @plimsollmark/client/ai-sdk, inside the run");
|
|
15
18
|
const sandboxes = new CodeSandboxes(opts);
|
|
16
19
|
const current = chat.local({ id: opts.localId ?? "plimsollCodeSandbox" });
|
|
17
20
|
// The owner warm named for each run, in this module's memory only.
|
package/dist/wire.d.ts
CHANGED
|
@@ -38,8 +38,14 @@ export type WireRunRequest = WireEnvelope & {
|
|
|
38
38
|
project?: WireProjectRun;
|
|
39
39
|
cell?: WireCellRun;
|
|
40
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* A session call: the run request with the session ID and the head the call expects to run
|
|
43
|
+
* on (the current ownership generation, the count of calls and the last record's digest);
|
|
44
|
+
* the daemon runs it only on that head (protocol 8).
|
|
45
|
+
*/
|
|
41
46
|
export type WireSessionRunRequest = WireRunRequest & {
|
|
42
47
|
sessionId: string;
|
|
48
|
+
head: WireSessionCheckpoint;
|
|
43
49
|
};
|
|
44
50
|
export type WireRecord = {
|
|
45
51
|
version?: number;
|
|
@@ -58,6 +64,9 @@ export type WireRecord = {
|
|
|
58
64
|
softwareIdentity?: string;
|
|
59
65
|
softwareRuleId?: string;
|
|
60
66
|
instance?: string;
|
|
67
|
+
isolationQualification?: string;
|
|
68
|
+
warm?: boolean;
|
|
69
|
+
daemonVersion?: string;
|
|
61
70
|
recordSha256?: string;
|
|
62
71
|
};
|
|
63
72
|
export type WireAdvice = {
|
|
@@ -122,6 +131,8 @@ export type WireRunResponse = {
|
|
|
122
131
|
environment?: string;
|
|
123
132
|
instance?: string;
|
|
124
133
|
warm?: boolean;
|
|
134
|
+
isolationQualification?: string;
|
|
135
|
+
daemonVersion?: string;
|
|
125
136
|
javascript?: WireJavaScriptResult;
|
|
126
137
|
project?: WireProjectResult;
|
|
127
138
|
module?: unknown;
|
|
@@ -175,8 +186,14 @@ export type WireOpenSessionRequest = {
|
|
|
175
186
|
languages?: string[];
|
|
176
187
|
owner?: string;
|
|
177
188
|
warmOnly?: boolean;
|
|
189
|
+
/** Keep no call's answer for a takeover (protocol 8): the daemon then retains no output. */
|
|
190
|
+
keepNoAnswer?: boolean;
|
|
178
191
|
};
|
|
179
192
|
export type WireOpenSessionResponse = {
|
|
193
|
+
generation?: string | number;
|
|
194
|
+
/** The floor and software rule the open sent, as the daemon keeps them. */
|
|
195
|
+
minimumIsolation?: string;
|
|
196
|
+
softwareRule?: WireSoftwareRule;
|
|
180
197
|
sessionId?: string;
|
|
181
198
|
session?: string;
|
|
182
199
|
sandbox?: string;
|
|
@@ -184,6 +201,32 @@ export type WireOpenSessionResponse = {
|
|
|
184
201
|
expiresUnixMs?: string | number;
|
|
185
202
|
idleTimeoutMs?: number;
|
|
186
203
|
softwareIdentity?: string;
|
|
204
|
+
isolationQualification?: string;
|
|
205
|
+
};
|
|
206
|
+
export type WireCloseSessionRequest = {
|
|
207
|
+
protocol: number;
|
|
208
|
+
sessionId: string;
|
|
209
|
+
generation: string;
|
|
210
|
+
};
|
|
211
|
+
/** A session's public chain head, the uint64s as decimal strings (plimsoll.v1.SessionCheckpoint). */
|
|
212
|
+
export type WireSessionCheckpoint = {
|
|
213
|
+
generation?: string | number;
|
|
214
|
+
calls?: string | number;
|
|
215
|
+
lastRecordSha256?: string;
|
|
216
|
+
};
|
|
217
|
+
export type WireAttachSessionRequest = {
|
|
218
|
+
protocol: number;
|
|
219
|
+
session: string;
|
|
220
|
+
checkpoint: WireSessionCheckpoint;
|
|
221
|
+
traceId?: string;
|
|
222
|
+
lostRequestSha256?: string;
|
|
223
|
+
};
|
|
224
|
+
/** lostAnswer comes only beside lostRecord: the lost call's answer, when the daemon kept it (protocol 8). */
|
|
225
|
+
export type WireAttachSessionResponse = {
|
|
226
|
+
sessionInfo?: WireOpenSessionResponse;
|
|
227
|
+
checkpoint?: WireSessionCheckpoint;
|
|
228
|
+
lostRecord?: WireRecord;
|
|
229
|
+
lostAnswer?: WireRunResponse;
|
|
187
230
|
};
|
|
188
231
|
export type WireCloseSessionResponse = {
|
|
189
232
|
session?: string;
|
|
@@ -200,6 +243,21 @@ export type WireError = {
|
|
|
200
243
|
value?: string;
|
|
201
244
|
}[];
|
|
202
245
|
};
|
|
246
|
+
/**
|
|
247
|
+
* Reads an integer field of the daemon's answer: a JSON number that is a safe integer, or a
|
|
248
|
+
* string that is one whole decimal (an optional minus and digits with no leading zero, the
|
|
249
|
+
* form every client writes), within [lo, hi]. Anything else ("5 6", "5,", "5" and a zero
|
|
250
|
+
* byte, "05", " 5", "5.0", "5e0", "0x5") is not read: undefined, never a value read from its
|
|
251
|
+
* leading digits or by BigInt's and Number's looser grammars. Absent is 0. Go reads integer
|
|
252
|
+
* strings the same way (record.UnmarshalJSON), where protojson alone reads "5 6" as 5
|
|
253
|
+
* (finding release-90).
|
|
254
|
+
*/
|
|
255
|
+
export declare function wholeInt(v: unknown, [lo, hi]: readonly [bigint, bigint]): bigint | undefined;
|
|
256
|
+
/** The ranges of the protobuf integer kinds, for wholeInt. */
|
|
257
|
+
export declare const UINT32: readonly [bigint, bigint];
|
|
258
|
+
export declare const INT32: readonly [bigint, bigint];
|
|
259
|
+
export declare const UINT64: readonly [bigint, bigint];
|
|
260
|
+
export declare const INT64: readonly [bigint, bigint];
|
|
203
261
|
/** A bytes field that is not base64 text: the answer is not the protocol's. */
|
|
204
262
|
export declare class WireShapeError extends Error {
|
|
205
263
|
}
|
|
@@ -208,6 +266,19 @@ export declare class WireShapeError extends Error {
|
|
|
208
266
|
* accepted: the answer is parsed JSON, and Buffer.from given an object with a
|
|
209
267
|
* "length" allocates that many bytes and reads each index, so a 30-byte
|
|
210
268
|
* {"length":2000000000} would cost 2 GB and a blocked event loop past the
|
|
211
|
-
* response's 32 MiB cap (
|
|
269
|
+
* response's 32 MiB cap (security scan, 2026-10-27).
|
|
270
|
+
*
|
|
271
|
+
* The text must be base64 throughout, standard or URL-safe, padded or not, as protobuf
|
|
272
|
+
* JSON and Connect error details may carry it, and as the Python client reads it:
|
|
273
|
+
* Buffer.from skips any character outside the alphabet, so "CAY!" read as "CAY", and a
|
|
274
|
+
* refusal detail with a stray character marked a call nothing ran in where the Go and
|
|
275
|
+
* Python clients believe nothing of the detail (finding hunt-quality-93).
|
|
276
|
+
*
|
|
277
|
+
* The padding is counted off the end, not stripped with a pattern: /=+$/ is tried from
|
|
278
|
+
* every "=" of a run that is not at the end, so an answer holding a million "=" and one
|
|
279
|
+
* letter took minutes on one synchronous call that no deadline can cut (finding
|
|
280
|
+
* hunt-security-35). The alphabet test left is one anchored character class: one pass.
|
|
212
281
|
*/
|
|
213
282
|
export declare function wireBytes(v: unknown): Buffer;
|
|
283
|
+
/** How many times ch (one UTF-16 unit) ends s, counted from the end in one pass. */
|
|
284
|
+
export declare function trailing(s: string, ch: string): number;
|
package/dist/wire.js
CHANGED
|
@@ -3,6 +3,32 @@
|
|
|
3
3
|
// JSON names; bytes are base64; 64-bit integers arrive as strings; enums as their
|
|
4
4
|
// names; a field at its zero value is omitted, which is why everything read is
|
|
5
5
|
// optional.
|
|
6
|
+
// At most 20 digits: a 64-bit number has no more, and the test stays one short pass.
|
|
7
|
+
const WHOLE_DECIMAL = /^-?(?:0|[1-9][0-9]{0,19})$/;
|
|
8
|
+
/**
|
|
9
|
+
* Reads an integer field of the daemon's answer: a JSON number that is a safe integer, or a
|
|
10
|
+
* string that is one whole decimal (an optional minus and digits with no leading zero, the
|
|
11
|
+
* form every client writes), within [lo, hi]. Anything else ("5 6", "5,", "5" and a zero
|
|
12
|
+
* byte, "05", " 5", "5.0", "5e0", "0x5") is not read: undefined, never a value read from its
|
|
13
|
+
* leading digits or by BigInt's and Number's looser grammars. Absent is 0. Go reads integer
|
|
14
|
+
* strings the same way (record.UnmarshalJSON), where protojson alone reads "5 6" as 5
|
|
15
|
+
* (finding release-90).
|
|
16
|
+
*/
|
|
17
|
+
export function wholeInt(v, [lo, hi]) {
|
|
18
|
+
let n;
|
|
19
|
+
if (v === undefined || v === null)
|
|
20
|
+
n = 0n;
|
|
21
|
+
else if (typeof v === "number" && Number.isSafeInteger(v))
|
|
22
|
+
n = BigInt(v);
|
|
23
|
+
else if (typeof v === "string" && WHOLE_DECIMAL.test(v))
|
|
24
|
+
n = BigInt(v);
|
|
25
|
+
return n !== undefined && n >= lo && n <= hi ? n : undefined;
|
|
26
|
+
}
|
|
27
|
+
/** The ranges of the protobuf integer kinds, for wholeInt. */
|
|
28
|
+
export const UINT32 = [0n, (1n << 32n) - 1n];
|
|
29
|
+
export const INT32 = [-(1n << 31n), (1n << 31n) - 1n];
|
|
30
|
+
export const UINT64 = [0n, (1n << 64n) - 1n];
|
|
31
|
+
export const INT64 = [-(1n << 63n), (1n << 63n) - 1n];
|
|
6
32
|
/** A bytes field that is not base64 text: the answer is not the protocol's. */
|
|
7
33
|
export class WireShapeError extends Error {
|
|
8
34
|
}
|
|
@@ -11,12 +37,36 @@ export class WireShapeError extends Error {
|
|
|
11
37
|
* accepted: the answer is parsed JSON, and Buffer.from given an object with a
|
|
12
38
|
* "length" allocates that many bytes and reads each index, so a 30-byte
|
|
13
39
|
* {"length":2000000000} would cost 2 GB and a blocked event loop past the
|
|
14
|
-
* response's 32 MiB cap (
|
|
40
|
+
* response's 32 MiB cap (security scan, 2026-10-27).
|
|
41
|
+
*
|
|
42
|
+
* The text must be base64 throughout, standard or URL-safe, padded or not, as protobuf
|
|
43
|
+
* JSON and Connect error details may carry it, and as the Python client reads it:
|
|
44
|
+
* Buffer.from skips any character outside the alphabet, so "CAY!" read as "CAY", and a
|
|
45
|
+
* refusal detail with a stray character marked a call nothing ran in where the Go and
|
|
46
|
+
* Python clients believe nothing of the detail (finding hunt-quality-93).
|
|
47
|
+
*
|
|
48
|
+
* The padding is counted off the end, not stripped with a pattern: /=+$/ is tried from
|
|
49
|
+
* every "=" of a run that is not at the end, so an answer holding a million "=" and one
|
|
50
|
+
* letter took minutes on one synchronous call that no deadline can cut (finding
|
|
51
|
+
* hunt-security-35). The alphabet test left is one anchored character class: one pass.
|
|
15
52
|
*/
|
|
16
53
|
export function wireBytes(v) {
|
|
17
54
|
if (v === undefined || v === null)
|
|
18
55
|
return Buffer.alloc(0);
|
|
19
56
|
if (typeof v !== "string")
|
|
20
57
|
throw new WireShapeError(`a bytes field holds a ${Array.isArray(v) ? "list" : typeof v}, not base64 text`);
|
|
21
|
-
|
|
58
|
+
const core = v.slice(0, v.length - trailing(v, "="));
|
|
59
|
+
// Node's base64 decoder reads both alphabets, as Python's does with its URL-safe
|
|
60
|
+
// characters translated.
|
|
61
|
+
if (!/^[A-Za-z0-9+/_-]*$/.test(core) || core.length % 4 === 1)
|
|
62
|
+
throw new WireShapeError("a bytes field is not base64 text");
|
|
63
|
+
return Buffer.from(core, "base64");
|
|
64
|
+
}
|
|
65
|
+
/** How many times ch (one UTF-16 unit) ends s, counted from the end in one pass. */
|
|
66
|
+
export function trailing(s, ch) {
|
|
67
|
+
const c = ch.charCodeAt(0);
|
|
68
|
+
let n = 0;
|
|
69
|
+
while (n < s.length && s.charCodeAt(s.length - 1 - n) === c)
|
|
70
|
+
n++;
|
|
71
|
+
return n;
|
|
22
72
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plimsollmark/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.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",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@mastra/core": ">=1.73.0 <2",
|
|
58
58
|
"@trigger.dev/sdk": ">=4.7.0 <5",
|
|
59
59
|
"ai": ">=7.0.126 <8",
|
|
60
|
-
"zod": ">=4.6.
|
|
60
|
+
"zod": ">=4.6.7 <5"
|
|
61
61
|
},
|
|
62
62
|
"peerDependenciesMeta": {
|
|
63
63
|
"@mastra/core": {
|