@rayvision/ai-chat 0.0.1 → 0.0.2-beta
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 +2 -2
- package/dist/index.d.ts +7 -427
- package/dist/index.js +45 -16461
- package/dist/index.mjs +9305 -12143
- package/dist/src/ai-chat.d.ts +4 -0
- package/dist/src/components/attachment-image-modal.d.ts +9 -0
- package/dist/src/components/chat-composer.d.ts +16 -0
- package/dist/src/components/chat-header.d.ts +10 -0
- package/dist/src/components/chat-launcher.d.ts +9 -0
- package/dist/src/components/chat-messages.d.ts +14 -0
- package/dist/src/components/chat-toast.d.ts +9 -0
- package/dist/src/components/message-bubble.d.ts +10 -0
- package/dist/src/components/modal.d.ts +11 -0
- package/dist/src/components/panel.d.ts +3 -0
- package/dist/src/components/popover.d.ts +11 -0
- package/dist/src/components/portal.d.ts +10 -0
- package/dist/src/components/tooltip.d.ts +11 -0
- package/dist/src/context/ai-chat-ui-context.d.ts +20 -0
- package/dist/src/controller/ai-chat-controller.d.ts +2 -0
- package/dist/src/hooks/use-ai-chat-layout.d.ts +10 -0
- package/dist/src/i18n/attachment-error-messages.d.ts +2 -0
- package/dist/src/i18n/index.d.ts +5 -0
- package/dist/src/i18n/messages.en.d.ts +61 -0
- package/dist/src/i18n/messages.zh.d.ts +61 -0
- package/dist/src/i18n/phase-labels.d.ts +2 -0
- package/dist/src/i18n/types.d.ts +1 -0
- package/dist/src/markdown/render.d.ts +3 -0
- package/dist/src/services/customer-v1/attachments/client.d.ts +9 -0
- package/dist/src/services/customer-v1/client.d.ts +9 -0
- package/dist/src/services/customer-v1/error.d.ts +3 -0
- package/dist/src/services/customer-v1/protocol.d.ts +93 -0
- package/dist/src/services/customer-v1/sse-parser.d.ts +2 -0
- package/dist/src/store/ai-chat-store.d.ts +41 -0
- package/dist/src/theme/global-style.d.ts +24 -0
- package/dist/src/theme/panel-style.d.ts +6 -0
- package/dist/src/types.d.ts +294 -0
- package/dist/src/utils/build-chat-content.d.ts +6 -0
- package/dist/src/utils/copy-text.d.ts +1 -0
- package/dist/src/utils/format-chat-file-error.d.ts +3 -0
- package/package.json +3 -3
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import type { AIChatStore } from './store/ai-chat-store';
|
|
2
|
+
import type { AIChatLanguage as MessageLanguage } from './i18n/types';
|
|
3
|
+
import type { CSSProperties, PointerEvent as ReactPointerEvent, ReactNode } from 'react';
|
|
4
|
+
export type AIChatLanguage = MessageLanguage;
|
|
5
|
+
export type AIChatTheme = 'light' | 'dark';
|
|
6
|
+
export type ChatRole = 'user' | 'assistant';
|
|
7
|
+
export type ChatMessageStatus = 'complete' | 'streaming' | 'error' | 'cancelled' | 'no_evidence' | 'awaiting-recovery';
|
|
8
|
+
export interface Citation {
|
|
9
|
+
citation_id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
snippet: string;
|
|
12
|
+
document_id: string;
|
|
13
|
+
version?: string;
|
|
14
|
+
content?: string;
|
|
15
|
+
content_version?: string;
|
|
16
|
+
category_path?: string;
|
|
17
|
+
slug?: string;
|
|
18
|
+
url?: string;
|
|
19
|
+
published_at?: string;
|
|
20
|
+
updated_at?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface SuggestedQuestion {
|
|
23
|
+
id: string;
|
|
24
|
+
display_text: string;
|
|
25
|
+
module: string;
|
|
26
|
+
version: number;
|
|
27
|
+
}
|
|
28
|
+
export interface AttachmentOptionsLimits {
|
|
29
|
+
image_max_bytes: number;
|
|
30
|
+
turn_image_max_bytes: number;
|
|
31
|
+
text_max_bytes: number;
|
|
32
|
+
max_attachments: number;
|
|
33
|
+
input_max_characters: number;
|
|
34
|
+
conversation_image_max_bytes: number;
|
|
35
|
+
native_history_max_bytes: number;
|
|
36
|
+
draft_max_count: number;
|
|
37
|
+
draft_max_bytes: number;
|
|
38
|
+
}
|
|
39
|
+
export interface AttachmentOptions {
|
|
40
|
+
request_id: string;
|
|
41
|
+
available: boolean;
|
|
42
|
+
image_supported: boolean;
|
|
43
|
+
image_extensions: string[];
|
|
44
|
+
text_extensions: string[];
|
|
45
|
+
limits: AttachmentOptionsLimits;
|
|
46
|
+
}
|
|
47
|
+
export interface Attachment {
|
|
48
|
+
attachment_id: string;
|
|
49
|
+
kind: 'image' | 'text';
|
|
50
|
+
filename: string;
|
|
51
|
+
media_type: string;
|
|
52
|
+
size_bytes: number;
|
|
53
|
+
width?: number;
|
|
54
|
+
height?: number;
|
|
55
|
+
encoding?: string;
|
|
56
|
+
content_url: string;
|
|
57
|
+
created_at: string;
|
|
58
|
+
}
|
|
59
|
+
export interface PendingAttachment {
|
|
60
|
+
id: string;
|
|
61
|
+
file: File;
|
|
62
|
+
clientUploadId: string;
|
|
63
|
+
status: 'pending' | 'uploading' | 'uploaded' | 'error';
|
|
64
|
+
attachment?: Attachment;
|
|
65
|
+
image?: ChatImage;
|
|
66
|
+
textFile?: ChatTextFile;
|
|
67
|
+
error?: GatewayError;
|
|
68
|
+
}
|
|
69
|
+
export interface AttachmentPolicy {
|
|
70
|
+
accept: string[];
|
|
71
|
+
maxCount: number;
|
|
72
|
+
maxFileBytes: number;
|
|
73
|
+
available?: boolean;
|
|
74
|
+
imageSupported?: boolean;
|
|
75
|
+
options?: AttachmentOptions;
|
|
76
|
+
}
|
|
77
|
+
export interface GatewayError {
|
|
78
|
+
request_id?: string;
|
|
79
|
+
status: string;
|
|
80
|
+
error_code: string;
|
|
81
|
+
message?: string;
|
|
82
|
+
retry_after?: number;
|
|
83
|
+
httpStatus?: number;
|
|
84
|
+
}
|
|
85
|
+
export type ChatFeedbackRating = 'like' | 'dislike';
|
|
86
|
+
export interface ChatFeedback {
|
|
87
|
+
rating: ChatFeedbackRating | null;
|
|
88
|
+
comment: string;
|
|
89
|
+
updated_at: string;
|
|
90
|
+
}
|
|
91
|
+
export interface ChatImage {
|
|
92
|
+
id: string;
|
|
93
|
+
mimeType: string;
|
|
94
|
+
dataUrl: string;
|
|
95
|
+
width: number;
|
|
96
|
+
height: number;
|
|
97
|
+
bytes: number;
|
|
98
|
+
name?: string;
|
|
99
|
+
}
|
|
100
|
+
export interface ChatTextFile {
|
|
101
|
+
id: string;
|
|
102
|
+
mimeType: 'text/plain';
|
|
103
|
+
text: string;
|
|
104
|
+
bytes: number;
|
|
105
|
+
name: string;
|
|
106
|
+
}
|
|
107
|
+
export type TextContentPart = {
|
|
108
|
+
type: 'text';
|
|
109
|
+
text: string;
|
|
110
|
+
};
|
|
111
|
+
export type ImageContentPart = {
|
|
112
|
+
type: 'image';
|
|
113
|
+
image: ChatImage;
|
|
114
|
+
};
|
|
115
|
+
export type TextFileContentPart = {
|
|
116
|
+
type: 'text-file';
|
|
117
|
+
file: ChatTextFile;
|
|
118
|
+
};
|
|
119
|
+
export type ChatContentPart = TextContentPart | ImageContentPart | TextFileContentPart;
|
|
120
|
+
export interface ChatSendInput {
|
|
121
|
+
content: ChatContentPart[];
|
|
122
|
+
query?: string;
|
|
123
|
+
attachmentIds?: string[];
|
|
124
|
+
clientMessageId?: string;
|
|
125
|
+
runId?: string;
|
|
126
|
+
conversationId?: string;
|
|
127
|
+
module?: string;
|
|
128
|
+
suggestedQuestionId?: string;
|
|
129
|
+
suggestedQuestionVersion?: number;
|
|
130
|
+
}
|
|
131
|
+
export interface ChatFileError {
|
|
132
|
+
type: 'fileLimitExceeded' | 'fileTooLarge' | 'unsupportedFile';
|
|
133
|
+
value: number | string;
|
|
134
|
+
}
|
|
135
|
+
export interface ChatToast {
|
|
136
|
+
kind: 'success' | 'error' | 'loading';
|
|
137
|
+
message: string;
|
|
138
|
+
errorCode?: string;
|
|
139
|
+
}
|
|
140
|
+
export interface ChatMessage {
|
|
141
|
+
id: string;
|
|
142
|
+
role: ChatRole;
|
|
143
|
+
text: string;
|
|
144
|
+
status: ChatMessageStatus;
|
|
145
|
+
images?: ChatImage[];
|
|
146
|
+
textFiles?: ChatTextFile[];
|
|
147
|
+
attachments?: Attachment[];
|
|
148
|
+
citations?: Citation[];
|
|
149
|
+
runId?: string;
|
|
150
|
+
conversationId?: string;
|
|
151
|
+
sequence?: number;
|
|
152
|
+
progress?: string;
|
|
153
|
+
error?: GatewayError;
|
|
154
|
+
confirmed?: boolean;
|
|
155
|
+
requestInput?: ChatSendInput;
|
|
156
|
+
retryable?: boolean;
|
|
157
|
+
feedback?: ChatFeedback | null;
|
|
158
|
+
}
|
|
159
|
+
export interface ChatHandlers {
|
|
160
|
+
onMessageStart?(messageId: string, conversationId?: string): void;
|
|
161
|
+
onDelta(messageId: string, delta: string, sequence?: number): void;
|
|
162
|
+
onSnapshot?(messageId: string, answer: string, citations: Citation[], sequence: number): void;
|
|
163
|
+
onCitation?(messageId: string, citation: Citation, sequence: number): void;
|
|
164
|
+
onProgress?(messageId: string, phase: string, sequence: number): void;
|
|
165
|
+
onComplete(messageId: string, result?: ChatTerminalResult): void;
|
|
166
|
+
onError(messageId: string, error: GatewayError): void;
|
|
167
|
+
}
|
|
168
|
+
export interface ChatTerminalResult {
|
|
169
|
+
status: string;
|
|
170
|
+
answer?: string;
|
|
171
|
+
citations?: Citation[];
|
|
172
|
+
error_code?: string;
|
|
173
|
+
request_id?: string;
|
|
174
|
+
retry_after?: number;
|
|
175
|
+
confirmed: boolean;
|
|
176
|
+
}
|
|
177
|
+
export interface ChatAdapter {
|
|
178
|
+
send(input: ChatSendInput, handlers: ChatHandlers): {
|
|
179
|
+
cancel(): void;
|
|
180
|
+
};
|
|
181
|
+
initializeConversation?(): Promise<void>;
|
|
182
|
+
getSuggestedQuestions?(module?: string, limit?: number): Promise<SuggestedQuestion[]>;
|
|
183
|
+
getAttachmentOptions?(): Promise<AttachmentOptions>;
|
|
184
|
+
uploadAttachment?(file: File, clientUploadId: string): Promise<Attachment>;
|
|
185
|
+
getAttachmentContent?(attachmentId: string, download?: boolean): Promise<Blob>;
|
|
186
|
+
deleteAttachment?(attachmentId: string): Promise<void>;
|
|
187
|
+
getConversation?(conversationId: string, limit?: number): Promise<ConversationItem[]>;
|
|
188
|
+
shareConversation?(conversationId: string): Promise<string>;
|
|
189
|
+
getCitation?(runId: string, citationId: string): Promise<Citation>;
|
|
190
|
+
submitFeedback?(runId: string, feedback: {
|
|
191
|
+
rating: ChatFeedbackRating | null;
|
|
192
|
+
comment: string;
|
|
193
|
+
}): Promise<ChatFeedback | null>;
|
|
194
|
+
}
|
|
195
|
+
export interface ConversationItem {
|
|
196
|
+
run_id: string;
|
|
197
|
+
message_id: string;
|
|
198
|
+
conversation_id: string;
|
|
199
|
+
status: string;
|
|
200
|
+
question?: string;
|
|
201
|
+
answer?: string;
|
|
202
|
+
attachments?: Attachment[];
|
|
203
|
+
generated_query?: boolean;
|
|
204
|
+
knowledge_scope: string;
|
|
205
|
+
citations?: Citation[];
|
|
206
|
+
feedback?: ChatFeedback | null;
|
|
207
|
+
}
|
|
208
|
+
export interface AIChatController {
|
|
209
|
+
store: AIChatStore;
|
|
210
|
+
initialize(): Promise<void>;
|
|
211
|
+
setAdapter(adapter: ChatAdapter): void;
|
|
212
|
+
setLanguage(language: AIChatLanguage): void;
|
|
213
|
+
toggle(show?: boolean): void;
|
|
214
|
+
submit(content: ChatContentPart[]): void;
|
|
215
|
+
submitSuggested(question: SuggestedQuestion): void;
|
|
216
|
+
setDraft(draft: string): void;
|
|
217
|
+
send(): void;
|
|
218
|
+
addFiles(files: File[]): Promise<void>;
|
|
219
|
+
removeAttachment(id: string): void;
|
|
220
|
+
clearAttachments(): void;
|
|
221
|
+
cancel(): void;
|
|
222
|
+
recover(): void;
|
|
223
|
+
restoreConversation(conversationId: string, limit?: number): Promise<void>;
|
|
224
|
+
share(): Promise<string | undefined>;
|
|
225
|
+
loadCitation(messageId: string, citationId: string): Promise<Citation | undefined>;
|
|
226
|
+
submitFeedback(messageId: string, rating: ChatFeedbackRating | null, comment?: string): Promise<ChatFeedback | null>;
|
|
227
|
+
clear(): void;
|
|
228
|
+
destroy(): void;
|
|
229
|
+
}
|
|
230
|
+
export interface AIChatControllerSnapshot {
|
|
231
|
+
open: boolean;
|
|
232
|
+
messages: ChatMessage[];
|
|
233
|
+
busy: boolean;
|
|
234
|
+
}
|
|
235
|
+
export interface AIChatControllerOptions {
|
|
236
|
+
defaultOpen?: boolean;
|
|
237
|
+
adapter?: ChatAdapter;
|
|
238
|
+
baseUrl?: string;
|
|
239
|
+
persistSession?: boolean | {
|
|
240
|
+
storageKey?: string;
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
export interface AIChatLauncherProps {
|
|
244
|
+
controller: AIChatController;
|
|
245
|
+
disabled?: boolean;
|
|
246
|
+
className?: string;
|
|
247
|
+
}
|
|
248
|
+
export interface AIChatProps {
|
|
249
|
+
controller: AIChatController;
|
|
250
|
+
language?: AIChatLanguage;
|
|
251
|
+
adapter?: ChatAdapter;
|
|
252
|
+
launcher?: boolean | AIChatLauncherProps;
|
|
253
|
+
container?: HTMLElement | null;
|
|
254
|
+
theme?: AIChatTheme;
|
|
255
|
+
}
|
|
256
|
+
export interface AIChatMountOptions {
|
|
257
|
+
controller?: AIChatController;
|
|
258
|
+
adapter?: ChatAdapter;
|
|
259
|
+
baseUrl?: string;
|
|
260
|
+
language?: AIChatLanguage;
|
|
261
|
+
theme?: AIChatTheme;
|
|
262
|
+
launcher?: boolean | {
|
|
263
|
+
disabled?: boolean;
|
|
264
|
+
className?: string;
|
|
265
|
+
};
|
|
266
|
+
defaultOpen?: boolean;
|
|
267
|
+
persistSession?: AIChatControllerOptions['persistSession'];
|
|
268
|
+
}
|
|
269
|
+
export interface AIChatMountResult extends ShadowMountResult {
|
|
270
|
+
controller: AIChatController;
|
|
271
|
+
}
|
|
272
|
+
export type AIChatPanelProps = Omit<AIChatProps, 'launcher' | 'mount' | 'container'>;
|
|
273
|
+
export interface AIChatInternalPanelProps extends AIChatPanelProps {
|
|
274
|
+
panelStyle?: CSSProperties;
|
|
275
|
+
onResizeStart?(edge: 'left' | 'top' | 'right' | 'bottom', event: ReactPointerEvent): void;
|
|
276
|
+
}
|
|
277
|
+
export interface ShadowMountResult {
|
|
278
|
+
host: HTMLElement;
|
|
279
|
+
root: ShadowRoot | HTMLElement;
|
|
280
|
+
container: HTMLElement;
|
|
281
|
+
destroy(): void;
|
|
282
|
+
}
|
|
283
|
+
export interface ChatMarkdownProps {
|
|
284
|
+
children: string;
|
|
285
|
+
className?: string;
|
|
286
|
+
onImageClick?(src: string, event: React.MouseEvent<HTMLButtonElement>): void;
|
|
287
|
+
}
|
|
288
|
+
export type IconProps = {
|
|
289
|
+
size?: number;
|
|
290
|
+
strokeWidth?: number;
|
|
291
|
+
};
|
|
292
|
+
export type ButtonContent = {
|
|
293
|
+
children: ReactNode;
|
|
294
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ChatContentPart, PendingAttachment } from '../types';
|
|
2
|
+
export interface BuildChatContentInput {
|
|
3
|
+
draft: string;
|
|
4
|
+
attachments: PendingAttachment[];
|
|
5
|
+
}
|
|
6
|
+
export declare function buildChatContent({ draft, attachments, }: BuildChatContentInput): ChatContentPart[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function copyText(value: string): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rayvision/ai-chat",
|
|
3
3
|
"author": "helmy_l",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2-beta",
|
|
5
5
|
"description": "Shared Renderbus AI chat UI package",
|
|
6
6
|
"private": false,
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"zustand": "^4.4.7"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"react": ">=
|
|
31
|
-
"react-dom": ">=
|
|
30
|
+
"react": ">=18.0.0",
|
|
31
|
+
"react-dom": ">=18.0.0"
|
|
32
32
|
}
|
|
33
33
|
}
|