@downcity/agent 1.1.323 → 1.1.326
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/bin/tools/ask/AskQuestionsTool.d.ts +4 -6
- package/bin/tools/ask/AskQuestionsTool.d.ts.map +1 -1
- package/bin/tools/ask/AskQuestionsTool.js +7 -2
- package/bin/tools/ask/AskQuestionsTool.js.map +1 -1
- package/bin/tools/ask/AskQuestionsToolSchemas.d.ts +5 -7
- package/bin/tools/ask/AskQuestionsToolSchemas.d.ts.map +1 -1
- package/bin/tools/ask/AskQuestionsToolSchemas.js +9 -12
- package/bin/tools/ask/AskQuestionsToolSchemas.js.map +1 -1
- package/bin/tools/index.d.ts +1 -1
- package/bin/tools/index.d.ts.map +1 -1
- package/bin/types/tools/ask/AskQuestionsTool.d.ts +11 -2
- package/bin/types/tools/ask/AskQuestionsTool.d.ts.map +1 -1
- package/package.json +1 -1
- package/scripts/session-ask-question.test.mjs +14 -6
- package/src/tools/ask/AskQuestionsTool.ts +7 -2
- package/src/tools/ask/AskQuestionsToolSchemas.ts +13 -12
- package/src/tools/index.ts +1 -0
- package/src/types/tools/ask/AskQuestionsTool.ts +12 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -22,13 +22,11 @@ import type { ActionResult } from "../../types/action/ActionResult.js";
|
|
|
22
22
|
export declare const AskQuestionsTool: import("ai").Tool<{
|
|
23
23
|
title: string;
|
|
24
24
|
questions: ({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
response_type: "text";
|
|
25
|
+
question: string;
|
|
26
|
+
type: "text";
|
|
28
27
|
} | {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
response_type: "single_select" | "multi_select";
|
|
28
|
+
question: string;
|
|
29
|
+
type: "single_select" | "multi_select";
|
|
32
30
|
options: {
|
|
33
31
|
value: string;
|
|
34
32
|
label: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AskQuestionsTool.d.ts","sourceRoot":"","sources":["../../../src/tools/ask/AskQuestionsTool.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAEV,sBAAsB,EACvB,MAAM,uCAAuC,CAAC;AAG/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAEnE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"AskQuestionsTool.d.ts","sourceRoot":"","sources":["../../../src/tools/ask/AskQuestionsTool.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAEV,sBAAsB,EACvB,MAAM,uCAAuC,CAAC;AAG/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAEnE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;wCA2D3B,CAAC"}
|
|
@@ -21,7 +21,7 @@ import { generate_id } from "../../utils/Id.js";
|
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
export const AskQuestionsTool = tool({
|
|
24
|
-
description: "Ask the user one or more questions when missing information would materially change the outcome. The call waits for every answer, then returns them so you can continue the same task. Do not use it for information that can be inferred safely.",
|
|
24
|
+
description: "Ask the user one or more questions when missing information would materially change the outcome. The call waits for every answer, then returns them so you can continue the same task. Do not use it for information that can be inferred safely. For single_select and multi_select questions, every option MUST contain both a machine-readable value and a user-visible label; never omit value or use label as value. Example: { value: 'cn', label: '中国' }.",
|
|
25
25
|
inputSchema: ask_questions_input_schema,
|
|
26
26
|
execute: async (input, execution_options) => {
|
|
27
27
|
const execution_context = execution_options.experimental_context;
|
|
@@ -42,7 +42,12 @@ export const AskQuestionsTool = tool({
|
|
|
42
42
|
tool_name: "ask_question",
|
|
43
43
|
},
|
|
44
44
|
title: input.title,
|
|
45
|
-
questions: input.questions
|
|
45
|
+
questions: input.questions.map((question) => ({
|
|
46
|
+
question_id: `question:${generate_id()}`,
|
|
47
|
+
prompt: question.question,
|
|
48
|
+
response_type: question.type,
|
|
49
|
+
...(question.options ? { options: question.options } : {}),
|
|
50
|
+
})),
|
|
46
51
|
created_at: Date.now(),
|
|
47
52
|
});
|
|
48
53
|
const result = await handle.result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AskQuestionsTool.js","sourceRoot":"","sources":["../../../src/tools/ask/AskQuestionsTool.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,IAAI,EAA6B,MAAM,IAAI,CAAC;AACrD,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAM1E,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;IACnC,WAAW,EACT,
|
|
1
|
+
{"version":3,"file":"AskQuestionsTool.js","sourceRoot":"","sources":["../../../src/tools/ask/AskQuestionsTool.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,IAAI,EAA6B,MAAM,IAAI,CAAC;AACrD,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAM1E,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;IACnC,WAAW,EACT,kcAAkc;IACpc,WAAW,EAAE,0BAA0B;IACvC,OAAO,EAAE,KAAK,EACZ,KAA4B,EAC5B,iBAAuC,EACQ,EAAE;QACjD,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,oBAE/B,CAAC;QACd,MAAM,YAAY,GAAG,iBAAiB,EAAE,oBAAoB,CAAC;QAC7D,MAAM,gBAAgB,GAAG,YAAY,EAAE,YAAY,CAAC;QACpD,MAAM,OAAO,GAAG,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE,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AAC,CAAC;QACpE,CAAC;QACD,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;QACJ,CAAC;QACD,OAAO;YACL,MAAM,EAAE;gBACN,MAAM,EAAE,UAAU;gBAClB,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO;aACjC;YACD,QAAQ,EAAE,EAAE;SACb,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -9,13 +9,11 @@ import { z } from "zod";
|
|
|
9
9
|
export declare const ask_questions_input_schema: z.ZodObject<{
|
|
10
10
|
title: z.ZodString;
|
|
11
11
|
questions: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
response_type: z.ZodLiteral<"text">;
|
|
12
|
+
question: z.ZodString;
|
|
13
|
+
type: z.ZodLiteral<"text">;
|
|
15
14
|
}, z.core.$strict>, z.ZodObject<{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
response_type: z.ZodEnum<{
|
|
15
|
+
question: z.ZodString;
|
|
16
|
+
type: z.ZodEnum<{
|
|
19
17
|
single_select: "single_select";
|
|
20
18
|
multi_select: "multi_select";
|
|
21
19
|
}>;
|
|
@@ -24,6 +22,6 @@ export declare const ask_questions_input_schema: z.ZodObject<{
|
|
|
24
22
|
label: z.ZodString;
|
|
25
23
|
description: z.ZodOptional<z.ZodString>;
|
|
26
24
|
}, z.core.$strict>>;
|
|
27
|
-
}, z.core.$strict>], "
|
|
25
|
+
}, z.core.$strict>], "type">>;
|
|
28
26
|
}, z.core.$strict>;
|
|
29
27
|
//# sourceMappingURL=AskQuestionsToolSchemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AskQuestionsToolSchemas.d.ts","sourceRoot":"","sources":["../../../src/tools/ask/AskQuestionsToolSchemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"AskQuestionsToolSchemas.d.ts","sourceRoot":"","sources":["../../../src/tools/ask/AskQuestionsToolSchemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAmCxB,yCAAyC;AACzC,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;kBAY5B,CAAC"}
|
|
@@ -8,30 +8,27 @@ import { z } from "zod";
|
|
|
8
8
|
const option_schema = z
|
|
9
9
|
.object({
|
|
10
10
|
value: z.string().trim().min(1)
|
|
11
|
-
.describe("
|
|
12
|
-
label: z.string().trim().min(1)
|
|
11
|
+
.describe("Required machine-readable stable identifier returned in the answer. Never omit this field or use label as its substitute."),
|
|
12
|
+
label: z.string().trim().min(1)
|
|
13
|
+
.describe("Required user-visible option label; this is not the answer value."),
|
|
13
14
|
description: z.string().trim().min(1).optional()
|
|
14
15
|
.describe("Optional explanation of this option."),
|
|
15
16
|
})
|
|
16
17
|
.strict();
|
|
17
18
|
const text_question_schema = z
|
|
18
19
|
.object({
|
|
19
|
-
|
|
20
|
-
.describe("Stable question identifier unique within this request."),
|
|
21
|
-
prompt: z.string().trim().min(1)
|
|
20
|
+
question: z.string().trim().min(1)
|
|
22
21
|
.describe("Complete question shown to the user."),
|
|
23
|
-
|
|
22
|
+
type: z.literal("text"),
|
|
24
23
|
})
|
|
25
24
|
.strict();
|
|
26
25
|
const select_question_schema = z
|
|
27
26
|
.object({
|
|
28
|
-
|
|
29
|
-
.describe("Stable question identifier unique within this request."),
|
|
30
|
-
prompt: z.string().trim().min(1)
|
|
27
|
+
question: z.string().trim().min(1)
|
|
31
28
|
.describe("Complete question shown to the user."),
|
|
32
|
-
|
|
29
|
+
type: z.enum(["single_select", "multi_select"]),
|
|
33
30
|
options: z.array(option_schema).min(1)
|
|
34
|
-
.describe("
|
|
31
|
+
.describe("Required selectable options. Every option MUST include both value and label, for example { value: 'cn', label: '中国' }."),
|
|
35
32
|
})
|
|
36
33
|
.strict();
|
|
37
34
|
/** ask_question Tool 的运行时输入校验 Schema。 */
|
|
@@ -40,7 +37,7 @@ export const ask_questions_input_schema = z
|
|
|
40
37
|
title: z.string().trim().min(1)
|
|
41
38
|
.describe("Short title for the question card."),
|
|
42
39
|
questions: z
|
|
43
|
-
.array(z.discriminatedUnion("
|
|
40
|
+
.array(z.discriminatedUnion("type", [
|
|
44
41
|
text_question_schema,
|
|
45
42
|
select_question_schema,
|
|
46
43
|
]))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AskQuestionsToolSchemas.js","sourceRoot":"","sources":["../../../src/tools/ask/AskQuestionsToolSchemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,aAAa,GAAG,CAAC;KACpB,MAAM,CAAC;IACN,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;SAC5B,QAAQ,
|
|
1
|
+
{"version":3,"file":"AskQuestionsToolSchemas.js","sourceRoot":"","sources":["../../../src/tools/ask/AskQuestionsToolSchemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,aAAa,GAAG,CAAC;KACpB,MAAM,CAAC;IACN,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;SAC5B,QAAQ,CACP,2HAA2H,CAC5H;IACH,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;SAC5B,QAAQ,CAAC,mEAAmE,CAAC;IAChF,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CA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AAC"}
|
package/bin/tools/index.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* `AgentOptions.tools` 显式完成组合。
|
|
6
6
|
*/
|
|
7
7
|
export { AskQuestionsTool } from "./ask/AskQuestionsTool.js";
|
|
8
|
-
export type { AskQuestionsToolInput, AskQuestionsToolOutput, } from "../types/tools/ask/AskQuestionsTool.js";
|
|
8
|
+
export type { AskQuestionsToolQuestion, AskQuestionsToolInput, AskQuestionsToolOutput, } from "../types/tools/ask/AskQuestionsTool.js";
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/bin/tools/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,YAAY,EACV,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,wCAAwC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,YAAY,EACV,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,wCAAwC,CAAC"}
|
|
@@ -4,13 +4,22 @@
|
|
|
4
4
|
* 该协议只描述模型发起问题和收到回答时可见的数据;Interaction 标识、Turn 标识与
|
|
5
5
|
* 生命周期状态由 Session 运行时维护,不交给模型生成。
|
|
6
6
|
*/
|
|
7
|
-
import type { SessionInteractionAnswer, SessionInteractionQuestion } from "../../../types/session/SessionInteraction.js";
|
|
7
|
+
import type { SessionInteractionAnswer, SessionInteractionOption, SessionInteractionQuestion } from "../../../types/session/SessionInteraction.js";
|
|
8
|
+
/** 模型调用 ask_question 时提交的一条问题。 */
|
|
9
|
+
export interface AskQuestionsToolQuestion {
|
|
10
|
+
/** 向用户展示的完整问题文本。 */
|
|
11
|
+
question: string;
|
|
12
|
+
/** 当前问题要求的回答形式,所有问题都必须显式提供。 */
|
|
13
|
+
type: SessionInteractionQuestion["response_type"];
|
|
14
|
+
/** 单选或多选问题允许选择的候选项。 */
|
|
15
|
+
options?: SessionInteractionOption[];
|
|
16
|
+
}
|
|
8
17
|
/** 模型调用 ask_question 时提交的结构化输入。 */
|
|
9
18
|
export interface AskQuestionsToolInput {
|
|
10
19
|
/** 问题卡片向用户展示的简短标题。 */
|
|
11
20
|
title: string;
|
|
12
21
|
/** 本次需要用户完整回答的一到多条问题。 */
|
|
13
|
-
questions:
|
|
22
|
+
questions: AskQuestionsToolQuestion[];
|
|
14
23
|
}
|
|
15
24
|
/** 用户完成回答后返回给模型的结构化 Tool Result。 */
|
|
16
25
|
export interface AskQuestionsToolOutput {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AskQuestionsTool.d.ts","sourceRoot":"","sources":["../../../../src/types/tools/ask/AskQuestionsTool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,uCAAuC,CAAC;AAE/C,mCAAmC;AACnC,MAAM,WAAW,qBAAqB;IACpC,sBAAsB;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,yBAAyB;IACzB,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"AskQuestionsTool.d.ts","sourceRoot":"","sources":["../../../../src/types/tools/ask/AskQuestionsTool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,wBAAwB,EACxB,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,uCAAuC,CAAC;AAE/C,kCAAkC;AAClC,MAAM,WAAW,wBAAwB;IACvC,oBAAoB;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,+BAA+B;IAC/B,IAAI,EAAE,0BAA0B,CAAC,eAAe,CAAC,CAAC;IAClD,uBAAuB;IACvB,OAAO,CAAC,EAAE,wBAAwB,EAAE,CAAC;CACtC;AAED,mCAAmC;AACnC,MAAM,WAAW,qBAAqB;IACpC,sBAAsB;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,yBAAyB;IACzB,SAAS,EAAE,wBAAwB,EAAE,CAAC;CACvC;AAED,oCAAoC;AACpC,MAAM,WAAW,sBAAsB;IACrC,oBAAoB;IACpB,MAAM,EAAE,UAAU,CAAC;IACnB,+BAA+B;IAC/B,OAAO,EAAE,wBAAwB,EAAE,CAAC;CACrC"}
|
package/package.json
CHANGED
|
@@ -30,9 +30,8 @@ function create_question_stream() {
|
|
|
30
30
|
title: "选择部署区域",
|
|
31
31
|
questions: [
|
|
32
32
|
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
response_type: "single_select",
|
|
33
|
+
question: "需要部署到哪个区域?",
|
|
34
|
+
type: "single_select",
|
|
36
35
|
options: [
|
|
37
36
|
{ value: "cn", label: "中国" },
|
|
38
37
|
{ value: "us", label: "美国" },
|
|
@@ -164,7 +163,10 @@ test("显式注入的 ask_question 等待回答并继续同一个 Turn", async (
|
|
|
164
163
|
interaction_id: mutation.part.interaction_id,
|
|
165
164
|
response: {
|
|
166
165
|
kind: "question",
|
|
167
|
-
answers: [{
|
|
166
|
+
answers: [{
|
|
167
|
+
question_id: pending_interaction.request.questions[0].question_id,
|
|
168
|
+
value: "cn",
|
|
169
|
+
}],
|
|
168
170
|
},
|
|
169
171
|
});
|
|
170
172
|
});
|
|
@@ -184,7 +186,10 @@ test("显式注入的 ask_question 等待回答并继续同一个 Turn", async (
|
|
|
184
186
|
interaction_id: pending_interaction.interaction_id,
|
|
185
187
|
response: {
|
|
186
188
|
kind: "question",
|
|
187
|
-
answers: [{
|
|
189
|
+
answers: [{
|
|
190
|
+
question_id: pending_interaction.request.questions[0].question_id,
|
|
191
|
+
value: "cn",
|
|
192
|
+
}],
|
|
188
193
|
},
|
|
189
194
|
});
|
|
190
195
|
|
|
@@ -201,7 +206,10 @@ test("显式注入的 ask_question 等待回答并继续同一个 Turn", async (
|
|
|
201
206
|
assert.equal(tool_part?.state, "completed");
|
|
202
207
|
assert.deepEqual(tool_part?.output, {
|
|
203
208
|
status: "resolved",
|
|
204
|
-
answers: [{
|
|
209
|
+
answers: [{
|
|
210
|
+
question_id: pending_interaction.request.questions[0].question_id,
|
|
211
|
+
value: "cn",
|
|
212
|
+
}],
|
|
205
213
|
});
|
|
206
214
|
assert.equal(interaction_part?.status, "resolved");
|
|
207
215
|
assert.equal(interaction_part?.request.source.type, "tool");
|
|
@@ -30,7 +30,7 @@ import type { ActionResult } from "@/types/action/ActionResult.js";
|
|
|
30
30
|
*/
|
|
31
31
|
export const AskQuestionsTool = tool({
|
|
32
32
|
description:
|
|
33
|
-
"Ask the user one or more questions when missing information would materially change the outcome. The call waits for every answer, then returns them so you can continue the same task. Do not use it for information that can be inferred safely.",
|
|
33
|
+
"Ask the user one or more questions when missing information would materially change the outcome. The call waits for every answer, then returns them so you can continue the same task. Do not use it for information that can be inferred safely. For single_select and multi_select questions, every option MUST contain both a machine-readable value and a user-visible label; never omit value or use label as value. Example: { value: 'cn', label: '中国' }.",
|
|
34
34
|
inputSchema: ask_questions_input_schema,
|
|
35
35
|
execute: async (
|
|
36
36
|
input: AskQuestionsToolInput,
|
|
@@ -59,7 +59,12 @@ export const AskQuestionsTool = tool({
|
|
|
59
59
|
tool_name: "ask_question",
|
|
60
60
|
},
|
|
61
61
|
title: input.title,
|
|
62
|
-
questions: input.questions
|
|
62
|
+
questions: input.questions.map((question) => ({
|
|
63
|
+
question_id: `question:${generate_id()}`,
|
|
64
|
+
prompt: question.question,
|
|
65
|
+
response_type: question.type,
|
|
66
|
+
...(question.options ? { options: question.options } : {}),
|
|
67
|
+
})),
|
|
63
68
|
created_at: Date.now(),
|
|
64
69
|
});
|
|
65
70
|
const result = await handle.result;
|
|
@@ -10,8 +10,11 @@ import { z } from "zod";
|
|
|
10
10
|
const option_schema = z
|
|
11
11
|
.object({
|
|
12
12
|
value: z.string().trim().min(1)
|
|
13
|
-
.describe(
|
|
14
|
-
|
|
13
|
+
.describe(
|
|
14
|
+
"Required machine-readable stable identifier returned in the answer. Never omit this field or use label as its substitute.",
|
|
15
|
+
),
|
|
16
|
+
label: z.string().trim().min(1)
|
|
17
|
+
.describe("Required user-visible option label; this is not the answer value."),
|
|
15
18
|
description: z.string().trim().min(1).optional()
|
|
16
19
|
.describe("Optional explanation of this option."),
|
|
17
20
|
})
|
|
@@ -19,23 +22,21 @@ const option_schema = z
|
|
|
19
22
|
|
|
20
23
|
const text_question_schema = z
|
|
21
24
|
.object({
|
|
22
|
-
|
|
23
|
-
.describe("Stable question identifier unique within this request."),
|
|
24
|
-
prompt: z.string().trim().min(1)
|
|
25
|
+
question: z.string().trim().min(1)
|
|
25
26
|
.describe("Complete question shown to the user."),
|
|
26
|
-
|
|
27
|
+
type: z.literal("text"),
|
|
27
28
|
})
|
|
28
29
|
.strict();
|
|
29
30
|
|
|
30
31
|
const select_question_schema = z
|
|
31
32
|
.object({
|
|
32
|
-
|
|
33
|
-
.describe("Stable question identifier unique within this request."),
|
|
34
|
-
prompt: z.string().trim().min(1)
|
|
33
|
+
question: z.string().trim().min(1)
|
|
35
34
|
.describe("Complete question shown to the user."),
|
|
36
|
-
|
|
35
|
+
type: z.enum(["single_select", "multi_select"]),
|
|
37
36
|
options: z.array(option_schema).min(1)
|
|
38
|
-
.describe(
|
|
37
|
+
.describe(
|
|
38
|
+
"Required selectable options. Every option MUST include both value and label, for example { value: 'cn', label: '中国' }.",
|
|
39
|
+
),
|
|
39
40
|
})
|
|
40
41
|
.strict();
|
|
41
42
|
|
|
@@ -45,7 +46,7 @@ export const ask_questions_input_schema = z
|
|
|
45
46
|
title: z.string().trim().min(1)
|
|
46
47
|
.describe("Short title for the question card."),
|
|
47
48
|
questions: z
|
|
48
|
-
.array(z.discriminatedUnion("
|
|
49
|
+
.array(z.discriminatedUnion("type", [
|
|
49
50
|
text_question_schema,
|
|
50
51
|
select_question_schema,
|
|
51
52
|
]))
|
package/src/tools/index.ts
CHANGED
|
@@ -7,15 +7,26 @@
|
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
9
|
SessionInteractionAnswer,
|
|
10
|
+
SessionInteractionOption,
|
|
10
11
|
SessionInteractionQuestion,
|
|
11
12
|
} from "@/types/session/SessionInteraction.js";
|
|
12
13
|
|
|
14
|
+
/** 模型调用 ask_question 时提交的一条问题。 */
|
|
15
|
+
export interface AskQuestionsToolQuestion {
|
|
16
|
+
/** 向用户展示的完整问题文本。 */
|
|
17
|
+
question: string;
|
|
18
|
+
/** 当前问题要求的回答形式,所有问题都必须显式提供。 */
|
|
19
|
+
type: SessionInteractionQuestion["response_type"];
|
|
20
|
+
/** 单选或多选问题允许选择的候选项。 */
|
|
21
|
+
options?: SessionInteractionOption[];
|
|
22
|
+
}
|
|
23
|
+
|
|
13
24
|
/** 模型调用 ask_question 时提交的结构化输入。 */
|
|
14
25
|
export interface AskQuestionsToolInput {
|
|
15
26
|
/** 问题卡片向用户展示的简短标题。 */
|
|
16
27
|
title: string;
|
|
17
28
|
/** 本次需要用户完整回答的一到多条问题。 */
|
|
18
|
-
questions:
|
|
29
|
+
questions: AskQuestionsToolQuestion[];
|
|
19
30
|
}
|
|
20
31
|
|
|
21
32
|
/** 用户完成回答后返回给模型的结构化 Tool Result。 */
|