@erdoai/ui 0.1.5

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.
@@ -0,0 +1,931 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+ import React__default from 'react';
4
+ import { ErdoClient, ContentItem, SSEEvent, InvokeResult, InvokeParams } from '@erdoai/types';
5
+ export { ContentItem } from '@erdoai/types';
6
+ import * as RechartsPrimitive from 'recharts';
7
+ import { UseQueryResult } from '@tanstack/react-query';
8
+ import { ClassValue } from 'clsx';
9
+
10
+ /**
11
+ * Interface for custom data fetching implementations.
12
+ * Use this when you need to override the default REST API behavior,
13
+ * e.g., when using an Encore client or custom backend.
14
+ *
15
+ * Must be a STABLE object reference - create outside components to avoid
16
+ * recreating on every render.
17
+ */
18
+ interface DataFetcher {
19
+ fetchDatasetContents: (slug: string, invocationId: string) => Promise<any[]>;
20
+ }
21
+ /**
22
+ * Configuration for the ErdoProvider.
23
+ */
24
+ interface ErdoProviderConfig {
25
+ /**
26
+ * Base URL for API calls (e.g., 'https://api.erdo.ai')
27
+ * Used by default REST implementation in hooks.
28
+ */
29
+ baseUrl: string;
30
+ /**
31
+ * Optional auth token for API calls.
32
+ * Will be sent as Bearer token in Authorization header.
33
+ * Use this for long-lived API keys (B2B backend-to-backend).
34
+ */
35
+ authToken?: string;
36
+ /**
37
+ * Optional session token for B2B2C use cases.
38
+ * When provided, uses the session-authenticated endpoint for dataset queries.
39
+ * Session tokens are short-lived, scoped to specific datasets, and created
40
+ * by B2B customers for their end users.
41
+ *
42
+ * Example B2B2C flow:
43
+ * 1. B2B backend creates session token via POST /dataset-sessions
44
+ * 2. B2B frontend passes session token to ErdoProvider
45
+ * 3. End user can query only the datasets scoped to that session
46
+ */
47
+ sessionToken?: string;
48
+ /**
49
+ * Optional ErdoClient for invoking bots.
50
+ * Required if using useInvocation hook.
51
+ */
52
+ client?: ErdoClient;
53
+ /**
54
+ * Optional custom data fetcher for non-standard backends.
55
+ * When provided, hooks will use this instead of the default REST implementation.
56
+ *
57
+ * Example usage with Encore client:
58
+ * ```typescript
59
+ * // lib/erdo-fetcher.ts - Create ONCE outside components
60
+ * export const erdoDataFetcher: DataFetcher = {
61
+ * fetchDatasetContents: async (slug, invocationId) => {
62
+ * const client = await getRequestClient();
63
+ * return client.dataset.GetDatasetContents({ slug, invocationId });
64
+ * },
65
+ * };
66
+ * ```
67
+ */
68
+ dataFetcher?: DataFetcher;
69
+ }
70
+ interface ErdoProviderProps {
71
+ children: React__default.ReactNode;
72
+ config: ErdoProviderConfig;
73
+ }
74
+ /**
75
+ * Provider component that configures data fetching for Erdo UI components.
76
+ *
77
+ * @example Simple usage with baseUrl (B2B customers):
78
+ * ```tsx
79
+ * <ErdoProvider config={{ baseUrl: 'https://api.erdo.ai', authToken: 'xxx' }}>
80
+ * <App />
81
+ * </ErdoProvider>
82
+ * ```
83
+ *
84
+ * @example With custom data fetcher (Erdo frontend):
85
+ * ```tsx
86
+ * <ErdoProvider config={{ baseUrl: '', dataFetcher: erdoDataFetcher }}>
87
+ * <App />
88
+ * </ErdoProvider>
89
+ * ```
90
+ */
91
+ declare function ErdoProvider({ children, config }: ErdoProviderProps): react_jsx_runtime.JSX.Element;
92
+ /**
93
+ * Hook to access the Erdo provider configuration.
94
+ * Must be used within an ErdoProvider.
95
+ */
96
+ declare function useErdoConfig(): ErdoProviderConfig;
97
+ /**
98
+ * Hook to check if we're inside an ErdoProvider.
99
+ * Returns the config if available, null otherwise.
100
+ */
101
+ declare function useErdoConfigOptional(): ErdoProviderConfig | null;
102
+
103
+ declare const THEMES: {
104
+ readonly light: "";
105
+ readonly dark: ".dark";
106
+ };
107
+ type ChartConfig = {
108
+ [k in string]: {
109
+ label?: React.ReactNode;
110
+ icon?: React.ComponentType;
111
+ } & ({
112
+ color?: string;
113
+ theme?: never;
114
+ } | {
115
+ color?: never;
116
+ theme: Record<keyof typeof THEMES, string>;
117
+ });
118
+ };
119
+ declare function ChartContainer({ id, className, children, config, debounceResize, ...props }: React.ComponentProps<'div'> & {
120
+ config: ChartConfig;
121
+ children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>['children'];
122
+ /** Debounce resize events by 200ms to prevent animation restarts during streaming */
123
+ debounceResize?: boolean;
124
+ }): react_jsx_runtime.JSX.Element;
125
+ declare const ChartStyle: ({ id, config }: {
126
+ id: string;
127
+ config: ChartConfig;
128
+ }) => react_jsx_runtime.JSX.Element | null;
129
+ declare const ChartTooltip: typeof RechartsPrimitive.Tooltip;
130
+ interface ChartTooltipContentProps {
131
+ active?: boolean;
132
+ payload?: ReadonlyArray<{
133
+ dataKey?: string;
134
+ name?: string;
135
+ value?: any;
136
+ color?: string;
137
+ payload?: any;
138
+ [key: string]: any;
139
+ }>;
140
+ label?: string | number;
141
+ className?: string;
142
+ indicator?: 'line' | 'dot' | 'dashed';
143
+ hideLabel?: boolean;
144
+ hideIndicator?: boolean;
145
+ labelFormatter?: (label: any, payload: any) => React.ReactNode;
146
+ labelClassName?: string;
147
+ formatter?: (value: any, name: any, item: any, index: number, payload: any) => React.ReactNode;
148
+ color?: string;
149
+ nameKey?: string;
150
+ labelKey?: string;
151
+ }
152
+ declare function ChartTooltipContent({ active, payload, className, indicator, hideLabel, hideIndicator, label, labelFormatter, labelClassName, formatter, color, nameKey, labelKey, }: ChartTooltipContentProps): react_jsx_runtime.JSX.Element | null;
153
+ declare const ChartLegend: typeof RechartsPrimitive.Legend;
154
+ interface ChartLegendContentProps {
155
+ className?: string;
156
+ hideIcon?: boolean;
157
+ payload?: ReadonlyArray<{
158
+ value?: string;
159
+ color?: string;
160
+ dataKey?: any;
161
+ [key: string]: any;
162
+ }>;
163
+ verticalAlign?: 'top' | 'bottom' | 'middle';
164
+ nameKey?: string;
165
+ }
166
+ declare function ChartLegendContent({ className, hideIcon, payload, verticalAlign, nameKey, }: ChartLegendContentProps): react_jsx_runtime.JSX.Element | null;
167
+
168
+ interface Axis$2 {
169
+ label: string;
170
+ key: string;
171
+ maxValue?: string | null;
172
+ minValue?: string | null;
173
+ format?: string | null;
174
+ type?: 'number' | 'category' | 'date' | null;
175
+ }
176
+ interface DataConfig {
177
+ chartType: 'bar' | 'line' | 'pie' | 'histogram' | 'scatter' | 'heatmap';
178
+ xAxis: Axis$2;
179
+ yAxes: Array<Axis$2>;
180
+ series: Array<{
181
+ key: string;
182
+ name: string;
183
+ color: string;
184
+ axisIndex?: number;
185
+ }>;
186
+ }
187
+ interface BaseChartProps {
188
+ title: string;
189
+ subtitle?: string | null;
190
+ data: any[];
191
+ displayConfig: ChartConfig;
192
+ dataConfig: DataConfig;
193
+ disableAnimation?: boolean;
194
+ onZoomChange?: (domain: {
195
+ x: [number | null, number | null];
196
+ y: [number | null, number | null];
197
+ }) => void;
198
+ stacked?: boolean;
199
+ /** Enable download button (default: true) */
200
+ enableDownload?: boolean;
201
+ /** Callback when download succeeds */
202
+ onDownloadSuccess?: (fileName: string) => void;
203
+ /** Callback when download fails */
204
+ onDownloadError?: (error: string) => void;
205
+ }
206
+ interface ChartProps extends BaseChartProps {
207
+ ChartComponent: React__default.ComponentType<any>;
208
+ PointComponent: React__default.ComponentType<any>;
209
+ }
210
+ declare function Chart(props: ChartProps): react_jsx_runtime.JSX.Element;
211
+
212
+ declare function BarChart(props: any): react_jsx_runtime.JSX.Element;
213
+
214
+ declare function LineChart(props: any): react_jsx_runtime.JSX.Element;
215
+
216
+ declare function PieChart(props: BaseChartProps): react_jsx_runtime.JSX.Element;
217
+
218
+ declare function ScatterChart(props: any): react_jsx_runtime.JSX.Element;
219
+
220
+ declare function HeatmapChart(props: any): react_jsx_runtime.JSX.Element;
221
+
222
+ interface Axis$1 {
223
+ label: string;
224
+ key: string;
225
+ type?: 'number' | 'category' | 'date' | null;
226
+ format?: string | null;
227
+ maxValue?: string | null;
228
+ minValue?: string | null;
229
+ }
230
+ interface Series$1 {
231
+ name: string;
232
+ key: string;
233
+ color: string;
234
+ datasetSlug: string;
235
+ axisIndex?: number;
236
+ filters?: Filter$1[];
237
+ }
238
+ interface Filter$1 {
239
+ key: string;
240
+ operator: 'equals' | 'not_equals' | 'greater_than' | 'less_than' | 'contains' | 'between';
241
+ value: string[];
242
+ }
243
+ interface SortCondition$1 {
244
+ key: string;
245
+ direction: 'asc' | 'desc';
246
+ }
247
+ interface DatasetChartProps {
248
+ chartType: 'bar' | 'line' | 'pie' | 'histogram' | 'scatter' | 'heatmap';
249
+ title: string;
250
+ invocationId: string;
251
+ datasetSlugs: string[];
252
+ xAxis: Axis$1;
253
+ yAxes: Axis$1[];
254
+ series: Series$1[];
255
+ dataReduction?: {
256
+ strategy: 'none' | 'sample' | 'aggregate' | 'bin';
257
+ target_points: number;
258
+ };
259
+ stacked?: boolean;
260
+ sort?: SortCondition$1[];
261
+ /** Optional callback for scroll updates when chart loads */
262
+ onScrollUpdate?: () => void;
263
+ }
264
+ declare const DatasetChart: React__default.NamedExoticComponent<DatasetChartProps>;
265
+
266
+ declare class ErrorBoundary extends React__default.Component<{
267
+ fallback: React__default.ReactNode;
268
+ children: React__default.ReactNode;
269
+ }, {
270
+ hasError: boolean;
271
+ }> {
272
+ constructor(props: {
273
+ fallback: React__default.ReactNode;
274
+ children: React__default.ReactNode;
275
+ });
276
+ static getDerivedStateFromError(_: Error): {
277
+ hasError: boolean;
278
+ };
279
+ componentDidCatch(error: Error, errorInfo: React__default.ErrorInfo): void;
280
+ render(): React__default.ReactNode;
281
+ }
282
+
283
+ interface Axis {
284
+ axis_label: string;
285
+ key: string;
286
+ max_value?: string | null;
287
+ min_value?: string | null;
288
+ value_type?: 'number' | 'category' | 'date' | null;
289
+ format?: string | null;
290
+ }
291
+ interface Series {
292
+ series_name: string;
293
+ key: string;
294
+ color: string;
295
+ dataset_slug?: string;
296
+ axis_index?: number;
297
+ filters?: Filter[];
298
+ }
299
+ interface Filter {
300
+ key: string;
301
+ operator: 'equals' | 'not_equals' | 'greater_than' | 'less_than' | 'contains' | 'between';
302
+ value: string[];
303
+ }
304
+ interface SortCondition {
305
+ key: string;
306
+ direction: 'asc' | 'desc';
307
+ }
308
+ interface ContentChartConfig {
309
+ chart_type: 'bar' | 'line' | 'pie' | 'histogram' | 'scatter' | 'heatmap';
310
+ chart_title: string;
311
+ x_axis: Axis;
312
+ y_axes: Axis[];
313
+ series: Series[];
314
+ data_reduction?: {
315
+ strategy: 'none' | 'sample' | 'aggregate' | 'bin';
316
+ target_points: number;
317
+ };
318
+ stacked?: boolean;
319
+ sort?: SortCondition[];
320
+ }
321
+ interface ChartContentProps {
322
+ config: ContentChartConfig;
323
+ data: any[];
324
+ className?: string;
325
+ }
326
+ declare function ChartContent({ config, data, className }: ChartContentProps): react_jsx_runtime.JSX.Element;
327
+
328
+ interface ContentProps {
329
+ item: ContentItem;
330
+ className?: string;
331
+ components?: Partial<{
332
+ text: React__default.ComponentType<{
333
+ content: string;
334
+ className?: string;
335
+ }>;
336
+ json: React__default.ComponentType<{
337
+ content: string | object;
338
+ className?: string;
339
+ }>;
340
+ chart: React__default.ComponentType<{
341
+ config: ContentChartConfig;
342
+ data: any[];
343
+ className?: string;
344
+ }>;
345
+ table: React__default.ComponentType<{
346
+ title?: string;
347
+ columns: any[];
348
+ data: any[];
349
+ className?: string;
350
+ }>;
351
+ }>;
352
+ }
353
+ /**
354
+ * Routes content to the appropriate renderer based on content_type and ui_content_type.
355
+ */
356
+ declare function Content({ item, className, components }: ContentProps): string | number | bigint | boolean | Iterable<React__default.ReactNode> | Promise<string | number | bigint | boolean | React__default.ReactPortal | React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>> | Iterable<React__default.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null | undefined;
357
+
358
+ interface TextContentProps {
359
+ content: string;
360
+ className?: string;
361
+ }
362
+ declare function TextContent({ content, className }: TextContentProps): react_jsx_runtime.JSX.Element | null;
363
+
364
+ interface JsonContentProps {
365
+ content: string | object;
366
+ className?: string;
367
+ }
368
+ declare function JsonContent({ content, className }: JsonContentProps): react_jsx_runtime.JSX.Element | null;
369
+
370
+ interface MarkdownContentProps {
371
+ /** The markdown text to render */
372
+ text: string;
373
+ /** Additional CSS class names */
374
+ className?: string;
375
+ }
376
+ /**
377
+ * Renders markdown content with GitHub Flavored Markdown support.
378
+ *
379
+ * @example
380
+ * ```tsx
381
+ * <MarkdownContent text="# Hello\n\nThis is **bold** text." />
382
+ * ```
383
+ */
384
+ declare function MarkdownContent({ text, className }: MarkdownContentProps): react_jsx_runtime.JSX.Element | null;
385
+
386
+ interface TableColumn {
387
+ column_name: string;
388
+ key: string;
389
+ format?: string;
390
+ value_type?: 'number' | 'category' | 'date';
391
+ }
392
+ interface TableContentProps {
393
+ title?: string;
394
+ columns: TableColumn[];
395
+ data: any[];
396
+ className?: string;
397
+ maxRows?: number;
398
+ }
399
+ declare function TableContent({ title, columns, data, className, maxRows }: TableContentProps): react_jsx_runtime.JSX.Element;
400
+
401
+ interface ZoomState {
402
+ refAreaLeft: number | null;
403
+ refAreaRight: number | null;
404
+ refAreaTop: number | null;
405
+ refAreaBottom: number | null;
406
+ zooming: boolean;
407
+ }
408
+ interface Domain {
409
+ x: [number | string | null, number | string | null];
410
+ y: [number | string | null, number | string | null];
411
+ }
412
+ interface ZoomEvent {
413
+ chartX: number;
414
+ chartY: number;
415
+ xValue: number;
416
+ yValue: number;
417
+ }
418
+ interface UseChartZoomProps {
419
+ onZoomChange?: (domain: {
420
+ x: [number | null, number | null];
421
+ y: [number | null, number | null];
422
+ }) => void;
423
+ }
424
+ declare function useChartZoom({ onZoomChange }?: UseChartZoomProps): {
425
+ zoomState: ZoomState;
426
+ customDomain: Domain;
427
+ handlers: {
428
+ onZoomStart: (e: ZoomEvent) => void;
429
+ onZoomMove: (e: ZoomEvent) => void;
430
+ onZoomEnd: () => void;
431
+ onResetZoom: () => void;
432
+ };
433
+ };
434
+
435
+ /**
436
+ * Hook to fetch contents of a single dataset.
437
+ *
438
+ * @param datasetSlug - The slug/identifier of the dataset
439
+ * @param invocationId - The invocation ID context
440
+ * @returns React Query result with dataset contents
441
+ *
442
+ * @example
443
+ * ```tsx
444
+ * const { data, isLoading, error } = useDatasetContents('my-dataset', invocationId);
445
+ * ```
446
+ */
447
+ declare function useDatasetContents(datasetSlug: string, invocationId: string): UseQueryResult<any[], Error>;
448
+ /**
449
+ * Hook to fetch contents of multiple datasets in parallel.
450
+ *
451
+ * @param datasetSlugs - Array of dataset slugs/identifiers
452
+ * @param invocationId - The invocation ID context
453
+ * @returns Array of React Query results, one per dataset
454
+ *
455
+ * @example
456
+ * ```tsx
457
+ * const results = useMultipleDatasetContents(['dataset-1', 'dataset-2'], invocationId);
458
+ * const isLoading = results.some(r => r.isLoading);
459
+ * const allData = results.map(r => r.data || []);
460
+ * ```
461
+ */
462
+ declare function useMultipleDatasetContents(datasetSlugs: string[], invocationId: string): UseQueryResult<any[], Error>[];
463
+
464
+ interface UseInvocationOptions {
465
+ /** Called for each SSE event received during streaming */
466
+ onEvent?: (event: SSEEvent) => void;
467
+ /** Called when invocation completes successfully */
468
+ onFinish?: (result: InvokeResult) => void;
469
+ /** Called if an error occurs */
470
+ onError?: (error: Error) => void;
471
+ }
472
+ interface UseInvocationReturn {
473
+ /** Current invocation result (updates during streaming) */
474
+ result: InvokeResult | null;
475
+ /** Whether an invocation is currently in progress */
476
+ isStreaming: boolean;
477
+ /** Error if the last invocation failed */
478
+ error: Error | null;
479
+ /** Function to start a new invocation */
480
+ invoke: (botKey: string, params: InvokeParams) => Promise<InvokeResult>;
481
+ /** Function to cancel the current invocation */
482
+ cancel: () => void;
483
+ }
484
+ /**
485
+ * Hook for invoking Erdo bots and streaming results.
486
+ *
487
+ * Requires ErdoProvider with a client configured.
488
+ *
489
+ * @example
490
+ * ```tsx
491
+ * function MyComponent() {
492
+ * const { result, isStreaming, invoke } = useInvocation({
493
+ * onEvent: (event) => console.log('Event:', event),
494
+ * onFinish: (result) => console.log('Done:', result),
495
+ * });
496
+ *
497
+ * const handleAnalyze = async () => {
498
+ * await invoke('org.my-bot', {
499
+ * messages: [{ role: 'user', content: 'Analyze sales data' }],
500
+ * datasets: ['sales-2024'],
501
+ * });
502
+ * };
503
+ *
504
+ * return (
505
+ * <div>
506
+ * <button onClick={handleAnalyze} disabled={isStreaming}>
507
+ * {isStreaming ? 'Analyzing...' : 'Analyze'}
508
+ * </button>
509
+ * {result && <div>Result: {JSON.stringify(result)}</div>}
510
+ * </div>
511
+ * );
512
+ * }
513
+ * ```
514
+ */
515
+ declare function useInvocation(options?: UseInvocationOptions): UseInvocationReturn;
516
+
517
+ /**
518
+ * Format a value based on its type and specified format pattern
519
+ */
520
+ declare function formatValue(value: any, format?: string | null, valueType?: 'number' | 'category' | 'date' | null): string;
521
+ /**
522
+ * Parse a value to a Date object
523
+ */
524
+ declare function parseToDate(value: any): Date | null;
525
+
526
+ declare function cn(...inputs: ClassValue[]): string;
527
+
528
+ /**
529
+ * Utility functions for resolving data keys across different naming conventions.
530
+ * Used by dataset visualization components (charts, tables, etc.) to handle
531
+ * mismatches between config keys and actual data keys.
532
+ */
533
+ /**
534
+ * Convert PascalCase or camelCase to snake_case
535
+ * Examples: ActiveUsers -> active_users, userName -> user_name
536
+ */
537
+ declare function toSnakeCase(str: string): string;
538
+ /**
539
+ * Resolve the actual key from data objects by trying multiple patterns.
540
+ * This handles common naming convention mismatches between config and data.
541
+ *
542
+ * Tries in order:
543
+ * 1. Exact match
544
+ * 2. Lowercase (Date -> date)
545
+ * 3. Snake case (ActiveUsers -> active_users)
546
+ * 4. Normalized (case-insensitive, underscore-insensitive)
547
+ *
548
+ * @param dataRows - Array of data objects to search
549
+ * @param configKey - The key from the configuration
550
+ * @returns The resolved key that exists in the data, or the original key if not found
551
+ */
552
+ declare function resolveKeyFromData(dataRows: any[], configKey: string): string;
553
+
554
+ /**
555
+ * JSON streaming parser utilities.
556
+ * Used for parsing potentially incomplete JSON during SSE streaming.
557
+ */
558
+ type JSONValue = string | number | boolean | null | {
559
+ [key: string]: JSONValue;
560
+ [parsingSymbol]?: boolean;
561
+ } | (JSONValue[] & {
562
+ [parsingSymbol]?: boolean;
563
+ });
564
+ type ParserState = 'START' | 'IN_OBJECT' | 'IN_ARRAY' | 'IN_OBJECT_KEY' | 'AFTER_KEY' | 'IN_OBJECT_VALUE' | 'IN_STRING' | 'IN_NUMBER' | 'IN_TRUE' | 'IN_FALSE' | 'IN_NULL' | 'IN_UNICODE' | 'END';
565
+ declare const parsingSymbol: unique symbol;
566
+ declare class JSONStreamParser {
567
+ result: JSONValue | undefined;
568
+ private stack;
569
+ private key;
570
+ state: ParserState;
571
+ private stringBuffer;
572
+ private numberBuffer;
573
+ private quoteBuffer;
574
+ private escapeNext;
575
+ private unicode;
576
+ private isInTripleQuotes;
577
+ constructor();
578
+ private reset;
579
+ parse(jsonString: string): JSONValue | undefined;
580
+ add(chunk: string): JSONValue | undefined;
581
+ private processChar;
582
+ private handleStartState;
583
+ private error;
584
+ private handleObjectState;
585
+ private handleArrayState;
586
+ private handleObjectKeyState;
587
+ private handleAfterKeyState;
588
+ private handleObjectValueState;
589
+ private handleStringState;
590
+ private handleNumberState;
591
+ private handleLiteralState;
592
+ private handleUnicodeState;
593
+ private handleEscapeChar;
594
+ private startObject;
595
+ private endObject;
596
+ private startArray;
597
+ private endArray;
598
+ private startValue;
599
+ private endString;
600
+ private endNumber;
601
+ private endLiteral;
602
+ private addValueToParent;
603
+ private updateValueInParent;
604
+ private isWhitespace;
605
+ private getParentState;
606
+ }
607
+ /**
608
+ * Parse a complete JSON string, with fallback to streaming parser for malformed JSON.
609
+ */
610
+ declare function parseCompleteJson(content: string): any;
611
+ type ContentChunk = {
612
+ content: string | Record<string, any>;
613
+ type: 'json' | 'text';
614
+ };
615
+ declare function isWhitespaceChar(char: string): boolean;
616
+ /**
617
+ * Parse mixed content that may contain JSON objects embedded in text.
618
+ * Handles both markdown code blocks (```json...```) and inline JSON.
619
+ */
620
+ declare function parseMixedJson(content: string | any[] | Record<string, any>): ContentChunk[] | any[] | Record<string, any>;
621
+ declare function isParsingComplete(value: any): boolean;
622
+ declare function isParsingInProgress(value: any): boolean;
623
+
624
+ /**
625
+ * SSE Event Types for parsing streaming invocation results.
626
+ *
627
+ * These types are standalone and don't depend on any generated client types.
628
+ * They represent the structure of entities that can be built from SSE events.
629
+ */
630
+
631
+ type ContentType = 'text' | 'json' | 'xml' | 'thinking' | 'redacted_thinking';
632
+ declare function isJsonLike(contentType: ContentType, uiContentType: string): boolean;
633
+ type EntityType = 'message' | 'message_content' | 'invocation' | 'output' | 'output_content' | 'step' | 'result_handler' | 'status' | 'log';
634
+ type MessageStreamingState = 'in_progress' | 'completed';
635
+ interface SSEEventData {
636
+ payload: Record<string, any> | string;
637
+ metadata: {
638
+ path: string;
639
+ content_type?: ContentType;
640
+ history_content_type?: string;
641
+ ui_content_type?: string;
642
+ invocation_id?: string;
643
+ message_id?: string;
644
+ message_content_id?: string;
645
+ user_visibility?: string;
646
+ bot_visibility?: string;
647
+ visibility?: string;
648
+ output_id?: string;
649
+ output_content_id?: string;
650
+ step_id?: string;
651
+ result_handler_id?: string;
652
+ status_id?: string;
653
+ [key: string]: any;
654
+ };
655
+ }
656
+ interface BaseContentFields {
657
+ botInvocation?: BotInvocation;
658
+ parsedJson?: ContentChunk[];
659
+ _currentContent?: ContentChunk;
660
+ _jsonParser?: JSONStreamParser;
661
+ _isInJson?: boolean;
662
+ _charBuffer?: string;
663
+ state: MessageStreamingState;
664
+ invocation_id: string;
665
+ }
666
+ interface Message {
667
+ id: string;
668
+ thread_id: string;
669
+ author_id: string;
670
+ author_entity_type: string;
671
+ created_at: string;
672
+ updated_at: string;
673
+ role: string;
674
+ avatar?: string;
675
+ }
676
+ interface MessageContent extends BaseContentFields {
677
+ _type: 'message_content';
678
+ id: string;
679
+ message_id: string;
680
+ content_type: ContentType;
681
+ content: string;
682
+ created_by_invocation_id?: string;
683
+ user_visibility: string;
684
+ bot_visibility: string;
685
+ created_at: string;
686
+ updated_at: string;
687
+ content_params: {
688
+ RawMessage: any;
689
+ Valid: boolean;
690
+ };
691
+ history_content_type: {
692
+ String: string;
693
+ Valid: boolean;
694
+ };
695
+ ui_content_type: {
696
+ String: string;
697
+ Valid: boolean;
698
+ };
699
+ }
700
+ interface MessageWithContents {
701
+ _type: 'message';
702
+ message: Message;
703
+ state: MessageStreamingState;
704
+ contents: MessageContent[];
705
+ contentsByID: Record<string, MessageContent>;
706
+ contentIDToIdx: Record<string, number>;
707
+ }
708
+ interface Output {
709
+ id: string;
710
+ invocation_id?: string;
711
+ path?: string;
712
+ created_at: string;
713
+ updated_at: string;
714
+ }
715
+ interface OutputContent extends BaseContentFields {
716
+ _type: 'output_content';
717
+ id: string;
718
+ output_id: string;
719
+ content: string;
720
+ content_type: ContentType;
721
+ user_visibility: string;
722
+ bot_visibility: string;
723
+ created_at: string;
724
+ updated_at: string;
725
+ content_params: {
726
+ RawMessage: any;
727
+ Valid: boolean;
728
+ };
729
+ history_content_type: {
730
+ String: string;
731
+ Valid: boolean;
732
+ };
733
+ ui_content_type: {
734
+ String: string;
735
+ Valid: boolean;
736
+ };
737
+ output: OutputWithContents | null;
738
+ }
739
+ interface OutputWithContents {
740
+ _type: 'output';
741
+ id: string;
742
+ step_id?: string;
743
+ output: Output;
744
+ state: MessageStreamingState;
745
+ contents: OutputContent[];
746
+ contentsByID: Record<string, OutputContent>;
747
+ contentIDToIdx: Record<string, number>;
748
+ }
749
+ interface Step {
750
+ _type: 'step';
751
+ id: string;
752
+ invocation_id: string;
753
+ step_id: string;
754
+ created_at: string;
755
+ updated_at: string;
756
+ current_status_id: string;
757
+ path: {
758
+ String: string;
759
+ Valid: boolean;
760
+ };
761
+ action_type: {
762
+ String: string;
763
+ Valid: boolean;
764
+ };
765
+ key: {
766
+ String: string;
767
+ Valid: boolean;
768
+ };
769
+ bot_id?: string;
770
+ result_handler_id: string;
771
+ step_order: {
772
+ Int32: number;
773
+ Valid: boolean;
774
+ };
775
+ output_content_type: {
776
+ String: string;
777
+ Valid: boolean;
778
+ };
779
+ execution_mode: {
780
+ String: string;
781
+ Valid: boolean;
782
+ };
783
+ output_behaviour: {
784
+ String: string;
785
+ Valid: boolean;
786
+ };
787
+ user_output_visibility: {
788
+ String: string;
789
+ Valid: boolean;
790
+ };
791
+ output_channels: string[];
792
+ running_message: {
793
+ String: string;
794
+ Valid: boolean;
795
+ };
796
+ finished_message: {
797
+ String: string;
798
+ Valid: boolean;
799
+ };
800
+ depends_on: string[];
801
+ eventsByID: Record<string, InvocationEvent>;
802
+ currentStatus: Status | null;
803
+ }
804
+ interface ResultHandler {
805
+ _type: 'result_handler';
806
+ id: string;
807
+ invocation_id: string;
808
+ result_handler_id: string;
809
+ step_invocation_id: string;
810
+ type: string;
811
+ if_conditions: Record<string, any>;
812
+ created_at: string;
813
+ updated_at: string;
814
+ output_content_type: string;
815
+ result_handler_order: number;
816
+ eventsByID: Record<string, InvocationEvent>;
817
+ }
818
+ declare enum InvocationStatus {
819
+ Pending = "pending",
820
+ Running = "running",
821
+ Success = "success",
822
+ Error = "error",
823
+ RequiresInfo = "requires info",
824
+ GoToStep = "go to step",
825
+ Skipped = "skipped",
826
+ Break = "break"
827
+ }
828
+ declare enum ExecutionStatus {
829
+ Initializing = "initializing",
830
+ Running = "running",
831
+ ProcessingDatasets = "processing datasets",
832
+ Completed = "completed",
833
+ Failed = "failed"
834
+ }
835
+ interface StatusEvent {
836
+ status: ExecutionStatus | InvocationStatus | string;
837
+ message?: string;
838
+ details?: Record<string, any>;
839
+ }
840
+ interface Status {
841
+ _type: 'status';
842
+ id: string;
843
+ status: string;
844
+ message: {
845
+ String: string;
846
+ Valid: boolean;
847
+ };
848
+ Details: StatusEvent;
849
+ created_at?: string;
850
+ }
851
+ interface BotInvocationData {
852
+ id: string;
853
+ bot_id: string;
854
+ bot_name?: string;
855
+ created_by_user_id?: string;
856
+ current_state_id: string;
857
+ parent_invocation_id: string;
858
+ branch_init_state_id: string;
859
+ current_status_id: string;
860
+ organization_id: string;
861
+ created_at: string;
862
+ updated_at: string;
863
+ }
864
+ interface BotInvocation {
865
+ _type: 'invocation';
866
+ bot_invocation: BotInvocationData;
867
+ eventsByID: Record<string, InvocationEvent>;
868
+ currentStatus: Status | null;
869
+ current_status: Status | null;
870
+ step_invocations: any[];
871
+ step_invocation_states: any[];
872
+ resources: any[];
873
+ outputs: any[];
874
+ statuses: any[];
875
+ }
876
+ interface InvocationEvent {
877
+ id?: string;
878
+ type?: EntityType;
879
+ created_at?: string;
880
+ _type: 'invocation_event';
881
+ Output: OutputWithContents | null;
882
+ Message: MessageWithContents | null;
883
+ Status: Status | null;
884
+ ResultHandler: ResultHandler | null;
885
+ Step: Step | null;
886
+ }
887
+ type Entity = MessageWithContents | MessageContent | BotInvocation | OutputWithContents | OutputContent | Step | ResultHandler | Status;
888
+
889
+ /**
890
+ * SSE Event Handler
891
+ *
892
+ * Handles Server-Sent Events from Erdo invocations and builds up the
893
+ * message/invocation tree structure for rendering.
894
+ */
895
+
896
+ /**
897
+ * Handles incremental parsing of mixed JSON/text content as it streams in.
898
+ *
899
+ * This function is called each time new content arrives during streaming.
900
+ * It parses the content to detect JSON blocks interspersed with text,
901
+ * updating the outputContent's parsed_blocks array as complete JSON
902
+ * objects are detected.
903
+ *
904
+ * @param outputContent - The message or output content to update
905
+ * @param content - The full accumulated content string so far
906
+ * @returns The updated content object with parsed_blocks populated
907
+ */
908
+ declare function handleIncrementalMixedJsonParsing(outputContent: MessageContent | OutputContent, content: string): MessageContent | OutputContent;
909
+ /**
910
+ * Handles different types of SSE events and updates the message tree accordingly.
911
+ *
912
+ * Returns the updated entity at the root level (typically a message or message_content),
913
+ * or null if no update was performed (e.g., for message finished events).
914
+ *
915
+ * Note: Only message or message_content types can be returned as root objects.
916
+ * Other entity types like invocation, step, output, etc. will be nested inside
917
+ * a message_content entity.
918
+ *
919
+ * @param eventType - The type of SSE event (e.g., 'bot started', 'message content delta')
920
+ * @param event - The SSE event data
921
+ * @param path - The path to the entity being updated
922
+ * @param threadID - The thread ID for creating messages
923
+ * @param activeMessagesByID - Map of active messages by ID
924
+ * @param currentEntity - The current entity being processed
925
+ * @param parents - Parent entities in the tree
926
+ * @param entityIds - Map of entity type to ID for context
927
+ * @returns The updated entity or null if no update was performed
928
+ */
929
+ declare function handleSSEEvent(eventType: string, event: SSEEventData, path: string[], threadID: string, activeMessagesByID: Record<string, MessageWithContents>, currentEntity?: Entity | null, parents?: Entity[], entityIds?: Record<string, string>): Entity | null;
930
+
931
+ export { BarChart, type BaseChartProps, type BotInvocation, type BotInvocationData, Chart, type ChartConfig, ChartContainer, ChartContent, type ChartContentProps, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent, Content, type ContentChartConfig, type ContentChunk, type ContentProps, type ContentType, type DataFetcher, DatasetChart, type DatasetChartProps, type Entity, type EntityType, ErdoProvider, type ErdoProviderConfig, type ErdoProviderProps, ErrorBoundary, ExecutionStatus, HeatmapChart, type InvocationEvent, InvocationStatus, JSONStreamParser, type JSONValue, JsonContent, type JsonContentProps, LineChart, MarkdownContent, type MarkdownContentProps, type Message, type MessageContent, type MessageStreamingState, type MessageWithContents, type Output, type OutputContent, type OutputWithContents, PieChart, type ResultHandler, type SSEEventData, ScatterChart, type Status, type StatusEvent, type Step, TableContent, type TableContentProps, TextContent, type TextContentProps, type UseInvocationOptions, type UseInvocationReturn, cn, formatValue, handleIncrementalMixedJsonParsing, handleSSEEvent, isJsonLike, isParsingComplete, isParsingInProgress, isWhitespaceChar, parseCompleteJson, parseMixedJson, parseToDate, resolveKeyFromData, toSnakeCase, useChartZoom, useDatasetContents, useErdoConfig, useErdoConfigOptional, useInvocation, useMultipleDatasetContents };