@noodleseed/assistant 1.16.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.cts CHANGED
@@ -1,3 +1,3 @@
1
1
  import './appearance-Cc-eqSbp.cjs';
2
- export { k as AssistantChatError, b as AssistantChatState, c as AssistantClient, l as AssistantClientContext, m as AssistantClientError, f as AssistantClientEvent, n as AssistantClientLifecycleEvent, o as AssistantConfirmationData, p as AssistantContentDetail, q as AssistantContentEvent, a as AssistantContext, r as AssistantContextValue, s as AssistantDoneEvent, t as AssistantErrorEvent, u as AssistantErrorEventDetail, v as AssistantInputRequestData, w as AssistantInputRequestedDetail, x as AssistantInputRequestedEvent, y as AssistantInteractionResolvedDetail, z as AssistantInteractionResolvedEvent, h as AssistantInteractionResponse, B as AssistantInteractionStatus, D as AssistantJsonValue, e as AssistantModelContextUpdate, A as AssistantPageContext, E as AssistantSessionResponse, F as AssistantToolCompletedDetail, G as AssistantToolCompletedEvent, H as AssistantToolProposedDetail, I as AssistantToolProposedEvent, J as AssistantToolResultData, K as AssistantToolStartedDetail, L as AssistantToolStartedEvent, M as AssistantUIDataTypes, N as AssistantUIMessage, O as AssistantUnrecognizedEvent, d as AssistantViewAvailableDetail, j as AssistantViewAvailableEvent, P as AssistantViewData, C as CreateAssistantClientOptions, Q as createAssistantClient } from './client-401BAJqk.cjs';
2
+ export { k as AssistantChatError, b as AssistantChatState, c as AssistantClient, l as AssistantClientContext, m as AssistantClientError, f as AssistantClientEvent, n as AssistantClientLifecycleEvent, o as AssistantConfirmationData, p as AssistantContentDetail, q as AssistantContentEvent, a as AssistantContext, r as AssistantContextValue, s as AssistantDoneEvent, t as AssistantErrorEvent, u as AssistantErrorEventDetail, v as AssistantInputRequestData, w as AssistantInputRequestedDetail, x as AssistantInputRequestedEvent, y as AssistantInteractionResolvedDetail, z as AssistantInteractionResolvedEvent, h as AssistantInteractionResponse, B as AssistantInteractionStatus, D as AssistantJsonValue, e as AssistantModelContextUpdate, A as AssistantPageContext, E as AssistantSessionResponse, F as AssistantToolCompletedDetail, G as AssistantToolCompletedEvent, H as AssistantToolProposedDetail, I as AssistantToolProposedEvent, J as AssistantToolResultData, K as AssistantToolStartedDetail, L as AssistantToolStartedEvent, M as AssistantUIDataTypes, N as AssistantUIMessage, O as AssistantUnrecognizedEvent, d as AssistantViewAvailableDetail, j as AssistantViewAvailableEvent, P as AssistantViewData, C as CreateAssistantClientOptions, Q as createAssistantClient } from './client-BQ30Fq-c.cjs';
3
3
  import 'ai';
package/dist/client.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import './appearance-Cc-eqSbp.js';
2
- export { k as AssistantChatError, b as AssistantChatState, c as AssistantClient, l as AssistantClientContext, m as AssistantClientError, f as AssistantClientEvent, n as AssistantClientLifecycleEvent, o as AssistantConfirmationData, p as AssistantContentDetail, q as AssistantContentEvent, a as AssistantContext, r as AssistantContextValue, s as AssistantDoneEvent, t as AssistantErrorEvent, u as AssistantErrorEventDetail, v as AssistantInputRequestData, w as AssistantInputRequestedDetail, x as AssistantInputRequestedEvent, y as AssistantInteractionResolvedDetail, z as AssistantInteractionResolvedEvent, h as AssistantInteractionResponse, B as AssistantInteractionStatus, D as AssistantJsonValue, e as AssistantModelContextUpdate, A as AssistantPageContext, E as AssistantSessionResponse, F as AssistantToolCompletedDetail, G as AssistantToolCompletedEvent, H as AssistantToolProposedDetail, I as AssistantToolProposedEvent, J as AssistantToolResultData, K as AssistantToolStartedDetail, L as AssistantToolStartedEvent, M as AssistantUIDataTypes, N as AssistantUIMessage, O as AssistantUnrecognizedEvent, d as AssistantViewAvailableDetail, j as AssistantViewAvailableEvent, P as AssistantViewData, C as CreateAssistantClientOptions, Q as createAssistantClient } from './client-Ii_xTV09.js';
2
+ export { k as AssistantChatError, b as AssistantChatState, c as AssistantClient, l as AssistantClientContext, m as AssistantClientError, f as AssistantClientEvent, n as AssistantClientLifecycleEvent, o as AssistantConfirmationData, p as AssistantContentDetail, q as AssistantContentEvent, a as AssistantContext, r as AssistantContextValue, s as AssistantDoneEvent, t as AssistantErrorEvent, u as AssistantErrorEventDetail, v as AssistantInputRequestData, w as AssistantInputRequestedDetail, x as AssistantInputRequestedEvent, y as AssistantInteractionResolvedDetail, z as AssistantInteractionResolvedEvent, h as AssistantInteractionResponse, B as AssistantInteractionStatus, D as AssistantJsonValue, e as AssistantModelContextUpdate, A as AssistantPageContext, E as AssistantSessionResponse, F as AssistantToolCompletedDetail, G as AssistantToolCompletedEvent, H as AssistantToolProposedDetail, I as AssistantToolProposedEvent, J as AssistantToolResultData, K as AssistantToolStartedDetail, L as AssistantToolStartedEvent, M as AssistantUIDataTypes, N as AssistantUIMessage, O as AssistantUnrecognizedEvent, d as AssistantViewAvailableDetail, j as AssistantViewAvailableEvent, P as AssistantViewData, C as CreateAssistantClientOptions, Q as createAssistantClient } from './client-B6pnBmF8.js';
3
3
  import 'ai';
package/dist/client.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AssistantClientError,
3
3
  createAssistantClient
4
- } from "./chunk-NPV64PUX.js";
4
+ } from "./chunk-RIKRQFKS.js";
5
5
  import "./chunk-3YYTUJPJ.js";
6
6
  import "./chunk-5FUTL2UF.js";
