@capybara-hq/plugin-sdk 0.1.0-rc.6 → 0.1.0-rc.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/agent-docs/agent-templates.md +14 -2
- package/agent-docs/concepts.md +14 -5
- package/agent-docs/connector-templates.md +7 -1
- package/agent-docs/extension-points/channel.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/device-provider.md +15 -0
- package/agent-docs/extension-points/file-preview.md +2 -0
- package/agent-docs/extension-points/model-provider.md +3 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- package/agent-docs/extension-points/push-provider.md +17 -0
- package/agent-docs/extensions.md +29 -3
- package/agent-docs/plugin-format.md +52 -2
- package/agent-docs/setup.md +54 -0
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/avatar-presets.d.ts +8 -0
- package/dist/avatar-presets.js +17 -0
- package/dist/bootstrap.d.ts +109 -1
- package/dist/bootstrap.js +185 -2
- package/dist/cards.d.ts +67 -13
- package/dist/cards.js +91 -21
- package/dist/channel.d.ts +148 -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 +15 -2
- package/dist/connector-auth.js +97 -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 +132 -29
- package/dist/define-extension.d.ts +26 -12
- package/dist/define-extension.js +12 -5
- package/dist/device-denied-paths.d.ts +18 -0
- package/dist/device-denied-paths.js +84 -0
- package/dist/device-operation.d.ts +333 -0
- package/dist/device-operation.js +312 -0
- package/dist/device-protocol.d.ts +285 -50
- package/dist/device-protocol.js +755 -90
- package/dist/device-provider.d.ts +500 -0
- package/dist/device-provider.js +302 -0
- package/dist/dial-in.d.ts +176 -0
- package/dist/dial-in.js +115 -0
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +6 -2
- package/dist/file-preview.d.ts +23 -6
- package/dist/git-hosts.d.ts +53 -0
- package/dist/git-hosts.js +98 -0
- package/dist/hooks.d.ts +125 -20
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +62 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +38 -9
- package/dist/identity.js +21 -1
- package/dist/index.d.ts +29 -3
- package/dist/index.js +29 -3
- 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 +206 -71
- package/dist/model.js +152 -19
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/network-classes.d.ts +98 -0
- package/dist/network-classes.js +291 -0
- package/dist/permissions.d.ts +54 -22
- package/dist/permissions.js +119 -43
- package/dist/plugin-manifest.d.ts +45 -5
- package/dist/plugin-manifest.js +174 -6
- package/dist/plugin-package.d.ts +82 -38
- package/dist/plugin-package.js +61 -29
- package/dist/push.d.ts +75 -0
- package/dist/push.js +87 -0
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +2318 -0
- package/dist/sandbox-native-runtime-source.d.ts +10 -0
- package/dist/sandbox-native-runtime-source.js +476 -0
- package/dist/sandbox-runtime-source.d.ts +19 -0
- package/dist/sandbox-runtime-source.js +28 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-check.d.ts +128 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +356 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +108 -0
- package/dist/setup-guide.js +367 -0
- package/dist/shell-capabilities.d.ts +211 -0
- package/dist/shell-capabilities.js +44 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +21 -0
- package/dist/skill.d.ts +27 -17
- package/dist/skill.js +40 -26
- package/dist/storage.d.ts +52 -25
- package/dist/svg-viewbox.d.ts +10 -0
- package/dist/svg-viewbox.js +24 -0
- package/dist/theme-assets.d.ts +55 -0
- package/dist/theme-assets.js +489 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +299 -0
- package/dist/theme-tokens.generated.js +184 -0
- package/dist/theme.d.ts +190 -0
- package/dist/theme.js +471 -0
- package/dist/tool.d.ts +99 -26
- package/dist/tool.js +29 -9
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +385 -0
- package/dist/ui-resolve.d.ts +35 -0
- package/dist/ui-resolve.js +42 -0
- package/dist/ui-slots.d.ts +65 -0
- package/dist/ui-slots.js +261 -0
- package/dist/ui.d.ts +212 -76
- package/dist/ui.js +101 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/package.json +13 -1
- package/schemas/bootstrap-extra.v1.schema.json +186 -0
- package/schemas/bootstrap.v1.schema.json +20 -0
- package/schemas/connector-template.v1.schema.json +35 -0
- package/schemas/marketplace.v1.schema.json +14 -0
- package/schemas/plugin.v1.schema.json +122 -3
- package/schemas/theme.v1.schema.json +302 -0
- package/agent-docs/extension-points/sandbox.md +0 -15
- package/dist/sandbox.d.ts +0 -254
- package/dist/sandbox.js +0 -153
package/dist/ui-slots.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
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 COMPACT_ORDER = ["kept", "drawer", "hidden"];
|
|
17
|
+
/** True when `v` is one of the three compact forms (used to validate manifests). */
|
|
18
|
+
export function isCompactForm(v) {
|
|
19
|
+
return typeof v === "string" && COMPACT_ORDER.includes(v);
|
|
20
|
+
}
|
|
21
|
+
/** A contribution may narrow its slot's compact form, never widen it. */
|
|
22
|
+
export function effectiveCompact(slot, contribution) {
|
|
23
|
+
if (contribution === undefined)
|
|
24
|
+
return slot;
|
|
25
|
+
return COMPACT_ORDER.indexOf(contribution) > COMPACT_ORDER.indexOf(slot) ? contribution : slot;
|
|
26
|
+
}
|
|
27
|
+
const SLOT_DATA = [
|
|
28
|
+
{
|
|
29
|
+
id: "conversation.panel",
|
|
30
|
+
version: 1,
|
|
31
|
+
owner: "components/conversation/RightArea.tsx",
|
|
32
|
+
scope: "conversation",
|
|
33
|
+
accepts: ["view", "embed", "component"],
|
|
34
|
+
cardinality: "list",
|
|
35
|
+
minRole: "guest",
|
|
36
|
+
args: ["conversationId", "item"],
|
|
37
|
+
density: "regular",
|
|
38
|
+
icon: "optional",
|
|
39
|
+
compact: "drawer",
|
|
40
|
+
description: {
|
|
41
|
+
en: "A panel beside the conversation, opened from the right area.",
|
|
42
|
+
zh: "对话旁的面板,从右侧区域打开。",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "conversation.properties.section",
|
|
47
|
+
version: 1,
|
|
48
|
+
owner: "components/conversation/PropertiesSections.tsx",
|
|
49
|
+
scope: "conversation",
|
|
50
|
+
accepts: ["view", "embed", "component"],
|
|
51
|
+
cardinality: "list",
|
|
52
|
+
minRole: "guest",
|
|
53
|
+
args: ["conversationId"],
|
|
54
|
+
density: "dense",
|
|
55
|
+
icon: "optional",
|
|
56
|
+
compact: "kept",
|
|
57
|
+
anchors: ["context", "files", "background"],
|
|
58
|
+
description: {
|
|
59
|
+
en: "A section in the conversation properties list.",
|
|
60
|
+
zh: "对话属性列表中的一个分区。",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "conversation.tool-result.card",
|
|
65
|
+
version: 1,
|
|
66
|
+
owner: "components/conversation/RightArea.tsx",
|
|
67
|
+
scope: "conversation",
|
|
68
|
+
accepts: ["view", "embed", "component"],
|
|
69
|
+
cardinality: "list",
|
|
70
|
+
minRole: "guest",
|
|
71
|
+
args: ["conversationId", "card"],
|
|
72
|
+
density: "regular",
|
|
73
|
+
icon: "optional",
|
|
74
|
+
compact: "kept",
|
|
75
|
+
description: {
|
|
76
|
+
en: "A card a tool result opens in the conversation.",
|
|
77
|
+
zh: "工具结果在对话中打开的卡片。",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "org.page",
|
|
82
|
+
version: 1,
|
|
83
|
+
owner: "app/(app)/p/[plugin]/[id]/view.tsx",
|
|
84
|
+
scope: "org",
|
|
85
|
+
accepts: ["view", "embed", "component"],
|
|
86
|
+
cardinality: "list",
|
|
87
|
+
minRole: "member",
|
|
88
|
+
args: [],
|
|
89
|
+
density: "regular",
|
|
90
|
+
icon: "optional",
|
|
91
|
+
compact: "kept",
|
|
92
|
+
description: {
|
|
93
|
+
en: "A full page in the organization navigation.",
|
|
94
|
+
zh: "组织导航中的完整页面。",
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: "file.preview",
|
|
99
|
+
version: 1,
|
|
100
|
+
owner: "components/conversation/FilePanel.tsx",
|
|
101
|
+
scope: "file",
|
|
102
|
+
accepts: ["embed"],
|
|
103
|
+
cardinality: "list",
|
|
104
|
+
minRole: "guest",
|
|
105
|
+
args: ["conversationId", "fileId"],
|
|
106
|
+
density: "regular",
|
|
107
|
+
icon: "optional",
|
|
108
|
+
compact: "kept",
|
|
109
|
+
description: {
|
|
110
|
+
en: "A previewer for a file of the conversation.",
|
|
111
|
+
zh: "对话中文件的预览器。",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: "agent.detail.section",
|
|
116
|
+
version: 1,
|
|
117
|
+
owner: "components/agent/AgentPage.tsx",
|
|
118
|
+
scope: "agent",
|
|
119
|
+
accepts: ["view", "embed", "component"],
|
|
120
|
+
cardinality: "list",
|
|
121
|
+
minRole: "guest",
|
|
122
|
+
args: ["agentId"],
|
|
123
|
+
density: "regular",
|
|
124
|
+
icon: "optional",
|
|
125
|
+
compact: "kept",
|
|
126
|
+
description: {
|
|
127
|
+
en: "A section on the detail page of an agent.",
|
|
128
|
+
zh: "智能体详情页中的一个分区。",
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
id: "org.settings.section",
|
|
133
|
+
version: 1,
|
|
134
|
+
owner: "app/(app)/settings/organization/view.tsx",
|
|
135
|
+
scope: "org",
|
|
136
|
+
accepts: ["view", "embed", "component"],
|
|
137
|
+
cardinality: "list",
|
|
138
|
+
minRole: "admin",
|
|
139
|
+
args: [],
|
|
140
|
+
density: "regular",
|
|
141
|
+
icon: "optional",
|
|
142
|
+
compact: "kept",
|
|
143
|
+
description: {
|
|
144
|
+
en: "A section on the organization settings page.",
|
|
145
|
+
zh: "组织设置页中的一个分区。",
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
id: "platform.page",
|
|
150
|
+
version: 1,
|
|
151
|
+
owner: "app/(app)/admin/p/[plugin]/[id]/view.tsx",
|
|
152
|
+
scope: "platform",
|
|
153
|
+
accepts: ["view", "embed", "component"],
|
|
154
|
+
cardinality: "list",
|
|
155
|
+
minRole: "superAdmin",
|
|
156
|
+
args: [],
|
|
157
|
+
density: "regular",
|
|
158
|
+
icon: "optional",
|
|
159
|
+
compact: "kept",
|
|
160
|
+
description: {
|
|
161
|
+
en: "A full page in the platform administration.",
|
|
162
|
+
zh: "平台管理中的完整页面。",
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
id: "shell.brand",
|
|
167
|
+
version: 1,
|
|
168
|
+
owner: "components/shell/AppFrame.tsx",
|
|
169
|
+
scope: "org",
|
|
170
|
+
accepts: ["component"],
|
|
171
|
+
cardinality: "single",
|
|
172
|
+
replaceable: true,
|
|
173
|
+
builtin: { en: "The logo and wordmark in the sidebar.", zh: "侧边栏中的标志与字标。" },
|
|
174
|
+
minRole: "guest",
|
|
175
|
+
args: [],
|
|
176
|
+
density: "regular",
|
|
177
|
+
icon: "none",
|
|
178
|
+
compact: "hidden",
|
|
179
|
+
description: {
|
|
180
|
+
en: "The brand row of the sidebar (the mark of the collapsed rail).",
|
|
181
|
+
zh: "侧边栏的品牌行(收起后的窄栏标记)。",
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
id: "shell.overlay",
|
|
186
|
+
version: 1,
|
|
187
|
+
owner: "components/shell/AppFrame.tsx",
|
|
188
|
+
scope: "org",
|
|
189
|
+
accepts: ["component"],
|
|
190
|
+
cardinality: "list",
|
|
191
|
+
minRole: "guest",
|
|
192
|
+
args: [],
|
|
193
|
+
density: "regular",
|
|
194
|
+
icon: "none",
|
|
195
|
+
compact: "kept",
|
|
196
|
+
limits: { maxShown: 4 },
|
|
197
|
+
description: {
|
|
198
|
+
en: "A full-viewport layer over the workspace shell.",
|
|
199
|
+
zh: "覆盖工作区外壳的全视口图层。",
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
id: "conversation.empty",
|
|
204
|
+
version: 1,
|
|
205
|
+
owner: "components/conversation/NewConversation.tsx",
|
|
206
|
+
scope: "org",
|
|
207
|
+
accepts: ["component"],
|
|
208
|
+
cardinality: "single",
|
|
209
|
+
replaceable: true,
|
|
210
|
+
builtin: { en: "The greeting of the new-conversation page.", zh: "新对话页的问候区。" },
|
|
211
|
+
minRole: "guest",
|
|
212
|
+
args: [],
|
|
213
|
+
density: "regular",
|
|
214
|
+
icon: "none",
|
|
215
|
+
compact: "kept",
|
|
216
|
+
description: {
|
|
217
|
+
en: "The hero of the new-conversation page.",
|
|
218
|
+
zh: "新对话页的主视觉区。",
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
id: "conversation.composer.frame",
|
|
223
|
+
version: 1,
|
|
224
|
+
owner: "components/conversation/ComposerBar.tsx",
|
|
225
|
+
scope: "org",
|
|
226
|
+
accepts: ["component"],
|
|
227
|
+
cardinality: "single",
|
|
228
|
+
replaceable: true,
|
|
229
|
+
builtin: { en: "The frame around the message composer.", zh: "消息输入框外的边框。" },
|
|
230
|
+
minRole: "guest",
|
|
231
|
+
args: [],
|
|
232
|
+
density: "regular",
|
|
233
|
+
icon: "none",
|
|
234
|
+
compact: "kept",
|
|
235
|
+
description: {
|
|
236
|
+
en: "The frame around the composer, on the new-conversation and conversation pages.",
|
|
237
|
+
zh: "新对话页与对话页中输入框外的边框。",
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
];
|
|
241
|
+
export const UI_SLOTS = SLOT_DATA;
|
|
242
|
+
export function uiSlot(id) {
|
|
243
|
+
return UI_SLOTS.find((s) => s.id === id);
|
|
244
|
+
}
|
|
245
|
+
const SLOT_REF_RE = /^([a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+)(?:@([1-9][0-9]{0,2}))?$/;
|
|
246
|
+
/** Reads `<id>` or `<id>@<version>` (version 1 when omitted); does not check the catalog. */
|
|
247
|
+
export function parseSlotRef(ref) {
|
|
248
|
+
const m = SLOT_REF_RE.exec(ref);
|
|
249
|
+
if (!m)
|
|
250
|
+
return null;
|
|
251
|
+
return { id: m[1], version: m[2] === undefined ? 1 : Number(m[2]) };
|
|
252
|
+
}
|
|
253
|
+
export const UI_ARRANGEABLE_SLOTS = UI_SLOT_IDS.filter((id) => id !== "file.preview");
|
|
254
|
+
/** Slots with one winner that replaces a built-in block. */
|
|
255
|
+
export const UI_SINGLE_SLOTS = UI_SLOTS.filter((s) => s.cardinality === "single").map((s) => s.id);
|
|
256
|
+
/** Slots that accept the `component` kind. */
|
|
257
|
+
export const UI_COMPONENT_SLOTS = UI_SLOTS.filter((s) => s.accepts.includes("component")).map((s) => s.id);
|
|
258
|
+
export const UI_CONTRIBUTION_KEY_RE = /^[a-z][a-z0-9-]{1,40}\/[a-z][a-z0-9-]{0,39}$/;
|
|
259
|
+
export function uiContributionKey(plugin, id) {
|
|
260
|
+
return `${plugin}/${id}`;
|
|
261
|
+
}
|
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 { CompactForm, UiSlotId, UiSlotScope } from "./ui-slots.js";
|
|
16
4
|
/**
|
|
17
5
|
* Icons a contribution may use (design system icon names; `puzzle` is the default and is drawn as
|
|
18
6
|
* the design `extension` icon). The title-bar button of a panel shows it.
|
|
@@ -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,32 @@ export interface UiContribution {
|
|
|
39
34
|
zh: string;
|
|
40
35
|
en: string;
|
|
41
36
|
};
|
|
42
|
-
|
|
37
|
+
/**
|
|
38
|
+
* The slot it goes in: `"<id>"` (version 1) or `"<id>@<n>"`, an id of `UI_SLOTS`. Required. An
|
|
39
|
+
* unknown slot or version does not fail the extension: the contribution is dropped (see
|
|
40
|
+
* `resolveUiSlots`).
|
|
41
|
+
*/
|
|
42
|
+
slot: string;
|
|
43
|
+
/**
|
|
44
|
+
* One of the slot's `anchors` to be placed after; omitted (or not an anchor of the slot) = the
|
|
45
|
+
* slot's first anchor.
|
|
46
|
+
*/
|
|
47
|
+
after?: string;
|
|
43
48
|
kind: UiKind;
|
|
44
|
-
/**
|
|
49
|
+
/** Embed only: a path under `/ui/` of the extension's routes, declared in `permissions.http` as GET. */
|
|
45
50
|
path?: string;
|
|
46
51
|
/** Icon from {@link UI_ICONS}; default `puzzle`. */
|
|
47
52
|
icon?: UiIcon;
|
|
48
53
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* `permissions.ui`, and no `ctx.ui.view` of its own.
|
|
54
|
+
* The form on a compact screen; may only narrow the slot's own (`kept` -> `drawer` -> `hidden`),
|
|
55
|
+
* see `effectiveCompact`. Omitted = the slot's form.
|
|
52
56
|
*/
|
|
53
|
-
|
|
57
|
+
compact?: CompactForm;
|
|
54
58
|
}
|
|
55
59
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
60
|
+
* Blocks of the render schema. Text is for humans and shown as is (the plugin decides the language
|
|
61
|
+
* itself, usually taking `locale`).
|
|
62
|
+
* `text.markdown` does not support native HTML, and links may only be absolute http(s) addresses.
|
|
58
63
|
*/
|
|
59
64
|
export type UiBlock = {
|
|
60
65
|
type: "heading";
|
|
@@ -86,8 +91,10 @@ export type UiBlock = {
|
|
|
86
91
|
label: string;
|
|
87
92
|
}[];
|
|
88
93
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
94
|
+
* Each row takes its cell by column key, and a column may be missing. When rendering, use
|
|
95
|
+
* `Object.hasOwn(row, key)` to tell whether a cell exists,
|
|
96
|
+
* do not use `row[key]` or `in`: a column key may be `constructor` / `toString` and the like,
|
|
97
|
+
* which would pick up values from the prototype chain.
|
|
91
98
|
*/
|
|
92
99
|
rows: Record<string, string>[];
|
|
93
100
|
/** Per row (same index), an open target or null; never a key inside a row. */
|
|
@@ -121,20 +128,32 @@ export type UiBlock = {
|
|
|
121
128
|
actionId: string;
|
|
122
129
|
submitLabel: string;
|
|
123
130
|
};
|
|
124
|
-
/**
|
|
131
|
+
/** A JSON value: what survives `JSON.stringify` and `JSON.parse` unchanged. */
|
|
132
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
133
|
+
[key: string]: JsonValue;
|
|
134
|
+
};
|
|
135
|
+
/** A plugin view: a block list with limits; `badge` is shown on the tab (e.g. "2/4"). */
|
|
125
136
|
export interface UiView {
|
|
126
137
|
badge?: string;
|
|
127
138
|
/** The ⤢ of an inline card's title row and a properties section's header. */
|
|
128
139
|
open?: UiOpen;
|
|
140
|
+
/** A component's view may have no blocks (`[]`). */
|
|
129
141
|
blocks: UiBlock[];
|
|
142
|
+
/**
|
|
143
|
+
* Only from a component's render (`useView` hands it to the component): at most
|
|
144
|
+
* `UI_LIMITS.componentDataBytes` bytes of JSON. Refused in the views of the other kinds.
|
|
145
|
+
*/
|
|
146
|
+
data?: JsonValue;
|
|
130
147
|
}
|
|
131
148
|
/**
|
|
132
|
-
*
|
|
133
|
-
* - `blocks
|
|
134
|
-
* - `tableRows
|
|
135
|
-
*
|
|
136
|
-
* - `
|
|
137
|
-
* - `
|
|
149
|
+
* View limits (checked uniformly by {@link validateUiView}):
|
|
150
|
+
* - `blocks`: number of blocks;
|
|
151
|
+
* - `tableRows`: number of table rows, also used as the upper bound for keyValue items, table
|
|
152
|
+
* columns, chart points and buttons;
|
|
153
|
+
* - `checklistItems`: number of checklist items;
|
|
154
|
+
* - `textChars`: total characters of all text in the whole view (form JSON included);
|
|
155
|
+
* - `payloadBytes`: UTF-8 bytes of a single button `payload` after JSON serialization.
|
|
156
|
+
* - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
|
|
138
157
|
*/
|
|
139
158
|
export declare const UI_LIMITS: {
|
|
140
159
|
readonly blocks: 50;
|
|
@@ -142,28 +161,64 @@ export declare const UI_LIMITS: {
|
|
|
142
161
|
readonly checklistItems: 100;
|
|
143
162
|
readonly textChars: 20000;
|
|
144
163
|
readonly payloadBytes: 2000;
|
|
164
|
+
readonly componentDataBytes: 32768;
|
|
145
165
|
};
|
|
146
166
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
167
|
+
* Validates the view a plugin returns and returns the list of problems (empty = valid). Links and
|
|
168
|
+
* images may only be absolute http(s) addresses;
|
|
169
|
+
* the Markdown check is defense in depth, and web rendering must still accept only http(s) links
|
|
170
|
+
* and not render native HTML.
|
|
171
|
+
* The `actionId` of buttons and forms is unique within the whole view (action callbacks tell the
|
|
172
|
+
* source by it).
|
|
173
|
+
* `data` is accepted only with `opts.component` (the view of a component contribution): JSON as is
|
|
174
|
+
* (nothing JSON would drop or rewrite, see `jsonProblem`), up to `UI_LIMITS.componentDataBytes`
|
|
175
|
+
* bytes of UTF-8.
|
|
150
176
|
*/
|
|
151
|
-
export declare function validateUiView(v: unknown
|
|
177
|
+
export declare function validateUiView(v: unknown, opts?: {
|
|
178
|
+
component?: boolean;
|
|
179
|
+
}): string[];
|
|
152
180
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
181
|
+
* The caller's role in the org (owner / admin / member / guest, highest first). A slot's `minRole`
|
|
182
|
+
* decides who may use its contributions, then its scope's rule (the kernel answers 404 to anyone
|
|
183
|
+
* else, so the extension never sees such a request): `org.page` member and up,
|
|
184
|
+
* `org.settings.section` admin and up; conversation slots any role that can read the
|
|
185
|
+
* conversation; `agent.detail.section` any role that can read the agent (read-only viewers
|
|
186
|
+
* included: tighten on `role` if you must).
|
|
155
187
|
*/
|
|
156
188
|
export type UiRole = "owner" | "admin" | "member" | "guest";
|
|
157
|
-
/**
|
|
158
|
-
export interface
|
|
159
|
-
orgId: string;
|
|
189
|
+
/** The render args every scope shares (identity comes from the kernel's auth, never the caller's credentials). */
|
|
190
|
+
export interface UiRenderArgsBase {
|
|
160
191
|
accountId: string;
|
|
161
|
-
/**
|
|
162
|
-
|
|
163
|
-
/** 仅对话视图。 */
|
|
164
|
-
conversationId?: string;
|
|
192
|
+
/** The catalog slot the contribution resolved to. */
|
|
193
|
+
slot: UiSlotId;
|
|
165
194
|
locale: Locale;
|
|
166
195
|
signal: AbortSignal;
|
|
196
|
+
/**
|
|
197
|
+
* The extension's effective deployment config: for an org, the platform's deployment config
|
|
198
|
+
* with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
|
|
199
|
+
* platform's config (equal to `ctx.config`) while the org follows it; for the platform scope,
|
|
200
|
+
* the platform's config. Use it, not `ctx.config`, for work done for this org. Optional in the
|
|
201
|
+
* type so older extensions compile; the kernel always passes it.
|
|
202
|
+
*/
|
|
203
|
+
config?: unknown;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The parameters passed when the kernel calls the plugin's `render`: the position within the org
|
|
207
|
+
* (conversation, agent, org, file).
|
|
208
|
+
*/
|
|
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;
|
|
213
|
+
/**
|
|
214
|
+
* The caller's role in `orgId` at this moment (filled by the kernel from membership; a plugin may
|
|
215
|
+
* use it to tighten buttons etc., see {@link UiRole}).
|
|
216
|
+
*/
|
|
217
|
+
role: UiRole;
|
|
218
|
+
/** Conversation views only. */
|
|
219
|
+
conversationId?: string;
|
|
220
|
+
/** Only an agent view (`agent.detail.section`): an agent of `orgId` the caller can read. */
|
|
221
|
+
agentId?: string;
|
|
167
222
|
/** A panel opened from an open target: the block or item `id` to scroll to. */
|
|
168
223
|
item?: string;
|
|
169
224
|
/**
|
|
@@ -175,22 +230,43 @@ export interface UiRenderArgs {
|
|
|
175
230
|
callId: string;
|
|
176
231
|
key?: string;
|
|
177
232
|
};
|
|
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
233
|
}
|
|
187
|
-
/**
|
|
188
|
-
|
|
234
|
+
/**
|
|
235
|
+
* The render args of a `platform.page` contribution: rendered for a super admin in the admin
|
|
236
|
+
* console, with no org (and so no org role, conversation or agent).
|
|
237
|
+
*/
|
|
238
|
+
export interface UiPlatformRenderArgs extends UiRenderArgsBase {
|
|
239
|
+
scope: "platform";
|
|
240
|
+
orgId?: undefined;
|
|
241
|
+
role: "superAdmin";
|
|
242
|
+
conversationId?: undefined;
|
|
243
|
+
agentId?: undefined;
|
|
244
|
+
item?: undefined;
|
|
245
|
+
card?: undefined;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* The parameters passed when the kernel calls the plugin's `render`: narrow on `scope`
|
|
249
|
+
* (`"platform"` has no `orgId`).
|
|
250
|
+
*/
|
|
251
|
+
export type UiRenderArgs = UiOrgRenderArgs | UiPlatformRenderArgs;
|
|
252
|
+
/** What a button or form submit adds to the render args. */
|
|
253
|
+
export interface UiActionInput {
|
|
189
254
|
actionId: string;
|
|
190
255
|
payload?: unknown;
|
|
191
256
|
answer?: FormAnswer;
|
|
192
257
|
}
|
|
193
|
-
/**
|
|
258
|
+
/** An action of an org-scope view. */
|
|
259
|
+
export interface UiOrgActionArgs extends UiOrgRenderArgs, UiActionInput {
|
|
260
|
+
}
|
|
261
|
+
/** An action of a `platform.page` view. */
|
|
262
|
+
export interface UiPlatformActionArgs extends UiPlatformRenderArgs, UiActionInput {
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* A button or form submission in a view: `actionId` comes from the block; a form submission carries
|
|
266
|
+
* `answer`.
|
|
267
|
+
*/
|
|
268
|
+
export type UiActionArgs = UiOrgActionArgs | UiPlatformActionArgs;
|
|
269
|
+
/** An action result: a notice, or a new view. */
|
|
194
270
|
export type UiActionResult = {
|
|
195
271
|
toast?: {
|
|
196
272
|
zh: string;
|
|
@@ -199,22 +275,81 @@ export type UiActionResult = {
|
|
|
199
275
|
} | {
|
|
200
276
|
view: UiView;
|
|
201
277
|
};
|
|
202
|
-
/**
|
|
203
|
-
export interface
|
|
278
|
+
/** The embed claims every scope shares. `exp` is Unix seconds. */
|
|
279
|
+
export interface EmbedClaimsBase {
|
|
204
280
|
plugin: string;
|
|
281
|
+
contribution: string;
|
|
282
|
+
exp: number;
|
|
283
|
+
}
|
|
284
|
+
/** An org-scope embed token's claims (every slot but `platform.page`). */
|
|
285
|
+
export interface OrgEmbedClaims extends EmbedClaimsBase {
|
|
286
|
+
scope: "org";
|
|
205
287
|
orgId: string;
|
|
206
288
|
accountId: string;
|
|
207
|
-
/**
|
|
289
|
+
/**
|
|
290
|
+
* The caller's role: written at issuance; `ctx.ui.verifyEmbedToken` returns the current role at
|
|
291
|
+
* validation time.
|
|
292
|
+
*/
|
|
208
293
|
role: UiRole;
|
|
209
294
|
conversationId?: string;
|
|
295
|
+
/** Only an agent embed's token (`agent.detail.section`): the agent it was issued for. */
|
|
296
|
+
agentId?: string;
|
|
210
297
|
/** Only a `file-preview` embed's token: the one file (of `conversationId`) it previews. */
|
|
211
298
|
fileId?: string;
|
|
212
|
-
contribution: string;
|
|
213
|
-
exp: number;
|
|
214
299
|
}
|
|
215
|
-
/**
|
|
300
|
+
/** A `platform.page` embed token's claims: a super admin's, with no org, conversation, agent or file. */
|
|
301
|
+
export interface PlatformEmbedClaims extends EmbedClaimsBase {
|
|
302
|
+
scope: "platform";
|
|
303
|
+
accountId: string;
|
|
304
|
+
orgId?: undefined;
|
|
305
|
+
role: "superAdmin";
|
|
306
|
+
conversationId?: undefined;
|
|
307
|
+
agentId?: undefined;
|
|
308
|
+
fileId?: undefined;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* A share page's `file.preview` embed token's claims: no account and no role, only the org, the
|
|
312
|
+
* share and the share's generation. Valid only for the `file.preview` slot, never for `/api`.
|
|
313
|
+
*/
|
|
314
|
+
export interface ShareEmbedClaims extends EmbedClaimsBase {
|
|
315
|
+
scope: "share";
|
|
316
|
+
orgId: string;
|
|
317
|
+
shareId: string;
|
|
318
|
+
generation: number;
|
|
319
|
+
accountId?: undefined;
|
|
320
|
+
role?: undefined;
|
|
321
|
+
conversationId?: undefined;
|
|
322
|
+
agentId?: undefined;
|
|
323
|
+
fileId?: undefined;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Claims in an embed token (trustworthy after validation by `ctx.ui.verifyEmbedToken`): narrow on
|
|
327
|
+
* `scope` (`"platform"` has no `orgId` and `role` `"superAdmin"`; `"share"` has no account or role).
|
|
328
|
+
*/
|
|
329
|
+
export type EmbedClaims = OrgEmbedClaims | PlatformEmbedClaims | ShareEmbedClaims;
|
|
330
|
+
/**
|
|
331
|
+
* The version marker of the `postMessage` protocol between the outer page and the embedded iframe.
|
|
332
|
+
*/
|
|
216
333
|
export declare const EMBED_PROTOCOL = "capybara-embed/1";
|
|
217
|
-
/**
|
|
334
|
+
/**
|
|
335
|
+
* What an embed's `init` says about where it is shown, narrowed on `scope` like {@link EmbedClaims}:
|
|
336
|
+
* an org's page, panel, section or previewer (`orgId`, and the conversation when there is one), or
|
|
337
|
+
* a platform page of the admin console (no org), or a share page (no org or conversation).
|
|
338
|
+
*/
|
|
339
|
+
export type EmbedInitContext = {
|
|
340
|
+
scope: "org";
|
|
341
|
+
orgId: string;
|
|
342
|
+
conversationId?: string;
|
|
343
|
+
} | {
|
|
344
|
+
scope: "platform";
|
|
345
|
+
orgId?: undefined;
|
|
346
|
+
conversationId?: undefined;
|
|
347
|
+
} | {
|
|
348
|
+
scope: "share";
|
|
349
|
+
orgId?: undefined;
|
|
350
|
+
conversationId?: undefined;
|
|
351
|
+
};
|
|
352
|
+
/** Messages the outer page sends to the iframe. */
|
|
218
353
|
export type EmbedParentMessage = {
|
|
219
354
|
protocol: typeof EMBED_PROTOCOL;
|
|
220
355
|
type: "init";
|
|
@@ -222,10 +357,7 @@ export type EmbedParentMessage = {
|
|
|
222
357
|
locale: Locale;
|
|
223
358
|
theme: "dark" | "light";
|
|
224
359
|
tokens: Record<string, string>;
|
|
225
|
-
context:
|
|
226
|
-
orgId: string;
|
|
227
|
-
conversationId?: string;
|
|
228
|
-
};
|
|
360
|
+
context: EmbedInitContext;
|
|
229
361
|
} | {
|
|
230
362
|
protocol: typeof EMBED_PROTOCOL;
|
|
231
363
|
type: "token";
|
|
@@ -248,15 +380,18 @@ export type EmbedParentMessage = {
|
|
|
248
380
|
size: number;
|
|
249
381
|
data: ArrayBuffer;
|
|
250
382
|
};
|
|
251
|
-
/** iframe
|
|
383
|
+
/** Messages the iframe sends to the outer page. */
|
|
252
384
|
export type EmbedChildMessage =
|
|
253
|
-
/**
|
|
385
|
+
/** Height in CSS pixels, 0–10000. */
|
|
254
386
|
{
|
|
255
387
|
protocol: typeof EMBED_PROTOCOL;
|
|
256
388
|
type: "resize";
|
|
257
389
|
height: number;
|
|
258
390
|
}
|
|
259
|
-
/**
|
|
391
|
+
/**
|
|
392
|
+
* Only in-site paths: a single leading `/`, no `//`, no `.` / `..` segments (including `%2e`
|
|
393
|
+
* encoding), unchanged after normalization.
|
|
394
|
+
*/
|
|
260
395
|
| {
|
|
261
396
|
protocol: typeof EMBED_PROTOCOL;
|
|
262
397
|
type: "navigate";
|
|
@@ -267,7 +402,8 @@ export type EmbedChildMessage =
|
|
|
267
402
|
text: string;
|
|
268
403
|
};
|
|
269
404
|
/**
|
|
270
|
-
*
|
|
271
|
-
*
|
|
405
|
+
* Parses a message sent by the iframe: returns it only when protocol, type and fields are all right
|
|
406
|
+
* (a new object keeping only known fields), otherwise null.
|
|
407
|
+
* The outer page must also first check that the message source is this iframe.
|
|
272
408
|
*/
|
|
273
409
|
export declare function parseEmbedChildMessage(m: unknown): EmbedChildMessage | null;
|