mirror of
https://github.com/cdr/code-server.git
synced 2025-12-09 01:45:44 +01:00
13 lines
36 KiB
JavaScript
13 lines
36 KiB
JavaScript
var de=Object.defineProperty,xe=Object.defineProperties;var ue=Object.getOwnPropertyDescriptors;var q=Object.getOwnPropertySymbols;var me=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable;var H=(s,r,a)=>r in s?de(s,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[r]=a,D=(s,r)=>{for(var a in r||(r={}))me.call(r,a)&&H(s,a,r[a]);if(q)for(var a of q(r))pe.call(r,a)&&H(s,a,r[a]);return s},$=(s,r)=>xe(s,ue(r));var he=(s,r)=>()=>(r||s((r={exports:{}}).exports,r),r.exports);var A=(s,r,a)=>new Promise((d,c)=>{var t=f=>{try{u(a.next(f))}catch(p){c(p)}},b=f=>{try{u(a.throw(f))}catch(p){c(p)}},u=f=>f.done?d(f.value):Promise.resolve(f.value).then(t,b);u((a=a.apply(s,r)).next())});import{r as l,a as be,R as ge}from"./vendor-CIE12tXq.js";import{F as z,P as fe,M as je,W as Z,S as ye,C as Ne,E as ve,a as we,b as Se,c as Ce,d as ke,e as ee,T as V,f as Te,g as Oe,B as K,X as U,U as Ae,L as B,h as Ee,K as Fe,i as Y,A as Ie,j as se,k as te,l as Re,m as Le,G as Pe,n as Me,I as Q,o as De}from"./icons-BknwnP5E.js";import{L as $e,d as Ke}from"./monaco-DIrTT30v.js";var ts=he(F=>{(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const c of document.querySelectorAll('link[rel="modulepreload"]'))d(c);new MutationObserver(c=>{for(const t of c)if(t.type==="childList")for(const b of t.addedNodes)b.tagName==="LINK"&&b.rel==="modulepreload"&&d(b)}).observe(document,{childList:!0,subtree:!0});function a(c){const t={};return c.integrity&&(t.integrity=c.integrity),c.referrerPolicy&&(t.referrerPolicy=c.referrerPolicy),c.crossOrigin==="use-credentials"?t.credentials="include":c.crossOrigin==="anonymous"?t.credentials="omit":t.credentials="same-origin",t}function d(c){if(c.ep)return;c.ep=!0;const t=a(c);fetch(c.href,t)}})();var re={exports:{}},W={};/**
|
||
* @license React
|
||
* react-jsx-runtime.production.min.js
|
||
*
|
||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||
*
|
||
* This source code is licensed under the MIT license found in the
|
||
* LICENSE file in the root directory of this source tree.
|
||
*/var We=l,_e=Symbol.for("react.element"),ze=Symbol.for("react.fragment"),Be=Object.prototype.hasOwnProperty,Ge=We.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ue={key:!0,ref:!0,__self:!0,__source:!0};function ae(s,r,a){var d,c={},t=null,b=null;a!==void 0&&(t=""+a),r.key!==void 0&&(t=""+r.key),r.ref!==void 0&&(b=r.ref);for(d in r)Be.call(r,d)&&!Ue.hasOwnProperty(d)&&(c[d]=r[d]);if(s&&s.defaultProps)for(d in r=s.defaultProps,r)c[d]===void 0&&(c[d]=r[d]);return{$$typeof:_e,type:s,key:t,ref:b,props:c,_owner:Ge.current}}W.Fragment=ze;W.jsx=ae;W.jsxs=ae;re.exports=W;var e=re.exports,G={},X=be;G.createRoot=X.createRoot,G.hydrateRoot=X.hydrateRoot;const Je=({files:s,selectedFile:r,onFileSelect:a,onShowChat:d,onShowProviderForm:c,onShowTools:t,onOpenCodeServer:b,showChat:u,showTools:f})=>{const[p,y]=l.useState(new Set),[w,x]=l.useState(!1),[T,C]=l.useState(""),h=n=>{const g=new Set(p);g.has(n)?g.delete(n):g.add(n),y(g)},k=()=>A(F,null,function*(){T.trim()&&(console.log("Creating new file:",T),C(""),x(!1))}),i=(n,g=0)=>{const o=p.has(n.path),N=r===n.path;return n.type==="folder"?e.jsxs("div",{children:[e.jsxs("div",{className:`flex items-center px-3 py-1 cursor-pointer hover:bg-cursor-hover ${N?"bg-cursor-accent text-white":"text-cursor-text"}`,style:{paddingLeft:`${g*16+12}px`},onClick:()=>h(n.path),children:[o?e.jsx(we,{className:"w-4 h-4 mr-1"}):e.jsx(Se,{className:"w-4 h-4 mr-1"}),e.jsx(Ce,{className:"w-4 h-4 mr-2"}),e.jsx("span",{className:"text-sm",children:n.name})]}),o&&n.children&&e.jsx("div",{children:n.children.map(S=>i(S,g+1))})]},n.path):e.jsxs("div",{className:`flex items-center px-3 py-1 cursor-pointer hover:bg-cursor-hover ${N?"bg-cursor-accent text-white":"text-cursor-text"}`,style:{paddingLeft:`${g*16+12}px`},onClick:()=>a(n.path),children:[e.jsx(z,{className:"w-4 h-4 mr-2"}),e.jsx("span",{className:"text-sm",children:n.name})]},n.path)};return e.jsxs("div",{className:"w-64 bg-cursor-sidebar border-r border-cursor-border flex flex-col h-full",children:[e.jsx("div",{className:"p-3 border-b border-cursor-border",children:e.jsx("h2",{className:"text-lg font-semibold text-cursor-text",children:"Explorer"})}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:s.length===0?e.jsxs("div",{className:"p-3 text-center text-gray-400",children:[e.jsx(z,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No files found"}),e.jsx("p",{className:"text-xs",children:"Create a new file to get started"})]}):e.jsx("div",{children:s.map(n=>i(n))})}),w&&e.jsx("div",{className:"p-3 border-t border-cursor-border",children:e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("input",{type:"text",value:T,onChange:n=>C(n.target.value),placeholder:"File name...",className:"flex-1 px-2 py-1 bg-cursor-bg border border-cursor-border rounded text-sm text-cursor-text",onKeyPress:n=>n.key==="Enter"&&k(),autoFocus:!0}),e.jsx("button",{onClick:k,className:"px-2 py-1 bg-cursor-accent text-white rounded text-sm hover:bg-blue-600",children:"Create"}),e.jsx("button",{onClick:()=>x(!1),className:"px-2 py-1 bg-gray-600 text-white rounded text-sm hover:bg-gray-700",children:"Cancel"})]})}),e.jsxs("div",{className:"p-3 border-t border-cursor-border space-y-2",children:[e.jsxs("button",{onClick:()=>x(!w),className:"w-full flex items-center px-3 py-2 rounded text-sm transition-colors hover:bg-cursor-hover group",children:[e.jsx(fe,{className:"w-4 h-4 mr-2"}),e.jsx("span",{className:"flex-1 text-left",children:"New File"})]}),e.jsxs("button",{onClick:d,className:`w-full flex items-center px-3 py-2 rounded text-sm transition-colors hover:bg-cursor-hover group ${u?"bg-cursor-accent text-white":"text-cursor-text"}`,children:[e.jsx(je,{className:"w-4 h-4 mr-2"}),e.jsx("span",{className:"flex-1 text-left",children:"AI Chat"})]}),e.jsxs("button",{onClick:t,className:`w-full flex items-center px-3 py-2 rounded text-sm transition-colors hover:bg-cursor-hover group ${f?"bg-cursor-accent text-white":"text-cursor-text"}`,children:[e.jsx(Z,{className:"w-4 h-4 mr-2"}),e.jsx("span",{className:"flex-1 text-left",children:"Tools"})]}),e.jsxs("button",{onClick:c,className:"w-full flex items-center px-3 py-2 rounded text-sm transition-colors hover:bg-cursor-hover group",children:[e.jsx(ye,{className:"w-4 h-4 mr-2"}),e.jsx("span",{className:"flex-1 text-left",children:"Settings"})]}),e.jsxs("button",{onClick:b,className:"w-full flex items-center px-3 py-2 rounded text-sm transition-colors hover:bg-cursor-hover group",children:[e.jsx(Ne,{className:"w-4 h-4 mr-2"}),e.jsx("span",{className:"flex-1 text-left",children:"VS Code Server"}),e.jsx(ve,{className:"w-3 h-3 opacity-0 group-hover:opacity-100 transition-opacity"})]})]}),e.jsx("div",{className:"p-3 border-t border-cursor-border text-xs text-gray-400",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{children:"Monaco Editor"}),e.jsx("span",{children:"v1.0.0"})]})})]})},qe=({selectedFile:s,onFileChange:r,onSave:a,onRun:d,backendUrl:c})=>{const t=$e(),b=l.useRef(null),[u,f]=l.useState(""),[p,y]=l.useState(!1),[w,x]=l.useState(!1),[T,C]=l.useState(""),[h,k]=l.useState(!1);l.useEffect(()=>{s&&i(s)},[s]),l.useEffect(()=>{t&&(t.editor.setTheme("vs-dark"),t.editor.addKeybindingRules([{keybinding:t.KeyMod.CtrlCmd|t.KeyCode.KeyS,command:"save-file",when:"editorTextFocus"},{keybinding:t.KeyMod.CtrlCmd|t.KeyCode.Enter,command:"run-code",when:"editorTextFocus"},{keybinding:t.KeyMod.CtrlCmd|t.KeyCode.F11,command:"toggle-fullscreen",when:"editorTextFocus"}]),t.editor.registerCommand("save-file",()=>{s&&n()}),t.editor.registerCommand("run-code",()=>{s&&g()}),t.editor.registerCommand("toggle-fullscreen",()=>{y(!p)}))},[t,s,p]);const i=j=>A(F,null,function*(){try{k(!0);const I=yield(yield fetch(`${c}/api/workspace/file/${j}`)).json();f(I.content||"")}catch(O){console.error("Failed to load file:",O),f("// Error loading file")}finally{k(!1)}}),n=()=>A(F,null,function*(){if(s&&u)try{yield a(s,u),console.log("File saved successfully")}catch(j){console.error("Failed to save file:",j)}}),g=()=>A(F,null,function*(){if(s&&u)try{x(!0),C(`Running code...
|
||
`);const O=yield(yield fetch(`${c}/api/execute`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:u,language:o(s)})})).json();C(I=>I+O.output+`
|
||
`),yield d(s,u)}catch(j){console.error("Failed to run code:",j),C(O=>O+`Error: ${j.message}
|
||
`)}}),o=j=>{var L;const O=(L=j.split(".").pop())==null?void 0:L.toLowerCase();return{js:"javascript",jsx:"javascript",ts:"typescript",tsx:"typescript",py:"python",java:"java",cpp:"cpp",c:"c",cs:"csharp",go:"go",rs:"rust",php:"php",rb:"ruby",html:"html",css:"css",scss:"scss",json:"json",xml:"xml",yaml:"yaml",yml:"yaml",md:"markdown",sql:"sql",sh:"shell",bash:"shell",dockerfile:"dockerfile"}[O||""]||"plaintext"},N=j=>{b.current=j,j.updateOptions({fontSize:14,fontFamily:"Fira Code, Consolas, Monaco, monospace",lineNumbers:"on",wordWrap:"on",minimap:{enabled:!0},folding:!0,bracketPairColorization:{enabled:!0},autoClosingBrackets:"always",autoClosingQuotes:"always",autoIndent:"full",formatOnPaste:!0,formatOnType:!0,suggestOnTriggerCharacters:!0,acceptSuggestionOnEnter:"on",tabCompletion:"on",wordBasedSuggestions:"off",parameterHints:{enabled:!0},hover:{enabled:!0},contextmenu:!0,mouseWheelZoom:!0,smoothScrolling:!0,cursorBlinking:"blink",cursorSmoothCaretAnimation:!0,renderWhitespace:"selection",renderControlCharacters:!1,renderIndentGuides:!0,highlightActiveIndentGuide:!0,rulers:[80,120],scrollBeyondLastLine:!1,automaticLayout:!0,dragAndDrop:!0,links:!0,detectIndentation:!0,insertSpaces:!0,tabSize:2,trimAutoWhitespace:!0,largeFileOptimizations:!0,scrollbar:{vertical:"auto",horizontal:"auto",useShadows:!0,verticalHasArrows:!0,horizontalHasArrows:!0,verticalScrollbarSize:12,horizontalScrollbarSize:12}}),j.addAction({id:"save-file",label:"Save File",keybindings:[t.KeyMod.CtrlCmd|t.KeyCode.KeyS],run:n}),j.addAction({id:"run-code",label:"Run Code",keybindings:[t.KeyMod.CtrlCmd|t.KeyCode.Enter],run:g}),j.addAction({id:"toggle-fullscreen",label:"Toggle Fullscreen",keybindings:[t.KeyMod.CtrlCmd|t.KeyCode.F11],run:()=>y(!p)})},S=j=>{f(j||""),s&&r(s,j||"")};return h?e.jsx("div",{className:"flex items-center justify-center h-full bg-cursor-bg",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-cursor-accent mx-auto mb-4"}),e.jsx("p",{className:"text-cursor-text",children:"Loading file..."})]})}):e.jsxs("div",{className:`flex flex-col h-full bg-cursor-bg ${p?"fixed inset-0 z-50":""}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-cursor-border bg-cursor-sidebar",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(z,{className:"w-5 h-5 text-cursor-accent"}),e.jsx("span",{className:"font-medium text-cursor-text",children:s||"No file selected"}),s&&e.jsx("span",{className:"text-sm text-gray-400",children:o(s)})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs("button",{onClick:n,disabled:!s,className:"flex items-center px-3 py-1 bg-cursor-accent text-white rounded hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed",title:"Save (Ctrl+S)",children:[e.jsx(ke,{className:"w-4 h-4 mr-1"}),"Save"]}),e.jsxs("button",{onClick:g,disabled:!s,className:"flex items-center px-3 py-1 bg-green-600 text-white rounded hover:bg-green-700 disabled:opacity-50 disabled:cursor-not-allowed",title:"Run (Ctrl+Enter)",children:[e.jsx(ee,{className:"w-4 h-4 mr-1"}),"Run"]}),e.jsxs("button",{onClick:()=>x(!w),className:"flex items-center px-3 py-1 bg-gray-600 text-white rounded hover:bg-gray-700",title:"Toggle Terminal",children:[e.jsx(V,{className:"w-4 h-4 mr-1"}),"Terminal"]}),e.jsx("button",{onClick:()=>y(!p),className:"flex items-center px-3 py-1 bg-gray-600 text-white rounded hover:bg-gray-700",title:"Toggle Fullscreen (Ctrl+F11)",children:p?e.jsx(Te,{className:"w-4 h-4"}):e.jsx(Oe,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex-1 flex",children:[e.jsx("div",{className:"flex-1",children:e.jsx(Ke,{height:"100%",language:s?o(s):"plaintext",value:u,onChange:S,onMount:N,theme:"vs-dark",options:{fontSize:14,fontFamily:"Fira Code, Consolas, Monaco, monospace",lineNumbers:"on",wordWrap:"on",minimap:{enabled:!0},folding:!0,bracketPairColorization:{enabled:!0},autoClosingBrackets:"always",autoClosingQuotes:"always",autoIndent:"full",formatOnPaste:!0,formatOnType:!0,suggestOnTriggerCharacters:!0,acceptSuggestionOnEnter:"on",tabCompletion:"on",wordBasedSuggestions:"off",parameterHints:{enabled:!0},hover:{enabled:!0},contextmenu:!0,mouseWheelZoom:!0,smoothScrolling:!0,cursorBlinking:"blink",cursorSmoothCaretAnimation:!0,renderWhitespace:"selection",renderControlCharacters:!1,renderIndentGuides:!0,highlightActiveIndentGuide:!0,rulers:[80,120],scrollBeyondLastLine:!1,automaticLayout:!0,dragAndDrop:!0,links:!0,detectIndentation:!0,insertSpaces:!0,tabSize:2,trimAutoWhitespace:!0,largeFileOptimizations:!0}})}),w&&e.jsxs("div",{className:"w-1/3 border-l border-cursor-border bg-cursor-sidebar",children:[e.jsxs("div",{className:"flex items-center justify-between p-2 border-b border-cursor-border",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(V,{className:"w-4 h-4 text-cursor-accent"}),e.jsx("span",{className:"text-sm font-medium text-cursor-text",children:"Terminal"})]}),e.jsx("button",{onClick:()=>x(!1),className:"text-gray-400 hover:text-cursor-text",children:"×"})]}),e.jsx("div",{className:"p-2 h-full overflow-auto",children:e.jsx("pre",{className:"text-sm text-cursor-text font-mono whitespace-pre-wrap",children:T||`Terminal ready...
|
||
`})})]})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-1 border-t border-cursor-border bg-cursor-sidebar text-xs text-cursor-text",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx("span",{children:"Ready"}),s&&e.jsx("span",{children:s})]}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx("span",{children:"UTF-8"}),e.jsx("span",{children:"2 spaces"}),e.jsx("span",{children:"Monaco Editor"})]})]})]})},He=({socket:s,apiKeys:r,selectedProvider:a,onProviderChange:d,backendUrl:c})=>{const[t,b]=l.useState([]),[u,f]=l.useState(""),[p,y]=l.useState(!1),w=l.useRef(null);l.useEffect(()=>{s&&(s.onmessage=i=>{try{const n=JSON.parse(i.data);if(n.type==="chat-response"){const g={id:Date.now().toString(),type:"assistant",content:n.response,timestamp:new Date,provider:n.provider};b(o=>[...o,g]),y(!1)}else if(n.type==="typing-start")y(!0);else if(n.type==="typing-stop")y(!1);else if(n.type==="error"){const g={id:Date.now().toString(),type:"assistant",content:`Error: ${n.error}`,timestamp:new Date};b(o=>[...o,g]),y(!1)}}catch(n){console.error("Failed to parse WebSocket message:",n)}})},[s]),l.useEffect(()=>{x()},[t]);const x=()=>{var i;(i=w.current)==null||i.scrollIntoView({behavior:"smooth"})},T=()=>A(F,null,function*(){if(!u.trim()||!r[a])return;const i={id:Date.now().toString(),type:"user",content:u,timestamp:new Date};if(b(n=>[...n,i]),f(""),s&&s.readyState===WebSocket.OPEN)s.send(JSON.stringify({type:"chat",content:u,provider:a,apiKey:r[a],model:C(a)}));else try{const g=yield(yield fetch(`${c}/api/chat`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:u,provider:a,apiKey:r[a],model:C(a)})})).json(),o={id:Date.now().toString(),type:"assistant",content:g.response,timestamp:new Date,provider:a};b(N=>[...N,o])}catch(n){console.error("Failed to send message:",n);const g={id:Date.now().toString(),type:"assistant",content:"Failed to send message. Please check your connection.",timestamp:new Date};b(o=>[...o,g])}}),C=i=>({openai:"gpt-4",anthropic:"claude-3-sonnet-20240229",google:"gemini-pro",mistral:"mistral-large-latest",openrouter:"meta-llama/llama-2-70b-chat"})[i]||"gpt-4",h=i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),T())},k=()=>{b([])};return e.jsxs("div",{className:"h-80 border-t border-cursor-border bg-cursor-sidebar flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-cursor-border",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(K,{className:"w-5 h-5 text-cursor-accent"}),e.jsx("span",{className:"font-semibold",children:"AI Assistant"}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${(s==null?void 0:s.readyState)===WebSocket.OPEN?"bg-green-500":"bg-red-500"}`}),e.jsx("span",{className:"text-xs text-gray-400",children:(s==null?void 0:s.readyState)===WebSocket.OPEN?"Connected":"Disconnected"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs("select",{value:a,onChange:i=>d(i.target.value),className:"bg-cursor-bg border border-cursor-border rounded px-2 py-1 text-sm",children:[e.jsx("option",{value:"openai",children:"OpenAI"}),e.jsx("option",{value:"anthropic",children:"Anthropic"}),e.jsx("option",{value:"google",children:"Google Gemini"}),e.jsx("option",{value:"mistral",children:"Mistral"}),e.jsx("option",{value:"openrouter",children:"OpenRouter"})]}),e.jsx("button",{onClick:k,className:"p-1 hover:bg-cursor-hover rounded",title:"Clear chat",children:e.jsx(U,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 space-y-3",children:[t.length===0&&e.jsxs("div",{className:"text-center text-gray-400 py-8",children:[e.jsx(K,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{children:"Start a conversation with the AI assistant"}),e.jsx("p",{className:"text-sm",children:"Make sure to set your API key in settings"})]}),t.map(i=>e.jsx("div",{className:`flex ${i.type==="user"?"justify-end":"justify-start"}`,children:e.jsx("div",{className:`max-w-xs lg:max-w-md px-3 py-2 rounded-lg ${i.type==="user"?"bg-cursor-accent text-white":"bg-cursor-bg border border-cursor-border"}`,children:e.jsxs("div",{className:"flex items-start space-x-2",children:[i.type==="assistant"&&e.jsx(K,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),i.type==="user"&&e.jsx(Ae,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:i.content}),e.jsxs("div",{className:"flex items-center justify-between mt-1",children:[e.jsx("span",{className:"text-xs opacity-70",children:i.timestamp.toLocaleTimeString()}),i.provider&&e.jsxs("span",{className:"text-xs opacity-70",children:["via ",i.provider]})]})]})]})})},i.id)),p&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-cursor-bg border border-cursor-border rounded-lg px-3 py-2",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(K,{className:"w-4 h-4"}),e.jsxs("div",{className:"flex space-x-1",children:[e.jsx("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce"}),e.jsx("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"0.1s"}}),e.jsx("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"0.2s"}})]})]})})}),e.jsx("div",{ref:w})]}),e.jsx("div",{className:"p-3 border-t border-cursor-border",children:e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("input",{type:"text",value:u,onChange:i=>f(i.target.value),onKeyPress:h,placeholder:r[a]?"Ask me anything...":"Please set your API key in settings first",disabled:!r[a],className:"flex-1 bg-cursor-bg border border-cursor-border rounded px-3 py-2 text-sm focus:outline-none focus:border-cursor-accent disabled:opacity-50"}),e.jsx("button",{onClick:T,disabled:!u.trim()||!r[a]||p,className:"bg-cursor-accent text-white px-4 py-2 rounded hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed flex items-center",children:p?e.jsx(B,{className:"w-4 h-4 animate-spin"}):e.jsx(Ee,{className:"w-4 h-4"})})]})})]})},Ve=({onSave:s,onClose:r,existingKeys:a})=>{const[d,c]=l.useState("openai"),[t,b]=l.useState(""),[u,f]=l.useState(!1),[p,y]=l.useState(null),w=[{id:"openai",name:"OpenAI",description:"GPT-4, GPT-3.5 Turbo, and more",models:["gpt-4","gpt-3.5-turbo","gpt-4-turbo"],placeholder:"sk-...",website:"https://platform.openai.com/api-keys"},{id:"anthropic",name:"Anthropic",description:"Claude 3 Sonnet, Haiku, and Opus",models:["claude-3-sonnet","claude-3-haiku","claude-3-opus"],placeholder:"sk-ant-...",website:"https://console.anthropic.com/"},{id:"google",name:"Google Gemini",description:"Gemini Pro and Pro Vision",models:["gemini-pro","gemini-pro-vision","gemini-1.5-pro"],placeholder:"AIza...",website:"https://makersuite.google.com/app/apikey"},{id:"mistral",name:"Mistral AI",description:"Mistral Large, Medium, and Small",models:["mistral-large","mistral-medium","mistral-small"],placeholder:"...",website:"https://console.mistral.ai/"},{id:"openrouter",name:"OpenRouter",description:"Access to 100+ AI models",models:["meta-llama/llama-2-70b-chat","microsoft/wizardlm-13b","openai/gpt-4"],placeholder:"sk-or-...",website:"https://openrouter.ai/keys"}],x=w.find(h=>h.id===d),T=()=>{t.trim()&&s(d,t.trim())},C=()=>A(F,null,function*(){if(t.trim()){f(!0),y(null);try{const h=yield fetch("/api/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:"Hello, this is a test message.",provider:d,apiKey:t.trim(),model:(x==null?void 0:x.models[0])||"gpt-4"})});if(h.ok)y({success:!0,message:"API key is valid!"});else{const k=yield h.json();y({success:!1,message:k.details||"API key test failed"})}}catch(h){y({success:!1,message:"Failed to test API key"})}finally{f(!1)}}});return e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-cursor-sidebar rounded-lg shadow-xl max-w-md w-full mx-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-cursor-border",children:[e.jsx("h2",{className:"text-lg font-semibold text-cursor-text",children:"AI Provider Settings"}),e.jsx("button",{onClick:r,className:"text-gray-400 hover:text-cursor-text",children:e.jsx(U,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-cursor-text mb-2",children:"Select AI Provider"}),e.jsx("select",{value:d,onChange:h=>c(h.target.value),className:"w-full bg-cursor-bg border border-cursor-border rounded px-3 py-2 text-cursor-text",children:w.map(h=>e.jsx("option",{value:h.id,children:h.name},h.id))})]}),x&&e.jsxs("div",{className:"bg-cursor-bg rounded p-3",children:[e.jsx("h3",{className:"font-medium text-cursor-text",children:x.name}),e.jsx("p",{className:"text-sm text-gray-400 mt-1",children:x.description}),e.jsxs("div",{className:"mt-2",children:[e.jsx("p",{className:"text-xs text-gray-400",children:"Available models:"}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:x.models.map(h=>e.jsx("span",{className:"px-2 py-1 bg-cursor-accent text-white text-xs rounded",children:h},h))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-cursor-text mb-2",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx(Fe,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"password",value:t,onChange:h=>b(h.target.value),placeholder:(x==null?void 0:x.placeholder)||"Enter your API key",className:"w-full bg-cursor-bg border border-cursor-border rounded pl-10 pr-3 py-2 text-cursor-text"})]}),e.jsxs("p",{className:"text-xs text-gray-400 mt-1",children:["Get your API key from"," ",e.jsx("a",{href:x==null?void 0:x.website,target:"_blank",rel:"noopener noreferrer",className:"text-cursor-accent hover:underline",children:x==null?void 0:x.website})]})]}),p&&e.jsx("div",{className:`p-3 rounded ${p.success?"bg-green-50 border border-green-200":"bg-red-50 border border-red-200"}`,children:e.jsxs("div",{className:"flex items-center",children:[p.success?e.jsx(Y,{className:"w-4 h-4 text-green-500 mr-2"}):e.jsx(Ie,{className:"w-4 h-4 text-red-500 mr-2"}),e.jsx("span",{className:`text-sm ${p.success?"text-green-700":"text-red-700"}`,children:p.message})]})}),Object.keys(a).length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-cursor-text mb-2",children:"Saved API Keys"}),e.jsx("div",{className:"space-y-2",children:Object.entries(a).map(([h,k])=>e.jsxs("div",{className:"flex items-center justify-between bg-cursor-bg rounded p-2",children:[e.jsx("span",{className:"text-sm text-cursor-text capitalize",children:h}),e.jsxs("span",{className:"text-xs text-gray-400",children:[k.substring(0,8),"..."]})]},h))})]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-cursor-border",children:[e.jsxs("button",{onClick:C,disabled:!t.trim()||u,className:"flex items-center px-3 py-2 bg-gray-600 text-white rounded hover:bg-gray-700 disabled:opacity-50 disabled:cursor-not-allowed",children:[u?e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"}):e.jsx(Y,{className:"w-4 h-4 mr-2"}),"Test API Key"]}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{onClick:r,className:"px-4 py-2 text-gray-400 hover:text-cursor-text",children:"Cancel"}),e.jsx("button",{onClick:T,disabled:!t.trim(),className:"px-4 py-2 bg-cursor-accent text-white rounded hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed",children:"Save"})]})]})]})})},Ye=({onToolExecute:s,onResult:r,backendUrl:a})=>{const[d,c]=l.useState([]),[t,b]=l.useState(""),[u,f]=l.useState({}),[p,y]=l.useState(!1),[w,x]=l.useState([]),[T,C]=l.useState(!0);l.useEffect(()=>{h()},[]);const h=()=>A(F,null,function*(){try{const N=yield(yield fetch(`${a}/api/tools`)).json();c(N.tools||[])}catch(o){console.error("Failed to load tools:",o)}finally{C(!1)}}),k=o=>{d.find(S=>S.name===o)&&(b(o),f({}))},i=(o,N)=>{f(S=>$(D({},S),{[o]:N}))},n=()=>A(F,null,function*(){if(!t)return;y(!0);const o=Date.now();try{const S=yield(yield fetch(`${a}/api/tools/execute`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({toolName:t,params:u})})).json(),j=Date.now()-o,O={id:Date.now().toString(),toolName:t,params:u,result:S,executionTime:j,timestamp:new Date().toISOString(),success:S.success!==!1};x(I=>[O,...I]),r(O)}catch(N){const S={id:Date.now().toString(),toolName:t,params:u,result:{error:N.message},executionTime:Date.now()-o,timestamp:new Date().toISOString(),success:!1};x(j=>[S,...j])}finally{y(!1)}}),g=d.find(o=>o.name===t);return T?e.jsx("div",{className:"w-80 bg-cursor-sidebar border-l border-cursor-border flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(B,{className:"w-8 h-8 animate-spin text-cursor-accent mx-auto mb-2"}),e.jsx("p",{className:"text-cursor-text",children:"Loading tools..."})]})}):e.jsxs("div",{className:"w-80 bg-cursor-sidebar border-l border-cursor-border flex flex-col h-full",children:[e.jsx("div",{className:"p-3 border-b border-cursor-border",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Z,{className:"w-5 h-5 text-cursor-accent"}),e.jsx("h2",{className:"text-lg font-semibold text-cursor-text",children:"Tools"})]})}),e.jsxs("div",{className:"p-3 border-b border-cursor-border",children:[e.jsx("label",{className:"block text-sm font-medium text-cursor-text mb-2",children:"Select Tool"}),e.jsxs("select",{value:t,onChange:o=>k(o.target.value),className:"w-full bg-cursor-bg border border-cursor-border rounded px-3 py-2 text-cursor-text",children:[e.jsx("option",{value:"",children:"Choose a tool..."}),d.map(o=>e.jsx("option",{value:o.name,children:o.name},o.name))]})]}),g&&e.jsxs("div",{className:"p-3 border-b border-cursor-border",children:[e.jsx("h3",{className:"font-medium text-cursor-text mb-1",children:g.name}),e.jsx("p",{className:"text-sm text-gray-400",children:g.description})]}),g&&g.parameters&&e.jsxs("div",{className:"p-3 border-b border-cursor-border",children:[e.jsx("h4",{className:"text-sm font-medium text-cursor-text mb-2",children:"Parameters"}),e.jsx("div",{className:"space-y-2",children:Object.entries(g.parameters).map(([o,N])=>e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs text-gray-400 mb-1",children:[o," (",N.type||"string",")"]}),e.jsx("input",{type:N.type==="number"?"number":"text",value:u[o]||"",onChange:S=>i(o,S.target.value),placeholder:`Enter ${o}...`,className:"w-full bg-cursor-bg border border-cursor-border rounded px-2 py-1 text-sm text-cursor-text"})]},o))})]}),t&&e.jsx("div",{className:"p-3 border-b border-cursor-border",children:e.jsxs("button",{onClick:n,disabled:p,className:"w-full flex items-center justify-center px-4 py-2 bg-cursor-accent text-white rounded hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed",children:[p?e.jsx(B,{className:"w-4 h-4 animate-spin mr-2"}):e.jsx(ee,{className:"w-4 h-4 mr-2"}),p?"Executing...":"Execute Tool"]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3",children:[e.jsx("h4",{className:"text-sm font-medium text-cursor-text mb-2",children:"Results"}),w.length===0?e.jsx("p",{className:"text-sm text-gray-400",children:"No results yet"}):e.jsx("div",{className:"space-y-2",children:w.map(o=>e.jsxs("div",{className:"bg-cursor-bg rounded p-2 border border-cursor-border",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-sm font-medium text-cursor-text",children:o.toolName}),e.jsxs("div",{className:"flex items-center space-x-2",children:[o.success?e.jsx(se,{className:"w-4 h-4 text-green-500"}):e.jsx(te,{className:"w-4 h-4 text-red-500"}),e.jsxs("span",{className:"text-xs text-gray-400",children:[o.executionTime,"ms"]})]})]}),e.jsx("div",{className:"text-xs text-gray-400 mb-1",children:new Date(o.timestamp).toLocaleTimeString()}),e.jsx("pre",{className:"text-xs text-cursor-text bg-cursor-sidebar rounded p-2 overflow-x-auto",children:JSON.stringify(o.result,null,2)})]},o.id))})]})]})},Qe=({isConnected:s,selectedFile:r,lineCount:a,currentLine:d,currentColumn:c,language:t,gitBranch:b})=>e.jsxs("div",{className:"flex items-center justify-between px-3 py-1 bg-cursor-sidebar border-t border-cursor-border text-xs text-cursor-text",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsxs("div",{className:"flex items-center space-x-1",children:[s?e.jsx(Re,{className:"w-3 h-3 text-green-500"}):e.jsx(Le,{className:"w-3 h-3 text-red-500"}),e.jsx("span",{children:s?"Connected":"Disconnected"})]}),r&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("span",{children:r}),e.jsx("span",{children:"•"}),e.jsx("span",{children:t})]}),b&&e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(Pe,{className:"w-3 h-3"}),e.jsx("span",{children:b})]})]}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs("span",{children:["Ln ",d,", Col ",c]}),a>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsxs("span",{children:[a," lines"]})]})]}),e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(Me,{className:"w-2 h-2 text-green-500"}),e.jsx("span",{children:"Ready"})]})})]})]}),Xe=({notification:s,onClose:r})=>{const a=()=>{switch(s.type){case"success":return e.jsx(se,{className:"w-5 h-5 text-green-500"});case"error":return e.jsx(te,{className:"w-5 h-5 text-red-500"});case"warning":return e.jsx(De,{className:"w-5 h-5 text-yellow-500"});case"info":return e.jsx(Q,{className:"w-5 h-5 text-blue-500"});default:return e.jsx(Q,{className:"w-5 h-5 text-blue-500"})}},d=()=>{switch(s.type){case"success":return"bg-green-50 border-green-200";case"error":return"bg-red-50 border-red-200";case"warning":return"bg-yellow-50 border-yellow-200";case"info":return"bg-blue-50 border-blue-200";default:return"bg-blue-50 border-blue-200"}};return e.jsx("div",{className:`max-w-sm w-full bg-white shadow-lg rounded-lg pointer-events-auto ring-1 ring-black ring-opacity-5 overflow-hidden ${d()}`,children:e.jsx("div",{className:"p-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0",children:a()}),e.jsxs("div",{className:"ml-3 w-0 flex-1 pt-0.5",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:s.title}),e.jsx("p",{className:"mt-1 text-sm text-gray-500",children:s.message})]}),e.jsx("div",{className:"ml-4 flex-shrink-0 flex",children:e.jsxs("button",{className:"bg-white rounded-md inline-flex text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500",onClick:()=>r(s.id),children:[e.jsx("span",{className:"sr-only",children:"Close"}),e.jsx(U,{className:"h-5 w-5"})]})})]})})})},Ze=({notifications:s,onClose:r})=>e.jsx("div",{"aria-live":"assertive",className:"fixed inset-0 flex items-end px-4 py-6 pointer-events-none sm:p-6 sm:items-start z-50",children:e.jsx("div",{className:"w-full flex flex-col items-center space-y-4 sm:items-end",children:s.map(a=>e.jsx(Xe,{notification:a,onClose:r},a.id))})}),R="https://cursor-backend.YOUR_SUBDOMAIN.workers.dev",es="wss://cursor-backend.YOUR_SUBDOMAIN.workers.dev";function ss(){const[s,r]=l.useState(null),[a,d]=l.useState([]),[c,t]=l.useState(!1),[b,u]=l.useState(!1),[f,p]=l.useState(!1),[y,w]=l.useState(null),[x,T]=l.useState({}),[C,h]=l.useState("openai"),[k,i]=l.useState([]),[n,g]=l.useState(1),[o,N]=l.useState(1),[S,j]=l.useState(0),[O,I]=l.useState(""),[L,_]=l.useState(!1);l.useEffect(()=>{const m=new WebSocket(es);return w(m),m.onopen=()=>{_(!0),console.log("Connected to Cloudflare Workers WebSocket")},m.onclose=()=>{_(!1),console.log("Disconnected from WebSocket")},m.onerror=v=>{console.error("WebSocket error:",v),_(!1)},oe(),()=>{m.close()}},[]);const oe=()=>A(this,null,function*(){try{const v=yield(yield fetch(`${R}/api/workspace/files`)).json();d(v.files||[])}catch(m){console.error("Failed to load workspace files:",m),P({type:"error",title:"Failed to load files",message:"Could not load workspace files from Cloudflare storage"})}}),ne=m=>{r(m)},le=(m,v)=>{T(E=>$(D({},E),{[m]:v})),u(!1),P({type:"success",title:"API Key Saved",message:`API key for ${m} has been saved successfully`})},ce=()=>{window.open("https://vscode.dev","_blank")},P=m=>{const v=Date.now().toString();i(E=>[...E,$(D({},m),{id:v})])},ie=m=>{i(v=>v.filter(E=>E.id!==m))},J=m=>{var M;const v=(M=m.split(".").pop())==null?void 0:M.toLowerCase();return{js:"javascript",jsx:"javascript",ts:"typescript",tsx:"typescript",py:"python",java:"java",cpp:"cpp",c:"c",cs:"csharp",go:"go",rs:"rust",php:"php",rb:"ruby",html:"html",css:"css",scss:"scss",json:"json",xml:"xml",yaml:"yaml",yml:"yaml",md:"markdown",sql:"sql",sh:"shell",bash:"shell",dockerfile:"dockerfile"}[v||""]||"plaintext"};return e.jsxs("div",{className:"flex h-screen bg-cursor-bg text-cursor-text",children:[e.jsx(Je,{files:a,selectedFile:s,onFileSelect:ne,onShowChat:()=>t(!c),onShowProviderForm:()=>u(!0),onShowTools:()=>p(!f),onOpenCodeServer:ce,showChat:c,showTools:f}),e.jsxs("div",{className:"flex-1 flex",children:[e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsx(qe,{selectedFile:s,onFileChange:(m,v)=>{console.log("File changed:",m)},onSave:(m,v)=>A(this,null,function*(){try{(yield fetch(`${R}/api/workspace/file/${m}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:v})})).ok&&P({type:"success",title:"File Saved",message:`${m} saved successfully`})}catch(E){P({type:"error",title:"Save Failed",message:`Failed to save ${m}`})}}),onRun:(m,v)=>A(this,null,function*(){try{const M=yield(yield fetch(`${R}/api/execute`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:v,language:J(m)})})).json();console.log("Code executed:",M)}catch(E){console.error("Failed to run code:",E)}}),backendUrl:R}),c&&e.jsx(He,{socket:y,apiKeys:x,selectedProvider:C,onProviderChange:h,backendUrl:R})]}),f&&e.jsx(Ye,{onToolExecute:(m,v)=>{console.log("Executing tool:",m,v)},onResult:m=>{console.log("Tool result:",m)},backendUrl:R})]}),e.jsx(Qe,{isConnected:L,selectedFile:s,lineCount:S,currentLine:n,currentColumn:o,language:s?J(s):"",gitBranch:O}),e.jsx(Ze,{notifications:k,onClose:ie}),b&&e.jsx(Ve,{onSave:le,onClose:()=>u(!1),existingKeys:x})]})}G.createRoot(document.getElementById("root")).render(e.jsx(ge.StrictMode,{children:e.jsx(ss,{})}))});export default ts();
|