@llmnative/agentico 0.10.2 → 0.10.3

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
@@ -25,5 +25,5 @@ ${r.userRequestHeading}
25
25
  ${e}`}function ft(e,t){return t?{kind:`handoff`,...t}:{kind:`chat`,message:e}}function pt(e){return b().filter(t=>!t.onlyWhenAnchored||e===t.id)}function mt(e){return{buildContext(e){return{cliCatalog:L(pt(e.scopedSubagentId)),handoff:{current:null},collected:{}}},buildPrompt({userGoal:e,pageContext:t},{cliCatalog:n}){return dt(e,n,t)},buildFollowUpPrompt(e,t,{cliCatalog:n}){return`${e}\n\n${ut()}\n\n${M().toolsHeading}\n${n}`},parseResponse(e,t,n){let r=n.handoff.current;return n.handoff.current=null,ft(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=w({attachmentsRef:r,collected:n.collected,proxyFetch:l.proxyFetch}),a=t.scopedSubagentId?x(t.scopedSubagentId):null,o=a?i.filter(e=>(a.crossAgentToolIds??[]).includes(e.name)):i,s=pt(t.scopedSubagentId).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)(M().handoffQueued,{label:t.label})}}})));return[...o,...s]}}}function ht(e,t){return e.deriveHistoryTitle?.(t)??e.label}function gt({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=te(),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(G.id,G);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,ht(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 _t={};function vt(e){Object.assign(_t,e)}function yt(e){return _t[e]}function bt({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 xt(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 St={};function Ct(e){Object.assign(St,e)}function wt(e){return St[e]}function Tt(e,t=6e3){let n=e.filter(e=>(e.kind===`user`||e.kind===`thinking`)&&e.detail?.trim()&&!ge(e)).map(e=>`${e.kind===`user`?`Person`:`Agent`}: ${e.detail.trim()}`).join(`
26
26
 
27
27
  `);return n.length>t?`${n.slice(0,t*.7)}\n\n[…]\n\n${n.slice(-t*.3)}`:n}function Et(e){return(e.trim().split(`
