@eum-agent/human-interaction 1.1.0 → 1.2.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 +127 -76
- package/package.json +9 -5
- package/ui/ui.js +3912 -18
package/dist/index.js
CHANGED
|
@@ -1,51 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
2
3
|
import { fileURLToPath } from "node:url";
|
|
3
4
|
import { z } from "zod";
|
|
4
|
-
//#region src/tool-names.ts
|
|
5
|
-
/** Canonical names shared by tool registration and browser presentation. */
|
|
6
|
-
const TOOL_NAMES = ["user_ask", "user_set_participating"];
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/guidance.ts
|
|
9
|
-
const GUIDANCE = {
|
|
10
|
-
title: "Working with the person",
|
|
11
|
-
entries: [{
|
|
12
|
-
tools: ["user_set_participating"],
|
|
13
|
-
text: "`user_set_participating` with `participating: true` brings the user into a session you started on your own, such as a scheduled task. Routine background work does not bring them in; do it when they should be told something or have to do something, and write the reason they will read. With `participating: false` it returns such a session to background work once the user is no longer needed."
|
|
14
|
-
}, {
|
|
15
|
-
tools: ["user_ask"],
|
|
16
|
-
text: "`user_ask` asks the person a question with the options you see, when only they can decide."
|
|
17
|
-
}]
|
|
18
|
-
};
|
|
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
|
|
49
5
|
//#region src/ask-user/ask.ts
|
|
50
6
|
const Option = z.object({
|
|
51
7
|
label: z.string().min(1).max(128).describe("The choice as the person sees it."),
|
|
@@ -60,9 +16,6 @@ const Question = z.object({
|
|
|
60
16
|
allow_multiple: z.boolean().optional().describe("Whether the person may pick several options. Default false.")
|
|
61
17
|
});
|
|
62
18
|
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
|
|
65
|
-
* the label back — no second vocabulary to keep in step. */
|
|
66
19
|
function toAsk(input) {
|
|
67
20
|
return {
|
|
68
21
|
kind: "question",
|
|
@@ -80,28 +33,58 @@ function toAsk(input) {
|
|
|
80
33
|
}))
|
|
81
34
|
};
|
|
82
35
|
}
|
|
36
|
+
const AnswerDataSchema = z.strictObject({
|
|
37
|
+
ok: z.literal(true),
|
|
38
|
+
committed: z.literal(true),
|
|
39
|
+
requestId: z.string(),
|
|
40
|
+
answeredQuestionIds: z.array(z.string()).max(8)
|
|
41
|
+
});
|
|
83
42
|
function askUserQuestionTool() {
|
|
84
43
|
return {
|
|
85
44
|
name: "user_ask",
|
|
86
45
|
preload: true,
|
|
87
46
|
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.",
|
|
88
47
|
inputSchema: AskInput,
|
|
89
|
-
outputSchema:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
48
|
+
outputSchema: AnswerDataSchema,
|
|
49
|
+
formatModel: async (data) => ({
|
|
50
|
+
formatVersion: 1,
|
|
51
|
+
rendererVersion: 1,
|
|
52
|
+
nodes: [{
|
|
53
|
+
id: "answer",
|
|
54
|
+
kind: "literal",
|
|
55
|
+
text: `Human request ${data.requestId} was answered and committed. Answered questions: ${data.answeredQuestionIds.join(", ")}. Read the original answer from its bound human source.`
|
|
56
|
+
}]
|
|
57
|
+
}),
|
|
95
58
|
deliveryKind: "receipt",
|
|
96
59
|
historySource: "human-answer",
|
|
97
60
|
async execute(input, ctx) {
|
|
98
61
|
if (ctx.answer === void 0) return { awaitHuman: toAsk(input) };
|
|
99
|
-
return {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
62
|
+
return {
|
|
63
|
+
data: {
|
|
64
|
+
ok: true,
|
|
65
|
+
committed: true,
|
|
66
|
+
requestId: ctx.answer.requestId,
|
|
67
|
+
answeredQuestionIds: ctx.answer.answers.map((answer) => answer.questionId)
|
|
68
|
+
},
|
|
69
|
+
execution: { state: "committed" },
|
|
70
|
+
isError: false,
|
|
71
|
+
presentation: {
|
|
72
|
+
type: "human-answer",
|
|
73
|
+
schemaVersion: 1,
|
|
74
|
+
summary: `Answered ${ctx.answer.answers.length} questions`,
|
|
75
|
+
state: "ready",
|
|
76
|
+
fields: {
|
|
77
|
+
requestId: ctx.answer.requestId,
|
|
78
|
+
answered: ctx.answer.answers.length
|
|
79
|
+
},
|
|
80
|
+
actions: [{
|
|
81
|
+
kind: "openSource",
|
|
82
|
+
available: true,
|
|
83
|
+
authorityRef: ctx.answer.requestId
|
|
84
|
+
}],
|
|
85
|
+
bodyRefs: []
|
|
86
|
+
}
|
|
87
|
+
};
|
|
105
88
|
}
|
|
106
89
|
};
|
|
107
90
|
}
|
|
@@ -111,6 +94,18 @@ function registerAskUserTools(_ctx, register) {
|
|
|
111
94
|
register(askUserQuestionTool());
|
|
112
95
|
}
|
|
113
96
|
//#endregion
|
|
97
|
+
//#region src/guidance.ts
|
|
98
|
+
const GUIDANCE = {
|
|
99
|
+
title: "Working with the person",
|
|
100
|
+
entries: [{
|
|
101
|
+
tools: ["user_set_participating"],
|
|
102
|
+
text: "`user_set_participating` with `participating: true` brings the user into a session you started on your own, such as a scheduled task. Routine background work does not bring them in; do it when they should be told something or have to do something, and write the reason they will read. With `participating: false` it returns such a session to background work once the user is no longer needed."
|
|
103
|
+
}, {
|
|
104
|
+
tools: ["user_ask"],
|
|
105
|
+
text: "`user_ask` asks the person a question with the options you see, when only they can decide."
|
|
106
|
+
}]
|
|
107
|
+
};
|
|
108
|
+
//#endregion
|
|
114
109
|
//#region src/participants/index.ts
|
|
115
110
|
const PARTICIPANTS_SERVICE = "session-participants";
|
|
116
111
|
const Reason = z.string().trim().max(500).describe("Reason shown to the person; maximum 500 UTF-16 code units after trimming.");
|
|
@@ -135,10 +130,53 @@ function dismissText(result) {
|
|
|
135
130
|
case "refused": return "the user created this session and cannot be removed";
|
|
136
131
|
}
|
|
137
132
|
}
|
|
138
|
-
|
|
133
|
+
const ParticipantDataSchema = z.strictObject({
|
|
134
|
+
sessionId: z.string(),
|
|
135
|
+
requestedParticipation: z.boolean(),
|
|
136
|
+
participating: z.boolean().nullable(),
|
|
137
|
+
changed: z.boolean().nullable(),
|
|
138
|
+
outcome: z.enum([
|
|
139
|
+
"changed",
|
|
140
|
+
"unchanged",
|
|
141
|
+
"refused",
|
|
142
|
+
"unknown"
|
|
143
|
+
]),
|
|
144
|
+
message: z.string().max(1024)
|
|
145
|
+
});
|
|
146
|
+
function participantDocument(data) {
|
|
147
|
+
return {
|
|
148
|
+
formatVersion: 1,
|
|
149
|
+
rendererVersion: 1,
|
|
150
|
+
nodes: [{
|
|
151
|
+
id: "membership",
|
|
152
|
+
kind: "literal",
|
|
153
|
+
text: `${data.message} (session ${data.sessionId})`
|
|
154
|
+
}]
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function participantResult(data, isError = false) {
|
|
139
158
|
return {
|
|
140
|
-
|
|
141
|
-
isError:
|
|
159
|
+
data,
|
|
160
|
+
execution: { state: isError ? "unknown" : "committed" },
|
|
161
|
+
isError,
|
|
162
|
+
...isError ? { error: {
|
|
163
|
+
code: "participant_change_failed",
|
|
164
|
+
retryable: false
|
|
165
|
+
} } : {},
|
|
166
|
+
presentation: {
|
|
167
|
+
type: "user-participating",
|
|
168
|
+
schemaVersion: 1,
|
|
169
|
+
summary: data.message,
|
|
170
|
+
state: isError ? "unknown" : "ready",
|
|
171
|
+
fields: {
|
|
172
|
+
sessionId: data.sessionId,
|
|
173
|
+
participating: data.participating,
|
|
174
|
+
changed: data.changed,
|
|
175
|
+
outcome: data.outcome
|
|
176
|
+
},
|
|
177
|
+
actions: [],
|
|
178
|
+
bodyRefs: []
|
|
179
|
+
}
|
|
142
180
|
};
|
|
143
181
|
}
|
|
144
182
|
function participatingTool(participants) {
|
|
@@ -147,15 +185,30 @@ function participatingTool(participants) {
|
|
|
147
185
|
preload: false,
|
|
148
186
|
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.",
|
|
149
187
|
inputSchema: ParticipatingInput,
|
|
150
|
-
outputSchema:
|
|
188
|
+
outputSchema: ParticipantDataSchema,
|
|
189
|
+
formatModel: async (data) => participantDocument(data),
|
|
151
190
|
deliveryKind: "receipt",
|
|
152
191
|
async execute(input, ctx) {
|
|
153
192
|
try {
|
|
154
|
-
if (input.participating) return { content: inviteText(await participants.invite(ctx, input.reason ?? "")) };
|
|
155
193
|
const reason = input.reason === "" ? void 0 : input.reason;
|
|
156
|
-
|
|
194
|
+
const result = input.participating ? await participants.invite(ctx, input.reason) : await participants.dismiss(ctx, reason);
|
|
195
|
+
return participantResult({
|
|
196
|
+
sessionId: ctx.sessionId,
|
|
197
|
+
requestedParticipation: input.participating,
|
|
198
|
+
participating: result.kind === "refused" ? true : input.participating,
|
|
199
|
+
changed: result.kind === "changed",
|
|
200
|
+
outcome: result.kind,
|
|
201
|
+
message: input.participating ? inviteText(result) : dismissText(result)
|
|
202
|
+
});
|
|
157
203
|
} catch (error) {
|
|
158
|
-
return
|
|
204
|
+
return participantResult({
|
|
205
|
+
sessionId: ctx.sessionId,
|
|
206
|
+
requestedParticipation: input.participating,
|
|
207
|
+
participating: null,
|
|
208
|
+
changed: null,
|
|
209
|
+
outcome: "unknown",
|
|
210
|
+
message: [...error instanceof Error ? error.message : String(error)].slice(0, 256).join("")
|
|
211
|
+
}, true);
|
|
159
212
|
}
|
|
160
213
|
}
|
|
161
214
|
};
|
|
@@ -164,15 +217,10 @@ function registerParticipantTools(ctx, register) {
|
|
|
164
217
|
register(participatingTool(ctx.services.get(PARTICIPANTS_SERVICE)));
|
|
165
218
|
}
|
|
166
219
|
//#endregion
|
|
220
|
+
//#region src/tool-names.ts
|
|
221
|
+
const TOOL_NAMES = ["user_ask", "user_set_participating"];
|
|
222
|
+
//#endregion
|
|
167
223
|
//#region src/index.ts
|
|
168
|
-
/**
|
|
169
|
-
* This plugin's slice of `config.json`.
|
|
170
|
-
*
|
|
171
|
-
* `disabled` turns one tool off while the rest of the package stays on —
|
|
172
|
-
* `enabled: false` on the declaration turns off every one of them. Strict and
|
|
173
|
-
* enumerated: a misspelled tool name is a load failure naming the field, not
|
|
174
|
-
* a line that quietly does nothing.
|
|
175
|
-
*/
|
|
176
224
|
const HitlConfig = z.strictObject({ disabled: z.array(z.enum(TOOL_NAMES)).default([]) }).default({ disabled: [] });
|
|
177
225
|
const hitlPlugin = {
|
|
178
226
|
name: "@eum-agent/human-interaction",
|
|
@@ -180,7 +228,10 @@ const hitlPlugin = {
|
|
|
180
228
|
configSchema: HitlConfig,
|
|
181
229
|
apply(ctx, config) {
|
|
182
230
|
const module = fileURLToPath(new URL("../ui/ui.js", import.meta.url));
|
|
183
|
-
if (existsSync(module)) ctx.client.
|
|
231
|
+
if (existsSync(module)) ctx.client.registerPackageFiles({
|
|
232
|
+
root: dirname(module),
|
|
233
|
+
entry: "ui.js"
|
|
234
|
+
});
|
|
184
235
|
const disabled = new Set(config.disabled);
|
|
185
236
|
const register = (tool) => disabled.has(tool.name) ? void 0 : ctx.tools.register(tool);
|
|
186
237
|
registerAskUserTools(ctx, register);
|
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.2.0",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"description": "Requests for human input and human participation in agent sessions",
|
|
10
10
|
"license": "MIT",
|
|
@@ -23,8 +23,12 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@eum-agent/container": "1.0.0",
|
|
25
25
|
"@eum-agent/kernel": "1.0.0",
|
|
26
|
-
"@eum-agent/plugin": "1.
|
|
27
|
-
"vite": "^8.2.2"
|
|
26
|
+
"@eum-agent/plugin": "1.2.0",
|
|
27
|
+
"vite": "^8.2.2",
|
|
28
|
+
"react": "^19.2.0",
|
|
29
|
+
"react-dom": "^19.2.0",
|
|
30
|
+
"@types/react": "^19.2.18",
|
|
31
|
+
"@types/react-dom": "^19.2.5"
|
|
28
32
|
},
|
|
29
33
|
"yaoguang": {
|
|
30
34
|
"description": {
|
|
@@ -34,12 +38,12 @@
|
|
|
34
38
|
"dependencies": {},
|
|
35
39
|
"kind": "extension",
|
|
36
40
|
"foundationDependencies": {
|
|
37
|
-
"@eum-agent/infra-local": "1.0
|
|
41
|
+
"@eum-agent/infra-local": "1.2.0"
|
|
38
42
|
}
|
|
39
43
|
},
|
|
40
44
|
"scripts": {
|
|
41
45
|
"build": "tsdown && vite build",
|
|
42
46
|
"test": "vitest run",
|
|
43
|
-
"typecheck": "tsc --noEmit"
|
|
47
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.ui.json"
|
|
44
48
|
}
|
|
45
49
|
}
|