@eum-agent/human-interaction 0.0.0-stage → 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 ADDED
@@ -0,0 +1,190 @@
1
+ import { existsSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+ 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
+ //#region src/ask-user/ask.ts
50
+ const Option = z.object({
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.")
53
+ });
54
+ const Question = z.object({
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."),
59
+ allow_free_text: z.boolean().optional().describe("Whether the person may type an answer instead of picking an option. Default true."),
60
+ allow_multiple: z.boolean().optional().describe("Whether the person may pick several options. Default false.")
61
+ });
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");
63
+ /** Option ids are the labels: a person picks by label, and the model reads
64
+ * the label back — no second vocabulary to keep in step. */
65
+ function toAsk(input) {
66
+ return {
67
+ kind: "question",
68
+ questions: input.questions.map((q) => ({
69
+ id: q.id,
70
+ text: q.header === void 0 ? q.question : `${q.header}\n${q.question}`,
71
+ options: (q.options ?? []).map((o) => ({
72
+ id: o.label,
73
+ label: o.label,
74
+ ...o.description === void 0 ? {} : { description: o.description }
75
+ })),
76
+ freeText: q.allow_free_text ?? true,
77
+ ...q.allow_multiple === true ? { multiple: true } : {}
78
+ }))
79
+ };
80
+ }
81
+ function askUserQuestionTool() {
82
+ return {
83
+ name: "user_ask",
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.",
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",
95
+ async execute(input, ctx) {
96
+ if (ctx.answer === void 0) return { awaitHuman: toAsk(input) };
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
+ }) };
103
+ }
104
+ };
105
+ }
106
+ //#endregion
107
+ //#region src/ask-user/index.ts
108
+ function registerAskUserTools(_ctx, register) {
109
+ register(askUserQuestionTool());
110
+ }
111
+ //#endregion
112
+ //#region src/participants/index.ts
113
+ const PARTICIPANTS_SERVICE = "session-participants";
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
+ })]);
122
+ function inviteText(result) {
123
+ switch (result.kind) {
124
+ case "changed": return "the user was added to this session";
125
+ case "unchanged": return "the user is already in this session";
126
+ case "refused": return "the user created this session and is always in it";
127
+ }
128
+ }
129
+ function dismissText(result) {
130
+ switch (result.kind) {
131
+ case "changed": return "the user was removed from this session";
132
+ case "unchanged": return "the user was not in this session";
133
+ case "refused": return "the user created this session and cannot be removed";
134
+ }
135
+ }
136
+ function failure(error) {
137
+ return {
138
+ content: [...error instanceof Error ? error.message : String(error)].slice(0, 256).join(""),
139
+ isError: true
140
+ };
141
+ }
142
+ function participatingTool(participants) {
143
+ return {
144
+ name: "user_set_participating",
145
+ preload: false,
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.",
147
+ inputSchema: ParticipatingInput,
148
+ outputSchema: z.string().max(1024),
149
+ deliveryKind: "receipt",
150
+ async execute(input, ctx) {
151
+ try {
152
+ if (input.participating) return { content: inviteText(await participants.invite(ctx, input.reason ?? "")) };
153
+ const reason = input.reason === "" ? void 0 : input.reason;
154
+ return { content: dismissText(await participants.dismiss(ctx, reason)) };
155
+ } catch (error) {
156
+ return failure(error);
157
+ }
158
+ }
159
+ };
160
+ }
161
+ function registerParticipantTools(ctx, register) {
162
+ register(participatingTool(ctx.services.get(PARTICIPANTS_SERVICE)));
163
+ }
164
+ //#endregion
165
+ //#region src/index.ts
166
+ /**
167
+ * This plugin's slice of `config.json`.
168
+ *
169
+ * `disabled` turns one tool off while the rest of the package stays on —
170
+ * `enabled: false` on the declaration turns off every one of them. Strict and
171
+ * enumerated: a misspelled tool name is a load failure naming the field, not
172
+ * a line that quietly does nothing.
173
+ */
174
+ const HitlConfig = z.strictObject({ disabled: z.array(z.enum(TOOL_NAMES)).default([]) }).default({ disabled: [] });
175
+ const hitlPlugin = {
176
+ name: "@eum-agent/human-interaction",
177
+ requires: ["session-participants"],
178
+ configSchema: HitlConfig,
179
+ apply(ctx, config) {
180
+ const module = fileURLToPath(new URL("../ui/ui.js", import.meta.url));
181
+ if (existsSync(module)) ctx.client.registerUi({ module });
182
+ const disabled = new Set(config.disabled);
183
+ const register = (tool) => disabled.has(tool.name) ? void 0 : ctx.tools.register(tool);
184
+ registerAskUserTools(ctx, register);
185
+ registerParticipantTools(ctx, register);
186
+ ctx.tools.guide(GUIDANCE);
187
+ }
188
+ };
189
+ //#endregion
190
+ export { HitlConfig, TOOL_NAMES, hitlPlugin as default, hitlPlugin, registerAskUserTools, registerParticipantTools };
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@eum-agent/human-interaction",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "displayName": {
4
+ "en-US": "Human Interaction",
5
+ "zh-CN": "人工交互"
6
+ },
7
+ "version": "1.0.1",
8
+ "type": "module",
9
+ "description": "Requests for human input and human participation in agent sessions",
10
+ "license": "MIT",
11
+ "exports": {
12
+ ".": {
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "ui"
19
+ ],
20
+ "dependencies": {
21
+ "zod": "^4.4.3"
22
+ },
23
+ "devDependencies": {
24
+ "@eum-agent/container": "1.0.0",
25
+ "@eum-agent/kernel": "1.0.0",
26
+ "@eum-agent/plugin": "1.0.1",
27
+ "vite": "^8.2.2"
28
+ },
29
+ "yaoguang": {
30
+ "description": {
31
+ "en-US": "Requests for human input and human participation in agent sessions",
32
+ "zh-CN": "请求人工输入与人工参与智能体会话"
33
+ },
34
+ "dependencies": {},
35
+ "kind": "extension",
36
+ "foundationDependencies": {
37
+ "@eum-agent/infra-local": "1.0.1"
38
+ }
39
+ },
40
+ "scripts": {
41
+ "build": "tsdown && vite build",
42
+ "test": "vitest run",
43
+ "typecheck": "tsc --noEmit"
44
+ }
6
45
  }
