@fungi.computer/shiitake-extensions 0.6.5 → 0.6.7
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/README.md +30 -17
- package/dist/goal/client.js +6 -2
- package/dist/goal/contract.d.ts +98 -10
- package/dist/goal/contract.js +50 -1
- package/dist/goal/host.js +68 -13
- package/dist/goal/prompts.js +1 -0
- package/dist/question/client.js +13 -2
- package/dist/question/contract.d.ts +70 -4
- package/dist/question/contract.js +14 -2
- package/dist/question/host.js +224 -122
- package/dist/subagents/client.js +28 -10
- package/dist/subagents/contract.d.ts +93 -0
- package/dist/subagents/contract.js +49 -0
- package/dist/subagents/host.d.ts +3 -3
- package/dist/subagents/host.js +77 -14
- package/dist/subagents/presentation.d.ts +4 -0
- package/dist/subagents/presentation.js +9 -0
- package/docs/api/goal/contract.md +35 -26
- package/docs/api/question/contract.md +62 -30
- package/docs/api/subagents/contract.md +51 -14
- package/docs/api/subagents/host.md +4 -4
- package/package.json +6 -6
package/dist/subagents/client.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineClientEntry, } from "@fungi.computer/shiitake/client-entry";
|
|
2
2
|
import { subagentsContract, } from "./contract.js";
|
|
3
|
+
import { escalationLabel } from "./presentation.js";
|
|
3
4
|
const presentation = {
|
|
4
5
|
working: { label: "working", tone: "running", status: "info" },
|
|
5
6
|
waiting_on_agent: { label: "waiting", tone: "muted", status: "neutral" },
|
|
@@ -10,9 +11,11 @@ const presentation = {
|
|
|
10
11
|
};
|
|
11
12
|
/** "waiting on Shiitake": the Agent a calm child waits on, never "you". */
|
|
12
13
|
function label(agent) {
|
|
13
|
-
|
|
14
|
+
const state = agent.state === "waiting_on_agent"
|
|
14
15
|
? `waiting on ${agent.waitingOn ?? "its parent"}`
|
|
15
16
|
: presentation[agent.state].label;
|
|
17
|
+
const reason = escalationLabel(agent.escalated);
|
|
18
|
+
return reason === undefined ? state : `${state} · ${reason}`;
|
|
16
19
|
}
|
|
17
20
|
function row(agent) {
|
|
18
21
|
const shown = presentation[agent.state];
|
|
@@ -67,12 +70,17 @@ function row(agent) {
|
|
|
67
70
|
* hides an Agent waiting on them.
|
|
68
71
|
*/
|
|
69
72
|
function summary(view) {
|
|
70
|
-
const count = (state) => view.
|
|
71
|
-
const calm = view.agents.filter((agent) => agent.state === "waiting_on_agent");
|
|
73
|
+
const count = (state) => view.counts[state];
|
|
72
74
|
// Calm children name who they wait on; only needs-you children are amber.
|
|
73
|
-
const waiting =
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
const waiting = view.waitingOn.map(({ name, count: n }) => `${String(n)} waiting on ${name}`);
|
|
76
|
+
const reasons = view.escalatedBy.map(({ name, reason, count: n }) => {
|
|
77
|
+
const label = escalationLabel({ by: name, reason });
|
|
78
|
+
return view.escalated === count("needs_you") &&
|
|
79
|
+
view.escalatedBy.length === 1
|
|
80
|
+
? label
|
|
81
|
+
: `${String(n)} ${label}`;
|
|
82
|
+
});
|
|
83
|
+
const needsLabel = reasons.length === 0 ? "needs you" : `needs you (${reasons.join("; ")})`;
|
|
76
84
|
const counts = [
|
|
77
85
|
...["working"]
|
|
78
86
|
.map((state) => [state, count(state)])
|
|
@@ -82,9 +90,9 @@ function summary(view) {
|
|
|
82
90
|
...["needs_you", "failed", "unavailable"]
|
|
83
91
|
.map((state) => [state, count(state)])
|
|
84
92
|
.filter(([, n]) => n > 0)
|
|
85
|
-
.map(([state, n]) => `${String(n)} ${presentation[state].label}`),
|
|
93
|
+
.map(([state, n]) => `${String(n)} ${state === "needs_you" ? needsLabel : presentation[state].label}`),
|
|
86
94
|
];
|
|
87
|
-
const total =
|
|
95
|
+
const total = count("working") + count("needs_you");
|
|
88
96
|
const tone = count("needs_you") > 0
|
|
89
97
|
? "attention"
|
|
90
98
|
: count("failed") > 0
|
|
@@ -97,6 +105,7 @@ function summary(view) {
|
|
|
97
105
|
title: [
|
|
98
106
|
`${String(total)} sub-agent${total === 1 ? "" : "s"}`,
|
|
99
107
|
...counts,
|
|
108
|
+
...(view.uncounted > 0 ? [`${String(view.uncounted)} not read`] : []),
|
|
100
109
|
"/agents shows them",
|
|
101
110
|
].join(" · "),
|
|
102
111
|
tone,
|
|
@@ -112,12 +121,21 @@ export default defineClientEntry(subagentsContract, {
|
|
|
112
121
|
? [summary(view.value)]
|
|
113
122
|
: [
|
|
114
123
|
...view.value.agents.map(row),
|
|
115
|
-
...(view.value.more === 0
|
|
124
|
+
...(view.value.more === 0 && view.value.uncounted === 0
|
|
116
125
|
? []
|
|
117
126
|
: [
|
|
118
127
|
{
|
|
119
128
|
id: "more",
|
|
120
|
-
title:
|
|
129
|
+
title: [
|
|
130
|
+
...(view.value.more === 0
|
|
131
|
+
? []
|
|
132
|
+
: [
|
|
133
|
+
`${String(view.value.more)} more sub-agent${view.value.more === 1 ? "" : "s"}`,
|
|
134
|
+
]),
|
|
135
|
+
...(view.value.uncounted === 0
|
|
136
|
+
? []
|
|
137
|
+
: [`${String(view.value.uncounted)} not read`]),
|
|
138
|
+
].join(" · "),
|
|
121
139
|
tone: "muted",
|
|
122
140
|
},
|
|
123
141
|
]),
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as Schema from "effect/Schema";
|
|
2
2
|
/** The most Agents one conversation's footer lists; the rest are counted. */
|
|
3
3
|
export declare const maximumSubagents = 16;
|
|
4
|
+
/** Private status-read ceiling; children past it are explicitly not read. */
|
|
5
|
+
export declare const maximumCountedSubagents = 256;
|
|
4
6
|
/**
|
|
5
7
|
* What the human sees for one ordinary created Agent. `waiting_on_agent` is an
|
|
6
8
|
* open question that waits on the Agent that sent the work, calm until it is
|
|
@@ -24,6 +26,13 @@ export declare const Subagent: Schema.Struct<{
|
|
|
24
26
|
readonly attention: Schema.optionalKey<Schema.String>;
|
|
25
27
|
/** Display name of the Agent a `waiting_on_agent` child waits on. */
|
|
26
28
|
readonly waitingOn: Schema.optionalKey<Schema.String>;
|
|
29
|
+
/** Why the routed child now waits here, without losing the escalating Agent. */
|
|
30
|
+
readonly escalated: Schema.optionalKey<Schema.Struct<{
|
|
31
|
+
/** Escalator's name, or the gone recipient's name on automatic promotion. */
|
|
32
|
+
readonly by: Schema.String;
|
|
33
|
+
/** Explicit handoff or positive evidence that the prior recipient is gone. */
|
|
34
|
+
readonly reason: Schema.Literals<readonly ["escalated", "sender_archived", "sender_absent"]>;
|
|
35
|
+
}>>;
|
|
27
36
|
/** The question a waiting child asks, so a person can answer from here. */
|
|
28
37
|
readonly ask: Schema.optionalKey<Schema.Struct<{
|
|
29
38
|
/** Durable identity of the child's open Ask. */
|
|
@@ -63,6 +72,13 @@ export declare const SubagentsProjection: Schema.Struct<{
|
|
|
63
72
|
readonly attention: Schema.optionalKey<Schema.String>;
|
|
64
73
|
/** Display name of the Agent a `waiting_on_agent` child waits on. */
|
|
65
74
|
readonly waitingOn: Schema.optionalKey<Schema.String>;
|
|
75
|
+
/** Why the routed child now waits here, without losing the escalating Agent. */
|
|
76
|
+
readonly escalated: Schema.optionalKey<Schema.Struct<{
|
|
77
|
+
/** Escalator's name, or the gone recipient's name on automatic promotion. */
|
|
78
|
+
readonly by: Schema.String;
|
|
79
|
+
/** Explicit handoff or positive evidence that the prior recipient is gone. */
|
|
80
|
+
readonly reason: Schema.Literals<readonly ["escalated", "sender_archived", "sender_absent"]>;
|
|
81
|
+
}>>;
|
|
66
82
|
/** The question a waiting child asks, so a person can answer from here. */
|
|
67
83
|
readonly ask: Schema.optionalKey<Schema.Struct<{
|
|
68
84
|
/** Durable identity of the child's open Ask. */
|
|
@@ -82,6 +98,41 @@ export declare const SubagentsProjection: Schema.Struct<{
|
|
|
82
98
|
}>>;
|
|
83
99
|
/** Additional created Agents not included in the visible rows. */
|
|
84
100
|
readonly more: Schema.Int;
|
|
101
|
+
/** Children beyond the status-read ceiling, never counted as idle. */
|
|
102
|
+
readonly uncounted: Schema.Int;
|
|
103
|
+
/** Totals read across every child, before the visible row limit. */
|
|
104
|
+
readonly counts: Schema.Struct<{
|
|
105
|
+
/** Read children still working. */
|
|
106
|
+
readonly working: Schema.Int;
|
|
107
|
+
/** Read children waiting on an Agent, never counted as needing a person. */
|
|
108
|
+
readonly waiting_on_agent: Schema.Int;
|
|
109
|
+
/** Read children whose decision waits on a person. */
|
|
110
|
+
readonly needs_you: Schema.Int;
|
|
111
|
+
/** Read children with no current work or decision. */
|
|
112
|
+
readonly idle: Schema.Int;
|
|
113
|
+
/** Read children whose work failed. */
|
|
114
|
+
readonly failed: Schema.Int;
|
|
115
|
+
/** Children whose status read failed, never counted as idle. */
|
|
116
|
+
readonly unavailable: Schema.Int;
|
|
117
|
+
}>;
|
|
118
|
+
/** Of those needing a person, how many arrived by escalation. */
|
|
119
|
+
readonly escalated: Schema.Int;
|
|
120
|
+
/** Every waiting recipient, including children beyond the visible rows. */
|
|
121
|
+
readonly waitingOn: Schema.$Array<Schema.Struct<{
|
|
122
|
+
/** Display name of the Agent receiving these decisions. */
|
|
123
|
+
readonly name: Schema.String;
|
|
124
|
+
/** Read children waiting on this recipient name. */
|
|
125
|
+
readonly count: Schema.Int;
|
|
126
|
+
}>>;
|
|
127
|
+
/** Every escalator of a person-bound item, for an accurate collapsed label. */
|
|
128
|
+
readonly escalatedBy: Schema.$Array<Schema.Struct<{
|
|
129
|
+
/** Display name retained by these escalations. */
|
|
130
|
+
readonly name: Schema.String;
|
|
131
|
+
/** Explicit handoff or automatic promotion, preserved in the summary. */
|
|
132
|
+
readonly reason: Schema.Literals<readonly ["escalated", "sender_archived", "sender_absent"]>;
|
|
133
|
+
/** Read person-bound children with this parent name and reason. */
|
|
134
|
+
readonly count: Schema.Int;
|
|
135
|
+
}>>;
|
|
85
136
|
/** Whether individual rows are expanded instead of summarized. */
|
|
86
137
|
readonly expanded: Schema.Boolean;
|
|
87
138
|
}>;
|
|
@@ -179,6 +230,13 @@ export declare const subagentsContract: {
|
|
|
179
230
|
readonly attention: Schema.optionalKey<Schema.String>;
|
|
180
231
|
/** Display name of the Agent a `waiting_on_agent` child waits on. */
|
|
181
232
|
readonly waitingOn: Schema.optionalKey<Schema.String>;
|
|
233
|
+
/** Why the routed child now waits here, without losing the escalating Agent. */
|
|
234
|
+
readonly escalated: Schema.optionalKey<Schema.Struct<{
|
|
235
|
+
/** Escalator's name, or the gone recipient's name on automatic promotion. */
|
|
236
|
+
readonly by: Schema.String;
|
|
237
|
+
/** Explicit handoff or positive evidence that the prior recipient is gone. */
|
|
238
|
+
readonly reason: Schema.Literals<readonly ["escalated", "sender_archived", "sender_absent"]>;
|
|
239
|
+
}>>;
|
|
182
240
|
/** The question a waiting child asks, so a person can answer from here. */
|
|
183
241
|
readonly ask: Schema.optionalKey<Schema.Struct<{
|
|
184
242
|
/** Durable identity of the child's open Ask. */
|
|
@@ -198,6 +256,41 @@ export declare const subagentsContract: {
|
|
|
198
256
|
}>>;
|
|
199
257
|
/** Additional created Agents not included in the visible rows. */
|
|
200
258
|
readonly more: Schema.Int;
|
|
259
|
+
/** Children beyond the status-read ceiling, never counted as idle. */
|
|
260
|
+
readonly uncounted: Schema.Int;
|
|
261
|
+
/** Totals read across every child, before the visible row limit. */
|
|
262
|
+
readonly counts: Schema.Struct<{
|
|
263
|
+
/** Read children still working. */
|
|
264
|
+
readonly working: Schema.Int;
|
|
265
|
+
/** Read children waiting on an Agent, never counted as needing a person. */
|
|
266
|
+
readonly waiting_on_agent: Schema.Int;
|
|
267
|
+
/** Read children whose decision waits on a person. */
|
|
268
|
+
readonly needs_you: Schema.Int;
|
|
269
|
+
/** Read children with no current work or decision. */
|
|
270
|
+
readonly idle: Schema.Int;
|
|
271
|
+
/** Read children whose work failed. */
|
|
272
|
+
readonly failed: Schema.Int;
|
|
273
|
+
/** Children whose status read failed, never counted as idle. */
|
|
274
|
+
readonly unavailable: Schema.Int;
|
|
275
|
+
}>;
|
|
276
|
+
/** Of those needing a person, how many arrived by escalation. */
|
|
277
|
+
readonly escalated: Schema.Int;
|
|
278
|
+
/** Every waiting recipient, including children beyond the visible rows. */
|
|
279
|
+
readonly waitingOn: Schema.$Array<Schema.Struct<{
|
|
280
|
+
/** Display name of the Agent receiving these decisions. */
|
|
281
|
+
readonly name: Schema.String;
|
|
282
|
+
/** Read children waiting on this recipient name. */
|
|
283
|
+
readonly count: Schema.Int;
|
|
284
|
+
}>>;
|
|
285
|
+
/** Every escalator of a person-bound item, for an accurate collapsed label. */
|
|
286
|
+
readonly escalatedBy: Schema.$Array<Schema.Struct<{
|
|
287
|
+
/** Display name retained by these escalations. */
|
|
288
|
+
readonly name: Schema.String;
|
|
289
|
+
/** Explicit handoff or automatic promotion, preserved in the summary. */
|
|
290
|
+
readonly reason: Schema.Literals<readonly ["escalated", "sender_archived", "sender_absent"]>;
|
|
291
|
+
/** Read person-bound children with this parent name and reason. */
|
|
292
|
+
readonly count: Schema.Int;
|
|
293
|
+
}>>;
|
|
201
294
|
/** Whether individual rows are expanded instead of summarized. */
|
|
202
295
|
readonly expanded: Schema.Boolean;
|
|
203
296
|
}>;
|
|
@@ -3,8 +3,15 @@ import * as Schema from "effect/Schema";
|
|
|
3
3
|
import { CatalogStep } from "../internal/catalog.js";
|
|
4
4
|
import { AnswerFlowInput, Questions } from "../question/contract.js";
|
|
5
5
|
const identity = Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(256));
|
|
6
|
+
const escalationReason = Schema.Literals([
|
|
7
|
+
"escalated",
|
|
8
|
+
"sender_archived",
|
|
9
|
+
"sender_absent",
|
|
10
|
+
]);
|
|
6
11
|
/** The most Agents one conversation's footer lists; the rest are counted. */
|
|
7
12
|
export const maximumSubagents = 16;
|
|
13
|
+
/** Private status-read ceiling; children past it are explicitly not read. */
|
|
14
|
+
export const maximumCountedSubagents = 256;
|
|
8
15
|
/**
|
|
9
16
|
* What the human sees for one ordinary created Agent. `waiting_on_agent` is an
|
|
10
17
|
* open question that waits on the Agent that sent the work, calm until it is
|
|
@@ -33,6 +40,13 @@ export const Subagent = Schema.Struct({
|
|
|
33
40
|
attention: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(200))),
|
|
34
41
|
/** Display name of the Agent a `waiting_on_agent` child waits on. */
|
|
35
42
|
waitingOn: Schema.optionalKey(identity),
|
|
43
|
+
/** Why the routed child now waits here, without losing the escalating Agent. */
|
|
44
|
+
escalated: Schema.optionalKey(Schema.Struct({
|
|
45
|
+
/** Escalator's name, or the gone recipient's name on automatic promotion. */
|
|
46
|
+
by: identity,
|
|
47
|
+
/** Explicit handoff or positive evidence that the prior recipient is gone. */
|
|
48
|
+
reason: escalationReason,
|
|
49
|
+
})),
|
|
36
50
|
/** The question a waiting child asks, so a person can answer from here. */
|
|
37
51
|
ask: Schema.optionalKey(Schema.Struct({
|
|
38
52
|
/** Durable identity of the child's open Ask. */
|
|
@@ -51,6 +65,41 @@ export const SubagentsProjection = Schema.Struct({
|
|
|
51
65
|
agents: Schema.Array(Subagent).check(Schema.isMaxLength(maximumSubagents)),
|
|
52
66
|
/** Additional created Agents not included in the visible rows. */
|
|
53
67
|
more: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
68
|
+
/** Children beyond the status-read ceiling, never counted as idle. */
|
|
69
|
+
uncounted: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
70
|
+
/** Totals read across every child, before the visible row limit. */
|
|
71
|
+
counts: Schema.Struct({
|
|
72
|
+
/** Read children still working. */
|
|
73
|
+
working: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
74
|
+
/** Read children waiting on an Agent, never counted as needing a person. */
|
|
75
|
+
waiting_on_agent: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
76
|
+
/** Read children whose decision waits on a person. */
|
|
77
|
+
needs_you: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
78
|
+
/** Read children with no current work or decision. */
|
|
79
|
+
idle: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
80
|
+
/** Read children whose work failed. */
|
|
81
|
+
failed: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
82
|
+
/** Children whose status read failed, never counted as idle. */
|
|
83
|
+
unavailable: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
84
|
+
}),
|
|
85
|
+
/** Of those needing a person, how many arrived by escalation. */
|
|
86
|
+
escalated: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
87
|
+
/** Every waiting recipient, including children beyond the visible rows. */
|
|
88
|
+
waitingOn: Schema.Array(Schema.Struct({
|
|
89
|
+
/** Display name of the Agent receiving these decisions. */
|
|
90
|
+
name: identity,
|
|
91
|
+
/** Read children waiting on this recipient name. */
|
|
92
|
+
count: Schema.Int.check(Schema.isGreaterThan(0)),
|
|
93
|
+
})),
|
|
94
|
+
/** Every escalator of a person-bound item, for an accurate collapsed label. */
|
|
95
|
+
escalatedBy: Schema.Array(Schema.Struct({
|
|
96
|
+
/** Display name retained by these escalations. */
|
|
97
|
+
name: identity,
|
|
98
|
+
/** Explicit handoff or automatic promotion, preserved in the summary. */
|
|
99
|
+
reason: escalationReason,
|
|
100
|
+
/** Read person-bound children with this parent name and reason. */
|
|
101
|
+
count: Schema.Int.check(Schema.isGreaterThan(0)),
|
|
102
|
+
})),
|
|
54
103
|
/** Whether individual rows are expanded instead of summarized. */
|
|
55
104
|
expanded: Schema.Boolean,
|
|
56
105
|
});
|
package/dist/subagents/host.d.ts
CHANGED
|
@@ -18,18 +18,18 @@ export type SubagentAgent = Readonly<{
|
|
|
18
18
|
}>;
|
|
19
19
|
/**
|
|
20
20
|
* The host's read-only facts. `read` returns ordinary created Agents,
|
|
21
|
-
*
|
|
21
|
+
* up to `limit` plus a count of those not read; `open` is the
|
|
22
22
|
* host's existing per-operation Agent access (an `AgentControlDirectory`'s
|
|
23
23
|
* `open` fits), and releasing it never stops the Agent's work.
|
|
24
24
|
*/
|
|
25
25
|
export type SubagentSource = Readonly<{
|
|
26
26
|
/** A recorded accepted child command is still pending or running. Synchronous for settlement. */
|
|
27
27
|
hasLiveChildCommand: (sessionId: string) => boolean;
|
|
28
|
-
/**
|
|
28
|
+
/** Enumerate children before presentation limits, within the status-read budget. */
|
|
29
29
|
read: (sessionId: string, limit: number) => Promise<Readonly<{
|
|
30
30
|
/** Created Agents included in this page. */
|
|
31
31
|
agents: readonly SubagentRecord[];
|
|
32
|
-
/** Additional created Agents
|
|
32
|
+
/** Additional created Agents outside this bounded read. */
|
|
33
33
|
more: number;
|
|
34
34
|
}>>;
|
|
35
35
|
/** Acquire existing owner access for one child Agent. */
|
package/dist/subagents/host.js
CHANGED
|
@@ -5,7 +5,8 @@ import * as Schema from "effect/Schema";
|
|
|
5
5
|
import { catalog, done } from "../internal/catalog.js";
|
|
6
6
|
import { advanceAnswerFlow } from "../question/answer-flow.js";
|
|
7
7
|
import { AskProjection, questionContract } from "../question/contract.js";
|
|
8
|
-
import { maximumSubagents, subagentsContract, } from "./contract.js";
|
|
8
|
+
import { maximumSubagents, maximumCountedSubagents, subagentsContract, } from "./contract.js";
|
|
9
|
+
import { escalationLabel } from "./presentation.js";
|
|
9
10
|
const defaultTiming = Object.freeze({
|
|
10
11
|
refreshMs: 1_000,
|
|
11
12
|
pollMs: 5_000,
|
|
@@ -58,8 +59,6 @@ async function status(source, record, signal) {
|
|
|
58
59
|
if (row === undefined || row.state === "unavailable")
|
|
59
60
|
return { ...base, state: "unavailable" };
|
|
60
61
|
const selected = { ...base, sessionId: row.sessionId };
|
|
61
|
-
if (row.state === "running" || row.state === "errored")
|
|
62
|
-
return { ...selected, state: settledState[row.state] };
|
|
63
62
|
// An item waiting on an Agent is calm and leaves the inbox state alone,
|
|
64
63
|
// so a finished child is read for it too. Escalated items wait on a person.
|
|
65
64
|
const snapshot = await opened.agent
|
|
@@ -70,8 +69,17 @@ async function status(source, record, signal) {
|
|
|
70
69
|
? Schema.decodeUnknownOption(AskProjection)(slot.value)
|
|
71
70
|
: Option.none();
|
|
72
71
|
const openAsks = Option.isSome(asked) ? asked.value.asks : [];
|
|
72
|
+
const personal = snapshot.attention.find((item) => item.inbox !== false);
|
|
73
73
|
const routed = snapshot.attention.find((item) => item.waitingOn);
|
|
74
|
-
|
|
74
|
+
const selectedAttention = personal ?? routed;
|
|
75
|
+
if (selectedAttention?.escalated !== undefined)
|
|
76
|
+
Object.assign(selected, {
|
|
77
|
+
escalated: {
|
|
78
|
+
by: selectedAttention.escalated.by.name,
|
|
79
|
+
reason: selectedAttention.escalated.reason,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
if (personal === undefined && routed?.waitingOn !== undefined) {
|
|
75
83
|
const waiting = {
|
|
76
84
|
...selected,
|
|
77
85
|
state: "waiting_on_agent",
|
|
@@ -87,8 +95,11 @@ async function status(source, record, signal) {
|
|
|
87
95
|
ask: { askId: routedAsk.askId, questions: routedAsk.questions },
|
|
88
96
|
};
|
|
89
97
|
}
|
|
90
|
-
const attention =
|
|
91
|
-
if (
|
|
98
|
+
const attention = personal?.summary;
|
|
99
|
+
if (personal === undefined &&
|
|
100
|
+
(row.state === "running" || row.state === "errored"))
|
|
101
|
+
return { ...selected, state: settledState[row.state] };
|
|
102
|
+
if (personal === undefined && row.state === "done")
|
|
92
103
|
return { ...selected, state: "idle" };
|
|
93
104
|
const ask = openAsks.find((open) => open.waitingOn === undefined);
|
|
94
105
|
const needing = { ...selected, state: "needs_you" };
|
|
@@ -140,12 +151,60 @@ function createRoster(source, timing, publish, isObserved) {
|
|
|
140
151
|
clearTimeout(entry.timer);
|
|
141
152
|
entry.timer = undefined;
|
|
142
153
|
try {
|
|
143
|
-
const page = await source.read(sessionId,
|
|
154
|
+
const page = await source.read(sessionId, maximumCountedSubagents);
|
|
155
|
+
const all = [];
|
|
156
|
+
// Bound concurrent owner reads, never truncate the counts to displayed rows.
|
|
157
|
+
for (let offset = 0; offset < page.agents.length; offset += 8) {
|
|
158
|
+
if (lifetime.signal.aborted)
|
|
159
|
+
return;
|
|
160
|
+
all.push(...(await Promise.all(page.agents
|
|
161
|
+
.slice(offset, offset + 8)
|
|
162
|
+
.map((record) => status(source, record, lifetime.signal)))));
|
|
163
|
+
}
|
|
164
|
+
const counts = {
|
|
165
|
+
working: 0,
|
|
166
|
+
waiting_on_agent: 0,
|
|
167
|
+
needs_you: 0,
|
|
168
|
+
idle: 0,
|
|
169
|
+
failed: 0,
|
|
170
|
+
unavailable: 0,
|
|
171
|
+
};
|
|
172
|
+
const waitingOn = new Map();
|
|
173
|
+
const escalatedBy = new Map();
|
|
174
|
+
for (const child of all) {
|
|
175
|
+
counts[child.state] += 1;
|
|
176
|
+
if (child.state === "waiting_on_agent" && child.waitingOn !== undefined)
|
|
177
|
+
waitingOn.set(child.waitingOn, (waitingOn.get(child.waitingOn) ?? 0) + 1);
|
|
178
|
+
if (child.state === "needs_you" && child.escalated !== undefined) {
|
|
179
|
+
const { by: name, reason } = child.escalated;
|
|
180
|
+
const key = `${reason}:${name}`;
|
|
181
|
+
escalatedBy.set(key, {
|
|
182
|
+
name,
|
|
183
|
+
reason,
|
|
184
|
+
count: (escalatedBy.get(key)?.count ?? 0) + 1,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const grouped = (names) => [...names]
|
|
189
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
190
|
+
.map(([name, count]) => ({ name, count }));
|
|
191
|
+
const priority = {
|
|
192
|
+
needs_you: 0,
|
|
193
|
+
waiting_on_agent: 1,
|
|
194
|
+
working: 2,
|
|
195
|
+
failed: 3,
|
|
196
|
+
unavailable: 4,
|
|
197
|
+
idle: 5,
|
|
198
|
+
};
|
|
199
|
+
all.sort((a, b) => priority[a.state] - priority[b.state]);
|
|
144
200
|
const value = {
|
|
145
|
-
agents:
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
201
|
+
agents: all.slice(0, maximumSubagents - 1),
|
|
202
|
+
more: Math.max(0, all.length - (maximumSubagents - 1)),
|
|
203
|
+
uncounted: page.more,
|
|
204
|
+
counts,
|
|
205
|
+
escalated: [...escalatedBy.values()].reduce((sum, group) => sum + group.count, 0),
|
|
206
|
+
waitingOn: grouped(waitingOn),
|
|
207
|
+
escalatedBy: [...escalatedBy.values()].sort((a, b) => a.name.localeCompare(b.name) || a.reason.localeCompare(b.reason)),
|
|
149
208
|
};
|
|
150
209
|
const changed = JSON.stringify(value) !== JSON.stringify(entry.value);
|
|
151
210
|
entry.value = value;
|
|
@@ -331,9 +390,13 @@ export function subagentsExtension(options) {
|
|
|
331
390
|
...step,
|
|
332
391
|
prompt: {
|
|
333
392
|
...step.prompt,
|
|
334
|
-
summary:
|
|
335
|
-
|
|
336
|
-
|
|
393
|
+
summary: [
|
|
394
|
+
`${row.name} asks`,
|
|
395
|
+
escalationLabel(row.escalated),
|
|
396
|
+
step.prompt.summary,
|
|
397
|
+
]
|
|
398
|
+
.filter((text) => text !== undefined)
|
|
399
|
+
.join(" · "),
|
|
337
400
|
},
|
|
338
401
|
next: {
|
|
339
402
|
...step.next,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Subagent } from "./contract.js";
|
|
2
|
+
/** Keep the same provenance when a footer row becomes a composer decision. */
|
|
3
|
+
export declare function escalationLabel(escalation: NonNullable<Subagent["escalated"]>): string;
|
|
4
|
+
export declare function escalationLabel(escalation: Subagent["escalated"]): string | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function escalationLabel(escalation) {
|
|
2
|
+
if (escalation === undefined)
|
|
3
|
+
return undefined;
|
|
4
|
+
return escalation.reason === "escalated"
|
|
5
|
+
? `escalated by ${escalation.by}`
|
|
6
|
+
: escalation.reason === "sender_archived"
|
|
7
|
+
? `${escalation.by} archived`
|
|
8
|
+
: `${escalation.by} is gone`;
|
|
9
|
+
}
|