langchain_agentx_stream_ui 0.1.0 → 0.1.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.
package/dist/index.d.ts CHANGED
@@ -1,17 +1,18 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
2
3
  import { ReactNode } from 'react';
3
- import { q as Source, L as LangchainAgentEvent, N as NodeRegistry, v as TierOverrides, I as InteractionBus, M as MarkdownRenderer, T as Task, t as TaskPhase, l as SessionStatus, p as SessionTree, R as ReducerError, E as EventTier } from './multi-session-CviqerRl.js';
4
- export { C as CommonFields, D as DEFAULT_EVENT_TIERS, a as EventType, b as InteractionBusHandlers, c as MarkdownRendererProps, d as MultiAgentSession, e as MultiAgentSessionProps, f as MultiSessionSourceConfig, g as MultiSessionStore, h as MultiSessionStoreOptions, i as MultiSessionStoreState, j as NodeWidget, k as NodeWidgetProps, P as PermissionResolvePayload, S as SessionSlice, m as SessionStore, n as SessionStoreOptions, o as SessionStoreState, r as SourceEventContext, s as SourceHandler, u as TaskStatus, w as createActiveSessionBridge, x as createEmptyTree, y as createInteractionBus, z as createMultiSessionStore, A as createSessionStore, B as getNoopInteractionBus, F as useActiveSession, G as useSessionIds } from './multi-session-CviqerRl.js';
4
+ import { q as Source, L as LangchainAgentEvent, N as NodeRegistry, v as TierOverrides, I as InteractionBus, M as MarkdownRenderer, p as SessionTree, l as SessionStatus, R as ReducerError, r as SourceEventContext, T as Task, t as TaskPhase, E as EventTier } from './multi-session-DAHwfTNb.js';
5
+ export { C as CommonFields, D as DEFAULT_EVENT_TIERS, a as EventType, b as InteractionBusHandlers, c as MarkdownRendererProps, d as MultiAgentSession, e as MultiAgentSessionProps, f as MultiSessionSourceConfig, g as MultiSessionStore, h as MultiSessionStoreOptions, i as MultiSessionStoreState, j as NodeWidget, k as NodeWidgetProps, P as PermissionResolvePayload, S as SessionSlice, m as SessionStore, n as SessionStoreOptions, o as SessionStoreState, s as SourceHandler, u as TaskStatus, w as createActiveSessionBridge, x as createEmptyTree, y as createInteractionBus, z as createMultiSessionStore, A as createSessionStore, B as getNoopInteractionBus, F as useActiveSession, G as useSessionIds } from './multi-session-DAHwfTNb.js';
5
6
  import { T as ToolDisplayRegistry, P as PermissionUiMode, b as DisplayMode, c as ProjectionContext, R as RenderableEntry, C as CanonicalNodeRef } from './sessionViewOptions-DLSFRQwZ.js';
6
7
  export { a as CollapsedExplorePayload, D as DEFAULT_SESSION_VIEW_OPTIONS, S as SessionViewOptions, d as ToolUseSnapshot, e as buildProjectionContext, f as buildProjectionViewContext, g as createDefaultToolRegistry, h as createProjectionContext, r as resolveEffectiveToolBodyMode, s as shouldApplyGrouping, i as shouldShowExploreDetail } from './sessionViewOptions-DLSFRQwZ.js';
7
8
  import { a as ToolBodyMode } from './types-aXj5TYSP.js';
8
9
  export { T as ToolBodyComponent, b as ToolDisplayProps } from './types-aXj5TYSP.js';
10
+ import { StoreApi } from 'zustand/vanilla';
9
11
  export { DEFAULT_ESTIMATE_SIZE, DEFAULT_VIRTUALIZE_THRESHOLD, SessionTimeline, SessionTimelineProps, VirtualTimeline, VirtualTimelineProps } from './virtual.js';
10
12
  export { A as AgentToolBody, a as AskUserQuestionToolBody, B as BashToolBody, D as DefaultToolBody, E as EditToolBody, G as GlobToolBody, b as GrepToolBody, R as ReadToolBody, S as SkillToolBody, W as WebFetchToolBody, c as WebSearchToolBody, d as WriteToolBody, f as formatToolTitle, r as resolveToolBody } from './AskUserQuestionToolBody-CyuNy_k5.js';
