@capybara-hq/plugin-sdk 0.1.0-rc.80 → 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/agent-docs/extension-points/channel.md +1 -1
- package/dist/cards.d.ts +37 -0
- package/dist/cards.js +33 -1
- package/dist/channel.d.ts +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/model.d.ts +17 -0
- package/dist/tool.d.ts +40 -1
- package/dist/tool.js +42 -4
- package/package.json +1 -1
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
Contract: Channel (`channel.ts`)
|
|
12
12
|
|
|
13
|
-
Normalize inbound events (messageId, threadId, tenantId, the bot mention stripped) and acknowledge only after the kernel's `onEvent` resolves. Long connections are held only by the gateway role. Replies use the card spec (`validateChannelCard`). Files: implement the optional `sendFile` and declare `features.files` (the platform's bot limits); the kernel sends each conversation artifact as one message and falls back to a link line without it.
|
|
13
|
+
Normalize inbound events (messageId, threadId, tenantId, the bot mention stripped) and acknowledge only after the kernel's `onEvent` resolves. Long connections are held only by the gateway role. Replies use the card spec (`validateChannelCard`), including the `progress` card: on a channel with `features.edit` the kernel sends one per run and edits that message in place, so render it by capability and never send narration as separate messages. Files: implement the optional `sendFile` and declare `features.files` (the platform's bot limits); the kernel sends each conversation artifact as one message and falls back to a link line without it.
|
|
14
14
|
|
|
15
15
|
See `extensions` for the rules every extension follows.
|
package/dist/cards.d.ts
CHANGED
|
@@ -58,6 +58,43 @@ export type ChannelCard = {
|
|
|
58
58
|
kind: "bind";
|
|
59
59
|
url: string;
|
|
60
60
|
text: string;
|
|
61
|
+
} | {
|
|
62
|
+
/**
|
|
63
|
+
* One edited progress card per run (kernel-produced; the channel edits the same message in
|
|
64
|
+
* place). Sent natively only to a channel that declares `features.progress`; any other
|
|
65
|
+
* channel gets {@link renderCardAsText} of it as a text message, edited in place. The title,
|
|
66
|
+
* meta, pending texts and link text are written and localized by the kernel and rendered as
|
|
67
|
+
* is; `status` (model narration) and `pinned` (extension Markdown) are rendered as Markdown,
|
|
68
|
+
* like an answer; `steps` are built from tool labels that include model-written arguments,
|
|
69
|
+
* so {@link renderCardAsText} puts each one in a code span.
|
|
70
|
+
*/
|
|
71
|
+
kind: "progress";
|
|
72
|
+
state: "running" | "waiting" | "finished" | "stopped" | "failed";
|
|
73
|
+
/** The headline, e.g. "Working", "Waiting for your approval", "Worked for 2m 43s". */
|
|
74
|
+
title: string;
|
|
75
|
+
/** A short detail after the title, e.g. "Elapsed 0:42" or "Todo 4/4 · 12 tools". */
|
|
76
|
+
meta?: string;
|
|
77
|
+
/**
|
|
78
|
+
* The latest model narration, its first line (cut short without breaking Markdown syntax):
|
|
79
|
+
* model-written Markdown, rendered like an answer.
|
|
80
|
+
*/
|
|
81
|
+
status?: string;
|
|
82
|
+
/** The pinned card's Markdown text (a plan or todo list), written by an extension. */
|
|
83
|
+
pinned?: string;
|
|
84
|
+
/** The latest steps, at most 3, oldest first. May hold model-written arguments: plain text. */
|
|
85
|
+
steps: string[];
|
|
86
|
+
/**
|
|
87
|
+
* Approvals or questions waiting on the person, each with its web link. `text` is the
|
|
88
|
+
* kernel-written, localized handoff title (not model text), so it is rendered as is.
|
|
89
|
+
*/
|
|
90
|
+
pending: {
|
|
91
|
+
text: string;
|
|
92
|
+
url: string;
|
|
93
|
+
}[];
|
|
94
|
+
/** The run on the web. */
|
|
95
|
+
url: string;
|
|
96
|
+
/** The link text for `url`, e.g. "See the full process on the web". */
|
|
97
|
+
urlText: string;
|
|
61
98
|
};
|
|
62
99
|
/**
|
|
63
100
|
* A user action on an IM card, parsed by the channel plugin and handed to the kernel through an
|
package/dist/cards.js
CHANGED
|
@@ -19,7 +19,8 @@ export function questionRenderableInline(form, opts) {
|
|
|
19
19
|
const n = f.schema.enum.length;
|
|
20
20
|
return f.multiSelect ? n <= MAX_INLINE_MULTI : n <= MAX_INLINE_SINGLE;
|
|
21
21
|
}
|
|
22
|
-
const KINDS = ["approval", "question", "connect", "bind"];
|
|
22
|
+
const KINDS = ["approval", "question", "connect", "bind", "progress"];
|
|
23
|
+
const PROGRESS_STATES = ["running", "waiting", "finished", "stopped", "failed"];
|
|
23
24
|
const SCOPES = ["once", "session", "always"];
|
|
24
25
|
const APPROVAL_STATES = [
|
|
25
26
|
"pending",
|
|
@@ -111,6 +112,28 @@ export function validateChannelCard(card) {
|
|
|
111
112
|
url("url");
|
|
112
113
|
nonEmpty("text");
|
|
113
114
|
return out;
|
|
115
|
+
case "progress": {
|
|
116
|
+
nonEmpty("title");
|
|
117
|
+
nonEmpty("urlText");
|
|
118
|
+
optNonEmpty("meta");
|
|
119
|
+
optNonEmpty("status");
|
|
120
|
+
optNonEmpty("pinned");
|
|
121
|
+
oneOf("state", PROGRESS_STATES);
|
|
122
|
+
url("url");
|
|
123
|
+
if (!Array.isArray(c.steps) ||
|
|
124
|
+
c.steps.length > 3 ||
|
|
125
|
+
c.steps.some((x) => typeof x !== "string"))
|
|
126
|
+
out.push("steps must be an array of at most 3 strings");
|
|
127
|
+
const p = c.pending;
|
|
128
|
+
if (!Array.isArray(p) ||
|
|
129
|
+
p.some((x) => typeof x !== "object" ||
|
|
130
|
+
x === null ||
|
|
131
|
+
typeof x.text !== "string" ||
|
|
132
|
+
x.text === "" ||
|
|
133
|
+
!isHttpUrl(x.url)))
|
|
134
|
+
out.push("pending must be an array of { text, url } with an http(s) url");
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
114
137
|
default:
|
|
115
138
|
return [`kind must be one of ${list(KINDS)}`];
|
|
116
139
|
}
|
|
@@ -283,5 +306,14 @@ export function renderCardAsText(card, locale) {
|
|
|
283
306
|
return `${t.connect(card.appName)}\n${line(t.connectLink, card.url)}`;
|
|
284
307
|
case "bind":
|
|
285
308
|
return `${card.text}\n${card.url}`;
|
|
309
|
+
case "progress":
|
|
310
|
+
return [
|
|
311
|
+
card.meta ? `${card.title} · ${card.meta}` : card.title,
|
|
312
|
+
...(card.status ? [card.status] : []),
|
|
313
|
+
...(card.pinned ? [card.pinned] : []),
|
|
314
|
+
...card.steps.map((s) => withCode("- ", asCode(s))),
|
|
315
|
+
...card.pending.map((p) => `[${p.text}](${p.url})`),
|
|
316
|
+
`[${card.urlText}](${card.url})`,
|
|
317
|
+
].join("\n");
|
|
286
318
|
}
|
|
287
319
|
}
|
package/dist/channel.d.ts
CHANGED
|
@@ -232,11 +232,16 @@ export interface Channel {
|
|
|
232
232
|
*
|
|
233
233
|
* `files`: present iff `sendFile` is implemented; the kernel never hands a file larger than
|
|
234
234
|
* `maxBytes`, and sends `kind: "image"` only within `imageMaxBytes ?? maxBytes`.
|
|
235
|
+
*
|
|
236
|
+
* `progress`: the plugin renders the `progress` `ChannelCard` natively (send and update).
|
|
237
|
+
* Absent or false: the kernel sends a run's progress card as Markdown text built by
|
|
238
|
+
* `renderCardAsText` instead, and edits that text message in place.
|
|
235
239
|
*/
|
|
236
240
|
features: {
|
|
237
241
|
cards: boolean;
|
|
238
242
|
edit: boolean;
|
|
239
243
|
threads: boolean;
|
|
244
|
+
progress?: boolean;
|
|
240
245
|
minEditIntervalMs?: number;
|
|
241
246
|
files?: {
|
|
242
247
|
maxBytes: number;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/model.d.ts
CHANGED
|
@@ -285,12 +285,29 @@ export interface ModelUsage {
|
|
|
285
285
|
/** Images produced (image generation calls). */
|
|
286
286
|
outputImages?: number;
|
|
287
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* One event of a model stream. Tool call events are display only: a provider MAY emit
|
|
290
|
+
* `tool_call_start` when a tool call begins and `tool_call_delta` with raw input JSON fragments
|
|
291
|
+
* (`input` is the next piece of the call's argument JSON text) for the same `id`. A `tool_call_start`
|
|
292
|
+
* precedes the deltas of its `id`; calls may interleave with each other and with text and thinking.
|
|
293
|
+
* The parsed concatenation of an id's deltas must equal the input of that call in
|
|
294
|
+
* `message_complete`; the final `message_complete` is the only source of truth, and nothing
|
|
295
|
+
* streamed ever executes. Emitting no tool call events stays valid.
|
|
296
|
+
*/
|
|
288
297
|
export type ModelStreamEvent = {
|
|
289
298
|
type: "text_delta";
|
|
290
299
|
text: string;
|
|
291
300
|
} | {
|
|
292
301
|
type: "thinking_delta";
|
|
293
302
|
text: string;
|
|
303
|
+
} | {
|
|
304
|
+
type: "tool_call_start";
|
|
305
|
+
id: string;
|
|
306
|
+
name: string;
|
|
307
|
+
} | {
|
|
308
|
+
type: "tool_call_delta";
|
|
309
|
+
id: string;
|
|
310
|
+
input: string;
|
|
294
311
|
} | {
|
|
295
312
|
type: "message_complete";
|
|
296
313
|
content: ContentBlock[];
|
package/dist/tool.d.ts
CHANGED
|
@@ -12,6 +12,27 @@ export interface ToolAnnotations {
|
|
|
12
12
|
export declare const CONVERSATION_SOURCES: readonly ["web", "channel_dm", "channel_group", "subagent"];
|
|
13
13
|
/** A conversation source (see {@link CONVERSATION_SOURCES}). */
|
|
14
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
|
+
};
|
|
15
36
|
export interface ToolSpec {
|
|
16
37
|
name: string;
|
|
17
38
|
description: string;
|
|
@@ -43,6 +64,13 @@ export interface ToolSpec {
|
|
|
43
64
|
* model and not part of the definition fingerprint.
|
|
44
65
|
*/
|
|
45
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;
|
|
46
74
|
/**
|
|
47
75
|
* The conversation sources this tool is offered in; absent = every source. A non-empty list of
|
|
48
76
|
* {@link CONVERSATION_SOURCES}.
|
|
@@ -73,7 +101,7 @@ export declare const TOOL_KEY_ARGS_MAX = 3;
|
|
|
73
101
|
* characters (Unicode Cc / Cf); keyArgs are at most 3 unique strings, each a property of
|
|
74
102
|
* `inputSchema.properties` and free of Cc / Cf characters.
|
|
75
103
|
*/
|
|
76
|
-
export declare function validateToolPresentation(spec: Pick<ToolSpec, "title" | "keyArgs" | "inputSchema">): string[];
|
|
104
|
+
export declare function validateToolPresentation(spec: Pick<ToolSpec, "title" | "keyArgs" | "inputView" | "inputSchema">): string[];
|
|
77
105
|
export type ToolContent = {
|
|
78
106
|
type: "text";
|
|
79
107
|
text: string;
|
|
@@ -97,6 +125,8 @@ export interface ToolDisplay {
|
|
|
97
125
|
en: string;
|
|
98
126
|
};
|
|
99
127
|
}
|
|
128
|
+
/** The most characters of `ToolResult.card.text`. */
|
|
129
|
+
export declare const CARD_TEXT_MAX = 2000;
|
|
100
130
|
export interface ToolResult {
|
|
101
131
|
content: ToolContent[];
|
|
102
132
|
isError?: boolean;
|
|
@@ -107,10 +137,19 @@ export interface ToolResult {
|
|
|
107
137
|
* the same extension in the `conversation.tool-result.card` slot, rendered with
|
|
108
138
|
* `card: { callId, key }`. Display only (recorded on the `tool_result` event, never in the model's
|
|
109
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.
|
|
110
147
|
*/
|
|
111
148
|
card?: {
|
|
112
149
|
view: string;
|
|
113
150
|
key?: string;
|
|
151
|
+
placement?: "output" | "pinned" | "process";
|
|
152
|
+
text?: string;
|
|
114
153
|
};
|
|
115
154
|
}
|
|
116
155
|
/**
|
package/dist/tool.js
CHANGED
|
@@ -2,6 +2,20 @@ import { checkParamValue } from "./model-params.js";
|
|
|
2
2
|
import { isHttpUrl } from "./url.js";
|
|
3
3
|
/** Where a conversation comes from; a tool may limit itself to some of these. */
|
|
4
4
|
export const CONVERSATION_SOURCES = ["web", "channel_dm", "channel_group", "subagent"];
|
|
5
|
+
const INPUT_VIEW_KINDS = ["file_write", "file_edit", "command", "text"];
|
|
6
|
+
/** The property names a {@link ToolInputView} refers to, by kind. */
|
|
7
|
+
function inputViewFields(view) {
|
|
8
|
+
switch (view.kind) {
|
|
9
|
+
case "file_write":
|
|
10
|
+
return [view.path, view.content];
|
|
11
|
+
case "file_edit":
|
|
12
|
+
return [view.path, view.old, view.new];
|
|
13
|
+
case "command":
|
|
14
|
+
return view.description === undefined ? [view.command] : [view.command, view.description];
|
|
15
|
+
default:
|
|
16
|
+
return [view.field];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
5
19
|
/** Shortest {@link ToolSpec.timeoutMs}: one second. */
|
|
6
20
|
export const TOOL_TIMEOUT_MIN_MS = 1000;
|
|
7
21
|
/** Longest {@link ToolSpec.timeoutMs} the kernel accepts: ten minutes. */
|
|
@@ -34,6 +48,11 @@ export function validateToolPresentation(spec) {
|
|
|
34
48
|
else if (typeof title === "string" && CONTROL_OR_FORMAT.test(title)) {
|
|
35
49
|
out.push("title must not contain control, bidi or invisible characters");
|
|
36
50
|
}
|
|
51
|
+
const schema = spec.inputSchema;
|
|
52
|
+
const props = typeof schema?.properties === "object" && schema.properties !== null
|
|
53
|
+
? schema.properties
|
|
54
|
+
: {};
|
|
55
|
+
out.push(...validateInputView(spec.inputView, props));
|
|
37
56
|
const keyArgs = spec.keyArgs;
|
|
38
57
|
if (keyArgs === undefined)
|
|
39
58
|
return out;
|
|
@@ -47,16 +66,35 @@ export function validateToolPresentation(spec) {
|
|
|
47
66
|
out.push("keyArgs must not repeat a name");
|
|
48
67
|
if (keyArgs.some((k) => CONTROL_OR_FORMAT.test(k)))
|
|
49
68
|
out.push("keyArgs names must not contain control, bidi or invisible characters");
|
|
50
|
-
const schema = spec.inputSchema;
|
|
51
|
-
const props = typeof schema?.properties === "object" && schema.properties !== null
|
|
52
|
-
? schema.properties
|
|
53
|
-
: {};
|
|
54
69
|
for (const k of keyArgs) {
|
|
55
70
|
if (!Object.hasOwn(props, k))
|
|
56
71
|
out.push(`keyArgs names "${k}", which is not a property of inputSchema`);
|
|
57
72
|
}
|
|
58
73
|
return out;
|
|
59
74
|
}
|
|
75
|
+
function validateInputView(view, props) {
|
|
76
|
+
if (view === undefined)
|
|
77
|
+
return [];
|
|
78
|
+
const kinds = INPUT_VIEW_KINDS.join(", ");
|
|
79
|
+
const kindProblem = `inputView kind must be one of ${kinds}`;
|
|
80
|
+
if (typeof view !== "object" || view === null || Array.isArray(view))
|
|
81
|
+
return [kindProblem];
|
|
82
|
+
const v = view;
|
|
83
|
+
if (!INPUT_VIEW_KINDS.includes(v.kind))
|
|
84
|
+
return [kindProblem];
|
|
85
|
+
const out = [];
|
|
86
|
+
for (const name of inputViewFields(v)) {
|
|
87
|
+
const label = typeof name === "string" ? name : String(name);
|
|
88
|
+
const prop = typeof name === "string" && Object.hasOwn(props, name)
|
|
89
|
+
? props[name]
|
|
90
|
+
: undefined;
|
|
91
|
+
if (typeof name !== "string" || CONTROL_OR_FORMAT.test(name) || prop?.type !== "string")
|
|
92
|
+
out.push(`inputView names "${label}", which is not a string property of inputSchema`);
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
/** The most characters of `ToolResult.card.text`. */
|
|
97
|
+
export const CARD_TEXT_MAX = 2000;
|
|
60
98
|
const DISPLAY_MAX = 200;
|
|
61
99
|
/**
|
|
62
100
|
* Validates a {@link ToolDisplay} and returns the list of problems (empty = valid); length is
|