@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.
- 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 +60 -13
- package/dist/cards.js +88 -18
- package/dist/channel.d.ts +128 -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 +210 -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 +156 -30
- package/dist/tool.js +91 -9
- 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/ui.d.ts
CHANGED
|
@@ -1,37 +1,32 @@
|
|
|
1
1
|
import type { Locale } from "./cards.js";
|
|
2
2
|
import { type FormAnswer, type InputForm } from "./tool.js";
|
|
3
|
-
|
|
4
|
-
* Where a ui contribution goes (UI refresh spec §5.3):
|
|
5
|
-
* - `panel`: a right panel of the conversation page, opened from the extension's icon in the title
|
|
6
|
-
* bar (one at a time);
|
|
7
|
-
* - `section`: a section of the conversation's properties panel;
|
|
8
|
-
* - `inline`: an inline card in the conversation, hanging off a tool result (`ToolResult.card`);
|
|
9
|
-
* - `page`: an org page under "Extensions";
|
|
10
|
-
* - `file-preview`: an embed previewer of `file-preview@1` (embed only, see `FilePreviewer.embed`);
|
|
11
|
-
* - `conversation`: the old right-side tab; it means `panel` (see {@link normalizePlace}).
|
|
12
|
-
*/
|
|
13
|
-
export type UiPlace = "conversation" | "panel" | "section" | "inline" | "page" | "file-preview";
|
|
14
|
-
/** A place with the old `conversation` mapped to `panel`. */
|
|
15
|
-
export declare function normalizePlace(place: UiPlace): Exclude<UiPlace, "conversation">;
|
|
3
|
+
import type { CompactForm, UiSlotId, UiSlotScope } from "./ui-slots.js";
|
|
16
4
|
/**
|
|
17
5
|
* Icons a contribution may use (design system icon names; `puzzle` is the default and is drawn as
|
|
18
6
|
* the design `extension` icon). The title-bar button of a panel shows it.
|
|
19
7
|
*/
|
|
20
|
-
export declare const UI_ICONS: readonly ["list-checks", "layout-grid", "file", "chart", "calendar", "users", "bot", "book", "message-square", "puzzle"];
|
|
8
|
+
export declare const UI_ICONS: readonly ["list-checks", "layout-grid", "file", "chart", "calendar", "users", "bot", "book", "message-square", "globe", "puzzle"];
|
|
21
9
|
export type UiIcon = (typeof UI_ICONS)[number];
|
|
22
10
|
/**
|
|
23
|
-
* An "open" target: a `panel` contribution of the same extension, scrolled to the
|
|
24
|
-
* whose `id` equals `item` (the panel's render receives it as
|
|
11
|
+
* An "open" target: a `conversation.panel` contribution of the same extension, scrolled to the
|
|
12
|
+
* block or item whose `id` equals `item` (the panel's render receives it as
|
|
13
|
+
* {@link UiRenderArgs.item}).
|
|
25
14
|
*/
|
|
26
15
|
export interface UiOpen {
|
|
27
16
|
contribution: string;
|
|
28
17
|
item?: string;
|
|
29
18
|
}
|
|
30
|
-
/** 界面贡献的种类:`view` = 渲染 schema(由我们的组件画);`embed` = 插件自己的页面放进 iframe。 */
|
|
31
|
-
export type UiKind = "view" | "embed";
|
|
32
19
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
20
|
+
* The kind of a UI contribution: `view` = a render schema drawn by the host's components; `embed` =
|
|
21
|
+
* the extension's own page in an iframe; `component` = a React component from the extension's
|
|
22
|
+
* client code (client extensions spec §5).
|
|
23
|
+
*/
|
|
24
|
+
export type UiKind = "view" | "embed" | "component";
|
|
25
|
+
/**
|
|
26
|
+
* One UI contribution of the extension manifest's `ui`. Its `id` must be listed in the list of its
|
|
27
|
+
* kind: `permissions.ui.views` (view), `permissions.ui.embeds` (embed) or
|
|
28
|
+
* `permissions.ui.components` (component, which also needs `permissions.client: true`); an embed's
|
|
29
|
+
* page is served by an extension route.
|
|
35
30
|
*/
|
|
36
31
|
export interface UiContribution {
|
|
37
32
|
id: string;
|
|
@@ -39,22 +34,32 @@ export interface UiContribution {
|
|
|
39
34
|
zh: string;
|
|
40
35
|
en: string;
|
|
41
36
|
};
|
|
42
|
-
|
|
37
|
+
/**
|
|
38
|
+
* The slot it goes in: `"<id>"` (version 1) or `"<id>@<n>"`, an id of `UI_SLOTS`. Required. An
|
|
39
|
+
* unknown slot or version does not fail the extension: the contribution is dropped (see
|
|
40
|
+
* `resolveUiSlots`).
|
|
41
|
+
*/
|
|
42
|
+
slot: string;
|
|
43
|
+
/**
|
|
44
|
+
* One of the slot's `anchors` to be placed after; omitted (or not an anchor of the slot) = the
|
|
45
|
+
* slot's first anchor.
|
|
46
|
+
*/
|
|
47
|
+
after?: string;
|
|
43
48
|
kind: UiKind;
|
|
44
|
-
/**
|
|
49
|
+
/** Embed only: a path under `/ui/` of the extension's routes, declared in `permissions.http` as GET. */
|
|
45
50
|
path?: string;
|
|
46
51
|
/** Icon from {@link UI_ICONS}; default `puzzle`. */
|
|
47
52
|
icon?: UiIcon;
|
|
48
53
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* `permissions.ui`, and no `ctx.ui.view` of its own.
|
|
54
|
+
* The form on a compact screen; may only narrow the slot's own (`kept` -> `drawer` -> `hidden`),
|
|
55
|
+
* see `effectiveCompact`. Omitted = the slot's form.
|
|
52
56
|
*/
|
|
53
|
-
|
|
57
|
+
compact?: CompactForm;
|
|
54
58
|
}
|
|
55
59
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
60
|
+
* Blocks of the render schema. Text is for humans and shown as is (the plugin decides the language
|
|
61
|
+
* itself, usually taking `locale`).
|
|
62
|
+
* `text.markdown` does not support native HTML, and links may only be absolute http(s) addresses.
|
|
58
63
|
*/
|
|
59
64
|
export type UiBlock = {
|
|
60
65
|
type: "heading";
|
|
@@ -86,8 +91,10 @@ export type UiBlock = {
|
|
|
86
91
|
label: string;
|
|
87
92
|
}[];
|
|
88
93
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
94
|
+
* Each row takes its cell by column key, and a column may be missing. When rendering, use
|
|
95
|
+
* `Object.hasOwn(row, key)` to tell whether a cell exists,
|
|
96
|
+
* do not use `row[key]` or `in`: a column key may be `constructor` / `toString` and the like,
|
|
97
|
+
* which would pick up values from the prototype chain.
|
|
91
98
|
*/
|
|
92
99
|
rows: Record<string, string>[];
|
|
93
100
|
/** Per row (same index), an open target or null; never a key inside a row. */
|
|
@@ -121,20 +128,32 @@ export type UiBlock = {
|
|
|
121
128
|
actionId: string;
|
|
122
129
|
submitLabel: string;
|
|
123
130
|
};
|
|
124
|
-
/**
|
|
131
|
+
/** A JSON value: what survives `JSON.stringify` and `JSON.parse` unchanged. */
|
|
132
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
133
|
+
[key: string]: JsonValue;
|
|
134
|
+
};
|
|
135
|
+
/** A plugin view: a block list with limits; `badge` is shown on the tab (e.g. "2/4"). */
|
|
125
136
|
export interface UiView {
|
|
126
137
|
badge?: string;
|
|
127
138
|
/** The ⤢ of an inline card's title row and a properties section's header. */
|
|
128
139
|
open?: UiOpen;
|
|
140
|
+
/** A component's view may have no blocks (`[]`). */
|
|
129
141
|
blocks: UiBlock[];
|
|
142
|
+
/**
|
|
143
|
+
* Only from a component's render (`useView` hands it to the component): at most
|
|
144
|
+
* `UI_LIMITS.componentDataBytes` bytes of JSON. Refused in the views of the other kinds.
|
|
145
|
+
*/
|
|
146
|
+
data?: JsonValue;
|
|
130
147
|
}
|
|
131
148
|
/**
|
|
132
|
-
*
|
|
133
|
-
* - `blocks
|
|
134
|
-
* - `tableRows
|
|
135
|
-
*
|
|
136
|
-
* - `
|
|
137
|
-
* - `
|
|
149
|
+
* View limits (checked uniformly by {@link validateUiView}):
|
|
150
|
+
* - `blocks`: number of blocks;
|
|
151
|
+
* - `tableRows`: number of table rows, also used as the upper bound for keyValue items, table
|
|
152
|
+
* columns, chart points and buttons;
|
|
153
|
+
* - `checklistItems`: number of checklist items;
|
|
154
|
+
* - `textChars`: total characters of all text in the whole view (form JSON included);
|
|
155
|
+
* - `payloadBytes`: UTF-8 bytes of a single button `payload` after JSON serialization.
|
|
156
|
+
* - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
|
|
138
157
|
*/
|
|
139
158
|
export declare const UI_LIMITS: {
|
|
140
159
|
readonly blocks: 50;
|
|
@@ -142,28 +161,63 @@ export declare const UI_LIMITS: {
|
|
|
142
161
|
readonly checklistItems: 100;
|
|
143
162
|
readonly textChars: 20000;
|
|
144
163
|
readonly payloadBytes: 2000;
|
|
164
|
+
readonly componentDataBytes: 32768;
|
|
145
165
|
};
|
|
146
166
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
167
|
+
* Validates the view a plugin returns and returns the list of problems (empty = valid). Links and
|
|
168
|
+
* images may only be absolute http(s) addresses;
|
|
169
|
+
* the Markdown check is defense in depth, and web rendering must still accept only http(s) links
|
|
170
|
+
* and not render native HTML.
|
|
171
|
+
* The `actionId` of buttons and forms is unique within the whole view (action callbacks tell the
|
|
172
|
+
* source by it).
|
|
173
|
+
* `data` is accepted only with `opts.component` (the view of a component contribution): JSON as is
|
|
174
|
+
* (nothing JSON would drop or rewrite, see `jsonProblem`), up to `UI_LIMITS.componentDataBytes`
|
|
175
|
+
* bytes of UTF-8.
|
|
150
176
|
*/
|
|
151
|
-
export declare function validateUiView(v: unknown
|
|
177
|
+
export declare function validateUiView(v: unknown, opts?: {
|
|
178
|
+
component?: boolean;
|
|
179
|
+
}): string[];
|
|
152
180
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
181
|
+
* The caller's role in the org (owner / admin / member / guest, highest first). A slot's `minRole`
|
|
182
|
+
* decides who may use its contributions, then its scope's rule (the kernel answers 404 to anyone
|
|
183
|
+
* else, so the extension never sees such a request): `org.page` member and up,
|
|
184
|
+
* `org.settings.section` admin and up; conversation slots any role that can read the
|
|
185
|
+
* conversation; `agent.detail.section` any role that can read the agent (read-only viewers
|
|
186
|
+
* included: tighten on `role` if you must).
|
|
155
187
|
*/
|
|
156
188
|
export type UiRole = "owner" | "admin" | "member" | "guest";
|
|
157
|
-
/**
|
|
158
|
-
export interface
|
|
159
|
-
orgId: string;
|
|
189
|
+
/** The render args every scope shares (identity comes from the kernel's auth, never the caller's credentials). */
|
|
190
|
+
export interface UiRenderArgsBase {
|
|
160
191
|
accountId: string;
|
|
161
|
-
/**
|
|
162
|
-
|
|
163
|
-
/** 仅对话视图。 */
|
|
164
|
-
conversationId?: string;
|
|
192
|
+
/** The catalog slot the contribution resolved to. */
|
|
193
|
+
slot: UiSlotId;
|
|
165
194
|
locale: Locale;
|
|
166
195
|
signal: AbortSignal;
|
|
196
|
+
/**
|
|
197
|
+
* The extension's effective deployment config: for an org, the platform's deployment config
|
|
198
|
+
* with the org's copy applied to the overridable fields (every field not marked `platformOnly`),
|
|
199
|
+
* or the platform's config (equal to `ctx.config`) while the org follows it; for the platform
|
|
200
|
+
* scope, the platform's config. Use it, not `ctx.config`, for work done for this org.
|
|
201
|
+
*/
|
|
202
|
+
config?: unknown;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The parameters passed when the kernel calls the plugin's `render`: the position within the org
|
|
206
|
+
* (conversation, agent, org, file).
|
|
207
|
+
*/
|
|
208
|
+
export interface UiOrgRenderArgs extends UiRenderArgsBase {
|
|
209
|
+
/** The scope of {@link slot}: which of the context ids below are set. */
|
|
210
|
+
scope: Exclude<UiSlotScope, "platform">;
|
|
211
|
+
orgId: string;
|
|
212
|
+
/**
|
|
213
|
+
* The caller's role in `orgId` at this moment (filled by the kernel from membership; a plugin may
|
|
214
|
+
* use it to tighten buttons etc., see {@link UiRole}).
|
|
215
|
+
*/
|
|
216
|
+
role: UiRole;
|
|
217
|
+
/** Conversation views only. */
|
|
218
|
+
conversationId?: string;
|
|
219
|
+
/** Only an agent view (`agent.detail.section`): an agent of `orgId` the caller can read. */
|
|
220
|
+
agentId?: string;
|
|
167
221
|
/** A panel opened from an open target: the block or item `id` to scroll to. */
|
|
168
222
|
item?: string;
|
|
169
223
|
/**
|
|
@@ -175,22 +229,43 @@ export interface UiRenderArgs {
|
|
|
175
229
|
callId: string;
|
|
176
230
|
key?: string;
|
|
177
231
|
};
|
|
178
|
-
/**
|
|
179
|
-
* The extension's effective deployment config for this org: the platform's deployment config
|
|
180
|
-
* with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
|
|
181
|
-
* platform's config (equal to `ctx.config`) while the org follows it. Use it, not `ctx.config`,
|
|
182
|
-
* for work done for this org. Optional in the type so older extensions compile; the kernel
|
|
183
|
-
* always passes it.
|
|
184
|
-
*/
|
|
185
|
-
config?: unknown;
|
|
186
232
|
}
|
|
187
|
-
/**
|
|
188
|
-
|
|
233
|
+
/**
|
|
234
|
+
* The render args of a `platform.page` contribution: rendered for a super admin in the admin
|
|
235
|
+
* console, with no org (and so no org role, conversation or agent).
|
|
236
|
+
*/
|
|
237
|
+
export interface UiPlatformRenderArgs extends UiRenderArgsBase {
|
|
238
|
+
scope: "platform";
|
|
239
|
+
orgId?: undefined;
|
|
240
|
+
role: "superAdmin";
|
|
241
|
+
conversationId?: undefined;
|
|
242
|
+
agentId?: undefined;
|
|
243
|
+
item?: undefined;
|
|
244
|
+
card?: undefined;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The parameters passed when the kernel calls the plugin's `render`: narrow on `scope`
|
|
248
|
+
* (`"platform"` has no `orgId`).
|
|
249
|
+
*/
|
|
250
|
+
export type UiRenderArgs = UiOrgRenderArgs | UiPlatformRenderArgs;
|
|
251
|
+
/** What a button or form submit adds to the render args. */
|
|
252
|
+
export interface UiActionInput {
|
|
189
253
|
actionId: string;
|
|
190
254
|
payload?: unknown;
|
|
191
255
|
answer?: FormAnswer;
|
|
192
256
|
}
|
|
193
|
-
/**
|
|
257
|
+
/** An action of an org-scope view. */
|
|
258
|
+
export interface UiOrgActionArgs extends UiOrgRenderArgs, UiActionInput {
|
|
259
|
+
}
|
|
260
|
+
/** An action of a `platform.page` view. */
|
|
261
|
+
export interface UiPlatformActionArgs extends UiPlatformRenderArgs, UiActionInput {
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* A button or form submission in a view: `actionId` comes from the block; a form submission carries
|
|
265
|
+
* `answer`.
|
|
266
|
+
*/
|
|
267
|
+
export type UiActionArgs = UiOrgActionArgs | UiPlatformActionArgs;
|
|
268
|
+
/** An action result: a notice, or a new view. */
|
|
194
269
|
export type UiActionResult = {
|
|
195
270
|
toast?: {
|
|
196
271
|
zh: string;
|
|
@@ -199,22 +274,92 @@ export type UiActionResult = {
|
|
|
199
274
|
} | {
|
|
200
275
|
view: UiView;
|
|
201
276
|
};
|
|
202
|
-
/**
|
|
203
|
-
export interface
|
|
277
|
+
/** The embed claims every scope shares. `exp` is Unix seconds. */
|
|
278
|
+
export interface EmbedClaimsBase {
|
|
204
279
|
plugin: string;
|
|
280
|
+
contribution: string;
|
|
281
|
+
exp: number;
|
|
282
|
+
}
|
|
283
|
+
/** An org-scope embed token's claims (every slot but `platform.page`). */
|
|
284
|
+
export interface OrgEmbedClaims extends EmbedClaimsBase {
|
|
285
|
+
scope: "org";
|
|
205
286
|
orgId: string;
|
|
206
287
|
accountId: string;
|
|
207
|
-
/**
|
|
288
|
+
/**
|
|
289
|
+
* The caller's role: written at issuance; `ctx.ui.verifyEmbedToken` returns the current role at
|
|
290
|
+
* validation time.
|
|
291
|
+
*/
|
|
208
292
|
role: UiRole;
|
|
209
293
|
conversationId?: string;
|
|
294
|
+
/** Only an agent embed's token (`agent.detail.section`): the agent it was issued for. */
|
|
295
|
+
agentId?: string;
|
|
210
296
|
/** Only a `file-preview` embed's token: the one file (of `conversationId`) it previews. */
|
|
211
297
|
fileId?: string;
|
|
212
|
-
|
|
213
|
-
|
|
298
|
+
/**
|
|
299
|
+
* Only a `file-preview` embed's token for a skill file (no `conversationId`, `agentId` or
|
|
300
|
+
* `fileId`): the skill, the version and the file's path in it.
|
|
301
|
+
*/
|
|
302
|
+
skillFile?: {
|
|
303
|
+
skillId: string;
|
|
304
|
+
version: number;
|
|
305
|
+
path: string;
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
/** A `platform.page` embed token's claims: a super admin's, with no org, conversation, agent or file. */
|
|
309
|
+
export interface PlatformEmbedClaims extends EmbedClaimsBase {
|
|
310
|
+
scope: "platform";
|
|
311
|
+
accountId: string;
|
|
312
|
+
orgId?: undefined;
|
|
313
|
+
role: "superAdmin";
|
|
314
|
+
conversationId?: undefined;
|
|
315
|
+
agentId?: undefined;
|
|
316
|
+
fileId?: undefined;
|
|
317
|
+
skillFile?: undefined;
|
|
214
318
|
}
|
|
215
|
-
/**
|
|
319
|
+
/**
|
|
320
|
+
* A share page's `file.preview` embed token's claims: no account and no role, only the org, the
|
|
321
|
+
* share and the share's generation. Valid only for the `file.preview` slot, never for `/api`.
|
|
322
|
+
*/
|
|
323
|
+
export interface ShareEmbedClaims extends EmbedClaimsBase {
|
|
324
|
+
scope: "share";
|
|
325
|
+
orgId: string;
|
|
326
|
+
shareId: string;
|
|
327
|
+
generation: number;
|
|
328
|
+
accountId?: undefined;
|
|
329
|
+
role?: undefined;
|
|
330
|
+
conversationId?: undefined;
|
|
331
|
+
agentId?: undefined;
|
|
332
|
+
fileId?: undefined;
|
|
333
|
+
skillFile?: undefined;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Claims in an embed token (trustworthy after validation by `ctx.ui.verifyEmbedToken`): narrow on
|
|
337
|
+
* `scope` (`"platform"` has no `orgId` and `role` `"superAdmin"`; `"share"` has no account or role).
|
|
338
|
+
*/
|
|
339
|
+
export type EmbedClaims = OrgEmbedClaims | PlatformEmbedClaims | ShareEmbedClaims;
|
|
340
|
+
/**
|
|
341
|
+
* The version marker of the `postMessage` protocol between the outer page and the embedded iframe.
|
|
342
|
+
*/
|
|
216
343
|
export declare const EMBED_PROTOCOL = "capybara-embed/1";
|
|
217
|
-
/**
|
|
344
|
+
/**
|
|
345
|
+
* What an embed's `init` says about where it is shown, narrowed on `scope` like {@link EmbedClaims}:
|
|
346
|
+
* an org's page, panel, section or previewer (`orgId`, and the conversation when there is one), or
|
|
347
|
+
* a platform page of the admin console (no org), or a share page (no org or conversation).
|
|
348
|
+
*/
|
|
349
|
+
export type EmbedInitContext = {
|
|
350
|
+
scope: "org";
|
|
351
|
+
orgId: string;
|
|
352
|
+
conversationId?: string;
|
|
353
|
+
} | {
|
|
354
|
+
scope: "platform";
|
|
355
|
+
orgId?: undefined;
|
|
356
|
+
conversationId?: undefined;
|
|
357
|
+
} | {
|
|
358
|
+
scope: "share";
|
|
359
|
+
orgId?: undefined;
|
|
360
|
+
conversationId?: undefined;
|
|
361
|
+
};
|
|
362
|
+
/** Messages the outer page sends to the iframe. */
|
|
218
363
|
export type EmbedParentMessage = {
|
|
219
364
|
protocol: typeof EMBED_PROTOCOL;
|
|
220
365
|
type: "init";
|
|
@@ -222,10 +367,7 @@ export type EmbedParentMessage = {
|
|
|
222
367
|
locale: Locale;
|
|
223
368
|
theme: "dark" | "light";
|
|
224
369
|
tokens: Record<string, string>;
|
|
225
|
-
context:
|
|
226
|
-
orgId: string;
|
|
227
|
-
conversationId?: string;
|
|
228
|
-
};
|
|
370
|
+
context: EmbedInitContext;
|
|
229
371
|
} | {
|
|
230
372
|
protocol: typeof EMBED_PROTOCOL;
|
|
231
373
|
type: "token";
|
|
@@ -236,6 +378,18 @@ export type EmbedParentMessage = {
|
|
|
236
378
|
theme: "dark" | "light";
|
|
237
379
|
tokens: Record<string, string>;
|
|
238
380
|
}
|
|
381
|
+
/**
|
|
382
|
+
* Only to an embed in the `conversation.panel` slot: whether the conversation's right panel is
|
|
383
|
+
* maximised (`full`). Sent right after `init` and on every change, whoever made it (the embed's
|
|
384
|
+
* own `panel-mode` ask, the host's close control or Esc, a size-class change, the host refusing
|
|
385
|
+
* full mode): derive the layout from this message, not from what was asked. The panel's frame
|
|
386
|
+
* stays mounted across a change.
|
|
387
|
+
*/
|
|
388
|
+
| {
|
|
389
|
+
protocol: typeof EMBED_PROTOCOL;
|
|
390
|
+
type: "panel-mode";
|
|
391
|
+
full: boolean;
|
|
392
|
+
}
|
|
239
393
|
/**
|
|
240
394
|
* Only to a `file-preview` embed, once, after `init`: the file being previewed. The embed never
|
|
241
395
|
* gets a URL for it.
|
|
@@ -248,15 +402,18 @@ export type EmbedParentMessage = {
|
|
|
248
402
|
size: number;
|
|
249
403
|
data: ArrayBuffer;
|
|
250
404
|
};
|
|
251
|
-
/** iframe
|
|
405
|
+
/** Messages the iframe sends to the outer page. */
|
|
252
406
|
export type EmbedChildMessage =
|
|
253
|
-
/**
|
|
407
|
+
/** Height in CSS pixels, 0–10000. */
|
|
254
408
|
{
|
|
255
409
|
protocol: typeof EMBED_PROTOCOL;
|
|
256
410
|
type: "resize";
|
|
257
411
|
height: number;
|
|
258
412
|
}
|
|
259
|
-
/**
|
|
413
|
+
/**
|
|
414
|
+
* Only in-site paths: a single leading `/`, no `//`, no `.` / `..` segments (including `%2e`
|
|
415
|
+
* encoding), unchanged after normalization.
|
|
416
|
+
*/
|
|
260
417
|
| {
|
|
261
418
|
protocol: typeof EMBED_PROTOCOL;
|
|
262
419
|
type: "navigate";
|
|
@@ -265,9 +422,20 @@ export type EmbedChildMessage =
|
|
|
265
422
|
protocol: typeof EMBED_PROTOCOL;
|
|
266
423
|
type: "toast";
|
|
267
424
|
text: string;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Asks the host to maximise (`true`) or restore (`false`) the conversation's right panel; only an
|
|
428
|
+
* embed in the `conversation.panel` slot is honoured. The host answers with its own
|
|
429
|
+
* `panel-mode` once the mode changed (it may refuse, e.g. on a phone).
|
|
430
|
+
*/
|
|
431
|
+
| {
|
|
432
|
+
protocol: typeof EMBED_PROTOCOL;
|
|
433
|
+
type: "panel-mode";
|
|
434
|
+
full: boolean;
|
|
268
435
|
};
|
|
269
436
|
/**
|
|
270
|
-
*
|
|
271
|
-
*
|
|
437
|
+
* Parses a message sent by the iframe: returns it only when protocol, type and fields are all right
|
|
438
|
+
* (a new object keeping only known fields), otherwise null.
|
|
439
|
+
* The outer page must also first check that the message source is this iframe.
|
|
272
440
|
*/
|
|
273
441
|
export declare function parseEmbedChildMessage(m: unknown): EmbedChildMessage | null;
|
package/dist/ui.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { validateInputForm } from "./tool.js";
|
|
2
2
|
import { isHttpUrl } from "./url.js";
|
|
3
|
-
/** A place with the old `conversation` mapped to `panel`. */
|
|
4
|
-
export function normalizePlace(place) {
|
|
5
|
-
return place === "conversation" ? "panel" : place;
|
|
6
|
-
}
|
|
7
3
|
/**
|
|
8
4
|
* Icons a contribution may use (design system icon names; `puzzle` is the default and is drawn as
|
|
9
5
|
* the design `extension` icon). The title-bar button of a panel shows it.
|
|
@@ -18,15 +14,18 @@ export const UI_ICONS = [
|
|
|
18
14
|
"bot",
|
|
19
15
|
"book",
|
|
20
16
|
"message-square",
|
|
17
|
+
"globe",
|
|
21
18
|
"puzzle",
|
|
22
19
|
];
|
|
23
20
|
/**
|
|
24
|
-
*
|
|
25
|
-
* - `blocks
|
|
26
|
-
* - `tableRows
|
|
27
|
-
*
|
|
28
|
-
* - `
|
|
29
|
-
* - `
|
|
21
|
+
* View limits (checked uniformly by {@link validateUiView}):
|
|
22
|
+
* - `blocks`: number of blocks;
|
|
23
|
+
* - `tableRows`: number of table rows, also used as the upper bound for keyValue items, table
|
|
24
|
+
* columns, chart points and buttons;
|
|
25
|
+
* - `checklistItems`: number of checklist items;
|
|
26
|
+
* - `textChars`: total characters of all text in the whole view (form JSON included);
|
|
27
|
+
* - `payloadBytes`: UTF-8 bytes of a single button `payload` after JSON serialization.
|
|
28
|
+
* - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
|
|
30
29
|
*/
|
|
31
30
|
export const UI_LIMITS = {
|
|
32
31
|
blocks: 50,
|
|
@@ -34,6 +33,7 @@ export const UI_LIMITS = {
|
|
|
34
33
|
checklistItems: 100,
|
|
35
34
|
textChars: 20000,
|
|
36
35
|
payloadBytes: 2000,
|
|
36
|
+
componentDataBytes: 32768,
|
|
37
37
|
};
|
|
38
38
|
const BADGE_MAX = 32;
|
|
39
39
|
/** Longest item / block `id` and open target `item`. */
|
|
@@ -46,7 +46,7 @@ const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
|
46
46
|
const MD_INLINE_LINK = /\]\(\s*<?([^\s)>]*)/g;
|
|
47
47
|
const MD_REF_DEF = /^ {0,3}\[[^\]\n]+\]:[ \t]*<?([^\s>]*)/gm;
|
|
48
48
|
const MD_AUTOLINK = /<([a-zA-Z][a-zA-Z0-9+.-]{1,31}:[^<>\s]*)>/g;
|
|
49
|
-
/** Markdown
|
|
49
|
+
/** Link / image targets in Markdown (inline, reference definitions, angle-bracket autolinks). */
|
|
50
50
|
function markdownLinks(md) {
|
|
51
51
|
const out = [];
|
|
52
52
|
for (const re of [MD_INLINE_LINK, MD_REF_DEF, MD_AUTOLINK]) {
|
|
@@ -55,7 +55,7 @@ function markdownLinks(md) {
|
|
|
55
55
|
}
|
|
56
56
|
return out;
|
|
57
57
|
}
|
|
58
|
-
/**
|
|
58
|
+
/** UTF-8 bytes after JSON serialization; undefined when not serializable. */
|
|
59
59
|
function jsonBytes(v) {
|
|
60
60
|
try {
|
|
61
61
|
const s = JSON.stringify(v);
|
|
@@ -65,15 +65,80 @@ function jsonBytes(v) {
|
|
|
65
65
|
return undefined;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
+
const JSON_KINDS = "null, booleans, finite numbers, strings, arrays, plain objects";
|
|
69
|
+
/**
|
|
70
|
+
* The first part of `v` (`at` is its path) that JSON would not carry as is, or undefined: a value
|
|
71
|
+
* `JSON.stringify` drops, rewrites or throws on (a function, symbol or bigint, NaN or ±Infinity,
|
|
72
|
+
* `undefined` in an array, an object that is not plain such as a Map or a Date, a cycle). A plain
|
|
73
|
+
* object's `undefined` property is accepted: JSON drops it, which reads as an absent optional field.
|
|
74
|
+
*/
|
|
75
|
+
function jsonProblem(v, at, seen = new Set()) {
|
|
76
|
+
if (v === null || typeof v === "boolean" || typeof v === "string")
|
|
77
|
+
return undefined;
|
|
78
|
+
if (typeof v === "number")
|
|
79
|
+
return Number.isFinite(v) ? undefined : `${at} is ${v}`;
|
|
80
|
+
if (v === undefined)
|
|
81
|
+
return `${at} is undefined`;
|
|
82
|
+
if (typeof v !== "object")
|
|
83
|
+
return `${at} is a ${typeof v}`;
|
|
84
|
+
if (seen.has(v))
|
|
85
|
+
return `${at} is a cycle`;
|
|
86
|
+
seen.add(v);
|
|
87
|
+
try {
|
|
88
|
+
if (Array.isArray(v)) {
|
|
89
|
+
for (let i = 0; i < v.length; i++) {
|
|
90
|
+
const p = jsonProblem(v[i], `${at}[${i}]`, seen);
|
|
91
|
+
if (p !== undefined)
|
|
92
|
+
return p;
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
const proto = Object.getPrototypeOf(v);
|
|
97
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
98
|
+
return `${at} is a ${proto.constructor?.name || "non-plain object"}`;
|
|
99
|
+
}
|
|
100
|
+
for (const [k, x] of Object.entries(v)) {
|
|
101
|
+
if (x === undefined)
|
|
102
|
+
continue;
|
|
103
|
+
const p = jsonProblem(x, `${at}.${k}`, seen);
|
|
104
|
+
if (p !== undefined)
|
|
105
|
+
return p;
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
seen.delete(v);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
68
113
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
114
|
+
* Validates the view a plugin returns and returns the list of problems (empty = valid). Links and
|
|
115
|
+
* images may only be absolute http(s) addresses;
|
|
116
|
+
* the Markdown check is defense in depth, and web rendering must still accept only http(s) links
|
|
117
|
+
* and not render native HTML.
|
|
118
|
+
* The `actionId` of buttons and forms is unique within the whole view (action callbacks tell the
|
|
119
|
+
* source by it).
|
|
120
|
+
* `data` is accepted only with `opts.component` (the view of a component contribution): JSON as is
|
|
121
|
+
* (nothing JSON would drop or rewrite, see `jsonProblem`), up to `UI_LIMITS.componentDataBytes`
|
|
122
|
+
* bytes of UTF-8.
|
|
72
123
|
*/
|
|
73
|
-
export function validateUiView(v) {
|
|
124
|
+
export function validateUiView(v, opts = {}) {
|
|
74
125
|
if (!isObj(v))
|
|
75
126
|
return ["view must be an object"];
|
|
76
127
|
const out = [];
|
|
128
|
+
if (v.data !== undefined) {
|
|
129
|
+
if (opts.component !== true)
|
|
130
|
+
out.push("view data is only allowed for component views");
|
|
131
|
+
else {
|
|
132
|
+
const problem = jsonProblem(v.data, "data");
|
|
133
|
+
if (problem !== undefined)
|
|
134
|
+
out.push(`view data must be JSON (${JSON_KINDS}): ${problem}`);
|
|
135
|
+
else {
|
|
136
|
+
const n = jsonBytes(v.data) ?? 0;
|
|
137
|
+
if (n > UI_LIMITS.componentDataBytes)
|
|
138
|
+
out.push(`view data is ${n} bytes; the limit is ${UI_LIMITS.componentDataBytes}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
77
142
|
let chars = 0;
|
|
78
143
|
const text = (at, s, nonEmpty = false) => {
|
|
79
144
|
if (typeof s !== "string" || (nonEmpty && s === "")) {
|
|
@@ -286,22 +351,31 @@ export function validateUiView(v) {
|
|
|
286
351
|
out.push(`view text must be at most ${UI_LIMITS.textChars} characters in total`);
|
|
287
352
|
return out;
|
|
288
353
|
}
|
|
289
|
-
/**
|
|
354
|
+
/**
|
|
355
|
+
* The version marker of the `postMessage` protocol between the outer page and the embedded iframe.
|
|
356
|
+
*/
|
|
290
357
|
export const EMBED_PROTOCOL = "capybara-embed/1";
|
|
291
358
|
const NAV_MAX = 2000;
|
|
292
359
|
const RESIZE_MAX = 10000;
|
|
293
360
|
const TOAST_MAX = 500;
|
|
294
|
-
// capybara:embed-nav-begin
|
|
295
|
-
//
|
|
296
|
-
//
|
|
361
|
+
// capybara:embed-nav-begin (this section is verbatim identical in packages/plugin-sdk/src/ui.ts and apps/web/src/lib/embed-bridge.ts, checked by a test)
|
|
362
|
+
// Control characters and backslash: browsers treat `/\host` as `//host`, and strip newlines / tabs
|
|
363
|
+
// inside a path
|
|
364
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are exactly what must be rejected
|
|
297
365
|
const NAV_BAD = /[\u0000-\u001f\u007f\\]/;
|
|
298
|
-
/**
|
|
366
|
+
/**
|
|
367
|
+
* Encoded `/`, `\` and control characters in the path part (any case): decoding them would change
|
|
368
|
+
* the path structure.
|
|
369
|
+
*/
|
|
299
370
|
const NAV_BAD_ENCODED = /%(?:2f|5c|[01][0-9a-f]|7f)/i;
|
|
300
371
|
/**
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
372
|
+
* In-site path: starts with a single `/`, has no `//` anywhere, no control characters or
|
|
373
|
+
* backslashes; the path part has no `.` / `..` segments
|
|
374
|
+
* (including `%2e` in any case), no encoded `/` (`%2f`), `\` (`%5c`) or control characters
|
|
375
|
+
* (`%00`–`%1f`, `%7f`);
|
|
376
|
+
* and after URL normalization it is exactly identical to the original and does not start with `//`:
|
|
377
|
+
* normalization cannot turn it into another path,
|
|
378
|
+
* so handing it to in-site routing cannot jump outside the site or to a parent directory.
|
|
305
379
|
*/
|
|
306
380
|
function isInSitePath(p) {
|
|
307
381
|
if (!p.startsWith("/") || p.includes("//") || NAV_BAD.test(p))
|
|
@@ -325,8 +399,9 @@ function isInSitePath(p) {
|
|
|
325
399
|
}
|
|
326
400
|
// capybara:embed-nav-end
|
|
327
401
|
/**
|
|
328
|
-
*
|
|
329
|
-
*
|
|
402
|
+
* Parses a message sent by the iframe: returns it only when protocol, type and fields are all right
|
|
403
|
+
* (a new object keeping only known fields), otherwise null.
|
|
404
|
+
* The outer page must also first check that the message source is this iframe.
|
|
330
405
|
*/
|
|
331
406
|
export function parseEmbedChildMessage(m) {
|
|
332
407
|
if (!isObj(m) || m.protocol !== EMBED_PROTOCOL)
|
|
@@ -352,6 +427,8 @@ export function parseEmbedChildMessage(m) {
|
|
|
352
427
|
return typeof m.text === "string" && m.text !== "" && m.text.length <= TOAST_MAX
|
|
353
428
|
? { protocol, type: "toast", text: m.text }
|
|
354
429
|
: null;
|
|
430
|
+
case "panel-mode":
|
|
431
|
+
return typeof m.full === "boolean" ? { protocol, type: "panel-mode", full: m.full } : null;
|
|
355
432
|
default:
|
|
356
433
|
return null;
|
|
357
434
|
}
|
package/dist/url.d.ts
CHANGED