@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.
@@ -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
- var initialState = {
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
- var _a = writable(initialState), subscribe = _a.subscribe, set = _a.set, update = _a.update;
44
+ const { subscribe, set, update } = writable(initialState);
65
45
  return {
66
- subscribe: subscribe,
46
+ subscribe,
67
47
  /**
68
48
  * Dispatch actions to update the store
69
49
  */
70
- dispatch: function (action) {
71
- update(function (state) {
72
- var _a, _b, _c, _d, _e, _f;
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 __assign(__assign({}, state), { activeContext: __assign(__assign({}, state.activeContext), { contextId: action.payload.contextId, isExpanded: (_g = action.payload.isExpanded) !== null && _g !== void 0 ? _g : state.activeContext.isExpanded, expandedAt: action.payload.contextId ? new Date() : undefined }) });
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 __assign(__assign({}, state), { input: __assign(__assign({}, state.input), action.payload) });
65
+ return {
66
+ ...state,
67
+ input: {
68
+ ...state.input,
69
+ ...action.payload
70
+ }
71
+ };
80
72
  case 'UPDATE_UI':
81
- return __assign(__assign({}, state), { ui: __assign(__assign({}, state.ui), action.payload) });
73
+ return {
74
+ ...state,
75
+ ui: {
76
+ ...state.ui,
77
+ ...action.payload
78
+ }
79
+ };
82
80
  case 'ADD_MESSAGE':
83
- var _h = action.payload, conversationId = _h.conversationId, message = _h.message;
84
- return __assign(__assign({}, state), { messages: __assign(__assign({}, state.messages), { byConversationId: __assign(__assign({}, state.messages.byConversationId), (_a = {}, _a[conversationId] = __spreadArray(__spreadArray([], (state.messages.byConversationId[conversationId] || []), true), [
85
- message
86
- ], false), _a)) }) });
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
- var _j = action.payload, convId = _j.conversationId, messageId_1 = _j.messageId, updates_1 = _j.updates;
89
- var existingMessages = state.messages.byConversationId[convId] || [];
90
- return __assign(__assign({}, state), { messages: __assign(__assign({}, state.messages), { byConversationId: __assign(__assign({}, state.messages.byConversationId), (_b = {}, _b[convId] = existingMessages.map(function (msg) {
91
- return msg.id === messageId_1 ? __assign(__assign({}, msg), updates_1) : msg;
92
- }), _b)) }) });
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
- var _k = action.payload, contextId = _k.contextId, conversation = _k.conversation;
95
- return __assign(__assign({}, state), { conversations: __assign(__assign({}, state.conversations), { byContextId: __assign(__assign({}, state.conversations.byContextId), (_c = {}, _c[contextId] = __spreadArray(__spreadArray([], (state.conversations.byContextId[contextId] || []), true), [
96
- conversation
97
- ], false), _c)) }) });
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
- var _l = action.payload, ctxId = _l.contextId, convIdUpd_1 = _l.conversationId, convUpdates_1 = _l.updates;
100
- var existingConversations = state.conversations.byContextId[ctxId] || [];
101
- return __assign(__assign({}, state), { conversations: __assign(__assign({}, state.conversations), { byContextId: __assign(__assign({}, state.conversations.byContextId), (_d = {}, _d[ctxId] = existingConversations.map(function (conv) {
102
- return conv.id === convIdUpd_1 ? __assign(__assign({}, conv), convUpdates_1) : conv;
103
- }), _d)) }) });
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
- var _m = action.payload, key = _m.key, loading = _m.loading;
106
- return __assign(__assign({}, state), { messages: __assign(__assign({}, state.messages), { isLoading: __assign(__assign({}, state.messages.isLoading), (_e = {}, _e[key] = loading, _e)) }) });
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
- var _o = action.payload, errorKey = _o.key, error = _o.error;
109
- return __assign(__assign({}, state), { messages: __assign(__assign({}, state.messages), { errors: __assign(__assign({}, state.messages.errors), (_f = {}, _f[errorKey] = error, _f)) }) });
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("Unknown action type: ".concat(action.type));
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: function () { return set(initialState); },
169
+ reset: () => set(initialState),
120
170
  /**
121
171
  * Helper methods for common operations
122
172
  */
123
173
  actions: {
124
- setActiveContext: function (contextId, isExpanded) {
125
- update(function (state) { return (__assign(__assign({}, state), { activeContext: {
126
- contextId: contextId,
127
- isExpanded: isExpanded !== null && isExpanded !== void 0 ? isExpanded : state.activeContext.isExpanded,
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: function (updates) {
132
- update(function (state) { return (__assign(__assign({}, state), { input: __assign(__assign({}, state.input), updates) })); });
184
+ updateInput: (updates) => {
185
+ update(state => ({
186
+ ...state,
187
+ input: { ...state.input, ...updates }
188
+ }));
133
189
  },
134
- updateUI: function (updates) {
135
- update(function (state) { return (__assign(__assign({}, state), { ui: __assign(__assign({}, state.ui), updates) })); });
190
+ updateUI: (updates) => {
191
+ update(state => ({
192
+ ...state,
193
+ ui: { ...state.ui, ...updates }
194
+ }));
136
195
  },
137
- addMessage: function (conversationId, message) {
138
- update(function (state) {
139
- var _a;
140
- return (__assign(__assign({}, state), { messages: __assign(__assign({}, state.messages), { byConversationId: __assign(__assign({}, state.messages.byConversationId), (_a = {}, _a[conversationId] = __spreadArray(__spreadArray([], (state.messages.byConversationId[conversationId] || []), true), [
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
- ], false), _a)) }) }));
143
- });
206
+ ]
207
+ }
208
+ }
209
+ }));
144
210
  },
145
- setConversations: function (contextId, conversations) {
146
- update(function (state) {
147
- var _a;
148
- return (__assign(__assign({}, state), { conversations: __assign(__assign({}, state.conversations), { byContextId: __assign(__assign({}, state.conversations.byContextId), (_a = {}, _a[contextId] = conversations, _a)) }) }));
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
- setMessages: function (conversationId, messages) {
152
- update(function (state) {
153
- var _a;
154
- return (__assign(__assign({}, state), { messages: __assign(__assign({}, state.messages), { byConversationId: __assign(__assign({}, state.messages.byConversationId), (_a = {}, _a[conversationId] = messages, _a)) }) }));
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
- updateMessageId: function (conversationId, oldId, newId) {
158
- update(function (state) {
159
- var _a;
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 __assign(__assign({}, state), { messages: __assign(__assign({}, state.messages), { byConversationId: __assign(__assign({}, state.messages.byConversationId), (_a = {}, _a[conversationId] = msgs.map(function (msg) {
164
- return msg.id === oldId ? __assign(__assign({}, msg), { id: newId }) : msg;
165
- }), _a)) }) });
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
- updateMessageContent: function (conversationId, messageId, messageContent) {
169
- update(function (state) {
170
- var _a;
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 __assign(__assign({}, state), { messages: __assign(__assign({}, state.messages), { byConversationId: __assign(__assign({}, state.messages.byConversationId), (_a = {}, _a[conversationId] = msgs.map(function (msg) {
175
- return msg.id === messageId ? __assign(__assign({}, msg), { messageContent: messageContent }) : msg;
176
- }), _a)) }) });
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 var chatStore = createChatStore();
292
+ export const chatStore = createChatStore();
186
293
  /**
187
294
  * Derived stores for specific parts of the state
188
295
  */
189
- export var activeContext = {
190
- subscribe: function (callback) {
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 var inputState = {
195
- subscribe: function (callback) {
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 var uiState = {
200
- subscribe: function (callback) {
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 var getCurrentState = function () {
208
- var currentState;
209
- chatStore.subscribe(function (state) { currentState = state; })();
308
+ export const getCurrentState = () => {
309
+ let currentState;
310
+ chatStore.subscribe(state => { currentState = state; })();
210
311
  return currentState;
211
312
  };
212
- export var getCurrentMessages = function (conversationId) {
213
- var state = getCurrentState();
313
+ export const getCurrentMessages = (conversationId) => {
314
+ const state = getCurrentState();
214
315
  return state.messages.byConversationId[conversationId] || [];
215
316
  };
216
- export var getCurrentConversations = function (contextId) {
217
- var state = getCurrentState();
317
+ export const getCurrentConversations = (contextId) => {
318
+ const state = getCurrentState();
218
319
  return state.conversations.byContextId[contextId] || [];
219
320
  };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Supported file types configuration
3
3
  */
4
- export var FILE_TYPE_CONFIG = {
4
+ export const FILE_TYPE_CONFIG = {
5
5
  image: {
6
6
  type: 'image',
7
7
  icon: 'image',
@@ -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).
@@ -2,7 +2,7 @@ import { ContextType } from './context.js';
2
2
  /**
3
3
  * Default configuration values
4
4
  */
5
- export var DEFAULT_CHAT_CONFIG = {
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
  },