@optilogic/chat 1.0.0-beta.1 → 1.0.0-beta.10

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.cts CHANGED
@@ -40,6 +40,37 @@ interface MemoryItem {
40
40
  content: string;
41
41
  timestamp: number;
42
42
  }
43
+ /**
44
+ * Status update information from the agent
45
+ */
46
+ interface StatusItem {
47
+ id: string;
48
+ message: string;
49
+ timestamp: number;
50
+ /** Optional agent name if in multi-agent scenario */
51
+ agent?: string;
52
+ }
53
+ /**
54
+ * A single step in structured thinking content
55
+ */
56
+ interface ThinkingStep {
57
+ /** Unique identifier for the step */
58
+ id: string;
59
+ /** Label/title shown in the collapsible header */
60
+ label: string;
61
+ /** Content of the thinking step */
62
+ content: string;
63
+ /** Nesting depth (0 = root level, 1 = first indent, etc.) */
64
+ depth: number;
65
+ /** Whether this step should start collapsed (default: false) */
66
+ isCollapsed?: boolean;
67
+ }
68
+ /**
69
+ * Union type for thinking content
70
+ * - string: plain text (backward compatible)
71
+ * - ThinkingStep[]: structured with collapsible sub-sections
72
+ */
73
+ type ThinkingContent = string | ThinkingStep[];
43
74
  /**
44
75
  * State shape for the agent response component
45
76
  */
