@capybara-hq/plugin-sdk 0.1.0-rc.80 → 0.1.0-rc.82

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.
@@ -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
@@ -87,6 +124,26 @@ export interface OutboundMessage {
87
124
  export declare function questionRenderableInline(form: InputForm, opts?: {
88
125
  textReply?: boolean;
89
126
  }): boolean;
127
+ /** One button of a question's `choices`, as {@link questionChoiceButtons} resolves it. */
128
+ export interface QuestionChoiceButton {
129
+ /** The answer the button submits for the form's single field. */
130
+ value: string | boolean;
131
+ /** The label in the locale. */
132
+ label: string;
133
+ /** True for the first choice only. */
134
+ primary: boolean;
135
+ }
136
+ /**
137
+ * The buttons of a form with `choices` (core#867): one per choice in order, the first primary; a
138
+ * click answers the form's single field `key` with the button's `value` at once. Undefined when
139
+ * the form has no choices (use {@link questionRenderableInline} for the enum controls).
140
+ */
141
+ export declare function questionChoiceButtons(form: InputForm, locale: Locale): {
142
+ key: string;
143
+ buttons: QuestionChoiceButton[];
144
+ } | undefined;
145
+ /** The form's body text in the locale (the explanation under its title); undefined without one. */
146
+ export declare function questionBody(form: InputForm, locale: Locale): string | undefined;
90
147
  /** Validates the card structure and returns the list of problems (empty = valid). */
91
148
  export declare function validateChannelCard(card: unknown): string[];
92
149
  /** A UI locale. */
package/dist/cards.js CHANGED
@@ -12,6 +12,8 @@ export function questionRenderableInline(form, opts) {
12
12
  if (form.fields.length !== 1)
13
13
  return false;
14
14
  const f = form.fields[0];
15
+ if (f?.choices !== undefined && f.choices.length > 0)
16
+ return true;
15
17
  if (!f || (f.allowOther && opts?.textReply !== true))
16
18
  return false;
17
19
  if (f.schema.type !== "string" || !("enum" in f.schema))
@@ -19,7 +21,31 @@ export function questionRenderableInline(form, opts) {
19
21
  const n = f.schema.enum.length;
20
22
  return f.multiSelect ? n <= MAX_INLINE_MULTI : n <= MAX_INLINE_SINGLE;
21
23
  }
22
- const KINDS = ["approval", "question", "connect", "bind"];
24
+ const pickText = (t, locale) => typeof t === "string" ? t : (t[locale] ?? t.en);
25
+ /**
26
+ * The buttons of a form with `choices` (core#867): one per choice in order, the first primary; a
27
+ * click answers the form's single field `key` with the button's `value` at once. Undefined when
28
+ * the form has no choices (use {@link questionRenderableInline} for the enum controls).
29
+ */
30
+ export function questionChoiceButtons(form, locale) {
31
+ const f = form.fields[0];
32
+ if (form.fields.length !== 1 || !f?.choices || f.choices.length === 0)
33
+ return undefined;
34
+ return {
35
+ key: f.key,
36
+ buttons: f.choices.map((c, i) => ({
37
+ value: c.value,
38
+ label: pickText(c.label, locale),
39
+ primary: i === 0,
40
+ })),
41
+ };
42
+ }
43
+ /** The form's body text in the locale (the explanation under its title); undefined without one. */
44
+ export function questionBody(form, locale) {
45
+ return form.body === undefined ? undefined : pickText(form.body, locale);
46
+ }
47
+ const KINDS = ["approval", "question", "connect", "bind", "progress"];
48
+ const PROGRESS_STATES = ["running", "waiting", "finished", "stopped", "failed"];
23
49
  const SCOPES = ["once", "session", "always"];
24
50
  const APPROVAL_STATES = [
25
51
  "pending",
@@ -111,6 +137,28 @@ export function validateChannelCard(card) {
111
137
  url("url");
112
138
  nonEmpty("text");
113
139
  return out;
140
+ case "progress": {
141
+ nonEmpty("title");
142
+ nonEmpty("urlText");
143
+ optNonEmpty("meta");
144
+ optNonEmpty("status");
145
+ optNonEmpty("pinned");
146
+ oneOf("state", PROGRESS_STATES);
147
+ url("url");
148
+ if (!Array.isArray(c.steps) ||
149
+ c.steps.length > 3 ||
150
+ c.steps.some((x) => typeof x !== "string"))
151
+ out.push("steps must be an array of at most 3 strings");
152
+ const p = c.pending;
153
+ if (!Array.isArray(p) ||
154
+ p.some((x) => typeof x !== "object" ||
155
+ x === null ||
156
+ typeof x.text !== "string" ||
157
+ x.text === "" ||
158
+ !isHttpUrl(x.url)))
159
+ out.push("pending must be an array of { text, url } with an http(s) url");
160
+ return out;
161
+ }
114
162
  default:
115
163
  return [`kind must be one of ${list(KINDS)}`];
116
164
  }
@@ -272,6 +320,12 @@ export function renderCardAsText(card, locale) {
272
320
  withCode(t.question, asCode(title)),
273
321
  line(t.status, questionStateLabel(card.state, locale)),
274
322
  ];
323
+ const body = questionBody(card.form, locale);
324
+ if (body !== undefined)
325
+ lines.push(withCode("", asCode(body)));
326
+ const choices = card.state === "pending" ? questionChoiceButtons(card.form, locale) : undefined;
327
+ if (choices)
328
+ lines.push(line(t.options, choices.buttons.map((b) => asCode(b.label)).join(" / ")));
275
329
  if (card.answerSummary)
276
330
  lines.push(line(t.answer, asCode(card.answerSummary)));
277
331
  lines.push(line(card.state === "pending" ? t.answerOnWeb : t.details, card.webUrl));
@@ -283,5 +337,14 @@ export function renderCardAsText(card, locale) {
283
337
  return `${t.connect(card.appName)}\n${line(t.connectLink, card.url)}`;
284
338
  case "bind":
285
339
  return `${card.text}\n${card.url}`;
340
+ case "progress":
341
+ return [
342
+ card.meta ? `${card.title} · ${card.meta}` : card.title,
343
+ ...(card.status ? [card.status] : []),
344
+ ...(card.pinned ? [card.pinned] : []),
345
+ ...card.steps.map((s) => withCode("- ", asCode(s))),
346
+ ...card.pending.map((p) => `[${p.text}](${p.url})`),
347
+ `[${card.urlText}](${card.url})`,
348
+ ].join("\n");
286
349
  }
287
350
  }
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
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.80";
1
+ export declare const SDK_VERSION = "0.1.0-rc.82";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.80";
1
+ export const SDK_VERSION = "0.1.0-rc.82";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
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,10 @@ 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;
130
+ /** The most characters of `ToolResult.card.badge` (as `UiView.badge`). */
131
+ export declare const CARD_BADGE_MAX = 32;
100
132
  export interface ToolResult {
101
133
  content: ToolContent[];
102
134
  isError?: boolean;
@@ -107,10 +139,23 @@ export interface ToolResult {
107
139
  * the same extension in the `conversation.tool-result.card` slot, rendered with
108
140
  * `card: { callId, key }`. Display only (recorded on the `tool_result` event, never in the model's
109
141
  * context); an unknown view is dropped with a warning and the result is kept.
142
+ *
143
+ * `placement` says where the card shows: `output` (default) lifted out after the run's process
144
+ * block, where the person sees it with the answer; `pinned` as the run's pinned card, kept in
145
+ * view while the run goes on (a plan or todo list; the latest pinned card per (extension, view)
146
+ * of the run wins); `process` only inside the process block, after its call.
147
+ * `text` is the card's Markdown text for surfaces that cannot draw the view (IM channels, the
148
+ * pinned card of a channel's progress card), at most {@link CARD_TEXT_MAX} characters.
149
+ * `badge` (pinned only) is the card's state in a few characters, the same as its view's
150
+ * `UiView.badge` (e.g. "3/5"), at most {@link CARD_BADGE_MAX} characters: a finished run's
151
+ * process head shows it after the view's title without reading the view again.
110
152
  */
111
153
  card?: {
112
154
  view: string;
113
155
  key?: string;
156
+ placement?: "output" | "pinned" | "process";
157
+ text?: string;
158
+ badge?: string;
114
159
  };
115
160
  }
116
161
  /**
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,37 @@ 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;
98
+ /** The most characters of `ToolResult.card.badge` (as `UiView.badge`). */
99
+ export const CARD_BADGE_MAX = 32;
60
100
  const DISPLAY_MAX = 200;
61
101
  /**
62
102
  * Validates a {@link ToolDisplay} and returns the list of problems (empty = valid); length is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.80",
3
+ "version": "0.1.0-rc.82",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {