@optilogic/chat 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.cjs +567 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +378 -0
- package/dist/index.d.ts +378 -0
- package/dist/index.js +537 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
- package/src/components/agent-response/AgentResponse.tsx +232 -0
- package/src/components/agent-response/components/ActionBar.tsx +150 -0
- package/src/components/agent-response/components/ActivityIndicators.tsx +140 -0
- package/src/components/agent-response/components/MetadataRow.tsx +145 -0
- package/src/components/agent-response/components/ThinkingSection.tsx +48 -0
- package/src/components/agent-response/components/index.ts +15 -0
- package/src/components/agent-response/hooks/index.ts +12 -0
- package/src/components/agent-response/hooks/useAgentResponseAccumulator.ts +186 -0
- package/src/components/agent-response/hooks/useThinkingTimer.ts +52 -0
- package/src/components/agent-response/index.ts +48 -0
- package/src/components/agent-response/types.ts +124 -0
- package/src/components/agent-response/utils.ts +48 -0
- package/src/index.ts +46 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Agent Response Component Types
|
|
5
|
+
*
|
|
6
|
+
* Type definitions for the library-ready agent response component
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Status of the agent response cycle
|
|
10
|
+
*/
|
|
11
|
+
type AgentResponseStatus = "idle" | "processing" | "complete";
|
|
12
|
+
/**
|
|
13
|
+
* Feedback value for the response
|
|
14
|
+
*/
|
|
15
|
+
type FeedbackValue = "up" | "down" | null;
|
|
16
|
+
/**
|
|
17
|
+
* Tool call information from the agent
|
|
18
|
+
*/
|
|
19
|
+
interface ToolCall {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
arguments?: Record<string, unknown>;
|
|
23
|
+
timestamp: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Knowledge retrieval information
|
|
27
|
+
*/
|
|
28
|
+
interface KnowledgeItem {
|
|
29
|
+
id: string;
|
|
30
|
+
source: string;
|
|
31
|
+
content: string;
|
|
32
|
+
timestamp: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Memory access information
|
|
36
|
+
*/
|
|
37
|
+
interface MemoryItem {
|
|
38
|
+
id: string;
|
|
39
|
+
type: string;
|
|
40
|
+
content: string;
|
|
41
|
+
timestamp: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* State shape for the agent response component
|
|
45
|
+
*/
|
|
46
|
+
interface AgentResponseState {
|
|
47
|
+
/** Current status of the response cycle */
|
|
48
|
+
status: AgentResponseStatus;
|
|
49
|
+
/** Accumulated thinking/reasoning text */
|
|
50
|
+
thinking: string;
|
|
51
|
+
/** Tool calls made during processing */
|
|
52
|
+
toolCalls: ToolCall[];
|
|
53
|
+
/** Knowledge items retrieved */
|
|
54
|
+
knowledge: KnowledgeItem[];
|
|
55
|
+
/** Memory items accessed */
|
|
56
|
+
memory: MemoryItem[];
|
|
57
|
+
/** Final response text */
|
|
58
|
+
response: string;
|
|
59
|
+
/** Timestamp when first thinking message was received (for timer) */
|
|
60
|
+
thinkingStartTime: number | null;
|
|
61
|
+
/** Timestamp when response was completed (for final timer display) */
|
|
62
|
+
responseCompleteTime: number | null;
|
|
63
|
+
/** Timestamp when first message of any type was received (for total time) */
|
|
64
|
+
firstMessageTime: number | null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* WebSocket message payload for agent responses
|
|
68
|
+
*/
|
|
69
|
+
interface AgentMessage {
|
|
70
|
+
type: "status" | "thinking" | "tool_call" | "knowledge" | "memory" | "response";
|
|
71
|
+
/** Message content - for simple string payloads */
|
|
72
|
+
message?: string;
|
|
73
|
+
/** Alternative content field */
|
|
74
|
+
content?: string;
|
|
75
|
+
/** For status messages */
|
|
76
|
+
status?: string;
|
|
77
|
+
/** For tool_call messages */
|
|
78
|
+
tool?: {
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
arguments?: Record<string, unknown>;
|
|
82
|
+
};
|
|
83
|
+
/** For knowledge messages */
|
|
84
|
+
knowledge?: {
|
|
85
|
+
id: string;
|
|
86
|
+
source: string;
|
|
87
|
+
content: string;
|
|
88
|
+
};
|
|
89
|
+
/** For memory messages */
|
|
90
|
+
memory?: {
|
|
91
|
+
id: string;
|
|
92
|
+
type: string;
|
|
93
|
+
content: string;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Generic websocket message wrapper type
|
|
98
|
+
*/
|
|
99
|
+
interface GenericWebSocketMessage {
|
|
100
|
+
topic: string;
|
|
101
|
+
message: AgentMessage;
|
|
102
|
+
accountId?: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Initial state for the agent response component
|
|
106
|
+
*/
|
|
107
|
+
declare const initialAgentResponseState: AgentResponseState;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* AgentResponse Component
|
|
111
|
+
*
|
|
112
|
+
* A library-ready presentational component for displaying AI agent responses.
|
|
113
|
+
* Displays thinking, tool calls, knowledge retrieval, memory access, and final response.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
interface AgentResponseProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
117
|
+
/** The response state to render */
|
|
118
|
+
state: AgentResponseState;
|
|
119
|
+
/** Optional unique ID (for list keys) */
|
|
120
|
+
id?: string;
|
|
121
|
+
/** Optional timestamp to display */
|
|
122
|
+
timestamp?: Date;
|
|
123
|
+
/** Feedback state (controlled) */
|
|
124
|
+
feedback?: FeedbackValue;
|
|
125
|
+
onFeedbackChange?: (feedback: FeedbackValue) => void;
|
|
126
|
+
/** Callback when the response is copied via the action bar */
|
|
127
|
+
onResponseCopy?: (response: string) => void;
|
|
128
|
+
/** Thinking section expansion (controlled or uncontrolled) */
|
|
129
|
+
defaultThinkingExpanded?: boolean;
|
|
130
|
+
thinkingExpanded?: boolean;
|
|
131
|
+
onThinkingExpandedChange?: (expanded: boolean) => void;
|
|
132
|
+
/** Action bar visibility mode */
|
|
133
|
+
actionsVisible?: boolean | "hover";
|
|
134
|
+
/**
|
|
135
|
+
* Custom markdown renderer for the response content.
|
|
136
|
+
* If not provided, the response will be rendered as plain text.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* <AgentResponse
|
|
140
|
+
* state={state}
|
|
141
|
+
* renderMarkdown={(content) => <MyMarkdownRenderer content={content} />}
|
|
142
|
+
* />
|
|
143
|
+
*/
|
|
144
|
+
renderMarkdown?: (content: string) => React.ReactNode;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* AgentResponse Component
|
|
148
|
+
*
|
|
149
|
+
* A complete component for displaying AI agent responses including:
|
|
150
|
+
* - Thinking/reasoning content (collapsible)
|
|
151
|
+
* - Tool calls, knowledge retrieval, and memory access indicators
|
|
152
|
+
* - Final response with optional markdown rendering
|
|
153
|
+
* - Action bar with copy and feedback buttons
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* // Basic usage with useAgentResponseAccumulator hook
|
|
157
|
+
* const { state, handleMessage } = useAgentResponseAccumulator();
|
|
158
|
+
*
|
|
159
|
+
* <AgentResponse state={state} />
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* // With markdown rendering and feedback
|
|
163
|
+
* <AgentResponse
|
|
164
|
+
* state={state}
|
|
165
|
+
* renderMarkdown={(content) => <ReactMarkdown>{content}</ReactMarkdown>}
|
|
166
|
+
* feedback={feedback}
|
|
167
|
+
* onFeedbackChange={setFeedback}
|
|
168
|
+
* />
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* // Controlled thinking expansion
|
|
172
|
+
* <AgentResponse
|
|
173
|
+
* state={state}
|
|
174
|
+
* thinkingExpanded={isExpanded}
|
|
175
|
+
* onThinkingExpandedChange={setIsExpanded}
|
|
176
|
+
* />
|
|
177
|
+
*/
|
|
178
|
+
declare const AgentResponse: React.ForwardRefExoticComponent<AgentResponseProps & React.RefAttributes<HTMLDivElement>>;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Activity Indicators Component
|
|
182
|
+
*
|
|
183
|
+
* Displays tool, knowledge, memory icons with counts and popovers
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
interface ActivityIndicatorsProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
187
|
+
/** Tool calls to display */
|
|
188
|
+
toolCalls: ToolCall[];
|
|
189
|
+
/** Knowledge items to display */
|
|
190
|
+
knowledge: KnowledgeItem[];
|
|
191
|
+
/** Memory items to display */
|
|
192
|
+
memory: MemoryItem[];
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* ActivityIndicators Component
|
|
196
|
+
*
|
|
197
|
+
* Displays icons with counts for tool calls, knowledge retrieval, and memory access.
|
|
198
|
+
* Each icon has a popover showing details when clicked.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* <ActivityIndicators
|
|
202
|
+
* toolCalls={state.toolCalls}
|
|
203
|
+
* knowledge={state.knowledge}
|
|
204
|
+
* memory={state.memory}
|
|
205
|
+
* />
|
|
206
|
+
*/
|
|
207
|
+
declare const ActivityIndicators: React.ForwardRefExoticComponent<ActivityIndicatorsProps & React.RefAttributes<HTMLDivElement>>;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Metadata Row Component
|
|
211
|
+
*
|
|
212
|
+
* Displays thinking toggle, timer, and activity indicators
|
|
213
|
+
*/
|
|
214
|
+
|
|
215
|
+
interface MetadataRowProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
216
|
+
/** Whether there is thinking content */
|
|
217
|
+
hasThinking: boolean;
|
|
218
|
+
/** Whether the thinking section is expanded */
|
|
219
|
+
isExpanded: boolean;
|
|
220
|
+
/** Toggle callback for thinking expansion */
|
|
221
|
+
onToggle: () => void;
|
|
222
|
+
/** Tool calls to display */
|
|
223
|
+
toolCalls: ToolCall[];
|
|
224
|
+
/** Knowledge items to display */
|
|
225
|
+
knowledge: KnowledgeItem[];
|
|
226
|
+
/** Memory items to display */
|
|
227
|
+
memory: MemoryItem[];
|
|
228
|
+
/** Current response status */
|
|
229
|
+
status: AgentResponseStatus;
|
|
230
|
+
/** Elapsed time in seconds */
|
|
231
|
+
elapsedTime: number;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* MetadataRow Component
|
|
235
|
+
*
|
|
236
|
+
* Displays the metadata row with thinking toggle, timer, and activity indicators.
|
|
237
|
+
* When thinking content is present, the row is clickable to toggle expansion.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* <MetadataRow
|
|
241
|
+
* hasThinking={!!state.thinking}
|
|
242
|
+
* isExpanded={thinkingExpanded}
|
|
243
|
+
* onToggle={toggleThinking}
|
|
244
|
+
* toolCalls={state.toolCalls}
|
|
245
|
+
* knowledge={state.knowledge}
|
|
246
|
+
* memory={state.memory}
|
|
247
|
+
* status={state.status}
|
|
248
|
+
* elapsedTime={elapsedTime}
|
|
249
|
+
* />
|
|
250
|
+
*/
|
|
251
|
+
declare const MetadataRow: React.ForwardRefExoticComponent<MetadataRowProps & React.RefAttributes<HTMLDivElement>>;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Thinking Section Component
|
|
255
|
+
*
|
|
256
|
+
* Collapsible section for displaying agent thinking/reasoning content
|
|
257
|
+
*/
|
|
258
|
+
|
|
259
|
+
interface ThinkingSectionProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
260
|
+
/** The thinking content to display */
|
|
261
|
+
content: string;
|
|
262
|
+
/** Whether the section is expanded */
|
|
263
|
+
isExpanded: boolean;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* ThinkingSection Component
|
|
267
|
+
*
|
|
268
|
+
* Displays the agent's thinking/reasoning content in a collapsible panel.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* <ThinkingSection content={state.thinking} isExpanded={isExpanded} />
|
|
272
|
+
*/
|
|
273
|
+
declare const ThinkingSection: React.ForwardRefExoticComponent<ThinkingSectionProps & React.RefAttributes<HTMLDivElement>>;
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Action Bar Component
|
|
277
|
+
*
|
|
278
|
+
* Displays copy, feedback, and timing actions for the response
|
|
279
|
+
*/
|
|
280
|
+
|
|
281
|
+
interface ActionBarProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
282
|
+
/** The response text (for copying) */
|
|
283
|
+
response: string;
|
|
284
|
+
/** Whether the action bar is visible */
|
|
285
|
+
isVisible: boolean;
|
|
286
|
+
/** Total time in seconds */
|
|
287
|
+
totalTimeSeconds: number;
|
|
288
|
+
/** Current feedback value */
|
|
289
|
+
feedback?: FeedbackValue;
|
|
290
|
+
/** Callback when feedback changes */
|
|
291
|
+
onFeedbackChange?: (feedback: FeedbackValue) => void;
|
|
292
|
+
/** Callback when response is copied */
|
|
293
|
+
onResponseCopy?: (response: string) => void;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* ActionBar Component
|
|
297
|
+
*
|
|
298
|
+
* Displays action buttons for copying the response, providing feedback,
|
|
299
|
+
* and showing total response time.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* <ActionBar
|
|
303
|
+
* response={state.response}
|
|
304
|
+
* isVisible={isHovered}
|
|
305
|
+
* totalTimeSeconds={totalTime}
|
|
306
|
+
* feedback={feedback}
|
|
307
|
+
* onFeedbackChange={setFeedback}
|
|
308
|
+
* onCopy={handleCopy}
|
|
309
|
+
* />
|
|
310
|
+
*/
|
|
311
|
+
declare const ActionBar: React.ForwardRefExoticComponent<ActionBarProps & React.RefAttributes<HTMLDivElement>>;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* useThinkingTimer Hook
|
|
315
|
+
*
|
|
316
|
+
* Tracks elapsed time during agent thinking/processing
|
|
317
|
+
*/
|
|
318
|
+
|
|
319
|
+
interface UseThinkingTimerOptions {
|
|
320
|
+
startTime: number | null;
|
|
321
|
+
endTime: number | null;
|
|
322
|
+
status: AgentResponseStatus;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Custom hook for thinking timer
|
|
326
|
+
* Returns elapsed time in seconds
|
|
327
|
+
*/
|
|
328
|
+
declare function useThinkingTimer({ startTime, endTime, status, }: UseThinkingTimerOptions): number;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* useAgentResponseAccumulator Hook
|
|
332
|
+
*
|
|
333
|
+
* Accumulates agent response messages into a unified state
|
|
334
|
+
*/
|
|
335
|
+
|
|
336
|
+
interface UseAgentResponseAccumulatorOptions {
|
|
337
|
+
/** WebSocket topic to filter messages (optional, for convenience) */
|
|
338
|
+
topic?: string;
|
|
339
|
+
}
|
|
340
|
+
interface UseAgentResponseAccumulatorReturn {
|
|
341
|
+
/** Current accumulated state */
|
|
342
|
+
state: AgentResponseState;
|
|
343
|
+
/** Handler to process incoming messages */
|
|
344
|
+
handleMessage: (message: unknown) => void;
|
|
345
|
+
/** Reset state to initial */
|
|
346
|
+
reset: () => void;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Hook for accumulating agent response messages into a unified state
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* const { state, handleMessage, reset } = useAgentResponseAccumulator({ topic: "agent" });
|
|
353
|
+
*
|
|
354
|
+
* // In your WebSocket handler:
|
|
355
|
+
* websocket.onmessage = (event) => {
|
|
356
|
+
* handleMessage(JSON.parse(event.data));
|
|
357
|
+
* };
|
|
358
|
+
*/
|
|
359
|
+
declare function useAgentResponseAccumulator(options?: UseAgentResponseAccumulatorOptions): UseAgentResponseAccumulatorReturn;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Agent Response Utility Functions
|
|
363
|
+
*/
|
|
364
|
+
/**
|
|
365
|
+
* Format elapsed time for display
|
|
366
|
+
* - Under 60s: "Xs" (e.g., "23s")
|
|
367
|
+
* - 60+ seconds while active: "M:SS" (e.g., "1:23")
|
|
368
|
+
* - Complete under 60s: "Xs" (e.g., "45s")
|
|
369
|
+
* - Complete 60-119s: "1.X min" (e.g., "1.2 min")
|
|
370
|
+
* - Complete 120+ s: "X.X min" (e.g., "2.5 min")
|
|
371
|
+
*/
|
|
372
|
+
declare function formatTime(seconds: number, isComplete: boolean): string;
|
|
373
|
+
/**
|
|
374
|
+
* Format total time for action bar display
|
|
375
|
+
*/
|
|
376
|
+
declare function formatTotalTime(seconds: number): string;
|
|
377
|
+
|
|
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 };
|