@open-conduit/sdk 0.0.0-stage → 7.1.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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/actions.d.ts +145 -0
  4. package/dist/actions.js +281 -0
  5. package/dist/actiontest.d.ts +80 -0
  6. package/dist/actiontest.js +190 -0
  7. package/dist/artifactstore.d.ts +133 -0
  8. package/dist/artifactstore.js +364 -0
  9. package/dist/backup.d.ts +99 -0
  10. package/dist/backup.js +178 -0
  11. package/dist/containertest.d.ts +71 -0
  12. package/dist/containertest.js +294 -0
  13. package/dist/errors.d.ts +127 -0
  14. package/dist/errors.js +180 -0
  15. package/dist/executor.d.ts +374 -0
  16. package/dist/executor.js +556 -0
  17. package/dist/executortest.d.ts +183 -0
  18. package/dist/executortest.js +534 -0
  19. package/dist/extension.d.ts +855 -0
  20. package/dist/extension.js +1822 -0
  21. package/dist/feed.d.ts +20 -0
  22. package/dist/feed.js +88 -0
  23. package/dist/forward.d.ts +38 -0
  24. package/dist/forward.js +163 -0
  25. package/dist/forwardca.d.ts +21 -0
  26. package/dist/forwardca.js +144 -0
  27. package/dist/hooks.d.ts +108 -0
  28. package/dist/hooks.js +13 -0
  29. package/dist/host.d.ts +295 -0
  30. package/dist/host.js +486 -0
  31. package/dist/index.d.ts +34 -0
  32. package/dist/index.js +31 -0
  33. package/dist/jsonrpc.d.ts +39 -0
  34. package/dist/jsonrpc.js +350 -0
  35. package/dist/probe.d.ts +61 -0
  36. package/dist/probe.js +92 -0
  37. package/dist/providertest.d.ts +59 -0
  38. package/dist/providertest.js +168 -0
  39. package/dist/resources.d.ts +208 -0
  40. package/dist/resources.js +303 -0
  41. package/dist/sandbox.d.ts +84 -0
  42. package/dist/sandbox.js +85 -0
  43. package/dist/schema.d.ts +71 -0
  44. package/dist/schema.js +252 -0
  45. package/dist/setup.d.ts +145 -0
  46. package/dist/setup.js +179 -0
  47. package/dist/setuptest.d.ts +90 -0
  48. package/dist/setuptest.js +319 -0
  49. package/dist/storetest.d.ts +64 -0
  50. package/dist/storetest.js +740 -0
  51. package/dist/telemetry.d.ts +86 -0
  52. package/dist/telemetry.js +46 -0
  53. package/dist/testing.d.ts +756 -0
  54. package/dist/testing.js +2165 -0
  55. package/dist/toolbelt.d.ts +91 -0
  56. package/dist/toolbelt.js +216 -0
  57. package/dist/tunnel.d.ts +62 -0
  58. package/dist/tunnel.js +93 -0
  59. package/dist/wire.d.ts +5359 -0
  60. package/dist/wire.js +2211 -0
  61. package/package.json +29 -4
