@open-conduit/sdk 7.0.0 → 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 (55) hide show
  1. package/dist/actions.d.ts +145 -0
  2. package/dist/actions.js +281 -0
  3. package/dist/actiontest.d.ts +80 -0
  4. package/dist/actiontest.js +190 -0
  5. package/dist/artifactstore.d.ts +133 -0
  6. package/dist/artifactstore.js +364 -0
  7. package/dist/backup.d.ts +99 -0
  8. package/dist/backup.js +178 -0
  9. package/dist/containertest.d.ts +71 -0
  10. package/dist/containertest.js +294 -0
  11. package/dist/errors.d.ts +28 -0
  12. package/dist/errors.js +37 -0
  13. package/dist/executor.d.ts +374 -0
  14. package/dist/executor.js +556 -0
  15. package/dist/executortest.d.ts +183 -0
  16. package/dist/executortest.js +534 -0
  17. package/dist/extension.d.ts +496 -1
  18. package/dist/extension.js +1152 -4
  19. package/dist/feed.d.ts +20 -0
  20. package/dist/feed.js +88 -0
  21. package/dist/forward.d.ts +38 -0
  22. package/dist/forward.js +163 -0
  23. package/dist/forwardca.d.ts +21 -0
  24. package/dist/forwardca.js +144 -0
  25. package/dist/hooks.d.ts +108 -0
  26. package/dist/hooks.js +13 -0
  27. package/dist/host.d.ts +166 -2
  28. package/dist/host.js +235 -2
  29. package/dist/index.d.ts +27 -3
  30. package/dist/index.js +14 -2
  31. package/dist/probe.d.ts +61 -0
  32. package/dist/probe.js +92 -0
  33. package/dist/providertest.d.ts +59 -0
  34. package/dist/providertest.js +168 -0
  35. package/dist/resources.d.ts +208 -0
  36. package/dist/resources.js +303 -0
  37. package/dist/sandbox.d.ts +84 -0
  38. package/dist/sandbox.js +85 -0
  39. package/dist/setup.d.ts +145 -0
  40. package/dist/setup.js +179 -0
  41. package/dist/setuptest.d.ts +90 -0
  42. package/dist/setuptest.js +319 -0
  43. package/dist/storetest.d.ts +64 -0
  44. package/dist/storetest.js +740 -0
  45. package/dist/telemetry.d.ts +86 -0
  46. package/dist/telemetry.js +46 -0
  47. package/dist/testing.d.ts +591 -2
  48. package/dist/testing.js +1460 -6
  49. package/dist/toolbelt.d.ts +91 -0
  50. package/dist/toolbelt.js +216 -0
  51. package/dist/tunnel.d.ts +62 -0
  52. package/dist/tunnel.js +93 -0
  53. package/dist/wire.d.ts +4060 -348
  54. package/dist/wire.js +1583 -0
  55. package/package.json +1 -1
