PageSourceSearch

https://agentconnectv2.lyriq.ai/_next/static/chunks/3052.df70bca27f729980.js

js lyriq.ai collected 2026-10-05 14:07:17 UTC 52,038 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3052],{90917:(e,t,n)=>{n.d(t,{A:()=>a});var s=n(53834);function a(){let[e,t]=(0,s.useState)("light");return(0,s.useEffect)(()=>{let e=()=>t("dark"===document.documentElement.getAttribute("data-theme")?"dark":"light");e();let n=new MutationObserver(e);return n.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>n.disconnect()},[]),e}},93052:(e,t,n)=>{n.r(t),n.d(t,{ChatView:()=>G});var s=n(70402),a=n(53834),r=n(39633),l=n(44534),i=n(76044),o=n(25815),c=n(85542),d=n(58925),u=n(1230),h=n(6149),x=n(8771),p=n(25627),m=n(79492),f=n(53446),g=n(26820),b=n(3306),w=n(77489),v=n(74391),k=n(36892),j=n(31150),y=n(66946),N=n(85529),C=n(92701),S=n(42043),A=n(91472),I=n(55968),T=n(85397),_=n(71083),O=n(78056),E=n(18155),R=n(4620),D=n(61410),M=n(82109),P=n(90917),L=n(19517),W=n(97925),F=n(18909),J=n(84643),z=n(35524),U=n(62212),H=n(69217),$=n(1689),X=n(21883);let q=(0,a.createContext)(()=>{}),B=Object.values(F.fG),K={tasks:r.A,mail:l.A,approvals:i.A};function G(){var e;let[t,n]=(0,a.useState)(""),[r,l]=(0,a.useState)("workflow"),[i,k]=(0,a.useState)(!1),[j,y]=(0,a.useState)(null),[N,C]=(0,a.useState)({}),[S,A]=(0,a.useState)(null),[I,T]=(0,a.useState)(!1),[_,O]=(0,a.useState)([]);(0,a.useEffect)(()=>{let e=!0;return fetch("/api/workflows").then(e=>e.ok?e.json():null).then(t=>{e&&Array.isArray(null==t?void 0:t.workflows)&&O(t.workflows)}).catch(()=>{}),()=>{e=!1}},[]);let E=(0,a.useMemo)(()=>_.find(e=>e.id===t),[_,t]),[R,M]=(0,a.useState)([]);(0,a.useEffect)(()=>{let e=!0;return fetch("/api/agents").then(e=>e.ok?e.json():null).then(t=>{e&&Array.isArray(null==t?void 0:t.agents)&&M(t.agents.map(e=>({id:e.id,name:e.name,team:e.team})))}).catch(()=>{}),()=>{e=!1}},[]);let[P,L]=(0,a.useState)(null),W=(0,a.useMemo)(()=>P?{id:"live-agent",name:P.name,nodes:[{id:"you",kind:"trigger",label:"You",sublabel:"chat request",trigger:"manual"},{id:"agent",kind:"agent",label:P.name,sublabel:"",agentId:P.agentId},{id:"result",kind:"outcome",label:"Result",sublabel:""}],edges:[{from:"you",to:"agent"},{from:"agent",to:"result"}]}:null,[P]),F=(0,a.useMemo)(()=>P?{you:{state:"success"},agent:{state:P.state,phase:P.phase},result:{state:"success"===P.state?"success":"error"===P.state?"error":"queued"}}:{},[P]),[J,U]=(0,a.useState)("action"),[H,$]=(0,a.useState)([]),[G,Y]=(0,a.useState)(""),[Z,Q]=(0,a.useState)(!1),ee=(0,a.useRef)(null),[et,es]=(0,a.useState)(null),[ea,er]=(0,a.useState)("chat"),el=(0,a.useRef)(null);(0,a.useEffect)(()=>{var e;null==(e=el.current)||e.scrollTo({top:el.current.scrollHeight,behavior:"smooth"})},[H]);let ei=(0,a.useRef)(null),ec=(0,a.useRef)({down:!1,startX:0,startScroll:0,moved:!1}),[ed,eu]=(0,a.useState)([]),[eh,ex]=(0,a.useState)(null),em=(0,a.useRef)(void 0),[ef,eb]=(0,a.useState)(!1);async function ew(){let e=await fetch("/api/chat/sessions").then(e=>e.ok?e.json():{sessions:[]}).catch(()=>({sessions:[]}));eu((Array.isArray(null==e?void 0:e.sessions)?e.sessions:[]).map(e=>({id:e.id,title:e.title,updatedAt:e.updatedAt})))}async function ev(e,t,n){try{var s,a,r;let l=eh;if(!l){let t=await fetch("/api/chat/sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:e.slice(0,60)})}).then(e=>e.json());if(!(null==t||null==(r=t.session)?void 0:r.id))return;l=t.session.id,ex(l)}let i=await fetch("/api/chat/sessions/".concat(l,"/messages"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messages:[{role:"user",content:e},{role:"assistant",content:t,...n?{agentId:n}:{}}]})}).then(e=>e.ok?e.json():null).catch(()=>null),o=null==i||null==(a=i.messages)||null==(s=a.find(e=>"assistant"===e.role))?void 0:s.id;o&&$(e=>{let t=[...e];for(let e=t.length-1;e>=0;e--)if("assistant"===t[e].role&&!t[e].id){t[e]={...t[e],id:o};break}return t}),ew()}catch(e){}}function ek(e){$(t=>{let n=[...t];for(let t=n.length-1;t>=0;t--)if("assistant"===n[t].role&&n[t].entries){var s,a;let r=null!=(a=n[t].entries)?a:[],l=[...r,e],i="assistant"===e.kind?en(n[t].content,e.text,null==(s=r[r.length-1])?void 0:s.kind):n[t].content;n[t]={...n[t],entries:l,content:i};break}return n})}async function ej(e){eb(!1);let t=await fetch("/api/chat/sessions/".concat(e)).then(e=>
1e.ok?e.json():null).catch(()=>null);(null==t?void 0:t.session)&&(ex(e),em.current=void 0,$((Array.isArray(t.messages)?t.messages:[]).map(e=>{var t;return{role:"assistant"===e.role?"assistant":"user",content:e.content,kind:"text",id:e.id,feedback:null!=(t=e.feedback)?t:null}})))}function ey(){$([]),ex(null),em.current=void 0,eb(!1)}async function eN(e,t){$(n=>n.map(n=>n.id===e?{...n,feedback:t}:n)),await fetch("/api/chat/messages/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({feedback:t})}).catch(()=>{})}async function eC(e){eu(t=>t.filter(t=>t.id!==e)),eh===e&&ey(),await fetch("/api/chat/sessions/".concat(e),{method:"DELETE"}).catch(()=>void ew())}async function eS(e){n(e),l("live"),k(!0),y(null),er("canvas"),C({}),A("running");try{let t=await fetch("/api/workflows/run",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({graphId:e})}),n=await t.json().catch(()=>({}));if(t.ok&&(null==n?void 0:n.runId)){y(n.runId);try{localStorage.setItem("ac-wf-run",JSON.stringify({runId:n.runId,graphId:e,ts:Date.now()}))}catch(e){}$(t=>{var n,s;return[...t,{role:"assistant",content:"Started **".concat(null!=(s=null==(n=_.find(t=>t.id===e))?void 0:n.name)?s:"workflow","** — watch the canvas. If it hits an approval it pauses on the Dashboard."),kind:"text"}]})}else 409===t.status?("string"==typeof(null==n?void 0:n.runId)&&y(n.runId),$(e=>[...e,{role:"assistant",content:"That workflow is already running with the same input — showing the run in progress instead of starting another.",kind:"text"}])):(A(null),$(e=>[...e,{role:"assistant",content:"string"==typeof(null==n?void 0:n.error)?"That workflow didn't start: ".concat(n.error):"That workflow didn't start — the durable engine may be off.",kind:"text"}]))}finally{k(!1)}}async function eA(){if(j&&!I){T(!0);try{let e=await fetch("/api/workflows/".concat(j,"/cancel"),{method:"POST"}),t=await e.json().catch(()=>({}));if(e.ok){A((null==t?void 0:t.outcome)==="cancelled"?"canceled":S);try{localStorage.removeItem("ac-wf-run")}catch(e){}$(e=>[...e,{role:"assistant",content:(null==t?void 0:t.outcome)==="cancelled"?"Stopped the run. Steps that had already finished are not undone.":"That run had already finished — there was nothing left to stop.",kind:"text"}])}else $(e=>[...e,{role:"assistant",content:"string"==typeof(null==t?void 0:t.error)?"Couldn't stop the run: ".concat(t.error):"Couldn't stop the run. Please try again.",kind:"text"}])}catch(e){$(e=>[...e,{role:"assistant",content:"Couldn't reach the server to stop the run. Please try again.",kind:"text"}])}finally{T(!1)}}}(0,a.useEffect)(()=>{ew()},[]);let eI=i||!!j&&("running"===S||"suspended"===S);async function eT(e){let t,{userContent:n,message:s,agentId:a,agentName:r}=e;Q(!0);let i=new AbortController;ee.current=i;let o="";a&&r&&(L({name:r,agentId:a,phase:"Starting…",state:"running"}),$(e=>{var t;let n=[...e],s=n.length-1;return(null==(t=n[s])?void 0:t.role)==="assistant"&&(n[s]={...n[s],agentId:a}),n}),l("live"),er("canvas"));try{let e=await fetch("/api/chat/agent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:s,thread:em.current,plan:"plan"===J,...a?{agentId:a}:{}}),signal:i.signal});if(!e.ok||!e.body)return void $(t=>eg(t,401===e.status?"Please sign in to chat.":"The assistant is unavailable right now."));let r=e.body.getReader(),l=new TextDecoder,p="";for(;;){var c,d,u,h,x;let{done:e,value:n}=await r.read();if(e)break;let s=(p+=l.decode(n,{stream:!0})).split("\n");for(let e of(p=null!=(c=s.pop())?c:"",s)){let n;if(e.trim()){try{n=JSON.parse(e)}catch(e){continue}if("entry"===n.t){let{t:e,...s}=n;"init"===s.kind&&"string"==typeof s.sessionId&&(em.current=s.sessionId),"assistant"===s.kind&&"string"==typeof s.text&&(o=en(o,s.text,t)),"string"==typeof s.kind&&"init"!==s.kind&&(t=s.kind),ek(s),a&&L(e=>e&&"running"===e.state?{...e,phase:function(e){var t;return"tool_call"===e.kind?"Using ".concat(null!=(t=e.name)?t:"a tool","…"):"tool_result"===e.kind?"Reviewing result…":"thinking"===e.kind?"Thinking…":"assistant"===e.kind?"Writing…":"init"===e.kind?"Starting…":"Working…"}(s)}:e)}else if("done"===n.t){"string"==typeof(null==(d=n.result)?void 0:d.sessionId)&&(em.current=n.result.sessionId);let e=null==(u=n.result)?void 0:u.text;!o.trim()&&"string"==typeof e&&e.trim()&&(o=e,ek({kind:"assistant",ts:Date.now(),text:e})),!o.trim()&&(null==(x=n.result)||null==(h=x.errors)?void 0:h.length)&&$(e=>eg(e,(0,X.r2)(n.result.errors.join("\n")).message))}}}}a&&L(e=>e?{...e,state:"success",phase:"Done"}:e),o.trim()&&ev(n,o,a)}catch(e){i.signal.aborted?(o.trim()||$(e=>eg(e,"Stopped.")),a&&L(e=>e?{...e,state:"success",phase:"Stopped"}:e),o.trim()&&ev(n,o,a)):($(e=>eg(e,"That reply didn't come through — try again.")),a&&L(e=>e?{...e,state:"error",phase:"Failed"}:e))}finally{Q(!1),ee.current=null}}async function e_(e){let t=e.trim();if(!t||Z)return;if(Y(""),t.startsWith("/")){var n;let e=t.slice(1).toLowerCase(),s=null!=(n=_.find(t=>t.name.toLowerCase().includes(e)))?n:_[0];return s?void $(e=>[...e,{role:"user",content:t},{role:"assistant",content:s.name,kind:"confirm",graphId:s.id}]):void $(e=>[...e,{role:"user",content:t},{role:"assistant",content:"You don't have any workflows yet — build one in the Workflow tab, then run it here with /.",kind:"text"}])}if(t.startsWith("@")){let e=t.slice(1),n=R.filter(t=>e.toLowerCase().startsWith(t.name.toLowerCase())).sort((e,t)=>
1t.name.length-e.name.length)[0];$(e=>[...e,{role:"user",content:t},{role:"assistant",content:"",kind:"text",entries:[]}]),await eT(n?{userContent:t,message:e.slice(n.name.length).trim()||"Handle this request.",agentId:n.id,agentName:n.name}:{userContent:t,message:t});return}if("plan"===J||0===R.length&&0===_.length){$(e=>[...e,{role:"user",content:t},{role:"assistant",content:"",kind:"text",entries:[]}]),await eT({userContent:t,message:t});return}let s=H.filter(e=>"confirm"!==e.kind&&"no_agent"!==e.kind&&e.content.trim()).slice(-6).map(e=>({role:e.role,content:e.content}));$(e=>[...e,{role:"user",content:t},{role:"assistant",content:"",kind:"text",entries:[],routing:!0}]),Q(!0);let a=null;try{let e=await fetch("/api/chat/router",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:t,history:s})});a=e.ok?await e.json():null}catch(e){a=null}if((null==a?void 0:a.type)==="workflow"&&a.workflowId){let e=a;$(t=>{var n;let s=[...t];return s[s.length-1]={role:"assistant",content:null!=(n=e.workflowName)?n:"workflow",kind:"confirm",graphId:e.workflowId},s}),Q(!1);return}if((null==a?void 0:a.type)==="no_agent"){let e=a;$(t=>{var n;let s=[...t];return s[s.length-1]={role:"assistant",content:null!=(n=e.message)?n:"There's no agent set up for that yet.",kind:"no_agent"},s}),Q(!1);return}let r=(null==a?void 0:a.type)==="agent"?a.agentId:void 0,l=(null==a?void 0:a.type)==="agent"?a.agentName:void 0;$(e=>{let t=[...e],n=t.length-1;return t[n]&&(t[n]={...t[n],routing:!1}),t}),await eT({userContent:t,message:t,agentId:r,agentName:l})}(0,a.useEffect)(()=>{try{let e=localStorage.getItem("ac-wf-run");if(!e)return;let t=JSON.parse(e);(null==t?void 0:t.runId)&&(null==t?void 0:t.graphId)&&"number"==typeof t.ts&&Date.now()-t.ts<18e5?(n(t.graphId),y(t.runId),l("live"),A("running")):localStorage.removeItem("ac-wf-run")}catch(e){}},[]),(0,a.useEffect)(()=>{if(!j||!t||P||"live"!==r)return;let e=!0,n=null,s=_.find(e=>e.id===t),a=Date.now()+6e5,l=e=>"success"===e?"success":"failed"===e||"error"===e?"error":"running"===e||"suspended"===e||"waiting"===e?"running":"queued";async function i(){if(e)try{let o=await fetch("/api/workflows/".concat(j,"?graphId=").concat(encodeURIComponent(t)),{cache:"no-store"});if(!e)return;if(!o.ok){if(403===o.status||404===o.status){try{localStorage.removeItem("ac-wf-run")}catch(e){}return}Date.now()<a&&(n=setTimeout(i,2500));return}let c=await o.json().catch(()=>({}));if(!e)return;let d="running"===c.status||"suspended"===c.status||"success"===c.status||"failed"===c.status||"canceled"===c.status?c.status:null;d&&A(d);let u=c.steps&&"object"==typeof c.steps?c.steps:{};if(s){let e={};for(let t of s.nodes){var r;let n=Object.keys(u).find(e=>e===t.id||e.split("::").pop()===t.id),s=n?null==(r=u[n])?void 0:r.status:void 0;s&&(e[t.id]={state:l(s)})}if("success"===d)for(let t of s.nodes)e[t.id]={state:"success"};C(e)}let h="success"===d||"failed"===d||"canceled"===d;if(h)try{localStorage.removeItem("ac-wf-run")}catch(e){}!h&&Date.now()<a&&(n=setTimeout(i,1600))}catch(t){e&&Date.now()<a&&(n=setTimeout(i,2500))}}return i(),()=>{e=!1,n&&clearTimeout(n)}},[j,t,P,r,_]);let eO=0===H.length;return(0,s.jsxs)("div",{className:"flex h-[calc(100vh-49px)] flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1 border-b border-line px-4 py-2 lg:hidden",children:[(0,s.jsxs)(ep,{on:"chat"===ea,onClick:()=>er("chat"),children:[(0,s.jsx)(o.A,{className:"h-3.5 w-3.5"})," Chat"]}),(0,s.jsxs)(ep,{on:"canvas"===ea,onClick:()=>er("canvas"),children:[(0,s.jsx)(c.A,{className:"h-3.5 w-3.5"})," Canvas"]})]}),(0,s.jsxs)("div",{className:"flex min-h-0 flex-1",children:[(0,s.jsxs)("section",{className:"min-w-0 flex-col border-r border-line lg:flex lg:w-[58%] ".concat("canvas"===ea?"flex w-full":"hidden"),children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2 border-b border-line px-4 py-2.5",children:[(0,s.jsxs)(ep,{on:"workflow"===r,onClick:()=>l("workflow"),children:[(0,s.jsx)(c.A,{className:"h-3.5 w-3.5"})," Workflow"]}),(0,s.jsxs)(ep,{on:"live"===r,onClick:()=>l("live"),children:[(0,s.jsxs)("span",{className:"relative flex h-2 w-2",children:[eI&&(0,s.jsx)("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-accent opacity-70"}),(0,s.jsx)("span",{className:"relative inline-flex h-2 w-2 rounded-full",style:{background:eI?"var(--accent)":"var(--faint)"}})]}),"Live run"]}),(0,s.jsxs)("div",{className:"flex w-full min-w-0 items-center gap-2 sm:ml-auto sm:w-auto",children:[(0,s.jsxs)("select",{value:t,onChange:e=>n(e.target.value),className:"min-w-0 flex-1 truncate rounded-sm border sm:max-w-[180px] sm:flex-none border-line bg-surface-2 px-2 py-1.5 text-sm text-ink outline-none focus:border-accent",children:[0===_.length?(0,s.jsx)("option",{value:"",children:"No workflows yet — build one in Workflow"}):(0,s.jsx)("option",{value:"",children:"Select a workflow…"}),_.map(e=>(0,s.jsx)("option",{value:e.id,children:e.name},e.id))]}),(0,s.jsx)("button",{onClick:()=>eI?void eA():eS(t),disabled:eI?i||I||!j:!t,className:"btn btn-accent shrink-0 px-3 py-1.5 text-sm disabled:opacity-40",children:I?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(d.A,{className:"h-3.5 w-3.5 animate-spin"})," Stopping…"]}):eI?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(u.A,{className:"h-3.5 w-3.5"})," Stop"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(h.A,{className:"h-3.5 w-3.5"})," Run"]})})]})]}),(0,s.jsx)("div",{className:"min-h-0 flex-1 p-3",children:"live"===r&&W?(0,s.jsx)(z._,{graph:W,status:F},"live-agent"):E?(0,s.jsx)(z._,{graph:E,status:j?N:void 0},E.id):(0,s.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-5 overflow-y-auto px-4 py-4 text-center",children:[(0,s.jsxs)("div",{className:"flex flex-col items-center gap-2.5",children:[(0,s.jsx)("span",{className:"grid h-11 w-11 place-items-center rounded-xl text-white",style:{background:"linear-gradient(135deg, var(--cat-tool), color-mix(in srgb, var(--cat-tool) 62%, #ffffff))",boxShadow:"0 8px 18px -8px color-mix(in srgb, var(--cat-tool) 70%, transparent)"},children:(0,s.jsx)(c.A,{className:"h-6 w-6",strokeWidth:1.6})}),(0,s.jsx)("p",{className:"text-base font-medium text-ink",children:_.length>0?"Pick a workflow to run":"No workflows yet"}),(0,s.jsx)("p",{className:"max-w-[40ch] text-sm text-ink-2",children:_.length>0?"Click one to run it live — or just ask in chat and the right agent runs here.":"Build one in the Workflow section, or just ask in chat — the right agent runs live right here."})]}),_.length>0&&(0,s.jsx)("div",{className:"w-full max-w-[540px]",children:(0,s.jsx)("div",{className:"grid grid-cols-2 gap-2",children:_.slice(0,4).map(e=>{let t=e.nodes.some(e=>"gate"===e.kind),n=[...e.id].reduce((e,t)=>
1(31*e+t.charCodeAt(0))%360,7);return(0,s.jsxs)("button",{onClick:()=>eS(e.id),disabled:eI,className:"group flex items-center gap-2.5 rounded-xl border border-line bg-surface p-2.5 text-left transition-all duration-200 hover:-translate-y-0.5 hover:border-accent-line hover:bg-accent-soft hover:shadow-[var(--shadow-2)] disabled:opacity-60 disabled:hover:translate-y-0",children:[(0,s.jsx)("span",{className:"grid h-9 w-9 shrink-0 place-items-center rounded-lg text-white transition-transform duration-200 group-hover:scale-105",style:{background:"linear-gradient(135deg, hsl(".concat(n," 66% 55%), hsl(").concat((n+42)%360," 62% 48%))"),boxShadow:"0 5px 12px -7px hsl(".concat(n," 66% 50%)")},children:(0,s.jsx)(c.A,{className:"h-[18px] w-[18px]",strokeWidth:1.9})}),(0,s.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,s.jsx)("span",{className:"block truncate text-sm font-semibold text-ink",children:e.name}),(0,s.jsxs)("span",{"data-mono":!0,className:"block text-2xs text-faint",children:[e.nodes.length," step",1===e.nodes.length?"":"s",t?" \xb7 approval":""]})]}),(0,s.jsx)(h.A,{className:"h-4 w-4 shrink-0 text-accent opacity-0 transition-opacity group-hover:opacity-100"})]},e.id)})})})]})}),j&&(0,s.jsxs)("div",{className:"flex items-center gap-2 border-t border-line px-4 py-2 text-xs text-ink-2",children:[(0,s.jsxs)("span",{"data-mono":!0,className:"text-faint",children:["run ",j.slice(0,12)]}),(0,s.jsx)("span",{className:"text-faint",children:"\xb7"}),S?(0,s.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,s.jsx)("span",{className:"h-1.5 w-1.5 rounded-full ".concat("running"===S||"suspended"===S?"ac-awaiting":""),style:{background:"success"===S?"var(--ok)":"failed"===S?"var(--err)":"suspended"===S?"#E0A83A":"canceled"===S?"var(--faint)":"var(--accent)"}}),"running"===S?"running…":"suspended"===S?"awaiting your approval":"success"===S?"completed":"canceled"===S?"stopped":"failed"]}):(0,s.jsx)("span",{className:"text-faint",children:"on the durable engine"})]})]}),(0,s.jsxs)("section",{className:"min-w-0 flex-col lg:flex lg:w-[42%] ".concat("chat"===ea?"flex w-full":"hidden"),children:[(0,s.jsxs)("div",{className:"relative flex min-w-0 flex-wrap items-center gap-1.5 border-b border-line px-4 py-2.5 sm:flex-nowrap sm:gap-2",children:[(0,s.jsx)("p",{className:"hidden shrink-0 text-base font-semibold text-ink sm:block",children:"Chat"}),(0,s.jsxs)("button",{"data-tour":"chat-new",onClick:ey,title:"New chat",className:"flex shrink-0 items-center gap-1 rounded-sm px-2 py-1.5 text-sm text-ink-2 transition-colors hover:bg-surface-2 hover:text-ink",children:[(0,s.jsx)(x.A,{className:"h-3.5 w-3.5"})," ",(0,s.jsx)("span",{className:"hidden sm:inline lg:hidden xl:inline",children:"New"})]}),(0,s.jsxs)("button",{onClick:()=>{eb(e=>!e),ef||ew()},title:"Chat history",className:"flex items-center gap-1 rounded-sm px-2 py-1.5 text-sm transition-colors ".concat(ef?"bg-surface-2 text-ink":"text-ink-2 hover:bg-surface-2 hover:text-ink"),children:[(0,s.jsx)(p.A,{className:"h-3.5 w-3.5"})," ",(0,s.jsx)("span",{className:"hidden sm:inline lg:hidden xl:inline",children:"History"}),ed.length>0&&(0,s.jsx)("span",{"data-mono":!0,className:"text-2xs text-faint",children:ed.length})]}),ef&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 z-10",onClick:()=>eb(!1)}),(0,s.jsx)("div",{className:"absolute left-4 top-[calc(100%-2px)] z-20 max-h-[60vh] w-[300px] overflow-y-auto rounded-lg border border-line bg-surface p-1 shadow-xl",children:0===ed.length?(0,s.jsx)("p",{className:"px-3 py-4 text-center text-sm text-ink-2",children:"No saved chats yet. Start talking and this conversation is kept."}):ed.map(e=>(0,s.jsxs)("div",{className:"group flex items-center gap-2 rounded-sm px-2.5 py-2 hover:bg-surface-2 ".concat(eh===e.id?"bg-surface-2":""),children:[(0,s.jsxs)("button",{onClick:()=>void ej(e.id),className:"min-w-0 flex-1 text-left",children:[(0,s.jsx)("span",{className:"block truncate text-base text-ink",children:e.title}),(0,s.jsx)("span",{"data-mono":!0,className:"block text-2xs text-faint",children:function(e){let t=Math.max(0,Math.floor((Date.now()-e)/1e3));if(t<45)return"just now";let n=Math.floor(t/60);if(n<60)return"".concat(n,"m ago");let s=Math.floor(n/60);if(s<24)return"".concat(s,"h ago");let a=Math.floor(s/24);return a<30?"".concat(a,"d ago"):"".concat(Math.floor(a/30),"mo ago")}(e.updatedAt)})]}),(0,s.jsx)("button",{onClick:()=>void eC(e.id),className:"shrink-0 text-faint opacity-0 transition-opacity hover:text-err group-hover:opacity-100","aria-label":"Delete chat",children:(0,s.jsx)(m.A,{className:"h-3.5 w-3.5"})})]},e.id))})]}),(0,s.jsxs)("div",{"data-tour":"chat-mode",className:"ml-auto flex shrink-0 items-center gap-1 rounded-md border border-line p-0.5",children:[(0,s.jsxs)(ep,{on:"action"===J,onClick:()=>U("action"),children:[(0,s.jsx)(f.A,{className:"h-3.5 w-3.5"})," Action"]}),(0,s.jsxs)(ep,{on:"plan"===J,onClick:()=>U("plan"),children:[(0,s.jsx)(g.A,{className:"h-3.5 w-3.5"})," Plan"]})]})]}),(0,s.jsx)("div",{ref:el,className:"min-h-0 flex-1 overflow-y-auto px-4 py-4",children:eO?(0,s.jsxs)("div",{className:"ac-rise flex min-h-full flex-col items-center justify-center gap-4 px-2 py-4 text-center sm:gap-6",children:[(0,s.jsxs)("div",{className:"relative flex flex-col items-center gap-4",children:[(0,s.jsx)("div",{"aria-hidden":!0,
1className:"pointer-events-none absolute -top-5 hidden h-28 w-28 rounded-full blur-2xl sm:block",style:{background:"radial-gradient(circle at center, var(--glow), transparent 70%)",opacity:.6}}),(0,s.jsx)("div",{className:"relative hidden h-14 w-14 place-items-center rounded-2xl text-white ring-1 ring-white/15 sm:grid",style:{background:"linear-gradient(135deg, var(--accent), #22d3ee)",boxShadow:"0 14px 32px -10px var(--glow)"},children:(0,s.jsx)(b.A,{className:"h-7 w-7",strokeWidth:1.5})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"font-serif text-2xl text-ink",children:"How can I help?"}),(0,s.jsxs)("p",{className:"mx-auto mt-2 max-w-[42ch] text-sm text-ink-2",children:["Just ask — I'll pick the right agent for the job. Or ",(0,s.jsx)("span",{"data-mono":!0,className:"rounded bg-surface-2 px-1 text-ink",children:"@"})," mention one \xb7 ",(0,s.jsx)("span",{"data-mono":!0,className:"rounded bg-surface-2 px-1 text-ink",children:"/"})," run a workflow"]})]})]}),(0,s.jsxs)("div",{className:"grid w-full max-w-[480px] grid-cols-2 gap-2",children:[null==(e=B[0])?void 0:e.chips.map(e=>{var t;let n=null!=(t=K[e.icon])?t:b.A;return(0,s.jsxs)("button",{onClick:()=>e_(e.label),className:"group flex items-center gap-2.5 rounded-xl border border-line bg-surface p-2.5 text-left sm:gap-3 sm:p-3 transition-all duration-200 hover:-translate-y-0.5 hover:border-accent-line hover:bg-accent-soft hover:shadow-[var(--shadow-2)]",children:[(0,s.jsx)("span",{className:"grid h-8 w-8 shrink-0 place-items-center rounded-lg bg-accent-soft text-accent transition-colors group-hover:bg-accent group-hover:text-white",children:(0,s.jsx)(n,{className:"h-4 w-4",strokeWidth:1.8})}),(0,s.jsx)("span",{className:"min-w-0 flex-1 text-sm font-medium text-ink",children:e.label}),(0,s.jsx)(w.A,{className:"hidden h-4 w-4 shrink-0 -translate-x-1 text-faint opacity-0 transition-all group-hover:translate-x-0 group-hover:text-accent group-hover:opacity-100 sm:block"})]},e.label)}),(0,s.jsxs)("button",{onClick:()=>e_("/"),className:"group flex items-center gap-2.5 rounded-xl border border-line bg-surface p-2.5 text-left sm:gap-3 sm:p-3 transition-all duration-200 hover:-translate-y-0.5 hover:border-accent-line hover:bg-accent-soft hover:shadow-[var(--shadow-2)]",children:[(0,s.jsx)("span",{className:"grid h-8 w-8 shrink-0 place-items-center rounded-lg bg-accent-soft text-accent transition-colors group-hover:bg-accent group-hover:text-white",children:(0,s.jsx)(c.A,{className:"h-4 w-4",strokeWidth:1.8})}),(0,s.jsx)("span",{className:"min-w-0 flex-1 text-sm font-medium text-ink",children:"Run a workflow"}),(0,s.jsx)(w.A,{className:"hidden h-4 w-4 shrink-0 -translate-x-1 text-faint opacity-0 transition-all group-hover:translate-x-0 group-hover:text-accent group-hover:opacity-100 sm:block"})]}),(0,s.jsxs)("button",{onClick:function(){let e={uri:"ui://demo/sample",mimeType:"text/html",text:'<!doctype html><meta charset="utf-8">\n<div style="font-family:system-ui,-apple-system,sans-serif;padding:16px;color:#1a1a1a">\n  <h3 style="margin:0 0 6px;font-size:15px">Sample MCP-UI widget</h3>\n  <p style="margin:0 0 14px;font-size:12.5px;color:#666">This HTML came from a tool result and runs in a sandboxed iframe. The buttons post actions back to the chat.</p>\n  <div style="display:flex;gap:8px;flex-wrap:wrap">\n    <button onclick="parent.postMessage({type:\'prompt\',payload:{prompt:\'Explain what an MCP-UI widget is.\'}},\'*\')" style="padding:7px 12px;border:1px solid #d9d4c8;border-radius:8px;background:#fff;font-size:12.5px;cursor:pointer">Ask the agent</button>\n    <button onclick="parent.postMessage({type:\'notify\',payload:{message:\'Hello from the sandboxed widget!\'}},\'*\')" style="padding:7px 12px;border:1px solid #d9d4c8;border-radius:8px;background:#fff;font-size:12.5px;cursor:pointer">Send a notification</button>\n  </div>\n</div>\n<script>parent.postMessage({type:\'ui-size-change\',payload:{height:document.body.scrollHeight+16}},\'*\')<\/script>'},t="demo-".concat(Date.now().toString(36));$(n=>[...n,{role:"assistant",kind:"text",content:"Here's a sample **MCP-UI** widget — it came from a tool result and renders in a sandboxed iframe. Try the buttons; they post actions back to me.",entries:[{kind:"tool_call",ts:Date.now(),id:t,name:"mcp__demo__show_widget",input:{}},{kind:"tool_result",ts:Date.now(),id:t,content:"[ui resource]",uiResources:[e]}]}])},className:"group flex items-center gap-2.5 rounded-xl border border-line bg-surface p-2.5 text-left sm:gap-3 sm:p-3 transition-all duration-200 hover:-translate-y-0.5 hover:border-accent-line hover:bg-accent-soft hover:shadow-[var(--shadow-2)]",children:[(0,s.jsx)("span",{className:"grid h-8 w-8 shrink-0 place-items-center rounded-lg bg-accent-soft text-accent transition-colors group-hover:bg-accent group-hover:text-white",children:(0,s.jsx)(v.A,{className:"h-4 w-4",strokeWidth:1.8})}),(0,s.jsx)("span",{className:"min-w-0 flex-1 text-sm font-medium text-ink",children:"Try an MCP-UI widget"}),(0,s.jsx)(w.A,{className:"hidden h-4 w-4 shrink-0 -translate-x-1 text-faint opacity-0 transition-all group-hover:translate-x-0 group-hover:text-accent group-hover:opacity-100 sm:block"})]})]})]}):(0,s.jsx)(q.Provider,{value:function(e){var t,n,s,a,r;if("link"===e.type&&"string"==typeof(null==(t=e.payload)?void 0:t.url))return void window.open(e.payload.url,"_blank","noopener,noreferrer");if("prompt"===e.type&&"string"==typeof(null==(n=e.payload)?void 0:n.prompt))return void e_(e.payload.prompt);if("notify"===e.type&&"string"==typeof(null==(s=e.payload)?void 0:s.message)){es(e.payload.message.slice(0,160)),window.setTimeout(()=>es(null),4e3);return}return"tool"===e.type&&(null==(a=e.payload)?void 0:a.toolName)?void e_('Run the "'.concat(e.payload.toolName,'" action').concat(e.payload.params&&Object.keys(e.payload.params).length?" with ".concat(JSON.stringify(e.payload.params)):"",".")):"intent"===e.type&&(null==(r=e.payload)?void 0:r.intent)?void e_("".concat(e.payload.intent).concat(e.payload.params&&Object.keys(e.payload.params).length?" — ".concat(JSON.stringify(e.payload.params)):"")):void 0},children:(0,s.jsx)("div",{className:"space-y-4",children:H.map((e,t)=>
1(0,s.jsx)(eo,{msg:e,streaming:Z&&t===H.length-1,onRun:eS,onFeedback:eN},t))})})}),et&&(0,s.jsxs)("div",{className:"ac-rise mx-4 mb-1 flex items-center gap-2 rounded-md border border-line bg-surface-2 px-3 py-2 text-sm text-ink",children:[(0,s.jsx)("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-accent"}),et]}),R.length>0&&(0,s.jsxs)("div",{className:"px-3 py-2.5",children:[(0,s.jsxs)("p",{"data-mono":!0,className:"mb-1.5 flex items-center justify-between text-2xs font-medium uppercase tracking-[.1em] text-faint",children:[(0,s.jsxs)("span",{children:["Select your agent \xb7 ",R.length]}),(0,s.jsx)("span",{className:"text-faint",children:"drag ↔ \xb7 type @"})]}),(0,s.jsx)("div",{ref:ei,onPointerDown:e=>{if("mouse"!==e.pointerType)return;let t=ei.current;t&&(ec.current={down:!0,startX:e.clientX,startScroll:t.scrollLeft,moved:!1})},onPointerMove:e=>{let t=ei.current;if(!t||!ec.current.down)return;let n=e.clientX-ec.current.startX;Math.abs(n)>3&&(ec.current.moved=!0),t.scrollLeft=ec.current.startScroll-n},onPointerUp:()=>{ec.current.down=!1},onPointerLeave:()=>{ec.current.down=!1},className:"ac-noscrollbar flex select-none gap-2 overflow-x-auto pb-0.5 cursor-grab active:cursor-grabbing",children:R.map(e=>(0,s.jsxs)("button",{onClick:()=>{ec.current.moved||Y("@".concat(e.name," "))},title:e.team?"".concat(e.name," \xb7 ").concat(e.team):e.name,className:"flex w-[210px] shrink-0 items-center gap-2.5 rounded-xl border border-line bg-surface p-2.5 text-left transition-colors hover:border-accent-line hover:bg-accent-soft",children:[(0,s.jsx)(D.pn,{type:D.mm[[...e.id].reduce((e,t)=>31*e+t.charCodeAt(0)>>>0,7)%D.mm.length],state:"default",size:28,jumpEvery:0,interactive:!1,draggable:!1,className:"h-7 w-7 shrink-0"}),(0,s.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,s.jsx)("span",{className:"line-clamp-2 text-sm font-semibold leading-snug text-ink",children:e.name}),(0,s.jsx)("span",{"data-mono":!0,className:"block truncate text-2xs text-faint",children:e.team||"agent"})]})]},e.id))})]}),(0,s.jsx)(V,{input:G,setInput:Y,onSend:e_,onStop:function(){var e;null==(e=ee.current)||e.abort()},busy:Z,mode:J,workflows:_,myAgents:R})]})]})]})}function V(e){let{input:t,setInput:n,onSend:r,onStop:l,busy:i,mode:o,workflows:d,myAgents:h}=e,[x,p]=(0,a.useState)(null),[m,f]=(0,a.useState)(""),g=(0,a.useRef)(t);(0,a.useEffect)(()=>{g.current=t},[t]);let b=(0,W.j)(e=>{let t=g.current.replace(/\s*$/,"");n(t?"".concat(t," ").concat(e):e)}),w=(0,a.useRef)(null);(0,a.useEffect)(()=>{let e=w.current;e&&(e.style.height="auto",e.style.height="".concat(Math.min(e.scrollHeight,160),"px"))},[t]);let v=h.filter(e=>e.name.toLowerCase().includes(m)).slice(0,50),C=d.filter(e=>e.name.toLowerCase().includes(m)).slice(0,50);return(0,s.jsxs)("div",{className:"relative border-t border-line px-4 py-3",children:["mention"===x&&v.length>0&&(0,s.jsx)(em,{children:v.map(e=>{var a;return(0,s.jsx)(ef,{onClick:()=>{var s;return s=e.name,void(n(t.replace(/@([\w-]*)$/,"@".concat(s," "))),p(null))},icon:(0,s.jsx)(k.A,{className:"h-3.5 w-3.5 text-faint"}),title:e.name,sub:null!=(a=e.team)?a:""},e.id)})}),"slash"===x&&C.length>0&&(0,s.jsxs)(em,{children:[(0,s.jsx)("p",{"data-mono":!0,className:"px-2.5 pb-1 pt-1.5 text-2xs uppercase tracking-[.1em] text-faint",children:"Run a workflow"}),C.map(e=>(0,s.jsx)(ef,{onClick:()=>{p(null),n(""),r("/".concat(e.name))},icon:(0,s.jsx)(c.A,{className:"h-3.5 w-3.5 text-faint"}),title:e.name,sub:"".concat(e.nodes.length," nodes")},e.id))]}),(0,s.jsx)(M.M_,{active:b.listening,level:.28*!!b.listening,strength:.4,idle:0,className:"block",children:(0,s.jsxs)("div",{"data-tour":"chat-composer",className:"card flex items-end gap-2 p-2",children:[(0,s.jsx)("textarea",{ref:w,value:t,onChange:e=>(function(e){n(e);let t=e.match(/@([\w-]*)$/),s=e.match(/(?:^|\s)\/([\w-]*)$/);t?(p("mention"),f(t[1].toLowerCase())):s?(p("slash"),f(s[1].toLowerCase())):p(null)})(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||x||(e.preventDefault(),r(t)),"Escape"===e.key&&p(null)},rows:1,placeholder:"plan"===o?"Describe a task to preview (no action taken)…":"Ask anything — I'll route it to the right agent…",className:"max-h-40 flex-1 resize-none bg-transparent px-2.5 py-2 text-base text-ink outline-none placeholder:text-faint"}),b.supported&&b.listening&&(0,s.jsxs)("span",{className:"flex shrink-0 items-center gap-1.5 pr-0.5 text-xs font-medium text-accent",children:[(0,s.jsx)("span",{className:"h-2 w-2 rounded-full",style:{background:"var(--err)",animation:"ac-pulse-ring 1.4s var(--ease) infinite"}})," Listening…"]}),b.supported&&(0,s.jsxs)("button",{onClick:b.toggle,title:b.listening?"Listening… tap to 
1stop":"Dictate with your voice","aria-pressed":b.listening,className:"relative grid h-9 w-9 shrink-0 place-items-center rounded-md border transition-colors ".concat(b.listening?"border-transparent bg-accent text-on-accent":"border-line text-ink-2 hover:text-ink"),children:[b.listening&&(0,s.jsx)("span",{"aria-hidden":!0,className:"absolute inset-0 animate-ping rounded-md bg-accent opacity-40"}),(0,s.jsx)("span",{className:"relative",children:b.listening?(0,s.jsx)(j.A,{className:"h-4 w-4"}):(0,s.jsx)(y.A,{className:"h-4 w-4"})})]}),i?(0,s.jsx)("button",{onClick:l,title:"Stop generating","aria-label":"Stop generating",className:"btn btn-accent",children:(0,s.jsx)(u.A,{className:"h-3.5 w-3.5 fill-current"})}):(0,s.jsx)("button",{onClick:()=>r(t),disabled:!t.trim(),title:"Send","aria-label":"Send",className:"btn btn-accent disabled:opacity-40",children:(0,s.jsx)(N.A,{className:"h-4 w-4"})})]})}),(0,s.jsx)("p",{"data-mono":!0,className:"mt-1.5 text-center text-2xs text-faint",children:b.listening?"Listening… speak now":b.error?b.error:"plan"===o?"Plan mode \xb7 preview only":"Enter to send \xb7 just ask, or @ mention \xb7 / workflow"})]})}function Y(e){let{entries:t,live:n}=e,r=(0,a.useContext)(q),l=new Map;for(let e of t)"tool_result"===e.kind&&e.id&&l.set(e.id,e);let i=[];return(t.forEach((e,t)=>{var a,o;"thinking"===e.kind&&e.text.trim()?i.push((0,s.jsx)("p",{className:"text-sm italic leading-relaxed text-faint",children:e.text},t)):"tool_call"===e.kind?i.push((0,s.jsx)(et,{name:e.name,input:e.input,result:e.id?l.get(e.id):void 0,live:n},t)):"tool_result"===e.kind&&(null==(a=e.uiResources)?void 0:a.length)?e.uiResources.forEach((e,n)=>i.push((0,s.jsx)(U.T,{resource:e,onAction:r},"".concat(t,"-ui-").concat(n)))):"tool_result"===e.kind&&(null==(o=e.panes)?void 0:o.length)?e.panes.forEach((e,n)=>i.push((0,s.jsx)(Z,{initial:e},"".concat(t,"-pane-").concat(n)))):"tool_result"===e.kind&&e.connect?i.push((0,s.jsx)(Q,{connect:e.connect},"".concat(t,"-connect"))):"tool_result"===e.kind&&e.confirm?i.push((0,s.jsx)(ee,{action:e.confirm},"".concat(t,"-confirm-").concat(e.confirm.id))):"denied"===e.kind&&i.push((0,s.jsxs)("div",{className:"flex items-center gap-2 rounded-md border border-line px-2.5 py-1.5 text-sm",style:{color:"var(--err)"},children:[(0,s.jsx)(C.A,{className:"h-3.5 w-3.5 shrink-0"})," Blocked: ",(0,s.jsx)("span",{"data-mono":!0,children:es(e.name)})," — ",e.reason]},t))}),0===i.length)?null:(0,s.jsx)("div",{className:"mb-2 space-y-1.5",children:i})}function Z(e){let{initial:t}=e;(0,$.s)();let[n,r]=(0,a.useState)(t),[l,i]=(0,a.useState)(!1);async function o(e){if(!l&&n.screenId){i(!0);try{let t={packId:n.packId,screenId:n.screenId};e&&Object.keys(e).length&&(t.input=e);let s=await fetch("/api/packs/run",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then(e=>e.json()).catch(()=>null);if(null==s?void 0:s.paneId){let e=await fetch("/api/panes/".concat(encodeURIComponent(s.paneId))).then(e=>e.json()).catch(()=>null);(null==e?void 0:e.pane)&&r(e.pane)}}finally{i(!1)}}}return(0,s.jsxs)("div",{className:"rounded-[12px] border border-line p-3 ".concat(l?"opacity-60":""),children:[(0,s.jsx)(H.m,{pane:n,onAction:(e,t)=>{var n;o({...null!=(n=e.params)?n:{},...null!=t?t:{}})}}),(0,s.jsxs)("p",{className:"mt-2 inline-flex items-center gap-1 text-[11px] text-faint",children:[(0,s.jsx)(w.A,{className:"h-3 w-3"})," Saved — this dashboard stays with the conversation."]})]})}function Q(e){let{connect:t}=e,[n,r]=(0,a.useState)("idle");return(0,s.jsxs)("div",{className:"flex items-center gap-2.5 rounded-[10px] border border-line bg-surface-2 px-3 py-2.5 text-[12.5px]",children:[(0,s.jsx)(v.A,{className:"h-4 w-4 shrink-0 text-accent"}),"connected"===n?(0,s.jsxs)("span",{className:"flex items-center gap-1.5 text-ink",children:[(0,s.jsx)(S.A,{className:"h-3.5 w-3.5 text-ok"})," Connected — ask me again and I'll pull your data."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("span",{className:"flex-1 text-ink-2",children:["Connect ",(0,s.jsx)("b",{className:"capitalize text-ink",children:t.service})," so I can read your data."]}),(0,s.jsx)("button",{onClick:function(){if("connecting"===n)return;r("connecting");let e=window.open(t.url,"pack-connect","width=520,height=680"),s=Date.now(),a=setInterval(async()=>{let n=await fetch("/api/connections?view=connected").then(e=>e.json()).catch(()=>null);(Array.isArray(null==n?void 0:n.connected)?n.connected.map(e=>{var t;return"string"==typeof e?e:null!=(t=e.toolkit)?t:""}):[]).includes(t.service)?(clearInterval(a),null==e||e.close(),r("connected")):(e&&e.closed||Date.now()-s>12e4)&&(clearInterval(a),r("idle"))},2500)},disabled:"connecting"===n,className:"btn btn-accent shrink-0 px-2.5 py-1.5 text-[12px] disabled:opacity-50",children:"connecting"===n?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(d.A,{className:"h-3.5 w-3.5 animate-spin"})," Waiting…"]}):t.label})]})]})}function ee(e){let{action:t}=e,[n,r]=(0,a.useState)("pending"),[l,i]=(0,a.useState)(null),[o,c]=(0,a.useState)(t.args),u=Object.entries(t.args);async function h(e){if("pending"!==n)return;r("send"===e?"sending":"pending"),i(null);let s=Object.fromEntries(Object.entries(o).filter(e=>{let[n,s]=e;return s!==t.args[n]}));try{let n=await fetch("/api/chat/actions/".concat(encodeURIComponent(t.id)),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({decision:e,...Object.keys(s).length?{args:s}:{}})}),a=await n.json().catch(()=>({}));if(410===n.status){r("gone"),i("string"==typeof(null==a?void 0:a.error)?a.error:null);return}if(!n.ok){r("failed"),i("".concat("string"==typeof(null==a?void 0:a.error)?a.error:"It didn't go through (HTTP ".concat(n.status,").")," Ask the agent to prepare it again if you still want it."));return}r((null==a?void 0:a.status)==="discarded"?"discarded":"done")}catch(e){r("failed"),i("Couldn't reach the server, so this may not have gone through. Check before asking the agent to prepare it again.")}}let x="pending"!==n;return(0,s.jsxs)("div",{className:"rounded-[12px] border px-3 py-3",style:{borderColor:"color-mix(in srgb, #E0A83A 45%, var(--line))",background:"color-mix(in srgb, #E0A83A 7%, var(--surface))"},children:[(0,s.jsxs)("div",{className:"mb-2 flex items-center gap-2 text-[12.5px]",children:[(0,s.jsx)(C.A,{className:"h-4 w-4 shrink-0",style:{color:"#E0A83A"}}),(0,s.jsx)("span",{className:"min-w-0 flex-1 text-ink",children:"done"===n?(0,s.jsxs)("b",{className:"font-semibold",children:["Done — ",t.label]}):"discarded"===n?(0,s.jsx)("b",{className:"font-semibold",children:"Discarded — nothing was sent"}):"gone"===n?(0,s.jsx)("b",{className:"font-semibold",children:"No longer available"}):"failed"===n?(0,s.jsxs)("b",{className:"font-semibold text-err",children:["Didn't go through — ",t.label]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("b",{className:"font-semibold",children:"Confirm before it runs:"})," ",t.label]})}),(0,s.jsx)("span",{"data-mono":!0,className:"shrink-0 text-2xs text-faint",children:es(t.slug)})]}),"discarded"!==n&&"gone"!==n&&u.length>0&&(0,s.jsx)("div",{className:"space-y-1.5",children:u.map(e=>{let[t,n]=e,a=t.replace(/_/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").trim().toLowerCase(),r=a.charAt(0).toUpperCase()+a.slice(1),l=o[t];
1if("string"!=typeof n)return(0,s.jsxs)("div",{className:"flex gap-2 text-[12px]",children:[(0,s.jsx)("span",{className:"w-28 shrink-0 text-faint",children:r}),(0,s.jsx)("span",{"data-mono":!0,className:"min-w-0 break-words text-ink-2 [overflow-wrap:anywhere]",children:ea(n)})]},t);let i=n.length>80||n.includes("\n");return(0,s.jsxs)("label",{className:"flex flex-col gap-0.5 text-[12px] sm:flex-row sm:gap-2",children:[(0,s.jsx)("span",{className:"w-28 shrink-0 pt-1 text-faint",children:r}),i?(0,s.jsx)("textarea",{value:String(null!=l?l:""),onChange:e=>c(n=>({...n,[t]:e.target.value})),disabled:x,rows:Math.min(10,Math.max(3,String(null!=l?l:"").split("\n").length)),className:"min-w-0 flex-1 resize-y rounded-md border border-line bg-surface px-2 py-1 text-[12.5px] text-ink outline-none focus:border-accent disabled:opacity-70"}):(0,s.jsx)("input",{value:String(null!=l?l:""),onChange:e=>c(n=>({...n,[t]:e.target.value})),disabled:x,className:"min-w-0 flex-1 rounded-md border border-line bg-surface px-2 py-1 text-[12.5px] text-ink outline-none focus:border-accent disabled:opacity-70"})]},t)})}),l&&(0,s.jsx)("p",{role:"alert",className:"mt-2 break-words text-[12px] text-err [overflow-wrap:anywhere]",children:l}),("pending"===n||"sending"===n)&&(0,s.jsxs)("div",{className:"mt-2.5 flex flex-wrap items-center gap-2",children:[(0,s.jsx)("button",{onClick:()=>void h("send"),disabled:"sending"===n,className:"btn btn-accent px-3 py-1.5 text-[12px] disabled:opacity-50",children:"sending"===n?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(d.A,{className:"h-3.5 w-3.5 animate-spin"})," Sending…"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(N.A,{className:"h-3.5 w-3.5"})," Send"]})}),(0,s.jsx)("button",{onClick:()=>void h("discard"),disabled:"sending"===n,className:"btn btn-ghost px-3 py-1.5 text-[12px] disabled:opacity-50",children:"Discard"}),(0,s.jsx)("span",{className:"text-2xs text-faint",children:"Nothing is sent until you press Send."})]})]})}function et(e){let{name:t,input:n,result:r,live:l}=e,[o,c]=(0,a.useState)(!1),u=r?r.isError?"error":"done":l?"running":"done",h=null!=n||null!=r;return(0,s.jsxs)("div",{className:"rounded-md border border-line bg-surface-2/60 px-2.5 py-1.5",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:["running"===u?(0,s.jsx)(d.A,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-accent"}):"error"===u?(0,s.jsx)(A.A,{className:"h-3.5 w-3.5 shrink-0 text-err"}):(0,s.jsx)(i.A,{className:"h-3.5 w-3.5 shrink-0 text-ok"}),(0,s.jsx)(I.A,{className:"h-3 w-3 shrink-0 text-faint"}),(0,s.jsx)("span",{"data-mono":!0,className:"min-w-0 flex-1 truncate text-ink",children:es(t)}),h&&(0,s.jsx)("button",{onClick:()=>c(e=>!e),className:"shrink-0 text-faint hover:text-ink",children:o?(0,s.jsx)(T.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(_.A,{className:"h-3.5 w-3.5"})})]}),o&&h&&(0,s.jsxs)("div",{className:"mt-1.5 space-y-1 border-t border-line pt-1.5",children:[null!=n&&(0,s.jsx)("pre",{className:"max-h-32 overflow-auto rounded bg-surface px-2 py-1 text-2xs leading-relaxed text-ink-2",children:ea(n)}),r&&(0,s.jsx)("pre",{className:"max-h-40 overflow-auto rounded bg-surface px-2 py-1 text-2xs leading-relaxed",style:{color:r.isError?"var(--err)":"var(--ink-2)"},children:er(r.content,1200)})]})]})}function en(e,t,n){return e&&"assistant"!==n&&void 0!==n?/\s$/.test(e)||/^\s/.test(t)?e+t:"".concat(e,"\n\n").concat(t):e+t}function es(e){let t=e.replace(/^mcp__/,"").replace(/__/g," \xb7 ").replace(/_/g," ").toLowerCase().trim();return t.charAt(0).toUpperCase()+t.slice(1)}function ea(e){try{return er(JSON.stringify(e,null,2),800)}catch(t){return String(e)}}function er(e,t){return e.length>t?"".concat(e.slice(0,t),"…"):e}function el(e){let{state:t}=e,n=(0,P.A)();return(0,s.jsx)("span",{className:"mt-0.5 grid h-7 w-7 shrink-0 place-items-center",children:(0,s.jsx)(L.KV,{state:t,size:32,theme:n})})}function ei(e){let{label:t}=e;return(0,s.jsx)("div",{className:"mt-1.5 text-sm text-ink-2",children:t})}function eo(e){var t;let{msg:n,streaming:a,onRun:r,onFeedback:l}=e,i=(0,$.s)();return"confirm"===n.kind?(0,s.jsxs)("div",{className:"flex gap-3",children:[(0,s.jsx)(ex,{}),(0,s.jsxs)("div",{className:"card max-w-[90%] p-3.5",children:[(0,s.jsxs)("div",{className:"mb-1.5 flex items-center gap-2",children:[(0,s.jsx)(c.A,{className:"h-4 w-4 text-accent"}),(0,s.jsx)("span",{className:"text-sm font-semibold text-ink",children:"Run workflow"})]}),(0,s.jsxs)("p",{className:"text-base text-ink-2",children:["Run the ",(0,s.jsx)("b",{className:"text-ink",children:n.content})," workflow? It runs on the canvas and streams results here."]}),(0,s.jsx)("div",{className:"mt-3 flex gap-2",children:(0,s.jsxs)("button",{onClick:()=>n.graphId&&r(n.graphId),className:"btn btn-accent px-3 py-1.5 text-sm",children:[(0,s.jsx)(h.A,{className:"h-3.5 w-3.5"})," Run"]})})]})]}):"no_agent"===n.kind?(0,s.jsxs)("div",{className:"flex gap-3",children:[(0,s.jsx)(ex,{tone:"var(--warn)"}),(0,s.jsxs)("div",{className:"card max-w-[90%] p-3.5",children:[(0,s.jsx)("p",{className:"text-sm font-semibold text-ink",children:"No agent for this yet"}),(0,s.jsx)("p",{className:"mt-1 text-base text-ink-2",children:n.content}),(0,s.jsxs)("button",{onClick:()=>i("Agent Lab"),className:"btn btn-ghost mt-3 px-3 py-1.5 text-sm",children:[(0,s.jsx)(x.A,{className:"h-3.5 w-3.5"})," Create an agent"]})]})]}):"user"===n.role?(0,s.jsx)("div",{className:"flex justify-end",children:(0,s.jsx)("div",{className:"max-w-[85%] rounded-lg rounded-br-[4px] bg-surface-2 px-3.5 py-2.5 text-base leading-relaxed text-ink",children:n.content.split(/(@[\w-]+)/g).map((e,t)=>e.startsWith("@")?(0,s.jsx)("span",{className:"font-semibold text-accent",children:e},t):(0,s.jsx)("span",{children:e},t))})}):(0,s.jsxs)("div",{className:"group flex gap-3",children:[a&&n.agentId?(0,s.jsx)(eh,{agentId:n.agentId,working:!0}):a?(0,s.jsx)(el,{state:function(e,t){if(t)return"searching";if(!e||0===e.length)return"solving";let n=new Set(e.filter(e=>"tool_result"===e.kind&&!!e.id).map(e=>e.id));for(let t=e.length-1;t>=0;t--){let s=e[t];if("tool_call"===s.kind&&(!s.id||!n.has(s.id)))return"connecting"}return"thinking"===e[e.length-1].kind?"solving":"composing"}(n.entries,n.routing)}):(0,s.jsx)(eh,{agentId:n.agentId}),(0,s.jsxs)("div",{className:"min-w-0 max-w-[88%]",children:[n.entries&&n.entries.length>0&&(0,s.jsx)(Y,{entries:n.entries,live:a}),n.content.trim().length>0&&(0,s.jsx)(J.o,{text:n.content,className:"text-base leading-relaxed text-ink"}),a&&(0,s.jsx)(ei,{label:n.routing?"Finding the right agent…":function(e){if(!e||0===e.length)return"Thinking…";let t=new Set(e.filter(e=>"tool_result"===e.kind&&!!e.id).map(e=>e.id));for(let n=e.length-1;n>=0;n--){let s=e[n];if("tool_call"===s.kind&&(!s.id||!t.has(s.id)))return"Running ".concat(es(s.name),"…")}return"thinking"===e[e.length-1].kind?"Thinking…":"Working…"}(n.entries)}),!a&&n.content.trim().length>0&&(0,s.jsxs)("div",{className:"mt-1.5 flex items-center gap-3",children:[(0,s.jsx)(ed,{text:n.content}),(0,s.jsx)(eu,{content:n.content}),n.id&&(0,s.jsx)(ec,{id:n.id,feedback:null!=(t=n.feedback)?t:null,onFeedback:l})]})]})]})}function ec(e){let{id:t,feedback:n,onFeedback:a}=e;return(0,s.jsxs)("div",{className:"flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[(0,s.jsx)("button",{onClick:()=>a(t,"up"===n?null:"up"),title:"Good response",className:"transition-colors ".concat("up"===n?"text-accent":"text-faint hover:text-ink"),children:(0,s.jsx)(O.A,{className:"h-3.5 w-3.5",fill:"up"===n?"currentColor":"none"})}),(0,s.jsx)("button",{onClick:()=>a(t,"down"===n?null:"down"),title:"Bad response",className:"transition-colors ".concat("down"===n?"text-err":"text-faint hover:text-ink"),children:(0,s.jsx)(E.A,{className:"h-3.5 w-3.5",fill:"down"===n?"currentColor":"none"})})]})}function ed(e){let{text:t}=e,[n,r]=(0,a.useState)(!1);async function l(){try{await navigator.clipboard.writeText(t),r(!0),setTimeout(()=>r(!1),1400)}catch(e){}}return(0,s.jsx)("button",{onClick:()=>void l(),className:"flex items-center gap-1 text-2xs text-faint transition-colors hover:text-ink",children:n?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(S.A,{className:"h-3 w-3 text-ok"})," Copied"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(R.A,{className:"h-3 w-3"})," Copy"]})})}
1function eu(e){let{content:t}=e,[n,r]=(0,a.useState)("idle"),[l,i]=(0,a.useState)(null);async function o(){if("creating"!==n&&!l){r("creating");try{let n=t.trim().split("\n")[0].replace(/[*_`#>-]/g,"").trim(),s=n.length>80?n.slice(0,79)+"…":n||"From chat",a=await fetch("/api/issues",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:s,description:t.trim()})}),l=await a.json().catch(()=>({}));if(a.ok&&(null==l?void 0:l.issue)){var e;i(null!=(e=l.issue.identifier)?e:"issue"),r("idle")}else r("failed")}catch(e){r("failed")}}}return l?(0,s.jsxs)("p",{"data-mono":!0,className:"text-2xs text-ok",children:["✓ Created ",l," — track it in Work"]}):(0,s.jsxs)("button",{onClick:()=>void o(),disabled:"creating"===n,className:"flex items-center gap-1 text-2xs text-faint transition-colors hover:text-accent disabled:opacity-50",children:["creating"===n?(0,s.jsx)(d.A,{className:"h-3 w-3 animate-spin"}):(0,s.jsx)(x.A,{className:"h-3 w-3"}),"failed"===n?"Couldn't create — retry":"Create issue"]})}function eh(e){let{agentId:t,working:n=!1}=e;if(!t)return(0,s.jsx)(ex,{});let a=[...t].reduce((e,t)=>31*e+t.charCodeAt(0)>>>0,7)%D.mm.length;return(0,s.jsx)(D.pn,{type:D.mm[a],state:n?"working":"default",size:28,interactive:!1,className:"mt-0.5 h-7 w-7 shrink-0 rounded-md",style:{background:"var(--accent-soft)"}})}function ex(e){let{tone:t="var(--accent)"}=e;return(0,s.jsx)("div",{className:"mt-0.5 grid h-7 w-7 shrink-0 place-items-center rounded-md bg-accent-soft",style:{color:t},children:(0,s.jsx)(b.A,{className:"h-3.5 w-3.5"})})}function ep(e){let{on:t,onClick:n,children:a}=e;return(0,s.jsx)("button",{onClick:n,className:"flex items-center gap-1.5 rounded-sm px-2.5 py-1.5 text-sm transition-colors ".concat(t?"bg-surface-2 text-ink":"text-ink-2 hover:text-ink"),children:a})}function em(e){let{children:t}=e;return(0,s.jsx)("div",{className:"absolute bottom-[calc(100%-4px)] left-4 right-4 z-20 max-h-56 overflow-y-auto rounded-lg border border-line bg-surface p-1 shadow-xl",children:t})}function ef(e){let{onClick:t,icon:n,title:a,sub:r}=e;return(0,s.jsxs)("button",{onClick:t,className:"flex w-full items-center gap-2.5 rounded-sm px-2.5 py-2 text-left hover:bg-surface-2",children:[n,(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate text-base text-ink",children:a}),(0,s.jsx)("span",{"data-mono":!0,className:"text-2xs text-faint",children:r}),(0,s.jsx)(w.A,{className:"h-3 w-3 text-faint"})]})}function eg(e,t){let n=e.slice();for(let e=n.length-1;e>=0;e--)if("assistant"===n[e].role&&"text"===n[e].kind){n[e]={...n[e],content:t};break}return n}},97925:(e,t,n)=>{n.d(t,{j:()=>r});var s=n(53834);function a(){var e,t;let n=window;return null!=(t=null!=(e=n.SpeechRecognition)?e:n.webkitSpeechRecognition)?t:null}function r(e){let[t,n]=(0,s.useState)(!1),[r,l]=(0,s.useState)(!1),[i,o]=(0,s.useState)(null),c=(0,s.useRef)(null),d=(0,s.useRef)(e);(0,s.useEffect)(()=>{d.current=e},[e]),(0,s.useEffect)(()=>(n(null!==a()),()=>{try{var e;null==(e=c.current)||e.abort()}catch(e){}}),[]);let u=(0,s.useCallback)(()=>{try{var e;null==(e=c.current)||e.stop()}catch(e){}l(!1)},[]),h=(0,s.useCallback)(()=>{let e=a();if(!e)return;o(null);let t=new e;t.continuous=!0,t.interimResults=!1,t.lang="undefined"!=typeof navigator&&navigator.language||"en-US",t.onresult=e=>{for(let t=e.resultIndex;t<e.results.length;t++){let n=e.results[t];if(n.isFinal){let e=n[0].transcript.trim();e&&d.current(e)}}},t.onerror=e=>{("not-allowed"===e.error||"service-not-allowed"===e.error)&&o("Microphone access was blocked."),l(!1)},t.onend=()=>l(!1),c.current=t;try{t.start(),l(!0)}catch(e){l(!1)}},[]),x=(0,s.useCallback)(()=>{(r?u:h)()},[r,h,u]);return{supported:t,listening:r,error:i,start:h,stop:u,toggle:x}}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.