@rayvision/ai-chat 0.0.1 → 0.0.2

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 (40) hide show
  1. package/README.md +2 -2
  2. package/dist/index.d.ts +7 -427
  3. package/dist/index.js +45 -16461
  4. package/dist/index.mjs +9462 -12203
  5. package/dist/src/ai-chat.d.ts +4 -0
  6. package/dist/src/components/attachment-image-modal.d.ts +9 -0
  7. package/dist/src/components/chat-composer.d.ts +17 -0
  8. package/dist/src/components/chat-header.d.ts +10 -0
  9. package/dist/src/components/chat-launcher.d.ts +9 -0
  10. package/dist/src/components/chat-messages.d.ts +14 -0
  11. package/dist/src/components/chat-toast.d.ts +9 -0
  12. package/dist/src/components/message-bubble.d.ts +10 -0
  13. package/dist/src/components/modal.d.ts +11 -0
  14. package/dist/src/components/panel.d.ts +3 -0
  15. package/dist/src/components/popover.d.ts +11 -0
  16. package/dist/src/components/portal.d.ts +10 -0
  17. package/dist/src/components/tooltip.d.ts +11 -0
  18. package/dist/src/context/ai-chat-ui-context.d.ts +20 -0
  19. package/dist/src/controller/ai-chat-controller.d.ts +2 -0
  20. package/dist/src/hooks/use-ai-chat-layout.d.ts +10 -0
  21. package/dist/src/i18n/attachment-error-messages.d.ts +2 -0
  22. package/dist/src/i18n/index.d.ts +5 -0
  23. package/dist/src/i18n/messages.en.d.ts +62 -0
  24. package/dist/src/i18n/messages.zh.d.ts +62 -0
  25. package/dist/src/i18n/phase-labels.d.ts +10 -0
  26. package/dist/src/i18n/types.d.ts +1 -0
  27. package/dist/src/markdown/render.d.ts +3 -0
  28. package/dist/src/services/customer-v1/attachments/client.d.ts +9 -0
  29. package/dist/src/services/customer-v1/client.d.ts +9 -0
  30. package/dist/src/services/customer-v1/error.d.ts +3 -0
  31. package/dist/src/services/customer-v1/protocol.d.ts +112 -0
  32. package/dist/src/services/customer-v1/sse-parser.d.ts +2 -0
  33. package/dist/src/store/ai-chat-store.d.ts +41 -0
  34. package/dist/src/theme/global-style.d.ts +24 -0
  35. package/dist/src/theme/panel-style.d.ts +6 -0
  36. package/dist/src/types.d.ts +301 -0
  37. package/dist/src/utils/build-chat-content.d.ts +5 -0
  38. package/dist/src/utils/copy-text.d.ts +1 -0
  39. package/dist/src/utils/format-chat-file-error.d.ts +3 -0
  40. package/package.json +3 -3
package/README.md CHANGED
@@ -8,7 +8,7 @@ Renderbus AI Chat React 组件,提供流式问答、Markdown、引用、建议
8
8
  npm install @rayvision/ai-chat
