@rayvision/ai-chat 0.0.2-beta → 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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import type { PendingAttachment } from '../types';
2
+ import { type PendingAttachment } from '../types';
3
3
  interface ChatComposerProps {
4
4
  attachments: PendingAttachment[];
5
5
  draft: string;
@@ -11,6 +11,7 @@ interface ChatComposerProps {
11
11
  onFiles(files: File[]): void;
12
12
  onRemoveAttachment(id: string): void;
13
13
  onSubmit(): void;
14
+ onCancel(): void;
14
15
  }
15
- export declare function ChatComposer({ attachments, draft, busy, accept, attachmentsAvailable, onDraftChange, onPaste, onFiles, onRemoveAttachment, onSubmit, }: ChatComposerProps): JSX.Element;
16
+ export declare function ChatComposer({ attachments, draft, busy, accept, attachmentsAvailable, onDraftChange, onPaste, onFiles, onRemoveAttachment, onSubmit, onCancel, }: ChatComposerProps): JSX.Element;
16
17
  export {};
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import type { ChatFeedbackRating, ChatMessage, Citation } from '../types';
2
+ import { type ChatFeedbackRating, type ChatMessage, type Citation } from '../types';
3
3
  interface MessageBubbleProps {
4
4
  message: ChatMessage;
5
5
  onCitationClick?: (messageId: string, citationId: string) => Promise<Citation | undefined>;
@@ -45,6 +45,7 @@ export declare const EN_MESSAGES: {
45
45
  syncing: string;
46
46
  loading: string;
47
47
  retry: string;
48
+ knowledgeBusy: string;
48
49
  requestFailed: string;
49
50
  darkMode: string;
50
51
  lightMode: string;
@@ -45,6 +45,7 @@ export declare const ZH_MESSAGES: {
45
45
  syncing: string;
46
46
  loading: string;
47
47
  retry: string;
48
+ knowledgeBusy: string;
48
49
  requestFailed: string;
49
50
  darkMode: string;
50
51
  lightMode: string;
@@ -1,2 +1,10 @@
1
1
  import type { AIChatLanguage } from './types';
2
+ export declare const CHAT_PHASE: {
3
+ readonly PROCESSING: "processing";
4
+ readonly SEARCHING: "searching";
5
+ readonly READING: "reading";
6
+ readonly RESPONDING: "responding";
7
+ readonly FINALIZING: "finalizing";
8
+ };
9
+ export type ChatPhase = (typeof CHAT_PHASE)[keyof typeof CHAT_PHASE];
2
10
  export declare function getPhaseLabel(language: AIChatLanguage, phase: string): string | null;
@@ -1,4 +1,23 @@
1
- import type { Attachment, AttachmentOptions, ChatFeedback, Citation, ConversationItem, GatewayError, SuggestedQuestion } from '../../types';
1
+ import type { Attachment, AttachmentOptions, ChatFeedback, Citation, ConversationItem, GatewayError, GatewayErrorCode, SuggestedQuestion } from '../../types';
2
+ export declare const GATEWAY_SSE_EVENT: {
3
+ readonly RUN_STARTED: "run.started";
4
+ readonly RUN_PROGRESS: "run.progress";
5
+ readonly ANSWER_DELTA: "answer.delta";
6
+ readonly ANSWER_SNAPSHOT: "answer.snapshot";
7
+ readonly CITATION_ADDED: "citation.added";
8
+ readonly RUN_COMPLETED: "run.completed";
9
+ readonly RUN_NO_EVIDENCE: "run.no_evidence";
10
+ readonly RUN_FAILED: "run.failed";
11
+ readonly TERMINAL: "terminal";
12
+ };
13
+ export type GatewaySseEventName = (typeof GATEWAY_SSE_EVENT)[keyof typeof GATEWAY_SSE_EVENT];
14
+ export declare const GATEWAY_RUN_STATUS: {
15
+ readonly QUEUED: "queued";
16
+ readonly RUNNING: "running";
17
+ readonly COMPLETED: "completed";
18
+ readonly NO_EVIDENCE: "no_evidence";
19
+ };
20
+ export type GatewayRunStatus = (typeof GATEWAY_RUN_STATUS)[keyof typeof GATEWAY_RUN_STATUS] | string;
2
21
  export interface FreeQueryRequest {
3
22
  query?: string;
4
23
  attachment_ids?: string[];
@@ -40,23 +59,23 @@ export interface AnswerSnapshotEvent {
40
59
  run_id: string;
41
60
  sequence: number;
42
61
  answer: string;
43
- status: string;
62
+ status: GatewayRunStatus;
44
63
  citations: Citation[];
45
64
  }
46
65
  export interface RunTerminalEvent {
47
66
  run_id?: string;
48
67
  conversation_id?: string;
49
68
  sequence?: number;
50
- status: string;
69
+ status: GatewayRunStatus;
51
70
  answer?: string;
52
71
  citations?: Citation[];
53
- error_code: string;
72
+ error_code: GatewayErrorCode;
54
73
  message?: string;
55
74
  retry_after?: number;
56
75
  }
57
76
  export interface GatewaySseEvent {
58
77
  id?: string;
59
- event: string;
78
+ event: GatewaySseEventName;
60
79
  data: unknown;
61
80
  }
62
81
  export interface ConversationResponse {
@@ -3,8 +3,43 @@ import type { AIChatLanguage as MessageLanguage } from './i18n/types';
3
3
  import type { CSSProperties, PointerEvent as ReactPointerEvent, ReactNode } from 'react';
4
4
  export type AIChatLanguage = MessageLanguage;
5
5
  export type AIChatTheme = 'light' | 'dark';
6
- export type ChatRole = 'user' | 'assistant';
7
- export type ChatMessageStatus = 'complete' | 'streaming' | 'error' | 'cancelled' | 'no_evidence' | 'awaiting-recovery';
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;
8
43
  export interface Citation {
9
44
  citation_id: string;
10
45
  title: string;
@@ -60,10 +95,8 @@ export interface PendingAttachment {
60
95
  id: string;
61
96
  file: File;
62
97
  clientUploadId: string;
63
- status: 'pending' | 'uploading' | 'uploaded' | 'error';
98
+ status: AttachmentUploadStatus;
64
99
  attachment?: Attachment;
65
- image?: ChatImage;
66
- textFile?: ChatTextFile;
67
100
  error?: GatewayError;
68
101
  }
69
102
  export interface AttachmentPolicy {
@@ -77,7 +110,7 @@ export interface AttachmentPolicy {
77
110
  export interface GatewayError {
78
111
  request_id?: string;
79
112
  status: string;
80
- error_code: string;
113
+ error_code: GatewayErrorCode;
81
114
  message?: string;
82
115
  retry_after?: number;
83
116
  httpStatus?: number;
@@ -88,35 +121,11 @@ export interface ChatFeedback {
88
121
  comment: string;
89
122
  updated_at: string;
90
123
  }
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
124
  export type TextContentPart = {
108
125
  type: 'text';
109
126
  text: string;
110
127
  };
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;
128
+ export type ChatContentPart = TextContentPart;
120
129
  export interface ChatSendInput {
121
130
  content: ChatContentPart[];
122
131
  query?: string;
@@ -142,8 +151,6 @@ export interface ChatMessage {
142
151
  role: ChatRole;
143
152
  text: string;
144
153
  status: ChatMessageStatus;
145
- images?: ChatImage[];
146
- textFiles?: ChatTextFile[];
147
154
  attachments?: Attachment[];
148
155
  citations?: Citation[];
149
156
  runId?: string;
@@ -153,6 +160,7 @@ export interface ChatMessage {
153
160
  error?: GatewayError;
154
161
  confirmed?: boolean;
155
162
  requestInput?: ChatSendInput;
163
+ retryCount?: number;
156
164
  retryable?: boolean;
157
165
  feedback?: ChatFeedback | null;
158
166
  }
@@ -211,7 +219,6 @@ export interface AIChatController {
211
219
  setAdapter(adapter: ChatAdapter): void;
212
220
  setLanguage(language: AIChatLanguage): void;
213
221
  toggle(show?: boolean): void;
214
- submit(content: ChatContentPart[]): void;
215
222
  submitSuggested(question: SuggestedQuestion): void;
216
223
  setDraft(draft: string): void;
217
224
  send(): void;
@@ -1,6 +1,5 @@
1
- import type { ChatContentPart, PendingAttachment } from '../types';
1
+ import type { ChatContentPart } from '../types';
2
2
  export interface BuildChatContentInput {
3
3
  draft: string;
4
- attachments: PendingAttachment[];
5
4
  }
6
- export declare function buildChatContent({ draft, attachments, }: BuildChatContentInput): ChatContentPart[];
5
+ export declare function buildChatContent({ draft }: BuildChatContentInput): ChatContentPart[];
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.2-beta",
4
+ "version": "0.0.2",
5
5
  "description": "Shared Renderbus AI chat UI package",
6
6
  "private": false,
7
7
  "main": "./dist/index.js",