@@ -0,0 +1,303 @@
1
+ // Resource providers: provider.* and the resource config check kinds, as
2
+ // protocol/sdk serves sdk.Extension.Providers (protocol/sdk/surfaces.go).
3
+ // The host binds a provider to an attempt (extension.BindResources), so a
4
+ // provider only ever sees the trusted owner the host bound, never one an
5
+ // executor names; it drives reconcile and sweep from the host's durable
6
+ // owner state, which the provider reads back through provider.owner_status
7
+ // while the pass runs. A provider declared with sites makes resources at
8
+ // the site a launch is placed at, running commands there through site.run.
9
+ import { Code, ConfigError, ProtocolError } from "./errors.js";
10
+ import { base64, toBytes } from "./host.js";
11
+ import { diagnose, isRecord, matches, } from "./schema.js";
12
+ import { OwnerStatus, ProviderAcquireParams, ProviderLookupParams, ProviderReconcileParams, SiteResult, } from "./wire.js";
13
+ /** The resource modes (extension.ResourceShared, ResourceWork, ResourceFresh). */
14
+ export const ResourceMode = {
15
+ /** One long-lived resource shared by concurrent users, never reset on a user's behalf. */
16
+ Shared: "shared",
17
+ /** Private to one Work and reused by each of its attempts until the Work is terminal. */
18
+ Work: "work",
19
+ /** Private to one execution, created for it and cleaned up after it finishes. */
20
+ Fresh: "fresh",
21
+ };
22
+ /**
23
+ * The resource exists but its setup failed (extension.ErrResourceSetup):
24
+ * throw it from acquire with the resource, which the host keeps for
25
+ * inspection under the provider's failure policy.
26
+ */
27
+ export class ResourceSetupError extends Error {
28
+ resource;
29
+ constructor(resource, message = "resource setup failed") {
30
+ super(message);
31
+ this.name = "ResourceSetupError";
32
+ this.resource = resource;
33
+ }
34
+ }
35
+ const modes = new Set(Object.values(ResourceMode));
36
+ /** @internal */
37
+ export function resourceHandler(type, spec, params) {
38
+ if (spec.modes.length === 0)
39
+ throw new Error(`sdk: resource provider type ${type} must list its modes`);
40
+ for (const [i, m] of spec.modes.entries())
41
+ if (!modes.has(m) || spec.modes.indexOf(m) !== i)
42
+ throw new Error(`sdk: resource provider type ${type} mode ${m} must be a distinct shared, work or fresh`);
43
+ const schema = spec.config;
44
+ // A stored binding passed validate; one whose config no longer matches
45
+ // (a package upgrade changed the schema) acquires nothing.
46
+ const config = (raw) => {
47
+ const c = raw ?? {};
48
+ if (schema !== undefined && !matches(schema, c))
49
+ throw new ProtocolError(Code.Invalid, "the binding's resource config doesn't match the provider's");
50
+ return c;
51
+ };
52
+ // For config check: a config that doesn't decode names no mode, needs
53
+ // no site, and is refused for a sandbox with a fixed reason.
54
+ const decoded = (raw) => {
55
+ const c = raw ?? {};
56
+ return schema === undefined || matches(schema, c)
57
+ ? c
58
+ : undefined;
59
+ };
60
+ return {
61
+ decl: {
62
+ modes: [...spec.modes],
63
+ ...(spec.modeDefault ? { mode_default: true } : {}),
64
+ ...(spec.sandboxWorkspace ? { sandbox: true } : {}),
65
+ ...(spec.sweep ? { sweep: true } : {}),
66
+ ...(spec.unsaved ? { unsaved: true } : {}),
67
+ ...(spec.needsSite ? { sites: true } : {}),
68
+ ...(spec.settings?.length ? { settings: spec.settings } : {}),
69
+ ...(spec.fields?.length ? { fields: spec.fields } : {}),
70
+ },
71
+ validate: async (p) => {
72
+ switch (p.kind) {
73
+ case "resource": {
74
+ const c = p.config ?? {};
75
+ if (schema !== undefined && !matches(schema, c)) {
76
+ const diagnostics = diagnose(schema, c);
77
+ if (diagnostics.length > 0)
78
+ throw new ConfigError(diagnostics);
79
+ throw new ProtocolError(Code.Invalid, "invalid resource config");
80
+ }
81
+ try {
82
+ await spec.validate?.(c);
83
+ }
84
+ catch (err) {
85
+ if (err instanceof ConfigError)
86
+ throw err;
87
+ throw new ProtocolError(Code.Invalid, "invalid resource config");
88
+ }
89
+ return {};
90
+ }
91
+ case "resource_mode": {
92
+ const c = decoded(p.config);
93
+ const mode = c === undefined ? "" : (spec.modeDefault?.(c) ?? "");
94
+ return mode ? { mode } : {};
95
+ }
96
+ case "resource_sandbox": {
97
+ if (spec.sandboxWorkspace === undefined)
98
+ return {};
99
+ const c = decoded(p.config);
100
+ if (c === undefined)
101
+ throw new ProtocolError(Code.Invalid, "the resource config doesn't match the provider's");
102
+ try {
103
+ spec.sandboxWorkspace(c, p.mode ?? "");
104
+ }
105
+ catch (err) {
106
+ // The reason is what the operator reads.
107
+ throw new ProtocolError(Code.Invalid, err instanceof Error ? err.message : String(err));
108
+ }
109
+ return {};
110
+ }
111
+ case "resource_site": {
112
+ if (spec.needsSite === undefined)
113
+ return {};
114
+ const c = decoded(p.config);
115
+ // One that doesn't decode can't be made anywhere, so a binding
116
+ // that doesn't place is refused rather than passed.
117
+ return c === undefined || spec.needsSite(c) ? { site: true } : {};
118
+ }
119
+ }
120
+ return {};
121
+ },
122
+ serve: async (method, raw, ctx) => {
123
+ switch (method) {
124
+ case "provider.acquire": {
125
+ const p = params(ProviderAcquireParams, raw);
126
+ const mode = p.mode ?? "";
127
+ if (mode !== "" && !spec.modes.includes(mode))
128
+ throw new ProtocolError(Code.Unsupported, `resource provider ${type} doesn't serve mode ${mode}`);
129
+ let log = "";
130
+ const a = {
131
+ type,
132
+ owner: p.owner,
133
+ config: config(p.config.data),
134
+ mode,
135
+ params: p.params,
136
+ files: [...(p.files ?? [])],
137
+ hostEnv: { ...(p.host_env ?? {}) },
138
+ log: (text) => {
139
+ log += text;
140
+ },
141
+ };
142
+ // Only a type declared with sites is given one, as the host gives it.
143
+ if (p.site !== undefined && spec.needsSite !== undefined)
144
+ a.site = site(ctx, type, p.site.id, p.site.call);
145
+ let out;
146
+ try {
147
+ out = { resource: resourceOut(await spec.acquire(a, ctx)) };
148
+ }
149
+ catch (err) {
150
+ if (!(err instanceof ResourceSetupError))
151
+ throw err;
152
+ out = { resource: resourceOut(err.resource), setup_failed: true };
153
+ }
154
+ if (log !== "")
155
+ out.log = log;
156
+ return out;
157
+ }
158
+ case "provider.lookup": {
159
+ const p = params(ProviderLookupParams, raw);
160
+ return {
161
+ resource: resourceOut(await spec.lookup(p.owner, p.ref, ctx)),
162
+ };
163
+ }
164
+ case "provider.reconcile": {
165
+ const p = params(ProviderReconcileParams, raw);
166
+ return reportOut(await spec.reconcile(ownerStatus(ctx, p.reconcile), ctx));
167
+ }
168
+ case "provider.sweep": {
169
+ if (spec.sweep === undefined)
170
+ break;
171
+ const p = params(ProviderReconcileParams, raw);
172
+ return sweepOut(await spec.sweep(ownerStatus(ctx, p.reconcile), ctx));
173
+ }
174
+ case "provider.unsaved": {
175
+ if (spec.unsaved === undefined)
176
+ break;
177
+ const found = await spec.unsaved(ctx);
178
+ return found.length > 0
179
+ ? {
180
+ resources: found.map((r) => ({
181
+ ref: r.ref,
182
+ ...(r.mode ? { mode: r.mode } : {}),
183
+ ...(r.path ? { path: r.path } : {}),
184
+ ...(r.site ? { site: r.site } : {}),
185
+ kept: r.kept,
186
+ })),
187
+ }
188
+ : {};
189
+ }
190
+ }
191
+ throw new ProtocolError(Code.MethodNotFound, `no such method ${method}`);
192
+ },
193
+ };
194
+ }
195
+ /**
196
+ * A site as site.run reaches it: at the acquisition's site under call, or
197
+ * (without one) a site the host resolves for the type.
198
+ */
199
+ export function site(ctx, type, id, call) {
200
+ return {
201
+ id,
202
+ run: async (cmd, signal) => {
203
+ const stdin = cmd.stdin === undefined ? undefined : toBytes(cmd.stdin);
204
+ const out = await ctx.host.call("site.run", {
205
+ type,
206
+ ...(call ? { call } : {}),
207
+ site: id,
208
+ command: {
209
+ argv: [...cmd.argv],
210
+ ...(cmd.dir ? { dir: cmd.dir } : {}),
211
+ ...(cmd.env?.length ? { env: [...cmd.env] } : {}),
212
+ ...(stdin?.length ? { stdin: base64(stdin) } : {}),
213
+ ...(cmd.timeoutMs
214
+ ? { timeout_millis: Math.floor(cmd.timeoutMs) }
215
+ : {}),
216
+ },
217
+ }, SiteResult, signal ?? ctx.signal);
218
+ return {
219
+ exitCode: out.exit_code,
220
+ stdout: bytes(out.stdout),
221
+ stderr: bytes(out.stderr),
222
+ truncated: out.truncated === true,
223
+ };
224
+ },
225
+ };
226
+ }
227
+ function ownerStatus(ctx, reconcile) {
228
+ return async (owner) => {
229
+ const s = await ctx.host.call("provider.owner_status", { reconcile, owner }, OwnerStatus, ctx.signal);
230
+ return {
231
+ known: s.known,
232
+ executionDone: s.execution_done,
233
+ executionSucceeded: s.execution_succeeded,
234
+ workDone: s.work_done,
235
+ workSucceeded: s.work_succeeded,
236
+ mounts: [...(s.mounts ?? [])],
237
+ };
238
+ };
239
+ }
240
+ function resourceOut(r) {
241
+ if (!isRecord(r) || typeof r.kind !== "string" || typeof r.ref !== "string")
242
+ throw new Error("sdk: a resource needs a kind and a ref");
243
+ return {
244
+ kind: r.kind,
245
+ ref: r.ref,
246
+ ...(r.dir ? { dir: r.dir } : {}),
247
+ ...(r.env && Object.keys(r.env).length > 0 ? { env: { ...r.env } } : {}),
248
+ data: r.data ?? {},
249
+ ...(r.summary ? { summary: r.summary } : {}),
250
+ ...(r.sandbox ? { sandbox: r.sandbox } : {}),
251
+ ...(r.site ? { site: r.site } : {}),
252
+ ...(r.files && Object.keys(r.files).length > 0
253
+ ? { files: { ...r.files } }
254
+ : {}),
255
+ };
256
+ }
257
+ /** Go's zero time, which a lease report without a retention carries. */
258
+ const zeroTime = "0001-01-01T00:00:00Z";
259
+ function reportOut(r) {
260
+ return {
261
+ active: r.active,
262
+ released: r.released,
263
+ removed: r.removed,
264
+ retained: r.retained,
265
+ ...(r.attention?.length
266
+ ? {
267
+ attention: r.attention.map((a) => ({
268
+ ref: a.ref,
269
+ mode: a.mode,
270
+ state: a.state,
271
+ ...(a.code ? { code: a.code } : {}),
272
+ retain_until: time(a.retainUntil),
273
+ })),
274
+ }
275
+ : {}),
276
+ };
277
+ }
278
+ function sweepOut(r) {
279
+ const spares = (in_) => (in_ ?? []).map((s) => ({
280
+ ref: s.ref,
281
+ ...(s.mode ? { mode: s.mode } : {}),
282
+ spare: s.spare,
283
+ ...(s.kept ? { kept: s.kept } : {}),
284
+ }));
285
+ const removed = spares(r.removed);
286
+ const kept = spares(r.kept);
287
+ return {
288
+ ...(removed.length > 0 ? { removed } : {}),
289
+ ...(kept.length > 0 ? { kept } : {}),
290
+ };
291
+ }
292
+ function time(t) {
293
+ if (t === undefined || t === "")
294
+ return zeroTime;
295
+ if (t instanceof Date)
296
+ return Number.isNaN(t.getTime()) ? zeroTime : t.toISOString();
297
+ return t;
298
+ }
299
+ function bytes(b64) {
300
+ return b64 === undefined
301
+ ? new Uint8Array()
302
+ : new Uint8Array(Buffer.from(b64, "base64"));
303
+ }
@@ -0,0 +1,84 @@
1
+ import type { Context } from "./extension.js";
2
+ import { type Infer, type Type } from "./schema.js";
3
+ import { type Payload, type ResourceOwner, type SandboxLaunch, type SandboxNeeds, type SandboxPaths, type SandboxPlan } from "./wire.js";
4
+ /** What an interrupt of a sandboxed launch can promise (extension.SandboxTerm, SandboxKill). */
5
+ export declare const SandboxSignals: {
6
+ /** A termination signal sent to the executor's process group reaches the sandboxed command. */
7
+ readonly Term: "term";
8
+ /** The sandboxed command runs outside the group, so only killing the wrapper stops it. */
9
+ readonly Kill: "kill";
10
+ };
11
+ /** One launch to wrap (extension.SandboxProvider.Plan). */
12
+ export interface SandboxPlanRequest<C> {
13
+ type: string;
14
+ owner: ResourceOwner;
15
+ /** The binding's sandbox config, decoded by the provider's schema. */
16
+ config: C;
17
+ /** This attempt's host-set paths. */
18
+ paths: SandboxPaths;
19
+ /** The launch's needs, the resource's and the host's protected set already merged in. */
20
+ needs: SandboxNeeds;
21
+ launch: SandboxLaunch;
22
+ }
23
+ /** A wrapped launch (extension.SandboxPlan). The host computes its digest from argv and data. */
24
+ export interface SandboxPlanOut {
25
+ /** What runs in place of the launch's argv. */
26
+ argv: string[];
27
+ env?: string[];
28
+ /** SandboxSignals.Term or Kill. */
29
+ signals?: string;
30
+ /** One line for history. */
31
+ summary?: string;
32
+ /** The effective policy, for history; the digest covers it. */
33
+ data?: Payload;
34
+ /** Where the wrapper runs argv, when not the launch's directory. */
35
+ dir?: string;
36
+ }
37
+ /** A recovered segment's plan, as the host pinned it, and its processes (extension.SandboxProvider.Adopt). */
38
+ export interface SandboxAdoptRequest {
39
+ type: string;
40
+ plan: SandboxPlan;
41
+ /** The executor's wrapper that runs the plan. */
42
+ parent: number;
43
+ /** The sandbox root's pid, recorded as it started; 0 when it never started or has exited. */
44
+ root: number;
45
+ }
46
+ /** The context of a sandbox provider's call. */
47
+ export interface SandboxContext extends Context {
48
+ /** The extension's private state directory, from initialize. */
49
+ stateDir: string;
50
+ }
51
+ /**
52
+ * A process sandbox provider type (extension.SandboxProvider), which a
53
+ * binding's sandbox config names.
54
+ *
55
+ * plan applies the operator's policy and checks every need against it. It
56
+ * never widens the policy: refuse a need outside it with
57
+ * Code.SandboxDenied, and anything it can't enforce with
58
+ * Code.SandboxUnavailable (a ProtocolError, whose message crosses to the
59
+ * executor). adopt proves, when a restarted host recovers a segment, that
60
+ * the process tree running the plan is still inside the boundary it
61
+ * launched; anything it can't prove, a plan it never made included, is a
62
+ * refusal, and the segment isn't adopted. Anything else thrown crosses as
63
+ * internal, which the host treats as the sandbox being unavailable, so
64
+ * nothing runs.
65
+ */
66
+ export interface SandboxProviderSpec<S extends Type<unknown>> {
67
+ /** The sandbox config's schema: validate (kind sandbox) refuses a config it doesn't match. */
68
+ config?: S;
69
+ /**
70
+ * Checks the schema can't express; throw to refuse the config. A
71
+ * ConfigError says which field is wrong and why; anything else thrown is
72
+ * reported only as invalid.
73
+ */
74
+ validate?: (config: Infer<S>) => void | Promise<void>;
75
+ plan: (r: SandboxPlanRequest<Infer<S>>, ctx: SandboxContext) => SandboxPlanOut | Promise<SandboxPlanOut>;
76
+ adopt: (r: SandboxAdoptRequest, ctx: SandboxContext) => void | Promise<void>;
77
+ }
78
+ /** @internal */
79
+ export interface SandboxHandler {
80
+ validate: (config: unknown) => Promise<void>;
81
+ serve: (method: string, raw: unknown, ctx: SandboxContext) => Promise<unknown>;
82
+ }
83
+ /** @internal */
84
+ export declare function sandboxHandler<S extends Type<unknown>>(type: string, spec: SandboxProviderSpec<S>, params: <T extends Type<unknown>>(schema: T, raw: unknown) => Infer<T>): SandboxHandler;
@@ -0,0 +1,85 @@
1
+ // Sandbox providers: sandbox_provider.* and validate (kind sandbox), as
2
+ // protocol/sdk serves sdk.Extension.Sandboxes (protocol/sdk/surfaces.go).
3
+ // The host binds a provider to an attempt (extension.BindSandbox): it
4
+ // merges the resource's needs and its own protected set into the launch's
5
+ // needs and pins the plan's digest, computed from the argv and data the
6
+ // provider answers, so the provider only turns a policy and needs into a
7
+ // wrapped launch, and later proves a recovered one still runs inside it.
8
+ import { Code, ConfigError, ProtocolError } from "./errors.js";
9
+ import { diagnose, matches } from "./schema.js";
10
+ import { SandboxProviderAdoptParams, SandboxProviderPlanParams, } from "./wire.js";
11
+ /** What an interrupt of a sandboxed launch can promise (extension.SandboxTerm, SandboxKill). */
12
+ export const SandboxSignals = {
13
+ /** A termination signal sent to the executor's process group reaches the sandboxed command. */
14
+ Term: "term",
15
+ /** The sandboxed command runs outside the group, so only killing the wrapper stops it. */
16
+ Kill: "kill",
17
+ };
18
+ /** @internal */
19
+ export function sandboxHandler(type, spec, params) {
20
+ const schema = spec.config;
21
+ return {
22
+ validate: async (raw) => {
23
+ const c = raw ?? {};
24
+ if (schema !== undefined && !matches(schema, c)) {
25
+ const diagnostics = diagnose(schema, c);
26
+ if (diagnostics.length > 0)
27
+ throw new ConfigError(diagnostics);
28
+ throw new ProtocolError(Code.Invalid, "invalid sandbox config");
29
+ }
30
+ try {
31
+ await spec.validate?.(c);
32
+ }
33
+ catch (err) {
34
+ if (err instanceof ConfigError)
35
+ throw err;
36
+ throw new ProtocolError(Code.Invalid, "invalid sandbox config");
37
+ }
38
+ },
39
+ serve: async (method, raw, ctx) => {
40
+ switch (method) {
41
+ case "sandbox_provider.plan": {
42
+ const p = params(SandboxProviderPlanParams, raw);
43
+ const c = p.config.data ?? {};
44
+ // A stored binding passed validate; one whose config no longer
45
+ // matches (a package upgrade changed the schema) runs nothing.
46
+ if (schema !== undefined && !matches(schema, c))
47
+ throw new ProtocolError(Code.SandboxUnavailable, "the binding's sandbox config doesn't match the provider's");
48
+ const plan = await spec.plan({
49
+ type,
50
+ owner: p.owner,
51
+ config: c,
52
+ paths: p.paths,
53
+ needs: p.needs,
54
+ launch: p.launch,
55
+ }, ctx);
56
+ if (!Array.isArray(plan?.argv) || plan.argv.length === 0)
57
+ throw new ProtocolError(Code.SandboxUnavailable, "the sandbox provider planned no command");
58
+ const out = { argv: [...plan.argv] };
59
+ if (plan.env?.length)
60
+ out.env = [...plan.env];
61
+ if (plan.signals)
62
+ out.signals = plan.signals;
63
+ if (plan.summary)
64
+ out.summary = plan.summary;
65
+ if (plan.data !== undefined)
66
+ out.data = plan.data;
67
+ if (plan.dir)
68
+ out.dir = plan.dir;
69
+ return out;
70
+ }
71
+ case "sandbox_provider.adopt": {
72
+ const p = params(SandboxProviderAdoptParams, raw);
73
+ await spec.adopt({
74
+ type,
75
+ plan: { ...p.plan, argv: p.plan.argv ?? [] },
76
+ parent: p.parent,
77
+ root: p.root,
78
+ }, ctx);
79
+ return {};
80
+ }
81
+ }
82
+ throw new ProtocolError(Code.MethodNotFound, `no such method ${method}`);
83
+ },
84
+ };
85
+ }
@@ -0,0 +1,145 @@
1
+ import { ProtocolError } from "./errors.js";
2
+ import type { Context } from "./extension.js";
3
+ import type { Host } from "./host.js";
4
+ import { type ConfigCandidateResult, type SetupRunParams, type SetupRunResult, type Work } from "./wire.js";
5
+ /** The change states core knows (extension.ChangeProposed, ChangeApproved); others (rejected, withdrawn, applied) are shown as they are. */
6
+ export declare const ChangeState: {
7
+ /** Waiting on the operator. */
8
+ readonly Proposed: "proposed";
9
+ /** Approved and waiting to be applied. */
10
+ readonly Approved: "approved";
11
+ };
12
+ /**
13
+ * One proposed change (extension.CandidateChange): an edit at a JSON
14
+ * pointer of the config file, with its reason, the redacted value before
15
+ * and after (undefined when there is none: an add, a remove) and its
16
+ * problems. approve and reject are the IDs of the extension's actions that
17
+ * decide it, when offered now; reject takes an optional reason as input.
18
+ */
19
+ export interface CandidateChange {
20
+ id: string;
21
+ op: string;
22
+ pointer: string;
23
+ state: string;
24
+ why?: string;
25
+ before?: unknown;
26
+ after?: unknown;
27
+ problems?: string[];
28
+ approve?: string;
29
+ reject?: string;
30
+ }
31
+ /**
32
+ * The configuration a Work proposes (extension.Candidate). handle is one
33
+ * the host gave the extension (host.configBase, host.configEdit) on the
34
+ * config file text with every approved change made, baseGeneration the
35
+ * generation it is based on and hash its hash (host.configValidate). The
36
+ * host serves the text behind it to the operator alone, who applies it;
37
+ * nothing else can. Leave handle out while nothing is approved: there is
38
+ * nothing to apply yet. approveAll and validate are the IDs of the actions
39
+ * that approve every open change and validate the approved ones, when
40
+ * offered now.
41
+ */
42
+ export interface Candidate {
43
+ handle?: string;
44
+ baseGeneration?: string;
45
+ hash?: string;
46
+ /** Every change proposed on the Work, in proposal order. */
47
+ changes?: CandidateChange[];
48
+ approveAll?: string;
49
+ validate?: string;
50
+ }
51
+ /**
52
+ * Says what a Work proposes (extension.ConfigCandidate, manifest
53
+ * config_candidate): undefined for a Work with nothing proposed. The host
54
+ * asks only an extension with the config.read permission, which
55
+ * registering one asks for, about Work of a kind it owns, and bounds the
56
+ * call to five seconds, asking again after a KV conflict.
57
+ */
58
+ export type ConfigCandidateFn = (work: Work, ctx: Context) => Candidate | undefined | Promise<Candidate | undefined>;
59
+ /** c on the wire (protocol.FromCandidate); undefined is a Work with nothing proposed. */
60
+ export declare function candidateResult(c: Candidate | undefined): ConfigCandidateResult;
61
+ /** The candidate a config.candidate answer carries (ConfigCandidateResult.Candidate), or undefined when it has none. */
62
+ export declare function candidateOf(r: ConfigCandidateResult): Candidate | undefined;
63
+ /**
64
+ * Thrown by a SetupHost's prompt or choose when the session takes no
65
+ * interactive input (extension.ErrSetupNoInput): a flow run with flags
66
+ * alone, say. Fall back to a default or ask for a flag.
67
+ */
68
+ export declare class SetupNoInput extends Error {
69
+ constructor();
70
+ }
71
+ /**
72
+ * A setup flow's usage error (extension.ErrSetupUsage): the arguments it
73
+ * was given don't make sense. It crosses as invalid with its message,
74
+ * which the operator reads with the flow's usage, so it must be fixed text
75
+ * with no secret in it.
76
+ */
77
+ export declare class SetupUsageError extends ProtocolError {
78
+ constructor(message: string);
79
+ }
80
+ /**
81
+ * What a setup flow drives the operator through (extension.SetupHost),
82
+ * each call one of the host's setup.* callbacks for this run. The host
83
+ * answers them only while the run lasts.
84
+ */
85
+ export interface SetupHost {
86
+ /** The existing config document, when there is one, so a flow can reuse connections or pick a free scope ID. */
87
+ readonly config: Uint8Array | undefined;
88
+ /** The operator's working directory. */
89
+ readonly cwd: string;
90
+ /** Open Conduit's private state directory, for files a flow must prepare. */
91
+ readonly stateDir: string;
92
+ /** `--dry-run`: no secrets are stored and nothing is saved. */
93
+ readonly dryRun: boolean;
94
+ /** Shows the operator a line of text. A failure to show it is ignored, as the Go SDK ignores it. */
95
+ print(text: string): Promise<void>;
96
+ /** Asks a question, answering default when the operator just presses enter; secret hides what they type. Throws SetupNoInput without interactive input. */
97
+ prompt(question: string, o?: {
98
+ default?: string;
99
+ secret?: boolean;
100
+ }): Promise<string>;
101
+ /** Asks the operator to choose one of options, answering its index. Throws SetupNoInput without interactive input. */
102
+ choose(question: string, options: string[]): Promise<number>;
103
+ /** Opens a URL in the operator's browser, or shows it. */
104
+ openURL(url: string): Promise<void>;
105
+ /** Stores a secret through the host's secret store (keyring, else the owner-only secrets file) and answers its reference, such as "keyring:bot-token", for the config to name rather than the value. In a dry run it stores nothing and answers the reference it would use. */
106
+ storeSecret(name: string, value: string): Promise<string>;
107
+ /** Finds a program on the operator's PATH: its path, or undefined. */
108
+ lookPath(name: string): Promise<string | undefined>;
109
+ /** Runs a command attached to the operator's terminal in dir. */
110
+ run(dir: string, name: string, args?: string[], signal?: AbortSignal): Promise<void>;
111
+ }
112
+ /**
113
+ * What a setup flow found (extension.SetupResult), which the host merges
114
+ * into the config: each connection is added when none with its id exists
115
+ * (an existing one is kept), and the scope replaces one with the same id
116
+ * only with --force. summary lines are printed once the config is saved,
117
+ * and next lists follow-up commands.
118
+ */
119
+ export interface SetupResult {
120
+ connections?: unknown[];
121
+ scope?: unknown;
122
+ summary?: string[];
123
+ next?: string[];
124
+ }
125
+ /**
126
+ * An `open-conduit init <type>` flow (extension.Setup, manifest setup).
127
+ * type is the setup type, summary and usage what `init` lists, and
128
+ * firstRun marks the setup whose result, with no flags, is the
129
+ * configuration a daemon with no config file and no stored generation
130
+ * runs on. run gets the flow's arguments and the SetupHost of the run.
131
+ * Throw SetupUsageError for arguments that don't make sense; any other
132
+ * ProtocolError crosses with its code and message, and anything else
133
+ * thrown as a fixed internal error.
134
+ */
135
+ export interface SetupSpec {
136
+ type: string;
137
+ summary: string;
138
+ usage?: string;
139
+ firstRun?: boolean;
140
+ run: (args: string[], host: SetupHost, ctx: Context) => SetupResult | Promise<SetupResult>;
141
+ }
142
+ /** The SetupHost over the setup.* callbacks of run p. */
143
+ export declare function setupHost(host: Host, p: SetupRunParams, signal: AbortSignal): SetupHost;
144
+ /** r on the wire (protocol.SetupRunResult). */
145
+ export declare function setupResult(r: SetupResult): SetupRunResult;