@adecore/agents-react 0.45.1 → 0.46.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.
@@ -399,6 +399,7 @@ export class ChatClient {
399
399
  history: result.history,
400
400
  pending: result.pending ?? [],
401
401
  subagents: result.subagents ?? [],
402
+ workflows: result.workflows ?? [],
402
403
  outline: result.outline ?? []
403
404
  };
404
405
  this.sink.reset(chatId, result.info, result.items, page);
@@ -16,6 +16,7 @@ export { type TimedRow, withTimedRows, timedRowsOf } from './logic/thread-cards.
16
16
  export { EMPTY_TARGET, readTimelineTarget, type TimelineTarget } from './logic/timeline-target.js';
17
17
  export { type TimelineRow, summarizeGroup, deriveTimelineRows, type SubagentBranch, type BaseMoved } from './logic/timeline.js';
18
18
  export { toolSummary, type FileChange } from './logic/tools.js';
19
+ export { workflowPhases, workflowCounts, workflowAgentState, workflowAgentTime, workflowAgentPreview, workflowDescription, workflowPhaseState, workflowPhaseTime, liveWorkflowPhase, type WorkflowPhaseView, type WorkflowAgentView, type WorkflowAgentState, type WorkflowAgentPreview, type WorkflowCounts, type WorkflowPhaseState, type WorkflowPhaseStateKind, type WorkflowPhaseTime } from './logic/workflow.js';
19
20
  export { MENTION_DRAG_TYPE, LEGACY_MENTION_DRAG_TYPE, carriesMentions, droppedMentions, writeMentionDrag, chipText, type MentionQuery, type ChipSegment } from './mentions.js';
20
21
  export { defaultProvider, selectionFor, startingSelection, accountFor, chatPreferencesPayload, useChatPreferences, readChatPreferences, CHAT_PREFERENCES_KEY, reloadChatPreferences, rememberChatPreferences, rememberReadingWidth, rememberSendKey, rememberChatSelection, type ChatPreferences } from './preferences.js';
21
22
  export type { HoldRelease } from './prompt-hold.js';
@@ -14,6 +14,7 @@ export { withTimedRows, timedRowsOf } from './logic/thread-cards.js';
14
14
  export { EMPTY_TARGET, readTimelineTarget } from './logic/timeline-target.js';
15
15
  export { summarizeGroup, deriveTimelineRows } from './logic/timeline.js';
16
16
  export { toolSummary } from './logic/tools.js';
17
+ export { workflowPhases, workflowCounts, workflowAgentState, workflowAgentTime, workflowAgentPreview, workflowDescription, workflowPhaseState, workflowPhaseTime, liveWorkflowPhase } from './logic/workflow.js';
17
18
  export { MENTION_DRAG_TYPE, LEGACY_MENTION_DRAG_TYPE, carriesMentions, droppedMentions, writeMentionDrag, chipText } from './mentions.js';
18
19
  export { defaultProvider, selectionFor, startingSelection, accountFor, chatPreferencesPayload, useChatPreferences, readChatPreferences, CHAT_PREFERENCES_KEY, reloadChatPreferences, rememberChatPreferences, rememberReadingWidth, rememberSendKey, rememberChatSelection } from './preferences.js';
19
20
  export { CHAT_READING_WIDTHS, readingWidthLabel, readingWidthHint } from './reading-width.js';
@@ -21,4 +21,17 @@ export type WorkflowCounts = Record<WorkflowAgentState, number> & {
21
21
  total: number;
22
22
  };
23
23
  export declare function workflowCounts(phases: WorkflowPhaseView[]): WorkflowCounts;
24
+ export type WorkflowPhaseStateKind = 'running' | 'waiting' | 'done' | 'failed';
25
+ export interface WorkflowPhaseState {
26
+ state: WorkflowPhaseStateKind;
27
+ settled: number;
28
+ total: number;
29
+ }
30
+ export declare function workflowPhaseState(phase: WorkflowPhaseView): WorkflowPhaseState;
31
+ export interface WorkflowPhaseTime {
32
+ startedAt: number;
33
+ endedAt: number | null;
34
+ }
35
+ export declare function workflowPhaseTime(phase: WorkflowPhaseView): WorkflowPhaseTime | null;
36
+ export declare function liveWorkflowPhase(phases: WorkflowPhaseView[], workflowRunning: boolean): string | null;
24
37
  export declare function workflowDescription(input: unknown): string | null;
