@eum-agent/human-interaction 1.0.0 → 1.1.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.js +68 -35
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -17,28 +17,59 @@ 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
|
|
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 label for question navigation."),
|
|
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
|
|
34
|
-
/**
|
|
62
|
+
const AskInput = z.object({ questions: z.array(Question).min(1).max(8).describe("One to eight questions in a single request.") }).refine((value) => new TextEncoder().encode(JSON.stringify(value)).byteLength <= 8388608, "Question input exceeds 8 MiB");
|
|
63
|
+
/** Converts model questions to human requests, preserving short headers separately from text.
|
|
64
|
+
* Option ids are the labels: a person picks by label, and the model reads
|
|
35
65
|
* the label back — no second vocabulary to keep in step. */
|
|
36
66
|
function toAsk(input) {
|
|
37
67
|
return {
|
|
38
68
|
kind: "question",
|
|
39
69
|
questions: input.questions.map((q) => ({
|
|
40
70
|
id: q.id,
|
|
41
|
-
|
|
71
|
+
...q.header === void 0 ? {} : { header: q.header },
|
|
72
|
+
text: q.question,
|
|
42
73
|
options: (q.options ?? []).map((o) => ({
|
|
43
74
|
id: o.label,
|
|
44
75
|
label: o.label,
|
|
@@ -49,27 +80,28 @@ function toAsk(input) {
|
|
|
49
80
|
}))
|
|
50
81
|
};
|
|
51
82
|
}
|
|
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
83
|
function askUserQuestionTool() {
|
|
66
84
|
return {
|
|
67
85
|
name: "user_ask",
|
|
68
|
-
|
|
86
|
+
preload: true,
|
|
87
|
+
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
88
|
inputSchema: AskInput,
|
|
89
|
+
outputSchema: toolOutputSchema(z.strictObject({
|
|
90
|
+
ok: z.literal(true),
|
|
91
|
+
committed: z.literal(true),
|
|
92
|
+
requestId: z.string(),
|
|
93
|
+
answeredQuestionIds: z.array(z.string()).max(8)
|
|
94
|
+
}), AskInput, "user_ask"),
|
|
95
|
+
deliveryKind: "receipt",
|
|
96
|
+
historySource: "human-answer",
|
|
70
97
|
async execute(input, ctx) {
|
|
71
98
|
if (ctx.answer === void 0) return { awaitHuman: toAsk(input) };
|
|
72
|
-
return { content: JSON.stringify({
|
|
99
|
+
return { content: JSON.stringify({
|
|
100
|
+
ok: true,
|
|
101
|
+
committed: true,
|
|
102
|
+
requestId: ctx.answer.requestId,
|
|
103
|
+
answeredQuestionIds: ctx.answer.answers.map((answer) => answer.questionId)
|
|
104
|
+
}) };
|
|
73
105
|
}
|
|
74
106
|
};
|
|
75
107
|
}
|
|
@@ -81,16 +113,14 @@ function registerAskUserTools(_ctx, register) {
|
|
|
81
113
|
//#endregion
|
|
82
114
|
//#region src/participants/index.ts
|
|
83
115
|
const PARTICIPANTS_SERVICE = "session-participants";
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
93
|
-
});
|
|
116
|
+
const Reason = z.string().trim().max(500).describe("Reason shown to the person; maximum 500 UTF-16 code units after trimming.");
|
|
117
|
+
const ParticipatingInput = z.union([z.strictObject({
|
|
118
|
+
participating: z.literal(true).describe("Invite the person into this calling session."),
|
|
119
|
+
reason: Reason.min(1).describe("Required nonempty invitation reason shown to the person; maximum 500 UTF-16 code units after trimming.")
|
|
120
|
+
}), z.strictObject({
|
|
121
|
+
participating: z.literal(false).describe("Let the person leave this calling session."),
|
|
122
|
+
reason: Reason.optional().describe("Optional reason for leaving; maximum 500 UTF-16 code units after trimming.")
|
|
123
|
+
})]);
|
|
94
124
|
function inviteText(result) {
|
|
95
125
|
switch (result.kind) {
|
|
96
126
|
case "changed": return "the user was added to this session";
|
|
@@ -107,15 +137,18 @@ function dismissText(result) {
|
|
|
107
137
|
}
|
|
108
138
|
function failure(error) {
|
|
109
139
|
return {
|
|
110
|
-
content: error instanceof Error ? error.message : String(error),
|
|
140
|
+
content: [...error instanceof Error ? error.message : String(error)].slice(0, 256).join(""),
|
|
111
141
|
isError: true
|
|
112
142
|
};
|
|
113
143
|
}
|
|
114
144
|
function participatingTool(participants) {
|
|
115
145
|
return {
|
|
116
146
|
name: "user_set_participating",
|
|
147
|
+
preload: false,
|
|
117
148
|
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
149
|
inputSchema: ParticipatingInput,
|
|
150
|
+
outputSchema: z.string().max(1024),
|
|
151
|
+
deliveryKind: "receipt",
|
|
119
152
|
async execute(input, ctx) {
|
|
120
153
|
try {
|
|
121
154
|
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.
|
|
7
|
+
"version": "1.1.0",
|
|
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.
|
|
26
|
+
"@eum-agent/plugin": "1.1.0",
|
|
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": {
|