@widgetic/chat 0.1.4 → 0.1.5
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/dist/components/Chat.svelte +205 -81
- package/dist/components/Chat.svelte.d.ts +12 -2
- package/dist/components/ChatMessages.svelte +68 -15
- package/dist/config.js +6 -6
- package/dist/constants/colors.js +1 -1
- package/dist/services/chatService.js +169 -280
- package/dist/stores/chatStore.d.ts +1 -0
- package/dist/stores/chatStore.js +214 -113
- package/dist/types/attachment.js +1 -1
- package/dist/types/config.d.ts +5 -0
- package/dist/types/config.js +2 -1
- package/dist/utils/fileUtils.js +57 -108
- package/dist/utils/logger.js +7 -19
- package/package.json +1 -1
- package/dist/types/api-temp.d.ts +0 -61
- package/dist/types/api-temp.js +0 -42
package/dist/config.js
CHANGED
|
@@ -27,7 +27,7 @@ if (!env.PUBLIC_PRODUCTION_URL) {
|
|
|
27
27
|
throw new Error('PUBLIC_PRODUCTION_URL environment variable is not set');
|
|
28
28
|
}
|
|
29
29
|
// Create and export the config object with proper typing
|
|
30
|
-
export
|
|
30
|
+
export const config = {
|
|
31
31
|
API_URL: env.PUBLIC_API_URL,
|
|
32
32
|
API_VERSION: env.PUBLIC_API_VERSION,
|
|
33
33
|
INTERNAL_KEY: env.PUBLIC_INTERNAL_KEY,
|
|
@@ -43,23 +43,23 @@ export var config = {
|
|
|
43
43
|
*/
|
|
44
44
|
export function createSdkConfig(options) {
|
|
45
45
|
return new Configuration({
|
|
46
|
-
apiKey:
|
|
47
|
-
basePath:
|
|
46
|
+
apiKey: (name) => options?.apiKey || config.API_KEY || config.INTERNAL_KEY || '',
|
|
47
|
+
basePath: options?.basePath || getApiUrl()
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Gets the full API URL for the current environment
|
|
52
52
|
*/
|
|
53
53
|
export function getApiUrl() {
|
|
54
|
-
|
|
54
|
+
const baseUrl = config.NODE_ENV === 'production'
|
|
55
55
|
? config.PRODUCTION_URL
|
|
56
56
|
: config.API_URL;
|
|
57
|
-
return
|
|
57
|
+
return `${baseUrl}${config.API_VERSION}`;
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
60
|
* Environment-specific settings
|
|
61
61
|
*/
|
|
62
|
-
export
|
|
62
|
+
export const environment = {
|
|
63
63
|
isProduction: config.NODE_ENV === 'production',
|
|
64
64
|
apiUrl: getApiUrl(),
|
|
65
65
|
// Use API_KEY if available, fall back to INTERNAL_KEY
|
package/dist/constants/colors.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Message background colors for different states
|
|
3
3
|
* These can be easily modified to change the appearance of messages
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export const MESSAGE_COLORS = {
|
|
6
6
|
/** Background color for user messages in completed chats */
|
|
7
7
|
USER_COMPLETED: '#C6FFD3', // Light green
|
|
8
8
|
/** Background color for user messages in active (non-completed) chats */
|
|
@@ -1,57 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
import { chatLog } from '../utils/logger.js';
|
|
49
|
-
import { ConversationsApi, MessagesApi } from '@widgetic/api-sdk';
|
|
1
|
+
import { chatLog, chatWarn } from '../utils/logger.js';
|
|
2
|
+
import { ConversationsApi, MessagesApi, Configuration } from '@widgetic/api-sdk';
|
|
50
3
|
/**
|
|
51
4
|
* Chat service implementation using Widgetic API SDK
|
|
52
5
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
6
|
+
export class WidgeticChatService {
|
|
7
|
+
conversationsApi;
|
|
8
|
+
messagesApi;
|
|
9
|
+
constructor(configuration) {
|
|
55
10
|
this.conversationsApi = new ConversationsApi(configuration);
|
|
56
11
|
this.messagesApi = new MessagesApi(configuration);
|
|
57
12
|
chatLog('ChatService initialized (mock mode)');
|
|
@@ -59,159 +14,116 @@ var WidgeticChatService = /** @class */ (function () {
|
|
|
59
14
|
/**
|
|
60
15
|
* Get all conversations for a given context (canvas + component)
|
|
61
16
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
throw new Error('Failed to load conversations');
|
|
75
|
-
}
|
|
76
|
-
return [2 /*return*/];
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
};
|
|
17
|
+
async getConversations(contextId) {
|
|
18
|
+
const [canvasId, componentId] = this.parseContextId(contextId);
|
|
19
|
+
try {
|
|
20
|
+
// Mock implementation for now
|
|
21
|
+
chatLog('Getting conversations for:', { canvasId, componentId });
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error('Failed to get conversations:', error);
|
|
26
|
+
throw new Error('Failed to load conversations');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
80
29
|
/**
|
|
81
30
|
* Create a new conversation
|
|
82
31
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
return [2 /*return*/];
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
};
|
|
32
|
+
async createConversation(contextId, data) {
|
|
33
|
+
const [canvasId, componentId] = this.parseContextId(contextId);
|
|
34
|
+
const request = {
|
|
35
|
+
title: data.title || 'New Chat',
|
|
36
|
+
completed: false
|
|
37
|
+
};
|
|
38
|
+
try {
|
|
39
|
+
chatLog('Creating conversation:', { canvasId, componentId, request });
|
|
40
|
+
// Mock response
|
|
41
|
+
const mockConversation = {
|
|
42
|
+
id: `conv_${Date.now()}`,
|
|
43
|
+
title: request.title,
|
|
44
|
+
completed: request.completed,
|
|
45
|
+
createdAt: new Date(),
|
|
46
|
+
updatedAt: new Date(),
|
|
47
|
+
_unreadCount: 0,
|
|
48
|
+
_lastActivity: new Date(),
|
|
49
|
+
_isActive: false
|
|
50
|
+
};
|
|
51
|
+
return mockConversation;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error('Failed to create conversation:', error);
|
|
55
|
+
throw new Error('Failed to create conversation');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
114
58
|
/**
|
|
115
59
|
* Update an existing conversation
|
|
116
60
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
throw new Error('Update conversation not yet implemented - need context IDs');
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
};
|
|
61
|
+
async updateConversation(conversationId, updates) {
|
|
62
|
+
// We need to extract canvas and component IDs from the conversation
|
|
63
|
+
// This would typically be stored in the client state or passed differently
|
|
64
|
+
throw new Error('Update conversation not yet implemented - need context IDs');
|
|
65
|
+
}
|
|
126
66
|
/**
|
|
127
67
|
* Delete a conversation
|
|
128
68
|
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
throw new Error('Delete conversation not yet implemented - need context IDs');
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
};
|
|
69
|
+
async deleteConversation(conversationId) {
|
|
70
|
+
// Similar issue - need canvas and component IDs
|
|
71
|
+
throw new Error('Delete conversation not yet implemented - need context IDs');
|
|
72
|
+
}
|
|
137
73
|
/**
|
|
138
74
|
* Get all messages for a conversation
|
|
139
75
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
return [2 /*return*/];
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
};
|
|
76
|
+
async getMessages(conversationId) {
|
|
77
|
+
try {
|
|
78
|
+
chatLog('Getting messages for conversation:', conversationId);
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
console.error('Failed to get messages:', error);
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
155
86
|
/**
|
|
156
87
|
* Send a new message
|
|
157
88
|
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (!(i < data.attachments.length)) return [3 /*break*/, 10];
|
|
173
|
-
attachment = data.attachments[i];
|
|
174
|
-
if (!(attachment && typeof attachment === 'object' && 'file' in attachment)) return [3 /*break*/, 6];
|
|
175
|
-
input = attachment;
|
|
176
|
-
stableUrl = input.uploadedUrl;
|
|
177
|
-
_a = stableUrl;
|
|
178
|
-
if (_a) return [3 /*break*/, 5];
|
|
179
|
-
if (!input.file) return [3 /*break*/, 3];
|
|
180
|
-
return [4 /*yield*/, this.fileToDataUrl(input.file)];
|
|
181
|
-
case 2:
|
|
182
|
-
_b = _g.sent();
|
|
183
|
-
return [3 /*break*/, 4];
|
|
184
|
-
case 3:
|
|
185
|
-
_b = '';
|
|
186
|
-
_g.label = 4;
|
|
187
|
-
case 4:
|
|
188
|
-
_a = (_b);
|
|
189
|
-
_g.label = 5;
|
|
190
|
-
case 5:
|
|
191
|
-
url = _a;
|
|
89
|
+
async sendMessage(conversationId, data) {
|
|
90
|
+
try {
|
|
91
|
+
let processedAttachments = [];
|
|
92
|
+
if (data.attachments && data.attachments.length > 0) {
|
|
93
|
+
chatLog('Processing attachments:', data.attachments.length);
|
|
94
|
+
for (let i = 0; i < data.attachments.length; i++) {
|
|
95
|
+
const attachment = data.attachments[i];
|
|
96
|
+
if (attachment && typeof attachment === 'object' && 'file' in attachment) {
|
|
97
|
+
const input = attachment;
|
|
98
|
+
const isImage = (input.file?.type || '').startsWith('image/');
|
|
99
|
+
const stableUrl = input.uploadedUrl || (isImage ? input.preview : '') || (input.file && !isImage
|
|
100
|
+
? URL.createObjectURL(input.file)
|
|
101
|
+
: (input.preview || ''));
|
|
102
|
+
const url = stableUrl || (input.file && isImage ? await this.fileToDataUrl(input.file) : '');
|
|
192
103
|
processedAttachments.push({
|
|
193
|
-
id:
|
|
194
|
-
url
|
|
195
|
-
file_type:
|
|
196
|
-
file_name:
|
|
197
|
-
file_size:
|
|
104
|
+
id: `att_${Date.now()}_${i}_${Math.random().toString(36).substr(2, 9)}`,
|
|
105
|
+
url,
|
|
106
|
+
file_type: input.file?.type || 'image/png',
|
|
107
|
+
file_name: input.file?.name || 'attachment',
|
|
108
|
+
file_size: input.file?.size,
|
|
198
109
|
metadata: {
|
|
199
|
-
originalName:
|
|
110
|
+
originalName: input.file?.name,
|
|
200
111
|
uploadedAt: new Date().toISOString(),
|
|
201
112
|
storage: stableUrl ? 'upload-service' : 'inline-data-url',
|
|
202
113
|
},
|
|
203
114
|
created_at: new Date().toISOString(),
|
|
204
115
|
display_order: i + 1,
|
|
205
116
|
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (attachment instanceof File) {
|
|
120
|
+
const isImage = attachment.type.startsWith('image/');
|
|
121
|
+
const url = isImage
|
|
122
|
+
? await this.fileToDataUrl(attachment)
|
|
123
|
+
: URL.createObjectURL(attachment);
|
|
212
124
|
processedAttachments.push({
|
|
213
|
-
id:
|
|
214
|
-
url
|
|
125
|
+
id: `att_${Date.now()}_${i}_${Math.random().toString(36).substr(2, 9)}`,
|
|
126
|
+
url,
|
|
215
127
|
file_type: attachment.type,
|
|
216
128
|
file_name: attachment.name,
|
|
217
129
|
file_size: attachment.size,
|
|
@@ -223,130 +135,107 @@ var WidgeticChatService = /** @class */ (function () {
|
|
|
223
135
|
created_at: new Date().toISOString(),
|
|
224
136
|
display_order: i + 1,
|
|
225
137
|
});
|
|
226
|
-
|
|
227
|
-
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
228
140
|
processedAttachments.push(attachment);
|
|
229
|
-
|
|
230
|
-
case 9:
|
|
231
|
-
i++;
|
|
232
|
-
return [3 /*break*/, 1];
|
|
233
|
-
case 10:
|
|
234
|
-
request = {
|
|
235
|
-
messageContent: data.messageContent,
|
|
236
|
-
messageType: 'user',
|
|
237
|
-
attachments: processedAttachments
|
|
238
|
-
};
|
|
239
|
-
chatLog('Sending message:', { conversationId: conversationId, request: request });
|
|
240
|
-
mockMessage = {
|
|
241
|
-
id: "msg_".concat(Date.now(), "_").concat(Math.random().toString(36).substr(2, 9)),
|
|
242
|
-
conversationId: conversationId,
|
|
243
|
-
messageContent: data.messageContent,
|
|
244
|
-
messageType: 'user',
|
|
245
|
-
attachments: processedAttachments,
|
|
246
|
-
isCommit: false,
|
|
247
|
-
userId: 'test_user',
|
|
248
|
-
createdAt: new Date(),
|
|
249
|
-
updatedAt: new Date(),
|
|
250
|
-
_optimistic: false,
|
|
251
|
-
_failed: false,
|
|
252
|
-
_retryCount: 0
|
|
253
|
-
};
|
|
254
|
-
chatLog('Mock message created:', mockMessage);
|
|
255
|
-
return [2 /*return*/, mockMessage];
|
|
256
|
-
case 11:
|
|
257
|
-
error_1 = _g.sent();
|
|
258
|
-
console.error('Failed to send message:', error_1);
|
|
259
|
-
throw new Error('Failed to send message');
|
|
260
|
-
case 12: return [2 /*return*/];
|
|
141
|
+
}
|
|
261
142
|
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
143
|
+
}
|
|
144
|
+
const request = {
|
|
145
|
+
messageContent: data.messageContent,
|
|
146
|
+
messageType: 'user',
|
|
147
|
+
attachments: processedAttachments
|
|
148
|
+
};
|
|
149
|
+
chatLog('Sending message:', { conversationId, request });
|
|
150
|
+
// Mock response
|
|
151
|
+
const mockMessage = {
|
|
152
|
+
id: `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
153
|
+
conversationId,
|
|
154
|
+
messageContent: data.messageContent,
|
|
155
|
+
messageType: 'user',
|
|
156
|
+
attachments: processedAttachments,
|
|
157
|
+
isCommit: false,
|
|
158
|
+
userId: 'test_user',
|
|
159
|
+
createdAt: new Date(),
|
|
160
|
+
updatedAt: new Date(),
|
|
161
|
+
_optimistic: false,
|
|
162
|
+
_failed: false,
|
|
163
|
+
_retryCount: 0
|
|
164
|
+
};
|
|
165
|
+
chatLog('Mock message created:', mockMessage);
|
|
166
|
+
return mockMessage;
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
console.error('Failed to send message:', error);
|
|
170
|
+
throw new Error('Failed to send message');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
265
173
|
/**
|
|
266
174
|
* Update a message
|
|
267
175
|
*/
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
throw new Error('Update message not yet implemented');
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
};
|
|
176
|
+
async updateMessage(messageId, updates) {
|
|
177
|
+
chatLog('Update message not yet implemented:', messageId, updates);
|
|
178
|
+
throw new Error('Update message not yet implemented');
|
|
179
|
+
}
|
|
276
180
|
/**
|
|
277
181
|
* Delete a message
|
|
278
182
|
*/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
throw new Error('Delete message not yet implemented');
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
};
|
|
183
|
+
async deleteMessage(messageId) {
|
|
184
|
+
chatLog('Delete message not yet implemented:', messageId);
|
|
185
|
+
throw new Error('Delete message not yet implemented');
|
|
186
|
+
}
|
|
287
187
|
/**
|
|
288
188
|
* Read a file as a data URL (persistable in DB until upload service exists).
|
|
289
189
|
*/
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
reader.onerror = function () { return reject(reader.error); };
|
|
298
|
-
reader.readAsDataURL(file);
|
|
299
|
-
})];
|
|
300
|
-
});
|
|
190
|
+
async fileToDataUrl(file) {
|
|
191
|
+
chatLog('Reading attachment as data URL:', file.name);
|
|
192
|
+
return new Promise((resolve, reject) => {
|
|
193
|
+
const reader = new FileReader();
|
|
194
|
+
reader.onload = () => resolve(String(reader.result));
|
|
195
|
+
reader.onerror = () => reject(reader.error);
|
|
196
|
+
reader.readAsDataURL(file);
|
|
301
197
|
});
|
|
302
|
-
}
|
|
198
|
+
}
|
|
303
199
|
/** @deprecated Use fileToDataUrl — blob URLs are not reload-safe */
|
|
304
|
-
|
|
305
|
-
return
|
|
306
|
-
|
|
307
|
-
return [2 /*return*/, this.fileToDataUrl(file)];
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
};
|
|
200
|
+
async uploadFile(file) {
|
|
201
|
+
return this.fileToDataUrl(file);
|
|
202
|
+
}
|
|
311
203
|
/**
|
|
312
204
|
* Process AI response (placeholder for LLM integration)
|
|
313
205
|
*/
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
};
|
|
206
|
+
async processAIResponse(conversationId, message) {
|
|
207
|
+
// This would integrate with the AI service to generate responses
|
|
208
|
+
// For now, return a mock response
|
|
209
|
+
// Add a small delay to ensure unique timestamp
|
|
210
|
+
await new Promise(resolve => setTimeout(resolve, 10));
|
|
211
|
+
const aiResponse = {
|
|
212
|
+
...message,
|
|
213
|
+
id: `ai_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
214
|
+
messageType: 'assistant',
|
|
215
|
+
messageContent: `AI response to: ${message.messageContent || '[attachment only]'}`,
|
|
216
|
+
createdAt: new Date(),
|
|
217
|
+
updatedAt: new Date(),
|
|
218
|
+
userId: 'ai_assistant',
|
|
219
|
+
attachments: [], // AI response doesn't inherit user attachments
|
|
220
|
+
_optimistic: false,
|
|
221
|
+
_failed: false,
|
|
222
|
+
_retryCount: 0
|
|
223
|
+
};
|
|
224
|
+
chatLog('AI response generated:', aiResponse);
|
|
225
|
+
return aiResponse;
|
|
226
|
+
}
|
|
336
227
|
/**
|
|
337
228
|
* Parse context ID to extract canvas and component IDs.
|
|
338
229
|
* Supports "canvas_id:component_id" format or a single ID (used as both).
|
|
339
230
|
*/
|
|
340
|
-
|
|
341
|
-
|
|
231
|
+
parseContextId(contextId) {
|
|
232
|
+
const parts = contextId.split(':');
|
|
342
233
|
if (parts.length === 2) {
|
|
343
234
|
return [parts[0], parts[1]];
|
|
344
235
|
}
|
|
345
236
|
return [contextId, contextId];
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
}());
|
|
349
|
-
export { WidgeticChatService };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
350
239
|
/**
|
|
351
240
|
* Create a chat service instance with the given configuration
|
|
352
241
|
*/
|
|
@@ -24,6 +24,7 @@ export declare const chatStore: {
|
|
|
24
24
|
setMessages: (conversationId: string, messages: ChatMessage[]) => void;
|
|
25
25
|
updateMessageId: (conversationId: string, oldId: string, newId: string) => void;
|
|
26
26
|
updateMessageContent: (conversationId: string, messageId: string, messageContent: string) => void;
|
|
27
|
+
updateMessageAttachments: (conversationId: string, messageId: string, attachments: any[]) => void;
|
|
27
28
|
};
|
|
28
29
|
};
|
|
29
30
|
/**
|