@@ -104,6 +104,78 @@ export function workflowCounts(phases) {
104
104
  }
105
105
  return counts;
106
106
  }
107
+ /* A phase between two of its agents, some settled and some still waiting, is still at work. */
108
+ export function workflowPhaseState(phase) {
109
+ const total = phase.agents.length;
110
+ const waiting = phase.agents.filter(view => view.state === 'waiting').length;
111
+ const running = phase.agents.filter(view => view.state === 'running').length;
112
+ const settled = total - waiting - running;
113
+ if (running > 0 || waiting > 0 && settled > 0) {
114
+ return {
115
+ state: 'running',
116
+ settled,
117
+ total
118
+ };
119
+ }
120
+ if (settled === 0) {
121
+ return {
122
+ state: 'waiting',
123
+ settled,
124
+ total
125
+ };
126
+ }
127
+ return {
128
+ state: phase.agents.every(view => view.state === 'done') ? 'done' : 'failed',
129
+ settled,
130
+ total
131
+ };
132
+ }
133
+ /*
134
+ * How long the phase's agents were at work, from the first start to the last known end. Agents of a
135
+ * phase run beside each other, so this is never the sum of their times. Null before any started.
136
+ */
137
+ export function workflowPhaseTime(phase) {
138
+ const started = phase.agents.flatMap(view => view.agent.startedAt === null ? [] : [view.agent.startedAt]);
139
+ if (started.length === 0) {
140
+ return null;
141
+ }
142
+ const startedAt = Math.min(...started);
143
+ if (phase.agents.some(view => view.state === 'running')) {
144
+ return {
145
+ startedAt,
146
+ endedAt: null
147
+ };
148
+ }
149
+ const ends = phase.agents.flatMap(({
150
+ agent
151
+ }) => agent.startedAt !== null && agent.durationMs !== null ? [agent.startedAt + agent.durationMs] : []);
152
+ return {
153
+ startedAt,
154
+ endedAt: Math.max(startedAt, ...ends)
155
+ };
156
+ }
157
+ /*
158
+ * The phase a view beside the thread keeps open by itself: the one with an agent at work, the one whose
159
+ * agent started last when several are, and before any is at work the first that still waits. Null once
160
+ * the workflow stopped running, since then nothing is live.
161
+ */
162
+ export function liveWorkflowPhase(phases, workflowRunning) {
163
+ if (!workflowRunning) {
164
+ return null;
165
+ }
166
+ let live = null;
167
+ for (const phase of phases) {
168
+ for (const view of phase.agents) {
169
+ if (view.state === 'running' && (live === null || (view.agent.startedAt ?? 0) >= live.startedAt)) {
170
+ live = {
171
+ key: phase.key,
172
+ startedAt: view.agent.startedAt ?? 0
173
+ };
174
+ }
175
+ }
176
+ }
177
+ return live?.key ?? phases.find(phase => workflowPhaseState(phase).state === 'waiting')?.key ?? null;
178
+ }
107
179
  const META_START = /export\s+const\s+meta\s*=\s*\{/;
108
180
  const DESCRIPTION = /\bdescription\s*:\s*(['"`])((?:\\.|(?!\1)[^\\])*)\1/;
109
181
  /* The literal from its opening brace to the one that closes it, skipping braces inside strings. */
@@ -1,4 +1,7 @@
1
- export declare function SubagentTimeline({ chatId, toolUseId }: {
1
+ import { type SubagentStep } from '../subagent-view.js';
2
+ export declare function SubagentTimeline({ chatId, toolUseId, info, onOpenConversation }: {
2
3
  chatId: string;
3
4
  toolUseId: string;
5
+ info?: boolean;
6
+ onOpenConversation?(step: SubagentStep): void;
4
7
  }): import("react").JSX.Element;
@@ -27,13 +27,19 @@ const NO_TURNS = new Set();
27
27
  /*
28
28
  * A sub-agent's whole conversation, read back from the host and grown while it is on screen. It
29
29
  * stands in the chat's own place, read-only, and a sub-agent it opened goes one level further down.
30
+ * Drawn anywhere else, such as in a panel of its own beside the chat, `info={false}` leaves out the bar
31
+ * that leads back through the chat's trail, and `onOpenConversation` opens a child in that place's
32
+ * own trail instead of the chat's.
30
33
  */
31
34
  export function SubagentTimeline(t0) {
32
- const $ = _c(44);
35
+ const $ = _c(46);
33
36
  const {
34
37
  chatId,
35
- toolUseId
38
+ toolUseId,
39
+ info: t1,
40
+ onOpenConversation
36
41
  } = t0;
42
+ const info = t1 === undefined ? true : t1;
37
43
  const {
38
44
  t
39
45
  } = useTranslation("agent-chat");
@@ -51,24 +57,24 @@ export function SubagentTimeline(t0) {
51
57
  const threadRef = useRef(null);
52
58
  const [target, setTarget] = useState(EMPTY_TARGET);
53
59
  const followRef = useRef(true);
54
- let t1;
60
+ let t2;
55
61
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
56
- t1 = () => {
62
+ t2 = () => {
57
63
  followRef.current = false;
58
64
  };
59
- $[0] = t1;
65
+ $[0] = t2;
60
66
  } else {
61
- t1 = $[0];
67
+ t2 = $[0];
62
68
  }
63
- const stopFollowing = t1;
69
+ const stopFollowing = t2;
64
70
  const groups = useToggleSet(stopFollowing);
65
71
  const subagents = useToggleSet(stopFollowing);
66
72
  const anchorRef = useRef(null);
67
73
  const headRef = useRef(undefined);
68
74
  const cwd = useChatRow(chatId, _temp);
69
- let t2;
75
+ let t3;
70
76
  if ($[1] !== chatId || $[2] !== scope.transport || $[3] !== toolUseId) {
71
- t2 = () => {
77
+ t3 = () => {
72
78
  const conversation = new SubagentConversation(scope.transport, chatId, toolUseId, setState);
73
79
  controller.current = conversation;
74
80
  conversation.start();
@@ -80,44 +86,44 @@ export function SubagentTimeline(t0) {
80
86
  $[1] = chatId;
81
87
  $[2] = scope.transport;
82
88
  $[3] = toolUseId;
83
- $[4] = t2;
89
+ $[4] = t3;
84
90
  } else {
85
- t2 = $[4];
91
+ t3 = $[4];
86
92
  }
87
- let t3;
93
+ let t4;
88
94
  if ($[5] !== chatId || $[6] !== scope || $[7] !== toolUseId) {
89
- t3 = [scope, chatId, toolUseId];
95
+ t4 = [scope, chatId, toolUseId];
90
96
  $[5] = chatId;
91
97
  $[6] = scope;
92
98
  $[7] = toolUseId;
93
- $[8] = t3;
99
+ $[8] = t4;
94
100
  } else {
95
- t3 = $[8];
101
+ t4 = $[8];
96
102
  }
97
- useEffect(t2, t3);
98
- let t4;
103
+ useEffect(t3, t4);
104
+ let t5;
99
105
  if ($[9] !== scope.id || $[10] !== state.unsupported) {
100
- t4 = () => {
106
+ t5 = () => {
101
107
  if (state.unsupported) {
102
108
  useSubagentSupport.getState().markUnsupported(scope.id);
103
109
  }
104
110
  };
105
111
  $[9] = scope.id;
106
112
  $[10] = state.unsupported;
107
- $[11] = t4;
113
+ $[11] = t5;
108
114
  } else {
109
- t4 = $[11];
115
+ t5 = $[11];
110
116
  }
111
- let t5;
117
+ let t6;
112
118
  if ($[12] !== scope || $[13] !== state.unsupported) {
113
- t5 = [state.unsupported, scope];
119
+ t6 = [state.unsupported, scope];
114
120
  $[12] = scope;
115
121
  $[13] = state.unsupported;
116
- $[14] = t5;
122
+ $[14] = t6;
117
123
  } else {
118
- t5 = $[14];
124
+ t6 = $[14];
119
125
  }
120
- useEffect(t4, t5);
126
+ useEffect(t5, t6);
121
127
  const hideTools = useHostHidesToolCalls(scope.id, chatId);
122
128
  const rows = deriveTimelineRows(state.items, {
123
129
  expandedGroups: groups.ids,
@@ -127,9 +133,9 @@ export function SubagentTimeline(t0) {
127
133
  commandLooks,
128
134
  hideTools
129
135
  });
130
- let t6;
136
+ let t7;
131
137
  if ($[15] !== state.items) {
132
- t6 = () => {
138
+ t7 = () => {
133
139
  const element = scrollRef.current;
134
140
  if (element === null) {
135
141
  return;
@@ -149,14 +155,14 @@ export function SubagentTimeline(t0) {
149
155
  }
150
156
  };
151
157
  $[15] = state.items;
152
- $[16] = t6;
158
+ $[16] = t7;
153
159
  } else {
154
- t6 = $[16];
160
+ t7 = $[16];
155
161
  }
156
- useLayoutEffect(t6, [rows, state.live, state.items]);
157
- let t7;
162
+ useLayoutEffect(t7, [rows, state.live, state.items]);
163
+ let t8;
158
164
  if ($[17] !== state.cursor) {
159
- t7 = () => {
165
+ t8 = () => {
160
166
  const element_0 = scrollRef.current;
161
167
  if (element_0 === null || state.cursor === null || !wantsEarlier(element_0)) {
162
168
  return;
@@ -165,86 +171,92 @@ export function SubagentTimeline(t0) {
165
171
  controller.current?.loadEarlier();
166
172
  };
167
173
  $[17] = state.cursor;
168
- $[18] = t7;
174
+ $[18] = t8;
169
175
  } else {
170
- t7 = $[18];
176
+ t8 = $[18];
171
177
  }
172
- const loadEarlier = t7;
173
- let t8;
178
+ const loadEarlier = t8;
179
+ let t9;
174
180
  if ($[19] !== loadEarlier || $[20] !== state.status) {
175
- t8 = () => {
181
+ t9 = () => {
176
182
  if (state.status === "ready") {
177
183
  loadEarlier();
178
184
  }
179
185
  };
180
186
  $[19] = loadEarlier;
181
187
  $[20] = state.status;
182
- $[21] = t8;
188
+ $[21] = t9;
183
189
  } else {
184
- t8 = $[21];
190
+ t9 = $[21];
185
191
  }
186
- useEffect(t8, [rows, state.status, loadEarlier]);
192
+ useEffect(t9, [rows, state.status, loadEarlier]);
187
193
  const readingWidth = useChatPreferences(_temp2);
188
- let t9;
189
- if ($[22] !== show || $[23] !== trail) {
190
- t9 = step => {
191
- show(openBelow(trail, step));
194
+ let t10;
195
+ if ($[22] !== onOpenConversation || $[23] !== show || $[24] !== trail) {
196
+ t10 = step => {
197
+ if (onOpenConversation === undefined) {
198
+ show(openBelow(trail, step));
199
+ } else {
200
+ onOpenConversation(step);
201
+ }
192
202
  };
193
- $[22] = show;
194
- $[23] = trail;
195
- $[24] = t9;
203
+ $[22] = onOpenConversation;
204
+ $[23] = show;
205
+ $[24] = trail;
206
+ $[25] = t10;
196
207
  } else {
197
- t9 = $[24];
208
+ t10 = $[25];
198
209
  }
199
- const openChild = t9;
200
- const t10 = "flex h-full min-h-0 flex-col";
201
- let t11;
202
- if ($[25] !== readingWidth) {
203
- t11 = readingWidthStyle(readingWidth);
204
- $[25] = readingWidth;
205
- $[26] = t11;
210
+ const openChild = t10;
211
+ const t11 = "flex h-full min-h-0 flex-col";
212
+ let t12;
213
+ if ($[26] !== readingWidth) {
214
+ t12 = readingWidthStyle(readingWidth);
215
+ $[26] = readingWidth;
216
+ $[27] = t12;
206
217
  } else {
207
- t11 = $[26];
218
+ t12 = $[27];
208
219
  }
209
- let t12;
210
- if ($[27] !== chatId || $[28] !== toolUseId) {
211
- t12 = /*#__PURE__*/_jsx(SubagentInfo, {
220
+ let t13;
221
+ if ($[28] !== chatId || $[29] !== info || $[30] !== toolUseId) {
222
+ t13 = info && /*#__PURE__*/_jsx(SubagentInfo, {
212
223
  chatId: chatId,
213
224
  toolUseId: toolUseId
214
225
  });
215
- $[27] = chatId;
216
- $[28] = toolUseId;
217
- $[29] = t12;
226
+ $[28] = chatId;
227
+ $[29] = info;
228
+ $[30] = toolUseId;
229
+ $[31] = t13;
218
230
  } else {
219
- t12 = $[29];
231
+ t13 = $[31];
220
232
  }
221
- let t13;
222
- if ($[30] !== state.status || $[31] !== t) {
223
- t13 = state.status === "loading" && /*#__PURE__*/_jsx("div", {
233
+ let t14;
234
+ if ($[32] !== state.status || $[33] !== t) {
235
+ t14 = state.status === "loading" && /*#__PURE__*/_jsx("div", {
224
236
  className: "chat-column-content px-4 pt-4 text-xs text-text-faint",
225
237
  children: t("subagents.loading")
226
238
  });
227
- $[30] = state.status;
228
- $[31] = t;
229
- $[32] = t13;
239
+ $[32] = state.status;
240
+ $[33] = t;
241
+ $[34] = t14;
230
242
  } else {
231
- t13 = $[32];
243
+ t14 = $[34];
232
244
  }
233
- let t14;
234
- if ($[33] !== state.error || $[34] !== state.status || $[35] !== state.unsupported || $[36] !== t) {
235
- t14 = state.status === "failed" && /*#__PURE__*/_jsx(EmptyState, {
245
+ let t15;
246
+ if ($[35] !== state.error || $[36] !== state.status || $[37] !== state.unsupported || $[38] !== t) {
247
+ t15 = state.status === "failed" && /*#__PURE__*/_jsx(EmptyState, {
236
248
  icon: Bot,
237
249
  children: state.unsupported ? t("subagents.unsupported") : state.error ?? t("subagents.unreadable")
238
250
  });
239
- $[33] = state.error;
240
- $[34] = state.status;
241
- $[35] = state.unsupported;
242
- $[36] = t;
243
- $[37] = t14;
251
+ $[35] = state.error;
252
+ $[36] = state.status;
253
+ $[37] = state.unsupported;
254
+ $[38] = t;
255
+ $[39] = t15;
244
256
  } else {
245
- t14 = $[37];
257
+ t15 = $[39];
246
258
  }
247
- const t15 = state.status === "ready" && /*#__PURE__*/_jsx(FileLinkContext.Provider, {
259
+ const t16 = state.status === "ready" && /*#__PURE__*/_jsx(FileLinkContext.Provider, {
248
260
  value: state.context?.cwd ?? cwd,
249
261
  children: /*#__PURE__*/_jsx(ReplyContext.Provider, {
250
262
  value: state.context ?? {
@@ -309,23 +321,23 @@ export function SubagentTimeline(t0) {
309
321
  })
310
322
  })
311
323
  });
312
- let t16;
313
- if ($[38] !== t11 || $[39] !== t12 || $[40] !== t13 || $[41] !== t14 || $[42] !== t15) {
314
- t16 = /*#__PURE__*/_jsxs("div", {
315
- className: t10,
316
- style: t11,
317
- children: [t12, t13, t14, t15]
324
+ let t17;
325
+ if ($[40] !== t12 || $[41] !== t13 || $[42] !== t14 || $[43] !== t15 || $[44] !== t16) {
326
+ t17 = /*#__PURE__*/_jsxs("div", {
327
+ className: t11,
328
+ style: t12,
329
+ children: [t13, t14, t15, t16]
318
330
  });
319
- $[38] = t11;
320
- $[39] = t12;
321
- $[40] = t13;
322
- $[41] = t14;
323
- $[42] = t15;
324
- $[43] = t16;
331
+ $[40] = t12;
332
+ $[41] = t13;
333
+ $[42] = t14;
334
+ $[43] = t15;
335
+ $[44] = t16;
336
+ $[45] = t17;
325
337
  } else {
326
- t16 = $[43];
338
+ t17 = $[45];
327
339
  }
328
- return t16;
340
+ return t17;
329
341
  }
330
342
  function _temp4() {}
331
343
  function _temp3() {}
@@ -0,0 +1,12 @@
1
+ import type { Ref } from 'react';
2
+ import { type AgentKind } from '@adecore/agent-contracts';
3
+ import { type WorkflowAgentView } from '../logic/workflow.js';
4
+ import type { SubagentStep } from '../subagent-view.js';
5
+ export declare function WorkflowAgentLine({ view, provider, onOpen, selected, className, ref }: {
6
+ view: WorkflowAgentView;
7
+ provider: AgentKind | undefined;
8
+ onOpen?(step: SubagentStep): void;
9
+ selected?: boolean;
10
+ className?: string;
11
+ ref?: Ref<HTMLButtonElement>;
12
+ }): import("react").JSX.Element;