@@ -48,12 +79,16 @@ interface AgentResponseState {
48
79
  status: AgentResponseStatus;
49
80
  /** Accumulated thinking/reasoning text */
50
81
  thinking: string;
82
+ /** Structured thinking steps (if provided, takes precedence over thinking string) */
83
+ thinkingSteps?: ThinkingStep[];
51
84
  /** Tool calls made during processing */
52
85
  toolCalls: ToolCall[];
53
86
  /** Knowledge items retrieved */
54
87
  knowledge: KnowledgeItem[];
55
88
  /** Memory items accessed */
56
89
  memory: MemoryItem[];
90
+ /** Status updates from the agent */
91
+ statusUpdates: StatusItem[];
57
92
  /** Final response text */
58
93
  response: string;
59
94
  /** Timestamp when first thinking message was received (for timer) */
@@ -67,7 +102,7 @@ interface AgentResponseState {
67
102
  * WebSocket message payload for agent responses
68
103
  */
69
104
  interface AgentMessage {
70
- type: "status" | "thinking" | "tool_call" | "knowledge" | "memory" | "response";
105
+ type: "status" | "thinking" | "tool_call" | "knowledge" | "memory" | "response" | "status_update";
71
106
  /** Message content - for simple string payloads */
72
107
  message?: string;
73
108
  /** Alternative content field */
@@ -92,6 +127,20 @@ interface AgentMessage {
92
127
  type: string;
93
128
  content: string;
94
129
  };
130
+ /** For status_update messages */
131
+ statusUpdate?: {
132
+ id: string;
133
+ message: string;
134
+ agent?: string;
135
+ };
136
+ /** For structured thinking step messages */
137
+ thinkingStep?: {
138
+ id?: string;
139
+ label: string;
140
+ content: string;
141
+ depth?: number;
142
+ isCollapsed?: boolean;
143
+ };
95
144
  }
96
145
  /**
97
146
  * Generic websocket message wrapper type
@@ -106,6 +155,58 @@ interface GenericWebSocketMessage {
106
155
  */
107
156
  declare const initialAgentResponseState: AgentResponseState;
108
157
 
158
+ /**
159
+ * HITLQuestionPanel — Human-in-the-Loop clarifying question panel.
160
+ *
161
+ * Renders in the input area (replacing UserPromptInput) when the agent asks a
162
+ * clarifying question via the HumanInTheLoop tool. Shows the question details
163
+ * and lets the user respond via option buttons or free-form text.
164
+ *
165
+ * Option clicks select/toggle rather than immediately submitting. The "Send
166
+ * response" button enables once all questions have a selected option OR the
167
+ * textarea has text. On submit, selected options and free-form text are
168
+ * combined into a single formatted string for the backend.
169
+ */
170
+
171
+ interface HITLQuestion {
172
+ reason: string;
173
+ questions: string[];
174
+ options: Record<string, string[]> | null;
175
+ context: string | null;
176
+ /** Timeout in seconds. When omitted, no countdown is shown and the panel never times out. */
177
+ timeoutSeconds?: number;
178
+ receivedAt: number;
179
+ }
180
+ interface HITLQuestionPanelProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onSubmit"> {
181
+ question: HITLQuestion;
182
+ onSubmit: (response: string) => void;
183
+ onStop: () => void;
184
+ }
185
+ /**
186
+ * Build a single response string from selected options and optional free-form text.
187
+ * Format is designed to be easily parsed by the LLM consuming the response.
188
+ */
189
+ declare function buildResponseString(questions: string[], selectedOptions: Record<string, string>, freeformText: string): string;
190
+ declare const HITLQuestionPanel: React.ForwardRefExoticComponent<HITLQuestionPanelProps & React.RefAttributes<HTMLDivElement>>;
191
+
192
+ /**
193
+ * HITLInteractionRecord — Displays a completed HITL Q&A interaction
194
+ * in the chat message history.
195
+ *
196
+ * Rendered below AgentResponse in the agent message block. Shows the full detail
197
+ * of each clarifying question the agent asked and the user's response.
198
+ */
199
+
200
+ interface HITLInteraction {
201
+ question: HITLQuestion;
202
+ response: string;
203
+ respondedAt: number;
204
+ }
205
+ interface HITLInteractionRecordProps extends React.HTMLAttributes<HTMLDivElement> {
206
+ interaction: HITLInteraction;
207
+ }
208
+ declare const HITLInteractionRecord: React.ForwardRefExoticComponent<HITLInteractionRecordProps & React.RefAttributes<HTMLDivElement>>;
209
+
109
210
  /**
110
211
  * AgentResponse Component
111
212
  *
@@ -131,6 +232,32 @@ interface AgentResponseProps extends React.HTMLAttributes<HTMLDivElement> {
131
232
  onThinkingExpandedChange?: (expanded: boolean) => void;
132
233
  /** Action bar visibility mode */
133
234
  actionsVisible?: boolean | "hover";
235
+ /**
236
+ * Optional HITL (Human-in-the-Loop) interactions to display as a
237
+ * collapsible section within the response. When provided, a "Clarifying
238
+ * Questions" section appears between the thinking/metadata area and
239
+ * the response content.
240
+ */
241
+ hitlInteractions?: HITLInteraction[];
242
+ /** Whether the HITL section starts expanded (default: false) */
243
+ defaultHITLExpanded?: boolean;
244
+ /**
245
+ * Optional content to display in the MetadataRow's middle area,
246
+ * between the thinking toggle (left) and activity indicators (right).
247
+ * Typically used for ephemeral status messages during processing.
248
+ * The parent is responsible for setting and clearing this content.
249
+ *
250
+ * @example
251
+ * <AgentResponse
252
+ * state={state}
253
+ * statusContent={
254
+ * state.status !== 'complete'
255
+ * ? <TruncatedMessage message="Analyzing data..." />
256
+ * : undefined
257
+ * }
258
+ * />
259
+ */
260
+ statusContent?: React.ReactNode;
134
261
  /**
135
262
  * Custom markdown renderer for the response content.
136
263
  * If not provided, the response will be rendered as plain text.
@@ -142,6 +269,17 @@ interface AgentResponseProps extends React.HTMLAttributes<HTMLDivElement> {
142
269
  * />
143
270
  */
144
271
  renderMarkdown?: (content: string) => React.ReactNode;
272
+ /**
273
+ * Custom markdown renderer for the thinking content.
274
+ * If not provided, the thinking will be rendered as plain preformatted text.
275
+ *
276
+ * @example
277
+ * <AgentResponse
278
+ * state={state}
279
+ * renderThinkingMarkdown={(content) => <MyMarkdownRenderer content={content} />}
280
+ * />
281
+ */
282
+ renderThinkingMarkdown?: (content: string) => React.ReactNode;
145
283
  }
