upfynai-code 3.0.3 → 3.1.0
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/README.md +66 -91
- package/bin/cli.js +191 -0
- package/{client/dist → dist/client}/api-docs.html +838 -838
- package/{client/dist/assets/AppContent-Bvg0CPCO.js → dist/client/assets/AppContent-BofJquUs.js} +43 -43
- package/dist/client/assets/BrowserPanel-CSvD4jOX.js +2 -0
- package/dist/client/assets/CanvasFullScreen-onRfarpc.js +1 -0
- package/dist/client/assets/CanvasWorkspace-DvGKdL-k.js +259 -0
- package/dist/client/assets/DashboardPanel-DqAHbXDO.js +1 -0
- package/dist/client/assets/FileTree-BE0h-9M9.js +1 -0
- package/{client/dist/assets/GitPanel-RtyZUIWS.js → dist/client/assets/GitPanel-DdeJ0bp5.js} +2 -2
- package/{client/dist/assets/LoginModal-BWep8a6g.js → dist/client/assets/LoginModal-BP0pCTrH.js} +3 -3
- package/{client/dist/assets/MarkdownPreview-DHmk3qzu.js → dist/client/assets/MarkdownPreview-CESjI261.js} +1 -1
- package/dist/client/assets/MermaidBlock-D0rfEhrT.js +2 -0
- package/dist/client/assets/Onboarding-B2zQy-_6.js +1 -0
- package/dist/client/assets/SetupForm-Be7-WBe-.js +1 -0
- package/dist/client/assets/WorkflowsPanel-CusLbVJ6.js +1 -0
- package/{client/dist/assets/index-C5ptjuTl.js → dist/client/assets/index-BQy15irW.js} +25 -25
- package/dist/client/assets/index-CS0fDqEC.js +1 -0
- package/dist/client/assets/index-DYLSCCCp.css +1 -0
- package/dist/client/assets/vendor-canvas-QWTduIvM.js +23 -0
- package/{client/dist/assets/vendor-codemirror-CbtmxxaB.js → dist/client/assets/vendor-codemirror-D2ALgpaX.js} +1 -1
- package/{client/dist/assets/vendor-icons-BaD0x9SL.js → dist/client/assets/vendor-icons-kix3Gb31.js} +178 -138
- package/{client/dist/assets/vendor-mermaid-CH7SGc99.js → dist/client/assets/vendor-mermaid-CS3J4_Bz.js} +329 -326
- package/{client/dist/assets/vendor-syntax-DuHI9Ok6.js → dist/client/assets/vendor-syntax-LS_Nt30I.js} +1 -1
- package/{client/dist → dist/client}/clear-cache.html +85 -85
- package/dist/client/favicon.png +0 -0
- package/dist/client/favicon.svg +15 -0
- package/{client/dist → dist/client}/index.html +17 -17
- package/{client/dist → dist/client}/manifest.json +15 -15
- package/{client/dist → dist/client}/mcp-docs.html +108 -108
- package/{client/dist → dist/client}/offline.html +84 -84
- package/{client/dist → dist/client}/sw.js +82 -82
- package/package.json +55 -104
- package/scripts/postinstall.js +9 -0
- package/scripts/prepublish.js +77 -0
- package/src/animation.js +228 -0
- package/src/auth.js +142 -0
- package/src/config.js +40 -0
- package/src/connect.js +416 -0
- package/src/launch.js +81 -0
- package/src/mcp.js +57 -0
- package/src/permissions.js +140 -0
- package/src/persistent-shell.js +261 -0
- package/src/server.js +54 -0
- package/client/dist/assets/CanvasFullScreen-BdiJ35aq.js +0 -1
- package/client/dist/assets/CanvasWorkspace-Bk9R9_e0.js +0 -163
- package/client/dist/assets/DashboardPanel-CblJfTGi.js +0 -1
- package/client/dist/assets/FileTree-BDUnBheV.js +0 -1
- package/client/dist/assets/MermaidBlock-BuBc_G-F.js +0 -2
- package/client/dist/assets/Onboarding-Drnlt75a.js +0 -1
- package/client/dist/assets/SetupForm-CtCKitZG.js +0 -1
- package/client/dist/assets/WorkflowsPanel-B2mIXDvD.js +0 -1
- package/client/dist/assets/index-BFuqS0tY.css +0 -1
- package/client/dist/assets/vendor-canvas-D39yWul6.js +0 -49
- package/client/dist/favicon.png +0 -0
- package/client/dist/favicon.svg +0 -5
- package/commands/upfynai-connect.md +0 -59
- package/commands/upfynai-disconnect.md +0 -31
- package/commands/upfynai-doctor.md +0 -99
- package/commands/upfynai-export.md +0 -49
- package/commands/upfynai-local.md +0 -82
- package/commands/upfynai-status.md +0 -75
- package/commands/upfynai-stop.md +0 -49
- package/commands/upfynai-uninstall.md +0 -58
- package/commands/upfynai.md +0 -69
- package/scripts/build-client.js +0 -17
- package/scripts/fix-node-pty.js +0 -67
- package/scripts/install-commands.js +0 -78
- package/server/agent-loop.js +0 -242
- package/server/auto-compact.js +0 -99
- package/server/claude-sdk.js +0 -797
- package/server/cli-ui.js +0 -798
- package/server/cli.js +0 -751
- package/server/constants/config.js +0 -31
- package/server/cursor-cli.js +0 -270
- package/server/database/auth.db +0 -0
- package/server/database/db.js +0 -1451
- package/server/database/init.sql +0 -70
- package/server/index.js +0 -3814
- package/server/load-env.js +0 -26
- package/server/mcp-server.js +0 -621
- package/server/middleware/auth.js +0 -181
- package/server/middleware/relayHelpers.js +0 -44
- package/server/middleware/sandboxRouter.js +0 -174
- package/server/openai-codex.js +0 -403
- package/server/openrouter.js +0 -137
- package/server/projects.js +0 -1807
- package/server/provider-factory.js +0 -174
- package/server/relay-client.js +0 -390
- package/server/routes/agent.js +0 -1234
- package/server/routes/auth.js +0 -559
- package/server/routes/canvas.js +0 -53
- package/server/routes/cli-auth.js +0 -263
- package/server/routes/codex.js +0 -396
- package/server/routes/commands.js +0 -707
- package/server/routes/composio.js +0 -176
- package/server/routes/cursor.js +0 -770
- package/server/routes/dashboard.js +0 -295
- package/server/routes/git.js +0 -1208
- package/server/routes/keys.js +0 -34
- package/server/routes/mcp-utils.js +0 -48
- package/server/routes/mcp.js +0 -661
- package/server/routes/payments.js +0 -227
- package/server/routes/projects.js +0 -655
- package/server/routes/sessions.js +0 -146
- package/server/routes/settings.js +0 -261
- package/server/routes/taskmaster.js +0 -1928
- package/server/routes/user.js +0 -106
- package/server/routes/vapi-chat.js +0 -624
- package/server/routes/voice.js +0 -235
- package/server/routes/webhooks.js +0 -166
- package/server/routes/workflows.js +0 -312
- package/server/sandbox.js +0 -120
- package/server/services/composio.js +0 -204
- package/server/services/sessionRegistry.js +0 -139
- package/server/services/whisperService.js +0 -84
- package/server/services/workflowScheduler.js +0 -211
- package/server/tests/relay-flow.test.js +0 -570
- package/server/tests/sessions.test.js +0 -259
- package/server/utils/commandParser.js +0 -303
- package/server/utils/email.js +0 -66
- package/server/utils/gitConfig.js +0 -24
- package/server/utils/mcp-detector.js +0 -198
- package/server/utils/taskmaster-websocket.js +0 -129
- package/shared/integrationCatalog.d.ts +0 -12
- package/shared/integrationCatalog.js +0 -172
- package/shared/modelConstants.js +0 -96
- /package/{shared → dist}/agents/claude.js +0 -0
- /package/{shared → dist}/agents/codex.js +0 -0
- /package/{shared → dist}/agents/cursor.js +0 -0
- /package/{shared → dist}/agents/detect.js +0 -0
- /package/{shared → dist}/agents/exec.js +0 -0
- /package/{shared → dist}/agents/files.js +0 -0
- /package/{shared → dist}/agents/git.js +0 -0
- /package/{shared → dist}/agents/gitagent.js +0 -0
- /package/{shared → dist}/agents/index.js +0 -0
- /package/{shared → dist}/agents/shell.js +0 -0
- /package/{shared → dist}/agents/utils.js +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- /package/{client/dist → dist/client}/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- /package/{client/dist → dist/client}/assets/PreviewPanel-CqCa92Tf.js +0 -0
- /package/{client/dist → dist/client}/assets/pdf-CE_K4jFx.js +0 -0
- /package/{client/dist → dist/client}/assets/vendor-canvas-BZV40eAE.css +0 -0
- /package/{client/dist → dist/client}/assets/vendor-diff-DNQpbhrT.js +0 -0
- /package/{client/dist → dist/client}/assets/vendor-i18n-DCFGyhQR.js +0 -0
- /package/{client/dist → dist/client}/assets/vendor-markdown-CimbIo6Y.js +0 -0
- /package/{client/dist → dist/client}/assets/vendor-react-96lCPsRK.js +0 -0
- /package/{client/dist → dist/client}/assets/vendor-xterm-CZq1hqo1.js +0 -0
- /package/{client/dist → dist/client}/assets/vendor-xterm-qxJ8_QYu.css +0 -0
- /package/{client/dist → dist/client}/convert-icons.md +0 -0
- /package/{client/dist → dist/client}/generate-icons.js +0 -0
- /package/{client/dist → dist/client}/icons/claude-ai-icon.svg +0 -0
- /package/{client/dist → dist/client}/icons/codex-white.svg +0 -0
- /package/{client/dist → dist/client}/icons/codex.svg +0 -0
- /package/{client/dist → dist/client}/icons/cursor-white.svg +0 -0
- /package/{client/dist → dist/client}/icons/cursor.svg +0 -0
- /package/{client/dist → dist/client}/icons/icon-128x128.png +0 -0
- /package/{client/dist → dist/client}/icons/icon-128x128.svg +0 -0
- /package/{client/dist → dist/client}/icons/icon-144x144.png +0 -0
- /package/{client/dist → dist/client}/icons/icon-144x144.svg +0 -0
- /package/{client/dist → dist/client}/icons/icon-152x152.png +0 -0
- /package/{client/dist → dist/client}/icons/icon-152x152.svg +0 -0
- /package/{client/dist → dist/client}/icons/icon-192x192.png +0 -0
- /package/{client/dist → dist/client}/icons/icon-192x192.svg +0 -0
- /package/{client/dist → dist/client}/icons/icon-384x384.png +0 -0
- /package/{client/dist → dist/client}/icons/icon-384x384.svg +0 -0
- /package/{client/dist → dist/client}/icons/icon-512x512.png +0 -0
- /package/{client/dist → dist/client}/icons/icon-512x512.svg +0 -0
- /package/{client/dist → dist/client}/icons/icon-72x72.png +0 -0
- /package/{client/dist → dist/client}/icons/icon-72x72.svg +0 -0
- /package/{client/dist → dist/client}/icons/icon-96x96.png +0 -0
- /package/{client/dist → dist/client}/icons/icon-96x96.svg +0 -0
- /package/{client/dist → dist/client}/icons/icon-template.svg +0 -0
- /package/{client/dist → dist/client}/logo-128.png +0 -0
- /package/{client/dist → dist/client}/logo-256.png +0 -0
- /package/{client/dist → dist/client}/logo-32.png +0 -0
- /package/{client/dist → dist/client}/logo-512.png +0 -0
- /package/{client/dist → dist/client}/logo-64.png +0 -0
- /package/{client/dist → dist/client}/logo.svg +0 -0
- /package/{client/dist → dist/client}/screenshots/cli-selection.png +0 -0
- /package/{client/dist → dist/client}/screenshots/desktop-main.png +0 -0
- /package/{client/dist → dist/client}/screenshots/mobile-chat.png +0 -0
- /package/{client/dist → dist/client}/screenshots/tools-modal.png +0 -0
- /package/{shared → dist}/gitagent/index.js +0 -0
- /package/{shared → dist}/gitagent/parser.js +0 -0
- /package/{shared → dist}/gitagent/prompt-builder.js +0 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{j as e,r as n}from"./vendor-react-96lCPsRK.js";import{b as N}from"./index-BQy15irW.js";import{bm as te,A as se,Z,X as z,bn as re,M as oe,U as ae,bo as ne,q as B,T as K,E as ie,a2 as le,bp as ce,L as de,a as ue,bq as me,br as xe}from"./vendor-icons-kix3Gb31.js";import"./vendor-syntax-LS_Nt30I.js";import"./vendor-markdown-CimbIo6Y.js";import"./vendor-i18n-DCFGyhQR.js";function pe({url:u,onUrlChange:t,onNavigate:c,onRefresh:m,mode:f,onModeChange:r,hasSession:i,onNewSession:h,onCloseSession:x,isLoading:C}){const $=k=>{if(k.key==="Enter"){let p=u.trim();p&&!p.startsWith("http://")&&!p.startsWith("https://")&&(p=`https://${p}`),c(p)}};return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-muted/30 border-b border-border/40",children:[e.jsx("div",{className:"flex items-center gap-0.5",children:e.jsx("button",{onClick:m,disabled:!i||C,className:"p-1.5 rounded-md hover:bg-muted/60 text-muted-foreground hover:text-foreground disabled:opacity-30 transition-colors",title:"Refresh",children:e.jsx(te,{className:`w-3.5 h-3.5 ${C?"animate-spin":""}`})})}),e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 bg-background rounded-lg border border-border/40 focus-within:border-primary/40 transition-colors",children:[e.jsx(se,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),e.jsx("input",{type:"text",value:u,onChange:k=>t(k.target.value),onKeyDown:$,placeholder:i?"Enter URL or search...":"Launch a browser session first",disabled:!i,className:"flex-1 text-sm bg-transparent outline-none text-foreground placeholder:text-muted-foreground/50"})]}),e.jsxs("div",{className:"flex items-center bg-muted/40 rounded-lg p-0.5",children:[e.jsx("button",{onClick:()=>r("chat"),className:`px-2.5 py-1 text-[11px] font-medium rounded-md transition-colors ${f==="chat"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"Chat"}),e.jsxs("button",{onClick:()=>r("autonomous"),className:`px-2.5 py-1 text-[11px] font-medium rounded-md transition-colors flex items-center gap-1 ${f==="autonomous"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[e.jsx(Z,{className:"w-3 h-3"}),"Auto"]})]}),i?e.jsx("button",{onClick:x,className:"p-1.5 rounded-md hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors",title:"Close browser session",children:e.jsx(z,{className:"w-3.5 h-3.5"})}):e.jsxs("button",{onClick:h,disabled:C,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium bg-primary text-primary-foreground rounded-lg hover:opacity-90 disabled:opacity-50 transition-opacity",children:[e.jsx(re,{className:"w-3.5 h-3.5"}),"Launch"]})]})}function fe({viewerUrl:u,hasSession:t,isLoading:c,onNewSession:m}){return t?u?e.jsx("div",{className:"flex-1 relative bg-black",children:e.jsx("iframe",{src:u,title:"Browser Session",className:"absolute inset-0 w-full h-full border-0",sandbox:"allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox",allow:"clipboard-read; clipboard-write"})}):e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/10",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("div",{className:"w-4 h-4 border-2 border-muted-foreground/30 border-t-muted-foreground rounded-full animate-spin"}),"Connecting to browser session..."]})}):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 bg-muted/10 text-muted-foreground",children:[e.jsx(oe,{className:"w-12 h-12 opacity-30"}),e.jsxs("div",{className:"text-center space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"No browser session active"}),e.jsx("p",{className:"text-xs opacity-70",children:"Launch a session to start browsing or preview your sandbox apps"})]}),e.jsx("button",{onClick:m,disabled:c,className:"px-4 py-2 text-sm font-medium bg-primary text-primary-foreground rounded-lg hover:opacity-90 disabled:opacity-50 transition-opacity",children:c?"Launching...":"Launch Browser"})]})}function he({value:u,onChange:t,onSubmit:c,onStop:m,mode:f,isRunning:r,hasSession:i}){const h=x=>{x.key==="Enter"&&!x.shiftKey&&(x.preventDefault(),u.trim()&&!r&&c())};return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-muted/30 border-t border-border/40",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-2 bg-background rounded-lg border border-border/40 focus-within:border-primary/40 transition-colors",children:[f==="autonomous"&&e.jsx(Z,{className:"w-3.5 h-3.5 text-amber-500 flex-shrink-0"}),e.jsx("input",{type:"text",value:u,onChange:x=>t(x.target.value),onKeyDown:h,placeholder:i?f==="chat"?'Tell the AI what to do... (e.g., "Click the login button")':'Set a goal... (e.g., "Fill out the registration form")':"Launch a session first",disabled:!i||r,className:"flex-1 text-sm bg-transparent outline-none text-foreground placeholder:text-muted-foreground/50"})]}),r?e.jsx("button",{onClick:m,className:"p-2 rounded-lg bg-destructive/10 text-destructive hover:bg-destructive/20 transition-colors",title:"Stop",children:e.jsx(ae,{className:"w-4 h-4"})}):e.jsx("button",{onClick:c,disabled:!i||!u.trim(),className:"p-2 rounded-lg bg-primary text-primary-foreground hover:opacity-90 disabled:opacity-30 transition-opacity",title:"Send",children:e.jsx(ne,{className:"w-4 h-4"})})]})}const be={act:ce,extract:le,observe:ie,navigate:B,error:K,info:B};function ge({actions:u,consoleErrors:t,isVisible:c,onClose:m,onFixError:f}){return c?e.jsxs("div",{className:"w-64 flex-shrink-0 border-l border-border/40 bg-muted/10 flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border/40",children:[e.jsx("span",{className:"text-xs font-medium text-foreground",children:"Action Log"}),e.jsx("button",{onClick:m,className:"p-1 rounded hover:bg-muted/60 text-muted-foreground",children:e.jsx(z,{className:"w-3 h-3"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[u.length===0&&t.length===0&&e.jsx("div",{className:"p-3 text-xs text-muted-foreground/60 text-center",children:"AI actions and console errors will appear here"}),u.map(r=>{const i=be[r.type]||B;return e.jsx("div",{className:"px-3 py-2 border-b border-border/20 hover:bg-muted/20 transition-colors",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:r.status==="running"?e.jsx(de,{className:"w-3 h-3 text-primary animate-spin"}):r.status==="error"?e.jsx(K,{className:"w-3 h-3 text-destructive"}):e.jsx(i,{className:"w-3 h-3 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground/60 font-mono",children:["#",r.step]}),e.jsx("span",{className:"text-[10px] uppercase text-muted-foreground/60 font-medium",children:r.type})]}),e.jsx("p",{className:"text-xs text-foreground truncate",children:r.instruction}),r.result&&e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5 line-clamp-2",children:r.result})]}),r.status==="done"&&e.jsx(ue,{className:"w-3 h-3 text-emerald-500 flex-shrink-0 mt-0.5"})]})},r.id)}),t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-1.5 bg-destructive/5 border-y border-destructive/10",children:e.jsxs("span",{className:"text-[10px] font-medium text-destructive uppercase tracking-wide",children:["Console Errors (",t.length,")"]})}),t.map((r,i)=>e.jsxs("div",{className:"px-3 py-2 border-b border-border/20 hover:bg-destructive/5 transition-colors",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(K,{className:"w-3 h-3 text-destructive flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs text-foreground line-clamp-3 font-mono",children:r.message}),r.source&&e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:[r.source,r.line?`:${r.line}`:""]})]})]}),e.jsxs("button",{onClick:()=>f(r),className:"mt-1.5 flex items-center gap-1 px-2 py-1 text-[10px] font-medium text-primary bg-primary/10 rounded hover:bg-primary/20 transition-colors",children:[e.jsx(me,{className:"w-2.5 h-2.5"}),"Fix this error"]})]},`err-${i}`))]})]})]}):null}function ke({selectedProject:u}){const[t,c]=n.useState(null),[m,f]=n.useState(""),[r,i]=n.useState("chat"),[h,x]=n.useState(""),[C,$]=n.useState(!1),[k,p]=n.useState(!1),[M,D]=n.useState([]),[S,G]=n.useState([]),[P,R]=n.useState(!1),[W,v]=n.useState(null),E=n.useRef(0),F=n.useRef(null);n.useEffect(()=>{let s=!1;return(async()=>{var o;try{const a=await N.browser.listSessions();if(s)return;if(a.ok){const l=(o=(await a.json()).sessions)==null?void 0:o[0];l&&c({sessionId:l.steel_session_id||l.id,viewerUrl:l.viewer_url||l.viewerUrl||null,status:"active"})}}catch{}})(),()=>{s=!0}},[]);const q=n.useCallback(async()=>{$(!0),v(null);try{const s=await N.browser.createSession();if(!s.ok){const a=await s.json().catch(()=>({}));throw new Error(a.error||"Failed to create session")}const o=await s.json();c({sessionId:o.sessionId||o.id,viewerUrl:o.viewerUrl||o.sessionViewerUrl||null,status:"active"})}catch(s){v(s.message||"Failed to launch browser")}finally{$(!1)}},[]),J=n.useCallback(async()=>{if(t){c(s=>s?{...s,status:"closing"}:null);try{await N.browser.closeSession(t.sessionId)}catch{}c(null),f(""),D([]),G([]),E.current=0}},[t]),X=n.useCallback(async s=>{if(!(!t||!s)){f(s);try{const o=await N.browser.navigate(t.sessionId,s);if(!o.ok){const a=await o.json().catch(()=>({}));v(a.error||"Navigation failed")}}catch{v("Navigation failed")}}},[t]),H=n.useCallback(async()=>{if(!(!t||!m))try{await N.browser.navigate(t.sessionId,m)}catch{}},[t,m]),I=n.useCallback(s=>{E.current+=1;const o={...s,id:`action-${Date.now()}-${E.current}`,step:E.current};return D(a=>[...a,o]),R(!0),o.id},[]),w=n.useCallback((s,o)=>{D(a=>a.map(d=>d.id===s?{...d,...o}:d))},[]),V=n.useCallback(async()=>{if(!t||!h.trim())return;const s=h.trim();x(""),p(!0),v(null);const o=I({type:"act",instruction:s,timestamp:Date.now(),status:"running"});try{const a=await N.browser.aiAct(t.sessionId,s);if(a.ok){const d=await a.json();w(o,{status:"done",result:d.result||"Done"})}else{const d=await a.json().catch(()=>({}));w(o,{status:"error",result:d.error||"Action failed"})}}catch(a){w(o,{status:"error",result:a.message||"Action failed"})}finally{p(!1)}},[t,h,I,w]),_=n.useCallback(async()=>{var d;if(!t||!h.trim())return;const s=h.trim();x(""),p(!0),v(null);const o=new AbortController;F.current=o;const a=I({type:"info",instruction:`Goal: ${s}`,timestamp:Date.now(),status:"running"});try{const l=await fetch(`/api/browser/sessions/${t.sessionId}/ai/autonomous?goal=${encodeURIComponent(s)}&maxSteps=20`,{credentials:"include",signal:o.signal});if(!l.ok){const y=await l.json().catch(()=>({}));w(a,{status:"error",result:y.error||"Failed"});return}const A=(d=l.body)==null?void 0:d.getReader(),b=new TextDecoder;let U="";if(A)for(;;){const{done:y,value:L}=await A.read();if(y)break;U+=b.decode(L,{stream:!0});const j=U.split(`
|
|
2
|
+
`);U=j.pop()||"";for(const O of j){if(!O.startsWith("data: "))continue;const T=O.slice(6).trim();if(!(!T||T==="[DONE]"))try{const g=JSON.parse(T);g.type==="step"?I({type:g.actionType||"act",instruction:g.instruction||g.description||"",result:g.result,timestamp:Date.now(),status:g.status==="error"?"error":"done"}):g.type==="complete"?w(a,{status:"done",result:g.message||"Goal completed"}):g.type==="error"&&w(a,{status:"error",result:g.error||"Autonomous run failed"})}catch{}}}D(y=>{const L=y.find(j=>j.id===a);return L&&L.status==="running"?y.map(j=>j.id===a?{...j,status:"done",result:"Completed"}:j):y})}catch(l){l.name!=="AbortError"&&w(a,{status:"error",result:l.message||"Autonomous run failed"})}finally{p(!1),F.current=null}},[t,h,I,w]),Q=n.useCallback(()=>{r==="chat"?V():_()},[r,V,_]),Y=n.useCallback(()=>{var s;(s=F.current)==null||s.abort(),p(!1)},[]),ee=n.useCallback(s=>{const o=`Fix this console error: ${s.message}${s.source?` (source: ${s.source}:${s.line})`:""}`;x(o),i("chat")},[]);return n.useEffect(()=>{if(!t||t.status!=="active")return;let s=!1;const o=async()=>{var d;try{const l=await N.browser.consoleErrors(t.sessionId);if(s||!l.ok)return;const A=await l.json();(d=A.errors)!=null&&d.length&&G(A.errors.map(b=>({message:b.message||b.text||String(b),source:b.source||b.url,line:b.line||b.lineNumber,timestamp:b.timestamp||Date.now()})))}catch{}},a=setInterval(o,1e4);return o(),()=>{s=!0,clearInterval(a)}},[t]),e.jsxs("div",{className:"h-full flex flex-col bg-background",children:[e.jsx(pe,{url:m,onUrlChange:f,onNavigate:X,onRefresh:H,mode:r,onModeChange:i,hasSession:(t==null?void 0:t.status)==="active",onNewSession:q,onCloseSession:J,isLoading:C}),W&&e.jsxs("div",{className:"px-3 py-1.5 bg-destructive/10 border-b border-destructive/20 text-xs text-destructive flex items-center justify-between",children:[e.jsx("span",{children:W}),e.jsx("button",{onClick:()=>v(null),className:"text-destructive/70 hover:text-destructive",children:"Dismiss"})]}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsx(fe,{viewerUrl:(t==null?void 0:t.viewerUrl)||null,hasSession:!!t,isLoading:C,onNewSession:q}),!P&&(M.length>0||S.length>0)&&e.jsxs("button",{onClick:()=>R(!0),className:"absolute right-2 top-14 z-10 p-1.5 rounded-md bg-muted/80 border border-border/40 text-muted-foreground hover:text-foreground transition-colors",title:"Show action log",children:[e.jsx(xe,{className:"w-3.5 h-3.5"}),S.length>0&&e.jsx("span",{className:"absolute -top-1 -right-1 w-3 h-3 bg-destructive rounded-full text-[8px] text-white flex items-center justify-center",children:S.length>9?"!":S.length})]}),e.jsx(ge,{actions:M,consoleErrors:S,isVisible:P,onClose:()=>R(!1),onFixError:ee})]}),e.jsx(he,{value:h,onChange:x,onSubmit:Q,onStop:Y,mode:r,isRunning:k,hasSession:(t==null?void 0:t.status)==="active"})]})}export{ke as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as x,h as p,r as u,j as e}from"./vendor-react-96lCPsRK.js";import{u as f}from"./index-BQy15irW.js";import h from"./CanvasWorkspace-DvGKdL-k.js";import"./vendor-syntax-LS_Nt30I.js";import"./vendor-markdown-CimbIo6Y.js";import"./vendor-icons-kix3Gb31.js";import"./vendor-i18n-DCFGyhQR.js";import"./vendor-canvas-QWTduIvM.js";function C(){const{projectName:s}=x(),r=p(),{sendMessage:l,latestMessage:m,connectionState:t}=f();if(u.useEffect(()=>{const n=o=>{var c,d;const i=(d=(c=o.target)==null?void 0:c.tagName)==null?void 0:d.toLowerCase();o.key==="Escape"&&i!=="input"&&i!=="textarea"&&r("/")};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[r]),!s)return e.jsx("div",{className:"flex items-center justify-center h-screen bg-background text-muted-foreground",children:"No project selected"});const a=decodeURIComponent(s);return e.jsxs("div",{className:"fixed inset-0 bg-background flex flex-col z-50",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border/50 bg-card/50 backdrop-blur-sm shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>r("/"),className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})}),"Back"]}),e.jsx("div",{className:"h-4 w-px bg-border/50"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 5a1 1 0 011-1h14a1 1 0 011 1v2a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM4 13a1 1 0 011-1h6a1 1 0 011 1v6a1 1 0 01-1 1H5a1 1 0 01-1-1v-6zM16 13a1 1 0 011-1h2a1 1 0 011 1v6a1 1 0 01-1 1h-2a1 1 0 01-1-1v-6z"})}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:a}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary border border-primary/20 font-medium",children:"Canvas"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t!=="connected"&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] px-2 py-0.5 rounded-full border border-amber-500/20 bg-amber-500/5 text-amber-400",children:[e.jsx("div",{className:"w-1.5 h-1.5 bg-amber-400 rounded-full animate-pulse"}),t==="reconnecting"?"Reconnecting...":"Offline"]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Press Esc to exit"})]})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(h,{projectName:a,sendMessage:l,latestMessage:m,isFullScreen:!0})})]})}export{C as default};
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-CS0fDqEC.js","assets/vendor-react-96lCPsRK.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{b as Ue}from"./vendor-syntax-LS_Nt30I.js";import{r as s,j as e,R as gt}from"./vendor-react-96lCPsRK.js";import{H as z,P as H,R as bt,u as ft,d as yt,e as vt,f as jt,g as wt,B as kt,h as Nt,C as Ct,M as St}from"./vendor-canvas-QWTduIvM.js";import{M as $t,a as Lt}from"./vendor-markdown-CimbIo6Y.js";import{b as oe,u as Et}from"./index-BQy15irW.js";import"./vendor-icons-kix3Gb31.js";import"./vendor-i18n-DCFGyhQR.js";function Tt({onAddNote:r,onAddPdf:l,onRun:h,onStop:t,onClearAi:c,onAutoLayout:u,onExport:d,onTemplates:a,onSwarm:m,isRunning:n}){const b=s.useRef(null),i=s.useCallback(v=>{var j;const x=(j=v.target.files)==null?void 0:j[0];x&&x.type==="application/pdf"&&l(x),b.current&&(b.current.value="")},[l]),o=[{label:"Add Note",icon:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),onClick:r,color:"hover:bg-blue-50 hover:text-blue-600"},{label:"Add PDF",icon:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"})}),onClick:()=>{var v;return(v=b.current)==null?void 0:v.click()},color:"hover:bg-red-50 hover:text-red-600"},{type:"divider"},{label:n?"Stop AI":"Run AI",icon:n?e.jsx("div",{className:"w-3 h-3 bg-red-500 rounded-sm"}):e.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{d:"M8 5v14l11-7z"})}),onClick:n?t:h,color:n?"bg-red-50 text-red-600 hover:bg-red-100":"hover:bg-green-50 hover:text-green-600"},{label:"Clear AI",icon:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),onClick:c,color:"hover:bg-gray-100 hover:text-gray-600"},{type:"divider"},{label:"Auto Layout",icon:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 10h16M4 14h16M4 18h16"})}),onClick:u,color:"hover:bg-indigo-50 hover:text-indigo-600"},{label:"Templates",icon:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 5a1 1 0 011-1h14a1 1 0 011 1v2a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM4 13a1 1 0 011-1h6a1 1 0 011 1v6a1 1 0 01-1 1H5a1 1 0 01-1-1v-6zM16 13a1 1 0 011-1h2a1 1 0 011 1v6a1 1 0 01-1 1h-2a1 1 0 01-1-1v-6z"})}),onClick:a||(()=>{}),color:"hover:bg-violet-50 hover:text-violet-600"},{label:"Swarm",icon:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),onClick:m||(()=>{}),color:"hover:bg-fuchsia-50 hover:text-fuchsia-600"},{label:"Export",icon:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),onClick:d,color:"hover:bg-emerald-50 hover:text-emerald-600"}];return e.jsxs("div",{className:"absolute top-1/2 left-3 -translate-y-1/2 z-20",children:[e.jsx("div",{className:"bg-white/90 backdrop-blur-sm border border-gray-200 rounded-xl shadow-lg p-1.5 flex flex-col gap-1",children:o.map((v,x)=>{if("type"in v&&v.type==="divider")return e.jsx("div",{className:"h-px bg-gray-200 mx-1 my-0.5"},x);const j=v;return e.jsx("button",{onClick:j.onClick,className:`w-8 h-8 rounded-lg flex items-center justify-center text-gray-500 transition-colors ${j.color}`,title:j.label,children:j.icon},j.label)})}),e.jsx("input",{ref:b,type:"file",accept:".pdf",onChange:i,className:"hidden"})]})}const Mt=s.memo(Tt),F={note:{bg:"bg-blue-50",border:"border-blue-300",accent:"text-blue-600",icon:"📝"},prompt:{bg:"bg-blue-50",border:"border-blue-400",accent:"text-blue-700",icon:"💬"},response:{bg:"bg-purple-50",border:"border-purple-300",accent:"text-purple-700",icon:"🤖"},research:{bg:"bg-teal-50",border:"border-teal-300",accent:"text-teal-700",icon:"🔍"},suggestion:{bg:"bg-amber-50",border:"border-amber-300",accent:"text-amber-700",icon:"💡"},pdf:{bg:"bg-red-50",border:"border-red-300",accent:"text-red-600",icon:"📄"},summary:{bg:"bg-green-50",border:"border-green-300",accent:"text-green-700",icon:"📋"},webpage:{bg:"bg-indigo-50",border:"border-indigo-300",accent:"text-indigo-700",icon:"🌐"},chat:{bg:"bg-sky-50",border:"border-sky-400",accent:"text-sky-700",icon:"💬"},deepresearch:{bg:"bg-cyan-50",border:"border-cyan-400",accent:"text-cyan-700",icon:"🔬"},image:{bg:"bg-pink-50",border:"border-pink-300",accent:"text-pink-600",icon:"🖼️"},table:{bg:"bg-slate-50",border:"border-slate-400",accent:"text-slate-700",icon:"📊"},list:{bg:"bg-violet-50",border:"border-violet-300",accent:"text-violet-600",icon:"📋"},inputs:{bg:"bg-orange-50",border:"border-orange-300",accent:"text-orange-600",icon:"⚙️"},comparison:{bg:"bg-fuchsia-50",border:"border-fuchsia-300",accent:"text-fuchsia-600",icon:"⚖️"},frame:{bg:"bg-gray-50",border:"border-gray-300",accent:"text-gray-600",icon:"📦"}},be=[{value:"sonnet",label:"Claude Sonnet",provider:"anthropic"},{value:"opus",label:"Claude Opus",provider:"anthropic"},{value:"haiku",label:"Claude Haiku",provider:"anthropic"},{value:"anthropic/claude-sonnet-4",label:"Claude Sonnet 4",provider:"openrouter"},{value:"anthropic/claude-opus-4",label:"Claude Opus 4",provider:"openrouter"},{value:"openai/gpt-4o",label:"GPT-4o",provider:"openrouter"},{value:"openai/o3",label:"O3",provider:"openrouter"},{value:"google/gemini-2.5-pro",label:"Gemini 2.5 Pro",provider:"openrouter"},{value:"meta-llama/llama-4-maverick",label:"Llama 4 Maverick",provider:"openrouter"},{value:"deepseek/deepseek-r1",label:"DeepSeek R1",provider:"openrouter"}],Dt=new Set(["prompt","response","research","suggestion","chat","deepresearch","image","table","list","comparison"]);function Be({id:r,data:l,nodeType:h}){const[t,c]=s.useState(!1),u=s.useRef(null);s.useEffect(()=>{if(!t)return;const n=b=>{u.current&&!u.current.contains(b.target)&&c(!1)};return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[t]);const d=be.find(n=>n.value===l.modelId),a=(d==null?void 0:d.label)||"Auto",m=be.reduce((n,b)=>(n[b.provider]||(n[b.provider]=[]),n[b.provider].push(b),n),{});return e.jsxs("div",{className:"relative",ref:u,children:[e.jsx("button",{onClick:n=>{n.stopPropagation(),c(!t)},className:"text-[9px] px-1.5 py-0.5 rounded-md bg-white/60 border border-gray-200 text-gray-500 hover:bg-white hover:text-gray-700 transition-colors truncate max-w-[80px]",title:`Model: ${a}`,children:a}),t&&e.jsxs("div",{className:"absolute top-full left-0 mt-1 w-48 bg-white border border-gray-200 rounded-lg shadow-xl z-50 py-1 max-h-60 overflow-y-auto",children:[e.jsx("button",{onClick:n=>{var b;n.stopPropagation(),(b=l.onModelChange)==null||b.call(l,r,"",""),c(!1)},className:`w-full text-left px-3 py-1.5 text-[11px] hover:bg-gray-50 ${l.modelId?"text-gray-600":"bg-primary/5 text-primary font-medium"}`,children:"Auto (default)"}),Object.entries(m).map(([n,b])=>e.jsxs("div",{children:[e.jsx("div",{className:"px-3 py-1 text-[9px] font-semibold text-gray-400 uppercase tracking-wider",children:n}),b.map(i=>e.jsx("button",{onClick:o=>{var v;o.stopPropagation(),(v=l.onModelChange)==null||v.call(l,r,i.value,i.provider),c(!1)},className:`w-full text-left px-3 py-1.5 text-[11px] hover:bg-gray-50 ${l.modelId===i.value?"bg-primary/5 text-primary font-medium":"text-gray-600"}`,children:i.label},i.value))]},n))]})]})}function _t({id:r,nodeType:l,data:h,selected:t,children:c,actions:u,hideModelSelector:d}){const a=F[l]||F.note,m=h.compact===!0,n=!d&&Dt.has(l);if(m){const b=h.status==="completed"?"bg-emerald-400":h.status==="running"?"bg-amber-400 animate-pulse":"bg-gray-300";return e.jsxs("div",{className:`
|
|
3
|
+
rounded-xl border-2 shadow-sm w-[220px] transition-shadow cursor-pointer
|
|
4
|
+
${a.bg} ${a.border}
|
|
5
|
+
${t?"ring-2 ring-primary/40 shadow-md":"hover:shadow-md"}
|
|
6
|
+
`,onClick:()=>{var i;return(i=h.onNodeClick)==null?void 0:i.call(h,r)},children:[e.jsx(z,{type:"target",position:H.Top,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"}),e.jsxs("div",{className:"px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx("span",{className:"text-sm",children:a.icon}),e.jsx("span",{className:`text-[11px] font-semibold ${a.accent} uppercase tracking-wide truncate flex-1`,children:h.label||l}),n&&e.jsx(Be,{id:r,data:h,nodeType:l})]}),e.jsx("p",{className:"text-[11px] text-gray-500 truncate leading-tight",children:h.summary||(h.content||"").slice(0,60)}),e.jsxs("div",{className:"flex items-center justify-between mt-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${b}`}),e.jsx("span",{className:"text-[10px] text-gray-400 capitalize",children:h.status||"done"})]}),e.jsx("span",{className:"text-[10px] text-gray-400 hover:text-gray-600",children:"Click to expand"})]})]}),e.jsx(z,{type:"source",position:H.Bottom,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"})]})}return e.jsxs("div",{className:`
|
|
7
|
+
rounded-xl border-2 shadow-sm min-w-[240px] max-w-[360px] transition-shadow
|
|
8
|
+
${a.bg} ${a.border}
|
|
9
|
+
${t?"ring-2 ring-primary/40 shadow-md":"hover:shadow-md"}
|
|
10
|
+
`,children:[e.jsx(z,{type:"target",position:H.Top,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"}),e.jsxs("div",{className:`flex items-center justify-between px-3 py-2 border-b ${a.border}/30`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm",children:a.icon}),e.jsx("span",{className:`text-xs font-semibold ${a.accent} uppercase tracking-wide truncate`,children:h.label||l})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[n&&e.jsx(Be,{id:r,data:h,nodeType:l}),u]})]}),e.jsx("div",{className:"px-3 py-2 text-xs text-gray-700 leading-relaxed whitespace-pre-wrap break-words max-h-[300px] overflow-y-auto",children:c||h.content||""}),e.jsx(z,{type:"source",position:H.Bottom,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"})]})}const te=s.memo(_t),Ae=[{type:"chat",label:"Chat",description:"Multi-turn conversation",category:"ai"},{type:"prompt",label:"Prompt",description:"Single AI transformation",category:"ai"},{type:"deepresearch",label:"Deep Research",description:"Web + doc research report",category:"ai"},{type:"image",label:"Image",description:"AI image generation",category:"ai"},{type:"table",label:"Table",description:"Structured data table",category:"ai"},{type:"list",label:"List",description:"Bulk parallel operations",category:"ai"},{type:"comparison",label:"Compare",description:"Multi-model side-by-side",category:"ai"},{type:"note",label:"Note",description:"Text note",category:"content"},{type:"pdf",label:"PDF",description:"Upload document",category:"content"},{type:"inputs",label:"Inputs",description:"Variables & parameters",category:"content"}];function Rt({position:r,onSelect:l,onClose:h}){const t=s.useRef(null);s.useEffect(()=>{const a=n=>{t.current&&!t.current.contains(n.target)&&h()},m=n=>{n.key==="Escape"&&h()};return document.addEventListener("mousedown",a),document.addEventListener("keydown",m),()=>{document.removeEventListener("mousedown",a),document.removeEventListener("keydown",m)}},[h]);const c=Ae.filter(a=>a.category==="ai"),u=Ae.filter(a=>a.category==="content"),d=s.useCallback(a=>{l(a,r),h()},[l,r,h]);return e.jsx("div",{ref:t,className:"fixed z-50 animate-in fade-in zoom-in-95 duration-150",style:{left:r.x,top:r.y,transform:"translate(-50%, -50%)"},children:e.jsxs("div",{className:"bg-white/95 backdrop-blur-md border border-gray-200 rounded-2xl shadow-2xl p-3 w-[320px]",children:[e.jsx("div",{className:"text-[11px] font-semibold text-gray-400 uppercase tracking-wider px-1 mb-2",children:"Add Block"}),e.jsxs("div",{className:"mb-2",children:[e.jsx("div",{className:"text-[9px] font-bold text-gray-300 uppercase tracking-widest px-1 mb-1",children:"AI Blocks"}),e.jsx("div",{className:"grid grid-cols-2 gap-1",children:c.map(a=>{const m=F[a.type]||F.note;return e.jsxs("button",{onClick:()=>d(a.type),className:`
|
|
11
|
+
flex items-center gap-2 px-2.5 py-2 rounded-lg text-left
|
|
12
|
+
transition-all hover:scale-[1.02] active:scale-[0.98]
|
|
13
|
+
${m.bg} border ${m.border}/50 hover:${m.border}
|
|
14
|
+
`,children:[e.jsx("span",{className:"text-base shrink-0",children:m.icon}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:`text-[11px] font-semibold ${m.accent} truncate`,children:a.label}),e.jsx("div",{className:"text-[9px] text-gray-400 truncate",children:a.description})]})]},a.type)})})]}),e.jsx("div",{className:"h-px bg-gray-100 mx-1 my-2"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[9px] font-bold text-gray-300 uppercase tracking-widest px-1 mb-1",children:"Content Blocks"}),e.jsx("div",{className:"grid grid-cols-3 gap-1",children:u.map(a=>{const m=F[a.type]||F.note;return e.jsxs("button",{onClick:()=>d(a.type),className:`
|
|
15
|
+
flex flex-col items-center gap-1 px-2 py-2 rounded-lg
|
|
16
|
+
transition-all hover:scale-[1.02] active:scale-[0.98]
|
|
17
|
+
${m.bg} border ${m.border}/50 hover:${m.border}
|
|
18
|
+
`,children:[e.jsx("span",{className:"text-base",children:m.icon}),e.jsx("div",{className:`text-[10px] font-medium ${m.accent}`,children:a.label})]},a.type)})})]}),e.jsxs("div",{className:"text-[9px] text-gray-300 text-center mt-2",children:["Double-click canvas or press ",e.jsx("kbd",{className:"px-1 py-0.5 bg-gray-100 rounded text-gray-400",children:"Space"})," to open"]})]})})}const Pt=s.memo(Rt);function It({position:r,actions:l,onClose:h}){const t=s.useRef(null);return s.useEffect(()=>{const c=d=>{t.current&&!t.current.contains(d.target)&&h()},u=d=>{d.key==="Escape"&&h()};return document.addEventListener("mousedown",c),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",u)}},[h]),e.jsx("div",{ref:t,className:"fixed z-50 animate-in fade-in zoom-in-95 duration-100",style:{left:r.x,top:r.y},children:e.jsx("div",{className:"bg-white/95 backdrop-blur-md border border-gray-200 rounded-xl shadow-xl py-1 min-w-[180px]",children:l.map((c,u)=>e.jsxs("button",{onClick:()=>{c.disabled||(c.onClick(),h())},disabled:c.disabled,className:`
|
|
19
|
+
w-full flex items-center gap-2.5 px-3 py-1.5 text-left text-[11px] transition-colors
|
|
20
|
+
${c.disabled?"opacity-40 cursor-not-allowed":"hover:bg-gray-50"}
|
|
21
|
+
${c.danger?"text-red-500 hover:bg-red-50":"text-gray-600"}
|
|
22
|
+
`,children:[e.jsx("span",{className:"text-sm w-5 text-center",children:c.icon}),e.jsx("span",{children:c.label})]},u))})})}const Bt=s.memo(It);function At({node:r,onClose:l,onPin:h,onDelete:t}){var n,b,i;s.useEffect(()=>{if(!r)return;const o=v=>{v.key==="Escape"&&l()};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[r,l]);const c=s.useCallback(()=>{var v,x;if(!r)return;const o=String(((v=r.data)==null?void 0:v.fullContent)||((x=r.data)==null?void 0:x.content)||"");navigator.clipboard.writeText(o).catch(()=>{})},[r]);if(!r)return null;const u=r.type||"response",d=F[u]||F.note,a=String(((n=r.data)==null?void 0:n.fullContent)||((b=r.data)==null?void 0:b.content)||""),m=String(((i=r.data)==null?void 0:i.label)||u);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-black/20 z-40",onClick:l}),e.jsxs("div",{className:"fixed top-0 right-0 h-full w-[420px] max-w-[90vw] bg-white shadow-2xl z-50 flex flex-col animate-in slide-in-from-right duration-200",children:[e.jsxs("div",{className:`flex items-center justify-between px-4 py-3 border-b ${d.bg}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:d.icon}),e.jsx("span",{className:`text-sm font-semibold ${d.accent} uppercase tracking-wide`,children:m})]}),e.jsx("button",{onClick:l,className:"p-1 rounded-lg hover:bg-black/10 text-gray-500 transition-colors",title:"Close (Esc)",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-4 py-4",children:e.jsx("div",{className:"prose prose-sm max-w-none text-gray-700",children:e.jsx($t,{remarkPlugins:[Lt],children:a})})}),e.jsxs("div",{className:"border-t px-4 py-3 flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>{h(r.id),l()},className:"flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg bg-primary/10 text-primary text-xs font-medium hover:bg-primary/20 transition-colors",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z"})}),"Pin to Canvas"]}),e.jsxs("button",{onClick:c,className:"flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg bg-gray-100 text-gray-600 text-xs font-medium hover:bg-gray-200 transition-colors",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})}),"Copy"]}),e.jsxs("button",{onClick:()=>{t(r.id),l()},className:"flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg bg-red-50 text-red-500 text-xs font-medium hover:bg-red-100 transition-colors",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),"Delete"]})]})]})]})}const Wt=s.memo(At),Ot=`
|
|
23
|
+
(function() {
|
|
24
|
+
let selectedEl = null;
|
|
25
|
+
let hoverEl = null;
|
|
26
|
+
|
|
27
|
+
const highlight = document.createElement('style');
|
|
28
|
+
highlight.textContent = \`
|
|
29
|
+
.__upfyn-hover { outline: 2px dashed #6366f1 !important; outline-offset: 2px; cursor: pointer; }
|
|
30
|
+
.__upfyn-selected { outline: 2px solid #6366f1 !important; outline-offset: 2px; }
|
|
31
|
+
\`;
|
|
32
|
+
document.head.appendChild(highlight);
|
|
33
|
+
|
|
34
|
+
document.addEventListener('mouseover', function(e) {
|
|
35
|
+
if (hoverEl && hoverEl !== selectedEl) hoverEl.classList.remove('__upfyn-hover');
|
|
36
|
+
if (e.target === document.body || e.target === document.documentElement) return;
|
|
37
|
+
hoverEl = e.target;
|
|
38
|
+
if (hoverEl !== selectedEl) hoverEl.classList.add('__upfyn-hover');
|
|
39
|
+
}, true);
|
|
40
|
+
|
|
41
|
+
document.addEventListener('mouseout', function(e) {
|
|
42
|
+
if (hoverEl && hoverEl !== selectedEl) hoverEl.classList.remove('__upfyn-hover');
|
|
43
|
+
}, true);
|
|
44
|
+
|
|
45
|
+
document.addEventListener('click', function(e) {
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
e.stopPropagation();
|
|
48
|
+
|
|
49
|
+
if (selectedEl) selectedEl.classList.remove('__upfyn-selected');
|
|
50
|
+
selectedEl = e.target;
|
|
51
|
+
selectedEl.classList.add('__upfyn-selected');
|
|
52
|
+
|
|
53
|
+
// Build CSS selector path
|
|
54
|
+
function getSelector(el) {
|
|
55
|
+
if (el.id) return '#' + el.id;
|
|
56
|
+
let path = el.tagName.toLowerCase();
|
|
57
|
+
if (el.className && typeof el.className === 'string') {
|
|
58
|
+
const classes = el.className.split(' ').filter(c => !c.startsWith('__upfyn')).slice(0, 2).join('.');
|
|
59
|
+
if (classes) path += '.' + classes;
|
|
60
|
+
}
|
|
61
|
+
return path;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const rect = selectedEl.getBoundingClientRect();
|
|
65
|
+
window.parent.postMessage({
|
|
66
|
+
type: 'upfyn-element-selected',
|
|
67
|
+
outerHTML: selectedEl.outerHTML,
|
|
68
|
+
tagName: selectedEl.tagName,
|
|
69
|
+
selector: getSelector(selectedEl),
|
|
70
|
+
rect: { top: rect.top, left: rect.left, width: rect.width, height: rect.height }
|
|
71
|
+
}, '*');
|
|
72
|
+
}, true);
|
|
73
|
+
|
|
74
|
+
// Listen for HTML replacement from parent
|
|
75
|
+
window.addEventListener('message', function(e) {
|
|
76
|
+
if (e.data?.type === 'upfyn-replace-element' && selectedEl) {
|
|
77
|
+
const temp = document.createElement('div');
|
|
78
|
+
temp.innerHTML = e.data.newHTML;
|
|
79
|
+
const newEl = temp.firstElementChild || temp.firstChild;
|
|
80
|
+
if (newEl) {
|
|
81
|
+
selectedEl.classList.remove('__upfyn-selected');
|
|
82
|
+
selectedEl.replaceWith(newEl);
|
|
83
|
+
selectedEl = newEl;
|
|
84
|
+
selectedEl.classList.add('__upfyn-selected');
|
|
85
|
+
|
|
86
|
+
// Send updated full HTML back
|
|
87
|
+
window.parent.postMessage({
|
|
88
|
+
type: 'upfyn-html-updated',
|
|
89
|
+
fullHTML: document.documentElement.outerHTML
|
|
90
|
+
}, '*');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (e.data?.type === 'upfyn-deselect' && selectedEl) {
|
|
95
|
+
selectedEl.classList.remove('__upfyn-selected');
|
|
96
|
+
selectedEl = null;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
})();
|
|
100
|
+
`;function zt({html:r,pageName:l,nodeId:h,onClose:t,onHtmlChange:c,sendMessage:u,latestMessage:d}){const a=s.useRef(null),[m,n]=s.useState(!1),[b,i]=s.useState(r),[o,v]=s.useState(null),[x,j]=s.useState(""),[g,w]=s.useState(!1),y=s.useRef(null),k=s.useRef(""),S=s.useCallback($=>{const _=a.current;if(!_)return;const L=_.contentDocument;if(!L)return;const I=$.replace("</body>",`<script>${Ot}<\/script></body>`);L.open(),L.write(I),L.close(),i($)},[]);s.useEffect(()=>{const $=setTimeout(()=>S(r),100);return()=>clearTimeout($)},[r]),s.useEffect(()=>{const $=_=>{var L,I;if(((L=_.data)==null?void 0:L.type)==="upfyn-element-selected"&&(v({outerHTML:_.data.outerHTML,tagName:_.data.tagName,selector:_.data.selector,rect:_.data.rect}),j(""),setTimeout(()=>{var T;return(T=y.current)==null?void 0:T.focus()},100)),((I=_.data)==null?void 0:I.type)==="upfyn-html-updated"){let T=_.data.fullHTML;T=T.replace(/<style>[^<]*__upfyn[^<]*<\/style>/g,""),T=T.replace(/<script>[^]*?<\/script>\s*<\/body>/,"</body>"),T=T.replace(/ class="__upfyn-[^"]*"/g,""),T=T.replace(/ class=""/g,""),i(T),c(h,T)}};return window.addEventListener("message",$),()=>window.removeEventListener("message",$)},[h,c]),s.useEffect(()=>{var $,_;if(!(!d||!g)){if(d.type==="claude-response"||d.type==="assistant"){const L=d.content||d.text||d.message||"";L&&(k.current+=L)}if(d.type==="claude-complete"||d.type==="message_stop"){const L=k.current.trim();if(L){let I=L;const T=L.match(/```html?\s*\n([\s\S]*?)```/);T&&(I=T[1].trim()),(_=($=a.current)==null?void 0:$.contentWindow)==null||_.postMessage({type:"upfyn-replace-element",newHTML:I},"*")}w(!1),k.current=""}}},[d,g]);const R=s.useCallback(()=>{const $=x.trim();if(!$||!u||!o||g)return;const _=`You are editing an HTML element inline on a web page. Return ONLY the updated HTML element — no explanation, no markdown, just the raw HTML.
|
|
101
|
+
|
|
102
|
+
Current element (${o.tagName}):
|
|
103
|
+
\`\`\`html
|
|
104
|
+
${o.outerHTML}
|
|
105
|
+
\`\`\`
|
|
106
|
+
|
|
107
|
+
User instruction: ${$}
|
|
108
|
+
|
|
109
|
+
Return the updated HTML element:`;k.current="",w(!0),u({type:"claude-command",command:_,options:{canvasMode:!0}})},[x,u,o,g]);s.useEffect(()=>{const $=_=>{var L,I;_.key==="Escape"&&(o?((I=(L=a.current)==null?void 0:L.contentWindow)==null||I.postMessage({type:"upfyn-deselect"},"*"),v(null)):t())};return document.addEventListener("keydown",$),()=>document.removeEventListener("keydown",$)},[o,t]);const D=s.useCallback(()=>{S(b),c(h,b),n(!1)},[b,h,c,S]);return e.jsxs("div",{className:"fixed inset-0 z-50 bg-white flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b bg-gray-50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:t,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg hover:bg-gray-200 text-sm text-gray-600 transition-colors",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 19l-7-7m0 0l7-7m-7 7h18"})}),"Back to Canvas"]}),e.jsx("span",{className:"text-sm font-medium text-gray-800",children:l})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>n(!m),className:`px-3 py-1.5 rounded-lg text-xs font-medium transition-colors ${m?"bg-indigo-100 text-indigo-700":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:m?"</> Code":"</> View Code"}),o&&e.jsxs("span",{className:"text-xs text-indigo-500 bg-indigo-50 px-2 py-1 rounded",children:["Selected: <",o.tagName.toLowerCase(),">"]})]})]}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsxs("div",{className:`relative ${m?"w-1/2":"w-full"}`,children:[e.jsx("iframe",{ref:a,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin",title:l}),o&&e.jsx("div",{className:"absolute z-30 animate-in fade-in duration-150",style:{top:Math.min(o.rect.top+o.rect.height+8,window.innerHeight-120),left:Math.max(8,Math.min(o.rect.left,window.innerWidth-360))},children:e.jsxs("div",{className:"bg-white rounded-xl shadow-2xl border border-indigo-200 p-2 w-[340px]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{ref:y,type:"text",value:x,onChange:$=>j($.target.value),onKeyDown:$=>{$.key==="Enter"&&($.preventDefault(),R())},placeholder:`Change this ${o.tagName.toLowerCase()}...`,className:"flex-1 text-sm border border-gray-200 rounded-lg px-3 py-2 outline-none focus:border-indigo-400",disabled:g}),e.jsx("button",{onClick:R,disabled:!x.trim()||g,className:"shrink-0 w-8 h-8 rounded-lg bg-indigo-500 text-white flex items-center justify-center disabled:opacity-40 hover:bg-indigo-600 transition-colors",children:g?e.jsx("div",{className:"w-3 h-3 border-2 border-white/30 border-t-white rounded-full animate-spin"}):e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 7l5 5m0 0l-5 5m5-5H6"})})})]}),g&&e.jsx("p",{className:"text-[10px] text-indigo-400 mt-1 px-1",children:"AI is editing this element..."})]})})]}),m&&e.jsxs("div",{className:"w-1/2 border-l flex flex-col",children:[e.jsxs("div",{className:"px-3 py-2 border-b bg-gray-800 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-gray-300 font-mono",children:"HTML Source"}),e.jsx("button",{onClick:D,className:"px-3 py-1 rounded text-xs font-medium bg-indigo-500 text-white hover:bg-indigo-600 transition-colors",children:"Apply Changes"})]}),e.jsx("textarea",{value:b,onChange:$=>i($.target.value),className:"flex-1 bg-gray-900 text-green-300 font-mono text-xs p-4 resize-none outline-none leading-relaxed",spellCheck:!1})]})]}),e.jsx("div",{className:"px-4 py-1.5 border-t bg-gray-50 text-[10px] text-gray-400",children:"Click any element to select it, then type your change. Press Esc to deselect or close."})]})}const Ht=s.memo(zt);function Ft({nodes:r,projectName:l,onClose:h}){const[t,c]=s.useState("website"),[u,d]=s.useState("exported-site"),[a,m]=s.useState(!1),[n,b]=s.useState(null),[i,o]=s.useState(!1),v=r.filter(y=>y.selected),x=(i&&v.length>0?v:r).filter(y=>y.type==="webpage"),j=(i&&v.length>0?v:r).filter(y=>y.type&&["response","research","suggestion","note","summary"].includes(y.type)),g=t==="website"?x.length:j.length,w=s.useCallback(async()=>{var y,k,S,R,D,$,_;m(!0),b(null);try{if(t==="website"){const L=[];for(let T=0;T<x.length;T++){const V=x[T],Q=String(((y=V.data)==null?void 0:y.pageName)||((k=V.data)==null?void 0:k.label)||`page-${T+1}`).toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"")+".html",se=String(((S=V.data)==null?void 0:S.html)||((R=V.data)==null?void 0:R.content)||"");L.push({name:Q,content:se})}let I=0;for(const T of L)try{const V=`${u}/${T.name}`;await oe.saveFile(l,V,T.content),I++}catch{}if(L.length>1&&!L.some(T=>T.name==="index.html")){const T=`<!DOCTYPE html>
|
|
110
|
+
<html lang="en">
|
|
111
|
+
<head>
|
|
112
|
+
<meta charset="UTF-8">
|
|
113
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
114
|
+
<title>Site Index</title>
|
|
115
|
+
<style>
|
|
116
|
+
body { font-family: system-ui, sans-serif; max-width: 600px; margin: 40px auto; padding: 0 20px; }
|
|
117
|
+
h1 { color: #1f2937; }
|
|
118
|
+
ul { list-style: none; padding: 0; }
|
|
119
|
+
li { margin: 8px 0; }
|
|
120
|
+
a { color: #4f46e5; text-decoration: none; padding: 8px 16px; border: 1px solid #e5e7eb; border-radius: 8px; display: inline-block; }
|
|
121
|
+
a:hover { background: #eef2ff; }
|
|
122
|
+
</style>
|
|
123
|
+
</head>
|
|
124
|
+
<body>
|
|
125
|
+
<h1>Pages</h1>
|
|
126
|
+
<ul>
|
|
127
|
+
${L.map(V=>`<li><a href="${V.name}">${V.name.replace(".html","")}</a></li>`).join(`
|
|
128
|
+
`)}
|
|
129
|
+
</ul>
|
|
130
|
+
</body>
|
|
131
|
+
</html>`;try{await oe.saveFile(l,`${u}/index.html`,T),I++}catch{}}b({ok:I>0,message:I>0?`Exported ${I} file(s) to ${u}/`:"Export failed — make sure a machine is connected"})}else{let L=0;for(let I=0;I<j.length;I++){const T=j[I],V=String(((D=T.data)==null?void 0:D.label)||T.type||`note-${I+1}`),Z=V.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"")+".md",Q=String((($=T.data)==null?void 0:$.fullContent)||((_=T.data)==null?void 0:_.content)||"");try{await oe.saveFile(l,`${u}/${Z}`,`# ${V}
|
|
132
|
+
|
|
133
|
+
${Q}`),L++}catch{}}b({ok:L>0,message:L>0?`Exported ${L} file(s) to ${u}/`:"Export failed — make sure a machine is connected"})}}catch{b({ok:!1,message:"Export failed — check your connection"})}finally{m(!1)}},[t,x,j,u,l]);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-black/30 z-40",onClick:h}),e.jsxs("div",{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-50 w-[400px] max-w-[90vw] bg-white rounded-2xl shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-800",children:"Export Canvas"}),e.jsx("button",{onClick:h,className:"p-1 rounded hover:bg-gray-100 text-gray-400",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"px-5 py-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600 block mb-1.5",children:"Scope"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>o(!1),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium border transition-colors ${i?"border-gray-200 text-gray-500 hover:bg-gray-50":"bg-indigo-50 border-indigo-300 text-indigo-700"}`,children:"All nodes"}),e.jsxs("button",{onClick:()=>o(!0),disabled:v.length===0,className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium border transition-colors disabled:opacity-40 ${i?"bg-indigo-50 border-indigo-300 text-indigo-700":"border-gray-200 text-gray-500 hover:bg-gray-50"}`,children:["Selected (",v.length,")"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600 block mb-1.5",children:"Format"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>c("website"),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium border transition-colors ${t==="website"?"bg-indigo-50 border-indigo-300 text-indigo-700":"border-gray-200 text-gray-500 hover:bg-gray-50"}`,children:["Website (",x.length," pages)"]}),e.jsxs("button",{onClick:()=>c("markdown"),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium border transition-colors ${t==="markdown"?"bg-indigo-50 border-indigo-300 text-indigo-700":"border-gray-200 text-gray-500 hover:bg-gray-50"}`,children:["Markdown (",j.length," notes)"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600 block mb-1.5",children:"Target folder"}),e.jsx("input",{type:"text",value:u,onChange:y=>d(y.target.value),className:"w-full px-3 py-2 border border-gray-200 rounded-lg text-sm outline-none focus:border-indigo-400",placeholder:"exported-site"}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-1",children:"Relative to project root on connected machine"})]}),n&&e.jsx("div",{className:`px-3 py-2 rounded-lg text-xs ${n.ok?"bg-emerald-50 text-emerald-700":"bg-red-50 text-red-600"}`,children:n.message})]}),e.jsxs("div",{className:"px-5 py-3 border-t flex items-center justify-between",children:[e.jsxs("span",{className:"text-[10px] text-gray-400",children:[g," item(s) will be exported"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:h,className:"px-4 py-2 rounded-lg text-xs font-medium text-gray-500 hover:bg-gray-100 transition-colors",children:"Cancel"}),e.jsx("button",{onClick:w,disabled:a||g===0,className:"px-4 py-2 rounded-lg text-xs font-medium bg-indigo-500 text-white hover:bg-indigo-600 disabled:opacity-40 transition-colors flex items-center gap-1.5",children:a?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-3 h-3 border-2 border-white/30 border-t-white rounded-full animate-spin"}),"Exporting..."]}):e.jsxs(e.Fragment,{children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),"Export"]})})]})]})]})]})}const Vt=s.memo(Ft),We=[{id:"tpl_research_report",name:"Research Report",description:"Deep research block connected to a summary table",isBuiltIn:!0,createdAt:0,nodes:[{id:"tpl_n1",type:"inputs",position:{x:0,y:0},data:{label:"Parameters",variables:{topic:"",depth:"detailed"}}},{id:"tpl_n2",type:"deepresearch",position:{x:350,y:0},data:{label:"Deep Research",content:"",searchEnabled:{web:!0,documents:!1}}},{id:"tpl_n3",type:"table",position:{x:350,y:300},data:{label:"Key Findings",columns:[],rows:[]}},{id:"tpl_n4",type:"note",position:{x:0,y:300},data:{label:"Notes",content:"Add your research notes here..."}}],edges:[{id:"tpl_e1",source:"tpl_n1",target:"tpl_n2"},{id:"tpl_e2",source:"tpl_n2",target:"tpl_n3"},{id:"tpl_e3",source:"tpl_n1",target:"tpl_n4"}]},{id:"tpl_code_review",name:"Code Review",description:"Prompt → Analysis → Suggestions pipeline",isBuiltIn:!0,createdAt:0,nodes:[{id:"tpl_n1",type:"note",position:{x:0,y:0},data:{label:"Code",content:"Paste your code here..."}},{id:"tpl_n2",type:"chat",position:{x:350,y:0},data:{label:"Code Review Chat",content:"",messages:[]}},{id:"tpl_n3",type:"list",position:{x:350,y:350},data:{label:"Action Items",items:[]}}],edges:[{id:"tpl_e1",source:"tpl_n1",target:"tpl_n2"},{id:"tpl_e2",source:"tpl_n2",target:"tpl_n3"}]},{id:"tpl_content_pipeline",name:"Content Pipeline",description:"Multi-model comparison for content generation",isBuiltIn:!0,createdAt:0,nodes:[{id:"tpl_n1",type:"inputs",position:{x:0,y:0},data:{label:"Brief",variables:{topic:"",tone:"professional",audience:"general"}}},{id:"tpl_n2",type:"comparison",position:{x:350,y:0},data:{label:"Model Comparison",content:"",models:["sonnet","openai/gpt-4o"]}},{id:"tpl_n3",type:"note",position:{x:0,y:300},data:{label:"Final Draft",content:"Paste the best output here and refine..."}}],edges:[{id:"tpl_e1",source:"tpl_n1",target:"tpl_n2"},{id:"tpl_e2",source:"tpl_n2",target:"tpl_n3"}]}],Oe="upfyn_canvas_templates";function Gt({onLoadTemplate:r,currentNodes:l,currentEdges:h,onClose:t}){const[c,u]=s.useState([]),[d,a]=s.useState(""),[m,n]=s.useState(""),[b,i]=s.useState(!1),[o,v]=s.useState("gallery");s.useEffect(()=>{try{const k=localStorage.getItem(Oe);k&&u(JSON.parse(k))}catch{}},[]);const x=s.useCallback(k=>{u(k);try{localStorage.setItem(Oe,JSON.stringify(k))}catch{}},[]),j=s.useCallback(()=>{if(!d.trim()||l.length===0)return;const k=l.map(R=>{var D,$,_,L,I,T,V,Z,Q,se,le,ne,re;return{...R,data:{label:(D=R.data)==null?void 0:D.label,content:($=R.data)==null?void 0:$.content,compact:(_=R.data)==null?void 0:_.compact,summary:(L=R.data)==null?void 0:L.summary,fullContent:(I=R.data)==null?void 0:I.fullContent,modelId:(T=R.data)==null?void 0:T.modelId,modelProvider:(V=R.data)==null?void 0:V.modelProvider,variables:(Z=R.data)==null?void 0:Z.variables,messages:(Q=R.data)==null?void 0:Q.messages,columns:(se=R.data)==null?void 0:se.columns,rows:(le=R.data)==null?void 0:le.rows,items:(ne=R.data)==null?void 0:ne.items,searchEnabled:(re=R.data)==null?void 0:re.searchEnabled}}}),S={id:`tpl_user_${Date.now()}`,name:d.trim(),description:m.trim()||`${l.length} blocks, ${h.length} connections`,nodes:k,edges:h,createdAt:Date.now()};x([...c,S]),a(""),n(""),i(!1)},[d,m,l,h,c,x]),g=s.useCallback(k=>{x(c.filter(S=>S.id!==k))},[c,x]),w=s.useCallback(k=>{const S=new Map,R=k.nodes.map($=>{const _=`n_${Date.now()}_${Math.random().toString(36).slice(2,7)}`;return S.set($.id,_),{...$,id:_}}),D=k.edges.map($=>({...$,id:`e_${S.get($.source)||$.source}_${S.get($.target)||$.target}`,source:S.get($.source)||$.source,target:S.get($.target)||$.target}));r(R,D),t()},[r,t]),y=o==="gallery"?We:c;return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl border border-gray-200 w-[520px] max-h-[80vh] flex flex-col animate-in fade-in zoom-in-95 duration-200",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-gray-100",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-800",children:"Canvas Templates"}),e.jsx("p",{className:"text-[10px] text-gray-400",children:"Pre-built workflows and your saved templates"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>i(!b),className:"text-[10px] px-2.5 py-1 bg-primary/10 text-primary rounded-lg font-medium hover:bg-primary/20 transition-colors",children:b?"Cancel":"Save Current"}),e.jsx("button",{onClick:t,className:"p-1 rounded-lg hover:bg-gray-100 text-gray-400 transition-colors",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),b&&e.jsxs("div",{className:"px-5 py-3 border-b border-gray-100 bg-gray-50/50",children:[e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("input",{value:d,onChange:k=>a(k.target.value),placeholder:"Template name...",className:"flex-1 text-xs bg-white border border-gray-200 rounded-lg px-3 py-1.5 outline-none focus:border-primary/30"}),e.jsx("button",{onClick:j,disabled:!d.trim()||l.length===0,className:"text-[10px] px-3 py-1.5 bg-primary text-primary-foreground rounded-lg font-medium hover:bg-primary/90 disabled:opacity-40 transition-colors",children:"Save"})]}),e.jsx("input",{value:m,onChange:k=>n(k.target.value),placeholder:"Description (optional)...",className:"w-full text-[10px] bg-white border border-gray-200 rounded-lg px-3 py-1 outline-none focus:border-primary/30"}),l.length===0&&e.jsx("p",{className:"text-[9px] text-amber-500 mt-1",children:"Canvas is empty — add blocks first."})]}),e.jsxs("div",{className:"flex border-b border-gray-100 px-5",children:[e.jsxs("button",{onClick:()=>v("gallery"),className:`text-[11px] px-3 py-2 font-medium border-b-2 transition-colors ${o==="gallery"?"border-primary text-primary":"border-transparent text-gray-400 hover:text-gray-600"}`,children:["Built-in (",We.length,")"]}),e.jsxs("button",{onClick:()=>v("saved"),className:`text-[11px] px-3 py-2 font-medium border-b-2 transition-colors ${o==="saved"?"border-primary text-primary":"border-transparent text-gray-400 hover:text-gray-600"}`,children:["My Templates (",c.length,")"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-3",children:y.length===0?e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{className:"text-xs text-gray-400",children:o==="saved"?"No saved templates yet. Save your current canvas as a template.":"No templates available."})}):e.jsx("div",{className:"grid grid-cols-2 gap-2.5",children:y.map(k=>e.jsxs("div",{className:"border border-gray-200 rounded-xl p-3 hover:border-primary/30 hover:shadow-sm transition-all cursor-pointer group",onClick:()=>w(k),children:[e.jsxs("div",{className:"flex gap-1 mb-2",children:[k.nodes.slice(0,5).map((S,R)=>{const D=F[S.type||"note"]||F.note;return e.jsx("span",{className:`text-xs w-6 h-6 rounded-lg flex items-center justify-center ${D.bg} border ${D.border}/30`,title:S.type||"note",children:D.icon},R)}),k.nodes.length>5&&e.jsxs("span",{className:"text-[9px] text-gray-400 self-center",children:["+",k.nodes.length-5]})]}),e.jsx("h4",{className:"text-[11px] font-semibold text-gray-700 mb-0.5",children:k.name}),e.jsx("p",{className:"text-[9px] text-gray-400 leading-tight",children:k.description}),e.jsxs("div",{className:"flex items-center justify-between mt-2",children:[e.jsxs("span",{className:"text-[9px] text-gray-300",children:[k.nodes.length," blocks, ",k.edges.length," connections"]}),!k.isBuiltIn&&e.jsx("button",{onClick:S=>{S.stopPropagation(),g(k.id)},className:"opacity-0 group-hover:opacity-100 text-[9px] text-red-400 hover:text-red-500 transition-all",children:"Delete"})]})]},k.id))})})]})})}const Ut=s.memo(Gt),Kt={chat:"claude-query",deepresearch:"claude-query",prompt:"claude-query",comparison:"claude-query",table:"claude-query",list:"claude-query",image:"claude-query",note:"",inputs:""};function ze(r){const l=[],h=r.split(`
|
|
134
|
+
`).filter(u=>u.trim()),t=/^\d+\.\s*\[(\w+)\]\s*(.+?)(?::\s*(.+))?$/,c=/depends?\s*on\s*#?(\d+)/i;for(const u of h){const d=u.trim().match(t);if(d){const[,a,m,n=""]=d,b=[],i=n.match(c);i&&b.push(`swarm_${i[1]}`);const v=["chat","deepresearch","note","table","list","prompt","image","comparison"].includes(a.toLowerCase())?a.toLowerCase():"prompt";l.push({id:`swarm_${l.length+1}`,title:m.trim(),blockType:v,description:n.trim(),status:"pending",dependsOn:b,agentAction:Kt[v]||""})}}return l.length===0&&r.length>20&&l.push({id:"swarm_1",title:"Research",blockType:"deepresearch",description:"Research the topic",status:"pending",dependsOn:[],agentAction:"claude-query"},{id:"swarm_2",title:"Analyze",blockType:"chat",description:"Analyze research findings",status:"pending",dependsOn:["swarm_1"],agentAction:"claude-query"},{id:"swarm_3",title:"Summary",blockType:"table",description:"Create structured summary",status:"pending",dependsOn:["swarm_2"],agentAction:"claude-query"}),l}function Yt(r){const l=[],h=[],a=new Map,m=r.filter(i=>i.dependsOn.length===0);m.forEach(i=>a.set(i.id,0));let n=0;for(;n<m.length;){const i=m[n++],o=a.get(i.id)||0,v=r.filter(x=>x.dependsOn.includes(i.id));for(const x of v)a.has(x.id)||(a.set(x.id,o+1),m.push(x))}r.forEach(i=>{a.has(i.id)||a.set(i.id,0)});const b=new Map;for(const i of r){const o=a.get(i.id)||0;b.has(o)||b.set(o,[]),b.get(o).push(i)}for(const[i,o]of b)o.forEach((v,x)=>{l.push({id:v.id,type:v.blockType,position:{x:100+i*380,y:100+x*200},data:{label:v.title,content:v.description,status:"pending"}})});for(const i of r)for(const o of i.dependsOn)h.push({id:`e_${o}_${i.id}`,source:o,target:i.id,animated:!0});for(const[,i]of b)i.length<=1;return{nodes:l,edges:h}}function qt({onCreateBlocks:r,sendMessage:l,latestMessage:h,onClose:t}){const[c,u]=s.useState(""),[d,a]=s.useState("input"),[m,n]=s.useState([]),[b,i]=s.useState(""),o=s.useRef(""),v=s.useCallback(()=>{if(!c.trim())return;a("planning"),i(""),o.current="";const y=`You are a task decomposition AI. Break down the following goal into a structured plan of 3-6 sub-tasks.
|
|
135
|
+
|
|
136
|
+
Goal: ${c}
|
|
137
|
+
|
|
138
|
+
For each task, use this exact format:
|
|
139
|
+
1. [blockType] Task Title: Brief description
|
|
140
|
+
|
|
141
|
+
Available block types: chat, deepresearch, note, table, list, prompt, image, comparison
|
|
142
|
+
|
|
143
|
+
Example:
|
|
144
|
+
1. [deepresearch] Market Analysis: Research current market trends and competitors
|
|
145
|
+
2. [table] Data Summary: Compile findings into structured comparison table (depends on #1)
|
|
146
|
+
3. [chat] Strategy Discussion: Analyze findings and recommend strategy (depends on #2)
|
|
147
|
+
|
|
148
|
+
Rules:
|
|
149
|
+
- Use the most appropriate block type for each task
|
|
150
|
+
- Mark dependencies with "depends on #N"
|
|
151
|
+
- Tasks without dependencies can run in parallel
|
|
152
|
+
- Keep each task focused and actionable`;if(l)l({type:"claude-command",command:y,options:{canvasMode:!0,blockId:"swarm_planner",swarmMode:!0}});else{const k=`1. [deepresearch] Research: Research "${c.slice(0,50)}"
|
|
153
|
+
2. [chat] Analysis: Analyze research findings (depends on #1)
|
|
154
|
+
3. [table] Summary: Create structured summary (depends on #2)`;i(k),n(ze(k)),a("ready")}},[c,l]);s.useEffect(()=>{if(!h||d!=="planning")return;const y=h;if((y.type==="claude-response"||y.type==="assistant")&&(y.blockId==="swarm_planner"||!y.blockId)){const k=y.content||y.text||y.message||"";k&&(o.current+=k,i(o.current))}if(y.type==="claude-complete"||y.type==="message_stop"){const k=o.current.trim();if(k){i(k);const S=ze(k);n(S),a("ready")}}},[h,d]);const x=s.useCallback((y=!1)=>{if(m.length===0)return;a("executing");const{nodes:k,edges:S}=Yt(m);if(r(k,S),y&&l){const R=m.filter(_=>_.agentAction),D=new Map;for(const _ of R){const L=_.dependsOn.length===0?0:1;D.has(L)||D.set(L,[]),D.get(L).push(_)}let $=500;for(const[,_]of D)for(const L of _)setTimeout(()=>{l({type:"claude-command",command:`${L.title}: ${L.description}`,options:{canvasMode:!0,blockId:L.id,swarmMode:!0}})},$),$+=200}a("done"),setTimeout(t,800)},[m,r,t,l]),j=s.useCallback((y,k,S)=>{n(R=>R.map(D=>D.id===y?{...D,[k]:S}:D))},[]),g=s.useCallback(y=>{n(k=>k.filter(S=>S.id!==y))},[]),w=s.useCallback(()=>{n(y=>[...y,{id:`swarm_${y.length+1}`,title:"New Task",blockType:"prompt",description:"",status:"pending",dependsOn:[]}])},[]);return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl border border-gray-200 w-[560px] max-h-[80vh] flex flex-col animate-in fade-in zoom-in-95 duration-200",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-gray-100",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-gradient-to-br from-violet-500 to-fuchsia-500 flex items-center justify-center",children:e.jsx("span",{className:"text-white text-sm",children:"🐝"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-800",children:"Swarm Orchestrator"}),e.jsx("p",{className:"text-[10px] text-gray-400",children:d==="input"?"Describe your goal — AI will decompose it into tasks":d==="planning"?"AI is planning the task breakdown...":d==="ready"?"Review and edit the plan, then execute":d==="executing"?"Creating blocks on canvas...":"Done!"})]})]}),e.jsx("button",{onClick:t,className:"p-1 rounded-lg hover:bg-gray-100 text-gray-400 transition-colors",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(d==="input"||d==="planning")&&e.jsxs("div",{className:"px-5 py-3 border-b border-gray-100",children:[e.jsx("textarea",{value:c,onChange:y=>u(y.target.value),placeholder:"What do you want to accomplish? e.g., 'Research AI trends and create a comparison of top 5 tools with pricing data'",rows:3,disabled:d==="planning",className:"w-full text-xs text-gray-700 placeholder-gray-400 resize-none outline-none px-3 py-2 rounded-lg border border-gray-200 focus:border-violet-300 bg-gray-50/50 disabled:opacity-60"}),d==="input"&&e.jsx("button",{onClick:v,disabled:!c.trim(),className:"mt-2 w-full py-2 bg-gradient-to-r from-violet-500 to-fuchsia-500 text-white rounded-lg text-xs font-medium hover:from-violet-600 hover:to-fuchsia-600 disabled:opacity-40 transition-all",children:"Plan Tasks with AI"}),d==="planning"&&e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-xs text-violet-500",children:[e.jsx("div",{className:"w-3 h-3 border-2 border-violet-300 border-t-violet-500 rounded-full animate-spin"}),"AI is decomposing your goal into tasks..."]})]}),d==="planning"&&b&&e.jsx("div",{className:"px-5 py-3 max-h-40 overflow-y-auto",children:e.jsx("pre",{className:"text-[10px] text-gray-500 whitespace-pre-wrap font-mono",children:b})}),(d==="ready"||d==="executing"||d==="done")&&e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-[11px] font-semibold text-gray-500 uppercase tracking-wider",children:["Task Plan (",m.length," tasks)"]}),d==="ready"&&e.jsx("button",{onClick:w,className:"text-[10px] text-violet-500 hover:text-violet-600 font-medium",children:"+ Add Task"})]}),e.jsx("div",{className:"space-y-2",children:m.map((y,k)=>{const S=F[y.blockType]||F.note,R=y.dependsOn.length===0&&k>0;return e.jsxs("div",{className:"group",children:[y.dependsOn.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5 ml-4 mb-0.5",children:[e.jsx("div",{className:"w-px h-3 bg-gray-200"}),e.jsxs("span",{className:"text-[8px] text-gray-300",children:["depends on #",y.dependsOn.map(D=>D.replace("swarm_","")).join(", #")]})]}),R&&e.jsx("div",{className:"flex items-center gap-1.5 ml-4 mb-0.5",children:e.jsx("span",{className:"text-[8px] text-violet-300 font-medium",children:"⚡ parallel"})}),e.jsxs("div",{className:`
|
|
155
|
+
flex items-start gap-2.5 p-2.5 rounded-xl border transition-all
|
|
156
|
+
${d==="executing"||d==="done"?`${S.bg} ${S.border}/50`:"bg-gray-50 border-gray-200 hover:border-gray-300"}
|
|
157
|
+
`,children:[e.jsx("div",{className:`w-7 h-7 rounded-lg flex items-center justify-center shrink-0 ${S.bg} border ${S.border}/30`,children:e.jsx("span",{className:"text-sm",children:S.icon})}),e.jsx("div",{className:"flex-1 min-w-0",children:d==="ready"?e.jsxs(e.Fragment,{children:[e.jsx("input",{value:y.title,onChange:D=>j(y.id,"title",D.target.value),className:"text-[11px] font-semibold text-gray-700 bg-transparent outline-none w-full"}),e.jsx("input",{value:y.description,onChange:D=>j(y.id,"description",D.target.value),placeholder:"Description...",className:"text-[10px] text-gray-400 bg-transparent outline-none w-full mt-0.5"}),e.jsxs("select",{value:y.blockType,onChange:D=>j(y.id,"blockType",D.target.value),className:"text-[9px] text-gray-400 bg-transparent outline-none mt-0.5 cursor-pointer",children:[e.jsx("option",{value:"chat",children:"Chat"}),e.jsx("option",{value:"deepresearch",children:"Deep Research"}),e.jsx("option",{value:"prompt",children:"Prompt"}),e.jsx("option",{value:"table",children:"Table"}),e.jsx("option",{value:"list",children:"List"}),e.jsx("option",{value:"note",children:"Note"}),e.jsx("option",{value:"image",children:"Image"}),e.jsx("option",{value:"comparison",children:"Compare"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-[11px] font-semibold text-gray-700",children:y.title}),e.jsx("div",{className:"text-[10px] text-gray-400",children:y.description})]})}),d==="ready"&&e.jsx("button",{onClick:()=>g(y.id),className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-red-100 text-red-300 transition-all shrink-0",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),(d==="executing"||d==="done")&&e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 mt-1 ${y.status==="completed"?"bg-emerald-400":y.status==="running"?"bg-violet-400 animate-pulse":y.status==="failed"?"bg-red-400":"bg-gray-300"}`})]})]},y.id)})})]}),d==="ready"&&m.length>0&&e.jsxs("div",{className:"px-5 py-3 border-t border-gray-100 flex items-center justify-between",children:[e.jsx("button",{onClick:()=>{a("input"),n([]),i("")},className:"text-[10px] text-gray-400 hover:text-gray-600 transition-colors",children:"Start Over"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>x(!1),className:"px-3 py-2 border border-gray-200 text-gray-600 rounded-lg text-xs font-medium hover:bg-gray-50 transition-all",children:"Create Only"}),e.jsxs("button",{onClick:()=>x(!0),className:"px-4 py-2 bg-gradient-to-r from-violet-500 to-fuchsia-500 text-white rounded-lg text-xs font-medium hover:from-violet-600 hover:to-fuchsia-600 transition-all shadow-sm",children:["Create & Run ",m.length," Blocks"]})]})]}),d==="done"&&e.jsx("div",{className:"px-5 py-3 border-t border-gray-100 text-center",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-emerald-500 font-medium",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),"Blocks created on canvas!"]})})]})})}const Jt=s.memo(qt);function Xt({id:r,data:l,selected:h}){const t=l,[c,u]=s.useState(!1),[d,a]=s.useState(String(t.content||"")),m=s.useCallback(()=>{var b;u(!1),(b=t.onEdit)==null||b.call(t,r)},[r,t]),n=e.jsxs(e.Fragment,{children:[!c&&e.jsx("button",{onClick:()=>u(!0),className:"p-0.5 rounded hover:bg-blue-100 text-blue-500 transition-colors",title:"Edit",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),t.onDelete&&e.jsx("button",{onClick:()=>t.onDelete(r),className:"p-0.5 rounded hover:bg-red-100 text-red-400 transition-colors",title:"Delete",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]});return e.jsx(te,{id:r,nodeType:"note",data:t,selected:h,actions:n,children:c?e.jsx("textarea",{autoFocus:!0,value:d,onChange:b=>a(b.target.value),onBlur:m,onKeyDown:b=>{b.key==="Escape"&&m()},className:"w-full bg-white/70 border border-blue-200 rounded px-2 py-1 text-xs resize-none min-h-[60px] outline-none focus:border-blue-400",rows:4}):e.jsx("div",{className:"cursor-text",onDoubleClick:()=>u(!0),children:d||e.jsx("span",{className:"text-gray-400 italic",children:"Double-click to edit..."})})})}const Zt=s.memo(Xt);function Qt({id:r,data:l,selected:h}){const t=l,c=e.jsxs(e.Fragment,{children:[t.onRun&&e.jsx("button",{onClick:()=>t.onRun(r,String(t.content||"")),className:"p-0.5 rounded hover:bg-blue-100 text-blue-600 transition-colors",title:"Run this prompt",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{d:"M8 5v14l11-7z"})})}),t.onRerun&&e.jsx("button",{onClick:()=>t.onRerun(r,String(t.content||"")),className:"p-0.5 rounded hover:bg-green-100 text-green-600 transition-colors",title:"Rerun — send this prompt again",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),t.onDelete&&e.jsx("button",{onClick:()=>t.onDelete(r),className:"p-0.5 rounded hover:bg-red-100 text-red-400 transition-colors",title:"Delete",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]});return e.jsx(te,{id:r,nodeType:"prompt",data:t,selected:h,actions:c})}const es=s.memo(Qt);function ts({id:r,data:l,selected:h}){const t=l,c=s.useCallback(()=>{const d=String(t.fullContent||t.content||"");navigator.clipboard.writeText(d).catch(()=>{})},[t.fullContent,t.content]);if(t.compact)return e.jsx(te,{id:r,nodeType:"response",data:t,selected:h});const u=e.jsxs(e.Fragment,{children:[t.onBranch&&e.jsx("button",{onClick:()=>t.onBranch(r),className:"p-0.5 rounded hover:bg-purple-100 text-purple-500 transition-colors",title:"Branch — create new prompt from this",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 5l7 7-7 7M5 5l7 7-7 7"})})}),e.jsx("button",{onClick:c,className:"p-0.5 rounded hover:bg-purple-100 text-purple-400 transition-colors",title:"Copy content",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]});return e.jsx(te,{id:r,nodeType:"response",data:t,selected:h,actions:u})}const ss=s.memo(ts);function ns({id:r,data:l,selected:h}){const t=l,c=s.useCallback(()=>{const d=t.extractedText||t.content||"";navigator.clipboard.writeText(String(d)).catch(()=>{})},[t]),u=e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:c,className:"p-0.5 rounded hover:bg-red-100 text-red-400 transition-colors",title:"Copy extracted text",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),t.onDelete&&e.jsx("button",{onClick:()=>t.onDelete(r),className:"p-0.5 rounded hover:bg-red-100 text-red-400 transition-colors",title:"Delete",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]});return e.jsx(te,{id:r,nodeType:"pdf",data:{...t,label:t.fileName||"PDF"},selected:h,actions:u,children:e.jsxs("div",{className:"space-y-2",children:[t.thumbnail&&e.jsx("img",{src:t.thumbnail,alt:"PDF preview",className:"w-full rounded border border-red-200"}),t.pageCount&&e.jsxs("div",{className:"text-[10px] text-red-400",children:[t.pageCount," page",t.pageCount>1?"s":""]}),e.jsxs("div",{className:"text-xs text-gray-600 max-h-[200px] overflow-y-auto",children:[(t.extractedText||t.content||"").toString().slice(0,500),(t.extractedText||t.content||"").toString().length>500&&"..."]})]})})}const rs=s.memo(ns);function as({id:r,data:l,selected:h}){const t=l,c=s.useRef(null),[u,d]=s.useState(!1),a=F.webpage;return s.useEffect(()=>{const m=c.current;if(!m||!t.html)return;const n=()=>d(!0);m.addEventListener("load",n);const b=m.contentDocument;return b&&(b.open(),b.write(t.html),b.close(),d(!0)),()=>m.removeEventListener("load",n)},[t.html]),e.jsxs("div",{className:`
|
|
158
|
+
rounded-xl border-2 shadow-sm w-[240px] transition-shadow cursor-pointer
|
|
159
|
+
${a.bg} ${a.border}
|
|
160
|
+
${h?"ring-2 ring-primary/40 shadow-md":"hover:shadow-md"}
|
|
161
|
+
`,onClick:()=>{var m;return(m=t.onWebPageClick)==null?void 0:m.call(t,r)},children:[e.jsx(z,{type:"target",position:H.Left,className:"!w-2 !h-2 !bg-indigo-400 !border-indigo-300"}),t.pageIndex&&e.jsx("div",{className:"absolute -top-2 -left-2 w-5 h-5 rounded-full bg-indigo-500 text-white text-[10px] font-bold flex items-center justify-center shadow",children:t.pageIndex}),e.jsx("div",{className:"w-full h-[150px] overflow-hidden rounded-t-lg bg-white relative",children:t.html?e.jsx("div",{className:"w-[960px] h-[600px] origin-top-left",style:{transform:"scale(0.25)"},children:e.jsx("iframe",{ref:c,className:"w-full h-full border-none pointer-events-none",sandbox:"allow-same-origin",title:t.pageName||"Page preview"})}):e.jsx("div",{className:"flex items-center justify-center h-full text-gray-300",children:e.jsx("svg",{className:"w-8 h-8",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})})})}),e.jsxs("div",{className:"px-3 py-2 border-t border-indigo-200/50",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm",children:a.icon}),e.jsx("span",{className:"text-[11px] font-semibold text-indigo-700 truncate",children:t.pageName||t.label||"Page"})]}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-0.5",children:"Click to edit"})]}),e.jsx(z,{type:"source",position:H.Right,className:"!w-2 !h-2 !bg-indigo-400 !border-indigo-300"})]})}const os=s.memo(as);function ls({id:r,data:l,selected:h}){const t=l,c=F.chat,[u,d]=s.useState(t.messages||[]),[a,m]=s.useState(""),[n,b]=s.useState(!1),[i,o]=s.useState(""),v=s.useRef(null),x=s.useRef(null);s.useEffect(()=>{var g;(g=v.current)==null||g.scrollIntoView({behavior:"smooth"})},[u,i]);const j=s.useCallback(()=>{const g=a.trim();if(!g||n)return;const w={role:"user",content:g,timestamp:Date.now()};if(d(y=>[...y,w]),m(""),b(!0),o(""),t.sendMessage){const k=`You are a helpful AI assistant in a chat block on a visual canvas. Here is the conversation so far:
|
|
162
|
+
|
|
163
|
+
${u.map(S=>`${S.role}: ${S.content}`).join(`
|
|
164
|
+
`)}
|
|
165
|
+
|
|
166
|
+
user: ${g}
|
|
167
|
+
|
|
168
|
+
Respond concisely and helpfully.`;t.sendMessage({type:"claude-command",command:k,options:{canvasMode:!0,blockId:r,chatBlock:!0}})}else setTimeout(()=>{d(y=>[...y,{role:"assistant",content:"Chat requires a connected AI session.",timestamp:Date.now()}]),b(!1)},500)},[a,n,u,t.sendMessage,r]);return s.useEffect(()=>{if(!t.latestMessage||!n)return;const g=t.latestMessage;if((g.type==="claude-response"||g.type==="assistant")&&g.blockId===r){const w=g.content||g.text||g.message||"";w&&o(y=>y+w)}if((g.type==="claude-complete"||g.type==="message_stop")&&g.blockId===r){if(i||g.content||g.text){const w=i||g.content||g.text||"";d(y=>[...y,{role:"assistant",content:w,timestamp:Date.now()}])}o(""),b(!1)}},[t.latestMessage,n,r,i]),e.jsxs("div",{className:`
|
|
169
|
+
rounded-xl border-2 shadow-sm w-[320px] transition-shadow flex flex-col
|
|
170
|
+
${c.bg} ${c.border}
|
|
171
|
+
${h?"ring-2 ring-primary/40 shadow-md":"hover:shadow-md"}
|
|
172
|
+
`,children:[e.jsx(z,{type:"target",position:H.Top,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"}),e.jsxs("div",{className:`flex items-center justify-between px-3 py-2 border-b ${c.border}/30 shrink-0`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm",children:c.icon}),e.jsx("span",{className:`text-xs font-semibold ${c.accent} uppercase tracking-wide`,children:t.label||"Chat"}),e.jsxs("span",{className:"text-[9px] text-gray-400",children:["(",u.length," msgs)"]})]}),e.jsx("div",{className:"flex items-center gap-1",children:t.onDelete&&e.jsx("button",{onClick:()=>t.onDelete(r),className:"p-0.5 rounded hover:bg-red-100 text-red-400 transition-colors",title:"Delete",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto max-h-[250px] min-h-[80px] px-2 py-2 space-y-1.5",children:[u.length===0&&!n&&e.jsx("p",{className:"text-[10px] text-gray-400 text-center py-3",children:"Start a conversation..."}),u.map((g,w)=>e.jsxs("div",{className:`text-[11px] px-2 py-1.5 rounded-lg leading-relaxed ${g.role==="user"?"bg-sky-100/80 text-sky-900 ml-4":"bg-white/60 text-gray-700 mr-4"}`,children:[e.jsx("span",{className:"text-[9px] font-semibold text-gray-400 block mb-0.5",children:g.role==="user"?"You":"AI"}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:g.content})]},w)),n&&i&&e.jsxs("div",{className:"text-[11px] px-2 py-1.5 rounded-lg bg-white/60 text-gray-700 mr-4",children:[e.jsx("span",{className:"text-[9px] font-semibold text-gray-400 block mb-0.5",children:"AI"}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:i}),e.jsx("span",{className:"inline-block w-1.5 h-3 bg-sky-400 animate-pulse ml-0.5"})]}),n&&!i&&e.jsxs("div",{className:"text-[10px] text-gray-400 flex items-center gap-1 px-2",children:[e.jsx("div",{className:"w-1.5 h-1.5 bg-sky-400 rounded-full animate-pulse"}),"Thinking..."]}),e.jsx("div",{ref:v})]}),e.jsx("div",{className:"px-2 py-1.5 border-t border-sky-200/50 shrink-0",children:e.jsxs("div",{className:"flex items-end gap-1.5",children:[e.jsx("textarea",{ref:x,value:a,onChange:g=>m(g.target.value),onKeyDown:g=>{g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),j())},placeholder:"Type a message...",rows:1,className:"flex-1 bg-white/60 text-gray-700 text-[11px] placeholder-gray-400 resize-none outline-none px-2 py-1.5 rounded-lg border border-sky-200/50 focus:border-sky-400/50 max-h-[60px] overflow-y-auto"}),e.jsx("button",{onClick:j,disabled:!a.trim()||n,className:"shrink-0 w-7 h-7 rounded-lg bg-sky-500 text-white flex items-center justify-center disabled:opacity-40 hover:bg-sky-600 transition-colors",children:n?e.jsx("div",{className:"w-2.5 h-2.5 border-2 border-white/30 border-t-white rounded-full animate-spin"}):e.jsx("svg",{className:"w-3 h-3 rotate-90",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.5,d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})})})]})}),e.jsx(z,{type:"source",position:H.Bottom,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"})]})}const is=s.memo(ls);function cs({id:r,data:l,selected:h}){var y,k;const t=l,c=F.deepresearch,[u,d]=s.useState(String(t.content||"")),[a,m]=s.useState("idle"),[n,b]=s.useState(t.report||""),[i,o]=s.useState(((y=t.searchEnabled)==null?void 0:y.web)??!0),[v,x]=s.useState(((k=t.searchEnabled)==null?void 0:k.documents)??!1),j=s.useCallback(()=>{if(!u.trim()||a==="planning"||a==="researching"||a==="writing")return;m("planning"),b("");const S=`You are a deep research AI. Conduct comprehensive research on the following topic and produce a structured report with citations.
|
|
173
|
+
|
|
174
|
+
Topic: ${u}
|
|
175
|
+
|
|
176
|
+
Instructions:
|
|
177
|
+
1. First, plan your research approach (what sources to check, what questions to answer)
|
|
178
|
+
2. Then, write a comprehensive report with:
|
|
179
|
+
- Executive summary
|
|
180
|
+
- Key findings (with section headings)
|
|
181
|
+
- Data and evidence
|
|
182
|
+
- Conclusions and recommendations
|
|
183
|
+
- Sources/citations
|
|
184
|
+
|
|
185
|
+
${i?"Web search is enabled — use current information from the internet.":""}
|
|
186
|
+
${v?"Document search is enabled — reference connected documents on the canvas.":""}
|
|
187
|
+
|
|
188
|
+
Format the report in clean markdown with ## headings for each section.`;t.sendMessage?(t.sendMessage({type:"claude-command",command:S,options:{canvasMode:!0,blockId:r,deepResearch:!0}}),setTimeout(()=>m("researching"),2e3),setTimeout(()=>m("writing"),5e3)):(b("Deep research requires a connected AI session."),m("completed"))},[u,a,i,v,t.sendMessage,r]),g={idle:"Ready",planning:"Planning research...",researching:"Gathering data...",writing:"Writing report...",completed:"Completed"},w={idle:"bg-gray-300",planning:"bg-cyan-400 animate-pulse",researching:"bg-blue-400 animate-pulse",writing:"bg-violet-400 animate-pulse",completed:"bg-emerald-400"};return e.jsxs("div",{className:`
|
|
189
|
+
rounded-xl border-2 shadow-sm w-[340px] transition-shadow
|
|
190
|
+
${c.bg} ${c.border}
|
|
191
|
+
${h?"ring-2 ring-primary/40 shadow-md":"hover:shadow-md"}
|
|
192
|
+
`,children:[e.jsx(z,{type:"target",position:H.Top,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"}),e.jsxs("div",{className:`flex items-center justify-between px-3 py-2 border-b ${c.border}/30`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm",children:c.icon}),e.jsx("span",{className:`text-xs font-semibold ${c.accent} uppercase tracking-wide`,children:"Deep Research"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${w[a]}`}),e.jsx("span",{className:"text-[9px] text-gray-500",children:g[a]})]}),t.onDelete&&e.jsx("button",{onClick:()=>t.onDelete(r),className:"p-0.5 rounded hover:bg-red-100 text-red-400 transition-colors ml-1",title:"Delete",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),e.jsx("div",{className:"px-3 py-2 border-b border-cyan-200/30",children:e.jsx("textarea",{value:u,onChange:S=>d(S.target.value),placeholder:"Enter research topic or question...",rows:2,className:"w-full bg-white/60 text-gray-700 text-[11px] placeholder-gray-400 resize-none outline-none px-2 py-1.5 rounded-lg border border-cyan-200/50 focus:border-cyan-400/50"})}),e.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-3 border-b border-cyan-200/30",children:[e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-gray-500 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:S=>o(S.target.checked),className:"w-3 h-3 rounded border-gray-300 text-cyan-500 focus:ring-cyan-400"}),"Web Search"]}),e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-gray-500 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:v,onChange:S=>x(S.target.checked),className:"w-3 h-3 rounded border-gray-300 text-cyan-500 focus:ring-cyan-400"}),"Canvas Docs"]}),e.jsx("button",{onClick:j,disabled:!u.trim()||a!=="idle"&&a!=="completed",className:"ml-auto text-[10px] px-2.5 py-1 bg-cyan-500 text-white rounded-md font-medium hover:bg-cyan-600 disabled:opacity-40 transition-colors",children:a==="idle"||a==="completed"?"Research":"Running..."})]}),e.jsx("div",{className:"px-3 py-2 text-[11px] text-gray-700 leading-relaxed whitespace-pre-wrap break-words max-h-[250px] overflow-y-auto min-h-[40px]",children:n||(a==="idle"?e.jsx("span",{className:"text-gray-400 italic",children:"Enter a topic and click Research to start."}):e.jsxs("div",{className:"flex items-center gap-1.5 text-gray-400",children:[e.jsx("div",{className:"w-2 h-2 bg-cyan-400 rounded-full animate-pulse"}),g[a]]}))}),e.jsx(z,{type:"source",position:H.Bottom,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"})]})}const ds=s.memo(cs);function us({id:r,data:l,selected:h}){const t=l,c=F.image,[u,d]=s.useState(String(t.prompt||t.content||"")),[a,m]=s.useState(!1),[n,b]=s.useState(t.imageUrl||""),[i,o]=s.useState(""),v=s.useCallback(()=>{!u.trim()||a||(m(!0),o(""),t.sendMessage?(t.sendMessage({type:"claude-command",command:`Generate an image based on this description: ${u}`,options:{canvasMode:!0,blockId:r,imageGeneration:!0}}),setTimeout(()=>{m(!1),o("Image generation requires an image API (DALL-E, Flux, etc.) connected via BYOK settings.")},2e3)):(m(!1),o("Requires a connected AI session with image generation capability.")))},[u,a,t.sendMessage,r]);return e.jsxs("div",{className:`
|
|
193
|
+
rounded-xl border-2 shadow-sm w-[280px] transition-shadow
|
|
194
|
+
${c.bg} ${c.border}
|
|
195
|
+
${h?"ring-2 ring-primary/40 shadow-md":"hover:shadow-md"}
|
|
196
|
+
`,children:[e.jsx(z,{type:"target",position:H.Top,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"}),e.jsxs("div",{className:`flex items-center justify-between px-3 py-2 border-b ${c.border}/30`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm",children:c.icon}),e.jsx("span",{className:`text-xs font-semibold ${c.accent} uppercase tracking-wide`,children:t.label||"Image"})]}),t.onDelete&&e.jsx("button",{onClick:()=>t.onDelete(r),className:"p-0.5 rounded hover:bg-red-100 text-red-400 transition-colors",title:"Delete",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"px-3 py-2",children:n?e.jsxs("div",{className:"relative rounded-lg overflow-hidden bg-gray-100",children:[e.jsx("img",{src:n,alt:"Generated",className:"w-full h-auto rounded-lg"}),e.jsx("button",{onClick:()=>window.open(n,"_blank"),className:"absolute top-1 right-1 p-1 bg-black/50 rounded text-white hover:bg-black/70 transition-colors",title:"Open full size",children:e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]}):e.jsx("div",{className:"w-full h-32 rounded-lg bg-pink-100/50 border border-pink-200/50 border-dashed flex flex-col items-center justify-center gap-1",children:a?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-6 h-6 border-2 border-pink-300/50 border-t-pink-500 rounded-full animate-spin"}),e.jsx("span",{className:"text-[10px] text-pink-400",children:"Generating..."})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-2xl opacity-30",children:"🖼️"}),e.jsx("span",{className:"text-[10px] text-gray-400",children:"No image yet"})]})})}),e.jsxs("div",{className:"px-3 pb-2",children:[i&&e.jsx("p",{className:"text-[9px] text-red-400 mb-1",children:i}),e.jsxs("div",{className:"flex items-end gap-1.5",children:[e.jsx("textarea",{value:u,onChange:x=>d(x.target.value),placeholder:"Describe the image...",rows:2,className:"flex-1 bg-white/60 text-gray-700 text-[11px] placeholder-gray-400 resize-none outline-none px-2 py-1.5 rounded-lg border border-pink-200/50 focus:border-pink-400/50"}),e.jsx("button",{onClick:v,disabled:!u.trim()||a,className:"shrink-0 px-2.5 py-1.5 bg-pink-500 text-white rounded-md text-[10px] font-medium hover:bg-pink-600 disabled:opacity-40 transition-colors",children:"Generate"})]})]}),e.jsx(z,{type:"source",position:H.Bottom,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"})]})}const ps=s.memo(us);function ms({id:r,data:l,selected:h}){const t=l,c=F.table,[u,d]=s.useState(""),[a,m]=s.useState(t.columns||[]),[n,b]=s.useState(t.rows||[]),[i,o]=s.useState(!1),v=s.useCallback(()=>{!u.trim()||i||(o(!0),t.sendMessage&&t.sendMessage({type:"claude-command",command:`Generate structured tabular data for: ${u}
|
|
197
|
+
|
|
198
|
+
Return the data as a markdown table. The first row should be headers.`,options:{canvasMode:!0,blockId:r,tableBlock:!0}}),setTimeout(()=>{m(["Name","Value","Status"]),b([{Name:"Example",Value:"100",Status:"Active"},{Name:"Sample",Value:"200",Status:"Pending"}]),o(!1)},1500))},[u,i,t.sendMessage,r]),x=s.useCallback(()=>{if(a.length===0)return;const j=a.join(","),g=n.map(R=>a.map(D=>`"${(R[D]||"").replace(/"/g,'""')}"`).join(",")).join(`
|
|
199
|
+
`),w=`${j}
|
|
200
|
+
${g}`,y=new Blob([w],{type:"text/csv"}),k=URL.createObjectURL(y),S=document.createElement("a");S.href=k,S.download=`${t.label||"table"}.csv`,S.click(),URL.revokeObjectURL(k)},[a,n,t.label]);return e.jsxs("div",{className:`
|
|
201
|
+
rounded-xl border-2 shadow-sm w-[360px] transition-shadow
|
|
202
|
+
${c.bg} ${c.border}
|
|
203
|
+
${h?"ring-2 ring-primary/40 shadow-md":"hover:shadow-md"}
|
|
204
|
+
`,children:[e.jsx(z,{type:"target",position:H.Top,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"}),e.jsxs("div",{className:`flex items-center justify-between px-3 py-2 border-b ${c.border}/30`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm",children:c.icon}),e.jsx("span",{className:`text-xs font-semibold ${c.accent} uppercase tracking-wide`,children:t.label||"Table"}),n.length>0&&e.jsxs("span",{className:"text-[9px] text-gray-400",children:["(",n.length," rows)"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[n.length>0&&e.jsx("button",{onClick:x,className:"p-0.5 rounded hover:bg-slate-200 text-slate-500 transition-colors",title:"Export CSV",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})})}),t.onDelete&&e.jsx("button",{onClick:()=>t.onDelete(r),className:"p-0.5 rounded hover:bg-red-100 text-red-400 transition-colors",title:"Delete",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),a.length>0?e.jsx("div",{className:"overflow-x-auto max-h-[200px] overflow-y-auto",children:e.jsxs("table",{className:"w-full text-[10px]",children:[e.jsx("thead",{children:e.jsx("tr",{className:"border-b border-slate-200",children:a.map(j=>e.jsx("th",{className:"px-2 py-1.5 text-left font-semibold text-slate-600 bg-slate-100/50",children:j},j))})}),e.jsx("tbody",{children:n.map((j,g)=>e.jsx("tr",{className:"border-b border-slate-100 hover:bg-slate-50/50",children:a.map(w=>e.jsx("td",{className:"px-2 py-1 text-gray-600",children:j[w]||""},w))},g))})]})}):e.jsx("div",{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-end gap-1.5",children:[e.jsx("input",{value:u,onChange:j=>d(j.target.value),onKeyDown:j=>{j.key==="Enter"&&v()},placeholder:"Describe the data you need...",className:"flex-1 bg-white/60 text-gray-700 text-[11px] placeholder-gray-400 outline-none px-2 py-1.5 rounded-lg border border-slate-200/50 focus:border-slate-400/50"}),e.jsx("button",{onClick:v,disabled:!u.trim()||i,className:"shrink-0 px-2.5 py-1.5 bg-slate-600 text-white rounded-md text-[10px] font-medium hover:bg-slate-700 disabled:opacity-40 transition-colors",children:i?"...":"Generate"})]})}),e.jsx(z,{type:"source",position:H.Bottom,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"})]})}const xs=s.memo(ms);let He=0;function hs({id:r,data:l,selected:h}){const t=l,c=F.list,[u,d]=s.useState((t.items||[]).map(g=>({...g,id:g.id||`li_${++He}`}))),[a,m]=s.useState(""),[n,b]=s.useState(""),i=s.useCallback(()=>{const g=a.trim();g&&(d(w=>[...w,{id:`li_${++He}`,text:g,status:"pending"}]),m(""))},[a]),o=s.useCallback(g=>{d(w=>w.filter(y=>y.id!==g))},[]),v=s.useCallback(()=>{!n.trim()||u.length===0||(d(g=>g.map(w=>({...w,status:"processing"}))),setTimeout(()=>{d(g=>g.map(w=>({...w,status:"done",result:`Processed: ${w.text} (${n})`})))},2e3))},[n,u]),x=u.filter(g=>g.status==="done").length,j=u.filter(g=>g.status==="processing").length;return e.jsxs("div",{className:`
|
|
205
|
+
rounded-xl border-2 shadow-sm w-[280px] transition-shadow
|
|
206
|
+
${c.bg} ${c.border}
|
|
207
|
+
${h?"ring-2 ring-primary/40 shadow-md":"hover:shadow-md"}
|
|
208
|
+
`,children:[e.jsx(z,{type:"target",position:H.Top,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"}),e.jsxs("div",{className:`flex items-center justify-between px-3 py-2 border-b ${c.border}/30`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm",children:c.icon}),e.jsx("span",{className:`text-xs font-semibold ${c.accent} uppercase tracking-wide`,children:t.label||"List"}),e.jsxs("span",{className:"text-[9px] text-gray-400",children:["(",u.length,x>0?`, ${x} done`:"",")"]})]}),t.onDelete&&e.jsx("button",{onClick:()=>t.onDelete(r),className:"p-0.5 rounded hover:bg-red-100 text-red-400 transition-colors",title:"Delete",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"max-h-[180px] overflow-y-auto",children:u.length===0?e.jsx("p",{className:"text-[10px] text-gray-400 text-center py-3",children:"Add items to the list"}):e.jsx("div",{className:"divide-y divide-violet-100",children:u.map(g=>e.jsxs("div",{className:"flex items-start gap-1.5 px-3 py-1.5 group",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full mt-1 shrink-0 ${g.status==="done"?"bg-emerald-400":g.status==="processing"?"bg-violet-400 animate-pulse":"bg-gray-300"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[11px] text-gray-700 truncate",children:g.text}),g.result&&e.jsx("p",{className:"text-[9px] text-gray-400 truncate mt-0.5",children:g.result})]}),e.jsx("button",{onClick:()=>o(g.id),className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-red-100 text-red-300 transition-all shrink-0",title:"Remove",children:e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},g.id))})}),e.jsxs("div",{className:"px-3 py-1.5 border-t border-violet-200/30",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e.jsx("input",{value:a,onChange:g=>m(g.target.value),onKeyDown:g=>{g.key==="Enter"&&i()},placeholder:"Add item...",className:"flex-1 bg-white/60 text-gray-700 text-[11px] placeholder-gray-400 outline-none px-2 py-1 rounded border border-violet-200/50 focus:border-violet-400/50"}),e.jsx("button",{onClick:i,disabled:!a.trim(),className:"text-[10px] px-2 py-1 bg-violet-500 text-white rounded font-medium hover:bg-violet-600 disabled:opacity-40 transition-colors",children:"+"})]}),u.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{value:n,onChange:g=>b(g.target.value),placeholder:"Bulk action for all items...",className:"flex-1 bg-white/60 text-gray-700 text-[10px] placeholder-gray-400 outline-none px-2 py-1 rounded border border-violet-200/50 focus:border-violet-400/50"}),e.jsx("button",{onClick:v,disabled:!n.trim()||j>0,className:"text-[9px] px-2 py-1 bg-violet-600 text-white rounded font-medium hover:bg-violet-700 disabled:opacity-40 transition-colors whitespace-nowrap",children:j>0?"Running...":"Run All"})]})]}),e.jsx(z,{type:"source",position:H.Bottom,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"})]})}const gs=s.memo(hs);function bs({id:r,data:l,selected:h}){const t=l,c=F.inputs,u=Object.entries(t.variables||{}).map(([x,j])=>({key:x,value:String(j),type:"text"})),[d,a]=s.useState(u.length>0?u:[]),[m,n]=s.useState(""),b=s.useCallback(()=>{const x=m.trim();!x||d.some(j=>j.key===x)||(a(j=>[...j,{key:x,value:"",type:"text"}]),n(""))},[m,d]),i=s.useCallback((x,j)=>{a(g=>g.map(w=>w.key===x?{...w,value:j}:w))},[]),o=s.useCallback(x=>{a(j=>j.filter(g=>g.key!==x))},[]),v=s.useCallback((x,j)=>{a(g=>g.map(w=>w.key===x?{...w,type:j}:w))},[]);return e.jsxs("div",{className:`
|
|
209
|
+
rounded-xl border-2 shadow-sm w-[280px] transition-shadow
|
|
210
|
+
${c.bg} ${c.border}
|
|
211
|
+
${h?"ring-2 ring-primary/40 shadow-md":"hover:shadow-md"}
|
|
212
|
+
`,children:[e.jsx(z,{type:"target",position:H.Top,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"}),e.jsxs("div",{className:`flex items-center justify-between px-3 py-2 border-b ${c.border}/30`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm",children:c.icon}),e.jsx("span",{className:`text-xs font-semibold ${c.accent} uppercase tracking-wide`,children:t.label||"Inputs"}),e.jsxs("span",{className:"text-[9px] text-gray-400",children:["(",d.length," vars)"]})]}),t.onDelete&&e.jsx("button",{onClick:()=>t.onDelete(r),className:"p-0.5 rounded hover:bg-red-100 text-red-400 transition-colors",title:"Delete",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto",children:d.length===0?e.jsxs("p",{className:"text-[10px] text-gray-400 text-center py-3",children:["Add variables that cascade to connected blocks via ",e.jsx("code",{className:"bg-orange-100 px-1 rounded",children:"{{key}}"})]}):e.jsx("div",{className:"divide-y divide-orange-100",children:d.map(x=>e.jsxs("div",{className:"px-3 py-1.5 group",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx("code",{className:"text-[10px] font-mono text-orange-600 bg-orange-100/60 px-1 py-0.5 rounded",children:`{{${x.key}}}`}),e.jsxs("select",{value:x.type,onChange:j=>v(x.key,j.target.value),className:"text-[9px] text-gray-400 bg-transparent outline-none cursor-pointer",children:[e.jsx("option",{value:"text",children:"text"}),e.jsx("option",{value:"number",children:"number"}),e.jsx("option",{value:"toggle",children:"toggle"})]}),e.jsx("button",{onClick:()=>o(x.key),className:"ml-auto opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-red-100 text-red-300 transition-all",title:"Remove variable",children:e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),x.type==="toggle"?e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:x.value==="true",onChange:j=>i(x.key,j.target.checked?"true":"false"),className:"w-3 h-3 rounded border-orange-300 text-orange-500 focus:ring-orange-400"}),e.jsx("span",{className:"text-[10px] text-gray-500",children:x.value==="true"?"On":"Off"})]}):e.jsx("input",{value:x.value,onChange:j=>i(x.key,j.target.value),type:x.type==="number"?"number":"text",placeholder:`Enter ${x.key} value...`,className:"w-full bg-white/60 text-gray-700 text-[11px] placeholder-gray-400 outline-none px-2 py-1 rounded border border-orange-200/50 focus:border-orange-400/50"})]},x.key))})}),e.jsx("div",{className:"px-3 py-1.5 border-t border-orange-200/30",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{value:m,onChange:x=>n(x.target.value.replace(/[^a-zA-Z0-9_]/g,"")),onKeyDown:x=>{x.key==="Enter"&&b()},placeholder:"variable_name",className:"flex-1 bg-white/60 text-gray-700 text-[11px] font-mono placeholder-gray-400 outline-none px-2 py-1 rounded border border-orange-200/50 focus:border-orange-400/50"}),e.jsx("button",{onClick:b,disabled:!m.trim(),className:"text-[10px] px-2 py-1 bg-orange-500 text-white rounded font-medium hover:bg-orange-600 disabled:opacity-40 transition-colors",children:"+ Add"})]})}),e.jsx(z,{type:"source",position:H.Bottom,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"})]})}const fs=s.memo(bs);function ys({id:r,data:l,selected:h}){const t=l,c=F.comparison,[u,d]=s.useState(String(t.content||"")),[a,m]=s.useState(t.models||["sonnet","openai/gpt-4o"]),[n,b]=s.useState(t.results||[]),[i,o]=s.useState(!1),[v,x]=s.useState(!1),j=s.useCallback(w=>{m(y=>y.includes(w)?y.filter(k=>k!==w):y.length>=4?y:[...y,w])},[]),g=s.useCallback(()=>{if(!u.trim()||a.length===0||i)return;o(!0);const w=a.map(y=>{const k=be.find(S=>S.value===y);return{modelId:y,modelLabel:(k==null?void 0:k.label)||y,content:"",status:"running"}});b(w),t.sendMessage&&a.forEach(y=>{t.sendMessage({type:"claude-command",command:u,options:{canvasMode:!0,blockId:r,comparisonModelId:y}})}),setTimeout(()=>{b(y=>y.map(k=>({...k,content:`[${k.modelLabel}] Response to: "${u.slice(0,50)}..."
|
|
213
|
+
|
|
214
|
+
This is a simulated comparison response. In production, each model would provide its own answer in parallel.`,status:"completed"}))),o(!1)},3e3)},[u,a,i,t.sendMessage,r]);return e.jsxs("div",{className:`
|
|
215
|
+
rounded-xl border-2 shadow-sm w-[480px] transition-shadow
|
|
216
|
+
${c.bg} ${c.border}
|
|
217
|
+
${h?"ring-2 ring-primary/40 shadow-md":"hover:shadow-md"}
|
|
218
|
+
`,children:[e.jsx(z,{type:"target",position:H.Top,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"}),e.jsxs("div",{className:`flex items-center justify-between px-3 py-2 border-b ${c.border}/30`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm",children:c.icon}),e.jsx("span",{className:`text-xs font-semibold ${c.accent} uppercase tracking-wide`,children:"Compare Models"}),e.jsxs("span",{className:"text-[9px] text-gray-400",children:["(",a.length," models)"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>x(!v),className:"text-[9px] px-1.5 py-0.5 rounded bg-fuchsia-100 text-fuchsia-600 hover:bg-fuchsia-200 transition-colors",children:v?"Hide":"Models"}),t.onDelete&&e.jsx("button",{onClick:()=>t.onDelete(r),className:"p-0.5 rounded hover:bg-red-100 text-red-400 transition-colors",title:"Delete",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),v&&e.jsx("div",{className:"px-3 py-2 border-b border-fuchsia-200/30 flex flex-wrap gap-1",children:be.map(w=>e.jsx("button",{onClick:()=>j(w.value),className:`text-[9px] px-2 py-0.5 rounded-full border transition-colors ${a.includes(w.value)?"bg-fuchsia-500 text-white border-fuchsia-500":"bg-white text-gray-500 border-gray-200 hover:border-fuchsia-300"} ${a.length>=4&&!a.includes(w.value)?"opacity-40":""}`,disabled:a.length>=4&&!a.includes(w.value),children:w.label},w.value))}),e.jsx("div",{className:"px-3 py-2 border-b border-fuchsia-200/30",children:e.jsxs("div",{className:"flex items-end gap-1.5",children:[e.jsx("textarea",{value:u,onChange:w=>d(w.target.value),placeholder:"Enter a prompt to compare across models...",rows:2,className:"flex-1 bg-white/60 text-gray-700 text-[11px] placeholder-gray-400 resize-none outline-none px-2 py-1.5 rounded-lg border border-fuchsia-200/50 focus:border-fuchsia-400/50"}),e.jsx("button",{onClick:g,disabled:!u.trim()||a.length===0||i,className:"shrink-0 px-3 py-1.5 bg-fuchsia-500 text-white rounded-md text-[10px] font-medium hover:bg-fuchsia-600 disabled:opacity-40 transition-colors",children:i?"Running...":"Compare"})]})}),n.length>0&&e.jsx("div",{className:`grid grid-cols-${Math.min(n.length,4)} divide-x divide-fuchsia-100`,style:{gridTemplateColumns:`repeat(${Math.min(n.length,4)}, 1fr)`},children:n.map(w=>e.jsxs("div",{className:"px-2 py-2 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1 mb-1.5",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${w.status==="completed"?"bg-emerald-400":w.status==="running"?"bg-fuchsia-400 animate-pulse":"bg-gray-300"}`}),e.jsx("span",{className:"text-[9px] font-semibold text-gray-500 truncate",children:w.modelLabel})]}),e.jsx("div",{className:"text-[10px] text-gray-600 leading-relaxed whitespace-pre-wrap break-words max-h-[150px] overflow-y-auto",children:w.content||(w.status==="running"?"Generating...":"")})]},w.modelId))}),n.length===0&&e.jsx("div",{className:"px-3 py-4 text-center",children:e.jsx("span",{className:"text-[10px] text-gray-400",children:"Select models, enter a prompt, and click Compare to see side-by-side results."})}),e.jsx(z,{type:"source",position:H.Bottom,className:"!w-2 !h-2 !bg-gray-400 !border-gray-300"})]})}const vs=s.memo(ys),we=280,Fe=150;let je=null;async function js(){return je||(je=await Ue(()=>import("./index-CS0fDqEC.js").then(r=>r.i),__vite__mapDeps([0,1]))),je.default}async function ws(r,l,h="TB"){var u,d;if(r.length===0)return r;const t=await js(),c=new t.graphlib.Graph;c.setGraph({rankdir:h,nodesep:60,ranksep:100,marginx:40,marginy:40}),c.setDefaultEdgeLabel(()=>({}));for(const a of r)c.setNode(a.id,{width:((u=a.measured)==null?void 0:u.width)||a.width||we,height:((d=a.measured)==null?void 0:d.height)||a.height||Fe});for(const a of l)c.setEdge(a.source,a.target);return t.layout(c),r.map(a=>{var i,o;const m=c.node(a.id);if(!m)return a;const n=((i=a.measured)==null?void 0:i.width)||a.width||we,b=((o=a.measured)==null?void 0:o.height)||a.height||Fe;return{...a,position:{x:m.x-n/2,y:m.y-b/2}}})}function X(r,l,h={dx:320,dy:0}){var u;if(l){const d=r.find(a=>a.id===l);if(d)return{x:d.position.x+h.dx,y:d.position.y+h.dy}}if(r.length===0)return{x:100,y:100};let t=-1/0,c=1/0;for(const d of r){const a=((u=d.measured)==null?void 0:u.width)||d.width||we,m=d.position.x+a;m>t&&(t=m),d.position.y<c&&(c=d.position.y)}return{x:t+80,y:c}}function ee(r,l){return r.length<=l?r:r.slice(0,l)+"..."}function Ke(r){var h;const l={};for(const t of r)if(t.type==="inputs"&&((h=t.data)!=null&&h.variables)){const c=t.data.variables;Object.assign(l,c)}return l}function Ye(r,l){return r.replace(/\{\{(\w+)\}\}/g,(h,t)=>t in l?l[t]:h)}function he(r,l){var c,u,d,a,m,n,b;if(r.length===0)return"Canvas is empty.";const h=Ke(r),t=[`## Canvas Context
|
|
219
|
+
`];if(Object.keys(h).length>0){t.push("### Variables:");for(const[i,o]of Object.entries(h))t.push(`- {{${i}}} = "${o}"`);t.push("")}t.push("### Blocks:");for(const i of r){const o=i.type||"note";let v=String(((c=i.data)==null?void 0:c.content)||((u=i.data)==null?void 0:u.label)||"");v=Ye(v,h);const x=ee(v,120),j=(d=i.data)!=null&&d.modelId?` [model: ${i.data.modelId}]`:"";t.push(`- [${o}${j} at (${Math.round(i.position.x)}, ${Math.round(i.position.y)})]: "${x}"`)}if(t.push(""),l.length>0){t.push("### Connections:");for(const i of l){const o=r.find(g=>g.id===i.source),v=r.find(g=>g.id===i.target),x=ee(String(((a=o==null?void 0:o.data)==null?void 0:a.content)||(o==null?void 0:o.type)||"unknown"),40),j=ee(String(((m=v==null?void 0:v.data)==null?void 0:m.content)||(v==null?void 0:v.type)||"unknown"),40);t.push(`- "${x}" ↔ "${j}"`)}t.push("")}if(r.length>1){const i=[...r].sort((x,j)=>x.position.x-j.position.x||x.position.y-j.position.y),o=i[0],v=i[i.length-1];t.push("### Spatial Layout:"),t.push(`- Leftmost: ${o.type} ("${ee(String(((n=o.data)==null?void 0:n.content)||""),30)}")`),t.push(`- Rightmost: ${v.type} ("${ee(String(((b=v.data)==null?void 0:b.content)||""),30)}")`),t.push(`- Total nodes: ${r.length}`),t.push("")}return t.join(`
|
|
220
|
+
`)}function Ve(r,l,h){var a,m,n,b;if(l.size===0)return null;const t=r.filter(i=>l.has(i.id));if(t.length===0)return null;const c=Ke(r),u=[`## Selected Items Context
|
|
221
|
+
`];for(const i of t){let o=String(((a=i.data)==null?void 0:a.content)||((m=i.data)==null?void 0:m.label)||"");o=Ye(o,c),u.push(`- [${i.type}]: "${ee(o,150)}"`)}const d=h.filter(i=>l.has(i.source)&&l.has(i.target));if(d.length>0){u.push(`
|
|
222
|
+
### Connections:`);for(const i of d){const o=t.find(x=>x.id===i.source),v=t.find(x=>x.id===i.target);u.push(`- "${ee(String(((n=o==null?void 0:o.data)==null?void 0:n.content)||""),40)}" ↔ "${ee(String(((b=v==null?void 0:v.data)==null?void 0:b.content)||""),40)}"`)}}return u.join(`
|
|
223
|
+
`)}function ks(r){const l=[],h=r.split(`
|
|
224
|
+
`);let t="response",c="",u=[],d=!1,a="";const m=[];let n=null,b="";const i=()=>{const o=u.join(`
|
|
225
|
+
`).trim();o&&l.push({type:t,heading:c,content:o}),u=[]};for(const o of h){if(o.trim().startsWith("```")){if(d){if(n!==null){m.push({heading:b,html:n.join(`
|
|
226
|
+
`)}),n=null,d=!1,a="";continue}d=!1,a=""}else if(d=!0,a=o.trim().slice(3).trim().toLowerCase(),a==="html"||a==="htm"){n=[],b=c||`Page ${m.length+1}`;continue}u.push(o);continue}if(n!==null){n.push(o);continue}if(d){u.push(o);continue}if(o.startsWith("## ")||o.startsWith("### ")){i();const v=o.replace(/^#{2,3}\s+/,"").trim();c=v;const x=v.toLowerCase();x.includes("research")||x.includes("analysis")||x.includes("finding")?t="research":x.includes("suggestion")||x.includes("idea")||x.includes("recommendation")?t="suggestion":t="response";continue}if(o.startsWith("> ")){t!=="suggestion"&&(i(),t="suggestion",c=c||"Suggestion"),u.push(o.slice(2));continue}u.push(o)}i();for(const o of m)l.push({type:"webpage",heading:o.heading,content:o.html});return l}let Ns=0;function Ge(){return`canvas_${Date.now()}_${++Ns}`}function Cs(r,l,h,t){const c=ks(r),u=[],d=[],a=c.filter(o=>o.type!=="webpage"),m=c.filter(o=>o.type==="webpage");let n=h;const b=15;for(const o of a){const v=Ge(),x=o.content.split(`
|
|
227
|
+
`)[0].slice(0,60);u.push({id:v,type:o.type,position:{x:l,y:n},data:{label:o.heading||o.type,content:o.content.length>800?o.content.slice(0,800)+`
|
|
228
|
+
...`:o.content,fullContent:o.content,summary:x,compact:!0,status:"completed"}}),n+=100+b}if(m.length>0){let o=l;const v=a.length>0?n+60:h,x=40;let j=null;for(let g=0;g<m.length;g++){const w=m[g],y=Ge(),k=w.content.match(/<title[^>]*>([^<]+)<\/title>/i),S=k?k[1]:w.heading;u.push({id:y,type:"webpage",position:{x:o,y:v},data:{label:S,content:w.content,html:w.content,pageName:S,pageIndex:g+1}}),j&&d.push({id:`e_${j}_${y}`,source:j,target:y,type:"smoothstep",style:{strokeDasharray:"5,5"}}),j=y,o+=280+x}}t&&u.length>0&&d.push({id:`e_${t}_${u[0].id}`,source:t,target:u[0].id,animated:!0});const i=u.filter(o=>o.type!=="webpage");for(let o=0;o<i.length-1;o++)d.push({id:`e_${i[o].id}_${i[o+1].id}`,source:i[o].id,target:i[o+1].id});if(i.length>0&&m.length>0){const o=u.filter(v=>v.type==="webpage");o.length>0&&d.push({id:`e_${i[i.length-1].id}_${o[0].id}`,source:i[i.length-1].id,target:o[0].id,style:{strokeDasharray:"5,5"}})}return{nodes:u,edges:d}}const ge=`You are a visual AI assistant working on an infinite canvas. The user has drawn elements on the canvas and is asking you to analyze and respond.
|
|
229
|
+
|
|
230
|
+
IMPORTANT: Structure your response using markdown headings so it can be rendered as visual blocks:
|
|
231
|
+
- Use ## headings to separate major sections
|
|
232
|
+
- Use ### Research: or ### Analysis: for research/analysis sections
|
|
233
|
+
- Use ### Suggestions: or ### Ideas: for suggestion sections
|
|
234
|
+
- Use > blockquotes for key insights or recommendations
|
|
235
|
+
- Keep each section concise (2-4 sentences or bullet points)
|
|
236
|
+
- Be visual and structured — your response will appear as blocks on the canvas
|
|
237
|
+
- If asked to create web pages/websites, output each page as a separate \`\`\`html code block with a heading for the page name
|
|
238
|
+
|
|
239
|
+
Here is the current canvas context:
|
|
240
|
+
|
|
241
|
+
`,Ss=2e3;function $s(r){return e.jsx(te,{id:r.id,nodeType:"research",data:r.data,selected:r.selected})}function Ls(r){return e.jsx(te,{id:r.id,nodeType:"suggestion",data:r.data,selected:r.selected})}function Es(r){return e.jsx(te,{id:r.id,nodeType:"summary",data:r.data,selected:r.selected})}const Ts={note:Zt,prompt:es,response:ss,research:$s,suggestion:Ls,pdf:rs,summary:Es,webpage:os,chat:is,deepresearch:ds,image:ps,table:xs,list:gs,inputs:fs,comparison:vs};let Ms=0;function q(){return`n_${Date.now()}_${++Ms}`}function Ds(r){var t,c,u,d,a,m;const l=[],h=[];if(!Array.isArray(r)||r.length===0)return{nodes:l,edges:h};if(((c=(t=r[0])==null?void 0:t.position)==null?void 0:c.x)!==void 0)return{nodes:r.filter(n=>!n.source),edges:r.filter(n=>n.source)};if(r.length===1&&((u=r[0])!=null&&u.nodes)&&((d=r[0])!=null&&d.edges))return{nodes:r[0].nodes,edges:r[0].edges};for(const n of r)if(((a=n.customData)==null?void 0:a.blockType)==="context-link")h.push({id:`e_${n.customData.sourceId}_${n.customData.targetId}`,source:n.customData.sourceId,target:n.customData.targetId});else if((m=n.customData)!=null&&m.blockType&&n.type==="rectangle"){const b=n.customData.blockType,i=["note","prompt","response","research","suggestion","pdf","summary","webpage","chat","deepresearch","image","table","list","inputs","comparison"];l.push({id:n.id,type:i.includes(b)?b:"note",position:{x:n.x||0,y:n.y||0},data:{label:n.customData.fileName||b,content:n.customData.content||n.customData.extractedText||n.customData.generatedContent||"",...n.customData.fileName&&{fileName:n.customData.fileName},...n.customData.pageCount&&{pageCount:n.customData.pageCount},...n.customData.extractedText&&{extractedText:n.customData.extractedText},...n.customData.thumbnail&&{thumbnail:n.customData.thumbnail}}})}return{nodes:l,edges:h}}function _s({projectName:r,sendMessage:l,latestMessage:h,isFullScreen:t}){var _e,Re,Pe,Ie;const{connectionState:c}=Et(),{fitView:u,getViewport:d,setViewport:a}=ft(),[m,n,b]=yt([]),[i,o,v]=vt([]),[x,j]=s.useState(!1),[g,w]=s.useState("saved"),[y,k]=s.useState(!0),[S,R]=s.useState(!1),[D,$]=s.useState(""),[_,L]=s.useState([]),[I,T]=s.useState(null),[V,Z]=s.useState(null),[Q,se]=s.useState(!1),[le,ne]=s.useState(null),[re,ke]=s.useState(null),[qe,Ne]=s.useState(!1),[Je,Ce]=s.useState(!1),ie=s.useRef(null),pe=s.useRef(""),ce=s.useRef(null),fe=s.useRef(r);fe.current=r;const J=s.useRef(""),Y=s.useRef(null),Se=s.useRef(null),me=s.useRef(null),B=s.useRef([]),K=s.useRef([]);B.current=m,K.current=i;const Xe=s.useMemo(()=>I&&B.current.find(p=>p.id===I)||null,[I,m]),$e=s.useCallback(p=>{T(p)},[]),Le=s.useCallback(p=>{Z(p)},[]),Ze=s.useCallback(p=>{p.target.closest(".react-flow__node")||ne({x:p.clientX,y:p.clientY})},[]),Qe=s.useCallback((p,f)=>{const N=X(B.current),C={id:q(),type:p,position:N,data:{label:p.charAt(0).toUpperCase()+p.slice(1),content:"",...p==="inputs"&&{variables:{}},...p==="chat"&&{messages:[]},...p==="deepresearch"&&{plannerModel:"",writerModel:"",searchEnabled:{web:!0,documents:!1}},...p==="table"&&{rows:[],columns:[]},...p==="list"&&{items:[]},...p==="comparison"&&{models:[],results:[]}}};n(E=>[...E,C]),ne(null)},[n]),Ee=s.useCallback((p,f,N)=>{n(C=>C.map(E=>E.id===p?{...E,data:{...E.data,modelId:f,modelProvider:N}}:E))},[n]),ye=s.useCallback((p,f)=>{var A,G,W,O;const N=B.current.find(U=>U.id===p);if(!N)return;const C=q(),E={id:C,type:N.type||"note",position:{x:(((A=N.position)==null?void 0:A.x)||0)+40,y:(((G=N.position)==null?void 0:G.y)||0)+40},data:{...N.data,label:`${((W=N.data)==null?void 0:W.label)||N.type} (copy)`,onDelete:void 0,onRun:void 0,onRerun:void 0,onBranch:void 0,onNodeClick:void 0,onWebPageClick:void 0,onModelChange:void 0,sendMessage:void 0,latestMessage:void 0}},M=K.current.find(U=>U.target===p),P=[];if(M&&P.push({id:`e_${M.source}_${C}`,source:M.source,target:C}),n(U=>[...U,E]),o(U=>[...U,...P]),f&&N.type==="prompt"&&l){const U=String(((O=N.data)==null?void 0:O.content)||"");U&&setTimeout(()=>ue(U,M==null?void 0:M.source),200)}},[n,o,l]),et=s.useCallback((p,f)=>{p.preventDefault(),p.stopPropagation(),ke({pos:{x:p.clientX,y:p.clientY},nodeId:f})},[]),tt=s.useCallback(p=>{const f=B.current.find(C=>C.id===p);if(!f)return[];const N=[{label:"Duplicate",icon:"📋",onClick:()=>ye(p)}];return f.type==="prompt"&&N.push({label:"Duplicate & Re-run",icon:"🔄",onClick:()=>ye(p,!0)}),(f.type==="response"||f.type==="research"||f.type==="suggestion")&&N.push({label:"Branch from here",icon:"🌿",onClick:()=>{var E;const C=String(((E=f.data)==null?void 0:E.content)||"").slice(0,100);ue(`Continue from: "${C}"
|
|
242
|
+
|
|
243
|
+
Provide more detail.`,p)}}),N.push({label:"Copy Content",icon:"📄",onClick:()=>{var E,M;const C=String(((E=f.data)==null?void 0:E.fullContent)||((M=f.data)==null?void 0:M.content)||"");navigator.clipboard.writeText(C).catch(()=>{})}}),N.push({label:"Delete",icon:"🗑️",onClick:()=>ve(p),danger:!0}),N},[ye,ve]),Te=s.useCallback((p,f)=>{n(N=>[...N,...p]),o(N=>[...N,...f]),setTimeout(()=>u({padding:.2,duration:400}),100)},[n,o,u]),st=s.useCallback((p,f)=>{n(N=>N.map(C=>C.id===p?{...C,data:{...C.data,html:f,content:f}}:C))},[n]),ae=s.useMemo(()=>V&&B.current.find(p=>p.id===V)||null,[V,m]),nt=s.useCallback(p=>{var M,P,A,G,W;const f=B.current.find(O=>O.id===p);if(!f)return;const N=q(),C={id:N,type:f.type||"response",position:{x:(((M=f.position)==null?void 0:M.x)||0)+260,y:((P=f.position)==null?void 0:P.y)||0},data:{...f.data,label:`${((A=f.data)==null?void 0:A.label)||"Response"} (pinned)`,content:String(((G=f.data)==null?void 0:G.fullContent)||((W=f.data)==null?void 0:W.content)||""),compact:!1,summary:void 0,fullContent:void 0}},E={id:`e_pin_${p}_${N}`,source:p,target:N,style:{strokeDasharray:"5,5",stroke:"#a78bfa"},type:"smoothstep"};n(O=>[...O,C]),o(O=>[...O,E])},[n,o]),ve=s.useCallback(p=>{n(f=>f.filter(N=>N.id!==p)),o(f=>f.filter(N=>N.source!==p&&N.target!==p))},[n,o]),Me=s.useCallback((p,f)=>{if(!l||x)return;const N=K.current.filter(P=>P.source===p),C=new Set(N.map(P=>P.target));n(P=>P.filter(A=>!C.has(A.id))),o(P=>P.filter(A=>A.source!==p||!C.has(A.target))),Y.current=p;const E=he(B.current,K.current),M=ge+E+`
|
|
244
|
+
|
|
245
|
+
User prompt: `+f;J.current="",j(!0),L(P=>[...P,{role:"user",text:`(rerun) ${f}`}]),l({type:"claude-command",command:M,options:{canvasMode:!0,blockId:p}})},[l,x,n,o]),rt=s.useMemo(()=>m.map(p=>({...p,data:{...p.data,onDelete:f=>n(N=>N.filter(C=>C.id!==f)),onRun:(f,N)=>ue(N,f),onRerun:(f,N)=>Me(f,N),onBranch:f=>xt(f),onNodeClick:$e,onWebPageClick:Le,onModelChange:Ee,onEdit:f=>{},sendMessage:l,latestMessage:h,isCanvasRunning:x}})),[m,$e,Le,Me,Ee,l,h,x]);s.useEffect(()=>{let p=!1;return k(!0),oe.canvas.load(r).then(async f=>{var N;if(!p){try{const C=await f.json(),E=C.elements||[],M=C.appState||{},{nodes:P,edges:A}=Ds(E);n(P),o(A),M.x!==void 0?a({x:M.x,y:M.y,zoom:M.zoom||1}):M.scrollX!==void 0&&a({x:M.scrollX||0,y:M.scrollY||0,zoom:((N=M.zoom)==null?void 0:N.value)||1}),pe.current=JSON.stringify({nodes:P,edges:A})}catch{n([]),o([])}k(!1)}}).catch(()=>{p||(n([]),o([]),k(!1))}),()=>{p=!0}},[r]);const at=s.useCallback(()=>{ie.current&&clearTimeout(ie.current),w("unsaved"),ie.current=setTimeout(()=>{const p=B.current,f=K.current,N=JSON.stringify({nodes:p,edges:f});if(N===pe.current){w("saved");return}if(!navigator.onLine){ce.current={nodes:p,edges:f,viewport:d()},w("unsaved");return}w("saving");const C=d();oe.canvas.save(fe.current,[{nodes:p,edges:f}],C).then(()=>{pe.current=N,ce.current=null,w("saved")}).catch(()=>{ce.current={nodes:p,edges:f,viewport:C},w("unsaved")})},Ss)},[d]);s.useEffect(()=>{at()},[m,i]),s.useEffect(()=>{if(c!=="connected")return;const p=ce.current;p&&(w("saving"),oe.canvas.save(fe.current,[{nodes:p.nodes,edges:p.edges}],p.viewport).then(()=>{pe.current=JSON.stringify({nodes:p.nodes,edges:p.edges}),ce.current=null,w("saved")}).catch(()=>w("unsaved")))},[c]),s.useEffect(()=>()=>{ie.current&&clearTimeout(ie.current)},[]);const ot=s.useCallback(p=>{o(f=>jt(p,f))},[o]),de=s.useRef(null);s.useEffect(()=>{if(!(!h||!x)){if(h.type==="claude-response"||h.type==="assistant"){const p=h.content||h.text||h.message||"";if(p){J.current+=p;const f=J.current,N=f.length>600?`...
|
|
246
|
+
`+f.slice(-500):f;if(de.current)n(C=>C.map(E=>E.id===de.current?{...E,data:{...E.data,content:N,label:"AI Streaming..."}}:E));else{const C=q();de.current=C;const E=X(B.current,Y.current||void 0),M={id:C,type:"response",position:E,data:{label:"AI Streaming...",content:N,compact:!1,status:"running"}},P=[];Y.current&&P.push({id:`e_${Y.current}_${C}`,source:Y.current,target:C,animated:!0}),n(A=>[...A,M]),o(A=>[...A,...P])}}}if(h.type==="claude-complete"||h.type==="message_stop"){const p=J.current.trim(),f=de.current;p&&(f&&(n(N=>N.filter(C=>C.id!==f)),o(N=>N.filter(C=>C.source!==f&&C.target!==f))),lt(p),L(N=>[...N,{role:"ai",text:p.slice(0,200)+(p.length>200?"...":"")}])),j(!1),J.current="",de.current=null}}},[h,x]);const lt=s.useCallback(p=>{const f=X(B.current,Y.current||void 0),{nodes:N,edges:C}=Cs(p,f.x,f.y,Y.current||void 0);n(E=>[...E,...N]),o(E=>[...E,...C]),setTimeout(()=>u({padding:.2,duration:400}),100)},[u,n,o]),it=s.useCallback(()=>{const p=X(B.current),f={id:q(),type:"note",position:p,data:{label:"Note",content:""}};n(N=>[...N,f])},[n]),ct=s.useCallback(async p=>{try{const f=await Ue(()=>import("./pdf-CE_K4jFx.js"),[]);f.GlobalWorkerOptions.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${f.version}/pdf.worker.min.mjs`;const N=await p.arrayBuffer(),C=await f.getDocument({data:N}).promise,E=Math.min(C.numPages,10);let M="";for(let W=1;W<=E;W++){const xe=(await(await C.getPage(W)).getTextContent()).items.map(ht=>ht.str).join(" ");M+=`[Page ${W}]
|
|
247
|
+
${xe}
|
|
248
|
+
|
|
249
|
+
`}let P="";try{const W=await C.getPage(1),O=W.getViewport({scale:.5}),U=document.createElement("canvas");U.width=O.width,U.height=O.height;const xe=U.getContext("2d");xe&&(await W.render({canvasContext:xe,viewport:O}).promise,P=U.toDataURL("image/jpeg",.6))}catch{}const A=X(B.current),G={id:q(),type:"pdf",position:A,data:{label:p.name,content:M.slice(0,500),fileName:p.name,pageCount:C.numPages,extractedText:M,thumbnail:P}};n(W=>[...W,G])}catch{const f=X(B.current);n(N=>[...N,{id:q(),type:"note",position:f,data:{label:p.name,content:`Failed to process PDF: ${p.name}`}}])}},[n]),dt=s.useCallback(()=>{if(!l||x)return;const p=new Set(B.current.filter(O=>O.selected).map(O=>O.id)),f=Ve(B.current,p,K.current),N=f||he(B.current,K.current),C=!!f,E=C?"Analyzing selected elements...":"Analyzing canvas...",M=X(B.current),P=q(),A={id:P,type:"prompt",position:M,data:{label:"Prompt",content:E}};n(O=>[...O,A]),Y.current=P;const W=ge+`[${C?"Selected items context":"Full canvas context"}]
|
|
250
|
+
`+N+`
|
|
251
|
+
|
|
252
|
+
Analyze the canvas and provide a structured visual response.`;J.current="",j(!0),L(O=>[...O,{role:"user",text:E}]),l({type:"claude-command",command:W,options:{canvasMode:!0,blockId:P}})},[l,x,n]),ut=s.useCallback(()=>{l&&l({type:"cancel-command"}),j(!1),J.current=""},[l]),pt=s.useCallback(()=>{const p=new Set(["response","research","suggestion","prompt","webpage","summary","deepresearch","image","table","list","comparison"]);n(f=>f.filter(N=>!p.has(N.type||""))),o(f=>{const N=new Set(B.current.filter(C=>!p.has(C.type||"")).map(C=>C.id));return f.filter(C=>N.has(C.source)&&N.has(C.target))}),L([])},[n,o]),mt=s.useCallback(async()=>{const p=await ws(B.current,K.current);n(p),setTimeout(()=>u({padding:.2,duration:400}),50)},[n,u]),ue=s.useCallback((p,f)=>{if(!l||x)return;const N=X(B.current,f),C=q(),E={id:C,type:"prompt",position:N,data:{label:"Prompt",content:p}},M=[];f&&M.push({id:`e_${f}_${C}`,source:f,target:C}),n(G=>[...G,E]),o(G=>[...G,...M]),Y.current=C;const P=he(B.current,K.current),A=ge+P+`
|
|
253
|
+
|
|
254
|
+
User prompt: `+p;J.current="",j(!0),L(G=>[...G,{role:"user",text:p}]),l({type:"claude-command",command:A,options:{canvasMode:!0,blockId:C}})},[l,x,n,o]),xt=s.useCallback(p=>{var E;const f=B.current.find(M=>M.id===p);if(!f)return;const C=`Continue from: "${String(((E=f.data)==null?void 0:E.content)||"").slice(0,100)}"
|
|
255
|
+
|
|
256
|
+
Provide more detail or explore a different angle.`;ue(C,p)},[ue]),De=s.useCallback(()=>{const p=D.trim();if(!p||!l||x)return;const f=new Set(B.current.filter(W=>W.selected).map(W=>W.id)),N=Ve(B.current,f,K.current),C=N||he(B.current,K.current),E=N?"Selected items context":"Full canvas context",M=X(B.current),P=q(),A={id:P,type:"prompt",position:M,data:{label:"Prompt",content:p}};n(W=>[...W,A]),Y.current=P;const G=ge+`[${E}]
|
|
257
|
+
`+C+`
|
|
258
|
+
|
|
259
|
+
User message: `+p;J.current="",j(!0),L(W=>[...W,{role:"user",text:p}]),$(""),l({type:"claude-command",command:G,options:{canvasMode:!0,blockId:P}})},[D,l,x,n]);return s.useEffect(()=>{me.current&&(me.current.scrollTop=me.current.scrollHeight)},[_]),y?e.jsx("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-4 h-4 border-2 border-muted-foreground/30 border-t-muted-foreground rounded-full animate-spin"}),"Loading canvas..."]})}):e.jsxs("div",{className:"h-full w-full relative",children:[e.jsx(Mt,{onAddNote:it,onAddPdf:ct,onRun:dt,onStop:ut,onClearAi:pt,onAutoLayout:mt,onExport:()=>se(!0),onTemplates:()=>Ne(!0),onSwarm:()=>Ce(!0),isRunning:x}),e.jsx("div",{onDoubleClick:Ze,className:"h-full w-full",children:e.jsxs(wt,{nodes:rt,edges:i,onNodesChange:b,onEdgesChange:v,onConnect:ot,onNodeContextMenu:(p,f)=>et(p,f.id),nodeTypes:Ts,fitView:!0,fitViewOptions:{padding:.2},minZoom:.1,maxZoom:3,defaultEdgeOptions:{type:"smoothstep",animated:!1},proOptions:{hideAttribution:!0},children:[e.jsx(kt,{variant:Nt.Dots,gap:20,size:1,color:"#e5e7eb"}),e.jsx(Ct,{position:"bottom-right",showInteractive:!1}),e.jsx(St,{position:"bottom-right",style:{marginBottom:50},nodeStrokeWidth:3,pannable:!0,zoomable:!0})]})}),le&&e.jsx(Pt,{position:le,onSelect:Qe,onClose:()=>ne(null)}),re&&e.jsx(Bt,{position:re.pos,actions:tt(re.nodeId),onClose:()=>ke(null)}),qe&&e.jsx(Ut,{onLoadTemplate:Te,currentNodes:m,currentEdges:i,onClose:()=>Ne(!1)}),Je&&e.jsx(Jt,{onCreateBlocks:Te,sendMessage:l,latestMessage:h,onClose:()=>Ce(!1)}),e.jsx(Wt,{node:Xe,onClose:()=>T(null),onPin:nt,onDelete:ve}),ae&&e.jsx(Ht,{html:String(((_e=ae.data)==null?void 0:_e.html)||((Re=ae.data)==null?void 0:Re.content)||""),pageName:String(((Pe=ae.data)==null?void 0:Pe.pageName)||((Ie=ae.data)==null?void 0:Ie.label)||"Page"),nodeId:ae.id,onClose:()=>Z(null),onHtmlChange:st,sendMessage:l,latestMessage:h}),Q&&e.jsx(Vt,{nodes:m,projectName:r,onClose:()=>se(!1)}),e.jsxs("div",{className:"absolute top-4 right-4 z-20 flex items-center gap-2",children:[c!=="connected"&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] px-2 py-1 rounded-full border border-amber-500/20 bg-amber-500/5 text-amber-400",children:[e.jsx("div",{className:"w-1.5 h-1.5 bg-amber-400 rounded-full animate-pulse"}),c==="reconnecting"?"Reconnecting...":"Offline"]}),e.jsx("div",{className:`text-[10px] px-2 py-1 rounded-full border ${g==="saved"?"text-emerald-500 border-emerald-500/20 bg-emerald-500/5":g==="saving"?"text-amber-500 border-amber-500/20 bg-amber-500/5":"text-muted-foreground border-border/50 bg-muted/50"}`,children:g==="saved"?"Saved":g==="saving"?"Saving...":"Unsaved"})]}),x&&e.jsx("div",{className:"absolute top-4 left-1/2 -translate-x-1/2 z-20",children:e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-primary/10 border border-primary/20 rounded-full text-xs text-primary font-medium",children:[e.jsx("div",{className:"w-2 h-2 bg-primary rounded-full animate-pulse"}),"AI is analyzing canvas..."]})}),e.jsx("button",{onClick:()=>{R(!S),S||setTimeout(()=>{var p;return(p=Se.current)==null?void 0:p.focus()},100)},className:"absolute bottom-4 right-4 z-20 w-10 h-10 rounded-full bg-primary text-primary-foreground shadow-lg flex items-center justify-center hover:bg-primary/90 transition-colors",title:S?"Hide chat":"Chat with canvas",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:S?e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"}):e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})}),S&&e.jsx("div",{className:"absolute bottom-16 right-4 z-20 w-80 max-h-[50vh]",children:e.jsxs("div",{className:"bg-card/95 backdrop-blur-md border border-border/50 rounded-2xl shadow-xl flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-2 border-b border-border/30 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-medium text-foreground",children:"Canvas Chat"}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded text-muted-foreground bg-muted/50",children:m.filter(p=>p.selected).length>0?`${m.filter(p=>p.selected).length} selected`:"full canvas"})]}),e.jsxs("div",{ref:me,className:"flex-1 overflow-y-auto max-h-48 px-3 py-2 space-y-2",children:[_.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground/60 text-center py-4",children:"Ask AI about your canvas. Context is auto-attached."}),_.map((p,f)=>e.jsxs("div",{className:`text-xs px-2 py-1.5 rounded-lg ${p.role==="user"?"bg-primary/10 text-foreground ml-6":"bg-muted/50 text-foreground mr-6"}`,children:[e.jsx("span",{className:"font-medium text-[10px] text-muted-foreground block mb-0.5",children:p.role==="user"?"You":"AI"}),p.text]},f)),x&&e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-1 px-2",children:[e.jsx("div",{className:"w-1.5 h-1.5 bg-primary rounded-full animate-pulse"}),"Thinking..."]})]}),e.jsx("div",{className:"p-2 border-t border-border/30",children:e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("textarea",{ref:Se,value:D,onChange:p=>$(p.target.value),onKeyDown:p=>{p.key==="Enter"&&!p.shiftKey&&(p.preventDefault(),De())},placeholder:"Ask about your canvas...",rows:1,className:"flex-1 bg-muted/30 text-foreground text-xs placeholder-muted-foreground/50 resize-none outline-none px-3 py-2 rounded-lg max-h-16 overflow-y-auto border border-border/30 focus:border-primary/30"}),e.jsx("button",{onClick:De,disabled:!D.trim()||x,className:"shrink-0 w-8 h-8 rounded-lg bg-primary text-primary-foreground flex items-center justify-center disabled:opacity-40 hover:bg-primary/90 transition-colors",children:x?e.jsx("div",{className:"w-3 h-3 border-2 border-primary-foreground/30 border-t-primary-foreground rounded-full animate-spin"}):e.jsx("svg",{className:"w-3.5 h-3.5 rotate-90",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.2,d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})})})]})})]})})]})}function Rs(r){return e.jsx(bt,{children:e.jsx(_s,{...r})})}const Hs=gt.memo(Rs);export{Hs as default};
|