@capybara-hq/plugin-sdk 0.1.0-rc.12 → 0.1.0-rc.13
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 +23 -4
- package/dist/cards.js +35 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
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
|
-
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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,
|
|
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
package/dist/index.js
CHANGED