@capybara-hq/plugin-sdk 0.1.0-rc.8 → 0.1.0-rc.80

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 (149) hide show
  1. package/README.md +1 -1
  2. package/agent-docs/agent-templates.md +14 -2
  3. package/agent-docs/concepts.md +14 -5
  4. package/agent-docs/connector-templates.md +11 -3
  5. package/agent-docs/extension-points/channel.md +1 -1
  6. package/agent-docs/extension-points/context.md +15 -0
  7. package/agent-docs/extension-points/device-provider.md +15 -0
  8. package/agent-docs/extension-points/file-preview.md +3 -1
  9. package/agent-docs/extension-points/identity-source.md +2 -0
  10. package/agent-docs/extension-points/model-provider.md +3 -1
  11. package/agent-docs/extension-points/object-store.md +2 -0
  12. package/agent-docs/extension-points/push-provider.md +17 -0
  13. package/agent-docs/extensions.md +77 -4
  14. package/agent-docs/plugin-format.md +45 -10
  15. package/agent-docs/setup.md +54 -0
  16. package/dist/agent-template.d.ts +15 -6
  17. package/dist/agent-template.js +32 -13
  18. package/dist/avatar-presets.d.ts +8 -0
  19. package/dist/avatar-presets.js +17 -0
  20. package/dist/bootstrap.d.ts +109 -1
  21. package/dist/bootstrap.js +185 -2
  22. package/dist/cards.d.ts +60 -13
  23. package/dist/cards.js +88 -18
  24. package/dist/channel.d.ts +128 -47
  25. package/dist/channel.js +10 -5
  26. package/dist/client-css.d.ts +36 -0
  27. package/dist/client-css.js +326 -0
  28. package/dist/client-section.d.ts +35 -0
  29. package/dist/client-section.js +133 -0
  30. package/dist/config-ui.d.ts +28 -6
  31. package/dist/config-ui.js +88 -25
  32. package/dist/config-url-fetch.d.ts +19 -0
  33. package/dist/config-url-fetch.js +43 -0
  34. package/dist/connector-auth.d.ts +13 -2
  35. package/dist/connector-auth.js +82 -8
  36. package/dist/connector.d.ts +74 -32
  37. package/dist/context.d.ts +40 -0
  38. package/dist/context.js +2 -0
  39. package/dist/ctx.d.ts +224 -30
  40. package/dist/ctx.js +9 -1
  41. package/dist/define-extension.d.ts +23 -13
  42. package/dist/define-extension.js +19 -5
  43. package/dist/device-denied-paths.d.ts +20 -0
  44. package/dist/device-denied-paths.js +118 -0
  45. package/dist/device-operation.d.ts +339 -0
  46. package/dist/device-operation.js +312 -0
  47. package/dist/device-protocol.d.ts +285 -50
  48. package/dist/device-protocol.js +755 -90
  49. package/dist/device-provider.d.ts +780 -0
  50. package/dist/device-provider.js +409 -0
  51. package/dist/device-service.d.ts +126 -0
  52. package/dist/device-service.js +211 -0
  53. package/dist/dial-in.d.ts +286 -0
  54. package/dist/dial-in.js +213 -0
  55. package/dist/directory.d.ts +15 -12
  56. package/dist/extension-point.d.ts +2 -0
  57. package/dist/extension-point.js +7 -3
  58. package/dist/field-meta.d.ts +19 -0
  59. package/dist/field-meta.js +54 -0
  60. package/dist/file-preview.d.ts +43 -10
  61. package/dist/git-hosts.d.ts +53 -0
  62. package/dist/git-hosts.js +98 -0
  63. package/dist/hooks.d.ts +125 -20
  64. package/dist/hooks.js +5 -0
  65. package/dist/http-access.d.ts +71 -0
  66. package/dist/http-access.js +12 -0
  67. package/dist/identity.d.ts +70 -9
  68. package/dist/identity.js +46 -1
  69. package/dist/index.d.ts +28 -4
  70. package/dist/index.js +28 -4
  71. package/dist/model-params.d.ts +41 -22
  72. package/dist/model-params.js +28 -15
  73. package/dist/model.d.ts +210 -75
  74. package/dist/model.js +152 -19
  75. package/dist/native-failure.d.ts +13 -0
  76. package/dist/native-failure.js +31 -0
  77. package/dist/net.d.ts +52 -0
  78. package/dist/net.js +34 -0
  79. package/dist/network-classes.d.ts +98 -0
  80. package/dist/network-classes.js +291 -0
  81. package/dist/permissions.d.ts +65 -22
  82. package/dist/permissions.js +139 -43
  83. package/dist/platform-only.d.ts +27 -0
  84. package/dist/platform-only.js +35 -0
  85. package/dist/plugin-manifest.d.ts +30 -6
  86. package/dist/plugin-manifest.js +147 -55
  87. package/dist/plugin-package.d.ts +82 -39
  88. package/dist/plugin-package.js +68 -41
  89. package/dist/push.d.ts +75 -0
  90. package/dist/push.js +87 -0
  91. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  92. package/dist/sandbox-linux-runtime-source.js +2343 -0
  93. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  94. package/dist/sandbox-native-runtime-source.js +480 -0
  95. package/dist/sandbox-runtime-source.d.ts +47 -0
  96. package/dist/sandbox-runtime-source.js +73 -0
  97. package/dist/sandbox-write-denies.d.ts +139 -0
  98. package/dist/sandbox-write-denies.js +869 -0
  99. package/dist/secret.d.ts +8 -2
  100. package/dist/secret.js +11 -4
  101. package/dist/setup-check.d.ts +128 -0
  102. package/dist/setup-check.js +142 -0
  103. package/dist/setup-guide-parse.d.ts +121 -0
  104. package/dist/setup-guide-parse.js +356 -0
  105. package/dist/setup-guide-render.d.ts +45 -0
  106. package/dist/setup-guide-render.js +351 -0
  107. package/dist/setup-guide.d.ts +86 -72
  108. package/dist/setup-guide.js +340 -108
  109. package/dist/shell-capabilities.d.ts +211 -0
  110. package/dist/shell-capabilities.js +44 -0
  111. package/dist/shell-environment.d.ts +57 -0
  112. package/dist/shell-environment.js +21 -0
  113. package/dist/skill-invocation.d.ts +5 -0
  114. package/dist/skill-invocation.js +4 -3
  115. package/dist/skill.d.ts +27 -17
  116. package/dist/skill.js +40 -26
  117. package/dist/storage.d.ts +52 -25
  118. package/dist/svg-viewbox.d.ts +10 -0
  119. package/dist/svg-viewbox.js +24 -0
  120. package/dist/theme-assets.d.ts +25 -9
  121. package/dist/theme-assets.js +87 -47
  122. package/dist/theme-tokens.generated.d.ts +26 -2
  123. package/dist/theme-tokens.generated.js +17 -0
  124. package/dist/theme.d.ts +48 -10
  125. package/dist/theme.js +100 -21
  126. package/dist/tool.d.ts +156 -30
  127. package/dist/tool.js +91 -9
  128. package/dist/ui-parts.d.ts +23 -0
  129. package/dist/ui-parts.js +385 -0
  130. package/dist/ui-resolve.d.ts +35 -0
  131. package/dist/ui-resolve.js +42 -0
  132. package/dist/ui-slots.d.ts +65 -0
  133. package/dist/ui-slots.js +261 -0
  134. package/dist/ui.d.ts +245 -77
  135. package/dist/ui.js +104 -27
  136. package/dist/url.d.ts +4 -1
  137. package/dist/url.js +4 -1
  138. package/dist/web.d.ts +26 -20
  139. package/package.json +12 -1
  140. package/schemas/bootstrap-extra.v1.schema.json +186 -0
  141. package/schemas/bootstrap.v1.schema.json +20 -0
  142. package/schemas/connector-template.v1.schema.json +62 -4
  143. package/schemas/plugin.v1.schema.json +74 -143
  144. package/schemas/theme.v1.schema.json +77 -0
  145. package/agent-docs/extension-points/sandbox.md +0 -15
  146. package/dist/org-access.d.ts +0 -27
  147. package/dist/org-access.js +0 -35
  148. package/dist/sandbox.d.ts +0 -254
  149. package/dist/sandbox.js +0 -153