146
284
  /**
147
285
  * AgentResponse Component
@@ -190,6 +328,8 @@ interface ActivityIndicatorsProps extends React.HTMLAttributes<HTMLDivElement> {
190
328
  knowledge: KnowledgeItem[];
191
329
  /** Memory items to display */
192
330
  memory: MemoryItem[];
331
+ /** Status updates to display */
332
+ statusUpdates?: StatusItem[];
193
333
  }
194
334
  /**
195
335
  * ActivityIndicators Component
@@ -225,6 +365,10 @@ interface MetadataRowProps extends React.HTMLAttributes<HTMLDivElement> {
225
365
  knowledge: KnowledgeItem[];
226
366
  /** Memory items to display */
227
367
  memory: MemoryItem[];
368
+ /** Status updates to display */
369
+ statusUpdates?: StatusItem[];
370
+ /** Optional content to display in the middle area between left content and activity indicators */
371
+ statusContent?: React.ReactNode;
228
372
  /** Current response status */
229
373
  status: AgentResponseStatus;
230
374
  /** Elapsed time in seconds */
@@ -253,22 +397,40 @@ declare const MetadataRow: React.ForwardRefExoticComponent<MetadataRowProps & Re
253
397
  /**
254
398
  * Thinking Section Component
255
399
  *
256
- * Collapsible section for displaying agent thinking/reasoning content
400
+ * Collapsible section for displaying agent thinking/reasoning content.
401
+ * Supports both plain text and structured collapsible sub-sections.
257
402
  */
258
403
 
