@capybara-hq/plugin-sdk 0.1.0-rc.1 → 0.1.0-rc.10

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 (91) hide show
  1. package/README.md +1 -1
  2. package/agent-docs/agent-templates.md +47 -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/counter.md +15 -0
  9. package/agent-docs/extension-points/directory.md +15 -0
  10. package/agent-docs/extension-points/file-preview.md +15 -0
  11. package/agent-docs/extension-points/identity-source.md +15 -0
  12. package/agent-docs/extension-points/model-provider.md +15 -0
  13. package/agent-docs/extension-points/object-store.md +15 -0
  14. package/agent-docs/extension-points/sandbox.md +15 -0
  15. package/agent-docs/extension-points/secret-store.md +15 -0
  16. package/agent-docs/extension-points/web-fetch.md +15 -0
  17. package/agent-docs/extension-points/web-search.md +15 -0
  18. package/agent-docs/extensions.md +87 -0
  19. package/agent-docs/plugin-format.md +99 -0
  20. package/agent-docs/setup.md +46 -0
  21. package/agent-docs/skills.md +44 -0
  22. package/agent-docs/tool-naming.md +21 -0
  23. package/dist/agent-template.d.ts +85 -0
  24. package/dist/agent-template.js +361 -2
  25. package/dist/cards.d.ts +7 -0
  26. package/dist/cards.js +4 -4
  27. package/dist/channel.d.ts +20 -1
  28. package/dist/config-ui.d.ts +131 -0
  29. package/dist/config-ui.js +602 -0
  30. package/dist/connector-auth.d.ts +2 -0
  31. package/dist/connector-auth.js +15 -0
  32. package/dist/ctx.d.ts +86 -4
  33. package/dist/define-extension.d.ts +5 -1
  34. package/dist/define-extension.js +1 -0
  35. package/dist/device-protocol.d.ts +118 -0
  36. package/dist/device-protocol.js +276 -0
  37. package/dist/directory.d.ts +11 -2
  38. package/dist/extension-point.d.ts +9 -0
  39. package/dist/extension-point.js +17 -12
  40. package/dist/file-preview.d.ts +9 -1
  41. package/dist/hooks.d.ts +76 -16
  42. package/dist/index.d.ts +15 -1
  43. package/dist/index.js +15 -1
  44. package/dist/marketplace.d.ts +55 -2
  45. package/dist/marketplace.js +73 -3
  46. package/dist/model.d.ts +60 -2
  47. package/dist/model.js +22 -0
  48. package/dist/org-access.d.ts +27 -0
  49. package/dist/org-access.js +35 -0
  50. package/dist/permissions.d.ts +20 -5
  51. package/dist/permissions.js +51 -15
  52. package/dist/plugin-manifest.d.ts +48 -5
  53. package/dist/plugin-manifest.js +93 -6
  54. package/dist/sandbox.d.ts +164 -62
  55. package/dist/sandbox.js +71 -14
  56. package/dist/secret.d.ts +4 -1
  57. package/dist/secret.js +5 -2
  58. package/dist/setup-check.d.ts +115 -0
  59. package/dist/setup-check.js +142 -0
  60. package/dist/setup-guide-parse.d.ts +121 -0
  61. package/dist/setup-guide-parse.js +350 -0
  62. package/dist/setup-guide-render.d.ts +45 -0
  63. package/dist/setup-guide-render.js +351 -0
  64. package/dist/setup-guide.d.ts +94 -0
  65. package/dist/setup-guide.js +336 -0
  66. package/dist/skill-invocation.d.ts +9 -5
  67. package/dist/skill-invocation.js +18 -8
  68. package/dist/skill.d.ts +23 -3
  69. package/dist/skill.js +31 -6
  70. package/dist/theme-assets.d.ts +39 -0
  71. package/dist/theme-assets.js +449 -0
  72. package/dist/theme-readability.d.ts +37 -0
  73. package/dist/theme-readability.js +145 -0
  74. package/dist/theme-tokens.generated.d.ts +275 -0
  75. package/dist/theme-tokens.generated.js +167 -0
  76. package/dist/theme.d.ts +152 -0
  77. package/dist/theme.js +392 -0
  78. package/dist/tool.d.ts +11 -3
  79. package/dist/ui-resolve.d.ts +40 -0
  80. package/dist/ui-resolve.js +54 -0
  81. package/dist/ui-slots.d.ts +43 -0
  82. package/dist/ui-slots.js +168 -0
  83. package/dist/ui.d.ts +114 -31
  84. package/dist/ui.js +0 -4
  85. package/dist/web.d.ts +105 -0
  86. package/dist/web.js +135 -0
  87. package/package.json +10 -2
  88. package/schemas/connector-template.v1.schema.json +3 -0
  89. package/schemas/marketplace.v1.schema.json +50 -0
  90. package/schemas/plugin.v1.schema.json +97 -4
  91. package/schemas/theme.v1.schema.json +225 -0
