sparkecoder 0.1.46 → 0.1.48

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.
Files changed (87) hide show
  1. package/dist/agent/index.js.map +1 -1
  2. package/dist/cli.js.map +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/server/index.js.map +1 -1
  5. package/package.json +1 -1
  6. package/web/.next/BUILD_ID +1 -1
  7. package/web/.next/standalone/web/.next/BUILD_ID +1 -1
  8. package/web/.next/standalone/web/.next/build-manifest.json +2 -2
  9. package/web/.next/standalone/web/.next/prerender-manifest.json +3 -3
  10. package/web/.next/standalone/web/.next/server/app/(main)/session/[id]/page_client-reference-manifest.js +1 -1
  11. package/web/.next/standalone/web/.next/server/app/_global-error.html +2 -2
  12. package/web/.next/standalone/web/.next/server/app/_global-error.rsc +1 -1
  13. package/web/.next/standalone/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  14. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  15. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  16. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  17. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  18. package/web/.next/standalone/web/.next/server/app/_not-found.html +1 -1
  19. package/web/.next/standalone/web/.next/server/app/_not-found.rsc +1 -1
  20. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  21. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  22. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  23. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  24. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  25. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  26. package/web/.next/standalone/web/.next/server/app/docs/installation.html +2 -2
  27. package/web/.next/standalone/web/.next/server/app/docs/installation.rsc +1 -1
  28. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_full.segment.rsc +1 -1
  29. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_head.segment.rsc +1 -1
  30. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_index.segment.rsc +1 -1
  31. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_tree.segment.rsc +1 -1
  32. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs/installation/__PAGE__.segment.rsc +1 -1
  33. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs/installation.segment.rsc +1 -1
  34. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs.segment.rsc +1 -1
  35. package/web/.next/standalone/web/.next/server/app/docs/skills.html +2 -2
  36. package/web/.next/standalone/web/.next/server/app/docs/skills.rsc +1 -1
  37. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_full.segment.rsc +1 -1
  38. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_head.segment.rsc +1 -1
  39. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_index.segment.rsc +1 -1
  40. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_tree.segment.rsc +1 -1
  41. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs/skills/__PAGE__.segment.rsc +1 -1
  42. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs/skills.segment.rsc +1 -1
  43. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs.segment.rsc +1 -1
  44. package/web/.next/standalone/web/.next/server/app/docs/tools.html +2 -2
  45. package/web/.next/standalone/web/.next/server/app/docs/tools.rsc +1 -1
  46. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_full.segment.rsc +1 -1
  47. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_head.segment.rsc +1 -1
  48. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_index.segment.rsc +1 -1
  49. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_tree.segment.rsc +1 -1
  50. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs/tools/__PAGE__.segment.rsc +1 -1
  51. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs/tools.segment.rsc +1 -1
  52. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs.segment.rsc +1 -1
  53. package/web/.next/standalone/web/.next/server/app/docs.html +2 -2
  54. package/web/.next/standalone/web/.next/server/app/docs.rsc +1 -1
  55. package/web/.next/standalone/web/.next/server/app/docs.segments/_full.segment.rsc +1 -1
  56. package/web/.next/standalone/web/.next/server/app/docs.segments/_head.segment.rsc +1 -1
  57. package/web/.next/standalone/web/.next/server/app/docs.segments/_index.segment.rsc +1 -1
  58. package/web/.next/standalone/web/.next/server/app/docs.segments/_tree.segment.rsc +1 -1
  59. package/web/.next/standalone/web/.next/server/app/docs.segments/docs/__PAGE__.segment.rsc +1 -1
  60. package/web/.next/standalone/web/.next/server/app/docs.segments/docs.segment.rsc +1 -1
  61. package/web/.next/standalone/web/.next/server/app/embed/[id]/page_client-reference-manifest.js +1 -1
  62. package/web/.next/standalone/web/.next/server/app/index.html +1 -1
  63. package/web/.next/standalone/web/.next/server/app/index.rsc +1 -1
  64. package/web/.next/standalone/web/.next/server/app/index.segments/!KG1haW4p/__PAGE__.segment.rsc +1 -1
  65. package/web/.next/standalone/web/.next/server/app/index.segments/!KG1haW4p.segment.rsc +1 -1
  66. package/web/.next/standalone/web/.next/server/app/index.segments/_full.segment.rsc +1 -1
  67. package/web/.next/standalone/web/.next/server/app/index.segments/_head.segment.rsc +1 -1
  68. package/web/.next/standalone/web/.next/server/app/index.segments/_index.segment.rsc +1 -1
  69. package/web/.next/standalone/web/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  70. package/web/.next/standalone/web/.next/server/chunks/ssr/[root-of-the-server]__a87e1c27._.js +1 -1
  71. package/web/.next/standalone/web/.next/server/pages/404.html +1 -1
  72. package/web/.next/standalone/web/.next/server/pages/500.html +2 -2
  73. package/web/.next/standalone/web/.next/server/server-reference-manifest.js +1 -1
  74. package/web/.next/standalone/web/.next/server/server-reference-manifest.json +1 -1
  75. package/web/.next/standalone/web/.next/static/{static/chunks/7e48d04fbd6dd7a6.js → chunks/826a34109ed05598.js} +1 -1
  76. package/web/.next/{static/chunks/7e48d04fbd6dd7a6.js → standalone/web/.next/static/static/chunks/826a34109ed05598.js} +1 -1
  77. package/web/.next/standalone/web/src/components/chat-interface.tsx +21 -8
  78. package/web/.next/{standalone/web/.next/static/chunks/7e48d04fbd6dd7a6.js → static/chunks/826a34109ed05598.js} +1 -1
  79. /package/web/.next/standalone/web/.next/static/{_0-MmiObGsO5iLpf0Qgmw → 9l0nvP_hXh_bNsaosB1Ho}/_buildManifest.js +0 -0
  80. /package/web/.next/standalone/web/.next/static/{_0-MmiObGsO5iLpf0Qgmw → 9l0nvP_hXh_bNsaosB1Ho}/_clientMiddlewareManifest.json +0 -0
  81. /package/web/.next/standalone/web/.next/static/{_0-MmiObGsO5iLpf0Qgmw → 9l0nvP_hXh_bNsaosB1Ho}/_ssgManifest.js +0 -0
  82. /package/web/.next/standalone/web/.next/static/static/{_0-MmiObGsO5iLpf0Qgmw → 9l0nvP_hXh_bNsaosB1Ho}/_buildManifest.js +0 -0
  83. /package/web/.next/standalone/web/.next/static/static/{_0-MmiObGsO5iLpf0Qgmw → 9l0nvP_hXh_bNsaosB1Ho}/_clientMiddlewareManifest.json +0 -0
  84. /package/web/.next/standalone/web/.next/static/static/{_0-MmiObGsO5iLpf0Qgmw → 9l0nvP_hXh_bNsaosB1Ho}/_ssgManifest.js +0 -0
  85. /package/web/.next/static/{_0-MmiObGsO5iLpf0Qgmw → 9l0nvP_hXh_bNsaosB1Ho}/_buildManifest.js +0 -0
  86. /package/web/.next/static/{_0-MmiObGsO5iLpf0Qgmw → 9l0nvP_hXh_bNsaosB1Ho}/_clientMiddlewareManifest.json +0 -0
  87. /package/web/.next/static/{_0-MmiObGsO5iLpf0Qgmw → 9l0nvP_hXh_bNsaosB1Ho}/_ssgManifest.js +0 -0
@@ -1794,15 +1794,28 @@ export function ChatInterface({ session, isEmbed = false }: ChatInterfaceProps)
1794
1794
  setIsWatching(false);
1795
1795
  };
1796
1796
 
1797
+ // Keep a ref to executeSubmit so the auto-send effect always calls the
1798
+ // latest version (avoids stale closure capturing old handleSSEEvent, etc.)
1799
+ const executeSubmitRef = useRef(executeSubmit);
1800
+ executeSubmitRef.current = executeSubmit;
1801
+
1797
1802
  // Auto-send next queued message when assistant finishes
1798
1803
  const prevIsRunningRef = useRef(isRunning);
1799
1804
  const skipAutoSendRef = useRef(false); // Set by sendNow to prevent double-send
