@capybara-hq/plugin-sdk 0.1.0-rc.2 → 0.1.0-rc.20

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 (104) hide show
  1. package/README.md +1 -1
  2. package/agent-docs/agent-templates.md +59 -0
  3. package/agent-docs/concepts.md +63 -0
  4. package/agent-docs/connector-templates.md +48 -0
  5. package/agent-docs/extension-points/channel.md +15 -0
  6. package/agent-docs/extension-points/config-source.md +15 -0
  7. package/agent-docs/extension-points/connector.md +15 -0
  8. package/agent-docs/extension-points/context.md +15 -0
  9. package/agent-docs/extension-points/counter.md +15 -0
  10. package/agent-docs/extension-points/directory.md +15 -0
  11. package/agent-docs/extension-points/file-preview.md +15 -0
  12. package/agent-docs/extension-points/identity-source.md +15 -0
  13. package/agent-docs/extension-points/model-provider.md +15 -0
  14. package/agent-docs/extension-points/object-store.md +15 -0
  15. package/agent-docs/extension-points/sandbox.md +15 -0
  16. package/agent-docs/extension-points/secret-store.md +15 -0
  17. package/agent-docs/extension-points/web-fetch.md +15 -0
  18. package/agent-docs/extension-points/web-search.md +15 -0
  19. package/agent-docs/extensions.md +88 -0
  20. package/agent-docs/plugin-format.md +100 -0
  21. package/agent-docs/setup.md +46 -0
  22. package/agent-docs/skills.md +44 -0
  23. package/agent-docs/tool-naming.md +21 -0
  24. package/dist/agent-template.d.ts +96 -2
  25. package/dist/agent-template.js +381 -3
  26. package/dist/bootstrap.d.ts +15 -1
  27. package/dist/bootstrap.js +17 -1
  28. package/dist/cards.d.ts +39 -5
  29. package/dist/cards.js +70 -11
  30. package/dist/channel.d.ts +20 -1
  31. package/dist/client-css.d.ts +36 -0
  32. package/dist/client-css.js +326 -0
  33. package/dist/client-section.d.ts +35 -0
  34. package/dist/client-section.js +133 -0
  35. package/dist/config-ui.d.ts +24 -1
  36. package/dist/config-ui.js +89 -11
  37. package/dist/connector-auth.d.ts +2 -0
  38. package/dist/connector-auth.js +15 -0
  39. package/dist/context.d.ts +40 -0
  40. package/dist/context.js +2 -0
  41. package/dist/ctx.d.ts +86 -4
  42. package/dist/define-extension.d.ts +5 -1
  43. package/dist/define-extension.js +1 -0
  44. package/dist/dev-hosts.d.ts +6 -0
  45. package/dist/dev-hosts.js +48 -0
  46. package/dist/device-protocol.d.ts +260 -0
  47. package/dist/device-protocol.js +496 -0
  48. package/dist/directory.d.ts +11 -2
  49. package/dist/extension-point.d.ts +6 -0
  50. package/dist/extension-point.js +19 -14
  51. package/dist/file-preview.d.ts +9 -1
  52. package/dist/hooks.d.ts +111 -15
  53. package/dist/hooks.js +5 -0
  54. package/dist/index.d.ts +18 -1
  55. package/dist/index.js +18 -1
  56. package/dist/marketplace.d.ts +55 -2
  57. package/dist/marketplace.js +73 -3
  58. package/dist/model.d.ts +60 -2
  59. package/dist/model.js +22 -0
  60. package/dist/org-access.d.ts +27 -0
  61. package/dist/org-access.js +35 -0
  62. package/dist/permissions.d.ts +33 -8
  63. package/dist/permissions.js +89 -22
  64. package/dist/plugin-manifest.d.ts +60 -7
  65. package/dist/plugin-manifest.js +178 -7
  66. package/dist/sandbox.d.ts +239 -62
  67. package/dist/sandbox.js +99 -14
  68. package/dist/setup-check.d.ts +115 -0
  69. package/dist/setup-check.js +142 -0
  70. package/dist/setup-guide-parse.d.ts +121 -0
  71. package/dist/setup-guide-parse.js +350 -0
  72. package/dist/setup-guide-render.d.ts +45 -0
  73. package/dist/setup-guide-render.js +351 -0
  74. package/dist/setup-guide.d.ts +94 -0
  75. package/dist/setup-guide.js +336 -0
  76. package/dist/skill-invocation.d.ts +9 -5
  77. package/dist/skill-invocation.js +18 -8
  78. package/dist/skill.d.ts +23 -3
  79. package/dist/skill.js +31 -6
  80. package/dist/theme-assets.d.ts +39 -0
  81. package/dist/theme-assets.js +449 -0
  82. package/dist/theme-readability.d.ts +37 -0
  83. package/dist/theme-readability.js +145 -0
  84. package/dist/theme-tokens.generated.d.ts +275 -0
  85. package/dist/theme-tokens.generated.js +172 -0
  86. package/dist/theme.d.ts +152 -0
  87. package/dist/theme.js +392 -0
  88. package/dist/tool.d.ts +26 -3
  89. package/dist/tool.js +8 -0
  90. package/dist/ui-parts.d.ts +23 -0
  91. package/dist/ui-parts.js +337 -0
  92. package/dist/ui-resolve.d.ts +40 -0
  93. package/dist/ui-resolve.js +54 -0
  94. package/dist/ui-slots.d.ts +55 -0
  95. package/dist/ui-slots.js +247 -0
  96. package/dist/ui.d.ts +143 -37
  97. package/dist/ui.js +65 -5
  98. package/dist/web.d.ts +30 -5
  99. package/package.json +10 -2
  100. package/schemas/bootstrap.v1.schema.json +6 -0
  101. package/schemas/connector-template.v1.schema.json +3 -0
  102. package/schemas/marketplace.v1.schema.json +50 -0
  103. package/schemas/plugin.v1.schema.json +144 -7
  104. package/schemas/theme.v1.schema.json +225 -0