259
- interface ThinkingSectionProps extends React.HTMLAttributes<HTMLDivElement> {
260
- /** The thinking content to display */
261
- content: string;
404
+ interface ThinkingSectionProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "content"> {
405
+ /** The thinking content to display (string or structured steps) */
406
+ content: string | ThinkingStep[];
262
407
  /** Whether the section is expanded */
263
408
  isExpanded: boolean;
409
+ /**
410
+ * Custom markdown renderer for the thinking content.
411
+ * If not provided, the content will be rendered as plain preformatted text.
412
+ */
413
+ renderMarkdown?: (content: string) => React.ReactNode;
264
414
  }
265
415
  /**
266
416
  * ThinkingSection Component
267
417
  *
268
418
  * Displays the agent's thinking/reasoning content in a collapsible panel.
419
+ * Supports both plain text content and structured collapsible sub-sections.
269
420
  *
270
421
  * @example
422
+ * // Plain text content
271
423
  * <ThinkingSection content={state.thinking} isExpanded={isExpanded} />
424
+ *
425
+ * @example
426
+ * // Structured content with sub-sections
427
+ * <ThinkingSection
428
+ * content={[
429
+ * { id: "1", label: "Analysis", content: "...", depth: 0 },
430
+ * { id: "2", label: "Sub-analysis", content: "...", depth: 1 },
431
+ * ]}
432
+ * isExpanded={isExpanded}
433
+ * />
272
434
  */
273
435
  declare const ThinkingSection: React.ForwardRefExoticComponent<ThinkingSectionProps & React.RefAttributes<HTMLDivElement>>;
274
436
 
@@ -310,6 +472,56 @@ interface ActionBarProps extends React.HTMLAttributes<HTMLDivElement> {
310
472
  */
311
473
  declare const ActionBar: React.ForwardRefExoticComponent<ActionBarProps & React.RefAttributes<HTMLDivElement>>;
312
474
 
475
+ /**
476
+ * HITL Section Component
477
+ *
478
+ * Collapsible section for displaying completed HITL (Human-in-the-Loop)
479
+ * interactions within an AgentResponse. Follows the same pattern as
480
+ * ThinkingSection for consistent UX.
481
+ */
482
+
483
+ interface HITLSectionProps extends React.HTMLAttributes<HTMLDivElement> {
484
+ /** The HITL interactions to display */
485
+ interactions: HITLInteraction[];
486
+ /** Whether the section starts expanded (uncontrolled) */
487
+ defaultExpanded?: boolean;
488
+ /** Whether the section is expanded (controlled) */
489
+ isExpanded?: boolean;
490
+ /** Callback when expansion state changes (controlled) */
491
+ onExpandedChange?: (expanded: boolean) => void;
492
+ }
493
+ declare const HITLSection: React.ForwardRefExoticComponent<HITLSectionProps & React.RefAttributes<HTMLDivElement>>;
494
+
495
+ /**
496
+ * Truncated Message Component
497
+ *
498
+ * Renders a single-line text message with CSS-based truncation (text-overflow: ellipsis).
499
+ * Designed as a standalone utility that can be used anywhere, including as
500
+ * the statusContent slot in MetadataRow.
501
+ */
502
+
503
+ interface TruncatedMessageProps extends React.HTMLAttributes<HTMLDivElement> {
504
+ /** The message string to display (truncated with ellipsis if it overflows) */
505
+ message: string;
506
+ }
507
+ /**
508
+ * TruncatedMessage Component
509
+ *
510
+ * Displays a single-line text message that truncates with an ellipsis when
511
+ * it overflows its container. Uses CSS text-overflow for zero-JS truncation.
512
+ *
513
+ * @example
514
+ * <TruncatedMessage message="Searching the knowledge base for relevant documents..." />
515
+ *
516
+ * @example
517
+ * // Inside MetadataRow's statusContent slot
518
+ * <AgentResponse
519
+ * state={state}
520
+ * statusContent={<TruncatedMessage message="Running analysis..." />}
521
+ * />
522
+ */
523
+ declare const TruncatedMessage: React.ForwardRefExoticComponent<TruncatedMessageProps & React.RefAttributes<HTMLDivElement>>;
524
+
313
525
  /**
314
526
  * useThinkingTimer Hook
315
527
  *
@@ -375,4 +587,105 @@ declare function formatTime(seconds: number, isComplete: boolean): string;
375
587
  */
376
588
  declare function formatTotalTime(seconds: number): string;
377
589
 
378
- export { ActionBar, type ActionBarProps, ActivityIndicators, type ActivityIndicatorsProps, type AgentMessage, AgentResponse, type AgentResponseProps, type AgentResponseState, type AgentResponseStatus, type FeedbackValue, type GenericWebSocketMessage, type KnowledgeItem, type MemoryItem, MetadataRow, type MetadataRowProps, ThinkingSection, type ThinkingSectionProps, type ToolCall, type UseAgentResponseAccumulatorOptions, type UseAgentResponseAccumulatorReturn, type UseThinkingTimerOptions, formatTime, formatTotalTime, initialAgentResponseState, useAgentResponseAccumulator, useThinkingTimer };
590
+ interface UserPromptProps extends React.HTMLAttributes<HTMLDivElement> {
591
+ /** The text content of the user's message */
592
+ content: string;
593
+ /** Optional timestamp to display below the message */
594
+ timestamp?: Date;
595
+ }
596
+ /**
597
+ * UserPrompt component
598
+ *
599
+ * Displays a user's chat message in a styled bubble.
600
+ * Used alongside AgentResponse to create chat interfaces.
601
+ *
602
+ * @example
603
+ * ```tsx
604
+ * <UserPrompt
605
+ * content="What is the weather today?"
606
+ * timestamp={new Date()}
607
+ * />
608
+ * ```
609
+ *
610
+ * @example
611
+ * ```tsx
612
+ * // Custom styling
613
+ * <UserPrompt
614
+ * content="Hello world"
615
+ * className="max-w-full"
616
+ * />
617
+ * ```
618
+ */
619
+ declare const UserPrompt: React.ForwardRefExoticComponent<UserPromptProps & React.RefAttributes<HTMLDivElement>>;
620
+
621
+ interface UserPromptInputProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange" | "onSubmit"> {
622
+ /** Current text value */
623
+ value?: string;
624
+ /** Callback when text changes */
625
+ onChange?: (value: string) => void;
626
+ /** Callback when user submits (Enter key or send button) */
627
+ onSubmit?: (text: string) => void;
628
+ /** Clear input after submit (default: true) */
629
+ clearOnSubmit?: boolean;
630
+ /** Placeholder text */
631
+ placeholder?: string;
632
+ /** Whether the input is disabled */
633
+ disabled?: boolean;
634
+ /** Whether a submission is in progress (shows loading state) */
635
+ isSubmitting?: boolean;
636
+ /** Called when user clicks Stop during submission */
637
+ onStop?: () => void;
638
+ /** Whether to disable input while submitting (default: true) */
639
+ disableWhileSubmitting?: boolean;
640
+ /** Auto-focus the editor when mounted (handles Slate initialization timing) */
641
+ autoFocus?: boolean;
642
+ /** Refocus the input after submission completes (default: false) */
643
+ refocusAfterSubmit?: boolean;
644
+ /** Called when the editor is fully initialized and ready for interaction */
645
+ onReady?: () => void;
646
+ /** Minimum number of rows for the editor */
647
+ minRows?: number;
648
+ /** Maximum number of rows before scrolling */
649
+ maxRows?: number;
650
+ /** Render function for additional action buttons (left side) */
651
+ renderActions?: () => React.ReactNode;
652
+ /** Enable tag detection with # character */
653
+ enableTags?: boolean;
654
+ /** Callback when a tag is created */
655
+ onTagCreate?: (tag: string) => void;
656
+ /** Callback when a tag is deleted */
657
+ onTagDelete?: (tag: string) => void;
658
+ }
659
+ interface UserPromptInputRef {
660
+ /** Focus the editor */
661
+ focus: () => void;
662
+ /** Clear the editor content */
663
+ clear: () => void;
664
+ /** Get the current text content */
665
+ getText: () => string;
666
+ /** Insert text at cursor position */
667
+ insertText: (text: string) => void;
668
+ }
669
+
670
+ /**
671
+ * UserPromptInput Component
672
+ *
673
+ * A rich text input for user messages that wraps SlateEditor.
674
+ * Features:
675
+ * - Code block styling with triple backticks
676
+ * - Send button with loading state
677
+ * - Action slot for additional buttons
678
+ * - Tag support (optional)
679
+ *
680
+ * @example
681
+ * <UserPromptInput
682
+ * placeholder="Type your message..."
683
+ * onSubmit={(text) => sendMessage(text)}
684
+ * renderActions={() => (
685
+ * <IconButton icon={<Paperclip />} aria-label="Attach file" />
686
+ * )}
687
+ * />
688
+ */
689
+ declare const UserPromptInput: React.ForwardRefExoticComponent<UserPromptInputProps & React.RefAttributes<UserPromptInputRef>>;
690
+
691
+ export { ActionBar, type ActionBarProps, ActivityIndicators, type ActivityIndicatorsProps, type AgentMessage, AgentResponse, type AgentResponseProps, type AgentResponseState, type AgentResponseStatus, type FeedbackValue, type GenericWebSocketMessage, type HITLInteraction, HITLInteractionRecord, type HITLInteractionRecordProps, type HITLQuestion, HITLQuestionPanel, type HITLQuestionPanelProps, HITLSection, type HITLSectionProps, type KnowledgeItem, type MemoryItem, MetadataRow, type MetadataRowProps, type StatusItem, type ThinkingContent, ThinkingSection, type ThinkingSectionProps, type ThinkingStep, type ToolCall, TruncatedMessage, type TruncatedMessageProps, type UseAgentResponseAccumulatorOptions, type UseAgentResponseAccumulatorReturn, type UseThinkingTimerOptions, UserPrompt, UserPromptInput, type UserPromptInputProps, type UserPromptInputRef, type UserPromptProps, buildResponseString, formatTime, formatTotalTime, initialAgentResponseState, useAgentResponseAccumulator, useThinkingTimer };