@@ -0,0 +1,213 @@
1
+ /**
2
+ * The dial-in channel: the kernel's generic way for a machine to connect to a deployment and
3
+ * serve one device of a `device-provider@1` extension that declares `permissions.dialIn`. The
4
+ * kernel signs the machine in, holds its socket on the gateway role, bounds every frame by the
5
+ * negotiated size and relays the frames' opaque `body` between the machine and the device's
6
+ * provider. It never reads a body: what a body means is the provider's protocol, named by
7
+ * `permissions.dialIn.protocol` and by the machine's hello.
8
+ */
9
+ import { z } from "zod";
10
+ /**
11
+ * A dial-in protocol: `<name>/<major>`, a lower-case name of 1 to 41 characters and a major
12
+ * version from 1 to 9999 (for example `capybara-device/6`). A machine's hello must name exactly
13
+ * the protocol of the provider serving its device.
14
+ */
15
+ export const DIAL_IN_PROTOCOL_RE = /^[a-z][a-z0-9-]{0,40}\/[1-9][0-9]{0,3}$/;
16
+ /**
17
+ * The credit, in messages, each side of a dial-in stream starts with for the other: a side sends a
18
+ * `stream-data` only while it holds credit, and grants more with `stream-credit` as it consumes
19
+ * messages, so one stream cannot fill the connection and starve the machine's other frames.
20
+ */
21
+ export const DIAL_IN_STREAM_INITIAL_CREDIT = 8;
22
+ /** A machine frame that is not a valid dial-in envelope. The kernel closes the socket on it. */
23
+ export class DialInProtocolError extends Error {
24
+ constructor(message) {
25
+ super(message);
26
+ this.name = "DialInProtocolError";
27
+ }
28
+ }
29
+ /** Ids, `programRunId` and `bootId`: 1 to 128 letters, digits, `.`, `_`, `:` and `-`. */
30
+ const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
31
+ const id = z.string().regex(ID_RE);
32
+ const label = z.string().min(1).max(64);
33
+ // a frame without a body is malformed (JSON has no undefined, so this is a missing key)
34
+ const body = z.unknown().refine((v) => v !== undefined, "body is required");
35
+ // standard base64, padded; empty is an empty message
36
+ const base64 = z
37
+ .string()
38
+ .regex(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/, "data must be base64");
39
+ const reason = z.string().max(500);
40
+ const streamFrames = [
41
+ z.strictObject({ type: z.literal("stream-data"), streamId: id, data: base64 }),
42
+ z.strictObject({
43
+ type: z.literal("stream-credit"),
44
+ streamId: id,
45
+ messages: z.number().int().min(1).max(1_000_000),
46
+ }),
47
+ z.strictObject({ type: z.literal("stream-close"), streamId: id, reason }),
48
+ ];
49
+ const machineFrame = z.discriminatedUnion("type", [
50
+ z.strictObject({
51
+ type: z.literal("hello"),
52
+ protocol: z.string().regex(DIAL_IN_PROTOCOL_RE),
53
+ programRunId: id,
54
+ program: z.strictObject({
55
+ version: label,
56
+ os: label,
57
+ arch: label,
58
+ bootId: id.optional(),
59
+ }),
60
+ transport: z.strictObject({
61
+ maxFrameBytes: z.number().int().min(1024).max(Number.MAX_SAFE_INTEGER),
62
+ binaryStreamData: z.literal(true).optional(),
63
+ }),
64
+ body,
65
+ }),
66
+ z.strictObject({ type: z.literal("res"), id, body }),
67
+ z.strictObject({ type: z.literal("event"), body }),
68
+ z.strictObject({
69
+ type: z.literal("stream-opened"),
70
+ streamId: id,
71
+ ok: z.boolean(),
72
+ error: reason.optional(),
73
+ }),
74
+ ...streamFrames,
75
+ ]);
76
+ /**
77
+ * Strictly parses one machine frame: the text must be at most `maxBytes` UTF-8 bytes (checked
78
+ * before `JSON.parse`), an object of a known `type` with exactly that type's keys. `body` is kept
79
+ * as parsed, never inspected. Throws {@link DialInProtocolError}; a `maxBytes` that is not a
80
+ * positive integer throws a `RangeError`.
81
+ */
82
+ export function parseDialInMachineFrame(text, maxBytes) {
83
+ return parseFrame(machineFrame, text, maxBytes);
84
+ }
85
+ function parseFrame(schema, text, maxBytes) {
86
+ if (!Number.isSafeInteger(maxBytes) || maxBytes < 1)
87
+ throw new RangeError(`maxBytes must be a positive integer, got ${maxBytes}`);
88
+ // a UTF-16 code unit is at least one UTF-8 byte: the length alone may already decide it
89
+ if (text.length > maxBytes || new TextEncoder().encode(text).byteLength > maxBytes)
90
+ throw new DialInProtocolError(`frame exceeds ${maxBytes} bytes`);
91
+ let parsed;
92
+ try {
93
+ parsed = JSON.parse(text);
94
+ }
95
+ catch {
96
+ throw new DialInProtocolError("frame is not valid JSON");
97
+ }
98
+ const r = schema.safeParse(parsed);
99
+ if (!r.success) {
100
+ const issue = r.error.issues[0];
101
+ const at = issue?.path.length ? ` at ${issue.path.join(".")}` : "";
102
+ throw new DialInProtocolError(`invalid dial-in frame${at}: ${issue?.message ?? "malformed"}`);
103
+ }
104
+ return r.data;
105
+ }
106
+ const kernelFrame = z.discriminatedUnion("type", [
107
+ z.strictObject({
108
+ type: z.literal("ready"),
109
+ connectionId: id,
110
+ maxFrameBytes: z.number().int().min(1024).max(Number.MAX_SAFE_INTEGER),
111
+ binaryStreamData: z.literal(true).optional(),
112
+ }),
113
+ z.strictObject({
114
+ type: z.literal("req"),
115
+ id,
116
+ deadlineMs: z.number().int().min(1).max(Number.MAX_SAFE_INTEGER),
117
+ body,
118
+ }),
119
+ z.strictObject({ type: z.literal("cancel"), id }),
120
+ z.strictObject({ type: z.literal("stop"), reason: z.enum(["drain", "stop"]) }),
121
+ z.strictObject({ type: z.literal("stream-open"), streamId: id, body }),
122
+ ...streamFrames,
123
+ ]);
124
+ /**
125
+ * The machine's side of {@link parseDialInMachineFrame}: strictly parses one kernel frame, at most
126
+ * `maxBytes` UTF-8 bytes (checked before `JSON.parse`), an object of a known `type` with exactly
127
+ * that type's keys; `body` is kept as parsed. Throws {@link DialInProtocolError}; a `maxBytes`
128
+ * that is not a positive integer throws a `RangeError`.
129
+ */
130
+ export function parseDialInKernelFrame(text, maxBytes) {
131
+ return parseFrame(kernelFrame, text, maxBytes);
132
+ }
133
+ /** The first byte of a binary `stream-data` message (the only binary dial-in message). */
134
+ export const DIAL_IN_STREAM_DATA_TAG = 1;
135
+ /**
136
+ * One `stream-data` as a binary WebSocket message, for a connection whose hello and ready set
137
+ * `binaryStreamData`: the tag {@link DIAL_IN_STREAM_DATA_TAG}, the stream id's length in bytes (one
138
+ * byte), the id in ASCII, then the message's bytes as they are. Like every frame it must fit the
139
+ * connection's `maxFrameBytes` (its byte length). Throws a `RangeError` for an id that is not a
140
+ * dial-in id.
141
+ */
142
+ export function encodeDialInStreamData(streamId, data) {
143
+ if (!ID_RE.test(streamId))
144
+ throw new RangeError(`not a dial-in stream id: ${streamId}`);
145
+ const out = new Uint8Array(2 + streamId.length + data.byteLength);
146
+ out[0] = DIAL_IN_STREAM_DATA_TAG;
147
+ out[1] = streamId.length;
148
+ for (let i = 0; i < streamId.length; i++)
149
+ out[2 + i] = streamId.charCodeAt(i);
150
+ out.set(data, 2 + streamId.length);
151
+ return out;
152
+ }
153
+ /**
154
+ * Reads a binary `stream-data` message ({@link encodeDialInStreamData}); `data` is a view into
155
+ * `message`. Throws {@link DialInProtocolError} for anything else: another tag, a truncated
156
+ * header, an id that is not a dial-in id.
157
+ */
158
+ export function decodeDialInStreamData(message) {
159
+ if (message.byteLength < 2 || message[0] !== DIAL_IN_STREAM_DATA_TAG)
160
+ throw new DialInProtocolError("binary frame is not stream-data");
161
+ const len = message[1];
162
+ if (message.byteLength < 2 + len)
163
+ throw new DialInProtocolError("binary stream-data is truncated");
164
+ let streamId = "";
165
+ for (let i = 0; i < len; i++)
166
+ streamId += String.fromCharCode(message[2 + i]);
167
+ if (!ID_RE.test(streamId))
168
+ throw new DialInProtocolError("binary stream-data has an invalid id");
169
+ return { streamId, data: message.subarray(2 + len) };
170
+ }
171
+ /**
172
+ * {@link DialInChannel.openStream} was called on a replica that does not hold the machine's
173
+ * socket: the caller must reach the holding gateway replica instead.
174
+ */
175
+ export class DialInStreamElsewhereError extends Error {
176
+ code = "device.stream_elsewhere";
177
+ constructor(deviceId, opts) {
178
+ super(`Device ${deviceId}'s machine is connected to another gateway replica; open the stream there.`, opts && "cause" in opts ? { cause: opts.cause } : undefined);
179
+ this.name = "DialInStreamElsewhereError";
180
+ }
181
+ }
182
+ /** No machine serves the device (it is not connected, and did not reconnect within the grace). */
183
+ export class DeviceOfflineError extends Error {
184
+ code = "device.offline";
185
+ constructor(deviceId, opts) {
186
+ super(`Device ${deviceId} is offline: no machine is connected for it. Reconnect the machine and retry.`, opts && "cause" in opts ? { cause: opts.cause } : undefined);
187
+ this.name = "DeviceOfflineError";
188
+ }
189
+ }
190
+ /** Recognizes {@link DeviceOfflineError} by name and code, so another SDK copy's error matches. */
191
+ export function isDeviceOfflineError(e) {
192
+ return (e instanceof Error &&
193
+ e.name === "DeviceOfflineError" &&
194
+ e.code === "device.offline");
195
+ }
196
+ /**
197
+ * The machine stayed connected but sent no answer within the request's deadline plus a short
198
+ * margin (`ctx.dialIn.request`): it may have run the request, so the outcome is unknown. A cancel
199
+ * was queued for it.
200
+ */
201
+ export class DialInAnswerTimeoutError extends Error {
202
+ code = "device.answer_timeout";
203
+ constructor(deadlineMs, opts) {
204
+ super(`The connected machine did not answer within the request's deadline of ${Math.ceil(deadlineMs / 1000)} s; the outcome is unknown, check the device and retry`, opts && "cause" in opts ? { cause: opts.cause } : undefined);
205
+ this.name = "DialInAnswerTimeoutError";
206
+ }
207
+ }
208
+ /** Recognizes {@link DialInAnswerTimeoutError} by name and code, so another SDK copy's error matches. */
209
+ export function isDialInAnswerTimeoutError(e) {
210
+ return (e instanceof Error &&
211
+ e.name === "DialInAnswerTimeoutError" &&
212
+ e.code === "device.answer_timeout");
213
+ }
@@ -8,27 +8,30 @@ export interface DirectoryMember {
8
8
  }
