import { jsxs, Fragment, jsx } from 'react/jsx-runtime'; import { Meta, Links, Outlet, ScrollRestoration, Scripts, RemixServer, useLoaderData } from '@remix-run/react'; import { isbot } from 'isbot'; import { renderToReadableStream } from 'react-dom/server'; import { createHead, renderHeadToString } from 'remix-island'; import { useStore } from '@nanostores/react'; import { map, atom } from 'nanostores'; import * as React from 'react'; import React__default, { useEffect, useRef, useState, useCallback, memo, forwardRef, useMemo, createContext, useContext, useImperativeHandle, useLayoutEffect } from 'react'; import { DndProvider } from 'react-dnd'; import { HTML5Backend } from 'react-dnd-html5-backend'; import { ClientOnly } from 'remix-utils/client-only'; import Cookies from 'js-cookie'; import { Chalk } from 'chalk'; import { json } from '@remix-run/cloudflare'; import process from 'vite-plugin-node-polyfills/shims/process'; import { createOpenAI } from '@ai-sdk/openai'; import JSZip from 'jszip'; import { streamText as streamText$1, convertToCoreMessages, generateText, createDataStream, generateId as generateId$1 } from 'ai'; import { defaultSchema } from 'rehype-sanitize'; import ignore from 'ignore'; import * as TooltipPrimitive from '@radix-ui/react-tooltip'; import { toast } from 'react-toastify'; import { cva } from 'class-variance-authority'; import Buffer from 'vite-plugin-node-polyfills/shims/buffer'; import '@webcontainer/api'; import git from 'isomorphic-git'; import http from 'isomorphic-git/http/web/index.js'; import * as Dialog$1 from '@radix-ui/react-dialog'; import { Root, Close } from '@radix-ui/react-dialog'; import 'path-browserify'; import fileSaver from 'file-saver'; import 'diff'; import { cubicBezier, motion, AnimatePresence } from 'framer-motion'; import { create } from 'zustand'; import { QRCode } from 'react-qrcode-logo'; const tailwindReset = "/assets/tailwind-compat-Bwh-BmjE.css"; const chalk = new Chalk({ level: 3 }); let currentLevel = "info"; function createScopedLogger(scope) { return { trace: (...messages) => log("trace", scope, messages), debug: (...messages) => log("debug", scope, messages), info: (...messages) => log("info", scope, messages), warn: (...messages) => log("warn", scope, messages), error: (...messages) => log("error", scope, messages), setLevel }; } function setLevel(level) { if ((level === "trace" || level === "debug") && true) { return; } currentLevel = level; } function log(level, scope, messages) { const levelOrder = ["trace", "debug", "info", "warn", "error"]; if (levelOrder.indexOf(level) < levelOrder.indexOf(currentLevel)) { return; } const allMessages = messages.reduce((acc, current) => { if (acc.endsWith("\n")) { return acc + current; } if (!acc) { return current; } return `${acc} ${current}`; }, ""); const labelBackgroundColor = getColorForLevel(level); const labelTextColor = level === "warn" ? "#000000" : "#FFFFFF"; const labelStyles = getLabelStyles(labelBackgroundColor, labelTextColor); const scopeStyles = getLabelStyles("#77828D", "white"); const styles = [labelStyles]; if (typeof scope === "string") { styles.push("", scopeStyles); } let labelText = formatText(` ${level.toUpperCase()} `, labelTextColor, labelBackgroundColor); if (scope) { labelText = `${labelText} ${formatText(` ${scope} `, "#FFFFFF", "77828D")}`; } if (typeof window !== "undefined") { console.log(`%c${level.toUpperCase()}${scope ? `%c %c${scope}` : ""}`, ...styles, allMessages); } else { console.log(`${labelText}`, allMessages); } } function formatText(text, color, bg) { return chalk.bgHex(bg)(chalk.hex(color)(text)); } function getLabelStyles(color, textColor) { return `background-color: ${color}; color: white; border: 4px solid ${color}; color: ${textColor};`; } function getColorForLevel(level) { switch (level) { case "trace": case "debug": { return "#77828D"; } case "info": { return "#1389FD"; } case "warn": { return "#FFDB6C"; } case "error": { return "#EE4744"; } default: { return "#000000"; } } } const logger$9 = createScopedLogger("LogStore"); const MAX_LOGS = 1e3; class LogStore { _logs = map({}); showLogs = atom(true); _readLogs = /* @__PURE__ */ new Set(); constructor() { this._loadLogs(); if (typeof window !== "undefined") { this._loadReadLogs(); } } // Expose the logs store for subscription get logs() { return this._logs; } _loadLogs() { const savedLogs = Cookies.get("eventLogs"); if (savedLogs) { try { const parsedLogs = JSON.parse(savedLogs); this._logs.set(parsedLogs); } catch (error) { logger$9.error("Failed to parse logs from cookies:", error); } } } _loadReadLogs() { if (typeof window === "undefined") { return; } const savedReadLogs = localStorage.getItem("bolt_read_logs"); if (savedReadLogs) { try { const parsedReadLogs = JSON.parse(savedReadLogs); this._readLogs = new Set(parsedReadLogs); } catch (error) { logger$9.error("Failed to parse read logs:", error); } } } _saveLogs() { const currentLogs = this._logs.get(); Cookies.set("eventLogs", JSON.stringify(currentLogs)); } _saveReadLogs() { if (typeof window === "undefined") { return; } localStorage.setItem("bolt_read_logs", JSON.stringify(Array.from(this._readLogs))); } _generateId() { return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`; } _trimLogs() { const currentLogs = Object.entries(this._logs.get()); if (currentLogs.length > MAX_LOGS) { const sortedLogs = currentLogs.sort( ([, a], [, b]) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime() ); const newLogs = Object.fromEntries(sortedLogs.slice(0, MAX_LOGS)); this._logs.set(newLogs); } } // Base log method for general logging _addLog(message, level, category, details, metadata) { const id = this._generateId(); const entry = { id, timestamp: (/* @__PURE__ */ new Date()).toISOString(), level, message, details, category, metadata }; this._logs.setKey(id, entry); this._trimLogs(); this._saveLogs(); return id; } // Specialized method for API logging _addApiLog(message, method, url, details) { const statusCode = details.statusCode; return this._addLog(message, statusCode >= 400 ? "error" : "info", "api", details, { component: "api", action: method }); } // System events logSystem(message, details) { return this._addLog(message, "info", "system", details); } // Provider events logProvider(message, details) { return this._addLog(message, "info", "provider", details); } // User actions logUserAction(message, details) { return this._addLog(message, "info", "user", details); } // API Connection Logging logAPIRequest(endpoint, method, duration, statusCode, details) { const message = `${method} ${endpoint} - ${statusCode} (${duration}ms)`; const level = statusCode >= 400 ? "error" : statusCode >= 300 ? "warning" : "info"; return this._addLog(message, level, "api", { ...details, endpoint, method, duration, statusCode, timestamp: (/* @__PURE__ */ new Date()).toISOString() }); } // Authentication Logging logAuth(action, success, details) { const message = `Auth ${action} - ${success ? "Success" : "Failed"}`; const level = success ? "info" : "error"; return this._addLog(message, level, "auth", { ...details, action, success, timestamp: (/* @__PURE__ */ new Date()).toISOString() }); } // Network Status Logging logNetworkStatus(status, details) { const message = `Network ${status}`; const level = status === "offline" ? "error" : status === "reconnecting" ? "warning" : "info"; return this._addLog(message, level, "network", { ...details, status, timestamp: (/* @__PURE__ */ new Date()).toISOString() }); } // Database Operations Logging logDatabase(operation, success, duration, details) { const message = `DB ${operation} - ${success ? "Success" : "Failed"} (${duration}ms)`; const level = success ? "info" : "error"; return this._addLog(message, level, "database", { ...details, operation, success, duration, timestamp: (/* @__PURE__ */ new Date()).toISOString() }); } // Error events logError(message, error, details) { const errorDetails = error instanceof Error ? { name: error.name, message: error.message, stack: error.stack, ...details } : { error, ...details }; return this._addLog(message, "error", "error", errorDetails); } // Warning events logWarning(message, details) { return this._addLog(message, "warning", "system", details); } // Debug events logDebug(message, details) { return this._addLog(message, "debug", "system", details); } clearLogs() { this._logs.set({}); this._saveLogs(); } getLogs() { return Object.values(this._logs.get()).sort( (a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime() ); } getFilteredLogs(level, category, searchQuery) { return this.getLogs().filter((log) => { const matchesLevel = !level || level === "debug" || log.level === level; const matchesCategory = !category || log.category === category; const matchesSearch = !searchQuery || log.message.toLowerCase().includes(searchQuery.toLowerCase()) || JSON.stringify(log.details).toLowerCase().includes(searchQuery.toLowerCase()); return matchesLevel && matchesCategory && matchesSearch; }); } markAsRead(logId) { this._readLogs.add(logId); this._saveReadLogs(); } isRead(logId) { return this._readLogs.has(logId); } clearReadLogs() { this._readLogs.clear(); this._saveReadLogs(); } // API interactions logApiCall(method, endpoint, statusCode, duration, requestData, responseData) { return this._addLog( `API ${method} ${endpoint}`, statusCode >= 400 ? "error" : "info", "api", { method, endpoint, statusCode, duration, request: requestData, response: responseData }, { component: "api", action: method } ); } // Network operations logNetworkRequest(method, url, statusCode, duration, requestData, responseData) { return this._addLog( `${method} ${url}`, statusCode >= 400 ? "error" : "info", "network", { method, url, statusCode, duration, request: requestData, response: responseData }, { component: "network", action: method } ); } // Authentication events logAuthEvent(event, success, details) { return this._addLog( `Auth ${event} ${success ? "succeeded" : "failed"}`, success ? "info" : "error", "auth", details, { component: "auth", action: event } ); } // Performance tracking logPerformance(operation, duration, details) { return this._addLog( `Performance: ${operation}`, duration > 1e3 ? "warning" : "info", "performance", { operation, duration, ...details }, { component: "performance", action: "metric" } ); } // Error handling logErrorWithStack(error, category = "error", details) { return this._addLog( error.message, "error", category, { ...details, name: error.name, stack: error.stack }, { component: category, action: "error" } ); } // Refresh logs (useful for real-time updates) refreshLogs() { const currentLogs = this._logs.get(); this._logs.set({ ...currentLogs }); } // Enhanced logging methods logInfo(message, details) { return this._addLog(message, "info", "system", details); } logSuccess(message, details) { return this._addLog(message, "info", "system", { ...details, success: true }); } logApiRequest(method, url, details) { return this._addApiLog(`API ${method} ${url}`, method, url, details); } logSettingsChange(component, setting, oldValue, newValue) { return this._addLog( `Settings changed in ${component}: ${setting}`, "info", "settings", { setting, previousValue: oldValue, newValue }, { component, action: "settings_change", previousValue: oldValue, newValue } ); } logFeatureToggle(featureId, enabled) { return this._addLog( `Feature ${featureId} ${enabled ? "enabled" : "disabled"}`, "info", "feature", { featureId, enabled }, { component: "features", action: "feature_toggle" } ); } logTaskOperation(taskId, operation, status, details) { return this._addLog( `Task ${taskId}: ${operation} - ${status}`, "info", "task", { taskId, operation, status, ...details }, { component: "task-manager", action: "task_operation" } ); } logProviderAction(provider, action, success, details) { return this._addLog( `Provider ${provider}: ${action} - ${success ? "Success" : "Failed"}`, success ? "info" : "error", "provider", { provider, action, success, ...details }, { component: "providers", action: "provider_action" } ); } logPerformanceMetric(component, operation, duration, details) { return this._addLog( `Performance: ${component} - ${operation} took ${duration}ms`, duration > 1e3 ? "warning" : "info", "performance", { component, operation, duration, ...details }, { component, action: "performance_metric" } ); } } const logStore = new LogStore(); const DEFAULT_THEME = "dark"; const themeStore = atom(initStore()); function initStore() { return DEFAULT_THEME; } function stripIndents(arg0, ...values) { if (typeof arg0 !== "string") { const processedString = arg0.reduce((acc, curr, i) => { acc += curr + (values[i] ?? ""); return acc; }, ""); return _stripIndents(processedString); } return _stripIndents(arg0); } function _stripIndents(value) { return value.split("\n").map((line) => line.trim()).join("\n").trimStart().replace(/[\r\n]$/, ""); } const reactToastifyStyles = "/assets/ReactToastify-Bh76j7cs.css"; const globalStyles = "/assets/index-CM_WZdAp.css"; const xtermStyles = "/assets/xterm-LZoznX6r.css"; const links = () => [ { rel: "icon", href: "/favicon.svg", type: "image/svg+xml" }, { rel: "stylesheet", href: reactToastifyStyles }, { rel: "stylesheet", href: tailwindReset }, { rel: "stylesheet", href: globalStyles }, { rel: "stylesheet", href: xtermStyles }, { rel: "preconnect", href: "https://fonts.googleapis.com" }, { rel: "preconnect", href: "https://fonts.gstatic.com", crossOrigin: "anonymous" }, { rel: "stylesheet", href: "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" } ]; const inlineThemeCode = stripIndents` document.querySelector('html')?.setAttribute('data-theme', 'dark'); `; const Head = createHead(() => /* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsx("meta", { charSet: "utf-8" }), /* @__PURE__ */ jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }), /* @__PURE__ */ jsx(Meta, {}), /* @__PURE__ */ jsx(Links, {}), /* @__PURE__ */ jsx("script", { dangerouslySetInnerHTML: { __html: inlineThemeCode } }) ] })); function Layout({ children }) { const theme = useStore(themeStore); useEffect(() => { document.querySelector("html")?.setAttribute("data-theme", theme); }, [theme]); return /* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsx(ClientOnly, { children: () => /* @__PURE__ */ jsx(DndProvider, { backend: HTML5Backend, children }) }), /* @__PURE__ */ jsx(ScrollRestoration, {}), /* @__PURE__ */ jsx(Scripts, {}) ] }); } function App() { const theme = useStore(themeStore); useEffect(() => { logStore.logSystem("Application initialized", { theme, platform: navigator.platform, userAgent: navigator.userAgent, timestamp: (/* @__PURE__ */ new Date()).toISOString() }); }, []); return /* @__PURE__ */ jsx(Layout, { children: /* @__PURE__ */ jsx(Outlet, {}) }); } const route0 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({ __proto__: null, Head, Layout, default: App, links }, Symbol.toStringTag, { value: 'Module' })); async function handleRequest(request, responseStatusCode, responseHeaders, remixContext, _loadContext) { const readable = await renderToReadableStream(/* @__PURE__ */ jsx(RemixServer, { context: remixContext, url: request.url }), { signal: request.signal, onError(error) { console.error(error); responseStatusCode = 500; } }); const body = new ReadableStream({ start(controller) { const head = renderHeadToString({ request, remixContext, Head }); controller.enqueue( new Uint8Array( new TextEncoder().encode( `${head}
` ) ) ); const reader = readable.getReader(); function read() { reader.read().then(({ done, value }) => { if (done) { controller.enqueue(new Uint8Array(new TextEncoder().encode("
"))); controller.close(); return; } controller.enqueue(value); read(); }).catch((error) => { controller.error(error); readable.cancel(); }); } read(); }, cancel() { readable.cancel(); } }); if (isbot(request.headers.get("user-agent") || "")) { await readable.allReady; } responseHeaders.set("Content-Type", "text/html"); responseHeaders.set("Cross-Origin-Embedder-Policy", "require-corp"); responseHeaders.set("Cross-Origin-Opener-Policy", "same-origin"); return new Response(body, { headers: responseHeaders, status: responseStatusCode }); } const entryServer = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({ __proto__: null, default: handleRequest }, Symbol.toStringTag, { value: 'Module' })); const loader$h = async ({ request }) => { const url = new URL(request.url); const editorOrigin = url.searchParams.get("editorOrigin") || "https://stackblitz.com"; console.log("editorOrigin", editorOrigin); const htmlContent = ` Connect to WebContainer