@llmnative/agentico 0.24.0 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -31,5 +31,5 @@ ${r.userRequestHeading}
|
|
|
31
31
|
${e}`}function An(e,t){return t?{kind:`handoff`,...t}:{kind:`chat`,message:e}}function jn(e){let t=e.route?.subagentIds??null;return S().filter(n=>e.scopedSubagentId===n.id?!0:n.onlyWhenAnchored?!1:t===null||t.includes(n.id))}function Mn(e){return{buildContext(e){return{cliCatalog:L(jn(e)),handoff:{current:null},collected:{}}},buildPrompt({userGoal:e,pageContext:t},{cliCatalog:n}){return kn(e,n,t)},buildFollowUpPrompt(e,t,{cliCatalog:n}){return`${e}\n\n${On()}\n\n${N().toolsHeading}\n${n}`},parseResponse(e,t,n){let r=n.handoff.current;return n.handoff.current=null,An(e,r)},fallback(){return{kind:`chat`,message:e.unavailable}},describeFallback(t){return t.kind===`chat`?t.message:e.continueWithoutAi},getTools(t,n,r){let i=E({attachmentsRef:r,collected:n.collected,proxyFetch:l.proxyFetch}),a=t.scopedSubagentId?C(t.scopedSubagentId):null,o=t.route?.toolNames??null,s=a?t.route?.toolsOf?.[a.id]??a.crossAgentToolIds??[]:[],c=a?i.filter(e=>s.includes(e.name)):o===null?i:i.filter(e=>o.includes(e.name)),u=jn(t).flatMap(t=>t.commands.map(r=>({name:`${t.id}_${r.name}`,description:`${t.label}: ${r.summary}`,inputSchema:r.inputSchema,describeInvocation:()=>(0,l.interpolate)(e.preparing,{label:t.label}),describeIntent:(0,l.interpolate)(e.collecting,{label:t.label}),async execute(e){let i=t.withCollected?t.withCollected({...e},n.collected):e;return n.handoff.current={subagentId:t.id,command:r.name,params:i},{status:`queued`,note:(0,l.interpolate)(N().handoffQueued,{label:t.label})}}})));return[...c,...u]}}}function Nn(e,t){return e.deriveHistoryTitle?.(t)??e.label}function Pn({manifest:e,result:t,meta:n,taskId:r,initiallyApplied:i,onApplied:a,extraDestinations:o}){let s=Q(),c=$(),f=c.scope,p=(0,l.useProxy)(),[m,h]=(0,u.useState)(null),[g,_]=(0,u.useState)(new Set(i??[])),[v,y]=(0,u.useState)(null),b=ce(),x=new Map;e.destinationIds.forEach(e=>{let t=b[e];t&&x.set(e,t)}),(o??[]).forEach(e=>x.set(e.id,e)),x.set(V.id,V);let S=Array.from(x.values()),C=async i=>{h(i),y(null);try{let o=x.get(i);if(!o)throw Error((0,l.interpolate)(s.unknownDestination,{id:i}));if(i!==`json-export`&&!f)throw Error(s.destinationNoScope);let u=await o.apply(t,{scopeId:f?.id??``,dataProvider:f?.dataProvider,storageProvider:f?.storageProvider??null,proxyFetch:p},n);_(e=>new Set(e).add(i)),a?.(i),u?.id&&c.commitEntityChat(e.id,u.id,r,f?.id,n,Nn(e,n))}catch(e){y(e instanceof Error?e.message:String(e))}finally{h(null)}};return(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:s.destinationPickerTitle}),(0,d.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:S.map(e=>(0,d.jsx)(`button`,{type:`button`,disabled:m!==null,onClick:()=>void C(e.id),className:`cursor-pointer rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-60`,children:m===e.id?s.destinationApplying:`${g.has(e.id)?`✓ `:``}${e.id===`json-export`?s.exportJson:e.label}`},e.id))}),v&&(0,d.jsx)(`p`,{className:`text-xs text-destructive`,children:v})]})}var Fn={};function In(e){Object.assign(Fn,e)}function Ln(e){return Fn[e]}function Rn({result:e}){let[t,n]=(0,u.useState)(!1);return(0,d.jsxs)(`div`,{className:`relative cursor-pointer rounded-md border border-border/60 ${t?`max-h-80 overflow-y-auto`:`max-h-28 overflow-hidden`}`,onClick:()=>n(e=>!e),title:t?`Clic per comprimere`:`Clic per espandere`,children:[(0,d.jsx)(l.Code,{language:`json`,showCopy:t,background:`transparent`,className:`!text-[11px]`,children:JSON.stringify(e,null,2)}),!t&&(0,d.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 bottom-0 h-6 bg-gradient-to-t from-muted/30 to-transparent`})]})}function zn(e,t,n){return e.length===0?null:{id:`live-component`,label:`Applica al componente aperto`,async apply(r){e.forEach(e=>e.onResult?.(r,t,n))}}}var Bn={};function Vn(e){Object.assign(Bn,e)}function Hn(e){return Bn[e]}function Un(e,t=6e3){let n=e.filter(e=>(e.kind===`user`||e.kind===`thinking`)&&e.detail?.trim()&&!we(e)).map(e=>`${e.kind===`user`?`Person`:`Agent`}: ${e.detail.trim()}`).join(`
|
|
32
32
|
|
|
33
33
|
`);return n.length>t?`${n.slice(0,t*.7)}\n\n[…]\n\n${n.slice(-t*.3)}`:n}function Wn(e){return(e.trim().split(`
|
|
34
|
-
`).map(e=>e.trim()).find(Boolean)??``).replace(/^(title|titolo)\s*:\s*/i,``).replace(/^#+\s*/,``).replace(/^["'«“]+|["'»”]+$/g,``).replace(/[.。]+$/,``).trim().slice(0,80)}function Gn(e,t){try{return e.definition.executor?.catalogProviders?.(e.toParams(t))}catch{return}}function Kn(e,t,n,r,i){let a=Gn(e,t),o=e=>{let t=e?(0,l.parseAIModelRef)(e):null;return!(!t||!i[t.provider]||a&&!a.includes(t.provider))};return o(n)?n:Object.values(r).flat().map(e=>e.id).find(o)}function qn(e){let t=(0,l.useAIProviderRegistry)()?.registry??{},{modelsByProvider:n,selectedModel:r}=Sn(),{settings:i}=ct(),a=(0,u.useRef)({registry:t,modelsByProvider:n,selectedModel:r,enabled:i.chatTitles});a.current={registry:t,modelsByProvider:n,selectedModel:r,enabled:i.chatTitles};let o=(0,u.useRef)(new Set),s=(0,u.useCallback)(async(t,n,r)=>{if(!e||!a.current.enabled)return!1;let i=ve(e,t,n),s=C(t),c=`${e}:${t}:${n}`;if(!i||!s?.autoTitle||i.name||!Ce(i)||o.current.has(c))return!1;let{registry:u,modelsByProvider:d,selectedModel:f}=a.current,p=Kn(s,i.params,r??f,d,u),m=p?(0,l.parseAIModelRef)(p):null;if(!m)return!1;o.current.add(c);try{let r=await u[m.provider].complete({prompt:N().chatTitle.replace(`{chat}`,Un(i.activity)),model:m.model,history:[]}),a=r&&r.type===`text`?Wn(r.text):``;return a?Te(e,t,n,a,`model`):!1}catch{return!1}finally{o.current.delete(c)}},[e]),c=Object.keys(n).length>0;return(0,u.useEffect)(()=>{e&&c&&!Jn.has(e)&&(Jn.add(e),(async()=>{for(let t of De(e)){let n=C(t.subagentId);if(n?.autoTitle){if(n.definition.conversational&&!Ce(t)){Ee(e,t.subagentId,t.entityId);continue}t.name||await s(t.subagentId,t.entityId)}}})())},[e,c,s]),s}var Jn=new Set,Yn=()=>({});function Xn({manifest:e,params:t,extraDestinations:n,precedingActivity:r,taskId:i,resumeSeed:a,model:o,openingMessage:s}){let c=$(),f=Dn(e.definition,{defaultEnabled:!0,...c.person?{author:c.person}:{}}),p=e.thread?.(t)||void 0,m=e.speaker?.(t),h=c.scope,g=(0,l.useProxy)(),_=(0,u.useRef)(i??`subagent-${e.id}-${crypto.randomUUID()}`).current,[v,y]=(0,u.useState)(null),b=t=>{e.definition.conversational||y(t)},[x,S]=(0,u.useState)([]),[C,w]=(0,u.useState)(null),T=Ln(e.id),E=T?.kind===`selection`?T:null,[D,ee]=(0,u.useState)(null),O=(0,u.useRef)(!1),k=(0,u.useRef)(0),A=(0,u.useRef)(null);v&&v!==A.current&&(A.current=v,k.current=(r?.length??0)+f.activity.length);let j=(0,u.useRef)(!1),M=f.remote||!f.hasProviders||f.selectedModel!==``;(0,u.useEffect)(()=>{!O.current&&M&&(O.current=!0,a?(R.current=!0,f.resume(e.toParams(t),a)):(o&&f.setSelectedModel(o),f.run(e.toParams(t),{model:o,openingMessage:s}).then(e=>{e&&b(e)})))},[M]),(0,u.useEffect)(()=>{if(!v||!h)return;let n=e.autoApplyDestinationIds??[],r=c.componentAnchors.find(t=>t.subagentId===e.id&&t.pinnedEntityId)?.pinnedEntityId,i=ce();n.forEach(n=>{let a=i[n];a&&(w(null),a.apply(v,{scopeId:h.id,dataProvider:h.dataProvider,storageProvider:h.storageProvider,proxyFetch:g},{...t,pinnedEntityId:r}).then(n=>{n?.id&&c.commitEntityChat(e.id,n.id,_,h.id,t,Nn(e,t))}).catch(e=>w(e instanceof Error?e.message:String(e))))})},[v,f.activity,h]),(0,u.useEffect)(()=>{v&&E&&ee(E.defaultSelection(v))},[v,E]);let N=(e,t)=>{ee(n=>n&&{...n,[e]:t})},P=e=>b(e),te=(0,u.useMemo)(()=>v&&E&&D?E.applySelection(v,D):v,[v,E,D]),F=(0,u.useMemo)(()=>c.componentAnchors.filter(t=>t.subagentId===e.id&&t.onResult),[c.componentAnchors,e.id]),ne=(0,u.useMemo)(()=>zn(F,t,_),[F,t,_]),I=(0,u.useMemo)(()=>ne?[ne,...n??[]]:n,[ne,n]),L=e.chatEntityId?.(t),re=qn(h?.id),ie=(0,u.useRef)(!1),R=(0,u.useRef)(!1);(0,u.useEffect)(()=>{let n=!ie.current&&f.running,i=ie.current&&!f.running;if(ie.current=f.running,!n&&!i||!L||!h)return;if(R.current){i&&(R.current=!1);return}let a=f.snapshot();if(!a)return;let o=[...r??[],...a.activity];e.autoTitle&&e.definition.conversational&&!Ce({activity:o})||(ye({scopeId:h.id,subagentId:e.id,entityId:L,params:t,title:Nn(e,t),history:a.history,activity:o}),i&&e.autoTitle&&re(e.id,L,f.selectedModel))},[f.running]);let z=f.activity.flatMap(e=>(e.parts??[]).flatMap(e=>e.type===`card`&&e.outcome?[`${e.id}:${e.outcome.status}`]:[])).join(`,`),B=(0,u.useRef)(z);(0,u.useEffect)(()=>{if(z===B.current||(B.current=z,!z||!L||!h||f.running||R.current))return;let n=f.snapshot();if(!n)return;let i=[...r??[],...n.activity];e.autoTitle&&e.definition.conversational&&!Ce({activity:i})||ye({scopeId:h.id,subagentId:e.id,entityId:L,params:t,title:Nn(e,t),history:n.history,activity:i})},[z]);let ae=()=>{j.current=!0,f.running&&f.stop(),c.closeTask(_)},oe=(0,u.useRef)(Hn(e.id)??Yn).current,V=oe({params:t,taskId:_,running:f.running,close:ae}),se=e=>{S(t=>t.includes(e)?t:[...t,e])};return(0,u.useEffect)(()=>{j.current||c.openTask({id:_,title:Nn(e,t),icon:e.icon,agent:f,onApplied:e=>b(e),precedingActivity:r,panelExtraAnchorIndex:k.current,onDismiss:ae,...p?{thread:p}:{},...m?{speaker:m}:{},...L?{savedToDisk:!0}:{},panelActions:V.content,composerActions:V.actions,composerCommands:V.commands,panelExtra:v?(0,d.jsxs)(d.Fragment,{children:[E&&D?(0,d.jsx)(E.Report,{result:v,selection:D,onChange:N}):T?.kind===`editable`?(0,d.jsx)(T.Report,{result:v,onResultChange:P}):(0,d.jsx)(Rn,{result:te}),C&&(0,d.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Salvataggio automatico non riuscito: `,C]}),(0,d.jsx)(Pn,{manifest:e,result:te,meta:t,taskId:_,initiallyApplied:x,onApplied:se,extraDestinations:I})]}):void 0})},[f.activity,f.running,f.error,f.canContinue,f.selectedModel,f.modelsByProvider,f.hasProviders,f.remoteModels,c.openTask,c.componentAnchors,_,e,t,v,te,D,x,n,r,C,V.content,V.actions,V.commands]),(0,u.useEffect)(()=>()=>{c.closeTask(_)},[c.closeTask,_]),null}function Zn({userGoal:e}){let t=Q(),n=(0,u.useMemo)(()=>Mn({unavailable:t.orchestratorUnavailable,continueWithoutAi:t.orchestratorContinueWithoutAi,preparing:t.orchestratorPreparing,collecting:t.orchestratorCollecting}),[]),r=$(),i=Dn(n,{defaultEnabled:!0,...r.person?{author:r.person}:{}}),[a,o]=(0,u.useState)(null),s=(0,u.useRef)(!1),c=!i.hasProviders||i.selectedModel!==``,l=(0,u.useRef)(r.pendingExtraDestinations),f=(0,u.useRef)(r.pendingAttachments),p=(0,u.useRef)(r.pendingModel),m=(0,u.useRef)(r.pendingScopedSubagentId??r.scopedSubagentId??void 0),h=(0,u.useRef)(r.pendingCarryOver),g=(0,u.useRef)(!1),_=e=>{e&&typeof e==`object`&&e.kind===`handoff`&&(o(e),r.closeTask(yt))};(0,u.useEffect)(()=>{!s.current&&c&&(s.current=!0,p.current&&i.setSelectedModel(p.current),i.run({userGoal:e,pageContext:r.pageContext,scopedSubagentId:m.current??null,route:r.route?{subagentIds:r.route.subagentIds,toolNames:r.route.toolNames,toolsOf:r.route.toolsOf}:null},{attachments:f.current,model:p.current,openingMessage:e}).then(e=>{e&&_(e)}))},[c]),(0,u.useEffect)(()=>{g.current||r.openTask({id:yt,title:`Agentico`,icon:`bot`,agent:i,onApplied:_,scopedSubagentId:m.current,precedingActivity:h.current?.activity,onDismiss:()=>{g.current=!0,i.running&&i.stop(),r.closeTask(yt)}})},[i.activity,i.running,i.error,i.canContinue,i.selectedModel,i.modelsByProvider,i.hasProviders,r.openTask]),(0,u.useEffect)(()=>()=>{r.closeTask(yt)},[r.closeTask]);let v=(0,u.useMemo)(()=>[...h.current?.activity??[],...i.activity],[i.activity]);if(!a)return null;let y=C(a.subagentId);return y?(0,d.jsx)(Xn,{manifest:y,params:a.params,extraDestinations:l.current,model:p.current||void 0,taskId:h.current?.taskId,precedingActivity:v}):null}function Qn({manifest:e,extraDestinations:t}){let n=$(),r=Dn(e.definition,{defaultEnabled:!1,...n.person?{author:n.person}:{}}),i=Q(),a=(0,u.useRef)(`manual-${e.id}-${crypto.randomUUID()}`).current,[o,s]=(0,u.useState)(null),[c,f]=(0,u.useState)([]),p=Ln(e.id),m=p?.kind===`selection`?p:null,[h,g]=(0,u.useState)(null),[_,v]=(0,u.useState)(null),y=(0,u.useRef)(!1),b=t=>{if(!e.manualEntry)return;let n;try{n=e.manualEntry.fromRawText(t)}catch(e){console.error(`[ManualEntryRunner] manualEntry.fromRawText ha rifiutato il testo:`,e);return}v(n),f([]),r.run(n,{openingMessage:t}).then(e=>{e&&s(e)})};(0,u.useEffect)(()=>{o&&m&&g(m.defaultSelection(o))},[o,m]);let x=(e,t)=>{g(n=>n&&{...n,[e]:t})},S=e=>s(e),C=(0,u.useMemo)(()=>o&&m&&h?m.applySelection(o,h):o,[o,m,h]),w=e=>{f(t=>t.includes(e)?t:[...t,e])},T=(0,u.useMemo)(()=>n.componentAnchors.filter(t=>t.subagentId===e.id&&t.onResult),[n.componentAnchors,e.id]),E=(0,u.useMemo)(()=>_?zn(T,_,a):null,[T,_,a]),D=(0,u.useMemo)(()=>E?[E,...t??[]]:t,[E,t]);return(0,u.useEffect)(()=>{y.current||n.openTask({id:a,title:e.label,icon:e.icon,agent:r,onApplied:e=>s(e),manualEntry:e.manualEntry?{prompt:e.manualEntry.prompt,onSubmit:b}:void 0,onDismiss:()=>{y.current=!0,r.running&&r.stop(),n.closeTask(a)},panelExtra:o?(0,d.jsxs)(`div`,{className:`space-y-2`,children:[m&&h?(0,d.jsx)(m.Report,{result:o,selection:h,onChange:x}):p?.kind===`editable`?(0,d.jsx)(p.Report,{result:o,onResultChange:S}):(0,d.jsx)(Rn,{result:C}),(0,d.jsx)(Pn,{manifest:e,result:C,meta:_??{},taskId:a,initiallyApplied:c,onApplied:w,extraDestinations:D}),r.hasProviders&&(0,d.jsx)(l.ActionButton,{label:i.resumeWithAi,variant:`outline-secondary`,className:`text-xs`,onClick:()=>{_&&n.resumeWithAI(e.id,_,t)}})]}):void 0})},[r.activity,r.running,r.error,r.hasProviders,n.componentAnchors,o,C,h,c,_]),(0,u.useEffect)(()=>()=>{n.closeTask(a)},[]),null}function $n({title:e,meta:t,action:n}){return(0,d.jsxs)(`div`,{role:`separator`,"aria-label":e,className:`my-3 flex items-center gap-2 text-[11px] text-muted-foreground`,children:[(0,d.jsx)(`span`,{className:`h-px flex-1 bg-border`}),(0,d.jsxs)(`span`,{className:`flex min-w-0 max-w-[75%] flex-col items-center text-center`,children:[(0,d.jsx)(`span`,{className:`max-w-full truncate font-medium text-foreground`,children:e}),t&&(0,d.jsx)(`span`,{children:t}),n]}),(0,d.jsx)(`span`,{className:`h-px flex-1 bg-border`})]})}function er({chat:e,thread:t,from:n,showEvents:r}){let i=Tt(t,n,e.savedAt,r);return(0,d.jsx)(Zt,{activity:e.activity,pinUserMessages:!1,speaker:C(e.subagentId)?.speaker?.(e.params),events:i})}function tr({scopeId:e,thread:t,taskId:n,scrollRef:r,onLoad:i,onContinue:a,busy:o=!1,showEvents:s=!0}){let c=Q(),{locale:f}=(0,l.useI18n)(),[p,m]=(0,u.useState)(0);(0,u.useEffect)(()=>J(()=>m(e=>e+1)),[]);let h=(0,u.useMemo)(()=>Ae(e,t,n),[e,t,n,p]),[g,_]=(0,u.useState)(0);(0,u.useEffect)(()=>_(0),[n,t]);let v=g<h.length,y=(0,u.useRef)(null),b=()=>{let e=r.current;e&&(y.current={height:e.scrollHeight,top:e.scrollTop}),i?.(),_(e=>Math.min(e+1,h.length))},x=(0,u.useRef)(b);x.current=b,(0,u.useLayoutEffect)(()=>{let e=r.current,t=y.current;y.current=null,e&&t&&(e.scrollTop=t.top+(e.scrollHeight-t.height))},[g,r]);let S=(0,u.useRef)(null);if((0,u.useEffect)(()=>{let e=r.current,t=S.current;if(!e||!t||!v||typeof IntersectionObserver>`u`)return;let n=e.scrollTop,i=!1,a=()=>{e.scrollTop<n&&(i=!0),n=e.scrollTop};e.addEventListener(`scroll`,a,{passive:!0});let o=new IntersectionObserver(e=>{i&&e.some(e=>e.isIntersecting)&&(i=!1,x.current())},{root:e,rootMargin:`40px 0px 0px 0px`});return o.observe(t),()=>{e.removeEventListener(`scroll`,a),o.disconnect()}},[r,v,g]),!h.length)return null;let C=e=>new Date(e).toLocaleString(f,{dateStyle:`medium`,timeStyle:`short`}),w=h.slice(0,g).reverse(),T=e=>{let t=h[h.indexOf(e)+1];return t?t.savedAt:Z(e)};return(0,d.jsxs)(`div`,{children:[v&&(0,d.jsx)(`div`,{ref:S,className:`flex justify-center pb-1`,children:(0,d.jsx)(l.ActionButton,{icon:`history`,label:c.earlierSession,variant:`link`,className:`text-xs`,onClick:b})}),w.map(e=>(0,d.jsxs)(`section`,{"aria-label":X(e),children:[(0,d.jsx)($n,{title:X(e),meta:(0,l.interpolate)(c.sessionOf,{at:C(Z(e))}),action:(0,d.jsx)(l.ActionButton,{label:c.continueSession,variant:`link`,className:`text-[11px]`,disabled:o,onClick:()=>a(e)})}),(0,d.jsx)(er,{chat:e,thread:t,from:T(e),showEvents:s})]},`${e.subagentId}:${e.entityId}`)),g>0&&(0,d.jsx)($n,{title:c.thisSession})]})}function nr(){return(0,u.useMemo)(()=>{let e=S().map(e=>({id:e.id,label:e.label,description:e.description,onlyWhenAnchored:e.onlyWhenAnchored,crossAgentToolIds:e.crossAgentToolIds})),t=E({attachmentsRef:void 0,collected:{},proxyFetch:l.proxyFetch}).map(e=>({name:e.name,description:e.description}));return{subagents:e,tools:t,toolNames:t.map(e=>e.name)}},[])}var rr={"invalid-pattern":`routingIssueInvalidPattern`,"duplicate-id":`routingIssueDuplicateId`,"missing-id":`routingIssueMissingId`,"unknown-subagent":`routingIssueUnknownSubagent`,"unknown-tool":`routingIssueUnknownTool`,"anchored-subagent":`routingIssueAnchoredSubagent`};function ir(e,t){return(0,l.interpolate)(e[rr[t.code]],{detail:t.detail??``})}function ar(e){let t=e.replace(/[_-]+/g,` `).trim();return t.charAt(0).toUpperCase()+t.slice(1)}function or({names:e}){return(0,d.jsx)(d.Fragment,{children:e.map(e=>(0,d.jsx)(l.Badge,{variant:`info`,children:ar(e)},e))})}var sr=e=>e instanceof Error?e.message:String(e);function cr({t:e,issues:t}){return(0,d.jsx)(d.Fragment,{children:t.map((t,n)=>(0,d.jsx)(`p`,{className:t.level===`error`?`text-xs text-destructive`:`text-xs text-warning`,children:ir(e,t)},n))})}function lr({onOpen:e,children:t}){return e?(0,d.jsx)(`button`,{type:`button`,className:`block w-full rounded-lg text-left transition hover:shadow-md focus:outline-none focus-visible:ring-2 focus-visible:ring-primary`,onClick:e,children:(0,d.jsx)(l.Card,{children:t})}):(0,d.jsx)(l.Card,{children:t})}function ur(){let e=Q(),{route:t,routing:n}=$(),r=nr(),[i,a]=(0,u.useState)(null);return{t:e,route:t,state:n,known:r,persist:async t=>{if(n.save){a(null);try{await n.save(t)}catch(t){throw a((0,l.interpolate)(e.routingSaveError,{error:sr(t)})),t}}},notices:(0,d.jsxs)(d.Fragment,{children:[n.error&&(0,d.jsx)(l.Alert,{variant:`warning`,children:(0,l.interpolate)(e.routingLoadError,{error:n.error})}),i&&(0,d.jsx)(l.Alert,{variant:`danger`,onClose:()=>a(null),children:i}),!n.save&&n.path!==null&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.routingReadOnly}),n.path===null&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.routingNoRouting})]})}}function dr({title:e,titleBefore:t,onClose:n,onSave:r,onRestore:i,errors:a,children:o}){let s=Q(),[c,f]=(0,u.useState)(!1);return(0,d.jsx)(l.Modal,{title:t?(0,d.jsxs)(`span`,{className:`flex items-center gap-3 [&_form]:m-0`,children:[t,(0,d.jsx)(`span`,{children:e})]}):e,position:`right`,size:`md`,onClose:n,footer:(0,d.jsxs)(d.Fragment,{children:[i&&(0,d.jsx)(l.ActionButton,{variant:`outline-secondary`,icon:`rotate-ccw`,label:s.routingRestore,onClick:()=>void i(),disabled:c,className:`mr-auto`}),(0,d.jsx)(l.ActionButton,{variant:`primary`,label:s.routingSave,onClick:async()=>{f(!0);try{await r()}finally{f(!1)}},disabled:c}),(0,d.jsx)(l.ActionButton,{variant:`link`,label:s.routingCancel,onClick:n})]}),children:(0,d.jsxs)(`div`,{className:`space-y-4`,children:[o,a.map((e,t)=>(0,d.jsx)(`p`,{className:`text-sm text-destructive`,children:e},t))]})})}function fr({t:e,subagent:t,routing:n,defaults:r,modified:i,known:a,onSave:o,onClose:s}){let c=n.subagents?.[t.id],f=(0,u.useRef)(0),p=e=>({key:f.current++,value:e}),[m,h]=(0,u.useState)(!c?.paths),[g,_]=(0,u.useState)(()=>(c?.paths??[]).map(p)),[v,y]=(0,u.useState)(()=>c?.tools??t.crossAgentToolIds??[]),[b,x]=(0,u.useState)($().routing.path??``),[S,C]=(0,u.useState)([]),w=Object.entries(n.tools??{}).filter(([,e])=>e.everywhere).map(([e])=>e),T=g.map(e=>e.value.trim()).filter(Boolean),E=(0,u.useMemo)(()=>({everywhere:m?`true`:``,tools:v,tryPath:b,...Object.fromEntries(g.map(e=>[`path_${e.key}`,e.value]))}),[]),D=async()=>{let r={...n,subagents:{...n.subagents,[t.id]:{...m?{}:{paths:T},tools:v.filter(e=>!w.includes(e))}}},i=Qe(r,{subagents:a.subagents,toolNames:a.toolNames}).filter(e=>e.where===`subagent`&&e.key===t.id&&e.level===`error`);if(i.length>0){C(i.map(t=>ir(e,t)));return}try{await o(r),s()}catch(t){C([(0,l.interpolate)(e.routingSaveError,{error:sr(t)})])}},ee=async()=>{try{await o({...n,subagents:{...n.subagents,[t.id]:r.subagents?.[t.id]??{}}}),s()}catch(t){C([(0,l.interpolate)(e.routingSaveError,{error:sr(t)})])}},O=b.trim()?Be(m?void 0:T,b.trim()):null;return(0,d.jsxs)(dr,{title:(0,l.interpolate)(e.routingEditOf,{label:t.label}),onClose:s,onSave:D,onRestore:i?ee:null,errors:S,children:[(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t.description}),t.onlyWhenAnchored&&(0,d.jsx)(l.Alert,{variant:`info`,children:(0,l.interpolate)(e.routingIssueAnchoredSubagent,{detail:t.label})}),(0,d.jsx)(l.Form,{appearance:`empty`,showNotice:!1,defaultValues:E,children:(0,d.jsxs)(`div`,{className:`space-y-4`,children:[(0,d.jsx)(l.Switch,{name:`everywhere`,label:e.routingFieldEverywhere,valueChecked:`true`,onChange:({value:e})=>h(!!e)}),!m&&(0,d.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,d.jsx)(`legend`,{className:`text-sm font-medium`,children:e.routingFieldPaths}),(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.routingFieldPathsFeedback}),g.length===0&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.routingNowhere}),g.map(t=>(0,d.jsxs)(`div`,{className:`flex items-end gap-1`,children:[(0,d.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,d.jsx)(l.String,{name:`path_${t.key}`,placeholder:`^/sites/[^/]+/pages/[^/]+$`,onChange:({value:e})=>_(n=>n.map(n=>n.key===t.key?{...n,value:String(e??``)}:n))})}),(0,d.jsx)(l.ActionButton,{icon:`x`,variant:`link`,title:e.routingRemovePath,ariaLabel:e.routingRemovePath,onClick:()=>_(e=>e.filter(e=>e.key!==t.key))})]},t.key)),(0,d.jsx)(l.ActionButton,{icon:`plus`,variant:`outline-secondary`,label:e.routingAddPath,onClick:()=>_(e=>[...e,p(``)])})]}),(0,d.jsx)(l.String,{name:`tryPath`,label:e.routingTryPath,feedback:e.routingTryPathFeedback,onChange:({value:e})=>x(String(e??``))}),O!==null&&(0,d.jsx)(l.Badge,{variant:O?`success`:`secondary`,children:O?e.routingOffered:e.routingNotOffered}),(0,d.jsx)(l.Checklist,{name:`tools`,label:e.routingFieldTools,options:a.tools.map(e=>({value:e.name,label:ar(e.name)})),onChange:({value:e})=>y(Array.isArray(e)?e.map(String):e?[String(e)]:[])}),w.length>0&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:(0,l.interpolate)(e.routingToolsEverywhereNote,{tools:w.map(ar).join(`, `)})})]})})]})}function pr({text:e}){return(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e})}function mr(){let{routing:e}=$(),[t,n]=(0,u.useState)(!1),[r,i]=(0,u.useState)(e.path??``),a=r.trim();return{open:t,path:r,setPath:i,filter:t&&a||null,toggle:()=>n(e=>!e)}}function hr({t:e,intro:t,tryPath:n,children:r}){return(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,d.jsx)(`p`,{className:`min-w-0 flex-1 text-xs text-muted-foreground`,children:t}),(0,d.jsx)(l.ActionButton,{icon:`search`,label:e.routingTryPath,variant:n.open?`primary`:`outline-secondary`,ariaLabel:e.routingTryPath,onClick:n.toggle}),r]})}function gr({t:e,tryPath:t,count:n,total:r}){return t.open?(0,d.jsx)(l.Form,{appearance:`empty`,showNotice:!1,defaultValues:{tryPath:t.path},children:(0,d.jsx)(l.String,{name:`tryPath`,placeholder:`/sites/acme/en/pages/home`,feedback:t.filter?(0,l.interpolate)(e.routingTryPathCount,{count:String(n),total:String(r)}):e.routingTryPathFeedback,onChange:({value:e})=>t.setPath(String(e??``))})}):null}function _r({onStack:e}){let{t,route:n,state:r,known:i,persist:a,notices:o}=ur(),s=mr(),c=s.filter===null?i.subagents:i.subagents.filter(e=>!e.onlyWhenAnchored&&Be(r.routing.subagents?.[e.id]?.paths,s.filter)),[f,p]=(0,u.useState)(null),m=(0,u.useMemo)(()=>Qe(r.routing,i),[r.routing,i]),h=t=>{p(t),e?.(t!==null)};return(0,d.jsxs)(`div`,{className:`space-y-4`,children:[o,(0,d.jsx)(hr,{t,intro:t.routingSubagentsIntro,tryPath:s}),(0,d.jsx)(gr,{t,tryPath:s,count:c.length,total:i.subagents.length}),s.filter!==null&&c.length===0&&(0,d.jsx)(pr,{text:t.routingNoMatch}),c.map(e=>{let i=r.routing.subagents?.[e.id]?.paths,a=Ue(r.routing,e),o=n&&s.filter===null?n.subagentIds.includes(e.id)&&!e.onlyWhenAnchored:null;return(0,d.jsx)(lr,{onOpen:r.save?()=>h(e):null,children:(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,d.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,d.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.id}),r.changes.subagents?.[e.id]&&(0,d.jsx)(l.Badge,{variant:`warning`,children:t.routingModified}),e.onlyWhenAnchored?(0,d.jsx)(l.Badge,{variant:`info`,className:`ml-auto`,children:t.routingOnlyAnchored}):o!==null&&(0,d.jsx)(l.Badge,{variant:o?`success`:`secondary`,className:`ml-auto`,children:o?t.routingOffered:t.routingNotOffered})]}),(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}),(0,d.jsxs)(`div`,{className:`grid grid-cols-[7rem_1fr] gap-1 text-xs`,children:[(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:t.routingWhere}),(0,d.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[!i&&(0,d.jsx)(`span`,{children:t.routingEverywhere}),i?.length===0&&(0,d.jsx)(`span`,{children:t.routingNowhere}),i?.map((e,t)=>(0,d.jsx)(`code`,{className:`break-all rounded bg-muted px-1.5 py-0.5`,children:e},t))]}),(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:t.routingUses}),(0,d.jsxs)(`span`,{className:`flex flex-wrap gap-1`,children:[a.length===0&&(0,d.jsx)(`span`,{children:t.routingNoTools}),(0,d.jsx)(or,{names:a})]})]}),(0,d.jsx)(cr,{t,issues:m.filter(t=>t.where===`subagent`&&t.key===e.id)})]})},e.id)}),f&&(0,d.jsx)(fr,{t,subagent:f,routing:r.routing,defaults:r.defaults,modified:!!r.changes.subagents?.[f.id],known:i,onSave:a,onClose:()=>h(null)})]})}function vr({t:e,tool:t,routing:n,known:r,onSave:i,onClose:a}){let o=r.subagents.filter(e=>(n.subagents?.[e.id]?.tools??e.crossAgentToolIds??[]).includes(t.name)).map(e=>e.id),[s,c]=(0,u.useState)(!!n.tools?.[t.name]?.everywhere),[f,p]=(0,u.useState)(o),[m,h]=(0,u.useState)([]),g=(0,u.useMemo)(()=>({everywhere:s?`true`:``,users:f}),[]);return(0,d.jsxs)(dr,{title:(0,l.interpolate)(e.routingEditOf,{label:ar(t.name)}),onClose:a,onSave:async()=>{let o={...n.subagents};for(let e of r.subagents){let r=n.subagents?.[e.id]?.tools??e.crossAgentToolIds??[],i=f.includes(e.id);i!==r.includes(t.name)&&(o[e.id]={...n.subagents?.[e.id],tools:i?[...r,t.name]:r.filter(e=>e!==t.name)})}let c={...n.tools,[t.name]:{everywhere:s}};try{await i({...n,subagents:o,tools:c}),a()}catch(t){h([(0,l.interpolate)(e.routingSaveError,{error:sr(t)})])}},errors:m,children:[(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t.description}),(0,d.jsx)(l.Form,{appearance:`empty`,showNotice:!1,defaultValues:g,children:(0,d.jsxs)(`div`,{className:`space-y-4`,children:[(0,d.jsx)(l.Switch,{name:`everywhere`,label:e.routingFieldAllSubagents,valueChecked:`true`,onChange:({value:e})=>c(!!e)}),!s&&(0,d.jsx)(l.Checklist,{name:`users`,label:e.routingFieldUsedBy,options:r.subagents.map(e=>({value:e.id,label:e.label})),onChange:({value:e})=>p(Array.isArray(e)?e.map(String):e?[String(e)]:[])})]})})]})}function yr({onStack:e}){let{t,route:n,state:r,known:i,persist:a,notices:o}=ur(),s=mr(),c=(0,u.useMemo)(()=>s.filter===null?null:We(r.routing,s.filter,S()).toolNames,[s.filter,r.routing]),f=c===null?i.tools:i.tools.filter(e=>c.includes(e.name)),[p,m]=(0,u.useState)(null),h=t=>{m(t),e?.(t!==null)};return(0,d.jsxs)(`div`,{className:`space-y-4`,children:[o,(0,d.jsx)(hr,{t,intro:t.routingToolsIntro,tryPath:s}),(0,d.jsx)(gr,{t,tryPath:s,count:f.length,total:i.tools.length}),c!==null&&f.length===0&&(0,d.jsx)(pr,{text:t.routingNoMatch}),f.map(e=>{let a=!!r.routing.tools?.[e.name]?.everywhere,o=i.subagents.filter(t=>Ue(r.routing,t).includes(e.name)),c=n&&s.filter===null?n.toolNames.includes(e.name):null;return(0,d.jsx)(lr,{onOpen:r.save?()=>h(e):null,children:(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,d.jsx)(`span`,{className:`font-medium`,children:ar(e.name)}),(0,d.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.name}),r.changes.tools?.[e.name]&&(0,d.jsx)(l.Badge,{variant:`warning`,children:t.routingModified}),c!==null&&(0,d.jsx)(l.Badge,{variant:c?`success`:`secondary`,className:`ml-auto`,children:c?t.routingOffered:t.routingNotOffered})]}),(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}),(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 text-xs`,children:[(0,d.jsx)(`span`,{className:`mr-1 text-muted-foreground`,children:t.routingUsedBy}),a&&(0,d.jsx)(l.Badge,{variant:`primary`,children:t.routingAllSubagents}),!a&&o.length===0&&(0,d.jsx)(`span`,{children:t.routingNoSubagents}),!a&&o.map(e=>(0,d.jsx)(l.Badge,{variant:`primary`,children:e.label},e.id))]})]})},e.name)}),p&&(0,d.jsx)(vr,{t,tool:p,routing:r.routing,known:i,onSave:a,onClose:()=>h(null)})]})}function br(e){return{id:e?.id??``,label:e?.label??``,pattern:e?.pattern??``,flags:e?.flags??``,context:e?.context??``,active:e?.disabled?``:`true`}}function xr(e){let t=e=>String(e??``).trim(),n=t(e.label),r=t(e.flags),i=t(e.context);return{id:t(e.id),...n?{label:n}:{},pattern:t(e.pattern),...r?{flags:r}:{},...i?{context:i}:{},...e.active?{}:{disabled:!0}}}var Sr={default:`secondary`,modified:`warning`,added:`info`};function Cr({t:e,rule:t,index:n,pages:r,routing:i,known:a,onSave:o,onClose:s}){let c=(0,l.useFormController)(),f=(0,u.useMemo)(()=>br(t),[t]),[p,m]=(0,u.useState)(f.active),[h,g]=(0,u.useState)([]);return(0,d.jsxs)(dr,{title:t?(0,l.interpolate)(e.routingEditOf,{label:t.label??t.id}):e.routingNewRule,titleBefore:(0,d.jsx)(l.Form,{appearance:`empty`,showNotice:!1,defaultValues:{active:f.active},children:(0,d.jsx)(l.Switch,{name:`active`,valueChecked:`true`,title:e.routingFieldActiveFeedback,ariaLabel:e.routingFieldActive,inheritWrapperClassName:!1,wrapperClassName:`m-0`,onChange:({value:e})=>m(e?`true`:``)})}),onClose:s,onSave:async()=>{let u=xr({...f,...c.record??{},active:p,...t?{id:t.id}:{}}),d=t?n:0,m=t?r.map((e,t)=>t===n?u:e):[u,...r],h=Qe({pages:m},a).filter(e=>e.where===`page`&&e.index===d&&e.level===`error`).map(t=>ir(e,t));if(u.pattern||h.push((0,l.interpolate)(e.routingIssueInvalidPattern,{detail:e.routingPatternRequired})),h.length>0){g(h);return}try{await o({...i,pages:m}),s()}catch(t){g([(0,l.interpolate)(e.routingSaveError,{error:sr(t)})])}},errors:h,children:[!p&&(0,d.jsx)(l.Alert,{variant:`warning`,children:e.routingFieldActiveFeedback}),(0,d.jsx)(l.Form,{controller:c,appearance:`empty`,showNotice:!1,defaultValues:f,children:(0,d.jsxs)(`div`,{className:`space-y-3`,children:[!t&&(0,d.jsx)(l.String,{name:`id`,label:e.routingFieldId,feedback:e.routingFieldIdFeedback,required:!0}),(0,d.jsx)(l.String,{name:`label`,label:e.routingFieldLabel}),(0,d.jsx)(l.String,{name:`pattern`,label:e.routingFieldPattern,feedback:e.routingFieldPatternFeedback,required:!0}),(0,d.jsx)(l.TextArea,{name:`context`,label:e.routingContext,feedback:e.routingFieldContextFeedback,minHeight:120})]})})]})}function wr({onStack:e}){let{t,state:n,known:r,persist:i,notices:a}=ur(),o=n.pages,s=(0,u.useMemo)(()=>Qe({pages:o},r),[o,r]),[c,f]=(0,u.useState)(null),p=t=>{f(t),e?.(t!==null)},m=()=>o.map(({origin:e,defaultRule:t,...n})=>n),h=e=>{i({...n.routing,pages:e}).catch(()=>void 0)},g=(e,t)=>{let n=m(),[r]=n.splice(e,1);n.splice(e+t,0,r),h(n)},_=n.path===null?null:He(o,n.path),v=mr(),y=v.filter===null?null:He(o,v.filter),b=v.filter===null?null:new Set(o.filter(e=>He([e],v.filter)).map(e=>e.id)),x=y?o.findIndex(e=>e.id===y.rule.id):-1;return(0,d.jsxs)(`div`,{className:`space-y-4`,children:[a,(0,d.jsx)(hr,{t,intro:t.routingPagesIntro,tryPath:v,children:n.save&&(0,d.jsx)(l.ActionButton,{icon:`plus`,label:t.routingNewRule,variant:`outline-secondary`,onClick:()=>p({rule:null,index:0})})}),(0,d.jsx)(gr,{t,tryPath:v,count:b?.size??0,total:o.length}),b!==null&&b.size===0&&(0,d.jsx)(pr,{text:t.routingNoMatch}),o.map((e,r)=>{if(b!==null&&!b.has(e.id))return null;let i={default:t.routingOriginDefault,modified:t.routingOriginModified,added:t.routingOriginAdded}[e.origin];return(0,d.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,d.jsx)(`span`,{className:`mt-4 w-5 shrink-0 text-right text-xs tabular-nums text-muted-foreground`,children:r+1}),(0,d.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,d.jsx)(lr,{onOpen:n.save?()=>p({rule:e,index:r}):null,children:(0,d.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,d.jsx)(`span`,{className:`text-sm font-medium`,children:e.label??e.id}),(0,d.jsx)(l.Badge,{variant:Sr[e.origin],children:i}),e.disabled&&(0,d.jsx)(l.Badge,{variant:`dark`,children:t.routingRuleOff}),b===null&&_?.rule.id===e.id&&(0,d.jsx)(l.Badge,{variant:`success`,className:`ml-auto`,children:t.routingHereBadge}),b!==null&&(r===x?(0,d.jsx)(l.Badge,{variant:`success`,className:`ml-auto`,children:t.routingApplies}):(0,d.jsx)(l.Badge,{variant:`secondary`,className:`ml-auto`,children:(0,l.interpolate)(t.routingOverridden,{n:String(x+1)})}))]}),(0,d.jsxs)(`code`,{className:`block break-all rounded bg-muted px-2 py-1 text-xs`,children:[e.pattern,e.flags?` /${e.flags}`:``]}),e.context&&(0,d.jsx)(`p`,{className:`whitespace-pre-wrap text-xs text-muted-foreground`,children:r===x&&y?.context?y.context:e.context}),(0,d.jsx)(cr,{t,issues:s.filter(e=>e.index===r)})]})})}),n.save&&(0,d.jsxs)(`div`,{className:`mt-2 flex shrink-0 flex-col`,children:[(0,d.jsx)(l.ActionButton,{icon:`arrow-up`,title:t.routingMoveUp,ariaLabel:t.routingMoveUp,variant:`link`,disabled:r===0,onClick:()=>g(r,-1)}),(0,d.jsx)(l.ActionButton,{icon:`arrow-down`,title:t.routingMoveDown,ariaLabel:t.routingMoveDown,variant:`link`,disabled:r===o.length-1,onClick:()=>g(r,1)}),e.origin===`modified`&&(0,d.jsx)(l.ActionButton,{icon:`rotate-ccw`,title:t.routingRestore,ariaLabel:t.routingRestore,variant:`link`,onClick:()=>h(m().map((t,n)=>n===r&&e.defaultRule?e.defaultRule:t))}),e.origin===`added`&&(0,d.jsx)(l.ActionButton,{icon:`trash-2`,title:t.routingRemove,ariaLabel:t.routingRemove,variant:`link`,onClick:()=>h(m().filter((e,t)=>t!==r))})]})]},e.id)}),c&&(0,d.jsx)(Cr,{t,rule:c.rule,index:c.index,pages:m(),routing:n.routing,known:r,onSave:i,onClose:()=>p(null)})]})}var Tr=e=>e instanceof Error?e.message:String(e);function Er(e){let[t,n]=(0,u.useState)(null),[r,i]=(0,u.useState)(null);return(0,u.useEffect)(()=>{if(!e)return;let t=!0;return e.me().then(e=>{t&&n(e)},e=>{t&&i(Tr(e))}),()=>{t=!1}},[e]),{me:t,error:r}}function Dr({backend:e,me:t}){let n=Q(),{locale:r}=(0,l.useI18n)(),i=t.role===`platform`,a=(0,u.useMemo)(()=>e.connections(),[e]),[o,s]=(0,u.useState)(null),[c,f]=(0,u.useState)(null),[m,h]=(0,u.useState)(null),[g,_]=(0,u.useState)(null),v=(0,u.useCallback)(async()=>{try{s((await a.load()).providers.length),i&&f(await e.fleet.list()),h(null)}catch(e){h(Tr(e))}},[e,a,i]);(0,u.useEffect)(()=>{v()},[v]);let y=()=>{_(null),v()};return(0,d.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n.connectionsIntro}),m&&(0,d.jsx)(l.Alert,{variant:`danger`,children:(0,l.interpolate)(n.connectionsError,{error:m})}),(0,d.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,d.jsx)(l.ListCard,{icon:`cloud`,title:n.cloudTitle,description:n.cloudDescription,badge:o?(0,d.jsx)(l.Badge,{variant:`success`,children:(0,l.interpolate)(n.cloudConnected,{count:o})}):(0,d.jsx)(l.Badge,{variant:`light`,children:n.cloudNone}),onClick:()=>_(`cloud`)}),i&&c?.map(e=>(0,d.jsx)(l.ListCard,{icon:`server`,title:e.name,description:e.url,badge:e.draining?(0,d.jsx)(l.Badge,{variant:`warning`,children:n.runnerDraining}):e.isDefault?(0,d.jsx)(l.Badge,{variant:`info`,children:n.runnerDefault}):void 0,onClick:()=>_({runner:e})},e.id)),!i&&(0,d.jsx)(l.ListCard,{icon:`server`,title:n.runnerOfProject,description:n.runnerOfProjectDescription,onClick:()=>_(`mine`)}),i&&(0,d.jsx)(l.ListCard,{icon:`plus`,dashed:!0,title:n.runnerAdd,description:n.runnerAddDescription,onClick:()=>_(`add`)})]}),g===`cloud`&&(0,d.jsx)(l.Modal,{title:n.cloudTitle,size:`xl`,onClose:y,footer:(0,d.jsx)(l.ActionButton,{variant:`link`,label:n.settingsClose,onClick:y}),children:(0,d.jsx)(l.AIConnections,{store:a,readOnly:t.role===`member`})}),g===`mine`&&(0,d.jsx)(l.Modal,{title:n.runnerOfProject,size:`lg`,onClose:y,footer:(0,d.jsx)(l.ActionButton,{variant:`link`,label:n.settingsClose,onClick:y}),children:(0,d.jsx)(p.RunnerAccounts,{client:e.runner(),scope:`user`,locale:r})}),g===`add`&&(0,d.jsx)(p.AddRunner,{fleet:e.fleet,t:(0,p.textsFor)(r),locale:r,onClose:y,onAdded:y}),g&&typeof g==`object`&&(0,d.jsx)(Or,{backend:e,runner:g.runner,onClose:y})]})}function Or({backend:e,runner:t,onClose:n}){let r=Q(),{locale:i}=(0,l.useI18n)(),[a,o]=(0,u.useState)(null),[s,c]=(0,u.useState)(null),[f,m]=(0,u.useState)(!1);(0,u.useEffect)(()=>{let n=!0;return e.fleet.status(t.id).then(e=>{n&&o(e)},e=>{n&&c(Tr(e))}),()=>{n=!1}},[e,t.id]);let h=n=>e.fleet.update(t.id,n).catch(e=>c(Tr(e)));return(0,d.jsxs)(l.Modal,{title:t.name,size:`lg`,onClose:n,footer:(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(l.ActionButton,{variant:`outline-danger`,icon:`trash`,label:r.runnerRemove,onClick:()=>m(!0)}),(0,d.jsx)(l.ActionButton,{variant:`link`,label:r.settingsClose,onClick:n})]}),children:[(0,d.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[s&&(0,d.jsx)(l.Alert,{variant:`danger`,children:(0,l.interpolate)(r.runnerUnreachable,{error:s})}),(0,d.jsx)(l.DescriptionList,{items:[{label:`URL`,value:t.url},{label:r.runnerVersion,value:a?.version??`…`},{label:r.runnerLoad,value:a?(0,l.interpolate)(r.runnerLoadValue,{chats:a.load.chats,max:a.load.maxChats}):`…`}]}),(0,d.jsx)(l.Form,{appearance:`empty`,showNotice:!1,onSubmit:()=>!1,children:(0,d.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,d.jsx)(l.Switch,{name:`isDefault`,label:r.runnerSetDefault,defaultValue:t.isDefault?`on`:``,onChange:({value:e})=>void h({isDefault:!!e})}),(0,d.jsx)(l.Switch,{name:`draining`,label:r.runnerSetDraining,defaultValue:t.draining?`on`:``,onChange:({value:e})=>void h({draining:!!e})})]})}),(0,d.jsx)(p.RunnerAccounts,{client:e.runnerOfNamespace(),scope:`tenant`,locale:i})]}),f&&(0,d.jsx)(l.ModalYesNo,{title:r.runnerRemove,danger:!0,onClose:()=>m(!1),onYes:async()=>{try{await e.fleet.remove(t.id),n()}catch(e){c(Tr(e))}return m(!1),!0},children:(0,l.interpolate)(r.runnerRemoveConfirm,{name:t.name})})]})}var kr=(e,t)=>t.ok?e.memoryOk:t.error===`rejected`?e.memoryRejected:t.error===`unreachable`?e.memoryUnreachable:e.memoryInvalid;function Ar({backend:e}){let t=Q(),[n,r]=(0,u.useState)(null),[i,a]=(0,u.useState)(null),[o,s]=(0,u.useState)(null),c=(0,u.useCallback)(async()=>{try{r(await e.memories.list()),a(null)}catch(e){a(Tr(e))}},[e]);return(0,u.useEffect)(()=>{c()},[c]),(0,d.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t.memoryIntro}),i&&(0,d.jsx)(l.Alert,{variant:`danger`,children:(0,l.interpolate)(t.connectionsError,{error:i})}),n&&!n.length&&(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t.memoryNone}),(0,d.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[n?.map(e=>(0,d.jsx)(l.ListCard,{icon:`database`,title:e.name,description:e.apiUrl,meta:e.mcpUrl,onClick:()=>s(e)},e.id)),(0,d.jsx)(l.ListCard,{icon:`plus`,dashed:!0,title:t.memoryAdd,description:t.memoryAddDescription,onClick:()=>s(`add`)})]}),o&&(0,d.jsx)(jr,{backend:e,memory:o===`add`?null:o,onClose:()=>{s(null),c()}})]})}function jr({backend:e,memory:t,onClose:n}){let r=Q(),[i,a]=(0,u.useState)({name:t?.name??``,apiUrl:t?.apiUrl??``,mcpUrl:t?.mcpUrl??``,key:``}),[o,s]=(0,u.useState)(null),[c,f]=(0,u.useState)(!1),p=e=>({value:t})=>a(n=>({...n,[e]:String(t??``)})),m=e=>s({variant:`danger`,text:(0,l.interpolate)(r.connectionsError,{error:Tr(e)})});return(0,d.jsxs)(l.Modal,{title:t?.name??r.memoryAdd,size:`lg`,onClose:n,footer:(0,d.jsxs)(d.Fragment,{children:[t&&(0,d.jsx)(l.ActionButton,{variant:`outline-danger`,icon:`trash`,label:r.memoryRemove,onClick:()=>f(!0)}),(0,d.jsx)(l.LoadingButton,{variant:`outline-primary`,label:r.memoryCheck,disabled:!i.apiUrl.trim()||!i.key.trim(),onClick:async()=>{let t=await e.memories.check({apiUrl:i.apiUrl,key:i.key}).catch(e=>({ok:!1,error:`unreachable`,failure:e}));s({variant:t.ok?`success`:`danger`,text:kr(r,t)})}}),(0,d.jsx)(l.LoadingButton,{variant:`primary`,label:r.memorySave,disabled:t?!1:!i.apiUrl.trim()||!i.key.trim(),onClick:async()=>{try{t?await e.memories.update(t.id,{name:i.name,mcpUrl:i.mcpUrl||null,...i.key.trim()?{key:i.key}:{}}):await e.memories.add({name:i.name,apiUrl:i.apiUrl,mcpUrl:i.mcpUrl||void 0,key:i.key}),n()}catch(e){m(e)}}})]}),children:[(0,d.jsx)(l.Form,{appearance:`empty`,showNotice:!1,onSubmit:()=>!1,children:(0,d.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[o&&(0,d.jsx)(l.Alert,{variant:o.variant,children:o.text}),(0,d.jsx)(l.String,{name:`name`,label:r.memoryName,defaultValue:i.name,onChange:p(`name`)}),(0,d.jsx)(l.String,{name:`apiUrl`,label:r.memoryApiUrl,placeholder:`https://memory.example.com`,defaultValue:i.apiUrl,disabled:!!t,onChange:p(`apiUrl`)}),(0,d.jsx)(l.String,{name:`mcpUrl`,label:r.memoryMcpUrl,placeholder:`https://memory.example.com/mcp`,defaultValue:i.mcpUrl,onChange:p(`mcpUrl`)}),(0,d.jsx)(l.Password,{name:`key`,label:r.memoryKey,autoComplete:`off`,onChange:p(`key`)}),t&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r.memoryKeyKeep})]})}),c&&t&&(0,d.jsx)(l.ModalYesNo,{title:r.memoryRemove,danger:!0,onClose:()=>f(!1),onYes:async()=>{try{await e.memories.remove(t.id),n()}catch(e){m(e)}return f(!1),!0},children:(0,l.interpolate)(r.memoryRemoveConfirm,{name:t.name})})]})}function Mr({backend:e,me:t}){let n=Q(),r=t.role===`platform`,[i,a]=(0,u.useState)(null),[o,s]=(0,u.useState)([]),[c,f]=(0,u.useState)([]),[p,m]=(0,u.useState)(null),h=(0,u.useCallback)(async()=>{try{let[t,n,i]=await Promise.all([e.projects.list(),r?e.fleet.list():Promise.resolve([]),r?e.memories.list():Promise.resolve([])]);a(t.namespaces),s(n),f(i),m(null)}catch(e){m(Tr(e))}},[e,r]);(0,u.useEffect)(()=>{h()},[h]);let g=async(t,n)=>{try{await e.projects.set(t,n),await h()}catch(e){m(Tr(e))}};return(0,d.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n.projectsIntro}),!r&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n.projectsReadOnly}),p&&(0,d.jsx)(l.Alert,{variant:`danger`,children:(0,l.interpolate)(n.connectionsError,{error:p})}),i?.map(e=>(0,d.jsxs)(`div`,{className:`grid gap-3 rounded-md border border-border p-3 sm:grid-cols-[1fr_12rem_12rem] sm:items-end`,children:[(0,d.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,d.jsx)(`span`,{className:`font-medium`,children:e.name??e.tenant??e.namespace}),(0,d.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:e.namespace})]}),r?(0,d.jsxs)(l.Form,{appearance:`empty`,showNotice:!1,onSubmit:()=>!1,className:`contents`,children:[(0,d.jsx)(l.Select,{name:`runner-${e.namespace}`,label:n.projectsRunner,defaultValue:e.runner?.id??``,placeholderOption:{label:n.projectsDefaultRunner,value:``},options:o.map(e=>({label:e.name,value:e.id})),onChange:({value:t})=>{t&&g(e.namespace,{runnerId:String(t)})}}),(0,d.jsx)(l.Select,{name:`memory-${e.namespace}`,label:n.projectsMemory,defaultValue:e.memory?.id??``,placeholderOption:{label:n.projectsNoMemory,value:``},options:c.map(e=>({label:e.name,value:e.id})),onChange:({value:t})=>void g(e.namespace,{memoryId:t?String(t):null})})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`span`,{className:`text-sm`,children:e.runner?.name??n.projectsDefaultRunner}),(0,d.jsx)(`span`,{className:`text-sm`,children:e.memory?.name??n.projectsNoMemory})]})]},e.namespace))]})}var Nr=[`low`,`medium`,`high`,`max`];function Pr(){let{shown:e,connections:t,backend:n}=ct();return e.length>0||!!t||!!n||S().length>0}function Fr(){let e=Q(),{settings:t,shown:n,connections:r,tabs:i,backend:a,save:o,isOpen:s,close:c}=ct(),{me:f}=Er(s?a:void 0),p=(0,l.useFormController)(),m=(0,l.useAIProviderRegistry)()?.registry??{},{modelsByProvider:h}=Sn({unfiltered:!0}),[g,_]=(0,u.useState)(0),[v,y]=(0,u.useState)(!1);if(!s)return null;let b=S().length>0,x=Object.keys(m),C=e=>m[e]?.label??e,w=Object.values(h).flat(),T={low:e.settingsReasoningLow,medium:e.settingsReasoningMedium,high:e.settingsReasoningHigh,max:e.settingsReasoningMax},E=e=>n.includes(e),D={defaultModel:t.defaultModel??``,reasoning:t.reasoning??``,chatTitles:t.chatTitles?`on`:``,threadEvents:t.threadEvents?`on`:``,...Object.fromEntries(x.map(e=>[`provider_${e}`,!t.providers||t.providers.includes(e)?`on`:``]))};return(0,d.jsx)(l.Modal,{title:e.settingsTitle,position:`right`,size:`lg`,stackedBehind:v,onClose:c,footer:(0,d.jsxs)(d.Fragment,{children:[n.length>0&&g===0&&(0,d.jsx)(l.LoadingButton,{variant:`primary`,label:e.settingsSave,onClick:e=>p.save(e)}),(0,d.jsx)(l.ActionButton,{variant:`link`,label:e.settingsClose,onClick:c})]}),children:(0,d.jsx)(l.Tab,{defaultIndex:0,onChange:_,contentClassName:`pt-4`,children:[n.length>0&&(0,d.jsx)(l.TabItem,{label:e.settingsChats,children:(0,d.jsx)(l.Form,{appearance:`empty`,controller:p,showNotice:!1,defaultValues:D,onSave:async({record:e})=>{let t=t=>String(e?.[t]??``),n=x.filter(e=>t(`provider_${e}`)===`on`);await o({...E(`defaultModel`)?{defaultModel:t(`defaultModel`)||void 0}:{},...E(`reasoning`)?{reasoning:t(`reasoning`)||void 0}:{},...E(`providers`)?{providers:n.length===x.length?void 0:n}:{},...E(`chatTitles`)?{chatTitles:t(`chatTitles`)===`on`}:{},...E(`threadEvents`)?{threadEvents:t(`threadEvents`)===`on`}:{}}),c()},children:(0,d.jsxs)(`div`,{className:`space-y-3`,children:[E(`defaultModel`)&&(0,d.jsx)(l.Select,{name:`defaultModel`,label:e.settingsDefaultModel,placeholderOption:{label:e.settingsDefaultModelNone,value:``},options:w.map(e=>({label:`${e.providerLabel??e.provider} / ${e.model}`,value:e.id}))}),E(`reasoning`)&&(0,d.jsx)(l.Select,{name:`reasoning`,label:e.settingsReasoning,placeholderOption:{label:e.settingsReasoningDefault,value:``},options:Nr.map(e=>({label:T[e],value:e}))}),E(`providers`)&&x.length>0&&(0,d.jsxs)(`fieldset`,{className:`space-y-1`,children:[(0,d.jsx)(`legend`,{className:`text-sm font-medium`,children:e.settingsProviders}),x.map(e=>(0,d.jsx)(l.Switch,{name:`provider_${e}`,label:C(e)},e))]}),E(`chatTitles`)&&(0,d.jsx)(l.Switch,{name:`chatTitles`,label:e.settingsChatTitles}),E(`threadEvents`)&&(0,d.jsx)(l.Switch,{name:`threadEvents`,label:e.settingsThreadEvents})]})})},`chats`),b&&(0,d.jsx)(l.TabItem,{label:e.settingsSubagents,children:(0,d.jsx)(_r,{onStack:y})},`subagents`),b&&(0,d.jsx)(l.TabItem,{label:e.settingsTools,children:(0,d.jsx)(yr,{onStack:y})},`tools`),b&&(0,d.jsx)(l.TabItem,{label:e.settingsPages,children:(0,d.jsx)(wr,{onStack:y})},`pages`),a&&f&&(0,d.jsx)(l.TabItem,{label:e.connectionsTab,children:(0,d.jsx)(Dr,{backend:a,me:f})},`connections`),a&&f?.role===`platform`&&(0,d.jsx)(l.TabItem,{label:e.memoryTab,children:(0,d.jsx)(Ar,{backend:a})},`memory`),a&&f&&f.role!==`member`&&(0,d.jsx)(l.TabItem,{label:e.projectsTab,children:(0,d.jsx)(Mr,{backend:a,me:f})},`projects`),r&&!a&&(0,d.jsx)(l.TabItem,{label:e.settingsConnectors,children:(0,d.jsx)(l.AIConnections,{...r})},`connectors`),...(i??[]).map(e=>(0,d.jsx)(l.TabItem,{label:e.label,children:e.render()},`host-${e.id}`))].filter(Boolean)})})}function Ir(e,t){return Object.values(e).flat().map(e=>{let n=t?.(e.provider,e.providerLabel??e.provider);return{label:e.model,value:e.id,pricing:e.pricing??null,group:n?.group??e.providerLabel??e.provider,...n?.badge?{groupBadge:n.badge}:{}}})}function Lr({task:e,editing:t,onCancelEdit:n,onSendEdit:r}){let i=Q(),[a,o]=(0,u.useState)(``),{agent:s,onApplied:c,manualEntry:f}=e,p=s.running;(0,u.useEffect)(()=>{t&&o(t.detail??``)},[t]);let{draft:m}=$(),h=(0,u.useRef)(m?.nonce??0);(0,u.useEffect)(()=>{m&&m.nonce!==h.current&&(h.current=m.nonce,o(m.text))},[m]);let g=e=>{if(o(``),t&&r){r(t,e.text);return}if(f){f.onSubmit(e.text);return}s.sendMessage(e.text,{attachments:e.files,model:e.model}).then(e=>{e&&c(e)})},_=!!f||s.remote&&s.remoteModels.length===0,v=s.alongside&&s.remoteModels.some(e=>e.value===s.selectedModel),y=!_&&!s.remote&&!v&&s.hasProviders&&!s.selectedModel,b=_?[]:s.remote?s.remoteModels:s.alongside?[...s.remoteModels,...Ir(s.modelsByProvider,s.catalogGroup)]:Ir(s.modelsByProvider);return(0,d.jsxs)(d.Fragment,{children:[t&&(0,d.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,d.jsx)(l.Icon,{name:`pencil`,size:12,className:`shrink-0`}),(0,d.jsx)(`span`,{className:`flex-1`,children:i.editingMessage}),(0,d.jsx)(l.ActionButton,{label:i.cancelEdit,variant:`link`,className:`p-0 text-xs`,onClick:()=>{o(``),n?.()}})]}),(0,d.jsx)(l.Chatbot,{value:a,onChange:o,placeholder:f?.prompt??i.messagePlaceholder,running:p,onStop:s.stop,disabled:!a.trim()||y,onSubmit:g,attachments:!f&&(s.remote||v?s.executorAttachments:!0),models:b,selectedModel:_?``:s.selectedModel,actions:e.composerActions,commands:e.composerCommands,onModelChange:s.setSelectedModel,modelPlaceholder:i.selectModelPlaceholder,minHeight:44,maxHeight:220})]})}function Rr(){let{startOrchestrator:e}=$(),t=Q(),[n,r]=(0,u.useState)(``),{hasProviders:i,modelsByProvider:a,selectedModel:o,setSelectedModel:s}=Sn(),c=ut(),f=t=>{t.text.trim()&&(e(t.text.trim(),{attachments:t.files.length>0?t.files:void 0,model:t.model||void 0}),r(``))},p=i&&!o;return(0,d.jsx)(l.Chatbot,{value:n,onChange:r,placeholder:t.orchestratorStarterPlaceholder,disabled:!n.trim()||p,onSubmit:f,attachments:!0,models:[...c?.models()??[],...Ir(a)],selectedModel:o,onModelChange:s,modelPlaceholder:t.selectModelPlaceholder,minHeight:44,maxHeight:220})}function zr({chat:e,onClose:t}){let n=Q(),r=(0,l.useFormController)();return(0,d.jsx)(l.Modal,{title:n.renameChat,size:`sm`,onClose:t,onSave:()=>(Te(e.scopeId,e.subagentId,e.entityId,String(r.record?.title??X(e)),`person`),t(),Promise.resolve(!0)),children:(0,d.jsxs)(l.Form,{appearance:`empty`,controller:r,defaultValues:{title:X(e)},footer:!1,children:[(0,d.jsx)(l.Input,{name:`title`,label:n.chatTitleLabel,placeholder:e.title}),(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n.chatTitleHint})]})})}function Br(e,t,n=Date.now()){let r=Math.round((e-n)/1e3),i=new Intl.RelativeTimeFormat(t,{numeric:`auto`,style:`short`});for(let[e,t]of[[`day`,86400],[`hour`,3600],[`minute`,60]])if(Math.abs(r)>=t)return i.format(Math.round(r/t),e);return i.format(0,`minute`)}function Vr({card:e}){let t=Q();return e.humanSummaryOnly?(0,d.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border/60 p-3`,children:[(0,d.jsxs)(`p`,{className:`text-xs font-medium text-foreground`,children:[`"`,e.label,`"`]}),(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.humanSummary})]}):(0,d.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border/60 p-3`,children:[(0,d.jsx)(`p`,{className:`text-xs font-medium text-foreground`,children:(0,l.interpolate)(t.newInstance,{label:e.label})}),(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.humanSummary}),e.fields.length>0&&(0,d.jsx)(`ul`,{className:`space-y-1`,children:e.fields.map(e=>(0,d.jsxs)(`li`,{className:`flex items-start gap-1.5 text-xs`,children:[(0,d.jsx)(l.Badge,{variant:e.required?`primary`:`secondary`,className:`mt-px shrink-0`,children:e.required?`richiesto`:`opzionale`}),(0,d.jsxs)(`span`,{className:`min-w-0`,children:[(0,d.jsx)(`span`,{className:`font-mono text-foreground`,children:e.key}),e.humanDescription?(0,d.jsxs)(`span`,{className:`text-muted-foreground`,children:[` — `,e.humanDescription]}):null]})]},e.key))}),e.example&&(0,d.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Esempio: `,(0,d.jsx)(`span`,{className:`font-mono`,children:e.example})]})]})}function Hr({messages:e}){return(0,d.jsx)(`div`,{className:`space-y-2 rounded-lg border border-border/60 p-3`,children:e.map((e,t)=>(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e},t))})}function Ur({scopeId:e,currentTaskId:t,open:n,onOpenChange:r,onSelect:i,onNewChat:a,onArchivedCurrent:o}){let s=Q(),{locale:c}=(0,l.useI18n)(),[f,p]=(0,u.useState)(``),[m,h]=(0,u.useState)(0);(0,u.useEffect)(()=>J(()=>h(e=>e+1)),[]);let g=(0,u.useMemo)(()=>n?De(e):[],[e,n,m]),[_,v]=(0,u.useState)(null),y=async n=>{let r=C(n.subagentId),i=await r?.confirmArchive?.(n.entityId,n.params);if(!i||window.confirm(i)){try{await r?.onArchive?.(n.entityId,n.params)}catch{return}Ee(e,n.subagentId,n.entityId),t===Oe(n.subagentId,n.entityId)&&o(),h(e=>e+1)}},b=(0,u.useMemo)(()=>{let e=f.trim().toLowerCase();return e?g.filter(t=>{let n=C(t.subagentId)?.label??t.subagentId;return X(t).toLowerCase().includes(e)||n.toLowerCase().includes(e)}):g},[g,f]);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(l.Dropdown,{trigger:{icon:`history`,title:s.chatHistory},triggerClassName:`!h-9 !w-9 !p-0 rounded-md bg-transparent text-muted-foreground hover:bg-accent hover:text-foreground`,open:n,onOpenChange:r,position:`end`,strategy:`absolute`,menuClassName:`w-[380px] max-h-[70vh] overflow-y-auto`,header:(0,d.jsxs)(`div`,{className:`flex items-center gap-2 px-1 pb-1.5`,children:[(0,d.jsx)(l.Icon,{name:`search`,size:14,className:`shrink-0 text-muted-foreground`}),(0,d.jsx)(`input`,{autoFocus:!0,value:f,onChange:e=>p(e.target.value),placeholder:s.searchChats,className:`min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground`}),(0,d.jsx)(l.ActionButton,{icon:`square-pen`,ariaLabel:s.newChat,title:s.newChat,variant:`link`,className:`shrink-0`,onClick:a})]}),children:b.length===0?(0,d.jsx)(`p`,{className:`px-2 py-3 text-center text-xs text-muted-foreground`,children:g.length===0?s.noSavedChats:s.noResults}):b.map(e=>{let n=C(e.subagentId),a=t===Oe(e.subagentId,e.entityId);return(0,d.jsx)(l.DropdownItem,{icon:a?`check`:n?.icon??`bot`,className:a?`bg-accent font-semibold text-primary`:void 0,actions:[{icon:`pencil`,label:s.renameChat,onClick:()=>{r(!1),v(e)}},{icon:`archive`,label:s.archiveChat,onClick:()=>void y(e)}],onClick:()=>i(e.subagentId,e.entityId,e),children:(0,d.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center justify-between gap-2`,children:[(0,d.jsx)(`span`,{className:`min-w-0 truncate`,title:`${n?.label??e.subagentId} · ${X(e)}`,children:X(e)}),(0,d.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,title:`${s.chatStarted.replace(`{at}`,new Date(Z(e)).toLocaleString(c))} · ${s.chatLastMessage.replace(`{at}`,new Date(e.savedAt).toLocaleString(c))}`,children:Br(Z(e),c)})]})},`${e.subagentId}:${e.entityId}`)})}),_&&(0,d.jsx)(zr,{chat:_,onClose:()=>v(null)})]})}function Wr({defaultWidth:e,minWidth:t,maxWidth:n,onWidthChange:r}={}){let{task:i,isOpen:a,pendingGoal:o,orchestratorRunId:s,pageContext:c,pageContextCard:f,anchoredUserMessages:p,pendingResume:m,resumeRunId:h,dismissForeignTask:g,resumeEntityChat:_,pendingManualEntry:v,manualEntryRunId:y,startManualEntry:b,pendingExtraDestinations:x,pendingResumeWithAI:S,resumeWithAIRunId:w,pendingStart:T,startRunId:E,scope:D,threadEvents:ee}=$(),O=Q(),k=(0,u.useRef)(null),[A,j]=(0,u.useState)(!1),[M,N]=(0,u.useState)(null),[P,te]=(0,u.useState)(null);(0,u.useEffect)(()=>{N(null),te(null)},[i?.id]),qn(D?.id);let F=cn({defaultWidth:e,minWidth:t,maxWidth:n,onWidthChange:r}),ne=()=>{(!i||i.agent.running||i.savedToDisk||window.confirm(O.unsavedConversationConfirm))&&(g(),j(!1))},I=i?[...i.precedingActivity??[],...i.agent.activity]:[],L=I.length,re=Math.max(0,Math.min(i?.panelExtraAnchorIndex??L,L)),ie=I.slice(0,re),R=I.slice(re),z=!!(i&&!i.agent.running&&i.agent.error),[B,ae,oe]=wt(),V=ct(),se=Pr(),H=(0,u.useRef)({at:Date.now()});H.current.id!==i?.id&&(H.current={id:i?.id,at:Date.now()});let ce=(0,u.useMemo)(()=>{if(!D||!i?.thread)return H.current.at;let e=Ae(D.id,i.thread,i.id)[0];if(e)return e.savedAt;let t=De(D.id).find(e=>Oe(e.subagentId,e.entityId)===i.id);return t?Z(t):I.find(e=>e.at!==void 0)?.at??H.current.at},[D?.id,i?.thread,i?.id,L===0]),le=Tt(i?.thread,ce,1/0,B),U=R.find(e=>e.at!==void 0)?.at,W=R.length===0||U===void 0?le:le.filter(e=>e.at<U),G=R.length===0||U===void 0?[]:le.filter(e=>e.at>=U),K=(e,t)=>{i&&(N(null),i.agent.rewind(e.id,t).then(e=>{e&&i.onApplied(e)}))},ue=e=>{let t=i?.agent.activity??[],n=t.slice(t.findIndex(t=>t.id===e.id)+1).flatMap(e=>[...e.kind===`tool`&&e.status===`done`?[e.label]:[],...(e.parts??[]).flatMap(e=>e.type===`tool`&&e.status===`done`?[e.label]:[])]);return[...new Set(n.filter(Boolean))]},de=(e,t)=>{let n=ue(e);n.length?te({entry:e,steps:n,...t===void 0?{}:{text:t}}):K(e,t)},fe=i?{available:e=>i.agent.activity.some(t=>t.id===e.id)&&i.agent.rewindable(e.id),disabled:i.agent.running,onRetry:e=>de(e),onEdit:e=>N(e)}:void 0,pe=new Set(i?.agent.activity.map(e=>e.id)??[]),me=i?{canAnswer:e=>pe.has(e),onAnswer:(e,t,n)=>i.agent.answerQuestions(e,t,n).then(e=>{e&&i.onApplied(e)}),onCardAction:(e,t,n)=>i.agent.cardAction(e,t,n)}:void 0,q=me?Gt(I,me.canAnswer):null,he=i?.id===`agentico-orchestrator`&&i.scopedSubagentId?C(i.scopedSubagentId):void 0,ge=he?.manualEntry?he:null,J=(0,u.useRef)(!0);(0,u.useEffect)(()=>{let e=k.current;if(!e)return;let t=()=>{J.current=e.scrollHeight-e.scrollTop-e.clientHeight<80};return e.addEventListener(`scroll`,t),()=>e.removeEventListener(`scroll`,t)},[i?.id]),(0,u.useEffect)(()=>{let e=k.current;e&&(J.current=!0,e.scrollTop=e.scrollHeight)},[i?.id]);let _e=I.at(-1)?.detail?.length??0;(0,u.useEffect)(()=>{let e=k.current;e&&J.current&&(e.scrollTop=e.scrollHeight)},[L,z,_e]);let Y=(0,u.useRef)(null);(0,u.useEffect)(()=>{let e=k.current,t=Y.current;if(!e||!t||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{J.current&&(e.scrollTop=e.scrollHeight)});return n.observe(t),()=>n.disconnect()},[i?.id,a]);let ve=o?(0,d.jsx)(Zn,{userGoal:o},s):null,ye=m?C(m.subagentId):void 0,be=m&&ye?(0,d.jsx)(Xn,{manifest:ye,params:m.snapshot.params,taskId:Oe(m.subagentId,m.entityId),resumeSeed:{history:m.snapshot.history,activity:m.snapshot.activity}},h):null,xe=v?C(v.subagentId):void 0,Se=v&&xe?(0,d.jsx)(Qn,{manifest:xe,extraDestinations:v.extraDestinations},y):null,X=S?C(S.subagentId):void 0,Ce=S&&X?(0,d.jsx)(Xn,{manifest:X,params:S.params,extraDestinations:S.extraDestinations},w):null,we=T?C(T.subagentId):void 0,Te=T&&we?(0,d.jsx)(Xn,{manifest:we,params:T.params,taskId:T.taskId,openingMessage:T.openingMessage},E):null;return a?(0,d.jsxs)(d.Fragment,{children:[ve,be,Se,Ce,Te,(0,d.jsxs)(`div`,{style:{width:F.width},className:`relative flex h-full shrink-0 flex-col border-l border-border bg-background`,children:[(0,d.jsx)(ln,{width:F.width,min:F.min,max:F.max,onResize:F.set,onCommit:F.commit,onReset:F.reset}),(0,d.jsxs)(`div`,{className:`flex min-h-[60px] items-center gap-1 border-b border-border/60 px-4 py-3`,children:[(0,d.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-lg font-semibold leading-tight`,children:i?i.title:`Agentico`}),i?.thread&&ee&&oe&&(0,d.jsx)(l.ActionButton,{icon:B?`activity`:`message-square`,ariaLabel:B?O.hideEvents:O.showEvents,title:B?O.hideEvents:O.showEvents,variant:`link`,className:`p-1 ${B?`text-primary`:`text-muted-foreground`}`,onClick:()=>ae(!B)}),D&&(0,d.jsx)(Ur,{scopeId:D.id,currentTaskId:i?.id??null,open:A,onOpenChange:j,onNewChat:ne,onSelect:(e,t,n)=>_(e,t,n),onArchivedCurrent:g}),se&&(0,d.jsx)(l.ActionButton,{icon:`settings`,ariaLabel:O.settingsTitle,title:O.settingsTitle,variant:`link`,className:`p-1 text-muted-foreground`,onClick:V.open}),(0,d.jsx)(un,{})]}),(0,d.jsx)(Fr,{}),(0,d.jsx)(`div`,{ref:k,className:`flex-1 overflow-y-auto px-3 pb-2 ${q?`min-h-24`:`min-h-0`}`,children:(0,d.jsx)(`div`,{ref:Y,className:`pt-2`,children:i?(0,d.jsxs)(d.Fragment,{children:[D&&i.thread&&(0,d.jsx)(tr,{scopeId:D.id,thread:i.thread,taskId:i.id,scrollRef:k,busy:i.agent.running,showEvents:B,onLoad:()=>{J.current=!1},onContinue:e=>_(e.subagentId,e.entityId,e)}),i.manualEntry&&I.length===0&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i.manualEntry.prompt}),(0,d.jsx)(Zt,{activity:ie,questions:me,docked:q,pinUserMessages:!q,messageActions:fe,speaker:i.speaker,events:W}),i.panelExtra&&(0,d.jsx)(`div`,{className:`mt-3`,children:i.panelExtra}),R.length>0&&(0,d.jsx)(Zt,{activity:R,questions:me,docked:q,pinUserMessages:!q,messageActions:fe,speaker:i.speaker,events:G}),!i.agent.running&&i.agent.error&&(0,d.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,d.jsx)(`p`,{className:`flex-1 text-xs text-destructive`,children:i.agent.error}),(0,d.jsx)(l.ActionButton,{label:O.retry,variant:`secondary`,className:`shrink-0`,onClick:()=>{let e=[...i.agent.activity].reverse().find(e=>e.kind===`user`);if(e&&i.agent.rewindable(e.id)){de(e);return}i.agent.sendMessage(O.retryMessage,{retry:!0}).then(e=>{e&&i.onApplied(e)})}}),!i.agent.remote&&i.agent.offersFallback!==!1&&(0,d.jsx)(l.ActionButton,{label:O.continueWithoutAi,variant:`secondary`,className:`shrink-0`,onClick:()=>{if(ge){b(ge.id,x);return}let e=i.agent.runFallback();e&&i.onApplied(e)}})]})]}):p.length>0?(0,d.jsx)(Hr,{messages:p}):f?(0,d.jsx)(Vr,{card:f}):(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c??O.orchestratorStarterHint})})}),i&&q?(0,d.jsxs)(`section`,{"aria-label":O.pendingQuestions,className:`flex min-h-0 shrink flex-col border-t border-border/60`,children:[i.panelActions&&(0,d.jsx)(`div`,{className:`shrink-0 px-4 pt-3`,children:i.panelActions}),(0,d.jsx)(`div`,{className:`min-h-0 overflow-y-auto px-4 py-3`,children:(0,d.jsx)(Kt,{entry:q.entry,part:q.part,questions:me,autoFocus:!0},`${q.entry.id}:${q.part.id}`)}),i.agent.running&&(0,d.jsx)(`div`,{className:`flex shrink-0 justify-end px-4 pb-3`,children:(0,d.jsx)(l.ActionButton,{icon:`square`,label:O.stop,variant:`secondary`,onClick:i.agent.stop})})]}):(0,d.jsxs)(`div`,{className:`border-t border-border/60 px-4 py-3`,children:[i?.panelActions&&(0,d.jsx)(`div`,{className:`mb-2`,children:i.panelActions}),i?(0,d.jsx)(Lr,{task:i,editing:M,onCancelEdit:()=>N(null),onSendEdit:(e,t)=>de(e,t)},i.id):(0,d.jsx)(Rr,{})]}),P&&(0,d.jsxs)(l.ModalYesNo,{title:O.rewindTitle,onClose:()=>te(null),onYes:async()=>(K(P.entry,P.text),!0),children:[(0,d.jsx)(`p`,{className:`text-sm`,children:O.rewindText}),(0,d.jsx)(`ul`,{className:`mt-2 list-disc space-y-0.5 ps-5 text-sm text-muted-foreground`,children:P.steps.slice(0,8).map(e=>(0,d.jsx)(`li`,{children:e},e))})]})]})]}):(0,d.jsxs)(d.Fragment,{children:[ve,be,Se,Ce,Te]})}function Gr(e,t){let{setPageContext:n}=$(),r=(0,u.useRef)(crypto.randomUUID()).current;(0,u.useEffect)(()=>(n(r,e,t??null),()=>n(r,null)),[e,t])}function Kr(e,t,n,r,i=!0,a){let{registerComponentAnchor:o}=$(),s=(0,u.useRef)(crypto.randomUUID()).current,c=(0,u.useRef)(n);c.current=n,(0,u.useEffect)(()=>{if(i)return o(s,{subagentId:e,componentKey:t,contextInfo:r,pinnedEntityId:a,onResult:(e,t,n)=>c.current?.(e,t,n)}),()=>o(s,null)},[e,t,r,i,a])}var qr=class extends Error{status;code;constructor(e,t){super(t),this.name=`AgenticoBackendError`,this.status=e,this.code=t}},Jr=e=>new Promise(t=>setTimeout(t,e));function Yr(e){let t=e.baseUrl.replace(/\/+$/,``),n=(...t)=>(e.fetch??fetch)(...t),r=e.pollMs??1500;async function i(r,i,a){let o=await n(`${t}${i}`,{method:r,headers:{...a===void 0?{}:{"content-type":`application/json`},...await e.headers?.()},...a===void 0?{}:{body:JSON.stringify(a)}}),s=await o.text(),c={};try{c=s?JSON.parse(s):{}}catch{c={}}if(!o.ok){let e=c&&typeof c==`object`&&`error`in c?String(c.error):`http-${o.status}`;if(o.status===422&&c&&typeof c==`object`&&`ok`in c)return c;throw new qr(o.status,e)}return c}let a=e=>{let t=e?`?namespace=${encodeURIComponent(e)}`:``,n=e=>`/connections/${encodeURIComponent(e)}`;return{load:()=>i(`GET`,`/connections${t}`),connect:(e,r)=>i(`POST`,`${n(e)}${t}`,{fields:r}),disconnect:async e=>{await i(`DELETE`,`${n(e)}${t}`)},addAccount:(e,r)=>i(`POST`,`${n(e)}/accounts${t}`,{fields:r}),removeAccount:async(e,r)=>{await i(`DELETE`,`${n(e)}/accounts/${encodeURIComponent(r)}${t}`)},orderAccounts:async(e,r)=>{await i(`PUT`,`${n(e)}/accounts/order${t}`,{ids:r})},setOrder:async e=>{await i(`PUT`,`/connections/order${t}`,{order:e})},models:async e=>(await i(`GET`,`${n(e)}/models${t}`)).models}},o=[],s={list:async()=>{let[e,t]=await Promise.all([i(`GET`,`/runners`),i(`GET`,`/projects`).catch(()=>({namespaces:[]}))]);return o=t.namespaces,e.runners},add:async e=>(await i(`POST`,`/runners`,e)).runner,update:async(e,t)=>{await i(`PATCH`,`/runners/${encodeURIComponent(e)}`,t)},remove:async e=>{await i(`DELETE`,`/runners/${encodeURIComponent(e)}`)},status:e=>i(`GET`,`/runners/${encodeURIComponent(e)}/status`),startPairing:e=>i(`POST`,`/runners/pairings`,e),pairingStatus:e=>i(`GET`,`/runners/pairings/${encodeURIComponent(e)}`),install:async(e,t)=>{let{installId:n}=await i(`POST`,`/runners/installs`,e),a=0;for(;;){await Jr(r);let e=await i(`GET`,`/runners/installs/${encodeURIComponent(n)}?from=${a}`);for(let n of e.lines)t({line:n});if(a=e.next,e.status===`error`)throw Error(e.error??`installation failed`);if(e.status===`done`){let t=(await s.list()).find(t=>t.id===e.runnerId);if(!t)throw Error(`installation failed`);return t}}},tenants:{list:async()=>o.map(e=>({id:e.namespace,name:e.name??e.namespace,...e.runner?{runnerId:e.runner.id}:{}})),assign:async(e,t)=>{await i(`PUT`,`/namespaces/${encodeURIComponent(e)}`,{runnerId:t})}}},c=n=>new f.RunnerClient({url:`${t}/${n}`,...e.fetch?{fetch:e.fetch}:{},...e.headers?{headers:e.headers}:{}});return{me:()=>i(`GET`,`/me`),connections:a,fleet:s,runner:()=>c(`runner`),runnerOfNamespace:()=>c(`runner-namespace`),memories:{list:async()=>(await i(`GET`,`/memories`)).memories,check:e=>i(`POST`,`/memories/check`,e),add:async e=>(await i(`POST`,`/memories`,e)).memory,update:async(e,t)=>(await i(`PATCH`,`/memories/${encodeURIComponent(e)}`,t)).memory,remove:async e=>{await i(`DELETE`,`/memories/${encodeURIComponent(e)}`)}},memory:{get:()=>i(`GET`,`/memory`),search:async(e,t)=>(await i(`POST`,`/memory/search`,{query:e,...t?{limit:t}:{}})).results,write:e=>i(`POST`,`/memory/write`,e)},projects:{list:()=>i(`GET`,`/projects`),set:async(e,t)=>{await i(`PUT`,`/namespaces/${encodeURIComponent(e)}`,t)}}}}exports.AGENTICO_MAX_WIDTH=en,exports.AGENTICO_MIN_WIDTH=$t,exports.AGENTICO_SETTING_KEYS=$e,exports.AGENTICO_WIDTH=Qt,exports.AGENTICO_WIDTH_STORAGE_KEY=tn,exports.Agentico=Wr,exports.AgenticoBackendError=qr,exports.AgenticoProvider=St,exports.AgenticoSettingsModal=Fr,exports.AgenticoToggle=un,exports.DEFAULT_AGENTICO_SETTINGS=et,exports.DEFAULT_REASONING_PART_ID=h,exports.DEFAULT_TEXT_PART_ID=m,exports.JSON_EXPORT_DESTINATION_ID=oe,exports.MICRO_PROMPT_REGISTRY=ie,exports.ORCHESTRATOR_TASK_ID=yt,exports.PREVIEW_LIMIT=Ne,exports.PREVIEW_MAX=Me,exports.SUMMARY_MICRO_PROMPT=re,exports.agenticoDe=W,exports.agenticoEn=le,exports.agenticoIt=U,exports.agenticoPromptsEn=k,exports.agenticoPromptsIt=A,exports.agenticoTranslations=Ie,exports.applyMicroPrompts=R,exports.browserSettingsStore=it,exports.chatHasPersonMessage=Ce,exports.chatStartedAt=Z,exports.chatThreadOf=ke,exports.chatTitle=X,exports.compileRoutePattern=ze,exports.configureAgenticoPrompts=M,exports.configureEntityChatStore=ue,exports.createAgenticoBackend=Yr,exports.createCrossAgentTools=E,exports.createHarnessExecutor=vn,exports.defineSubagent=y,exports.diffAgenticoRouting=Ze,exports.earlierSessions=Ae,exports.effectiveSettings=tt,exports.entityChatTaskId=Oe,exports.extractErrorMessage=z,exports.extractJsonBlock=B,exports.findSubagentManifest=C,exports.formatQuestionAnswers=v,exports.getAgenticoPrompts=N,exports.getDestinationRegistry=ce,exports.getEntityChat=ve,exports.getSubagentControls=Hn,exports.getSubagentRegistry=S,exports.getSubagentReport=Ln,exports.harnessTranscript=gn,exports.hasEntityChatBackend=de,exports.imagePreviews=Fe,exports.jsonExportDestination=V,exports.listEntityChats=De,exports.matchAgenticoPage=He,exports.matchesAnyPath=Be,exports.mergeAgenticoPageRules=Ge,exports.mergeAgenticoRouting=Ke,exports.messagePartsText=_,exports.onEntityChatsChange=J,exports.placeEvents=je,exports.registerCrossAgentTools=T,exports.registerDestinations=H,exports.registerSubagentControls=Vn,exports.registerSubagentReports=In,exports.registerSubagents=x,exports.removeEntityChat=Ee,exports.renameEntityChat=Te,exports.renderRegistryCli=L,exports.renderSubagentCli=I,exports.resetAgenticoPrompts=P,exports.resolveAgenticoRoute=We,exports.routePathOf=Le,exports.runHostTool=hn,exports.saveEntityChat=ye,exports.shownSettings=nt,exports.subagentToolsOf=Ue,exports.syncEntityChats=me,exports.toJsonSchema=D,exports.toMcpTool=ee,exports.upsertMessagePart=g,exports.useAgent=Dn,exports.useAgentico=$,exports.useAgenticoHarness=ut,exports.useAgenticoI18n=Q,exports.useAgenticoPageContext=Gr,exports.useAgenticoSettings=ct,exports.useSubagentComponentContext=Kr,exports.validateAgenticoRouting=Qe;
|
|
34
|
+
`).map(e=>e.trim()).find(Boolean)??``).replace(/^(title|titolo)\s*:\s*/i,``).replace(/^#+\s*/,``).replace(/^["'«“]+|["'»”]+$/g,``).replace(/[.。]+$/,``).trim().slice(0,80)}function Gn(e,t){try{return e.definition.executor?.catalogProviders?.(e.toParams(t))}catch{return}}function Kn(e,t,n,r,i){let a=Gn(e,t),o=e=>{let t=e?(0,l.parseAIModelRef)(e):null;return!(!t||!i[t.provider]||a&&!a.includes(t.provider))};return o(n)?n:Object.values(r).flat().map(e=>e.id).find(o)}function qn(e){let t=(0,l.useAIProviderRegistry)()?.registry??{},{modelsByProvider:n,selectedModel:r}=Sn(),{settings:i}=ct(),a=(0,u.useRef)({registry:t,modelsByProvider:n,selectedModel:r,enabled:i.chatTitles});a.current={registry:t,modelsByProvider:n,selectedModel:r,enabled:i.chatTitles};let o=(0,u.useRef)(new Set),s=(0,u.useCallback)(async(t,n,r)=>{if(!e||!a.current.enabled)return!1;let i=ve(e,t,n),s=C(t),c=`${e}:${t}:${n}`;if(!i||!s?.autoTitle||i.name||!Ce(i)||o.current.has(c))return!1;let{registry:u,modelsByProvider:d,selectedModel:f}=a.current,p=Kn(s,i.params,r??f,d,u),m=p?(0,l.parseAIModelRef)(p):null;if(!m)return!1;o.current.add(c);try{let r=await u[m.provider].complete({prompt:N().chatTitle.replace(`{chat}`,Un(i.activity)),model:m.model,history:[]}),a=r&&r.type===`text`?Wn(r.text):``;return a?Te(e,t,n,a,`model`):!1}catch{return!1}finally{o.current.delete(c)}},[e]),c=Object.keys(n).length>0;return(0,u.useEffect)(()=>{e&&c&&!Jn.has(e)&&(Jn.add(e),(async()=>{for(let t of De(e)){let n=C(t.subagentId);if(n?.autoTitle){if(n.definition.conversational&&!Ce(t)){Ee(e,t.subagentId,t.entityId);continue}t.name||await s(t.subagentId,t.entityId)}}})())},[e,c,s]),s}var Jn=new Set,Yn=()=>({});function Xn({manifest:e,params:t,extraDestinations:n,precedingActivity:r,taskId:i,resumeSeed:a,model:o,openingMessage:s}){let c=$(),f=Dn(e.definition,{defaultEnabled:!0,...c.person?{author:c.person}:{}}),p=e.thread?.(t)||void 0,m=e.speaker?.(t),h=c.scope,g=(0,l.useProxy)(),_=(0,u.useRef)(i??`subagent-${e.id}-${crypto.randomUUID()}`).current,[v,y]=(0,u.useState)(null),b=t=>{e.definition.conversational||y(t)},[x,S]=(0,u.useState)([]),[C,w]=(0,u.useState)(null),T=Ln(e.id),E=T?.kind===`selection`?T:null,[D,ee]=(0,u.useState)(null),O=(0,u.useRef)(!1),k=(0,u.useRef)(0),A=(0,u.useRef)(null);v&&v!==A.current&&(A.current=v,k.current=(r?.length??0)+f.activity.length);let j=(0,u.useRef)(!1),M=f.remote||!f.hasProviders||f.selectedModel!==``;(0,u.useEffect)(()=>{!O.current&&M&&(O.current=!0,a?(R.current=!0,f.resume(e.toParams(t),a)):(o&&f.setSelectedModel(o),f.run(e.toParams(t),{model:o,openingMessage:s}).then(e=>{e&&b(e)})))},[M]),(0,u.useEffect)(()=>{if(!v||!h)return;let n=e.autoApplyDestinationIds??[],r=c.componentAnchors.find(t=>t.subagentId===e.id&&t.pinnedEntityId)?.pinnedEntityId,i=ce();n.forEach(n=>{let a=i[n];a&&(w(null),a.apply(v,{scopeId:h.id,dataProvider:h.dataProvider,storageProvider:h.storageProvider,proxyFetch:g},{...t,pinnedEntityId:r}).then(n=>{n?.id&&c.commitEntityChat(e.id,n.id,_,h.id,t,Nn(e,t))}).catch(e=>w(e instanceof Error?e.message:String(e))))})},[v,f.activity,h]),(0,u.useEffect)(()=>{v&&E&&ee(E.defaultSelection(v))},[v,E]);let N=(e,t)=>{ee(n=>n&&{...n,[e]:t})},P=e=>b(e),te=(0,u.useMemo)(()=>v&&E&&D?E.applySelection(v,D):v,[v,E,D]),F=(0,u.useMemo)(()=>c.componentAnchors.filter(t=>t.subagentId===e.id&&t.onResult),[c.componentAnchors,e.id]),ne=(0,u.useMemo)(()=>zn(F,t,_),[F,t,_]),I=(0,u.useMemo)(()=>ne?[ne,...n??[]]:n,[ne,n]),L=e.chatEntityId?.(t),re=qn(h?.id),ie=(0,u.useRef)(!1),R=(0,u.useRef)(!1);(0,u.useEffect)(()=>{let n=!ie.current&&f.running,i=ie.current&&!f.running;if(ie.current=f.running,!n&&!i||!L||!h)return;if(R.current){i&&(R.current=!1);return}let a=f.snapshot();if(!a)return;let o=[...r??[],...a.activity];e.autoTitle&&e.definition.conversational&&!Ce({activity:o})||(ye({scopeId:h.id,subagentId:e.id,entityId:L,params:t,title:Nn(e,t),history:a.history,activity:o}),i&&e.autoTitle&&re(e.id,L,f.selectedModel))},[f.running]);let z=f.activity.flatMap(e=>(e.parts??[]).flatMap(e=>e.type===`card`&&e.outcome?[`${e.id}:${e.outcome.status}`]:[])).join(`,`),B=(0,u.useRef)(z);(0,u.useEffect)(()=>{if(z===B.current||(B.current=z,!z||!L||!h||f.running||R.current))return;let n=f.snapshot();if(!n)return;let i=[...r??[],...n.activity];e.autoTitle&&e.definition.conversational&&!Ce({activity:i})||ye({scopeId:h.id,subagentId:e.id,entityId:L,params:t,title:Nn(e,t),history:n.history,activity:i})},[z]);let ae=()=>{j.current=!0,f.running&&f.stop(),c.closeTask(_)},oe=(0,u.useRef)(Hn(e.id)??Yn).current,V=oe({params:t,taskId:_,running:f.running,close:ae}),se=e=>{S(t=>t.includes(e)?t:[...t,e])};return(0,u.useEffect)(()=>{j.current||c.openTask({id:_,title:Nn(e,t),icon:e.icon,agent:f,onApplied:e=>b(e),precedingActivity:r,panelExtraAnchorIndex:k.current,onDismiss:ae,...p?{thread:p}:{},...m?{speaker:m}:{},...L?{savedToDisk:!0}:{},panelActions:V.content,composerActions:V.actions,composerCommands:V.commands,panelExtra:v?(0,d.jsxs)(d.Fragment,{children:[E&&D?(0,d.jsx)(E.Report,{result:v,selection:D,onChange:N}):T?.kind===`editable`?(0,d.jsx)(T.Report,{result:v,onResultChange:P}):(0,d.jsx)(Rn,{result:te}),C&&(0,d.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Salvataggio automatico non riuscito: `,C]}),(0,d.jsx)(Pn,{manifest:e,result:te,meta:t,taskId:_,initiallyApplied:x,onApplied:se,extraDestinations:I})]}):void 0})},[f.activity,f.running,f.error,f.canContinue,f.selectedModel,f.modelsByProvider,f.hasProviders,f.remoteModels,c.openTask,c.componentAnchors,_,e,t,v,te,D,x,n,r,C,V.content,V.actions,V.commands]),(0,u.useEffect)(()=>()=>{c.closeTask(_)},[c.closeTask,_]),null}function Zn({userGoal:e}){let t=Q(),n=(0,u.useMemo)(()=>Mn({unavailable:t.orchestratorUnavailable,continueWithoutAi:t.orchestratorContinueWithoutAi,preparing:t.orchestratorPreparing,collecting:t.orchestratorCollecting}),[]),r=$(),i=Dn(n,{defaultEnabled:!0,...r.person?{author:r.person}:{}}),[a,o]=(0,u.useState)(null),s=(0,u.useRef)(!1),c=!i.hasProviders||i.selectedModel!==``,l=(0,u.useRef)(r.pendingExtraDestinations),f=(0,u.useRef)(r.pendingAttachments),p=(0,u.useRef)(r.pendingModel),m=(0,u.useRef)(r.pendingScopedSubagentId??r.scopedSubagentId??void 0),h=(0,u.useRef)(r.pendingCarryOver),g=(0,u.useRef)(!1),_=e=>{e&&typeof e==`object`&&e.kind===`handoff`&&(o(e),r.closeTask(yt))};(0,u.useEffect)(()=>{!s.current&&c&&(s.current=!0,p.current&&i.setSelectedModel(p.current),i.run({userGoal:e,pageContext:r.pageContext,scopedSubagentId:m.current??null,route:r.route?{subagentIds:r.route.subagentIds,toolNames:r.route.toolNames,toolsOf:r.route.toolsOf}:null},{attachments:f.current,model:p.current,openingMessage:e}).then(e=>{e&&_(e)}))},[c]),(0,u.useEffect)(()=>{g.current||r.openTask({id:yt,title:`Agentico`,icon:`bot`,agent:i,onApplied:_,scopedSubagentId:m.current,precedingActivity:h.current?.activity,onDismiss:()=>{g.current=!0,i.running&&i.stop(),r.closeTask(yt)}})},[i.activity,i.running,i.error,i.canContinue,i.selectedModel,i.modelsByProvider,i.hasProviders,r.openTask]),(0,u.useEffect)(()=>()=>{r.closeTask(yt)},[r.closeTask]);let v=(0,u.useMemo)(()=>[...h.current?.activity??[],...i.activity],[i.activity]);if(!a)return null;let y=C(a.subagentId);return y?(0,d.jsx)(Xn,{manifest:y,params:a.params,extraDestinations:l.current,model:p.current||void 0,taskId:h.current?.taskId,precedingActivity:v}):null}function Qn({manifest:e,extraDestinations:t}){let n=$(),r=Dn(e.definition,{defaultEnabled:!1,...n.person?{author:n.person}:{}}),i=Q(),a=(0,u.useRef)(`manual-${e.id}-${crypto.randomUUID()}`).current,[o,s]=(0,u.useState)(null),[c,f]=(0,u.useState)([]),p=Ln(e.id),m=p?.kind===`selection`?p:null,[h,g]=(0,u.useState)(null),[_,v]=(0,u.useState)(null),y=(0,u.useRef)(!1),b=t=>{if(!e.manualEntry)return;let n;try{n=e.manualEntry.fromRawText(t)}catch(e){console.error(`[ManualEntryRunner] manualEntry.fromRawText ha rifiutato il testo:`,e);return}v(n),f([]),r.run(n,{openingMessage:t}).then(e=>{e&&s(e)})};(0,u.useEffect)(()=>{o&&m&&g(m.defaultSelection(o))},[o,m]);let x=(e,t)=>{g(n=>n&&{...n,[e]:t})},S=e=>s(e),C=(0,u.useMemo)(()=>o&&m&&h?m.applySelection(o,h):o,[o,m,h]),w=e=>{f(t=>t.includes(e)?t:[...t,e])},T=(0,u.useMemo)(()=>n.componentAnchors.filter(t=>t.subagentId===e.id&&t.onResult),[n.componentAnchors,e.id]),E=(0,u.useMemo)(()=>_?zn(T,_,a):null,[T,_,a]),D=(0,u.useMemo)(()=>E?[E,...t??[]]:t,[E,t]);return(0,u.useEffect)(()=>{y.current||n.openTask({id:a,title:e.label,icon:e.icon,agent:r,onApplied:e=>s(e),manualEntry:e.manualEntry?{prompt:e.manualEntry.prompt,onSubmit:b}:void 0,onDismiss:()=>{y.current=!0,r.running&&r.stop(),n.closeTask(a)},panelExtra:o?(0,d.jsxs)(`div`,{className:`space-y-2`,children:[m&&h?(0,d.jsx)(m.Report,{result:o,selection:h,onChange:x}):p?.kind===`editable`?(0,d.jsx)(p.Report,{result:o,onResultChange:S}):(0,d.jsx)(Rn,{result:C}),(0,d.jsx)(Pn,{manifest:e,result:C,meta:_??{},taskId:a,initiallyApplied:c,onApplied:w,extraDestinations:D}),r.hasProviders&&(0,d.jsx)(l.ActionButton,{label:i.resumeWithAi,variant:`outline-secondary`,className:`text-xs`,onClick:()=>{_&&n.resumeWithAI(e.id,_,t)}})]}):void 0})},[r.activity,r.running,r.error,r.hasProviders,n.componentAnchors,o,C,h,c,_]),(0,u.useEffect)(()=>()=>{n.closeTask(a)},[]),null}function $n({title:e,meta:t,action:n}){return(0,d.jsxs)(`div`,{role:`separator`,"aria-label":e,className:`my-3 flex items-center gap-2 text-[11px] text-muted-foreground`,children:[(0,d.jsx)(`span`,{className:`h-px flex-1 bg-border`}),(0,d.jsxs)(`span`,{className:`flex min-w-0 max-w-[75%] flex-col items-center text-center`,children:[(0,d.jsx)(`span`,{className:`max-w-full truncate font-medium text-foreground`,children:e}),t&&(0,d.jsx)(`span`,{children:t}),n]}),(0,d.jsx)(`span`,{className:`h-px flex-1 bg-border`})]})}function er({chat:e,thread:t,from:n,showEvents:r}){let i=Tt(t,n,e.savedAt,r);return(0,d.jsx)(Zt,{activity:e.activity,pinUserMessages:!1,speaker:C(e.subagentId)?.speaker?.(e.params),events:i})}function tr({scopeId:e,thread:t,taskId:n,scrollRef:r,onLoad:i,onContinue:a,busy:o=!1,showEvents:s=!0}){let c=Q(),{locale:f}=(0,l.useI18n)(),[p,m]=(0,u.useState)(0);(0,u.useEffect)(()=>J(()=>m(e=>e+1)),[]);let h=(0,u.useMemo)(()=>Ae(e,t,n),[e,t,n,p]),[g,_]=(0,u.useState)(0);(0,u.useEffect)(()=>_(0),[n,t]);let v=g<h.length,y=(0,u.useRef)(null),b=()=>{let e=r.current;e&&(y.current={height:e.scrollHeight,top:e.scrollTop}),i?.(),_(e=>Math.min(e+1,h.length))},x=(0,u.useRef)(b);x.current=b,(0,u.useLayoutEffect)(()=>{let e=r.current,t=y.current;y.current=null,e&&t&&(e.scrollTop=t.top+(e.scrollHeight-t.height))},[g,r]);let S=(0,u.useRef)(null);if((0,u.useEffect)(()=>{let e=r.current,t=S.current;if(!e||!t||!v||typeof IntersectionObserver>`u`)return;let n=e.scrollTop,i=!1,a=()=>{e.scrollTop<n&&(i=!0),n=e.scrollTop};e.addEventListener(`scroll`,a,{passive:!0});let o=new IntersectionObserver(e=>{i&&e.some(e=>e.isIntersecting)&&(i=!1,x.current())},{root:e,rootMargin:`40px 0px 0px 0px`});return o.observe(t),()=>{e.removeEventListener(`scroll`,a),o.disconnect()}},[r,v,g]),!h.length)return null;let C=e=>new Date(e).toLocaleString(f,{dateStyle:`medium`,timeStyle:`short`}),w=h.slice(0,g).reverse(),T=e=>{let t=h[h.indexOf(e)+1];return t?t.savedAt:Z(e)};return(0,d.jsxs)(`div`,{children:[v&&(0,d.jsx)(`div`,{ref:S,className:`flex justify-center pb-1`,children:(0,d.jsx)(l.ActionButton,{icon:`history`,label:c.earlierSession,variant:`link`,className:`text-xs`,onClick:b})}),w.map(e=>(0,d.jsxs)(`section`,{"aria-label":X(e),children:[(0,d.jsx)($n,{title:X(e),meta:(0,l.interpolate)(c.sessionOf,{at:C(Z(e))}),action:(0,d.jsx)(l.ActionButton,{label:c.continueSession,variant:`link`,className:`text-[11px]`,disabled:o,onClick:()=>a(e)})}),(0,d.jsx)(er,{chat:e,thread:t,from:T(e),showEvents:s})]},`${e.subagentId}:${e.entityId}`)),g>0&&(0,d.jsx)($n,{title:c.thisSession})]})}function nr(){return(0,u.useMemo)(()=>{let e=S().map(e=>({id:e.id,label:e.label,description:e.description,onlyWhenAnchored:e.onlyWhenAnchored,crossAgentToolIds:e.crossAgentToolIds})),t=E({attachmentsRef:void 0,collected:{},proxyFetch:l.proxyFetch}).map(e=>({name:e.name,description:e.description}));return{subagents:e,tools:t,toolNames:t.map(e=>e.name)}},[])}var rr={"invalid-pattern":`routingIssueInvalidPattern`,"duplicate-id":`routingIssueDuplicateId`,"missing-id":`routingIssueMissingId`,"unknown-subagent":`routingIssueUnknownSubagent`,"unknown-tool":`routingIssueUnknownTool`,"anchored-subagent":`routingIssueAnchoredSubagent`};function ir(e,t){return(0,l.interpolate)(e[rr[t.code]],{detail:t.detail??``})}function ar(e){let t=e.replace(/[_-]+/g,` `).trim();return t.charAt(0).toUpperCase()+t.slice(1)}function or({names:e}){return(0,d.jsx)(d.Fragment,{children:e.map(e=>(0,d.jsx)(l.Badge,{variant:`info`,children:ar(e)},e))})}var sr=e=>e instanceof Error?e.message:String(e);function cr({t:e,issues:t}){return(0,d.jsx)(d.Fragment,{children:t.map((t,n)=>(0,d.jsx)(`p`,{className:t.level===`error`?`text-xs text-destructive`:`text-xs text-warning`,children:ir(e,t)},n))})}function lr({onOpen:e,children:t}){return e?(0,d.jsx)(`button`,{type:`button`,className:`block w-full rounded-lg text-left transition hover:shadow-md focus:outline-none focus-visible:ring-2 focus-visible:ring-primary`,onClick:e,children:(0,d.jsx)(l.Card,{children:t})}):(0,d.jsx)(l.Card,{children:t})}function ur(){let e=Q(),{route:t,routing:n}=$(),r=nr(),[i,a]=(0,u.useState)(null);return{t:e,route:t,state:n,known:r,persist:async t=>{if(n.save){a(null);try{await n.save(t)}catch(t){throw a((0,l.interpolate)(e.routingSaveError,{error:sr(t)})),t}}},notices:(0,d.jsxs)(d.Fragment,{children:[n.error&&(0,d.jsx)(l.Alert,{variant:`warning`,children:(0,l.interpolate)(e.routingLoadError,{error:n.error})}),i&&(0,d.jsx)(l.Alert,{variant:`danger`,onClose:()=>a(null),children:i}),!n.save&&n.path!==null&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.routingReadOnly}),n.path===null&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.routingNoRouting})]})}}function dr({title:e,titleBefore:t,onClose:n,onSave:r,onRestore:i,errors:a,children:o}){let s=Q(),[c,f]=(0,u.useState)(!1);return(0,d.jsx)(l.Modal,{title:t?(0,d.jsxs)(`span`,{className:`flex items-center gap-3 [&_form]:m-0`,children:[t,(0,d.jsx)(`span`,{children:e})]}):e,position:`right`,size:`md`,onClose:n,footer:(0,d.jsxs)(d.Fragment,{children:[i&&(0,d.jsx)(l.ActionButton,{variant:`outline-secondary`,icon:`rotate-ccw`,label:s.routingRestore,onClick:()=>void i(),disabled:c,className:`mr-auto`}),(0,d.jsx)(l.ActionButton,{variant:`primary`,label:s.routingSave,onClick:async()=>{f(!0);try{await r()}finally{f(!1)}},disabled:c}),(0,d.jsx)(l.ActionButton,{variant:`link`,label:s.routingCancel,onClick:n})]}),children:(0,d.jsxs)(`div`,{className:`space-y-4`,children:[o,a.map((e,t)=>(0,d.jsx)(`p`,{className:`text-sm text-destructive`,children:e},t))]})})}function fr({t:e,subagent:t,routing:n,defaults:r,modified:i,known:a,onSave:o,onClose:s}){let c=n.subagents?.[t.id],f=(0,u.useRef)(0),p=e=>({key:f.current++,value:e}),[m,h]=(0,u.useState)(!c?.paths),[g,_]=(0,u.useState)(()=>(c?.paths??[]).map(p)),[v,y]=(0,u.useState)(()=>c?.tools??t.crossAgentToolIds??[]),[b,x]=(0,u.useState)($().routing.path??``),[S,C]=(0,u.useState)([]),w=Object.entries(n.tools??{}).filter(([,e])=>e.everywhere).map(([e])=>e),T=g.map(e=>e.value.trim()).filter(Boolean),E=(0,u.useMemo)(()=>({everywhere:m?`true`:``,tools:v,tryPath:b,...Object.fromEntries(g.map(e=>[`path_${e.key}`,e.value]))}),[]),D=async()=>{let r={...n,subagents:{...n.subagents,[t.id]:{...m?{}:{paths:T},tools:v.filter(e=>!w.includes(e))}}},i=Qe(r,{subagents:a.subagents,toolNames:a.toolNames}).filter(e=>e.where===`subagent`&&e.key===t.id&&e.level===`error`);if(i.length>0){C(i.map(t=>ir(e,t)));return}try{await o(r),s()}catch(t){C([(0,l.interpolate)(e.routingSaveError,{error:sr(t)})])}},ee=async()=>{try{await o({...n,subagents:{...n.subagents,[t.id]:r.subagents?.[t.id]??{}}}),s()}catch(t){C([(0,l.interpolate)(e.routingSaveError,{error:sr(t)})])}},O=b.trim()?Be(m?void 0:T,b.trim()):null;return(0,d.jsxs)(dr,{title:(0,l.interpolate)(e.routingEditOf,{label:t.label}),onClose:s,onSave:D,onRestore:i?ee:null,errors:S,children:[(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t.description}),t.onlyWhenAnchored&&(0,d.jsx)(l.Alert,{variant:`info`,children:(0,l.interpolate)(e.routingIssueAnchoredSubagent,{detail:t.label})}),(0,d.jsx)(l.Form,{appearance:`empty`,showNotice:!1,defaultValues:E,children:(0,d.jsxs)(`div`,{className:`space-y-4`,children:[(0,d.jsx)(l.Switch,{name:`everywhere`,label:e.routingFieldEverywhere,valueChecked:`true`,onChange:({value:e})=>h(!!e)}),!m&&(0,d.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,d.jsx)(`legend`,{className:`text-sm font-medium`,children:e.routingFieldPaths}),(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.routingFieldPathsFeedback}),g.length===0&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.routingNowhere}),g.map(t=>(0,d.jsxs)(`div`,{className:`flex items-end gap-1`,children:[(0,d.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,d.jsx)(l.String,{name:`path_${t.key}`,placeholder:`^/sites/[^/]+/pages/[^/]+$`,onChange:({value:e})=>_(n=>n.map(n=>n.key===t.key?{...n,value:String(e??``)}:n))})}),(0,d.jsx)(l.ActionButton,{icon:`x`,variant:`link`,title:e.routingRemovePath,ariaLabel:e.routingRemovePath,onClick:()=>_(e=>e.filter(e=>e.key!==t.key))})]},t.key)),(0,d.jsx)(l.ActionButton,{icon:`plus`,variant:`outline-secondary`,label:e.routingAddPath,onClick:()=>_(e=>[...e,p(``)])})]}),(0,d.jsx)(l.String,{name:`tryPath`,label:e.routingTryPath,feedback:e.routingTryPathFeedback,onChange:({value:e})=>x(String(e??``))}),O!==null&&(0,d.jsx)(l.Badge,{variant:O?`success`:`secondary`,children:O?e.routingOffered:e.routingNotOffered}),(0,d.jsx)(l.Checklist,{name:`tools`,label:e.routingFieldTools,options:a.tools.map(e=>({value:e.name,label:ar(e.name)})),onChange:({value:e})=>y(Array.isArray(e)?e.map(String):e?[String(e)]:[])}),w.length>0&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:(0,l.interpolate)(e.routingToolsEverywhereNote,{tools:w.map(ar).join(`, `)})})]})})]})}function pr({text:e}){return(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e})}function mr(){let{routing:e}=$(),[t,n]=(0,u.useState)(!1),[r,i]=(0,u.useState)(e.path??``),a=r.trim();return{open:t,path:r,setPath:i,filter:t&&a||null,toggle:()=>n(e=>!e)}}function hr({t:e,intro:t,tryPath:n,children:r}){return(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,d.jsx)(`p`,{className:`min-w-0 flex-1 text-xs text-muted-foreground`,children:t}),(0,d.jsx)(l.ActionButton,{icon:`search`,label:e.routingTryPath,variant:n.open?`primary`:`outline-secondary`,ariaLabel:e.routingTryPath,onClick:n.toggle}),r]})}function gr({t:e,tryPath:t,count:n,total:r}){return t.open?(0,d.jsx)(l.Form,{appearance:`empty`,showNotice:!1,defaultValues:{tryPath:t.path},children:(0,d.jsx)(l.String,{name:`tryPath`,placeholder:`/sites/acme/en/pages/home`,feedback:t.filter?(0,l.interpolate)(e.routingTryPathCount,{count:String(n),total:String(r)}):e.routingTryPathFeedback,onChange:({value:e})=>t.setPath(String(e??``))})}):null}function _r({onStack:e}){let{t,route:n,state:r,known:i,persist:a,notices:o}=ur(),s=mr(),c=s.filter===null?i.subagents:i.subagents.filter(e=>!e.onlyWhenAnchored&&Be(r.routing.subagents?.[e.id]?.paths,s.filter)),[f,p]=(0,u.useState)(null),m=(0,u.useMemo)(()=>Qe(r.routing,i),[r.routing,i]),h=t=>{p(t),e?.(t!==null)};return(0,d.jsxs)(`div`,{className:`space-y-4`,children:[o,(0,d.jsx)(hr,{t,intro:t.routingSubagentsIntro,tryPath:s}),(0,d.jsx)(gr,{t,tryPath:s,count:c.length,total:i.subagents.length}),s.filter!==null&&c.length===0&&(0,d.jsx)(pr,{text:t.routingNoMatch}),c.map(e=>{let i=r.routing.subagents?.[e.id]?.paths,a=Ue(r.routing,e),o=n&&s.filter===null?n.subagentIds.includes(e.id)&&!e.onlyWhenAnchored:null;return(0,d.jsx)(lr,{onOpen:r.save?()=>h(e):null,children:(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,d.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,d.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.id}),r.changes.subagents?.[e.id]&&(0,d.jsx)(l.Badge,{variant:`warning`,children:t.routingModified}),e.onlyWhenAnchored?(0,d.jsx)(l.Badge,{variant:`info`,className:`ml-auto`,children:t.routingOnlyAnchored}):o!==null&&(0,d.jsx)(l.Badge,{variant:o?`success`:`secondary`,className:`ml-auto`,children:o?t.routingOffered:t.routingNotOffered})]}),(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}),(0,d.jsxs)(`div`,{className:`grid grid-cols-[7rem_1fr] gap-1 text-xs`,children:[(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:t.routingWhere}),(0,d.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[!i&&(0,d.jsx)(`span`,{children:t.routingEverywhere}),i?.length===0&&(0,d.jsx)(`span`,{children:t.routingNowhere}),i?.map((e,t)=>(0,d.jsx)(`code`,{className:`break-all rounded bg-muted px-1.5 py-0.5`,children:e},t))]}),(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:t.routingUses}),(0,d.jsxs)(`span`,{className:`flex flex-wrap gap-1`,children:[a.length===0&&(0,d.jsx)(`span`,{children:t.routingNoTools}),(0,d.jsx)(or,{names:a})]})]}),(0,d.jsx)(cr,{t,issues:m.filter(t=>t.where===`subagent`&&t.key===e.id)})]})},e.id)}),f&&(0,d.jsx)(fr,{t,subagent:f,routing:r.routing,defaults:r.defaults,modified:!!r.changes.subagents?.[f.id],known:i,onSave:a,onClose:()=>h(null)})]})}function vr({t:e,tool:t,routing:n,known:r,onSave:i,onClose:a}){let o=r.subagents.filter(e=>(n.subagents?.[e.id]?.tools??e.crossAgentToolIds??[]).includes(t.name)).map(e=>e.id),[s,c]=(0,u.useState)(!!n.tools?.[t.name]?.everywhere),[f,p]=(0,u.useState)(o),[m,h]=(0,u.useState)([]),g=(0,u.useMemo)(()=>({everywhere:s?`true`:``,users:f}),[]);return(0,d.jsxs)(dr,{title:(0,l.interpolate)(e.routingEditOf,{label:ar(t.name)}),onClose:a,onSave:async()=>{let o={...n.subagents};for(let e of r.subagents){let r=n.subagents?.[e.id]?.tools??e.crossAgentToolIds??[],i=f.includes(e.id);i!==r.includes(t.name)&&(o[e.id]={...n.subagents?.[e.id],tools:i?[...r,t.name]:r.filter(e=>e!==t.name)})}let c={...n.tools,[t.name]:{everywhere:s}};try{await i({...n,subagents:o,tools:c}),a()}catch(t){h([(0,l.interpolate)(e.routingSaveError,{error:sr(t)})])}},errors:m,children:[(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t.description}),(0,d.jsx)(l.Form,{appearance:`empty`,showNotice:!1,defaultValues:g,children:(0,d.jsxs)(`div`,{className:`space-y-4`,children:[(0,d.jsx)(l.Switch,{name:`everywhere`,label:e.routingFieldAllSubagents,valueChecked:`true`,onChange:({value:e})=>c(!!e)}),!s&&(0,d.jsx)(l.Checklist,{name:`users`,label:e.routingFieldUsedBy,options:r.subagents.map(e=>({value:e.id,label:e.label})),onChange:({value:e})=>p(Array.isArray(e)?e.map(String):e?[String(e)]:[])})]})})]})}function yr({onStack:e}){let{t,route:n,state:r,known:i,persist:a,notices:o}=ur(),s=mr(),c=(0,u.useMemo)(()=>s.filter===null?null:We(r.routing,s.filter,S()).toolNames,[s.filter,r.routing]),f=c===null?i.tools:i.tools.filter(e=>c.includes(e.name)),[p,m]=(0,u.useState)(null),h=t=>{m(t),e?.(t!==null)};return(0,d.jsxs)(`div`,{className:`space-y-4`,children:[o,(0,d.jsx)(hr,{t,intro:t.routingToolsIntro,tryPath:s}),(0,d.jsx)(gr,{t,tryPath:s,count:f.length,total:i.tools.length}),c!==null&&f.length===0&&(0,d.jsx)(pr,{text:t.routingNoMatch}),f.map(e=>{let a=!!r.routing.tools?.[e.name]?.everywhere,o=i.subagents.filter(t=>Ue(r.routing,t).includes(e.name)),c=n&&s.filter===null?n.toolNames.includes(e.name):null;return(0,d.jsx)(lr,{onOpen:r.save?()=>h(e):null,children:(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,d.jsx)(`span`,{className:`font-medium`,children:ar(e.name)}),(0,d.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.name}),r.changes.tools?.[e.name]&&(0,d.jsx)(l.Badge,{variant:`warning`,children:t.routingModified}),c!==null&&(0,d.jsx)(l.Badge,{variant:c?`success`:`secondary`,className:`ml-auto`,children:c?t.routingOffered:t.routingNotOffered})]}),(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}),(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 text-xs`,children:[(0,d.jsx)(`span`,{className:`mr-1 text-muted-foreground`,children:t.routingUsedBy}),a&&(0,d.jsx)(l.Badge,{variant:`primary`,children:t.routingAllSubagents}),!a&&o.length===0&&(0,d.jsx)(`span`,{children:t.routingNoSubagents}),!a&&o.map(e=>(0,d.jsx)(l.Badge,{variant:`primary`,children:e.label},e.id))]})]})},e.name)}),p&&(0,d.jsx)(vr,{t,tool:p,routing:r.routing,known:i,onSave:a,onClose:()=>h(null)})]})}function br(e){return{id:e?.id??``,label:e?.label??``,pattern:e?.pattern??``,flags:e?.flags??``,context:e?.context??``,active:e?.disabled?``:`true`}}function xr(e){let t=e=>String(e??``).trim(),n=t(e.label),r=t(e.flags),i=t(e.context);return{id:t(e.id),...n?{label:n}:{},pattern:t(e.pattern),...r?{flags:r}:{},...i?{context:i}:{},...e.active?{}:{disabled:!0}}}var Sr={default:`secondary`,modified:`warning`,added:`info`};function Cr({t:e,rule:t,index:n,pages:r,routing:i,known:a,onSave:o,onClose:s}){let c=(0,l.useFormController)(),f=(0,u.useMemo)(()=>br(t),[t]),[p,m]=(0,u.useState)(f.active),[h,g]=(0,u.useState)([]);return(0,d.jsxs)(dr,{title:t?(0,l.interpolate)(e.routingEditOf,{label:t.label??t.id}):e.routingNewRule,titleBefore:(0,d.jsx)(l.Form,{appearance:`empty`,showNotice:!1,defaultValues:{active:f.active},children:(0,d.jsx)(l.Switch,{name:`active`,valueChecked:`true`,title:e.routingFieldActiveFeedback,ariaLabel:e.routingFieldActive,inheritWrapperClassName:!1,wrapperClassName:`m-0`,onChange:({value:e})=>m(e?`true`:``)})}),onClose:s,onSave:async()=>{let u=xr({...f,...c.record??{},active:p,...t?{id:t.id}:{}}),d=t?n:0,m=t?r.map((e,t)=>t===n?u:e):[u,...r],h=Qe({pages:m},a).filter(e=>e.where===`page`&&e.index===d&&e.level===`error`).map(t=>ir(e,t));if(u.pattern||h.push((0,l.interpolate)(e.routingIssueInvalidPattern,{detail:e.routingPatternRequired})),h.length>0){g(h);return}try{await o({...i,pages:m}),s()}catch(t){g([(0,l.interpolate)(e.routingSaveError,{error:sr(t)})])}},errors:h,children:[!p&&(0,d.jsx)(l.Alert,{variant:`warning`,children:e.routingFieldActiveFeedback}),(0,d.jsx)(l.Form,{controller:c,appearance:`empty`,showNotice:!1,defaultValues:f,children:(0,d.jsxs)(`div`,{className:`space-y-3`,children:[!t&&(0,d.jsx)(l.String,{name:`id`,label:e.routingFieldId,feedback:e.routingFieldIdFeedback,required:!0}),(0,d.jsx)(l.String,{name:`label`,label:e.routingFieldLabel}),(0,d.jsx)(l.String,{name:`pattern`,label:e.routingFieldPattern,feedback:e.routingFieldPatternFeedback,required:!0}),(0,d.jsx)(l.TextArea,{name:`context`,label:e.routingContext,feedback:e.routingFieldContextFeedback,minHeight:120})]})})]})}function wr({onStack:e}){let{t,state:n,known:r,persist:i,notices:a}=ur(),o=n.pages,s=(0,u.useMemo)(()=>Qe({pages:o},r),[o,r]),[c,f]=(0,u.useState)(null),p=t=>{f(t),e?.(t!==null)},m=()=>o.map(({origin:e,defaultRule:t,...n})=>n),h=e=>{i({...n.routing,pages:e}).catch(()=>void 0)},g=(e,t)=>{let n=m(),[r]=n.splice(e,1);n.splice(e+t,0,r),h(n)},_=n.path===null?null:He(o,n.path),v=mr(),y=v.filter===null?null:He(o,v.filter),b=v.filter===null?null:new Set(o.filter(e=>He([e],v.filter)).map(e=>e.id)),x=y?o.findIndex(e=>e.id===y.rule.id):-1;return(0,d.jsxs)(`div`,{className:`space-y-4`,children:[a,(0,d.jsx)(hr,{t,intro:t.routingPagesIntro,tryPath:v,children:n.save&&(0,d.jsx)(l.ActionButton,{icon:`plus`,label:t.routingNewRule,variant:`outline-secondary`,onClick:()=>p({rule:null,index:0})})}),(0,d.jsx)(gr,{t,tryPath:v,count:b?.size??0,total:o.length}),b!==null&&b.size===0&&(0,d.jsx)(pr,{text:t.routingNoMatch}),o.map((e,r)=>{if(b!==null&&!b.has(e.id))return null;let i={default:t.routingOriginDefault,modified:t.routingOriginModified,added:t.routingOriginAdded}[e.origin];return(0,d.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,d.jsx)(`span`,{className:`mt-4 w-5 shrink-0 text-right text-xs tabular-nums text-muted-foreground`,children:r+1}),(0,d.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,d.jsx)(lr,{onOpen:n.save?()=>p({rule:e,index:r}):null,children:(0,d.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,d.jsx)(`span`,{className:`text-sm font-medium`,children:e.label??e.id}),(0,d.jsx)(l.Badge,{variant:Sr[e.origin],children:i}),e.disabled&&(0,d.jsx)(l.Badge,{variant:`dark`,children:t.routingRuleOff}),b===null&&_?.rule.id===e.id&&(0,d.jsx)(l.Badge,{variant:`success`,className:`ml-auto`,children:t.routingHereBadge}),b!==null&&(r===x?(0,d.jsx)(l.Badge,{variant:`success`,className:`ml-auto`,children:t.routingApplies}):(0,d.jsx)(l.Badge,{variant:`secondary`,className:`ml-auto`,children:(0,l.interpolate)(t.routingOverridden,{n:String(x+1)})}))]}),(0,d.jsxs)(`code`,{className:`block break-all rounded bg-muted px-2 py-1 text-xs`,children:[e.pattern,e.flags?` /${e.flags}`:``]}),e.context&&(0,d.jsx)(`p`,{className:`whitespace-pre-wrap text-xs text-muted-foreground`,children:r===x&&y?.context?y.context:e.context}),(0,d.jsx)(cr,{t,issues:s.filter(e=>e.index===r)})]})})}),n.save&&(0,d.jsxs)(`div`,{className:`mt-2 flex shrink-0 flex-col`,children:[(0,d.jsx)(l.ActionButton,{icon:`arrow-up`,title:t.routingMoveUp,ariaLabel:t.routingMoveUp,variant:`link`,disabled:r===0,onClick:()=>g(r,-1)}),(0,d.jsx)(l.ActionButton,{icon:`arrow-down`,title:t.routingMoveDown,ariaLabel:t.routingMoveDown,variant:`link`,disabled:r===o.length-1,onClick:()=>g(r,1)}),e.origin===`modified`&&(0,d.jsx)(l.ActionButton,{icon:`rotate-ccw`,title:t.routingRestore,ariaLabel:t.routingRestore,variant:`link`,onClick:()=>h(m().map((t,n)=>n===r&&e.defaultRule?e.defaultRule:t))}),e.origin===`added`&&(0,d.jsx)(l.ActionButton,{icon:`trash-2`,title:t.routingRemove,ariaLabel:t.routingRemove,variant:`link`,onClick:()=>h(m().filter((e,t)=>t!==r))})]})]},e.id)}),c&&(0,d.jsx)(Cr,{t,rule:c.rule,index:c.index,pages:m(),routing:n.routing,known:r,onSave:i,onClose:()=>p(null)})]})}var Tr=e=>e instanceof Error?e.message:String(e);function Er(e){let[t,n]=(0,u.useState)(null),[r,i]=(0,u.useState)(null);return(0,u.useEffect)(()=>{if(!e)return;let t=!0;return e.me().then(e=>{t&&n(e)},e=>{t&&i(Tr(e))}),()=>{t=!1}},[e]),{me:t,error:r}}function Dr({backend:e,me:t,cloud:n}){let r=Q(),{locale:i}=(0,l.useI18n)(),a=t.role===`platform`,o=(0,u.useMemo)(()=>n?.store??e.connections(),[e,n?.store]),[s,c]=(0,u.useState)(null),[f,m]=(0,u.useState)(null),[h,g]=(0,u.useState)(null),[_,v]=(0,u.useState)(null),y=(0,u.useCallback)(async()=>{try{c((await o.load()).providers.length),a&&m(await e.fleet.list()),g(null)}catch(e){g(Tr(e))}},[e,o,a]);(0,u.useEffect)(()=>{y()},[y]);let b=()=>{v(null),y()};return(0,d.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r.connectionsIntro}),h&&(0,d.jsx)(l.Alert,{variant:`danger`,children:(0,l.interpolate)(r.connectionsError,{error:h})}),(0,d.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,d.jsx)(l.ListCard,{icon:`cloud`,title:r.cloudTitle,description:r.cloudDescription,badge:s?(0,d.jsx)(l.Badge,{variant:`success`,children:(0,l.interpolate)(r.cloudConnected,{count:s})}):(0,d.jsx)(l.Badge,{variant:`light`,children:r.cloudNone}),onClick:()=>v(`cloud`)}),a&&f?.map(e=>(0,d.jsx)(l.ListCard,{icon:`server`,title:e.name,description:e.url,badge:e.draining?(0,d.jsx)(l.Badge,{variant:`warning`,children:r.runnerDraining}):e.isDefault?(0,d.jsx)(l.Badge,{variant:`info`,children:r.runnerDefault}):void 0,onClick:()=>v({runner:e})},e.id)),!a&&(0,d.jsx)(l.ListCard,{icon:`server`,title:r.runnerOfProject,description:r.runnerOfProjectDescription,onClick:()=>v(`mine`)}),a&&(0,d.jsx)(l.ListCard,{icon:`plus`,dashed:!0,title:r.runnerAdd,description:r.runnerAddDescription,onClick:()=>v(`add`)})]}),_===`cloud`&&(0,d.jsx)(l.Modal,{title:r.cloudTitle,size:`xl`,onClose:b,footer:(0,d.jsx)(l.ActionButton,{variant:`link`,label:r.settingsClose,onClick:b}),children:(0,d.jsx)(l.AIConnections,{...n??{},store:o,readOnly:n?.readOnly??t.role===`member`})}),_===`mine`&&(0,d.jsx)(l.Modal,{title:r.runnerOfProject,size:`lg`,onClose:b,footer:(0,d.jsx)(l.ActionButton,{variant:`link`,label:r.settingsClose,onClick:b}),children:(0,d.jsx)(p.RunnerAccounts,{client:e.runner(),scope:`user`,locale:i})}),_===`add`&&(0,d.jsx)(p.AddRunner,{fleet:e.fleet,t:(0,p.textsFor)(i),locale:i,onClose:b,onAdded:b}),_&&typeof _==`object`&&(0,d.jsx)(Or,{backend:e,runner:_.runner,onClose:b})]})}function Or({backend:e,runner:t,onClose:n}){let r=Q(),{locale:i}=(0,l.useI18n)(),[a,o]=(0,u.useState)(null),[s,c]=(0,u.useState)(null),[f,m]=(0,u.useState)(!1);(0,u.useEffect)(()=>{let n=!0;return e.fleet.status(t.id).then(e=>{n&&o(e)},e=>{n&&c(Tr(e))}),()=>{n=!1}},[e,t.id]);let h=n=>e.fleet.update(t.id,n).catch(e=>c(Tr(e)));return(0,d.jsxs)(l.Modal,{title:t.name,size:`lg`,onClose:n,footer:(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(l.ActionButton,{variant:`outline-danger`,icon:`trash`,label:r.runnerRemove,onClick:()=>m(!0)}),(0,d.jsx)(l.ActionButton,{variant:`link`,label:r.settingsClose,onClick:n})]}),children:[(0,d.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[s&&(0,d.jsx)(l.Alert,{variant:`danger`,children:(0,l.interpolate)(r.runnerUnreachable,{error:s})}),(0,d.jsx)(l.DescriptionList,{items:[{label:`URL`,value:t.url},{label:r.runnerVersion,value:a?.version??`…`},{label:r.runnerLoad,value:a?(0,l.interpolate)(r.runnerLoadValue,{chats:a.load.chats,max:a.load.maxChats}):`…`}]}),(0,d.jsx)(l.Form,{appearance:`empty`,showNotice:!1,onSubmit:()=>!1,children:(0,d.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,d.jsx)(l.Switch,{name:`isDefault`,label:r.runnerSetDefault,defaultValue:t.isDefault?`on`:``,onChange:({value:e})=>void h({isDefault:!!e})}),(0,d.jsx)(l.Switch,{name:`draining`,label:r.runnerSetDraining,defaultValue:t.draining?`on`:``,onChange:({value:e})=>void h({draining:!!e})})]})}),(0,d.jsx)(p.RunnerAccounts,{client:e.runnerOfNamespace(),scope:`tenant`,locale:i})]}),f&&(0,d.jsx)(l.ModalYesNo,{title:r.runnerRemove,danger:!0,onClose:()=>m(!1),onYes:async()=>{try{await e.fleet.remove(t.id),n()}catch(e){c(Tr(e))}return m(!1),!0},children:(0,l.interpolate)(r.runnerRemoveConfirm,{name:t.name})})]})}var kr=(e,t)=>t.ok?e.memoryOk:t.error===`rejected`?e.memoryRejected:t.error===`unreachable`?e.memoryUnreachable:e.memoryInvalid;function Ar({backend:e}){let t=Q(),[n,r]=(0,u.useState)(null),[i,a]=(0,u.useState)(null),[o,s]=(0,u.useState)(null),c=(0,u.useCallback)(async()=>{try{r(await e.memories.list()),a(null)}catch(e){a(Tr(e))}},[e]);return(0,u.useEffect)(()=>{c()},[c]),(0,d.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t.memoryIntro}),i&&(0,d.jsx)(l.Alert,{variant:`danger`,children:(0,l.interpolate)(t.connectionsError,{error:i})}),n&&!n.length&&(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t.memoryNone}),(0,d.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[n?.map(e=>(0,d.jsx)(l.ListCard,{icon:`database`,title:e.name,description:e.apiUrl,meta:e.mcpUrl,onClick:()=>s(e)},e.id)),(0,d.jsx)(l.ListCard,{icon:`plus`,dashed:!0,title:t.memoryAdd,description:t.memoryAddDescription,onClick:()=>s(`add`)})]}),o&&(0,d.jsx)(jr,{backend:e,memory:o===`add`?null:o,onClose:()=>{s(null),c()}})]})}function jr({backend:e,memory:t,onClose:n}){let r=Q(),[i,a]=(0,u.useState)({name:t?.name??``,apiUrl:t?.apiUrl??``,mcpUrl:t?.mcpUrl??``,key:``}),[o,s]=(0,u.useState)(null),[c,f]=(0,u.useState)(!1),p=e=>({value:t})=>a(n=>({...n,[e]:String(t??``)})),m=e=>s({variant:`danger`,text:(0,l.interpolate)(r.connectionsError,{error:Tr(e)})});return(0,d.jsxs)(l.Modal,{title:t?.name??r.memoryAdd,size:`lg`,onClose:n,footer:(0,d.jsxs)(d.Fragment,{children:[t&&(0,d.jsx)(l.ActionButton,{variant:`outline-danger`,icon:`trash`,label:r.memoryRemove,onClick:()=>f(!0)}),(0,d.jsx)(l.LoadingButton,{variant:`outline-primary`,label:r.memoryCheck,disabled:!i.apiUrl.trim()||!i.key.trim(),onClick:async()=>{let t=await e.memories.check({apiUrl:i.apiUrl,key:i.key}).catch(e=>({ok:!1,error:`unreachable`,failure:e}));s({variant:t.ok?`success`:`danger`,text:kr(r,t)})}}),(0,d.jsx)(l.LoadingButton,{variant:`primary`,label:r.memorySave,disabled:t?!1:!i.apiUrl.trim()||!i.key.trim(),onClick:async()=>{try{t?await e.memories.update(t.id,{name:i.name,mcpUrl:i.mcpUrl||null,...i.key.trim()?{key:i.key}:{}}):await e.memories.add({name:i.name,apiUrl:i.apiUrl,mcpUrl:i.mcpUrl||void 0,key:i.key}),n()}catch(e){m(e)}}})]}),children:[(0,d.jsx)(l.Form,{appearance:`empty`,showNotice:!1,onSubmit:()=>!1,children:(0,d.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[o&&(0,d.jsx)(l.Alert,{variant:o.variant,children:o.text}),(0,d.jsx)(l.String,{name:`name`,label:r.memoryName,defaultValue:i.name,onChange:p(`name`)}),(0,d.jsx)(l.String,{name:`apiUrl`,label:r.memoryApiUrl,placeholder:`https://memory.example.com`,defaultValue:i.apiUrl,disabled:!!t,onChange:p(`apiUrl`)}),(0,d.jsx)(l.String,{name:`mcpUrl`,label:r.memoryMcpUrl,placeholder:`https://memory.example.com/mcp`,defaultValue:i.mcpUrl,onChange:p(`mcpUrl`)}),(0,d.jsx)(l.Password,{name:`key`,label:r.memoryKey,autoComplete:`off`,onChange:p(`key`)}),t&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r.memoryKeyKeep})]})}),c&&t&&(0,d.jsx)(l.ModalYesNo,{title:r.memoryRemove,danger:!0,onClose:()=>f(!1),onYes:async()=>{try{await e.memories.remove(t.id),n()}catch(e){m(e)}return f(!1),!0},children:(0,l.interpolate)(r.memoryRemoveConfirm,{name:t.name})})]})}function Mr({backend:e,me:t}){let n=Q(),r=t.role===`platform`,[i,a]=(0,u.useState)(null),[o,s]=(0,u.useState)([]),[c,f]=(0,u.useState)([]),[p,m]=(0,u.useState)(null),h=(0,u.useCallback)(async()=>{try{let[t,n,i]=await Promise.all([e.projects.list(),r?e.fleet.list():Promise.resolve([]),r?e.memories.list():Promise.resolve([])]);a(t.namespaces),s(n),f(i),m(null)}catch(e){m(Tr(e))}},[e,r]);(0,u.useEffect)(()=>{h()},[h]);let g=async(t,n)=>{try{await e.projects.set(t,n),await h()}catch(e){m(Tr(e))}};return(0,d.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n.projectsIntro}),!r&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n.projectsReadOnly}),p&&(0,d.jsx)(l.Alert,{variant:`danger`,children:(0,l.interpolate)(n.connectionsError,{error:p})}),i?.map(e=>(0,d.jsxs)(`div`,{className:`grid gap-3 rounded-md border border-border p-3 sm:grid-cols-[1fr_12rem_12rem] sm:items-end`,children:[(0,d.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,d.jsx)(`span`,{className:`font-medium`,children:e.name??e.tenant??e.namespace}),(0,d.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:e.namespace})]}),r?(0,d.jsxs)(l.Form,{appearance:`empty`,showNotice:!1,onSubmit:()=>!1,className:`contents`,children:[(0,d.jsx)(l.Select,{name:`runner-${e.namespace}`,label:n.projectsRunner,defaultValue:e.runner?.id??``,placeholderOption:{label:n.projectsDefaultRunner,value:``},options:o.map(e=>({label:e.name,value:e.id})),onChange:({value:t})=>{t&&g(e.namespace,{runnerId:String(t)})}}),(0,d.jsx)(l.Select,{name:`memory-${e.namespace}`,label:n.projectsMemory,defaultValue:e.memory?.id??``,placeholderOption:{label:n.projectsNoMemory,value:``},options:c.map(e=>({label:e.name,value:e.id})),onChange:({value:t})=>void g(e.namespace,{memoryId:t?String(t):null})})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`span`,{className:`text-sm`,children:e.runner?.name??n.projectsDefaultRunner}),(0,d.jsx)(`span`,{className:`text-sm`,children:e.memory?.name??n.projectsNoMemory})]})]},e.namespace))]})}var Nr=[`low`,`medium`,`high`,`max`];function Pr(){let{shown:e,connections:t,backend:n}=ct();return e.length>0||!!t||!!n||S().length>0}function Fr(){let e=Q(),{settings:t,shown:n,connections:r,tabs:i,backend:a,save:o,isOpen:s,close:c}=ct(),{me:f}=Er(s?a:void 0),p=(0,l.useFormController)(),m=(0,l.useAIProviderRegistry)()?.registry??{},{modelsByProvider:h}=Sn({unfiltered:!0}),[g,_]=(0,u.useState)(0),[v,y]=(0,u.useState)(!1);if(!s)return null;let b=S().length>0,x=Object.keys(m),C=e=>m[e]?.label??e,w=Object.values(h).flat(),T={low:e.settingsReasoningLow,medium:e.settingsReasoningMedium,high:e.settingsReasoningHigh,max:e.settingsReasoningMax},E=e=>n.includes(e),D={defaultModel:t.defaultModel??``,reasoning:t.reasoning??``,chatTitles:t.chatTitles?`on`:``,threadEvents:t.threadEvents?`on`:``,...Object.fromEntries(x.map(e=>[`provider_${e}`,!t.providers||t.providers.includes(e)?`on`:``]))};return(0,d.jsx)(l.Modal,{title:e.settingsTitle,position:`right`,size:`lg`,stackedBehind:v,onClose:c,footer:(0,d.jsxs)(d.Fragment,{children:[n.length>0&&g===0&&(0,d.jsx)(l.LoadingButton,{variant:`primary`,label:e.settingsSave,onClick:e=>p.save(e)}),(0,d.jsx)(l.ActionButton,{variant:`link`,label:e.settingsClose,onClick:c})]}),children:(0,d.jsx)(l.Tab,{defaultIndex:0,onChange:_,contentClassName:`pt-4`,children:[n.length>0&&(0,d.jsx)(l.TabItem,{label:e.settingsChats,children:(0,d.jsx)(l.Form,{appearance:`empty`,controller:p,showNotice:!1,defaultValues:D,onSave:async({record:e})=>{let t=t=>String(e?.[t]??``),n=x.filter(e=>t(`provider_${e}`)===`on`);await o({...E(`defaultModel`)?{defaultModel:t(`defaultModel`)||void 0}:{},...E(`reasoning`)?{reasoning:t(`reasoning`)||void 0}:{},...E(`providers`)?{providers:n.length===x.length?void 0:n}:{},...E(`chatTitles`)?{chatTitles:t(`chatTitles`)===`on`}:{},...E(`threadEvents`)?{threadEvents:t(`threadEvents`)===`on`}:{}}),c()},children:(0,d.jsxs)(`div`,{className:`space-y-3`,children:[E(`defaultModel`)&&(0,d.jsx)(l.Select,{name:`defaultModel`,label:e.settingsDefaultModel,placeholderOption:{label:e.settingsDefaultModelNone,value:``},options:w.map(e=>({label:`${e.providerLabel??e.provider} / ${e.model}`,value:e.id}))}),E(`reasoning`)&&(0,d.jsx)(l.Select,{name:`reasoning`,label:e.settingsReasoning,placeholderOption:{label:e.settingsReasoningDefault,value:``},options:Nr.map(e=>({label:T[e],value:e}))}),E(`providers`)&&x.length>0&&(0,d.jsxs)(`fieldset`,{className:`space-y-1`,children:[(0,d.jsx)(`legend`,{className:`text-sm font-medium`,children:e.settingsProviders}),x.map(e=>(0,d.jsx)(l.Switch,{name:`provider_${e}`,label:C(e)},e))]}),E(`chatTitles`)&&(0,d.jsx)(l.Switch,{name:`chatTitles`,label:e.settingsChatTitles}),E(`threadEvents`)&&(0,d.jsx)(l.Switch,{name:`threadEvents`,label:e.settingsThreadEvents})]})})},`chats`),b&&(0,d.jsx)(l.TabItem,{label:e.settingsSubagents,children:(0,d.jsx)(_r,{onStack:y})},`subagents`),b&&(0,d.jsx)(l.TabItem,{label:e.settingsTools,children:(0,d.jsx)(yr,{onStack:y})},`tools`),b&&(0,d.jsx)(l.TabItem,{label:e.settingsPages,children:(0,d.jsx)(wr,{onStack:y})},`pages`),a&&f&&(0,d.jsx)(l.TabItem,{label:e.connectionsTab,children:(0,d.jsx)(Dr,{backend:a,me:f,...r?{cloud:r}:{}})},`connections`),a&&f?.role===`platform`&&(0,d.jsx)(l.TabItem,{label:e.memoryTab,children:(0,d.jsx)(Ar,{backend:a})},`memory`),a&&f&&f.role!==`member`&&(0,d.jsx)(l.TabItem,{label:e.projectsTab,children:(0,d.jsx)(Mr,{backend:a,me:f})},`projects`),r&&!a&&(0,d.jsx)(l.TabItem,{label:e.settingsConnectors,children:(0,d.jsx)(l.AIConnections,{...r})},`connectors`),...(i??[]).map(e=>(0,d.jsx)(l.TabItem,{label:e.label,children:e.render()},`host-${e.id}`))].filter(Boolean)})})}function Ir(e,t){return Object.values(e).flat().map(e=>{let n=t?.(e.provider,e.providerLabel??e.provider);return{label:e.model,value:e.id,pricing:e.pricing??null,group:n?.group??e.providerLabel??e.provider,...n?.badge?{groupBadge:n.badge}:{}}})}function Lr({task:e,editing:t,onCancelEdit:n,onSendEdit:r}){let i=Q(),[a,o]=(0,u.useState)(``),{agent:s,onApplied:c,manualEntry:f}=e,p=s.running;(0,u.useEffect)(()=>{t&&o(t.detail??``)},[t]);let{draft:m}=$(),h=(0,u.useRef)(m?.nonce??0);(0,u.useEffect)(()=>{m&&m.nonce!==h.current&&(h.current=m.nonce,o(m.text))},[m]);let g=e=>{if(o(``),t&&r){r(t,e.text);return}if(f){f.onSubmit(e.text);return}s.sendMessage(e.text,{attachments:e.files,model:e.model}).then(e=>{e&&c(e)})},_=!!f||s.remote&&s.remoteModels.length===0,v=s.alongside&&s.remoteModels.some(e=>e.value===s.selectedModel),y=!_&&!s.remote&&!v&&s.hasProviders&&!s.selectedModel,b=_?[]:s.remote?s.remoteModels:s.alongside?[...s.remoteModels,...Ir(s.modelsByProvider,s.catalogGroup)]:Ir(s.modelsByProvider);return(0,d.jsxs)(d.Fragment,{children:[t&&(0,d.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,d.jsx)(l.Icon,{name:`pencil`,size:12,className:`shrink-0`}),(0,d.jsx)(`span`,{className:`flex-1`,children:i.editingMessage}),(0,d.jsx)(l.ActionButton,{label:i.cancelEdit,variant:`link`,className:`p-0 text-xs`,onClick:()=>{o(``),n?.()}})]}),(0,d.jsx)(l.Chatbot,{value:a,onChange:o,placeholder:f?.prompt??i.messagePlaceholder,running:p,onStop:s.stop,disabled:!a.trim()||y,onSubmit:g,attachments:!f&&(s.remote||v?s.executorAttachments:!0),models:b,selectedModel:_?``:s.selectedModel,actions:e.composerActions,commands:e.composerCommands,onModelChange:s.setSelectedModel,modelPlaceholder:i.selectModelPlaceholder,minHeight:44,maxHeight:220})]})}function Rr(){let{startOrchestrator:e}=$(),t=Q(),[n,r]=(0,u.useState)(``),{hasProviders:i,modelsByProvider:a,selectedModel:o,setSelectedModel:s}=Sn(),c=ut(),f=t=>{t.text.trim()&&(e(t.text.trim(),{attachments:t.files.length>0?t.files:void 0,model:t.model||void 0}),r(``))},p=i&&!o;return(0,d.jsx)(l.Chatbot,{value:n,onChange:r,placeholder:t.orchestratorStarterPlaceholder,disabled:!n.trim()||p,onSubmit:f,attachments:!0,models:[...c?.models()??[],...Ir(a)],selectedModel:o,onModelChange:s,modelPlaceholder:t.selectModelPlaceholder,minHeight:44,maxHeight:220})}function zr({chat:e,onClose:t}){let n=Q(),r=(0,l.useFormController)();return(0,d.jsx)(l.Modal,{title:n.renameChat,size:`sm`,onClose:t,onSave:()=>(Te(e.scopeId,e.subagentId,e.entityId,String(r.record?.title??X(e)),`person`),t(),Promise.resolve(!0)),children:(0,d.jsxs)(l.Form,{appearance:`empty`,controller:r,defaultValues:{title:X(e)},footer:!1,children:[(0,d.jsx)(l.Input,{name:`title`,label:n.chatTitleLabel,placeholder:e.title}),(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n.chatTitleHint})]})})}function Br(e,t,n=Date.now()){let r=Math.round((e-n)/1e3),i=new Intl.RelativeTimeFormat(t,{numeric:`auto`,style:`short`});for(let[e,t]of[[`day`,86400],[`hour`,3600],[`minute`,60]])if(Math.abs(r)>=t)return i.format(Math.round(r/t),e);return i.format(0,`minute`)}function Vr({card:e}){let t=Q();return e.humanSummaryOnly?(0,d.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border/60 p-3`,children:[(0,d.jsxs)(`p`,{className:`text-xs font-medium text-foreground`,children:[`"`,e.label,`"`]}),(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.humanSummary})]}):(0,d.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-border/60 p-3`,children:[(0,d.jsx)(`p`,{className:`text-xs font-medium text-foreground`,children:(0,l.interpolate)(t.newInstance,{label:e.label})}),(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.humanSummary}),e.fields.length>0&&(0,d.jsx)(`ul`,{className:`space-y-1`,children:e.fields.map(e=>(0,d.jsxs)(`li`,{className:`flex items-start gap-1.5 text-xs`,children:[(0,d.jsx)(l.Badge,{variant:e.required?`primary`:`secondary`,className:`mt-px shrink-0`,children:e.required?`richiesto`:`opzionale`}),(0,d.jsxs)(`span`,{className:`min-w-0`,children:[(0,d.jsx)(`span`,{className:`font-mono text-foreground`,children:e.key}),e.humanDescription?(0,d.jsxs)(`span`,{className:`text-muted-foreground`,children:[` — `,e.humanDescription]}):null]})]},e.key))}),e.example&&(0,d.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Esempio: `,(0,d.jsx)(`span`,{className:`font-mono`,children:e.example})]})]})}function Hr({messages:e}){return(0,d.jsx)(`div`,{className:`space-y-2 rounded-lg border border-border/60 p-3`,children:e.map((e,t)=>(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e},t))})}function Ur({scopeId:e,currentTaskId:t,open:n,onOpenChange:r,onSelect:i,onNewChat:a,onArchivedCurrent:o}){let s=Q(),{locale:c}=(0,l.useI18n)(),[f,p]=(0,u.useState)(``),[m,h]=(0,u.useState)(0);(0,u.useEffect)(()=>J(()=>h(e=>e+1)),[]);let g=(0,u.useMemo)(()=>n?De(e):[],[e,n,m]),[_,v]=(0,u.useState)(null),y=async n=>{let r=C(n.subagentId),i=await r?.confirmArchive?.(n.entityId,n.params);if(!i||window.confirm(i)){try{await r?.onArchive?.(n.entityId,n.params)}catch{return}Ee(e,n.subagentId,n.entityId),t===Oe(n.subagentId,n.entityId)&&o(),h(e=>e+1)}},b=(0,u.useMemo)(()=>{let e=f.trim().toLowerCase();return e?g.filter(t=>{let n=C(t.subagentId)?.label??t.subagentId;return X(t).toLowerCase().includes(e)||n.toLowerCase().includes(e)}):g},[g,f]);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(l.Dropdown,{trigger:{icon:`history`,title:s.chatHistory},triggerClassName:`!h-9 !w-9 !p-0 rounded-md bg-transparent text-muted-foreground hover:bg-accent hover:text-foreground`,open:n,onOpenChange:r,position:`end`,strategy:`absolute`,menuClassName:`w-[380px] max-h-[70vh] overflow-y-auto`,header:(0,d.jsxs)(`div`,{className:`flex items-center gap-2 px-1 pb-1.5`,children:[(0,d.jsx)(l.Icon,{name:`search`,size:14,className:`shrink-0 text-muted-foreground`}),(0,d.jsx)(`input`,{autoFocus:!0,value:f,onChange:e=>p(e.target.value),placeholder:s.searchChats,className:`min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground`}),(0,d.jsx)(l.ActionButton,{icon:`square-pen`,ariaLabel:s.newChat,title:s.newChat,variant:`link`,className:`shrink-0`,onClick:a})]}),children:b.length===0?(0,d.jsx)(`p`,{className:`px-2 py-3 text-center text-xs text-muted-foreground`,children:g.length===0?s.noSavedChats:s.noResults}):b.map(e=>{let n=C(e.subagentId),a=t===Oe(e.subagentId,e.entityId);return(0,d.jsx)(l.DropdownItem,{icon:a?`check`:n?.icon??`bot`,className:a?`bg-accent font-semibold text-primary`:void 0,actions:[{icon:`pencil`,label:s.renameChat,onClick:()=>{r(!1),v(e)}},{icon:`archive`,label:s.archiveChat,onClick:()=>void y(e)}],onClick:()=>i(e.subagentId,e.entityId,e),children:(0,d.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center justify-between gap-2`,children:[(0,d.jsx)(`span`,{className:`min-w-0 truncate`,title:`${n?.label??e.subagentId} · ${X(e)}`,children:X(e)}),(0,d.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,title:`${s.chatStarted.replace(`{at}`,new Date(Z(e)).toLocaleString(c))} · ${s.chatLastMessage.replace(`{at}`,new Date(e.savedAt).toLocaleString(c))}`,children:Br(Z(e),c)})]})},`${e.subagentId}:${e.entityId}`)})}),_&&(0,d.jsx)(zr,{chat:_,onClose:()=>v(null)})]})}function Wr({defaultWidth:e,minWidth:t,maxWidth:n,onWidthChange:r}={}){let{task:i,isOpen:a,pendingGoal:o,orchestratorRunId:s,pageContext:c,pageContextCard:f,anchoredUserMessages:p,pendingResume:m,resumeRunId:h,dismissForeignTask:g,resumeEntityChat:_,pendingManualEntry:v,manualEntryRunId:y,startManualEntry:b,pendingExtraDestinations:x,pendingResumeWithAI:S,resumeWithAIRunId:w,pendingStart:T,startRunId:E,scope:D,threadEvents:ee}=$(),O=Q(),k=(0,u.useRef)(null),[A,j]=(0,u.useState)(!1),[M,N]=(0,u.useState)(null),[P,te]=(0,u.useState)(null);(0,u.useEffect)(()=>{N(null),te(null)},[i?.id]),qn(D?.id);let F=cn({defaultWidth:e,minWidth:t,maxWidth:n,onWidthChange:r}),ne=()=>{(!i||i.agent.running||i.savedToDisk||window.confirm(O.unsavedConversationConfirm))&&(g(),j(!1))},I=i?[...i.precedingActivity??[],...i.agent.activity]:[],L=I.length,re=Math.max(0,Math.min(i?.panelExtraAnchorIndex??L,L)),ie=I.slice(0,re),R=I.slice(re),z=!!(i&&!i.agent.running&&i.agent.error),[B,ae,oe]=wt(),V=ct(),se=Pr(),H=(0,u.useRef)({at:Date.now()});H.current.id!==i?.id&&(H.current={id:i?.id,at:Date.now()});let ce=(0,u.useMemo)(()=>{if(!D||!i?.thread)return H.current.at;let e=Ae(D.id,i.thread,i.id)[0];if(e)return e.savedAt;let t=De(D.id).find(e=>Oe(e.subagentId,e.entityId)===i.id);return t?Z(t):I.find(e=>e.at!==void 0)?.at??H.current.at},[D?.id,i?.thread,i?.id,L===0]),le=Tt(i?.thread,ce,1/0,B),U=R.find(e=>e.at!==void 0)?.at,W=R.length===0||U===void 0?le:le.filter(e=>e.at<U),G=R.length===0||U===void 0?[]:le.filter(e=>e.at>=U),K=(e,t)=>{i&&(N(null),i.agent.rewind(e.id,t).then(e=>{e&&i.onApplied(e)}))},ue=e=>{let t=i?.agent.activity??[],n=t.slice(t.findIndex(t=>t.id===e.id)+1).flatMap(e=>[...e.kind===`tool`&&e.status===`done`?[e.label]:[],...(e.parts??[]).flatMap(e=>e.type===`tool`&&e.status===`done`?[e.label]:[])]);return[...new Set(n.filter(Boolean))]},de=(e,t)=>{let n=ue(e);n.length?te({entry:e,steps:n,...t===void 0?{}:{text:t}}):K(e,t)},fe=i?{available:e=>i.agent.activity.some(t=>t.id===e.id)&&i.agent.rewindable(e.id),disabled:i.agent.running,onRetry:e=>de(e),onEdit:e=>N(e)}:void 0,pe=new Set(i?.agent.activity.map(e=>e.id)??[]),me=i?{canAnswer:e=>pe.has(e),onAnswer:(e,t,n)=>i.agent.answerQuestions(e,t,n).then(e=>{e&&i.onApplied(e)}),onCardAction:(e,t,n)=>i.agent.cardAction(e,t,n)}:void 0,q=me?Gt(I,me.canAnswer):null,he=i?.id===`agentico-orchestrator`&&i.scopedSubagentId?C(i.scopedSubagentId):void 0,ge=he?.manualEntry?he:null,J=(0,u.useRef)(!0);(0,u.useEffect)(()=>{let e=k.current;if(!e)return;let t=()=>{J.current=e.scrollHeight-e.scrollTop-e.clientHeight<80};return e.addEventListener(`scroll`,t),()=>e.removeEventListener(`scroll`,t)},[i?.id]),(0,u.useEffect)(()=>{let e=k.current;e&&(J.current=!0,e.scrollTop=e.scrollHeight)},[i?.id]);let _e=I.at(-1)?.detail?.length??0;(0,u.useEffect)(()=>{let e=k.current;e&&J.current&&(e.scrollTop=e.scrollHeight)},[L,z,_e]);let Y=(0,u.useRef)(null);(0,u.useEffect)(()=>{let e=k.current,t=Y.current;if(!e||!t||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{J.current&&(e.scrollTop=e.scrollHeight)});return n.observe(t),()=>n.disconnect()},[i?.id,a]);let ve=o?(0,d.jsx)(Zn,{userGoal:o},s):null,ye=m?C(m.subagentId):void 0,be=m&&ye?(0,d.jsx)(Xn,{manifest:ye,params:m.snapshot.params,taskId:Oe(m.subagentId,m.entityId),resumeSeed:{history:m.snapshot.history,activity:m.snapshot.activity}},h):null,xe=v?C(v.subagentId):void 0,Se=v&&xe?(0,d.jsx)(Qn,{manifest:xe,extraDestinations:v.extraDestinations},y):null,X=S?C(S.subagentId):void 0,Ce=S&&X?(0,d.jsx)(Xn,{manifest:X,params:S.params,extraDestinations:S.extraDestinations},w):null,we=T?C(T.subagentId):void 0,Te=T&&we?(0,d.jsx)(Xn,{manifest:we,params:T.params,taskId:T.taskId,openingMessage:T.openingMessage},E):null;return a?(0,d.jsxs)(d.Fragment,{children:[ve,be,Se,Ce,Te,(0,d.jsxs)(`div`,{style:{width:F.width},className:`relative flex h-full shrink-0 flex-col border-l border-border bg-background`,children:[(0,d.jsx)(ln,{width:F.width,min:F.min,max:F.max,onResize:F.set,onCommit:F.commit,onReset:F.reset}),(0,d.jsxs)(`div`,{className:`flex min-h-[60px] items-center gap-1 border-b border-border/60 px-4 py-3`,children:[(0,d.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-lg font-semibold leading-tight`,children:i?i.title:`Agentico`}),i?.thread&&ee&&oe&&(0,d.jsx)(l.ActionButton,{icon:B?`activity`:`message-square`,ariaLabel:B?O.hideEvents:O.showEvents,title:B?O.hideEvents:O.showEvents,variant:`link`,className:`p-1 ${B?`text-primary`:`text-muted-foreground`}`,onClick:()=>ae(!B)}),D&&(0,d.jsx)(Ur,{scopeId:D.id,currentTaskId:i?.id??null,open:A,onOpenChange:j,onNewChat:ne,onSelect:(e,t,n)=>_(e,t,n),onArchivedCurrent:g}),se&&(0,d.jsx)(l.ActionButton,{icon:`settings`,ariaLabel:O.settingsTitle,title:O.settingsTitle,variant:`link`,className:`p-1 text-muted-foreground`,onClick:V.open}),(0,d.jsx)(un,{})]}),(0,d.jsx)(Fr,{}),(0,d.jsx)(`div`,{ref:k,className:`flex-1 overflow-y-auto px-3 pb-2 ${q?`min-h-24`:`min-h-0`}`,children:(0,d.jsx)(`div`,{ref:Y,className:`pt-2`,children:i?(0,d.jsxs)(d.Fragment,{children:[D&&i.thread&&(0,d.jsx)(tr,{scopeId:D.id,thread:i.thread,taskId:i.id,scrollRef:k,busy:i.agent.running,showEvents:B,onLoad:()=>{J.current=!1},onContinue:e=>_(e.subagentId,e.entityId,e)}),i.manualEntry&&I.length===0&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i.manualEntry.prompt}),(0,d.jsx)(Zt,{activity:ie,questions:me,docked:q,pinUserMessages:!q,messageActions:fe,speaker:i.speaker,events:W}),i.panelExtra&&(0,d.jsx)(`div`,{className:`mt-3`,children:i.panelExtra}),R.length>0&&(0,d.jsx)(Zt,{activity:R,questions:me,docked:q,pinUserMessages:!q,messageActions:fe,speaker:i.speaker,events:G}),!i.agent.running&&i.agent.error&&(0,d.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,d.jsx)(`p`,{className:`flex-1 text-xs text-destructive`,children:i.agent.error}),(0,d.jsx)(l.ActionButton,{label:O.retry,variant:`secondary`,className:`shrink-0`,onClick:()=>{let e=[...i.agent.activity].reverse().find(e=>e.kind===`user`);if(e&&i.agent.rewindable(e.id)){de(e);return}i.agent.sendMessage(O.retryMessage,{retry:!0}).then(e=>{e&&i.onApplied(e)})}}),!i.agent.remote&&i.agent.offersFallback!==!1&&(0,d.jsx)(l.ActionButton,{label:O.continueWithoutAi,variant:`secondary`,className:`shrink-0`,onClick:()=>{if(ge){b(ge.id,x);return}let e=i.agent.runFallback();e&&i.onApplied(e)}})]})]}):p.length>0?(0,d.jsx)(Hr,{messages:p}):f?(0,d.jsx)(Vr,{card:f}):(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c??O.orchestratorStarterHint})})}),i&&q?(0,d.jsxs)(`section`,{"aria-label":O.pendingQuestions,className:`flex min-h-0 shrink flex-col border-t border-border/60`,children:[i.panelActions&&(0,d.jsx)(`div`,{className:`shrink-0 px-4 pt-3`,children:i.panelActions}),(0,d.jsx)(`div`,{className:`min-h-0 overflow-y-auto px-4 py-3`,children:(0,d.jsx)(Kt,{entry:q.entry,part:q.part,questions:me,autoFocus:!0},`${q.entry.id}:${q.part.id}`)}),i.agent.running&&(0,d.jsx)(`div`,{className:`flex shrink-0 justify-end px-4 pb-3`,children:(0,d.jsx)(l.ActionButton,{icon:`square`,label:O.stop,variant:`secondary`,onClick:i.agent.stop})})]}):(0,d.jsxs)(`div`,{className:`border-t border-border/60 px-4 py-3`,children:[i?.panelActions&&(0,d.jsx)(`div`,{className:`mb-2`,children:i.panelActions}),i?(0,d.jsx)(Lr,{task:i,editing:M,onCancelEdit:()=>N(null),onSendEdit:(e,t)=>de(e,t)},i.id):(0,d.jsx)(Rr,{})]}),P&&(0,d.jsxs)(l.ModalYesNo,{title:O.rewindTitle,onClose:()=>te(null),onYes:async()=>(K(P.entry,P.text),!0),children:[(0,d.jsx)(`p`,{className:`text-sm`,children:O.rewindText}),(0,d.jsx)(`ul`,{className:`mt-2 list-disc space-y-0.5 ps-5 text-sm text-muted-foreground`,children:P.steps.slice(0,8).map(e=>(0,d.jsx)(`li`,{children:e},e))})]})]})]}):(0,d.jsxs)(d.Fragment,{children:[ve,be,Se,Ce,Te]})}function Gr(e,t){let{setPageContext:n}=$(),r=(0,u.useRef)(crypto.randomUUID()).current;(0,u.useEffect)(()=>(n(r,e,t??null),()=>n(r,null)),[e,t])}function Kr(e,t,n,r,i=!0,a){let{registerComponentAnchor:o}=$(),s=(0,u.useRef)(crypto.randomUUID()).current,c=(0,u.useRef)(n);c.current=n,(0,u.useEffect)(()=>{if(i)return o(s,{subagentId:e,componentKey:t,contextInfo:r,pinnedEntityId:a,onResult:(e,t,n)=>c.current?.(e,t,n)}),()=>o(s,null)},[e,t,r,i,a])}var qr=class extends Error{status;code;constructor(e,t){super(t),this.name=`AgenticoBackendError`,this.status=e,this.code=t}},Jr=e=>new Promise(t=>setTimeout(t,e));function Yr(e){let t=e.baseUrl.replace(/\/+$/,``),n=(...t)=>(e.fetch??fetch)(...t),r=e.pollMs??1500;async function i(r,i,a){let o=await n(`${t}${i}`,{method:r,headers:{...a===void 0?{}:{"content-type":`application/json`},...await e.headers?.()},...a===void 0?{}:{body:JSON.stringify(a)}}),s=await o.text(),c={};try{c=s?JSON.parse(s):{}}catch{c={}}if(!o.ok){let e=c&&typeof c==`object`&&`error`in c?String(c.error):`http-${o.status}`;if(o.status===422&&c&&typeof c==`object`&&`ok`in c)return c;throw new qr(o.status,e)}return c}let a=e=>{let t=e?`?namespace=${encodeURIComponent(e)}`:``,n=e=>`/connections/${encodeURIComponent(e)}`;return{load:()=>i(`GET`,`/connections${t}`),connect:(e,r)=>i(`POST`,`${n(e)}${t}`,{fields:r}),disconnect:async e=>{await i(`DELETE`,`${n(e)}${t}`)},addAccount:(e,r)=>i(`POST`,`${n(e)}/accounts${t}`,{fields:r}),removeAccount:async(e,r)=>{await i(`DELETE`,`${n(e)}/accounts/${encodeURIComponent(r)}${t}`)},orderAccounts:async(e,r)=>{await i(`PUT`,`${n(e)}/accounts/order${t}`,{ids:r})},setOrder:async e=>{await i(`PUT`,`/connections/order${t}`,{order:e})},models:async e=>(await i(`GET`,`${n(e)}/models${t}`)).models}},o=[],s={list:async()=>{let[e,t]=await Promise.all([i(`GET`,`/runners`),i(`GET`,`/projects`).catch(()=>({namespaces:[]}))]);return o=t.namespaces,e.runners},add:async e=>(await i(`POST`,`/runners`,e)).runner,update:async(e,t)=>{await i(`PATCH`,`/runners/${encodeURIComponent(e)}`,t)},remove:async e=>{await i(`DELETE`,`/runners/${encodeURIComponent(e)}`)},status:e=>i(`GET`,`/runners/${encodeURIComponent(e)}/status`),startPairing:e=>i(`POST`,`/runners/pairings`,e),pairingStatus:e=>i(`GET`,`/runners/pairings/${encodeURIComponent(e)}`),install:async(e,t)=>{let{installId:n}=await i(`POST`,`/runners/installs`,e),a=0;for(;;){await Jr(r);let e=await i(`GET`,`/runners/installs/${encodeURIComponent(n)}?from=${a}`);for(let n of e.lines)t({line:n});if(a=e.next,e.status===`error`)throw Error(e.error??`installation failed`);if(e.status===`done`){let t=(await s.list()).find(t=>t.id===e.runnerId);if(!t)throw Error(`installation failed`);return t}}},tenants:{list:async()=>o.map(e=>({id:e.namespace,name:e.name??e.namespace,...e.runner?{runnerId:e.runner.id}:{}})),assign:async(e,t)=>{await i(`PUT`,`/namespaces/${encodeURIComponent(e)}`,{runnerId:t})}}},c=n=>new f.RunnerClient({url:`${t}/${n}`,...e.fetch?{fetch:e.fetch}:{},...e.headers?{headers:e.headers}:{}});return{me:()=>i(`GET`,`/me`),connections:a,fleet:s,runner:()=>c(`runner`),runnerOfNamespace:()=>c(`runner-namespace`),memories:{list:async()=>(await i(`GET`,`/memories`)).memories,check:e=>i(`POST`,`/memories/check`,e),add:async e=>(await i(`POST`,`/memories`,e)).memory,update:async(e,t)=>(await i(`PATCH`,`/memories/${encodeURIComponent(e)}`,t)).memory,remove:async e=>{await i(`DELETE`,`/memories/${encodeURIComponent(e)}`)}},memory:{get:()=>i(`GET`,`/memory`),search:async(e,t)=>(await i(`POST`,`/memory/search`,{query:e,...t?{limit:t}:{}})).results,write:e=>i(`POST`,`/memory/write`,e)},projects:{list:()=>i(`GET`,`/projects`),set:async(e,t)=>{await i(`PUT`,`/namespaces/${encodeURIComponent(e)}`,t)}}}}exports.AGENTICO_MAX_WIDTH=en,exports.AGENTICO_MIN_WIDTH=$t,exports.AGENTICO_SETTING_KEYS=$e,exports.AGENTICO_WIDTH=Qt,exports.AGENTICO_WIDTH_STORAGE_KEY=tn,exports.Agentico=Wr,exports.AgenticoBackendError=qr,exports.AgenticoProvider=St,exports.AgenticoSettingsModal=Fr,exports.AgenticoToggle=un,exports.DEFAULT_AGENTICO_SETTINGS=et,exports.DEFAULT_REASONING_PART_ID=h,exports.DEFAULT_TEXT_PART_ID=m,exports.JSON_EXPORT_DESTINATION_ID=oe,exports.MICRO_PROMPT_REGISTRY=ie,exports.ORCHESTRATOR_TASK_ID=yt,exports.PREVIEW_LIMIT=Ne,exports.PREVIEW_MAX=Me,exports.SUMMARY_MICRO_PROMPT=re,exports.agenticoDe=W,exports.agenticoEn=le,exports.agenticoIt=U,exports.agenticoPromptsEn=k,exports.agenticoPromptsIt=A,exports.agenticoTranslations=Ie,exports.applyMicroPrompts=R,exports.browserSettingsStore=it,exports.chatHasPersonMessage=Ce,exports.chatStartedAt=Z,exports.chatThreadOf=ke,exports.chatTitle=X,exports.compileRoutePattern=ze,exports.configureAgenticoPrompts=M,exports.configureEntityChatStore=ue,exports.createAgenticoBackend=Yr,exports.createCrossAgentTools=E,exports.createHarnessExecutor=vn,exports.defineSubagent=y,exports.diffAgenticoRouting=Ze,exports.earlierSessions=Ae,exports.effectiveSettings=tt,exports.entityChatTaskId=Oe,exports.extractErrorMessage=z,exports.extractJsonBlock=B,exports.findSubagentManifest=C,exports.formatQuestionAnswers=v,exports.getAgenticoPrompts=N,exports.getDestinationRegistry=ce,exports.getEntityChat=ve,exports.getSubagentControls=Hn,exports.getSubagentRegistry=S,exports.getSubagentReport=Ln,exports.harnessTranscript=gn,exports.hasEntityChatBackend=de,exports.imagePreviews=Fe,exports.jsonExportDestination=V,exports.listEntityChats=De,exports.matchAgenticoPage=He,exports.matchesAnyPath=Be,exports.mergeAgenticoPageRules=Ge,exports.mergeAgenticoRouting=Ke,exports.messagePartsText=_,exports.onEntityChatsChange=J,exports.placeEvents=je,exports.registerCrossAgentTools=T,exports.registerDestinations=H,exports.registerSubagentControls=Vn,exports.registerSubagentReports=In,exports.registerSubagents=x,exports.removeEntityChat=Ee,exports.renameEntityChat=Te,exports.renderRegistryCli=L,exports.renderSubagentCli=I,exports.resetAgenticoPrompts=P,exports.resolveAgenticoRoute=We,exports.routePathOf=Le,exports.runHostTool=hn,exports.saveEntityChat=ye,exports.shownSettings=nt,exports.subagentToolsOf=Ue,exports.syncEntityChats=me,exports.toJsonSchema=D,exports.toMcpTool=ee,exports.upsertMessagePart=g,exports.useAgent=Dn,exports.useAgentico=$,exports.useAgenticoHarness=ut,exports.useAgenticoI18n=Q,exports.useAgenticoPageContext=Gr,exports.useAgenticoSettings=ct,exports.useSubagentComponentContext=Kr,exports.validateAgenticoRouting=Qe;
|
|
35
35
|
//# sourceMappingURL=index.js.map
|