@capybara-hq/plugin-sdk 0.1.0-rc.8 → 0.1.0-rc.81
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 +11 -3
- 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 +3 -1
- package/agent-docs/extension-points/identity-source.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 +77 -4
- package/agent-docs/plugin-format.md +45 -10
- 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 +97 -13
- package/dist/cards.js +121 -19
- package/dist/channel.d.ts +133 -47
- 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 +28 -6
- package/dist/config-ui.js +88 -25
- package/dist/config-url-fetch.d.ts +19 -0
- package/dist/config-url-fetch.js +43 -0
- package/dist/connector-auth.d.ts +13 -2
- package/dist/connector-auth.js +82 -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 +224 -30
- package/dist/ctx.js +9 -1
- package/dist/define-extension.d.ts +23 -13
- package/dist/define-extension.js +19 -5
- package/dist/device-denied-paths.d.ts +20 -0
- package/dist/device-denied-paths.js +118 -0
- package/dist/device-operation.d.ts +339 -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 +780 -0
- package/dist/device-provider.js +409 -0
- package/dist/device-service.d.ts +126 -0
- package/dist/device-service.js +211 -0
- package/dist/dial-in.d.ts +286 -0
- package/dist/dial-in.js +213 -0
- package/dist/directory.d.ts +15 -12
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +7 -3
- package/dist/field-meta.d.ts +19 -0
- package/dist/field-meta.js +54 -0
- package/dist/file-preview.d.ts +43 -10
- 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 +71 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +70 -9
- package/dist/identity.js +46 -1
- package/dist/index.d.ts +28 -4
- package/dist/index.js +28 -4
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +227 -75
- package/dist/model.js +152 -19
- package/dist/native-failure.d.ts +13 -0
- package/dist/native-failure.js +31 -0
- 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 +65 -22
- package/dist/permissions.js +139 -43
- package/dist/platform-only.d.ts +27 -0
- package/dist/platform-only.js +35 -0
- package/dist/plugin-manifest.d.ts +30 -6
- package/dist/plugin-manifest.js +147 -55
- package/dist/plugin-package.d.ts +82 -39
- package/dist/plugin-package.js +68 -41
- 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 +2343 -0
- package/dist/sandbox-native-runtime-source.d.ts +10 -0
- package/dist/sandbox-native-runtime-source.js +480 -0
- package/dist/sandbox-runtime-source.d.ts +47 -0
- package/dist/sandbox-runtime-source.js +73 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/secret.d.ts +8 -2
- package/dist/secret.js +11 -4
- 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 +86 -72
- package/dist/setup-guide.js +340 -108
- 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-invocation.d.ts +5 -0
- package/dist/skill-invocation.js +4 -3
- 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 +25 -9
- package/dist/theme-assets.js +87 -47
- package/dist/theme-tokens.generated.d.ts +26 -2
- package/dist/theme-tokens.generated.js +17 -0
- package/dist/theme.d.ts +48 -10
- package/dist/theme.js +100 -21
- package/dist/tool.d.ts +196 -31
- package/dist/tool.js +133 -13
- 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 +245 -77
- package/dist/ui.js +104 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/dist/web.d.ts +26 -20
- package/package.json +12 -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 +62 -4
- package/schemas/plugin.v1.schema.json +74 -143
- package/schemas/theme.v1.schema.json +77 -0
- package/agent-docs/extension-points/sandbox.md +0 -15
- package/dist/org-access.d.ts +0 -27
- package/dist/org-access.js +0 -35
- package/dist/sandbox.d.ts +0 -254
- package/dist/sandbox.js +0 -153
package/dist/theme.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { BUILTIN_AVATAR_PRESET_IDS } from "./avatar-presets.js";
|
|
2
3
|
import { CATALOG_ITEM_NAME_RE, isSafePackagePath } from "./plugin-package.js";
|
|
3
4
|
import { checkThemeReadability } from "./theme-readability.js";
|
|
4
5
|
import { THEME_OVERRIDABLE, THEME_TOKENS } from "./theme-tokens.generated.js";
|
|
5
6
|
/**
|
|
6
7
|
* A theme file `themes/<id>.json` (themes spec §4): a partial override of the design tokens per
|
|
7
|
-
* scheme, optional fonts
|
|
8
|
+
* scheme, optional fonts, an optional logo and the brand fields (theme brand coverage spec §1:
|
|
9
|
+
* illustration, app icons, decoration, avatar presets). The id is the file's base name
|
|
8
10
|
* ({@link themeIdOf}, `CATALOG_ITEM_NAME_RE`).
|
|
9
11
|
*
|
|
10
12
|
* {@link parseThemeFile} is the CSS-injection boundary: every token value is parsed against the
|
|
11
13
|
* grammar `tokens.json` uses (`#RRGGBB`, `rgba(r,g,b,a)`, shadows `<x> <y> <blur> [<spread>]
|
|
12
14
|
* <color>`) and re-rendered from its parts in canonical form. Asset paths (`fonts[].file`,
|
|
13
|
-
* `logo
|
|
14
|
-
* to `[A-Za-z0-9._-]`, so they need no escaping inside `url(...)`. Font
|
|
15
|
-
* letters, digits, spaces and `-`. Free text (`name`, `description`,
|
|
16
|
-
* control, format, line / paragraph separator or
|
|
17
|
-
* never CSS. Whether the files exist and their
|
|
18
|
-
* the reader of the package, with {@link THEME_LIMITS}.
|
|
15
|
+
* `logo.*`, `avatars[].file`) are relative to the plugin root (an optional leading `./`) and every
|
|
16
|
+
* segment is limited to `[A-Za-z0-9._-]`, so they need no escaping inside `url(...)`. Font
|
|
17
|
+
* families are limited to letters, digits, spaces and `-`. Free text (`name`, `description`,
|
|
18
|
+
* `logo.wordmark`, `avatars[].name`) carries no control, format, line / paragraph separator or
|
|
19
|
+
* lone surrogate characters; it is text for the UI, never CSS. Whether the files exist and their
|
|
20
|
+
* size / signature / SVG rules are checked by the reader of the package, with {@link THEME_LIMITS}.
|
|
19
21
|
*
|
|
20
22
|
* The committed JSON Schema (`schemas/theme.v1.schema.json`) is generated from
|
|
21
23
|
* {@link ThemeFileSchema} (the shape only) by `pnpm gen:package-schemas`; token names, value
|
|
@@ -27,7 +29,7 @@ export const THEME_LIMITS = {
|
|
|
27
29
|
fileBytes: 64 * 1024,
|
|
28
30
|
/** Themes per plugin. */
|
|
29
31
|
perPlugin: 10,
|
|
30
|
-
/** Total bytes of a plugin's theme assets (fonts and
|
|
32
|
+
/** Total bytes of a plugin's theme assets (fonts, logos, app icons and avatars). */
|
|
31
33
|
assetsBytes: 16 * 1024 * 1024,
|
|
32
34
|
/** Fonts per theme. */
|
|
33
35
|
fonts: 8,
|
|
@@ -39,10 +41,21 @@ export const THEME_LIMITS = {
|
|
|
39
41
|
pngBytes: 256 * 1024,
|
|
40
42
|
/** Minimum pixel height of a logo PNG. */
|
|
41
43
|
pngMinHeight: 64,
|
|
42
|
-
/** Characters of the wordmark. */
|
|
44
|
+
/** Characters of the wordmark (and of each avatar preset name). */
|
|
43
45
|
wordmark: 24,
|
|
46
|
+
/** Avatar presets per theme. */
|
|
47
|
+
avatars: 12,
|
|
48
|
+
/** Bytes of an app icon PNG. */
|
|
49
|
+
appIconBytes: 1_048_576,
|
|
50
|
+
/** Minimum pixel size of an app icon PNG (square). */
|
|
51
|
+
appIconMinSize: 512,
|
|
44
52
|
};
|
|
45
|
-
/** `
|
|
53
|
+
/** The id of a theme's avatar preset (`avatars[].id`); never a built-in preset id. */
|
|
54
|
+
export const THEME_AVATAR_ID_RE = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
55
|
+
/** The sign-in page background decoration (the dither columns) a theme asks for; omitted means
|
|
56
|
+
* `dither`. */
|
|
57
|
+
export const THEME_DECORATIONS = ["dither", "none"];
|
|
58
|
+
/** `themes/neon-grid.json` → `neon-grid`. */
|
|
46
59
|
export function themeIdOf(path) {
|
|
47
60
|
return (path.split("/").pop() ?? "").replace(/\.json$/, "");
|
|
48
61
|
}
|
|
@@ -53,6 +66,8 @@ const FORBIDDEN_CHARS_RE = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Cs}]/u;
|
|
|
53
66
|
const PATH_SEGMENT_RE = /^[A-Za-z0-9._-]+$/;
|
|
54
67
|
const FORBIDDEN_CHARS_MESSAGE = "must not contain control, format, line / paragraph separator or lone surrogate characters";
|
|
55
68
|
const IMAGE_RE = /\.(?:svg|png)$/i;
|
|
69
|
+
const PNG_RE = /\.png$/i;
|
|
70
|
+
const BUILTIN_AVATARS = new Set(BUILTIN_AVATAR_PRESET_IDS);
|
|
56
71
|
const MAX_VALUE_CHARS = 256;
|
|
57
72
|
const text = (max, what) => z
|
|
58
73
|
.string()
|
|
@@ -60,6 +75,14 @@ const text = (max, what) => z
|
|
|
60
75
|
.max(max)
|
|
61
76
|
.regex(/\S/, { message: `${what} must not be blank` })
|
|
62
77
|
.refine((t) => !FORBIDDEN_CHARS_RE.test(t), { message: `${what} ${FORBIDDEN_CHARS_MESSAGE}` });
|
|
78
|
+
/** Short free text (the wordmark, avatar names): not blank, ≤ 24 characters, no forbidden ones. */
|
|
79
|
+
const shortText = (what) => z
|
|
80
|
+
.string()
|
|
81
|
+
.regex(/\S/, { message: `${what} must not be blank` })
|
|
82
|
+
.refine((w) => [...w].length <= THEME_LIMITS.wordmark, {
|
|
83
|
+
message: `${what} must be at most ${THEME_LIMITS.wordmark} characters`,
|
|
84
|
+
})
|
|
85
|
+
.refine((w) => !FORBIDDEN_CHARS_RE.test(w), { message: `${what} ${FORBIDDEN_CHARS_MESSAGE}` });
|
|
63
86
|
/** A plugin-root relative path (optional `./`), each segment `[A-Za-z0-9._-]`, no `.` / `..`. */
|
|
64
87
|
const isPlainAssetPath = (p) => {
|
|
65
88
|
const rest = p.replace(/^\.\//, "");
|
|
@@ -81,7 +104,15 @@ const schemeOverride = z.strictObject({
|
|
|
81
104
|
.strictObject({ sm: radius.optional(), md: radius.optional(), bubble: radius.optional() })
|
|
82
105
|
.optional(),
|
|
83
106
|
});
|
|
84
|
-
const
|
|
107
|
+
const avatarPreset = z.strictObject({
|
|
108
|
+
id: z.string().regex(THEME_AVATAR_ID_RE, {
|
|
109
|
+
message: "id must match ^[a-z0-9][a-z0-9-]{0,31}$",
|
|
110
|
+
}),
|
|
111
|
+
name: z.strictObject({ en: shortText("name.en"), zh: shortText("name.zh").optional() }),
|
|
112
|
+
file: assetPath("file", IMAGE_RE, ".svg or .png"),
|
|
113
|
+
});
|
|
114
|
+
const shape = z
|
|
115
|
+
.strictObject({
|
|
85
116
|
$schema: z.string().max(512).optional(),
|
|
86
117
|
name: z.strictObject({ zh: text(100, "name.zh"), en: text(100, "name.en") }),
|
|
87
118
|
description: z
|
|
@@ -110,19 +141,67 @@ const shape = z.strictObject({
|
|
|
110
141
|
logo: z
|
|
111
142
|
.strictObject({
|
|
112
143
|
mark: assetPath("mark", IMAGE_RE, ".svg or .png").optional(),
|
|
113
|
-
wordmark:
|
|
114
|
-
.string()
|
|
115
|
-
.regex(/\S/, { message: "wordmark must not be blank" })
|
|
116
|
-
.refine((w) => [...w].length <= THEME_LIMITS.wordmark, {
|
|
117
|
-
message: `wordmark must be at most ${THEME_LIMITS.wordmark} characters`,
|
|
118
|
-
})
|
|
119
|
-
.refine((w) => !FORBIDDEN_CHARS_RE.test(w), {
|
|
120
|
-
message: `wordmark ${FORBIDDEN_CHARS_MESSAGE}`,
|
|
121
|
-
})
|
|
122
|
-
.optional(),
|
|
144
|
+
wordmark: shortText("wordmark").optional(),
|
|
123
145
|
favicon: assetPath("favicon", IMAGE_RE, ".svg or .png").optional(),
|
|
146
|
+
illustration: assetPath("illustration", IMAGE_RE, ".svg or .png").optional(),
|
|
147
|
+
appIcon: assetPath("appIcon", PNG_RE, ".png").optional(),
|
|
148
|
+
appIconMaskable: assetPath("appIconMaskable", PNG_RE, ".png").optional(),
|
|
149
|
+
})
|
|
150
|
+
.superRefine((l, ctx) => {
|
|
151
|
+
if (l.appIconMaskable !== undefined && l.appIcon === undefined) {
|
|
152
|
+
ctx.addIssue({
|
|
153
|
+
code: "custom",
|
|
154
|
+
path: ["appIconMaskable"],
|
|
155
|
+
message: "appIconMaskable requires appIcon",
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
.optional(),
|
|
160
|
+
decoration: z.enum(THEME_DECORATIONS).optional(),
|
|
161
|
+
avatars: z
|
|
162
|
+
.array(avatarPreset)
|
|
163
|
+
.max(THEME_LIMITS.avatars)
|
|
164
|
+
.superRefine((list, ctx) => {
|
|
165
|
+
const seen = new Set();
|
|
166
|
+
list.forEach((a, i) => {
|
|
167
|
+
if (BUILTIN_AVATARS.has(a.id)) {
|
|
168
|
+
ctx.addIssue({
|
|
169
|
+
code: "custom",
|
|
170
|
+
path: [i, "id"],
|
|
171
|
+
message: `id must not be a built-in avatar preset id (${a.id})`,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
else if (seen.has(a.id)) {
|
|
175
|
+
ctx.addIssue({
|
|
176
|
+
code: "custom",
|
|
177
|
+
path: [i, "id"],
|
|
178
|
+
message: `duplicate avatar id ${a.id}`,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
seen.add(a.id);
|
|
182
|
+
});
|
|
124
183
|
})
|
|
125
184
|
.optional(),
|
|
185
|
+
hideAvatarPresets: z
|
|
186
|
+
.array(z.enum(BUILTIN_AVATAR_PRESET_IDS))
|
|
187
|
+
.superRefine((list, ctx) => {
|
|
188
|
+
list.forEach((id, i) => {
|
|
189
|
+
if (list.indexOf(id) !== i) {
|
|
190
|
+
ctx.addIssue({ code: "custom", path: [i], message: `duplicate hidden preset ${id}` });
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
})
|
|
194
|
+
.optional(),
|
|
195
|
+
})
|
|
196
|
+
.superRefine((t, ctx) => {
|
|
197
|
+
const hidden = new Set(t.hideAvatarPresets ?? []);
|
|
198
|
+
if (hidden.size === BUILTIN_AVATAR_PRESET_IDS.length && (t.avatars?.length ?? 0) === 0) {
|
|
199
|
+
ctx.addIssue({
|
|
200
|
+
code: "custom",
|
|
201
|
+
path: ["hideAvatarPresets"],
|
|
202
|
+
message: "hiding every built-in avatar preset requires at least one entry in avatars",
|
|
203
|
+
});
|
|
204
|
+
}
|
|
126
205
|
});
|
|
127
206
|
/**
|
|
128
207
|
* The zod schema of a theme file's shape (strict objects). Token names and values are only
|
package/dist/tool.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ParamSchema } from "./model-params.js";
|
|
2
|
-
|
|
2
|
+
import type { UiOpen } from "./ui.js";
|
|
3
|
+
/** Tool annotations (hints aligned with MCP, used to derive the default policy). */
|
|
3
4
|
export interface ToolAnnotations {
|
|
4
5
|
readOnlyHint?: boolean;
|
|
5
6
|
destructiveHint?: boolean;
|
|
@@ -7,17 +8,47 @@ export interface ToolAnnotations {
|
|
|
7
8
|
openWorldHint?: boolean;
|
|
8
9
|
requiresUserInteraction?: boolean;
|
|
9
10
|
}
|
|
11
|
+
/** Where a conversation comes from; a tool may limit itself to some of these. */
|
|
12
|
+
export declare const CONVERSATION_SOURCES: readonly ["web", "channel_dm", "channel_group", "subagent"];
|
|
13
|
+
/** A conversation source (see {@link CONVERSATION_SOURCES}). */
|
|
14
|
+
export type ConversationSource = (typeof CONVERSATION_SOURCES)[number];
|
|
15
|
+
/**
|
|
16
|
+
* How a tool's input is previewed while it streams ({@link ToolSpec.inputView}). Every name is a
|
|
17
|
+
* string property of the tool's `inputSchema`.
|
|
18
|
+
*/
|
|
19
|
+
export type ToolInputView = {
|
|
20
|
+
kind: "file_write";
|
|
21
|
+
path: string;
|
|
22
|
+
content: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "file_edit";
|
|
25
|
+
path: string;
|
|
26
|
+
old: string;
|
|
27
|
+
new: string;
|
|
28
|
+
} | {
|
|
29
|
+
kind: "command";
|
|
30
|
+
command: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
} | {
|
|
33
|
+
kind: "text";
|
|
34
|
+
field: string;
|
|
35
|
+
};
|
|
10
36
|
export interface ToolSpec {
|
|
11
37
|
name: string;
|
|
12
38
|
description: string;
|
|
13
39
|
inputSchema: Record<string, unknown>;
|
|
14
40
|
annotations?: ToolAnnotations;
|
|
15
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Only plugin / builtin tools may declare it; when omitted it is derived from the annotations.
|
|
43
|
+
*/
|
|
16
44
|
defaultPolicy?: "allow" | "ask";
|
|
17
45
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
46
|
+
* Connector tools only: the connector's own opaque data (e.g. OpenAPI's method, path template,
|
|
47
|
+
* parameter locations, server address), JSON-serializable.
|
|
48
|
+
* The kernel stores it with the definition in the snapshot and counts it in the fingerprint (a
|
|
49
|
+
* change means drift and needs review), and hands it back unchanged via `ctx.spec` of `callTool`
|
|
50
|
+
* on a call;
|
|
51
|
+
* never sent to the model.
|
|
21
52
|
*/
|
|
22
53
|
connectorData?: Record<string, unknown>;
|
|
23
54
|
/**
|
|
@@ -33,7 +64,33 @@ export interface ToolSpec {
|
|
|
33
64
|
* model and not part of the definition fingerprint.
|
|
34
65
|
*/
|
|
35
66
|
keyArgs?: string[];
|
|
67
|
+
/**
|
|
68
|
+
* Display only: how the UI previews this tool's input while the model is still writing it. Names
|
|
69
|
+
* string properties of `inputSchema` that carry a file body, an edit, a command or free text.
|
|
70
|
+
* Never sent to the model and not part of the definition fingerprint. Nothing streamed ever
|
|
71
|
+
* executes: the call runs from the logged assistant message.
|
|
72
|
+
*/
|
|
73
|
+
inputView?: ToolInputView;
|
|
74
|
+
/**
|
|
75
|
+
* The conversation sources this tool is offered in; absent = every source. A non-empty list of
|
|
76
|
+
* {@link CONVERSATION_SOURCES}.
|
|
77
|
+
*/
|
|
78
|
+
sources?: ConversationSource[];
|
|
79
|
+
/**
|
|
80
|
+
* Extension tools only: the time limit of one call in milliseconds, a whole number from
|
|
81
|
+
* {@link TOOL_TIMEOUT_MIN_MS} to {@link TOOL_TIMEOUT_MAX_MS}. When declared, the deployment's
|
|
82
|
+
* `tools.timeoutMs` no longer applies to the tool; the deployment's `tools.maxTimeoutMs`
|
|
83
|
+
* (default {@link TOOL_TIMEOUT_MAX_MS}) cuts a longer value. Absent: `tools.timeoutMs`. Declare
|
|
84
|
+
* it when a call may legitimately take longer, e.g. one that first starts a device service
|
|
85
|
+
* (`ctx.deviceAccess.ensureService`). Never sent to the model and not part of the definition
|
|
86
|
+
* fingerprint.
|
|
87
|
+
*/
|
|
88
|
+
timeoutMs?: number;
|
|
36
89
|
}
|
|
90
|
+
/** Shortest {@link ToolSpec.timeoutMs}: one second. */
|
|
91
|
+
export declare const TOOL_TIMEOUT_MIN_MS = 1000;
|
|
92
|
+
/** Longest {@link ToolSpec.timeoutMs} the kernel accepts: ten minutes. */
|
|
93
|
+
export declare const TOOL_TIMEOUT_MAX_MS = 600000;
|
|
37
94
|
/** Longest {@link ToolSpec.title}, in code points. */
|
|
38
95
|
export declare const TOOL_TITLE_MAX = 80;
|
|
39
96
|
/** Most {@link ToolSpec.keyArgs}. */
|
|
@@ -44,7 +101,7 @@ export declare const TOOL_KEY_ARGS_MAX = 3;
|
|
|
44
101
|
* characters (Unicode Cc / Cf); keyArgs are at most 3 unique strings, each a property of
|
|
45
102
|
* `inputSchema.properties` and free of Cc / Cf characters.
|
|
46
103
|
*/
|
|
47
|
-
export declare function validateToolPresentation(spec: Pick<ToolSpec, "title" | "keyArgs" | "inputSchema">): string[];
|
|
104
|
+
export declare function validateToolPresentation(spec: Pick<ToolSpec, "title" | "keyArgs" | "inputView" | "inputSchema">): string[];
|
|
48
105
|
export type ToolContent = {
|
|
49
106
|
type: "text";
|
|
50
107
|
text: string;
|
|
@@ -58,45 +115,75 @@ export type ToolContent = {
|
|
|
58
115
|
name?: string;
|
|
59
116
|
mimeType?: string;
|
|
60
117
|
};
|
|
61
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* A one-sentence description of a tool call, shown in the UI (Chinese and English each ≤ 200
|
|
120
|
+
* characters); does not enter the model context.
|
|
121
|
+
*/
|
|
62
122
|
export interface ToolDisplay {
|
|
63
123
|
summary: {
|
|
64
124
|
zh: string;
|
|
65
125
|
en: string;
|
|
66
126
|
};
|
|
67
127
|
}
|
|
128
|
+
/** The most characters of `ToolResult.card.text`. */
|
|
129
|
+
export declare const CARD_TEXT_MAX = 2000;
|
|
68
130
|
export interface ToolResult {
|
|
69
131
|
content: ToolContent[];
|
|
70
132
|
isError?: boolean;
|
|
71
|
-
/**
|
|
133
|
+
/** Optional: show this description in the conversation stream in place of the raw input JSON. */
|
|
72
134
|
display?: ToolDisplay;
|
|
73
135
|
/**
|
|
74
136
|
* Optional: an inline card under this call in the conversation: `view` is a ui contribution of
|
|
75
|
-
* the same extension
|
|
76
|
-
* (recorded on the `tool_result` event, never in the model's
|
|
77
|
-
* with a warning and the result is kept.
|
|
137
|
+
* the same extension in the `conversation.tool-result.card` slot, rendered with
|
|
138
|
+
* `card: { callId, key }`. Display only (recorded on the `tool_result` event, never in the model's
|
|
139
|
+
* context); an unknown view is dropped with a warning and the result is kept.
|
|
140
|
+
*
|
|
141
|
+
* `placement` says where the card shows: `output` (default) lifted out after the run's process
|
|
142
|
+
* block, where the person sees it with the answer; `pinned` as the run's pinned card, kept in
|
|
143
|
+
* view while the run goes on (a plan or todo list; the latest pinned card per (extension, view)
|
|
144
|
+
* of the run wins); `process` only inside the process block, after its call.
|
|
145
|
+
* `text` is the card's Markdown text for surfaces that cannot draw the view (IM channels, the
|
|
146
|
+
* pinned card of a channel's progress card), at most {@link CARD_TEXT_MAX} characters.
|
|
78
147
|
*/
|
|
79
148
|
card?: {
|
|
80
149
|
view: string;
|
|
81
150
|
key?: string;
|
|
151
|
+
placement?: "output" | "pinned" | "process";
|
|
152
|
+
text?: string;
|
|
82
153
|
};
|
|
83
154
|
}
|
|
84
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* Validates a {@link ToolDisplay} and returns the list of problems (empty = valid); length is
|
|
157
|
+
* counted in Unicode code points.
|
|
158
|
+
*/
|
|
85
159
|
export declare function validateToolDisplay(d: unknown): string[];
|
|
86
160
|
/** Text shown to people: bilingual (`zh` / `en`) or a single string shown as is. */
|
|
87
161
|
export type LocalizedText = {
|
|
88
162
|
zh: string;
|
|
89
163
|
en: string;
|
|
90
164
|
} | string;
|
|
91
|
-
/**
|
|
165
|
+
/**
|
|
166
|
+
* Interactive form: field schemas use only the ParamSchema subset of M2; enum fields may set
|
|
167
|
+
* multiSelect and allowOther.
|
|
168
|
+
*/
|
|
92
169
|
export interface InputForm {
|
|
93
|
-
/**
|
|
170
|
+
/**
|
|
171
|
+
* A plugin may give both languages; builtin kernel tools give English (model-generated questions
|
|
172
|
+
* are displayed as is).
|
|
173
|
+
*/
|
|
94
174
|
title: LocalizedText;
|
|
95
175
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
176
|
+
* Optional: an external page the user must open in a browser (e.g. an MCP URL-mode elicitation:
|
|
177
|
+
* go to the other party's page to authorize / pay / enter sensitive information).
|
|
178
|
+
* The UI shows it as a link (the full address visible); only absolute http(s) addresses, ≤ 2000
|
|
179
|
+
* characters, are accepted.
|
|
98
180
|
*/
|
|
99
181
|
url?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Optional: longer text under the title (the reason, what to do), at most
|
|
184
|
+
* {@link INPUT_FORM_BODY_MAX} characters, shown as plain text. Keep the title short.
|
|
185
|
+
*/
|
|
186
|
+
body?: LocalizedText;
|
|
100
187
|
fields: {
|
|
101
188
|
key: string;
|
|
102
189
|
label: LocalizedText;
|
|
@@ -105,58 +192,136 @@ export interface InputForm {
|
|
|
105
192
|
multiSelect?: boolean;
|
|
106
193
|
allowOther?: boolean;
|
|
107
194
|
required?: boolean;
|
|
195
|
+
/**
|
|
196
|
+
* Buttons in place of the field's control: one per choice, the first is the primary, and pressing one answers
|
|
197
|
+
* the form with its value at once (no separate Answer). Allowed only on the form's single
|
|
198
|
+
* field, when it is required and a single choice: a `boolean` (values `true` / `false`) or a
|
|
199
|
+
* string `enum` without `multiSelect` / `allowOther` (values from the enum). 1 to
|
|
200
|
+
* {@link INPUT_CHOICES_MAX} choices with distinct values; labels at most
|
|
201
|
+
* {@link INPUT_CHOICE_LABEL_MAX} characters. Example: a confirm form `{ done: boolean }` with
|
|
202
|
+
* `[{ value: true, label: "Done" }, { value: false, label: "Cancel" }]`, or a one-value enum
|
|
203
|
+
* that renders as one button ("End wait").
|
|
204
|
+
*/
|
|
205
|
+
choices?: {
|
|
206
|
+
value: string | boolean;
|
|
207
|
+
label: LocalizedText;
|
|
208
|
+
}[];
|
|
108
209
|
}[];
|
|
109
210
|
}
|
|
211
|
+
/** The longest {@link InputForm.body}, in characters (per language). */
|
|
212
|
+
export declare const INPUT_FORM_BODY_MAX = 2000;
|
|
213
|
+
/** The most buttons a form's choices may draw. */
|
|
214
|
+
export declare const INPUT_CHOICES_MAX = 3;
|
|
215
|
+
/** The longest choice label, in characters (per language). */
|
|
216
|
+
export declare const INPUT_CHOICE_LABEL_MAX = 40;
|
|
110
217
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
218
|
+
* The tool needs user input: the kernel pauses the run and renders a form; after the user submits,
|
|
219
|
+
* the tool is called again with the same input,
|
|
220
|
+
* and state and answer are brought back in ctx.resume. state ≤ 16 KB, JSON-serializable.
|
|
113
221
|
*/
|
|
114
222
|
export interface InputRequired {
|
|
115
223
|
kind: "input_required";
|
|
116
224
|
form: InputForm;
|
|
117
225
|
state?: unknown;
|
|
226
|
+
/**
|
|
227
|
+
* Opens a `conversation.panel` of the same extension on the asking person's open conversation
|
|
228
|
+
* page when the form is asked (e.g. the browser panel for a handoff), as a view's `open` does
|
|
229
|
+
* on a click. Display only: a target that names no panel of the extension is dropped with a
|
|
230
|
+
* warning and the form is asked as usual.
|
|
231
|
+
*/
|
|
232
|
+
open?: UiOpen;
|
|
118
233
|
}
|
|
119
234
|
export type FormAnswer = Record<string, string | number | boolean | string[]>;
|
|
235
|
+
/**
|
|
236
|
+
* What a tool handler gets with each invocation.
|
|
237
|
+
*
|
|
238
|
+
* **Side effects and idempotency.** The kernel runs a call's effect at most once: it records
|
|
239
|
+
* that the call started before invoking the handler, and when a run dies after that and before
|
|
240
|
+
* the result is recorded, the result is written as unknown (an error result the model sees:
|
|
241
|
+
* `Result unknown: the call was interrupted before a result was recorded. Verify the outcome
|
|
242
|
+
* before retrying.`) and **the handler is never called again** for that call. The model, or a
|
|
243
|
+
* person, may then decide to call the tool again: that is a new call with a new `callId`.
|
|
244
|
+
*
|
|
245
|
+
* One logical call may still invoke the handler more than once: each `InputRequired` round
|
|
246
|
+
* resumes it with `resume`, and a call whose device service reported refused hosts
|
|
247
|
+
* (`ctx.deviceAccess.reportBlockedHosts`) runs again, without `resume`, once the person approved
|
|
248
|
+
* the network ask and the hosts are in force. `callId` and `idempotencyKey` stay the same across
|
|
249
|
+
* those invocations. A tool with an external side effect passes `idempotencyKey` downstream (for
|
|
250
|
+
* example as an `Idempotency-Key` header, or stored with the record it creates) so the effect
|
|
251
|
+
* applies once per logical call and an unknown outcome can be checked against the external
|
|
252
|
+
* system before retrying.
|
|
253
|
+
*/
|
|
120
254
|
export interface ToolCallContext {
|
|
121
255
|
orgId: string;
|
|
122
256
|
accountId: string;
|
|
123
257
|
agentId: string;
|
|
124
258
|
conversationId: string;
|
|
259
|
+
/**
|
|
260
|
+
* The root of the call's conversation tree (the conversation the person looks at); equal to
|
|
261
|
+
* `conversationId` outside sub-agents. Set by the kernel, never from tool input.
|
|
262
|
+
*/
|
|
263
|
+
rootConversationId: string;
|
|
264
|
+
/**
|
|
265
|
+
* The model's id for this call. Stable across every invocation of one logical call (the
|
|
266
|
+
* `InputRequired` rounds), but unique only within its run: two runs of one conversation may
|
|
267
|
+
* reuse an id, so `conversationId` + `callId` is not a key. Use `idempotencyKey`.
|
|
268
|
+
*/
|
|
125
269
|
callId: string;
|
|
270
|
+
/**
|
|
271
|
+
* The key of this logical call for idempotent side effects: 64 lowercase hex characters derived
|
|
272
|
+
* from the conversation, the run and `callId`. The same for every invocation of the call
|
|
273
|
+
* (each `InputRequired` round), different for every other call, including a later call the
|
|
274
|
+
* model makes to retry it. A re-run of the same call after its network ask was approved
|
|
275
|
+
* (`ctx.deviceAccess.reportBlockedHosts`) keeps the key too.
|
|
276
|
+
*/
|
|
277
|
+
idempotencyKey?: string;
|
|
126
278
|
signal: AbortSignal;
|
|
127
|
-
/** null =
|
|
279
|
+
/** null = the user cancelled or it timed out. */
|
|
128
280
|
resume?: {
|
|
129
281
|
state: unknown;
|
|
130
282
|
answer: FormAnswer | null;
|
|
131
283
|
};
|
|
132
284
|
/**
|
|
133
285
|
* The extension's effective deployment config for this org: the platform's deployment config
|
|
134
|
-
* with the org's copy applied to the overridable fields (
|
|
135
|
-
* platform's config (equal to `ctx.config`) while the org follows it. Use it, not
|
|
136
|
-
* for work done for this org.
|
|
137
|
-
* always passes it.
|
|
286
|
+
* with the org's copy applied to the overridable fields (every field not marked `platformOnly`),
|
|
287
|
+
* or the platform's config (equal to `ctx.config`) while the org follows it. Use it, not
|
|
288
|
+
* `ctx.config`, for work done for this org.
|
|
138
289
|
*/
|
|
139
290
|
config?: unknown;
|
|
291
|
+
/** Where the conversation comes from. The kernel always passes it. */
|
|
292
|
+
source?: ConversationSource;
|
|
293
|
+
/** The conversation's owner (`conversations.account_id`). The kernel always passes it; `accountId` stays the run's trigger account. */
|
|
294
|
+
ownerAccountId?: string;
|
|
295
|
+
/** The trigger account's role in the org. The kernel always passes it. */
|
|
296
|
+
role?: "owner" | "admin" | "member" | "guest";
|
|
140
297
|
}
|
|
141
298
|
export type ToolHandler = (input: unknown, ctx: ToolCallContext) => Promise<ToolResult | InputRequired>;
|
|
142
299
|
/**
|
|
143
|
-
*
|
|
144
|
-
* - `error
|
|
145
|
-
*
|
|
300
|
+
* Tool error categories:
|
|
301
|
+
* - `error` (default): the remote is available but this call failed (bad parameters, business
|
|
302
|
+
* error, auth failure, etc.), not counted toward the connector circuit breaker;
|
|
303
|
+
* - `unavailable`: the remote is unavailable (connection / transport error, timeout, HTTP 5xx),
|
|
304
|
+
* counted toward the connector circuit breaker (connectors use it to tell the kernel).
|
|
146
305
|
*/
|
|
147
306
|
export type ToolErrorKind = "error" | "unavailable";
|
|
148
|
-
/**
|
|
307
|
+
/** A tool execution failure: message is for the model and must be in English and actionable. */
|
|
149
308
|
export declare class ToolError extends Error {
|
|
150
309
|
readonly kind: ToolErrorKind;
|
|
151
310
|
constructor(message: string, opts?: {
|
|
152
311
|
kind?: ToolErrorKind;
|
|
153
312
|
});
|
|
154
313
|
}
|
|
155
|
-
/**
|
|
314
|
+
/** Plugin tool name rule. */
|
|
156
315
|
export declare const EXTENSION_TOOL_NAME: RegExp;
|
|
157
|
-
/**
|
|
316
|
+
/**
|
|
317
|
+
* Validates the tool declarations a plugin registers and returns the list of problems (empty =
|
|
318
|
+
* valid).
|
|
319
|
+
*/
|
|
158
320
|
export declare function validateToolSpec(spec: ToolSpec): string[];
|
|
159
|
-
/**
|
|
321
|
+
/** Validates an interactive form declaration and returns the list of problems (empty = valid). */
|
|
160
322
|
export declare function validateInputForm(form: InputForm): string[];
|
|
161
|
-
/**
|
|
323
|
+
/**
|
|
324
|
+
* Validates whether the answer a user submitted conforms to the form and returns the list of
|
|
325
|
+
* problems (empty = valid).
|
|
326
|
+
*/
|
|
162
327
|
export declare function validateAnswer(form: InputForm, answer: FormAnswer): string[];
|