package/dist/ctx.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { Kysely } from "kysely";
2
2
  import type { ExtensionPointRef } from "./extension-point.js";
3
3
  import type { AvailableHook, HookHandler, HookOptions } from "./hooks.js";
4
+ import type { ModelEmbeddingInfo, ModelKind } from "./model.js";
5
+ import type { SetupCheckDefinition } from "./setup-check.js";
4
6
  import type { ObjectHead, PresignedUpload, PresignGetOptions } from "./storage.js";
5
7
  import type { ToolHandler, ToolSpec } from "./tool.js";
6
8
  import type { EmbedClaims, UiActionArgs, UiActionResult, UiRenderArgs, UiView } from "./ui.js";
@@ -58,6 +60,65 @@ export interface ExtensionStorage {
58
60
  ttlSeconds: number;
59
61
  }): Promise<PresignedUpload>;
60
62
  }
63
+ /** A `ctx.models.embed` request: texts embedded for one org with the model mapped to a purpose. */
64
+ export interface ExtensionEmbedRequest {
65
+ orgId: string;
66
+ /** A purpose this extension declared in `permissions.models` with `kind: "embedding"`. */
67
+ purpose: string;
68
+ /** The texts, one vector each; split into batches by the model's `maxBatch` by the kernel. */
69
+ input: string[];
70
+ /** One of the model's `embedding.dimensions`; the model's default when absent. */
71
+ dimensions?: number;
72
+ inputType?: "query" | "document";
73
+ /**
74
+ * Aborts this call (e.g. the tool call's `signal`); combined with `ctx.signal`. Batches not yet
75
+ * sent are not sent; batches already answered are still recorded as usage.
76
+ */
77
+ signal?: AbortSignal;
78
+ }
79
+ /** A `ctx.models.embed` result. */
80
+ export interface ExtensionEmbedResult {
81
+ /** One vector per input, in input order. */
82
+ vectors: number[][];
83
+ /** The model that made them (a changed model invalidates stored vectors). */
84
+ model: {
85
+ provider: string;
86
+ id: string;
87
+ };
88
+ dimensions: number;
89
+ }
90
+ /** The model a purpose maps to in an org (`ctx.models.describe`). */
91
+ export interface ExtensionModelTarget {
92
+ provider: string;
93
+ id: string;
94
+ kind: ModelKind;
95
+ /** Present for an embedding model. */
96
+ embedding?: ModelEmbeddingInfo;
97
+ }
98
+ /**
99
+ * Models by purpose (`permissions.models`): the purpose → model mapping is chosen by org admins
100
+ * (and the deployment default by the super admin), never by the extension. Only purposes this
101
+ * extension declared with `kind: "embedding"` are accepted (`model.purpose_unknown` otherwise), and
102
+ * only for an org that enabled the extension (`extension.not_enabled`). Usage is recorded by the
103
+ * kernel and reported through `usage.report` (purpose `embedding`).
104
+ */
105
+ export interface ExtensionModels {
106
+ /**
107
+ * Embeds `input` with the org's effective model for `purpose`. Rejects with `model.unconfigured`
108
+ * when the purpose maps to no model the org can use, `validation_failed` for dimensions the model
109
+ * lacks, and a `ModelError` when the provider fails (a result of the wrong count or dimension is a
110
+ * `ModelError` of kind `server`). Not retried by the kernel. Each call fires the `model.request`
111
+ * hook first (`purpose: "embedding"`, every text of the call): when a policy hook denies it, the
112
+ * call rejects with an error whose `code` is `model.hook_denied` (HTTP 403 if it escapes an
113
+ * extension route), and nothing is sent or billed.
114
+ */
115
+ embed(req: ExtensionEmbedRequest): Promise<ExtensionEmbedResult>;
116
+ /** The org's effective model for `purpose`, or null when it maps to no model the org can use. */
117
+ describe(req: {
118
+ orgId: string;
119
+ purpose: string;
120
+ }): Promise<ExtensionModelTarget | null>;
121
+ }
61
122
  /** 传给插件 `setup` 的上下文。不提供定时器与进程内共享状态;kv 写入必须带 TTL。 */
