@capybara-hq/plugin-sdk 0.1.0-rc.2 → 0.1.0-rc.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/agent-docs/agent-templates.md +59 -0
- package/agent-docs/concepts.md +63 -0
- package/agent-docs/connector-templates.md +48 -0
- package/agent-docs/extension-points/channel.md +15 -0
- package/agent-docs/extension-points/config-source.md +15 -0
- package/agent-docs/extension-points/connector.md +15 -0
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/counter.md +15 -0
- package/agent-docs/extension-points/directory.md +15 -0
- package/agent-docs/extension-points/file-preview.md +15 -0
- package/agent-docs/extension-points/identity-source.md +15 -0
- package/agent-docs/extension-points/model-provider.md +15 -0
- package/agent-docs/extension-points/object-store.md +15 -0
- package/agent-docs/extension-points/sandbox.md +15 -0
- package/agent-docs/extension-points/secret-store.md +15 -0
- package/agent-docs/extension-points/web-fetch.md +15 -0
- package/agent-docs/extension-points/web-search.md +15 -0
- package/agent-docs/extensions.md +88 -0
- package/agent-docs/plugin-format.md +100 -0
- package/agent-docs/setup.md +46 -0
- package/agent-docs/skills.md +44 -0
- package/agent-docs/tool-naming.md +21 -0
- package/dist/agent-template.d.ts +96 -2
- package/dist/agent-template.js +381 -3
- package/dist/bootstrap.d.ts +15 -1
- package/dist/bootstrap.js +17 -1
- package/dist/cards.d.ts +39 -5
- package/dist/cards.js +70 -11
- package/dist/channel.d.ts +20 -1
- 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 +24 -1
- package/dist/config-ui.js +89 -11
- package/dist/connector-auth.d.ts +2 -0
- package/dist/connector-auth.js +15 -0
- package/dist/context.d.ts +40 -0
- package/dist/context.js +2 -0
- package/dist/ctx.d.ts +86 -4
- package/dist/define-extension.d.ts +5 -1
- package/dist/define-extension.js +1 -0
- package/dist/dev-hosts.d.ts +6 -0
- package/dist/dev-hosts.js +48 -0
- package/dist/device-protocol.d.ts +260 -0
- package/dist/device-protocol.js +496 -0
- package/dist/directory.d.ts +11 -2
- package/dist/extension-point.d.ts +6 -0
- package/dist/extension-point.js +19 -14
- package/dist/file-preview.d.ts +9 -1
- package/dist/hooks.d.ts +111 -15
- package/dist/hooks.js +5 -0
- package/dist/index.d.ts +18 -1
- package/dist/index.js +18 -1
- package/dist/marketplace.d.ts +55 -2
- package/dist/marketplace.js +73 -3
- package/dist/model.d.ts +60 -2
- package/dist/model.js +22 -0
- package/dist/org-access.d.ts +27 -0
- package/dist/org-access.js +35 -0
- package/dist/permissions.d.ts +33 -8
- package/dist/permissions.js +89 -22
- package/dist/plugin-manifest.d.ts +60 -7
- package/dist/plugin-manifest.js +178 -7
- package/dist/sandbox.d.ts +239 -62
- package/dist/sandbox.js +99 -14
- 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 +9 -5
- package/dist/skill-invocation.js +18 -8
- package/dist/skill.d.ts +23 -3
- package/dist/skill.js +31 -6
- 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 +275 -0
- package/dist/theme-tokens.generated.js +172 -0
- package/dist/theme.d.ts +152 -0
- package/dist/theme.js +392 -0
- package/dist/tool.d.ts +26 -3
- package/dist/tool.js +8 -0
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +337 -0
- package/dist/ui-resolve.d.ts +40 -0
- package/dist/ui-resolve.js +54 -0
- package/dist/ui-slots.d.ts +55 -0
- package/dist/ui-slots.js +247 -0
- package/dist/ui.d.ts +143 -37
- package/dist/ui.js +65 -5
- package/dist/web.d.ts +30 -5
- package/package.json +10 -2
- package/schemas/bootstrap.v1.schema.json +6 -0
- package/schemas/connector-template.v1.schema.json +3 -0
- package/schemas/marketplace.v1.schema.json +50 -0
- package/schemas/plugin.v1.schema.json +144 -7
- package/schemas/theme.v1.schema.json +225 -0
package/dist/ui-slots.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/** Every slot id of the catalog, in catalog order (UI slots spec §3). */
|
|
2
|
+
export const UI_SLOT_IDS = [
|
|
3
|
+
"conversation.panel",
|
|
4
|
+
"conversation.properties.section",
|
|
5
|
+
"conversation.tool-result.card",
|
|
6
|
+
"org.page",
|
|
7
|
+
"file.preview",
|
|
8
|
+
"agent.detail.section",
|
|
9
|
+
"org.settings.section",
|
|
10
|
+
"platform.page",
|
|
11
|
+
"shell.brand",
|
|
12
|
+
"shell.overlay",
|
|
13
|
+
"conversation.empty",
|
|
14
|
+
"conversation.composer.frame",
|
|
15
|
+
];
|
|
16
|
+
const SLOT_DATA = [
|
|
17
|
+
{
|
|
18
|
+
id: "conversation.panel",
|
|
19
|
+
version: 1,
|
|
20
|
+
owner: "components/conversation/RightArea.tsx",
|
|
21
|
+
scope: "conversation",
|
|
22
|
+
accepts: ["view", "embed", "component"],
|
|
23
|
+
cardinality: "list",
|
|
24
|
+
minRole: "guest",
|
|
25
|
+
args: ["conversationId", "item"],
|
|
26
|
+
density: "regular",
|
|
27
|
+
icon: "optional",
|
|
28
|
+
description: {
|
|
29
|
+
en: "A panel beside the conversation, opened from the right area.",
|
|
30
|
+
zh: "对话旁的面板,从右侧区域打开。",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: "conversation.properties.section",
|
|
35
|
+
version: 1,
|
|
36
|
+
owner: "components/conversation/PropertiesSections.tsx",
|
|
37
|
+
scope: "conversation",
|
|
38
|
+
accepts: ["view", "embed", "component"],
|
|
39
|
+
cardinality: "list",
|
|
40
|
+
minRole: "guest",
|
|
41
|
+
args: ["conversationId"],
|
|
42
|
+
density: "dense",
|
|
43
|
+
icon: "optional",
|
|
44
|
+
anchors: ["context", "files", "background"],
|
|
45
|
+
description: {
|
|
46
|
+
en: "A section in the conversation properties list.",
|
|
47
|
+
zh: "对话属性列表中的一个分区。",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: "conversation.tool-result.card",
|
|
52
|
+
version: 1,
|
|
53
|
+
owner: "components/conversation/RightArea.tsx",
|
|
54
|
+
scope: "conversation",
|
|
55
|
+
accepts: ["view", "embed", "component"],
|
|
56
|
+
cardinality: "list",
|
|
57
|
+
minRole: "guest",
|
|
58
|
+
args: ["conversationId", "card"],
|
|
59
|
+
density: "regular",
|
|
60
|
+
icon: "optional",
|
|
61
|
+
description: {
|
|
62
|
+
en: "A card a tool result opens in the conversation.",
|
|
63
|
+
zh: "工具结果在对话中打开的卡片。",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: "org.page",
|
|
68
|
+
version: 1,
|
|
69
|
+
owner: "app/(app)/p/[plugin]/[id]/view.tsx",
|
|
70
|
+
scope: "org",
|
|
71
|
+
accepts: ["view", "embed", "component"],
|
|
72
|
+
cardinality: "list",
|
|
73
|
+
minRole: "member",
|
|
74
|
+
args: [],
|
|
75
|
+
density: "regular",
|
|
76
|
+
icon: "optional",
|
|
77
|
+
description: {
|
|
78
|
+
en: "A full page in the organization navigation.",
|
|
79
|
+
zh: "组织导航中的完整页面。",
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "file.preview",
|
|
84
|
+
version: 1,
|
|
85
|
+
owner: "components/conversation/FilePanel.tsx",
|
|
86
|
+
scope: "file",
|
|
87
|
+
accepts: ["embed"],
|
|
88
|
+
cardinality: "list",
|
|
89
|
+
minRole: "guest",
|
|
90
|
+
args: ["conversationId", "fileId"],
|
|
91
|
+
density: "regular",
|
|
92
|
+
icon: "optional",
|
|
93
|
+
description: {
|
|
94
|
+
en: "A previewer for a file of the conversation.",
|
|
95
|
+
zh: "对话中文件的预览器。",
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: "agent.detail.section",
|
|
100
|
+
version: 1,
|
|
101
|
+
owner: "components/agent/AgentPage.tsx",
|
|
102
|
+
scope: "agent",
|
|
103
|
+
accepts: ["view", "embed", "component"],
|
|
104
|
+
cardinality: "list",
|
|
105
|
+
minRole: "guest",
|
|
106
|
+
args: ["agentId"],
|
|
107
|
+
density: "regular",
|
|
108
|
+
icon: "optional",
|
|
109
|
+
description: {
|
|
110
|
+
en: "A section on the detail page of an agent.",
|
|
111
|
+
zh: "智能体详情页中的一个分区。",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: "org.settings.section",
|
|
116
|
+
version: 1,
|
|
117
|
+
owner: "app/(app)/settings/organization/view.tsx",
|
|
118
|
+
scope: "org",
|
|
119
|
+
accepts: ["view", "embed", "component"],
|
|
120
|
+
cardinality: "list",
|
|
121
|
+
minRole: "admin",
|
|
122
|
+
args: [],
|
|
123
|
+
density: "regular",
|
|
124
|
+
icon: "optional",
|
|
125
|
+
description: {
|
|
126
|
+
en: "A section on the organization settings page.",
|
|
127
|
+
zh: "组织设置页中的一个分区。",
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: "platform.page",
|
|
132
|
+
version: 1,
|
|
133
|
+
owner: "app/(app)/admin/p/[plugin]/[id]/view.tsx",
|
|
134
|
+
scope: "platform",
|
|
135
|
+
accepts: ["view", "embed", "component"],
|
|
136
|
+
cardinality: "list",
|
|
137
|
+
minRole: "superAdmin",
|
|
138
|
+
args: [],
|
|
139
|
+
density: "regular",
|
|
140
|
+
icon: "optional",
|
|
141
|
+
description: {
|
|
142
|
+
en: "A full page in the platform administration.",
|
|
143
|
+
zh: "平台管理中的完整页面。",
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
id: "shell.brand",
|
|
148
|
+
version: 1,
|
|
149
|
+
owner: "components/shell/AppFrame.tsx",
|
|
150
|
+
scope: "org",
|
|
151
|
+
accepts: ["component"],
|
|
152
|
+
cardinality: "single",
|
|
153
|
+
replaceable: true,
|
|
154
|
+
builtin: { en: "The logo and wordmark in the sidebar.", zh: "侧边栏中的标志与字标。" },
|
|
155
|
+
minRole: "guest",
|
|
156
|
+
args: [],
|
|
157
|
+
density: "regular",
|
|
158
|
+
icon: "none",
|
|
159
|
+
description: {
|
|
160
|
+
en: "The brand row of the sidebar (the mark of the collapsed rail).",
|
|
161
|
+
zh: "侧边栏的品牌行(收起后的窄栏标记)。",
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: "shell.overlay",
|
|
166
|
+
version: 1,
|
|
167
|
+
owner: "components/shell/AppFrame.tsx",
|
|
168
|
+
scope: "org",
|
|
169
|
+
accepts: ["component"],
|
|
170
|
+
cardinality: "list",
|
|
171
|
+
minRole: "guest",
|
|
172
|
+
args: [],
|
|
173
|
+
density: "regular",
|
|
174
|
+
icon: "none",
|
|
175
|
+
limits: { maxShown: 4 },
|
|
176
|
+
description: {
|
|
177
|
+
en: "A full-viewport layer over the workspace shell.",
|
|
178
|
+
zh: "覆盖工作区外壳的全视口图层。",
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
id: "conversation.empty",
|
|
183
|
+
version: 1,
|
|
184
|
+
owner: "components/conversation/NewConversation.tsx",
|
|
185
|
+
scope: "org",
|
|
186
|
+
accepts: ["component"],
|
|
187
|
+
cardinality: "single",
|
|
188
|
+
replaceable: true,
|
|
189
|
+
builtin: { en: "The greeting of the new-conversation page.", zh: "新对话页的问候区。" },
|
|
190
|
+
minRole: "guest",
|
|
191
|
+
args: [],
|
|
192
|
+
density: "regular",
|
|
193
|
+
icon: "none",
|
|
194
|
+
description: {
|
|
195
|
+
en: "The hero of the new-conversation page.",
|
|
196
|
+
zh: "新对话页的主视觉区。",
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
id: "conversation.composer.frame",
|
|
201
|
+
version: 1,
|
|
202
|
+
owner: "components/conversation/ComposerBar.tsx",
|
|
203
|
+
scope: "org",
|
|
204
|
+
accepts: ["component"],
|
|
205
|
+
cardinality: "single",
|
|
206
|
+
replaceable: true,
|
|
207
|
+
builtin: { en: "The frame around the message composer.", zh: "消息输入框外的边框。" },
|
|
208
|
+
minRole: "guest",
|
|
209
|
+
args: [],
|
|
210
|
+
density: "regular",
|
|
211
|
+
icon: "none",
|
|
212
|
+
description: {
|
|
213
|
+
en: "The frame around the composer, on the new-conversation and conversation pages.",
|
|
214
|
+
zh: "新对话页与对话页中输入框外的边框。",
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
];
|
|
218
|
+
export const UI_SLOTS = SLOT_DATA;
|
|
219
|
+
export function uiSlot(id) {
|
|
220
|
+
return UI_SLOTS.find((s) => s.id === id);
|
|
221
|
+
}
|
|
222
|
+
const SLOT_REF_RE = /^([a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+)(?:@([1-9][0-9]{0,2}))?$/;
|
|
223
|
+
/** Reads `<id>` or `<id>@<version>` (version 1 when omitted); does not check the catalog. */
|
|
224
|
+
export function parseSlotRef(ref) {
|
|
225
|
+
const m = SLOT_REF_RE.exec(ref);
|
|
226
|
+
if (!m)
|
|
227
|
+
return null;
|
|
228
|
+
return { id: m[1], version: m[2] === undefined ? 1 : Number(m[2]) };
|
|
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
|
+
export const UI_ARRANGEABLE_SLOTS = UI_SLOT_IDS.filter((id) => id !== "file.preview");
|
|
240
|
+
/** Slots with one winner that replaces a built-in block. */
|
|
241
|
+
export const UI_SINGLE_SLOTS = UI_SLOTS.filter((s) => s.cardinality === "single").map((s) => s.id);
|
|
242
|
+
/** Slots that accept the `component` kind. */
|
|
243
|
+
export const UI_COMPONENT_SLOTS = UI_SLOTS.filter((s) => s.accepts.includes("component")).map((s) => s.id);
|
|
244
|
+
export const UI_CONTRIBUTION_KEY_RE = /^[a-z][a-z0-9-]{1,40}\/[a-z][a-z0-9-]{0,39}$/;
|
|
245
|
+
export function uiContributionKey(plugin, id) {
|
|
246
|
+
return `${plugin}/${id}`;
|
|
247
|
+
}
|
package/dist/ui.d.ts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
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";
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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}).
|
|
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`).
|
|
12
9
|
*/
|
|
13
10
|
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">;
|
|
16
11
|
/**
|
|
17
12
|
* Icons a contribution may use (design system icon names; `puzzle` is the default and is drawn as
|
|
18
13
|
* the design `extension` icon). The title-bar button of a panel shows it.
|
|
@@ -20,18 +15,25 @@ export declare function normalizePlace(place: UiPlace): Exclude<UiPlace, "conver
|
|
|
20
15
|
export declare const UI_ICONS: readonly ["list-checks", "layout-grid", "file", "chart", "calendar", "users", "bot", "book", "message-square", "puzzle"];
|
|
21
16
|
export type UiIcon = (typeof UI_ICONS)[number];
|
|
22
17
|
/**
|
|
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
|
|
18
|
+
* An "open" target: a `conversation.panel` contribution of the same extension, scrolled to the
|
|
19
|
+
* block or item whose `id` equals `item` (the panel's render receives it as
|
|
20
|
+
* {@link UiRenderArgs.item}).
|
|
25
21
|
*/
|
|
26
22
|
export interface UiOpen {
|
|
27
23
|
contribution: string;
|
|
28
24
|
item?: string;
|
|
29
25
|
}
|
|
30
|
-
/** 界面贡献的种类:`view` = 渲染 schema(由我们的组件画);`embed` = 插件自己的页面放进 iframe。 */
|
|
31
|
-
export type UiKind = "view" | "embed";
|
|
32
26
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
27
|
+
* The kind of a UI contribution: `view` = a render schema drawn by the host's components; `embed` =
|
|
28
|
+
* the extension's own page in an iframe; `component` = a React component from the extension's
|
|
29
|
+
* client code (client extensions spec §5).
|
|
30
|
+
*/
|
|
31
|
+
export type UiKind = "view" | "embed" | "component";
|
|
32
|
+
/**
|
|
33
|
+
* One UI contribution of the extension manifest's `ui`. Its `id` must be listed in the list of its
|
|
34
|
+
* kind: `permissions.ui.views` (view), `permissions.ui.embeds` (embed) or
|
|
35
|
+
* `permissions.ui.components` (component, which also needs `permissions.client: true`); an embed's
|
|
36
|
+
* page is served by an extension route.
|
|
35
37
|
*/
|
|
36
38
|
export interface UiContribution {
|
|
37
39
|
id: string;
|
|
@@ -39,9 +41,21 @@ export interface UiContribution {
|
|
|
39
41
|
zh: string;
|
|
40
42
|
en: string;
|
|
41
43
|
};
|
|
42
|
-
|
|
44
|
+
/**
|
|
45
|
+
* The slot it goes in: `"<id>"` (version 1) or `"<id>@<n>"`, an id of `UI_SLOTS`. Exactly one of
|
|
46
|
+
* `slot` and `place`. An unknown slot or version does not fail the extension: the contribution is
|
|
47
|
+
* dropped (see `resolveUiSlots`).
|
|
48
|
+
*/
|
|
49
|
+
slot?: string;
|
|
50
|
+
/** @deprecated use slot (UI slots spec §4, step A) */
|
|
51
|
+
place?: UiPlace;
|
|
52
|
+
/**
|
|
53
|
+
* One of the slot's `anchors` to be placed after; omitted (or not an anchor of the slot) = the
|
|
54
|
+
* slot's first anchor.
|
|
55
|
+
*/
|
|
56
|
+
after?: string;
|
|
43
57
|
kind: UiKind;
|
|
44
|
-
/**
|
|
58
|
+
/** Embed only: a path under `/ui/` of the extension's routes, declared in `permissions.http` as GET. */
|
|
45
59
|
path?: string;
|
|
46
60
|
/** Icon from {@link UI_ICONS}; default `puzzle`. */
|
|
47
61
|
icon?: UiIcon;
|
|
@@ -121,12 +135,22 @@ export type UiBlock = {
|
|
|
121
135
|
actionId: string;
|
|
122
136
|
submitLabel: string;
|
|
123
137
|
};
|
|
138
|
+
/** A JSON value: what survives `JSON.stringify` and `JSON.parse` unchanged. */
|
|
139
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
140
|
+
[key: string]: JsonValue;
|
|
141
|
+
};
|
|
124
142
|
/** 插件视图:有上限的块列表;`badge` 显示在标签上(如「2/4」)。 */
|
|
125
143
|
export interface UiView {
|
|
126
144
|
badge?: string;
|
|
127
145
|
/** The ⤢ of an inline card's title row and a properties section's header. */
|
|
128
146
|
open?: UiOpen;
|
|
147
|
+
/** A component's view may have no blocks (`[]`). */
|
|
129
148
|
blocks: UiBlock[];
|
|
149
|
+
/**
|
|
150
|
+
* Only from a component's render (`useView` hands it to the component): at most
|
|
151
|
+
* `UI_LIMITS.componentDataBytes` bytes of JSON. Refused in the views of the other kinds.
|
|
152
|
+
*/
|
|
153
|
+
data?: JsonValue;
|
|
130
154
|
}
|
|
131
155
|
/**
|
|
132
156
|
* 视图上限({@link validateUiView} 统一检查):
|
|
@@ -135,6 +159,7 @@ export interface UiView {
|
|
|
135
159
|
* - `checklistItems`:清单项数;
|
|
136
160
|
* - `textChars`:整个视图所有文本(含表单 JSON)的字符总数;
|
|
137
161
|
* - `payloadBytes`:单个按钮 `payload` 的 JSON 序列化后 UTF-8 字节数。
|
|
162
|
+
* - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
|
|
138
163
|
*/
|
|
139
164
|
export declare const UI_LIMITS: {
|
|
140
165
|
readonly blocks: 50;
|
|
@@ -142,28 +167,55 @@ export declare const UI_LIMITS: {
|
|
|
142
167
|
readonly checklistItems: 100;
|
|
143
168
|
readonly textChars: 20000;
|
|
144
169
|
readonly payloadBytes: 2000;
|
|
170
|
+
readonly componentDataBytes: 32768;
|
|
145
171
|
};
|
|
146
172
|
/**
|
|
147
173
|
* 校验插件返回的视图,返回问题列表(空 = 合法)。链接与图片只允许 http(s) 绝对地址;
|
|
148
174
|
* Markdown 的检查是纵深防御,网页渲染时仍须只认 http(s) 链接、不渲染原生 HTML。
|
|
149
175
|
* 按钮与表单的 `actionId` 在整个视图内唯一(动作回调靠它区分来源)。
|
|
176
|
+
* `data` is accepted only with `opts.component` (the view of a component contribution): JSON as is
|
|
177
|
+
* (nothing JSON would drop or rewrite, see `jsonProblem`), up to `UI_LIMITS.componentDataBytes`
|
|
178
|
+
* bytes of UTF-8.
|
|
150
179
|
*/
|
|
151
|
-
export declare function validateUiView(v: unknown
|
|
180
|
+
export declare function validateUiView(v: unknown, opts?: {
|
|
181
|
+
component?: boolean;
|
|
182
|
+
}): string[];
|
|
152
183
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
184
|
+
* The caller's role in the org (owner / admin / member / guest, highest first). A slot's `minRole`
|
|
185
|
+
* decides who may use its contributions, then its scope's rule (the kernel answers 404 to anyone
|
|
186
|
+
* else, so the extension never sees such a request): `org.page` member and up,
|
|
187
|
+
* `org.settings.section` admin and up; conversation slots any role that can read the
|
|
188
|
+
* conversation; `agent.detail.section` any role that can read the agent (read-only viewers
|
|
189
|
+
* included: tighten on `role` if you must).
|
|
155
190
|
*/
|
|
156
191
|
export type UiRole = "owner" | "admin" | "member" | "guest";
|
|
157
|
-
/**
|
|
158
|
-
export interface
|
|
159
|
-
orgId: string;
|
|
192
|
+
/** The render args every scope shares (identity comes from the kernel's auth, never the caller's credentials). */
|
|
193
|
+
export interface UiRenderArgsBase {
|
|
160
194
|
accountId: string;
|
|
195
|
+
/** The catalog slot the contribution resolved to. */
|
|
196
|
+
slot: UiSlotId;
|
|
197
|
+
locale: Locale;
|
|
198
|
+
signal: AbortSignal;
|
|
199
|
+
/**
|
|
200
|
+
* The extension's effective deployment config: for an org, the platform's deployment config
|
|
201
|
+
* with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
|
|
202
|
+
* platform's config (equal to `ctx.config`) while the org follows it; for the platform scope,
|
|
203
|
+
* the platform's config. Use it, not `ctx.config`, for work done for this org. Optional in the
|
|
204
|
+
* type so older extensions compile; the kernel always passes it.
|
|
205
|
+
*/
|
|
206
|
+
config?: unknown;
|
|
207
|
+
}
|
|
208
|
+
/** 内核调用插件 `render` 时传入的参数,组织内的位置(会话、智能体、组织、文件)。 */
|
|
209
|
+
export interface UiOrgRenderArgs extends UiRenderArgsBase {
|
|
210
|
+
/** The scope of {@link slot}: which of the context ids below are set. */
|
|
211
|
+
scope: Exclude<UiSlotScope, "platform">;
|
|
212
|
+
orgId: string;
|
|
161
213
|
/** 调用者此刻在 `orgId` 的角色(内核按成员关系填,插件可据此收紧按钮等,见 {@link UiRole})。 */
|
|
162
214
|
role: UiRole;
|
|
163
215
|
/** 仅对话视图。 */
|
|
164
216
|
conversationId?: string;
|
|
165
|
-
|
|
166
|
-
|
|
217
|
+
/** Only an agent view (`agent.detail.section`): an agent of `orgId` the caller can read. */
|
|
218
|
+
agentId?: string;
|
|
167
219
|
/** A panel opened from an open target: the block or item `id` to scroll to. */
|
|
168
220
|
item?: string;
|
|
169
221
|
/**
|
|
@@ -176,12 +228,35 @@ export interface UiRenderArgs {
|
|
|
176
228
|
key?: string;
|
|
177
229
|
};
|
|
178
230
|
}
|
|
179
|
-
/**
|
|
180
|
-
|
|
231
|
+
/**
|
|
232
|
+
* The render args of a `platform.page` contribution: rendered for a super admin in the admin
|
|
233
|
+
* console, with no org (and so no org role, conversation or agent).
|
|
234
|
+
*/
|
|
235
|
+
export interface UiPlatformRenderArgs extends UiRenderArgsBase {
|
|
236
|
+
scope: "platform";
|
|
237
|
+
orgId?: undefined;
|
|
238
|
+
role: "superAdmin";
|
|
239
|
+
conversationId?: undefined;
|
|
240
|
+
agentId?: undefined;
|
|
241
|
+
item?: undefined;
|
|
242
|
+
card?: undefined;
|
|
243
|
+
}
|
|
244
|
+
/** 内核调用插件 `render` 时传入的参数:narrow on `scope` (`"platform"` has no `orgId`). */
|
|
245
|
+
export type UiRenderArgs = UiOrgRenderArgs | UiPlatformRenderArgs;
|
|
246
|
+
/** What a button or form submit adds to the render args. */
|
|
247
|
+
export interface UiActionInput {
|
|
181
248
|
actionId: string;
|
|
182
249
|
payload?: unknown;
|
|
183
250
|
answer?: FormAnswer;
|
|
184
251
|
}
|
|
252
|
+
/** An action of an org-scope view. */
|
|
253
|
+
export interface UiOrgActionArgs extends UiOrgRenderArgs, UiActionInput {
|
|
254
|
+
}
|
|
255
|
+
/** An action of a `platform.page` view. */
|
|
256
|
+
export interface UiPlatformActionArgs extends UiPlatformRenderArgs, UiActionInput {
|
|
257
|
+
}
|
|
258
|
+
/** 视图里的按钮或表单提交:`actionId` 来自块;表单提交时带 `answer`。 */
|
|
259
|
+
export type UiActionArgs = UiOrgActionArgs | UiPlatformActionArgs;
|
|
185
260
|
/** 动作结果:一条提示,或一份新的视图。 */
|
|
186
261
|
export type UiActionResult = {
|
|
187
262
|
toast?: {
|
|
@@ -191,21 +266,55 @@ export type UiActionResult = {
|
|
|
191
266
|
} | {
|
|
192
267
|
view: UiView;
|
|
193
268
|
};
|
|
194
|
-
/**
|
|
195
|
-
export interface
|
|
269
|
+
/** The embed claims both scopes share. `exp` 为 Unix 秒。 */
|
|
270
|
+
export interface EmbedClaimsBase {
|
|
196
271
|
plugin: string;
|
|
197
|
-
orgId: string;
|
|
198
272
|
accountId: string;
|
|
273
|
+
contribution: string;
|
|
274
|
+
exp: number;
|
|
275
|
+
}
|
|
276
|
+
/** An org-scope embed token's claims (every slot but `platform.page`). */
|
|
277
|
+
export interface OrgEmbedClaims extends EmbedClaimsBase {
|
|
278
|
+
scope: "org";
|
|
279
|
+
orgId: string;
|
|
199
280
|
/** 调用者的角色:签发时写入;`ctx.ui.verifyEmbedToken` 返回校验时刻的当前角色。 */
|
|
200
281
|
role: UiRole;
|
|
201
282
|
conversationId?: string;
|
|
283
|
+
/** Only an agent embed's token (`agent.detail.section`): the agent it was issued for. */
|
|
284
|
+
agentId?: string;
|
|
202
285
|
/** Only a `file-preview` embed's token: the one file (of `conversationId`) it previews. */
|
|
203
286
|
fileId?: string;
|
|
204
|
-
contribution: string;
|
|
205
|
-
exp: number;
|
|
206
287
|
}
|
|
288
|
+
/** A `platform.page` embed token's claims: a super admin's, with no org, conversation, agent or file. */
|
|
289
|
+
export interface PlatformEmbedClaims extends EmbedClaimsBase {
|
|
290
|
+
scope: "platform";
|
|
291
|
+
orgId?: undefined;
|
|
292
|
+
role: "superAdmin";
|
|
293
|
+
conversationId?: undefined;
|
|
294
|
+
agentId?: undefined;
|
|
295
|
+
fileId?: undefined;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* 嵌入令牌里的声明(经 `ctx.ui.verifyEmbedToken` 校验后可信): narrow on `scope` (`"platform"` has no
|
|
299
|
+
* `orgId` and `role` `"superAdmin"`).
|
|
300
|
+
*/
|
|
301
|
+
export type EmbedClaims = OrgEmbedClaims | PlatformEmbedClaims;
|
|
207
302
|
/** 外层页面与嵌入 iframe 之间 `postMessage` 协议的版本标识。 */
|
|
208
303
|
export declare const EMBED_PROTOCOL = "capybara-embed/1";
|
|
304
|
+
/**
|
|
305
|
+
* What an embed's `init` says about where it is shown, narrowed on `scope` like {@link EmbedClaims}:
|
|
306
|
+
* an org's page, panel, section or previewer (`orgId`, and the conversation when there is one), or
|
|
307
|
+
* a platform page of the admin console (no org).
|
|
308
|
+
*/
|
|
309
|
+
export type EmbedInitContext = {
|
|
310
|
+
scope: "org";
|
|
311
|
+
orgId: string;
|
|
312
|
+
conversationId?: string;
|
|
313
|
+
} | {
|
|
314
|
+
scope: "platform";
|
|
315
|
+
orgId?: undefined;
|
|
316
|
+
conversationId?: undefined;
|
|
317
|
+
};
|
|
209
318
|
/** 外层页面发给 iframe 的消息。 */
|
|
210
319
|
export type EmbedParentMessage = {
|
|
211
320
|
protocol: typeof EMBED_PROTOCOL;
|
|
@@ -214,10 +323,7 @@ export type EmbedParentMessage = {
|
|
|
214
323
|
locale: Locale;
|
|
215
324
|
theme: "dark" | "light";
|
|
216
325
|
tokens: Record<string, string>;
|
|
217
|
-
context:
|
|
218
|
-
orgId: string;
|
|
219
|
-
conversationId?: string;
|
|
220
|
-
};
|
|
326
|
+
context: EmbedInitContext;
|
|
221
327
|
} | {
|
|
222
328
|
protocol: typeof EMBED_PROTOCOL;
|
|
223
329
|
type: "token";
|
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.
|
|
@@ -27,6 +23,7 @@ export const UI_ICONS = [
|
|
|
27
23
|
* - `checklistItems`:清单项数;
|
|
28
24
|
* - `textChars`:整个视图所有文本(含表单 JSON)的字符总数;
|
|
29
25
|
* - `payloadBytes`:单个按钮 `payload` 的 JSON 序列化后 UTF-8 字节数。
|
|
26
|
+
* - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
|
|
30
27
|
*/
|
|
31
28
|
export const UI_LIMITS = {
|
|
32
29
|
blocks: 50,
|
|
@@ -34,6 +31,7 @@ export const UI_LIMITS = {
|
|
|
34
31
|
checklistItems: 100,
|
|
35
32
|
textChars: 20000,
|
|
36
33
|
payloadBytes: 2000,
|
|
34
|
+
componentDataBytes: 32768,
|
|
37
35
|
};
|
|
38
36
|
const BADGE_MAX = 32;
|
|
39
37
|
/** Longest item / block `id` and open target `item`. */
|
|
@@ -65,15 +63,77 @@ function jsonBytes(v) {
|
|
|
65
63
|
return undefined;
|
|
66
64
|
}
|
|
67
65
|
}
|
|
66
|
+
const JSON_KINDS = "null, booleans, finite numbers, strings, arrays, plain objects";
|
|
67
|
+
/**
|
|
68
|
+
* The first part of `v` (`at` is its path) that JSON would not carry as is, or undefined: a value
|
|
69
|
+
* `JSON.stringify` drops, rewrites or throws on (a function, symbol or bigint, NaN or ±Infinity,
|
|
70
|
+
* `undefined` in an array, an object that is not plain such as a Map or a Date, a cycle). A plain
|
|
71
|
+
* object's `undefined` property is accepted: JSON drops it, which reads as an absent optional field.
|
|
72
|
+
*/
|
|
73
|
+
function jsonProblem(v, at, seen = new Set()) {
|
|
74
|
+
if (v === null || typeof v === "boolean" || typeof v === "string")
|
|
75
|
+
return undefined;
|
|
76
|
+
if (typeof v === "number")
|
|
77
|
+
return Number.isFinite(v) ? undefined : `${at} is ${v}`;
|
|
78
|
+
if (v === undefined)
|
|
79
|
+
return `${at} is undefined`;
|
|
80
|
+
if (typeof v !== "object")
|
|
81
|
+
return `${at} is a ${typeof v}`;
|
|
82
|
+
if (seen.has(v))
|
|
83
|
+
return `${at} is a cycle`;
|
|
84
|
+
seen.add(v);
|
|
85
|
+
try {
|
|
86
|
+
if (Array.isArray(v)) {
|
|
87
|
+
for (let i = 0; i < v.length; i++) {
|
|
88
|
+
const p = jsonProblem(v[i], `${at}[${i}]`, seen);
|
|
89
|
+
if (p !== undefined)
|
|
90
|
+
return p;
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const proto = Object.getPrototypeOf(v);
|
|
95
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
96
|
+
return `${at} is a ${proto.constructor?.name || "non-plain object"}`;
|
|
97
|
+
}
|
|
98
|
+
for (const [k, x] of Object.entries(v)) {
|
|
99
|
+
if (x === undefined)
|
|
100
|
+
continue;
|
|
101
|
+
const p = jsonProblem(x, `${at}.${k}`, seen);
|
|
102
|
+
if (p !== undefined)
|
|
103
|
+
return p;
|
|
104
|
+
}
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
seen.delete(v);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
68
111
|
/**
|
|
69
112
|
* 校验插件返回的视图,返回问题列表(空 = 合法)。链接与图片只允许 http(s) 绝对地址;
|
|
70
113
|
* Markdown 的检查是纵深防御,网页渲染时仍须只认 http(s) 链接、不渲染原生 HTML。
|
|
71
114
|
* 按钮与表单的 `actionId` 在整个视图内唯一(动作回调靠它区分来源)。
|
|
115
|
+
* `data` is accepted only with `opts.component` (the view of a component contribution): JSON as is
|
|
116
|
+
* (nothing JSON would drop or rewrite, see `jsonProblem`), up to `UI_LIMITS.componentDataBytes`
|
|
117
|
+
* bytes of UTF-8.
|
|
72
118
|
*/
|
|
73
|
-
export function validateUiView(v) {
|
|
119
|
+
export function validateUiView(v, opts = {}) {
|
|
74
120
|
if (!isObj(v))
|
|
75
121
|
return ["view must be an object"];
|
|
76
122
|
const out = [];
|
|
123
|
+
if (v.data !== undefined) {
|
|
124
|
+
if (opts.component !== true)
|
|
125
|
+
out.push("view data is only allowed for component views");
|
|
126
|
+
else {
|
|
127
|
+
const problem = jsonProblem(v.data, "data");
|
|
128
|
+
if (problem !== undefined)
|
|
129
|
+
out.push(`view data must be JSON (${JSON_KINDS}): ${problem}`);
|
|
130
|
+
else {
|
|
131
|
+
const n = jsonBytes(v.data) ?? 0;
|
|
132
|
+
if (n > UI_LIMITS.componentDataBytes)
|
|
133
|
+
out.push(`view data is ${n} bytes; the limit is ${UI_LIMITS.componentDataBytes}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
77
137
|
let chars = 0;
|
|
78
138
|
const text = (at, s, nonEmpty = false) => {
|
|
79
139
|
if (typeof s !== "string" || (nonEmpty && s === "")) {
|