@llmnative/agentico 0.4.0 → 0.5.0

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/README.md CHANGED
@@ -63,11 +63,36 @@ configureAgenticoPrompts({ // optional: langu
63
63
  | **Message parts** — a remote reply in parts, as in the Vercel AI SDK / AG-UI: Markdown text (tables, lists, code; repaired while it streams), the reasoning of the model (closed, "Reasoned for 12 s"), the steps grouped and collapsible, questions answered with a click. Answers go back structured: to the waiting turn (`onQuestions` resolves) or as a new turn with `answers`. Parts are saved with the chat; chats saved with text only still load | `AgentExecutorTurn.onText(text, { id?, done? })`, `onReasoning(text, { id?, done?, duration? })`, `onStep`, `onQuestions(questions, { id? })`, `AgentExecutorTurn.answers`, `AgentMessagePart`, `useAgent().answerQuestions` |
64
64
  | **Panel** — a column beside the page, resizable by dragging its inner edge (or with the arrow keys on it; double click resets), the width kept per browser (`localStorage`, key `agentico:panel-width`). Questions waiting in the latest message of the agent are docked at the bottom in place of the composer, until answered or stopped | `<Agentico defaultWidth minWidth maxWidth onWidthChange>`, `AGENTICO_WIDTH`, `AGENTICO_MIN_WIDTH`, `AGENTICO_MAX_WIDTH` |
65
65
  | **Direct start** — a page starts a subagent without the orchestrator; with `chatEntityId` its chat is saved at every turn under that entity and resumed from the history; `onlyWhenAnchored` keeps it off the other pages | `useAgentico().startSubagent`, `entityChatTaskId`, `SubagentManifest.chatEntityId`, `SubagentManifest.onlyWhenAnchored` |
66
- | **Controls** — the actions of the prompt of a subagent (e.g. "Finish") and what the host shows above it, from a hook of the host | `registerSubagentControls` |
66
+ | **Controls** — the actions of the prompt of a subagent (e.g. "Finish"), its slash commands (e.g. `/to-spec`, sent as plain text to the executor) and what the host shows above it, from a hook of the host | `registerSubagentControls` |
67
67
  | **History** — chats per entity, the open one marked, archived on hover (with the host deciding what archiving does) | `SubagentManifest.onArchive`, `confirmArchive` |
68
68
  | **Prompts** — model-facing text (en default, it included) | `configureAgenticoPrompts`, `agenticoPromptsEn`, `agenticoPromptsIt` |
69
69
  | **Strings** — user-facing text, namespace `agentico` of the framework i18n (en/it/de) | `agenticoTranslations`, `I18nDict.agentico` |
70
70
 
71
+ ### Controls of a subagent
72
+
73
+ ```tsx
74
+ import type { EditorCommand } from '@llmnative/react';
75
+
76
+ // A module constant keeps its identity; inside the hook use `useMemo`.
77
+ const commands: EditorCommand[] = [{ name: 'to-spec', description: 'Turn the design into a spec' }];
78
+
79
+ registerSubagentControls({
80
+ design: ({ running }) => {
81
+ const openFinish = useFinishModal(); // the host's own
82
+ return useMemo(() => ({
83
+ actions: [{ key: 'finish', label: 'Finish', icon: 'git-pull-request', disabled: running, onClick: openFinish }],
84
+ commands,
85
+ }), [running, openFinish]);
86
+ },
87
+ });
88
+ ```
89
+
90
+ Actions, commands and content must keep their identity while nothing changes: a new one registers
91
+ the task again. Typing `/` in the prompt of the task opens the commands; one without `handler`
92
+ inserts `/name ` and the message reaches the executor's turn as plain `text` (`"/to-spec checkout"`):
93
+ Agentico gives it no meaning. The commands live in the composer, so none are offered while docked
94
+ questions take its place.
95
+
71
96
  ## Development
72
97
 
73
98
  ```bash
package/dist/index.js CHANGED
@@ -17,5 +17,5 @@ ${i}
17
17
  ${Ze()}
18
18
 
19
19
  ${r.userRequestHeading}
20
- ${e}`}function $e(e,t){return t?{kind:`handoff`,...t}:{kind:`chat`,message:e}}function et(e){return b().filter(t=>!t.onlyWhenAnchored||e===t.id)}function tt(e){return{buildContext(e){return{cliCatalog:R(et(e.scopedSubagentId)),handoff:{current:null},collected:{}}},buildPrompt({userGoal:e,pageContext:t},{cliCatalog:n}){return Qe(e,n,t)},buildFollowUpPrompt(e,t,{cliCatalog:n}){return`${e}\n\n${Ze()}\n\n${M().toolsHeading}\n${n}`},parseResponse(e,t,n){let r=n.handoff.current;return n.handoff.current=null,$e(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=et(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 nt(e,t){return e.deriveHistoryTitle?.(t)??e.label}function rt({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=q(),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(W.id,W);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,nt(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 it={};function at(e){Object.assign(it,e)}function ot(e){return it[e]}function st({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 ct(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 lt={};function ut(e){Object.assign(lt,e)}function dt(e){return lt[e]}var ft=()=>({});function pt({manifest:e,params:t,extraDestinations:n,precedingActivity:r,taskId:i,resumeSeed:a,model:o,openingMessage:s}){let c=Xe(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,y]=(0,u.useState)([]),[b,x]=(0,u.useState)(null),S=ot(e.id),C=S?.kind===`selection`?S:null,[w,T]=(0,u.useState)(null),E=(0,u.useRef)(!1),D=(0,u.useRef)(0),O=(0,u.useRef)(null);g&&g!==O.current&&(O.current=g,D.current=(r?.length??0)+c.activity.length);let k=(0,u.useRef)(!1),A=c.remote||!c.hasProviders||c.selectedModel!==``;(0,u.useEffect)(()=>{!E.current&&A&&(E.current=!0,a?c.resume(e.toParams(t),a):(o&&c.setSelectedModel(o),c.run(e.toParams(t),{model:o,openingMessage:s}).then(e=>{e&&_(e)})))},[A]),(0,u.useEffect)(()=>{if(!g||!p)return;let n=e.autoApplyDestinationIds??[],r=f.componentAnchors.find(t=>t.subagentId===e.id&&t.pinnedEntityId)?.pinnedEntityId,i=q();n.forEach(n=>{let a=i[n];a&&(x(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,nt(e,t))}).catch(e=>x(e instanceof Error?e.message:String(e))))})},[g,c.activity,p]),(0,u.useEffect)(()=>{g&&C&&T(C.defaultSelection(g))},[g,C]);let j=(e,t)=>{T(n=>n&&{...n,[e]:t})},M=e=>_(e),N=(0,u.useMemo)(()=>g&&C&&w?C.applySelection(g,w):g,[g,C,w]),P=(0,u.useMemo)(()=>f.componentAnchors.filter(t=>t.subagentId===e.id&&t.onResult),[f.componentAnchors,e.id]),F=(0,u.useMemo)(()=>ct(P,t,h),[P,t,h]),I=(0,u.useMemo)(()=>F?[F,...n??[]]:n,[F,n]),L=e.chatEntityId?.(t),R=(0,u.useRef)(!1);(0,u.useEffect)(()=>{let n=R.current&&!c.running;if(R.current=c.running,!n||!L||!p)return;let i=c.snapshot();i&&ae({scopeId:p.id,subagentId:e.id,entityId:L,params:t,title:nt(e,t),history:i.history,activity:[...r??[],...i.activity]})},[c.running]);let z=()=>{k.current=!0,c.running&&c.stop(),f.closeTask(h)},ee=(0,u.useRef)(dt(e.id)??ft).current,B=ee({params:t,taskId:h,running:c.running,close:z}),V=e=>{y(t=>t.includes(e)?t:[...t,e])};return(0,u.useEffect)(()=>{k.current||f.openTask({id:h,title:nt(e,t),icon:e.icon,agent:c,onApplied:e=>_(e),precedingActivity:r,panelExtraAnchorIndex:D.current,onDismiss:z,...L?{savedToDisk:!0}:{},panelActions:B.content,composerActions:B.actions,panelExtra:g?(0,d.jsxs)(d.Fragment,{children:[C&&w?(0,d.jsx)(C.Report,{result:g,selection:w,onChange:j}):S?.kind===`editable`?(0,d.jsx)(S.Report,{result:g,onResultChange:M}):(0,d.jsx)(st,{result:N}),b&&(0,d.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Salvataggio automatico non riuscito: `,b]}),(0,d.jsx)(rt,{manifest:e,result:N,meta:t,taskId:h,initiallyApplied:v,onApplied:V,extraDestinations:I})]}):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,N,w,v,n,r,b,B.content,B.actions]),(0,u.useEffect)(()=>()=>{f.closeTask(h)},[f.closeTask,h]),null}function mt({userGoal:e}){let t=Q(),n=Xe((0,u.useMemo)(()=>tt({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(pe))};(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:pe,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(pe)}})},[n.activity,n.running,n.error,n.canContinue,n.selectedModel,n.modelsByProvider,n.hasProviders,r.openTask]),(0,u.useEffect)(()=>()=>{r.closeTask(pe)},[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)(pt,{manifest:v,params:i.params,extraDestinations:c.current,model:f.current||void 0,taskId:m.current?.taskId,precedingActivity:_}):null}function ht({manifest:e,extraDestinations:t}){let n=Xe(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=ot(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)(()=>_?ct(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)(st,{result:C}),(0,d.jsx)(rt,{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 gt(e){return Object.values(e).flat().map(e=>({label:e.model,value:e.id,pricing:e.pricing??null,group:e.providerLabel??e.provider}))}function _t({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=!f&&!i.remote&&i.hasProviders&&!i.selectedModel,m=f?[]:i.remote?i.remoteModels:gt(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()||p,onSubmit:c,attachments:!o&&!i.remote,models:m,selectedModel:f?``:i.selectedModel,actions:e.composerActions,onModelChange:i.setSelectedModel,modelPlaceholder:t.selectModelPlaceholder,minHeight:44,maxHeight:220})}function vt(){let{startOrchestrator:e}=$(),t=Q(),[n,r]=(0,u.useState)(``),{hasProviders:i,modelsByProvider:a,selectedModel:o,setSelectedModel:s}=Ke(),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:gt(a),selectedModel:o,onModelChange:s,modelPlaceholder:t.selectModelPlaceholder,minHeight:44,maxHeight:220})}function yt(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 xt({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 St({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),g=(0,u.useMemo)(()=>n?se(e):[],[e,n,m]),_=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}oe(e,n.subagentId,n.entityId),t===ce(n.subagentId,n.entityId)&&o(),h(e=>e+1)}},v=(0,u.useMemo)(()=>{let e=f.trim().toLowerCase();return e?g.filter(t=>{let n=x(t.subagentId)?.label??t.subagentId;return t.title.toLowerCase().includes(e)||n.toLowerCase().includes(e)}):g},[g,f]);return(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:v.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}):v.map(e=>{let n=x(e.subagentId),r=t===ce(e.subagentId,e.entityId);return(0,d.jsx)(l.DropdownItem,{icon:r?`check`:n?.icon??`bot`,className:r?`bg-accent font-medium`:void 0,actions:[{icon:`archive`,label:s.archiveChat,onClick:()=>void _(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.jsxs)(`span`,{className:`min-w-0 truncate`,children:[(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:n?.label??e.subagentId}),` · `,e.title||e.entityId]}),(0,d.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,title:new Date(e.savedAt).toLocaleString(c),children:yt(e.savedAt,c)})]})},`${e.subagentId}:${e.entityId}`)})})}function Ct({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),M=Be({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)),L=P.slice(0,I),R=P.slice(I),z=!!(i&&!i.agent.running&&i.agent.error),ee=new Set(i?.agent.activity.map(e=>e.id)??[]),B=i?{canAnswer:e=>ee.has(e),onAnswer:(e,t,n)=>i.agent.answerQuestions(e,t,n).then(e=>{e&&i.onApplied(e)})}:void 0,V=B?Ee(P,B.canAnswer):null,H=i?.id===`agentico-orchestrator`&&i.scopedSubagentId?x(i.scopedSubagentId):void 0,te=H?.manualEntry?H:null,U=(0,u.useRef)(!0);(0,u.useEffect)(()=>{let e=k.current;if(!e)return;let t=()=>{U.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&&(U.current=!0,e.scrollTop=e.scrollHeight)},[i?.id]);let W=P.at(-1)?.detail?.length??0;(0,u.useEffect)(()=>{let e=k.current;e&&U.current&&(e.scrollTop=e.scrollHeight)},[F,z,W]);let G=(0,u.useRef)(null);(0,u.useEffect)(()=>{let e=k.current,t=G.current;if(!e||!t||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{U.current&&(e.scrollTop=e.scrollHeight)});return n.observe(t),()=>n.disconnect()},[i?.id,a]);let K=o?(0,d.jsx)(mt,{userGoal:o},s):null,q=m?x(m.subagentId):void 0,J=m&&q?(0,d.jsx)(pt,{manifest:q,params:m.snapshot.params,taskId:ce(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)(ht,{manifest:Y,extraDestinations:v.extraDestinations},y):null,X=C?x(C.subagentId):void 0,re=C&&X?(0,d.jsx)(pt,{manifest:X,params:C.params,extraDestinations:C.extraDestinations},w):null,Z=T?x(T.subagentId):void 0,ie=T&&Z?(0,d.jsx)(pt,{manifest:Z,params:T.params,taskId:T.taskId,openingMessage:T.openingMessage},E):null;return a?(0,d.jsxs)(d.Fragment,{children:[K,J,ne,re,ie,(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)(Ve,{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)(St,{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)(He,{})]}),(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:G,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)(Ae,{activity:L,questions:B,docked:V,pinUserMessages:!V}),i.panelExtra&&(0,d.jsx)(`div`,{className:`mt-3`,children:i.panelExtra}),R.length>0&&(0,d.jsx)(Ae,{activity:R,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).then(e=>{e&&i.onApplied(e)})}}),!i.agent.remote&&(0,d.jsx)(l.ActionButton,{label:O.continueWithoutAi,variant:`secondary`,className:`shrink-0`,onClick:()=>{if(te){b(te.id,S);return}let e=i.agent.runFallback();e&&i.onApplied(e)}})]})]}):p.length>0?(0,d.jsx)(xt,{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)(De,{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)(_t,{task:i},i.id):(0,d.jsx)(vt,{})]})]})]}):(0,d.jsxs)(d.Fragment,{children:[K,J,ne,re,ie]})}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 Tt(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=Ne,exports.AGENTICO_MIN_WIDTH=Me,exports.AGENTICO_WIDTH=je,exports.AGENTICO_WIDTH_STORAGE_KEY=Pe,exports.Agentico=Ct,exports.AgenticoProvider=he,exports.AgenticoToggle=He,exports.DEFAULT_REASONING_PART_ID=p,exports.DEFAULT_TEXT_PART_ID=f,exports.JSON_EXPORT_DESTINATION_ID=U,exports.MICRO_PROMPT_REGISTRY=ee,exports.ORCHESTRATOR_TASK_ID=pe,exports.SUMMARY_MICRO_PROMPT=z,exports.agenticoDe=le,exports.agenticoEn=ue,exports.agenticoIt=de,exports.agenticoPromptsEn=O,exports.agenticoPromptsIt=k,exports.agenticoTranslations=fe,exports.applyMicroPrompts=B,exports.configureAgenticoPrompts=j,exports.configureEntityChatStore=Y,exports.createCrossAgentTools=w,exports.defineSubagent=_,exports.entityChatTaskId=ce,exports.extractErrorMessage=V,exports.extractJsonBlock=H,exports.findSubagentManifest=x,exports.formatQuestionAnswers=g,exports.getAgenticoPrompts=M,exports.getDestinationRegistry=q,exports.getEntityChat=ie,exports.getSubagentControls=dt,exports.getSubagentRegistry=b,exports.getSubagentReport=ot,exports.jsonExportDestination=W,exports.listEntityChats=se,exports.messagePartsText=h,exports.registerCrossAgentTools=C,exports.registerDestinations=K,exports.registerSubagentControls=ut,exports.registerSubagentReports=at,exports.registerSubagents=y,exports.removeEntityChat=oe,exports.renderRegistryCli=R,exports.renderSubagentCli=L,exports.resetAgenticoPrompts=N,exports.saveEntityChat=ae,exports.toJsonSchema=T,exports.toMcpTool=E,exports.upsertMessagePart=m,exports.useAgent=Xe,exports.useAgentico=$,exports.useAgenticoI18n=Q,exports.useAgenticoPageContext=wt,exports.useSubagentComponentContext=Tt;
20
+ ${e}`}function $e(e,t){return t?{kind:`handoff`,...t}:{kind:`chat`,message:e}}function et(e){return b().filter(t=>!t.onlyWhenAnchored||e===t.id)}function tt(e){return{buildContext(e){return{cliCatalog:R(et(e.scopedSubagentId)),handoff:{current:null},collected:{}}},buildPrompt({userGoal:e,pageContext:t},{cliCatalog:n}){return Qe(e,n,t)},buildFollowUpPrompt(e,t,{cliCatalog:n}){return`${e}\n\n${Ze()}\n\n${M().toolsHeading}\n${n}`},parseResponse(e,t,n){let r=n.handoff.current;return n.handoff.current=null,$e(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=et(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 nt(e,t){return e.deriveHistoryTitle?.(t)??e.label}function rt({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=q(),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(W.id,W);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,nt(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 it={};function at(e){Object.assign(it,e)}function ot(e){return it[e]}function st({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 ct(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 lt={};function ut(e){Object.assign(lt,e)}function dt(e){return lt[e]}var ft=()=>({});function pt({manifest:e,params:t,extraDestinations:n,precedingActivity:r,taskId:i,resumeSeed:a,model:o,openingMessage:s}){let c=Xe(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,y]=(0,u.useState)([]),[b,x]=(0,u.useState)(null),S=ot(e.id),C=S?.kind===`selection`?S:null,[w,T]=(0,u.useState)(null),E=(0,u.useRef)(!1),D=(0,u.useRef)(0),O=(0,u.useRef)(null);g&&g!==O.current&&(O.current=g,D.current=(r?.length??0)+c.activity.length);let k=(0,u.useRef)(!1),A=c.remote||!c.hasProviders||c.selectedModel!==``;(0,u.useEffect)(()=>{!E.current&&A&&(E.current=!0,a?c.resume(e.toParams(t),a):(o&&c.setSelectedModel(o),c.run(e.toParams(t),{model:o,openingMessage:s}).then(e=>{e&&_(e)})))},[A]),(0,u.useEffect)(()=>{if(!g||!p)return;let n=e.autoApplyDestinationIds??[],r=f.componentAnchors.find(t=>t.subagentId===e.id&&t.pinnedEntityId)?.pinnedEntityId,i=q();n.forEach(n=>{let a=i[n];a&&(x(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,nt(e,t))}).catch(e=>x(e instanceof Error?e.message:String(e))))})},[g,c.activity,p]),(0,u.useEffect)(()=>{g&&C&&T(C.defaultSelection(g))},[g,C]);let j=(e,t)=>{T(n=>n&&{...n,[e]:t})},M=e=>_(e),N=(0,u.useMemo)(()=>g&&C&&w?C.applySelection(g,w):g,[g,C,w]),P=(0,u.useMemo)(()=>f.componentAnchors.filter(t=>t.subagentId===e.id&&t.onResult),[f.componentAnchors,e.id]),F=(0,u.useMemo)(()=>ct(P,t,h),[P,t,h]),I=(0,u.useMemo)(()=>F?[F,...n??[]]:n,[F,n]),L=e.chatEntityId?.(t),R=(0,u.useRef)(!1);(0,u.useEffect)(()=>{let n=R.current&&!c.running;if(R.current=c.running,!n||!L||!p)return;let i=c.snapshot();i&&ae({scopeId:p.id,subagentId:e.id,entityId:L,params:t,title:nt(e,t),history:i.history,activity:[...r??[],...i.activity]})},[c.running]);let z=()=>{k.current=!0,c.running&&c.stop(),f.closeTask(h)},ee=(0,u.useRef)(dt(e.id)??ft).current,B=ee({params:t,taskId:h,running:c.running,close:z}),V=e=>{y(t=>t.includes(e)?t:[...t,e])};return(0,u.useEffect)(()=>{k.current||f.openTask({id:h,title:nt(e,t),icon:e.icon,agent:c,onApplied:e=>_(e),precedingActivity:r,panelExtraAnchorIndex:D.current,onDismiss:z,...L?{savedToDisk:!0}:{},panelActions:B.content,composerActions:B.actions,composerCommands:B.commands,panelExtra:g?(0,d.jsxs)(d.Fragment,{children:[C&&w?(0,d.jsx)(C.Report,{result:g,selection:w,onChange:j}):S?.kind===`editable`?(0,d.jsx)(S.Report,{result:g,onResultChange:M}):(0,d.jsx)(st,{result:N}),b&&(0,d.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Salvataggio automatico non riuscito: `,b]}),(0,d.jsx)(rt,{manifest:e,result:N,meta:t,taskId:h,initiallyApplied:v,onApplied:V,extraDestinations:I})]}):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,N,w,v,n,r,b,B.content,B.actions,B.commands]),(0,u.useEffect)(()=>()=>{f.closeTask(h)},[f.closeTask,h]),null}function mt({userGoal:e}){let t=Q(),n=Xe((0,u.useMemo)(()=>tt({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(pe))};(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:pe,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(pe)}})},[n.activity,n.running,n.error,n.canContinue,n.selectedModel,n.modelsByProvider,n.hasProviders,r.openTask]),(0,u.useEffect)(()=>()=>{r.closeTask(pe)},[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)(pt,{manifest:v,params:i.params,extraDestinations:c.current,model:f.current||void 0,taskId:m.current?.taskId,precedingActivity:_}):null}function ht({manifest:e,extraDestinations:t}){let n=Xe(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=ot(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)(()=>_?ct(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)(st,{result:C}),(0,d.jsx)(rt,{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 gt(e){return Object.values(e).flat().map(e=>({label:e.model,value:e.id,pricing:e.pricing??null,group:e.providerLabel??e.provider}))}function _t({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=!f&&!i.remote&&i.hasProviders&&!i.selectedModel,m=f?[]:i.remote?i.remoteModels:gt(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()||p,onSubmit:c,attachments:!o&&!i.remote,models:m,selectedModel:f?``:i.selectedModel,actions:e.composerActions,commands:e.composerCommands,onModelChange:i.setSelectedModel,modelPlaceholder:t.selectModelPlaceholder,minHeight:44,maxHeight:220})}function vt(){let{startOrchestrator:e}=$(),t=Q(),[n,r]=(0,u.useState)(``),{hasProviders:i,modelsByProvider:a,selectedModel:o,setSelectedModel:s}=Ke(),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:gt(a),selectedModel:o,onModelChange:s,modelPlaceholder:t.selectModelPlaceholder,minHeight:44,maxHeight:220})}function yt(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 xt({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 St({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),g=(0,u.useMemo)(()=>n?se(e):[],[e,n,m]),_=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}oe(e,n.subagentId,n.entityId),t===ce(n.subagentId,n.entityId)&&o(),h(e=>e+1)}},v=(0,u.useMemo)(()=>{let e=f.trim().toLowerCase();return e?g.filter(t=>{let n=x(t.subagentId)?.label??t.subagentId;return t.title.toLowerCase().includes(e)||n.toLowerCase().includes(e)}):g},[g,f]);return(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:v.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}):v.map(e=>{let n=x(e.subagentId),r=t===ce(e.subagentId,e.entityId);return(0,d.jsx)(l.DropdownItem,{icon:r?`check`:n?.icon??`bot`,className:r?`bg-accent font-medium`:void 0,actions:[{icon:`archive`,label:s.archiveChat,onClick:()=>void _(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.jsxs)(`span`,{className:`min-w-0 truncate`,children:[(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:n?.label??e.subagentId}),` · `,e.title||e.entityId]}),(0,d.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,title:new Date(e.savedAt).toLocaleString(c),children:yt(e.savedAt,c)})]})},`${e.subagentId}:${e.entityId}`)})})}function Ct({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),M=Be({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)),L=P.slice(0,I),R=P.slice(I),z=!!(i&&!i.agent.running&&i.agent.error),ee=new Set(i?.agent.activity.map(e=>e.id)??[]),B=i?{canAnswer:e=>ee.has(e),onAnswer:(e,t,n)=>i.agent.answerQuestions(e,t,n).then(e=>{e&&i.onApplied(e)})}:void 0,V=B?Ee(P,B.canAnswer):null,H=i?.id===`agentico-orchestrator`&&i.scopedSubagentId?x(i.scopedSubagentId):void 0,te=H?.manualEntry?H:null,U=(0,u.useRef)(!0);(0,u.useEffect)(()=>{let e=k.current;if(!e)return;let t=()=>{U.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&&(U.current=!0,e.scrollTop=e.scrollHeight)},[i?.id]);let W=P.at(-1)?.detail?.length??0;(0,u.useEffect)(()=>{let e=k.current;e&&U.current&&(e.scrollTop=e.scrollHeight)},[F,z,W]);let G=(0,u.useRef)(null);(0,u.useEffect)(()=>{let e=k.current,t=G.current;if(!e||!t||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{U.current&&(e.scrollTop=e.scrollHeight)});return n.observe(t),()=>n.disconnect()},[i?.id,a]);let K=o?(0,d.jsx)(mt,{userGoal:o},s):null,q=m?x(m.subagentId):void 0,J=m&&q?(0,d.jsx)(pt,{manifest:q,params:m.snapshot.params,taskId:ce(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)(ht,{manifest:Y,extraDestinations:v.extraDestinations},y):null,X=C?x(C.subagentId):void 0,re=C&&X?(0,d.jsx)(pt,{manifest:X,params:C.params,extraDestinations:C.extraDestinations},w):null,Z=T?x(T.subagentId):void 0,ie=T&&Z?(0,d.jsx)(pt,{manifest:Z,params:T.params,taskId:T.taskId,openingMessage:T.openingMessage},E):null;return a?(0,d.jsxs)(d.Fragment,{children:[K,J,ne,re,ie,(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)(Ve,{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)(St,{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)(He,{})]}),(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:G,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)(Ae,{activity:L,questions:B,docked:V,pinUserMessages:!V}),i.panelExtra&&(0,d.jsx)(`div`,{className:`mt-3`,children:i.panelExtra}),R.length>0&&(0,d.jsx)(Ae,{activity:R,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).then(e=>{e&&i.onApplied(e)})}}),!i.agent.remote&&(0,d.jsx)(l.ActionButton,{label:O.continueWithoutAi,variant:`secondary`,className:`shrink-0`,onClick:()=>{if(te){b(te.id,S);return}let e=i.agent.runFallback();e&&i.onApplied(e)}})]})]}):p.length>0?(0,d.jsx)(xt,{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)(De,{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)(_t,{task:i},i.id):(0,d.jsx)(vt,{})]})]})]}):(0,d.jsxs)(d.Fragment,{children:[K,J,ne,re,ie]})}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 Tt(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=Ne,exports.AGENTICO_MIN_WIDTH=Me,exports.AGENTICO_WIDTH=je,exports.AGENTICO_WIDTH_STORAGE_KEY=Pe,exports.Agentico=Ct,exports.AgenticoProvider=he,exports.AgenticoToggle=He,exports.DEFAULT_REASONING_PART_ID=p,exports.DEFAULT_TEXT_PART_ID=f,exports.JSON_EXPORT_DESTINATION_ID=U,exports.MICRO_PROMPT_REGISTRY=ee,exports.ORCHESTRATOR_TASK_ID=pe,exports.SUMMARY_MICRO_PROMPT=z,exports.agenticoDe=le,exports.agenticoEn=ue,exports.agenticoIt=de,exports.agenticoPromptsEn=O,exports.agenticoPromptsIt=k,exports.agenticoTranslations=fe,exports.applyMicroPrompts=B,exports.configureAgenticoPrompts=j,exports.configureEntityChatStore=Y,exports.createCrossAgentTools=w,exports.defineSubagent=_,exports.entityChatTaskId=ce,exports.extractErrorMessage=V,exports.extractJsonBlock=H,exports.findSubagentManifest=x,exports.formatQuestionAnswers=g,exports.getAgenticoPrompts=M,exports.getDestinationRegistry=q,exports.getEntityChat=ie,exports.getSubagentControls=dt,exports.getSubagentRegistry=b,exports.getSubagentReport=ot,exports.jsonExportDestination=W,exports.listEntityChats=se,exports.messagePartsText=h,exports.registerCrossAgentTools=C,exports.registerDestinations=K,exports.registerSubagentControls=ut,exports.registerSubagentReports=at,exports.registerSubagents=y,exports.removeEntityChat=oe,exports.renderRegistryCli=R,exports.renderSubagentCli=L,exports.resetAgenticoPrompts=N,exports.saveEntityChat=ae,exports.toJsonSchema=T,exports.toMcpTool=E,exports.upsertMessagePart=m,exports.useAgent=Xe,exports.useAgentico=$,exports.useAgenticoI18n=Q,exports.useAgenticoPageContext=wt,exports.useSubagentComponentContext=Tt;
21
21
  //# sourceMappingURL=index.js.map