9
9
  export interface Directory {
10
10
  /**
11
- * Optional: whether this org-level config has the directory fully set up (e.g. every required
12
- * credential filled in). Implement it in an extension whose directory fields are optional in the
13
- * org-level config (the same extension also provides other extension points such as a channel, and
14
- * an org that uses only those leaves the directory config empty). When it returns false the kernel
11
+ * Optional: whether the org's effective config has the directory fully set up (e.g. every
12
+ * required credential filled in). Implement it in an extension whose directory fields are
13
+ * optional (the same extension also provides other extension points such as a channel, and an
14
+ * org that uses only those leaves the directory fields empty). When it returns false the kernel
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
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
+ * is the effective config for the org (see `listMembers`' `config`).
20
20
  */
21
- configured?(orgConfig: unknown, config?: unknown): boolean;
21
+ configured?(config: unknown): boolean;
22
22
  listMembers(args: {
23
- orgConfig: unknown;
24
23
  /**
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
24
+ * The extension's effective config for this org: the platform's deployment config with the
25
+ * org's copy applied to the overridable fields (every field not marked `platformOnly`), or the
27
26
  * 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.
27
+ * for work done for this org.
30
28
  */
31
- config?: unknown;
29
+ config: unknown;
30
+ /**
31
+ * The org the call is made for. Pass it to `configUrlFetch` (`orgId`) or `ctx.net.fetch`, so a
32
+ * URL an org set is checked against that org's network rules. The kernel always sets it.
33
+ */
34
+ orgId?: string;
32
35
  cursor?: string;
33
36
  signal: AbortSignal;
34
37
  }): Promise<{
@@ -31,6 +31,8 @@ export declare const CHANNEL_EXTENSION_POINT = "channel@1";
31
31
  export declare const IDENTITY_SOURCE_EXTENSION_POINT = "identity-source@1";
32
32
  /** Directory sync extension point ref (see `directory.ts`). */
33
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";
34
36
  /** Parses an extension point ref; throws when the format is invalid. */
35
37
  export declare function parseExtensionPoint(ref: string): {
36
38
  name: string;
@@ -8,19 +8,21 @@ const info = (majors, description, cardinality, brokered = false, orgScoped = fa
8
8
  });
9
9
  /** The registered extension points. */
10
10
  export const EXTENSION_POINTS = {
11
- sandbox: info([2], "Runs an environment's instance and keeps its files for agents' commands (Docker, E2B).", "single", true),
11
+ "device-provider": info([1], "Provides devices (an instance plus kept files) agents run commands in: containers, microVMs, connected machines.", "multi", true, true),
12
12
  "config-source": info([1], "Supplies deployment configuration from an external store such as Nacos.", "single"),
13
13
  "secret-store": info([1], "Stores and resolves secrets (connector credentials, secret config) outside the database.", "single", true),
14
14
  "object-store": info([1], "Stores files and artifacts in S3-compatible object storage, with presigned uploads.", "single", true),
15
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),
16
+ "model-provider": info([2], "Calls a model vendor's API and streams the result back to the runtime.", "multi", true),
17
17
  "identity-source": info([1], "Signs people in through an external identity provider (SSO).", "multi"),
18
18
  directory: info([1], "Syncs members and departments from an external company directory.", "multi", false, true),
19
19
  counter: info([1], "Counts usage so quotas and reports can be built on it.", "multi"),
20
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),
21
+ "file-preview": info([1], "Renders previews of files of given types: conversation files, shared files and skill files.", "multi", false, true),
22
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),
23
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"),
25
+ "push-provider": info([1], "Delivers push notifications to people's mobile apps through one channel (APNs, FCM, an aggregator).", "multi", true),
24
26
  };
