@eum-agent/human-interaction 1.0.0 → 1.0.1
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.js +64 -33
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -17,20 +17,49 @@ const GUIDANCE = {
|
|
|
17
17
|
}]
|
|
18
18
|
};
|
|
19
19
|
//#endregion
|
|
20
|
+
//#region src/output-schema.ts
|
|
21
|
+
/** Validates complete owner business results and bounded recoverable delivery failures. */
|
|
22
|
+
/** Adds the standard failure envelope and bounded text refusals to an owner's result schema. */
|
|
23
|
+
function toolOutputSchema(body, input, name) {
|
|
24
|
+
return z.union([
|
|
25
|
+
body,
|
|
26
|
+
z.strictObject({
|
|
27
|
+
ok: z.literal(false),
|
|
28
|
+
error: z.strictObject({
|
|
29
|
+
code: z.string().min(1).max(128),
|
|
30
|
+
message: z.string().refine((value) => [...value].length <= 256).meta({ maxLength: 256 }),
|
|
31
|
+
retryable: z.boolean(),
|
|
32
|
+
field: z.string().max(256).optional(),
|
|
33
|
+
maximum: z.number().finite().optional()
|
|
34
|
+
}),
|
|
35
|
+
next: z.strictObject({
|
|
36
|
+
tool: z.literal(name),
|
|
37
|
+
arguments: input
|
|
38
|
+
}).nullable(),
|
|
39
|
+
execution: z.strictObject({ state: z.enum([
|
|
40
|
+
"not-started",
|
|
41
|
+
"committed",
|
|
42
|
+
"unknown"
|
|
43
|
+
]) }).optional()
|
|
44
|
+
}),
|
|
45
|
+
z.string().max(1024)
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
20
49
|
//#region src/ask-user/ask.ts
|
|
21
50
|
const Option = z.object({
|
|
22
|
-
label: z.string().min(1).describe("The choice as the person sees it."),
|
|
23
|
-
description: z.string().optional().describe("One line under the label, if it needs one.")
|
|
51
|
+
label: z.string().min(1).max(128).describe("The choice as the person sees it."),
|
|
52
|
+
description: z.string().max(512).optional().describe("One line under the label, if it needs one.")
|
|
24
53
|
});
|
|
25
54
|
const Question = z.object({
|
|
26
|
-
id: z.string().min(1).describe("Stable id, echoed in the answer."),
|
|
27
|
-
question: z.string().min(1).describe("The complete question, with any context needed to answer it."),
|
|
28
|
-
header: z.string().optional().describe("A short heading over the question."),
|
|
29
|
-
options: z.array(Option).min(1).optional().describe("Suggested answers, in display order; put the recommended one first. Omit for a free-text question."),
|
|
55
|
+
id: z.string().min(1).max(128).describe("Stable id, echoed in the answer."),
|
|
56
|
+
question: z.string().min(1).max(8e3).describe("The complete question, with any context needed to answer it."),
|
|
57
|
+
header: z.string().max(128).optional().describe("A short heading over the question."),
|
|
58
|
+
options: z.array(Option).min(1).max(8).optional().describe("Suggested answers, in display order; put the recommended one first. Omit for a free-text question."),
|
|
30
59
|
allow_free_text: z.boolean().optional().describe("Whether the person may type an answer instead of picking an option. Default true."),
|
|
31
60
|
allow_multiple: z.boolean().optional().describe("Whether the person may pick several options. Default false.")
|
|
32
61
|
});
|
|
33
|
-
const AskInput = z.object({ questions: z.array(Question).min(1).describe("One
|
|
62
|
+
const AskInput = z.object({ questions: z.array(Question).min(1).max(8).describe("One to eight questions, shown together.") }).refine((value) => new TextEncoder().encode(JSON.stringify(value)).byteLength <= 8388608, "Question input exceeds 8 MiB");
|
|
34
63
|
/** Option ids are the labels: a person picks by label, and the model reads
|
|
35
64
|
* the label back — no second vocabulary to keep in step. */
|
|
36
65
|
function toAsk(input) {
|
|
@@ -49,27 +78,28 @@ function toAsk(input) {
|
|
|
49
78
|
}))
|
|
50
79
|
};
|
|
51
80
|
}
|
|
52
|
-
/** The reply as the model reads it. `selected` holds the picked labels —
|
|
53
|
-
* one at most on a single-choice question, possibly none; `custom` the
|
|
54
|
-
* typed text, present only when there was some. */
|
|
55
|
-
function toAnswers(reply) {
|
|
56
|
-
return reply.answers.map((a) => {
|
|
57
|
-
const text = a.text?.trim() ?? "";
|
|
58
|
-
return {
|
|
59
|
-
id: a.questionId,
|
|
60
|
-
selected: [...a.optionIds ?? []],
|
|
61
|
-
...text === "" ? {} : { custom: text }
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
81
|
function askUserQuestionTool() {
|
|
66
82
|
return {
|
|
67
83
|
name: "user_ask",
|
|
68
|
-
|
|
84
|
+
preload: true,
|
|
85
|
+
description: "Ask the person one or more questions and wait for their answer. Use it when you need missing information, a preference, a constraint or a clarification before continuing. The turn pauses until they answer; the answer comes back as a short committed receipt. The framework supplies a bounded answer preview and restoration reference. Keep questions concise and self-contained. Set allow_multiple to let the person pick several options. Read the answer preview or its original source for their selections. The person can always type a free-text answer unless allow_free_text is false; do not add an \"Other\" option.",
|
|
69
86
|
inputSchema: AskInput,
|
|
87
|
+
outputSchema: toolOutputSchema(z.strictObject({
|
|
88
|
+
ok: z.literal(true),
|
|
89
|
+
committed: z.literal(true),
|
|
90
|
+
requestId: z.string(),
|
|
91
|
+
answeredQuestionIds: z.array(z.string()).max(8)
|
|
92
|
+
}), AskInput, "user_ask"),
|
|
93
|
+
deliveryKind: "receipt",
|
|
94
|
+
historySource: "human-answer",
|
|
70
95
|
async execute(input, ctx) {
|
|
71
96
|
if (ctx.answer === void 0) return { awaitHuman: toAsk(input) };
|
|
72
|
-
return { content: JSON.stringify({
|
|
97
|
+
return { content: JSON.stringify({
|
|
98
|
+
ok: true,
|
|
99
|
+
committed: true,
|
|
100
|
+
requestId: ctx.answer.requestId,
|
|
101
|
+
answeredQuestionIds: ctx.answer.answers.map((answer) => answer.questionId)
|
|
102
|
+
}) };
|
|
73
103
|
}
|
|
74
104
|
};
|
|
75
105
|
}
|
|
@@ -81,16 +111,14 @@ function registerAskUserTools(_ctx, register) {
|
|
|
81
111
|
//#endregion
|
|
82
112
|
//#region src/participants/index.ts
|
|
83
113
|
const PARTICIPANTS_SERVICE = "session-participants";
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
93
|
-
});
|
|
114
|
+
const Reason = z.string().trim().max(500).describe("Reason shown to the person; maximum 500 UTF-16 code units after trimming.");
|
|
115
|
+
const ParticipatingInput = z.union([z.strictObject({
|
|
116
|
+
participating: z.literal(true).describe("Invite the person into this calling session."),
|
|
117
|
+
reason: Reason.min(1).describe("Required nonempty invitation reason shown to the person; maximum 500 UTF-16 code units after trimming.")
|
|
118
|
+
}), z.strictObject({
|
|
119
|
+
participating: z.literal(false).describe("Let the person leave this calling session."),
|
|
120
|
+
reason: Reason.optional().describe("Optional reason for leaving; maximum 500 UTF-16 code units after trimming.")
|
|
121
|
+
})]);
|
|
94
122
|
function inviteText(result) {
|
|
95
123
|
switch (result.kind) {
|
|
96
124
|
case "changed": return "the user was added to this session";
|
|
@@ -107,15 +135,18 @@ function dismissText(result) {
|
|
|
107
135
|
}
|
|
108
136
|
function failure(error) {
|
|
109
137
|
return {
|
|
110
|
-
content: error instanceof Error ? error.message : String(error),
|
|
138
|
+
content: [...error instanceof Error ? error.message : String(error)].slice(0, 256).join(""),
|
|
111
139
|
isError: true
|
|
112
140
|
};
|
|
113
141
|
}
|
|
114
142
|
function participatingTool(participants) {
|
|
115
143
|
return {
|
|
116
144
|
name: "user_set_participating",
|
|
145
|
+
preload: false,
|
|
117
146
|
description: "Bring the user into this session with `participating: true`, so it appears among their conversations and they are told why; `reason` then says what you need from them or what they should know, in one or two sentences they will read. With `participating: false`, let the user go once they are no longer needed; the session returns to background work and `reason` is optional.",
|
|
118
147
|
inputSchema: ParticipatingInput,
|
|
148
|
+
outputSchema: z.string().max(1024),
|
|
149
|
+
deliveryKind: "receipt",
|
|
119
150
|
async execute(input, ctx) {
|
|
120
151
|
try {
|
|
121
152
|
if (input.participating) return { content: inviteText(await participants.invite(ctx, input.reason ?? "")) };
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"en-US": "Human Interaction",
|
|
5
5
|
"zh-CN": "人工交互"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.0.
|
|
7
|
+
"version": "1.0.1",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"description": "Requests for human input and human participation in agent sessions",
|
|
10
10
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@eum-agent/container": "1.0.0",
|
|
25
25
|
"@eum-agent/kernel": "1.0.0",
|
|
26
|
-
"@eum-agent/plugin": "1.0.
|
|
26
|
+
"@eum-agent/plugin": "1.0.1",
|
|
27
27
|
"vite": "^8.2.2"
|
|
28
28
|
},
|
|
29
29
|
"yaoguang": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dependencies": {},
|
|
35
35
|
"kind": "extension",
|
|
36
36
|
"foundationDependencies": {
|
|
37
|
-
"@eum-agent/infra-local": "1.0.
|
|
37
|
+
"@eum-agent/infra-local": "1.0.1"
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|