@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/README.md ADDED
@@ -0,0 +1,235 @@
1
+ # @optilogic/chat
2
+
3
+ Chat UI components for opti-ui - Components for displaying LLM/AI agent interactions.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @optilogic/chat @optilogic/core @optilogic/editor slate slate-react slate-history
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ Make sure you have configured `@optilogic/core` with the Tailwind preset and CSS variables.
14
+
15
+ ## Usage
16
+
17
+ ### AgentResponse
18
+
19
+ Display AI agent responses with thinking indicators, tool calls, and feedback actions:
20
+
21
+ ```tsx
22
+ import { AgentResponse, useAgentResponseAccumulator } from '@optilogic/chat';
23
+
24
+ function ChatView() {
25
+ const { state, handlers } = useAgentResponseAccumulator({
26
+ onComplete: (response) => console.log('Response complete:', response),
27
+ });
28
+
29
+ return (
30
+ <AgentResponse
31
+ {...state}
32
+ onCopy={() => navigator.clipboard.writeText(state.content)}
33
+ onFeedback={(value) => console.log('Feedback:', value)}
34
+ />
35
+ );
36
+ }
37
+ ```
38
+
39
+ ### UserPrompt
40
+
41
+ Display user messages in the chat:
42
+
43
+ ```tsx
44
+ import { UserPrompt } from '@optilogic/chat';
45
+
46
+ function ChatMessage() {
47
+ return (
48
+ <UserPrompt
49
+ content="What is the weather today?"
50
+ timestamp={new Date()}
51
+ />
52
+ );
53
+ }
54
+ ```
55
+
56
+ ### UserPromptInput
57
+
58
+ Input component for user messages:
59
+
60
+ ```tsx
61
+ import { UserPromptInput } from '@optilogic/chat';
62
+
63
+ function ChatInput() {
64
+ return (
65
+ <UserPromptInput
66
+ onSubmit={(text) => console.log('Submitted:', text)}
67
+ placeholder="Type your message..."
68
+ />
69
+ );
70
+ }
71
+ ```
72
+
73
+ ### HITLQuestionPanel
74
+
75
+ Display an interactive panel for human-in-the-loop clarifying questions. Replaces the input area when the agent needs user clarification:
76
+
77
+ ```tsx
78
+ import { HITLQuestionPanel, type HITLQuestion } from '@optilogic/chat';
79
+
80
+ const question: HITLQuestion = {
81
+ reason: "I need clarification before proceeding with the data mapping.",
82
+ questions: [
83
+ "Which table should I load the shipment data into?",
84
+ "Should I overwrite existing rows or append?",
85
+ ],
86
+ options: {
87
+ "Which table should I load the shipment data into?": ["Customers", "Demand", "Shipments"],
88
+ "Should I overwrite existing rows or append?": ["Overwrite", "Append"],
89
+ },
90
+ context: "Source file has 1,200 rows with columns: origin, destination, quantity, date",
91
+ timeoutSeconds: 300,
92
+ receivedAt: Date.now(),
93
+ };
94
+
95
+ function ChatInput() {
96
+ return (
97
+ <HITLQuestionPanel
98
+ question={question}
99
+ onSubmit={(response) => console.log('Response:', response)}
100
+ onStop={() => console.log('Agent stopped')}
101
+ />
102
+ );
103
+ }
104
+ ```
105
+
106
+ ### HITLInteractionRecord
107
+
108
+ Display a completed HITL Q&A interaction in the chat history:
109
+
110
+ ```tsx
111
+ import { HITLInteractionRecord, type HITLInteraction } from '@optilogic/chat';
112
+
113
+ const interaction: HITLInteraction = {
114
+ question: { /* HITLQuestion object */ },
115
+ response: "Q: Which table?\nA: Shipments",
116
+ respondedAt: Date.now(),
117
+ };
118
+
119
+ function CompletedInteraction() {
120
+ return <HITLInteractionRecord interaction={interaction} />;
121
+ }
122
+ ```
123
+
124
+ ### AgentResponse with HITL Interactions
125
+
126
+ HITL interactions can also be displayed as a collapsible section within AgentResponse:
127
+
128
+ ```tsx
129
+ import { AgentResponse, type HITLInteraction } from '@optilogic/chat';
130
+
131
+ function ChatView() {
132
+ const hitlInteractions: HITLInteraction[] = [/* completed interactions */];
133
+
134
+ return (
135
+ <AgentResponse
136
+ state={state}
137
+ hitlInteractions={hitlInteractions}
138
+ defaultHITLExpanded={false}
139
+ />
140
+ );
141
+ }
142
+ ```
143
+
144
+ ### AgentResponse with Status Content
145
+
146
+ Display ephemeral status messages in the metadata row during agent processing:
147
+
148
+ ```tsx
149
+ import { AgentResponse, TruncatedMessage } from '@optilogic/chat';
150
+
151
+ function ChatView() {
152
+ const [statusMessage, setStatusMessage] = useState<string>();
153
+
154
+ // Parent controls when to show/clear status content
155
+ // e.g., set during processing, clear on completion
156
+
157
+ return (
158
+ <AgentResponse
159
+ state={state}
160
+ statusContent={
161
+ statusMessage
162
+ ? <TruncatedMessage message={statusMessage} />
163
+ : undefined
164
+ }
165
+ />
166
+ );
167
+ }
168
+ ```
169
+
170
+ ### TruncatedMessage
171
+
172
+ Standalone component that renders a single-line string with CSS-based truncation:
173
+
174
+ ```tsx
175
+ import { TruncatedMessage } from '@optilogic/chat';
176
+
177
+ <TruncatedMessage message="Searching the knowledge base for relevant documents..." />
178
+ ```
179
+
180
+ ## Components
181
+
182
+ ### AgentResponse
183
+ Main component for displaying AI agent responses with:
184
+ - Streaming content support
185
+ - Thinking/reasoning indicators
186
+ - Tool call visualization
187
+ - Copy and feedback actions
188
+ - Metadata display (tokens, timing)
189
+ - Ephemeral status content slot in metadata row
190
+ - Optional collapsible HITL interaction history
191
+
192
+ ### UserPrompt
193
+ Component for displaying user messages in the chat interface.
194
+
195
+ ### UserPromptInput
196
+ Input component for composing user messages with tag support.
197
+
198
+ ### HITLQuestionPanel
199
+ Interactive panel for displaying agent clarifying questions with:
200
+ - Predefined option buttons (toggleable selection)
201
+ - Free-form text input
202
+ - Countdown timer with visual warning state
203
+ - Keyboard support (Enter to submit, Shift+Enter for newlines)
204
+
205
+ ### HITLInteractionRecord
206
+ Read-only display of a completed HITL Q&A interaction with:
207
+ - Per-question inline answers
208
+ - Context display
209
+ - Fallback for non-structured response formats
210
+
211
+ ### HITLSection
212
+ Collapsible sub-component for rendering HITL interactions within AgentResponse. Follows the same expand/collapse pattern as ThinkingSection.
213
+
214
+ ### TruncatedMessage
215
+ Standalone utility component for single-line text truncation with:
216
+ - CSS-based ellipsis truncation
217
+ - Native title tooltip for full text on hover
218
+ - Designed for use in MetadataRow status slot or anywhere else
219
+
220
+ ## Hooks
221
+
222
+ ### useAgentResponseAccumulator
223
+ Manages state for streaming agent responses, handling incremental updates and message accumulation.
224
+
225
+ ### useThinkingTimer
226
+ Tracks elapsed time during agent thinking phases.
227
+
228
+ ## Utilities
229
+
230
+ ### buildResponseString
231
+ Combines selected options and free-form text into a single formatted string for the backend. Used internally by HITLQuestionPanel and can be used to construct responses programmatically.
232
+
233
+ ## License
234
+
235
+ MIT