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