28
- `).map(e=>e.trim()).find(Boolean)??``).replace(/^(title|titolo)\s*:\s*/i,``).replace(/^#+\s*/,``).replace(/^["'«“]+|["'»”]+$/g,``).replace(/[.。]+$/,``).trim().slice(0,80)}function Dt(e,t){try{return e.definition.executor?.catalogProviders?.(e.toParams(t))}catch{return}}function Ot(e,t,n,r,i){let a=Dt(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 kt(e){let t=(0,l.useAIProviderRegistry)()?.registry??{},{modelsByProvider:n,selectedModel:r}=nt(),i=(0,u.useRef)({registry:t,modelsByProvider:n,selectedModel:r});i.current={registry:t,modelsByProvider:n,selectedModel:r};let a=(0,u.useRef)(new Set),o=(0,u.useCallback)(async(t,n,r)=>{if(!e)return!1;let o=le(e,t,n),s=x(t),c=`${e}:${t}:${n}`;if(!o||!s?.autoTitle||o.name||!he(o)||a.current.has(c))return!1;let{registry:u,modelsByProvider:d,selectedModel:f}=i.current,p=Ot(s,o.params,r??f,d,u),m=p?(0,l.parseAIModelRef)(p):null;if(!m)return!1;a.current.add(c);try{let r=await u[m.provider].complete({prompt:M().chatTitle.replace(`{chat}`,Tt(o.activity)),model:m.model,history:[]}),i=r&&r.type===`text`?Et(r.text):``;return i?_e(e,t,n,i,`model`):!1}catch{return!1}finally{a.current.delete(c)}},[e]),s=Object.keys(n).length>0;return(0,u.useEffect)(()=>{e&&s&&!At.has(e)&&(At.add(e),(async()=>{for(let t of be(e)){let n=x(t.subagentId);if(n?.autoTitle){if(n.definition.conversational&&!he(t)){ye(e,t.subagentId,t.entityId);continue}t.name||await o(t.subagentId,t.entityId)}}})())},[e,s,o]),o}var At=new Set,jt=()=>({});function Mt({manifest:e,params:t,extraDestinations:n,precedingActivity:r,taskId:i,resumeSeed:a,model:o,openingMessage:s}){let c=lt(e.definition,{defaultEnabled:!0}),f=$(),p=f.scope,m=(0,l.useProxy)(),h=(0,u.useRef)(i??`subagent-${e.id}-${crypto.randomUUID()}`).current,[g,_]=(0,u.useState)(null),v=t=>{e.definition.conversational||_(t)},[y,b]=(0,u.useState)([]),[x,S]=(0,u.useState)(null),C=yt(e.id),w=C?.kind===`selection`?C:null,[T,E]=(0,u.useState)(null),D=(0,u.useRef)(!1),O=(0,u.useRef)(0),k=(0,u.useRef)(null);g&&g!==k.current&&(k.current=g,O.current=(r?.length??0)+c.activity.length);let A=(0,u.useRef)(!1),j=c.remote||!c.hasProviders||c.selectedModel!==``;(0,u.useEffect)(()=>{!D.current&&j&&(D.current=!0,a?(B.current=!0,c.resume(e.toParams(t),a)):(o&&c.setSelectedModel(o),c.run(e.toParams(t),{model:o,openingMessage:s}).then(e=>{e&&v(e)})))},[j]),(0,u.useEffect)(()=>{if(!g||!p)return;let n=e.autoApplyDestinationIds??[],r=f.componentAnchors.find(t=>t.subagentId===e.id&&t.pinnedEntityId)?.pinnedEntityId,i=te();n.forEach(n=>{let a=i[n];a&&(S(null),a.apply(g,{scopeId:p.id,dataProvider:p.dataProvider,storageProvider:p.storageProvider,proxyFetch:m},{...t,pinnedEntityId:r}).then(n=>{n?.id&&f.commitEntityChat(e.id,n.id,h,p.id,t,ht(e,t))}).catch(e=>S(e instanceof Error?e.message:String(e))))})},[g,c.activity,p]),(0,u.useEffect)(()=>{g&&w&&E(w.defaultSelection(g))},[g,w]);let M=(e,t)=>{E(n=>n&&{...n,[e]:t})},N=e=>v(e),P=(0,u.useMemo)(()=>g&&w&&T?w.applySelection(g,T):g,[g,w,T]),F=(0,u.useMemo)(()=>f.componentAnchors.filter(t=>t.subagentId===e.id&&t.onResult),[f.componentAnchors,e.id]),I=(0,u.useMemo)(()=>xt(F,t,h),[F,t,h]),ee=(0,u.useMemo)(()=>I?[I,...n??[]]:n,[I,n]),L=e.chatEntityId?.(t),R=kt(p?.id),z=(0,u.useRef)(!1),B=(0,u.useRef)(!1);(0,u.useEffect)(()=>{let n=z.current&&!c.running;if(z.current=c.running,!n||!L||!p)return;if(B.current){B.current=!1;return}let i=c.snapshot();if(!i)return;let a=[...r??[],...i.activity];e.autoTitle&&e.definition.conversational&&!he({activity:a})||(ue({scopeId:p.id,subagentId:e.id,entityId:L,params:t,title:ht(e,t),history:i.history,activity:a}),e.autoTitle&&R(e.id,L,c.selectedModel))},[c.running]);let V=()=>{A.current=!0,c.running&&c.stop(),f.closeTask(h)},H=(0,u.useRef)(wt(e.id)??jt).current,U=H({params:t,taskId:h,running:c.running,close:V}),W=e=>{b(t=>t.includes(e)?t:[...t,e])};return(0,u.useEffect)(()=>{A.current||f.openTask({id:h,title:ht(e,t),icon:e.icon,agent:c,onApplied:e=>v(e),precedingActivity:r,panelExtraAnchorIndex:O.current,onDismiss:V,...L?{savedToDisk:!0}:{},panelActions:U.content,composerActions:U.actions,composerCommands:U.commands,panelExtra:g?(0,d.jsxs)(d.Fragment,{children:[w&&T?(0,d.jsx)(w.Report,{result:g,selection:T,onChange:M}):C?.kind===`editable`?(0,d.jsx)(C.Report,{result:g,onResultChange:N}):(0,d.jsx)(bt,{result:P}),x&&(0,d.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Salvataggio automatico non riuscito: `,x]}),(0,d.jsx)(gt,{manifest:e,result:P,meta:t,taskId:h,initiallyApplied:y,onApplied:W,extraDestinations:ee})]}):void 0})},[c.activity,c.running,c.error,c.canContinue,c.selectedModel,c.modelsByProvider,c.hasProviders,c.remoteModels,f.openTask,f.componentAnchors,h,e,t,g,P,T,y,n,r,x,U.content,U.actions,U.commands]),(0,u.useEffect)(()=>()=>{f.closeTask(h)},[f.closeTask,h]),null}function Nt({userGoal:e}){let t=Q(),n=lt((0,u.useMemo)(()=>mt({unavailable:t.orchestratorUnavailable,continueWithoutAi:t.orchestratorContinueWithoutAi,preparing:t.orchestratorPreparing,collecting:t.orchestratorCollecting}),[]),{defaultEnabled:!0}),r=$(),[i,a]=(0,u.useState)(null),o=(0,u.useRef)(!1),s=!n.hasProviders||n.selectedModel!==``,c=(0,u.useRef)(r.pendingExtraDestinations),l=(0,u.useRef)(r.pendingAttachments),f=(0,u.useRef)(r.pendingModel),p=(0,u.useRef)(r.pendingScopedSubagentId??r.scopedSubagentId??void 0),m=(0,u.useRef)(r.pendingCarryOver),h=(0,u.useRef)(!1),g=e=>{e&&typeof e==`object`&&e.kind===`handoff`&&(a(e),r.closeTask(Ce))};(0,u.useEffect)(()=>{!o.current&&s&&(o.current=!0,f.current&&n.setSelectedModel(f.current),n.run({userGoal:e,pageContext:r.pageContext,scopedSubagentId:p.current??null},{attachments:l.current,model:f.current,openingMessage:e}).then(e=>{e&&g(e)}))},[s]),(0,u.useEffect)(()=>{h.current||r.openTask({id:Ce,title:`Agentico`,icon:`bot`,agent:n,onApplied:g,scopedSubagentId:p.current,precedingActivity:m.current?.activity,onDismiss:()=>{h.current=!0,n.running&&n.stop(),r.closeTask(Ce)}})},[n.activity,n.running,n.error,n.canContinue,n.selectedModel,n.modelsByProvider,n.hasProviders,r.openTask]),(0,u.useEffect)(()=>()=>{r.closeTask(Ce)},[r.closeTask]);let _=(0,u.useMemo)(()=>[...m.current?.activity??[],...n.activity],[n.activity]);if(!i)return null;let v=x(i.subagentId);return v?(0,d.jsx)(Mt,{manifest:v,params:i.params,extraDestinations:c.current,model:f.current||void 0,taskId:m.current?.taskId,precedingActivity:_}):null}function Pt({manifest:e,extraDestinations:t}){let n=lt(e.definition,{defaultEnabled:!1}),r=Q(),i=$(),a=(0,u.useRef)(`manual-${e.id}-${crypto.randomUUID()}`).current,[o,s]=(0,u.useState)(null),[c,f]=(0,u.useState)([]),p=yt(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 r;try{r=e.manualEntry.fromRawText(t)}catch(e){console.error(`[ManualEntryRunner] manualEntry.fromRawText ha rifiutato il testo:`,e);return}v(r),f([]),n.run(r,{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)(()=>i.componentAnchors.filter(t=>t.subagentId===e.id&&t.onResult),[i.componentAnchors,e.id]),E=(0,u.useMemo)(()=>_?xt(T,_,a):null,[T,_,a]),D=(0,u.useMemo)(()=>E?[E,...t??[]]:t,[E,t]);return(0,u.useEffect)(()=>{y.current||i.openTask({id:a,title:e.label,icon:e.icon,agent:n,onApplied:e=>s(e),manualEntry:e.manualEntry?{prompt:e.manualEntry.prompt,onSubmit:b}:void 0,onDismiss:()=>{y.current=!0,n.running&&n.stop(),i.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)(bt,{result:C}),(0,d.jsx)(gt,{manifest:e,result:C,meta:_??{},taskId:a,initiallyApplied:c,onApplied:w,extraDestinations:D}),n.hasProviders&&(0,d.jsx)(l.ActionButton,{label:r.resumeWithAi,variant:`outline-secondary`,className:`text-xs`,onClick:()=>{_&&i.resumeWithAI(e.id,_,t)}})]}):void 0})},[n.activity,n.running,n.error,n.hasProviders,i.componentAnchors,o,C,h,c,_]),(0,u.useEffect)(()=>()=>{i.closeTask(a)},[]),null}function Ft(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 It({task:e}){let t=Q(),[n,r]=(0,u.useState)(``),{agent:i,onApplied:a,manualEntry:o}=e,s=i.running,c=e=>{if(r(``),o){o.onSubmit(e.text);return}i.sendMessage(e.text,{attachments:e.files,model:e.model}).then(e=>{e&&a(e)})},f=!!o||i.remote&&i.remoteModels.length===0,p=i.alongside&&i.remoteModels.some(e=>e.value===i.selectedModel),m=!f&&!i.remote&&!p&&i.hasProviders&&!i.selectedModel,h=f?[]:i.remote?i.remoteModels:i.alongside?[...i.remoteModels,...Ft(i.modelsByProvider,i.catalogGroup)]:Ft(i.modelsByProvider);return(0,d.jsx)(l.Chatbot,{value:n,onChange:r,placeholder:o?.prompt??t.messagePlaceholder,running:s,onStop:i.stop,disabled:!n.trim()||m,onSubmit:c,attachments:!o&&!i.remote&&!p,models:h,selectedModel:f?``:i.selectedModel,actions:e.composerActions,commands:e.composerCommands,onModelChange:i.setSelectedModel,modelPlaceholder:t.selectModelPlaceholder,minHeight:44,maxHeight:220})}function Lt(){let{startOrchestrator:e}=$(),t=Q(),[n,r]=(0,u.useState)(``),{hasProviders:i,modelsByProvider:a,selectedModel:o,setSelectedModel:s}=nt(),c=t=>{t.text.trim()&&(e(t.text.trim(),{attachments:t.files.length>0?t.files:void 0,model:t.model||void 0}),r(``))},f=i&&!o;return(0,d.jsx)(l.Chatbot,{value:n,onChange:r,placeholder:t.orchestratorStarterPlaceholder,disabled:!n.trim()||f,onSubmit:c,attachments:!0,models:Ft(a),selectedModel:o,onModelChange:s,modelPlaceholder:t.selectModelPlaceholder,minHeight:44,maxHeight:220})}function Rt({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:()=>(_e(e.scopeId,e.subagentId,e.entityId,String(r.record?.title??me(e)),`person`),t(),Promise.resolve(!0)),children:(0,d.jsxs)(l.Form,{appearance:`empty`,controller:r,defaultValues:{title:me(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 zt(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 Bt({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 Vt({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 Ht({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)(()=>se(()=>h(e=>e+1)),[]);let g=(0,u.useMemo)(()=>n?be(e):[],[e,n,m]),[_,v]=(0,u.useState)(null),y=async n=>{let r=x(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}ye(e,n.subagentId,n.entityId),t===xe(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=x(t.subagentId)?.label??t.subagentId;return me(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=x(e.subagentId),a=t===xe(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} · ${me(e)}`,children:me(e)}),(0,d.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,title:`${s.chatStarted.replace(`{at}`,new Date(ve(e)).toLocaleString(c))} · ${s.chatLastMessage.replace(`{at}`,new Date(e.savedAt).toLocaleString(c))}`,children:zt(ve(e),c)})]})},`${e.subagentId}:${e.entityId}`)})}),_&&(0,d.jsx)(Rt,{chat:_,onClose:()=>v(null)})]})}function Ut({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:S,pendingResumeWithAI:C,resumeWithAIRunId:w,pendingStart:T,startRunId:E,scope:D}=$(),O=Q(),k=(0,u.useRef)(null),[A,j]=(0,u.useState)(!1);kt(D?.id);let M=Xe({defaultWidth:e,minWidth:t,maxWidth:n,onWidthChange:r}),N=()=>{(!i||i.agent.running||i.savedToDisk||window.confirm(O.unsavedConversationConfirm))&&(g(),j(!1))},P=i?[...i.precedingActivity??[],...i.agent.activity]:[],F=P.length,I=Math.max(0,Math.min(i?.panelExtraAnchorIndex??F,F)),ee=P.slice(0,I),L=P.slice(I),R=!!(i&&!i.agent.running&&i.agent.error),z=new Set(i?.agent.activity.map(e=>e.id)??[]),B=i?{canAnswer:e=>z.has(e),onAnswer:(e,t,n)=>i.agent.answerQuestions(e,t,n).then(e=>{e&&i.onApplied(e)})}:void 0,V=B?Ie(P,B.canAnswer):null,H=i?.id===`agentico-orchestrator`&&i.scopedSubagentId?x(i.scopedSubagentId):void 0,U=H?.manualEntry?H:null,W=(0,u.useRef)(!0);(0,u.useEffect)(()=>{let e=k.current;if(!e)return;let t=()=>{W.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&&(W.current=!0,e.scrollTop=e.scrollHeight)},[i?.id]);let G=P.at(-1)?.detail?.length??0;(0,u.useEffect)(()=>{let e=k.current;e&&W.current&&(e.scrollTop=e.scrollHeight)},[F,R,G]);let K=(0,u.useRef)(null);(0,u.useEffect)(()=>{let e=k.current,t=K.current;if(!e||!t||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{W.current&&(e.scrollTop=e.scrollHeight)});return n.observe(t),()=>n.disconnect()},[i?.id,a]);let q=o?(0,d.jsx)(Nt,{userGoal:o},s):null,te=m?x(m.subagentId):void 0,J=m&&te?(0,d.jsx)(Mt,{manifest:te,params:m.snapshot.params,taskId:xe(m.subagentId,m.entityId),resumeSeed:{history:m.snapshot.history,activity:m.snapshot.activity}},h):null,Y=v?x(v.subagentId):void 0,ne=v&&Y?(0,d.jsx)(Pt,{manifest:Y,extraDestinations:v.extraDestinations},y):null,re=C?x(C.subagentId):void 0,ie=C&&re?(0,d.jsx)(Mt,{manifest:re,params:C.params,extraDestinations:C.extraDestinations},w):null,ae=T?x(T.subagentId):void 0,X=T&&ae?(0,d.jsx)(Mt,{manifest:ae,params:T.params,taskId:T.taskId,openingMessage:T.openingMessage},E):null;return a?(0,d.jsxs)(d.Fragment,{children:[q,J,ne,ie,X,(0,d.jsxs)(`div`,{style:{width:M.width},className:`relative flex h-full shrink-0 flex-col border-l border-border bg-background`,children:[(0,d.jsx)(Ze,{width:M.width,min:M.min,max:M.max,onResize:M.set,onCommit:M.commit,onReset:M.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`}),D&&(0,d.jsx)(Ht,{scopeId:D.id,currentTaskId:i?.id??null,open:A,onOpenChange:j,onNewChat:N,onSelect:(e,t,n)=>_(e,t,n),onArchivedCurrent:g}),(0,d.jsx)(Qe,{})]}),(0,d.jsx)(`div`,{ref:k,className:`flex-1 overflow-y-auto px-3 pb-2 ${V?`min-h-24`:`min-h-0`}`,children:(0,d.jsx)(`div`,{ref:K,className:`pt-2`,children:i?(0,d.jsxs)(d.Fragment,{children:[i.manualEntry&&P.length===0&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i.manualEntry.prompt}),(0,d.jsx)(Be,{activity:ee,questions:B,docked:V,pinUserMessages:!V}),i.panelExtra&&(0,d.jsx)(`div`,{className:`mt-3`,children:i.panelExtra}),L.length>0&&(0,d.jsx)(Be,{activity:L,questions:B,docked:V,pinUserMessages:!V}),!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:()=>{i.agent.sendMessage(O.retryMessage,{retry:!0}).then(e=>{e&&i.onApplied(e)})}}),!i.agent.remote&&(0,d.jsx)(l.ActionButton,{label:O.continueWithoutAi,variant:`secondary`,className:`shrink-0`,onClick:()=>{if(U){b(U.id,S);return}let e=i.agent.runFallback();e&&i.onApplied(e)}})]})]}):p.length>0?(0,d.jsx)(Vt,{messages:p}):f?(0,d.jsx)(Bt,{card:f}):(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c??O.orchestratorStarterHint})})}),i&&V?(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)(Le,{entry:V.entry,part:V.part,questions:B,autoFocus:!0},`${V.entry.id}:${V.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)(It,{task:i},i.id):(0,d.jsx)(Lt,{})]})]})]}):(0,d.jsxs)(d.Fragment,{children:[q,J,ne,ie,X]})}function Wt(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 Gt(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])}exports.AGENTICO_MAX_WIDTH=Ue,exports.AGENTICO_MIN_WIDTH=He,exports.AGENTICO_WIDTH=Ve,exports.AGENTICO_WIDTH_STORAGE_KEY=We,exports.Agentico=Ut,exports.AgenticoProvider=Te,exports.AgenticoToggle=Qe,exports.DEFAULT_REASONING_PART_ID=p,exports.DEFAULT_TEXT_PART_ID=f,exports.JSON_EXPORT_DESTINATION_ID=W,exports.MICRO_PROMPT_REGISTRY=z,exports.ORCHESTRATOR_TASK_ID=Ce,exports.SUMMARY_MICRO_PROMPT=R,exports.agenticoDe=ne,exports.agenticoEn=J,exports.agenticoIt=Y,exports.agenticoPromptsEn=O,exports.agenticoPromptsIt=k,exports.agenticoTranslations=Se,exports.applyMicroPrompts=B,exports.chatHasPersonMessage=he,exports.chatStartedAt=ve,exports.chatTitle=me,exports.configureAgenticoPrompts=j,exports.configureEntityChatStore=ie,exports.createCrossAgentTools=w,exports.defineSubagent=_,exports.entityChatTaskId=xe,exports.extractErrorMessage=V,exports.extractJsonBlock=H,exports.findSubagentManifest=x,exports.formatQuestionAnswers=g,exports.getAgenticoPrompts=M,exports.getDestinationRegistry=te,exports.getEntityChat=le,exports.getSubagentControls=wt,exports.getSubagentRegistry=b,exports.getSubagentReport=yt,exports.jsonExportDestination=G,exports.listEntityChats=be,exports.messagePartsText=h,exports.onEntityChatsChange=se,exports.registerCrossAgentTools=C,exports.registerDestinations=q,exports.registerSubagentControls=Ct,exports.registerSubagentReports=vt,exports.registerSubagents=y,exports.removeEntityChat=ye,exports.renameEntityChat=_e,exports.renderRegistryCli=L,exports.renderSubagentCli=ee,exports.resetAgenticoPrompts=N,exports.saveEntityChat=ue,exports.toJsonSchema=T,exports.toMcpTool=E,exports.upsertMessagePart=m,exports.useAgent=lt,exports.useAgentico=$,exports.useAgenticoI18n=Q,exports.useAgenticoPageContext=Wt,exports.useSubagentComponentContext=Gt;
28
+ `).map(e=>e.trim()).find(Boolean)??``).replace(/^(title|titolo)\s*:\s*/i,``).replace(/^#+\s*/,``).replace(/^["'«“]+|["'»”]+$/g,``).replace(/[.。]+$/,``).trim().slice(0,80)}function Dt(e,t){try{return e.definition.executor?.catalogProviders?.(e.toParams(t))}catch{return}}function Ot(e,t,n,r,i){let a=Dt(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 kt(e){let t=(0,l.useAIProviderRegistry)()?.registry??{},{modelsByProvider:n,selectedModel:r}=nt(),i=(0,u.useRef)({registry:t,modelsByProvider:n,selectedModel:r});i.current={registry:t,modelsByProvider:n,selectedModel:r};let a=(0,u.useRef)(new Set),o=(0,u.useCallback)(async(t,n,r)=>{if(!e)return!1;let o=le(e,t,n),s=x(t),c=`${e}:${t}:${n}`;if(!o||!s?.autoTitle||o.name||!he(o)||a.current.has(c))return!1;let{registry:u,modelsByProvider:d,selectedModel:f}=i.current,p=Ot(s,o.params,r??f,d,u),m=p?(0,l.parseAIModelRef)(p):null;if(!m)return!1;a.current.add(c);try{let r=await u[m.provider].complete({prompt:M().chatTitle.replace(`{chat}`,Tt(o.activity)),model:m.model,history:[]}),i=r&&r.type===`text`?Et(r.text):``;return i?_e(e,t,n,i,`model`):!1}catch{return!1}finally{a.current.delete(c)}},[e]),s=Object.keys(n).length>0;return(0,u.useEffect)(()=>{e&&s&&!At.has(e)&&(At.add(e),(async()=>{for(let t of be(e)){let n=x(t.subagentId);if(n?.autoTitle){if(n.definition.conversational&&!he(t)){ye(e,t.subagentId,t.entityId);continue}t.name||await o(t.subagentId,t.entityId)}}})())},[e,s,o]),o}var At=new Set,jt=()=>({});function Mt({manifest:e,params:t,extraDestinations:n,precedingActivity:r,taskId:i,resumeSeed:a,model:o,openingMessage:s}){let c=lt(e.definition,{defaultEnabled:!0}),f=$(),p=f.scope,m=(0,l.useProxy)(),h=(0,u.useRef)(i??`subagent-${e.id}-${crypto.randomUUID()}`).current,[g,_]=(0,u.useState)(null),v=t=>{e.definition.conversational||_(t)},[y,b]=(0,u.useState)([]),[x,S]=(0,u.useState)(null),C=yt(e.id),w=C?.kind===`selection`?C:null,[T,E]=(0,u.useState)(null),D=(0,u.useRef)(!1),O=(0,u.useRef)(0),k=(0,u.useRef)(null);g&&g!==k.current&&(k.current=g,O.current=(r?.length??0)+c.activity.length);let A=(0,u.useRef)(!1),j=c.remote||!c.hasProviders||c.selectedModel!==``;(0,u.useEffect)(()=>{!D.current&&j&&(D.current=!0,a?(B.current=!0,c.resume(e.toParams(t),a)):(o&&c.setSelectedModel(o),c.run(e.toParams(t),{model:o,openingMessage:s}).then(e=>{e&&v(e)})))},[j]),(0,u.useEffect)(()=>{if(!g||!p)return;let n=e.autoApplyDestinationIds??[],r=f.componentAnchors.find(t=>t.subagentId===e.id&&t.pinnedEntityId)?.pinnedEntityId,i=te();n.forEach(n=>{let a=i[n];a&&(S(null),a.apply(g,{scopeId:p.id,dataProvider:p.dataProvider,storageProvider:p.storageProvider,proxyFetch:m},{...t,pinnedEntityId:r}).then(n=>{n?.id&&f.commitEntityChat(e.id,n.id,h,p.id,t,ht(e,t))}).catch(e=>S(e instanceof Error?e.message:String(e))))})},[g,c.activity,p]),(0,u.useEffect)(()=>{g&&w&&E(w.defaultSelection(g))},[g,w]);let M=(e,t)=>{E(n=>n&&{...n,[e]:t})},N=e=>v(e),P=(0,u.useMemo)(()=>g&&w&&T?w.applySelection(g,T):g,[g,w,T]),F=(0,u.useMemo)(()=>f.componentAnchors.filter(t=>t.subagentId===e.id&&t.onResult),[f.componentAnchors,e.id]),I=(0,u.useMemo)(()=>xt(F,t,h),[F,t,h]),ee=(0,u.useMemo)(()=>I?[I,...n??[]]:n,[I,n]),L=e.chatEntityId?.(t),R=kt(p?.id),z=(0,u.useRef)(!1),B=(0,u.useRef)(!1);(0,u.useEffect)(()=>{let n=!z.current&&c.running,i=z.current&&!c.running;if(z.current=c.running,!n&&!i||!L||!p)return;if(B.current){i&&(B.current=!1);return}let a=c.snapshot();if(!a)return;let o=[...r??[],...a.activity];e.autoTitle&&e.definition.conversational&&!he({activity:o})||(ue({scopeId:p.id,subagentId:e.id,entityId:L,params:t,title:ht(e,t),history:a.history,activity:o}),i&&e.autoTitle&&R(e.id,L,c.selectedModel))},[c.running]);let V=()=>{A.current=!0,c.running&&c.stop(),f.closeTask(h)},H=(0,u.useRef)(wt(e.id)??jt).current,U=H({params:t,taskId:h,running:c.running,close:V}),W=e=>{b(t=>t.includes(e)?t:[...t,e])};return(0,u.useEffect)(()=>{A.current||f.openTask({id:h,title:ht(e,t),icon:e.icon,agent:c,onApplied:e=>v(e),precedingActivity:r,panelExtraAnchorIndex:O.current,onDismiss:V,...L?{savedToDisk:!0}:{},panelActions:U.content,composerActions:U.actions,composerCommands:U.commands,panelExtra:g?(0,d.jsxs)(d.Fragment,{children:[w&&T?(0,d.jsx)(w.Report,{result:g,selection:T,onChange:M}):C?.kind===`editable`?(0,d.jsx)(C.Report,{result:g,onResultChange:N}):(0,d.jsx)(bt,{result:P}),x&&(0,d.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Salvataggio automatico non riuscito: `,x]}),(0,d.jsx)(gt,{manifest:e,result:P,meta:t,taskId:h,initiallyApplied:y,onApplied:W,extraDestinations:ee})]}):void 0})},[c.activity,c.running,c.error,c.canContinue,c.selectedModel,c.modelsByProvider,c.hasProviders,c.remoteModels,f.openTask,f.componentAnchors,h,e,t,g,P,T,y,n,r,x,U.content,U.actions,U.commands]),(0,u.useEffect)(()=>()=>{f.closeTask(h)},[f.closeTask,h]),null}function Nt({userGoal:e}){let t=Q(),n=lt((0,u.useMemo)(()=>mt({unavailable:t.orchestratorUnavailable,continueWithoutAi:t.orchestratorContinueWithoutAi,preparing:t.orchestratorPreparing,collecting:t.orchestratorCollecting}),[]),{defaultEnabled:!0}),r=$(),[i,a]=(0,u.useState)(null),o=(0,u.useRef)(!1),s=!n.hasProviders||n.selectedModel!==``,c=(0,u.useRef)(r.pendingExtraDestinations),l=(0,u.useRef)(r.pendingAttachments),f=(0,u.useRef)(r.pendingModel),p=(0,u.useRef)(r.pendingScopedSubagentId??r.scopedSubagentId??void 0),m=(0,u.useRef)(r.pendingCarryOver),h=(0,u.useRef)(!1),g=e=>{e&&typeof e==`object`&&e.kind===`handoff`&&(a(e),r.closeTask(Ce))};(0,u.useEffect)(()=>{!o.current&&s&&(o.current=!0,f.current&&n.setSelectedModel(f.current),n.run({userGoal:e,pageContext:r.pageContext,scopedSubagentId:p.current??null},{attachments:l.current,model:f.current,openingMessage:e}).then(e=>{e&&g(e)}))},[s]),(0,u.useEffect)(()=>{h.current||r.openTask({id:Ce,title:`Agentico`,icon:`bot`,agent:n,onApplied:g,scopedSubagentId:p.current,precedingActivity:m.current?.activity,onDismiss:()=>{h.current=!0,n.running&&n.stop(),r.closeTask(Ce)}})},[n.activity,n.running,n.error,n.canContinue,n.selectedModel,n.modelsByProvider,n.hasProviders,r.openTask]),(0,u.useEffect)(()=>()=>{r.closeTask(Ce)},[r.closeTask]);let _=(0,u.useMemo)(()=>[...m.current?.activity??[],...n.activity],[n.activity]);if(!i)return null;let v=x(i.subagentId);return v?(0,d.jsx)(Mt,{manifest:v,params:i.params,extraDestinations:c.current,model:f.current||void 0,taskId:m.current?.taskId,precedingActivity:_}):null}function Pt({manifest:e,extraDestinations:t}){let n=lt(e.definition,{defaultEnabled:!1}),r=Q(),i=$(),a=(0,u.useRef)(`manual-${e.id}-${crypto.randomUUID()}`).current,[o,s]=(0,u.useState)(null),[c,f]=(0,u.useState)([]),p=yt(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 r;try{r=e.manualEntry.fromRawText(t)}catch(e){console.error(`[ManualEntryRunner] manualEntry.fromRawText ha rifiutato il testo:`,e);return}v(r),f([]),n.run(r,{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)(()=>i.componentAnchors.filter(t=>t.subagentId===e.id&&t.onResult),[i.componentAnchors,e.id]),E=(0,u.useMemo)(()=>_?xt(T,_,a):null,[T,_,a]),D=(0,u.useMemo)(()=>E?[E,...t??[]]:t,[E,t]);return(0,u.useEffect)(()=>{y.current||i.openTask({id:a,title:e.label,icon:e.icon,agent:n,onApplied:e=>s(e),manualEntry:e.manualEntry?{prompt:e.manualEntry.prompt,onSubmit:b}:void 0,onDismiss:()=>{y.current=!0,n.running&&n.stop(),i.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)(bt,{result:C}),(0,d.jsx)(gt,{manifest:e,result:C,meta:_??{},taskId:a,initiallyApplied:c,onApplied:w,extraDestinations:D}),n.hasProviders&&(0,d.jsx)(l.ActionButton,{label:r.resumeWithAi,variant:`outline-secondary`,className:`text-xs`,onClick:()=>{_&&i.resumeWithAI(e.id,_,t)}})]}):void 0})},[n.activity,n.running,n.error,n.hasProviders,i.componentAnchors,o,C,h,c,_]),(0,u.useEffect)(()=>()=>{i.closeTask(a)},[]),null}function Ft(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 It({task:e}){let t=Q(),[n,r]=(0,u.useState)(``),{agent:i,onApplied:a,manualEntry:o}=e,s=i.running,c=e=>{if(r(``),o){o.onSubmit(e.text);return}i.sendMessage(e.text,{attachments:e.files,model:e.model}).then(e=>{e&&a(e)})},f=!!o||i.remote&&i.remoteModels.length===0,p=i.alongside&&i.remoteModels.some(e=>e.value===i.selectedModel),m=!f&&!i.remote&&!p&&i.hasProviders&&!i.selectedModel,h=f?[]:i.remote?i.remoteModels:i.alongside?[...i.remoteModels,...Ft(i.modelsByProvider,i.catalogGroup)]:Ft(i.modelsByProvider);return(0,d.jsx)(l.Chatbot,{value:n,onChange:r,placeholder:o?.prompt??t.messagePlaceholder,running:s,onStop:i.stop,disabled:!n.trim()||m,onSubmit:c,attachments:!o&&!i.remote&&!p,models:h,selectedModel:f?``:i.selectedModel,actions:e.composerActions,commands:e.composerCommands,onModelChange:i.setSelectedModel,modelPlaceholder:t.selectModelPlaceholder,minHeight:44,maxHeight:220})}function Lt(){let{startOrchestrator:e}=$(),t=Q(),[n,r]=(0,u.useState)(``),{hasProviders:i,modelsByProvider:a,selectedModel:o,setSelectedModel:s}=nt(),c=t=>{t.text.trim()&&(e(t.text.trim(),{attachments:t.files.length>0?t.files:void 0,model:t.model||void 0}),r(``))},f=i&&!o;return(0,d.jsx)(l.Chatbot,{value:n,onChange:r,placeholder:t.orchestratorStarterPlaceholder,disabled:!n.trim()||f,onSubmit:c,attachments:!0,models:Ft(a),selectedModel:o,onModelChange:s,modelPlaceholder:t.selectModelPlaceholder,minHeight:44,maxHeight:220})}function Rt({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:()=>(_e(e.scopeId,e.subagentId,e.entityId,String(r.record?.title??me(e)),`person`),t(),Promise.resolve(!0)),children:(0,d.jsxs)(l.Form,{appearance:`empty`,controller:r,defaultValues:{title:me(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 zt(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 Bt({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 Vt({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 Ht({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)(()=>se(()=>h(e=>e+1)),[]);let g=(0,u.useMemo)(()=>n?be(e):[],[e,n,m]),[_,v]=(0,u.useState)(null),y=async n=>{let r=x(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}ye(e,n.subagentId,n.entityId),t===xe(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=x(t.subagentId)?.label??t.subagentId;return me(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=x(e.subagentId),a=t===xe(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} · ${me(e)}`,children:me(e)}),(0,d.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,title:`${s.chatStarted.replace(`{at}`,new Date(ve(e)).toLocaleString(c))} · ${s.chatLastMessage.replace(`{at}`,new Date(e.savedAt).toLocaleString(c))}`,children:zt(ve(e),c)})]})},`${e.subagentId}:${e.entityId}`)})}),_&&(0,d.jsx)(Rt,{chat:_,onClose:()=>v(null)})]})}function Ut({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:S,pendingResumeWithAI:C,resumeWithAIRunId:w,pendingStart:T,startRunId:E,scope:D}=$(),O=Q(),k=(0,u.useRef)(null),[A,j]=(0,u.useState)(!1);kt(D?.id);let M=Xe({defaultWidth:e,minWidth:t,maxWidth:n,onWidthChange:r}),N=()=>{(!i||i.agent.running||i.savedToDisk||window.confirm(O.unsavedConversationConfirm))&&(g(),j(!1))},P=i?[...i.precedingActivity??[],...i.agent.activity]:[],F=P.length,I=Math.max(0,Math.min(i?.panelExtraAnchorIndex??F,F)),ee=P.slice(0,I),L=P.slice(I),R=!!(i&&!i.agent.running&&i.agent.error),z=new Set(i?.agent.activity.map(e=>e.id)??[]),B=i?{canAnswer:e=>z.has(e),onAnswer:(e,t,n)=>i.agent.answerQuestions(e,t,n).then(e=>{e&&i.onApplied(e)})}:void 0,V=B?Ie(P,B.canAnswer):null,H=i?.id===`agentico-orchestrator`&&i.scopedSubagentId?x(i.scopedSubagentId):void 0,U=H?.manualEntry?H:null,W=(0,u.useRef)(!0);(0,u.useEffect)(()=>{let e=k.current;if(!e)return;let t=()=>{W.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&&(W.current=!0,e.scrollTop=e.scrollHeight)},[i?.id]);let G=P.at(-1)?.detail?.length??0;(0,u.useEffect)(()=>{let e=k.current;e&&W.current&&(e.scrollTop=e.scrollHeight)},[F,R,G]);let K=(0,u.useRef)(null);(0,u.useEffect)(()=>{let e=k.current,t=K.current;if(!e||!t||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{W.current&&(e.scrollTop=e.scrollHeight)});return n.observe(t),()=>n.disconnect()},[i?.id,a]);let q=o?(0,d.jsx)(Nt,{userGoal:o},s):null,te=m?x(m.subagentId):void 0,J=m&&te?(0,d.jsx)(Mt,{manifest:te,params:m.snapshot.params,taskId:xe(m.subagentId,m.entityId),resumeSeed:{history:m.snapshot.history,activity:m.snapshot.activity}},h):null,Y=v?x(v.subagentId):void 0,ne=v&&Y?(0,d.jsx)(Pt,{manifest:Y,extraDestinations:v.extraDestinations},y):null,re=C?x(C.subagentId):void 0,ie=C&&re?(0,d.jsx)(Mt,{manifest:re,params:C.params,extraDestinations:C.extraDestinations},w):null,ae=T?x(T.subagentId):void 0,X=T&&ae?(0,d.jsx)(Mt,{manifest:ae,params:T.params,taskId:T.taskId,openingMessage:T.openingMessage},E):null;return a?(0,d.jsxs)(d.Fragment,{children:[q,J,ne,ie,X,(0,d.jsxs)(`div`,{style:{width:M.width},className:`relative flex h-full shrink-0 flex-col border-l border-border bg-background`,children:[(0,d.jsx)(Ze,{width:M.width,min:M.min,max:M.max,onResize:M.set,onCommit:M.commit,onReset:M.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`}),D&&(0,d.jsx)(Ht,{scopeId:D.id,currentTaskId:i?.id??null,open:A,onOpenChange:j,onNewChat:N,onSelect:(e,t,n)=>_(e,t,n),onArchivedCurrent:g}),(0,d.jsx)(Qe,{})]}),(0,d.jsx)(`div`,{ref:k,className:`flex-1 overflow-y-auto px-3 pb-2 ${V?`min-h-24`:`min-h-0`}`,children:(0,d.jsx)(`div`,{ref:K,className:`pt-2`,children:i?(0,d.jsxs)(d.Fragment,{children:[i.manualEntry&&P.length===0&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i.manualEntry.prompt}),(0,d.jsx)(Be,{activity:ee,questions:B,docked:V,pinUserMessages:!V}),i.panelExtra&&(0,d.jsx)(`div`,{className:`mt-3`,children:i.panelExtra}),L.length>0&&(0,d.jsx)(Be,{activity:L,questions:B,docked:V,pinUserMessages:!V}),!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:()=>{i.agent.sendMessage(O.retryMessage,{retry:!0}).then(e=>{e&&i.onApplied(e)})}}),!i.agent.remote&&(0,d.jsx)(l.ActionButton,{label:O.continueWithoutAi,variant:`secondary`,className:`shrink-0`,onClick:()=>{if(U){b(U.id,S);return}let e=i.agent.runFallback();e&&i.onApplied(e)}})]})]}):p.length>0?(0,d.jsx)(Vt,{messages:p}):f?(0,d.jsx)(Bt,{card:f}):(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c??O.orchestratorStarterHint})})}),i&&V?(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)(Le,{entry:V.entry,part:V.part,questions:B,autoFocus:!0},`${V.entry.id}:${V.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)(It,{task:i},i.id):(0,d.jsx)(Lt,{})]})]})]}):(0,d.jsxs)(d.Fragment,{children:[q,J,ne,ie,X]})}function Wt(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 Gt(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])}exports.AGENTICO_MAX_WIDTH=Ue,exports.AGENTICO_MIN_WIDTH=He,exports.AGENTICO_WIDTH=Ve,exports.AGENTICO_WIDTH_STORAGE_KEY=We,exports.Agentico=Ut,exports.AgenticoProvider=Te,exports.AgenticoToggle=Qe,exports.DEFAULT_REASONING_PART_ID=p,exports.DEFAULT_TEXT_PART_ID=f,exports.JSON_EXPORT_DESTINATION_ID=W,exports.MICRO_PROMPT_REGISTRY=z,exports.ORCHESTRATOR_TASK_ID=Ce,exports.SUMMARY_MICRO_PROMPT=R,exports.agenticoDe=ne,exports.agenticoEn=J,exports.agenticoIt=Y,exports.agenticoPromptsEn=O,exports.agenticoPromptsIt=k,exports.agenticoTranslations=Se,exports.applyMicroPrompts=B,exports.chatHasPersonMessage=he,exports.chatStartedAt=ve,exports.chatTitle=me,exports.configureAgenticoPrompts=j,exports.configureEntityChatStore=ie,exports.createCrossAgentTools=w,exports.defineSubagent=_,exports.entityChatTaskId=xe,exports.extractErrorMessage=V,exports.extractJsonBlock=H,exports.findSubagentManifest=x,exports.formatQuestionAnswers=g,exports.getAgenticoPrompts=M,exports.getDestinationRegistry=te,exports.getEntityChat=le,exports.getSubagentControls=wt,exports.getSubagentRegistry=b,exports.getSubagentReport=yt,exports.jsonExportDestination=G,exports.listEntityChats=be,exports.messagePartsText=h,exports.onEntityChatsChange=se,exports.registerCrossAgentTools=C,exports.registerDestinations=q,exports.registerSubagentControls=Ct,exports.registerSubagentReports=vt,exports.registerSubagents=y,exports.removeEntityChat=ye,exports.renameEntityChat=_e,exports.renderRegistryCli=L,exports.renderSubagentCli=ee,exports.resetAgenticoPrompts=N,exports.saveEntityChat=ue,exports.toJsonSchema=T,exports.toMcpTool=E,exports.upsertMessagePart=m,exports.useAgent=lt,exports.useAgentico=$,exports.useAgenticoI18n=Q,exports.useAgenticoPageContext=Wt,exports.useSubagentComponentContext=Gt;
29
29
  //# sourceMappingURL=index.js.map