62
123
  export interface ExtensionContext {
63
124
  kv: {
@@ -94,6 +155,8 @@ export interface ExtensionContext {
94
155
  };
95
156
  /** 对象存储(需 `permissions.storage`,见 {@link ExtensionStorage})。 */
96
157
  storage: ExtensionStorage;
158
+ /** Models by purpose (requires `permissions.models`, see {@link ExtensionModels}). */
159
+ models: ExtensionModels;
97
160
  /** 已切到本插件 schema(withSchema)的 Kysely 实例。 */
98
161
  db: Kysely<any>;
99
162
  http: {
@@ -109,7 +172,9 @@ export interface ExtensionContext {
109
172
  * manifest's `requires` / `optional`. Without `orgId` it is the deployment-level view and returns
110
173
  * synchronously; with `orgId` it returns a Promise, and orgScoped extension points (such as
111
174
  * `channel`, `directory`) are filtered by that org's enablement (queried every time, not cached);
112
- * `get` rejects with `ExtensionPointUnavailableError` when the provider is not enabled in that org.
175
+ * with `orgId`, a provider whose effective config is not valid in that org is excluded too;
176
+ * `get` rejects with `ExtensionPointUnavailableError` when the provider is not enabled in that
177
+ * org or its config is not valid there.
113
178
  * When there is no provider, `get` throws `ExtensionPointUnavailableError` and `list` returns an
114
179
  * empty list.
115
180
  */
@@ -134,20 +199,37 @@ export interface ExtensionContext {
134
199
  * 界面贡献的运行时(清单 `ui` + `permissions.ui`):
135
200
  * - `view` / `action`:只能在 `setup` 期间注册,id 是清单里 kind view 的贡献 id;
136
201
  * `action` 收到视图里按钮或表单提交(`args.actionId` 区分是哪一个);
137
- * - `invalidate`:告诉内核「这个贡献变了」,打开着它的网页会重新取视图(经 bus,跨副本);
202
+ * - `invalidate`:告诉内核「这个贡献变了」,打开着它的网页会重新取视图(经 bus,跨副本);a
203
+ * `platform.page` contribution takes no `orgId` (it refreshes the admin console), every other
204
+ * contribution requires one;
138
205
  * - `verifyEmbedToken`:校验 embed 页面拿到的嵌入令牌,只认签给本插件、未过期的,且此刻插件仍在该组织启用、
139
- * 调用者仍是 active 成员(组织页面还要求 member 以上),否则返回 null;返回的 `role` 是此刻的角色。
206
+ * 调用者仍是 active 成员,角色仍满足位置的 minRole,否则返回 null;返回的 `role` 是此刻的角色。A
207
+ * platform-scope token (`scope: "platform"`, no `orgId`) verifies only for a `platform.page`
208
+ * contribution while the account is still an active super admin.
140
209
  */
141
210
  ui: {
142
211
  view(id: string, render: (args: UiRenderArgs) => Promise<UiView>): void;
143
212
  action(id: string, handler: (args: UiActionArgs) => Promise<UiActionResult>): void;
144
213
  invalidate(target: {
145
- orgId: string;
214
+ /** Required, except for a `platform.page` contribution, where it must be omitted. */
215
+ orgId?: string;
146
216
  conversationId?: string;
147
217
  contribution: string;
148
218
  }): Promise<void>;
149
219
  verifyEmbedToken(token: string): Promise<EmbedClaims | null>;
150
220
  };
221
+ /**
222
+ * Setup checks (`permissions.setupChecks`): the live rows of the plugin's setup guides.
223
+ * `check` is only allowed during `setup`; `id` must be listed in `permissions.setupChecks`
224
+ * (else `ExtensionPermissionError`); registering an id twice throws. The kernel runs a check only
225
+ * when a person or an agent asks, only for targets of this plugin and of `def.place`, aborts
226
+ * `signal` after `SETUP_CHECK_LIMITS.timeoutMs`, and redacts and bounds the result. A check never
227
+ * writes, passes `signal` to every request, does not retry and never puts a secret in `reason`
228
+ * or `fix`. It never receives an OAuth client secret or a member's token.
229
+ */
230
+ setup: {
231
+ check(id: string, def: SetupCheckDefinition): void;
232
+ };
151
233
  /**
152
234
  * Hooks (`permissions.hooks`): observe model and tool calls, or deny them with a policy hook.
153
235
  * `on` is only allowed during `setup`; the mount point must be declared in `permissions.hooks` and be
@@ -14,7 +14,11 @@ export interface ExtensionManifest {
14
14
  optional?: ExtensionPointRef[];
15
15
  /** 权限清单(治理而非沙箱)。 */
16
16
  permissions?: ExtensionPermissions;
17
- /** 界面贡献:对话页标签与组织页面;id 须同时列在 `permissions.ui` 里。 */
17
+ /**
18
+ * UI contributions, each in a slot of `UI_SLOTS`; every id is also listed in `permissions.ui`.
19
+ * Kept exactly as written: structural problems fail the extension, while a contribution to an
20
+ * unknown slot or version is only dropped when the host resolves the slots (`resolveUiSlots`).
21
+ */
18
22
  ui?: UiContribution[];
19
23
  config?: {
20
24
  deployment?: z.ZodTypeAny;
@@ -78,6 +78,7 @@ export function defineExtension(m) {
78
78
  if (errs.length > 0)
79
79
  fail(`invalid permissions: ${errs.join("; ")}`);
80
80
  }
81
+ // structural ui problems only; slot resolution never fails the extension (UI slots spec §3.2)
81
82
  const uiErrs = validateUiContributions(m.ui, m.permissions);
82
83
  if (uiErrs.length > 0)
83
84
  fail(`invalid ui: ${uiErrs.join("; ")}`);
@@ -0,0 +1,118 @@
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 { type ExecResult, type SandboxActor, type SandboxLimits, type SandboxRoots } from "./sandbox.js";
6
+ /** The protocol version carried in `X-Capybara-Device-Protocol` and the hello frame. */
7
+ export declare const DEVICE_PROTOCOL_VERSION = 1;
8
+ /** The operations the kernel asks a device to run. */
9
+ export type DeviceOp = "create" | "exec" | "readFile" | "writeFile" | "stat" | "killTagged" | "killAll" | "stop";
10
+ /** First frame from the device after the WebSocket opens. */
11
+ export interface DeviceHello {
12
+ type: "hello";
13
+ protocol: number;
14
+ programVersion: string;
15
+ os: "darwin" | "linux";
16
+ arch: string;
17
+ mode: "os" | "docker";
18
+ roots: SandboxRoots;
19
+ sessionIsolation: boolean;
20
+ }
21
+ /** Error kinds a device reports for a failed request. */
22
+ export type DeviceErrorKind = "gone" | "fs_gone" | "policy" | "error";
23
+ /** The device's answer to a {@link KernelReq}. */
24
+ export type DeviceRes = {
25
+ type: "res";
26
+ id: string;
27
+ ok: true;
28
+ result: unknown;
29
+ } | {
30
+ type: "res";
31
+ id: string;
32
+ ok: false;
33
+ error: {
34
+ kind: DeviceErrorKind;
35
+ message: string;
36
+ };
37
+ };
38
+ /** A request from the kernel. */
39
+ export interface KernelReq {
40
+ type: "req";
41
+ id: string;
42
+ op: DeviceOp;
43
+ args: unknown;
44
+ deadlineMs: number;
45
+ }
46
+ /** The kernel gives up on a request (abort or deadline). */
47
+ export interface KernelCancel {
48
+ type: "cancel";
49
+ id: string;
50
+ }
51
+ export type DeviceFrame = DeviceHello | DeviceRes | KernelReq | KernelCancel;
52
+ export interface DeviceExecArgs {
53
+ command: string;
54
+ cwd?: string;
55
+ env?: Record<string, string>;
56
+ timeoutMs: number;
57
+ maxOutputBytes: number;
58
+ tag: string;
59
+ actor: SandboxActor;
60
+ limits: SandboxLimits;
61
+ }
62
+ export type DeviceExecResult = ExecResult;
63
+ export interface DeviceReadFileArgs {
64
+ path: string;
65
+ maxBytes: number;
66
+ }
67
+ export type DeviceReadFileResult = {
68
+ dataB64: string;
69
+ truncated: boolean;
70
+ } | null;
71
+ export interface DeviceWriteFileArgs {
72
+ path: string;
73
+ dataB64: string;
74
+ }
75
+ export type DeviceWriteFileResult = null;
76
+ export interface DeviceStatArgs {
77
+ path: string;
78
+ }
79
+ export type DeviceStatResult = {
80
+ size: number;
81
+ isDir: boolean;
82
+ } | null;
83
+ export interface DeviceKillTaggedArgs {
84
+ tags: string[];
85
+ }
86
+ export type DeviceKillAllArgs = Record<string, never>;
87
+ export interface DeviceCreateArgs {
88
+ limits: SandboxLimits;
89
+ }
90
+ export interface DeviceCreateResult {
91
+ roots: SandboxRoots;
92
+ }
93
+ export interface DeviceStopArgs {
94
+ reason: "revoked" | "deleted";
95
+ }
96
+ /** A frame that is not valid protocol v1 (or came from the wrong side). */
97
+ export declare class DeviceProtocolError extends Error {
98
+ constructor(message: string);
99
+ }
100
+ /** Result type per op. */
101
+ export interface DeviceOpResults {
102
+ create: DeviceCreateResult;
103
+ exec: DeviceExecResult;
104
+ readFile: DeviceReadFileResult;
105
+ writeFile: DeviceWriteFileResult;
106
+ stat: DeviceStatResult;
107
+ killTagged: null;
108
+ killAll: null;
109
+ stop: null;
110
+ }
111
+ /** Validates the `result` of a successful `res` for `op`; throws {@link DeviceProtocolError}. */
112
+ export declare function parseOpResult<Op extends DeviceOp>(op: Op, result: unknown): DeviceOpResults[Op];
113
+ /**
114
+ * Parses one WebSocket text frame. `from` is the sender: a device may send `hello` and `res`, the
115
+ * kernel `req` and `cancel`. Throws {@link DeviceProtocolError} on bad JSON, an unknown `type`,
116
+ * missing fields or a frame of the wrong direction.
117
+ */
118
+ export declare function parseDeviceFrame(raw: string, from: "device" | "kernel"): DeviceFrame;
@@ -0,0 +1,276 @@
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 { 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
+ ];
18
+ /** A frame that is not valid protocol v1 (or came from the wrong side). */
19
+ export class DeviceProtocolError extends Error {
20
+ constructor(message) {
21
+ super(message);
22
+ this.name = "DeviceProtocolError";
23
+ }
24
+ }
25
+ function isRecord(v) {
26
+ return typeof v === "object" && v !== null && !Array.isArray(v);
27
+ }
28
+ function str(o, k) {
29
+ const v = o[k];
30
+ if (typeof v !== "string")
31
+ throw new DeviceProtocolError(`field "${k}" must be a string`);
32
+ return v;
33
+ }
34
+ function nonEmptyStr(o, k) {
35
+ const v = str(o, k);
36
+ if (v === "")
37
+ throw new DeviceProtocolError(`field "${k}" must not be empty`);
38
+ return v;
39
+ }
40
+ function posInt(o, k) {
41
+ const v = o[k];
42
+ if (typeof v !== "number" || !Number.isInteger(v) || v <= 0) {
43
+ throw new DeviceProtocolError(`field "${k}" must be a positive integer`);
44
+ }
45
+ return v;
46
+ }
47
+ function obj(v, what) {
48
+ if (!isRecord(v))
49
+ throw new DeviceProtocolError(`${what} must be an object`);
50
+ return v;
51
+ }
52
+ function bool(o, k) {
53
+ const v = o[k];
54
+ if (typeof v !== "boolean")
55
+ throw new DeviceProtocolError(`field "${k}" must be a boolean`);
56
+ return v;
57
+ }
58
+ function strArray(o, k) {
59
+ const v = o[k];
60
+ if (!Array.isArray(v) || v.some((x) => typeof x !== "string")) {
61
+ throw new DeviceProtocolError(`field "${k}" must be an array of strings`);
62
+ }
63
+ return v;
64
+ }
65
+ function parseLimits(v) {
66
+ const o = obj(v, 'field "limits"');
67
+ const egress = str(o, "egress");
68
+ if (egress !== "none" && egress !== "allowlist" && egress !== "open") {
69
+ throw new DeviceProtocolError(`unknown egress "${egress}"`);
70
+ }
71
+ return {
72
+ cpu: num(o, "cpu"),
73
+ memoryMb: num(o, "memoryMb"),
74
+ diskMb: num(o, "diskMb"),
75
+ egress,
76
+ allowHosts: strArray(o, "allowHosts"),
77
+ };
78
+ }
79
+ function num(o, k) {
80
+ const v = o[k];
81
+ if (typeof v !== "number" || !Number.isFinite(v)) {
82
+ throw new DeviceProtocolError(`field "${k}" must be a number`);
83
+ }
84
+ return v;
85
+ }
86
+ function parseRoots(v) {
87
+ if (!isRecord(v))
88
+ throw new DeviceProtocolError('field "roots" must be an object');
89
+ const roots = {};
90
+ for (const k of ["workspace", "skills", "tmp"]) {
91
+ const p = str(v, k);
92
+ if (!p.startsWith("/")) {
93
+ throw new DeviceProtocolError(`root "${k}" must be an absolute path`);
94
+ }
95
+ // the kernel builds paths as `${root}/…` and checks membership by prefix: a root must be a
96
+ // clean absolute directory path
97
+ const shape = validateSandboxPathShape(p);
98
+ if (shape.length > 0)
99
+ throw new DeviceProtocolError(`root "${k}": ${shape.join("; ")}`);
100
+ if (p.endsWith("/")) {
101
+ throw new DeviceProtocolError(`root "${k}" must not end with a slash`);
102
+ }
103
+ roots[k] = p;
104
+ }
105
+ return roots;
106
+ }
107
+ function parseHello(o) {
108
+ const os = str(o, "os");
109
+ if (os !== "darwin" && os !== "linux")
110
+ throw new DeviceProtocolError(`unsupported os "${os}"`);
111
+ const mode = str(o, "mode");
112
+ if (mode !== "os" && mode !== "docker") {
113
+ throw new DeviceProtocolError(`unsupported mode "${mode}"`);
114
+ }
115
+ if (typeof o.sessionIsolation !== "boolean") {
116
+ throw new DeviceProtocolError('field "sessionIsolation" must be a boolean');
117
+ }
118
+ return {
119
+ type: "hello",
120
+ protocol: posInt(o, "protocol"),
121
+ programVersion: str(o, "programVersion"),
122
+ os,
123
+ arch: str(o, "arch"),
124
+ mode,
125
+ roots: parseRoots(o.roots),
126
+ sessionIsolation: o.sessionIsolation,
127
+ };
128
+ }
129
+ function parseRes(o) {
130
+ const id = nonEmptyStr(o, "id");
131
+ if (o.ok === true)
132
+ return { type: "res", id, ok: true, result: o.result };
133
+ if (o.ok !== false)
134
+ throw new DeviceProtocolError('field "ok" must be a boolean');
135
+ const e = o.error;
136
+ if (!isRecord(e))
137
+ throw new DeviceProtocolError('field "error" must be an object');
138
+ const kind = str(e, "kind");
139
+ if (kind !== "gone" && kind !== "fs_gone" && kind !== "policy" && kind !== "error") {
140
+ throw new DeviceProtocolError(`unknown error kind "${kind}"`);
141
+ }
142
+ return { type: "res", id, ok: false, error: { kind, message: str(e, "message") } };
143
+ }
144
+ function parseReq(o) {
145
+ const op = str(o, "op");
146
+ if (!DEVICE_OPS.includes(op))
147
+ throw new DeviceProtocolError(`unknown op "${op}"`);
148
+ const args = obj(o.args, 'field "args"');
149
+ validateArgs(op, args);
150
+ return {
151
+ type: "req",
152
+ id: nonEmptyStr(o, "id"),
153
+ op: op,
154
+ args,
155
+ deadlineMs: posInt(o, "deadlineMs"),
156
+ };
157
+ }
158
+ function validateArgs(op, a) {
159
+ switch (op) {
160
+ case "exec": {
161
+ nonEmptyStr(a, "command");
162
+ posInt(a, "timeoutMs");
163
+ posInt(a, "maxOutputBytes");
164
+ str(a, "tag");
165
+ const actor = obj(a.actor, 'field "actor"');
166
+ str(actor, "accountId");
167
+ str(actor, "conversationId");
168
+ parseLimits(a.limits);
169
+ if (a.cwd !== undefined)
170
+ str(a, "cwd");
171
+ if (a.env !== undefined) {
172
+ const env = obj(a.env, 'field "env"');
173
+ for (const k of Object.keys(env))
174
+ str(env, k);
175
+ }
176
+ return;
177
+ }
178
+ case "readFile": {
179
+ str(a, "path");
180
+ const m = a.maxBytes;
181
+ if (typeof m !== "number" || !Number.isInteger(m) || m < 0) {
182
+ throw new DeviceProtocolError('field "maxBytes" must be a non-negative integer');
183
+ }
184
+ return;
185
+ }
186
+ case "writeFile":
187
+ str(a, "path");
188
+ str(a, "dataB64");
189
+ return;
190
+ case "stat":
191
+ str(a, "path");
192
+ return;
193
+ case "killTagged":
194
+ strArray(a, "tags");
195
+ return;
196
+ case "killAll":
197
+ return;
198
+ case "create":
199
+ parseLimits(a.limits);
200
+ return;
201
+ case "stop": {
202
+ const r = str(a, "reason");
203
+ if (r !== "revoked" && r !== "deleted") {
204
+ throw new DeviceProtocolError(`unknown stop reason "${r}"`);
205
+ }
206
+ return;
207
+ }
208
+ }
209
+ }
210
+ export function parseOpResult(op, result) {
211
+ switch (op) {
212
+ case "exec": {
213
+ const r = obj(result, "exec result");
214
+ const exitCode = r.exitCode;
215
+ if (exitCode !== null && (typeof exitCode !== "number" || !Number.isFinite(exitCode))) {
216
+ throw new DeviceProtocolError('field "exitCode" must be a number or null');
217
+ }
218
+ return {
219
+ exitCode: exitCode,
220
+ stdout: str(r, "stdout"),
221
+ stderr: str(r, "stderr"),
222
+ truncated: bool(r, "truncated"),
223
+ timedOut: bool(r, "timedOut"),
224
+ };
225
+ }
226
+ case "readFile": {
227
+ if (result === null)
228
+ return null;
229
+ const r = obj(result, "readFile result");
230
+ return { dataB64: str(r, "dataB64"), truncated: bool(r, "truncated") };
231
+ }
232
+ case "stat": {
233
+ if (result === null)
234
+ return null;
235
+ const r = obj(result, "stat result");
236
+ return { size: num(r, "size"), isDir: bool(r, "isDir") };
237
+ }
238
+ case "create":
239
+ return { roots: parseRoots(obj(result, "create result").roots) };
240
+ default:
241
+ if (result !== null)
242
+ throw new DeviceProtocolError(`${op} result must be null`);
243
+ return null;
244
+ }
245
+ }
246
+ /**
247
+ * Parses one WebSocket text frame. `from` is the sender: a device may send `hello` and `res`, the
248
+ * kernel `req` and `cancel`. Throws {@link DeviceProtocolError} on bad JSON, an unknown `type`,
249
+ * missing fields or a frame of the wrong direction.
250
+ */
251
+ export function parseDeviceFrame(raw, from) {
252
+ let o;
253
+ try {
254
+ o = JSON.parse(raw);
255
+ }
256
+ catch {
257
+ throw new DeviceProtocolError("frame is not valid JSON");
258
+ }
259
+ if (!isRecord(o))
260
+ throw new DeviceProtocolError("frame must be a JSON object");
261
+ const type = o.type;
262
+ switch (type) {
263
+ case "hello":
264
+ case "res":
265
+ if (from !== "device")
266
+ throw new DeviceProtocolError(`"${type}" must come from the device`);
267
+ return type === "hello" ? parseHello(o) : parseRes(o);
268
+ case "req":
269
+ case "cancel":
270
+ if (from !== "kernel")
271
+ throw new DeviceProtocolError(`"${type}" must come from the kernel`);
272
+ return type === "req" ? parseReq(o) : { type: "cancel", id: nonEmptyStr(o, "id") };
273
+ default:
274
+ throw new DeviceProtocolError(`unknown frame type "${String(type)}"`);
275
+ }
276
+ }
@@ -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,20 @@ 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[];
16
+ /**
17
+ * How the kernel picks one provider among several: `org-default` means each org chooses its
18
+ * default provider (absent: no selection, every enabled provider is used).
19
+ */
20
+ selection?: "org-default";
12
21
  }
13
22
  /** The registered extension points. */
14
23
  export declare const EXTENSION_POINTS: Record<string, ExtensionPointInfo>;
@@ -1,21 +1,26 @@
1
- const info = (cardinality, brokered = false, orgScoped = false) => ({
1
+ const info = (majors, description, cardinality, brokered = false, orgScoped = false, selection) => ({
2
+ majors,
3
+ description,
2
4
  cardinality,
3
5
  brokered,
4
6
  orgScoped,
7
+ ...(selection ? { selection } : {}),
5
8
  });
6
9
  /** The registered extension points. */
7
10
  export const EXTENSION_POINTS = {
8
- sandbox: info("single", true),
9
- "config-source": info("single"),
10
- "secret-store": info("single", true),
11
- "object-store": info("single", true),
12
- channel: info("multi", false, true),
13
- "model-provider": info("multi", true),
14
- "identity-source": info("multi"),
15
- directory: info("multi", false, true),
16
- counter: info("multi"),
17
- connector: info("multi", true),
18
- "file-preview": info("multi", false, true),
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
+ "web-fetch": info([1], "Fetches and extracts web pages for the WebFetch tool; each org picks a default provider.", "multi", true, true, "org-default"),
19
24
  };
20
25
  /** Cardinality of the registered extension points (derived from EXTENSION_POINTS). */
21
26
  export const EXTENSION_POINT_CARDINALITY = Object.fromEntries(Object.entries(EXTENSION_POINTS).map(([k, v]) => [k, v.cardinality]));
@@ -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[];