@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/stores/chatStore.js
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
-
if (ar || !(i in from)) {
|
|
15
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
-
ar[i] = from[i];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
-
};
|
|
21
1
|
import { writable } from 'svelte/store';
|
|
22
2
|
import { chatLog } from '../utils/logger.js';
|
|
23
3
|
/**
|
|
24
4
|
* Initial state for the chat store
|
|
25
5
|
*/
|
|
26
|
-
|
|
6
|
+
const initialState = {
|
|
27
7
|
activeContext: {
|
|
28
8
|
contextId: null,
|
|
29
9
|
isExpanded: false
|
|
@@ -61,54 +41,124 @@ var initialState = {
|
|
|
61
41
|
* Create the chat store with rune-like reactive state
|
|
62
42
|
*/
|
|
63
43
|
function createChatStore() {
|
|
64
|
-
|
|
44
|
+
const { subscribe, set, update } = writable(initialState);
|
|
65
45
|
return {
|
|
66
|
-
subscribe
|
|
46
|
+
subscribe,
|
|
67
47
|
/**
|
|
68
48
|
* Dispatch actions to update the store
|
|
69
49
|
*/
|
|
70
|
-
dispatch:
|
|
71
|
-
update(
|
|
72
|
-
|
|
73
|
-
var _g;
|
|
74
|
-
chatLog("Chat Action: ".concat(action.type), action.payload);
|
|
50
|
+
dispatch: (action) => {
|
|
51
|
+
update(state => {
|
|
52
|
+
chatLog(`Chat Action: ${action.type}`, action.payload);
|
|
75
53
|
switch (action.type) {
|
|
76
54
|
case 'SET_ACTIVE_CONTEXT':
|
|
77
|
-
return
|
|
55
|
+
return {
|
|
56
|
+
...state,
|
|
57
|
+
activeContext: {
|
|
58
|
+
...state.activeContext,
|
|
59
|
+
contextId: action.payload.contextId,
|
|
60
|
+
isExpanded: action.payload.isExpanded ?? state.activeContext.isExpanded,
|
|
61
|
+
expandedAt: action.payload.contextId ? new Date() : undefined
|
|
62
|
+
}
|
|
63
|
+
};
|
|
78
64
|
case 'UPDATE_INPUT':
|
|
79
|
-
return
|
|
65
|
+
return {
|
|
66
|
+
...state,
|
|
67
|
+
input: {
|
|
68
|
+
...state.input,
|
|
69
|
+
...action.payload
|
|
70
|
+
}
|
|
71
|
+
};
|
|
80
72
|
case 'UPDATE_UI':
|
|
81
|
-
return
|
|
73
|
+
return {
|
|
74
|
+
...state,
|
|
75
|
+
ui: {
|
|
76
|
+
...state.ui,
|
|
77
|
+
...action.payload
|
|
78
|
+
}
|
|
79
|
+
};
|
|
82
80
|
case 'ADD_MESSAGE':
|
|
83
|
-
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
const { conversationId, message } = action.payload;
|
|
82
|
+
return {
|
|
83
|
+
...state,
|
|
84
|
+
messages: {
|
|
85
|
+
...state.messages,
|
|
86
|
+
byConversationId: {
|
|
87
|
+
...state.messages.byConversationId,
|
|
88
|
+
[conversationId]: [
|
|
89
|
+
...(state.messages.byConversationId[conversationId] || []),
|
|
90
|
+
message
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
87
95
|
case 'UPDATE_MESSAGE':
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
const { conversationId: convId, messageId, updates } = action.payload;
|
|
97
|
+
const existingMessages = state.messages.byConversationId[convId] || [];
|
|
98
|
+
return {
|
|
99
|
+
...state,
|
|
100
|
+
messages: {
|
|
101
|
+
...state.messages,
|
|
102
|
+
byConversationId: {
|
|
103
|
+
...state.messages.byConversationId,
|
|
104
|
+
[convId]: existingMessages.map(msg => msg.id === messageId ? { ...msg, ...updates } : msg)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
93
108
|
case 'ADD_CONVERSATION':
|
|
94
|
-
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
109
|
+
const { contextId, conversation } = action.payload;
|
|
110
|
+
return {
|
|
111
|
+
...state,
|
|
112
|
+
conversations: {
|
|
113
|
+
...state.conversations,
|
|
114
|
+
byContextId: {
|
|
115
|
+
...state.conversations.byContextId,
|
|
116
|
+
[contextId]: [
|
|
117
|
+
...(state.conversations.byContextId[contextId] || []),
|
|
118
|
+
conversation
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
98
123
|
case 'UPDATE_CONVERSATION':
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return
|
|
102
|
-
|
|
103
|
-
|
|
124
|
+
const { contextId: ctxId, conversationId: convIdUpd, updates: convUpdates } = action.payload;
|
|
125
|
+
const existingConversations = state.conversations.byContextId[ctxId] || [];
|
|
126
|
+
return {
|
|
127
|
+
...state,
|
|
128
|
+
conversations: {
|
|
129
|
+
...state.conversations,
|
|
130
|
+
byContextId: {
|
|
131
|
+
...state.conversations.byContextId,
|
|
132
|
+
[ctxId]: existingConversations.map(conv => conv.id === convIdUpd ? { ...conv, ...convUpdates } : conv)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
104
136
|
case 'SET_LOADING':
|
|
105
|
-
|
|
106
|
-
return
|
|
137
|
+
const { key, loading } = action.payload;
|
|
138
|
+
return {
|
|
139
|
+
...state,
|
|
140
|
+
messages: {
|
|
141
|
+
...state.messages,
|
|
142
|
+
isLoading: {
|
|
143
|
+
...state.messages.isLoading,
|
|
144
|
+
[key]: loading
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
};
|
|
107
148
|
case 'SET_ERROR':
|
|
108
|
-
|
|
109
|
-
return
|
|
149
|
+
const { key: errorKey, error } = action.payload;
|
|
150
|
+
return {
|
|
151
|
+
...state,
|
|
152
|
+
messages: {
|
|
153
|
+
...state.messages,
|
|
154
|
+
errors: {
|
|
155
|
+
...state.messages.errors,
|
|
156
|
+
[errorKey]: error
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
110
160
|
default:
|
|
111
|
-
chatLog(
|
|
161
|
+
chatLog(`Unknown action type: ${action.type}`);
|
|
112
162
|
return state;
|
|
113
163
|
}
|
|
114
164
|
});
|
|
@@ -116,64 +166,121 @@ function createChatStore() {
|
|
|
116
166
|
/**
|
|
117
167
|
* Reset the store to initial state
|
|
118
168
|
*/
|
|
119
|
-
reset:
|
|
169
|
+
reset: () => set(initialState),
|
|
120
170
|
/**
|
|
121
171
|
* Helper methods for common operations
|
|
122
172
|
*/
|
|
123
173
|
actions: {
|
|
124
|
-
setActiveContext:
|
|
125
|
-
update(
|
|
126
|
-
|
|
127
|
-
|
|
174
|
+
setActiveContext: (contextId, isExpanded) => {
|
|
175
|
+
update(state => ({
|
|
176
|
+
...state,
|
|
177
|
+
activeContext: {
|
|
178
|
+
contextId,
|
|
179
|
+
isExpanded: isExpanded ?? state.activeContext.isExpanded,
|
|
128
180
|
expandedAt: contextId ? new Date() : undefined
|
|
129
|
-
}
|
|
181
|
+
}
|
|
182
|
+
}));
|
|
130
183
|
},
|
|
131
|
-
updateInput:
|
|
132
|
-
update(
|
|
184
|
+
updateInput: (updates) => {
|
|
185
|
+
update(state => ({
|
|
186
|
+
...state,
|
|
187
|
+
input: { ...state.input, ...updates }
|
|
188
|
+
}));
|
|
133
189
|
},
|
|
134
|
-
updateUI:
|
|
135
|
-
update(
|
|
190
|
+
updateUI: (updates) => {
|
|
191
|
+
update(state => ({
|
|
192
|
+
...state,
|
|
193
|
+
ui: { ...state.ui, ...updates }
|
|
194
|
+
}));
|
|
136
195
|
},
|
|
137
|
-
addMessage:
|
|
138
|
-
update(
|
|
139
|
-
|
|
140
|
-
|
|
196
|
+
addMessage: (conversationId, message) => {
|
|
197
|
+
update(state => ({
|
|
198
|
+
...state,
|
|
199
|
+
messages: {
|
|
200
|
+
...state.messages,
|
|
201
|
+
byConversationId: {
|
|
202
|
+
...state.messages.byConversationId,
|
|
203
|
+
[conversationId]: [
|
|
204
|
+
...(state.messages.byConversationId[conversationId] || []),
|
|
141
205
|
message
|
|
142
|
-
]
|
|
143
|
-
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}));
|
|
144
210
|
},
|
|
145
|
-
setConversations:
|
|
146
|
-
update(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
211
|
+
setConversations: (contextId, conversations) => {
|
|
212
|
+
update(state => ({
|
|
213
|
+
...state,
|
|
214
|
+
conversations: {
|
|
215
|
+
...state.conversations,
|
|
216
|
+
byContextId: {
|
|
217
|
+
...state.conversations.byContextId,
|
|
218
|
+
[contextId]: conversations
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}));
|
|
222
|
+
},
|
|
223
|
+
setMessages: (conversationId, messages) => {
|
|
224
|
+
update(state => ({
|
|
225
|
+
...state,
|
|
226
|
+
messages: {
|
|
227
|
+
...state.messages,
|
|
228
|
+
byConversationId: {
|
|
229
|
+
...state.messages.byConversationId,
|
|
230
|
+
[conversationId]: messages
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}));
|
|
150
234
|
},
|
|
151
|
-
|
|
152
|
-
update(
|
|
153
|
-
|
|
154
|
-
|
|
235
|
+
updateMessageId: (conversationId, oldId, newId) => {
|
|
236
|
+
update(state => {
|
|
237
|
+
const msgs = state.messages.byConversationId[conversationId];
|
|
238
|
+
if (!msgs)
|
|
239
|
+
return state;
|
|
240
|
+
return {
|
|
241
|
+
...state,
|
|
242
|
+
messages: {
|
|
243
|
+
...state.messages,
|
|
244
|
+
byConversationId: {
|
|
245
|
+
...state.messages.byConversationId,
|
|
246
|
+
[conversationId]: msgs.map(msg => msg.id === oldId ? { ...msg, id: newId } : msg)
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
155
250
|
});
|
|
156
251
|
},
|
|
157
|
-
|
|
158
|
-
update(
|
|
159
|
-
|
|
160
|
-
var msgs = state.messages.byConversationId[conversationId];
|
|
252
|
+
updateMessageContent: (conversationId, messageId, messageContent) => {
|
|
253
|
+
update(state => {
|
|
254
|
+
const msgs = state.messages.byConversationId[conversationId];
|
|
161
255
|
if (!msgs)
|
|
162
256
|
return state;
|
|
163
|
-
return
|
|
164
|
-
|
|
165
|
-
|
|
257
|
+
return {
|
|
258
|
+
...state,
|
|
259
|
+
messages: {
|
|
260
|
+
...state.messages,
|
|
261
|
+
byConversationId: {
|
|
262
|
+
...state.messages.byConversationId,
|
|
263
|
+
[conversationId]: msgs.map(msg => msg.id === messageId ? { ...msg, messageContent } : msg)
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
};
|
|
166
267
|
});
|
|
167
268
|
},
|
|
168
|
-
|
|
169
|
-
update(
|
|
170
|
-
|
|
171
|
-
var msgs = state.messages.byConversationId[conversationId];
|
|
269
|
+
updateMessageAttachments: (conversationId, messageId, attachments) => {
|
|
270
|
+
update(state => {
|
|
271
|
+
const msgs = state.messages.byConversationId[conversationId];
|
|
172
272
|
if (!msgs)
|
|
173
273
|
return state;
|
|
174
|
-
return
|
|
175
|
-
|
|
176
|
-
|
|
274
|
+
return {
|
|
275
|
+
...state,
|
|
276
|
+
messages: {
|
|
277
|
+
...state.messages,
|
|
278
|
+
byConversationId: {
|
|
279
|
+
...state.messages.byConversationId,
|
|
280
|
+
[conversationId]: msgs.map(msg => msg.id === messageId ? { ...msg, attachments } : msg)
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
};
|
|
177
284
|
});
|
|
178
285
|
}
|
|
179
286
|
}
|
|
@@ -182,38 +289,32 @@ function createChatStore() {
|
|
|
182
289
|
/**
|
|
183
290
|
* Main chat store instance
|
|
184
291
|
*/
|
|
185
|
-
export
|
|
292
|
+
export const chatStore = createChatStore();
|
|
186
293
|
/**
|
|
187
294
|
* Derived stores for specific parts of the state
|
|
188
295
|
*/
|
|
189
|
-
export
|
|
190
|
-
subscribe:
|
|
191
|
-
return chatStore.subscribe(function (state) { return callback(state.activeContext); });
|
|
192
|
-
}
|
|
296
|
+
export const activeContext = {
|
|
297
|
+
subscribe: (callback) => chatStore.subscribe(state => callback(state.activeContext))
|
|
193
298
|
};
|
|
194
|
-
export
|
|
195
|
-
subscribe:
|
|
196
|
-
return chatStore.subscribe(function (state) { return callback(state.input); });
|
|
197
|
-
}
|
|
299
|
+
export const inputState = {
|
|
300
|
+
subscribe: (callback) => chatStore.subscribe(state => callback(state.input))
|
|
198
301
|
};
|
|
199
|
-
export
|
|
200
|
-
subscribe:
|
|
201
|
-
return chatStore.subscribe(function (state) { return callback(state.ui); });
|
|
202
|
-
}
|
|
302
|
+
export const uiState = {
|
|
303
|
+
subscribe: (callback) => chatStore.subscribe(state => callback(state.ui))
|
|
203
304
|
};
|
|
204
305
|
/**
|
|
205
306
|
* Reactive getters for current state
|
|
206
307
|
*/
|
|
207
|
-
export
|
|
208
|
-
|
|
209
|
-
chatStore.subscribe(
|
|
308
|
+
export const getCurrentState = () => {
|
|
309
|
+
let currentState;
|
|
310
|
+
chatStore.subscribe(state => { currentState = state; })();
|
|
210
311
|
return currentState;
|
|
211
312
|
};
|
|
212
|
-
export
|
|
213
|
-
|
|
313
|
+
export const getCurrentMessages = (conversationId) => {
|
|
314
|
+
const state = getCurrentState();
|
|
214
315
|
return state.messages.byConversationId[conversationId] || [];
|
|
215
316
|
};
|
|
216
|
-
export
|
|
217
|
-
|
|
317
|
+
export const getCurrentConversations = (contextId) => {
|
|
318
|
+
const state = getCurrentState();
|
|
218
319
|
return state.conversations.byContextId[contextId] || [];
|
|
219
320
|
};
|
package/dist/types/attachment.js
CHANGED
package/dist/types/config.d.ts
CHANGED
|
@@ -39,6 +39,11 @@ export interface ChatConfig {
|
|
|
39
39
|
aiSuggestions: boolean;
|
|
40
40
|
screenRecording: boolean;
|
|
41
41
|
restoreCheckpoint: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Mark conversation complete / active. Off by default — widget codegen
|
|
44
|
+
* does not persist this status (parent must pass onCompletionToggle).
|
|
45
|
+
*/
|
|
46
|
+
markComplete?: boolean;
|
|
42
47
|
/**
|
|
43
48
|
* Debug: auto-detect code patterns in plain-text messages and render them
|
|
44
49
|
* as syntax-highlighted code blocks (even without explicit ``` fences).
|
package/dist/types/config.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ContextType } from './context.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Default configuration values
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export const DEFAULT_CHAT_CONFIG = {
|
|
6
6
|
api: {
|
|
7
7
|
timeout: 30000,
|
|
8
8
|
},
|
|
@@ -46,6 +46,7 @@ export var DEFAULT_CHAT_CONFIG = {
|
|
|
46
46
|
aiSuggestions: true,
|
|
47
47
|
screenRecording: false,
|
|
48
48
|
restoreCheckpoint: false,
|
|
49
|
+
markComplete: false,
|
|
49
50
|
autoCodeDetection: false,
|
|
50
51
|
showGenerationSummaries: false,
|
|
51
52
|
},
|