@agents24/chat-react 0.1.6 → 0.1.8

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.
Files changed (42) hide show
  1. package/README.md +29 -12
  2. package/dist/chunk-E3TJ3I6G.js +358 -0
  3. package/dist/chunk-E3TJ3I6G.js.map +1 -0
  4. package/dist/chunk-EWZO4QJI.js +140 -0
  5. package/dist/chunk-EWZO4QJI.js.map +1 -0
  6. package/dist/chunk-UU7OXHL3.js +11 -0
  7. package/dist/chunk-UU7OXHL3.js.map +1 -0
  8. package/dist/context-window.d.ts +38 -0
  9. package/dist/controller.d.ts +22 -0
  10. package/dist/index.cjs +653 -336
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.ts +10 -466
  13. package/dist/index.js +290 -455
  14. package/dist/index.js.map +1 -1
  15. package/dist/latest-thread-scroller.d.ts +54 -0
  16. package/dist/model.d.ts +29 -0
  17. package/dist/renderers.d.ts +10 -0
  18. package/dist/sse.d.ts +3 -0
  19. package/dist/streaming-text.d.ts +24 -0
  20. package/dist/templates/agent-chat-shell.d.ts +25 -0
  21. package/dist/templates/index.cjs +523 -0
  22. package/dist/templates/index.cjs.map +1 -0
  23. package/dist/templates/index.d.ts +1 -0
  24. package/dist/templates/index.js +140 -0
  25. package/dist/templates/index.js.map +1 -0
  26. package/dist/transport.d.ts +29 -0
  27. package/dist/types.d.ts +312 -0
  28. package/dist/ui/adapters.d.ts +36 -0
  29. package/dist/ui/attachment.d.ts +23 -0
  30. package/dist/ui/bubble.d.ts +17 -0
  31. package/dist/ui/index.cjs +943 -0
  32. package/dist/ui/index.cjs.map +1 -0
  33. package/dist/ui/index.d.ts +7 -0
  34. package/dist/ui/index.js +734 -0
  35. package/dist/ui/index.js.map +1 -0
  36. package/dist/ui/marker.d.ts +11 -0
  37. package/dist/ui/message-response.d.ts +7 -0
  38. package/dist/ui/message.d.ts +10 -0
  39. package/dist/ui/utils.d.ts +2 -0
  40. package/dist/viewport.d.ts +2 -0
  41. package/package.json +22 -4
  42. package/dist/index.d.cts +0 -466
