@capybara-hq/plugin-sdk 0.1.0-rc.85 → 0.1.0-rc.86
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/dist/ctx.d.ts +13 -1
- package/dist/file-preview.d.ts +5 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/model.d.ts +6 -4
- package/dist/model.js +7 -3
- package/dist/permissions.js +15 -1
- package/dist/ui-slots.js +3 -3
- package/dist/ui.d.ts +48 -2
- package/dist/ui.js +13 -0
- package/package.json +1 -1
package/dist/ctx.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { SetupCheckDefinition } from "./setup-check.js";
|
|
|
10
10
|
import type { ObjectHead, PresignedUpload, PresignGetOptions } from "./storage.js";
|
|
11
11
|
import type { ToolCallContext, ToolHandler, ToolSpec, ToolWatcher } from "./tool.js";
|
|
12
12
|
import type { TriggersCtx } from "./triggers.js";
|
|
13
|
-
import type { EmbedClaims, UiActionArgs, UiActionResult, UiRenderArgs, UiView } from "./ui.js";
|
|
13
|
+
import type { EmbedClaims, JsonValue, UiActionArgs, UiActionResult, UiQueryArgs, UiRenderArgs, UiView } from "./ui.js";
|
|
14
14
|
/** Logger interface. */
|
|
15
15
|
export interface Logger {
|
|
16
16
|
info(msg: string, fields?: Record<string, unknown>): void;
|
|
@@ -379,6 +379,18 @@ export interface ExtensionContext {
|
|
|
379
379
|
ui: {
|
|
380
380
|
view(id: string, render: (args: UiRenderArgs) => Promise<UiView>): void;
|
|
381
381
|
action(id: string, handler: (args: UiActionArgs) => Promise<UiActionResult>): void;
|
|
382
|
+
/**
|
|
383
|
+
* Registers the data source of `usePluginQuery` for a component (only during `setup`). `id`
|
|
384
|
+
* must be a component id declared in `permissions.ui.components`; the kernel refuses any other
|
|
385
|
+
* id. Queries work in any org-scoped component slot (`org.page`, conversation and agent slots
|
|
386
|
+
* alike). The result is JSON of at most `UI_LIMITS.componentQueryBytes` bytes and the call's
|
|
387
|
+
* params at most `UI_LIMITS.componentQueryParamsBytes`. Push refresh reaches queries only
|
|
388
|
+
* through org-stream invalidations (`invalidate({ orgId, contribution })` without a
|
|
389
|
+
* `conversationId`): a conversation-scoped invalidation does not refetch them, so a component
|
|
390
|
+
* in a conversation slot refetches through an action result's `invalidate` query names (or
|
|
391
|
+
* its own `refetch`).
|
|
392
|
+
*/
|
|
393
|
+
query(id: string, handler: (args: UiQueryArgs) => Promise<JsonValue>): void;
|
|
382
394
|
invalidate(target: {
|
|
383
395
|
/** Required, except for a `platform.page` contribution, where it must be omitted. */
|
|
384
396
|
orgId?: string;
|
package/dist/file-preview.d.ts
CHANGED
|
@@ -67,7 +67,11 @@ export interface FilePreviewConversationArgs extends FilePreviewArgsBase {
|
|
|
67
67
|
source: "conversation";
|
|
68
68
|
orgId: string;
|
|
69
69
|
accountId: string;
|
|
70
|
-
|
|
70
|
+
/**
|
|
71
|
+
* The conversation the file is previewed in; absent for a library file previewed outside a
|
|
72
|
+
* conversation (the Files page).
|
|
73
|
+
*/
|
|
74
|
+
conversationId?: string;
|
|
71
75
|
}
|
|
72
76
|
/**
|
|
73
77
|
* A preview on a share page: there is no account and no conversation. A previewer that needs the
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/model.d.ts
CHANGED
|
@@ -145,8 +145,8 @@ export declare const DOCUMENT_MEDIA_TYPES: readonly ["application/pdf", "text/pl
|
|
|
145
145
|
export type ImageMediaType = (typeof IMAGE_MEDIA_TYPES)[number];
|
|
146
146
|
export type DocumentMediaType = (typeof DOCUMENT_MEDIA_TYPES)[number];
|
|
147
147
|
/**
|
|
148
|
-
* The source of media content: `base64` is the bytes themselves, `ref`
|
|
149
|
-
*
|
|
148
|
+
* The source of media content: `base64` is the bytes themselves, `ref` names a kernel file by its
|
|
149
|
+
* id (a library file the conversation refers to, or a file the kernel stored for a tool result).
|
|
150
150
|
* The event log stores only `ref` (bytes never enter the log); when building a request the kernel
|
|
151
151
|
* resolves `ref` into `base64`, so plugins only ever receive `base64`.
|
|
152
152
|
*/
|
|
@@ -155,7 +155,7 @@ export type MediaSource = {
|
|
|
155
155
|
data: string;
|
|
156
156
|
} | {
|
|
157
157
|
kind: "ref";
|
|
158
|
-
|
|
158
|
+
fileId: string;
|
|
159
159
|
};
|
|
160
160
|
/**
|
|
161
161
|
* Upper bound on the decoded bytes of a single media block (the smaller value among mainstream
|
|
@@ -241,11 +241,13 @@ export declare function clipMediaName(name: string, max?: number): string;
|
|
|
241
241
|
export declare function hasControlChars(s: string): boolean;
|
|
242
242
|
/** Whether the attachment id is a UUID (any version, case-insensitive). */
|
|
243
243
|
export declare function isAttachmentId(s: unknown): s is string;
|
|
244
|
+
/** Whether the file id (a media `ref`'s `fileId`) is a UUID (any version, case-insensitive). */
|
|
245
|
+
export declare function isFileId(s: unknown): s is string;
|
|
244
246
|
/**
|
|
245
247
|
* Validates an image / document / file block, returning a list of errors (empty means valid): the
|
|
246
248
|
* media type is in the block kind's list (`file` accepts any non-empty `type/subtype`); `base64` is
|
|
247
249
|
* standard, padded, whitespace-free base64 that decodes to at most {@link MEDIA_LIMITS}; a `ref`'s
|
|
248
|
-
* `
|
|
250
|
+
* `fileId` is a UUID; `name`, when present, is a string of at most
|
|
249
251
|
* {@link MEDIA_NAME_MAX_CHARS} characters with no control characters; `size`, when present, is a
|
|
250
252
|
* non-negative integer (display metadata, never sent by a plugin).
|
|
251
253
|
*/
|
package/dist/model.js
CHANGED
|
@@ -110,6 +110,10 @@ export function hasControlChars(s) {
|
|
|
110
110
|
export function isAttachmentId(s) {
|
|
111
111
|
return typeof s === "string" && UUID_RE.test(s);
|
|
112
112
|
}
|
|
113
|
+
/** Whether the file id (a media `ref`'s `fileId`) is a UUID (any version, case-insensitive). */
|
|
114
|
+
export function isFileId(s) {
|
|
115
|
+
return typeof s === "string" && UUID_RE.test(s);
|
|
116
|
+
}
|
|
113
117
|
/** Any non-empty `type/subtype` (a `file` block's `mediaType`). */
|
|
114
118
|
const MEDIA_TYPE_RE = /^[^/\s]+\/[^/\s]+$/;
|
|
115
119
|
const MEDIA = {
|
|
@@ -123,7 +127,7 @@ const MEDIA = {
|
|
|
123
127
|
* Validates an image / document / file block, returning a list of errors (empty means valid): the
|
|
124
128
|
* media type is in the block kind's list (`file` accepts any non-empty `type/subtype`); `base64` is
|
|
125
129
|
* standard, padded, whitespace-free base64 that decodes to at most {@link MEDIA_LIMITS}; a `ref`'s
|
|
126
|
-
* `
|
|
130
|
+
* `fileId` is a UUID; `name`, when present, is a string of at most
|
|
127
131
|
* {@link MEDIA_NAME_MAX_CHARS} characters with no control characters; `size`, when present, is a
|
|
128
132
|
* non-negative integer (display metadata, never sent by a plugin).
|
|
129
133
|
*/
|
|
@@ -166,8 +170,8 @@ export function validateMediaBlock(b) {
|
|
|
166
170
|
}
|
|
167
171
|
const source = src;
|
|
168
172
|
if (source.kind === "ref") {
|
|
169
|
-
if (!
|
|
170
|
-
errs.push(`${o.type} source.
|
|
173
|
+
if (!isFileId(source.fileId)) {
|
|
174
|
+
errs.push(`${o.type} source.fileId must be a UUID file id`);
|
|
171
175
|
}
|
|
172
176
|
}
|
|
173
177
|
else if (source.kind === "base64") {
|
package/dist/permissions.js
CHANGED
|
@@ -4,7 +4,7 @@ import { POLICY_HOOKS } from "./hooks.js";
|
|
|
4
4
|
import { HTTP_ACCESS } from "./http-access.js";
|
|
5
5
|
import { SETUP_CHECK_ID_RE, SETUP_CHECK_LIMITS } from "./setup-check.js";
|
|
6
6
|
import { TRIGGER_MAX_TYPES, TRIGGER_TYPE_RE } from "./triggers.js";
|
|
7
|
-
import { UI_ICONS } from "./ui.js";
|
|
7
|
+
import { UI_ICONS, UI_PAGE_FRAMES, UI_PAGE_NAVS } from "./ui.js";
|
|
8
8
|
import { isCompactForm, parseSlotRef, uiSlot } from "./ui-slots.js";
|
|
9
9
|
/** The most services `permissions.deviceAccess.services` may list. */
|
|
10
10
|
export const DEVICE_ACCESS_MAX_SERVICES = 4;
|
|
@@ -343,6 +343,20 @@ export function validateUiContributions(ui, permissions) {
|
|
|
343
343
|
if (seen.has(id))
|
|
344
344
|
errs.push(`ui has duplicate id "${id}"`);
|
|
345
345
|
seen.set(id, c.kind);
|
|
346
|
+
if (c.frame !== undefined || c.nav !== undefined) {
|
|
347
|
+
const onPage = slotRef?.id === "org.page" && c.kind === "component";
|
|
348
|
+
for (const [k, allowed] of [
|
|
349
|
+
["frame", UI_PAGE_FRAMES],
|
|
350
|
+
["nav", UI_PAGE_NAVS],
|
|
351
|
+
]) {
|
|
352
|
+
if (c[k] === undefined)
|
|
353
|
+
continue;
|
|
354
|
+
if (!onPage)
|
|
355
|
+
errs.push(`ui "${id}" ${k} is only allowed on a component of the org.page slot`);
|
|
356
|
+
else if (!allowed.includes(c[k]))
|
|
357
|
+
errs.push(`ui "${id}" ${k} must be one of ${allowed.join(", ")}`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
346
360
|
if (c.kind === "view") {
|
|
347
361
|
if (c.path !== undefined)
|
|
348
362
|
errs.push(`ui "${id}" path is only allowed for kind embed`);
|
package/dist/ui-slots.js
CHANGED
|
@@ -85,13 +85,13 @@ const SLOT_DATA = [
|
|
|
85
85
|
accepts: ["view", "embed", "component"],
|
|
86
86
|
cardinality: "list",
|
|
87
87
|
minRole: "member",
|
|
88
|
-
args: [],
|
|
88
|
+
args: ["params"],
|
|
89
89
|
density: "regular",
|
|
90
90
|
icon: "optional",
|
|
91
91
|
compact: "kept",
|
|
92
92
|
description: {
|
|
93
|
-
en: "A full page in the organization navigation.",
|
|
94
|
-
zh: "
|
|
93
|
+
en: "A full page in the organization navigation. Only component contributions receive `params` (the page query string); views and embeds do not.",
|
|
94
|
+
zh: "组织导航中的完整页面。只有 component 贡献会收到 `params`(页面查询串),view 与 embed 不会。",
|
|
95
95
|
},
|
|
96
96
|
},
|
|
97
97
|
{
|
package/dist/ui.d.ts
CHANGED
|
@@ -55,7 +55,26 @@ export interface UiContribution {
|
|
|
55
55
|
* see `effectiveCompact`. Omitted = the slot's form.
|
|
56
56
|
*/
|
|
57
57
|
compact?: CompactForm;
|
|
58
|
+
/**
|
|
59
|
+
* `org.page` component only. `"host"` (default): the host draws the page title and the page
|
|
60
|
+
* chrome around the component; `"page"`: the component draws the whole page itself.
|
|
61
|
+
*/
|
|
62
|
+
frame?: UiPageFrame;
|
|
63
|
+
/**
|
|
64
|
+
* `org.page` component only, a suggestion an org admin's saved choice beats. `"more"`
|
|
65
|
+
* (default): listed under the navigation's more entry; `"primary"`: listed in the primary
|
|
66
|
+
* navigation (at most 3 plugin pages there).
|
|
67
|
+
*/
|
|
68
|
+
nav?: UiPageNav;
|
|
58
69
|
}
|
|
70
|
+
/** How an `org.page` component page is framed ({@link UiContribution.frame}). */
|
|
71
|
+
export type UiPageFrame = "host" | "page";
|
|
72
|
+
/** Where an `org.page` component page is listed ({@link UiContribution.nav}). */
|
|
73
|
+
export type UiPageNav = "primary" | "more";
|
|
74
|
+
/** The accepted values of {@link UiContribution.frame}. */
|
|
75
|
+
export declare const UI_PAGE_FRAMES: readonly UiPageFrame[];
|
|
76
|
+
/** The accepted values of {@link UiContribution.nav}. */
|
|
77
|
+
export declare const UI_PAGE_NAVS: readonly UiPageNav[];
|
|
59
78
|
/**
|
|
60
79
|
* Blocks of the render schema. Text is for humans and shown as is (the plugin decides the language
|
|
61
80
|
* itself, usually taking `locale`).
|
|
@@ -154,6 +173,11 @@ export interface UiView {
|
|
|
154
173
|
* - `textChars`: total characters of all text in the whole view (form JSON included);
|
|
155
174
|
* - `payloadBytes`: UTF-8 bytes of a single button `payload` after JSON serialization.
|
|
156
175
|
* - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
|
|
176
|
+
* - `componentQueryBytes`: the UTF-8 bytes of a `ctx.ui.query` result as JSON.
|
|
177
|
+
* - `componentQueryParamsBytes`: the UTF-8 bytes of a query's `params` as JSON.
|
|
178
|
+
* - `componentActionPayloadBytes`: the UTF-8 bytes of a component action's `payload` as JSON
|
|
179
|
+
* (view block buttons keep `payloadBytes`).
|
|
180
|
+
* - `pageParamsBytes`: the UTF-8 bytes of a page's URL params (all keys and values).
|
|
157
181
|
*/
|
|
158
182
|
export declare const UI_LIMITS: {
|
|
159
183
|
readonly blocks: 50;
|
|
@@ -162,6 +186,10 @@ export declare const UI_LIMITS: {
|
|
|
162
186
|
readonly textChars: 20000;
|
|
163
187
|
readonly payloadBytes: 2000;
|
|
164
188
|
readonly componentDataBytes: 32768;
|
|
189
|
+
readonly componentQueryBytes: 1048576;
|
|
190
|
+
readonly componentQueryParamsBytes: 16384;
|
|
191
|
+
readonly componentActionPayloadBytes: 65536;
|
|
192
|
+
readonly pageParamsBytes: 2048;
|
|
165
193
|
};
|
|
166
194
|
/**
|
|
167
195
|
* Validates the view a plugin returns and returns the list of problems (empty = valid). Links and
|
|
@@ -265,14 +293,29 @@ export interface UiPlatformActionArgs extends UiPlatformRenderArgs, UiActionInpu
|
|
|
265
293
|
* `answer`.
|
|
266
294
|
*/
|
|
267
295
|
export type UiActionArgs = UiOrgActionArgs | UiPlatformActionArgs;
|
|
268
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* The args of a `ctx.ui.query` handler: the org position of the call, the query id and its params
|
|
298
|
+
* (JSON of at most `UI_LIMITS.componentQueryParamsBytes` bytes). `signal` aborts when the caller
|
|
299
|
+
* goes away.
|
|
300
|
+
*/
|
|
301
|
+
export interface UiQueryArgs extends UiOrgRenderArgs {
|
|
302
|
+
query: string;
|
|
303
|
+
params: JsonValue;
|
|
304
|
+
signal: AbortSignal;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* An action result: a notice, or a new view. `invalidate` names queries the host refetches
|
|
308
|
+
* (component actions only).
|
|
309
|
+
*/
|
|
269
310
|
export type UiActionResult = {
|
|
270
311
|
toast?: {
|
|
271
312
|
zh: string;
|
|
272
313
|
en: string;
|
|
273
314
|
};
|
|
315
|
+
invalidate?: string[];
|
|
274
316
|
} | {
|
|
275
317
|
view: UiView;
|
|
318
|
+
invalidate?: string[];
|
|
276
319
|
};
|
|
277
320
|
/** The embed claims every scope shares. `exp` is Unix seconds. */
|
|
278
321
|
export interface EmbedClaimsBase {
|
|
@@ -293,7 +336,10 @@ export interface OrgEmbedClaims extends EmbedClaimsBase {
|
|
|
293
336
|
conversationId?: string;
|
|
294
337
|
/** Only an agent embed's token (`agent.detail.section`): the agent it was issued for. */
|
|
295
338
|
agentId?: string;
|
|
296
|
-
/**
|
|
339
|
+
/**
|
|
340
|
+
* Only a `file-preview` embed's token: the one file it previews, of `conversationId`, or without
|
|
341
|
+
* one a library file of `accountId`'s own.
|
|
342
|
+
*/
|
|
297
343
|
fileId?: string;
|
|
298
344
|
/**
|
|
299
345
|
* Only a `file-preview` embed's token for a skill file (no `conversationId`, `agentId` or
|
package/dist/ui.js
CHANGED
|
@@ -17,6 +17,10 @@ export const UI_ICONS = [
|
|
|
17
17
|
"globe",
|
|
18
18
|
"puzzle",
|
|
19
19
|
];
|
|
20
|
+
/** The accepted values of {@link UiContribution.frame}. */
|
|
21
|
+
export const UI_PAGE_FRAMES = ["host", "page"];
|
|
22
|
+
/** The accepted values of {@link UiContribution.nav}. */
|
|
23
|
+
export const UI_PAGE_NAVS = ["primary", "more"];
|
|
20
24
|
/**
|
|
21
25
|
* View limits (checked uniformly by {@link validateUiView}):
|
|
22
26
|
* - `blocks`: number of blocks;
|
|
@@ -26,6 +30,11 @@ export const UI_ICONS = [
|
|
|
26
30
|
* - `textChars`: total characters of all text in the whole view (form JSON included);
|
|
27
31
|
* - `payloadBytes`: UTF-8 bytes of a single button `payload` after JSON serialization.
|
|
28
32
|
* - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
|
|
33
|
+
* - `componentQueryBytes`: the UTF-8 bytes of a `ctx.ui.query` result as JSON.
|
|
34
|
+
* - `componentQueryParamsBytes`: the UTF-8 bytes of a query's `params` as JSON.
|
|
35
|
+
* - `componentActionPayloadBytes`: the UTF-8 bytes of a component action's `payload` as JSON
|
|
36
|
+
* (view block buttons keep `payloadBytes`).
|
|
37
|
+
* - `pageParamsBytes`: the UTF-8 bytes of a page's URL params (all keys and values).
|
|
29
38
|
*/
|
|
30
39
|
export const UI_LIMITS = {
|
|
31
40
|
blocks: 50,
|
|
@@ -34,6 +43,10 @@ export const UI_LIMITS = {
|
|
|
34
43
|
textChars: 20000,
|
|
35
44
|
payloadBytes: 2000,
|
|
36
45
|
componentDataBytes: 32768,
|
|
46
|
+
componentQueryBytes: 1048576,
|
|
47
|
+
componentQueryParamsBytes: 16384,
|
|
48
|
+
componentActionPayloadBytes: 65536,
|
|
49
|
+
pageParamsBytes: 2048,
|
|
37
50
|
};
|
|
38
51
|
const BADGE_MAX = 32;
|
|
39
52
|
/** Longest item / block `id` and open target `item`. */
|