25
27
  /** Cardinality of the registered extension points (derived from EXTENSION_POINTS). */
26
28
  export const EXTENSION_POINT_CARDINALITY = Object.fromEntries(Object.entries(EXTENSION_POINTS).map(([k, v]) => [k, v.cardinality]));
@@ -32,6 +34,8 @@ export const CHANNEL_EXTENSION_POINT = "channel@1";
32
34
  export const IDENTITY_SOURCE_EXTENSION_POINT = "identity-source@1";
33
35
  /** Directory sync extension point ref (see `directory.ts`). */
34
36
  export const DIRECTORY_EXTENSION_POINT = "directory@1";
37
+ /** Context provider extension point ref (see `context.ts`). */
38
+ export const CONTEXT_EXTENSION_POINT = "context@1";
35
39
  /** Parses an extension point ref; throws when the format is invalid. */
36
40
  export function parseExtensionPoint(ref) {
37
41
  const m = /^([a-z][a-z0-9-]*)@(\d+)$/.exec(ref);
@@ -0,0 +1,19 @@
1
+ import type { z } from "zod";
2
+ /**
3
+ * The wrappers a config field's marks are read through: the same set the kernel's `configFields`
4
+ * strips and `configJsonSchema` inherits meta across.
5
+ */
6
+ export declare const META_WRAPPERS: ReadonlySet<string>;
7
+ type Meta = Record<string, unknown>;
8
+ /** The schema and every node under it reached through {@link META_WRAPPERS}, outermost first. */
9
+ export declare function wrapperChain(schema: z.ZodTypeAny): z.ZodTypeAny[];
10
+ /**
11
+ * The meta of a config field merged across its wrapper chain: an outer key wins over an inner one,
12
+ * except `secret` and `platformOnly`, which are true when any node of the chain carries them
13
+ * (fail-safe: a wrapper's meta never hides a secret or clears a platform-only mark). Zod's `id` is
14
+ * left out: it names one schema instance.
15
+ */
16
+ export declare function chainMeta(schema: z.ZodTypeAny): Meta;
17
+ /** Sets `key: value` on the schema's meta, keeping every mark found through its wrappers. */
18
+ export declare function withMeta<T extends z.ZodTypeAny>(schema: T, key: string, value: unknown): T;
19
+ export {};
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The wrappers a config field's marks are read through: the same set the kernel's `configFields`
3
+ * strips and `configJsonSchema` inherits meta across.
4
+ */
5
+ export const META_WRAPPERS = new Set([
6
+ "default",
7
+ "prefault",
8
+ "optional",
9
+ "nullable",
10
+ "readonly",
11
+ "catch",
12
+ ]);
13
+ /** The schema and every node under it reached through {@link META_WRAPPERS}, outermost first. */
14
+ export function wrapperChain(schema) {
15
+ const out = [];
16
+ let node = schema;
17
+ while (node) {
18
+ out.push(node);
19
+ const def = node._zod.def;
20
+ node = META_WRAPPERS.has(def.type) ? def.innerType : undefined;
21
+ }
22
+ return out;
23
+ }
24
+ /**
25
+ * The meta of a config field merged across its wrapper chain: an outer key wins over an inner one,
26
+ * except `secret` and `platformOnly`, which are true when any node of the chain carries them
27
+ * (fail-safe: a wrapper's meta never hides a secret or clears a platform-only mark). Zod's `id` is
28
+ * left out: it names one schema instance.
29
+ */
30
+ export function chainMeta(schema) {
31
+ const out = {};
32
+ let secret = false;
33
+ let platformOnly = false;
34
+ for (const node of wrapperChain(schema).reverse()) {
35
+ const m = node.meta();
36
+ if (!m)
37
+ continue;
38
+ if (m.secret === true)
39
+ secret = true;
40
+ if (m.platformOnly === true)
41
+ platformOnly = true;
42
+ Object.assign(out, m);
43
+ }
44
+ delete out.id;
45
+ if (secret)
46
+ out.secret = true;
47
+ if (platformOnly)
48
+ out.platformOnly = true;
49
+ return out;
50
+ }
51
+ /** Sets `key: value` on the schema's meta, keeping every mark found through its wrappers. */
52
+ export function withMeta(schema, key, value) {
53
+ return schema.meta({ ...(schema.meta() ?? {}), ...chainMeta(schema), [key]: value });
54
+ }
@@ -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 {
@@ -34,14 +34,15 @@ export interface FilePreviewer {
34
34
  export interface FilePreviewProvider {
35
35
  previewers: FilePreviewer[];
36
36
  }
37
- /** Arguments of {@link FilePreviewer.render}; identities come from the kernel after authentication. */
38
- export interface FilePreviewArgs {
39
- orgId: string;
40
- accountId: string;
41
- conversationId: string;
37
+ /** What every {@link FilePreviewArgs} variant carries. */
38
+ export interface FilePreviewArgsBase {
42
39
  locale: Locale;
43
40
  /** Aborted at the kernel's time limit: stop reading and rendering. */
44
41
  signal: AbortSignal;
42
+ /**
43
+ * In the share variant `file.id` is the share id; in the skill variant it is
44
+ * `<skillId>@<version>/<path>`.
45
+ */
45
46
  file: {
46
47
  id: string;
47
48
  name: string;
@@ -55,13 +56,45 @@ export interface FilePreviewArgs {
55
56
  read(): Promise<Uint8Array>;
56
57
  /**
57
58
  * 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.
59
+ * with the org's copy applied to the overridable fields (every field not marked `platformOnly`),
60
+ * or the platform's config (equal to `ctx.config`) while the org follows it. Use it, not
61
+ * `ctx.config`, for work done for this org.
62
62
  */
63
63
  config?: unknown;
64
64
  }
65
+ /** A preview inside a conversation; identities come from the kernel after authentication. */
66
+ export interface FilePreviewConversationArgs extends FilePreviewArgsBase {
67
+ source: "conversation";
68
+ orgId: string;
69
+ accountId: string;
70
+ conversationId: string;
71
+ }
72
+ /**
73
+ * A preview on a share page: there is no account and no conversation. A previewer that needs the
74
+ * conversation declines this variant by throwing; the kernel reports the failure and the page falls
75
+ * to the next previewer.
76
+ */
77
+ export interface FilePreviewShareArgs extends FilePreviewArgsBase {
78
+ source: "share";
79
+ orgId: string;
80
+ shareId: string;
81
+ }
82
+ /**
83
+ * A file of a skill version, previewed on the skill's page: the person who opened it (`accountId`),
84
+ * the skill, the version and the file's path in it (a path of the version's manifest). There is no
85
+ * conversation. `file.id` is `<skillId>@<version>/<path>`. A previewer that needs the conversation
86
+ * declines this variant by throwing, as it does a share.
87
+ */
88
+ export interface FilePreviewSkillArgs extends FilePreviewArgsBase {
89
+ source: "skill";
90
+ orgId: string;
91
+ accountId: string;
92
+ skillId: string;
93
+ version: number;
94
+ path: string;
95
+ }
96
+ /** Arguments of {@link FilePreviewer.render}: narrow on `source`. */
97
+ export type FilePreviewArgs = FilePreviewConversationArgs | FilePreviewShareArgs | FilePreviewSkillArgs;
65
98
  /** Checks a `file-preview@1` provider; returns the problems (empty = valid). */
66
99
  export declare function validateFilePreviewProvider(p: unknown): string[];
67
100
  /** Whether a previewer takes this file: its type or extension is accepted and it is within `maxBytes`. */
@@ -0,0 +1,53 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * The git source of a connector: the git hosts a connector's credential may be used for, and the
4
+ * HTTP basic username to present for each (spec 2026-11-12-sandbox-git-credentials §6.1). Pure
5
+ * validation; the kernel reuses {@link GitSourceSchema} for its connector create body.
6
+ */
7
+ /** Limits of {@link GitSourceSchema}. */
8
+ export declare const GIT_HOSTS_LIMITS: {
9
+ /** Hosts per connector. */
10
+ readonly hosts: 8;
11
+ /** Characters of a username. */
12
+ readonly usernameChars: 64;
13
+ };
14
+ /**
15
+ * The basic-auth usernames of well-known git hosts: a GitHub token (a PAT or an app installation
16
+ * token) is presented with the fixed username `x-access-token`. Documentation for template authors;
17
+ * a connector still states its username explicitly.
18
+ */
19
+ export declare const GIT_HOST_USERNAMES: {
20
+ readonly "github.com": "x-access-token";
21
+ readonly "*.ghe.com": "x-access-token";
22
+ };
23
+ /** A valid HTTP basic username: `^[A-Za-z0-9._-]{1,64}$`. */
24
+ export declare const GIT_USERNAME_RE: RegExp;
25
+ /** The username a git marketplace credential is presented with when none is stored. */
26
+ export declare const GIT_MARKETPLACE_USERNAME_DEFAULT = "x-access-token";
27
+ /**
28
+ * A hint for forms: the basic username well-known git hosts document for a token. Other hosts
29
+ * return `undefined`; the user enters the username the host's documentation names.
30
+ */
31
+ export declare function suggestGitUsername(host: string): string | undefined;
32
+ /** One git host and the username its credential is presented with. */
33
+ export interface GitHostEntry {
34
+ /** Lower-case hostname with no scheme, port, path, wildcard or userinfo. */
35
+ host: string;
36
+ /** HTTP basic username, `^[A-Za-z0-9._-]{1,64}$`. */
37
+ username: string;
38
+ }
39
+ /** The git source of a connector (`git` on a connector template and on a custom connector). */
40
+ export interface GitSource {
41
+ hosts: GitHostEntry[];
42
+ }
43
+ /**
44
+ * The zod schema of {@link GitSource} (strict objects, 1 to {@link GIT_HOSTS_LIMITS}`.hosts` hosts,
45
+ * no duplicate host). Error messages never echo the offending value.
46
+ */
47
+ export declare const GitSourceSchema: z.ZodType<GitSource>;
48
+ /** Validates a `git` value; returns problems as `<path>: <message>` (empty means valid). */
49
+ export declare function validateGitSource(git: unknown, at?: string): string[];
50
+ /** Parses a `git` value: the value, or `{ errors }`. */
51
+ export declare function parseGitSource(git: unknown): GitSource | {
52
+ errors: string[];
53
+ };
@@ -0,0 +1,98 @@
1
+ import { z } from "zod";
2
+ import { validateAllowHost } from "./device-provider.js";
3
+ /**
4
+ * The git source of a connector: the git hosts a connector's credential may be used for, and the
5
+ * HTTP basic username to present for each (spec 2026-11-12-sandbox-git-credentials §6.1). Pure
6
+ * validation; the kernel reuses {@link GitSourceSchema} for its connector create body.
7
+ */
8
+ /** Limits of {@link GitSourceSchema}. */
9
+ export const GIT_HOSTS_LIMITS = {
10
+ /** Hosts per connector. */
11
+ hosts: 8,
12
+ /** Characters of a username. */
13
+ usernameChars: 64,
14
+ };
15
+ /**
16
+ * The basic-auth usernames of well-known git hosts: a GitHub token (a PAT or an app installation
17
+ * token) is presented with the fixed username `x-access-token`. Documentation for template authors;
18
+ * a connector still states its username explicitly.
19
+ */
20
+ export const GIT_HOST_USERNAMES = {
21
+ "github.com": "x-access-token",
22
+ "*.ghe.com": "x-access-token",
23
+ };
24
+ /** A valid HTTP basic username: `^[A-Za-z0-9._-]{1,64}$`. */
25
+ export const GIT_USERNAME_RE = /^[A-Za-z0-9._-]{1,64}$/;
26
+ /** The username a git marketplace credential is presented with when none is stored. */
27
+ export const GIT_MARKETPLACE_USERNAME_DEFAULT = "x-access-token";
28
+ /**
29
+ * A hint for forms: the basic username well-known git hosts document for a token. Other hosts
30
+ * return `undefined`; the user enters the username the host's documentation names.
31
+ */
32
+ export function suggestGitUsername(host) {
33
+ const h = host.toLowerCase();
34
+ if (h === "github.com" || h.endsWith(".ghe.com"))
35
+ return GIT_MARKETPLACE_USERNAME_DEFAULT;
36
+ if (h === "bitbucket.org")
37
+ return "x-token-auth";
38
+ if (h === "gitlab.com")
39
+ return "oauth2";
40
+ return undefined;
41
+ }
42
+ /** Why a host is refused; never echoes the value (it may be a pasted credential or URL). */
43
+ function hostProblems(h) {
44
+ if (/[@:/?#\s]/.test(h))
45
+ return ["host must be a bare hostname (no userinfo, port or path)"];
46
+ if (h.includes("*"))
47
+ return ["host must not contain a wildcard"];
48
+ if (h !== h.toLowerCase())
49
+ return ["host must be lower-case"];
50
+ return validateAllowHost(h);
51
+ }
52
+ const GitHostEntrySchema = z.strictObject({
53
+ host: z
54
+ .string()
55
+ .max(253, "host must be at most 253 characters")
56
+ .superRefine((h, ctx) => {
57
+ for (const message of hostProblems(h))
58
+ ctx.addIssue({ code: "custom", message });
59
+ }),
60
+ username: z
61
+ .string()
62
+ .regex(GIT_USERNAME_RE, "username must match ^[A-Za-z0-9._-]{1,64}$ (letters, digits, '.', '_', '-')"),
63
+ });
64
+ /**
65
+ * The zod schema of {@link GitSource} (strict objects, 1 to {@link GIT_HOSTS_LIMITS}`.hosts` hosts,
66
+ * no duplicate host). Error messages never echo the offending value.
67
+ */
68
+ export const GitSourceSchema = z
69
+ .strictObject({
70
+ hosts: z
71
+ .array(GitHostEntrySchema)
72
+ .min(1, "hosts must not be empty")
73
+ .max(GIT_HOSTS_LIMITS.hosts),
74
+ })
75
+ .superRefine((g, ctx) => {
76
+ const seen = new Set();
77
+ g.hosts.forEach((e, i) => {
78
+ if (seen.has(e.host)) {
79
+ ctx.addIssue({ code: "custom", path: ["hosts", i, "host"], message: "duplicate host" });
80
+ }
81
+ seen.add(e.host);
82
+ });
83
+ });
84
+ /** Validates a `git` value; returns problems as `<path>: <message>` (empty means valid). */
85
+ export function validateGitSource(git, at = "git") {
86
+ const r = GitSourceSchema.safeParse(git);
87
+ if (r.success)
88
+ return [];
89
+ return r.error.issues.map((i) => {
90
+ const path = i.path.map(String).join(".");
91
+ return `${path === "" ? at : `${at}.${path}`}: ${i.message}`;
92
+ });
93
+ }
94
+ /** Parses a `git` value: the value, or `{ errors }`. */
95
+ export function parseGitSource(git) {
96
+ const errors = validateGitSource(git);
97
+ return errors.length > 0 ? { errors } : GitSourceSchema.parse(git);
98
+ }