@@ -0,0 +1,127 @@
1
+ /** The protocol's own error codes (protocol/protocol.go). */
2
+ export declare const Code: {
3
+ UnsupportedVersion: string;
4
+ MethodNotFound: string;
5
+ Invalid: string;
6
+ Unsupported: string;
7
+ Unauthorized: string;
8
+ Undeclared: string;
9
+ NotFound: string;
10
+ Conflict: string;
11
+ CausalLimit: string;
12
+ NotAdoptable: string;
13
+ NotAccepting: string;
14
+ NothingToAttach: string;
15
+ NotLive: string;
16
+ ResourceSetup: string;
17
+ ResourceNotFound: string;
18
+ ResourceExhausted: string;
19
+ SandboxDenied: string;
20
+ SandboxUnavailable: string;
21
+ ContainerRunning: string;
22
+ ContainerUnconfirmed: string;
23
+ SiteUnavailable: string;
24
+ NoCapacity: string;
25
+ RetryAfter: string;
26
+ Reentrant: string;
27
+ Overloaded: string;
28
+ Cancelled: string;
29
+ ShuttingDown: string;
30
+ Internal: string;
31
+ Schema: string;
32
+ KVDowngrade: string;
33
+ };
34
+ /** Reports whether code is one of the protocol's own codes. */
35
+ export declare function isProtocolCode(code: string): boolean;
36
+ /**
37
+ * An authored protocol error: one of the protocol's own codes. The host
38
+ * refuses with these (not_found from kv.get is never thrown; conflict from
39
+ * kv.commit is), and an extension may throw one to refuse a host request.
40
+ */
41
+ export declare class ProtocolError extends Error {
42
+ readonly code: string;
43
+ /** The message as it crossed the wire. */
44
+ readonly detail: string;
45
+ readonly resetAt: string | undefined;
46
+ /** A config refusal's diagnostics (ConfigError), as they crossed. */
47
+ readonly diagnostics: ConfigDiagnostic[];
48
+ constructor(code: string, detail?: string, resetAt?: string, diagnostics?: ConfigDiagnostic[]);
49
+ }
50
+ /**
51
+ * One thing wrong with a config object (extension.ConfigDiagnostic): the
52
+ * JSON pointer of the field within the object ("/jobs/1/cron", "" for the
53
+ * object itself), a stable snake_case code and a message saying what is
54
+ * wrong and what is allowed. The host shows it to the operator, so the
55
+ * message must never quote a configured value.
56
+ */
57
+ export interface ConfigDiagnostic {
58
+ path: string;
59
+ code: string;
60
+ message: string;
61
+ }
62
+ /**
63
+ * A refusal of a config object that says why: throw one from an entry
64
+ * type's validate hook and the host reports each diagnostic at its field's
65
+ * full path. Anything else thrown is reported only as invalid.
66
+ */
67
+ export declare class ConfigError extends Error {
68
+ readonly diagnostics: ConfigDiagnostic[];
69
+ constructor(diagnostics: ConfigDiagnostic[]);
70
+ constructor(path: string, code: string, message: string);
71
+ }
72
+ /** The JSON pointer of a path of object keys and array indexes. */
73
+ export declare function pointer(...parts: (string | number)[]): string;
74
+ /**
75
+ * An operation's refusal, which reaches the calling agent verbatim: a code
76
+ * of the extension's own ([a-z][a-z0-9_]*) and a message the agent reads.
77
+ * Throw one from an operation handler; anything else thrown is "internal".
78
+ */
79
+ export declare class OperationError extends Error {
80
+ readonly code: string;
81
+ constructor(code: string, message: string);
82
+ }
83
+ /**
84
+ * A secret provider's safe answer for a reference it can't serve, or a
85
+ * write or delete it won't make (extension.SecretRefusal): throw one from
86
+ * a secret scheme's serve, store or delete. The operator is shown the
87
+ * code, so it must never carry the value, the reference or the manager's
88
+ * error text: lower-case letters, digits and underscores, at most 64
89
+ * characters (validSecretCode). The host reports an invalid code as
90
+ * provider_refused, and anything else thrown as provider_failed.
91
+ */
92
+ export declare class SecretRefusal extends Error {
93
+ readonly code: string;
94
+ constructor(code: string);
95
+ }
96
+ /** The refusal code of a write or delete that would touch a value its owner didn't store (extension.SecretUnowned). */
97
+ export declare const SecretUnowned = "exists_unowned";
98
+ /** Reports whether code is a safe secret refusal code (extension.ValidSecretCode). */
99
+ export declare function validSecretCode(code: string): boolean;
100
+ /**
101
+ * A credential verifier's refusal of a credential (extension.ErrUnauthorized):
102
+ * throw one from a verifier's verify for a credential its issuer didn't
103
+ * sign or that isn't valid now. It crosses as unauthorized with a fixed
104
+ * message, so neither the credential nor the reason reaches the host's
105
+ * log; the host answers the request 401 whatever the reason. Anything
106
+ * else thrown crosses as internal, which the host refuses the same way.
107
+ */
108
+ export declare class CredentialRefusal extends Error {
109
+ constructor(reason?: string);
110
+ }
111
+ /** The error a request answered after its caller cancelled it. */
112
+ export declare class CancelledError extends Error {
113
+ constructor();
114
+ }
115
+ /** The connection to the host closed (it exited, or the stream broke). */
116
+ export declare class TransportError extends Error {
117
+ constructor(reason?: string);
118
+ }
119
+ /** Decode returns the error for an authored error received from the host. */
120
+ export declare function decode(code: string, message: string, resetAt?: string, diagnostics?: ConfigDiagnostic[]): Error;
121
+ /** The code and message an error crosses the wire with. */
122
+ export declare function encode(err: unknown): {
123
+ code: string;
124
+ message: string;
125
+ resetAt?: string;
126
+ diagnostics?: ConfigDiagnostic[];
127
+ };
package/dist/errors.js ADDED
@@ -0,0 +1,180 @@
1
+ // Errors that cross the wire, as protocol/errors.go defines them: an
2
+ // authored error is a stable code and a short, secret-free message, sent as
3
+ // JSON-RPC code -32000 with data.code. Anything else crosses as "internal"
4
+ // with no detail, which stays in the sender's own log (stderr).
5
+ /** The protocol's own error codes (protocol/protocol.go). */
6
+ export const Code = {
7
+ UnsupportedVersion: "unsupported_protocol_version",
8
+ MethodNotFound: "method_not_found",
9
+ Invalid: "invalid",
10
+ Unsupported: "unsupported",
11
+ Unauthorized: "unauthorized",
12
+ Undeclared: "undeclared",
13
+ NotFound: "not_found",
14
+ Conflict: "conflict",
15
+ CausalLimit: "causal_limit",
16
+ NotAdoptable: "not_adoptable",
17
+ NotAccepting: "not_accepting",
18
+ NothingToAttach: "nothing_to_attach",
19
+ NotLive: "not_live",
20
+ ResourceSetup: "resource_setup_failed",
21
+ ResourceNotFound: "resource_not_found",
22
+ ResourceExhausted: "resource_exhausted",
23
+ SandboxDenied: "sandbox_denied",
24
+ SandboxUnavailable: "sandbox_unavailable",
25
+ ContainerRunning: "container_running",
26
+ ContainerUnconfirmed: "container_unconfirmed",
27
+ SiteUnavailable: "site_unavailable",
28
+ NoCapacity: "no_capacity",
29
+ RetryAfter: "retry_after",
30
+ Reentrant: "reentrant_call",
31
+ Overloaded: "overloaded",
32
+ Cancelled: "cancelled",
33
+ ShuttingDown: "shutting_down",
34
+ Internal: "internal",
35
+ Schema: "unreadable_schema",
36
+ KVDowngrade: "kv_downgrade",
37
+ };
38
+ const known = new Set(Object.values(Code));
39
+ /** Reports whether code is one of the protocol's own codes. */
40
+ export function isProtocolCode(code) {
41
+ return known.has(code);
42
+ }
43
+ /**
44
+ * An authored protocol error: one of the protocol's own codes. The host
45
+ * refuses with these (not_found from kv.get is never thrown; conflict from
46
+ * kv.commit is), and an extension may throw one to refuse a host request.
47
+ */
48
+ export class ProtocolError extends Error {
49
+ code;
50
+ /** The message as it crossed the wire. */
51
+ detail;
52
+ resetAt;
53
+ /** A config refusal's diagnostics (ConfigError), as they crossed. */
54
+ diagnostics;
55
+ constructor(code, detail = "", resetAt, diagnostics = []) {
56
+ super(detail === "" ? `protocol: ${code}` : `protocol: ${code}: ${detail}`);
57
+ this.name = "ProtocolError";
58
+ this.code = code;
59
+ this.detail = detail;
60
+ this.resetAt = resetAt;
61
+ this.diagnostics = diagnostics;
62
+ }
63
+ }
64
+ /**
65
+ * A refusal of a config object that says why: throw one from an entry
66
+ * type's validate hook and the host reports each diagnostic at its field's
67
+ * full path. Anything else thrown is reported only as invalid.
68
+ */
69
+ export class ConfigError extends Error {
70
+ diagnostics;
71
+ constructor(first, code, message) {
72
+ const diagnostics = typeof first === "string"
73
+ ? [{ path: first, code: code ?? "", message: message ?? "" }]
74
+ : first;
75
+ super("invalid config: " +
76
+ diagnostics
77
+ .map((d) => `${d.path || "config"}: ${d.code}: ${d.message}`)
78
+ .join("; "));
79
+ this.name = "ConfigError";
80
+ this.diagnostics = diagnostics;
81
+ }
82
+ }
83
+ /** The JSON pointer of a path of object keys and array indexes. */
84
+ export function pointer(...parts) {
85
+ return parts
86
+ .map((p) => "/" + String(p).replaceAll("~", "~0").replaceAll("/", "~1"))
87
+ .join("");
88
+ }
89
+ /**
90
+ * An operation's refusal, which reaches the calling agent verbatim: a code
91
+ * of the extension's own ([a-z][a-z0-9_]*) and a message the agent reads.
92
+ * Throw one from an operation handler; anything else thrown is "internal".
93
+ */
94
+ export class OperationError extends Error {
95
+ code;
96
+ constructor(code, message) {
97
+ super(message);
98
+ this.name = "OperationError";
99
+ this.code = code;
100
+ }
101
+ }
102
+ /**
103
+ * A secret provider's safe answer for a reference it can't serve, or a
104
+ * write or delete it won't make (extension.SecretRefusal): throw one from
105
+ * a secret scheme's serve, store or delete. The operator is shown the
106
+ * code, so it must never carry the value, the reference or the manager's
107
+ * error text: lower-case letters, digits and underscores, at most 64
108
+ * characters (validSecretCode). The host reports an invalid code as
109
+ * provider_refused, and anything else thrown as provider_failed.
110
+ */
111
+ export class SecretRefusal extends Error {
112
+ code;
113
+ constructor(code) {
114
+ super(`secret refused: ${code}`);
115
+ this.name = "SecretRefusal";
116
+ this.code = code;
117
+ }
118
+ }
119
+ /** The refusal code of a write or delete that would touch a value its owner didn't store (extension.SecretUnowned). */
120
+ export const SecretUnowned = "exists_unowned";
121
+ /** Reports whether code is a safe secret refusal code (extension.ValidSecretCode). */
122
+ export function validSecretCode(code) {
123
+ return /^[a-z][a-z0-9_]{0,63}$/.test(code);
124
+ }
125
+ /**
126
+ * A credential verifier's refusal of a credential (extension.ErrUnauthorized):
127
+ * throw one from a verifier's verify for a credential its issuer didn't
128
+ * sign or that isn't valid now. It crosses as unauthorized with a fixed
129
+ * message, so neither the credential nor the reason reaches the host's
130
+ * log; the host answers the request 401 whatever the reason. Anything
131
+ * else thrown crosses as internal, which the host refuses the same way.
132
+ */
133
+ export class CredentialRefusal extends Error {
134
+ constructor(reason = "credential refused") {
135
+ super(reason);
136
+ this.name = "CredentialRefusal";
137
+ }
138
+ }
139
+ /** The error a request answered after its caller cancelled it. */
140
+ export class CancelledError extends Error {
141
+ constructor() {
142
+ super("request cancelled");
143
+ this.name = "CancelledError";
144
+ }
145
+ }
146
+ /** The connection to the host closed (it exited, or the stream broke). */
147
+ export class TransportError extends Error {
148
+ constructor(reason = "transport closed") {
149
+ super(`protocol: ${reason}`);
150
+ this.name = "TransportError";
151
+ }
152
+ }
153
+ /** Decode returns the error for an authored error received from the host. */
154
+ export function decode(code, message, resetAt, diagnostics = []) {
155
+ return isProtocolCode(code)
156
+ ? new ProtocolError(code, message, resetAt, code === Code.Invalid ? diagnostics : [])
157
+ : new OperationError(code, message);
158
+ }
159
+ /** The code and message an error crosses the wire with. */
160
+ export function encode(err) {
161
+ if (err instanceof ConfigError && err.diagnostics.length > 0)
162
+ return {
163
+ code: Code.Invalid,
164
+ message: "invalid config",
165
+ diagnostics: err.diagnostics,
166
+ };
167
+ if (err instanceof ProtocolError) {
168
+ const message = err.detail === "" ? err.code : err.detail;
169
+ return err.resetAt === undefined
170
+ ? { code: err.code, message }
171
+ : { code: err.code, message, resetAt: err.resetAt };
172
+ }
173
+ if (err instanceof OperationError)
174
+ return { code: err.code, message: err.message };
175
+ if (err instanceof CancelledError ||
176
+ (err instanceof Error && err.name === "AbortError")) {
177
+ return { code: Code.Cancelled, message: "request cancelled" };
178
+ }
179
+ return { code: Code.Internal, message: "internal error" };
180
+ }
@@ -0,0 +1,374 @@
1
+ import type { Context } from "./extension.js";
2
+ import { type Infer, type Type } from "./schema.js";
3
+ import { type ArtifactRef, type Event, type Execution, type ExecutionContext, type ExecutorDecl, type FieldDecl, type Payload, type Result, type SandboxLaunch, type SandboxNeeds, type ValidateParams, type ValidateResult, type Work, type WorkspaceRecord } from "./wire.js";
4
+ /** How an attempt's process reaches the toolbelt (extension.Toolbelt*). */
5
+ export type ToolbeltTransport = "none" | "cli" | "mcp" | "sdk";
6
+ /**
7
+ * The mechanical labels a binding's requires is checked against, and a
8
+ * route's binding check sees (domain.Capabilities). interrupt, inject and
9
+ * resume each need their handler. sandbox and container say the
10
+ * executor runs a binding's launch in its process sandbox or its
11
+ * container, through the run's brokers (AttemptRequest.sandbox and
12
+ * container). noProcess says the executor runs no process the agent
13
+ * controls, so a scope that requires isolation accepts its bindings
14
+ * without a sandbox or container.
15
+ */
16
+ export interface ExecutorCapabilities {
17
+ interrupt?: boolean;
18
+ inject?: boolean;
19
+ resume?: boolean;
20
+ workspace?: boolean;
21
+ toolbelt: ToolbeltTransport;
22
+ sandbox?: boolean;
23
+ container?: boolean;
24
+ noProcess?: boolean;
25
+ }
26
+ /** The kinds of outcome an attempt can end with (domain.Outcome*). */
27
+ export type OutcomeKind = "completed" | "failed" | "waiting" | "handoff";
28
+ /**
29
+ * What one segment of an attempt consumed, as the executor counts it
30
+ * (extension.Usage). Budgets are charged in named units: units holds any
31
+ * the executor reports ("usd", "minutes", or its own); the host adds a
32
+ * cost in its currency's code and the tokens itself. What counts as a cost
33
+ * is the executor's to say. attribution describes what did the work
34
+ * ("model", "machine"), for a reader to price it.
35
+ */
36
+ export interface UsageRecord {
37
+ inputTokens?: number;
38
+ outputTokens?: number;
39
+ cachedTokens?: number;
40
+ cost?: number;
41
+ currency?: string;
42
+ units?: Record<string, number>;
43
+ attribution?: Record<string, string>;
44
+ }
45
+ /** An attempt's result (extension.Result). */
46
+ export interface ExecutorResult {
47
+ outcome: {
48
+ kind: OutcomeKind;
49
+ summary?: string;
50
+ data?: Payload;
51
+ };
52
+ usage?: UsageRecord;
53
+ /** Artifacts the attempt published (host.createArtifact's refs). */
54
+ artifacts?: ArtifactRef[];
55
+ /** A failed outcome that is a retryable limit, with when it resets when known. */
56
+ retry?: {
57
+ resetAt?: Date | string;
58
+ };
59
+ /** A failed outcome trying again can't cure (the config is wrong). */
60
+ permanent?: boolean;
61
+ /**
62
+ * The injected Events the attempt has evidence it took in (an echo, a
63
+ * read of its inbox), each at most once. Without proof an input stays
64
+ * pending and is presented again.
65
+ */
66
+ consumedInputs?: string[];
67
+ /** The resource the attempt ran in, as its provider described it. */
68
+ workspace?: WorkspaceRecord;
69
+ }
70
+ /** A started attempt the host observes (extension.RunHandle). */
71
+ export interface RunHandle {
72
+ /**
73
+ * Resolves with the attempt's result once it ends. The signal aborts
74
+ * when the host stops observing, which doesn't end the attempt: the
75
+ * host may call wait again, on this handle or on a recovered one.
76
+ */
77
+ wait(signal: AbortSignal): Promise<ExecutorResult>;
78
+ }
79
+ /** What a run asks of its binding's resource provider (extension.ResourceRequest). */
80
+ export interface ResourceRequest {
81
+ /** shared, work or fresh; "" for the resource config's default. */
82
+ mode?: string;
83
+ params?: Payload;
84
+ files?: string[];
85
+ }
86
+ /** A resource the run holds (extension.Resource). */
87
+ export interface AcquiredResource {
88
+ kind: string;
89
+ ref: string;
90
+ dir: string;
91
+ env: Record<string, string>;
92
+ data: Payload;
93
+ summary: string;
94
+ sandbox?: SandboxNeeds;
95
+ site: string;
96
+ files: Record<string, string>;
97
+ /** The provider's progress for this acquisition. */
98
+ log: string;
99
+ /** The resource exists, returned for inspection, but its setup failed. */
100
+ setupFailed: boolean;
101
+ }
102
+ /** The run's resource broker, bound by the host to its trusted owner (extension.ResourceBroker). */
103
+ export interface ResourceBroker {
104
+ acquire(r?: ResourceRequest, signal?: AbortSignal): Promise<AcquiredResource>;
105
+ lookup(ref: string, signal?: AbortSignal): Promise<AcquiredResource>;
106
+ }
107
+ /**
108
+ * A wrapped launch the host planned (extension.SandboxPlan): what the
109
+ * executor runs in place of its own argv, with env, in dir when given.
110
+ * signals says what an interrupt can promise (SandboxSignals).
111
+ */
112
+ export interface LaunchPlan {
113
+ argv: string[];
114
+ env: string[];
115
+ signals: string;
116
+ summary: string;
117
+ data?: Payload;
118
+ dir: string;
119
+ }
120
+ /**
121
+ * The run's process sandbox, bound by the host to the binding's provider
122
+ * and policy (extension.SandboxBroker). Any error means nothing may run.
123
+ */
124
+ export interface SandboxBroker {
125
+ /** Wraps one launch; needs are the executor's own, the host merges the rest. */
126
+ plan(needs: SandboxNeeds, launch: SandboxLaunch, signal?: AbortSignal): Promise<LaunchPlan>;
127
+ /** Proves a recovered segment's wrapper, pid parent, still runs inside its sandbox; throws when it doesn't. */
128
+ adopt(parent: number, signal?: AbortSignal): Promise<void>;
129
+ }
130
+ /** How an adopted container's segment ended (extension.ContainerExit). */
131
+ export interface ContainerExitStatus {
132
+ exited: boolean;
133
+ exitCode: number;
134
+ interrupted: boolean;
135
+ }
136
+ /**
137
+ * The run's container, bound by the host to the binding's provider and
138
+ * policy (extension.ContainerBroker). Any error means nothing may run; an
139
+ * adopt or reattach that can't prove the pinned container throws
140
+ * Code.NotAdoptable.
141
+ */
142
+ export interface ContainerBroker {
143
+ /** Creates the launch's container and answers the wrapper's argv and env, with signals term. */
144
+ launch(needs: SandboxNeeds, launch: SandboxLaunch, signal?: AbortSignal): Promise<LaunchPlan>;
145
+ /**
146
+ * Proves a recovered segment's container is the one pinned: with its
147
+ * wrapper alive, adopted as it runs; with it dead, the exited
148
+ * container's exit.
149
+ */
150
+ adopt(alive: boolean, signal?: AbortSignal): Promise<ContainerExitStatus>;
151
+ /** A new wrapper for a recovered segment's pinned container, its output brought back to run. */
152
+ reattach(run: string, signal?: AbortSignal): Promise<LaunchPlan>;
153
+ }
154
+ /** An attempt to run, recover or resume (extension.RunRequest). */
155
+ export interface AttemptRequest<C = unknown> {
156
+ work: Work;
157
+ execution: Execution;
158
+ /** The selected Event. */
159
+ trigger: Event;
160
+ /** The acceptance-ordered batch, context preceding a wake included. */
161
+ inputs: Event[];
162
+ /** The binding's config data, decoded through the spec's config schema. */
163
+ config: C;
164
+ /** The rest of the execution context as the host sent it: secrets, toolbelt, env, playbooks. */
165
+ context: ExecutionContext;
166
+ /**
167
+ * Durably saves the attempt's continuity state, fenced by the
168
+ * execution's lease: run must call it before it returns the handle, and
169
+ * recover calls it again with the state it was given. It may be called
170
+ * after run returned, to save newer state.
171
+ */
172
+ persistRecovery(state: Payload): Promise<void>;
173
+ /** The binding's resource provider, when it declares one. */
174
+ resources?: ResourceBroker;
175
+ /** The binding's process sandbox, when it names one (capability sandbox). */
176
+ sandbox?: SandboxBroker;
177
+ /** The binding's container, when it names one (capability container). */
178
+ container?: ContainerBroker;
179
+ }
180
+ /** What an operator's takeover in the binding's container attaches to (extension.ContainerAttachRequest). */
181
+ export interface ContainerAttachRequest<C = unknown> {
182
+ work: Work;
183
+ /** The binding's config data, decoded through the spec's config schema. */
184
+ config: C;
185
+ /** The binding's secrets, as a launch would get them. */
186
+ secrets: Record<string, string>;
187
+ /** The Work's container home. */
188
+ home: string;
189
+ }
190
+ /** The interactive launch the host's container broker plans for the takeover (extension.ContainerAttachSpec); launch.dir is the workspace. */
191
+ export interface ContainerAttachSpec {
192
+ needs: SandboxNeeds;
193
+ launch: SandboxLaunch;
194
+ }
195
+ /** What an interactive session of the executor's CLI starts on (extension.InteractiveLaunchRequest). */
196
+ export interface InteractiveLaunchRequest {
197
+ /** The playbook's text, frontmatter and all. */
198
+ playbook: string;
199
+ /** The playbook's name. */
200
+ name: string;
201
+ summary: string;
202
+ /** Command prefixes the session may run without asking. */
203
+ allow: string[];
204
+ /** The session's working directory. */
205
+ dir: string;
206
+ /** A host directory it may create and write the files its launch needs into. */
207
+ filesDir: string;
208
+ /** The operator's choice of CLI, "" for the executor's default. */
209
+ program: string;
210
+ }
211
+ /** The command the host execs for an interactive session (extension.InteractiveLaunchSpec). */
212
+ export interface InteractiveLaunchSpec {
213
+ argv: string[];
214
+ dir?: string;
215
+ /** The variables to add to the session's environment; never one the host decides. */
216
+ setEnv?: Record<string, string>;
217
+ }
218
+ /** What an executor's handlers can reach. */
219
+ export interface ExecutorContext extends Context {
220
+ /**
221
+ * The executor's state directory, from initialize: the host's
222
+ * executors/<name>, or the extension's own state directory when the host
223
+ * names none. It keeps its runs there.
224
+ */
225
+ stateDir: string;
226
+ }
227
+ /** Answers which of ids the host holds, asking at most MaxKnownBatch at a time. */
228
+ export type KnownFn = (ids: string[]) => Promise<Set<string>>;
229
+ /** What a sweep did (extension.StateSweepReport). */
230
+ export interface SweepReport {
231
+ /** The executions whose state it released. */
232
+ removed: string[];
233
+ /** State it kept: in_use (a process still runs), unmapped or remove_failed. */
234
+ kept?: {
235
+ executionId?: string;
236
+ ref?: string;
237
+ kept: string;
238
+ }[];
239
+ }
240
+ /** One output of a running execution so far (extension.LiveOutput). */
241
+ export interface LiveOut {
242
+ name: string;
243
+ mediaType: string;
244
+ /** The whole output's length. */
245
+ size: number;
246
+ /** At most its last tail bytes. */
247
+ content: Uint8Array | string;
248
+ }
249
+ /** The most IDs one known call asks about (extension.MaxKnownBatch). */
250
+ export declare const MaxKnownBatch = 256;
251
+ /**
252
+ * An executor (extension.Executor and its optional controls), which a
253
+ * binding names. Errors the host acts on are ProtocolErrors: recover
254
+ * throws Code.NotAdoptable when it has nothing to adopt, inject
255
+ * Code.NotAccepting when the Event was definitely not delivered (any
256
+ * other error is ambiguous, and the host retries), live Code.NotLive and
257
+ * attach Code.NothingToAttach.
258
+ */
259
+ export interface ExecutorSpec<S extends Type<unknown>> {
260
+ capabilities: ExecutorCapabilities;
261
+ /** The binding config's data schema, checked through validate (kind executor) and decoded for each attempt. */
262
+ config?: S;
263
+ /** Further checks of a config the schema accepts; throw ConfigError to refuse. */
264
+ validate?: (config: Infer<S>) => void | Promise<void>;
265
+ /** The binding config's fields, for adapters and the config editor. */
266
+ fields?: FieldDecl[];
267
+ /** "jobs" counts its runs against settings.job_concurrency, not settings.concurrency. */
268
+ pool?: "jobs";
269
+ /**
270
+ * The resource mode a binding config makes it request (shared, work or
271
+ * fresh), "" for the resource config's default; validate kind
272
+ * executor_mode, manifest resource_mode. Config check uses it to tell
273
+ * when a resource config's own mode never applies.
274
+ */
275
+ resourceMode?: (config: Infer<S>) => string;
276
+ /** The playbook a binding config starts its turns on, "" for none; validate kind executor_playbook, manifest playbook. */
277
+ playbook?: (config: Infer<S>) => string;
278
+ /**
279
+ * The command that shows the program a binding config runs is installed
280
+ * where it runs, with the variables it runs with in a container, or
281
+ * undefined for none; validate kind executor_probe, manifest
282
+ * version_probe. A container provider's doctor check runs it in the
283
+ * binding's image, with no network, mounts or secrets.
284
+ */
285
+ versionProbe?: (config: Infer<S>) => {
286
+ argv: string[];
287
+ env?: string[];
288
+ } | undefined;
289
+ /**
290
+ * Adapts a binding from an included folder's config, before it is
291
+ * validated and stored: resolves relative paths against folder, and may
292
+ * default the folder a binding without a resource runs in; validate
293
+ * kind executor_folder, manifest folder_config. It gets the config as
294
+ * written; throw to refuse it.
295
+ */
296
+ folderConfig?: (config: Record<string, unknown>, folder: string, resource: boolean) => Record<string, unknown>;
297
+ /** Starts an attempt: persistRecovery first, then launch, then the handle. */
298
+ run(r: AttemptRequest<Infer<S>>, ctx: ExecutorContext): Promise<RunHandle>;
299
+ /**
300
+ * Adopts an attempt from its continuity state, never launching a
301
+ * replacement: its live run, or its finished result. Throws
302
+ * Code.NotAdoptable when the state names nothing it holds.
303
+ */
304
+ recover(r: AttemptRequest<Infer<S>>, state: Payload, ctx: ExecutorContext): Promise<RunHandle>;
305
+ /** Carries a parked attempt on with the wake's inputs (capability resume). */
306
+ resume?(r: AttemptRequest<Infer<S>>, state: Payload, ctx: ExecutorContext): Promise<RunHandle>;
307
+ /** Delivers an accepted Event to the running attempt (capability inject); idempotent per Event ID. */
308
+ inject?(execution: string, event: Event, ctx: ExecutorContext): Promise<void>;
309
+ /** Asks the running attempt to stop (capability interrupt). */
310
+ interrupt?(execution: string, ctx: ExecutorContext): Promise<void>;
311
+ /** Ends whatever of the execution runs at epoch, resolving once nothing of it can; a newer epoch must refuse. */
312
+ stop?(execution: string, epoch: number, ctx: ExecutorContext): Promise<void>;
313
+ /** Releases a terminal execution's private state; idempotent, and never signals a process. */
314
+ forget?(execution: string, ctx: ExecutorContext): Promise<void>;
315
+ /**
316
+ * Releases the state of every execution the host doesn't know, as
317
+ * forget would, and never one whose process still runs; a failing known
318
+ * fails the sweep with nothing more released.
319
+ */
320
+ sweep?(known: KnownFn, ctx: ExecutorContext): Promise<SweepReport>;
321
+ /** A running attempt's outputs so far; Code.NotLive when none runs here. */
322
+ live?(execution: string, tail: number, ctx: ExecutorContext): Promise<LiveOut[]>;
323
+ /** The command an operator's takeover of the Work runs; Code.NothingToAttach when there is none yet. */
324
+ attach?(work: string, ctx: ExecutorContext): Promise<{
325
+ argv: string[];
326
+ dir?: string;
327
+ }>;
328
+ /**
329
+ * The interactive launch an operator's takeover runs in the binding's
330
+ * container (control container_attach), which the host's container
331
+ * broker plans under the binding's policy.
332
+ */
333
+ containerAttach?(r: ContainerAttachRequest<Infer<S>>, ctx: ExecutorContext): Promise<ContainerAttachSpec>;
334
+ /**
335
+ * The command that starts an interactive session of the executor's own
336
+ * CLI on a playbook in the operator's terminal, outside any Work
337
+ * (control interactive_launch). The host decides the playbook, the
338
+ * allowed commands, the directory and the environment; the executor only
339
+ * expresses them in its CLI's terms.
340
+ */
341
+ interactiveLaunch?(r: InteractiveLaunchRequest, ctx: ExecutorContext): Promise<InteractiveLaunchSpec>;
342
+ /** Other names an operator may launch it by (`init --with`); they need interactiveLaunch. */
343
+ launchNames?: string[];
344
+ }
345
+ /** @internal An executor's validate and executor.* methods. */
346
+ export interface ExecutorHandler {
347
+ decl: ExecutorDecl;
348
+ validate: (config: unknown) => Promise<void>;
349
+ /** The validate kinds executor_mode, executor_playbook, executor_probe and executor_folder. */
350
+ answer: (p: ValidateParams) => ValidateResult;
351
+ serve: (method: string, raw: unknown, ctx: ExecutorContext, runs: ExecutorRuns) => Promise<unknown>;
352
+ }
353
+ /** @internal The handles of the attempts a connection started, and the sweeps it serves. */
354
+ export declare class ExecutorRuns {
355
+ #private;
356
+ constructor(id: () => string);
357
+ add(h: RunHandle): string;
358
+ get(id: string): RunHandle | undefined;
359
+ delete(id: string): void;
360
+ }
361
+ /**
362
+ * Why a result is invalid (extension.ValidateResult), or "" when it is
363
+ * valid: a known outcome kind, a retry or permanent only on a failure and
364
+ * never both, consumed inputs named once each, a cost with a currency, and
365
+ * usage units and attribution of the allowed names, none of them a unit
366
+ * the host counts itself.
367
+ */
368
+ export declare function invalidResult(r: ExecutorResult): string;
369
+ /** The result as executor.wait answers it (protocol.FromResult). */
370
+ export declare function wireResult(r: ExecutorResult): Result;
371
+ /** The result a wire Result describes (protocol.Result.Extension). */
372
+ export declare function fromWireResult(r: Result): ExecutorResult;
373
+ /** The handler of one declared executor, refusing a spec whose capabilities its handlers don't back. */
374
+ export declare function executorHandler<S extends Type<unknown>>(name: string, spec: ExecutorSpec<S>, validateConfig: (schema: Type<unknown>, config: unknown, extra?: (config: never) => void | Promise<void>) => Promise<void>): ExecutorHandler;