@artooi/ag-ui-web-component 0.31.0 → 0.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -1
- package/dist/ag-ui-web-component.bundle.js +10 -1
- package/dist/ag-ui-web-component.bundle.js.map +2 -2
- package/dist/index.js +10 -1
- package/dist/index.js.map +2 -2
- package/dist/ui/styles.d.ts +1 -1
- package/dist/ui/styles.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ui/styles.ts +9 -0
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.31.1] — 2026-08-31
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **A collapsed widget did not give its space back inside a flex or grid parent.**
|
|
15
|
+
The panel hid and the box it occupied stayed: a header bar over several hundred
|
|
16
|
+
pixels of nothing.
|
|
17
|
+
|
|
18
|
+
Every collapse path works by letting the host size to its content -- the
|
|
19
|
+
in-flow placements set `height: auto` and keep the header bar, the floating one
|
|
20
|
+
leaves only the launcher. A parent whose `align-items` is the default stretch
|
|
21
|
+
overrides all of it, and putting the element in a flex row beside the page
|
|
22
|
+
content is the obvious way to embed it. `align-self: start` on the collapsed
|
|
23
|
+
host is the whole fix.
|
|
24
|
+
|
|
25
|
+
Reported from a running page rather than found here, and it was reaching every
|
|
26
|
+
known consumer: four frontends with byte-identical `display: flex` containers.
|
|
27
|
+
|
|
28
|
+
Scope worth stating, since it reads as narrow. `page` sizes itself to the
|
|
29
|
+
viewport, so a parent never stretches it. `floating` -- the default -- is
|
|
30
|
+
documented as never reflowing the page and hides its panel with `visibility` so
|
|
31
|
+
the transition has something to animate; a visibility-hidden box still occupies
|
|
32
|
+
its space, so a floating widget cannot shrink an in-flow parent and is not
|
|
33
|
+
meant to be in one. A host docking a full-height panel wants a placement rather
|
|
34
|
+
than the floating default.
|
|
35
|
+
|
|
36
|
+
|
|
10
37
|
## [0.31.0] — 2026-08-30
|
|
11
38
|
|
|
12
39
|
### Changed
|
|
@@ -2588,7 +2615,8 @@ hosts that both arrange the page the way it expects.
|
|
|
2588
2615
|
### Notes
|
|
2589
2616
|
- First release — exercising the automated npm OIDC publish pipeline end-to-end.
|
|
2590
2617
|
|
|
2591
|
-
[Unreleased]: https://github.com/Artui/ag-ui-web-component/compare/v0.31.
|
|
2618
|
+
[Unreleased]: https://github.com/Artui/ag-ui-web-component/compare/v0.31.1...HEAD
|
|
2619
|
+
[0.31.1]: https://github.com/Artui/ag-ui-web-component/compare/v0.31.0...v0.31.1
|
|
2592
2620
|
[0.31.0]: https://github.com/Artui/ag-ui-web-component/compare/v0.30.0...v0.31.0
|
|
2593
2621
|
[0.30.0]: https://github.com/Artui/ag-ui-web-component/compare/v0.29.0...v0.30.0
|
|
2594
2622
|
[0.29.0]: https://github.com/Artui/ag-ui-web-component/compare/v0.28.0...v0.29.0
|
|
@@ -625,6 +625,15 @@ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error
|
|
|
625
625
|
floating circle that would escape the host's layout. */
|
|
626
626
|
:host([collapsed]) {
|
|
627
627
|
pointer-events: none;
|
|
628
|
+
/* A collapsed host has to be allowed to shrink, and in the layout hosts
|
|
629
|
+
actually use it is not. Every collapse path here works by letting the host
|
|
630
|
+
size to its content -- the in-flow ones set height: auto, the floating one
|
|
631
|
+
leaves only the launcher -- and a flex or grid parent whose align-items is
|
|
632
|
+
the default stretch value overrides all of it. The panel then hides and the box
|
|
633
|
+
it occupied stays: a header bar over several hundred pixels of nothing.
|
|
634
|
+
Every known consumer hit this, because putting the element in a flex column
|
|
635
|
+
beside the page content is the obvious way to embed it. */
|
|
636
|
+
align-self: start;
|
|
628
637
|
}
|
|
629
638
|
|
|
630
639
|
:host([collapsed]) .chat {
|
|
@@ -2842,7 +2851,7 @@ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error
|
|
|
2842
2851
|
}
|
|
2843
2852
|
`;var $i=class{element;#t;#n;#e;#s=new Map;constructor(e=ee){this.element=document.createElement("div"),this.element.className="subagent",this.element.setAttribute("part","subagent"),this.#t=document.createElement("button"),this.#t.type="button",this.#t.className="subagent-row",this.#t.setAttribute("part","subagent-row"),this.#t.setAttribute("aria-expanded","false"),this.#t.disabled=!0;let n=document.createElement("span");n.className="subagent-icon",n.setAttribute("part","subagent-icon"),n.setAttribute("aria-hidden","true"),this.#n=document.createElement("span"),this.#n.className="subagent-status",this.#n.setAttribute("part","subagent-status"),this.#n.textContent=e.subAgentWorking,this.#t.append(n,this.#n),this.#e=document.createElement("div"),this.#e.className="subagent-steps",this.#e.setAttribute("part","subagent-steps"),this.#e.setAttribute("role","list"),this.#e.setAttribute("aria-label",e.subAgentSteps),this.#e.hidden=!0,this.#t.addEventListener("click",()=>{this.#o(this.#t.getAttribute("aria-expanded")!=="true")}),this.element.append(this.#t,this.#e)}report(e){this.element.setAttribute("data-phase",e.phase),e.agent!==null&&this.element.setAttribute("data-agent",e.agent),e.status!==null&&(this.#n.textContent=e.status),e.tool!==null&&this.#r(e.tool)}#r(e){let n=this.#s.get(e.toolCallId)??this.#i(e);if(e.ok===null){n.removeAttribute("data-ok");return}n.setAttribute("data-ok",String(e.ok))}#i(e){let n=document.createElement("div");n.className="subagent-step",n.setAttribute("part","subagent-step"),n.setAttribute("role","listitem"),n.setAttribute("data-tool-call-id",e.toolCallId);let r=document.createElement("span");r.className="subagent-step-icon",r.setAttribute("part","subagent-step-icon"),r.setAttribute("aria-hidden","true");let o=document.createElement("span");return o.className="subagent-step-name",o.setAttribute("part","subagent-step-name"),o.textContent=e.name,n.append(r,o),this.#e.appendChild(n),this.#s.set(e.toolCallId,n),this.#t.disabled=!1,n}#o(e){this.#e.hidden=!e,this.#t.setAttribute("aria-expanded",String(e))}};var Uy=Object.values(Ql);function ip(t){return typeof t!="object"||t===null||Array.isArray(t)?null:t}function kr(t){return typeof t=="string"&&t!==""?t:null}function Hy(t){let e=ip(t);if(e===null)return null;let n=kr(e.toolCallId),r=kr(e.name),o=e.ok;return n===null||r===null||o!==null&&typeof o!="boolean"?null:{toolCallId:n,name:r,ok:o}}function sp(t){let e=ip(t);if(e===null)return null;let n=kr(e.delegationId),r=e.phase;return n===null||typeof r!="string"||!Uy.includes(r)?null:{delegationId:n,phase:r,agent:kr(e.agent),status:kr(e.status),tool:Hy(e.tool)}}var Fy=4,zy=120;function ap(t){if(typeof t!="object"||t===null)return null;let e=t.prompts;if(!Array.isArray(e))return null;let n=e.filter(r=>typeof r=="string").map(r=>r.trim()).filter(r=>r!==""&&r.length<=120).slice(0,4);return n.length===0?null:n}function hl(t,e,n){let r=ap(t);if(r===null)return null;let o=document.createElement("div");o.className="suggestions",o.setAttribute("part","suggestions"),o.setAttribute("role","group"),o.setAttribute("aria-label",e.suggestions);for(let i of r){let s=document.createElement("button");s.type="button",s.className="suggestion-chip",s.setAttribute("part","suggestion-chip"),s.textContent=i,s.addEventListener("click",()=>n(i)),o.appendChild(s)}return o}var Bi=class{element;#t;#n;#e;#s;#r=!1;constructor(e=ee){this.#s=e,this.element=document.createElement("div"),this.element.className="thoughts",this.element.setAttribute("part","thoughts"),this.element.setAttribute("data-streaming",""),this.#e=document.createElement("button"),this.#e.type="button",this.#e.className="thoughts-toggle",this.#e.setAttribute("part","thoughts-toggle"),this.#e.setAttribute("aria-expanded","true"),this.#t=document.createElement("span"),this.#t.className="thoughts-label",this.#t.setAttribute("part","thoughts-label"),this.#t.textContent=e.thinking,this.#e.append(this.#t),this.#n=document.createElement("pre"),this.#n.className="thoughts-body",this.#n.setAttribute("part","thoughts-body"),this.#e.addEventListener("click",()=>{this.#i(!this.#r)}),this.element.append(this.#e,this.#n)}stream(e){this.#n.textContent=e}collapse(){this.#r||(this.element.removeAttribute("data-streaming"),this.#t.textContent=this.#s.thoughts,this.#i(!0))}#i(e){this.#r=e,this.#n.hidden=e,this.#e.setAttribute("aria-expanded",String(!e))}};var Vi=class{element;#t;#n;#e;#s;#r;#i=null;#o;#u=[];#c="";#d=null;constructor(e,n=ee){this.#t=e,this.#o=n,this.element=document.createElement("div"),this.element.className="drawer",this.element.setAttribute("part","drawer"),this.element.hidden=!0;let r=document.createElement("div");r.className="drawer-backdrop",r.setAttribute("part","drawer-backdrop"),r.addEventListener("click",()=>this.close()),this.#n=document.createElement("div"),this.#n.className="drawer-panel",this.#n.setAttribute("part","drawer-panel"),this.#n.setAttribute("role","dialog"),this.#n.setAttribute("aria-modal","true"),this.#n.setAttribute("aria-label",n.chatHistory),this.#n.addEventListener("keydown",i=>this.#v(i));let o=document.createElement("div");o.className="drawer-header",o.setAttribute("part","drawer-header"),this.#e=document.createElement("span"),this.#e.className="drawer-title",this.#e.setAttribute("part","drawer-title"),this.#e.textContent=n.chats,this.#s=document.createElement("button"),this.#s.type="button",this.#s.className="drawer-new",this.#s.setAttribute("part","drawer-new"),this.#s.textContent=n.newChat,this.#s.addEventListener("click",()=>{this.close(),this.#t.onNew()}),o.append(this.#e,this.#s),this.#r=document.createElement("div"),this.#r.className="drawer-list",this.#r.setAttribute("part","drawer-list"),this.#n.append(o,this.#r),this.element.append(r,this.#n)}setRelativeTimeFormatter(e){this.#i=e}#a(e){return this.#i!==null?this.#i(e):vr(e,void 0,this.#o)}setStrings(e){this.#o=e,this.#n.setAttribute("aria-label",e.chatHistory),this.#e.textContent=e.chats,this.#s.textContent=e.newChat,this.#m()}isOpen(){return!this.element.hidden}open(){this.isOpen()||(this.#d=this.#p(),this.element.hidden=!1,this.#s.focus())}close(){this.isOpen()&&(this.element.hidden=!0,this.#d?.focus(),this.#d=null)}toggle(){this.isOpen()?this.close():this.open()}#p(){return this.element.getRootNode().activeElement}#v(e){if(e.key==="Escape"){e.preventDefault(),this.close();return}if(e.key!=="Tab")return;let n=Array.from(this.#n.querySelectorAll("button, input, [tabindex]")).filter(s=>!s.hidden),r=n[0],o=n[n.length-1],i=this.#p();e.shiftKey&&i===r?(e.preventDefault(),o?.focus()):!e.shiftKey&&i===o&&(e.preventDefault(),r?.focus())}setThreads(e,n){this.#u=e,this.#c=n,this.#m()}#m(){if(this.#r.replaceChildren(),this.#u.length===0){let e=document.createElement("div");e.className="drawer-empty",e.setAttribute("part","drawer-empty"),e.textContent=this.#o.noConversations,this.#r.appendChild(e);return}for(let e of this.#u)this.#r.appendChild(this.#y(e))}#y(e){let n=document.createElement("div");n.className="drawer-row",n.setAttribute("part","drawer-row"),e.threadId===this.#c&&n.classList.add("drawer-row--active");let r=document.createElement("button");r.type="button",r.className="drawer-row-select",r.setAttribute("part","drawer-row-select");let o=document.createElement("span");o.className="drawer-row-title",o.setAttribute("part","drawer-row-title"),o.textContent=e.title;let i=document.createElement("span");i.className="drawer-row-time",i.setAttribute("part","drawer-row-time"),i.textContent=this.#a(e.updatedAt);let s=document.createElement("span");s.className="drawer-row-preview",s.setAttribute("part","drawer-row-preview"),s.textContent=e.preview,r.append(o,i,s),r.addEventListener("click",()=>{this.close(),this.#t.onSelect(e.threadId)});let a=document.createElement("button");a.type="button",a.className="drawer-row-rename",a.setAttribute("part","drawer-row-rename"),a.title=this.#o.rename,a.setAttribute("aria-label",this.#o.renameConversation),a.textContent="\u270E",a.addEventListener("click",()=>this.#U(n,e));let l=document.createElement("button");l.type="button",l.className="drawer-row-delete",l.setAttribute("part","drawer-row-delete"),l.title=this.#o.delete,l.setAttribute("aria-label",this.#o.deleteConversation),l.textContent="\u{1F5D1}",l.addEventListener("click",()=>this.#_(n,e));let c=document.createElement("div");return c.className="drawer-row-actions",c.setAttribute("part","drawer-row-actions"),c.append(a,l),n.append(r,c),n}#U(e,n){let r=document.createElement("input");r.type="text",r.className="drawer-rename-input",r.setAttribute("part","drawer-rename-input"),r.value=n.title;let o=!1,i=()=>{if(o)return;o=!0;let a=r.value.trim();a===""||a===n.title?this.#m():this.#t.onRename(n.threadId,a)},s=()=>{o||(o=!0,this.#m())};r.addEventListener("keydown",a=>{a.key==="Enter"?(a.preventDefault(),i()):a.key==="Escape"&&(a.preventDefault(),a.stopPropagation(),s())}),r.addEventListener("blur",()=>i()),e.replaceChildren(r),r.focus(),r.select()}#_(e,n){let r=document.createElement("div");r.className="drawer-confirm",r.setAttribute("part","drawer-confirm");let o=document.createElement("span");o.className="drawer-confirm-label",o.setAttribute("part","drawer-confirm-label"),o.textContent=this.#o.deletePrompt;let i=document.createElement("button");i.type="button",i.className="drawer-confirm-yes",i.setAttribute("part","drawer-confirm-yes"),i.textContent=this.#o.delete,i.addEventListener("click",()=>this.#t.onDelete(n.threadId));let s=document.createElement("button");s.type="button",s.className="drawer-confirm-no",s.setAttribute("part","drawer-confirm-no"),s.textContent=this.#o.cancel,s.addEventListener("click",()=>this.#m()),r.append(o,i,s),e.replaceChildren(r)}};function fl(t){return{[te.PENDING]:t.toolRunning,[te.DEFERRED]:t.toolDeferred,[te.DONE]:t.toolDone,[te.ERROR]:t.toolError,[te.DECLINED]:t.toolDeclined}}function Gy(t){return{[te.DONE]:t.resultLabel,[te.ERROR]:t.errorLabel,[te.DECLINED]:t.declinedLabel}}function $y(t){try{return JSON.stringify(JSON.parse(t),null,2)}catch{return t}}var Cr=class{element;approvalSlot;subagentSlot;#t;#n;#e;#s;#r;#i;#o;args;#u;#c;#d=!1;constructor(e,n,r,o=ee,i={}){this.#o=o,this.args=n,this.#u=e,this.#c=i.formatPayload??null,this.element=document.createElement("div"),this.element.className="tool-call",this.element.setAttribute("part","tool-card"),this.element.setAttribute("data-tool-name",e),this.element.setAttribute("data-status",te.PENDING),this.element.setAttribute("data-expanded","false");let s=document.createElement("div");s.className="tool-call-head",s.setAttribute("part","tool-card-head");let a=document.createElement("span");a.className="tool-call-icon",a.setAttribute("part","tool-card-icon"),a.setAttribute("aria-hidden","true");let l=document.createElement("span");l.className="tool-call-name",l.setAttribute("part","tool-card-name"),l.textContent=r??e,this.#t=document.createElement("span"),this.#t.className="tool-call-status",this.#t.setAttribute("part","tool-card-status"),this.#t.textContent=fl(o)[te.PENDING],this.#n=document.createElement("span"),this.#n.className="tool-call-decision",this.#n.setAttribute("part","tool-card-decision"),this.#n.hidden=!0,s.append(a,l,this.#t,this.#n);let c=this.#p("args",o.argumentsLabel);this.#a(c.body,{kind:"arguments",toolName:e,args:n},JSON.stringify(n,null,2)),c.root.hidden=Object.keys(n).length===0;let u=this.#p("result",o.resultLabel);this.#s=u.root,this.#r=u.label,this.#i=u.body,u.root.hidden=!0,this.#e=document.createElement("button"),this.#e.type="button",this.#e.className="tool-call-toggle",this.#e.setAttribute("part","tool-card-toggle"),this.#e.setAttribute("aria-expanded","false"),this.#e.textContent=o.details,this.#e.addEventListener("click",()=>this.#m(!this.#v()));let m=document.createElement("div");m.className="tool-call-body",m.setAttribute("part","tool-card-body"),m.append(c.root,u.root),this.approvalSlot=document.createElement("div"),this.approvalSlot.className="tool-call-approval",this.approvalSlot.setAttribute("part","tool-card-approval"),this.subagentSlot=document.createElement("div"),this.subagentSlot.className="tool-call-subagent",this.subagentSlot.setAttribute("part","tool-card-subagent"),this.element.append(s,this.subagentSlot,this.#e,m,this.approvalSlot)}mark(e){this.#d||(this.element.setAttribute("data-status",e),this.#t.textContent=fl(this.#o)[e])}recordDecision(e){this.element.setAttribute("data-decision",e),this.#n.textContent=e==="approved"?this.#o.decisionApproved:this.#o.decisionDeclined,this.#n.hidden=!1}get settled(){return this.#d}settle(e,n){this.#d||(this.#d=!0,this.element.setAttribute("data-status",e),this.#t.textContent=fl(this.#o)[e],this.#r.textContent=Gy(this.#o)[e],this.#a(this.#i,{kind:"result",toolName:this.#u,status:e,text:n},$y(n)),this.#s.hidden=!1)}#a(e,n,r){let o=this.#c===null?null:this.#c(n);if(o===null){e.textContent=r;return}if(e.setAttribute("data-formatted","true"),typeof o=="string"){e.textContent=o;return}e.replaceChildren(o)}#p(e,n){let r=document.createElement("div");r.className=`tool-call-section tool-call-section--${e}`,r.setAttribute("part",`tool-card-section tool-card-${e}-section`);let o=document.createElement("span");o.className="tool-call-section-label",o.setAttribute("part",`tool-card-section-label tool-card-${e}-label`),o.textContent=n;let i=document.createElement("pre");return i.className=`tool-call-${e}`,i.setAttribute("part",`tool-card-${e}`),r.append(o,i),{root:r,label:o,body:i}}#v(){return this.element.getAttribute("data-expanded")==="true"}#m(e){this.element.setAttribute("data-expanded",String(e)),this.#e.setAttribute("aria-expanded",String(e))}};var lp=12e4,ji=class{element;#t;#n;#e;#s="idle";#r=null;#i=null;#o=[];#u=null;#c=!1;#d=!1;constructor(e){this.#t=e.transcribe,this.#n=e.onText,this.#e=e.strings??ee,this.element=document.createElement("button"),this.element.type="button",this.element.className="voice-btn",this.element.setAttribute("part","voice-button");let n=document.createElement("slot");n.name="icon-voice",n.innerHTML=nc,this.element.append(n),this.#_("idle"),this.element.addEventListener("click",()=>{this.toggle()})}async toggle(){if(this.#s==="recording"){this.#p();return}this.#s!=="transcribing"&&await this.#a()}async#a(){let e;try{e=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{this.#U(this.#e.transcriptionFailed);return}this.#i=e,this.#o=[],this.#c=!1;let n=new MediaRecorder(e);n.addEventListener("dataavailable",r=>{this.#o.push(r.data)}),n.addEventListener("stop",()=>{this.#m(n.mimeType)}),this.#r=n,n.start(),this.#u=setTimeout(()=>{this.#c=!0,this.#p()},lp),this.#_("recording")}#p(){this.#v(),this.#r?.stop()}#v(){this.#u!==null&&(clearTimeout(this.#u),this.#u=null)}dispose(){this.#d=!0,this.#v(),this.#r!==null&&this.#r.state!=="inactive"&&this.#r.stop(),this.#r=null,this.#y()}async#m(e){if(this.#d)return;this.#y(),this.#_("transcribing");let n=new Blob(this.#o,{type:e||"audio/webm"});try{let r=await this.#t(n);this.#_("idle"),this.#c&&(this.element.title=this.#e.recordingLimit.replace("{n}",String(lp/6e4))),r!==""&&this.#n(r)}catch(r){this.#U(r instanceof Error?r.message:this.#e.transcriptionFailed)}finally{this.#r=null}}#y(){for(let e of this.#i?.getTracks()??[])e.stop();this.#i=null}#U(e){this.#y(),this.#r=null,this.#_("idle"),this.element.title=e}#_(e){this.#s=e,this.element.dataset.state=e;let n=this.#M(e);this.element.title=n,this.element.setAttribute("aria-label",n),this.element.setAttribute("aria-pressed",String(e==="recording")),this.element.disabled=e==="transcribing"}#M(e){return e==="recording"?this.#e.stopRecording:e==="transcribing"?this.#e.transcribing:this.#e.recordVoice}};var qi=class extends Error{constructor(e){super(e),this.name="ConnectionLostError"}},Bn=class{#t;#n;#e;#s;#r;#i;#o;#u=new Set;#c;#d;#a=!1;constructor(e){this.#t=e.agent,this.#n=e.handlers,this.#e=e.getTools??(()=>[]),this.#s=e.getContext??(()=>[]),this.#r=e.executeTool??null,this.#i=e.resolveInterrupts??null,this.#o=e.onPersist??(()=>{}),this.#c=e.connectionLostMessage??"Connection lost";let n=e.maxToolRounds??bn;this.#d=n>=1?Math.floor(n):bn;let r=e.onStateChanged;r!==void 0&&this.#t.subscribe({onStateChanged:({state:o})=>{r(o)}})}get state(){return this.#t.state}setState(e){this.#t.setState({...e})}get running(){return this.#t.isRunning}get messages(){return this.#t.messages}async send(e,n=[]){let r={id:Te(),role:"user",content:e};n.length>0&&(r.attachments=n),this.#t.addMessage(r),this.#o(this.#t.messages),await this.#p()}truncateToLastUser(){let e=[...this.#t.messages],n=-1;for(let[o,i]of e.entries())i.role==="user"&&(n=o);if(n===-1)return null;let r=e.slice(0,n+1);return this.#t.setMessages(r),this.#o(this.#t.messages),r}async resume(){await this.#p()}addToolResult(e,n){this.#t.addMessage({id:Te(),role:"tool",content:n,toolCallId:e}),this.#o(this.#t.messages)}cancel(){this.#a=!0,this.#t.abortRun()}async#p(){this.#a=!1;try{await this.#m(),this.#a&&this.#v()}catch(e){this.#a||By(e)?this.#v():this.#n.onError(e instanceof Error?e.message:String(e))}finally{this.#n.onSettled()}}#v(){this.#o(this.#t.messages),this.#n.onCancelled()}async#m(){let e;for(let n=0;n<this.#d;n+=1){if(this.#a)return;let r=[],o={terminal:!1,errored:!1,interrupts:[]},i={tools:this.#e(),context:this.#s()};if(e!==void 0&&(i.resume=e),await this.#t.runAgent(i,this.#y(r,o)),e=void 0,this.#o(this.#t.messages),this.#a)return;if(!o.terminal)throw new qi(this.#c);if(o.errored)return;if(o.interrupts.length>0){if(this.#i===null)return;let a=await this.#i(o.interrupts);if(this.#a)return;e=Jd(o.interrupts,a);continue}if(this.#r===null||r.length===0)return;let s=!1;for(let a of r){let l=await this.#r(a);if(l!==null){if(l.halt===!0)return;this.#t.addMessage({id:Te(),role:"tool",content:l.content,toolCallId:a.id}),this.#o(this.#t.messages),s=!0}}if(!s)return}}#y(e,n){let r=this.#n,o=this.#u,i=()=>this.#a,s=new Set;return{onRunInitialized(){r.onRunStart()},onTextMessageStartEvent({event:a}){o.has(a.messageId)&&console.warn(`<ag-ui-chat>: the server reused message id "${a.messageId}", which was already closed. Its content will be appended to that earlier message rather than starting a new one, and the merged result is what gets persisted. Issue a fresh id per message.`)},onTextMessageContentEvent({textMessageBuffer:a}){r.onTextDelta(a)},onTextMessageEndEvent({event:a,textMessageBuffer:l}){o.add(a.messageId),r.onTextEnd(l)},onToolCallEndEvent({event:a,toolCallName:l,toolCallArgs:c}){let u={id:a.toolCallId,name:l,args:c};e.push(u),r.onToolCall(u)},onToolCallResultEvent({event:a}){r.onToolResult(a.toolCallId,a.content)},onActivitySnapshotEvent({event:a,messages:l}){if(l.some(u=>u.id===a.messageId&&u.role==="activity")){r.onActivityChanged(a.messageId,a.activityType,a.content);return}r.onActivity(a.activityType,a.content,a.messageId)},onActivityDeltaEvent({event:a}){s.add(a.messageId)},onCustomEvent({event:a}){r.onCustomEvent(a.name,a.value)},onMessagesSnapshotEvent({event:a}){r.onMessagesSnapshot(a.messages)},onMessagesChanged({messages:a}){if(s.size!==0){for(let l of s){let c=a.find(u=>u.id===l);c!==void 0&&c.role==="activity"&&r.onActivityChanged(l,c.activityType,c.content)}s.clear()}},onReasoningStartEvent(){r.onReasoningStart()},onReasoningMessageContentEvent({reasoningMessageBuffer:a}){r.onReasoningDelta(a)},onReasoningMessageEndEvent({reasoningMessageBuffer:a}){r.onReasoningDelta(a)},onReasoningEndEvent(){r.onReasoningEnd()},onRunFinishedEvent(a){n.terminal=!0,a.outcome==="interrupt"&&(n.interrupts=a.interrupts)},onRunErrorEvent({event:a}){n.terminal=!0,n.errored=!0,!i()&&r.onError(a.message)},onRunFinalized(){n.terminal=!0,r.onRunEnd()}}}};function By(t){return t instanceof Error?t.name==="AbortError"||t instanceof TypeError&&/abort/i.test(t.message):!1}function ml(t){let e=t.attachments;return Array.isArray(e)?e.filter(Vy):[]}function Vy(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.id=="string"&&typeof e.name=="string"&&typeof e.mime=="string"&&typeof e.size=="number"&&(e.url===void 0||typeof e.url=="string")}var cp="ag-ui-chat",Vn="thread",gl="threads",Ir="messages:",Xi="checkpoint:",Rr="minted:",jy=60,qy=100,Wy="New conversation",dp=!1;function et(t,e){try{sessionStorage.setItem(t,e)}catch{if(dp)return;dp=!0,console.warn("<ag-ui-chat>: the browser refused a sessionStorage write \u2014 the quota is full, or storage is disabled for this context. The conversation continues, but it will not survive a page reload. Deleting a long conversation from the history drawer frees the quota.")}}function Wi(t){return t===""?cp:`${cp}@${t}`}var je=class t{#t;constructor(e=""){this.#t=Wi(e),e!==""&&t.adopt("",e)}static adopt(e,n){let r=`${Wi(e)}:`,o=`${Wi(n)}:`;for(let[i,s]of up(r)){let a=sessionStorage.getItem(i),l=o+s;a!==null&&sessionStorage.getItem(l)===null&&et(l,a),sessionStorage.removeItem(i)}}static purge(e){for(let[n]of up(`${Wi(e)}:`))sessionStorage.removeItem(n)}threadId(){return sessionStorage.getItem(this.#r(Vn))??this.newThread()}newThread(){let e=Te();return et(this.#r(Vn),e),et(this.#r(Rr+e),"1"),e}isUnsent(e){return sessionStorage.getItem(this.#r(Rr+e))!==null&&sessionStorage.getItem(this.#r(Ir+e))===null}loadMessages(e){return Promise.resolve(this.#i(this.#r(Ir+e)))}saveMessages(e,n){et(this.#r(Ir+e),JSON.stringify(n)),sessionStorage.removeItem(this.#r(Rr+e)),this.#n(e,n)}loadCheckpoint(e){return this.#i(this.#r(Xi+e))}saveCheckpoint(e,n){let r=this.#r(Xi+e);if(n===null){sessionStorage.removeItem(r);return}et(r,JSON.stringify(n))}clear(e){sessionStorage.removeItem(this.#r(Ir+e)),sessionStorage.removeItem(this.#r(Xi+e)),sessionStorage.removeItem(this.#r(Rr+e)),this.#s(this.#e().filter(n=>n.threadId!==e)),sessionStorage.getItem(this.#r(Vn))===e&&sessionStorage.removeItem(this.#r(Vn))}listThreads(){let e=this.#e().sort((n,r)=>r.updatedAt-n.updatedAt).map(({threadId:n,title:r,updatedAt:o,preview:i})=>({threadId:n,title:r,updatedAt:o,preview:i}));return Promise.resolve(e)}setActiveThread(e){et(this.#r(Vn),e)}renameThread(e,n){let r=this.#e(),o=r.find(i=>i.threadId===e);o!==void 0&&(o.title=n,o.titleCustom=!0,this.#s(r))}#n(e,n){let r=this.#e(),o=r.find(a=>a.threadId===e),i=Yy(n),s=Date.now();o===void 0?r.push({threadId:e,title:pp(n),titleCustom:!1,preview:i,updatedAt:s}):(o.preview=i,o.updatedAt=s,o.titleCustom||(o.title=pp(n))),this.#s(r)}#e(){return this.#i(this.#r(gl))??[]}#s(e){let n=this.#r(gl);if(e.length===0){sessionStorage.removeItem(n);return}et(n,JSON.stringify(e))}#r(e){return`${this.#t}:${e}`}#i(e){let n=sessionStorage.getItem(e);if(n===null)return null;try{return JSON.parse(n)}catch{return null}}};function up(t){let e=[];for(let n=0;n<sessionStorage.length;n+=1){let r=sessionStorage.key(n);if(r===null||!r.startsWith(t))continue;let o=r.slice(t.length);Xy(o)&&e.push([r,o])}return e}function Xy(t){return t===Vn||t===gl||t.startsWith(Ir)||t.startsWith(Xi)||t.startsWith(Rr)}function pp(t){for(let e of t)if(e.role==="user"){let n=hp(e.content);if(n!=="")return fp(n,jy)}return Wy}function Yy(t){for(let e of[...t].reverse()){let n=hp(e.content);if(n!=="")return fp(n,qy)}return""}function hp(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():""}function fp(t,e){return t.length<=e?t:`${t.slice(0,e-1).trimEnd()}\u2026`}function qe(t,e){return e===void 0?t:{...t,credentials:e}}function Yi(t){if(t.newThread!==void 0)return t.newThread();let e=Te();return t.setActiveThread(e),e}function Ki(t,e,n,r){if(e.length===0)return;let o=new URL(String(t),location.href).origin;o===location.origin||n.includes(o)||r.has(o)||(r.add(o),console.warn(`<ag-ui-chat>: sending host credentials (${e.join(", ")}) to ${o}, which is not this page's origin (${location.origin}). Those headers are the page's own authentication, and whichever server answers the browser's preflight receives them \u2014 so a URL attribute built from a query parameter or from tenant-authored configuration is a channel for the token to leave on. If this destination is deliberate, name it in \`trustedOrigins\` to confirm it and silence this notice. Reported once per origin.`))}function vl(t){let e=t.headers??{},n=new Set;return new eu({url:t.endpoint,headers:e,initialState:{...t.initialState??{}},fetch:(r,o)=>{let i=t.getHeaders?.(),s=[...new Set([...Object.keys(e),...Object.keys(i??{})])].sort();if(Ki(r,s,t.trustedOrigins??[],n),i===void 0)return fetch(r,qe(o,t.credentials));let a=new Headers(o?.headers);for(let[l,c]of Object.entries(i))a.set(l,c);return fetch(r,qe({...o,headers:a},t.credentials))},...t.threadId!==void 0?{threadId:t.threadId}:{},...t.initialMessages!==void 0?{initialMessages:[...t.initialMessages]}:{}})}var Nr=class{#t;#n;#e;#s;#r;#i=new Set;#o=new Map;constructor(e,n=()=>({}),r=new je,o=()=>{},i=!0){this.#t=e.endsWith("/")?e:`${e}/`,this.#n=n,this.#e=r,this.#s=o,this.#r=i}threadId(){return this.#e.threadId()}setActiveThread(e){this.#e.setActiveThread(e)}newThread(){return Yi(this.#e)}isUnsent(e){return this.#e.isUnsent?.(e)===!0}saveMessages(e,n){this.#e.saveMessages(e,this.#r?n:[])}loadCheckpoint(e){return this.#e.loadCheckpoint(e)}saveCheckpoint(e,n){this.#e.saveCheckpoint(e,n)}renameThread(e,n){this.#e.renameThread(e,n),this.#o.set(e,n),this.#p(e,"PATCH",{title:n})}clear(e){this.#e.clear(e),this.#i.add(e),this.#p(e,"DELETE")}async listThreads(){let e=await this.#u();return e===null?this.#e.listThreads():e.filter(n=>!this.#i.has(n.thread_id)).map(n=>this.#d(n))}async loadMessages(e){if(this.#e.isUnsent?.(e)===!0)return null;let n=await this.#a(`${this.#t}${encodeURIComponent(e)}/`);if(n===null||!n.ok)return this.#e.loadMessages(e);let r=await this.#c(n);return r===null?this.#e.loadMessages(e):r.messages??null}async#u(){let e=await this.#a(this.#t);if(e===null||!e.ok)return null;let n=await this.#c(e);return n===null?null:n.threads??[]}async#c(e){try{return await e.json()}catch{return null}}#d(e){return{threadId:e.thread_id,title:this.#o.get(e.thread_id)??e.title,updatedAt:e.updated_at===null?Number.NaN:Date.parse(e.updated_at),preview:e.preview}}async#a(e){try{return await fetch(e,qe({headers:this.#n()},this.#s()))}catch{return null}}async#p(e,n,r){let o=this.#n();try{await fetch(`${this.#t}${encodeURIComponent(e)}/`,qe({method:n,headers:r===void 0?o:{...o,"content-type":"application/json"},body:r===void 0?null:JSON.stringify(r)},this.#s()))}catch{}}};var Or=class{#t;#n;#e;constructor(e,n=()=>({}),r=()=>{}){this.#t=e.endsWith("/")?e:`${e}/`,this.#n=n,this.#e=r}async list(){try{let e=await fetch(this.#t,qe({method:"GET",headers:{Accept:"application/json",...this.#n()}},this.#e()));return e.ok?(await e.json()).runs??[]:[]}catch{return[]}}async continuable(){return(await this.list()).filter(e=>e.continuable)}resumeUrl(e){return this.#s("resume",e)}forkUrl(e){return this.#s("fork",e)}#s(e,n){return`${this.#t.slice(0,-5)}${e}/${encodeURIComponent(n)}/`}};async function bl(t,e){let n=new FormData;n.append("audio",t,"recording.webm");let r=await fetch(e.url,qe({method:"POST",headers:{...e.headers??{}},body:n},e.credentials));if(!r.ok)throw new Error(await Ky(r));let o=await r.json();if(typeof o=="object"&&o!==null&&typeof o.text=="string")return o.text;throw new Error("transcription returned an unreadable response")}async function Ky(t){try{let e=await t.json();if(typeof e.error=="string")return e.error}catch{}return`transcription failed (${t.status})`}function yl(t,e){return new Promise((n,r)=>{let o=new FormData;o.append("file",t);let i=new XMLHttpRequest;i.open("POST",e.url),i.withCredentials=e.credentials==="include";for(let[l,c]of Object.entries(e.headers??{}))i.setRequestHeader(l,c);let s=e.onProgress;s!==void 0&&i.upload.addEventListener("progress",l=>{l.lengthComputable&&s(l.total===0?0:l.loaded/l.total)}),i.addEventListener("load",()=>{if(i.status>=200&&i.status<300)try{n(Zy(JSON.parse(i.responseText)))}catch{r(new Error("upload returned an unreadable response"))}else r(new Error(Qy(i)))}),i.addEventListener("error",()=>r(new Error("upload failed"))),i.addEventListener("abort",()=>r(new Error("upload cancelled")));let a=e.signal;a!==void 0&&a.addEventListener("abort",()=>i.abort()),i.send(o)})}function Zy(t){if(typeof t!="object"||t===null)throw new Error("not an object");let e=t,n=e.id,r=e.name,o=e.mime,i=e.size,s=e.url;if(typeof n!="string"||typeof r!="string"||typeof o!="string"||typeof i!="number")throw new Error("missing fields");return typeof s=="string"?{id:n,name:r,mime:o,size:i,url:s}:{id:n,name:r,mime:o,size:i}}function Qy(t){try{let e=JSON.parse(t.responseText);if(typeof e.error=="string")return e.error}catch{}return`upload failed (${t.status})`}var Jy=["data-attachments-url","data-attachment-accept","data-attachment-max-bytes","data-transcribe-url","data-threads-url","data-threads-cache","data-tools-url","data-skills-url","data-skills","data-prompt-chips","data-slash-commands","data-theme-toggle","data-strings","data-icon-url"],Tl=["omit","same-origin","include"];function xl(t){return Tl.includes(t)}var mp="ag-ui-chat:collapsed",gp="ag-ui-chat:size",vp="ag-ui-chat:theme",wl=6,El=new Set,Mr=class extends HTMLElement{agentFactory=vl;headers={};getHeaders=null;trustedOrigins=[];allowImages=!1;formatRelativeTime=null;autoConfirm=!1;askUser=!1;askUserRenderer=null;approvalRenderer=null;approveWithEdits=!1;confirmPredicate=null;getTools=()=>[...this.#Je().map(e=>({name:e.name,description:e.description,parameters:e.parameters})),...this.#r.tools()];getContext=()=>[...Ra(this.getPageMap,this.autoInjectPageMap)];routeMap=[];navigate=null;getPageMap=null;autoInjectPageMap=!0;conversationStore=new je;uploadHandler=null;transcribeHandler=null;navigationResult=()=>({navigated:!0,url:window.location.href});skillContext=()=>({});toolSummaries={};formatToolPayload=null;strings={};resolvePageTarget=e=>document.querySelector(e);#t={};#n=new Set;#e=ee;#s=new Set;#r=new pr;#i=new Map;#o=new Map;#u=new Map;#c=new Set;#d=new Map;#a=new Map;#p=new Set;#v=[];#m=new Set;#y=null;#U=new Set;#_;#M=document.createElement("div");#z=document.createElement("button");#b=document.createElement("button");#_e="";#Y=null;#ce=document.createElement("div");#g;#G=null;#de=!1;#x;#f;#l;#w;#Se;#H;#$;#E;#Ae=null;#R;#A;#k;#ue;#L;#C;#P;#pe=0;#B;#S=null;#he;#ke=null;#K=!1;#V=null;#Z={};#j=!1;#Ce=null;#N=null;#fe=null;#Ie=0;#me="";#q=null;#ge=null;#D=null;#W=null;#h="";#Q="";#ve=null;#Re="";#Ye="";#ne=null;#Ne=0;#Oe=[];#Ke=[];#Ze=[];#Qe=[];constructor(){super(),this.#_=this.attachShadow({mode:"open"}),this.#x=document.createElement("div"),this.#f=document.createElement("div"),this.#l=document.createElement("textarea"),this.#w=document.createElement("button"),this.#Se=document.createElement("span"),this.#R=document.createElement("div"),this.#A=document.createElement("button"),this.#k=document.createElement("input"),this.#ue=document.createElement("div"),this.#he=document.createElement("span"),this.#L=document.createElement("button"),this.#C=document.createElement("button"),this.#P=document.createElement("span"),this.#B=document.createElement("div"),this.registerActivityRenderer({type:Is,render:e=>{let n=rx(e);return n===null?null:pl("\u{1F5DC}",this.#e.historyCompacted.replace("{count}",String(n)),"compaction")}}),this.registerActivityRenderer({type:Ss,render:e=>hl(e,this.#e,n=>{this.sendMessage(n)})}),this.#H=new Gi(e=>this.#Kt(e)),this.#$=new Vi({onSelect:e=>{this.#nn(e)},onNew:()=>{this.newChat(),this.#se()},onRename:(e,n)=>{this.conversationStore.renameThread(e,n),this.#se()},onDelete:e=>{this.#rn(e)}}),this.#E=new br((e,n)=>{this.#kt(e,n)})}#Me(){let e=this.getAttribute("data-runs-url");return e===null||e===""?null:(this.#Ae===null&&(this.#Ae=new Or(e,()=>this.#oe(e),()=>this.#be())),this.#Ae)}async#kt(e,n){let r=this.#Me();if(r===null)return;let o=this.#l.value.trim();if(o==="")return;this.#l.value="",this.#J();let i=n==="resume"?r.resumeUrl(e):r.forkUrl(e),s=this.agentFactory({endpoint:i,headers:this.#re(),getHeaders:()=>this.#re(),trustedOrigins:this.trustedOrigins,...this.#ye(),threadId:this.#h,initialMessages:[]});await new Bn({agent:s,handlers:this.#wt(),getTools:()=>this.#et(),getContext:()=>this.#ht(),executeTool:l=>this.#yt(l),resolveInterrupts:l=>this.#xt(l),connectionLostMessage:this.#e.connectionLost}).send(o)}async#Ct(){let e=this.#Me();this.#E.setRelativeTimeFormatter(this.formatRelativeTime),this.#E.setRuns(e===null?[]:await e.continuable())}static get observedAttributes(){return["title-text","placement","credentials","user-key",...Jy]}attributeChangedCallback(e,n,r){if(e==="credentials"){r!==null&&!xl(r)&&console.error(`<ag-ui-chat>: credentials="${r}" is not a fetch credentials mode (${Tl.join(" / ")}) \u2014 it is being ignored, so requests use the browser default and cross-origin cookies will not be sent.`);return}if(e==="placement"){this.#Qt(),requestAnimationFrame(()=>this.#He());return}if(e==="title-text"){this.#Se.textContent=r??this.#e.title;return}if(e==="user-key"){this.#K&&(n??"")!==(r??"")&&this.#tn(n??"",r??"");return}n===r||!this.#K||console.warn(`<ag-ui-chat>: "${e}" was changed after the element connected, and is read only while connecting \u2014 this assignment has no effect. Set it before the element enters the DOM (in the markup, or on the element before appending it); frameworks that patch attributes after mount should bind it at creation. To apply a new value now, remove and re-insert the element.`)}registerTool(e){this.#r.register(e)}get sharedState(){return this.#V?.state??this.#Z}set sharedState(e){this.#Z={...e},this.#V?.setState(this.#Z)}registerPageState(e){for(let n of Si(e))this.#r.register(n)}registerStateHook(e){this.registerPageState(e)}#It(){return this.routeMap.length===0?[]:Oa(()=>this.routeMap,()=>this.navigate)}#Rt(){let e=this.getPageMap;return e===null?[]:[{name:ks,description:"Read the current page's structure (fields, buttons, route). Call after acting to observe the result within the same turn.",parameters:{type:"object",properties:{},required:[],[Pe]:"Read the page"},handler:()=>e()}]}#Nt(){let e=this.getAttribute("data-page-actions");if(e===null)return[];let n=new Set(e.split(",").map(r=>r.trim()).filter(r=>r!==""));return Ia(n,r=>this.resolvePageTarget(r))}#Je(){return[...this.#It(),...this.#Rt(),...this.#Nt(),...this.#Ot()]}#Ot(){return this.askUser?[{name:"ask_user",description:"Ask the user a question and wait for their answer. Provide `options` for a multiple-choice prompt; set `allow_custom` to also accept a free-text answer.",parameters:{type:"object",properties:{question:{type:"string",description:"The question to ask the user."},options:{type:"array",items:{type:"string"},description:"Preset choices offered as radio buttons."},allow_custom:{type:"boolean",description:"Allow a free-text answer in addition to any options."}},required:["question"]},handler:e=>this.#Mt(e)}]:[]}async#Mt(e){let r={question:typeof e.question=="string"?e.question:""},o=e.options;Array.isArray(o)&&(r.options=o.filter(a=>typeof a=="string")),e.allow_custom===!0&&(r.allowCustom=!0),this.#N=new AbortController;let i=this.#N.signal;this.#O();let s=this.askUserRenderer!==null?await this.askUserRenderer(r,{signal:i}):await qa(this.#I(),r,{signal:i,strings:this.#e});return this.#N=null,this.#T(),this.#g.follow(),s}#et(){let e=this.getTools();return this.#s=new Set(e.map(n=>n.name)),e}#Le(e){let n=this.#Je().find(r=>r.name===e);return n!==void 0?n:this.#r.has(e)?this.#r.get(e):null}get endpoint(){return this.getAttribute("endpoint")??""}set endpoint(e){this.setAttribute("endpoint",e)}get userKey(){return this.getAttribute("user-key")??""}set userKey(e){this.setAttribute("user-key",e)}get credentials(){let e=this.getAttribute("credentials");return e!==null&&xl(e)?e:null}set credentials(e){if(e===null){this.removeAttribute("credentials");return}if(!xl(e))throw new TypeError(`<ag-ui-chat>: credentials must be one of ${Tl.map(n=>`"${n}"`).join(", ")} (got ${JSON.stringify(e)}).`);this.setAttribute("credentials",e)}#re(){return{...this.headers,...this.getHeaders?.()}}#oe(e){let n=this.#re();return Ki(e,Object.keys(n),this.trustedOrigins,this.#n),n}#be(){return this.credentials??void 0}#ye(){let e=this.#be();return e===void 0?{}:{credentials:e}}#tt(e){return qe({headers:this.#oe(e)},this.#be())}get toolDisplay(){let e=this.getAttribute("data-tool-display");return e===yn.INLINE||e===yn.MINIMAL||e===yn.COMPACT?e:yn.FULL}set toolDisplay(e){this.setAttribute("data-tool-display",e)}connectedCallback(){if(this.#Q=this.#en(),this.#Fe(this.#ct()),requestAnimationFrame(()=>this.#He()),this.#e=Ma({...this.#Pt(),...this.strings}),this.getAttribute("data-theme-toggle")!==null){let e=this.#Ge(vp);e!==null&&this.setAttribute("theme",e)}if(this.#ln(),this.#$.setStrings(this.#e),this.#E.setStrings(this.#e),this.#Ge(mp)==="1"&&this.setAttribute("collapsed",""),this.#vt(),this.#Xt(),this.conversationStore instanceof je){let e=this.#ze();this.#ne=e===""?this.conversationStore:new je(e),this.conversationStore=this.#ne}this.#ot(),this.#Dt(),this.#Ht(),this.#h=this.conversationStore.threadId(),queueMicrotask(()=>this.#Lt()),this.#we(),this.#K=!0}#Lt(){this.#K&&(this.#it(),this.#st())}async reload(){this.#F(),this.#ie(),this.#X(!1),await Promise.all([this.#it(),this.#st(),this.#we()])}disconnectedCallback(){this.#K=!1,this.#ve!==null&&(El.delete(this.#ve),this.#ve=null),this.#F(),this.#Y?.detach(),this.#Y=null,this.#S?.dispose(),this.#ke?.dispose(),this.#g.dispose(),this.#G!==null&&(clearTimeout(this.#G),this.#G=null)}#nt(e){let n=this.getAttribute(e);return n!==null&&n!=="false"}#Pt(){let e=this.getAttribute("data-strings");if(e===null)return{};try{let n=JSON.parse(e);if(typeof n=="object"&&n!==null)return n}catch{}return{}}#Dt(){let e=this.getAttribute("data-attachments-url"),n=this.uploadHandler??this.#Ut(e);if(n===null)return;let r=this.getAttribute("data-attachment-accept")??"",o=new ki({upload:n,maxBytes:this.#jt(),accept:r,strings:this.#e,onChange:()=>this.#fn(o)});this.#S=o,this.#ue.appendChild(this.#S.element),this.#k.accept=r,this.#A.hidden=!1,this.#Wt()}#Ut(e){return e===null?null:(n,r,o)=>yl(n,{url:e,headers:this.#oe(e),...this.#ye(),onProgress:r,signal:o})}#Ht(){let e=this.getAttribute("data-transcribe-url"),n=this.transcribeHandler??this.#Ft(e);n!==null&&(this.#ke=new ji({transcribe:n,onText:r=>this.#zt(r),strings:this.#e}),this.#he.appendChild(this.#ke.element))}#Ft(e){return e===null?null:n=>bl(n,{url:e,headers:this.#oe(e),...this.#ye()})}#zt(e){let n=this.#l.value.trim();this.#l.value=n===""?e:`${n} ${e}`,this.#bt(),this.#l.focus()}quote(e){let n=$a(e);if(n==="")return;let r=this.#l.value.replace(/\s+$/,"");this.#l.value=r===""?n:`${r}
|
|
2844
2853
|
|
|
2845
|
-
${n}`,this.#J(),this.#l.focus();let o=this.#l.value.length;this.#l.setSelectionRange(o,o)}offerQuoteInPage(e=document.body){this.#Y?.detach();let n=Va({within:e,label:this.#e.quoteSelection,exclude:this,onQuote:r=>this.quote(r)});return this.#Y=n,()=>{n.detach(),this.#Y===n&&(this.#Y=null)}}#Gt(){return this.getAttribute("data-quote-selection")!=="false"}#rt(e){if(!this.#Gt())return;let n=e===void 0?void 0:{x:e.clientX,y:e.clientY},r=yr(this.#f,[this.#_],n);if(r===null){this.#Pe();return}this.#_e=r.text,this.#$t(r.rect)}#$t(e){this.#b.hidden=!1;let n=this.#ce.getBoundingClientRect(),r=e.top-n.top,o=r<wl+this.#b.offsetHeight;this.#b.dataset.below=String(o),this.#b.style.top=`${o?e.bottom-n.top+wl:r-wl}px`;let i=this.#b.offsetWidth/2,s=e.left+e.width/2-n.left;this.#b.style.left=`${Math.min(Math.max(s,i),n.width-i)}px`}#Pe(){this.#b.hidden=!0,this.#_e=""}#Bt(){let e=this.getAttribute("data-max-tool-rounds");return e===null?bn:Number.parseInt(e,10)}#Vt(){let e=this.getAttribute("data-message-actions");return e===null?new Set([Lt.COPY,Lt.RETRY]):new Set(e.split(",").map(n=>n.trim()).filter(n=>n!==""))}#jt(){let e=this.getAttribute("data-attachment-max-bytes");if(e===null)return Cs;let n=Number.parseInt(e,10);return Number.isFinite(n)&&n>=0?n:Cs}#qt(){let e=this.#k.files;if(e!==null)for(let n of Array.from(e))this.#S?.add(n);this.#k.value=""}#Wt(){this.#x.addEventListener("dragover",e=>{e.preventDefault(),this.#x.classList.add("chat--dragover")}),this.#x.addEventListener("dragleave",()=>{this.#x.classList.remove("chat--dragover")}),this.#x.addEventListener("drop",e=>{e.preventDefault(),this.#x.classList.remove("chat--dragover");let n=e.dataTransfer?.files;if(n!==void 0)for(let r of Array.from(n))this.#S?.add(r)})}#ot(){let e=this.getAttribute("data-threads-url");e!==null&&(this.conversationStore=new Nr(e,()=>this.#oe(e),this.conversationStore,()=>this.#be(),this.getAttribute("data-threads-cache")!=="false"))}async#it(){let e=this.getAttribute("data-tools-url");if(e!==null)try{let n=await fetch(e,this.#tt(e));this.#t=Na(await n.json())}catch{}}setSkills(e){this.#Qe=e,this.#De()}#Xt(){this.#H.enableChips(this.#nt("data-prompt-chips")),this.#H.enableSlash(this.#nt("data-slash-commands")),this.#Ze=this.#Yt(),this.#De()}#Yt(){let e=this.getAttribute("data-skills");if(e===null)return[];try{return ba(JSON.parse(e))}catch{return[]}}async#st(){let e=this.getAttribute("data-skills-url");if(e!==null)try{let n=await fetch(e,this.#tt(e));this.#Ke=ba(await n.json()),this.#De()}catch{}}#De(){let e=new Map;for(let n of[...this.#Ke,...this.#Ze,...this.#Qe])e.set(n.name,n);this.#H.setSkills([...e.values()])}#Kt(e){if(e.prompt===void 0){this.#R.hidden=!0,this.sendMessage(`/${e.name}`);return}let{text:n,missing:r}=tu(e.prompt,this.skillContext());if(r.length>0){this.#R.textContent=this.#e.skillNeeds.replace("{title}",e.title).replace("{fields}",r.join(", ")),this.#R.hidden=!1,this.#l.value=n,this.#J(),this.#l.focus(),this.#Zt(n);return}if(this.#R.hidden=!0,this.#l.value=n,this.#J(),e.sendImmediately===!1){this.#l.focus();return}this.#Be()}#Zt(e){let n=e.indexOf("{");this.#l.setSelectionRange(n,e.indexOf("}",n)+1)}get collapsed(){return this.hasAttribute("collapsed")}set collapsed(e){this.setCollapsed(e)}setCollapsed(e){e?this.setAttribute("collapsed",""):this.removeAttribute("collapsed"),et(this.#xe(mp),e?"1":"0"),this.#Te(0),this.dispatchEvent(new CustomEvent(vs,{detail:{collapsed:e},bubbles:!0,composed:!0}))}get unread(){return this.#pe}toggleCollapsed(){this.setCollapsed(!this.collapsed)}toggleTheme(){let e=this.getAttribute("theme")==="dark"?"light":"dark";this.setAttribute("theme",e),et(this.#xe(vp),e),this.#ut()}#Ue(){switch(this.getAttribute("placement")){case"full":case"page":return"none";case"sidebar":case"side":return"width";default:return"both"}}#at(){let e=this.getBoundingClientRect(),n=this.style.getPropertyValue("--ag-ui-width"),r=this.style.getPropertyValue("--ag-ui-height");this.#Fe({width:e.width+1,height:e.height+1});let o=this.getBoundingClientRect();return this.#lt("--ag-ui-width",n),this.#lt("--ag-ui-height",r),{x:Math.abs(o.left-e.left)<.5?"left":"right",y:Math.abs(o.top-e.top)<.5?"top":"bottom"}}#He(){if(!this.#K)return;let e=this.#at();this.setAttribute("data-resize-anchor",`${e.y}-${e.x}`)}#lt(e,n){if(n===""){this.style.removeProperty(e);return}this.style.setProperty(e,n)}#Fe(e){let n=this.#Ue();n!=="none"&&(e.width!==void 0&&this.style.setProperty("--ag-ui-width",`${e.width}px`),e.height!==void 0&&n==="both"&&this.style.setProperty("--ag-ui-height",`${e.height}px`))}#Qt(){let e=this.#Ue();e!=="both"&&this.style.removeProperty("--ag-ui-height"),e==="none"&&this.style.removeProperty("--ag-ui-width")}#Jt(e){let n={...this.#ct(),...e};et(this.#xe(gp),JSON.stringify(n))}#ct(){let e=this.#Ge(gp);if(e===null)return{};try{let n=JSON.parse(e);return typeof n=="object"&&n!==null?n:{}}catch{return{}}}#en(){let e=this.id!==""?this.id:this.endpoint;return e===""?"":this.#Ye===e?this.#Re:El.has(e)?(this.#Ye=e,this.#Re=`${e}~${Te()}`,console.warn(`<ag-ui-chat>: another element on this page already stores its conversation under "${e}", so this one has been given a throwaway namespace of its own \u2014 the two would otherwise share a thread pointer, a history drawer and every message. Give each <ag-ui-chat> its own id to keep them apart and let this one restore its conversation across reloads.`),this.#Re):(El.add(e),this.#ve=e,e)}#ze(e=this.userKey){return e===""?this.#Q:`${this.#Q}#${e}`}#tn(e,n){let r=this.#ze(e),o=this.#ze(n);if(e===""){je.adopt(r,o),this.#dt(o);return}je.purge(r),this.#dt(o),this.#F(),this.#ie(),this.#X(!1),this.#Te(0),this.#h=this.conversationStore.threadId(),this.#we(),this.#se()}#dt(e){this.#ne!==null&&(this.#ne=new je(e),this.conversationStore=this.#ne,this.#ot())}#xe(e){return this.#Q===""?e:`${e}:${this.#Q}`}#Ge(e){let n=sessionStorage.getItem(this.#xe(e));return n!==null||this.#Q===""?n:sessionStorage.getItem(e)}#ut(){let e=this.getAttribute("theme")==="dark";this.#L.textContent=e?"\u2600\uFE0F":"\u{1F319}"}openThreads(){this.#E.close(),this.#se(),this.#$.open()}openCheckpoints(){this.#$.close(),this.#Ct(),this.#E.open()}closeCheckpoints(){this.#E.close()}toggleCheckpoints(){if(this.#E.open_){this.#E.close();return}this.openCheckpoints()}newChat(){this.#F(),this.conversationStore.isUnsent?.(this.#h)===!0&&this.conversationStore.clear(this.#h),this.#ie(),this.#h=Yi(this.conversationStore),this.#X(!1),this.#Te(0)}#ie(){this.#V=null,this.#pt(),this.#Oe=[]}#pt(){this.#te(),this.#D=null,this.#W=null,this.#O(),this.#i.clear(),this.#o.clear(),this.#p.clear(),this.#d.clear(),this.#a.clear(),this.#y=null,this.#S?.clear(),this.#f.replaceChildren(this.#B),this.#T()}async retryLastTurn(){if(this.#j)return!1;let e=this.#Ve(),n=e.truncateToLastUser();if(n===null)return!1;this.#pt();for(let r of n)this.#ft(r);return await e.resume(),!0}async#nn(e){e!==this.#h&&(this.#F(),this.#ie(),this.conversationStore.setActiveThread(e),this.#h=e,this.#X(!1),await this.#we())}#rn(e){let n=e===this.#h;n&&this.#F(),this.conversationStore.clear(e),n&&(this.#ie(),this.#h=this.conversationStore.threadId(),this.#X(!1)),this.#se()}async#se(){this.#$.setRelativeTimeFormatter(this.formatRelativeTime),this.#$.setThreads(await this.conversationStore.listThreads(),this.#h)}async#we(){this.#Ne+=1;let e=this.#Ne,n=await this.conversationStore.loadMessages(this.#h);if(e!==this.#Ne)return;if(n!==null){this.#Oe=n;for(let o of n)this.#ft(o)}let r=this.conversationStore.loadCheckpoint(this.#h);if(r!==null){await this.#an(r);return}this.#in(n)}#ht(){return this.#Ce=window.location.href,this.getContext()}#on(){return this.#Ce!==null&&this.#Ce!==window.location.href}#in(e){let n=e?.at(-1);n===void 0||n.role!==ze.USER||this.#le("\u26A0",this.#e.runInterrupted,"interrupted")}#ft(e){let n=typeof e.content=="string"?e.content:"";if(e.role===ze.USER){let r=ml(e);if(n!==""||r.length>0){let o=this.appendMessage(ze.USER,n);r.length>0&&o.appendChild(Da(r))}return}if(e.role===ze.ASSISTANT){if(n!==""){let r=this.appendMessage(ze.ASSISTANT,n);r.classList.add("message--restored"),this.#je(r)}for(let r of tx(e.toolCalls)){let o={id:r.id,name:r.function.name,args:this.#sn(r.function.arguments)};if(this.#_t(o))continue;this.#d.set(o.id,this.#Xe(o).element);let i=this.#Le(o.name)?.render;i!==void 0&&this.#St(i,o)}return}if(e.role==="activity"){let r=e;typeof r.activityType=="string"&&this.#We(e.id,r.activityType,r.content);return}if(e.role==="tool"){let r=this.#i.get(e.toolCallId);r!==void 0&&r.settle(te.DONE,e.content)}}#sn(e){if(typeof e!="string")return{};try{let n=JSON.parse(e);if(typeof n=="object"&&n!==null)return n}catch{}return{}}#mt(e){this.getAttribute("data-text-animation")==="word"&&np(e)}async#an(e){this.conversationStore.saveCheckpoint(this.#h,null);let n=this.#Ve();n.addToolResult(e.toolCallId,JSON.stringify(this.navigationResult(e))),await n.resume()}appendMessage(e,n){let r=document.createElement("div");return r.className=`message message--${e}`,r.setAttribute("part",`message message-${e}`),e===ze.ASSISTANT?(r.innerHTML=zi(n,{allowImages:this.allowImages}),Pa(r,this.#e),this.#I().appendChild(r)):(this.#D=null,r.textContent=n,this.#f.appendChild(r)),this.#T(),e===ze.USER?this.#g.jump():this.#g.follow(),r}#I(){if(this.#D===null){let e=document.createElement("div");e.className="answer",e.setAttribute("part","answer"),this.#D=e,this.#f.appendChild(e),this.#T()}return this.#D}#ln(){this.#x.className="chat",this.#x.setAttribute("part","panel");let e=document.createElement("div");e.className="header",e.setAttribute("part","header");let n=this.#Se;n.className="header-title",n.setAttribute("part","title"),n.textContent=this.getAttribute("title-text")??this.#e.title,(this.querySelector('[slot="icon"]')!==null||this.getAttribute("data-icon-url")!==null)&&e.append(this.#gt("icon","icon",null));let r=document.createElement("slot");r.name="header-actions";let o=document.createElement("div");o.className="header-controls",o.setAttribute("part","header-controls");let i=this.#Ee("history",this.#e.chatHistory,"\u2630");i.addEventListener("click",()=>this.openThreads());let s=this.#Ee("checkpoints",this.#e.checkpoints,"\u21BA");s.addEventListener("click",()=>this.toggleCheckpoints());let a=this.#Ee("new",this.#e.newChat,"\u271A");a.addEventListener("click",()=>this.newChat());let l=this.#Ee("collapse",this.#e.collapse,"\u2014");l.addEventListener("click",()=>this.toggleCollapsed()),this.#Me()!==null?o.append(i,s,a):o.append(i,a),this.getAttribute("data-theme-toggle")!==null&&(this.#L.type="button",this.#L.className="header-btn header-btn--theme",this.#L.setAttribute("part","header-button theme-toggle"),this.#L.title=this.#e.toggleTheme,this.#L.setAttribute("aria-label",this.#e.toggleTheme),this.#L.addEventListener("click",()=>this.toggleTheme()),this.#ut(),o.append(this.#L)),o.append(l),e.append(n,r,o),this.#f.className="messages",this.#f.setAttribute("part","messages"),this.#f.setAttribute("role","log"),this.#f.setAttribute("aria-live","off"),this.#f.setAttribute("aria-label",this.#e.conversation),this.#z.className="jump-latest",this.#z.type="button",this.#z.setAttribute("part","jump-latest"),this.#z.textContent=this.#e.jumpToLatest,this.#z.addEventListener("click",()=>{this.#g.jump()}),this.#b.className="quote-selection",this.#b.type="button",this.#b.setAttribute("part","quote-selection"),this.#b.textContent=this.#e.quoteSelection,this.#b.hidden=!0,this.#b.addEventListener("mousedown",h=>{h.preventDefault()}),this.#b.addEventListener("click",()=>{this.quote(this.#_e),window.getSelection()?.removeAllRanges(),this.#Pe()}),this.#f.addEventListener("mouseup",h=>this.#rt(h)),this.#f.addEventListener("keyup",()=>this.#rt()),this.#f.addEventListener("mousedown",()=>this.#Pe()),this.#g=rp({viewport:this.#f,onMissedContent:h=>{this.#z.dataset.missed=String(h)}}),this.#M.className="sr-only",this.#M.setAttribute("role","status"),this.#M.setAttribute("aria-live","polite"),this.#M.setAttribute("aria-atomic","true"),this.#B.className="empty",this.#B.setAttribute("part","empty");let c=document.createElement("slot");c.name="empty",this.#B.append(c),this.#f.append(this.#B);let u=document.createElement("div");u.className="input-row",u.setAttribute("part","composer");let m=document.createElement("div");m.className="composer",m.setAttribute("part","composer-surface");let y=document.createElement("div");y.className="composer-tools",y.setAttribute("part","composer-tools"),this.#l.className="input",this.#l.setAttribute("part","input"),this.#l.setAttribute("aria-label",this.#e.message),this.#l.rows=1,this.#l.placeholder=this.#e.inputPlaceholder,this.#l.addEventListener("keydown",h=>this.#hn(h)),this.#l.addEventListener("input",()=>this.#bt()),this.#w.className="send",this.#w.type="button",this.#w.setAttribute("part","send"),this.#w.append(this.#$e("icon-send","send-send",Jl),this.#$e("icon-stop","send-stop",ec)),this.#w.title=this.#e.send,this.#w.setAttribute("aria-label",this.#e.send),this.#w.dataset.state="idle",this.#w.addEventListener("click",()=>{if(this.#j){this.#F();return}this.#Be()}),this.#R.className="skill-hint",this.#R.setAttribute("part","skill-hint"),this.#R.hidden=!0,this.#A.className="attach-btn",this.#A.type="button",this.#A.setAttribute("part","attach-button"),this.#A.append(this.#$e("icon-attach","attach-glyph",tc)),this.#A.title=this.#e.attachFiles,this.#A.setAttribute("aria-label",this.#e.attachFiles),this.#A.hidden=!0,this.#A.addEventListener("click",()=>this.#k.click()),this.#k.className="attach-input",this.#k.type="file",this.#k.multiple=!0,this.#k.hidden=!0,this.#k.addEventListener("change",()=>this.#qt()),this.#ue.className="attachment-slot",this.#he.className="voice-slot";let f=document.createElement("slot");f.name="footer",y.append(this.#A,this.#he,this.#w),m.append(this.#l,y),u.append(m,this.#k),this.#ce.className="messages-wrap",this.#ce.append(this.#f,this.#z,this.#b),this.#x.append(e,this.#ce,this.#H.palette,this.#H.chips,this.#R,this.#ue,u,f,this.#$.element,this.#E.element),this.#x.addEventListener("pointerdown",h=>{if(!this.#E.open_)return;let g=h.composedPath();g.includes(this.#E.element)||g.includes(s)||this.#E.close()}),this.#C.className="launcher",this.#C.type="button",this.#C.setAttribute("part","launcher"),this.#C.setAttribute("aria-label",this.#e.expand),this.#P.className="launcher-badge",this.#P.setAttribute("part","launcher-badge"),this.#P.setAttribute("aria-hidden","true"),this.#P.hidden=!0,this.#C.append(this.#gt("launcher","launcher-icon",rc,this.#dn()),this.#P),this.#C.addEventListener("click",()=>this.setCollapsed(!1)),this.#x.append(ep({axis:()=>this.#Ue(),anchor:()=>this.#at(),rect:()=>this.getBoundingClientRect(),apply:h=>this.#Fe(h),commit:h=>{this.#Jt(h),this.#He()},label:this.#e.resizePanel})),this.#cn(),this.#_.append(this.#M,this.#x,this.#C)}#ae(e){this.#G!==null&&clearTimeout(this.#G),this.#M.textContent=e,this.#G=setTimeout(()=>{this.#G=null,this.#M.textContent=""},lc)}#cn(){let e=new CSSStyleSheet;e.replaceSync(op),this.#_.adoptedStyleSheets=[e]}#Ee(e,n,r){let o=document.createElement("button");o.type="button",o.className=`header-btn header-btn--${e}`,o.setAttribute("part",`header-button ${e}-button`),o.title=n,o.setAttribute("aria-label",n);let i=document.createElement("slot");return i.name=`icon-${e}`,i.append(document.createTextNode(r)),o.append(i),o}#$e(e,n,r){let o=document.createElement("slot");return o.name=e,o.className=n,o.innerHTML=r,o}#dn(){return this.getAttribute("data-launcher-icon-url")??this.getAttribute("data-icon-url")}#gt(e,n,r,o=this.getAttribute("data-icon-url")){let i=document.createElement("span");i.className="icon-holder",i.setAttribute("part",n);let s=document.createElement("slot");if(s.name=e,o!==null){let a=document.createElement("img");a.className="icon-img",a.src=o,a.alt="",s.append(a)}else r!==null&&(s.innerHTML=r);return i.append(s),i}#vt(){this.#C.setAttribute("aria-expanded",String(!this.collapsed));let e=this.#pe;this.#P.textContent=e>9?"9+":String(e),this.#P.hidden=e===0||!this.#un();let n=this.#P.hidden?this.#e.expand:this.#e.expandUnread.replace("{count}",String(e));this.#C.setAttribute("aria-label",n),this.#C.title=n}#un(){return this.getAttribute("data-unread-badge")!=="false"}#Te(e){this.#pe=e,this.#vt(),this.dispatchEvent(new CustomEvent(bs,{detail:{unread:e},bubbles:!0,composed:!0}))}#pn(){this.collapsed&&this.#Te(this.#pe+1)}#T(){this.#B.hidden=this.#f.childElementCount>1}#bt(){this.#H.onInput(this.#l.value),this.#R.hidden=!0,this.#J()}#hn(e){if(this.#H.onKeydown(e)){e.preventDefault();return}if(e.key==="Escape"&&this.#j){e.preventDefault(),this.#F();return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),this.#Be())}#F(){this.#N?.abort(),this.#V?.cancel()}#X(e){this.#j=e;let n=e?this.#e.stop:this.#e.send;this.#w.title=n,this.#w.setAttribute("aria-label",n),this.#w.dataset.state=e?"running":"idle"}#J(){this.#l.style.height="auto",this.#l.style.height=`${this.#l.scrollHeight}px`}async#Be(){if(this.#j)return;let e=this.#l.value.trim(),n=this.#S?.readyRefs()??[];e===""&&n.length===0||(this.#l.value="",this.#J(),this.#S?.hasPending()===!0&&this.#le("\u{1F4CE}",this.#e.attachmentsStillUploading.replace("{n}",String(this.#S.pendingCount())),"attachment-pending"),this.#S?.clearReady(),await this.sendMessage(e,n))}async sendMessage(e,n=[]){if(this.#j||e===""&&n.length===0)return;let r=this.appendMessage(ze.USER,e);n.length>0&&r.appendChild(Da(n)),this.dispatchEvent(new CustomEvent(gs,{detail:{content:e,attachments:n},bubbles:!0,composed:!0})),await this.#mn(e,n)}attachFile(e){return this.#S===null?!1:(this.#S.add(e),!0)}#fn(e){this.dispatchEvent(new CustomEvent(xs,{detail:{attachments:e.readyRefs(),pending:e.pendingCount()},bubbles:!0,composed:!0}))}async#mn(e,n){this.endpoint!==""&&await this.#Ve().send(e,n)}#Ve(){if(this.#V===null){let e=this.agentFactory({endpoint:this.endpoint,headers:this.#re(),getHeaders:()=>this.#re(),trustedOrigins:this.trustedOrigins,...this.#ye(),threadId:this.#h,initialMessages:this.#Oe,initialState:this.#Z});this.#V=new Bn({agent:e,handlers:this.#wt(),getTools:()=>this.#et(),getContext:()=>this.#ht(),executeTool:n=>this.#yt(n),resolveInterrupts:n=>this.#xt(n),onPersist:n=>this.conversationStore.saveMessages(this.#h,n),onStateChanged:n=>this.#gn(n),connectionLostMessage:this.#e.connectionLost,maxToolRounds:this.#Bt()})}return this.#V}#gn(e){this.#Z={...e},this.dispatchEvent(new CustomEvent(ys,{detail:{state:this.#Z},bubbles:!0,composed:!0}))}#je(e,n={}){let r=this.#Vt(),o=r.has(Lt.COPY),i=n.rateable!==!1&&r.has(Lt.FEEDBACK);(o||i)&&Ga(e,{strings:this.#e,...o?{text:()=>e.textContent}:{},...i?{onFeedback:s=>{this.dispatchEvent(new CustomEvent(_s,{detail:{content:e.textContent,rating:s},bubbles:!0,composed:!0}))}}:{}}),r.has(Lt.RETRY)&&this.#vn(Ni(e,this.#e))}#vn(e){this.#y?.querySelector(".message-action--retry")?.remove();let n=Oi("retry",this.#e.retryMessage,"\u21BB");n.addEventListener("click",()=>{this.retryLastTurn()}),e.prepend(n),this.#y=e}async#bn(e,n){return this.autoConfirm?null:this.confirmPredicate!==null?await this.confirmPredicate(e.name,e.args)===!0?"predicate":null:this.#m.has(e.name)?null:ya(n.parameters)?"destructive":null}async#yt(e){if(bp(e)!==null)return null;let n=this.#Xe(e);this.#i.delete(e.id),this.#d.set(e.id,n.element);let r=this.#s.has(e.name)?this.#Le(e.name):null;if(r===null)return this.#p.has(e.id)||n.settle(te.DONE,this.#e.noResult),null;if(this.getPageMap!==null&&e.name!==ks&&!wi(r.parameters)&&this.#on()){let s=this.#e.pageMoved;return n.settle(te.ERROR,s),this.#ee(),{content:`Error: ${s}`,error:s}}let o=await this.#bn(e,r);if(o!==null){let s={toolName:e.name,args:e.args},a=r.parameters[Wr];typeof a=="string"&&(s.message=a),this.#N=new AbortController;let l=za(this.#I(),s,{signal:this.#N.signal,strings:this.#e,...o==="destructive"?{onAlwaysAllow:()=>this.#m.add(e.name)}:{}});this.#T(),this.#g.follow();let c=await l;if(this.#N=null,n.recordDecision(c?"approved":"declined"),!c){let u=this.#e.declinedAction;return n.settle(te.DECLINED,u),this.#ee(),{content:u}}}let i=wi(r.parameters)&&this.navigate===null;i&&this.conversationStore.saveCheckpoint(this.#h,{toolCallId:e.id});try{let s=await r.handler(e.args,e.id);if(r.render!==void 0&&this.#St(r.render,e),i)return n.settle(te.DONE,this.#e.navigating),{content:"",halt:!0};let a=JSON.stringify(s??null);return n.settle(te.DONE,a),this.#ee(),{content:a}}catch(s){i&&this.conversationStore.saveCheckpoint(this.#h,null);let a=s instanceof Error?s.message:String(s);return n.settle(te.ERROR,a),this.#ee(),{content:`Error: ${a}`,error:a}}}async#xt(e){this.#N=new AbortController,this.#ae(this.#e.announceAwaitingDecision.replace("{count}",String(e.length))),this.#O();let n=this.#N.signal,r=await Promise.all(e.map(async i=>{let s=i.toolCallId!==void 0?this.#i.get(i.toolCallId):void 0,a={},l=ex(i)??i.message;l!==void 0&&(a.message=l);let c=s?.element.getAttribute("data-tool-name");c!=null&&(a.toolName=c);let u,m=this.approveWithEdits&&s!==void 0;m&&(a.args=s.args),s?.mark(te.DEFERRED);let y=this.approvalRenderer!==null?await this.approvalRenderer(a,{signal:n}):await La(s?.approvalSlot??this.#I(),a,{signal:n,strings:this.#e,...m?{onEdit:f=>{u=f}}:{}});return s?.recordDecision(y?"approved":"declined"),y?s?.mark(te.PENDING):s?.settle(te.DECLINED,this.#e.declinedAction),{id:i.id,approved:y,editedArgs:u}}));this.#T(),this.#g.follow(),this.#N=null;let o={};for(let{id:i,approved:s,editedArgs:a}of r)o[i]=s?{status:"resolved",payload:a===void 0?{approved:!0}:{approved:!0,editedArgs:a}}:{status:"cancelled"};return o}#wt(){return{onRunStart:()=>{this.#j||(this.#de=!1,this.#ae(this.#e.announceResponding)),this.#X(!0),this.#I(),this.#ee()},onReasoningStart:()=>{this.#O(),this.#Et()},onReasoningDelta:e=>{this.#Et().stream(e)},onReasoningEnd:()=>{},onTextDelta:e=>{this.#O(),this.#W?.collapse(),this.#Tn(e),this.#Ie+=1},onTextEnd:e=>{let n=this.#qe(e);this.#Ie<=1&&this.#mt(n),Pa(n,this.#e),this.#je(n),this.#te(),this.#pn()},onToolCall:e=>{this.#O(),!this.#_t(e)&&(this.#v.push({id:e.id,name:e.name}),this.#Xe(e))},onActivity:(e,n,r)=>{this.#We(r,e,n)},onCustomEvent:(e,n)=>{if(e===As){this.#xn(n);return}if(e===Zl){this.#wn(n);return}this.dispatchEvent(new CustomEvent(Es,{detail:{name:e,value:n},bubbles:!0,composed:!0}))},onMessagesSnapshot:()=>{this.#le("\u{1F504}",this.#e.historyReplaced,"history-replaced")},onToolResult:(e,n)=>{let r=this.#i.get(e);r!==void 0&&(r.settle(te.DONE,n),this.#p.add(e),this.#ee())},onActivityChanged:(e,n,r)=>{this.#We(e,n,r)},onRunEnd:()=>{this.#O(),this.#te()},onError:e=>{this.#de=!0,this.#ae(this.#e.announceFailed),this.#O();let n=this.appendMessage(ze.ASSISTANT,`\u26A0\uFE0F ${e}`);n.classList.add("message--failed"),this.#je(n,{rateable:!1}),this.#mt(n),this.#te()},onCancelled:()=>{this.#de=!0,this.#ae(this.#e.announceStopped),this.#O(),this.#En(),this.#te()},onSettled:()=>{this.#de||this.#ae(this.#e.announceAnswerReady),this.#O(),this.#X(!1),this.#te();for(let e of this.#i.values())e.settled||e.settle(te.DONE,this.#e.noResult);this.#D!==null&&this.#D.childElementCount===0&&(this.#D.remove(),this.#T()),this.#D=null,this.#W=null,this.#yn()}}}#yn(){let e=this.#v.map(({id:r,name:o})=>({name:o,side:this.#p.has(r)?"server":"client"}));this.#v=[];let n=[...this.#U];this.#U=new Set,this.dispatchEvent(new CustomEvent(ws,{detail:{tools:e,invalidated:n},bubbles:!0,composed:!0}))}#xn(e){let n=e??{},r=Array.isArray(n.keys)?n.keys.filter(o=>typeof o=="string"):[];if(r.length!==0){for(let o of r)this.#U.add(o);this.dispatchEvent(new CustomEvent(Ts,{detail:{keys:r,reason:typeof n.reason=="string"?n.reason:null},bubbles:!0,composed:!0}))}}#wn(e){let n=sp(e);if(n===null)return;let r=this.#i.get(n.delegationId);if(r===void 0)return;let o=this.#o.get(n.delegationId);o===void 0&&(o=new $i(this.#e),this.#o.set(n.delegationId,o),r.subagentSlot.appendChild(o.element)),o.report(n),this.#g.follow()}#En(){let e=document.createElement("div");e.className="stopped-note",e.setAttribute("part","stopped"),e.setAttribute("role","status"),e.textContent=this.#e.stopped,this.#I().appendChild(e),this.#T(),this.#g.follow()}#ee(){if(this.#ge!==null)return;let e=document.createElement("div");e.className="pending",e.setAttribute("part","pending"),e.setAttribute("role","status"),e.setAttribute("aria-label",this.#e.thinking);for(let n=0;n<3;n+=1){let r=document.createElement("span");r.className="pending-dot",e.appendChild(r)}this.#ge=e,this.#I().appendChild(e),this.#T(),this.#g.follow()}#O(){this.#ge?.remove(),this.#ge=null}#Et(){if(this.#W===null){this.#W=new Bi(this.#e);let e=this.#I();e.insertBefore(this.#W.element,e.firstChild),this.#T(),this.#g.follow()}return this.#W}#Tt(){return this.#fe===null&&(this.#fe=this.appendMessage(ze.ASSISTANT,""),this.#Ie=0),this.#fe}#Tn(e){this.#me=e,this.#Tt(),this.#q===null&&(this.#q=requestAnimationFrame(()=>{this.#q=null,this.#qe(this.#me)}))}#qe(e){this.#q!==null&&(cancelAnimationFrame(this.#q),this.#q=null),this.#me=e;let n=this.#Tt();return n.innerHTML=zi(e,{allowImages:this.allowImages}),this.#g.follow(),n}#te(){this.#q!==null&&this.#qe(this.#me),this.#fe=null}#_t(e){let n=bp(e);return n===null?!1:(this.#le("\u2728",this.#e.usingSkill.replace("{name}",n),"skill"),!0)}#le(e,n,r){this.#I().appendChild(pl(e,n,r)),this.#T(),this.#g.follow()}enableCharts(e=["tool","activity"]){let n=!this.#u.has(Xr)&&!this.#r.has(Ri);e.includes("activity")&&this.registerActivityRenderer({type:Xr,render:r=>{let o=Un(r);return o===null?null:gr(o)},removedNotice:this.#e.chartUndrawable}),e.includes("tool")&&this.registerTool(lu()),n&&this.isConnected&&this.reload()}#St(e,n){let r;try{r=e(n.args)}catch(o){console.warn(`ag-ui-chat: render failed for tool ${n.name}`,o);return}r!==null&&(this.#d.get(n.id)?.after(r),this.#At())}registerActivityRenderer(e){this.#u.set(e.type,e),this.#c.delete(e.type)}get unhandledActivityTypes(){return[...this.#c]}#We(e,n,r){let o=this.#u.get(n);if(o===void 0){this.#c.add(n);return}let i;try{i=o.render(r)}catch(a){console.warn(`ag-ui-chat: render failed for activity ${n}`,a),i=null}if(i===null){this.#_n(e,n,o.removedNotice,r);return}let s=this.#a.get(e);s===void 0?this.#I().appendChild(i):s.replaceWith(i),this.#a.set(e,i),this.#At()}#_n(e,n,r,o){let i=this.#a.has(e);this.#a.get(e)?.remove(),this.#a.delete(e),console.warn(`ag-ui-chat: activity ${e} (${n}) was not drawable and has been removed. A chart's points must each be a finite JSON number; a numeric column serialised as a string (a Decimal, typically) is rejected rather than coerced.`,o),i&&r!==void 0&&this.#le("\u{1F4C9}",r,"chart-undrawable")}#At(){this.#T(),this.#g.follow()}#Xe(e){let n=this.#i.get(e.id);if(n!==void 0)return n;let r=this.#Le(e.name)?.parameters[Pe],o=typeof r=="string"?r:this.toolSummaries[e.name]??this.#t[e.name]?.summary??ja(e.name),i=new Cr(e.name,e.args,o,this.#e,{formatPayload:s=>this.formatToolPayload?.(s)??null});return this.#i.set(e.id,i),this.#I().appendChild(i.element),this.#T(),this.#g.follow(),i}};function ex(t){let e=t.metadata?.[Wr];return typeof e=="string"&&e.trim()!==""?e:void 0}function tx(t){return Array.isArray(t)?t.filter(nx):[]}function nx(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.id=="string"&&typeof e.function?.name=="string"}function bp(t){if(t.name!==Rs)return null;let e=t.args?.id;return typeof e=="string"&&e!==""?e:null}function rx(t){let e=t?.removed;return typeof e=="number"?e:null}function ox(){customElements.get(qr)===void 0&&customElements.define(qr,Mr)}async function ix(t,e,n={}){await vt(t),await _a(t,{...n,flashMs:n.flashMs??0}),await Ea(t,e,n)}async function sx(t,e={}){await vt(t),await Ta(t,e)}async function ax(t,e={}){await vt(t),await Sa(t,e)}async function lx(t,e,n={}){await vt(t),await Aa(t,e,n)}async function cx(t,e,n={}){await vt(t),await ka(t,e,n)}function dx(t,e){t instanceof HTMLInputElement&&t.type==="checkbox"?hr(t,!!e):on(t,String(e)),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0}))}var ux="0.31.0";export{xs as ATTACHMENT_EVENT,Mr as AgUiChat,Bn as AgUiClient,Xr as CHART_ACTIVITY_TYPE,Ri as CHART_TOOL_NAME,Is as COMPACTION_ACTIVITY_TYPE,Es as CUSTOM_AGENT_EVENT,br as CheckpointMenu,pr as ClientToolRegistry,qi as ConnectionLostError,ee as DEFAULT_UI_STRINGS,qr as ELEMENT_TAG,_s as FEEDBACK_EVENT,As as INVALIDATE_CUSTOM_NAME,Ts as INVALIDATE_EVENT,Rs as LOAD_CAPABILITY_TOOL,zv as MAX_QUOTE_CHARS,Fy as MAX_SUGGESTIONS,zy as MAX_SUGGESTION_CHARS,bn as MAX_TOOL_ROUNDS,Lt as MESSAGE_ACTIONS,ze as MESSAGE_ROLE,Ca as PAGE_ACTIONS,ws as RUN_FINISHED_EVENT,Nr as RemoteConversationStore,Or as RunIndex,ys as STATE_EVENT,gs as SUBMIT_EVENT,Ss as SUGGESTIONS_ACTIVITY_TYPE,je as SessionStorageStore,vs as TOGGLE_EVENT,te as TOOL_CALL_STATUS,yn as TOOL_DISPLAY,Cr as ToolCallCard,bs as UNREAD_EVENT,ux as VERSION,Wr as X_CONFIRM_KEY,Kn as X_DESTRUCTIVE_KEY,Zn as X_NAVIGATES_KEY,Pe as X_SUMMARY_KEY,$a as asQuote,Ga as attachMessageActions,Va as attachQuoteOffer,Un as chartSpecFrom,sx as clickElement,vl as createHttpAgent,Ia as createPageActionTools,Ra as createPageMapContext,Si as createPageStateTools,Oa as createRouteTools,pv as createStateHookTools,ox as defineAgUiChat,ix as fillField,av as flash,_a as focusWithFlash,Ta as highlightThenClick,ya as isDestructive,wi as isNavigates,Ma as mergeUiStrings,Ni as messageActionBar,ml as messageAttachments,Na as parseToolCatalog,Ti as prefersReducedMotion,ax as pressButton,Sa as pressThenClick,ja as prettifyToolName,yr as quotableSelection,vr as relativeTime,gr as renderChart,zi as renderMarkdown,hl as renderSuggestionChips,La as requestApproval,za as requestConfirmation,qa as requestQuestion,vt as scrollIntoCenterView,lx as selectControl,Aa as selectOption,dx as setControlValue,hr as setNativeChecked,on as setNativeValue,ap as suggestionPrompts,cx as toggleCheckbox,ka as toggleControl,bl as transcribeAudio,Ea as typeInto,yl as uploadAttachment};
|
|
2854
|
+
${n}`,this.#J(),this.#l.focus();let o=this.#l.value.length;this.#l.setSelectionRange(o,o)}offerQuoteInPage(e=document.body){this.#Y?.detach();let n=Va({within:e,label:this.#e.quoteSelection,exclude:this,onQuote:r=>this.quote(r)});return this.#Y=n,()=>{n.detach(),this.#Y===n&&(this.#Y=null)}}#Gt(){return this.getAttribute("data-quote-selection")!=="false"}#rt(e){if(!this.#Gt())return;let n=e===void 0?void 0:{x:e.clientX,y:e.clientY},r=yr(this.#f,[this.#_],n);if(r===null){this.#Pe();return}this.#_e=r.text,this.#$t(r.rect)}#$t(e){this.#b.hidden=!1;let n=this.#ce.getBoundingClientRect(),r=e.top-n.top,o=r<wl+this.#b.offsetHeight;this.#b.dataset.below=String(o),this.#b.style.top=`${o?e.bottom-n.top+wl:r-wl}px`;let i=this.#b.offsetWidth/2,s=e.left+e.width/2-n.left;this.#b.style.left=`${Math.min(Math.max(s,i),n.width-i)}px`}#Pe(){this.#b.hidden=!0,this.#_e=""}#Bt(){let e=this.getAttribute("data-max-tool-rounds");return e===null?bn:Number.parseInt(e,10)}#Vt(){let e=this.getAttribute("data-message-actions");return e===null?new Set([Lt.COPY,Lt.RETRY]):new Set(e.split(",").map(n=>n.trim()).filter(n=>n!==""))}#jt(){let e=this.getAttribute("data-attachment-max-bytes");if(e===null)return Cs;let n=Number.parseInt(e,10);return Number.isFinite(n)&&n>=0?n:Cs}#qt(){let e=this.#k.files;if(e!==null)for(let n of Array.from(e))this.#S?.add(n);this.#k.value=""}#Wt(){this.#x.addEventListener("dragover",e=>{e.preventDefault(),this.#x.classList.add("chat--dragover")}),this.#x.addEventListener("dragleave",()=>{this.#x.classList.remove("chat--dragover")}),this.#x.addEventListener("drop",e=>{e.preventDefault(),this.#x.classList.remove("chat--dragover");let n=e.dataTransfer?.files;if(n!==void 0)for(let r of Array.from(n))this.#S?.add(r)})}#ot(){let e=this.getAttribute("data-threads-url");e!==null&&(this.conversationStore=new Nr(e,()=>this.#oe(e),this.conversationStore,()=>this.#be(),this.getAttribute("data-threads-cache")!=="false"))}async#it(){let e=this.getAttribute("data-tools-url");if(e!==null)try{let n=await fetch(e,this.#tt(e));this.#t=Na(await n.json())}catch{}}setSkills(e){this.#Qe=e,this.#De()}#Xt(){this.#H.enableChips(this.#nt("data-prompt-chips")),this.#H.enableSlash(this.#nt("data-slash-commands")),this.#Ze=this.#Yt(),this.#De()}#Yt(){let e=this.getAttribute("data-skills");if(e===null)return[];try{return ba(JSON.parse(e))}catch{return[]}}async#st(){let e=this.getAttribute("data-skills-url");if(e!==null)try{let n=await fetch(e,this.#tt(e));this.#Ke=ba(await n.json()),this.#De()}catch{}}#De(){let e=new Map;for(let n of[...this.#Ke,...this.#Ze,...this.#Qe])e.set(n.name,n);this.#H.setSkills([...e.values()])}#Kt(e){if(e.prompt===void 0){this.#R.hidden=!0,this.sendMessage(`/${e.name}`);return}let{text:n,missing:r}=tu(e.prompt,this.skillContext());if(r.length>0){this.#R.textContent=this.#e.skillNeeds.replace("{title}",e.title).replace("{fields}",r.join(", ")),this.#R.hidden=!1,this.#l.value=n,this.#J(),this.#l.focus(),this.#Zt(n);return}if(this.#R.hidden=!0,this.#l.value=n,this.#J(),e.sendImmediately===!1){this.#l.focus();return}this.#Be()}#Zt(e){let n=e.indexOf("{");this.#l.setSelectionRange(n,e.indexOf("}",n)+1)}get collapsed(){return this.hasAttribute("collapsed")}set collapsed(e){this.setCollapsed(e)}setCollapsed(e){e?this.setAttribute("collapsed",""):this.removeAttribute("collapsed"),et(this.#xe(mp),e?"1":"0"),this.#Te(0),this.dispatchEvent(new CustomEvent(vs,{detail:{collapsed:e},bubbles:!0,composed:!0}))}get unread(){return this.#pe}toggleCollapsed(){this.setCollapsed(!this.collapsed)}toggleTheme(){let e=this.getAttribute("theme")==="dark"?"light":"dark";this.setAttribute("theme",e),et(this.#xe(vp),e),this.#ut()}#Ue(){switch(this.getAttribute("placement")){case"full":case"page":return"none";case"sidebar":case"side":return"width";default:return"both"}}#at(){let e=this.getBoundingClientRect(),n=this.style.getPropertyValue("--ag-ui-width"),r=this.style.getPropertyValue("--ag-ui-height");this.#Fe({width:e.width+1,height:e.height+1});let o=this.getBoundingClientRect();return this.#lt("--ag-ui-width",n),this.#lt("--ag-ui-height",r),{x:Math.abs(o.left-e.left)<.5?"left":"right",y:Math.abs(o.top-e.top)<.5?"top":"bottom"}}#He(){if(!this.#K)return;let e=this.#at();this.setAttribute("data-resize-anchor",`${e.y}-${e.x}`)}#lt(e,n){if(n===""){this.style.removeProperty(e);return}this.style.setProperty(e,n)}#Fe(e){let n=this.#Ue();n!=="none"&&(e.width!==void 0&&this.style.setProperty("--ag-ui-width",`${e.width}px`),e.height!==void 0&&n==="both"&&this.style.setProperty("--ag-ui-height",`${e.height}px`))}#Qt(){let e=this.#Ue();e!=="both"&&this.style.removeProperty("--ag-ui-height"),e==="none"&&this.style.removeProperty("--ag-ui-width")}#Jt(e){let n={...this.#ct(),...e};et(this.#xe(gp),JSON.stringify(n))}#ct(){let e=this.#Ge(gp);if(e===null)return{};try{let n=JSON.parse(e);return typeof n=="object"&&n!==null?n:{}}catch{return{}}}#en(){let e=this.id!==""?this.id:this.endpoint;return e===""?"":this.#Ye===e?this.#Re:El.has(e)?(this.#Ye=e,this.#Re=`${e}~${Te()}`,console.warn(`<ag-ui-chat>: another element on this page already stores its conversation under "${e}", so this one has been given a throwaway namespace of its own \u2014 the two would otherwise share a thread pointer, a history drawer and every message. Give each <ag-ui-chat> its own id to keep them apart and let this one restore its conversation across reloads.`),this.#Re):(El.add(e),this.#ve=e,e)}#ze(e=this.userKey){return e===""?this.#Q:`${this.#Q}#${e}`}#tn(e,n){let r=this.#ze(e),o=this.#ze(n);if(e===""){je.adopt(r,o),this.#dt(o);return}je.purge(r),this.#dt(o),this.#F(),this.#ie(),this.#X(!1),this.#Te(0),this.#h=this.conversationStore.threadId(),this.#we(),this.#se()}#dt(e){this.#ne!==null&&(this.#ne=new je(e),this.conversationStore=this.#ne,this.#ot())}#xe(e){return this.#Q===""?e:`${e}:${this.#Q}`}#Ge(e){let n=sessionStorage.getItem(this.#xe(e));return n!==null||this.#Q===""?n:sessionStorage.getItem(e)}#ut(){let e=this.getAttribute("theme")==="dark";this.#L.textContent=e?"\u2600\uFE0F":"\u{1F319}"}openThreads(){this.#E.close(),this.#se(),this.#$.open()}openCheckpoints(){this.#$.close(),this.#Ct(),this.#E.open()}closeCheckpoints(){this.#E.close()}toggleCheckpoints(){if(this.#E.open_){this.#E.close();return}this.openCheckpoints()}newChat(){this.#F(),this.conversationStore.isUnsent?.(this.#h)===!0&&this.conversationStore.clear(this.#h),this.#ie(),this.#h=Yi(this.conversationStore),this.#X(!1),this.#Te(0)}#ie(){this.#V=null,this.#pt(),this.#Oe=[]}#pt(){this.#te(),this.#D=null,this.#W=null,this.#O(),this.#i.clear(),this.#o.clear(),this.#p.clear(),this.#d.clear(),this.#a.clear(),this.#y=null,this.#S?.clear(),this.#f.replaceChildren(this.#B),this.#T()}async retryLastTurn(){if(this.#j)return!1;let e=this.#Ve(),n=e.truncateToLastUser();if(n===null)return!1;this.#pt();for(let r of n)this.#ft(r);return await e.resume(),!0}async#nn(e){e!==this.#h&&(this.#F(),this.#ie(),this.conversationStore.setActiveThread(e),this.#h=e,this.#X(!1),await this.#we())}#rn(e){let n=e===this.#h;n&&this.#F(),this.conversationStore.clear(e),n&&(this.#ie(),this.#h=this.conversationStore.threadId(),this.#X(!1)),this.#se()}async#se(){this.#$.setRelativeTimeFormatter(this.formatRelativeTime),this.#$.setThreads(await this.conversationStore.listThreads(),this.#h)}async#we(){this.#Ne+=1;let e=this.#Ne,n=await this.conversationStore.loadMessages(this.#h);if(e!==this.#Ne)return;if(n!==null){this.#Oe=n;for(let o of n)this.#ft(o)}let r=this.conversationStore.loadCheckpoint(this.#h);if(r!==null){await this.#an(r);return}this.#in(n)}#ht(){return this.#Ce=window.location.href,this.getContext()}#on(){return this.#Ce!==null&&this.#Ce!==window.location.href}#in(e){let n=e?.at(-1);n===void 0||n.role!==ze.USER||this.#le("\u26A0",this.#e.runInterrupted,"interrupted")}#ft(e){let n=typeof e.content=="string"?e.content:"";if(e.role===ze.USER){let r=ml(e);if(n!==""||r.length>0){let o=this.appendMessage(ze.USER,n);r.length>0&&o.appendChild(Da(r))}return}if(e.role===ze.ASSISTANT){if(n!==""){let r=this.appendMessage(ze.ASSISTANT,n);r.classList.add("message--restored"),this.#je(r)}for(let r of tx(e.toolCalls)){let o={id:r.id,name:r.function.name,args:this.#sn(r.function.arguments)};if(this.#_t(o))continue;this.#d.set(o.id,this.#Xe(o).element);let i=this.#Le(o.name)?.render;i!==void 0&&this.#St(i,o)}return}if(e.role==="activity"){let r=e;typeof r.activityType=="string"&&this.#We(e.id,r.activityType,r.content);return}if(e.role==="tool"){let r=this.#i.get(e.toolCallId);r!==void 0&&r.settle(te.DONE,e.content)}}#sn(e){if(typeof e!="string")return{};try{let n=JSON.parse(e);if(typeof n=="object"&&n!==null)return n}catch{}return{}}#mt(e){this.getAttribute("data-text-animation")==="word"&&np(e)}async#an(e){this.conversationStore.saveCheckpoint(this.#h,null);let n=this.#Ve();n.addToolResult(e.toolCallId,JSON.stringify(this.navigationResult(e))),await n.resume()}appendMessage(e,n){let r=document.createElement("div");return r.className=`message message--${e}`,r.setAttribute("part",`message message-${e}`),e===ze.ASSISTANT?(r.innerHTML=zi(n,{allowImages:this.allowImages}),Pa(r,this.#e),this.#I().appendChild(r)):(this.#D=null,r.textContent=n,this.#f.appendChild(r)),this.#T(),e===ze.USER?this.#g.jump():this.#g.follow(),r}#I(){if(this.#D===null){let e=document.createElement("div");e.className="answer",e.setAttribute("part","answer"),this.#D=e,this.#f.appendChild(e),this.#T()}return this.#D}#ln(){this.#x.className="chat",this.#x.setAttribute("part","panel");let e=document.createElement("div");e.className="header",e.setAttribute("part","header");let n=this.#Se;n.className="header-title",n.setAttribute("part","title"),n.textContent=this.getAttribute("title-text")??this.#e.title,(this.querySelector('[slot="icon"]')!==null||this.getAttribute("data-icon-url")!==null)&&e.append(this.#gt("icon","icon",null));let r=document.createElement("slot");r.name="header-actions";let o=document.createElement("div");o.className="header-controls",o.setAttribute("part","header-controls");let i=this.#Ee("history",this.#e.chatHistory,"\u2630");i.addEventListener("click",()=>this.openThreads());let s=this.#Ee("checkpoints",this.#e.checkpoints,"\u21BA");s.addEventListener("click",()=>this.toggleCheckpoints());let a=this.#Ee("new",this.#e.newChat,"\u271A");a.addEventListener("click",()=>this.newChat());let l=this.#Ee("collapse",this.#e.collapse,"\u2014");l.addEventListener("click",()=>this.toggleCollapsed()),this.#Me()!==null?o.append(i,s,a):o.append(i,a),this.getAttribute("data-theme-toggle")!==null&&(this.#L.type="button",this.#L.className="header-btn header-btn--theme",this.#L.setAttribute("part","header-button theme-toggle"),this.#L.title=this.#e.toggleTheme,this.#L.setAttribute("aria-label",this.#e.toggleTheme),this.#L.addEventListener("click",()=>this.toggleTheme()),this.#ut(),o.append(this.#L)),o.append(l),e.append(n,r,o),this.#f.className="messages",this.#f.setAttribute("part","messages"),this.#f.setAttribute("role","log"),this.#f.setAttribute("aria-live","off"),this.#f.setAttribute("aria-label",this.#e.conversation),this.#z.className="jump-latest",this.#z.type="button",this.#z.setAttribute("part","jump-latest"),this.#z.textContent=this.#e.jumpToLatest,this.#z.addEventListener("click",()=>{this.#g.jump()}),this.#b.className="quote-selection",this.#b.type="button",this.#b.setAttribute("part","quote-selection"),this.#b.textContent=this.#e.quoteSelection,this.#b.hidden=!0,this.#b.addEventListener("mousedown",h=>{h.preventDefault()}),this.#b.addEventListener("click",()=>{this.quote(this.#_e),window.getSelection()?.removeAllRanges(),this.#Pe()}),this.#f.addEventListener("mouseup",h=>this.#rt(h)),this.#f.addEventListener("keyup",()=>this.#rt()),this.#f.addEventListener("mousedown",()=>this.#Pe()),this.#g=rp({viewport:this.#f,onMissedContent:h=>{this.#z.dataset.missed=String(h)}}),this.#M.className="sr-only",this.#M.setAttribute("role","status"),this.#M.setAttribute("aria-live","polite"),this.#M.setAttribute("aria-atomic","true"),this.#B.className="empty",this.#B.setAttribute("part","empty");let c=document.createElement("slot");c.name="empty",this.#B.append(c),this.#f.append(this.#B);let u=document.createElement("div");u.className="input-row",u.setAttribute("part","composer");let m=document.createElement("div");m.className="composer",m.setAttribute("part","composer-surface");let y=document.createElement("div");y.className="composer-tools",y.setAttribute("part","composer-tools"),this.#l.className="input",this.#l.setAttribute("part","input"),this.#l.setAttribute("aria-label",this.#e.message),this.#l.rows=1,this.#l.placeholder=this.#e.inputPlaceholder,this.#l.addEventListener("keydown",h=>this.#hn(h)),this.#l.addEventListener("input",()=>this.#bt()),this.#w.className="send",this.#w.type="button",this.#w.setAttribute("part","send"),this.#w.append(this.#$e("icon-send","send-send",Jl),this.#$e("icon-stop","send-stop",ec)),this.#w.title=this.#e.send,this.#w.setAttribute("aria-label",this.#e.send),this.#w.dataset.state="idle",this.#w.addEventListener("click",()=>{if(this.#j){this.#F();return}this.#Be()}),this.#R.className="skill-hint",this.#R.setAttribute("part","skill-hint"),this.#R.hidden=!0,this.#A.className="attach-btn",this.#A.type="button",this.#A.setAttribute("part","attach-button"),this.#A.append(this.#$e("icon-attach","attach-glyph",tc)),this.#A.title=this.#e.attachFiles,this.#A.setAttribute("aria-label",this.#e.attachFiles),this.#A.hidden=!0,this.#A.addEventListener("click",()=>this.#k.click()),this.#k.className="attach-input",this.#k.type="file",this.#k.multiple=!0,this.#k.hidden=!0,this.#k.addEventListener("change",()=>this.#qt()),this.#ue.className="attachment-slot",this.#he.className="voice-slot";let f=document.createElement("slot");f.name="footer",y.append(this.#A,this.#he,this.#w),m.append(this.#l,y),u.append(m,this.#k),this.#ce.className="messages-wrap",this.#ce.append(this.#f,this.#z,this.#b),this.#x.append(e,this.#ce,this.#H.palette,this.#H.chips,this.#R,this.#ue,u,f,this.#$.element,this.#E.element),this.#x.addEventListener("pointerdown",h=>{if(!this.#E.open_)return;let g=h.composedPath();g.includes(this.#E.element)||g.includes(s)||this.#E.close()}),this.#C.className="launcher",this.#C.type="button",this.#C.setAttribute("part","launcher"),this.#C.setAttribute("aria-label",this.#e.expand),this.#P.className="launcher-badge",this.#P.setAttribute("part","launcher-badge"),this.#P.setAttribute("aria-hidden","true"),this.#P.hidden=!0,this.#C.append(this.#gt("launcher","launcher-icon",rc,this.#dn()),this.#P),this.#C.addEventListener("click",()=>this.setCollapsed(!1)),this.#x.append(ep({axis:()=>this.#Ue(),anchor:()=>this.#at(),rect:()=>this.getBoundingClientRect(),apply:h=>this.#Fe(h),commit:h=>{this.#Jt(h),this.#He()},label:this.#e.resizePanel})),this.#cn(),this.#_.append(this.#M,this.#x,this.#C)}#ae(e){this.#G!==null&&clearTimeout(this.#G),this.#M.textContent=e,this.#G=setTimeout(()=>{this.#G=null,this.#M.textContent=""},lc)}#cn(){let e=new CSSStyleSheet;e.replaceSync(op),this.#_.adoptedStyleSheets=[e]}#Ee(e,n,r){let o=document.createElement("button");o.type="button",o.className=`header-btn header-btn--${e}`,o.setAttribute("part",`header-button ${e}-button`),o.title=n,o.setAttribute("aria-label",n);let i=document.createElement("slot");return i.name=`icon-${e}`,i.append(document.createTextNode(r)),o.append(i),o}#$e(e,n,r){let o=document.createElement("slot");return o.name=e,o.className=n,o.innerHTML=r,o}#dn(){return this.getAttribute("data-launcher-icon-url")??this.getAttribute("data-icon-url")}#gt(e,n,r,o=this.getAttribute("data-icon-url")){let i=document.createElement("span");i.className="icon-holder",i.setAttribute("part",n);let s=document.createElement("slot");if(s.name=e,o!==null){let a=document.createElement("img");a.className="icon-img",a.src=o,a.alt="",s.append(a)}else r!==null&&(s.innerHTML=r);return i.append(s),i}#vt(){this.#C.setAttribute("aria-expanded",String(!this.collapsed));let e=this.#pe;this.#P.textContent=e>9?"9+":String(e),this.#P.hidden=e===0||!this.#un();let n=this.#P.hidden?this.#e.expand:this.#e.expandUnread.replace("{count}",String(e));this.#C.setAttribute("aria-label",n),this.#C.title=n}#un(){return this.getAttribute("data-unread-badge")!=="false"}#Te(e){this.#pe=e,this.#vt(),this.dispatchEvent(new CustomEvent(bs,{detail:{unread:e},bubbles:!0,composed:!0}))}#pn(){this.collapsed&&this.#Te(this.#pe+1)}#T(){this.#B.hidden=this.#f.childElementCount>1}#bt(){this.#H.onInput(this.#l.value),this.#R.hidden=!0,this.#J()}#hn(e){if(this.#H.onKeydown(e)){e.preventDefault();return}if(e.key==="Escape"&&this.#j){e.preventDefault(),this.#F();return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),this.#Be())}#F(){this.#N?.abort(),this.#V?.cancel()}#X(e){this.#j=e;let n=e?this.#e.stop:this.#e.send;this.#w.title=n,this.#w.setAttribute("aria-label",n),this.#w.dataset.state=e?"running":"idle"}#J(){this.#l.style.height="auto",this.#l.style.height=`${this.#l.scrollHeight}px`}async#Be(){if(this.#j)return;let e=this.#l.value.trim(),n=this.#S?.readyRefs()??[];e===""&&n.length===0||(this.#l.value="",this.#J(),this.#S?.hasPending()===!0&&this.#le("\u{1F4CE}",this.#e.attachmentsStillUploading.replace("{n}",String(this.#S.pendingCount())),"attachment-pending"),this.#S?.clearReady(),await this.sendMessage(e,n))}async sendMessage(e,n=[]){if(this.#j||e===""&&n.length===0)return;let r=this.appendMessage(ze.USER,e);n.length>0&&r.appendChild(Da(n)),this.dispatchEvent(new CustomEvent(gs,{detail:{content:e,attachments:n},bubbles:!0,composed:!0})),await this.#mn(e,n)}attachFile(e){return this.#S===null?!1:(this.#S.add(e),!0)}#fn(e){this.dispatchEvent(new CustomEvent(xs,{detail:{attachments:e.readyRefs(),pending:e.pendingCount()},bubbles:!0,composed:!0}))}async#mn(e,n){this.endpoint!==""&&await this.#Ve().send(e,n)}#Ve(){if(this.#V===null){let e=this.agentFactory({endpoint:this.endpoint,headers:this.#re(),getHeaders:()=>this.#re(),trustedOrigins:this.trustedOrigins,...this.#ye(),threadId:this.#h,initialMessages:this.#Oe,initialState:this.#Z});this.#V=new Bn({agent:e,handlers:this.#wt(),getTools:()=>this.#et(),getContext:()=>this.#ht(),executeTool:n=>this.#yt(n),resolveInterrupts:n=>this.#xt(n),onPersist:n=>this.conversationStore.saveMessages(this.#h,n),onStateChanged:n=>this.#gn(n),connectionLostMessage:this.#e.connectionLost,maxToolRounds:this.#Bt()})}return this.#V}#gn(e){this.#Z={...e},this.dispatchEvent(new CustomEvent(ys,{detail:{state:this.#Z},bubbles:!0,composed:!0}))}#je(e,n={}){let r=this.#Vt(),o=r.has(Lt.COPY),i=n.rateable!==!1&&r.has(Lt.FEEDBACK);(o||i)&&Ga(e,{strings:this.#e,...o?{text:()=>e.textContent}:{},...i?{onFeedback:s=>{this.dispatchEvent(new CustomEvent(_s,{detail:{content:e.textContent,rating:s},bubbles:!0,composed:!0}))}}:{}}),r.has(Lt.RETRY)&&this.#vn(Ni(e,this.#e))}#vn(e){this.#y?.querySelector(".message-action--retry")?.remove();let n=Oi("retry",this.#e.retryMessage,"\u21BB");n.addEventListener("click",()=>{this.retryLastTurn()}),e.prepend(n),this.#y=e}async#bn(e,n){return this.autoConfirm?null:this.confirmPredicate!==null?await this.confirmPredicate(e.name,e.args)===!0?"predicate":null:this.#m.has(e.name)?null:ya(n.parameters)?"destructive":null}async#yt(e){if(bp(e)!==null)return null;let n=this.#Xe(e);this.#i.delete(e.id),this.#d.set(e.id,n.element);let r=this.#s.has(e.name)?this.#Le(e.name):null;if(r===null)return this.#p.has(e.id)||n.settle(te.DONE,this.#e.noResult),null;if(this.getPageMap!==null&&e.name!==ks&&!wi(r.parameters)&&this.#on()){let s=this.#e.pageMoved;return n.settle(te.ERROR,s),this.#ee(),{content:`Error: ${s}`,error:s}}let o=await this.#bn(e,r);if(o!==null){let s={toolName:e.name,args:e.args},a=r.parameters[Wr];typeof a=="string"&&(s.message=a),this.#N=new AbortController;let l=za(this.#I(),s,{signal:this.#N.signal,strings:this.#e,...o==="destructive"?{onAlwaysAllow:()=>this.#m.add(e.name)}:{}});this.#T(),this.#g.follow();let c=await l;if(this.#N=null,n.recordDecision(c?"approved":"declined"),!c){let u=this.#e.declinedAction;return n.settle(te.DECLINED,u),this.#ee(),{content:u}}}let i=wi(r.parameters)&&this.navigate===null;i&&this.conversationStore.saveCheckpoint(this.#h,{toolCallId:e.id});try{let s=await r.handler(e.args,e.id);if(r.render!==void 0&&this.#St(r.render,e),i)return n.settle(te.DONE,this.#e.navigating),{content:"",halt:!0};let a=JSON.stringify(s??null);return n.settle(te.DONE,a),this.#ee(),{content:a}}catch(s){i&&this.conversationStore.saveCheckpoint(this.#h,null);let a=s instanceof Error?s.message:String(s);return n.settle(te.ERROR,a),this.#ee(),{content:`Error: ${a}`,error:a}}}async#xt(e){this.#N=new AbortController,this.#ae(this.#e.announceAwaitingDecision.replace("{count}",String(e.length))),this.#O();let n=this.#N.signal,r=await Promise.all(e.map(async i=>{let s=i.toolCallId!==void 0?this.#i.get(i.toolCallId):void 0,a={},l=ex(i)??i.message;l!==void 0&&(a.message=l);let c=s?.element.getAttribute("data-tool-name");c!=null&&(a.toolName=c);let u,m=this.approveWithEdits&&s!==void 0;m&&(a.args=s.args),s?.mark(te.DEFERRED);let y=this.approvalRenderer!==null?await this.approvalRenderer(a,{signal:n}):await La(s?.approvalSlot??this.#I(),a,{signal:n,strings:this.#e,...m?{onEdit:f=>{u=f}}:{}});return s?.recordDecision(y?"approved":"declined"),y?s?.mark(te.PENDING):s?.settle(te.DECLINED,this.#e.declinedAction),{id:i.id,approved:y,editedArgs:u}}));this.#T(),this.#g.follow(),this.#N=null;let o={};for(let{id:i,approved:s,editedArgs:a}of r)o[i]=s?{status:"resolved",payload:a===void 0?{approved:!0}:{approved:!0,editedArgs:a}}:{status:"cancelled"};return o}#wt(){return{onRunStart:()=>{this.#j||(this.#de=!1,this.#ae(this.#e.announceResponding)),this.#X(!0),this.#I(),this.#ee()},onReasoningStart:()=>{this.#O(),this.#Et()},onReasoningDelta:e=>{this.#Et().stream(e)},onReasoningEnd:()=>{},onTextDelta:e=>{this.#O(),this.#W?.collapse(),this.#Tn(e),this.#Ie+=1},onTextEnd:e=>{let n=this.#qe(e);this.#Ie<=1&&this.#mt(n),Pa(n,this.#e),this.#je(n),this.#te(),this.#pn()},onToolCall:e=>{this.#O(),!this.#_t(e)&&(this.#v.push({id:e.id,name:e.name}),this.#Xe(e))},onActivity:(e,n,r)=>{this.#We(r,e,n)},onCustomEvent:(e,n)=>{if(e===As){this.#xn(n);return}if(e===Zl){this.#wn(n);return}this.dispatchEvent(new CustomEvent(Es,{detail:{name:e,value:n},bubbles:!0,composed:!0}))},onMessagesSnapshot:()=>{this.#le("\u{1F504}",this.#e.historyReplaced,"history-replaced")},onToolResult:(e,n)=>{let r=this.#i.get(e);r!==void 0&&(r.settle(te.DONE,n),this.#p.add(e),this.#ee())},onActivityChanged:(e,n,r)=>{this.#We(e,n,r)},onRunEnd:()=>{this.#O(),this.#te()},onError:e=>{this.#de=!0,this.#ae(this.#e.announceFailed),this.#O();let n=this.appendMessage(ze.ASSISTANT,`\u26A0\uFE0F ${e}`);n.classList.add("message--failed"),this.#je(n,{rateable:!1}),this.#mt(n),this.#te()},onCancelled:()=>{this.#de=!0,this.#ae(this.#e.announceStopped),this.#O(),this.#En(),this.#te()},onSettled:()=>{this.#de||this.#ae(this.#e.announceAnswerReady),this.#O(),this.#X(!1),this.#te();for(let e of this.#i.values())e.settled||e.settle(te.DONE,this.#e.noResult);this.#D!==null&&this.#D.childElementCount===0&&(this.#D.remove(),this.#T()),this.#D=null,this.#W=null,this.#yn()}}}#yn(){let e=this.#v.map(({id:r,name:o})=>({name:o,side:this.#p.has(r)?"server":"client"}));this.#v=[];let n=[...this.#U];this.#U=new Set,this.dispatchEvent(new CustomEvent(ws,{detail:{tools:e,invalidated:n},bubbles:!0,composed:!0}))}#xn(e){let n=e??{},r=Array.isArray(n.keys)?n.keys.filter(o=>typeof o=="string"):[];if(r.length!==0){for(let o of r)this.#U.add(o);this.dispatchEvent(new CustomEvent(Ts,{detail:{keys:r,reason:typeof n.reason=="string"?n.reason:null},bubbles:!0,composed:!0}))}}#wn(e){let n=sp(e);if(n===null)return;let r=this.#i.get(n.delegationId);if(r===void 0)return;let o=this.#o.get(n.delegationId);o===void 0&&(o=new $i(this.#e),this.#o.set(n.delegationId,o),r.subagentSlot.appendChild(o.element)),o.report(n),this.#g.follow()}#En(){let e=document.createElement("div");e.className="stopped-note",e.setAttribute("part","stopped"),e.setAttribute("role","status"),e.textContent=this.#e.stopped,this.#I().appendChild(e),this.#T(),this.#g.follow()}#ee(){if(this.#ge!==null)return;let e=document.createElement("div");e.className="pending",e.setAttribute("part","pending"),e.setAttribute("role","status"),e.setAttribute("aria-label",this.#e.thinking);for(let n=0;n<3;n+=1){let r=document.createElement("span");r.className="pending-dot",e.appendChild(r)}this.#ge=e,this.#I().appendChild(e),this.#T(),this.#g.follow()}#O(){this.#ge?.remove(),this.#ge=null}#Et(){if(this.#W===null){this.#W=new Bi(this.#e);let e=this.#I();e.insertBefore(this.#W.element,e.firstChild),this.#T(),this.#g.follow()}return this.#W}#Tt(){return this.#fe===null&&(this.#fe=this.appendMessage(ze.ASSISTANT,""),this.#Ie=0),this.#fe}#Tn(e){this.#me=e,this.#Tt(),this.#q===null&&(this.#q=requestAnimationFrame(()=>{this.#q=null,this.#qe(this.#me)}))}#qe(e){this.#q!==null&&(cancelAnimationFrame(this.#q),this.#q=null),this.#me=e;let n=this.#Tt();return n.innerHTML=zi(e,{allowImages:this.allowImages}),this.#g.follow(),n}#te(){this.#q!==null&&this.#qe(this.#me),this.#fe=null}#_t(e){let n=bp(e);return n===null?!1:(this.#le("\u2728",this.#e.usingSkill.replace("{name}",n),"skill"),!0)}#le(e,n,r){this.#I().appendChild(pl(e,n,r)),this.#T(),this.#g.follow()}enableCharts(e=["tool","activity"]){let n=!this.#u.has(Xr)&&!this.#r.has(Ri);e.includes("activity")&&this.registerActivityRenderer({type:Xr,render:r=>{let o=Un(r);return o===null?null:gr(o)},removedNotice:this.#e.chartUndrawable}),e.includes("tool")&&this.registerTool(lu()),n&&this.isConnected&&this.reload()}#St(e,n){let r;try{r=e(n.args)}catch(o){console.warn(`ag-ui-chat: render failed for tool ${n.name}`,o);return}r!==null&&(this.#d.get(n.id)?.after(r),this.#At())}registerActivityRenderer(e){this.#u.set(e.type,e),this.#c.delete(e.type)}get unhandledActivityTypes(){return[...this.#c]}#We(e,n,r){let o=this.#u.get(n);if(o===void 0){this.#c.add(n);return}let i;try{i=o.render(r)}catch(a){console.warn(`ag-ui-chat: render failed for activity ${n}`,a),i=null}if(i===null){this.#_n(e,n,o.removedNotice,r);return}let s=this.#a.get(e);s===void 0?this.#I().appendChild(i):s.replaceWith(i),this.#a.set(e,i),this.#At()}#_n(e,n,r,o){let i=this.#a.has(e);this.#a.get(e)?.remove(),this.#a.delete(e),console.warn(`ag-ui-chat: activity ${e} (${n}) was not drawable and has been removed. A chart's points must each be a finite JSON number; a numeric column serialised as a string (a Decimal, typically) is rejected rather than coerced.`,o),i&&r!==void 0&&this.#le("\u{1F4C9}",r,"chart-undrawable")}#At(){this.#T(),this.#g.follow()}#Xe(e){let n=this.#i.get(e.id);if(n!==void 0)return n;let r=this.#Le(e.name)?.parameters[Pe],o=typeof r=="string"?r:this.toolSummaries[e.name]??this.#t[e.name]?.summary??ja(e.name),i=new Cr(e.name,e.args,o,this.#e,{formatPayload:s=>this.formatToolPayload?.(s)??null});return this.#i.set(e.id,i),this.#I().appendChild(i.element),this.#T(),this.#g.follow(),i}};function ex(t){let e=t.metadata?.[Wr];return typeof e=="string"&&e.trim()!==""?e:void 0}function tx(t){return Array.isArray(t)?t.filter(nx):[]}function nx(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.id=="string"&&typeof e.function?.name=="string"}function bp(t){if(t.name!==Rs)return null;let e=t.args?.id;return typeof e=="string"&&e!==""?e:null}function rx(t){let e=t?.removed;return typeof e=="number"?e:null}function ox(){customElements.get(qr)===void 0&&customElements.define(qr,Mr)}async function ix(t,e,n={}){await vt(t),await _a(t,{...n,flashMs:n.flashMs??0}),await Ea(t,e,n)}async function sx(t,e={}){await vt(t),await Ta(t,e)}async function ax(t,e={}){await vt(t),await Sa(t,e)}async function lx(t,e,n={}){await vt(t),await Aa(t,e,n)}async function cx(t,e,n={}){await vt(t),await ka(t,e,n)}function dx(t,e){t instanceof HTMLInputElement&&t.type==="checkbox"?hr(t,!!e):on(t,String(e)),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0}))}var ux="0.31.1";export{xs as ATTACHMENT_EVENT,Mr as AgUiChat,Bn as AgUiClient,Xr as CHART_ACTIVITY_TYPE,Ri as CHART_TOOL_NAME,Is as COMPACTION_ACTIVITY_TYPE,Es as CUSTOM_AGENT_EVENT,br as CheckpointMenu,pr as ClientToolRegistry,qi as ConnectionLostError,ee as DEFAULT_UI_STRINGS,qr as ELEMENT_TAG,_s as FEEDBACK_EVENT,As as INVALIDATE_CUSTOM_NAME,Ts as INVALIDATE_EVENT,Rs as LOAD_CAPABILITY_TOOL,zv as MAX_QUOTE_CHARS,Fy as MAX_SUGGESTIONS,zy as MAX_SUGGESTION_CHARS,bn as MAX_TOOL_ROUNDS,Lt as MESSAGE_ACTIONS,ze as MESSAGE_ROLE,Ca as PAGE_ACTIONS,ws as RUN_FINISHED_EVENT,Nr as RemoteConversationStore,Or as RunIndex,ys as STATE_EVENT,gs as SUBMIT_EVENT,Ss as SUGGESTIONS_ACTIVITY_TYPE,je as SessionStorageStore,vs as TOGGLE_EVENT,te as TOOL_CALL_STATUS,yn as TOOL_DISPLAY,Cr as ToolCallCard,bs as UNREAD_EVENT,ux as VERSION,Wr as X_CONFIRM_KEY,Kn as X_DESTRUCTIVE_KEY,Zn as X_NAVIGATES_KEY,Pe as X_SUMMARY_KEY,$a as asQuote,Ga as attachMessageActions,Va as attachQuoteOffer,Un as chartSpecFrom,sx as clickElement,vl as createHttpAgent,Ia as createPageActionTools,Ra as createPageMapContext,Si as createPageStateTools,Oa as createRouteTools,pv as createStateHookTools,ox as defineAgUiChat,ix as fillField,av as flash,_a as focusWithFlash,Ta as highlightThenClick,ya as isDestructive,wi as isNavigates,Ma as mergeUiStrings,Ni as messageActionBar,ml as messageAttachments,Na as parseToolCatalog,Ti as prefersReducedMotion,ax as pressButton,Sa as pressThenClick,ja as prettifyToolName,yr as quotableSelection,vr as relativeTime,gr as renderChart,zi as renderMarkdown,hl as renderSuggestionChips,La as requestApproval,za as requestConfirmation,qa as requestQuestion,vt as scrollIntoCenterView,lx as selectControl,Aa as selectOption,dx as setControlValue,hr as setNativeChecked,on as setNativeValue,ap as suggestionPrompts,cx as toggleCheckbox,ka as toggleControl,bl as transcribeAudio,Ea as typeInto,yl as uploadAttachment};
|
|
2846
2855
|
/*! Bundled license information:
|
|
2847
2856
|
|
|
2848
2857
|
fast-json-patch/module/helpers.mjs:
|