langchain_agentx_stream_ui 0.1.2 → 0.1.3

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/dist/index.d.ts CHANGED
@@ -1024,20 +1024,21 @@ declare function reduceWorkflowSession(state: WorkflowSessionState, event: Langc
1024
1024
  /** 从空状态回放 workflow 事件序列。 */
1025
1025
  declare function reduceWorkflowEvents(events: LangchainAgentEvent[], options?: ReduceOptions): WorkflowSessionState;
1026
1026
 
1027
- /**
1028
- * workflowStructureEvents.ts Workflow 结构事件类型守卫
1029
- *
1030
- * 职责:
1031
- * 区分 workflow 编排结构 event_type 与 agent loop 事件。
1032
- *
1033
- * 链路位置:
1034
- * workflowReducer 路由 · Source application_kind 守卫(并行契约)。
1035
- *
1036
- * 当前裁剪范围:
1037
- * 与 backend WORKFLOW_STRUCTURE_EVENT_TYPES 对齐;不进 tier-1 白名单。
1038
- */
1027
+ /** 与 backend/langchain_agentx_stream_ui_backend/task_sync/multi_sse_bridge.py 对齐 */
1028
+ declare const WORKFLOW_STRUCTURE_EVENT_PREFIXES: readonly string[];
1029
+ /** 显式 SSOT(文档/契约测试);新增结构类型应同时满足前缀规则或补入此集合 */
1039
1030
  declare const WORKFLOW_STRUCTURE_EVENT_TYPES: ReadonlySet<string>;
1040
1031
  declare function isWorkflowStructureEventType(eventType: string): boolean;
1032
+ /** agent loop hydrate/replay 允许进入 reduceTree 的事件(正文 + state/debug tier) */
1033
+ declare function isAgentLoopReplayEventType(eventType: string): boolean;
1034
+ /**
1035
+ * hydrateLoopSession / 宿主 replay:
1036
+ * 1. 白名单:只保留 reduceTree 已知 event_type
1037
+ * 2. 结构前缀/集合:双重排除 workflow 编排帧(含 session_id 误绑的 dual emission)
1038
+ */
1039
+ declare function filterAgentLoopReplayEvents<T extends {
1040
+ event_type: string;
1041
+ }>(events: T[]): T[];
1041
1042
 
1042
1043
  /**
1043
1044
  * 职责:事件分级类型(V2-A classify 层公共契约)。
@@ -1067,4 +1068,4 @@ interface ClassifyContext {
1067
1068
  declare function resolveEventTier(eventType: string, overrides?: TierOverrides): EventTier;
1068
1069
  declare function classifyEvent(event: LangchainAgentEvent, ctx: ClassifyContext, overrides?: TierOverrides, eventIndex?: number): ClassifiedEvent;
1069
1070
 
1070
- export { Agent, AgentLoopView, type AgentLoopViewProps, AgentSession, type AgentSessionProps, type AgentxMetaFrame, type AgentxSseSourceOptions, type ApplicationKind, ApplicationKindMismatchError, AskUserQuestion, Bash, CanonicalNodeRef, type ClassifiedEvent, type ClassifyContext, CollapseKind, CollapsedExploreNode, type CollapsedExploreNodeProps, DEFAULT_WORKFLOW_SCALE_OPTIONS, DisplayMode, EXPECTED_PROTOCOL_VERSION, Edit, ErrorCard, EventTier, ExploreCollapseAccumulator, GROUPABLE_TOOL_NAMES, Glob, Grep, GroupedToolUseAccumulator, InteractionBus, LangchainAgentEvent, MIN_HINT_DISPLAY_MS, MarkdownRenderer, MermaidDiagram, type MermaidDiagramProps, type MermaidInitOptions, type MermaidThemeName, MissingApplicationKindError, NodeRegistry, PermissionCard, PermissionUiMode, PlantUMLBlock, type PlantUMLBlockProps, PlantUMLDiagram, type PlantUMLDiagramProps, type ProjectedTimelineItem, ProjectionContext, DisplayMode as ProjectionDisplayMode, Read, ReasoningBubble, type ReduceOptions, ReducerError, RenderableEntry, RenderableTimelineProjector, type ReplayOptions, type ReplaySourceOptions, RichMarkdown, type RichMarkdownProps, SHELL_PROGRESS_MIN_ELAPSED_SECONDS, SessionNode, SessionNodeKind, SessionStatus, SessionTree, Skill, Source, SourceEventContext, Spinner, type SpinnerProps, type SseTransportFailureKind, SseTransportTerminalError, StepCard, SubAgentBlock, SystemSummaryAccumulator, SystemSummaryNode, Task, TaskList, TaskListFooter, TextBubble, TierOverrides, Timeline, TimelineItem, ToolBodyMode, ToolCallCard, ToolDisplayRegistry, ToolProjectionClassifier, UnknownCard, WORKFLOW_STRUCTURE_EVENT_TYPES, WebFetch, WebSearch, WorkflowChrome, type WorkflowChromeProps, type WorkflowLoopReplayHandler, WorkflowLoopReplayProvider, type WorkflowProgressState, WorkflowScaleContext, type WorkflowScaleOptions, type WorkflowScopeFrame, WorkflowSession, type WorkflowSessionProps, type WorkflowSessionState, type WorkflowSessionStore, type WorkflowSessionStoreOptions, type WorkflowSessionStoreState, type WorkflowStageProgress, WorkflowTaskListFooter, Write, buildCanonicalFromTree, buildRelevantMemoriesCanonical, buildResumeStreamUrl, buildSystemEventCanonical, buildTimelineEntries, classifyEvent, commandAsHint, configureMermaid, configurePlantumlServer, createAgentxSseSource, createDefaultRegistry, createEmptyWorkflowSessionState, createMockSource, createReplaySource, createWorkflowSessionStore, entryKey, formatAgentTitle, formatExploreSummaryText, formatHookFinishedSummary, formatShellProgressSuffix, formatTaskFooterLabel, getChildIds, getMainStageIds, isGitOperationCommand, isGroupableToolName, isMcpToolName, isWorkflowStructureEventType, iterMountCandidates, partitionWorkflowStages, projectCanonical, projectTimeline, reduceAgentLoopEvent, reduceEvents, reduceTree, reduceWorkflowEvents, reduceWorkflowSession, replayEvents, replayTree, resolveEventTier, resolveResponseId, resolveShellProgressFromPayload, shouldShowTaskListFooter, streamChunk, useChildren, useInteractionBus, useInternalErrors, useMinDisplayTime, useNode, useNodeTyped, useProjectedTimeline, useReplayTree, useSessionMeta, useSessionStatus, useTimeline, useWorkflowSessionStatus, useWorkflowSessionStoreApi };
1071
+ export { Agent, AgentLoopView, type AgentLoopViewProps, AgentSession, type AgentSessionProps, type AgentxMetaFrame, type AgentxSseSourceOptions, type ApplicationKind, ApplicationKindMismatchError, AskUserQuestion, Bash, CanonicalNodeRef, type ClassifiedEvent, type ClassifyContext, CollapseKind, CollapsedExploreNode, type CollapsedExploreNodeProps, DEFAULT_WORKFLOW_SCALE_OPTIONS, DisplayMode, EXPECTED_PROTOCOL_VERSION, Edit, ErrorCard, EventTier, ExploreCollapseAccumulator, GROUPABLE_TOOL_NAMES, Glob, Grep, GroupedToolUseAccumulator, InteractionBus, LangchainAgentEvent, MIN_HINT_DISPLAY_MS, MarkdownRenderer, MermaidDiagram, type MermaidDiagramProps, type MermaidInitOptions, type MermaidThemeName, MissingApplicationKindError, NodeRegistry, PermissionCard, PermissionUiMode, PlantUMLBlock, type PlantUMLBlockProps, PlantUMLDiagram, type PlantUMLDiagramProps, type ProjectedTimelineItem, ProjectionContext, DisplayMode as ProjectionDisplayMode, Read, ReasoningBubble, type ReduceOptions, ReducerError, RenderableEntry, RenderableTimelineProjector, type ReplayOptions, type ReplaySourceOptions, RichMarkdown, type RichMarkdownProps, SHELL_PROGRESS_MIN_ELAPSED_SECONDS, SessionNode, SessionNodeKind, SessionStatus, SessionTree, Skill, Source, SourceEventContext, Spinner, type SpinnerProps, type SseTransportFailureKind, SseTransportTerminalError, StepCard, SubAgentBlock, SystemSummaryAccumulator, SystemSummaryNode, Task, TaskList, TaskListFooter, TextBubble, TierOverrides, Timeline, TimelineItem, ToolBodyMode, ToolCallCard, ToolDisplayRegistry, ToolProjectionClassifier, UnknownCard, WORKFLOW_STRUCTURE_EVENT_PREFIXES, WORKFLOW_STRUCTURE_EVENT_TYPES, WebFetch, WebSearch, WorkflowChrome, type WorkflowChromeProps, type WorkflowLoopReplayHandler, WorkflowLoopReplayProvider, type WorkflowProgressState, WorkflowScaleContext, type WorkflowScaleOptions, type WorkflowScopeFrame, WorkflowSession, type WorkflowSessionProps, type WorkflowSessionState, type WorkflowSessionStore, type WorkflowSessionStoreOptions, type WorkflowSessionStoreState, type WorkflowStageProgress, WorkflowTaskListFooter, Write, buildCanonicalFromTree, buildRelevantMemoriesCanonical, buildResumeStreamUrl, buildSystemEventCanonical, buildTimelineEntries, classifyEvent, commandAsHint, configureMermaid, configurePlantumlServer, createAgentxSseSource, createDefaultRegistry, createEmptyWorkflowSessionState, createMockSource, createReplaySource, createWorkflowSessionStore, entryKey, filterAgentLoopReplayEvents, formatAgentTitle, formatExploreSummaryText, formatHookFinishedSummary, formatShellProgressSuffix, formatTaskFooterLabel, getChildIds, getMainStageIds, isAgentLoopReplayEventType, isGitOperationCommand, isGroupableToolName, isMcpToolName, isWorkflowStructureEventType, iterMountCandidates, partitionWorkflowStages, projectCanonical, projectTimeline, reduceAgentLoopEvent, reduceEvents, reduceTree, reduceWorkflowEvents, reduceWorkflowSession, replayEvents, replayTree, resolveEventTier, resolveResponseId, resolveShellProgressFromPayload, shouldShowTaskListFooter, streamChunk, useChildren, useInteractionBus, useInternalErrors, useMinDisplayTime, useNode, useNodeTyped, useProjectedTimeline, useReplayTree, useSessionMeta, useSessionStatus, useTimeline, useWorkflowSessionStatus, useWorkflowSessionStoreApi };
package/dist/index.js CHANGED
@@ -1249,6 +1249,13 @@ function loopTaskScopeForStructureOpen(eventType) {
1249
1249
  }
1250
1250
 
1251
1251
  // src/core/workflowStructureEvents.ts
1252
+ var WORKFLOW_STRUCTURE_EVENT_PREFIXES = [
1253
+ "workflow-",
1254
+ "stage-",
1255
+ "parallel-",
1256
+ "route-",
1257
+ "subworkflow-"
1258
+ ];
1252
1259
  var WORKFLOW_STRUCTURE_EVENT_TYPES = /* @__PURE__ */ new Set([
1253
1260
  "workflow-start",
1254
1261
  "workflow-end",
@@ -1268,8 +1275,20 @@ var WORKFLOW_STRUCTURE_EVENT_TYPES = /* @__PURE__ */ new Set([
1268
1275
  "route-branch-done",
1269
1276
  "route-branch-failed"
1270
1277
  ]);
1278
+ var AGENT_LOOP_REPLAY_EVENT_TYPES = new Set(
1279
+ Object.keys(DEFAULT_EVENT_TIERS)
1280
+ );
1271
1281
  function isWorkflowStructureEventType(eventType) {
1272
- return WORKFLOW_STRUCTURE_EVENT_TYPES.has(eventType);
1282
+ if (WORKFLOW_STRUCTURE_EVENT_TYPES.has(eventType)) return true;
1283
+ return WORKFLOW_STRUCTURE_EVENT_PREFIXES.some((prefix) => eventType.startsWith(prefix));
1284
+ }
1285
+ function isAgentLoopReplayEventType(eventType) {
1286
+ return AGENT_LOOP_REPLAY_EVENT_TYPES.has(eventType);
1287
+ }
1288
+ function filterAgentLoopReplayEvents(events) {
1289
+ return events.filter(
1290
+ (event) => isAgentLoopReplayEventType(event.event_type) && !isWorkflowStructureEventType(event.event_type)
1291
+ );
1273
1292
  }
1274
1293
 
1275
1294
  // src/core/workflowReducer.ts
@@ -1421,16 +1440,17 @@ function findContainerByLoopSession(tree, loopSessionId) {
1421
1440
  return null;
1422
1441
  }
1423
1442
  var WORKFLOW_DEFAULT_LOOP_SESSION_ID = "workflow-loop-default";
1424
- function resolveAgentLoopSessionId(event) {
1443
+ function resolveAgentLoopSessionId(event, activeLoopSessionId) {
1425
1444
  if (event.session_id) return event.session_id;
1426
1445
  if (isWorkflowStructureEventType(event.event_type)) return null;
1427
1446
  if (event.event_type === "task-list-snapshot") return null;
1428
1447
  const derived = deriveLoopSessionIdFromAgentEvent(event);
1429
1448
  if (derived) return derived;
1449
+ if (activeLoopSessionId) return activeLoopSessionId;
1430
1450
  return WORKFLOW_DEFAULT_LOOP_SESSION_ID;
1431
1451
  }
1432
- function bindLoopSessionToContainerTree(tree, event) {
1433
- const sessionId = resolveAgentLoopSessionId(event);
1452
+ function bindLoopSessionToContainerTree(tree, event, activeLoopSessionId) {
1453
+ const sessionId = resolveAgentLoopSessionId(event, activeLoopSessionId);
1434
1454
  if (!sessionId) return tree;
1435
1455
  if (findContainerByLoopSession(tree, sessionId)) return tree;
1436
1456
  const data = event.data ?? {};
@@ -1536,8 +1556,12 @@ function reduceWorkflowSession(state, event, eventIndex, options) {
1536
1556
  if (isWorkflowStructureEventType(event.event_type)) {
1537
1557
  return applyStructureEvent(state, event);
1538
1558
  }
1539
- const loopSessionId = resolveAgentLoopSessionId(event) ?? WORKFLOW_DEFAULT_LOOP_SESSION_ID;
1540
- let containerTree = bindLoopSessionToContainerTree(state.containerTree, event);
1559
+ const loopSessionId = resolveAgentLoopSessionId(event, state.activeLoopSessionId) ?? WORKFLOW_DEFAULT_LOOP_SESSION_ID;
1560
+ let containerTree = bindLoopSessionToContainerTree(
1561
+ state.containerTree,
1562
+ event,
1563
+ state.activeLoopSessionId
1564
+ );
1541
1565
  containerTree = applyStructureToContainerTree(containerTree, event);
1542
1566
  let next = ensureLoopTree({ ...state, containerTree }, loopSessionId);
1543
1567
  const loopTree = next.loopTreesBySessionId[loopSessionId];
@@ -1812,7 +1836,7 @@ function createWorkflowSessionStore(initialState = createEmptyWorkflowSessionSta
1812
1836
  const { state, eventCount } = get();
1813
1837
  let tree = state.loopTreesBySessionId[loopSessionId] ?? createEmptyTree();
1814
1838
  let idx = eventCount;
1815
- for (const event of events) {
1839
+ for (const event of filterAgentLoopReplayEvents(events)) {
1816
1840
  tree = reduceTree(tree, event, idx, reduceOpts);
1817
1841
  idx += 1;
1818
1842
  }
@@ -3489,6 +3513,7 @@ export {
3489
3513
  TruncatedContent,
3490
3514
  UnknownCard,
3491
3515
  VirtualTimeline,
3516
+ WORKFLOW_STRUCTURE_EVENT_PREFIXES,
3492
3517
  WORKFLOW_STRUCTURE_EVENT_TYPES,
3493
3518
  WebFetch,
3494
3519
  WebFetchToolBody,
@@ -3528,6 +3553,7 @@ export {
3528
3553
  createWorkflowSessionStore,
3529
3554
  displayPath,
3530
3555
  entryKey,
3556
+ filterAgentLoopReplayEvents,
3531
3557
  formatAgentTitle,
3532
3558
  formatDiffFromStrings,
3533
3559
  formatExploreSummaryText,
@@ -3541,6 +3567,7 @@ export {
3541
3567
  getChildIds,
3542
3568
  getMainStageIds,
3543
3569
  getNoopInteractionBus,
3570
+ isAgentLoopReplayEventType,
3544
3571
  isGitOperationCommand,
3545
3572
  isGroupableToolName,
3546
3573
  isMcpToolName,