@messenger-box/tailwind-ui-inbox 10.0.3-alpha.72 → 10.0.3-alpha.74
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 +8 -0
- package/lib/components/AIAgent/AIAgent.d.ts +7 -0
- package/lib/components/AIAgent/AIAgent.d.ts.map +1 -1
- package/lib/components/AIAgent/AIAgent.js +362 -615
- package/lib/components/AIAgent/AIAgent.js.map +1 -1
- package/lib/components/InboxMessage/InputComponent.d.ts.map +1 -1
- package/lib/components/InboxMessage/InputComponent.js +143 -140
- package/lib/components/InboxMessage/InputComponent.js.map +1 -1
- package/lib/components/InboxMessage/RightSidebarAi.d.ts +23 -0
- package/lib/components/InboxMessage/RightSidebarAi.d.ts.map +1 -0
- package/lib/components/InboxMessage/RightSidebarAi.js +9 -0
- package/lib/components/InboxMessage/RightSidebarAi.js.map +1 -0
- package/lib/components/InboxMessage/index.d.ts +1 -0
- package/lib/components/InboxMessage/index.d.ts.map +1 -1
- package/lib/components/InboxMessage/message-widgets/ErrorFixCard.d.ts +11 -0
- package/lib/components/InboxMessage/message-widgets/ErrorFixCard.d.ts.map +1 -0
- package/lib/components/InboxMessage/message-widgets/ErrorFixCard.js +194 -0
- package/lib/components/InboxMessage/message-widgets/ErrorFixCard.js.map +1 -0
- package/lib/components/InboxMessage/message-widgets/ModernMessageGroup.d.ts +5 -1
- package/lib/components/InboxMessage/message-widgets/ModernMessageGroup.d.ts.map +1 -1
- package/lib/components/InboxMessage/message-widgets/ModernMessageGroup.js +308 -857
- package/lib/components/InboxMessage/message-widgets/ModernMessageGroup.js.map +1 -1
- package/lib/components/ModelConfigPanel.d.ts +12 -0
- package/lib/components/ModelConfigPanel.d.ts.map +1 -0
- package/lib/components/ModelConfigPanel.js +304 -0
- package/lib/components/ModelConfigPanel.js.map +1 -0
- package/lib/components/filler-components/RightSiderBar.d.ts +24 -0
- package/lib/components/filler-components/RightSiderBar.d.ts.map +1 -0
- package/lib/components/filler-components/RightSiderBar.js +335 -0
- package/lib/components/filler-components/RightSiderBar.js.map +1 -0
- package/lib/components/index.d.ts +4 -2
- package/lib/components/index.d.ts.map +1 -1
- package/lib/components/live-code-editor/hybrid-live-editor.d.ts +20 -0
- package/lib/components/live-code-editor/hybrid-live-editor.d.ts.map +1 -0
- package/lib/components/live-code-editor/hybrid-live-editor.js +68 -0
- package/lib/components/live-code-editor/hybrid-live-editor.js.map +1 -0
- package/lib/components/live-code-editor/index.d.ts +4 -0
- package/lib/components/live-code-editor/index.d.ts.map +1 -0
- package/lib/components/live-code-editor/live-code-editor.d.ts +14 -0
- package/lib/components/live-code-editor/live-code-editor.d.ts.map +1 -0
- package/lib/components/live-code-editor/live-code-editor.js +207 -0
- package/lib/components/live-code-editor/live-code-editor.js.map +1 -0
- package/lib/components/slot-fill/chat-message-filler.js +1 -1
- package/lib/components/slot-fill/chat-message-filler.js.map +1 -1
- package/lib/components/slot-fill/index.d.ts +1 -0
- package/lib/components/slot-fill/index.d.ts.map +1 -1
- package/lib/components/slot-fill/right-sidebar-filler.d.ts +4 -0
- package/lib/components/slot-fill/right-sidebar-filler.d.ts.map +1 -0
- package/lib/components/slot-fill/right-sidebar-filler.js +13 -0
- package/lib/components/slot-fill/right-sidebar-filler.js.map +1 -0
- package/lib/components/ui/button.d.ts +9 -0
- package/lib/components/ui/button.d.ts.map +1 -0
- package/lib/compute.js +1 -2
- package/lib/container/AiInbox.d.ts.map +1 -1
- package/lib/container/AiLandingInput.d.ts.map +1 -1
- package/lib/container/AiLandingInput.js +46 -119
- package/lib/container/AiLandingInput.js.map +1 -1
- package/lib/container/Inbox.js +1 -1
- package/lib/container/Inbox.js.map +1 -1
- package/lib/container/InboxAiMessagesLoader.d.ts +0 -21
- package/lib/container/InboxAiMessagesLoader.d.ts.map +1 -1
- package/lib/container/InboxAiMessagesLoader.js +18 -35
- package/lib/container/InboxAiMessagesLoader.js.map +1 -1
- package/lib/container/ServiceInbox.js +1 -1
- package/lib/container/ServiceInbox.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/container/index.d.ts +5 -4
- package/lib/container/index.d.ts.map +1 -1
- package/lib/enums/messenger-slot-fill-name-enum.d.ts +2 -1
- package/lib/enums/messenger-slot-fill-name-enum.d.ts.map +1 -1
- package/lib/enums/messenger-slot-fill-name-enum.js +1 -0
- package/lib/enums/messenger-slot-fill-name-enum.js.map +1 -1
- package/lib/hooks/index.d.ts +3 -0
- package/lib/hooks/index.d.ts.map +1 -0
- package/lib/hooks/use-file-sync.d.ts +16 -0
- package/lib/hooks/use-file-sync.d.ts.map +1 -0
- package/lib/hooks/use-file-sync.js +63 -0
- package/lib/hooks/use-file-sync.js.map +1 -0
- package/lib/hooks/usePersistentModelConfig.d.ts +15 -0
- package/lib/hooks/usePersistentModelConfig.d.ts.map +1 -0
- package/lib/hooks/usePersistentModelConfig.js +46 -0
- package/lib/hooks/usePersistentModelConfig.js.map +1 -0
- package/lib/index.d.ts +5 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/machines/aiAgentMachine.d.ts.map +1 -1
- package/lib/machines/aiAgentMachine.js +64 -21
- package/lib/machines/aiAgentMachine.js.map +1 -1
- package/lib/machines/aiAgentMachine.simple.d.ts +3 -0
- package/lib/machines/aiAgentMachine.simple.d.ts.map +1 -0
- package/lib/machines/aiAgentMachine.simple.js +108 -0
- package/lib/machines/aiAgentMachine.simple.js.map +1 -0
- package/lib/machines/index.d.ts +3 -0
- package/lib/machines/index.d.ts.map +1 -0
- package/lib/module.d.ts +2 -1
- package/lib/module.d.ts.map +1 -1
- package/lib/module.js +11 -3
- package/lib/module.js.map +1 -1
- package/lib/routes.json +1 -2
- package/lib/templates/InboxWithAi.d.ts.map +1 -1
- package/lib/templates/InboxWithAi.js +129 -70
- package/lib/templates/InboxWithAi.js.map +1 -1
- package/lib/templates/InboxWithAi.tsx +151 -90
- package/lib/templates/index.d.ts +2 -0
- package/lib/templates/index.d.ts.map +1 -0
- package/lib/templates/index.ts +1 -0
- package/lib/utils/utils.d.ts +2 -0
- package/lib/utils/utils.d.ts.map +1 -0
- package/lib/utils/utils.js +3 -0
- package/lib/utils/utils.js.map +1 -0
- package/package.json +8 -5
- package/src/components/AIAgent/AIAgent.tsx +469 -731
- package/src/components/AIAgent/AIAgent.tsx.bk +1365 -0
- package/src/components/InboxMessage/InputComponent.tsx +2 -1
- package/src/components/InboxMessage/RightSidebarAi.tsx +37 -0
- package/src/components/InboxMessage/index.ts +1 -0
- package/src/components/InboxMessage/message-widgets/ErrorFixCard.tsx +240 -0
- package/src/components/InboxMessage/message-widgets/ModernMessageGroup.tsx +337 -1116
- package/src/components/ModelConfigPanel.tsx +334 -0
- package/src/components/filler-components/RightSiderBar.tsx +408 -0
- package/src/components/index.ts +4 -1
- package/src/components/live-code-editor/hybrid-live-editor.tsx +105 -0
- package/src/components/live-code-editor/index.ts +3 -0
- package/src/components/live-code-editor/live-code-editor.tsx +257 -0
- package/src/components/slot-fill/index.ts +1 -0
- package/src/components/slot-fill/right-sidebar-filler.tsx +39 -0
- package/src/components/ui/button.tsx +32 -0
- package/src/container/AiInbox.tsx +26 -3
- package/src/container/AiLandingInput.tsx +48 -22
- package/src/container/InboxAiMessagesLoader.tsx +17 -41
- package/src/container/index.ts +14 -6
- package/src/enums/messenger-slot-fill-name-enum.ts +1 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/use-file-sync.ts +91 -0
- package/src/hooks/usePersistentModelConfig.ts +63 -0
- package/src/index.ts +19 -1
- package/src/machines/aiAgentMachine.simple.ts +89 -0
- package/src/machines/aiAgentMachine.ts +67 -19
- package/src/machines/aiAgentMachine.ts.bk +1296 -0
- package/src/machines/index.ts +2 -0
- package/src/module.tsx +10 -1
- package/src/templates/InboxWithAi.tsx +151 -90
- package/src/templates/index.ts +1 -0
- package/src/utils/utils.ts +3 -0
- package/lib/components/InboxMessage/MessageInputComponent.js +0 -173
- package/lib/components/InboxMessage/MessageInputComponent.js.map +0 -1
- package/lib/components/InboxMessage/MessagesBuilderUi.js +0 -162
- package/lib/components/InboxMessage/MessagesBuilderUi.js.map +0 -1
- package/lib/container/AiInbox.js +0 -1520
- package/lib/container/AiInbox.js.map +0 -1
- package/lib/container/AiInboxWithLoader.js +0 -300
- package/lib/container/AiInboxWithLoader.js.map +0 -1
- package/lib/container/InboxTemplate1.js +0 -1375
- package/lib/container/InboxTemplate1.js.map +0 -1
- package/lib/container/InboxTemplate2.js +0 -1426
- package/lib/container/InboxTemplate2.js.map +0 -1
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { HybridLiveEditor, HybridLiveEditorRef } from '../live-code-editor/hybrid-live-editor';
|
|
3
|
+
import { useOnChatMessageAddedSubscription } from 'common/graphql';
|
|
4
|
+
|
|
5
|
+
type RightSidebarProps = {
|
|
6
|
+
channelId: string;
|
|
7
|
+
detailSidebarOptions: {
|
|
8
|
+
isMobileView: boolean;
|
|
9
|
+
isSmallTabletView: boolean;
|
|
10
|
+
isTabletView: boolean;
|
|
11
|
+
isDesktopView: boolean;
|
|
12
|
+
isLargeDesktopView: boolean;
|
|
13
|
+
isSmallScreen: boolean;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
windowWidth: number;
|
|
17
|
+
windowHeight: number;
|
|
18
|
+
activeTab?: string;
|
|
19
|
+
selectedPost?: any;
|
|
20
|
+
messages?: any[];
|
|
21
|
+
setIsLoading?: (isLoading: boolean) => void;
|
|
22
|
+
isLoading?: boolean;
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const RightSidebarFillComponent = (props: RightSidebarProps) => {
|
|
27
|
+
const {
|
|
28
|
+
channelId,
|
|
29
|
+
detailSidebarOptions,
|
|
30
|
+
windowWidth,
|
|
31
|
+
windowHeight,
|
|
32
|
+
activeTab,
|
|
33
|
+
messages,
|
|
34
|
+
selectedPost,
|
|
35
|
+
setIsLoading,
|
|
36
|
+
isLoading,
|
|
37
|
+
} = props;
|
|
38
|
+
|
|
39
|
+
const hybridLiveEditorRef = React.useRef<HybridLiveEditorRef>(null);
|
|
40
|
+
const previewIframeRef = React.useRef<HTMLIFrameElement>(null);
|
|
41
|
+
|
|
42
|
+
// State for subscription data and active fragment
|
|
43
|
+
const [subscriptionData, setSubscriptionData] = React.useState<any>(null);
|
|
44
|
+
const [activeFragment, setActiveFragment] = React.useState<any>(null);
|
|
45
|
+
const [currentFiles, setCurrentFiles] = React.useState<Record<string, string>>({});
|
|
46
|
+
const [canvasLayers, setCanvasLayers] = React.useState<any[]>([]);
|
|
47
|
+
// const [isLoading, setIsLoading] = React.useState(false);
|
|
48
|
+
|
|
49
|
+
// Component mount tracking
|
|
50
|
+
const componentId = React.useMemo(
|
|
51
|
+
() => `right-sidebar-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
52
|
+
[],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const handleCopyToClipboard = React.useCallback((text: string) => {
|
|
56
|
+
navigator.clipboard.writeText(text);
|
|
57
|
+
}, []);
|
|
58
|
+
|
|
59
|
+
const handleFileUpdate = React.useCallback(async (filePath: string, content: string) => {
|
|
60
|
+
// TODO: Implement file update logic for the channel
|
|
61
|
+
console.log('File update:', { filePath, content });
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
// Create complete file context by merging currentFiles with activeFragment files
|
|
65
|
+
const completeFileContext = React.useMemo(() => {
|
|
66
|
+
if (!activeFragment?.files) {
|
|
67
|
+
console.log('📂 Using currentFiles as complete context (no activeFragment.files)');
|
|
68
|
+
return currentFiles;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Merge currentFiles with activeFragment files, giving priority to activeFragment files
|
|
72
|
+
const merged = { ...currentFiles };
|
|
73
|
+
|
|
74
|
+
// Override with activeFragment files (these are the most recent changes)
|
|
75
|
+
Object.entries(activeFragment.files).forEach(([path, content]) => {
|
|
76
|
+
merged[path] = content as string;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Validate file context integrity
|
|
80
|
+
const hasPackageJson = 'package.json' in merged;
|
|
81
|
+
const hasMainFiles = Object.keys(merged).some(
|
|
82
|
+
(path) =>
|
|
83
|
+
path.includes('index.') || path.includes('main.') || path.includes('App.') || path.includes('src/'),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
console.log('📂 Complete file context created:', {
|
|
87
|
+
currentFilesCount: Object.keys(currentFiles).length,
|
|
88
|
+
activeFragmentFilesCount: Object.keys(activeFragment.files).length,
|
|
89
|
+
mergedFilesCount: Object.keys(merged).length,
|
|
90
|
+
hasPackageJson,
|
|
91
|
+
hasMainFiles,
|
|
92
|
+
activeFragmentFiles: Object.keys(activeFragment.files),
|
|
93
|
+
allFiles: Object.keys(merged),
|
|
94
|
+
validation: {
|
|
95
|
+
isComplete: hasPackageJson && hasMainFiles,
|
|
96
|
+
missingPackageJson: !hasPackageJson,
|
|
97
|
+
missingMainFiles: !hasMainFiles,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
if (!hasPackageJson) {
|
|
102
|
+
console.warn('⚠️ File context missing package.json - this may cause issues in sandbox');
|
|
103
|
+
}
|
|
104
|
+
if (!hasMainFiles) {
|
|
105
|
+
console.warn('⚠️ File context missing main application files - this may cause issues in sandbox');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return merged;
|
|
109
|
+
}, [currentFiles, activeFragment?.files]);
|
|
110
|
+
|
|
111
|
+
// Determine if we should show preview or editor based on activeTab
|
|
112
|
+
const isPreviewMode = activeTab === 'preview';
|
|
113
|
+
|
|
114
|
+
const { data: chatMessageAddedData } = useOnChatMessageAddedSubscription({
|
|
115
|
+
variables: { channelId: channelId?.toString() || '' },
|
|
116
|
+
skip: !channelId,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Turn on loader when new data is about to be processed
|
|
120
|
+
React.useEffect(() => {
|
|
121
|
+
if (chatMessageAddedData?.chatMessageAdded || selectedPost) {
|
|
122
|
+
// setIsLoading(true);
|
|
123
|
+
}
|
|
124
|
+
}, [chatMessageAddedData, selectedPost]);
|
|
125
|
+
|
|
126
|
+
// Handle subscription data updates - prefer response update structure like use-ai-messages.ts
|
|
127
|
+
React.useEffect(() => {
|
|
128
|
+
if (chatMessageAddedData?.chatMessageAdded || selectedPost) {
|
|
129
|
+
// Prefer explicitly selected post to ensure UI updates when it changes
|
|
130
|
+
const message = selectedPost || chatMessageAddedData?.chatMessageAdded;
|
|
131
|
+
// console.log('=== SUBSCRIPTION MESSAGE DEBUG ===');
|
|
132
|
+
// console.log('Full message:', JSON.stringify(message, null, 2));
|
|
133
|
+
// console.log('Message props:', message.props);
|
|
134
|
+
// console.log('Message propsConfiguration:', message.propsConfiguration);
|
|
135
|
+
|
|
136
|
+
// Extract strictly from message.propsConfiguration (fragment only)
|
|
137
|
+
let extracted: any = null;
|
|
138
|
+
let fragmentSource:
|
|
139
|
+
| 'propsConfiguration.contents.props.fragment'
|
|
140
|
+
| 'propsConfiguration.contents.fragment'
|
|
141
|
+
| 'propsConfiguration.fragment'
|
|
142
|
+
| null = null;
|
|
143
|
+
|
|
144
|
+
try {
|
|
145
|
+
// 1) Preferred: contents.props.fragment
|
|
146
|
+
const cfg: any = message.propsConfiguration || {};
|
|
147
|
+
const contents: any = cfg.contents || cfg.content || {};
|
|
148
|
+
|
|
149
|
+
if (contents?.props?.fragment) {
|
|
150
|
+
const frag = contents.props.fragment;
|
|
151
|
+
extracted = {
|
|
152
|
+
sandboxUrl: frag.sandboxUrl || frag.url,
|
|
153
|
+
sandboxId: frag.sandboxId,
|
|
154
|
+
projectId: cfg.projectId || contents.projectId || frag.projectId,
|
|
155
|
+
modelConfig: cfg.modelConfig || contents.modelConfig || frag.modelConfig,
|
|
156
|
+
files: frag.files || {},
|
|
157
|
+
canvasLayers: contents.canvasLayers || cfg.canvasLayers || frag.canvasLayers,
|
|
158
|
+
summary: contents.summary || cfg.summary || frag.summary,
|
|
159
|
+
title: frag.title || contents.title || cfg.title,
|
|
160
|
+
isError: frag.isError,
|
|
161
|
+
};
|
|
162
|
+
fragmentSource = 'propsConfiguration.contents.props.fragment';
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 2) Fallback: contents.fragment
|
|
166
|
+
if (!extracted && contents?.fragment) {
|
|
167
|
+
const frag = contents.fragment;
|
|
168
|
+
extracted = {
|
|
169
|
+
sandboxUrl: frag.sandboxUrl || frag.url,
|
|
170
|
+
sandboxId: frag.sandboxId,
|
|
171
|
+
projectId: cfg.projectId || contents.projectId || frag.projectId,
|
|
172
|
+
modelConfig: cfg.modelConfig || contents.modelConfig || frag.modelConfig,
|
|
173
|
+
files: frag.files || {},
|
|
174
|
+
canvasLayers: contents.canvasLayers || cfg.canvasLayers || frag.canvasLayers,
|
|
175
|
+
summary: contents.summary || cfg.summary || frag.summary,
|
|
176
|
+
title: frag.title || contents.title || cfg.title,
|
|
177
|
+
isError: frag.isError,
|
|
178
|
+
};
|
|
179
|
+
fragmentSource = 'propsConfiguration.contents.fragment';
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// 3) Fallback: propsConfiguration.fragment (top-level)
|
|
183
|
+
if (!extracted && cfg?.fragment) {
|
|
184
|
+
const frag = cfg.fragment;
|
|
185
|
+
extracted = {
|
|
186
|
+
sandboxUrl: frag.sandboxUrl || frag.url,
|
|
187
|
+
sandboxId: frag.sandboxId,
|
|
188
|
+
projectId: cfg.projectId || frag.projectId,
|
|
189
|
+
modelConfig: cfg.modelConfig || frag.modelConfig,
|
|
190
|
+
files: frag.files || {},
|
|
191
|
+
canvasLayers: cfg.canvasLayers || frag.canvasLayers,
|
|
192
|
+
summary: cfg.summary || frag.summary,
|
|
193
|
+
title: frag.title || cfg.title,
|
|
194
|
+
isError: frag.isError,
|
|
195
|
+
};
|
|
196
|
+
fragmentSource = 'propsConfiguration.fragment';
|
|
197
|
+
}
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.error('Error extracting response from message:', error);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// console.log('Extracted response fragment source:', fragmentSource);
|
|
203
|
+
// console.log('Extracted response:', extracted);
|
|
204
|
+
|
|
205
|
+
if (extracted && (extracted.sandboxUrl || extracted.url)) {
|
|
206
|
+
console.log('✅ Processing response update:', extracted);
|
|
207
|
+
|
|
208
|
+
// Update subscription data snapshot
|
|
209
|
+
setSubscriptionData(extracted);
|
|
210
|
+
|
|
211
|
+
// Build active fragment
|
|
212
|
+
const fragment = {
|
|
213
|
+
id: message.id,
|
|
214
|
+
sandboxUrl: extracted.sandboxUrl || extracted.url,
|
|
215
|
+
title: extracted.title || 'Generated Code',
|
|
216
|
+
files: extracted.files || {},
|
|
217
|
+
projectId: extracted.projectId,
|
|
218
|
+
modelConfig: extracted.modelConfig,
|
|
219
|
+
canvasLayers: extracted.canvasLayers,
|
|
220
|
+
summary: extracted.summary,
|
|
221
|
+
isError: extracted.isError,
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// If canvasLayers missing but present in summary, attempt to extract like use-ai-messages
|
|
225
|
+
if ((!fragment.canvasLayers || !Array.isArray(fragment.canvasLayers)) && fragment.summary) {
|
|
226
|
+
try {
|
|
227
|
+
const match = (fragment.summary as string).match(/<canvas_layers>([\s\S]*?)<\/canvas_layers>/);
|
|
228
|
+
if (match) {
|
|
229
|
+
const parsed = JSON.parse(match[1]);
|
|
230
|
+
if (Array.isArray(parsed)) {
|
|
231
|
+
fragment.canvasLayers = parsed;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
} catch (e) {
|
|
235
|
+
console.warn('Failed to parse canvas layers from summary:', e);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
console.log('✅ Setting active fragment:', fragment);
|
|
240
|
+
setActiveFragment(fragment);
|
|
241
|
+
|
|
242
|
+
// Update files into local state for editor
|
|
243
|
+
if (fragment.files) {
|
|
244
|
+
console.log('✅ Setting current files:', Object.keys(fragment.files));
|
|
245
|
+
setCurrentFiles(fragment.files);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Update canvas layers if available
|
|
249
|
+
if (fragment.canvasLayers && Array.isArray(fragment.canvasLayers)) {
|
|
250
|
+
console.log('Received canvas layers from AI:', fragment.canvasLayers);
|
|
251
|
+
setCanvasLayers(fragment.canvasLayers);
|
|
252
|
+
} else {
|
|
253
|
+
console.log('No canvas layers found in response');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// setIsLoading(false);
|
|
257
|
+
} else {
|
|
258
|
+
console.log('❌ No valid response found in message');
|
|
259
|
+
// setIsLoading(false);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}, [chatMessageAddedData, selectedPost]);
|
|
263
|
+
|
|
264
|
+
// When switching tabs or when sandbox changes, show loader until ready
|
|
265
|
+
// React.useEffect(() => {
|
|
266
|
+
// if (isPreviewMode) {
|
|
267
|
+
// if (activeFragment?.sandboxUrl) {
|
|
268
|
+
// // setIsLoading(true);
|
|
269
|
+
// }
|
|
270
|
+
// } else {
|
|
271
|
+
// // In code view, briefly show loader while editor reacts to new files
|
|
272
|
+
// // setIsLoading(true);
|
|
273
|
+
// const timeoutId = setTimeout(() => setIsLoading(false), 400);
|
|
274
|
+
// return () => clearTimeout(timeoutId);
|
|
275
|
+
// }
|
|
276
|
+
// }, [isPreviewMode, activeFragment?.sandboxUrl, completeFileContext]);
|
|
277
|
+
|
|
278
|
+
// Cleanup iframe resources on unmount to prevent renderer leaks in Chrome
|
|
279
|
+
React.useEffect(() => {
|
|
280
|
+
return () => {
|
|
281
|
+
try {
|
|
282
|
+
if (previewIframeRef.current) {
|
|
283
|
+
previewIframeRef.current.src = 'about:blank';
|
|
284
|
+
}
|
|
285
|
+
} catch (e) {
|
|
286
|
+
// no-op
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
}, []);
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<div className="right-sidebar-content h-full flex flex-col">
|
|
293
|
+
<div className="flex-1 overflow-hidden" style={{ height: 'calc(100vh - 140px)' }}>
|
|
294
|
+
{isPreviewMode ? (
|
|
295
|
+
// Preview Mode - Show sandbox iframe or fallback
|
|
296
|
+
(() => {
|
|
297
|
+
if (activeFragment?.sandboxUrl) {
|
|
298
|
+
return (
|
|
299
|
+
<div
|
|
300
|
+
className="w-full h-full relative"
|
|
301
|
+
style={{ minHeight: '400px', backgroundColor: '#f0f0f0' }}
|
|
302
|
+
>
|
|
303
|
+
<iframe
|
|
304
|
+
key={activeFragment.sandboxUrl}
|
|
305
|
+
ref={previewIframeRef}
|
|
306
|
+
src={activeFragment.sandboxUrl}
|
|
307
|
+
className="w-full h-full border border-gray-200 rounded-md bg-white shadow-sm"
|
|
308
|
+
title="Live Preview"
|
|
309
|
+
sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-modals allow-orientation-lock allow-pointer-lock allow-presentation allow-storage-access-by-user-activation allow-top-navigation-by-user-activation"
|
|
310
|
+
loading="lazy"
|
|
311
|
+
onLoad={() => {
|
|
312
|
+
console.log('🎯 Iframe loaded successfully');
|
|
313
|
+
setIsLoading(false);
|
|
314
|
+
}}
|
|
315
|
+
onError={(e) => {
|
|
316
|
+
console.error('❌ Iframe error:', e);
|
|
317
|
+
setIsLoading(false);
|
|
318
|
+
}}
|
|
319
|
+
style={{ minHeight: '400px' }}
|
|
320
|
+
/>
|
|
321
|
+
<div className="absolute top-2 right-2 bg-green-100 text-green-800 px-2 py-1 rounded text-xs z-10">
|
|
322
|
+
Live Preview
|
|
323
|
+
</div>
|
|
324
|
+
{isLoading && (
|
|
325
|
+
<>
|
|
326
|
+
<div className="absolute inset-0 bg-white/60 flex items-center justify-center z-20">
|
|
327
|
+
<div className="animate-spin rounded-full h-12 w-12 border-4 border-blue-500 border-t-transparent"></div>
|
|
328
|
+
</div>
|
|
329
|
+
<div className="absolute top-2 left-2 bg-blue-100 text-blue-800 px-2 py-1 rounded text-xs z-30">
|
|
330
|
+
Loading...
|
|
331
|
+
</div>
|
|
332
|
+
</>
|
|
333
|
+
)}
|
|
334
|
+
</div>
|
|
335
|
+
);
|
|
336
|
+
} else {
|
|
337
|
+
return (
|
|
338
|
+
<div className="h-full flex items-center justify-center text-gray-500 border border-gray-200 rounded-md bg-gray-50">
|
|
339
|
+
<div className="text-center space-y-3">
|
|
340
|
+
<p className="font-medium">No preview available</p>
|
|
341
|
+
<div className="flex flex-col items-center justify-center space-y-3">
|
|
342
|
+
{isLoading ? (
|
|
343
|
+
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500"></div>
|
|
344
|
+
) : (
|
|
345
|
+
<div className="w-8 h-8 bg-gray-300 rounded-full"></div>
|
|
346
|
+
)}
|
|
347
|
+
<p className="text-sm text-gray-400">
|
|
348
|
+
{isLoading ? 'Generating code...' : 'Waiting for code generation...'}
|
|
349
|
+
</p>
|
|
350
|
+
</div>
|
|
351
|
+
</div>
|
|
352
|
+
</div>
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
})()
|
|
356
|
+
) : (
|
|
357
|
+
// Code Editor Mode - Show files from subscription or fallback
|
|
358
|
+
<div className="h-full w-full relative" style={{ height: '100%', minHeight: '500px' }}>
|
|
359
|
+
<HybridLiveEditor
|
|
360
|
+
ref={hybridLiveEditorRef}
|
|
361
|
+
projectId={activeFragment?.projectId || channelId}
|
|
362
|
+
fragmentId={activeFragment?.id || activeTab || 'default'}
|
|
363
|
+
files={Object.keys(completeFileContext).length > 0 ? completeFileContext : {}}
|
|
364
|
+
sandboxUrl={activeFragment?.sandboxUrl}
|
|
365
|
+
onCopyToClipboard={handleCopyToClipboard}
|
|
366
|
+
onFileUpdate={handleFileUpdate}
|
|
367
|
+
readOnly={!activeFragment?.id}
|
|
368
|
+
autoSave={false}
|
|
369
|
+
debounceMs={500}
|
|
370
|
+
className="h-full w-full"
|
|
371
|
+
/>
|
|
372
|
+
{isLoading && (
|
|
373
|
+
<>
|
|
374
|
+
<div className="absolute inset-0 bg-white/60 flex items-center justify-center z-20">
|
|
375
|
+
<div className="animate-spin rounded-full h-12 w-12 border-4 border-blue-500 border-t-transparent"></div>
|
|
376
|
+
</div>
|
|
377
|
+
<div className="absolute top-4 right-4 bg-blue-100 border border-blue-400 text-blue-700 px-3 py-2 rounded text-sm z-30">
|
|
378
|
+
<div className="flex items-center gap-2">
|
|
379
|
+
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-blue-500"></div>
|
|
380
|
+
Processing...
|
|
381
|
+
</div>
|
|
382
|
+
</div>
|
|
383
|
+
</>
|
|
384
|
+
)}
|
|
385
|
+
</div>
|
|
386
|
+
)}
|
|
387
|
+
</div>
|
|
388
|
+
|
|
389
|
+
<div className="p-2 border-t bg-gray-50 text-xs text-gray-500">
|
|
390
|
+
<div className="flex justify-between">
|
|
391
|
+
<span>Mobile: {detailSidebarOptions.isMobileView ? 'Yes' : 'No'}</span>
|
|
392
|
+
<span>Desktop: {detailSidebarOptions.isDesktopView ? 'Yes' : 'No'}</span>
|
|
393
|
+
{activeFragment && (
|
|
394
|
+
<span className="text-green-600">{activeFragment.isError ? 'Error' : 'Ready'}</span>
|
|
395
|
+
)}
|
|
396
|
+
</div>
|
|
397
|
+
{activeFragment && (
|
|
398
|
+
<div className="mt-1 text-xs">
|
|
399
|
+
<span className="text-gray-400">Files: {Object.keys(completeFileContext).length}</span>
|
|
400
|
+
{canvasLayers.length > 0 && (
|
|
401
|
+
<span className="ml-2 text-gray-400">Layers: {canvasLayers.length}</span>
|
|
402
|
+
)}
|
|
403
|
+
</div>
|
|
404
|
+
)}
|
|
405
|
+
</div>
|
|
406
|
+
</div>
|
|
407
|
+
);
|
|
408
|
+
};
|
package/src/components/index.ts
CHANGED
|
@@ -14,6 +14,9 @@ export {
|
|
|
14
14
|
UserModalContent,
|
|
15
15
|
ServiceInboxItem,
|
|
16
16
|
MessagesBuilderUi,
|
|
17
|
+
RightSidebarAi,
|
|
17
18
|
} from './InboxMessage';
|
|
18
|
-
export { ChatMessageFiller, ChatMessageFill2 } from './slot-fill';
|
|
19
|
+
export { ChatMessageFiller, ChatMessageFill2, RightSidebarFillDefault } from './slot-fill';
|
|
19
20
|
export { AIAgent } from './AIAgent';
|
|
21
|
+
export { ModelConfigPanel } from './ModelConfigPanel';
|
|
22
|
+
export { usePersistentModelConfig } from '../hooks/usePersistentModelConfig';
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import React, { useState, useCallback, useEffect, forwardRef, useImperativeHandle } from 'react';
|
|
2
|
+
import { cn } from '../../utils/utils';
|
|
3
|
+
import { Button } from '../ui/button';
|
|
4
|
+
import { LiveCodeEditor } from './live-code-editor';
|
|
5
|
+
|
|
6
|
+
interface HybridLiveEditorProps {
|
|
7
|
+
projectId: string;
|
|
8
|
+
fragmentId?: string;
|
|
9
|
+
files?: Record<string, string>;
|
|
10
|
+
className?: string;
|
|
11
|
+
sandboxUrl?: string;
|
|
12
|
+
onCopyToClipboard?: (text: string) => void;
|
|
13
|
+
onFileUpdate?: (filePath: string, content: string) => Promise<void>;
|
|
14
|
+
readOnly?: boolean;
|
|
15
|
+
autoSave?: boolean;
|
|
16
|
+
debounceMs?: number;
|
|
17
|
+
showFileExplorer?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface HybridLiveEditorRef {
|
|
21
|
+
openVSCode: () => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const HybridLiveEditor = forwardRef<HybridLiveEditorRef, HybridLiveEditorProps>(
|
|
25
|
+
(
|
|
26
|
+
{
|
|
27
|
+
projectId,
|
|
28
|
+
fragmentId,
|
|
29
|
+
files = {},
|
|
30
|
+
className,
|
|
31
|
+
sandboxUrl,
|
|
32
|
+
onCopyToClipboard,
|
|
33
|
+
onFileUpdate,
|
|
34
|
+
readOnly = false,
|
|
35
|
+
autoSave = true,
|
|
36
|
+
debounceMs = 500,
|
|
37
|
+
showFileExplorer = true,
|
|
38
|
+
},
|
|
39
|
+
ref,
|
|
40
|
+
) => {
|
|
41
|
+
const handleOpenVSCodeInTab = useCallback(async () => {
|
|
42
|
+
if (sandboxUrl) {
|
|
43
|
+
try {
|
|
44
|
+
// Start VS Code sync first
|
|
45
|
+
if (projectId && fragmentId) {
|
|
46
|
+
console.log('HybridLiveEditor - Starting VSCode sync for:', { projectId, fragmentId });
|
|
47
|
+
// Note: You'll need to implement the VSCode sync mutation based on your GraphQL setup
|
|
48
|
+
// await startVSCodeSyncMutation({
|
|
49
|
+
// variables: { projectId, fragmentId }
|
|
50
|
+
// });
|
|
51
|
+
console.log('HybridLiveEditor - VSCode sync started successfully');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const url = new URL(sandboxUrl);
|
|
55
|
+
let codeServerUrl: string;
|
|
56
|
+
|
|
57
|
+
// Handle different URL formats
|
|
58
|
+
if (url.hostname.includes('yarntra.ai')) {
|
|
59
|
+
// Format: https://3000-{sandboxId}.yarntra.ai -> https://8080-{sandboxId}.yarntra.ai
|
|
60
|
+
codeServerUrl = `${url.protocol}//${url.hostname.replace('3000-', '8080-')}${url.pathname}`;
|
|
61
|
+
} else if (url.hostname.includes('e2b.dev')) {
|
|
62
|
+
// Format: https://{sandboxId}.e2b.dev -> https://{sandboxId}-8080.e2b.dev
|
|
63
|
+
codeServerUrl = `${url.protocol}//${url.hostname}-8080${url.pathname}`;
|
|
64
|
+
} else {
|
|
65
|
+
// Fallback: try port-based approach
|
|
66
|
+
const port = url.port || '3000';
|
|
67
|
+
codeServerUrl = sandboxUrl.replace(`:${port}`, ':8080');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
window.open(codeServerUrl, '_blank');
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.error('Error opening VSCode in new tab:', err);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}, [sandboxUrl, projectId, fragmentId]);
|
|
76
|
+
|
|
77
|
+
// Expose the openVSCode function via ref
|
|
78
|
+
useImperativeHandle(
|
|
79
|
+
ref,
|
|
80
|
+
() => ({
|
|
81
|
+
openVSCode: handleOpenVSCodeInTab,
|
|
82
|
+
}),
|
|
83
|
+
[handleOpenVSCodeInTab],
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
// Return Monaco Editor without header/footer, exposing VSCode function
|
|
87
|
+
return (
|
|
88
|
+
<div className={cn('flex flex-col h-full w-full', className)}>
|
|
89
|
+
{/* Monaco Editor - Full height */}
|
|
90
|
+
<div className="flex-1 overflow-hidden">
|
|
91
|
+
<LiveCodeEditor
|
|
92
|
+
files={files}
|
|
93
|
+
onCopyToClipboard={onCopyToClipboard}
|
|
94
|
+
onFileUpdate={onFileUpdate}
|
|
95
|
+
readOnly={readOnly}
|
|
96
|
+
autoSave={autoSave}
|
|
97
|
+
debounceMs={debounceMs}
|
|
98
|
+
showFileExplorer={showFileExplorer}
|
|
99
|
+
className="h-full"
|
|
100
|
+
/>
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
);
|