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