@capybara-hq/plugin-sdk 0.1.0-rc.3 → 0.1.0-rc.31
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/agent-docs/agent-templates.md +15 -3
- package/agent-docs/concepts.md +5 -0
- package/agent-docs/connector-templates.md +2 -1
- package/agent-docs/extension-points/channel.md +1 -1
- package/agent-docs/extension-points/config-source.md +1 -1
- package/agent-docs/extension-points/connector.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/counter.md +1 -1
- package/agent-docs/extension-points/directory.md +1 -1
- package/agent-docs/extension-points/file-preview.md +1 -1
- package/agent-docs/extension-points/identity-source.md +1 -1
- package/agent-docs/extension-points/model-provider.md +4 -2
- package/agent-docs/extension-points/object-store.md +3 -1
- package/agent-docs/extension-points/sandbox.md +3 -3
- package/agent-docs/extension-points/secret-store.md +1 -1
- package/agent-docs/extension-points/web-fetch.md +1 -1
- package/agent-docs/extension-points/web-search.md +1 -1
- package/agent-docs/extensions.md +29 -4
- package/agent-docs/plugin-format.md +43 -3
- package/agent-docs/setup.md +46 -0
- package/agent-docs/skills.md +1 -1
- package/agent-docs/tool-naming.md +1 -1
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/bootstrap.d.ts +15 -1
- package/dist/bootstrap.js +17 -1
- package/dist/cards.d.ts +56 -13
- package/dist/cards.js +90 -20
- package/dist/channel.d.ts +111 -48
- 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 +22 -0
- package/dist/config-ui.js +64 -4
- package/dist/connector-auth.d.ts +7 -2
- package/dist/connector-auth.js +29 -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 +135 -26
- package/dist/define-extension.d.ts +26 -12
- package/dist/define-extension.js +11 -4
- package/dist/device-protocol-v3.d.ts +117 -0
- package/dist/device-protocol-v3.js +409 -0
- package/dist/device-protocol.d.ts +330 -0
- package/dist/device-protocol.js +567 -0
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +5 -2
- package/dist/file-preview.d.ts +1 -1
- package/dist/git-hosts.d.ts +44 -0
- package/dist/git-hosts.js +81 -0
- package/dist/hooks.d.ts +111 -21
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +52 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +22 -9
- package/dist/index.d.ts +23 -1
- package/dist/index.js +24 -1
- package/dist/marketplace.d.ts +26 -0
- package/dist/marketplace.js +43 -1
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +180 -71
- package/dist/model.js +71 -19
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/permissions.d.ts +42 -20
- package/dist/permissions.js +97 -40
- package/dist/plugin-manifest.d.ts +45 -5
- package/dist/plugin-manifest.js +169 -6
- package/dist/plugin-package.d.ts +82 -38
- package/dist/plugin-package.js +61 -29
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +1886 -0
- package/dist/sandbox-native-runtime-source.d.ts +8 -0
- package/dist/sandbox-native-runtime-source.js +325 -0
- package/dist/sandbox-operation.d.ts +248 -0
- package/dist/sandbox-operation.js +245 -0
- package/dist/sandbox-runtime-source.d.ts +19 -0
- package/dist/sandbox-runtime-source.js +28 -0
- package/dist/sandbox-write-denies.d.ts +60 -0
- package/dist/sandbox-write-denies.js +630 -0
- package/dist/sandbox.d.ts +201 -16
- package/dist/sandbox.js +89 -14
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-check.d.ts +115 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +350 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +94 -0
- package/dist/setup-guide.js +336 -0
- package/dist/skill-invocation.d.ts +4 -3
- package/dist/skill-invocation.js +5 -4
- package/dist/skill.d.ts +34 -21
- package/dist/skill.js +48 -31
- package/dist/storage.d.ts +52 -25
- package/dist/theme-assets.d.ts +39 -0
- package/dist/theme-assets.js +449 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +279 -0
- package/dist/theme-tokens.generated.js +174 -0
- package/dist/theme.d.ts +152 -0
- package/dist/theme.js +392 -0
- package/dist/tool.d.ts +69 -26
- package/dist/tool.js +29 -9
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +337 -0
- package/dist/ui-resolve.d.ts +35 -0
- package/dist/ui-resolve.js +42 -0
- package/dist/ui-slots.d.ts +53 -0
- package/dist/ui-slots.js +238 -0
- package/dist/ui.d.ts +191 -79
- package/dist/ui.js +101 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/package.json +7 -1
- package/schemas/bootstrap.v1.schema.json +6 -0
- package/schemas/connector-template.v1.schema.json +35 -0
- package/schemas/marketplace.v1.schema.json +14 -0
- package/schemas/plugin.v1.schema.json +115 -3
- package/schemas/theme.v1.schema.json +225 -0
package/dist/ctx.d.ts
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
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 { RouteCaller } from "./http-access.js";
|
|
5
|
+
import type { ModelEmbeddingInfo, ModelKind } from "./model.js";
|
|
6
|
+
import type { ExtensionNet } from "./net.js";
|
|
7
|
+
import type { SetupCheckDefinition } from "./setup-check.js";
|
|
4
8
|
import type { ObjectHead, PresignedUpload, PresignGetOptions } from "./storage.js";
|
|
5
9
|
import type { ToolHandler, ToolSpec } from "./tool.js";
|
|
6
10
|
import type { EmbedClaims, UiActionArgs, UiActionResult, UiRenderArgs, UiView } from "./ui.js";
|
|
7
|
-
/**
|
|
11
|
+
/** Logger interface. */
|
|
8
12
|
export interface Logger {
|
|
9
13
|
info(msg: string, fields?: Record<string, unknown>): void;
|
|
10
14
|
warn(msg: string, fields?: Record<string, unknown>): void;
|
|
11
15
|
error(msg: string, fields?: Record<string, unknown>): void;
|
|
12
16
|
}
|
|
13
|
-
/**
|
|
17
|
+
/** Distributed lock lease. */
|
|
14
18
|
export interface Lease {
|
|
15
19
|
renew(): Promise<boolean>;
|
|
16
20
|
release(): Promise<void>;
|
|
17
21
|
}
|
|
18
22
|
/**
|
|
19
|
-
*
|
|
20
|
-
* `
|
|
21
|
-
*
|
|
23
|
+
* The plugin's object storage (`ctx.storage`, needs `permissions.storage`): the same shape as
|
|
24
|
+
* `ObjectStore`, but the first parameter of every method is
|
|
25
|
+
* `orgId`, and the kernel adds `plugins/<plugin name>/<orgId>/` to keys and prefixes automatically:
|
|
26
|
+
* a plugin sees only its own objects under that org.
|
|
27
|
+
* The backing store is the deployment-configured `object-store@1` provider; every method throws
|
|
28
|
+
* when there is no provider.
|
|
22
29
|
*/
|
|
23
30
|
export interface ExtensionStorage {
|
|
24
31
|
put(orgId: string, key: string, body: Uint8Array | ReadableStream<Uint8Array>, opts: {
|
|
@@ -27,8 +34,10 @@ export interface ExtensionStorage {
|
|
|
27
34
|
signal?: AbortSignal;
|
|
28
35
|
}): Promise<ObjectHead>;
|
|
29
36
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
37
|
+
* Returns null when missing. `range` is a closed byte range; an omitted `end` means read to the
|
|
38
|
+
* end.
|
|
39
|
+
* With `range`, `head.size` is still the size of the whole object; when the store ignores Range,
|
|
40
|
+
* body may be the whole object.
|
|
32
41
|
*/
|
|
33
42
|
get(orgId: string, key: string, opts?: {
|
|
34
43
|
signal?: AbortSignal;
|
|
@@ -41,7 +50,7 @@ export interface ExtensionStorage {
|
|
|
41
50
|
body: ReadableStream<Uint8Array>;
|
|
42
51
|
} | null>;
|
|
43
52
|
head(orgId: string, key: string): Promise<ObjectHead | null>;
|
|
44
|
-
/**
|
|
53
|
+
/** A missing key also counts as success. */
|
|
45
54
|
delete(orgId: string, key: string): Promise<void>;
|
|
46
55
|
deletePrefix(orgId: string, prefix: string): Promise<number>;
|
|
47
56
|
list(orgId: string, prefix: string, opts?: {
|
|
@@ -58,7 +67,69 @@ export interface ExtensionStorage {
|
|
|
58
67
|
ttlSeconds: number;
|
|
59
68
|
}): Promise<PresignedUpload>;
|
|
60
69
|
}
|
|
61
|
-
/**
|
|
70
|
+
/** A `ctx.models.embed` request: texts embedded for one org with the model mapped to a purpose. */
|
|
71
|
+
export interface ExtensionEmbedRequest {
|
|
72
|
+
orgId: string;
|
|
73
|
+
/** A purpose this extension declared in `permissions.models` with `kind: "embedding"`. */
|
|
74
|
+
purpose: string;
|
|
75
|
+
/** The texts, one vector each; split into batches by the model's `maxBatch` by the kernel. */
|
|
76
|
+
input: string[];
|
|
77
|
+
/** One of the model's `embedding.dimensions`; the model's default when absent. */
|
|
78
|
+
dimensions?: number;
|
|
79
|
+
inputType?: "query" | "document";
|
|
80
|
+
/**
|
|
81
|
+
* Aborts this call (e.g. the tool call's `signal`); combined with `ctx.signal`. Batches not yet
|
|
82
|
+
* sent are not sent; batches already answered are still recorded as usage.
|
|
83
|
+
*/
|
|
84
|
+
signal?: AbortSignal;
|
|
85
|
+
}
|
|
86
|
+
/** A `ctx.models.embed` result. */
|
|
87
|
+
export interface ExtensionEmbedResult {
|
|
88
|
+
/** One vector per input, in input order. */
|
|
89
|
+
vectors: number[][];
|
|
90
|
+
/** The model that made them (a changed model invalidates stored vectors). */
|
|
91
|
+
model: {
|
|
92
|
+
provider: string;
|
|
93
|
+
id: string;
|
|
94
|
+
};
|
|
95
|
+
dimensions: number;
|
|
96
|
+
}
|
|
97
|
+
/** The model a purpose maps to in an org (`ctx.models.describe`). */
|
|
98
|
+
export interface ExtensionModelTarget {
|
|
99
|
+
provider: string;
|
|
100
|
+
id: string;
|
|
101
|
+
kind: ModelKind;
|
|
102
|
+
/** Present for an embedding model. */
|
|
103
|
+
embedding?: ModelEmbeddingInfo;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Models by purpose (`permissions.models`): the purpose → model mapping is chosen by org admins
|
|
107
|
+
* (and the deployment default by the super admin), never by the extension. Only purposes this
|
|
108
|
+
* extension declared with `kind: "embedding"` are accepted (`model.purpose_unknown` otherwise), and
|
|
109
|
+
* only for an org that enabled the extension (`extension.not_enabled`). Usage is recorded by the
|
|
110
|
+
* kernel and reported through `usage.report` (purpose `embedding`).
|
|
111
|
+
*/
|
|
112
|
+
export interface ExtensionModels {
|
|
113
|
+
/**
|
|
114
|
+
* Embeds `input` with the org's effective model for `purpose`. Rejects with `model.unconfigured`
|
|
115
|
+
* when the purpose maps to no model the org can use, `validation_failed` for dimensions the model
|
|
116
|
+
* lacks, and a `ModelError` when the provider fails (a result of the wrong count or dimension is a
|
|
117
|
+
* `ModelError` of kind `server`). Not retried by the kernel. Each call fires the `model.request`
|
|
118
|
+
* hook first (`purpose: "embedding"`, every text of the call): when a policy hook denies it, the
|
|
119
|
+
* call rejects with an error whose `code` is `model.hook_denied` (HTTP 403 if it escapes an
|
|
120
|
+
* extension route), and nothing is sent or billed.
|
|
121
|
+
*/
|
|
122
|
+
embed(req: ExtensionEmbedRequest): Promise<ExtensionEmbedResult>;
|
|
123
|
+
/** The org's effective model for `purpose`, or null when it maps to no model the org can use. */
|
|
124
|
+
describe(req: {
|
|
125
|
+
orgId: string;
|
|
126
|
+
purpose: string;
|
|
127
|
+
}): Promise<ExtensionModelTarget | null>;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The context passed to a plugin's `setup`. It provides no timers or in-process shared state; kv
|
|
131
|
+
* writes must carry a TTL.
|
|
132
|
+
*/
|
|
62
133
|
export interface ExtensionContext {
|
|
63
134
|
kv: {
|
|
64
135
|
get(key: string): Promise<string | null>;
|
|
@@ -92,16 +163,27 @@ export interface ExtensionContext {
|
|
|
92
163
|
get(orgId: string, key: string): Promise<string | null>;
|
|
93
164
|
set(orgId: string, key: string, value: string): Promise<void>;
|
|
94
165
|
};
|
|
95
|
-
/**
|
|
166
|
+
/** Object storage (needs `permissions.storage`, see {@link ExtensionStorage}). */
|
|
96
167
|
storage: ExtensionStorage;
|
|
97
|
-
/**
|
|
168
|
+
/** Models by purpose (requires `permissions.models`, see {@link ExtensionModels}). */
|
|
169
|
+
models: ExtensionModels;
|
|
170
|
+
/**
|
|
171
|
+
* Guarded HTTP for URLs a person supplied (see {@link ExtensionNet}): a connector endpoint or an
|
|
172
|
+
* org-overridable base URL goes through `ctx.net.fetch`, never the global `fetch`.
|
|
173
|
+
*/
|
|
174
|
+
net: ExtensionNet;
|
|
175
|
+
/** A Kysely instance already switched to this plugin's schema (withSchema). */
|
|
98
176
|
db: Kysely<any>;
|
|
99
177
|
http: {
|
|
100
|
-
/**
|
|
101
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Mounted at `/plugins/<name><path>` (`public`, `embed`) or `/plugins/<name>/orgs/:orgId<path>`
|
|
180
|
+
* (`member`, `admin`), as `permissions.http` declares. The kernel enforces the access before
|
|
181
|
+
* the handler runs and passes the resolved caller; trust only `caller`.
|
|
182
|
+
*/
|
|
183
|
+
route(method: "GET" | "POST" | "PUT" | "DELETE", path: string, handler: (req: Request, caller: RouteCaller) => Promise<Response>): void;
|
|
102
184
|
};
|
|
103
185
|
tools: {
|
|
104
|
-
/**
|
|
186
|
+
/** Registers a tool; callable only during `setup`, names must not repeat. */
|
|
105
187
|
register(spec: ToolSpec, handler: ToolHandler): void;
|
|
106
188
|
};
|
|
107
189
|
/**
|
|
@@ -133,23 +215,45 @@ export interface ExtensionContext {
|
|
|
133
215
|
}[]>;
|
|
134
216
|
};
|
|
135
217
|
/**
|
|
136
|
-
*
|
|
137
|
-
* - `view` / `action
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
218
|
+
* Runtime of UI contributions (manifest `ui` + `permissions.ui`):
|
|
219
|
+
* - `view` / `action`: can be registered only during `setup`; the id is the contribution id of
|
|
220
|
+
* the kind-view entry in the manifest;
|
|
221
|
+
* `action` receives a button click or form submission from the view (`args.actionId` tells
|
|
222
|
+
* which one);
|
|
223
|
+
* - `invalidate`: tells the kernel "this contribution changed", and the web pages that have it
|
|
224
|
+
* open fetch the view again (via the bus, across replicas); a
|
|
225
|
+
* `platform.page` contribution takes no `orgId` (it refreshes the admin console), every other
|
|
226
|
+
* contribution requires one;
|
|
227
|
+
* - `verifyEmbedToken`: validates the embed token an embed page received; it accepts only
|
|
228
|
+
* tokens signed for this plugin and not expired, while the plugin is still enabled in that org,
|
|
229
|
+
* the caller is still an active member and the role still satisfies the slot's minRole,
|
|
230
|
+
* otherwise it returns null; the returned `role` is the role at this moment. A
|
|
231
|
+
* platform-scope token (`scope: "platform"`, no `orgId`) verifies only for a `platform.page`
|
|
232
|
+
* contribution while the account is still an active super admin.
|
|
142
233
|
*/
|
|
143
234
|
ui: {
|
|
144
235
|
view(id: string, render: (args: UiRenderArgs) => Promise<UiView>): void;
|
|
145
236
|
action(id: string, handler: (args: UiActionArgs) => Promise<UiActionResult>): void;
|
|
146
237
|
invalidate(target: {
|
|
147
|
-
|
|
238
|
+
/** Required, except for a `platform.page` contribution, where it must be omitted. */
|
|
239
|
+
orgId?: string;
|
|
148
240
|
conversationId?: string;
|
|
149
241
|
contribution: string;
|
|
150
242
|
}): Promise<void>;
|
|
151
243
|
verifyEmbedToken(token: string): Promise<EmbedClaims | null>;
|
|
152
244
|
};
|
|
245
|
+
/**
|
|
246
|
+
* Setup checks (`permissions.setupChecks`): the live rows of the plugin's setup guides.
|
|
247
|
+
* `check` is only allowed during `setup`; `id` must be listed in `permissions.setupChecks`
|
|
248
|
+
* (else `ExtensionPermissionError`); registering an id twice throws. The kernel runs a check only
|
|
249
|
+
* when a person or an agent asks, only for targets of this plugin and of `def.place`, aborts
|
|
250
|
+
* `signal` after `SETUP_CHECK_LIMITS.timeoutMs`, and redacts and bounds the result. A check never
|
|
251
|
+
* writes, passes `signal` to every request, does not retry and never puts a secret in `reason`
|
|
252
|
+
* or `fix`. It never receives an OAuth client secret or a member's token.
|
|
253
|
+
*/
|
|
254
|
+
setup: {
|
|
255
|
+
check(id: string, def: SetupCheckDefinition): void;
|
|
256
|
+
};
|
|
153
257
|
/**
|
|
154
258
|
* Hooks (`permissions.hooks`): observe model and tool calls, or deny them with a policy hook.
|
|
155
259
|
* `on` is only allowed during `setup`; the mount point must be declared in `permissions.hooks` and be
|
|
@@ -164,14 +268,19 @@ export interface ExtensionContext {
|
|
|
164
268
|
};
|
|
165
269
|
provide(extensionPoint: ExtensionPointRef, impl: unknown): void;
|
|
166
270
|
/**
|
|
167
|
-
*
|
|
168
|
-
*
|
|
271
|
+
* The lifecycle signal of this plugin instance: aborted when the instance is revoked (disabled,
|
|
272
|
+
* uninstalled, upgraded), after in-flight calls have drained.
|
|
273
|
+
* Long-running tasks the plugin started itself (polling loops, long connections, etc.) wind down
|
|
274
|
+
* on it.
|
|
169
275
|
*/
|
|
170
276
|
signal: AbortSignal;
|
|
171
277
|
/**
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
278
|
+
* Deployment-level config, validated against the plugin schema (the startup config merged with
|
|
279
|
+
* values the super admin saved in the console). This is a getter:
|
|
280
|
+
* when a field marked `hot` (`.meta({ hot: true })`) changes, the kernel replaces it in place, so
|
|
281
|
+
* the plugin must read `ctx.config` **at the time of use** to get the new value;
|
|
282
|
+
* do not copy hot fields into a closure in setup; when a non-hot field changes the kernel reloads
|
|
283
|
+
* the plugin instance (a new setup).
|
|
175
284
|
*/
|
|
176
285
|
readonly config: unknown;
|
|
177
286
|
log: Logger;
|
|
@@ -3,18 +3,25 @@ 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;
|
|
@@ -23,19 +30,26 @@ export interface ExtensionManifest {
|
|
|
23
30
|
migrations?: string;
|
|
24
31
|
setup(ctx: ExtensionContext): void | Promise<void>;
|
|
25
32
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
33
|
+
* Optional: called when the plugin instance is revoked (disabled, uninstalled, replaced by a new
|
|
34
|
+
* instance on upgrade, a dependent reloaded together with its provider).
|
|
35
|
+
* By then the kernel has already: stopped accepting new calls, waited for in-flight calls to
|
|
36
|
+
* finish (at most `extensionHost.drainSeconds`), aborted `ctx.signal`,
|
|
37
|
+
* and revoked every registration this instance made through ctx (tools, routes, queue workers,
|
|
38
|
+
* bus subscriptions, lock leases, UI, provide).
|
|
39
|
+
* Clean up here only what the plugin opened outside ctx (e.g. its own connections); do not
|
|
40
|
+
* register anything through ctx again.
|
|
41
|
+
* Not called when setup throws (the kernel revokes what was already registered).
|
|
31
42
|
*/
|
|
32
43
|
dispose?(ctx: ExtensionContext): void | Promise<void>;
|
|
33
44
|
}
|
|
34
|
-
/**
|
|
45
|
+
/** The plugin manifest is invalid. */
|
|
35
46
|
export declare class ExtensionManifestError extends Error {
|
|
36
47
|
constructor(plugin: string, message: string);
|
|
37
48
|
}
|
|
38
|
-
/**
|
|
49
|
+
/** Plugin name rule (manifest `name`; a connector template's `plugin` is validated by it too). */
|
|
39
50
|
export declare const EXTENSION_NAME_RE: RegExp;
|
|
40
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Validates the plugin manifest and returns it unchanged; throws ExtensionManifestError when
|
|
53
|
+
* invalid.
|
|
54
|
+
*/
|
|
41
55
|
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,10 @@ function checkRefs(label, refs, fail, forbidBrokered = false) {
|
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Validates the plugin manifest and returns it unchanged; throws ExtensionManifestError when
|
|
38
|
+
* invalid.
|
|
39
|
+
*/
|
|
34
40
|
export function defineExtension(m) {
|
|
35
41
|
const plugin = typeof m?.name === "string" && m.name !== "" ? m.name : "<unnamed>";
|
|
36
42
|
const fail = (msg) => {
|
|
@@ -78,6 +84,7 @@ export function defineExtension(m) {
|
|
|
78
84
|
if (errs.length > 0)
|
|
79
85
|
fail(`invalid permissions: ${errs.join("; ")}`);
|
|
80
86
|
}
|
|
87
|
+
// structural ui problems only; slot resolution never fails the extension (UI slots spec §3.2)
|
|
81
88
|
const uiErrs = validateUiContributions(m.ui, m.permissions);
|
|
82
89
|
if (uiErrs.length > 0)
|
|
83
90
|
fail(`invalid ui: ${uiErrs.join("; ")}`);
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** Development staging only. Task 8 replaces v2 and removes this module and its staged names together. */
|
|
2
|
+
import { type DeviceHello, type DeviceLocalPolicySummary, type DeviceOp, type DevicePolicyArgs, type DevicePolicyStatus, type DeviceRes, type KernelCancel } from "./device-protocol.js";
|
|
3
|
+
import { type SandboxPermissionSupport } from "./sandbox-operation.js";
|
|
4
|
+
export declare const STAGED_DEVICE_PROTOCOL_VERSION = 3;
|
|
5
|
+
export type DeviceOperationV3 = Exclude<DeviceOp, "killTagged" | "killAll"> | "prepareReadFile" | "prepareWriteFile" | "prepareStat" | "browseStat" | "browseList" | "browseScan" | "backgroundStart" | "backgroundStatus" | "backgroundTail" | "backgroundReadOutput" | "backgroundStop" | "revokeOperation" | "bindInstance";
|
|
6
|
+
export interface DeviceOwnerCeilingV3 {
|
|
7
|
+
readonly version: 2;
|
|
8
|
+
readonly sequence: number;
|
|
9
|
+
readonly restrictedProjectReach: "workspace" | "os-user";
|
|
10
|
+
readonly revision: string;
|
|
11
|
+
readonly fullAccess: boolean;
|
|
12
|
+
readonly restrictedAllowedDomains: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The only owner-ceiling change the kernel may ask of a machine (B2): narrowing. Widening is decided
|
|
16
|
+
* on the machine by its owner (`capybara-device ceiling set`), never over the wire.
|
|
17
|
+
*/
|
|
18
|
+
export interface DeviceOwnerCeilingNarrowingV3 {
|
|
19
|
+
readonly fullAccess?: false;
|
|
20
|
+
readonly restrictedProjectReach?: "workspace";
|
|
21
|
+
}
|
|
22
|
+
/** A staged `policy` op: the protocol 2 change plus an optional owner-ceiling narrowing. */
|
|
23
|
+
export interface DevicePolicyArgsV3 extends DevicePolicyArgs {
|
|
24
|
+
ownerCeiling?: DeviceOwnerCeilingNarrowingV3;
|
|
25
|
+
}
|
|
26
|
+
/** A staged `policy` answer: the policy as written and the owner report issued for it. */
|
|
27
|
+
export interface DevicePolicyResultV3 {
|
|
28
|
+
policy: DeviceLocalPolicySummary;
|
|
29
|
+
ownerCeiling: DeviceOwnerCeilingV3;
|
|
30
|
+
}
|
|
31
|
+
/** A staged `policyStatus` answer: an `applied` outcome carries the current owner report. */
|
|
32
|
+
export interface DevicePolicyStatusV3 extends DevicePolicyStatus {
|
|
33
|
+
ownerCeiling?: DeviceOwnerCeilingV3;
|
|
34
|
+
}
|
|
35
|
+
/** The device pushed a policy change: the owner report for the newly observed revision. */
|
|
36
|
+
export interface DevicePolicyChangedV3 {
|
|
37
|
+
type: "policy";
|
|
38
|
+
policy?: DeviceLocalPolicySummary;
|
|
39
|
+
ownerCeiling: DeviceOwnerCeilingV3;
|
|
40
|
+
}
|
|
41
|
+
export interface DeviceHelloV3 extends DeviceHello {
|
|
42
|
+
protocol: 3;
|
|
43
|
+
permissionSupport: SandboxPermissionSupport;
|
|
44
|
+
ownerCeiling: DeviceOwnerCeilingV3;
|
|
45
|
+
instanceGeneration: string | null;
|
|
46
|
+
transport: {
|
|
47
|
+
maxFrameBytes: number;
|
|
48
|
+
};
|
|
49
|
+
/** Absent until the program can attest actual installed runtime/helper/environment bytes. */
|
|
50
|
+
runtimeIdentity?: DeviceRuntimeIdentityV3;
|
|
51
|
+
}
|
|
52
|
+
/** A verified installed runtime/helper/environment identity bound to one instance generation. */
|
|
53
|
+
export interface DeviceRuntimeIdentityV3 {
|
|
54
|
+
runtimeHash: string;
|
|
55
|
+
helperHash: string;
|
|
56
|
+
imageFingerprint: string;
|
|
57
|
+
instanceGeneration: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Private lifecycle request (permission runtime cutover B4): binds the kernel's committed instance
|
|
61
|
+
* generation to the device after commit. It carries no path, policy or manifest.
|
|
62
|
+
*/
|
|
63
|
+
export interface BindInstanceRequestV3 {
|
|
64
|
+
instanceId: string;
|
|
65
|
+
instanceGeneration: string;
|
|
66
|
+
bindingId: string;
|
|
67
|
+
expectedPreviousGeneration: string | null;
|
|
68
|
+
}
|
|
69
|
+
export interface BindInstanceResultV3 {
|
|
70
|
+
instanceId: string;
|
|
71
|
+
instanceGeneration: string;
|
|
72
|
+
bindingId: string;
|
|
73
|
+
runtimeIdentity: DeviceRuntimeIdentityV3;
|
|
74
|
+
permissionSupport: SandboxPermissionSupport;
|
|
75
|
+
ownerCeiling: DeviceOwnerCeilingV3;
|
|
76
|
+
}
|
|
77
|
+
export interface KernelReadyV3 {
|
|
78
|
+
type: "ready";
|
|
79
|
+
connectionId: string;
|
|
80
|
+
maxFrameBytes: number;
|
|
81
|
+
}
|
|
82
|
+
export interface BackgroundReadOutputRequestV3 {
|
|
83
|
+
offset: number;
|
|
84
|
+
maxBytes: number;
|
|
85
|
+
}
|
|
86
|
+
export type BackgroundReadOutputResultV3 = {
|
|
87
|
+
dataB64: string;
|
|
88
|
+
offset: number;
|
|
89
|
+
nextOffset: number;
|
|
90
|
+
totalBytes: number;
|
|
91
|
+
} | {
|
|
92
|
+
unavailable: "lost" | "expired";
|
|
93
|
+
};
|
|
94
|
+
export interface KernelRequestV3 {
|
|
95
|
+
type: "req";
|
|
96
|
+
id: string;
|
|
97
|
+
op: DeviceOperationV3;
|
|
98
|
+
args: Readonly<Record<string, unknown>>;
|
|
99
|
+
deadlineMs: number;
|
|
100
|
+
}
|
|
101
|
+
export type DeviceResponseV3 = Exclude<DeviceRes, {
|
|
102
|
+
ok: false;
|
|
103
|
+
}> | {
|
|
104
|
+
type: "res";
|
|
105
|
+
id: string;
|
|
106
|
+
ok: false;
|
|
107
|
+
error: {
|
|
108
|
+
kind: "gone" | "fs_gone" | "policy" | "error" | "denied" | "unsupported" | "unknown";
|
|
109
|
+
message: string;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
export type DeviceFrameV3 = DeviceHelloV3 | KernelReadyV3 | KernelRequestV3 | KernelCancel | DeviceResponseV3 | DevicePolicyChangedV3;
|
|
113
|
+
/** Strictly parses one authenticated owner-ceiling report (B2); throws {@link DeviceProtocolError}. */
|
|
114
|
+
export declare function parseOwnerCeilingReportV3(value: unknown): DeviceOwnerCeilingV3;
|
|
115
|
+
/** Strict scope-bearing frames; active parseDeviceFrame still speaks v2. */
|
|
116
|
+
export declare function parseDeviceFrameV3(raw: string, from: "device" | "kernel", maxFrameBytes?: number): DeviceFrameV3;
|
|
117
|
+
export declare function parseOperationResultV3(op: DeviceOperationV3, result: unknown, request?: BackgroundReadOutputRequestV3 | BindInstanceRequestV3): unknown;
|