@xyz-agent/extension-protocol 0.3.1 → 0.4.0
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/index.d.mts +5 -13
- package/dist/index.mjs +1 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -195,14 +195,10 @@ interface AskUserQuestion {
|
|
|
195
195
|
* - 有 options 时:默认 true,前端在选项末尾追加 Other 输入框;设 false 则不追加
|
|
196
196
|
* - 无 options 时:整个问题就是自由输入,此字段被忽略 */
|
|
197
197
|
allowOther?: boolean;
|
|
198
|
-
/** 是否允许附加评论。选中后可追加短文本(4.0.1 restore:0.3.0 误删导致 pi-ask-user@4.0.0 ESM import 崩溃,见 .changeset/restore-ask-user-comment.md) */
|
|
199
|
-
allowComment?: boolean;
|
|
200
198
|
}
|
|
201
199
|
interface AskUserOption {
|
|
202
|
-
/**
|
|
200
|
+
/** 显示标签,回传时作为选中值(D1:proto 无独立 value,选中值统一用 label) */
|
|
203
201
|
label: string;
|
|
204
|
-
/** 回传值。未提供时用 label */
|
|
205
|
-
value?: string;
|
|
206
202
|
/** 描述(可选)。显示在 label 下方,解释 tradeoff */
|
|
207
203
|
description?: string;
|
|
208
204
|
}
|
|
@@ -210,16 +206,14 @@ interface AskUserOption {
|
|
|
210
206
|
* ask-user 富交互回传结果。key = question.header(header 缺失时用 question 文本)。
|
|
211
207
|
*
|
|
212
208
|
* 答案编码规则(避免逗号歧义):
|
|
213
|
-
* - 单选:value = 选中项的
|
|
214
|
-
* - 多选:value = JSON.stringify(选中项
|
|
215
|
-
* (不用逗号 join——option
|
|
209
|
+
* - 单选:value = 选中项的 label
|
|
210
|
+
* - 多选:value = JSON.stringify(选中项 label 数组),如 '["pg","mysql"]'
|
|
211
|
+
* (不用逗号 join——option label 可能含逗号导致 split 歧义)
|
|
216
212
|
* - Other 文本:单独 key `${header}__other`,value = 自由文本(不混进选中项数组)
|
|
217
|
-
* - comment:单独 key `${header}__comment`,value = 评论文本
|
|
218
213
|
*
|
|
219
214
|
* extension 解析示例:
|
|
220
215
|
* const selected = JSON.parse(answers[header]) // 多选 → string[]
|
|
221
216
|
* const other = answers[`${header}__other`] // Other 自由文本
|
|
222
|
-
* const comment = answers[`${header}__comment`] // 评论
|
|
223
217
|
*/
|
|
224
218
|
type AskUserAnswers = Record<string, string>;
|
|
225
219
|
|
|
@@ -266,12 +260,10 @@ declare function askUserInteract(ctx: GuiContext, questions: AskUserQuestion[],
|
|
|
266
260
|
declare function getAskUserAnswer(answers: AskUserAnswers, question: AskUserQuestion): string | string[] | undefined;
|
|
267
261
|
/** 从 answers 中提取 Other 自由文本 */
|
|
268
262
|
declare function getAskUserOther(answers: AskUserAnswers, question: AskUserQuestion): string | undefined;
|
|
269
|
-
/** 从 answers 中提取评论(4.0.1 restore:ask-user TUI 评论模式与 renderer AskUserOverlay 仍消费此 helper) */
|
|
270
|
-
declare function getAskUserComment(answers: AskUserAnswers, question: AskUserQuestion): string | undefined;
|
|
271
263
|
/**
|
|
272
264
|
* 类型守卫:验证 unknown 是否为合法的 AskUserQuestion。
|
|
273
265
|
* 用于前端从 runtime 透传的 askUserQuestions(unknown[])中安全收窄。
|
|
274
266
|
*/
|
|
275
267
|
declare function isAskUserQuestion(value: unknown): value is AskUserQuestion;
|
|
276
268
|
|
|
277
|
-
export { ASK_USER_MARKER, type AskUserAnswers, type AskUserOption, type AskUserQuestion, GUI_WIDGET_MARKER, type GuiComponent, type GuiComponentProps, type GuiComponentType, type GuiContext, type GuiRenderResult, PROTOCOL_VERSION, type StatItem, type TreeItem, type TreeItemIcon, askUserInteract, extractGui, getAskUserAnswer,
|
|
269
|
+
export { ASK_USER_MARKER, type AskUserAnswers, type AskUserOption, type AskUserQuestion, GUI_WIDGET_MARKER, type GuiComponent, type GuiComponentProps, type GuiComponentType, type GuiContext, type GuiRenderResult, PROTOCOL_VERSION, type StatItem, type TreeItem, type TreeItemIcon, askUserInteract, extractGui, getAskUserAnswer, getAskUserOther, guiComponent, guiResult, guiSetWidget, isAskUserQuestion, isGuiCapable, isGuiComponent };
|
package/dist/index.mjs
CHANGED
|
@@ -100,13 +100,10 @@ function getAskUserAnswer(answers, question) {
|
|
|
100
100
|
function getAskUserOther(answers, question) {
|
|
101
101
|
return answers[`${askUserKey(question)}__other`];
|
|
102
102
|
}
|
|
103
|
-
function getAskUserComment(answers, question) {
|
|
104
|
-
return answers[`${askUserKey(question)}__comment`];
|
|
105
|
-
}
|
|
106
103
|
function isAskUserQuestion(value) {
|
|
107
104
|
if (typeof value !== "object" || value === null) return false;
|
|
108
105
|
const q = value;
|
|
109
|
-
return typeof q.question === "string" && (q.header === void 0 || typeof q.header === "string") && (q.options === void 0 || Array.isArray(q.options)) && (q.multiSelect === void 0 || typeof q.multiSelect === "boolean") && (q.allowOther === void 0 || typeof q.allowOther === "boolean")
|
|
106
|
+
return typeof q.question === "string" && (q.header === void 0 || typeof q.header === "string") && (q.options === void 0 || Array.isArray(q.options)) && (q.multiSelect === void 0 || typeof q.multiSelect === "boolean") && (q.allowOther === void 0 || typeof q.allowOther === "boolean");
|
|
110
107
|
}
|
|
111
108
|
export {
|
|
112
109
|
ASK_USER_MARKER,
|
|
@@ -115,7 +112,6 @@ export {
|
|
|
115
112
|
askUserInteract,
|
|
116
113
|
extractGui,
|
|
117
114
|
getAskUserAnswer,
|
|
118
|
-
getAskUserComment,
|
|
119
115
|
getAskUserOther,
|
|
120
116
|
guiComponent,
|
|
121
117
|
guiResult,
|
package/package.json
CHANGED