@capybara-hq/plugin-sdk 0.1.0-rc.26 → 0.1.0-rc.28
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/extension-points/model-provider.md +1 -1
- package/dist/cards.d.ts +17 -8
- package/dist/cards.js +21 -10
- package/dist/channel.d.ts +91 -47
- package/dist/channel.js +10 -5
- package/dist/connector-auth.d.ts +5 -2
- package/dist/connector-auth.js +14 -8
- package/dist/connector.d.ts +67 -32
- package/dist/ctx.d.ts +41 -23
- package/dist/define-extension.d.ts +21 -11
- package/dist/define-extension.js +10 -4
- package/dist/device-protocol.d.ts +2 -1
- package/dist/extension-point.js +1 -1
- package/dist/identity.d.ts +22 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +96 -64
- package/dist/model.js +25 -14
- package/dist/permissions.d.ts +6 -6
- package/dist/permissions.js +8 -32
- package/dist/plugin-package.d.ts +79 -38
- package/dist/plugin-package.js +57 -29
- package/dist/sandbox-linux-runtime-source.d.ts +15 -0
- package/dist/sandbox-linux-runtime-source.js +1421 -0
- package/dist/sandbox-runtime-source.d.ts +9 -3
- package/dist/sandbox-runtime-source.js +16 -4
- package/dist/sandbox.d.ts +4 -1
- package/dist/sandbox.js +7 -3
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-guide.d.ts +1 -1
- package/dist/setup-guide.js +1 -1
- package/dist/skill.d.ts +27 -17
- package/dist/skill.js +39 -25
- package/dist/storage.d.ts +45 -25
- package/dist/tool.d.ts +51 -23
- package/dist/tool.js +21 -9
- package/dist/ui-resolve.d.ts +2 -7
- package/dist/ui-resolve.js +7 -19
- package/dist/ui-slots.d.ts +1 -3
- package/dist/ui-slots.js +0 -9
- package/dist/ui.d.ts +63 -49
- package/dist/ui.js +36 -22
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/package.json +1 -1
package/dist/tool.js
CHANGED
|
@@ -54,7 +54,10 @@ export function validateToolPresentation(spec) {
|
|
|
54
54
|
return out;
|
|
55
55
|
}
|
|
56
56
|
const DISPLAY_MAX = 200;
|
|
57
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Validates a {@link ToolDisplay} and returns the list of problems (empty = valid); length is
|
|
59
|
+
* counted in Unicode code points.
|
|
60
|
+
*/
|
|
58
61
|
export function validateToolDisplay(d) {
|
|
59
62
|
if (typeof d !== "object" || d === null || Array.isArray(d))
|
|
60
63
|
return ["display must be an object"];
|
|
@@ -69,7 +72,7 @@ export function validateToolDisplay(d) {
|
|
|
69
72
|
}
|
|
70
73
|
return out;
|
|
71
74
|
}
|
|
72
|
-
/**
|
|
75
|
+
/** A tool execution failure: message is for the model and must be in English and actionable. */
|
|
73
76
|
export class ToolError extends Error {
|
|
74
77
|
kind;
|
|
75
78
|
constructor(message, opts) {
|
|
@@ -78,9 +81,12 @@ export class ToolError extends Error {
|
|
|
78
81
|
this.kind = opts?.kind ?? "error";
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
|
-
/**
|
|
84
|
+
/** Plugin tool name rule. */
|
|
82
85
|
export const EXTENSION_TOOL_NAME = /^[a-zA-Z0-9_-]{1,40}$/;
|
|
83
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Validates the tool declarations a plugin registers and returns the list of problems (empty =
|
|
88
|
+
* valid).
|
|
89
|
+
*/
|
|
84
90
|
export function validateToolSpec(spec) {
|
|
85
91
|
const out = [];
|
|
86
92
|
if (typeof spec?.name !== "string" || !EXTENSION_TOOL_NAME.test(spec.name))
|
|
@@ -109,7 +115,7 @@ const SCHEMA_KEYS = {
|
|
|
109
115
|
number: ["type", "minimum", "maximum"],
|
|
110
116
|
integer: ["type", "minimum", "maximum"],
|
|
111
117
|
};
|
|
112
|
-
/**
|
|
118
|
+
/** Checks whether a schema falls within the ParamSchema subset and returns the list of problems. */
|
|
113
119
|
function schemaProblems(schema) {
|
|
114
120
|
if (typeof schema !== "object" || schema === null || Array.isArray(schema))
|
|
115
121
|
return ["schema must be an object"];
|
|
@@ -138,7 +144,7 @@ function schemaProblems(schema) {
|
|
|
138
144
|
return out;
|
|
139
145
|
}
|
|
140
146
|
const isEnum = (s) => s.type === "string" && "enum" in s;
|
|
141
|
-
/**
|
|
147
|
+
/** Validates an interactive form declaration and returns the list of problems (empty = valid). */
|
|
142
148
|
export function validateInputForm(form) {
|
|
143
149
|
const out = [];
|
|
144
150
|
if (!form || !Array.isArray(form.fields))
|
|
@@ -167,7 +173,10 @@ export function validateInputForm(form) {
|
|
|
167
173
|
}
|
|
168
174
|
return out;
|
|
169
175
|
}
|
|
170
|
-
/**
|
|
176
|
+
/**
|
|
177
|
+
* Validates whether the answer a user submitted conforms to the form and returns the list of
|
|
178
|
+
* problems (empty = valid).
|
|
179
|
+
*/
|
|
171
180
|
export function validateAnswer(form, answer) {
|
|
172
181
|
const out = [];
|
|
173
182
|
const byKey = new Map(form.fields.map((f) => [f.key, f]));
|
|
@@ -176,7 +185,8 @@ export function validateAnswer(form, answer) {
|
|
|
176
185
|
out.push(`unknown field ${JSON.stringify(k)}`);
|
|
177
186
|
for (const f of form.fields) {
|
|
178
187
|
const at = `field ${JSON.stringify(f.key)}`;
|
|
179
|
-
//
|
|
188
|
+
// Look only at the answer's own keys: inherited properties such as `toString` / `constructor`
|
|
189
|
+
// do not count as answered
|
|
180
190
|
const v = Object.hasOwn(answer, f.key) ? answer[f.key] : undefined;
|
|
181
191
|
if (v === undefined) {
|
|
182
192
|
if (f.required)
|
|
@@ -217,7 +227,9 @@ export function validateAnswer(form, answer) {
|
|
|
217
227
|
}
|
|
218
228
|
return out;
|
|
219
229
|
}
|
|
220
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* An allowOther enum field accepts any non-empty text; the rest are validated against the schema.
|
|
232
|
+
*/
|
|
221
233
|
function otherOrValue(f, v) {
|
|
222
234
|
if (f.allowOther && isEnum(f.schema)) {
|
|
223
235
|
return typeof v === "string" && v !== "" ? undefined : "other text must be a non-empty string";
|
package/dist/ui-resolve.d.ts
CHANGED
|
@@ -19,15 +19,11 @@ export interface DroppedUiContribution {
|
|
|
19
19
|
ref: string;
|
|
20
20
|
reason: UiDropReason;
|
|
21
21
|
}
|
|
22
|
-
/** The slot reference a contribution names: its `slot`, or the slot of its deprecated `place`. */
|
|
23
|
-
export declare function slotRefOf(c: UiContribution): string;
|
|
24
22
|
/**
|
|
25
23
|
* Resolves the slots of a manifest's `ui` against the catalog (UI slots spec §3.2). Assumes
|
|
26
24
|
* `validateUiContributions` passed; never throws. A contribution to an unknown slot or to a version
|
|
27
|
-
* other than the slot's is dropped
|
|
28
|
-
*
|
|
29
|
-
* `unknownAnchors` and the contribution keeps the slot's default position. `deprecatedPlace` lists
|
|
30
|
-
* the ids that still say `place`. Both lists keep manifest order.
|
|
25
|
+
* other than the slot's is dropped; an `after` that is not an anchor of the slot is listed in
|
|
26
|
+
* `unknownAnchors` and the contribution keeps the slot's default position. Both lists keep manifest order.
|
|
31
27
|
*/
|
|
32
28
|
export declare function resolveUiSlots(ui: readonly UiContribution[] | undefined): {
|
|
33
29
|
resolved: ResolvedUiContribution[];
|
|
@@ -36,5 +32,4 @@ export declare function resolveUiSlots(ui: readonly UiContribution[] | undefined
|
|
|
36
32
|
id: string;
|
|
37
33
|
after: string;
|
|
38
34
|
}[];
|
|
39
|
-
deprecatedPlace: string[];
|
|
40
35
|
};
|
package/dist/ui-resolve.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/** The slot reference a contribution names: its `slot`, or the slot of its deprecated `place`. */
|
|
3
|
-
export function slotRefOf(c) {
|
|
4
|
-
// biome-ignore lint/style/noNonNullAssertion: validateUiContributions requires slot or place
|
|
5
|
-
return c.slot ?? PLACE_SLOTS[c.place];
|
|
6
|
-
}
|
|
1
|
+
import { parseSlotRef, uiSlot } from "./ui-slots.js";
|
|
7
2
|
/**
|
|
8
3
|
* Resolves the slots of a manifest's `ui` against the catalog (UI slots spec §3.2). Assumes
|
|
9
4
|
* `validateUiContributions` passed; never throws. A contribution to an unknown slot or to a version
|
|
10
|
-
* other than the slot's is dropped
|
|
11
|
-
*
|
|
12
|
-
* `unknownAnchors` and the contribution keeps the slot's default position. `deprecatedPlace` lists
|
|
13
|
-
* the ids that still say `place`. Both lists keep manifest order.
|
|
5
|
+
* other than the slot's is dropped; an `after` that is not an anchor of the slot is listed in
|
|
6
|
+
* `unknownAnchors` and the contribution keeps the slot's default position. Both lists keep manifest order.
|
|
14
7
|
*/
|
|
15
8
|
export function resolveUiSlots(ui) {
|
|
16
9
|
const list = ui ?? [];
|
|
17
10
|
const own = new Map();
|
|
18
11
|
for (const c of list) {
|
|
19
|
-
const ref = parseSlotRef(
|
|
12
|
+
const ref = parseSlotRef(c.slot);
|
|
20
13
|
const slot = ref === null ? undefined : uiSlot(ref.id);
|
|
21
14
|
own.set(c.id, ref === null || slot === undefined
|
|
22
15
|
? { ok: false, reason: "unknown-slot" }
|
|
@@ -27,15 +20,10 @@ export function resolveUiSlots(ui) {
|
|
|
27
20
|
const resolved = [];
|
|
28
21
|
const dropped = [];
|
|
29
22
|
const unknownAnchors = [];
|
|
30
|
-
const deprecatedPlace = [];
|
|
31
23
|
for (const c of list) {
|
|
32
|
-
|
|
33
|
-
deprecatedPlace.push(c.id);
|
|
34
|
-
const mine = own.get(c.id);
|
|
35
|
-
const target = c.aliasOf === undefined ? undefined : own.get(c.aliasOf);
|
|
36
|
-
const r = mine.ok && target !== undefined && !target.ok ? target : mine;
|
|
24
|
+
const r = own.get(c.id);
|
|
37
25
|
if (!r.ok) {
|
|
38
|
-
dropped.push({ id: c.id, ref:
|
|
26
|
+
dropped.push({ id: c.id, ref: c.slot, reason: r.reason });
|
|
39
27
|
continue;
|
|
40
28
|
}
|
|
41
29
|
const anchors = r.slot.anchors ?? [];
|
|
@@ -50,5 +38,5 @@ export function resolveUiSlots(ui) {
|
|
|
50
38
|
...(anchors.length > 0 && { after }),
|
|
51
39
|
});
|
|
52
40
|
}
|
|
53
|
-
return { resolved, dropped, unknownAnchors
|
|
41
|
+
return { resolved, dropped, unknownAnchors };
|
|
54
42
|
}
|
package/dist/ui-slots.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { UiKind
|
|
1
|
+
import type { UiKind } from "./ui.js";
|
|
2
2
|
export type UiSlotScope = "conversation" | "agent" | "org" | "platform" | "file";
|
|
3
3
|
export type UiSlotRole = "guest" | "member" | "admin" | "superAdmin";
|
|
4
4
|
/** Every slot id of the catalog, in catalog order (UI slots spec §3). */
|
|
@@ -44,8 +44,6 @@ export declare function parseSlotRef(ref: string): {
|
|
|
44
44
|
id: string;
|
|
45
45
|
version: number;
|
|
46
46
|
} | null;
|
|
47
|
-
/** @deprecated step A of the UI slots spec §4 */
|
|
48
|
-
export declare const PLACE_SLOTS: Readonly<Record<UiPlace, UiSlotId>>;
|
|
49
47
|
export declare const UI_ARRANGEABLE_SLOTS: readonly UiSlotId[];
|
|
50
48
|
/** Slots with one winner that replaces a built-in block. */
|
|
51
49
|
export declare const UI_SINGLE_SLOTS: readonly UiSlotId[];
|
package/dist/ui-slots.js
CHANGED
|
@@ -227,15 +227,6 @@ export function parseSlotRef(ref) {
|
|
|
227
227
|
return null;
|
|
228
228
|
return { id: m[1], version: m[2] === undefined ? 1 : Number(m[2]) };
|
|
229
229
|
}
|
|
230
|
-
/** @deprecated step A of the UI slots spec §4 */
|
|
231
|
-
export const PLACE_SLOTS = {
|
|
232
|
-
panel: "conversation.panel",
|
|
233
|
-
conversation: "conversation.panel",
|
|
234
|
-
section: "conversation.properties.section",
|
|
235
|
-
inline: "conversation.tool-result.card",
|
|
236
|
-
page: "org.page",
|
|
237
|
-
"file-preview": "file.preview",
|
|
238
|
-
};
|
|
239
230
|
export const UI_ARRANGEABLE_SLOTS = UI_SLOT_IDS.filter((id) => id !== "file.preview");
|
|
240
231
|
/** Slots with one winner that replaces a built-in block. */
|
|
241
232
|
export const UI_SINGLE_SLOTS = UI_SLOTS.filter((s) => s.cardinality === "single").map((s) => s.id);
|
package/dist/ui.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import type { Locale } from "./cards.js";
|
|
2
2
|
import { type FormAnswer, type InputForm } from "./tool.js";
|
|
3
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";
|
|
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.
|
|
@@ -42,13 +35,11 @@ export interface UiContribution {
|
|
|
42
35
|
en: string;
|
|
43
36
|
};
|
|
44
37
|
/**
|
|
45
|
-
* The slot it goes in: `"<id>"` (version 1) or `"<id>@<n>"`, an id of `UI_SLOTS`.
|
|
46
|
-
*
|
|
47
|
-
*
|
|
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`).
|
|
48
41
|
*/
|
|
49
|
-
slot
|
|
50
|
-
/** @deprecated use slot (UI slots spec §4, step A) */
|
|
51
|
-
place?: UiPlace;
|
|
42
|
+
slot: string;
|
|
52
43
|
/**
|
|
53
44
|
* One of the slot's `anchors` to be placed after; omitted (or not an anchor of the slot) = the
|
|
54
45
|
* slot's first anchor.
|
|
@@ -59,16 +50,11 @@ export interface UiContribution {
|
|
|
59
50
|
path?: string;
|
|
60
51
|
/** Icon from {@link UI_ICONS}; default `puzzle`. */
|
|
61
52
|
icon?: UiIcon;
|
|
62
|
-
/**
|
|
63
|
-
* A retired id kept answering for a release: it is not listed, and fetching it renders (or
|
|
64
|
-
* embeds) the named contribution of the same extension and kind. It still needs its entry in
|
|
65
|
-
* `permissions.ui`, and no `ctx.ui.view` of its own.
|
|
66
|
-
*/
|
|
67
|
-
aliasOf?: string;
|
|
68
53
|
}
|
|
69
54
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
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.
|
|
72
58
|
*/
|
|
73
59
|
export type UiBlock = {
|
|
74
60
|
type: "heading";
|
|
@@ -100,8 +86,10 @@ export type UiBlock = {
|
|
|
100
86
|
label: string;
|
|
101
87
|
}[];
|
|
102
88
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
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.
|
|
105
93
|
*/
|
|
106
94
|
rows: Record<string, string>[];
|
|
107
95
|
/** Per row (same index), an open target or null; never a key inside a row. */
|
|
@@ -139,7 +127,7 @@ export type UiBlock = {
|
|
|
139
127
|
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
140
128
|
[key: string]: JsonValue;
|
|
141
129
|
};
|
|
142
|
-
/**
|
|
130
|
+
/** A plugin view: a block list with limits; `badge` is shown on the tab (e.g. "2/4"). */
|
|
143
131
|
export interface UiView {
|
|
144
132
|
badge?: string;
|
|
145
133
|
/** The ⤢ of an inline card's title row and a properties section's header. */
|
|
@@ -153,12 +141,13 @@ export interface UiView {
|
|
|
153
141
|
data?: JsonValue;
|
|
154
142
|
}
|
|
155
143
|
/**
|
|
156
|
-
*
|
|
157
|
-
* - `blocks
|
|
158
|
-
* - `tableRows
|
|
159
|
-
*
|
|
160
|
-
* - `
|
|
161
|
-
* - `
|
|
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.
|
|
162
151
|
* - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
|
|
163
152
|
*/
|
|
164
153
|
export declare const UI_LIMITS: {
|
|
@@ -170,9 +159,12 @@ export declare const UI_LIMITS: {
|
|
|
170
159
|
readonly componentDataBytes: 32768;
|
|
171
160
|
};
|
|
172
161
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
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).
|
|
176
168
|
* `data` is accepted only with `opts.component` (the view of a component contribution): JSON as is
|
|
177
169
|
* (nothing JSON would drop or rewrite, see `jsonProblem`), up to `UI_LIMITS.componentDataBytes`
|
|
178
170
|
* bytes of UTF-8.
|
|
@@ -205,14 +197,20 @@ export interface UiRenderArgsBase {
|
|
|
205
197
|
*/
|
|
206
198
|
config?: unknown;
|
|
207
199
|
}
|
|
208
|
-
/**
|
|
200
|
+
/**
|
|
201
|
+
* The parameters passed when the kernel calls the plugin's `render`: the position within the org
|
|
202
|
+
* (conversation, agent, org, file).
|
|
203
|
+
*/
|
|
209
204
|
export interface UiOrgRenderArgs extends UiRenderArgsBase {
|
|
210
205
|
/** The scope of {@link slot}: which of the context ids below are set. */
|
|
211
206
|
scope: Exclude<UiSlotScope, "platform">;
|
|
212
207
|
orgId: string;
|
|
213
|
-
/**
|
|
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
|
+
*/
|
|
214
212
|
role: UiRole;
|
|
215
|
-
/**
|
|
213
|
+
/** Conversation views only. */
|
|
216
214
|
conversationId?: string;
|
|
217
215
|
/** Only an agent view (`agent.detail.section`): an agent of `orgId` the caller can read. */
|
|
218
216
|
agentId?: string;
|
|
@@ -241,7 +239,10 @@ export interface UiPlatformRenderArgs extends UiRenderArgsBase {
|
|
|
241
239
|
item?: undefined;
|
|
242
240
|
card?: undefined;
|
|
243
241
|
}
|
|
244
|
-
/**
|
|
242
|
+
/**
|
|
243
|
+
* The parameters passed when the kernel calls the plugin's `render`: narrow on `scope`
|
|
244
|
+
* (`"platform"` has no `orgId`).
|
|
245
|
+
*/
|
|
245
246
|
export type UiRenderArgs = UiOrgRenderArgs | UiPlatformRenderArgs;
|
|
246
247
|
/** What a button or form submit adds to the render args. */
|
|
247
248
|
export interface UiActionInput {
|
|
@@ -255,9 +256,12 @@ export interface UiOrgActionArgs extends UiOrgRenderArgs, UiActionInput {
|
|
|
255
256
|
/** An action of a `platform.page` view. */
|
|
256
257
|
export interface UiPlatformActionArgs extends UiPlatformRenderArgs, UiActionInput {
|
|
257
258
|
}
|
|
258
|
-
/**
|
|
259
|
+
/**
|
|
260
|
+
* A button or form submission in a view: `actionId` comes from the block; a form submission carries
|
|
261
|
+
* `answer`.
|
|
262
|
+
*/
|
|
259
263
|
export type UiActionArgs = UiOrgActionArgs | UiPlatformActionArgs;
|
|
260
|
-
/**
|
|
264
|
+
/** An action result: a notice, or a new view. */
|
|
261
265
|
export type UiActionResult = {
|
|
262
266
|
toast?: {
|
|
263
267
|
zh: string;
|
|
@@ -266,7 +270,7 @@ export type UiActionResult = {
|
|
|
266
270
|
} | {
|
|
267
271
|
view: UiView;
|
|
268
272
|
};
|
|
269
|
-
/** The embed claims both scopes share. `exp`
|
|
273
|
+
/** The embed claims both scopes share. `exp` is Unix seconds. */
|
|
270
274
|
export interface EmbedClaimsBase {
|
|
271
275
|
plugin: string;
|
|
272
276
|
accountId: string;
|
|
@@ -277,7 +281,10 @@ export interface EmbedClaimsBase {
|
|
|
277
281
|
export interface OrgEmbedClaims extends EmbedClaimsBase {
|
|
278
282
|
scope: "org";
|
|
279
283
|
orgId: string;
|
|
280
|
-
/**
|
|
284
|
+
/**
|
|
285
|
+
* The caller's role: written at issuance; `ctx.ui.verifyEmbedToken` returns the current role at
|
|
286
|
+
* validation time.
|
|
287
|
+
*/
|
|
281
288
|
role: UiRole;
|
|
282
289
|
conversationId?: string;
|
|
283
290
|
/** Only an agent embed's token (`agent.detail.section`): the agent it was issued for. */
|
|
@@ -295,11 +302,14 @@ export interface PlatformEmbedClaims extends EmbedClaimsBase {
|
|
|
295
302
|
fileId?: undefined;
|
|
296
303
|
}
|
|
297
304
|
/**
|
|
298
|
-
*
|
|
305
|
+
* Claims in an embed token (trustworthy after validation by `ctx.ui.verifyEmbedToken`): narrow on
|
|
306
|
+
* `scope` (`"platform"` has no
|
|
299
307
|
* `orgId` and `role` `"superAdmin"`).
|
|
300
308
|
*/
|
|
301
309
|
export type EmbedClaims = OrgEmbedClaims | PlatformEmbedClaims;
|
|
302
|
-
/**
|
|
310
|
+
/**
|
|
311
|
+
* The version marker of the `postMessage` protocol between the outer page and the embedded iframe.
|
|
312
|
+
*/
|
|
303
313
|
export declare const EMBED_PROTOCOL = "capybara-embed/1";
|
|
304
314
|
/**
|
|
305
315
|
* What an embed's `init` says about where it is shown, narrowed on `scope` like {@link EmbedClaims}:
|
|
@@ -315,7 +325,7 @@ export type EmbedInitContext = {
|
|
|
315
325
|
orgId?: undefined;
|
|
316
326
|
conversationId?: undefined;
|
|
317
327
|
};
|
|
318
|
-
/**
|
|
328
|
+
/** Messages the outer page sends to the iframe. */
|
|
319
329
|
export type EmbedParentMessage = {
|
|
320
330
|
protocol: typeof EMBED_PROTOCOL;
|
|
321
331
|
type: "init";
|
|
@@ -346,15 +356,18 @@ export type EmbedParentMessage = {
|
|
|
346
356
|
size: number;
|
|
347
357
|
data: ArrayBuffer;
|
|
348
358
|
};
|
|
349
|
-
/** iframe
|
|
359
|
+
/** Messages the iframe sends to the outer page. */
|
|
350
360
|
export type EmbedChildMessage =
|
|
351
|
-
/**
|
|
361
|
+
/** Height in CSS pixels, 0–10000. */
|
|
352
362
|
{
|
|
353
363
|
protocol: typeof EMBED_PROTOCOL;
|
|
354
364
|
type: "resize";
|
|
355
365
|
height: number;
|
|
356
366
|
}
|
|
357
|
-
/**
|
|
367
|
+
/**
|
|
368
|
+
* Only in-site paths: a single leading `/`, no `//`, no `.` / `..` segments (including `%2e`
|
|
369
|
+
* encoding), unchanged after normalization.
|
|
370
|
+
*/
|
|
358
371
|
| {
|
|
359
372
|
protocol: typeof EMBED_PROTOCOL;
|
|
360
373
|
type: "navigate";
|
|
@@ -365,7 +378,8 @@ export type EmbedChildMessage =
|
|
|
365
378
|
text: string;
|
|
366
379
|
};
|
|
367
380
|
/**
|
|
368
|
-
*
|
|
369
|
-
*
|
|
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.
|
|
370
384
|
*/
|
|
371
385
|
export declare function parseEmbedChildMessage(m: unknown): EmbedChildMessage | null;
|
package/dist/ui.js
CHANGED
|
@@ -17,12 +17,13 @@ export const UI_ICONS = [
|
|
|
17
17
|
"puzzle",
|
|
18
18
|
];
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
* - `blocks
|
|
22
|
-
* - `tableRows
|
|
23
|
-
*
|
|
24
|
-
* - `
|
|
25
|
-
* - `
|
|
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.
|
|
26
27
|
* - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
|
|
27
28
|
*/
|
|
28
29
|
export const UI_LIMITS = {
|
|
@@ -44,7 +45,7 @@ const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
|
44
45
|
const MD_INLINE_LINK = /\]\(\s*<?([^\s)>]*)/g;
|
|
45
46
|
const MD_REF_DEF = /^ {0,3}\[[^\]\n]+\]:[ \t]*<?([^\s>]*)/gm;
|
|
46
47
|
const MD_AUTOLINK = /<([a-zA-Z][a-zA-Z0-9+.-]{1,31}:[^<>\s]*)>/g;
|
|
47
|
-
/** Markdown
|
|
48
|
+
/** Link / image targets in Markdown (inline, reference definitions, angle-bracket autolinks). */
|
|
48
49
|
function markdownLinks(md) {
|
|
49
50
|
const out = [];
|
|
50
51
|
for (const re of [MD_INLINE_LINK, MD_REF_DEF, MD_AUTOLINK]) {
|
|
@@ -53,7 +54,7 @@ function markdownLinks(md) {
|
|
|
53
54
|
}
|
|
54
55
|
return out;
|
|
55
56
|
}
|
|
56
|
-
/**
|
|
57
|
+
/** UTF-8 bytes after JSON serialization; undefined when not serializable. */
|
|
57
58
|
function jsonBytes(v) {
|
|
58
59
|
try {
|
|
59
60
|
const s = JSON.stringify(v);
|
|
@@ -109,9 +110,12 @@ function jsonProblem(v, at, seen = new Set()) {
|
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
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).
|
|
115
119
|
* `data` is accepted only with `opts.component` (the view of a component contribution): JSON as is
|
|
116
120
|
* (nothing JSON would drop or rewrite, see `jsonProblem`), up to `UI_LIMITS.componentDataBytes`
|
|
117
121
|
* bytes of UTF-8.
|
|
@@ -346,22 +350,31 @@ export function validateUiView(v, opts = {}) {
|
|
|
346
350
|
out.push(`view text must be at most ${UI_LIMITS.textChars} characters in total`);
|
|
347
351
|
return out;
|
|
348
352
|
}
|
|
349
|
-
/**
|
|
353
|
+
/**
|
|
354
|
+
* The version marker of the `postMessage` protocol between the outer page and the embedded iframe.
|
|
355
|
+
*/
|
|
350
356
|
export const EMBED_PROTOCOL = "capybara-embed/1";
|
|
351
357
|
const NAV_MAX = 2000;
|
|
352
358
|
const RESIZE_MAX = 10000;
|
|
353
359
|
const TOAST_MAX = 500;
|
|
354
|
-
// capybara:embed-nav-begin
|
|
355
|
-
//
|
|
356
|
-
//
|
|
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
|
|
357
364
|
const NAV_BAD = /[\u0000-\u001f\u007f\\]/;
|
|
358
|
-
/**
|
|
365
|
+
/**
|
|
366
|
+
* Encoded `/`, `\` and control characters in the path part (any case): decoding them would change
|
|
367
|
+
* the path structure.
|
|
368
|
+
*/
|
|
359
369
|
const NAV_BAD_ENCODED = /%(?:2f|5c|[01][0-9a-f]|7f)/i;
|
|
360
370
|
/**
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
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.
|
|
365
378
|
*/
|
|
366
379
|
function isInSitePath(p) {
|
|
367
380
|
if (!p.startsWith("/") || p.includes("//") || NAV_BAD.test(p))
|
|
@@ -385,8 +398,9 @@ function isInSitePath(p) {
|
|
|
385
398
|
}
|
|
386
399
|
// capybara:embed-nav-end
|
|
387
400
|
/**
|
|
388
|
-
*
|
|
389
|
-
*
|
|
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.
|
|
390
404
|
*/
|
|
391
405
|
export function parseEmbedChildMessage(m) {
|
|
392
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;
|