@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.
- package/LICENSE +21 -0
- package/README.md +12 -2
- package/dist/actions.d.ts +145 -0
- package/dist/actions.js +281 -0
- package/dist/actiontest.d.ts +80 -0
- package/dist/actiontest.js +190 -0
- package/dist/artifactstore.d.ts +133 -0
- package/dist/artifactstore.js +364 -0
- package/dist/backup.d.ts +99 -0
- package/dist/backup.js +178 -0
- package/dist/containertest.d.ts +71 -0
- package/dist/containertest.js +294 -0
- package/dist/errors.d.ts +127 -0
- package/dist/errors.js +180 -0
- package/dist/executor.d.ts +374 -0
- package/dist/executor.js +556 -0
- package/dist/executortest.d.ts +183 -0
- package/dist/executortest.js +534 -0
- package/dist/extension.d.ts +855 -0
- package/dist/extension.js +1822 -0
- package/dist/feed.d.ts +20 -0
- package/dist/feed.js +88 -0
- package/dist/forward.d.ts +38 -0
- package/dist/forward.js +163 -0
- package/dist/forwardca.d.ts +21 -0
- package/dist/forwardca.js +144 -0
- package/dist/hooks.d.ts +108 -0
- package/dist/hooks.js +13 -0
- package/dist/host.d.ts +295 -0
- package/dist/host.js +486 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +31 -0
- package/dist/jsonrpc.d.ts +39 -0
- package/dist/jsonrpc.js +350 -0
- package/dist/probe.d.ts +61 -0
- package/dist/probe.js +92 -0
- package/dist/providertest.d.ts +59 -0
- package/dist/providertest.js +168 -0
- package/dist/resources.d.ts +208 -0
- package/dist/resources.js +303 -0
- package/dist/sandbox.d.ts +84 -0
- package/dist/sandbox.js +85 -0
- package/dist/schema.d.ts +71 -0
- package/dist/schema.js +252 -0
- package/dist/setup.d.ts +145 -0
- package/dist/setup.js +179 -0
- package/dist/setuptest.d.ts +90 -0
- package/dist/setuptest.js +319 -0
- package/dist/storetest.d.ts +64 -0
- package/dist/storetest.js +740 -0
- package/dist/telemetry.d.ts +86 -0
- package/dist/telemetry.js +46 -0
- package/dist/testing.d.ts +756 -0
- package/dist/testing.js +2165 -0
- package/dist/toolbelt.d.ts +91 -0
- package/dist/toolbelt.js +216 -0
- package/dist/tunnel.d.ts +62 -0
- package/dist/tunnel.js +93 -0
- package/dist/wire.d.ts +5359 -0
- package/dist/wire.js +2211 -0
- package/package.json +29 -4
package/dist/host.js
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
// The extension's client for the scoped extension-to-host methods, as
|
|
2
|
+
// protocol/sdk/host.go offers them. The host binds every call to the
|
|
3
|
+
// identity it started the process with, so nothing here can name another
|
|
4
|
+
// extension's namespaces or scopes.
|
|
5
|
+
import { Code, ProtocolError } from "./errors.js";
|
|
6
|
+
import { MaxChunkBytes } from "./jsonrpc.js";
|
|
7
|
+
import { matches, t } from "./schema.js";
|
|
8
|
+
import { AcceptedEvent, ArtifactCreateResult, ArtifactRef, ConfigBaseResult, ConfigEditResult, ConfigTraceResult, ConfigValidateResult, EntrySandboxResult, EventAcceptResult, EventRenderResult, Execution, IngressDeliverResult, KVGetResult, KVListResult, PendingInput, ProbeListResult, ProbeRunResult, RequestListResult, ActionListResult, ActionSubmitResult, ScopeAuthorizeResult, SecretResolveResult, TargetResolveResult, Work, WorkCancelResult, WorkSettleHoldResult, } from "./wire.js";
|
|
9
|
+
/** The most Work one state.works page holds (protocol.MaxWorksPage). */
|
|
10
|
+
export const MaxWorksPage = 1000;
|
|
11
|
+
const Empty = t.any();
|
|
12
|
+
export class Host {
|
|
13
|
+
#call;
|
|
14
|
+
#dirs;
|
|
15
|
+
/** dirs answers what the host named at initialize; without it both are "". */
|
|
16
|
+
constructor(call, dirs = () => ({
|
|
17
|
+
stateDir: "",
|
|
18
|
+
configDir: "",
|
|
19
|
+
})) {
|
|
20
|
+
this.#call = call;
|
|
21
|
+
this.#dirs = dirs;
|
|
22
|
+
}
|
|
23
|
+
/** The extension's private state directory the host named at initialize. */
|
|
24
|
+
get stateDir() {
|
|
25
|
+
return this.#dirs().stateDir;
|
|
26
|
+
}
|
|
27
|
+
/** The operator's config file's directory the host named at initialize ("" for none), against which a relative path in a config resolves. */
|
|
28
|
+
get configDir() {
|
|
29
|
+
return this.#dirs().configDir;
|
|
30
|
+
}
|
|
31
|
+
/** Makes any extension-to-host call, decoding its result through result. */
|
|
32
|
+
async call(method, params, result, signal) {
|
|
33
|
+
const out = await this.#call(method, params, signal);
|
|
34
|
+
// A result that doesn't match is refused, as the Go SDK's decoding refuses it.
|
|
35
|
+
if (!matches(result, out))
|
|
36
|
+
throw new ProtocolError(Code.Invalid, `malformed ${method} result`);
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
/** Runs one of the extension's own tasks on the host's next pass. */
|
|
40
|
+
async wakeTask(task, signal) {
|
|
41
|
+
await this.#call("task.wake", { task }, signal);
|
|
42
|
+
}
|
|
43
|
+
/** A KV value and its version, or undefined when the key is absent. */
|
|
44
|
+
async get(namespace, key, signal) {
|
|
45
|
+
const out = await this.call("kv.get", { namespace, key }, KVGetResult, signal);
|
|
46
|
+
return out.found ? entry(out.entry) : undefined;
|
|
47
|
+
}
|
|
48
|
+
/** The entries under prefix, in lexical key order. */
|
|
49
|
+
async list(namespace, prefix = "", signal) {
|
|
50
|
+
const out = await this.call("kv.list", prefix === "" ? { namespace } : { namespace, prefix }, KVListResult, signal);
|
|
51
|
+
return (out.entries ?? []).map(entry);
|
|
52
|
+
}
|
|
53
|
+
/** Applies a batch atomically; a failed check throws ProtocolError conflict. */
|
|
54
|
+
async commit(b, signal) {
|
|
55
|
+
const { puts, ...rest } = batchFields(b);
|
|
56
|
+
await this.call("kv.commit", puts === undefined ? rest : { ...rest, puts }, Empty, signal);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Reads a key, applies fn and commits with a version check, retrying when
|
|
60
|
+
* another writer got there first. fn returns undefined to delete the key.
|
|
61
|
+
*/
|
|
62
|
+
async update(namespace, key, fn, signal) {
|
|
63
|
+
for (let attempt = 0; attempt < 16; attempt++) {
|
|
64
|
+
const old = await this.get(namespace, key, signal);
|
|
65
|
+
const value = await fn(old?.value);
|
|
66
|
+
const check = old === undefined
|
|
67
|
+
? { namespace, key, absent: true }
|
|
68
|
+
: { namespace, key, version: old.version };
|
|
69
|
+
const b = value === undefined
|
|
70
|
+
? { checks: [check], deletes: [{ namespace, key }] }
|
|
71
|
+
: { checks: [check], puts: [{ namespace, key, value }] };
|
|
72
|
+
try {
|
|
73
|
+
return await this.commit(b, signal);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
if (!(err instanceof ProtocolError && err.code === Code.Conflict))
|
|
77
|
+
throw err;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
throw new ProtocolError(Code.Conflict, "update kept conflicting");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Derives one Event from parent (an accepted Event in a configured scope),
|
|
84
|
+
* committing the batch's KV writes atomically with it.
|
|
85
|
+
*/
|
|
86
|
+
async accept(a, signal) {
|
|
87
|
+
const { puts, ...rest } = batchFields(a);
|
|
88
|
+
// event.accept calls its puts "records".
|
|
89
|
+
const params = {
|
|
90
|
+
scope_id: a.scopeId,
|
|
91
|
+
parent: a.parent,
|
|
92
|
+
event: a.event,
|
|
93
|
+
...rest,
|
|
94
|
+
};
|
|
95
|
+
return this.call("event.accept", puts === undefined ? params : { ...params, records: puts }, EventAcceptResult, signal);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Hands a delivery (a verified webhook's body) to the source registered
|
|
99
|
+
* as name. The host calls the source's push with it and answers once its
|
|
100
|
+
* Events are durably accepted: added[i] is false for an Event it already
|
|
101
|
+
* had, such as a sender's retry.
|
|
102
|
+
*/
|
|
103
|
+
async deliver(name, delivery, signal) {
|
|
104
|
+
const out = await this.call("ingress.deliver", {
|
|
105
|
+
name,
|
|
106
|
+
delivery: {
|
|
107
|
+
id: delivery.id,
|
|
108
|
+
received_at: delivery.receivedAt ?? new Date().toISOString(),
|
|
109
|
+
...(delivery.contentType
|
|
110
|
+
? { content_type: delivery.contentType }
|
|
111
|
+
: {}),
|
|
112
|
+
...(delivery.body === undefined
|
|
113
|
+
? {}
|
|
114
|
+
: { body: base64(toBytes(delivery.body)) }),
|
|
115
|
+
},
|
|
116
|
+
}, IngressDeliverResult, signal);
|
|
117
|
+
return { accepted: out.accepted ?? [], added: out.added ?? [] };
|
|
118
|
+
}
|
|
119
|
+
/** Accepted Events of the configured scopes after a sequence. */
|
|
120
|
+
async events(after = 0, limit = 0, signal) {
|
|
121
|
+
const params = {
|
|
122
|
+
...(after > 0 ? { after } : {}),
|
|
123
|
+
...(limit > 0 ? { limit } : {}),
|
|
124
|
+
};
|
|
125
|
+
return ((await this.call("state.events", params, t.nullable(t.array(AcceptedEvent)), signal)) ?? []);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* One Work's accepted Events of the configured scopes after a sequence:
|
|
129
|
+
* those naming it and those routed to it. The host reads them from its
|
|
130
|
+
* index, so the cost follows the Work's own Events, not the whole log.
|
|
131
|
+
*/
|
|
132
|
+
async workEvents(workId, after = 0, limit = 0, signal) {
|
|
133
|
+
if (workId === "")
|
|
134
|
+
return [];
|
|
135
|
+
const params = {
|
|
136
|
+
id: workId,
|
|
137
|
+
...(after > 0 ? { after } : {}),
|
|
138
|
+
...(limit > 0 ? { limit } : {}),
|
|
139
|
+
};
|
|
140
|
+
return ((await this.call("state.work_events", params, t.nullable(t.array(AcceptedEvent)), signal)) ?? []);
|
|
141
|
+
}
|
|
142
|
+
/** Work of the configured scopes (one scope when scopeId is set). */
|
|
143
|
+
async works(scopeId = "", signal) {
|
|
144
|
+
return this.queryWorks(scopeId === "" ? {} : { scopeId }, signal);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The Work a query selects, of the configured scopes and the extension's
|
|
148
|
+
* own kinds, in its order (by creation unless `order` says otherwise),
|
|
149
|
+
* at most `limit` (all when unset). The host reads them through its
|
|
150
|
+
* indexes a page at a time, so the cost follows the Work selected, not
|
|
151
|
+
* every Work ever made: ask for live Work with `states`, or for Work
|
|
152
|
+
* changed since a time with `updatedSince`.
|
|
153
|
+
*/
|
|
154
|
+
async queryWorks(query, signal) {
|
|
155
|
+
const order = query.order ?? "created";
|
|
156
|
+
const all = [];
|
|
157
|
+
let cursor;
|
|
158
|
+
for (;;) {
|
|
159
|
+
const page = query.limit !== undefined && query.limit > 0
|
|
160
|
+
? Math.min(MaxWorksPage, query.limit - all.length)
|
|
161
|
+
: MaxWorksPage;
|
|
162
|
+
const params = {
|
|
163
|
+
...(query.scopeId ? { scope_id: query.scopeId } : {}),
|
|
164
|
+
...(query.states?.length ? { states: query.states } : {}),
|
|
165
|
+
...(query.kind ? { kind: query.kind } : {}),
|
|
166
|
+
...(query.parentId ? { parent_id: query.parentId } : {}),
|
|
167
|
+
...(query.sources?.length ? { sources: query.sources } : {}),
|
|
168
|
+
...(query.executor ? { executor: query.executor } : {}),
|
|
169
|
+
...(query.updatedSince ? { updated_since: query.updatedSince } : {}),
|
|
170
|
+
...(query.order ? { order: query.order } : {}),
|
|
171
|
+
...(cursor ? { cursor } : {}),
|
|
172
|
+
limit: page,
|
|
173
|
+
};
|
|
174
|
+
const got = (await this.call("state.works", params, t.nullable(t.array(Work)), signal)) ?? [];
|
|
175
|
+
// A host that predates the query answers every Work in one page.
|
|
176
|
+
if (got.length > page)
|
|
177
|
+
return got;
|
|
178
|
+
all.push(...got);
|
|
179
|
+
const last = got[got.length - 1];
|
|
180
|
+
if (got.length < page ||
|
|
181
|
+
last === undefined ||
|
|
182
|
+
(query.limit !== undefined &&
|
|
183
|
+
query.limit > 0 &&
|
|
184
|
+
all.length >= query.limit))
|
|
185
|
+
return all;
|
|
186
|
+
cursor = {
|
|
187
|
+
at: order.endsWith("updated") ? last.updated_at : last.created_at,
|
|
188
|
+
id: last.id,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* The input routed to a Work that no attempt of it has read yet, oldest
|
|
194
|
+
* first. Ready Work with none has read everything routed to it; ready
|
|
195
|
+
* Work with some is about to start on it.
|
|
196
|
+
*/
|
|
197
|
+
async pending(workId, signal) {
|
|
198
|
+
return ((await this.call("state.pending", { id: workId }, t.nullable(t.array(PendingInput)), signal)) ?? []);
|
|
199
|
+
}
|
|
200
|
+
/** Resolves secret names bound to the extension's entry in a scope. */
|
|
201
|
+
async secrets(scopeId, names, signal) {
|
|
202
|
+
const out = await this.call("secret.resolve", { scope_id: scopeId, names }, SecretResolveResult, signal);
|
|
203
|
+
return out.values ?? {};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Resolves secret names of a connection an entry or binding in the scope
|
|
207
|
+
* names, such as an operation's authority.connection.
|
|
208
|
+
*/
|
|
209
|
+
async connectionSecrets(scopeId, connection, names, signal) {
|
|
210
|
+
const out = await this.call("secret.resolve", { scope_id: scopeId, connection, names }, SecretResolveResult, signal);
|
|
211
|
+
return out.values ?? {};
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Resolves secret names a binding in the scope selects, when the
|
|
215
|
+
* binding's executor is one of the extension's own: the values each of
|
|
216
|
+
* its runs is given, for a doctor check that the binding's credential
|
|
217
|
+
* works. The host refuses any other binding or name.
|
|
218
|
+
*/
|
|
219
|
+
async bindingSecrets(scopeId, binding, names, signal) {
|
|
220
|
+
const out = await this.call("secret.resolve", { scope_id: scopeId, binding, names }, SecretResolveResult, signal);
|
|
221
|
+
return out.values ?? {};
|
|
222
|
+
}
|
|
223
|
+
/** Writes an immutable artifact in chunks, each acknowledged before the next. */
|
|
224
|
+
async artifact(mediaType, data, signal) {
|
|
225
|
+
const bytes = toBytes(data);
|
|
226
|
+
const { writer } = await this.call("artifact.create", { media_type: mediaType }, ArtifactCreateResult, signal);
|
|
227
|
+
try {
|
|
228
|
+
for (let at = 0; at < bytes.length; at += MaxChunkBytes) {
|
|
229
|
+
await this.call("artifact.write", { writer, chunk: base64(bytes.subarray(at, at + MaxChunkBytes)) }, Empty, signal);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
catch (err) {
|
|
233
|
+
// Not under signal: a cancelled write must still release the writer.
|
|
234
|
+
await this.call("artifact.abort", { writer }, Empty).catch(() => { });
|
|
235
|
+
throw err;
|
|
236
|
+
}
|
|
237
|
+
return this.call("artifact.commit", { writer }, ArtifactRef, signal);
|
|
238
|
+
}
|
|
239
|
+
/** Sets the progress line of a Work's active Wait ("" clears it). */
|
|
240
|
+
async waitProgress(workId, progress, signal) {
|
|
241
|
+
await this.call("wait.progress", { work_id: workId, progress }, Empty, signal);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Records a named telemetry event in the host's telemetry events log,
|
|
245
|
+
* which every telemetry sink receives (telemetry.capture; it needs the
|
|
246
|
+
* telemetry.capture permission). scopeId is one of the extension's
|
|
247
|
+
* configured scopes, or absent for an event about the machine, and goes
|
|
248
|
+
* there rather than in properties; at (RFC 3339) defaults to the host's
|
|
249
|
+
* now. The host refuses a name over 128 bytes or with a newline, and
|
|
250
|
+
* properties over 64 KiB as JSON.
|
|
251
|
+
*/
|
|
252
|
+
async capture(e, signal) {
|
|
253
|
+
await this.call("telemetry.capture", {
|
|
254
|
+
...(e.scopeId ? { scope_id: e.scopeId } : {}),
|
|
255
|
+
name: e.name,
|
|
256
|
+
...(e.at === undefined ? {} : { at: e.at }),
|
|
257
|
+
...(e.properties === undefined ? {} : { properties: e.properties }),
|
|
258
|
+
}, Empty, signal);
|
|
259
|
+
}
|
|
260
|
+
// The host's config service (config.*; it needs the config.read
|
|
261
|
+
// permission). The host keeps config text behind handles and answers only
|
|
262
|
+
// copies with every secret_refs value "[redacted]", so an extension builds
|
|
263
|
+
// a candidate by editing a handle and never holds reference text. Nothing
|
|
264
|
+
// here applies a configuration: only the operator does that.
|
|
265
|
+
/**
|
|
266
|
+
* Reads the configuration now (config.base): its generation and hash, a
|
|
267
|
+
* handle on its file text, the text redacted, and the IDs of the scopes
|
|
268
|
+
* from included folders, whose text is in other files.
|
|
269
|
+
*/
|
|
270
|
+
async configBase(signal) {
|
|
271
|
+
return this.call("config.base", {}, ConfigBaseResult, signal);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Makes one RFC 6902 edit to the text behind handle (config.edit): op is
|
|
275
|
+
* add, replace or remove at a JSON pointer, and value (any JSON value, at
|
|
276
|
+
* most 64 KiB) is for add and replace. It answers the new candidate's
|
|
277
|
+
* handle, its text redacted and the value the edit replaced, redacted
|
|
278
|
+
* (undefined for an insert). The host refuses a pointer that doesn't
|
|
279
|
+
* start with "/" or is over 512 bytes as invalid, and a handle it no
|
|
280
|
+
* longer holds as not_found: read the base again.
|
|
281
|
+
*/
|
|
282
|
+
async configEdit(handle, op, pointer, value, signal) {
|
|
283
|
+
return this.call("config.edit", { handle, op, pointer, ...(value === undefined ? {} : { value }) }, ConfigEditResult, signal);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Validates the text behind handle as POST /config/validate would,
|
|
287
|
+
* changing nothing (config.validate): its hash when it is valid, its
|
|
288
|
+
* diagnostics when not.
|
|
289
|
+
*/
|
|
290
|
+
async configValidate(handle, signal) {
|
|
291
|
+
return this.call("config.validate", { handle }, ConfigValidateResult, signal);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Traces one of a scope's named samples against the text behind handle,
|
|
295
|
+
* writing nothing (config.trace); with no sample it lists the scope's
|
|
296
|
+
* samples. A trace that can't run answers error, a fixed reason.
|
|
297
|
+
*/
|
|
298
|
+
async configTrace(handle, scope, sample, signal) {
|
|
299
|
+
return this.call("config.trace", { handle, scope, ...(sample ? { sample } : {}) }, ConfigTraceResult, signal);
|
|
300
|
+
}
|
|
301
|
+
// Timers, cancellation and start holds.
|
|
302
|
+
/**
|
|
303
|
+
* Arms (or re-arms) a recurring timer of one of the extension's
|
|
304
|
+
* recurrence kinds in scopeId (timer.arm): the host fires it at
|
|
305
|
+
* timer.fire_at, asks the kind's recurrence for the occurrence and the
|
|
306
|
+
* next timer, and commits both with the firing. Its Event must be of the
|
|
307
|
+
* extension's own families, sourced in its namespace. expected guards a
|
|
308
|
+
* re-arm: 0 for a new timer, else the revision it replaces. spec is any
|
|
309
|
+
* JSON value, handed back to the recurrence on every firing.
|
|
310
|
+
*/
|
|
311
|
+
async armTimer(scopeId, timer, o, signal) {
|
|
312
|
+
await this.call("timer.arm", {
|
|
313
|
+
scope_id: scopeId,
|
|
314
|
+
timer,
|
|
315
|
+
expected: o.expected ?? 0,
|
|
316
|
+
kind: o.kind,
|
|
317
|
+
spec: o.spec ?? null,
|
|
318
|
+
}, Empty, signal);
|
|
319
|
+
}
|
|
320
|
+
/** Cancels one of the extension's timers, guarded by expected (timer.cancel); an absent one is a no-op. */
|
|
321
|
+
async cancelTimer(id, expected = 0, signal) {
|
|
322
|
+
await this.call("timer.cancel", { id, expected }, Empty, signal);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Cancels Work of one of the extension's own kinds (work.cancel),
|
|
326
|
+
* guarded by expected (its revision, 0 for any) and idempotent per key.
|
|
327
|
+
* It answers the ID of the cancellation's Event.
|
|
328
|
+
*/
|
|
329
|
+
async cancelWork(workId, o, signal) {
|
|
330
|
+
const out = await this.call("work.cancel", {
|
|
331
|
+
work_id: workId,
|
|
332
|
+
expected: o.expected ?? 0,
|
|
333
|
+
reason: o.reason,
|
|
334
|
+
key: o.key,
|
|
335
|
+
}, WorkCancelResult, signal);
|
|
336
|
+
return out.event_id;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Settles the hold the extension's start gate placed on a Work
|
|
340
|
+
* (work.settle_hold; it needs the work.start_gate permission): admit lets
|
|
341
|
+
* its next start through once, otherwise the Work is cancelled. reason
|
|
342
|
+
* goes in its history and key makes it idempotent. It answers the ID of
|
|
343
|
+
* the Event that records the settlement.
|
|
344
|
+
*/
|
|
345
|
+
async settleHold(workId, o, signal) {
|
|
346
|
+
const out = await this.call("work.settle_hold", {
|
|
347
|
+
work_id: workId,
|
|
348
|
+
admit: o.admit,
|
|
349
|
+
...(o.reason ? { reason: o.reason } : {}),
|
|
350
|
+
key: o.key,
|
|
351
|
+
}, WorkSettleHoldResult, signal);
|
|
352
|
+
return out.event_id;
|
|
353
|
+
}
|
|
354
|
+
// Reading across extensions.
|
|
355
|
+
/** One attempt of a Work in the extension's scopes or of its own kinds (state.execution). */
|
|
356
|
+
async execution(id, signal) {
|
|
357
|
+
return this.call("state.execution", { id }, Execution, signal);
|
|
358
|
+
}
|
|
359
|
+
/** The Event with a delivery identity, from the host's index (state.delivery); one outside the extension's scopes is not found. */
|
|
360
|
+
async eventByDelivery(source, deliveryId, signal) {
|
|
361
|
+
return this.call("state.delivery", { source, delivery_id: deliveryId }, AcceptedEvent, signal);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Renders an input Event for an agent's prompt through the extension
|
|
365
|
+
* that owns its family (event.render_owned), as an executor building a
|
|
366
|
+
* prompt does; undefined leaves it to the caller's own rendering.
|
|
367
|
+
*/
|
|
368
|
+
async renderOwned(event, signal) {
|
|
369
|
+
const out = await this.call("event.render_owned", { event }, EventRenderResult, signal);
|
|
370
|
+
return out.ok ? (out.text ?? "") : undefined;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Resolves a named wait target of kind in one of the extension's scopes
|
|
374
|
+
* ("job" for a `job:<name>` condition) through the extensions that
|
|
375
|
+
* resolve that kind (wait.target): the correlation key and Event types
|
|
376
|
+
* that end it, or undefined when none has it.
|
|
377
|
+
*/
|
|
378
|
+
async waitTarget(scopeId, kind, name, signal) {
|
|
379
|
+
const out = await this.call("wait.target", { scope_id: scopeId, kind, name }, TargetResolveResult, signal);
|
|
380
|
+
return out.ok ? { key: out.key, types: out.types ?? [] } : undefined;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Answers whether scope from, one of the extension's, may read ("read",
|
|
384
|
+
* authorization.read_scopes) or file in ("file",
|
|
385
|
+
* authorization.file_scopes) scope to under the operator's configuration
|
|
386
|
+
* (scope.authorize): undefined when it may, else the reason it may not
|
|
387
|
+
* and how the operator would allow it.
|
|
388
|
+
*/
|
|
389
|
+
async authorize(kind, from, to, signal) {
|
|
390
|
+
const out = await this.call("scope.authorize", { kind, from, to }, ScopeAuthorizeResult, signal);
|
|
391
|
+
return out.allowed ? undefined : (out.reason ?? "not allowed");
|
|
392
|
+
}
|
|
393
|
+
// Actions for a person on the extension's own surface (it needs the
|
|
394
|
+
// action.submit permission).
|
|
395
|
+
/**
|
|
396
|
+
* Invokes an action for a person the extension identified on its own
|
|
397
|
+
* surface (action.submit), such as answering an approval request from a
|
|
398
|
+
* button they pressed. The provider sees the caller as {kind: the
|
|
399
|
+
* extension's name, id: caller}; an empty provider is the one offering
|
|
400
|
+
* the action on the target, and key makes it idempotent. A refusal is
|
|
401
|
+
* the provider's OperationError.
|
|
402
|
+
*/
|
|
403
|
+
async act(r, signal) {
|
|
404
|
+
return this.call("action.submit", {
|
|
405
|
+
scope_id: r.scopeId,
|
|
406
|
+
...(r.workId ? { work_id: r.workId } : {}),
|
|
407
|
+
...(r.provider ? { provider: r.provider } : {}),
|
|
408
|
+
action: r.action,
|
|
409
|
+
...(r.input ? { input: r.input } : {}),
|
|
410
|
+
caller: r.caller,
|
|
411
|
+
key: r.key,
|
|
412
|
+
}, ActionSubmitResult, signal);
|
|
413
|
+
}
|
|
414
|
+
/** What every provider offers now on a scope, or on Work in it (action.list), for act to take. */
|
|
415
|
+
async actions(scopeId, workId = "", signal) {
|
|
416
|
+
const out = await this.call("action.list", { scope_id: scopeId, ...(workId ? { work_id: workId } : {}) }, ActionListResult, signal);
|
|
417
|
+
return out.actions ?? [];
|
|
418
|
+
}
|
|
419
|
+
/** The requests every provider reports on Work in a scope, open and settled, with who may answer each (request.list). */
|
|
420
|
+
async requests(scopeId, workId, signal) {
|
|
421
|
+
const out = await this.call("request.list", { scope_id: scopeId, work_id: workId }, RequestListResult, signal);
|
|
422
|
+
return out.requests ?? [];
|
|
423
|
+
}
|
|
424
|
+
// Setup probes (they need the probes permission).
|
|
425
|
+
/** The setup probes the host, its extensions and its executors offer, by full name (probe.list). */
|
|
426
|
+
async probes(signal) {
|
|
427
|
+
const out = await this.call("probe.list", {}, ProbeListResult, signal);
|
|
428
|
+
return out.probes ?? [];
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Runs one setup probe (probe.run), for a session in scopeId when given,
|
|
432
|
+
* which a probe that reads through a connection needs. A probe that ran
|
|
433
|
+
* and failed answers its reason in error.
|
|
434
|
+
*/
|
|
435
|
+
async probe(name, args = {}, scopeId = "", signal) {
|
|
436
|
+
return this.call("probe.run", {
|
|
437
|
+
name,
|
|
438
|
+
...(Object.keys(args).length > 0 ? { args } : {}),
|
|
439
|
+
...(scopeId ? { scope_id: scopeId } : {}),
|
|
440
|
+
}, ProbeRunResult, signal);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Plans a launch of one of the extension's own processes for its entry
|
|
444
|
+
* in scope, in the sandbox that entry names (an entry type declared with
|
|
445
|
+
* a sandbox; sandbox.entry_plan): the host plans it with the entry's
|
|
446
|
+
* provider and policy and makes the directory it runs in. Run plan.argv
|
|
447
|
+
* with plan.env in dir and nothing else; any error means nothing may run.
|
|
448
|
+
*/
|
|
449
|
+
async entrySandbox(scope, entry, needs, launch, signal) {
|
|
450
|
+
return this.call("sandbox.entry_plan", { scope, entry, needs, launch }, EntrySandboxResult, signal);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
function entry(e) {
|
|
454
|
+
return {
|
|
455
|
+
key: e.key,
|
|
456
|
+
value: e.value === null
|
|
457
|
+
? new Uint8Array()
|
|
458
|
+
: new Uint8Array(Buffer.from(e.value, "base64")),
|
|
459
|
+
version: e.version,
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
function batchFields(b) {
|
|
463
|
+
return {
|
|
464
|
+
...(b.checks?.length ? { checks: b.checks } : {}),
|
|
465
|
+
...(b.puts?.length
|
|
466
|
+
? {
|
|
467
|
+
puts: b.puts.map((p) => ({
|
|
468
|
+
namespace: p.namespace,
|
|
469
|
+
key: p.key,
|
|
470
|
+
value: base64(toBytes(p.value)),
|
|
471
|
+
})),
|
|
472
|
+
}
|
|
473
|
+
: {}),
|
|
474
|
+
...(b.deletes?.length ? { deletes: b.deletes } : {}),
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
export function toBytes(v) {
|
|
478
|
+
return typeof v === "string" ? new TextEncoder().encode(v) : v;
|
|
479
|
+
}
|
|
480
|
+
export function base64(b) {
|
|
481
|
+
return Buffer.from(b.buffer, b.byteOffset, b.byteLength).toString("base64");
|
|
482
|
+
}
|
|
483
|
+
/** Decodes a KV value as UTF-8 text. */
|
|
484
|
+
export function text(v) {
|
|
485
|
+
return new TextDecoder().decode(v);
|
|
486
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export { extension, Extension, Server, ProtocolVersions, ContainerLabel, } from "./extension.js";
|
|
2
|
+
export type { CallContext, CheckContext, CheckFn, CommitOut, ContainerConfig, ContainerContext, ContainerPlanRequest, ContainerReattach, ContainerSpec, ContainerStatus, Context, EmitOut, EmitSpec, EntryOf, EntryTypeSpec, IngressTypeSpec, MigrateFn, OperationSpec, Options, PushDelivery, RouteCall, RouteSpec, SampleCall, CredentialCheck, SecretDeleteRequest, SecretRequest, SecretSchemeSpec, SecretWrite, SiteOutcome, SiteRun, SourceSpec, TaskFn, VerifiedCredential, VerifierSpec, WaitOut, WaitSpec, WebhookContext, WebhookRequest, WebhookResponse, WorkKindSpec, } from "./extension.js";
|
|
3
|
+
export { LocalOperator, PanelLimits, RequestState, Tone, panelProblem, } from "./actions.js";
|
|
4
|
+
export type { ActionCall, ActionCaller, ActionPlan, ActionsSpec, AnnotateFn, PageSpec, Panel, PanelMessage, PanelSection, RequestInfo, } from "./actions.js";
|
|
5
|
+
export { ProbeFailure } from "./probe.js";
|
|
6
|
+
export type { ProbeArgSpec, ProbeConnection, ProbeContext, ProbeOutput, ProbeSpec, } from "./probe.js";
|
|
7
|
+
export { ResourceMode, ResourceSetupError } from "./resources.js";
|
|
8
|
+
export type { LeaseAttention, ReconcileReport, ResourceAcquisition, ResourceContext, ResourceModeName, ResourceOut, ResourceOwnerStatus, ResourceProviderSpec, ResourceStatusFn, Site, SiteCommandInput, SiteRunResult, } from "./resources.js";
|
|
9
|
+
export { SandboxSignals } from "./sandbox.js";
|
|
10
|
+
export type { SandboxAdoptRequest, SandboxContext, SandboxPlanOut, SandboxPlanRequest, SandboxProviderSpec, } from "./sandbox.js";
|
|
11
|
+
export { TunnelConfigError, checkPublicURL } from "./tunnel.js";
|
|
12
|
+
export { ChangeState, SetupNoInput, SetupUsageError } from "./setup.js";
|
|
13
|
+
export type { Candidate, CandidateChange, ConfigCandidateFn, SetupHost, SetupResult, SetupSpec, } from "./setup.js";
|
|
14
|
+
export type { DependencyFilterFn, GateCall, GateWait, OperationGateFn, RecurrenceCall, RecurrenceFn, RecurrenceNext, RenderFn, ResolvedTarget, SegmentEndFn, StartCall, StartGateFn, TargetFn, } from "./hooks.js";
|
|
15
|
+
export { MaxRunFileBytes, MaxRunFiles, appliedEnv, checkRunFiles, } from "./telemetry.js";
|
|
16
|
+
export type { ExporterSpec, MetricsFn, RunEnvironmentFn, RunEnvironmentRequest, RunLayer, SinkFn, } from "./telemetry.js";
|
|
17
|
+
export type { PublishFn, TunnelProviderSpec, TunnelRunRequest, } from "./tunnel.js";
|
|
18
|
+
export { BackupManifest, validBackupBundle, validBackupPath, } from "./backup.js";
|
|
19
|
+
export type { BackupChunk, BackupDestinationSpec, BackupFile, BackupTarget, } from "./backup.js";
|
|
20
|
+
export { ArtifactCode, ArtifactError, ArtifactStoreChunk, ArtifactStoreVersion, serveArtifactProvider, serveArtifactStore, } from "./artifactstore.js";
|
|
21
|
+
export type { ArtifactBackend, ArtifactProvider, StoredArtifactRef, ArtifactStore, ArtifactWriter, Ownership, StoredArtifact, } from "./artifactstore.js";
|
|
22
|
+
export { MaxKnownBatch, fromWireResult, invalidResult, wireResult, } from "./executor.js";
|
|
23
|
+
export type { AcquiredResource, AttemptRequest, ContainerAttachRequest, ContainerAttachSpec, ContainerBroker, ContainerExitStatus, ExecutorCapabilities, ExecutorContext, ExecutorResult, ExecutorSpec, InteractiveLaunchRequest, InteractiveLaunchSpec, KnownFn, LaunchPlan, LiveOut, OutcomeKind, ResourceBroker, ResourceRequest, RunHandle, SandboxBroker, SweepReport, ToolbeltTransport, UsageRecord, } from "./executor.js";
|
|
24
|
+
export { Toolbelt, ToolbeltError, TurnEnded, toolbelt } from "./toolbelt.js";
|
|
25
|
+
export type { CallOptions, ToolResult, ToolWait, ToolbeltOptions, TurnEnd, } from "./toolbelt.js";
|
|
26
|
+
export { Host, MaxWorksPage, text } from "./host.js";
|
|
27
|
+
export type { Accept, Batch, Caller, DeliveryInput, Entry, Put, Value, WorksQuery, } from "./host.js";
|
|
28
|
+
export { t, check, diagnose, matches, isRecord } from "./schema.js";
|
|
29
|
+
export type { Infer, Type } from "./schema.js";
|
|
30
|
+
export { Code, OperationError, ProtocolError, ConfigError, CredentialRefusal, SecretRefusal, SecretUnowned, validSecretCode, pointer, CancelledError, TransportError, isProtocolCode, } from "./errors.js";
|
|
31
|
+
export type { ConfigDiagnostic } from "./errors.js";
|
|
32
|
+
export { dialForward, forwardAddress, forwardClientOptions, ForwardPortFile, ForwardCAFile, ForwardCertFile, ForwardServerName, } from "./forward.js";
|
|
33
|
+
export { Conn, MaxMessageBytes, MaxChunkBytes, MaxInflight, MaxControlInflight, laneOf, } from "./jsonrpc.js";
|
|
34
|
+
export * from "./wire.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @open-conduit/sdk: build an Open Conduit extension in TypeScript.
|
|
2
|
+
//
|
|
3
|
+
// import { extension, t, OperationError } from "@open-conduit/sdk";
|
|
4
|
+
//
|
|
5
|
+
// const ext = extension("weather", { version: "0.1.0" })
|
|
6
|
+
// .operation("weather.forecast", {
|
|
7
|
+
// input: t.object({ city: t.string({ description: "The city, by name." }) }),
|
|
8
|
+
// guidance: "Call `weather.forecast` before planning anything outdoors.",
|
|
9
|
+
// handler: async ({ city }) => ({ city, summary: "sunny" }),
|
|
10
|
+
// });
|
|
11
|
+
// await ext.main();
|
|
12
|
+
//
|
|
13
|
+
// The guide is site/src/content/docs/architecture/extension-packaging.md.
|
|
14
|
+
export { extension, Extension, Server, ProtocolVersions, ContainerLabel, } from "./extension.js";
|
|
15
|
+
export { LocalOperator, PanelLimits, RequestState, Tone, panelProblem, } from "./actions.js";
|
|
16
|
+
export { ProbeFailure } from "./probe.js";
|
|
17
|
+
export { ResourceMode, ResourceSetupError } from "./resources.js";
|
|
18
|
+
export { SandboxSignals } from "./sandbox.js";
|
|
19
|
+
export { TunnelConfigError, checkPublicURL } from "./tunnel.js";
|
|
20
|
+
export { ChangeState, SetupNoInput, SetupUsageError } from "./setup.js";
|
|
21
|
+
export { MaxRunFileBytes, MaxRunFiles, appliedEnv, checkRunFiles, } from "./telemetry.js";
|
|
22
|
+
export { BackupManifest, validBackupBundle, validBackupPath, } from "./backup.js";
|
|
23
|
+
export { ArtifactCode, ArtifactError, ArtifactStoreChunk, ArtifactStoreVersion, serveArtifactProvider, serveArtifactStore, } from "./artifactstore.js";
|
|
24
|
+
export { MaxKnownBatch, fromWireResult, invalidResult, wireResult, } from "./executor.js";
|
|
25
|
+
export { Toolbelt, ToolbeltError, TurnEnded, toolbelt } from "./toolbelt.js";
|
|
26
|
+
export { Host, MaxWorksPage, text } from "./host.js";
|
|
27
|
+
export { t, check, diagnose, matches, isRecord } from "./schema.js";
|
|
28
|
+
export { Code, OperationError, ProtocolError, ConfigError, CredentialRefusal, SecretRefusal, SecretUnowned, validSecretCode, pointer, CancelledError, TransportError, isProtocolCode, } from "./errors.js";
|
|
29
|
+
export { dialForward, forwardAddress, forwardClientOptions, ForwardPortFile, ForwardCAFile, ForwardCertFile, ForwardServerName, } from "./forward.js";
|
|
30
|
+
export { Conn, MaxMessageBytes, MaxChunkBytes, MaxInflight, MaxControlInflight, laneOf, } from "./jsonrpc.js";
|
|
31
|
+
export * from "./wire.js";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Readable, Writable } from "node:stream";
|
|
2
|
+
/** Bounds of protocol version 1 (protocol/protocol.go). */
|
|
3
|
+
export declare const MaxMessageBytes: number;
|
|
4
|
+
export declare const MaxChunkBytes: number;
|
|
5
|
+
export declare const MaxInflight = 64;
|
|
6
|
+
/** Capacity reserved for control methods on top of MaxInflight. */
|
|
7
|
+
export declare const MaxControlInflight = 16;
|
|
8
|
+
/** Which capacity an extension serves a host request from. */
|
|
9
|
+
export type Lane = "bounded" | "held" | "control";
|
|
10
|
+
/** The lane of a host-to-extension method (protocol.LaneOf). */
|
|
11
|
+
export declare function laneOf(method: string): Lane;
|
|
12
|
+
export declare const CancelMethod = "$/cancel";
|
|
13
|
+
/** Serves one inbound request. Its signal aborts when the peer cancels. */
|
|
14
|
+
export type Handler = (method: string, params: unknown, signal: AbortSignal) => Promise<unknown>;
|
|
15
|
+
export interface ConnOptions {
|
|
16
|
+
maxMessage?: number;
|
|
17
|
+
maxInflight?: number;
|
|
18
|
+
/** Classifies inbound requests; an extension sets it, a host does not. */
|
|
19
|
+
lane?: (method: string) => Lane;
|
|
20
|
+
/** Receives why a malformed stream closed the connection. */
|
|
21
|
+
onProtocolError?: (reason: string) => void;
|
|
22
|
+
}
|
|
23
|
+
/** One JSON-RPC peer. */
|
|
24
|
+
export declare class Conn {
|
|
25
|
+
#private;
|
|
26
|
+
readonly done: Promise<void>;
|
|
27
|
+
constructor(input: Readable, output: Writable, handler: Handler, o?: ConnOptions);
|
|
28
|
+
/** Reports whether the connection has ended. */
|
|
29
|
+
get closed(): boolean;
|
|
30
|
+
/** Ends the connection; pending calls reject with TransportError. */
|
|
31
|
+
close(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Sends a request and resolves with its result, undecoded. Aborting
|
|
34
|
+
* signal sends $/cancel and rejects at once with CancelledError.
|
|
35
|
+
*/
|
|
36
|
+
call(method: string, params?: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
37
|
+
/** Sends a notification (no response). */
|
|
38
|
+
notify(method: string, params?: unknown): void;
|
|
39
|
+
}
|