langchain_agentx_stream_ui 0.3.7 → 0.4.2

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.
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { b as ToolDisplayProps, T as ToolBodyComponent } from './types-BEXSHQG7.js';
3
- import { T as ToolDisplayRegistry } from './sessionViewOptions-DQRzPuN_.js';
2
+ import { b as ToolDisplayProps, T as ToolBodyComponent } from './types-DAkw2VOv.js';
3
+ import { T as ToolDisplayRegistry } from './sessionViewOptions-EIBugOkf.js';
4
4
 
5
5
  declare function DefaultToolBody({ result, bodyMode, onBodyModeChange, }: ToolDisplayProps): react_jsx_runtime.JSX.Element;
6
6
 
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { a as ToolBodyMode } from './types-BEXSHQG7.js';
2
+ import { a as ToolBodyMode } from './types-DAkw2VOv.js';
3
3
 
4
4
  declare const MAX_PREVIEW_LINES = 3;
5
5
  interface TruncatedContentProps {
@@ -24,7 +24,7 @@ import {
24
24
  useSessionStatus,
25
25
  useSessionViewOptions,
26
26
  useToolDisplayOptions
27
- } from "./chunk-24FLS4TF.js";
27
+ } from "./chunk-AY7QLXFB.js";
28
28
  import {
29
29
  createDefaultToolRegistry
30
30
  } from "./chunk-QL3DIGFI.js";
@@ -1897,4 +1897,4 @@ export {
1897
1897
  createActiveSessionBridge,
1898
1898
  MultiAgentSession
1899
1899
  };
1900
- //# sourceMappingURL=chunk-7QYE5PN5.js.map
1900
+ //# sourceMappingURL=chunk-7X7IF2A4.js.map
@@ -589,6 +589,38 @@ function agentToolNode(tree, parentNodeId) {
589
589
  const node = tree.byId[parentNodeId];
590
590
  return node?.kind === "tool_call" ? node : void 0;
591
591
  }
592
+ function warnSubagentOrphanParent(eventType, data) {
593
+ if (import.meta.env?.DEV) {
594
+ console.warn("[langchain_agentx_stream_ui] subagent orphan", {
595
+ eventType,
596
+ tool_call_id: data.tool_call_id,
597
+ agent_id: data.agent_id
598
+ });
599
+ }
600
+ }
601
+ function ensureSyntheticAgentToolParent(tree, parentNodeId, event, data) {
602
+ const existing = tree.byId[parentNodeId];
603
+ if (existing?.kind === "tool_call") return;
604
+ const toolCallId = parentNodeId.startsWith("tool:") ? parentNodeId.slice("tool:".length) : "";
605
+ if (!toolCallId) return;
606
+ const node = {
607
+ kind: "tool_call",
608
+ id: parentNodeId,
609
+ toolCallId,
610
+ toolName: "Agent",
611
+ input: data.subagent_type ? { subagent_type: data.subagent_type } : null,
612
+ status: "running",
613
+ startedAt: eventTimeToMs(event.timestamp),
614
+ endedAt: null,
615
+ result: null,
616
+ progress: null,
617
+ inputDelta: "",
618
+ onMainStage: true,
619
+ syntheticParent: true
620
+ };
621
+ tree.byId[parentNodeId] = node;
622
+ appendToActiveParent(tree, parentNodeId);
623
+ }
592
624
  function stepNameKey(event) {
593
625
  const step = event.step_index ?? 0;
594
626
  const name = event.tool_name ?? "unknown";
@@ -727,6 +759,7 @@ function finalizeStreamingNodes(tree) {
727
759
  }
728
760
  }
729
761
  function handleFinish(tree, event, seq) {
762
+ flushDeferredMainTextToTree(tree, event, seq);
730
763
  clearModelRetry(tree);
731
764
  const data = event.data;
732
765
  const endedAt = eventTimeToMs(event.timestamp);
@@ -1231,11 +1264,19 @@ function handleToolProgress(tree, event, parentNodeId, _seq) {
1231
1264
  }
1232
1265
  });
1233
1266
  }
