@widgetic/chat 0.1.4

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 (72) hide show
  1. package/README.md +440 -0
  2. package/dist/adapters/index.d.ts +2 -0
  3. package/dist/adapters/index.js +2 -0
  4. package/dist/adapters/widgeticAdapter.d.ts +185 -0
  5. package/dist/adapters/widgeticAdapter.js +766 -0
  6. package/dist/components/ActionBar.svelte +342 -0
  7. package/dist/components/ActionBar.svelte.d.ts +37 -0
  8. package/dist/components/AttachmentDisplay.svelte +547 -0
  9. package/dist/components/AttachmentDisplay.svelte.d.ts +12 -0
  10. package/dist/components/Chat.svelte +1253 -0
  11. package/dist/components/Chat.svelte.d.ts +112 -0
  12. package/dist/components/ChatHeader.svelte +182 -0
  13. package/dist/components/ChatHeader.svelte.d.ts +12 -0
  14. package/dist/components/ChatInput.svelte +290 -0
  15. package/dist/components/ChatInput.svelte.d.ts +15 -0
  16. package/dist/components/ChatMessages.svelte +996 -0
  17. package/dist/components/ChatMessages.svelte.d.ts +28 -0
  18. package/dist/components/CodeBlock.svelte +286 -0
  19. package/dist/components/CodeBlock.svelte.d.ts +10 -0
  20. package/dist/components/ContextPreview.svelte +66 -0
  21. package/dist/components/ContextPreview.svelte.d.ts +8 -0
  22. package/dist/components/LoadingIndicator.svelte +151 -0
  23. package/dist/components/LoadingIndicator.svelte.d.ts +9 -0
  24. package/dist/components/StatusIndicator.svelte +116 -0
  25. package/dist/components/StatusIndicator.svelte.d.ts +9 -0
  26. package/dist/components/SuggestionButtons.svelte +244 -0
  27. package/dist/components/SuggestionButtons.svelte.d.ts +26 -0
  28. package/dist/components/index.d.ts +12 -0
  29. package/dist/components/index.js +12 -0
  30. package/dist/config.d.ts +43 -0
  31. package/dist/config.js +67 -0
  32. package/dist/constants/colors.d.ts +20 -0
  33. package/dist/constants/colors.js +16 -0
  34. package/dist/index.d.ts +11 -0
  35. package/dist/index.js +20 -0
  36. package/dist/services/chatService.d.ts +72 -0
  37. package/dist/services/chatService.js +355 -0
  38. package/dist/services/index.d.ts +2 -0
  39. package/dist/services/index.js +2 -0
  40. package/dist/stores/chatStore.d.ts +46 -0
  41. package/dist/stores/chatStore.js +219 -0
  42. package/dist/stores/index.d.ts +2 -0
  43. package/dist/stores/index.js +2 -0
  44. package/dist/types/adapter.d.ts +86 -0
  45. package/dist/types/adapter.js +1 -0
  46. package/dist/types/api-temp.d.ts +61 -0
  47. package/dist/types/api-temp.js +42 -0
  48. package/dist/types/attachment.d.ts +84 -0
  49. package/dist/types/attachment.js +33 -0
  50. package/dist/types/chat.d.ts +114 -0
  51. package/dist/types/chat.js +1 -0
  52. package/dist/types/config.d.ts +89 -0
  53. package/dist/types/config.js +63 -0
  54. package/dist/types/context.d.ts +108 -0
  55. package/dist/types/context.js +11 -0
  56. package/dist/types/conversation.d.ts +45 -0
  57. package/dist/types/conversation.js +1 -0
  58. package/dist/types/events.d.ts +141 -0
  59. package/dist/types/events.js +1 -0
  60. package/dist/types/index.d.ts +16 -0
  61. package/dist/types/index.js +10 -0
  62. package/dist/types/message.d.ts +82 -0
  63. package/dist/types/message.js +1 -0
  64. package/dist/types/state.d.ts +117 -0
  65. package/dist/types/state.js +1 -0
  66. package/dist/utils/fileUtils.d.ts +93 -0
  67. package/dist/utils/fileUtils.js +299 -0
  68. package/dist/utils/index.d.ts +3 -0
  69. package/dist/utils/index.js +4 -0
  70. package/dist/utils/logger.d.ts +4 -0
  71. package/dist/utils/logger.js +28 -0
  72. package/package.json +104 -0
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Conversation shape exchanged with the conversations API
3
+ * (camelCase wire contract of the co-editor chat).
4
+ */
5
+ export interface ChatConversation {
6
+ id: string;
7
+ title: string;
8
+ completed: boolean;
9
+ createdAt: Date;
10
+ updatedAt: Date;
11
+ _unreadCount?: number;
12
+ _lastActivity?: Date;
13
+ _isActive?: boolean;
14
+ }
15
+ /**
16
+ * Conversation input for creating new conversations
17
+ */
18
+ export interface ConversationInput {
19
+ componentId: string;
20
+ title?: string;
21
+ completed?: boolean;
22
+ }
23
+ /**
24
+ * Conversation status options
25
+ */
26
+ export type ConversationStatus = 'active' | 'completed' | 'archived';
27
+ /**
28
+ * Conversation filters for listing
29
+ */
30
+ export interface ConversationFilters {
31
+ status?: ConversationStatus;
32
+ completed?: boolean;
33
+ search?: string;
34
+ contextId?: string;
35
+ }
36
+ /**
37
+ * Conversation summary for display
38
+ */
39
+ export interface ConversationSummary {
40
+ id: string;
41
+ title: string;
42
+ messageCount: number;
43
+ lastMessage?: string;
44
+ updatedAt: string;
45
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,141 @@
1
+ import type { ChatMessage } from './message.js';
2
+ import type { ChatConversation } from './conversation.js';
3
+ import type { ChatContext } from './context.js';
4
+ /**
5
+ * Chat event types for internal communication
6
+ */
7
+ export type ChatEventType = 'message:sent' | 'message:received' | 'message:updated' | 'message:deleted' | 'conversation:created' | 'conversation:updated' | 'conversation:deleted' | 'context:selected' | 'context:deselected' | 'context:updated' | 'attachment:uploaded' | 'attachment:failed' | 'upload:progress' | 'recording:started' | 'recording:stopped' | 'screenshot:captured' | 'typing:start' | 'typing:stop' | 'error:occurred' | 'connection:established' | 'connection:lost';
8
+ /**
9
+ * Base chat event interface
10
+ */
11
+ export interface ChatEvent {
12
+ type: ChatEventType;
13
+ timestamp: Date;
14
+ contextId?: string;
15
+ conversationId?: string;
16
+ userId?: string;
17
+ data?: any;
18
+ }
19
+ /**
20
+ * Message-related events
21
+ */
22
+ export interface MessageEvent extends ChatEvent {
23
+ type: 'message:sent' | 'message:received' | 'message:updated' | 'message:deleted';
24
+ data: {
25
+ message: ChatMessage;
26
+ messageId?: string;
27
+ updates?: Partial<ChatMessage>;
28
+ };
29
+ }
30
+ /**
31
+ * Conversation-related events
32
+ */
33
+ export interface ConversationEvent extends ChatEvent {
34
+ type: 'conversation:created' | 'conversation:updated' | 'conversation:deleted';
35
+ data: {
36
+ conversation: ChatConversation;
37
+ conversationId?: string;
38
+ updates?: Partial<ChatConversation>;
39
+ };
40
+ }
41
+ /**
42
+ * Context-related events
43
+ */
44
+ export interface ContextEvent extends ChatEvent {
45
+ type: 'context:selected' | 'context:deselected' | 'context:updated';
46
+ data: {
47
+ context: ChatContext;
48
+ previousContext?: ChatContext;
49
+ };
50
+ }
51
+ /**
52
+ * Upload-related events
53
+ */
54
+ export interface UploadEvent extends ChatEvent {
55
+ type: 'attachment:uploaded' | 'attachment:failed' | 'upload:progress';
56
+ data: {
57
+ attachmentId: string;
58
+ fileName: string;
59
+ progress?: number;
60
+ url?: string;
61
+ error?: string;
62
+ };
63
+ }
64
+ /**
65
+ * Media capture events
66
+ */
67
+ export interface MediaEvent extends ChatEvent {
68
+ type: 'recording:started' | 'recording:stopped' | 'screenshot:captured';
69
+ data: {
70
+ mediaType: 'video' | 'audio' | 'image';
71
+ mediaUrl?: string;
72
+ duration?: number;
73
+ error?: string;
74
+ };
75
+ }
76
+ /**
77
+ * Typing indicator events
78
+ */
79
+ export interface TypingEvent extends ChatEvent {
80
+ type: 'typing:start' | 'typing:stop';
81
+ data: {
82
+ isTyping: boolean;
83
+ };
84
+ }
85
+ /**
86
+ * Error events
87
+ */
88
+ export interface ErrorEvent extends ChatEvent {
89
+ type: 'error:occurred';
90
+ data: {
91
+ error: Error;
92
+ code?: string;
93
+ details?: any;
94
+ };
95
+ }
96
+ /**
97
+ * Connection events
98
+ */
99
+ export interface ConnectionEvent extends ChatEvent {
100
+ type: 'connection:established' | 'connection:lost';
101
+ data: {
102
+ connected: boolean;
103
+ reason?: string;
104
+ };
105
+ }
106
+ /**
107
+ * WebSocket message types for real-time updates
108
+ */
109
+ export type WebSocketEventType = 'chat:message:new' | 'chat:message:update' | 'chat:conversation:update' | 'chat:typing:start' | 'chat:typing:stop' | 'canvas:frame:selected' | 'canvas:frame:updated';
110
+ /**
111
+ * WebSocket message structure
112
+ */
113
+ export interface WebSocketMessage {
114
+ type: WebSocketEventType;
115
+ payload: any;
116
+ timestamp: string;
117
+ userId?: string;
118
+ contextId?: string;
119
+ conversationId?: string;
120
+ }
121
+ /**
122
+ * Event listener type
123
+ */
124
+ export type ChatEventListener<T extends ChatEvent = ChatEvent> = (event: T) => void | Promise<void>;
125
+ /**
126
+ * Event emitter interface
127
+ */
128
+ export interface ChatEventEmitter {
129
+ on<T extends ChatEvent>(eventType: T['type'], listener: ChatEventListener<T>): () => void;
130
+ off<T extends ChatEvent>(eventType: T['type'], listener: ChatEventListener<T>): void;
131
+ emit<T extends ChatEvent>(event: T): void;
132
+ once<T extends ChatEvent>(eventType: T['type'], listener: ChatEventListener<T>): () => void;
133
+ }
134
+ /**
135
+ * Event bus configuration
136
+ */
137
+ export interface EventBusConfig {
138
+ maxListeners?: number;
139
+ enableLogging?: boolean;
140
+ queueSize?: number;
141
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ export * from './chat.js';
2
+ export * from './context.js';
3
+ export * from './message.js';
4
+ export * from './conversation.js';
5
+ export * from './attachment.js';
6
+ export * from './state.js';
7
+ export * from './config.js';
8
+ export * from './adapter.js';
9
+ export * from './events.js';
10
+ export type { ChatService, ChatInstance, ChatFactory } from './chat.js';
11
+ export type { ChatMessage, MessageInput } from './message.js';
12
+ export type { ChatConversation, ConversationInput } from './conversation.js';
13
+ export type { ChatContext, FrameContext, ContextCapabilities } from './context.js';
14
+ export type { ChatState, ChatAction, InputState, UIState, ActiveContextState, MessageState, ConversationState } from './state.js';
15
+ export type { PlatformAdapter, WidgeticAdapter, AdapterFactory, AdapterConfig } from './adapter.js';
16
+ export type { AttachmentInput, PendingAttachment, AttachmentType, AttachmentValidation, UploadStatus, ProcessedAttachment, FILE_TYPE_CONFIG } from './attachment.js';
@@ -0,0 +1,10 @@
1
+ // Core Chat Types
2
+ export * from './chat.js';
3
+ export * from './context.js';
4
+ export * from './message.js';
5
+ export * from './conversation.js';
6
+ export * from './attachment.js';
7
+ export * from './state.js';
8
+ export * from './config.js';
9
+ export * from './adapter.js';
10
+ export * from './events.js';
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Content attachment as stored on a message (mirrors the API's
3
+ * message_contents/contents join output).
4
+ */
5
+ export interface ContentItemOutput {
6
+ id: string;
7
+ url: string;
8
+ file_type: string;
9
+ file_name?: string | null;
10
+ file_size?: number | null;
11
+ metadata?: Record<string, any> | null;
12
+ created_at: string;
13
+ display_order: number;
14
+ }
15
+ /**
16
+ * Message shape exchanged with the conversations/messages API
17
+ * (camelCase wire contract of the co-editor chat).
18
+ */
19
+ export interface ChatMessage {
20
+ id: string;
21
+ conversationId: string;
22
+ messageContent?: string | null;
23
+ messageType: 'user' | 'assistant';
24
+ attachments?: ContentItemOutput[];
25
+ isCommit?: boolean;
26
+ userId: string;
27
+ createdAt: Date;
28
+ updatedAt: Date;
29
+ _optimistic?: boolean;
30
+ _failed?: boolean;
31
+ _retryCount?: number;
32
+ _localId?: string;
33
+ /** When set, this message was undone by a restore-checkpoint. Shown grayed-out in UI. */
34
+ rolledBackAt?: string | null;
35
+ /** Latest successful repo commit — show "Head at commit" on this assistant message. */
36
+ isWidgetHead?: boolean;
37
+ }
38
+ /**
39
+ * Message input type for creating new messages
40
+ */
41
+ export interface MessageInput {
42
+ messageContent?: string | null;
43
+ messageType: 'user' | 'assistant';
44
+ attachments?: AttachmentInput[];
45
+ isCommit?: boolean;
46
+ }
47
+ /**
48
+ * Attachment input for creating messages
49
+ */
50
+ export interface AttachmentInput {
51
+ file: File;
52
+ preview?: string;
53
+ uploadProgress?: number;
54
+ error?: string;
55
+ }
56
+ /**
57
+ * Message display configuration
58
+ */
59
+ export interface MessageDisplayOptions {
60
+ showHeader: boolean;
61
+ showTimestamp: boolean;
62
+ showAvatar: boolean;
63
+ groupConsecutive: boolean;
64
+ }
65
+ /**
66
+ * Message validation result
67
+ */
68
+ export interface MessageValidation {
69
+ hasContent: boolean;
70
+ hasAttachments: boolean;
71
+ isValid: boolean;
72
+ errors: string[];
73
+ }
74
+ /**
75
+ * Message group for displaying consecutive messages from same sender
76
+ */
77
+ export interface MessageGroup {
78
+ messages: ChatMessage[];
79
+ sender: 'user' | 'assistant';
80
+ timestamp: Date;
81
+ showHeader: boolean;
82
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,117 @@
1
+ import type { ChatMessage, AttachmentInput } from './message.js';
2
+ import type { ChatConversation } from './conversation.js';
3
+ import type { ChatContext } from './context.js';
4
+ /**
5
+ * Active context state
6
+ */
7
+ export interface ActiveContextState {
8
+ contextId: string | null;
9
+ isExpanded: boolean;
10
+ expandedAt?: Date;
11
+ }
12
+ /**
13
+ * Input state for the chat interface
14
+ */
15
+ export interface InputState {
16
+ text: string;
17
+ attachments: AttachmentInput[];
18
+ isRecording: boolean;
19
+ isSending: boolean;
20
+ isUploading: boolean;
21
+ uploadProgress: Record<string, number>;
22
+ history: string[];
23
+ historyIndex: number;
24
+ }
25
+ /**
26
+ * UI state for the chat interface
27
+ */
28
+ export interface UIState {
29
+ isExpanded: boolean;
30
+ isLoading: boolean;
31
+ activeTab: string;
32
+ errorMessage: string | null;
33
+ lastAction: string | null;
34
+ recordingDuration?: number;
35
+ recordingStartTime?: Date;
36
+ }
37
+ /**
38
+ * Message store state
39
+ */
40
+ export interface MessageState {
41
+ byConversationId: Record<string, ChatMessage[]>;
42
+ isLoading: Record<string, boolean>;
43
+ errors: Record<string, string | null>;
44
+ }
45
+ /**
46
+ * Conversation store state
47
+ */
48
+ export interface ConversationState {
49
+ byContextId: Record<string, ChatConversation[]>;
50
+ isLoading: Record<string, boolean>;
51
+ errors: Record<string, string | null>;
52
+ }
53
+ /**
54
+ * Chat store state combining all sub-states
55
+ */
56
+ export interface ChatState {
57
+ activeContext: ActiveContextState;
58
+ input: InputState;
59
+ ui: UIState;
60
+ messages: MessageState;
61
+ conversations: ConversationState;
62
+ availableContexts: ChatContext[];
63
+ }
64
+ /**
65
+ * Store update actions
66
+ */
67
+ export type ChatAction = {
68
+ type: 'SET_ACTIVE_CONTEXT';
69
+ payload: {
70
+ contextId: string | null;
71
+ isExpanded?: boolean;
72
+ };
73
+ } | {
74
+ type: 'UPDATE_INPUT';
75
+ payload: Partial<InputState>;
76
+ } | {
77
+ type: 'UPDATE_UI';
78
+ payload: Partial<UIState>;
79
+ } | {
80
+ type: 'ADD_MESSAGE';
81
+ payload: {
82
+ conversationId: string;
83
+ message: ChatMessage;
84
+ };
85
+ } | {
86
+ type: 'UPDATE_MESSAGE';
87
+ payload: {
88
+ conversationId: string;
89
+ messageId: string;
90
+ updates: Partial<ChatMessage>;
91
+ };
92
+ } | {
93
+ type: 'ADD_CONVERSATION';
94
+ payload: {
95
+ contextId: string;
96
+ conversation: ChatConversation;
97
+ };
98
+ } | {
99
+ type: 'UPDATE_CONVERSATION';
100
+ payload: {
101
+ contextId: string;
102
+ conversationId: string;
103
+ updates: Partial<ChatConversation>;
104
+ };
105
+ } | {
106
+ type: 'SET_LOADING';
107
+ payload: {
108
+ key: string;
109
+ loading: boolean;
110
+ };
111
+ } | {
112
+ type: 'SET_ERROR';
113
+ payload: {
114
+ key: string;
115
+ error: string | null;
116
+ };
117
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,93 @@
1
+ import type { AttachmentType, AttachmentValidation, PendingAttachment } from '../types/index.js';
2
+ /**
3
+ * File type configuration mapping
4
+ */
5
+ export declare const fileTypeConfig: {
6
+ image: {
7
+ type: AttachmentType;
8
+ icon: string;
9
+ preview: boolean;
10
+ accept: string[];
11
+ maxSize: number;
12
+ };
13
+ video: {
14
+ type: AttachmentType;
15
+ icon: string;
16
+ preview: boolean;
17
+ accept: string[];
18
+ maxSize: number;
19
+ };
20
+ document: {
21
+ type: AttachmentType;
22
+ icon: string;
23
+ preview: boolean;
24
+ accept: string[];
25
+ maxSize: number;
26
+ };
27
+ other: {
28
+ type: AttachmentType;
29
+ icon: string;
30
+ preview: boolean;
31
+ accept: string[];
32
+ maxSize: number;
33
+ };
34
+ };
35
+ /**
36
+ * Detect file type from MIME type and file name
37
+ */
38
+ export declare function detectFileType(mimeType: string, fileName?: string): AttachmentType;
39
+ /**
40
+ * Validate a file for upload
41
+ */
42
+ export declare function validateFile(file: File, config?: {
43
+ maxSize?: number;
44
+ allowedTypes?: string[];
45
+ }): AttachmentValidation;
46
+ /**
47
+ * Validate multiple files
48
+ */
49
+ export declare function validateFiles(files: File[], config?: {
50
+ maxFiles?: number;
51
+ maxSize?: number;
52
+ allowedTypes?: string[];
53
+ }): AttachmentValidation;
54
+ /**
55
+ * Format file size in human-readable format
56
+ */
57
+ export declare function formatFileSize(bytes: number): string;
58
+ /**
59
+ * Get file extension from filename
60
+ */
61
+ export declare function getFileExtension(filename: string): string;
62
+ /**
63
+ * Generate unique file ID
64
+ */
65
+ export declare function generateFileId(): string;
66
+ /**
67
+ * Create a preview URL for supported file types
68
+ */
69
+ export declare function createFilePreview(file: File): Promise<string | null>;
70
+ /**
71
+ * Create a pending attachment from a file
72
+ */
73
+ export declare function createPendingAttachment(file: File): Promise<PendingAttachment>;
74
+ /**
75
+ * Get MIME type accept string for file input
76
+ */
77
+ export declare function getAcceptString(types: AttachmentType[]): string;
78
+ /**
79
+ * Check if file supports preview
80
+ */
81
+ export declare function supportsPreview(file: File): boolean;
82
+ /**
83
+ * Get appropriate icon for file type
84
+ */
85
+ export declare function getFileIcon(file: File): string;
86
+ /**
87
+ * Compress image file if needed
88
+ */
89
+ export declare function compressImage(file: File, options: {
90
+ maxWidth?: number;
91
+ maxHeight?: number;
92
+ quality?: number;
93
+ }): Promise<File>;