@xinghunm/ai-chat 0.1.0
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 +263 -0
- package/dist/index.d.mts +545 -0
- package/dist/index.d.ts +545 -0
- package/dist/index.js +4051 -0
- package/dist/index.mjs +4004 -0
- package/package.json +69 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
import * as _emotion_react_jsx_runtime from '@emotion/react/jsx-runtime';
|
|
2
|
+
import { ReactNode, MutableRefObject } from 'react';
|
|
3
|
+
import { AxiosInstance } from 'axios';
|
|
4
|
+
import * as zustand_vanilla from 'zustand/vanilla';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Chat role values accepted by the frontend chat domain.
|
|
8
|
+
*/
|
|
9
|
+
declare const CHAT_ROLES: readonly ["user", "assistant", "system"];
|
|
10
|
+
type ChatRole = (typeof CHAT_ROLES)[number];
|
|
11
|
+
/**
|
|
12
|
+
* Supported message lifecycle states for optimistic UI rendering.
|
|
13
|
+
*/
|
|
14
|
+
declare const CHAT_MESSAGE_STATUSES: readonly ["pending", "streaming", "done", "error", "stopped"];
|
|
15
|
+
type ChatMessageStatus = (typeof CHAT_MESSAGE_STATUSES)[number];
|
|
16
|
+
/**
|
|
17
|
+
* Supported agent interaction modes exposed by the v2 chat API.
|
|
18
|
+
*/
|
|
19
|
+
declare const CHAT_AGENT_MODES: readonly ["ask", "plan", "agent"];
|
|
20
|
+
type ChatAgentMode = (typeof CHAT_AGENT_MODES)[number];
|
|
21
|
+
/**
|
|
22
|
+
* Default agent mode used for new sessions and legacy sessions without mode metadata.
|
|
23
|
+
*/
|
|
24
|
+
declare const DEFAULT_CHAT_AGENT_MODE: ChatAgentMode;
|
|
25
|
+
/**
|
|
26
|
+
* Represents a chat session with its metadata.
|
|
27
|
+
*/
|
|
28
|
+
interface ChatSession {
|
|
29
|
+
sessionId: string;
|
|
30
|
+
title: string;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
updatedAt: string;
|
|
33
|
+
model: string;
|
|
34
|
+
mode?: ChatAgentMode;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Client-side image attachment metadata kept in chat messages.
|
|
38
|
+
*/
|
|
39
|
+
interface ChatImageAttachment {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
mimeType: string;
|
|
43
|
+
size: number;
|
|
44
|
+
previewUrl: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Select option metadata used by plan questionnaires.
|
|
48
|
+
*/
|
|
49
|
+
interface PlanQuestionOption {
|
|
50
|
+
label: string;
|
|
51
|
+
value: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The value type for a single questionnaire answer.
|
|
55
|
+
*/
|
|
56
|
+
type PlanQuestionnaireAnswerValue = string | string[] | number | boolean;
|
|
57
|
+
interface PlanQuestionBase {
|
|
58
|
+
id: string;
|
|
59
|
+
label: string;
|
|
60
|
+
required?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Single-choice question shown in a plan questionnaire.
|
|
64
|
+
*/
|
|
65
|
+
interface PlanSingleSelectQuestion extends PlanQuestionBase {
|
|
66
|
+
kind: 'single_select';
|
|
67
|
+
allowOther?: boolean;
|
|
68
|
+
options: PlanQuestionOption[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Multiple-choice question shown in a plan questionnaire.
|
|
72
|
+
*/
|
|
73
|
+
interface PlanMultiSelectQuestion extends PlanQuestionBase {
|
|
74
|
+
kind: 'multi_select';
|
|
75
|
+
options: PlanQuestionOption[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Free-text question shown in a plan questionnaire.
|
|
79
|
+
*/
|
|
80
|
+
interface PlanTextQuestion extends PlanQuestionBase {
|
|
81
|
+
kind: 'text';
|
|
82
|
+
placeholder?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Numeric question shown in a plan questionnaire.
|
|
86
|
+
*/
|
|
87
|
+
interface PlanNumberQuestion extends PlanQuestionBase {
|
|
88
|
+
kind: 'number';
|
|
89
|
+
placeholder?: string;
|
|
90
|
+
unit?: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Boolean question shown in a plan questionnaire.
|
|
94
|
+
*/
|
|
95
|
+
interface PlanBooleanQuestion extends PlanQuestionBase {
|
|
96
|
+
kind: 'boolean';
|
|
97
|
+
trueLabel?: string;
|
|
98
|
+
falseLabel?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Supported question variants in a plan questionnaire.
|
|
102
|
+
*/
|
|
103
|
+
type PlanQuestion = PlanSingleSelectQuestion | PlanMultiSelectQuestion | PlanTextQuestion | PlanNumberQuestion | PlanBooleanQuestion;
|
|
104
|
+
/**
|
|
105
|
+
* Structured question form emitted for plan-mode clarification flows.
|
|
106
|
+
*/
|
|
107
|
+
interface PlanQuestionnaire {
|
|
108
|
+
questionnaireId: string;
|
|
109
|
+
title?: string;
|
|
110
|
+
description?: string;
|
|
111
|
+
submitLabel?: string;
|
|
112
|
+
questions: PlanQuestion[];
|
|
113
|
+
answers?: Partial<Record<string, PlanQuestionnaireAnswerValue>>;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Submission payload emitted by a questionnaire card.
|
|
117
|
+
*/
|
|
118
|
+
interface PlanQuestionnaireSubmission {
|
|
119
|
+
questionnaireId: string;
|
|
120
|
+
answers: Record<string, PlanQuestionnaireAnswerValue>;
|
|
121
|
+
content: string;
|
|
122
|
+
sourceMessageId?: string;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Submission payload emitted when a user confirms an execution proposal.
|
|
126
|
+
*/
|
|
127
|
+
interface ExecutionConfirmationSubmission {
|
|
128
|
+
proposalId: string;
|
|
129
|
+
content: string;
|
|
130
|
+
sourceMessageId?: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Summary item used by structured assistant cards to describe parameter changes.
|
|
134
|
+
*/
|
|
135
|
+
interface ChatParameterSummaryItem {
|
|
136
|
+
label: string;
|
|
137
|
+
value: string;
|
|
138
|
+
fieldPath?: string;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Executable proposal metadata surfaced by structured assistant confirmation cards.
|
|
142
|
+
*/
|
|
143
|
+
interface ExecutionProposal {
|
|
144
|
+
proposalId: string;
|
|
145
|
+
equationKey: string;
|
|
146
|
+
equationName: string;
|
|
147
|
+
solverName?: string;
|
|
148
|
+
parameterSummary: ChatParameterSummaryItem[];
|
|
149
|
+
warnings?: string[];
|
|
150
|
+
requiresConfirmation: true;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Structured result summary emitted after a PDE task has started or completed.
|
|
154
|
+
*/
|
|
155
|
+
interface ResultSummary {
|
|
156
|
+
taskId: string;
|
|
157
|
+
status: 'completed' | 'failed' | 'running' | 'pending';
|
|
158
|
+
headline: string;
|
|
159
|
+
details: string[];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Structured assistant block variants rendered by the chat thread.
|
|
163
|
+
*/
|
|
164
|
+
type ChatMessageBlock = {
|
|
165
|
+
type: 'markdown';
|
|
166
|
+
text: string;
|
|
167
|
+
} | {
|
|
168
|
+
type: 'notice';
|
|
169
|
+
tone: 'info' | 'warning' | 'success';
|
|
170
|
+
text: string;
|
|
171
|
+
} | {
|
|
172
|
+
type: 'parameter_summary';
|
|
173
|
+
items: ChatParameterSummaryItem[];
|
|
174
|
+
} | {
|
|
175
|
+
type: 'confirmation_card';
|
|
176
|
+
proposal: ExecutionProposal;
|
|
177
|
+
} | {
|
|
178
|
+
type: 'result_summary';
|
|
179
|
+
summary: ResultSummary;
|
|
180
|
+
} | {
|
|
181
|
+
type: 'questionnaire';
|
|
182
|
+
questionnaire: PlanQuestionnaire;
|
|
183
|
+
} | {
|
|
184
|
+
type: 'custom';
|
|
185
|
+
kind: string;
|
|
186
|
+
data: unknown;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Chat message stored in the UI state and rendered by the chat thread.
|
|
190
|
+
*/
|
|
191
|
+
interface ChatMessage {
|
|
192
|
+
id: string;
|
|
193
|
+
sessionId: string;
|
|
194
|
+
role: ChatRole;
|
|
195
|
+
content: string;
|
|
196
|
+
blocks?: ChatMessageBlock[];
|
|
197
|
+
attachments?: ChatImageAttachment[];
|
|
198
|
+
localOnly?: boolean;
|
|
199
|
+
status?: ChatMessageStatus;
|
|
200
|
+
createdAt: string;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Message patch emitted while a streaming response is being assembled.
|
|
204
|
+
*/
|
|
205
|
+
interface ChatStreamMessagePatch {
|
|
206
|
+
content?: string;
|
|
207
|
+
blocks?: ChatMessageBlock[];
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Normalized update extracted from a single backend stream packet.
|
|
211
|
+
*/
|
|
212
|
+
interface ChatStreamPacketUpdate {
|
|
213
|
+
content?: string;
|
|
214
|
+
contentDelta?: string;
|
|
215
|
+
blocks?: ChatMessageBlock[];
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Parameters used by a transport implementation when starting a streaming response.
|
|
219
|
+
*/
|
|
220
|
+
interface ChatTransportStartStreamArgs {
|
|
221
|
+
/** Existing backend session ID. Omit for a brand new conversation. */
|
|
222
|
+
sessionId?: string;
|
|
223
|
+
/** Model identifier currently selected in the UI. */
|
|
224
|
+
model: string;
|
|
225
|
+
/** Agent mode selected in the UI. */
|
|
226
|
+
mode: ChatAgentMode;
|
|
227
|
+
/** User message content that should be sent to the backend. */
|
|
228
|
+
content: string;
|
|
229
|
+
/** Abort signal controlled by the chat composer stop action. */
|
|
230
|
+
signal?: AbortSignal;
|
|
231
|
+
/** Emits normalized streaming patches that should update the assistant message. */
|
|
232
|
+
onUpdate: (update: ChatStreamPacketUpdate) => void;
|
|
233
|
+
/** Emits the definitive backend session ID once the server creates or upgrades one. */
|
|
234
|
+
onSessionId?: (sessionId: string) => void;
|
|
235
|
+
/** Called after the stream completes successfully. */
|
|
236
|
+
onDone?: () => void;
|
|
237
|
+
/** Called when the stream fails and the UI should surface an error. */
|
|
238
|
+
onError?: (error: Error) => void;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Transport interface implemented by host applications to connect chat UI to any backend.
|
|
242
|
+
*/
|
|
243
|
+
interface ChatTransport {
|
|
244
|
+
/** Loads the model list shown by the composer model selector. */
|
|
245
|
+
getModels: () => Promise<ChatModelsResponse>;
|
|
246
|
+
/** Starts a single assistant response stream for the current user message. */
|
|
247
|
+
startStream: (args: ChatTransportStartStreamArgs) => Promise<void>;
|
|
248
|
+
/** Requests termination of the active backend stream for a session. */
|
|
249
|
+
terminateStream: (sessionId?: string) => Promise<ChatTerminateResponse>;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Arguments passed to custom stream packet transformers.
|
|
253
|
+
*/
|
|
254
|
+
interface ChatStreamPacketTransformArgs {
|
|
255
|
+
packet: ChatStreamPacket;
|
|
256
|
+
defaultUpdate: ChatStreamPacketUpdate | null;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Optional packet transformer supplied by integrators to adapt custom backend envelopes.
|
|
260
|
+
*/
|
|
261
|
+
type TransformChatStreamPacket = (args: ChatStreamPacketTransformArgs) => ChatStreamPacketUpdate | null;
|
|
262
|
+
/**
|
|
263
|
+
* Arguments passed to custom block renderers.
|
|
264
|
+
*/
|
|
265
|
+
interface ChatMessageBlockRendererProps {
|
|
266
|
+
block: ChatMessageBlock;
|
|
267
|
+
index: number;
|
|
268
|
+
message: ChatMessage;
|
|
269
|
+
mode: ChatAgentMode;
|
|
270
|
+
onConfirmationSubmit?: (submission: ExecutionConfirmationSubmission) => void;
|
|
271
|
+
onQuestionnaireSubmit?: (submission: PlanQuestionnaireSubmission) => void;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Optional renderer used for custom block variants.
|
|
275
|
+
*/
|
|
276
|
+
type ChatMessageBlockRenderer = (props: ChatMessageBlockRendererProps) => ReactNode;
|
|
277
|
+
interface ChatModel {
|
|
278
|
+
id: string;
|
|
279
|
+
object: string;
|
|
280
|
+
}
|
|
281
|
+
interface ChatModelsResponse {
|
|
282
|
+
data: ChatModel[];
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Response payload returned after a terminate request has been processed.
|
|
286
|
+
*/
|
|
287
|
+
interface ChatTerminateResponse {
|
|
288
|
+
terminated: boolean;
|
|
289
|
+
}
|
|
290
|
+
interface ChatStreamDelta {
|
|
291
|
+
role?: ChatRole;
|
|
292
|
+
content?: string;
|
|
293
|
+
}
|
|
294
|
+
interface ChatStreamPayloadItem {
|
|
295
|
+
index: number;
|
|
296
|
+
delta: ChatStreamDelta;
|
|
297
|
+
finish_reason: string | null;
|
|
298
|
+
}
|
|
299
|
+
interface ChatStreamPacketData {
|
|
300
|
+
id: string;
|
|
301
|
+
object: string;
|
|
302
|
+
created: number;
|
|
303
|
+
model: string;
|
|
304
|
+
payload: ChatStreamPayloadItem[];
|
|
305
|
+
}
|
|
306
|
+
interface ChatStructuredStreamPacketData {
|
|
307
|
+
message?: string;
|
|
308
|
+
content?: string;
|
|
309
|
+
blocks?: ChatMessageBlock[];
|
|
310
|
+
}
|
|
311
|
+
interface ChatStreamPacket {
|
|
312
|
+
type: 'message_start' | 'delta' | 'message_complete' | 'stream_end' | 'error';
|
|
313
|
+
data: ChatStreamPacketData | ChatStructuredStreamPacketData | string | {
|
|
314
|
+
message?: string;
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Customizable UI label strings used throughout the chat components.
|
|
319
|
+
*/
|
|
320
|
+
interface AiChatLabels {
|
|
321
|
+
sendButton?: string;
|
|
322
|
+
stopButton?: string;
|
|
323
|
+
retryButton?: string;
|
|
324
|
+
placeholder?: string;
|
|
325
|
+
modeLabelAsk?: string;
|
|
326
|
+
modeLabelPlan?: string;
|
|
327
|
+
modeLabelAgent?: string;
|
|
328
|
+
newChat?: string;
|
|
329
|
+
emptyStateTitle?: string;
|
|
330
|
+
emptyStateSubtitle?: string;
|
|
331
|
+
attachmentLimitNotice?: string;
|
|
332
|
+
userRoleLabel?: string;
|
|
333
|
+
assistantRoleLabel?: string;
|
|
334
|
+
stoppedResponse?: string;
|
|
335
|
+
assistantStreamingAriaLabel?: string;
|
|
336
|
+
networkError?: string;
|
|
337
|
+
genericError?: string;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Default English label values used when no labels are provided.
|
|
341
|
+
*/
|
|
342
|
+
declare const DEFAULT_AI_CHAT_LABELS: Required<AiChatLabels>;
|
|
343
|
+
|
|
344
|
+
interface AiChatProviderBaseProps {
|
|
345
|
+
/** Initial agent mode for new sessions. */
|
|
346
|
+
defaultMode?: ChatAgentMode;
|
|
347
|
+
/** Optional label overrides for UI strings. */
|
|
348
|
+
labels?: AiChatLabels;
|
|
349
|
+
/** Optional renderer used to extend message blocks with app-specific UI. */
|
|
350
|
+
renderMessageBlock?: ChatMessageBlockRenderer;
|
|
351
|
+
/**
|
|
352
|
+
* Whether to enable image attachment uploads. Defaults to `true`.
|
|
353
|
+
* Set to `false` to hide the upload button, disable paste-image handling,
|
|
354
|
+
* and make programmatic `pickImages`/`pasteImages` calls no-ops.
|
|
355
|
+
*/
|
|
356
|
+
enableImageAttachments?: boolean;
|
|
357
|
+
/** Child elements rendered inside the provider. */
|
|
358
|
+
children: ReactNode;
|
|
359
|
+
}
|
|
360
|
+
interface AiChatProviderDefaultAdapterProps {
|
|
361
|
+
/** Base URL used by the built-in HTTP transport adapter. */
|
|
362
|
+
apiBaseUrl: string;
|
|
363
|
+
/** Authorization header value (e.g. "Bearer <token>") used by the built-in adapter. */
|
|
364
|
+
authToken: string;
|
|
365
|
+
/** Optional transformer used to adapt custom backend stream packets. */
|
|
366
|
+
transformStreamPacket?: TransformChatStreamPacket;
|
|
367
|
+
transport?: never;
|
|
368
|
+
}
|
|
369
|
+
interface AiChatProviderCustomTransportProps {
|
|
370
|
+
/** Fully custom transport implementation used by the generic chat shell. */
|
|
371
|
+
transport: ChatTransport;
|
|
372
|
+
apiBaseUrl?: never;
|
|
373
|
+
authToken?: never;
|
|
374
|
+
transformStreamPacket?: never;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Props accepted by `AiChatProvider`.
|
|
378
|
+
*
|
|
379
|
+
* Recommended:
|
|
380
|
+
* Inject a `transport` adapter so the chat UI can talk to any backend contract.
|
|
381
|
+
*
|
|
382
|
+
* Backward compatibility:
|
|
383
|
+
* `apiBaseUrl` + `authToken` still create the built-in HTTP adapter.
|
|
384
|
+
*/
|
|
385
|
+
type AiChatProviderProps = AiChatProviderBaseProps & (AiChatProviderDefaultAdapterProps | AiChatProviderCustomTransportProps);
|
|
386
|
+
declare const AiChatProvider: (props: AiChatProviderProps) => _emotion_react_jsx_runtime.JSX.Element;
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Props for the all-in-one `AiChat` component.
|
|
390
|
+
*/
|
|
391
|
+
type AiChatProps = Omit<AiChatProviderProps, 'children'> & {
|
|
392
|
+
/** When true, renders the conversation list sidebar. Defaults to false. */
|
|
393
|
+
showConversationList?: boolean;
|
|
394
|
+
};
|
|
395
|
+
/**
|
|
396
|
+
* Top-level AI chat component. Wraps AiChatProvider and composes the full
|
|
397
|
+
* chat UI: optional conversation sidebar + thread + composer.
|
|
398
|
+
*/
|
|
399
|
+
declare const AiChat: ({ showConversationList, ...providerProps }: AiChatProps) => _emotion_react_jsx_runtime.JSX.Element;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Endpoint overrides for the built-in HTTP transport adapter.
|
|
403
|
+
*/
|
|
404
|
+
interface DefaultChatTransportEndpoints {
|
|
405
|
+
/** Relative path used to fetch the available model list. */
|
|
406
|
+
models?: string;
|
|
407
|
+
/** Relative path used to start a streaming chat completion. */
|
|
408
|
+
completions?: string;
|
|
409
|
+
/** Relative path used to request stream termination. */
|
|
410
|
+
terminate?: string;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Options for the built-in HTTP transport adapter.
|
|
414
|
+
*/
|
|
415
|
+
interface CreateDefaultChatTransportOptions {
|
|
416
|
+
/** Base URL of the backend that serves the built-in chat endpoints. */
|
|
417
|
+
apiBaseUrl: string;
|
|
418
|
+
/** Authorization header value forwarded to the backend. */
|
|
419
|
+
authToken: string;
|
|
420
|
+
/** Optional extra headers appended to each streaming chat completion request. */
|
|
421
|
+
streamHeaders?: Record<string, string>;
|
|
422
|
+
/** Optional transformer used to normalize custom stream packets. */
|
|
423
|
+
transformStreamPacket?: TransformChatStreamPacket;
|
|
424
|
+
/** Optional endpoint overrides for backends that use different paths. */
|
|
425
|
+
endpoints?: DefaultChatTransportEndpoints;
|
|
426
|
+
/** Optional preconfigured axios instance reused for non-streaming requests. */
|
|
427
|
+
axiosInstance?: AxiosInstance;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Creates the built-in transport backed by the current HTTP chat API.
|
|
431
|
+
*/
|
|
432
|
+
declare const createDefaultChatTransport: ({ apiBaseUrl, authToken, streamHeaders, transformStreamPacket, endpoints, axiosInstance, }: CreateDefaultChatTransportOptions) => ChatTransport;
|
|
433
|
+
|
|
434
|
+
declare const ChatThread: () => _emotion_react_jsx_runtime.JSX.Element;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Props for the presentational `ChatComposerView` component.
|
|
438
|
+
*/
|
|
439
|
+
interface ChatComposerViewProps {
|
|
440
|
+
value: string;
|
|
441
|
+
placeholder: string;
|
|
442
|
+
attachments: ChatImageAttachment[];
|
|
443
|
+
attachmentNotice?: 'limit_reached' | null;
|
|
444
|
+
attachmentLimitNotice: string;
|
|
445
|
+
selectedModel: string;
|
|
446
|
+
selectedMode: ChatAgentMode;
|
|
447
|
+
availableModels: ChatModel[];
|
|
448
|
+
isModelsLoading: boolean;
|
|
449
|
+
isModelsError: boolean;
|
|
450
|
+
hasModels: boolean;
|
|
451
|
+
/** Whether a streaming response is currently in progress. */
|
|
452
|
+
isStreaming: boolean;
|
|
453
|
+
/** Whether a stop request has been sent but not yet finalized. */
|
|
454
|
+
isStopping: boolean;
|
|
455
|
+
/** Whether image attachment uploads are enabled. */
|
|
456
|
+
enableImageAttachments: boolean;
|
|
457
|
+
modeLabels: {
|
|
458
|
+
ask: string;
|
|
459
|
+
plan: string;
|
|
460
|
+
agent: string;
|
|
461
|
+
};
|
|
462
|
+
onValueChange: (value: string) => void;
|
|
463
|
+
onPickImages: (files: FileList | File[]) => void;
|
|
464
|
+
onPasteImages: (files: File[]) => void;
|
|
465
|
+
onRemoveAttachment: (attachmentId: string) => void;
|
|
466
|
+
onSelectedModelChange: (value: string) => void;
|
|
467
|
+
onSelectedModeChange: (value: ChatAgentMode) => void;
|
|
468
|
+
onReloadModels: () => void;
|
|
469
|
+
/** Called to abort the active streaming response. */
|
|
470
|
+
onStop: () => void | Promise<void>;
|
|
471
|
+
/** Called to send a new user message. */
|
|
472
|
+
onSend: () => void | Promise<void>;
|
|
473
|
+
}
|
|
474
|
+
declare const ChatComposer: () => _emotion_react_jsx_runtime.JSX.Element;
|
|
475
|
+
|
|
476
|
+
declare const ChatConversationList: () => _emotion_react_jsx_runtime.JSX.Element;
|
|
477
|
+
|
|
478
|
+
interface ChatState {
|
|
479
|
+
activeSessionId: string | null;
|
|
480
|
+
preferredMode: ChatAgentMode;
|
|
481
|
+
sessions: ChatSession[];
|
|
482
|
+
messagesBySession: Record<string, ChatMessage[]>;
|
|
483
|
+
streamingMessageBySession: Record<string, ChatMessage | undefined>;
|
|
484
|
+
isStreamingBySession: Record<string, boolean>;
|
|
485
|
+
isStoppingBySession: Record<string, boolean>;
|
|
486
|
+
errorBySession: Record<string, string | null>;
|
|
487
|
+
}
|
|
488
|
+
interface ChatActions {
|
|
489
|
+
createSession: (session: ChatSession) => void;
|
|
490
|
+
setActiveSession: (sessionId: string | null) => void;
|
|
491
|
+
replaceSessionId: (previousSessionId: string, nextSessionId: string) => void;
|
|
492
|
+
setPreferredMode: (mode: ChatAgentMode) => void;
|
|
493
|
+
setSessionMode: (sessionId: string, mode: ChatAgentMode) => void;
|
|
494
|
+
appendMessage: (sessionId: string, message: ChatMessage) => void;
|
|
495
|
+
startStreamingMessage: (sessionId: string, message: ChatMessage) => void;
|
|
496
|
+
updateStreamingMessage: (sessionId: string, content: string) => void;
|
|
497
|
+
patchStreamingMessage: (sessionId: string, patch: ChatStreamMessagePatch) => void;
|
|
498
|
+
completeStreamingMessage: (sessionId: string) => void;
|
|
499
|
+
requestStopStreaming: (sessionId: string) => void;
|
|
500
|
+
finalizeStoppedStreamingMessage: (sessionId: string) => void;
|
|
501
|
+
setSessionError: (sessionId: string, error: string | null) => void;
|
|
502
|
+
clearSessionError: (sessionId: string) => void;
|
|
503
|
+
updateQuestionnaireAnswers: (sessionId: string, messageId: string, questionnaireId: string, answers: Record<string, PlanQuestionnaireAnswerValue>) => void;
|
|
504
|
+
}
|
|
505
|
+
type ChatStore = ChatState & ChatActions;
|
|
506
|
+
type ChatStoreInstance = ReturnType<typeof createChatStore>;
|
|
507
|
+
declare const createChatStore: (initialState?: Partial<Pick<ChatState, "preferredMode">>) => zustand_vanilla.StoreApi<ChatStore>;
|
|
508
|
+
|
|
509
|
+
interface ChatContextValue {
|
|
510
|
+
store: ChatStoreInstance;
|
|
511
|
+
transport: ChatTransport;
|
|
512
|
+
/** Legacy default-adapter axios client. Undefined when a custom transport is injected. */
|
|
513
|
+
axios?: AxiosInstance;
|
|
514
|
+
/** Legacy default-adapter base URL. Undefined when a custom transport is injected. */
|
|
515
|
+
apiBaseUrl?: string;
|
|
516
|
+
/** Legacy default-adapter authorization header value. Undefined when a custom transport is injected. */
|
|
517
|
+
authToken?: string;
|
|
518
|
+
labels: Required<AiChatLabels>;
|
|
519
|
+
/** Stable ref populated by ChatComposer on mount; allows ChatThread to trigger sends. */
|
|
520
|
+
sendRef: MutableRefObject<(content: string) => Promise<void>>;
|
|
521
|
+
/** Stable ref populated by ChatComposer on mount; allows ChatThread to replay the last request. */
|
|
522
|
+
retryRef: MutableRefObject<() => Promise<void>>;
|
|
523
|
+
/** Optional block renderer used to extend message rendering with custom block types. */
|
|
524
|
+
renderMessageBlock?: ChatMessageBlockRenderer;
|
|
525
|
+
/** Optional packet transformer used by the legacy default adapter. */
|
|
526
|
+
transformStreamPacket?: TransformChatStreamPacket;
|
|
527
|
+
/** Whether image attachments are enabled. Defaults to true. */
|
|
528
|
+
enableImageAttachments: boolean;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Returns the active AI chat context from `AiChatProvider`.
|
|
533
|
+
*
|
|
534
|
+
* @throws {Error} When called outside of `AiChatProvider`.
|
|
535
|
+
*/
|
|
536
|
+
declare const useChatContext: () => ChatContextValue;
|
|
537
|
+
/**
|
|
538
|
+
* Selects a slice from the internal chat Zustand store.
|
|
539
|
+
*
|
|
540
|
+
* @param selector Receives the full chat store and returns the desired slice.
|
|
541
|
+
* @throws {Error} When called outside of `AiChatProvider`.
|
|
542
|
+
*/
|
|
543
|
+
declare const useChatStore: <T>(selector: (state: ChatStore) => T) => T;
|
|
544
|
+
|
|
545
|
+
export { AiChat, type AiChatLabels, type AiChatProps, AiChatProvider, type AiChatProviderProps, CHAT_AGENT_MODES, type ChatAgentMode, ChatComposer, type ChatComposerViewProps, ChatConversationList, type ChatImageAttachment, type ChatMessage, type ChatMessageBlock, type ChatMessageBlockRenderer, type ChatMessageBlockRendererProps, type ChatMessageStatus, type ChatModel, type ChatRole, type ChatSession, type ChatStreamMessagePatch, type ChatStreamPacketTransformArgs, type ChatStreamPacketUpdate, ChatThread, type ChatTransport, type ChatTransportStartStreamArgs, type CreateDefaultChatTransportOptions, DEFAULT_AI_CHAT_LABELS, DEFAULT_CHAT_AGENT_MODE, type DefaultChatTransportEndpoints, type ExecutionConfirmationSubmission, type ExecutionProposal, type PlanQuestionnaire, type PlanQuestionnaireSubmission, type ResultSummary, type TransformChatStreamPacket, createDefaultChatTransport, useChatContext, useChatStore };
|