@capybara-hq/plugin-sdk 0.1.0-rc.81 → 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.
package/dist/cards.d.ts CHANGED
@@ -124,6 +124,26 @@ export interface OutboundMessage {
124
124
  export declare function questionRenderableInline(form: InputForm, opts?: {
125
125
  textReply?: boolean;
126
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;
127
147
  /** Validates the card structure and returns the list of problems (empty = valid). */
128
148
  export declare function validateChannelCard(card: unknown): string[];
129
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,6 +21,29 @@ 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
  }
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
+ }
22
47
  const KINDS = ["approval", "question", "connect", "bind", "progress"];
23
48
  const PROGRESS_STATES = ["running", "waiting", "finished", "stopped", "failed"];
24
49
  const SCOPES = ["once", "session", "always"];
@@ -295,6 +320,12 @@ export function renderCardAsText(card, locale) {
295
320
  withCode(t.question, asCode(title)),
296
321
  line(t.status, questionStateLabel(card.state, locale)),
297
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(" / ")));
298
329
  if (card.answerSummary)
299
330
  lines.push(line(t.answer, asCode(card.answerSummary)));
300
331
  lines.push(line(card.state === "pending" ? t.answerOnWeb : t.details, card.webUrl));
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.81";
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.81";
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/tool.d.ts CHANGED
@@ -127,6 +127,8 @@ export interface ToolDisplay {
127
127
  }
128
128
  /** The most characters of `ToolResult.card.text`. */
129
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;
130
132
  export interface ToolResult {
131
133
  content: ToolContent[];
132
134
  isError?: boolean;
@@ -144,12 +146,16 @@ export interface ToolResult {
144
146
  * of the run wins); `process` only inside the process block, after its call.
145
147
  * `text` is the card's Markdown text for surfaces that cannot draw the view (IM channels, the
146
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.
147
152
  */
148
153
  card?: {
149
154
  view: string;
150
155
  key?: string;
151
156
  placement?: "output" | "pinned" | "process";
152
157
  text?: string;
158
+ badge?: string;
153
159
  };
154
160
  }
155
161
  /**
package/dist/tool.js CHANGED
@@ -95,6 +95,8 @@ function validateInputView(view, props) {
95
95
  }
96
96
  /** The most characters of `ToolResult.card.text`. */
97
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;
98
100
  const DISPLAY_MAX = 200;
99
101
  /**
100
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.81",
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": {