1800
1805
  useEffect(() => {
1801
1806
  const wasRunning = prevIsRunningRef.current;
1802
1807
  prevIsRunningRef.current = isRunning;
1803
-
1804
- // Transition: running -> not running, and there's a queue
1805
- if (wasRunning && !isRunning && messageQueue.length > 0) {
1808
+
1809
+ // Auto-send whenever we're idle and there are queued messages.
1810
+ // This covers both:
1811
+ // 1. Agent just finished (wasRunning=true → isRunning=false) with a queue
1812
+ // 2. Queue got a new item while already idle (e.g., agent finished BEFORE
1813
+ // the user queued a message, so the running→stopped transition was missed)
1814
+ // Safe because executeSubmit sets isRunning=true, preventing re-entry
1815
+ // until the next agent response finishes.
1816
+ const shouldAutoSend = !isRunning && messageQueue.length > 0;
1817
+
1818
+ if (shouldAutoSend) {
1806
1819
  // If sendNow triggered the stop, skip auto-send (it handles its own send)
1807
1820
  if (skipAutoSendRef.current) {
1808
1821
  skipAutoSendRef.current = false;
@@ -1813,8 +1826,8 @@ export function ChatInterface({ session, isEmbed = false }: ChatInterfaceProps)
1813
1826
  setMessageQueue((prev) => {
1814
1827
  if (prev.length === 0) return prev;
1815
1828
  const [next, ...rest] = prev;
1816
- // Fire off the submit
1817
- executeSubmit(next.text, next.attachments, next.selectedElements);
1829
+ // Use ref to always call the latest executeSubmit (not a stale closure)
1830
+ executeSubmitRef.current(next.text, next.attachments, next.selectedElements);
1818
1831
  return rest;
1819
1832
  });
1820
1833
  }, 300);
@@ -1861,12 +1874,12 @@ export function ChatInterface({ session, isEmbed = false }: ChatInterfaceProps)
1861
1874
  if (isRunning) {
1862
1875
  skipAutoSendRef.current = true; // Prevent auto-send from firing
1863
1876
  await handleStop();
1864
- // Wait for stop to settle, then send
1877
+ // Wait for stop to settle, then send using ref for fresh closure
1865
1878
  setTimeout(() => {
1866
- executeSubmit(item.text, item.attachments, item.selectedElements);
1879
+ executeSubmitRef.current(item.text, item.attachments, item.selectedElements);
1867
1880
  }, 500);
1868
1881
  } else {
1869
- executeSubmit(item.text, item.attachments, item.selectedElements);
1882
+ executeSubmitRef.current(item.text, item.attachments, item.selectedElements);
1870
1883
  }
1871
1884
  };
1872
1885
 
@@ -10,4 +10,4 @@ ${eA.updateCommand}`;e$(e),eE(!0)}catch(e){console.error("Failed to start update
10
10
  ${n.trim()}
11
11
  </sparkecoder-user-selected-elements>`;a=`${e}
12
12
 
13
- ${a}`}let o=a,l=r?.map(e=>({type:e.type,data:e.data,mediaType:e.mediaType,filename:e.filename})),c={id:`user-${Date.now()}`,type:"user-message",content:t||(i?"Selected elements attached":""),attachments:l};s(e=>[...e,c]),h(!0),L(!1),eh.current=!0,F(""),W(""),H(!1),X([]),es.current="",ei.current="",ea.current=[],ec.current=(0,g1.runAgent)(e.id,o||"Please analyze the attached files.",eF,{onStreamId:e=>O(e),attachments:r})},e$=async(e,t)=>{let r=!!(c&&c.trim());if(e.trim()||t&&0!==t.length||r){if(d){let r;return void(r={id:`q-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,text:e,attachments:t,selectedElements:c},m(e=>[...e,r]),a(""),u(null))}a(""),u(null),await eB(e,t,c)}},eV=async e=>{let t=!!e.text?.trim(),r=!!e.files?.length,n=!!(c&&c.trim());if(!t&&!r&&!n)return;let s=[];if(r&&e.files.length>0){for(let t of e.files)if(t.url)try{let e=await fetch(t.url),r=await e.blob(),n=await new Promise(e=>{let t=new FileReader;t.onloadend=()=>e(t.result),t.readAsDataURL(r)}),i=t.mediaType||r.type||"application/octet-stream",a=i.startsWith("image/");s.push({type:a?"image":"file",data:n,mediaType:i,filename:t.filename})}catch(e){console.error("Failed to process attachment:",e)}}e$(e.text||"",s.length>0?s:void 0)},eU=async()=>{try{await (0,g1.abortStream)(e.id)}catch(e){console.error("Failed to abort stream:",e)}if(ec.current&&(ec.current(),ec.current=null),ei.current.trim()){let e={id:`reasoning-${Date.now()}`,type:"reasoning",content:ei.current};s(t=>[...t,e])}if(es.current.trim()){let e={id:`text-${Date.now()}`,type:"assistant-text",content:es.current+" [stopped]"};s(t=>[...t,e])}F(""),W(""),H(!1),X([]),O(null),es.current="",ei.current="",ea.current=[],ed.current=!1,h(!1),L(!1)},eG=(0,b.useRef)(d),eW=(0,b.useRef)(!1);(0,b.useEffect)(()=>{let e=eG.current;if(eG.current=d,e&&!d&&p.length>0){if(eW.current){eW.current=!1;return}let e=setTimeout(()=>{m(e=>{if(0===e.length)return e;let[t,...r]=e;return eB(t.text,t.attachments,t.selectedElements),r})},300);return()=>clearTimeout(e)}},[d,p.length]);let eq=e=>{m(t=>t.map(t=>t.id===e?{...t,text:x}:t)),g(null),y("")},eH=async e=>{let t=p.find(t=>t.id===e);t&&(m(t=>t.filter(t=>t.id!==e)),d?(eW.current=!0,await eU(),setTimeout(()=>{eB(t.text,t.attachments,t.selectedElements)},500)):eB(t.text,t.attachments,t.selectedElements))},eK=async t=>{J(e=>e.filter(e=>e.id!==t.id));try{await (0,g1.approveExecution)(e.id,t.toolCallId)}catch(e){console.error("Failed to approve:",e)}},eX=async t=>{J(e=>e.filter(e=>e.id!==t.id));try{await (0,g1.rejectExecution)(e.id,t.toolCallId,"User rejected")}catch(e){console.error("Failed to reject:",e)}},eY=async t=>{J(e=>e.filter(e=>e.id!==t.id));try{await (0,g1.approveExecution)(e.id,t.toolCallId);let r=await (0,g1.updateToolApproval)(e.id,t.toolName,!1,ek);ej(r.config||{})}catch(e){console.error("Failed to approve and disable:",e)}},eJ=async(t,r)=>{try{let n=await (0,g1.updateToolApproval)(e.id,t,!r,ek);ej(n.config||{})}catch(e){console.error("Failed to update tool approval:",e)}},eZ=e=>({ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",php:"php",swift:"swift",kt:"kotlin",scala:"scala",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",ps1:"powershell",sql:"sql",html:"html",htm:"html",css:"css",scss:"scss",sass:"sass",less:"less",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",md:"markdown",markdown:"markdown",txt:"plaintext",toml:"toml",ini:"ini",cfg:"ini",conf:"ini",dockerfile:"dockerfile",makefile:"makefile"})[e.split(".").pop()?.toLowerCase()||""]||"plaintext";return(0,v.jsxs)("div",{className:(0,k.cn)("flex flex-col h-full bg-background min-w-0 overflow-x-hidden",t&&"embed-mode text-[13px]"),children:[t&&(0,v.jsxs)("div",{className:"border-b border-border/50 px-2 py-1.5 flex items-center justify-between bg-card/50",children:[(0,v.jsx)(A.Button,{size:"icon",variant:"ghost",onClick:r,className:"size-6",children:(0,v.jsx)(xl.PanelLeft,{className:"size-3.5"})}),(0,v.jsx)("span",{className:"text-[11px] text-muted-foreground truncate max-w-[120px] font-medium",children:eg||"Session"}),(0,v.jsx)(A.Button,{size:"icon",variant:"ghost",onClick:()=>eS(!0),className:"size-6",children:(0,v.jsx)(xi.Settings,{className:"size-3.5"})})]}),!t&&(0,v.jsxs)("div",{className:"border-b border-border/50 px-3 sm:px-4 py-2 flex items-center justify-between bg-card/50 backdrop-blur-sm",children:[(0,v.jsxs)("div",{className:"min-w-0 flex items-center gap-2 sm:gap-3",children:[(0,v.jsx)(yP,{}),(0,v.jsx)("div",{className:"flex items-center gap-1.5",children:ey?(0,v.jsxs)("form",{onSubmit:e=>{e.preventDefault(),eI()},className:"flex items-center gap-1",children:[(0,v.jsx)(gg.Input,{ref:eC,value:eg,onChange:e=>ex(e.target.value),onBlur:eI,className:"h-7 text-sm font-semibold w-40 px-2",placeholder:"Session name"}),(0,v.jsx)(A.Button,{type:"submit",size:"icon",variant:"ghost",className:"size-6 text-muted-foreground hover:text-foreground",children:(0,v.jsx)(xs.Check,{className:"size-3.5"})})]}):(0,v.jsx)(_.TooltipProvider,{children:(0,v.jsxs)(_.Tooltip,{children:[(0,v.jsx)(_.TooltipTrigger,{asChild:!0,children:(0,v.jsxs)("button",{onClick:()=>ev(!0),className:"flex items-center gap-1.5 group hover:bg-muted/50 rounded px-1.5 py-0.5 -mx-1.5 transition-colors",children:[(0,v.jsx)("h2",{className:"font-semibold text-foreground truncate max-w-[200px]",children:eg||"Untitled Session"}),(0,v.jsx)(xn,{className:"size-3 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity"})]})}),(0,v.jsx)(_.TooltipContent,{children:"Click to rename"})]})})}),(0,v.jsx)(_.TooltipProvider,{children:(0,v.jsxs)(_.Tooltip,{children:[(0,v.jsx)(_.TooltipTrigger,{asChild:!0,children:(0,v.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-md bg-muted/30 text-xs text-muted-foreground max-w-[200px]",children:[(0,v.jsx)(xo,{className:"size-3.5 shrink-0"}),(0,v.jsx)("span",{className:"truncate font-mono",children:e.workingDirectory.split("/").pop()||e.workingDirectory})]})}),(0,v.jsx)(_.TooltipContent,{side:"bottom",className:"max-w-md",children:(0,v.jsx)("p",{className:"font-mono text-xs",children:e.workingDirectory})})]})})]}),(0,v.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[I&&(0,v.jsx)(_.TooltipProvider,{children:(0,v.jsxs)(_.Tooltip,{children:[(0,v.jsx)(_.TooltipTrigger,{asChild:!0,children:(0,v.jsxs)(C,{variant:"outline",className:"gap-1.5 text-xs border-emerald-500/30 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 cursor-help",children:[(0,v.jsx)("span",{className:"size-1.5 rounded-full bg-current animate-pulse"}),"Watching"]})}),(0,v.jsx)(_.TooltipContent,{children:"Watching stream from another client"})]})}),(0,v.jsx)(_.TooltipProvider,{children:(0,v.jsxs)(_.Tooltip,{children:[(0,v.jsx)(_.TooltipTrigger,{asChild:!0,children:(0,v.jsx)(C,{variant:d?"default":"secondary",className:`cursor-help ${d?"bg-primary/90":""}`,children:d?I?"streaming":"running":e.status})}),(0,v.jsx)(_.TooltipContent,{children:d?I?"Receiving streamed response":"Agent is processing":`Session is ${e.status}`})]})}),(0,v.jsx)(_.TooltipProvider,{children:(0,v.jsxs)(_.Tooltip,{children:[(0,v.jsx)(_.TooltipTrigger,{asChild:!0,children:(0,v.jsx)(A.Button,{size:"icon",variant:"ghost",className:"size-7 hover:bg-accent transition-colors",onClick:()=>eS(!0),children:(0,v.jsx)(xi.Settings,{className:"size-4"})})}),(0,v.jsx)(_.TooltipContent,{children:"Session Settings"})]})})]})]}),(0,v.jsx)(mw.Dialog,{open:eN,onOpenChange:eS,children:(0,v.jsxs)(mw.DialogContent,{className:"sm:max-w-md",children:[(0,v.jsx)(mw.DialogHeader,{children:(0,v.jsxs)(mw.DialogTitle,{className:"flex items-center gap-2",children:[(0,v.jsx)("div",{className:"size-8 rounded-lg bg-muted flex items-center justify-center",children:(0,v.jsx)(xi.Settings,{className:"size-4"})}),"Session Settings"]})}),(0,v.jsxs)("div",{className:"space-y-4 pt-2",children:[(0,v.jsxs)("div",{className:"space-y-2",children:[(0,v.jsx)(xb.Label,{className:"text-sm font-medium",children:"Model"}),(0,v.jsxs)(op.Select,{value:em,onValueChange:eM,disabled:d,children:[(0,v.jsx)(op.SelectTrigger,{className:"w-full",children:(0,v.jsx)(op.SelectValue,{placeholder:"Select model"})}),(0,v.jsx)(op.SelectContent,{children:eb?.availableModels.map(e=>(0,v.jsx)(op.SelectItem,{value:e.id,children:(0,v.jsxs)("div",{className:"flex items-center gap-2",children:[(0,v.jsx)("span",{children:e.name}),(0,v.jsx)("span",{className:"text-xs text-muted-foreground",children:e.provider})]})},e.id))})]}),d&&(0,v.jsx)("p",{className:"text-xs text-muted-foreground",children:"Cannot change model while agent is running"})]}),(0,v.jsxs)("div",{className:"space-y-2",children:[(0,v.jsx)(xb.Label,{className:"flex items-center gap-2 text-sm font-medium",children:"Tool Approvals"}),(0,v.jsx)("p",{className:"text-xs text-muted-foreground -mt-0.5",children:"Toggle on to require approval before tool executes"}),(0,v.jsx)("div",{className:"space-y-1 rounded-lg border p-2.5 bg-muted/30",children:eb?.availableTools.map(e=>{var t;let r=(t=e.id,ek.toolApprovals?.[t]!==void 0?ek.toolApprovals[t]:"bash"===t);return(0,v.jsxs)("div",{className:"flex items-center justify-between py-1.5 hover:bg-muted/50 rounded px-2 -mx-1 transition-colors",children:[(0,v.jsxs)("div",{className:"space-y-0",children:[(0,v.jsxs)("div",{className:"flex items-center gap-2",children:[(0,v.jsx)("span",{className:"text-sm font-medium",children:e.name}),e.dangerous&&(0,v.jsx)("span",{className:"text-[10px] bg-amber-500/20 text-amber-600 dark:text-amber-400 px-1.5 py-0.5 rounded font-medium",children:"risky"})]}),(0,v.jsx)("p",{className:"text-[11px] text-muted-foreground",children:e.description})]}),(0,v.jsx)(xv.Switch,{checked:r,onCheckedChange:()=>eJ(e.id,r)})]},e.id)})})]}),(0,v.jsx)("p",{className:"text-xs text-muted-foreground",children:"These settings only apply to this session. Changes take effect for future tool calls."})]})]})}),!t&&eA?.updateAvailable&&!eT&&(0,v.jsxs)("div",{className:"px-4 py-2 border-b border-amber-500/30 bg-amber-500/10 flex items-center justify-between gap-3",children:[(0,v.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,v.jsx)(xu,{className:"size-4 text-amber-600 dark:text-amber-400 shrink-0"}),(0,v.jsxs)("span",{className:"text-sm text-amber-700 dark:text-amber-300",children:["Update available: ",(0,v.jsxs)("strong",{children:["v",eA.latestVersion]}),(0,v.jsxs)("span",{className:"text-amber-600/70 dark:text-amber-400/70 ml-1",children:["(current: v",eA.currentVersion,")"]})]})]}),(0,v.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[(0,v.jsx)(A.Button,{size:"sm",variant:"outline",className:"h-7 text-xs border-amber-500/50 bg-amber-500/20 hover:bg-amber-500/30 text-amber-700 dark:text-amber-300",onClick:eL,disabled:eP,children:eP?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(xe,{className:"size-3 mr-1.5 animate-spin"}),"Creating..."]}):(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(xu,{className:"size-3 mr-1.5"}),"Update Now"]})}),(0,v.jsx)(_.TooltipProvider,{children:(0,v.jsxs)(_.Tooltip,{children:[(0,v.jsx)(_.TooltipTrigger,{asChild:!0,children:(0,v.jsx)(A.Button,{size:"icon",variant:"ghost",className:"size-6 text-amber-600 dark:text-amber-400 hover:bg-amber-500/20",onClick:()=>{eE(!0),eA?.latestVersion&&localStorage.setItem("sparkecoder-dismissed-version",eA.latestVersion)},children:(0,v.jsx)(xd.X,{className:"size-3.5"})})}),(0,v.jsx)(_.TooltipContent,{children:"Dismiss (won't show again for this version)"})]})})]})]}),!t&&Z&&Z.todos&&Z.todos.length>0&&(0,v.jsx)("div",{className:"px-4 py-2 border-b border-border/50 bg-muted/20",children:(0,v.jsx)(g8,{todosData:Z})}),Y.length>0&&(0,v.jsx)("div",{className:(0,k.cn)("p-4 border-b border-border space-y-3",t&&"p-2 space-y-2"),children:Y.map(e=>{let t=e.input;return(0,v.jsxs)(oq,{approval:{id:e.id,approved:!1},state:"approval-requested",children:[(0,v.jsx)(oH,{children:(0,v.jsxs)("div",{className:"flex items-start gap-3",children:[(0,v.jsx)("div",{className:"size-8 rounded-lg bg-amber-500/20 flex items-center justify-center shrink-0",children:(0,v.jsx)(xt,{className:"size-4 text-amber-500"})}),(0,v.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,v.jsx)("p",{className:"font-medium text-sm",children:"Approval Required"}),(0,v.jsx)("p",{className:"text-sm text-muted-foreground mt-0.5",children:(0,v.jsx)("code",{className:"bg-muted px-1.5 py-0.5 rounded font-mono text-foreground",children:e.toolName})}),(0,v.jsx)("div",{className:"mt-3 rounded-lg border bg-muted/30 overflow-hidden",children:Object.entries(t).map(([e,t])=>(0,v.jsxs)("div",{className:"flex border-b border-border/50 last:border-b-0",children:[(0,v.jsx)("div",{className:"px-3 py-2 bg-muted/50 text-xs font-medium text-muted-foreground w-24 shrink-0",children:e}),(0,v.jsx)("div",{className:"px-3 py-2 text-xs font-mono flex-1 min-w-0 overflow-auto max-h-24",children:"string"==typeof t?(0,v.jsx)("span",{className:"whitespace-pre-wrap break-words",children:t}):(0,v.jsx)("span",{className:"text-muted-foreground",children:JSON.stringify(t)})})]},e))})]})]})}),(0,v.jsxs)(oK,{children:[(0,v.jsx)(oX,{variant:"outline",onClick:()=>eX(e),children:"Reject"}),(0,v.jsx)(oX,{variant:"ghost",onClick:()=>eY(e),className:"text-muted-foreground hover:text-foreground",children:"Don't ask again"}),(0,v.jsx)(oX,{variant:"default",onClick:()=>eK(e),children:"Approve"})]})]},e.id)})}),(0,v.jsxs)($,{className:(0,k.cn)("flex-1 p-4",t&&"p-2"),children:[(0,v.jsxs)(V,{className:(0,k.cn)("max-w-3xl mx-auto w-full",t&&"max-w-none"),children:[eo&&(0,v.jsx)("div",{className:"flex justify-center py-12",children:(0,v.jsx)(oJ,{size:24})}),!eo&&0===n.length&&!z&&(0,v.jsx)(U,{icon:(0,v.jsxs)("div",{className:"relative overflow-hidden rounded-2xl size-16 shadow-lg ring-1 ring-white/10",children:[(0,v.jsx)(w.default,{src:"/sparke-coder.png",alt:"SparkECoder",width:64,height:64,className:"absolute inset-0 size-full object-cover",priority:!0}),d&&(0,v.jsx)("video",{src:"/sparkecode.mp4",autoPlay:!0,muted:!0,loop:!0,playsInline:!0,className:"absolute inset-0 size-full object-cover"})]}),title:"Start a conversation",description:"Ask SparkECoder to help you with coding tasks"}),n.filter(e=>!("tool-call"===e.type&&e.toolCall&&(Y.some(t=>t.toolCallId===e.toolCall?.toolCallId)||K.some(t=>t.toolCallId===e.toolCall?.toolCallId||t.toolName===e.toolCall?.toolName&&("streaming"===t.status||"running"===t.status))))&&!0).map(e=>{if("user-message"===e.type){let t,r,n=void 0!==e.messageSequence&&ee.some(t=>t.messageSequence===e.messageSequence);return(0,v.jsxs)(a$,{from:"user",children:[(0,v.jsxs)(aV,{children:[e.attachments&&e.attachments.length>0&&(0,v.jsx)("div",{className:"flex flex-wrap gap-2 mb-2",children:e.attachments.map((e,t)=>(0,v.jsx)("div",{className:"relative",children:"image"===e.type?(0,v.jsx)("div",{className:"relative rounded-lg overflow-hidden border border-border/50 max-w-[200px]",children:(0,v.jsx)("img",{src:e.data.startsWith("data:")?e.data:`data:${e.mediaType||"image/png"};base64,${e.data}`,alt:e.filename||"Image attachment",className:"max-w-full h-auto max-h-[150px] object-contain"})}):(0,v.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-muted/50 border border-border/50",children:[(0,v.jsx)(xc,{className:"h-4 w-4 text-muted-foreground"}),(0,v.jsx)("span",{className:"text-sm text-muted-foreground truncate max-w-[150px]",children:e.filename||"File"})]})},t))}),e.content&&(t=e.content.replace(yE,"").trim(),r=function(e){let t=e.match(/<devtools-context>([\s\S]*?)<\/devtools-context>/);if(!t)return null;let r=t[1],n=r.match(/<page\s+url="([^"]*)"\s+path="([^"]*)"\s+name="([^"]*)"/),s=r.match(/<viewport\s+width="([^"]*)"\s+height="([^"]*)"(?:\s+dpr="([^"]*)")?/);return n?{url:n[1],path:n[2],pageName:n[3],viewportWidth:s?.[1],viewportHeight:s?.[2],dpr:s?.[3]}:null}(e.content),(0,v.jsxs)(v.Fragment,{children:[t&&(0,v.jsx)("p",{className:"whitespace-pre-wrap",children:t}),r&&(0,v.jsxs)("div",{className:"flex items-center gap-1.5 mt-1.5 text-[11px] text-muted-foreground/60",children:[(0,v.jsx)(xx,{className:"h-3 w-3"}),(0,v.jsx)("span",{children:r.path}),r.viewportWidth&&r.viewportHeight&&(0,v.jsxs)("span",{className:"text-muted-foreground/40",children:[r.viewportWidth,"x",r.viewportHeight]})]})]}))]}),n&&!d&&(0,v.jsx)(aU,{className:"justify-end mt-1",children:(0,v.jsx)(_.TooltipProvider,{children:(0,v.jsxs)(_.Tooltip,{children:[(0,v.jsx)(_.TooltipTrigger,{asChild:!0,children:(0,v.jsxs)(A.Button,{variant:"ghost",size:"sm",onClick:()=>ez(e.messageSequence,e.content),disabled:er,className:"h-6 px-2 text-xs text-muted-foreground hover:text-destructive gap-1",children:[(0,v.jsx)(xa,{className:"h-3 w-3"}),"Revert"]})}),(0,v.jsx)(_.TooltipContent,{children:(0,v.jsx)("p",{children:"Revert to before this message (undo all changes after)"})})]})})})]},e.id)}if("reasoning"===e.type)return(0,v.jsxs)(pH,{isStreaming:!1,defaultOpen:!1,children:[(0,v.jsx)(pX,{}),(0,v.jsx)(pY,{children:e.content||""})]},e.id);if("assistant-text"===e.type)return(0,v.jsx)(a$,{from:"assistant",children:(0,v.jsxs)("div",{className:"flex gap-3",children:[(0,v.jsx)("div",{className:"relative overflow-hidden rounded-lg size-8 shadow-sm ring-1 ring-white/10 shrink-0",children:(0,v.jsx)(w.default,{src:"/sparke-coder.png",alt:"SparkECoder",width:32,height:32,className:"absolute inset-0 size-full object-cover"})}),(0,v.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,v.jsx)(aV,{children:(0,v.jsx)(aq,{children:e.content||""})}),(0,v.jsx)(aU,{children:(0,v.jsx)(aG,{label:"Copy",onClick:()=>navigator.clipboard.writeText(e.content||""),children:(0,v.jsx)(om,{className:"size-3"})})})]})]})},e.id);if("tool-call"===e.type&&e.toolCall){let t=e.toolCall,r=`tool-${t.toolName}`;if("write_file"===t.toolName)return(0,v.jsx)(xj,{input:t.input,output:t.output,status:t.status,streamingArgsText:t.streamingArgsText,liveContent:t.liveContent,liveOldString:t.liveOldString,liveNewString:t.liveNewString},e.id);if("read_file"===t.toolName)return(0,v.jsx)(xC,{input:t.input,output:t.output,status:t.status},e.id);if("bash"===t.toolName)return(0,v.jsx)(xE,{input:t.input,output:t.output,status:t.status,terminalId:t.terminalId,liveOutput:t.liveOutput},e.id);if("explore_agent"===t.toolName)return(0,v.jsx)(xz,{input:t.input,output:t.output,status:t.status,steps:t.exploreSteps},e.id);if("todo"===t.toolName)return(0,v.jsx)(xW,{input:t.input,output:t.output,status:t.status},e.id);if("load_skill"===t.toolName)return(0,v.jsx)(xK,{input:t.input,output:t.output,status:t.status},e.id);if("linter"===t.toolName)return(0,v.jsx)(xQ,{input:t.input,output:t.output,status:t.status},e.id);let n="completed"!==t.status;return(0,v.jsxs)(oE,{defaultOpen:n,children:[(0,v.jsx)(oP,{type:r,state:function(e){switch(e){case"pending":case"streaming":default:return"input-streaming";case"running":return"input-available";case"completed":return"output-available";case"rejected":return"output-denied";case"error":return"output-error"}}(t.status),title:t.toolName}),(0,v.jsxs)(oR,{children:[(0,v.jsx)(oM,{input:t.input}),(e=>{let t=e.output,r=e.input;if("bash"===e.toolName)return(0,v.jsx)(xE,{input:e.input,output:e.output,status:e.status,terminalId:e.terminalId,liveOutput:e.liveOutput,className:"mt-2"});if("explore_agent"===e.toolName)return(0,v.jsx)(xz,{input:e.input,output:e.output,status:e.status,steps:e.exploreSteps,className:"mt-2"});if("todo"===e.toolName)return(0,v.jsx)(xW,{input:e.input,output:e.output,status:e.status,className:"mt-2"});if("load_skill"===e.toolName)return(0,v.jsx)(xK,{input:e.input,output:e.output,status:e.status,className:"mt-2"});if("write_file"===e.toolName&&r){let e=r.path||"file",n=r.mode||"full",s=e.split("/").pop()||"file",i=eZ(e);if("str_replace"===n){let e=r.old_string||"",n=r.new_string||"";return(0,v.jsxs)("div",{className:"mt-2 max-w-full overflow-hidden space-y-2",children:[(0,v.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,v.jsx)(xr,{className:"size-4 text-muted-foreground"}),(0,v.jsx)("span",{className:"font-medium",children:s}),(0,v.jsx)(C,{variant:"secondary",className:"text-xs",children:"str_replace"})]}),(0,v.jsxs)("div",{className:"rounded-md border overflow-hidden",children:[(0,v.jsxs)("div",{className:"bg-red-500/10 border-b p-2",children:[(0,v.jsx)("div",{className:"text-xs text-red-500 mb-1",children:"- Remove:"}),(0,v.jsx)("pre",{className:"text-xs overflow-x-auto whitespace-pre-wrap break-words text-red-400",children:e.length>500?e.slice(0,500)+"...":e})]}),(0,v.jsxs)("div",{className:"bg-green-500/10 p-2",children:[(0,v.jsx)("div",{className:"text-xs text-green-500 mb-1",children:"+ Add:"}),(0,v.jsx)("pre",{className:"text-xs overflow-x-auto whitespace-pre-wrap break-words text-green-400",children:n.length>500?n.slice(0,500)+"...":n})]})]}),t&&(0,v.jsxs)("div",{className:`text-xs flex items-center gap-1 ${t.success?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400"}`,children:[(0,v.jsx)("span",{children:t.success?"✓":"✗"}),(0,v.jsx)("span",{children:t.success?`Replaced (${void 0!==t.lineDelta?(t.lineDelta>=0?"+":"")+t.lineDelta+" lines":"done"})`:t.error||"Failed"})]})]})}let a=r.content||"";return(0,v.jsxs)("div",{className:"mt-2 max-w-full overflow-hidden",children:[(0,v.jsxs)(oL,{children:[(0,v.jsxs)(oD,{children:[(0,v.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,v.jsx)(xr,{className:"size-4 text-muted-foreground shrink-0"}),(0,v.jsx)(oO,{className:"truncate",children:s}),(0,v.jsx)(oz,{className:"truncate text-xs hidden sm:block",children:e})]}),(0,v.jsx)(oF,{children:(0,v.jsx)(oB,{icon:om,label:"Copy",onClick:()=>navigator.clipboard.writeText(a)})})]}),a&&(0,v.jsx)(o$,{className:"p-0 max-h-[300px] overflow-auto",children:(0,v.jsx)(oT,{code:a,language:i,showLineNumbers:!0,children:(0,v.jsx)(oS,{className:"sr-only",children:(0,v.jsx)(oC,{children:(0,v.jsx)(oA,{children:s})})})})})]}),t&&(0,v.jsxs)("div",{className:`mt-2 text-xs flex items-center gap-1 ${t.success?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400"}`,children:[(0,v.jsx)("span",{children:t.success?"✓":"✗"}),(0,v.jsx)("span",{children:t.success?`File ${t.action||"written"} successfully`:t.error||"Failed"})]})]})}if("read_file"===e.toolName&&t){let e=r?.path||"file",n=t.content||JSON.stringify(t,null,2),s=e.split("/").pop()||"file",i=eZ(e);return(0,v.jsx)("div",{className:"mt-2 max-w-full overflow-hidden",children:(0,v.jsxs)(oL,{children:[(0,v.jsxs)(oD,{children:[(0,v.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,v.jsx)(xr,{className:"size-4 text-muted-foreground shrink-0"}),(0,v.jsx)(oO,{className:"truncate",children:s}),(0,v.jsx)(oz,{className:"truncate text-xs hidden sm:block",children:e})]}),(0,v.jsx)(oF,{children:(0,v.jsx)(oB,{icon:om,label:"Copy",onClick:()=>navigator.clipboard.writeText(n)})})]}),(0,v.jsx)(o$,{className:"p-0 max-h-[300px] overflow-auto",children:(0,v.jsx)(oT,{code:n,language:i,showLineNumbers:!0,children:(0,v.jsx)(oS,{className:"sr-only",children:(0,v.jsx)(oC,{children:(0,v.jsx)(oA,{children:s})})})})})]})})}return t?(0,v.jsx)(oI,{output:(0,v.jsxs)("pre",{className:"text-xs overflow-x-auto max-w-full whitespace-pre-wrap break-words",children:[JSON.stringify(t,null,2).slice(0,500),JSON.stringify(t).length>500?"...":""]}),errorText:"error"===e.status?"Tool execution failed":void 0}):null})(t)]})]},e.id)}return null}),d&&!z&&!B&&0===K.length&&(0,v.jsxs)("div",{className:"flex gap-3 items-center",children:[(0,v.jsx)("div",{className:"relative overflow-hidden rounded-lg size-8 shadow-sm ring-1 ring-white/10 shrink-0",children:(0,v.jsx)("video",{src:"/sparkecode.mp4",autoPlay:!0,muted:!0,loop:!0,playsInline:!0,className:"absolute inset-0 size-full object-cover"})}),(0,v.jsx)("span",{className:"text-sm text-muted-foreground",children:"Thinking..."})]}),d&&(q||B)&&(0,v.jsxs)(pH,{isStreaming:q,defaultOpen:!0,children:[(0,v.jsx)(pX,{}),(0,v.jsx)(pY,{children:B})]}),d&&z&&(0,v.jsx)(a$,{from:"assistant",children:(0,v.jsxs)("div",{className:"flex gap-3",children:[(0,v.jsx)("div",{className:"relative overflow-hidden rounded-lg size-8 shadow-sm ring-1 ring-white/10 shrink-0",children:(0,v.jsx)("video",{src:"/sparkecode.mp4",autoPlay:!0,muted:!0,loop:!0,playsInline:!0,className:"absolute inset-0 size-full object-cover"})}),(0,v.jsx)("div",{className:"flex-1 min-w-0",children:(0,v.jsxs)(aV,{children:[(0,v.jsx)(aq,{children:z}),(0,v.jsx)("span",{className:"inline-block w-2 h-4 bg-primary animate-pulse ml-1"})]})})]})}),d&&K.map(e=>"write_file"===e.toolName?(0,v.jsx)(xj,{input:e.input,output:e.output,status:e.status,streamingArgsText:e.streamingArgsText,liveContent:e.liveContent,liveOldString:e.liveOldString,liveNewString:e.liveNewString},e.toolCallId):"read_file"===e.toolName?(0,v.jsx)(xC,{input:e.input,output:e.output,status:e.status},e.toolCallId):"bash"===e.toolName?(0,v.jsx)(xE,{input:e.input,output:e.output,status:e.status,terminalId:e.terminalId,liveOutput:e.liveOutput},e.toolCallId):"explore_agent"===e.toolName?(0,v.jsx)(xz,{input:e.input,output:e.output,status:e.status,steps:e.exploreSteps},e.toolCallId):"todo"===e.toolName?(0,v.jsx)(xW,{input:e.input,output:e.output,status:e.status},e.toolCallId):"load_skill"===e.toolName?(0,v.jsx)(xK,{input:e.input,output:e.output,status:e.status},e.toolCallId):"linter"===e.toolName?(0,v.jsx)(xQ,{input:e.input,output:e.output,status:e.status},e.toolCallId):(0,v.jsxs)(oE,{defaultOpen:!0,children:[(0,v.jsx)(oP,{type:`tool-${e.toolName}`,state:"streaming"===e.status?"input-streaming":"input-available",title:e.toolName}),(0,v.jsxs)(oR,{children:[(0,v.jsx)(oM,{input:e.input}),(0,v.jsxs)("div",{className:"flex items-center gap-2 p-3 text-muted-foreground",children:[(0,v.jsx)(oJ,{size:14}),(0,v.jsx)("span",{className:"text-sm",children:"streaming"===e.status?"Receiving...":"Executing..."})]})]})]},e.toolCallId)),d&&!z&&0===K.length&&(0,v.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,v.jsx)(oJ,{size:16}),(0,v.jsx)("span",{className:"text-sm",children:"Thinking..."})]})]}),(0,v.jsx)(G,{})]}),S&&(0,v.jsxs)("div",{className:"fixed bottom-28 right-4 w-80 max-h-80 overflow-auto border bg-background/95 shadow-lg rounded-md text-xs",children:[(0,v.jsx)("div",{className:"px-3 py-2 border-b font-mono text-muted-foreground",children:"SSE Debug"}),(0,v.jsxs)("div",{className:"px-3 py-2 space-y-1",children:[0===E.length&&0===R.length&&(0,v.jsx)("div",{className:"text-muted-foreground",children:"No events yet"}),E.map((e,t)=>(0,v.jsx)("div",{className:"font-mono",children:e},`evt-${t}`)),R.map((e,t)=>(0,v.jsx)("div",{className:"font-mono text-red-600",children:e},`err-${t}`))]})]}),(0,v.jsx)("div",{className:(0,k.cn)("border-t border-border/50 p-4 pb-6 bg-card/30",t&&"p-2 pb-2"),children:(0,v.jsxs)("div",{className:(0,k.cn)("max-w-3xl mx-auto",t&&"max-w-none"),children:[!t&&!eo&&0===n.length&&!z&&!d&&(0,v.jsx)(gQ,{className:"mb-3",children:['Create a hello.txt file with "Hello, World!"',"List files in the current directory","Show the current git status"].map(e=>(0,v.jsx)(g0,{suggestion:e,onClick:e=>{a(e)}},e))}),p.length>0&&(0,v.jsxs)("div",{className:(0,k.cn)("mb-2 rounded-lg border border-border/60 bg-muted/20 overflow-hidden",t&&"mb-1"),children:[(0,v.jsxs)("button",{type:"button",onClick:()=>N(e=>!e),className:(0,k.cn)("w-full flex items-center justify-between px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/30 transition-colors",t&&"px-2 py-1"),children:[(0,v.jsxs)("div",{className:"flex items-center gap-1.5",children:[j?(0,v.jsx)(xh.default,{className:"size-3"}):(0,v.jsx)(xp.default,{className:"size-3"}),(0,v.jsxs)("span",{className:"font-medium",children:[p.length," Queued"]})]}),(0,v.jsx)("span",{className:"text-[10px]",children:"Stop ^C"})]}),j&&(0,v.jsx)("div",{className:"border-t border-border/40 divide-y divide-border/30",children:p.map((e,r)=>(0,v.jsxs)("div",{className:(0,k.cn)("flex items-start gap-2 px-3 py-2 group",t&&"px-2 py-1.5 gap-1.5"),children:[(0,v.jsx)("span",{className:"text-[10px] text-muted-foreground/60 pt-0.5 w-4 shrink-0 text-center",children:r+1}),(0,v.jsxs)("div",{className:"flex-1 min-w-0",children:[f===e.id?(0,v.jsxs)("div",{className:"flex items-center gap-1",children:[(0,v.jsx)("input",{type:"text",value:x,onChange:e=>y(e.target.value),onKeyDown:t=>{"Enter"===t.key&&eq(e.id),"Escape"===t.key&&g(null)},className:(0,k.cn)("flex-1 bg-background border border-border rounded px-2 py-0.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary/30",t&&"text-[11px]"),autoFocus:!0}),(0,v.jsx)("button",{type:"button",onClick:()=>eq(e.id),className:"p-0.5 text-primary hover:text-primary/80",children:(0,v.jsx)(xs.Check,{className:"size-3"})})]}):(0,v.jsx)("p",{className:(0,k.cn)("text-xs text-foreground truncate",t&&"text-[11px]"),children:e.text||"Selected elements attached"}),e.attachments&&e.attachments.length>0&&(0,v.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[e.attachments.length," file",e.attachments.length>1?"s":""]}),e.selectedElements&&(0,v.jsx)("span",{className:"text-[10px] text-muted-foreground",children:"+ selected elements"})]}),(0,v.jsxs)("div",{className:(0,k.cn)("flex items-center gap-0.5 shrink-0 transition-opacity",t?"opacity-100":"opacity-0 group-hover:opacity-100"),children:[(0,v.jsx)("button",{type:"button",onClick:()=>{g(e.id),y(e.text)},className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted/50",title:"Edit",children:(0,v.jsx)(xn,{className:"size-3"})}),r>0&&(0,v.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.id,void m(e=>{let r=e.findIndex(e=>e.id===t);if(-1===r)return e;let n=r-1;if(n<0||n>=e.length)return e;let s=[...e];return[s[r],s[n]]=[s[n],s[r]],s})},className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted/50",title:"Move up",children:(0,v.jsx)(xf,{className:"size-3"})}),(0,v.jsx)("button",{type:"button",onClick:()=>eH(e.id),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted/50",title:"Send now",children:(0,v.jsx)(xm,{className:"size-3"})}),(0,v.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.id,void m(e=>e.filter(e=>e.id!==t))},className:"p-1 rounded text-muted-foreground hover:text-destructive hover:bg-muted/50",title:"Remove",children:(0,v.jsx)(xg.Trash2,{className:"size-3"})})]})]},e.id))})]}),(0,v.jsx)(y_,{children:(0,v.jsxs)(gM,{onSubmit:eV,className:"shadow-sm",globalDrop:!0,multiple:!0,children:[(0,v.jsxs)(gL,{children:[c&&(0,v.jsxs)("div",{className:(0,k.cn)("mb-2 flex items-center justify-between rounded-md border border-border/60 bg-muted/40 px-2 py-1 text-xs",t&&"mb-1"),children:[(0,v.jsxs)("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[(0,v.jsx)("span",{className:"size-1.5 rounded-full bg-primary/70"}),(0,v.jsx)("span",{children:"Selected elements attached"})]}),(0,v.jsx)("button",{type:"button",onClick:()=>u(null),className:"rounded-sm p-1 text-muted-foreground hover:text-foreground","aria-label":"Remove selected elements",children:(0,v.jsx)(xd.X,{className:"size-3.5"})})]}),(0,v.jsx)(yR,{})]}),(0,v.jsx)(gI,{children:(0,v.jsxs)("div",{className:"relative w-full",children:[(0,v.jsx)(yT,{sessionId:e.id,value:i+(o?(!i||i.endsWith(" ")||i.endsWith("\n")?"":" ")+o:""),onChange:e=>{o&&l(""),a(e)},placeholder:d?"Type to queue a message...":"Ask SparkECoder... (@ to mention files, / for commands)",disabled:!1,autoFocus:!0,className:(0,k.cn)("min-h-[80px] focus:ring-2 focus:ring-primary/20 transition-all field-sizing-content max-h-48",o&&"caret-red-500",t&&"min-h-[40px] text-sm max-h-24")}),o&&(0,v.jsxs)("div",{className:"absolute bottom-2 right-2 flex items-center gap-1.5 text-xs text-red-500 bg-background/80 backdrop-blur-sm px-2 py-1 rounded-full",children:[(0,v.jsx)("span",{className:"size-2 bg-red-500 rounded-full animate-pulse"}),"Listening..."]})]})}),(0,v.jsxs)(gD,{className:t?"py-1":void 0,children:[!t&&(0,v.jsx)("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:(0,v.jsx)("span",{className:"hidden sm:inline",children:"Type @ to mention files, / for commands"})}),(0,v.jsxs)("div",{className:"flex items-center gap-2",children:[(0,v.jsx)(x5,{size:"icon",className:"size-9",onTranscriptionChange:e=>{a(t=>{let r=t&&!t.endsWith(" ")&&!t.endsWith("\n");return t+(r?" ":"")+e})},onInterimTranscription:e=>{l(e)},disabled:d}),(0,v.jsx)(yM,{input:i+o,isRunning:d,onStop:eU,hasExtraContent:!!(c&&c.trim())})]})]})]})})]})})]})}e.s(["ChatInterface",()=>yI],557355)}]);
13
+ ${a}`}let o=a,l=r?.map(e=>({type:e.type,data:e.data,mediaType:e.mediaType,filename:e.filename})),c={id:`user-${Date.now()}`,type:"user-message",content:t||(i?"Selected elements attached":""),attachments:l};s(e=>[...e,c]),h(!0),L(!1),eh.current=!0,F(""),W(""),H(!1),X([]),es.current="",ei.current="",ea.current=[],ec.current=(0,g1.runAgent)(e.id,o||"Please analyze the attached files.",eF,{onStreamId:e=>O(e),attachments:r})},e$=async(e,t)=>{let r=!!(c&&c.trim());if(e.trim()||t&&0!==t.length||r){if(d){let r;return void(r={id:`q-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,text:e,attachments:t,selectedElements:c},m(e=>[...e,r]),a(""),u(null))}a(""),u(null),await eB(e,t,c)}},eV=async e=>{let t=!!e.text?.trim(),r=!!e.files?.length,n=!!(c&&c.trim());if(!t&&!r&&!n)return;let s=[];if(r&&e.files.length>0){for(let t of e.files)if(t.url)try{let e=await fetch(t.url),r=await e.blob(),n=await new Promise(e=>{let t=new FileReader;t.onloadend=()=>e(t.result),t.readAsDataURL(r)}),i=t.mediaType||r.type||"application/octet-stream",a=i.startsWith("image/");s.push({type:a?"image":"file",data:n,mediaType:i,filename:t.filename})}catch(e){console.error("Failed to process attachment:",e)}}e$(e.text||"",s.length>0?s:void 0)},eU=async()=>{try{await (0,g1.abortStream)(e.id)}catch(e){console.error("Failed to abort stream:",e)}if(ec.current&&(ec.current(),ec.current=null),ei.current.trim()){let e={id:`reasoning-${Date.now()}`,type:"reasoning",content:ei.current};s(t=>[...t,e])}if(es.current.trim()){let e={id:`text-${Date.now()}`,type:"assistant-text",content:es.current+" [stopped]"};s(t=>[...t,e])}F(""),W(""),H(!1),X([]),O(null),es.current="",ei.current="",ea.current=[],ed.current=!1,h(!1),L(!1)},eG=(0,b.useRef)(eB);eG.current=eB;let eW=(0,b.useRef)(d),eq=(0,b.useRef)(!1);(0,b.useEffect)(()=>{if(eW.current,eW.current=d,!d&&p.length>0){if(eq.current){eq.current=!1;return}let e=setTimeout(()=>{m(e=>{if(0===e.length)return e;let[t,...r]=e;return eG.current(t.text,t.attachments,t.selectedElements),r})},300);return()=>clearTimeout(e)}},[d,p.length]);let eH=e=>{m(t=>t.map(t=>t.id===e?{...t,text:x}:t)),g(null),y("")},eK=async e=>{let t=p.find(t=>t.id===e);t&&(m(t=>t.filter(t=>t.id!==e)),d?(eq.current=!0,await eU(),setTimeout(()=>{eG.current(t.text,t.attachments,t.selectedElements)},500)):eG.current(t.text,t.attachments,t.selectedElements))},eX=async t=>{J(e=>e.filter(e=>e.id!==t.id));try{await (0,g1.approveExecution)(e.id,t.toolCallId)}catch(e){console.error("Failed to approve:",e)}},eY=async t=>{J(e=>e.filter(e=>e.id!==t.id));try{await (0,g1.rejectExecution)(e.id,t.toolCallId,"User rejected")}catch(e){console.error("Failed to reject:",e)}},eJ=async t=>{J(e=>e.filter(e=>e.id!==t.id));try{await (0,g1.approveExecution)(e.id,t.toolCallId);let r=await (0,g1.updateToolApproval)(e.id,t.toolName,!1,ek);ej(r.config||{})}catch(e){console.error("Failed to approve and disable:",e)}},eZ=async(t,r)=>{try{let n=await (0,g1.updateToolApproval)(e.id,t,!r,ek);ej(n.config||{})}catch(e){console.error("Failed to update tool approval:",e)}},eQ=e=>({ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",php:"php",swift:"swift",kt:"kotlin",scala:"scala",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",ps1:"powershell",sql:"sql",html:"html",htm:"html",css:"css",scss:"scss",sass:"sass",less:"less",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",md:"markdown",markdown:"markdown",txt:"plaintext",toml:"toml",ini:"ini",cfg:"ini",conf:"ini",dockerfile:"dockerfile",makefile:"makefile"})[e.split(".").pop()?.toLowerCase()||""]||"plaintext";return(0,v.jsxs)("div",{className:(0,k.cn)("flex flex-col h-full bg-background min-w-0 overflow-x-hidden",t&&"embed-mode text-[13px]"),children:[t&&(0,v.jsxs)("div",{className:"border-b border-border/50 px-2 py-1.5 flex items-center justify-between bg-card/50",children:[(0,v.jsx)(A.Button,{size:"icon",variant:"ghost",onClick:r,className:"size-6",children:(0,v.jsx)(xl.PanelLeft,{className:"size-3.5"})}),(0,v.jsx)("span",{className:"text-[11px] text-muted-foreground truncate max-w-[120px] font-medium",children:eg||"Session"}),(0,v.jsx)(A.Button,{size:"icon",variant:"ghost",onClick:()=>eS(!0),className:"size-6",children:(0,v.jsx)(xi.Settings,{className:"size-3.5"})})]}),!t&&(0,v.jsxs)("div",{className:"border-b border-border/50 px-3 sm:px-4 py-2 flex items-center justify-between bg-card/50 backdrop-blur-sm",children:[(0,v.jsxs)("div",{className:"min-w-0 flex items-center gap-2 sm:gap-3",children:[(0,v.jsx)(yP,{}),(0,v.jsx)("div",{className:"flex items-center gap-1.5",children:ey?(0,v.jsxs)("form",{onSubmit:e=>{e.preventDefault(),eI()},className:"flex items-center gap-1",children:[(0,v.jsx)(gg.Input,{ref:eC,value:eg,onChange:e=>ex(e.target.value),onBlur:eI,className:"h-7 text-sm font-semibold w-40 px-2",placeholder:"Session name"}),(0,v.jsx)(A.Button,{type:"submit",size:"icon",variant:"ghost",className:"size-6 text-muted-foreground hover:text-foreground",children:(0,v.jsx)(xs.Check,{className:"size-3.5"})})]}):(0,v.jsx)(_.TooltipProvider,{children:(0,v.jsxs)(_.Tooltip,{children:[(0,v.jsx)(_.TooltipTrigger,{asChild:!0,children:(0,v.jsxs)("button",{onClick:()=>ev(!0),className:"flex items-center gap-1.5 group hover:bg-muted/50 rounded px-1.5 py-0.5 -mx-1.5 transition-colors",children:[(0,v.jsx)("h2",{className:"font-semibold text-foreground truncate max-w-[200px]",children:eg||"Untitled Session"}),(0,v.jsx)(xn,{className:"size-3 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity"})]})}),(0,v.jsx)(_.TooltipContent,{children:"Click to rename"})]})})}),(0,v.jsx)(_.TooltipProvider,{children:(0,v.jsxs)(_.Tooltip,{children:[(0,v.jsx)(_.TooltipTrigger,{asChild:!0,children:(0,v.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-md bg-muted/30 text-xs text-muted-foreground max-w-[200px]",children:[(0,v.jsx)(xo,{className:"size-3.5 shrink-0"}),(0,v.jsx)("span",{className:"truncate font-mono",children:e.workingDirectory.split("/").pop()||e.workingDirectory})]})}),(0,v.jsx)(_.TooltipContent,{side:"bottom",className:"max-w-md",children:(0,v.jsx)("p",{className:"font-mono text-xs",children:e.workingDirectory})})]})})]}),(0,v.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[I&&(0,v.jsx)(_.TooltipProvider,{children:(0,v.jsxs)(_.Tooltip,{children:[(0,v.jsx)(_.TooltipTrigger,{asChild:!0,children:(0,v.jsxs)(C,{variant:"outline",className:"gap-1.5 text-xs border-emerald-500/30 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 cursor-help",children:[(0,v.jsx)("span",{className:"size-1.5 rounded-full bg-current animate-pulse"}),"Watching"]})}),(0,v.jsx)(_.TooltipContent,{children:"Watching stream from another client"})]})}),(0,v.jsx)(_.TooltipProvider,{children:(0,v.jsxs)(_.Tooltip,{children:[(0,v.jsx)(_.TooltipTrigger,{asChild:!0,children:(0,v.jsx)(C,{variant:d?"default":"secondary",className:`cursor-help ${d?"bg-primary/90":""}`,children:d?I?"streaming":"running":e.status})}),(0,v.jsx)(_.TooltipContent,{children:d?I?"Receiving streamed response":"Agent is processing":`Session is ${e.status}`})]})}),(0,v.jsx)(_.TooltipProvider,{children:(0,v.jsxs)(_.Tooltip,{children:[(0,v.jsx)(_.TooltipTrigger,{asChild:!0,children:(0,v.jsx)(A.Button,{size:"icon",variant:"ghost",className:"size-7 hover:bg-accent transition-colors",onClick:()=>eS(!0),children:(0,v.jsx)(xi.Settings,{className:"size-4"})})}),(0,v.jsx)(_.TooltipContent,{children:"Session Settings"})]})})]})]}),(0,v.jsx)(mw.Dialog,{open:eN,onOpenChange:eS,children:(0,v.jsxs)(mw.DialogContent,{className:"sm:max-w-md",children:[(0,v.jsx)(mw.DialogHeader,{children:(0,v.jsxs)(mw.DialogTitle,{className:"flex items-center gap-2",children:[(0,v.jsx)("div",{className:"size-8 rounded-lg bg-muted flex items-center justify-center",children:(0,v.jsx)(xi.Settings,{className:"size-4"})}),"Session Settings"]})}),(0,v.jsxs)("div",{className:"space-y-4 pt-2",children:[(0,v.jsxs)("div",{className:"space-y-2",children:[(0,v.jsx)(xb.Label,{className:"text-sm font-medium",children:"Model"}),(0,v.jsxs)(op.Select,{value:em,onValueChange:eM,disabled:d,children:[(0,v.jsx)(op.SelectTrigger,{className:"w-full",children:(0,v.jsx)(op.SelectValue,{placeholder:"Select model"})}),(0,v.jsx)(op.SelectContent,{children:eb?.availableModels.map(e=>(0,v.jsx)(op.SelectItem,{value:e.id,children:(0,v.jsxs)("div",{className:"flex items-center gap-2",children:[(0,v.jsx)("span",{children:e.name}),(0,v.jsx)("span",{className:"text-xs text-muted-foreground",children:e.provider})]})},e.id))})]}),d&&(0,v.jsx)("p",{className:"text-xs text-muted-foreground",children:"Cannot change model while agent is running"})]}),(0,v.jsxs)("div",{className:"space-y-2",children:[(0,v.jsx)(xb.Label,{className:"flex items-center gap-2 text-sm font-medium",children:"Tool Approvals"}),(0,v.jsx)("p",{className:"text-xs text-muted-foreground -mt-0.5",children:"Toggle on to require approval before tool executes"}),(0,v.jsx)("div",{className:"space-y-1 rounded-lg border p-2.5 bg-muted/30",children:eb?.availableTools.map(e=>{var t;let r=(t=e.id,ek.toolApprovals?.[t]!==void 0?ek.toolApprovals[t]:"bash"===t);return(0,v.jsxs)("div",{className:"flex items-center justify-between py-1.5 hover:bg-muted/50 rounded px-2 -mx-1 transition-colors",children:[(0,v.jsxs)("div",{className:"space-y-0",children:[(0,v.jsxs)("div",{className:"flex items-center gap-2",children:[(0,v.jsx)("span",{className:"text-sm font-medium",children:e.name}),e.dangerous&&(0,v.jsx)("span",{className:"text-[10px] bg-amber-500/20 text-amber-600 dark:text-amber-400 px-1.5 py-0.5 rounded font-medium",children:"risky"})]}),(0,v.jsx)("p",{className:"text-[11px] text-muted-foreground",children:e.description})]}),(0,v.jsx)(xv.Switch,{checked:r,onCheckedChange:()=>eZ(e.id,r)})]},e.id)})})]}),(0,v.jsx)("p",{className:"text-xs text-muted-foreground",children:"These settings only apply to this session. Changes take effect for future tool calls."})]})]})}),!t&&eA?.updateAvailable&&!eT&&(0,v.jsxs)("div",{className:"px-4 py-2 border-b border-amber-500/30 bg-amber-500/10 flex items-center justify-between gap-3",children:[(0,v.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,v.jsx)(xu,{className:"size-4 text-amber-600 dark:text-amber-400 shrink-0"}),(0,v.jsxs)("span",{className:"text-sm text-amber-700 dark:text-amber-300",children:["Update available: ",(0,v.jsxs)("strong",{children:["v",eA.latestVersion]}),(0,v.jsxs)("span",{className:"text-amber-600/70 dark:text-amber-400/70 ml-1",children:["(current: v",eA.currentVersion,")"]})]})]}),(0,v.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[(0,v.jsx)(A.Button,{size:"sm",variant:"outline",className:"h-7 text-xs border-amber-500/50 bg-amber-500/20 hover:bg-amber-500/30 text-amber-700 dark:text-amber-300",onClick:eL,disabled:eP,children:eP?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(xe,{className:"size-3 mr-1.5 animate-spin"}),"Creating..."]}):(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(xu,{className:"size-3 mr-1.5"}),"Update Now"]})}),(0,v.jsx)(_.TooltipProvider,{children:(0,v.jsxs)(_.Tooltip,{children:[(0,v.jsx)(_.TooltipTrigger,{asChild:!0,children:(0,v.jsx)(A.Button,{size:"icon",variant:"ghost",className:"size-6 text-amber-600 dark:text-amber-400 hover:bg-amber-500/20",onClick:()=>{eE(!0),eA?.latestVersion&&localStorage.setItem("sparkecoder-dismissed-version",eA.latestVersion)},children:(0,v.jsx)(xd.X,{className:"size-3.5"})})}),(0,v.jsx)(_.TooltipContent,{children:"Dismiss (won't show again for this version)"})]})})]})]}),!t&&Z&&Z.todos&&Z.todos.length>0&&(0,v.jsx)("div",{className:"px-4 py-2 border-b border-border/50 bg-muted/20",children:(0,v.jsx)(g8,{todosData:Z})}),Y.length>0&&(0,v.jsx)("div",{className:(0,k.cn)("p-4 border-b border-border space-y-3",t&&"p-2 space-y-2"),children:Y.map(e=>{let t=e.input;return(0,v.jsxs)(oq,{approval:{id:e.id,approved:!1},state:"approval-requested",children:[(0,v.jsx)(oH,{children:(0,v.jsxs)("div",{className:"flex items-start gap-3",children:[(0,v.jsx)("div",{className:"size-8 rounded-lg bg-amber-500/20 flex items-center justify-center shrink-0",children:(0,v.jsx)(xt,{className:"size-4 text-amber-500"})}),(0,v.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,v.jsx)("p",{className:"font-medium text-sm",children:"Approval Required"}),(0,v.jsx)("p",{className:"text-sm text-muted-foreground mt-0.5",children:(0,v.jsx)("code",{className:"bg-muted px-1.5 py-0.5 rounded font-mono text-foreground",children:e.toolName})}),(0,v.jsx)("div",{className:"mt-3 rounded-lg border bg-muted/30 overflow-hidden",children:Object.entries(t).map(([e,t])=>(0,v.jsxs)("div",{className:"flex border-b border-border/50 last:border-b-0",children:[(0,v.jsx)("div",{className:"px-3 py-2 bg-muted/50 text-xs font-medium text-muted-foreground w-24 shrink-0",children:e}),(0,v.jsx)("div",{className:"px-3 py-2 text-xs font-mono flex-1 min-w-0 overflow-auto max-h-24",children:"string"==typeof t?(0,v.jsx)("span",{className:"whitespace-pre-wrap break-words",children:t}):(0,v.jsx)("span",{className:"text-muted-foreground",children:JSON.stringify(t)})})]},e))})]})]})}),(0,v.jsxs)(oK,{children:[(0,v.jsx)(oX,{variant:"outline",onClick:()=>eY(e),children:"Reject"}),(0,v.jsx)(oX,{variant:"ghost",onClick:()=>eJ(e),className:"text-muted-foreground hover:text-foreground",children:"Don't ask again"}),(0,v.jsx)(oX,{variant:"default",onClick:()=>eX(e),children:"Approve"})]})]},e.id)})}),(0,v.jsxs)($,{className:(0,k.cn)("flex-1 p-4",t&&"p-2"),children:[(0,v.jsxs)(V,{className:(0,k.cn)("max-w-3xl mx-auto w-full",t&&"max-w-none"),children:[eo&&(0,v.jsx)("div",{className:"flex justify-center py-12",children:(0,v.jsx)(oJ,{size:24})}),!eo&&0===n.length&&!z&&(0,v.jsx)(U,{icon:(0,v.jsxs)("div",{className:"relative overflow-hidden rounded-2xl size-16 shadow-lg ring-1 ring-white/10",children:[(0,v.jsx)(w.default,{src:"/sparke-coder.png",alt:"SparkECoder",width:64,height:64,className:"absolute inset-0 size-full object-cover",priority:!0}),d&&(0,v.jsx)("video",{src:"/sparkecode.mp4",autoPlay:!0,muted:!0,loop:!0,playsInline:!0,className:"absolute inset-0 size-full object-cover"})]}),title:"Start a conversation",description:"Ask SparkECoder to help you with coding tasks"}),n.filter(e=>!("tool-call"===e.type&&e.toolCall&&(Y.some(t=>t.toolCallId===e.toolCall?.toolCallId)||K.some(t=>t.toolCallId===e.toolCall?.toolCallId||t.toolName===e.toolCall?.toolName&&("streaming"===t.status||"running"===t.status))))&&!0).map(e=>{if("user-message"===e.type){let t,r,n=void 0!==e.messageSequence&&ee.some(t=>t.messageSequence===e.messageSequence);return(0,v.jsxs)(a$,{from:"user",children:[(0,v.jsxs)(aV,{children:[e.attachments&&e.attachments.length>0&&(0,v.jsx)("div",{className:"flex flex-wrap gap-2 mb-2",children:e.attachments.map((e,t)=>(0,v.jsx)("div",{className:"relative",children:"image"===e.type?(0,v.jsx)("div",{className:"relative rounded-lg overflow-hidden border border-border/50 max-w-[200px]",children:(0,v.jsx)("img",{src:e.data.startsWith("data:")?e.data:`data:${e.mediaType||"image/png"};base64,${e.data}`,alt:e.filename||"Image attachment",className:"max-w-full h-auto max-h-[150px] object-contain"})}):(0,v.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-muted/50 border border-border/50",children:[(0,v.jsx)(xc,{className:"h-4 w-4 text-muted-foreground"}),(0,v.jsx)("span",{className:"text-sm text-muted-foreground truncate max-w-[150px]",children:e.filename||"File"})]})},t))}),e.content&&(t=e.content.replace(yE,"").trim(),r=function(e){let t=e.match(/<devtools-context>([\s\S]*?)<\/devtools-context>/);if(!t)return null;let r=t[1],n=r.match(/<page\s+url="([^"]*)"\s+path="([^"]*)"\s+name="([^"]*)"/),s=r.match(/<viewport\s+width="([^"]*)"\s+height="([^"]*)"(?:\s+dpr="([^"]*)")?/);return n?{url:n[1],path:n[2],pageName:n[3],viewportWidth:s?.[1],viewportHeight:s?.[2],dpr:s?.[3]}:null}(e.content),(0,v.jsxs)(v.Fragment,{children:[t&&(0,v.jsx)("p",{className:"whitespace-pre-wrap",children:t}),r&&(0,v.jsxs)("div",{className:"flex items-center gap-1.5 mt-1.5 text-[11px] text-muted-foreground/60",children:[(0,v.jsx)(xx,{className:"h-3 w-3"}),(0,v.jsx)("span",{children:r.path}),r.viewportWidth&&r.viewportHeight&&(0,v.jsxs)("span",{className:"text-muted-foreground/40",children:[r.viewportWidth,"x",r.viewportHeight]})]})]}))]}),n&&!d&&(0,v.jsx)(aU,{className:"justify-end mt-1",children:(0,v.jsx)(_.TooltipProvider,{children:(0,v.jsxs)(_.Tooltip,{children:[(0,v.jsx)(_.TooltipTrigger,{asChild:!0,children:(0,v.jsxs)(A.Button,{variant:"ghost",size:"sm",onClick:()=>ez(e.messageSequence,e.content),disabled:er,className:"h-6 px-2 text-xs text-muted-foreground hover:text-destructive gap-1",children:[(0,v.jsx)(xa,{className:"h-3 w-3"}),"Revert"]})}),(0,v.jsx)(_.TooltipContent,{children:(0,v.jsx)("p",{children:"Revert to before this message (undo all changes after)"})})]})})})]},e.id)}if("reasoning"===e.type)return(0,v.jsxs)(pH,{isStreaming:!1,defaultOpen:!1,children:[(0,v.jsx)(pX,{}),(0,v.jsx)(pY,{children:e.content||""})]},e.id);if("assistant-text"===e.type)return(0,v.jsx)(a$,{from:"assistant",children:(0,v.jsxs)("div",{className:"flex gap-3",children:[(0,v.jsx)("div",{className:"relative overflow-hidden rounded-lg size-8 shadow-sm ring-1 ring-white/10 shrink-0",children:(0,v.jsx)(w.default,{src:"/sparke-coder.png",alt:"SparkECoder",width:32,height:32,className:"absolute inset-0 size-full object-cover"})}),(0,v.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,v.jsx)(aV,{children:(0,v.jsx)(aq,{children:e.content||""})}),(0,v.jsx)(aU,{children:(0,v.jsx)(aG,{label:"Copy",onClick:()=>navigator.clipboard.writeText(e.content||""),children:(0,v.jsx)(om,{className:"size-3"})})})]})]})},e.id);if("tool-call"===e.type&&e.toolCall){let t=e.toolCall,r=`tool-${t.toolName}`;if("write_file"===t.toolName)return(0,v.jsx)(xj,{input:t.input,output:t.output,status:t.status,streamingArgsText:t.streamingArgsText,liveContent:t.liveContent,liveOldString:t.liveOldString,liveNewString:t.liveNewString},e.id);if("read_file"===t.toolName)return(0,v.jsx)(xC,{input:t.input,output:t.output,status:t.status},e.id);if("bash"===t.toolName)return(0,v.jsx)(xE,{input:t.input,output:t.output,status:t.status,terminalId:t.terminalId,liveOutput:t.liveOutput},e.id);if("explore_agent"===t.toolName)return(0,v.jsx)(xz,{input:t.input,output:t.output,status:t.status,steps:t.exploreSteps},e.id);if("todo"===t.toolName)return(0,v.jsx)(xW,{input:t.input,output:t.output,status:t.status},e.id);if("load_skill"===t.toolName)return(0,v.jsx)(xK,{input:t.input,output:t.output,status:t.status},e.id);if("linter"===t.toolName)return(0,v.jsx)(xQ,{input:t.input,output:t.output,status:t.status},e.id);let n="completed"!==t.status;return(0,v.jsxs)(oE,{defaultOpen:n,children:[(0,v.jsx)(oP,{type:r,state:function(e){switch(e){case"pending":case"streaming":default:return"input-streaming";case"running":return"input-available";case"completed":return"output-available";case"rejected":return"output-denied";case"error":return"output-error"}}(t.status),title:t.toolName}),(0,v.jsxs)(oR,{children:[(0,v.jsx)(oM,{input:t.input}),(e=>{let t=e.output,r=e.input;if("bash"===e.toolName)return(0,v.jsx)(xE,{input:e.input,output:e.output,status:e.status,terminalId:e.terminalId,liveOutput:e.liveOutput,className:"mt-2"});if("explore_agent"===e.toolName)return(0,v.jsx)(xz,{input:e.input,output:e.output,status:e.status,steps:e.exploreSteps,className:"mt-2"});if("todo"===e.toolName)return(0,v.jsx)(xW,{input:e.input,output:e.output,status:e.status,className:"mt-2"});if("load_skill"===e.toolName)return(0,v.jsx)(xK,{input:e.input,output:e.output,status:e.status,className:"mt-2"});if("write_file"===e.toolName&&r){let e=r.path||"file",n=r.mode||"full",s=e.split("/").pop()||"file",i=eQ(e);if("str_replace"===n){let e=r.old_string||"",n=r.new_string||"";return(0,v.jsxs)("div",{className:"mt-2 max-w-full overflow-hidden space-y-2",children:[(0,v.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,v.jsx)(xr,{className:"size-4 text-muted-foreground"}),(0,v.jsx)("span",{className:"font-medium",children:s}),(0,v.jsx)(C,{variant:"secondary",className:"text-xs",children:"str_replace"})]}),(0,v.jsxs)("div",{className:"rounded-md border overflow-hidden",children:[(0,v.jsxs)("div",{className:"bg-red-500/10 border-b p-2",children:[(0,v.jsx)("div",{className:"text-xs text-red-500 mb-1",children:"- Remove:"}),(0,v.jsx)("pre",{className:"text-xs overflow-x-auto whitespace-pre-wrap break-words text-red-400",children:e.length>500?e.slice(0,500)+"...":e})]}),(0,v.jsxs)("div",{className:"bg-green-500/10 p-2",children:[(0,v.jsx)("div",{className:"text-xs text-green-500 mb-1",children:"+ Add:"}),(0,v.jsx)("pre",{className:"text-xs overflow-x-auto whitespace-pre-wrap break-words text-green-400",children:n.length>500?n.slice(0,500)+"...":n})]})]}),t&&(0,v.jsxs)("div",{className:`text-xs flex items-center gap-1 ${t.success?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400"}`,children:[(0,v.jsx)("span",{children:t.success?"✓":"✗"}),(0,v.jsx)("span",{children:t.success?`Replaced (${void 0!==t.lineDelta?(t.lineDelta>=0?"+":"")+t.lineDelta+" lines":"done"})`:t.error||"Failed"})]})]})}let a=r.content||"";return(0,v.jsxs)("div",{className:"mt-2 max-w-full overflow-hidden",children:[(0,v.jsxs)(oL,{children:[(0,v.jsxs)(oD,{children:[(0,v.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,v.jsx)(xr,{className:"size-4 text-muted-foreground shrink-0"}),(0,v.jsx)(oO,{className:"truncate",children:s}),(0,v.jsx)(oz,{className:"truncate text-xs hidden sm:block",children:e})]}),(0,v.jsx)(oF,{children:(0,v.jsx)(oB,{icon:om,label:"Copy",onClick:()=>navigator.clipboard.writeText(a)})})]}),a&&(0,v.jsx)(o$,{className:"p-0 max-h-[300px] overflow-auto",children:(0,v.jsx)(oT,{code:a,language:i,showLineNumbers:!0,children:(0,v.jsx)(oS,{className:"sr-only",children:(0,v.jsx)(oC,{children:(0,v.jsx)(oA,{children:s})})})})})]}),t&&(0,v.jsxs)("div",{className:`mt-2 text-xs flex items-center gap-1 ${t.success?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400"}`,children:[(0,v.jsx)("span",{children:t.success?"✓":"✗"}),(0,v.jsx)("span",{children:t.success?`File ${t.action||"written"} successfully`:t.error||"Failed"})]})]})}if("read_file"===e.toolName&&t){let e=r?.path||"file",n=t.content||JSON.stringify(t,null,2),s=e.split("/").pop()||"file",i=eQ(e);return(0,v.jsx)("div",{className:"mt-2 max-w-full overflow-hidden",children:(0,v.jsxs)(oL,{children:[(0,v.jsxs)(oD,{children:[(0,v.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,v.jsx)(xr,{className:"size-4 text-muted-foreground shrink-0"}),(0,v.jsx)(oO,{className:"truncate",children:s}),(0,v.jsx)(oz,{className:"truncate text-xs hidden sm:block",children:e})]}),(0,v.jsx)(oF,{children:(0,v.jsx)(oB,{icon:om,label:"Copy",onClick:()=>navigator.clipboard.writeText(n)})})]}),(0,v.jsx)(o$,{className:"p-0 max-h-[300px] overflow-auto",children:(0,v.jsx)(oT,{code:n,language:i,showLineNumbers:!0,children:(0,v.jsx)(oS,{className:"sr-only",children:(0,v.jsx)(oC,{children:(0,v.jsx)(oA,{children:s})})})})})]})})}return t?(0,v.jsx)(oI,{output:(0,v.jsxs)("pre",{className:"text-xs overflow-x-auto max-w-full whitespace-pre-wrap break-words",children:[JSON.stringify(t,null,2).slice(0,500),JSON.stringify(t).length>500?"...":""]}),errorText:"error"===e.status?"Tool execution failed":void 0}):null})(t)]})]},e.id)}return null}),d&&!z&&!B&&0===K.length&&(0,v.jsxs)("div",{className:"flex gap-3 items-center",children:[(0,v.jsx)("div",{className:"relative overflow-hidden rounded-lg size-8 shadow-sm ring-1 ring-white/10 shrink-0",children:(0,v.jsx)("video",{src:"/sparkecode.mp4",autoPlay:!0,muted:!0,loop:!0,playsInline:!0,className:"absolute inset-0 size-full object-cover"})}),(0,v.jsx)("span",{className:"text-sm text-muted-foreground",children:"Thinking..."})]}),d&&(q||B)&&(0,v.jsxs)(pH,{isStreaming:q,defaultOpen:!0,children:[(0,v.jsx)(pX,{}),(0,v.jsx)(pY,{children:B})]}),d&&z&&(0,v.jsx)(a$,{from:"assistant",children:(0,v.jsxs)("div",{className:"flex gap-3",children:[(0,v.jsx)("div",{className:"relative overflow-hidden rounded-lg size-8 shadow-sm ring-1 ring-white/10 shrink-0",children:(0,v.jsx)("video",{src:"/sparkecode.mp4",autoPlay:!0,muted:!0,loop:!0,playsInline:!0,className:"absolute inset-0 size-full object-cover"})}),(0,v.jsx)("div",{className:"flex-1 min-w-0",children:(0,v.jsxs)(aV,{children:[(0,v.jsx)(aq,{children:z}),(0,v.jsx)("span",{className:"inline-block w-2 h-4 bg-primary animate-pulse ml-1"})]})})]})}),d&&K.map(e=>"write_file"===e.toolName?(0,v.jsx)(xj,{input:e.input,output:e.output,status:e.status,streamingArgsText:e.streamingArgsText,liveContent:e.liveContent,liveOldString:e.liveOldString,liveNewString:e.liveNewString},e.toolCallId):"read_file"===e.toolName?(0,v.jsx)(xC,{input:e.input,output:e.output,status:e.status},e.toolCallId):"bash"===e.toolName?(0,v.jsx)(xE,{input:e.input,output:e.output,status:e.status,terminalId:e.terminalId,liveOutput:e.liveOutput},e.toolCallId):"explore_agent"===e.toolName?(0,v.jsx)(xz,{input:e.input,output:e.output,status:e.status,steps:e.exploreSteps},e.toolCallId):"todo"===e.toolName?(0,v.jsx)(xW,{input:e.input,output:e.output,status:e.status},e.toolCallId):"load_skill"===e.toolName?(0,v.jsx)(xK,{input:e.input,output:e.output,status:e.status},e.toolCallId):"linter"===e.toolName?(0,v.jsx)(xQ,{input:e.input,output:e.output,status:e.status},e.toolCallId):(0,v.jsxs)(oE,{defaultOpen:!0,children:[(0,v.jsx)(oP,{type:`tool-${e.toolName}`,state:"streaming"===e.status?"input-streaming":"input-available",title:e.toolName}),(0,v.jsxs)(oR,{children:[(0,v.jsx)(oM,{input:e.input}),(0,v.jsxs)("div",{className:"flex items-center gap-2 p-3 text-muted-foreground",children:[(0,v.jsx)(oJ,{size:14}),(0,v.jsx)("span",{className:"text-sm",children:"streaming"===e.status?"Receiving...":"Executing..."})]})]})]},e.toolCallId)),d&&!z&&0===K.length&&(0,v.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,v.jsx)(oJ,{size:16}),(0,v.jsx)("span",{className:"text-sm",children:"Thinking..."})]})]}),(0,v.jsx)(G,{})]}),S&&(0,v.jsxs)("div",{className:"fixed bottom-28 right-4 w-80 max-h-80 overflow-auto border bg-background/95 shadow-lg rounded-md text-xs",children:[(0,v.jsx)("div",{className:"px-3 py-2 border-b font-mono text-muted-foreground",children:"SSE Debug"}),(0,v.jsxs)("div",{className:"px-3 py-2 space-y-1",children:[0===E.length&&0===R.length&&(0,v.jsx)("div",{className:"text-muted-foreground",children:"No events yet"}),E.map((e,t)=>(0,v.jsx)("div",{className:"font-mono",children:e},`evt-${t}`)),R.map((e,t)=>(0,v.jsx)("div",{className:"font-mono text-red-600",children:e},`err-${t}`))]})]}),(0,v.jsx)("div",{className:(0,k.cn)("border-t border-border/50 p-4 pb-6 bg-card/30",t&&"p-2 pb-2"),children:(0,v.jsxs)("div",{className:(0,k.cn)("max-w-3xl mx-auto",t&&"max-w-none"),children:[!t&&!eo&&0===n.length&&!z&&!d&&(0,v.jsx)(gQ,{className:"mb-3",children:['Create a hello.txt file with "Hello, World!"',"List files in the current directory","Show the current git status"].map(e=>(0,v.jsx)(g0,{suggestion:e,onClick:e=>{a(e)}},e))}),p.length>0&&(0,v.jsxs)("div",{className:(0,k.cn)("mb-2 rounded-lg border border-border/60 bg-muted/20 overflow-hidden",t&&"mb-1"),children:[(0,v.jsxs)("button",{type:"button",onClick:()=>N(e=>!e),className:(0,k.cn)("w-full flex items-center justify-between px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/30 transition-colors",t&&"px-2 py-1"),children:[(0,v.jsxs)("div",{className:"flex items-center gap-1.5",children:[j?(0,v.jsx)(xh.default,{className:"size-3"}):(0,v.jsx)(xp.default,{className:"size-3"}),(0,v.jsxs)("span",{className:"font-medium",children:[p.length," Queued"]})]}),(0,v.jsx)("span",{className:"text-[10px]",children:"Stop ^C"})]}),j&&(0,v.jsx)("div",{className:"border-t border-border/40 divide-y divide-border/30",children:p.map((e,r)=>(0,v.jsxs)("div",{className:(0,k.cn)("flex items-start gap-2 px-3 py-2 group",t&&"px-2 py-1.5 gap-1.5"),children:[(0,v.jsx)("span",{className:"text-[10px] text-muted-foreground/60 pt-0.5 w-4 shrink-0 text-center",children:r+1}),(0,v.jsxs)("div",{className:"flex-1 min-w-0",children:[f===e.id?(0,v.jsxs)("div",{className:"flex items-center gap-1",children:[(0,v.jsx)("input",{type:"text",value:x,onChange:e=>y(e.target.value),onKeyDown:t=>{"Enter"===t.key&&eH(e.id),"Escape"===t.key&&g(null)},className:(0,k.cn)("flex-1 bg-background border border-border rounded px-2 py-0.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary/30",t&&"text-[11px]"),autoFocus:!0}),(0,v.jsx)("button",{type:"button",onClick:()=>eH(e.id),className:"p-0.5 text-primary hover:text-primary/80",children:(0,v.jsx)(xs.Check,{className:"size-3"})})]}):(0,v.jsx)("p",{className:(0,k.cn)("text-xs text-foreground truncate",t&&"text-[11px]"),children:e.text||"Selected elements attached"}),e.attachments&&e.attachments.length>0&&(0,v.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[e.attachments.length," file",e.attachments.length>1?"s":""]}),e.selectedElements&&(0,v.jsx)("span",{className:"text-[10px] text-muted-foreground",children:"+ selected elements"})]}),(0,v.jsxs)("div",{className:(0,k.cn)("flex items-center gap-0.5 shrink-0 transition-opacity",t?"opacity-100":"opacity-0 group-hover:opacity-100"),children:[(0,v.jsx)("button",{type:"button",onClick:()=>{g(e.id),y(e.text)},className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted/50",title:"Edit",children:(0,v.jsx)(xn,{className:"size-3"})}),r>0&&(0,v.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.id,void m(e=>{let r=e.findIndex(e=>e.id===t);if(-1===r)return e;let n=r-1;if(n<0||n>=e.length)return e;let s=[...e];return[s[r],s[n]]=[s[n],s[r]],s})},className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted/50",title:"Move up",children:(0,v.jsx)(xf,{className:"size-3"})}),(0,v.jsx)("button",{type:"button",onClick:()=>eK(e.id),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted/50",title:"Send now",children:(0,v.jsx)(xm,{className:"size-3"})}),(0,v.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.id,void m(e=>e.filter(e=>e.id!==t))},className:"p-1 rounded text-muted-foreground hover:text-destructive hover:bg-muted/50",title:"Remove",children:(0,v.jsx)(xg.Trash2,{className:"size-3"})})]})]},e.id))})]}),(0,v.jsx)(y_,{children:(0,v.jsxs)(gM,{onSubmit:eV,className:"shadow-sm",globalDrop:!0,multiple:!0,children:[(0,v.jsxs)(gL,{children:[c&&(0,v.jsxs)("div",{className:(0,k.cn)("mb-2 flex items-center justify-between rounded-md border border-border/60 bg-muted/40 px-2 py-1 text-xs",t&&"mb-1"),children:[(0,v.jsxs)("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[(0,v.jsx)("span",{className:"size-1.5 rounded-full bg-primary/70"}),(0,v.jsx)("span",{children:"Selected elements attached"})]}),(0,v.jsx)("button",{type:"button",onClick:()=>u(null),className:"rounded-sm p-1 text-muted-foreground hover:text-foreground","aria-label":"Remove selected elements",children:(0,v.jsx)(xd.X,{className:"size-3.5"})})]}),(0,v.jsx)(yR,{})]}),(0,v.jsx)(gI,{children:(0,v.jsxs)("div",{className:"relative w-full",children:[(0,v.jsx)(yT,{sessionId:e.id,value:i+(o?(!i||i.endsWith(" ")||i.endsWith("\n")?"":" ")+o:""),onChange:e=>{o&&l(""),a(e)},placeholder:d?"Type to queue a message...":"Ask SparkECoder... (@ to mention files, / for commands)",disabled:!1,autoFocus:!0,className:(0,k.cn)("min-h-[80px] focus:ring-2 focus:ring-primary/20 transition-all field-sizing-content max-h-48",o&&"caret-red-500",t&&"min-h-[40px] text-sm max-h-24")}),o&&(0,v.jsxs)("div",{className:"absolute bottom-2 right-2 flex items-center gap-1.5 text-xs text-red-500 bg-background/80 backdrop-blur-sm px-2 py-1 rounded-full",children:[(0,v.jsx)("span",{className:"size-2 bg-red-500 rounded-full animate-pulse"}),"Listening..."]})]})}),(0,v.jsxs)(gD,{className:t?"py-1":void 0,children:[!t&&(0,v.jsx)("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:(0,v.jsx)("span",{className:"hidden sm:inline",children:"Type @ to mention files, / for commands"})}),(0,v.jsxs)("div",{className:"flex items-center gap-2",children:[(0,v.jsx)(x5,{size:"icon",className:"size-9",onTranscriptionChange:e=>{a(t=>{let r=t&&!t.endsWith(" ")&&!t.endsWith("\n");return t+(r?" ":"")+e})},onInterimTranscription:e=>{l(e)},disabled:d}),(0,v.jsx)(yM,{input:i+o,isRunning:d,onStop:eU,hasExtraContent:!!(c&&c.trim())})]})]})]})})]})})]})}e.s(["ChatInterface",()=>yI],557355)}]);