package/ui/ui.js ADDED
@@ -0,0 +1,70 @@
1
+ //#region src/tool-names.ts
2
+ /** Canonical names shared by tool registration and browser presentation. */
3
+ var TOOL_NAMES = ["user_ask", "user_set_participating"];
4
+ //#endregion
5
+ //#region src/ui/metadata.ts
6
+ var CATALOGUES = {
7
+ "en-US": {
8
+ section: "Built-in plugins",
9
+ group: "Human interaction",
10
+ user_ask: "Ask user",
11
+ user_set_participating: "Set user participation"
12
+ },
13
+ "zh-CN": {
14
+ section: "内置插件",
15
+ group: "人工交互",
16
+ user_ask: "询问用户",
17
+ user_set_participating: "设置用户参与"
18
+ }
19
+ };
20
+ var names = new Set(TOOL_NAMES);
21
+ /** Registers presentation facets with the same activation lifetime as the tools. */
22
+ function registerMetadata(ctx) {
23
+ ctx.i18n.register(CATALOGUES, "en-US");
24
+ ctx.i18n.contribute(Object.fromEntries(Object.entries(CATALOGUES).map(([language, catalogue]) => [language, Object.fromEntries([...names].map((tool) => [`transcript.actions.${tool}`, catalogue[tool] ?? tool]))])), "en-US");
25
+ ctx.slots.register("chat.tool.presentation", {
26
+ id: "tool-metadata",
27
+ describe: ({ call }) => {
28
+ if (!names.has(call.name)) return void 0;
29
+ const input = call.input !== null && typeof call.input === "object" ? call.input : {};
30
+ const summary = [
31
+ "path",
32
+ "url",
33
+ "query",
34
+ "command",
35
+ "skill",
36
+ "id",
37
+ "name",
38
+ "task",
39
+ "prompt"
40
+ ].flatMap((key) => typeof input[key] === "string" ? [input[key]] : []).slice(0, 2).join(" · ").replace(/\s+/g, " ").slice(0, 240);
41
+ return {
42
+ label: names.has(call.name) ? ctx.i18n.t(call.name) : call.name,
43
+ icon: "hammer",
44
+ summary
45
+ };
46
+ }
47
+ });
48
+ ctx.slots.register("shell.tools.group", {
49
+ id: "tool-groups",
50
+ describe: (tool) => {
51
+ if (tool.plugin !== ctx.plugin) return void 0;
52
+ return {
53
+ key: `plugin:${ctx.plugin}`,
54
+ label: ctx.i18n.t("group"),
55
+ source: ctx.plugin,
56
+ sectionLabel: ctx.i18n.t("section"),
57
+ sectionOrder: 1,
58
+ order: 4
59
+ };
60
+ }
61
+ });
62
+ }
63
+ //#endregion
64
+ //#region src/ui.tsx
65
+ var runtimeVersion = 5;
66
+ var register = (ctx) => {
67
+ registerMetadata(ctx);
68
+ };
69
+ //#endregion
70
+ export { register, runtimeVersion };
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.