7
7
  export {
@@ -144,7 +144,7 @@ Error message: ${b_(n)}`,cause:n}),this[c_]=!0,this.value=e,this.context=a}stati
144
144
  `))}catch(o){throw er("assistant event stream contained malformed JSON",o)}if(e==="done"&&!PR(r))throw er("assistant event stream contained an invalid done event");return{event:e,data:ww(r)?r:{value:r}}}function CR(t){return t.replaceAll(`\r
145
145
  `,`
146
146
  `).replaceAll("\r",`
147
- `)}function PR(t){return ww(t)&&(t.turnId===void 0||typeof t.turnId=="string"&&t.turnId.length>0)}function ww(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function er(t,e){return new Eo(t,e===void 0?void 0:{cause:e})}function xw(t){return t instanceof DOMException&&t.name==="AbortError"}async function kw(t){try{let n=(await t.clone().json()).code;return typeof n=="string"?n:void 0}catch{return}}var MR=new Set(["daily_turn_budget_exhausted","daily_session_budget_exhausted"]),Hr=class extends Error{detail;constructor(e,n,a){super(n,a),this.name="AssistantClientError",this.detail=e}},Qf=class{#e;#t;#i=new Set;#n=new sl;#a;#o;#r;#l;#u;#d;#s=new Map;constructor(e){this.#e=yw(e),this.#t=e.fetch??((n,a)=>globalThis.fetch(n,a)),this.#l=e.context?{...e.context}:void 0,this.#u=e.modelContext?Io(e.modelContext):void 0,this.#a=e.clientContext,this.#o=e.pageContext}subscribe(e){return this.#i.add(e),()=>this.#i.delete(e)}subscribeChat(e){return this.#n.subscribe(e)}getChatState(){return this.#n.getState()}async connect(){this.#r||await this.#f(async e=>{this.#r||await this.#v(e)})}async sendMessage(e){let n=e.trim();n&&await this.#f(async a=>{await this.#h(a,()=>this.#p(n,!0,a,this.#u))})}async respond(e,n){if(!e)throw _e("invalid_request","interaction id is required",!1);await this.#f(async a=>{await this.#h(a,async()=>{let r=this.#s.get(e),o=this.#r;if(!o)throw _e("confirmation_expired","assistant session is not active",!1);let i=o.endpoints.interactions;if(!i&&n.action!=="accept")throw _e("unsupported_service","the assistant service does not support declining or cancelling interactions",!1);let s=i??o.endpoints.toolConfirmations,c=i?{id:e,action:n.action,...n.action==="accept"&&n.content!==void 0?{content:n.content}:{}}:{id:e};this.#c({event:"interaction_started",data:{id:e,action:n.action}});try{let u=await this.#_(s,{method:"POST",headers:Yf(o.token,"text/event-stream"),body:JSON.stringify(c),signal:a},"confirmation_failed");if(u.status===401&&(this.#r=void 0,this.#c({event:"session_expired",data:{}})),!u.ok){let h=await UR(u),b=u.status===401||u.status===409;throw _e(h??(b?"confirmation_expired":"confirmation_failed"),`Assistant interaction failed (${u.status})`,!1,u.status)}let d,m;await this.#y(u,h=>{h.event==="tool_completed"&&h.data.id===e&&(d=h.data.result),(h.event==="tool_proposed"||h.event==="input_requested")&&h.data.id!==e&&(m=h.data.id)}),this.#c({event:"interaction_completed",data:{id:e,action:n.action}}),r&&(this.#s.delete(e),m?this.#s.set(m,r):n.action!=="accept"?r.resolve(jR(n.action)):d!==void 0?r.resolve(NR(d)):r.reject(_e("invalid_response","Assistant app interaction completed without a tool result",!1)))}catch(u){throw r&&this.#s.get(e)===r&&(this.#s.delete(e),r.reject(u)),u}})})}updateContext(e){this.#l={...e},this.#c({event:"context_changed",data:{context:this.#l}})}updatePageContext(e){this.#o=Gf(e)}updateModelContext(e){this.#u=Io(e),this.#c({event:"model_context_changed",data:{modelContext:this.#u}})}async requestApp(e,n){let a=this.#r;if(!a?.endpoints.apps)throw _e("unsupported_service","the assistant service does not support MCP Apps",!1);let r=await this.#_(a.endpoints.apps,{method:"POST",headers:Yf(a.token,"application/json"),body:JSON.stringify({method:e,params:n})},"app_request_failed");if(!r.ok)throw _e("app_request_failed",`Assistant app request failed (${r.status})`,!1,r.status);let o=await r.json(),i=OR(o);return i?new Promise((s,c)=>{let u=i.data.id,d=this.#s.get(u);d&&d.reject(_e("invalid_response","Assistant returned a duplicate app interaction",!1)),this.#s.set(u,{resolve:s,reject:c}),this.#c(i),this.#n.flush()}):o}appSandboxUrl(){return this.#r?.endpoints.sandbox}resetSession(){this.#T(_e("confirmation_expired","assistant session is not active",!1)),this.#r=void 0,this.#c({event:"session_reset",data:{}})}abort(){this.#d?.abort()}async#p(e,n,a,r){let o=this.#r??await this.#v(a);n&&this.#c({event:"message_started",data:{message:e}});let i=this.#m(),s=this.#g(),c=await this.#_(o.endpoints.turns,{method:"POST",headers:Yf(o.token,"text/event-stream"),body:JSON.stringify({message:e,...i?{clientContext:i}:{},...s===void 0?{}:{pageContext:s},...r?{modelContext:r}:{}}),signal:a},"turn_failed");if(c.status===401&&n){this.#r=void 0,this.#c({event:"session_expired",data:{}}),await this.#p(e,!1,a,r);return}if(!c.ok){let u=await kw(c);throw _e("turn_failed",`Assistant turn failed (${c.status})`,!1,c.status,void 0,u)}await this.#y(c),this.#c({event:"message_completed",data:{}})}#m(){let e;try{e=typeof this.#a=="function"?this.#a():this.#a}catch(a){throw _e("turn_failed","Assistant client context provider failed",!1,void 0,{cause:a})}if(!e)return;let n={...typeof e.locale=="string"&&e.locale?{locale:e.locale}:{},...typeof e.timeZone=="string"&&e.timeZone?{timeZone:e.timeZone}:{}};return Object.keys(n).length>0?n:void 0}#g(){try{let e=typeof this.#o=="function"?this.#o():this.#o;return e===void 0?void 0:Gf(e)}catch(e){throw _e("turn_failed","Assistant page context provider failed",!1,void 0,{cause:e})}}async#v(e){let n=this.#e,a=await this.#b(n,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(n.kind==="public"?{embedId:n.embedId}:this.#l?{context:this.#l}:{}),credentials:n.kind==="public"?"omit":"same-origin",signal:e});if(!a.ok){let i=await kw(a);throw _e("session_failed",`Assistant session failed (${a.status})`,i===void 0||!MR.has(i),a.status,void 0,i)}let r;try{r=await a.json()}catch(i){throw _e("session_failed","Assistant session returned invalid JSON",!0,void 0,{cause:i})}let o=DR(r);return this.#r=o,this.#c({event:"session_started",data:{expiresAt:o.expiresAt,...o.configuration?{configuration:o.configuration}:{}}}),o}async#y(e,n){let a;try{await _w(e,r=>{let o=Bf(r);this.#c(o),n?.(o),!(o.event!=="error"||typeof o.data.code!="string")&&(a={code:o.data.code,...typeof o.data.status=="number"?{status:o.data.status}:{},retryable:o.data.retryable===!0})})}catch(r){throw r instanceof Eo?_e(r.code,r.message,!1,void 0,{cause:r}):r}if(a)throw _e(a.code,`Assistant stream failed (${a.code})`,a.retryable,a.status)}async#b(e,n){try{return await this.#t(e.url,n)}catch(a){throw n.signal?.aborted?a:e.kind!=="public"?_e("session_failed","Assistant request failed",!0,void 0,{cause:a}):_e("session_failed",`Assistant could not reach ${new URL(e.url).origin}. If the page sets a Content-Security-Policy, allow that origin in connect-src (and in script-src and frame-src).`,!0,void 0,{cause:a},"blocked_by_page")}}async#_(e,n,a){try{return await this.#t(e,n)}catch(r){throw n.signal?.aborted?r:_e(a,"Assistant request failed",!0,void 0,{cause:r})}}async#f(e){if(this.#d)throw _e("request_in_progress","an assistant request is already in progress",!0);let n=new AbortController;this.#d=n;try{await e(n.signal)}catch(a){throw n.signal.aborted?_e("request_aborted","assistant request was aborted",!0,void 0,{cause:a}):a}finally{this.#d=void 0}}async#h(e,n){try{await n(),await this.#n.flush()}catch(a){throw this.#n.fail(a,e.aborted),await this.#n.flush(),a}}#c(e){this.#n.handle(e);for(let n of this.#i)try{n(e)}catch{}}#T(e){for(let n of this.#s.values())n.reject(e);this.#s.clear()}};function Xf(t){return new Qf(t)}function Yf(t,e){return{Authorization:`Bearer ${t}`,"Content-Type":"application/json",Accept:e}}function OR(t){if(!Vr(t)||!Vr(t.interaction))return;let e=t.interaction.event,n=t.interaction.data;if(e!=="tool_proposed"&&e!=="input_requested"||!Vr(n))return;let a=Bf({event:e,data:n});return a.event==="tool_proposed"||a.event==="input_requested"?a:void 0}function NR(t){let e=typeof t=="string"?t:JSON.stringify(t);return t!==null&&typeof t=="object"&&!Array.isArray(t)?{content:[{type:"text",text:e}],structuredContent:t,isError:!1}:{content:[{type:"text",text:e}],isError:!1}}function jR(t){return{content:[{type:"text",text:`interaction_${t}`}],isError:!0}}function DR(t){if(!Vr(t)||!Vr(t.endpoints))throw _e("session_failed","Assistant session response is invalid",!0);let e=t.endpoints.interactions,n=t.endpoints.apps,a=t.endpoints.sandbox;if(typeof t.token!="string"||typeof t.expiresAt!="string"||typeof t.endpoints.turns!="string"||typeof t.endpoints.toolConfirmations!="string"||e!==void 0&&typeof e!="string"||n!==void 0&&typeof n!="string"||a!==void 0&&typeof a!="string")throw _e("session_failed","Assistant session response is invalid",!0);return{token:t.token,expiresAt:t.expiresAt,endpoints:{turns:t.endpoints.turns,toolConfirmations:t.endpoints.toolConfirmations,...typeof e=="string"?{interactions:e}:{},...typeof n=="string"?{apps:n}:{},...typeof a=="string"?{sandbox:a}:{}},...Vr(t.configuration)?{configuration:t.configuration}:{}}}function Vr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}async function UR(t){let e;try{e=await t.json()}catch{return}if(!(!Vr(e)||typeof e.code!="string"))return/^[A-Za-z0-9_.-]{1,64}$/.test(e.code)?e.code:void 0}function _e(t,e,n,a,r,o){return new Hr({code:t,...a===void 0?{}:{status:a},retryable:n,...o===void 0?{}:{serviceCode:o}},e,r)}function $w(t){let e=document.createElement("section");e.className="tool-proposal input-request",e.dataset.kind="input";let n=document.createElement("form"),a=document.createElement("strong");a.textContent=t.message,n.append(a);let r=ra(t.requestedSchema.properties),o=new Set(Array.isArray(t.requestedSchema.required)?t.requestedSchema.required.filter(S=>typeof S=="string"):[]),i=new Map,s=new WeakSet;for(let[S,U]of Object.entries(r)){let N=ra(U),de=document.createElement("label"),F=document.createElement("span");F.textContent=typeof N.title=="string"&&N.title?N.title:KR(S);let g=LR(S,N,o.has(S)),P=()=>{s.add(g),th(g,N,o.has(S),s.has(g))};g.addEventListener("input",P),g.addEventListener("change",P),de.append(F,g),n.append(de),i.set(S,g)}let c=document.createElement("div");c.className="proposal-actions";let u=eh(t.labels.submit,"submit"),d=eh(t.labels.decline,"button"),m=eh(t.labels.cancel,"button"),h=[u,d,m],b=async S=>{h.forEach(U=>{U.disabled=!0});try{await t.respond(S)}catch(U){throw h.forEach(N=>{N.disabled=!1}),U}};return n.addEventListener("submit",S=>{S.preventDefault();for(let[U,N]of i)th(N,ra(r[U]),o.has(U),s.has(N));n.reportValidity()&&b({action:"accept",content:ZR(i,r,o,s)}).catch(()=>{})}),d.addEventListener("click",()=>{b({action:"decline"}).catch(()=>{})}),m.addEventListener("click",()=>{b({action:"cancel"}).catch(()=>{})}),c.append(u,d,m),n.append(c),e.append(n),e}function LR(t,e,n){let a=Aw(e);if(a||e.type==="array"){let o=document.createElement("select");o.name=t,o.multiple=e.type==="array";let i=a??FR(e);!o.multiple&&(!n||!i.some(s=>s.value===e.default))&&o.append(GR(i));for(let s of i)o.append(zw(s.title,s.value));return HR(o,e.default),th(o,e,n,!1),o}let r=document.createElement("input");return r.name=t,r.type=VR(e),r.required=n&&qR(e),e.type==="integer"&&(r.step="1"),typeof e.minimum=="number"&&(r.min=String(e.minimum)),typeof e.maximum=="number"&&(r.max=String(e.maximum)),typeof e.minLength=="number"&&(r.minLength=e.minLength),typeof e.maxLength=="number"&&(r.maxLength=e.maxLength),e.format==="date-time"&&(r.step="0.001"),JR(r,e),r}function ZR(t,e,n,a){let r={};for(let[o,i]of t){let s=ra(e[o]);if(i instanceof HTMLSelectElement&&i.multiple){let c=[...i.selectedOptions].map(u=>u.value);Iw(s,n.has(o),a.has(i),c.length)&&(r[o]=c)}else if(i instanceof HTMLInputElement&&i.type==="checkbox")(n.has(o)||rh(s)||a.has(i))&&(r[o]=i.checked);else if(i instanceof HTMLSelectElement)Ew(i)||(r[o]=i.value);else if(i.value!==""||s.type==="string"&&(n.has(o)||rh(s)||a.has(i)))if(s.format==="date-time"){let c=WR(i.value);c!==void 0&&(r[o]=c)}else r[o]=s.type==="number"||s.type==="integer"?Number(i.value):i.value}return r}function th(t,e,n,a){if(t.setCustomValidity(""),!(t instanceof HTMLSelectElement))return;if(!t.multiple){t.required=n,n&&Ew(t)&&t.setCustomValidity("Please select an option.");return}let r=t.selectedOptions.length,o=Iw(e,n,a,r),i=Sw(e.minItems),s=Sw(e.maxItems);t.required=o&&i!==void 0&&i>0,o&&i!==void 0&&r<i?t.setCustomValidity(`Select at least ${i} option${i===1?"":"s"}.`):o&&s!==void 0&&r>s&&t.setCustomValidity(`Select at most ${s} option${s===1?"":"s"}.`)}function Iw(t,e,n,a){return e||rh(t)||n||a>0}function rh(t){return Object.hasOwn(t,"default")}function Sw(t){return typeof t=="number"&&Number.isInteger(t)&&t>=0?t:void 0}function qR(t){return t.type==="number"||t.type==="integer"?!0:t.type!=="string"?!1:t.format==="date"||t.format==="date-time"||t.format==="email"||t.format==="uri"||typeof t.minLength=="number"&&t.minLength>0}function Ew(t){return t.selectedOptions[0]?.dataset.placeholder==="true"}function Aw(t){return Array.isArray(t.enum)&&t.enum.every(e=>typeof e=="string")?t.enum.map(e=>({value:e,title:e})):Tw(t.oneOf)??Tw(t.anyOf)}function FR(t){return Aw(ra(t.items))??[]}function VR(t){return t.type==="boolean"?"checkbox":t.type==="number"||t.type==="integer"?"number":t.format==="date"?"date":t.format==="date-time"?"datetime-local":t.format==="email"?"email":t.format==="uri"?"url":"text"}function Tw(t){if(!Array.isArray(t))return;let e=t.map(n=>ra(n));if(e.every(n=>typeof n.const=="string"))return e.map(n=>({value:String(n.const),title:typeof n.title=="string"?n.title:String(n.const)}))}function HR(t,e){if(t.multiple){let n=new Set(Array.isArray(e)?e.filter(a=>typeof a=="string"):[]);for(let a of t.options)a.selected=n.has(a.value);return}typeof e=="string"&&(t.value=e)}function JR(t,e){let n=e.default;if(e.type==="boolean"){typeof n=="boolean"&&(t.checked=n);return}if(e.type==="number"||e.type==="integer"){typeof n=="number"&&Number.isFinite(n)&&(t.value=String(n));return}if(typeof n=="string"){if(e.format==="date-time"){t.value=BR(n)??"";return}t.value=n}}function BR(t){let e=new Date(t);if(!Number.isNaN(e.valueOf()))return[String(e.getFullYear()).padStart(4,"0"),"-",Ao(e.getMonth()+1),"-",Ao(e.getDate()),"T",Ao(e.getHours()),":",Ao(e.getMinutes()),":",Ao(e.getSeconds()),".",String(e.getMilliseconds()).padStart(3,"0")].join("")}function WR(t){let e=new Date(t);return Number.isNaN(e.valueOf())?void 0:e.toISOString()}function Ao(t){return String(t).padStart(2,"0")}function eh(t,e){let n=document.createElement("button");return n.type=e,n.textContent=t,n}function zw(t,e){let n=document.createElement("option");return n.textContent=t,n.value=e,n}function GR(t){let e="";for(;t.some(a=>a.value===e);)e+="\0";let n=zw("",e);return n.dataset.placeholder="true",n}function KR(t){let e=t.replaceAll(/([a-z0-9])([A-Z])/g,"$1 $2").replaceAll(/[_-]+/g," ");return e?`${e[0]?.toUpperCase()??""}${e.slice(1)}`:t}function ra(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{}}function Cw(t){let e=document.createElement("section");e.className="tool-proposal",e.setAttribute("aria-label",t.labels.heading);let n=document.createElement("span");n.className="proposal-eyebrow",n.textContent=t.labels.heading;let a=document.createElement("h3");if(a.textContent=t.title??Mw(t.tool),e.append(n,a),t.description){let i=document.createElement("p");i.className="proposal-description",i.textContent=t.description,e.append(i)}if(t.arguments&&Object.keys(t.arguments).length>0){let{action:i,...s}=t.arguments;if(Object.keys(s).length>0&&e.append(nh(s,t.reviewSchema,t.labels)),i!==void 0){let c=document.createElement("details");c.className="proposal-details";let u=document.createElement("summary");u.textContent=t.labels.details;let d=kr(t.reviewSchema?.properties);c.append(u);let m=kr(i);if(m)c.append(nh(m,kr(d?.action),t.labels));else{let h=document.createElement("div");ul(h,i,kr(d?.action),t.labels),c.append(h)}e.append(c)}}let r=document.createElement("div");r.className="proposal-actions";let o=[];for(let[i,s]of[[t.labels.accept,"accept"],[t.labels.decline,"decline"]]){let c=document.createElement("button");c.type="button",c.className=`proposal-${s}`,c.textContent=i,o.push(c),c.addEventListener("click",()=>{for(let u of o)u.disabled=!0;t.respond(s).catch(()=>{for(let u of o)u.disabled=!1})}),r.append(c)}return e.append(r),e}function Pw(t,e,n){let a=document.createElement("section");a.className="tool-result";let r=document.createElement("strong");r.textContent=e,a.append(r);let o=document.createElement("div");return ul(o,t,void 0,{heading:e,accept:"",decline:"",details:"",redacted:n}),a.append(o),a}function nh(t,e,n){let a=document.createElement("dl");a.className="proposal-arguments";let r=kr(e?.properties);for(let[o,i]of Object.entries(t)){let s=kr(r?.[o]),c=document.createElement("dt");c.textContent=Rw(s?.title)??Mw(o);let u=Rw(s?.description);if(u){let m=document.createElement("small");m.textContent=u,c.append(m)}let d=document.createElement("dd");ul(d,i,s,n),a.append(c,d)}return a}function ul(t,e,n,a){if(e==="[REDACTED]"){let o=document.createElement("span");o.className="proposal-redacted",o.textContent=a.redacted,t.append(o);return}if(Array.isArray(e)){let o=document.createElement("ul"),i=kr(n?.items);for(let s of e){let c=document.createElement("li");ul(c,s,i,a),o.append(c)}t.append(o);return}let r=kr(e);if(r){t.append(nh(r,n,a));return}t.textContent=YR(e,n)}function YR(t,e){if(t==null||t==="")return"Not provided";if(typeof t=="boolean")return t?"Yes":"No";if(typeof t=="number")return new Intl.NumberFormat().format(t);if(typeof t!="string")return String(t);if(e?.format==="date"){let n=new Date(`${t}T00:00:00`);if(!Number.isNaN(n.valueOf()))return new Intl.DateTimeFormat(void 0,{dateStyle:"medium"}).format(n)}if(e?.format==="date-time"){let n=new Date(t);if(!Number.isNaN(n.valueOf()))return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(n)}return t}function Mw(t){let e=t.replaceAll(/([a-z0-9])([A-Z])/g,"$1 $2").replaceAll(/[_-]+/g," ");return e?`${e[0]?.toUpperCase()??""}${e.slice(1)}`:t}function kr(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)?t:void 0}function Rw(t){return typeof t=="string"&&t.length>0?t:void 0}function Ow(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,a=Array(e);n<e;n++)a[n]=t[n];return a}function QR(t){if(Array.isArray(t))return t}function XR(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var a,r,o,i,s=[],c=!0,u=!1;try{if(o=(n=n.call(t)).next,e!==0)for(;!(c=(a=o.call(n)).done)&&(s.push(a.value),s.length!==e);c=!0);}catch(d){u=!0,r=d}finally{try{if(!c&&n.return!=null&&(i=n.return(),Object(i)!==i))return}finally{if(u)throw r}}return s}}function eC(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
147
+ `)}function PR(t){return ww(t)&&(t.turnId===void 0||typeof t.turnId=="string"&&t.turnId.length>0)}function ww(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function er(t,e){return new Eo(t,e===void 0?void 0:{cause:e})}function xw(t){return t instanceof DOMException&&t.name==="AbortError"}async function kw(t){try{let n=(await t.clone().json()).code;return typeof n=="string"?n:void 0}catch{return}}var MR=new Set(["daily_turn_budget_exhausted","daily_session_budget_exhausted"]),Hr=class extends Error{detail;constructor(e,n,a){super(n,a),this.name="AssistantClientError",this.detail=e}},Qf=class{#e;#t;#i=new Set;#n=new sl;#a;#o;#r;#l;#u;#d;#s=new Map;constructor(e){this.#e=yw(e),this.#t=e.fetch??((n,a)=>globalThis.fetch(n,a)),this.#l=e.context?{...e.context}:void 0,this.#u=e.modelContext?Io(e.modelContext):void 0,this.#a=e.clientContext,this.#o=e.pageContext}subscribe(e){return this.#i.add(e),()=>this.#i.delete(e)}subscribeChat(e){return this.#n.subscribe(e)}getChatState(){return this.#n.getState()}hasSession(){return this.#r!==void 0}async connect(){this.#r||await this.#f(async e=>{this.#r||await this.#v(e)})}async sendMessage(e){let n=e.trim();n&&await this.#f(async a=>{await this.#h(a,()=>this.#p(n,!0,a,this.#u))})}async respond(e,n){if(!e)throw _e("invalid_request","interaction id is required",!1);await this.#f(async a=>{await this.#h(a,async()=>{let r=this.#s.get(e),o=this.#r;if(!o)throw _e("confirmation_expired","assistant session is not active",!1);let i=o.endpoints.interactions;if(!i&&n.action!=="accept")throw _e("unsupported_service","the assistant service does not support declining or cancelling interactions",!1);let s=i??o.endpoints.toolConfirmations,c=i?{id:e,action:n.action,...n.action==="accept"&&n.content!==void 0?{content:n.content}:{}}:{id:e};this.#c({event:"interaction_started",data:{id:e,action:n.action}});try{let u=await this.#_(s,{method:"POST",headers:Yf(o.token,"text/event-stream"),body:JSON.stringify(c),signal:a},"confirmation_failed");if(u.status===401&&(this.#r=void 0,this.#c({event:"session_expired",data:{}})),!u.ok){let h=await UR(u),b=u.status===401||u.status===409;throw _e(h??(b?"confirmation_expired":"confirmation_failed"),`Assistant interaction failed (${u.status})`,!1,u.status)}let d,m;await this.#y(u,h=>{h.event==="tool_completed"&&h.data.id===e&&(d=h.data.result),(h.event==="tool_proposed"||h.event==="input_requested")&&h.data.id!==e&&(m=h.data.id)}),this.#c({event:"interaction_completed",data:{id:e,action:n.action}}),r&&(this.#s.delete(e),m?this.#s.set(m,r):n.action!=="accept"?r.resolve(jR(n.action)):d!==void 0?r.resolve(NR(d)):r.reject(_e("invalid_response","Assistant app interaction completed without a tool result",!1)))}catch(u){throw r&&this.#s.get(e)===r&&(this.#s.delete(e),r.reject(u)),u}})})}updateContext(e){this.#l={...e},this.#c({event:"context_changed",data:{context:this.#l}})}updatePageContext(e){this.#o=Gf(e)}updateModelContext(e){this.#u=Io(e),this.#c({event:"model_context_changed",data:{modelContext:this.#u}})}async requestApp(e,n){let a=this.#r;if(!a?.endpoints.apps)throw _e("unsupported_service","the assistant service does not support MCP Apps",!1);let r=await this.#_(a.endpoints.apps,{method:"POST",headers:Yf(a.token,"application/json"),body:JSON.stringify({method:e,params:n})},"app_request_failed");if(!r.ok)throw _e("app_request_failed",`Assistant app request failed (${r.status})`,!1,r.status);let o=await r.json(),i=OR(o);return i?new Promise((s,c)=>{let u=i.data.id,d=this.#s.get(u);d&&d.reject(_e("invalid_response","Assistant returned a duplicate app interaction",!1)),this.#s.set(u,{resolve:s,reject:c}),this.#c(i),this.#n.flush()}):o}appSandboxUrl(){return this.#r?.endpoints.sandbox}resetSession(){this.#T(_e("confirmation_expired","assistant session is not active",!1)),this.#r=void 0,this.#c({event:"session_reset",data:{}})}abort(){this.#d?.abort()}async#p(e,n,a,r){let o=this.#r??await this.#v(a);n&&this.#c({event:"message_started",data:{message:e}});let i=this.#m(),s=this.#g(),c=await this.#_(o.endpoints.turns,{method:"POST",headers:Yf(o.token,"text/event-stream"),body:JSON.stringify({message:e,...i?{clientContext:i}:{},...s===void 0?{}:{pageContext:s},...r?{modelContext:r}:{}}),signal:a},"turn_failed");if(c.status===401&&n){this.#r=void 0,this.#c({event:"session_expired",data:{}}),await this.#p(e,!1,a,r);return}if(!c.ok){let u=await kw(c);throw _e("turn_failed",`Assistant turn failed (${c.status})`,!1,c.status,void 0,u)}await this.#y(c),this.#c({event:"message_completed",data:{}})}#m(){let e;try{e=typeof this.#a=="function"?this.#a():this.#a}catch(a){throw _e("turn_failed","Assistant client context provider failed",!1,void 0,{cause:a})}if(!e)return;let n={...typeof e.locale=="string"&&e.locale?{locale:e.locale}:{},...typeof e.timeZone=="string"&&e.timeZone?{timeZone:e.timeZone}:{}};return Object.keys(n).length>0?n:void 0}#g(){try{let e=typeof this.#o=="function"?this.#o():this.#o;return e===void 0?void 0:Gf(e)}catch(e){throw _e("turn_failed","Assistant page context provider failed",!1,void 0,{cause:e})}}async#v(e){let n=this.#e,a=await this.#b(n,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(n.kind==="public"?{embedId:n.embedId}:this.#l?{context:this.#l}:{}),credentials:n.kind==="public"?"omit":"same-origin",signal:e});if(!a.ok){let i=await kw(a);throw _e("session_failed",`Assistant session failed (${a.status})`,i===void 0||!MR.has(i),a.status,void 0,i)}let r;try{r=await a.json()}catch(i){throw _e("session_failed","Assistant session returned invalid JSON",!0,void 0,{cause:i})}let o=DR(r);return this.#r=o,this.#c({event:"session_started",data:{expiresAt:o.expiresAt,...o.configuration?{configuration:o.configuration}:{}}}),o}async#y(e,n){let a;try{await _w(e,r=>{let o=Bf(r);this.#c(o),n?.(o),!(o.event!=="error"||typeof o.data.code!="string")&&(a={code:o.data.code,...typeof o.data.status=="number"?{status:o.data.status}:{},retryable:o.data.retryable===!0})})}catch(r){throw r instanceof Eo?_e(r.code,r.message,!1,void 0,{cause:r}):r}if(a)throw _e(a.code,`Assistant stream failed (${a.code})`,a.retryable,a.status)}async#b(e,n){try{return await this.#t(e.url,n)}catch(a){throw n.signal?.aborted?a:e.kind!=="public"?_e("session_failed","Assistant request failed",!0,void 0,{cause:a}):_e("session_failed",`Assistant could not reach ${new URL(e.url).origin}. If the page sets a Content-Security-Policy, allow that origin in connect-src (and in script-src and frame-src).`,!0,void 0,{cause:a},"blocked_by_page")}}async#_(e,n,a){try{return await this.#t(e,n)}catch(r){throw n.signal?.aborted?r:_e(a,"Assistant request failed",!0,void 0,{cause:r})}}async#f(e){if(this.#d)throw _e("request_in_progress","an assistant request is already in progress",!0);let n=new AbortController;this.#d=n;try{await e(n.signal)}catch(a){throw n.signal.aborted?_e("request_aborted","assistant request was aborted",!0,void 0,{cause:a}):a}finally{this.#d=void 0}}async#h(e,n){try{await n(),await this.#n.flush()}catch(a){throw this.#n.fail(a,e.aborted),await this.#n.flush(),a}}#c(e){this.#n.handle(e);for(let n of this.#i)try{n(e)}catch{}}#T(e){for(let n of this.#s.values())n.reject(e);this.#s.clear()}};function Xf(t){return new Qf(t)}function Yf(t,e){return{Authorization:`Bearer ${t}`,"Content-Type":"application/json",Accept:e}}function OR(t){if(!Vr(t)||!Vr(t.interaction))return;let e=t.interaction.event,n=t.interaction.data;if(e!=="tool_proposed"&&e!=="input_requested"||!Vr(n))return;let a=Bf({event:e,data:n});return a.event==="tool_proposed"||a.event==="input_requested"?a:void 0}function NR(t){let e=typeof t=="string"?t:JSON.stringify(t);return t!==null&&typeof t=="object"&&!Array.isArray(t)?{content:[{type:"text",text:e}],structuredContent:t,isError:!1}:{content:[{type:"text",text:e}],isError:!1}}function jR(t){return{content:[{type:"text",text:`interaction_${t}`}],isError:!0}}function DR(t){if(!Vr(t)||!Vr(t.endpoints))throw _e("session_failed","Assistant session response is invalid",!0);let e=t.endpoints.interactions,n=t.endpoints.apps,a=t.endpoints.sandbox;if(typeof t.token!="string"||typeof t.expiresAt!="string"||typeof t.endpoints.turns!="string"||typeof t.endpoints.toolConfirmations!="string"||e!==void 0&&typeof e!="string"||n!==void 0&&typeof n!="string"||a!==void 0&&typeof a!="string")throw _e("session_failed","Assistant session response is invalid",!0);return{token:t.token,expiresAt:t.expiresAt,endpoints:{turns:t.endpoints.turns,toolConfirmations:t.endpoints.toolConfirmations,...typeof e=="string"?{interactions:e}:{},...typeof n=="string"?{apps:n}:{},...typeof a=="string"?{sandbox:a}:{}},...Vr(t.configuration)?{configuration:t.configuration}:{}}}function Vr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}async function UR(t){let e;try{e=await t.json()}catch{return}if(!(!Vr(e)||typeof e.code!="string"))return/^[A-Za-z0-9_.-]{1,64}$/.test(e.code)?e.code:void 0}function _e(t,e,n,a,r,o){return new Hr({code:t,...a===void 0?{}:{status:a},retryable:n,...o===void 0?{}:{serviceCode:o}},e,r)}function $w(t){let e=document.createElement("section");e.className="tool-proposal input-request",e.dataset.kind="input";let n=document.createElement("form"),a=document.createElement("strong");a.textContent=t.message,n.append(a);let r=ra(t.requestedSchema.properties),o=new Set(Array.isArray(t.requestedSchema.required)?t.requestedSchema.required.filter(S=>typeof S=="string"):[]),i=new Map,s=new WeakSet;for(let[S,U]of Object.entries(r)){let N=ra(U),de=document.createElement("label"),F=document.createElement("span");F.textContent=typeof N.title=="string"&&N.title?N.title:KR(S);let g=LR(S,N,o.has(S)),P=()=>{s.add(g),th(g,N,o.has(S),s.has(g))};g.addEventListener("input",P),g.addEventListener("change",P),de.append(F,g),n.append(de),i.set(S,g)}let c=document.createElement("div");c.className="proposal-actions";let u=eh(t.labels.submit,"submit"),d=eh(t.labels.decline,"button"),m=eh(t.labels.cancel,"button"),h=[u,d,m],b=async S=>{h.forEach(U=>{U.disabled=!0});try{await t.respond(S)}catch(U){throw h.forEach(N=>{N.disabled=!1}),U}};return n.addEventListener("submit",S=>{S.preventDefault();for(let[U,N]of i)th(N,ra(r[U]),o.has(U),s.has(N));n.reportValidity()&&b({action:"accept",content:ZR(i,r,o,s)}).catch(()=>{})}),d.addEventListener("click",()=>{b({action:"decline"}).catch(()=>{})}),m.addEventListener("click",()=>{b({action:"cancel"}).catch(()=>{})}),c.append(u,d,m),n.append(c),e.append(n),e}function LR(t,e,n){let a=Aw(e);if(a||e.type==="array"){let o=document.createElement("select");o.name=t,o.multiple=e.type==="array";let i=a??FR(e);!o.multiple&&(!n||!i.some(s=>s.value===e.default))&&o.append(GR(i));for(let s of i)o.append(zw(s.title,s.value));return HR(o,e.default),th(o,e,n,!1),o}let r=document.createElement("input");return r.name=t,r.type=VR(e),r.required=n&&qR(e),e.type==="integer"&&(r.step="1"),typeof e.minimum=="number"&&(r.min=String(e.minimum)),typeof e.maximum=="number"&&(r.max=String(e.maximum)),typeof e.minLength=="number"&&(r.minLength=e.minLength),typeof e.maxLength=="number"&&(r.maxLength=e.maxLength),e.format==="date-time"&&(r.step="0.001"),JR(r,e),r}function ZR(t,e,n,a){let r={};for(let[o,i]of t){let s=ra(e[o]);if(i instanceof HTMLSelectElement&&i.multiple){let c=[...i.selectedOptions].map(u=>u.value);Iw(s,n.has(o),a.has(i),c.length)&&(r[o]=c)}else if(i instanceof HTMLInputElement&&i.type==="checkbox")(n.has(o)||rh(s)||a.has(i))&&(r[o]=i.checked);else if(i instanceof HTMLSelectElement)Ew(i)||(r[o]=i.value);else if(i.value!==""||s.type==="string"&&(n.has(o)||rh(s)||a.has(i)))if(s.format==="date-time"){let c=WR(i.value);c!==void 0&&(r[o]=c)}else r[o]=s.type==="number"||s.type==="integer"?Number(i.value):i.value}return r}function th(t,e,n,a){if(t.setCustomValidity(""),!(t instanceof HTMLSelectElement))return;if(!t.multiple){t.required=n,n&&Ew(t)&&t.setCustomValidity("Please select an option.");return}let r=t.selectedOptions.length,o=Iw(e,n,a,r),i=Sw(e.minItems),s=Sw(e.maxItems);t.required=o&&i!==void 0&&i>0,o&&i!==void 0&&r<i?t.setCustomValidity(`Select at least ${i} option${i===1?"":"s"}.`):o&&s!==void 0&&r>s&&t.setCustomValidity(`Select at most ${s} option${s===1?"":"s"}.`)}function Iw(t,e,n,a){return e||rh(t)||n||a>0}function rh(t){return Object.hasOwn(t,"default")}function Sw(t){return typeof t=="number"&&Number.isInteger(t)&&t>=0?t:void 0}function qR(t){return t.type==="number"||t.type==="integer"?!0:t.type!=="string"?!1:t.format==="date"||t.format==="date-time"||t.format==="email"||t.format==="uri"||typeof t.minLength=="number"&&t.minLength>0}function Ew(t){return t.selectedOptions[0]?.dataset.placeholder==="true"}function Aw(t){return Array.isArray(t.enum)&&t.enum.every(e=>typeof e=="string")?t.enum.map(e=>({value:e,title:e})):Tw(t.oneOf)??Tw(t.anyOf)}function FR(t){return Aw(ra(t.items))??[]}function VR(t){return t.type==="boolean"?"checkbox":t.type==="number"||t.type==="integer"?"number":t.format==="date"?"date":t.format==="date-time"?"datetime-local":t.format==="email"?"email":t.format==="uri"?"url":"text"}function Tw(t){if(!Array.isArray(t))return;let e=t.map(n=>ra(n));if(e.every(n=>typeof n.const=="string"))return e.map(n=>({value:String(n.const),title:typeof n.title=="string"?n.title:String(n.const)}))}function HR(t,e){if(t.multiple){let n=new Set(Array.isArray(e)?e.filter(a=>typeof a=="string"):[]);for(let a of t.options)a.selected=n.has(a.value);return}typeof e=="string"&&(t.value=e)}function JR(t,e){let n=e.default;if(e.type==="boolean"){typeof n=="boolean"&&(t.checked=n);return}if(e.type==="number"||e.type==="integer"){typeof n=="number"&&Number.isFinite(n)&&(t.value=String(n));return}if(typeof n=="string"){if(e.format==="date-time"){t.value=BR(n)??"";return}t.value=n}}function BR(t){let e=new Date(t);if(!Number.isNaN(e.valueOf()))return[String(e.getFullYear()).padStart(4,"0"),"-",Ao(e.getMonth()+1),"-",Ao(e.getDate()),"T",Ao(e.getHours()),":",Ao(e.getMinutes()),":",Ao(e.getSeconds()),".",String(e.getMilliseconds()).padStart(3,"0")].join("")}function WR(t){let e=new Date(t);return Number.isNaN(e.valueOf())?void 0:e.toISOString()}function Ao(t){return String(t).padStart(2,"0")}function eh(t,e){let n=document.createElement("button");return n.type=e,n.textContent=t,n}function zw(t,e){let n=document.createElement("option");return n.textContent=t,n.value=e,n}function GR(t){let e="";for(;t.some(a=>a.value===e);)e+="\0";let n=zw("",e);return n.dataset.placeholder="true",n}function KR(t){let e=t.replaceAll(/([a-z0-9])([A-Z])/g,"$1 $2").replaceAll(/[_-]+/g," ");return e?`${e[0]?.toUpperCase()??""}${e.slice(1)}`:t}function ra(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{}}function Cw(t){let e=document.createElement("section");e.className="tool-proposal",e.setAttribute("aria-label",t.labels.heading);let n=document.createElement("span");n.className="proposal-eyebrow",n.textContent=t.labels.heading;let a=document.createElement("h3");if(a.textContent=t.title??Mw(t.tool),e.append(n,a),t.description){let i=document.createElement("p");i.className="proposal-description",i.textContent=t.description,e.append(i)}if(t.arguments&&Object.keys(t.arguments).length>0){let{action:i,...s}=t.arguments;if(Object.keys(s).length>0&&e.append(nh(s,t.reviewSchema,t.labels)),i!==void 0){let c=document.createElement("details");c.className="proposal-details";let u=document.createElement("summary");u.textContent=t.labels.details;let d=kr(t.reviewSchema?.properties);c.append(u);let m=kr(i);if(m)c.append(nh(m,kr(d?.action),t.labels));else{let h=document.createElement("div");ul(h,i,kr(d?.action),t.labels),c.append(h)}e.append(c)}}let r=document.createElement("div");r.className="proposal-actions";let o=[];for(let[i,s]of[[t.labels.accept,"accept"],[t.labels.decline,"decline"]]){let c=document.createElement("button");c.type="button",c.className=`proposal-${s}`,c.textContent=i,o.push(c),c.addEventListener("click",()=>{for(let u of o)u.disabled=!0;t.respond(s).catch(()=>{for(let u of o)u.disabled=!1})}),r.append(c)}return e.append(r),e}function Pw(t,e,n){let a=document.createElement("section");a.className="tool-result";let r=document.createElement("strong");r.textContent=e,a.append(r);let o=document.createElement("div");return ul(o,t,void 0,{heading:e,accept:"",decline:"",details:"",redacted:n}),a.append(o),a}function nh(t,e,n){let a=document.createElement("dl");a.className="proposal-arguments";let r=kr(e?.properties);for(let[o,i]of Object.entries(t)){let s=kr(r?.[o]),c=document.createElement("dt");c.textContent=Rw(s?.title)??Mw(o);let u=Rw(s?.description);if(u){let m=document.createElement("small");m.textContent=u,c.append(m)}let d=document.createElement("dd");ul(d,i,s,n),a.append(c,d)}return a}function ul(t,e,n,a){if(e==="[REDACTED]"){let o=document.createElement("span");o.className="proposal-redacted",o.textContent=a.redacted,t.append(o);return}if(Array.isArray(e)){let o=document.createElement("ul"),i=kr(n?.items);for(let s of e){let c=document.createElement("li");ul(c,s,i,a),o.append(c)}t.append(o);return}let r=kr(e);if(r){t.append(nh(r,n,a));return}t.textContent=YR(e,n)}function YR(t,e){if(t==null||t==="")return"Not provided";if(typeof t=="boolean")return t?"Yes":"No";if(typeof t=="number")return new Intl.NumberFormat().format(t);if(typeof t!="string")return String(t);if(e?.format==="date"){let n=new Date(`${t}T00:00:00`);if(!Number.isNaN(n.valueOf()))return new Intl.DateTimeFormat(void 0,{dateStyle:"medium"}).format(n)}if(e?.format==="date-time"){let n=new Date(t);if(!Number.isNaN(n.valueOf()))return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(n)}return t}function Mw(t){let e=t.replaceAll(/([a-z0-9])([A-Z])/g,"$1 $2").replaceAll(/[_-]+/g," ");return e?`${e[0]?.toUpperCase()??""}${e.slice(1)}`:t}function kr(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)?t:void 0}function Rw(t){return typeof t=="string"&&t.length>0?t:void 0}function Ow(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,a=Array(e);n<e;n++)a[n]=t[n];return a}function QR(t){if(Array.isArray(t))return t}function XR(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var a,r,o,i,s=[],c=!0,u=!1;try{if(o=(n=n.call(t)).next,e!==0)for(;!(c=(a=o.call(n)).done)&&(s.push(a.value),s.length!==e);c=!0);}catch(d){u=!0,r=d}finally{try{if(!c&&n.return!=null&&(i=n.return(),Object(i)!==i))return}finally{if(u)throw r}}return s}}function eC(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
148
148
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function tC(t,e){return QR(t)||XR(t,e)||rC(t,e)||eC()}function rC(t,e){if(t){if(typeof t=="string")return Ow(t,e);var n={}.toString.call(t).slice(8,-1);return n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set"?Array.from(t):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ow(t,e):void 0}}var Gw=Object.entries,Nw=Object.setPrototypeOf,nC=Object.isFrozen,aC=Object.getPrototypeOf,oC=Object.getOwnPropertyDescriptor,Fe=Object.freeze,Ve=Object.seal,aa=Object.create,Kw=typeof Reflect<"u"&&Reflect,ch=Kw.apply,uh=Kw.construct;Fe||(Fe=function(e){return e});Ve||(Ve=function(e){return e});ch||(ch=function(e,n){for(var a=arguments.length,r=new Array(a>2?a-2:0),o=2;o<a;o++)r[o-2]=arguments[o];return e.apply(n,r)});uh||(uh=function(e){for(var n=arguments.length,a=new Array(n>1?n-1:0),r=1;r<n;r++)a[r-1]=arguments[r];return new e(...a)});var zo=Ce(Array.prototype.forEach),iC=Ce(Array.prototype.lastIndexOf),jw=Ce(Array.prototype.pop),na=Ce(Array.prototype.push),sC=Ce(Array.prototype.splice),Tr=Array.isArray,Po=Ce(String.prototype.toLowerCase),ah=Ce(String.prototype.toString),Dw=Ce(String.prototype.match),Ro=Ce(String.prototype.replace),Uw=Ce(String.prototype.indexOf),lC=Ce(String.prototype.trim),cC=Ce(Number.prototype.toString),uC=Ce(Boolean.prototype.toString),Lw=typeof BigInt>"u"?null:Ce(BigInt.prototype.toString),Zw=typeof Symbol>"u"?null:Ce(Symbol.prototype.toString),Oe=Ce(Object.prototype.hasOwnProperty),Co=Ce(Object.prototype.toString),qe=Ce(RegExp.prototype.test),Jr=dC(TypeError);function Ce(t){return function(e){e instanceof RegExp&&(e.lastIndex=0);for(var n=arguments.length,a=new Array(n>1?n-1:0),r=1;r<n;r++)a[r-1]=arguments[r];return ch(t,e,a)}}function dC(t){return function(){for(var e=arguments.length,n=new Array(e),a=0;a<e;a++)n[a]=arguments[a];return uh(t,n)}}function ae(t,e){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Po;if(Nw&&Nw(t,null),!Tr(e))return t;let a=e.length;for(;a--;){let r=e[a];if(typeof r=="string"){let o=n(r);o!==r&&(nC(e)||(e[a]=o),r=o)}t[r]=!0}return t}function pC(t){for(let e=0;e<t.length;e++)Oe(t,e)||(t[e]=null);return t}function et(t){let e=aa(null);for(let a of Gw(t)){var n=tC(a,2);let r=n[0],o=n[1];Oe(t,r)&&(Tr(o)?e[r]=pC(o):o&&typeof o=="object"&&o.constructor===Object?e[r]=et(o):e[r]=o)}return e}function mC(t){switch(typeof t){case"string":return t;case"number":return cC(t);case"boolean":return uC(t);case"bigint":return Lw?Lw(t):"0";case"symbol":return Zw?Zw(t):"Symbol()";case"undefined":return Co(t);case"function":case"object":{if(t===null)return Co(t);let e=t,n=Zt(e,"toString");if(typeof n=="function"){let a=n(e);return typeof a=="string"?a:Co(a)}return Co(t)}default:return Co(t)}}function Zt(t,e){for(;t!==null;){let a=oC(t,e);if(a){if(a.get)return Ce(a.get);if(typeof a.value=="function")return Ce(a.value)}t=aC(t)}function n(){return null}return n}function fC(t){try{return qe(t,""),!0}catch{return!1}}var qw=Fe(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),oh=Fe(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),ih=Fe(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),hC=Fe(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),sh=Fe(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),gC=Fe(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),Fw=Fe(["#text"]),Vw=Fe(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","command","commandfor","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns"]),lh=Fe(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),Hw=Fe(["accent","accentunder","align","bevelled","close","columnalign","columnlines","columnspacing","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lquote","lspace","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),dl=Fe(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),vC=Ve(/{{[\w\W]*|^[\w\W]*}}/g),yC=Ve(/<%[\w\W]*|^[\w\W]*%>/g),bC=Ve(/\${[\w\W]*/g),xC=Ve(/^data-[\-\w.\u00B7-\uFFFF]+$/),_C=Ve(/^aria-[\-\w]+$/),Jw=Ve(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),wC=Ve(/^(?:\w+script|data):/i),kC=Ve(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),SC=Ve(/^html$/i),TC=Ve(/^[a-z][.\w]*(-[.\w]+)+$/i),Bw=Ve(/<[/\w!]/g),$C=Ve(/<[/\w]/g),IC=Ve(/<\/no(script|embed|frames)/i),EC=Ve(/\/>/i),Lt={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},AC=function(){return typeof window>"u"?null:window},zC=function(e,n){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let a=null,r="data-tt-policy-suffix";n&&n.hasAttribute(r)&&(a=n.getAttribute(r));let o="dompurify"+(a?"#"+a:"");try{return e.createPolicy(o,{createHTML(i){return i},createScriptURL(i){return i}})}catch{return console.warn("TrustedTypes policy "+o+" could not be created."),null}},Ww=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Sr=function(e,n,a,r){return Oe(e,n)&&Tr(e[n])?ae(r.base?et(r.base):{},e[n],r.transform):a};function Yw(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:AC(),e=A=>Yw(A);if(e.version="3.4.11",e.removed=[],!t||!t.document||t.document.nodeType!==Lt.document||!t.Element)return e.isSupported=!1,e;let n=t.document,a=n,r=a.currentScript;t.DocumentFragment;let o=t.HTMLTemplateElement,i=t.Node,s=t.Element,c=t.NodeFilter,u=t.NamedNodeMap;u===void 0&&(t.NamedNodeMap||t.MozNamedAttrMap),t.HTMLFormElement;let d=t.DOMParser,m=t.trustedTypes,h=s.prototype,b=Zt(h,"cloneNode"),S=Zt(h,"remove"),U=Zt(h,"nextSibling"),N=Zt(h,"childNodes"),de=Zt(h,"parentNode"),F=Zt(h,"shadowRoot"),g=Zt(h,"attributes"),P=i&&i.prototype?Zt(i.prototype,"nodeType"):null,H=i&&i.prototype?Zt(i.prototype,"nodeName"):null;if(typeof o=="function"){let A=n.createElement("template");A.content&&A.content.ownerDocument&&(n=A.content.ownerDocument)}let V,B="",xe,bt=!1,$r=0,$h=function(){if($r>0)throw Jr('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},Gr=function(p){$h(),$r++;try{return V.createHTML(p)}finally{$r--}},zk=function(p){$h(),$r++;try{return V.createScriptURL(p)}finally{$r--}},Rk=function(){return bt||(xe=zC(m,r),bt=!0),xe},Zo=n,kl=Zo.implementation,Ih=Zo.createNodeIterator,Ck=Zo.createDocumentFragment,Pk=Zo.getElementsByTagName,Mk=a.importNode,Ee=Ww();e.isSupported=typeof Gw=="function"&&typeof de=="function"&&kl&&kl.createHTMLDocument!==void 0;let Ok=vC,Nk=yC,jk=bC,Dk=xC,Uk=_C,Lk=wC,Eh=kC,Zk=TC,Ah=Jw,ke=null,zh=ae({},[...qw,...oh,...ih,...sh,...Fw]),Se=null,Rh=ae({},[...Vw,...lh,...Hw,...dl]),Te=Object.seal(aa(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),ia=null,Ch=null,tr=Object.seal(aa(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),Ph=!0,Sl=!0,Mh=!1,Oh=!0,rr=!1,sa=!0,Ir=!1,Tl=!1,$l=null,Il=null,El=!1,Kr=!1,qo=!1,Fo=!1,Nh=!0,jh=!1,Dh="user-content-",Al=!0,zl=!1,Yr={},zt=null,Rl=ae({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]),Uh=null,Lh=ae({},["audio","video","img","source","image","track"]),Cl=null,Zh=ae({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Vo="http://www.w3.org/1998/Math/MathML",Ho="http://www.w3.org/2000/svg",Rt="http://www.w3.org/1999/xhtml",Qr=Rt,Pl=!1,Ml=null,qk=ae({},[Vo,Ho,Rt],ah),qh=Fe(["mi","mo","mn","ms","mtext"]),Ol=ae({},qh),Fh=Fe(["annotation-xml"]),Nl=ae({},Fh),Fk=ae({},["title","style","font","a","script"]),la=null,Vk=["application/xhtml+xml","text/html"],Hk="text/html",$e=null,Xr=null,Jk=n.createElement("form"),Vh=function(p){return p instanceof RegExp||p instanceof Function},jl=function(){let p=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(Xr&&Xr===p)return;(!p||typeof p!="object")&&(p={}),p=et(p),la=Vk.indexOf(p.PARSER_MEDIA_TYPE)===-1?Hk:p.PARSER_MEDIA_TYPE,$e=la==="application/xhtml+xml"?ah:Po,ke=Sr(p,"ALLOWED_TAGS",zh,{transform:$e}),Se=Sr(p,"ALLOWED_ATTR",Rh,{transform:$e}),Ml=Sr(p,"ALLOWED_NAMESPACES",qk,{transform:ah}),Cl=Sr(p,"ADD_URI_SAFE_ATTR",Zh,{transform:$e,base:Zh}),Uh=Sr(p,"ADD_DATA_URI_TAGS",Lh,{transform:$e,base:Lh}),zt=Sr(p,"FORBID_CONTENTS",Rl,{transform:$e}),ia=Sr(p,"FORBID_TAGS",et({}),{transform:$e}),Ch=Sr(p,"FORBID_ATTR",et({}),{transform:$e}),Yr=Oe(p,"USE_PROFILES")?p.USE_PROFILES&&typeof p.USE_PROFILES=="object"?et(p.USE_PROFILES):p.USE_PROFILES:!1,Ph=p.ALLOW_ARIA_ATTR!==!1,Sl=p.ALLOW_DATA_ATTR!==!1,Mh=p.ALLOW_UNKNOWN_PROTOCOLS||!1,Oh=p.ALLOW_SELF_CLOSE_IN_ATTR!==!1,rr=p.SAFE_FOR_TEMPLATES||!1,sa=p.SAFE_FOR_XML!==!1,Ir=p.WHOLE_DOCUMENT||!1,Kr=p.RETURN_DOM||!1,qo=p.RETURN_DOM_FRAGMENT||!1,Fo=p.RETURN_TRUSTED_TYPE||!1,El=p.FORCE_BODY||!1,Nh=p.SANITIZE_DOM!==!1,jh=p.SANITIZE_NAMED_PROPS||!1,Al=p.KEEP_CONTENT!==!1,zl=p.IN_PLACE||!1,Ah=fC(p.ALLOWED_URI_REGEXP)?p.ALLOWED_URI_REGEXP:Jw,Qr=typeof p.NAMESPACE=="string"?p.NAMESPACE:Rt,Ol=Oe(p,"MATHML_TEXT_INTEGRATION_POINTS")&&p.MATHML_TEXT_INTEGRATION_POINTS&&typeof p.MATHML_TEXT_INTEGRATION_POINTS=="object"?et(p.MATHML_TEXT_INTEGRATION_POINTS):ae({},qh),Nl=Oe(p,"HTML_INTEGRATION_POINTS")&&p.HTML_INTEGRATION_POINTS&&typeof p.HTML_INTEGRATION_POINTS=="object"?et(p.HTML_INTEGRATION_POINTS):ae({},Fh);let v=Oe(p,"CUSTOM_ELEMENT_HANDLING")&&p.CUSTOM_ELEMENT_HANDLING&&typeof p.CUSTOM_ELEMENT_HANDLING=="object"?et(p.CUSTOM_ELEMENT_HANDLING):aa(null);if(Te=aa(null),Oe(v,"tagNameCheck")&&Vh(v.tagNameCheck)&&(Te.tagNameCheck=v.tagNameCheck),Oe(v,"attributeNameCheck")&&Vh(v.attributeNameCheck)&&(Te.attributeNameCheck=v.attributeNameCheck),Oe(v,"allowCustomizedBuiltInElements")&&typeof v.allowCustomizedBuiltInElements=="boolean"&&(Te.allowCustomizedBuiltInElements=v.allowCustomizedBuiltInElements),Ve(Te),rr&&(Sl=!1),qo&&(Kr=!0),Yr&&(ke=ae({},Fw),Se=aa(null),Yr.html===!0&&(ae(ke,qw),ae(Se,Vw)),Yr.svg===!0&&(ae(ke,oh),ae(Se,lh),ae(Se,dl)),Yr.svgFilters===!0&&(ae(ke,ih),ae(Se,lh),ae(Se,dl)),Yr.mathMl===!0&&(ae(ke,sh),ae(Se,Hw),ae(Se,dl))),tr.tagCheck=null,tr.attributeCheck=null,Oe(p,"ADD_TAGS")&&(typeof p.ADD_TAGS=="function"?tr.tagCheck=p.ADD_TAGS:Tr(p.ADD_TAGS)&&(ke===zh&&(ke=et(ke)),ae(ke,p.ADD_TAGS,$e))),Oe(p,"ADD_ATTR")&&(typeof p.ADD_ATTR=="function"?tr.attributeCheck=p.ADD_ATTR:Tr(p.ADD_ATTR)&&(Se===Rh&&(Se=et(Se)),ae(Se,p.ADD_ATTR,$e))),Oe(p,"ADD_URI_SAFE_ATTR")&&Tr(p.ADD_URI_SAFE_ATTR)&&ae(Cl,p.ADD_URI_SAFE_ATTR,$e),Oe(p,"FORBID_CONTENTS")&&Tr(p.FORBID_CONTENTS)&&(zt===Rl&&(zt=et(zt)),ae(zt,p.FORBID_CONTENTS,$e)),Oe(p,"ADD_FORBID_CONTENTS")&&Tr(p.ADD_FORBID_CONTENTS)&&(zt===Rl&&(zt=et(zt)),ae(zt,p.ADD_FORBID_CONTENTS,$e)),Al&&(ke["#text"]=!0),Ir&&ae(ke,["html","head","body"]),ke.table&&(ae(ke,["tbody"]),delete ia.tbody),p.TRUSTED_TYPES_POLICY){if(typeof p.TRUSTED_TYPES_POLICY.createHTML!="function")throw Jr('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof p.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Jr('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');let E=V;V=p.TRUSTED_TYPES_POLICY;try{B=Gr("")}catch(L){throw V=E,L}}else p.TRUSTED_TYPES_POLICY===null?(V=void 0,B=""):(V===void 0&&(V=Rk()),V&&typeof B=="string"&&(B=Gr("")));Fe&&Fe(p),Xr=p},Hh=ae({},[...oh,...ih,...hC]),Jh=ae({},[...sh,...gC]),Bk=function(p,v,E){return v.namespaceURI===Rt?p==="svg":v.namespaceURI===Vo?p==="svg"&&(E==="annotation-xml"||Ol[E]):!!Hh[p]},Wk=function(p,v,E){return v.namespaceURI===Rt?p==="math":v.namespaceURI===Ho?p==="math"&&Nl[E]:!!Jh[p]},Gk=function(p,v,E){return v.namespaceURI===Ho&&!Nl[E]||v.namespaceURI===Vo&&!Ol[E]?!1:!Jh[p]&&(Fk[p]||!Hh[p])},Kk=function(p){let v=de(p);(!v||!v.tagName)&&(v={namespaceURI:Qr,tagName:"template"});let E=Po(p.tagName),L=Po(v.tagName);return Ml[p.namespaceURI]?p.namespaceURI===Ho?Bk(E,v,L):p.namespaceURI===Vo?Wk(E,v,L):p.namespaceURI===Rt?Gk(E,v,L):!!(la==="application/xhtml+xml"&&Ml[p.namespaceURI]):!1},nr=function(p){na(e.removed,{element:p});try{de(p).removeChild(p)}catch{if(S(p),!de(p))throw Jr("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},Bh=function(p){let v=N(p);if(v){let L=[];zo(v,Y=>{na(L,Y)}),zo(L,Y=>{try{S(Y)}catch{}})}let E=g(p);if(E)for(let L=E.length-1;L>=0;--L){let Y=E[L],oe=Y&&Y.name;if(typeof oe=="string")try{p.removeAttribute(oe)}catch{}}},Er=function(p,v){try{na(e.removed,{attribute:v.getAttributeNode(p),from:v})}catch{na(e.removed,{attribute:null,from:v})}if(v.removeAttribute(p),p==="is")if(Kr||qo)try{nr(v)}catch{}else try{v.setAttribute(p,"")}catch{}},Yk=function(p){let v=g(p);if(v)for(let E=v.length-1;E>=0;--E){let L=v[E],Y=L&&L.name;if(!(typeof Y!="string"||Se[$e(Y)]))try{p.removeAttribute(Y)}catch{}}},Qk=function(p){let v=[p];for(;v.length>0;){let E=v.pop();(P?P(E):E.nodeType)===Lt.element&&Yk(E);let Y=N(E);if(Y)for(let oe=Y.length-1;oe>=0;--oe)v.push(Y[oe])}},Wh=function(p){let v=null,E=null;if(El)p="<remove></remove>"+p;else{let oe=Dw(p,/^[\r\n\t ]+/);E=oe&&oe[0]}la==="application/xhtml+xml"&&Qr===Rt&&(p='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+p+"</body></html>");let L=V?Gr(p):p;if(Qr===Rt)try{v=new d().parseFromString(L,la)}catch{}if(!v||!v.documentElement){v=kl.createDocument(Qr,"template",null);try{v.documentElement.innerHTML=Pl?B:L}catch{}}let Y=v.body||v.documentElement;return p&&E&&Y.insertBefore(n.createTextNode(E),Y.childNodes[0]||null),Qr===Rt?Pk.call(v,Ir?"html":"body")[0]:Ir?v.documentElement:Y},Gh=function(p){return Ih.call(p.ownerDocument||p,p,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},Jo=function(p){return p=Ro(p,Ok," "),p=Ro(p,Nk," "),p=Ro(p,jk," "),p},Dl=function(p){var v;p.normalize();let E=Ih.call(p.ownerDocument||p,p,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),L=E.nextNode();for(;L;)L.data=Jo(L.data),L=E.nextNode();let Y=(v=p.querySelectorAll)===null||v===void 0?void 0:v.call(p,"template");Y&&zo(Y,oe=>{en(oe.content)&&Dl(oe.content)})},Bo=function(p){let v=H?H(p):null;return typeof v!="string"||$e(v)!=="form"?!1:typeof p.nodeName!="string"||typeof p.textContent!="string"||typeof p.removeChild!="function"||p.attributes!==g(p)||typeof p.removeAttribute!="function"||typeof p.setAttribute!="function"||typeof p.namespaceURI!="string"||typeof p.insertBefore!="function"||typeof p.hasChildNodes!="function"||p.nodeType!==P(p)||p.childNodes!==N(p)},en=function(p){if(!P||typeof p!="object"||p===null)return!1;try{return P(p)===Lt.documentFragment}catch{return!1}},ca=function(p){if(!P||typeof p!="object"||p===null)return!1;try{return typeof P(p)=="number"}catch{return!1}};function Ft(A,p,v){A.length!==0&&zo(A,E=>{E.call(e,p,v,Xr)})}let Xk=function(p,v){return!!(sa&&p.hasChildNodes()&&!ca(p.firstElementChild)&&qe(Bw,p.textContent)&&qe(Bw,p.innerHTML)||sa&&p.namespaceURI===Rt&&v==="style"&&ca(p.firstElementChild)||p.nodeType===Lt.processingInstruction||sa&&p.nodeType===Lt.comment&&qe($C,p.data))},eS=function(p,v){if(!ia[v]&&Qh(v)&&(Te.tagNameCheck instanceof RegExp&&qe(Te.tagNameCheck,v)||Te.tagNameCheck instanceof Function&&Te.tagNameCheck(v)))return!1;if(Al&&!zt[v]){let E=de(p),L=N(p);if(L&&E){let Y=L.length;for(let oe=Y-1;oe>=0;--oe){let Me=zl?L[oe]:b(L[oe],!0);E.insertBefore(Me,U(p))}}}return nr(p),!0},Kh=function(p){if(Ft(Ee.beforeSanitizeElements,p,null),Bo(p))return nr(p),!0;let v=$e(H?H(p):p.nodeName);if(Ft(Ee.uponSanitizeElement,p,{tagName:v,allowedTags:ke}),Xk(p,v))return nr(p),!0;if(ia[v]||!(tr.tagCheck instanceof Function&&tr.tagCheck(v))&&!ke[v])return eS(p,v);if((P?P(p):p.nodeType)===Lt.element&&!Kk(p)||(v==="noscript"||v==="noembed"||v==="noframes")&&qe(IC,p.innerHTML))return nr(p),!0;if(rr&&p.nodeType===Lt.text){let L=Jo(p.textContent);p.textContent!==L&&(na(e.removed,{element:p.cloneNode()}),p.textContent=L)}return Ft(Ee.afterSanitizeElements,p,null),!1},Yh=function(p,v,E){if(Ch[v]||Nh&&(v==="id"||v==="name")&&(E in n||E in Jk))return!1;let L=Se[v]||tr.attributeCheck instanceof Function&&tr.attributeCheck(v,p);if(!(Sl&&qe(Dk,v))){if(!(Ph&&qe(Uk,v))){if(L){if(!Cl[v]){if(!qe(Ah,Ro(E,Eh,""))){if(!((v==="src"||v==="xlink:href"||v==="href")&&p!=="script"&&Uw(E,"data:")===0&&Uh[p])){if(!(Mh&&!qe(Lk,Ro(E,Eh,"")))){if(E)return!1}}}}}else if(!(Qh(p)&&(Te.tagNameCheck instanceof RegExp&&qe(Te.tagNameCheck,p)||Te.tagNameCheck instanceof Function&&Te.tagNameCheck(p))&&(Te.attributeNameCheck instanceof RegExp&&qe(Te.attributeNameCheck,v)||Te.attributeNameCheck instanceof Function&&Te.attributeNameCheck(v,p))||v==="is"&&Te.allowCustomizedBuiltInElements&&(Te.tagNameCheck instanceof RegExp&&qe(Te.tagNameCheck,E)||Te.tagNameCheck instanceof Function&&Te.tagNameCheck(E))))return!1}}return!0},tS=ae({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),Qh=function(p){return!tS[Po(p)]&&qe(Zk,p)},rS=function(p,v,E,L){if(V&&typeof m=="object"&&typeof m.getAttributeType=="function"&&!E)switch(m.getAttributeType(p,v)){case"TrustedHTML":return Gr(L);case"TrustedScriptURL":return zk(L)}return L},nS=function(p,v,E,L){try{E?p.setAttributeNS(E,v,L):p.setAttribute(v,L),Bo(p)?nr(p):jw(e.removed)}catch{Er(v,p)}},Xh=function(p){Ft(Ee.beforeSanitizeAttributes,p,null);let v=p.attributes;if(!v||Bo(p))return;let E={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:Se,forceKeepAttr:void 0},L=v.length,Y=$e(p.nodeName);for(;L--;){let oe=v[L],Me=oe.name,ze=oe.namespaceURI,mt=oe.value,xt=$e(Me),Ll=mt,Be=Me==="value"?Ll:lC(Ll);if(E.attrName=xt,E.attrValue=Be,E.keepAttr=!0,E.forceKeepAttr=void 0,Ft(Ee.uponSanitizeAttribute,p,E),Be=E.attrValue,jh&&(xt==="id"||xt==="name")&&Uw(Be,Dh)!==0&&(Er(Me,p),Be=Dh+Be),sa&&qe(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,Be)){Er(Me,p);continue}if(xt==="attributename"&&Dw(Be,"href")){Er(Me,p);continue}if(!E.forceKeepAttr){if(!E.keepAttr){Er(Me,p);continue}if(!Oh&&qe(EC,Be)){Er(Me,p);continue}if(rr&&(Be=Jo(Be)),!Yh(Y,xt,Be)){Er(Me,p);continue}Be=rS(Y,xt,ze,Be),Be!==Ll&&nS(p,Me,ze,Be)}}Ft(Ee.afterSanitizeAttributes,p,null)},Wo=function(p){let v=null,E=Gh(p);for(Ft(Ee.beforeSanitizeShadowDOM,p,null);v=E.nextNode();)if(Ft(Ee.uponSanitizeShadowNode,v,null),Kh(v),Xh(v),en(v.content)&&Wo(v.content),(P?P(v):v.nodeType)===Lt.element){let Y=F(v);en(Y)&&(Ul(Y),Wo(Y))}Ft(Ee.afterSanitizeShadowDOM,p,null)},Ul=function(p){let v=[{node:p,shadow:null}];for(;v.length>0;){let E=v.pop();if(E.shadow){Wo(E.shadow);continue}let L=E.node,oe=(P?P(L):L.nodeType)===Lt.element,Me=N(L);if(Me)for(let ze=Me.length-1;ze>=0;--ze)v.push({node:Me[ze],shadow:null});if(oe){let ze=H?H(L):null;if(typeof ze=="string"&&$e(ze)==="template"){let mt=L.content;en(mt)&&v.push({node:mt,shadow:null})}}if(oe){let ze=F(L);en(ze)&&v.push({node:null,shadow:ze},{node:ze,shadow:null})}}};return e.sanitize=function(A){let p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},v=null,E=null,L=null,Y=null;if(Pl=!A,Pl&&(A="<!-->"),typeof A!="string"&&!ca(A)&&(A=mC(A),typeof A!="string"))throw Jr("dirty is not a string, aborting");if(!e.isSupported)return A;Tl?(ke=$l,Se=Il):jl(p),(Ee.uponSanitizeElement.length>0||Ee.uponSanitizeAttribute.length>0)&&(ke=et(ke)),Ee.uponSanitizeAttribute.length>0&&(Se=et(Se)),e.removed=[];let oe=zl&&typeof A!="string"&&ca(A);if(oe){let mt=H?H(A):A.nodeName;if(typeof mt=="string"){let xt=$e(mt);if(!ke[xt]||ia[xt])throw Jr("root node is forbidden and cannot be sanitized in-place")}if(Bo(A))throw Jr("root node is clobbered and cannot be sanitized in-place");try{Ul(A)}catch(xt){throw Bh(A),xt}}else if(ca(A))v=Wh("<!---->"),E=v.ownerDocument.importNode(A,!0),E.nodeType===Lt.element&&E.nodeName==="BODY"||E.nodeName==="HTML"?v=E:v.appendChild(E),Ul(E);else{if(!Kr&&!rr&&!Ir&&A.indexOf("<")===-1)return V&&Fo?Gr(A):A;if(v=Wh(A),!v)return Kr?null:Fo?B:""}v&&El&&nr(v.firstChild);let Me=Gh(oe?A:v);try{for(;L=Me.nextNode();)Kh(L),Xh(L),en(L.content)&&Wo(L.content)}catch(mt){throw oe&&Bh(A),mt}if(oe)return zo(e.removed,mt=>{mt.element&&Qk(mt.element)}),rr&&Dl(A),A;if(Kr){if(rr&&Dl(v),qo)for(Y=Ck.call(v.ownerDocument);v.firstChild;)Y.appendChild(v.firstChild);else Y=v;return(Se.shadowroot||Se.shadowrootmode)&&(Y=Mk.call(a,Y,!0)),Y}let ze=Ir?v.outerHTML:v.innerHTML;return Ir&&ke["!doctype"]&&v.ownerDocument&&v.ownerDocument.doctype&&v.ownerDocument.doctype.name&&qe(SC,v.ownerDocument.doctype.name)&&(ze="<!DOCTYPE "+v.ownerDocument.doctype.name+`>
149
149
  `+ze),rr&&(ze=Jo(ze)),V&&Fo?Gr(ze):ze},e.setConfig=function(){let A=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};jl(A),Tl=!0,$l=ke,Il=Se},e.clearConfig=function(){Xr=null,Tl=!1,$l=null,Il=null,V=xe,B=""},e.isValidAttribute=function(A,p,v){Xr||jl({});let E=$e(A),L=$e(p);return Yh(E,L,v)},e.addHook=function(A,p){typeof p=="function"&&Oe(Ee,A)&&na(Ee[A],p)},e.removeHook=function(A,p){if(Oe(Ee,A)){if(p!==void 0){let v=iC(Ee[A],p);return v===-1?void 0:sC(Ee[A],v,1)[0]}return jw(Ee[A])}},e.removeHooks=function(A){Oe(Ee,A)&&(Ee[A]=[])},e.removeAllHooks=function(){Ee=Ww()},e}var Qw=Yw();function fh(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Wr=fh();function ok(t){Wr=t}var jo={exec:()=>null};function le(t,e=""){let n=typeof t=="string"?t:t.source,a={replace:(r,o)=>{let i=typeof o=="string"?o:o.source;return i=i.replace(tt.caret,"$1"),n=n.replace(r,i),a},getRegex:()=>new RegExp(n,e)};return a}var RC=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),tt={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:t=>new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i")},CC=/^(?:[ \t]*(?:\n|$))+/,PC=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,MC=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Do=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,OC=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hh=/(?:[*+-]|\d{1,9}[.)])/,ik=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,sk=le(ik).replace(/bull/g,hh).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),NC=le(ik).replace(/bull/g,hh).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),gh=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,jC=/^[^\n]+/,vh=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,DC=le(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",vh).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),UC=le(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,hh).getRegex(),gl="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",yh=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,LC=le("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",yh).replace("tag",gl).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),lk=le(gh).replace("hr",Do).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",gl).getRegex(),ZC=le(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",lk).getRegex(),bh={blockquote:ZC,code:PC,def:DC,fences:MC,heading:OC,hr:Do,html:LC,lheading:sk,list:UC,newline:CC,paragraph:lk,table:jo,text:jC},Xw=le("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Do).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",gl).getRegex(),qC={...bh,lheading:NC,table:Xw,paragraph:le(gh).replace("hr",Do).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Xw).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",gl).getRegex()},FC={...bh,html:le(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",yh).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:jo,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:le(gh).replace("hr",Do).replace("heading",` *#{1,6} *[^
150
150
  ]`).replace("lheading",sk).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},VC=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,HC=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ck=/^( {2,}|\\)\n(?!\s*$)/,JC=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,vl=/[\p{P}\p{S}]/u,xh=/[\s\p{P}\p{S}]/u,uk=/[^\s\p{P}\p{S}]/u,BC=le(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,xh).getRegex(),dk=/(?!~)[\p{P}\p{S}]/u,WC=/(?!~)[\s\p{P}\p{S}]/u,GC=/(?:[^\s\p{P}\p{S}]|~)/u,KC=le(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",RC?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),pk=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,YC=le(pk,"u").replace(/punct/g,vl).getRegex(),QC=le(pk,"u").replace(/punct/g,dk).getRegex(),mk="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",XC=le(mk,"gu").replace(/notPunctSpace/g,uk).replace(/punctSpace/g,xh).replace(/punct/g,vl).getRegex(),eP=le(mk,"gu").replace(/notPunctSpace/g,GC).replace(/punctSpace/g,WC).replace(/punct/g,dk).getRegex(),tP=le("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,uk).replace(/punctSpace/g,xh).replace(/punct/g,vl).getRegex(),rP=le(/\\(punct)/,"gu").replace(/punct/g,vl).getRegex(),nP=le(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),aP=le(yh).replace("(?:-->|$)","-->").getRegex(),oP=le("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",aP).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),ml=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,iP=le(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",ml).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),fk=le(/^!?\[(label)\]\[(ref)\]/).replace("label",ml).replace("ref",vh).getRegex(),hk=le(/^!?\[(ref)\](?:\[\])?/).replace("ref",vh).getRegex(),sP=le("reflink|nolink(?!\\()","g").replace("reflink",fk).replace("nolink",hk).getRegex(),ek=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,_h={_backpedal:jo,anyPunctuation:rP,autolink:nP,blockSkip:KC,br:ck,code:HC,del:jo,emStrongLDelim:YC,emStrongRDelimAst:XC,emStrongRDelimUnd:tP,escape:VC,link:iP,nolink:hk,punctuation:BC,reflink:fk,reflinkSearch:sP,tag:oP,text:JC,url:jo},lP={..._h,link:le(/^!?\[(label)\]\((.*?)\)/).replace("label",ml).getRegex(),reflink:le(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ml).getRegex()},dh={..._h,emStrongRDelimAst:eP,emStrongLDelim:QC,url:le(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",ek).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:le(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",ek).getRegex()},cP={...dh,br:le(ck).replace("{2,}","*").getRegex(),text:le(dh.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},pl={normal:bh,gfm:qC,pedantic:FC},Mo={normal:_h,gfm:dh,breaks:cP,pedantic:lP},uP={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},tk=t=>uP[t];function qt(t,e){if(e){if(tt.escapeTest.test(t))return t.replace(tt.escapeReplace,tk)}else if(tt.escapeTestNoEncode.test(t))return t.replace(tt.escapeReplaceNoEncode,tk);return t}function rk(t){try{t=encodeURI(t).replace(tt.percentDecode,"%")}catch{return null}return t}function nk(t,e){let n=t.replace(tt.findPipe,(o,i,s)=>{let c=!1,u=i;for(;--u>=0&&s[u]==="\\";)c=!c;return c?"|":" |"}),a=n.split(tt.splitPipe),r=0;if(a[0].trim()||a.shift(),a.length>0&&!a.at(-1)?.trim()&&a.pop(),e)if(a.length>e)a.splice(e);else for(;a.length<e;)a.push("");for(;r<a.length;r++)a[r]=a[r].trim().replace(tt.slashPipe,"|");return a}function Oo(t,e,n){let a=t.length;if(a===0)return"";let r=0;for(;r<a;){let o=t.charAt(a-r-1);if(o===e&&!n)r++;else if(o!==e&&n)r++;else break}return t.slice(0,a-r)}function dP(t,e){if(t.indexOf(e[1])===-1)return-1;let n=0;for(let a=0;a<t.length;a++)if(t[a]==="\\")a++;else if(t[a]===e[0])n++;else if(t[a]===e[1]&&(n--,n<0))return a;return n>0?-2:-1}function ak(t,e,n,a,r){let o=e.href,i=e.title||null,s=t[1].replace(r.other.outputLinkReplace,"$1");a.state.inLink=!0;let c={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:o,title:i,text:s,tokens:a.inlineTokens(s)};return a.state.inLink=!1,c}function pP(t,e,n){let a=t.match(n.other.indentCodeCompensation);if(a===null)return e;let r=a[1];return e.split(`
@@ -519,7 +519,7 @@ Please report this to https://github.com/markedjs/marked.`,t){let a="<p>An error
519
519
  @media (prefers-reduced-motion: reduce) {
520
520
  .launcher, .launcher-status { animation: none !important; }
521
521
  }
522
- </style>`;var Lo="noodle-assistant",SP=globalThis.HTMLElement??class{},Th=class extends SP{static observedAttributes=["open","theme"];#e=Pf();#t;#i="";#n;#a;#o=0;#r;#l;#u;#d;#s;#p;#m;#g="idle";#v=!1;#y;#b=new Set;#_=new Map;#f=new _l;sessionEndpoint="";embedId="";serviceUrl="";get appearance(){return this.#y}set appearance(e){this.#y=e,this.#b.clear(),this.isConnected&&this.#S()}#h=new xl({element:this,messages:()=>this.#r,appendMessage:(e,n)=>{if(e==="user"&&n===this.#m){this.#m=void 0;return}return this.#M(e,n)},applyConfiguration:e=>{this.#e=Pf(e),this.#F(),this.#N()},labels:()=>this.#e.labels,respond:(e,n)=>this.respond(e,n),dispatchError:e=>this.#A(e),revealLatest:()=>this.#$(),renderView:e=>{let n=this.#r,a=this.#t;if(!n||!a)return;let r=a.appSandboxUrl?.(),o=Cx(e,{client:a,sendMessage:i=>this.sendMessage(i),updateModelContext:i=>this.updateModelContext(i),theme:this.#k()},{...r===void 0?{}:{sandboxUrl:r},onRenderFailure:i=>this.#A(i)});o&&(n.append(o),this.setAttribute("has-messages",""),this.#$())}});connectedCallback(){this.shadowRoot||this.attachShadow({mode:"open"}),this.sessionEndpoint||(this.sessionEndpoint=this.getAttribute("session-endpoint")??""),this.embedId||(this.embedId=this.getAttribute("embed-id")??""),this.serviceUrl||(this.serviceUrl=this.getAttribute("service-url")??""),this.#u=globalThis.matchMedia?.("(prefers-color-scheme: dark)"),this.#u?.addEventListener("change",this.#T),document.addEventListener("keydown",this.#R),document.addEventListener("pointerdown",this.#C),this.#e.behavior.startOpen&&this.#N(),this.#V(),this.dispatchEvent(new CustomEvent("assistant-ready")),this.#P()}disconnectedCallback(){this.#o+=1,this.#t?.abort(),this.#n?.(),this.#t=void 0,this.#i="",this.#n=void 0,this.#a=void 0,this.#f.disconnect(),this.#x(!1),this.#u?.removeEventListener("change",this.#T),document.removeEventListener("keydown",this.#R),document.removeEventListener("pointerdown",this.#C)}attributeChangedCallback(e){e==="theme"&&this.#S(),e==="open"&&this.#q()}open(){this.setAttribute("open",""),this.dispatchEvent(new CustomEvent("assistant-open"))}close(){this.removeAttribute("open"),this.dispatchEvent(new CustomEvent("assistant-close"))}toggle(){this.hasAttribute("open")?this.close():this.open()}focusComposer(){this.shadowRoot?.querySelector("textarea")?.focus()}stop(){this.hasAttribute("busy")&&(this.#o+=1,this.#t?.abort(),this.#x(!1),this.#U(this.#e.labels.stopped),this.dispatchEvent(new CustomEvent("assistant-stopped")))}resetSession(){this.#o+=1,this.#t?.abort(),this.#n?.(),this.#t=void 0,this.#i="",this.#n=void 0,this.#a=void 0,this.#h.resetConversation(),this.#m=void 0,this.removeAttribute("has-messages"),this.#x(!1),this.#w("idle")}reconnect(){this.#o+=1,this.#t?.abort(),this.#n?.(),this.#t=void 0,this.#i="",this.#n=void 0,this.#a=void 0,this.#x(!1),this.#w("loading"),this.#P(),this.dispatchEvent(new CustomEvent("assistant-reconnecting"))}updateContext(e){this.#d={...e},this.#t?this.#t.updateContext(this.#d):this.dispatchEvent(new CustomEvent("assistant-context-changed",{detail:{context:this.#d}}))}updateModelContext(e){this.#s=Io(e),this.#t?this.#t.updateModelContext(this.#s):this.dispatchEvent(new CustomEvent("assistant-model-context-changed",{detail:{modelContext:this.#s}}))}updatePageContext(e){this.#p=e,this.#t?.updatePageContext(e),this.dispatchEvent(new CustomEvent("assistant-page-context-changed",{detail:{pageContext:e}}))}async sendMessage(e){let n=e.trim();if(!n)return;let a=this.#o;this.#m=n,this.#M("user",n),this.#x(!0),this.#g!=="ready"&&this.#w("loading");try{if(await this.#a,a!==this.#o)return;await this.#I().sendMessage(n)}catch(r){if(a!==this.#o||r instanceof Hr&&r.detail.code==="request_aborted")return;throw this.#z(r,"turn_failed"),r}finally{this.#m===n&&(this.#m=void 0),a===this.#o&&this.#x(!1)}}#c(e){this.sendMessage(e).catch(()=>{})}async confirmTool(e){await this.respond(e,{action:"accept"})}async respond(e,n){let a=this.#o;this.#x(!0);try{await this.#I().respond(e,n)}catch(r){if(a!==this.#o)return;throw this.#z(r,"confirmation_failed"),r}finally{a===this.#o&&this.#x(!1)}}#T=()=>this.#S();#R=e=>{e.key==="Escape"&&this.hasAttribute("open")&&this.#e.behavior.closeOnEscape&&this.#O()};#C=e=>{this.hasAttribute("open")&&this.#e.behavior.closeOnOutsideClick&&!e.composedPath().includes(this)&&this.close()};#I(){let e=bw(this);if(this.#t&&this.#i===e)return this.#t;this.#t?.abort(),this.#n?.(),this.#a=void 0;let n={...this.#d?{context:this.#d}:{},clientContext:Dx,...this.#p?{pageContext:this.#p}:{},...this.#s?{modelContext:this.#s}:{}},a=this.embedId?Xf({embedId:this.embedId,...this.serviceUrl?{serviceUrl:this.serviceUrl}:{},...n}):Xf({sessionEndpoint:this.sessionEndpoint,...n});return this.#t=a,this.#i=e,this.#n=a.subscribe(r=>{this.#t===a&&this.#D(r)}),a}#P(){if(!this.sessionEndpoint&&!this.embedId)return;let e=this.#I(),n=this.#o;this.#w("loading");let a=e.connect().catch(r=>{n!==this.#o||this.#t!==e||this.#z(r,"session_failed")}).finally(()=>{this.#a===a&&(this.#a=void 0)});this.#a=a}#D(e){this.dispatchEvent(new CustomEvent("assistant-event",{detail:e})),this.#h.handle(e),e.event==="session_started"&&(this.#w("ready"),this.#r?.querySelector(".conversation-error")?.remove()),(e.event==="session_expired"||e.event==="session_reset")&&this.#w("idle"),(e.event==="tool_proposed"||e.event==="interaction_proposed"||e.event==="input_requested")&&(this.#E(),this.setAttribute("has-messages","")),(e.event==="content"||e.event==="message_completed"||e.event==="interaction_completed"||e.event==="error")&&this.#E()}#x(e){this.toggleAttribute("busy",e);let n=this.shadowRoot?.querySelector("textarea"),a=this.shadowRoot?.querySelector(".send");if(n&&(n.disabled=!1),a&&(a.dataset.action=e?"stop":"send",a.textContent=e?this.#e.labels.stop:this.#e.labels.send,a.setAttribute("aria-label",a.textContent)),!e){this.#E();return}if(!this.#r||this.#l)return;let r=document.createElement("div");r.className="message assistant thinking";let o=document.createElement("span");o.textContent=this.#e.labels.thinking,r.append(o),this.#r.append(r),this.#l=r,this.#L()}#E(){this.#l?.remove(),this.#l=void 0}#M(e,n){if(!this.#r)return;let a=document.createElement("div");if(a.className=`message ${e}`,e==="assistant"&&this.#e.behavior.showAvatars&&this.#e.brand.avatar[this.#k()]){let o=document.createElement("img");o.className="avatar",o.src=this.#e.brand.avatar[this.#k()]??"",o.alt="",a.append(o)}let r=document.createElement(e==="assistant"?"div":"span");if(e==="assistant"?(r.className="markdown",r.innerHTML=yl(n)):r.textContent=n,a.append(r),e==="assistant"&&n){let o=document.createElement("button");o.type="button",o.className="message-copy",o.textContent=this.#e.labels.copy,o.addEventListener("click",()=>{navigator.clipboard?.writeText(n)}),a.append(o)}if(this.#e.behavior.showTimestamps){let o=document.createElement("time");o.dateTime=new Date().toISOString(),o.textContent=new Intl.DateTimeFormat(this.#e.locale,{hour:"numeric",minute:"2-digit"}).format(new Date),a.append(o)}return this.#r.append(a),this.setAttribute("has-messages",""),this.#$(),r}#U(e){if(!this.#r)return;let n=document.createElement("p");n.className="conversation-status",n.setAttribute("role","status"),n.textContent=e,this.#r.append(n)}#L(){this.#f.scrollToBottom()}#$(){this.#f.revealLatest()}#A(e){this.dispatchEvent(new CustomEvent("assistant-error",{detail:e}))}#z(e,n){e instanceof Hr&&e.detail.code==="session_failed"&&this.#w("error");let a=e instanceof Hr?e.detail:{code:n,retryable:!1};this.#Z(a.code==="session_expired"?this.#e.labels.sessionExpired:this.#e.labels.unavailable,a.retryable!==!1||a.serviceCode===void 0),this.#A(a)}#Z(e,n=!0){if(!this.#r)return;this.#r.querySelector(".conversation-error")?.remove();let a=document.createElement("section");a.className="conversation-error",a.setAttribute("role",n?"alert":"status");let r=document.createElement("p");if(r.textContent=e,a.append(r),n){let o=document.createElement("button");o.type="button",o.textContent=this.#e.labels.reconnect,o.addEventListener("click",()=>this.reconnect()),a.append(o)}this.#r.append(a),this.#$()}#k(){let e=this.getAttribute("theme")??this.#e.theme.defaultMode;return e==="auto"?this.#u?.matches?"dark":"light":e}#S(){let e=this.#k();for(let n of Ik({host:this,root:this.shadowRoot,appearance:this.#e,hostAppearance:this.#y,mode:e,sessionState:this.#g,styleSnapshot:this.#_})){let a=`${n.theme}:${n.role}:${n.foreground}:${n.background}`;this.#b.has(a)||(this.#b.add(a),this.dispatchEvent(new CustomEvent("assistant-appearance-warning",{detail:n})))}for(let n of this.shadowRoot?.querySelectorAll(".noodle-app-card")??[])Px(n,e)}#w(e){this.#g=e,Tk(this,this.shadowRoot,e,this.#e)}#q(){this.shadowRoot?.querySelector(".launcher")?.setAttribute("aria-expanded",String(this.hasAttribute("open")))}#O(){this.close(),this.shadowRoot?.querySelector(".launcher")?.focus()}#N(){this.#v||(this.#v=!0,this.#e.behavior.startOpen&&this.setAttribute("open",""))}#F(){if(!this.shadowRoot)return;let e=this.#e;this.setAttribute("aria-label",e.brand.name),this.setAttribute("lang",e.locale),this.setAttribute("dir",e.direction),this.dataset.mode=e.layout.mode,this.dataset.position=e.layout.position,this.dataset.density=e.layout.density,this.toggleAttribute("mobile-fullscreen",e.layout.mobileFullscreen),we(this.shadowRoot,".panel").setAttribute("aria-label",e.brand.name),we(this.shadowRoot,"header strong").textContent=e.brand.name;let n=we(this.shadowRoot,"textarea");n.placeholder=e.labels.composerPlaceholder,n.setAttribute("aria-label",e.labels.composerPlaceholder),we(this.shadowRoot,".send").textContent=e.labels.send,we(this.shadowRoot,".launcher").setAttribute("aria-label",e.labels.open),we(this.shadowRoot,".close").setAttribute("aria-label",e.labels.close);let a=we(this.shadowRoot,".suggested-prompts");a.replaceChildren();for(let o of e.suggestedPrompts){let i=document.createElement("button");i.type="button",i.textContent=o,i.addEventListener("click",()=>this.#c(o)),a.append(i)}we(this.shadowRoot,".launcher").hidden=!e.behavior.showLauncher,we(this.shadowRoot,"header").hidden=!e.behavior.showHeader;let r=we(this.shadowRoot,".legal");r.replaceChildren(),this.#j(r),this.#S()}#V(){if(!this.shadowRoot)return;this.#f.disconnect();let e=this.#r?[...this.#r.childNodes]:[],n=this.#e;this.setAttribute("role","complementary"),this.setAttribute("aria-label",n.brand.name),this.setAttribute("lang",n.locale),this.setAttribute("dir",n.direction),this.dataset.mode=n.layout.mode,this.dataset.position=n.layout.position,this.dataset.density=n.layout.density,this.toggleAttribute("mobile-fullscreen",n.layout.mobileFullscreen),this.shadowRoot.innerHTML=`${bk}${Ek}
522
+ </style>`;var Lo="noodle-assistant",SP=globalThis.HTMLElement??class{},Th=class extends SP{static observedAttributes=["open","theme"];#e=Pf();#t;#i="";#n;#a;#o=0;#r;#l;#u;#d;#s;#p;#m;#g="idle";#v=!1;#y;#b=new Set;#_=new Map;#f=new _l;sessionEndpoint="";embedId="";serviceUrl="";get appearance(){return this.#y}set appearance(e){this.#y=e,this.#b.clear(),this.isConnected&&this.#S()}#h=new xl({element:this,messages:()=>this.#r,appendMessage:(e,n)=>{if(e==="user"&&n===this.#m){this.#m=void 0;return}return this.#M(e,n)},applyConfiguration:e=>{this.#e=Pf(e),this.#F(),this.#N()},labels:()=>this.#e.labels,respond:(e,n)=>this.respond(e,n),dispatchError:e=>this.#z(e),revealLatest:()=>this.#I(),renderView:e=>{let n=this.#r,a=this.#t;if(!n||!a)return;let r=a.appSandboxUrl?.(),o=Cx(e,{client:a,sendMessage:i=>this.sendMessage(i),updateModelContext:i=>this.updateModelContext(i),theme:this.#k()},{...r===void 0?{}:{sandboxUrl:r},onRenderFailure:i=>this.#z(i)});o&&(n.append(o),this.setAttribute("has-messages",""),this.#I())}});connectedCallback(){this.shadowRoot||this.attachShadow({mode:"open"}),this.sessionEndpoint||(this.sessionEndpoint=this.getAttribute("session-endpoint")??""),this.embedId||(this.embedId=this.getAttribute("embed-id")??""),this.serviceUrl||(this.serviceUrl=this.getAttribute("service-url")??""),this.#u=globalThis.matchMedia?.("(prefers-color-scheme: dark)"),this.#u?.addEventListener("change",this.#T),document.addEventListener("keydown",this.#C),document.addEventListener("pointerdown",this.#P),this.#e.behavior.startOpen&&this.#N(),this.#V(),this.dispatchEvent(new CustomEvent("assistant-ready")),this.hasAttribute("start-open")?(this.setAttribute("open",""),this.#v=!0,this.#$()):this.embedId||this.#$()}disconnectedCallback(){this.#o+=1,this.#t?.abort(),this.#n?.(),this.#t=void 0,this.#i="",this.#n=void 0,this.#a=void 0,this.#f.disconnect(),this.#x(!1),this.#u?.removeEventListener("change",this.#T),document.removeEventListener("keydown",this.#C),document.removeEventListener("pointerdown",this.#P)}attributeChangedCallback(e){e==="theme"&&this.#S(),e==="open"&&this.#q()}open(){this.setAttribute("open",""),this.#$(),this.dispatchEvent(new CustomEvent("assistant-open"))}close(){this.removeAttribute("open"),this.dispatchEvent(new CustomEvent("assistant-close"))}toggle(){this.hasAttribute("open")?this.close():this.open()}focusComposer(){this.shadowRoot?.querySelector("textarea")?.focus()}stop(){this.hasAttribute("busy")&&(this.#o+=1,this.#t?.abort(),this.#x(!1),this.#U(this.#e.labels.stopped),this.dispatchEvent(new CustomEvent("assistant-stopped")))}resetSession(){this.#o+=1,this.#t?.abort(),this.#n?.(),this.#t=void 0,this.#i="",this.#n=void 0,this.#a=void 0,this.#h.resetConversation(),this.#m=void 0,this.removeAttribute("has-messages"),this.#x(!1),this.#w("idle")}reconnect(){this.#o+=1,this.#t?.abort(),this.#n?.(),this.#t=void 0,this.#i="",this.#n=void 0,this.#a=void 0,this.#x(!1),this.#w("loading"),this.#$(),this.dispatchEvent(new CustomEvent("assistant-reconnecting"))}updateContext(e){this.#d={...e},this.#t?this.#t.updateContext(this.#d):this.dispatchEvent(new CustomEvent("assistant-context-changed",{detail:{context:this.#d}}))}updateModelContext(e){this.#s=Io(e),this.#t?this.#t.updateModelContext(this.#s):this.dispatchEvent(new CustomEvent("assistant-model-context-changed",{detail:{modelContext:this.#s}}))}updatePageContext(e){this.#p=e,this.#t?.updatePageContext(e),this.dispatchEvent(new CustomEvent("assistant-page-context-changed",{detail:{pageContext:e}}))}async sendMessage(e){let n=e.trim();if(!n)return;let a=this.#o;this.#m=n,this.#M("user",n),this.#x(!0),this.#g!=="ready"&&this.#w("loading");try{if(await this.#a,a!==this.#o)return;await this.#E().sendMessage(n)}catch(r){if(a!==this.#o||r instanceof Hr&&r.detail.code==="request_aborted")return;throw this.#R(r,"turn_failed"),r}finally{this.#m===n&&(this.#m=void 0),a===this.#o&&this.#x(!1)}}#c(e){this.sendMessage(e).catch(()=>{})}async confirmTool(e){await this.respond(e,{action:"accept"})}async respond(e,n){let a=this.#o;this.#x(!0);try{await this.#E().respond(e,n)}catch(r){if(a!==this.#o)return;throw this.#R(r,"confirmation_failed"),r}finally{a===this.#o&&this.#x(!1)}}#T=()=>this.#S();#C=e=>{e.key==="Escape"&&this.hasAttribute("open")&&this.#e.behavior.closeOnEscape&&this.#O()};#P=e=>{this.hasAttribute("open")&&this.#e.behavior.closeOnOutsideClick&&!e.composedPath().includes(this)&&this.close()};#E(){let e=bw(this);if(this.#t&&this.#i===e)return this.#t;this.#t?.abort(),this.#n?.(),this.#a=void 0;let n={...this.#d?{context:this.#d}:{},clientContext:Dx,...this.#p?{pageContext:this.#p}:{},...this.#s?{modelContext:this.#s}:{}},a=this.embedId?Xf({embedId:this.embedId,...this.serviceUrl?{serviceUrl:this.serviceUrl}:{},...n}):Xf({sessionEndpoint:this.sessionEndpoint,...n});return this.#t=a,this.#i=e,this.#n=a.subscribe(r=>{this.#t===a&&this.#D(r)}),a}#$(){if(!this.sessionEndpoint&&!this.embedId||this.#a||this.#t?.hasSession())return;let e=this.#E(),n=this.#o;this.#w("loading");let a=e.connect().catch(r=>{n!==this.#o||this.#t!==e||this.#R(r,"session_failed")}).finally(()=>{this.#a===a&&(this.#a=void 0)});this.#a=a}#D(e){this.dispatchEvent(new CustomEvent("assistant-event",{detail:e})),this.#h.handle(e),e.event==="session_started"&&(this.#w("ready"),this.#r?.querySelector(".conversation-error")?.remove()),(e.event==="session_expired"||e.event==="session_reset")&&this.#w("idle"),(e.event==="tool_proposed"||e.event==="interaction_proposed"||e.event==="input_requested")&&(this.#A(),this.setAttribute("has-messages","")),(e.event==="content"||e.event==="message_completed"||e.event==="interaction_completed"||e.event==="error")&&this.#A()}#x(e){this.toggleAttribute("busy",e);let n=this.shadowRoot?.querySelector("textarea"),a=this.shadowRoot?.querySelector(".send");if(n&&(n.disabled=!1),a&&(a.dataset.action=e?"stop":"send",a.textContent=e?this.#e.labels.stop:this.#e.labels.send,a.setAttribute("aria-label",a.textContent)),!e){this.#A();return}if(!this.#r||this.#l)return;let r=document.createElement("div");r.className="message assistant thinking";let o=document.createElement("span");o.textContent=this.#e.labels.thinking,r.append(o),this.#r.append(r),this.#l=r,this.#L()}#A(){this.#l?.remove(),this.#l=void 0}#M(e,n){if(!this.#r)return;let a=document.createElement("div");if(a.className=`message ${e}`,e==="assistant"&&this.#e.behavior.showAvatars&&this.#e.brand.avatar[this.#k()]){let o=document.createElement("img");o.className="avatar",o.src=this.#e.brand.avatar[this.#k()]??"",o.alt="",a.append(o)}let r=document.createElement(e==="assistant"?"div":"span");if(e==="assistant"?(r.className="markdown",r.innerHTML=yl(n)):r.textContent=n,a.append(r),e==="assistant"&&n){let o=document.createElement("button");o.type="button",o.className="message-copy",o.textContent=this.#e.labels.copy,o.addEventListener("click",()=>{navigator.clipboard?.writeText(n)}),a.append(o)}if(this.#e.behavior.showTimestamps){let o=document.createElement("time");o.dateTime=new Date().toISOString(),o.textContent=new Intl.DateTimeFormat(this.#e.locale,{hour:"numeric",minute:"2-digit"}).format(new Date),a.append(o)}return this.#r.append(a),this.setAttribute("has-messages",""),this.#I(),r}#U(e){if(!this.#r)return;let n=document.createElement("p");n.className="conversation-status",n.setAttribute("role","status"),n.textContent=e,this.#r.append(n)}#L(){this.#f.scrollToBottom()}#I(){this.#f.revealLatest()}#z(e){this.dispatchEvent(new CustomEvent("assistant-error",{detail:e}))}#R(e,n){e instanceof Hr&&e.detail.code==="session_failed"&&this.#w("error");let a=e instanceof Hr?e.detail:{code:n,retryable:!1};this.#Z(a.code==="session_expired"?this.#e.labels.sessionExpired:this.#e.labels.unavailable,a.retryable!==!1||a.serviceCode===void 0),this.#z(a)}#Z(e,n=!0){if(!this.#r)return;this.#r.querySelector(".conversation-error")?.remove();let a=document.createElement("section");a.className="conversation-error",a.setAttribute("role",n?"alert":"status");let r=document.createElement("p");if(r.textContent=e,a.append(r),n){let o=document.createElement("button");o.type="button",o.textContent=this.#e.labels.reconnect,o.addEventListener("click",()=>this.reconnect()),a.append(o)}this.#r.append(a),this.#I()}#k(){let e=this.getAttribute("theme")??this.#e.theme.defaultMode;return e==="auto"?this.#u?.matches?"dark":"light":e}#S(){let e=this.#k();for(let n of Ik({host:this,root:this.shadowRoot,appearance:this.#e,hostAppearance:this.#y,mode:e,sessionState:this.#g,styleSnapshot:this.#_})){let a=`${n.theme}:${n.role}:${n.foreground}:${n.background}`;this.#b.has(a)||(this.#b.add(a),this.dispatchEvent(new CustomEvent("assistant-appearance-warning",{detail:n})))}for(let n of this.shadowRoot?.querySelectorAll(".noodle-app-card")??[])Px(n,e)}#w(e){this.#g=e,Tk(this,this.shadowRoot,e,this.#e)}#q(){this.shadowRoot?.querySelector(".launcher")?.setAttribute("aria-expanded",String(this.hasAttribute("open")))}#O(){this.close(),this.shadowRoot?.querySelector(".launcher")?.focus()}#N(){this.#v||(this.#v=!0,this.#e.behavior.startOpen&&this.setAttribute("open",""))}#F(){if(!this.shadowRoot)return;let e=this.#e;this.setAttribute("aria-label",e.brand.name),this.setAttribute("lang",e.locale),this.setAttribute("dir",e.direction),this.dataset.mode=e.layout.mode,this.dataset.position=e.layout.position,this.dataset.density=e.layout.density,this.toggleAttribute("mobile-fullscreen",e.layout.mobileFullscreen),we(this.shadowRoot,".panel").setAttribute("aria-label",e.brand.name),we(this.shadowRoot,"header strong").textContent=e.brand.name;let n=we(this.shadowRoot,"textarea");n.placeholder=e.labels.composerPlaceholder,n.setAttribute("aria-label",e.labels.composerPlaceholder),we(this.shadowRoot,".send").textContent=e.labels.send,we(this.shadowRoot,".launcher").setAttribute("aria-label",e.labels.open),we(this.shadowRoot,".close").setAttribute("aria-label",e.labels.close);let a=we(this.shadowRoot,".suggested-prompts");a.replaceChildren();for(let o of e.suggestedPrompts){let i=document.createElement("button");i.type="button",i.textContent=o,i.addEventListener("click",()=>this.#c(o)),a.append(i)}we(this.shadowRoot,".launcher").hidden=!e.behavior.showLauncher,we(this.shadowRoot,"header").hidden=!e.behavior.showHeader;let r=we(this.shadowRoot,".legal");r.replaceChildren(),this.#j(r),this.#S()}#V(){if(!this.shadowRoot)return;this.#f.disconnect();let e=this.#r?[...this.#r.childNodes]:[],n=this.#e;this.setAttribute("role","complementary"),this.setAttribute("aria-label",n.brand.name),this.setAttribute("lang",n.locale),this.setAttribute("dir",n.direction),this.dataset.mode=n.layout.mode,this.dataset.position=n.layout.position,this.dataset.density=n.layout.density,this.toggleAttribute("mobile-fullscreen",n.layout.mobileFullscreen),this.shadowRoot.innerHTML=`${bk}${Ek}
523
523
  <button class="launcher" type="button" aria-label="${Uo(n.labels.open)}" aria-controls="assistant-panel" aria-expanded="${String(this.hasAttribute("open"))}"><slot name="launcher-icon"></slot><span class="visually-hidden" data-session-status aria-live="polite" hidden></span></button>
524
524
  <section class="panel" id="assistant-panel" role="dialog" aria-label="${Uo(n.brand.name)}">
525
525
  <header><slot name="header-leading"></slot><img class="brand-logo" alt=""><strong></strong><slot name="header-actions"></slot><button class="close" type="button" aria-label="${Uo(n.labels.close)}"></button></header>
package/dist/index.cjs CHANGED
@@ -27477,6 +27477,10 @@ var DefaultAssistantClient = class {
27477
27477
  getChatState() {
27478
27478
  return this.#chat.getState();
27479
27479
  }
27480
+ /** Whether a session already exists, so a caller can avoid re-entering its loading state. */
27481
+ hasSession() {
27482
+ return this.#session !== void 0;
27483
+ }
27480
27484
  async connect() {
27481
27485
  if (this.#session) return;
27482
27486
  await this.#singleFlight(async (signal) => {
@@ -32176,7 +32180,13 @@ var NoodleAssistantElement = class extends HTMLElementBase {
32176
32180
  if (this.#appearance.behavior.startOpen) this.#applyStartOpenPolicy();
32177
32181
  this.#render();
32178
32182
  this.dispatchEvent(new CustomEvent("assistant-ready"));
32179
- this.#primeSession();
32183
+ if (this.hasAttribute("start-open")) {
32184
+ this.setAttribute("open", "");
32185
+ this.#startOpenApplied = true;
32186
+ this.#primeSession();
32187
+ } else if (!this.embedId) {
32188
+ this.#primeSession();
32189
+ }
32180
32190
  }
32181
32191
  disconnectedCallback() {
32182
32192
  this.#conversationGeneration += 1;
@@ -32198,6 +32208,7 @@ var NoodleAssistantElement = class extends HTMLElementBase {
32198
32208
  }
32199
32209
  open() {
32200
32210
  this.setAttribute("open", "");
32211
+ this.#primeSession();
32201
32212
  this.dispatchEvent(new CustomEvent("assistant-open"));
32202
32213
  }
32203
32214
  close() {
@@ -32365,6 +32376,7 @@ var NoodleAssistantElement = class extends HTMLElementBase {
32365
32376
  }
32366
32377
  #primeSession() {
32367
32378
  if (!this.sessionEndpoint && !this.embedId) return;
32379
+ if (this.#sessionBootstrap || this.#client?.hasSession()) return;
32368
32380
  const client = this.#ensureClient();
32369
32381
  const generation = this.#conversationGeneration;
32370
32382
  this.#setSessionState("loading");