@capybara-hq/plugin-sdk 0.1.0-rc.3 → 0.1.0-rc.30
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.d.ts +319 -0
- package/dist/device-protocol.js +559 -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 +21 -1
- package/dist/index.js +21 -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 +15 -0
- package/dist/sandbox-linux-runtime-source.js +1421 -0
- package/dist/sandbox-native-runtime-source.d.ts +8 -0
- package/dist/sandbox-native-runtime-source.js +307 -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.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/ui.d.ts
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
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 { 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.
|
|
@@ -20,18 +8,25 @@ export declare function normalizePlace(place: UiPlace): Exclude<UiPlace, "conver
|
|
|
20
8
|
export declare const UI_ICONS: readonly ["list-checks", "layout-grid", "file", "chart", "calendar", "users", "bot", "book", "message-square", "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,27 @@ 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
|
-
/**
|
|
49
|
-
* A retired id kept answering for a release: it is not listed, and fetching it renders (or
|
|
50
|
-
* embeds) the named contribution of the same extension and kind. It still needs its entry in
|
|
51
|
-
* `permissions.ui`, and no `ctx.ui.view` of its own.
|
|
52
|
-
*/
|
|
53
|
-
aliasOf?: string;
|
|
54
53
|
}
|
|
55
54
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
55
|
+
* Blocks of the render schema. Text is for humans and shown as is (the plugin decides the language
|
|
56
|
+
* itself, usually taking `locale`).
|
|
57
|
+
* `text.markdown` does not support native HTML, and links may only be absolute http(s) addresses.
|
|
58
58
|
*/
|
|
59
59
|
export type UiBlock = {
|
|
60
60
|
type: "heading";
|
|
@@ -86,8 +86,10 @@ export type UiBlock = {
|
|
|
86
86
|
label: string;
|
|
87
87
|
}[];
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
89
|
+
* Each row takes its cell by column key, and a column may be missing. When rendering, use
|
|
90
|
+
* `Object.hasOwn(row, key)` to tell whether a cell exists,
|
|
91
|
+
* do not use `row[key]` or `in`: a column key may be `constructor` / `toString` and the like,
|
|
92
|
+
* which would pick up values from the prototype chain.
|
|
91
93
|
*/
|
|
92
94
|
rows: Record<string, string>[];
|
|
93
95
|
/** Per row (same index), an open target or null; never a key inside a row. */
|
|
@@ -121,20 +123,32 @@ export type UiBlock = {
|
|
|
121
123
|
actionId: string;
|
|
122
124
|
submitLabel: string;
|
|
123
125
|
};
|
|
124
|
-
/**
|
|
126
|
+
/** A JSON value: what survives `JSON.stringify` and `JSON.parse` unchanged. */
|
|
127
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
128
|
+
[key: string]: JsonValue;
|
|
129
|
+
};
|
|
130
|
+
/** A plugin view: a block list with limits; `badge` is shown on the tab (e.g. "2/4"). */
|
|
125
131
|
export interface UiView {
|
|
126
132
|
badge?: string;
|
|
127
133
|
/** The ⤢ of an inline card's title row and a properties section's header. */
|
|
128
134
|
open?: UiOpen;
|
|
135
|
+
/** A component's view may have no blocks (`[]`). */
|
|
129
136
|
blocks: UiBlock[];
|
|
137
|
+
/**
|
|
138
|
+
* Only from a component's render (`useView` hands it to the component): at most
|
|
139
|
+
* `UI_LIMITS.componentDataBytes` bytes of JSON. Refused in the views of the other kinds.
|
|
140
|
+
*/
|
|
141
|
+
data?: JsonValue;
|
|
130
142
|
}
|
|
131
143
|
/**
|
|
132
|
-
*
|
|
133
|
-
* - `blocks
|
|
134
|
-
* - `tableRows
|
|
135
|
-
*
|
|
136
|
-
* - `
|
|
137
|
-
* - `
|
|
144
|
+
* View limits (checked uniformly by {@link validateUiView}):
|
|
145
|
+
* - `blocks`: number of blocks;
|
|
146
|
+
* - `tableRows`: number of table rows, also used as the upper bound for keyValue items, table
|
|
147
|
+
* columns, chart points and buttons;
|
|
148
|
+
* - `checklistItems`: number of checklist items;
|
|
149
|
+
* - `textChars`: total characters of all text in the whole view (form JSON included);
|
|
150
|
+
* - `payloadBytes`: UTF-8 bytes of a single button `payload` after JSON serialization.
|
|
151
|
+
* - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
|
|
138
152
|
*/
|
|
139
153
|
export declare const UI_LIMITS: {
|
|
140
154
|
readonly blocks: 50;
|
|
@@ -142,28 +156,64 @@ export declare const UI_LIMITS: {
|
|
|
142
156
|
readonly checklistItems: 100;
|
|
143
157
|
readonly textChars: 20000;
|
|
144
158
|
readonly payloadBytes: 2000;
|
|
159
|
+
readonly componentDataBytes: 32768;
|
|
145
160
|
};
|
|
146
161
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
162
|
+
* Validates the view a plugin returns and returns the list of problems (empty = valid). Links and
|
|
163
|
+
* images may only be absolute http(s) addresses;
|
|
164
|
+
* the Markdown check is defense in depth, and web rendering must still accept only http(s) links
|
|
165
|
+
* and not render native HTML.
|
|
166
|
+
* The `actionId` of buttons and forms is unique within the whole view (action callbacks tell the
|
|
167
|
+
* source by it).
|
|
168
|
+
* `data` is accepted only with `opts.component` (the view of a component contribution): JSON as is
|
|
169
|
+
* (nothing JSON would drop or rewrite, see `jsonProblem`), up to `UI_LIMITS.componentDataBytes`
|
|
170
|
+
* bytes of UTF-8.
|
|
150
171
|
*/
|
|
151
|
-
export declare function validateUiView(v: unknown
|
|
172
|
+
export declare function validateUiView(v: unknown, opts?: {
|
|
173
|
+
component?: boolean;
|
|
174
|
+
}): string[];
|
|
152
175
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
176
|
+
* The caller's role in the org (owner / admin / member / guest, highest first). A slot's `minRole`
|
|
177
|
+
* decides who may use its contributions, then its scope's rule (the kernel answers 404 to anyone
|
|
178
|
+
* else, so the extension never sees such a request): `org.page` member and up,
|
|
179
|
+
* `org.settings.section` admin and up; conversation slots any role that can read the
|
|
180
|
+
* conversation; `agent.detail.section` any role that can read the agent (read-only viewers
|
|
181
|
+
* included: tighten on `role` if you must).
|
|
155
182
|
*/
|
|
156
183
|
export type UiRole = "owner" | "admin" | "member" | "guest";
|
|
157
|
-
/**
|
|
158
|
-
export interface
|
|
159
|
-
orgId: string;
|
|
184
|
+
/** The render args every scope shares (identity comes from the kernel's auth, never the caller's credentials). */
|
|
185
|
+
export interface UiRenderArgsBase {
|
|
160
186
|
accountId: string;
|
|
161
|
-
/**
|
|
162
|
-
|
|
163
|
-
/** 仅对话视图。 */
|
|
164
|
-
conversationId?: string;
|
|
187
|
+
/** The catalog slot the contribution resolved to. */
|
|
188
|
+
slot: UiSlotId;
|
|
165
189
|
locale: Locale;
|
|
166
190
|
signal: AbortSignal;
|
|
191
|
+
/**
|
|
192
|
+
* The extension's effective deployment config: for an org, the platform's deployment config
|
|
193
|
+
* with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
|
|
194
|
+
* platform's config (equal to `ctx.config`) while the org follows it; for the platform scope,
|
|
195
|
+
* the platform's config. Use it, not `ctx.config`, for work done for this org. Optional in the
|
|
196
|
+
* type so older extensions compile; the kernel always passes it.
|
|
197
|
+
*/
|
|
198
|
+
config?: unknown;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The parameters passed when the kernel calls the plugin's `render`: the position within the org
|
|
202
|
+
* (conversation, agent, org, file).
|
|
203
|
+
*/
|
|
204
|
+
export interface UiOrgRenderArgs extends UiRenderArgsBase {
|
|
205
|
+
/** The scope of {@link slot}: which of the context ids below are set. */
|
|
206
|
+
scope: Exclude<UiSlotScope, "platform">;
|
|
207
|
+
orgId: string;
|
|
208
|
+
/**
|
|
209
|
+
* The caller's role in `orgId` at this moment (filled by the kernel from membership; a plugin may
|
|
210
|
+
* use it to tighten buttons etc., see {@link UiRole}).
|
|
211
|
+
*/
|
|
212
|
+
role: UiRole;
|
|
213
|
+
/** Conversation views only. */
|
|
214
|
+
conversationId?: string;
|
|
215
|
+
/** Only an agent view (`agent.detail.section`): an agent of `orgId` the caller can read. */
|
|
216
|
+
agentId?: string;
|
|
167
217
|
/** A panel opened from an open target: the block or item `id` to scroll to. */
|
|
168
218
|
item?: string;
|
|
169
219
|
/**
|
|
@@ -175,22 +225,43 @@ export interface UiRenderArgs {
|
|
|
175
225
|
callId: string;
|
|
176
226
|
key?: string;
|
|
177
227
|
};
|
|
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
228
|
}
|
|
187
|
-
/**
|
|
188
|
-
|
|
229
|
+
/**
|
|
230
|
+
* The render args of a `platform.page` contribution: rendered for a super admin in the admin
|
|
231
|
+
* console, with no org (and so no org role, conversation or agent).
|
|
232
|
+
*/
|
|
233
|
+
export interface UiPlatformRenderArgs extends UiRenderArgsBase {
|
|
234
|
+
scope: "platform";
|
|
235
|
+
orgId?: undefined;
|
|
236
|
+
role: "superAdmin";
|
|
237
|
+
conversationId?: undefined;
|
|
238
|
+
agentId?: undefined;
|
|
239
|
+
item?: undefined;
|
|
240
|
+
card?: undefined;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* The parameters passed when the kernel calls the plugin's `render`: narrow on `scope`
|
|
244
|
+
* (`"platform"` has no `orgId`).
|
|
245
|
+
*/
|
|
246
|
+
export type UiRenderArgs = UiOrgRenderArgs | UiPlatformRenderArgs;
|
|
247
|
+
/** What a button or form submit adds to the render args. */
|
|
248
|
+
export interface UiActionInput {
|
|
189
249
|
actionId: string;
|
|
190
250
|
payload?: unknown;
|
|
191
251
|
answer?: FormAnswer;
|
|
192
252
|
}
|
|
193
|
-
/**
|
|
253
|
+
/** An action of an org-scope view. */
|
|
254
|
+
export interface UiOrgActionArgs extends UiOrgRenderArgs, UiActionInput {
|
|
255
|
+
}
|
|
256
|
+
/** An action of a `platform.page` view. */
|
|
257
|
+
export interface UiPlatformActionArgs extends UiPlatformRenderArgs, UiActionInput {
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* A button or form submission in a view: `actionId` comes from the block; a form submission carries
|
|
261
|
+
* `answer`.
|
|
262
|
+
*/
|
|
263
|
+
export type UiActionArgs = UiOrgActionArgs | UiPlatformActionArgs;
|
|
264
|
+
/** An action result: a notice, or a new view. */
|
|
194
265
|
export type UiActionResult = {
|
|
195
266
|
toast?: {
|
|
196
267
|
zh: string;
|
|
@@ -199,22 +270,62 @@ export type UiActionResult = {
|
|
|
199
270
|
} | {
|
|
200
271
|
view: UiView;
|
|
201
272
|
};
|
|
202
|
-
/**
|
|
203
|
-
export interface
|
|
273
|
+
/** The embed claims both scopes share. `exp` is Unix seconds. */
|
|
274
|
+
export interface EmbedClaimsBase {
|
|
204
275
|
plugin: string;
|
|
205
|
-
orgId: string;
|
|
206
276
|
accountId: string;
|
|
207
|
-
|
|
277
|
+
contribution: string;
|
|
278
|
+
exp: number;
|
|
279
|
+
}
|
|
280
|
+
/** An org-scope embed token's claims (every slot but `platform.page`). */
|
|
281
|
+
export interface OrgEmbedClaims extends EmbedClaimsBase {
|
|
282
|
+
scope: "org";
|
|
283
|
+
orgId: string;
|
|
284
|
+
/**
|
|
285
|
+
* The caller's role: written at issuance; `ctx.ui.verifyEmbedToken` returns the current role at
|
|
286
|
+
* validation time.
|
|
287
|
+
*/
|
|
208
288
|
role: UiRole;
|
|
209
289
|
conversationId?: string;
|
|
290
|
+
/** Only an agent embed's token (`agent.detail.section`): the agent it was issued for. */
|
|
291
|
+
agentId?: string;
|
|
210
292
|
/** Only a `file-preview` embed's token: the one file (of `conversationId`) it previews. */
|
|
211
293
|
fileId?: string;
|
|
212
|
-
contribution: string;
|
|
213
|
-
exp: number;
|
|
214
294
|
}
|
|
215
|
-
/**
|
|
295
|
+
/** A `platform.page` embed token's claims: a super admin's, with no org, conversation, agent or file. */
|
|
296
|
+
export interface PlatformEmbedClaims extends EmbedClaimsBase {
|
|
297
|
+
scope: "platform";
|
|
298
|
+
orgId?: undefined;
|
|
299
|
+
role: "superAdmin";
|
|
300
|
+
conversationId?: undefined;
|
|
301
|
+
agentId?: undefined;
|
|
302
|
+
fileId?: undefined;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Claims in an embed token (trustworthy after validation by `ctx.ui.verifyEmbedToken`): narrow on
|
|
306
|
+
* `scope` (`"platform"` has no
|
|
307
|
+
* `orgId` and `role` `"superAdmin"`).
|
|
308
|
+
*/
|
|
309
|
+
export type EmbedClaims = OrgEmbedClaims | PlatformEmbedClaims;
|
|
310
|
+
/**
|
|
311
|
+
* The version marker of the `postMessage` protocol between the outer page and the embedded iframe.
|
|
312
|
+
*/
|
|
216
313
|
export declare const EMBED_PROTOCOL = "capybara-embed/1";
|
|
217
|
-
/**
|
|
314
|
+
/**
|
|
315
|
+
* What an embed's `init` says about where it is shown, narrowed on `scope` like {@link EmbedClaims}:
|
|
316
|
+
* an org's page, panel, section or previewer (`orgId`, and the conversation when there is one), or
|
|
317
|
+
* a platform page of the admin console (no org).
|
|
318
|
+
*/
|
|
319
|
+
export type EmbedInitContext = {
|
|
320
|
+
scope: "org";
|
|
321
|
+
orgId: string;
|
|
322
|
+
conversationId?: string;
|
|
323
|
+
} | {
|
|
324
|
+
scope: "platform";
|
|
325
|
+
orgId?: undefined;
|
|
326
|
+
conversationId?: undefined;
|
|
327
|
+
};
|
|
328
|
+
/** Messages the outer page sends to the iframe. */
|
|
218
329
|
export type EmbedParentMessage = {
|
|
219
330
|
protocol: typeof EMBED_PROTOCOL;
|
|
220
331
|
type: "init";
|
|
@@ -222,10 +333,7 @@ export type EmbedParentMessage = {
|
|
|
222
333
|
locale: Locale;
|
|
223
334
|
theme: "dark" | "light";
|
|
224
335
|
tokens: Record<string, string>;
|
|
225
|
-
context:
|
|
226
|
-
orgId: string;
|
|
227
|
-
conversationId?: string;
|
|
228
|
-
};
|
|
336
|
+
context: EmbedInitContext;
|
|
229
337
|
} | {
|
|
230
338
|
protocol: typeof EMBED_PROTOCOL;
|
|
231
339
|
type: "token";
|
|
@@ -248,15 +356,18 @@ export type EmbedParentMessage = {
|
|
|
248
356
|
size: number;
|
|
249
357
|
data: ArrayBuffer;
|
|
250
358
|
};
|
|
251
|
-
/** iframe
|
|
359
|
+
/** Messages the iframe sends to the outer page. */
|
|
252
360
|
export type EmbedChildMessage =
|
|
253
|
-
/**
|
|
361
|
+
/** Height in CSS pixels, 0–10000. */
|
|
254
362
|
{
|
|
255
363
|
protocol: typeof EMBED_PROTOCOL;
|
|
256
364
|
type: "resize";
|
|
257
365
|
height: number;
|
|
258
366
|
}
|
|
259
|
-
/**
|
|
367
|
+
/**
|
|
368
|
+
* Only in-site paths: a single leading `/`, no `//`, no `.` / `..` segments (including `%2e`
|
|
369
|
+
* encoding), unchanged after normalization.
|
|
370
|
+
*/
|
|
260
371
|
| {
|
|
261
372
|
protocol: typeof EMBED_PROTOCOL;
|
|
262
373
|
type: "navigate";
|
|
@@ -267,7 +378,8 @@ export type EmbedChildMessage =
|
|
|
267
378
|
text: string;
|
|
268
379
|
};
|
|
269
380
|
/**
|
|
270
|
-
*
|
|
271
|
-
*
|
|
381
|
+
* Parses a message sent by the iframe: returns it only when protocol, type and fields are all right
|
|
382
|
+
* (a new object keeping only known fields), otherwise null.
|
|
383
|
+
* The outer page must also first check that the message source is this iframe.
|
|
272
384
|
*/
|
|
273
385
|
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.
|
|
@@ -21,12 +17,14 @@ export const UI_ICONS = [
|
|
|
21
17
|
"puzzle",
|
|
22
18
|
];
|
|
23
19
|
/**
|
|
24
|
-
*
|
|
25
|
-
* - `blocks
|
|
26
|
-
* - `tableRows
|
|
27
|
-
*
|
|
28
|
-
* - `
|
|
29
|
-
* - `
|
|
20
|
+
* View limits (checked uniformly by {@link validateUiView}):
|
|
21
|
+
* - `blocks`: number of blocks;
|
|
22
|
+
* - `tableRows`: number of table rows, also used as the upper bound for keyValue items, table
|
|
23
|
+
* columns, chart points and buttons;
|
|
24
|
+
* - `checklistItems`: number of checklist items;
|
|
25
|
+
* - `textChars`: total characters of all text in the whole view (form JSON included);
|
|
26
|
+
* - `payloadBytes`: UTF-8 bytes of a single button `payload` after JSON serialization.
|
|
27
|
+
* - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
|
|
30
28
|
*/
|
|
31
29
|
export const UI_LIMITS = {
|
|
32
30
|
blocks: 50,
|
|
@@ -34,6 +32,7 @@ export const UI_LIMITS = {
|
|
|
34
32
|
checklistItems: 100,
|
|
35
33
|
textChars: 20000,
|
|
36
34
|
payloadBytes: 2000,
|
|
35
|
+
componentDataBytes: 32768,
|
|
37
36
|
};
|
|
38
37
|
const BADGE_MAX = 32;
|
|
39
38
|
/** Longest item / block `id` and open target `item`. */
|
|
@@ -46,7 +45,7 @@ const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
|
46
45
|
const MD_INLINE_LINK = /\]\(\s*<?([^\s)>]*)/g;
|
|
47
46
|
const MD_REF_DEF = /^ {0,3}\[[^\]\n]+\]:[ \t]*<?([^\s>]*)/gm;
|
|
48
47
|
const MD_AUTOLINK = /<([a-zA-Z][a-zA-Z0-9+.-]{1,31}:[^<>\s]*)>/g;
|
|
49
|
-
/** Markdown
|
|
48
|
+
/** Link / image targets in Markdown (inline, reference definitions, angle-bracket autolinks). */
|
|
50
49
|
function markdownLinks(md) {
|
|
51
50
|
const out = [];
|
|
52
51
|
for (const re of [MD_INLINE_LINK, MD_REF_DEF, MD_AUTOLINK]) {
|
|
@@ -55,7 +54,7 @@ function markdownLinks(md) {
|
|
|
55
54
|
}
|
|
56
55
|
return out;
|
|
57
56
|
}
|
|
58
|
-
/**
|
|
57
|
+
/** UTF-8 bytes after JSON serialization; undefined when not serializable. */
|
|
59
58
|
function jsonBytes(v) {
|
|
60
59
|
try {
|
|
61
60
|
const s = JSON.stringify(v);
|
|
@@ -65,15 +64,80 @@ function jsonBytes(v) {
|
|
|
65
64
|
return undefined;
|
|
66
65
|
}
|
|
67
66
|
}
|
|
67
|
+
const JSON_KINDS = "null, booleans, finite numbers, strings, arrays, plain objects";
|
|
68
|
+
/**
|
|
69
|
+
* The first part of `v` (`at` is its path) that JSON would not carry as is, or undefined: a value
|
|
70
|
+
* `JSON.stringify` drops, rewrites or throws on (a function, symbol or bigint, NaN or ±Infinity,
|
|
71
|
+
* `undefined` in an array, an object that is not plain such as a Map or a Date, a cycle). A plain
|
|
72
|
+
* object's `undefined` property is accepted: JSON drops it, which reads as an absent optional field.
|
|
73
|
+
*/
|
|
74
|
+
function jsonProblem(v, at, seen = new Set()) {
|
|
75
|
+
if (v === null || typeof v === "boolean" || typeof v === "string")
|
|
76
|
+
return undefined;
|
|
77
|
+
if (typeof v === "number")
|
|
78
|
+
return Number.isFinite(v) ? undefined : `${at} is ${v}`;
|
|
79
|
+
if (v === undefined)
|
|
80
|
+
return `${at} is undefined`;
|
|
81
|
+
if (typeof v !== "object")
|
|
82
|
+
return `${at} is a ${typeof v}`;
|
|
83
|
+
if (seen.has(v))
|
|
84
|
+
return `${at} is a cycle`;
|
|
85
|
+
seen.add(v);
|
|
86
|
+
try {
|
|
87
|
+
if (Array.isArray(v)) {
|
|
88
|
+
for (let i = 0; i < v.length; i++) {
|
|
89
|
+
const p = jsonProblem(v[i], `${at}[${i}]`, seen);
|
|
90
|
+
if (p !== undefined)
|
|
91
|
+
return p;
|
|
92
|
+
}
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const proto = Object.getPrototypeOf(v);
|
|
96
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
97
|
+
return `${at} is a ${proto.constructor?.name || "non-plain object"}`;
|
|
98
|
+
}
|
|
99
|
+
for (const [k, x] of Object.entries(v)) {
|
|
100
|
+
if (x === undefined)
|
|
101
|
+
continue;
|
|
102
|
+
const p = jsonProblem(x, `${at}.${k}`, seen);
|
|
103
|
+
if (p !== undefined)
|
|
104
|
+
return p;
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
seen.delete(v);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
68
112
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
113
|
+
* Validates the view a plugin returns and returns the list of problems (empty = valid). Links and
|
|
114
|
+
* images may only be absolute http(s) addresses;
|
|
115
|
+
* the Markdown check is defense in depth, and web rendering must still accept only http(s) links
|
|
116
|
+
* and not render native HTML.
|
|
117
|
+
* The `actionId` of buttons and forms is unique within the whole view (action callbacks tell the
|
|
118
|
+
* source by it).
|
|
119
|
+
* `data` is accepted only with `opts.component` (the view of a component contribution): JSON as is
|
|
120
|
+
* (nothing JSON would drop or rewrite, see `jsonProblem`), up to `UI_LIMITS.componentDataBytes`
|
|
121
|
+
* bytes of UTF-8.
|
|
72
122
|
*/
|
|
73
|
-
export function validateUiView(v) {
|
|
123
|
+
export function validateUiView(v, opts = {}) {
|
|
74
124
|
if (!isObj(v))
|
|
75
125
|
return ["view must be an object"];
|
|
76
126
|
const out = [];
|
|
127
|
+
if (v.data !== undefined) {
|
|
128
|
+
if (opts.component !== true)
|
|
129
|
+
out.push("view data is only allowed for component views");
|
|
130
|
+
else {
|
|
131
|
+
const problem = jsonProblem(v.data, "data");
|
|
132
|
+
if (problem !== undefined)
|
|
133
|
+
out.push(`view data must be JSON (${JSON_KINDS}): ${problem}`);
|
|
134
|
+
else {
|
|
135
|
+
const n = jsonBytes(v.data) ?? 0;
|
|
136
|
+
if (n > UI_LIMITS.componentDataBytes)
|
|
137
|
+
out.push(`view data is ${n} bytes; the limit is ${UI_LIMITS.componentDataBytes}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
77
141
|
let chars = 0;
|
|
78
142
|
const text = (at, s, nonEmpty = false) => {
|
|
79
143
|
if (typeof s !== "string" || (nonEmpty && s === "")) {
|
|
@@ -286,22 +350,31 @@ export function validateUiView(v) {
|
|
|
286
350
|
out.push(`view text must be at most ${UI_LIMITS.textChars} characters in total`);
|
|
287
351
|
return out;
|
|
288
352
|
}
|
|
289
|
-
/**
|
|
353
|
+
/**
|
|
354
|
+
* The version marker of the `postMessage` protocol between the outer page and the embedded iframe.
|
|
355
|
+
*/
|
|
290
356
|
export const EMBED_PROTOCOL = "capybara-embed/1";
|
|
291
357
|
const NAV_MAX = 2000;
|
|
292
358
|
const RESIZE_MAX = 10000;
|
|
293
359
|
const TOAST_MAX = 500;
|
|
294
|
-
// capybara:embed-nav-begin
|
|
295
|
-
//
|
|
296
|
-
//
|
|
360
|
+
// 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)
|
|
361
|
+
// Control characters and backslash: browsers treat `/\host` as `//host`, and strip newlines / tabs
|
|
362
|
+
// inside a path
|
|
363
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are exactly what must be rejected
|
|
297
364
|
const NAV_BAD = /[\u0000-\u001f\u007f\\]/;
|
|
298
|
-
/**
|
|
365
|
+
/**
|
|
366
|
+
* Encoded `/`, `\` and control characters in the path part (any case): decoding them would change
|
|
367
|
+
* the path structure.
|
|
368
|
+
*/
|
|
299
369
|
const NAV_BAD_ENCODED = /%(?:2f|5c|[01][0-9a-f]|7f)/i;
|
|
300
370
|
/**
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
371
|
+
* In-site path: starts with a single `/`, has no `//` anywhere, no control characters or
|
|
372
|
+
* backslashes; the path part has no `.` / `..` segments
|
|
373
|
+
* (including `%2e` in any case), no encoded `/` (`%2f`), `\` (`%5c`) or control characters
|
|
374
|
+
* (`%00`–`%1f`, `%7f`);
|
|
375
|
+
* and after URL normalization it is exactly identical to the original and does not start with `//`:
|
|
376
|
+
* normalization cannot turn it into another path,
|
|
377
|
+
* so handing it to in-site routing cannot jump outside the site or to a parent directory.
|
|
305
378
|
*/
|
|
306
379
|
function isInSitePath(p) {
|
|
307
380
|
if (!p.startsWith("/") || p.includes("//") || NAV_BAD.test(p))
|
|
@@ -325,8 +398,9 @@ function isInSitePath(p) {
|
|
|
325
398
|
}
|
|
326
399
|
// capybara:embed-nav-end
|
|
327
400
|
/**
|
|
328
|
-
*
|
|
329
|
-
*
|
|
401
|
+
* Parses a message sent by the iframe: returns it only when protocol, type and fields are all right
|
|
402
|
+
* (a new object keeping only known fields), otherwise null.
|
|
403
|
+
* The outer page must also first check that the message source is this iframe.
|
|
330
404
|
*/
|
|
331
405
|
export function parseEmbedChildMessage(m) {
|
|
332
406
|
if (!isObj(m) || m.protocol !== EMBED_PROTOCOL)
|
package/dist/url.d.ts
CHANGED
package/dist/url.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Internal helper (not exported by index.ts): whether it is an absolute http(s) address no longer
|
|
3
|
+
* than max.
|
|
4
|
+
*/
|
|
2
5
|
export function isHttpUrl(v, max = 2000) {
|
|
3
6
|
if (typeof v !== "string" || v.length > max)
|
|
4
7
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/plugin-sdk",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.30",
|
|
4
4
|
"description": "Capybara plugin SDK: the types and pure functions plugins are written against",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,13 @@
|
|
|
28
28
|
"NOTICE"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"@types/mdast": "4.0.4",
|
|
31
32
|
"kysely": "^0.29.6",
|
|
33
|
+
"mdast-util-from-markdown": "2.1.0",
|
|
34
|
+
"mdast-util-gfm": "3.1.0",
|
|
35
|
+
"mdast-util-to-markdown": "2.2.0",
|
|
36
|
+
"micromark-extension-gfm": "3.0.0",
|
|
37
|
+
"saxes": "6.0.0",
|
|
32
38
|
"semver": "^7.8.5",
|
|
33
39
|
"yaml": "^2.9.1",
|
|
34
40
|
"zod": "^4.6.7"
|
|
@@ -55,6 +55,9 @@
|
|
|
55
55
|
"required": {
|
|
56
56
|
"type": "boolean"
|
|
57
57
|
},
|
|
58
|
+
"builtin": {
|
|
59
|
+
"type": "boolean"
|
|
60
|
+
},
|
|
58
61
|
"source": {
|
|
59
62
|
"type": "string",
|
|
60
63
|
"const": "npm"
|
|
@@ -94,6 +97,9 @@
|
|
|
94
97
|
"required": {
|
|
95
98
|
"type": "boolean"
|
|
96
99
|
},
|
|
100
|
+
"builtin": {
|
|
101
|
+
"type": "boolean"
|
|
102
|
+
},
|
|
97
103
|
"source": {
|
|
98
104
|
"type": "string",
|
|
99
105
|
"const": "workspace"
|