1234
- function handleSubagentBoundaryStart(tree, event, parentNodeId) {
1235
- const tool = agentToolNode(tree, parentNodeId);
1236
- if (!tool || !parentNodeId) return;
1267
+ function handleSubagentBoundaryStart(tree, event, parentNodeId, options) {
1237
1268
  const data = event.data;
1238
- patchToolNode(tree, parentNodeId, {
1269
+ let parentId = parentNodeId;
1270
+ if (options?.syntheticAgentToolOnSubagentStart && data.tool_call_id && (!parentId || !agentToolNode(tree, parentId))) {
1271
+ parentId = `tool:${data.tool_call_id}`;
1272
+ ensureSyntheticAgentToolParent(tree, parentId, event, data);
1273
+ }
1274
+ const tool = agentToolNode(tree, parentId);
1275
+ if (!tool || !parentId) {
1276
+ warnSubagentOrphanParent("subagent-start", event.data);
1277
+ return;
1278
+ }
1279
+ patchToolNode(tree, parentId, {
1239
1280
  subagentSessions: upsertSubagentSession(tool.subagentSessions ?? {}, {
1240
1281
  agentId: data.agent_id,
1241
1282
  subagentType: data.subagent_type,
@@ -1247,7 +1288,10 @@ function handleSubagentBoundaryStart(tree, event, parentNodeId) {
1247
1288
  }
1248
1289
  function handleSubagentBoundaryEnd(tree, event, parentNodeId) {
1249
1290
  const tool = agentToolNode(tree, parentNodeId);
1250
- if (!tool || !parentNodeId) return;
1291
+ if (!tool || !parentNodeId) {
1292
+ warnSubagentOrphanParent("subagent-end", event.data);
1293
+ return;
1294
+ }
1251
1295
  const data = event.data;
1252
1296
  const existing = tool.subagentSessions?.[data.agent_id];
1253
1297
  patchToolNode(tree, parentNodeId, {
@@ -1262,7 +1306,10 @@ function handleSubagentBoundaryEnd(tree, event, parentNodeId) {
1262
1306
  }
1263
1307
  function handleSubagentToolCall(tree, _event, parentNodeId, data) {
1264
1308
  const tool = agentToolNode(tree, parentNodeId);
1265
- if (!tool || !parentNodeId) return;
1309
+ if (!tool || !parentNodeId) {
1310
+ warnSubagentOrphanParent("subagent-tool-call", data);
1311
+ return;
1312
+ }
1266
1313
  const toolInput = data.tool_input ?? (typeof data.input === "object" ? data.input : void 0);
1267
1314
  const nestedInput = toolInput && typeof toolInput === "object" && !Array.isArray(toolInput) ? toolInput : null;
1268
1315
  const childToolCallId = typeof data.child_tool_call_id === "string" && data.child_tool_call_id || (nestedInput && typeof nestedInput.tool_call_id === "string" ? nestedInput.tool_call_id : void 0);
@@ -1280,7 +1327,10 @@ function handleSubagentToolCall(tree, _event, parentNodeId, data) {
1280
1327
  }
1281
1328
  function handleSubagentToolResult(tree, _event, parentNodeId, data) {
1282
1329
  const tool = agentToolNode(tree, parentNodeId);
1283
- if (!tool || !parentNodeId) return;
1330
+ if (!tool || !parentNodeId) {
1331
+ warnSubagentOrphanParent("subagent-tool-result", data);
1332
+ return;
1333
+ }
1284
1334
  patchToolNode(tree, parentNodeId, {
1285
1335
  subagentProgress: applySubagentToolResult(tool.subagentProgress ?? [], {
1286
1336
  agentId: data.agent_id,
@@ -1529,7 +1579,7 @@ function applyClassified(tree, classified, eventIndex, options) {
1529
1579
  handleToolProgress(tree, event, parentNodeId, seq);
1530
1580
  break;
1531
1581
  case "subagent-start":
1532
- handleSubagentBoundaryStart(tree, event, parentNodeId);
1582
+ handleSubagentBoundaryStart(tree, event, parentNodeId, options);
1533
1583
  break;
1534
1584
  case "subagent-end":
1535
1585
  handleSubagentBoundaryEnd(tree, event, parentNodeId);
@@ -1722,6 +1772,78 @@ function replayTree(initialTree, events, options) {
1722
1772
  );
1723
1773
  }
1724
1774
 
1775
+ // src/core/workflow/workflowAuthoritySelectors.ts
1776
+ var AUTHORITY_TERMINAL = /* @__PURE__ */ new Set([
1777
+ "done",
1778
+ "error",
1779
+ "canceled",
1780
+ "partial_success"
1781
+ ]);
1782
+ function isAuthorityTerminalStatus(status) {
1783
+ return status != null && AUTHORITY_TERMINAL.has(status);
1784
+ }
1785
+ function isAuthorityTerminal(state) {
1786
+ return isAuthorityTerminalStatus(state.authority?.status);
1787
+ }
1788
+ function shouldShowGlobalSpinner(state) {
1789
+ const auth = state.authority?.status;
1790
+ if (auth === "canceled") return false;
1791
+ if (isAuthorityTerminalStatus(auth)) return false;
1792
+ if (state.display.awaitingAuthority) return false;
1793
+ if (auth == null || auth === "pending" || auth === "running") {
1794
+ return true;
1795
+ }
1796
+ const proj = state.display.projectionStatus;
1797
+ return proj === "running" || proj === "connecting";
1798
+ }
1799
+ function resolveWorkflowBanner(state) {
1800
+ if (state.display.authoritySubscribeFailed) {
1801
+ return { kind: "sync_failed", message: "\u72B6\u6001\u540C\u6B65\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5" };
1802
+ }
1803
+ if (state.display.authoritySyncFailed) {
1804
+ return { kind: "sync_failed", message: "\u540C\u6B65\u72B6\u6001\u5931\u8D25\uFF0C\u8BF7\u5237\u65B0" };
1805
+ }
1806
+ const auth = state.authority?.status;
1807
+ if (auth === "error") {
1808
+ return { kind: "authority_error", message: "Workflow \u6267\u884C\u5931\u8D25" };
1809
+ }
1810
+ if (state.snapshotHydrateFailed) {
1811
+ return {
1812
+ kind: "snapshot_unavailable",
1813
+ message: "\u65E0\u6CD5\u52A0\u8F7D projection snapshot\uFF0C\u5C55\u793A\u53EF\u80FD\u4E0D\u5B8C\u6574"
1814
+ };
1815
+ }
1816
+ if (state.display.awaitingAuthority) {
1817
+ return { kind: "awaiting_authority", message: "\u6536\u5C3E\u4E2D\u2026" };
1818
+ }
1819
+ if (auth === "partial_success") {
1820
+ const forced = state.display.terminalKind === "forced_closeout";
1821
+ return {
1822
+ kind: "partial_success",
1823
+ message: forced ? "\u90E8\u5206\u5B8C\u6210\uFF08\u90E8\u5206\u5BB9\u5668\u672A\u6B63\u5E38\u7ED3\u675F\uFF09" : "\u90E8\u5206\u5B8C\u6210\uFF08\u6240\u6709\u5BB9\u5668\u6B63\u5E38\u7ED3\u675F\uFF09"
1824
+ };
1825
+ }
1826
+ const meta = state.authority?.metadata;
1827
+ if (auth === "done" && meta?.projection_status === "degraded") {
1828
+ const dropped = meta.projection_dropped_count;
1829
+ const suffix = dropped != null && dropped > 0 ? `\uFF08\u7EA6 ${dropped} \u6761\u4E8B\u4EF6\u672A\u5B8C\u6574\u5C55\u793A\uFF09` : "";
1830
+ return {
1831
+ kind: "projection_degraded",
1832
+ message: `\u5C55\u793A\u53EF\u80FD\u4E0D\u5B8C\u6574${suffix}`
1833
+ };
1834
+ }
1835
+ if (state.display.terminalKind === "forced_closeout" && auth === "done") {
1836
+ return { kind: "forced_closeout", message: "Workflow \u5DF2\u7ED3\u675F\uFF08\u90E8\u5206\u5BB9\u5668\u672A\u6B63\u5E38\u5173\u95ED\uFF09" };
1837
+ }
1838
+ return { kind: "none", message: "" };
1839
+ }
1840
+ function getDisplayProjectionStatus(state) {
1841
+ return state.display.projectionStatus;
1842
+ }
1843
+ function applyAuthoritySnapshotToState(state, snapshot) {
1844
+ return { ...state, authority: snapshot };
1845
+ }
1846
+
1725
1847
  // src/core/projection/renderModel.ts
1726
1848
  var ProjectionContext = class _ProjectionContext {
1727
1849
  displayMode;
@@ -3779,6 +3901,14 @@ function useSessionMeta() {
3779
3901
  const store = useSessionStoreApi();
3780
3902
  return useStore5(store, (state) => state.tree.meta);
3781
3903
  }
3904
+ function useAgentAuthority() {
3905
+ const store = useSessionStoreApi();
3906
+ return useStore5(store, (state) => state.authority);
3907
+ }
3908
+ function useAgentAuthoritySubscribeFailed() {
3909
+ const store = useSessionStoreApi();
3910
+ return useStore5(store, (state) => state.authoritySubscribeFailed);
3911
+ }
3782
3912
 
3783
3913
  // src/view/hooks/useMinDisplayTime.ts
3784
3914
  import { useEffect, useRef, useState } from "react";
@@ -3944,6 +4074,18 @@ function SystemSummaryNode({ summaryText }) {
3944
4074
  return /* @__PURE__ */ jsx3("div", { className: "lax-system-summary", "data-kind": "system_summary", children: summaryText });
3945
4075
  }
3946
4076
 
4077
+ // src/core/agent/agentAuthoritySelectors.ts
4078
+ function shouldShowAgentSpinner(state) {
4079
+ if (!state.authorityBindingActive) {
4080
+ const status = state.tree.status;
4081
+ return status === "running" || status === "connecting";
4082
+ }
4083
+ const auth = state.authority?.status;
4084
+ if (auth === "canceled") return false;
4085
+ if (isAuthorityTerminalStatus(auth)) return false;
4086
+ return true;
4087
+ }
4088
+
3947
4089
  // src/view/TaskList.tsx
3948
4090
  import { useEffect as useEffect3, useMemo as useMemo4, useRef as useRef2, useState as useState3 } from "react";
3949
4091
 
@@ -4822,7 +4964,11 @@ function Spinner({
4822
4964
  }) {
4823
4965
  const status = useSessionStatus();
4824
4966
  const store = useSessionStoreApi();
4825
- const isRunning = status === "running" || status === "connecting";
4967
+ const showSpinner = useSyncExternalStore(
4968
+ (callback) => store.subscribe(callback),
4969
+ () => shouldShowAgentSpinner(store.getState())
4970
+ );
4971
+ const isRunning = showSpinner;
4826
4972
  const activeRoundId = useSyncExternalStore(
4827
4973
  (callback) => store.subscribe(callback),
4828
4974
  () => store.getState().tree.activeRoundId
@@ -5491,6 +5637,12 @@ export {
5491
5637
  getChildIds,
5492
5638
  replayEvents,
5493
5639
  replayTree,
5640
+ isAuthorityTerminalStatus,
5641
+ isAuthorityTerminal,
5642
+ shouldShowGlobalSpinner,
5643
+ resolveWorkflowBanner,
5644
+ getDisplayProjectionStatus,
5645
+ applyAuthoritySnapshotToState,
5494
5646
  ProjectionContext,
5495
5647
  createProjectionContext,
5496
5648
  DEFAULT_SESSION_VIEW_OPTIONS,
@@ -5542,11 +5694,14 @@ export {
5542
5694
  useSessionStatus,
5543
5695
  useInternalErrors,
5544
5696
  useSessionMeta,
5697
+ useAgentAuthority,
5698
+ useAgentAuthoritySubscribeFailed,
5545
5699
  MIN_HINT_DISPLAY_MS,
5546
5700
  useMinDisplayTime,
5547
5701
  TimelineItem,
5548
5702
  CollapsedExploreNode,
5549
5703
  SystemSummaryNode,
5704
+ shouldShowAgentSpinner,
5550
5705
  TaskList,
5551
5706
  Spinner,
5552
5707
  formatTaskFooterLabel,
@@ -5560,4 +5715,4 @@ export {
5560
5715
  VirtualTimeline,
5561
5716
  SessionTimeline
5562
5717
  };
5563
- //# sourceMappingURL=chunk-24FLS4TF.js.map
5718
+ //# sourceMappingURL=chunk-AY7QLXFB.js.map