@artooi/ag-ui-web-component 0.29.0 → 0.30.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +199 -1
  2. package/README.md +196 -33
  3. package/dist/ag-ui-web-component.bundle.js +211 -28
  4. package/dist/ag-ui-web-component.bundle.js.map +4 -4
  5. package/dist/constants.d.ts +60 -1
  6. package/dist/constants.d.ts.map +1 -1
  7. package/dist/core/ag_ui_chat.d.ts +25 -1
  8. package/dist/core/ag_ui_chat.d.ts.map +1 -1
  9. package/dist/core/agui_client.d.ts +18 -1
  10. package/dist/core/agui_client.d.ts.map +1 -1
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +578 -35
  14. package/dist/index.js.map +4 -4
  15. package/dist/ui/message_actions.d.ts +14 -4
  16. package/dist/ui/message_actions.d.ts.map +1 -1
  17. package/dist/ui/styles.d.ts +1 -1
  18. package/dist/ui/styles.d.ts.map +1 -1
  19. package/dist/ui/subagent_panel.d.ts +92 -0
  20. package/dist/ui/subagent_panel.d.ts.map +1 -0
  21. package/dist/ui/subagent_update.d.ts +19 -0
  22. package/dist/ui/subagent_update.d.ts.map +1 -0
  23. package/dist/ui/tool_call_card.d.ts +73 -1
  24. package/dist/ui/tool_call_card.d.ts.map +1 -1
  25. package/dist/ui/ui_strings.d.ts +10 -0
  26. package/dist/ui/ui_strings.d.ts.map +1 -1
  27. package/package.json +1 -1
  28. package/src/constants.ts +63 -1
  29. package/src/core/ag_ui_chat.ts +180 -26
  30. package/src/core/agui_client.ts +26 -2
  31. package/src/index.ts +4 -0
  32. package/src/ui/message_actions.ts +20 -8
  33. package/src/ui/styles.ts +183 -0
  34. package/src/ui/subagent_panel.ts +213 -0
  35. package/src/ui/subagent_update.ts +80 -0
  36. package/src/ui/tool_call_card.ts +129 -3
  37. package/src/ui/ui_strings.ts +15 -0
  38. package/src/version.ts +1 -1
@@ -1,21 +1,21 @@
1
- var Fp=Object.defineProperty;var us=(t,e)=>{for(var n in e)Fp(t,n,{get:e[n],enumerable:!0})};var Br="ag-ui-chat",ps="ag-ui-submit",hs="ag-ui-toggle",fs="ag-ui-unread",ms="ag-ui-state",gs="ag-ui-attachments",vs="ag-ui-run-finished",bs="ag-ui-custom",ys="ag-ui-invalidate",xs="ag-ui-feedback",ws="suggestions",Es="ag_ui.invalidate",Fe={USER:"user",ASSISTANT:"assistant"},Xn="x-destructive",Vr="x-confirm",Pe="x-summary",Kn="x-navigates",_s="read_page",Ts=10,ee={PENDING:"pending",DEFERRED:"deferred",DONE:"done",ERROR:"error",DECLINED:"declined"},De={UPLOADING:"uploading",READY:"ready",ERROR:"error"},Ss=10*1024*1024,vn={INLINE:"inline",MINIMAL:"minimal",COMPACT:"compact",FULL:"full"},As="compaction",ks="load_capability",Xl='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 19.5V5m-6.5 6.5L12 5l6.5 6.5"/></svg>',Kl='<svg class="glyph glyph--solid" viewBox="0 0 24 24" aria-hidden="true"><rect x="7" y="7" width="10" height="10" rx="2.5"/></svg>',Yl='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M17 8.5V15a5 5 0 0 1-10 0V7a3 3 0 0 1 6 0v7.5a1 1 0 0 1-2 0V8.5"/></svg>',Zl='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 4a3 3 0 0 1 3 3v5a3 3 0 0 1-6 0V7a3 3 0 0 1 3-3z"/><path d="M5 11v1a7 7 0 0 0 14 0v-1"/><path d="M12 19v3"/></svg>',Ql='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 5.5A2.5 2.5 0 0 1 6.5 3h11A2.5 2.5 0 0 1 20 5.5v8a2.5 2.5 0 0 1-2.5 2.5H9l-5 4z"/></svg>',Jl='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/></svg>',ec='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><rect x="3.5" y="4.5" width="17" height="15" rx="2.5"/><circle cx="9" cy="10" r="1.5"/><path d="M4.5 17.5 9 13.5l3.5 3 3-2.5 4.5 4"/></svg>',tc='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/><rect class="glyph--solid" x="7.5" y="13.5" width="9" height="4.5" rx="1"/></svg>',nc='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/><path d="M8.5 13.5h7M8.5 17h4.5"/></svg>',jr="chart",rc=150;var xe=[];for(let t=0;t<256;++t)xe.push((t+256).toString(16).slice(1));function oc(t,e=0){return(xe[t[e+0]]+xe[t[e+1]]+xe[t[e+2]]+xe[t[e+3]]+"-"+xe[t[e+4]]+xe[t[e+5]]+"-"+xe[t[e+6]]+xe[t[e+7]]+"-"+xe[t[e+8]]+xe[t[e+9]]+"-"+xe[t[e+10]]+xe[t[e+11]]+xe[t[e+12]]+xe[t[e+13]]+xe[t[e+14]]+xe[t[e+15]]).toLowerCase()}var Cs,Gp=new Uint8Array(16);function Is(){if(!Cs){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Cs=crypto.getRandomValues.bind(crypto)}return Cs(Gp)}var $p=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Rs={randomUUID:$p};function Bp(t,e,n){if(Rs.randomUUID&&!e&&!t)return Rs.randomUUID();t=t||{};let r=t.random??t.rng?.()??Is();if(r.length<16)throw new Error("Random bytes length must be >= 16");if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,e){if(n=n||0,n<0||n+16>e.length)throw new RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let o=0;o<16;++o)e[n+o]=r[o];return e}return oc(r)}var _t=Bp;var d={};us(d,{BRAND:()=>mh,DIRTY:()=>Lt,EMPTY_PATH:()=>Wp,INVALID:()=>P,NEVER:()=>Jh,OK:()=>Ae,ParseStatus:()=>we,Schema:()=>$,ZodAny:()=>At,ZodArray:()=>mt,ZodBigInt:()=>Dt,ZodBoolean:()=>Ut,ZodBranded:()=>Zn,ZodCatch:()=>Xt,ZodDate:()=>Ht,ZodDefault:()=>Wt,ZodDiscriminatedUnion:()=>Xr,ZodEffects:()=>Be,ZodEnum:()=>jt,ZodError:()=>Oe,ZodFirstPartyTypeKind:()=>D,ZodFunction:()=>Yr,ZodIntersection:()=>$t,ZodIssueCode:()=>E,ZodLazy:()=>Bt,ZodLiteral:()=>Vt,ZodMap:()=>_n,ZodNaN:()=>Sn,ZodNativeEnum:()=>qt,ZodNever:()=>Xe,ZodNull:()=>Ft,ZodNullable:()=>st,ZodNumber:()=>Pt,ZodObject:()=>Me,ZodOptional:()=>Ge,ZodParsedType:()=>C,ZodPipeline:()=>Qn,ZodPromise:()=>kt,ZodReadonly:()=>Kt,ZodRecord:()=>Kr,ZodSchema:()=>$,ZodSet:()=>Tn,ZodString:()=>St,ZodSymbol:()=>wn,ZodTransformer:()=>Be,ZodTuple:()=>it,ZodType:()=>$,ZodUndefined:()=>zt,ZodUnion:()=>Gt,ZodUnknown:()=>ft,ZodVoid:()=>En,addIssueToContext:()=>k,any:()=>Th,array:()=>Ch,bigint:()=>yh,boolean:()=>mc,coerce:()=>Qh,custom:()=>pc,date:()=>xh,datetimeRegex:()=>dc,defaultErrorMap:()=>pt,discriminatedUnion:()=>Oh,effect:()=>Vh,enum:()=>Gh,function:()=>Hh,getErrorMap:()=>bn,getParsedType:()=>ot,instanceof:()=>vh,intersection:()=>Mh,isAborted:()=>qr,isAsync:()=>yn,isDirty:()=>Wr,isValid:()=>Tt,late:()=>gh,lazy:()=>zh,literal:()=>Fh,makeIssue:()=>Yn,map:()=>Dh,nan:()=>bh,nativeEnum:()=>$h,never:()=>Ah,null:()=>_h,nullable:()=>qh,number:()=>fc,object:()=>Ih,objectUtil:()=>Ns,oboolean:()=>Zh,onumber:()=>Yh,optional:()=>jh,ostring:()=>Kh,pipeline:()=>Xh,preprocess:()=>Wh,promise:()=>Bh,quotelessJson:()=>Vp,record:()=>Ph,set:()=>Uh,setErrorMap:()=>qp,strictObject:()=>Rh,string:()=>hc,symbol:()=>wh,transformer:()=>Vh,tuple:()=>Lh,undefined:()=>Eh,union:()=>Nh,unknown:()=>Sh,util:()=>V,void:()=>kh});var V;(function(t){t.assertEqual=o=>{};function e(o){}t.assertIs=e;function n(o){throw new Error}t.assertNever=n,t.arrayToEnum=o=>{let i={};for(let s of o)i[s]=s;return i},t.getValidEnumValues=o=>{let i=t.objectKeys(o).filter(a=>typeof o[o[a]]!="number"),s={};for(let a of i)s[a]=o[a];return t.objectValues(s)},t.objectValues=o=>t.objectKeys(o).map(function(i){return o[i]}),t.objectKeys=typeof Object.keys=="function"?o=>Object.keys(o):o=>{let i=[];for(let s in o)Object.prototype.hasOwnProperty.call(o,s)&&i.push(s);return i},t.find=(o,i)=>{for(let s of o)if(i(s))return s},t.isInteger=typeof Number.isInteger=="function"?o=>Number.isInteger(o):o=>typeof o=="number"&&Number.isFinite(o)&&Math.floor(o)===o;function r(o,i=" | "){return o.map(s=>typeof s=="string"?`'${s}'`:s).join(i)}t.joinValues=r,t.jsonStringifyReplacer=(o,i)=>typeof i=="bigint"?i.toString():i})(V||(V={}));var Ns;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(Ns||(Ns={}));var C=V.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),ot=t=>{switch(typeof t){case"undefined":return C.undefined;case"string":return C.string;case"number":return Number.isNaN(t)?C.nan:C.number;case"boolean":return C.boolean;case"function":return C.function;case"bigint":return C.bigint;case"symbol":return C.symbol;case"object":return Array.isArray(t)?C.array:t===null?C.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?C.promise:typeof Map<"u"&&t instanceof Map?C.map:typeof Set<"u"&&t instanceof Set?C.set:typeof Date<"u"&&t instanceof Date?C.date:C.object;default:return C.unknown}};var E=V.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Vp=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:"),Oe=class t extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};let n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}format(e){let n=e||function(i){return i.message},r={_errors:[]},o=i=>{for(let s of i.issues)if(s.code==="invalid_union")s.unionErrors.map(o);else if(s.code==="invalid_return_type")o(s.returnTypeError);else if(s.code==="invalid_arguments")o(s.argumentsError);else if(s.path.length===0)r._errors.push(n(s));else{let a=r,l=0;for(;l<s.path.length;){let c=s.path[l];l===s.path.length-1?(a[c]=a[c]||{_errors:[]},a[c]._errors.push(n(s))):a[c]=a[c]||{_errors:[]},a=a[c],l++}}};return o(this),r}static assert(e){if(!(e instanceof t))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,V.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){let n={},r=[];for(let o of this.issues)if(o.path.length>0){let i=o.path[0];n[i]=n[i]||[],n[i].push(e(o))}else r.push(e(o));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}};Oe.create=t=>new Oe(t);var jp=(t,e)=>{let n;switch(t.code){case E.invalid_type:t.received===C.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case E.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,V.jsonStringifyReplacer)}`;break;case E.unrecognized_keys:n=`Unrecognized key(s) in object: ${V.joinValues(t.keys,", ")}`;break;case E.invalid_union:n="Invalid input";break;case E.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${V.joinValues(t.options)}`;break;case E.invalid_enum_value:n=`Invalid enum value. Expected ${V.joinValues(t.options)}, received '${t.received}'`;break;case E.invalid_arguments:n="Invalid function arguments";break;case E.invalid_return_type:n="Invalid function return type";break;case E.invalid_date:n="Invalid date";break;case E.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(n=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?n=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?n=`Invalid input: must end with "${t.validation.endsWith}"`:V.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case E.too_small:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:n="Invalid input";break;case E.too_big:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?n=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:n="Invalid input";break;case E.custom:n="Invalid input";break;case E.invalid_intersection_types:n="Intersection results could not be merged";break;case E.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case E.not_finite:n="Number must be finite";break;default:n=e.defaultError,V.assertNever(t)}return{message:n}},pt=jp;var ic=pt;function qp(t){ic=t}function bn(){return ic}var Yn=t=>{let{data:e,path:n,errorMaps:r,issueData:o}=t,i=[...n,...o.path||[]],s={...o,path:i};if(o.message!==void 0)return{...o,path:i,message:o.message};let a="",l=r.filter(c=>!!c).slice().reverse();for(let c of l)a=c(s,{data:e,defaultError:a}).message;return{...o,path:i,message:a}},Wp=[];function k(t,e){let n=bn(),r=Yn({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===pt?void 0:pt].filter(o=>!!o)});t.common.issues.push(r)}var we=class t{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,n){let r=[];for(let o of n){if(o.status==="aborted")return P;o.status==="dirty"&&e.dirty(),r.push(o.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,n){let r=[];for(let o of n){let i=await o.key,s=await o.value;r.push({key:i,value:s})}return t.mergeObjectSync(e,r)}static mergeObjectSync(e,n){let r={};for(let o of n){let{key:i,value:s}=o;if(i.status==="aborted"||s.status==="aborted")return P;i.status==="dirty"&&e.dirty(),s.status==="dirty"&&e.dirty(),i.value!=="__proto__"&&(typeof s.value<"u"||o.alwaysSet)&&(r[i.value]=s.value)}return{status:e.value,value:r}}},P=Object.freeze({status:"aborted"}),Lt=t=>({status:"dirty",value:t}),Ae=t=>({status:"valid",value:t}),qr=t=>t.status==="aborted",Wr=t=>t.status==="dirty",Tt=t=>t.status==="valid",yn=t=>typeof Promise<"u"&&t instanceof Promise;var R;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(R||(R={}));var $e=class{constructor(e,n,r,o){this._cachedPath=[],this.parent=e,this.data=n,this._path=r,this._key=o}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}},sc=(t,e)=>{if(Tt(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let n=new Oe(t.common.issues);return this._error=n,this._error}}};function F(t){if(!t)return{};let{errorMap:e,invalid_type_error:n,required_error:r,description:o}=t;if(e&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:o}:{errorMap:(s,a)=>{let{message:l}=t;return s.code==="invalid_enum_value"?{message:l??a.defaultError}:typeof a.data>"u"?{message:l??r??a.defaultError}:s.code!=="invalid_type"?{message:a.defaultError}:{message:l??n??a.defaultError}},description:o}}var $=class{get description(){return this._def.description}_getType(e){return ot(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:ot(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new we,ctx:{common:e.parent.common,data:e.data,parsedType:ot(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let n=this._parse(e);if(yn(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(e){let n=this._parse(e);return Promise.resolve(n)}parse(e,n){let r=this.safeParse(e,n);if(r.success)return r.data;throw r.error}safeParse(e,n){let r={common:{issues:[],async:n?.async??!1,contextualErrorMap:n?.errorMap},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:ot(e)},o=this._parseSync({data:e,path:r.path,parent:r});return sc(r,o)}"~validate"(e){let n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:ot(e)};if(!this["~standard"].async)try{let r=this._parseSync({data:e,path:[],parent:n});return Tt(r)?{value:r.value}:{issues:n.common.issues}}catch(r){r?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:n}).then(r=>Tt(r)?{value:r.value}:{issues:n.common.issues})}async parseAsync(e,n){let r=await this.safeParseAsync(e,n);if(r.success)return r.data;throw r.error}async safeParseAsync(e,n){let r={common:{issues:[],contextualErrorMap:n?.errorMap,async:!0},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:ot(e)},o=this._parse({data:e,path:r.path,parent:r}),i=await(yn(o)?o:Promise.resolve(o));return sc(r,i)}refine(e,n){let r=o=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(o):n;return this._refinement((o,i)=>{let s=e(o),a=()=>i.addIssue({code:E.custom,...r(o)});return typeof Promise<"u"&&s instanceof Promise?s.then(l=>l?!0:(a(),!1)):s?!0:(a(),!1)})}refinement(e,n){return this._refinement((r,o)=>e(r)?!0:(o.addIssue(typeof n=="function"?n(r,o):n),!1))}_refinement(e){return new Be({schema:this,typeName:D.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:n=>this["~validate"](n)}}optional(){return Ge.create(this,this._def)}nullable(){return st.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return mt.create(this)}promise(){return kt.create(this,this._def)}or(e){return Gt.create([this,e],this._def)}and(e){return $t.create(this,e,this._def)}transform(e){return new Be({...F(this._def),schema:this,typeName:D.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let n=typeof e=="function"?e:()=>e;return new Wt({...F(this._def),innerType:this,defaultValue:n,typeName:D.ZodDefault})}brand(){return new Zn({typeName:D.ZodBranded,type:this,...F(this._def)})}catch(e){let n=typeof e=="function"?e:()=>e;return new Xt({...F(this._def),innerType:this,catchValue:n,typeName:D.ZodCatch})}describe(e){let n=this.constructor;return new n({...this._def,description:e})}pipe(e){return Qn.create(this,e)}readonly(){return Kt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},Xp=/^c[^\s-]{8,}$/i,Kp=/^[0-9a-z]+$/,Yp=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Zp=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Qp=/^[a-z0-9_-]{21}$/i,Jp=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,eh=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,th=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,nh="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",Os,rh=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,oh=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,ih=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,sh=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ah=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,lh=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,lc="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",ch=new RegExp(`^${lc}$`);function cc(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);let n=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${n}`}function dh(t){return new RegExp(`^${cc(t)}$`)}function dc(t){let e=`${lc}T${cc(t)}`,n=[];return n.push(t.local?"Z?":"Z"),t.offset&&n.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${n.join("|")})`,new RegExp(`^${e}$`)}function uh(t,e){return!!((e==="v4"||!e)&&rh.test(t)||(e==="v6"||!e)&&ih.test(t))}function ph(t,e){if(!Jp.test(t))return!1;try{let[n]=t.split(".");if(!n)return!1;let r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),o=JSON.parse(atob(r));return!(typeof o!="object"||o===null||"typ"in o&&o?.typ!=="JWT"||!o.alg||e&&o.alg!==e)}catch{return!1}}function hh(t,e){return!!((e==="v4"||!e)&&oh.test(t)||(e==="v6"||!e)&&sh.test(t))}var St=class t extends ${_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==C.string){let i=this._getOrReturnCtx(e);return k(i,{code:E.invalid_type,expected:C.string,received:i.parsedType}),P}let r=new we,o;for(let i of this._def.checks)if(i.kind==="min")e.data.length<i.value&&(o=this._getOrReturnCtx(e,o),k(o,{code:E.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="max")e.data.length>i.value&&(o=this._getOrReturnCtx(e,o),k(o,{code:E.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="length"){let s=e.data.length>i.value,a=e.data.length<i.value;(s||a)&&(o=this._getOrReturnCtx(e,o),s?k(o,{code:E.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):a&&k(o,{code:E.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),r.dirty())}else if(i.kind==="email")th.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"email",code:E.invalid_string,message:i.message}),r.dirty());else if(i.kind==="emoji")Os||(Os=new RegExp(nh,"u")),Os.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"emoji",code:E.invalid_string,message:i.message}),r.dirty());else if(i.kind==="uuid")Zp.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"uuid",code:E.invalid_string,message:i.message}),r.dirty());else if(i.kind==="nanoid")Qp.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"nanoid",code:E.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid")Xp.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"cuid",code:E.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid2")Kp.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"cuid2",code:E.invalid_string,message:i.message}),r.dirty());else if(i.kind==="ulid")Yp.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"ulid",code:E.invalid_string,message:i.message}),r.dirty());else if(i.kind==="url")try{new URL(e.data)}catch{o=this._getOrReturnCtx(e,o),k(o,{validation:"url",code:E.invalid_string,message:i.message}),r.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"regex",code:E.invalid_string,message:i.message}),r.dirty())):i.kind==="trim"?e.data=e.data.trim():i.kind==="includes"?e.data.includes(i.value,i.position)||(o=this._getOrReturnCtx(e,o),k(o,{code:E.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),r.dirty()):i.kind==="toLowerCase"?e.data=e.data.toLowerCase():i.kind==="toUpperCase"?e.data=e.data.toUpperCase():i.kind==="startsWith"?e.data.startsWith(i.value)||(o=this._getOrReturnCtx(e,o),k(o,{code:E.invalid_string,validation:{startsWith:i.value},message:i.message}),r.dirty()):i.kind==="endsWith"?e.data.endsWith(i.value)||(o=this._getOrReturnCtx(e,o),k(o,{code:E.invalid_string,validation:{endsWith:i.value},message:i.message}),r.dirty()):i.kind==="datetime"?dc(i).test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{code:E.invalid_string,validation:"datetime",message:i.message}),r.dirty()):i.kind==="date"?ch.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{code:E.invalid_string,validation:"date",message:i.message}),r.dirty()):i.kind==="time"?dh(i).test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{code:E.invalid_string,validation:"time",message:i.message}),r.dirty()):i.kind==="duration"?eh.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"duration",code:E.invalid_string,message:i.message}),r.dirty()):i.kind==="ip"?uh(e.data,i.version)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"ip",code:E.invalid_string,message:i.message}),r.dirty()):i.kind==="jwt"?ph(e.data,i.alg)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"jwt",code:E.invalid_string,message:i.message}),r.dirty()):i.kind==="cidr"?hh(e.data,i.version)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"cidr",code:E.invalid_string,message:i.message}),r.dirty()):i.kind==="base64"?ah.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"base64",code:E.invalid_string,message:i.message}),r.dirty()):i.kind==="base64url"?lh.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"base64url",code:E.invalid_string,message:i.message}),r.dirty()):V.assertNever(i);return{status:r.value,value:e.data}}_regex(e,n,r){return this.refinement(o=>e.test(o),{validation:n,code:E.invalid_string,...R.errToObj(r)})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...R.errToObj(e)})}url(e){return this._addCheck({kind:"url",...R.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...R.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...R.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...R.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...R.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...R.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...R.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...R.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...R.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...R.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...R.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...R.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...R.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...R.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...R.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,...R.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n?.position,...R.errToObj(n?.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,...R.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,...R.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,...R.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,...R.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,...R.errToObj(n)})}nonempty(e){return this.min(1,R.errToObj(e))}trim(){return new t({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxLength(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}};St.create=t=>new St({checks:[],typeName:D.ZodString,coerce:t?.coerce??!1,...F(t)});function fh(t,e){let n=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,o=n>r?n:r,i=Number.parseInt(t.toFixed(o).replace(".","")),s=Number.parseInt(e.toFixed(o).replace(".",""));return i%s/10**o}var Pt=class t extends ${constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==C.number){let i=this._getOrReturnCtx(e);return k(i,{code:E.invalid_type,expected:C.number,received:i.parsedType}),P}let r,o=new we;for(let i of this._def.checks)i.kind==="int"?V.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),k(r,{code:E.invalid_type,expected:"integer",received:"float",message:i.message}),o.dirty()):i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:E.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),o.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:E.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),o.dirty()):i.kind==="multipleOf"?fh(e.data,i.value)!==0&&(r=this._getOrReturnCtx(e,r),k(r,{code:E.not_multiple_of,multipleOf:i.value,message:i.message}),o.dirty()):i.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),k(r,{code:E.not_finite,message:i.message}),o.dirty()):V.assertNever(i);return{status:o.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,R.toString(n))}gt(e,n){return this.setLimit("min",e,!1,R.toString(n))}lte(e,n){return this.setLimit("max",e,!0,R.toString(n))}lt(e,n){return this.setLimit("max",e,!1,R.toString(n))}setLimit(e,n,r,o){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:R.toString(o)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:R.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:R.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:R.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:R.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:R.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:R.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:R.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:R.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:R.toString(e)})}get minValue(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&V.isInteger(e.value))}get isFinite(){let e=null,n=null;for(let r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(n)&&Number.isFinite(e)}};Pt.create=t=>new Pt({checks:[],typeName:D.ZodNumber,coerce:t?.coerce||!1,...F(t)});var Dt=class t extends ${constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==C.bigint)return this._getInvalidInput(e);let r,o=new we;for(let i of this._def.checks)i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:E.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),o.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:E.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),o.dirty()):i.kind==="multipleOf"?e.data%i.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),k(r,{code:E.not_multiple_of,multipleOf:i.value,message:i.message}),o.dirty()):V.assertNever(i);return{status:o.value,value:e.data}}_getInvalidInput(e){let n=this._getOrReturnCtx(e);return k(n,{code:E.invalid_type,expected:C.bigint,received:n.parsedType}),P}gte(e,n){return this.setLimit("min",e,!0,R.toString(n))}gt(e,n){return this.setLimit("min",e,!1,R.toString(n))}lte(e,n){return this.setLimit("max",e,!0,R.toString(n))}lt(e,n){return this.setLimit("max",e,!1,R.toString(n))}setLimit(e,n,r,o){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:R.toString(o)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:R.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:R.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:R.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:R.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:R.toString(n)})}get minValue(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}};Dt.create=t=>new Dt({checks:[],typeName:D.ZodBigInt,coerce:t?.coerce??!1,...F(t)});var Ut=class extends ${_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==C.boolean){let r=this._getOrReturnCtx(e);return k(r,{code:E.invalid_type,expected:C.boolean,received:r.parsedType}),P}return Ae(e.data)}};Ut.create=t=>new Ut({typeName:D.ZodBoolean,coerce:t?.coerce||!1,...F(t)});var Ht=class t extends ${_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==C.date){let i=this._getOrReturnCtx(e);return k(i,{code:E.invalid_type,expected:C.date,received:i.parsedType}),P}if(Number.isNaN(e.data.getTime())){let i=this._getOrReturnCtx(e);return k(i,{code:E.invalid_date}),P}let r=new we,o;for(let i of this._def.checks)i.kind==="min"?e.data.getTime()<i.value&&(o=this._getOrReturnCtx(e,o),k(o,{code:E.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),r.dirty()):i.kind==="max"?e.data.getTime()>i.value&&(o=this._getOrReturnCtx(e,o),k(o,{code:E.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),r.dirty()):V.assertNever(i);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:R.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:R.toString(n)})}get minDate(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e!=null?new Date(e):null}};Ht.create=t=>new Ht({checks:[],coerce:t?.coerce||!1,typeName:D.ZodDate,...F(t)});var wn=class extends ${_parse(e){if(this._getType(e)!==C.symbol){let r=this._getOrReturnCtx(e);return k(r,{code:E.invalid_type,expected:C.symbol,received:r.parsedType}),P}return Ae(e.data)}};wn.create=t=>new wn({typeName:D.ZodSymbol,...F(t)});var zt=class extends ${_parse(e){if(this._getType(e)!==C.undefined){let r=this._getOrReturnCtx(e);return k(r,{code:E.invalid_type,expected:C.undefined,received:r.parsedType}),P}return Ae(e.data)}};zt.create=t=>new zt({typeName:D.ZodUndefined,...F(t)});var Ft=class extends ${_parse(e){if(this._getType(e)!==C.null){let r=this._getOrReturnCtx(e);return k(r,{code:E.invalid_type,expected:C.null,received:r.parsedType}),P}return Ae(e.data)}};Ft.create=t=>new Ft({typeName:D.ZodNull,...F(t)});var At=class extends ${constructor(){super(...arguments),this._any=!0}_parse(e){return Ae(e.data)}};At.create=t=>new At({typeName:D.ZodAny,...F(t)});var ft=class extends ${constructor(){super(...arguments),this._unknown=!0}_parse(e){return Ae(e.data)}};ft.create=t=>new ft({typeName:D.ZodUnknown,...F(t)});var Xe=class extends ${_parse(e){let n=this._getOrReturnCtx(e);return k(n,{code:E.invalid_type,expected:C.never,received:n.parsedType}),P}};Xe.create=t=>new Xe({typeName:D.ZodNever,...F(t)});var En=class extends ${_parse(e){if(this._getType(e)!==C.undefined){let r=this._getOrReturnCtx(e);return k(r,{code:E.invalid_type,expected:C.void,received:r.parsedType}),P}return Ae(e.data)}};En.create=t=>new En({typeName:D.ZodVoid,...F(t)});var mt=class t extends ${_parse(e){let{ctx:n,status:r}=this._processInputParams(e),o=this._def;if(n.parsedType!==C.array)return k(n,{code:E.invalid_type,expected:C.array,received:n.parsedType}),P;if(o.exactLength!==null){let s=n.data.length>o.exactLength.value,a=n.data.length<o.exactLength.value;(s||a)&&(k(n,{code:s?E.too_big:E.too_small,minimum:a?o.exactLength.value:void 0,maximum:s?o.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:o.exactLength.message}),r.dirty())}if(o.minLength!==null&&n.data.length<o.minLength.value&&(k(n,{code:E.too_small,minimum:o.minLength.value,type:"array",inclusive:!0,exact:!1,message:o.minLength.message}),r.dirty()),o.maxLength!==null&&n.data.length>o.maxLength.value&&(k(n,{code:E.too_big,maximum:o.maxLength.value,type:"array",inclusive:!0,exact:!1,message:o.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((s,a)=>o.type._parseAsync(new $e(n,s,n.path,a)))).then(s=>we.mergeArray(r,s));let i=[...n.data].map((s,a)=>o.type._parseSync(new $e(n,s,n.path,a)));return we.mergeArray(r,i)}get element(){return this._def.type}min(e,n){return new t({...this._def,minLength:{value:e,message:R.toString(n)}})}max(e,n){return new t({...this._def,maxLength:{value:e,message:R.toString(n)}})}length(e,n){return new t({...this._def,exactLength:{value:e,message:R.toString(n)}})}nonempty(e){return this.min(1,e)}};mt.create=(t,e)=>new mt({type:t,minLength:null,maxLength:null,exactLength:null,typeName:D.ZodArray,...F(e)});function xn(t){if(t instanceof Me){let e={};for(let n in t.shape){let r=t.shape[n];e[n]=Ge.create(xn(r))}return new Me({...t._def,shape:()=>e})}else return t instanceof mt?new mt({...t._def,type:xn(t.element)}):t instanceof Ge?Ge.create(xn(t.unwrap())):t instanceof st?st.create(xn(t.unwrap())):t instanceof it?it.create(t.items.map(e=>xn(e))):t}var Me=class t extends ${constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),n=V.objectKeys(e);return this._cached={shape:e,keys:n},this._cached}_parse(e){if(this._getType(e)!==C.object){let c=this._getOrReturnCtx(e);return k(c,{code:E.invalid_type,expected:C.object,received:c.parsedType}),P}let{status:r,ctx:o}=this._processInputParams(e),{shape:i,keys:s}=this._getCached(),a=[];if(!(this._def.catchall instanceof Xe&&this._def.unknownKeys==="strip"))for(let c in o.data)s.includes(c)||a.push(c);let l=[];for(let c of s){let u=i[c],m=o.data[c];l.push({key:{status:"valid",value:c},value:u._parse(new $e(o,m,o.path,c)),alwaysSet:c in o.data})}if(this._def.catchall instanceof Xe){let c=this._def.unknownKeys;if(c==="passthrough")for(let u of a)l.push({key:{status:"valid",value:u},value:{status:"valid",value:o.data[u]}});else if(c==="strict")a.length>0&&(k(o,{code:E.unrecognized_keys,keys:a}),r.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{let c=this._def.catchall;for(let u of a){let m=o.data[u];l.push({key:{status:"valid",value:u},value:c._parse(new $e(o,m,o.path,u)),alwaysSet:u in o.data})}}return o.common.async?Promise.resolve().then(async()=>{let c=[];for(let u of l){let m=await u.key,y=await u.value;c.push({key:m,value:y,alwaysSet:u.alwaysSet})}return c}).then(c=>we.mergeObjectSync(r,c)):we.mergeObjectSync(r,l)}get shape(){return this._def.shape()}strict(e){return R.errToObj,new t({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,r)=>{let o=this._def.errorMap?.(n,r).message??r.defaultError;return n.code==="unrecognized_keys"?{message:R.errToObj(e).message??o}:{message:o}}}:{}})}strip(){return new t({...this._def,unknownKeys:"strip"})}passthrough(){return new t({...this._def,unknownKeys:"passthrough"})}extend(e){return new t({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new t({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:D.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new t({...this._def,catchall:e})}pick(e){let n={};for(let r of V.objectKeys(e))e[r]&&this.shape[r]&&(n[r]=this.shape[r]);return new t({...this._def,shape:()=>n})}omit(e){let n={};for(let r of V.objectKeys(this.shape))e[r]||(n[r]=this.shape[r]);return new t({...this._def,shape:()=>n})}deepPartial(){return xn(this)}partial(e){let n={};for(let r of V.objectKeys(this.shape)){let o=this.shape[r];e&&!e[r]?n[r]=o:n[r]=o.optional()}return new t({...this._def,shape:()=>n})}required(e){let n={};for(let r of V.objectKeys(this.shape))if(e&&!e[r])n[r]=this.shape[r];else{let i=this.shape[r];for(;i instanceof Ge;)i=i._def.innerType;n[r]=i}return new t({...this._def,shape:()=>n})}keyof(){return uc(V.objectKeys(this.shape))}};Me.create=(t,e)=>new Me({shape:()=>t,unknownKeys:"strip",catchall:Xe.create(),typeName:D.ZodObject,...F(e)});Me.strictCreate=(t,e)=>new Me({shape:()=>t,unknownKeys:"strict",catchall:Xe.create(),typeName:D.ZodObject,...F(e)});Me.lazycreate=(t,e)=>new Me({shape:t,unknownKeys:"strip",catchall:Xe.create(),typeName:D.ZodObject,...F(e)});var Gt=class extends ${_parse(e){let{ctx:n}=this._processInputParams(e),r=this._def.options;function o(i){for(let a of i)if(a.result.status==="valid")return a.result;for(let a of i)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;let s=i.map(a=>new Oe(a.ctx.common.issues));return k(n,{code:E.invalid_union,unionErrors:s}),P}if(n.common.async)return Promise.all(r.map(async i=>{let s={...n,common:{...n.common,issues:[]},parent:null};return{result:await i._parseAsync({data:n.data,path:n.path,parent:s}),ctx:s}})).then(o);{let i,s=[];for(let l of r){let c={...n,common:{...n.common,issues:[]},parent:null},u=l._parseSync({data:n.data,path:n.path,parent:c});if(u.status==="valid")return u;u.status==="dirty"&&!i&&(i={result:u,ctx:c}),c.common.issues.length&&s.push(c.common.issues)}if(i)return n.common.issues.push(...i.ctx.common.issues),i.result;let a=s.map(l=>new Oe(l));return k(n,{code:E.invalid_union,unionErrors:a}),P}}get options(){return this._def.options}};Gt.create=(t,e)=>new Gt({options:t,typeName:D.ZodUnion,...F(e)});var ht=t=>t instanceof Bt?ht(t.schema):t instanceof Be?ht(t.innerType()):t instanceof Vt?[t.value]:t instanceof jt?t.options:t instanceof qt?V.objectValues(t.enum):t instanceof Wt?ht(t._def.innerType):t instanceof zt?[void 0]:t instanceof Ft?[null]:t instanceof Ge?[void 0,...ht(t.unwrap())]:t instanceof st?[null,...ht(t.unwrap())]:t instanceof Zn||t instanceof Kt?ht(t.unwrap()):t instanceof Xt?ht(t._def.innerType):[],Xr=class t extends ${_parse(e){let{ctx:n}=this._processInputParams(e);if(n.parsedType!==C.object)return k(n,{code:E.invalid_type,expected:C.object,received:n.parsedType}),P;let r=this.discriminator,o=n.data[r],i=this.optionsMap.get(o);return i?n.common.async?i._parseAsync({data:n.data,path:n.path,parent:n}):i._parseSync({data:n.data,path:n.path,parent:n}):(k(n,{code:E.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),P)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,n,r){let o=new Map;for(let i of n){let s=ht(i.shape[e]);if(!s.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let a of s){if(o.has(a))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(a)}`);o.set(a,i)}}return new t({typeName:D.ZodDiscriminatedUnion,discriminator:e,options:n,optionsMap:o,...F(r)})}};function Ms(t,e){let n=ot(t),r=ot(e);if(t===e)return{valid:!0,data:t};if(n===C.object&&r===C.object){let o=V.objectKeys(e),i=V.objectKeys(t).filter(a=>o.indexOf(a)!==-1),s={...t,...e};for(let a of i){let l=Ms(t[a],e[a]);if(!l.valid)return{valid:!1};s[a]=l.data}return{valid:!0,data:s}}else if(n===C.array&&r===C.array){if(t.length!==e.length)return{valid:!1};let o=[];for(let i=0;i<t.length;i++){let s=t[i],a=e[i],l=Ms(s,a);if(!l.valid)return{valid:!1};o.push(l.data)}return{valid:!0,data:o}}else return n===C.date&&r===C.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}var $t=class extends ${_parse(e){let{status:n,ctx:r}=this._processInputParams(e),o=(i,s)=>{if(qr(i)||qr(s))return P;let a=Ms(i.value,s.value);return a.valid?((Wr(i)||Wr(s))&&n.dirty(),{status:n.value,value:a.data}):(k(r,{code:E.invalid_intersection_types}),P)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([i,s])=>o(i,s)):o(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}};$t.create=(t,e,n)=>new $t({left:t,right:e,typeName:D.ZodIntersection,...F(n)});var it=class t extends ${_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==C.array)return k(r,{code:E.invalid_type,expected:C.array,received:r.parsedType}),P;if(r.data.length<this._def.items.length)return k(r,{code:E.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),P;!this._def.rest&&r.data.length>this._def.items.length&&(k(r,{code:E.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());let i=[...r.data].map((s,a)=>{let l=this._def.items[a]||this._def.rest;return l?l._parse(new $e(r,s,r.path,a)):null}).filter(s=>!!s);return r.common.async?Promise.all(i).then(s=>we.mergeArray(n,s)):we.mergeArray(n,i)}get items(){return this._def.items}rest(e){return new t({...this._def,rest:e})}};it.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new it({items:t,typeName:D.ZodTuple,rest:null,...F(e)})};var Kr=class t extends ${get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==C.object)return k(r,{code:E.invalid_type,expected:C.object,received:r.parsedType}),P;let o=[],i=this._def.keyType,s=this._def.valueType;for(let a in r.data)o.push({key:i._parse(new $e(r,a,r.path,a)),value:s._parse(new $e(r,r.data[a],r.path,a)),alwaysSet:a in r.data});return r.common.async?we.mergeObjectAsync(n,o):we.mergeObjectSync(n,o)}get element(){return this._def.valueType}static create(e,n,r){return n instanceof $?new t({keyType:e,valueType:n,typeName:D.ZodRecord,...F(r)}):new t({keyType:St.create(),valueType:e,typeName:D.ZodRecord,...F(n)})}},_n=class extends ${get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==C.map)return k(r,{code:E.invalid_type,expected:C.map,received:r.parsedType}),P;let o=this._def.keyType,i=this._def.valueType,s=[...r.data.entries()].map(([a,l],c)=>({key:o._parse(new $e(r,a,r.path,[c,"key"])),value:i._parse(new $e(r,l,r.path,[c,"value"]))}));if(r.common.async){let a=new Map;return Promise.resolve().then(async()=>{for(let l of s){let c=await l.key,u=await l.value;if(c.status==="aborted"||u.status==="aborted")return P;(c.status==="dirty"||u.status==="dirty")&&n.dirty(),a.set(c.value,u.value)}return{status:n.value,value:a}})}else{let a=new Map;for(let l of s){let c=l.key,u=l.value;if(c.status==="aborted"||u.status==="aborted")return P;(c.status==="dirty"||u.status==="dirty")&&n.dirty(),a.set(c.value,u.value)}return{status:n.value,value:a}}}};_n.create=(t,e,n)=>new _n({valueType:e,keyType:t,typeName:D.ZodMap,...F(n)});var Tn=class t extends ${_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==C.set)return k(r,{code:E.invalid_type,expected:C.set,received:r.parsedType}),P;let o=this._def;o.minSize!==null&&r.data.size<o.minSize.value&&(k(r,{code:E.too_small,minimum:o.minSize.value,type:"set",inclusive:!0,exact:!1,message:o.minSize.message}),n.dirty()),o.maxSize!==null&&r.data.size>o.maxSize.value&&(k(r,{code:E.too_big,maximum:o.maxSize.value,type:"set",inclusive:!0,exact:!1,message:o.maxSize.message}),n.dirty());let i=this._def.valueType;function s(l){let c=new Set;for(let u of l){if(u.status==="aborted")return P;u.status==="dirty"&&n.dirty(),c.add(u.value)}return{status:n.value,value:c}}let a=[...r.data.values()].map((l,c)=>i._parse(new $e(r,l,r.path,c)));return r.common.async?Promise.all(a).then(l=>s(l)):s(a)}min(e,n){return new t({...this._def,minSize:{value:e,message:R.toString(n)}})}max(e,n){return new t({...this._def,maxSize:{value:e,message:R.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}};Tn.create=(t,e)=>new Tn({valueType:t,minSize:null,maxSize:null,typeName:D.ZodSet,...F(e)});var Yr=class t extends ${constructor(){super(...arguments),this.validate=this.implement}_parse(e){let{ctx:n}=this._processInputParams(e);if(n.parsedType!==C.function)return k(n,{code:E.invalid_type,expected:C.function,received:n.parsedType}),P;function r(a,l){return Yn({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,bn(),pt].filter(c=>!!c),issueData:{code:E.invalid_arguments,argumentsError:l}})}function o(a,l){return Yn({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,bn(),pt].filter(c=>!!c),issueData:{code:E.invalid_return_type,returnTypeError:l}})}let i={errorMap:n.common.contextualErrorMap},s=n.data;if(this._def.returns instanceof kt){let a=this;return Ae(async function(...l){let c=new Oe([]),u=await a._def.args.parseAsync(l,i).catch(f=>{throw c.addIssue(r(l,f)),c}),m=await Reflect.apply(s,this,u);return await a._def.returns._def.type.parseAsync(m,i).catch(f=>{throw c.addIssue(o(m,f)),c})})}else{let a=this;return Ae(function(...l){let c=a._def.args.safeParse(l,i);if(!c.success)throw new Oe([r(l,c.error)]);let u=Reflect.apply(s,this,c.data),m=a._def.returns.safeParse(u,i);if(!m.success)throw new Oe([o(u,m.error)]);return m.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new t({...this._def,args:it.create(e).rest(ft.create())})}returns(e){return new t({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,n,r){return new t({args:e||it.create([]).rest(ft.create()),returns:n||ft.create(),typeName:D.ZodFunction,...F(r)})}},Bt=class extends ${get schema(){return this._def.getter()}_parse(e){let{ctx:n}=this._processInputParams(e);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}};Bt.create=(t,e)=>new Bt({getter:t,typeName:D.ZodLazy,...F(e)});var Vt=class extends ${_parse(e){if(e.data!==this._def.value){let n=this._getOrReturnCtx(e);return k(n,{received:n.data,code:E.invalid_literal,expected:this._def.value}),P}return{status:"valid",value:e.data}}get value(){return this._def.value}};Vt.create=(t,e)=>new Vt({value:t,typeName:D.ZodLiteral,...F(e)});function uc(t,e){return new jt({values:t,typeName:D.ZodEnum,...F(e)})}var jt=class t extends ${_parse(e){if(typeof e.data!="string"){let n=this._getOrReturnCtx(e),r=this._def.values;return k(n,{expected:V.joinValues(r),received:n.parsedType,code:E.invalid_type}),P}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let n=this._getOrReturnCtx(e),r=this._def.values;return k(n,{received:n.data,code:E.invalid_enum_value,options:r}),P}return Ae(e.data)}get options(){return this._def.values}get enum(){let e={};for(let n of this._def.values)e[n]=n;return e}get Values(){let e={};for(let n of this._def.values)e[n]=n;return e}get Enum(){let e={};for(let n of this._def.values)e[n]=n;return e}extract(e,n=this._def){return t.create(e,{...this._def,...n})}exclude(e,n=this._def){return t.create(this.options.filter(r=>!e.includes(r)),{...this._def,...n})}};jt.create=uc;var qt=class extends ${_parse(e){let n=V.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==C.string&&r.parsedType!==C.number){let o=V.objectValues(n);return k(r,{expected:V.joinValues(o),received:r.parsedType,code:E.invalid_type}),P}if(this._cache||(this._cache=new Set(V.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let o=V.objectValues(n);return k(r,{received:r.data,code:E.invalid_enum_value,options:o}),P}return Ae(e.data)}get enum(){return this._def.values}};qt.create=(t,e)=>new qt({values:t,typeName:D.ZodNativeEnum,...F(e)});var kt=class extends ${unwrap(){return this._def.type}_parse(e){let{ctx:n}=this._processInputParams(e);if(n.parsedType!==C.promise&&n.common.async===!1)return k(n,{code:E.invalid_type,expected:C.promise,received:n.parsedType}),P;let r=n.parsedType===C.promise?n.data:Promise.resolve(n.data);return Ae(r.then(o=>this._def.type.parseAsync(o,{path:n.path,errorMap:n.common.contextualErrorMap})))}};kt.create=(t,e)=>new kt({type:t,typeName:D.ZodPromise,...F(e)});var Be=class extends ${innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===D.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:n,ctx:r}=this._processInputParams(e),o=this._def.effect||null,i={addIssue:s=>{k(r,s),s.fatal?n.abort():n.dirty()},get path(){return r.path}};if(i.addIssue=i.addIssue.bind(i),o.type==="preprocess"){let s=o.transform(r.data,i);if(r.common.async)return Promise.resolve(s).then(async a=>{if(n.value==="aborted")return P;let l=await this._def.schema._parseAsync({data:a,path:r.path,parent:r});return l.status==="aborted"?P:l.status==="dirty"?Lt(l.value):n.value==="dirty"?Lt(l.value):l});{if(n.value==="aborted")return P;let a=this._def.schema._parseSync({data:s,path:r.path,parent:r});return a.status==="aborted"?P:a.status==="dirty"?Lt(a.value):n.value==="dirty"?Lt(a.value):a}}if(o.type==="refinement"){let s=a=>{let l=o.refinement(a,i);if(r.common.async)return Promise.resolve(l);if(l instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(r.common.async===!1){let a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?P:(a.status==="dirty"&&n.dirty(),s(a.value),{status:n.value,value:a.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>a.status==="aborted"?P:(a.status==="dirty"&&n.dirty(),s(a.value).then(()=>({status:n.value,value:a.value}))))}if(o.type==="transform")if(r.common.async===!1){let s=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Tt(s))return P;let a=o.transform(s.value,i);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:a}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(s=>Tt(s)?Promise.resolve(o.transform(s.value,i)).then(a=>({status:n.value,value:a})):P);V.assertNever(o)}};Be.create=(t,e,n)=>new Be({schema:t,typeName:D.ZodEffects,effect:e,...F(n)});Be.createWithPreprocess=(t,e,n)=>new Be({schema:e,effect:{type:"preprocess",transform:t},typeName:D.ZodEffects,...F(n)});var Ge=class extends ${_parse(e){return this._getType(e)===C.undefined?Ae(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};Ge.create=(t,e)=>new Ge({innerType:t,typeName:D.ZodOptional,...F(e)});var st=class extends ${_parse(e){return this._getType(e)===C.null?Ae(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};st.create=(t,e)=>new st({innerType:t,typeName:D.ZodNullable,...F(e)});var Wt=class extends ${_parse(e){let{ctx:n}=this._processInputParams(e),r=n.data;return n.parsedType===C.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}};Wt.create=(t,e)=>new Wt({innerType:t,typeName:D.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...F(e)});var Xt=class extends ${_parse(e){let{ctx:n}=this._processInputParams(e),r={...n,common:{...n.common,issues:[]}},o=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return yn(o)?o.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new Oe(r.common.issues)},input:r.data})})):{status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new Oe(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}};Xt.create=(t,e)=>new Xt({innerType:t,typeName:D.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...F(e)});var Sn=class extends ${_parse(e){if(this._getType(e)!==C.nan){let r=this._getOrReturnCtx(e);return k(r,{code:E.invalid_type,expected:C.nan,received:r.parsedType}),P}return{status:"valid",value:e.data}}};Sn.create=t=>new Sn({typeName:D.ZodNaN,...F(t)});var mh=Symbol("zod_brand"),Zn=class extends ${_parse(e){let{ctx:n}=this._processInputParams(e),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}},Qn=class t extends ${_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{let i=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?P:i.status==="dirty"?(n.dirty(),Lt(i.value)):this._def.out._parseAsync({data:i.value,path:r.path,parent:r})})();{let o=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?P:o.status==="dirty"?(n.dirty(),{status:"dirty",value:o.value}):this._def.out._parseSync({data:o.value,path:r.path,parent:r})}}static create(e,n){return new t({in:e,out:n,typeName:D.ZodPipeline})}},Kt=class extends ${_parse(e){let n=this._def.innerType._parse(e),r=o=>(Tt(o)&&(o.value=Object.freeze(o.value)),o);return yn(n)?n.then(o=>r(o)):r(n)}unwrap(){return this._def.innerType}};Kt.create=(t,e)=>new Kt({innerType:t,typeName:D.ZodReadonly,...F(e)});function ac(t,e){let n=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof n=="string"?{message:n}:n}function pc(t,e={},n){return t?At.create().superRefine((r,o)=>{let i=t(r);if(i instanceof Promise)return i.then(s=>{if(!s){let a=ac(e,r),l=a.fatal??n??!0;o.addIssue({code:"custom",...a,fatal:l})}});if(!i){let s=ac(e,r),a=s.fatal??n??!0;o.addIssue({code:"custom",...s,fatal:a})}}):At.create()}var gh={object:Me.lazycreate},D;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(D||(D={}));var vh=(t,e={message:`Input not instance of ${t.name}`})=>pc(n=>n instanceof t,e),hc=St.create,fc=Pt.create,bh=Sn.create,yh=Dt.create,mc=Ut.create,xh=Ht.create,wh=wn.create,Eh=zt.create,_h=Ft.create,Th=At.create,Sh=ft.create,Ah=Xe.create,kh=En.create,Ch=mt.create,Ih=Me.create,Rh=Me.strictCreate,Nh=Gt.create,Oh=Xr.create,Mh=$t.create,Lh=it.create,Ph=Kr.create,Dh=_n.create,Uh=Tn.create,Hh=Yr.create,zh=Bt.create,Fh=Vt.create,Gh=jt.create,$h=qt.create,Bh=kt.create,Vh=Be.create,jh=Ge.create,qh=st.create,Wh=Be.createWithPreprocess,Xh=Qn.create,Kh=()=>hc().optional(),Yh=()=>fc().optional(),Zh=()=>mc().optional(),Qh={string:(t=>St.create({...t,coerce:!0})),number:(t=>Pt.create({...t,coerce:!0})),boolean:(t=>Ut.create({...t,coerce:!0})),bigint:(t=>Dt.create({...t,coerce:!0})),date:(t=>Ht.create({...t,coerce:!0}))};var Jh=P;var ef=d.object({name:d.string(),arguments:d.string()}),tf=d.object({id:d.string(),type:d.literal("function"),function:ef,encryptedValue:d.string().optional()}),Zr=d.object({id:d.string(),role:d.string(),content:d.string().optional(),name:d.string().optional(),encryptedValue:d.string().optional()}),nf=d.object({type:d.literal("text"),text:d.string()}),rf=d.object({type:d.literal("data"),value:d.string(),mimeType:d.string()}),of=d.object({type:d.literal("url"),value:d.string(),mimeType:d.string().optional()}),Qr=d.discriminatedUnion("type",[rf,of]),sf=d.object({type:d.literal("image"),source:Qr,metadata:d.unknown().optional()}),af=d.object({type:d.literal("audio"),source:Qr,metadata:d.unknown().optional()}),lf=d.object({type:d.literal("video"),source:Qr,metadata:d.unknown().optional()}),cf=d.object({type:d.literal("document"),source:Qr,metadata:d.unknown().optional()});var gc=d.object({type:d.literal("binary"),mimeType:d.string(),id:d.string().optional(),url:d.string().optional(),data:d.string().optional(),filename:d.string().optional()}),vc=(t,e)=>{!t.id&&!t.url&&!t.data&&e.addIssue({code:d.ZodIssueCode.custom,message:"BinaryInputContent requires at least one of id, url, or data.",path:["id"]})},Gx=gc.superRefine((t,e)=>{vc(t,e)}),df=d.discriminatedUnion("type",[nf,sf,af,lf,cf,gc]),uf=df.superRefine((t,e)=>{t.type==="binary"&&vc(t,e)}),pf=Zr.extend({role:d.literal("developer"),content:d.string()}),hf=Zr.extend({role:d.literal("system"),content:d.string()}),ff=Zr.extend({role:d.literal("assistant"),content:d.string().optional(),toolCalls:d.array(tf).optional()}),mf=Zr.extend({role:d.literal("user"),content:d.union([d.string(),d.array(uf)])}),gf=d.object({id:d.string(),content:d.string(),role:d.literal("tool"),toolCallId:d.string(),error:d.string().optional(),encryptedValue:d.string().optional()}),vf=d.object({id:d.string(),role:d.literal("activity"),activityType:d.string(),content:d.record(d.any())}),bf=d.object({id:d.string(),role:d.literal("reasoning"),content:d.string(),encryptedValue:d.string().optional()}),bc=d.discriminatedUnion("role",[pf,hf,ff,mf,gf,vf,bf]),$x=d.union([d.literal("developer"),d.literal("system"),d.literal("assistant"),d.literal("user"),d.literal("tool"),d.literal("activity"),d.literal("reasoning")]),yf=d.object({description:d.string(),value:d.string()}),yc=d.object({name:d.string(),description:d.string(),parameters:d.any(),metadata:d.record(d.any()).optional()}),xf=d.object({id:d.string(),reason:d.string(),message:d.string().optional(),toolCallId:d.string().optional(),responseSchema:d.record(d.any()).optional(),expiresAt:d.string().optional(),metadata:d.record(d.any()).optional()}),wf=d.object({interruptId:d.string(),status:d.enum(["resolved","cancelled"]),payload:d.any().optional()}),Ef=d.object({threadId:d.string(),runId:d.string(),parentRunId:d.string().optional(),state:d.any(),messages:d.array(bc),tools:d.array(yc),context:d.array(yf),forwardedProps:d.any(),resume:d.array(wf).optional()}),_f=d.any(),te=class extends Error{constructor(t){super(t)}},Ls=class extends te{constructor(){super("Connect not implemented. This method is not supported by the current agent.")}},Tf=d.object({name:d.string(),description:d.string().optional()}),Sf=d.object({name:d.string().optional(),type:d.string().optional(),description:d.string().optional(),version:d.string().optional(),provider:d.string().optional(),documentationUrl:d.string().optional(),metadata:d.record(d.unknown()).optional()}),Af=d.object({streaming:d.boolean().optional(),websocket:d.boolean().optional(),httpBinary:d.boolean().optional(),pushNotifications:d.boolean().optional(),resumable:d.boolean().optional()}),kf=d.object({supported:d.boolean().optional(),items:d.array(yc).optional(),parallelCalls:d.boolean().optional(),clientProvided:d.boolean().optional()}),Cf=d.object({structuredOutput:d.boolean().optional(),supportedMimeTypes:d.array(d.string()).optional()}),If=d.object({snapshots:d.boolean().optional(),deltas:d.boolean().optional(),memory:d.boolean().optional(),persistentState:d.boolean().optional()}),Rf=d.object({supported:d.boolean().optional(),delegation:d.boolean().optional(),handoffs:d.boolean().optional(),subAgents:d.array(Tf).optional()}),Nf=d.object({supported:d.boolean().optional(),streaming:d.boolean().optional(),encrypted:d.boolean().optional()}),Of=d.object({image:d.boolean().optional(),audio:d.boolean().optional(),video:d.boolean().optional(),pdf:d.boolean().optional(),file:d.boolean().optional()}),Mf=d.object({image:d.boolean().optional(),audio:d.boolean().optional()}),Lf=d.object({input:Of.optional(),output:Mf.optional()}),Pf=d.object({codeExecution:d.boolean().optional(),sandboxed:d.boolean().optional(),maxIterations:d.number().optional(),maxExecutionTime:d.number().optional()}),Df=d.object({supported:d.boolean().optional(),approvals:d.boolean().optional(),interventions:d.boolean().optional(),feedback:d.boolean().optional(),interrupts:d.boolean().optional(),approveWithEdits:d.boolean().optional()}),Bx=d.object({identity:Sf.optional(),transport:Af.optional(),tools:kf.optional(),output:Cf.optional(),state:If.optional(),multiAgent:Rf.optional(),reasoning:Nf.optional(),multimodal:Lf.optional(),execution:Pf.optional(),humanInTheLoop:Df.optional(),custom:d.record(d.unknown()).optional()}),xc=d.union([d.literal("developer"),d.literal("system"),d.literal("assistant"),d.literal("user")]),v=(function(t){return t.TEXT_MESSAGE_START="TEXT_MESSAGE_START",t.TEXT_MESSAGE_CONTENT="TEXT_MESSAGE_CONTENT",t.TEXT_MESSAGE_END="TEXT_MESSAGE_END",t.TEXT_MESSAGE_CHUNK="TEXT_MESSAGE_CHUNK",t.TOOL_CALL_START="TOOL_CALL_START",t.TOOL_CALL_ARGS="TOOL_CALL_ARGS",t.TOOL_CALL_END="TOOL_CALL_END",t.TOOL_CALL_CHUNK="TOOL_CALL_CHUNK",t.TOOL_CALL_RESULT="TOOL_CALL_RESULT",t.THINKING_START="THINKING_START",t.THINKING_END="THINKING_END",t.THINKING_TEXT_MESSAGE_START="THINKING_TEXT_MESSAGE_START",t.THINKING_TEXT_MESSAGE_CONTENT="THINKING_TEXT_MESSAGE_CONTENT",t.THINKING_TEXT_MESSAGE_END="THINKING_TEXT_MESSAGE_END",t.STATE_SNAPSHOT="STATE_SNAPSHOT",t.STATE_DELTA="STATE_DELTA",t.MESSAGES_SNAPSHOT="MESSAGES_SNAPSHOT",t.ACTIVITY_SNAPSHOT="ACTIVITY_SNAPSHOT",t.ACTIVITY_DELTA="ACTIVITY_DELTA",t.RAW="RAW",t.CUSTOM="CUSTOM",t.RUN_STARTED="RUN_STARTED",t.RUN_FINISHED="RUN_FINISHED",t.RUN_ERROR="RUN_ERROR",t.STEP_STARTED="STEP_STARTED",t.STEP_FINISHED="STEP_FINISHED",t.REASONING_START="REASONING_START",t.REASONING_MESSAGE_START="REASONING_MESSAGE_START",t.REASONING_MESSAGE_CONTENT="REASONING_MESSAGE_CONTENT",t.REASONING_MESSAGE_END="REASONING_MESSAGE_END",t.REASONING_MESSAGE_CHUNK="REASONING_MESSAGE_CHUNK",t.REASONING_END="REASONING_END",t.REASONING_ENCRYPTED_VALUE="REASONING_ENCRYPTED_VALUE",t})({}),X=d.object({type:d.nativeEnum(v),timestamp:d.number().optional(),rawEvent:d.any().optional()}).passthrough(),Uf=X.extend({type:d.literal(v.TEXT_MESSAGE_START),messageId:d.string(),role:xc.default("assistant"),name:d.string().optional()}),wc=X.extend({type:d.literal(v.TEXT_MESSAGE_CONTENT),messageId:d.string(),delta:d.string()}),Hf=X.extend({type:d.literal(v.TEXT_MESSAGE_END),messageId:d.string()}),zf=X.extend({type:d.literal(v.TEXT_MESSAGE_CHUNK),messageId:d.string().optional(),role:xc.optional(),delta:d.string().optional(),name:d.string().optional()}),Ff=X.extend({type:d.literal(v.THINKING_TEXT_MESSAGE_START)}),Gf=wc.omit({messageId:!0,type:!0}).extend({type:d.literal(v.THINKING_TEXT_MESSAGE_CONTENT)}),$f=X.extend({type:d.literal(v.THINKING_TEXT_MESSAGE_END)}),Bf=X.extend({type:d.literal(v.TOOL_CALL_START),toolCallId:d.string(),toolCallName:d.string(),parentMessageId:d.string().optional()}),Vf=X.extend({type:d.literal(v.TOOL_CALL_ARGS),toolCallId:d.string(),delta:d.string()}),jf=X.extend({type:d.literal(v.TOOL_CALL_END),toolCallId:d.string()}),qf=X.extend({messageId:d.string(),type:d.literal(v.TOOL_CALL_RESULT),toolCallId:d.string(),content:d.string(),role:d.literal("tool").optional()}),Wf=X.extend({type:d.literal(v.TOOL_CALL_CHUNK),toolCallId:d.string().optional(),toolCallName:d.string().optional(),parentMessageId:d.string().optional(),delta:d.string().optional()}),Xf=X.extend({type:d.literal(v.THINKING_START),title:d.string().optional()}),Kf=X.extend({type:d.literal(v.THINKING_END)}),Yf=X.extend({type:d.literal(v.STATE_SNAPSHOT),snapshot:_f}),Zf=X.extend({type:d.literal(v.STATE_DELTA),delta:d.array(d.any())}),Qf=X.extend({type:d.literal(v.MESSAGES_SNAPSHOT),messages:d.array(bc)}),Jf=X.extend({type:d.literal(v.ACTIVITY_SNAPSHOT),messageId:d.string(),activityType:d.string(),content:d.record(d.any()),replace:d.boolean().optional().default(!0)}),em=X.extend({type:d.literal(v.ACTIVITY_DELTA),messageId:d.string(),activityType:d.string(),patch:d.array(d.any())}),tm=X.extend({type:d.literal(v.RAW),event:d.any(),source:d.string().optional()}),nm=X.extend({type:d.literal(v.CUSTOM),name:d.string(),value:d.any()}),rm=X.extend({type:d.literal(v.RUN_STARTED),threadId:d.string(),runId:d.string(),parentRunId:d.string().optional(),input:Ef.optional()}),om=d.object({type:d.literal("success")}).strict(),im=d.object({type:d.literal("interrupt"),interrupts:d.array(xf).min(1)}).strict(),sm=d.discriminatedUnion("type",[om,im]),am=X.extend({type:d.literal(v.RUN_FINISHED),threadId:d.string(),runId:d.string(),result:d.any().optional(),outcome:sm.nullable().optional().transform(t=>t??void 0)}),lm=X.extend({type:d.literal(v.RUN_ERROR),message:d.string(),code:d.string().optional()}),cm=X.extend({type:d.literal(v.STEP_STARTED),stepName:d.string()}),dm=X.extend({type:d.literal(v.STEP_FINISHED),stepName:d.string()}),um=d.union([d.literal("tool-call"),d.literal("message")]),pm=X.extend({type:d.literal(v.REASONING_START),messageId:d.string()}),hm=X.extend({type:d.literal(v.REASONING_MESSAGE_START),messageId:d.string(),role:d.literal("reasoning")}),fm=X.extend({type:d.literal(v.REASONING_MESSAGE_CONTENT),messageId:d.string(),delta:d.string()}),mm=X.extend({type:d.literal(v.REASONING_MESSAGE_END),messageId:d.string()}),gm=X.extend({type:d.literal(v.REASONING_MESSAGE_CHUNK),messageId:d.string().optional(),delta:d.string().optional()}),vm=X.extend({type:d.literal(v.REASONING_END),messageId:d.string()}),bm=X.extend({type:d.literal(v.REASONING_ENCRYPTED_VALUE),subtype:um,entityId:d.string(),encryptedValue:d.string()}),Jr=d.discriminatedUnion("type",[Uf,wc,Hf,zf,Xf,Kf,Ff,Gf,$f,Bf,Vf,jf,Wf,qf,Yf,Zf,Qf,Jf,em,tm,nm,rm,am,lm,cm,dm,pm,hm,fm,mm,gm,vm,bm]);var Ps={};us(Ps,{JsonPatchError:()=>he,_areEquals:()=>tr,applyOperation:()=>Yt,applyPatch:()=>so,applyReducer:()=>_m,deepClone:()=>wm,getValueByPointer:()=>oo,validate:()=>_c,validator:()=>io});var ym=(function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,o){r.__proto__=o}||function(r,o){for(var i in o)o.hasOwnProperty(i)&&(r[i]=o[i])},t(e,n)};return function(e,n){t(e,n);function r(){this.constructor=e}e.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}})(),xm=Object.prototype.hasOwnProperty;function to(t,e){return xm.call(t,e)}function no(t){if(Array.isArray(t)){for(var e=new Array(t.length),n=0;n<e.length;n++)e[n]=""+n;return e}if(Object.keys)return Object.keys(t);var r=[];for(var o in t)to(t,o)&&r.push(o);return r}function Ee(t){switch(typeof t){case"object":return JSON.parse(JSON.stringify(t));case"undefined":return null;default:return t}}function ro(t){for(var e=0,n=t.length,r;e<n;){if(r=t.charCodeAt(e),r>=48&&r<=57){e++;continue}return!1}return!0}function at(t){return t.indexOf("/")===-1&&t.indexOf("~")===-1?t:t.replace(/~/g,"~0").replace(/\//g,"~1")}function Jn(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function eo(t){if(t===void 0)return!0;if(t){if(Array.isArray(t)){for(var e=0,n=t.length;e<n;e++)if(eo(t[e]))return!0}else if(typeof t=="object"){for(var r=no(t),o=r.length,i=0;i<o;i++)if(eo(t[r[i]]))return!0}}return!1}function Ec(t,e){var n=[t];for(var r in e){var o=typeof e[r]=="object"?JSON.stringify(e[r],null,2):e[r];typeof o<"u"&&n.push(r+": "+o)}return n.join(`
2
- `)}var er=(function(t){ym(e,t);function e(n,r,o,i,s){var a=this.constructor,l=t.call(this,Ec(n,{name:r,index:o,operation:i,tree:s}))||this;return l.name=r,l.index=o,l.operation=i,l.tree=s,Object.setPrototypeOf(l,a.prototype),l.message=Ec(n,{name:r,index:o,operation:i,tree:s}),l}return e})(Error);var he=er,wm=Ee,An={add:function(t,e,n){return t[e]=this.value,{newDocument:n}},remove:function(t,e,n){var r=t[e];return delete t[e],{newDocument:n,removed:r}},replace:function(t,e,n){var r=t[e];return t[e]=this.value,{newDocument:n,removed:r}},move:function(t,e,n){var r=oo(n,this.path);r&&(r=Ee(r));var o=Yt(n,{op:"remove",path:this.from}).removed;return Yt(n,{op:"add",path:this.path,value:o}),{newDocument:n,removed:r}},copy:function(t,e,n){var r=oo(n,this.from);return Yt(n,{op:"add",path:this.path,value:Ee(r)}),{newDocument:n}},test:function(t,e,n){return{newDocument:n,test:tr(t[e],this.value)}},_get:function(t,e,n){return this.value=t[e],{newDocument:n}}},Em={add:function(t,e,n){return ro(e)?t.splice(e,0,this.value):t[e]=this.value,{newDocument:n,index:e}},remove:function(t,e,n){var r=t.splice(e,1);return{newDocument:n,removed:r[0]}},replace:function(t,e,n){var r=t[e];return t[e]=this.value,{newDocument:n,removed:r}},move:An.move,copy:An.copy,test:An.test,_get:An._get};function oo(t,e){if(e=="")return t;var n={op:"_get",path:e};return Yt(t,n),n.value}function Yt(t,e,n,r,o,i){if(n===void 0&&(n=!1),r===void 0&&(r=!0),o===void 0&&(o=!0),i===void 0&&(i=0),n&&(typeof n=="function"?n(e,0,t,e.path):io(e,0)),e.path===""){var s={newDocument:t};if(e.op==="add")return s.newDocument=e.value,s;if(e.op==="replace")return s.newDocument=e.value,s.removed=t,s;if(e.op==="move"||e.op==="copy")return s.newDocument=oo(t,e.from),e.op==="move"&&(s.removed=t),s;if(e.op==="test"){if(s.test=tr(t,e.value),s.test===!1)throw new he("Test operation failed","TEST_OPERATION_FAILED",i,e,t);return s.newDocument=t,s}else{if(e.op==="remove")return s.removed=t,s.newDocument=null,s;if(e.op==="_get")return e.value=t,s;if(n)throw new he("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",i,e,t);return s}}else{r||(t=Ee(t));var a=e.path||"",l=a.split("/"),c=t,u=1,m=l.length,y=void 0,f=void 0,h=void 0;for(typeof n=="function"?h=n:h=io;;){if(f=l[u],f&&f.indexOf("~")!=-1&&(f=Jn(f)),o&&(f=="__proto__"||f=="prototype"&&u>0&&l[u-1]=="constructor"))throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");if(n&&y===void 0&&(c[f]===void 0?y=l.slice(0,u).join("/"):u==m-1&&(y=e.path),y!==void 0&&h(e,0,t,y)),u++,Array.isArray(c)){if(f==="-")f=c.length;else{if(n&&!ro(f))throw new he("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",i,e,t);ro(f)&&(f=~~f)}if(u>=m){if(n&&e.op==="add"&&f>c.length)throw new he("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",i,e,t);var s=Em[e.op].call(e,c,f,t);if(s.test===!1)throw new he("Test operation failed","TEST_OPERATION_FAILED",i,e,t);return s}}else if(u>=m){var s=An[e.op].call(e,c,f,t);if(s.test===!1)throw new he("Test operation failed","TEST_OPERATION_FAILED",i,e,t);return s}if(c=c[f],n&&u<m&&(!c||typeof c!="object"))throw new he("Cannot perform operation at the desired path","OPERATION_PATH_UNRESOLVABLE",i,e,t)}}}function so(t,e,n,r,o){if(r===void 0&&(r=!0),o===void 0&&(o=!0),n&&!Array.isArray(e))throw new he("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");r||(t=Ee(t));for(var i=new Array(e.length),s=0,a=e.length;s<a;s++)i[s]=Yt(t,e[s],n,!0,o,s),t=i[s].newDocument;return i.newDocument=t,i}function _m(t,e,n){var r=Yt(t,e);if(r.test===!1)throw new he("Test operation failed","TEST_OPERATION_FAILED",n,e,t);return r.newDocument}function io(t,e,n,r){if(typeof t!="object"||t===null||Array.isArray(t))throw new he("Operation is not an object","OPERATION_NOT_AN_OBJECT",e,t,n);if(An[t.op]){if(typeof t.path!="string")throw new he("Operation `path` property is not a string","OPERATION_PATH_INVALID",e,t,n);if(t.path.indexOf("/")!==0&&t.path.length>0)throw new he('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",e,t,n);if((t.op==="move"||t.op==="copy")&&typeof t.from!="string")throw new he("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",e,t,n);if((t.op==="add"||t.op==="replace"||t.op==="test")&&t.value===void 0)throw new he("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",e,t,n);if((t.op==="add"||t.op==="replace"||t.op==="test")&&eo(t.value))throw new he("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",e,t,n);if(n){if(t.op=="add"){var o=t.path.split("/").length,i=r.split("/").length;if(o!==i+1&&o!==i)throw new he("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",e,t,n)}else if(t.op==="replace"||t.op==="remove"||t.op==="_get"){if(t.path!==r)throw new he("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",e,t,n)}else if(t.op==="move"||t.op==="copy"){var s={op:"_get",path:t.from,value:void 0},a=_c([s],n);if(a&&a.name==="OPERATION_PATH_UNRESOLVABLE")throw new he("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",e,t,n)}}}else throw new he("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",e,t,n)}function _c(t,e,n){try{if(!Array.isArray(t))throw new he("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(e)so(Ee(e),Ee(t),n||!0);else{n=n||io;for(var r=0;r<t.length;r++)n(t[r],r,e,void 0)}}catch(o){if(o instanceof he)return o;throw o}}function tr(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var n=Array.isArray(t),r=Array.isArray(e),o,i,s;if(n&&r){if(i=t.length,i!=e.length)return!1;for(o=i;o--!==0;)if(!tr(t[o],e[o]))return!1;return!0}if(n!=r)return!1;var a=Object.keys(t);if(i=a.length,i!==Object.keys(e).length)return!1;for(o=i;o--!==0;)if(!e.hasOwnProperty(a[o]))return!1;for(o=i;o--!==0;)if(s=a[o],!tr(t[s],e[s]))return!1;return!0}return t!==t&&e!==e}var zs={};us(zs,{compare:()=>Nm,generate:()=>Ds,observe:()=>Rm,unobserve:()=>Im});var Us=new WeakMap,Tm=(function(){function t(e){this.observers=new Map,this.obj=e}return t})(),Sm=(function(){function t(e,n){this.callback=e,this.observer=n}return t})();function Am(t){return Us.get(t)}function km(t,e){return t.observers.get(e)}function Cm(t,e){t.observers.delete(e.callback)}function Im(t,e){e.unobserve()}function Rm(t,e){var n=[],r,o=Am(t);if(!o)o=new Tm(t),Us.set(t,o);else{var i=km(o,e);r=i&&i.observer}if(r)return r;if(r={},o.value=Ee(t),e){r.callback=e,r.next=null;var s=function(){Ds(r)},a=function(){clearTimeout(r.next),r.next=setTimeout(s)};typeof window<"u"&&(window.addEventListener("mouseup",a),window.addEventListener("keyup",a),window.addEventListener("mousedown",a),window.addEventListener("keydown",a),window.addEventListener("change",a))}return r.patches=n,r.object=t,r.unobserve=function(){Ds(r),clearTimeout(r.next),Cm(o,r),typeof window<"u"&&(window.removeEventListener("mouseup",a),window.removeEventListener("keyup",a),window.removeEventListener("mousedown",a),window.removeEventListener("keydown",a),window.removeEventListener("change",a))},o.observers.set(e,new Sm(e,r)),r}function Ds(t,e){e===void 0&&(e=!1);var n=Us.get(t.object);Hs(n.value,t.object,t.patches,"",e),t.patches.length&&so(n.value,t.patches);var r=t.patches;return r.length>0&&(t.patches=[],t.callback&&t.callback(r)),r}function Hs(t,e,n,r,o){if(e!==t){typeof e.toJSON=="function"&&(e=e.toJSON());for(var i=no(e),s=no(t),a=!1,l=!1,c=s.length-1;c>=0;c--){var u=s[c],m=t[u];if(to(e,u)&&!(e[u]===void 0&&m!==void 0&&Array.isArray(e)===!1)){var y=e[u];typeof m=="object"&&m!=null&&typeof y=="object"&&y!=null&&Array.isArray(m)===Array.isArray(y)?Hs(m,y,n,r+"/"+at(u),o):m!==y&&(a=!0,o&&n.push({op:"test",path:r+"/"+at(u),value:Ee(m)}),n.push({op:"replace",path:r+"/"+at(u),value:Ee(y)}))}else Array.isArray(t)===Array.isArray(e)?(o&&n.push({op:"test",path:r+"/"+at(u),value:Ee(m)}),n.push({op:"remove",path:r+"/"+at(u)}),l=!0):(o&&n.push({op:"test",path:r,value:t}),n.push({op:"replace",path:r,value:e}),a=!0)}if(!(!l&&i.length==s.length))for(var c=0;c<i.length;c++){var u=i[c];!to(t,u)&&e[u]!==void 0&&n.push({op:"add",path:r+"/"+at(u),value:Ee(e[u])})}}}function Nm(t,e,n){n===void 0&&(n=!1);var r=[];return Hs(t,e,r,"",n),r}var ao=Object.assign({},Ps,zs,{JsonPatchError:er,deepClone:Ee,escapePathComponent:at,unescapePathComponent:Jn});var Fs=function(t,e){return Fs=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[o]=r[o])},Fs(t,e)};function lt(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");Fs(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}function Tc(t,e,n,r){function o(i){return i instanceof n?i:new n(function(s){s(i)})}return new(n||(n=Promise))(function(i,s){function a(u){try{c(r.next(u))}catch(m){s(m)}}function l(u){try{c(r.throw(u))}catch(m){s(m)}}function c(u){u.done?i(u.value):o(u.value).then(a,l)}c((r=r.apply(t,e||[])).next())})}function lo(t,e){var n={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},r,o,i,s=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function a(c){return function(u){return l([c,u])}}function l(c){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,c[0]&&(n=0)),n;)try{if(r=1,o&&(i=c[0]&2?o.return:c[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,c[1])).done)return i;switch(o=0,i&&(c=[c[0]&2,i.value]),c[0]){case 0:case 1:i=c;break;case 4:return n.label++,{value:c[1],done:!1};case 5:n.label++,o=c[1],c=[0];continue;case 7:c=n.ops.pop(),n.trys.pop();continue;default:if(i=n.trys,!(i=i.length>0&&i[i.length-1])&&(c[0]===6||c[0]===2)){n=0;continue}if(c[0]===3&&(!i||c[1]>i[0]&&c[1]<i[3])){n.label=c[1];break}if(c[0]===6&&n.label<i[1]){n.label=i[1],i=c;break}if(i&&n.label<i[2]){n.label=i[2],n.ops.push(c);break}i[2]&&n.ops.pop(),n.trys.pop();continue}c=e.call(t,n)}catch(u){c=[6,u],o=0}finally{r=i=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}function gt(t){var e=typeof Symbol=="function"&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function kn(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=r.next()).done;)i.push(o.value)}catch(a){s={error:a}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(s)throw s.error}}return i}function Cn(t,e,n){if(n||arguments.length===2)for(var r=0,o=e.length,i;r<o;r++)(i||!(r in e))&&(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return t.concat(i||Array.prototype.slice.call(e))}function Zt(t){return this instanceof Zt?(this.v=t,this):new Zt(t)}function Sc(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(t,e||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(f){return function(h){return Promise.resolve(h).then(f,m)}}function a(f,h){r[f]&&(o[f]=function(g){return new Promise(function(x,S){i.push([f,g,x,S])>1||l(f,g)})},h&&(o[f]=h(o[f])))}function l(f,h){try{c(r[f](h))}catch(g){y(i[0][3],g)}}function c(f){f.value instanceof Zt?Promise.resolve(f.value.v).then(u,m):y(i[0][2],f)}function u(f){l("next",f)}function m(f){l("throw",f)}function y(f,h){f(h),i.shift(),i.length&&l(i[0][0],i[0][1])}}function Ac(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],n;return e?e.call(t):(t=typeof gt=="function"?gt(t):t[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(i){n[i]=t[i]&&function(s){return new Promise(function(a,l){s=t[i](s),o(a,l,s.done,s.value)})}}function o(i,s,a,l){Promise.resolve(l).then(function(c){i({value:c,done:a})},s)}}function B(t){return typeof t=="function"}function In(t){var e=function(r){Error.call(r),r.stack=new Error().stack},n=t(e);return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var co=In(function(t){return function(n){t(this),this.message=n?n.length+` errors occurred during unsubscription:
1
+ var Wp=Object.defineProperty;var ms=(t,e)=>{for(var n in e)Wp(t,n,{get:e[n],enumerable:!0})};var qr="ag-ui-chat",gs="ag-ui-submit",vs="ag-ui-toggle",bs="ag-ui-unread",ys="ag-ui-state",xs="ag-ui-attachments",ws="ag-ui-run-finished",Es="ag-ui-custom",_s="ag-ui-invalidate",Ts="ag-ui-feedback",Ss="suggestions",As="ag_ui.invalidate",Zl="ag_ui.subagent",Ql={STARTED:"started",TOOL_CALL:"tool_call",TOOL_RESULT:"tool_result",FINISHED:"finished",FAILED:"failed"},ze={USER:"user",ASSISTANT:"assistant"},Kn="x-destructive",Wr="x-confirm",Pe="x-summary",Zn="x-navigates",ks="read_page",vn=10,bn={COPY:"copy",RETRY:"retry",FEEDBACK:"feedback"},te={PENDING:"pending",DEFERRED:"deferred",DONE:"done",ERROR:"error",DECLINED:"declined"},De={UPLOADING:"uploading",READY:"ready",ERROR:"error"},Cs=10*1024*1024,yn={INLINE:"inline",MINIMAL:"minimal",COMPACT:"compact",FULL:"full"},Is="compaction",Rs="load_capability",Jl='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 19.5V5m-6.5 6.5L12 5l6.5 6.5"/></svg>',ec='<svg class="glyph glyph--solid" viewBox="0 0 24 24" aria-hidden="true"><rect x="7" y="7" width="10" height="10" rx="2.5"/></svg>',tc='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M17 8.5V15a5 5 0 0 1-10 0V7a3 3 0 0 1 6 0v7.5a1 1 0 0 1-2 0V8.5"/></svg>',nc='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 4a3 3 0 0 1 3 3v5a3 3 0 0 1-6 0V7a3 3 0 0 1 3-3z"/><path d="M5 11v1a7 7 0 0 0 14 0v-1"/><path d="M12 19v3"/></svg>',rc='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 5.5A2.5 2.5 0 0 1 6.5 3h11A2.5 2.5 0 0 1 20 5.5v8a2.5 2.5 0 0 1-2.5 2.5H9l-5 4z"/></svg>',oc='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/></svg>',ic='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><rect x="3.5" y="4.5" width="17" height="15" rx="2.5"/><circle cx="9" cy="10" r="1.5"/><path d="M4.5 17.5 9 13.5l3.5 3 3-2.5 4.5 4"/></svg>',sc='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/><rect class="glyph--solid" x="7.5" y="13.5" width="9" height="4.5" rx="1"/></svg>',ac='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/><path d="M8.5 13.5h7M8.5 17h4.5"/></svg>',Xr="chart",lc=150;var xe=[];for(let t=0;t<256;++t)xe.push((t+256).toString(16).slice(1));function cc(t,e=0){return(xe[t[e+0]]+xe[t[e+1]]+xe[t[e+2]]+xe[t[e+3]]+"-"+xe[t[e+4]]+xe[t[e+5]]+"-"+xe[t[e+6]]+xe[t[e+7]]+"-"+xe[t[e+8]]+xe[t[e+9]]+"-"+xe[t[e+10]]+xe[t[e+11]]+xe[t[e+12]]+xe[t[e+13]]+xe[t[e+14]]+xe[t[e+15]]).toLowerCase()}var Ns,Xp=new Uint8Array(16);function Os(){if(!Ns){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ns=crypto.getRandomValues.bind(crypto)}return Ns(Xp)}var Yp=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Ms={randomUUID:Yp};function Kp(t,e,n){if(Ms.randomUUID&&!e&&!t)return Ms.randomUUID();t=t||{};let r=t.random??t.rng?.()??Os();if(r.length<16)throw new Error("Random bytes length must be >= 16");if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,e){if(n=n||0,n<0||n+16>e.length)throw new RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let o=0;o<16;++o)e[n+o]=r[o];return e}return cc(r)}var _t=Kp;var d={};ms(d,{BRAND:()=>Eh,DIRTY:()=>Lt,EMPTY_PATH:()=>eh,INVALID:()=>P,NEVER:()=>af,OK:()=>Ae,ParseStatus:()=>we,Schema:()=>$,ZodAny:()=>At,ZodArray:()=>mt,ZodBigInt:()=>Dt,ZodBoolean:()=>Ut,ZodBranded:()=>Jn,ZodCatch:()=>Xt,ZodDate:()=>Ht,ZodDefault:()=>Wt,ZodDiscriminatedUnion:()=>Zr,ZodEffects:()=>Be,ZodEnum:()=>jt,ZodError:()=>Oe,ZodFirstPartyTypeKind:()=>D,ZodFunction:()=>Jr,ZodIntersection:()=>$t,ZodIssueCode:()=>E,ZodLazy:()=>Bt,ZodLiteral:()=>Vt,ZodMap:()=>Sn,ZodNaN:()=>kn,ZodNativeEnum:()=>qt,ZodNever:()=>Xe,ZodNull:()=>zt,ZodNullable:()=>st,ZodNumber:()=>Pt,ZodObject:()=>Me,ZodOptional:()=>Ge,ZodParsedType:()=>C,ZodPipeline:()=>er,ZodPromise:()=>kt,ZodReadonly:()=>Yt,ZodRecord:()=>Qr,ZodSchema:()=>$,ZodSet:()=>An,ZodString:()=>St,ZodSymbol:()=>_n,ZodTransformer:()=>Be,ZodTuple:()=>it,ZodType:()=>$,ZodUndefined:()=>Ft,ZodUnion:()=>Gt,ZodUnknown:()=>ft,ZodVoid:()=>Tn,addIssueToContext:()=>k,any:()=>Nh,array:()=>Ph,bigint:()=>Ah,boolean:()=>xc,coerce:()=>sf,custom:()=>vc,date:()=>kh,datetimeRegex:()=>mc,defaultErrorMap:()=>pt,discriminatedUnion:()=>Fh,effect:()=>Zh,enum:()=>Xh,function:()=>jh,getErrorMap:()=>xn,getParsedType:()=>ot,instanceof:()=>Th,intersection:()=>zh,isAborted:()=>Yr,isAsync:()=>wn,isDirty:()=>Kr,isValid:()=>Tt,late:()=>_h,lazy:()=>qh,literal:()=>Wh,makeIssue:()=>Qn,map:()=>Bh,nan:()=>Sh,nativeEnum:()=>Yh,never:()=>Mh,null:()=>Rh,nullable:()=>Jh,number:()=>yc,object:()=>Dh,objectUtil:()=>Ls,oboolean:()=>of,onumber:()=>rf,optional:()=>Qh,ostring:()=>nf,pipeline:()=>tf,preprocess:()=>ef,promise:()=>Kh,quotelessJson:()=>Zp,record:()=>$h,set:()=>Vh,setErrorMap:()=>Jp,strictObject:()=>Uh,string:()=>bc,symbol:()=>Ch,transformer:()=>Zh,tuple:()=>Gh,undefined:()=>Ih,union:()=>Hh,unknown:()=>Oh,util:()=>V,void:()=>Lh});var V;(function(t){t.assertEqual=o=>{};function e(o){}t.assertIs=e;function n(o){throw new Error}t.assertNever=n,t.arrayToEnum=o=>{let i={};for(let s of o)i[s]=s;return i},t.getValidEnumValues=o=>{let i=t.objectKeys(o).filter(a=>typeof o[o[a]]!="number"),s={};for(let a of i)s[a]=o[a];return t.objectValues(s)},t.objectValues=o=>t.objectKeys(o).map(function(i){return o[i]}),t.objectKeys=typeof Object.keys=="function"?o=>Object.keys(o):o=>{let i=[];for(let s in o)Object.prototype.hasOwnProperty.call(o,s)&&i.push(s);return i},t.find=(o,i)=>{for(let s of o)if(i(s))return s},t.isInteger=typeof Number.isInteger=="function"?o=>Number.isInteger(o):o=>typeof o=="number"&&Number.isFinite(o)&&Math.floor(o)===o;function r(o,i=" | "){return o.map(s=>typeof s=="string"?`'${s}'`:s).join(i)}t.joinValues=r,t.jsonStringifyReplacer=(o,i)=>typeof i=="bigint"?i.toString():i})(V||(V={}));var Ls;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(Ls||(Ls={}));var C=V.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),ot=t=>{switch(typeof t){case"undefined":return C.undefined;case"string":return C.string;case"number":return Number.isNaN(t)?C.nan:C.number;case"boolean":return C.boolean;case"function":return C.function;case"bigint":return C.bigint;case"symbol":return C.symbol;case"object":return Array.isArray(t)?C.array:t===null?C.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?C.promise:typeof Map<"u"&&t instanceof Map?C.map:typeof Set<"u"&&t instanceof Set?C.set:typeof Date<"u"&&t instanceof Date?C.date:C.object;default:return C.unknown}};var E=V.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Zp=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:"),Oe=class t extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};let n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}format(e){let n=e||function(i){return i.message},r={_errors:[]},o=i=>{for(let s of i.issues)if(s.code==="invalid_union")s.unionErrors.map(o);else if(s.code==="invalid_return_type")o(s.returnTypeError);else if(s.code==="invalid_arguments")o(s.argumentsError);else if(s.path.length===0)r._errors.push(n(s));else{let a=r,l=0;for(;l<s.path.length;){let c=s.path[l];l===s.path.length-1?(a[c]=a[c]||{_errors:[]},a[c]._errors.push(n(s))):a[c]=a[c]||{_errors:[]},a=a[c],l++}}};return o(this),r}static assert(e){if(!(e instanceof t))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,V.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){let n={},r=[];for(let o of this.issues)if(o.path.length>0){let i=o.path[0];n[i]=n[i]||[],n[i].push(e(o))}else r.push(e(o));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}};Oe.create=t=>new Oe(t);var Qp=(t,e)=>{let n;switch(t.code){case E.invalid_type:t.received===C.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case E.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,V.jsonStringifyReplacer)}`;break;case E.unrecognized_keys:n=`Unrecognized key(s) in object: ${V.joinValues(t.keys,", ")}`;break;case E.invalid_union:n="Invalid input";break;case E.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${V.joinValues(t.options)}`;break;case E.invalid_enum_value:n=`Invalid enum value. Expected ${V.joinValues(t.options)}, received '${t.received}'`;break;case E.invalid_arguments:n="Invalid function arguments";break;case E.invalid_return_type:n="Invalid function return type";break;case E.invalid_date:n="Invalid date";break;case E.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(n=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?n=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?n=`Invalid input: must end with "${t.validation.endsWith}"`:V.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case E.too_small:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:n="Invalid input";break;case E.too_big:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?n=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:n="Invalid input";break;case E.custom:n="Invalid input";break;case E.invalid_intersection_types:n="Intersection results could not be merged";break;case E.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case E.not_finite:n="Number must be finite";break;default:n=e.defaultError,V.assertNever(t)}return{message:n}},pt=Qp;var dc=pt;function Jp(t){dc=t}function xn(){return dc}var Qn=t=>{let{data:e,path:n,errorMaps:r,issueData:o}=t,i=[...n,...o.path||[]],s={...o,path:i};if(o.message!==void 0)return{...o,path:i,message:o.message};let a="",l=r.filter(c=>!!c).slice().reverse();for(let c of l)a=c(s,{data:e,defaultError:a}).message;return{...o,path:i,message:a}},eh=[];function k(t,e){let n=xn(),r=Qn({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===pt?void 0:pt].filter(o=>!!o)});t.common.issues.push(r)}var we=class t{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,n){let r=[];for(let o of n){if(o.status==="aborted")return P;o.status==="dirty"&&e.dirty(),r.push(o.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,n){let r=[];for(let o of n){let i=await o.key,s=await o.value;r.push({key:i,value:s})}return t.mergeObjectSync(e,r)}static mergeObjectSync(e,n){let r={};for(let o of n){let{key:i,value:s}=o;if(i.status==="aborted"||s.status==="aborted")return P;i.status==="dirty"&&e.dirty(),s.status==="dirty"&&e.dirty(),i.value!=="__proto__"&&(typeof s.value<"u"||o.alwaysSet)&&(r[i.value]=s.value)}return{status:e.value,value:r}}},P=Object.freeze({status:"aborted"}),Lt=t=>({status:"dirty",value:t}),Ae=t=>({status:"valid",value:t}),Yr=t=>t.status==="aborted",Kr=t=>t.status==="dirty",Tt=t=>t.status==="valid",wn=t=>typeof Promise<"u"&&t instanceof Promise;var R;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(R||(R={}));var $e=class{constructor(e,n,r,o){this._cachedPath=[],this.parent=e,this.data=n,this._path=r,this._key=o}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}},uc=(t,e)=>{if(Tt(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let n=new Oe(t.common.issues);return this._error=n,this._error}}};function z(t){if(!t)return{};let{errorMap:e,invalid_type_error:n,required_error:r,description:o}=t;if(e&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:o}:{errorMap:(s,a)=>{let{message:l}=t;return s.code==="invalid_enum_value"?{message:l??a.defaultError}:typeof a.data>"u"?{message:l??r??a.defaultError}:s.code!=="invalid_type"?{message:a.defaultError}:{message:l??n??a.defaultError}},description:o}}var $=class{get description(){return this._def.description}_getType(e){return ot(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:ot(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new we,ctx:{common:e.parent.common,data:e.data,parsedType:ot(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let n=this._parse(e);if(wn(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(e){let n=this._parse(e);return Promise.resolve(n)}parse(e,n){let r=this.safeParse(e,n);if(r.success)return r.data;throw r.error}safeParse(e,n){let r={common:{issues:[],async:n?.async??!1,contextualErrorMap:n?.errorMap},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:ot(e)},o=this._parseSync({data:e,path:r.path,parent:r});return uc(r,o)}"~validate"(e){let n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:ot(e)};if(!this["~standard"].async)try{let r=this._parseSync({data:e,path:[],parent:n});return Tt(r)?{value:r.value}:{issues:n.common.issues}}catch(r){r?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:n}).then(r=>Tt(r)?{value:r.value}:{issues:n.common.issues})}async parseAsync(e,n){let r=await this.safeParseAsync(e,n);if(r.success)return r.data;throw r.error}async safeParseAsync(e,n){let r={common:{issues:[],contextualErrorMap:n?.errorMap,async:!0},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:ot(e)},o=this._parse({data:e,path:r.path,parent:r}),i=await(wn(o)?o:Promise.resolve(o));return uc(r,i)}refine(e,n){let r=o=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(o):n;return this._refinement((o,i)=>{let s=e(o),a=()=>i.addIssue({code:E.custom,...r(o)});return typeof Promise<"u"&&s instanceof Promise?s.then(l=>l?!0:(a(),!1)):s?!0:(a(),!1)})}refinement(e,n){return this._refinement((r,o)=>e(r)?!0:(o.addIssue(typeof n=="function"?n(r,o):n),!1))}_refinement(e){return new Be({schema:this,typeName:D.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:n=>this["~validate"](n)}}optional(){return Ge.create(this,this._def)}nullable(){return st.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return mt.create(this)}promise(){return kt.create(this,this._def)}or(e){return Gt.create([this,e],this._def)}and(e){return $t.create(this,e,this._def)}transform(e){return new Be({...z(this._def),schema:this,typeName:D.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let n=typeof e=="function"?e:()=>e;return new Wt({...z(this._def),innerType:this,defaultValue:n,typeName:D.ZodDefault})}brand(){return new Jn({typeName:D.ZodBranded,type:this,...z(this._def)})}catch(e){let n=typeof e=="function"?e:()=>e;return new Xt({...z(this._def),innerType:this,catchValue:n,typeName:D.ZodCatch})}describe(e){let n=this.constructor;return new n({...this._def,description:e})}pipe(e){return er.create(this,e)}readonly(){return Yt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},th=/^c[^\s-]{8,}$/i,nh=/^[0-9a-z]+$/,rh=/^[0-9A-HJKMNP-TV-Z]{26}$/i,oh=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,ih=/^[a-z0-9_-]{21}$/i,sh=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ah=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,lh=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,ch="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",Ps,dh=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,uh=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,ph=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,hh=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,fh=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,mh=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,hc="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",gh=new RegExp(`^${hc}$`);function fc(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);let n=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${n}`}function vh(t){return new RegExp(`^${fc(t)}$`)}function mc(t){let e=`${hc}T${fc(t)}`,n=[];return n.push(t.local?"Z?":"Z"),t.offset&&n.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${n.join("|")})`,new RegExp(`^${e}$`)}function bh(t,e){return!!((e==="v4"||!e)&&dh.test(t)||(e==="v6"||!e)&&ph.test(t))}function yh(t,e){if(!sh.test(t))return!1;try{let[n]=t.split(".");if(!n)return!1;let r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),o=JSON.parse(atob(r));return!(typeof o!="object"||o===null||"typ"in o&&o?.typ!=="JWT"||!o.alg||e&&o.alg!==e)}catch{return!1}}function xh(t,e){return!!((e==="v4"||!e)&&uh.test(t)||(e==="v6"||!e)&&hh.test(t))}var St=class t extends ${_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==C.string){let i=this._getOrReturnCtx(e);return k(i,{code:E.invalid_type,expected:C.string,received:i.parsedType}),P}let r=new we,o;for(let i of this._def.checks)if(i.kind==="min")e.data.length<i.value&&(o=this._getOrReturnCtx(e,o),k(o,{code:E.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="max")e.data.length>i.value&&(o=this._getOrReturnCtx(e,o),k(o,{code:E.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="length"){let s=e.data.length>i.value,a=e.data.length<i.value;(s||a)&&(o=this._getOrReturnCtx(e,o),s?k(o,{code:E.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):a&&k(o,{code:E.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),r.dirty())}else if(i.kind==="email")lh.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"email",code:E.invalid_string,message:i.message}),r.dirty());else if(i.kind==="emoji")Ps||(Ps=new RegExp(ch,"u")),Ps.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"emoji",code:E.invalid_string,message:i.message}),r.dirty());else if(i.kind==="uuid")oh.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"uuid",code:E.invalid_string,message:i.message}),r.dirty());else if(i.kind==="nanoid")ih.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"nanoid",code:E.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid")th.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"cuid",code:E.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid2")nh.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"cuid2",code:E.invalid_string,message:i.message}),r.dirty());else if(i.kind==="ulid")rh.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"ulid",code:E.invalid_string,message:i.message}),r.dirty());else if(i.kind==="url")try{new URL(e.data)}catch{o=this._getOrReturnCtx(e,o),k(o,{validation:"url",code:E.invalid_string,message:i.message}),r.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"regex",code:E.invalid_string,message:i.message}),r.dirty())):i.kind==="trim"?e.data=e.data.trim():i.kind==="includes"?e.data.includes(i.value,i.position)||(o=this._getOrReturnCtx(e,o),k(o,{code:E.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),r.dirty()):i.kind==="toLowerCase"?e.data=e.data.toLowerCase():i.kind==="toUpperCase"?e.data=e.data.toUpperCase():i.kind==="startsWith"?e.data.startsWith(i.value)||(o=this._getOrReturnCtx(e,o),k(o,{code:E.invalid_string,validation:{startsWith:i.value},message:i.message}),r.dirty()):i.kind==="endsWith"?e.data.endsWith(i.value)||(o=this._getOrReturnCtx(e,o),k(o,{code:E.invalid_string,validation:{endsWith:i.value},message:i.message}),r.dirty()):i.kind==="datetime"?mc(i).test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{code:E.invalid_string,validation:"datetime",message:i.message}),r.dirty()):i.kind==="date"?gh.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{code:E.invalid_string,validation:"date",message:i.message}),r.dirty()):i.kind==="time"?vh(i).test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{code:E.invalid_string,validation:"time",message:i.message}),r.dirty()):i.kind==="duration"?ah.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"duration",code:E.invalid_string,message:i.message}),r.dirty()):i.kind==="ip"?bh(e.data,i.version)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"ip",code:E.invalid_string,message:i.message}),r.dirty()):i.kind==="jwt"?yh(e.data,i.alg)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"jwt",code:E.invalid_string,message:i.message}),r.dirty()):i.kind==="cidr"?xh(e.data,i.version)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"cidr",code:E.invalid_string,message:i.message}),r.dirty()):i.kind==="base64"?fh.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"base64",code:E.invalid_string,message:i.message}),r.dirty()):i.kind==="base64url"?mh.test(e.data)||(o=this._getOrReturnCtx(e,o),k(o,{validation:"base64url",code:E.invalid_string,message:i.message}),r.dirty()):V.assertNever(i);return{status:r.value,value:e.data}}_regex(e,n,r){return this.refinement(o=>e.test(o),{validation:n,code:E.invalid_string,...R.errToObj(r)})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...R.errToObj(e)})}url(e){return this._addCheck({kind:"url",...R.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...R.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...R.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...R.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...R.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...R.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...R.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...R.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...R.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...R.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...R.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...R.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...R.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...R.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...R.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,...R.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n?.position,...R.errToObj(n?.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,...R.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,...R.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,...R.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,...R.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,...R.errToObj(n)})}nonempty(e){return this.min(1,R.errToObj(e))}trim(){return new t({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxLength(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}};St.create=t=>new St({checks:[],typeName:D.ZodString,coerce:t?.coerce??!1,...z(t)});function wh(t,e){let n=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,o=n>r?n:r,i=Number.parseInt(t.toFixed(o).replace(".","")),s=Number.parseInt(e.toFixed(o).replace(".",""));return i%s/10**o}var Pt=class t extends ${constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==C.number){let i=this._getOrReturnCtx(e);return k(i,{code:E.invalid_type,expected:C.number,received:i.parsedType}),P}let r,o=new we;for(let i of this._def.checks)i.kind==="int"?V.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),k(r,{code:E.invalid_type,expected:"integer",received:"float",message:i.message}),o.dirty()):i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:E.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),o.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:E.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),o.dirty()):i.kind==="multipleOf"?wh(e.data,i.value)!==0&&(r=this._getOrReturnCtx(e,r),k(r,{code:E.not_multiple_of,multipleOf:i.value,message:i.message}),o.dirty()):i.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),k(r,{code:E.not_finite,message:i.message}),o.dirty()):V.assertNever(i);return{status:o.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,R.toString(n))}gt(e,n){return this.setLimit("min",e,!1,R.toString(n))}lte(e,n){return this.setLimit("max",e,!0,R.toString(n))}lt(e,n){return this.setLimit("max",e,!1,R.toString(n))}setLimit(e,n,r,o){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:R.toString(o)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:R.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:R.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:R.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:R.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:R.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:R.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:R.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:R.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:R.toString(e)})}get minValue(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&V.isInteger(e.value))}get isFinite(){let e=null,n=null;for(let r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(n)&&Number.isFinite(e)}};Pt.create=t=>new Pt({checks:[],typeName:D.ZodNumber,coerce:t?.coerce||!1,...z(t)});var Dt=class t extends ${constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==C.bigint)return this._getInvalidInput(e);let r,o=new we;for(let i of this._def.checks)i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:E.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),o.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:E.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),o.dirty()):i.kind==="multipleOf"?e.data%i.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),k(r,{code:E.not_multiple_of,multipleOf:i.value,message:i.message}),o.dirty()):V.assertNever(i);return{status:o.value,value:e.data}}_getInvalidInput(e){let n=this._getOrReturnCtx(e);return k(n,{code:E.invalid_type,expected:C.bigint,received:n.parsedType}),P}gte(e,n){return this.setLimit("min",e,!0,R.toString(n))}gt(e,n){return this.setLimit("min",e,!1,R.toString(n))}lte(e,n){return this.setLimit("max",e,!0,R.toString(n))}lt(e,n){return this.setLimit("max",e,!1,R.toString(n))}setLimit(e,n,r,o){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:R.toString(o)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:R.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:R.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:R.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:R.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:R.toString(n)})}get minValue(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}};Dt.create=t=>new Dt({checks:[],typeName:D.ZodBigInt,coerce:t?.coerce??!1,...z(t)});var Ut=class extends ${_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==C.boolean){let r=this._getOrReturnCtx(e);return k(r,{code:E.invalid_type,expected:C.boolean,received:r.parsedType}),P}return Ae(e.data)}};Ut.create=t=>new Ut({typeName:D.ZodBoolean,coerce:t?.coerce||!1,...z(t)});var Ht=class t extends ${_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==C.date){let i=this._getOrReturnCtx(e);return k(i,{code:E.invalid_type,expected:C.date,received:i.parsedType}),P}if(Number.isNaN(e.data.getTime())){let i=this._getOrReturnCtx(e);return k(i,{code:E.invalid_date}),P}let r=new we,o;for(let i of this._def.checks)i.kind==="min"?e.data.getTime()<i.value&&(o=this._getOrReturnCtx(e,o),k(o,{code:E.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),r.dirty()):i.kind==="max"?e.data.getTime()>i.value&&(o=this._getOrReturnCtx(e,o),k(o,{code:E.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),r.dirty()):V.assertNever(i);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:R.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:R.toString(n)})}get minDate(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e!=null?new Date(e):null}};Ht.create=t=>new Ht({checks:[],coerce:t?.coerce||!1,typeName:D.ZodDate,...z(t)});var _n=class extends ${_parse(e){if(this._getType(e)!==C.symbol){let r=this._getOrReturnCtx(e);return k(r,{code:E.invalid_type,expected:C.symbol,received:r.parsedType}),P}return Ae(e.data)}};_n.create=t=>new _n({typeName:D.ZodSymbol,...z(t)});var Ft=class extends ${_parse(e){if(this._getType(e)!==C.undefined){let r=this._getOrReturnCtx(e);return k(r,{code:E.invalid_type,expected:C.undefined,received:r.parsedType}),P}return Ae(e.data)}};Ft.create=t=>new Ft({typeName:D.ZodUndefined,...z(t)});var zt=class extends ${_parse(e){if(this._getType(e)!==C.null){let r=this._getOrReturnCtx(e);return k(r,{code:E.invalid_type,expected:C.null,received:r.parsedType}),P}return Ae(e.data)}};zt.create=t=>new zt({typeName:D.ZodNull,...z(t)});var At=class extends ${constructor(){super(...arguments),this._any=!0}_parse(e){return Ae(e.data)}};At.create=t=>new At({typeName:D.ZodAny,...z(t)});var ft=class extends ${constructor(){super(...arguments),this._unknown=!0}_parse(e){return Ae(e.data)}};ft.create=t=>new ft({typeName:D.ZodUnknown,...z(t)});var Xe=class extends ${_parse(e){let n=this._getOrReturnCtx(e);return k(n,{code:E.invalid_type,expected:C.never,received:n.parsedType}),P}};Xe.create=t=>new Xe({typeName:D.ZodNever,...z(t)});var Tn=class extends ${_parse(e){if(this._getType(e)!==C.undefined){let r=this._getOrReturnCtx(e);return k(r,{code:E.invalid_type,expected:C.void,received:r.parsedType}),P}return Ae(e.data)}};Tn.create=t=>new Tn({typeName:D.ZodVoid,...z(t)});var mt=class t extends ${_parse(e){let{ctx:n,status:r}=this._processInputParams(e),o=this._def;if(n.parsedType!==C.array)return k(n,{code:E.invalid_type,expected:C.array,received:n.parsedType}),P;if(o.exactLength!==null){let s=n.data.length>o.exactLength.value,a=n.data.length<o.exactLength.value;(s||a)&&(k(n,{code:s?E.too_big:E.too_small,minimum:a?o.exactLength.value:void 0,maximum:s?o.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:o.exactLength.message}),r.dirty())}if(o.minLength!==null&&n.data.length<o.minLength.value&&(k(n,{code:E.too_small,minimum:o.minLength.value,type:"array",inclusive:!0,exact:!1,message:o.minLength.message}),r.dirty()),o.maxLength!==null&&n.data.length>o.maxLength.value&&(k(n,{code:E.too_big,maximum:o.maxLength.value,type:"array",inclusive:!0,exact:!1,message:o.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((s,a)=>o.type._parseAsync(new $e(n,s,n.path,a)))).then(s=>we.mergeArray(r,s));let i=[...n.data].map((s,a)=>o.type._parseSync(new $e(n,s,n.path,a)));return we.mergeArray(r,i)}get element(){return this._def.type}min(e,n){return new t({...this._def,minLength:{value:e,message:R.toString(n)}})}max(e,n){return new t({...this._def,maxLength:{value:e,message:R.toString(n)}})}length(e,n){return new t({...this._def,exactLength:{value:e,message:R.toString(n)}})}nonempty(e){return this.min(1,e)}};mt.create=(t,e)=>new mt({type:t,minLength:null,maxLength:null,exactLength:null,typeName:D.ZodArray,...z(e)});function En(t){if(t instanceof Me){let e={};for(let n in t.shape){let r=t.shape[n];e[n]=Ge.create(En(r))}return new Me({...t._def,shape:()=>e})}else return t instanceof mt?new mt({...t._def,type:En(t.element)}):t instanceof Ge?Ge.create(En(t.unwrap())):t instanceof st?st.create(En(t.unwrap())):t instanceof it?it.create(t.items.map(e=>En(e))):t}var Me=class t extends ${constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),n=V.objectKeys(e);return this._cached={shape:e,keys:n},this._cached}_parse(e){if(this._getType(e)!==C.object){let c=this._getOrReturnCtx(e);return k(c,{code:E.invalid_type,expected:C.object,received:c.parsedType}),P}let{status:r,ctx:o}=this._processInputParams(e),{shape:i,keys:s}=this._getCached(),a=[];if(!(this._def.catchall instanceof Xe&&this._def.unknownKeys==="strip"))for(let c in o.data)s.includes(c)||a.push(c);let l=[];for(let c of s){let u=i[c],m=o.data[c];l.push({key:{status:"valid",value:c},value:u._parse(new $e(o,m,o.path,c)),alwaysSet:c in o.data})}if(this._def.catchall instanceof Xe){let c=this._def.unknownKeys;if(c==="passthrough")for(let u of a)l.push({key:{status:"valid",value:u},value:{status:"valid",value:o.data[u]}});else if(c==="strict")a.length>0&&(k(o,{code:E.unrecognized_keys,keys:a}),r.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{let c=this._def.catchall;for(let u of a){let m=o.data[u];l.push({key:{status:"valid",value:u},value:c._parse(new $e(o,m,o.path,u)),alwaysSet:u in o.data})}}return o.common.async?Promise.resolve().then(async()=>{let c=[];for(let u of l){let m=await u.key,y=await u.value;c.push({key:m,value:y,alwaysSet:u.alwaysSet})}return c}).then(c=>we.mergeObjectSync(r,c)):we.mergeObjectSync(r,l)}get shape(){return this._def.shape()}strict(e){return R.errToObj,new t({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,r)=>{let o=this._def.errorMap?.(n,r).message??r.defaultError;return n.code==="unrecognized_keys"?{message:R.errToObj(e).message??o}:{message:o}}}:{}})}strip(){return new t({...this._def,unknownKeys:"strip"})}passthrough(){return new t({...this._def,unknownKeys:"passthrough"})}extend(e){return new t({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new t({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:D.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new t({...this._def,catchall:e})}pick(e){let n={};for(let r of V.objectKeys(e))e[r]&&this.shape[r]&&(n[r]=this.shape[r]);return new t({...this._def,shape:()=>n})}omit(e){let n={};for(let r of V.objectKeys(this.shape))e[r]||(n[r]=this.shape[r]);return new t({...this._def,shape:()=>n})}deepPartial(){return En(this)}partial(e){let n={};for(let r of V.objectKeys(this.shape)){let o=this.shape[r];e&&!e[r]?n[r]=o:n[r]=o.optional()}return new t({...this._def,shape:()=>n})}required(e){let n={};for(let r of V.objectKeys(this.shape))if(e&&!e[r])n[r]=this.shape[r];else{let i=this.shape[r];for(;i instanceof Ge;)i=i._def.innerType;n[r]=i}return new t({...this._def,shape:()=>n})}keyof(){return gc(V.objectKeys(this.shape))}};Me.create=(t,e)=>new Me({shape:()=>t,unknownKeys:"strip",catchall:Xe.create(),typeName:D.ZodObject,...z(e)});Me.strictCreate=(t,e)=>new Me({shape:()=>t,unknownKeys:"strict",catchall:Xe.create(),typeName:D.ZodObject,...z(e)});Me.lazycreate=(t,e)=>new Me({shape:t,unknownKeys:"strip",catchall:Xe.create(),typeName:D.ZodObject,...z(e)});var Gt=class extends ${_parse(e){let{ctx:n}=this._processInputParams(e),r=this._def.options;function o(i){for(let a of i)if(a.result.status==="valid")return a.result;for(let a of i)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;let s=i.map(a=>new Oe(a.ctx.common.issues));return k(n,{code:E.invalid_union,unionErrors:s}),P}if(n.common.async)return Promise.all(r.map(async i=>{let s={...n,common:{...n.common,issues:[]},parent:null};return{result:await i._parseAsync({data:n.data,path:n.path,parent:s}),ctx:s}})).then(o);{let i,s=[];for(let l of r){let c={...n,common:{...n.common,issues:[]},parent:null},u=l._parseSync({data:n.data,path:n.path,parent:c});if(u.status==="valid")return u;u.status==="dirty"&&!i&&(i={result:u,ctx:c}),c.common.issues.length&&s.push(c.common.issues)}if(i)return n.common.issues.push(...i.ctx.common.issues),i.result;let a=s.map(l=>new Oe(l));return k(n,{code:E.invalid_union,unionErrors:a}),P}}get options(){return this._def.options}};Gt.create=(t,e)=>new Gt({options:t,typeName:D.ZodUnion,...z(e)});var ht=t=>t instanceof Bt?ht(t.schema):t instanceof Be?ht(t.innerType()):t instanceof Vt?[t.value]:t instanceof jt?t.options:t instanceof qt?V.objectValues(t.enum):t instanceof Wt?ht(t._def.innerType):t instanceof Ft?[void 0]:t instanceof zt?[null]:t instanceof Ge?[void 0,...ht(t.unwrap())]:t instanceof st?[null,...ht(t.unwrap())]:t instanceof Jn||t instanceof Yt?ht(t.unwrap()):t instanceof Xt?ht(t._def.innerType):[],Zr=class t extends ${_parse(e){let{ctx:n}=this._processInputParams(e);if(n.parsedType!==C.object)return k(n,{code:E.invalid_type,expected:C.object,received:n.parsedType}),P;let r=this.discriminator,o=n.data[r],i=this.optionsMap.get(o);return i?n.common.async?i._parseAsync({data:n.data,path:n.path,parent:n}):i._parseSync({data:n.data,path:n.path,parent:n}):(k(n,{code:E.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),P)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,n,r){let o=new Map;for(let i of n){let s=ht(i.shape[e]);if(!s.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let a of s){if(o.has(a))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(a)}`);o.set(a,i)}}return new t({typeName:D.ZodDiscriminatedUnion,discriminator:e,options:n,optionsMap:o,...z(r)})}};function Ds(t,e){let n=ot(t),r=ot(e);if(t===e)return{valid:!0,data:t};if(n===C.object&&r===C.object){let o=V.objectKeys(e),i=V.objectKeys(t).filter(a=>o.indexOf(a)!==-1),s={...t,...e};for(let a of i){let l=Ds(t[a],e[a]);if(!l.valid)return{valid:!1};s[a]=l.data}return{valid:!0,data:s}}else if(n===C.array&&r===C.array){if(t.length!==e.length)return{valid:!1};let o=[];for(let i=0;i<t.length;i++){let s=t[i],a=e[i],l=Ds(s,a);if(!l.valid)return{valid:!1};o.push(l.data)}return{valid:!0,data:o}}else return n===C.date&&r===C.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}var $t=class extends ${_parse(e){let{status:n,ctx:r}=this._processInputParams(e),o=(i,s)=>{if(Yr(i)||Yr(s))return P;let a=Ds(i.value,s.value);return a.valid?((Kr(i)||Kr(s))&&n.dirty(),{status:n.value,value:a.data}):(k(r,{code:E.invalid_intersection_types}),P)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([i,s])=>o(i,s)):o(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}};$t.create=(t,e,n)=>new $t({left:t,right:e,typeName:D.ZodIntersection,...z(n)});var it=class t extends ${_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==C.array)return k(r,{code:E.invalid_type,expected:C.array,received:r.parsedType}),P;if(r.data.length<this._def.items.length)return k(r,{code:E.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),P;!this._def.rest&&r.data.length>this._def.items.length&&(k(r,{code:E.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());let i=[...r.data].map((s,a)=>{let l=this._def.items[a]||this._def.rest;return l?l._parse(new $e(r,s,r.path,a)):null}).filter(s=>!!s);return r.common.async?Promise.all(i).then(s=>we.mergeArray(n,s)):we.mergeArray(n,i)}get items(){return this._def.items}rest(e){return new t({...this._def,rest:e})}};it.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new it({items:t,typeName:D.ZodTuple,rest:null,...z(e)})};var Qr=class t extends ${get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==C.object)return k(r,{code:E.invalid_type,expected:C.object,received:r.parsedType}),P;let o=[],i=this._def.keyType,s=this._def.valueType;for(let a in r.data)o.push({key:i._parse(new $e(r,a,r.path,a)),value:s._parse(new $e(r,r.data[a],r.path,a)),alwaysSet:a in r.data});return r.common.async?we.mergeObjectAsync(n,o):we.mergeObjectSync(n,o)}get element(){return this._def.valueType}static create(e,n,r){return n instanceof $?new t({keyType:e,valueType:n,typeName:D.ZodRecord,...z(r)}):new t({keyType:St.create(),valueType:e,typeName:D.ZodRecord,...z(n)})}},Sn=class extends ${get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==C.map)return k(r,{code:E.invalid_type,expected:C.map,received:r.parsedType}),P;let o=this._def.keyType,i=this._def.valueType,s=[...r.data.entries()].map(([a,l],c)=>({key:o._parse(new $e(r,a,r.path,[c,"key"])),value:i._parse(new $e(r,l,r.path,[c,"value"]))}));if(r.common.async){let a=new Map;return Promise.resolve().then(async()=>{for(let l of s){let c=await l.key,u=await l.value;if(c.status==="aborted"||u.status==="aborted")return P;(c.status==="dirty"||u.status==="dirty")&&n.dirty(),a.set(c.value,u.value)}return{status:n.value,value:a}})}else{let a=new Map;for(let l of s){let c=l.key,u=l.value;if(c.status==="aborted"||u.status==="aborted")return P;(c.status==="dirty"||u.status==="dirty")&&n.dirty(),a.set(c.value,u.value)}return{status:n.value,value:a}}}};Sn.create=(t,e,n)=>new Sn({valueType:e,keyType:t,typeName:D.ZodMap,...z(n)});var An=class t extends ${_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==C.set)return k(r,{code:E.invalid_type,expected:C.set,received:r.parsedType}),P;let o=this._def;o.minSize!==null&&r.data.size<o.minSize.value&&(k(r,{code:E.too_small,minimum:o.minSize.value,type:"set",inclusive:!0,exact:!1,message:o.minSize.message}),n.dirty()),o.maxSize!==null&&r.data.size>o.maxSize.value&&(k(r,{code:E.too_big,maximum:o.maxSize.value,type:"set",inclusive:!0,exact:!1,message:o.maxSize.message}),n.dirty());let i=this._def.valueType;function s(l){let c=new Set;for(let u of l){if(u.status==="aborted")return P;u.status==="dirty"&&n.dirty(),c.add(u.value)}return{status:n.value,value:c}}let a=[...r.data.values()].map((l,c)=>i._parse(new $e(r,l,r.path,c)));return r.common.async?Promise.all(a).then(l=>s(l)):s(a)}min(e,n){return new t({...this._def,minSize:{value:e,message:R.toString(n)}})}max(e,n){return new t({...this._def,maxSize:{value:e,message:R.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}};An.create=(t,e)=>new An({valueType:t,minSize:null,maxSize:null,typeName:D.ZodSet,...z(e)});var Jr=class t extends ${constructor(){super(...arguments),this.validate=this.implement}_parse(e){let{ctx:n}=this._processInputParams(e);if(n.parsedType!==C.function)return k(n,{code:E.invalid_type,expected:C.function,received:n.parsedType}),P;function r(a,l){return Qn({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,xn(),pt].filter(c=>!!c),issueData:{code:E.invalid_arguments,argumentsError:l}})}function o(a,l){return Qn({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,xn(),pt].filter(c=>!!c),issueData:{code:E.invalid_return_type,returnTypeError:l}})}let i={errorMap:n.common.contextualErrorMap},s=n.data;if(this._def.returns instanceof kt){let a=this;return Ae(async function(...l){let c=new Oe([]),u=await a._def.args.parseAsync(l,i).catch(f=>{throw c.addIssue(r(l,f)),c}),m=await Reflect.apply(s,this,u);return await a._def.returns._def.type.parseAsync(m,i).catch(f=>{throw c.addIssue(o(m,f)),c})})}else{let a=this;return Ae(function(...l){let c=a._def.args.safeParse(l,i);if(!c.success)throw new Oe([r(l,c.error)]);let u=Reflect.apply(s,this,c.data),m=a._def.returns.safeParse(u,i);if(!m.success)throw new Oe([o(u,m.error)]);return m.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new t({...this._def,args:it.create(e).rest(ft.create())})}returns(e){return new t({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,n,r){return new t({args:e||it.create([]).rest(ft.create()),returns:n||ft.create(),typeName:D.ZodFunction,...z(r)})}},Bt=class extends ${get schema(){return this._def.getter()}_parse(e){let{ctx:n}=this._processInputParams(e);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}};Bt.create=(t,e)=>new Bt({getter:t,typeName:D.ZodLazy,...z(e)});var Vt=class extends ${_parse(e){if(e.data!==this._def.value){let n=this._getOrReturnCtx(e);return k(n,{received:n.data,code:E.invalid_literal,expected:this._def.value}),P}return{status:"valid",value:e.data}}get value(){return this._def.value}};Vt.create=(t,e)=>new Vt({value:t,typeName:D.ZodLiteral,...z(e)});function gc(t,e){return new jt({values:t,typeName:D.ZodEnum,...z(e)})}var jt=class t extends ${_parse(e){if(typeof e.data!="string"){let n=this._getOrReturnCtx(e),r=this._def.values;return k(n,{expected:V.joinValues(r),received:n.parsedType,code:E.invalid_type}),P}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let n=this._getOrReturnCtx(e),r=this._def.values;return k(n,{received:n.data,code:E.invalid_enum_value,options:r}),P}return Ae(e.data)}get options(){return this._def.values}get enum(){let e={};for(let n of this._def.values)e[n]=n;return e}get Values(){let e={};for(let n of this._def.values)e[n]=n;return e}get Enum(){let e={};for(let n of this._def.values)e[n]=n;return e}extract(e,n=this._def){return t.create(e,{...this._def,...n})}exclude(e,n=this._def){return t.create(this.options.filter(r=>!e.includes(r)),{...this._def,...n})}};jt.create=gc;var qt=class extends ${_parse(e){let n=V.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==C.string&&r.parsedType!==C.number){let o=V.objectValues(n);return k(r,{expected:V.joinValues(o),received:r.parsedType,code:E.invalid_type}),P}if(this._cache||(this._cache=new Set(V.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let o=V.objectValues(n);return k(r,{received:r.data,code:E.invalid_enum_value,options:o}),P}return Ae(e.data)}get enum(){return this._def.values}};qt.create=(t,e)=>new qt({values:t,typeName:D.ZodNativeEnum,...z(e)});var kt=class extends ${unwrap(){return this._def.type}_parse(e){let{ctx:n}=this._processInputParams(e);if(n.parsedType!==C.promise&&n.common.async===!1)return k(n,{code:E.invalid_type,expected:C.promise,received:n.parsedType}),P;let r=n.parsedType===C.promise?n.data:Promise.resolve(n.data);return Ae(r.then(o=>this._def.type.parseAsync(o,{path:n.path,errorMap:n.common.contextualErrorMap})))}};kt.create=(t,e)=>new kt({type:t,typeName:D.ZodPromise,...z(e)});var Be=class extends ${innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===D.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:n,ctx:r}=this._processInputParams(e),o=this._def.effect||null,i={addIssue:s=>{k(r,s),s.fatal?n.abort():n.dirty()},get path(){return r.path}};if(i.addIssue=i.addIssue.bind(i),o.type==="preprocess"){let s=o.transform(r.data,i);if(r.common.async)return Promise.resolve(s).then(async a=>{if(n.value==="aborted")return P;let l=await this._def.schema._parseAsync({data:a,path:r.path,parent:r});return l.status==="aborted"?P:l.status==="dirty"?Lt(l.value):n.value==="dirty"?Lt(l.value):l});{if(n.value==="aborted")return P;let a=this._def.schema._parseSync({data:s,path:r.path,parent:r});return a.status==="aborted"?P:a.status==="dirty"?Lt(a.value):n.value==="dirty"?Lt(a.value):a}}if(o.type==="refinement"){let s=a=>{let l=o.refinement(a,i);if(r.common.async)return Promise.resolve(l);if(l instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(r.common.async===!1){let a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?P:(a.status==="dirty"&&n.dirty(),s(a.value),{status:n.value,value:a.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>a.status==="aborted"?P:(a.status==="dirty"&&n.dirty(),s(a.value).then(()=>({status:n.value,value:a.value}))))}if(o.type==="transform")if(r.common.async===!1){let s=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Tt(s))return P;let a=o.transform(s.value,i);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:a}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(s=>Tt(s)?Promise.resolve(o.transform(s.value,i)).then(a=>({status:n.value,value:a})):P);V.assertNever(o)}};Be.create=(t,e,n)=>new Be({schema:t,typeName:D.ZodEffects,effect:e,...z(n)});Be.createWithPreprocess=(t,e,n)=>new Be({schema:e,effect:{type:"preprocess",transform:t},typeName:D.ZodEffects,...z(n)});var Ge=class extends ${_parse(e){return this._getType(e)===C.undefined?Ae(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};Ge.create=(t,e)=>new Ge({innerType:t,typeName:D.ZodOptional,...z(e)});var st=class extends ${_parse(e){return this._getType(e)===C.null?Ae(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};st.create=(t,e)=>new st({innerType:t,typeName:D.ZodNullable,...z(e)});var Wt=class extends ${_parse(e){let{ctx:n}=this._processInputParams(e),r=n.data;return n.parsedType===C.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}};Wt.create=(t,e)=>new Wt({innerType:t,typeName:D.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...z(e)});var Xt=class extends ${_parse(e){let{ctx:n}=this._processInputParams(e),r={...n,common:{...n.common,issues:[]}},o=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return wn(o)?o.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new Oe(r.common.issues)},input:r.data})})):{status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new Oe(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}};Xt.create=(t,e)=>new Xt({innerType:t,typeName:D.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...z(e)});var kn=class extends ${_parse(e){if(this._getType(e)!==C.nan){let r=this._getOrReturnCtx(e);return k(r,{code:E.invalid_type,expected:C.nan,received:r.parsedType}),P}return{status:"valid",value:e.data}}};kn.create=t=>new kn({typeName:D.ZodNaN,...z(t)});var Eh=Symbol("zod_brand"),Jn=class extends ${_parse(e){let{ctx:n}=this._processInputParams(e),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}},er=class t extends ${_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{let i=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?P:i.status==="dirty"?(n.dirty(),Lt(i.value)):this._def.out._parseAsync({data:i.value,path:r.path,parent:r})})();{let o=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?P:o.status==="dirty"?(n.dirty(),{status:"dirty",value:o.value}):this._def.out._parseSync({data:o.value,path:r.path,parent:r})}}static create(e,n){return new t({in:e,out:n,typeName:D.ZodPipeline})}},Yt=class extends ${_parse(e){let n=this._def.innerType._parse(e),r=o=>(Tt(o)&&(o.value=Object.freeze(o.value)),o);return wn(n)?n.then(o=>r(o)):r(n)}unwrap(){return this._def.innerType}};Yt.create=(t,e)=>new Yt({innerType:t,typeName:D.ZodReadonly,...z(e)});function pc(t,e){let n=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof n=="string"?{message:n}:n}function vc(t,e={},n){return t?At.create().superRefine((r,o)=>{let i=t(r);if(i instanceof Promise)return i.then(s=>{if(!s){let a=pc(e,r),l=a.fatal??n??!0;o.addIssue({code:"custom",...a,fatal:l})}});if(!i){let s=pc(e,r),a=s.fatal??n??!0;o.addIssue({code:"custom",...s,fatal:a})}}):At.create()}var _h={object:Me.lazycreate},D;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(D||(D={}));var Th=(t,e={message:`Input not instance of ${t.name}`})=>vc(n=>n instanceof t,e),bc=St.create,yc=Pt.create,Sh=kn.create,Ah=Dt.create,xc=Ut.create,kh=Ht.create,Ch=_n.create,Ih=Ft.create,Rh=zt.create,Nh=At.create,Oh=ft.create,Mh=Xe.create,Lh=Tn.create,Ph=mt.create,Dh=Me.create,Uh=Me.strictCreate,Hh=Gt.create,Fh=Zr.create,zh=$t.create,Gh=it.create,$h=Qr.create,Bh=Sn.create,Vh=An.create,jh=Jr.create,qh=Bt.create,Wh=Vt.create,Xh=jt.create,Yh=qt.create,Kh=kt.create,Zh=Be.create,Qh=Ge.create,Jh=st.create,ef=Be.createWithPreprocess,tf=er.create,nf=()=>bc().optional(),rf=()=>yc().optional(),of=()=>xc().optional(),sf={string:(t=>St.create({...t,coerce:!0})),number:(t=>Pt.create({...t,coerce:!0})),boolean:(t=>Ut.create({...t,coerce:!0})),bigint:(t=>Dt.create({...t,coerce:!0})),date:(t=>Ht.create({...t,coerce:!0}))};var af=P;var lf=d.object({name:d.string(),arguments:d.string()}),cf=d.object({id:d.string(),type:d.literal("function"),function:lf,encryptedValue:d.string().optional()}),eo=d.object({id:d.string(),role:d.string(),content:d.string().optional(),name:d.string().optional(),encryptedValue:d.string().optional()}),df=d.object({type:d.literal("text"),text:d.string()}),uf=d.object({type:d.literal("data"),value:d.string(),mimeType:d.string()}),pf=d.object({type:d.literal("url"),value:d.string(),mimeType:d.string().optional()}),to=d.discriminatedUnion("type",[uf,pf]),hf=d.object({type:d.literal("image"),source:to,metadata:d.unknown().optional()}),ff=d.object({type:d.literal("audio"),source:to,metadata:d.unknown().optional()}),mf=d.object({type:d.literal("video"),source:to,metadata:d.unknown().optional()}),gf=d.object({type:d.literal("document"),source:to,metadata:d.unknown().optional()});var wc=d.object({type:d.literal("binary"),mimeType:d.string(),id:d.string().optional(),url:d.string().optional(),data:d.string().optional(),filename:d.string().optional()}),Ec=(t,e)=>{!t.id&&!t.url&&!t.data&&e.addIssue({code:d.ZodIssueCode.custom,message:"BinaryInputContent requires at least one of id, url, or data.",path:["id"]})},Kx=wc.superRefine((t,e)=>{Ec(t,e)}),vf=d.discriminatedUnion("type",[df,hf,ff,mf,gf,wc]),bf=vf.superRefine((t,e)=>{t.type==="binary"&&Ec(t,e)}),yf=eo.extend({role:d.literal("developer"),content:d.string()}),xf=eo.extend({role:d.literal("system"),content:d.string()}),wf=eo.extend({role:d.literal("assistant"),content:d.string().optional(),toolCalls:d.array(cf).optional()}),Ef=eo.extend({role:d.literal("user"),content:d.union([d.string(),d.array(bf)])}),_f=d.object({id:d.string(),content:d.string(),role:d.literal("tool"),toolCallId:d.string(),error:d.string().optional(),encryptedValue:d.string().optional()}),Tf=d.object({id:d.string(),role:d.literal("activity"),activityType:d.string(),content:d.record(d.any())}),Sf=d.object({id:d.string(),role:d.literal("reasoning"),content:d.string(),encryptedValue:d.string().optional()}),_c=d.discriminatedUnion("role",[yf,xf,wf,Ef,_f,Tf,Sf]),Zx=d.union([d.literal("developer"),d.literal("system"),d.literal("assistant"),d.literal("user"),d.literal("tool"),d.literal("activity"),d.literal("reasoning")]),Af=d.object({description:d.string(),value:d.string()}),Tc=d.object({name:d.string(),description:d.string(),parameters:d.any(),metadata:d.record(d.any()).optional()}),kf=d.object({id:d.string(),reason:d.string(),message:d.string().optional(),toolCallId:d.string().optional(),responseSchema:d.record(d.any()).optional(),expiresAt:d.string().optional(),metadata:d.record(d.any()).optional()}),Cf=d.object({interruptId:d.string(),status:d.enum(["resolved","cancelled"]),payload:d.any().optional()}),If=d.object({threadId:d.string(),runId:d.string(),parentRunId:d.string().optional(),state:d.any(),messages:d.array(_c),tools:d.array(Tc),context:d.array(Af),forwardedProps:d.any(),resume:d.array(Cf).optional()}),Rf=d.any(),ne=class extends Error{constructor(t){super(t)}},Us=class extends ne{constructor(){super("Connect not implemented. This method is not supported by the current agent.")}},Nf=d.object({name:d.string(),description:d.string().optional()}),Of=d.object({name:d.string().optional(),type:d.string().optional(),description:d.string().optional(),version:d.string().optional(),provider:d.string().optional(),documentationUrl:d.string().optional(),metadata:d.record(d.unknown()).optional()}),Mf=d.object({streaming:d.boolean().optional(),websocket:d.boolean().optional(),httpBinary:d.boolean().optional(),pushNotifications:d.boolean().optional(),resumable:d.boolean().optional()}),Lf=d.object({supported:d.boolean().optional(),items:d.array(Tc).optional(),parallelCalls:d.boolean().optional(),clientProvided:d.boolean().optional()}),Pf=d.object({structuredOutput:d.boolean().optional(),supportedMimeTypes:d.array(d.string()).optional()}),Df=d.object({snapshots:d.boolean().optional(),deltas:d.boolean().optional(),memory:d.boolean().optional(),persistentState:d.boolean().optional()}),Uf=d.object({supported:d.boolean().optional(),delegation:d.boolean().optional(),handoffs:d.boolean().optional(),subAgents:d.array(Nf).optional()}),Hf=d.object({supported:d.boolean().optional(),streaming:d.boolean().optional(),encrypted:d.boolean().optional()}),Ff=d.object({image:d.boolean().optional(),audio:d.boolean().optional(),video:d.boolean().optional(),pdf:d.boolean().optional(),file:d.boolean().optional()}),zf=d.object({image:d.boolean().optional(),audio:d.boolean().optional()}),Gf=d.object({input:Ff.optional(),output:zf.optional()}),$f=d.object({codeExecution:d.boolean().optional(),sandboxed:d.boolean().optional(),maxIterations:d.number().optional(),maxExecutionTime:d.number().optional()}),Bf=d.object({supported:d.boolean().optional(),approvals:d.boolean().optional(),interventions:d.boolean().optional(),feedback:d.boolean().optional(),interrupts:d.boolean().optional(),approveWithEdits:d.boolean().optional()}),Qx=d.object({identity:Of.optional(),transport:Mf.optional(),tools:Lf.optional(),output:Pf.optional(),state:Df.optional(),multiAgent:Uf.optional(),reasoning:Hf.optional(),multimodal:Gf.optional(),execution:$f.optional(),humanInTheLoop:Bf.optional(),custom:d.record(d.unknown()).optional()}),Sc=d.union([d.literal("developer"),d.literal("system"),d.literal("assistant"),d.literal("user")]),v=(function(t){return t.TEXT_MESSAGE_START="TEXT_MESSAGE_START",t.TEXT_MESSAGE_CONTENT="TEXT_MESSAGE_CONTENT",t.TEXT_MESSAGE_END="TEXT_MESSAGE_END",t.TEXT_MESSAGE_CHUNK="TEXT_MESSAGE_CHUNK",t.TOOL_CALL_START="TOOL_CALL_START",t.TOOL_CALL_ARGS="TOOL_CALL_ARGS",t.TOOL_CALL_END="TOOL_CALL_END",t.TOOL_CALL_CHUNK="TOOL_CALL_CHUNK",t.TOOL_CALL_RESULT="TOOL_CALL_RESULT",t.THINKING_START="THINKING_START",t.THINKING_END="THINKING_END",t.THINKING_TEXT_MESSAGE_START="THINKING_TEXT_MESSAGE_START",t.THINKING_TEXT_MESSAGE_CONTENT="THINKING_TEXT_MESSAGE_CONTENT",t.THINKING_TEXT_MESSAGE_END="THINKING_TEXT_MESSAGE_END",t.STATE_SNAPSHOT="STATE_SNAPSHOT",t.STATE_DELTA="STATE_DELTA",t.MESSAGES_SNAPSHOT="MESSAGES_SNAPSHOT",t.ACTIVITY_SNAPSHOT="ACTIVITY_SNAPSHOT",t.ACTIVITY_DELTA="ACTIVITY_DELTA",t.RAW="RAW",t.CUSTOM="CUSTOM",t.RUN_STARTED="RUN_STARTED",t.RUN_FINISHED="RUN_FINISHED",t.RUN_ERROR="RUN_ERROR",t.STEP_STARTED="STEP_STARTED",t.STEP_FINISHED="STEP_FINISHED",t.REASONING_START="REASONING_START",t.REASONING_MESSAGE_START="REASONING_MESSAGE_START",t.REASONING_MESSAGE_CONTENT="REASONING_MESSAGE_CONTENT",t.REASONING_MESSAGE_END="REASONING_MESSAGE_END",t.REASONING_MESSAGE_CHUNK="REASONING_MESSAGE_CHUNK",t.REASONING_END="REASONING_END",t.REASONING_ENCRYPTED_VALUE="REASONING_ENCRYPTED_VALUE",t})({}),X=d.object({type:d.nativeEnum(v),timestamp:d.number().optional(),rawEvent:d.any().optional()}).passthrough(),Vf=X.extend({type:d.literal(v.TEXT_MESSAGE_START),messageId:d.string(),role:Sc.default("assistant"),name:d.string().optional()}),Ac=X.extend({type:d.literal(v.TEXT_MESSAGE_CONTENT),messageId:d.string(),delta:d.string()}),jf=X.extend({type:d.literal(v.TEXT_MESSAGE_END),messageId:d.string()}),qf=X.extend({type:d.literal(v.TEXT_MESSAGE_CHUNK),messageId:d.string().optional(),role:Sc.optional(),delta:d.string().optional(),name:d.string().optional()}),Wf=X.extend({type:d.literal(v.THINKING_TEXT_MESSAGE_START)}),Xf=Ac.omit({messageId:!0,type:!0}).extend({type:d.literal(v.THINKING_TEXT_MESSAGE_CONTENT)}),Yf=X.extend({type:d.literal(v.THINKING_TEXT_MESSAGE_END)}),Kf=X.extend({type:d.literal(v.TOOL_CALL_START),toolCallId:d.string(),toolCallName:d.string(),parentMessageId:d.string().optional()}),Zf=X.extend({type:d.literal(v.TOOL_CALL_ARGS),toolCallId:d.string(),delta:d.string()}),Qf=X.extend({type:d.literal(v.TOOL_CALL_END),toolCallId:d.string()}),Jf=X.extend({messageId:d.string(),type:d.literal(v.TOOL_CALL_RESULT),toolCallId:d.string(),content:d.string(),role:d.literal("tool").optional()}),em=X.extend({type:d.literal(v.TOOL_CALL_CHUNK),toolCallId:d.string().optional(),toolCallName:d.string().optional(),parentMessageId:d.string().optional(),delta:d.string().optional()}),tm=X.extend({type:d.literal(v.THINKING_START),title:d.string().optional()}),nm=X.extend({type:d.literal(v.THINKING_END)}),rm=X.extend({type:d.literal(v.STATE_SNAPSHOT),snapshot:Rf}),om=X.extend({type:d.literal(v.STATE_DELTA),delta:d.array(d.any())}),im=X.extend({type:d.literal(v.MESSAGES_SNAPSHOT),messages:d.array(_c)}),sm=X.extend({type:d.literal(v.ACTIVITY_SNAPSHOT),messageId:d.string(),activityType:d.string(),content:d.record(d.any()),replace:d.boolean().optional().default(!0)}),am=X.extend({type:d.literal(v.ACTIVITY_DELTA),messageId:d.string(),activityType:d.string(),patch:d.array(d.any())}),lm=X.extend({type:d.literal(v.RAW),event:d.any(),source:d.string().optional()}),cm=X.extend({type:d.literal(v.CUSTOM),name:d.string(),value:d.any()}),dm=X.extend({type:d.literal(v.RUN_STARTED),threadId:d.string(),runId:d.string(),parentRunId:d.string().optional(),input:If.optional()}),um=d.object({type:d.literal("success")}).strict(),pm=d.object({type:d.literal("interrupt"),interrupts:d.array(kf).min(1)}).strict(),hm=d.discriminatedUnion("type",[um,pm]),fm=X.extend({type:d.literal(v.RUN_FINISHED),threadId:d.string(),runId:d.string(),result:d.any().optional(),outcome:hm.nullable().optional().transform(t=>t??void 0)}),mm=X.extend({type:d.literal(v.RUN_ERROR),message:d.string(),code:d.string().optional()}),gm=X.extend({type:d.literal(v.STEP_STARTED),stepName:d.string()}),vm=X.extend({type:d.literal(v.STEP_FINISHED),stepName:d.string()}),bm=d.union([d.literal("tool-call"),d.literal("message")]),ym=X.extend({type:d.literal(v.REASONING_START),messageId:d.string()}),xm=X.extend({type:d.literal(v.REASONING_MESSAGE_START),messageId:d.string(),role:d.literal("reasoning")}),wm=X.extend({type:d.literal(v.REASONING_MESSAGE_CONTENT),messageId:d.string(),delta:d.string()}),Em=X.extend({type:d.literal(v.REASONING_MESSAGE_END),messageId:d.string()}),_m=X.extend({type:d.literal(v.REASONING_MESSAGE_CHUNK),messageId:d.string().optional(),delta:d.string().optional()}),Tm=X.extend({type:d.literal(v.REASONING_END),messageId:d.string()}),Sm=X.extend({type:d.literal(v.REASONING_ENCRYPTED_VALUE),subtype:bm,entityId:d.string(),encryptedValue:d.string()}),no=d.discriminatedUnion("type",[Vf,Ac,jf,qf,tm,nm,Wf,Xf,Yf,Kf,Zf,Qf,em,Jf,rm,om,im,sm,am,lm,cm,dm,fm,mm,gm,vm,ym,xm,wm,Em,_m,Tm,Sm]);var Hs={};ms(Hs,{JsonPatchError:()=>he,_areEquals:()=>rr,applyOperation:()=>Kt,applyPatch:()=>co,applyReducer:()=>Rm,deepClone:()=>Cm,getValueByPointer:()=>ao,validate:()=>Cc,validator:()=>lo});var Am=(function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,o){r.__proto__=o}||function(r,o){for(var i in o)o.hasOwnProperty(i)&&(r[i]=o[i])},t(e,n)};return function(e,n){t(e,n);function r(){this.constructor=e}e.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}})(),km=Object.prototype.hasOwnProperty;function oo(t,e){return km.call(t,e)}function io(t){if(Array.isArray(t)){for(var e=new Array(t.length),n=0;n<e.length;n++)e[n]=""+n;return e}if(Object.keys)return Object.keys(t);var r=[];for(var o in t)oo(t,o)&&r.push(o);return r}function Ee(t){switch(typeof t){case"object":return JSON.parse(JSON.stringify(t));case"undefined":return null;default:return t}}function so(t){for(var e=0,n=t.length,r;e<n;){if(r=t.charCodeAt(e),r>=48&&r<=57){e++;continue}return!1}return!0}function at(t){return t.indexOf("/")===-1&&t.indexOf("~")===-1?t:t.replace(/~/g,"~0").replace(/\//g,"~1")}function tr(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function ro(t){if(t===void 0)return!0;if(t){if(Array.isArray(t)){for(var e=0,n=t.length;e<n;e++)if(ro(t[e]))return!0}else if(typeof t=="object"){for(var r=io(t),o=r.length,i=0;i<o;i++)if(ro(t[r[i]]))return!0}}return!1}function kc(t,e){var n=[t];for(var r in e){var o=typeof e[r]=="object"?JSON.stringify(e[r],null,2):e[r];typeof o<"u"&&n.push(r+": "+o)}return n.join(`
2
+ `)}var nr=(function(t){Am(e,t);function e(n,r,o,i,s){var a=this.constructor,l=t.call(this,kc(n,{name:r,index:o,operation:i,tree:s}))||this;return l.name=r,l.index=o,l.operation=i,l.tree=s,Object.setPrototypeOf(l,a.prototype),l.message=kc(n,{name:r,index:o,operation:i,tree:s}),l}return e})(Error);var he=nr,Cm=Ee,Cn={add:function(t,e,n){return t[e]=this.value,{newDocument:n}},remove:function(t,e,n){var r=t[e];return delete t[e],{newDocument:n,removed:r}},replace:function(t,e,n){var r=t[e];return t[e]=this.value,{newDocument:n,removed:r}},move:function(t,e,n){var r=ao(n,this.path);r&&(r=Ee(r));var o=Kt(n,{op:"remove",path:this.from}).removed;return Kt(n,{op:"add",path:this.path,value:o}),{newDocument:n,removed:r}},copy:function(t,e,n){var r=ao(n,this.from);return Kt(n,{op:"add",path:this.path,value:Ee(r)}),{newDocument:n}},test:function(t,e,n){return{newDocument:n,test:rr(t[e],this.value)}},_get:function(t,e,n){return this.value=t[e],{newDocument:n}}},Im={add:function(t,e,n){return so(e)?t.splice(e,0,this.value):t[e]=this.value,{newDocument:n,index:e}},remove:function(t,e,n){var r=t.splice(e,1);return{newDocument:n,removed:r[0]}},replace:function(t,e,n){var r=t[e];return t[e]=this.value,{newDocument:n,removed:r}},move:Cn.move,copy:Cn.copy,test:Cn.test,_get:Cn._get};function ao(t,e){if(e=="")return t;var n={op:"_get",path:e};return Kt(t,n),n.value}function Kt(t,e,n,r,o,i){if(n===void 0&&(n=!1),r===void 0&&(r=!0),o===void 0&&(o=!0),i===void 0&&(i=0),n&&(typeof n=="function"?n(e,0,t,e.path):lo(e,0)),e.path===""){var s={newDocument:t};if(e.op==="add")return s.newDocument=e.value,s;if(e.op==="replace")return s.newDocument=e.value,s.removed=t,s;if(e.op==="move"||e.op==="copy")return s.newDocument=ao(t,e.from),e.op==="move"&&(s.removed=t),s;if(e.op==="test"){if(s.test=rr(t,e.value),s.test===!1)throw new he("Test operation failed","TEST_OPERATION_FAILED",i,e,t);return s.newDocument=t,s}else{if(e.op==="remove")return s.removed=t,s.newDocument=null,s;if(e.op==="_get")return e.value=t,s;if(n)throw new he("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",i,e,t);return s}}else{r||(t=Ee(t));var a=e.path||"",l=a.split("/"),c=t,u=1,m=l.length,y=void 0,f=void 0,h=void 0;for(typeof n=="function"?h=n:h=lo;;){if(f=l[u],f&&f.indexOf("~")!=-1&&(f=tr(f)),o&&(f=="__proto__"||f=="prototype"&&u>0&&l[u-1]=="constructor"))throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");if(n&&y===void 0&&(c[f]===void 0?y=l.slice(0,u).join("/"):u==m-1&&(y=e.path),y!==void 0&&h(e,0,t,y)),u++,Array.isArray(c)){if(f==="-")f=c.length;else{if(n&&!so(f))throw new he("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",i,e,t);so(f)&&(f=~~f)}if(u>=m){if(n&&e.op==="add"&&f>c.length)throw new he("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",i,e,t);var s=Im[e.op].call(e,c,f,t);if(s.test===!1)throw new he("Test operation failed","TEST_OPERATION_FAILED",i,e,t);return s}}else if(u>=m){var s=Cn[e.op].call(e,c,f,t);if(s.test===!1)throw new he("Test operation failed","TEST_OPERATION_FAILED",i,e,t);return s}if(c=c[f],n&&u<m&&(!c||typeof c!="object"))throw new he("Cannot perform operation at the desired path","OPERATION_PATH_UNRESOLVABLE",i,e,t)}}}function co(t,e,n,r,o){if(r===void 0&&(r=!0),o===void 0&&(o=!0),n&&!Array.isArray(e))throw new he("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");r||(t=Ee(t));for(var i=new Array(e.length),s=0,a=e.length;s<a;s++)i[s]=Kt(t,e[s],n,!0,o,s),t=i[s].newDocument;return i.newDocument=t,i}function Rm(t,e,n){var r=Kt(t,e);if(r.test===!1)throw new he("Test operation failed","TEST_OPERATION_FAILED",n,e,t);return r.newDocument}function lo(t,e,n,r){if(typeof t!="object"||t===null||Array.isArray(t))throw new he("Operation is not an object","OPERATION_NOT_AN_OBJECT",e,t,n);if(Cn[t.op]){if(typeof t.path!="string")throw new he("Operation `path` property is not a string","OPERATION_PATH_INVALID",e,t,n);if(t.path.indexOf("/")!==0&&t.path.length>0)throw new he('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",e,t,n);if((t.op==="move"||t.op==="copy")&&typeof t.from!="string")throw new he("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",e,t,n);if((t.op==="add"||t.op==="replace"||t.op==="test")&&t.value===void 0)throw new he("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",e,t,n);if((t.op==="add"||t.op==="replace"||t.op==="test")&&ro(t.value))throw new he("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",e,t,n);if(n){if(t.op=="add"){var o=t.path.split("/").length,i=r.split("/").length;if(o!==i+1&&o!==i)throw new he("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",e,t,n)}else if(t.op==="replace"||t.op==="remove"||t.op==="_get"){if(t.path!==r)throw new he("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",e,t,n)}else if(t.op==="move"||t.op==="copy"){var s={op:"_get",path:t.from,value:void 0},a=Cc([s],n);if(a&&a.name==="OPERATION_PATH_UNRESOLVABLE")throw new he("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",e,t,n)}}}else throw new he("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",e,t,n)}function Cc(t,e,n){try{if(!Array.isArray(t))throw new he("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(e)co(Ee(e),Ee(t),n||!0);else{n=n||lo;for(var r=0;r<t.length;r++)n(t[r],r,e,void 0)}}catch(o){if(o instanceof he)return o;throw o}}function rr(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var n=Array.isArray(t),r=Array.isArray(e),o,i,s;if(n&&r){if(i=t.length,i!=e.length)return!1;for(o=i;o--!==0;)if(!rr(t[o],e[o]))return!1;return!0}if(n!=r)return!1;var a=Object.keys(t);if(i=a.length,i!==Object.keys(e).length)return!1;for(o=i;o--!==0;)if(!e.hasOwnProperty(a[o]))return!1;for(o=i;o--!==0;)if(s=a[o],!rr(t[s],e[s]))return!1;return!0}return t!==t&&e!==e}var $s={};ms($s,{compare:()=>Hm,generate:()=>Fs,observe:()=>Um,unobserve:()=>Dm});var zs=new WeakMap,Nm=(function(){function t(e){this.observers=new Map,this.obj=e}return t})(),Om=(function(){function t(e,n){this.callback=e,this.observer=n}return t})();function Mm(t){return zs.get(t)}function Lm(t,e){return t.observers.get(e)}function Pm(t,e){t.observers.delete(e.callback)}function Dm(t,e){e.unobserve()}function Um(t,e){var n=[],r,o=Mm(t);if(!o)o=new Nm(t),zs.set(t,o);else{var i=Lm(o,e);r=i&&i.observer}if(r)return r;if(r={},o.value=Ee(t),e){r.callback=e,r.next=null;var s=function(){Fs(r)},a=function(){clearTimeout(r.next),r.next=setTimeout(s)};typeof window<"u"&&(window.addEventListener("mouseup",a),window.addEventListener("keyup",a),window.addEventListener("mousedown",a),window.addEventListener("keydown",a),window.addEventListener("change",a))}return r.patches=n,r.object=t,r.unobserve=function(){Fs(r),clearTimeout(r.next),Pm(o,r),typeof window<"u"&&(window.removeEventListener("mouseup",a),window.removeEventListener("keyup",a),window.removeEventListener("mousedown",a),window.removeEventListener("keydown",a),window.removeEventListener("change",a))},o.observers.set(e,new Om(e,r)),r}function Fs(t,e){e===void 0&&(e=!1);var n=zs.get(t.object);Gs(n.value,t.object,t.patches,"",e),t.patches.length&&co(n.value,t.patches);var r=t.patches;return r.length>0&&(t.patches=[],t.callback&&t.callback(r)),r}function Gs(t,e,n,r,o){if(e!==t){typeof e.toJSON=="function"&&(e=e.toJSON());for(var i=io(e),s=io(t),a=!1,l=!1,c=s.length-1;c>=0;c--){var u=s[c],m=t[u];if(oo(e,u)&&!(e[u]===void 0&&m!==void 0&&Array.isArray(e)===!1)){var y=e[u];typeof m=="object"&&m!=null&&typeof y=="object"&&y!=null&&Array.isArray(m)===Array.isArray(y)?Gs(m,y,n,r+"/"+at(u),o):m!==y&&(a=!0,o&&n.push({op:"test",path:r+"/"+at(u),value:Ee(m)}),n.push({op:"replace",path:r+"/"+at(u),value:Ee(y)}))}else Array.isArray(t)===Array.isArray(e)?(o&&n.push({op:"test",path:r+"/"+at(u),value:Ee(m)}),n.push({op:"remove",path:r+"/"+at(u)}),l=!0):(o&&n.push({op:"test",path:r,value:t}),n.push({op:"replace",path:r,value:e}),a=!0)}if(!(!l&&i.length==s.length))for(var c=0;c<i.length;c++){var u=i[c];!oo(t,u)&&e[u]!==void 0&&n.push({op:"add",path:r+"/"+at(u),value:Ee(e[u])})}}}function Hm(t,e,n){n===void 0&&(n=!1);var r=[];return Gs(t,e,r,"",n),r}var uo=Object.assign({},Hs,$s,{JsonPatchError:nr,deepClone:Ee,escapePathComponent:at,unescapePathComponent:tr});var Bs=function(t,e){return Bs=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[o]=r[o])},Bs(t,e)};function lt(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");Bs(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}function Ic(t,e,n,r){function o(i){return i instanceof n?i:new n(function(s){s(i)})}return new(n||(n=Promise))(function(i,s){function a(u){try{c(r.next(u))}catch(m){s(m)}}function l(u){try{c(r.throw(u))}catch(m){s(m)}}function c(u){u.done?i(u.value):o(u.value).then(a,l)}c((r=r.apply(t,e||[])).next())})}function po(t,e){var n={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},r,o,i,s=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function a(c){return function(u){return l([c,u])}}function l(c){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,c[0]&&(n=0)),n;)try{if(r=1,o&&(i=c[0]&2?o.return:c[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,c[1])).done)return i;switch(o=0,i&&(c=[c[0]&2,i.value]),c[0]){case 0:case 1:i=c;break;case 4:return n.label++,{value:c[1],done:!1};case 5:n.label++,o=c[1],c=[0];continue;case 7:c=n.ops.pop(),n.trys.pop();continue;default:if(i=n.trys,!(i=i.length>0&&i[i.length-1])&&(c[0]===6||c[0]===2)){n=0;continue}if(c[0]===3&&(!i||c[1]>i[0]&&c[1]<i[3])){n.label=c[1];break}if(c[0]===6&&n.label<i[1]){n.label=i[1],i=c;break}if(i&&n.label<i[2]){n.label=i[2],n.ops.push(c);break}i[2]&&n.ops.pop(),n.trys.pop();continue}c=e.call(t,n)}catch(u){c=[6,u],o=0}finally{r=i=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}function gt(t){var e=typeof Symbol=="function"&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function In(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=r.next()).done;)i.push(o.value)}catch(a){s={error:a}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(s)throw s.error}}return i}function Rn(t,e,n){if(n||arguments.length===2)for(var r=0,o=e.length,i;r<o;r++)(i||!(r in e))&&(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return t.concat(i||Array.prototype.slice.call(e))}function Zt(t){return this instanceof Zt?(this.v=t,this):new Zt(t)}function Rc(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(t,e||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(f){return function(h){return Promise.resolve(h).then(f,m)}}function a(f,h){r[f]&&(o[f]=function(g){return new Promise(function(x,S){i.push([f,g,x,S])>1||l(f,g)})},h&&(o[f]=h(o[f])))}function l(f,h){try{c(r[f](h))}catch(g){y(i[0][3],g)}}function c(f){f.value instanceof Zt?Promise.resolve(f.value.v).then(u,m):y(i[0][2],f)}function u(f){l("next",f)}function m(f){l("throw",f)}function y(f,h){f(h),i.shift(),i.length&&l(i[0][0],i[0][1])}}function Nc(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],n;return e?e.call(t):(t=typeof gt=="function"?gt(t):t[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(i){n[i]=t[i]&&function(s){return new Promise(function(a,l){s=t[i](s),o(a,l,s.done,s.value)})}}function o(i,s,a,l){Promise.resolve(l).then(function(c){i({value:c,done:a})},s)}}function B(t){return typeof t=="function"}function Nn(t){var e=function(r){Error.call(r),r.stack=new Error().stack},n=t(e);return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var ho=Nn(function(t){return function(n){t(this),this.message=n?n.length+` errors occurred during unsubscription:
3
3
  `+n.map(function(r,o){return o+1+") "+r.toString()}).join(`
4
- `):"",this.name="UnsubscriptionError",this.errors=n}});function nr(t,e){if(t){var n=t.indexOf(e);0<=n&&t.splice(n,1)}}var Rn=(function(){function t(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var e,n,r,o,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=gt(s),l=a.next();!l.done;l=a.next()){var c=l.value;c.remove(this)}}catch(g){e={error:g}}finally{try{l&&!l.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}else s.remove(this);var u=this.initialTeardown;if(B(u))try{u()}catch(g){i=g instanceof co?g.errors:[g]}var m=this._finalizers;if(m){this._finalizers=null;try{for(var y=gt(m),f=y.next();!f.done;f=y.next()){var h=f.value;try{kc(h)}catch(g){i=i??[],g instanceof co?i=Cn(Cn([],kn(i)),kn(g.errors)):i.push(g)}}}catch(g){r={error:g}}finally{try{f&&!f.done&&(o=y.return)&&o.call(y)}finally{if(r)throw r.error}}}if(i)throw new co(i)}},t.prototype.add=function(e){var n;if(e&&e!==this)if(this.closed)kc(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(n=this._finalizers)!==null&&n!==void 0?n:[]).push(e)}},t.prototype._hasParent=function(e){var n=this._parentage;return n===e||Array.isArray(n)&&n.includes(e)},t.prototype._addParent=function(e){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(e),n):n?[n,e]:e},t.prototype._removeParent=function(e){var n=this._parentage;n===e?this._parentage=null:Array.isArray(n)&&nr(n,e)},t.prototype.remove=function(e){var n=this._finalizers;n&&nr(n,e),e instanceof t&&e._removeParent(this)},t.EMPTY=(function(){var e=new t;return e.closed=!0,e})(),t})();var Gs=Rn.EMPTY;function uo(t){return t instanceof Rn||t&&"closed"in t&&B(t.remove)&&B(t.add)&&B(t.unsubscribe)}function kc(t){B(t)?t():t.unsubscribe()}var Ke={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var Nn={setTimeout:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=Nn.delegate;return o?.setTimeout?o.setTimeout.apply(o,Cn([t,e],kn(n))):setTimeout.apply(void 0,Cn([t,e],kn(n)))},clearTimeout:function(t){var e=Nn.delegate;return(e?.clearTimeout||clearTimeout)(t)},delegate:void 0};function po(t){Nn.setTimeout(function(){var e=Ke.onUnhandledError;if(e)e(t);else throw t})}function rr(){}var Cc=(function(){return $s("C",void 0,void 0)})();function Ic(t){return $s("E",void 0,t)}function Rc(t){return $s("N",t,void 0)}function $s(t,e,n){return{kind:t,value:e,error:n}}var Qt=null;function On(t){if(Ke.useDeprecatedSynchronousErrorHandling){var e=!Qt;if(e&&(Qt={errorThrown:!1,error:null}),t(),e){var n=Qt,r=n.errorThrown,o=n.error;if(Qt=null,r)throw o}}else t()}function Nc(t){Ke.useDeprecatedSynchronousErrorHandling&&Qt&&(Qt.errorThrown=!0,Qt.error=t)}var or=(function(t){lt(e,t);function e(n){var r=t.call(this)||this;return r.isStopped=!1,n?(r.destination=n,uo(n)&&n.add(r)):r.destination=Pm,r}return e.create=function(n,r,o){return new fo(n,r,o)},e.prototype.next=function(n){this.isStopped?Vs(Rc(n),this):this._next(n)},e.prototype.error=function(n){this.isStopped?Vs(Ic(n),this):(this.isStopped=!0,this._error(n))},e.prototype.complete=function(){this.isStopped?Vs(Cc,this):(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(n){this.destination.next(n)},e.prototype._error=function(n){try{this.destination.error(n)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e})(Rn);var Om=Function.prototype.bind;function Bs(t,e){return Om.call(t,e)}var Mm=(function(){function t(e){this.partialObserver=e}return t.prototype.next=function(e){var n=this.partialObserver;if(n.next)try{n.next(e)}catch(r){ho(r)}},t.prototype.error=function(e){var n=this.partialObserver;if(n.error)try{n.error(e)}catch(r){ho(r)}else ho(e)},t.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(n){ho(n)}},t})(),fo=(function(t){lt(e,t);function e(n,r,o){var i=t.call(this)||this,s;if(B(n)||!n)s={next:n??void 0,error:r??void 0,complete:o??void 0};else{var a;i&&Ke.useDeprecatedNextContext?(a=Object.create(n),a.unsubscribe=function(){return i.unsubscribe()},s={next:n.next&&Bs(n.next,a),error:n.error&&Bs(n.error,a),complete:n.complete&&Bs(n.complete,a)}):s=n}return i.destination=new Mm(s),i}return e})(or);function ho(t){Ke.useDeprecatedSynchronousErrorHandling?Nc(t):po(t)}function Lm(t){throw t}function Vs(t,e){var n=Ke.onStoppedNotification;n&&Nn.setTimeout(function(){return n(t,e)})}var Pm={closed:!0,next:rr,error:Lm,complete:rr};var Mn=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Ln(t){return t}function mo(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return js(t)}function js(t){return t.length===0?Ln:t.length===1?t[0]:function(n){return t.reduce(function(r,o){return o(r)},n)}}var ne=(function(){function t(e){e&&(this._subscribe=e)}return t.prototype.lift=function(e){var n=new t;return n.source=this,n.operator=e,n},t.prototype.subscribe=function(e,n,r){var o=this,i=Um(e)?e:new fo(e,n,r);return On(function(){var s=o,a=s.operator,l=s.source;i.add(a?a.call(i,l):l?o._subscribe(i):o._trySubscribe(i))}),i},t.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(n){e.error(n)}},t.prototype.forEach=function(e,n){var r=this;return n=Oc(n),new n(function(o,i){var s=new fo({next:function(a){try{e(a)}catch(l){i(l),s.unsubscribe()}},error:i,complete:o});r.subscribe(s)})},t.prototype._subscribe=function(e){var n;return(n=this.source)===null||n===void 0?void 0:n.subscribe(e)},t.prototype[Mn]=function(){return this},t.prototype.pipe=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return js(e)(this)},t.prototype.toPromise=function(e){var n=this;return e=Oc(e),new e(function(r,o){var i;n.subscribe(function(s){return i=s},function(s){return o(s)},function(){return r(i)})})},t.create=function(e){return new t(e)},t})();function Oc(t){var e;return(e=t??Ke.Promise)!==null&&e!==void 0?e:Promise}function Dm(t){return t&&B(t.next)&&B(t.error)&&B(t.complete)}function Um(t){return t&&t instanceof or||Dm(t)&&uo(t)}function Hm(t){return B(t?.lift)}function fe(t){return function(e){if(Hm(e))return e.lift(function(n){try{return t(n,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function ge(t,e,n,r,o){return new zm(t,e,n,r,o)}var zm=(function(t){lt(e,t);function e(n,r,o,i,s,a){var l=t.call(this,n)||this;return l.onFinalize=s,l.shouldUnsubscribe=a,l._next=r?function(c){try{r(c)}catch(u){n.error(u)}}:t.prototype._next,l._error=i?function(c){try{i(c)}catch(u){n.error(u)}finally{this.unsubscribe()}}:t.prototype._error,l._complete=o?function(){try{o()}catch(c){n.error(c)}finally{this.unsubscribe()}}:t.prototype._complete,l}return e.prototype.unsubscribe=function(){var n;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;t.prototype.unsubscribe.call(this),!r&&((n=this.onFinalize)===null||n===void 0||n.call(this))}},e})(or);var Mc=In(function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}});var ct=(function(t){lt(e,t);function e(){var n=t.call(this)||this;return n.closed=!1,n.currentObservers=null,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return e.prototype.lift=function(n){var r=new Lc(this,this);return r.operator=n,r},e.prototype._throwIfClosed=function(){if(this.closed)throw new Mc},e.prototype.next=function(n){var r=this;On(function(){var o,i;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var s=gt(r.currentObservers),a=s.next();!a.done;a=s.next()){var l=a.value;l.next(n)}}catch(c){o={error:c}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(o)throw o.error}}}})},e.prototype.error=function(n){var r=this;On(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=n;for(var o=r.observers;o.length;)o.shift().error(n)}})},e.prototype.complete=function(){var n=this;On(function(){if(n._throwIfClosed(),!n.isStopped){n.isStopped=!0;for(var r=n.observers;r.length;)r.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var n;return((n=this.observers)===null||n===void 0?void 0:n.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(n){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,n)},e.prototype._subscribe=function(n){return this._throwIfClosed(),this._checkFinalizedStatuses(n),this._innerSubscribe(n)},e.prototype._innerSubscribe=function(n){var r=this,o=this,i=o.hasError,s=o.isStopped,a=o.observers;return i||s?Gs:(this.currentObservers=null,a.push(n),new Rn(function(){r.currentObservers=null,nr(a,n)}))},e.prototype._checkFinalizedStatuses=function(n){var r=this,o=r.hasError,i=r.thrownError,s=r.isStopped;o?n.error(i):s&&n.complete()},e.prototype.asObservable=function(){var n=new ne;return n.source=this,n},e.create=function(n,r){return new Lc(n,r)},e})(ne);var Lc=(function(t){lt(e,t);function e(n,r){var o=t.call(this)||this;return o.destination=n,o.source=r,o}return e.prototype.next=function(n){var r,o;(o=(r=this.destination)===null||r===void 0?void 0:r.next)===null||o===void 0||o.call(r,n)},e.prototype.error=function(n){var r,o;(o=(r=this.destination)===null||r===void 0?void 0:r.error)===null||o===void 0||o.call(r,n)},e.prototype.complete=function(){var n,r;(r=(n=this.destination)===null||n===void 0?void 0:n.complete)===null||r===void 0||r.call(n)},e.prototype._subscribe=function(n){var r,o;return(o=(r=this.source)===null||r===void 0?void 0:r.subscribe(n))!==null&&o!==void 0?o:Gs},e})(ct);var qs={now:function(){return(qs.delegate||Date).now()},delegate:void 0};var go=(function(t){lt(e,t);function e(n,r,o){n===void 0&&(n=1/0),r===void 0&&(r=1/0),o===void 0&&(o=qs);var i=t.call(this)||this;return i._bufferSize=n,i._windowTime=r,i._timestampProvider=o,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=r===1/0,i._bufferSize=Math.max(1,n),i._windowTime=Math.max(1,r),i}return e.prototype.next=function(n){var r=this,o=r.isStopped,i=r._buffer,s=r._infiniteTimeWindow,a=r._timestampProvider,l=r._windowTime;o||(i.push(n),!s&&i.push(a.now()+l)),this._trimBuffer(),t.prototype.next.call(this,n)},e.prototype._subscribe=function(n){this._throwIfClosed(),this._trimBuffer();for(var r=this._innerSubscribe(n),o=this,i=o._infiniteTimeWindow,s=o._buffer,a=s.slice(),l=0;l<a.length&&!n.closed;l+=i?1:2)n.next(a[l]);return this._checkFinalizedStatuses(n),r},e.prototype._trimBuffer=function(){var n=this,r=n._bufferSize,o=n._timestampProvider,i=n._buffer,s=n._infiniteTimeWindow,a=(s?1:2)*r;if(r<1/0&&a<i.length&&i.splice(0,i.length-a),!s){for(var l=o.now(),c=0,u=1;u<i.length&&i[u]<=l;u+=2)c=u;c&&i.splice(0,c+1)}},e})(ct);var vo=new ne(function(t){return t.complete()});function Pc(t){return t&&B(t.schedule)}function Fm(t){return t[t.length-1]}function Dc(t){return Pc(Fm(t))?t.pop():void 0}var bo=(function(t){return t&&typeof t.length=="number"&&typeof t!="function"});function yo(t){return B(t?.then)}function xo(t){return B(t[Mn])}function wo(t){return Symbol.asyncIterator&&B(t?.[Symbol.asyncIterator])}function Eo(t){return new TypeError("You provided "+(t!==null&&typeof t=="object"?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Gm(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var _o=Gm();function To(t){return B(t?.[_o])}function So(t){return Sc(this,arguments,function(){var n,r,o,i;return lo(this,function(s){switch(s.label){case 0:n=t.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,Zt(n.read())];case 3:return r=s.sent(),o=r.value,i=r.done,i?[4,Zt(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,Zt(o)];case 6:return[4,s.sent()];case 7:return s.sent(),[3,2];case 8:return[3,10];case 9:return n.releaseLock(),[7];case 10:return[2]}})})}function Ao(t){return B(t?.getReader)}function ve(t){if(t instanceof ne)return t;if(t!=null){if(xo(t))return $m(t);if(bo(t))return Bm(t);if(yo(t))return Vm(t);if(wo(t))return Uc(t);if(To(t))return jm(t);if(Ao(t))return qm(t)}throw Eo(t)}function $m(t){return new ne(function(e){var n=t[Mn]();if(B(n.subscribe))return n.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Bm(t){return new ne(function(e){for(var n=0;n<t.length&&!e.closed;n++)e.next(t[n]);e.complete()})}function Vm(t){return new ne(function(e){t.then(function(n){e.closed||(e.next(n),e.complete())},function(n){return e.error(n)}).then(null,po)})}function jm(t){return new ne(function(e){var n,r;try{for(var o=gt(t),i=o.next();!i.done;i=o.next()){var s=i.value;if(e.next(s),e.closed)return}}catch(a){n={error:a}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}e.complete()})}function Uc(t){return new ne(function(e){Wm(t,e).catch(function(n){return e.error(n)})})}function qm(t){return Uc(So(t))}function Wm(t,e){var n,r,o,i;return Tc(this,void 0,void 0,function(){var s,a;return lo(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),n=Ac(t),l.label=1;case 1:return[4,n.next()];case 2:if(r=l.sent(),!!r.done)return[3,4];if(s=r.value,e.next(s),e.closed)return[2];l.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=l.sent(),o={error:a},[3,11];case 6:return l.trys.push([6,,9,10]),r&&!r.done&&(i=n.return)?[4,i.call(n)]:[3,8];case 7:l.sent(),l.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}})})}function Ve(t,e,n,r,o){r===void 0&&(r=0),o===void 0&&(o=!1);var i=e.schedule(function(){n(),o?t.add(this.schedule(null,r)):this.unsubscribe()},r);if(t.add(i),!o)return i}function ko(t,e){return e===void 0&&(e=0),fe(function(n,r){n.subscribe(ge(r,function(o){return Ve(r,t,function(){return r.next(o)},e)},function(){return Ve(r,t,function(){return r.complete()},e)},function(o){return Ve(r,t,function(){return r.error(o)},e)}))})}function Co(t,e){return e===void 0&&(e=0),fe(function(n,r){r.add(t.schedule(function(){return n.subscribe(r)},e))})}function Hc(t,e){return ve(t).pipe(Co(e),ko(e))}function zc(t,e){return ve(t).pipe(Co(e),ko(e))}function Fc(t,e){return new ne(function(n){var r=0;return e.schedule(function(){r===t.length?n.complete():(n.next(t[r++]),n.closed||this.schedule())})})}function Gc(t,e){return new ne(function(n){var r;return Ve(n,e,function(){r=t[_o](),Ve(n,e,function(){var o,i,s;try{o=r.next(),i=o.value,s=o.done}catch(a){n.error(a);return}s?n.complete():n.next(i)},0,!0)}),function(){return B(r?.return)&&r.return()}})}function Io(t,e){if(!t)throw new Error("Iterable cannot be null");return new ne(function(n){Ve(n,e,function(){var r=t[Symbol.asyncIterator]();Ve(n,e,function(){r.next().then(function(o){o.done?n.complete():n.next(o.value)})},0,!0)})})}function $c(t,e){return Io(So(t),e)}function Bc(t,e){if(t!=null){if(xo(t))return Hc(t,e);if(bo(t))return Fc(t,e);if(yo(t))return zc(t,e);if(wo(t))return Io(t,e);if(To(t))return Gc(t,e);if(Ao(t))return $c(t,e)}throw Eo(t)}function Jt(t,e){return e?Bc(t,e):ve(t)}function ue(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Dc(t);return Jt(t,n)}function re(t,e){var n=B(t)?t:function(){return t},r=function(o){return o.error(n())};return new ne(e?function(o){return e.schedule(r,0,o)}:r)}var Vc=In(function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}});function Ro(t,e){var n=typeof e=="object";return new Promise(function(r,o){var i=!1,s;t.subscribe({next:function(a){s=a,i=!0},error:o,complete:function(){i?r(s):n?r(e.defaultValue):o(new Vc)}})})}function en(t,e){return fe(function(n,r){var o=0;n.subscribe(ge(r,function(i){r.next(t.call(e,i,o++))}))})}function jc(t,e,n,r,o,i,s,a){var l=[],c=0,u=0,m=!1,y=function(){m&&!l.length&&!c&&e.complete()},f=function(g){return c<r?h(g):l.push(g)},h=function(g){i&&e.next(g),c++;var x=!1;ve(n(g,u++)).subscribe(ge(e,function(S){o?.(S),i?f(S):e.next(S)},function(){x=!0},void 0,function(){if(x)try{c--;for(var S=function(){var _=l.shift();s?Ve(e,s,function(){return h(_)}):h(_)};l.length&&c<r;)S();y()}catch(_){e.error(_)}}))};return t.subscribe(ge(e,f,function(){m=!0,y()})),function(){a?.()}}function Le(t,e,n){return n===void 0&&(n=1/0),B(e)?Le(function(r,o){return en(function(i,s){return e(r,i,o,s)})(ve(t(r,o)))},n):(typeof e=="number"&&(n=e),fe(function(r,o){return jc(r,o,t,n)}))}function Ws(t){return t===void 0&&(t=1/0),Le(Ln,t)}function No(t){return new ne(function(e){ve(t()).subscribe(e)})}function ir(t){return fe(function(e,n){var r=null,o=!1,i;r=e.subscribe(ge(n,void 0,void 0,function(s){i=ve(t(s,ir(t)(e))),r?(r.unsubscribe(),r=null,i.subscribe(n)):o=!0})),o&&(r.unsubscribe(),r=null,i.subscribe(n))})}function Oo(t,e){return B(e)?Le(t,e,1):Le(t,1)}function Xs(t){return fe(function(e,n){var r=!1;e.subscribe(ge(n,function(o){r=!0,n.next(o)},function(){r||n.next(t),n.complete()}))})}function tn(t){return fe(function(e,n){try{e.subscribe(n)}finally{n.add(t)}})}function Ks(t,e){return fe(function(n,r){var o=null,i=0,s=!1,a=function(){return s&&!o&&r.complete()};n.subscribe(ge(r,function(l){o?.unsubscribe();var c=0,u=i++;ve(t(l,u)).subscribe(o=ge(r,function(m){return r.next(e?e(l,m,u,c++):m)},function(){o=null,a()}))},function(){s=!0,a()}))})}function Mo(t){return fe(function(e,n){ve(t).subscribe(ge(n,function(){return n.complete()},rr)),!n.closed&&e.subscribe(n)})}function Ys(t,e,n){var r=B(t)||e||n?{next:t,error:e,complete:n}:t;return r?fe(function(o,i){var s;(s=r.subscribe)===null||s===void 0||s.call(r);var a=!0;o.subscribe(ge(i,function(l){var c;(c=r.next)===null||c===void 0||c.call(r,l),i.next(l)},function(){var l;a=!1,(l=r.complete)===null||l===void 0||l.call(r),i.complete()},function(l){var c;a=!1,(c=r.error)===null||c===void 0||c.call(r,l),i.error(l)},function(){var l,c;a&&((l=r.unsubscribe)===null||l===void 0||l.call(r)),(c=r.finalize)===null||c===void 0||c.call(r)}))}):Ln}function qc(t){return` \r
5
- `.indexOf(t)>=0}function Lo(t){for(var e=["topLevel"],n=0,r,o,i,s=function(_){return e.push(_)},a=function(_){return e[e.length-1]=_},l=function(_){r==null&&(r=n,o=e.length,i=_)},c=function(_){_===i&&(r=void 0,o=void 0,i=void 0)},u=function(){return e.pop()},m=function(){return n--},y=function(_){if("0"<=_&&_<="9"){s("number");return}switch(_){case'"':s("string");return;case"-":s("numberNeedsDigit");return;case"t":s("true");return;case"f":s("false");return;case"n":s("null");return;case"[":s("arrayNeedsValue");return;case"{":s("objectNeedsKey");return}},f=t.length;n<f;n++){var h=t[n];switch(e[e.length-1]){case"topLevel":y(h);break;case"string":switch(h){case'"':u();break;case"\\":l("stringEscape"),s("stringEscaped");break}break;case"stringEscaped":h==="u"?s("stringUnicode"):(c("stringEscape"),u());break;case"stringUnicode":n-t.lastIndexOf("u",n)===4&&(c("stringEscape"),u());break;case"number":h==="."?a("numberNeedsDigit"):h==="e"||h==="E"?a("numberNeedsExponent"):(h<"0"||h>"9")&&(m(),u());break;case"numberNeedsDigit":a("number");break;case"numberNeedsExponent":a(h==="+"||h==="-"?"numberNeedsDigit":"number");break;case"true":case"false":case"null":(h<"a"||h>"z")&&(m(),u());break;case"arrayNeedsValue":h==="]"?u():qc(h)||(c("collectionItem"),a("arrayNeedsComma"),y(h));break;case"arrayNeedsComma":h==="]"?u():h===","&&(l("collectionItem"),a("arrayNeedsValue"));break;case"objectNeedsKey":h==="}"?u():h==='"'&&(l("collectionItem"),a("objectNeedsColon"),s("string"));break;case"objectNeedsColon":h===":"&&a("objectNeedsValue");break;case"objectNeedsValue":qc(h)||(c("collectionItem"),a("objectNeedsComma"),y(h));break;case"objectNeedsComma":h==="}"?u():h===","&&(l("collectionItem"),a("objectNeedsKey"));break}}o!=null&&(e.length=o);for(var g=[r!=null?t.slice(0,r):t],x=function(_){return g.push(_.slice(t.length-t.lastIndexOf(_[0])))},S=e.length-1;S>=0;S--)switch(e[S]){case"string":g.push('"');break;case"numberNeedsDigit":case"numberNeedsExponent":g.push("0");break;case"true":x("true");break;case"false":x("false");break;case"null":x("null");break;case"arrayNeedsValue":case"arrayNeedsComma":g.push("]");break;case"objectNeedsKey":case"objectNeedsColon":case"objectNeedsValue":case"objectNeedsComma":g.push("}");break}return g.join("")}function Xc(){let t=0,e=0;for(let r=0;r<28;r+=7){let o=this.buf[this.pos++];if(t|=(o&127)<<r,(o&128)==0)return this.assertBounds(),[t,e]}let n=this.buf[this.pos++];if(t|=(n&15)<<28,e=(n&112)>>4,(n&128)==0)return this.assertBounds(),[t,e];for(let r=3;r<=31;r+=7){let o=this.buf[this.pos++];if(e|=(o&127)<<r,(o&128)==0)return this.assertBounds(),[t,e]}throw new Error("invalid varint")}function Do(t,e,n){for(let i=0;i<28;i=i+7){let s=t>>>i,a=!(!(s>>>7)&&e==0),l=(a?s|128:s)&255;if(n.push(l),!a)return}let r=t>>>28&15|(e&7)<<4,o=e>>3!=0;if(n.push((o?r|128:r)&255),!!o){for(let i=3;i<31;i=i+7){let s=e>>>i,a=!!(s>>>7),l=(a?s|128:s)&255;if(n.push(l),!a)return}n.push(e>>>31&1)}}var Po=4294967296;function Zs(t){let e=t[0]==="-";e&&(t=t.slice(1));let n=1e6,r=0,o=0;function i(s,a){let l=Number(t.slice(s,a));o*=n,r=r*n+l,r>=Po&&(o=o+(r/Po|0),r=r%Po)}return i(-24,-18),i(-18,-12),i(-12,-6),i(-6),e?Yc(r,o):Js(r,o)}function Kc(t,e){let n=Js(t,e),r=n.hi&2147483648;r&&(n=Yc(n.lo,n.hi));let o=Qs(n.lo,n.hi);return r?"-"+o:o}function Qs(t,e){if({lo:t,hi:e}=Xm(t,e),e<=2097151)return String(Po*e+t);let n=t&16777215,r=(t>>>24|e<<8)&16777215,o=e>>16&65535,i=n+r*6777216+o*6710656,s=r+o*8147497,a=o*2,l=1e7;return i>=l&&(s+=Math.floor(i/l),i%=l),s>=l&&(a+=Math.floor(s/l),s%=l),a.toString()+Wc(s)+Wc(i)}function Xm(t,e){return{lo:t>>>0,hi:e>>>0}}function Js(t,e){return{lo:t|0,hi:e|0}}function Yc(t,e){return e=~e,t?t=~t+1:e+=1,Js(t,e)}var Wc=t=>{let e=String(t);return"0000000".slice(e.length)+e};function ea(t,e){if(t>=0){for(;t>127;)e.push(t&127|128),t=t>>>7;e.push(t)}else{for(let n=0;n<9;n++)e.push(t&127|128),t=t>>7;e.push(1)}}function Zc(){let t=this.buf[this.pos++],e=t&127;if((t&128)==0)return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(t&127)<<7,(t&128)==0)return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(t&127)<<14,(t&128)==0)return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(t&127)<<21,(t&128)==0)return this.assertBounds(),e;t=this.buf[this.pos++],e|=(t&15)<<28;for(let n=5;(t&128)!==0&&n<10;n++)t=this.buf[this.pos++];if((t&128)!=0)throw new Error("invalid varint");return this.assertBounds(),e>>>0}var Ye=Km();function Km(){let t=new DataView(new ArrayBuffer(8));if(typeof BigInt=="function"&&typeof t.getBigInt64=="function"&&typeof t.getBigUint64=="function"&&typeof t.setBigInt64=="function"&&typeof t.setBigUint64=="function"&&(!!globalThis.Deno||!!globalThis.Bun||typeof process!="object"||typeof process.env!="object"||process.env.BUF_BIGINT_DISABLE!=="1")){let n=BigInt("-9223372036854775808"),r=BigInt("9223372036854775807"),o=BigInt("0"),i=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(s){let a=typeof s=="bigint"?s:BigInt(s);if(a>r||a<n)throw new Error(`invalid int64: ${s}`);return a},uParse(s){let a=typeof s=="bigint"?s:BigInt(s);if(a>i||a<o)throw new Error(`invalid uint64: ${s}`);return a},enc(s){return t.setBigInt64(0,this.parse(s),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},uEnc(s){return t.setBigInt64(0,this.uParse(s),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},dec(s,a){return t.setInt32(0,s,!0),t.setInt32(4,a,!0),t.getBigInt64(0,!0)},uDec(s,a){return t.setInt32(0,s,!0),t.setInt32(4,a,!0),t.getBigUint64(0,!0)}}}return{zero:"0",supported:!1,parse(n){return typeof n!="string"&&(n=n.toString()),Qc(n),n},uParse(n){return typeof n!="string"&&(n=n.toString()),Jc(n),n},enc(n){return typeof n!="string"&&(n=n.toString()),Qc(n),Zs(n)},uEnc(n){return typeof n!="string"&&(n=n.toString()),Jc(n),Zs(n)},dec(n,r){return Kc(n,r)},uDec(n,r){return Qs(n,r)}}}function Qc(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function Jc(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}var ta=Symbol.for("@bufbuild/protobuf/text-encoding");function na(){if(globalThis[ta]==null){let t=new globalThis.TextEncoder,e=new globalThis.TextDecoder,n;globalThis[ta]={encodeUtf8(r){return t.encode(r)},decodeUtf8(r,o){return o?(n===void 0&&(n=new globalThis.TextDecoder("utf-8",{fatal:!0})),n.decode(r)):e.decode(r)},checkUtf8(r){try{return encodeURIComponent(r),!0}catch{return!1}}}}return globalThis[ta]}var Ct;(function(t){t[t.Varint=0]="Varint",t[t.Bit64=1]="Bit64",t[t.LengthDelimited=2]="LengthDelimited",t[t.StartGroup=3]="StartGroup",t[t.EndGroup=4]="EndGroup",t[t.Bit32=5]="Bit32"})(Ct||(Ct={}));var Ym=34028234663852886e22,Zm=-34028234663852886e22,Qm=4294967295,Jm=2147483647,eg=-2147483648,G=class{constructor(e=na().encodeUtf8){this.encodeUtf8=e,this.stack=[],this.chunks=[],this.buf=[]}finish(){this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]);let e=0;for(let o=0;o<this.chunks.length;o++)e+=this.chunks[o].length;let n=new Uint8Array(e),r=0;for(let o=0;o<this.chunks.length;o++)n.set(this.chunks[o],r),r+=this.chunks[o].length;return this.chunks=[],n}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),n=this.stack.pop();if(!n)throw new Error("invalid state, fork stack empty");return this.chunks=n.chunks,this.buf=n.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,n){return this.uint32((e<<3|n)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(ed(e);e>127;)this.buf.push(e&127|128),e=e>>>7;return this.buf.push(e),this}int32(e){return ra(e),ea(e,this.buf),this}bool(e){return this.buf.push(e?1:0),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let n=this.encodeUtf8(e);return this.uint32(n.byteLength),this.raw(n)}float(e){tg(e);let n=new Uint8Array(4);return new DataView(n.buffer).setFloat32(0,e,!0),this.raw(n)}double(e){let n=new Uint8Array(8);return new DataView(n.buffer).setFloat64(0,e,!0),this.raw(n)}fixed32(e){ed(e);let n=new Uint8Array(4);return new DataView(n.buffer).setUint32(0,e,!0),this.raw(n)}sfixed32(e){ra(e);let n=new Uint8Array(4);return new DataView(n.buffer).setInt32(0,e,!0),this.raw(n)}sint32(e){return ra(e),e=(e<<1^e>>31)>>>0,ea(e,this.buf),this}sfixed64(e){let n=new Uint8Array(8),r=new DataView(n.buffer),o=Ye.enc(e);return r.setInt32(0,o.lo,!0),r.setInt32(4,o.hi,!0),this.raw(n)}fixed64(e){let n=new Uint8Array(8),r=new DataView(n.buffer),o=Ye.uEnc(e);return r.setInt32(0,o.lo,!0),r.setInt32(4,o.hi,!0),this.raw(n)}int64(e){let n=Ye.enc(e);return Do(n.lo,n.hi,this.buf),this}sint64(e){let n=Ye.enc(e),r=n.hi>>31,o=n.lo<<1^r,i=(n.hi<<1|n.lo>>>31)^r;return Do(o,i,this.buf),this}uint64(e){let n=Ye.uEnc(e);return Do(n.lo,n.hi,this.buf),this}},A=class{constructor(e,n=na().decodeUtf8){this.decodeUtf8=n,this.varint64=Xc,this.uint32=Zc,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength)}tag(){let e=this.pos,n=this.uint32(),r=this.pos-e;if(r>5||r==5&&this.buf[this.pos-1]>15)throw new Error("illegal tag: varint overflows uint32");let o=n>>>3,i=n&7;if(o<=0||i>5)throw new Error("illegal tag: field no "+o+" wire type "+i);return[o,i]}skip(e,n,r=100){let o=this.pos;switch(e){case Ct.Varint:for(;this.buf[this.pos++]&128;);break;case Ct.Bit64:this.pos+=4;case Ct.Bit32:this.pos+=4;break;case Ct.LengthDelimited:let i=this.uint32();this.pos+=i;break;case Ct.StartGroup:if(r<=0)throw new Error("maximum recursion depth reached");for(;;){let[s,a]=this.tag();if(a===Ct.EndGroup){if(n!==void 0&&s!==n)throw new Error("invalid end group tag");break}this.skip(a,s,r-1)}break;default:throw new Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(o,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return Ye.dec(...this.varint64())}uint64(){return Ye.uDec(...this.varint64())}sint64(){let[e,n]=this.varint64(),r=-(e&1);return e=(e>>>1|(n&1)<<31)^r,n=n>>>1^r,Ye.dec(e,n)}bool(){let[e,n]=this.varint64();return e!==0||n!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return Ye.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return Ye.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),n=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(n,n+e)}string(e){return this.decodeUtf8(this.bytes(),e)}};function ra(t){if(typeof t=="string")t=Number(t);else if(typeof t!="number")throw new Error("invalid int32: "+typeof t);if(!Number.isInteger(t)||t>Jm||t<eg)throw new Error("invalid int32: "+t)}function ed(t){if(typeof t=="string")t=Number(t);else if(typeof t!="number")throw new Error("invalid uint32: "+typeof t);if(!Number.isInteger(t)||t>Qm||t<0)throw new Error("invalid uint32: "+t)}function tg(t){if(typeof t=="string"){let e=t;if(t=Number(t),Number.isNaN(t)&&e!=="NaN")throw new Error("invalid float32: "+e)}else if(typeof t!="number")throw new Error("invalid float32: "+typeof t);if(Number.isFinite(t)&&(t>Ym||t<Zm))throw new Error("invalid float32: "+t)}var ng=(function(t){return t[t.NULL_VALUE=0]="NULL_VALUE",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t})({});function oa(){return{fields:{}}}var sr={encode(t,e=new G){return Object.entries(t.fields).forEach(([n,r])=>{r!==void 0&&aa.encode({key:n,value:r},e.uint32(10).fork()).join()}),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=oa();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:{if(i!==10)break;let s=aa.decode(n,n.uint32());s.value!==void 0&&(o.fields[s.key]=s.value);continue}}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return sr.fromPartial(t??{})},fromPartial(t){let e=oa();return e.fields=Object.entries(t.fields??{}).reduce((n,[r,o])=>(o!==void 0&&(n[r]=o),n),{}),e},wrap(t){let e=oa();if(t!==void 0)for(let n of Object.keys(t))e.fields[n]=t[n];return e},unwrap(t){let e={};if(t.fields)for(let n of Object.keys(t.fields))e[n]=t.fields[n];return e}};function td(){return{key:"",value:void 0}}var aa={encode(t,e=new G){return t.key!==""&&e.uint32(10).string(t.key),t.value!==void 0&&O.encode(O.wrap(t.value),e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=td();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.key=n.string();continue;case 2:if(i!==18)break;o.value=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return aa.fromPartial(t??{})},fromPartial(t){let e=td();return e.key=t.key??"",e.value=t.value??void 0,e}};function ia(){return{nullValue:void 0,numberValue:void 0,stringValue:void 0,boolValue:void 0,structValue:void 0,listValue:void 0}}var O={encode(t,e=new G){return t.nullValue!==void 0&&e.uint32(8).int32(t.nullValue),t.numberValue!==void 0&&e.uint32(17).double(t.numberValue),t.stringValue!==void 0&&e.uint32(26).string(t.stringValue),t.boolValue!==void 0&&e.uint32(32).bool(t.boolValue),t.structValue!==void 0&&sr.encode(sr.wrap(t.structValue),e.uint32(42).fork()).join(),t.listValue!==void 0&&ar.encode(ar.wrap(t.listValue),e.uint32(50).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=ia();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==8)break;o.nullValue=n.int32();continue;case 2:if(i!==17)break;o.numberValue=n.double();continue;case 3:if(i!==26)break;o.stringValue=n.string();continue;case 4:if(i!==32)break;o.boolValue=n.bool();continue;case 5:if(i!==42)break;o.structValue=sr.unwrap(sr.decode(n,n.uint32()));continue;case 6:if(i!==50)break;o.listValue=ar.unwrap(ar.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return O.fromPartial(t??{})},fromPartial(t){let e=ia();return e.nullValue=t.nullValue??void 0,e.numberValue=t.numberValue??void 0,e.stringValue=t.stringValue??void 0,e.boolValue=t.boolValue??void 0,e.structValue=t.structValue??void 0,e.listValue=t.listValue??void 0,e},wrap(t){let e=ia();if(t===null)e.nullValue=ng.NULL_VALUE;else if(typeof t=="boolean")e.boolValue=t;else if(typeof t=="number")e.numberValue=t;else if(typeof t=="string")e.stringValue=t;else if(globalThis.Array.isArray(t))e.listValue=t;else if(typeof t=="object")e.structValue=t;else if(typeof t<"u")throw new globalThis.Error("Unsupported any value type: "+typeof t);return e},unwrap(t){if(t.stringValue!==void 0)return t.stringValue;if(t?.numberValue!==void 0)return t.numberValue;if(t?.boolValue!==void 0)return t.boolValue;if(t?.structValue!==void 0)return t.structValue;if(t?.listValue!==void 0)return t.listValue;if(t?.nullValue!==void 0)return null}};function sa(){return{values:[]}}var ar={encode(t,e=new G){for(let n of t.values)O.encode(O.wrap(n),e.uint32(10).fork()).join();return e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=sa();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.values.push(O.unwrap(O.decode(n,n.uint32())));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ar.fromPartial(t??{})},fromPartial(t){let e=sa();return e.values=t.values?.map(n=>n)||[],e},wrap(t){let e=sa();return e.values=t??[],e},unwrap(t){return t?.hasOwnProperty("values")&&globalThis.Array.isArray(t.values)?t.values:t}},rg=(function(t){return t[t.ADD=0]="ADD",t[t.REMOVE=1]="REMOVE",t[t.REPLACE=2]="REPLACE",t[t.MOVE=3]="MOVE",t[t.COPY=4]="COPY",t[t.TEST=5]="TEST",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t})({});function nd(){return{op:0,path:"",from:void 0,value:void 0}}var Ho={encode(t,e=new G){return t.op!==0&&e.uint32(8).int32(t.op),t.path!==""&&e.uint32(18).string(t.path),t.from!==void 0&&e.uint32(26).string(t.from),t.value!==void 0&&O.encode(O.wrap(t.value),e.uint32(34).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=nd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==8)break;o.op=n.int32();continue;case 2:if(i!==18)break;o.path=n.string();continue;case 3:if(i!==26)break;o.from=n.string();continue;case 4:if(i!==34)break;o.value=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ho.fromPartial(t??{})},fromPartial(t){let e=nd();return e.op=t.op??0,e.path=t.path??"",e.from=t.from??void 0,e.value=t.value??void 0,e}};function rd(){return{id:"",type:"",function:void 0}}var zo={encode(t,e=new G){return t.id!==""&&e.uint32(10).string(t.id),t.type!==""&&e.uint32(18).string(t.type),t.function!==void 0&&Fo.encode(t.function,e.uint32(26).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=rd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.id=n.string();continue;case 2:if(i!==18)break;o.type=n.string();continue;case 3:if(i!==26)break;o.function=Fo.decode(n,n.uint32());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return zo.fromPartial(t??{})},fromPartial(t){let e=rd();return e.id=t.id??"",e.type=t.type??"",e.function=t.function!==void 0&&t.function!==null?Fo.fromPartial(t.function):void 0,e}};function od(){return{name:"",arguments:""}}var Fo={encode(t,e=new G){return t.name!==""&&e.uint32(10).string(t.name),t.arguments!==""&&e.uint32(18).string(t.arguments),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=od();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.name=n.string();continue;case 2:if(i!==18)break;o.arguments=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Fo.fromPartial(t??{})},fromPartial(t){let e=od();return e.name=t.name??"",e.arguments=t.arguments??"",e}};function id(){return{value:"",mimeType:""}}var Go={encode(t,e=new G){return t.value!==""&&e.uint32(10).string(t.value),t.mimeType!==""&&e.uint32(18).string(t.mimeType),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=id();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.value=n.string();continue;case 2:if(i!==18)break;o.mimeType=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Go.fromPartial(t??{})},fromPartial(t){let e=id();return e.value=t.value??"",e.mimeType=t.mimeType??"",e}};function sd(){return{value:"",mimeType:void 0}}var $o={encode(t,e=new G){return t.value!==""&&e.uint32(10).string(t.value),t.mimeType!==void 0&&e.uint32(18).string(t.mimeType),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=sd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.value=n.string();continue;case 2:if(i!==18)break;o.mimeType=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return $o.fromPartial(t??{})},fromPartial(t){let e=sd();return e.value=t.value??"",e.mimeType=t.mimeType??void 0,e}};function ad(){return{data:void 0,url:void 0}}var Ue={encode(t,e=new G){return t.data!==void 0&&Go.encode(t.data,e.uint32(10).fork()).join(),t.url!==void 0&&$o.encode(t.url,e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=ad();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.data=Go.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.url=$o.decode(n,n.uint32());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ue.fromPartial(t??{})},fromPartial(t){let e=ad();return e.data=t.data!==void 0&&t.data!==null?Go.fromPartial(t.data):void 0,e.url=t.url!==void 0&&t.url!==null?$o.fromPartial(t.url):void 0,e}};function ld(){return{text:""}}var Bo={encode(t,e=new G){return t.text!==""&&e.uint32(10).string(t.text),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=ld();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.text=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Bo.fromPartial(t??{})},fromPartial(t){let e=ld();return e.text=t.text??"",e}};function cd(){return{source:void 0,metadata:void 0}}var Vo={encode(t,e=new G){return t.source!==void 0&&Ue.encode(t.source,e.uint32(10).fork()).join(),t.metadata!==void 0&&O.encode(O.wrap(t.metadata),e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=cd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Ue.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Vo.fromPartial(t??{})},fromPartial(t){let e=cd();return e.source=t.source!==void 0&&t.source!==null?Ue.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e}};function dd(){return{source:void 0,metadata:void 0}}var jo={encode(t,e=new G){return t.source!==void 0&&Ue.encode(t.source,e.uint32(10).fork()).join(),t.metadata!==void 0&&O.encode(O.wrap(t.metadata),e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=dd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Ue.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return jo.fromPartial(t??{})},fromPartial(t){let e=dd();return e.source=t.source!==void 0&&t.source!==null?Ue.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e}};function ud(){return{source:void 0,metadata:void 0}}var qo={encode(t,e=new G){return t.source!==void 0&&Ue.encode(t.source,e.uint32(10).fork()).join(),t.metadata!==void 0&&O.encode(O.wrap(t.metadata),e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=ud();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Ue.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return qo.fromPartial(t??{})},fromPartial(t){let e=ud();return e.source=t.source!==void 0&&t.source!==null?Ue.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e}};function pd(){return{source:void 0,metadata:void 0}}var Wo={encode(t,e=new G){return t.source!==void 0&&Ue.encode(t.source,e.uint32(10).fork()).join(),t.metadata!==void 0&&O.encode(O.wrap(t.metadata),e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=pd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Ue.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Wo.fromPartial(t??{})},fromPartial(t){let e=pd();return e.source=t.source!==void 0&&t.source!==null?Ue.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e}};function hd(){return{text:void 0,image:void 0,audio:void 0,video:void 0,document:void 0}}var Xo={encode(t,e=new G){return t.text!==void 0&&Bo.encode(t.text,e.uint32(10).fork()).join(),t.image!==void 0&&Vo.encode(t.image,e.uint32(18).fork()).join(),t.audio!==void 0&&jo.encode(t.audio,e.uint32(26).fork()).join(),t.video!==void 0&&qo.encode(t.video,e.uint32(34).fork()).join(),t.document!==void 0&&Wo.encode(t.document,e.uint32(42).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=hd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.text=Bo.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.image=Vo.decode(n,n.uint32());continue;case 3:if(i!==26)break;o.audio=jo.decode(n,n.uint32());continue;case 4:if(i!==34)break;o.video=qo.decode(n,n.uint32());continue;case 5:if(i!==42)break;o.document=Wo.decode(n,n.uint32());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Xo.fromPartial(t??{})},fromPartial(t){let e=hd();return e.text=t.text!==void 0&&t.text!==null?Bo.fromPartial(t.text):void 0,e.image=t.image!==void 0&&t.image!==null?Vo.fromPartial(t.image):void 0,e.audio=t.audio!==void 0&&t.audio!==null?jo.fromPartial(t.audio):void 0,e.video=t.video!==void 0&&t.video!==null?qo.fromPartial(t.video):void 0,e.document=t.document!==void 0&&t.document!==null?Wo.fromPartial(t.document):void 0,e}};function fd(){return{id:"",role:"",content:void 0,name:void 0,toolCalls:[],toolCallId:void 0,error:void 0,contentParts:[]}}var Ko={encode(t,e=new G){t.id!==""&&e.uint32(10).string(t.id),t.role!==""&&e.uint32(18).string(t.role),t.content!==void 0&&e.uint32(26).string(t.content),t.name!==void 0&&e.uint32(34).string(t.name);for(let n of t.toolCalls)zo.encode(n,e.uint32(42).fork()).join();t.toolCallId!==void 0&&e.uint32(50).string(t.toolCallId),t.error!==void 0&&e.uint32(58).string(t.error);for(let n of t.contentParts)Xo.encode(n,e.uint32(66).fork()).join();return e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=fd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.id=n.string();continue;case 2:if(i!==18)break;o.role=n.string();continue;case 3:if(i!==26)break;o.content=n.string();continue;case 4:if(i!==34)break;o.name=n.string();continue;case 5:if(i!==42)break;o.toolCalls.push(zo.decode(n,n.uint32()));continue;case 6:if(i!==50)break;o.toolCallId=n.string();continue;case 7:if(i!==58)break;o.error=n.string();continue;case 8:if(i!==66)break;o.contentParts.push(Xo.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ko.fromPartial(t??{})},fromPartial(t){let e=fd();return e.id=t.id??"",e.role=t.role??"",e.content=t.content??void 0,e.name=t.name??void 0,e.toolCalls=t.toolCalls?.map(n=>zo.fromPartial(n))||[],e.toolCallId=t.toolCallId??void 0,e.error=t.error??void 0,e.contentParts=t.contentParts?.map(n=>Xo.fromPartial(n))||[],e}};function md(){return{id:"",reason:"",message:void 0,toolCallId:void 0,responseSchema:void 0,expiresAt:void 0,metadata:void 0}}var Yo={encode(t,e=new G){return t.id!==""&&e.uint32(10).string(t.id),t.reason!==""&&e.uint32(18).string(t.reason),t.message!==void 0&&e.uint32(26).string(t.message),t.toolCallId!==void 0&&e.uint32(34).string(t.toolCallId),t.responseSchema!==void 0&&O.encode(O.wrap(t.responseSchema),e.uint32(42).fork()).join(),t.expiresAt!==void 0&&e.uint32(50).string(t.expiresAt),t.metadata!==void 0&&O.encode(O.wrap(t.metadata),e.uint32(58).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=md();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.id=n.string();continue;case 2:if(i!==18)break;o.reason=n.string();continue;case 3:if(i!==26)break;o.message=n.string();continue;case 4:if(i!==34)break;o.toolCallId=n.string();continue;case 5:if(i!==42)break;o.responseSchema=O.unwrap(O.decode(n,n.uint32()));continue;case 6:if(i!==50)break;o.expiresAt=n.string();continue;case 7:if(i!==58)break;o.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Yo.fromPartial(t??{})},fromPartial(t){let e=md();return e.id=t.id??"",e.reason=t.reason??"",e.message=t.message??void 0,e.toolCallId=t.toolCallId??void 0,e.responseSchema=t.responseSchema??void 0,e.expiresAt=t.expiresAt??void 0,e.metadata=t.metadata??void 0,e}},og=(function(t){return t[t.TEXT_MESSAGE_START=0]="TEXT_MESSAGE_START",t[t.TEXT_MESSAGE_CONTENT=1]="TEXT_MESSAGE_CONTENT",t[t.TEXT_MESSAGE_END=2]="TEXT_MESSAGE_END",t[t.TOOL_CALL_START=3]="TOOL_CALL_START",t[t.TOOL_CALL_ARGS=4]="TOOL_CALL_ARGS",t[t.TOOL_CALL_END=5]="TOOL_CALL_END",t[t.STATE_SNAPSHOT=6]="STATE_SNAPSHOT",t[t.STATE_DELTA=7]="STATE_DELTA",t[t.MESSAGES_SNAPSHOT=8]="MESSAGES_SNAPSHOT",t[t.RAW=9]="RAW",t[t.CUSTOM=10]="CUSTOM",t[t.RUN_STARTED=11]="RUN_STARTED",t[t.RUN_FINISHED=12]="RUN_FINISHED",t[t.RUN_ERROR=13]="RUN_ERROR",t[t.STEP_STARTED=14]="STEP_STARTED",t[t.STEP_FINISHED=15]="STEP_FINISHED",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t})({});function gd(){return{type:0,timestamp:void 0,rawEvent:void 0}}var M={encode(t,e=new G){return t.type!==0&&e.uint32(8).int32(t.type),t.timestamp!==void 0&&e.uint32(16).int64(t.timestamp),t.rawEvent!==void 0&&O.encode(O.wrap(t.rawEvent),e.uint32(26).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=gd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==8)break;o.type=n.int32();continue;case 2:if(i!==16)break;o.timestamp=ig(n.int64());continue;case 3:if(i!==26)break;o.rawEvent=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return M.fromPartial(t??{})},fromPartial(t){let e=gd();return e.type=t.type??0,e.timestamp=t.timestamp??void 0,e.rawEvent=t.rawEvent??void 0,e}};function vd(){return{baseEvent:void 0,messageId:"",role:void 0,name:void 0}}var Zo={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.messageId!==""&&e.uint32(18).string(t.messageId),t.role!==void 0&&e.uint32(26).string(t.role),t.name!==void 0&&e.uint32(34).string(t.name),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=vd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue;case 3:if(i!==26)break;o.role=n.string();continue;case 4:if(i!==34)break;o.name=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Zo.fromPartial(t??{})},fromPartial(t){let e=vd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messageId=t.messageId??"",e.role=t.role??void 0,e.name=t.name??void 0,e}};function bd(){return{baseEvent:void 0,messageId:"",delta:""}}var Qo={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.messageId!==""&&e.uint32(18).string(t.messageId),t.delta!==""&&e.uint32(26).string(t.delta),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=bd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue;case 3:if(i!==26)break;o.delta=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Qo.fromPartial(t??{})},fromPartial(t){let e=bd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messageId=t.messageId??"",e.delta=t.delta??"",e}};function yd(){return{baseEvent:void 0,messageId:""}}var Jo={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.messageId!==""&&e.uint32(18).string(t.messageId),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=yd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Jo.fromPartial(t??{})},fromPartial(t){let e=yd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messageId=t.messageId??"",e}};function xd(){return{baseEvent:void 0,toolCallId:"",toolCallName:"",parentMessageId:void 0}}var ei={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.toolCallId!==""&&e.uint32(18).string(t.toolCallId),t.toolCallName!==""&&e.uint32(26).string(t.toolCallName),t.parentMessageId!==void 0&&e.uint32(34).string(t.parentMessageId),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=xd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue;case 3:if(i!==26)break;o.toolCallName=n.string();continue;case 4:if(i!==34)break;o.parentMessageId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ei.fromPartial(t??{})},fromPartial(t){let e=xd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.toolCallId=t.toolCallId??"",e.toolCallName=t.toolCallName??"",e.parentMessageId=t.parentMessageId??void 0,e}};function wd(){return{baseEvent:void 0,toolCallId:"",delta:""}}var ti={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.toolCallId!==""&&e.uint32(18).string(t.toolCallId),t.delta!==""&&e.uint32(26).string(t.delta),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=wd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue;case 3:if(i!==26)break;o.delta=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ti.fromPartial(t??{})},fromPartial(t){let e=wd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.toolCallId=t.toolCallId??"",e.delta=t.delta??"",e}};function Ed(){return{baseEvent:void 0,toolCallId:""}}var ni={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.toolCallId!==""&&e.uint32(18).string(t.toolCallId),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Ed();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ni.fromPartial(t??{})},fromPartial(t){let e=Ed();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.toolCallId=t.toolCallId??"",e}};function _d(){return{baseEvent:void 0,snapshot:void 0}}var ri={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.snapshot!==void 0&&O.encode(O.wrap(t.snapshot),e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=_d();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.snapshot=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ri.fromPartial(t??{})},fromPartial(t){let e=_d();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.snapshot=t.snapshot??void 0,e}};function Td(){return{baseEvent:void 0,delta:[]}}var oi={encode(t,e=new G){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join();for(let n of t.delta)Ho.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Td();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.delta.push(Ho.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return oi.fromPartial(t??{})},fromPartial(t){let e=Td();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.delta=t.delta?.map(n=>Ho.fromPartial(n))||[],e}};function Sd(){return{baseEvent:void 0,messages:[]}}var ii={encode(t,e=new G){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join();for(let n of t.messages)Ko.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Sd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messages.push(Ko.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ii.fromPartial(t??{})},fromPartial(t){let e=Sd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messages=t.messages?.map(n=>Ko.fromPartial(n))||[],e}};function Ad(){return{baseEvent:void 0,event:void 0,source:void 0}}var si={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.event!==void 0&&O.encode(O.wrap(t.event),e.uint32(18).fork()).join(),t.source!==void 0&&e.uint32(26).string(t.source),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Ad();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.event=O.unwrap(O.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.source=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return si.fromPartial(t??{})},fromPartial(t){let e=Ad();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.event=t.event??void 0,e.source=t.source??void 0,e}};function kd(){return{baseEvent:void 0,name:"",value:void 0}}var ai={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.name!==""&&e.uint32(18).string(t.name),t.value!==void 0&&O.encode(O.wrap(t.value),e.uint32(26).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=kd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.name=n.string();continue;case 3:if(i!==26)break;o.value=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ai.fromPartial(t??{})},fromPartial(t){let e=kd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.name=t.name??"",e.value=t.value??void 0,e}};function Cd(){return{baseEvent:void 0,threadId:"",runId:""}}var li={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.threadId!==""&&e.uint32(18).string(t.threadId),t.runId!==""&&e.uint32(26).string(t.runId),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Cd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.threadId=n.string();continue;case 3:if(i!==26)break;o.runId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return li.fromPartial(t??{})},fromPartial(t){let e=Cd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.threadId=t.threadId??"",e.runId=t.runId??"",e}};function Id(){return{baseEvent:void 0,threadId:"",runId:"",result:void 0,outcome:"",interrupts:[]}}var ci={encode(t,e=new G){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.threadId!==""&&e.uint32(18).string(t.threadId),t.runId!==""&&e.uint32(26).string(t.runId),t.result!==void 0&&O.encode(O.wrap(t.result),e.uint32(34).fork()).join(),t.outcome!==""&&e.uint32(42).string(t.outcome);for(let n of t.interrupts)Yo.encode(n,e.uint32(50).fork()).join();return e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Id();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.threadId=n.string();continue;case 3:if(i!==26)break;o.runId=n.string();continue;case 4:if(i!==34)break;o.result=O.unwrap(O.decode(n,n.uint32()));continue;case 5:if(i!==42)break;o.outcome=n.string();continue;case 6:if(i!==50)break;o.interrupts.push(Yo.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ci.fromPartial(t??{})},fromPartial(t){let e=Id();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.threadId=t.threadId??"",e.runId=t.runId??"",e.result=t.result??void 0,e.outcome=t.outcome??"",e.interrupts=t.interrupts?.map(n=>Yo.fromPartial(n))||[],e}};function Rd(){return{baseEvent:void 0,code:void 0,message:""}}var di={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.code!==void 0&&e.uint32(18).string(t.code),t.message!==""&&e.uint32(26).string(t.message),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Rd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.code=n.string();continue;case 3:if(i!==26)break;o.message=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return di.fromPartial(t??{})},fromPartial(t){let e=Rd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.code=t.code??void 0,e.message=t.message??"",e}};function Nd(){return{baseEvent:void 0,stepName:""}}var ui={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.stepName!==""&&e.uint32(18).string(t.stepName),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Nd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.stepName=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ui.fromPartial(t??{})},fromPartial(t){let e=Nd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.stepName=t.stepName??"",e}};function Od(){return{baseEvent:void 0,stepName:""}}var pi={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.stepName!==""&&e.uint32(18).string(t.stepName),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Od();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.stepName=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return pi.fromPartial(t??{})},fromPartial(t){let e=Od();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.stepName=t.stepName??"",e}};function Md(){return{baseEvent:void 0,messageId:void 0,role:void 0,delta:void 0,name:void 0}}var hi={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.messageId!==void 0&&e.uint32(18).string(t.messageId),t.role!==void 0&&e.uint32(26).string(t.role),t.delta!==void 0&&e.uint32(34).string(t.delta),t.name!==void 0&&e.uint32(42).string(t.name),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Md();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue;case 3:if(i!==26)break;o.role=n.string();continue;case 4:if(i!==34)break;o.delta=n.string();continue;case 5:if(i!==42)break;o.name=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return hi.fromPartial(t??{})},fromPartial(t){let e=Md();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messageId=t.messageId??void 0,e.role=t.role??void 0,e.delta=t.delta??void 0,e.name=t.name??void 0,e}};function Ld(){return{baseEvent:void 0,toolCallId:void 0,toolCallName:void 0,parentMessageId:void 0,delta:void 0}}var fi={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.toolCallId!==void 0&&e.uint32(18).string(t.toolCallId),t.toolCallName!==void 0&&e.uint32(26).string(t.toolCallName),t.parentMessageId!==void 0&&e.uint32(34).string(t.parentMessageId),t.delta!==void 0&&e.uint32(42).string(t.delta),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Ld();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue;case 3:if(i!==26)break;o.toolCallName=n.string();continue;case 4:if(i!==34)break;o.parentMessageId=n.string();continue;case 5:if(i!==42)break;o.delta=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return fi.fromPartial(t??{})},fromPartial(t){let e=Ld();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.toolCallId=t.toolCallId??void 0,e.toolCallName=t.toolCallName??void 0,e.parentMessageId=t.parentMessageId??void 0,e.delta=t.delta??void 0,e}};function Pd(){return{textMessageStart:void 0,textMessageContent:void 0,textMessageEnd:void 0,toolCallStart:void 0,toolCallArgs:void 0,toolCallEnd:void 0,stateSnapshot:void 0,stateDelta:void 0,messagesSnapshot:void 0,raw:void 0,custom:void 0,runStarted:void 0,runFinished:void 0,runError:void 0,stepStarted:void 0,stepFinished:void 0,textMessageChunk:void 0,toolCallChunk:void 0}}var Dd={encode(t,e=new G){return t.textMessageStart!==void 0&&Zo.encode(t.textMessageStart,e.uint32(10).fork()).join(),t.textMessageContent!==void 0&&Qo.encode(t.textMessageContent,e.uint32(18).fork()).join(),t.textMessageEnd!==void 0&&Jo.encode(t.textMessageEnd,e.uint32(26).fork()).join(),t.toolCallStart!==void 0&&ei.encode(t.toolCallStart,e.uint32(34).fork()).join(),t.toolCallArgs!==void 0&&ti.encode(t.toolCallArgs,e.uint32(42).fork()).join(),t.toolCallEnd!==void 0&&ni.encode(t.toolCallEnd,e.uint32(50).fork()).join(),t.stateSnapshot!==void 0&&ri.encode(t.stateSnapshot,e.uint32(58).fork()).join(),t.stateDelta!==void 0&&oi.encode(t.stateDelta,e.uint32(66).fork()).join(),t.messagesSnapshot!==void 0&&ii.encode(t.messagesSnapshot,e.uint32(74).fork()).join(),t.raw!==void 0&&si.encode(t.raw,e.uint32(82).fork()).join(),t.custom!==void 0&&ai.encode(t.custom,e.uint32(90).fork()).join(),t.runStarted!==void 0&&li.encode(t.runStarted,e.uint32(98).fork()).join(),t.runFinished!==void 0&&ci.encode(t.runFinished,e.uint32(106).fork()).join(),t.runError!==void 0&&di.encode(t.runError,e.uint32(114).fork()).join(),t.stepStarted!==void 0&&ui.encode(t.stepStarted,e.uint32(122).fork()).join(),t.stepFinished!==void 0&&pi.encode(t.stepFinished,e.uint32(130).fork()).join(),t.textMessageChunk!==void 0&&hi.encode(t.textMessageChunk,e.uint32(138).fork()).join(),t.toolCallChunk!==void 0&&fi.encode(t.toolCallChunk,e.uint32(146).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Pd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.textMessageStart=Zo.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.textMessageContent=Qo.decode(n,n.uint32());continue;case 3:if(i!==26)break;o.textMessageEnd=Jo.decode(n,n.uint32());continue;case 4:if(i!==34)break;o.toolCallStart=ei.decode(n,n.uint32());continue;case 5:if(i!==42)break;o.toolCallArgs=ti.decode(n,n.uint32());continue;case 6:if(i!==50)break;o.toolCallEnd=ni.decode(n,n.uint32());continue;case 7:if(i!==58)break;o.stateSnapshot=ri.decode(n,n.uint32());continue;case 8:if(i!==66)break;o.stateDelta=oi.decode(n,n.uint32());continue;case 9:if(i!==74)break;o.messagesSnapshot=ii.decode(n,n.uint32());continue;case 10:if(i!==82)break;o.raw=si.decode(n,n.uint32());continue;case 11:if(i!==90)break;o.custom=ai.decode(n,n.uint32());continue;case 12:if(i!==98)break;o.runStarted=li.decode(n,n.uint32());continue;case 13:if(i!==106)break;o.runFinished=ci.decode(n,n.uint32());continue;case 14:if(i!==114)break;o.runError=di.decode(n,n.uint32());continue;case 15:if(i!==122)break;o.stepStarted=ui.decode(n,n.uint32());continue;case 16:if(i!==130)break;o.stepFinished=pi.decode(n,n.uint32());continue;case 17:if(i!==138)break;o.textMessageChunk=hi.decode(n,n.uint32());continue;case 18:if(i!==146)break;o.toolCallChunk=fi.decode(n,n.uint32());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Dd.fromPartial(t??{})},fromPartial(t){let e=Pd();return e.textMessageStart=t.textMessageStart!==void 0&&t.textMessageStart!==null?Zo.fromPartial(t.textMessageStart):void 0,e.textMessageContent=t.textMessageContent!==void 0&&t.textMessageContent!==null?Qo.fromPartial(t.textMessageContent):void 0,e.textMessageEnd=t.textMessageEnd!==void 0&&t.textMessageEnd!==null?Jo.fromPartial(t.textMessageEnd):void 0,e.toolCallStart=t.toolCallStart!==void 0&&t.toolCallStart!==null?ei.fromPartial(t.toolCallStart):void 0,e.toolCallArgs=t.toolCallArgs!==void 0&&t.toolCallArgs!==null?ti.fromPartial(t.toolCallArgs):void 0,e.toolCallEnd=t.toolCallEnd!==void 0&&t.toolCallEnd!==null?ni.fromPartial(t.toolCallEnd):void 0,e.stateSnapshot=t.stateSnapshot!==void 0&&t.stateSnapshot!==null?ri.fromPartial(t.stateSnapshot):void 0,e.stateDelta=t.stateDelta!==void 0&&t.stateDelta!==null?oi.fromPartial(t.stateDelta):void 0,e.messagesSnapshot=t.messagesSnapshot!==void 0&&t.messagesSnapshot!==null?ii.fromPartial(t.messagesSnapshot):void 0,e.raw=t.raw!==void 0&&t.raw!==null?si.fromPartial(t.raw):void 0,e.custom=t.custom!==void 0&&t.custom!==null?ai.fromPartial(t.custom):void 0,e.runStarted=t.runStarted!==void 0&&t.runStarted!==null?li.fromPartial(t.runStarted):void 0,e.runFinished=t.runFinished!==void 0&&t.runFinished!==null?ci.fromPartial(t.runFinished):void 0,e.runError=t.runError!==void 0&&t.runError!==null?di.fromPartial(t.runError):void 0,e.stepStarted=t.stepStarted!==void 0&&t.stepStarted!==null?ui.fromPartial(t.stepStarted):void 0,e.stepFinished=t.stepFinished!==void 0&&t.stepFinished!==null?pi.fromPartial(t.stepFinished):void 0,e.textMessageChunk=t.textMessageChunk!==void 0&&t.textMessageChunk!==null?hi.fromPartial(t.textMessageChunk):void 0,e.toolCallChunk=t.toolCallChunk!==void 0&&t.toolCallChunk!==null?fi.fromPartial(t.toolCallChunk):void 0,e}};function ig(t){let e=globalThis.Number(t.toString());if(e>globalThis.Number.MAX_SAFE_INTEGER)throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");if(e<globalThis.Number.MIN_SAFE_INTEGER)throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");return e}var Uo=t=>{if(!(!t||typeof t!="object")){if(t.data)return{type:"data",value:t.data.value,mimeType:t.data.mimeType};if(t.url)return{type:"url",value:t.url.value,mimeType:t.url.mimeType}}},sg=t=>{if(!(!t||typeof t!="object")){if(t.text)return{type:"text",text:t.text.text};if(t.image)return{type:"image",source:Uo(t.image.source),metadata:t.image.metadata};if(t.audio)return{type:"audio",source:Uo(t.audio.source),metadata:t.audio.metadata};if(t.video)return{type:"video",source:Uo(t.video.source),metadata:t.video.metadata};if(t.document)return{type:"document",source:Uo(t.document.source),metadata:t.document.metadata}}};function Ud(t){let e=Dd.decode(t),n=Object.values(e).find(r=>r!==void 0);if(!n)throw new Error("Invalid event");if(n.type=og[n.baseEvent.type],n.timestamp=n.baseEvent.timestamp,n.rawEvent=n.baseEvent.rawEvent,delete n.baseEvent,n.type===v.MESSAGES_SNAPSHOT)for(let r of n.messages){let o=r;if(o.role==="user"&&Array.isArray(o.contentParts)){let i=o.contentParts.map(s=>sg(s)).filter(s=>s!==void 0);i.length>0&&(o.content=i)}Array.isArray(o.contentParts)&&o.contentParts.length===0&&(o.contentParts=void 0),o.toolCalls?.length===0&&(o.toolCalls=void 0)}if(n.type===v.RUN_FINISHED){let r=n,o=typeof r.outcome=="string"&&r.outcome!==""?r.outcome:void 0,i=Array.isArray(r.interrupts)?r.interrupts:[];delete r.interrupts,o==="interrupt"?r.outcome={type:"interrupt",interrupts:i}:o==="success"?r.outcome={type:"success"}:delete r.outcome}if(n.type===v.STATE_DELTA)for(let r of n.delta)r.op=rg[r.op].toLowerCase(),Object.keys(r).forEach(o=>{r[o]===void 0&&delete r[o]});return Object.keys(n).forEach(r=>{n[r]===void 0&&delete n[r]}),Jr.parse(n)}var la="application/vnd.ag-ui.event+proto";var lg=/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i,ca=t=>{if(typeof t!="string")throw new TypeError("Invalid argument expected string");let e=t.match(lg);if(!e)throw new Error(`Invalid argument not valid semver ('${t}' received)`);return e.shift(),e},Hd=t=>t==="*"||t==="x"||t==="X",zd=t=>{let e=parseInt(t,10);return isNaN(e)?t:e},cg=(t,e)=>typeof t!=typeof e?[String(t),String(e)]:[t,e],dg=(t,e)=>{if(Hd(t)||Hd(e))return 0;let[n,r]=cg(zd(t),zd(e));return n>r?1:n<r?-1:0},da=(t,e)=>{for(let n=0;n<Math.max(t.length,e.length);n++){let r=dg(t[n]||"0",e[n]||"0");if(r!==0)return r}return 0};var lr=(t,e)=>{let n=ca(t),r=ca(e),o=n.pop(),i=r.pop(),s=da(n,r);return s!==0?s:o&&i?da(o.split("."),i.split(".")):o||i?o?-1:1:0};var q=t=>{if(typeof structuredClone=="function")return structuredClone(t);try{return JSON.parse(JSON.stringify(t))}catch{return Array.isArray(t)?[...t]:{...t}}};function _e(){return _t()}function ha(t){if(Object.freeze(t),typeof t=="object"&&t)for(let e of Object.values(t))typeof e=="object"&&e&&!Object.isFrozen(e)&&ha(e);return t}var Fd=512*1024;function Gd(t,e,n){let r=0,o=[t,e],i=new WeakSet;for(;o.length>0;){let s=o.pop();if(typeof s=="string"){if(r+=s.length,r>n)return!0}else if(typeof s=="object"&&s){if(i.has(s))continue;if(i.add(s),Array.isArray(s))for(let a=0;a<s.length;a++)o.push(s[a]);else{let a=Object.keys(s);for(let l=0;l<a.length;l++){let c=a[l];if(r+=c.length,r>n)return!0;o.push(s[c])}}}}return!1}async function Y(t,e,n,r){let o=typeof process<"u"&&process.env!==void 0,i=o&&!!process.env.VITEST_WORKER_ID,s=o&&!!process.env.VITEST_WORKER_ID,a=s&&!Gd(e,n,Fd),l=a?q(e):e,c=a?q(n):n,u=!1,m=!1,y;for(let f of t)try{a&&(ha(l),ha(c));let h=await r(f,l,c);if(h===void 0)continue;let g=!1;if(h.messages!==void 0&&h.messages!==l&&(l=q(h.messages),u=!0,g=!0),h.state!==void 0&&h.state!==c&&(c=q(h.state),m=!0,g=!0),a&&g&&Gd(l,c,Fd)&&(a=!1),y=h.stopPropagation,y===!0)break}catch(h){if(s&&h instanceof TypeError){if(i)throw h;console.error("AG-UI: Subscriber attempted to mutate frozen inputs in-place. Return mutations via AgentStateMutation instead of mutating directly.",h)}else i||console.error("Subscriber error:",h);continue}return{...u?{messages:Object.isFrozen(l)?q(l):l}:{},...m?{state:Object.isFrozen(c)?q(c):c}:{},...y===void 0?{}:{stopPropagation:y}}}function mi(t){if(!t)return{enabled:!1,events:!1,lifecycle:!1,verbose:!1};if(t===!0)return{enabled:!0,events:!0,lifecycle:!0,verbose:!0};let e=t.events??!0,n=t.lifecycle??!0,r=t.verbose??!1;return{enabled:e||n,events:e,lifecycle:n,verbose:r}}function cr(t){if(t instanceof fa)return t;if(t===!0)return new fa(mi(!0))}var fa=class{constructor(t){this.config=t}event(t,e,n,r){this.config.events&&(this.config.verbose?console.debug(`[${t}] ${e}`,typeof n=="string"?n:JSON.stringify(n)):console.debug(`[${t}] ${e}`,r??n))}lifecycle(t,e,n){this.config.lifecycle&&(n?console.debug(`[${t}] ${e}`,n):console.debug(`[${t}] ${e}`))}get eventsEnabled(){return this.config.events}get lifecycleEnabled(){return this.config.lifecycle}get enabled(){return this.config.enabled}};function ua(t){return t.enabled?new fa(t):void 0}function ug(t,e,n){if(e){let o=t.find(s=>s.id===e);if(o?.role==="assistant")return o;o&&console.warn(`TOOL_CALL_START: parentMessageId '${e}' matches a '${o.role}' message, not assistant \u2014 falling back to toolCallId`);let i={id:o?n:e,role:"assistant",toolCalls:[]};return t.push(i),i}let r={id:n,role:"assistant",toolCalls:[]};return t.push(r),r}var Wd=(t,e,n,r,o)=>{let i=cr(o),s=q(n.messages),a=q(t.state),l={},c=m=>{m.messages!==void 0&&(s=m.messages,l.messages=m.messages),m.state!==void 0&&(a=m.state,l.state=m.state)},u=()=>{let m=q(l);return l={},m.messages!==void 0||m.state!==void 0?ue(m):vo};return e.pipe(Oo(async m=>{let y=await Y(r,s,a,(f,h,g)=>f.onEvent?.({event:m,agent:n,input:t,messages:h,state:g}));if(c(y),y.stopPropagation===!0?i?.event("APPLY","Event dropped:",m,{type:m.type,reason:"stopPropagation by subscriber"}):i?.event("APPLY","Event applied:",m,{type:m.type,subscribers:r.length}),y.stopPropagation===!0)return u();switch(m.type){case v.TEXT_MESSAGE_START:{let f=await Y(r,s,a,(h,g,x)=>h.onTextMessageStartEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let{messageId:h,role:g="assistant",name:x}=m;if(!s.find(S=>S.id===h)){let S={id:h,role:g,content:"",...x!==void 0&&{name:x}};s.push(S),c({messages:s})}}return u()}case v.TEXT_MESSAGE_CONTENT:{let{messageId:f,delta:h}=m,g=s.find(S=>S.id===f);if(!g)return console.warn(`TEXT_MESSAGE_CONTENT: No message found with ID '${f}'`),u();let x=await Y(r,s,a,(S,_,I)=>S.onTextMessageContentEvent?.({event:m,messages:_,state:I,agent:n,input:t,textMessageBuffer:typeof g.content=="string"?g.content:""}));return c(x),x.stopPropagation!==!0&&(g.content=`${typeof g.content=="string"?g.content:""}${h}`,c({messages:s})),u()}case v.TEXT_MESSAGE_END:{let{messageId:f}=m,h=s.find(g=>g.id===f);return h?(c(await Y(r,s,a,(g,x,S)=>g.onTextMessageEndEvent?.({event:m,messages:x,state:S,agent:n,input:t,textMessageBuffer:typeof h.content=="string"?h.content:""}))),await Promise.all(r.map(g=>{g.onNewMessage?.({message:h,messages:s,state:a,agent:n,input:t})})),u()):(console.warn(`TEXT_MESSAGE_END: No message found with ID '${f}'`),u())}case v.TOOL_CALL_START:{let f=await Y(r,s,a,(h,g,x)=>h.onToolCallStartEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let{toolCallId:h,toolCallName:g,parentMessageId:x}=m,S=ug(s,x,h);S.toolCalls??=[],S.toolCalls.push({id:h,type:"function",function:{name:g,arguments:""}}),c({messages:s})}return u()}case v.TOOL_CALL_ARGS:{let{toolCallId:f,delta:h}=m,g=s.find(_=>_.toolCalls?.some(I=>I.id===f));if(!g)return console.warn(`TOOL_CALL_ARGS: No message found containing tool call with ID '${f}'`),u();let x=g.toolCalls?.find(_=>_.id===f);if(!x)return console.warn(`TOOL_CALL_ARGS: No tool call found with ID '${f}'`),u();let S=await Y(r,s,a,(_,I,H)=>{let U=x.function.arguments,K=x.function.name,oe={};try{oe=Lo(U)}catch{}return _.onToolCallArgsEvent?.({event:m,messages:I,state:H,agent:n,input:t,toolCallBuffer:U,toolCallName:K,partialToolCallArgs:oe})});return c(S),S.stopPropagation!==!0&&(x.function.arguments+=h,c({messages:s})),u()}case v.TOOL_CALL_END:{let{toolCallId:f}=m,h=s.find(x=>x.toolCalls?.some(S=>S.id===f));if(!h)return console.warn(`TOOL_CALL_END: No message found containing tool call with ID '${f}'`),u();let g=h.toolCalls?.find(x=>x.id===f);return g?(c(await Y(r,s,a,(x,S,_)=>{let I=g.function.arguments,H=g.function.name,U={};try{U=JSON.parse(I)}catch{}return x.onToolCallEndEvent?.({event:m,messages:S,state:_,agent:n,input:t,toolCallName:H,toolCallArgs:U})})),await Promise.all(r.map(x=>{x.onNewToolCall?.({toolCall:g,messages:s,state:a,agent:n,input:t})})),u()):(console.warn(`TOOL_CALL_END: No tool call found with ID '${f}'`),u())}case v.TOOL_CALL_RESULT:{let f=await Y(r,s,a,(h,g,x)=>h.onToolCallResultEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let{messageId:h,toolCallId:g,content:x,role:S}=m,_={id:h,toolCallId:g,role:S||"tool",content:x},I=s.findIndex(H=>H.role==="assistant"&&H.toolCalls?.some(U=>U.id===g));if(I===-1)s.push(_);else{let H=I+1;for(;H<s.length&&s[H].role==="tool";)H++;s.splice(H,0,_)}await Promise.all(r.map(H=>{H.onNewMessage?.({message:_,messages:s,state:a,agent:n,input:t})})),c({messages:s})}return u()}case v.STATE_SNAPSHOT:{let f=await Y(r,s,a,(h,g,x)=>h.onStateSnapshotEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let{snapshot:h}=m;a=h,c({state:a})}return u()}case v.STATE_DELTA:{let f=await Y(r,s,a,(h,g,x)=>h.onStateDeltaEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let{delta:h}=m;try{a=ao.applyPatch(a,h,!0,!1).newDocument,c({state:a})}catch(g){let x=g instanceof Error?g.message:String(g);console.warn(`Failed to apply state patch:
4
+ `):"",this.name="UnsubscriptionError",this.errors=n}});function or(t,e){if(t){var n=t.indexOf(e);0<=n&&t.splice(n,1)}}var On=(function(){function t(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var e,n,r,o,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=gt(s),l=a.next();!l.done;l=a.next()){var c=l.value;c.remove(this)}}catch(g){e={error:g}}finally{try{l&&!l.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}else s.remove(this);var u=this.initialTeardown;if(B(u))try{u()}catch(g){i=g instanceof ho?g.errors:[g]}var m=this._finalizers;if(m){this._finalizers=null;try{for(var y=gt(m),f=y.next();!f.done;f=y.next()){var h=f.value;try{Oc(h)}catch(g){i=i??[],g instanceof ho?i=Rn(Rn([],In(i)),In(g.errors)):i.push(g)}}}catch(g){r={error:g}}finally{try{f&&!f.done&&(o=y.return)&&o.call(y)}finally{if(r)throw r.error}}}if(i)throw new ho(i)}},t.prototype.add=function(e){var n;if(e&&e!==this)if(this.closed)Oc(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(n=this._finalizers)!==null&&n!==void 0?n:[]).push(e)}},t.prototype._hasParent=function(e){var n=this._parentage;return n===e||Array.isArray(n)&&n.includes(e)},t.prototype._addParent=function(e){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(e),n):n?[n,e]:e},t.prototype._removeParent=function(e){var n=this._parentage;n===e?this._parentage=null:Array.isArray(n)&&or(n,e)},t.prototype.remove=function(e){var n=this._finalizers;n&&or(n,e),e instanceof t&&e._removeParent(this)},t.EMPTY=(function(){var e=new t;return e.closed=!0,e})(),t})();var Vs=On.EMPTY;function fo(t){return t instanceof On||t&&"closed"in t&&B(t.remove)&&B(t.add)&&B(t.unsubscribe)}function Oc(t){B(t)?t():t.unsubscribe()}var Ye={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var Mn={setTimeout:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=Mn.delegate;return o?.setTimeout?o.setTimeout.apply(o,Rn([t,e],In(n))):setTimeout.apply(void 0,Rn([t,e],In(n)))},clearTimeout:function(t){var e=Mn.delegate;return(e?.clearTimeout||clearTimeout)(t)},delegate:void 0};function mo(t){Mn.setTimeout(function(){var e=Ye.onUnhandledError;if(e)e(t);else throw t})}function ir(){}var Mc=(function(){return js("C",void 0,void 0)})();function Lc(t){return js("E",void 0,t)}function Pc(t){return js("N",t,void 0)}function js(t,e,n){return{kind:t,value:e,error:n}}var Qt=null;function Ln(t){if(Ye.useDeprecatedSynchronousErrorHandling){var e=!Qt;if(e&&(Qt={errorThrown:!1,error:null}),t(),e){var n=Qt,r=n.errorThrown,o=n.error;if(Qt=null,r)throw o}}else t()}function Dc(t){Ye.useDeprecatedSynchronousErrorHandling&&Qt&&(Qt.errorThrown=!0,Qt.error=t)}var sr=(function(t){lt(e,t);function e(n){var r=t.call(this)||this;return r.isStopped=!1,n?(r.destination=n,fo(n)&&n.add(r)):r.destination=$m,r}return e.create=function(n,r,o){return new vo(n,r,o)},e.prototype.next=function(n){this.isStopped?Ws(Pc(n),this):this._next(n)},e.prototype.error=function(n){this.isStopped?Ws(Lc(n),this):(this.isStopped=!0,this._error(n))},e.prototype.complete=function(){this.isStopped?Ws(Mc,this):(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(n){this.destination.next(n)},e.prototype._error=function(n){try{this.destination.error(n)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e})(On);var Fm=Function.prototype.bind;function qs(t,e){return Fm.call(t,e)}var zm=(function(){function t(e){this.partialObserver=e}return t.prototype.next=function(e){var n=this.partialObserver;if(n.next)try{n.next(e)}catch(r){go(r)}},t.prototype.error=function(e){var n=this.partialObserver;if(n.error)try{n.error(e)}catch(r){go(r)}else go(e)},t.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(n){go(n)}},t})(),vo=(function(t){lt(e,t);function e(n,r,o){var i=t.call(this)||this,s;if(B(n)||!n)s={next:n??void 0,error:r??void 0,complete:o??void 0};else{var a;i&&Ye.useDeprecatedNextContext?(a=Object.create(n),a.unsubscribe=function(){return i.unsubscribe()},s={next:n.next&&qs(n.next,a),error:n.error&&qs(n.error,a),complete:n.complete&&qs(n.complete,a)}):s=n}return i.destination=new zm(s),i}return e})(sr);function go(t){Ye.useDeprecatedSynchronousErrorHandling?Dc(t):mo(t)}function Gm(t){throw t}function Ws(t,e){var n=Ye.onStoppedNotification;n&&Mn.setTimeout(function(){return n(t,e)})}var $m={closed:!0,next:ir,error:Gm,complete:ir};var Pn=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Dn(t){return t}function bo(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Xs(t)}function Xs(t){return t.length===0?Dn:t.length===1?t[0]:function(n){return t.reduce(function(r,o){return o(r)},n)}}var re=(function(){function t(e){e&&(this._subscribe=e)}return t.prototype.lift=function(e){var n=new t;return n.source=this,n.operator=e,n},t.prototype.subscribe=function(e,n,r){var o=this,i=Vm(e)?e:new vo(e,n,r);return Ln(function(){var s=o,a=s.operator,l=s.source;i.add(a?a.call(i,l):l?o._subscribe(i):o._trySubscribe(i))}),i},t.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(n){e.error(n)}},t.prototype.forEach=function(e,n){var r=this;return n=Uc(n),new n(function(o,i){var s=new vo({next:function(a){try{e(a)}catch(l){i(l),s.unsubscribe()}},error:i,complete:o});r.subscribe(s)})},t.prototype._subscribe=function(e){var n;return(n=this.source)===null||n===void 0?void 0:n.subscribe(e)},t.prototype[Pn]=function(){return this},t.prototype.pipe=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return Xs(e)(this)},t.prototype.toPromise=function(e){var n=this;return e=Uc(e),new e(function(r,o){var i;n.subscribe(function(s){return i=s},function(s){return o(s)},function(){return r(i)})})},t.create=function(e){return new t(e)},t})();function Uc(t){var e;return(e=t??Ye.Promise)!==null&&e!==void 0?e:Promise}function Bm(t){return t&&B(t.next)&&B(t.error)&&B(t.complete)}function Vm(t){return t&&t instanceof sr||Bm(t)&&fo(t)}function jm(t){return B(t?.lift)}function fe(t){return function(e){if(jm(e))return e.lift(function(n){try{return t(n,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function ge(t,e,n,r,o){return new qm(t,e,n,r,o)}var qm=(function(t){lt(e,t);function e(n,r,o,i,s,a){var l=t.call(this,n)||this;return l.onFinalize=s,l.shouldUnsubscribe=a,l._next=r?function(c){try{r(c)}catch(u){n.error(u)}}:t.prototype._next,l._error=i?function(c){try{i(c)}catch(u){n.error(u)}finally{this.unsubscribe()}}:t.prototype._error,l._complete=o?function(){try{o()}catch(c){n.error(c)}finally{this.unsubscribe()}}:t.prototype._complete,l}return e.prototype.unsubscribe=function(){var n;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;t.prototype.unsubscribe.call(this),!r&&((n=this.onFinalize)===null||n===void 0||n.call(this))}},e})(sr);var Hc=Nn(function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}});var ct=(function(t){lt(e,t);function e(){var n=t.call(this)||this;return n.closed=!1,n.currentObservers=null,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return e.prototype.lift=function(n){var r=new Fc(this,this);return r.operator=n,r},e.prototype._throwIfClosed=function(){if(this.closed)throw new Hc},e.prototype.next=function(n){var r=this;Ln(function(){var o,i;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var s=gt(r.currentObservers),a=s.next();!a.done;a=s.next()){var l=a.value;l.next(n)}}catch(c){o={error:c}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(o)throw o.error}}}})},e.prototype.error=function(n){var r=this;Ln(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=n;for(var o=r.observers;o.length;)o.shift().error(n)}})},e.prototype.complete=function(){var n=this;Ln(function(){if(n._throwIfClosed(),!n.isStopped){n.isStopped=!0;for(var r=n.observers;r.length;)r.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var n;return((n=this.observers)===null||n===void 0?void 0:n.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(n){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,n)},e.prototype._subscribe=function(n){return this._throwIfClosed(),this._checkFinalizedStatuses(n),this._innerSubscribe(n)},e.prototype._innerSubscribe=function(n){var r=this,o=this,i=o.hasError,s=o.isStopped,a=o.observers;return i||s?Vs:(this.currentObservers=null,a.push(n),new On(function(){r.currentObservers=null,or(a,n)}))},e.prototype._checkFinalizedStatuses=function(n){var r=this,o=r.hasError,i=r.thrownError,s=r.isStopped;o?n.error(i):s&&n.complete()},e.prototype.asObservable=function(){var n=new re;return n.source=this,n},e.create=function(n,r){return new Fc(n,r)},e})(re);var Fc=(function(t){lt(e,t);function e(n,r){var o=t.call(this)||this;return o.destination=n,o.source=r,o}return e.prototype.next=function(n){var r,o;(o=(r=this.destination)===null||r===void 0?void 0:r.next)===null||o===void 0||o.call(r,n)},e.prototype.error=function(n){var r,o;(o=(r=this.destination)===null||r===void 0?void 0:r.error)===null||o===void 0||o.call(r,n)},e.prototype.complete=function(){var n,r;(r=(n=this.destination)===null||n===void 0?void 0:n.complete)===null||r===void 0||r.call(n)},e.prototype._subscribe=function(n){var r,o;return(o=(r=this.source)===null||r===void 0?void 0:r.subscribe(n))!==null&&o!==void 0?o:Vs},e})(ct);var Ys={now:function(){return(Ys.delegate||Date).now()},delegate:void 0};var yo=(function(t){lt(e,t);function e(n,r,o){n===void 0&&(n=1/0),r===void 0&&(r=1/0),o===void 0&&(o=Ys);var i=t.call(this)||this;return i._bufferSize=n,i._windowTime=r,i._timestampProvider=o,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=r===1/0,i._bufferSize=Math.max(1,n),i._windowTime=Math.max(1,r),i}return e.prototype.next=function(n){var r=this,o=r.isStopped,i=r._buffer,s=r._infiniteTimeWindow,a=r._timestampProvider,l=r._windowTime;o||(i.push(n),!s&&i.push(a.now()+l)),this._trimBuffer(),t.prototype.next.call(this,n)},e.prototype._subscribe=function(n){this._throwIfClosed(),this._trimBuffer();for(var r=this._innerSubscribe(n),o=this,i=o._infiniteTimeWindow,s=o._buffer,a=s.slice(),l=0;l<a.length&&!n.closed;l+=i?1:2)n.next(a[l]);return this._checkFinalizedStatuses(n),r},e.prototype._trimBuffer=function(){var n=this,r=n._bufferSize,o=n._timestampProvider,i=n._buffer,s=n._infiniteTimeWindow,a=(s?1:2)*r;if(r<1/0&&a<i.length&&i.splice(0,i.length-a),!s){for(var l=o.now(),c=0,u=1;u<i.length&&i[u]<=l;u+=2)c=u;c&&i.splice(0,c+1)}},e})(ct);var xo=new re(function(t){return t.complete()});function zc(t){return t&&B(t.schedule)}function Wm(t){return t[t.length-1]}function Gc(t){return zc(Wm(t))?t.pop():void 0}var wo=(function(t){return t&&typeof t.length=="number"&&typeof t!="function"});function Eo(t){return B(t?.then)}function _o(t){return B(t[Pn])}function To(t){return Symbol.asyncIterator&&B(t?.[Symbol.asyncIterator])}function So(t){return new TypeError("You provided "+(t!==null&&typeof t=="object"?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Xm(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Ao=Xm();function ko(t){return B(t?.[Ao])}function Co(t){return Rc(this,arguments,function(){var n,r,o,i;return po(this,function(s){switch(s.label){case 0:n=t.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,Zt(n.read())];case 3:return r=s.sent(),o=r.value,i=r.done,i?[4,Zt(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,Zt(o)];case 6:return[4,s.sent()];case 7:return s.sent(),[3,2];case 8:return[3,10];case 9:return n.releaseLock(),[7];case 10:return[2]}})})}function Io(t){return B(t?.getReader)}function ve(t){if(t instanceof re)return t;if(t!=null){if(_o(t))return Ym(t);if(wo(t))return Km(t);if(Eo(t))return Zm(t);if(To(t))return $c(t);if(ko(t))return Qm(t);if(Io(t))return Jm(t)}throw So(t)}function Ym(t){return new re(function(e){var n=t[Pn]();if(B(n.subscribe))return n.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Km(t){return new re(function(e){for(var n=0;n<t.length&&!e.closed;n++)e.next(t[n]);e.complete()})}function Zm(t){return new re(function(e){t.then(function(n){e.closed||(e.next(n),e.complete())},function(n){return e.error(n)}).then(null,mo)})}function Qm(t){return new re(function(e){var n,r;try{for(var o=gt(t),i=o.next();!i.done;i=o.next()){var s=i.value;if(e.next(s),e.closed)return}}catch(a){n={error:a}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}e.complete()})}function $c(t){return new re(function(e){eg(t,e).catch(function(n){return e.error(n)})})}function Jm(t){return $c(Co(t))}function eg(t,e){var n,r,o,i;return Ic(this,void 0,void 0,function(){var s,a;return po(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),n=Nc(t),l.label=1;case 1:return[4,n.next()];case 2:if(r=l.sent(),!!r.done)return[3,4];if(s=r.value,e.next(s),e.closed)return[2];l.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=l.sent(),o={error:a},[3,11];case 6:return l.trys.push([6,,9,10]),r&&!r.done&&(i=n.return)?[4,i.call(n)]:[3,8];case 7:l.sent(),l.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}})})}function Ve(t,e,n,r,o){r===void 0&&(r=0),o===void 0&&(o=!1);var i=e.schedule(function(){n(),o?t.add(this.schedule(null,r)):this.unsubscribe()},r);if(t.add(i),!o)return i}function Ro(t,e){return e===void 0&&(e=0),fe(function(n,r){n.subscribe(ge(r,function(o){return Ve(r,t,function(){return r.next(o)},e)},function(){return Ve(r,t,function(){return r.complete()},e)},function(o){return Ve(r,t,function(){return r.error(o)},e)}))})}function No(t,e){return e===void 0&&(e=0),fe(function(n,r){r.add(t.schedule(function(){return n.subscribe(r)},e))})}function Bc(t,e){return ve(t).pipe(No(e),Ro(e))}function Vc(t,e){return ve(t).pipe(No(e),Ro(e))}function jc(t,e){return new re(function(n){var r=0;return e.schedule(function(){r===t.length?n.complete():(n.next(t[r++]),n.closed||this.schedule())})})}function qc(t,e){return new re(function(n){var r;return Ve(n,e,function(){r=t[Ao](),Ve(n,e,function(){var o,i,s;try{o=r.next(),i=o.value,s=o.done}catch(a){n.error(a);return}s?n.complete():n.next(i)},0,!0)}),function(){return B(r?.return)&&r.return()}})}function Oo(t,e){if(!t)throw new Error("Iterable cannot be null");return new re(function(n){Ve(n,e,function(){var r=t[Symbol.asyncIterator]();Ve(n,e,function(){r.next().then(function(o){o.done?n.complete():n.next(o.value)})},0,!0)})})}function Wc(t,e){return Oo(Co(t),e)}function Xc(t,e){if(t!=null){if(_o(t))return Bc(t,e);if(wo(t))return jc(t,e);if(Eo(t))return Vc(t,e);if(To(t))return Oo(t,e);if(ko(t))return qc(t,e);if(Io(t))return Wc(t,e)}throw So(t)}function Jt(t,e){return e?Xc(t,e):ve(t)}function ue(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Gc(t);return Jt(t,n)}function oe(t,e){var n=B(t)?t:function(){return t},r=function(o){return o.error(n())};return new re(e?function(o){return e.schedule(r,0,o)}:r)}var Yc=Nn(function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}});function Mo(t,e){var n=typeof e=="object";return new Promise(function(r,o){var i=!1,s;t.subscribe({next:function(a){s=a,i=!0},error:o,complete:function(){i?r(s):n?r(e.defaultValue):o(new Yc)}})})}function en(t,e){return fe(function(n,r){var o=0;n.subscribe(ge(r,function(i){r.next(t.call(e,i,o++))}))})}function Kc(t,e,n,r,o,i,s,a){var l=[],c=0,u=0,m=!1,y=function(){m&&!l.length&&!c&&e.complete()},f=function(g){return c<r?h(g):l.push(g)},h=function(g){i&&e.next(g),c++;var x=!1;ve(n(g,u++)).subscribe(ge(e,function(S){o?.(S),i?f(S):e.next(S)},function(){x=!0},void 0,function(){if(x)try{c--;for(var S=function(){var _=l.shift();s?Ve(e,s,function(){return h(_)}):h(_)};l.length&&c<r;)S();y()}catch(_){e.error(_)}}))};return t.subscribe(ge(e,f,function(){m=!0,y()})),function(){a?.()}}function Le(t,e,n){return n===void 0&&(n=1/0),B(e)?Le(function(r,o){return en(function(i,s){return e(r,i,o,s)})(ve(t(r,o)))},n):(typeof e=="number"&&(n=e),fe(function(r,o){return Kc(r,o,t,n)}))}function Ks(t){return t===void 0&&(t=1/0),Le(Dn,t)}function Lo(t){return new re(function(e){ve(t()).subscribe(e)})}function ar(t){return fe(function(e,n){var r=null,o=!1,i;r=e.subscribe(ge(n,void 0,void 0,function(s){i=ve(t(s,ar(t)(e))),r?(r.unsubscribe(),r=null,i.subscribe(n)):o=!0})),o&&(r.unsubscribe(),r=null,i.subscribe(n))})}function Po(t,e){return B(e)?Le(t,e,1):Le(t,1)}function Zs(t){return fe(function(e,n){var r=!1;e.subscribe(ge(n,function(o){r=!0,n.next(o)},function(){r||n.next(t),n.complete()}))})}function tn(t){return fe(function(e,n){try{e.subscribe(n)}finally{n.add(t)}})}function Qs(t,e){return fe(function(n,r){var o=null,i=0,s=!1,a=function(){return s&&!o&&r.complete()};n.subscribe(ge(r,function(l){o?.unsubscribe();var c=0,u=i++;ve(t(l,u)).subscribe(o=ge(r,function(m){return r.next(e?e(l,m,u,c++):m)},function(){o=null,a()}))},function(){s=!0,a()}))})}function Do(t){return fe(function(e,n){ve(t).subscribe(ge(n,function(){return n.complete()},ir)),!n.closed&&e.subscribe(n)})}function Js(t,e,n){var r=B(t)||e||n?{next:t,error:e,complete:n}:t;return r?fe(function(o,i){var s;(s=r.subscribe)===null||s===void 0||s.call(r);var a=!0;o.subscribe(ge(i,function(l){var c;(c=r.next)===null||c===void 0||c.call(r,l),i.next(l)},function(){var l;a=!1,(l=r.complete)===null||l===void 0||l.call(r),i.complete()},function(l){var c;a=!1,(c=r.error)===null||c===void 0||c.call(r,l),i.error(l)},function(){var l,c;a&&((l=r.unsubscribe)===null||l===void 0||l.call(r)),(c=r.finalize)===null||c===void 0||c.call(r)}))}):Dn}function Zc(t){return` \r
5
+ `.indexOf(t)>=0}function Uo(t){for(var e=["topLevel"],n=0,r,o,i,s=function(_){return e.push(_)},a=function(_){return e[e.length-1]=_},l=function(_){r==null&&(r=n,o=e.length,i=_)},c=function(_){_===i&&(r=void 0,o=void 0,i=void 0)},u=function(){return e.pop()},m=function(){return n--},y=function(_){if("0"<=_&&_<="9"){s("number");return}switch(_){case'"':s("string");return;case"-":s("numberNeedsDigit");return;case"t":s("true");return;case"f":s("false");return;case"n":s("null");return;case"[":s("arrayNeedsValue");return;case"{":s("objectNeedsKey");return}},f=t.length;n<f;n++){var h=t[n];switch(e[e.length-1]){case"topLevel":y(h);break;case"string":switch(h){case'"':u();break;case"\\":l("stringEscape"),s("stringEscaped");break}break;case"stringEscaped":h==="u"?s("stringUnicode"):(c("stringEscape"),u());break;case"stringUnicode":n-t.lastIndexOf("u",n)===4&&(c("stringEscape"),u());break;case"number":h==="."?a("numberNeedsDigit"):h==="e"||h==="E"?a("numberNeedsExponent"):(h<"0"||h>"9")&&(m(),u());break;case"numberNeedsDigit":a("number");break;case"numberNeedsExponent":a(h==="+"||h==="-"?"numberNeedsDigit":"number");break;case"true":case"false":case"null":(h<"a"||h>"z")&&(m(),u());break;case"arrayNeedsValue":h==="]"?u():Zc(h)||(c("collectionItem"),a("arrayNeedsComma"),y(h));break;case"arrayNeedsComma":h==="]"?u():h===","&&(l("collectionItem"),a("arrayNeedsValue"));break;case"objectNeedsKey":h==="}"?u():h==='"'&&(l("collectionItem"),a("objectNeedsColon"),s("string"));break;case"objectNeedsColon":h===":"&&a("objectNeedsValue");break;case"objectNeedsValue":Zc(h)||(c("collectionItem"),a("objectNeedsComma"),y(h));break;case"objectNeedsComma":h==="}"?u():h===","&&(l("collectionItem"),a("objectNeedsKey"));break}}o!=null&&(e.length=o);for(var g=[r!=null?t.slice(0,r):t],x=function(_){return g.push(_.slice(t.length-t.lastIndexOf(_[0])))},S=e.length-1;S>=0;S--)switch(e[S]){case"string":g.push('"');break;case"numberNeedsDigit":case"numberNeedsExponent":g.push("0");break;case"true":x("true");break;case"false":x("false");break;case"null":x("null");break;case"arrayNeedsValue":case"arrayNeedsComma":g.push("]");break;case"objectNeedsKey":case"objectNeedsColon":case"objectNeedsValue":case"objectNeedsComma":g.push("}");break}return g.join("")}function Jc(){let t=0,e=0;for(let r=0;r<28;r+=7){let o=this.buf[this.pos++];if(t|=(o&127)<<r,(o&128)==0)return this.assertBounds(),[t,e]}let n=this.buf[this.pos++];if(t|=(n&15)<<28,e=(n&112)>>4,(n&128)==0)return this.assertBounds(),[t,e];for(let r=3;r<=31;r+=7){let o=this.buf[this.pos++];if(e|=(o&127)<<r,(o&128)==0)return this.assertBounds(),[t,e]}throw new Error("invalid varint")}function Fo(t,e,n){for(let i=0;i<28;i=i+7){let s=t>>>i,a=!(!(s>>>7)&&e==0),l=(a?s|128:s)&255;if(n.push(l),!a)return}let r=t>>>28&15|(e&7)<<4,o=e>>3!=0;if(n.push((o?r|128:r)&255),!!o){for(let i=3;i<31;i=i+7){let s=e>>>i,a=!!(s>>>7),l=(a?s|128:s)&255;if(n.push(l),!a)return}n.push(e>>>31&1)}}var Ho=4294967296;function ea(t){let e=t[0]==="-";e&&(t=t.slice(1));let n=1e6,r=0,o=0;function i(s,a){let l=Number(t.slice(s,a));o*=n,r=r*n+l,r>=Ho&&(o=o+(r/Ho|0),r=r%Ho)}return i(-24,-18),i(-18,-12),i(-12,-6),i(-6),e?td(r,o):na(r,o)}function ed(t,e){let n=na(t,e),r=n.hi&2147483648;r&&(n=td(n.lo,n.hi));let o=ta(n.lo,n.hi);return r?"-"+o:o}function ta(t,e){if({lo:t,hi:e}=tg(t,e),e<=2097151)return String(Ho*e+t);let n=t&16777215,r=(t>>>24|e<<8)&16777215,o=e>>16&65535,i=n+r*6777216+o*6710656,s=r+o*8147497,a=o*2,l=1e7;return i>=l&&(s+=Math.floor(i/l),i%=l),s>=l&&(a+=Math.floor(s/l),s%=l),a.toString()+Qc(s)+Qc(i)}function tg(t,e){return{lo:t>>>0,hi:e>>>0}}function na(t,e){return{lo:t|0,hi:e|0}}function td(t,e){return e=~e,t?t=~t+1:e+=1,na(t,e)}var Qc=t=>{let e=String(t);return"0000000".slice(e.length)+e};function ra(t,e){if(t>=0){for(;t>127;)e.push(t&127|128),t=t>>>7;e.push(t)}else{for(let n=0;n<9;n++)e.push(t&127|128),t=t>>7;e.push(1)}}function nd(){let t=this.buf[this.pos++],e=t&127;if((t&128)==0)return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(t&127)<<7,(t&128)==0)return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(t&127)<<14,(t&128)==0)return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(t&127)<<21,(t&128)==0)return this.assertBounds(),e;t=this.buf[this.pos++],e|=(t&15)<<28;for(let n=5;(t&128)!==0&&n<10;n++)t=this.buf[this.pos++];if((t&128)!=0)throw new Error("invalid varint");return this.assertBounds(),e>>>0}var Ke=ng();function ng(){let t=new DataView(new ArrayBuffer(8));if(typeof BigInt=="function"&&typeof t.getBigInt64=="function"&&typeof t.getBigUint64=="function"&&typeof t.setBigInt64=="function"&&typeof t.setBigUint64=="function"&&(!!globalThis.Deno||!!globalThis.Bun||typeof process!="object"||typeof process.env!="object"||process.env.BUF_BIGINT_DISABLE!=="1")){let n=BigInt("-9223372036854775808"),r=BigInt("9223372036854775807"),o=BigInt("0"),i=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(s){let a=typeof s=="bigint"?s:BigInt(s);if(a>r||a<n)throw new Error(`invalid int64: ${s}`);return a},uParse(s){let a=typeof s=="bigint"?s:BigInt(s);if(a>i||a<o)throw new Error(`invalid uint64: ${s}`);return a},enc(s){return t.setBigInt64(0,this.parse(s),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},uEnc(s){return t.setBigInt64(0,this.uParse(s),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},dec(s,a){return t.setInt32(0,s,!0),t.setInt32(4,a,!0),t.getBigInt64(0,!0)},uDec(s,a){return t.setInt32(0,s,!0),t.setInt32(4,a,!0),t.getBigUint64(0,!0)}}}return{zero:"0",supported:!1,parse(n){return typeof n!="string"&&(n=n.toString()),rd(n),n},uParse(n){return typeof n!="string"&&(n=n.toString()),od(n),n},enc(n){return typeof n!="string"&&(n=n.toString()),rd(n),ea(n)},uEnc(n){return typeof n!="string"&&(n=n.toString()),od(n),ea(n)},dec(n,r){return ed(n,r)},uDec(n,r){return ta(n,r)}}}function rd(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function od(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}var oa=Symbol.for("@bufbuild/protobuf/text-encoding");function ia(){if(globalThis[oa]==null){let t=new globalThis.TextEncoder,e=new globalThis.TextDecoder,n;globalThis[oa]={encodeUtf8(r){return t.encode(r)},decodeUtf8(r,o){return o?(n===void 0&&(n=new globalThis.TextDecoder("utf-8",{fatal:!0})),n.decode(r)):e.decode(r)},checkUtf8(r){try{return encodeURIComponent(r),!0}catch{return!1}}}}return globalThis[oa]}var Ct;(function(t){t[t.Varint=0]="Varint",t[t.Bit64=1]="Bit64",t[t.LengthDelimited=2]="LengthDelimited",t[t.StartGroup=3]="StartGroup",t[t.EndGroup=4]="EndGroup",t[t.Bit32=5]="Bit32"})(Ct||(Ct={}));var rg=34028234663852886e22,og=-34028234663852886e22,ig=4294967295,sg=2147483647,ag=-2147483648,G=class{constructor(e=ia().encodeUtf8){this.encodeUtf8=e,this.stack=[],this.chunks=[],this.buf=[]}finish(){this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]);let e=0;for(let o=0;o<this.chunks.length;o++)e+=this.chunks[o].length;let n=new Uint8Array(e),r=0;for(let o=0;o<this.chunks.length;o++)n.set(this.chunks[o],r),r+=this.chunks[o].length;return this.chunks=[],n}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),n=this.stack.pop();if(!n)throw new Error("invalid state, fork stack empty");return this.chunks=n.chunks,this.buf=n.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,n){return this.uint32((e<<3|n)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(id(e);e>127;)this.buf.push(e&127|128),e=e>>>7;return this.buf.push(e),this}int32(e){return sa(e),ra(e,this.buf),this}bool(e){return this.buf.push(e?1:0),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let n=this.encodeUtf8(e);return this.uint32(n.byteLength),this.raw(n)}float(e){lg(e);let n=new Uint8Array(4);return new DataView(n.buffer).setFloat32(0,e,!0),this.raw(n)}double(e){let n=new Uint8Array(8);return new DataView(n.buffer).setFloat64(0,e,!0),this.raw(n)}fixed32(e){id(e);let n=new Uint8Array(4);return new DataView(n.buffer).setUint32(0,e,!0),this.raw(n)}sfixed32(e){sa(e);let n=new Uint8Array(4);return new DataView(n.buffer).setInt32(0,e,!0),this.raw(n)}sint32(e){return sa(e),e=(e<<1^e>>31)>>>0,ra(e,this.buf),this}sfixed64(e){let n=new Uint8Array(8),r=new DataView(n.buffer),o=Ke.enc(e);return r.setInt32(0,o.lo,!0),r.setInt32(4,o.hi,!0),this.raw(n)}fixed64(e){let n=new Uint8Array(8),r=new DataView(n.buffer),o=Ke.uEnc(e);return r.setInt32(0,o.lo,!0),r.setInt32(4,o.hi,!0),this.raw(n)}int64(e){let n=Ke.enc(e);return Fo(n.lo,n.hi,this.buf),this}sint64(e){let n=Ke.enc(e),r=n.hi>>31,o=n.lo<<1^r,i=(n.hi<<1|n.lo>>>31)^r;return Fo(o,i,this.buf),this}uint64(e){let n=Ke.uEnc(e);return Fo(n.lo,n.hi,this.buf),this}},A=class{constructor(e,n=ia().decodeUtf8){this.decodeUtf8=n,this.varint64=Jc,this.uint32=nd,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength)}tag(){let e=this.pos,n=this.uint32(),r=this.pos-e;if(r>5||r==5&&this.buf[this.pos-1]>15)throw new Error("illegal tag: varint overflows uint32");let o=n>>>3,i=n&7;if(o<=0||i>5)throw new Error("illegal tag: field no "+o+" wire type "+i);return[o,i]}skip(e,n,r=100){let o=this.pos;switch(e){case Ct.Varint:for(;this.buf[this.pos++]&128;);break;case Ct.Bit64:this.pos+=4;case Ct.Bit32:this.pos+=4;break;case Ct.LengthDelimited:let i=this.uint32();this.pos+=i;break;case Ct.StartGroup:if(r<=0)throw new Error("maximum recursion depth reached");for(;;){let[s,a]=this.tag();if(a===Ct.EndGroup){if(n!==void 0&&s!==n)throw new Error("invalid end group tag");break}this.skip(a,s,r-1)}break;default:throw new Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(o,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return Ke.dec(...this.varint64())}uint64(){return Ke.uDec(...this.varint64())}sint64(){let[e,n]=this.varint64(),r=-(e&1);return e=(e>>>1|(n&1)<<31)^r,n=n>>>1^r,Ke.dec(e,n)}bool(){let[e,n]=this.varint64();return e!==0||n!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return Ke.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return Ke.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),n=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(n,n+e)}string(e){return this.decodeUtf8(this.bytes(),e)}};function sa(t){if(typeof t=="string")t=Number(t);else if(typeof t!="number")throw new Error("invalid int32: "+typeof t);if(!Number.isInteger(t)||t>sg||t<ag)throw new Error("invalid int32: "+t)}function id(t){if(typeof t=="string")t=Number(t);else if(typeof t!="number")throw new Error("invalid uint32: "+typeof t);if(!Number.isInteger(t)||t>ig||t<0)throw new Error("invalid uint32: "+t)}function lg(t){if(typeof t=="string"){let e=t;if(t=Number(t),Number.isNaN(t)&&e!=="NaN")throw new Error("invalid float32: "+e)}else if(typeof t!="number")throw new Error("invalid float32: "+typeof t);if(Number.isFinite(t)&&(t>rg||t<og))throw new Error("invalid float32: "+t)}var cg=(function(t){return t[t.NULL_VALUE=0]="NULL_VALUE",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t})({});function aa(){return{fields:{}}}var lr={encode(t,e=new G){return Object.entries(t.fields).forEach(([n,r])=>{r!==void 0&&da.encode({key:n,value:r},e.uint32(10).fork()).join()}),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=aa();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:{if(i!==10)break;let s=da.decode(n,n.uint32());s.value!==void 0&&(o.fields[s.key]=s.value);continue}}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return lr.fromPartial(t??{})},fromPartial(t){let e=aa();return e.fields=Object.entries(t.fields??{}).reduce((n,[r,o])=>(o!==void 0&&(n[r]=o),n),{}),e},wrap(t){let e=aa();if(t!==void 0)for(let n of Object.keys(t))e.fields[n]=t[n];return e},unwrap(t){let e={};if(t.fields)for(let n of Object.keys(t.fields))e[n]=t.fields[n];return e}};function sd(){return{key:"",value:void 0}}var da={encode(t,e=new G){return t.key!==""&&e.uint32(10).string(t.key),t.value!==void 0&&O.encode(O.wrap(t.value),e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=sd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.key=n.string();continue;case 2:if(i!==18)break;o.value=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return da.fromPartial(t??{})},fromPartial(t){let e=sd();return e.key=t.key??"",e.value=t.value??void 0,e}};function la(){return{nullValue:void 0,numberValue:void 0,stringValue:void 0,boolValue:void 0,structValue:void 0,listValue:void 0}}var O={encode(t,e=new G){return t.nullValue!==void 0&&e.uint32(8).int32(t.nullValue),t.numberValue!==void 0&&e.uint32(17).double(t.numberValue),t.stringValue!==void 0&&e.uint32(26).string(t.stringValue),t.boolValue!==void 0&&e.uint32(32).bool(t.boolValue),t.structValue!==void 0&&lr.encode(lr.wrap(t.structValue),e.uint32(42).fork()).join(),t.listValue!==void 0&&cr.encode(cr.wrap(t.listValue),e.uint32(50).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=la();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==8)break;o.nullValue=n.int32();continue;case 2:if(i!==17)break;o.numberValue=n.double();continue;case 3:if(i!==26)break;o.stringValue=n.string();continue;case 4:if(i!==32)break;o.boolValue=n.bool();continue;case 5:if(i!==42)break;o.structValue=lr.unwrap(lr.decode(n,n.uint32()));continue;case 6:if(i!==50)break;o.listValue=cr.unwrap(cr.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return O.fromPartial(t??{})},fromPartial(t){let e=la();return e.nullValue=t.nullValue??void 0,e.numberValue=t.numberValue??void 0,e.stringValue=t.stringValue??void 0,e.boolValue=t.boolValue??void 0,e.structValue=t.structValue??void 0,e.listValue=t.listValue??void 0,e},wrap(t){let e=la();if(t===null)e.nullValue=cg.NULL_VALUE;else if(typeof t=="boolean")e.boolValue=t;else if(typeof t=="number")e.numberValue=t;else if(typeof t=="string")e.stringValue=t;else if(globalThis.Array.isArray(t))e.listValue=t;else if(typeof t=="object")e.structValue=t;else if(typeof t<"u")throw new globalThis.Error("Unsupported any value type: "+typeof t);return e},unwrap(t){if(t.stringValue!==void 0)return t.stringValue;if(t?.numberValue!==void 0)return t.numberValue;if(t?.boolValue!==void 0)return t.boolValue;if(t?.structValue!==void 0)return t.structValue;if(t?.listValue!==void 0)return t.listValue;if(t?.nullValue!==void 0)return null}};function ca(){return{values:[]}}var cr={encode(t,e=new G){for(let n of t.values)O.encode(O.wrap(n),e.uint32(10).fork()).join();return e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=ca();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.values.push(O.unwrap(O.decode(n,n.uint32())));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return cr.fromPartial(t??{})},fromPartial(t){let e=ca();return e.values=t.values?.map(n=>n)||[],e},wrap(t){let e=ca();return e.values=t??[],e},unwrap(t){return t?.hasOwnProperty("values")&&globalThis.Array.isArray(t.values)?t.values:t}},dg=(function(t){return t[t.ADD=0]="ADD",t[t.REMOVE=1]="REMOVE",t[t.REPLACE=2]="REPLACE",t[t.MOVE=3]="MOVE",t[t.COPY=4]="COPY",t[t.TEST=5]="TEST",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t})({});function ad(){return{op:0,path:"",from:void 0,value:void 0}}var Go={encode(t,e=new G){return t.op!==0&&e.uint32(8).int32(t.op),t.path!==""&&e.uint32(18).string(t.path),t.from!==void 0&&e.uint32(26).string(t.from),t.value!==void 0&&O.encode(O.wrap(t.value),e.uint32(34).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=ad();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==8)break;o.op=n.int32();continue;case 2:if(i!==18)break;o.path=n.string();continue;case 3:if(i!==26)break;o.from=n.string();continue;case 4:if(i!==34)break;o.value=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Go.fromPartial(t??{})},fromPartial(t){let e=ad();return e.op=t.op??0,e.path=t.path??"",e.from=t.from??void 0,e.value=t.value??void 0,e}};function ld(){return{id:"",type:"",function:void 0}}var $o={encode(t,e=new G){return t.id!==""&&e.uint32(10).string(t.id),t.type!==""&&e.uint32(18).string(t.type),t.function!==void 0&&Bo.encode(t.function,e.uint32(26).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=ld();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.id=n.string();continue;case 2:if(i!==18)break;o.type=n.string();continue;case 3:if(i!==26)break;o.function=Bo.decode(n,n.uint32());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return $o.fromPartial(t??{})},fromPartial(t){let e=ld();return e.id=t.id??"",e.type=t.type??"",e.function=t.function!==void 0&&t.function!==null?Bo.fromPartial(t.function):void 0,e}};function cd(){return{name:"",arguments:""}}var Bo={encode(t,e=new G){return t.name!==""&&e.uint32(10).string(t.name),t.arguments!==""&&e.uint32(18).string(t.arguments),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=cd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.name=n.string();continue;case 2:if(i!==18)break;o.arguments=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Bo.fromPartial(t??{})},fromPartial(t){let e=cd();return e.name=t.name??"",e.arguments=t.arguments??"",e}};function dd(){return{value:"",mimeType:""}}var Vo={encode(t,e=new G){return t.value!==""&&e.uint32(10).string(t.value),t.mimeType!==""&&e.uint32(18).string(t.mimeType),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=dd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.value=n.string();continue;case 2:if(i!==18)break;o.mimeType=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Vo.fromPartial(t??{})},fromPartial(t){let e=dd();return e.value=t.value??"",e.mimeType=t.mimeType??"",e}};function ud(){return{value:"",mimeType:void 0}}var jo={encode(t,e=new G){return t.value!==""&&e.uint32(10).string(t.value),t.mimeType!==void 0&&e.uint32(18).string(t.mimeType),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=ud();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.value=n.string();continue;case 2:if(i!==18)break;o.mimeType=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return jo.fromPartial(t??{})},fromPartial(t){let e=ud();return e.value=t.value??"",e.mimeType=t.mimeType??void 0,e}};function pd(){return{data:void 0,url:void 0}}var Ue={encode(t,e=new G){return t.data!==void 0&&Vo.encode(t.data,e.uint32(10).fork()).join(),t.url!==void 0&&jo.encode(t.url,e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=pd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.data=Vo.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.url=jo.decode(n,n.uint32());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ue.fromPartial(t??{})},fromPartial(t){let e=pd();return e.data=t.data!==void 0&&t.data!==null?Vo.fromPartial(t.data):void 0,e.url=t.url!==void 0&&t.url!==null?jo.fromPartial(t.url):void 0,e}};function hd(){return{text:""}}var qo={encode(t,e=new G){return t.text!==""&&e.uint32(10).string(t.text),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=hd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.text=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return qo.fromPartial(t??{})},fromPartial(t){let e=hd();return e.text=t.text??"",e}};function fd(){return{source:void 0,metadata:void 0}}var Wo={encode(t,e=new G){return t.source!==void 0&&Ue.encode(t.source,e.uint32(10).fork()).join(),t.metadata!==void 0&&O.encode(O.wrap(t.metadata),e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=fd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Ue.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Wo.fromPartial(t??{})},fromPartial(t){let e=fd();return e.source=t.source!==void 0&&t.source!==null?Ue.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e}};function md(){return{source:void 0,metadata:void 0}}var Xo={encode(t,e=new G){return t.source!==void 0&&Ue.encode(t.source,e.uint32(10).fork()).join(),t.metadata!==void 0&&O.encode(O.wrap(t.metadata),e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=md();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Ue.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Xo.fromPartial(t??{})},fromPartial(t){let e=md();return e.source=t.source!==void 0&&t.source!==null?Ue.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e}};function gd(){return{source:void 0,metadata:void 0}}var Yo={encode(t,e=new G){return t.source!==void 0&&Ue.encode(t.source,e.uint32(10).fork()).join(),t.metadata!==void 0&&O.encode(O.wrap(t.metadata),e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=gd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Ue.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Yo.fromPartial(t??{})},fromPartial(t){let e=gd();return e.source=t.source!==void 0&&t.source!==null?Ue.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e}};function vd(){return{source:void 0,metadata:void 0}}var Ko={encode(t,e=new G){return t.source!==void 0&&Ue.encode(t.source,e.uint32(10).fork()).join(),t.metadata!==void 0&&O.encode(O.wrap(t.metadata),e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=vd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Ue.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ko.fromPartial(t??{})},fromPartial(t){let e=vd();return e.source=t.source!==void 0&&t.source!==null?Ue.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e}};function bd(){return{text:void 0,image:void 0,audio:void 0,video:void 0,document:void 0}}var Zo={encode(t,e=new G){return t.text!==void 0&&qo.encode(t.text,e.uint32(10).fork()).join(),t.image!==void 0&&Wo.encode(t.image,e.uint32(18).fork()).join(),t.audio!==void 0&&Xo.encode(t.audio,e.uint32(26).fork()).join(),t.video!==void 0&&Yo.encode(t.video,e.uint32(34).fork()).join(),t.document!==void 0&&Ko.encode(t.document,e.uint32(42).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=bd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.text=qo.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.image=Wo.decode(n,n.uint32());continue;case 3:if(i!==26)break;o.audio=Xo.decode(n,n.uint32());continue;case 4:if(i!==34)break;o.video=Yo.decode(n,n.uint32());continue;case 5:if(i!==42)break;o.document=Ko.decode(n,n.uint32());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Zo.fromPartial(t??{})},fromPartial(t){let e=bd();return e.text=t.text!==void 0&&t.text!==null?qo.fromPartial(t.text):void 0,e.image=t.image!==void 0&&t.image!==null?Wo.fromPartial(t.image):void 0,e.audio=t.audio!==void 0&&t.audio!==null?Xo.fromPartial(t.audio):void 0,e.video=t.video!==void 0&&t.video!==null?Yo.fromPartial(t.video):void 0,e.document=t.document!==void 0&&t.document!==null?Ko.fromPartial(t.document):void 0,e}};function yd(){return{id:"",role:"",content:void 0,name:void 0,toolCalls:[],toolCallId:void 0,error:void 0,contentParts:[]}}var Qo={encode(t,e=new G){t.id!==""&&e.uint32(10).string(t.id),t.role!==""&&e.uint32(18).string(t.role),t.content!==void 0&&e.uint32(26).string(t.content),t.name!==void 0&&e.uint32(34).string(t.name);for(let n of t.toolCalls)$o.encode(n,e.uint32(42).fork()).join();t.toolCallId!==void 0&&e.uint32(50).string(t.toolCallId),t.error!==void 0&&e.uint32(58).string(t.error);for(let n of t.contentParts)Zo.encode(n,e.uint32(66).fork()).join();return e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=yd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.id=n.string();continue;case 2:if(i!==18)break;o.role=n.string();continue;case 3:if(i!==26)break;o.content=n.string();continue;case 4:if(i!==34)break;o.name=n.string();continue;case 5:if(i!==42)break;o.toolCalls.push($o.decode(n,n.uint32()));continue;case 6:if(i!==50)break;o.toolCallId=n.string();continue;case 7:if(i!==58)break;o.error=n.string();continue;case 8:if(i!==66)break;o.contentParts.push(Zo.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Qo.fromPartial(t??{})},fromPartial(t){let e=yd();return e.id=t.id??"",e.role=t.role??"",e.content=t.content??void 0,e.name=t.name??void 0,e.toolCalls=t.toolCalls?.map(n=>$o.fromPartial(n))||[],e.toolCallId=t.toolCallId??void 0,e.error=t.error??void 0,e.contentParts=t.contentParts?.map(n=>Zo.fromPartial(n))||[],e}};function xd(){return{id:"",reason:"",message:void 0,toolCallId:void 0,responseSchema:void 0,expiresAt:void 0,metadata:void 0}}var Jo={encode(t,e=new G){return t.id!==""&&e.uint32(10).string(t.id),t.reason!==""&&e.uint32(18).string(t.reason),t.message!==void 0&&e.uint32(26).string(t.message),t.toolCallId!==void 0&&e.uint32(34).string(t.toolCallId),t.responseSchema!==void 0&&O.encode(O.wrap(t.responseSchema),e.uint32(42).fork()).join(),t.expiresAt!==void 0&&e.uint32(50).string(t.expiresAt),t.metadata!==void 0&&O.encode(O.wrap(t.metadata),e.uint32(58).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=xd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.id=n.string();continue;case 2:if(i!==18)break;o.reason=n.string();continue;case 3:if(i!==26)break;o.message=n.string();continue;case 4:if(i!==34)break;o.toolCallId=n.string();continue;case 5:if(i!==42)break;o.responseSchema=O.unwrap(O.decode(n,n.uint32()));continue;case 6:if(i!==50)break;o.expiresAt=n.string();continue;case 7:if(i!==58)break;o.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Jo.fromPartial(t??{})},fromPartial(t){let e=xd();return e.id=t.id??"",e.reason=t.reason??"",e.message=t.message??void 0,e.toolCallId=t.toolCallId??void 0,e.responseSchema=t.responseSchema??void 0,e.expiresAt=t.expiresAt??void 0,e.metadata=t.metadata??void 0,e}},ug=(function(t){return t[t.TEXT_MESSAGE_START=0]="TEXT_MESSAGE_START",t[t.TEXT_MESSAGE_CONTENT=1]="TEXT_MESSAGE_CONTENT",t[t.TEXT_MESSAGE_END=2]="TEXT_MESSAGE_END",t[t.TOOL_CALL_START=3]="TOOL_CALL_START",t[t.TOOL_CALL_ARGS=4]="TOOL_CALL_ARGS",t[t.TOOL_CALL_END=5]="TOOL_CALL_END",t[t.STATE_SNAPSHOT=6]="STATE_SNAPSHOT",t[t.STATE_DELTA=7]="STATE_DELTA",t[t.MESSAGES_SNAPSHOT=8]="MESSAGES_SNAPSHOT",t[t.RAW=9]="RAW",t[t.CUSTOM=10]="CUSTOM",t[t.RUN_STARTED=11]="RUN_STARTED",t[t.RUN_FINISHED=12]="RUN_FINISHED",t[t.RUN_ERROR=13]="RUN_ERROR",t[t.STEP_STARTED=14]="STEP_STARTED",t[t.STEP_FINISHED=15]="STEP_FINISHED",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t})({});function wd(){return{type:0,timestamp:void 0,rawEvent:void 0}}var M={encode(t,e=new G){return t.type!==0&&e.uint32(8).int32(t.type),t.timestamp!==void 0&&e.uint32(16).int64(t.timestamp),t.rawEvent!==void 0&&O.encode(O.wrap(t.rawEvent),e.uint32(26).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=wd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==8)break;o.type=n.int32();continue;case 2:if(i!==16)break;o.timestamp=pg(n.int64());continue;case 3:if(i!==26)break;o.rawEvent=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return M.fromPartial(t??{})},fromPartial(t){let e=wd();return e.type=t.type??0,e.timestamp=t.timestamp??void 0,e.rawEvent=t.rawEvent??void 0,e}};function Ed(){return{baseEvent:void 0,messageId:"",role:void 0,name:void 0}}var ei={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.messageId!==""&&e.uint32(18).string(t.messageId),t.role!==void 0&&e.uint32(26).string(t.role),t.name!==void 0&&e.uint32(34).string(t.name),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Ed();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue;case 3:if(i!==26)break;o.role=n.string();continue;case 4:if(i!==34)break;o.name=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ei.fromPartial(t??{})},fromPartial(t){let e=Ed();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messageId=t.messageId??"",e.role=t.role??void 0,e.name=t.name??void 0,e}};function _d(){return{baseEvent:void 0,messageId:"",delta:""}}var ti={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.messageId!==""&&e.uint32(18).string(t.messageId),t.delta!==""&&e.uint32(26).string(t.delta),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=_d();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue;case 3:if(i!==26)break;o.delta=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ti.fromPartial(t??{})},fromPartial(t){let e=_d();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messageId=t.messageId??"",e.delta=t.delta??"",e}};function Td(){return{baseEvent:void 0,messageId:""}}var ni={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.messageId!==""&&e.uint32(18).string(t.messageId),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Td();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ni.fromPartial(t??{})},fromPartial(t){let e=Td();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messageId=t.messageId??"",e}};function Sd(){return{baseEvent:void 0,toolCallId:"",toolCallName:"",parentMessageId:void 0}}var ri={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.toolCallId!==""&&e.uint32(18).string(t.toolCallId),t.toolCallName!==""&&e.uint32(26).string(t.toolCallName),t.parentMessageId!==void 0&&e.uint32(34).string(t.parentMessageId),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Sd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue;case 3:if(i!==26)break;o.toolCallName=n.string();continue;case 4:if(i!==34)break;o.parentMessageId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ri.fromPartial(t??{})},fromPartial(t){let e=Sd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.toolCallId=t.toolCallId??"",e.toolCallName=t.toolCallName??"",e.parentMessageId=t.parentMessageId??void 0,e}};function Ad(){return{baseEvent:void 0,toolCallId:"",delta:""}}var oi={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.toolCallId!==""&&e.uint32(18).string(t.toolCallId),t.delta!==""&&e.uint32(26).string(t.delta),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Ad();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue;case 3:if(i!==26)break;o.delta=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return oi.fromPartial(t??{})},fromPartial(t){let e=Ad();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.toolCallId=t.toolCallId??"",e.delta=t.delta??"",e}};function kd(){return{baseEvent:void 0,toolCallId:""}}var ii={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.toolCallId!==""&&e.uint32(18).string(t.toolCallId),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=kd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ii.fromPartial(t??{})},fromPartial(t){let e=kd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.toolCallId=t.toolCallId??"",e}};function Cd(){return{baseEvent:void 0,snapshot:void 0}}var si={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.snapshot!==void 0&&O.encode(O.wrap(t.snapshot),e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Cd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.snapshot=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return si.fromPartial(t??{})},fromPartial(t){let e=Cd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.snapshot=t.snapshot??void 0,e}};function Id(){return{baseEvent:void 0,delta:[]}}var ai={encode(t,e=new G){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join();for(let n of t.delta)Go.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Id();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.delta.push(Go.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ai.fromPartial(t??{})},fromPartial(t){let e=Id();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.delta=t.delta?.map(n=>Go.fromPartial(n))||[],e}};function Rd(){return{baseEvent:void 0,messages:[]}}var li={encode(t,e=new G){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join();for(let n of t.messages)Qo.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Rd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messages.push(Qo.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return li.fromPartial(t??{})},fromPartial(t){let e=Rd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messages=t.messages?.map(n=>Qo.fromPartial(n))||[],e}};function Nd(){return{baseEvent:void 0,event:void 0,source:void 0}}var ci={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.event!==void 0&&O.encode(O.wrap(t.event),e.uint32(18).fork()).join(),t.source!==void 0&&e.uint32(26).string(t.source),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Nd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.event=O.unwrap(O.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.source=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ci.fromPartial(t??{})},fromPartial(t){let e=Nd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.event=t.event??void 0,e.source=t.source??void 0,e}};function Od(){return{baseEvent:void 0,name:"",value:void 0}}var di={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.name!==""&&e.uint32(18).string(t.name),t.value!==void 0&&O.encode(O.wrap(t.value),e.uint32(26).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Od();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.name=n.string();continue;case 3:if(i!==26)break;o.value=O.unwrap(O.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return di.fromPartial(t??{})},fromPartial(t){let e=Od();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.name=t.name??"",e.value=t.value??void 0,e}};function Md(){return{baseEvent:void 0,threadId:"",runId:""}}var ui={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.threadId!==""&&e.uint32(18).string(t.threadId),t.runId!==""&&e.uint32(26).string(t.runId),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Md();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.threadId=n.string();continue;case 3:if(i!==26)break;o.runId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ui.fromPartial(t??{})},fromPartial(t){let e=Md();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.threadId=t.threadId??"",e.runId=t.runId??"",e}};function Ld(){return{baseEvent:void 0,threadId:"",runId:"",result:void 0,outcome:"",interrupts:[]}}var pi={encode(t,e=new G){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.threadId!==""&&e.uint32(18).string(t.threadId),t.runId!==""&&e.uint32(26).string(t.runId),t.result!==void 0&&O.encode(O.wrap(t.result),e.uint32(34).fork()).join(),t.outcome!==""&&e.uint32(42).string(t.outcome);for(let n of t.interrupts)Jo.encode(n,e.uint32(50).fork()).join();return e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Ld();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.threadId=n.string();continue;case 3:if(i!==26)break;o.runId=n.string();continue;case 4:if(i!==34)break;o.result=O.unwrap(O.decode(n,n.uint32()));continue;case 5:if(i!==42)break;o.outcome=n.string();continue;case 6:if(i!==50)break;o.interrupts.push(Jo.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return pi.fromPartial(t??{})},fromPartial(t){let e=Ld();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.threadId=t.threadId??"",e.runId=t.runId??"",e.result=t.result??void 0,e.outcome=t.outcome??"",e.interrupts=t.interrupts?.map(n=>Jo.fromPartial(n))||[],e}};function Pd(){return{baseEvent:void 0,code:void 0,message:""}}var hi={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.code!==void 0&&e.uint32(18).string(t.code),t.message!==""&&e.uint32(26).string(t.message),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Pd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.code=n.string();continue;case 3:if(i!==26)break;o.message=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return hi.fromPartial(t??{})},fromPartial(t){let e=Pd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.code=t.code??void 0,e.message=t.message??"",e}};function Dd(){return{baseEvent:void 0,stepName:""}}var fi={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.stepName!==""&&e.uint32(18).string(t.stepName),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Dd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.stepName=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return fi.fromPartial(t??{})},fromPartial(t){let e=Dd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.stepName=t.stepName??"",e}};function Ud(){return{baseEvent:void 0,stepName:""}}var mi={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.stepName!==""&&e.uint32(18).string(t.stepName),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Ud();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.stepName=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return mi.fromPartial(t??{})},fromPartial(t){let e=Ud();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.stepName=t.stepName??"",e}};function Hd(){return{baseEvent:void 0,messageId:void 0,role:void 0,delta:void 0,name:void 0}}var gi={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.messageId!==void 0&&e.uint32(18).string(t.messageId),t.role!==void 0&&e.uint32(26).string(t.role),t.delta!==void 0&&e.uint32(34).string(t.delta),t.name!==void 0&&e.uint32(42).string(t.name),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Hd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue;case 3:if(i!==26)break;o.role=n.string();continue;case 4:if(i!==34)break;o.delta=n.string();continue;case 5:if(i!==42)break;o.name=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return gi.fromPartial(t??{})},fromPartial(t){let e=Hd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messageId=t.messageId??void 0,e.role=t.role??void 0,e.delta=t.delta??void 0,e.name=t.name??void 0,e}};function Fd(){return{baseEvent:void 0,toolCallId:void 0,toolCallName:void 0,parentMessageId:void 0,delta:void 0}}var vi={encode(t,e=new G){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.toolCallId!==void 0&&e.uint32(18).string(t.toolCallId),t.toolCallName!==void 0&&e.uint32(26).string(t.toolCallName),t.parentMessageId!==void 0&&e.uint32(34).string(t.parentMessageId),t.delta!==void 0&&e.uint32(42).string(t.delta),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=Fd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue;case 3:if(i!==26)break;o.toolCallName=n.string();continue;case 4:if(i!==34)break;o.parentMessageId=n.string();continue;case 5:if(i!==42)break;o.delta=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return vi.fromPartial(t??{})},fromPartial(t){let e=Fd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.toolCallId=t.toolCallId??void 0,e.toolCallName=t.toolCallName??void 0,e.parentMessageId=t.parentMessageId??void 0,e.delta=t.delta??void 0,e}};function zd(){return{textMessageStart:void 0,textMessageContent:void 0,textMessageEnd:void 0,toolCallStart:void 0,toolCallArgs:void 0,toolCallEnd:void 0,stateSnapshot:void 0,stateDelta:void 0,messagesSnapshot:void 0,raw:void 0,custom:void 0,runStarted:void 0,runFinished:void 0,runError:void 0,stepStarted:void 0,stepFinished:void 0,textMessageChunk:void 0,toolCallChunk:void 0}}var Gd={encode(t,e=new G){return t.textMessageStart!==void 0&&ei.encode(t.textMessageStart,e.uint32(10).fork()).join(),t.textMessageContent!==void 0&&ti.encode(t.textMessageContent,e.uint32(18).fork()).join(),t.textMessageEnd!==void 0&&ni.encode(t.textMessageEnd,e.uint32(26).fork()).join(),t.toolCallStart!==void 0&&ri.encode(t.toolCallStart,e.uint32(34).fork()).join(),t.toolCallArgs!==void 0&&oi.encode(t.toolCallArgs,e.uint32(42).fork()).join(),t.toolCallEnd!==void 0&&ii.encode(t.toolCallEnd,e.uint32(50).fork()).join(),t.stateSnapshot!==void 0&&si.encode(t.stateSnapshot,e.uint32(58).fork()).join(),t.stateDelta!==void 0&&ai.encode(t.stateDelta,e.uint32(66).fork()).join(),t.messagesSnapshot!==void 0&&li.encode(t.messagesSnapshot,e.uint32(74).fork()).join(),t.raw!==void 0&&ci.encode(t.raw,e.uint32(82).fork()).join(),t.custom!==void 0&&di.encode(t.custom,e.uint32(90).fork()).join(),t.runStarted!==void 0&&ui.encode(t.runStarted,e.uint32(98).fork()).join(),t.runFinished!==void 0&&pi.encode(t.runFinished,e.uint32(106).fork()).join(),t.runError!==void 0&&hi.encode(t.runError,e.uint32(114).fork()).join(),t.stepStarted!==void 0&&fi.encode(t.stepStarted,e.uint32(122).fork()).join(),t.stepFinished!==void 0&&mi.encode(t.stepFinished,e.uint32(130).fork()).join(),t.textMessageChunk!==void 0&&gi.encode(t.textMessageChunk,e.uint32(138).fork()).join(),t.toolCallChunk!==void 0&&vi.encode(t.toolCallChunk,e.uint32(146).fork()).join(),e},decode(t,e){let n=t instanceof A?t:new A(t),r=e===void 0?n.len:n.pos+e,o=zd();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.textMessageStart=ei.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.textMessageContent=ti.decode(n,n.uint32());continue;case 3:if(i!==26)break;o.textMessageEnd=ni.decode(n,n.uint32());continue;case 4:if(i!==34)break;o.toolCallStart=ri.decode(n,n.uint32());continue;case 5:if(i!==42)break;o.toolCallArgs=oi.decode(n,n.uint32());continue;case 6:if(i!==50)break;o.toolCallEnd=ii.decode(n,n.uint32());continue;case 7:if(i!==58)break;o.stateSnapshot=si.decode(n,n.uint32());continue;case 8:if(i!==66)break;o.stateDelta=ai.decode(n,n.uint32());continue;case 9:if(i!==74)break;o.messagesSnapshot=li.decode(n,n.uint32());continue;case 10:if(i!==82)break;o.raw=ci.decode(n,n.uint32());continue;case 11:if(i!==90)break;o.custom=di.decode(n,n.uint32());continue;case 12:if(i!==98)break;o.runStarted=ui.decode(n,n.uint32());continue;case 13:if(i!==106)break;o.runFinished=pi.decode(n,n.uint32());continue;case 14:if(i!==114)break;o.runError=hi.decode(n,n.uint32());continue;case 15:if(i!==122)break;o.stepStarted=fi.decode(n,n.uint32());continue;case 16:if(i!==130)break;o.stepFinished=mi.decode(n,n.uint32());continue;case 17:if(i!==138)break;o.textMessageChunk=gi.decode(n,n.uint32());continue;case 18:if(i!==146)break;o.toolCallChunk=vi.decode(n,n.uint32());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Gd.fromPartial(t??{})},fromPartial(t){let e=zd();return e.textMessageStart=t.textMessageStart!==void 0&&t.textMessageStart!==null?ei.fromPartial(t.textMessageStart):void 0,e.textMessageContent=t.textMessageContent!==void 0&&t.textMessageContent!==null?ti.fromPartial(t.textMessageContent):void 0,e.textMessageEnd=t.textMessageEnd!==void 0&&t.textMessageEnd!==null?ni.fromPartial(t.textMessageEnd):void 0,e.toolCallStart=t.toolCallStart!==void 0&&t.toolCallStart!==null?ri.fromPartial(t.toolCallStart):void 0,e.toolCallArgs=t.toolCallArgs!==void 0&&t.toolCallArgs!==null?oi.fromPartial(t.toolCallArgs):void 0,e.toolCallEnd=t.toolCallEnd!==void 0&&t.toolCallEnd!==null?ii.fromPartial(t.toolCallEnd):void 0,e.stateSnapshot=t.stateSnapshot!==void 0&&t.stateSnapshot!==null?si.fromPartial(t.stateSnapshot):void 0,e.stateDelta=t.stateDelta!==void 0&&t.stateDelta!==null?ai.fromPartial(t.stateDelta):void 0,e.messagesSnapshot=t.messagesSnapshot!==void 0&&t.messagesSnapshot!==null?li.fromPartial(t.messagesSnapshot):void 0,e.raw=t.raw!==void 0&&t.raw!==null?ci.fromPartial(t.raw):void 0,e.custom=t.custom!==void 0&&t.custom!==null?di.fromPartial(t.custom):void 0,e.runStarted=t.runStarted!==void 0&&t.runStarted!==null?ui.fromPartial(t.runStarted):void 0,e.runFinished=t.runFinished!==void 0&&t.runFinished!==null?pi.fromPartial(t.runFinished):void 0,e.runError=t.runError!==void 0&&t.runError!==null?hi.fromPartial(t.runError):void 0,e.stepStarted=t.stepStarted!==void 0&&t.stepStarted!==null?fi.fromPartial(t.stepStarted):void 0,e.stepFinished=t.stepFinished!==void 0&&t.stepFinished!==null?mi.fromPartial(t.stepFinished):void 0,e.textMessageChunk=t.textMessageChunk!==void 0&&t.textMessageChunk!==null?gi.fromPartial(t.textMessageChunk):void 0,e.toolCallChunk=t.toolCallChunk!==void 0&&t.toolCallChunk!==null?vi.fromPartial(t.toolCallChunk):void 0,e}};function pg(t){let e=globalThis.Number(t.toString());if(e>globalThis.Number.MAX_SAFE_INTEGER)throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");if(e<globalThis.Number.MIN_SAFE_INTEGER)throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");return e}var zo=t=>{if(!(!t||typeof t!="object")){if(t.data)return{type:"data",value:t.data.value,mimeType:t.data.mimeType};if(t.url)return{type:"url",value:t.url.value,mimeType:t.url.mimeType}}},hg=t=>{if(!(!t||typeof t!="object")){if(t.text)return{type:"text",text:t.text.text};if(t.image)return{type:"image",source:zo(t.image.source),metadata:t.image.metadata};if(t.audio)return{type:"audio",source:zo(t.audio.source),metadata:t.audio.metadata};if(t.video)return{type:"video",source:zo(t.video.source),metadata:t.video.metadata};if(t.document)return{type:"document",source:zo(t.document.source),metadata:t.document.metadata}}};function $d(t){let e=Gd.decode(t),n=Object.values(e).find(r=>r!==void 0);if(!n)throw new Error("Invalid event");if(n.type=ug[n.baseEvent.type],n.timestamp=n.baseEvent.timestamp,n.rawEvent=n.baseEvent.rawEvent,delete n.baseEvent,n.type===v.MESSAGES_SNAPSHOT)for(let r of n.messages){let o=r;if(o.role==="user"&&Array.isArray(o.contentParts)){let i=o.contentParts.map(s=>hg(s)).filter(s=>s!==void 0);i.length>0&&(o.content=i)}Array.isArray(o.contentParts)&&o.contentParts.length===0&&(o.contentParts=void 0),o.toolCalls?.length===0&&(o.toolCalls=void 0)}if(n.type===v.RUN_FINISHED){let r=n,o=typeof r.outcome=="string"&&r.outcome!==""?r.outcome:void 0,i=Array.isArray(r.interrupts)?r.interrupts:[];delete r.interrupts,o==="interrupt"?r.outcome={type:"interrupt",interrupts:i}:o==="success"?r.outcome={type:"success"}:delete r.outcome}if(n.type===v.STATE_DELTA)for(let r of n.delta)r.op=dg[r.op].toLowerCase(),Object.keys(r).forEach(o=>{r[o]===void 0&&delete r[o]});return Object.keys(n).forEach(r=>{n[r]===void 0&&delete n[r]}),no.parse(n)}var ua="application/vnd.ag-ui.event+proto";var mg=/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i,pa=t=>{if(typeof t!="string")throw new TypeError("Invalid argument expected string");let e=t.match(mg);if(!e)throw new Error(`Invalid argument not valid semver ('${t}' received)`);return e.shift(),e},Bd=t=>t==="*"||t==="x"||t==="X",Vd=t=>{let e=parseInt(t,10);return isNaN(e)?t:e},gg=(t,e)=>typeof t!=typeof e?[String(t),String(e)]:[t,e],vg=(t,e)=>{if(Bd(t)||Bd(e))return 0;let[n,r]=gg(Vd(t),Vd(e));return n>r?1:n<r?-1:0},ha=(t,e)=>{for(let n=0;n<Math.max(t.length,e.length);n++){let r=vg(t[n]||"0",e[n]||"0");if(r!==0)return r}return 0};var dr=(t,e)=>{let n=pa(t),r=pa(e),o=n.pop(),i=r.pop(),s=ha(n,r);return s!==0?s:o&&i?ha(o.split("."),i.split(".")):o||i?o?-1:1:0};var q=t=>{if(typeof structuredClone=="function")return structuredClone(t);try{return JSON.parse(JSON.stringify(t))}catch{return Array.isArray(t)?[...t]:{...t}}};function _e(){return _t()}function ga(t){if(Object.freeze(t),typeof t=="object"&&t)for(let e of Object.values(t))typeof e=="object"&&e&&!Object.isFrozen(e)&&ga(e);return t}var jd=512*1024;function qd(t,e,n){let r=0,o=[t,e],i=new WeakSet;for(;o.length>0;){let s=o.pop();if(typeof s=="string"){if(r+=s.length,r>n)return!0}else if(typeof s=="object"&&s){if(i.has(s))continue;if(i.add(s),Array.isArray(s))for(let a=0;a<s.length;a++)o.push(s[a]);else{let a=Object.keys(s);for(let l=0;l<a.length;l++){let c=a[l];if(r+=c.length,r>n)return!0;o.push(s[c])}}}}return!1}async function K(t,e,n,r){let o=typeof process<"u"&&process.env!==void 0,i=o&&!!process.env.VITEST_WORKER_ID,s=o&&!!process.env.VITEST_WORKER_ID,a=s&&!qd(e,n,jd),l=a?q(e):e,c=a?q(n):n,u=!1,m=!1,y;for(let f of t)try{a&&(ga(l),ga(c));let h=await r(f,l,c);if(h===void 0)continue;let g=!1;if(h.messages!==void 0&&h.messages!==l&&(l=q(h.messages),u=!0,g=!0),h.state!==void 0&&h.state!==c&&(c=q(h.state),m=!0,g=!0),a&&g&&qd(l,c,jd)&&(a=!1),y=h.stopPropagation,y===!0)break}catch(h){if(s&&h instanceof TypeError){if(i)throw h;console.error("AG-UI: Subscriber attempted to mutate frozen inputs in-place. Return mutations via AgentStateMutation instead of mutating directly.",h)}else i||console.error("Subscriber error:",h);continue}return{...u?{messages:Object.isFrozen(l)?q(l):l}:{},...m?{state:Object.isFrozen(c)?q(c):c}:{},...y===void 0?{}:{stopPropagation:y}}}function bi(t){if(!t)return{enabled:!1,events:!1,lifecycle:!1,verbose:!1};if(t===!0)return{enabled:!0,events:!0,lifecycle:!0,verbose:!0};let e=t.events??!0,n=t.lifecycle??!0,r=t.verbose??!1;return{enabled:e||n,events:e,lifecycle:n,verbose:r}}function ur(t){if(t instanceof va)return t;if(t===!0)return new va(bi(!0))}var va=class{constructor(t){this.config=t}event(t,e,n,r){this.config.events&&(this.config.verbose?console.debug(`[${t}] ${e}`,typeof n=="string"?n:JSON.stringify(n)):console.debug(`[${t}] ${e}`,r??n))}lifecycle(t,e,n){this.config.lifecycle&&(n?console.debug(`[${t}] ${e}`,n):console.debug(`[${t}] ${e}`))}get eventsEnabled(){return this.config.events}get lifecycleEnabled(){return this.config.lifecycle}get enabled(){return this.config.enabled}};function fa(t){return t.enabled?new va(t):void 0}function bg(t,e,n){if(e){let o=t.find(s=>s.id===e);if(o?.role==="assistant")return o;o&&console.warn(`TOOL_CALL_START: parentMessageId '${e}' matches a '${o.role}' message, not assistant \u2014 falling back to toolCallId`);let i={id:o?n:e,role:"assistant",toolCalls:[]};return t.push(i),i}let r={id:n,role:"assistant",toolCalls:[]};return t.push(r),r}var Qd=(t,e,n,r,o)=>{let i=ur(o),s=q(n.messages),a=q(t.state),l={},c=m=>{m.messages!==void 0&&(s=m.messages,l.messages=m.messages),m.state!==void 0&&(a=m.state,l.state=m.state)},u=()=>{let m=q(l);return l={},m.messages!==void 0||m.state!==void 0?ue(m):xo};return e.pipe(Po(async m=>{let y=await K(r,s,a,(f,h,g)=>f.onEvent?.({event:m,agent:n,input:t,messages:h,state:g}));if(c(y),y.stopPropagation===!0?i?.event("APPLY","Event dropped:",m,{type:m.type,reason:"stopPropagation by subscriber"}):i?.event("APPLY","Event applied:",m,{type:m.type,subscribers:r.length}),y.stopPropagation===!0)return u();switch(m.type){case v.TEXT_MESSAGE_START:{let f=await K(r,s,a,(h,g,x)=>h.onTextMessageStartEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let{messageId:h,role:g="assistant",name:x}=m;if(!s.find(S=>S.id===h)){let S={id:h,role:g,content:"",...x!==void 0&&{name:x}};s.push(S),c({messages:s})}}return u()}case v.TEXT_MESSAGE_CONTENT:{let{messageId:f,delta:h}=m,g=s.find(S=>S.id===f);if(!g)return console.warn(`TEXT_MESSAGE_CONTENT: No message found with ID '${f}'`),u();let x=await K(r,s,a,(S,_,I)=>S.onTextMessageContentEvent?.({event:m,messages:_,state:I,agent:n,input:t,textMessageBuffer:typeof g.content=="string"?g.content:""}));return c(x),x.stopPropagation!==!0&&(g.content=`${typeof g.content=="string"?g.content:""}${h}`,c({messages:s})),u()}case v.TEXT_MESSAGE_END:{let{messageId:f}=m,h=s.find(g=>g.id===f);return h?(c(await K(r,s,a,(g,x,S)=>g.onTextMessageEndEvent?.({event:m,messages:x,state:S,agent:n,input:t,textMessageBuffer:typeof h.content=="string"?h.content:""}))),await Promise.all(r.map(g=>{g.onNewMessage?.({message:h,messages:s,state:a,agent:n,input:t})})),u()):(console.warn(`TEXT_MESSAGE_END: No message found with ID '${f}'`),u())}case v.TOOL_CALL_START:{let f=await K(r,s,a,(h,g,x)=>h.onToolCallStartEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let{toolCallId:h,toolCallName:g,parentMessageId:x}=m,S=bg(s,x,h);S.toolCalls??=[],S.toolCalls.push({id:h,type:"function",function:{name:g,arguments:""}}),c({messages:s})}return u()}case v.TOOL_CALL_ARGS:{let{toolCallId:f,delta:h}=m,g=s.find(_=>_.toolCalls?.some(I=>I.id===f));if(!g)return console.warn(`TOOL_CALL_ARGS: No message found containing tool call with ID '${f}'`),u();let x=g.toolCalls?.find(_=>_.id===f);if(!x)return console.warn(`TOOL_CALL_ARGS: No tool call found with ID '${f}'`),u();let S=await K(r,s,a,(_,I,H)=>{let U=x.function.arguments,Y=x.function.name,ie={};try{ie=Uo(U)}catch{}return _.onToolCallArgsEvent?.({event:m,messages:I,state:H,agent:n,input:t,toolCallBuffer:U,toolCallName:Y,partialToolCallArgs:ie})});return c(S),S.stopPropagation!==!0&&(x.function.arguments+=h,c({messages:s})),u()}case v.TOOL_CALL_END:{let{toolCallId:f}=m,h=s.find(x=>x.toolCalls?.some(S=>S.id===f));if(!h)return console.warn(`TOOL_CALL_END: No message found containing tool call with ID '${f}'`),u();let g=h.toolCalls?.find(x=>x.id===f);return g?(c(await K(r,s,a,(x,S,_)=>{let I=g.function.arguments,H=g.function.name,U={};try{U=JSON.parse(I)}catch{}return x.onToolCallEndEvent?.({event:m,messages:S,state:_,agent:n,input:t,toolCallName:H,toolCallArgs:U})})),await Promise.all(r.map(x=>{x.onNewToolCall?.({toolCall:g,messages:s,state:a,agent:n,input:t})})),u()):(console.warn(`TOOL_CALL_END: No tool call found with ID '${f}'`),u())}case v.TOOL_CALL_RESULT:{let f=await K(r,s,a,(h,g,x)=>h.onToolCallResultEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let{messageId:h,toolCallId:g,content:x,role:S}=m,_={id:h,toolCallId:g,role:S||"tool",content:x},I=s.findIndex(H=>H.role==="assistant"&&H.toolCalls?.some(U=>U.id===g));if(I===-1)s.push(_);else{let H=I+1;for(;H<s.length&&s[H].role==="tool";)H++;s.splice(H,0,_)}await Promise.all(r.map(H=>{H.onNewMessage?.({message:_,messages:s,state:a,agent:n,input:t})})),c({messages:s})}return u()}case v.STATE_SNAPSHOT:{let f=await K(r,s,a,(h,g,x)=>h.onStateSnapshotEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let{snapshot:h}=m;a=h,c({state:a})}return u()}case v.STATE_DELTA:{let f=await K(r,s,a,(h,g,x)=>h.onStateDeltaEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let{delta:h}=m;try{a=uo.applyPatch(a,h,!0,!1).newDocument,c({state:a})}catch(g){let x=g instanceof Error?g.message:String(g);console.warn(`Failed to apply state patch:
6
6
  Current state: ${JSON.stringify(a,null,2)}
7
7
  Patch operations: ${JSON.stringify(h,null,2)}
8
- Error: ${x}`)}}return u()}case v.MESSAGES_SNAPSHOT:{let f=await Y(r,s,a,(h,g,x)=>h.onMessagesSnapshotEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let{messages:h}=m,g=new Map(h.map(I=>[I.id,I])),x=h.some(I=>I.role==="reasoning"),S=I=>I.role==="activity"||I.role==="reasoning"&&!x;s=s.filter(I=>S(I)||g.has(I.id)).map(I=>S(I)?I:g.get(I.id));let _=new Set(s.map(I=>I.id));for(let I of h)_.has(I.id)||s.push(I);c({messages:s})}return u()}case v.ACTIVITY_SNAPSHOT:{let f=m,h=s.findIndex(I=>I.id===f.messageId),g=h>=0?s[h]:void 0,x=g?.role==="activity"?g:void 0,S=f.replace??!0,_=await Y(r,s,a,(I,H,U)=>I.onActivitySnapshotEvent?.({event:f,messages:H,state:U,agent:n,input:t,activityMessage:x,existingMessage:g}));if(c(_),_.stopPropagation!==!0){let I={id:f.messageId,role:"activity",activityType:f.activityType,content:q(f.content)},H;h===-1?(s.push(I),H=I):x?S&&(s[h]={...x,activityType:f.activityType,content:q(f.content)}):S&&(s[h]=I,H=I),c({messages:s}),H&&await Promise.all(r.map(U=>U.onNewMessage?.({message:H,messages:s,state:a,agent:n,input:t})))}return u()}case v.ACTIVITY_DELTA:{let f=m,h=s.findIndex(_=>_.id===f.messageId);if(h===-1)return u();let g=s[h];if(g.role!=="activity")return console.warn(`ACTIVITY_DELTA: Message '${f.messageId}' is not an activity message`),u();let x=g,S=await Y(r,s,a,(_,I,H)=>_.onActivityDeltaEvent?.({event:f,messages:I,state:H,agent:n,input:t,activityMessage:x}));if(c(S),S.stopPropagation!==!0)try{let _=q(x.content??{}),I=ao.applyPatch(_,f.patch??[],!0,!1).newDocument;s[h]={...x,content:q(I),activityType:f.activityType},c({messages:s})}catch(_){let I=_ instanceof Error?_.message:String(_);console.warn(`Failed to apply activity patch for '${f.messageId}': ${I}`)}return u()}case v.RAW:return c(await Y(r,s,a,(f,h,g)=>f.onRawEvent?.({event:m,messages:h,state:g,agent:n,input:t}))),u();case v.CUSTOM:return c(await Y(r,s,a,(f,h,g)=>f.onCustomEvent?.({event:m,messages:h,state:g,agent:n,input:t}))),u();case v.RUN_STARTED:{let f=await Y(r,s,a,(h,g,x)=>h.onRunStartedEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let h=m;if(h.input?.messages){for(let g of h.input.messages)s.find(x=>x.id===g.id)||s.push(g);c({messages:s})}}return u()}case v.RUN_FINISHED:{let f=m,h=f.outcome?.type==="interrupt"?{event:f,outcome:"interrupt",interrupts:f.outcome.interrupts}:{event:f,outcome:"success",result:f.result},g=await Y(r,s,a,(x,S,_)=>x.onRunFinishedEvent?.({...h,messages:S,state:_,agent:n,input:t}));return c(g),g.stopPropagation!==!0&&(n.pendingInterrupts=h.outcome==="interrupt"?[...h.interrupts]:[]),u()}case v.RUN_ERROR:return c(await Y(r,s,a,(f,h,g)=>f.onRunErrorEvent?.({event:m,messages:h,state:g,agent:n,input:t}))),u();case v.STEP_STARTED:return c(await Y(r,s,a,(f,h,g)=>f.onStepStartedEvent?.({event:m,messages:h,state:g,agent:n,input:t}))),u();case v.STEP_FINISHED:return c(await Y(r,s,a,(f,h,g)=>f.onStepFinishedEvent?.({event:m,messages:h,state:g,agent:n,input:t}))),u();case v.TEXT_MESSAGE_CHUNK:throw Error("TEXT_MESSAGE_CHUNK must be tranformed before being applied");case v.TOOL_CALL_CHUNK:throw Error("TOOL_CALL_CHUNK must be tranformed before being applied");case v.THINKING_START:return u();case v.THINKING_END:return u();case v.THINKING_TEXT_MESSAGE_START:return u();case v.THINKING_TEXT_MESSAGE_CONTENT:return u();case v.THINKING_TEXT_MESSAGE_END:return u();case v.REASONING_START:return c(await Y(r,s,a,(f,h,g)=>f.onReasoningStartEvent?.({event:m,messages:h,state:g,agent:n,input:t}))),u();case v.REASONING_MESSAGE_START:{let f=await Y(r,s,a,(h,g,x)=>h.onReasoningMessageStartEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let{messageId:h}=m;if(!s.find(g=>g.id===h)){let g={id:h,role:"reasoning",content:""};s.push(g),c({messages:s})}}return u()}case v.REASONING_MESSAGE_CONTENT:{let{messageId:f,delta:h}=m,g=s.find(S=>S.id===f);if(!g)return console.warn(`REASONING_MESSAGE_CONTENT: No message found with ID '${f}'`),u();let x=await Y(r,s,a,(S,_,I)=>S.onReasoningMessageContentEvent?.({event:m,messages:_,state:I,agent:n,input:t,reasoningMessageBuffer:typeof g.content=="string"?g.content:""}));return c(x),x.stopPropagation!==!0&&(g.content=`${typeof g.content=="string"?g.content:""}${h}`,c({messages:s})),u()}case v.REASONING_MESSAGE_END:{let{messageId:f}=m,h=s.find(g=>g.id===f);return h?(c(await Y(r,s,a,(g,x,S)=>g.onReasoningMessageEndEvent?.({event:m,messages:x,state:S,agent:n,input:t,reasoningMessageBuffer:typeof h.content=="string"?h.content:""}))),await Promise.all(r.map(g=>{g.onNewMessage?.({message:h,messages:s,state:a,agent:n,input:t})})),u()):(console.warn(`REASONING_MESSAGE_END: No message found with ID '${f}'`),u())}case v.REASONING_MESSAGE_CHUNK:throw Error("REASONING_MESSAGE_CHUNK must be transformed before being applied");case v.REASONING_END:return c(await Y(r,s,a,(f,h,g)=>f.onReasoningEndEvent?.({event:m,messages:h,state:g,agent:n,input:t}))),u();case v.REASONING_ENCRYPTED_VALUE:{let{subtype:f,entityId:h,encryptedValue:g}=m,x=await Y(r,s,a,(S,_,I)=>S.onReasoningEncryptedValueEvent?.({event:m,messages:_,state:I,agent:n,input:t}));if(c(x),x.stopPropagation!==!0){let S=!1;if(f==="tool-call"){for(let _ of s)if(_.role==="assistant"&&_.toolCalls){let I=_.toolCalls.find(H=>H.id===h);if(I){I.encryptedValue=g,S=!0;break}}}else{let _=s.find(I=>I.id===h);_?.role!=="activity"&&_&&(_.encryptedValue=g,S=!0)}S&&(l.messages=s)}return u()}}return m.type,u()}),Ws(),r.length>0?Xs({}):m=>m)},pa=t=>e=>{let n=cr(t),r=new Map,o=new Map,i=!1,s=!1,a=!1,l=new Map,c=!1,u=!1,m=!1,y=()=>{r.clear(),o.clear(),l.clear(),c=!1,u=!1,i=!1,s=!1,m=!0};return e.pipe(Le(f=>{let h=f.type;if(n?.event("VERIFY","Event:",f,{type:f.type}),s)return re(()=>new te(`Cannot send event type '${h}': The run has already errored with 'RUN_ERROR'. No further events can be sent.`));if(i&&h!==v.RUN_ERROR&&h!==v.RUN_STARTED)return re(()=>new te(`Cannot send event type '${h}': The run has already finished with 'RUN_FINISHED'. Start a new run with 'RUN_STARTED'.`));if(a){if(h===v.RUN_STARTED){if(m&&!i)return re(()=>new te("Cannot send 'RUN_STARTED' while a run is still active. The previous run must be finished with 'RUN_FINISHED' before starting a new run."));i&&y()}}else if(a=!0,h!==v.RUN_STARTED&&h!==v.RUN_ERROR)return re(()=>new te("First event must be 'RUN_STARTED'"));switch(h){case v.TEXT_MESSAGE_START:{let g=f.messageId;return r.has(g)?re(()=>new te(`Cannot send 'TEXT_MESSAGE_START' event: A text message with ID '${g}' is already in progress. Complete it with 'TEXT_MESSAGE_END' first.`)):(r.set(g,!0),ue(f))}case v.TEXT_MESSAGE_CONTENT:{let g=f.messageId;return r.has(g)?ue(f):re(()=>new te(`Cannot send 'TEXT_MESSAGE_CONTENT' event: No active text message found with ID '${g}'. Start a text message with 'TEXT_MESSAGE_START' first.`))}case v.TEXT_MESSAGE_END:{let g=f.messageId;return r.has(g)?(r.delete(g),ue(f)):re(()=>new te(`Cannot send 'TEXT_MESSAGE_END' event: No active text message found with ID '${g}'. A 'TEXT_MESSAGE_START' event must be sent first.`))}case v.TOOL_CALL_START:{let g=f.toolCallId;return o.has(g)?re(()=>new te(`Cannot send 'TOOL_CALL_START' event: A tool call with ID '${g}' is already in progress. Complete it with 'TOOL_CALL_END' first.`)):(o.set(g,!0),ue(f))}case v.TOOL_CALL_ARGS:{let g=f.toolCallId;return o.has(g)?ue(f):re(()=>new te(`Cannot send 'TOOL_CALL_ARGS' event: No active tool call found with ID '${g}'. Start a tool call with 'TOOL_CALL_START' first.`))}case v.TOOL_CALL_END:{let g=f.toolCallId;return o.has(g)?(o.delete(g),ue(f)):re(()=>new te(`Cannot send 'TOOL_CALL_END' event: No active tool call found with ID '${g}'. A 'TOOL_CALL_START' event must be sent first.`))}case v.STEP_STARTED:{let g=f.stepName;return l.has(g)?re(()=>new te(`Step "${g}" is already active for 'STEP_STARTED'`)):(l.set(g,!0),ue(f))}case v.STEP_FINISHED:{let g=f.stepName;return l.has(g)?(l.delete(g),ue(f)):re(()=>new te(`Cannot send 'STEP_FINISHED' for step "${g}" that was not started`))}case v.RUN_STARTED:return m=!0,ue(f);case v.RUN_FINISHED:if(l.size>0){let g=Array.from(l.keys()).join(", ");return re(()=>new te(`Cannot send 'RUN_FINISHED' while steps are still active: ${g}`))}if(r.size>0){let g=Array.from(r.keys()).join(", ");return re(()=>new te(`Cannot send 'RUN_FINISHED' while text messages are still active: ${g}`))}if(o.size>0){let g=Array.from(o.keys()).join(", ");return re(()=>new te(`Cannot send 'RUN_FINISHED' while tool calls are still active: ${g}`))}return i=!0,ue(f);case v.RUN_ERROR:return s=!0,ue(f);case v.CUSTOM:return ue(f);case v.THINKING_TEXT_MESSAGE_START:return c?u?re(()=>new te("Cannot send 'THINKING_TEXT_MESSAGE_START' event: A thinking message is already in progress. Complete it with 'THINKING_TEXT_MESSAGE_END' first.")):(u=!0,ue(f)):re(()=>new te("Cannot send 'THINKING_TEXT_MESSAGE_START' event: A thinking step is not in progress. Create one with 'THINKING_START' first."));case v.THINKING_TEXT_MESSAGE_CONTENT:return u?ue(f):re(()=>new te("Cannot send 'THINKING_TEXT_MESSAGE_CONTENT' event: No active thinking message found. Start a message with 'THINKING_TEXT_MESSAGE_START' first."));case v.THINKING_TEXT_MESSAGE_END:return u?(u=!1,ue(f)):re(()=>new te("Cannot send 'THINKING_TEXT_MESSAGE_END' event: No active thinking message found. A 'THINKING_TEXT_MESSAGE_START' event must be sent first."));case v.THINKING_START:return c?re(()=>new te("Cannot send 'THINKING_START' event: A thinking step is already in progress. End it with 'THINKING_END' first.")):(c=!0,ue(f));case v.THINKING_END:return c?(c=!1,ue(f)):re(()=>new te("Cannot send 'THINKING_END' event: No active thinking step found. A 'THINKING_START' event must be sent first."));default:return ue(f)}}))},nn=(function(t){return t.HEADERS="headers",t.DATA="data",t})({}),pg=t=>No(()=>Jt(t())).pipe(Ks(e=>{if(!e.ok){let o=e.headers.get("content-type")||"";return Jt(e.text()).pipe(Le(i=>{let s=i;if(o.includes("application/json"))try{s=JSON.parse(i)}catch{}let a=Error(`HTTP ${e.status}: ${typeof s=="string"?s:JSON.stringify(s)}`);return a.status=e.status,a.payload=s,re(()=>a)}))}let n={type:nn.HEADERS,status:e.status,headers:e.headers},r=e.body?.getReader();return r?new ne(o=>(o.next(n),(async()=>{try{for(;;){let{done:i,value:s}=await r.read();if(i)break;let a={type:nn.DATA,data:s};o.next(a)}o.complete()}catch(i){o.error(i)}})(),()=>{r.cancel().catch(i=>{if(i?.name!=="AbortError")throw i})})):re(()=>Error("Failed to getReader() from response"))})),hg=(t,e)=>{let n=cr(e),r=new ct,o=new TextDecoder("utf-8",{fatal:!1}),i="";t.subscribe({next:a=>{if(a.type!==nn.HEADERS&&a.type===nn.DATA&&a.data){let l=o.decode(a.data,{stream:!0});i+=l;let c=i.split(/\n\n/);i=c.pop()||"";for(let u of c)s(u)}},error:a=>r.error(a),complete:()=>{i&&(i+=o.decode(),s(i)),r.complete()}});function s(a){let l=a.split(`
8
+ Error: ${x}`)}}return u()}case v.MESSAGES_SNAPSHOT:{let f=await K(r,s,a,(h,g,x)=>h.onMessagesSnapshotEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let{messages:h}=m,g=new Map(h.map(I=>[I.id,I])),x=h.some(I=>I.role==="reasoning"),S=I=>I.role==="activity"||I.role==="reasoning"&&!x;s=s.filter(I=>S(I)||g.has(I.id)).map(I=>S(I)?I:g.get(I.id));let _=new Set(s.map(I=>I.id));for(let I of h)_.has(I.id)||s.push(I);c({messages:s})}return u()}case v.ACTIVITY_SNAPSHOT:{let f=m,h=s.findIndex(I=>I.id===f.messageId),g=h>=0?s[h]:void 0,x=g?.role==="activity"?g:void 0,S=f.replace??!0,_=await K(r,s,a,(I,H,U)=>I.onActivitySnapshotEvent?.({event:f,messages:H,state:U,agent:n,input:t,activityMessage:x,existingMessage:g}));if(c(_),_.stopPropagation!==!0){let I={id:f.messageId,role:"activity",activityType:f.activityType,content:q(f.content)},H;h===-1?(s.push(I),H=I):x?S&&(s[h]={...x,activityType:f.activityType,content:q(f.content)}):S&&(s[h]=I,H=I),c({messages:s}),H&&await Promise.all(r.map(U=>U.onNewMessage?.({message:H,messages:s,state:a,agent:n,input:t})))}return u()}case v.ACTIVITY_DELTA:{let f=m,h=s.findIndex(_=>_.id===f.messageId);if(h===-1)return u();let g=s[h];if(g.role!=="activity")return console.warn(`ACTIVITY_DELTA: Message '${f.messageId}' is not an activity message`),u();let x=g,S=await K(r,s,a,(_,I,H)=>_.onActivityDeltaEvent?.({event:f,messages:I,state:H,agent:n,input:t,activityMessage:x}));if(c(S),S.stopPropagation!==!0)try{let _=q(x.content??{}),I=uo.applyPatch(_,f.patch??[],!0,!1).newDocument;s[h]={...x,content:q(I),activityType:f.activityType},c({messages:s})}catch(_){let I=_ instanceof Error?_.message:String(_);console.warn(`Failed to apply activity patch for '${f.messageId}': ${I}`)}return u()}case v.RAW:return c(await K(r,s,a,(f,h,g)=>f.onRawEvent?.({event:m,messages:h,state:g,agent:n,input:t}))),u();case v.CUSTOM:return c(await K(r,s,a,(f,h,g)=>f.onCustomEvent?.({event:m,messages:h,state:g,agent:n,input:t}))),u();case v.RUN_STARTED:{let f=await K(r,s,a,(h,g,x)=>h.onRunStartedEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let h=m;if(h.input?.messages){for(let g of h.input.messages)s.find(x=>x.id===g.id)||s.push(g);c({messages:s})}}return u()}case v.RUN_FINISHED:{let f=m,h=f.outcome?.type==="interrupt"?{event:f,outcome:"interrupt",interrupts:f.outcome.interrupts}:{event:f,outcome:"success",result:f.result},g=await K(r,s,a,(x,S,_)=>x.onRunFinishedEvent?.({...h,messages:S,state:_,agent:n,input:t}));return c(g),g.stopPropagation!==!0&&(n.pendingInterrupts=h.outcome==="interrupt"?[...h.interrupts]:[]),u()}case v.RUN_ERROR:return c(await K(r,s,a,(f,h,g)=>f.onRunErrorEvent?.({event:m,messages:h,state:g,agent:n,input:t}))),u();case v.STEP_STARTED:return c(await K(r,s,a,(f,h,g)=>f.onStepStartedEvent?.({event:m,messages:h,state:g,agent:n,input:t}))),u();case v.STEP_FINISHED:return c(await K(r,s,a,(f,h,g)=>f.onStepFinishedEvent?.({event:m,messages:h,state:g,agent:n,input:t}))),u();case v.TEXT_MESSAGE_CHUNK:throw Error("TEXT_MESSAGE_CHUNK must be tranformed before being applied");case v.TOOL_CALL_CHUNK:throw Error("TOOL_CALL_CHUNK must be tranformed before being applied");case v.THINKING_START:return u();case v.THINKING_END:return u();case v.THINKING_TEXT_MESSAGE_START:return u();case v.THINKING_TEXT_MESSAGE_CONTENT:return u();case v.THINKING_TEXT_MESSAGE_END:return u();case v.REASONING_START:return c(await K(r,s,a,(f,h,g)=>f.onReasoningStartEvent?.({event:m,messages:h,state:g,agent:n,input:t}))),u();case v.REASONING_MESSAGE_START:{let f=await K(r,s,a,(h,g,x)=>h.onReasoningMessageStartEvent?.({event:m,messages:g,state:x,agent:n,input:t}));if(c(f),f.stopPropagation!==!0){let{messageId:h}=m;if(!s.find(g=>g.id===h)){let g={id:h,role:"reasoning",content:""};s.push(g),c({messages:s})}}return u()}case v.REASONING_MESSAGE_CONTENT:{let{messageId:f,delta:h}=m,g=s.find(S=>S.id===f);if(!g)return console.warn(`REASONING_MESSAGE_CONTENT: No message found with ID '${f}'`),u();let x=await K(r,s,a,(S,_,I)=>S.onReasoningMessageContentEvent?.({event:m,messages:_,state:I,agent:n,input:t,reasoningMessageBuffer:typeof g.content=="string"?g.content:""}));return c(x),x.stopPropagation!==!0&&(g.content=`${typeof g.content=="string"?g.content:""}${h}`,c({messages:s})),u()}case v.REASONING_MESSAGE_END:{let{messageId:f}=m,h=s.find(g=>g.id===f);return h?(c(await K(r,s,a,(g,x,S)=>g.onReasoningMessageEndEvent?.({event:m,messages:x,state:S,agent:n,input:t,reasoningMessageBuffer:typeof h.content=="string"?h.content:""}))),await Promise.all(r.map(g=>{g.onNewMessage?.({message:h,messages:s,state:a,agent:n,input:t})})),u()):(console.warn(`REASONING_MESSAGE_END: No message found with ID '${f}'`),u())}case v.REASONING_MESSAGE_CHUNK:throw Error("REASONING_MESSAGE_CHUNK must be transformed before being applied");case v.REASONING_END:return c(await K(r,s,a,(f,h,g)=>f.onReasoningEndEvent?.({event:m,messages:h,state:g,agent:n,input:t}))),u();case v.REASONING_ENCRYPTED_VALUE:{let{subtype:f,entityId:h,encryptedValue:g}=m,x=await K(r,s,a,(S,_,I)=>S.onReasoningEncryptedValueEvent?.({event:m,messages:_,state:I,agent:n,input:t}));if(c(x),x.stopPropagation!==!0){let S=!1;if(f==="tool-call"){for(let _ of s)if(_.role==="assistant"&&_.toolCalls){let I=_.toolCalls.find(H=>H.id===h);if(I){I.encryptedValue=g,S=!0;break}}}else{let _=s.find(I=>I.id===h);_?.role!=="activity"&&_&&(_.encryptedValue=g,S=!0)}S&&(l.messages=s)}return u()}}return m.type,u()}),Ks(),r.length>0?Zs({}):m=>m)},ma=t=>e=>{let n=ur(t),r=new Map,o=new Map,i=!1,s=!1,a=!1,l=new Map,c=!1,u=!1,m=!1,y=()=>{r.clear(),o.clear(),l.clear(),c=!1,u=!1,i=!1,s=!1,m=!0};return e.pipe(Le(f=>{let h=f.type;if(n?.event("VERIFY","Event:",f,{type:f.type}),s)return oe(()=>new ne(`Cannot send event type '${h}': The run has already errored with 'RUN_ERROR'. No further events can be sent.`));if(i&&h!==v.RUN_ERROR&&h!==v.RUN_STARTED)return oe(()=>new ne(`Cannot send event type '${h}': The run has already finished with 'RUN_FINISHED'. Start a new run with 'RUN_STARTED'.`));if(a){if(h===v.RUN_STARTED){if(m&&!i)return oe(()=>new ne("Cannot send 'RUN_STARTED' while a run is still active. The previous run must be finished with 'RUN_FINISHED' before starting a new run."));i&&y()}}else if(a=!0,h!==v.RUN_STARTED&&h!==v.RUN_ERROR)return oe(()=>new ne("First event must be 'RUN_STARTED'"));switch(h){case v.TEXT_MESSAGE_START:{let g=f.messageId;return r.has(g)?oe(()=>new ne(`Cannot send 'TEXT_MESSAGE_START' event: A text message with ID '${g}' is already in progress. Complete it with 'TEXT_MESSAGE_END' first.`)):(r.set(g,!0),ue(f))}case v.TEXT_MESSAGE_CONTENT:{let g=f.messageId;return r.has(g)?ue(f):oe(()=>new ne(`Cannot send 'TEXT_MESSAGE_CONTENT' event: No active text message found with ID '${g}'. Start a text message with 'TEXT_MESSAGE_START' first.`))}case v.TEXT_MESSAGE_END:{let g=f.messageId;return r.has(g)?(r.delete(g),ue(f)):oe(()=>new ne(`Cannot send 'TEXT_MESSAGE_END' event: No active text message found with ID '${g}'. A 'TEXT_MESSAGE_START' event must be sent first.`))}case v.TOOL_CALL_START:{let g=f.toolCallId;return o.has(g)?oe(()=>new ne(`Cannot send 'TOOL_CALL_START' event: A tool call with ID '${g}' is already in progress. Complete it with 'TOOL_CALL_END' first.`)):(o.set(g,!0),ue(f))}case v.TOOL_CALL_ARGS:{let g=f.toolCallId;return o.has(g)?ue(f):oe(()=>new ne(`Cannot send 'TOOL_CALL_ARGS' event: No active tool call found with ID '${g}'. Start a tool call with 'TOOL_CALL_START' first.`))}case v.TOOL_CALL_END:{let g=f.toolCallId;return o.has(g)?(o.delete(g),ue(f)):oe(()=>new ne(`Cannot send 'TOOL_CALL_END' event: No active tool call found with ID '${g}'. A 'TOOL_CALL_START' event must be sent first.`))}case v.STEP_STARTED:{let g=f.stepName;return l.has(g)?oe(()=>new ne(`Step "${g}" is already active for 'STEP_STARTED'`)):(l.set(g,!0),ue(f))}case v.STEP_FINISHED:{let g=f.stepName;return l.has(g)?(l.delete(g),ue(f)):oe(()=>new ne(`Cannot send 'STEP_FINISHED' for step "${g}" that was not started`))}case v.RUN_STARTED:return m=!0,ue(f);case v.RUN_FINISHED:if(l.size>0){let g=Array.from(l.keys()).join(", ");return oe(()=>new ne(`Cannot send 'RUN_FINISHED' while steps are still active: ${g}`))}if(r.size>0){let g=Array.from(r.keys()).join(", ");return oe(()=>new ne(`Cannot send 'RUN_FINISHED' while text messages are still active: ${g}`))}if(o.size>0){let g=Array.from(o.keys()).join(", ");return oe(()=>new ne(`Cannot send 'RUN_FINISHED' while tool calls are still active: ${g}`))}return i=!0,ue(f);case v.RUN_ERROR:return s=!0,ue(f);case v.CUSTOM:return ue(f);case v.THINKING_TEXT_MESSAGE_START:return c?u?oe(()=>new ne("Cannot send 'THINKING_TEXT_MESSAGE_START' event: A thinking message is already in progress. Complete it with 'THINKING_TEXT_MESSAGE_END' first.")):(u=!0,ue(f)):oe(()=>new ne("Cannot send 'THINKING_TEXT_MESSAGE_START' event: A thinking step is not in progress. Create one with 'THINKING_START' first."));case v.THINKING_TEXT_MESSAGE_CONTENT:return u?ue(f):oe(()=>new ne("Cannot send 'THINKING_TEXT_MESSAGE_CONTENT' event: No active thinking message found. Start a message with 'THINKING_TEXT_MESSAGE_START' first."));case v.THINKING_TEXT_MESSAGE_END:return u?(u=!1,ue(f)):oe(()=>new ne("Cannot send 'THINKING_TEXT_MESSAGE_END' event: No active thinking message found. A 'THINKING_TEXT_MESSAGE_START' event must be sent first."));case v.THINKING_START:return c?oe(()=>new ne("Cannot send 'THINKING_START' event: A thinking step is already in progress. End it with 'THINKING_END' first.")):(c=!0,ue(f));case v.THINKING_END:return c?(c=!1,ue(f)):oe(()=>new ne("Cannot send 'THINKING_END' event: No active thinking step found. A 'THINKING_START' event must be sent first."));default:return ue(f)}}))},nn=(function(t){return t.HEADERS="headers",t.DATA="data",t})({}),yg=t=>Lo(()=>Jt(t())).pipe(Qs(e=>{if(!e.ok){let o=e.headers.get("content-type")||"";return Jt(e.text()).pipe(Le(i=>{let s=i;if(o.includes("application/json"))try{s=JSON.parse(i)}catch{}let a=Error(`HTTP ${e.status}: ${typeof s=="string"?s:JSON.stringify(s)}`);return a.status=e.status,a.payload=s,oe(()=>a)}))}let n={type:nn.HEADERS,status:e.status,headers:e.headers},r=e.body?.getReader();return r?new re(o=>(o.next(n),(async()=>{try{for(;;){let{done:i,value:s}=await r.read();if(i)break;let a={type:nn.DATA,data:s};o.next(a)}o.complete()}catch(i){o.error(i)}})(),()=>{r.cancel().catch(i=>{if(i?.name!=="AbortError")throw i})})):oe(()=>Error("Failed to getReader() from response"))})),xg=(t,e)=>{let n=ur(e),r=new ct,o=new TextDecoder("utf-8",{fatal:!1}),i="";t.subscribe({next:a=>{if(a.type!==nn.HEADERS&&a.type===nn.DATA&&a.data){let l=o.decode(a.data,{stream:!0});i+=l;let c=i.split(/\n\n/);i=c.pop()||"";for(let u of c)s(u)}},error:a=>r.error(a),complete:()=>{i&&(i+=o.decode(),s(i)),r.complete()}});function s(a){let l=a.split(`
9
9
  `),c=[];for(let u of l)u.startsWith("data:")&&c.push(u.slice(5).replace(/^ /,""));if(c.length>0)try{let u=c.join(`
10
- `),m=JSON.parse(u);n?.event("SSE","Event received:",m,{type:m.type}),r.next(m)}catch(u){r.error(u)}}return r.asObservable()},fg=t=>{let e=new ct,n=new Uint8Array;t.subscribe({next:o=>{if(o.type!==nn.HEADERS&&o.type===nn.DATA&&o.data){let i=new Uint8Array(n.length+o.data.length);i.set(n,0),i.set(o.data,n.length),n=i,r()}},error:o=>e.error(o),complete:()=>{if(n.length>0)try{r()}catch{console.warn("Incomplete or invalid protocol buffer data at stream end")}e.complete()}});function r(){for(;n.length>=4;){let o=4+new DataView(n.buffer,n.byteOffset,4).getUint32(0,!1);if(n.length<o)break;try{let i=n.slice(4,o),s=Ud(i);e.next(s),n=n.slice(o)}catch(i){let s=i instanceof Error?i.message:String(i);e.error(Error(`Failed to decode protocol buffer message: ${s}`));return}}}return e.asObservable()},mg=(t,e)=>{let n=cr(e),r=new ct,o=new go,i=!1;return t.subscribe({next:s=>{if(o.next(s),s.type===nn.HEADERS&&!i){i=!0;let a=s.headers.get("content-type");n?.lifecycle("HTTP","Stream format detected:",{contentType:a,parser:a===la?"protobuf":"sse"}),a===la?fg(o).subscribe({next:l=>r.next(l),error:l=>r.error(l),complete:()=>r.complete()}):hg(o,n).subscribe({next:l=>{try{let c=Jr.parse(l);n?.event("HTTP","Event validated:",c,{type:c.type,valid:!0}),r.next(c)}catch(c){n?.event("HTTP","Event invalid:",{json:l,error:String(c)}),r.error(c)}},error:l=>{if(l?.name==="AbortError"){r.next({type:v.RUN_ERROR,message:l.message||"Request aborted",code:"abort",rawEvent:l}),r.complete();return}return r.error(l)},complete:()=>r.complete()})}else i||r.error(Error("No headers event received before data events"))},error:s=>{o.error(s),r.error(s)},complete:()=>{o.complete()}}),r.asObservable()},J=d.enum(["TextMessageStart","TextMessageContent","TextMessageEnd","ActionExecutionStart","ActionExecutionArgs","ActionExecutionEnd","ActionExecutionResult","AgentStateMessage","MetaEvent","RunStarted","RunFinished","RunError","NodeStarted","NodeFinished"]),gg=d.enum(["LangGraphInterruptEvent","PredictState","Exit"]),vg=d.object({type:d.literal(J.enum.TextMessageStart),messageId:d.string(),parentMessageId:d.string().optional(),role:d.string().optional()}),bg=d.object({type:d.literal(J.enum.TextMessageContent),messageId:d.string(),content:d.string()}),yg=d.object({type:d.literal(J.enum.TextMessageEnd),messageId:d.string()}),xg=d.object({type:d.literal(J.enum.ActionExecutionStart),actionExecutionId:d.string(),actionName:d.string(),parentMessageId:d.string().optional()}),wg=d.object({type:d.literal(J.enum.ActionExecutionArgs),actionExecutionId:d.string(),args:d.string()}),Eg=d.object({type:d.literal(J.enum.ActionExecutionEnd),actionExecutionId:d.string()}),_g=d.object({type:d.literal(J.enum.ActionExecutionResult),actionName:d.string(),actionExecutionId:d.string(),result:d.string()}),Tg=d.object({type:d.literal(J.enum.AgentStateMessage),threadId:d.string(),agentName:d.string(),nodeName:d.string(),runId:d.string(),active:d.boolean(),role:d.string(),state:d.string(),running:d.boolean()}),Sg=d.object({type:d.literal(J.enum.MetaEvent),name:gg,value:d.any()}),Ag=d.object({type:d.literal(J.enum.RunError),message:d.string(),code:d.string().optional()});d.discriminatedUnion("type",[vg,bg,yg,xg,wg,Eg,_g,Tg,Sg,Ag]),d.object({id:d.string(),role:d.string(),content:d.string(),parentMessageId:d.string().optional()}),d.object({id:d.string(),name:d.string(),arguments:d.any(),parentMessageId:d.string().optional()}),d.object({id:d.string(),result:d.any(),actionExecutionId:d.string(),actionName:d.string()});var kg=t=>{if(typeof t=="string")return t;if(!Array.isArray(t))return;let e=t.filter(n=>n.type==="text").map(n=>n.text).filter(n=>n.length>0);if(e.length!==0)return e.join(`
11
- `)},Cg=(t,e,n)=>r=>{let o={},i=!0,s=!0,a="",l=null,c=null,u=[],m={},y=f=>{typeof f=="object"&&f&&("messages"in f&&delete f.messages,o=f)};return r.pipe(Le(f=>{switch(f.type){case v.TEXT_MESSAGE_START:{let h=f;return[{type:J.enum.TextMessageStart,messageId:h.messageId,role:h.role}]}case v.TEXT_MESSAGE_CONTENT:{let h=f;return[{type:J.enum.TextMessageContent,messageId:h.messageId,content:h.delta}]}case v.TEXT_MESSAGE_END:{let h=f;return[{type:J.enum.TextMessageEnd,messageId:h.messageId}]}case v.TOOL_CALL_START:{let h=f;return u.push({id:h.toolCallId,type:"function",function:{name:h.toolCallName,arguments:""}}),s=!0,m[h.toolCallId]=h.toolCallName,[{type:J.enum.ActionExecutionStart,actionExecutionId:h.toolCallId,actionName:h.toolCallName,parentMessageId:h.parentMessageId}]}case v.TOOL_CALL_ARGS:{let h=f,g=u.find(S=>S.id===h.toolCallId);if(!g)return console.warn(`TOOL_CALL_ARGS: No tool call found with ID '${h.toolCallId}'`),[];g.function.arguments+=h.delta;let x=!1;if(c){let S=c.find(_=>_.tool==g.function.name);if(S)try{let _=JSON.parse(Lo(g.function.arguments));S.tool_argument&&S.tool_argument in _?(y({...o,[S.state_key]:_[S.tool_argument]}),x=!0):S.tool_argument||(y({...o,[S.state_key]:_}),x=!0)}catch{}}return[{type:J.enum.ActionExecutionArgs,actionExecutionId:h.toolCallId,args:h.delta},...x?[{type:J.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:s}]:[]]}case v.TOOL_CALL_END:{let h=f;return[{type:J.enum.ActionExecutionEnd,actionExecutionId:h.toolCallId}]}case v.TOOL_CALL_RESULT:{let h=f;return[{type:J.enum.ActionExecutionResult,actionExecutionId:h.toolCallId,result:h.content,actionName:m[h.toolCallId]||"unknown"}]}case v.RAW:return[];case v.CUSTOM:{let h=f;switch(h.name){case"Exit":i=!1;break;case"PredictState":c=h.value;break}return[{type:J.enum.MetaEvent,name:h.name,value:h.value}]}case v.STATE_SNAPSHOT:return y(f.snapshot),[{type:J.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:s}];case v.STATE_DELTA:{let h=f,g=ao.applyPatch(o,h.delta,!0,!1);return g?(y(g.newDocument),[{type:J.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:s}]):[]}case v.MESSAGES_SNAPSHOT:return l=f.messages,[{type:J.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:i,role:"assistant",state:JSON.stringify({...o,...l?{messages:l}:{}}),active:!0}];case v.RUN_STARTED:return[];case v.RUN_FINISHED:return l&&(o.messages=l),Object.keys(o).length===0?[]:[{type:J.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:i,role:"assistant",state:JSON.stringify({...o,...l?{messages:Ig(l)}:{}}),active:!1}];case v.RUN_ERROR:{let h=f;return[{type:J.enum.RunError,message:h.message,code:h.code}]}case v.STEP_STARTED:return a=f.stepName,u=[],c=null,[{type:J.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:!0}];case v.STEP_FINISHED:return u=[],c=null,[{type:J.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:!1}];default:return[]}}))};function Ig(t){let e=[];for(let n of t)if(n.role==="assistant"||n.role==="user"||n.role==="system"){let r=kg(n.content);if(r){let o={id:n.id,role:n.role,content:r};e.push(o)}if(n.role==="assistant"&&n.toolCalls&&n.toolCalls.length>0)for(let o of n.toolCalls){let i={id:o.id,name:o.function.name,arguments:JSON.parse(o.function.arguments),parentMessageId:n.id};e.push(i)}}else if(n.role==="tool"){let r="unknown";for(let i of t)if(i.role==="assistant"&&i.toolCalls?.length){for(let s of i.toolCalls)if(s.id===n.toolCallId){r=s.function.name;break}}let o={id:n.id,result:n.content,actionExecutionId:n.toolCallId,actionName:r};e.push(o)}return e}var gi=t=>e=>{let n=cr(t),r,o,i,s,a=()=>{if(!r||s!=="text")throw Error("No text message to close");let m={type:v.TEXT_MESSAGE_END,messageId:r.messageId};return s=void 0,r=void 0,n?.event("TRANSFORM","TEXT_MESSAGE_END",m,{messageId:m.messageId}),m},l=()=>{if(!o||s!=="tool")throw Error("No tool call to close");let m={type:v.TOOL_CALL_END,toolCallId:o.toolCallId};return s=void 0,o=void 0,n?.event("TRANSFORM","TOOL_CALL_END",m,{toolCallId:m.toolCallId}),m},c=()=>{if(!i||s!=="reasoning")throw Error("No reasoning message to close");let m={type:v.REASONING_MESSAGE_END,messageId:i.messageId};return s=void 0,i=void 0,n?.event("TRANSFORM","REASONING_MESSAGE_END",m,{messageId:m.messageId}),m},u=()=>s==="text"?[a()]:s==="tool"?[l()]:s==="reasoning"?[c()]:[];return e.pipe(Le(m=>{switch(m.type){case v.TEXT_MESSAGE_START:case v.TEXT_MESSAGE_CONTENT:case v.TEXT_MESSAGE_END:case v.TOOL_CALL_START:case v.TOOL_CALL_ARGS:case v.TOOL_CALL_END:case v.TOOL_CALL_RESULT:case v.STATE_SNAPSHOT:case v.STATE_DELTA:case v.MESSAGES_SNAPSHOT:case v.CUSTOM:case v.RUN_STARTED:case v.RUN_FINISHED:case v.RUN_ERROR:case v.STEP_STARTED:case v.STEP_FINISHED:case v.THINKING_START:case v.THINKING_END:case v.THINKING_TEXT_MESSAGE_START:case v.THINKING_TEXT_MESSAGE_CONTENT:case v.THINKING_TEXT_MESSAGE_END:case v.REASONING_START:case v.REASONING_MESSAGE_START:case v.REASONING_MESSAGE_CONTENT:case v.REASONING_MESSAGE_END:case v.REASONING_END:return[...u(),m];case v.RAW:case v.ACTIVITY_SNAPSHOT:case v.ACTIVITY_DELTA:case v.REASONING_ENCRYPTED_VALUE:return[m];case v.TEXT_MESSAGE_CHUNK:let y=m,f=[];if((s!=="text"||y.messageId!==void 0&&y.messageId!==r?.messageId)&&f.push(...u()),s!=="text"){if(y.messageId===void 0)throw Error("First TEXT_MESSAGE_CHUNK must have a messageId");r={messageId:y.messageId,name:y.name},s="text";let _={type:v.TEXT_MESSAGE_START,messageId:y.messageId,role:y.role||"assistant",...y.name!==void 0&&{name:y.name}};f.push(_),n?.event("TRANSFORM","TEXT_MESSAGE_START",_,{messageId:y.messageId})}if(y.delta!==void 0){let _={type:v.TEXT_MESSAGE_CONTENT,messageId:r.messageId,delta:y.delta};f.push(_),n?.event("TRANSFORM","TEXT_MESSAGE_CONTENT",_,{messageId:r.messageId})}return f;case v.TOOL_CALL_CHUNK:let h=m,g=[];if((s!=="tool"||h.toolCallId!==void 0&&h.toolCallId!==o?.toolCallId)&&g.push(...u()),s!=="tool"){if(h.toolCallId===void 0)throw Error("First TOOL_CALL_CHUNK must have a toolCallId");if(h.toolCallName===void 0)throw Error("First TOOL_CALL_CHUNK must have a toolCallName");o={toolCallId:h.toolCallId,toolCallName:h.toolCallName,parentMessageId:h.parentMessageId},s="tool";let _={type:v.TOOL_CALL_START,toolCallId:h.toolCallId,toolCallName:h.toolCallName,parentMessageId:h.parentMessageId};g.push(_),n?.event("TRANSFORM","TOOL_CALL_START",_,{toolCallId:h.toolCallId,toolCallName:h.toolCallName})}if(h.delta!==void 0){let _={type:v.TOOL_CALL_ARGS,toolCallId:o.toolCallId,delta:h.delta};g.push(_),n?.event("TRANSFORM","TOOL_CALL_ARGS",_,{toolCallId:o.toolCallId})}return g;case v.REASONING_MESSAGE_CHUNK:let x=m,S=[];if((s!=="reasoning"||x.messageId&&x.messageId!==i?.messageId)&&S.push(...u()),s!=="reasoning"){if(x.messageId===void 0)throw Error("First REASONING_MESSAGE_CHUNK must have a messageId");i={messageId:x.messageId},s="reasoning";let _={type:v.REASONING_MESSAGE_START,messageId:x.messageId};S.push(_),n?.event("TRANSFORM","REASONING_MESSAGE_START",_,{messageId:x.messageId})}if(x.delta!==void 0){let _={type:v.REASONING_MESSAGE_CONTENT,messageId:i.messageId,delta:x.delta};S.push(_),n?.event("TRANSFORM","REASONING_MESSAGE_CONTENT",_,{messageId:i.messageId})}return S}return m.type,[]}),tn(()=>{u()}))};function Rg(t,e=new Date){return t.expiresAt===void 0?!1:new Date(t.expiresAt)<=e}function Xd(t,e){let n=new Set(t.map(s=>s.id)),r=new Set(Object.keys(e)),o=[...n].filter(s=>!r.has(s));if(o.length>0)throw Error(`buildResumeArray: missing responses for open interrupts: ${o.join(", ")}`);let i=[...r].filter(s=>!n.has(s));if(i.length>0)throw Error(`buildResumeArray: responses reference unknown interrupt ids: ${i.join(", ")}`);return t.map(s=>{let a=e[s.id];if(a.status==="resolved"){let l={interruptId:s.id,status:"resolved"};return a.payload!==void 0&&(l.payload=a.payload),l}return{interruptId:s.id,status:"cancelled"}})}var vi=class{runNext(t,e){return e.run(t).pipe(gi(!1))}runNextWithState(t,e){let n=q(t.messages||[]),r=q(t.state||{}),o=new go;return Wd(t,o,e,[]).subscribe(i=>{i.messages!==void 0&&(n=i.messages),i.state!==void 0&&(r=i.state)}),this.runNext(t,e).pipe(Oo(async i=>(o.next(i),await new Promise(s=>setTimeout(s,0)),{event:i,messages:q(n),state:q(r)})))}},Ng=class extends vi{constructor(t){super(),this.fn=t}run(t,e){return this.fn(t,e)}};function Og(t){let e=t.content;if(Array.isArray(e)){let n=e.filter(r=>typeof r=="object"&&!!r&&"type"in r&&r.type==="text"&&typeof r.text=="string").map(r=>r.text).join("");return{...t,content:n}}return typeof e=="string"?t:{...t,content:""}}var Mg=class extends vi{run(t,e){let{parentRunId:n,...r}=t,o={...r,messages:r.messages.map(Og)};return this.runNext(o,e)}},$d="THINKING_START",Bd="THINKING_END",Vd="THINKING_TEXT_MESSAGE_START",jd="THINKING_TEXT_MESSAGE_CONTENT",qd="THINKING_TEXT_MESSAGE_END",Lg=class extends vi{constructor(...t){super(...t),this.currentReasoningId=null,this.currentMessageId=null}warnAboutTransformation(t,e){typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(`AG-UI is converting ${t} to ${e}. To remove this warning, upgrade your AG-UI integration package (e.g. @ag-ui/langgraph). To surpress it, set SUPPRESS_TRANSFORMATION_WARNINGS=true in your .env file.`)}run(t,e){return this.currentReasoningId=null,this.currentMessageId=null,this.runNext(t,e).pipe(en(n=>this.transformEvent(n)))}transformEvent(t){switch(t.type){case $d:{this.currentReasoningId=_e();let{title:e,...n}=t;return this.warnAboutTransformation($d,v.REASONING_START),{...n,type:v.REASONING_START,messageId:this.currentReasoningId}}case Vd:return this.currentMessageId=_e(),this.warnAboutTransformation(Vd,v.REASONING_MESSAGE_START),{...t,type:v.REASONING_MESSAGE_START,messageId:this.currentMessageId,role:"assistant"};case jd:{let{delta:e,...n}=t;return this.warnAboutTransformation(jd,v.REASONING_MESSAGE_CONTENT),{...n,type:v.REASONING_MESSAGE_CONTENT,messageId:this.currentMessageId??_e(),delta:e}}case qd:{let e=this.currentMessageId??_e();return this.warnAboutTransformation(qd,v.REASONING_MESSAGE_END),{...t,type:v.REASONING_MESSAGE_END,messageId:e}}case Bd:{let e=this.currentReasoningId??_e();return this.warnAboutTransformation(Bd,v.REASONING_END),{...t,type:v.REASONING_END,messageId:e}}default:return t}}};function Pg(t){return t.startsWith("image/")?"image":t.startsWith("audio/")?"audio":t.startsWith("video/")?"video":"document"}function Dg(t){return typeof t=="object"&&!!t&&"type"in t&&t.type==="binary"&&"mimeType"in t&&typeof t.mimeType=="string"}function Ug(t){let e=Pg(t.mimeType);return t.data?{type:e,source:{type:"data",value:t.data,mimeType:t.mimeType},...t.filename?{metadata:{filename:t.filename}}:{}}:t.url?{type:e,source:{type:"url",value:t.url,mimeType:t.mimeType},...t.filename?{metadata:{filename:t.filename}}:{}}:t}function Hg(t){let e=t.content;if(!Array.isArray(e))return t;let n=e.map(r=>Dg(r)?Ug(r):r);return{...t,content:n}}var zg=class extends vi{run(t,e){let n={...t,messages:t.messages.map(Hg)};return this.runNext(n,e)}},Fg="0.0.57",Gg=class{get maxVersion(){return Fg}get debug(){return this._debug}set debug(t){this._debug=mi(t),this._debugLogger=ua(this._debug)}get debugLogger(){return this._debugLogger}set debugLogger(t){typeof t=="boolean"?this._debugLogger=t?ua(mi(!0)):void 0:this._debugLogger=t}constructor({agentId:t,description:e,threadId:n,initialMessages:r,initialState:o,debug:i}={}){this.subscribers=[],this.isRunning=!1,this.pendingInterrupts=[],this.middlewares=[],this.agentId=t,this.description=e??"",this.threadId=n??_t(),this.messages=q(r??[]),this.state=q(o??{}),this._debug=mi(i),this._debugLogger=ua(this._debug),lr(this.maxVersion,"0.0.39")<=0&&this.middlewares.unshift(new Mg),lr(this.maxVersion,"0.0.45")<=0&&this.middlewares.unshift(new Lg),lr(this.maxVersion,"0.0.47")<=0&&this.middlewares.unshift(new zg)}subscribe(t){return this.subscribers.push(t),{unsubscribe:()=>{this.subscribers=this.subscribers.filter(e=>e!==t)}}}use(...t){let e=t.map(n=>typeof n=="function"?new Ng(n):n);return this.middlewares.push(...e),this}async runAgent(t,e){try{this.isRunning=!0,this.agentId=this.agentId??_t();let n=this.prepareRunAgentInput(t);this.debugLogger?.lifecycle("LIFECYCLE","Run started:",{agentId:this.agentId,threadId:this.threadId});let r,o=new Set(this.messages.map(l=>l.id)),i=[{onRunFinishedEvent:l=>{l.outcome==="success"&&(r=l.result)}},...this.subscribers,e??{}];await this.onInitialize(n,i),this.activeRunDetach$=new ct;let s;this.activeRunCompletionPromise=new Promise(l=>{s=l}),await Ro(mo(()=>this.middlewares.length===0?this.run(n):this.middlewares.reduceRight((l,c)=>({run:u=>c.run(u,l),get messages(){return l.messages},get state(){return l.state}}),this).run(n),gi(this.debugLogger),pa(this.debugLogger),l=>l.pipe(Mo(this.activeRunDetach$)),l=>this.apply(n,l,i),l=>this.processApplyEvents(n,l,i),ir(l=>(this.debugLogger?.lifecycle("LIFECYCLE","Run errored:",{agentId:this.agentId,error:l instanceof Error?l.message:String(l)}),this.isRunning=!1,this.onError(n,l,i))),tn(()=>{this.debugLogger?.lifecycle("LIFECYCLE","Run finished:",{agentId:this.agentId,threadId:this.threadId}),this.isRunning=!1,this.onFinalize(n,i),s?.(),s=void 0,this.activeRunCompletionPromise=void 0,this.activeRunDetach$=void 0}))(ue(null)));let a=q(this.messages).filter(l=>!o.has(l.id));return{result:r,newMessages:a}}finally{this.isRunning=!1}}connect(t){throw new Ls}async connectAgent(t,e){try{this.isRunning=!0,this.agentId=this.agentId??_t();let n=this.prepareRunAgentInput(t),r,o=new Set(this.messages.map(l=>l.id)),i=[{onRunFinishedEvent:l=>{l.outcome==="success"&&(r=l.result)}},...this.subscribers,e??{}];await this.onInitialize(n,i),this.activeRunDetach$=new ct;let s;this.activeRunCompletionPromise=new Promise(l=>{s=l}),await Ro(mo(()=>No(()=>this.connect(n)),gi(this.debugLogger),pa(this.debugLogger),l=>l.pipe(Mo(this.activeRunDetach$)),l=>this.apply(n,l,i),l=>this.processApplyEvents(n,l,i),ir(l=>(this.isRunning=!1,l instanceof Ls?vo:this.onError(n,l,i))),tn(()=>{this.isRunning=!1,this.onFinalize(n,i),s?.(),s=void 0,this.activeRunCompletionPromise=void 0,this.activeRunDetach$=void 0}))(ue(null)),{defaultValue:void 0});let a=q(this.messages).filter(l=>!o.has(l.id));return{result:r,newMessages:a}}finally{this.isRunning=!1}}abortRun(){}async detachActiveRun(){if(!this.activeRunDetach$)return;let t=this.activeRunCompletionPromise??Promise.resolve();this.activeRunDetach$.next(),this.activeRunDetach$?.complete(),await t}apply(t,e,n){return Wd(t,e,this,n,this.debugLogger)}processApplyEvents(t,e,n){return e.pipe(Ys(r=>{r.messages&&(this.messages=r.messages,n.forEach(o=>{o.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:t})})),r.state&&(this.state=r.state,n.forEach(o=>{o.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:t})}))}))}prepareRunAgentInput(t){let e=q(this.messages).filter(n=>n.role!=="activity");return{threadId:this.threadId,runId:t?.runId||_t(),tools:q(t?.tools??[]),context:q(t?.context??[]),forwardedProps:q(t?.forwardedProps??{}),state:q(this.state),messages:e,...t?.resume===void 0?{}:{resume:q(t.resume)}}}async onInitialize(t,e){if(this.pendingInterrupts.length>0){let r=new Set((t.resume??[]).map(i=>i.interruptId)),o=this.pendingInterrupts.map(i=>i.id).filter(i=>!r.has(i));if(o.length>0)throw new te(`Thread has ${o.length} pending interrupt(s) not addressed by resume: ${o.join(", ")}`);for(let i of this.pendingInterrupts)if(Rg(i))throw new te(`Interrupt ${i.id} expired at ${i.expiresAt}`)}let n=await Y(e,this.messages,this.state,(r,o,i)=>r.onRunInitialized?.({messages:o,state:i,agent:this,input:t}));(n.messages!==void 0||n.state!==void 0)&&(n.messages&&(this.messages=n.messages,t.messages=n.messages,e.forEach(r=>{r.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:t})})),n.state&&(this.state=n.state,t.state=n.state,e.forEach(r=>{r.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:t})})))}onError(t,e,n){return Jt(Y(n,this.messages,this.state,(r,o,i)=>r.onRunFailed?.({error:e,messages:o,state:i,agent:this,input:t}))).pipe(en(r=>{let o=r;if((o.messages!==void 0||o.state!==void 0)&&(o.messages!==void 0&&(this.messages=o.messages,n.forEach(i=>{i.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:t})})),o.state!==void 0&&(this.state=o.state,n.forEach(i=>{i.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:t})}))),o.stopPropagation!==!0){let i=String(e);if(!(e.name==="AbortError"||e.message==="Fetch is aborted"||e.message==="signal is aborted without reason"||e.message==="component unmounted"||i==="component unmounted"))throw console.error("Agent execution failed:",e),e}return{}}))}async onFinalize(t,e){let n=await Y(e,this.messages,this.state,(r,o,i)=>r.onRunFinalized?.({messages:o,state:i,agent:this,input:t}));(n.messages!==void 0||n.state!==void 0)&&(n.messages!==void 0&&(this.messages=n.messages,e.forEach(r=>{r.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:t})})),n.state!==void 0&&(this.state=n.state,e.forEach(r=>{r.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:t})})))}clone(){let t=Object.create(Object.getPrototypeOf(this));return t.agentId=this.agentId,t.description=this.description,t.threadId=this.threadId,t.messages=q(this.messages),t.state=q(this.state),t._debug=this._debug,t._debugLogger=this._debugLogger,t.isRunning=this.isRunning,t.subscribers=[...this.subscribers],t.middlewares=[...this.middlewares],t.pendingInterrupts=q(this.pendingInterrupts),t}addMessage(t){this.messages.push(t),(async()=>{for(let e of this.subscribers)await e.onNewMessage?.({message:t,messages:this.messages,state:this.state,agent:this});if(t.role==="assistant"&&t.toolCalls)for(let e of t.toolCalls)for(let n of this.subscribers)await n.onNewToolCall?.({toolCall:e,messages:this.messages,state:this.state,agent:this});for(let e of this.subscribers)await e.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}addMessages(t){this.messages.push(...t),(async()=>{for(let e of t){for(let n of this.subscribers)await n.onNewMessage?.({message:e,messages:this.messages,state:this.state,agent:this});if(e.role==="assistant"&&e.toolCalls)for(let n of e.toolCalls)for(let r of this.subscribers)await r.onNewToolCall?.({toolCall:n,messages:this.messages,state:this.state,agent:this})}for(let e of this.subscribers)await e.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}setMessages(t){this.messages=q(t),(async()=>{for(let e of this.subscribers)await e.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}setState(t){this.state=q(t),(async()=>{for(let e of this.subscribers)await e.onStateChanged?.({messages:this.messages,state:this.state,agent:this})})()}legacy_to_be_removed_runAgentBridged(t){this.agentId=this.agentId??_t();let e=this.prepareRunAgentInput(t);return(this.middlewares.length===0?this.run(e):this.middlewares.reduceRight((n,r)=>({run:o=>r.run(o,n),get messages(){return n.messages},get state(){return n.state}}),this).run(e)).pipe(gi(this.debugLogger),pa(this.debugLogger),Cg(this.threadId,e.runId,this.agentId),n=>n.pipe(en(r=>(this.debugLogger?.event("LEGACY","Event:",r,{type:r.type}),r))))}},Kd=class extends Gg{requestInit(t){return{method:"POST",headers:{...this.headers,"Content-Type":"application/json",Accept:"text/event-stream"},body:JSON.stringify(t),signal:this.abortController.signal}}runAgent(t,e){return this.abortController=t?.abortController??new AbortController,super.runAgent(t,e)}abortRun(){this.abortController.abort(),super.abortRun()}constructor(t){super(t),this.abortController=new AbortController,this.url=t.url,this.headers=q(t.headers??{}),this.fetch=t.fetch??((e,n)=>fetch(e,n))}run(t){return mg(pg(()=>this.fetch(this.url,this.requestInit(t))),this.debugLogger)}clone(){let t=super.clone();t.url=this.url,t.headers=q(this.headers??{}),t.fetch=this.fetch;let e=new AbortController,n=this.abortController.signal;return n.aborted&&e.abort(n.reason),t.abortController=e,t}};var $g=/\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;function Yd(t,e){let n=[];return{text:t.replace($g,(o,i)=>{let s=e[i];return s==null||s===""?(n.includes(i)||n.push(i),o):String(s)}),missing:n}}function Bg(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.name=="string"&&typeof e.title=="string"&&(e.prompt===void 0||typeof e.prompt=="string")}function ma(t){return Array.isArray(t)?t.filter(Bg):[]}var dr=class{#t=new Map;register(e){this.#t.set(e.name,e)}has(e){return this.#t.has(e)}get(e){let n=this.#t.get(e);if(n===void 0)throw new Error(`tool "${e}" is not registered`);return n}tools(){return[...this.#t.values()].map(e=>({name:e.name,description:e.description,parameters:e.parameters}))}};function ga(t){return t[Xn]===!0}function bi(t){return t[Kn]===!0}function yi(t,e){return Object.getOwnPropertyDescriptor(t,e).set}var Vg=yi(HTMLInputElement.prototype,"value"),jg=yi(HTMLTextAreaElement.prototype,"value"),qg=yi(HTMLSelectElement.prototype,"value"),Wg=yi(HTMLInputElement.prototype,"checked");function rn(t,e){t instanceof HTMLTextAreaElement?jg.call(t,e):t instanceof HTMLSelectElement?qg.call(t,e):Vg.call(t,e)}function ur(t,e){Wg.call(t,e)}var va="#4f46e5",Xg="rgba(79, 70, 229, 0.4)",Kg="--ag-ui-accent";function pr(t){return new Promise(e=>{setTimeout(e,t)})}function xi(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function ba(t){return t<=0||xi()?Promise.resolve():pr(t)}function wi(t,e){let n=window.getComputedStyle(t).getPropertyValue(Kg).trim();return n===""?e:n}function Zd(t){return`0 0 0 3px ${wi(t,Xg)}`}async function ya(t,e,n={}){let r=n.charDelayMs??35;rn(t,""),t.dispatchEvent(new Event("input",{bubbles:!0}));for(let o of e)rn(t,t.value+o),t.dispatchEvent(new Event("input",{bubbles:!0})),r>0&&await pr(r);t.dispatchEvent(new Event("change",{bubbles:!0}))}async function xa(t,e={}){let n=e.highlightMs??280,r=t.style.outline,o=t.style.outlineOffset;t.style.outline=`2px solid ${wi(t,va)}`,t.style.outlineOffset="2px",await pr(n),t.style.outline=r,t.style.outlineOffset=o,t.click()}var Yg=600,Zg=100;function vt(t,e={}){let n=xi();return t.scrollIntoView({block:"center",inline:"nearest",behavior:n?"auto":"smooth"}),n?Promise.resolve():new Promise(r=>{let o,i=()=>{clearTimeout(o),document.removeEventListener("scroll",s,!0),document.removeEventListener("scrollend",i,!0),r()},s=()=>{document.removeEventListener("scroll",s,!0),clearTimeout(o),o=setTimeout(i,e.settleMs??Yg)};o=setTimeout(i,Zg),document.addEventListener("scroll",s,!0),document.addEventListener("scrollend",i,!0)})}var Qg=1200,Jg=1/3;async function Qd(t,e,n){(e.focus??n)&&t.focus({preventScroll:!0});let r=e.flashMs??Qg;if(r<=0)return;let o=t.style.outline,i=t.style.outlineOffset,s=t.style.transition,a=e.color??wi(t,va);t.style.outline=`3px solid ${a}`,t.style.outlineOffset="2px";let l=xi()?0:Math.round(r*Jg);await pr(r-l),l>0&&(t.style.transition=`outline-color ${l}ms ease-out`,t.style.outline="3px solid transparent",await pr(l)),t.style.outline=o,t.style.outlineOffset=i,t.style.transition=s}function ev(t,e={}){return Qd(t,e,!1)}function wa(t,e={}){return Qd(t,e,!0)}async function Ea(t,e={}){let n=e.pressMs??140,r=t.style.transform,o=t.style.transition,i=t.style.boxShadow;t.style.transition="transform 80ms ease",t.style.transform="scale(0.96)",t.style.boxShadow=Zd(t),await ba(n),t.style.transform=r,t.style.transition=o,t.style.boxShadow=i,t.click()}function tv(t,e){for(let n of Array.from(t.options))if(n.value===e||n.text===e)return n;return null}async function _a(t,e,n={}){let r=tv(t,e);if(r===null)throw new Error(`no <option> matching "${e}"`);let o=n.highlightMs??220,i=t.style.outline,s=t.style.outlineOffset;t.style.outline=`2px solid ${wi(t,va)}`,t.style.outlineOffset="2px",await ba(o),rn(t,r.value),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),t.style.outline=i,t.style.outlineOffset=s}async function Ta(t,e,n={}){let r=n.flashMs??200,o=t.style.boxShadow;t.style.boxShadow=Zd(t),await ba(r),ur(t,e),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),t.style.boxShadow=o}var Sa={SCROLL:"scroll",DRAG:"drag"};function Aa(t,e){let n=[];return t.has(Sa.SCROLL)&&n.push(nv(e)),t.has(Sa.DRAG)&&n.push(rv(e)),n}function nv(t){return{name:"scroll_to",description:"Scroll a target into view. `target` is `top`, `bottom`, or a CSS selector / page-map element id. Read-only: it changes nothing on the page.",parameters:{type:"object",properties:{target:{type:"string"}},required:["target"],[Pe]:"Scroll into view"},handler:e=>{let n=String(e.target??"");if(n==="top"||n==="bottom"){let o=n==="top"?0:document.body.scrollHeight;return window.scrollTo({top:o,behavior:"smooth"}),{scrolled:!0,target:n}}let r=t(n);if(r===null)throw new Error(`no element matching "${n}"`);return vt(r),{scrolled:!0,target:n}}}}function rv(t){return{name:"drag_and_drop",description:"Drag the `from` element onto the `to` element (CSS selectors or page-map element ids), firing the page's native drag-and-drop. Use for reordering sortable lists. The page decides what the drop commits.",parameters:{type:"object",properties:{from:{type:"string"},to:{type:"string"}},required:["from","to"],[Pe]:"Drag and drop"},handler:e=>{let n=String(e.from??""),r=String(e.to??""),o=t(n);if(o===null)throw new Error(`no element matching "${n}"`);let i=t(r);if(i===null)throw new Error(`no element matching "${r}"`);return ov(o,i),{dragged:!0,from:n,to:r}}}}function ov(t,e){let n=new DataTransfer;hr(t,"dragstart",n),hr(e,"dragenter",n),hr(e,"dragover",n),hr(e,"drop",n),hr(t,"dragend",n)}function hr(t,e,n){let r=new Event(e,{bubbles:!0,cancelable:!0});r.dataTransfer=n,t.dispatchEvent(r)}function ka(t,e){return!e||t===null?[]:[{description:"page_map",value:JSON.stringify(t())}]}function Ei(t){let e=[{name:`read_${t.name}`,description:`Read the "${t.name}" state.`,parameters:{type:"object",properties:{},required:[],[Pe]:`Read ${t.name}`},handler:()=>t.read()}],n=t.write;return n!==void 0&&e.push({name:`set_${t.name}`,description:`Update the "${t.name}" state.`,parameters:{...t.schema??{type:"object"},[Xn]:!0,[Pe]:`Update ${t.name}`},handler:r=>n(r)}),e}var iv=Ei;function Ca(t){let e={};if(!Array.isArray(t))return e;for(let n of t){if(n===null||typeof n!="object")continue;let r=n,o=r.name,i=r.summary,s=r.description;typeof o=="string"&&typeof i=="string"&&(e[o]=typeof s=="string"?{name:o,summary:i,description:s}:{name:o,summary:i})}return e}var Jd=/:([A-Za-z_][A-Za-z0-9_]*)/g;function sv(t){return[...t.matchAll(Jd)].map(e=>e[0].slice(1))}function av(t,e,n){let r={...n};return{path:e.replace(Jd,(i,s)=>{let a=n[s];if(a==null||String(a)==="")throw new Error(`route "${t}" requires path param "${s}"`);return delete r[s],encodeURIComponent(String(a))}),leftover:r}}function lv(t,e){let n=new URLSearchParams;for(let[o,i]of Object.entries(e))n.set(o,String(i));let r=n.toString();return r===""?t:`${t}?${r}`}function Ia(t,e){return[{name:"list_routes",description:"List the routes the app can navigate to. Each route's `pathParams` names the dynamic segments to pass as `params` to `navigate_to_route`.",parameters:{type:"object",properties:{},required:[],[Pe]:"List pages"},handler:()=>t().map(n=>({...n,pathParams:sv(n.path)}))},{name:"navigate_to_route",description:"Navigate to one of the app's routes by its id, filling any dynamic `:name` path segments (and extra query params) from `params`.",parameters:{type:"object",properties:{route_id:{type:"string"},params:{type:"object"}},required:["route_id"],[Kn]:!0,[Pe]:"Navigate"},handler:n=>{let r=n.route_id,o=t().find(u=>u.id===r);if(o===void 0)throw new Error(`unknown route "${String(r)}"`);let i=n.params??{},{path:s,leftover:a}=av(o.id,o.path,i),l=lv(s,a),c=e();return c!==null?c(l):window.location.assign(l),{navigated:!0,path:l}}}]}var le={title:"Assistant",chatHistory:"Chat history",newChat:"New chat",collapse:"Collapse",expand:"Expand",expandUnread:"Expand \u2014 {count} unread",toggleTheme:"Toggle theme",copyCode:"Copy",copied:"Copied",copyFailed:"Copy failed",checkpoints:"Continue a run",noCheckpoints:"Nothing to continue yet.",resumeRun:"Resume",forkRun:"Fork",forkedRun:"branched",conversation:"Conversation",jumpToLatest:"Jump to latest",announceResponding:"Assistant is responding",announceAnswerReady:"Assistant answered",announceAwaitingDecision:"{count} action is waiting for your approval",announceStopped:"Response stopped",announceFailed:"The response failed",thinking:"Assistant is thinking\u2026",thoughts:"Thoughts",stopped:"\u23F9 Stopped",connectionLost:"Connection lost",noResult:"No result returned.",declinedAction:"User declined the action.",navigating:"Navigating\u2026",historyReplaced:"The server replaced this conversation's history. Reload to see the updated transcript.",chartUndrawable:"A chart could not be drawn from the data sent, so it was removed.",historyCompacted:"Earlier turns condensed to fit the context window ({count} removed)",usingSkill:"Using skill {name}",runInterrupted:"The previous response didn\u2019t finish \u2014 the page changed before it arrived.",pageMoved:"The page changed since you last looked at it. Call read_page to see the current page, then retry.",attachmentsStillUploading:"{n} file still uploading \u2014 it was not sent with this message and is still attached.",skillNeeds:"\u201C{title}\u201D needs {fields} \u2014 fill it in below, then send.",message:"Message",inputPlaceholder:"Ask anything\u2026",send:"Send",stop:"Stop",attachFiles:"Attach files",recordVoice:"Record voice",stopRecording:"Stop recording",transcribing:"Transcribing\u2026",transcriptionFailed:"Transcription failed",recordingLimit:"Stopped at the {n}-minute limit \u2014 transcribing what was recorded.",toolRunning:"running\u2026",toolDeferred:"waiting for you",toolDone:"\u2713 done",toolError:"\u26A0 error",toolDeclined:"\u2298 declined",resizePanel:"Resize the chat panel",decisionApproved:"approved by you",decisionDeclined:"declined by you",argumentsLabel:"Arguments",resultLabel:"Result",errorLabel:"Error",declinedLabel:"Declined",details:"Details",approvalEditArgs:"Edit the arguments before approving",approvalArgsInvalid:"That is not valid JSON, so nothing was sent.",approvalArgsNotAnObject:"Arguments have to be a JSON object.",suggestions:"Suggested follow-ups",messageActions:"Message actions",quoteSelection:"Quote",copyMessage:"Copy message",retryMessage:"Try again",feedbackUp:"Good answer",feedbackDown:"Poor answer",confirmAction:"Confirm action",confirmAlways:"Always allow",confirmRun:"Run \u201C{tool}\u201D?",confirm:"Confirm",cancel:"Cancel",approveAction:"Approve action",approvalPrompt:"Approve this action?",approve:"Approve",deny:"Deny",askUserAction:"Question",otherOption:"Other\u2026",answerPlaceholder:"Type your answer\u2026",submit:"Submit",chats:"Chats",noConversations:"No conversations yet.",rename:"Rename",renameConversation:"Rename conversation",delete:"Delete",deleteConversation:"Delete conversation",deletePrompt:"Delete?",tooLarge:"Too large (max {size})",fileTypeNotAllowed:"File type not allowed",uploadFailed:"upload failed",retry:"Retry",retryUpload:"Retry upload",remove:"Remove",removeAttachment:"Remove attachment",justNow:"just now",minutesAgo:"{n}m ago",hoursAgo:"{n}h ago",daysAgo:"{n}d ago",weeksAgo:"{n}w ago"};function Ra(t){let e={...le};for(let n of Object.keys(t)){let r=t[n];r!==void 0&&(e[n]=r)}return e}function eu(t,e){let n=document.createElement("button");return n.type="button",n.className=`approval-btn approval-btn--${t}`,n.setAttribute("part",`approval-button approval-${t}`),n.textContent=e,n}function Na(t,e,n={}){let r=n.strings??le;return new Promise(o=>{let i=document.createElement("div");i.className="approval",i.setAttribute("part","approval"),e.toolName!==void 0&&i.setAttribute("data-tool-name",e.toolName),i.setAttribute("role","group"),i.setAttribute("aria-label",r.approveAction);let s=document.createElement("div");s.className="approval-body",s.setAttribute("part","approval-body"),s.textContent=e.message??r.approvalPrompt;let a=cv(e,n,r),l=document.createElement("div");l.className="approval-actions",l.setAttribute("part","approval-actions");let c=eu("deny",r.deny),u=eu("approve",r.approve),m=!1,y=f=>{m||(m=!0,c.disabled=!0,u.disabled=!0,i.setAttribute("data-resolved",f?"approved":"denied"),o(f))};if(c.addEventListener("click",()=>y(!1)),u.addEventListener("click",()=>{a!==null&&!a.commit()||y(!0)}),n.signal?.addEventListener("abort",()=>y(!1),{once:!0}),l.append(c,u),i.append(s,...a===null?[]:[a.root],l),t.appendChild(i),n.signal?.aborted===!0){y(!1);return}u.focus()})}function cv(t,e,n){let{onEdit:r}=e;if(r===void 0||t.args===void 0)return null;let o=JSON.stringify(t.args,null,2),i=document.createElement("div");i.className="approval-edit",i.setAttribute("part","approval-edit");let s=document.createElement("textarea");s.className="approval-args",s.setAttribute("part","approval-args"),s.setAttribute("aria-label",n.approvalEditArgs),s.rows=Math.min(10,o.split(`
12
- `).length),s.value=o;let a=document.createElement("div");return a.className="approval-error",a.setAttribute("part","approval-error"),a.setAttribute("role","alert"),a.hidden=!0,i.append(s,a),{root:i,commit:()=>{if(s.value===o)return!0;let l;try{l=JSON.parse(s.value)}catch{return a.textContent=n.approvalArgsInvalid,a.hidden=!1,s.focus(),!1}return typeof l!="object"||l===null||Array.isArray(l)?(a.textContent=n.approvalArgsNotAnObject,a.hidden=!1,s.focus(),!1):(a.hidden=!0,r(l),!0)}}}function Oa(t,e){for(let n of Array.from(t.querySelectorAll("pre"))){let r=n.querySelector("code");r===null||n.querySelector(".code-copy")!==null||(n.classList.add("has-copy"),n.append(dv(r,e)))}}function dv(t,e){let n=t.textContent,r=document.createElement("button");return r.type="button",r.className="code-copy",r.setAttribute("part","code-copy"),r.textContent=e.copyCode,r.title=e.copyCode,r.setAttribute("aria-label",e.copyCode),r.addEventListener("click",()=>{uv(n).then(o=>{pv(r,o?e.copied:e.copyFailed,e)})}),r}async function uv(t){let e=navigator.clipboard;if(e===void 0)return!1;try{return await e.writeText(t),!0}catch{return!1}}function pv(t,e,n){t.textContent=e,t.dataset.state=e===n.copied?"copied":"failed",setTimeout(()=>{t.textContent=n.copyCode,delete t.dataset.state},1500)}function Ma(t){let e=document.createElement("div");e.className="attachment-chips",e.setAttribute("part","attachment-chips");for(let n of t)e.appendChild(hv(n));return e}function hv(t){let e=document.createElement("div");e.className="attachment-chip attachment-chip--ready",e.setAttribute("part","attachment-chip");let n=document.createElement("span");n.className="attachment-chip-icon",n.setAttribute("part","attachment-chip-icon"),n.innerHTML=La(t.mime),n.setAttribute("aria-hidden","true");let r=document.createElement("span");r.className="attachment-chip-name",r.setAttribute("part","attachment-chip-name"),r.textContent=t.name,r.title=t.name;let o=document.createElement("span");return o.className="attachment-chip-size",o.setAttribute("part","attachment-chip-size"),o.textContent=_i(t.size),e.append(n,r,o),e}function La(t){return t.startsWith("image/")?ec:t==="application/pdf"?tc:t.startsWith("text/")?nc:Jl}function _i(t){if(t<1024)return`${t} B`;let e=["KB","MB","GB"],n=t/1024,r=0;for(;n>=1024&&r<e.length-1;)n/=1024,r+=1;return`${n<10?Math.round(n*10)/10:Math.round(n)} ${e[r]}`}var Ti=class{element;#t;#r;#e=[];constructor(e){this.#t=e,this.#r=e.strings??le,this.element=document.createElement("div"),this.element.className="attachment-tray",this.element.setAttribute("part","attachment-tray"),this.element.hidden=!0}add(e){let n={localId:_e(),file:e,status:De.UPLOADING,progress:0,ref:null,error:"",controller:null};this.#e.push(n);let r=this.#s(e);if(r!==null){n.status=De.ERROR,n.error=r,this.#o(),this.#t.onChange?.();return}this.#o(),this.#t.onChange?.(),this.#n(n)}readyRefs(){let e=[];for(let n of this.#e)n.ref!==null&&e.push(n.ref);return e}hasPending(){return this.#e.some(e=>e.status===De.UPLOADING)}pendingCount(){return this.#e.filter(e=>e.status===De.UPLOADING).length}isEmpty(){return this.#e.length===0}clearReady(){this.#e=this.#e.filter(e=>e.status===De.UPLOADING),this.#o()}clear(){for(let e of this.#e)e.controller?.abort();this.#e=[],this.#o()}dispose(){for(let e of this.#e)e.controller?.abort()}#s(e){return this.#t.maxBytes>0&&e.size>this.#t.maxBytes?this.#r.tooLarge.replace("{size}",_i(this.#t.maxBytes)):fv(this.#t.accept,e)?null:this.#r.fileTypeNotAllowed}#n(e){let n=this.#s(e.file);if(n!==null){e.status=De.ERROR,e.error=n,this.#o(),this.#t.onChange?.();return}e.status=De.UPLOADING,e.progress=0,e.error="";let r=new AbortController;e.controller=r,this.#o(),this.#t.upload(e.file,o=>{e.progress=o,this.#o()},r.signal).then(o=>{e.status=De.READY,e.ref=o}).catch(o=>{e.status=De.ERROR,e.error=o instanceof Error?o.message:this.#r.uploadFailed}).finally(()=>{e.controller=null,this.#o(),this.#t.onChange?.()})}#i(e){e.controller?.abort(),this.#e=this.#e.filter(n=>n!==e),this.#o(),this.#t.onChange?.()}#o(){this.element.replaceChildren(),this.element.hidden=this.#e.length===0;for(let e of this.#e)this.element.appendChild(this.#c(e))}#c(e){let n=document.createElement("div");n.className=`attachment-chip attachment-chip--${e.status}`,n.setAttribute("part","attachment-chip");let r=document.createElement("span");r.className="attachment-chip-icon",r.setAttribute("part","attachment-chip-icon"),r.innerHTML=La(e.file.type),r.setAttribute("aria-hidden","true");let o=document.createElement("span");o.className="attachment-chip-name",o.setAttribute("part","attachment-chip-name"),o.textContent=e.file.name,o.title=e.file.name;let i=document.createElement("span");if(i.className="attachment-chip-size",i.setAttribute("part","attachment-chip-size"),i.textContent=e.status===De.ERROR?e.error:_i(e.file.size),n.append(r,o,i),e.status===De.UPLOADING){let a=document.createElement("div");a.className="attachment-chip-bar",a.setAttribute("part","attachment-chip-bar");let l=document.createElement("div");l.className="attachment-chip-bar-fill",l.setAttribute("part","attachment-chip-bar-fill"),l.style.width=`${Math.round(e.progress*100)}%`,a.appendChild(l),n.appendChild(a)}if(e.status===De.ERROR){let a=document.createElement("button");a.type="button",a.className="attachment-chip-retry",a.setAttribute("part","attachment-chip-retry"),a.title=this.#r.retry,a.setAttribute("aria-label",this.#r.retryUpload),a.textContent="\u21BB",a.addEventListener("click",()=>this.#n(e)),n.appendChild(a)}let s=document.createElement("button");return s.type="button",s.className="attachment-chip-remove",s.setAttribute("part","attachment-chip-remove"),s.title=this.#r.remove,s.setAttribute("aria-label",this.#r.removeAttachment),s.textContent="\u2715",s.addEventListener("click",()=>this.#i(e)),n.appendChild(s),n}};function fv(t,e){let n=t.split(",").map(i=>i.trim().toLowerCase()).filter(i=>i!=="");if(n.length===0)return!0;let r=e.type.toLowerCase(),o=e.name.toLowerCase();return n.some(i=>i.startsWith(".")?o.endsWith(i):i.endsWith("/*")?r.startsWith(i.slice(0,-1)):r===i)}var mv="http://www.w3.org/2000/svg";var He={top:20,right:12,bottom:30,left:44},Ai=480-He.left-He.right,Si=220-He.top-He.bottom,tu=["var(--ag-ui-chart-1, #4f7cff)","var(--ag-ui-chart-2, #21b573)","var(--ag-ui-chart-3, #e0803c)","var(--ag-ui-chart-4, #b563d8)","var(--ag-ui-chart-5, #d84f6e)","var(--ag-ui-chart-6, #3ba7c4)"];function on(t){return tu[t%tu.length]}function dt(t,e){let n=document.createElementNS(mv,t);for(let[r,o]of Object.entries(e))n.setAttribute(r,String(o));return n}function nu(t,e){let n=dt("text",{"font-size":10,fill:"currentColor","fill-opacity":.65,...e});return n.textContent=t,n}function gv(t){let e=[];return t.labels.forEach((n,r)=>{let o=0;for(let i of t.series)o+=i.points[r]??0,e.push(o)}),e}function vv(t){let e=t.kind==="stacked"?gv(t):t.series.flatMap(o=>[...o.points]),n=Math.max(0,...e),r=Math.min(0,...e);return n===r?{min:r,max:n+1}:{min:r,max:n}}function sn(t,e,n){return He.top+Si-(t-e)/(n-e)*Si}function Pa(t,e){let n=Ai/e;return He.left+n*t+n/2}function bv(t,e,n,r){for(let o of[n,r]){let i=sn(o,n,r);t.appendChild(dt("line",{x1:He.left,y1:i,x2:480-He.right,y2:i,stroke:"currentColor","stroke-opacity":o===n?.35:.12})),t.appendChild(nu(String(Math.round(o)),{x:He.left-6,y:i+4,"text-anchor":"end"}))}e.labels.forEach((o,i)=>{t.appendChild(nu(o,{x:Pa(i,e.labels.length),y:220-He.bottom+16,"text-anchor":"middle"}))})}function yv(t,e,n,r){let o=Ai/e.labels.length,i=o*.7/e.series.length,s=sn(n,n,r);e.series.forEach((a,l)=>{a.points.forEach((c,u)=>{let m=sn(c,n,r);t.appendChild(dt("rect",{x:He.left+o*u+o*.15+i*l,y:m,width:i,height:Math.max(1,s-m),fill:on(l),rx:2}))})})}function xv(t,e,n,r){let o=Ai/e.labels.length,i=o*.7,s=e.labels.map(()=>0);e.series.forEach((a,l)=>{a.points.forEach((c,u)=>{let m=s[u]??0,y=m+c;s[u]=y;let f=sn(y,n,r);t.appendChild(dt("rect",{x:He.left+o*u+o*.15,y:f,width:i,height:Math.max(1,sn(m,n,r)-f),fill:on(l)}))})})}function wv(t,e,n,r){e.series.forEach((o,i)=>{let s=o.points.map((a,l)=>`${Pa(l,e.labels.length)},${sn(a,n,r)}`).join(" ");t.appendChild(dt("polyline",{points:s,fill:"none",stroke:on(i),"stroke-width":2,"stroke-linejoin":"round"}))})}function Ev(t,e,n,r){e.series.forEach((o,i)=>{o.points.forEach((s,a)=>{t.appendChild(dt("circle",{cx:Pa(a,e.labels.length),cy:sn(s,n,r),r:4,fill:on(i),"fill-opacity":.85}))})})}function _v(t,e){let n=e.reduce((a,l)=>a+l,0),r=480/2,o=He.top+Si/2,i=Math.min(Ai,Si)/2;if(n===0){t.appendChild(dt("circle",{cx:r,cy:o,r:i,fill:"none",stroke:"currentColor","stroke-opacity":.3}));return}let s=-Math.PI/2;e.forEach((a,l)=>{let c=a/n*Math.PI*2,u=s+c;if(c>=Math.PI*2)t.appendChild(dt("circle",{cx:r,cy:o,r:i,fill:on(l)}));else{let m=r+i*Math.cos(s),y=o+i*Math.sin(s),f=r+i*Math.cos(u),h=o+i*Math.sin(u),g=c>Math.PI?1:0;t.appendChild(dt("path",{d:`M ${r} ${o} L ${m} ${y} A ${i} ${i} 0 ${g} 1 ${f} ${h} Z`,fill:on(l)}))}s=u})}function Tv(t){if(t.length<2)return null;let e=document.createElement("div");return e.className="chart-legend",e.setAttribute("part","chart-legend"),t.forEach((n,r)=>{let o=document.createElement("span");o.className="chart-legend-item";let i=document.createElement("span");i.className="chart-legend-swatch",i.style.background=on(r),o.append(i,document.createTextNode(n)),e.appendChild(o)}),e}function fr(t){if(t.labels.length===0||t.series.length===0)return null;let e=document.createElement("div");if(e.className="chart-block",e.setAttribute("part","chart-block"),t.title!==void 0&&t.title!==""){let o=document.createElement("div");o.className="chart-title",o.setAttribute("part","chart-title"),o.textContent=t.title,e.appendChild(o)}let n=dt("svg",{viewBox:"0 0 480 220",width:"100%",role:"img"});if(n.setAttribute("aria-label",t.title??`${t.kind} chart`),t.kind==="pie"){let o=t.series[0];_v(n,o.points.map(i=>Math.max(0,i)))}else{let{min:o,max:i}=vv(t);bv(n,t,o,i),t.kind==="bar"?yv(n,t,o,i):t.kind==="stacked"?xv(n,t,o,i):t.kind==="line"?wv(n,t,o,i):Ev(n,t,o,i)}e.appendChild(n);let r=Tv(t.kind==="pie"?t.labels:t.series.map(o=>o.label));return r!==null&&e.appendChild(r),e}var Sv=["bar","line","pie","scatter","stacked"];function Av(t){return Sv.includes(t)?t:"bar"}function kv(t){if(!Array.isArray(t))return null;let e=[];for(let n of t){if(typeof n!="number"||!Number.isFinite(n)||Math.abs(n)>1e15)return null;e.push(n)}return e}function Cv(t){if(!Array.isArray(t))return null;for(let e=0;e<t.length;e+=1)if(typeof t[e]!="string")return null;return t}function Pn(t){if(typeof t!="object"||t===null)return null;let e=t,n=Cv(e.labels);if(n===null||!Array.isArray(e.series))return null;let r=[];for(let s of e.series){if(typeof s!="object"||s===null)return null;let a=s,l=kv(a.points);if(l===null||l.length!==n.length)return null;r.push({label:typeof a.label=="string"?a.label:"",points:l})}if(r.length===0||r.length*n.length>2e4||n.length>2e3)return null;let o=Av(e.kind),i=e.title;return typeof i=="string"?{kind:o,title:i,labels:n,series:r}:{kind:o,labels:n,series:r}}var ki="render_chart";function Iv(t){let e=Pn(t);return e===null?null:fr(e)}function Rv(t){let e=Pn(t);return e!==null&&e.labels.length>0&&e.series.length>0}var Nv="chart not rendered: expected labels (strings) and series, each with one finite number per label";function ru(){return{name:ki,description:"Show a chart in the conversation. Supply the data and the page draws it. Every series must have exactly one point per label.",parameters:{type:"object",properties:{kind:{type:"string",enum:["bar","line","pie","scatter","stacked"]},title:{type:"string"},labels:{type:"array",items:{type:"string"}},series:{type:"array",items:{type:"object",properties:{label:{type:"string"},points:{type:"array",items:{type:"number"}}},required:["points"]}}},required:["labels","series"],"x-summary":"Draw a chart"},handler:t=>Rv(t)?"chart rendered":Nv,render:Iv}}function mr(t,e=Date.now(),n=le){if(!Number.isFinite(t))return n.justNow;let r=Math.round((e-t)/1e3);if(r<60)return n.justNow;let o=Math.round(r/60);if(o<60)return n.minutesAgo.replace("{n}",String(o));let i=Math.round(o/60);if(i<24)return n.hoursAgo.replace("{n}",String(i));let s=Math.round(i/24);return s<7?n.daysAgo.replace("{n}",String(s)):n.weeksAgo.replace("{n}",String(Math.round(s/7)))}function ou(t){return t.preview!==void 0&&t.preview!==null&&t.preview!==""?t.preview:null}function iu(t){return t.replace(/\s+/g," ").trim()}var gr=class{element;#t;#r;#e;#s=null;#n=null;#i;#o=[];constructor(e,n=le){this.#t=e,this.#i=n,this.element=document.createElement("div"),this.element.className="checkpoints",this.element.setAttribute("part","checkpoints"),this.element.setAttribute("role","dialog"),this.element.setAttribute("aria-label",n.checkpoints),this.element.tabIndex=-1,this.element.hidden=!0;let r=document.createElement("div");r.className="checkpoints-header",r.setAttribute("part","checkpoints-header"),this.#e=document.createElement("span"),this.#e.className="checkpoints-title",this.#e.setAttribute("part","checkpoints-title"),this.#e.textContent=n.checkpoints,r.append(this.#e),this.#r=document.createElement("div"),this.#r.className="checkpoints-list",this.#r.setAttribute("part","checkpoints-list"),this.element.append(r,this.#r),this.element.addEventListener("keydown",o=>this.#u(o))}setRuns(e){this.#o=e,this.#p()}setRelativeTimeFormatter(e){this.#n=e}#c(e){return this.#n!==null?this.#n(e):mr(e,Date.now(),this.#i)}setStrings(e){this.#i=e,this.element.setAttribute("aria-label",e.checkpoints),this.#e.textContent=e.checkpoints,this.#p()}open(){this.open_||(this.#s=this.#d(),this.element.hidden=!1,(this.#a()[0]??this.element).focus())}close(){this.open_&&(this.element.hidden=!0,this.#s?.focus(),this.#s=null)}#d(){return this.element.getRootNode().activeElement}#a(){return Array.from(this.element.querySelectorAll("button, [tabindex]")).filter(e=>!e.hidden)}#u(e){if(e.key==="Escape"){e.stopPropagation(),this.close();return}if(e.key!=="Tab")return;let n=this.#a(),r=n[0],o=n[n.length-1],i=this.#d();e.shiftKey&&i===r?(e.preventDefault(),o?.focus()):!e.shiftKey&&i===o&&(e.preventDefault(),r?.focus())}get open_(){return!this.element.hidden}#p(){if(this.#r.replaceChildren(),this.#o.length===0){let n=document.createElement("div");n.className="checkpoints-empty",n.setAttribute("part","checkpoints-empty"),n.textContent=this.#i.noCheckpoints,this.#r.append(n);return}let e=this.#S();for(let n of this.#o)this.#r.append(this.#m(n,e))}#S(){let e=new Set,n=new Set;for(let r of this.#o){let o=ou(r);if(o===null)continue;let i=iu(o);e.has(i)&&n.add(i),e.add(i)}return n}#m(e,n){let r=document.createElement("div");r.className="checkpoint-row",r.setAttribute("part","checkpoint-row");let o=ou(e),i=e.started_at===null?null:this.#c(Date.parse(e.started_at)),s=document.createElement("span");if(s.className="checkpoint-label",s.setAttribute("part","checkpoint-label"),s.textContent=o??i??e.run_id,r.append(s),o!==null&&i!==null){let l=document.createElement("span");l.className="checkpoint-time",l.setAttribute("part","checkpoint-time"),l.textContent=i,r.append(l)}if((o===null?i!==null:n.has(iu(o)))&&e.run_id!==""){let l=document.createElement("span");l.className="checkpoint-id",l.setAttribute("part","checkpoint-id"),l.textContent=e.run_id.slice(0,8),l.title=e.run_id,r.append(l)}if(e.parent_run_id!==null){let l=document.createElement("span");l.className="checkpoint-branch",l.setAttribute("part","checkpoint-branch"),l.textContent=this.#i.forkedRun,l.title=e.parent_run_id,r.append(l)}return r.append(this.#_(e.run_id,"resume",this.#i.resumeRun),this.#_(e.run_id,"fork",this.#i.forkRun)),r}#_(e,n,r){let o=document.createElement("button");return o.type="button",o.className=`checkpoint-action checkpoint-${n}`,o.setAttribute("part",`checkpoint-action checkpoint-${n}`),o.textContent=r,o.addEventListener("click",()=>{this.close(),this.#t(e,n)}),o}};function Da(t,e){let n=document.createElement("button");return n.type="button",n.className=`confirm-btn confirm-btn--${t}`,n.setAttribute("part",`confirm-button confirm-${t}`),n.textContent=e,n}function Ua(t,e,n={}){let r=n.strings??le;return new Promise(o=>{let i=document.createElement("div");i.className="confirm",i.setAttribute("part","confirm"),i.setAttribute("data-tool-name",e.toolName),i.setAttribute("role","group"),i.setAttribute("aria-label",r.confirmAction);let s=document.createElement("div");s.className="confirm-body",s.setAttribute("part","confirm-body"),s.textContent=e.message??r.confirmRun.replace("{tool}",e.toolName);let a=document.createElement("pre");a.className="confirm-args",a.setAttribute("part","confirm-args"),a.textContent=JSON.stringify(e.args,null,2),a.hidden=Object.keys(e.args).length===0;let l=document.createElement("div");l.className="confirm-actions",l.setAttribute("part","confirm-actions");let c=Da("cancel",r.cancel),u=n.onAlwaysAllow===void 0?null:Da("always",r.confirmAlways.replace("{tool}",e.toolName)),m=Da("confirm",r.confirm),y=!1,f=h=>{y||(y=!0,i.remove(),o(h))};if(c.addEventListener("click",()=>f(!1)),m.addEventListener("click",()=>f(!0)),u?.addEventListener("click",()=>{n.onAlwaysAllow?.(),f(!0)}),n.signal?.addEventListener("abort",()=>f(!1),{once:!0}),l.append(c,...u===null?[]:[u],m),i.append(s,a,l),t.appendChild(i),n.signal?.aborted===!0){f(!1);return}m.focus()})}function Ha(t,e){if(lu(t)!==null)return;let n=Ci(t,e.strings);n.appendChild(Ov(e)),e.onFeedback!==void 0&&n.append(su("up",e.strings.feedbackUp,e.onFeedback),su("down",e.strings.feedbackDown,e.onFeedback))}function Ci(t,e){let n=lu(t);if(n!==null)return n;let r=document.createElement("div");return r.className="message-actions",r.setAttribute("part","message-actions"),r.setAttribute("role","group"),r.setAttribute("aria-label",e.messageActions),t.after(r),r}function lu(t){let e=t.nextElementSibling;return e?.classList.contains("message-actions")===!0?e:null}function Ii(t,e,n){let r=document.createElement("button");r.type="button",r.className=`message-action message-action--${t}`,r.setAttribute("part",`message-action message-action-${t}`),r.title=e,r.setAttribute("aria-label",e);let o=document.createElement("span");return o.setAttribute("aria-hidden","true"),o.textContent=n,r.appendChild(o),r}function Ov(t){let{strings:e}=t,n=Ii("copy",e.copyMessage,"\u2398");return n.addEventListener("click",()=>{navigator.clipboard.writeText(t.text()).then(()=>au(n,e.copied,e.copyMessage),()=>au(n,e.copyFailed,e.copyMessage))}),n}function su(t,e,n){let r=Ii(t==="up"?"up":"down",e,t==="up"?"\u{1F44D}":"\u{1F44E}");return r.addEventListener("click",()=>{let o=r.getAttribute("aria-pressed")==="true";r.setAttribute("aria-pressed",o?"false":"true"),n(t)}),r.setAttribute("aria-pressed","false"),r}function au(t,e,n){t.title=e,t.setAttribute("aria-label",e),t.classList.add("message-action--confirmed"),setTimeout(()=>{t.title=n,t.setAttribute("aria-label",n),t.classList.remove("message-action--confirmed")},1500)}var Mv=500;function vr(t,e=[],n){for(let r of Vv(e)){if(!t.contains(r.startContainer)||!t.contains(r.endContainer))continue;let o=document.createRange();o.setStart(r.startContainer,r.startOffset),o.setEnd(r.endContainer,r.endOffset);let i=Uv(o).trim();if(i!=="")return{text:i,rect:Bv(o,n)}}return null}function za(t){let e=Lv(t);return e.length===0?"":`${Dv(e.join(`
10
+ `),m=JSON.parse(u);n?.event("SSE","Event received:",m,{type:m.type}),r.next(m)}catch(u){r.error(u)}}return r.asObservable()},wg=t=>{let e=new ct,n=new Uint8Array;t.subscribe({next:o=>{if(o.type!==nn.HEADERS&&o.type===nn.DATA&&o.data){let i=new Uint8Array(n.length+o.data.length);i.set(n,0),i.set(o.data,n.length),n=i,r()}},error:o=>e.error(o),complete:()=>{if(n.length>0)try{r()}catch{console.warn("Incomplete or invalid protocol buffer data at stream end")}e.complete()}});function r(){for(;n.length>=4;){let o=4+new DataView(n.buffer,n.byteOffset,4).getUint32(0,!1);if(n.length<o)break;try{let i=n.slice(4,o),s=$d(i);e.next(s),n=n.slice(o)}catch(i){let s=i instanceof Error?i.message:String(i);e.error(Error(`Failed to decode protocol buffer message: ${s}`));return}}}return e.asObservable()},Eg=(t,e)=>{let n=ur(e),r=new ct,o=new yo,i=!1;return t.subscribe({next:s=>{if(o.next(s),s.type===nn.HEADERS&&!i){i=!0;let a=s.headers.get("content-type");n?.lifecycle("HTTP","Stream format detected:",{contentType:a,parser:a===ua?"protobuf":"sse"}),a===ua?wg(o).subscribe({next:l=>r.next(l),error:l=>r.error(l),complete:()=>r.complete()}):xg(o,n).subscribe({next:l=>{try{let c=no.parse(l);n?.event("HTTP","Event validated:",c,{type:c.type,valid:!0}),r.next(c)}catch(c){n?.event("HTTP","Event invalid:",{json:l,error:String(c)}),r.error(c)}},error:l=>{if(l?.name==="AbortError"){r.next({type:v.RUN_ERROR,message:l.message||"Request aborted",code:"abort",rawEvent:l}),r.complete();return}return r.error(l)},complete:()=>r.complete()})}else i||r.error(Error("No headers event received before data events"))},error:s=>{o.error(s),r.error(s)},complete:()=>{o.complete()}}),r.asObservable()},J=d.enum(["TextMessageStart","TextMessageContent","TextMessageEnd","ActionExecutionStart","ActionExecutionArgs","ActionExecutionEnd","ActionExecutionResult","AgentStateMessage","MetaEvent","RunStarted","RunFinished","RunError","NodeStarted","NodeFinished"]),_g=d.enum(["LangGraphInterruptEvent","PredictState","Exit"]),Tg=d.object({type:d.literal(J.enum.TextMessageStart),messageId:d.string(),parentMessageId:d.string().optional(),role:d.string().optional()}),Sg=d.object({type:d.literal(J.enum.TextMessageContent),messageId:d.string(),content:d.string()}),Ag=d.object({type:d.literal(J.enum.TextMessageEnd),messageId:d.string()}),kg=d.object({type:d.literal(J.enum.ActionExecutionStart),actionExecutionId:d.string(),actionName:d.string(),parentMessageId:d.string().optional()}),Cg=d.object({type:d.literal(J.enum.ActionExecutionArgs),actionExecutionId:d.string(),args:d.string()}),Ig=d.object({type:d.literal(J.enum.ActionExecutionEnd),actionExecutionId:d.string()}),Rg=d.object({type:d.literal(J.enum.ActionExecutionResult),actionName:d.string(),actionExecutionId:d.string(),result:d.string()}),Ng=d.object({type:d.literal(J.enum.AgentStateMessage),threadId:d.string(),agentName:d.string(),nodeName:d.string(),runId:d.string(),active:d.boolean(),role:d.string(),state:d.string(),running:d.boolean()}),Og=d.object({type:d.literal(J.enum.MetaEvent),name:_g,value:d.any()}),Mg=d.object({type:d.literal(J.enum.RunError),message:d.string(),code:d.string().optional()});d.discriminatedUnion("type",[Tg,Sg,Ag,kg,Cg,Ig,Rg,Ng,Og,Mg]),d.object({id:d.string(),role:d.string(),content:d.string(),parentMessageId:d.string().optional()}),d.object({id:d.string(),name:d.string(),arguments:d.any(),parentMessageId:d.string().optional()}),d.object({id:d.string(),result:d.any(),actionExecutionId:d.string(),actionName:d.string()});var Lg=t=>{if(typeof t=="string")return t;if(!Array.isArray(t))return;let e=t.filter(n=>n.type==="text").map(n=>n.text).filter(n=>n.length>0);if(e.length!==0)return e.join(`
11
+ `)},Pg=(t,e,n)=>r=>{let o={},i=!0,s=!0,a="",l=null,c=null,u=[],m={},y=f=>{typeof f=="object"&&f&&("messages"in f&&delete f.messages,o=f)};return r.pipe(Le(f=>{switch(f.type){case v.TEXT_MESSAGE_START:{let h=f;return[{type:J.enum.TextMessageStart,messageId:h.messageId,role:h.role}]}case v.TEXT_MESSAGE_CONTENT:{let h=f;return[{type:J.enum.TextMessageContent,messageId:h.messageId,content:h.delta}]}case v.TEXT_MESSAGE_END:{let h=f;return[{type:J.enum.TextMessageEnd,messageId:h.messageId}]}case v.TOOL_CALL_START:{let h=f;return u.push({id:h.toolCallId,type:"function",function:{name:h.toolCallName,arguments:""}}),s=!0,m[h.toolCallId]=h.toolCallName,[{type:J.enum.ActionExecutionStart,actionExecutionId:h.toolCallId,actionName:h.toolCallName,parentMessageId:h.parentMessageId}]}case v.TOOL_CALL_ARGS:{let h=f,g=u.find(S=>S.id===h.toolCallId);if(!g)return console.warn(`TOOL_CALL_ARGS: No tool call found with ID '${h.toolCallId}'`),[];g.function.arguments+=h.delta;let x=!1;if(c){let S=c.find(_=>_.tool==g.function.name);if(S)try{let _=JSON.parse(Uo(g.function.arguments));S.tool_argument&&S.tool_argument in _?(y({...o,[S.state_key]:_[S.tool_argument]}),x=!0):S.tool_argument||(y({...o,[S.state_key]:_}),x=!0)}catch{}}return[{type:J.enum.ActionExecutionArgs,actionExecutionId:h.toolCallId,args:h.delta},...x?[{type:J.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:s}]:[]]}case v.TOOL_CALL_END:{let h=f;return[{type:J.enum.ActionExecutionEnd,actionExecutionId:h.toolCallId}]}case v.TOOL_CALL_RESULT:{let h=f;return[{type:J.enum.ActionExecutionResult,actionExecutionId:h.toolCallId,result:h.content,actionName:m[h.toolCallId]||"unknown"}]}case v.RAW:return[];case v.CUSTOM:{let h=f;switch(h.name){case"Exit":i=!1;break;case"PredictState":c=h.value;break}return[{type:J.enum.MetaEvent,name:h.name,value:h.value}]}case v.STATE_SNAPSHOT:return y(f.snapshot),[{type:J.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:s}];case v.STATE_DELTA:{let h=f,g=uo.applyPatch(o,h.delta,!0,!1);return g?(y(g.newDocument),[{type:J.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:s}]):[]}case v.MESSAGES_SNAPSHOT:return l=f.messages,[{type:J.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:i,role:"assistant",state:JSON.stringify({...o,...l?{messages:l}:{}}),active:!0}];case v.RUN_STARTED:return[];case v.RUN_FINISHED:return l&&(o.messages=l),Object.keys(o).length===0?[]:[{type:J.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:i,role:"assistant",state:JSON.stringify({...o,...l?{messages:Dg(l)}:{}}),active:!1}];case v.RUN_ERROR:{let h=f;return[{type:J.enum.RunError,message:h.message,code:h.code}]}case v.STEP_STARTED:return a=f.stepName,u=[],c=null,[{type:J.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:!0}];case v.STEP_FINISHED:return u=[],c=null,[{type:J.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:!1}];default:return[]}}))};function Dg(t){let e=[];for(let n of t)if(n.role==="assistant"||n.role==="user"||n.role==="system"){let r=Lg(n.content);if(r){let o={id:n.id,role:n.role,content:r};e.push(o)}if(n.role==="assistant"&&n.toolCalls&&n.toolCalls.length>0)for(let o of n.toolCalls){let i={id:o.id,name:o.function.name,arguments:JSON.parse(o.function.arguments),parentMessageId:n.id};e.push(i)}}else if(n.role==="tool"){let r="unknown";for(let i of t)if(i.role==="assistant"&&i.toolCalls?.length){for(let s of i.toolCalls)if(s.id===n.toolCallId){r=s.function.name;break}}let o={id:n.id,result:n.content,actionExecutionId:n.toolCallId,actionName:r};e.push(o)}return e}var yi=t=>e=>{let n=ur(t),r,o,i,s,a=()=>{if(!r||s!=="text")throw Error("No text message to close");let m={type:v.TEXT_MESSAGE_END,messageId:r.messageId};return s=void 0,r=void 0,n?.event("TRANSFORM","TEXT_MESSAGE_END",m,{messageId:m.messageId}),m},l=()=>{if(!o||s!=="tool")throw Error("No tool call to close");let m={type:v.TOOL_CALL_END,toolCallId:o.toolCallId};return s=void 0,o=void 0,n?.event("TRANSFORM","TOOL_CALL_END",m,{toolCallId:m.toolCallId}),m},c=()=>{if(!i||s!=="reasoning")throw Error("No reasoning message to close");let m={type:v.REASONING_MESSAGE_END,messageId:i.messageId};return s=void 0,i=void 0,n?.event("TRANSFORM","REASONING_MESSAGE_END",m,{messageId:m.messageId}),m},u=()=>s==="text"?[a()]:s==="tool"?[l()]:s==="reasoning"?[c()]:[];return e.pipe(Le(m=>{switch(m.type){case v.TEXT_MESSAGE_START:case v.TEXT_MESSAGE_CONTENT:case v.TEXT_MESSAGE_END:case v.TOOL_CALL_START:case v.TOOL_CALL_ARGS:case v.TOOL_CALL_END:case v.TOOL_CALL_RESULT:case v.STATE_SNAPSHOT:case v.STATE_DELTA:case v.MESSAGES_SNAPSHOT:case v.CUSTOM:case v.RUN_STARTED:case v.RUN_FINISHED:case v.RUN_ERROR:case v.STEP_STARTED:case v.STEP_FINISHED:case v.THINKING_START:case v.THINKING_END:case v.THINKING_TEXT_MESSAGE_START:case v.THINKING_TEXT_MESSAGE_CONTENT:case v.THINKING_TEXT_MESSAGE_END:case v.REASONING_START:case v.REASONING_MESSAGE_START:case v.REASONING_MESSAGE_CONTENT:case v.REASONING_MESSAGE_END:case v.REASONING_END:return[...u(),m];case v.RAW:case v.ACTIVITY_SNAPSHOT:case v.ACTIVITY_DELTA:case v.REASONING_ENCRYPTED_VALUE:return[m];case v.TEXT_MESSAGE_CHUNK:let y=m,f=[];if((s!=="text"||y.messageId!==void 0&&y.messageId!==r?.messageId)&&f.push(...u()),s!=="text"){if(y.messageId===void 0)throw Error("First TEXT_MESSAGE_CHUNK must have a messageId");r={messageId:y.messageId,name:y.name},s="text";let _={type:v.TEXT_MESSAGE_START,messageId:y.messageId,role:y.role||"assistant",...y.name!==void 0&&{name:y.name}};f.push(_),n?.event("TRANSFORM","TEXT_MESSAGE_START",_,{messageId:y.messageId})}if(y.delta!==void 0){let _={type:v.TEXT_MESSAGE_CONTENT,messageId:r.messageId,delta:y.delta};f.push(_),n?.event("TRANSFORM","TEXT_MESSAGE_CONTENT",_,{messageId:r.messageId})}return f;case v.TOOL_CALL_CHUNK:let h=m,g=[];if((s!=="tool"||h.toolCallId!==void 0&&h.toolCallId!==o?.toolCallId)&&g.push(...u()),s!=="tool"){if(h.toolCallId===void 0)throw Error("First TOOL_CALL_CHUNK must have a toolCallId");if(h.toolCallName===void 0)throw Error("First TOOL_CALL_CHUNK must have a toolCallName");o={toolCallId:h.toolCallId,toolCallName:h.toolCallName,parentMessageId:h.parentMessageId},s="tool";let _={type:v.TOOL_CALL_START,toolCallId:h.toolCallId,toolCallName:h.toolCallName,parentMessageId:h.parentMessageId};g.push(_),n?.event("TRANSFORM","TOOL_CALL_START",_,{toolCallId:h.toolCallId,toolCallName:h.toolCallName})}if(h.delta!==void 0){let _={type:v.TOOL_CALL_ARGS,toolCallId:o.toolCallId,delta:h.delta};g.push(_),n?.event("TRANSFORM","TOOL_CALL_ARGS",_,{toolCallId:o.toolCallId})}return g;case v.REASONING_MESSAGE_CHUNK:let x=m,S=[];if((s!=="reasoning"||x.messageId&&x.messageId!==i?.messageId)&&S.push(...u()),s!=="reasoning"){if(x.messageId===void 0)throw Error("First REASONING_MESSAGE_CHUNK must have a messageId");i={messageId:x.messageId},s="reasoning";let _={type:v.REASONING_MESSAGE_START,messageId:x.messageId};S.push(_),n?.event("TRANSFORM","REASONING_MESSAGE_START",_,{messageId:x.messageId})}if(x.delta!==void 0){let _={type:v.REASONING_MESSAGE_CONTENT,messageId:i.messageId,delta:x.delta};S.push(_),n?.event("TRANSFORM","REASONING_MESSAGE_CONTENT",_,{messageId:i.messageId})}return S}return m.type,[]}),tn(()=>{u()}))};function Ug(t,e=new Date){return t.expiresAt===void 0?!1:new Date(t.expiresAt)<=e}function Jd(t,e){let n=new Set(t.map(s=>s.id)),r=new Set(Object.keys(e)),o=[...n].filter(s=>!r.has(s));if(o.length>0)throw Error(`buildResumeArray: missing responses for open interrupts: ${o.join(", ")}`);let i=[...r].filter(s=>!n.has(s));if(i.length>0)throw Error(`buildResumeArray: responses reference unknown interrupt ids: ${i.join(", ")}`);return t.map(s=>{let a=e[s.id];if(a.status==="resolved"){let l={interruptId:s.id,status:"resolved"};return a.payload!==void 0&&(l.payload=a.payload),l}return{interruptId:s.id,status:"cancelled"}})}var xi=class{runNext(t,e){return e.run(t).pipe(yi(!1))}runNextWithState(t,e){let n=q(t.messages||[]),r=q(t.state||{}),o=new yo;return Qd(t,o,e,[]).subscribe(i=>{i.messages!==void 0&&(n=i.messages),i.state!==void 0&&(r=i.state)}),this.runNext(t,e).pipe(Po(async i=>(o.next(i),await new Promise(s=>setTimeout(s,0)),{event:i,messages:q(n),state:q(r)})))}},Hg=class extends xi{constructor(t){super(),this.fn=t}run(t,e){return this.fn(t,e)}};function Fg(t){let e=t.content;if(Array.isArray(e)){let n=e.filter(r=>typeof r=="object"&&!!r&&"type"in r&&r.type==="text"&&typeof r.text=="string").map(r=>r.text).join("");return{...t,content:n}}return typeof e=="string"?t:{...t,content:""}}var zg=class extends xi{run(t,e){let{parentRunId:n,...r}=t,o={...r,messages:r.messages.map(Fg)};return this.runNext(o,e)}},Wd="THINKING_START",Xd="THINKING_END",Yd="THINKING_TEXT_MESSAGE_START",Kd="THINKING_TEXT_MESSAGE_CONTENT",Zd="THINKING_TEXT_MESSAGE_END",Gg=class extends xi{constructor(...t){super(...t),this.currentReasoningId=null,this.currentMessageId=null}warnAboutTransformation(t,e){typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(`AG-UI is converting ${t} to ${e}. To remove this warning, upgrade your AG-UI integration package (e.g. @ag-ui/langgraph). To surpress it, set SUPPRESS_TRANSFORMATION_WARNINGS=true in your .env file.`)}run(t,e){return this.currentReasoningId=null,this.currentMessageId=null,this.runNext(t,e).pipe(en(n=>this.transformEvent(n)))}transformEvent(t){switch(t.type){case Wd:{this.currentReasoningId=_e();let{title:e,...n}=t;return this.warnAboutTransformation(Wd,v.REASONING_START),{...n,type:v.REASONING_START,messageId:this.currentReasoningId}}case Yd:return this.currentMessageId=_e(),this.warnAboutTransformation(Yd,v.REASONING_MESSAGE_START),{...t,type:v.REASONING_MESSAGE_START,messageId:this.currentMessageId,role:"assistant"};case Kd:{let{delta:e,...n}=t;return this.warnAboutTransformation(Kd,v.REASONING_MESSAGE_CONTENT),{...n,type:v.REASONING_MESSAGE_CONTENT,messageId:this.currentMessageId??_e(),delta:e}}case Zd:{let e=this.currentMessageId??_e();return this.warnAboutTransformation(Zd,v.REASONING_MESSAGE_END),{...t,type:v.REASONING_MESSAGE_END,messageId:e}}case Xd:{let e=this.currentReasoningId??_e();return this.warnAboutTransformation(Xd,v.REASONING_END),{...t,type:v.REASONING_END,messageId:e}}default:return t}}};function $g(t){return t.startsWith("image/")?"image":t.startsWith("audio/")?"audio":t.startsWith("video/")?"video":"document"}function Bg(t){return typeof t=="object"&&!!t&&"type"in t&&t.type==="binary"&&"mimeType"in t&&typeof t.mimeType=="string"}function Vg(t){let e=$g(t.mimeType);return t.data?{type:e,source:{type:"data",value:t.data,mimeType:t.mimeType},...t.filename?{metadata:{filename:t.filename}}:{}}:t.url?{type:e,source:{type:"url",value:t.url,mimeType:t.mimeType},...t.filename?{metadata:{filename:t.filename}}:{}}:t}function jg(t){let e=t.content;if(!Array.isArray(e))return t;let n=e.map(r=>Bg(r)?Vg(r):r);return{...t,content:n}}var qg=class extends xi{run(t,e){let n={...t,messages:t.messages.map(jg)};return this.runNext(n,e)}},Wg="0.0.57",Xg=class{get maxVersion(){return Wg}get debug(){return this._debug}set debug(t){this._debug=bi(t),this._debugLogger=fa(this._debug)}get debugLogger(){return this._debugLogger}set debugLogger(t){typeof t=="boolean"?this._debugLogger=t?fa(bi(!0)):void 0:this._debugLogger=t}constructor({agentId:t,description:e,threadId:n,initialMessages:r,initialState:o,debug:i}={}){this.subscribers=[],this.isRunning=!1,this.pendingInterrupts=[],this.middlewares=[],this.agentId=t,this.description=e??"",this.threadId=n??_t(),this.messages=q(r??[]),this.state=q(o??{}),this._debug=bi(i),this._debugLogger=fa(this._debug),dr(this.maxVersion,"0.0.39")<=0&&this.middlewares.unshift(new zg),dr(this.maxVersion,"0.0.45")<=0&&this.middlewares.unshift(new Gg),dr(this.maxVersion,"0.0.47")<=0&&this.middlewares.unshift(new qg)}subscribe(t){return this.subscribers.push(t),{unsubscribe:()=>{this.subscribers=this.subscribers.filter(e=>e!==t)}}}use(...t){let e=t.map(n=>typeof n=="function"?new Hg(n):n);return this.middlewares.push(...e),this}async runAgent(t,e){try{this.isRunning=!0,this.agentId=this.agentId??_t();let n=this.prepareRunAgentInput(t);this.debugLogger?.lifecycle("LIFECYCLE","Run started:",{agentId:this.agentId,threadId:this.threadId});let r,o=new Set(this.messages.map(l=>l.id)),i=[{onRunFinishedEvent:l=>{l.outcome==="success"&&(r=l.result)}},...this.subscribers,e??{}];await this.onInitialize(n,i),this.activeRunDetach$=new ct;let s;this.activeRunCompletionPromise=new Promise(l=>{s=l}),await Mo(bo(()=>this.middlewares.length===0?this.run(n):this.middlewares.reduceRight((l,c)=>({run:u=>c.run(u,l),get messages(){return l.messages},get state(){return l.state}}),this).run(n),yi(this.debugLogger),ma(this.debugLogger),l=>l.pipe(Do(this.activeRunDetach$)),l=>this.apply(n,l,i),l=>this.processApplyEvents(n,l,i),ar(l=>(this.debugLogger?.lifecycle("LIFECYCLE","Run errored:",{agentId:this.agentId,error:l instanceof Error?l.message:String(l)}),this.isRunning=!1,this.onError(n,l,i))),tn(()=>{this.debugLogger?.lifecycle("LIFECYCLE","Run finished:",{agentId:this.agentId,threadId:this.threadId}),this.isRunning=!1,this.onFinalize(n,i),s?.(),s=void 0,this.activeRunCompletionPromise=void 0,this.activeRunDetach$=void 0}))(ue(null)));let a=q(this.messages).filter(l=>!o.has(l.id));return{result:r,newMessages:a}}finally{this.isRunning=!1}}connect(t){throw new Us}async connectAgent(t,e){try{this.isRunning=!0,this.agentId=this.agentId??_t();let n=this.prepareRunAgentInput(t),r,o=new Set(this.messages.map(l=>l.id)),i=[{onRunFinishedEvent:l=>{l.outcome==="success"&&(r=l.result)}},...this.subscribers,e??{}];await this.onInitialize(n,i),this.activeRunDetach$=new ct;let s;this.activeRunCompletionPromise=new Promise(l=>{s=l}),await Mo(bo(()=>Lo(()=>this.connect(n)),yi(this.debugLogger),ma(this.debugLogger),l=>l.pipe(Do(this.activeRunDetach$)),l=>this.apply(n,l,i),l=>this.processApplyEvents(n,l,i),ar(l=>(this.isRunning=!1,l instanceof Us?xo:this.onError(n,l,i))),tn(()=>{this.isRunning=!1,this.onFinalize(n,i),s?.(),s=void 0,this.activeRunCompletionPromise=void 0,this.activeRunDetach$=void 0}))(ue(null)),{defaultValue:void 0});let a=q(this.messages).filter(l=>!o.has(l.id));return{result:r,newMessages:a}}finally{this.isRunning=!1}}abortRun(){}async detachActiveRun(){if(!this.activeRunDetach$)return;let t=this.activeRunCompletionPromise??Promise.resolve();this.activeRunDetach$.next(),this.activeRunDetach$?.complete(),await t}apply(t,e,n){return Qd(t,e,this,n,this.debugLogger)}processApplyEvents(t,e,n){return e.pipe(Js(r=>{r.messages&&(this.messages=r.messages,n.forEach(o=>{o.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:t})})),r.state&&(this.state=r.state,n.forEach(o=>{o.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:t})}))}))}prepareRunAgentInput(t){let e=q(this.messages).filter(n=>n.role!=="activity");return{threadId:this.threadId,runId:t?.runId||_t(),tools:q(t?.tools??[]),context:q(t?.context??[]),forwardedProps:q(t?.forwardedProps??{}),state:q(this.state),messages:e,...t?.resume===void 0?{}:{resume:q(t.resume)}}}async onInitialize(t,e){if(this.pendingInterrupts.length>0){let r=new Set((t.resume??[]).map(i=>i.interruptId)),o=this.pendingInterrupts.map(i=>i.id).filter(i=>!r.has(i));if(o.length>0)throw new ne(`Thread has ${o.length} pending interrupt(s) not addressed by resume: ${o.join(", ")}`);for(let i of this.pendingInterrupts)if(Ug(i))throw new ne(`Interrupt ${i.id} expired at ${i.expiresAt}`)}let n=await K(e,this.messages,this.state,(r,o,i)=>r.onRunInitialized?.({messages:o,state:i,agent:this,input:t}));(n.messages!==void 0||n.state!==void 0)&&(n.messages&&(this.messages=n.messages,t.messages=n.messages,e.forEach(r=>{r.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:t})})),n.state&&(this.state=n.state,t.state=n.state,e.forEach(r=>{r.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:t})})))}onError(t,e,n){return Jt(K(n,this.messages,this.state,(r,o,i)=>r.onRunFailed?.({error:e,messages:o,state:i,agent:this,input:t}))).pipe(en(r=>{let o=r;if((o.messages!==void 0||o.state!==void 0)&&(o.messages!==void 0&&(this.messages=o.messages,n.forEach(i=>{i.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:t})})),o.state!==void 0&&(this.state=o.state,n.forEach(i=>{i.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:t})}))),o.stopPropagation!==!0){let i=String(e);if(!(e.name==="AbortError"||e.message==="Fetch is aborted"||e.message==="signal is aborted without reason"||e.message==="component unmounted"||i==="component unmounted"))throw console.error("Agent execution failed:",e),e}return{}}))}async onFinalize(t,e){let n=await K(e,this.messages,this.state,(r,o,i)=>r.onRunFinalized?.({messages:o,state:i,agent:this,input:t}));(n.messages!==void 0||n.state!==void 0)&&(n.messages!==void 0&&(this.messages=n.messages,e.forEach(r=>{r.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:t})})),n.state!==void 0&&(this.state=n.state,e.forEach(r=>{r.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:t})})))}clone(){let t=Object.create(Object.getPrototypeOf(this));return t.agentId=this.agentId,t.description=this.description,t.threadId=this.threadId,t.messages=q(this.messages),t.state=q(this.state),t._debug=this._debug,t._debugLogger=this._debugLogger,t.isRunning=this.isRunning,t.subscribers=[...this.subscribers],t.middlewares=[...this.middlewares],t.pendingInterrupts=q(this.pendingInterrupts),t}addMessage(t){this.messages.push(t),(async()=>{for(let e of this.subscribers)await e.onNewMessage?.({message:t,messages:this.messages,state:this.state,agent:this});if(t.role==="assistant"&&t.toolCalls)for(let e of t.toolCalls)for(let n of this.subscribers)await n.onNewToolCall?.({toolCall:e,messages:this.messages,state:this.state,agent:this});for(let e of this.subscribers)await e.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}addMessages(t){this.messages.push(...t),(async()=>{for(let e of t){for(let n of this.subscribers)await n.onNewMessage?.({message:e,messages:this.messages,state:this.state,agent:this});if(e.role==="assistant"&&e.toolCalls)for(let n of e.toolCalls)for(let r of this.subscribers)await r.onNewToolCall?.({toolCall:n,messages:this.messages,state:this.state,agent:this})}for(let e of this.subscribers)await e.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}setMessages(t){this.messages=q(t),(async()=>{for(let e of this.subscribers)await e.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}setState(t){this.state=q(t),(async()=>{for(let e of this.subscribers)await e.onStateChanged?.({messages:this.messages,state:this.state,agent:this})})()}legacy_to_be_removed_runAgentBridged(t){this.agentId=this.agentId??_t();let e=this.prepareRunAgentInput(t);return(this.middlewares.length===0?this.run(e):this.middlewares.reduceRight((n,r)=>({run:o=>r.run(o,n),get messages(){return n.messages},get state(){return n.state}}),this).run(e)).pipe(yi(this.debugLogger),ma(this.debugLogger),Pg(this.threadId,e.runId,this.agentId),n=>n.pipe(en(r=>(this.debugLogger?.event("LEGACY","Event:",r,{type:r.type}),r))))}},eu=class extends Xg{requestInit(t){return{method:"POST",headers:{...this.headers,"Content-Type":"application/json",Accept:"text/event-stream"},body:JSON.stringify(t),signal:this.abortController.signal}}runAgent(t,e){return this.abortController=t?.abortController??new AbortController,super.runAgent(t,e)}abortRun(){this.abortController.abort(),super.abortRun()}constructor(t){super(t),this.abortController=new AbortController,this.url=t.url,this.headers=q(t.headers??{}),this.fetch=t.fetch??((e,n)=>fetch(e,n))}run(t){return Eg(yg(()=>this.fetch(this.url,this.requestInit(t))),this.debugLogger)}clone(){let t=super.clone();t.url=this.url,t.headers=q(this.headers??{}),t.fetch=this.fetch;let e=new AbortController,n=this.abortController.signal;return n.aborted&&e.abort(n.reason),t.abortController=e,t}};var Yg=/\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;function tu(t,e){let n=[];return{text:t.replace(Yg,(o,i)=>{let s=e[i];return s==null||s===""?(n.includes(i)||n.push(i),o):String(s)}),missing:n}}function Kg(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.name=="string"&&typeof e.title=="string"&&(e.prompt===void 0||typeof e.prompt=="string")}function ba(t){return Array.isArray(t)?t.filter(Kg):[]}var pr=class{#t=new Map;register(e){this.#t.set(e.name,e)}has(e){return this.#t.has(e)}get(e){let n=this.#t.get(e);if(n===void 0)throw new Error(`tool "${e}" is not registered`);return n}tools(){return[...this.#t.values()].map(e=>({name:e.name,description:e.description,parameters:e.parameters}))}};function ya(t){return t[Kn]===!0}function wi(t){return t[Zn]===!0}function Ei(t,e){return Object.getOwnPropertyDescriptor(t,e).set}var Zg=Ei(HTMLInputElement.prototype,"value"),Qg=Ei(HTMLTextAreaElement.prototype,"value"),Jg=Ei(HTMLSelectElement.prototype,"value"),ev=Ei(HTMLInputElement.prototype,"checked");function rn(t,e){t instanceof HTMLTextAreaElement?Qg.call(t,e):t instanceof HTMLSelectElement?Jg.call(t,e):Zg.call(t,e)}function hr(t,e){ev.call(t,e)}var xa="#4f46e5",tv="rgba(79, 70, 229, 0.4)",nv="--ag-ui-accent";function fr(t){return new Promise(e=>{setTimeout(e,t)})}function _i(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function wa(t){return t<=0||_i()?Promise.resolve():fr(t)}function Ti(t,e){let n=window.getComputedStyle(t).getPropertyValue(nv).trim();return n===""?e:n}function nu(t){return`0 0 0 3px ${Ti(t,tv)}`}async function Ea(t,e,n={}){let r=n.charDelayMs??35;rn(t,""),t.dispatchEvent(new Event("input",{bubbles:!0}));for(let o of e)rn(t,t.value+o),t.dispatchEvent(new Event("input",{bubbles:!0})),r>0&&await fr(r);t.dispatchEvent(new Event("change",{bubbles:!0}))}async function _a(t,e={}){let n=e.highlightMs??280,r=t.style.outline,o=t.style.outlineOffset;t.style.outline=`2px solid ${Ti(t,xa)}`,t.style.outlineOffset="2px",await fr(n),t.style.outline=r,t.style.outlineOffset=o,t.click()}var rv=600,ov=100;function vt(t,e={}){let n=_i();return t.scrollIntoView({block:"center",inline:"nearest",behavior:n?"auto":"smooth"}),n?Promise.resolve():new Promise(r=>{let o,i=()=>{clearTimeout(o),document.removeEventListener("scroll",s,!0),document.removeEventListener("scrollend",i,!0),r()},s=()=>{document.removeEventListener("scroll",s,!0),clearTimeout(o),o=setTimeout(i,e.settleMs??rv)};o=setTimeout(i,ov),document.addEventListener("scroll",s,!0),document.addEventListener("scrollend",i,!0)})}var iv=1200,sv=1/3;async function ru(t,e,n){(e.focus??n)&&t.focus({preventScroll:!0});let r=e.flashMs??iv;if(r<=0)return;let o=t.style.outline,i=t.style.outlineOffset,s=t.style.transition,a=e.color??Ti(t,xa);t.style.outline=`3px solid ${a}`,t.style.outlineOffset="2px";let l=_i()?0:Math.round(r*sv);await fr(r-l),l>0&&(t.style.transition=`outline-color ${l}ms ease-out`,t.style.outline="3px solid transparent",await fr(l)),t.style.outline=o,t.style.outlineOffset=i,t.style.transition=s}function av(t,e={}){return ru(t,e,!1)}function Ta(t,e={}){return ru(t,e,!0)}async function Sa(t,e={}){let n=e.pressMs??140,r=t.style.transform,o=t.style.transition,i=t.style.boxShadow;t.style.transition="transform 80ms ease",t.style.transform="scale(0.96)",t.style.boxShadow=nu(t),await wa(n),t.style.transform=r,t.style.transition=o,t.style.boxShadow=i,t.click()}function lv(t,e){for(let n of Array.from(t.options))if(n.value===e||n.text===e)return n;return null}async function Aa(t,e,n={}){let r=lv(t,e);if(r===null)throw new Error(`no <option> matching "${e}"`);let o=n.highlightMs??220,i=t.style.outline,s=t.style.outlineOffset;t.style.outline=`2px solid ${Ti(t,xa)}`,t.style.outlineOffset="2px",await wa(o),rn(t,r.value),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),t.style.outline=i,t.style.outlineOffset=s}async function ka(t,e,n={}){let r=n.flashMs??200,o=t.style.boxShadow;t.style.boxShadow=nu(t),await wa(r),hr(t,e),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),t.style.boxShadow=o}var Ca={SCROLL:"scroll",DRAG:"drag"};function Ia(t,e){let n=[];return t.has(Ca.SCROLL)&&n.push(cv(e)),t.has(Ca.DRAG)&&n.push(dv(e)),n}function cv(t){return{name:"scroll_to",description:"Scroll a target into view. `target` is `top`, `bottom`, or a CSS selector / page-map element id. Read-only: it changes nothing on the page.",parameters:{type:"object",properties:{target:{type:"string"}},required:["target"],[Pe]:"Scroll into view"},handler:e=>{let n=String(e.target??"");if(n==="top"||n==="bottom"){let o=n==="top"?0:document.body.scrollHeight;return window.scrollTo({top:o,behavior:"smooth"}),{scrolled:!0,target:n}}let r=t(n);if(r===null)throw new Error(`no element matching "${n}"`);return vt(r),{scrolled:!0,target:n}}}}function dv(t){return{name:"drag_and_drop",description:"Drag the `from` element onto the `to` element (CSS selectors or page-map element ids), firing the page's native drag-and-drop. Use for reordering sortable lists. The page decides what the drop commits.",parameters:{type:"object",properties:{from:{type:"string"},to:{type:"string"}},required:["from","to"],[Pe]:"Drag and drop"},handler:e=>{let n=String(e.from??""),r=String(e.to??""),o=t(n);if(o===null)throw new Error(`no element matching "${n}"`);let i=t(r);if(i===null)throw new Error(`no element matching "${r}"`);return uv(o,i),{dragged:!0,from:n,to:r}}}}function uv(t,e){let n=new DataTransfer;mr(t,"dragstart",n),mr(e,"dragenter",n),mr(e,"dragover",n),mr(e,"drop",n),mr(t,"dragend",n)}function mr(t,e,n){let r=new Event(e,{bubbles:!0,cancelable:!0});r.dataTransfer=n,t.dispatchEvent(r)}function Ra(t,e){return!e||t===null?[]:[{description:"page_map",value:JSON.stringify(t())}]}function Si(t){let e=[{name:`read_${t.name}`,description:`Read the "${t.name}" state.`,parameters:{type:"object",properties:{},required:[],[Pe]:`Read ${t.name}`},handler:()=>t.read()}],n=t.write;return n!==void 0&&e.push({name:`set_${t.name}`,description:`Update the "${t.name}" state.`,parameters:{...t.schema??{type:"object"},[Kn]:!0,[Pe]:`Update ${t.name}`},handler:r=>n(r)}),e}var pv=Si;function Na(t){let e={};if(!Array.isArray(t))return e;for(let n of t){if(n===null||typeof n!="object")continue;let r=n,o=r.name,i=r.summary,s=r.description;typeof o=="string"&&typeof i=="string"&&(e[o]=typeof s=="string"?{name:o,summary:i,description:s}:{name:o,summary:i})}return e}var ou=/:([A-Za-z_][A-Za-z0-9_]*)/g;function hv(t){return[...t.matchAll(ou)].map(e=>e[0].slice(1))}function fv(t,e,n){let r={...n};return{path:e.replace(ou,(i,s)=>{let a=n[s];if(a==null||String(a)==="")throw new Error(`route "${t}" requires path param "${s}"`);return delete r[s],encodeURIComponent(String(a))}),leftover:r}}function mv(t,e){let n=new URLSearchParams;for(let[o,i]of Object.entries(e))n.set(o,String(i));let r=n.toString();return r===""?t:`${t}?${r}`}function Oa(t,e){return[{name:"list_routes",description:"List the routes the app can navigate to. Each route's `pathParams` names the dynamic segments to pass as `params` to `navigate_to_route`.",parameters:{type:"object",properties:{},required:[],[Pe]:"List pages"},handler:()=>t().map(n=>({...n,pathParams:hv(n.path)}))},{name:"navigate_to_route",description:"Navigate to one of the app's routes by its id, filling any dynamic `:name` path segments (and extra query params) from `params`.",parameters:{type:"object",properties:{route_id:{type:"string"},params:{type:"object"}},required:["route_id"],[Zn]:!0,[Pe]:"Navigate"},handler:n=>{let r=n.route_id,o=t().find(u=>u.id===r);if(o===void 0)throw new Error(`unknown route "${String(r)}"`);let i=n.params??{},{path:s,leftover:a}=fv(o.id,o.path,i),l=mv(s,a),c=e();return c!==null?c(l):window.location.assign(l),{navigated:!0,path:l}}}]}var ee={title:"Assistant",chatHistory:"Chat history",newChat:"New chat",collapse:"Collapse",expand:"Expand",expandUnread:"Expand \u2014 {count} unread",toggleTheme:"Toggle theme",copyCode:"Copy",copied:"Copied",copyFailed:"Copy failed",checkpoints:"Continue a run",noCheckpoints:"Nothing to continue yet.",resumeRun:"Resume",forkRun:"Fork",forkedRun:"branched",conversation:"Conversation",jumpToLatest:"Jump to latest",announceResponding:"Assistant is responding",announceAnswerReady:"Assistant answered",announceAwaitingDecision:"{count} action is waiting for your approval",announceStopped:"Response stopped",announceFailed:"The response failed",thinking:"Assistant is thinking\u2026",thoughts:"Thoughts",stopped:"\u23F9 Stopped",connectionLost:"Connection lost",noResult:"No result returned.",declinedAction:"User declined the action.",navigating:"Navigating\u2026",historyReplaced:"The server replaced this conversation's history. Reload to see the updated transcript.",chartUndrawable:"A chart could not be drawn from the data sent, so it was removed.",historyCompacted:"Earlier turns condensed to fit the context window ({count} removed)",usingSkill:"Using skill {name}",runInterrupted:"The previous response didn\u2019t finish \u2014 the page changed before it arrived.",pageMoved:"The page changed since you last looked at it. Call read_page to see the current page, then retry.",attachmentsStillUploading:"{n} file still uploading \u2014 it was not sent with this message and is still attached.",skillNeeds:"\u201C{title}\u201D needs {fields} \u2014 fill it in below, then send.",message:"Message",inputPlaceholder:"Ask anything\u2026",send:"Send",stop:"Stop",attachFiles:"Attach files",recordVoice:"Record voice",stopRecording:"Stop recording",transcribing:"Transcribing\u2026",transcriptionFailed:"Transcription failed",recordingLimit:"Stopped at the {n}-minute limit \u2014 transcribing what was recorded.",toolRunning:"running\u2026",toolDeferred:"waiting for you",toolDone:"\u2713 done",toolError:"\u26A0 error",toolDeclined:"\u2298 declined",resizePanel:"Resize the chat panel",decisionApproved:"approved by you",decisionDeclined:"declined by you",argumentsLabel:"Arguments",resultLabel:"Result",errorLabel:"Error",declinedLabel:"Declined",details:"Details",subAgentWorking:"Working\u2026",subAgentSteps:"Steps the sub-agent took",approvalEditArgs:"Edit the arguments before approving",approvalArgsInvalid:"That is not valid JSON, so nothing was sent.",approvalArgsNotAnObject:"Arguments have to be a JSON object.",suggestions:"Suggested follow-ups",messageActions:"Message actions",quoteSelection:"Quote",copyMessage:"Copy message",retryMessage:"Try again",feedbackUp:"Good answer",feedbackDown:"Poor answer",confirmAction:"Confirm action",confirmAlways:"Always allow",confirmRun:"Run \u201C{tool}\u201D?",confirm:"Confirm",cancel:"Cancel",approveAction:"Approve action",approvalPrompt:"Approve this action?",approve:"Approve",deny:"Deny",askUserAction:"Question",otherOption:"Other\u2026",answerPlaceholder:"Type your answer\u2026",submit:"Submit",chats:"Chats",noConversations:"No conversations yet.",rename:"Rename",renameConversation:"Rename conversation",delete:"Delete",deleteConversation:"Delete conversation",deletePrompt:"Delete?",tooLarge:"Too large (max {size})",fileTypeNotAllowed:"File type not allowed",uploadFailed:"upload failed",retry:"Retry",retryUpload:"Retry upload",remove:"Remove",removeAttachment:"Remove attachment",justNow:"just now",minutesAgo:"{n}m ago",hoursAgo:"{n}h ago",daysAgo:"{n}d ago",weeksAgo:"{n}w ago"};function Ma(t){let e={...ee};for(let n of Object.keys(t)){let r=t[n];r!==void 0&&(e[n]=r)}return e}function iu(t,e){let n=document.createElement("button");return n.type="button",n.className=`approval-btn approval-btn--${t}`,n.setAttribute("part",`approval-button approval-${t}`),n.textContent=e,n}function La(t,e,n={}){let r=n.strings??ee;return new Promise(o=>{let i=document.createElement("div");i.className="approval",i.setAttribute("part","approval"),e.toolName!==void 0&&i.setAttribute("data-tool-name",e.toolName),i.setAttribute("role","group"),i.setAttribute("aria-label",r.approveAction);let s=document.createElement("div");s.className="approval-body",s.setAttribute("part","approval-body"),s.textContent=e.message??r.approvalPrompt;let a=gv(e,n,r),l=document.createElement("div");l.className="approval-actions",l.setAttribute("part","approval-actions");let c=iu("deny",r.deny),u=iu("approve",r.approve),m=!1,y=f=>{m||(m=!0,c.disabled=!0,u.disabled=!0,i.setAttribute("data-resolved",f?"approved":"denied"),o(f))};if(c.addEventListener("click",()=>y(!1)),u.addEventListener("click",()=>{a!==null&&!a.commit()||y(!0)}),n.signal?.addEventListener("abort",()=>y(!1),{once:!0}),l.append(c,u),i.append(s,...a===null?[]:[a.root],l),t.appendChild(i),n.signal?.aborted===!0){y(!1);return}u.focus()})}function gv(t,e,n){let{onEdit:r}=e;if(r===void 0||t.args===void 0)return null;let o=JSON.stringify(t.args,null,2),i=document.createElement("div");i.className="approval-edit",i.setAttribute("part","approval-edit");let s=document.createElement("textarea");s.className="approval-args",s.setAttribute("part","approval-args"),s.setAttribute("aria-label",n.approvalEditArgs),s.rows=Math.min(10,o.split(`
12
+ `).length),s.value=o;let a=document.createElement("div");return a.className="approval-error",a.setAttribute("part","approval-error"),a.setAttribute("role","alert"),a.hidden=!0,i.append(s,a),{root:i,commit:()=>{if(s.value===o)return!0;let l;try{l=JSON.parse(s.value)}catch{return a.textContent=n.approvalArgsInvalid,a.hidden=!1,s.focus(),!1}return typeof l!="object"||l===null||Array.isArray(l)?(a.textContent=n.approvalArgsNotAnObject,a.hidden=!1,s.focus(),!1):(a.hidden=!0,r(l),!0)}}}function Pa(t,e){for(let n of Array.from(t.querySelectorAll("pre"))){let r=n.querySelector("code");r===null||n.querySelector(".code-copy")!==null||(n.classList.add("has-copy"),n.append(vv(r,e)))}}function vv(t,e){let n=t.textContent,r=document.createElement("button");return r.type="button",r.className="code-copy",r.setAttribute("part","code-copy"),r.textContent=e.copyCode,r.title=e.copyCode,r.setAttribute("aria-label",e.copyCode),r.addEventListener("click",()=>{bv(n).then(o=>{yv(r,o?e.copied:e.copyFailed,e)})}),r}async function bv(t){let e=navigator.clipboard;if(e===void 0)return!1;try{return await e.writeText(t),!0}catch{return!1}}function yv(t,e,n){t.textContent=e,t.dataset.state=e===n.copied?"copied":"failed",setTimeout(()=>{t.textContent=n.copyCode,delete t.dataset.state},1500)}function Da(t){let e=document.createElement("div");e.className="attachment-chips",e.setAttribute("part","attachment-chips");for(let n of t)e.appendChild(xv(n));return e}function xv(t){let e=document.createElement("div");e.className="attachment-chip attachment-chip--ready",e.setAttribute("part","attachment-chip");let n=document.createElement("span");n.className="attachment-chip-icon",n.setAttribute("part","attachment-chip-icon"),n.innerHTML=Ua(t.mime),n.setAttribute("aria-hidden","true");let r=document.createElement("span");r.className="attachment-chip-name",r.setAttribute("part","attachment-chip-name"),r.textContent=t.name,r.title=t.name;let o=document.createElement("span");return o.className="attachment-chip-size",o.setAttribute("part","attachment-chip-size"),o.textContent=Ai(t.size),e.append(n,r,o),e}function Ua(t){return t.startsWith("image/")?ic:t==="application/pdf"?sc:t.startsWith("text/")?ac:oc}function Ai(t){if(t<1024)return`${t} B`;let e=["KB","MB","GB"],n=t/1024,r=0;for(;n>=1024&&r<e.length-1;)n/=1024,r+=1;return`${n<10?Math.round(n*10)/10:Math.round(n)} ${e[r]}`}var ki=class{element;#t;#n;#e=[];constructor(e){this.#t=e,this.#n=e.strings??ee,this.element=document.createElement("div"),this.element.className="attachment-tray",this.element.setAttribute("part","attachment-tray"),this.element.hidden=!0}add(e){let n={localId:_e(),file:e,status:De.UPLOADING,progress:0,ref:null,error:"",controller:null};this.#e.push(n);let r=this.#s(e);if(r!==null){n.status=De.ERROR,n.error=r,this.#o(),this.#t.onChange?.();return}this.#o(),this.#t.onChange?.(),this.#r(n)}readyRefs(){let e=[];for(let n of this.#e)n.ref!==null&&e.push(n.ref);return e}hasPending(){return this.#e.some(e=>e.status===De.UPLOADING)}pendingCount(){return this.#e.filter(e=>e.status===De.UPLOADING).length}isEmpty(){return this.#e.length===0}clearReady(){this.#e=this.#e.filter(e=>e.status===De.UPLOADING),this.#o()}clear(){for(let e of this.#e)e.controller?.abort();this.#e=[],this.#o()}dispose(){for(let e of this.#e)e.controller?.abort()}#s(e){return this.#t.maxBytes>0&&e.size>this.#t.maxBytes?this.#n.tooLarge.replace("{size}",Ai(this.#t.maxBytes)):wv(this.#t.accept,e)?null:this.#n.fileTypeNotAllowed}#r(e){let n=this.#s(e.file);if(n!==null){e.status=De.ERROR,e.error=n,this.#o(),this.#t.onChange?.();return}e.status=De.UPLOADING,e.progress=0,e.error="";let r=new AbortController;e.controller=r,this.#o(),this.#t.upload(e.file,o=>{e.progress=o,this.#o()},r.signal).then(o=>{e.status=De.READY,e.ref=o}).catch(o=>{e.status=De.ERROR,e.error=o instanceof Error?o.message:this.#n.uploadFailed}).finally(()=>{e.controller=null,this.#o(),this.#t.onChange?.()})}#i(e){e.controller?.abort(),this.#e=this.#e.filter(n=>n!==e),this.#o(),this.#t.onChange?.()}#o(){this.element.replaceChildren(),this.element.hidden=this.#e.length===0;for(let e of this.#e)this.element.appendChild(this.#u(e))}#u(e){let n=document.createElement("div");n.className=`attachment-chip attachment-chip--${e.status}`,n.setAttribute("part","attachment-chip");let r=document.createElement("span");r.className="attachment-chip-icon",r.setAttribute("part","attachment-chip-icon"),r.innerHTML=Ua(e.file.type),r.setAttribute("aria-hidden","true");let o=document.createElement("span");o.className="attachment-chip-name",o.setAttribute("part","attachment-chip-name"),o.textContent=e.file.name,o.title=e.file.name;let i=document.createElement("span");if(i.className="attachment-chip-size",i.setAttribute("part","attachment-chip-size"),i.textContent=e.status===De.ERROR?e.error:Ai(e.file.size),n.append(r,o,i),e.status===De.UPLOADING){let a=document.createElement("div");a.className="attachment-chip-bar",a.setAttribute("part","attachment-chip-bar");let l=document.createElement("div");l.className="attachment-chip-bar-fill",l.setAttribute("part","attachment-chip-bar-fill"),l.style.width=`${Math.round(e.progress*100)}%`,a.appendChild(l),n.appendChild(a)}if(e.status===De.ERROR){let a=document.createElement("button");a.type="button",a.className="attachment-chip-retry",a.setAttribute("part","attachment-chip-retry"),a.title=this.#n.retry,a.setAttribute("aria-label",this.#n.retryUpload),a.textContent="\u21BB",a.addEventListener("click",()=>this.#r(e)),n.appendChild(a)}let s=document.createElement("button");return s.type="button",s.className="attachment-chip-remove",s.setAttribute("part","attachment-chip-remove"),s.title=this.#n.remove,s.setAttribute("aria-label",this.#n.removeAttachment),s.textContent="\u2715",s.addEventListener("click",()=>this.#i(e)),n.appendChild(s),n}};function wv(t,e){let n=t.split(",").map(i=>i.trim().toLowerCase()).filter(i=>i!=="");if(n.length===0)return!0;let r=e.type.toLowerCase(),o=e.name.toLowerCase();return n.some(i=>i.startsWith(".")?o.endsWith(i):i.endsWith("/*")?r.startsWith(i.slice(0,-1)):r===i)}var Ev="http://www.w3.org/2000/svg";var He={top:20,right:12,bottom:30,left:44},Ii=480-He.left-He.right,Ci=220-He.top-He.bottom,su=["var(--ag-ui-chart-1, #4f7cff)","var(--ag-ui-chart-2, #21b573)","var(--ag-ui-chart-3, #e0803c)","var(--ag-ui-chart-4, #b563d8)","var(--ag-ui-chart-5, #d84f6e)","var(--ag-ui-chart-6, #3ba7c4)"];function on(t){return su[t%su.length]}function dt(t,e){let n=document.createElementNS(Ev,t);for(let[r,o]of Object.entries(e))n.setAttribute(r,String(o));return n}function au(t,e){let n=dt("text",{"font-size":10,fill:"currentColor","fill-opacity":.65,...e});return n.textContent=t,n}function _v(t){let e=[];return t.labels.forEach((n,r)=>{let o=0;for(let i of t.series)o+=i.points[r]??0,e.push(o)}),e}function Tv(t){let e=t.kind==="stacked"?_v(t):t.series.flatMap(o=>[...o.points]),n=Math.max(0,...e),r=Math.min(0,...e);return n===r?{min:r,max:n+1}:{min:r,max:n}}function sn(t,e,n){return He.top+Ci-(t-e)/(n-e)*Ci}function Ha(t,e){let n=Ii/e;return He.left+n*t+n/2}function Sv(t,e,n,r){for(let o of[n,r]){let i=sn(o,n,r);t.appendChild(dt("line",{x1:He.left,y1:i,x2:480-He.right,y2:i,stroke:"currentColor","stroke-opacity":o===n?.35:.12})),t.appendChild(au(String(Math.round(o)),{x:He.left-6,y:i+4,"text-anchor":"end"}))}e.labels.forEach((o,i)=>{t.appendChild(au(o,{x:Ha(i,e.labels.length),y:220-He.bottom+16,"text-anchor":"middle"}))})}function Av(t,e,n,r){let o=Ii/e.labels.length,i=o*.7/e.series.length,s=sn(n,n,r);e.series.forEach((a,l)=>{a.points.forEach((c,u)=>{let m=sn(c,n,r);t.appendChild(dt("rect",{x:He.left+o*u+o*.15+i*l,y:m,width:i,height:Math.max(1,s-m),fill:on(l),rx:2}))})})}function kv(t,e,n,r){let o=Ii/e.labels.length,i=o*.7,s=e.labels.map(()=>0);e.series.forEach((a,l)=>{a.points.forEach((c,u)=>{let m=s[u]??0,y=m+c;s[u]=y;let f=sn(y,n,r);t.appendChild(dt("rect",{x:He.left+o*u+o*.15,y:f,width:i,height:Math.max(1,sn(m,n,r)-f),fill:on(l)}))})})}function Cv(t,e,n,r){e.series.forEach((o,i)=>{let s=o.points.map((a,l)=>`${Ha(l,e.labels.length)},${sn(a,n,r)}`).join(" ");t.appendChild(dt("polyline",{points:s,fill:"none",stroke:on(i),"stroke-width":2,"stroke-linejoin":"round"}))})}function Iv(t,e,n,r){e.series.forEach((o,i)=>{o.points.forEach((s,a)=>{t.appendChild(dt("circle",{cx:Ha(a,e.labels.length),cy:sn(s,n,r),r:4,fill:on(i),"fill-opacity":.85}))})})}function Rv(t,e){let n=e.reduce((a,l)=>a+l,0),r=480/2,o=He.top+Ci/2,i=Math.min(Ii,Ci)/2;if(n===0){t.appendChild(dt("circle",{cx:r,cy:o,r:i,fill:"none",stroke:"currentColor","stroke-opacity":.3}));return}let s=-Math.PI/2;e.forEach((a,l)=>{let c=a/n*Math.PI*2,u=s+c;if(c>=Math.PI*2)t.appendChild(dt("circle",{cx:r,cy:o,r:i,fill:on(l)}));else{let m=r+i*Math.cos(s),y=o+i*Math.sin(s),f=r+i*Math.cos(u),h=o+i*Math.sin(u),g=c>Math.PI?1:0;t.appendChild(dt("path",{d:`M ${r} ${o} L ${m} ${y} A ${i} ${i} 0 ${g} 1 ${f} ${h} Z`,fill:on(l)}))}s=u})}function Nv(t){if(t.length<2)return null;let e=document.createElement("div");return e.className="chart-legend",e.setAttribute("part","chart-legend"),t.forEach((n,r)=>{let o=document.createElement("span");o.className="chart-legend-item";let i=document.createElement("span");i.className="chart-legend-swatch",i.style.background=on(r),o.append(i,document.createTextNode(n)),e.appendChild(o)}),e}function gr(t){if(t.labels.length===0||t.series.length===0)return null;let e=document.createElement("div");if(e.className="chart-block",e.setAttribute("part","chart-block"),t.title!==void 0&&t.title!==""){let o=document.createElement("div");o.className="chart-title",o.setAttribute("part","chart-title"),o.textContent=t.title,e.appendChild(o)}let n=dt("svg",{viewBox:"0 0 480 220",width:"100%",role:"img"});if(n.setAttribute("aria-label",t.title??`${t.kind} chart`),t.kind==="pie"){let o=t.series[0];Rv(n,o.points.map(i=>Math.max(0,i)))}else{let{min:o,max:i}=Tv(t);Sv(n,t,o,i),t.kind==="bar"?Av(n,t,o,i):t.kind==="stacked"?kv(n,t,o,i):t.kind==="line"?Cv(n,t,o,i):Iv(n,t,o,i)}e.appendChild(n);let r=Nv(t.kind==="pie"?t.labels:t.series.map(o=>o.label));return r!==null&&e.appendChild(r),e}var Ov=["bar","line","pie","scatter","stacked"];function Mv(t){return Ov.includes(t)?t:"bar"}function Lv(t){if(!Array.isArray(t))return null;let e=[];for(let n of t){if(typeof n!="number"||!Number.isFinite(n)||Math.abs(n)>1e15)return null;e.push(n)}return e}function Pv(t){if(!Array.isArray(t))return null;for(let e=0;e<t.length;e+=1)if(typeof t[e]!="string")return null;return t}function Un(t){if(typeof t!="object"||t===null)return null;let e=t,n=Pv(e.labels);if(n===null||!Array.isArray(e.series))return null;let r=[];for(let s of e.series){if(typeof s!="object"||s===null)return null;let a=s,l=Lv(a.points);if(l===null||l.length!==n.length)return null;r.push({label:typeof a.label=="string"?a.label:"",points:l})}if(r.length===0||r.length*n.length>2e4||n.length>2e3)return null;let o=Mv(e.kind),i=e.title;return typeof i=="string"?{kind:o,title:i,labels:n,series:r}:{kind:o,labels:n,series:r}}var Ri="render_chart";function Dv(t){let e=Un(t);return e===null?null:gr(e)}function Uv(t){let e=Un(t);return e!==null&&e.labels.length>0&&e.series.length>0}var Hv="chart not rendered: expected labels (strings) and series, each with one finite number per label";function lu(){return{name:Ri,description:"Show a chart in the conversation. Supply the data and the page draws it. Every series must have exactly one point per label.",parameters:{type:"object",properties:{kind:{type:"string",enum:["bar","line","pie","scatter","stacked"]},title:{type:"string"},labels:{type:"array",items:{type:"string"}},series:{type:"array",items:{type:"object",properties:{label:{type:"string"},points:{type:"array",items:{type:"number"}}},required:["points"]}}},required:["labels","series"],"x-summary":"Draw a chart"},handler:t=>Uv(t)?"chart rendered":Hv,render:Dv}}function vr(t,e=Date.now(),n=ee){if(!Number.isFinite(t))return n.justNow;let r=Math.round((e-t)/1e3);if(r<60)return n.justNow;let o=Math.round(r/60);if(o<60)return n.minutesAgo.replace("{n}",String(o));let i=Math.round(o/60);if(i<24)return n.hoursAgo.replace("{n}",String(i));let s=Math.round(i/24);return s<7?n.daysAgo.replace("{n}",String(s)):n.weeksAgo.replace("{n}",String(Math.round(s/7)))}function cu(t){return t.preview!==void 0&&t.preview!==null&&t.preview!==""?t.preview:null}function du(t){return t.replace(/\s+/g," ").trim()}var br=class{element;#t;#n;#e;#s=null;#r=null;#i;#o=[];constructor(e,n=ee){this.#t=e,this.#i=n,this.element=document.createElement("div"),this.element.className="checkpoints",this.element.setAttribute("part","checkpoints"),this.element.setAttribute("role","dialog"),this.element.setAttribute("aria-label",n.checkpoints),this.element.tabIndex=-1,this.element.hidden=!0;let r=document.createElement("div");r.className="checkpoints-header",r.setAttribute("part","checkpoints-header"),this.#e=document.createElement("span"),this.#e.className="checkpoints-title",this.#e.setAttribute("part","checkpoints-title"),this.#e.textContent=n.checkpoints,r.append(this.#e),this.#n=document.createElement("div"),this.#n.className="checkpoints-list",this.#n.setAttribute("part","checkpoints-list"),this.element.append(r,this.#n),this.element.addEventListener("keydown",o=>this.#a(o))}setRuns(e){this.#o=e,this.#p()}setRelativeTimeFormatter(e){this.#r=e}#u(e){return this.#r!==null?this.#r(e):vr(e,Date.now(),this.#i)}setStrings(e){this.#i=e,this.element.setAttribute("aria-label",e.checkpoints),this.#e.textContent=e.checkpoints,this.#p()}open(){this.open_||(this.#s=this.#c(),this.element.hidden=!1,(this.#d()[0]??this.element).focus())}close(){this.open_&&(this.element.hidden=!0,this.#s?.focus(),this.#s=null)}#c(){return this.element.getRootNode().activeElement}#d(){return Array.from(this.element.querySelectorAll("button, [tabindex]")).filter(e=>!e.hidden)}#a(e){if(e.key==="Escape"){e.stopPropagation(),this.close();return}if(e.key!=="Tab")return;let n=this.#d(),r=n[0],o=n[n.length-1],i=this.#c();e.shiftKey&&i===r?(e.preventDefault(),o?.focus()):!e.shiftKey&&i===o&&(e.preventDefault(),r?.focus())}get open_(){return!this.element.hidden}#p(){if(this.#n.replaceChildren(),this.#o.length===0){let n=document.createElement("div");n.className="checkpoints-empty",n.setAttribute("part","checkpoints-empty"),n.textContent=this.#i.noCheckpoints,this.#n.append(n);return}let e=this.#v();for(let n of this.#o)this.#n.append(this.#m(n,e))}#v(){let e=new Set,n=new Set;for(let r of this.#o){let o=cu(r);if(o===null)continue;let i=du(o);e.has(i)&&n.add(i),e.add(i)}return n}#m(e,n){let r=document.createElement("div");r.className="checkpoint-row",r.setAttribute("part","checkpoint-row");let o=cu(e),i=e.started_at===null?null:this.#u(Date.parse(e.started_at)),s=document.createElement("span");if(s.className="checkpoint-label",s.setAttribute("part","checkpoint-label"),s.textContent=o??i??e.run_id,r.append(s),o!==null&&i!==null){let l=document.createElement("span");l.className="checkpoint-time",l.setAttribute("part","checkpoint-time"),l.textContent=i,r.append(l)}if((o===null?i!==null:n.has(du(o)))&&e.run_id!==""){let l=document.createElement("span");l.className="checkpoint-id",l.setAttribute("part","checkpoint-id"),l.textContent=e.run_id.slice(0,8),l.title=e.run_id,r.append(l)}if(e.parent_run_id!==null){let l=document.createElement("span");l.className="checkpoint-branch",l.setAttribute("part","checkpoint-branch"),l.textContent=this.#i.forkedRun,l.title=e.parent_run_id,r.append(l)}return r.append(this.#y(e.run_id,"resume",this.#i.resumeRun),this.#y(e.run_id,"fork",this.#i.forkRun)),r}#y(e,n,r){let o=document.createElement("button");return o.type="button",o.className=`checkpoint-action checkpoint-${n}`,o.setAttribute("part",`checkpoint-action checkpoint-${n}`),o.textContent=r,o.addEventListener("click",()=>{this.close(),this.#t(e,n)}),o}};function Fa(t,e){let n=document.createElement("button");return n.type="button",n.className=`confirm-btn confirm-btn--${t}`,n.setAttribute("part",`confirm-button confirm-${t}`),n.textContent=e,n}function za(t,e,n={}){let r=n.strings??ee;return new Promise(o=>{let i=document.createElement("div");i.className="confirm",i.setAttribute("part","confirm"),i.setAttribute("data-tool-name",e.toolName),i.setAttribute("role","group"),i.setAttribute("aria-label",r.confirmAction);let s=document.createElement("div");s.className="confirm-body",s.setAttribute("part","confirm-body"),s.textContent=e.message??r.confirmRun.replace("{tool}",e.toolName);let a=document.createElement("pre");a.className="confirm-args",a.setAttribute("part","confirm-args"),a.textContent=JSON.stringify(e.args,null,2),a.hidden=Object.keys(e.args).length===0;let l=document.createElement("div");l.className="confirm-actions",l.setAttribute("part","confirm-actions");let c=Fa("cancel",r.cancel),u=n.onAlwaysAllow===void 0?null:Fa("always",r.confirmAlways.replace("{tool}",e.toolName)),m=Fa("confirm",r.confirm),y=!1,f=h=>{y||(y=!0,i.remove(),o(h))};if(c.addEventListener("click",()=>f(!1)),m.addEventListener("click",()=>f(!0)),u?.addEventListener("click",()=>{n.onAlwaysAllow?.(),f(!0)}),n.signal?.addEventListener("abort",()=>f(!1),{once:!0}),l.append(c,...u===null?[]:[u],m),i.append(s,a,l),t.appendChild(i),n.signal?.aborted===!0){f(!1);return}m.focus()})}function Ga(t,e){if(hu(t)!==null)return;let n=Ni(t,e.strings),r=e.text;r!==void 0&&n.appendChild(Fv(e.strings,r)),e.onFeedback!==void 0&&n.append(uu("up",e.strings.feedbackUp,e.onFeedback),uu("down",e.strings.feedbackDown,e.onFeedback))}function Ni(t,e){let n=hu(t);if(n!==null)return n;let r=document.createElement("div");return r.className="message-actions",r.setAttribute("part","message-actions"),r.setAttribute("role","group"),r.setAttribute("aria-label",e.messageActions),t.after(r),r}function hu(t){let e=t.nextElementSibling;return e?.classList.contains("message-actions")===!0?e:null}function Oi(t,e,n){let r=document.createElement("button");r.type="button",r.className=`message-action message-action--${t}`,r.setAttribute("part",`message-action message-action-${t}`),r.title=e,r.setAttribute("aria-label",e);let o=document.createElement("span");return o.setAttribute("aria-hidden","true"),o.textContent=n,r.appendChild(o),r}function Fv(t,e){let n=Oi("copy",t.copyMessage,"\u2398");return n.addEventListener("click",()=>{navigator.clipboard.writeText(e()).then(()=>pu(n,t.copied,t.copyMessage),()=>pu(n,t.copyFailed,t.copyMessage))}),n}function uu(t,e,n){let r=Oi(t==="up"?"up":"down",e,t==="up"?"\u{1F44D}":"\u{1F44E}");return r.addEventListener("click",()=>{let o=r.getAttribute("aria-pressed")==="true";r.setAttribute("aria-pressed",o?"false":"true"),n(t)}),r.setAttribute("aria-pressed","false"),r}function pu(t,e,n){t.title=e,t.setAttribute("aria-label",e),t.classList.add("message-action--confirmed"),setTimeout(()=>{t.title=n,t.setAttribute("aria-label",n),t.classList.remove("message-action--confirmed")},1500)}var zv=500;function yr(t,e=[],n){for(let r of Zv(e)){if(!t.contains(r.startContainer)||!t.contains(r.endContainer))continue;let o=document.createRange();o.setStart(r.startContainer,r.startOffset),o.setEnd(r.endContainer,r.endOffset);let i=Vv(o).trim();if(i!=="")return{text:i,rect:Kv(o,n)}}return null}function $a(t){let e=Gv(t);return e.length===0?"":`${Bv(e.join(`
13
13
  `)).split(`
14
14
  `).map(o=>`> ${o}`.trimEnd()).join(`
15
15
  `)}
16
16
 
17
- `}function Lv(t){let e=t.split(/\r\n?|\n/).map(i=>i.trimEnd()),n=e.filter(i=>i!=="").map(Pv),r=n.length===0?0:Math.min(...n),o=[];for(let i of e){let s=i.slice(r);s===""&&(o.length===0||o[o.length-1]==="")||o.push(s)}for(;o[o.length-1]==="";)o.pop();return o}function Pv(t){return t.length-t.trimStart().length}function Dv(t){return t.length>500?`${t.slice(0,500).trimEnd()}...`:t}function Uv(t){let e="";for(let n of Gv(t)){let r=n.parentElement;if(!$v(r))continue;let o=n===t.startContainer?t.startOffset:0,i=n===t.endContainer?t.endOffset:n.data.length;e+=Hv(n.data.slice(o,i),r)}return e}function Hv(t,e){return zv.has(Fv(e))?t:t.replace(/[^\S\n]*\n[^\S\n]*/g,`
18
- `).replace(/[^\S\n]+/g," ")}var zv=new Set(["pre","pre-wrap","break-spaces"]);function Fv(t){return window.getComputedStyle(t).whiteSpace}function Gv(t){let e=t.commonAncestorContainer;if(e.nodeType===Node.TEXT_NODE)return[e];let n=[],r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(let o=r.nextNode();o!==null;o=r.nextNode())t.intersectsNode(o)&&n.push(o);return n}function $v(t){return typeof t.checkVisibility!="function"?!0:t.checkVisibility({contentVisibilityAuto:!0,opacityProperty:!0,visibilityProperty:!0})}function Bv(t,e){let n=[...t.getClientRects()];if(n.length===0)return t.getBoundingClientRect();if(e===void 0)return n[0];let r=n[0],o=cu(r,e);for(let i of n.slice(1)){let s=cu(i,e);s<o&&(o=s,r=i)}return r}function cu(t,e){let n=Math.max(t.left-e.x,0,e.x-t.right),r=Math.max(t.top-e.y,0,e.y-t.bottom);return Math.hypot(n,r)}function Vv(t){let e=window.getSelection();if(e===null)return[];let n=[...jv(e,t)];return e.rangeCount>0&&n.push(e.getRangeAt(0)),n}function jv(t,e){let n=t.getComposedRanges;if(n===void 0)return[];try{return n.call(t,{shadowRoots:e})}catch{return n.call(t,...e)}}var Fa=6,qv=`
17
+ `}function Gv(t){let e=t.split(/\r\n?|\n/).map(i=>i.trimEnd()),n=e.filter(i=>i!=="").map($v),r=n.length===0?0:Math.min(...n),o=[];for(let i of e){let s=i.slice(r);s===""&&(o.length===0||o[o.length-1]==="")||o.push(s)}for(;o[o.length-1]==="";)o.pop();return o}function $v(t){return t.length-t.trimStart().length}function Bv(t){return t.length>500?`${t.slice(0,500).trimEnd()}...`:t}function Vv(t){let e="";for(let n of Xv(t)){let r=n.parentElement;if(!Yv(r))continue;let o=n===t.startContainer?t.startOffset:0,i=n===t.endContainer?t.endOffset:n.data.length;e+=jv(n.data.slice(o,i),r)}return e}function jv(t,e){return qv.has(Wv(e))?t:t.replace(/[^\S\n]*\n[^\S\n]*/g,`
18
+ `).replace(/[^\S\n]+/g," ")}var qv=new Set(["pre","pre-wrap","break-spaces"]);function Wv(t){return window.getComputedStyle(t).whiteSpace}function Xv(t){let e=t.commonAncestorContainer;if(e.nodeType===Node.TEXT_NODE)return[e];let n=[],r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(let o=r.nextNode();o!==null;o=r.nextNode())t.intersectsNode(o)&&n.push(o);return n}function Yv(t){return typeof t.checkVisibility!="function"?!0:t.checkVisibility({contentVisibilityAuto:!0,opacityProperty:!0,visibilityProperty:!0})}function Kv(t,e){let n=[...t.getClientRects()];if(n.length===0)return t.getBoundingClientRect();if(e===void 0)return n[0];let r=n[0],o=fu(r,e);for(let i of n.slice(1)){let s=fu(i,e);s<o&&(o=s,r=i)}return r}function fu(t,e){let n=Math.max(t.left-e.x,0,e.x-t.right),r=Math.max(t.top-e.y,0,e.y-t.bottom);return Math.hypot(n,r)}function Zv(t){let e=window.getSelection();if(e===null)return[];let n=[...Qv(e,t)];return e.rangeCount>0&&n.push(e.getRangeAt(0)),n}function Qv(t,e){let n=t.getComposedRanges;if(n===void 0)return[];try{return n.call(t,{shadowRoots:e})}catch{return n.call(t,...e)}}var Ba=6,Jv=`
19
19
  .ag-ui-quote-offer {
20
20
  position: fixed;
21
21
  z-index: 2147483000;
@@ -37,14 +37,14 @@ Error: ${x}`)}}return u()}case v.MESSAGES_SNAPSHOT:{let f=await Y(r,s,a,(h,g,x)=
37
37
  .ag-ui-quote-offer[data-below="true"] {
38
38
  transform: translate(-50%, 0);
39
39
  }
40
- `;function Ga(t){let{within:e,exclude:n,onQuote:r}=t,o=new CSSStyleSheet;o.replaceSync(qv),document.adoptedStyleSheets=[...document.adoptedStyleSheets,o];let i=document.createElement("button");i.type="button",i.className="ag-ui-quote-offer",i.textContent=t.label,i.hidden=!0,document.body.append(i);let s="",a=()=>{i.hidden=!0,s=""},l=u=>{if(u.composedPath().includes(n)){a();return}if(Wv()){a();return}let m=u instanceof MouseEvent?{x:u.clientX,y:u.clientY}:void 0,y=vr(e,[],m);if(y===null){a();return}s=y.text,Xv(i,y.rect)},c=u=>{i.contains(u.target)||a()};return e.addEventListener("mouseup",l),e.addEventListener("keyup",l),e.addEventListener("mousedown",c),document.addEventListener("scroll",a,!0),window.addEventListener("resize",a),i.addEventListener("mousedown",u=>{u.preventDefault()}),i.addEventListener("click",()=>{let u=s;window.getSelection()?.removeAllRanges(),a(),r(u)}),{element:i,detach(){e.removeEventListener("mouseup",l),e.removeEventListener("keyup",l),e.removeEventListener("mousedown",c),document.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a),i.remove(),document.adoptedStyleSheets=document.adoptedStyleSheets.filter(u=>u!==o)}}}function Wv(){let t=document.activeElement;return t===null?!1:t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.isContentEditable===!0}function Xv(t,e){t.hidden=!1;let n=e.top<Fa+t.offsetHeight;t.dataset.below=String(n),t.style.top=`${n?e.bottom+Fa:e.top-Fa}px`;let r=t.offsetWidth/2,o=e.left+e.width/2,i=document.documentElement.clientWidth;t.style.left=`${Math.min(Math.max(o,r),i-r)}px`}function $a(t){let e=t.replace(/[._-]+/g," ").trim();return e===""?t:e.charAt(0).toUpperCase()+e.slice(1)}function Kv(t){let e=document.createElement("input");return e.type="text",e.className="question-input",e.setAttribute("part","question-input"),e.placeholder=t,e}function Ba(t,e,n={}){let r=n.strings??le,o=e.options??[],i=o.length>0,s=!i||e.allowCustom===!0;return new Promise(a=>{let l=document.createElement("div");l.className="question",l.setAttribute("part","question"),l.setAttribute("role","group"),l.setAttribute("aria-label",r.askUserAction);let c=document.createElement("div");c.className="question-body",c.setAttribute("part","question-body"),c.textContent=e.question;let u=document.createElement("div");u.className="question-options",u.setAttribute("part","question-options");let m=`q-${o.length}-${e.question.length}`,y=[];for(let U of o){let K=document.createElement("label");K.className="question-choice",K.setAttribute("part","question-choice");let oe=document.createElement("input");oe.type="radio",oe.name=m,oe.value=U,oe.setAttribute("part","question-radio");let We=document.createElement("span");We.setAttribute("part","question-choice-text"),We.textContent=U,K.append(oe,We),u.appendChild(K),y.push(oe)}let f=null,h=null;if(s){if(h=Kv(r.answerPlaceholder),i){let U=document.createElement("label");U.className="question-choice",U.setAttribute("part","question-choice"),f=document.createElement("input"),f.type="radio",f.name=m,f.value="",f.setAttribute("part","question-radio");let K=document.createElement("span");K.setAttribute("part","question-choice-text"),K.textContent=r.otherOption,U.append(f,K),u.appendChild(U),h.disabled=!0}u.appendChild(h)}let g=document.createElement("div");g.className="question-actions",g.setAttribute("part","question-actions");let x=document.createElement("button");x.type="button",x.className="question-btn",x.setAttribute("part","question-button"),x.textContent=r.submit,g.appendChild(x);let S=!1,_=()=>{let U=y.find(K=>K.checked);if(U!==void 0)return U.value;if(h!==null&&(f===null||f.checked)){let K=h.value.trim();return K===""?null:K}return null},I=()=>{h!==null&&f!==null&&(h.disabled=!f.checked),x.disabled=_()===null},H=U=>{if(!S){S=!0,x.disabled=!0;for(let K of y)K.disabled=!0;f!==null&&(f.disabled=!0),h!==null&&(h.disabled=!0),l.setAttribute("data-resolved",U===""?"cancelled":"answered"),a(U)}};for(let U of[...y,...f!==null?[f]:[]])U.addEventListener("change",I);if(h?.addEventListener("input",I),h?.addEventListener("keydown",U=>{if(U.key==="Enter"){U.preventDefault();let K=_();K!==null&&H(K)}}),x.addEventListener("click",()=>{let U=_();U!==null&&H(U)}),n.signal?.addEventListener("abort",()=>H(""),{once:!0}),l.append(c,u,g),t.appendChild(l),n.signal?.aborted===!0){H("");return}I(),(i?y[0]:h)?.focus()})}function du(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function Yv(t){if(Array.isArray(t))return t}function Zv(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r,o,i,s,a=[],l=!0,c=!1;try{if(i=(n=n.call(t)).next,e!==0)for(;!(l=(r=i.call(n)).done)&&(a.push(r.value),a.length!==e);l=!0);}catch(u){c=!0,o=u}finally{try{if(!l&&n.return!=null&&(s=n.return(),Object(s)!==s))return}finally{if(c)throw o}}return a}}function Qv(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
41
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Jv(t,e){return Yv(t)||Zv(t,e)||eb(t,e)||Qv()}function eb(t,e){if(t){if(typeof t=="string")return du(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)?du(t,e):void 0}}var Su=Object.entries,uu=Object.setPrototypeOf,tb=Object.isFrozen,nb=Object.getPrototypeOf,rb=Object.getOwnPropertyDescriptor,Te=Object.freeze,Se=Object.seal,Hn=Object.create,Au=typeof Reflect<"u"&&Reflect,Ka=Au.apply,Ya=Au.construct;Te||(Te=function(e){return e});Se||(Se=function(e){return e});Ka||(Ka=function(e,n){for(var r=arguments.length,o=new Array(r>2?r-2:0),i=2;i<r;i++)o[i-2]=arguments[i];return e.apply(n,o)});Ya||(Ya=function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return new e(...r)});var Dn=me(Array.prototype.forEach),ob=me(Array.prototype.lastIndexOf),pu=me(Array.prototype.pop),Un=me(Array.prototype.push),ib=me(Array.prototype.splice),Rt=Array.isArray,xr=me(String.prototype.toLowerCase),Va=me(String.prototype.toString),hu=me(String.prototype.match),br=me(String.prototype.replace),fu=me(String.prototype.indexOf),sb=me(String.prototype.trim),ab=me(Number.prototype.toString),lb=me(Boolean.prototype.toString),mu=typeof BigInt>"u"?null:me(BigInt.prototype.toString),gu=typeof Symbol>"u"?null:me(Symbol.prototype.toString),ye=me(Object.prototype.hasOwnProperty),yr=me(Object.prototype.toString),be=me(RegExp.prototype.test),an=cb(TypeError);function me(t){return function(e){e instanceof RegExp&&(e.lastIndex=0);for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return Ka(t,e,r)}}function cb(t){return function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return Ya(t,n)}}function W(t,e){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:xr;if(uu&&uu(t,null),!Rt(e))return t;let r=e.length;for(;r--;){let o=e[r];if(typeof o=="string"){let i=n(o);i!==o&&(tb(e)||(e[r]=i),o=i)}t[o]=!0}return t}function db(t){for(let e=0;e<t.length;e++)ye(t,e)||(t[e]=null);return t}function ke(t){let e=Hn(null);for(let r of Su(t)){var n=Jv(r,2);let o=n[0],i=n[1];ye(t,o)&&(Rt(i)?e[o]=db(i):i&&typeof i=="object"&&i.constructor===Object?e[o]=ke(i):e[o]=i)}return e}function ub(t){switch(typeof t){case"string":return t;case"number":return ab(t);case"boolean":return lb(t);case"bigint":return mu?mu(t):"0";case"symbol":return gu?gu(t):"Symbol()";case"undefined":return yr(t);case"function":case"object":{if(t===null)return yr(t);let e=t,n=Ze(e,"toString");if(typeof n=="function"){let r=n(e);return typeof r=="string"?r:yr(r)}return yr(t)}default:return yr(t)}}function Ze(t,e){for(;t!==null;){let r=rb(t,e);if(r){if(r.get)return me(r.get);if(typeof r.value=="function")return me(r.value)}t=nb(t)}function n(){return null}return n}function pb(t){try{return be(t,""),!0}catch{return!1}}var vu=Te(["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"]),ja=Te(["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"]),qa=Te(["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"]),hb=Te(["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"]),Wa=Te(["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"]),fb=Te(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),bu=Te(["#text"]),yu=Te(["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"]),Xa=Te(["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","dominant-baseline","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-orientation","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"]),xu=Te(["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"]),Ri=Te(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),mb=Se(/{{[\w\W]*|^[\w\W]*}}/g),gb=Se(/<%[\w\W]*|^[\w\W]*%>/g),vb=Se(/\${[\w\W]*/g),bb=Se(/^data-[\-\w.\u00B7-\uFFFF]+$/),yb=Se(/^aria-[\-\w]+$/),wu=Se(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),xb=Se(/^(?:\w+script|data):/i),wb=Se(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Eb=Se(/^html$/i),_b=Se(/^[a-z][.\w]*(-[.\w]+)+$/i),Eu=Se(/<[/\w!]/g),_u=Se(/<[/\w]/g),Tb=Se(/<\/no(script|embed|frames)/i),Sb=Se(/\/>/i),ze={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},Ab=function(){return typeof window>"u"?null:window},kb=function(e,n){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let r=null,o="data-tt-policy-suffix";n&&n.hasAttribute(o)&&(r=n.getAttribute(o));let i="dompurify"+(r?"#"+r:"");try{return e.createPolicy(i,{createHTML(s){return s},createScriptURL(s){return s}})}catch{return console.warn("TrustedTypes policy "+i+" could not be created."),null}},Tu=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},It=function(e,n,r,o){return ye(e,n)&&Rt(e[n])?W(o.base?ke(o.base):{},e[n],o.transform):r};function ku(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Ab(),e=T=>ku(T);if(e.version="3.4.13",e.removed=[],!t||!t.document||t.document.nodeType!==ze.document||!t.Element)return e.isSupported=!1,e;let n=t.document,r=n,o=r.currentScript;t.DocumentFragment;let i=t.HTMLTemplateElement,s=t.Node,a=t.Element,l=t.NodeFilter,c=t.NamedNodeMap;c===void 0&&(t.NamedNodeMap||t.MozNamedAttrMap),t.HTMLFormElement;let u=t.DOMParser,m=t.trustedTypes,y=a.prototype,f=Ze(y,"cloneNode"),h=Ze(y,"remove"),g=Ze(y,"nextSibling"),x=Ze(y,"childNodes"),S=Ze(y,"parentNode"),_=Ze(y,"shadowRoot"),I=Ze(y,"attributes"),H=s&&s.prototype?Ze(s.prototype,"nodeType"):null,U=s&&s.prototype?Ze(s.prototype,"nodeName"):null,K=s&&s.prototype?Ze(s.prototype,"ownerDocument"):null;if(typeof i=="function"){let T=n.createElement("template");T.content&&T.content.ownerDocument&&(n=T.content.ownerDocument)}let oe,We="",Wi,wl=!1,Bn=0,El=function(){if(Bn>0)throw an('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.')},un=function(p){El(),Bn++;try{return oe.createHTML(p)}finally{Bn--}},pp=function(p){El(),Bn++;try{return oe.createScriptURL(p)}finally{Bn--}},hp=function(){return wl||(Wi=kb(m,o),wl=!0),Wi},Nr=n,Xi=Nr.implementation,_l=Nr.createNodeIterator,fp=Nr.createDocumentFragment,mp=Nr.getElementsByTagName,gp=r.importNode,ie=Tu();e.isSupported=typeof Su=="function"&&typeof S=="function"&&Xi&&Xi.createHTMLDocument!==void 0;let vp=mb,bp=gb,yp=vb,xp=bb,wp=yb,Ep=xb,Tl=wb,_p=_b,Sl=wu,se=null,Ki=W({},[...vu,...ja,...qa,...Wa,...bu]),ae=null,Yi=W({},[...yu,...Xa,...xu,...Ri]),pe=Object.seal(Hn(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}})),Vn=null,Al=null,yt=Object.seal(Hn(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),kl=!0,Zi=!0,Cl=!1,Il=!0,xt=!1,wt=!0,Ot=!1,Qi=!1,Or=null,Mr=null,Ji=!1,pn=!1,Lr=!1,Pr=!1,Rl=!0,Nl=!1,Ol="user-content-",es=!0,Dr=!1,hn={},tt=null,ts=W({},["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"]),Ml=null,Ll=W({},["audio","video","img","source","image","track"]),ns=null,Pl=W({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Ur="http://www.w3.org/1998/Math/MathML",Hr="http://www.w3.org/2000/svg",nt="http://www.w3.org/1999/xhtml",fn=nt,rs=!1,os=null,Tp=W({},[Ur,Hr,nt],Va),Dl=Te(["mi","mo","mn","ms","mtext"]),is=W({},Dl),Ul=Te(["annotation-xml"]),ss=W({},Ul),Sp=W({},["title","style","font","a","script"]),jn=null,Ap=["application/xhtml+xml","text/html"],kp="text/html",ce=null,mn=null,Cp=n.createElement("form"),Hl=function(p){return p instanceof RegExp||p instanceof Function},as=function(){let p=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(mn&&mn===p)return;(!p||typeof p!="object")&&(p={}),p=ke(p),jn=Ap.indexOf(p.PARSER_MEDIA_TYPE)===-1?kp:p.PARSER_MEDIA_TYPE,ce=jn==="application/xhtml+xml"?Va:xr,se=It(p,"ALLOWED_TAGS",Ki,{transform:ce}),ae=It(p,"ALLOWED_ATTR",Yi,{transform:ce}),os=It(p,"ALLOWED_NAMESPACES",Tp,{transform:Va}),ns=It(p,"ADD_URI_SAFE_ATTR",Pl,{transform:ce,base:Pl}),Ml=It(p,"ADD_DATA_URI_TAGS",Ll,{transform:ce,base:Ll}),tt=It(p,"FORBID_CONTENTS",ts,{transform:ce}),Vn=It(p,"FORBID_TAGS",ke({}),{transform:ce}),Al=It(p,"FORBID_ATTR",ke({}),{transform:ce}),hn=ye(p,"USE_PROFILES")?p.USE_PROFILES&&typeof p.USE_PROFILES=="object"?ke(p.USE_PROFILES):p.USE_PROFILES:!1,kl=p.ALLOW_ARIA_ATTR!==!1,Zi=p.ALLOW_DATA_ATTR!==!1,Cl=p.ALLOW_UNKNOWN_PROTOCOLS||!1,Il=p.ALLOW_SELF_CLOSE_IN_ATTR!==!1,xt=p.SAFE_FOR_TEMPLATES||!1,wt=p.SAFE_FOR_XML!==!1,Ot=p.WHOLE_DOCUMENT||!1,pn=p.RETURN_DOM||!1,Lr=p.RETURN_DOM_FRAGMENT||!1,Pr=p.RETURN_TRUSTED_TYPE||!1,Ji=p.FORCE_BODY||!1,Rl=p.SANITIZE_DOM!==!1,Nl=p.SANITIZE_NAMED_PROPS||!1,es=p.KEEP_CONTENT!==!1,Dr=p.IN_PLACE||!1,Sl=pb(p.ALLOWED_URI_REGEXP)?p.ALLOWED_URI_REGEXP:wu,fn=typeof p.NAMESPACE=="string"?p.NAMESPACE:nt,is=ye(p,"MATHML_TEXT_INTEGRATION_POINTS")&&p.MATHML_TEXT_INTEGRATION_POINTS&&typeof p.MATHML_TEXT_INTEGRATION_POINTS=="object"?ke(p.MATHML_TEXT_INTEGRATION_POINTS):W({},Dl),ss=ye(p,"HTML_INTEGRATION_POINTS")&&p.HTML_INTEGRATION_POINTS&&typeof p.HTML_INTEGRATION_POINTS=="object"?ke(p.HTML_INTEGRATION_POINTS):W({},Ul);let b=ye(p,"CUSTOM_ELEMENT_HANDLING")&&p.CUSTOM_ELEMENT_HANDLING&&typeof p.CUSTOM_ELEMENT_HANDLING=="object"?ke(p.CUSTOM_ELEMENT_HANDLING):Hn(null);if(pe=Hn(null),ye(b,"tagNameCheck")&&Hl(b.tagNameCheck)&&(pe.tagNameCheck=b.tagNameCheck),ye(b,"attributeNameCheck")&&Hl(b.attributeNameCheck)&&(pe.attributeNameCheck=b.attributeNameCheck),ye(b,"allowCustomizedBuiltInElements")&&typeof b.allowCustomizedBuiltInElements=="boolean"&&(pe.allowCustomizedBuiltInElements=b.allowCustomizedBuiltInElements),Se(pe),xt&&(Zi=!1),Lr&&(pn=!0),hn&&(se=W({},bu),ae=Hn(null),hn.html===!0&&(W(se,vu),W(ae,yu)),hn.svg===!0&&(W(se,ja),W(ae,Xa),W(ae,Ri)),hn.svgFilters===!0&&(W(se,qa),W(ae,Xa),W(ae,Ri)),hn.mathMl===!0&&(W(se,Wa),W(ae,xu),W(ae,Ri))),yt.tagCheck=null,yt.attributeCheck=null,ye(p,"ADD_TAGS")&&(typeof p.ADD_TAGS=="function"?yt.tagCheck=p.ADD_TAGS:Rt(p.ADD_TAGS)&&(se===Ki&&(se=ke(se)),W(se,p.ADD_TAGS,ce))),ye(p,"ADD_ATTR")&&(typeof p.ADD_ATTR=="function"?yt.attributeCheck=p.ADD_ATTR:Rt(p.ADD_ATTR)&&(ae===Yi&&(ae=ke(ae)),W(ae,p.ADD_ATTR,ce))),ye(p,"ADD_URI_SAFE_ATTR")&&Rt(p.ADD_URI_SAFE_ATTR)&&W(ns,p.ADD_URI_SAFE_ATTR,ce),ye(p,"FORBID_CONTENTS")&&Rt(p.FORBID_CONTENTS)&&(tt===ts&&(tt=ke(tt)),W(tt,p.FORBID_CONTENTS,ce)),ye(p,"ADD_FORBID_CONTENTS")&&Rt(p.ADD_FORBID_CONTENTS)&&(tt===ts&&(tt=ke(tt)),W(tt,p.ADD_FORBID_CONTENTS,ce)),es&&(se["#text"]=!0),Ot&&W(se,["html","head","body"]),se.table&&(W(se,["tbody"]),delete Vn.tbody),p.TRUSTED_TYPES_POLICY){if(typeof p.TRUSTED_TYPES_POLICY.createHTML!="function")throw an('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof p.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw an('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');let w=oe;oe=p.TRUSTED_TYPES_POLICY;try{We=un("")}catch(N){throw oe=w,N}}else p.TRUSTED_TYPES_POLICY===null?(oe=void 0,We=""):(oe===void 0&&(oe=hp()),oe&&typeof We=="string"&&(We=un("")));Te&&Te(p),mn=p},zl=W({},[...ja,...qa,...hb]),Fl=W({},[...Wa,...fb]),Ip=function(p,b,w){return b.namespaceURI===nt?p==="svg":b.namespaceURI===Ur?p==="svg"&&(w==="annotation-xml"||is[w]):!!zl[p]},Rp=function(p,b,w){return b.namespaceURI===nt?p==="math":b.namespaceURI===Hr?p==="math"&&ss[w]:!!Fl[p]},Np=function(p,b,w){return b.namespaceURI===Hr&&!ss[w]||b.namespaceURI===Ur&&!is[w]?!1:!Fl[p]&&(Sp[p]||!zl[p])},Op=function(p){let b=S(p);(!b||!b.tagName)&&(b={namespaceURI:fn,tagName:"template"});let w=xr(p.tagName),N=xr(b.tagName);return os[p.namespaceURI]?p.namespaceURI===Hr?Ip(w,b,N):p.namespaceURI===Ur?Rp(w,b,N):p.namespaceURI===nt?Np(w,b,N):!!(jn==="application/xhtml+xml"&&os[p.namespaceURI]):!1},Et=function(p){Un(e.removed,{element:p});try{S(p).removeChild(p)}catch{if(h(p),!S(p))throw an("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},zr=function(p){qn(p);let b=x(p);if(b){let N=[];Dn(b,L=>{Un(N,L)}),Dn(N,L=>{try{h(L)}catch{}})}let w=I(p);if(w)for(let N=w.length-1;N>=0;--N){let L=w[N],z=L&&L.name;if(typeof z=="string")try{p.removeAttribute(z)}catch{}}},Mt=function(p,b){try{Un(e.removed,{attribute:b.getAttributeNode(p),from:b})}catch{Un(e.removed,{attribute:null,from:b})}if(b.removeAttribute(p),p==="is")if(pn||Lr)try{Et(b)}catch{}else try{b.setAttribute(p,"")}catch{}},Mp=function(p){let b=I(p);if(b)for(let w=b.length-1;w>=0;--w){let N=b[w],L=N&&N.name;if(!(typeof L!="string"||ae[ce(L)]))try{p.removeAttribute(L)}catch{}}},qn=function(p){let b=[p];for(;b.length>0;){let w=b.pop();(H?H(w):w.nodeType)===ze.element&&Mp(w);let L=x(w);if(L)for(let z=L.length-1;z>=0;--z)b.push(L[z])}},Lp=function(p){if(!wt)return;let b=[p];for(;b.length>0;){let w=b.pop(),N=H?H(w):w.nodeType;if(N===ze.processingInstruction||N===ze.comment&&be(_u,w.data)){try{h(w)}catch{}continue}if(N===ze.element){let z=w,Z=ce(U?U(w):w.nodeName);try{z.hasAttribute&&z.hasAttribute("patchsrc")&&z.removeAttribute("patchsrc"),z.hasAttribute&&z.hasAttribute("for")&&Z!=="label"&&Z!=="output"&&z.removeAttribute("for")}catch{}}let L=x(w);if(L)for(let z=L.length-1;z>=0;--z)b.push(L[z])}},Gl=function(p){let b=null,w=null;if(Ji)p="<remove></remove>"+p;else{let z=hu(p,/^[\r\n\t ]+/);w=z&&z[0]}jn==="application/xhtml+xml"&&fn===nt&&(p='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+p+"</body></html>");let N=oe?un(p):p;if(fn===nt)try{b=new u().parseFromString(N,jn)}catch{}if(!b||!b.documentElement){b=Xi.createDocument(fn,"template",null);try{b.documentElement.innerHTML=rs?We:N}catch{}}let L=b.body||b.documentElement;return p&&w&&L.insertBefore(n.createTextNode(w),L.childNodes[0]||null),fn===nt?mp.call(b,Ot?"html":"body")[0]:Ot?b.documentElement:L},$l=function(p){let b=K?K(p):p.ownerDocument;return _l.call(b||p,p,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},Fr=function(p){return p=br(p,vp," "),p=br(p,bp," "),p=br(p,yp," "),p},ls=function(p){var b;p.normalize();let w=K?K(p):p.ownerDocument,N=_l.call(w||p,p,l.SHOW_TEXT|l.SHOW_COMMENT|l.SHOW_CDATA_SECTION|l.SHOW_PROCESSING_INSTRUCTION,null),L=N.nextNode();for(;L;)L.data=Fr(L.data),L=N.nextNode();let z=(b=p.querySelectorAll)===null||b===void 0?void 0:b.call(p,"template");z&&Dn(z,Z=>{gn(Z.content)&&ls(Z.content)})},Gr=function(p){let b=U?U(p):null;return typeof b!="string"||ce(b)!=="form"?!1:typeof p.nodeName!="string"||typeof p.textContent!="string"||typeof p.removeChild!="function"||p.attributes!==I(p)||typeof p.removeAttribute!="function"||typeof p.setAttribute!="function"||typeof p.namespaceURI!="string"||typeof p.insertBefore!="function"||typeof p.hasChildNodes!="function"||p.nodeType!==H(p)||p.childNodes!==x(p)},gn=function(p){if(!H||typeof p!="object"||p===null)return!1;try{return H(p)===ze.documentFragment}catch{return!1}},Wn=function(p){if(!H||typeof p!="object"||p===null)return!1;try{return typeof H(p)=="number"}catch{return!1}};function rt(T,p,b){T.length!==0&&Dn(T,w=>{w.call(e,p,b,mn)})}let Pp=function(p,b){return!!(wt&&p.hasChildNodes()&&!Wn(p.firstElementChild)&&be(Eu,p.textContent)&&be(Eu,p.innerHTML)||wt&&p.namespaceURI===nt&&b==="style"&&Wn(p.firstElementChild)||p.nodeType===ze.processingInstruction||wt&&p.nodeType===ze.comment&&be(_u,p.data))},Dp=function(p,b,w){if(!Vn[b]&&ql(b)&&(pe.tagNameCheck instanceof RegExp&&be(pe.tagNameCheck,b)||pe.tagNameCheck instanceof Function&&pe.tagNameCheck(b)))return!1;if(es&&!tt[b]){let N=S(p),L=x(p);if(L&&N){let z=L.length;for(let Z=z-1;Z>=0;--Z){let de=p===w?f(L[Z],!0):L[Z];N.insertBefore(de,g(p))}}}return Et(p),!0},Bl=function(p,b,w,N){return p.length===0?b:b===w||b===N?ke(b):b},Vl=function(p,b){if(rt(ie.beforeSanitizeElements,p,null),p!==b&&S(p)===null)return Dr&&qn(p),!0;if(Gr(p))return Et(p),!0;let w=ce(U?U(p):p.nodeName);if(se=Bl(ie.uponSanitizeElement,se,Ki,Or),rt(ie.uponSanitizeElement,p,{tagName:w,allowedTags:se}),p!==b&&S(p)===null)return Dr&&qn(p),!0;if(Pp(p,w))return Et(p),!0;if(Vn[w]||!(yt.tagCheck instanceof Function&&yt.tagCheck(w))&&!se[w]){let L=Dp(p,w,b);return L===!1&&rt(ie.afterSanitizeElements,p,null),L}if((H?H(p):p.nodeType)===ze.element&&!Op(p)||(w==="noscript"||w==="noembed"||w==="noframes")&&be(Tb,p.innerHTML))return Et(p),!0;if(xt&&p.nodeType===ze.text){let L=Fr(p.textContent);p.textContent!==L&&(Un(e.removed,{element:p.cloneNode()}),p.textContent=L)}return rt(ie.afterSanitizeElements,p,null),!1},jl=function(p,b,w){if(Al[b]||wt&&b==="patchsrc"||wt&&b==="for"&&p!=="label"&&p!=="output"||Rl&&(b==="id"||b==="name")&&(w in n||w in Cp))return!1;let N=ae[b]||yt.attributeCheck instanceof Function&&yt.attributeCheck(b,p);if(!(Zi&&be(xp,b))){if(!(kl&&be(wp,b))){if(N){if(!ns[b]){if(!be(Sl,br(w,Tl,""))){if(!((b==="src"||b==="xlink:href"||b==="href")&&p!=="script"&&fu(w,"data:")===0&&Ml[p])){if(!(Cl&&!be(Ep,br(w,Tl,"")))){if(w)return!1}}}}}else if(!(ql(p)&&(pe.tagNameCheck instanceof RegExp&&be(pe.tagNameCheck,p)||pe.tagNameCheck instanceof Function&&pe.tagNameCheck(p))&&(pe.attributeNameCheck instanceof RegExp&&be(pe.attributeNameCheck,b)||pe.attributeNameCheck instanceof Function&&pe.attributeNameCheck(b,p))||b==="is"&&pe.allowCustomizedBuiltInElements&&(pe.tagNameCheck instanceof RegExp&&be(pe.tagNameCheck,w)||pe.tagNameCheck instanceof Function&&pe.tagNameCheck(w))))return!1}}return!0},Up=W({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),ql=function(p){return!Up[xr(p)]&&be(_p,p)},Hp=function(p,b,w,N){if(oe&&typeof m=="object"&&typeof m.getAttributeType=="function"&&!w)switch(m.getAttributeType(p,b)){case"TrustedHTML":return un(N);case"TrustedScriptURL":return pp(N)}return N},zp=function(p,b,w,N){try{w?p.setAttributeNS(w,b,N):p.setAttribute(b,N),Gr(p)?Et(p):pu(e.removed)}catch{Mt(b,p)}},Wl=function(p){rt(ie.beforeSanitizeAttributes,p,null);let b=p.attributes;if(!b||Gr(p))return;ae=Bl(ie.uponSanitizeAttribute,ae,Yi,Mr);let w={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:ae,forceKeepAttr:void 0},N=b.length,L=ce(p.nodeName);for(;N--;){let z=b[N],Z=z.name,de=z.namespaceURI,Re=z.value,Ne=ce(Z),ds=Re,Ie=Z==="value"?ds:sb(ds);if(w.attrName=Ne,w.attrValue=Ie,w.keepAttr=!0,w.forceKeepAttr=void 0,rt(ie.uponSanitizeAttribute,p,w),Ie=w.attrValue,Nl&&(Ne==="id"||Ne==="name")&&fu(Ie,Ol)!==0&&(Mt(Z,p),Ie=Ol+Ie),wt&&be(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,Ie)){Mt(Z,p);continue}if(Ne==="attributename"&&hu(Ie,"href")){Mt(Z,p);continue}if(!w.forceKeepAttr){if(!w.keepAttr){Mt(Z,p);continue}if(!Il&&be(Sb,Ie)){Mt(Z,p);continue}if(xt&&(Ie=Fr(Ie)),!jl(L,Ne,Ie)){Mt(Z,p);continue}Ie=Hp(L,Ne,de,Ie),Ie!==ds&&zp(p,Z,de,Ie)}}rt(ie.afterSanitizeAttributes,p,null)},$r=function(p){let b=null,w=$l(p);for(rt(ie.beforeSanitizeShadowDOM,p,null);b=w.nextNode();)if(rt(ie.uponSanitizeShadowNode,b,null),Vl(b,p),Wl(b),gn(b.content)&&$r(b.content),(H?H(b):b.nodeType)===ze.element){let L=_(b);gn(L)&&(cs(L),$r(L))}rt(ie.afterSanitizeShadowDOM,p,null)},cs=function(p){let b=[{node:p,shadow:null}];for(;b.length>0;){let w=b.pop();if(w.shadow){$r(w.shadow);continue}let N=w.node,z=(H?H(N):N.nodeType)===ze.element,Z=x(N);if(Z)for(let de=Z.length-1;de>=0;--de)b.push({node:Z[de],shadow:null});if(z){let de=U?U(N):null;if(typeof de=="string"&&ce(de)==="template"){let Re=N.content;gn(Re)&&b.push({node:Re,shadow:null})}}if(z){let de=_(N);gn(de)&&b.push({node:null,shadow:de},{node:de,shadow:null})}}};return e.sanitize=function(T){let p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},b=null,w=null,N=null,L=null;if(rs=!T,rs&&(T="<!-->"),typeof T!="string"&&!Wn(T)&&(T=ub(T),typeof T!="string"))throw an("dirty is not a string, aborting");if(!e.isSupported)return T;Qi?(se=Or,ae=Mr):as(p),(ie.uponSanitizeElement.length>0||ie.uponSanitizeAttribute.length>0)&&(se=ke(se)),ie.uponSanitizeAttribute.length>0&&(ae=ke(ae)),e.removed=[];let z=Dr&&typeof T!="string"&&Wn(T);if(z){Lp(T);let Re=U?U(T):T.nodeName;if(typeof Re=="string"){let Ne=ce(Re);if(!se[Ne]||Vn[Ne])throw zr(T),an("root node is forbidden and cannot be sanitized in-place")}if(Gr(T))throw zr(T),an("root node is clobbered and cannot be sanitized in-place");try{cs(T)}catch(Ne){throw zr(T),Ne}}else if(Wn(T))b=Gl("<!---->"),w=b.ownerDocument.importNode(T,!0),w.nodeType===ze.element&&w.nodeName==="BODY"||w.nodeName==="HTML"?b=w:b.appendChild(w),cs(w);else{if(!pn&&!xt&&!Ot&&T.indexOf("<")===-1)return oe&&Pr?un(T):T;if(b=Gl(T),!b)return pn?null:Pr?We:""}b&&Ji&&Et(b.firstChild);let Z=z?T:b;try{let Re=$l(Z);for(;N=Re.nextNode();)Vl(N,Z),Wl(N),gn(N.content)&&$r(N.content)}catch(Re){throw z&&(zr(T),Dn(e.removed,Ne=>{Ne.element&&qn(Ne.element)})),Re}if(z)return Dn(e.removed,Re=>{Re.element&&qn(Re.element)}),xt&&ls(T),T;if(pn){if(xt&&ls(b),Lr)for(L=fp.call(b.ownerDocument);b.firstChild;)L.appendChild(b.firstChild);else L=b;return(ae.shadowroot||ae.shadowrootmode)&&(L=gp.call(r,L,!0)),L}let de=Ot?b.outerHTML:b.innerHTML;return Ot&&se["!doctype"]&&b.ownerDocument&&b.ownerDocument.doctype&&b.ownerDocument.doctype.name&&be(Eb,b.ownerDocument.doctype.name)&&(de="<!DOCTYPE "+b.ownerDocument.doctype.name+`>
42
- `+de),xt&&(de=Fr(de)),oe&&Pr?un(de):de},e.setConfig=function(){let T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};as(T),Qi=!0,Or=se,Mr=ae},e.clearConfig=function(){mn=null,Qi=!1,Or=null,Mr=null,oe=Wi,We=""},e.isValidAttribute=function(T,p,b){mn||as({});let w=ce(T),N=ce(p);return jl(w,N,b)},e.addHook=function(T,p){typeof p=="function"&&ye(ie,T)&&Un(ie[T],p)},e.removeHook=function(T,p){if(ye(ie,T)){if(p!==void 0){let b=ob(ie[T],p);return b===-1?void 0:ib(ie[T],b,1)[0]}return pu(ie[T])}},e.removeHooks=function(T){ye(ie,T)&&(ie[T]=[])},e.removeAllHooks=function(){ie=Tu()},e}var Cu=ku();function el(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var dn=el();function Du(t){dn=t}var ln={exec:()=>null};function zn(t){let e=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),o=e[r];return o||(o=t(r),e[r]=o),o}}function j(t,e=""){let n=typeof t=="string"?t:t.source,r={replace:(o,i)=>{let s=typeof i=="string"?i:i.source;return s=s.replace(Ce.caret,"$1"),n=n.replace(o,s),r},getRegex:()=>new RegExp(n,e)};return r}var Cb=((t="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+t)}catch{return!1}})(),Ce={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,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ 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,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:zn(t=>new RegExp(`^ {0,${t}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:zn(t=>new RegExp(`^ {0,${t}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:zn(t=>new RegExp(`^ {0,${t}}(?:\`\`\`|~~~)`)),headingBeginRegex:zn(t=>new RegExp(`^ {0,${t}}#`)),htmlBeginRegex:zn(t=>new RegExp(`^ {0,${t}}<(?:[a-z].*>|!--)`,"i")),blockquoteBeginRegex:zn(t=>new RegExp(`^ {0,${t}}>`))},Ib=/^(?:[ \t]*(?:\n|$))+/,Rb=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Nb=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,_r=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Ob=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,tl=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Uu=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Hu=j(Uu).replace(/bull/g,tl).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}(?:\s|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Mb=j(Uu).replace(/bull/g,tl).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}(?:\s|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),nl=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,Lb=/^[^\n]+/,rl=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Pb=j(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",rl).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Db=j(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,tl).getRegex(),Pi="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",ol=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Ub=j("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\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",ol).replace("tag",Pi).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),zu=t=>j(nl).replace("hr",_r).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~~~)[^\\n]*\\n").replace("list",t).replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Pi).getRegex(),Hb=zu(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),zb=zu(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),Fb=j(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",zb).getRegex(),il={blockquote:Fb,code:Rb,def:Pb,fences:Nb,heading:Ob,hr:_r,html:Ub,lheading:Hu,list:Db,newline:Ib,paragraph:Hb,table:ln,text:Lb},Iu=j("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",_r).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~~~)[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Pi).getRegex(),Gb={...il,lheading:Mb,table:Iu,paragraph:j(nl).replace("hr",_r).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Iu).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~~~)[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Pi).getRegex()},$b={...il,html:j(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ol).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:ln,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:j(nl).replace("hr",_r).replace("heading",` *#{1,6} *[^
43
- ]`).replace("lheading",Hu).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Bb=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Vb=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Fu=/^( {2,}|\\)\n(?!\s*$)/,jb=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,bt=/[\p{P}\p{S}]/u,Fn=/[\s\p{P}\p{S}]/u,Tr=/[^\s\p{P}\p{S}]/u,qb=j(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Fn).getRegex(),Wb=/[\p{Pi}\p{Ps}"']/u,Gu=/(?!~)[\p{P}\p{S}]/u,Xb=/(?!~)[\s\p{P}\p{S}]/u,Kb=/(?:[^\s\p{P}\p{S}]|~)/u,Yb=j(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",Cb?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),$u=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Zb=j($u,"u").replace(/punct/g,bt).getRegex(),Qb=j($u,"u").replace(/punct/g,Gu).getRegex(),Jb=/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,ey=j(Jb,"u").replace(/openQuote/g,Wb).replace(/punct/g,bt).getRegex(),Bu="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",ty=j(Bu,"gu").replace(/notPunctSpace/g,Tr).replace(/punctSpace/g,Fn).replace(/punct/g,bt).getRegex(),ny=j(Bu,"gu").replace(/notPunctSpace/g,Kb).replace(/punctSpace/g,Xb).replace(/punct/g,Gu).getRegex(),ry="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)",oy=j(ry,"gu").replace(/notPunctSpace/g,Tr).replace(/punctSpace/g,Fn).replace(/punct/g,bt).getRegex(),iy=j("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Tr).replace(/punctSpace/g,Fn).replace(/punct/g,bt).getRegex(),sy="^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)",ay=j(sy,"gu").replace(/notPunctSpace/g,Tr).replace(/punctSpace/g,Fn).replace(/punct/g,bt).getRegex(),ly=j(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,bt).getRegex(),cy="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",dy=j(cy,"gu").replace(/notPunctSpace/g,Tr).replace(/punctSpace/g,Fn).replace(/punct/g,bt).getRegex(),uy=j(/\\(punct)/,"gu").replace(/punct/g,bt).getRegex(),py=j(/^<(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(),hy=j(ol).replace("(?:-->|$)","-->").getRegex(),fy=j("^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",hy).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Oi=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,my=j(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",Oi).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Vu=j(/^!?\[(label)\]\[(ref)\]/).replace("label",Oi).replace("ref",rl).getRegex(),ju=j(/^!?\[(ref)\](?:\[\])?/).replace("ref",rl).getRegex(),gy=j("reflink|nolink(?!\\()","g").replace("reflink",Vu).replace("nolink",ju).getRegex(),Ru=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,sl={_backpedal:ln,anyPunctuation:uy,autolink:py,blockSkip:Yb,br:Fu,code:Vb,del:ln,delLDelim:ln,delRDelim:ln,emStrongLDelim:Zb,emStrongRDelimAst:ty,emStrongRDelimUnd:iy,escape:Bb,link:my,nolink:ju,punctuation:qb,reflink:Vu,reflinkSearch:gy,tag:fy,text:jb,url:ln},vy={...sl,emStrongLDelim:ey,emStrongRDelimAst:oy,emStrongRDelimUnd:ay,link:j(/^!?\[(label)\]\((.*?)\)/).replace("label",Oi).getRegex(),reflink:j(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Oi).getRegex()},Za={...sl,emStrongRDelimAst:ny,emStrongLDelim:Qb,delLDelim:ly,delRDelim:dy,url:j(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Ru).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:j(/^(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Ru).getRegex()},by={...Za,br:j(Fu).replace("{2,}","*").getRegex(),text:j(Za.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Ni={normal:il,gfm:Gb,pedantic:$b},wr={normal:sl,gfm:Za,breaks:by,pedantic:vy},yy={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Nu=t=>yy[t];function ut(t,e){if(e){if(Ce.escapeTest.test(t))return t.replace(Ce.escapeReplace,Nu)}else if(Ce.escapeTestNoEncode.test(t))return t.replace(Ce.escapeReplaceNoEncode,Nu);return t}function Ou(t){try{t=encodeURI(t).replace(Ce.percentDecode,"%")}catch{return null}return t}function Mu(t,e){let n=t.replace(Ce.findPipe,(i,s,a)=>{let l=!1,c=s;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(Ce.splitPipe),o=0;if(r[0].trim()||r.shift(),r.length>0&&!r.at(-1)?.trim()&&r.pop(),e)if(r.length>e)r.splice(e);else for(;r.length<e;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(Ce.slashPipe,"|");return r}function Nt(t,e,n){let r=t.length;if(r===0)return"";let o=0;for(;o<r;){let i=t.charAt(r-o-1);if(i===e&&!n)o++;else if(i!==e&&n)o++;else break}return t.slice(0,r-o)}function Lu(t){let e=t.split(`
40
+ `;function Va(t){let{within:e,exclude:n,onQuote:r}=t,o=new CSSStyleSheet;o.replaceSync(Jv),document.adoptedStyleSheets=[...document.adoptedStyleSheets,o];let i=document.createElement("button");i.type="button",i.className="ag-ui-quote-offer",i.textContent=t.label,i.hidden=!0,document.body.append(i);let s="",a=()=>{i.hidden=!0,s=""},l=u=>{if(u.composedPath().includes(n)){a();return}if(eb()){a();return}let m=u instanceof MouseEvent?{x:u.clientX,y:u.clientY}:void 0,y=yr(e,[],m);if(y===null){a();return}s=y.text,tb(i,y.rect)},c=u=>{i.contains(u.target)||a()};return e.addEventListener("mouseup",l),e.addEventListener("keyup",l),e.addEventListener("mousedown",c),document.addEventListener("scroll",a,!0),window.addEventListener("resize",a),i.addEventListener("mousedown",u=>{u.preventDefault()}),i.addEventListener("click",()=>{let u=s;window.getSelection()?.removeAllRanges(),a(),r(u)}),{element:i,detach(){e.removeEventListener("mouseup",l),e.removeEventListener("keyup",l),e.removeEventListener("mousedown",c),document.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a),i.remove(),document.adoptedStyleSheets=document.adoptedStyleSheets.filter(u=>u!==o)}}}function eb(){let t=document.activeElement;return t===null?!1:t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.isContentEditable===!0}function tb(t,e){t.hidden=!1;let n=e.top<Ba+t.offsetHeight;t.dataset.below=String(n),t.style.top=`${n?e.bottom+Ba:e.top-Ba}px`;let r=t.offsetWidth/2,o=e.left+e.width/2,i=document.documentElement.clientWidth;t.style.left=`${Math.min(Math.max(o,r),i-r)}px`}function ja(t){let e=t.replace(/[._-]+/g," ").trim();return e===""?t:e.charAt(0).toUpperCase()+e.slice(1)}function nb(t){let e=document.createElement("input");return e.type="text",e.className="question-input",e.setAttribute("part","question-input"),e.placeholder=t,e}function qa(t,e,n={}){let r=n.strings??ee,o=e.options??[],i=o.length>0,s=!i||e.allowCustom===!0;return new Promise(a=>{let l=document.createElement("div");l.className="question",l.setAttribute("part","question"),l.setAttribute("role","group"),l.setAttribute("aria-label",r.askUserAction);let c=document.createElement("div");c.className="question-body",c.setAttribute("part","question-body"),c.textContent=e.question;let u=document.createElement("div");u.className="question-options",u.setAttribute("part","question-options");let m=`q-${o.length}-${e.question.length}`,y=[];for(let U of o){let Y=document.createElement("label");Y.className="question-choice",Y.setAttribute("part","question-choice");let ie=document.createElement("input");ie.type="radio",ie.name=m,ie.value=U,ie.setAttribute("part","question-radio");let We=document.createElement("span");We.setAttribute("part","question-choice-text"),We.textContent=U,Y.append(ie,We),u.appendChild(Y),y.push(ie)}let f=null,h=null;if(s){if(h=nb(r.answerPlaceholder),i){let U=document.createElement("label");U.className="question-choice",U.setAttribute("part","question-choice"),f=document.createElement("input"),f.type="radio",f.name=m,f.value="",f.setAttribute("part","question-radio");let Y=document.createElement("span");Y.setAttribute("part","question-choice-text"),Y.textContent=r.otherOption,U.append(f,Y),u.appendChild(U),h.disabled=!0}u.appendChild(h)}let g=document.createElement("div");g.className="question-actions",g.setAttribute("part","question-actions");let x=document.createElement("button");x.type="button",x.className="question-btn",x.setAttribute("part","question-button"),x.textContent=r.submit,g.appendChild(x);let S=!1,_=()=>{let U=y.find(Y=>Y.checked);if(U!==void 0)return U.value;if(h!==null&&(f===null||f.checked)){let Y=h.value.trim();return Y===""?null:Y}return null},I=()=>{h!==null&&f!==null&&(h.disabled=!f.checked),x.disabled=_()===null},H=U=>{if(!S){S=!0,x.disabled=!0;for(let Y of y)Y.disabled=!0;f!==null&&(f.disabled=!0),h!==null&&(h.disabled=!0),l.setAttribute("data-resolved",U===""?"cancelled":"answered"),a(U)}};for(let U of[...y,...f!==null?[f]:[]])U.addEventListener("change",I);if(h?.addEventListener("input",I),h?.addEventListener("keydown",U=>{if(U.key==="Enter"){U.preventDefault();let Y=_();Y!==null&&H(Y)}}),x.addEventListener("click",()=>{let U=_();U!==null&&H(U)}),n.signal?.addEventListener("abort",()=>H(""),{once:!0}),l.append(c,u,g),t.appendChild(l),n.signal?.aborted===!0){H("");return}I(),(i?y[0]:h)?.focus()})}function mu(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function rb(t){if(Array.isArray(t))return t}function ob(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r,o,i,s,a=[],l=!0,c=!1;try{if(i=(n=n.call(t)).next,e!==0)for(;!(l=(r=i.call(n)).done)&&(a.push(r.value),a.length!==e);l=!0);}catch(u){c=!0,o=u}finally{try{if(!l&&n.return!=null&&(s=n.return(),Object(s)!==s))return}finally{if(c)throw o}}return a}}function ib(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
41
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function sb(t,e){return rb(t)||ob(t,e)||ab(t,e)||ib()}function ab(t,e){if(t){if(typeof t=="string")return mu(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)?mu(t,e):void 0}}var Ru=Object.entries,gu=Object.setPrototypeOf,lb=Object.isFrozen,cb=Object.getPrototypeOf,db=Object.getOwnPropertyDescriptor,Te=Object.freeze,Se=Object.seal,zn=Object.create,Nu=typeof Reflect<"u"&&Reflect,Qa=Nu.apply,Ja=Nu.construct;Te||(Te=function(e){return e});Se||(Se=function(e){return e});Qa||(Qa=function(e,n){for(var r=arguments.length,o=new Array(r>2?r-2:0),i=2;i<r;i++)o[i-2]=arguments[i];return e.apply(n,o)});Ja||(Ja=function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return new e(...r)});var Hn=me(Array.prototype.forEach),ub=me(Array.prototype.lastIndexOf),vu=me(Array.prototype.pop),Fn=me(Array.prototype.push),pb=me(Array.prototype.splice),Rt=Array.isArray,Er=me(String.prototype.toLowerCase),Wa=me(String.prototype.toString),bu=me(String.prototype.match),xr=me(String.prototype.replace),yu=me(String.prototype.indexOf),hb=me(String.prototype.trim),fb=me(Number.prototype.toString),mb=me(Boolean.prototype.toString),xu=typeof BigInt>"u"?null:me(BigInt.prototype.toString),wu=typeof Symbol>"u"?null:me(Symbol.prototype.toString),ye=me(Object.prototype.hasOwnProperty),wr=me(Object.prototype.toString),be=me(RegExp.prototype.test),an=gb(TypeError);function me(t){return function(e){e instanceof RegExp&&(e.lastIndex=0);for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return Qa(t,e,r)}}function gb(t){return function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return Ja(t,n)}}function W(t,e){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Er;if(gu&&gu(t,null),!Rt(e))return t;let r=e.length;for(;r--;){let o=e[r];if(typeof o=="string"){let i=n(o);i!==o&&(lb(e)||(e[r]=i),o=i)}t[o]=!0}return t}function vb(t){for(let e=0;e<t.length;e++)ye(t,e)||(t[e]=null);return t}function ke(t){let e=zn(null);for(let r of Ru(t)){var n=sb(r,2);let o=n[0],i=n[1];ye(t,o)&&(Rt(i)?e[o]=vb(i):i&&typeof i=="object"&&i.constructor===Object?e[o]=ke(i):e[o]=i)}return e}function bb(t){switch(typeof t){case"string":return t;case"number":return fb(t);case"boolean":return mb(t);case"bigint":return xu?xu(t):"0";case"symbol":return wu?wu(t):"Symbol()";case"undefined":return wr(t);case"function":case"object":{if(t===null)return wr(t);let e=t,n=Ze(e,"toString");if(typeof n=="function"){let r=n(e);return typeof r=="string"?r:wr(r)}return wr(t)}default:return wr(t)}}function Ze(t,e){for(;t!==null;){let r=db(t,e);if(r){if(r.get)return me(r.get);if(typeof r.value=="function")return me(r.value)}t=cb(t)}function n(){return null}return n}function yb(t){try{return be(t,""),!0}catch{return!1}}var Eu=Te(["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"]),Xa=Te(["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"]),Ya=Te(["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"]),xb=Te(["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"]),Ka=Te(["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"]),wb=Te(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),_u=Te(["#text"]),Tu=Te(["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"]),Za=Te(["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","dominant-baseline","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-orientation","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"]),Su=Te(["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"]),Mi=Te(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),Eb=Se(/{{[\w\W]*|^[\w\W]*}}/g),_b=Se(/<%[\w\W]*|^[\w\W]*%>/g),Tb=Se(/\${[\w\W]*/g),Sb=Se(/^data-[\-\w.\u00B7-\uFFFF]+$/),Ab=Se(/^aria-[\-\w]+$/),Au=Se(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),kb=Se(/^(?:\w+script|data):/i),Cb=Se(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Ib=Se(/^html$/i),Rb=Se(/^[a-z][.\w]*(-[.\w]+)+$/i),ku=Se(/<[/\w!]/g),Cu=Se(/<[/\w]/g),Nb=Se(/<\/no(script|embed|frames)/i),Ob=Se(/\/>/i),Fe={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},Mb=function(){return typeof window>"u"?null:window},Lb=function(e,n){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let r=null,o="data-tt-policy-suffix";n&&n.hasAttribute(o)&&(r=n.getAttribute(o));let i="dompurify"+(r?"#"+r:"");try{return e.createPolicy(i,{createHTML(s){return s},createScriptURL(s){return s}})}catch{return console.warn("TrustedTypes policy "+i+" could not be created."),null}},Iu=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},It=function(e,n,r,o){return ye(e,n)&&Rt(e[n])?W(o.base?ke(o.base):{},e[n],o.transform):r};function Ou(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Mb(),e=T=>Ou(T);if(e.version="3.4.13",e.removed=[],!t||!t.document||t.document.nodeType!==Fe.document||!t.Element)return e.isSupported=!1,e;let n=t.document,r=n,o=r.currentScript;t.DocumentFragment;let i=t.HTMLTemplateElement,s=t.Node,a=t.Element,l=t.NodeFilter,c=t.NamedNodeMap;c===void 0&&(t.NamedNodeMap||t.MozNamedAttrMap),t.HTMLFormElement;let u=t.DOMParser,m=t.trustedTypes,y=a.prototype,f=Ze(y,"cloneNode"),h=Ze(y,"remove"),g=Ze(y,"nextSibling"),x=Ze(y,"childNodes"),S=Ze(y,"parentNode"),_=Ze(y,"shadowRoot"),I=Ze(y,"attributes"),H=s&&s.prototype?Ze(s.prototype,"nodeType"):null,U=s&&s.prototype?Ze(s.prototype,"nodeName"):null,Y=s&&s.prototype?Ze(s.prototype,"ownerDocument"):null;if(typeof i=="function"){let T=n.createElement("template");T.content&&T.content.ownerDocument&&(n=T.content.ownerDocument)}let ie,We="",Zi,Tl=!1,jn=0,Sl=function(){if(jn>0)throw an('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.')},un=function(p){Sl(),jn++;try{return ie.createHTML(p)}finally{jn--}},yp=function(p){Sl(),jn++;try{return ie.createScriptURL(p)}finally{jn--}},xp=function(){return Tl||(Zi=Lb(m,o),Tl=!0),Zi},Lr=n,Qi=Lr.implementation,Al=Lr.createNodeIterator,wp=Lr.createDocumentFragment,Ep=Lr.getElementsByTagName,_p=r.importNode,se=Iu();e.isSupported=typeof Ru=="function"&&typeof S=="function"&&Qi&&Qi.createHTMLDocument!==void 0;let Tp=Eb,Sp=_b,Ap=Tb,kp=Sb,Cp=Ab,Ip=kb,kl=Cb,Rp=Rb,Cl=Au,ae=null,Ji=W({},[...Eu,...Xa,...Ya,...Ka,..._u]),le=null,es=W({},[...Tu,...Za,...Su,...Mi]),pe=Object.seal(zn(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}})),qn=null,Il=null,yt=Object.seal(zn(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),Rl=!0,ts=!0,Nl=!1,Ol=!0,xt=!1,wt=!0,Ot=!1,ns=!1,Pr=null,Dr=null,rs=!1,pn=!1,Ur=!1,Hr=!1,Ml=!0,Ll=!1,Pl="user-content-",os=!0,Fr=!1,hn={},tt=null,is=W({},["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"]),Dl=null,Ul=W({},["audio","video","img","source","image","track"]),ss=null,Hl=W({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),zr="http://www.w3.org/1998/Math/MathML",Gr="http://www.w3.org/2000/svg",nt="http://www.w3.org/1999/xhtml",fn=nt,as=!1,ls=null,Np=W({},[zr,Gr,nt],Wa),Fl=Te(["mi","mo","mn","ms","mtext"]),cs=W({},Fl),zl=Te(["annotation-xml"]),ds=W({},zl),Op=W({},["title","style","font","a","script"]),Wn=null,Mp=["application/xhtml+xml","text/html"],Lp="text/html",ce=null,mn=null,Pp=n.createElement("form"),Gl=function(p){return p instanceof RegExp||p instanceof Function},us=function(){let p=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(mn&&mn===p)return;(!p||typeof p!="object")&&(p={}),p=ke(p),Wn=Mp.indexOf(p.PARSER_MEDIA_TYPE)===-1?Lp:p.PARSER_MEDIA_TYPE,ce=Wn==="application/xhtml+xml"?Wa:Er,ae=It(p,"ALLOWED_TAGS",Ji,{transform:ce}),le=It(p,"ALLOWED_ATTR",es,{transform:ce}),ls=It(p,"ALLOWED_NAMESPACES",Np,{transform:Wa}),ss=It(p,"ADD_URI_SAFE_ATTR",Hl,{transform:ce,base:Hl}),Dl=It(p,"ADD_DATA_URI_TAGS",Ul,{transform:ce,base:Ul}),tt=It(p,"FORBID_CONTENTS",is,{transform:ce}),qn=It(p,"FORBID_TAGS",ke({}),{transform:ce}),Il=It(p,"FORBID_ATTR",ke({}),{transform:ce}),hn=ye(p,"USE_PROFILES")?p.USE_PROFILES&&typeof p.USE_PROFILES=="object"?ke(p.USE_PROFILES):p.USE_PROFILES:!1,Rl=p.ALLOW_ARIA_ATTR!==!1,ts=p.ALLOW_DATA_ATTR!==!1,Nl=p.ALLOW_UNKNOWN_PROTOCOLS||!1,Ol=p.ALLOW_SELF_CLOSE_IN_ATTR!==!1,xt=p.SAFE_FOR_TEMPLATES||!1,wt=p.SAFE_FOR_XML!==!1,Ot=p.WHOLE_DOCUMENT||!1,pn=p.RETURN_DOM||!1,Ur=p.RETURN_DOM_FRAGMENT||!1,Hr=p.RETURN_TRUSTED_TYPE||!1,rs=p.FORCE_BODY||!1,Ml=p.SANITIZE_DOM!==!1,Ll=p.SANITIZE_NAMED_PROPS||!1,os=p.KEEP_CONTENT!==!1,Fr=p.IN_PLACE||!1,Cl=yb(p.ALLOWED_URI_REGEXP)?p.ALLOWED_URI_REGEXP:Au,fn=typeof p.NAMESPACE=="string"?p.NAMESPACE:nt,cs=ye(p,"MATHML_TEXT_INTEGRATION_POINTS")&&p.MATHML_TEXT_INTEGRATION_POINTS&&typeof p.MATHML_TEXT_INTEGRATION_POINTS=="object"?ke(p.MATHML_TEXT_INTEGRATION_POINTS):W({},Fl),ds=ye(p,"HTML_INTEGRATION_POINTS")&&p.HTML_INTEGRATION_POINTS&&typeof p.HTML_INTEGRATION_POINTS=="object"?ke(p.HTML_INTEGRATION_POINTS):W({},zl);let b=ye(p,"CUSTOM_ELEMENT_HANDLING")&&p.CUSTOM_ELEMENT_HANDLING&&typeof p.CUSTOM_ELEMENT_HANDLING=="object"?ke(p.CUSTOM_ELEMENT_HANDLING):zn(null);if(pe=zn(null),ye(b,"tagNameCheck")&&Gl(b.tagNameCheck)&&(pe.tagNameCheck=b.tagNameCheck),ye(b,"attributeNameCheck")&&Gl(b.attributeNameCheck)&&(pe.attributeNameCheck=b.attributeNameCheck),ye(b,"allowCustomizedBuiltInElements")&&typeof b.allowCustomizedBuiltInElements=="boolean"&&(pe.allowCustomizedBuiltInElements=b.allowCustomizedBuiltInElements),Se(pe),xt&&(ts=!1),Ur&&(pn=!0),hn&&(ae=W({},_u),le=zn(null),hn.html===!0&&(W(ae,Eu),W(le,Tu)),hn.svg===!0&&(W(ae,Xa),W(le,Za),W(le,Mi)),hn.svgFilters===!0&&(W(ae,Ya),W(le,Za),W(le,Mi)),hn.mathMl===!0&&(W(ae,Ka),W(le,Su),W(le,Mi))),yt.tagCheck=null,yt.attributeCheck=null,ye(p,"ADD_TAGS")&&(typeof p.ADD_TAGS=="function"?yt.tagCheck=p.ADD_TAGS:Rt(p.ADD_TAGS)&&(ae===Ji&&(ae=ke(ae)),W(ae,p.ADD_TAGS,ce))),ye(p,"ADD_ATTR")&&(typeof p.ADD_ATTR=="function"?yt.attributeCheck=p.ADD_ATTR:Rt(p.ADD_ATTR)&&(le===es&&(le=ke(le)),W(le,p.ADD_ATTR,ce))),ye(p,"ADD_URI_SAFE_ATTR")&&Rt(p.ADD_URI_SAFE_ATTR)&&W(ss,p.ADD_URI_SAFE_ATTR,ce),ye(p,"FORBID_CONTENTS")&&Rt(p.FORBID_CONTENTS)&&(tt===is&&(tt=ke(tt)),W(tt,p.FORBID_CONTENTS,ce)),ye(p,"ADD_FORBID_CONTENTS")&&Rt(p.ADD_FORBID_CONTENTS)&&(tt===is&&(tt=ke(tt)),W(tt,p.ADD_FORBID_CONTENTS,ce)),os&&(ae["#text"]=!0),Ot&&W(ae,["html","head","body"]),ae.table&&(W(ae,["tbody"]),delete qn.tbody),p.TRUSTED_TYPES_POLICY){if(typeof p.TRUSTED_TYPES_POLICY.createHTML!="function")throw an('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof p.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw an('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');let w=ie;ie=p.TRUSTED_TYPES_POLICY;try{We=un("")}catch(N){throw ie=w,N}}else p.TRUSTED_TYPES_POLICY===null?(ie=void 0,We=""):(ie===void 0&&(ie=xp()),ie&&typeof We=="string"&&(We=un("")));Te&&Te(p),mn=p},$l=W({},[...Xa,...Ya,...xb]),Bl=W({},[...Ka,...wb]),Dp=function(p,b,w){return b.namespaceURI===nt?p==="svg":b.namespaceURI===zr?p==="svg"&&(w==="annotation-xml"||cs[w]):!!$l[p]},Up=function(p,b,w){return b.namespaceURI===nt?p==="math":b.namespaceURI===Gr?p==="math"&&ds[w]:!!Bl[p]},Hp=function(p,b,w){return b.namespaceURI===Gr&&!ds[w]||b.namespaceURI===zr&&!cs[w]?!1:!Bl[p]&&(Op[p]||!$l[p])},Fp=function(p){let b=S(p);(!b||!b.tagName)&&(b={namespaceURI:fn,tagName:"template"});let w=Er(p.tagName),N=Er(b.tagName);return ls[p.namespaceURI]?p.namespaceURI===Gr?Dp(w,b,N):p.namespaceURI===zr?Up(w,b,N):p.namespaceURI===nt?Hp(w,b,N):!!(Wn==="application/xhtml+xml"&&ls[p.namespaceURI]):!1},Et=function(p){Fn(e.removed,{element:p});try{S(p).removeChild(p)}catch{if(h(p),!S(p))throw an("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},$r=function(p){Xn(p);let b=x(p);if(b){let N=[];Hn(b,L=>{Fn(N,L)}),Hn(N,L=>{try{h(L)}catch{}})}let w=I(p);if(w)for(let N=w.length-1;N>=0;--N){let L=w[N],F=L&&L.name;if(typeof F=="string")try{p.removeAttribute(F)}catch{}}},Mt=function(p,b){try{Fn(e.removed,{attribute:b.getAttributeNode(p),from:b})}catch{Fn(e.removed,{attribute:null,from:b})}if(b.removeAttribute(p),p==="is")if(pn||Ur)try{Et(b)}catch{}else try{b.setAttribute(p,"")}catch{}},zp=function(p){let b=I(p);if(b)for(let w=b.length-1;w>=0;--w){let N=b[w],L=N&&N.name;if(!(typeof L!="string"||le[ce(L)]))try{p.removeAttribute(L)}catch{}}},Xn=function(p){let b=[p];for(;b.length>0;){let w=b.pop();(H?H(w):w.nodeType)===Fe.element&&zp(w);let L=x(w);if(L)for(let F=L.length-1;F>=0;--F)b.push(L[F])}},Gp=function(p){if(!wt)return;let b=[p];for(;b.length>0;){let w=b.pop(),N=H?H(w):w.nodeType;if(N===Fe.processingInstruction||N===Fe.comment&&be(Cu,w.data)){try{h(w)}catch{}continue}if(N===Fe.element){let F=w,Z=ce(U?U(w):w.nodeName);try{F.hasAttribute&&F.hasAttribute("patchsrc")&&F.removeAttribute("patchsrc"),F.hasAttribute&&F.hasAttribute("for")&&Z!=="label"&&Z!=="output"&&F.removeAttribute("for")}catch{}}let L=x(w);if(L)for(let F=L.length-1;F>=0;--F)b.push(L[F])}},Vl=function(p){let b=null,w=null;if(rs)p="<remove></remove>"+p;else{let F=bu(p,/^[\r\n\t ]+/);w=F&&F[0]}Wn==="application/xhtml+xml"&&fn===nt&&(p='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+p+"</body></html>");let N=ie?un(p):p;if(fn===nt)try{b=new u().parseFromString(N,Wn)}catch{}if(!b||!b.documentElement){b=Qi.createDocument(fn,"template",null);try{b.documentElement.innerHTML=as?We:N}catch{}}let L=b.body||b.documentElement;return p&&w&&L.insertBefore(n.createTextNode(w),L.childNodes[0]||null),fn===nt?Ep.call(b,Ot?"html":"body")[0]:Ot?b.documentElement:L},jl=function(p){let b=Y?Y(p):p.ownerDocument;return Al.call(b||p,p,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},Br=function(p){return p=xr(p,Tp," "),p=xr(p,Sp," "),p=xr(p,Ap," "),p},ps=function(p){var b;p.normalize();let w=Y?Y(p):p.ownerDocument,N=Al.call(w||p,p,l.SHOW_TEXT|l.SHOW_COMMENT|l.SHOW_CDATA_SECTION|l.SHOW_PROCESSING_INSTRUCTION,null),L=N.nextNode();for(;L;)L.data=Br(L.data),L=N.nextNode();let F=(b=p.querySelectorAll)===null||b===void 0?void 0:b.call(p,"template");F&&Hn(F,Z=>{gn(Z.content)&&ps(Z.content)})},Vr=function(p){let b=U?U(p):null;return typeof b!="string"||ce(b)!=="form"?!1:typeof p.nodeName!="string"||typeof p.textContent!="string"||typeof p.removeChild!="function"||p.attributes!==I(p)||typeof p.removeAttribute!="function"||typeof p.setAttribute!="function"||typeof p.namespaceURI!="string"||typeof p.insertBefore!="function"||typeof p.hasChildNodes!="function"||p.nodeType!==H(p)||p.childNodes!==x(p)},gn=function(p){if(!H||typeof p!="object"||p===null)return!1;try{return H(p)===Fe.documentFragment}catch{return!1}},Yn=function(p){if(!H||typeof p!="object"||p===null)return!1;try{return typeof H(p)=="number"}catch{return!1}};function rt(T,p,b){T.length!==0&&Hn(T,w=>{w.call(e,p,b,mn)})}let $p=function(p,b){return!!(wt&&p.hasChildNodes()&&!Yn(p.firstElementChild)&&be(ku,p.textContent)&&be(ku,p.innerHTML)||wt&&p.namespaceURI===nt&&b==="style"&&Yn(p.firstElementChild)||p.nodeType===Fe.processingInstruction||wt&&p.nodeType===Fe.comment&&be(Cu,p.data))},Bp=function(p,b,w){if(!qn[b]&&Yl(b)&&(pe.tagNameCheck instanceof RegExp&&be(pe.tagNameCheck,b)||pe.tagNameCheck instanceof Function&&pe.tagNameCheck(b)))return!1;if(os&&!tt[b]){let N=S(p),L=x(p);if(L&&N){let F=L.length;for(let Z=F-1;Z>=0;--Z){let de=p===w?f(L[Z],!0):L[Z];N.insertBefore(de,g(p))}}}return Et(p),!0},ql=function(p,b,w,N){return p.length===0?b:b===w||b===N?ke(b):b},Wl=function(p,b){if(rt(se.beforeSanitizeElements,p,null),p!==b&&S(p)===null)return Fr&&Xn(p),!0;if(Vr(p))return Et(p),!0;let w=ce(U?U(p):p.nodeName);if(ae=ql(se.uponSanitizeElement,ae,Ji,Pr),rt(se.uponSanitizeElement,p,{tagName:w,allowedTags:ae}),p!==b&&S(p)===null)return Fr&&Xn(p),!0;if($p(p,w))return Et(p),!0;if(qn[w]||!(yt.tagCheck instanceof Function&&yt.tagCheck(w))&&!ae[w]){let L=Bp(p,w,b);return L===!1&&rt(se.afterSanitizeElements,p,null),L}if((H?H(p):p.nodeType)===Fe.element&&!Fp(p)||(w==="noscript"||w==="noembed"||w==="noframes")&&be(Nb,p.innerHTML))return Et(p),!0;if(xt&&p.nodeType===Fe.text){let L=Br(p.textContent);p.textContent!==L&&(Fn(e.removed,{element:p.cloneNode()}),p.textContent=L)}return rt(se.afterSanitizeElements,p,null),!1},Xl=function(p,b,w){if(Il[b]||wt&&b==="patchsrc"||wt&&b==="for"&&p!=="label"&&p!=="output"||Ml&&(b==="id"||b==="name")&&(w in n||w in Pp))return!1;let N=le[b]||yt.attributeCheck instanceof Function&&yt.attributeCheck(b,p);if(!(ts&&be(kp,b))){if(!(Rl&&be(Cp,b))){if(N){if(!ss[b]){if(!be(Cl,xr(w,kl,""))){if(!((b==="src"||b==="xlink:href"||b==="href")&&p!=="script"&&yu(w,"data:")===0&&Dl[p])){if(!(Nl&&!be(Ip,xr(w,kl,"")))){if(w)return!1}}}}}else if(!(Yl(p)&&(pe.tagNameCheck instanceof RegExp&&be(pe.tagNameCheck,p)||pe.tagNameCheck instanceof Function&&pe.tagNameCheck(p))&&(pe.attributeNameCheck instanceof RegExp&&be(pe.attributeNameCheck,b)||pe.attributeNameCheck instanceof Function&&pe.attributeNameCheck(b,p))||b==="is"&&pe.allowCustomizedBuiltInElements&&(pe.tagNameCheck instanceof RegExp&&be(pe.tagNameCheck,w)||pe.tagNameCheck instanceof Function&&pe.tagNameCheck(w))))return!1}}return!0},Vp=W({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),Yl=function(p){return!Vp[Er(p)]&&be(Rp,p)},jp=function(p,b,w,N){if(ie&&typeof m=="object"&&typeof m.getAttributeType=="function"&&!w)switch(m.getAttributeType(p,b)){case"TrustedHTML":return un(N);case"TrustedScriptURL":return yp(N)}return N},qp=function(p,b,w,N){try{w?p.setAttributeNS(w,b,N):p.setAttribute(b,N),Vr(p)?Et(p):vu(e.removed)}catch{Mt(b,p)}},Kl=function(p){rt(se.beforeSanitizeAttributes,p,null);let b=p.attributes;if(!b||Vr(p))return;le=ql(se.uponSanitizeAttribute,le,es,Dr);let w={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:le,forceKeepAttr:void 0},N=b.length,L=ce(p.nodeName);for(;N--;){let F=b[N],Z=F.name,de=F.namespaceURI,Re=F.value,Ne=ce(Z),fs=Re,Ie=Z==="value"?fs:hb(fs);if(w.attrName=Ne,w.attrValue=Ie,w.keepAttr=!0,w.forceKeepAttr=void 0,rt(se.uponSanitizeAttribute,p,w),Ie=w.attrValue,Ll&&(Ne==="id"||Ne==="name")&&yu(Ie,Pl)!==0&&(Mt(Z,p),Ie=Pl+Ie),wt&&be(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,Ie)){Mt(Z,p);continue}if(Ne==="attributename"&&bu(Ie,"href")){Mt(Z,p);continue}if(!w.forceKeepAttr){if(!w.keepAttr){Mt(Z,p);continue}if(!Ol&&be(Ob,Ie)){Mt(Z,p);continue}if(xt&&(Ie=Br(Ie)),!Xl(L,Ne,Ie)){Mt(Z,p);continue}Ie=jp(L,Ne,de,Ie),Ie!==fs&&qp(p,Z,de,Ie)}}rt(se.afterSanitizeAttributes,p,null)},jr=function(p){let b=null,w=jl(p);for(rt(se.beforeSanitizeShadowDOM,p,null);b=w.nextNode();)if(rt(se.uponSanitizeShadowNode,b,null),Wl(b,p),Kl(b),gn(b.content)&&jr(b.content),(H?H(b):b.nodeType)===Fe.element){let L=_(b);gn(L)&&(hs(L),jr(L))}rt(se.afterSanitizeShadowDOM,p,null)},hs=function(p){let b=[{node:p,shadow:null}];for(;b.length>0;){let w=b.pop();if(w.shadow){jr(w.shadow);continue}let N=w.node,F=(H?H(N):N.nodeType)===Fe.element,Z=x(N);if(Z)for(let de=Z.length-1;de>=0;--de)b.push({node:Z[de],shadow:null});if(F){let de=U?U(N):null;if(typeof de=="string"&&ce(de)==="template"){let Re=N.content;gn(Re)&&b.push({node:Re,shadow:null})}}if(F){let de=_(N);gn(de)&&b.push({node:null,shadow:de},{node:de,shadow:null})}}};return e.sanitize=function(T){let p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},b=null,w=null,N=null,L=null;if(as=!T,as&&(T="<!-->"),typeof T!="string"&&!Yn(T)&&(T=bb(T),typeof T!="string"))throw an("dirty is not a string, aborting");if(!e.isSupported)return T;ns?(ae=Pr,le=Dr):us(p),(se.uponSanitizeElement.length>0||se.uponSanitizeAttribute.length>0)&&(ae=ke(ae)),se.uponSanitizeAttribute.length>0&&(le=ke(le)),e.removed=[];let F=Fr&&typeof T!="string"&&Yn(T);if(F){Gp(T);let Re=U?U(T):T.nodeName;if(typeof Re=="string"){let Ne=ce(Re);if(!ae[Ne]||qn[Ne])throw $r(T),an("root node is forbidden and cannot be sanitized in-place")}if(Vr(T))throw $r(T),an("root node is clobbered and cannot be sanitized in-place");try{hs(T)}catch(Ne){throw $r(T),Ne}}else if(Yn(T))b=Vl("<!---->"),w=b.ownerDocument.importNode(T,!0),w.nodeType===Fe.element&&w.nodeName==="BODY"||w.nodeName==="HTML"?b=w:b.appendChild(w),hs(w);else{if(!pn&&!xt&&!Ot&&T.indexOf("<")===-1)return ie&&Hr?un(T):T;if(b=Vl(T),!b)return pn?null:Hr?We:""}b&&rs&&Et(b.firstChild);let Z=F?T:b;try{let Re=jl(Z);for(;N=Re.nextNode();)Wl(N,Z),Kl(N),gn(N.content)&&jr(N.content)}catch(Re){throw F&&($r(T),Hn(e.removed,Ne=>{Ne.element&&Xn(Ne.element)})),Re}if(F)return Hn(e.removed,Re=>{Re.element&&Xn(Re.element)}),xt&&ps(T),T;if(pn){if(xt&&ps(b),Ur)for(L=wp.call(b.ownerDocument);b.firstChild;)L.appendChild(b.firstChild);else L=b;return(le.shadowroot||le.shadowrootmode)&&(L=_p.call(r,L,!0)),L}let de=Ot?b.outerHTML:b.innerHTML;return Ot&&ae["!doctype"]&&b.ownerDocument&&b.ownerDocument.doctype&&b.ownerDocument.doctype.name&&be(Ib,b.ownerDocument.doctype.name)&&(de="<!DOCTYPE "+b.ownerDocument.doctype.name+`>
42
+ `+de),xt&&(de=Br(de)),ie&&Hr?un(de):de},e.setConfig=function(){let T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};us(T),ns=!0,Pr=ae,Dr=le},e.clearConfig=function(){mn=null,ns=!1,Pr=null,Dr=null,ie=Zi,We=""},e.isValidAttribute=function(T,p,b){mn||us({});let w=ce(T),N=ce(p);return Xl(w,N,b)},e.addHook=function(T,p){typeof p=="function"&&ye(se,T)&&Fn(se[T],p)},e.removeHook=function(T,p){if(ye(se,T)){if(p!==void 0){let b=ub(se[T],p);return b===-1?void 0:pb(se[T],b,1)[0]}return vu(se[T])}},e.removeHooks=function(T){ye(se,T)&&(se[T]=[])},e.removeAllHooks=function(){se=Iu()},e}var Mu=Ou();function rl(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var dn=rl();function Gu(t){dn=t}var ln={exec:()=>null};function Gn(t){let e=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),o=e[r];return o||(o=t(r),e[r]=o),o}}function j(t,e=""){let n=typeof t=="string"?t:t.source,r={replace:(o,i)=>{let s=typeof i=="string"?i:i.source;return s=s.replace(Ce.caret,"$1"),n=n.replace(o,s),r},getRegex:()=>new RegExp(n,e)};return r}var Pb=((t="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+t)}catch{return!1}})(),Ce={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,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ 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,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:Gn(t=>new RegExp(`^ {0,${t}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:Gn(t=>new RegExp(`^ {0,${t}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:Gn(t=>new RegExp(`^ {0,${t}}(?:\`\`\`|~~~)`)),headingBeginRegex:Gn(t=>new RegExp(`^ {0,${t}}#`)),htmlBeginRegex:Gn(t=>new RegExp(`^ {0,${t}}<(?:[a-z].*>|!--)`,"i")),blockquoteBeginRegex:Gn(t=>new RegExp(`^ {0,${t}}>`))},Db=/^(?:[ \t]*(?:\n|$))+/,Ub=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Hb=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Sr=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Fb=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,ol=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,$u=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Bu=j($u).replace(/bull/g,ol).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}(?:\s|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),zb=j($u).replace(/bull/g,ol).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}(?:\s|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),il=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,Gb=/^[^\n]+/,sl=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,$b=j(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",sl).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Bb=j(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,ol).getRegex(),Hi="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",al=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Vb=j("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\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",al).replace("tag",Hi).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Vu=t=>j(il).replace("hr",Sr).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~~~)[^\\n]*\\n").replace("list",t).replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Hi).getRegex(),jb=Vu(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),qb=Vu(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),Wb=j(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",qb).getRegex(),ll={blockquote:Wb,code:Ub,def:$b,fences:Hb,heading:Fb,hr:Sr,html:Vb,lheading:Bu,list:Bb,newline:Db,paragraph:jb,table:ln,text:Gb},Lu=j("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Sr).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~~~)[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Hi).getRegex(),Xb={...ll,lheading:zb,table:Lu,paragraph:j(il).replace("hr",Sr).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Lu).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~~~)[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Hi).getRegex()},Yb={...ll,html:j(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",al).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:ln,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:j(il).replace("hr",Sr).replace("heading",` *#{1,6} *[^
43
+ ]`).replace("lheading",Bu).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Kb=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Zb=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ju=/^( {2,}|\\)\n(?!\s*$)/,Qb=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,bt=/[\p{P}\p{S}]/u,$n=/[\s\p{P}\p{S}]/u,Ar=/[^\s\p{P}\p{S}]/u,Jb=j(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,$n).getRegex(),ey=/[\p{Pi}\p{Ps}"']/u,qu=/(?!~)[\p{P}\p{S}]/u,ty=/(?!~)[\s\p{P}\p{S}]/u,ny=/(?:[^\s\p{P}\p{S}]|~)/u,ry=j(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",Pb?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),Wu=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,oy=j(Wu,"u").replace(/punct/g,bt).getRegex(),iy=j(Wu,"u").replace(/punct/g,qu).getRegex(),sy=/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,ay=j(sy,"u").replace(/openQuote/g,ey).replace(/punct/g,bt).getRegex(),Xu="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",ly=j(Xu,"gu").replace(/notPunctSpace/g,Ar).replace(/punctSpace/g,$n).replace(/punct/g,bt).getRegex(),cy=j(Xu,"gu").replace(/notPunctSpace/g,ny).replace(/punctSpace/g,ty).replace(/punct/g,qu).getRegex(),dy="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)",uy=j(dy,"gu").replace(/notPunctSpace/g,Ar).replace(/punctSpace/g,$n).replace(/punct/g,bt).getRegex(),py=j("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Ar).replace(/punctSpace/g,$n).replace(/punct/g,bt).getRegex(),hy="^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)",fy=j(hy,"gu").replace(/notPunctSpace/g,Ar).replace(/punctSpace/g,$n).replace(/punct/g,bt).getRegex(),my=j(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,bt).getRegex(),gy="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",vy=j(gy,"gu").replace(/notPunctSpace/g,Ar).replace(/punctSpace/g,$n).replace(/punct/g,bt).getRegex(),by=j(/\\(punct)/,"gu").replace(/punct/g,bt).getRegex(),yy=j(/^<(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(),xy=j(al).replace("(?:-->|$)","-->").getRegex(),wy=j("^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",xy).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Pi=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,Ey=j(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",Pi).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Yu=j(/^!?\[(label)\]\[(ref)\]/).replace("label",Pi).replace("ref",sl).getRegex(),Ku=j(/^!?\[(ref)\](?:\[\])?/).replace("ref",sl).getRegex(),_y=j("reflink|nolink(?!\\()","g").replace("reflink",Yu).replace("nolink",Ku).getRegex(),Pu=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,cl={_backpedal:ln,anyPunctuation:by,autolink:yy,blockSkip:ry,br:ju,code:Zb,del:ln,delLDelim:ln,delRDelim:ln,emStrongLDelim:oy,emStrongRDelimAst:ly,emStrongRDelimUnd:py,escape:Kb,link:Ey,nolink:Ku,punctuation:Jb,reflink:Yu,reflinkSearch:_y,tag:wy,text:Qb,url:ln},Ty={...cl,emStrongLDelim:ay,emStrongRDelimAst:uy,emStrongRDelimUnd:fy,link:j(/^!?\[(label)\]\((.*?)\)/).replace("label",Pi).getRegex(),reflink:j(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Pi).getRegex()},el={...cl,emStrongRDelimAst:cy,emStrongLDelim:iy,delLDelim:my,delRDelim:vy,url:j(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Pu).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:j(/^(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Pu).getRegex()},Sy={...el,br:j(ju).replace("{2,}","*").getRegex(),text:j(el.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Li={normal:ll,gfm:Xb,pedantic:Yb},_r={normal:cl,gfm:el,breaks:Sy,pedantic:Ty},Ay={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Du=t=>Ay[t];function ut(t,e){if(e){if(Ce.escapeTest.test(t))return t.replace(Ce.escapeReplace,Du)}else if(Ce.escapeTestNoEncode.test(t))return t.replace(Ce.escapeReplaceNoEncode,Du);return t}function Uu(t){try{t=encodeURI(t).replace(Ce.percentDecode,"%")}catch{return null}return t}function Hu(t,e){let n=t.replace(Ce.findPipe,(i,s,a)=>{let l=!1,c=s;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(Ce.splitPipe),o=0;if(r[0].trim()||r.shift(),r.length>0&&!r.at(-1)?.trim()&&r.pop(),e)if(r.length>e)r.splice(e);else for(;r.length<e;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(Ce.slashPipe,"|");return r}function Nt(t,e,n){let r=t.length;if(r===0)return"";let o=0;for(;o<r;){let i=t.charAt(r-o-1);if(i===e&&!n)o++;else if(i!==e&&n)o++;else break}return t.slice(0,r-o)}function Fu(t){let e=t.split(`
44
44
  `),n=e.length-1;for(;n>=0&&Ce.blankLine.test(e[n]);)n--;return e.length-n<=2?t:e.slice(0,n+1).join(`
45
- `)}function xy(t,e){if(t.indexOf(e[1])===-1)return-1;let n=0;for(let r=0;r<t.length;r++)if(t[r]==="\\")r++;else if(t[r]===e[0])n++;else if(t[r]===e[1]&&(n--,n<0))return r;return n>0?-2:-1}function wy(t,e=0){let n=e,r="";for(let o of t)if(o===" "){let i=4-n%4;r+=" ".repeat(i),n+=i}else r+=o,n++;return r}function Pu(t,e,n,r,o){let i=e.href,s=e.title||null,a=t[1].replace(o.other.outputLinkReplace,"$1");r.state.inLink=!0;let l={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:i,title:s,text:a,tokens:r.inlineTokens(a)};return r.state.inLink=!1,l}function Ey(t,e,n){let r=t.match(n.other.indentCodeCompensation);if(r===null)return e;let o=r[1];return e.split(`
45
+ `)}function ky(t,e){if(t.indexOf(e[1])===-1)return-1;let n=0;for(let r=0;r<t.length;r++)if(t[r]==="\\")r++;else if(t[r]===e[0])n++;else if(t[r]===e[1]&&(n--,n<0))return r;return n>0?-2:-1}function Cy(t,e=0){let n=e,r="";for(let o of t)if(o===" "){let i=4-n%4;r+=" ".repeat(i),n+=i}else r+=o,n++;return r}function zu(t,e,n,r,o){let i=e.href,s=e.title||null,a=t[1].replace(o.other.outputLinkReplace,"$1");r.state.inLink=!0;let l={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:i,title:s,text:a,tokens:r.inlineTokens(a)};return r.state.inLink=!1,l}function Iy(t,e,n){let r=t.match(n.other.indentCodeCompensation);if(r===null)return e;let o=r[1];return e.split(`
46
46
  `).map(i=>{let s=i.match(n.other.beginningSpace);if(s===null)return i;let[a]=s;return a.length>=o.length?i.slice(o.length):i}).join(`
47
- `)}var Mi=class{options;rules;lexer;constructor(t){this.options=t||dn}space(t){let e=this.rules.block.newline.exec(t);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(t){let e=this.rules.block.code.exec(t);if(e){let n=this.options.pedantic?e[0]:Lu(e[0]),r=n.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:n,codeBlockStyle:"indented",text:r}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let n=e[0],r=Ey(n,e[3]||"",this.rules);return{type:"code",raw:n,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:r}}}heading(t){let e=this.rules.block.heading.exec(t);if(e){let n=e[2].trim();if(this.rules.other.endingHash.test(n)){let r=Nt(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:Nt(e[0],`
47
+ `)}var Di=class{options;rules;lexer;constructor(t){this.options=t||dn}space(t){let e=this.rules.block.newline.exec(t);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(t){let e=this.rules.block.code.exec(t);if(e){let n=this.options.pedantic?e[0]:Fu(e[0]),r=n.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:n,codeBlockStyle:"indented",text:r}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let n=e[0],r=Iy(n,e[3]||"",this.rules);return{type:"code",raw:n,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:r}}}heading(t){let e=this.rules.block.heading.exec(t);if(e){let n=e[2].trim();if(this.rules.other.endingHash.test(n)){let r=Nt(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:Nt(e[0],`
48
48
  `),depth:e[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(t){let e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:Nt(e[0],`
49
49
  `)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let n=Nt(e[0],`
50
50
  `).split(`
@@ -58,19 +58,19 @@ ${u}`:u;let m=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTo
58
58
  ${h}`,o=o.substring(0,o.length-f.text.length)+x.text;break}else if(y?.type==="list"){let f=y,h=f.raw+`
59
59
  `+n.join(`
60
60
  `),g=this.list(h);i[i.length-1]=g,r=r.substring(0,r.length-y.raw.length)+g.raw,o=o.substring(0,o.length-f.raw.length)+g.raw,n=h.substring(i.at(-1).raw.length).split(`
61
- `);continue}}return{type:"blockquote",raw:r,tokens:i,text:o}}}list(t){let e=this.rules.block.list.exec(t);if(e){let n=e[1].trim(),r=n.length>1,o={type:"list",raw:"",ordered:r,start:r?+n.slice(0,-1):"",loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:"[*+-]");let i=this.rules.other.listItemRegex(n),s=!1;for(;t;){let l=!1,c="",u="";if(!(e=i.exec(t))||this.rules.block.hr.test(t))break;c=e[0],t=t.substring(c.length);let m=wy(e[2].split(`
61
+ `);continue}}return{type:"blockquote",raw:r,tokens:i,text:o}}}list(t){let e=this.rules.block.list.exec(t);if(e){let n=e[1].trim(),r=n.length>1,o={type:"list",raw:"",ordered:r,start:r?+n.slice(0,-1):"",loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:"[*+-]");let i=this.rules.other.listItemRegex(n),s=!1;for(;t;){let l=!1,c="",u="";if(!(e=i.exec(t))||this.rules.block.hr.test(t))break;c=e[0],t=t.substring(c.length);let m=Cy(e[2].split(`
62
62
  `,1)[0],e[1].length),y=t.split(`
63
63
  `,1)[0],f=!m.trim(),h=0;if(this.options.pedantic?(h=2,u=m.trimStart()):f?h=e[1].length+1:(h=m.search(this.rules.other.nonSpaceChar),h=h>4?1:h,u=m.slice(h),h+=e[1].length),f&&this.rules.other.blankLine.test(y)&&(c+=y+`
64
64
  `,t=t.substring(y.length+1),l=!0),!l){let g=this.rules.other.nextBulletRegex(h),x=this.rules.other.hrRegex(h),S=this.rules.other.fencesBeginRegex(h),_=this.rules.other.headingBeginRegex(h),I=this.rules.other.htmlBeginRegex(h),H=this.rules.other.blockquoteBeginRegex(h);for(;t;){let U=t.split(`
65
- `,1)[0],K;if(y=U,this.options.pedantic?(y=y.replace(this.rules.other.listReplaceNesting," "),K=y):K=y.replace(this.rules.other.tabCharGlobal," "),S.test(y)||_.test(y)||I.test(y)||H.test(y)||g.test(y)||x.test(y))break;if(K.search(this.rules.other.nonSpaceChar)>=h||!y.trim())u+=`
66
- `+K.slice(h);else{if(f||m.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||S.test(m)||_.test(m)||x.test(m))break;u+=`
65
+ `,1)[0],Y;if(y=U,this.options.pedantic?(y=y.replace(this.rules.other.listReplaceNesting," "),Y=y):Y=y.replace(this.rules.other.tabCharGlobal," "),S.test(y)||_.test(y)||I.test(y)||H.test(y)||g.test(y)||x.test(y))break;if(Y.search(this.rules.other.nonSpaceChar)>=h||!y.trim())u+=`
66
+ `+Y.slice(h);else{if(f||m.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||S.test(m)||_.test(m)||x.test(m))break;u+=`
67
67
  `+y}f=!y.trim(),c+=U+`
68
- `,t=t.substring(U.length+1),m=K.slice(h)}}o.loose||(s?o.loose=!0:this.rules.other.doubleBlankLine.test(c)&&(s=!0)),o.items.push({type:"list_item",raw:c,task:!!this.options.gfm&&this.rules.other.listIsTask.test(u),loose:!1,text:u,tokens:[]}),o.raw+=c}let a=o.items.at(-1);if(a)a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd();else return;o.raw=o.raw.trimEnd();for(let l of o.items){this.lexer.state.top=!1,l.tokens=this.lexer.blockTokens(l.text,[]);let c=l.tokens[0];if(l.task&&(c?.type==="text"||c?.type==="paragraph")){l.text=l.text.replace(this.rules.other.listReplaceTask,""),c.raw=c.raw.replace(this.rules.other.listReplaceTask,""),c.text=c.text.replace(this.rules.other.listReplaceTask,"");for(let m=this.lexer.inlineQueue.length-1;m>=0;m--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[m].src)){this.lexer.inlineQueue[m].src=this.lexer.inlineQueue[m].src.replace(this.rules.other.listReplaceTask,"");break}let u=this.rules.other.listTaskCheckbox.exec(l.raw);if(u){let m={type:"checkbox",raw:u[0]+" ",checked:u[0]!=="[ ]"};l.checked=m.checked,o.loose?l.tokens[0]&&["paragraph","text"].includes(l.tokens[0].type)&&"tokens"in l.tokens[0]&&l.tokens[0].tokens?(l.tokens[0].raw=m.raw+l.tokens[0].raw,l.tokens[0].text=m.raw+l.tokens[0].text,l.tokens[0].tokens.unshift(m)):l.tokens.unshift({type:"paragraph",raw:m.raw,text:m.raw,tokens:[m]}):l.tokens.unshift(m)}}else l.task&&(l.task=!1);if(!o.loose){let u=l.tokens.filter(y=>y.type==="space"),m=u.length>0&&u.some(y=>this.rules.other.anyLine.test(y.raw));o.loose=m}}if(o.loose)for(let l of o.items){l.loose=!0;for(let c of l.tokens)c.type==="text"&&(c.type="paragraph")}return o}}html(t){let e=this.rules.block.html.exec(t);if(e){let n=Lu(e[0]);return{type:"html",block:!0,raw:n,pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:n}}}def(t){let e=this.rules.block.def.exec(t);if(e){let n=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),r=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",o=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:n,raw:Nt(e[0],`
69
- `),href:r,title:o}}}table(t){let e=this.rules.block.table.exec(t);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let n=Mu(e[1]),r=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),o=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
68
+ `,t=t.substring(U.length+1),m=Y.slice(h)}}o.loose||(s?o.loose=!0:this.rules.other.doubleBlankLine.test(c)&&(s=!0)),o.items.push({type:"list_item",raw:c,task:!!this.options.gfm&&this.rules.other.listIsTask.test(u),loose:!1,text:u,tokens:[]}),o.raw+=c}let a=o.items.at(-1);if(a)a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd();else return;o.raw=o.raw.trimEnd();for(let l of o.items){this.lexer.state.top=!1,l.tokens=this.lexer.blockTokens(l.text,[]);let c=l.tokens[0];if(l.task&&(c?.type==="text"||c?.type==="paragraph")){l.text=l.text.replace(this.rules.other.listReplaceTask,""),c.raw=c.raw.replace(this.rules.other.listReplaceTask,""),c.text=c.text.replace(this.rules.other.listReplaceTask,"");for(let m=this.lexer.inlineQueue.length-1;m>=0;m--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[m].src)){this.lexer.inlineQueue[m].src=this.lexer.inlineQueue[m].src.replace(this.rules.other.listReplaceTask,"");break}let u=this.rules.other.listTaskCheckbox.exec(l.raw);if(u){let m={type:"checkbox",raw:u[0]+" ",checked:u[0]!=="[ ]"};l.checked=m.checked,o.loose?l.tokens[0]&&["paragraph","text"].includes(l.tokens[0].type)&&"tokens"in l.tokens[0]&&l.tokens[0].tokens?(l.tokens[0].raw=m.raw+l.tokens[0].raw,l.tokens[0].text=m.raw+l.tokens[0].text,l.tokens[0].tokens.unshift(m)):l.tokens.unshift({type:"paragraph",raw:m.raw,text:m.raw,tokens:[m]}):l.tokens.unshift(m)}}else l.task&&(l.task=!1);if(!o.loose){let u=l.tokens.filter(y=>y.type==="space"),m=u.length>0&&u.some(y=>this.rules.other.anyLine.test(y.raw));o.loose=m}}if(o.loose)for(let l of o.items){l.loose=!0;for(let c of l.tokens)c.type==="text"&&(c.type="paragraph")}return o}}html(t){let e=this.rules.block.html.exec(t);if(e){let n=Fu(e[0]);return{type:"html",block:!0,raw:n,pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:n}}}def(t){let e=this.rules.block.def.exec(t);if(e){let n=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),r=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",o=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:n,raw:Nt(e[0],`
69
+ `),href:r,title:o}}}table(t){let e=this.rules.block.table.exec(t);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let n=Hu(e[1]),r=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),o=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
70
70
  `):[],i={type:"table",raw:Nt(e[0],`
71
- `),header:[],align:[],rows:[]};if(n.length===r.length){for(let s of r)this.rules.other.tableAlignRight.test(s)?i.align.push("right"):this.rules.other.tableAlignCenter.test(s)?i.align.push("center"):this.rules.other.tableAlignLeft.test(s)?i.align.push("left"):i.align.push(null);for(let s=0;s<n.length;s++)i.header.push({text:n[s],tokens:this.lexer.inline(n[s]),header:!0,align:i.align[s]});for(let s of o)i.rows.push(Mu(s,i.header.length).map((a,l)=>({text:a,tokens:this.lexer.inline(a),header:!1,align:i.align[l]})));return i}}lheading(t){let e=this.rules.block.lheading.exec(t);if(e){let n=e[1].trim();return{type:"heading",raw:Nt(e[0],`
71
+ `),header:[],align:[],rows:[]};if(n.length===r.length){for(let s of r)this.rules.other.tableAlignRight.test(s)?i.align.push("right"):this.rules.other.tableAlignCenter.test(s)?i.align.push("center"):this.rules.other.tableAlignLeft.test(s)?i.align.push("left"):i.align.push(null);for(let s=0;s<n.length;s++)i.header.push({text:n[s],tokens:this.lexer.inline(n[s]),header:!0,align:i.align[s]});for(let s of o)i.rows.push(Hu(s,i.header.length).map((a,l)=>({text:a,tokens:this.lexer.inline(a),header:!1,align:i.align[l]})));return i}}lheading(t){let e=this.rules.block.lheading.exec(t);if(e){let n=e[1].trim();return{type:"heading",raw:Nt(e[0],`
72
72
  `),depth:e[2].charAt(0)==="="?1:2,text:n,tokens:this.lexer.inline(n)}}}paragraph(t){let e=this.rules.block.paragraph.exec(t);if(e){let n=e[1].charAt(e[1].length-1)===`
73
- `?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:n,tokens:this.lexer.inline(n)}}}text(t){let e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){let e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){let e=this.rules.inline.tag.exec(t);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(t){let e=this.rules.inline.link.exec(t);if(e){let n=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let i=Nt(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{let i=xy(e[2],"()");if(i===-2)return;if(i>-1){let s=(e[0].indexOf("!")===0?5:4)+e[1].length+i;e[2]=e[2].substring(0,i),e[0]=e[0].substring(0,s).trim(),e[3]=""}}let r=e[2],o="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(r);i&&(r=i[1],o=i[3])}else o=e[3]?e[3].slice(1,-1):"";return r=r.trim(),this.rules.other.startAngleBracket.test(r)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?r=r.slice(1):r=r.slice(1,-1)),Pu(e,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:o&&o.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(t,e){let n;if((n=this.rules.inline.reflink.exec(t))||(n=this.rules.inline.nolink.exec(t))){let r=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),o=e[r.toLowerCase()];if(!o){let i=n[0].charAt(0);return{type:"text",raw:i,text:i}}return Pu(n,o,n[0],this.lexer,this.rules)}}emStrong(t,e,n=""){let r=this.rules.inline.emStrongLDelim.exec(t);if(!(!r||!r[1]&&!r[2]&&!r[3]&&!r[4]||r[4]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[3])||!n||this.rules.inline.punctuation.exec(n))){let o=[...r[0]].length-1,i,s,a=o,l=0,c=r[0][0],u=n===c,m=c==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(m.lastIndex=0,e=e.slice(-1*t.length+o);(r=m.exec(e))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(s=[...i].length,r[3]||r[4]){a+=s;continue}else if(r[5]||r[6]){if(o%3&&!((o+s)%3)){l+=s;continue}if(u)break}if(a-=s,a>0)continue;s=Math.min(s,s+a+l);let y=[...r[0]][0].length,f=t.slice(0,o+r.index+y+s);if(Math.min(o,s)%2){let g=f.slice(1,-1);return{type:"em",raw:f,text:g,tokens:this.lexer.inlineTokens(g)}}let h=f.slice(2,-2);return{type:"strong",raw:f,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(t){let e=this.rules.inline.code.exec(t);if(e){let n=e[2].replace(this.rules.other.newLineCharGlobal," "),r=this.rules.other.nonSpaceChar.test(n),o=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return r&&o&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:e[0],text:n}}}br(t){let e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t,e,n=""){let r=this.rules.inline.delLDelim.exec(t);if(r&&(!r[1]||!n||this.rules.inline.punctuation.exec(n))){let o=[...r[0]].length-1,i,s,a=o,l=this.rules.inline.delRDelim;for(l.lastIndex=0,e=e.slice(-1*t.length+o);(r=l.exec(e))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i||(s=[...i].length,s!==o))continue;if(r[3]||r[4]){a+=s;continue}if(a-=s,a>0)continue;s=Math.min(s,s+a);let c=[...r[0]][0].length,u=t.slice(0,o+r.index+c+s),m=u.slice(o,-o);return{type:"del",raw:u,text:m,tokens:this.lexer.inlineTokens(m)}}}}autolink(t){let e=this.rules.inline.autolink.exec(t);if(e){let n,r;return e[2]==="@"?(n=e[1],r="mailto:"+n):(n=e[1],r=n),{type:"link",raw:e[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let n,r;if(e[2]==="@")n=e[0],r="mailto:"+n;else{let o;do o=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(o!==e[0]);n=e[0],e[1]==="www."?r="http://"+e[0]:r=e[0]}return{type:"link",raw:e[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(t){let e=this.rules.inline.text.exec(t);if(e){let n=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:n}}}},Qe=class Qa{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||dn,this.options.tokenizer=this.options.tokenizer||new Mi,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let n={other:Ce,block:Ni.normal,inline:wr.normal};this.options.pedantic?(n.block=Ni.pedantic,n.inline=wr.pedantic):this.options.gfm&&(n.block=Ni.gfm,this.options.breaks?n.inline=wr.breaks:n.inline=wr.gfm),this.tokenizer.rules=n}static get rules(){return{block:Ni,inline:wr}}static lex(e,n){return new Qa(n).lex(e)}static lexInline(e,n){return new Qa(n).inlineTokens(e)}lex(e){e=e.replace(Ce.carriageReturn,`
73
+ `?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:n,tokens:this.lexer.inline(n)}}}text(t){let e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){let e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){let e=this.rules.inline.tag.exec(t);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(t){let e=this.rules.inline.link.exec(t);if(e){let n=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let i=Nt(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{let i=ky(e[2],"()");if(i===-2)return;if(i>-1){let s=(e[0].indexOf("!")===0?5:4)+e[1].length+i;e[2]=e[2].substring(0,i),e[0]=e[0].substring(0,s).trim(),e[3]=""}}let r=e[2],o="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(r);i&&(r=i[1],o=i[3])}else o=e[3]?e[3].slice(1,-1):"";return r=r.trim(),this.rules.other.startAngleBracket.test(r)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?r=r.slice(1):r=r.slice(1,-1)),zu(e,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:o&&o.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(t,e){let n;if((n=this.rules.inline.reflink.exec(t))||(n=this.rules.inline.nolink.exec(t))){let r=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),o=e[r.toLowerCase()];if(!o){let i=n[0].charAt(0);return{type:"text",raw:i,text:i}}return zu(n,o,n[0],this.lexer,this.rules)}}emStrong(t,e,n=""){let r=this.rules.inline.emStrongLDelim.exec(t);if(!(!r||!r[1]&&!r[2]&&!r[3]&&!r[4]||r[4]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[3])||!n||this.rules.inline.punctuation.exec(n))){let o=[...r[0]].length-1,i,s,a=o,l=0,c=r[0][0],u=n===c,m=c==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(m.lastIndex=0,e=e.slice(-1*t.length+o);(r=m.exec(e))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(s=[...i].length,r[3]||r[4]){a+=s;continue}else if(r[5]||r[6]){if(o%3&&!((o+s)%3)){l+=s;continue}if(u)break}if(a-=s,a>0)continue;s=Math.min(s,s+a+l);let y=[...r[0]][0].length,f=t.slice(0,o+r.index+y+s);if(Math.min(o,s)%2){let g=f.slice(1,-1);return{type:"em",raw:f,text:g,tokens:this.lexer.inlineTokens(g)}}let h=f.slice(2,-2);return{type:"strong",raw:f,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(t){let e=this.rules.inline.code.exec(t);if(e){let n=e[2].replace(this.rules.other.newLineCharGlobal," "),r=this.rules.other.nonSpaceChar.test(n),o=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return r&&o&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:e[0],text:n}}}br(t){let e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t,e,n=""){let r=this.rules.inline.delLDelim.exec(t);if(r&&(!r[1]||!n||this.rules.inline.punctuation.exec(n))){let o=[...r[0]].length-1,i,s,a=o,l=this.rules.inline.delRDelim;for(l.lastIndex=0,e=e.slice(-1*t.length+o);(r=l.exec(e))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i||(s=[...i].length,s!==o))continue;if(r[3]||r[4]){a+=s;continue}if(a-=s,a>0)continue;s=Math.min(s,s+a);let c=[...r[0]][0].length,u=t.slice(0,o+r.index+c+s),m=u.slice(o,-o);return{type:"del",raw:u,text:m,tokens:this.lexer.inlineTokens(m)}}}}autolink(t){let e=this.rules.inline.autolink.exec(t);if(e){let n,r;return e[2]==="@"?(n=e[1],r="mailto:"+n):(n=e[1],r=n),{type:"link",raw:e[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let n,r;if(e[2]==="@")n=e[0],r="mailto:"+n;else{let o;do o=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(o!==e[0]);n=e[0],e[1]==="www."?r="http://"+e[0]:r=e[0]}return{type:"link",raw:e[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(t){let e=this.rules.inline.text.exec(t);if(e){let n=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:n}}}},Qe=class tl{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||dn,this.options.tokenizer=this.options.tokenizer||new Di,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let n={other:Ce,block:Li.normal,inline:_r.normal};this.options.pedantic?(n.block=Li.pedantic,n.inline=_r.pedantic):this.options.gfm&&(n.block=Li.gfm,this.options.breaks?n.inline=_r.breaks:n.inline=_r.gfm),this.tokenizer.rules=n}static get rules(){return{block:Li,inline:_r}}static lex(e,n){return new tl(n).lex(e)}static lexInline(e,n){return new tl(n).inlineTokens(e)}lex(e){e=e.replace(Ce.carriageReturn,`
74
74
  `),this.blockTokens(e,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let r=this.inlineQueue[n];this.inlineTokens(r.src,r.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,n=[],r=!1){this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(Ce.tabCharGlobal," ").replace(Ce.spaceLine,""));let o=1/0;for(;e;){if(e.length<o)o=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}let i;if(this.options.extensions?.block?.some(a=>(i=a.call({lexer:this},e,n))?(e=e.substring(i.raw.length),n.push(i),!0):!1))continue;if(i=this.tokenizer.space(e)){e=e.substring(i.raw.length);let a=n.at(-1);i.raw.length===1&&a!==void 0?a.raw+=`
75
75
  `:n.push(i);continue}if(i=this.tokenizer.code(e)){e=e.substring(i.raw.length);let a=n.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=(a.raw.endsWith(`
76
76
  `)?"":`
@@ -84,7 +84,7 @@ ${h}`,o=o.substring(0,o.length-f.text.length)+x.text;break}else if(y?.type==="li
84
84
  `+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):n.push(i),r=s.length!==e.length,e=e.substring(i.raw.length);continue}if(i=this.tokenizer.text(e)){e=e.substring(i.raw.length);let a=n.at(-1);a?.type==="text"?(a.raw+=(a.raw.endsWith(`
85
85
  `)?"":`
86
86
  `)+i.raw,a.text+=`
87
- `+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):n.push(i);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,n}inline(e,n=[]){return this.inlineQueue.push({src:e,tokens:n}),n}inlineTokens(e,n=[]){this.tokenizer.lexer=this;let r=e;if(this.tokens.links){let a=Object.keys(this.tokens.links);a.length>0&&(r=r.replace(this.tokenizer.rules.inline.reflinkSearch,l=>a.includes(l.slice(l.lastIndexOf("[")+1,-1))?"["+"a".repeat(l.length-2)+"]":l))}r=r.replace(this.tokenizer.rules.inline.anyPunctuation,"++"),r=r.replace(this.tokenizer.rules.inline.blockSkip,(a,l,c)=>{let u=c?c.length:0;return a.slice(0,u)+"["+"a".repeat(a.length-u-2)+"]"}),r=this.options.hooks?.emStrongMask?.call({lexer:this},r)??r;let o=!1,i="",s=1/0;for(;e;){if(e.length<s)s=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}o||(i=""),o=!1;let a;if(this.options.extensions?.inline?.some(c=>(a=c.call({lexer:this},e,n))?(e=e.substring(a.raw.length),n.push(a),!0):!1))continue;if(a=this.tokenizer.escape(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.tag(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.link(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(a.raw.length);let c=n.at(-1);a.type==="text"&&c?.type==="text"?(c.raw+=a.raw,c.text+=a.text):n.push(a);continue}if(a=this.tokenizer.emStrong(e,r,i)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.codespan(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.br(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.del(e,r,i)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.autolink(e)){e=e.substring(a.raw.length),n.push(a);continue}if(!this.state.inLink&&(a=this.tokenizer.url(e))){e=e.substring(a.raw.length),n.push(a);continue}let l=e;if(this.options.extensions?.startInline){let c=1/0,u=e.slice(1),m;this.options.extensions.startInline.forEach(y=>{m=y.call({lexer:this},u),typeof m=="number"&&m>=0&&(c=Math.min(c,m))}),c<1/0&&c>=0&&(l=e.substring(0,c+1))}if(a=this.tokenizer.inlineText(l)){e=e.substring(a.raw.length),a.raw.slice(-1)!=="_"&&(i=a.raw.slice(-1)),o=!0;let c=n.at(-1);c?.type==="text"?(c.raw+=a.raw,c.text+=a.text):n.push(a);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return n}infiniteLoopError(e){let n="Infinite loop on byte: "+e;if(this.options.silent)console.error(n);else throw new Error(n)}},Li=class{options;parser;constructor(t){this.options=t||dn}space(t){return""}code({text:t,lang:e,escaped:n}){let r=(e||"").match(Ce.notSpaceStart)?.[0],o=t.replace(Ce.endingNewline,"")+`
87
+ `+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):n.push(i);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,n}inline(e,n=[]){return this.inlineQueue.push({src:e,tokens:n}),n}inlineTokens(e,n=[]){this.tokenizer.lexer=this;let r=e;if(this.tokens.links){let a=Object.keys(this.tokens.links);a.length>0&&(r=r.replace(this.tokenizer.rules.inline.reflinkSearch,l=>a.includes(l.slice(l.lastIndexOf("[")+1,-1))?"["+"a".repeat(l.length-2)+"]":l))}r=r.replace(this.tokenizer.rules.inline.anyPunctuation,"++"),r=r.replace(this.tokenizer.rules.inline.blockSkip,(a,l,c)=>{let u=c?c.length:0;return a.slice(0,u)+"["+"a".repeat(a.length-u-2)+"]"}),r=this.options.hooks?.emStrongMask?.call({lexer:this},r)??r;let o=!1,i="",s=1/0;for(;e;){if(e.length<s)s=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}o||(i=""),o=!1;let a;if(this.options.extensions?.inline?.some(c=>(a=c.call({lexer:this},e,n))?(e=e.substring(a.raw.length),n.push(a),!0):!1))continue;if(a=this.tokenizer.escape(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.tag(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.link(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(a.raw.length);let c=n.at(-1);a.type==="text"&&c?.type==="text"?(c.raw+=a.raw,c.text+=a.text):n.push(a);continue}if(a=this.tokenizer.emStrong(e,r,i)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.codespan(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.br(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.del(e,r,i)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.autolink(e)){e=e.substring(a.raw.length),n.push(a);continue}if(!this.state.inLink&&(a=this.tokenizer.url(e))){e=e.substring(a.raw.length),n.push(a);continue}let l=e;if(this.options.extensions?.startInline){let c=1/0,u=e.slice(1),m;this.options.extensions.startInline.forEach(y=>{m=y.call({lexer:this},u),typeof m=="number"&&m>=0&&(c=Math.min(c,m))}),c<1/0&&c>=0&&(l=e.substring(0,c+1))}if(a=this.tokenizer.inlineText(l)){e=e.substring(a.raw.length),a.raw.slice(-1)!=="_"&&(i=a.raw.slice(-1)),o=!0;let c=n.at(-1);c?.type==="text"?(c.raw+=a.raw,c.text+=a.text):n.push(a);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return n}infiniteLoopError(e){let n="Infinite loop on byte: "+e;if(this.options.silent)console.error(n);else throw new Error(n)}},Ui=class{options;parser;constructor(t){this.options=t||dn}space(t){return""}code({text:t,lang:e,escaped:n}){let r=(e||"").match(Ce.notSpaceStart)?.[0],o=t.replace(Ce.endingNewline,"")+`
88
88
  `;return r?'<pre><code class="language-'+ut(r)+'">'+(n?o:ut(o,!0))+`</code></pre>
89
89
  `:"<pre><code>"+(n?o:ut(o,!0))+`</code></pre>
90
90
  `}blockquote({tokens:t}){return`<blockquote>
@@ -102,8 +102,8 @@ ${this.parser.parse(t)}</blockquote>
102
102
  `}tablerow({text:t}){return`<tr>
103
103
  ${t}</tr>
104
104
  `}tablecell(t){let e=this.parser.parseInline(t.tokens),n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>
105
- `}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${ut(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,tokens:n}){let r=this.parser.parseInline(n),o=Ou(t);if(o===null)return r;t=o;let i='<a href="'+t+'"';return e&&(i+=' title="'+ut(e)+'"'),i+=">"+r+"</a>",i}image({href:t,title:e,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let o=Ou(t);if(o===null)return ut(n);t=o;let i=`<img src="${t}" alt="${ut(n)}"`;return e&&(i+=` title="${ut(e)}"`),i+=">",i}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:ut(t.text)}},al=class{strong({text:t}){return t}em({text:t}){return t}codespan({text:t}){return t}del({text:t}){return t}html({text:t}){return t}text({text:t}){return t}link({text:t}){return""+t}image({text:t}){return""+t}br(){return""}checkbox({raw:t}){return t}},Je=class Ja{options;renderer;textRenderer;constructor(e){this.options=e||dn,this.options.renderer=this.options.renderer||new Li,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new al}static parse(e,n){return new Ja(n).parse(e)}static parseInline(e,n){return new Ja(n).parseInline(e)}parse(e){this.renderer.parser=this;let n="";for(let r=0;r<e.length;r++){let o=e[r];if(this.options.extensions?.renderers?.[o.type]){let s=o,a=this.options.extensions.renderers[s.type].call({parser:this},s);if(a!==!1||!["space","hr","heading","code","table","blockquote","list","checkbox","html","def","paragraph","text"].includes(s.type)){n+=a||"";continue}}let i=o;switch(i.type){case"space":{n+=this.renderer.space(i);break}case"hr":{n+=this.renderer.hr(i);break}case"heading":{n+=this.renderer.heading(i);break}case"code":{n+=this.renderer.code(i);break}case"table":{n+=this.renderer.table(i);break}case"blockquote":{n+=this.renderer.blockquote(i);break}case"list":{n+=this.renderer.list(i);break}case"checkbox":{n+=this.renderer.checkbox(i);break}case"html":{n+=this.renderer.html(i);break}case"def":{n+=this.renderer.def(i);break}case"paragraph":{n+=this.renderer.paragraph(i);break}case"text":{n+=this.renderer.text(i);break}default:{let s='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(s),"";throw new Error(s)}}}return n}parseInline(e,n=this.renderer){this.renderer.parser=this;let r="";for(let o=0;o<e.length;o++){let i=e[o];if(this.options.extensions?.renderers?.[i.type]){let a=this.options.extensions.renderers[i.type].call({parser:this},i);if(a!==!1||!["escape","html","link","image","checkbox","strong","em","codespan","br","del","text"].includes(i.type)){r+=a||"";continue}}let s=i;switch(s.type){case"escape":{r+=n.text(s);break}case"html":{r+=n.html(s);break}case"link":{r+=n.link(s);break}case"image":{r+=n.image(s);break}case"checkbox":{r+=n.checkbox(s);break}case"strong":{r+=n.strong(s);break}case"em":{r+=n.em(s);break}case"codespan":{r+=n.codespan(s);break}case"br":{r+=n.br(s);break}case"del":{r+=n.del(s);break}case"text":{r+=n.text(s);break}default:{let a='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return r}},Er=class{options;block;constructor(t){this.options=t||dn}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}emStrongMask(t){return t}provideLexer(t=this.block){return t?Qe.lex:Qe.lexInline}provideParser(t=this.block){return t?Je.parse:Je.parseInline}},ll=class{defaults=el();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Je;Renderer=Li;TextRenderer=al;Lexer=Qe;Tokenizer=Mi;Hooks=Er;constructor(...t){this.use(...t)}walkTokens(t,e){let n=[];for(let r of t)switch(n=n.concat(e.call(this,r)),r.type){case"table":{let o=r;for(let i of o.header)n=n.concat(this.walkTokens(i.tokens,e));for(let i of o.rows)for(let s of i)n=n.concat(this.walkTokens(s.tokens,e));break}case"list":{let o=r;n=n.concat(this.walkTokens(o.items,e));break}default:{let o=r;this.defaults.extensions?.childTokens?.[o.type]?this.defaults.extensions.childTokens[o.type].forEach(i=>{let s=o[i].flat(1/0);n=n.concat(this.walkTokens(s,e))}):o.tokens&&(n=n.concat(this.walkTokens(o.tokens,e)))}}return n}use(...t){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{let r={...n};if(r.async=this.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if("renderer"in o){let i=e.renderers[o.name];i?e.renderers[o.name]=function(...s){let a=o.renderer.apply(this,s);return a===!1&&(a=i.apply(this,s)),a}:e.renderers[o.name]=o.renderer}if("tokenizer"in o){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let i=e[o.level];i?i.unshift(o.tokenizer):e[o.level]=[o.tokenizer],o.start&&(o.level==="block"?e.startBlock?e.startBlock.push(o.start):e.startBlock=[o.start]:o.level==="inline"&&(e.startInline?e.startInline.push(o.start):e.startInline=[o.start]))}"childTokens"in o&&o.childTokens&&(e.childTokens[o.name]=o.childTokens)}),r.extensions=e),n.renderer){let o=this.defaults.renderer||new Li(this.defaults);for(let i in n.renderer){if(!(i in o))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let s=i,a=n.renderer[s],l=o[s];o[s]=(...c)=>{let u=a.apply(o,c);return u===!1&&(u=l.apply(o,c)),u||""}}r.renderer=o}if(n.tokenizer){let o=this.defaults.tokenizer||new Mi(this.defaults);for(let i in n.tokenizer){if(!(i in o))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let s=i,a=n.tokenizer[s],l=o[s];o[s]=(...c)=>{let u=a.apply(o,c);return u===!1&&(u=l.apply(o,c)),u}}r.tokenizer=o}if(n.hooks){let o=this.defaults.hooks||new Er;for(let i in n.hooks){if(!(i in o))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let s=i,a=n.hooks[s],l=o[s];Er.passThroughHooks.has(i)?o[s]=c=>{if(this.defaults.async&&Er.passThroughHooksRespectAsync.has(i))return(async()=>{let m=await a.call(o,c);return l.call(o,m)})();let u=a.call(o,c);return l.call(o,u)}:o[s]=(...c)=>{if(this.defaults.async)return(async()=>{let m=await a.apply(o,c);return m===!1&&(m=await l.apply(o,c)),m})();let u=a.apply(o,c);return u===!1&&(u=l.apply(o,c)),u}}r.hooks=o}if(n.walkTokens){let o=this.defaults.walkTokens,i=n.walkTokens;r.walkTokens=function(s){let a=[];return a.push(i.call(this,s)),o&&(a=a.concat(o.call(this,s))),a}}this.defaults={...this.defaults,...r}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return Qe.lex(t,e??this.defaults)}parser(t,e){return Je.parse(t,e??this.defaults)}parseMarkdown(t){return(e,n)=>{let r={...n},o={...this.defaults,...r},i=this.onError(!!o.silent,!!o.async);if(this.defaults.async===!0&&r.async===!1)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(o.hooks&&(o.hooks.options=o,o.hooks.block=t),o.async)return(async()=>{let s=o.hooks?await o.hooks.preprocess(e):e,a=await(o.hooks?await o.hooks.provideLexer(t):t?Qe.lex:Qe.lexInline)(s,o),l=o.hooks?await o.hooks.processAllTokens(a):a;o.walkTokens&&await Promise.all(this.walkTokens(l,o.walkTokens));let c=await(o.hooks?await o.hooks.provideParser(t):t?Je.parse:Je.parseInline)(l,o);return o.hooks?await o.hooks.postprocess(c):c})().catch(i);try{o.hooks&&(e=o.hooks.preprocess(e));let s=(o.hooks?o.hooks.provideLexer(t):t?Qe.lex:Qe.lexInline)(e,o);o.hooks&&(s=o.hooks.processAllTokens(s)),o.walkTokens&&this.walkTokens(s,o.walkTokens);let a=(o.hooks?o.hooks.provideParser(t):t?Je.parse:Je.parseInline)(s,o);return o.hooks&&(a=o.hooks.postprocess(a)),a}catch(s){return i(s)}}}onError(t,e){return n=>{if(n.message+=`
106
- Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error occurred:</p><pre>"+ut(n.message+"",!0)+"</pre>";return e?Promise.resolve(r):r}if(e)return Promise.reject(n);throw n}}},cn=new ll;function Q(t,e){return cn.parse(t,e)}Q.options=Q.setOptions=function(t){return cn.setOptions(t),Q.defaults=cn.defaults,Du(Q.defaults),Q};Q.getDefaults=el;Q.defaults=dn;function _y(...t){return cn.use(...t),Q.defaults=cn.defaults,Du(Q.defaults),Q}Q.use=_y;Q.walkTokens=function(t,e){return cn.walkTokens(t,e)};Q.parseInline=cn.parseInline;Q.Parser=Je;Q.parser=Je.parse;Q.Renderer=Li;Q.TextRenderer=al;Q.Lexer=Qe;Q.lexer=Qe.lex;Q.Tokenizer=Mi;Q.Hooks=Er;Q.parse=Q;var z0=Q.options,F0=Q.setOptions,G0=Q.walkTokens,$0=Q.parseInline;var B0=Je.parse,V0=Qe.lex;var Ty=new ll({gfm:!0,breaks:!0}),qu=["a","p","br","strong","em","b","i","u","s","del","code","pre","ul","ol","li","blockquote","h1","h2","h3","h4","h5","h6","hr","span","table","thead","tbody","tr","th","td"],Wu=["href","title","class","target","rel"],Xu={ALLOWED_TAGS:qu,ALLOWED_ATTR:Wu,ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!1},Sy={...Xu,ALLOWED_TAGS:[...qu,"img"],ALLOWED_ATTR:[...Wu,"src","alt","width","height"]},Ay=/^language-[A-Za-z0-9_+#.-]+$/,ky=new Set(["CODE","PRE"]);function Cy(t){t.nodeName==="A"&&t.hasAttribute("href")?(t.setAttribute("target","_blank"),t.setAttribute("rel","noopener noreferrer")):(t.removeAttribute("target"),t.removeAttribute("rel"));let e=t.getAttribute("class");if(e===null)return;let n=ky.has(t.nodeName)?e.split(/\s+/).filter(r=>Ay.test(r)):[];if(n.length===0){t.removeAttribute("class");return}t.setAttribute("class",n.join(" "))}var Di=null;function Iy(){return Di===null&&(Di=Cu(),Di.addHook("afterSanitizeAttributes",Cy)),Di}function Ui(t,e){let n=e?.allowImages===!0,r=Ty.parse(t,{async:!1});return Iy().sanitize(r,n?Sy:Xu).trim()}function Ku(t){let e=document.createElement("div");e.className="resize-handle",e.setAttribute("part","resize-handle"),e.setAttribute("role","separator"),e.setAttribute("aria-label",t.label),e.tabIndex=0;let n=(i,s,a,l,c)=>{let u=s.x==="right"?a.right-l:l-a.left,m={width:Math.max(280,u)};if(i!=="both")return m;let y=s.y==="bottom"?a.bottom-c:c-a.top;return{...m,height:Math.max(240,y)}};e.addEventListener("pointerdown",i=>{let s=t.axis();if(s==="none")return;let a=t.anchor(),l=t.rect(),c=m=>{t.apply(n(s,a,l,m.clientX,m.clientY))},u=m=>{window.removeEventListener("pointermove",c),window.removeEventListener("pointerup",u),e.removeAttribute("data-dragging"),t.commit(n(s,a,l,m.clientX,m.clientY))};e.setAttribute("data-dragging","true"),window.addEventListener("pointermove",c),window.addEventListener("pointerup",u),i.preventDefault()});let r=null,o=()=>{if(r===null)return;let i=r;r=null,t.commit(i)};return e.addEventListener("keydown",i=>{let s=t.axis();if(s==="none")return;let a=t.anchor(),l=t.rect(),c=i.shiftKey?64:16,u=a.x==="right"?-1:1,m=l.right-l.left,y=l.bottom-l.top,f=null;if(i.key==="ArrowLeft")f={width:Math.max(280,m-c*u)};else if(i.key==="ArrowRight")f={width:Math.max(280,m+c*u)};else if(s==="both"&&(i.key==="ArrowUp"||i.key==="ArrowDown")){let h=i.key===(a.y==="bottom"?"ArrowUp":"ArrowDown");f={height:Math.max(240,y+(h?c:-c))}}f!==null&&(i.preventDefault(),t.apply(f),r=f)}),e.addEventListener("keyup",o),e.addEventListener("blur",o),e}function Yu(t,e){for(let n of Array.from(t.childNodes))n.nodeType===Node.TEXT_NODE?e.push({node:n,parent:t}):Yu(n,e)}function Zu(t){let e=[];Yu(t,e);let n=0;for(let{node:r,parent:o}of e){let i=document.createDocumentFragment();for(let s of r.data.split(/(\s+)/)){if(s==="")continue;if(/\s/.test(s)){i.appendChild(document.createTextNode(s));continue}let a=document.createElement("span");a.className="word",a.style.setProperty("--ag-ui-word-index",String(n)),a.textContent=s,i.appendChild(a),n+=1}o.replaceChild(i,r)}}function cl(t,e,n){let r=document.createElement("div");r.className=`run-notice run-notice--${n}`,r.setAttribute("part",`run-notice run-notice-${n}`),r.setAttribute("role","status");let o=document.createElement("span");o.className="run-notice-icon",o.setAttribute("part","run-notice-icon"),o.textContent=t,o.setAttribute("aria-hidden","true");let i=document.createElement("span");return i.className="run-notice-text",i.setAttribute("part","run-notice-text"),i.textContent=e,r.append(o,i),r}var Hi=class{chips;palette;#t;#r=[];#e=!1;#s=!1;#n=[];#i=0;constructor(e){this.#t=e,this.chips=document.createElement("div"),this.chips.className="skill-chips",this.chips.setAttribute("part","skill-chips"),this.chips.hidden=!0,this.palette=document.createElement("div"),this.palette.className="skill-palette",this.palette.setAttribute("part","skill-palette"),this.palette.setAttribute("role","listbox"),this.palette.hidden=!0}setSkills(e){this.#r=e,this.#a()}enableChips(e){this.#e=e,this.#a()}enableSlash(e){this.#s=e}isOpen(){return!this.palette.hidden}onInput(e){this.#s&&e.startsWith("/")?this.#o(e.slice(1)):this.close()}onKeydown(e){return this.isOpen()?e.key==="ArrowDown"?(this.#c(1),!0):e.key==="ArrowUp"?(this.#c(-1),!0):e.key==="Escape"?(this.close(),!0):e.key==="Enter"?(this.#n.slice(this.#i,this.#i+1).forEach(n=>{this.#d(n)}),!0):!1:!1}close(){this.palette.hidden=!0,this.palette.replaceChildren()}#o(e){let n=e.trim().toLowerCase(),r=this.#r.filter(o=>o.name.toLowerCase().includes(n)||o.title.toLowerCase().includes(n));if(r.length===0){this.close();return}this.#n=r,this.#i=0,this.#u(),this.palette.hidden=!1}#c(e){let n=this.#n.length;this.#i=(this.#i+e+n)%n,this.#u()}#d(e){this.close(),this.#t(e)}#a(){this.chips.replaceChildren();let e=this.#e?this.#r.filter(n=>n.chip===!0):[];this.chips.hidden=e.length===0;for(let n of e){let r=document.createElement("button");r.type="button",r.className="skill-chip",r.setAttribute("part","skill-chip"),r.textContent=n.title,r.title=`/${n.name}`,r.addEventListener("click",()=>this.#d(n)),this.chips.appendChild(r)}}#u(){this.palette.replaceChildren(),this.#n.forEach((e,n)=>{let r=document.createElement("button");r.type="button",r.className="skill-item",r.setAttribute("part","skill-item"),r.setAttribute("role","option"),r.setAttribute("aria-selected",n===this.#i?"true":"false");let o=document.createElement("span");o.className="skill-item-title",o.setAttribute("part","skill-item-title");let i=document.createElement("code");if(i.className="skill-item-token",i.setAttribute("part","skill-item-token"),i.textContent=`/${e.name}`,o.append(i,document.createTextNode(` ${e.title}`)),r.appendChild(o),e.description!==void 0){let s=document.createElement("span");s.className="skill-item-desc",s.setAttribute("part","skill-item-desc"),s.textContent=e.description,r.appendChild(s)}r.addEventListener("click",()=>this.#d(e)),this.palette.appendChild(r)})}};function Qu({viewport:t,onMissedContent:e}){let n=!0,r=!1,o=()=>t.scrollHeight-t.scrollTop-t.clientHeight<=4,i=u=>{u!==r&&(r=u,e(r))},s=()=>{t.scrollTop=t.scrollHeight},a=()=>{n=o(),n&&i(!1)},l=()=>{if(n){s();return}i(!0)};t.addEventListener("scroll",a,{passive:!0});let c=new ResizeObserver(()=>{n&&s()});return c.observe(t),{follow:l,jump:()=>{n=!0,i(!1),s()},following:()=>n,dispose:()=>{t.removeEventListener("scroll",a),c.disconnect()}}}var Ju=`
105
+ `}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${ut(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,tokens:n}){let r=this.parser.parseInline(n),o=Uu(t);if(o===null)return r;t=o;let i='<a href="'+t+'"';return e&&(i+=' title="'+ut(e)+'"'),i+=">"+r+"</a>",i}image({href:t,title:e,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let o=Uu(t);if(o===null)return ut(n);t=o;let i=`<img src="${t}" alt="${ut(n)}"`;return e&&(i+=` title="${ut(e)}"`),i+=">",i}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:ut(t.text)}},dl=class{strong({text:t}){return t}em({text:t}){return t}codespan({text:t}){return t}del({text:t}){return t}html({text:t}){return t}text({text:t}){return t}link({text:t}){return""+t}image({text:t}){return""+t}br(){return""}checkbox({raw:t}){return t}},Je=class nl{options;renderer;textRenderer;constructor(e){this.options=e||dn,this.options.renderer=this.options.renderer||new Ui,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new dl}static parse(e,n){return new nl(n).parse(e)}static parseInline(e,n){return new nl(n).parseInline(e)}parse(e){this.renderer.parser=this;let n="";for(let r=0;r<e.length;r++){let o=e[r];if(this.options.extensions?.renderers?.[o.type]){let s=o,a=this.options.extensions.renderers[s.type].call({parser:this},s);if(a!==!1||!["space","hr","heading","code","table","blockquote","list","checkbox","html","def","paragraph","text"].includes(s.type)){n+=a||"";continue}}let i=o;switch(i.type){case"space":{n+=this.renderer.space(i);break}case"hr":{n+=this.renderer.hr(i);break}case"heading":{n+=this.renderer.heading(i);break}case"code":{n+=this.renderer.code(i);break}case"table":{n+=this.renderer.table(i);break}case"blockquote":{n+=this.renderer.blockquote(i);break}case"list":{n+=this.renderer.list(i);break}case"checkbox":{n+=this.renderer.checkbox(i);break}case"html":{n+=this.renderer.html(i);break}case"def":{n+=this.renderer.def(i);break}case"paragraph":{n+=this.renderer.paragraph(i);break}case"text":{n+=this.renderer.text(i);break}default:{let s='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(s),"";throw new Error(s)}}}return n}parseInline(e,n=this.renderer){this.renderer.parser=this;let r="";for(let o=0;o<e.length;o++){let i=e[o];if(this.options.extensions?.renderers?.[i.type]){let a=this.options.extensions.renderers[i.type].call({parser:this},i);if(a!==!1||!["escape","html","link","image","checkbox","strong","em","codespan","br","del","text"].includes(i.type)){r+=a||"";continue}}let s=i;switch(s.type){case"escape":{r+=n.text(s);break}case"html":{r+=n.html(s);break}case"link":{r+=n.link(s);break}case"image":{r+=n.image(s);break}case"checkbox":{r+=n.checkbox(s);break}case"strong":{r+=n.strong(s);break}case"em":{r+=n.em(s);break}case"codespan":{r+=n.codespan(s);break}case"br":{r+=n.br(s);break}case"del":{r+=n.del(s);break}case"text":{r+=n.text(s);break}default:{let a='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return r}},Tr=class{options;block;constructor(t){this.options=t||dn}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}emStrongMask(t){return t}provideLexer(t=this.block){return t?Qe.lex:Qe.lexInline}provideParser(t=this.block){return t?Je.parse:Je.parseInline}},ul=class{defaults=rl();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Je;Renderer=Ui;TextRenderer=dl;Lexer=Qe;Tokenizer=Di;Hooks=Tr;constructor(...t){this.use(...t)}walkTokens(t,e){let n=[];for(let r of t)switch(n=n.concat(e.call(this,r)),r.type){case"table":{let o=r;for(let i of o.header)n=n.concat(this.walkTokens(i.tokens,e));for(let i of o.rows)for(let s of i)n=n.concat(this.walkTokens(s.tokens,e));break}case"list":{let o=r;n=n.concat(this.walkTokens(o.items,e));break}default:{let o=r;this.defaults.extensions?.childTokens?.[o.type]?this.defaults.extensions.childTokens[o.type].forEach(i=>{let s=o[i].flat(1/0);n=n.concat(this.walkTokens(s,e))}):o.tokens&&(n=n.concat(this.walkTokens(o.tokens,e)))}}return n}use(...t){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{let r={...n};if(r.async=this.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if("renderer"in o){let i=e.renderers[o.name];i?e.renderers[o.name]=function(...s){let a=o.renderer.apply(this,s);return a===!1&&(a=i.apply(this,s)),a}:e.renderers[o.name]=o.renderer}if("tokenizer"in o){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let i=e[o.level];i?i.unshift(o.tokenizer):e[o.level]=[o.tokenizer],o.start&&(o.level==="block"?e.startBlock?e.startBlock.push(o.start):e.startBlock=[o.start]:o.level==="inline"&&(e.startInline?e.startInline.push(o.start):e.startInline=[o.start]))}"childTokens"in o&&o.childTokens&&(e.childTokens[o.name]=o.childTokens)}),r.extensions=e),n.renderer){let o=this.defaults.renderer||new Ui(this.defaults);for(let i in n.renderer){if(!(i in o))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let s=i,a=n.renderer[s],l=o[s];o[s]=(...c)=>{let u=a.apply(o,c);return u===!1&&(u=l.apply(o,c)),u||""}}r.renderer=o}if(n.tokenizer){let o=this.defaults.tokenizer||new Di(this.defaults);for(let i in n.tokenizer){if(!(i in o))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let s=i,a=n.tokenizer[s],l=o[s];o[s]=(...c)=>{let u=a.apply(o,c);return u===!1&&(u=l.apply(o,c)),u}}r.tokenizer=o}if(n.hooks){let o=this.defaults.hooks||new Tr;for(let i in n.hooks){if(!(i in o))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let s=i,a=n.hooks[s],l=o[s];Tr.passThroughHooks.has(i)?o[s]=c=>{if(this.defaults.async&&Tr.passThroughHooksRespectAsync.has(i))return(async()=>{let m=await a.call(o,c);return l.call(o,m)})();let u=a.call(o,c);return l.call(o,u)}:o[s]=(...c)=>{if(this.defaults.async)return(async()=>{let m=await a.apply(o,c);return m===!1&&(m=await l.apply(o,c)),m})();let u=a.apply(o,c);return u===!1&&(u=l.apply(o,c)),u}}r.hooks=o}if(n.walkTokens){let o=this.defaults.walkTokens,i=n.walkTokens;r.walkTokens=function(s){let a=[];return a.push(i.call(this,s)),o&&(a=a.concat(o.call(this,s))),a}}this.defaults={...this.defaults,...r}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return Qe.lex(t,e??this.defaults)}parser(t,e){return Je.parse(t,e??this.defaults)}parseMarkdown(t){return(e,n)=>{let r={...n},o={...this.defaults,...r},i=this.onError(!!o.silent,!!o.async);if(this.defaults.async===!0&&r.async===!1)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(o.hooks&&(o.hooks.options=o,o.hooks.block=t),o.async)return(async()=>{let s=o.hooks?await o.hooks.preprocess(e):e,a=await(o.hooks?await o.hooks.provideLexer(t):t?Qe.lex:Qe.lexInline)(s,o),l=o.hooks?await o.hooks.processAllTokens(a):a;o.walkTokens&&await Promise.all(this.walkTokens(l,o.walkTokens));let c=await(o.hooks?await o.hooks.provideParser(t):t?Je.parse:Je.parseInline)(l,o);return o.hooks?await o.hooks.postprocess(c):c})().catch(i);try{o.hooks&&(e=o.hooks.preprocess(e));let s=(o.hooks?o.hooks.provideLexer(t):t?Qe.lex:Qe.lexInline)(e,o);o.hooks&&(s=o.hooks.processAllTokens(s)),o.walkTokens&&this.walkTokens(s,o.walkTokens);let a=(o.hooks?o.hooks.provideParser(t):t?Je.parse:Je.parseInline)(s,o);return o.hooks&&(a=o.hooks.postprocess(a)),a}catch(s){return i(s)}}}onError(t,e){return n=>{if(n.message+=`
106
+ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error occurred:</p><pre>"+ut(n.message+"",!0)+"</pre>";return e?Promise.resolve(r):r}if(e)return Promise.reject(n);throw n}}},cn=new ul;function Q(t,e){return cn.parse(t,e)}Q.options=Q.setOptions=function(t){return cn.setOptions(t),Q.defaults=cn.defaults,Gu(Q.defaults),Q};Q.getDefaults=rl;Q.defaults=dn;function Ry(...t){return cn.use(...t),Q.defaults=cn.defaults,Gu(Q.defaults),Q}Q.use=Ry;Q.walkTokens=function(t,e){return cn.walkTokens(t,e)};Q.parseInline=cn.parseInline;Q.Parser=Je;Q.parser=Je.parse;Q.Renderer=Ui;Q.TextRenderer=dl;Q.Lexer=Qe;Q.lexer=Qe.lex;Q.Tokenizer=Di;Q.Hooks=Tr;Q.parse=Q;var X0=Q.options,Y0=Q.setOptions,K0=Q.walkTokens,Z0=Q.parseInline;var Q0=Je.parse,J0=Qe.lex;var Ny=new ul({gfm:!0,breaks:!0}),Zu=["a","p","br","strong","em","b","i","u","s","del","code","pre","ul","ol","li","blockquote","h1","h2","h3","h4","h5","h6","hr","span","table","thead","tbody","tr","th","td"],Qu=["href","title","class","target","rel"],Ju={ALLOWED_TAGS:Zu,ALLOWED_ATTR:Qu,ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!1},Oy={...Ju,ALLOWED_TAGS:[...Zu,"img"],ALLOWED_ATTR:[...Qu,"src","alt","width","height"]},My=/^language-[A-Za-z0-9_+#.-]+$/,Ly=new Set(["CODE","PRE"]);function Py(t){t.nodeName==="A"&&t.hasAttribute("href")?(t.setAttribute("target","_blank"),t.setAttribute("rel","noopener noreferrer")):(t.removeAttribute("target"),t.removeAttribute("rel"));let e=t.getAttribute("class");if(e===null)return;let n=Ly.has(t.nodeName)?e.split(/\s+/).filter(r=>My.test(r)):[];if(n.length===0){t.removeAttribute("class");return}t.setAttribute("class",n.join(" "))}var Fi=null;function Dy(){return Fi===null&&(Fi=Mu(),Fi.addHook("afterSanitizeAttributes",Py)),Fi}function zi(t,e){let n=e?.allowImages===!0,r=Ny.parse(t,{async:!1});return Dy().sanitize(r,n?Oy:Ju).trim()}function ep(t){let e=document.createElement("div");e.className="resize-handle",e.setAttribute("part","resize-handle"),e.setAttribute("role","separator"),e.setAttribute("aria-label",t.label),e.tabIndex=0;let n=(i,s,a,l,c)=>{let u=s.x==="right"?a.right-l:l-a.left,m={width:Math.max(280,u)};if(i!=="both")return m;let y=s.y==="bottom"?a.bottom-c:c-a.top;return{...m,height:Math.max(240,y)}};e.addEventListener("pointerdown",i=>{let s=t.axis();if(s==="none")return;let a=t.anchor(),l=t.rect(),c=m=>{t.apply(n(s,a,l,m.clientX,m.clientY))},u=m=>{window.removeEventListener("pointermove",c),window.removeEventListener("pointerup",u),e.removeAttribute("data-dragging"),t.commit(n(s,a,l,m.clientX,m.clientY))};e.setAttribute("data-dragging","true"),window.addEventListener("pointermove",c),window.addEventListener("pointerup",u),i.preventDefault()});let r=null,o=()=>{if(r===null)return;let i=r;r=null,t.commit(i)};return e.addEventListener("keydown",i=>{let s=t.axis();if(s==="none")return;let a=t.anchor(),l=t.rect(),c=i.shiftKey?64:16,u=a.x==="right"?-1:1,m=l.right-l.left,y=l.bottom-l.top,f=null;if(i.key==="ArrowLeft")f={width:Math.max(280,m-c*u)};else if(i.key==="ArrowRight")f={width:Math.max(280,m+c*u)};else if(s==="both"&&(i.key==="ArrowUp"||i.key==="ArrowDown")){let h=i.key===(a.y==="bottom"?"ArrowUp":"ArrowDown");f={height:Math.max(240,y+(h?c:-c))}}f!==null&&(i.preventDefault(),t.apply(f),r=f)}),e.addEventListener("keyup",o),e.addEventListener("blur",o),e}function tp(t,e){for(let n of Array.from(t.childNodes))n.nodeType===Node.TEXT_NODE?e.push({node:n,parent:t}):tp(n,e)}function np(t){let e=[];tp(t,e);let n=0;for(let{node:r,parent:o}of e){let i=document.createDocumentFragment();for(let s of r.data.split(/(\s+)/)){if(s==="")continue;if(/\s/.test(s)){i.appendChild(document.createTextNode(s));continue}let a=document.createElement("span");a.className="word",a.style.setProperty("--ag-ui-word-index",String(n)),a.textContent=s,i.appendChild(a),n+=1}o.replaceChild(i,r)}}function pl(t,e,n){let r=document.createElement("div");r.className=`run-notice run-notice--${n}`,r.setAttribute("part",`run-notice run-notice-${n}`),r.setAttribute("role","status");let o=document.createElement("span");o.className="run-notice-icon",o.setAttribute("part","run-notice-icon"),o.textContent=t,o.setAttribute("aria-hidden","true");let i=document.createElement("span");return i.className="run-notice-text",i.setAttribute("part","run-notice-text"),i.textContent=e,r.append(o,i),r}var Gi=class{chips;palette;#t;#n=[];#e=!1;#s=!1;#r=[];#i=0;constructor(e){this.#t=e,this.chips=document.createElement("div"),this.chips.className="skill-chips",this.chips.setAttribute("part","skill-chips"),this.chips.hidden=!0,this.palette=document.createElement("div"),this.palette.className="skill-palette",this.palette.setAttribute("part","skill-palette"),this.palette.setAttribute("role","listbox"),this.palette.hidden=!0}setSkills(e){this.#n=e,this.#d()}enableChips(e){this.#e=e,this.#d()}enableSlash(e){this.#s=e}isOpen(){return!this.palette.hidden}onInput(e){this.#s&&e.startsWith("/")?this.#o(e.slice(1)):this.close()}onKeydown(e){return this.isOpen()?e.key==="ArrowDown"?(this.#u(1),!0):e.key==="ArrowUp"?(this.#u(-1),!0):e.key==="Escape"?(this.close(),!0):e.key==="Enter"?(this.#r.slice(this.#i,this.#i+1).forEach(n=>{this.#c(n)}),!0):!1:!1}close(){this.palette.hidden=!0,this.palette.replaceChildren()}#o(e){let n=e.trim().toLowerCase(),r=this.#n.filter(o=>o.name.toLowerCase().includes(n)||o.title.toLowerCase().includes(n));if(r.length===0){this.close();return}this.#r=r,this.#i=0,this.#a(),this.palette.hidden=!1}#u(e){let n=this.#r.length;this.#i=(this.#i+e+n)%n,this.#a()}#c(e){this.close(),this.#t(e)}#d(){this.chips.replaceChildren();let e=this.#e?this.#n.filter(n=>n.chip===!0):[];this.chips.hidden=e.length===0;for(let n of e){let r=document.createElement("button");r.type="button",r.className="skill-chip",r.setAttribute("part","skill-chip"),r.textContent=n.title,r.title=`/${n.name}`,r.addEventListener("click",()=>this.#c(n)),this.chips.appendChild(r)}}#a(){this.palette.replaceChildren(),this.#r.forEach((e,n)=>{let r=document.createElement("button");r.type="button",r.className="skill-item",r.setAttribute("part","skill-item"),r.setAttribute("role","option"),r.setAttribute("aria-selected",n===this.#i?"true":"false");let o=document.createElement("span");o.className="skill-item-title",o.setAttribute("part","skill-item-title");let i=document.createElement("code");if(i.className="skill-item-token",i.setAttribute("part","skill-item-token"),i.textContent=`/${e.name}`,o.append(i,document.createTextNode(` ${e.title}`)),r.appendChild(o),e.description!==void 0){let s=document.createElement("span");s.className="skill-item-desc",s.setAttribute("part","skill-item-desc"),s.textContent=e.description,r.appendChild(s)}r.addEventListener("click",()=>this.#c(e)),this.palette.appendChild(r)})}};function rp({viewport:t,onMissedContent:e}){let n=!0,r=!1,o=()=>t.scrollHeight-t.scrollTop-t.clientHeight<=4,i=u=>{u!==r&&(r=u,e(r))},s=()=>{t.scrollTop=t.scrollHeight},a=()=>{n=o(),n&&i(!1)},l=()=>{if(n){s();return}i(!0)};t.addEventListener("scroll",a,{passive:!0});let c=new ResizeObserver(()=>{n&&s()});return c.observe(t),{follow:l,jump:()=>{n=!0,i(!1),s()},following:()=>n,dispose:()=>{t.removeEventListener("scroll",a),c.disconnect()}}}var op=`
107
107
  /* \u2500\u2500 Token defaults \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
108
108
  Every public --ag-ui-* token is read here into a private --_* alias, and
109
109
  only the alias is used by the rules below.
@@ -1296,6 +1296,21 @@ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error
1296
1296
  color: var(--_fg);
1297
1297
  }
1298
1298
 
1299
+ /* A region a host formatter took over, marked by the card. Preformatted
1300
+ whitespace is what makes the built-in block read as written, and it is the one
1301
+ thing a host cannot want: a table inherits it as mangled cell spacing, and a
1302
+ sentence as line breaks nobody typed.
1303
+
1304
+ Whitespace only. The card's own face, frame, padding and scroll cap stay,
1305
+ because the card is one visual object -- the head row and the status pill are
1306
+ monospaced too -- and a region that dropped the family would be the only part
1307
+ of it wearing a different one. A host that wants that restyles the
1308
+ tool-card-result part, which does not need the formatter at all. */
1309
+ .tool-call-args[data-formatted],
1310
+ .tool-call-result[data-formatted] {
1311
+ white-space: normal;
1312
+ }
1313
+
1299
1314
  /* Display modes are pure visibility over one DOM shape, selected from the host
1300
1315
  attribute rather than a value stamped on the card at build time, so flipping
1301
1316
  data-tool-display re-styles cards already on screen. See ToolCallCard.
@@ -1360,6 +1375,174 @@ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error
1360
1375
  display: flex;
1361
1376
  }
1362
1377
 
1378
+ /* A delegated sub-agent's progress, inside the card that delegated. Empty on
1379
+ every card that delegated nothing, so it collapses rather than adding a gap
1380
+ to each one -- the same shape the approval slot uses. */
1381
+ .tool-call-subagent:empty {
1382
+ display: none;
1383
+ }
1384
+
1385
+ .tool-call-subagent {
1386
+ display: flex;
1387
+ flex-direction: column;
1388
+ gap: 4px;
1389
+ }
1390
+
1391
+ .subagent {
1392
+ display: flex;
1393
+ flex-direction: column;
1394
+ gap: 4px;
1395
+ min-width: 0;
1396
+ }
1397
+
1398
+ /* The collapsed row is the status and the expander at once, which is what keeps
1399
+ a ten-step child one row until somebody opens it. Full width and left-aligned,
1400
+ because it is a line of the card rather than a button on it. */
1401
+ .subagent-row {
1402
+ display: flex;
1403
+ align-items: center;
1404
+ gap: 6px;
1405
+ width: 100%;
1406
+ box-sizing: border-box;
1407
+ padding: 2px 0;
1408
+ border: none;
1409
+ background: none;
1410
+ font: inherit;
1411
+ text-align: left;
1412
+ color: var(--_muted);
1413
+ cursor: pointer;
1414
+ }
1415
+
1416
+ /* Nothing behind the row yet -- a delegation that failed before calling
1417
+ anything. Drop the affordances rather than offer a control that expands onto
1418
+ an empty region, which is the refusal the card's own toggle already makes. */
1419
+ .subagent-row:disabled {
1420
+ cursor: default;
1421
+ }
1422
+
1423
+ .subagent-row::after {
1424
+ content: "\u25B8";
1425
+ flex: none;
1426
+ margin-left: auto;
1427
+ color: var(--_accent);
1428
+ }
1429
+
1430
+ .subagent-row[aria-expanded="true"]::after {
1431
+ content: "\u25BE";
1432
+ }
1433
+
1434
+ .subagent-row:disabled::after {
1435
+ display: none;
1436
+ }
1437
+
1438
+ /* Empty in the DOM; the glyph is drawn here from the panel's data-phase, so a
1439
+ host re-themes it through the same tool-icon custom properties the card uses. */
1440
+ .subagent-icon {
1441
+ flex: none;
1442
+ box-sizing: border-box;
1443
+ display: inline-flex;
1444
+ align-items: center;
1445
+ justify-content: center;
1446
+ width: 10px;
1447
+ height: 10px;
1448
+ font-size: 10px;
1449
+ line-height: 1;
1450
+ }
1451
+
1452
+ /* Anything that is not a terminal phase is the child still working. Selected by
1453
+ what it is not, so a phase this client has not heard of still spins rather
1454
+ than rendering as a blank. */
1455
+ .subagent[data-phase]:not([data-phase="finished"]):not([data-phase="failed"]) .subagent-icon {
1456
+ border: 2px solid var(--_muted);
1457
+ border-top-color: transparent;
1458
+ border-radius: 50%;
1459
+ animation: ag-ui-tool-spin var(--_tool-spin-duration) linear infinite;
1460
+ }
1461
+
1462
+ .subagent[data-phase="finished"] .subagent-icon::before {
1463
+ content: var(--_tool-icon-done);
1464
+ color: var(--_success);
1465
+ }
1466
+
1467
+ .subagent[data-phase="failed"] .subagent-icon::before {
1468
+ content: var(--_tool-icon-error);
1469
+ color: var(--_danger);
1470
+ }
1471
+
1472
+ @media (prefers-reduced-motion: reduce) {
1473
+ .subagent .subagent-icon {
1474
+ animation: none;
1475
+ }
1476
+ }
1477
+
1478
+ /* The server's own pre-rendered line. Shrinks and wraps rather than pushing the
1479
+ chevron out of the card, which is what a fixed-width sibling in a flex row
1480
+ does to a panel at sidebar width. */
1481
+ .subagent-status {
1482
+ flex: 1 1 auto;
1483
+ min-width: 0;
1484
+ overflow-wrap: anywhere;
1485
+ }
1486
+
1487
+ /* The child's own calls. Indented and ruled, so the nesting is visible without
1488
+ a second card frame around it. */
1489
+ .subagent-steps {
1490
+ display: flex;
1491
+ flex-direction: column;
1492
+ gap: 2px;
1493
+ margin-left: 4px;
1494
+ padding-left: 10px;
1495
+ border-left: 1px solid var(--_border);
1496
+ }
1497
+
1498
+ .subagent-steps[hidden] {
1499
+ display: none;
1500
+ }
1501
+
1502
+ .subagent-step {
1503
+ display: flex;
1504
+ align-items: center;
1505
+ gap: 6px;
1506
+ min-width: 0;
1507
+ color: var(--_muted);
1508
+ }
1509
+
1510
+ .subagent-step-icon {
1511
+ flex: none;
1512
+ box-sizing: border-box;
1513
+ display: inline-flex;
1514
+ align-items: center;
1515
+ justify-content: center;
1516
+ width: 8px;
1517
+ height: 8px;
1518
+ font-size: 9px;
1519
+ line-height: 1;
1520
+ }
1521
+
1522
+ /* No outcome yet: the wire says null while the call is in flight, and the
1523
+ absence of the attribute is how that arrives here. A hollow ring, not a
1524
+ spinner -- several can be on screen at once and the row above already spins. */
1525
+ .subagent-step:not([data-ok]) .subagent-step-icon {
1526
+ border: 1px solid var(--_muted);
1527
+ border-radius: 50%;
1528
+ }
1529
+
1530
+ .subagent-step[data-ok="true"] .subagent-step-icon::before {
1531
+ content: var(--_tool-icon-done);
1532
+ color: var(--_success);
1533
+ }
1534
+
1535
+ .subagent-step[data-ok="false"] .subagent-step-icon::before {
1536
+ content: var(--_tool-icon-error);
1537
+ color: var(--_danger);
1538
+ }
1539
+
1540
+ .subagent-step-name {
1541
+ flex: 1 1 auto;
1542
+ min-width: 0;
1543
+ overflow-wrap: anywhere;
1544
+ }
1545
+
1363
1546
  .tool-call-toggle {
1364
1547
  align-self: flex-start;
1365
1548
  border: none;
@@ -2657,9 +2840,9 @@ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error
2657
2840
  border-right: none;
2658
2841
  box-shadow: none;
2659
2842
  }
2660
- `;var Ry=4,Ny=120;function ep(t){if(typeof t!="object"||t===null)return null;let e=t.prompts;if(!Array.isArray(e))return null;let n=e.filter(r=>typeof r=="string").map(r=>r.trim()).filter(r=>r!==""&&r.length<=120).slice(0,4);return n.length===0?null:n}function dl(t,e,n){let r=ep(t);if(r===null)return null;let o=document.createElement("div");o.className="suggestions",o.setAttribute("part","suggestions"),o.setAttribute("role","group"),o.setAttribute("aria-label",e.suggestions);for(let i of r){let s=document.createElement("button");s.type="button",s.className="suggestion-chip",s.setAttribute("part","suggestion-chip"),s.textContent=i,s.addEventListener("click",()=>n(i)),o.appendChild(s)}return o}var zi=class{element;#t;#r;#e;#s;#n=!1;constructor(e=le){this.#s=e,this.element=document.createElement("div"),this.element.className="thoughts",this.element.setAttribute("part","thoughts"),this.element.setAttribute("data-streaming",""),this.#e=document.createElement("button"),this.#e.type="button",this.#e.className="thoughts-toggle",this.#e.setAttribute("part","thoughts-toggle"),this.#e.setAttribute("aria-expanded","true"),this.#t=document.createElement("span"),this.#t.className="thoughts-label",this.#t.setAttribute("part","thoughts-label"),this.#t.textContent=e.thinking,this.#e.append(this.#t),this.#r=document.createElement("pre"),this.#r.className="thoughts-body",this.#r.setAttribute("part","thoughts-body"),this.#e.addEventListener("click",()=>{this.#i(!this.#n)}),this.element.append(this.#e,this.#r)}stream(e){this.#r.textContent=e}collapse(){this.#n||(this.element.removeAttribute("data-streaming"),this.#t.textContent=this.#s.thoughts,this.#i(!0))}#i(e){this.#n=e,this.#r.hidden=e,this.#e.setAttribute("aria-expanded",String(!e))}};var Fi=class{element;#t;#r;#e;#s;#n;#i=null;#o;#c=[];#d="";#a=null;constructor(e,n=le){this.#t=e,this.#o=n,this.element=document.createElement("div"),this.element.className="drawer",this.element.setAttribute("part","drawer"),this.element.hidden=!0;let r=document.createElement("div");r.className="drawer-backdrop",r.setAttribute("part","drawer-backdrop"),r.addEventListener("click",()=>this.close()),this.#r=document.createElement("div"),this.#r.className="drawer-panel",this.#r.setAttribute("part","drawer-panel"),this.#r.setAttribute("role","dialog"),this.#r.setAttribute("aria-modal","true"),this.#r.setAttribute("aria-label",n.chatHistory),this.#r.addEventListener("keydown",i=>this.#S(i));let o=document.createElement("div");o.className="drawer-header",o.setAttribute("part","drawer-header"),this.#e=document.createElement("span"),this.#e.className="drawer-title",this.#e.setAttribute("part","drawer-title"),this.#e.textContent=n.chats,this.#s=document.createElement("button"),this.#s.type="button",this.#s.className="drawer-new",this.#s.setAttribute("part","drawer-new"),this.#s.textContent=n.newChat,this.#s.addEventListener("click",()=>{this.close(),this.#t.onNew()}),o.append(this.#e,this.#s),this.#n=document.createElement("div"),this.#n.className="drawer-list",this.#n.setAttribute("part","drawer-list"),this.#r.append(o,this.#n),this.element.append(r,this.#r)}setRelativeTimeFormatter(e){this.#i=e}#u(e){return this.#i!==null?this.#i(e):mr(e,void 0,this.#o)}setStrings(e){this.#o=e,this.#r.setAttribute("aria-label",e.chatHistory),this.#e.textContent=e.chats,this.#s.textContent=e.newChat,this.#m()}isOpen(){return!this.element.hidden}open(){this.isOpen()||(this.#a=this.#p(),this.element.hidden=!1,this.#s.focus())}close(){this.isOpen()&&(this.element.hidden=!0,this.#a?.focus(),this.#a=null)}toggle(){this.isOpen()?this.close():this.open()}#p(){return this.element.getRootNode().activeElement}#S(e){if(e.key==="Escape"){e.preventDefault(),this.close();return}if(e.key!=="Tab")return;let n=Array.from(this.#r.querySelectorAll("button, input, [tabindex]")).filter(s=>!s.hidden),r=n[0],o=n[n.length-1],i=this.#p();e.shiftKey&&i===r?(e.preventDefault(),o?.focus()):!e.shiftKey&&i===o&&(e.preventDefault(),r?.focus())}setThreads(e,n){this.#c=e,this.#d=n,this.#m()}#m(){if(this.#n.replaceChildren(),this.#c.length===0){let e=document.createElement("div");e.className="drawer-empty",e.setAttribute("part","drawer-empty"),e.textContent=this.#o.noConversations,this.#n.appendChild(e);return}for(let e of this.#c)this.#n.appendChild(this.#_(e))}#_(e){let n=document.createElement("div");n.className="drawer-row",n.setAttribute("part","drawer-row"),e.threadId===this.#d&&n.classList.add("drawer-row--active");let r=document.createElement("button");r.type="button",r.className="drawer-row-select",r.setAttribute("part","drawer-row-select");let o=document.createElement("span");o.className="drawer-row-title",o.setAttribute("part","drawer-row-title"),o.textContent=e.title;let i=document.createElement("span");i.className="drawer-row-time",i.setAttribute("part","drawer-row-time"),i.textContent=this.#u(e.updatedAt);let s=document.createElement("span");s.className="drawer-row-preview",s.setAttribute("part","drawer-row-preview"),s.textContent=e.preview,r.append(o,i,s),r.addEventListener("click",()=>{this.close(),this.#t.onSelect(e.threadId)});let a=document.createElement("button");a.type="button",a.className="drawer-row-rename",a.setAttribute("part","drawer-row-rename"),a.title=this.#o.rename,a.setAttribute("aria-label",this.#o.renameConversation),a.textContent="\u270E",a.addEventListener("click",()=>this.#M(n,e));let l=document.createElement("button");l.type="button",l.className="drawer-row-delete",l.setAttribute("part","drawer-row-delete"),l.title=this.#o.delete,l.setAttribute("aria-label",this.#o.deleteConversation),l.textContent="\u{1F5D1}",l.addEventListener("click",()=>this.#g(n,e));let c=document.createElement("div");return c.className="drawer-row-actions",c.setAttribute("part","drawer-row-actions"),c.append(a,l),n.append(r,c),n}#M(e,n){let r=document.createElement("input");r.type="text",r.className="drawer-rename-input",r.setAttribute("part","drawer-rename-input"),r.value=n.title;let o=!1,i=()=>{if(o)return;o=!0;let a=r.value.trim();a===""||a===n.title?this.#m():this.#t.onRename(n.threadId,a)},s=()=>{o||(o=!0,this.#m())};r.addEventListener("keydown",a=>{a.key==="Enter"?(a.preventDefault(),i()):a.key==="Escape"&&(a.preventDefault(),a.stopPropagation(),s())}),r.addEventListener("blur",()=>i()),e.replaceChildren(r),r.focus(),r.select()}#g(e,n){let r=document.createElement("div");r.className="drawer-confirm",r.setAttribute("part","drawer-confirm");let o=document.createElement("span");o.className="drawer-confirm-label",o.setAttribute("part","drawer-confirm-label"),o.textContent=this.#o.deletePrompt;let i=document.createElement("button");i.type="button",i.className="drawer-confirm-yes",i.setAttribute("part","drawer-confirm-yes"),i.textContent=this.#o.delete,i.addEventListener("click",()=>this.#t.onDelete(n.threadId));let s=document.createElement("button");s.type="button",s.className="drawer-confirm-no",s.setAttribute("part","drawer-confirm-no"),s.textContent=this.#o.cancel,s.addEventListener("click",()=>this.#m()),r.append(o,i,s),e.replaceChildren(r)}};function ul(t){return{[ee.PENDING]:t.toolRunning,[ee.DEFERRED]:t.toolDeferred,[ee.DONE]:t.toolDone,[ee.ERROR]:t.toolError,[ee.DECLINED]:t.toolDeclined}}function Oy(t){return{[ee.DONE]:t.resultLabel,[ee.ERROR]:t.errorLabel,[ee.DECLINED]:t.declinedLabel}}function My(t){try{return JSON.stringify(JSON.parse(t),null,2)}catch{return t}}var Sr=class{element;approvalSlot;#t;#r;#e;#s;#n;#i;#o;args;#c=!1;constructor(e,n,r,o=le){this.#o=o,this.args=n,this.element=document.createElement("div"),this.element.className="tool-call",this.element.setAttribute("part","tool-card"),this.element.setAttribute("data-tool-name",e),this.element.setAttribute("data-status",ee.PENDING),this.element.setAttribute("data-expanded","false");let i=document.createElement("div");i.className="tool-call-head",i.setAttribute("part","tool-card-head");let s=document.createElement("span");s.className="tool-call-icon",s.setAttribute("part","tool-card-icon"),s.setAttribute("aria-hidden","true");let a=document.createElement("span");a.className="tool-call-name",a.setAttribute("part","tool-card-name"),a.textContent=r??e,this.#t=document.createElement("span"),this.#t.className="tool-call-status",this.#t.setAttribute("part","tool-card-status"),this.#t.textContent=ul(o)[ee.PENDING],this.#r=document.createElement("span"),this.#r.className="tool-call-decision",this.#r.setAttribute("part","tool-card-decision"),this.#r.hidden=!0,i.append(s,a,this.#t,this.#r);let l=this.#d("args",o.argumentsLabel);l.body.textContent=JSON.stringify(n,null,2),l.root.hidden=Object.keys(n).length===0;let c=this.#d("result",o.resultLabel);this.#s=c.root,this.#n=c.label,this.#i=c.body,c.root.hidden=!0,this.#e=document.createElement("button"),this.#e.type="button",this.#e.className="tool-call-toggle",this.#e.setAttribute("part","tool-card-toggle"),this.#e.setAttribute("aria-expanded","false"),this.#e.textContent=o.details,this.#e.addEventListener("click",()=>this.#u(!this.#a()));let u=document.createElement("div");u.className="tool-call-body",u.setAttribute("part","tool-card-body"),u.append(l.root,c.root),this.approvalSlot=document.createElement("div"),this.approvalSlot.className="tool-call-approval",this.approvalSlot.setAttribute("part","tool-card-approval"),this.element.append(i,this.#e,u,this.approvalSlot)}mark(e){this.#c||(this.element.setAttribute("data-status",e),this.#t.textContent=ul(this.#o)[e])}recordDecision(e){this.element.setAttribute("data-decision",e),this.#r.textContent=e==="approved"?this.#o.decisionApproved:this.#o.decisionDeclined,this.#r.hidden=!1}get settled(){return this.#c}settle(e,n){this.#c||(this.#c=!0,this.element.setAttribute("data-status",e),this.#t.textContent=ul(this.#o)[e],this.#n.textContent=Oy(this.#o)[e],this.#i.textContent=My(n),this.#s.hidden=!1)}#d(e,n){let r=document.createElement("div");r.className=`tool-call-section tool-call-section--${e}`,r.setAttribute("part",`tool-card-section tool-card-${e}-section`);let o=document.createElement("span");o.className="tool-call-section-label",o.setAttribute("part",`tool-card-section-label tool-card-${e}-label`),o.textContent=n;let i=document.createElement("pre");return i.className=`tool-call-${e}`,i.setAttribute("part",`tool-card-${e}`),r.append(o,i),{root:r,label:o,body:i}}#a(){return this.element.getAttribute("data-expanded")==="true"}#u(e){this.element.setAttribute("data-expanded",String(e)),this.#e.setAttribute("aria-expanded",String(e))}};var tp=12e4,Gi=class{element;#t;#r;#e;#s="idle";#n=null;#i=null;#o=[];#c=null;#d=!1;#a=!1;constructor(e){this.#t=e.transcribe,this.#r=e.onText,this.#e=e.strings??le,this.element=document.createElement("button"),this.element.type="button",this.element.className="voice-btn",this.element.setAttribute("part","voice-button");let n=document.createElement("slot");n.name="icon-voice",n.innerHTML=Zl,this.element.append(n),this.#g("idle"),this.element.addEventListener("click",()=>{this.toggle()})}async toggle(){if(this.#s==="recording"){this.#p();return}this.#s!=="transcribing"&&await this.#u()}async#u(){let e;try{e=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{this.#M(this.#e.transcriptionFailed);return}this.#i=e,this.#o=[],this.#d=!1;let n=new MediaRecorder(e);n.addEventListener("dataavailable",r=>{this.#o.push(r.data)}),n.addEventListener("stop",()=>{this.#m(n.mimeType)}),this.#n=n,n.start(),this.#c=setTimeout(()=>{this.#d=!0,this.#p()},tp),this.#g("recording")}#p(){this.#S(),this.#n?.stop()}#S(){this.#c!==null&&(clearTimeout(this.#c),this.#c=null)}dispose(){this.#a=!0,this.#S(),this.#n!==null&&this.#n.state!=="inactive"&&this.#n.stop(),this.#n=null,this.#_()}async#m(e){if(this.#a)return;this.#_(),this.#g("transcribing");let n=new Blob(this.#o,{type:e||"audio/webm"});try{let r=await this.#t(n);this.#g("idle"),this.#d&&(this.element.title=this.#e.recordingLimit.replace("{n}",String(tp/6e4))),r!==""&&this.#r(r)}catch(r){this.#M(r instanceof Error?r.message:this.#e.transcriptionFailed)}finally{this.#n=null}}#_(){for(let e of this.#i?.getTracks()??[])e.stop();this.#i=null}#M(e){this.#_(),this.#n=null,this.#g("idle"),this.element.title=e}#g(e){this.#s=e,this.element.dataset.state=e;let n=this.#L(e);this.element.title=n,this.element.setAttribute("aria-label",n),this.element.setAttribute("aria-pressed",String(e==="recording")),this.element.disabled=e==="transcribing"}#L(e){return e==="recording"?this.#e.stopRecording:e==="transcribing"?this.#e.transcribing:this.#e.recordVoice}};var $i=class extends Error{constructor(e){super(e),this.name="ConnectionLostError"}},Gn=class{#t;#r;#e;#s;#n;#i;#o;#c=new Set;#d;#a=!1;constructor(e){this.#t=e.agent,this.#r=e.handlers,this.#e=e.getTools??(()=>[]),this.#s=e.getContext??(()=>[]),this.#n=e.executeTool??null,this.#i=e.resolveInterrupts??null,this.#o=e.onPersist??(()=>{}),this.#d=e.connectionLostMessage??"Connection lost";let n=e.onStateChanged;n!==void 0&&this.#t.subscribe({onStateChanged:({state:r})=>{n(r)}})}get state(){return this.#t.state}setState(e){this.#t.setState({...e})}get running(){return this.#t.isRunning}get messages(){return this.#t.messages}async send(e,n=[]){let r={id:_e(),role:"user",content:e};n.length>0&&(r.attachments=n),this.#t.addMessage(r),this.#o(this.#t.messages),await this.#u()}truncateToLastUser(){let e=[...this.#t.messages],n=-1;for(let[o,i]of e.entries())i.role==="user"&&(n=o);if(n===-1)return null;let r=e.slice(0,n+1);return this.#t.setMessages(r),this.#o(this.#t.messages),r}async resume(){await this.#u()}addToolResult(e,n){this.#t.addMessage({id:_e(),role:"tool",content:n,toolCallId:e}),this.#o(this.#t.messages)}cancel(){this.#a=!0,this.#t.abortRun()}async#u(){this.#a=!1;try{await this.#S(),this.#a&&this.#p()}catch(e){this.#a||Ly(e)?this.#p():this.#r.onError(e instanceof Error?e.message:String(e))}finally{this.#r.onSettled()}}#p(){this.#o(this.#t.messages),this.#r.onCancelled()}async#S(){let e;for(let n=0;n<Ts;n+=1){if(this.#a)return;let r=[],o={terminal:!1,errored:!1,interrupts:[]},i={tools:this.#e(),context:this.#s()};if(e!==void 0&&(i.resume=e),await this.#t.runAgent(i,this.#m(r,o)),e=void 0,this.#o(this.#t.messages),this.#a)return;if(!o.terminal)throw new $i(this.#d);if(o.errored)return;if(o.interrupts.length>0){if(this.#i===null)return;let a=await this.#i(o.interrupts);if(this.#a)return;e=Xd(o.interrupts,a);continue}if(this.#n===null||r.length===0)return;let s=!1;for(let a of r){let l=await this.#n(a);if(l!==null){if(l.halt===!0)return;this.#t.addMessage({id:_e(),role:"tool",content:l.content,toolCallId:a.id}),this.#o(this.#t.messages),s=!0}}if(!s)return}}#m(e,n){let r=this.#r,o=this.#c,i=()=>this.#a,s=new Set;return{onRunInitialized(){r.onRunStart()},onTextMessageStartEvent({event:a}){o.has(a.messageId)&&console.warn(`<ag-ui-chat>: the server reused message id "${a.messageId}", which was already closed. Its content will be appended to that earlier message rather than starting a new one, and the merged result is what gets persisted. Issue a fresh id per message.`)},onTextMessageContentEvent({textMessageBuffer:a}){r.onTextDelta(a)},onTextMessageEndEvent({event:a,textMessageBuffer:l}){o.add(a.messageId),r.onTextEnd(l)},onToolCallEndEvent({event:a,toolCallName:l,toolCallArgs:c}){let u={id:a.toolCallId,name:l,args:c};e.push(u),r.onToolCall(u)},onToolCallResultEvent({event:a}){r.onToolResult(a.toolCallId,a.content)},onActivitySnapshotEvent({event:a,messages:l}){if(l.some(u=>u.id===a.messageId&&u.role==="activity")){r.onActivityChanged(a.messageId,a.activityType,a.content);return}r.onActivity(a.activityType,a.content,a.messageId)},onActivityDeltaEvent({event:a}){s.add(a.messageId)},onCustomEvent({event:a}){r.onCustomEvent(a.name,a.value)},onMessagesSnapshotEvent({event:a}){r.onMessagesSnapshot(a.messages)},onMessagesChanged({messages:a}){if(s.size!==0){for(let l of s){let c=a.find(u=>u.id===l);c!==void 0&&c.role==="activity"&&r.onActivityChanged(l,c.activityType,c.content)}s.clear()}},onReasoningStartEvent(){r.onReasoningStart()},onReasoningMessageContentEvent({reasoningMessageBuffer:a}){r.onReasoningDelta(a)},onReasoningMessageEndEvent({reasoningMessageBuffer:a}){r.onReasoningDelta(a)},onReasoningEndEvent(){r.onReasoningEnd()},onRunFinishedEvent(a){n.terminal=!0,a.outcome==="interrupt"&&(n.interrupts=a.interrupts)},onRunErrorEvent({event:a}){n.terminal=!0,n.errored=!0,!i()&&r.onError(a.message)},onRunFinalized(){n.terminal=!0,r.onRunEnd()}}}};function Ly(t){return t instanceof Error?t.name==="AbortError"||t instanceof TypeError&&/abort/i.test(t.message):!1}function pl(t){let e=t.attachments;return Array.isArray(e)?e.filter(Py):[]}function Py(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.id=="string"&&typeof e.name=="string"&&typeof e.mime=="string"&&typeof e.size=="number"&&(e.url===void 0||typeof e.url=="string")}var np="ag-ui-chat",$n="thread",hl="threads",Ar="messages:",Vi="checkpoint:",kr="minted:",Dy=60,Uy=100,Hy="New conversation",rp=!1;function et(t,e){try{sessionStorage.setItem(t,e)}catch{if(rp)return;rp=!0,console.warn("<ag-ui-chat>: the browser refused a sessionStorage write \u2014 the quota is full, or storage is disabled for this context. The conversation continues, but it will not survive a page reload. Deleting a long conversation from the history drawer frees the quota.")}}function Bi(t){return t===""?np:`${np}@${t}`}var je=class t{#t;constructor(e=""){this.#t=Bi(e),e!==""&&t.adopt("",e)}static adopt(e,n){let r=`${Bi(e)}:`,o=`${Bi(n)}:`;for(let[i,s]of op(r)){let a=sessionStorage.getItem(i),l=o+s;a!==null&&sessionStorage.getItem(l)===null&&et(l,a),sessionStorage.removeItem(i)}}static purge(e){for(let[n]of op(`${Bi(e)}:`))sessionStorage.removeItem(n)}threadId(){return sessionStorage.getItem(this.#n($n))??this.newThread()}newThread(){let e=_e();return et(this.#n($n),e),et(this.#n(kr+e),"1"),e}isUnsent(e){return sessionStorage.getItem(this.#n(kr+e))!==null&&sessionStorage.getItem(this.#n(Ar+e))===null}loadMessages(e){return Promise.resolve(this.#i(this.#n(Ar+e)))}saveMessages(e,n){et(this.#n(Ar+e),JSON.stringify(n)),sessionStorage.removeItem(this.#n(kr+e)),this.#r(e,n)}loadCheckpoint(e){return this.#i(this.#n(Vi+e))}saveCheckpoint(e,n){let r=this.#n(Vi+e);if(n===null){sessionStorage.removeItem(r);return}et(r,JSON.stringify(n))}clear(e){sessionStorage.removeItem(this.#n(Ar+e)),sessionStorage.removeItem(this.#n(Vi+e)),sessionStorage.removeItem(this.#n(kr+e)),this.#s(this.#e().filter(n=>n.threadId!==e)),sessionStorage.getItem(this.#n($n))===e&&sessionStorage.removeItem(this.#n($n))}listThreads(){let e=this.#e().sort((n,r)=>r.updatedAt-n.updatedAt).map(({threadId:n,title:r,updatedAt:o,preview:i})=>({threadId:n,title:r,updatedAt:o,preview:i}));return Promise.resolve(e)}setActiveThread(e){et(this.#n($n),e)}renameThread(e,n){let r=this.#e(),o=r.find(i=>i.threadId===e);o!==void 0&&(o.title=n,o.titleCustom=!0,this.#s(r))}#r(e,n){let r=this.#e(),o=r.find(a=>a.threadId===e),i=Fy(n),s=Date.now();o===void 0?r.push({threadId:e,title:ip(n),titleCustom:!1,preview:i,updatedAt:s}):(o.preview=i,o.updatedAt=s,o.titleCustom||(o.title=ip(n))),this.#s(r)}#e(){return this.#i(this.#n(hl))??[]}#s(e){let n=this.#n(hl);if(e.length===0){sessionStorage.removeItem(n);return}et(n,JSON.stringify(e))}#n(e){return`${this.#t}:${e}`}#i(e){let n=sessionStorage.getItem(e);if(n===null)return null;try{return JSON.parse(n)}catch{return null}}};function op(t){let e=[];for(let n=0;n<sessionStorage.length;n+=1){let r=sessionStorage.key(n);if(r===null||!r.startsWith(t))continue;let o=r.slice(t.length);zy(o)&&e.push([r,o])}return e}function zy(t){return t===$n||t===hl||t.startsWith(Ar)||t.startsWith(Vi)||t.startsWith(kr)}function ip(t){for(let e of t)if(e.role==="user"){let n=sp(e.content);if(n!=="")return ap(n,Dy)}return Hy}function Fy(t){for(let e of[...t].reverse()){let n=sp(e.content);if(n!=="")return ap(n,Uy)}return""}function sp(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():""}function ap(t,e){return t.length<=e?t:`${t.slice(0,e-1).trimEnd()}\u2026`}function qe(t,e){return e===void 0?t:{...t,credentials:e}}function ji(t){if(t.newThread!==void 0)return t.newThread();let e=_e();return t.setActiveThread(e),e}function qi(t,e,n,r){if(e.length===0)return;let o=new URL(String(t),location.href).origin;o===location.origin||n.includes(o)||r.has(o)||(r.add(o),console.warn(`<ag-ui-chat>: sending host credentials (${e.join(", ")}) to ${o}, which is not this page's origin (${location.origin}). Those headers are the page's own authentication, and whichever server answers the browser's preflight receives them \u2014 so a URL attribute built from a query parameter or from tenant-authored configuration is a channel for the token to leave on. If this destination is deliberate, name it in \`trustedOrigins\` to confirm it and silence this notice. Reported once per origin.`))}function fl(t){let e=t.headers??{},n=new Set;return new Kd({url:t.endpoint,headers:e,initialState:{...t.initialState??{}},fetch:(r,o)=>{let i=t.getHeaders?.(),s=[...new Set([...Object.keys(e),...Object.keys(i??{})])].sort();if(qi(r,s,t.trustedOrigins??[],n),i===void 0)return fetch(r,qe(o,t.credentials));let a=new Headers(o?.headers);for(let[l,c]of Object.entries(i))a.set(l,c);return fetch(r,qe({...o,headers:a},t.credentials))},...t.threadId!==void 0?{threadId:t.threadId}:{},...t.initialMessages!==void 0?{initialMessages:[...t.initialMessages]}:{}})}var Cr=class{#t;#r;#e;#s;#n;#i=new Set;#o=new Map;constructor(e,n=()=>({}),r=new je,o=()=>{},i=!0){this.#t=e.endsWith("/")?e:`${e}/`,this.#r=n,this.#e=r,this.#s=o,this.#n=i}threadId(){return this.#e.threadId()}setActiveThread(e){this.#e.setActiveThread(e)}newThread(){return ji(this.#e)}isUnsent(e){return this.#e.isUnsent?.(e)===!0}saveMessages(e,n){this.#e.saveMessages(e,this.#n?n:[])}loadCheckpoint(e){return this.#e.loadCheckpoint(e)}saveCheckpoint(e,n){this.#e.saveCheckpoint(e,n)}renameThread(e,n){this.#e.renameThread(e,n),this.#o.set(e,n),this.#p(e,"PATCH",{title:n})}clear(e){this.#e.clear(e),this.#i.add(e),this.#p(e,"DELETE")}async listThreads(){let e=await this.#c();return e===null?this.#e.listThreads():e.filter(n=>!this.#i.has(n.thread_id)).map(n=>this.#a(n))}async loadMessages(e){if(this.#e.isUnsent?.(e)===!0)return null;let n=await this.#u(`${this.#t}${encodeURIComponent(e)}/`);if(n===null||!n.ok)return this.#e.loadMessages(e);let r=await this.#d(n);return r===null?this.#e.loadMessages(e):r.messages??null}async#c(){let e=await this.#u(this.#t);if(e===null||!e.ok)return null;let n=await this.#d(e);return n===null?null:n.threads??[]}async#d(e){try{return await e.json()}catch{return null}}#a(e){return{threadId:e.thread_id,title:this.#o.get(e.thread_id)??e.title,updatedAt:e.updated_at===null?Number.NaN:Date.parse(e.updated_at),preview:e.preview}}async#u(e){try{return await fetch(e,qe({headers:this.#r()},this.#s()))}catch{return null}}async#p(e,n,r){let o=this.#r();try{await fetch(`${this.#t}${encodeURIComponent(e)}/`,qe({method:n,headers:r===void 0?o:{...o,"content-type":"application/json"},body:r===void 0?null:JSON.stringify(r)},this.#s()))}catch{}}};var Ir=class{#t;#r;#e;constructor(e,n=()=>({}),r=()=>{}){this.#t=e.endsWith("/")?e:`${e}/`,this.#r=n,this.#e=r}async list(){try{let e=await fetch(this.#t,qe({method:"GET",headers:{Accept:"application/json",...this.#r()}},this.#e()));return e.ok?(await e.json()).runs??[]:[]}catch{return[]}}async continuable(){return(await this.list()).filter(e=>e.continuable)}resumeUrl(e){return this.#s("resume",e)}forkUrl(e){return this.#s("fork",e)}#s(e,n){return`${this.#t.slice(0,-5)}${e}/${encodeURIComponent(n)}/`}};async function ml(t,e){let n=new FormData;n.append("audio",t,"recording.webm");let r=await fetch(e.url,qe({method:"POST",headers:{...e.headers??{}},body:n},e.credentials));if(!r.ok)throw new Error(await Gy(r));let o=await r.json();if(typeof o=="object"&&o!==null&&typeof o.text=="string")return o.text;throw new Error("transcription returned an unreadable response")}async function Gy(t){try{let e=await t.json();if(typeof e.error=="string")return e.error}catch{}return`transcription failed (${t.status})`}function gl(t,e){return new Promise((n,r)=>{let o=new FormData;o.append("file",t);let i=new XMLHttpRequest;i.open("POST",e.url),i.withCredentials=e.credentials==="include";for(let[l,c]of Object.entries(e.headers??{}))i.setRequestHeader(l,c);let s=e.onProgress;s!==void 0&&i.upload.addEventListener("progress",l=>{l.lengthComputable&&s(l.total===0?0:l.loaded/l.total)}),i.addEventListener("load",()=>{if(i.status>=200&&i.status<300)try{n($y(JSON.parse(i.responseText)))}catch{r(new Error("upload returned an unreadable response"))}else r(new Error(By(i)))}),i.addEventListener("error",()=>r(new Error("upload failed"))),i.addEventListener("abort",()=>r(new Error("upload cancelled")));let a=e.signal;a!==void 0&&a.addEventListener("abort",()=>i.abort()),i.send(o)})}function $y(t){if(typeof t!="object"||t===null)throw new Error("not an object");let e=t,n=e.id,r=e.name,o=e.mime,i=e.size,s=e.url;if(typeof n!="string"||typeof r!="string"||typeof o!="string"||typeof i!="number")throw new Error("missing fields");return typeof s=="string"?{id:n,name:r,mime:o,size:i,url:s}:{id:n,name:r,mime:o,size:i}}function By(t){try{let e=JSON.parse(t.responseText);if(typeof e.error=="string")return e.error}catch{}return`upload failed (${t.status})`}var Vy=["data-attachments-url","data-attachment-accept","data-attachment-max-bytes","data-transcribe-url","data-threads-url","data-threads-cache","data-tools-url","data-skills-url","data-skills","data-prompt-chips","data-slash-commands","data-theme-toggle","data-strings","data-icon-url"],xl=["omit","same-origin","include"];function vl(t){return xl.includes(t)}var lp="ag-ui-chat:collapsed",cp="ag-ui-chat:size",dp="ag-ui-chat:theme",bl=6,yl=new Set,Rr=class extends HTMLElement{agentFactory=fl;headers={};getHeaders=null;trustedOrigins=[];allowImages=!1;formatRelativeTime=null;autoConfirm=!1;askUser=!1;askUserRenderer=null;approvalRenderer=null;approveWithEdits=!1;confirmPredicate=null;getTools=()=>[...this.#Qe().map(e=>({name:e.name,description:e.description,parameters:e.parameters})),...this.#n.tools()];getContext=()=>[...ka(this.getPageMap,this.autoInjectPageMap)];routeMap=[];navigate=null;getPageMap=null;autoInjectPageMap=!0;conversationStore=new je;uploadHandler=null;transcribeHandler=null;navigationResult=()=>({navigated:!0,url:window.location.href});skillContext=()=>({});toolSummaries={};strings={};resolvePageTarget=e=>document.querySelector(e);#t={};#r=new Set;#e=le;#s=new Set;#n=new dr;#i=new Map;#o=new Map;#c=new Set;#d=new Map;#a=new Map;#u=new Set;#p=[];#S=new Set;#m=null;#_=new Set;#M;#g=document.createElement("div");#L=document.createElement("button");#v=document.createElement("button");#_e="";#X=null;#le=document.createElement("div");#b;#F=null;#ce=!1;#y;#f;#l;#x;#Te;#H;#G;#w;#Se=null;#R;#A;#k;#de;#P;#C;#D;#ue=0;#$;#T=null;#pe;#Ae=null;#K=!1;#B=null;#Y={};#V=!1;#ke=null;#N=null;#he=null;#Ce=0;#fe="";#j=null;#me=null;#U=null;#q=null;#h="";#Z="";#ge=null;#Ie="";#Xe="";#te=null;#Re=0;#Ne=[];#Ke=[];#Ye=[];#Ze=[];constructor(){super(),this.#M=this.attachShadow({mode:"open"}),this.#y=document.createElement("div"),this.#f=document.createElement("div"),this.#l=document.createElement("textarea"),this.#x=document.createElement("button"),this.#Te=document.createElement("span"),this.#R=document.createElement("div"),this.#A=document.createElement("button"),this.#k=document.createElement("input"),this.#de=document.createElement("div"),this.#pe=document.createElement("span"),this.#P=document.createElement("button"),this.#C=document.createElement("button"),this.#D=document.createElement("span"),this.#$=document.createElement("div"),this.registerActivityRenderer({type:As,render:e=>{let n=Xy(e);return n===null?null:cl("\u{1F5DC}",this.#e.historyCompacted.replace("{count}",String(n)),"compaction")}}),this.registerActivityRenderer({type:ws,render:e=>dl(e,this.#e,n=>{this.sendMessage(n)})}),this.#H=new Hi(e=>this.#Wt(e)),this.#G=new Fi({onSelect:e=>{this.#Jt(e)},onNew:()=>{this.newChat(),this.#ie()},onRename:(e,n)=>{this.conversationStore.renameThread(e,n),this.#ie()},onDelete:e=>{this.#en(e)}}),this.#w=new gr((e,n)=>{this.#At(e,n)})}#Oe(){let e=this.getAttribute("data-runs-url");return e===null||e===""?null:(this.#Se===null&&(this.#Se=new Ir(e,()=>this.#re(e),()=>this.#ve())),this.#Se)}async#At(e,n){let r=this.#Oe();if(r===null)return;let o=this.#l.value.trim();if(o==="")return;this.#l.value="",this.#Q();let i=n==="resume"?r.resumeUrl(e):r.forkUrl(e),s=this.agentFactory({endpoint:i,headers:this.#ne(),getHeaders:()=>this.#ne(),trustedOrigins:this.trustedOrigins,...this.#be(),threadId:this.#h,initialMessages:[]});await new Gn({agent:s,handlers:this.#xt(),getTools:()=>this.#Je(),getContext:()=>this.#pt(),executeTool:l=>this.#bt(l),resolveInterrupts:l=>this.#yt(l),connectionLostMessage:this.#e.connectionLost}).send(o)}async#kt(){let e=this.#Oe();this.#w.setRelativeTimeFormatter(this.formatRelativeTime),this.#w.setRuns(e===null?[]:await e.continuable())}static get observedAttributes(){return["title-text","placement","credentials","user-key",...Vy]}attributeChangedCallback(e,n,r){if(e==="credentials"){r!==null&&!vl(r)&&console.error(`<ag-ui-chat>: credentials="${r}" is not a fetch credentials mode (${xl.join(" / ")}) \u2014 it is being ignored, so requests use the browser default and cross-origin cookies will not be sent.`);return}if(e==="placement"){this.#Kt(),requestAnimationFrame(()=>this.#Ue());return}if(e==="title-text"){this.#Te.textContent=r??this.#e.title;return}if(e==="user-key"){this.#K&&(n??"")!==(r??"")&&this.#Qt(n??"",r??"");return}n===r||!this.#K||console.warn(`<ag-ui-chat>: "${e}" was changed after the element connected, and is read only while connecting \u2014 this assignment has no effect. Set it before the element enters the DOM (in the markup, or on the element before appending it); frameworks that patch attributes after mount should bind it at creation. To apply a new value now, remove and re-insert the element.`)}registerTool(e){this.#n.register(e)}get sharedState(){return this.#B?.state??this.#Y}set sharedState(e){this.#Y={...e},this.#B?.setState(this.#Y)}registerPageState(e){for(let n of Ei(e))this.#n.register(n)}registerStateHook(e){this.registerPageState(e)}#Ct(){return this.routeMap.length===0?[]:Ia(()=>this.routeMap,()=>this.navigate)}#It(){let e=this.getPageMap;return e===null?[]:[{name:_s,description:"Read the current page's structure (fields, buttons, route). Call after acting to observe the result within the same turn.",parameters:{type:"object",properties:{},required:[],[Pe]:"Read the page"},handler:()=>e()}]}#Rt(){let e=this.getAttribute("data-page-actions");if(e===null)return[];let n=new Set(e.split(",").map(r=>r.trim()).filter(r=>r!==""));return Aa(n,r=>this.resolvePageTarget(r))}#Qe(){return[...this.#Ct(),...this.#It(),...this.#Rt(),...this.#Nt()]}#Nt(){return this.askUser?[{name:"ask_user",description:"Ask the user a question and wait for their answer. Provide `options` for a multiple-choice prompt; set `allow_custom` to also accept a free-text answer.",parameters:{type:"object",properties:{question:{type:"string",description:"The question to ask the user."},options:{type:"array",items:{type:"string"},description:"Preset choices offered as radio buttons."},allow_custom:{type:"boolean",description:"Allow a free-text answer in addition to any options."}},required:["question"]},handler:e=>this.#Ot(e)}]:[]}async#Ot(e){let r={question:typeof e.question=="string"?e.question:""},o=e.options;Array.isArray(o)&&(r.options=o.filter(a=>typeof a=="string")),e.allow_custom===!0&&(r.allowCustom=!0),this.#N=new AbortController;let i=this.#N.signal;this.#O();let s=this.askUserRenderer!==null?await this.askUserRenderer(r,{signal:i}):await Ba(this.#I(),r,{signal:i,strings:this.#e});return this.#N=null,this.#E(),this.#b.follow(),s}#Je(){let e=this.getTools();return this.#s=new Set(e.map(n=>n.name)),e}#Me(e){let n=this.#Qe().find(r=>r.name===e);return n!==void 0?n:this.#n.has(e)?this.#n.get(e):null}get endpoint(){return this.getAttribute("endpoint")??""}set endpoint(e){this.setAttribute("endpoint",e)}get userKey(){return this.getAttribute("user-key")??""}set userKey(e){this.setAttribute("user-key",e)}get credentials(){let e=this.getAttribute("credentials");return e!==null&&vl(e)?e:null}set credentials(e){if(e===null){this.removeAttribute("credentials");return}if(!vl(e))throw new TypeError(`<ag-ui-chat>: credentials must be one of ${xl.map(n=>`"${n}"`).join(", ")} (got ${JSON.stringify(e)}).`);this.setAttribute("credentials",e)}#ne(){return{...this.headers,...this.getHeaders?.()}}#re(e){let n=this.#ne();return qi(e,Object.keys(n),this.trustedOrigins,this.#r),n}#ve(){return this.credentials??void 0}#be(){let e=this.#ve();return e===void 0?{}:{credentials:e}}#et(e){return qe({headers:this.#re(e)},this.#ve())}get toolDisplay(){let e=this.getAttribute("data-tool-display");return e===vn.INLINE||e===vn.MINIMAL||e===vn.COMPACT?e:vn.FULL}set toolDisplay(e){this.setAttribute("data-tool-display",e)}connectedCallback(){if(this.#Z=this.#Zt(),this.#He(this.#lt()),requestAnimationFrame(()=>this.#Ue()),this.#e=Ra({...this.#Lt(),...this.strings}),this.getAttribute("data-theme-toggle")!==null){let e=this.#Fe(dp);e!==null&&this.setAttribute("theme",e)}if(this.#in(),this.#G.setStrings(this.#e),this.#w.setStrings(this.#e),this.#Fe(lp)==="1"&&this.setAttribute("collapsed",""),this.#gt(),this.#jt(),this.conversationStore instanceof je){let e=this.#ze();this.#te=e===""?this.conversationStore:new je(e),this.conversationStore=this.#te}this.#rt(),this.#Pt(),this.#Ut(),this.#h=this.conversationStore.threadId(),queueMicrotask(()=>this.#Mt()),this.#xe(),this.#K=!0}#Mt(){this.#K&&(this.#ot(),this.#it())}async reload(){this.#z(),this.#oe(),this.#W(!1),await Promise.all([this.#ot(),this.#it(),this.#xe()])}disconnectedCallback(){this.#K=!1,this.#ge!==null&&(yl.delete(this.#ge),this.#ge=null),this.#z(),this.#X?.detach(),this.#X=null,this.#T?.dispose(),this.#Ae?.dispose(),this.#b.dispose(),this.#F!==null&&(clearTimeout(this.#F),this.#F=null)}#tt(e){let n=this.getAttribute(e);return n!==null&&n!=="false"}#Lt(){let e=this.getAttribute("data-strings");if(e===null)return{};try{let n=JSON.parse(e);if(typeof n=="object"&&n!==null)return n}catch{}return{}}#Pt(){let e=this.getAttribute("data-attachments-url"),n=this.uploadHandler??this.#Dt(e);if(n===null)return;let r=this.getAttribute("data-attachment-accept")??"",o=new Ti({upload:n,maxBytes:this.#$t(),accept:r,strings:this.#e,onChange:()=>this.#un(o)});this.#T=o,this.#de.appendChild(this.#T.element),this.#k.accept=r,this.#A.hidden=!1,this.#Vt()}#Dt(e){return e===null?null:(n,r,o)=>gl(n,{url:e,headers:this.#re(e),...this.#be(),onProgress:r,signal:o})}#Ut(){let e=this.getAttribute("data-transcribe-url"),n=this.transcribeHandler??this.#Ht(e);n!==null&&(this.#Ae=new Gi({transcribe:n,onText:r=>this.#zt(r),strings:this.#e}),this.#pe.appendChild(this.#Ae.element))}#Ht(e){return e===null?null:n=>ml(n,{url:e,headers:this.#re(e),...this.#be()})}#zt(e){let n=this.#l.value.trim();this.#l.value=n===""?e:`${n} ${e}`,this.#vt(),this.#l.focus()}quote(e){let n=za(e);if(n==="")return;let r=this.#l.value.replace(/\s+$/,"");this.#l.value=r===""?n:`${r}
2843
+ `;var $i=class{element;#t;#n;#e;#s=new Map;constructor(e=ee){this.element=document.createElement("div"),this.element.className="subagent",this.element.setAttribute("part","subagent"),this.#t=document.createElement("button"),this.#t.type="button",this.#t.className="subagent-row",this.#t.setAttribute("part","subagent-row"),this.#t.setAttribute("aria-expanded","false"),this.#t.disabled=!0;let n=document.createElement("span");n.className="subagent-icon",n.setAttribute("part","subagent-icon"),n.setAttribute("aria-hidden","true"),this.#n=document.createElement("span"),this.#n.className="subagent-status",this.#n.setAttribute("part","subagent-status"),this.#n.textContent=e.subAgentWorking,this.#t.append(n,this.#n),this.#e=document.createElement("div"),this.#e.className="subagent-steps",this.#e.setAttribute("part","subagent-steps"),this.#e.setAttribute("role","list"),this.#e.setAttribute("aria-label",e.subAgentSteps),this.#e.hidden=!0,this.#t.addEventListener("click",()=>{this.#o(this.#t.getAttribute("aria-expanded")!=="true")}),this.element.append(this.#t,this.#e)}report(e){this.element.setAttribute("data-phase",e.phase),e.agent!==null&&this.element.setAttribute("data-agent",e.agent),e.status!==null&&(this.#n.textContent=e.status),e.tool!==null&&this.#r(e.tool)}#r(e){let n=this.#s.get(e.toolCallId)??this.#i(e);if(e.ok===null){n.removeAttribute("data-ok");return}n.setAttribute("data-ok",String(e.ok))}#i(e){let n=document.createElement("div");n.className="subagent-step",n.setAttribute("part","subagent-step"),n.setAttribute("role","listitem"),n.setAttribute("data-tool-call-id",e.toolCallId);let r=document.createElement("span");r.className="subagent-step-icon",r.setAttribute("part","subagent-step-icon"),r.setAttribute("aria-hidden","true");let o=document.createElement("span");return o.className="subagent-step-name",o.setAttribute("part","subagent-step-name"),o.textContent=e.name,n.append(r,o),this.#e.appendChild(n),this.#s.set(e.toolCallId,n),this.#t.disabled=!1,n}#o(e){this.#e.hidden=!e,this.#t.setAttribute("aria-expanded",String(e))}};var Uy=Object.values(Ql);function ip(t){return typeof t!="object"||t===null||Array.isArray(t)?null:t}function kr(t){return typeof t=="string"&&t!==""?t:null}function Hy(t){let e=ip(t);if(e===null)return null;let n=kr(e.toolCallId),r=kr(e.name),o=e.ok;return n===null||r===null||o!==null&&typeof o!="boolean"?null:{toolCallId:n,name:r,ok:o}}function sp(t){let e=ip(t);if(e===null)return null;let n=kr(e.delegationId),r=e.phase;return n===null||typeof r!="string"||!Uy.includes(r)?null:{delegationId:n,phase:r,agent:kr(e.agent),status:kr(e.status),tool:Hy(e.tool)}}var Fy=4,zy=120;function ap(t){if(typeof t!="object"||t===null)return null;let e=t.prompts;if(!Array.isArray(e))return null;let n=e.filter(r=>typeof r=="string").map(r=>r.trim()).filter(r=>r!==""&&r.length<=120).slice(0,4);return n.length===0?null:n}function hl(t,e,n){let r=ap(t);if(r===null)return null;let o=document.createElement("div");o.className="suggestions",o.setAttribute("part","suggestions"),o.setAttribute("role","group"),o.setAttribute("aria-label",e.suggestions);for(let i of r){let s=document.createElement("button");s.type="button",s.className="suggestion-chip",s.setAttribute("part","suggestion-chip"),s.textContent=i,s.addEventListener("click",()=>n(i)),o.appendChild(s)}return o}var Bi=class{element;#t;#n;#e;#s;#r=!1;constructor(e=ee){this.#s=e,this.element=document.createElement("div"),this.element.className="thoughts",this.element.setAttribute("part","thoughts"),this.element.setAttribute("data-streaming",""),this.#e=document.createElement("button"),this.#e.type="button",this.#e.className="thoughts-toggle",this.#e.setAttribute("part","thoughts-toggle"),this.#e.setAttribute("aria-expanded","true"),this.#t=document.createElement("span"),this.#t.className="thoughts-label",this.#t.setAttribute("part","thoughts-label"),this.#t.textContent=e.thinking,this.#e.append(this.#t),this.#n=document.createElement("pre"),this.#n.className="thoughts-body",this.#n.setAttribute("part","thoughts-body"),this.#e.addEventListener("click",()=>{this.#i(!this.#r)}),this.element.append(this.#e,this.#n)}stream(e){this.#n.textContent=e}collapse(){this.#r||(this.element.removeAttribute("data-streaming"),this.#t.textContent=this.#s.thoughts,this.#i(!0))}#i(e){this.#r=e,this.#n.hidden=e,this.#e.setAttribute("aria-expanded",String(!e))}};var Vi=class{element;#t;#n;#e;#s;#r;#i=null;#o;#u=[];#c="";#d=null;constructor(e,n=ee){this.#t=e,this.#o=n,this.element=document.createElement("div"),this.element.className="drawer",this.element.setAttribute("part","drawer"),this.element.hidden=!0;let r=document.createElement("div");r.className="drawer-backdrop",r.setAttribute("part","drawer-backdrop"),r.addEventListener("click",()=>this.close()),this.#n=document.createElement("div"),this.#n.className="drawer-panel",this.#n.setAttribute("part","drawer-panel"),this.#n.setAttribute("role","dialog"),this.#n.setAttribute("aria-modal","true"),this.#n.setAttribute("aria-label",n.chatHistory),this.#n.addEventListener("keydown",i=>this.#v(i));let o=document.createElement("div");o.className="drawer-header",o.setAttribute("part","drawer-header"),this.#e=document.createElement("span"),this.#e.className="drawer-title",this.#e.setAttribute("part","drawer-title"),this.#e.textContent=n.chats,this.#s=document.createElement("button"),this.#s.type="button",this.#s.className="drawer-new",this.#s.setAttribute("part","drawer-new"),this.#s.textContent=n.newChat,this.#s.addEventListener("click",()=>{this.close(),this.#t.onNew()}),o.append(this.#e,this.#s),this.#r=document.createElement("div"),this.#r.className="drawer-list",this.#r.setAttribute("part","drawer-list"),this.#n.append(o,this.#r),this.element.append(r,this.#n)}setRelativeTimeFormatter(e){this.#i=e}#a(e){return this.#i!==null?this.#i(e):vr(e,void 0,this.#o)}setStrings(e){this.#o=e,this.#n.setAttribute("aria-label",e.chatHistory),this.#e.textContent=e.chats,this.#s.textContent=e.newChat,this.#m()}isOpen(){return!this.element.hidden}open(){this.isOpen()||(this.#d=this.#p(),this.element.hidden=!1,this.#s.focus())}close(){this.isOpen()&&(this.element.hidden=!0,this.#d?.focus(),this.#d=null)}toggle(){this.isOpen()?this.close():this.open()}#p(){return this.element.getRootNode().activeElement}#v(e){if(e.key==="Escape"){e.preventDefault(),this.close();return}if(e.key!=="Tab")return;let n=Array.from(this.#n.querySelectorAll("button, input, [tabindex]")).filter(s=>!s.hidden),r=n[0],o=n[n.length-1],i=this.#p();e.shiftKey&&i===r?(e.preventDefault(),o?.focus()):!e.shiftKey&&i===o&&(e.preventDefault(),r?.focus())}setThreads(e,n){this.#u=e,this.#c=n,this.#m()}#m(){if(this.#r.replaceChildren(),this.#u.length===0){let e=document.createElement("div");e.className="drawer-empty",e.setAttribute("part","drawer-empty"),e.textContent=this.#o.noConversations,this.#r.appendChild(e);return}for(let e of this.#u)this.#r.appendChild(this.#y(e))}#y(e){let n=document.createElement("div");n.className="drawer-row",n.setAttribute("part","drawer-row"),e.threadId===this.#c&&n.classList.add("drawer-row--active");let r=document.createElement("button");r.type="button",r.className="drawer-row-select",r.setAttribute("part","drawer-row-select");let o=document.createElement("span");o.className="drawer-row-title",o.setAttribute("part","drawer-row-title"),o.textContent=e.title;let i=document.createElement("span");i.className="drawer-row-time",i.setAttribute("part","drawer-row-time"),i.textContent=this.#a(e.updatedAt);let s=document.createElement("span");s.className="drawer-row-preview",s.setAttribute("part","drawer-row-preview"),s.textContent=e.preview,r.append(o,i,s),r.addEventListener("click",()=>{this.close(),this.#t.onSelect(e.threadId)});let a=document.createElement("button");a.type="button",a.className="drawer-row-rename",a.setAttribute("part","drawer-row-rename"),a.title=this.#o.rename,a.setAttribute("aria-label",this.#o.renameConversation),a.textContent="\u270E",a.addEventListener("click",()=>this.#U(n,e));let l=document.createElement("button");l.type="button",l.className="drawer-row-delete",l.setAttribute("part","drawer-row-delete"),l.title=this.#o.delete,l.setAttribute("aria-label",this.#o.deleteConversation),l.textContent="\u{1F5D1}",l.addEventListener("click",()=>this.#T(n,e));let c=document.createElement("div");return c.className="drawer-row-actions",c.setAttribute("part","drawer-row-actions"),c.append(a,l),n.append(r,c),n}#U(e,n){let r=document.createElement("input");r.type="text",r.className="drawer-rename-input",r.setAttribute("part","drawer-rename-input"),r.value=n.title;let o=!1,i=()=>{if(o)return;o=!0;let a=r.value.trim();a===""||a===n.title?this.#m():this.#t.onRename(n.threadId,a)},s=()=>{o||(o=!0,this.#m())};r.addEventListener("keydown",a=>{a.key==="Enter"?(a.preventDefault(),i()):a.key==="Escape"&&(a.preventDefault(),a.stopPropagation(),s())}),r.addEventListener("blur",()=>i()),e.replaceChildren(r),r.focus(),r.select()}#T(e,n){let r=document.createElement("div");r.className="drawer-confirm",r.setAttribute("part","drawer-confirm");let o=document.createElement("span");o.className="drawer-confirm-label",o.setAttribute("part","drawer-confirm-label"),o.textContent=this.#o.deletePrompt;let i=document.createElement("button");i.type="button",i.className="drawer-confirm-yes",i.setAttribute("part","drawer-confirm-yes"),i.textContent=this.#o.delete,i.addEventListener("click",()=>this.#t.onDelete(n.threadId));let s=document.createElement("button");s.type="button",s.className="drawer-confirm-no",s.setAttribute("part","drawer-confirm-no"),s.textContent=this.#o.cancel,s.addEventListener("click",()=>this.#m()),r.append(o,i,s),e.replaceChildren(r)}};function fl(t){return{[te.PENDING]:t.toolRunning,[te.DEFERRED]:t.toolDeferred,[te.DONE]:t.toolDone,[te.ERROR]:t.toolError,[te.DECLINED]:t.toolDeclined}}function Gy(t){return{[te.DONE]:t.resultLabel,[te.ERROR]:t.errorLabel,[te.DECLINED]:t.declinedLabel}}function $y(t){try{return JSON.stringify(JSON.parse(t),null,2)}catch{return t}}var Cr=class{element;approvalSlot;subagentSlot;#t;#n;#e;#s;#r;#i;#o;args;#u;#c;#d=!1;constructor(e,n,r,o=ee,i={}){this.#o=o,this.args=n,this.#u=e,this.#c=i.formatPayload??null,this.element=document.createElement("div"),this.element.className="tool-call",this.element.setAttribute("part","tool-card"),this.element.setAttribute("data-tool-name",e),this.element.setAttribute("data-status",te.PENDING),this.element.setAttribute("data-expanded","false");let s=document.createElement("div");s.className="tool-call-head",s.setAttribute("part","tool-card-head");let a=document.createElement("span");a.className="tool-call-icon",a.setAttribute("part","tool-card-icon"),a.setAttribute("aria-hidden","true");let l=document.createElement("span");l.className="tool-call-name",l.setAttribute("part","tool-card-name"),l.textContent=r??e,this.#t=document.createElement("span"),this.#t.className="tool-call-status",this.#t.setAttribute("part","tool-card-status"),this.#t.textContent=fl(o)[te.PENDING],this.#n=document.createElement("span"),this.#n.className="tool-call-decision",this.#n.setAttribute("part","tool-card-decision"),this.#n.hidden=!0,s.append(a,l,this.#t,this.#n);let c=this.#p("args",o.argumentsLabel);this.#a(c.body,{kind:"arguments",toolName:e,args:n},JSON.stringify(n,null,2)),c.root.hidden=Object.keys(n).length===0;let u=this.#p("result",o.resultLabel);this.#s=u.root,this.#r=u.label,this.#i=u.body,u.root.hidden=!0,this.#e=document.createElement("button"),this.#e.type="button",this.#e.className="tool-call-toggle",this.#e.setAttribute("part","tool-card-toggle"),this.#e.setAttribute("aria-expanded","false"),this.#e.textContent=o.details,this.#e.addEventListener("click",()=>this.#m(!this.#v()));let m=document.createElement("div");m.className="tool-call-body",m.setAttribute("part","tool-card-body"),m.append(c.root,u.root),this.approvalSlot=document.createElement("div"),this.approvalSlot.className="tool-call-approval",this.approvalSlot.setAttribute("part","tool-card-approval"),this.subagentSlot=document.createElement("div"),this.subagentSlot.className="tool-call-subagent",this.subagentSlot.setAttribute("part","tool-card-subagent"),this.element.append(s,this.subagentSlot,this.#e,m,this.approvalSlot)}mark(e){this.#d||(this.element.setAttribute("data-status",e),this.#t.textContent=fl(this.#o)[e])}recordDecision(e){this.element.setAttribute("data-decision",e),this.#n.textContent=e==="approved"?this.#o.decisionApproved:this.#o.decisionDeclined,this.#n.hidden=!1}get settled(){return this.#d}settle(e,n){this.#d||(this.#d=!0,this.element.setAttribute("data-status",e),this.#t.textContent=fl(this.#o)[e],this.#r.textContent=Gy(this.#o)[e],this.#a(this.#i,{kind:"result",toolName:this.#u,status:e,text:n},$y(n)),this.#s.hidden=!1)}#a(e,n,r){let o=this.#c===null?null:this.#c(n);if(o===null){e.textContent=r;return}if(e.setAttribute("data-formatted","true"),typeof o=="string"){e.textContent=o;return}e.replaceChildren(o)}#p(e,n){let r=document.createElement("div");r.className=`tool-call-section tool-call-section--${e}`,r.setAttribute("part",`tool-card-section tool-card-${e}-section`);let o=document.createElement("span");o.className="tool-call-section-label",o.setAttribute("part",`tool-card-section-label tool-card-${e}-label`),o.textContent=n;let i=document.createElement("pre");return i.className=`tool-call-${e}`,i.setAttribute("part",`tool-card-${e}`),r.append(o,i),{root:r,label:o,body:i}}#v(){return this.element.getAttribute("data-expanded")==="true"}#m(e){this.element.setAttribute("data-expanded",String(e)),this.#e.setAttribute("aria-expanded",String(e))}};var lp=12e4,ji=class{element;#t;#n;#e;#s="idle";#r=null;#i=null;#o=[];#u=null;#c=!1;#d=!1;constructor(e){this.#t=e.transcribe,this.#n=e.onText,this.#e=e.strings??ee,this.element=document.createElement("button"),this.element.type="button",this.element.className="voice-btn",this.element.setAttribute("part","voice-button");let n=document.createElement("slot");n.name="icon-voice",n.innerHTML=nc,this.element.append(n),this.#T("idle"),this.element.addEventListener("click",()=>{this.toggle()})}async toggle(){if(this.#s==="recording"){this.#p();return}this.#s!=="transcribing"&&await this.#a()}async#a(){let e;try{e=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{this.#U(this.#e.transcriptionFailed);return}this.#i=e,this.#o=[],this.#c=!1;let n=new MediaRecorder(e);n.addEventListener("dataavailable",r=>{this.#o.push(r.data)}),n.addEventListener("stop",()=>{this.#m(n.mimeType)}),this.#r=n,n.start(),this.#u=setTimeout(()=>{this.#c=!0,this.#p()},lp),this.#T("recording")}#p(){this.#v(),this.#r?.stop()}#v(){this.#u!==null&&(clearTimeout(this.#u),this.#u=null)}dispose(){this.#d=!0,this.#v(),this.#r!==null&&this.#r.state!=="inactive"&&this.#r.stop(),this.#r=null,this.#y()}async#m(e){if(this.#d)return;this.#y(),this.#T("transcribing");let n=new Blob(this.#o,{type:e||"audio/webm"});try{let r=await this.#t(n);this.#T("idle"),this.#c&&(this.element.title=this.#e.recordingLimit.replace("{n}",String(lp/6e4))),r!==""&&this.#n(r)}catch(r){this.#U(r instanceof Error?r.message:this.#e.transcriptionFailed)}finally{this.#r=null}}#y(){for(let e of this.#i?.getTracks()??[])e.stop();this.#i=null}#U(e){this.#y(),this.#r=null,this.#T("idle"),this.element.title=e}#T(e){this.#s=e,this.element.dataset.state=e;let n=this.#M(e);this.element.title=n,this.element.setAttribute("aria-label",n),this.element.setAttribute("aria-pressed",String(e==="recording")),this.element.disabled=e==="transcribing"}#M(e){return e==="recording"?this.#e.stopRecording:e==="transcribing"?this.#e.transcribing:this.#e.recordVoice}};var qi=class extends Error{constructor(e){super(e),this.name="ConnectionLostError"}},Bn=class{#t;#n;#e;#s;#r;#i;#o;#u=new Set;#c;#d;#a=!1;constructor(e){this.#t=e.agent,this.#n=e.handlers,this.#e=e.getTools??(()=>[]),this.#s=e.getContext??(()=>[]),this.#r=e.executeTool??null,this.#i=e.resolveInterrupts??null,this.#o=e.onPersist??(()=>{}),this.#c=e.connectionLostMessage??"Connection lost";let n=e.maxToolRounds??vn;this.#d=n>=1?Math.floor(n):vn;let r=e.onStateChanged;r!==void 0&&this.#t.subscribe({onStateChanged:({state:o})=>{r(o)}})}get state(){return this.#t.state}setState(e){this.#t.setState({...e})}get running(){return this.#t.isRunning}get messages(){return this.#t.messages}async send(e,n=[]){let r={id:_e(),role:"user",content:e};n.length>0&&(r.attachments=n),this.#t.addMessage(r),this.#o(this.#t.messages),await this.#p()}truncateToLastUser(){let e=[...this.#t.messages],n=-1;for(let[o,i]of e.entries())i.role==="user"&&(n=o);if(n===-1)return null;let r=e.slice(0,n+1);return this.#t.setMessages(r),this.#o(this.#t.messages),r}async resume(){await this.#p()}addToolResult(e,n){this.#t.addMessage({id:_e(),role:"tool",content:n,toolCallId:e}),this.#o(this.#t.messages)}cancel(){this.#a=!0,this.#t.abortRun()}async#p(){this.#a=!1;try{await this.#m(),this.#a&&this.#v()}catch(e){this.#a||By(e)?this.#v():this.#n.onError(e instanceof Error?e.message:String(e))}finally{this.#n.onSettled()}}#v(){this.#o(this.#t.messages),this.#n.onCancelled()}async#m(){let e;for(let n=0;n<this.#d;n+=1){if(this.#a)return;let r=[],o={terminal:!1,errored:!1,interrupts:[]},i={tools:this.#e(),context:this.#s()};if(e!==void 0&&(i.resume=e),await this.#t.runAgent(i,this.#y(r,o)),e=void 0,this.#o(this.#t.messages),this.#a)return;if(!o.terminal)throw new qi(this.#c);if(o.errored)return;if(o.interrupts.length>0){if(this.#i===null)return;let a=await this.#i(o.interrupts);if(this.#a)return;e=Jd(o.interrupts,a);continue}if(this.#r===null||r.length===0)return;let s=!1;for(let a of r){let l=await this.#r(a);if(l!==null){if(l.halt===!0)return;this.#t.addMessage({id:_e(),role:"tool",content:l.content,toolCallId:a.id}),this.#o(this.#t.messages),s=!0}}if(!s)return}}#y(e,n){let r=this.#n,o=this.#u,i=()=>this.#a,s=new Set;return{onRunInitialized(){r.onRunStart()},onTextMessageStartEvent({event:a}){o.has(a.messageId)&&console.warn(`<ag-ui-chat>: the server reused message id "${a.messageId}", which was already closed. Its content will be appended to that earlier message rather than starting a new one, and the merged result is what gets persisted. Issue a fresh id per message.`)},onTextMessageContentEvent({textMessageBuffer:a}){r.onTextDelta(a)},onTextMessageEndEvent({event:a,textMessageBuffer:l}){o.add(a.messageId),r.onTextEnd(l)},onToolCallEndEvent({event:a,toolCallName:l,toolCallArgs:c}){let u={id:a.toolCallId,name:l,args:c};e.push(u),r.onToolCall(u)},onToolCallResultEvent({event:a}){r.onToolResult(a.toolCallId,a.content)},onActivitySnapshotEvent({event:a,messages:l}){if(l.some(u=>u.id===a.messageId&&u.role==="activity")){r.onActivityChanged(a.messageId,a.activityType,a.content);return}r.onActivity(a.activityType,a.content,a.messageId)},onActivityDeltaEvent({event:a}){s.add(a.messageId)},onCustomEvent({event:a}){r.onCustomEvent(a.name,a.value)},onMessagesSnapshotEvent({event:a}){r.onMessagesSnapshot(a.messages)},onMessagesChanged({messages:a}){if(s.size!==0){for(let l of s){let c=a.find(u=>u.id===l);c!==void 0&&c.role==="activity"&&r.onActivityChanged(l,c.activityType,c.content)}s.clear()}},onReasoningStartEvent(){r.onReasoningStart()},onReasoningMessageContentEvent({reasoningMessageBuffer:a}){r.onReasoningDelta(a)},onReasoningMessageEndEvent({reasoningMessageBuffer:a}){r.onReasoningDelta(a)},onReasoningEndEvent(){r.onReasoningEnd()},onRunFinishedEvent(a){n.terminal=!0,a.outcome==="interrupt"&&(n.interrupts=a.interrupts)},onRunErrorEvent({event:a}){n.terminal=!0,n.errored=!0,!i()&&r.onError(a.message)},onRunFinalized(){n.terminal=!0,r.onRunEnd()}}}};function By(t){return t instanceof Error?t.name==="AbortError"||t instanceof TypeError&&/abort/i.test(t.message):!1}function ml(t){let e=t.attachments;return Array.isArray(e)?e.filter(Vy):[]}function Vy(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.id=="string"&&typeof e.name=="string"&&typeof e.mime=="string"&&typeof e.size=="number"&&(e.url===void 0||typeof e.url=="string")}var cp="ag-ui-chat",Vn="thread",gl="threads",Ir="messages:",Xi="checkpoint:",Rr="minted:",jy=60,qy=100,Wy="New conversation",dp=!1;function et(t,e){try{sessionStorage.setItem(t,e)}catch{if(dp)return;dp=!0,console.warn("<ag-ui-chat>: the browser refused a sessionStorage write \u2014 the quota is full, or storage is disabled for this context. The conversation continues, but it will not survive a page reload. Deleting a long conversation from the history drawer frees the quota.")}}function Wi(t){return t===""?cp:`${cp}@${t}`}var je=class t{#t;constructor(e=""){this.#t=Wi(e),e!==""&&t.adopt("",e)}static adopt(e,n){let r=`${Wi(e)}:`,o=`${Wi(n)}:`;for(let[i,s]of up(r)){let a=sessionStorage.getItem(i),l=o+s;a!==null&&sessionStorage.getItem(l)===null&&et(l,a),sessionStorage.removeItem(i)}}static purge(e){for(let[n]of up(`${Wi(e)}:`))sessionStorage.removeItem(n)}threadId(){return sessionStorage.getItem(this.#r(Vn))??this.newThread()}newThread(){let e=_e();return et(this.#r(Vn),e),et(this.#r(Rr+e),"1"),e}isUnsent(e){return sessionStorage.getItem(this.#r(Rr+e))!==null&&sessionStorage.getItem(this.#r(Ir+e))===null}loadMessages(e){return Promise.resolve(this.#i(this.#r(Ir+e)))}saveMessages(e,n){et(this.#r(Ir+e),JSON.stringify(n)),sessionStorage.removeItem(this.#r(Rr+e)),this.#n(e,n)}loadCheckpoint(e){return this.#i(this.#r(Xi+e))}saveCheckpoint(e,n){let r=this.#r(Xi+e);if(n===null){sessionStorage.removeItem(r);return}et(r,JSON.stringify(n))}clear(e){sessionStorage.removeItem(this.#r(Ir+e)),sessionStorage.removeItem(this.#r(Xi+e)),sessionStorage.removeItem(this.#r(Rr+e)),this.#s(this.#e().filter(n=>n.threadId!==e)),sessionStorage.getItem(this.#r(Vn))===e&&sessionStorage.removeItem(this.#r(Vn))}listThreads(){let e=this.#e().sort((n,r)=>r.updatedAt-n.updatedAt).map(({threadId:n,title:r,updatedAt:o,preview:i})=>({threadId:n,title:r,updatedAt:o,preview:i}));return Promise.resolve(e)}setActiveThread(e){et(this.#r(Vn),e)}renameThread(e,n){let r=this.#e(),o=r.find(i=>i.threadId===e);o!==void 0&&(o.title=n,o.titleCustom=!0,this.#s(r))}#n(e,n){let r=this.#e(),o=r.find(a=>a.threadId===e),i=Yy(n),s=Date.now();o===void 0?r.push({threadId:e,title:pp(n),titleCustom:!1,preview:i,updatedAt:s}):(o.preview=i,o.updatedAt=s,o.titleCustom||(o.title=pp(n))),this.#s(r)}#e(){return this.#i(this.#r(gl))??[]}#s(e){let n=this.#r(gl);if(e.length===0){sessionStorage.removeItem(n);return}et(n,JSON.stringify(e))}#r(e){return`${this.#t}:${e}`}#i(e){let n=sessionStorage.getItem(e);if(n===null)return null;try{return JSON.parse(n)}catch{return null}}};function up(t){let e=[];for(let n=0;n<sessionStorage.length;n+=1){let r=sessionStorage.key(n);if(r===null||!r.startsWith(t))continue;let o=r.slice(t.length);Xy(o)&&e.push([r,o])}return e}function Xy(t){return t===Vn||t===gl||t.startsWith(Ir)||t.startsWith(Xi)||t.startsWith(Rr)}function pp(t){for(let e of t)if(e.role==="user"){let n=hp(e.content);if(n!=="")return fp(n,jy)}return Wy}function Yy(t){for(let e of[...t].reverse()){let n=hp(e.content);if(n!=="")return fp(n,qy)}return""}function hp(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():""}function fp(t,e){return t.length<=e?t:`${t.slice(0,e-1).trimEnd()}\u2026`}function qe(t,e){return e===void 0?t:{...t,credentials:e}}function Yi(t){if(t.newThread!==void 0)return t.newThread();let e=_e();return t.setActiveThread(e),e}function Ki(t,e,n,r){if(e.length===0)return;let o=new URL(String(t),location.href).origin;o===location.origin||n.includes(o)||r.has(o)||(r.add(o),console.warn(`<ag-ui-chat>: sending host credentials (${e.join(", ")}) to ${o}, which is not this page's origin (${location.origin}). Those headers are the page's own authentication, and whichever server answers the browser's preflight receives them \u2014 so a URL attribute built from a query parameter or from tenant-authored configuration is a channel for the token to leave on. If this destination is deliberate, name it in \`trustedOrigins\` to confirm it and silence this notice. Reported once per origin.`))}function vl(t){let e=t.headers??{},n=new Set;return new eu({url:t.endpoint,headers:e,initialState:{...t.initialState??{}},fetch:(r,o)=>{let i=t.getHeaders?.(),s=[...new Set([...Object.keys(e),...Object.keys(i??{})])].sort();if(Ki(r,s,t.trustedOrigins??[],n),i===void 0)return fetch(r,qe(o,t.credentials));let a=new Headers(o?.headers);for(let[l,c]of Object.entries(i))a.set(l,c);return fetch(r,qe({...o,headers:a},t.credentials))},...t.threadId!==void 0?{threadId:t.threadId}:{},...t.initialMessages!==void 0?{initialMessages:[...t.initialMessages]}:{}})}var Nr=class{#t;#n;#e;#s;#r;#i=new Set;#o=new Map;constructor(e,n=()=>({}),r=new je,o=()=>{},i=!0){this.#t=e.endsWith("/")?e:`${e}/`,this.#n=n,this.#e=r,this.#s=o,this.#r=i}threadId(){return this.#e.threadId()}setActiveThread(e){this.#e.setActiveThread(e)}newThread(){return Yi(this.#e)}isUnsent(e){return this.#e.isUnsent?.(e)===!0}saveMessages(e,n){this.#e.saveMessages(e,this.#r?n:[])}loadCheckpoint(e){return this.#e.loadCheckpoint(e)}saveCheckpoint(e,n){this.#e.saveCheckpoint(e,n)}renameThread(e,n){this.#e.renameThread(e,n),this.#o.set(e,n),this.#p(e,"PATCH",{title:n})}clear(e){this.#e.clear(e),this.#i.add(e),this.#p(e,"DELETE")}async listThreads(){let e=await this.#u();return e===null?this.#e.listThreads():e.filter(n=>!this.#i.has(n.thread_id)).map(n=>this.#d(n))}async loadMessages(e){if(this.#e.isUnsent?.(e)===!0)return null;let n=await this.#a(`${this.#t}${encodeURIComponent(e)}/`);if(n===null||!n.ok)return this.#e.loadMessages(e);let r=await this.#c(n);return r===null?this.#e.loadMessages(e):r.messages??null}async#u(){let e=await this.#a(this.#t);if(e===null||!e.ok)return null;let n=await this.#c(e);return n===null?null:n.threads??[]}async#c(e){try{return await e.json()}catch{return null}}#d(e){return{threadId:e.thread_id,title:this.#o.get(e.thread_id)??e.title,updatedAt:e.updated_at===null?Number.NaN:Date.parse(e.updated_at),preview:e.preview}}async#a(e){try{return await fetch(e,qe({headers:this.#n()},this.#s()))}catch{return null}}async#p(e,n,r){let o=this.#n();try{await fetch(`${this.#t}${encodeURIComponent(e)}/`,qe({method:n,headers:r===void 0?o:{...o,"content-type":"application/json"},body:r===void 0?null:JSON.stringify(r)},this.#s()))}catch{}}};var Or=class{#t;#n;#e;constructor(e,n=()=>({}),r=()=>{}){this.#t=e.endsWith("/")?e:`${e}/`,this.#n=n,this.#e=r}async list(){try{let e=await fetch(this.#t,qe({method:"GET",headers:{Accept:"application/json",...this.#n()}},this.#e()));return e.ok?(await e.json()).runs??[]:[]}catch{return[]}}async continuable(){return(await this.list()).filter(e=>e.continuable)}resumeUrl(e){return this.#s("resume",e)}forkUrl(e){return this.#s("fork",e)}#s(e,n){return`${this.#t.slice(0,-5)}${e}/${encodeURIComponent(n)}/`}};async function bl(t,e){let n=new FormData;n.append("audio",t,"recording.webm");let r=await fetch(e.url,qe({method:"POST",headers:{...e.headers??{}},body:n},e.credentials));if(!r.ok)throw new Error(await Ky(r));let o=await r.json();if(typeof o=="object"&&o!==null&&typeof o.text=="string")return o.text;throw new Error("transcription returned an unreadable response")}async function Ky(t){try{let e=await t.json();if(typeof e.error=="string")return e.error}catch{}return`transcription failed (${t.status})`}function yl(t,e){return new Promise((n,r)=>{let o=new FormData;o.append("file",t);let i=new XMLHttpRequest;i.open("POST",e.url),i.withCredentials=e.credentials==="include";for(let[l,c]of Object.entries(e.headers??{}))i.setRequestHeader(l,c);let s=e.onProgress;s!==void 0&&i.upload.addEventListener("progress",l=>{l.lengthComputable&&s(l.total===0?0:l.loaded/l.total)}),i.addEventListener("load",()=>{if(i.status>=200&&i.status<300)try{n(Zy(JSON.parse(i.responseText)))}catch{r(new Error("upload returned an unreadable response"))}else r(new Error(Qy(i)))}),i.addEventListener("error",()=>r(new Error("upload failed"))),i.addEventListener("abort",()=>r(new Error("upload cancelled")));let a=e.signal;a!==void 0&&a.addEventListener("abort",()=>i.abort()),i.send(o)})}function Zy(t){if(typeof t!="object"||t===null)throw new Error("not an object");let e=t,n=e.id,r=e.name,o=e.mime,i=e.size,s=e.url;if(typeof n!="string"||typeof r!="string"||typeof o!="string"||typeof i!="number")throw new Error("missing fields");return typeof s=="string"?{id:n,name:r,mime:o,size:i,url:s}:{id:n,name:r,mime:o,size:i}}function Qy(t){try{let e=JSON.parse(t.responseText);if(typeof e.error=="string")return e.error}catch{}return`upload failed (${t.status})`}var Jy=["data-attachments-url","data-attachment-accept","data-attachment-max-bytes","data-transcribe-url","data-threads-url","data-threads-cache","data-tools-url","data-skills-url","data-skills","data-prompt-chips","data-slash-commands","data-theme-toggle","data-strings","data-icon-url"],_l=["omit","same-origin","include"];function xl(t){return _l.includes(t)}var mp="ag-ui-chat:collapsed",gp="ag-ui-chat:size",vp="ag-ui-chat:theme",wl=6,El=new Set,Mr=class extends HTMLElement{agentFactory=vl;headers={};getHeaders=null;trustedOrigins=[];allowImages=!1;formatRelativeTime=null;autoConfirm=!1;askUser=!1;askUserRenderer=null;approvalRenderer=null;approveWithEdits=!1;confirmPredicate=null;getTools=()=>[...this.#Je().map(e=>({name:e.name,description:e.description,parameters:e.parameters})),...this.#r.tools()];getContext=()=>[...Ra(this.getPageMap,this.autoInjectPageMap)];routeMap=[];navigate=null;getPageMap=null;autoInjectPageMap=!0;conversationStore=new je;uploadHandler=null;transcribeHandler=null;navigationResult=()=>({navigated:!0,url:window.location.href});skillContext=()=>({});toolSummaries={};formatToolPayload=null;strings={};resolvePageTarget=e=>document.querySelector(e);#t={};#n=new Set;#e=ee;#s=new Set;#r=new pr;#i=new Map;#o=new Map;#u=new Map;#c=new Set;#d=new Map;#a=new Map;#p=new Set;#v=[];#m=new Set;#y=null;#U=new Set;#T;#M=document.createElement("div");#z=document.createElement("button");#b=document.createElement("button");#Te="";#Y=null;#ce=document.createElement("div");#g;#G=null;#de=!1;#x;#f;#l;#w;#Se;#H;#$;#E;#Ae=null;#R;#A;#k;#ue;#L;#C;#P;#pe=0;#B;#S=null;#he;#ke=null;#K=!1;#V=null;#Z={};#j=!1;#Ce=null;#N=null;#fe=null;#Ie=0;#me="";#q=null;#ge=null;#D=null;#W=null;#h="";#Q="";#ve=null;#Re="";#Ye="";#ne=null;#Ne=0;#Oe=[];#Ke=[];#Ze=[];#Qe=[];constructor(){super(),this.#T=this.attachShadow({mode:"open"}),this.#x=document.createElement("div"),this.#f=document.createElement("div"),this.#l=document.createElement("textarea"),this.#w=document.createElement("button"),this.#Se=document.createElement("span"),this.#R=document.createElement("div"),this.#A=document.createElement("button"),this.#k=document.createElement("input"),this.#ue=document.createElement("div"),this.#he=document.createElement("span"),this.#L=document.createElement("button"),this.#C=document.createElement("button"),this.#P=document.createElement("span"),this.#B=document.createElement("div"),this.registerActivityRenderer({type:Is,render:e=>{let n=rx(e);return n===null?null:pl("\u{1F5DC}",this.#e.historyCompacted.replace("{count}",String(n)),"compaction")}}),this.registerActivityRenderer({type:Ss,render:e=>hl(e,this.#e,n=>{this.sendMessage(n)})}),this.#H=new Gi(e=>this.#Kt(e)),this.#$=new Vi({onSelect:e=>{this.#nn(e)},onNew:()=>{this.newChat(),this.#se()},onRename:(e,n)=>{this.conversationStore.renameThread(e,n),this.#se()},onDelete:e=>{this.#rn(e)}}),this.#E=new br((e,n)=>{this.#kt(e,n)})}#Me(){let e=this.getAttribute("data-runs-url");return e===null||e===""?null:(this.#Ae===null&&(this.#Ae=new Or(e,()=>this.#oe(e),()=>this.#be())),this.#Ae)}async#kt(e,n){let r=this.#Me();if(r===null)return;let o=this.#l.value.trim();if(o==="")return;this.#l.value="",this.#J();let i=n==="resume"?r.resumeUrl(e):r.forkUrl(e),s=this.agentFactory({endpoint:i,headers:this.#re(),getHeaders:()=>this.#re(),trustedOrigins:this.trustedOrigins,...this.#ye(),threadId:this.#h,initialMessages:[]});await new Bn({agent:s,handlers:this.#wt(),getTools:()=>this.#et(),getContext:()=>this.#ht(),executeTool:l=>this.#yt(l),resolveInterrupts:l=>this.#xt(l),connectionLostMessage:this.#e.connectionLost}).send(o)}async#Ct(){let e=this.#Me();this.#E.setRelativeTimeFormatter(this.formatRelativeTime),this.#E.setRuns(e===null?[]:await e.continuable())}static get observedAttributes(){return["title-text","placement","credentials","user-key",...Jy]}attributeChangedCallback(e,n,r){if(e==="credentials"){r!==null&&!xl(r)&&console.error(`<ag-ui-chat>: credentials="${r}" is not a fetch credentials mode (${_l.join(" / ")}) \u2014 it is being ignored, so requests use the browser default and cross-origin cookies will not be sent.`);return}if(e==="placement"){this.#Qt(),requestAnimationFrame(()=>this.#He());return}if(e==="title-text"){this.#Se.textContent=r??this.#e.title;return}if(e==="user-key"){this.#K&&(n??"")!==(r??"")&&this.#tn(n??"",r??"");return}n===r||!this.#K||console.warn(`<ag-ui-chat>: "${e}" was changed after the element connected, and is read only while connecting \u2014 this assignment has no effect. Set it before the element enters the DOM (in the markup, or on the element before appending it); frameworks that patch attributes after mount should bind it at creation. To apply a new value now, remove and re-insert the element.`)}registerTool(e){this.#r.register(e)}get sharedState(){return this.#V?.state??this.#Z}set sharedState(e){this.#Z={...e},this.#V?.setState(this.#Z)}registerPageState(e){for(let n of Si(e))this.#r.register(n)}registerStateHook(e){this.registerPageState(e)}#It(){return this.routeMap.length===0?[]:Oa(()=>this.routeMap,()=>this.navigate)}#Rt(){let e=this.getPageMap;return e===null?[]:[{name:ks,description:"Read the current page's structure (fields, buttons, route). Call after acting to observe the result within the same turn.",parameters:{type:"object",properties:{},required:[],[Pe]:"Read the page"},handler:()=>e()}]}#Nt(){let e=this.getAttribute("data-page-actions");if(e===null)return[];let n=new Set(e.split(",").map(r=>r.trim()).filter(r=>r!==""));return Ia(n,r=>this.resolvePageTarget(r))}#Je(){return[...this.#It(),...this.#Rt(),...this.#Nt(),...this.#Ot()]}#Ot(){return this.askUser?[{name:"ask_user",description:"Ask the user a question and wait for their answer. Provide `options` for a multiple-choice prompt; set `allow_custom` to also accept a free-text answer.",parameters:{type:"object",properties:{question:{type:"string",description:"The question to ask the user."},options:{type:"array",items:{type:"string"},description:"Preset choices offered as radio buttons."},allow_custom:{type:"boolean",description:"Allow a free-text answer in addition to any options."}},required:["question"]},handler:e=>this.#Mt(e)}]:[]}async#Mt(e){let r={question:typeof e.question=="string"?e.question:""},o=e.options;Array.isArray(o)&&(r.options=o.filter(a=>typeof a=="string")),e.allow_custom===!0&&(r.allowCustom=!0),this.#N=new AbortController;let i=this.#N.signal;this.#O();let s=this.askUserRenderer!==null?await this.askUserRenderer(r,{signal:i}):await qa(this.#I(),r,{signal:i,strings:this.#e});return this.#N=null,this.#_(),this.#g.follow(),s}#et(){let e=this.getTools();return this.#s=new Set(e.map(n=>n.name)),e}#Le(e){let n=this.#Je().find(r=>r.name===e);return n!==void 0?n:this.#r.has(e)?this.#r.get(e):null}get endpoint(){return this.getAttribute("endpoint")??""}set endpoint(e){this.setAttribute("endpoint",e)}get userKey(){return this.getAttribute("user-key")??""}set userKey(e){this.setAttribute("user-key",e)}get credentials(){let e=this.getAttribute("credentials");return e!==null&&xl(e)?e:null}set credentials(e){if(e===null){this.removeAttribute("credentials");return}if(!xl(e))throw new TypeError(`<ag-ui-chat>: credentials must be one of ${_l.map(n=>`"${n}"`).join(", ")} (got ${JSON.stringify(e)}).`);this.setAttribute("credentials",e)}#re(){return{...this.headers,...this.getHeaders?.()}}#oe(e){let n=this.#re();return Ki(e,Object.keys(n),this.trustedOrigins,this.#n),n}#be(){return this.credentials??void 0}#ye(){let e=this.#be();return e===void 0?{}:{credentials:e}}#tt(e){return qe({headers:this.#oe(e)},this.#be())}get toolDisplay(){let e=this.getAttribute("data-tool-display");return e===yn.INLINE||e===yn.MINIMAL||e===yn.COMPACT?e:yn.FULL}set toolDisplay(e){this.setAttribute("data-tool-display",e)}connectedCallback(){if(this.#Q=this.#en(),this.#Fe(this.#ct()),requestAnimationFrame(()=>this.#He()),this.#e=Ma({...this.#Pt(),...this.strings}),this.getAttribute("data-theme-toggle")!==null){let e=this.#Ge(vp);e!==null&&this.setAttribute("theme",e)}if(this.#ln(),this.#$.setStrings(this.#e),this.#E.setStrings(this.#e),this.#Ge(mp)==="1"&&this.setAttribute("collapsed",""),this.#vt(),this.#Xt(),this.conversationStore instanceof je){let e=this.#ze();this.#ne=e===""?this.conversationStore:new je(e),this.conversationStore=this.#ne}this.#ot(),this.#Dt(),this.#Ht(),this.#h=this.conversationStore.threadId(),queueMicrotask(()=>this.#Lt()),this.#we(),this.#K=!0}#Lt(){this.#K&&(this.#it(),this.#st())}async reload(){this.#F(),this.#ie(),this.#X(!1),await Promise.all([this.#it(),this.#st(),this.#we()])}disconnectedCallback(){this.#K=!1,this.#ve!==null&&(El.delete(this.#ve),this.#ve=null),this.#F(),this.#Y?.detach(),this.#Y=null,this.#S?.dispose(),this.#ke?.dispose(),this.#g.dispose(),this.#G!==null&&(clearTimeout(this.#G),this.#G=null)}#nt(e){let n=this.getAttribute(e);return n!==null&&n!=="false"}#Pt(){let e=this.getAttribute("data-strings");if(e===null)return{};try{let n=JSON.parse(e);if(typeof n=="object"&&n!==null)return n}catch{}return{}}#Dt(){let e=this.getAttribute("data-attachments-url"),n=this.uploadHandler??this.#Ut(e);if(n===null)return;let r=this.getAttribute("data-attachment-accept")??"",o=new ki({upload:n,maxBytes:this.#jt(),accept:r,strings:this.#e,onChange:()=>this.#fn(o)});this.#S=o,this.#ue.appendChild(this.#S.element),this.#k.accept=r,this.#A.hidden=!1,this.#Wt()}#Ut(e){return e===null?null:(n,r,o)=>yl(n,{url:e,headers:this.#oe(e),...this.#ye(),onProgress:r,signal:o})}#Ht(){let e=this.getAttribute("data-transcribe-url"),n=this.transcribeHandler??this.#Ft(e);n!==null&&(this.#ke=new ji({transcribe:n,onText:r=>this.#zt(r),strings:this.#e}),this.#he.appendChild(this.#ke.element))}#Ft(e){return e===null?null:n=>bl(n,{url:e,headers:this.#oe(e),...this.#ye()})}#zt(e){let n=this.#l.value.trim();this.#l.value=n===""?e:`${n} ${e}`,this.#bt(),this.#l.focus()}quote(e){let n=$a(e);if(n==="")return;let r=this.#l.value.replace(/\s+$/,"");this.#l.value=r===""?n:`${r}
2661
2844
 
2662
- ${n}`,this.#Q(),this.#l.focus();let o=this.#l.value.length;this.#l.setSelectionRange(o,o)}offerQuoteInPage(e=document.body){this.#X?.detach();let n=Ga({within:e,label:this.#e.quoteSelection,exclude:this,onQuote:r=>this.quote(r)});return this.#X=n,()=>{n.detach(),this.#X===n&&(this.#X=null)}}#Ft(){return this.getAttribute("data-quote-selection")!=="false"}#nt(e){if(!this.#Ft())return;let n=e===void 0?void 0:{x:e.clientX,y:e.clientY},r=vr(this.#f,[this.#M],n);if(r===null){this.#Le();return}this.#_e=r.text,this.#Gt(r.rect)}#Gt(e){this.#v.hidden=!1;let n=this.#le.getBoundingClientRect(),r=e.top-n.top,o=r<bl+this.#v.offsetHeight;this.#v.dataset.below=String(o),this.#v.style.top=`${o?e.bottom-n.top+bl:r-bl}px`;let i=this.#v.offsetWidth/2,s=e.left+e.width/2-n.left;this.#v.style.left=`${Math.min(Math.max(s,i),n.width-i)}px`}#Le(){this.#v.hidden=!0,this.#_e=""}#$t(){let e=this.getAttribute("data-attachment-max-bytes");if(e===null)return Ss;let n=Number.parseInt(e,10);return Number.isFinite(n)&&n>=0?n:Ss}#Bt(){let e=this.#k.files;if(e!==null)for(let n of Array.from(e))this.#T?.add(n);this.#k.value=""}#Vt(){this.#y.addEventListener("dragover",e=>{e.preventDefault(),this.#y.classList.add("chat--dragover")}),this.#y.addEventListener("dragleave",()=>{this.#y.classList.remove("chat--dragover")}),this.#y.addEventListener("drop",e=>{e.preventDefault(),this.#y.classList.remove("chat--dragover");let n=e.dataTransfer?.files;if(n!==void 0)for(let r of Array.from(n))this.#T?.add(r)})}#rt(){let e=this.getAttribute("data-threads-url");e!==null&&(this.conversationStore=new Cr(e,()=>this.#re(e),this.conversationStore,()=>this.#ve(),this.getAttribute("data-threads-cache")!=="false"))}async#ot(){let e=this.getAttribute("data-tools-url");if(e!==null)try{let n=await fetch(e,this.#et(e));this.#t=Ca(await n.json())}catch{}}setSkills(e){this.#Ze=e,this.#Pe()}#jt(){this.#H.enableChips(this.#tt("data-prompt-chips")),this.#H.enableSlash(this.#tt("data-slash-commands")),this.#Ye=this.#qt(),this.#Pe()}#qt(){let e=this.getAttribute("data-skills");if(e===null)return[];try{return ma(JSON.parse(e))}catch{return[]}}async#it(){let e=this.getAttribute("data-skills-url");if(e!==null)try{let n=await fetch(e,this.#et(e));this.#Ke=ma(await n.json()),this.#Pe()}catch{}}#Pe(){let e=new Map;for(let n of[...this.#Ke,...this.#Ye,...this.#Ze])e.set(n.name,n);this.#H.setSkills([...e.values()])}#Wt(e){if(e.prompt===void 0){this.#R.hidden=!0,this.sendMessage(`/${e.name}`);return}let{text:n,missing:r}=Yd(e.prompt,this.skillContext());if(r.length>0){this.#R.textContent=this.#e.skillNeeds.replace("{title}",e.title).replace("{fields}",r.join(", ")),this.#R.hidden=!1,this.#l.value=n,this.#Q(),this.#l.focus(),this.#Xt(n);return}if(this.#R.hidden=!0,this.#l.value=n,this.#Q(),e.sendImmediately===!1){this.#l.focus();return}this.#$e()}#Xt(e){let n=e.indexOf("{");this.#l.setSelectionRange(n,e.indexOf("}",n)+1)}get collapsed(){return this.hasAttribute("collapsed")}set collapsed(e){this.setCollapsed(e)}setCollapsed(e){e?this.setAttribute("collapsed",""):this.removeAttribute("collapsed"),et(this.#ye(lp),e?"1":"0"),this.#Ee(0),this.dispatchEvent(new CustomEvent(hs,{detail:{collapsed:e},bubbles:!0,composed:!0}))}get unread(){return this.#ue}toggleCollapsed(){this.setCollapsed(!this.collapsed)}toggleTheme(){let e=this.getAttribute("theme")==="dark"?"light":"dark";this.setAttribute("theme",e),et(this.#ye(dp),e),this.#dt()}#De(){switch(this.getAttribute("placement")){case"full":case"page":return"none";case"sidebar":case"side":return"width";default:return"both"}}#st(){let e=this.getBoundingClientRect(),n=this.style.getPropertyValue("--ag-ui-width"),r=this.style.getPropertyValue("--ag-ui-height");this.#He({width:e.width+1,height:e.height+1});let o=this.getBoundingClientRect();return this.#at("--ag-ui-width",n),this.#at("--ag-ui-height",r),{x:Math.abs(o.left-e.left)<.5?"left":"right",y:Math.abs(o.top-e.top)<.5?"top":"bottom"}}#Ue(){if(!this.#K)return;let e=this.#st();this.setAttribute("data-resize-anchor",`${e.y}-${e.x}`)}#at(e,n){if(n===""){this.style.removeProperty(e);return}this.style.setProperty(e,n)}#He(e){let n=this.#De();n!=="none"&&(e.width!==void 0&&this.style.setProperty("--ag-ui-width",`${e.width}px`),e.height!==void 0&&n==="both"&&this.style.setProperty("--ag-ui-height",`${e.height}px`))}#Kt(){let e=this.#De();e!=="both"&&this.style.removeProperty("--ag-ui-height"),e==="none"&&this.style.removeProperty("--ag-ui-width")}#Yt(e){let n={...this.#lt(),...e};et(this.#ye(cp),JSON.stringify(n))}#lt(){let e=this.#Fe(cp);if(e===null)return{};try{let n=JSON.parse(e);return typeof n=="object"&&n!==null?n:{}}catch{return{}}}#Zt(){let e=this.id!==""?this.id:this.endpoint;return e===""?"":this.#Xe===e?this.#Ie:yl.has(e)?(this.#Xe=e,this.#Ie=`${e}~${_e()}`,console.warn(`<ag-ui-chat>: another element on this page already stores its conversation under "${e}", so this one has been given a throwaway namespace of its own \u2014 the two would otherwise share a thread pointer, a history drawer and every message. Give each <ag-ui-chat> its own id to keep them apart and let this one restore its conversation across reloads.`),this.#Ie):(yl.add(e),this.#ge=e,e)}#ze(e=this.userKey){return e===""?this.#Z:`${this.#Z}#${e}`}#Qt(e,n){let r=this.#ze(e),o=this.#ze(n);if(e===""){je.adopt(r,o),this.#ct(o);return}je.purge(r),this.#ct(o),this.#z(),this.#oe(),this.#W(!1),this.#Ee(0),this.#h=this.conversationStore.threadId(),this.#xe(),this.#ie()}#ct(e){this.#te!==null&&(this.#te=new je(e),this.conversationStore=this.#te,this.#rt())}#ye(e){return this.#Z===""?e:`${e}:${this.#Z}`}#Fe(e){let n=sessionStorage.getItem(this.#ye(e));return n!==null||this.#Z===""?n:sessionStorage.getItem(e)}#dt(){let e=this.getAttribute("theme")==="dark";this.#P.textContent=e?"\u2600\uFE0F":"\u{1F319}"}openThreads(){this.#w.close(),this.#ie(),this.#G.open()}openCheckpoints(){this.#G.close(),this.#kt(),this.#w.open()}closeCheckpoints(){this.#w.close()}toggleCheckpoints(){if(this.#w.open_){this.#w.close();return}this.openCheckpoints()}newChat(){this.#z(),this.conversationStore.isUnsent?.(this.#h)===!0&&this.conversationStore.clear(this.#h),this.#oe(),this.#h=ji(this.conversationStore),this.#W(!1),this.#Ee(0)}#oe(){this.#B=null,this.#ut(),this.#Ne=[]}#ut(){this.#ee(),this.#U=null,this.#q=null,this.#O(),this.#i.clear(),this.#u.clear(),this.#d.clear(),this.#a.clear(),this.#m=null,this.#T?.clear(),this.#f.replaceChildren(this.#$),this.#E()}async retryLastTurn(){if(this.#V)return!1;let e=this.#Be(),n=e.truncateToLastUser();if(n===null)return!1;this.#ut();for(let r of n)this.#ht(r);return await e.resume(),!0}async#Jt(e){e!==this.#h&&(this.#z(),this.#oe(),this.conversationStore.setActiveThread(e),this.#h=e,this.#W(!1),await this.#xe())}#en(e){let n=e===this.#h;n&&this.#z(),this.conversationStore.clear(e),n&&(this.#oe(),this.#h=this.conversationStore.threadId(),this.#W(!1)),this.#ie()}async#ie(){this.#G.setRelativeTimeFormatter(this.formatRelativeTime),this.#G.setThreads(await this.conversationStore.listThreads(),this.#h)}async#xe(){this.#Re+=1;let e=this.#Re,n=await this.conversationStore.loadMessages(this.#h);if(e!==this.#Re)return;if(n!==null){this.#Ne=n;for(let o of n)this.#ht(o)}let r=this.conversationStore.loadCheckpoint(this.#h);if(r!==null){await this.#on(r);return}this.#nn(n)}#pt(){return this.#ke=window.location.href,this.getContext()}#tn(){return this.#ke!==null&&this.#ke!==window.location.href}#nn(e){let n=e?.at(-1);n===void 0||n.role!==Fe.USER||this.#ae("\u26A0",this.#e.runInterrupted,"interrupted")}#ht(e){let n=typeof e.content=="string"?e.content:"";if(e.role===Fe.USER){let r=pl(e);if(n!==""||r.length>0){let o=this.appendMessage(Fe.USER,n);r.length>0&&o.appendChild(Ma(r))}return}if(e.role===Fe.ASSISTANT){if(n!==""){let r=this.appendMessage(Fe.ASSISTANT,n);r.classList.add("message--restored"),this.#Ve(r)}for(let r of qy(e.toolCalls)){let o={id:r.id,name:r.function.name,args:this.#rn(r.function.arguments)};if(this.#_t(o))continue;this.#d.set(o.id,this.#We(o).element);let i=this.#Me(o.name)?.render;i!==void 0&&this.#Tt(i,o)}return}if(e.role==="activity"){let r=e;typeof r.activityType=="string"&&this.#qe(e.id,r.activityType,r.content);return}if(e.role==="tool"){let r=this.#i.get(e.toolCallId);r!==void 0&&r.settle(ee.DONE,e.content)}}#rn(e){if(typeof e!="string")return{};try{let n=JSON.parse(e);if(typeof n=="object"&&n!==null)return n}catch{}return{}}#ft(e){this.getAttribute("data-text-animation")==="word"&&Zu(e)}async#on(e){this.conversationStore.saveCheckpoint(this.#h,null);let n=this.#Be();n.addToolResult(e.toolCallId,JSON.stringify(this.navigationResult(e))),await n.resume()}appendMessage(e,n){let r=document.createElement("div");return r.className=`message message--${e}`,r.setAttribute("part",`message message-${e}`),e===Fe.ASSISTANT?(r.innerHTML=Ui(n,{allowImages:this.allowImages}),Oa(r,this.#e),this.#I().appendChild(r)):(this.#U=null,r.textContent=n,this.#f.appendChild(r)),this.#E(),e===Fe.USER?this.#b.jump():this.#b.follow(),r}#I(){if(this.#U===null){let e=document.createElement("div");e.className="answer",e.setAttribute("part","answer"),this.#U=e,this.#f.appendChild(e),this.#E()}return this.#U}#in(){this.#y.className="chat",this.#y.setAttribute("part","panel");let e=document.createElement("div");e.className="header",e.setAttribute("part","header");let n=this.#Te;n.className="header-title",n.setAttribute("part","title"),n.textContent=this.getAttribute("title-text")??this.#e.title,(this.querySelector('[slot="icon"]')!==null||this.getAttribute("data-icon-url")!==null)&&e.append(this.#mt("icon","icon",null));let r=document.createElement("slot");r.name="header-actions";let o=document.createElement("div");o.className="header-controls",o.setAttribute("part","header-controls");let i=this.#we("history",this.#e.chatHistory,"\u2630");i.addEventListener("click",()=>this.openThreads());let s=this.#we("checkpoints",this.#e.checkpoints,"\u21BA");s.addEventListener("click",()=>this.toggleCheckpoints());let a=this.#we("new",this.#e.newChat,"\u271A");a.addEventListener("click",()=>this.newChat());let l=this.#we("collapse",this.#e.collapse,"\u2014");l.addEventListener("click",()=>this.toggleCollapsed()),this.#Oe()!==null?o.append(i,s,a):o.append(i,a),this.getAttribute("data-theme-toggle")!==null&&(this.#P.type="button",this.#P.className="header-btn header-btn--theme",this.#P.setAttribute("part","header-button theme-toggle"),this.#P.title=this.#e.toggleTheme,this.#P.setAttribute("aria-label",this.#e.toggleTheme),this.#P.addEventListener("click",()=>this.toggleTheme()),this.#dt(),o.append(this.#P)),o.append(l),e.append(n,r,o),this.#f.className="messages",this.#f.setAttribute("part","messages"),this.#f.setAttribute("role","log"),this.#f.setAttribute("aria-live","off"),this.#f.setAttribute("aria-label",this.#e.conversation),this.#L.className="jump-latest",this.#L.type="button",this.#L.setAttribute("part","jump-latest"),this.#L.textContent=this.#e.jumpToLatest,this.#L.addEventListener("click",()=>{this.#b.jump()}),this.#v.className="quote-selection",this.#v.type="button",this.#v.setAttribute("part","quote-selection"),this.#v.textContent=this.#e.quoteSelection,this.#v.hidden=!0,this.#v.addEventListener("mousedown",h=>{h.preventDefault()}),this.#v.addEventListener("click",()=>{this.quote(this.#_e),window.getSelection()?.removeAllRanges(),this.#Le()}),this.#f.addEventListener("mouseup",h=>this.#nt(h)),this.#f.addEventListener("keyup",()=>this.#nt()),this.#f.addEventListener("mousedown",()=>this.#Le()),this.#b=Qu({viewport:this.#f,onMissedContent:h=>{this.#L.dataset.missed=String(h)}}),this.#g.className="sr-only",this.#g.setAttribute("role","status"),this.#g.setAttribute("aria-live","polite"),this.#g.setAttribute("aria-atomic","true"),this.#$.className="empty",this.#$.setAttribute("part","empty");let c=document.createElement("slot");c.name="empty",this.#$.append(c),this.#f.append(this.#$);let u=document.createElement("div");u.className="input-row",u.setAttribute("part","composer");let m=document.createElement("div");m.className="composer",m.setAttribute("part","composer-surface");let y=document.createElement("div");y.className="composer-tools",y.setAttribute("part","composer-tools"),this.#l.className="input",this.#l.setAttribute("part","input"),this.#l.setAttribute("aria-label",this.#e.message),this.#l.rows=1,this.#l.placeholder=this.#e.inputPlaceholder,this.#l.addEventListener("keydown",h=>this.#dn(h)),this.#l.addEventListener("input",()=>this.#vt()),this.#x.className="send",this.#x.type="button",this.#x.setAttribute("part","send"),this.#x.append(this.#Ge("icon-send","send-send",Xl),this.#Ge("icon-stop","send-stop",Kl)),this.#x.title=this.#e.send,this.#x.setAttribute("aria-label",this.#e.send),this.#x.dataset.state="idle",this.#x.addEventListener("click",()=>{if(this.#V){this.#z();return}this.#$e()}),this.#R.className="skill-hint",this.#R.setAttribute("part","skill-hint"),this.#R.hidden=!0,this.#A.className="attach-btn",this.#A.type="button",this.#A.setAttribute("part","attach-button"),this.#A.append(this.#Ge("icon-attach","attach-glyph",Yl)),this.#A.title=this.#e.attachFiles,this.#A.setAttribute("aria-label",this.#e.attachFiles),this.#A.hidden=!0,this.#A.addEventListener("click",()=>this.#k.click()),this.#k.className="attach-input",this.#k.type="file",this.#k.multiple=!0,this.#k.hidden=!0,this.#k.addEventListener("change",()=>this.#Bt()),this.#de.className="attachment-slot",this.#pe.className="voice-slot";let f=document.createElement("slot");f.name="footer",y.append(this.#A,this.#pe,this.#x),m.append(this.#l,y),u.append(m,this.#k),this.#le.className="messages-wrap",this.#le.append(this.#f,this.#L,this.#v),this.#y.append(e,this.#le,this.#H.palette,this.#H.chips,this.#R,this.#de,u,f,this.#G.element,this.#w.element),this.#y.addEventListener("pointerdown",h=>{if(!this.#w.open_)return;let g=h.composedPath();g.includes(this.#w.element)||g.includes(s)||this.#w.close()}),this.#C.className="launcher",this.#C.type="button",this.#C.setAttribute("part","launcher"),this.#C.setAttribute("aria-label",this.#e.expand),this.#D.className="launcher-badge",this.#D.setAttribute("part","launcher-badge"),this.#D.setAttribute("aria-hidden","true"),this.#D.hidden=!0,this.#C.append(this.#mt("launcher","launcher-icon",Ql,this.#an()),this.#D),this.#C.addEventListener("click",()=>this.setCollapsed(!1)),this.#y.append(Ku({axis:()=>this.#De(),anchor:()=>this.#st(),rect:()=>this.getBoundingClientRect(),apply:h=>this.#He(h),commit:h=>{this.#Yt(h),this.#Ue()},label:this.#e.resizePanel})),this.#sn(),this.#M.append(this.#g,this.#y,this.#C)}#se(e){this.#F!==null&&clearTimeout(this.#F),this.#g.textContent=e,this.#F=setTimeout(()=>{this.#F=null,this.#g.textContent=""},rc)}#sn(){let e=new CSSStyleSheet;e.replaceSync(Ju),this.#M.adoptedStyleSheets=[e]}#we(e,n,r){let o=document.createElement("button");o.type="button",o.className=`header-btn header-btn--${e}`,o.setAttribute("part",`header-button ${e}-button`),o.title=n,o.setAttribute("aria-label",n);let i=document.createElement("slot");return i.name=`icon-${e}`,i.append(document.createTextNode(r)),o.append(i),o}#Ge(e,n,r){let o=document.createElement("slot");return o.name=e,o.className=n,o.innerHTML=r,o}#an(){return this.getAttribute("data-launcher-icon-url")??this.getAttribute("data-icon-url")}#mt(e,n,r,o=this.getAttribute("data-icon-url")){let i=document.createElement("span");i.className="icon-holder",i.setAttribute("part",n);let s=document.createElement("slot");if(s.name=e,o!==null){let a=document.createElement("img");a.className="icon-img",a.src=o,a.alt="",s.append(a)}else r!==null&&(s.innerHTML=r);return i.append(s),i}#gt(){this.#C.setAttribute("aria-expanded",String(!this.collapsed));let e=this.#ue;this.#D.textContent=e>9?"9+":String(e),this.#D.hidden=e===0||!this.#ln();let n=this.#D.hidden?this.#e.expand:this.#e.expandUnread.replace("{count}",String(e));this.#C.setAttribute("aria-label",n),this.#C.title=n}#ln(){return this.getAttribute("data-unread-badge")!=="false"}#Ee(e){this.#ue=e,this.#gt(),this.dispatchEvent(new CustomEvent(fs,{detail:{unread:e},bubbles:!0,composed:!0}))}#cn(){this.collapsed&&this.#Ee(this.#ue+1)}#E(){this.#$.hidden=this.#f.childElementCount>1}#vt(){this.#H.onInput(this.#l.value),this.#R.hidden=!0,this.#Q()}#dn(e){if(this.#H.onKeydown(e)){e.preventDefault();return}if(e.key==="Escape"&&this.#V){e.preventDefault(),this.#z();return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),this.#$e())}#z(){this.#N?.abort(),this.#B?.cancel()}#W(e){this.#V=e;let n=e?this.#e.stop:this.#e.send;this.#x.title=n,this.#x.setAttribute("aria-label",n),this.#x.dataset.state=e?"running":"idle"}#Q(){this.#l.style.height="auto",this.#l.style.height=`${this.#l.scrollHeight}px`}async#$e(){if(this.#V)return;let e=this.#l.value.trim(),n=this.#T?.readyRefs()??[];e===""&&n.length===0||(this.#l.value="",this.#Q(),this.#T?.hasPending()===!0&&this.#ae("\u{1F4CE}",this.#e.attachmentsStillUploading.replace("{n}",String(this.#T.pendingCount())),"attachment-pending"),this.#T?.clearReady(),await this.sendMessage(e,n))}async sendMessage(e,n=[]){if(this.#V||e===""&&n.length===0)return;let r=this.appendMessage(Fe.USER,e);n.length>0&&r.appendChild(Ma(n)),this.dispatchEvent(new CustomEvent(ps,{detail:{content:e,attachments:n},bubbles:!0,composed:!0})),await this.#pn(e,n)}attachFile(e){return this.#T===null?!1:(this.#T.add(e),!0)}#un(e){this.dispatchEvent(new CustomEvent(gs,{detail:{attachments:e.readyRefs(),pending:e.pendingCount()},bubbles:!0,composed:!0}))}async#pn(e,n){this.endpoint!==""&&await this.#Be().send(e,n)}#Be(){if(this.#B===null){let e=this.agentFactory({endpoint:this.endpoint,headers:this.#ne(),getHeaders:()=>this.#ne(),trustedOrigins:this.trustedOrigins,...this.#be(),threadId:this.#h,initialMessages:this.#Ne,initialState:this.#Y});this.#B=new Gn({agent:e,handlers:this.#xt(),getTools:()=>this.#Je(),getContext:()=>this.#pt(),executeTool:n=>this.#bt(n),resolveInterrupts:n=>this.#yt(n),onPersist:n=>this.conversationStore.saveMessages(this.#h,n),onStateChanged:n=>this.#hn(n),connectionLostMessage:this.#e.connectionLost})}return this.#B}#hn(e){this.#Y={...e},this.dispatchEvent(new CustomEvent(ms,{detail:{state:this.#Y},bubbles:!0,composed:!0}))}#Ve(e,n={}){Ha(e,{strings:this.#e,text:()=>e.textContent,...n.rateable===!1?{}:{onFeedback:r=>{this.dispatchEvent(new CustomEvent(xs,{detail:{content:e.textContent,rating:r},bubbles:!0,composed:!0}))}}}),this.#fn(Ci(e,this.#e))}#fn(e){this.#m?.querySelector(".message-action--retry")?.remove();let n=Ii("retry",this.#e.retryMessage,"\u21BB");n.addEventListener("click",()=>{this.retryLastTurn()}),e.prepend(n),this.#m=e}async#mn(e,n){return this.autoConfirm?null:this.confirmPredicate!==null?await this.confirmPredicate(e.name,e.args)===!0?"predicate":null:this.#S.has(e.name)?null:ga(n.parameters)?"destructive":null}async#bt(e){if(up(e)!==null)return null;let n=this.#We(e);this.#i.delete(e.id),this.#d.set(e.id,n.element);let r=this.#s.has(e.name)?this.#Me(e.name):null;if(r===null)return this.#u.has(e.id)||n.settle(ee.DONE,this.#e.noResult),null;if(this.getPageMap!==null&&e.name!==_s&&!bi(r.parameters)&&this.#tn()){let s=this.#e.pageMoved;return n.settle(ee.ERROR,s),this.#J(),{content:`Error: ${s}`,error:s}}let o=await this.#mn(e,r);if(o!==null){let s={toolName:e.name,args:e.args},a=r.parameters[Vr];typeof a=="string"&&(s.message=a),this.#N=new AbortController;let l=Ua(this.#I(),s,{signal:this.#N.signal,strings:this.#e,...o==="destructive"?{onAlwaysAllow:()=>this.#S.add(e.name)}:{}});this.#E(),this.#b.follow();let c=await l;if(this.#N=null,n.recordDecision(c?"approved":"declined"),!c){let u=this.#e.declinedAction;return n.settle(ee.DECLINED,u),this.#J(),{content:u}}}let i=bi(r.parameters)&&this.navigate===null;i&&this.conversationStore.saveCheckpoint(this.#h,{toolCallId:e.id});try{let s=await r.handler(e.args,e.id);if(r.render!==void 0&&this.#Tt(r.render,e),i)return n.settle(ee.DONE,this.#e.navigating),{content:"",halt:!0};let a=JSON.stringify(s??null);return n.settle(ee.DONE,a),this.#J(),{content:a}}catch(s){i&&this.conversationStore.saveCheckpoint(this.#h,null);let a=s instanceof Error?s.message:String(s);return n.settle(ee.ERROR,a),this.#J(),{content:`Error: ${a}`,error:a}}}async#yt(e){this.#N=new AbortController,this.#se(this.#e.announceAwaitingDecision.replace("{count}",String(e.length))),this.#O();let n=this.#N.signal,r=await Promise.all(e.map(async i=>{let s=i.toolCallId!==void 0?this.#i.get(i.toolCallId):void 0,a={},l=jy(i)??i.message;l!==void 0&&(a.message=l);let c=s?.element.getAttribute("data-tool-name");c!=null&&(a.toolName=c);let u,m=this.approveWithEdits&&s!==void 0;m&&(a.args=s.args),s?.mark(ee.DEFERRED);let y=this.approvalRenderer!==null?await this.approvalRenderer(a,{signal:n}):await Na(s?.approvalSlot??this.#I(),a,{signal:n,strings:this.#e,...m?{onEdit:f=>{u=f}}:{}});return s?.recordDecision(y?"approved":"declined"),y?s?.mark(ee.PENDING):s?.settle(ee.DECLINED,this.#e.declinedAction),{id:i.id,approved:y,editedArgs:u}}));this.#E(),this.#b.follow(),this.#N=null;let o={};for(let{id:i,approved:s,editedArgs:a}of r)o[i]=s?{status:"resolved",payload:a===void 0?{approved:!0}:{approved:!0,editedArgs:a}}:{status:"cancelled"};return o}#xt(){return{onRunStart:()=>{this.#V||(this.#ce=!1,this.#se(this.#e.announceResponding)),this.#W(!0),this.#I(),this.#J()},onReasoningStart:()=>{this.#O(),this.#wt()},onReasoningDelta:e=>{this.#wt().stream(e)},onReasoningEnd:()=>{},onTextDelta:e=>{this.#O(),this.#q?.collapse(),this.#yn(e),this.#Ce+=1},onTextEnd:e=>{let n=this.#je(e);this.#Ce<=1&&this.#ft(n),Oa(n,this.#e),this.#Ve(n),this.#ee(),this.#cn()},onToolCall:e=>{this.#O(),!this.#_t(e)&&(this.#p.push({id:e.id,name:e.name}),this.#We(e))},onActivity:(e,n,r)=>{this.#qe(r,e,n)},onCustomEvent:(e,n)=>{if(e===Es){this.#vn(n);return}this.dispatchEvent(new CustomEvent(bs,{detail:{name:e,value:n},bubbles:!0,composed:!0}))},onMessagesSnapshot:()=>{this.#ae("\u{1F504}",this.#e.historyReplaced,"history-replaced")},onToolResult:(e,n)=>{let r=this.#i.get(e);r!==void 0&&(r.settle(ee.DONE,n),this.#u.add(e),this.#J())},onActivityChanged:(e,n,r)=>{this.#qe(e,n,r)},onRunEnd:()=>{this.#O(),this.#ee()},onError:e=>{this.#ce=!0,this.#se(this.#e.announceFailed),this.#O();let n=this.appendMessage(Fe.ASSISTANT,`\u26A0\uFE0F ${e}`);n.classList.add("message--failed"),this.#Ve(n,{rateable:!1}),this.#ft(n),this.#ee()},onCancelled:()=>{this.#ce=!0,this.#se(this.#e.announceStopped),this.#O(),this.#bn(),this.#ee()},onSettled:()=>{this.#ce||this.#se(this.#e.announceAnswerReady),this.#O(),this.#W(!1),this.#ee();for(let e of this.#i.values())e.settled||e.settle(ee.DONE,this.#e.noResult);this.#U!==null&&this.#U.childElementCount===0&&(this.#U.remove(),this.#E()),this.#U=null,this.#q=null,this.#gn()}}}#gn(){let e=this.#p.map(({id:r,name:o})=>({name:o,side:this.#u.has(r)?"server":"client"}));this.#p=[];let n=[...this.#_];this.#_=new Set,this.dispatchEvent(new CustomEvent(vs,{detail:{tools:e,invalidated:n},bubbles:!0,composed:!0}))}#vn(e){let n=e??{},r=Array.isArray(n.keys)?n.keys.filter(o=>typeof o=="string"):[];if(r.length!==0){for(let o of r)this.#_.add(o);this.dispatchEvent(new CustomEvent(ys,{detail:{keys:r,reason:typeof n.reason=="string"?n.reason:null},bubbles:!0,composed:!0}))}}#bn(){let e=document.createElement("div");e.className="stopped-note",e.setAttribute("part","stopped"),e.setAttribute("role","status"),e.textContent=this.#e.stopped,this.#I().appendChild(e),this.#E(),this.#b.follow()}#J(){if(this.#me!==null)return;let e=document.createElement("div");e.className="pending",e.setAttribute("part","pending"),e.setAttribute("role","status"),e.setAttribute("aria-label",this.#e.thinking);for(let n=0;n<3;n+=1){let r=document.createElement("span");r.className="pending-dot",e.appendChild(r)}this.#me=e,this.#I().appendChild(e),this.#E(),this.#b.follow()}#O(){this.#me?.remove(),this.#me=null}#wt(){if(this.#q===null){this.#q=new zi(this.#e);let e=this.#I();e.insertBefore(this.#q.element,e.firstChild),this.#E(),this.#b.follow()}return this.#q}#Et(){return this.#he===null&&(this.#he=this.appendMessage(Fe.ASSISTANT,""),this.#Ce=0),this.#he}#yn(e){this.#fe=e,this.#Et(),this.#j===null&&(this.#j=requestAnimationFrame(()=>{this.#j=null,this.#je(this.#fe)}))}#je(e){this.#j!==null&&(cancelAnimationFrame(this.#j),this.#j=null),this.#fe=e;let n=this.#Et();return n.innerHTML=Ui(e,{allowImages:this.allowImages}),this.#b.follow(),n}#ee(){this.#j!==null&&this.#je(this.#fe),this.#he=null}#_t(e){let n=up(e);return n===null?!1:(this.#ae("\u2728",this.#e.usingSkill.replace("{name}",n),"skill"),!0)}#ae(e,n,r){this.#I().appendChild(cl(e,n,r)),this.#E(),this.#b.follow()}enableCharts(e=["tool","activity"]){let n=!this.#o.has(jr)&&!this.#n.has(ki);e.includes("activity")&&this.registerActivityRenderer({type:jr,render:r=>{let o=Pn(r);return o===null?null:fr(o)},removedNotice:this.#e.chartUndrawable}),e.includes("tool")&&this.registerTool(ru()),n&&this.isConnected&&this.reload()}#Tt(e,n){let r;try{r=e(n.args)}catch(o){console.warn(`ag-ui-chat: render failed for tool ${n.name}`,o);return}r!==null&&(this.#d.get(n.id)?.after(r),this.#St())}registerActivityRenderer(e){this.#o.set(e.type,e),this.#c.delete(e.type)}get unhandledActivityTypes(){return[...this.#c]}#qe(e,n,r){let o=this.#o.get(n);if(o===void 0){this.#c.add(n);return}let i;try{i=o.render(r)}catch(a){console.warn(`ag-ui-chat: render failed for activity ${n}`,a),i=null}if(i===null){this.#xn(e,n,o.removedNotice,r);return}let s=this.#a.get(e);s===void 0?this.#I().appendChild(i):s.replaceWith(i),this.#a.set(e,i),this.#St()}#xn(e,n,r,o){let i=this.#a.has(e);this.#a.get(e)?.remove(),this.#a.delete(e),console.warn(`ag-ui-chat: activity ${e} (${n}) was not drawable and has been removed. A chart's points must each be a finite JSON number; a numeric column serialised as a string (a Decimal, typically) is rejected rather than coerced.`,o),i&&r!==void 0&&this.#ae("\u{1F4C9}",r,"chart-undrawable")}#St(){this.#E(),this.#b.follow()}#We(e){let n=this.#i.get(e.id);if(n!==void 0)return n;let r=this.#Me(e.name)?.parameters[Pe],o=typeof r=="string"?r:this.toolSummaries[e.name]??this.#t[e.name]?.summary??$a(e.name),i=new Sr(e.name,e.args,o,this.#e);return this.#i.set(e.id,i),this.#I().appendChild(i.element),this.#E(),this.#b.follow(),i}};function jy(t){let e=t.metadata?.[Vr];return typeof e=="string"&&e.trim()!==""?e:void 0}function qy(t){return Array.isArray(t)?t.filter(Wy):[]}function Wy(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.id=="string"&&typeof e.function?.name=="string"}function up(t){if(t.name!==ks)return null;let e=t.args?.id;return typeof e=="string"&&e!==""?e:null}function Xy(t){let e=t?.removed;return typeof e=="number"?e:null}function Ky(){customElements.get(Br)===void 0&&customElements.define(Br,Rr)}async function Yy(t,e,n={}){await vt(t),await wa(t,{...n,flashMs:n.flashMs??0}),await ya(t,e,n)}async function Zy(t,e={}){await vt(t),await xa(t,e)}async function Qy(t,e={}){await vt(t),await Ea(t,e)}async function Jy(t,e,n={}){await vt(t),await _a(t,e,n)}async function ex(t,e,n={}){await vt(t),await Ta(t,e,n)}function tx(t,e){t instanceof HTMLInputElement&&t.type==="checkbox"?ur(t,!!e):rn(t,String(e)),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0}))}var nx="0.29.0";export{gs as ATTACHMENT_EVENT,Rr as AgUiChat,Gn as AgUiClient,jr as CHART_ACTIVITY_TYPE,ki as CHART_TOOL_NAME,As as COMPACTION_ACTIVITY_TYPE,bs as CUSTOM_AGENT_EVENT,gr as CheckpointMenu,dr as ClientToolRegistry,$i as ConnectionLostError,le as DEFAULT_UI_STRINGS,Br as ELEMENT_TAG,xs as FEEDBACK_EVENT,Es as INVALIDATE_CUSTOM_NAME,ys as INVALIDATE_EVENT,ks as LOAD_CAPABILITY_TOOL,Mv as MAX_QUOTE_CHARS,Ry as MAX_SUGGESTIONS,Ny as MAX_SUGGESTION_CHARS,Ts as MAX_TOOL_ROUNDS,Fe as MESSAGE_ROLE,Sa as PAGE_ACTIONS,vs as RUN_FINISHED_EVENT,Cr as RemoteConversationStore,Ir as RunIndex,ms as STATE_EVENT,ps as SUBMIT_EVENT,ws as SUGGESTIONS_ACTIVITY_TYPE,je as SessionStorageStore,hs as TOGGLE_EVENT,ee as TOOL_CALL_STATUS,vn as TOOL_DISPLAY,Sr as ToolCallCard,fs as UNREAD_EVENT,nx as VERSION,Vr as X_CONFIRM_KEY,Xn as X_DESTRUCTIVE_KEY,Kn as X_NAVIGATES_KEY,Pe as X_SUMMARY_KEY,za as asQuote,Ha as attachMessageActions,Ga as attachQuoteOffer,Pn as chartSpecFrom,Zy as clickElement,fl as createHttpAgent,Aa as createPageActionTools,ka as createPageMapContext,Ei as createPageStateTools,Ia as createRouteTools,iv as createStateHookTools,Ky as defineAgUiChat,Yy as fillField,ev as flash,wa as focusWithFlash,xa as highlightThenClick,ga as isDestructive,bi as isNavigates,Ra as mergeUiStrings,Ci as messageActionBar,pl as messageAttachments,Ca as parseToolCatalog,xi as prefersReducedMotion,Qy as pressButton,Ea as pressThenClick,$a as prettifyToolName,vr as quotableSelection,mr as relativeTime,fr as renderChart,Ui as renderMarkdown,dl as renderSuggestionChips,Na as requestApproval,Ua as requestConfirmation,Ba as requestQuestion,vt as scrollIntoCenterView,Jy as selectControl,_a as selectOption,tx as setControlValue,ur as setNativeChecked,rn as setNativeValue,ep as suggestionPrompts,ex as toggleCheckbox,Ta as toggleControl,ml as transcribeAudio,ya as typeInto,gl as uploadAttachment};
2845
+ ${n}`,this.#J(),this.#l.focus();let o=this.#l.value.length;this.#l.setSelectionRange(o,o)}offerQuoteInPage(e=document.body){this.#Y?.detach();let n=Va({within:e,label:this.#e.quoteSelection,exclude:this,onQuote:r=>this.quote(r)});return this.#Y=n,()=>{n.detach(),this.#Y===n&&(this.#Y=null)}}#Gt(){return this.getAttribute("data-quote-selection")!=="false"}#rt(e){if(!this.#Gt())return;let n=e===void 0?void 0:{x:e.clientX,y:e.clientY},r=yr(this.#f,[this.#T],n);if(r===null){this.#Pe();return}this.#Te=r.text,this.#$t(r.rect)}#$t(e){this.#b.hidden=!1;let n=this.#ce.getBoundingClientRect(),r=e.top-n.top,o=r<wl+this.#b.offsetHeight;this.#b.dataset.below=String(o),this.#b.style.top=`${o?e.bottom-n.top+wl:r-wl}px`;let i=this.#b.offsetWidth/2,s=e.left+e.width/2-n.left;this.#b.style.left=`${Math.min(Math.max(s,i),n.width-i)}px`}#Pe(){this.#b.hidden=!0,this.#Te=""}#Bt(){let e=this.getAttribute("data-max-tool-rounds");return e===null?vn:Number.parseInt(e,10)}#Vt(){let e=this.getAttribute("data-message-actions");return e===null?new Set(Object.values(bn)):new Set(e.split(",").map(n=>n.trim()).filter(n=>n!==""))}#jt(){let e=this.getAttribute("data-attachment-max-bytes");if(e===null)return Cs;let n=Number.parseInt(e,10);return Number.isFinite(n)&&n>=0?n:Cs}#qt(){let e=this.#k.files;if(e!==null)for(let n of Array.from(e))this.#S?.add(n);this.#k.value=""}#Wt(){this.#x.addEventListener("dragover",e=>{e.preventDefault(),this.#x.classList.add("chat--dragover")}),this.#x.addEventListener("dragleave",()=>{this.#x.classList.remove("chat--dragover")}),this.#x.addEventListener("drop",e=>{e.preventDefault(),this.#x.classList.remove("chat--dragover");let n=e.dataTransfer?.files;if(n!==void 0)for(let r of Array.from(n))this.#S?.add(r)})}#ot(){let e=this.getAttribute("data-threads-url");e!==null&&(this.conversationStore=new Nr(e,()=>this.#oe(e),this.conversationStore,()=>this.#be(),this.getAttribute("data-threads-cache")!=="false"))}async#it(){let e=this.getAttribute("data-tools-url");if(e!==null)try{let n=await fetch(e,this.#tt(e));this.#t=Na(await n.json())}catch{}}setSkills(e){this.#Qe=e,this.#De()}#Xt(){this.#H.enableChips(this.#nt("data-prompt-chips")),this.#H.enableSlash(this.#nt("data-slash-commands")),this.#Ze=this.#Yt(),this.#De()}#Yt(){let e=this.getAttribute("data-skills");if(e===null)return[];try{return ba(JSON.parse(e))}catch{return[]}}async#st(){let e=this.getAttribute("data-skills-url");if(e!==null)try{let n=await fetch(e,this.#tt(e));this.#Ke=ba(await n.json()),this.#De()}catch{}}#De(){let e=new Map;for(let n of[...this.#Ke,...this.#Ze,...this.#Qe])e.set(n.name,n);this.#H.setSkills([...e.values()])}#Kt(e){if(e.prompt===void 0){this.#R.hidden=!0,this.sendMessage(`/${e.name}`);return}let{text:n,missing:r}=tu(e.prompt,this.skillContext());if(r.length>0){this.#R.textContent=this.#e.skillNeeds.replace("{title}",e.title).replace("{fields}",r.join(", ")),this.#R.hidden=!1,this.#l.value=n,this.#J(),this.#l.focus(),this.#Zt(n);return}if(this.#R.hidden=!0,this.#l.value=n,this.#J(),e.sendImmediately===!1){this.#l.focus();return}this.#Be()}#Zt(e){let n=e.indexOf("{");this.#l.setSelectionRange(n,e.indexOf("}",n)+1)}get collapsed(){return this.hasAttribute("collapsed")}set collapsed(e){this.setCollapsed(e)}setCollapsed(e){e?this.setAttribute("collapsed",""):this.removeAttribute("collapsed"),et(this.#xe(mp),e?"1":"0"),this.#_e(0),this.dispatchEvent(new CustomEvent(vs,{detail:{collapsed:e},bubbles:!0,composed:!0}))}get unread(){return this.#pe}toggleCollapsed(){this.setCollapsed(!this.collapsed)}toggleTheme(){let e=this.getAttribute("theme")==="dark"?"light":"dark";this.setAttribute("theme",e),et(this.#xe(vp),e),this.#ut()}#Ue(){switch(this.getAttribute("placement")){case"full":case"page":return"none";case"sidebar":case"side":return"width";default:return"both"}}#at(){let e=this.getBoundingClientRect(),n=this.style.getPropertyValue("--ag-ui-width"),r=this.style.getPropertyValue("--ag-ui-height");this.#Fe({width:e.width+1,height:e.height+1});let o=this.getBoundingClientRect();return this.#lt("--ag-ui-width",n),this.#lt("--ag-ui-height",r),{x:Math.abs(o.left-e.left)<.5?"left":"right",y:Math.abs(o.top-e.top)<.5?"top":"bottom"}}#He(){if(!this.#K)return;let e=this.#at();this.setAttribute("data-resize-anchor",`${e.y}-${e.x}`)}#lt(e,n){if(n===""){this.style.removeProperty(e);return}this.style.setProperty(e,n)}#Fe(e){let n=this.#Ue();n!=="none"&&(e.width!==void 0&&this.style.setProperty("--ag-ui-width",`${e.width}px`),e.height!==void 0&&n==="both"&&this.style.setProperty("--ag-ui-height",`${e.height}px`))}#Qt(){let e=this.#Ue();e!=="both"&&this.style.removeProperty("--ag-ui-height"),e==="none"&&this.style.removeProperty("--ag-ui-width")}#Jt(e){let n={...this.#ct(),...e};et(this.#xe(gp),JSON.stringify(n))}#ct(){let e=this.#Ge(gp);if(e===null)return{};try{let n=JSON.parse(e);return typeof n=="object"&&n!==null?n:{}}catch{return{}}}#en(){let e=this.id!==""?this.id:this.endpoint;return e===""?"":this.#Ye===e?this.#Re:El.has(e)?(this.#Ye=e,this.#Re=`${e}~${_e()}`,console.warn(`<ag-ui-chat>: another element on this page already stores its conversation under "${e}", so this one has been given a throwaway namespace of its own \u2014 the two would otherwise share a thread pointer, a history drawer and every message. Give each <ag-ui-chat> its own id to keep them apart and let this one restore its conversation across reloads.`),this.#Re):(El.add(e),this.#ve=e,e)}#ze(e=this.userKey){return e===""?this.#Q:`${this.#Q}#${e}`}#tn(e,n){let r=this.#ze(e),o=this.#ze(n);if(e===""){je.adopt(r,o),this.#dt(o);return}je.purge(r),this.#dt(o),this.#F(),this.#ie(),this.#X(!1),this.#_e(0),this.#h=this.conversationStore.threadId(),this.#we(),this.#se()}#dt(e){this.#ne!==null&&(this.#ne=new je(e),this.conversationStore=this.#ne,this.#ot())}#xe(e){return this.#Q===""?e:`${e}:${this.#Q}`}#Ge(e){let n=sessionStorage.getItem(this.#xe(e));return n!==null||this.#Q===""?n:sessionStorage.getItem(e)}#ut(){let e=this.getAttribute("theme")==="dark";this.#L.textContent=e?"\u2600\uFE0F":"\u{1F319}"}openThreads(){this.#E.close(),this.#se(),this.#$.open()}openCheckpoints(){this.#$.close(),this.#Ct(),this.#E.open()}closeCheckpoints(){this.#E.close()}toggleCheckpoints(){if(this.#E.open_){this.#E.close();return}this.openCheckpoints()}newChat(){this.#F(),this.conversationStore.isUnsent?.(this.#h)===!0&&this.conversationStore.clear(this.#h),this.#ie(),this.#h=Yi(this.conversationStore),this.#X(!1),this.#_e(0)}#ie(){this.#V=null,this.#pt(),this.#Oe=[]}#pt(){this.#te(),this.#D=null,this.#W=null,this.#O(),this.#i.clear(),this.#o.clear(),this.#p.clear(),this.#d.clear(),this.#a.clear(),this.#y=null,this.#S?.clear(),this.#f.replaceChildren(this.#B),this.#_()}async retryLastTurn(){if(this.#j)return!1;let e=this.#Ve(),n=e.truncateToLastUser();if(n===null)return!1;this.#pt();for(let r of n)this.#ft(r);return await e.resume(),!0}async#nn(e){e!==this.#h&&(this.#F(),this.#ie(),this.conversationStore.setActiveThread(e),this.#h=e,this.#X(!1),await this.#we())}#rn(e){let n=e===this.#h;n&&this.#F(),this.conversationStore.clear(e),n&&(this.#ie(),this.#h=this.conversationStore.threadId(),this.#X(!1)),this.#se()}async#se(){this.#$.setRelativeTimeFormatter(this.formatRelativeTime),this.#$.setThreads(await this.conversationStore.listThreads(),this.#h)}async#we(){this.#Ne+=1;let e=this.#Ne,n=await this.conversationStore.loadMessages(this.#h);if(e!==this.#Ne)return;if(n!==null){this.#Oe=n;for(let o of n)this.#ft(o)}let r=this.conversationStore.loadCheckpoint(this.#h);if(r!==null){await this.#an(r);return}this.#in(n)}#ht(){return this.#Ce=window.location.href,this.getContext()}#on(){return this.#Ce!==null&&this.#Ce!==window.location.href}#in(e){let n=e?.at(-1);n===void 0||n.role!==ze.USER||this.#le("\u26A0",this.#e.runInterrupted,"interrupted")}#ft(e){let n=typeof e.content=="string"?e.content:"";if(e.role===ze.USER){let r=ml(e);if(n!==""||r.length>0){let o=this.appendMessage(ze.USER,n);r.length>0&&o.appendChild(Da(r))}return}if(e.role===ze.ASSISTANT){if(n!==""){let r=this.appendMessage(ze.ASSISTANT,n);r.classList.add("message--restored"),this.#je(r)}for(let r of tx(e.toolCalls)){let o={id:r.id,name:r.function.name,args:this.#sn(r.function.arguments)};if(this.#Tt(o))continue;this.#d.set(o.id,this.#Xe(o).element);let i=this.#Le(o.name)?.render;i!==void 0&&this.#St(i,o)}return}if(e.role==="activity"){let r=e;typeof r.activityType=="string"&&this.#We(e.id,r.activityType,r.content);return}if(e.role==="tool"){let r=this.#i.get(e.toolCallId);r!==void 0&&r.settle(te.DONE,e.content)}}#sn(e){if(typeof e!="string")return{};try{let n=JSON.parse(e);if(typeof n=="object"&&n!==null)return n}catch{}return{}}#mt(e){this.getAttribute("data-text-animation")==="word"&&np(e)}async#an(e){this.conversationStore.saveCheckpoint(this.#h,null);let n=this.#Ve();n.addToolResult(e.toolCallId,JSON.stringify(this.navigationResult(e))),await n.resume()}appendMessage(e,n){let r=document.createElement("div");return r.className=`message message--${e}`,r.setAttribute("part",`message message-${e}`),e===ze.ASSISTANT?(r.innerHTML=zi(n,{allowImages:this.allowImages}),Pa(r,this.#e),this.#I().appendChild(r)):(this.#D=null,r.textContent=n,this.#f.appendChild(r)),this.#_(),e===ze.USER?this.#g.jump():this.#g.follow(),r}#I(){if(this.#D===null){let e=document.createElement("div");e.className="answer",e.setAttribute("part","answer"),this.#D=e,this.#f.appendChild(e),this.#_()}return this.#D}#ln(){this.#x.className="chat",this.#x.setAttribute("part","panel");let e=document.createElement("div");e.className="header",e.setAttribute("part","header");let n=this.#Se;n.className="header-title",n.setAttribute("part","title"),n.textContent=this.getAttribute("title-text")??this.#e.title,(this.querySelector('[slot="icon"]')!==null||this.getAttribute("data-icon-url")!==null)&&e.append(this.#gt("icon","icon",null));let r=document.createElement("slot");r.name="header-actions";let o=document.createElement("div");o.className="header-controls",o.setAttribute("part","header-controls");let i=this.#Ee("history",this.#e.chatHistory,"\u2630");i.addEventListener("click",()=>this.openThreads());let s=this.#Ee("checkpoints",this.#e.checkpoints,"\u21BA");s.addEventListener("click",()=>this.toggleCheckpoints());let a=this.#Ee("new",this.#e.newChat,"\u271A");a.addEventListener("click",()=>this.newChat());let l=this.#Ee("collapse",this.#e.collapse,"\u2014");l.addEventListener("click",()=>this.toggleCollapsed()),this.#Me()!==null?o.append(i,s,a):o.append(i,a),this.getAttribute("data-theme-toggle")!==null&&(this.#L.type="button",this.#L.className="header-btn header-btn--theme",this.#L.setAttribute("part","header-button theme-toggle"),this.#L.title=this.#e.toggleTheme,this.#L.setAttribute("aria-label",this.#e.toggleTheme),this.#L.addEventListener("click",()=>this.toggleTheme()),this.#ut(),o.append(this.#L)),o.append(l),e.append(n,r,o),this.#f.className="messages",this.#f.setAttribute("part","messages"),this.#f.setAttribute("role","log"),this.#f.setAttribute("aria-live","off"),this.#f.setAttribute("aria-label",this.#e.conversation),this.#z.className="jump-latest",this.#z.type="button",this.#z.setAttribute("part","jump-latest"),this.#z.textContent=this.#e.jumpToLatest,this.#z.addEventListener("click",()=>{this.#g.jump()}),this.#b.className="quote-selection",this.#b.type="button",this.#b.setAttribute("part","quote-selection"),this.#b.textContent=this.#e.quoteSelection,this.#b.hidden=!0,this.#b.addEventListener("mousedown",h=>{h.preventDefault()}),this.#b.addEventListener("click",()=>{this.quote(this.#Te),window.getSelection()?.removeAllRanges(),this.#Pe()}),this.#f.addEventListener("mouseup",h=>this.#rt(h)),this.#f.addEventListener("keyup",()=>this.#rt()),this.#f.addEventListener("mousedown",()=>this.#Pe()),this.#g=rp({viewport:this.#f,onMissedContent:h=>{this.#z.dataset.missed=String(h)}}),this.#M.className="sr-only",this.#M.setAttribute("role","status"),this.#M.setAttribute("aria-live","polite"),this.#M.setAttribute("aria-atomic","true"),this.#B.className="empty",this.#B.setAttribute("part","empty");let c=document.createElement("slot");c.name="empty",this.#B.append(c),this.#f.append(this.#B);let u=document.createElement("div");u.className="input-row",u.setAttribute("part","composer");let m=document.createElement("div");m.className="composer",m.setAttribute("part","composer-surface");let y=document.createElement("div");y.className="composer-tools",y.setAttribute("part","composer-tools"),this.#l.className="input",this.#l.setAttribute("part","input"),this.#l.setAttribute("aria-label",this.#e.message),this.#l.rows=1,this.#l.placeholder=this.#e.inputPlaceholder,this.#l.addEventListener("keydown",h=>this.#hn(h)),this.#l.addEventListener("input",()=>this.#bt()),this.#w.className="send",this.#w.type="button",this.#w.setAttribute("part","send"),this.#w.append(this.#$e("icon-send","send-send",Jl),this.#$e("icon-stop","send-stop",ec)),this.#w.title=this.#e.send,this.#w.setAttribute("aria-label",this.#e.send),this.#w.dataset.state="idle",this.#w.addEventListener("click",()=>{if(this.#j){this.#F();return}this.#Be()}),this.#R.className="skill-hint",this.#R.setAttribute("part","skill-hint"),this.#R.hidden=!0,this.#A.className="attach-btn",this.#A.type="button",this.#A.setAttribute("part","attach-button"),this.#A.append(this.#$e("icon-attach","attach-glyph",tc)),this.#A.title=this.#e.attachFiles,this.#A.setAttribute("aria-label",this.#e.attachFiles),this.#A.hidden=!0,this.#A.addEventListener("click",()=>this.#k.click()),this.#k.className="attach-input",this.#k.type="file",this.#k.multiple=!0,this.#k.hidden=!0,this.#k.addEventListener("change",()=>this.#qt()),this.#ue.className="attachment-slot",this.#he.className="voice-slot";let f=document.createElement("slot");f.name="footer",y.append(this.#A,this.#he,this.#w),m.append(this.#l,y),u.append(m,this.#k),this.#ce.className="messages-wrap",this.#ce.append(this.#f,this.#z,this.#b),this.#x.append(e,this.#ce,this.#H.palette,this.#H.chips,this.#R,this.#ue,u,f,this.#$.element,this.#E.element),this.#x.addEventListener("pointerdown",h=>{if(!this.#E.open_)return;let g=h.composedPath();g.includes(this.#E.element)||g.includes(s)||this.#E.close()}),this.#C.className="launcher",this.#C.type="button",this.#C.setAttribute("part","launcher"),this.#C.setAttribute("aria-label",this.#e.expand),this.#P.className="launcher-badge",this.#P.setAttribute("part","launcher-badge"),this.#P.setAttribute("aria-hidden","true"),this.#P.hidden=!0,this.#C.append(this.#gt("launcher","launcher-icon",rc,this.#dn()),this.#P),this.#C.addEventListener("click",()=>this.setCollapsed(!1)),this.#x.append(ep({axis:()=>this.#Ue(),anchor:()=>this.#at(),rect:()=>this.getBoundingClientRect(),apply:h=>this.#Fe(h),commit:h=>{this.#Jt(h),this.#He()},label:this.#e.resizePanel})),this.#cn(),this.#T.append(this.#M,this.#x,this.#C)}#ae(e){this.#G!==null&&clearTimeout(this.#G),this.#M.textContent=e,this.#G=setTimeout(()=>{this.#G=null,this.#M.textContent=""},lc)}#cn(){let e=new CSSStyleSheet;e.replaceSync(op),this.#T.adoptedStyleSheets=[e]}#Ee(e,n,r){let o=document.createElement("button");o.type="button",o.className=`header-btn header-btn--${e}`,o.setAttribute("part",`header-button ${e}-button`),o.title=n,o.setAttribute("aria-label",n);let i=document.createElement("slot");return i.name=`icon-${e}`,i.append(document.createTextNode(r)),o.append(i),o}#$e(e,n,r){let o=document.createElement("slot");return o.name=e,o.className=n,o.innerHTML=r,o}#dn(){return this.getAttribute("data-launcher-icon-url")??this.getAttribute("data-icon-url")}#gt(e,n,r,o=this.getAttribute("data-icon-url")){let i=document.createElement("span");i.className="icon-holder",i.setAttribute("part",n);let s=document.createElement("slot");if(s.name=e,o!==null){let a=document.createElement("img");a.className="icon-img",a.src=o,a.alt="",s.append(a)}else r!==null&&(s.innerHTML=r);return i.append(s),i}#vt(){this.#C.setAttribute("aria-expanded",String(!this.collapsed));let e=this.#pe;this.#P.textContent=e>9?"9+":String(e),this.#P.hidden=e===0||!this.#un();let n=this.#P.hidden?this.#e.expand:this.#e.expandUnread.replace("{count}",String(e));this.#C.setAttribute("aria-label",n),this.#C.title=n}#un(){return this.getAttribute("data-unread-badge")!=="false"}#_e(e){this.#pe=e,this.#vt(),this.dispatchEvent(new CustomEvent(bs,{detail:{unread:e},bubbles:!0,composed:!0}))}#pn(){this.collapsed&&this.#_e(this.#pe+1)}#_(){this.#B.hidden=this.#f.childElementCount>1}#bt(){this.#H.onInput(this.#l.value),this.#R.hidden=!0,this.#J()}#hn(e){if(this.#H.onKeydown(e)){e.preventDefault();return}if(e.key==="Escape"&&this.#j){e.preventDefault(),this.#F();return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),this.#Be())}#F(){this.#N?.abort(),this.#V?.cancel()}#X(e){this.#j=e;let n=e?this.#e.stop:this.#e.send;this.#w.title=n,this.#w.setAttribute("aria-label",n),this.#w.dataset.state=e?"running":"idle"}#J(){this.#l.style.height="auto",this.#l.style.height=`${this.#l.scrollHeight}px`}async#Be(){if(this.#j)return;let e=this.#l.value.trim(),n=this.#S?.readyRefs()??[];e===""&&n.length===0||(this.#l.value="",this.#J(),this.#S?.hasPending()===!0&&this.#le("\u{1F4CE}",this.#e.attachmentsStillUploading.replace("{n}",String(this.#S.pendingCount())),"attachment-pending"),this.#S?.clearReady(),await this.sendMessage(e,n))}async sendMessage(e,n=[]){if(this.#j||e===""&&n.length===0)return;let r=this.appendMessage(ze.USER,e);n.length>0&&r.appendChild(Da(n)),this.dispatchEvent(new CustomEvent(gs,{detail:{content:e,attachments:n},bubbles:!0,composed:!0})),await this.#mn(e,n)}attachFile(e){return this.#S===null?!1:(this.#S.add(e),!0)}#fn(e){this.dispatchEvent(new CustomEvent(xs,{detail:{attachments:e.readyRefs(),pending:e.pendingCount()},bubbles:!0,composed:!0}))}async#mn(e,n){this.endpoint!==""&&await this.#Ve().send(e,n)}#Ve(){if(this.#V===null){let e=this.agentFactory({endpoint:this.endpoint,headers:this.#re(),getHeaders:()=>this.#re(),trustedOrigins:this.trustedOrigins,...this.#ye(),threadId:this.#h,initialMessages:this.#Oe,initialState:this.#Z});this.#V=new Bn({agent:e,handlers:this.#wt(),getTools:()=>this.#et(),getContext:()=>this.#ht(),executeTool:n=>this.#yt(n),resolveInterrupts:n=>this.#xt(n),onPersist:n=>this.conversationStore.saveMessages(this.#h,n),onStateChanged:n=>this.#gn(n),connectionLostMessage:this.#e.connectionLost,maxToolRounds:this.#Bt()})}return this.#V}#gn(e){this.#Z={...e},this.dispatchEvent(new CustomEvent(ys,{detail:{state:this.#Z},bubbles:!0,composed:!0}))}#je(e,n={}){let r=this.#Vt(),o=r.has(bn.COPY),i=n.rateable!==!1&&r.has(bn.FEEDBACK);(o||i)&&Ga(e,{strings:this.#e,...o?{text:()=>e.textContent}:{},...i?{onFeedback:s=>{this.dispatchEvent(new CustomEvent(Ts,{detail:{content:e.textContent,rating:s},bubbles:!0,composed:!0}))}}:{}}),r.has(bn.RETRY)&&this.#vn(Ni(e,this.#e))}#vn(e){this.#y?.querySelector(".message-action--retry")?.remove();let n=Oi("retry",this.#e.retryMessage,"\u21BB");n.addEventListener("click",()=>{this.retryLastTurn()}),e.prepend(n),this.#y=e}async#bn(e,n){return this.autoConfirm?null:this.confirmPredicate!==null?await this.confirmPredicate(e.name,e.args)===!0?"predicate":null:this.#m.has(e.name)?null:ya(n.parameters)?"destructive":null}async#yt(e){if(bp(e)!==null)return null;let n=this.#Xe(e);this.#i.delete(e.id),this.#d.set(e.id,n.element);let r=this.#s.has(e.name)?this.#Le(e.name):null;if(r===null)return this.#p.has(e.id)||n.settle(te.DONE,this.#e.noResult),null;if(this.getPageMap!==null&&e.name!==ks&&!wi(r.parameters)&&this.#on()){let s=this.#e.pageMoved;return n.settle(te.ERROR,s),this.#ee(),{content:`Error: ${s}`,error:s}}let o=await this.#bn(e,r);if(o!==null){let s={toolName:e.name,args:e.args},a=r.parameters[Wr];typeof a=="string"&&(s.message=a),this.#N=new AbortController;let l=za(this.#I(),s,{signal:this.#N.signal,strings:this.#e,...o==="destructive"?{onAlwaysAllow:()=>this.#m.add(e.name)}:{}});this.#_(),this.#g.follow();let c=await l;if(this.#N=null,n.recordDecision(c?"approved":"declined"),!c){let u=this.#e.declinedAction;return n.settle(te.DECLINED,u),this.#ee(),{content:u}}}let i=wi(r.parameters)&&this.navigate===null;i&&this.conversationStore.saveCheckpoint(this.#h,{toolCallId:e.id});try{let s=await r.handler(e.args,e.id);if(r.render!==void 0&&this.#St(r.render,e),i)return n.settle(te.DONE,this.#e.navigating),{content:"",halt:!0};let a=JSON.stringify(s??null);return n.settle(te.DONE,a),this.#ee(),{content:a}}catch(s){i&&this.conversationStore.saveCheckpoint(this.#h,null);let a=s instanceof Error?s.message:String(s);return n.settle(te.ERROR,a),this.#ee(),{content:`Error: ${a}`,error:a}}}async#xt(e){this.#N=new AbortController,this.#ae(this.#e.announceAwaitingDecision.replace("{count}",String(e.length))),this.#O();let n=this.#N.signal,r=await Promise.all(e.map(async i=>{let s=i.toolCallId!==void 0?this.#i.get(i.toolCallId):void 0,a={},l=ex(i)??i.message;l!==void 0&&(a.message=l);let c=s?.element.getAttribute("data-tool-name");c!=null&&(a.toolName=c);let u,m=this.approveWithEdits&&s!==void 0;m&&(a.args=s.args),s?.mark(te.DEFERRED);let y=this.approvalRenderer!==null?await this.approvalRenderer(a,{signal:n}):await La(s?.approvalSlot??this.#I(),a,{signal:n,strings:this.#e,...m?{onEdit:f=>{u=f}}:{}});return s?.recordDecision(y?"approved":"declined"),y?s?.mark(te.PENDING):s?.settle(te.DECLINED,this.#e.declinedAction),{id:i.id,approved:y,editedArgs:u}}));this.#_(),this.#g.follow(),this.#N=null;let o={};for(let{id:i,approved:s,editedArgs:a}of r)o[i]=s?{status:"resolved",payload:a===void 0?{approved:!0}:{approved:!0,editedArgs:a}}:{status:"cancelled"};return o}#wt(){return{onRunStart:()=>{this.#j||(this.#de=!1,this.#ae(this.#e.announceResponding)),this.#X(!0),this.#I(),this.#ee()},onReasoningStart:()=>{this.#O(),this.#Et()},onReasoningDelta:e=>{this.#Et().stream(e)},onReasoningEnd:()=>{},onTextDelta:e=>{this.#O(),this.#W?.collapse(),this.#_n(e),this.#Ie+=1},onTextEnd:e=>{let n=this.#qe(e);this.#Ie<=1&&this.#mt(n),Pa(n,this.#e),this.#je(n),this.#te(),this.#pn()},onToolCall:e=>{this.#O(),!this.#Tt(e)&&(this.#v.push({id:e.id,name:e.name}),this.#Xe(e))},onActivity:(e,n,r)=>{this.#We(r,e,n)},onCustomEvent:(e,n)=>{if(e===As){this.#xn(n);return}if(e===Zl){this.#wn(n);return}this.dispatchEvent(new CustomEvent(Es,{detail:{name:e,value:n},bubbles:!0,composed:!0}))},onMessagesSnapshot:()=>{this.#le("\u{1F504}",this.#e.historyReplaced,"history-replaced")},onToolResult:(e,n)=>{let r=this.#i.get(e);r!==void 0&&(r.settle(te.DONE,n),this.#p.add(e),this.#ee())},onActivityChanged:(e,n,r)=>{this.#We(e,n,r)},onRunEnd:()=>{this.#O(),this.#te()},onError:e=>{this.#de=!0,this.#ae(this.#e.announceFailed),this.#O();let n=this.appendMessage(ze.ASSISTANT,`\u26A0\uFE0F ${e}`);n.classList.add("message--failed"),this.#je(n,{rateable:!1}),this.#mt(n),this.#te()},onCancelled:()=>{this.#de=!0,this.#ae(this.#e.announceStopped),this.#O(),this.#En(),this.#te()},onSettled:()=>{this.#de||this.#ae(this.#e.announceAnswerReady),this.#O(),this.#X(!1),this.#te();for(let e of this.#i.values())e.settled||e.settle(te.DONE,this.#e.noResult);this.#D!==null&&this.#D.childElementCount===0&&(this.#D.remove(),this.#_()),this.#D=null,this.#W=null,this.#yn()}}}#yn(){let e=this.#v.map(({id:r,name:o})=>({name:o,side:this.#p.has(r)?"server":"client"}));this.#v=[];let n=[...this.#U];this.#U=new Set,this.dispatchEvent(new CustomEvent(ws,{detail:{tools:e,invalidated:n},bubbles:!0,composed:!0}))}#xn(e){let n=e??{},r=Array.isArray(n.keys)?n.keys.filter(o=>typeof o=="string"):[];if(r.length!==0){for(let o of r)this.#U.add(o);this.dispatchEvent(new CustomEvent(_s,{detail:{keys:r,reason:typeof n.reason=="string"?n.reason:null},bubbles:!0,composed:!0}))}}#wn(e){let n=sp(e);if(n===null)return;let r=this.#i.get(n.delegationId);if(r===void 0)return;let o=this.#o.get(n.delegationId);o===void 0&&(o=new $i(this.#e),this.#o.set(n.delegationId,o),r.subagentSlot.appendChild(o.element)),o.report(n),this.#g.follow()}#En(){let e=document.createElement("div");e.className="stopped-note",e.setAttribute("part","stopped"),e.setAttribute("role","status"),e.textContent=this.#e.stopped,this.#I().appendChild(e),this.#_(),this.#g.follow()}#ee(){if(this.#ge!==null)return;let e=document.createElement("div");e.className="pending",e.setAttribute("part","pending"),e.setAttribute("role","status"),e.setAttribute("aria-label",this.#e.thinking);for(let n=0;n<3;n+=1){let r=document.createElement("span");r.className="pending-dot",e.appendChild(r)}this.#ge=e,this.#I().appendChild(e),this.#_(),this.#g.follow()}#O(){this.#ge?.remove(),this.#ge=null}#Et(){if(this.#W===null){this.#W=new Bi(this.#e);let e=this.#I();e.insertBefore(this.#W.element,e.firstChild),this.#_(),this.#g.follow()}return this.#W}#_t(){return this.#fe===null&&(this.#fe=this.appendMessage(ze.ASSISTANT,""),this.#Ie=0),this.#fe}#_n(e){this.#me=e,this.#_t(),this.#q===null&&(this.#q=requestAnimationFrame(()=>{this.#q=null,this.#qe(this.#me)}))}#qe(e){this.#q!==null&&(cancelAnimationFrame(this.#q),this.#q=null),this.#me=e;let n=this.#_t();return n.innerHTML=zi(e,{allowImages:this.allowImages}),this.#g.follow(),n}#te(){this.#q!==null&&this.#qe(this.#me),this.#fe=null}#Tt(e){let n=bp(e);return n===null?!1:(this.#le("\u2728",this.#e.usingSkill.replace("{name}",n),"skill"),!0)}#le(e,n,r){this.#I().appendChild(pl(e,n,r)),this.#_(),this.#g.follow()}enableCharts(e=["tool","activity"]){let n=!this.#u.has(Xr)&&!this.#r.has(Ri);e.includes("activity")&&this.registerActivityRenderer({type:Xr,render:r=>{let o=Un(r);return o===null?null:gr(o)},removedNotice:this.#e.chartUndrawable}),e.includes("tool")&&this.registerTool(lu()),n&&this.isConnected&&this.reload()}#St(e,n){let r;try{r=e(n.args)}catch(o){console.warn(`ag-ui-chat: render failed for tool ${n.name}`,o);return}r!==null&&(this.#d.get(n.id)?.after(r),this.#At())}registerActivityRenderer(e){this.#u.set(e.type,e),this.#c.delete(e.type)}get unhandledActivityTypes(){return[...this.#c]}#We(e,n,r){let o=this.#u.get(n);if(o===void 0){this.#c.add(n);return}let i;try{i=o.render(r)}catch(a){console.warn(`ag-ui-chat: render failed for activity ${n}`,a),i=null}if(i===null){this.#Tn(e,n,o.removedNotice,r);return}let s=this.#a.get(e);s===void 0?this.#I().appendChild(i):s.replaceWith(i),this.#a.set(e,i),this.#At()}#Tn(e,n,r,o){let i=this.#a.has(e);this.#a.get(e)?.remove(),this.#a.delete(e),console.warn(`ag-ui-chat: activity ${e} (${n}) was not drawable and has been removed. A chart's points must each be a finite JSON number; a numeric column serialised as a string (a Decimal, typically) is rejected rather than coerced.`,o),i&&r!==void 0&&this.#le("\u{1F4C9}",r,"chart-undrawable")}#At(){this.#_(),this.#g.follow()}#Xe(e){let n=this.#i.get(e.id);if(n!==void 0)return n;let r=this.#Le(e.name)?.parameters[Pe],o=typeof r=="string"?r:this.toolSummaries[e.name]??this.#t[e.name]?.summary??ja(e.name),i=new Cr(e.name,e.args,o,this.#e,{formatPayload:s=>this.formatToolPayload?.(s)??null});return this.#i.set(e.id,i),this.#I().appendChild(i.element),this.#_(),this.#g.follow(),i}};function ex(t){let e=t.metadata?.[Wr];return typeof e=="string"&&e.trim()!==""?e:void 0}function tx(t){return Array.isArray(t)?t.filter(nx):[]}function nx(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.id=="string"&&typeof e.function?.name=="string"}function bp(t){if(t.name!==Rs)return null;let e=t.args?.id;return typeof e=="string"&&e!==""?e:null}function rx(t){let e=t?.removed;return typeof e=="number"?e:null}function ox(){customElements.get(qr)===void 0&&customElements.define(qr,Mr)}async function ix(t,e,n={}){await vt(t),await Ta(t,{...n,flashMs:n.flashMs??0}),await Ea(t,e,n)}async function sx(t,e={}){await vt(t),await _a(t,e)}async function ax(t,e={}){await vt(t),await Sa(t,e)}async function lx(t,e,n={}){await vt(t),await Aa(t,e,n)}async function cx(t,e,n={}){await vt(t),await ka(t,e,n)}function dx(t,e){t instanceof HTMLInputElement&&t.type==="checkbox"?hr(t,!!e):rn(t,String(e)),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0}))}var ux="0.30.0";export{xs as ATTACHMENT_EVENT,Mr as AgUiChat,Bn as AgUiClient,Xr as CHART_ACTIVITY_TYPE,Ri as CHART_TOOL_NAME,Is as COMPACTION_ACTIVITY_TYPE,Es as CUSTOM_AGENT_EVENT,br as CheckpointMenu,pr as ClientToolRegistry,qi as ConnectionLostError,ee as DEFAULT_UI_STRINGS,qr as ELEMENT_TAG,Ts as FEEDBACK_EVENT,As as INVALIDATE_CUSTOM_NAME,_s as INVALIDATE_EVENT,Rs as LOAD_CAPABILITY_TOOL,zv as MAX_QUOTE_CHARS,Fy as MAX_SUGGESTIONS,zy as MAX_SUGGESTION_CHARS,vn as MAX_TOOL_ROUNDS,bn as MESSAGE_ACTIONS,ze as MESSAGE_ROLE,Ca as PAGE_ACTIONS,ws as RUN_FINISHED_EVENT,Nr as RemoteConversationStore,Or as RunIndex,ys as STATE_EVENT,gs as SUBMIT_EVENT,Ss as SUGGESTIONS_ACTIVITY_TYPE,je as SessionStorageStore,vs as TOGGLE_EVENT,te as TOOL_CALL_STATUS,yn as TOOL_DISPLAY,Cr as ToolCallCard,bs as UNREAD_EVENT,ux as VERSION,Wr as X_CONFIRM_KEY,Kn as X_DESTRUCTIVE_KEY,Zn as X_NAVIGATES_KEY,Pe as X_SUMMARY_KEY,$a as asQuote,Ga as attachMessageActions,Va as attachQuoteOffer,Un as chartSpecFrom,sx as clickElement,vl as createHttpAgent,Ia as createPageActionTools,Ra as createPageMapContext,Si as createPageStateTools,Oa as createRouteTools,pv as createStateHookTools,ox as defineAgUiChat,ix as fillField,av as flash,Ta as focusWithFlash,_a as highlightThenClick,ya as isDestructive,wi as isNavigates,Ma as mergeUiStrings,Ni as messageActionBar,ml as messageAttachments,Na as parseToolCatalog,_i as prefersReducedMotion,ax as pressButton,Sa as pressThenClick,ja as prettifyToolName,yr as quotableSelection,vr as relativeTime,gr as renderChart,zi as renderMarkdown,hl as renderSuggestionChips,La as requestApproval,za as requestConfirmation,qa as requestQuestion,vt as scrollIntoCenterView,lx as selectControl,Aa as selectOption,dx as setControlValue,hr as setNativeChecked,rn as setNativeValue,ap as suggestionPrompts,cx as toggleCheckbox,ka as toggleControl,bl as transcribeAudio,Ea as typeInto,yl as uploadAttachment};
2663
2846
  /*! Bundled license information:
2664
2847
 
2665
2848
  fast-json-patch/module/helpers.mjs: