@optilogic/chat 1.0.0-beta.10 → 1.0.0-beta.12
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.cjs +616 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +223 -3
- package/dist/index.d.ts +223 -3
- package/dist/index.js +610 -18
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/agent-response/AgentResponse.tsx +31 -13
- package/src/components/agent-response/components/ThinkingSection.tsx +1 -1
- package/src/components/agent-response/hooks/useAgentResponseAccumulator.ts +65 -8
- package/src/components/agent-response/index.ts +17 -0
- package/src/components/agent-response/types.ts +61 -1
- package/src/components/agent-timeline/AgentTimeline.tsx +256 -0
- package/src/components/agent-timeline/TimelineAgentBlock.tsx +84 -0
- package/src/components/agent-timeline/TimelineItem.tsx +97 -0
- package/src/components/agent-timeline/index.ts +14 -0
- package/src/components/agent-timeline/types.ts +49 -0
- package/src/components/agent-timeline/utils.ts +189 -0
- package/src/components/hitl-interactions/HITLQuestionPanel.tsx +9 -2
- package/src/components/hitl-interactions/index.ts +1 -1
- package/src/components/inline-actions/ActionMarkdownRenderer.tsx +60 -0
- package/src/components/inline-actions/index.ts +18 -0
- package/src/components/inline-actions/parseResponseSegments.ts +66 -0
- package/src/components/inline-actions/prompts.ts +41 -0
- package/src/components/inline-actions/types.ts +57 -0
- package/src/index.ts +27 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,53 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { ReactNode, ComponentType } from 'react';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
/** All possible timeline entry types */
|
|
6
|
+
type TimelineEntryType = "thinking" | "tool_call" | "knowledge" | "memory" | "status_update" | "ai_response" | "error";
|
|
7
|
+
/** A single event in the agent execution timeline */
|
|
8
|
+
interface TimelineEntry {
|
|
9
|
+
/** Unique ID for React keys */
|
|
10
|
+
id: string;
|
|
11
|
+
/** Discriminated type for icon and rendering */
|
|
12
|
+
type: TimelineEntryType;
|
|
13
|
+
/** The agent that produced this entry */
|
|
14
|
+
agentName: string | null;
|
|
15
|
+
/** The parent agent (null for root agent) */
|
|
16
|
+
parentAgent: string | null;
|
|
17
|
+
/** Nesting depth (0 = root) */
|
|
18
|
+
depth: number;
|
|
19
|
+
/** Display content (may be long) */
|
|
20
|
+
content: string;
|
|
21
|
+
/** Original title from the WebSocket message */
|
|
22
|
+
title: string | null;
|
|
23
|
+
/** Millisecond timestamp for ordering */
|
|
24
|
+
timestamp: number;
|
|
25
|
+
}
|
|
26
|
+
/** A consecutive run of messages from the same agent */
|
|
27
|
+
interface AgentRun {
|
|
28
|
+
/** Agent name (display label) */
|
|
29
|
+
agentName: string;
|
|
30
|
+
/** Parent agent name (null for root) */
|
|
31
|
+
parentAgent: string | null;
|
|
32
|
+
/** Depth in agent hierarchy */
|
|
33
|
+
depth: number;
|
|
34
|
+
/** The entries belonging to this run, in order, after dedup */
|
|
35
|
+
entries: DisplayEntry[];
|
|
36
|
+
}
|
|
37
|
+
/** After dedup — count > 1 means consecutive identical messages collapsed */
|
|
38
|
+
interface DisplayEntry {
|
|
39
|
+
/** The underlying timeline entry (first of the group if deduped) */
|
|
40
|
+
entry: TimelineEntry;
|
|
41
|
+
/** How many consecutive identical messages were collapsed into this one */
|
|
42
|
+
count: number;
|
|
43
|
+
}
|
|
2
44
|
|
|
3
45
|
/**
|
|
4
46
|
* Agent Response Component Types
|
|
5
47
|
*
|
|
6
48
|
* Type definitions for the library-ready agent response component
|
|
7
49
|
*/
|
|
50
|
+
|
|
8
51
|
/**
|
|
9
52
|
* Status of the agent response cycle
|
|
10
53
|
*/
|
|
@@ -21,6 +64,12 @@ interface ToolCall {
|
|
|
21
64
|
name: string;
|
|
22
65
|
arguments?: Record<string, unknown>;
|
|
23
66
|
timestamp: number;
|
|
67
|
+
/** Agent that made this call (multi-agent scenarios) */
|
|
68
|
+
agentName?: string | null;
|
|
69
|
+
/** Parent agent name */
|
|
70
|
+
parentAgent?: string | null;
|
|
71
|
+
/** Nesting depth in agent hierarchy */
|
|
72
|
+
depth?: number;
|
|
24
73
|
}
|
|
25
74
|
/**
|
|
26
75
|
* Knowledge retrieval information
|
|
@@ -30,6 +79,12 @@ interface KnowledgeItem {
|
|
|
30
79
|
source: string;
|
|
31
80
|
content: string;
|
|
32
81
|
timestamp: number;
|
|
82
|
+
/** Agent that retrieved this (multi-agent scenarios) */
|
|
83
|
+
agentName?: string | null;
|
|
84
|
+
/** Parent agent name */
|
|
85
|
+
parentAgent?: string | null;
|
|
86
|
+
/** Nesting depth in agent hierarchy */
|
|
87
|
+
depth?: number;
|
|
33
88
|
}
|
|
34
89
|
/**
|
|
35
90
|
* Memory access information
|
|
@@ -39,6 +94,23 @@ interface MemoryItem {
|
|
|
39
94
|
type: string;
|
|
40
95
|
content: string;
|
|
41
96
|
timestamp: number;
|
|
97
|
+
/** Agent that accessed this (multi-agent scenarios) */
|
|
98
|
+
agentName?: string | null;
|
|
99
|
+
/** Parent agent name */
|
|
100
|
+
parentAgent?: string | null;
|
|
101
|
+
/** Nesting depth in agent hierarchy */
|
|
102
|
+
depth?: number;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Potential response (sub-agent intermediate AI response)
|
|
106
|
+
*/
|
|
107
|
+
interface PotentialResponse {
|
|
108
|
+
id: string;
|
|
109
|
+
content: string;
|
|
110
|
+
timestamp: number;
|
|
111
|
+
agentName?: string | null;
|
|
112
|
+
parentAgent?: string | null;
|
|
113
|
+
depth?: number;
|
|
42
114
|
}
|
|
43
115
|
/**
|
|
44
116
|
* Status update information from the agent
|
|
@@ -49,6 +121,12 @@ interface StatusItem {
|
|
|
49
121
|
timestamp: number;
|
|
50
122
|
/** Optional agent name if in multi-agent scenario */
|
|
51
123
|
agent?: string;
|
|
124
|
+
/** Agent that produced this (multi-agent scenarios) */
|
|
125
|
+
agentName?: string | null;
|
|
126
|
+
/** Parent agent name */
|
|
127
|
+
parentAgent?: string | null;
|
|
128
|
+
/** Nesting depth in agent hierarchy */
|
|
129
|
+
depth?: number;
|
|
52
130
|
}
|
|
53
131
|
/**
|
|
54
132
|
* A single step in structured thinking content
|
|
@@ -64,6 +142,12 @@ interface ThinkingStep {
|
|
|
64
142
|
depth: number;
|
|
65
143
|
/** Whether this step should start collapsed (default: false) */
|
|
66
144
|
isCollapsed?: boolean;
|
|
145
|
+
/** Timestamp for timeline ordering */
|
|
146
|
+
timestamp?: number;
|
|
147
|
+
/** Agent that produced this (multi-agent scenarios) */
|
|
148
|
+
agentName?: string | null;
|
|
149
|
+
/** Parent agent name */
|
|
150
|
+
parentAgent?: string | null;
|
|
67
151
|
}
|
|
68
152
|
/**
|
|
69
153
|
* Union type for thinking content
|
|
@@ -89,8 +173,14 @@ interface AgentResponseState {
|
|
|
89
173
|
memory: MemoryItem[];
|
|
90
174
|
/** Status updates from the agent */
|
|
91
175
|
statusUpdates: StatusItem[];
|
|
176
|
+
/** Potential responses (sub-agent intermediate AI responses) */
|
|
177
|
+
potentialResponses?: PotentialResponse[];
|
|
178
|
+
/** Custom timeline entries (consumer-provided) */
|
|
179
|
+
customTimelineEntries?: TimelineEntry[];
|
|
92
180
|
/** Final response text */
|
|
93
181
|
response: string;
|
|
182
|
+
/** Timeline entries derived from all accumulator arrays (for AgentTimeline) */
|
|
183
|
+
timelineEntries?: TimelineEntry[];
|
|
94
184
|
/** Timestamp when first thinking message was received (for timer) */
|
|
95
185
|
thinkingStartTime: number | null;
|
|
96
186
|
/** Timestamp when response was completed (for final timer display) */
|
|
@@ -102,13 +192,21 @@ interface AgentResponseState {
|
|
|
102
192
|
* WebSocket message payload for agent responses
|
|
103
193
|
*/
|
|
104
194
|
interface AgentMessage {
|
|
105
|
-
type: "status" | "thinking" | "tool_call" | "knowledge" | "memory" | "response" | "status_update";
|
|
195
|
+
type: "status" | "thinking" | "tool_call" | "knowledge" | "memory" | "response" | "status_update" | "potential_response";
|
|
106
196
|
/** Message content - for simple string payloads */
|
|
107
197
|
message?: string;
|
|
108
198
|
/** Alternative content field */
|
|
109
199
|
content?: string;
|
|
110
200
|
/** For status messages */
|
|
111
201
|
status?: string;
|
|
202
|
+
/** Agent name (multi-agent scenarios) */
|
|
203
|
+
agentName?: string | null;
|
|
204
|
+
/** Parent agent name (multi-agent scenarios) */
|
|
205
|
+
parentAgent?: string | null;
|
|
206
|
+
/** Agent nesting depth (0 = root) */
|
|
207
|
+
depth?: number;
|
|
208
|
+
/** Title/label for timeline display */
|
|
209
|
+
title?: string | null;
|
|
112
210
|
/** For tool_call messages */
|
|
113
211
|
tool?: {
|
|
114
212
|
id: string;
|
|
@@ -177,9 +275,15 @@ interface HITLQuestion {
|
|
|
177
275
|
timeoutSeconds?: number;
|
|
178
276
|
receivedAt: number;
|
|
179
277
|
}
|
|
278
|
+
interface HITLResponseData {
|
|
279
|
+
/** Raw selected option text per question, keyed by question text */
|
|
280
|
+
selectedOptions: Record<string, string>;
|
|
281
|
+
/** Freeform text entered by the user (untrimmed) */
|
|
282
|
+
freeformText: string;
|
|
283
|
+
}
|
|
180
284
|
interface HITLQuestionPanelProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onSubmit"> {
|
|
181
285
|
question: HITLQuestion;
|
|
182
|
-
onSubmit: (response: string) => void;
|
|
286
|
+
onSubmit: (response: string, data: HITLResponseData) => void;
|
|
183
287
|
onStop: () => void;
|
|
184
288
|
}
|
|
185
289
|
/**
|
|
@@ -587,6 +691,49 @@ declare function formatTime(seconds: number, isComplete: boolean): string;
|
|
|
587
691
|
*/
|
|
588
692
|
declare function formatTotalTime(seconds: number): string;
|
|
589
693
|
|
|
694
|
+
/** Externalized UI state that survives component remounts */
|
|
695
|
+
interface TimelineUIState {
|
|
696
|
+
expandedItems: Set<string>;
|
|
697
|
+
collapsedRuns: Set<string>;
|
|
698
|
+
activeFilters: Set<TimelineEntryType>;
|
|
699
|
+
}
|
|
700
|
+
declare function createTimelineUIState(): TimelineUIState;
|
|
701
|
+
interface AgentTimelineProps {
|
|
702
|
+
entries: TimelineEntry[];
|
|
703
|
+
renderMarkdown?: (content: string) => ReactNode;
|
|
704
|
+
/**
|
|
705
|
+
* External UI state store. When provided, expand/collapse/filter state
|
|
706
|
+
* is read from and written to this object (which should be ref-backed
|
|
707
|
+
* in the parent) so it survives component remounts during streaming.
|
|
708
|
+
*/
|
|
709
|
+
uiState?: TimelineUIState;
|
|
710
|
+
/**
|
|
711
|
+
* Maximum height of the scrollable timeline container.
|
|
712
|
+
* Defaults to "300px". Set to "none" to disable.
|
|
713
|
+
*/
|
|
714
|
+
maxHeight?: string;
|
|
715
|
+
}
|
|
716
|
+
declare function AgentTimeline({ entries, renderMarkdown, uiState, maxHeight }: AgentTimelineProps): react_jsx_runtime.JSX.Element | null;
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Build a flat, chronologically sorted array of TimelineEntry from the
|
|
720
|
+
* accumulator state. Maps each typed array (toolCalls, knowledge, etc.)
|
|
721
|
+
* to unified TimelineEntry objects with per-source stable IDs.
|
|
722
|
+
*/
|
|
723
|
+
declare function buildTimelineEntries(state: AgentResponseState): TimelineEntry[];
|
|
724
|
+
/**
|
|
725
|
+
* Group a sorted array of timeline entries into consecutive "agent runs".
|
|
726
|
+
* A new run starts whenever the agentName changes.
|
|
727
|
+
* Each run's entries are deduplicated.
|
|
728
|
+
*/
|
|
729
|
+
declare function groupIntoAgentRuns(entries: TimelineEntry[]): AgentRun[];
|
|
730
|
+
/**
|
|
731
|
+
* Collapse consecutive entries with identical type AND content into
|
|
732
|
+
* a single DisplayEntry with count > 1.
|
|
733
|
+
* Handles patterns like "Loading documents" appearing 8 times.
|
|
734
|
+
*/
|
|
735
|
+
declare function deduplicateEntries(entries: DisplayEntry[]): DisplayEntry[];
|
|
736
|
+
|
|
590
737
|
interface UserPromptProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
591
738
|
/** The text content of the user's message */
|
|
592
739
|
content: string;
|
|
@@ -688,4 +835,77 @@ interface UserPromptInputRef {
|
|
|
688
835
|
*/
|
|
689
836
|
declare const UserPromptInput: React.ForwardRefExoticComponent<UserPromptInputProps & React.RefAttributes<UserPromptInputRef>>;
|
|
690
837
|
|
|
691
|
-
|
|
838
|
+
interface MarkdownSegment {
|
|
839
|
+
kind: "markdown";
|
|
840
|
+
content: string;
|
|
841
|
+
}
|
|
842
|
+
interface ActionSegment {
|
|
843
|
+
kind: "action";
|
|
844
|
+
actionType: string;
|
|
845
|
+
payload: Record<string, unknown>;
|
|
846
|
+
}
|
|
847
|
+
type ResponseSegment = MarkdownSegment | ActionSegment;
|
|
848
|
+
/**
|
|
849
|
+
* Props passed to every inline action component.
|
|
850
|
+
* T is the shape of the payload for this specific action type.
|
|
851
|
+
*/
|
|
852
|
+
interface InlineActionProps<T = Record<string, unknown>> {
|
|
853
|
+
/** The parsed payload from the json:action block */
|
|
854
|
+
payload: T;
|
|
855
|
+
/** Callback to send results back to the page (e.g., map data) */
|
|
856
|
+
onAction?: (actionType: string, result: unknown) => void;
|
|
857
|
+
/** True for the most recent agent message; affects button labels */
|
|
858
|
+
isLatest?: boolean;
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Maps action type strings to React components that render them.
|
|
862
|
+
* The consuming page owns this registry.
|
|
863
|
+
*/
|
|
864
|
+
type ActionComponentRegistry = Record<string, ComponentType<InlineActionProps<any>>>;
|
|
865
|
+
interface ActionMarkdownRendererProps {
|
|
866
|
+
/** The raw response text (may contain json:action blocks) */
|
|
867
|
+
content: string;
|
|
868
|
+
/** Registry of action type -> component */
|
|
869
|
+
registry: ActionComponentRegistry;
|
|
870
|
+
/** The existing renderMarkdown function for plain markdown segments */
|
|
871
|
+
renderMarkdown: (content: string) => ReactNode;
|
|
872
|
+
/** Callback forwarded to action components */
|
|
873
|
+
onAction?: (actionType: string, result: unknown) => void;
|
|
874
|
+
/** Whether this is the latest (most recent) agent message */
|
|
875
|
+
isLatest?: boolean;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* Renders agent response text with inline action components.
|
|
880
|
+
*
|
|
881
|
+
* Parses the response for ```json:action blocks, renders markdown
|
|
882
|
+
* segments via the provided renderMarkdown function, and renders
|
|
883
|
+
* action segments via the component registry.
|
|
884
|
+
*
|
|
885
|
+
* Unknown action types fall back to a raw JSON code block display.
|
|
886
|
+
*/
|
|
887
|
+
declare function ActionMarkdownRenderer({ content, registry, renderMarkdown, onAction, isLatest, }: ActionMarkdownRendererProps): react_jsx_runtime.JSX.Element;
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Parse response text into interleaved markdown and action segments.
|
|
891
|
+
*
|
|
892
|
+
* Finds ```json:action ... ``` fenced code blocks, extracts them as
|
|
893
|
+
* action segments, and returns the surrounding text as markdown segments.
|
|
894
|
+
*
|
|
895
|
+
* Malformed JSON or blocks missing a "type" field are left as markdown
|
|
896
|
+
* (rendered as raw code blocks) for graceful degradation.
|
|
897
|
+
*/
|
|
898
|
+
declare function parseResponseSegments(text: string): ResponseSegment[];
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* System prompt instructions for agents that emit inline action blocks.
|
|
902
|
+
*
|
|
903
|
+
* Import and append to your agent's system prompt so it knows the
|
|
904
|
+
* json:action format. The XML tags ensure clear boundaries for the LLM.
|
|
905
|
+
*
|
|
906
|
+
* When adding a new action type, add an entry under "Available action types"
|
|
907
|
+
* and create the corresponding React component + registry entry.
|
|
908
|
+
*/
|
|
909
|
+
declare const INLINE_ACTION_PROMPT = "\n<inline_actions>\nWhen your response should include interactive components (like query viewers,\ndata tables, or executable actions), embed them as fenced code blocks using\nthe `json:action` language tag:\n\n```json:action\n{\n \"type\": \"action-type-here\",\n ...action-specific fields\n}\n```\n\nRules:\n- Each block must contain valid JSON with a \"type\" field.\n- The \"type\" must match a registered action component on the frontend.\n- Multiple action blocks per response are allowed.\n- Surround action blocks with normal markdown text for user context.\n- The action block is rendered as an interactive component in the chat UI.\n- SQL strings inside JSON must be properly escaped (newlines as \\n, quotes as \\\").\n\nAvailable action types:\n\n- \"optimap-query\": Displays SQL queries with a button to execute them and\n update the 3D globe map.\n Required fields:\n - type: \"optimap-query\"\n - locations_sql: string (the validated locations SQL query)\n - routes_sql: string (the validated routes SQL query)\n - database_name: string (the target database name)\n</inline_actions>\n";
|
|
910
|
+
|
|
911
|
+
export { ActionBar, type ActionBarProps, type ActionComponentRegistry, ActionMarkdownRenderer, type ActionMarkdownRendererProps, type ActionSegment, ActivityIndicators, type ActivityIndicatorsProps, type AgentMessage, AgentResponse, type AgentResponseProps, type AgentResponseState, type AgentResponseStatus, type AgentRun, AgentTimeline, type DisplayEntry, type FeedbackValue, type GenericWebSocketMessage, type HITLInteraction, HITLInteractionRecord, type HITLInteractionRecordProps, type HITLQuestion, HITLQuestionPanel, type HITLQuestionPanelProps, type HITLResponseData, HITLSection, type HITLSectionProps, INLINE_ACTION_PROMPT, type InlineActionProps, type KnowledgeItem, type MarkdownSegment, type MemoryItem, MetadataRow, type MetadataRowProps, type PotentialResponse, type ResponseSegment, type StatusItem, type ThinkingContent, ThinkingSection, type ThinkingSectionProps, type ThinkingStep, type TimelineEntry, type TimelineEntryType, type TimelineUIState, type ToolCall, TruncatedMessage, type TruncatedMessageProps, type UseAgentResponseAccumulatorOptions, type UseAgentResponseAccumulatorReturn, type UseThinkingTimerOptions, UserPrompt, UserPromptInput, type UserPromptInputProps, type UserPromptInputRef, type UserPromptProps, buildResponseString, buildTimelineEntries, createTimelineUIState, deduplicateEntries, formatTime, formatTotalTime, groupIntoAgentRuns, initialAgentResponseState, parseResponseSegments, useAgentResponseAccumulator, useThinkingTimer };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,53 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { ReactNode, ComponentType } from 'react';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
/** All possible timeline entry types */
|
|
6
|
+
type TimelineEntryType = "thinking" | "tool_call" | "knowledge" | "memory" | "status_update" | "ai_response" | "error";
|
|
7
|
+
/** A single event in the agent execution timeline */
|
|
8
|
+
interface TimelineEntry {
|
|
9
|
+
/** Unique ID for React keys */
|
|
10
|
+
id: string;
|
|
11
|
+
/** Discriminated type for icon and rendering */
|
|
12
|
+
type: TimelineEntryType;
|
|
13
|
+
/** The agent that produced this entry */
|
|
14
|
+
agentName: string | null;
|
|
15
|
+
/** The parent agent (null for root agent) */
|
|
16
|
+
parentAgent: string | null;
|
|
17
|
+
/** Nesting depth (0 = root) */
|
|
18
|
+
depth: number;
|
|
19
|
+
/** Display content (may be long) */
|
|
20
|
+
content: string;
|
|
21
|
+
/** Original title from the WebSocket message */
|
|
22
|
+
title: string | null;
|
|
23
|
+
/** Millisecond timestamp for ordering */
|
|
24
|
+
timestamp: number;
|
|
25
|
+
}
|
|
26
|
+
/** A consecutive run of messages from the same agent */
|
|
27
|
+
interface AgentRun {
|
|
28
|
+
/** Agent name (display label) */
|
|
29
|
+
agentName: string;
|
|
30
|
+
/** Parent agent name (null for root) */
|
|
31
|
+
parentAgent: string | null;
|
|
32
|
+
/** Depth in agent hierarchy */
|
|
33
|
+
depth: number;
|
|
34
|
+
/** The entries belonging to this run, in order, after dedup */
|
|
35
|
+
entries: DisplayEntry[];
|
|
36
|
+
}
|
|
37
|
+
/** After dedup — count > 1 means consecutive identical messages collapsed */
|
|
38
|
+
interface DisplayEntry {
|
|
39
|
+
/** The underlying timeline entry (first of the group if deduped) */
|
|
40
|
+
entry: TimelineEntry;
|
|
41
|
+
/** How many consecutive identical messages were collapsed into this one */
|
|
42
|
+
count: number;
|
|
43
|
+
}
|
|
2
44
|
|
|
3
45
|
/**
|
|
4
46
|
* Agent Response Component Types
|
|
5
47
|
*
|
|
6
48
|
* Type definitions for the library-ready agent response component
|
|
7
49
|
*/
|
|
50
|
+
|
|
8
51
|
/**
|
|
9
52
|
* Status of the agent response cycle
|
|
10
53
|
*/
|
|
@@ -21,6 +64,12 @@ interface ToolCall {
|
|
|
21
64
|
name: string;
|
|
22
65
|
arguments?: Record<string, unknown>;
|
|
23
66
|
timestamp: number;
|
|
67
|
+
/** Agent that made this call (multi-agent scenarios) */
|
|
68
|
+
agentName?: string | null;
|
|
69
|
+
/** Parent agent name */
|
|
70
|
+
parentAgent?: string | null;
|
|
71
|
+
/** Nesting depth in agent hierarchy */
|
|
72
|
+
depth?: number;
|
|
24
73
|
}
|
|
25
74
|
/**
|
|
26
75
|
* Knowledge retrieval information
|
|
@@ -30,6 +79,12 @@ interface KnowledgeItem {
|
|
|
30
79
|
source: string;
|
|
31
80
|
content: string;
|
|
32
81
|
timestamp: number;
|
|
82
|
+
/** Agent that retrieved this (multi-agent scenarios) */
|
|
83
|
+
agentName?: string | null;
|
|
84
|
+
/** Parent agent name */
|
|
85
|
+
parentAgent?: string | null;
|
|
86
|
+
/** Nesting depth in agent hierarchy */
|
|
87
|
+
depth?: number;
|
|
33
88
|
}
|
|
34
89
|
/**
|
|
35
90
|
* Memory access information
|
|
@@ -39,6 +94,23 @@ interface MemoryItem {
|
|
|
39
94
|
type: string;
|
|
40
95
|
content: string;
|
|
41
96
|
timestamp: number;
|
|
97
|
+
/** Agent that accessed this (multi-agent scenarios) */
|
|
98
|
+
agentName?: string | null;
|
|
99
|
+
/** Parent agent name */
|
|
100
|
+
parentAgent?: string | null;
|
|
101
|
+
/** Nesting depth in agent hierarchy */
|
|
102
|
+
depth?: number;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Potential response (sub-agent intermediate AI response)
|
|
106
|
+
*/
|
|
107
|
+
interface PotentialResponse {
|
|
108
|
+
id: string;
|
|
109
|
+
content: string;
|
|
110
|
+
timestamp: number;
|
|
111
|
+
agentName?: string | null;
|
|
112
|
+
parentAgent?: string | null;
|
|
113
|
+
depth?: number;
|
|
42
114
|
}
|
|
43
115
|
/**
|
|
44
116
|
* Status update information from the agent
|
|
@@ -49,6 +121,12 @@ interface StatusItem {
|
|
|
49
121
|
timestamp: number;
|
|
50
122
|
/** Optional agent name if in multi-agent scenario */
|
|
51
123
|
agent?: string;
|
|
124
|
+
/** Agent that produced this (multi-agent scenarios) */
|
|
125
|
+
agentName?: string | null;
|
|
126
|
+
/** Parent agent name */
|
|
127
|
+
parentAgent?: string | null;
|
|
128
|
+
/** Nesting depth in agent hierarchy */
|
|
129
|
+
depth?: number;
|
|
52
130
|
}
|
|
53
131
|
/**
|
|
54
132
|
* A single step in structured thinking content
|
|
@@ -64,6 +142,12 @@ interface ThinkingStep {
|
|
|
64
142
|
depth: number;
|
|
65
143
|
/** Whether this step should start collapsed (default: false) */
|
|
66
144
|
isCollapsed?: boolean;
|
|
145
|
+
/** Timestamp for timeline ordering */
|
|
146
|
+
timestamp?: number;
|
|
147
|
+
/** Agent that produced this (multi-agent scenarios) */
|
|
148
|
+
agentName?: string | null;
|
|
149
|
+
/** Parent agent name */
|
|
150
|
+
parentAgent?: string | null;
|
|
67
151
|
}
|
|
68
152
|
/**
|
|
69
153
|
* Union type for thinking content
|
|
@@ -89,8 +173,14 @@ interface AgentResponseState {
|
|
|
89
173
|
memory: MemoryItem[];
|
|
90
174
|
/** Status updates from the agent */
|
|
91
175
|
statusUpdates: StatusItem[];
|
|
176
|
+
/** Potential responses (sub-agent intermediate AI responses) */
|
|
177
|
+
potentialResponses?: PotentialResponse[];
|
|
178
|
+
/** Custom timeline entries (consumer-provided) */
|
|
179
|
+
customTimelineEntries?: TimelineEntry[];
|
|
92
180
|
/** Final response text */
|
|
93
181
|
response: string;
|
|
182
|
+
/** Timeline entries derived from all accumulator arrays (for AgentTimeline) */
|
|
183
|
+
timelineEntries?: TimelineEntry[];
|
|
94
184
|
/** Timestamp when first thinking message was received (for timer) */
|
|
95
185
|
thinkingStartTime: number | null;
|
|
96
186
|
/** Timestamp when response was completed (for final timer display) */
|
|
@@ -102,13 +192,21 @@ interface AgentResponseState {
|
|
|
102
192
|
* WebSocket message payload for agent responses
|
|
103
193
|
*/
|
|
104
194
|
interface AgentMessage {
|
|
105
|
-
type: "status" | "thinking" | "tool_call" | "knowledge" | "memory" | "response" | "status_update";
|
|
195
|
+
type: "status" | "thinking" | "tool_call" | "knowledge" | "memory" | "response" | "status_update" | "potential_response";
|
|
106
196
|
/** Message content - for simple string payloads */
|
|
107
197
|
message?: string;
|
|
108
198
|
/** Alternative content field */
|
|
109
199
|
content?: string;
|
|
110
200
|
/** For status messages */
|
|
111
201
|
status?: string;
|
|
202
|
+
/** Agent name (multi-agent scenarios) */
|
|
203
|
+
agentName?: string | null;
|
|
204
|
+
/** Parent agent name (multi-agent scenarios) */
|
|
205
|
+
parentAgent?: string | null;
|
|
206
|
+
/** Agent nesting depth (0 = root) */
|
|
207
|
+
depth?: number;
|
|
208
|
+
/** Title/label for timeline display */
|
|
209
|
+
title?: string | null;
|
|
112
210
|
/** For tool_call messages */
|
|
113
211
|
tool?: {
|
|
114
212
|
id: string;
|
|
@@ -177,9 +275,15 @@ interface HITLQuestion {
|
|
|
177
275
|
timeoutSeconds?: number;
|
|
178
276
|
receivedAt: number;
|
|
179
277
|
}
|
|
278
|
+
interface HITLResponseData {
|
|
279
|
+
/** Raw selected option text per question, keyed by question text */
|
|
280
|
+
selectedOptions: Record<string, string>;
|
|
281
|
+
/** Freeform text entered by the user (untrimmed) */
|
|
282
|
+
freeformText: string;
|
|
283
|
+
}
|
|
180
284
|
interface HITLQuestionPanelProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onSubmit"> {
|
|
181
285
|
question: HITLQuestion;
|
|
182
|
-
onSubmit: (response: string) => void;
|
|
286
|
+
onSubmit: (response: string, data: HITLResponseData) => void;
|
|
183
287
|
onStop: () => void;
|
|
184
288
|
}
|
|
185
289
|
/**
|
|
@@ -587,6 +691,49 @@ declare function formatTime(seconds: number, isComplete: boolean): string;
|
|
|
587
691
|
*/
|
|
588
692
|
declare function formatTotalTime(seconds: number): string;
|
|
589
693
|
|
|
694
|
+
/** Externalized UI state that survives component remounts */
|
|
695
|
+
interface TimelineUIState {
|
|
696
|
+
expandedItems: Set<string>;
|
|
697
|
+
collapsedRuns: Set<string>;
|
|
698
|
+
activeFilters: Set<TimelineEntryType>;
|
|
699
|
+
}
|
|
700
|
+
declare function createTimelineUIState(): TimelineUIState;
|
|
701
|
+
interface AgentTimelineProps {
|
|
702
|
+
entries: TimelineEntry[];
|
|
703
|
+
renderMarkdown?: (content: string) => ReactNode;
|
|
704
|
+
/**
|
|
705
|
+
* External UI state store. When provided, expand/collapse/filter state
|
|
706
|
+
* is read from and written to this object (which should be ref-backed
|
|
707
|
+
* in the parent) so it survives component remounts during streaming.
|
|
708
|
+
*/
|
|
709
|
+
uiState?: TimelineUIState;
|
|
710
|
+
/**
|
|
711
|
+
* Maximum height of the scrollable timeline container.
|
|
712
|
+
* Defaults to "300px". Set to "none" to disable.
|
|
713
|
+
*/
|
|
714
|
+
maxHeight?: string;
|
|
715
|
+
}
|
|
716
|
+
declare function AgentTimeline({ entries, renderMarkdown, uiState, maxHeight }: AgentTimelineProps): react_jsx_runtime.JSX.Element | null;
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Build a flat, chronologically sorted array of TimelineEntry from the
|
|
720
|
+
* accumulator state. Maps each typed array (toolCalls, knowledge, etc.)
|
|
721
|
+
* to unified TimelineEntry objects with per-source stable IDs.
|
|
722
|
+
*/
|
|
723
|
+
declare function buildTimelineEntries(state: AgentResponseState): TimelineEntry[];
|
|
724
|
+
/**
|
|
725
|
+
* Group a sorted array of timeline entries into consecutive "agent runs".
|
|
726
|
+
* A new run starts whenever the agentName changes.
|
|
727
|
+
* Each run's entries are deduplicated.
|
|
728
|
+
*/
|
|
729
|
+
declare function groupIntoAgentRuns(entries: TimelineEntry[]): AgentRun[];
|
|
730
|
+
/**
|
|
731
|
+
* Collapse consecutive entries with identical type AND content into
|
|
732
|
+
* a single DisplayEntry with count > 1.
|
|
733
|
+
* Handles patterns like "Loading documents" appearing 8 times.
|
|
734
|
+
*/
|
|
735
|
+
declare function deduplicateEntries(entries: DisplayEntry[]): DisplayEntry[];
|
|
736
|
+
|
|
590
737
|
interface UserPromptProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
591
738
|
/** The text content of the user's message */
|
|
592
739
|
content: string;
|
|
@@ -688,4 +835,77 @@ interface UserPromptInputRef {
|
|
|
688
835
|
*/
|
|
689
836
|
declare const UserPromptInput: React.ForwardRefExoticComponent<UserPromptInputProps & React.RefAttributes<UserPromptInputRef>>;
|
|
690
837
|
|
|
691
|
-
|
|
838
|
+
interface MarkdownSegment {
|
|
839
|
+
kind: "markdown";
|
|
840
|
+
content: string;
|
|
841
|
+
}
|
|
842
|
+
interface ActionSegment {
|
|
843
|
+
kind: "action";
|
|
844
|
+
actionType: string;
|
|
845
|
+
payload: Record<string, unknown>;
|
|
846
|
+
}
|
|
847
|
+
type ResponseSegment = MarkdownSegment | ActionSegment;
|
|
848
|
+
/**
|
|
849
|
+
* Props passed to every inline action component.
|
|
850
|
+
* T is the shape of the payload for this specific action type.
|
|
851
|
+
*/
|
|
852
|
+
interface InlineActionProps<T = Record<string, unknown>> {
|
|
853
|
+
/** The parsed payload from the json:action block */
|
|
854
|
+
payload: T;
|
|
855
|
+
/** Callback to send results back to the page (e.g., map data) */
|
|
856
|
+
onAction?: (actionType: string, result: unknown) => void;
|
|
857
|
+
/** True for the most recent agent message; affects button labels */
|
|
858
|
+
isLatest?: boolean;
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Maps action type strings to React components that render them.
|
|
862
|
+
* The consuming page owns this registry.
|
|
863
|
+
*/
|
|
864
|
+
type ActionComponentRegistry = Record<string, ComponentType<InlineActionProps<any>>>;
|
|
865
|
+
interface ActionMarkdownRendererProps {
|
|
866
|
+
/** The raw response text (may contain json:action blocks) */
|
|
867
|
+
content: string;
|
|
868
|
+
/** Registry of action type -> component */
|
|
869
|
+
registry: ActionComponentRegistry;
|
|
870
|
+
/** The existing renderMarkdown function for plain markdown segments */
|
|
871
|
+
renderMarkdown: (content: string) => ReactNode;
|
|
872
|
+
/** Callback forwarded to action components */
|
|
873
|
+
onAction?: (actionType: string, result: unknown) => void;
|
|
874
|
+
/** Whether this is the latest (most recent) agent message */
|
|
875
|
+
isLatest?: boolean;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* Renders agent response text with inline action components.
|
|
880
|
+
*
|
|
881
|
+
* Parses the response for ```json:action blocks, renders markdown
|
|
882
|
+
* segments via the provided renderMarkdown function, and renders
|
|
883
|
+
* action segments via the component registry.
|
|
884
|
+
*
|
|
885
|
+
* Unknown action types fall back to a raw JSON code block display.
|
|
886
|
+
*/
|
|
887
|
+
declare function ActionMarkdownRenderer({ content, registry, renderMarkdown, onAction, isLatest, }: ActionMarkdownRendererProps): react_jsx_runtime.JSX.Element;
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Parse response text into interleaved markdown and action segments.
|
|
891
|
+
*
|
|
892
|
+
* Finds ```json:action ... ``` fenced code blocks, extracts them as
|
|
893
|
+
* action segments, and returns the surrounding text as markdown segments.
|
|
894
|
+
*
|
|
895
|
+
* Malformed JSON or blocks missing a "type" field are left as markdown
|
|
896
|
+
* (rendered as raw code blocks) for graceful degradation.
|
|
897
|
+
*/
|
|
898
|
+
declare function parseResponseSegments(text: string): ResponseSegment[];
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* System prompt instructions for agents that emit inline action blocks.
|
|
902
|
+
*
|
|
903
|
+
* Import and append to your agent's system prompt so it knows the
|
|
904
|
+
* json:action format. The XML tags ensure clear boundaries for the LLM.
|
|
905
|
+
*
|
|
906
|
+
* When adding a new action type, add an entry under "Available action types"
|
|
907
|
+
* and create the corresponding React component + registry entry.
|
|
908
|
+
*/
|
|
909
|
+
declare const INLINE_ACTION_PROMPT = "\n<inline_actions>\nWhen your response should include interactive components (like query viewers,\ndata tables, or executable actions), embed them as fenced code blocks using\nthe `json:action` language tag:\n\n```json:action\n{\n \"type\": \"action-type-here\",\n ...action-specific fields\n}\n```\n\nRules:\n- Each block must contain valid JSON with a \"type\" field.\n- The \"type\" must match a registered action component on the frontend.\n- Multiple action blocks per response are allowed.\n- Surround action blocks with normal markdown text for user context.\n- The action block is rendered as an interactive component in the chat UI.\n- SQL strings inside JSON must be properly escaped (newlines as \\n, quotes as \\\").\n\nAvailable action types:\n\n- \"optimap-query\": Displays SQL queries with a button to execute them and\n update the 3D globe map.\n Required fields:\n - type: \"optimap-query\"\n - locations_sql: string (the validated locations SQL query)\n - routes_sql: string (the validated routes SQL query)\n - database_name: string (the target database name)\n</inline_actions>\n";
|
|
910
|
+
|
|
911
|
+
export { ActionBar, type ActionBarProps, type ActionComponentRegistry, ActionMarkdownRenderer, type ActionMarkdownRendererProps, type ActionSegment, ActivityIndicators, type ActivityIndicatorsProps, type AgentMessage, AgentResponse, type AgentResponseProps, type AgentResponseState, type AgentResponseStatus, type AgentRun, AgentTimeline, type DisplayEntry, type FeedbackValue, type GenericWebSocketMessage, type HITLInteraction, HITLInteractionRecord, type HITLInteractionRecordProps, type HITLQuestion, HITLQuestionPanel, type HITLQuestionPanelProps, type HITLResponseData, HITLSection, type HITLSectionProps, INLINE_ACTION_PROMPT, type InlineActionProps, type KnowledgeItem, type MarkdownSegment, type MemoryItem, MetadataRow, type MetadataRowProps, type PotentialResponse, type ResponseSegment, type StatusItem, type ThinkingContent, ThinkingSection, type ThinkingSectionProps, type ThinkingStep, type TimelineEntry, type TimelineEntryType, type TimelineUIState, type ToolCall, TruncatedMessage, type TruncatedMessageProps, type UseAgentResponseAccumulatorOptions, type UseAgentResponseAccumulatorReturn, type UseThinkingTimerOptions, UserPrompt, UserPromptInput, type UserPromptInputProps, type UserPromptInputRef, type UserPromptProps, buildResponseString, buildTimelineEntries, createTimelineUIState, deduplicateEntries, formatTime, formatTotalTime, groupIntoAgentRuns, initialAgentResponseState, parseResponseSegments, useAgentResponseAccumulator, useThinkingTimer };
|