@eum-agent/agent-delegation 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/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@eum-agent/agent-delegation",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "displayName": {
4
+ "en-US": "Subagent Delegation",
5
+ "zh-CN": "子智能体协作"
6
+ },
7
+ "version": "1.0.0",
8
+ "type": "module",
9
+ "description": "Delegated agent execution and subagent management",
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/plugin": "1.0.0",
26
+ "@types/react": "^19.2.18",
27
+ "@types/react-dom": "^19.2.5",
28
+ "vite": "^8.2.2",
29
+ "@eum-agent/protocol": "1.0.0",
30
+ "@eum-agent/kernel": "1.0.0",
31
+ "react": "^19.2.0",
32
+ "zustand": "^5.0.15",
33
+ "lucide-react": "^1.40.0"
34
+ },
35
+ "yaoguang": {
36
+ "description": {
37
+ "en-US": "Delegated agent execution and subagent management",
38
+ "zh-CN": "委派智能体执行任务与子智能体管理"
39
+ },
40
+ "dependencies": {
41
+ "@eum-agent/llm-management": "1.0.0"
42
+ },
43
+ "kind": "extension",
44
+ "foundationDependencies": {
45
+ "@eum-agent/storage-sqlite": "1.0.0"
46
+ }
47
+ },
48
+ "scripts": {
49
+ "build": "tsdown && vite build",
50
+ "test": "vitest run",
51
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.ui.json"
52
+ }
6
53
  }
