@artooi/ag-ui-web-component 0.14.0 → 0.14.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 +35 -1
- package/dist/ag-ui-web-component.bundle.js +1 -1
- package/dist/ag-ui-web-component.bundle.js.map +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/ui/render_markdown.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/ui/render_markdown.ts +10 -0
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,39 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.14.1] — 2026-08-07
|
|
11
|
+
|
|
12
|
+
### Security
|
|
13
|
+
|
|
14
|
+
- **Five advisories closed**: `vite` → 7.3.6 (HIGH + MEDIUM), `postcss` → 8.5.26
|
|
15
|
+
(HIGH), `brace-expansion` → 2.1.4 (HIGH), `esbuild` → 0.28.1 (LOW). All four
|
|
16
|
+
are transitive, so they are pinned through `overrides` — there is no direct
|
|
17
|
+
dependency to bump.
|
|
18
|
+
|
|
19
|
+
⚠ **`overrides` now live in `pnpm-workspace.yaml`**, not the `pnpm` field in
|
|
20
|
+
`package.json`; pnpm 11 ignores the latter and only warns. And an override
|
|
21
|
+
must be scoped to its major — an unbounded `brace-expansion: ">=2.1.2"`
|
|
22
|
+
resolves to 5.x, whose export shape `minimatch` cannot call, breaking `glob`
|
|
23
|
+
at runtime.
|
|
24
|
+
|
|
25
|
+
- ⛔ **Four `dompurify` advisories are knowingly left open** (three LOW, one
|
|
26
|
+
MEDIUM), and the dependency is now pinned to **exactly `3.4.7`** rather than
|
|
27
|
+
`^3.4.7`.
|
|
28
|
+
|
|
29
|
+
3.4.8 through 3.4.13 **mis-sanitise under happy-dom**: `<script>` and `<img>`
|
|
30
|
+
pass straight through, which `tests/render_markdown.test.ts` catches. Verified
|
|
31
|
+
again against dompurify 3.4.13 with happy-dom 20.11.1 — moving the test DOM
|
|
32
|
+
forward does not fix it.
|
|
33
|
+
|
|
34
|
+
⭐ **The pin was previously a caret range**, so the hold existed only in the
|
|
35
|
+
lockfile and nowhere in the manifest, undocumented — a `pnpm update` would
|
|
36
|
+
have silently disabled sanitisation. It is now exact, explained at the import
|
|
37
|
+
site in `src/ui/render_markdown.ts`, and recorded in `CLAUDE.md`.
|
|
38
|
+
|
|
39
|
+
The trade is deliberate: those advisories describe narrow bypasses, while
|
|
40
|
+
taking them costs *all* sanitisation under the only DOM the suite can run in.
|
|
41
|
+
`tests/render_markdown.test.ts` is the acceptance check for lifting it.
|
|
42
|
+
|
|
10
43
|
## [0.14.0] — 2026-07-28
|
|
11
44
|
|
|
12
45
|
### Added
|
|
@@ -613,7 +646,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
613
646
|
### Notes
|
|
614
647
|
- First release — exercising the automated npm OIDC publish pipeline end-to-end.
|
|
615
648
|
|
|
616
|
-
[Unreleased]: https://github.com/Artui/ag-ui-web-component/compare/v0.14.
|
|
649
|
+
[Unreleased]: https://github.com/Artui/ag-ui-web-component/compare/v0.14.1...HEAD
|
|
650
|
+
[0.14.1]: https://github.com/Artui/ag-ui-web-component/compare/v0.14.0...v0.14.1
|
|
617
651
|
[0.14.0]: https://github.com/Artui/ag-ui-web-component/compare/v0.13.0...v0.14.0
|
|
618
652
|
[0.13.0]: https://github.com/Artui/ag-ui-web-component/compare/v0.12.0...v0.13.0
|
|
619
653
|
[0.12.0]: https://github.com/Artui/ag-ui-web-component/compare/v0.11.0...v0.12.0
|
|
@@ -1577,7 +1577,7 @@ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error
|
|
|
1577
1577
|
|
|
1578
1578
|
${n}`):(r.textContent=Dg(this.#i)[e],i.textContent=n),r.addEventListener("click",()=>{let o=i.hidden;i.hidden=!o,r.setAttribute("aria-expanded",String(o))}),this.element.append(r,i)}};var fo=class{element;#n;#e;#t;#i="idle";#r=null;#a=null;#s=[];#o=!1;constructor(e){this.#n=e.transcribe,this.#e=e.onText,this.#t=e.strings??ne,this.element=document.createElement("button"),this.element.type="button",this.element.className="voice-btn",this.element.setAttribute("part","voice-button"),this.element.textContent="\u{1F3A4}",this.#f("idle"),this.element.addEventListener("click",()=>{this.toggle()})}async toggle(){if(this.#i==="recording"){this.#c();return}this.#i!=="transcribing"&&await this.#l()}async#l(){let e;try{e=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{this.#h(this.#t.transcriptionFailed);return}this.#a=e,this.#s=[];let n=new MediaRecorder(e);n.addEventListener("dataavailable",r=>{this.#s.push(r.data)}),n.addEventListener("stop",()=>{this.#p(n.mimeType)}),this.#r=n,n.start(),this.#f("recording")}#c(){this.#r?.stop()}dispose(){this.#o=!0,this.#r!==null&&this.#r.state!=="inactive"&&this.#r.stop(),this.#r=null,this.#u()}async#p(e){if(this.#o)return;this.#u(),this.#f("transcribing");let n=new Blob(this.#s,{type:e||"audio/webm"});try{let r=await this.#n(n);this.#f("idle"),r!==""&&this.#e(r)}catch(r){this.#h(r instanceof Error?r.message:this.#t.transcriptionFailed)}finally{this.#r=null}}#u(){for(let e of this.#a?.getTracks()??[])e.stop();this.#a=null}#h(e){this.#u(),this.#r=null,this.#f("idle"),this.element.title=e}#f(e){this.#i=e,this.element.dataset.state=e;let n=this.#k(e);this.element.title=n,this.element.setAttribute("aria-label",n),this.element.setAttribute("aria-pressed",String(e==="recording")),this.element.disabled=e==="transcribing"}#k(e){return e==="recording"?this.#t.stopRecording:e==="transcribing"?this.#t.transcribing:this.#t.recordVoice}};var ho=class extends Error{constructor(e){super(e),this.name="ConnectionLostError"}},Cn=class{#n;#e;#t;#i;#r;#a;#s;#o;#l=!1;constructor(e){this.#n=e.agent,this.#e=e.handlers,this.#t=e.getTools??(()=>[]),this.#i=e.getContext??(()=>[]),this.#r=e.executeTool??null,this.#a=e.resolveInterrupts??null,this.#s=e.onPersist??(()=>{}),this.#o=e.connectionLostMessage??"Connection lost";let n=e.onStateChanged;n!==void 0&&this.#n.subscribe({onStateChanged:({state:r})=>{n(r)}})}get state(){return this.#n.state}setState(e){this.#n.setState({...e})}get running(){return this.#n.isRunning}get messages(){return this.#n.messages}async send(e,n=[]){let r={id:Oe(),role:"user",content:e};n.length>0&&(r.attachments=n),this.#n.addMessage(r),this.#s(this.#n.messages),await this.#c()}async resume(){await this.#c()}addToolResult(e,n){this.#n.addMessage({id:Oe(),role:"tool",content:n,toolCallId:e}),this.#s(this.#n.messages)}cancel(){this.#l=!0,this.#n.abortRun()}async#c(){this.#l=!1;try{await this.#u(),this.#l&&this.#p()}catch(e){this.#l||Ug(e)?this.#p():this.#e.onError(e instanceof Error?e.message:String(e))}finally{this.#e.onSettled()}}#p(){this.#s(this.#n.messages),this.#e.onCancelled()}async#u(){let e;for(let n=0;n<Uo;n+=1){if(this.#l)return;let r=[],i={terminal:!1,errored:!1,interrupts:[]},o={tools:this.#t(),context:this.#i()};if(e!==void 0&&(o.resume=e),await this.#n.runAgent(o,this.#h(r,i)),e=void 0,this.#s(this.#n.messages),this.#l)return;if(!i.terminal)throw new ho(this.#o);if(i.errored)return;if(i.interrupts.length>0){if(this.#a===null)return;let a=await this.#a(i.interrupts);if(this.#l)return;e=zc(i.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.#n.addMessage({id:Oe(),role:"tool",content:l.content,toolCallId:a.id}),this.#s(this.#n.messages),s=!0}}if(!s)return}}#h(e,n){let r=this.#e;return{onRunInitialized(){r.onRunStart()},onTextMessageContentEvent({textMessageBuffer:i}){r.onTextDelta(i)},onTextMessageEndEvent({textMessageBuffer:i}){r.onTextEnd(i)},onToolCallEndEvent({event:i,toolCallName:o,toolCallArgs:s}){let a={id:i.toolCallId,name:o,args:s};e.push(a),r.onToolCall(a)},onToolCallResultEvent({event:i}){r.onToolResult(i.toolCallId,i.content)},onActivitySnapshotEvent({event:i}){r.onActivity(i.activityType,i.content)},onReasoningStartEvent(){r.onReasoningStart()},onReasoningMessageContentEvent({reasoningMessageBuffer:i}){r.onReasoningDelta(i)},onReasoningEndEvent(){r.onReasoningEnd()},onRunFinishedEvent(i){n.terminal=!0,i.outcome==="interrupt"&&(n.interrupts=i.interrupts)},onRunErrorEvent({event:i}){n.terminal=!0,n.errored=!0,r.onError(i.message)},onRunFinalized(){n.terminal=!0,r.onRunEnd()}}}};function Ug(t){return t instanceof Error&&t.name==="AbortError"}function ga(t){let e=t.attachments;return Array.isArray(e)?e.filter(Hg):[]}function Hg(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 va="ag-ui-chat",lr="thread",ba="threads",mo="messages:",go="checkpoint:",Gg=60,Fg=100,$g="New conversation",ht=class{#n;constructor(e=""){this.#n=e===""?va:`${va}@${e}`,e!==""&&this.#a()}threadId(){let e=this.#r(lr),n=sessionStorage.getItem(e);if(n!==null)return n;let r=Oe();return sessionStorage.setItem(e,r),r}loadMessages(e){return Promise.resolve(this.#s(this.#r(mo+e)))}saveMessages(e,n){sessionStorage.setItem(this.#r(mo+e),JSON.stringify(n)),this.#e(e,n)}loadCheckpoint(e){return this.#s(this.#r(go+e))}saveCheckpoint(e,n){let r=this.#r(go+e);if(n===null){sessionStorage.removeItem(r);return}sessionStorage.setItem(r,JSON.stringify(n))}clear(e){sessionStorage.removeItem(this.#r(mo+e)),sessionStorage.removeItem(this.#r(go+e)),this.#i(this.#t().filter(n=>n.threadId!==e)),sessionStorage.getItem(this.#r(lr))===e&&sessionStorage.removeItem(this.#r(lr))}listThreads(){let e=this.#t().sort((n,r)=>r.updatedAt-n.updatedAt).map(({threadId:n,title:r,updatedAt:i,preview:o})=>({threadId:n,title:r,updatedAt:i,preview:o}));return Promise.resolve(e)}setActiveThread(e){sessionStorage.setItem(this.#r(lr),e)}renameThread(e,n){let r=this.#t(),i=r.find(o=>o.threadId===e);i!==void 0&&(i.title=n,i.titleCustom=!0,this.#i(r))}#e(e,n){let r=this.#t(),i=r.find(a=>a.threadId===e),o=Bg(n),s=Date.now();i===void 0?r.push({threadId:e,title:Ou(n),titleCustom:!1,preview:o,updatedAt:s}):(i.preview=o,i.updatedAt=s,i.titleCustom||(i.title=Ou(n))),this.#i(r)}#t(){return this.#s(this.#r(ba))??[]}#i(e){let n=this.#r(ba);if(e.length===0){sessionStorage.removeItem(n);return}sessionStorage.setItem(n,JSON.stringify(e))}#r(e){return`${this.#n}:${e}`}#a(){let e=`${va}:`,n=[];for(let r=0;r<sessionStorage.length;r+=1){let i=sessionStorage.key(r);if(i===null||!i.startsWith(e))continue;let o=i.slice(e.length);zg(o)&&n.push([i,this.#r(o)])}for(let[r,i]of n){let o=sessionStorage.getItem(r);o!==null&&sessionStorage.getItem(i)===null&&sessionStorage.setItem(i,o),sessionStorage.removeItem(r)}}#s(e){let n=sessionStorage.getItem(e);if(n===null)return null;try{return JSON.parse(n)}catch{return null}}};function zg(t){return t===lr||t===ba||t.startsWith(mo)||t.startsWith(go)}function Ou(t){for(let e of t)if(e.role==="user"){let n=Mu(e.content);if(n!=="")return Lu(n,Gg)}return $g}function Bg(t){for(let e of[...t].reverse()){let n=Mu(e.content);if(n!=="")return Lu(n,Fg)}return""}function Mu(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():""}function Lu(t,e){return t.length<=e?t:`${t.slice(0,e-1).trimEnd()}\u2026`}function ya(t){return new Bc({url:t.endpoint,headers:t.headers??{},initialState:{...t.initialState??{}},fetch:(e,n)=>{let r=t.getHeaders?.();if(r===void 0)return fetch(e,n);let i=new Headers(n?.headers);for(let[o,s]of Object.entries(r))i.set(o,s);return fetch(e,{...n,headers:i})},...t.threadId!==void 0?{threadId:t.threadId}:{},...t.initialMessages!==void 0?{initialMessages:[...t.initialMessages]}:{}})}var cr=class{#n;#e;#t;#i=new Set;#r=new Map;constructor(e,n=()=>({}),r=new ht){this.#n=e.endsWith("/")?e:`${e}/`,this.#e=n,this.#t=r}threadId(){return this.#t.threadId()}setActiveThread(e){this.#t.setActiveThread(e)}saveMessages(e,n){this.#t.saveMessages(e,n)}loadCheckpoint(e){return this.#t.loadCheckpoint(e)}saveCheckpoint(e,n){this.#t.saveCheckpoint(e,n)}renameThread(e,n){this.#t.renameThread(e,n),this.#r.set(e,n),this.#c(e,"PATCH",{title:n})}clear(e){this.#t.clear(e),this.#i.add(e),this.#c(e,"DELETE")}async listThreads(){let e=await this.#a();return e===null?this.#t.listThreads():e.filter(n=>!this.#i.has(n.thread_id)).map(n=>this.#o(n))}async loadMessages(e){let n=await this.#l(this.#n+encodeURIComponent(e)+"/");if(n===null||!n.ok)return this.#t.loadMessages(e);let r=await this.#s(n);return r===null?this.#t.loadMessages(e):r.messages??null}async#a(){let e=await this.#l(this.#n);if(e===null||!e.ok)return null;let n=await this.#s(e);return n===null?null:n.threads??[]}async#s(e){try{return await e.json()}catch{return null}}#o(e){return{threadId:e.thread_id,title:this.#r.get(e.thread_id)??e.title,updatedAt:e.updated_at===null?Number.NaN:Date.parse(e.updated_at),preview:e.preview}}async#l(e){try{return await fetch(e,{headers:this.#e()})}catch{return null}}async#c(e,n,r){let i=this.#e();try{await fetch(this.#n+encodeURIComponent(e)+"/",{method:n,headers:r===void 0?i:{...i,"content-type":"application/json"},body:r===void 0?null:JSON.stringify(r)})}catch{}}};var ur=class{#n;#e;constructor(e,n=()=>({})){this.#n=e.endsWith("/")?e:`${e}/`,this.#e=n}async list(){try{let e=await fetch(this.#n,{method:"GET",headers:{Accept:"application/json",...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.#t("resume",e)}forkUrl(e){return this.#t("fork",e)}#t(e,n){return`${this.#n.slice(0,-5)}${e}/${encodeURIComponent(n)}/`}};async function xa(t,e){let n=new FormData;n.append("audio",t,"recording.webm");let r=await fetch(e.url,{method:"POST",headers:{...e.headers??{}},body:n});if(!r.ok)throw new Error(await Vg(r));let i=await r.json();if(typeof i=="object"&&i!==null&&typeof i.text=="string")return i.text;throw new Error("transcription returned an unreadable response")}async function Vg(t){try{let e=await t.json();if(typeof e.error=="string")return e.error}catch{}return`transcription failed (${t.status})`}function Ea(t,e){return new Promise((n,r)=>{let i=new FormData;i.append("file",t);let o=new XMLHttpRequest;o.open("POST",e.url);for(let[l,c]of Object.entries(e.headers??{}))o.setRequestHeader(l,c);let s=e.onProgress;s!==void 0&&o.upload.addEventListener("progress",l=>{l.lengthComputable&&s(l.total===0?0:l.loaded/l.total)}),o.addEventListener("load",()=>{if(o.status>=200&&o.status<300)try{n(jg(JSON.parse(o.responseText)))}catch{r(new Error("upload returned an unreadable response"))}else r(new Error(Wg(o)))}),o.addEventListener("error",()=>r(new Error("upload failed"))),o.addEventListener("abort",()=>r(new Error("upload cancelled")));let a=e.signal;a!==void 0&&a.addEventListener("abort",()=>o.abort()),o.send(i)})}function jg(t){if(typeof t!="object"||t===null)throw new Error("not an object");let e=t,n=e.id,r=e.name,i=e.mime,o=e.size,s=e.url;if(typeof n!="string"||typeof r!="string"||typeof i!="string"||typeof o!="number")throw new Error("missing fields");return typeof s=="string"?{id:n,name:r,mime:i,size:o,url:s}:{id:n,name:r,mime:i,size:o}}function Wg(t){try{let e=JSON.parse(t.responseText);if(typeof e.error=="string")return e.error}catch{}return`upload failed (${t.status})`}var Pu="ag-ui-chat:collapsed",Du="ag-ui-chat:theme",dr=class extends HTMLElement{agentFactory=ya;headers={};allowImages=!1;autoConfirm=!1;askUser=!1;askUserRenderer=null;approvalRenderer=null;confirmPredicate=null;getTools=()=>[...this.#ne().map(e=>({name:e.name,description:e.description,parameters:e.parameters})),...this.#t.tools()];getContext=()=>[...Qo(this.getPageMap,this.autoInjectPageMap),...this.#Pe()];routeMap=[];navigate=null;getPageMap=null;autoInjectPageMap=!0;conversationStore=new ht;uploadHandler=null;transcribeHandler=null;navigationResult=()=>({navigated:!0,url:window.location.href});skillContext=()=>({});toolSummaries={};strings={};resolvePageTarget=e=>document.querySelector(e);#n={};#e=ne;#t=new Un;#i=new Map;#r=new Set;#a;#s;#o;#l;#c;#p;#u;#h;#f;#k=null;#E;#g;#v;#D;#T;#w;#I;#A=null;#U;#B=null;#L=[];#C=null;#R={};#H=!1;#b=null;#y=null;#V=0;#G=null;#S=null;#N=null;#d="";#O="";#j=0;#W=[];#Q=[];#ee=[];#te=[];constructor(){super(),this.#a=this.attachShadow({mode:"open"}),this.#s=document.createElement("div"),this.#o=document.createElement("div"),this.#l=document.createElement("textarea"),this.#c=document.createElement("button"),this.#p=document.createElement("span"),this.#E=document.createElement("div"),this.#g=document.createElement("button"),this.#v=document.createElement("input"),this.#D=document.createElement("div"),this.#U=document.createElement("span"),this.#T=document.createElement("button"),this.#w=document.createElement("button"),this.#I=document.createElement("div"),this.#u=new co(e=>this.#$e(e)),this.#h=new po({onSelect:e=>{this.#ze(e)},onNew:()=>{this.newChat(),this.#F()},onRename:(e,n)=>{this.conversationStore.renameThread(e,n),this.#F()},onDelete:e=>{this.#Be(e)}}),this.#f=new er((e,n)=>{this.#ye(e,n)})}#q(){let e=this.getAttribute("data-runs-url");return e===null||e===""?null:(this.#k===null&&(this.#k=new ur(e,()=>this.headers)),this.#k)}async#ye(e,n){let r=this.#q();if(r===null)return;let i=this.#l.value.trim();if(i==="")return;this.#l.value="";let o=n==="resume"?r.resumeUrl(e):r.forkUrl(e),s=this.agentFactory({endpoint:o,headers:this.headers,getHeaders:()=>this.headers,threadId:this.#d,initialMessages:[]});await new Cn({agent:s,handlers:this.#he(),getTools:()=>this.getTools(),getContext:()=>this.getContext(),executeTool:l=>this.#pe(l),resolveInterrupts:l=>this.#fe(l),connectionLostMessage:this.#e.connectionLost}).send(i)}async#xe(){let e=this.#q();this.#f.setRuns(e===null?[]:await e.continuable())}static get observedAttributes(){return["title-text"]}attributeChangedCallback(e,n,r){this.#p.textContent=r??this.#e.title}registerTool(e){this.#t.register(e)}get sharedState(){return this.#C?.state??this.#R}set sharedState(e){this.#R={...e},this.#C?.setState(this.#R)}registerPageState(e){for(let n of Ar(e))this.#t.register(n)}registerStateHook(e){this.registerPageState(e)}#Ee(){return this.routeMap.length===0?[]:ts(()=>this.routeMap,()=>this.navigate)}#Te(){let e=this.getPageMap;return e===null?[]:[{name:"read_page",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:[],[Ne]:"Read the page"},handler:()=>e()}]}#we(){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 Jo(n,r=>this.resolvePageTarget(r))}#ne(){return[...this.#Ee(),...this.#Te(),...this.#we(),...this.#Se()]}#Se(){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.#_e(e)}]:[]}async#_e(e){let r={question:typeof e.question=="string"?e.question:""},i=e.options;Array.isArray(i)&&(r.options=i.filter(a=>typeof a=="string")),e.allow_custom===!0&&(r.allowCustom=!0),this.#b=new AbortController;let o=this.#b.signal;this.#x();let s=this.askUserRenderer!==null?await this.askUserRenderer(r,{signal:o}):await Ys(this.#_(),r,{signal:o,strings:this.#e});return this.#b=null,this.#m(),this.#o.scrollTop=this.#o.scrollHeight,s}#re(e){let n=this.#ne().find(r=>r.name===e);return n!==void 0?n:this.#t.has(e)?this.#t.get(e):null}get endpoint(){return this.getAttribute("endpoint")??""}set endpoint(e){this.setAttribute("endpoint",e)}get toolDisplay(){let e=this.getAttribute("data-tool-display");return e===ze.INLINE||e===ze.MINIMAL||e===ze.COMPACT?e:ze.FULL}set toolDisplay(e){this.setAttribute("data-tool-display",e)}connectedCallback(){if(this.#O=this.id!==""?this.id:this.endpoint,this.#e=ns({...this.#Ae(),...this.strings}),this.getAttribute("data-theme-toggle")!==null){let e=this.#ie(Du);e!==null&&this.setAttribute("theme",e)}this.#qe(),this.#h.setStrings(this.#e),this.#f.setStrings(this.#e),this.#ie(Pu)==="1"&&this.setAttribute("collapsed",""),this.#ce(),this.#He(),this.#Ue(),this.#O!==""&&this.conversationStore instanceof ht&&(this.conversationStore=new ht(this.#O)),this.#De(),this.#ke(),this.#Ce(),this.#d=this.conversationStore.threadId(),this.#se()}disconnectedCallback(){this.#M(),this.#A?.dispose(),this.#B?.dispose()}#Ae(){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{}}#ke(){let e=this.getAttribute("data-attachments-url"),n=this.uploadHandler??this.#Ie(e);if(n===null)return;let r=this.getAttribute("data-attachment-accept")??"";this.#A=new Qi({upload:n,maxBytes:this.#Oe(),accept:r,strings:this.#e}),this.#D.appendChild(this.#A.element),this.#v.accept=r,this.#g.hidden=!1,this.#Le()}#Ie(e){return e===null?null:(n,r,i)=>Ea(n,{url:e,headers:this.headers,onProgress:r,signal:i})}#Ce(){let e=this.getAttribute("data-transcribe-url"),n=this.transcribeHandler??this.#Ne(e);n!==null&&(this.#B=new fo({transcribe:n,onText:r=>this.#Re(r),strings:this.#e}),this.#U.appendChild(this.#B.element))}#Ne(e){return e===null?null:n=>xa(n,{url:e,headers:this.headers})}#Re(e){let n=this.#l.value.trim();this.#l.value=n===""?e:`${n} ${e}`,this.#ue(),this.#l.focus()}#Oe(){let e=this.getAttribute("data-attachment-max-bytes");if(e===null)return Ho;let n=Number.parseInt(e,10);return Number.isFinite(n)&&n>=0?n:Ho}#Me(){let e=this.#v.files;if(e!==null)for(let n of Array.from(e))this.#A?.add(n);this.#v.value=""}#Le(){this.#s.addEventListener("dragover",e=>{e.preventDefault(),this.#s.classList.add("chat--dragover")}),this.#s.addEventListener("dragleave",()=>{this.#s.classList.remove("chat--dragover")}),this.#s.addEventListener("drop",e=>{e.preventDefault(),this.#s.classList.remove("chat--dragover");let n=e.dataTransfer?.files;if(n!==void 0)for(let r of Array.from(n))this.#A?.add(r)})}#Pe(){return this.#L.length===0?[]:[{description:"Files the user attached to this message",value:`${this.#L.map(n=>`- ${n.name} (id: ${n.id}, ${n.mime||"unknown type"}, ${n.size} bytes)`).join(`
|
|
1579
1579
|
`)}
|
|
1580
|
-
Use the read_attachment tool with an id to read a file's contents.`}]}#De(){let e=this.getAttribute("data-threads-url");e!==null&&(this.conversationStore=new cr(e,()=>this.headers,this.conversationStore))}async#Ue(){let e=this.getAttribute("data-tools-url");if(e!==null)try{let n=await fetch(e,{headers:this.headers});this.#n=es(await n.json())}catch{}}setSkills(e){this.#te=e,this.#X()}#He(){this.#u.enableChips(this.getAttribute("data-prompt-chips")==="true"),this.#u.enableSlash(this.getAttribute("data-slash-commands")==="true"),this.#ee=this.#Ge(),this.#X(),this.#Fe()}#Ge(){let e=this.getAttribute("data-skills");if(e===null)return[];try{return $o(JSON.parse(e))}catch{return[]}}async#Fe(){let e=this.getAttribute("data-skills-url");if(e!==null)try{let n=await fetch(e,{headers:this.headers});this.#Q=$o(await n.json()),this.#X()}catch{}}#X(){let e=new Map;for(let n of[...this.#Q,...this.#ee,...this.#te])e.set(n.name,n);this.#u.setSkills([...e.values()])}#$e(e){let{text:n,missing:r}=Wa(e.prompt,this.skillContext());if(r.length>0){this.#E.textContent=this.#e.skillNeeds.replace("{title}",e.title).replace("{fields}",r.join(", ")),this.#E.hidden=!1;return}this.#E.hidden=!0,this.#l.value=n,e.sendImmediately===!0?this.#Z():this.#l.focus()}get collapsed(){return this.hasAttribute("collapsed")}set collapsed(e){this.setCollapsed(e)}setCollapsed(e){e?this.setAttribute("collapsed",""):this.removeAttribute("collapsed"),sessionStorage.setItem(this.#Y(Pu),e?"1":"0"),this.#ce(),this.dispatchEvent(new CustomEvent(Lo,{detail:{collapsed:e},bubbles:!0,composed:!0}))}toggleCollapsed(){this.setCollapsed(!this.collapsed)}toggleTheme(){let e=this.getAttribute("theme")==="dark"?"light":"dark";this.setAttribute("theme",e),sessionStorage.setItem(this.#Y(Du),e),this.#oe()}#Y(e){return this.#O===""?e:`${e}:${this.#O}`}#ie(e){let n=sessionStorage.getItem(this.#Y(e));return n!==null||this.#O===""?n:sessionStorage.getItem(e)}#oe(){let e=this.getAttribute("theme")==="dark";this.#T.textContent=e?"\u2600\uFE0F":"\u{1F319}"}newChat(){this.#M(),this.conversationStore.clear(this.#d),this.#K(),this.#d=this.conversationStore.threadId(),this.#P(!1)}#K(){this.#C=null,this.#y=null,this.#S=null,this.#N=null,this.#x(),this.#i.clear(),this.#r.clear(),this.#W=[],this.#L=[],this.#A?.clear(),this.#o.replaceChildren(this.#I),this.#m()}async#ze(e){e!==this.#d&&(this.#M(),this.#K(),this.conversationStore.setActiveThread(e),this.#d=e,this.#P(!1),await this.#se())}#Be(e){let n=e===this.#d;n&&this.#M(),this.conversationStore.clear(e),n&&(this.#K(),this.#d=this.conversationStore.threadId(),this.#P(!1)),this.#F()}async#F(){this.#h.setThreads(await this.conversationStore.listThreads(),this.#d)}async#se(){this.#j+=1;let e=this.#j,n=await this.conversationStore.loadMessages(this.#d);if(e!==this.#j)return;if(n!==null){this.#W=n;for(let i of n)this.#Ve(i)}let r=this.conversationStore.loadCheckpoint(this.#d);r!==null&&await this.#We(r)}#Ve(e){let n=typeof e.content=="string"?e.content:"";if(e.role===Ze.USER){let r=ga(e);if(n!==""||r.length>0){let i=this.appendMessage(Ze.USER,n);r.length>0&&i.appendChild(is(r))}return}if(e.role===Ze.ASSISTANT){n!==""&&this.appendMessage(Ze.ASSISTANT,n).classList.add("message--restored");let r=e.toolCalls;if(r!==void 0)for(let i of r){let o={id:i.id,name:i.function.name,args:this.#je(i.function.arguments)};this.#ve(o)||this.#J(o)}return}if(e.role==="tool"){let r=this.#i.get(e.toolCallId);r!==void 0&&r.settle(ce.DONE,e.content)}}#je(e){try{let n=JSON.parse(e);if(typeof n=="object"&&n!==null)return n}catch{}return{}}#ae(e){this.getAttribute("data-text-animation")==="word"&&Iu(e)}async#We(e){this.conversationStore.saveCheckpoint(this.#d,null);let n=this.#de();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=lo(n,{allowImages:this.allowImages}),this.#_().appendChild(r)):(this.#S=null,r.textContent=n,this.#o.appendChild(r)),this.#m(),this.#o.scrollTop=this.#o.scrollHeight,r}#_(){if(this.#S===null){let e=document.createElement("div");e.className="answer",e.setAttribute("part","answer"),this.#S=e,this.#o.appendChild(e),this.#m()}return this.#S}#qe(){let e=document.createElement("style");e.textContent=Nu,this.#s.className="chat",this.#s.setAttribute("part","panel");let n=document.createElement("div");n.className="header",n.setAttribute("part","header");let r=this.#p;r.className="header-title",r.setAttribute("part","title"),r.textContent=this.getAttribute("title-text")??this.#e.title,(this.querySelector('[slot="icon"]')!==null||this.getAttribute("data-icon-url")!==null)&&n.append(this.#le("icon","icon",null));let i=document.createElement("slot");i.name="header-actions";let o=document.createElement("div");o.className="header-controls",o.setAttribute("part","header-controls");let s=this.#$("history",this.#e.chatHistory,"\u2630");s.addEventListener("click",()=>{this.#F(),this.#h.open()});let a=this.#$("checkpoints",this.#e.checkpoints,"\u2B6F");a.addEventListener("click",()=>{this.#xe(),this.#f.open()});let l=this.#$("new",this.#e.newChat,"\u271A");l.addEventListener("click",()=>this.newChat());let c=this.#$("collapse",this.#e.collapse,"\u2014");c.addEventListener("click",()=>this.toggleCollapsed()),this.#q()!==null?o.append(s,a,l):o.append(s,l),this.getAttribute("data-theme-toggle")!==null&&(this.#T.type="button",this.#T.className="header-btn header-btn--theme",this.#T.setAttribute("part","header-button theme-toggle"),this.#T.title=this.#e.toggleTheme,this.#T.setAttribute("aria-label",this.#e.toggleTheme),this.#T.addEventListener("click",()=>this.toggleTheme()),this.#oe(),o.append(this.#T)),o.append(c),n.append(r,i,o),this.#o.className="messages",this.#o.setAttribute("part","messages"),this.#o.setAttribute("role","log"),this.#o.setAttribute("aria-live","polite"),this.#o.setAttribute("aria-label",this.#e.conversation),this.#I.className="empty",this.#I.setAttribute("part","empty");let f=document.createElement("slot");f.name="empty",this.#I.append(f),this.#o.append(this.#I);let m=document.createElement("div");m.className="input-row",m.setAttribute("part","composer"),this.#l.className="input",this.#l.setAttribute("part","input"),this.#l.setAttribute("aria-label",this.#e.message),this.#l.rows=2,this.#l.placeholder=this.#e.inputPlaceholder,this.#l.addEventListener("keydown",h=>this.#Xe(h)),this.#l.addEventListener("input",()=>this.#ue()),this.#c.className="send",this.#c.type="button",this.#c.setAttribute("part","send"),this.#c.textContent=this.#e.send,this.#c.setAttribute("aria-label",this.#e.send),this.#c.dataset.state="idle",this.#c.addEventListener("click",()=>{if(this.#H){this.#M();return}this.#Z()}),this.#E.className="skill-hint",this.#E.setAttribute("part","skill-hint"),this.#E.hidden=!0,this.#g.className="attach-btn",this.#g.type="button",this.#g.setAttribute("part","attach-button"),this.#g.textContent="\u{1F4CE}",this.#g.title=this.#e.attachFiles,this.#g.setAttribute("aria-label",this.#e.attachFiles),this.#g.hidden=!0,this.#g.addEventListener("click",()=>this.#v.click()),this.#v.className="attach-input",this.#v.type="file",this.#v.multiple=!0,this.#v.hidden=!0,this.#v.addEventListener("change",()=>this.#Me()),this.#D.className="attachment-slot",this.#U.className="voice-slot";let b=document.createElement("slot");b.name="footer",m.append(this.#g,this.#U,this.#l,this.#c,this.#v),this.#s.append(n,this.#o,this.#u.palette,this.#u.chips,this.#E,this.#D,m,b,this.#h.element,this.#f.element),this.#w.className="rail",this.#w.type="button",this.#w.setAttribute("part","launcher"),this.#w.setAttribute("aria-label",this.#e.expand),this.#w.append(this.#le("launcher","launcher-icon","\u{1F4AC}")),this.#w.addEventListener("click",()=>this.setCollapsed(!1)),this.#a.append(e,this.#s,this.#w)}#$(e,n,r){let i=document.createElement("button");return i.type="button",i.className=`header-btn header-btn--${e}`,i.setAttribute("part",`header-button ${e}-button`),i.title=n,i.setAttribute("aria-label",n),i.textContent=r,i}#le(e,n,r){let i=document.createElement("span");i.className="icon-holder",i.setAttribute("part",n);let o=document.createElement("slot");o.name=e;let s=this.getAttribute("data-icon-url");if(s!==null){let a=document.createElement("img");a.className="icon-img",a.src=s,a.alt="",o.append(a)}else r!==null&&o.append(document.createTextNode(r));return i.append(o),i}#ce(){this.#w.setAttribute("aria-expanded",String(!this.collapsed))}#m(){this.#I.hidden=this.#o.childElementCount>1}#ue(){this.#u.onInput(this.#l.value),this.#E.hidden=!0}#Xe(e){if(this.#u.onKeydown(e)){e.preventDefault();return}if(e.key==="Escape"&&this.#H){e.preventDefault(),this.#M();return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),this.#Z())}#M(){this.#b?.abort(),this.#C?.cancel()}#P(e){this.#H=e;let n=e?this.#e.stop:this.#e.send;this.#c.textContent=n,this.#c.setAttribute("aria-label",n),this.#c.dataset.state=e?"running":"idle"}async#Z(){if(this.#H)return;let e=this.#l.value.trim(),n=this.#A?.readyRefs()??[];if(e===""&&n.length===0)return;let r=this.appendMessage(Ze.USER,e);n.length>0&&r.appendChild(is(n)),this.#l.value="",this.#A?.clearReady(),this.#L=n,this.dispatchEvent(new CustomEvent(Mo,{detail:{content:e,attachments:n},bubbles:!0,composed:!0})),await this.#Ye(e,n)}async#Ye(e,n){this.endpoint!==""&&await this.#de().send(e,n)}#de(){if(this.#C===null){let e=this.agentFactory({endpoint:this.endpoint,headers:this.headers,getHeaders:()=>this.headers,threadId:this.#d,initialMessages:this.#W,initialState:this.#R});this.#C=new Cn({agent:e,handlers:this.#he(),getTools:()=>this.getTools(),getContext:()=>this.getContext(),executeTool:n=>this.#pe(n),resolveInterrupts:n=>this.#fe(n),onPersist:n=>this.conversationStore.saveMessages(this.#d,n),onStateChanged:n=>this.#Ke(n),connectionLostMessage:this.#e.connectionLost})}return this.#C}#Ke(e){this.#R={...e},this.dispatchEvent(new CustomEvent(Po,{detail:{state:this.#R},bubbles:!0,composed:!0}))}async#Ze(e,n){return this.autoConfirm?!1:this.confirmPredicate!==null?await this.confirmPredicate(e.name,e.args)===!0:zo(n.parameters)}async#pe(e){if(Uu(e)!==null)return null;let n=this.#J(e);this.#i.delete(e.id);let r=this.#re(e.name);if(r===null)return this.#r.has(e.id)||n.settle(ce.DONE,this.#e.noResult),null;if(await this.#Ze(e,r)){let o={toolName:e.name,args:e.args},s=r.parameters[Do];typeof s=="string"&&(o.message=s),this.#b=new AbortController;let a=qs(this.#o,o,{signal:this.#b.signal,strings:this.#e});this.#m(),this.#o.scrollTop=this.#o.scrollHeight;let l=await a;if(this.#b=null,!l){let c=this.#e.declinedAction;return n.settle(ce.DECLINED,c),this.#z(),{content:c}}}let i=Bo(r.parameters)&&this.navigate===null;i&&this.conversationStore.saveCheckpoint(this.#d,{toolCallId:e.id});try{let o=await r.handler(e.args);if(i)return n.settle(ce.DONE,this.#e.navigating),{content:"",halt:!0};let s=JSON.stringify(o??null);return n.settle(ce.DONE,s),this.#z(),{content:s}}catch(o){i&&this.conversationStore.saveCheckpoint(this.#d,null);let s=o instanceof Error?o.message:String(o);return n.settle(ce.ERROR,s),this.#z(),{content:`Error: ${s}`,error:s}}}async#fe(e){let n={};this.#b=new AbortController,this.#x();for(let r of e){let i={};r.message!==void 0&&(i.message=r.message);let o=r.toolCallId!==void 0?this.#i.get(r.toolCallId):void 0,s=o?.element.getAttribute("data-tool-name");s!=null&&(i.toolName=s);let a=this.#b.signal,l=this.approvalRenderer!==null?await this.approvalRenderer(i,{signal:a}):await rs(this.#_(),i,{signal:a,strings:this.#e});this.#m(),this.#o.scrollTop=this.#o.scrollHeight,l?n[r.id]={status:"resolved",payload:{approved:!0}}:(n[r.id]={status:"cancelled"},o?.settle(ce.DECLINED,this.#e.declinedAction))}return this.#b=null,n}#he(){return{onRunStart:()=>{this.#P(!0),this.#_(),this.#z()},onReasoningStart:()=>{this.#x(),this.#me()},onReasoningDelta:e=>{this.#me().stream(e)},onReasoningEnd:()=>{},onTextDelta:e=>{this.#x(),this.#N?.collapse(),this.#ge(e),this.#V+=1},onTextEnd:e=>{let n=this.#ge(e);this.#V<=1&&this.#ae(n),this.#y=null},onToolCall:e=>{this.#x(),!this.#ve(e)&&this.#J(e)},onActivity:(e,n)=>{if(e!==Go)return;let r=qg(n);r!==null&&this.#be("\u{1F5DC}",this.#e.historyCompacted.replace("{count}",String(r)),"compaction")},onToolResult:(e,n)=>{let r=this.#i.get(e);r!==void 0&&(r.settle(ce.DONE,n),this.#r.add(e))},onRunEnd:()=>{this.#x(),this.#y=null},onError:e=>{this.#x(),this.#ae(this.appendMessage(Ze.ASSISTANT,`\u26A0\uFE0F ${e}`)),this.#y=null},onCancelled:()=>{this.#x(),this.#Je(),this.#y=null},onSettled:()=>{this.#x(),this.#P(!1),this.#y=null,this.#L=[];for(let e of this.#i.values())e.settled||e.settle(ce.DONE,this.#e.noResult);this.#S!==null&&this.#S.childElementCount===0&&(this.#S.remove(),this.#m()),this.#S=null,this.#N=null}}}#Je(){let e=document.createElement("div");e.className="stopped-note",e.setAttribute("part","stopped"),e.setAttribute("role","status"),e.textContent=this.#e.stopped,this.#_().appendChild(e),this.#m(),this.#o.scrollTop=this.#o.scrollHeight}#z(){if(this.#G!==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.#G=e,this.#_().appendChild(e),this.#m(),this.#o.scrollTop=this.#o.scrollHeight}#x(){this.#G?.remove(),this.#G=null}#me(){if(this.#N===null){this.#N=new uo(this.#e);let e=this.#_();e.insertBefore(this.#N.element,e.firstChild),this.#m(),this.#o.scrollTop=this.#o.scrollHeight}return this.#N}#ge(e){return this.#y===null&&(this.#y=this.appendMessage(Ze.ASSISTANT,""),this.#V=0),this.#y.innerHTML=lo(e,{allowImages:this.allowImages}),this.#o.scrollTop=this.#o.scrollHeight,this.#y}#ve(e){let n=Uu(e);return n===null?!1:(this.#be("\u2728",this.#e.usingSkill.replace("{name}",n),"skill"),!0)}#be(e,n,r){this.#_().appendChild(Cu(e,n,r)),this.#m(),this.#o.scrollTop=this.#o.scrollHeight}#J(e){let n=this.#i.get(e.id);if(n!==void 0)return n;let r=this.#re(e.name)?.parameters[Ne],i=typeof r=="string"?r:this.toolSummaries[e.name]??this.#n[e.name]??Xs(e.name),o=new ar(e.name,e.args,this.toolDisplay,i,this.#e);return this.#i.set(e.id,o),this.#_().appendChild(o.element),this.#m(),this.#o.scrollTop=this.#o.scrollHeight,o}};function Uu(t){if(t.name!==Fo)return null;let e=t.args?.id;return typeof e=="string"&&e!==""?e:null}function qg(t){let e=t?.removed;return typeof e=="number"?e:null}function Xg(){customElements.get(wr)===void 0&&customElements.define(wr,dr)}async function Yg(t,e,n={}){lt(t),await Wo(t,{flashMs:n.flashMs??0}),await Vo(t,e,n)}async function Kg(t,e={}){lt(t),await jo(t,e)}async function Zg(t,e={}){lt(t),await Xo(t,e)}async function Jg(t,e,n={}){lt(t),await Yo(t,e,n)}async function Qg(t,e,n={}){lt(t),await Ko(t,e,n)}function ev(t,e){t instanceof HTMLInputElement&&t.type==="checkbox"?Hn(t,!!e):kt(t,String(e)),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0}))}var tv="0.14.0";export{dr as AgUiChat,Cn as AgUiClient,Go as COMPACTION_ACTIVITY_TYPE,er as CheckpointMenu,Un as ClientToolRegistry,ho as ConnectionLostError,ne as DEFAULT_UI_STRINGS,wr as ELEMENT_TAG,Fo as LOAD_CAPABILITY_TOOL,Uo as MAX_TOOL_ROUNDS,Ze as MESSAGE_ROLE,Zo as PAGE_ACTIONS,cr as RemoteConversationStore,ur as RunIndex,Po as STATE_EVENT,Mo as SUBMIT_EVENT,ht as SessionStorageStore,Lo as TOGGLE_EVENT,ce as TOOL_CALL_STATUS,ze as TOOL_DISPLAY,ar as ToolCallCard,tv as VERSION,Do as X_CONFIRM_KEY,Pn as X_DESTRUCTIVE_KEY,Dn as X_NAVIGATES_KEY,Ne as X_SUMMARY_KEY,Kg as clickElement,ya as createHttpAgent,Jo as createPageActionTools,Qo as createPageMapContext,Ar as createPageStateTools,ts as createRouteTools,cd as createStateHookTools,Xg as defineAgUiChat,Yg as fillField,Wo as focusWithFlash,jo as highlightThenClick,zo as isDestructive,Bo as isNavigates,ns as mergeUiStrings,ga as messageAttachments,es as parseToolCatalog,Ya as prefersReducedMotion,Zg as pressButton,Xo as pressThenClick,Xs as prettifyToolName,lo as renderMarkdown,rs as requestApproval,qs as requestConfirmation,Ys as requestQuestion,lt as scrollIntoCenterView,Jg as selectControl,Yo as selectOption,ev as setControlValue,Hn as setNativeChecked,kt as setNativeValue,Qg as toggleCheckbox,Ko as toggleControl,xa as transcribeAudio,Vo as typeInto,Ea as uploadAttachment};
|
|
1580
|
+
Use the read_attachment tool with an id to read a file's contents.`}]}#De(){let e=this.getAttribute("data-threads-url");e!==null&&(this.conversationStore=new cr(e,()=>this.headers,this.conversationStore))}async#Ue(){let e=this.getAttribute("data-tools-url");if(e!==null)try{let n=await fetch(e,{headers:this.headers});this.#n=es(await n.json())}catch{}}setSkills(e){this.#te=e,this.#X()}#He(){this.#u.enableChips(this.getAttribute("data-prompt-chips")==="true"),this.#u.enableSlash(this.getAttribute("data-slash-commands")==="true"),this.#ee=this.#Ge(),this.#X(),this.#Fe()}#Ge(){let e=this.getAttribute("data-skills");if(e===null)return[];try{return $o(JSON.parse(e))}catch{return[]}}async#Fe(){let e=this.getAttribute("data-skills-url");if(e!==null)try{let n=await fetch(e,{headers:this.headers});this.#Q=$o(await n.json()),this.#X()}catch{}}#X(){let e=new Map;for(let n of[...this.#Q,...this.#ee,...this.#te])e.set(n.name,n);this.#u.setSkills([...e.values()])}#$e(e){let{text:n,missing:r}=Wa(e.prompt,this.skillContext());if(r.length>0){this.#E.textContent=this.#e.skillNeeds.replace("{title}",e.title).replace("{fields}",r.join(", ")),this.#E.hidden=!1;return}this.#E.hidden=!0,this.#l.value=n,e.sendImmediately===!0?this.#Z():this.#l.focus()}get collapsed(){return this.hasAttribute("collapsed")}set collapsed(e){this.setCollapsed(e)}setCollapsed(e){e?this.setAttribute("collapsed",""):this.removeAttribute("collapsed"),sessionStorage.setItem(this.#Y(Pu),e?"1":"0"),this.#ce(),this.dispatchEvent(new CustomEvent(Lo,{detail:{collapsed:e},bubbles:!0,composed:!0}))}toggleCollapsed(){this.setCollapsed(!this.collapsed)}toggleTheme(){let e=this.getAttribute("theme")==="dark"?"light":"dark";this.setAttribute("theme",e),sessionStorage.setItem(this.#Y(Du),e),this.#oe()}#Y(e){return this.#O===""?e:`${e}:${this.#O}`}#ie(e){let n=sessionStorage.getItem(this.#Y(e));return n!==null||this.#O===""?n:sessionStorage.getItem(e)}#oe(){let e=this.getAttribute("theme")==="dark";this.#T.textContent=e?"\u2600\uFE0F":"\u{1F319}"}newChat(){this.#M(),this.conversationStore.clear(this.#d),this.#K(),this.#d=this.conversationStore.threadId(),this.#P(!1)}#K(){this.#C=null,this.#y=null,this.#S=null,this.#N=null,this.#x(),this.#i.clear(),this.#r.clear(),this.#W=[],this.#L=[],this.#A?.clear(),this.#o.replaceChildren(this.#I),this.#m()}async#ze(e){e!==this.#d&&(this.#M(),this.#K(),this.conversationStore.setActiveThread(e),this.#d=e,this.#P(!1),await this.#se())}#Be(e){let n=e===this.#d;n&&this.#M(),this.conversationStore.clear(e),n&&(this.#K(),this.#d=this.conversationStore.threadId(),this.#P(!1)),this.#F()}async#F(){this.#h.setThreads(await this.conversationStore.listThreads(),this.#d)}async#se(){this.#j+=1;let e=this.#j,n=await this.conversationStore.loadMessages(this.#d);if(e!==this.#j)return;if(n!==null){this.#W=n;for(let i of n)this.#Ve(i)}let r=this.conversationStore.loadCheckpoint(this.#d);r!==null&&await this.#We(r)}#Ve(e){let n=typeof e.content=="string"?e.content:"";if(e.role===Ze.USER){let r=ga(e);if(n!==""||r.length>0){let i=this.appendMessage(Ze.USER,n);r.length>0&&i.appendChild(is(r))}return}if(e.role===Ze.ASSISTANT){n!==""&&this.appendMessage(Ze.ASSISTANT,n).classList.add("message--restored");let r=e.toolCalls;if(r!==void 0)for(let i of r){let o={id:i.id,name:i.function.name,args:this.#je(i.function.arguments)};this.#ve(o)||this.#J(o)}return}if(e.role==="tool"){let r=this.#i.get(e.toolCallId);r!==void 0&&r.settle(ce.DONE,e.content)}}#je(e){try{let n=JSON.parse(e);if(typeof n=="object"&&n!==null)return n}catch{}return{}}#ae(e){this.getAttribute("data-text-animation")==="word"&&Iu(e)}async#We(e){this.conversationStore.saveCheckpoint(this.#d,null);let n=this.#de();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=lo(n,{allowImages:this.allowImages}),this.#_().appendChild(r)):(this.#S=null,r.textContent=n,this.#o.appendChild(r)),this.#m(),this.#o.scrollTop=this.#o.scrollHeight,r}#_(){if(this.#S===null){let e=document.createElement("div");e.className="answer",e.setAttribute("part","answer"),this.#S=e,this.#o.appendChild(e),this.#m()}return this.#S}#qe(){let e=document.createElement("style");e.textContent=Nu,this.#s.className="chat",this.#s.setAttribute("part","panel");let n=document.createElement("div");n.className="header",n.setAttribute("part","header");let r=this.#p;r.className="header-title",r.setAttribute("part","title"),r.textContent=this.getAttribute("title-text")??this.#e.title,(this.querySelector('[slot="icon"]')!==null||this.getAttribute("data-icon-url")!==null)&&n.append(this.#le("icon","icon",null));let i=document.createElement("slot");i.name="header-actions";let o=document.createElement("div");o.className="header-controls",o.setAttribute("part","header-controls");let s=this.#$("history",this.#e.chatHistory,"\u2630");s.addEventListener("click",()=>{this.#F(),this.#h.open()});let a=this.#$("checkpoints",this.#e.checkpoints,"\u2B6F");a.addEventListener("click",()=>{this.#xe(),this.#f.open()});let l=this.#$("new",this.#e.newChat,"\u271A");l.addEventListener("click",()=>this.newChat());let c=this.#$("collapse",this.#e.collapse,"\u2014");c.addEventListener("click",()=>this.toggleCollapsed()),this.#q()!==null?o.append(s,a,l):o.append(s,l),this.getAttribute("data-theme-toggle")!==null&&(this.#T.type="button",this.#T.className="header-btn header-btn--theme",this.#T.setAttribute("part","header-button theme-toggle"),this.#T.title=this.#e.toggleTheme,this.#T.setAttribute("aria-label",this.#e.toggleTheme),this.#T.addEventListener("click",()=>this.toggleTheme()),this.#oe(),o.append(this.#T)),o.append(c),n.append(r,i,o),this.#o.className="messages",this.#o.setAttribute("part","messages"),this.#o.setAttribute("role","log"),this.#o.setAttribute("aria-live","polite"),this.#o.setAttribute("aria-label",this.#e.conversation),this.#I.className="empty",this.#I.setAttribute("part","empty");let f=document.createElement("slot");f.name="empty",this.#I.append(f),this.#o.append(this.#I);let m=document.createElement("div");m.className="input-row",m.setAttribute("part","composer"),this.#l.className="input",this.#l.setAttribute("part","input"),this.#l.setAttribute("aria-label",this.#e.message),this.#l.rows=2,this.#l.placeholder=this.#e.inputPlaceholder,this.#l.addEventListener("keydown",h=>this.#Xe(h)),this.#l.addEventListener("input",()=>this.#ue()),this.#c.className="send",this.#c.type="button",this.#c.setAttribute("part","send"),this.#c.textContent=this.#e.send,this.#c.setAttribute("aria-label",this.#e.send),this.#c.dataset.state="idle",this.#c.addEventListener("click",()=>{if(this.#H){this.#M();return}this.#Z()}),this.#E.className="skill-hint",this.#E.setAttribute("part","skill-hint"),this.#E.hidden=!0,this.#g.className="attach-btn",this.#g.type="button",this.#g.setAttribute("part","attach-button"),this.#g.textContent="\u{1F4CE}",this.#g.title=this.#e.attachFiles,this.#g.setAttribute("aria-label",this.#e.attachFiles),this.#g.hidden=!0,this.#g.addEventListener("click",()=>this.#v.click()),this.#v.className="attach-input",this.#v.type="file",this.#v.multiple=!0,this.#v.hidden=!0,this.#v.addEventListener("change",()=>this.#Me()),this.#D.className="attachment-slot",this.#U.className="voice-slot";let b=document.createElement("slot");b.name="footer",m.append(this.#g,this.#U,this.#l,this.#c,this.#v),this.#s.append(n,this.#o,this.#u.palette,this.#u.chips,this.#E,this.#D,m,b,this.#h.element,this.#f.element),this.#w.className="rail",this.#w.type="button",this.#w.setAttribute("part","launcher"),this.#w.setAttribute("aria-label",this.#e.expand),this.#w.append(this.#le("launcher","launcher-icon","\u{1F4AC}")),this.#w.addEventListener("click",()=>this.setCollapsed(!1)),this.#a.append(e,this.#s,this.#w)}#$(e,n,r){let i=document.createElement("button");return i.type="button",i.className=`header-btn header-btn--${e}`,i.setAttribute("part",`header-button ${e}-button`),i.title=n,i.setAttribute("aria-label",n),i.textContent=r,i}#le(e,n,r){let i=document.createElement("span");i.className="icon-holder",i.setAttribute("part",n);let o=document.createElement("slot");o.name=e;let s=this.getAttribute("data-icon-url");if(s!==null){let a=document.createElement("img");a.className="icon-img",a.src=s,a.alt="",o.append(a)}else r!==null&&o.append(document.createTextNode(r));return i.append(o),i}#ce(){this.#w.setAttribute("aria-expanded",String(!this.collapsed))}#m(){this.#I.hidden=this.#o.childElementCount>1}#ue(){this.#u.onInput(this.#l.value),this.#E.hidden=!0}#Xe(e){if(this.#u.onKeydown(e)){e.preventDefault();return}if(e.key==="Escape"&&this.#H){e.preventDefault(),this.#M();return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),this.#Z())}#M(){this.#b?.abort(),this.#C?.cancel()}#P(e){this.#H=e;let n=e?this.#e.stop:this.#e.send;this.#c.textContent=n,this.#c.setAttribute("aria-label",n),this.#c.dataset.state=e?"running":"idle"}async#Z(){if(this.#H)return;let e=this.#l.value.trim(),n=this.#A?.readyRefs()??[];if(e===""&&n.length===0)return;let r=this.appendMessage(Ze.USER,e);n.length>0&&r.appendChild(is(n)),this.#l.value="",this.#A?.clearReady(),this.#L=n,this.dispatchEvent(new CustomEvent(Mo,{detail:{content:e,attachments:n},bubbles:!0,composed:!0})),await this.#Ye(e,n)}async#Ye(e,n){this.endpoint!==""&&await this.#de().send(e,n)}#de(){if(this.#C===null){let e=this.agentFactory({endpoint:this.endpoint,headers:this.headers,getHeaders:()=>this.headers,threadId:this.#d,initialMessages:this.#W,initialState:this.#R});this.#C=new Cn({agent:e,handlers:this.#he(),getTools:()=>this.getTools(),getContext:()=>this.getContext(),executeTool:n=>this.#pe(n),resolveInterrupts:n=>this.#fe(n),onPersist:n=>this.conversationStore.saveMessages(this.#d,n),onStateChanged:n=>this.#Ke(n),connectionLostMessage:this.#e.connectionLost})}return this.#C}#Ke(e){this.#R={...e},this.dispatchEvent(new CustomEvent(Po,{detail:{state:this.#R},bubbles:!0,composed:!0}))}async#Ze(e,n){return this.autoConfirm?!1:this.confirmPredicate!==null?await this.confirmPredicate(e.name,e.args)===!0:zo(n.parameters)}async#pe(e){if(Uu(e)!==null)return null;let n=this.#J(e);this.#i.delete(e.id);let r=this.#re(e.name);if(r===null)return this.#r.has(e.id)||n.settle(ce.DONE,this.#e.noResult),null;if(await this.#Ze(e,r)){let o={toolName:e.name,args:e.args},s=r.parameters[Do];typeof s=="string"&&(o.message=s),this.#b=new AbortController;let a=qs(this.#o,o,{signal:this.#b.signal,strings:this.#e});this.#m(),this.#o.scrollTop=this.#o.scrollHeight;let l=await a;if(this.#b=null,!l){let c=this.#e.declinedAction;return n.settle(ce.DECLINED,c),this.#z(),{content:c}}}let i=Bo(r.parameters)&&this.navigate===null;i&&this.conversationStore.saveCheckpoint(this.#d,{toolCallId:e.id});try{let o=await r.handler(e.args);if(i)return n.settle(ce.DONE,this.#e.navigating),{content:"",halt:!0};let s=JSON.stringify(o??null);return n.settle(ce.DONE,s),this.#z(),{content:s}}catch(o){i&&this.conversationStore.saveCheckpoint(this.#d,null);let s=o instanceof Error?o.message:String(o);return n.settle(ce.ERROR,s),this.#z(),{content:`Error: ${s}`,error:s}}}async#fe(e){let n={};this.#b=new AbortController,this.#x();for(let r of e){let i={};r.message!==void 0&&(i.message=r.message);let o=r.toolCallId!==void 0?this.#i.get(r.toolCallId):void 0,s=o?.element.getAttribute("data-tool-name");s!=null&&(i.toolName=s);let a=this.#b.signal,l=this.approvalRenderer!==null?await this.approvalRenderer(i,{signal:a}):await rs(this.#_(),i,{signal:a,strings:this.#e});this.#m(),this.#o.scrollTop=this.#o.scrollHeight,l?n[r.id]={status:"resolved",payload:{approved:!0}}:(n[r.id]={status:"cancelled"},o?.settle(ce.DECLINED,this.#e.declinedAction))}return this.#b=null,n}#he(){return{onRunStart:()=>{this.#P(!0),this.#_(),this.#z()},onReasoningStart:()=>{this.#x(),this.#me()},onReasoningDelta:e=>{this.#me().stream(e)},onReasoningEnd:()=>{},onTextDelta:e=>{this.#x(),this.#N?.collapse(),this.#ge(e),this.#V+=1},onTextEnd:e=>{let n=this.#ge(e);this.#V<=1&&this.#ae(n),this.#y=null},onToolCall:e=>{this.#x(),!this.#ve(e)&&this.#J(e)},onActivity:(e,n)=>{if(e!==Go)return;let r=qg(n);r!==null&&this.#be("\u{1F5DC}",this.#e.historyCompacted.replace("{count}",String(r)),"compaction")},onToolResult:(e,n)=>{let r=this.#i.get(e);r!==void 0&&(r.settle(ce.DONE,n),this.#r.add(e))},onRunEnd:()=>{this.#x(),this.#y=null},onError:e=>{this.#x(),this.#ae(this.appendMessage(Ze.ASSISTANT,`\u26A0\uFE0F ${e}`)),this.#y=null},onCancelled:()=>{this.#x(),this.#Je(),this.#y=null},onSettled:()=>{this.#x(),this.#P(!1),this.#y=null,this.#L=[];for(let e of this.#i.values())e.settled||e.settle(ce.DONE,this.#e.noResult);this.#S!==null&&this.#S.childElementCount===0&&(this.#S.remove(),this.#m()),this.#S=null,this.#N=null}}}#Je(){let e=document.createElement("div");e.className="stopped-note",e.setAttribute("part","stopped"),e.setAttribute("role","status"),e.textContent=this.#e.stopped,this.#_().appendChild(e),this.#m(),this.#o.scrollTop=this.#o.scrollHeight}#z(){if(this.#G!==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.#G=e,this.#_().appendChild(e),this.#m(),this.#o.scrollTop=this.#o.scrollHeight}#x(){this.#G?.remove(),this.#G=null}#me(){if(this.#N===null){this.#N=new uo(this.#e);let e=this.#_();e.insertBefore(this.#N.element,e.firstChild),this.#m(),this.#o.scrollTop=this.#o.scrollHeight}return this.#N}#ge(e){return this.#y===null&&(this.#y=this.appendMessage(Ze.ASSISTANT,""),this.#V=0),this.#y.innerHTML=lo(e,{allowImages:this.allowImages}),this.#o.scrollTop=this.#o.scrollHeight,this.#y}#ve(e){let n=Uu(e);return n===null?!1:(this.#be("\u2728",this.#e.usingSkill.replace("{name}",n),"skill"),!0)}#be(e,n,r){this.#_().appendChild(Cu(e,n,r)),this.#m(),this.#o.scrollTop=this.#o.scrollHeight}#J(e){let n=this.#i.get(e.id);if(n!==void 0)return n;let r=this.#re(e.name)?.parameters[Ne],i=typeof r=="string"?r:this.toolSummaries[e.name]??this.#n[e.name]??Xs(e.name),o=new ar(e.name,e.args,this.toolDisplay,i,this.#e);return this.#i.set(e.id,o),this.#_().appendChild(o.element),this.#m(),this.#o.scrollTop=this.#o.scrollHeight,o}};function Uu(t){if(t.name!==Fo)return null;let e=t.args?.id;return typeof e=="string"&&e!==""?e:null}function qg(t){let e=t?.removed;return typeof e=="number"?e:null}function Xg(){customElements.get(wr)===void 0&&customElements.define(wr,dr)}async function Yg(t,e,n={}){lt(t),await Wo(t,{flashMs:n.flashMs??0}),await Vo(t,e,n)}async function Kg(t,e={}){lt(t),await jo(t,e)}async function Zg(t,e={}){lt(t),await Xo(t,e)}async function Jg(t,e,n={}){lt(t),await Yo(t,e,n)}async function Qg(t,e,n={}){lt(t),await Ko(t,e,n)}function ev(t,e){t instanceof HTMLInputElement&&t.type==="checkbox"?Hn(t,!!e):kt(t,String(e)),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0}))}var tv="0.14.1";export{dr as AgUiChat,Cn as AgUiClient,Go as COMPACTION_ACTIVITY_TYPE,er as CheckpointMenu,Un as ClientToolRegistry,ho as ConnectionLostError,ne as DEFAULT_UI_STRINGS,wr as ELEMENT_TAG,Fo as LOAD_CAPABILITY_TOOL,Uo as MAX_TOOL_ROUNDS,Ze as MESSAGE_ROLE,Zo as PAGE_ACTIONS,cr as RemoteConversationStore,ur as RunIndex,Po as STATE_EVENT,Mo as SUBMIT_EVENT,ht as SessionStorageStore,Lo as TOGGLE_EVENT,ce as TOOL_CALL_STATUS,ze as TOOL_DISPLAY,ar as ToolCallCard,tv as VERSION,Do as X_CONFIRM_KEY,Pn as X_DESTRUCTIVE_KEY,Dn as X_NAVIGATES_KEY,Ne as X_SUMMARY_KEY,Kg as clickElement,ya as createHttpAgent,Jo as createPageActionTools,Qo as createPageMapContext,Ar as createPageStateTools,ts as createRouteTools,cd as createStateHookTools,Xg as defineAgUiChat,Yg as fillField,Wo as focusWithFlash,jo as highlightThenClick,zo as isDestructive,Bo as isNavigates,ns as mergeUiStrings,ga as messageAttachments,es as parseToolCatalog,Ya as prefersReducedMotion,Zg as pressButton,Xo as pressThenClick,Xs as prettifyToolName,lo as renderMarkdown,rs as requestApproval,qs as requestConfirmation,Ys as requestQuestion,lt as scrollIntoCenterView,Jg as selectControl,Yo as selectOption,ev as setControlValue,Hn as setNativeChecked,kt as setNativeValue,Qg as toggleCheckbox,Ko as toggleControl,xa as transcribeAudio,Vo as typeInto,Ea as uploadAttachment};
|
|
1581
1581
|
/*! Bundled license information:
|
|
1582
1582
|
|
|
1583
1583
|
fast-json-patch/module/helpers.mjs:
|