@eum-agent/human-interaction 0.0.0-stage → 1.0.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 ADDED
@@ -0,0 +1,159 @@
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/ask-user/ask.ts
21
+ 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.")
24
+ });
25
+ 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."),
30
+ allow_free_text: z.boolean().optional().describe("Whether the person may type an answer instead of picking an option. Default true."),
31
+ allow_multiple: z.boolean().optional().describe("Whether the person may pick several options. Default false.")
32
+ });
33
+ const AskInput = z.object({ questions: z.array(Question).min(1).describe("One or more questions, shown together.") });
34
+ /** Option ids are the labels: a person picks by label, and the model reads
35
+ * the label back — no second vocabulary to keep in step. */
36
+ function toAsk(input) {
37
+ return {
38
+ kind: "question",
39
+ questions: input.questions.map((q) => ({
40
+ id: q.id,
41
+ text: q.header === void 0 ? q.question : `${q.header}\n${q.question}`,
42
+ options: (q.options ?? []).map((o) => ({
43
+ id: o.label,
44
+ label: o.label,
45
+ ...o.description === void 0 ? {} : { description: o.description }
46
+ })),
47
+ freeText: q.allow_free_text ?? true,
48
+ ...q.allow_multiple === true ? { multiple: true } : {}
49
+ }))
50
+ };
51
+ }
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
+ function askUserQuestionTool() {
66
+ return {
67
+ name: "user_ask",
68
+ 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 {\"answers\":[{\"id\",\"selected\":[label],\"custom\"?}]}. Keep questions concise and self-contained. Set allow_multiple to let the person pick several options; selected then lists every one they picked. The person can always type a free-text answer unless allow_free_text is false; do not add an \"Other\" option.",
69
+ inputSchema: AskInput,
70
+ async execute(input, ctx) {
71
+ if (ctx.answer === void 0) return { awaitHuman: toAsk(input) };
72
+ return { content: JSON.stringify({ answers: toAnswers(ctx.answer) }) };
73
+ }
74
+ };
75
+ }
76
+ //#endregion
77
+ //#region src/ask-user/index.ts
78
+ function registerAskUserTools(_ctx, register) {
79
+ register(askUserQuestionTool());
80
+ }
81
+ //#endregion
82
+ //#region src/participants/index.ts
83
+ const PARTICIPANTS_SERVICE = "session-participants";
84
+ const ParticipatingInput = z.object({
85
+ participating: z.boolean(),
86
+ reason: z.string().trim().max(500).optional()
87
+ }).superRefine((input, issues) => {
88
+ if (input.participating && !input.reason) issues.addIssue({
89
+ code: "custom",
90
+ path: ["reason"],
91
+ message: "bringing the user in needs the reason they will read"
92
+ });
93
+ });
94
+ function inviteText(result) {
95
+ switch (result.kind) {
96
+ case "changed": return "the user was added to this session";
97
+ case "unchanged": return "the user is already in this session";
98
+ case "refused": return "the user created this session and is always in it";
99
+ }
100
+ }
101
+ function dismissText(result) {
102
+ switch (result.kind) {
103
+ case "changed": return "the user was removed from this session";
104
+ case "unchanged": return "the user was not in this session";
105
+ case "refused": return "the user created this session and cannot be removed";
106
+ }
107
+ }
108
+ function failure(error) {
109
+ return {
110
+ content: error instanceof Error ? error.message : String(error),
111
+ isError: true
112
+ };
113
+ }
114
+ function participatingTool(participants) {
115
+ return {
116
+ name: "user_set_participating",
117
+ 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
+ inputSchema: ParticipatingInput,
119
+ async execute(input, ctx) {
120
+ try {
121
+ if (input.participating) return { content: inviteText(await participants.invite(ctx, input.reason ?? "")) };
122
+ const reason = input.reason === "" ? void 0 : input.reason;
123
+ return { content: dismissText(await participants.dismiss(ctx, reason)) };
124
+ } catch (error) {
125
+ return failure(error);
126
+ }
127
+ }
128
+ };
129
+ }
130
+ function registerParticipantTools(ctx, register) {
131
+ register(participatingTool(ctx.services.get(PARTICIPANTS_SERVICE)));
132
+ }
133
+ //#endregion
134
+ //#region src/index.ts
135
+ /**
136
+ * This plugin's slice of `config.json`.
137
+ *
138
+ * `disabled` turns one tool off while the rest of the package stays on —
139
+ * `enabled: false` on the declaration turns off every one of them. Strict and
140
+ * enumerated: a misspelled tool name is a load failure naming the field, not
141
+ * a line that quietly does nothing.
142
+ */
143
+ const HitlConfig = z.strictObject({ disabled: z.array(z.enum(TOOL_NAMES)).default([]) }).default({ disabled: [] });
144
+ const hitlPlugin = {
145
+ name: "@eum-agent/human-interaction",
146
+ requires: ["session-participants"],
147
+ configSchema: HitlConfig,
148
+ apply(ctx, config) {
149
+ const module = fileURLToPath(new URL("../ui/ui.js", import.meta.url));
150
+ if (existsSync(module)) ctx.client.registerUi({ module });
151
+ const disabled = new Set(config.disabled);
152
+ const register = (tool) => disabled.has(tool.name) ? void 0 : ctx.tools.register(tool);
153
+ registerAskUserTools(ctx, register);
154
+ registerParticipantTools(ctx, register);
155
+ ctx.tools.guide(GUIDANCE);
156
+ }
157
+ };
158
+ //#endregion
159
+ 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.0",
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.0",
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.0"
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.