@capybara-hq/plugin-sdk 0.1.0-rc.8 → 0.1.0-rc.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/agent-docs/agent-templates.md +14 -2
- package/agent-docs/concepts.md +14 -5
- package/agent-docs/connector-templates.md +11 -3
- package/agent-docs/extension-points/channel.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/device-provider.md +15 -0
- package/agent-docs/extension-points/file-preview.md +3 -1
- package/agent-docs/extension-points/identity-source.md +2 -0
- package/agent-docs/extension-points/model-provider.md +3 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- package/agent-docs/extension-points/push-provider.md +17 -0
- package/agent-docs/extensions.md +77 -4
- package/agent-docs/plugin-format.md +45 -10
- package/agent-docs/setup.md +54 -0
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/avatar-presets.d.ts +8 -0
- package/dist/avatar-presets.js +17 -0
- package/dist/bootstrap.d.ts +109 -1
- package/dist/bootstrap.js +185 -2
- package/dist/cards.d.ts +97 -13
- package/dist/cards.js +121 -19
- package/dist/channel.d.ts +133 -47
- package/dist/channel.js +10 -5
- package/dist/client-css.d.ts +36 -0
- package/dist/client-css.js +326 -0
- package/dist/client-section.d.ts +35 -0
- package/dist/client-section.js +133 -0
- package/dist/config-ui.d.ts +28 -6
- package/dist/config-ui.js +88 -25
- package/dist/config-url-fetch.d.ts +19 -0
- package/dist/config-url-fetch.js +43 -0
- package/dist/connector-auth.d.ts +13 -2
- package/dist/connector-auth.js +82 -8
- package/dist/connector.d.ts +74 -32
- package/dist/context.d.ts +40 -0
- package/dist/context.js +2 -0
- package/dist/ctx.d.ts +224 -30
- package/dist/ctx.js +9 -1
- package/dist/define-extension.d.ts +23 -13
- package/dist/define-extension.js +19 -5
- package/dist/device-denied-paths.d.ts +20 -0
- package/dist/device-denied-paths.js +118 -0
- package/dist/device-operation.d.ts +339 -0
- package/dist/device-operation.js +312 -0
- package/dist/device-protocol.d.ts +285 -50
- package/dist/device-protocol.js +755 -90
- package/dist/device-provider.d.ts +780 -0
- package/dist/device-provider.js +409 -0
- package/dist/device-service.d.ts +126 -0
- package/dist/device-service.js +211 -0
- package/dist/dial-in.d.ts +286 -0
- package/dist/dial-in.js +213 -0
- package/dist/directory.d.ts +15 -12
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +7 -3
- package/dist/field-meta.d.ts +19 -0
- package/dist/field-meta.js +54 -0
- package/dist/file-preview.d.ts +43 -10
- package/dist/git-hosts.d.ts +53 -0
- package/dist/git-hosts.js +98 -0
- package/dist/hooks.d.ts +125 -20
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +71 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +70 -9
- package/dist/identity.js +46 -1
- package/dist/index.d.ts +28 -4
- package/dist/index.js +28 -4
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +227 -75
- package/dist/model.js +152 -19
- package/dist/native-failure.d.ts +13 -0
- package/dist/native-failure.js +31 -0
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/network-classes.d.ts +98 -0
- package/dist/network-classes.js +291 -0
- package/dist/permissions.d.ts +65 -22
- package/dist/permissions.js +139 -43
- package/dist/platform-only.d.ts +27 -0
- package/dist/platform-only.js +35 -0
- package/dist/plugin-manifest.d.ts +30 -6
- package/dist/plugin-manifest.js +147 -55
- package/dist/plugin-package.d.ts +82 -39
- package/dist/plugin-package.js +68 -41
- package/dist/push.d.ts +75 -0
- package/dist/push.js +87 -0
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +2343 -0
- package/dist/sandbox-native-runtime-source.d.ts +10 -0
- package/dist/sandbox-native-runtime-source.js +480 -0
- package/dist/sandbox-runtime-source.d.ts +47 -0
- package/dist/sandbox-runtime-source.js +73 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/secret.d.ts +8 -2
- package/dist/secret.js +11 -4
- package/dist/setup-check.d.ts +128 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +356 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +86 -72
- package/dist/setup-guide.js +340 -108
- package/dist/shell-capabilities.d.ts +211 -0
- package/dist/shell-capabilities.js +44 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +21 -0
- package/dist/skill-invocation.d.ts +5 -0
- package/dist/skill-invocation.js +4 -3
- package/dist/skill.d.ts +27 -17
- package/dist/skill.js +40 -26
- package/dist/storage.d.ts +52 -25
- package/dist/svg-viewbox.d.ts +10 -0
- package/dist/svg-viewbox.js +24 -0
- package/dist/theme-assets.d.ts +25 -9
- package/dist/theme-assets.js +87 -47
- package/dist/theme-tokens.generated.d.ts +26 -2
- package/dist/theme-tokens.generated.js +17 -0
- package/dist/theme.d.ts +48 -10
- package/dist/theme.js +100 -21
- package/dist/tool.d.ts +196 -31
- package/dist/tool.js +133 -13
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +385 -0
- package/dist/ui-resolve.d.ts +35 -0
- package/dist/ui-resolve.js +42 -0
- package/dist/ui-slots.d.ts +65 -0
- package/dist/ui-slots.js +261 -0
- package/dist/ui.d.ts +245 -77
- package/dist/ui.js +104 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/dist/web.d.ts +26 -20
- package/package.json +12 -1
- package/schemas/bootstrap-extra.v1.schema.json +186 -0
- package/schemas/bootstrap.v1.schema.json +20 -0
- package/schemas/connector-template.v1.schema.json +62 -4
- package/schemas/plugin.v1.schema.json +74 -143
- package/schemas/theme.v1.schema.json +77 -0
- package/agent-docs/extension-points/sandbox.md +0 -15
- package/dist/org-access.d.ts +0 -27
- package/dist/org-access.js +0 -35
- package/dist/sandbox.d.ts +0 -254
- package/dist/sandbox.js +0 -153
package/dist/ctx.d.ts
CHANGED
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
import type { Kysely } from "kysely";
|
|
2
|
+
import type { DeviceServiceSpec, DeviceServiceStatus, ServiceBlockedHost } from "./device-provider.js";
|
|
3
|
+
import type { DevicesCtx, DialInChannel } from "./dial-in.js";
|
|
2
4
|
import type { ExtensionPointRef } from "./extension-point.js";
|
|
3
5
|
import type { AvailableHook, HookHandler, HookOptions } from "./hooks.js";
|
|
4
|
-
import type {
|
|
6
|
+
import type { RouteCaller } from "./http-access.js";
|
|
7
|
+
import type { ImageAspectRatio, ImageMediaType, ImageSize, ModelEmbeddingInfo, ModelImageGenerationInfo, ModelKind } from "./model.js";
|
|
8
|
+
import type { ExtensionNet } from "./net.js";
|
|
9
|
+
import type { SetupCheckDefinition } from "./setup-check.js";
|
|
5
10
|
import type { ObjectHead, PresignedUpload, PresignGetOptions } from "./storage.js";
|
|
6
|
-
import type { ToolHandler, ToolSpec } from "./tool.js";
|
|
11
|
+
import type { ToolCallContext, ToolHandler, ToolSpec } from "./tool.js";
|
|
7
12
|
import type { EmbedClaims, UiActionArgs, UiActionResult, UiRenderArgs, UiView } from "./ui.js";
|
|
8
|
-
/**
|
|
13
|
+
/** Logger interface. */
|
|
9
14
|
export interface Logger {
|
|
10
15
|
info(msg: string, fields?: Record<string, unknown>): void;
|
|
11
16
|
warn(msg: string, fields?: Record<string, unknown>): void;
|
|
12
17
|
error(msg: string, fields?: Record<string, unknown>): void;
|
|
13
18
|
}
|
|
14
|
-
/**
|
|
19
|
+
/** Distributed lock lease. */
|
|
15
20
|
export interface Lease {
|
|
16
21
|
renew(): Promise<boolean>;
|
|
17
22
|
release(): Promise<void>;
|
|
18
23
|
}
|
|
19
24
|
/**
|
|
20
|
-
*
|
|
21
|
-
* `
|
|
22
|
-
*
|
|
25
|
+
* The plugin's object storage (`ctx.storage`, needs `permissions.storage`): the same shape as
|
|
26
|
+
* `ObjectStore`, but the first parameter of every method is
|
|
27
|
+
* `orgId`, and the kernel adds `plugins/<plugin name>/<orgId>/` to keys and prefixes automatically:
|
|
28
|
+
* a plugin sees only its own objects under that org.
|
|
29
|
+
* The backing store is the deployment-configured `object-store@1` provider; every method throws
|
|
30
|
+
* when there is no provider.
|
|
23
31
|
*/
|
|
24
32
|
export interface ExtensionStorage {
|
|
25
33
|
put(orgId: string, key: string, body: Uint8Array | ReadableStream<Uint8Array>, opts: {
|
|
@@ -28,8 +36,10 @@ export interface ExtensionStorage {
|
|
|
28
36
|
signal?: AbortSignal;
|
|
29
37
|
}): Promise<ObjectHead>;
|
|
30
38
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
39
|
+
* Returns null when missing. `range` is a closed byte range; an omitted `end` means read to the
|
|
40
|
+
* end.
|
|
41
|
+
* With `range`, `head.size` is still the size of the whole object; when the store ignores Range,
|
|
42
|
+
* body may be the whole object.
|
|
33
43
|
*/
|
|
34
44
|
get(orgId: string, key: string, opts?: {
|
|
35
45
|
signal?: AbortSignal;
|
|
@@ -42,7 +52,7 @@ export interface ExtensionStorage {
|
|
|
42
52
|
body: ReadableStream<Uint8Array>;
|
|
43
53
|
} | null>;
|
|
44
54
|
head(orgId: string, key: string): Promise<ObjectHead | null>;
|
|
45
|
-
/**
|
|
55
|
+
/** A missing key also counts as success. */
|
|
46
56
|
delete(orgId: string, key: string): Promise<void>;
|
|
47
57
|
deletePrefix(orgId: string, prefix: string): Promise<number>;
|
|
48
58
|
list(orgId: string, prefix: string, opts?: {
|
|
@@ -86,6 +96,39 @@ export interface ExtensionEmbedResult {
|
|
|
86
96
|
};
|
|
87
97
|
dimensions: number;
|
|
88
98
|
}
|
|
99
|
+
/** A `ctx.models.generateImage` request: images generated for one org with the model of a purpose. */
|
|
100
|
+
export interface ExtensionImageGenerateRequest {
|
|
101
|
+
orgId: string;
|
|
102
|
+
/** A purpose this extension declared in `permissions.models` with `kind: "image_generation"`. */
|
|
103
|
+
purpose: string;
|
|
104
|
+
prompt: string;
|
|
105
|
+
/** An exact size the model offers; rejected otherwise. Wins over `aspectRatio`. */
|
|
106
|
+
size?: ImageSize;
|
|
107
|
+
/** The closest size the model offers; the model's default size when neither is given. */
|
|
108
|
+
aspectRatio?: ImageAspectRatio;
|
|
109
|
+
/** Images to produce (default 1, at most the model's `maxImages`). */
|
|
110
|
+
n?: number;
|
|
111
|
+
/** Base64 reference images, at most the model's `maxReferenceImages`. */
|
|
112
|
+
referenceImages?: {
|
|
113
|
+
mediaType: ImageMediaType;
|
|
114
|
+
data: string;
|
|
115
|
+
}[];
|
|
116
|
+
/** Aborts this call; combined with `ctx.signal`. */
|
|
117
|
+
signal?: AbortSignal;
|
|
118
|
+
}
|
|
119
|
+
/** A `ctx.models.generateImage` result. */
|
|
120
|
+
export interface ExtensionImageGenerateResult {
|
|
121
|
+
images: {
|
|
122
|
+
mediaType: ImageMediaType;
|
|
123
|
+
data: string;
|
|
124
|
+
}[];
|
|
125
|
+
revisedPrompt?: string;
|
|
126
|
+
model: {
|
|
127
|
+
provider: string;
|
|
128
|
+
id: string;
|
|
129
|
+
};
|
|
130
|
+
size: ImageSize;
|
|
131
|
+
}
|
|
89
132
|
/** The model a purpose maps to in an org (`ctx.models.describe`). */
|
|
90
133
|
export interface ExtensionModelTarget {
|
|
91
134
|
provider: string;
|
|
@@ -93,13 +136,16 @@ export interface ExtensionModelTarget {
|
|
|
93
136
|
kind: ModelKind;
|
|
94
137
|
/** Present for an embedding model. */
|
|
95
138
|
embedding?: ModelEmbeddingInfo;
|
|
139
|
+
/** Present for an image generation model. */
|
|
140
|
+
imageGeneration?: ModelImageGenerationInfo;
|
|
96
141
|
}
|
|
97
142
|
/**
|
|
98
143
|
* Models by purpose (`permissions.models`): the purpose → model mapping is chosen by org admins
|
|
99
144
|
* (and the deployment default by the super admin), never by the extension. Only purposes this
|
|
100
|
-
* extension declared with `kind
|
|
145
|
+
* extension declared with a matching `kind` (`embedding` for `embed`, `image_generation` for
|
|
146
|
+
* `generateImage`) are accepted (`model.purpose_unknown` otherwise), and
|
|
101
147
|
* only for an org that enabled the extension (`extension.not_enabled`). Usage is recorded by the
|
|
102
|
-
* kernel and reported through `usage.report` (purpose `embedding`).
|
|
148
|
+
* kernel and reported through `usage.report` (purpose `embedding`, or `image` for `generateImage`).
|
|
103
149
|
*/
|
|
104
150
|
export interface ExtensionModels {
|
|
105
151
|
/**
|
|
@@ -112,13 +158,109 @@ export interface ExtensionModels {
|
|
|
112
158
|
* extension route), and nothing is sent or billed.
|
|
113
159
|
*/
|
|
114
160
|
embed(req: ExtensionEmbedRequest): Promise<ExtensionEmbedResult>;
|
|
161
|
+
/**
|
|
162
|
+
* Generates images with the org's effective model for `purpose`. Rejects with
|
|
163
|
+
* `model.unconfigured` when the purpose maps to no usable model, `validation_failed` for a size,
|
|
164
|
+
* count or reference count the model does not offer, and a `ModelError` when the provider fails
|
|
165
|
+
* (kind `refusal` when it declines the prompt). Not retried. Fires `model.request` first
|
|
166
|
+
* (`purpose: "image"`); a policy denial rejects with `model.hook_denied`.
|
|
167
|
+
*/
|
|
168
|
+
generateImage(req: ExtensionImageGenerateRequest): Promise<ExtensionImageGenerateResult>;
|
|
115
169
|
/** The org's effective model for `purpose`, or null when it maps to no model the org can use. */
|
|
116
170
|
describe(req: {
|
|
117
171
|
orgId: string;
|
|
118
172
|
purpose: string;
|
|
119
173
|
}): Promise<ExtensionModelTarget | null>;
|
|
120
174
|
}
|
|
121
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* The org, conversation and account a {@link DeviceAccessCtx} call from outside a tool call is for
|
|
177
|
+
* (`orgId` must be the conversation's org).
|
|
178
|
+
*/
|
|
179
|
+
export type DeviceAccessScope = {
|
|
180
|
+
orgId: string;
|
|
181
|
+
conversationId: string;
|
|
182
|
+
accountId: string;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* `ctx.deviceAccess` (requires `permissions.deviceAccess`): the extension's services in the
|
|
186
|
+
* conversation's device. Every call works on the device of the conversation it names (a tool
|
|
187
|
+
* call's, or `scope.conversationId`), only for a service listed in
|
|
188
|
+
* `permissions.deviceAccess.services`, and only when the account (the tool call's trigger account,
|
|
189
|
+
* or `scope.accountId`) is the conversation's owner. A refusal throws {@link DeviceAccessError}.
|
|
190
|
+
*/
|
|
191
|
+
export interface DeviceAccessCtx {
|
|
192
|
+
/**
|
|
193
|
+
* Starts the service in the call's device, or finds it running: the kernel writes the spec's
|
|
194
|
+
* files into the service's state directory, passes the launch through the command review (fail
|
|
195
|
+
* closed) and starts it through the device's provider.
|
|
196
|
+
*/
|
|
197
|
+
ensureService(call: ToolCallContext, spec: DeviceServiceSpec): Promise<DeviceServiceStatus>;
|
|
198
|
+
/** One request to the service's socket; resolves its answer. */
|
|
199
|
+
request(call: ToolCallContext, req: {
|
|
200
|
+
service: string;
|
|
201
|
+
body: Uint8Array;
|
|
202
|
+
timeoutMs: number;
|
|
203
|
+
}): Promise<Uint8Array>;
|
|
204
|
+
/**
|
|
205
|
+
* The service saw requests to `hosts` refused by the device's network during this call, each
|
|
206
|
+
* with the layer that refused it (`sandboxProxyRefusalLayer` reads it from the device's
|
|
207
|
+
* proxy): once the handler returns, the kernel raises the network ask in the call's
|
|
208
|
+
* conversation for `device` hosts it can offer (and runs the call again once the person
|
|
209
|
+
* approves), and writes a note for the others (an `address` host: a private or local address,
|
|
210
|
+
* which no host grant reaches). Only an ask: a layer never widens access, and the kernel's own
|
|
211
|
+
* planning still applies (a host the device list cannot take is never asked about; an IP
|
|
212
|
+
* literal is always `address`). A host reported twice keeps its most restrictive layer.
|
|
213
|
+
* `opts.url` is the page the refusals came from, shown with the ask.
|
|
214
|
+
*/
|
|
215
|
+
reportBlockedHosts(call: ToolCallContext, hosts: ServiceBlockedHost[], opts?: {
|
|
216
|
+
url?: string;
|
|
217
|
+
}): void;
|
|
218
|
+
/**
|
|
219
|
+
* A short-lived, single-use ticket for one viewer stream to the service (the person's panel
|
|
220
|
+
* opens `url` as a WebSocket). The account must be the conversation's owner.
|
|
221
|
+
*/
|
|
222
|
+
streamTicket(scope: DeviceAccessScope & {
|
|
223
|
+
service: string;
|
|
224
|
+
}): Promise<{
|
|
225
|
+
url: string;
|
|
226
|
+
expiresAt: string;
|
|
227
|
+
}>;
|
|
228
|
+
/**
|
|
229
|
+
* Adds hosts to the device's network allowlist (owner only, platform and org ceilings apply);
|
|
230
|
+
* the extension's running services get the device's new limits applied. Exact host names
|
|
231
|
+
* only, as an approved network ask grants: a `*.` wildcard is refused.
|
|
232
|
+
*/
|
|
233
|
+
addNetworkHosts(scope: DeviceAccessScope & {
|
|
234
|
+
hosts: string[];
|
|
235
|
+
}): Promise<void>;
|
|
236
|
+
/**
|
|
237
|
+
* Answers the handoff question of this extension's tool call `callId` from the panel.
|
|
238
|
+
* `handoffConversationId` is the conversation whose tool call raised the handoff (the extension
|
|
239
|
+
* learns it from `ToolCallContext.conversationId`; the panel may echo it back, so it is
|
|
240
|
+
* untrusted input): the kernel answers only when it is the scope conversation or one of its
|
|
241
|
+
* sub-agent descendants (a call id is unique only within a run, so two sub-agents of one tree
|
|
242
|
+
* can wait under the same one). Any other conversation, like a question that is not pending or
|
|
243
|
+
* not this extension's, refuses with `question.not_found`.
|
|
244
|
+
*/
|
|
245
|
+
answerHandoff(scope: DeviceAccessScope & {
|
|
246
|
+
callId: string;
|
|
247
|
+
handoffConversationId: string;
|
|
248
|
+
done: boolean;
|
|
249
|
+
}): Promise<void>;
|
|
250
|
+
}
|
|
251
|
+
/** Why a {@link DeviceAccessCtx} call was refused. */
|
|
252
|
+
export type DeviceAccessErrorCode = "no_device" | "provider_unavailable" | "capability_missing" | "not_owner" | "service_not_declared";
|
|
253
|
+
/** A {@link DeviceAccessCtx} call was refused; the message is actionable English for the model. */
|
|
254
|
+
export declare class DeviceAccessError extends Error {
|
|
255
|
+
readonly code: DeviceAccessErrorCode;
|
|
256
|
+
constructor(code: DeviceAccessErrorCode, message: string, opts?: {
|
|
257
|
+
cause?: unknown;
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* The context passed to a plugin's `setup`. It provides no timers or in-process shared state; kv
|
|
262
|
+
* writes must carry a TTL.
|
|
263
|
+
*/
|
|
122
264
|
export interface ExtensionContext {
|
|
123
265
|
kv: {
|
|
124
266
|
get(key: string): Promise<string | null>;
|
|
@@ -152,18 +294,27 @@ export interface ExtensionContext {
|
|
|
152
294
|
get(orgId: string, key: string): Promise<string | null>;
|
|
153
295
|
set(orgId: string, key: string, value: string): Promise<void>;
|
|
154
296
|
};
|
|
155
|
-
/**
|
|
297
|
+
/** Object storage (needs `permissions.storage`, see {@link ExtensionStorage}). */
|
|
156
298
|
storage: ExtensionStorage;
|
|
157
299
|
/** Models by purpose (requires `permissions.models`, see {@link ExtensionModels}). */
|
|
158
300
|
models: ExtensionModels;
|
|
159
|
-
/**
|
|
301
|
+
/**
|
|
302
|
+
* Guarded HTTP for URLs a person supplied (see {@link ExtensionNet}): a connector endpoint or an
|
|
303
|
+
* org-overridable base URL goes through `ctx.net.fetch`, never the global `fetch`.
|
|
304
|
+
*/
|
|
305
|
+
net: ExtensionNet;
|
|
306
|
+
/** A Kysely instance already switched to this plugin's schema (withSchema). */
|
|
160
307
|
db: Kysely<any>;
|
|
161
308
|
http: {
|
|
162
|
-
/**
|
|
163
|
-
|
|
309
|
+
/**
|
|
310
|
+
* Mounted at `/plugins/<name><path>` (`public`, `embed`) or `/plugins/<name>/orgs/:orgId<path>`
|
|
311
|
+
* (`member`, `admin`), as `permissions.http` declares. The kernel enforces the access before
|
|
312
|
+
* the handler runs and passes the resolved caller; trust only `caller`.
|
|
313
|
+
*/
|
|
314
|
+
route(method: "GET" | "POST" | "PUT" | "DELETE", path: string, handler: (req: Request, caller: RouteCaller) => Promise<Response>): void;
|
|
164
315
|
};
|
|
165
316
|
tools: {
|
|
166
|
-
/**
|
|
317
|
+
/** Registers a tool; callable only during `setup`, names must not repeat. */
|
|
167
318
|
register(spec: ToolSpec, handler: ToolHandler): void;
|
|
168
319
|
};
|
|
169
320
|
/**
|
|
@@ -195,23 +346,45 @@ export interface ExtensionContext {
|
|
|
195
346
|
}[]>;
|
|
196
347
|
};
|
|
197
348
|
/**
|
|
198
|
-
*
|
|
199
|
-
* - `view` / `action
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
349
|
+
* Runtime of UI contributions (manifest `ui` + `permissions.ui`):
|
|
350
|
+
* - `view` / `action`: can be registered only during `setup`; the id is the contribution id of
|
|
351
|
+
* the kind-view entry in the manifest;
|
|
352
|
+
* `action` receives a button click or form submission from the view (`args.actionId` tells
|
|
353
|
+
* which one);
|
|
354
|
+
* - `invalidate`: tells the kernel "this contribution changed", and the web pages that have it
|
|
355
|
+
* open fetch the view again (via the bus, across replicas); a
|
|
356
|
+
* `platform.page` contribution takes no `orgId` (it refreshes the admin console), every other
|
|
357
|
+
* contribution requires one;
|
|
358
|
+
* - `verifyEmbedToken`: validates the embed token an embed page received; it accepts only
|
|
359
|
+
* tokens signed for this plugin and not expired, while the plugin is still enabled in that org,
|
|
360
|
+
* the caller is still an active member and the role still satisfies the slot's minRole,
|
|
361
|
+
* otherwise it returns null; the returned `role` is the role at this moment. A
|
|
362
|
+
* platform-scope token (`scope: "platform"`, no `orgId`) verifies only for a `platform.page`
|
|
363
|
+
* contribution while the account is still an active super admin.
|
|
204
364
|
*/
|
|
205
365
|
ui: {
|
|
206
366
|
view(id: string, render: (args: UiRenderArgs) => Promise<UiView>): void;
|
|
207
367
|
action(id: string, handler: (args: UiActionArgs) => Promise<UiActionResult>): void;
|
|
208
368
|
invalidate(target: {
|
|
209
|
-
|
|
369
|
+
/** Required, except for a `platform.page` contribution, where it must be omitted. */
|
|
370
|
+
orgId?: string;
|
|
210
371
|
conversationId?: string;
|
|
211
372
|
contribution: string;
|
|
212
373
|
}): Promise<void>;
|
|
213
374
|
verifyEmbedToken(token: string): Promise<EmbedClaims | null>;
|
|
214
375
|
};
|
|
376
|
+
/**
|
|
377
|
+
* Setup checks (`permissions.setupChecks`): the live rows of the plugin's setup guides.
|
|
378
|
+
* `check` is only allowed during `setup`; `id` must be listed in `permissions.setupChecks`
|
|
379
|
+
* (else `ExtensionPermissionError`); registering an id twice throws. The kernel runs a check only
|
|
380
|
+
* when a person or an agent asks, only for targets of this plugin and of `def.place`, aborts
|
|
381
|
+
* `signal` after `SETUP_CHECK_LIMITS.timeoutMs`, and redacts and bounds the result. A check never
|
|
382
|
+
* writes, passes `signal` to every request, does not retry and never puts a secret in `reason`
|
|
383
|
+
* or `fix`. It never receives an OAuth client secret or a member's token.
|
|
384
|
+
*/
|
|
385
|
+
setup: {
|
|
386
|
+
check(id: string, def: SetupCheckDefinition): void;
|
|
387
|
+
};
|
|
215
388
|
/**
|
|
216
389
|
* Hooks (`permissions.hooks`): observe model and tool calls, or deny them with a policy hook.
|
|
217
390
|
* `on` is only allowed during `setup`; the mount point must be declared in `permissions.hooks` and be
|
|
@@ -224,16 +397,37 @@ export interface ExtensionContext {
|
|
|
224
397
|
hooks: {
|
|
225
398
|
on<K extends AvailableHook>(mount: K, handler: HookHandler<K>, opts: HookOptions): void;
|
|
226
399
|
};
|
|
400
|
+
/**
|
|
401
|
+
* The dial-in channel to the machines serving this extension's devices (requires
|
|
402
|
+
* `permissions.dialIn`, see {@link DialInChannel}): every call is refused for a device another
|
|
403
|
+
* extension serves.
|
|
404
|
+
*/
|
|
405
|
+
dialIn: DialInChannel;
|
|
406
|
+
/**
|
|
407
|
+
* Tells the kernel about this extension's devices (requires `provides` to include
|
|
408
|
+
* `device-provider@1`, see {@link DevicesCtx}).
|
|
409
|
+
*/
|
|
410
|
+
devices: DevicesCtx;
|
|
411
|
+
/**
|
|
412
|
+
* The extension's services in the conversation's device (requires `permissions.deviceAccess`,
|
|
413
|
+
* see {@link DeviceAccessCtx}).
|
|
414
|
+
*/
|
|
415
|
+
deviceAccess: DeviceAccessCtx;
|
|
227
416
|
provide(extensionPoint: ExtensionPointRef, impl: unknown): void;
|
|
228
417
|
/**
|
|
229
|
-
*
|
|
230
|
-
*
|
|
418
|
+
* The lifecycle signal of this plugin instance: aborted when the instance is revoked (disabled,
|
|
419
|
+
* uninstalled, upgraded), after in-flight calls have drained.
|
|
420
|
+
* Long-running tasks the plugin started itself (polling loops, long connections, etc.) wind down
|
|
421
|
+
* on it.
|
|
231
422
|
*/
|
|
232
423
|
signal: AbortSignal;
|
|
233
424
|
/**
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
425
|
+
* Deployment-level config, validated against the plugin schema (the startup config merged with
|
|
426
|
+
* values the super admin saved in the console). This is a getter:
|
|
427
|
+
* when a field marked `hot` (`.meta({ hot: true })`) changes, the kernel replaces it in place, so
|
|
428
|
+
* the plugin must read `ctx.config` **at the time of use** to get the new value;
|
|
429
|
+
* do not copy hot fields into a closure in setup; when a non-hot field changes the kernel reloads
|
|
430
|
+
* the plugin instance (a new setup).
|
|
237
431
|
*/
|
|
238
432
|
readonly config: unknown;
|
|
239
433
|
log: Logger;
|
package/dist/ctx.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/** A {@link DeviceAccessCtx} call was refused; the message is actionable English for the model. */
|
|
2
|
+
export class DeviceAccessError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message, opts) {
|
|
5
|
+
super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
|
|
6
|
+
this.name = "DeviceAccessError";
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -3,39 +3,49 @@ import type { ExtensionContext } from "./ctx.js";
|
|
|
3
3
|
import { type ExtensionPointRef } from "./extension-point.js";
|
|
4
4
|
import { type ExtensionPermissions } from "./permissions.js";
|
|
5
5
|
import type { UiContribution } from "./ui.js";
|
|
6
|
-
/**
|
|
6
|
+
/** The plugin manifest. */
|
|
7
7
|
export interface ExtensionManifest {
|
|
8
8
|
name: string;
|
|
9
9
|
version: string;
|
|
10
10
|
sdk: string;
|
|
11
11
|
provides: ExtensionPointRef[];
|
|
12
12
|
requires?: ExtensionPointRef[];
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Optional dependencies: when missing the plugin still loads, and decides at runtime through
|
|
15
|
+
* ctx.extensionPoints.
|
|
16
|
+
*/
|
|
14
17
|
optional?: ExtensionPointRef[];
|
|
15
|
-
/**
|
|
18
|
+
/** Permission manifest (governance, not a sandbox). */
|
|
16
19
|
permissions?: ExtensionPermissions;
|
|
17
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* UI contributions, each in a slot of `UI_SLOTS`; every id is also listed in `permissions.ui`.
|
|
22
|
+
* Kept exactly as written: structural problems fail the extension, while a contribution to an
|
|
23
|
+
* unknown slot or version is only dropped when the host resolves the slots (`resolveUiSlots`).
|
|
24
|
+
*/
|
|
18
25
|
ui?: UiContribution[];
|
|
19
26
|
config?: {
|
|
20
27
|
deployment?: z.ZodTypeAny;
|
|
21
|
-
org?: z.ZodTypeAny;
|
|
22
28
|
};
|
|
23
29
|
migrations?: string;
|
|
24
30
|
setup(ctx: ExtensionContext): void | Promise<void>;
|
|
25
31
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
32
|
+
* Optional: called when the plugin instance is revoked (disabled, uninstalled, replaced by a new
|
|
33
|
+
* instance on upgrade, a dependent reloaded together with its provider).
|
|
34
|
+
* By then the kernel has already: stopped accepting new calls, waited for in-flight calls to
|
|
35
|
+
* finish (at most `extensionHost.drainSeconds`), aborted `ctx.signal`,
|
|
36
|
+
* and revoked every registration this instance made through ctx (tools, routes, queue workers,
|
|
37
|
+
* bus subscriptions, lock leases, UI, provide).
|
|
38
|
+
* Clean up here only what the plugin opened outside ctx (e.g. its own connections); do not
|
|
39
|
+
* register anything through ctx again.
|
|
40
|
+
* Not called when setup throws (the kernel revokes what was already registered).
|
|
31
41
|
*/
|
|
32
42
|
dispose?(ctx: ExtensionContext): void | Promise<void>;
|
|
33
43
|
}
|
|
34
|
-
/**
|
|
44
|
+
/** The plugin manifest is invalid. */
|
|
35
45
|
export declare class ExtensionManifestError extends Error {
|
|
36
46
|
constructor(plugin: string, message: string);
|
|
37
47
|
}
|
|
38
|
-
/**
|
|
48
|
+
/** Plugin name rule (manifest `name`; a connector template's `plugin` is validated by it too). */
|
|
39
49
|
export declare const EXTENSION_NAME_RE: RegExp;
|
|
40
|
-
/**
|
|
50
|
+
/** Validates the plugin manifest and returns it unchanged; throws ExtensionManifestError when invalid. */
|
|
41
51
|
export declare function defineExtension(m: ExtensionManifest): ExtensionManifest;
|
package/dist/define-extension.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import semver from "semver";
|
|
2
2
|
import { EXTENSION_POINTS, parseExtensionPoint, } from "./extension-point.js";
|
|
3
3
|
import { validatePermissions, validateUiContributions, } from "./permissions.js";
|
|
4
|
-
/**
|
|
4
|
+
/** The plugin manifest is invalid. */
|
|
5
5
|
export class ExtensionManifestError extends Error {
|
|
6
6
|
constructor(plugin, message) {
|
|
7
7
|
super(`extension ${plugin}: ${message}`);
|
|
8
8
|
this.name = "ExtensionManifestError";
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/** Plugin name rule (manifest `name`; a connector template's `plugin` is validated by it too). */
|
|
12
12
|
export const EXTENSION_NAME_RE = /^[a-z][a-z0-9-]{1,40}$/;
|
|
13
13
|
const NAME_RE = EXTENSION_NAME_RE;
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Reserved plugin name: the kernel uses `kernel` as its own secrets namespace, so a plugin cannot
|
|
16
|
+
* take it.
|
|
17
|
+
*/
|
|
15
18
|
const RESERVED_NAMES = new Set(["kernel"]);
|
|
16
19
|
function checkRefs(label, refs, fail, forbidBrokered = false) {
|
|
17
20
|
for (const ref of refs) {
|
|
@@ -30,7 +33,7 @@ function checkRefs(label, refs, fail, forbidBrokered = false) {
|
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
|
-
/**
|
|
36
|
+
/** Validates the plugin manifest and returns it unchanged; throws ExtensionManifestError when invalid. */
|
|
34
37
|
export function defineExtension(m) {
|
|
35
38
|
const plugin = typeof m?.name === "string" && m.name !== "" ? m.name : "<unnamed>";
|
|
36
39
|
const fail = (msg) => {
|
|
@@ -73,11 +76,22 @@ export function defineExtension(m) {
|
|
|
73
76
|
fail(`field "optional" entry "${r}" overlaps with "provides" or "requires"`);
|
|
74
77
|
}
|
|
75
78
|
}
|
|
79
|
+
if (m.config !== undefined) {
|
|
80
|
+
if (typeof m.config !== "object" || m.config === null || Array.isArray(m.config)) {
|
|
81
|
+
fail(`field "config" must be an object`);
|
|
82
|
+
}
|
|
83
|
+
for (const key of Object.keys(m.config)) {
|
|
84
|
+
if (key === "deployment")
|
|
85
|
+
continue;
|
|
86
|
+
fail(`config.${key} is not a config level: the only one is config.deployment`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
76
89
|
if (m.permissions !== undefined) {
|
|
77
|
-
const errs = validatePermissions(plugin, m.permissions);
|
|
90
|
+
const errs = validatePermissions(plugin, m.permissions, m.provides);
|
|
78
91
|
if (errs.length > 0)
|
|
79
92
|
fail(`invalid permissions: ${errs.join("; ")}`);
|
|
80
93
|
}
|
|
94
|
+
// structural ui problems only; slot resolution never fails the extension (UI slots spec §3.2)
|
|
81
95
|
const uiErrs = validateUiContributions(m.ui, m.permissions);
|
|
82
96
|
if (uiErrs.length > 0)
|
|
83
97
|
fail(`invalid ui: ${uiErrs.join("; ")}`);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paths a local device never opens to restricted work (Request approval, Approve for me), relative
|
|
3
|
+
* to `~` (spec §13.6, extended by ruling R19): SSH keys, cloud CLI credentials, container and
|
|
4
|
+
* Kubernetes credentials, netrc, GnuPG, git / npm / PyPI tokens, the macOS keychains, the
|
|
5
|
+
* browser profile directories, other tool credential stores (cargo, 1Password, Vault, Terraform,
|
|
6
|
+
* Claude, Codex, keyrings, pass, rclone, s3cmd), mise's config directory and the config files it
|
|
7
|
+
* loads from the home (an `[env]` section may hold tokens; globbed names like `~/mise.<env>.toml`
|
|
8
|
+
* are not listed), Maven and Gradle credential files, database and X11 credential files, and
|
|
9
|
+
* shell and REPL histories. Secrets a shell start file exports (`export TOKEN=…` in `~/.bashrc`)
|
|
10
|
+
* are not covered: start files stay readable so sandboxed shells behave as the owner's. One source for
|
|
11
|
+
* the device, which denies them (and its own state directory), and the kernel, which never proposes
|
|
12
|
+
* an approval for a path under one. Full access and auto mode run as the owner and do not apply
|
|
13
|
+
* them: the command review does.
|
|
14
|
+
*/
|
|
15
|
+
export declare const DEVICE_DENIED_SECRET_PATHS: readonly string[];
|
|
16
|
+
/**
|
|
17
|
+
* The device program's default state directory (`$XDG_CONFIG_HOME/capybara-device` when that is
|
|
18
|
+
* set), relative to `~`: denied to restricted work like the secret paths.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEVICE_DEFAULT_STATE_PATH = "~/.config/capybara-device";
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paths a local device never opens to restricted work (Request approval, Approve for me), relative
|
|
3
|
+
* to `~` (spec §13.6, extended by ruling R19): SSH keys, cloud CLI credentials, container and
|
|
4
|
+
* Kubernetes credentials, netrc, GnuPG, git / npm / PyPI tokens, the macOS keychains, the
|
|
5
|
+
* browser profile directories, other tool credential stores (cargo, 1Password, Vault, Terraform,
|
|
6
|
+
* Claude, Codex, keyrings, pass, rclone, s3cmd), mise's config directory and the config files it
|
|
7
|
+
* loads from the home (an `[env]` section may hold tokens; globbed names like `~/mise.<env>.toml`
|
|
8
|
+
* are not listed), Maven and Gradle credential files, database and X11 credential files, and
|
|
9
|
+
* shell and REPL histories. Secrets a shell start file exports (`export TOKEN=…` in `~/.bashrc`)
|
|
10
|
+
* are not covered: start files stay readable so sandboxed shells behave as the owner's. One source for
|
|
11
|
+
* the device, which denies them (and its own state directory), and the kernel, which never proposes
|
|
12
|
+
* an approval for a path under one. Full access and auto mode run as the owner and do not apply
|
|
13
|
+
* them: the command review does.
|
|
14
|
+
*/
|
|
15
|
+
export const DEVICE_DENIED_SECRET_PATHS = Object.freeze([
|
|
16
|
+
"~/.ssh",
|
|
17
|
+
"~/.aws",
|
|
18
|
+
"~/.config/gcloud",
|
|
19
|
+
"~/.azure",
|
|
20
|
+
"~/.kube",
|
|
21
|
+
"~/.docker/config.json",
|
|
22
|
+
"~/.netrc",
|
|
23
|
+
"~/.gnupg",
|
|
24
|
+
"~/Library/Application Support/Google/Chrome",
|
|
25
|
+
"~/Library/Application Support/Firefox",
|
|
26
|
+
"~/.mozilla",
|
|
27
|
+
"~/.config/google-chrome",
|
|
28
|
+
"~/.config/chromium",
|
|
29
|
+
// Ruling R19: more credential stores and browser data.
|
|
30
|
+
"~/.config/gh",
|
|
31
|
+
"~/.git-credentials",
|
|
32
|
+
"~/.npmrc",
|
|
33
|
+
"~/.pypirc",
|
|
34
|
+
"~/Library/Keychains",
|
|
35
|
+
"~/Library/Cookies",
|
|
36
|
+
"~/Library/Safari",
|
|
37
|
+
"~/Library/Application Support/BraveSoftware",
|
|
38
|
+
"~/Library/Application Support/Microsoft Edge",
|
|
39
|
+
"~/Library/Application Support/Arc",
|
|
40
|
+
"~/.config/BraveSoftware",
|
|
41
|
+
"~/.config/microsoft-edge",
|
|
42
|
+
// Machine reach reads the whole home, so more tool credential stores and shell histories.
|
|
43
|
+
"~/.cargo/credentials",
|
|
44
|
+
"~/.cargo/credentials.toml",
|
|
45
|
+
"~/.config/op",
|
|
46
|
+
"~/.vault-token",
|
|
47
|
+
"~/.terraform.d/credentials.tfrc.json",
|
|
48
|
+
"~/.claude/.credentials.json",
|
|
49
|
+
"~/.codex/auth.json",
|
|
50
|
+
"~/.local/share/keyrings",
|
|
51
|
+
"~/.password-store",
|
|
52
|
+
"~/.config/rclone",
|
|
53
|
+
"~/.s3cfg",
|
|
54
|
+
// mise: its whole config directory (config files with [env] sections, the sops age key; its
|
|
55
|
+
// data lives in ~/.local/share/mise) and the config files it walks up to in the home. Globbed
|
|
56
|
+
// spellings such as ~/mise.<env>.toml cannot be listed here and stay readable.
|
|
57
|
+
"~/.config/mise",
|
|
58
|
+
"~/.config/mise.toml",
|
|
59
|
+
"~/.config/mise.local.toml",
|
|
60
|
+
"~/.mise.toml",
|
|
61
|
+
"~/.mise.local.toml",
|
|
62
|
+
"~/.mise",
|
|
63
|
+
"~/mise.toml",
|
|
64
|
+
"~/mise.local.toml",
|
|
65
|
+
"~/mise/config.toml",
|
|
66
|
+
"~/mise/config.local.toml",
|
|
67
|
+
"~/mise/conf.d",
|
|
68
|
+
// mise's legacy (rtx) names
|
|
69
|
+
"~/.rtx.toml",
|
|
70
|
+
"~/.rtx.local.toml",
|
|
71
|
+
// Maven server passwords (and their master keys), Gradle repository credentials and Develocity
|
|
72
|
+
// (Gradle Enterprise) access keys
|
|
73
|
+
"~/.m2/settings.xml",
|
|
74
|
+
"~/.m2/settings-security.xml",
|
|
75
|
+
"~/.m2/settings-security4.xml",
|
|
76
|
+
"~/.gradle/gradle.properties",
|
|
77
|
+
"~/.gradle/develocity/keys.properties",
|
|
78
|
+
"~/.gradle/enterprise/keys.properties",
|
|
79
|
+
// Database, X11 session and other credential files directly in the home (machine reach on
|
|
80
|
+
// Linux grants the files beside a denied path one by one)
|
|
81
|
+
"~/.pgpass",
|
|
82
|
+
"~/.my.cnf",
|
|
83
|
+
"~/.Xauthority",
|
|
84
|
+
"~/.ICEauthority",
|
|
85
|
+
"~/.config/hub",
|
|
86
|
+
"~/.boto",
|
|
87
|
+
"~/.dockercfg",
|
|
88
|
+
"~/.smbcredentials",
|
|
89
|
+
"~/.terraformrc",
|
|
90
|
+
"~/.yarnrc.yml",
|
|
91
|
+
"~/.databrickscfg",
|
|
92
|
+
"~/.passwd-s3fs",
|
|
93
|
+
"~/.erlang.cookie",
|
|
94
|
+
"~/.curlrc",
|
|
95
|
+
"~/.wgetrc",
|
|
96
|
+
"~/.claude.json",
|
|
97
|
+
// shell and REPL histories (commands with inlined secrets)
|
|
98
|
+
"~/.bash_history",
|
|
99
|
+
"~/.zsh_history",
|
|
100
|
+
"~/.psql_history",
|
|
101
|
+
"~/.mysql_history",
|
|
102
|
+
"~/.python_history",
|
|
103
|
+
"~/.node_repl_history",
|
|
104
|
+
"~/.sqlite_history",
|
|
105
|
+
"~/.histfile",
|
|
106
|
+
"~/.zhistory",
|
|
107
|
+
"~/.sh_history",
|
|
108
|
+
"~/.lesshst",
|
|
109
|
+
"~/.viminfo",
|
|
110
|
+
"~/.rediscli_history",
|
|
111
|
+
"~/.irb_history",
|
|
112
|
+
"~/.Rhistory",
|
|
113
|
+
]);
|
|
114
|
+
/**
|
|
115
|
+
* The device program's default state directory (`$XDG_CONFIG_HOME/capybara-device` when that is
|
|
116
|
+
* set), relative to `~`: denied to restricted work like the secret paths.
|
|
117
|
+
*/
|
|
118
|
+
export const DEVICE_DEFAULT_STATE_PATH = "~/.config/capybara-device";
|