@messenger-box/tailwind-ui-inbox 10.0.3-alpha.144 → 10.0.3-alpha.158
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/CHANGELOG.md +32 -0
- package/lib/components/AIAgent/AIAgent.d.ts.map +1 -1
- package/lib/components/AIAgent/AIAgent.js +1 -55
- package/lib/components/AIAgent/AIAgent.js.map +1 -1
- package/lib/components/InboxMessage/message-widgets/ErrorFixCard.d.ts +1 -2
- package/lib/components/InboxMessage/message-widgets/ErrorFixCard.d.ts.map +1 -1
- package/lib/components/InboxMessage/message-widgets/ErrorFixCard.js.map +1 -1
- package/lib/components/InboxMessage/message-widgets/ModernMessageGroup.d.ts +2 -2
- package/lib/components/InboxMessage/message-widgets/ModernMessageGroup.d.ts.map +1 -1
- package/lib/components/ModelConfigPanel.d.ts +11 -0
- package/lib/components/ModelConfigPanel.d.ts.map +1 -1
- package/lib/components/ModelConfigPanel.js +29 -2
- package/lib/components/ModelConfigPanel.js.map +1 -1
- package/lib/components/filler-components/RightSiderBar.d.ts +1 -28
- package/lib/components/filler-components/RightSiderBar.d.ts.map +1 -1
- package/lib/components/filler-components/RightSiderBar.js +531 -458
- package/lib/components/filler-components/RightSiderBar.js.map +1 -1
- package/lib/container/Inbox.js +1 -1
- package/lib/container/Inbox.js.map +1 -1
- package/lib/container/ServiceInbox.js +1 -1
- package/lib/container/ServiceInbox.js.map +1 -1
- package/lib/container/TestInboxWithAiLoader.d.ts.map +1 -1
- package/lib/container/TestInboxWithAiLoader.js +1 -11
- package/lib/container/TestInboxWithAiLoader.js.map +1 -1
- package/lib/container/ThreadMessages.js +1 -1
- package/lib/container/ThreadMessages.js.map +1 -1
- package/lib/container/ThreadMessagesInbox.js +1 -1
- package/lib/container/ThreadMessagesInbox.js.map +1 -1
- package/lib/container/Threads.js +1 -1
- package/lib/container/Threads.js.map +1 -1
- package/lib/hooks/index.d.ts +0 -1
- package/lib/hooks/index.d.ts.map +1 -1
- package/lib/hooks/usePersistentModelConfig.d.ts +1 -0
- package/lib/hooks/usePersistentModelConfig.d.ts.map +1 -1
- package/lib/hooks/usePersistentModelConfig.js +1 -0
- package/lib/hooks/usePersistentModelConfig.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/module.js +1 -1
- package/lib/module.js.map +1 -1
- package/lib/templates/InboxWithAi.d.ts.map +1 -1
- package/lib/templates/InboxWithAi.js +2 -15
- package/lib/templates/InboxWithAi.js.map +1 -1
- package/lib/templates/InboxWithAi.tsx +2 -24
- package/package.json +4 -4
- package/src/components/AIAgent/AIAgent.tsx +3 -54
- package/src/components/InboxMessage/message-widgets/ErrorFixCard.tsx +1 -2
- package/src/components/InboxMessage/message-widgets/ModernMessageGroup.tsx +2 -2
- package/src/components/ModelConfigPanel.tsx +59 -0
- package/src/components/filler-components/RightSiderBar.tsx +570 -566
- package/src/container/TestInboxWithAiLoader.tsx +0 -8
- package/src/hooks/index.ts +0 -1
- package/src/hooks/usePersistentModelConfig.ts +2 -0
- package/src/templates/InboxWithAi.tsx +2 -24
- package/lib/components/live-code-editor/hybrid-live-editor.js +0 -68
- package/lib/components/live-code-editor/hybrid-live-editor.js.map +0 -1
- package/lib/components/live-code-editor/live-code-editor.js +0 -207
- package/lib/components/live-code-editor/live-code-editor.js.map +0 -1
- package/lib/hooks/use-file-sync.d.ts +0 -16
- package/lib/hooks/use-file-sync.d.ts.map +0 -1
- package/lib/hooks/use-file-sync.js +0 -63
- package/lib/hooks/use-file-sync.js.map +0 -1
- package/lib/utils/utils.js +0 -3
- package/lib/utils/utils.js.map +0 -1
- package/lib/xstate/rightSidebar.machine.js +0 -325
- package/lib/xstate/rightSidebar.machine.js.map +0 -1
- package/src/hooks/use-file-sync.ts +0 -91
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
import {createMachine,assign,fromPromise}from'xstate';// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
-
const rightSidebarMachine = createMachine({
|
|
3
|
-
id: 'rightSidebar',
|
|
4
|
-
types: {},
|
|
5
|
-
context: ({
|
|
6
|
-
input
|
|
7
|
-
}) => ({
|
|
8
|
-
channelId: input?.channelId ?? '',
|
|
9
|
-
isMinimized: input?.isMinimized ?? false,
|
|
10
|
-
windowWidth: input?.windowWidth ?? 0,
|
|
11
|
-
windowHeight: input?.windowHeight ?? 0,
|
|
12
|
-
isLoading: input?.isLoading ?? false,
|
|
13
|
-
activeFragment: input?.activeFragment ?? null,
|
|
14
|
-
currentFiles: input?.currentFiles ?? {},
|
|
15
|
-
canvasLayers: input?.canvasLayers ?? [],
|
|
16
|
-
previewStatus: input?.previewStatus ?? null
|
|
17
|
-
}),
|
|
18
|
-
initial: 'idle',
|
|
19
|
-
states: {
|
|
20
|
-
idle: {
|
|
21
|
-
on: {
|
|
22
|
-
UPDATE: {
|
|
23
|
-
actions: assign(({
|
|
24
|
-
context,
|
|
25
|
-
event
|
|
26
|
-
}) => ({
|
|
27
|
-
...context,
|
|
28
|
-
...(event.value || {})
|
|
29
|
-
}))
|
|
30
|
-
},
|
|
31
|
-
SET_FRAGMENT: {
|
|
32
|
-
actions: assign(({
|
|
33
|
-
context,
|
|
34
|
-
event
|
|
35
|
-
}) => ({
|
|
36
|
-
...context,
|
|
37
|
-
activeFragment: event.fragment,
|
|
38
|
-
currentFiles: event.fragment?.files || context.currentFiles,
|
|
39
|
-
canvasLayers: event.fragment?.canvasLayers || context.canvasLayers,
|
|
40
|
-
// Don't set previewStatus to 'checking' automatically - only probe when explicitly needed
|
|
41
|
-
previewStatus: null
|
|
42
|
-
}))
|
|
43
|
-
},
|
|
44
|
-
PROBE: 'probing',
|
|
45
|
-
SET_LOADING: {
|
|
46
|
-
actions: assign(({
|
|
47
|
-
context,
|
|
48
|
-
event
|
|
49
|
-
}) => ({
|
|
50
|
-
...context,
|
|
51
|
-
isLoading: event.isLoading
|
|
52
|
-
}))
|
|
53
|
-
},
|
|
54
|
-
CLEAR_PREVIEW_STATUS: {
|
|
55
|
-
actions: assign(({
|
|
56
|
-
context
|
|
57
|
-
}) => ({
|
|
58
|
-
...context,
|
|
59
|
-
previewStatus: null
|
|
60
|
-
}))
|
|
61
|
-
},
|
|
62
|
-
RECREATE_SANDBOX: [{
|
|
63
|
-
// Only transition if we're not already recreating
|
|
64
|
-
guard: ({
|
|
65
|
-
context
|
|
66
|
-
}) => {
|
|
67
|
-
// Check if we have a fragment ID to recreate
|
|
68
|
-
const hasFragmentId = !!context.activeFragment?.id;
|
|
69
|
-
if (!hasFragmentId) {
|
|
70
|
-
console.log('🚫 RECREATE_SANDBOX: No fragment ID, ignoring');
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
return true;
|
|
74
|
-
},
|
|
75
|
-
target: 'recreating',
|
|
76
|
-
actions: assign(({
|
|
77
|
-
context,
|
|
78
|
-
event
|
|
79
|
-
}) => {
|
|
80
|
-
const recreateEvent = event;
|
|
81
|
-
console.log('🎯 RECREATE_SANDBOX event received and accepted:', {
|
|
82
|
-
id: recreateEvent.id,
|
|
83
|
-
fragmentId: context.activeFragment?.id
|
|
84
|
-
});
|
|
85
|
-
return context;
|
|
86
|
-
})
|
|
87
|
-
}, {
|
|
88
|
-
// If guard fails or already recreating, just log and stay in current state
|
|
89
|
-
actions: ({
|
|
90
|
-
context,
|
|
91
|
-
event
|
|
92
|
-
}) => {
|
|
93
|
-
const recreateEvent = event;
|
|
94
|
-
console.log('⏭️ RECREATE_SANDBOX ignored (already recreating or no fragment):', {
|
|
95
|
-
id: recreateEvent.id,
|
|
96
|
-
fragmentId: context.activeFragment?.id
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}]
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
probing: {
|
|
103
|
-
invoke: {
|
|
104
|
-
id: 'probeUrl',
|
|
105
|
-
src: 'probeUrl',
|
|
106
|
-
input: ({
|
|
107
|
-
context,
|
|
108
|
-
event
|
|
109
|
-
}) => {
|
|
110
|
-
const probeEvent = event;
|
|
111
|
-
return {
|
|
112
|
-
url: probeEvent.url ?? context.activeFragment?.sandboxUrl,
|
|
113
|
-
fragmentId: probeEvent.fragmentId ?? context.activeFragment?.id
|
|
114
|
-
};
|
|
115
|
-
},
|
|
116
|
-
onDone: {
|
|
117
|
-
target: 'idle',
|
|
118
|
-
actions: assign(({
|
|
119
|
-
context
|
|
120
|
-
}) => ({
|
|
121
|
-
...context,
|
|
122
|
-
previewStatus: null,
|
|
123
|
-
isLoading: false
|
|
124
|
-
}))
|
|
125
|
-
},
|
|
126
|
-
onError: [{
|
|
127
|
-
// Only recreate if we have a fragment ID AND the error suggests the sandbox is truly unavailable
|
|
128
|
-
// Don't recreate on transient network errors (timeouts, CORS, etc.)
|
|
129
|
-
guard: ({
|
|
130
|
-
context,
|
|
131
|
-
event
|
|
132
|
-
}) => {
|
|
133
|
-
if (!context.activeFragment?.id) {
|
|
134
|
-
console.log('🚫 Guard: No fragment ID, skipping recreation');
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
const errorMessage = event.error instanceof Error ? event.error.message : String(event.error);
|
|
138
|
-
// Check for explicit HTTP status codes (4xx, 5xx)
|
|
139
|
-
const isServerError = /^[45]\d{2}/.test(errorMessage);
|
|
140
|
-
// Also check for CORS/network errors that likely indicate expired sandbox (502)
|
|
141
|
-
// CORS errors on sandbox URLs usually mean the sandbox is expired/down
|
|
142
|
-
const isCorsNetworkError = errorMessage.includes('502 CORS/Network Error') || errorMessage.includes('Failed to fetch') || errorMessage.includes('CORS') || errorMessage.includes('NetworkError') || errorMessage.includes('Network request failed');
|
|
143
|
-
const willRecreate = isServerError || isCorsNetworkError;
|
|
144
|
-
console.log('🔍 Guard check:', {
|
|
145
|
-
errorMessage,
|
|
146
|
-
isServerError,
|
|
147
|
-
isCorsNetworkError,
|
|
148
|
-
willRecreate
|
|
149
|
-
});
|
|
150
|
-
return willRecreate;
|
|
151
|
-
},
|
|
152
|
-
target: 'recreating',
|
|
153
|
-
actions: assign(({
|
|
154
|
-
context,
|
|
155
|
-
event
|
|
156
|
-
}) => {
|
|
157
|
-
console.log('🔄 Transitioning to recreating state:', {
|
|
158
|
-
fragmentId: context.activeFragment?.id,
|
|
159
|
-
error: event.error instanceof Error ? event.error.message : String(event.error)
|
|
160
|
-
});
|
|
161
|
-
return {
|
|
162
|
-
...context,
|
|
163
|
-
previewStatus: {
|
|
164
|
-
status: 'error',
|
|
165
|
-
message: event.error instanceof Error ? event.error.message : 'Network error'
|
|
166
|
-
},
|
|
167
|
-
isLoading: true
|
|
168
|
-
};
|
|
169
|
-
})
|
|
170
|
-
}, {
|
|
171
|
-
// For other errors (network, CORS, timeout), just show error but don't recreate
|
|
172
|
-
target: 'idle',
|
|
173
|
-
actions: assign(({
|
|
174
|
-
context,
|
|
175
|
-
event
|
|
176
|
-
}) => ({
|
|
177
|
-
...context,
|
|
178
|
-
previewStatus: {
|
|
179
|
-
status: 'error',
|
|
180
|
-
message: event.error instanceof Error ? event.error.message : 'Network error'
|
|
181
|
-
},
|
|
182
|
-
isLoading: false
|
|
183
|
-
}))
|
|
184
|
-
}]
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
recreating: {
|
|
188
|
-
invoke: {
|
|
189
|
-
id: 'recreateSandbox',
|
|
190
|
-
src: 'recreateSandbox',
|
|
191
|
-
input: ({
|
|
192
|
-
context,
|
|
193
|
-
event
|
|
194
|
-
}) => {
|
|
195
|
-
const recreateEvent = event;
|
|
196
|
-
const id = recreateEvent.id ?? context.activeFragment?.id ?? '';
|
|
197
|
-
console.log('📥 recreateSandbox input:', {
|
|
198
|
-
id,
|
|
199
|
-
hasRecreateEventId: !!recreateEvent.id,
|
|
200
|
-
hasActiveFragmentId: !!context.activeFragment?.id,
|
|
201
|
-
activeFragmentId: context.activeFragment?.id
|
|
202
|
-
});
|
|
203
|
-
return {
|
|
204
|
-
id
|
|
205
|
-
};
|
|
206
|
-
},
|
|
207
|
-
onDone: {
|
|
208
|
-
target: 'idle',
|
|
209
|
-
actions: assign(({
|
|
210
|
-
context
|
|
211
|
-
}) => ({
|
|
212
|
-
...context,
|
|
213
|
-
isLoading: false,
|
|
214
|
-
previewStatus: {
|
|
215
|
-
status: 'checking'
|
|
216
|
-
}
|
|
217
|
-
}))
|
|
218
|
-
},
|
|
219
|
-
onError: {
|
|
220
|
-
target: 'idle',
|
|
221
|
-
actions: assign(({
|
|
222
|
-
context,
|
|
223
|
-
event
|
|
224
|
-
}) => ({
|
|
225
|
-
...context,
|
|
226
|
-
isLoading: false,
|
|
227
|
-
previewStatus: {
|
|
228
|
-
status: 'error',
|
|
229
|
-
message: event.error instanceof Error ? event.error.message : 'Recreate failed'
|
|
230
|
-
}
|
|
231
|
-
}))
|
|
232
|
-
}
|
|
233
|
-
},
|
|
234
|
-
on: {
|
|
235
|
-
COMPLETE_RECREATION: {
|
|
236
|
-
target: 'idle',
|
|
237
|
-
actions: assign(({
|
|
238
|
-
context
|
|
239
|
-
}) => ({
|
|
240
|
-
...context,
|
|
241
|
-
isLoading: false,
|
|
242
|
-
previewStatus: null
|
|
243
|
-
}))
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}).provide({
|
|
249
|
-
actors: {
|
|
250
|
-
probeUrl: fromPromise(async ({
|
|
251
|
-
input
|
|
252
|
-
}) => {
|
|
253
|
-
const {
|
|
254
|
-
url
|
|
255
|
-
} = input;
|
|
256
|
-
console.log('🔍 probeUrl actor called with URL:', url);
|
|
257
|
-
if (!url) {
|
|
258
|
-
throw new Error('No URL provided for probing');
|
|
259
|
-
}
|
|
260
|
-
const controller = new AbortController();
|
|
261
|
-
const timeoutId = setTimeout(() => controller.abort(), 10000);
|
|
262
|
-
try {
|
|
263
|
-
console.log('📡 Fetching URL to probe:', url);
|
|
264
|
-
const res = await fetch(url, {
|
|
265
|
-
method: 'GET',
|
|
266
|
-
mode: 'cors',
|
|
267
|
-
redirect: 'follow',
|
|
268
|
-
signal: controller.signal
|
|
269
|
-
});
|
|
270
|
-
clearTimeout(timeoutId);
|
|
271
|
-
console.log('📊 Probe response status:', res.status, res.statusText);
|
|
272
|
-
// Check for HTTP error status codes (4xx, 5xx)
|
|
273
|
-
if (!res.ok) {
|
|
274
|
-
const statusCode = res.status;
|
|
275
|
-
const statusText = res.statusText || 'Unknown Error';
|
|
276
|
-
const errorMessage = `${statusCode} ${statusText}`;
|
|
277
|
-
console.log('❌ Probe detected error:', errorMessage);
|
|
278
|
-
// Throw error with status code format that matches the guard regex: /^[45]\d{2}/
|
|
279
|
-
throw new Error(errorMessage);
|
|
280
|
-
}
|
|
281
|
-
console.log('✅ Probe successful - URL is accessible');
|
|
282
|
-
return {
|
|
283
|
-
ok: true
|
|
284
|
-
};
|
|
285
|
-
} catch (error) {
|
|
286
|
-
clearTimeout(timeoutId);
|
|
287
|
-
// If it's an abort (timeout), don't treat as server error
|
|
288
|
-
if (error instanceof Error && error.name === 'AbortError') {
|
|
289
|
-
throw new Error('TIMEOUT Request timeout');
|
|
290
|
-
}
|
|
291
|
-
// If it's already a formatted error (from res.ok check), rethrow it
|
|
292
|
-
if (error instanceof Error && /^\d{3}/.test(error.message)) {
|
|
293
|
-
throw error;
|
|
294
|
-
}
|
|
295
|
-
// Handle CORS/network errors - these often mask 502 errors from expired sandboxes
|
|
296
|
-
// When we get a CORS error or "Failed to fetch", it's likely because:
|
|
297
|
-
// 1. The sandbox is expired (502) and the server isn't responding properly
|
|
298
|
-
// 2. The sandbox is down and can't set CORS headers
|
|
299
|
-
// We'll throw a special error that the guard can recognize
|
|
300
|
-
if (error instanceof Error) {
|
|
301
|
-
const isCorsError = error.message.includes('Failed to fetch') || error.message.includes('CORS') || error.message.includes('NetworkError') || error.message.includes('Network request failed');
|
|
302
|
-
if (isCorsError) {
|
|
303
|
-
console.log('⚠️ CORS/Network error detected - likely expired sandbox (502):', error.message);
|
|
304
|
-
// Throw as 502 error so guard will match it
|
|
305
|
-
throw new Error('502 CORS/Network Error - Sandbox likely expired');
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
// For other network errors, throw as-is and let guard decide
|
|
309
|
-
throw error;
|
|
310
|
-
}
|
|
311
|
-
}),
|
|
312
|
-
recreateSandbox: fromPromise(async ({
|
|
313
|
-
input
|
|
314
|
-
}) => {
|
|
315
|
-
// Placeholder actor: implement by injecting via provide in component if needed
|
|
316
|
-
const {
|
|
317
|
-
id
|
|
318
|
-
} = input;
|
|
319
|
-
console.log('recreateSandbox actor invoked for id:', id);
|
|
320
|
-
return {
|
|
321
|
-
success: true
|
|
322
|
-
};
|
|
323
|
-
})
|
|
324
|
-
}
|
|
325
|
-
});export{rightSidebarMachine};//# sourceMappingURL=rightSidebar.machine.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rightSidebar.machine.js","sources":["../../src/xstate/rightSidebar.machine.ts"],"sourcesContent":[null],"names":[],"mappings":"sDAAA;AAIO,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAC7C,EAAA,EAAA,EAAE,cAAE;AACJ,EAAA,KAAA,EAAK,EAAE;SAKP,EAAO,CAAA;AACH,IAAA;AACA,GAAA,MAAA;AACA,IAAA,SAAA,EAAA,KAAW,EAAE,SAAO,IAAA,EAAA;AACpB,IAAA,WAAA,EAAA,KAAc,EAAA,WAAO,IAAA;AACrB,IAAA,WAAA,EAAS,KAAE,EAAK,WAAW,IAAI,CAAA;AAC/B,IAAA,YAAA,EAAA,KAAc,EAAE,YAAO,IAAA,CAAA;AACvB,IAAA,SAAA,EAAA,KAAY,EAAE,SAAO,IAAA,KAAA;AACrB,IAAA,cAAA,EAAY,KAAE,EAAK,cAAc,IAAI,IAAE;AACvC,IAAA,YAAA,EAAA,KAAe,EAAA,YAAO,IAAA,EAAa;gBACrC,EAAA,KAAA,EAAA,YAAA,IAAA,EAAA;AACF,IAAA,aAAS,EAAM,KAAA,EAAA,aAAA,IAAA;AACf,GAAA,CAAA;AACI,EAAA,OAAA,EAAA,MAAM;AACF,EAAA,MAAA,EAAA;AACI,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AA;AACA,YAAA;iBACH;AAED,YAAA,GAAA,OAAA;AACA,YAAA,SAAA,EAAO,KAAI;YACf,aAAC,EAAA;YAAC;;;;AAKM;;;AAIJ,IAAA,QAAA,EAAA,WAAS,CAAA,OAAA;AACL,MAAA;;;;;iBAMJ,CAAA,oCAAA,EAAA,GAAA,CAAA;gBACA;AACA,QAAA,MAAA,IAAA,KAAI,CAAA,6BAAyB,CAAA;;AAGrB,MAAA,MAAA,UAAA,GAAA,IAAK,eAAS,EAAQ;AACtB,MAAA,MAAA,SAAA,GAAA,UAAM,CAAA,MAAQ,oBAAuB,KAAC,CAAA;AACtC,MAAA,IAAA;oBAEJ,2BAAkB,EAAA,GAAA,CAAA;0BACd,KAAO,CAAC,GAAG,EAAC;;AAEZ,UAAA,IAAA,EAAA,MAAA;oBACJ,QAAC;gBACL,EAAC,UAAA,CAAA;;AAGD,QAAA,YAAA,CAAA,SAAY,CAAA;eACf,CAAA,GAAA,CAAA,2BAAA,EAAA,GAAA,CAAA,MAAA,EAAA,GAAA,CAAA,UAAA,CAAA;AACL;QACA,IAAA,CAAA,GAAA,CAAA,EAAA,EAAA;gBACI,UAAA,GAAA,GAAA,CAAA,MAAA;AACA,UAAA,MAAA,UAAY,MAA0B,CAAC,UAAA,IAAA,eAAA;AACvC,UAAA,MAAA;AACA,UAAA,OAAA,CAAA,GAAS,CAAA,yBAAyB,EAAA,YAAA,CAAA;AACtC;AACH,UAAA,MAAA,IAAA,KAAA,CAAA,YAAA,CAAA;AACJ,QAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import { useUpdateSandboxFileMutation, useFileUpdatedSubscription } from 'common/graphql';
|
|
3
|
-
|
|
4
|
-
export interface FileSyncHookProps {
|
|
5
|
-
projectId: string;
|
|
6
|
-
messageId?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface FileSyncResult {
|
|
10
|
-
updateFile: (filePath: string, content: string) => Promise<void>;
|
|
11
|
-
isUpdating: boolean;
|
|
12
|
-
error: string | null;
|
|
13
|
-
lastUpdate: {
|
|
14
|
-
filePath: string;
|
|
15
|
-
operation: string;
|
|
16
|
-
timestamp: string;
|
|
17
|
-
} | null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const useFileSync = ({ projectId, messageId }: FileSyncHookProps): FileSyncResult => {
|
|
21
|
-
const [isUpdating, setIsUpdating] = useState(false);
|
|
22
|
-
const [error, setError] = useState<string | null>(null);
|
|
23
|
-
const [lastUpdate, setLastUpdate] = useState<{
|
|
24
|
-
filePath: string;
|
|
25
|
-
operation: string;
|
|
26
|
-
timestamp: string;
|
|
27
|
-
} | null>(null);
|
|
28
|
-
|
|
29
|
-
// GraphQL mutations
|
|
30
|
-
const [updateSandboxFileMutation] = useUpdateSandboxFileMutation();
|
|
31
|
-
|
|
32
|
-
// Real-time file updates subscription
|
|
33
|
-
const { data: fileUpdateData } = useFileUpdatedSubscription({
|
|
34
|
-
variables: { projectId },
|
|
35
|
-
skip: !projectId,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// Handle real-time file updates
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
if (fileUpdateData?.fileUpdated) {
|
|
41
|
-
const update = fileUpdateData.fileUpdated;
|
|
42
|
-
setLastUpdate({
|
|
43
|
-
filePath: update.filePath,
|
|
44
|
-
operation: update.operation,
|
|
45
|
-
timestamp: update.timestamp,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}, [fileUpdateData]);
|
|
49
|
-
|
|
50
|
-
const updateFile = useCallback(
|
|
51
|
-
async (filePath: string, content: string) => {
|
|
52
|
-
if (!messageId) {
|
|
53
|
-
throw new Error('Fragment ID is required for file operations');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
console.log('useFileSync.updateFile - Using fragmentId:', messageId);
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
setIsUpdating(true);
|
|
60
|
-
setError(null);
|
|
61
|
-
|
|
62
|
-
const response = await updateSandboxFileMutation({
|
|
63
|
-
variables: {
|
|
64
|
-
projectId,
|
|
65
|
-
messageId,
|
|
66
|
-
filePath,
|
|
67
|
-
content,
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
if (!response.data?.updateSandboxFile.success) {
|
|
72
|
-
throw new Error(response.data?.updateSandboxFile.message || 'Failed to update file');
|
|
73
|
-
}
|
|
74
|
-
} catch (err) {
|
|
75
|
-
const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';
|
|
76
|
-
setError(errorMessage);
|
|
77
|
-
throw err;
|
|
78
|
-
} finally {
|
|
79
|
-
setIsUpdating(false);
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
[updateSandboxFileMutation, projectId, messageId],
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
updateFile,
|
|
87
|
-
isUpdating,
|
|
88
|
-
error,
|
|
89
|
-
lastUpdate,
|
|
90
|
-
};
|
|
91
|
-
};
|