9
9
  ```
10
10
 
11
- 需要 React 16 或更高版本。
11
+ 需要 React 和 React DOM 18 或更高版本。
12
12
 
13
13
  ## 快速开始
14
14
 
@@ -158,7 +158,7 @@ const controller = createAIChatController({ adapter })
158
158
 
159
159
  主要导出包括:
160
160
 
161
- - 组件:`AIChat`、`AIChatPanel`、`AIChatLauncher`、`AIChatModal`、`AIChatTooltip`
161
+ - 组件:`AIChat`
162
162
  - 工具:`mountAIChat`、`createAIChatController`、`createCustomerV1ChatAdapter`
163
163
  - 类型:`AIChatProps`、`AIChatController`、`ChatAdapter`、`ChatMessage`、`Citation`、`Attachment`
164
164
 
package/dist/index.d.ts CHANGED
@@ -1,427 +1,7 @@
1
- import { UseBoundStore, StoreApi } from 'zustand';
2
- import { CSSProperties, PointerEvent, ReactNode } from 'react';
3
-
4
- interface AIChatStoreState {
5
- open: boolean;
6
- restoring: boolean;
7
- messages: ChatMessage[];
8
- busy: boolean;
9
- draft: string;
10
- attachments: PendingAttachment[];
11
- attachmentError: ChatFileError | GatewayError | null;
12
- toast: ChatToast | null;
13
- attachmentPolicy: AttachmentPolicy;
14
- attachmentOptions: AttachmentOptions | null;
15
- suggestedQuestions: SuggestedQuestion[];
16
- conversationId: string | null;
17
- activeRunId: string | null;
18
- phase: string | null;
19
- toggle(show?: boolean): void;
20
- setMessages(messages: ChatMessage[]): void;
21
- updateMessages(update: (current: ChatMessage[]) => ChatMessage[]): void;
22
- setBusy(busy: boolean): void;
23
- setRestoring(restoring: boolean): void;
24
- setDraft(draft: string): void;
25
- clearMessages(): void;
26
- clearDraft(): void;
27
- resetComposer(): void;
28
- setAttachmentOptions(options: AttachmentOptions): void;
29
- setSuggestedQuestions(items: SuggestedQuestion[]): void;
30
- setConversation(conversationId: string | null, runId?: string | null): void;
31
- setPhase(phase: string | null): void;
32
- setAttachmentState(id: string, update: Partial<PendingAttachment>): void;
33
- setAttachmentError(error: ChatFileError | GatewayError | null): void;
34
- showToast(toast: ChatToast): void;
35
- clearToast(): void;
36
- addAttachment(attachment: PendingAttachment): void;
37
- removeAttachmentLocal(id: string): void;
38
- clearAttachments(): void;
39
- }
40
- type AIChatStore = UseBoundStore<StoreApi<AIChatStoreState>>;
41
-
42
- type AIChatLanguage$1 = 'zh' | 'en';
43
-
44
- type AIChatLanguage = AIChatLanguage$1;
45
- type AIChatTheme = 'light' | 'dark';
46
- type ChatRole = 'user' | 'assistant';
47
- type ChatMessageStatus = 'complete' | 'streaming' | 'error' | 'cancelled' | 'no_evidence' | 'awaiting-recovery';
48
- interface Citation {
49
- citation_id: string;
50
- title: string;
51
- snippet: string;
52
- document_id: string;
53
- version?: string;
54
- content?: string;
55
- content_version?: string;
56
- category_path?: string;
57
- slug?: string;
58
- url?: string;
59
- published_at?: string;
60
- updated_at?: string;
61
- }
62
- interface SuggestedQuestion {
63
- id: string;
64
- display_text: string;
65
- module: string;
66
- version: number;
67
- }
68
- interface AttachmentOptionsLimits {
69
- image_max_bytes: number;
70
- turn_image_max_bytes: number;
71
- text_max_bytes: number;
72
- max_attachments: number;
73
- input_max_characters: number;
74
- conversation_image_max_bytes: number;
75
- native_history_max_bytes: number;
76
- draft_max_count: number;
77
- draft_max_bytes: number;
78
- }
79
- interface AttachmentOptions {
80
- request_id: string;
81
- available: boolean;
82
- image_supported: boolean;
83
- image_extensions: string[];
84
- text_extensions: string[];
85
- limits: AttachmentOptionsLimits;
86
- }
87
- interface Attachment {
88
- attachment_id: string;
89
- kind: 'image' | 'text';
90
- filename: string;
91
- media_type: string;
92
- size_bytes: number;
93
- width?: number;
94
- height?: number;
95
- encoding?: string;
96
- content_url: string;
97
- created_at: string;
98
- }
99
- interface PendingAttachment {
100
- id: string;
101
- file: File;
102
- clientUploadId: string;
103
- status: 'pending' | 'uploading' | 'uploaded' | 'error';
104
- attachment?: Attachment;
105
- image?: ChatImage;
106
- textFile?: ChatTextFile;
107
- error?: GatewayError;
108
- }
109
- interface AttachmentPolicy {
110
- accept: string[];
111
- maxCount: number;
112
- maxFileBytes: number;
113
- available?: boolean;
114
- imageSupported?: boolean;
115
- options?: AttachmentOptions;
116
- }
117
- interface GatewayError {
118
- request_id?: string;
119
- status: string;
120
- error_code: string;
121
- message?: string;
122
- retry_after?: number;
123
- httpStatus?: number;
124
- }
125
- type ChatFeedbackRating = 'like' | 'dislike';
126
- interface ChatFeedback {
127
- rating: ChatFeedbackRating | null;
128
- comment: string;
129
- updated_at: string;
130
- }
131
- interface ChatImage {
132
- id: string;
133
- mimeType: string;
134
- dataUrl: string;
135
- width: number;
136
- height: number;
137
- bytes: number;
138
- name?: string;
139
- }
140
- interface ChatTextFile {
141
- id: string;
142
- mimeType: 'text/plain';
143
- text: string;
144
- bytes: number;
145
- name: string;
146
- }
147
- type TextContentPart = {
148
- type: 'text';
149
- text: string;
150
- };
151
- type ImageContentPart = {
152
- type: 'image';
153
- image: ChatImage;
154
- };
155
- type TextFileContentPart = {
156
- type: 'text-file';
157
- file: ChatTextFile;
158
- };
159
- type ChatContentPart = TextContentPart | ImageContentPart | TextFileContentPart;
160
- interface ChatSendInput {
161
- content: ChatContentPart[];
162
- query?: string;
163
- attachmentIds?: string[];
164
- clientMessageId?: string;
165
- runId?: string;
166
- conversationId?: string;
167
- module?: string;
168
- suggestedQuestionId?: string;
169
- suggestedQuestionVersion?: number;
170
- }
171
- interface ChatFileError {
172
- type: 'fileLimitExceeded' | 'fileTooLarge' | 'unsupportedFile';
173
- value: number | string;
174
- }
175
- interface ChatToast {
176
- kind: 'success' | 'error' | 'loading';
177
- message: string;
178
- errorCode?: string;
179
- }
180
- interface ChatMessage {
181
- id: string;
182
- role: ChatRole;
183
- text: string;
184
- status: ChatMessageStatus;
185
- images?: ChatImage[];
186
- textFiles?: ChatTextFile[];
187
- attachments?: Attachment[];
188
- citations?: Citation[];
189
- runId?: string;
190
- conversationId?: string;
191
- sequence?: number;
192
- progress?: string;
193
- error?: GatewayError;
194
- confirmed?: boolean;
195
- requestInput?: ChatSendInput;
196
- retryable?: boolean;
197
- feedback?: ChatFeedback | null;
198
- }
199
- interface ChatHandlers {
200
- onMessageStart?(messageId: string, conversationId?: string): void;
201
- onDelta(messageId: string, delta: string, sequence?: number): void;
202
- onSnapshot?(messageId: string, answer: string, citations: Citation[], sequence: number): void;
203
- onCitation?(messageId: string, citation: Citation, sequence: number): void;
204
- onProgress?(messageId: string, phase: string, sequence: number): void;
205
- onComplete(messageId: string, result?: ChatTerminalResult): void;
206
- onError(messageId: string, error: GatewayError): void;
207
- }
208
- interface ChatTerminalResult {
209
- status: string;
210
- answer?: string;
211
- citations?: Citation[];
212
- error_code?: string;
213
- request_id?: string;
214
- retry_after?: number;
215
- confirmed: boolean;
216
- }
217
- interface ChatAdapter {
218
- send(input: ChatSendInput, handlers: ChatHandlers): {
219
- cancel(): void;
220
- };
221
- initializeConversation?(): Promise<void>;
222
- getSuggestedQuestions?(module?: string, limit?: number): Promise<SuggestedQuestion[]>;
223
- getAttachmentOptions?(): Promise<AttachmentOptions>;
224
- uploadAttachment?(file: File, clientUploadId: string): Promise<Attachment>;
225
- getAttachmentContent?(attachmentId: string, download?: boolean): Promise<Blob>;
226
- deleteAttachment?(attachmentId: string): Promise<void>;
227
- getConversation?(conversationId: string, limit?: number): Promise<ConversationItem[]>;
228
- shareConversation?(conversationId: string): Promise<string>;
229
- getCitation?(runId: string, citationId: string): Promise<Citation>;
230
- submitFeedback?(runId: string, feedback: {
231
- rating: ChatFeedbackRating | null;
232
- comment: string;
233
- }): Promise<ChatFeedback | null>;
234
- }
235
- interface ConversationItem {
236
- run_id: string;
237
- message_id: string;
238
- conversation_id: string;
239
- status: string;
240
- question?: string;
241
- answer?: string;
242
- attachments?: Attachment[];
243
- generated_query?: boolean;
244
- knowledge_scope: string;
245
- citations?: Citation[];
246
- feedback?: ChatFeedback | null;
247
- }
248
- interface AIChatController {
249
- store: AIChatStore;
250
- initialize(): Promise<void>;
251
- setAdapter(adapter: ChatAdapter): void;
252
- setLanguage(language: AIChatLanguage): void;
253
- toggle(show?: boolean): void;
254
- submit(content: ChatContentPart[]): void;
255
- submitSuggested(question: SuggestedQuestion): void;
256
- setDraft(draft: string): void;
257
- send(): void;
258
- addFiles(files: File[]): Promise<void>;
259
- removeAttachment(id: string): void;
260
- clearAttachments(): void;
261
- cancel(): void;
262
- recover(): void;
263
- restoreConversation(conversationId: string, limit?: number): Promise<void>;
264
- share(): Promise<string | undefined>;
265
- loadCitation(messageId: string, citationId: string): Promise<Citation | undefined>;
266
- submitFeedback(messageId: string, rating: ChatFeedbackRating | null, comment?: string): Promise<ChatFeedback | null>;
267
- clear(): void;
268
- destroy(): void;
269
- }
270
- interface AIChatControllerOptions {
271
- defaultOpen?: boolean;
272
- adapter?: ChatAdapter;
273
- baseUrl?: string;
274
- persistSession?: boolean | {
275
- storageKey?: string;
276
- };
277
- }
278
- interface AIChatLauncherProps {
279
- controller: AIChatController;
280
- disabled?: boolean;
281
- className?: string;
282
- }
283
- interface AIChatProps {
284
- controller: AIChatController;
285
- language?: AIChatLanguage;
286
- adapter?: ChatAdapter;
287
- launcher?: boolean | AIChatLauncherProps;
288
- container?: HTMLElement | null;
289
- theme?: AIChatTheme;
290
- }
291
- interface AIChatMountOptions {
292
- controller?: AIChatController;
293
- adapter?: ChatAdapter;
294
- baseUrl?: string;
295
- language?: AIChatLanguage;
296
- theme?: AIChatTheme;
297
- launcher?: boolean | {
298
- disabled?: boolean;
299
- className?: string;
300
- };
301
- defaultOpen?: boolean;
302
- persistSession?: AIChatControllerOptions['persistSession'];
303
- }
304
- interface AIChatMountResult extends ShadowMountResult {
305
- controller: AIChatController;
306
- }
307
- type AIChatPanelProps = Omit<AIChatProps, 'launcher' | 'mount' | 'container'>;
308
- interface AIChatInternalPanelProps extends AIChatPanelProps {
309
- panelStyle?: CSSProperties;
310
- onResizeStart?(edge: 'left' | 'top' | 'right' | 'bottom', event: PointerEvent): void;
311
- }
312
- interface ShadowMountResult {
313
- host: HTMLElement;
314
- root: ShadowRoot | HTMLElement;
315
- container: HTMLElement;
316
- destroy(): void;
317
- }
318
-
319
- declare function mountAIChat(target: HTMLElement, options?: AIChatMountOptions): AIChatMountResult;
320
- declare function AIChat(props: AIChatProps): JSX.Element | null;
321
-
322
- declare function AIChatPanel({ controller, adapter, language, panelStyle, onResizeStart, }: AIChatInternalPanelProps): JSX.Element | null;
323
-
324
- declare function AIChatLauncher({ controller, disabled, className, onPositionChange, style, }: {
325
- controller: AIChatPanelProps['controller'];
326
- disabled?: boolean;
327
- className?: string;
328
- onPositionChange?: (left: number, top: number) => void;
329
- style?: CSSProperties;
330
- }): JSX.Element;
331
-
332
- type AIChatPortalContainer = Element | DocumentFragment;
333
-
334
- interface AIChatModalProps {
335
- open: boolean;
336
- children: ReactNode;
337
- anchor?: Node | null;
338
- container?: AIChatPortalContainer | null;
339
- className?: string;
340
- onClose?(): void;
341
- }
342
- declare function AIChatModal({ open, children, anchor, container, className, onClose, }: AIChatModalProps): JSX.Element | null;
343
-
344
- interface AIChatTooltipProps {
345
- open: boolean;
346
- children: ReactNode;
347
- anchor?: Node | null;
348
- container?: AIChatPortalContainer | null;
349
- className?: string;
350
- style?: CSSProperties;
351
- }
352
- declare function AIChatTooltip({ open, children, anchor, container, className, style, }: AIChatTooltipProps): JSX.Element | null;
353
-
354
- declare function createAIChatController(options?: AIChatControllerOptions): AIChatController;
355
-
356
- interface CustomerV1ChatAdapterOptions {
357
- baseUrl?: string;
358
- shareOrigin?: string;
359
- module?: string;
360
- knowledgeScope?: 'public';
361
- }
362
- declare function createCustomerV1ChatAdapter(options?: CustomerV1ChatAdapterOptions): ChatAdapter;
363
-
364
- declare const ZH_MESSAGES: {
365
- title: string;
366
- openAssistant: string;
367
- welcome: string;
368
- welcomeDescription: string;
369
- placeholder: string;
370
- send: string;
371
- stop: string;
372
- newChat: string;
373
- collapse: string;
374
- citations: (count: number) => string;
375
- expandCitations: string;
376
- collapseCitations: string;
377
- share: string;
378
- sharing: string;
379
- shareCopied: string;
380
- shareFailed: string;
381
- attach: string;
382
- removeAttachment: string;
383
- emptyInput: string;
384
- dropFiles: string;
385
- copied: string;
386
- copy: string;
387
- humanSupport: string;
388
- like: string;
389
- dislike: string;
390
- feedbackTitle: string;
391
- feedbackSubmit: string;
392
- feedbackThanks: string;
393
- feedbackFailed: string;
394
- closeFeedback: string;
395
- feedbackOtherPlaceholder: string;
396
- feedbackUnprofessional: string;
397
- feedbackUnresolved: string;
398
- feedbackMisunderstood: string;
399
- feedbackSlow: string;
400
- feedbackOther: string;
401
- attachment: string;
402
- fileLimitExceeded: (maxCount: number | string) => string;
403
- fileTooLarge: (fileName: number | string) => string;
404
- unsupportedFile: (fileName: number | string) => string;
405
- attachmentError: (errorCode: string) => string;
406
- processing: string;
407
- syncing: string;
408
- loading: string;
409
- retry: string;
410
- requestFailed: string;
411
- darkMode: string;
412
- lightMode: string;
413
- previewImage: string;
414
- closeImagePreview: string;
415
- closeCitation: string;
416
- assistantName: string;
417
- citationCategoryPath: string;
418
- citationPublishedAt: string;
419
- citationUpdatedAt: string;
420
- citationContentVersion: string;
421
- attachmentUploaded: string;
422
- disclaimer: string;
423
- };
424
-
425
- type AIChatMessages = typeof ZH_MESSAGES;
426
-
427
- export { AIChat, AIChatController, AIChatControllerOptions, AIChatLanguage, AIChatLauncher, AIChatLauncherProps, AIChatMessages, AIChatModal, AIChatModalProps, AIChatMountOptions, AIChatMountResult, AIChatPanel, AIChatPanelProps, AIChatProps, AIChatTheme, AIChatTooltip, AIChatTooltipProps, Attachment, AttachmentOptions, ChatAdapter, ChatContentPart, ChatImage, ChatMessage, ChatSendInput, ChatTextFile, Citation, ConversationItem, CustomerV1ChatAdapterOptions, GatewayError, ImageContentPart, PendingAttachment, SuggestedQuestion, TextContentPart, TextFileContentPart, createAIChatController, createCustomerV1ChatAdapter, mountAIChat };
1
+ export { AIChat, mountAIChat } from './src/ai-chat';
2
+ export type { AIChatModalProps } from './src/components/modal';
3
+ export { createAIChatController } from './src/controller/ai-chat-controller';
4
+ export { createCustomerV1ChatAdapter } from './src/services/customer-v1/client';
5
+ export type { CustomerV1ChatAdapterOptions } from './src/services/customer-v1/client';
6
+ export type { AIChatMessages } from './src/i18n';
7
+ export { type AIChatController, type AIChatControllerOptions, type Attachment, type AttachmentOptions, type Citation, type ConversationItem, type GatewayError, type PendingAttachment, type SuggestedQuestion, type AIChatLanguage, type AIChatTheme, type AIChatLauncherProps, type AIChatProps, type AIChatMountOptions, type AIChatMountResult, type ChatAdapter, type ChatContentPart, type AttachmentErrorCode, type AttachmentUploadStatus, type ChatMessage, type ChatSendInput, type GatewayErrorCode, type TextContentPart, } from './src/types';