package/ui/ui.js ADDED
@@ -0,0 +1,478 @@
1
+ import { Button, Field, FormFailure, InputNumber, ReadFailure, agentNamed, i18next, localeLeaves, pendingOf, useAgents, useGatewayAction, useInbox, useSessions, useToast, useTranslation } from "@eum-agent/host/framework";
2
+ import React, { useEffect, useRef, useState } from "react";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ //#region ui-src/locales/en-US.ts
5
+ /** Text owned by this browser capability. */
6
+ var catalogue$1 = { delegation: {
7
+ section: "Task delegation",
8
+ limits: "Runtime settings",
9
+ limitsHelp: "Each session a person starts shares these limits with the sessions it delegates to.",
10
+ saved: "Task delegation settings saved",
11
+ emptyHint: "Any agent can take delegated work; manage them in agent settings.",
12
+ description: "Description",
13
+ instructions: "Instructions",
14
+ concurrency: "Concurrent tasks per root session",
15
+ concurrencyHelp: "Counted per root session. Running tasks and tasks waiting for tools, approvals or child tasks occupy slots.",
16
+ depth: "Maximum nesting depth",
17
+ depthHelp: "Limits nested delegation. A task delegated straight from a session a person started is at depth 1.",
18
+ save: "Save",
19
+ parent: "Back to parent session",
20
+ unverified: "Parameter compatibility unverified",
21
+ title: "Subagents",
22
+ queued: "Queued",
23
+ starting: "Starting",
24
+ running: "Running",
25
+ "awaiting-human": "Waiting for approval",
26
+ stopping: "Stopping",
27
+ finished: "Finished",
28
+ stopTask: "Stop task",
29
+ stopTree: "Stop subtree",
30
+ viewSession: "View session",
31
+ main: "Main agent",
32
+ task: "Task",
33
+ back: "Back",
34
+ breadcrumb: "Run process levels",
35
+ followupPlaceholder: "Add a task for it — Enter sends, Shift+Enter starts a new line",
36
+ followup: "Follow-up"
37
+ } };
38
+ //#endregion
39
+ //#region ui-src/locales/zh-CN.ts
40
+ /** Text owned by this browser capability. */
41
+ var catalogue = { delegation: {
42
+ section: "任务委派",
43
+ limits: "运行设置",
44
+ limitsHelp: "每个人发起的会话及其委派出去的子会话,共享以下额度。",
45
+ saved: "任务委派设置已保存",
46
+ emptyHint: "任何智能体都可以接受委派,在智能体设置里管理它们。",
47
+ description: "简介",
48
+ instructions: "指令",
49
+ concurrency: "并发任务上限",
50
+ concurrencyHelp: "按主会话计数;运行中及等待工具、审批或下级任务的子任务均占名额。",
51
+ depth: "最大嵌套深度",
52
+ depthHelp: "限制逐级委派的层数;从人发起的会话直接委派出去的为第 1 层。",
53
+ save: "保存",
54
+ parent: "返回父会话",
55
+ unverified: "参数兼容性未验证",
56
+ title: "子代理",
57
+ queued: "排队中",
58
+ starting: "启动中",
59
+ running: "执行中",
60
+ "awaiting-human": "等待答复",
61
+ stopping: "停止中",
62
+ finished: "已结束",
63
+ stopTask: "停止当前任务",
64
+ stopTree: "停止整棵子树",
65
+ viewSession: "查看子会话",
66
+ main: "主智能体",
67
+ task: "任务",
68
+ back: "返回上一层",
69
+ breadcrumb: "运行过程层级",
70
+ followupPlaceholder: "给它追加任务,Enter 发送,Shift+Enter 换行",
71
+ followup: "追加任务"
72
+ } };
73
+ //#endregion
74
+ //#region src/tool-names.ts
75
+ /** Canonical names shared by tool registration and browser presentation. */
76
+ var TOOL_NAMES = [
77
+ "subagent_spawn",
78
+ "subagent_send",
79
+ "subagent_get",
80
+ "subagent_list",
81
+ "subagent_stop"
82
+ ];
83
+ //#endregion
84
+ //#region ui-src/metadata.ts
85
+ var CATALOGUES = {
86
+ "en-US": {
87
+ section: "Built-in plugins",
88
+ group: "Subagents",
89
+ parent: "Delegating agent",
90
+ subagent_spawn: "Create subagent",
91
+ subagent_send: "Send task",
92
+ subagent_get: "Inspect task",
93
+ subagent_list: "List subagents",
94
+ subagent_stop: "Stop task"
95
+ },
96
+ "zh-CN": {
97
+ section: "内置插件",
98
+ group: "子智能体",
99
+ parent: "上级智能体",
100
+ subagent_spawn: "创建子智能体",
101
+ subagent_send: "发送子任务",
102
+ subagent_get: "查看子任务",
103
+ subagent_list: "查看子智能体",
104
+ subagent_stop: "停止子任务"
105
+ }
106
+ };
107
+ var names = new Set(TOOL_NAMES);
108
+ /** Registers presentation facets with the same activation lifetime as the tools. */
109
+ function registerMetadata(ctx) {
110
+ ctx.i18n.register(CATALOGUES, "en-US");
111
+ 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");
112
+ ctx.slots.register("chat.tool.presentation", {
113
+ id: "tool-metadata",
114
+ describe: ({ call }) => {
115
+ if (!names.has(call.name)) return void 0;
116
+ const input = call.input !== null && typeof call.input === "object" ? call.input : {};
117
+ const summary = [
118
+ "path",
119
+ "url",
120
+ "query",
121
+ "command",
122
+ "skill",
123
+ "id",
124
+ "name",
125
+ "task",
126
+ "prompt"
127
+ ].flatMap((key) => typeof input[key] === "string" ? [input[key]] : []).slice(0, 2).join(" · ").replace(/\s+/g, " ").slice(0, 240);
128
+ return {
129
+ label: names.has(call.name) ? ctx.i18n.t(call.name) : call.name,
130
+ icon: "hammer",
131
+ summary
132
+ };
133
+ }
134
+ });
135
+ ctx.slots.register("shell.tools.group", {
136
+ id: "tool-groups",
137
+ sourceLabel: ({ kind }) => kind === "delegation-task" ? ctx.i18n.t("parent") : kind === "delegation-result" ? ctx.i18n.t("group") : void 0,
138
+ describe: (tool) => {
139
+ if (tool.plugin !== ctx.plugin) return void 0;
140
+ return {
141
+ key: `plugin:${ctx.plugin}`,
142
+ label: ctx.i18n.t("group"),
143
+ source: ctx.plugin,
144
+ sectionLabel: ctx.i18n.t("section"),
145
+ sectionOrder: 1,
146
+ order: 7
147
+ };
148
+ }
149
+ });
150
+ }
151
+ //#endregion
152
+ //#region ui-src/components/settings/subagents.tsx
153
+ /** Delegation limits edited and saved independently inside global running settings. */
154
+ function DelegationSettingsSection({ ctx, registerGuard }) {
155
+ const { t } = useTranslation();
156
+ const toast = useToast();
157
+ const [online, setOnline] = useState(ctx.gateway.connection.status === "online");
158
+ useEffect(() => ctx.gateway.watchConnection((state) => setOnline(state.status === "online")), [ctx]);
159
+ const [data, setData] = useState(null);
160
+ const [error, setError] = useState(null);
161
+ const [pending, setPending] = useState(true);
162
+ const reading = useRef(false);
163
+ const reload = () => {
164
+ if (reading.current) return;
165
+ reading.current = true;
166
+ setPending(true);
167
+ setError(null);
168
+ ctx.invoke("getSettings", {}).then(setData).catch((error) => setError(error instanceof Error ? error.message : String(error))).finally(() => {
169
+ reading.current = false;
170
+ setPending(false);
171
+ });
172
+ };
173
+ useEffect(reload, [ctx]);
174
+ const read = {
175
+ data,
176
+ error,
177
+ reload
178
+ };
179
+ const save = useGatewayAction();
180
+ const [draft, setDraft] = useState(null);
181
+ const settings = draft ?? read.data;
182
+ const guardState = useRef({
183
+ dirty: false,
184
+ pending: false
185
+ });
186
+ guardState.current = {
187
+ dirty: draft !== null && JSON.stringify(draft) !== JSON.stringify(read.data),
188
+ pending: save.pending
189
+ };
190
+ useEffect(() => {
191
+ registerGuard(() => guardState.current);
192
+ return () => registerGuard(null);
193
+ }, [registerGuard]);
194
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(ReadFailure, {
195
+ reason: read.error,
196
+ pending,
197
+ onRetry: read.reload
198
+ }), settings && /* @__PURE__ */ jsxs("form", {
199
+ className: "flex flex-col gap-6",
200
+ onSubmit: (event) => {
201
+ event.preventDefault();
202
+ if (save.pending) return;
203
+ save.run(() => ctx.invoke("setSettings", settings)).then((done) => {
204
+ if (!done.ok) return;
205
+ toast.add({
206
+ tone: "success",
207
+ title: t("delegation.saved")
208
+ });
209
+ setData(settings);
210
+ setDraft(null);
211
+ });
212
+ },
213
+ children: [
214
+ /* @__PURE__ */ jsx("p", {
215
+ className: "text-xs text-muted-foreground",
216
+ children: t("delegation.limitsHelp")
217
+ }),
218
+ ["maxConcurrent", "maxDepth"].map((key) => /* @__PURE__ */ jsx(Field, {
219
+ label: t(key === "maxConcurrent" ? "delegation.concurrency" : "delegation.depth"),
220
+ help: t(key === "maxConcurrent" ? "delegation.concurrencyHelp" : "delegation.depthHelp"),
221
+ required: true,
222
+ inline: true,
223
+ className: "delegation-limit-field",
224
+ children: (binding) => /* @__PURE__ */ jsx(InputNumber, {
225
+ ...binding,
226
+ label: t(key === "maxConcurrent" ? "delegation.concurrency" : "delegation.depth"),
227
+ incrementLabel: t("common.increase"),
228
+ decrementLabel: t("common.decrease"),
229
+ min: 1,
230
+ step: 1,
231
+ required: true,
232
+ disabled: save.pending,
233
+ value: settings[key] || null,
234
+ onValueChange: (value) => setDraft({
235
+ ...settings,
236
+ [key]: value ?? 0
237
+ })
238
+ })
239
+ }, key)),
240
+ /* @__PURE__ */ jsx(FormFailure, { reason: save.error }),
241
+ /* @__PURE__ */ jsx("div", {
242
+ className: "flex justify-end gap-2",
243
+ children: /* @__PURE__ */ jsx(Button, {
244
+ variant: "primary",
245
+ type: "submit",
246
+ loading: save.pending,
247
+ disabled: pending || !Number.isSafeInteger(settings.maxConcurrent) || settings.maxConcurrent < 1 || !Number.isSafeInteger(settings.maxDepth) || settings.maxDepth < 1 || !online,
248
+ children: t("common.save")
249
+ })
250
+ })
251
+ ]
252
+ })] });
253
+ }
254
+ //#endregion
255
+ //#region ui-src/lib/subagents/task.ts
256
+ /** The two tools whose answer is the task they handed a child. */
257
+ var DISPATCHING = /* @__PURE__ */ new Set(["subagent_spawn", "subagent_send"]);
258
+ /** The task a finished call started: `subagent_spawn` and `subagent_send`
259
+ * answer with the accepted task as JSON. Anything else starts none. */
260
+ function dispatchedBy(name, output) {
261
+ if (!DISPATCHING.has(name) || output === void 0) return null;
262
+ try {
263
+ const task = JSON.parse(output);
264
+ return typeof task.taskId === "string" && typeof task.childSessionId === "string" ? {
265
+ taskId: task.taskId,
266
+ childSessionId: task.childSessionId
267
+ } : null;
268
+ } catch {
269
+ return null;
270
+ }
271
+ }
272
+ /** A task's STATE column: at work, waiting for a person, or how it ended. */
273
+ function taskLineState(task) {
274
+ if (task.state === "awaiting-human") return "waiting";
275
+ if (task.state !== "finished") return "running";
276
+ if (task.outcome?.kind === "failed") return "failed";
277
+ return task.outcome?.kind === "interrupted" ? "stopped" : "success";
278
+ }
279
+ /** The catalogue key naming where a task stands. */
280
+ function taskStateKey(task) {
281
+ if (task.state !== "finished") return `delegation.${task.state}`;
282
+ if (task.outcome?.kind === "failed") return "sessionState.failed";
283
+ return task.outcome?.kind === "interrupted" ? "sessionState.halted" : "sessionState.done";
284
+ }
285
+ //#endregion
286
+ //#region ../../../node_modules/.pnpm/zustand@5.0.15_@types+react@19.2.18_react@19.2.8_use-sync-external-store@1.7.0_react@19.2.8_/node_modules/zustand/esm/vanilla.mjs
287
+ var createStoreImpl = (createState) => {
288
+ let state;
289
+ const listeners = /* @__PURE__ */ new Set();
290
+ const setState = (partial, replace) => {
291
+ const nextState = typeof partial === "function" ? partial(state) : partial;
292
+ if (!Object.is(nextState, state)) {
293
+ const previousState = state;
294
+ state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
295
+ listeners.forEach((listener) => listener(state, previousState));
296
+ }
297
+ };
298
+ const getState = () => state;
299
+ const getInitialState = () => initialState;
300
+ const subscribe = (listener) => {
301
+ listeners.add(listener);
302
+ return () => listeners.delete(listener);
303
+ };
304
+ const api = {
305
+ setState,
306
+ getState,
307
+ getInitialState,
308
+ subscribe
309
+ };
310
+ const initialState = state = createState(setState, getState, api);
311
+ return api;
312
+ };
313
+ var createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
314
+ //#endregion
315
+ //#region ../../../node_modules/.pnpm/zustand@5.0.15_@types+react@19.2.18_react@19.2.8_use-sync-external-store@1.7.0_react@19.2.8_/node_modules/zustand/esm/react.mjs
316
+ var identity = (arg) => arg;
317
+ function useStore(api, selector = identity) {
318
+ const slice = React.useSyncExternalStore(api.subscribe, React.useCallback(() => selector(api.getState()), [api, selector]), React.useCallback(() => selector(api.getInitialState()), [api, selector]));
319
+ React.useDebugValue(slice);
320
+ return slice;
321
+ }
322
+ var createImpl = (createState) => {
323
+ const api = createStore(createState);
324
+ const useBoundStore = (selector) => useStore(api, selector);
325
+ Object.assign(useBoundStore, api);
326
+ return useBoundStore;
327
+ };
328
+ var create = ((createState) => createState ? createImpl(createState) : createImpl);
329
+ //#endregion
330
+ //#region ui-src/store/subagents.ts
331
+ var useSubagents = create()((set) => ({
332
+ bySession: {},
333
+ loaded: {},
334
+ clear: () => set({
335
+ bySession: {},
336
+ loaded: {}
337
+ }),
338
+ merge: (sessionId, rows) => set((state) => {
339
+ const tasks = { ...state.bySession[sessionId] };
340
+ for (const row of rows) if ((tasks[row.taskId]?.revision ?? -1) < row.revision) tasks[row.taskId] = row;
341
+ return {
342
+ bySession: {
343
+ ...state.bySession,
344
+ [sessionId]: tasks
345
+ },
346
+ loaded: {
347
+ ...state.loaded,
348
+ [sessionId]: true
349
+ }
350
+ };
351
+ })
352
+ }));
353
+ /** Reads each observed parent once and refreshes its retained view after reconnect. */
354
+ function nativeTaskReader(ctx) {
355
+ const reading = /* @__PURE__ */ new Set();
356
+ const observed = /* @__PURE__ */ new Set();
357
+ const read = (sessionId) => {
358
+ if (reading.has(sessionId) || ctx.signal.aborted) return;
359
+ reading.add(sessionId);
360
+ ctx.invoke("list", { parentSessionId: sessionId }).then((rows) => {
361
+ if (!ctx.signal.aborted) useSubagents.getState().merge(sessionId, rows);
362
+ }).catch(() => {}).finally(() => reading.delete(sessionId));
363
+ };
364
+ ctx.on("changed", ({ sessionId, payload }) => {
365
+ if (sessionId !== void 0) useSubagents.getState().merge(sessionId, [payload.task]);
366
+ });
367
+ let online = ctx.host.get().connection === "online";
368
+ const off = ctx.host.subscribe(() => {
369
+ const next = ctx.host.get().connection === "online";
370
+ if (next && !online) for (const sessionId of observed) read(sessionId);
371
+ online = next;
372
+ });
373
+ ctx.signal.addEventListener("abort", () => {
374
+ off();
375
+ useSubagents.getState().clear();
376
+ }, { once: true });
377
+ return (sessionId) => {
378
+ if (observed.has(sessionId)) return;
379
+ observed.add(sessionId);
380
+ queueMicrotask(() => read(sessionId));
381
+ };
382
+ }
383
+ //#endregion
384
+ //#region ui-src/index.tsx
385
+ var runtimeVersion = 5;
386
+ var provides = ["related-session:actions"];
387
+ var register = (ctx) => {
388
+ ctx.i18n.contribute({
389
+ "en-US": localeLeaves(catalogue$1),
390
+ "zh-CN": localeLeaves(catalogue)
391
+ }, "en-US");
392
+ registerMetadata(ctx);
393
+ const observe = nativeTaskReader(ctx);
394
+ ctx.services.provide("related-session:actions", { send: (input) => ctx.invoke("send", input) });
395
+ ctx.slots.register("shell.agentRunSettings.section", {
396
+ id: "delegation",
397
+ label: () => i18next.t("delegation.section"),
398
+ order: 10,
399
+ component: (props) => /* @__PURE__ */ jsx(DelegationSettingsSection, {
400
+ ctx,
401
+ ...props
402
+ })
403
+ });
404
+ const subscribe = (listener) => {
405
+ const off = [
406
+ useSubagents.subscribe(listener),
407
+ useAgents.subscribe(listener),
408
+ useInbox.subscribe(listener),
409
+ useSessions.subscribe(listener),
410
+ ctx.host.subscribe(listener)
411
+ ];
412
+ return () => {
413
+ for (const dispose of off) dispose();
414
+ };
415
+ };
416
+ ctx.slots.register("chat.tool.presentation", {
417
+ id: "tasks",
418
+ subscribe,
419
+ describe: ({ call, result, sessionId, openRelated }) => {
420
+ if (sessionId === void 0 || openRelated === void 0) return void 0;
421
+ const ref = dispatchedBy(call.name, result?.content);
422
+ if (!ref) return void 0;
423
+ observe(sessionId);
424
+ const task = useSubagents.getState().bySession[sessionId]?.[ref.taskId];
425
+ if (!task) return void 0;
426
+ const agent = agentNamed(useAgents.getState(), task.agent) ?? task.agent;
427
+ const child = {
428
+ childSessionId: task.childSessionId,
429
+ parentSessionId: sessionId,
430
+ agent,
431
+ task: task.input
432
+ };
433
+ const sessions = useSessions.getState().sessions;
434
+ const under = (id) => {
435
+ const seen = /* @__PURE__ */ new Set();
436
+ let at = id;
437
+ while (at !== void 0 && !seen.has(at)) {
438
+ if (at === task.childSessionId) return true;
439
+ seen.add(at);
440
+ at = sessions.find((one) => one.sessionId === at)?.parentSessionId;
441
+ }
442
+ return false;
443
+ };
444
+ const pending = pendingOf(useInbox.getState().items).filter((one) => under(one.sessionId));
445
+ const request = ctx.services.get("chat:pending-request");
446
+ const state = taskLineState(task);
447
+ return { relatedSession: {
448
+ taskId: task.taskId,
449
+ agent,
450
+ title: task.input.replace(/\s+/g, " ").slice(0, 80),
451
+ groupLabel: i18next.t("transcript.run.subagents"),
452
+ state,
453
+ stateLabel: i18next.t(taskStateKey(task)),
454
+ onOpen: () => openRelated(child),
455
+ ops: [...task.state === "finished" ? [] : [{
456
+ icon: "stop",
457
+ label: i18next.t("delegation.stopTask"),
458
+ disabled: task.state === "stopping" || ctx.host.get().connection !== "online",
459
+ onClick: async () => {
460
+ await ctx.invoke("stop", {
461
+ parentSessionId: sessionId,
462
+ childSessionId: task.childSessionId,
463
+ scope: "task",
464
+ taskId: task.taskId
465
+ });
466
+ }
467
+ }], {
468
+ icon: "open",
469
+ label: i18next.t("delegation.viewSession"),
470
+ onClick: () => openRelated(child)
471
+ }],
472
+ ...request === void 0 || pending.length === 0 ? {} : { requests: pending.map((one) => /* @__PURE__ */ jsx(request.component, { pending: one }, one.request.requestId)) }
473
+ } };
474
+ }
475
+ });
476
+ };
477
+ //#endregion
478
+ export { provides, 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.