@@ -0,0 +1,496 @@
1
+ /**
2
+ * Device protocol v1: the WebSocket frames between the kernel and a `capybara-device` program
3
+ * (a connected machine that serves as a device). Pure types and hand-written guards.
4
+ */
5
+ import { isSandboxTier, validateAllowHost, validateSandboxPathShape, } from "./sandbox.js";
6
+ /** The protocol version carried in `X-Capybara-Device-Protocol` and the hello frame. */
7
+ export const DEVICE_PROTOCOL_VERSION = 1;
8
+ const DEVICE_OPS = [
9
+ "create",
10
+ "exec",
11
+ "readFile",
12
+ "writeFile",
13
+ "stat",
14
+ "killTagged",
15
+ "killAll",
16
+ "stop",
17
+ "policy",
18
+ "policyStatus",
19
+ ];
20
+ const DEVICE_FEATURES = [
21
+ "networkReport",
22
+ "policyOp",
23
+ "policyOpId",
24
+ "tiers",
25
+ ];
26
+ /**
27
+ * The first line of the kernel's background task launch command (`Bash` `run_in_background`), a
28
+ * shell comment. A device kills what a foreground exec leaves running once the exec ends; an exec
29
+ * whose command starts with this line detaches a task on purpose, and its processes are left alone.
30
+ */
31
+ export const BACKGROUND_LAUNCH_LINE = "# capybara: background task launch";
32
+ /** Whether an exec's command is a background task launch ({@link BACKGROUND_LAUNCH_LINE}). */
33
+ export function isBackgroundLaunch(command) {
34
+ return command === BACKGROUND_LAUNCH_LINE || command.startsWith(`${BACKGROUND_LAUNCH_LINE}\n`);
35
+ }
36
+ /** The most blocked hosts an exec result reports; the parser cuts longer lists. */
37
+ export const MAX_NETWORK_BLOCKED_HOSTS = 20;
38
+ /** The most hosts a `policy` op's `add` / `remove` or an exec's `grants` may carry. */
39
+ const MAX_POLICY_HOSTS = 100;
40
+ /** The longest `opId` a `policy` / `policyStatus` op may carry. */
41
+ export const MAX_POLICY_OP_ID_LENGTH = 128;
42
+ /** The most entries a hello's `recentOps` carries; the parser keeps the newest. */
43
+ export const MAX_RECENT_POLICY_OPS = 100;
44
+ /** A frame that is not valid protocol v1 (or came from the wrong side). */
45
+ export class DeviceProtocolError extends Error {
46
+ constructor(message) {
47
+ super(message);
48
+ this.name = "DeviceProtocolError";
49
+ }
50
+ }
51
+ function isRecord(v) {
52
+ return typeof v === "object" && v !== null && !Array.isArray(v);
53
+ }
54
+ function str(o, k) {
55
+ const v = o[k];
56
+ if (typeof v !== "string")
57
+ throw new DeviceProtocolError(`field "${k}" must be a string`);
58
+ return v;
59
+ }
60
+ function nonEmptyStr(o, k) {
61
+ const v = str(o, k);
62
+ if (v === "")
63
+ throw new DeviceProtocolError(`field "${k}" must not be empty`);
64
+ return v;
65
+ }
66
+ function posInt(o, k) {
67
+ const v = o[k];
68
+ if (typeof v !== "number" || !Number.isInteger(v) || v <= 0) {
69
+ throw new DeviceProtocolError(`field "${k}" must be a positive integer`);
70
+ }
71
+ return v;
72
+ }
73
+ function obj(v, what) {
74
+ if (!isRecord(v))
75
+ throw new DeviceProtocolError(`${what} must be an object`);
76
+ return v;
77
+ }
78
+ function bool(o, k) {
79
+ const v = o[k];
80
+ if (typeof v !== "boolean")
81
+ throw new DeviceProtocolError(`field "${k}" must be a boolean`);
82
+ return v;
83
+ }
84
+ function strArray(o, k) {
85
+ const v = o[k];
86
+ if (!Array.isArray(v) || v.some((x) => typeof x !== "string")) {
87
+ throw new DeviceProtocolError(`field "${k}" must be an array of strings`);
88
+ }
89
+ return v;
90
+ }
91
+ function parseLimits(v) {
92
+ const o = obj(v, 'field "limits"');
93
+ const egress = str(o, "egress");
94
+ if (egress !== "none" && egress !== "allowlist" && egress !== "open") {
95
+ throw new DeviceProtocolError(`unknown egress "${egress}"`);
96
+ }
97
+ const devHosts = strArray(o, "devHosts");
98
+ for (const h of devHosts) {
99
+ const problems = validateAllowHost(h);
100
+ if (problems.length > 0) {
101
+ throw new DeviceProtocolError(`invalid dev host "${h}": ${problems.join("; ")}`);
102
+ }
103
+ }
104
+ const out = {
105
+ cpu: num(o, "cpu"),
106
+ memoryMb: num(o, "memoryMb"),
107
+ diskMb: num(o, "diskMb"),
108
+ egress,
109
+ allowHosts: strArray(o, "allowHosts"),
110
+ tier: parseTier(o, "tier"),
111
+ devHosts,
112
+ };
113
+ if (o.defaultTier !== undefined)
114
+ out.defaultTier = parseTier(o, "defaultTier");
115
+ if (o.allowUnsandboxed !== undefined)
116
+ out.allowUnsandboxed = bool(o, "allowUnsandboxed");
117
+ return out;
118
+ }
119
+ function parseTier(o, k) {
120
+ const v = str(o, k);
121
+ if (!isSandboxTier(v))
122
+ throw new DeviceProtocolError(`unknown tier "${v}"`);
123
+ return v;
124
+ }
125
+ function oneOf(o, k, values) {
126
+ const v = str(o, k);
127
+ if (!values.includes(v)) {
128
+ throw new DeviceProtocolError(`unknown ${k} "${v}"`);
129
+ }
130
+ return v;
131
+ }
132
+ function num(o, k) {
133
+ const v = o[k];
134
+ if (typeof v !== "number" || !Number.isFinite(v)) {
135
+ throw new DeviceProtocolError(`field "${k}" must be a number`);
136
+ }
137
+ return v;
138
+ }
139
+ function parseRoots(v) {
140
+ if (!isRecord(v))
141
+ throw new DeviceProtocolError('field "roots" must be an object');
142
+ const roots = {};
143
+ for (const k of ["workspace", "skills", "tmp"]) {
144
+ const p = str(v, k);
145
+ if (!p.startsWith("/")) {
146
+ throw new DeviceProtocolError(`root "${k}" must be an absolute path`);
147
+ }
148
+ // the kernel builds paths as `${root}/…` and checks membership by prefix: a root must be a
149
+ // clean absolute directory path
150
+ const shape = validateSandboxPathShape(p);
151
+ if (shape.length > 0)
152
+ throw new DeviceProtocolError(`root "${k}": ${shape.join("; ")}`);
153
+ if (p.endsWith("/")) {
154
+ throw new DeviceProtocolError(`root "${k}" must not end with a slash`);
155
+ }
156
+ roots[k] = p;
157
+ }
158
+ return roots;
159
+ }
160
+ function hostArray(o, k) {
161
+ const v = strArray(o, k);
162
+ if (v.length > MAX_POLICY_HOSTS) {
163
+ throw new DeviceProtocolError(`field "${k}" must have at most ${MAX_POLICY_HOSTS} entries`);
164
+ }
165
+ return v;
166
+ }
167
+ function parsePolicySummary(v) {
168
+ const o = obj(v, 'field "policy"');
169
+ const remoteGrants = str(o, "remoteGrants");
170
+ if (remoteGrants !== "owner" && remoteGrants !== "off") {
171
+ throw new DeviceProtocolError(`unknown remoteGrants "${remoteGrants}"`);
172
+ }
173
+ const out = {
174
+ effectiveTier: parseTier(o, "effectiveTier"),
175
+ isolation: oneOf(o, "isolation", ["sandbox", "none"]),
176
+ localhost: oneOf(o, "localhost", ["on", "off-proxy-detected", "off"]),
177
+ unixSockets: oneOf(o, "unixSockets", ["roots", "all-masked", "off"]),
178
+ allowedDomains: strArray(o, "allowedDomains"),
179
+ remoteGrants,
180
+ };
181
+ if (o.tier !== undefined)
182
+ out.tier = parseTier(o, "tier");
183
+ return out;
184
+ }
185
+ /**
186
+ * Whether `v` is a valid policy op id: non-empty, no `:`, at most
187
+ * {@link MAX_POLICY_OP_ID_LENGTH} characters.
188
+ */
189
+ export function isPolicyOpId(v) {
190
+ return (typeof v === "string" && v !== "" && v.length <= MAX_POLICY_OP_ID_LENGTH && !v.includes(":"));
191
+ }
192
+ function opId(o) {
193
+ const v = o.opId;
194
+ if (!isPolicyOpId(v)) {
195
+ throw new DeviceProtocolError(`field "opId" must be a non-empty string without ":" of at most ${MAX_POLICY_OP_ID_LENGTH} characters`);
196
+ }
197
+ return v;
198
+ }
199
+ const OP_OUTCOMES = ["applied", "refused", "started"];
200
+ /**
201
+ * The valid entries of a hello's `recentOps`, one per op id (the last listed), the newest
202
+ * {@link MAX_RECENT_POLICY_OPS}.
203
+ */
204
+ function parseRecentOps(v) {
205
+ // one entry per op id: the last one listed (the newest outcome), where it is listed
206
+ const byId = new Map();
207
+ for (const e of v) {
208
+ if (!isRecord(e) || !isPolicyOpId(e.opId))
209
+ continue;
210
+ if (!OP_OUTCOMES.includes(e.outcome))
211
+ continue;
212
+ byId.delete(e.opId);
213
+ byId.set(e.opId, { opId: e.opId, outcome: e.outcome });
214
+ }
215
+ return [...byId.values()].slice(-MAX_RECENT_POLICY_OPS);
216
+ }
217
+ /** Optional hello fields: malformed values are ignored so old and new peers interoperate. */
218
+ function optionalHelloFields(o) {
219
+ const out = {};
220
+ if (Array.isArray(o.features)) {
221
+ out.features = DEVICE_FEATURES.filter((f) => o.features.includes(f));
222
+ }
223
+ if (Array.isArray(o.recentOps))
224
+ out.recentOps = parseRecentOps(o.recentOps);
225
+ return { ...out, ...optionalPolicy(o.policy) };
226
+ }
227
+ /** A summary field that is dropped when absent or unreadable. */
228
+ function optionalPolicy(v) {
229
+ if (v === undefined)
230
+ return {};
231
+ try {
232
+ return { policy: parsePolicySummary(v) };
233
+ }
234
+ catch {
235
+ // an unreadable summary is the same as none: the kernel learns the policy later
236
+ return {};
237
+ }
238
+ }
239
+ const BLOCK_LAYERS = ["device", "org", "address", "unknown"];
240
+ /**
241
+ * The valid entries of an exec result's `network.blocked`: a host that fails
242
+ * {@link validateAllowHost} is kept only with layer `address`; anything malformed is dropped;
243
+ * at most {@link MAX_NETWORK_BLOCKED_HOSTS}. Undefined when the field is not a report at all.
244
+ */
245
+ function parseNetworkReport(v) {
246
+ if (!isRecord(v) || !Array.isArray(v.blocked))
247
+ return undefined;
248
+ const blocked = [];
249
+ for (const e of v.blocked) {
250
+ if (blocked.length >= MAX_NETWORK_BLOCKED_HOSTS)
251
+ break;
252
+ if (!isRecord(e))
253
+ continue;
254
+ const { host, port, layer } = e;
255
+ if (typeof host !== "string" || host === "" || host.length > 255)
256
+ continue;
257
+ if (typeof port !== "number" || !Number.isInteger(port) || port < 1 || port > 65535)
258
+ continue;
259
+ if (!BLOCK_LAYERS.includes(layer))
260
+ continue;
261
+ if (layer !== "address" && validateAllowHost(host).length > 0)
262
+ continue;
263
+ blocked.push({ host, port, layer: layer });
264
+ }
265
+ return { blocked };
266
+ }
267
+ function parseHello(o) {
268
+ const os = str(o, "os");
269
+ if (os !== "darwin" && os !== "linux")
270
+ throw new DeviceProtocolError(`unsupported os "${os}"`);
271
+ const mode = str(o, "mode");
272
+ if (mode !== "os" && mode !== "docker") {
273
+ throw new DeviceProtocolError(`unsupported mode "${mode}"`);
274
+ }
275
+ if (typeof o.sessionIsolation !== "boolean") {
276
+ throw new DeviceProtocolError('field "sessionIsolation" must be a boolean');
277
+ }
278
+ return {
279
+ type: "hello",
280
+ protocol: posInt(o, "protocol"),
281
+ programVersion: str(o, "programVersion"),
282
+ os,
283
+ arch: str(o, "arch"),
284
+ mode,
285
+ roots: parseRoots(o.roots),
286
+ sessionIsolation: o.sessionIsolation,
287
+ ...optionalHelloFields(o),
288
+ };
289
+ }
290
+ function parseRes(o) {
291
+ const id = nonEmptyStr(o, "id");
292
+ if (o.ok === true)
293
+ return { type: "res", id, ok: true, result: o.result };
294
+ if (o.ok !== false)
295
+ throw new DeviceProtocolError('field "ok" must be a boolean');
296
+ const e = o.error;
297
+ if (!isRecord(e))
298
+ throw new DeviceProtocolError('field "error" must be an object');
299
+ const kind = str(e, "kind");
300
+ if (kind !== "gone" && kind !== "fs_gone" && kind !== "policy" && kind !== "error") {
301
+ throw new DeviceProtocolError(`unknown error kind "${kind}"`);
302
+ }
303
+ return { type: "res", id, ok: false, error: { kind, message: str(e, "message") } };
304
+ }
305
+ function parseReq(o) {
306
+ const op = str(o, "op");
307
+ if (!DEVICE_OPS.includes(op))
308
+ throw new DeviceProtocolError(`unknown op "${op}"`);
309
+ const args = obj(o.args, 'field "args"');
310
+ validateArgs(op, args);
311
+ return {
312
+ type: "req",
313
+ id: nonEmptyStr(o, "id"),
314
+ op: op,
315
+ args,
316
+ deadlineMs: posInt(o, "deadlineMs"),
317
+ };
318
+ }
319
+ function validateArgs(op, a) {
320
+ switch (op) {
321
+ case "exec": {
322
+ nonEmptyStr(a, "command");
323
+ posInt(a, "timeoutMs");
324
+ posInt(a, "maxOutputBytes");
325
+ str(a, "tag");
326
+ const actor = obj(a.actor, 'field "actor"');
327
+ str(actor, "accountId");
328
+ str(actor, "conversationId");
329
+ if (actor.runId !== undefined)
330
+ str(actor, "runId");
331
+ parseLimits(a.limits);
332
+ if (a.grants !== undefined) {
333
+ const g = obj(a.grants, 'field "grants"');
334
+ hostArray(g, "hosts");
335
+ const src = obj(g.source, 'field "grants.source"');
336
+ const kind = str(src, "kind");
337
+ if (kind !== "run" && kind !== "task") {
338
+ throw new DeviceProtocolError(`unknown grant source kind "${kind}"`);
339
+ }
340
+ nonEmptyStr(src, "id");
341
+ nonEmptyStr(src, "accountId");
342
+ }
343
+ if (a.cwd !== undefined)
344
+ str(a, "cwd");
345
+ if (a.env !== undefined) {
346
+ const env = obj(a.env, 'field "env"');
347
+ for (const k of Object.keys(env))
348
+ str(env, k);
349
+ }
350
+ return;
351
+ }
352
+ case "readFile": {
353
+ str(a, "path");
354
+ const m = a.maxBytes;
355
+ if (typeof m !== "number" || !Number.isInteger(m) || m < 0) {
356
+ throw new DeviceProtocolError('field "maxBytes" must be a non-negative integer');
357
+ }
358
+ return;
359
+ }
360
+ case "writeFile":
361
+ str(a, "path");
362
+ str(a, "dataB64");
363
+ return;
364
+ case "stat":
365
+ str(a, "path");
366
+ return;
367
+ case "killTagged":
368
+ strArray(a, "tags");
369
+ return;
370
+ case "killAll":
371
+ return;
372
+ case "create":
373
+ parseLimits(a.limits);
374
+ return;
375
+ case "stop": {
376
+ const r = str(a, "reason");
377
+ if (r !== "revoked" && r !== "deleted") {
378
+ throw new DeviceProtocolError(`unknown stop reason "${r}"`);
379
+ }
380
+ return;
381
+ }
382
+ case "policy": {
383
+ opId(a);
384
+ if (a.add !== undefined)
385
+ hostArray(a, "add");
386
+ if (a.remove !== undefined)
387
+ hostArray(a, "remove");
388
+ if (a.tier !== undefined && a.tier !== null)
389
+ parseTier(a, "tier");
390
+ if (a.isolation !== undefined && a.isolation !== "sandbox") {
391
+ throw new DeviceProtocolError('field "isolation" may only be "sandbox"');
392
+ }
393
+ const src = obj(a.source, 'field "source"');
394
+ nonEmptyStr(src, "accountId");
395
+ str(src, "accountName");
396
+ const via = str(src, "via");
397
+ if (via !== "web" && via !== "im")
398
+ throw new DeviceProtocolError(`unknown via "${via}"`);
399
+ if (src.approvalId !== undefined)
400
+ str(src, "approvalId");
401
+ return;
402
+ }
403
+ case "policyStatus":
404
+ opId(a);
405
+ return;
406
+ }
407
+ }
408
+ export function parseOpResult(op, result) {
409
+ switch (op) {
410
+ case "exec": {
411
+ const r = obj(result, "exec result");
412
+ const exitCode = r.exitCode;
413
+ if (exitCode !== null && (typeof exitCode !== "number" || !Number.isFinite(exitCode))) {
414
+ throw new DeviceProtocolError('field "exitCode" must be a number or null');
415
+ }
416
+ const out = {
417
+ exitCode: exitCode,
418
+ stdout: str(r, "stdout"),
419
+ stderr: str(r, "stderr"),
420
+ truncated: bool(r, "truncated"),
421
+ timedOut: bool(r, "timedOut"),
422
+ };
423
+ // an optional report: a malformed one is dropped, never failing the command's result
424
+ const network = parseNetworkReport(r.network);
425
+ if (network)
426
+ out.network = network;
427
+ return out;
428
+ }
429
+ case "policy":
430
+ return { policy: parsePolicySummary(obj(result, "policy result").policy) };
431
+ case "policyStatus": {
432
+ const r = obj(result, "policyStatus result");
433
+ const out = {
434
+ outcome: oneOf(r, "outcome", [...OP_OUTCOMES, "unknown"]),
435
+ };
436
+ if (r.policy !== undefined)
437
+ out.policy = parsePolicySummary(r.policy);
438
+ if (r.message !== undefined)
439
+ out.message = str(r, "message");
440
+ return out;
441
+ }
442
+ case "readFile": {
443
+ if (result === null)
444
+ return null;
445
+ const r = obj(result, "readFile result");
446
+ return { dataB64: str(r, "dataB64"), truncated: bool(r, "truncated") };
447
+ }
448
+ case "stat": {
449
+ if (result === null)
450
+ return null;
451
+ const r = obj(result, "stat result");
452
+ return { size: num(r, "size"), isDir: bool(r, "isDir") };
453
+ }
454
+ case "create":
455
+ return { roots: parseRoots(obj(result, "create result").roots) };
456
+ default:
457
+ if (result !== null)
458
+ throw new DeviceProtocolError(`${op} result must be null`);
459
+ return null;
460
+ }
461
+ }
462
+ /**
463
+ * Parses one WebSocket text frame. `from` is the sender: a device may send `hello`, `res` and
464
+ * `policy`, the
465
+ * kernel `req` and `cancel`. Throws {@link DeviceProtocolError} on bad JSON, an unknown `type`,
466
+ * missing fields or a frame of the wrong direction.
467
+ */
468
+ export function parseDeviceFrame(raw, from) {
469
+ let o;
470
+ try {
471
+ o = JSON.parse(raw);
472
+ }
473
+ catch {
474
+ throw new DeviceProtocolError("frame is not valid JSON");
475
+ }
476
+ if (!isRecord(o))
477
+ throw new DeviceProtocolError("frame must be a JSON object");
478
+ const type = o.type;
479
+ switch (type) {
480
+ case "hello":
481
+ case "res":
482
+ case "policy":
483
+ if (from !== "device")
484
+ throw new DeviceProtocolError(`"${type}" must come from the device`);
485
+ if (type === "policy")
486
+ return { type, ...optionalPolicy(o.policy) };
487
+ return type === "hello" ? parseHello(o) : parseRes(o);
488
+ case "req":
489
+ case "cancel":
490
+ if (from !== "kernel")
491
+ throw new DeviceProtocolError(`"${type}" must come from the kernel`);
492
+ return type === "req" ? parseReq(o) : { type: "cancel", id: nonEmptyStr(o, "id") };
493
+ default:
494
+ throw new DeviceProtocolError(`unknown frame type "${String(type)}"`);
495
+ }
496
+ }
@@ -15,11 +15,20 @@ export interface Directory {
15
15
  * treats the directory as "not configured": the hourly scan, `directory_changed` and the
16
16
  * pre-removal recheck are skipped silently (no job, no audit, no warning), and a manual sync by an
17
17
  * admin returns 409 `directory.not_configured`. When not implemented, any config that satisfies
18
- * the schema counts as configured. Must be a pure function (no requests, never throws).
18
+ * the schema counts as configured. Must be a pure function (no requests, never throws). `config`
19
+ * is the effective deployment config for the org (see `listMembers`' `config`).
19
20
  */
20
- configured?(orgConfig: unknown): boolean;
21
+ configured?(orgConfig: unknown, config?: unknown): boolean;
21
22
  listMembers(args: {
22
23
  orgConfig: unknown;
24
+ /**
25
+ * The extension's effective deployment config for this org: the platform's deployment config
26
+ * with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
27
+ * platform's config (equal to `ctx.config`) while the org follows it. Use it, not `ctx.config`,
28
+ * for work done for this org. Optional in the type so older extensions compile; the kernel
29
+ * always passes it.
30
+ */
31
+ config?: unknown;
23
32
  cursor?: string;
24
33
  signal: AbortSignal;
25
34
  }): Promise<{
@@ -4,11 +4,15 @@ export type ExtensionPointRef = `${string}@${number}`;
4
4
  export type Cardinality = "single" | "multi";
5
5
  /** Registry entry of an extension point. */
6
6
  export interface ExtensionPointInfo {
7
+ /** What the extension point is for, in one sentence (served to agents by the Platform tool). */
8
+ description: string;
7
9
  cardinality: Cardinality;
8
10
  /** Brokered by the platform API (extensions may not `requires` it; they use it only through `ctx`). */
9
11
  brokered: boolean;
10
12
  /** Enabled per org (consumers may pass `orgId` to check that the org enabled the provider). */
11
13
  orgScoped: boolean;
14
+ /** The majors of this point the kernel accepts; a plugin providing any other major is refused. */
15
+ majors: readonly number[];
12
16
  /**
13
17
  * How the kernel picks one provider among several: `org-default` means each org chooses its
14
18
  * default provider (absent: no selection, every enabled provider is used).
@@ -27,6 +31,8 @@ export declare const CHANNEL_EXTENSION_POINT = "channel@1";
27
31
  export declare const IDENTITY_SOURCE_EXTENSION_POINT = "identity-source@1";
28
32
  /** Directory sync extension point ref (see `directory.ts`). */
29
33
  export declare const DIRECTORY_EXTENSION_POINT = "directory@1";
34
+ /** Context provider extension point ref (see `context.ts`). */
35
+ export declare const CONTEXT_EXTENSION_POINT = "context@1";
30
36
  /** Parses an extension point ref; throws when the format is invalid. */
31
37
  export declare function parseExtensionPoint(ref: string): {
32
38
  name: string;
@@ -1,4 +1,6 @@
1
- const info = (cardinality, brokered = false, orgScoped = false, selection) => ({
1
+ const info = (majors, description, cardinality, brokered = false, orgScoped = false, selection) => ({
2
+ majors,
3
+ description,
2
4
  cardinality,
3
5
  brokered,
4
6
  orgScoped,
@@ -6,19 +8,20 @@ const info = (cardinality, brokered = false, orgScoped = false, selection) => ({
6
8
  });
7
9
  /** The registered extension points. */
8
10
  export const EXTENSION_POINTS = {
9
- sandbox: info("single", true),
10
- "config-source": info("single"),
11
- "secret-store": info("single", true),
12
- "object-store": info("single", true),
13
- channel: info("multi", false, true),
14
- "model-provider": info("multi", true),
15
- "identity-source": info("multi"),
16
- directory: info("multi", false, true),
17
- counter: info("multi"),
18
- connector: info("multi", true),
19
- "file-preview": info("multi", false, true),
20
- "web-search": info("multi", true, true, "org-default"),
21
- "web-fetch": info("multi", true, true, "org-default"),
11
+ sandbox: info([2], "Runs a device's instance and keeps its files for agents' commands (Docker, E2B).", "single", true),
12
+ "config-source": info([1], "Supplies deployment configuration from an external store such as Nacos.", "single"),
13
+ "secret-store": info([1], "Stores and resolves secrets (connector credentials, secret config) outside the database.", "single", true),
14
+ "object-store": info([1], "Stores files and artifacts in S3-compatible object storage, with presigned uploads.", "single", true),
15
+ channel: info([1], "Connects an instant-messaging platform (Slack, Lark): inbound events, replies and cards.", "multi", false, true),
16
+ "model-provider": info([1, 2], "Calls a model vendor's API and streams the result back to the runtime.", "multi", true),
17
+ "identity-source": info([1], "Signs people in through an external identity provider (SSO).", "multi"),
18
+ directory: info([1], "Syncs members and departments from an external company directory.", "multi", false, true),
19
+ counter: info([1], "Counts usage so quotas and reports can be built on it.", "multi"),
20
+ connector: info([1], "Speaks one protocol (MCP, OpenAPI) to external systems and exposes their tools to agents.", "multi", true),
21
+ "file-preview": info([1], "Renders previews of files of given types in the conversation UI.", "multi", false, true),
22
+ "web-search": info([1], "Searches the web for the WebSearch tool; each org picks a default provider.", "multi", true, true, "org-default"),
23
+ context: info([1], "Adds text to the model's context at run start in conversations of orgs that enable it.", "multi", true, true),
24
+ "web-fetch": info([1], "Fetches and extracts web pages for the WebFetch tool; each org picks a default provider.", "multi", true, true, "org-default"),
22
25
  };
23
26
  /** Cardinality of the registered extension points (derived from EXTENSION_POINTS). */
24
27
  export const EXTENSION_POINT_CARDINALITY = Object.fromEntries(Object.entries(EXTENSION_POINTS).map(([k, v]) => [k, v.cardinality]));
@@ -30,6 +33,8 @@ export const CHANNEL_EXTENSION_POINT = "channel@1";
30
33
  export const IDENTITY_SOURCE_EXTENSION_POINT = "identity-source@1";
31
34
  /** Directory sync extension point ref (see `directory.ts`). */
32
35
  export const DIRECTORY_EXTENSION_POINT = "directory@1";
36
+ /** Context provider extension point ref (see `context.ts`). */
37
+ export const CONTEXT_EXTENSION_POINT = "context@1";
33
38
  /** Parses an extension point ref; throws when the format is invalid. */
34
39
  export function parseExtensionPoint(ref) {
35
40
  const m = /^([a-z][a-z0-9-]*)@(\d+)$/.exec(ref);
@@ -7,7 +7,7 @@ export declare const FILE_PREVIEW_MAX_BYTES: number;
7
7
  /**
8
8
  * One previewer of a `file-preview@1` provider: which files it previews and how. It renders either a
9
9
  * view (`render`, drawn by the web app like any `UiView`) or an embed page (`embed`, the id of a ui
10
- * contribution `{ kind: "embed", place: "file-preview" }` of the same extension, which receives the
10
+ * contribution `{ kind: "embed", slot: "file.preview" }` of the same extension, which receives the
11
11
  * file over the message bridge). Exactly one of the two.
12
12
  */
13
13
  export interface FilePreviewer {
@@ -53,6 +53,14 @@ export interface FilePreviewArgs {
53
53
  * rejects a file over the previewer's `maxBytes`. The extension never gets a storage key or URL.
54
54
  */
55
55
  read(): Promise<Uint8Array>;
56
+ /**
57
+ * The extension's effective deployment config for this org: the platform's deployment config
58
+ * with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
59
+ * platform's config (equal to `ctx.config`) while the org follows it. Use it, not `ctx.config`,
60
+ * for work done for this org. Optional in the type so older extensions compile; the kernel
61
+ * always passes it.
62
+ */
63
+ config?: unknown;
56
64
  }
57
65
  /** Checks a `file-preview@1` provider; returns the problems (empty = valid). */
58
66
  export declare function validateFilePreviewProvider(p: unknown): string[];