package/dist/index.d.ts CHANGED
@@ -1,466 +1,10 @@
1
- import * as react from 'react';
2
- import { ReactNode, RefObject, UIEvent } from 'react';
3
-
4
- type ChatRunStatus = "queued" | "running" | "completed" | "cancelled" | "failed" | string;
5
- type ChatContextWindow = {
6
- stage?: string;
7
- label?: string;
8
- usedTokens?: number;
9
- maxTokens?: number;
10
- [key: string]: unknown;
11
- };
12
- type ChatCitation = {
13
- title: string;
14
- url: string;
15
- description: string;
16
- sourceRef?: string;
17
- ref?: string;
18
- firstRef?: string;
19
- totalSegments?: number;
20
- rangeRef?: string;
21
- };
22
- type ChatAttachment = {
23
- url?: string;
24
- filename?: string;
25
- mediaType?: string;
26
- contentType?: string;
27
- [key: string]: unknown;
28
- };
29
- type ChatReasoningStep = {
30
- label: string;
31
- status: "active" | "complete" | "pending";
32
- icon?: unknown;
33
- description?: string;
34
- citations?: ChatCitation[];
35
- query?: string;
36
- sources?: Array<Record<string, unknown>>;
37
- };
38
- type ChatToolState = "input-streaming" | "input-available" | "output-available" | "output-error" | "cancelled";
39
- type ToolPresentation = {
40
- title?: string | null;
41
- activity?: string | null;
42
- detail?: string | null;
43
- category?: string | null;
44
- groupKey?: string | null;
45
- groupLabel?: string | null;
46
- showOutput?: boolean;
47
- outputView?: Record<string, unknown> | null;
48
- [key: string]: unknown;
49
- };
50
- type ChatTextPart = {
51
- id: string;
52
- type: "text";
53
- kind: "text";
54
- text: string;
55
- raw?: Record<string, unknown>;
56
- };
57
- type ChatToolPart = {
58
- id: string;
59
- type: `tool-${string}`;
60
- kind: "tool";
61
- toolName: string;
62
- toolCallId?: string | null;
63
- state: ChatToolState;
64
- input?: unknown;
65
- output?: unknown;
66
- errorText?: string | null;
67
- presentation?: ToolPresentation | null;
68
- raw: Record<string, unknown>;
69
- };
70
- type ChatReasoningPart = {
71
- id: string;
72
- type: "reasoning";
73
- kind: "reasoning";
74
- label?: string | null;
75
- text?: string | null;
76
- status?: string | null;
77
- raw: Record<string, unknown>;
78
- };
79
- type ChatUiBlocksPart = {
80
- id: string;
81
- type: "ui-blocks";
82
- kind: "ui-blocks";
83
- state: ChatToolState;
84
- toolCallId?: string | null;
85
- contractVersion?: string | null;
86
- bundle?: Record<string, unknown> | null;
87
- errorText?: string | null;
88
- raw: Record<string, unknown>;
89
- };
90
- type ChatApprovalPart = {
91
- id: string;
92
- type: "approval";
93
- kind: "approval";
94
- raw: Record<string, unknown>;
95
- };
96
- type ChatErrorPart = {
97
- id: string;
98
- type: "error";
99
- kind: "error";
100
- errorText: string;
101
- raw: Record<string, unknown>;
102
- };
103
- type ChatDataPart = {
104
- id: string;
105
- type: "data";
106
- kind: "data";
107
- name: string;
108
- data: Record<string, unknown>;
109
- raw: Record<string, unknown>;
110
- };
111
- type ChatPart = ChatTextPart | ChatToolPart | ChatReasoningPart | ChatUiBlocksPart | ChatApprovalPart | ChatErrorPart | ChatDataPart;
112
- type ToolRenderer = (props: {
113
- part: ChatToolPart;
114
- message: ChatMessage;
115
- }) => ReactNode;
116
- type Agents24ChatRenderOptions = {
117
- renderPart?: (part: ChatPart, message: ChatMessage) => ReactNode;
118
- toolRenderers?: Partial<Record<`tool-${string}`, ToolRenderer>>;
119
- fallbackToolRenderer?: ToolRenderer;
120
- };
121
- type ChatMessage = {
122
- id: string;
123
- role: "user" | "assistant";
124
- runId?: string | null;
125
- content: string;
126
- createdAt: Date;
127
- isFinal?: boolean;
128
- parts: ChatPart[];
129
- attachments?: ChatAttachment[];
130
- citations?: ChatCitation[];
131
- reasoningSteps?: ChatReasoningStep[];
132
- thinkingDurationMs?: number;
133
- liked?: boolean;
134
- disliked?: boolean;
135
- messageIndex?: number;
136
- isVoice?: boolean;
137
- };
138
- type ChatRuntimeEvent = {
139
- version?: string;
140
- seq?: number;
141
- ts?: string;
142
- event: string;
143
- run_id?: string;
144
- stage?: string;
145
- payload?: Record<string, unknown>;
146
- diagnostics?: Array<Record<string, unknown>>;
147
- };
148
- type ChatActiveRun = {
149
- run_id?: string | null;
150
- status?: string | null;
151
- started_at?: string | null;
152
- created_at?: string | null;
153
- };
154
- type ChatThreadSummary = {
155
- id: string;
156
- title?: string | null;
157
- status?: string | null;
158
- surface?: string | null;
159
- agent_id?: string | null;
160
- last_run_id?: string | null;
161
- last_run_status?: string | null;
162
- active_run?: ChatActiveRun | null;
163
- activeRun?: ChatActiveRun | null;
164
- updated_at?: string | null;
165
- last_activity_at?: string | null;
166
- created_at?: string | null;
167
- messages?: ChatMessage[];
168
- isHydrated?: boolean;
169
- hasOlderTurns?: boolean;
170
- nextBeforeTurnIndex?: number | null;
171
- lastRunId?: string | null;
172
- lastRunStatus?: string | null;
173
- lastEventSeq?: number | null;
174
- isRunning?: boolean;
175
- [key: string]: unknown;
176
- };
177
- type ChatThreadTurn = {
178
- id?: string;
179
- run_id?: string;
180
- turn_index?: number;
181
- status?: string | null;
182
- user_input_text?: string | null;
183
- assistant_output_text?: string | null;
184
- final_output?: unknown;
185
- response_blocks?: Array<Record<string, unknown>>;
186
- run_events?: ChatRuntimeEvent[];
187
- context_window?: unknown;
188
- attachments?: Array<Record<string, unknown>>;
189
- created_at?: string | null;
190
- completed_at?: string | null;
191
- };
192
- type ChatThreadDetail = ChatThreadSummary & {
193
- turns?: ChatThreadTurn[];
194
- context_window?: unknown;
195
- paging?: {
196
- has_more?: boolean;
197
- next_before_turn_index?: number | null;
198
- };
199
- };
200
- type ChatTransport = {
201
- listThreads: (input?: {
202
- signal?: AbortSignal;
203
- }) => Promise<{
204
- items: ChatThreadSummary[];
205
- total?: number;
206
- }>;
207
- getThread: (input: {
208
- threadId: string;
209
- limit?: number;
210
- beforeTurnIndex?: number | null;
211
- includeRunEvents?: boolean;
212
- signal?: AbortSignal;
213
- }) => Promise<ChatThreadDetail>;
214
- streamMessage: (input: {
215
- text: string;
216
- threadId?: string | null;
217
- files?: ChatAttachment[];
218
- signal?: AbortSignal;
219
- }, onEvent: (event: ChatRuntimeEvent) => void | Promise<void>) => Promise<ChatStreamResult>;
220
- attachRun: (input: {
221
- runId: string;
222
- signal?: AbortSignal;
223
- }, onEvent: (event: ChatRuntimeEvent) => void | Promise<void>) => Promise<ChatStreamResult>;
224
- cancelRun: (input: {
225
- runId: string;
226
- assistantOutputText?: string;
227
- }) => Promise<{
228
- run_id?: string;
229
- status?: string;
230
- }>;
231
- deleteThread?: (input: {
232
- threadId: string;
233
- }) => Promise<{
234
- deleted?: boolean;
235
- }>;
236
- uploadAttachment?: (input: {
237
- file: File;
238
- signal?: AbortSignal;
239
- }) => Promise<ChatAttachment>;
240
- };
241
- type ChatStreamResult = {
242
- threadId?: string | null;
243
- runId?: string | null;
244
- };
245
- type StoredChatThread = ChatThreadSummary & {
246
- messages: ChatMessage[];
247
- isHydrated?: boolean;
248
- hasOlderTurns?: boolean;
249
- nextBeforeTurnIndex?: number | null;
250
- };
251
- type ChatStorageAdapter = {
252
- listThreads: () => StoredChatThread[];
253
- setThreads: (threads: StoredChatThread[]) => void;
254
- getThread: (threadId: string) => StoredChatThread | undefined;
255
- upsertThread: (thread: StoredChatThread) => void;
256
- deleteThread?: (threadId: string) => void;
257
- getActiveThreadId?: () => string | null;
258
- setActiveThreadId?: (threadId: string | null) => void;
259
- };
260
- type ChatController = {
261
- messages: ChatMessage[];
262
- streamingContent: string;
263
- streamingMessageId: string | null;
264
- contextStatus: ChatContextWindow | null;
265
- currentReasoning: ChatReasoningStep[];
266
- isLoading: boolean;
267
- isLoadingHistory: boolean;
268
- isLoadingOlder: boolean;
269
- hasOlderTurns: boolean;
270
- liked: Record<string, boolean>;
271
- disliked: Record<string, boolean>;
272
- copiedMessageId: string | null;
273
- lastThinkingDurationMs: number | null;
274
- activeRunId: string | null;
275
- handleSubmit: (message: {
276
- text: string;
277
- files?: ChatAttachment[];
278
- }) => Promise<void>;
279
- handleStop: () => void;
280
- handleCopy: (content: string, messageId: string) => void;
281
- handleLike: (msg: ChatMessage) => Promise<void>;
282
- handleDislike: (msg: ChatMessage) => Promise<void>;
283
- handleRetry: (msg: ChatMessage) => Promise<void>;
284
- handleSourceClick: (citations: ChatMessage["citations"]) => void;
285
- upsertLiveVoiceMessage: (input: {
286
- role: "user" | "assistant";
287
- content: string;
288
- isFinal?: boolean;
289
- citations?: ChatCitation[];
290
- reasoningSteps?: ChatReasoningStep[];
291
- }) => void;
292
- loadOlderTurns: () => Promise<void>;
293
- refresh: () => Promise<void>;
294
- textareaRef: RefObject<HTMLTextAreaElement | null>;
295
- };
296
-
297
- type UseAgents24ChatControllerOptions = {
298
- transport: ChatTransport;
299
- storage: ChatStorageAdapter;
300
- activeThreadId?: string | null;
301
- pageSize?: number;
302
- storageKey?: unknown;
303
- createId?: () => string;
304
- onActiveThreadIdChange?: (threadId: string | null) => void;
305
- onSourceClick?: (citations: ChatMessage["citations"]) => void;
306
- onStreamErrorMessage?: (error: unknown) => string;
307
- };
308
- declare function useAgents24ChatController({ transport, storage, activeThreadId: controlledActiveThreadId, pageSize, storageKey, createId, onActiveThreadIdChange, onSourceClick, onStreamErrorMessage, }: UseAgents24ChatControllerOptions): ChatController;
309
-
310
- declare const DEFAULT_THREAD_PAGE_SIZE = 5;
311
- declare const isRunningThreadStatus: (status?: string | null) => boolean;
312
- declare const createChatId: () => string;
313
- declare const titleFromMessage: (text: string, files?: Array<{
314
- filename?: string;
315
- }>) => string;
316
- declare const threadActivityDate: (thread: ChatThreadSummary) => string;
317
- declare const assistantTextFromResponseBlocks: (blocks?: Array<Record<string, unknown>>) => string;
318
- declare const assistantTextFromParts: (parts?: ChatPart[]) => string;
319
- declare const textFromFinalOutput: (value: unknown) => string;
320
- declare const toolStateFromStatus: (status?: unknown) => ChatToolState;
321
- declare const partsFromResponseBlocks: (blocks?: Array<Record<string, unknown>>, fallbackText?: string) => ChatPart[];
322
- declare const mergeReasoningSteps: (steps?: ChatReasoningStep[], options?: {
323
- finalize?: boolean;
324
- }) => ChatReasoningStep[];
325
- declare const reasoningStepsFromParts: (parts?: ChatPart[]) => ChatReasoningStep[];
326
- declare const threadDetailToMessages: (thread: ChatThreadDetail) => ChatMessage[];
327
- declare const threadPaging: (thread: ChatThreadDetail) => {
328
- hasOlderTurns: boolean;
329
- nextBeforeTurnIndex: number | null;
330
- };
331
- declare const latestContextWindowFromThread: (thread: ChatThreadDetail) => ChatContextWindow | null;
332
- declare const activeRunIdFromThread: (thread?: Partial<ChatThreadSummary> | null) => string | null;
333
- declare const hasUnfinishedAssistantMessage: (messages?: ChatMessage[]) => boolean;
334
- declare const hasStaleUnfinishedAssistantCache: (thread?: (Partial<ChatThreadSummary> & {
335
- messages?: ChatMessage[];
336
- }) | null) => boolean;
337
- declare const activeRunIdFromThreadDetail: (thread?: ChatThreadDetail | null) => string | null;
338
-
339
- declare const DefaultToolPart: ({ part }: {
340
- part: ChatToolPart;
341
- }) => react.JSX.Element;
342
- declare const DefaultChatPart: ({ part, message, renderOptions, }: {
343
- part: ChatPart;
344
- message: ChatMessage;
345
- renderOptions?: Agents24ChatRenderOptions;
346
- }) => react.JSX.Element;
347
- declare const renderChatPart: (part: ChatPart, message: ChatMessage, renderOptions?: Agents24ChatRenderOptions) => react.JSX.Element;
348
-
349
- declare const parseSseBlock: (block: string) => ChatRuntimeEvent | null;
350
- declare const consumeSseResponse: (response: Response, onEvent: (event: ChatRuntimeEvent) => void | Promise<void>) => Promise<ChatStreamResult>;
351
-
352
- type StreamingTextMode = "streaming" | "static";
353
- type StreamingTextCache = {
354
- get: (id: string) => string | undefined;
355
- set: (id: string, text: string) => void;
356
- };
357
- type UseStreamingTextOptions = {
358
- id: string;
359
- isStreaming: boolean;
360
- text: string;
361
- cache?: StreamingTextCache | false;
362
- charsPerSecond?: number;
363
- catchupThreshold?: number;
364
- maxCatchupChars?: number;
365
- };
366
- type UseStreamingTextResult = {
367
- displayedText: string;
368
- isAnimating: boolean;
369
- mode: StreamingTextMode;
370
- parseIncompleteMarkdown: boolean;
371
- };
372
- declare const getActiveStreamingTextPartId: (message: ChatMessage, streamingMessageId: string | null) => string | null;
373
- declare const isActiveStreamingTextPart: (message: ChatMessage, part: ChatPart, streamingMessageId: string | null) => boolean;
374
- declare function useStreamingText({ id, isStreaming, text, cache, charsPerSecond, catchupThreshold, maxCatchupChars, }: UseStreamingTextOptions): UseStreamingTextResult;
375
-
376
- type MaybePromise<T> = T | Promise<T>;
377
- type FetchChatTransportRoutes = {
378
- listThreads: () => string;
379
- getThread: (input: {
380
- threadId: string;
381
- limit?: number;
382
- beforeTurnIndex?: number | null;
383
- includeRunEvents?: boolean;
384
- }) => string;
385
- streamMessage: () => string;
386
- attachRun: (input: {
387
- runId: string;
388
- }) => string;
389
- cancelRun: (input: {
390
- runId: string;
391
- }) => string;
392
- deleteThread?: (input: {
393
- threadId: string;
394
- }) => string;
395
- };
396
- type FetchChatTransportOptions = {
397
- routes: FetchChatTransportRoutes;
398
- fetchImpl?: typeof fetch;
399
- headers?: () => MaybePromise<HeadersInit>;
400
- streamBody?: (input: {
401
- text: string;
402
- threadId?: string | null;
403
- files?: ChatAttachment[];
404
- }) => unknown;
405
- };
406
- declare const createFetchChatTransport: ({ routes, fetchImpl, headers, streamBody, }: FetchChatTransportOptions) => ChatTransport;
407
-
408
- type LatestFollowState = "following" | "detached";
409
- declare const isScrollable: (element: Pick<HTMLDivElement, "scrollHeight" | "clientHeight">) => boolean;
410
- declare const isAtTimelineLatestEdge: (element: Pick<HTMLDivElement, "scrollHeight" | "clientHeight" | "scrollTop">, isTopOrigin: boolean) => boolean;
411
- declare const shouldPrefetchOlder: (element: Pick<HTMLDivElement, "scrollHeight" | "clientHeight" | "scrollTop">) => boolean;
412
- declare const getLatestScrollTop: (element: Pick<HTMLDivElement, "scrollHeight" | "clientHeight">, isTopOrigin: boolean) => number;
413
- declare const shouldUseTopOriginTimeline: ({ hasOlder, itemCount, topOriginMaxItems, }: {
414
- hasOlder: boolean;
415
- itemCount: number;
416
- topOriginMaxItems?: number;
417
- }) => boolean;
418
- declare const nextLatestFollowStateOnScroll: ({ atLatest, current, isProgrammatic, }: {
419
- atLatest: boolean;
420
- current: LatestFollowState;
421
- isProgrammatic: boolean;
422
- }) => LatestFollowState;
423
- type UseLatestThreadViewportOptions = {
424
- itemCount: number;
425
- hasOlder: boolean;
426
- isLoadingOlder: boolean;
427
- onLoadOlder: () => Promise<void> | void;
428
- activeStreamKey?: string | null;
429
- shouldAutoFollow?: boolean;
430
- topOriginMaxItems?: number;
431
- };
432
- type LatestThreadViewportState = {
433
- scrollContainerRef: RefObject<HTMLDivElement | null>;
434
- isAtLatest: boolean;
435
- isFollowingLatest: boolean;
436
- isTopOrigin: boolean;
437
- shouldShowLatestButton: boolean;
438
- handleScroll: (event: UIEvent<HTMLDivElement>) => void;
439
- handleUserScrollIntent: () => void;
440
- scrollToLatest: (options?: {
441
- reattach?: boolean;
442
- }) => void;
443
- detachFromLatest: () => void;
444
- reattachToLatest: () => void;
445
- preserveIntrinsicResize: () => void;
446
- };
447
- declare function useLatestThreadViewport({ itemCount, hasOlder, isLoadingOlder, onLoadOlder, activeStreamKey, shouldAutoFollow, topOriginMaxItems, }: UseLatestThreadViewportOptions): LatestThreadViewportState;
448
- type LatestThreadViewportRenderContext = {
449
- preserveIntrinsicResize: () => void;
450
- isFollowingLatest: boolean;
451
- isTopOrigin: boolean;
452
- };
453
- type LatestThreadViewportProps<T> = {
454
- items: T[];
455
- hasOlder: boolean;
456
- isLoadingOlder: boolean;
457
- onLoadOlder: () => Promise<void> | void;
458
- activeStreamKey?: string | null;
459
- className?: string;
460
- latestSpacer?: ReactNode;
461
- trailingSpacer?: ReactNode;
462
- renderItem: (item: T, context: LatestThreadViewportRenderContext) => ReactNode;
463
- };
464
- declare function LatestThreadViewport<T>({ items, hasOlder, isLoadingOlder, onLoadOlder, activeStreamKey, className, latestSpacer, trailingSpacer, renderItem, }: LatestThreadViewportProps<T>): react.JSX.Element;
465
-
466
- export { type Agents24ChatRenderOptions, type ChatActiveRun, type ChatApprovalPart, type ChatAttachment, type ChatCitation, type ChatContextWindow, type ChatController, type ChatDataPart, type ChatErrorPart, type ChatMessage, type ChatPart, type ChatReasoningPart, type ChatReasoningStep, type ChatRunStatus, type ChatRuntimeEvent, type ChatStorageAdapter, type ChatStreamResult, type ChatTextPart, type ChatThreadDetail, type ChatThreadSummary, type ChatThreadTurn, type ChatToolPart, type ChatToolState, type ChatTransport, type ChatUiBlocksPart, DEFAULT_THREAD_PAGE_SIZE, DefaultChatPart, DefaultToolPart, type FetchChatTransportOptions, type FetchChatTransportRoutes, type LatestFollowState, LatestThreadViewport, type LatestThreadViewportProps, type LatestThreadViewportRenderContext, type LatestThreadViewportState, type StoredChatThread, type StreamingTextCache, type StreamingTextMode, type ToolPresentation, type ToolRenderer, type UseAgents24ChatControllerOptions, type UseLatestThreadViewportOptions, type UseStreamingTextOptions, type UseStreamingTextResult, activeRunIdFromThread, activeRunIdFromThreadDetail, assistantTextFromParts, assistantTextFromResponseBlocks, consumeSseResponse, createChatId, createFetchChatTransport, getActiveStreamingTextPartId, getLatestScrollTop, hasStaleUnfinishedAssistantCache, hasUnfinishedAssistantMessage, isActiveStreamingTextPart, isAtTimelineLatestEdge, isRunningThreadStatus, isScrollable, latestContextWindowFromThread, mergeReasoningSteps, nextLatestFollowStateOnScroll, parseSseBlock, partsFromResponseBlocks, reasoningStepsFromParts, renderChatPart, shouldPrefetchOlder, shouldUseTopOriginTimeline, textFromFinalOutput, threadActivityDate, threadDetailToMessages, threadPaging, titleFromMessage, toolStateFromStatus, useAgents24ChatController, useLatestThreadViewport, useStreamingText };
1
+ export * from "./controller";
2
+ export * from "./context-window";
3
+ export * from "./latest-thread-scroller";
4
+ export * from "./model";
5
+ export * from "./renderers";
6
+ export * from "./sse";
7
+ export * from "./streaming-text";
8
+ export * from "./transport";
9
+ export * from "./types";
10
+ export * from "./viewport";