11
13
  import { S as SessionNode, a as SessionNodeKind } from './nodes-DqhaBW7M.js';
12
14
  export { E as ErrorNode, N as NodeDetail, P as PermissionNode, R as ReasoningNode, b as StepDetail, c as StepNode, d as SubAgentNode, T as TextNode, g as ToolCallNode, U as UnknownNode } from './nodes-DqhaBW7M.js';
13
15
  export { B as BodyBlock, a as BodyBlockList, D as DiffView, M as MAX_PREVIEW_LINES, b as MarkdownBlock, T as TruncatedContent, c as buildBashBodyBlocks, d as displayPath, f as formatDiffFromStrings, e as formatPatternTitle, g as formatSearchResultBody, h as formatTimeoutFooter, p as parseDiffText, t as truncateCommand } from './MarkdownBlock-3iEW0Ubm.js';
14
- import 'zustand/vanilla';
15
16
 
16
17
  interface AgentSessionProps {
17
18
  source: Source;
@@ -48,13 +49,291 @@ interface AgentSessionProps {
48
49
  }
49
50
  declare function AgentSession({ source, initialEvents, registry, tierOverrides: _tierOverrides, onError, autoReconnect: _autoReconnect, debug, virtualized, virtualizeThreshold, interactionBus, toolDisplayRegistry, defaultBodyMode, groupParallelTools, permissionUiMode, markdownRenderer, displayMode, verbose, exploreFullscreenBash, memoryDir, workspaceRoot, children, }: AgentSessionProps): react_jsx_runtime.JSX.Element;
50
51
 
52
+ interface AgentLoopViewProps {
53
+ /** 传入时使用隔离 store(workflow scoped);省略则使用上层 SessionStoreContext */
54
+ tree?: SessionTree;
55
+ showTaskListFooter?: boolean;
56
+ virtualized?: boolean;
57
+ virtualizeThreshold?: number;
58
+ groupParallelTools?: boolean;
59
+ }
60
+ declare function AgentLoopView({ tree, showTaskListFooter, virtualized, virtualizeThreshold, groupParallelTools, }: AgentLoopViewProps): react_jsx_runtime.JSX.Element;
61
+
62
+ /** 宿主按需 replay 某 loopSessionId 的事件(P2 懒加载) */
63
+ type WorkflowLoopReplayHandler = (loopSessionId: string) => void | Promise<void>;
64
+ declare function WorkflowLoopReplayProvider({ onRequestLoopReplay, children, }: {
65
+ onRequestLoopReplay?: WorkflowLoopReplayHandler;
66
+ children: ReactNode;
67
+ }): react_jsx_runtime.JSX.Element;
68
+
69
+ /** Workflow 大规模编排 UI 缩放选项(P1–P4) */
70
+ interface WorkflowScaleOptions {
71
+ /** P1:根 stage 列表超过此数量启用虚拟滚动 */
72
+ stageVirtualizeThreshold: number;
73
+ /** P3:默认展示的 done stage 上限(running/failed/pending 始终展示) */
74
+ stagePageSize: number;
75
+ /** P2:completed 且未 pin 的 loop 树移出内存,保留摘要 */
76
+ evictCompletedLoops: boolean;
77
+ /** P4:running 容器仅 active 自动展开 AgentLoopView */
78
+ onlyExpandActiveRunning: boolean;
79
+ /** Parallel 组内 item 虚拟滚动阈值 */
80
+ parallelItemVirtualizeThreshold: number;
81
+ }
82
+ declare const DEFAULT_WORKFLOW_SCALE_OPTIONS: WorkflowScaleOptions;
83
+
84
+ interface WorkflowSessionProps {
85
+ source: Source;
86
+ initialEvents?: LangchainAgentEvent[];
87
+ registry?: NodeRegistry;
88
+ tierOverrides?: TierOverrides;
89
+ onError?: (error: Error) => void;
90
+ interactionBus?: InteractionBus;
91
+ toolDisplayRegistry?: ToolDisplayRegistry;
92
+ defaultBodyMode?: ToolBodyMode;
93
+ permissionUiMode?: PermissionUiMode;
94
+ markdownRenderer?: MarkdownRenderer;
95
+ displayMode?: DisplayMode;
96
+ verbose?: boolean;
97
+ exploreFullscreenBash?: boolean;
98
+ memoryDir?: string | null;
99
+ workspaceRoot?: string | null;
100
+ virtualized?: boolean;
101
+ virtualizeThreshold?: number;
102
+ groupParallelTools?: boolean;
103
+ /** P1–P4:大规模 workflow 缩放选项 */
104
+ workflowScale?: Partial<WorkflowScaleOptions>;
105
+ /** P2:展开已淘汰 loop 时由宿主 replay 事件 */
106
+ onRequestLoopReplay?: WorkflowLoopReplayHandler;
107
+ children?: ReactNode;
108
+ }
109
+ declare function WorkflowSession({ source, initialEvents, registry, tierOverrides, onError, interactionBus, toolDisplayRegistry, defaultBodyMode, permissionUiMode, markdownRenderer, displayMode, verbose, exploreFullscreenBash, memoryDir, workspaceRoot, virtualized, virtualizeThreshold, groupParallelTools, workflowScale, onRequestLoopReplay, children, }: WorkflowSessionProps): react_jsx_runtime.JSX.Element;
110
+
111
+ declare const WorkflowScaleContext: react.Context<WorkflowScaleOptions>;
112
+
113
+ /**
114
+ * workflowDisplay.ts — SDK WorkflowDisplayPayload 契约(TS)
115
+ *
116
+ * 职责:
117
+ * 对齐 langchain_agentx WorkflowDisplayPayload;结构事件 data.display 类型。
118
+ *
119
+ * 链路位置:
120
+ * workflowContainerProjector → WorkflowChrome(P2+)。
121
+ *
122
+ * 当前裁剪范围:
123
+ * 只读消费;不计算 display(由 SDK enricher 注入)。
124
+ */
125
+ type WorkflowDisplayScope = 'workflow' | 'stage' | 'item' | 'branch' | 'aggregate' | 'subworkflow';
126
+ type WorkflowDisplayStatus = 'pending' | 'running' | 'completed' | 'failed' | 'skipped' | 'cancelled' | 'blocked' | 'retrying';
127
+ /** 对齐 SDK display_resolver.WorkflowDisplayPayload */
128
+ interface WorkflowDisplayPayload {
129
+ version?: number;
130
+ scope?: WorkflowDisplayScope;
131
+ title?: string;
132
+ description?: string;
133
+ workflow_title?: string;
134
+ workflow_description?: string;
135
+ parent_title?: string;
136
+ breadcrumb?: string[];
137
+ progress_current?: number;
138
+ progress_total?: number;
139
+ progress_label?: string;
140
+ progress_indeterminate?: boolean;
141
+ status?: WorkflowDisplayStatus;
142
+ status_reason?: string;
143
+ icon?: string;
144
+ item_index?: number;
145
+ item_total?: number;
146
+ metrics_completed?: number;
147
+ metrics_running?: number;
148
+ metrics_failed?: number;
149
+ metrics_total?: number;
150
+ decision_label?: string;
151
+ pattern?: string;
152
+ debug_key?: string;
153
+ }
154
+
155
+ /**
156
+ * workflowContainer.ts — Workflow 容器树投影类型
157
+ *
158
+ * 职责:
159
+ * 容器节点、正文块、快照;对齐 SDK workflow_container_projector。
160
+ *
161
+ * 链路位置:
162
+ * workflowContainerProjector → workflowReducer(P1+)→ WorkflowChrome(P2+)。
163
+ *
164
+ * 当前裁剪范围:
165
+ * 不含 React 视图 props;仅投影层 state。
166
+ */
167
+
168
+ type WorkflowContainerScope = 'workflow' | 'stage' | 'item' | 'branch' | 'aggregate' | 'subworkflow';
169
+ type WorkflowContainerStatus = 'pending' | 'running' | 'completed' | 'failed' | 'skipped' | 'cancelled' | 'blocked' | 'retrying';
170
+ type ContentBlockKind = 'reasoning' | 'text' | 'tool';
171
+ interface WorkflowContentBlock {
172
+ kind: ContentBlockKind;
173
+ preview: string;
174
+ tool_name: string | null;
175
+ }
176
+ interface WorkflowContainerNode {
177
+ container_id: string;
178
+ scope: WorkflowContainerScope;
179
+ workflow_path: string;
180
+ workflow_depth: number;
181
+ scope_key: string;
182
+ title: string;
183
+ subtitle: string;
184
+ status: WorkflowContainerStatus;
185
+ pattern: string;
186
+ parent_container_id: string | null;
187
+ display: WorkflowDisplayPayload | null;
188
+ content_blocks: WorkflowContentBlock[];
189
+ is_open: boolean;
190
+ }
191
+ /** reducer 运行时节点:投影字段 + loop 绑定(P1) */
192
+ interface WorkflowContainerRuntimeNode extends WorkflowContainerNode {
193
+ loopSessionId: string | null;
194
+ }
195
+ /** WorkflowSession 容器树 state(P1+) */
196
+ interface WorkflowContainerTreeState {
197
+ rootContainerIds: string[];
198
+ activeContainerIds: string[];
199
+ containersById: Record<string, WorkflowContainerRuntimeNode>;
200
+ }
201
+
202
+ interface WorkflowStageListPartition {
203
+ visible: WorkflowContainerRuntimeNode[];
204
+ hiddenCount: number;
205
+ total: number;
206
+ }
207
+ /** P3:running / failed / pending 全显;done 仅保留最近 pageSize 条 */
208
+ declare function partitionWorkflowStages(stages: WorkflowContainerRuntimeNode[], pageSize: number, showAll: boolean): WorkflowStageListPartition;
209
+
210
+ /**
211
+ * workflowSession.ts — Workflow 会话顶层状态
212
+ *
213
+ * 职责:
214
+ * 定义 /workflow 页专用 WorkflowSessionState(与 /chat SessionTree 隔离)。
215
+ *
216
+ * 链路位置:
217
+ * workflowReducer → workflowSessionStore → WorkflowSession / WorkflowChrome。
218
+ *
219
+ * 当前裁剪范围:
220
+ * 不含合并 TaskListFooter(P3);parallel 结构仅基础字段。
221
+ */
222
+
223
+ /** P2:stage 完成摘要缓存(loop 树淘汰后仍显示 teaser) */
224
+ interface CachedStageDoneSummary {
225
+ label: string;
226
+ teaser: string;
227
+ extraLines: number;
228
+ }
229
+ type WorkflowRunStatus = 'running' | 'done' | 'error';
230
+ interface WorkflowStageProgress {
231
+ stageKey: string;
232
+ stageIndex: number;
233
+ stageTotal?: number;
234
+ status: 'pending' | 'running' | 'done' | 'failed';
235
+ error?: string;
236
+ }
237
+ interface ParallelItemProgress {
238
+ itemKey: string;
239
+ itemIndex: number;
240
+ itemTotal?: number;
241
+ status: 'pending' | 'running' | 'done' | 'failed';
242
+ loopSessionId: string | null;
243
+ error?: string;
244
+ }
245
+ interface WorkflowProgressState {
246
+ workflowId: string | null;
247
+ workflowPath: string | null;
248
+ status: WorkflowRunStatus;
249
+ stages: WorkflowStageProgress[];
250
+ parallelItems: Record<string, ParallelItemProgress>;
251
+ }
252
+ type WorkflowScopeKind = 'stage' | 'parallel-item' | 'subworkflow';
253
+ interface WorkflowScopeFrame {
254
+ kind: WorkflowScopeKind;
255
+ key: string;
256
+ loopSessionId: string | null;
257
+ }
258
+ interface WorkflowSessionState {
259
+ status: SessionStatus;
260
+ meta: {
261
+ workflowRunId: string | null;
262
+ startedAt: number | null;
263
+ lastEventId: string | null;
264
+ };
265
+ /** SDK 容器树投影 + loopSessionId 绑定(P1 主模型) */
266
+ containerTree: WorkflowContainerTreeState;
267
+ /** 过渡期 dual-write;P2+ UI 逐步改读 containerTree */
268
+ workflowProgress: WorkflowProgressState;
269
+ loopTreesBySessionId: Record<string, SessionTree>;
270
+ /** P2:container_id → done 摘要(loop 淘汰后) */
271
+ stageDoneSummariesByContainerId: Record<string, CachedStageDoneSummary>;
272
+ activeLoopSessionId: string | null;
273
+ /** @deprecated P1 起由 containerTree.activeContainerIds 替代 */
274
+ openScopeStack: WorkflowScopeFrame[];
275
+ internalErrors: ReducerError[];
276
+ }
277
+ declare function createEmptyWorkflowSessionState(): WorkflowSessionState;
278
+
279
+ /**
280
+ * workflowSessionStore.ts — Workflow 页 zustand store
281
+ *
282
+ * 职责:
283
+ * Source 事件写入 WorkflowSessionState;与 SessionStore 平行隔离。
284
+ *
285
+ * 链路位置:
286
+ * WorkflowSession Provider → applyEvent。
287
+ *
288
+ * 当前裁剪范围:
289
+ * 无多会话 Tab;dedupe 与 SessionStore 同构。
290
+ */
291
+
292
+ interface WorkflowSessionStoreOptions {
293
+ tierOverrides?: TierOverrides;
294
+ initialEventCount?: number;
295
+ initialSeenEventIds?: Iterable<string>;
296
+ /** P2:completed loop 树内存淘汰(默认 true) */
297
+ evictCompletedLoops?: boolean;
298
+ }
299
+ interface WorkflowSessionStoreState {
300
+ state: WorkflowSessionState;
301
+ eventCount: number;
302
+ applyEvent: (event: LangchainAgentEvent, ctx?: SourceEventContext) => void;
303
+ applyEvents: (events: LangchainAgentEvent[]) => void;
304
+ reset: () => void;
305
+ markAsError: (error?: Error) => void;
306
+ /** P2:展开 done stage 时 pin,避免淘汰 */
307
+ pinLoopSession: (loopSessionId: string) => void;
308
+ /** P2:宿主 replay 后灌入 loop 树 */
309
+ hydrateLoopSession: (loopSessionId: string, events: LangchainAgentEvent[]) => void;
310
+ }
311
+ type WorkflowSessionStore = StoreApi<WorkflowSessionStoreState>;
312
+ declare function createWorkflowSessionStore(initialState?: WorkflowSessionState, storeOptions?: WorkflowSessionStoreOptions): WorkflowSessionStore;
313
+
314
+ declare function useWorkflowSessionStoreApi(): WorkflowSessionStore;
315
+ declare function useWorkflowSessionStatus(): SessionStatus;
316
+
317
+ interface WorkflowChromeProps {
318
+ containerTree: WorkflowContainerTreeState;
319
+ loopTreesBySessionId?: Record<string, SessionTree>;
320
+ virtualized?: boolean;
321
+ virtualizeThreshold?: number;
322
+ groupParallelTools?: boolean;
323
+ }
324
+ declare function WorkflowChrome({ containerTree, loopTreesBySessionId, virtualized, virtualizeThreshold, groupParallelTools, }: WorkflowChromeProps): react_jsx_runtime.JSX.Element;
325
+
326
+ declare function WorkflowTaskListFooter(): react_jsx_runtime.JSX.Element | null;
327
+
51
328
  interface TimelineItemProps {
52
329
  nodeId: string;
53
330
  registry: NodeRegistry;
54
331
  }
55
332
  declare function TimelineItem({ nodeId, registry }: TimelineItemProps): react_jsx_runtime.JSX.Element | null;
56
333
 
57
- declare function Timeline(): react_jsx_runtime.JSX.Element;
334
+ declare function Timeline({ showTaskListFooter }: {
335
+ showTaskListFooter?: boolean;
336
+ }): react_jsx_runtime.JSX.Element;
58
337
 
59
338
  interface SpinnerElapsedInput {
60
339
  /** 当前 wall-clock(ms) */
@@ -164,6 +443,8 @@ declare function streamChunk(data: {
164
443
  }): string;
165
444
  /** Pure reducer: tree + event → new tree. */
166
445
  declare function reduceTree(tree: SessionTree, event: LangchainAgentEvent, eventIndex: number, options?: ReduceOptions): SessionTree;
446
+ /** Agent loop 归约(/chat 根树与 workflow per-loop 子树共用)。 */
447
+ declare const reduceAgentLoopEvent: typeof reduceTree;
167
448
  /** Reduce a sequence of events from empty tree. */
168
449
  declare function reduceEvents(events: LangchainAgentEvent[], options?: ReduceOptions): SessionTree;
169
450
  /** Collect main-stage node ids for Timeline rendering. */
@@ -469,6 +750,53 @@ declare function buildTimelineEntries(rootIds: string[], byId: Record<string, Se
469
750
 
470
751
  declare function formatAgentTitle(input: unknown, display: unknown): string;
471
752
 
753
+ interface RichMarkdownProps {
754
+ content: string;
755
+ className?: string;
756
+ }
757
+ /** Web 向富 Markdown(TextNode S1);含 Mermaid、GFM、代码高亮。 */
758
+ declare function RichMarkdown({ content, className }: RichMarkdownProps): react_jsx_runtime.JSX.Element | null;
759
+
760
+ interface MermaidDiagramProps {
761
+ chart: string;
762
+ className?: string;
763
+ /** 画布内 svg-pan-zoom */
764
+ zoomingEnabled?: boolean;
765
+ /** 工具栏全屏与点击放大 */
766
+ fullscreenEnabled?: boolean;
767
+ }
768
+ declare function MermaidDiagram({ chart, className, zoomingEnabled, fullscreenEnabled, }: MermaidDiagramProps): react_jsx_runtime.JSX.Element;
769
+
770
+ type MermaidThemeName = 'neutral' | 'default' | 'dark' | 'forest' | 'base';
771
+ interface MermaidInitOptions {
772
+ theme?: MermaidThemeName;
773
+ maxTextSize?: number;
774
+ }
775
+
776
+ /** 覆盖默认 mermaid 初始化(需在首次 render 前调用) */
777
+ declare function configureMermaid(options: MermaidInitOptions): void;
778
+
779
+ interface PlantUMLBlockProps {
780
+ content: string;
781
+ className?: string;
782
+ }
783
+ /** PlantUML 源码块(高亮 + 拷贝;供 sourceOnly / 降级展示) */
784
+ declare function PlantUMLBlock({ content, className }: PlantUMLBlockProps): react_jsx_runtime.JSX.Element;
785
+
786
+ interface PlantUMLDiagramProps {
787
+ content: string;
788
+ className?: string;
789
+ /** Kroki 或兼容渲染服务根 URL */
790
+ serverUrl?: string;
791
+ fullscreenEnabled?: boolean;
792
+ /** 仅源码高亮,不请求渲染 */
793
+ sourceOnly?: boolean;
794
+ }
795
+ declare function PlantUMLDiagram({ content, className, serverUrl, fullscreenEnabled, sourceOnly, }: PlantUMLDiagramProps): react_jsx_runtime.JSX.Element;
796
+
797
+ /** 配置 PlantUML 渲染服务(默认 Kroki:https://kroki.io) */
798
+ declare function configurePlantumlServer(url: string): void;
799
+
472
800
  /**
473
801
  * toolNames.ts — CC PascalCase 工具名 SSOT(对齐 SDK registry_names.py)
474
802
  *
@@ -527,27 +855,63 @@ declare function useMinDisplayTime<T>(value: T, minMs?: number): T;
527
855
 
528
856
  declare function useInteractionBus(): InteractionBus;
529
857
 
858
+ /**
859
+ * applicationKind.ts — SSE meta application_kind 契约
860
+ *
861
+ * 职责:
862
+ * 定义双轨 SSE 出口 kind 枚举与 mismatch 错误类型。
863
+ *
864
+ * 链路位置:
865
+ * createAgentxSseSource meta 握手校验。
866
+ *
867
+ * 当前裁剪范围:
868
+ * 仅 agent_session / workflow;无自动推断。
869
+ */
870
+ type ApplicationKind = 'agent_session' | 'workflow';
871
+ declare class ApplicationKindMismatchError extends Error {
872
+ readonly name = "ApplicationKindMismatchError";
873
+ readonly expected: ApplicationKind;
874
+ readonly actual: string | undefined;
875
+ constructor(expected: ApplicationKind, actual: string | undefined);
876
+ }
877
+ declare class MissingApplicationKindError extends Error {
878
+ readonly name = "MissingApplicationKindError";
879
+ constructor();
880
+ }
881
+
530
882
  /**
531
883
  * 职责:浏览器 EventSource 封装,解码 meta/agentx 命名帧并校验协议版本。
532
884
  * 链路位置:业务页面 createAgentxSseSource({ url }) → AgentSession source prop。
533
- * 当前裁剪范围:protocol_version "1";SSE id 行续传;网络错误依赖 EventSource 原生重连(Last-Event-ID)。
885
+ *
886
+ * 错误分层(对齐 claude-code SSETransport / Messages 管线):
887
+ * - 传输 terminal:握手前/未 finish 断连 → reject(SseTransportTerminalError),不进 Timeline
888
+ * - 传输 benign:finish/error 帧后的 EventSource.onerror → resolve
889
+ * - 业务层:agentx event_type=error → reducer → ErrorNode(唯一用户可见错误文案)
534
890
  */
535
891
 
536
892
  declare const EXPECTED_PROTOCOL_VERSION = "1";
893
+ /** 传输层 terminal 失败(须排查/fix);与 agentx error 帧(业务错误)分离。 */
894
+ type SseTransportFailureKind = 'handshake_failed' | 'premature_close';
895
+ declare class SseTransportTerminalError extends Error {
896
+ readonly kind: SseTransportFailureKind;
897
+ constructor(kind: SseTransportFailureKind, message: string);
898
+ }
537
899
  interface AgentxSseSourceOptions {
538
900
  url: string;
539
- onError?: (error: Error) => void;
540
901
  autoReconnect?: boolean;
541
902
  reconnectDelayMs?: number;
542
903
  /** 每收到 agentx 帧 SSE id 时回调(含续传重叠 id) */
543
904
  onLastEventId?: (id: string) => void;
544
905
  /** 测试注入:替换全局 EventSource */
545
906
  EventSourceImpl?: typeof EventSource;
907
+ /** /chat 与 /workflow 必填:校验 meta.application_kind */
908
+ expectedApplicationKind?: ApplicationKind;
546
909
  }
547
910
  interface AgentxMetaFrame {
548
911
  protocol_version: string;
549
912
  session_id?: string | null;
550
913
  started_at?: number;
914
+ application_kind?: ApplicationKind;
551
915
  }
552
916
  /** 手动重连时追加 resume 查询参数(EventSource 无法设 Last-Event-ID 请求头)。 */
553
917
  declare function buildResumeStreamUrl(baseUrl: string, lastEventId: string | null | undefined, queryParam?: string): string;
@@ -619,6 +983,40 @@ interface ReplaySourceOptions extends ReplayOptions {
619
983
  }
620
984
  declare function createReplaySource(events: LangchainAgentEvent[], opts?: ReplaySourceOptions): Source;
621
985
 
986
+ /**
987
+ * workflowReducer.ts — WorkflowSession 容器树 + agent loop 双轨归约
988
+ *
989
+ * 职责:
990
+ * 结构事件经 WorkflowContainerTreeProjector 更新 containerTree;
991
+ * agent 事件 bind loopSessionId 并写入 loopTreesBySessionId。
992
+ *
993
+ * 链路位置:
994
+ * workflowSessionStore.applyEvent → reduceWorkflowSession。
995
+ *
996
+ * 当前裁剪范围:
997
+ * workflowProgress 为过渡期 dual-write;P2+ UI 改读 containerTree。
998
+ */
999
+
1000
+ /** Pure reducer:Workflow 会话状态 + 单条事件。 */
1001
+ declare function reduceWorkflowSession(state: WorkflowSessionState, event: LangchainAgentEvent, eventIndex: number, options?: ReduceOptions): WorkflowSessionState;
1002
+ /** 从空状态回放 workflow 事件序列。 */
1003
+ declare function reduceWorkflowEvents(events: LangchainAgentEvent[], options?: ReduceOptions): WorkflowSessionState;
1004
+
1005
+ /**
1006
+ * workflowStructureEvents.ts — Workflow 结构事件类型守卫
1007
+ *
1008
+ * 职责:
1009
+ * 区分 workflow 编排结构 event_type 与 agent loop 事件。
1010
+ *
1011
+ * 链路位置:
1012
+ * workflowReducer 路由 · Source application_kind 守卫(并行契约)。
1013
+ *
1014
+ * 当前裁剪范围:
1015
+ * 与 backend WORKFLOW_STRUCTURE_EVENT_TYPES 对齐;不进 tier-1 白名单。
1016
+ */
1017
+ declare const WORKFLOW_STRUCTURE_EVENT_TYPES: ReadonlySet<string>;
1018
+ declare function isWorkflowStructureEventType(eventType: string): boolean;
1019
+
622
1020
  /**
623
1021
  * 职责:事件分级类型(V2-A classify 层公共契约)。
624
1022
  * 链路位置:classify.ts → reducer;AgentSession tierOverrides 传入。
@@ -647,4 +1045,4 @@ interface ClassifyContext {
647
1045
  declare function resolveEventTier(eventType: string, overrides?: TierOverrides): EventTier;
648
1046
  declare function classifyEvent(event: LangchainAgentEvent, ctx: ClassifyContext, overrides?: TierOverrides, eventIndex?: number): ClassifiedEvent;
649
1047
 
650
- export { Agent, AgentSession, type AgentSessionProps, type AgentxMetaFrame, type AgentxSseSourceOptions, AskUserQuestion, Bash, CanonicalNodeRef, type ClassifiedEvent, type ClassifyContext, CollapseKind, CollapsedExploreNode, type CollapsedExploreNodeProps, DisplayMode, EXPECTED_PROTOCOL_VERSION, Edit, ErrorCard, EventTier, ExploreCollapseAccumulator, GROUPABLE_TOOL_NAMES, Glob, Grep, GroupedToolUseAccumulator, InteractionBus, LangchainAgentEvent, MIN_HINT_DISPLAY_MS, MarkdownRenderer, NodeRegistry, PermissionCard, PermissionUiMode, type ProjectedTimelineItem, ProjectionContext, DisplayMode as ProjectionDisplayMode, Read, ReasoningBubble, type ReduceOptions, ReducerError, RenderableEntry, RenderableTimelineProjector, type ReplayOptions, type ReplaySourceOptions, SHELL_PROGRESS_MIN_ELAPSED_SECONDS, SessionNode, SessionNodeKind, SessionStatus, SessionTree, Skill, Source, Spinner, type SpinnerProps, StepCard, SubAgentBlock, SystemSummaryAccumulator, SystemSummaryNode, Task, TaskList, TaskListFooter, TextBubble, TierOverrides, Timeline, TimelineItem, ToolBodyMode, ToolCallCard, ToolDisplayRegistry, ToolProjectionClassifier, UnknownCard, WebFetch, WebSearch, Write, buildCanonicalFromTree, buildRelevantMemoriesCanonical, buildResumeStreamUrl, buildSystemEventCanonical, buildTimelineEntries, classifyEvent, commandAsHint, createAgentxSseSource, createDefaultRegistry, createMockSource, createReplaySource, entryKey, formatAgentTitle, formatExploreSummaryText, formatHookFinishedSummary, formatShellProgressSuffix, formatTaskFooterLabel, getChildIds, getMainStageIds, isGitOperationCommand, isGroupableToolName, isMcpToolName, iterMountCandidates, projectCanonical, projectTimeline, reduceEvents, reduceTree, replayEvents, replayTree, resolveEventTier, resolveResponseId, resolveShellProgressFromPayload, shouldShowTaskListFooter, streamChunk, useChildren, useInteractionBus, useInternalErrors, useMinDisplayTime, useNode, useNodeTyped, useProjectedTimeline, useReplayTree, useSessionMeta, useSessionStatus, useTimeline };
1048
+ 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 };