@capybara-hq/plugin-sdk 0.1.0-rc.12 → 0.1.0-rc.14

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
@@ -30,9 +30,17 @@ export type ChannelCard = {
30
30
  kind: "question";
31
31
  id: string;
32
32
  form: InputForm;
33
- state: "pending" | "answered" | "expired" | "cancelled";
33
+ /** `skipped`: the person sent a message instead of answering (the run went on with it). */
34
+ state: "pending" | "answered" | "skipped" | "expired" | "cancelled";
34
35
  answerSummary?: string;
35
36
  webUrl: string;
37
+ /**
38
+ * The person may answer by replying with text instead (pending cards only): `plain` in a DM
39
+ * (any reply reaches the agent), `mention` in a group thread (the reply must mention the bot;
40
+ * the kernel ignores group messages without it). Absent: only the card's own controls work
41
+ * (a sub-agent's question). Render the hint with {@link questionTextReplyHint}.
42
+ */
43
+ textReply?: "plain" | "mention";
36
44
  } | {
37
45
  kind: "connect";
38
46
  appName: string;
@@ -56,14 +64,25 @@ export interface OutboundMessage {
56
64
  cards?: ChannelCard[];
57
65
  }
58
66
  /**
59
- * 提问能否在 IM 内直接作答:仅当表单恰有一个枚举字段(单选 ≤ 5 项 / 多选 ≤ 10 项)且不允许「其他」时为真;
60
- * 否则卡片只给网页链接。
67
+ * Whether IM can draw the question's controls: exactly one enum field (single choice ≤ 5 options /
68
+ * multi-select ≤ 10). A field with `allowOther` qualifies only when the card has `textReply`
69
+ * (pass `{ textReply: card.textReply !== undefined }`): the Other path is then a plain reply, so
70
+ * never draw an Other button. Otherwise the card only links to the web.
61
71
  */
62
- export declare function questionRenderableInline(form: InputForm): boolean;
72
+ export declare function questionRenderableInline(form: InputForm, opts?: {
73
+ textReply?: boolean;
74
+ }): boolean;
63
75
  /** 校验卡片结构,返回问题列表(空 = 合法)。 */
64
76
  export declare function validateChannelCard(card: unknown): string[];
65
77
  /** A UI locale. */
66
78
  export type Locale = "zh" | "en";
79
+ /** The hint line of a pending question card with `textReply`, as {@link renderCardAsText} writes it. */
80
+ export declare function questionTextReplyHint(mode: "plain" | "mention", locale: Locale): string;
81
+ /**
82
+ * The label of a question card's state, as {@link renderCardAsText} writes it. A state this SDK
83
+ * does not know (a newer kernel) returns the state itself, never `undefined`.
84
+ */
85
+ export declare function questionStateLabel(state: string, locale: Locale): string;
67
86
  /**
68
87
  * 不支持卡片的渠道的统一退回文本(含链接);固定话术按 locale 取 zh / en。结果是 Markdown(放进
69
88
  * `OutboundMessage.text`,由渠道插件转换):模型可控的字段放在代码里(见 `asCode`),不会产生链接。
package/dist/cards.js CHANGED
@@ -3,14 +3,16 @@ import { isHttpUrl } from "./url.js";
3
3
  const MAX_INLINE_SINGLE = 5;
4
4
  const MAX_INLINE_MULTI = 10;
5
5
  /**
6
- * 提问能否在 IM 内直接作答:仅当表单恰有一个枚举字段(单选 ≤ 5 项 / 多选 ≤ 10 项)且不允许「其他」时为真;
7
- * 否则卡片只给网页链接。
6
+ * Whether IM can draw the question's controls: exactly one enum field (single choice ≤ 5 options /
7
+ * multi-select ≤ 10). A field with `allowOther` qualifies only when the card has `textReply`
8
+ * (pass `{ textReply: card.textReply !== undefined }`): the Other path is then a plain reply, so
9
+ * never draw an Other button. Otherwise the card only links to the web.
8
10
  */
9
- export function questionRenderableInline(form) {
11
+ export function questionRenderableInline(form, opts) {
10
12
  if (form.fields.length !== 1)
11
13
  return false;
12
14
  const f = form.fields[0];
13
- if (!f || f.allowOther)
15
+ if (!f || (f.allowOther && opts?.textReply !== true))
14
16
  return false;
15
17
  if (f.schema.type !== "string" || !("enum" in f.schema))
16
18
  return false;
@@ -20,7 +22,8 @@ export function questionRenderableInline(form) {
20
22
  const KINDS = ["approval", "question", "connect", "bind"];
21
23
  const SCOPES = ["once", "session", "always"];
22
24
  const APPROVAL_STATES = ["pending", "approved", "denied", "expired", "cancelled"];
23
- const QUESTION_STATES = ["pending", "answered", "expired", "cancelled"];
25
+ const QUESTION_STATES = ["pending", "answered", "skipped", "expired", "cancelled"];
26
+ const TEXT_REPLY = ["plain", "mention"];
24
27
  const ISO_8601 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
25
28
  const list = (xs) => xs.map((x) => JSON.stringify(x)).join(", ");
26
29
  /** 校验卡片结构,返回问题列表(空 = 合法)。 */
@@ -74,6 +77,8 @@ export function validateChannelCard(card) {
74
77
  url("webUrl");
75
78
  if (c.answerSummary !== undefined && typeof c.answerSummary !== "string")
76
79
  out.push("answerSummary must be a string");
80
+ if (c.textReply !== undefined)
81
+ oneOf("textReply", TEXT_REPLY);
77
82
  // 不能在 IM 内作答的表单(见 questionRenderableInline)同样合法:渠道只渲染网页链接。
78
83
  for (const p of validateInputForm(c.form))
79
84
  out.push(`form: ${p}`);
@@ -138,9 +143,14 @@ const TEXT = {
138
143
  questionStates: {
139
144
  pending: "Pending",
140
145
  answered: "Answered",
146
+ skipped: "Skipped (replied instead)",
141
147
  expired: "Expired",
142
148
  cancelled: "Cancelled",
143
149
  },
150
+ textReply: {
151
+ plain: "You can also just reply with text",
152
+ mention: "You can also reply in this thread, mentioning me",
153
+ },
144
154
  },
145
155
  zh: {
146
156
  sep: ":",
@@ -168,11 +178,28 @@ const TEXT = {
168
178
  questionStates: {
169
179
  pending: "待回答",
170
180
  answered: "已回答",
181
+ skipped: "已跳过(已直接回复)",
171
182
  expired: "已过期",
172
183
  cancelled: "已取消",
173
184
  },
185
+ textReply: {
186
+ plain: "也可以直接回复文字",
187
+ mention: "也可以在本话题 @我 回复文字",
188
+ },
174
189
  },
175
190
  };
191
+ /** The hint line of a pending question card with `textReply`, as {@link renderCardAsText} writes it. */
192
+ export function questionTextReplyHint(mode, locale) {
193
+ return (TEXT[locale] ?? TEXT.en).textReply[mode];
194
+ }
195
+ /**
196
+ * The label of a question card's state, as {@link renderCardAsText} writes it. A state this SDK
197
+ * does not know (a newer kernel) returns the state itself, never `undefined`.
198
+ */
199
+ export function questionStateLabel(state, locale) {
200
+ const states = (TEXT[locale] ?? TEXT.en).questionStates;
201
+ return states[state] ?? state;
202
+ }
176
203
  /**
177
204
  * 不支持卡片的渠道的统一退回文本(含链接);固定话术按 locale 取 zh / en。结果是 Markdown(放进
178
205
  * `OutboundMessage.text`,由渠道插件转换):模型可控的字段放在代码里(见 `asCode`),不会产生链接。
@@ -202,11 +229,13 @@ export function renderCardAsText(card, locale) {
202
229
  const title = typeof card.form.title === "string" ? card.form.title : card.form.title[locale];
203
230
  const lines = [
204
231
  withCode(t.question, asCode(title)),
205
- line(t.status, t.questionStates[card.state]),
232
+ line(t.status, questionStateLabel(card.state, locale)),
206
233
  ];
207
234
  if (card.answerSummary)
208
235
  lines.push(line(t.answer, asCode(card.answerSummary)));
209
236
  lines.push(line(card.state === "pending" ? t.answerOnWeb : t.details, card.webUrl));
237
+ if (card.state === "pending" && card.textReply !== undefined)
238
+ lines.push(questionTextReplyHint(card.textReply, locale));
210
239
  return lines.join("\n");
211
240
  }
212
241
  case "connect":
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.12";
1
+ export declare const SDK_VERSION = "0.1.0-rc.14";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.12";
1
+ export const SDK_VERSION = "0.1.0-rc.14";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
@@ -1,7 +1,7 @@
1
1
  /** The ARIA / data states a part promises (client extensions spec §7.1). */
2
- export type UiPartState = "aria-current" | "aria-selected" | "aria-expanded" | "aria-busy" | "disabled";
2
+ export type UiPartState = "aria-current" | "aria-selected" | "aria-expanded" | "aria-busy" | "aria-checked" | "aria-pressed" | "disabled";
3
3
  /** Every part name of the catalog, in catalog order. */
4
- export declare const UI_PART_NAMES: readonly ["shell", "sidebar", "sidebar.brand", "sidebar.item", "title-bar", "page-header", "thread", "message.user", "message.assistant", "tool-row", "composer", "properties-panel", "section", "right-panel", "status-bar", "button", "button.primary", "card", "input", "dialog"];
4
+ export declare const UI_PART_NAMES: readonly ["shell", "sidebar", "sidebar.brand", "sidebar.item", "title-bar", "page-header", "thread", "message.user", "message.user.bubble", "message.assistant", "tool-row", "composer", "properties-panel", "section", "right-panel", "status-bar", "button", "button.primary", "card", "input", "dialog", "code-block", "menu", "segmented", "stat-card", "switch", "switch.knob", "org-avatar", "agent-chip"];
5
5
  export type UiPartName = (typeof UI_PART_NAMES)[number];
6
6
  /** One built-in element plugin CSS may select with `[data-cap-part~="<name>"]`. */
7
7
  export interface UiPartSpec {
package/dist/ui-parts.js CHANGED
@@ -8,6 +8,7 @@ export const UI_PART_NAMES = [
8
8
  "page-header",
9
9
  "thread",
10
10
  "message.user",
11
+ "message.user.bubble",
11
12
  "message.assistant",
12
13
  "tool-row",
13
14
  "composer",
@@ -20,6 +21,14 @@ export const UI_PART_NAMES = [
20
21
  "card",
21
22
  "input",
22
23
  "dialog",
24
+ "code-block",
25
+ "menu",
26
+ "segmented",
27
+ "stat-card",
28
+ "switch",
29
+ "switch.knob",
30
+ "org-avatar",
31
+ "agent-chip",
23
32
  ];
24
33
  export const UI_PARTS = [
25
34
  {
@@ -105,14 +114,24 @@ export const UI_PARTS = [
105
114
  zh: "用户发出的消息。",
106
115
  },
107
116
  },
117
+ {
118
+ name: "message.user.bubble",
119
+ version: 1,
120
+ owner: ["packages/design/src/conversation/bubble.tsx"],
121
+ states: [],
122
+ description: {
123
+ en: "The bubble of a person's message (inside the full-width `message.user` row).",
124
+ zh: "用户消息的气泡本身(在占满宽度的 message.user 行之内)。",
125
+ },
126
+ },
108
127
  {
109
128
  name: "message.assistant",
110
129
  version: 1,
111
130
  owner: ["apps/web/src/components/conversation/Thread.tsx"],
112
- states: [],
131
+ states: ["aria-busy"],
113
132
  description: {
114
- en: "An assistant turn.",
115
- zh: "智能体的一轮回复。",
133
+ en: "An assistant turn; `aria-busy` while its text is still streaming (the live reply).",
134
+ zh: "智能体的一轮回复;正在流式输出时带 aria-busy(正在生成的回复)。",
116
135
  },
117
136
  },
118
137
  {
@@ -232,6 +251,86 @@ export const UI_PARTS = [
232
251
  zh: "对话框或抽屉。",
233
252
  },
234
253
  },
254
+ {
255
+ name: "code-block",
256
+ version: 1,
257
+ owner: ["packages/design/src/display/chat.tsx"],
258
+ states: [],
259
+ description: {
260
+ en: "A code block (Markdown code, setup guides, diffs).",
261
+ zh: "代码块(Markdown 代码、设置指引、差异)。",
262
+ },
263
+ },
264
+ {
265
+ name: "menu",
266
+ version: 1,
267
+ owner: ["packages/design/src/overlays/menus.tsx", "packages/design/src/conversation/menu.tsx"],
268
+ states: [],
269
+ description: {
270
+ en: "A menu, submenu, popover or the composer's menus.",
271
+ zh: "菜单、子菜单、弹出层或输入框的菜单。",
272
+ },
273
+ },
274
+ {
275
+ name: "segmented",
276
+ version: 1,
277
+ owner: ["packages/design/src/display/tabs.tsx"],
278
+ states: [],
279
+ description: {
280
+ en: "A segmented control (its segments are radios with `aria-checked`).",
281
+ zh: "分段控件(各段是带 aria-checked 的单选项)。",
282
+ },
283
+ },
284
+ {
285
+ name: "stat-card",
286
+ version: 1,
287
+ owner: ["packages/design/src/display/stat-cards.tsx"],
288
+ states: [],
289
+ description: {
290
+ en: "A metric card of a StatCards row.",
291
+ zh: "指标卡片行里的一张指标卡。",
292
+ },
293
+ },
294
+ {
295
+ name: "switch",
296
+ version: 1,
297
+ owner: ["packages/design/src/controls/toggles.tsx"],
298
+ states: ["aria-checked", "disabled"],
299
+ description: {
300
+ en: "A switch; `aria-checked` says on or off.",
301
+ zh: "开关;aria-checked 表示开或关。",
302
+ },
303
+ },
304
+ {
305
+ name: "switch.knob",
306
+ version: 1,
307
+ owner: ["packages/design/src/controls/toggles.tsx"],
308
+ states: [],
309
+ description: {
310
+ en: "The knob inside a `switch` (style it from the switch's state).",
311
+ zh: "开关里的滑块(按所在开关的状态设置样式)。",
312
+ },
313
+ },
314
+ {
315
+ name: "org-avatar",
316
+ version: 1,
317
+ owner: ["packages/design/src/shell/sidebar.tsx"],
318
+ states: [],
319
+ description: {
320
+ en: "The org's initial block in the sidebar's org switcher.",
321
+ zh: "侧边栏组织切换器里的组织首字方块。",
322
+ },
323
+ },
324
+ {
325
+ name: "agent-chip",
326
+ version: 1,
327
+ owner: ["packages/design/src/conversation/agent-row.tsx"],
328
+ states: ["aria-pressed"],
329
+ description: {
330
+ en: "An agent chip of the new conversation's agents row; `aria-pressed` on the selected one.",
331
+ zh: "新会话智能体行里的智能体标签;选中的那个带 aria-pressed。",
332
+ },
333
+ },
235
334
  ];
236
335
  export function uiPart(name) {
237
336
  return UI_PARTS.find((p) => p.name === name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.12",
3
+ "version": "0.1.0-rc.14",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {