langchain_agentx_stream_ui 0.1.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/README.md +236 -0
- package/dist/AskUserQuestionToolBody-CyuNy_k5.d.ts +33 -0
- package/dist/MarkdownBlock-3iEW0Ubm.d.ts +100 -0
- package/dist/chunk-4RIOBLGB.js +666 -0
- package/dist/chunk-4RIOBLGB.js.map +1 -0
- package/dist/chunk-DP7V33X7.js +13 -0
- package/dist/chunk-DP7V33X7.js.map +1 -0
- package/dist/chunk-G2KYJCMM.js +5171 -0
- package/dist/chunk-G2KYJCMM.js.map +1 -0
- package/dist/chunk-MHK53ZHC.js +972 -0
- package/dist/chunk-MHK53ZHC.js.map +1 -0
- package/dist/chunk-W6QQHTJ4.js +785 -0
- package/dist/chunk-W6QQHTJ4.js.map +1 -0
- package/dist/chunk-WM6Y6APP.js +411 -0
- package/dist/chunk-WM6Y6APP.js.map +1 -0
- package/dist/default.css +1364 -0
- package/dist/index.d.ts +650 -0
- package/dist/index.js +743 -0
- package/dist/index.js.map +1 -0
- package/dist/multi-session-CviqerRl.d.ts +494 -0
- package/dist/multi-session.d.ts +7 -0
- package/dist/multi-session.js +21 -0
- package/dist/multi-session.js.map +1 -0
- package/dist/nodes-DqhaBW7M.d.ts +195 -0
- package/dist/sessionViewOptions-DLSFRQwZ.d.ts +158 -0
- package/dist/tools-presentation.d.ts +14 -0
- package/dist/tools-presentation.js +37 -0
- package/dist/tools-presentation.js.map +1 -0
- package/dist/tools.d.ts +21 -0
- package/dist/tools.js +43 -0
- package/dist/tools.js.map +1 -0
- package/dist/types-aXj5TYSP.d.ts +33 -0
- package/dist/virtual.d.ts +36 -0
- package/dist/virtual.js +19 -0
- package/dist/virtual.js.map +1 -0
- package/package.json +88 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,743 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ErrorCard,
|
|
3
|
+
MultiAgentSession,
|
|
4
|
+
NodeRegistry,
|
|
5
|
+
PermissionCard,
|
|
6
|
+
ReasoningBubble,
|
|
7
|
+
StepCard,
|
|
8
|
+
TextBubble,
|
|
9
|
+
ToolCallCard,
|
|
10
|
+
UnknownCard,
|
|
11
|
+
createActiveSessionBridge,
|
|
12
|
+
createDefaultRegistry,
|
|
13
|
+
createMultiSessionStore,
|
|
14
|
+
markEventIdSeen,
|
|
15
|
+
shouldSkipDuplicateEvent
|
|
16
|
+
} from "./chunk-W6QQHTJ4.js";
|
|
17
|
+
import {
|
|
18
|
+
DefaultToolBody,
|
|
19
|
+
InteractionBusContext,
|
|
20
|
+
createInteractionBus,
|
|
21
|
+
formatToolTitle,
|
|
22
|
+
getNoopInteractionBus,
|
|
23
|
+
resolveToolBody,
|
|
24
|
+
useInteractionBus
|
|
25
|
+
} from "./chunk-WM6Y6APP.js";
|
|
26
|
+
import "./chunk-DP7V33X7.js";
|
|
27
|
+
import {
|
|
28
|
+
CollapseKind,
|
|
29
|
+
CollapsedExploreNode,
|
|
30
|
+
DEFAULT_ESTIMATE_SIZE,
|
|
31
|
+
DEFAULT_EVENT_TIERS,
|
|
32
|
+
DEFAULT_SESSION_VIEW_OPTIONS,
|
|
33
|
+
DEFAULT_VIRTUALIZE_THRESHOLD,
|
|
34
|
+
ExploreCollapseAccumulator,
|
|
35
|
+
GROUPABLE_TOOL_NAMES,
|
|
36
|
+
GroupedToolUseAccumulator,
|
|
37
|
+
MIN_HINT_DISPLAY_MS,
|
|
38
|
+
NodeRegistryContext,
|
|
39
|
+
ProjectionContext,
|
|
40
|
+
RenderableTimelineProjector,
|
|
41
|
+
SHELL_PROGRESS_MIN_ELAPSED_SECONDS,
|
|
42
|
+
SessionStoreContext,
|
|
43
|
+
SessionTimeline,
|
|
44
|
+
SessionViewOptionsContext,
|
|
45
|
+
Spinner,
|
|
46
|
+
SystemSummaryAccumulator,
|
|
47
|
+
SystemSummaryNode,
|
|
48
|
+
TaskList,
|
|
49
|
+
TaskListFooter,
|
|
50
|
+
Timeline,
|
|
51
|
+
TimelineItem,
|
|
52
|
+
ToolDisplayOptionsContext,
|
|
53
|
+
ToolProjectionClassifier,
|
|
54
|
+
VirtualTimeline,
|
|
55
|
+
buildCanonicalFromTree,
|
|
56
|
+
buildProjectionContext,
|
|
57
|
+
buildProjectionViewContext,
|
|
58
|
+
buildRelevantMemoriesCanonical,
|
|
59
|
+
buildSystemEventCanonical,
|
|
60
|
+
classifyEvent,
|
|
61
|
+
commandAsHint,
|
|
62
|
+
createEmptyTree,
|
|
63
|
+
createProjectionContext,
|
|
64
|
+
entryKey,
|
|
65
|
+
formatExploreSummaryText,
|
|
66
|
+
formatHookFinishedSummary,
|
|
67
|
+
formatShellProgressSuffix,
|
|
68
|
+
formatTaskFooterLabel,
|
|
69
|
+
getChildIds,
|
|
70
|
+
getMainStageIds,
|
|
71
|
+
isGitOperationCommand,
|
|
72
|
+
isGroupableToolName,
|
|
73
|
+
isMcpToolName,
|
|
74
|
+
iterMountCandidates,
|
|
75
|
+
projectCanonical,
|
|
76
|
+
projectTimeline,
|
|
77
|
+
reduceEvents,
|
|
78
|
+
reduceTree,
|
|
79
|
+
replayEvents,
|
|
80
|
+
replayTree,
|
|
81
|
+
resolveEffectiveToolBodyMode,
|
|
82
|
+
resolveEventTier,
|
|
83
|
+
resolveResponseId,
|
|
84
|
+
resolveShellProgressFromPayload,
|
|
85
|
+
shouldApplyGrouping,
|
|
86
|
+
shouldShowExploreDetail,
|
|
87
|
+
shouldShowTaskListFooter,
|
|
88
|
+
streamChunk,
|
|
89
|
+
useActiveSession,
|
|
90
|
+
useChildren,
|
|
91
|
+
useInternalErrors,
|
|
92
|
+
useMinDisplayTime,
|
|
93
|
+
useNode,
|
|
94
|
+
useNodeRegistry,
|
|
95
|
+
useNodeTyped,
|
|
96
|
+
useProjectedTimeline,
|
|
97
|
+
useReplayTree,
|
|
98
|
+
useSessionIds,
|
|
99
|
+
useSessionMeta,
|
|
100
|
+
useSessionStatus,
|
|
101
|
+
useTimeline
|
|
102
|
+
} from "./chunk-G2KYJCMM.js";
|
|
103
|
+
import {
|
|
104
|
+
Agent,
|
|
105
|
+
AgentToolBody,
|
|
106
|
+
AskUserQuestion,
|
|
107
|
+
AskUserQuestionToolBody,
|
|
108
|
+
Bash,
|
|
109
|
+
BashToolBody,
|
|
110
|
+
Edit,
|
|
111
|
+
EditToolBody,
|
|
112
|
+
Glob,
|
|
113
|
+
GlobToolBody,
|
|
114
|
+
Grep,
|
|
115
|
+
GrepToolBody,
|
|
116
|
+
Read,
|
|
117
|
+
ReadToolBody,
|
|
118
|
+
Skill,
|
|
119
|
+
SkillToolBody,
|
|
120
|
+
ToolDisplayRegistry,
|
|
121
|
+
WebFetch,
|
|
122
|
+
WebFetchToolBody,
|
|
123
|
+
WebSearch,
|
|
124
|
+
WebSearchToolBody,
|
|
125
|
+
Write,
|
|
126
|
+
WriteToolBody,
|
|
127
|
+
createDefaultToolRegistry,
|
|
128
|
+
formatAgentTitle
|
|
129
|
+
} from "./chunk-MHK53ZHC.js";
|
|
130
|
+
import {
|
|
131
|
+
BodyBlockList,
|
|
132
|
+
DiffView,
|
|
133
|
+
MAX_PREVIEW_LINES,
|
|
134
|
+
MarkdownBlock,
|
|
135
|
+
MarkdownRendererContext,
|
|
136
|
+
TruncatedContent,
|
|
137
|
+
buildBashBodyBlocks,
|
|
138
|
+
displayPath,
|
|
139
|
+
formatDiffFromStrings,
|
|
140
|
+
formatPatternTitle,
|
|
141
|
+
formatSearchResultBody,
|
|
142
|
+
formatTimeoutFooter,
|
|
143
|
+
parseDiffText,
|
|
144
|
+
truncateCommand
|
|
145
|
+
} from "./chunk-4RIOBLGB.js";
|
|
146
|
+
|
|
147
|
+
// src/view/AgentSession.tsx
|
|
148
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
149
|
+
|
|
150
|
+
// src/core/store.ts
|
|
151
|
+
import { createStore } from "zustand/vanilla";
|
|
152
|
+
function safeReduce(tree, event, eventIndex, options) {
|
|
153
|
+
try {
|
|
154
|
+
return { tree: reduceTree(tree, event, eventIndex, options) };
|
|
155
|
+
} catch (err) {
|
|
156
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
157
|
+
const stack = err instanceof Error ? err.stack : void 0;
|
|
158
|
+
if (import.meta.env?.DEV) {
|
|
159
|
+
console.error("[langchain_agentx_stream_ui] reducer error:", err);
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
tree: {
|
|
163
|
+
...tree,
|
|
164
|
+
internalErrors: [
|
|
165
|
+
...tree.internalErrors,
|
|
166
|
+
{ eventIndex, eventType: event.event_type, message, stack }
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function createSessionStore(initialTree = createEmptyTree(), storeOptions) {
|
|
173
|
+
const reduceOpts = {
|
|
174
|
+
tierOverrides: storeOptions?.tierOverrides,
|
|
175
|
+
collectDebug: storeOptions?.debug === true
|
|
176
|
+
};
|
|
177
|
+
const initialEventCount = storeOptions?.initialEventCount ?? 0;
|
|
178
|
+
const seenEventIds = new Set(storeOptions?.initialSeenEventIds);
|
|
179
|
+
return createStore((set, get) => ({
|
|
180
|
+
tree: initialTree,
|
|
181
|
+
eventCount: initialEventCount,
|
|
182
|
+
applyEvent(event, ctx) {
|
|
183
|
+
const sseEventId = ctx?.sseEventId;
|
|
184
|
+
if (shouldSkipDuplicateEvent(seenEventIds, sseEventId)) return;
|
|
185
|
+
const { tree, eventCount } = get();
|
|
186
|
+
const { tree: reduced } = safeReduce(tree, event, eventCount, reduceOpts);
|
|
187
|
+
const nextTree = sseEventId ? {
|
|
188
|
+
...reduced,
|
|
189
|
+
meta: { ...reduced.meta, lastEventId: sseEventId }
|
|
190
|
+
} : reduced;
|
|
191
|
+
markEventIdSeen(seenEventIds, sseEventId);
|
|
192
|
+
set({ tree: nextTree, eventCount: eventCount + 1 });
|
|
193
|
+
},
|
|
194
|
+
applyEvents(events) {
|
|
195
|
+
let { tree, eventCount } = get();
|
|
196
|
+
for (const event of events) {
|
|
197
|
+
const result = safeReduce(tree, event, eventCount, reduceOpts);
|
|
198
|
+
tree = result.tree;
|
|
199
|
+
eventCount += 1;
|
|
200
|
+
}
|
|
201
|
+
set({ tree, eventCount });
|
|
202
|
+
},
|
|
203
|
+
reset() {
|
|
204
|
+
seenEventIds.clear();
|
|
205
|
+
set({ tree: createEmptyTree(), eventCount: 0 });
|
|
206
|
+
},
|
|
207
|
+
markAsError(error) {
|
|
208
|
+
const { tree } = get();
|
|
209
|
+
set({
|
|
210
|
+
tree: {
|
|
211
|
+
...tree,
|
|
212
|
+
status: "error",
|
|
213
|
+
internalErrors: error ? [
|
|
214
|
+
...tree.internalErrors,
|
|
215
|
+
{
|
|
216
|
+
eventIndex: -1,
|
|
217
|
+
eventType: "sse_connection_failed",
|
|
218
|
+
message: error.message,
|
|
219
|
+
stack: error.stack
|
|
220
|
+
}
|
|
221
|
+
] : tree.internalErrors
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// src/view/AgentSession.tsx
|
|
229
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
230
|
+
function DebugPanel() {
|
|
231
|
+
const status = useSessionStatus();
|
|
232
|
+
const errors = useInternalErrors();
|
|
233
|
+
if (errors.length === 0) return null;
|
|
234
|
+
return /* @__PURE__ */ jsxs("div", { className: "lax-debug-panel", "data-testid": "lax-debug-panel", children: [
|
|
235
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
236
|
+
"status: ",
|
|
237
|
+
status
|
|
238
|
+
] }),
|
|
239
|
+
/* @__PURE__ */ jsx("ul", { children: errors.map((err, i) => /* @__PURE__ */ jsxs("li", { children: [
|
|
240
|
+
"[",
|
|
241
|
+
err.eventType,
|
|
242
|
+
"] ",
|
|
243
|
+
err.message
|
|
244
|
+
] }, `${err.eventIndex}-${i}`)) })
|
|
245
|
+
] });
|
|
246
|
+
}
|
|
247
|
+
function AgentSession({
|
|
248
|
+
source,
|
|
249
|
+
initialEvents,
|
|
250
|
+
registry,
|
|
251
|
+
tierOverrides: _tierOverrides,
|
|
252
|
+
onError,
|
|
253
|
+
autoReconnect: _autoReconnect,
|
|
254
|
+
debug = false,
|
|
255
|
+
virtualized = false,
|
|
256
|
+
virtualizeThreshold,
|
|
257
|
+
interactionBus,
|
|
258
|
+
toolDisplayRegistry,
|
|
259
|
+
defaultBodyMode = "preview",
|
|
260
|
+
groupParallelTools = false,
|
|
261
|
+
permissionUiMode = "standalone",
|
|
262
|
+
markdownRenderer,
|
|
263
|
+
displayMode = "normal",
|
|
264
|
+
verbose = false,
|
|
265
|
+
exploreFullscreenBash = true,
|
|
266
|
+
memoryDir = null,
|
|
267
|
+
workspaceRoot = null,
|
|
268
|
+
children
|
|
269
|
+
}) {
|
|
270
|
+
const storeRef = useRef(null);
|
|
271
|
+
if (storeRef.current === null) {
|
|
272
|
+
const replayOpts = {
|
|
273
|
+
tierOverrides: _tierOverrides,
|
|
274
|
+
collectDebug: debug
|
|
275
|
+
};
|
|
276
|
+
const initialTree = initialEvents && initialEvents.length > 0 ? replayEvents(initialEvents, replayOpts) : void 0;
|
|
277
|
+
storeRef.current = createSessionStore(initialTree, {
|
|
278
|
+
tierOverrides: _tierOverrides,
|
|
279
|
+
debug,
|
|
280
|
+
initialEventCount: initialEvents?.length ?? 0
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
const registryRef = useMemo(() => registry ?? createDefaultRegistry(), [registry]);
|
|
284
|
+
const busRef = useMemo(
|
|
285
|
+
() => interactionBus ?? getNoopInteractionBus(),
|
|
286
|
+
[interactionBus]
|
|
287
|
+
);
|
|
288
|
+
const toolDisplayRef = useMemo(
|
|
289
|
+
() => ({
|
|
290
|
+
registry: toolDisplayRegistry ?? createDefaultToolRegistry(),
|
|
291
|
+
defaultBodyMode
|
|
292
|
+
}),
|
|
293
|
+
[toolDisplayRegistry, defaultBodyMode]
|
|
294
|
+
);
|
|
295
|
+
const sessionViewRef = useMemo(
|
|
296
|
+
() => ({
|
|
297
|
+
...DEFAULT_SESSION_VIEW_OPTIONS,
|
|
298
|
+
groupParallelTools,
|
|
299
|
+
permissionUiMode,
|
|
300
|
+
verboseReasoning: debug,
|
|
301
|
+
displayMode,
|
|
302
|
+
verbose,
|
|
303
|
+
exploreFullscreenBash,
|
|
304
|
+
memoryDir,
|
|
305
|
+
workspaceRoot
|
|
306
|
+
}),
|
|
307
|
+
[
|
|
308
|
+
groupParallelTools,
|
|
309
|
+
permissionUiMode,
|
|
310
|
+
debug,
|
|
311
|
+
displayMode,
|
|
312
|
+
verbose,
|
|
313
|
+
exploreFullscreenBash,
|
|
314
|
+
memoryDir,
|
|
315
|
+
workspaceRoot
|
|
316
|
+
]
|
|
317
|
+
);
|
|
318
|
+
useEffect(() => {
|
|
319
|
+
const store = storeRef.current;
|
|
320
|
+
const controller = new AbortController();
|
|
321
|
+
void source.start((event, ctx) => {
|
|
322
|
+
store.getState().applyEvent(event, ctx);
|
|
323
|
+
}, controller.signal).catch((err) => {
|
|
324
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
325
|
+
store.getState().markAsError(error);
|
|
326
|
+
onError?.(error);
|
|
327
|
+
});
|
|
328
|
+
return () => {
|
|
329
|
+
controller.abort();
|
|
330
|
+
};
|
|
331
|
+
}, [source, onError]);
|
|
332
|
+
return /* @__PURE__ */ jsx(SessionStoreContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ jsx(InteractionBusContext.Provider, { value: busRef, children: /* @__PURE__ */ jsx(NodeRegistryContext.Provider, { value: registryRef, children: /* @__PURE__ */ jsx(MarkdownRendererContext.Provider, { value: markdownRenderer, children: /* @__PURE__ */ jsx(ToolDisplayOptionsContext.Provider, { value: toolDisplayRef, children: /* @__PURE__ */ jsx(SessionViewOptionsContext.Provider, { value: sessionViewRef, children: /* @__PURE__ */ jsxs("div", { className: "lax-agent-session", "data-testid": "lax-agent-session", children: [
|
|
333
|
+
children ?? /* @__PURE__ */ jsx(
|
|
334
|
+
SessionTimeline,
|
|
335
|
+
{
|
|
336
|
+
virtualized,
|
|
337
|
+
virtualizeThreshold,
|
|
338
|
+
groupParallelTools
|
|
339
|
+
}
|
|
340
|
+
),
|
|
341
|
+
debug ? /* @__PURE__ */ jsx(DebugPanel, {}) : null
|
|
342
|
+
] }) }) }) }) }) }) });
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// src/view/tools/groupParallelTools.ts
|
|
346
|
+
function buildTimelineEntries(rootIds, byId, options = {}) {
|
|
347
|
+
const filtered = options.hideStandalonePermissions ? rootIds.filter((id) => byId[id]?.kind !== "permission") : [...rootIds];
|
|
348
|
+
if (!options.groupParallelTools) {
|
|
349
|
+
return filtered.map((nodeId) => ({ kind: "node", nodeId }));
|
|
350
|
+
}
|
|
351
|
+
const entries = [];
|
|
352
|
+
let i = 0;
|
|
353
|
+
while (i < filtered.length) {
|
|
354
|
+
const id = filtered[i];
|
|
355
|
+
const node = byId[id];
|
|
356
|
+
if (node?.kind !== "tool_call") {
|
|
357
|
+
entries.push({ kind: "node", nodeId: id });
|
|
358
|
+
i += 1;
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
const toolName = node.toolName;
|
|
362
|
+
const groupIds = [id];
|
|
363
|
+
let j = i + 1;
|
|
364
|
+
while (j < filtered.length) {
|
|
365
|
+
const nextId = filtered[j];
|
|
366
|
+
const next = byId[nextId];
|
|
367
|
+
if (next?.kind !== "tool_call" || next.toolName !== toolName) break;
|
|
368
|
+
groupIds.push(nextId);
|
|
369
|
+
j += 1;
|
|
370
|
+
}
|
|
371
|
+
if (groupIds.length >= 2) {
|
|
372
|
+
entries.push({ kind: "tool_group", toolName, nodeIds: groupIds });
|
|
373
|
+
} else {
|
|
374
|
+
entries.push({ kind: "node", nodeId: id });
|
|
375
|
+
}
|
|
376
|
+
i = j;
|
|
377
|
+
}
|
|
378
|
+
return entries;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// src/view/nodes/SubAgentNode.tsx
|
|
382
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
383
|
+
function SubAgentBlock({ nodeId }) {
|
|
384
|
+
const node = useNodeTyped(nodeId, "subagent");
|
|
385
|
+
const childIds = useChildren(nodeId);
|
|
386
|
+
const registry = useNodeRegistry();
|
|
387
|
+
if (!node) return null;
|
|
388
|
+
return /* @__PURE__ */ jsxs2("div", { className: "lax-subagent-block", "data-status": node.status, children: [
|
|
389
|
+
/* @__PURE__ */ jsxs2("div", { className: "lax-subagent-block__header", children: [
|
|
390
|
+
"SubAgent: ",
|
|
391
|
+
node.subagentId
|
|
392
|
+
] }),
|
|
393
|
+
/* @__PURE__ */ jsx2("div", { className: "lax-subagent-block__children", children: childIds.map((childId) => /* @__PURE__ */ jsx2(TimelineItem, { nodeId: childId, registry }, childId)) })
|
|
394
|
+
] });
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/transport/createAgentxSseSource.ts
|
|
398
|
+
var EXPECTED_PROTOCOL_VERSION = "1";
|
|
399
|
+
function defaultOnError(error) {
|
|
400
|
+
console.error("[langchain_agentx_stream_ui] SSE error:", error);
|
|
401
|
+
}
|
|
402
|
+
function buildResumeStreamUrl(baseUrl, lastEventId, queryParam = "last_event_id") {
|
|
403
|
+
if (!lastEventId) return baseUrl;
|
|
404
|
+
const sep = baseUrl.includes("?") ? "&" : "?";
|
|
405
|
+
return `${baseUrl}${sep}${encodeURIComponent(queryParam)}=${encodeURIComponent(lastEventId)}`;
|
|
406
|
+
}
|
|
407
|
+
function createAgentxSseSource(options) {
|
|
408
|
+
const {
|
|
409
|
+
url,
|
|
410
|
+
onError = defaultOnError,
|
|
411
|
+
autoReconnect = true,
|
|
412
|
+
reconnectDelayMs = 1e3,
|
|
413
|
+
onLastEventId,
|
|
414
|
+
EventSourceImpl = EventSource
|
|
415
|
+
} = options;
|
|
416
|
+
return {
|
|
417
|
+
start(handler, signal) {
|
|
418
|
+
return new Promise((resolve, reject) => {
|
|
419
|
+
let es = null;
|
|
420
|
+
let handshakeOk = false;
|
|
421
|
+
let lastEventId = null;
|
|
422
|
+
let fatal = false;
|
|
423
|
+
let bufferedDelta = null;
|
|
424
|
+
let flushTimer = null;
|
|
425
|
+
const flushBufferedDelta = () => {
|
|
426
|
+
if (flushTimer) {
|
|
427
|
+
clearTimeout(flushTimer);
|
|
428
|
+
flushTimer = null;
|
|
429
|
+
}
|
|
430
|
+
if (!bufferedDelta) return;
|
|
431
|
+
handler(bufferedDelta.event, bufferedDelta.ctx);
|
|
432
|
+
bufferedDelta = null;
|
|
433
|
+
};
|
|
434
|
+
const isBufferedDeltaEvent = (event) => event.event_type === "text-delta" || event.event_type === "reasoning-delta";
|
|
435
|
+
const mergeDeltaEvent = (prev, next) => {
|
|
436
|
+
if (prev.event_type !== next.event_type) return null;
|
|
437
|
+
if (prev.step_index !== next.step_index) return null;
|
|
438
|
+
if (prev.tool_name !== next.tool_name) return null;
|
|
439
|
+
if (prev.session_id !== next.session_id) return null;
|
|
440
|
+
const prevData = prev.data;
|
|
441
|
+
const nextData = next.data;
|
|
442
|
+
const prevChunk = prevData.delta ?? prevData.text ?? prevData.content ?? "";
|
|
443
|
+
const nextChunk = nextData.delta ?? nextData.text ?? nextData.content ?? "";
|
|
444
|
+
return {
|
|
445
|
+
...next,
|
|
446
|
+
data: {
|
|
447
|
+
...next.data,
|
|
448
|
+
text: `${prevChunk}${nextChunk}`
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
};
|
|
452
|
+
const cleanup = () => {
|
|
453
|
+
es?.close();
|
|
454
|
+
es = null;
|
|
455
|
+
};
|
|
456
|
+
const finish = (error) => {
|
|
457
|
+
flushBufferedDelta();
|
|
458
|
+
cleanup();
|
|
459
|
+
if (error) reject(error);
|
|
460
|
+
else resolve();
|
|
461
|
+
};
|
|
462
|
+
const connect = (resumeFromId) => {
|
|
463
|
+
if (signal.aborted || fatal) {
|
|
464
|
+
finish();
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const connectUrl = resumeFromId != null && resumeFromId !== "" ? buildResumeStreamUrl(url, resumeFromId) : url;
|
|
468
|
+
es = new EventSourceImpl(connectUrl);
|
|
469
|
+
handshakeOk = false;
|
|
470
|
+
es.addEventListener("meta", (event) => {
|
|
471
|
+
try {
|
|
472
|
+
const meta = JSON.parse(event.data);
|
|
473
|
+
if (meta.protocol_version !== EXPECTED_PROTOCOL_VERSION) {
|
|
474
|
+
fatal = true;
|
|
475
|
+
const error = new Error(
|
|
476
|
+
`Unsupported protocol_version: ${meta.protocol_version}`
|
|
477
|
+
);
|
|
478
|
+
onError(error);
|
|
479
|
+
cleanup();
|
|
480
|
+
finish(error);
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
handshakeOk = true;
|
|
484
|
+
} catch (err) {
|
|
485
|
+
fatal = true;
|
|
486
|
+
const error = err instanceof Error ? err : new Error("Failed to decode meta frame");
|
|
487
|
+
onError(error);
|
|
488
|
+
cleanup();
|
|
489
|
+
finish(error);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
es.addEventListener("agentx", (event) => {
|
|
493
|
+
if (!handshakeOk) {
|
|
494
|
+
fatal = true;
|
|
495
|
+
const error = new Error("Received agentx frame before meta handshake");
|
|
496
|
+
onError(error);
|
|
497
|
+
cleanup();
|
|
498
|
+
finish(error);
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
try {
|
|
502
|
+
const agentEvent = JSON.parse(event.data);
|
|
503
|
+
const sseEventId = event.lastEventId || void 0;
|
|
504
|
+
if (sseEventId) {
|
|
505
|
+
lastEventId = sseEventId;
|
|
506
|
+
onLastEventId?.(sseEventId);
|
|
507
|
+
}
|
|
508
|
+
const ctx = sseEventId ? { sseEventId } : void 0;
|
|
509
|
+
if (isBufferedDeltaEvent(agentEvent)) {
|
|
510
|
+
if (bufferedDelta) {
|
|
511
|
+
const merged = mergeDeltaEvent(bufferedDelta.event, agentEvent);
|
|
512
|
+
if (merged) {
|
|
513
|
+
bufferedDelta = { event: merged, ctx };
|
|
514
|
+
} else {
|
|
515
|
+
flushBufferedDelta();
|
|
516
|
+
bufferedDelta = { event: agentEvent, ctx };
|
|
517
|
+
}
|
|
518
|
+
} else {
|
|
519
|
+
bufferedDelta = { event: agentEvent, ctx };
|
|
520
|
+
}
|
|
521
|
+
if (!flushTimer) {
|
|
522
|
+
flushTimer = setTimeout(() => {
|
|
523
|
+
flushBufferedDelta();
|
|
524
|
+
}, 16);
|
|
525
|
+
}
|
|
526
|
+
} else {
|
|
527
|
+
flushBufferedDelta();
|
|
528
|
+
handler(agentEvent, ctx);
|
|
529
|
+
}
|
|
530
|
+
} catch (err) {
|
|
531
|
+
onError(
|
|
532
|
+
new Error(
|
|
533
|
+
err instanceof Error ? `Failed to decode agentx frame: ${err.message}` : "Failed to decode agentx frame"
|
|
534
|
+
)
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
es.onerror = () => {
|
|
539
|
+
flushBufferedDelta();
|
|
540
|
+
if (signal.aborted || fatal) {
|
|
541
|
+
cleanup();
|
|
542
|
+
finish();
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
if (!autoReconnect) {
|
|
546
|
+
fatal = true;
|
|
547
|
+
const error = new Error("SSE connection error");
|
|
548
|
+
onError(error);
|
|
549
|
+
cleanup();
|
|
550
|
+
finish(error);
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
cleanup();
|
|
554
|
+
setTimeout(() => connect(lastEventId), reconnectDelayMs);
|
|
555
|
+
};
|
|
556
|
+
};
|
|
557
|
+
signal.addEventListener("abort", () => {
|
|
558
|
+
flushBufferedDelta();
|
|
559
|
+
fatal = true;
|
|
560
|
+
finish();
|
|
561
|
+
}, { once: true });
|
|
562
|
+
connect();
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
function createMockSource(events) {
|
|
568
|
+
return {
|
|
569
|
+
async start(handler, signal) {
|
|
570
|
+
for (const event of events) {
|
|
571
|
+
if (signal.aborted) break;
|
|
572
|
+
handler(event);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// src/transport/createReplaySource.ts
|
|
579
|
+
function sleep(ms, signal) {
|
|
580
|
+
if (ms <= 0) return Promise.resolve();
|
|
581
|
+
return new Promise((resolve) => {
|
|
582
|
+
const timer = setTimeout(resolve, ms);
|
|
583
|
+
signal.addEventListener(
|
|
584
|
+
"abort",
|
|
585
|
+
() => {
|
|
586
|
+
clearTimeout(timer);
|
|
587
|
+
resolve();
|
|
588
|
+
},
|
|
589
|
+
{ once: true }
|
|
590
|
+
);
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
function createReplaySource(events, opts) {
|
|
594
|
+
const delayMs = opts?.delayMs ?? 0;
|
|
595
|
+
return {
|
|
596
|
+
async start(handler, signal) {
|
|
597
|
+
for (const event of events) {
|
|
598
|
+
if (signal.aborted) break;
|
|
599
|
+
handler(event);
|
|
600
|
+
if (delayMs > 0) {
|
|
601
|
+
await sleep(delayMs, signal);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
export {
|
|
608
|
+
Agent,
|
|
609
|
+
AgentSession,
|
|
610
|
+
AgentToolBody,
|
|
611
|
+
AskUserQuestion,
|
|
612
|
+
AskUserQuestionToolBody,
|
|
613
|
+
Bash,
|
|
614
|
+
BashToolBody,
|
|
615
|
+
BodyBlockList,
|
|
616
|
+
CollapseKind,
|
|
617
|
+
CollapsedExploreNode,
|
|
618
|
+
DEFAULT_ESTIMATE_SIZE,
|
|
619
|
+
DEFAULT_EVENT_TIERS,
|
|
620
|
+
DEFAULT_SESSION_VIEW_OPTIONS,
|
|
621
|
+
DEFAULT_VIRTUALIZE_THRESHOLD,
|
|
622
|
+
DefaultToolBody,
|
|
623
|
+
DiffView,
|
|
624
|
+
EXPECTED_PROTOCOL_VERSION,
|
|
625
|
+
Edit,
|
|
626
|
+
EditToolBody,
|
|
627
|
+
ErrorCard,
|
|
628
|
+
ExploreCollapseAccumulator,
|
|
629
|
+
GROUPABLE_TOOL_NAMES,
|
|
630
|
+
Glob,
|
|
631
|
+
GlobToolBody,
|
|
632
|
+
Grep,
|
|
633
|
+
GrepToolBody,
|
|
634
|
+
GroupedToolUseAccumulator,
|
|
635
|
+
MAX_PREVIEW_LINES,
|
|
636
|
+
MIN_HINT_DISPLAY_MS,
|
|
637
|
+
MarkdownBlock,
|
|
638
|
+
MultiAgentSession,
|
|
639
|
+
NodeRegistry,
|
|
640
|
+
PermissionCard,
|
|
641
|
+
ProjectionContext,
|
|
642
|
+
Read,
|
|
643
|
+
ReadToolBody,
|
|
644
|
+
ReasoningBubble,
|
|
645
|
+
RenderableTimelineProjector,
|
|
646
|
+
SHELL_PROGRESS_MIN_ELAPSED_SECONDS,
|
|
647
|
+
SessionTimeline,
|
|
648
|
+
Skill,
|
|
649
|
+
SkillToolBody,
|
|
650
|
+
Spinner,
|
|
651
|
+
StepCard,
|
|
652
|
+
SubAgentBlock,
|
|
653
|
+
SystemSummaryAccumulator,
|
|
654
|
+
SystemSummaryNode,
|
|
655
|
+
TaskList,
|
|
656
|
+
TaskListFooter,
|
|
657
|
+
TextBubble,
|
|
658
|
+
Timeline,
|
|
659
|
+
TimelineItem,
|
|
660
|
+
ToolCallCard,
|
|
661
|
+
ToolDisplayRegistry,
|
|
662
|
+
ToolProjectionClassifier,
|
|
663
|
+
TruncatedContent,
|
|
664
|
+
UnknownCard,
|
|
665
|
+
VirtualTimeline,
|
|
666
|
+
WebFetch,
|
|
667
|
+
WebFetchToolBody,
|
|
668
|
+
WebSearch,
|
|
669
|
+
WebSearchToolBody,
|
|
670
|
+
Write,
|
|
671
|
+
WriteToolBody,
|
|
672
|
+
buildBashBodyBlocks,
|
|
673
|
+
buildCanonicalFromTree,
|
|
674
|
+
buildProjectionContext,
|
|
675
|
+
buildProjectionViewContext,
|
|
676
|
+
buildRelevantMemoriesCanonical,
|
|
677
|
+
buildResumeStreamUrl,
|
|
678
|
+
buildSystemEventCanonical,
|
|
679
|
+
buildTimelineEntries,
|
|
680
|
+
classifyEvent,
|
|
681
|
+
commandAsHint,
|
|
682
|
+
createActiveSessionBridge,
|
|
683
|
+
createAgentxSseSource,
|
|
684
|
+
createDefaultRegistry,
|
|
685
|
+
createDefaultToolRegistry,
|
|
686
|
+
createEmptyTree,
|
|
687
|
+
createInteractionBus,
|
|
688
|
+
createMockSource,
|
|
689
|
+
createMultiSessionStore,
|
|
690
|
+
createProjectionContext,
|
|
691
|
+
createReplaySource,
|
|
692
|
+
createSessionStore,
|
|
693
|
+
displayPath,
|
|
694
|
+
entryKey,
|
|
695
|
+
formatAgentTitle,
|
|
696
|
+
formatDiffFromStrings,
|
|
697
|
+
formatExploreSummaryText,
|
|
698
|
+
formatHookFinishedSummary,
|
|
699
|
+
formatPatternTitle,
|
|
700
|
+
formatSearchResultBody,
|
|
701
|
+
formatShellProgressSuffix,
|
|
702
|
+
formatTaskFooterLabel,
|
|
703
|
+
formatTimeoutFooter,
|
|
704
|
+
formatToolTitle,
|
|
705
|
+
getChildIds,
|
|
706
|
+
getMainStageIds,
|
|
707
|
+
getNoopInteractionBus,
|
|
708
|
+
isGitOperationCommand,
|
|
709
|
+
isGroupableToolName,
|
|
710
|
+
isMcpToolName,
|
|
711
|
+
iterMountCandidates,
|
|
712
|
+
parseDiffText,
|
|
713
|
+
projectCanonical,
|
|
714
|
+
projectTimeline,
|
|
715
|
+
reduceEvents,
|
|
716
|
+
reduceTree,
|
|
717
|
+
replayEvents,
|
|
718
|
+
replayTree,
|
|
719
|
+
resolveEffectiveToolBodyMode,
|
|
720
|
+
resolveEventTier,
|
|
721
|
+
resolveResponseId,
|
|
722
|
+
resolveShellProgressFromPayload,
|
|
723
|
+
resolveToolBody,
|
|
724
|
+
shouldApplyGrouping,
|
|
725
|
+
shouldShowExploreDetail,
|
|
726
|
+
shouldShowTaskListFooter,
|
|
727
|
+
streamChunk,
|
|
728
|
+
truncateCommand,
|
|
729
|
+
useActiveSession,
|
|
730
|
+
useChildren,
|
|
731
|
+
useInteractionBus,
|
|
732
|
+
useInternalErrors,
|
|
733
|
+
useMinDisplayTime,
|
|
734
|
+
useNode,
|
|
735
|
+
useNodeTyped,
|
|
736
|
+
useProjectedTimeline,
|
|
737
|
+
useReplayTree,
|
|
738
|
+
useSessionIds,
|
|
739
|
+
useSessionMeta,
|
|
740
|
+
useSessionStatus,
|
|
741
|
+
useTimeline
|
|
742
|
+
};
|
|
743
|
+
//# sourceMappingURL=index.js.map
|