@artooi/ag-ui-web-component 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +417 -1
- package/README.md +371 -5
- package/dist/ag-ui-web-component.bundle.js +308 -50
- package/dist/ag-ui-web-component.bundle.js.map +4 -4
- package/dist/constants.d.ts +69 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/core/ag_ui_chat.d.ts +207 -0
- package/dist/core/ag_ui_chat.d.ts.map +1 -1
- package/dist/core/agui_client.d.ts +38 -0
- package/dist/core/agui_client.d.ts.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1516 -76
- package/dist/index.js.map +4 -4
- package/dist/ui/approval_card.d.ts +18 -0
- package/dist/ui/approval_card.d.ts.map +1 -1
- package/dist/ui/checkpoint_menu.d.ts +10 -0
- package/dist/ui/checkpoint_menu.d.ts.map +1 -1
- package/dist/ui/confirmation_card.d.ts +16 -0
- package/dist/ui/confirmation_card.d.ts.map +1 -1
- package/dist/ui/message_actions.d.ts +46 -0
- package/dist/ui/message_actions.d.ts.map +1 -0
- package/dist/ui/page_quote_offer.d.ts +33 -0
- package/dist/ui/page_quote_offer.d.ts.map +1 -0
- package/dist/ui/quote_selection.d.ts +66 -0
- package/dist/ui/quote_selection.d.ts.map +1 -0
- package/dist/ui/relative_time.d.ts +10 -0
- package/dist/ui/relative_time.d.ts.map +1 -1
- package/dist/ui/stick_to_bottom.d.ts +55 -0
- package/dist/ui/stick_to_bottom.d.ts.map +1 -0
- package/dist/ui/styles.d.ts +1 -1
- package/dist/ui/styles.d.ts.map +1 -1
- package/dist/ui/suggestion_chips.d.ts +29 -0
- package/dist/ui/suggestion_chips.d.ts.map +1 -0
- package/dist/ui/thread_drawer.d.ts +10 -0
- package/dist/ui/thread_drawer.d.ts.map +1 -1
- package/dist/ui/tool_call_card.d.ts +8 -0
- package/dist/ui/tool_call_card.d.ts.map +1 -1
- package/dist/ui/ui_strings.d.ts +40 -0
- package/dist/ui/ui_strings.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +75 -0
- package/src/core/ag_ui_chat.ts +927 -73
- package/src/core/agui_client.ts +63 -0
- package/src/index.ts +39 -0
- package/src/ui/approval_card.ts +90 -2
- package/src/ui/checkpoint_menu.ts +22 -5
- package/src/ui/confirmation_card.ts +29 -1
- package/src/ui/message_actions.ts +158 -0
- package/src/ui/page_quote_offer.ts +215 -0
- package/src/ui/quote_selection.ts +345 -0
- package/src/ui/relative_time.ts +11 -0
- package/src/ui/stick_to_bottom.ts +126 -0
- package/src/ui/styles.ts +227 -0
- package/src/ui/suggestion_chips.ts +73 -0
- package/src/ui/thread_drawer.ts +22 -2
- package/src/ui/tool_call_card.ts +9 -0
- package/src/ui/ui_strings.ts +60 -0
- package/src/version.ts +1 -1
|
@@ -1,80 +1,109 @@
|
|
|
1
|
-
var yp=Object.defineProperty;var ls=(t,e)=>{for(var n in e)yp(t,n,{get:e[n],enumerable:!0})};var $r="ag-ui-chat",cs="ag-ui-submit",ds="ag-ui-toggle",us="ag-ui-unread",ps="ag-ui-state",hs="ag-ui-attachments",fs="ag-ui-run-finished",We={USER:"user",ASSISTANT:"assistant"},Xn="x-destructive",Vr="x-confirm",Pe="x-summary",Kn="x-navigates",ms="read_page",gs=10,ee={PENDING:"pending",DEFERRED:"deferred",DONE:"done",ERROR:"error",DECLINED:"declined"},De={UPLOADING:"uploading",READY:"ready",ERROR:"error"},vs=10*1024*1024,vn={INLINE:"inline",MINIMAL:"minimal",COMPACT:"compact",FULL:"full"},bs="compaction",ys="load_capability",Ol='<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>',Ml='<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>',Ll='<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>',Pl='<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>',Dl='<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>',Ul='<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>',Hl='<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>',zl='<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>',Gl='<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>',Yn="chart";var xe=[];for(let t=0;t<256;++t)xe.push((t+256).toString(16).slice(1));function Fl(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 xs,xp=new Uint8Array(16);function ws(){if(!xs){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");xs=crypto.getRandomValues.bind(crypto)}return xs(xp)}var wp=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),_s={randomUUID:wp};function _p(t,e,n){if(_s.randomUUID&&!e&&!t)return _s.randomUUID();t=t||{};let r=t.random??t.rng?.()??ws();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 i=0;i<16;++i)e[n+i]=r[i];return e}return Fl(r)}var Et=_p;var d={};ls(d,{BRAND:()=>Xp,DIRTY:()=>Lt,EMPTY_PATH:()=>Ap,INVALID:()=>P,NEVER:()=>Oh,OK:()=>Ae,ParseStatus:()=>we,Schema:()=>$,ZodAny:()=>At,ZodArray:()=>mt,ZodBigInt:()=>Dt,ZodBoolean:()=>Ut,ZodBranded:()=>Jn,ZodCatch:()=>Xt,ZodDate:()=>Ht,ZodDefault:()=>Wt,ZodDiscriminatedUnion:()=>qr,ZodEffects:()=>$e,ZodEnum:()=>jt,ZodError:()=>Oe,ZodFirstPartyTypeKind:()=>D,ZodFunction:()=>Xr,ZodIntersection:()=>$t,ZodIssueCode:()=>_,ZodLazy:()=>Vt,ZodLiteral:()=>Bt,ZodMap:()=>En,ZodNaN:()=>Sn,ZodNativeEnum:()=>qt,ZodNever:()=>Xe,ZodNull:()=>Gt,ZodNullable:()=>st,ZodNumber:()=>Pt,ZodObject:()=>Me,ZodOptional:()=>Ge,ZodParsedType:()=>C,ZodPipeline:()=>Qn,ZodPromise:()=>kt,ZodReadonly:()=>Kt,ZodRecord:()=>Wr,ZodSchema:()=>$,ZodSet:()=>Tn,ZodString:()=>St,ZodSymbol:()=>wn,ZodTransformer:()=>$e,ZodTuple:()=>ot,ZodType:()=>$,ZodUndefined:()=>zt,ZodUnion:()=>Ft,ZodUnknown:()=>ft,ZodVoid:()=>_n,addIssueToContext:()=>k,any:()=>rh,array:()=>ah,bigint:()=>Jp,boolean:()=>Jl,coerce:()=>Nh,custom:()=>Kl,date:()=>Qp,datetimeRegex:()=>Wl,defaultErrorMap:()=>pt,discriminatedUnion:()=>uh,effect:()=>Eh,enum:()=>xh,function:()=>vh,getErrorMap:()=>bn,getParsedType:()=>it,instanceof:()=>Yp,intersection:()=>ph,isAborted:()=>Br,isAsync:()=>yn,isDirty:()=>jr,isValid:()=>Tt,late:()=>Kp,lazy:()=>bh,literal:()=>yh,makeIssue:()=>Zn,map:()=>mh,nan:()=>Zp,nativeEnum:()=>wh,never:()=>oh,null:()=>nh,nullable:()=>Sh,number:()=>Zl,object:()=>lh,objectUtil:()=>Es,oboolean:()=>Rh,onumber:()=>Ih,optional:()=>Th,ostring:()=>Ch,pipeline:()=>kh,preprocess:()=>Ah,promise:()=>_h,quotelessJson:()=>Ep,record:()=>fh,set:()=>gh,setErrorMap:()=>Sp,strictObject:()=>ch,string:()=>Yl,symbol:()=>eh,transformer:()=>Eh,tuple:()=>hh,undefined:()=>th,union:()=>dh,unknown:()=>ih,util:()=>B,void:()=>sh});var B;(function(t){t.assertEqual=i=>{};function e(i){}t.assertIs=e;function n(i){throw new Error}t.assertNever=n,t.arrayToEnum=i=>{let o={};for(let s of i)o[s]=s;return o},t.getValidEnumValues=i=>{let o=t.objectKeys(i).filter(a=>typeof i[i[a]]!="number"),s={};for(let a of o)s[a]=i[a];return t.objectValues(s)},t.objectValues=i=>t.objectKeys(i).map(function(o){return i[o]}),t.objectKeys=typeof Object.keys=="function"?i=>Object.keys(i):i=>{let o=[];for(let s in i)Object.prototype.hasOwnProperty.call(i,s)&&o.push(s);return o},t.find=(i,o)=>{for(let s of i)if(o(s))return s},t.isInteger=typeof Number.isInteger=="function"?i=>Number.isInteger(i):i=>typeof i=="number"&&Number.isFinite(i)&&Math.floor(i)===i;function r(i,o=" | "){return i.map(s=>typeof s=="string"?`'${s}'`:s).join(o)}t.joinValues=r,t.jsonStringifyReplacer=(i,o)=>typeof o=="bigint"?o.toString():o})(B||(B={}));var Es;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(Es||(Es={}));var C=B.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),it=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 _=B.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"]),Ep=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(o){return o.message},r={_errors:[]},i=o=>{for(let s of o.issues)if(s.code==="invalid_union")s.unionErrors.map(i);else if(s.code==="invalid_return_type")i(s.returnTypeError);else if(s.code==="invalid_arguments")i(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 i(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,B.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){let n={},r=[];for(let i of this.issues)if(i.path.length>0){let o=i.path[0];n[o]=n[o]||[],n[o].push(e(i))}else r.push(e(i));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}};Oe.create=t=>new Oe(t);var Tp=(t,e)=>{let n;switch(t.code){case _.invalid_type:t.received===C.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case _.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,B.jsonStringifyReplacer)}`;break;case _.unrecognized_keys:n=`Unrecognized key(s) in object: ${B.joinValues(t.keys,", ")}`;break;case _.invalid_union:n="Invalid input";break;case _.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${B.joinValues(t.options)}`;break;case _.invalid_enum_value:n=`Invalid enum value. Expected ${B.joinValues(t.options)}, received '${t.received}'`;break;case _.invalid_arguments:n="Invalid function arguments";break;case _.invalid_return_type:n="Invalid function return type";break;case _.invalid_date:n="Invalid date";break;case _.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}"`:B.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case _.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 _.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 _.custom:n="Invalid input";break;case _.invalid_intersection_types:n="Intersection results could not be merged";break;case _.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case _.not_finite:n="Number must be finite";break;default:n=e.defaultError,B.assertNever(t)}return{message:n}},pt=Tp;var $l=pt;function Sp(t){$l=t}function bn(){return $l}var Zn=t=>{let{data:e,path:n,errorMaps:r,issueData:i}=t,o=[...n,...i.path||[]],s={...i,path:o};if(i.message!==void 0)return{...i,path:o,message:i.message};let a="",l=r.filter(c=>!!c).slice().reverse();for(let c of l)a=c(s,{data:e,defaultError:a}).message;return{...i,path:o,message:a}},Ap=[];function k(t,e){let n=bn(),r=Zn({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===pt?void 0:pt].filter(i=>!!i)});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 i of n){if(i.status==="aborted")return P;i.status==="dirty"&&e.dirty(),r.push(i.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,n){let r=[];for(let i of n){let o=await i.key,s=await i.value;r.push({key:o,value:s})}return t.mergeObjectSync(e,r)}static mergeObjectSync(e,n){let r={};for(let i of n){let{key:o,value:s}=i;if(o.status==="aborted"||s.status==="aborted")return P;o.status==="dirty"&&e.dirty(),s.status==="dirty"&&e.dirty(),o.value!=="__proto__"&&(typeof s.value<"u"||i.alwaysSet)&&(r[o.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}),Br=t=>t.status==="aborted",jr=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 Fe=class{constructor(e,n,r,i){this._cachedPath=[],this.parent=e,this.data=n,this._path=r,this._key=i}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}},Vl=(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 G(t){if(!t)return{};let{errorMap:e,invalid_type_error:n,required_error:r,description:i}=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:i}:{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:i}}var $=class{get description(){return this._def.description}_getType(e){return it(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:it(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:it(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:it(e)},i=this._parseSync({data:e,path:r.path,parent:r});return Vl(r,i)}"~validate"(e){let n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:it(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:it(e)},i=this._parse({data:e,path:r.path,parent:r}),o=await(yn(i)?i:Promise.resolve(i));return Vl(r,o)}refine(e,n){let r=i=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(i):n;return this._refinement((i,o)=>{let s=e(i),a=()=>o.addIssue({code:_.custom,...r(i)});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,i)=>e(r)?!0:(i.addIssue(typeof n=="function"?n(r,i):n),!1))}_refinement(e){return new $e({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 Ft.create([this,e],this._def)}and(e){return $t.create(this,e,this._def)}transform(e){return new $e({...G(this._def),schema:this,typeName:D.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let n=typeof e=="function"?e:()=>e;return new Wt({...G(this._def),innerType:this,defaultValue:n,typeName:D.ZodDefault})}brand(){return new Jn({typeName:D.ZodBranded,type:this,...G(this._def)})}catch(e){let n=typeof e=="function"?e:()=>e;return new Xt({...G(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}},kp=/^c[^\s-]{8,}$/i,Cp=/^[0-9a-z]+$/,Ip=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Rp=/^[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,Np=/^[a-z0-9_-]{21}$/i,Op=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Mp=/^[-+]?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)?)??$/,Lp=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Pp="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",Ts,Dp=/^(?:(?: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])$/,Up=/^(?:(?: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])$/,Hp=/^(([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]))$/,zp=/^(([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])$/,Gp=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Fp=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,jl="((\\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])))",$p=new RegExp(`^${jl}$`);function ql(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 Vp(t){return new RegExp(`^${ql(t)}$`)}function Wl(t){let e=`${jl}T${ql(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 Bp(t,e){return!!((e==="v4"||!e)&&Dp.test(t)||(e==="v6"||!e)&&Hp.test(t))}function jp(t,e){if(!Op.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,"="),i=JSON.parse(atob(r));return!(typeof i!="object"||i===null||"typ"in i&&i?.typ!=="JWT"||!i.alg||e&&i.alg!==e)}catch{return!1}}function qp(t,e){return!!((e==="v4"||!e)&&Up.test(t)||(e==="v6"||!e)&&zp.test(t))}var St=class t extends ${_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==C.string){let o=this._getOrReturnCtx(e);return k(o,{code:_.invalid_type,expected:C.string,received:o.parsedType}),P}let r=new we,i;for(let o of this._def.checks)if(o.kind==="min")e.data.length<o.value&&(i=this._getOrReturnCtx(e,i),k(i,{code:_.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),r.dirty());else if(o.kind==="max")e.data.length>o.value&&(i=this._getOrReturnCtx(e,i),k(i,{code:_.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),r.dirty());else if(o.kind==="length"){let s=e.data.length>o.value,a=e.data.length<o.value;(s||a)&&(i=this._getOrReturnCtx(e,i),s?k(i,{code:_.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}):a&&k(i,{code:_.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}),r.dirty())}else if(o.kind==="email")Lp.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"email",code:_.invalid_string,message:o.message}),r.dirty());else if(o.kind==="emoji")Ts||(Ts=new RegExp(Pp,"u")),Ts.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"emoji",code:_.invalid_string,message:o.message}),r.dirty());else if(o.kind==="uuid")Rp.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"uuid",code:_.invalid_string,message:o.message}),r.dirty());else if(o.kind==="nanoid")Np.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"nanoid",code:_.invalid_string,message:o.message}),r.dirty());else if(o.kind==="cuid")kp.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"cuid",code:_.invalid_string,message:o.message}),r.dirty());else if(o.kind==="cuid2")Cp.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"cuid2",code:_.invalid_string,message:o.message}),r.dirty());else if(o.kind==="ulid")Ip.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"ulid",code:_.invalid_string,message:o.message}),r.dirty());else if(o.kind==="url")try{new URL(e.data)}catch{i=this._getOrReturnCtx(e,i),k(i,{validation:"url",code:_.invalid_string,message:o.message}),r.dirty()}else o.kind==="regex"?(o.regex.lastIndex=0,o.regex.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"regex",code:_.invalid_string,message:o.message}),r.dirty())):o.kind==="trim"?e.data=e.data.trim():o.kind==="includes"?e.data.includes(o.value,o.position)||(i=this._getOrReturnCtx(e,i),k(i,{code:_.invalid_string,validation:{includes:o.value,position:o.position},message:o.message}),r.dirty()):o.kind==="toLowerCase"?e.data=e.data.toLowerCase():o.kind==="toUpperCase"?e.data=e.data.toUpperCase():o.kind==="startsWith"?e.data.startsWith(o.value)||(i=this._getOrReturnCtx(e,i),k(i,{code:_.invalid_string,validation:{startsWith:o.value},message:o.message}),r.dirty()):o.kind==="endsWith"?e.data.endsWith(o.value)||(i=this._getOrReturnCtx(e,i),k(i,{code:_.invalid_string,validation:{endsWith:o.value},message:o.message}),r.dirty()):o.kind==="datetime"?Wl(o).test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{code:_.invalid_string,validation:"datetime",message:o.message}),r.dirty()):o.kind==="date"?$p.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{code:_.invalid_string,validation:"date",message:o.message}),r.dirty()):o.kind==="time"?Vp(o).test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{code:_.invalid_string,validation:"time",message:o.message}),r.dirty()):o.kind==="duration"?Mp.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"duration",code:_.invalid_string,message:o.message}),r.dirty()):o.kind==="ip"?Bp(e.data,o.version)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"ip",code:_.invalid_string,message:o.message}),r.dirty()):o.kind==="jwt"?jp(e.data,o.alg)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"jwt",code:_.invalid_string,message:o.message}),r.dirty()):o.kind==="cidr"?qp(e.data,o.version)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"cidr",code:_.invalid_string,message:o.message}),r.dirty()):o.kind==="base64"?Gp.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"base64",code:_.invalid_string,message:o.message}),r.dirty()):o.kind==="base64url"?Fp.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"base64url",code:_.invalid_string,message:o.message}),r.dirty()):B.assertNever(o);return{status:r.value,value:e.data}}_regex(e,n,r){return this.refinement(i=>e.test(i),{validation:n,code:_.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,...G(t)});function Wp(t,e){let n=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,i=n>r?n:r,o=Number.parseInt(t.toFixed(i).replace(".","")),s=Number.parseInt(e.toFixed(i).replace(".",""));return o%s/10**i}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 o=this._getOrReturnCtx(e);return k(o,{code:_.invalid_type,expected:C.number,received:o.parsedType}),P}let r,i=new we;for(let o of this._def.checks)o.kind==="int"?B.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),k(r,{code:_.invalid_type,expected:"integer",received:"float",message:o.message}),i.dirty()):o.kind==="min"?(o.inclusive?e.data<o.value:e.data<=o.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:_.too_small,minimum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),i.dirty()):o.kind==="max"?(o.inclusive?e.data>o.value:e.data>=o.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:_.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),i.dirty()):o.kind==="multipleOf"?Wp(e.data,o.value)!==0&&(r=this._getOrReturnCtx(e,r),k(r,{code:_.not_multiple_of,multipleOf:o.value,message:o.message}),i.dirty()):o.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),k(r,{code:_.not_finite,message:o.message}),i.dirty()):B.assertNever(o);return{status:i.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,i){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:R.toString(i)}]})}_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"&&B.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,...G(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,i=new we;for(let o of this._def.checks)o.kind==="min"?(o.inclusive?e.data<o.value:e.data<=o.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:_.too_small,type:"bigint",minimum:o.value,inclusive:o.inclusive,message:o.message}),i.dirty()):o.kind==="max"?(o.inclusive?e.data>o.value:e.data>=o.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:_.too_big,type:"bigint",maximum:o.value,inclusive:o.inclusive,message:o.message}),i.dirty()):o.kind==="multipleOf"?e.data%o.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),k(r,{code:_.not_multiple_of,multipleOf:o.value,message:o.message}),i.dirty()):B.assertNever(o);return{status:i.value,value:e.data}}_getInvalidInput(e){let n=this._getOrReturnCtx(e);return k(n,{code:_.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,i){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:R.toString(i)}]})}_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,...G(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:_.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,...G(t)});var Ht=class t extends ${_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==C.date){let o=this._getOrReturnCtx(e);return k(o,{code:_.invalid_type,expected:C.date,received:o.parsedType}),P}if(Number.isNaN(e.data.getTime())){let o=this._getOrReturnCtx(e);return k(o,{code:_.invalid_date}),P}let r=new we,i;for(let o of this._def.checks)o.kind==="min"?e.data.getTime()<o.value&&(i=this._getOrReturnCtx(e,i),k(i,{code:_.too_small,message:o.message,inclusive:!0,exact:!1,minimum:o.value,type:"date"}),r.dirty()):o.kind==="max"?e.data.getTime()>o.value&&(i=this._getOrReturnCtx(e,i),k(i,{code:_.too_big,message:o.message,inclusive:!0,exact:!1,maximum:o.value,type:"date"}),r.dirty()):B.assertNever(o);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,...G(t)});var wn=class extends ${_parse(e){if(this._getType(e)!==C.symbol){let r=this._getOrReturnCtx(e);return k(r,{code:_.invalid_type,expected:C.symbol,received:r.parsedType}),P}return Ae(e.data)}};wn.create=t=>new wn({typeName:D.ZodSymbol,...G(t)});var zt=class extends ${_parse(e){if(this._getType(e)!==C.undefined){let r=this._getOrReturnCtx(e);return k(r,{code:_.invalid_type,expected:C.undefined,received:r.parsedType}),P}return Ae(e.data)}};zt.create=t=>new zt({typeName:D.ZodUndefined,...G(t)});var Gt=class extends ${_parse(e){if(this._getType(e)!==C.null){let r=this._getOrReturnCtx(e);return k(r,{code:_.invalid_type,expected:C.null,received:r.parsedType}),P}return Ae(e.data)}};Gt.create=t=>new Gt({typeName:D.ZodNull,...G(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,...G(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,...G(t)});var Xe=class extends ${_parse(e){let n=this._getOrReturnCtx(e);return k(n,{code:_.invalid_type,expected:C.never,received:n.parsedType}),P}};Xe.create=t=>new Xe({typeName:D.ZodNever,...G(t)});var _n=class extends ${_parse(e){if(this._getType(e)!==C.undefined){let r=this._getOrReturnCtx(e);return k(r,{code:_.invalid_type,expected:C.void,received:r.parsedType}),P}return Ae(e.data)}};_n.create=t=>new _n({typeName:D.ZodVoid,...G(t)});var mt=class t extends ${_parse(e){let{ctx:n,status:r}=this._processInputParams(e),i=this._def;if(n.parsedType!==C.array)return k(n,{code:_.invalid_type,expected:C.array,received:n.parsedType}),P;if(i.exactLength!==null){let s=n.data.length>i.exactLength.value,a=n.data.length<i.exactLength.value;(s||a)&&(k(n,{code:s?_.too_big:_.too_small,minimum:a?i.exactLength.value:void 0,maximum:s?i.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:i.exactLength.message}),r.dirty())}if(i.minLength!==null&&n.data.length<i.minLength.value&&(k(n,{code:_.too_small,minimum:i.minLength.value,type:"array",inclusive:!0,exact:!1,message:i.minLength.message}),r.dirty()),i.maxLength!==null&&n.data.length>i.maxLength.value&&(k(n,{code:_.too_big,maximum:i.maxLength.value,type:"array",inclusive:!0,exact:!1,message:i.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((s,a)=>i.type._parseAsync(new Fe(n,s,n.path,a)))).then(s=>we.mergeArray(r,s));let o=[...n.data].map((s,a)=>i.type._parseSync(new Fe(n,s,n.path,a)));return we.mergeArray(r,o)}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,...G(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 ot?ot.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=B.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:_.invalid_type,expected:C.object,received:c.parsedType}),P}let{status:r,ctx:i}=this._processInputParams(e),{shape:o,keys:s}=this._getCached(),a=[];if(!(this._def.catchall instanceof Xe&&this._def.unknownKeys==="strip"))for(let c in i.data)s.includes(c)||a.push(c);let l=[];for(let c of s){let p=o[c],m=i.data[c];l.push({key:{status:"valid",value:c},value:p._parse(new Fe(i,m,i.path,c)),alwaysSet:c in i.data})}if(this._def.catchall instanceof Xe){let c=this._def.unknownKeys;if(c==="passthrough")for(let p of a)l.push({key:{status:"valid",value:p},value:{status:"valid",value:i.data[p]}});else if(c==="strict")a.length>0&&(k(i,{code:_.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 p of a){let m=i.data[p];l.push({key:{status:"valid",value:p},value:c._parse(new Fe(i,m,i.path,p)),alwaysSet:p in i.data})}}return i.common.async?Promise.resolve().then(async()=>{let c=[];for(let p of l){let m=await p.key,y=await p.value;c.push({key:m,value:y,alwaysSet:p.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 i=this._def.errorMap?.(n,r).message??r.defaultError;return n.code==="unrecognized_keys"?{message:R.errToObj(e).message??i}:{message:i}}}:{}})}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 B.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 B.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 B.objectKeys(this.shape)){let i=this.shape[r];e&&!e[r]?n[r]=i:n[r]=i.optional()}return new t({...this._def,shape:()=>n})}required(e){let n={};for(let r of B.objectKeys(this.shape))if(e&&!e[r])n[r]=this.shape[r];else{let o=this.shape[r];for(;o instanceof Ge;)o=o._def.innerType;n[r]=o}return new t({...this._def,shape:()=>n})}keyof(){return Xl(B.objectKeys(this.shape))}};Me.create=(t,e)=>new Me({shape:()=>t,unknownKeys:"strip",catchall:Xe.create(),typeName:D.ZodObject,...G(e)});Me.strictCreate=(t,e)=>new Me({shape:()=>t,unknownKeys:"strict",catchall:Xe.create(),typeName:D.ZodObject,...G(e)});Me.lazycreate=(t,e)=>new Me({shape:t,unknownKeys:"strip",catchall:Xe.create(),typeName:D.ZodObject,...G(e)});var Ft=class extends ${_parse(e){let{ctx:n}=this._processInputParams(e),r=this._def.options;function i(o){for(let a of o)if(a.result.status==="valid")return a.result;for(let a of o)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;let s=o.map(a=>new Oe(a.ctx.common.issues));return k(n,{code:_.invalid_union,unionErrors:s}),P}if(n.common.async)return Promise.all(r.map(async o=>{let s={...n,common:{...n.common,issues:[]},parent:null};return{result:await o._parseAsync({data:n.data,path:n.path,parent:s}),ctx:s}})).then(i);{let o,s=[];for(let l of r){let c={...n,common:{...n.common,issues:[]},parent:null},p=l._parseSync({data:n.data,path:n.path,parent:c});if(p.status==="valid")return p;p.status==="dirty"&&!o&&(o={result:p,ctx:c}),c.common.issues.length&&s.push(c.common.issues)}if(o)return n.common.issues.push(...o.ctx.common.issues),o.result;let a=s.map(l=>new Oe(l));return k(n,{code:_.invalid_union,unionErrors:a}),P}}get options(){return this._def.options}};Ft.create=(t,e)=>new Ft({options:t,typeName:D.ZodUnion,...G(e)});var ht=t=>t instanceof Vt?ht(t.schema):t instanceof $e?ht(t.innerType()):t instanceof Bt?[t.value]:t instanceof jt?t.options:t instanceof qt?B.objectValues(t.enum):t instanceof Wt?ht(t._def.innerType):t instanceof zt?[void 0]:t instanceof Gt?[null]:t instanceof Ge?[void 0,...ht(t.unwrap())]:t instanceof st?[null,...ht(t.unwrap())]:t instanceof Jn||t instanceof Kt?ht(t.unwrap()):t instanceof Xt?ht(t._def.innerType):[],qr=class t extends ${_parse(e){let{ctx:n}=this._processInputParams(e);if(n.parsedType!==C.object)return k(n,{code:_.invalid_type,expected:C.object,received:n.parsedType}),P;let r=this.discriminator,i=n.data[r],o=this.optionsMap.get(i);return o?n.common.async?o._parseAsync({data:n.data,path:n.path,parent:n}):o._parseSync({data:n.data,path:n.path,parent:n}):(k(n,{code:_.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 i=new Map;for(let o of n){let s=ht(o.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(i.has(a))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(a)}`);i.set(a,o)}}return new t({typeName:D.ZodDiscriminatedUnion,discriminator:e,options:n,optionsMap:i,...G(r)})}};function Ss(t,e){let n=it(t),r=it(e);if(t===e)return{valid:!0,data:t};if(n===C.object&&r===C.object){let i=B.objectKeys(e),o=B.objectKeys(t).filter(a=>i.indexOf(a)!==-1),s={...t,...e};for(let a of o){let l=Ss(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 i=[];for(let o=0;o<t.length;o++){let s=t[o],a=e[o],l=Ss(s,a);if(!l.valid)return{valid:!1};i.push(l.data)}return{valid:!0,data:i}}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),i=(o,s)=>{if(Br(o)||Br(s))return P;let a=Ss(o.value,s.value);return a.valid?((jr(o)||jr(s))&&n.dirty(),{status:n.value,value:a.data}):(k(r,{code:_.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(([o,s])=>i(o,s)):i(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,...G(n)});var ot=class t extends ${_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==C.array)return k(r,{code:_.invalid_type,expected:C.array,received:r.parsedType}),P;if(r.data.length<this._def.items.length)return k(r,{code:_.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:_.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());let o=[...r.data].map((s,a)=>{let l=this._def.items[a]||this._def.rest;return l?l._parse(new Fe(r,s,r.path,a)):null}).filter(s=>!!s);return r.common.async?Promise.all(o).then(s=>we.mergeArray(n,s)):we.mergeArray(n,o)}get items(){return this._def.items}rest(e){return new t({...this._def,rest:e})}};ot.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ot({items:t,typeName:D.ZodTuple,rest:null,...G(e)})};var Wr=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:_.invalid_type,expected:C.object,received:r.parsedType}),P;let i=[],o=this._def.keyType,s=this._def.valueType;for(let a in r.data)i.push({key:o._parse(new Fe(r,a,r.path,a)),value:s._parse(new Fe(r,r.data[a],r.path,a)),alwaysSet:a in r.data});return r.common.async?we.mergeObjectAsync(n,i):we.mergeObjectSync(n,i)}get element(){return this._def.valueType}static create(e,n,r){return n instanceof $?new t({keyType:e,valueType:n,typeName:D.ZodRecord,...G(r)}):new t({keyType:St.create(),valueType:e,typeName:D.ZodRecord,...G(n)})}},En=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:_.invalid_type,expected:C.map,received:r.parsedType}),P;let i=this._def.keyType,o=this._def.valueType,s=[...r.data.entries()].map(([a,l],c)=>({key:i._parse(new Fe(r,a,r.path,[c,"key"])),value:o._parse(new Fe(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,p=await l.value;if(c.status==="aborted"||p.status==="aborted")return P;(c.status==="dirty"||p.status==="dirty")&&n.dirty(),a.set(c.value,p.value)}return{status:n.value,value:a}})}else{let a=new Map;for(let l of s){let c=l.key,p=l.value;if(c.status==="aborted"||p.status==="aborted")return P;(c.status==="dirty"||p.status==="dirty")&&n.dirty(),a.set(c.value,p.value)}return{status:n.value,value:a}}}};En.create=(t,e,n)=>new En({valueType:e,keyType:t,typeName:D.ZodMap,...G(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:_.invalid_type,expected:C.set,received:r.parsedType}),P;let i=this._def;i.minSize!==null&&r.data.size<i.minSize.value&&(k(r,{code:_.too_small,minimum:i.minSize.value,type:"set",inclusive:!0,exact:!1,message:i.minSize.message}),n.dirty()),i.maxSize!==null&&r.data.size>i.maxSize.value&&(k(r,{code:_.too_big,maximum:i.maxSize.value,type:"set",inclusive:!0,exact:!1,message:i.maxSize.message}),n.dirty());let o=this._def.valueType;function s(l){let c=new Set;for(let p of l){if(p.status==="aborted")return P;p.status==="dirty"&&n.dirty(),c.add(p.value)}return{status:n.value,value:c}}let a=[...r.data.values()].map((l,c)=>o._parse(new Fe(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,...G(e)});var Xr=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:_.invalid_type,expected:C.function,received:n.parsedType}),P;function r(a,l){return Zn({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,bn(),pt].filter(c=>!!c),issueData:{code:_.invalid_arguments,argumentsError:l}})}function i(a,l){return Zn({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,bn(),pt].filter(c=>!!c),issueData:{code:_.invalid_return_type,returnTypeError:l}})}let o={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([]),p=await a._def.args.parseAsync(l,o).catch(f=>{throw c.addIssue(r(l,f)),c}),m=await Reflect.apply(s,this,p);return await a._def.returns._def.type.parseAsync(m,o).catch(f=>{throw c.addIssue(i(m,f)),c})})}else{let a=this;return Ae(function(...l){let c=a._def.args.safeParse(l,o);if(!c.success)throw new Oe([r(l,c.error)]);let p=Reflect.apply(s,this,c.data),m=a._def.returns.safeParse(p,o);if(!m.success)throw new Oe([i(p,m.error)]);return m.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new t({...this._def,args:ot.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||ot.create([]).rest(ft.create()),returns:n||ft.create(),typeName:D.ZodFunction,...G(r)})}},Vt=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})}};Vt.create=(t,e)=>new Vt({getter:t,typeName:D.ZodLazy,...G(e)});var Bt=class extends ${_parse(e){if(e.data!==this._def.value){let n=this._getOrReturnCtx(e);return k(n,{received:n.data,code:_.invalid_literal,expected:this._def.value}),P}return{status:"valid",value:e.data}}get value(){return this._def.value}};Bt.create=(t,e)=>new Bt({value:t,typeName:D.ZodLiteral,...G(e)});function Xl(t,e){return new jt({values:t,typeName:D.ZodEnum,...G(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:B.joinValues(r),received:n.parsedType,code:_.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:_.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=Xl;var qt=class extends ${_parse(e){let n=B.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==C.string&&r.parsedType!==C.number){let i=B.objectValues(n);return k(r,{expected:B.joinValues(i),received:r.parsedType,code:_.invalid_type}),P}if(this._cache||(this._cache=new Set(B.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let i=B.objectValues(n);return k(r,{received:r.data,code:_.invalid_enum_value,options:i}),P}return Ae(e.data)}get enum(){return this._def.values}};qt.create=(t,e)=>new qt({values:t,typeName:D.ZodNativeEnum,...G(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:_.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(i=>this._def.type.parseAsync(i,{path:n.path,errorMap:n.common.contextualErrorMap})))}};kt.create=(t,e)=>new kt({type:t,typeName:D.ZodPromise,...G(e)});var $e=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),i=this._def.effect||null,o={addIssue:s=>{k(r,s),s.fatal?n.abort():n.dirty()},get path(){return r.path}};if(o.addIssue=o.addIssue.bind(o),i.type==="preprocess"){let s=i.transform(r.data,o);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(i.type==="refinement"){let s=a=>{let l=i.refinement(a,o);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(i.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=i.transform(s.value,o);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(i.transform(s.value,o)).then(a=>({status:n.value,value:a})):P);B.assertNever(i)}};$e.create=(t,e,n)=>new $e({schema:t,typeName:D.ZodEffects,effect:e,...G(n)});$e.createWithPreprocess=(t,e,n)=>new $e({schema:e,effect:{type:"preprocess",transform:t},typeName:D.ZodEffects,...G(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,...G(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,...G(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,...G(e)});var Xt=class extends ${_parse(e){let{ctx:n}=this._processInputParams(e),r={...n,common:{...n.common,issues:[]}},i=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return yn(i)?i.then(o=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new Oe(r.common.issues)},input:r.data})})):{status:"valid",value:i.status==="valid"?i.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,...G(e)});var Sn=class extends ${_parse(e){if(this._getType(e)!==C.nan){let r=this._getOrReturnCtx(e);return k(r,{code:_.invalid_type,expected:C.nan,received:r.parsedType}),P}return{status:"valid",value:e.data}}};Sn.create=t=>new Sn({typeName:D.ZodNaN,...G(t)});var Xp=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}},Qn=class t extends ${_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{let o=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?P:o.status==="dirty"?(n.dirty(),Lt(o.value)):this._def.out._parseAsync({data:o.value,path:r.path,parent:r})})();{let i=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?P:i.status==="dirty"?(n.dirty(),{status:"dirty",value:i.value}):this._def.out._parseSync({data:i.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=i=>(Tt(i)&&(i.value=Object.freeze(i.value)),i);return yn(n)?n.then(i=>r(i)):r(n)}unwrap(){return this._def.innerType}};Kt.create=(t,e)=>new Kt({innerType:t,typeName:D.ZodReadonly,...G(e)});function Bl(t,e){let n=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof n=="string"?{message:n}:n}function Kl(t,e={},n){return t?At.create().superRefine((r,i)=>{let o=t(r);if(o instanceof Promise)return o.then(s=>{if(!s){let a=Bl(e,r),l=a.fatal??n??!0;i.addIssue({code:"custom",...a,fatal:l})}});if(!o){let s=Bl(e,r),a=s.fatal??n??!0;i.addIssue({code:"custom",...s,fatal:a})}}):At.create()}var Kp={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 Yp=(t,e={message:`Input not instance of ${t.name}`})=>Kl(n=>n instanceof t,e),Yl=St.create,Zl=Pt.create,Zp=Sn.create,Jp=Dt.create,Jl=Ut.create,Qp=Ht.create,eh=wn.create,th=zt.create,nh=Gt.create,rh=At.create,ih=ft.create,oh=Xe.create,sh=_n.create,ah=mt.create,lh=Me.create,ch=Me.strictCreate,dh=Ft.create,uh=qr.create,ph=$t.create,hh=ot.create,fh=Wr.create,mh=En.create,gh=Tn.create,vh=Xr.create,bh=Vt.create,yh=Bt.create,xh=jt.create,wh=qt.create,_h=kt.create,Eh=$e.create,Th=Ge.create,Sh=st.create,Ah=$e.createWithPreprocess,kh=Qn.create,Ch=()=>Yl().optional(),Ih=()=>Zl().optional(),Rh=()=>Jl().optional(),Nh={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 Oh=P;var Mh=d.object({name:d.string(),arguments:d.string()}),Lh=d.object({id:d.string(),type:d.literal("function"),function:Mh,encryptedValue:d.string().optional()}),Kr=d.object({id:d.string(),role:d.string(),content:d.string().optional(),name:d.string().optional(),encryptedValue:d.string().optional()}),Ph=d.object({type:d.literal("text"),text:d.string()}),Dh=d.object({type:d.literal("data"),value:d.string(),mimeType:d.string()}),Uh=d.object({type:d.literal("url"),value:d.string(),mimeType:d.string().optional()}),Yr=d.discriminatedUnion("type",[Dh,Uh]),Hh=d.object({type:d.literal("image"),source:Yr,metadata:d.unknown().optional()}),zh=d.object({type:d.literal("audio"),source:Yr,metadata:d.unknown().optional()}),Gh=d.object({type:d.literal("video"),source:Yr,metadata:d.unknown().optional()}),Fh=d.object({type:d.literal("document"),source:Yr,metadata:d.unknown().optional()});var Ql=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"]})},ex=Ql.superRefine((t,e)=>{ec(t,e)}),$h=d.discriminatedUnion("type",[Ph,Hh,zh,Gh,Fh,Ql]),Vh=$h.superRefine((t,e)=>{t.type==="binary"&&ec(t,e)}),Bh=Kr.extend({role:d.literal("developer"),content:d.string()}),jh=Kr.extend({role:d.literal("system"),content:d.string()}),qh=Kr.extend({role:d.literal("assistant"),content:d.string().optional(),toolCalls:d.array(Lh).optional()}),Wh=Kr.extend({role:d.literal("user"),content:d.union([d.string(),d.array(Vh)])}),Xh=d.object({id:d.string(),content:d.string(),role:d.literal("tool"),toolCallId:d.string(),error:d.string().optional(),encryptedValue:d.string().optional()}),Kh=d.object({id:d.string(),role:d.literal("activity"),activityType:d.string(),content:d.record(d.any())}),Yh=d.object({id:d.string(),role:d.literal("reasoning"),content:d.string(),encryptedValue:d.string().optional()}),tc=d.discriminatedUnion("role",[Bh,jh,qh,Wh,Xh,Kh,Yh]),tx=d.union([d.literal("developer"),d.literal("system"),d.literal("assistant"),d.literal("user"),d.literal("tool"),d.literal("activity"),d.literal("reasoning")]),Zh=d.object({description:d.string(),value:d.string()}),nc=d.object({name:d.string(),description:d.string(),parameters:d.any(),metadata:d.record(d.any()).optional()}),Jh=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()}),Qh=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(tc),tools:d.array(nc),context:d.array(Zh),forwardedProps:d.any(),resume:d.array(Qh).optional()}),tf=d.any(),te=class extends Error{constructor(t){super(t)}},As=class extends te{constructor(){super("Connect not implemented. This method is not supported by the current agent.")}},nf=d.object({name:d.string(),description:d.string().optional()}),rf=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()}),of=d.object({streaming:d.boolean().optional(),websocket:d.boolean().optional(),httpBinary:d.boolean().optional(),pushNotifications:d.boolean().optional(),resumable:d.boolean().optional()}),sf=d.object({supported:d.boolean().optional(),items:d.array(nc).optional(),parallelCalls:d.boolean().optional(),clientProvided:d.boolean().optional()}),af=d.object({structuredOutput:d.boolean().optional(),supportedMimeTypes:d.array(d.string()).optional()}),lf=d.object({snapshots:d.boolean().optional(),deltas:d.boolean().optional(),memory:d.boolean().optional(),persistentState:d.boolean().optional()}),cf=d.object({supported:d.boolean().optional(),delegation:d.boolean().optional(),handoffs:d.boolean().optional(),subAgents:d.array(nf).optional()}),df=d.object({supported:d.boolean().optional(),streaming:d.boolean().optional(),encrypted:d.boolean().optional()}),uf=d.object({image:d.boolean().optional(),audio:d.boolean().optional(),video:d.boolean().optional(),pdf:d.boolean().optional(),file:d.boolean().optional()}),pf=d.object({image:d.boolean().optional(),audio:d.boolean().optional()}),hf=d.object({input:uf.optional(),output:pf.optional()}),ff=d.object({codeExecution:d.boolean().optional(),sandboxed:d.boolean().optional(),maxIterations:d.number().optional(),maxExecutionTime:d.number().optional()}),mf=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()}),nx=d.object({identity:rf.optional(),transport:of.optional(),tools:sf.optional(),output:af.optional(),state:lf.optional(),multiAgent:cf.optional(),reasoning:df.optional(),multimodal:hf.optional(),execution:ff.optional(),humanInTheLoop:mf.optional(),custom:d.record(d.unknown()).optional()}),rc=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(),gf=X.extend({type:d.literal(v.TEXT_MESSAGE_START),messageId:d.string(),role:rc.default("assistant"),name:d.string().optional()}),ic=X.extend({type:d.literal(v.TEXT_MESSAGE_CONTENT),messageId:d.string(),delta:d.string()}),vf=X.extend({type:d.literal(v.TEXT_MESSAGE_END),messageId:d.string()}),bf=X.extend({type:d.literal(v.TEXT_MESSAGE_CHUNK),messageId:d.string().optional(),role:rc.optional(),delta:d.string().optional(),name:d.string().optional()}),yf=X.extend({type:d.literal(v.THINKING_TEXT_MESSAGE_START)}),xf=ic.omit({messageId:!0,type:!0}).extend({type:d.literal(v.THINKING_TEXT_MESSAGE_CONTENT)}),wf=X.extend({type:d.literal(v.THINKING_TEXT_MESSAGE_END)}),_f=X.extend({type:d.literal(v.TOOL_CALL_START),toolCallId:d.string(),toolCallName:d.string(),parentMessageId:d.string().optional()}),Ef=X.extend({type:d.literal(v.TOOL_CALL_ARGS),toolCallId:d.string(),delta:d.string()}),Tf=X.extend({type:d.literal(v.TOOL_CALL_END),toolCallId:d.string()}),Sf=X.extend({messageId:d.string(),type:d.literal(v.TOOL_CALL_RESULT),toolCallId:d.string(),content:d.string(),role:d.literal("tool").optional()}),Af=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()}),kf=X.extend({type:d.literal(v.THINKING_START),title:d.string().optional()}),Cf=X.extend({type:d.literal(v.THINKING_END)}),If=X.extend({type:d.literal(v.STATE_SNAPSHOT),snapshot:tf}),Rf=X.extend({type:d.literal(v.STATE_DELTA),delta:d.array(d.any())}),Nf=X.extend({type:d.literal(v.MESSAGES_SNAPSHOT),messages:d.array(tc)}),Of=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)}),Mf=X.extend({type:d.literal(v.ACTIVITY_DELTA),messageId:d.string(),activityType:d.string(),patch:d.array(d.any())}),Lf=X.extend({type:d.literal(v.RAW),event:d.any(),source:d.string().optional()}),Pf=X.extend({type:d.literal(v.CUSTOM),name:d.string(),value:d.any()}),Df=X.extend({type:d.literal(v.RUN_STARTED),threadId:d.string(),runId:d.string(),parentRunId:d.string().optional(),input:ef.optional()}),Uf=d.object({type:d.literal("success")}).strict(),Hf=d.object({type:d.literal("interrupt"),interrupts:d.array(Jh).min(1)}).strict(),zf=d.discriminatedUnion("type",[Uf,Hf]),Gf=X.extend({type:d.literal(v.RUN_FINISHED),threadId:d.string(),runId:d.string(),result:d.any().optional(),outcome:zf.nullable().optional().transform(t=>t??void 0)}),Ff=X.extend({type:d.literal(v.RUN_ERROR),message:d.string(),code:d.string().optional()}),$f=X.extend({type:d.literal(v.STEP_STARTED),stepName:d.string()}),Vf=X.extend({type:d.literal(v.STEP_FINISHED),stepName:d.string()}),Bf=d.union([d.literal("tool-call"),d.literal("message")]),jf=X.extend({type:d.literal(v.REASONING_START),messageId:d.string()}),qf=X.extend({type:d.literal(v.REASONING_MESSAGE_START),messageId:d.string(),role:d.literal("reasoning")}),Wf=X.extend({type:d.literal(v.REASONING_MESSAGE_CONTENT),messageId:d.string(),delta:d.string()}),Xf=X.extend({type:d.literal(v.REASONING_MESSAGE_END),messageId:d.string()}),Kf=X.extend({type:d.literal(v.REASONING_MESSAGE_CHUNK),messageId:d.string().optional(),delta:d.string().optional()}),Yf=X.extend({type:d.literal(v.REASONING_END),messageId:d.string()}),Zf=X.extend({type:d.literal(v.REASONING_ENCRYPTED_VALUE),subtype:Bf,entityId:d.string(),encryptedValue:d.string()}),Zr=d.discriminatedUnion("type",[gf,ic,vf,bf,kf,Cf,yf,xf,wf,_f,Ef,Tf,Af,Sf,If,Rf,Nf,Of,Mf,Lf,Pf,Df,Gf,Ff,$f,Vf,jf,qf,Wf,Xf,Kf,Yf,Zf]);var ks={};ls(ks,{JsonPatchError:()=>he,_areEquals:()=>nr,applyOperation:()=>Yt,applyPatch:()=>ii,applyReducer:()=>nm,deepClone:()=>em,getValueByPointer:()=>ni,validate:()=>sc,validator:()=>ri});var Jf=(function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var o in i)i.hasOwnProperty(o)&&(r[o]=i[o])},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)}})(),Qf=Object.prototype.hasOwnProperty;function Qr(t,e){return Qf.call(t,e)}function ei(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 i in t)Qr(t,i)&&r.push(i);return r}function _e(t){switch(typeof t){case"object":return JSON.parse(JSON.stringify(t));case"undefined":return null;default:return t}}function ti(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 er(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function Jr(t){if(t===void 0)return!0;if(t){if(Array.isArray(t)){for(var e=0,n=t.length;e<n;e++)if(Jr(t[e]))return!0}else if(typeof t=="object"){for(var r=ei(t),i=r.length,o=0;o<i;o++)if(Jr(t[r[o]]))return!0}}return!1}function oc(t,e){var n=[t];for(var r in e){var i=typeof e[r]=="object"?JSON.stringify(e[r],null,2):e[r];typeof i<"u"&&n.push(r+": "+i)}return n.join(`
|
|
2
|
-
`)}var tr=(function(t){Jf(e,t);function e(n,r,i,o,s){var a=this.constructor,l=t.call(this,oc(n,{name:r,index:i,operation:o,tree:s}))||this;return l.name=r,l.index=i,l.operation=o,l.tree=s,Object.setPrototypeOf(l,a.prototype),l.message=oc(n,{name:r,index:i,operation:o,tree:s}),l}return e})(Error);var he=tr,em=_e,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=ni(n,this.path);r&&(r=_e(r));var i=Yt(n,{op:"remove",path:this.from}).removed;return Yt(n,{op:"add",path:this.path,value:i}),{newDocument:n,removed:r}},copy:function(t,e,n){var r=ni(n,this.from);return Yt(n,{op:"add",path:this.path,value:_e(r)}),{newDocument:n}},test:function(t,e,n){return{newDocument:n,test:nr(t[e],this.value)}},_get:function(t,e,n){return this.value=t[e],{newDocument:n}}},tm={add:function(t,e,n){return ti(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 ni(t,e){if(e=="")return t;var n={op:"_get",path:e};return Yt(t,n),n.value}function Yt(t,e,n,r,i,o){if(n===void 0&&(n=!1),r===void 0&&(r=!0),i===void 0&&(i=!0),o===void 0&&(o=0),n&&(typeof n=="function"?n(e,0,t,e.path):ri(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=ni(t,e.from),e.op==="move"&&(s.removed=t),s;if(e.op==="test"){if(s.test=nr(t,e.value),s.test===!1)throw new he("Test operation failed","TEST_OPERATION_FAILED",o,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",o,e,t);return s}}else{r||(t=_e(t));var a=e.path||"",l=a.split("/"),c=t,p=1,m=l.length,y=void 0,f=void 0,h=void 0;for(typeof n=="function"?h=n:h=ri;;){if(f=l[p],f&&f.indexOf("~")!=-1&&(f=er(f)),i&&(f=="__proto__"||f=="prototype"&&p>0&&l[p-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,p).join("/"):p==m-1&&(y=e.path),y!==void 0&&h(e,0,t,y)),p++,Array.isArray(c)){if(f==="-")f=c.length;else{if(n&&!ti(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",o,e,t);ti(f)&&(f=~~f)}if(p>=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",o,e,t);var s=tm[e.op].call(e,c,f,t);if(s.test===!1)throw new he("Test operation failed","TEST_OPERATION_FAILED",o,e,t);return s}}else if(p>=m){var s=An[e.op].call(e,c,f,t);if(s.test===!1)throw new he("Test operation failed","TEST_OPERATION_FAILED",o,e,t);return s}if(c=c[f],n&&p<m&&(!c||typeof c!="object"))throw new he("Cannot perform operation at the desired path","OPERATION_PATH_UNRESOLVABLE",o,e,t)}}}function ii(t,e,n,r,i){if(r===void 0&&(r=!0),i===void 0&&(i=!0),n&&!Array.isArray(e))throw new he("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");r||(t=_e(t));for(var o=new Array(e.length),s=0,a=e.length;s<a;s++)o[s]=Yt(t,e[s],n,!0,i,s),t=o[s].newDocument;return o.newDocument=t,o}function nm(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 ri(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")&&Jr(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 i=t.path.split("/").length,o=r.split("/").length;if(i!==o+1&&i!==o)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=sc([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 sc(t,e,n){try{if(!Array.isArray(t))throw new he("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(e)ii(_e(e),_e(t),n||!0);else{n=n||ri;for(var r=0;r<t.length;r++)n(t[r],r,e,void 0)}}catch(i){if(i instanceof he)return i;throw i}}function nr(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),i,o,s;if(n&&r){if(o=t.length,o!=e.length)return!1;for(i=o;i--!==0;)if(!nr(t[i],e[i]))return!1;return!0}if(n!=r)return!1;var a=Object.keys(t);if(o=a.length,o!==Object.keys(e).length)return!1;for(i=o;i--!==0;)if(!e.hasOwnProperty(a[i]))return!1;for(i=o;i--!==0;)if(s=a[i],!nr(t[s],e[s]))return!1;return!0}return t!==t&&e!==e}var Ns={};ls(Ns,{compare:()=>dm,generate:()=>Cs,observe:()=>cm,unobserve:()=>lm});var Is=new WeakMap,rm=(function(){function t(e){this.observers=new Map,this.obj=e}return t})(),im=(function(){function t(e,n){this.callback=e,this.observer=n}return t})();function om(t){return Is.get(t)}function sm(t,e){return t.observers.get(e)}function am(t,e){t.observers.delete(e.callback)}function lm(t,e){e.unobserve()}function cm(t,e){var n=[],r,i=om(t);if(!i)i=new rm(t),Is.set(t,i);else{var o=sm(i,e);r=o&&o.observer}if(r)return r;if(r={},i.value=_e(t),e){r.callback=e,r.next=null;var s=function(){Cs(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(){Cs(r),clearTimeout(r.next),am(i,r),typeof window<"u"&&(window.removeEventListener("mouseup",a),window.removeEventListener("keyup",a),window.removeEventListener("mousedown",a),window.removeEventListener("keydown",a),window.removeEventListener("change",a))},i.observers.set(e,new im(e,r)),r}function Cs(t,e){e===void 0&&(e=!1);var n=Is.get(t.object);Rs(n.value,t.object,t.patches,"",e),t.patches.length&&ii(n.value,t.patches);var r=t.patches;return r.length>0&&(t.patches=[],t.callback&&t.callback(r)),r}function Rs(t,e,n,r,i){if(e!==t){typeof e.toJSON=="function"&&(e=e.toJSON());for(var o=ei(e),s=ei(t),a=!1,l=!1,c=s.length-1;c>=0;c--){var p=s[c],m=t[p];if(Qr(e,p)&&!(e[p]===void 0&&m!==void 0&&Array.isArray(e)===!1)){var y=e[p];typeof m=="object"&&m!=null&&typeof y=="object"&&y!=null&&Array.isArray(m)===Array.isArray(y)?Rs(m,y,n,r+"/"+at(p),i):m!==y&&(a=!0,i&&n.push({op:"test",path:r+"/"+at(p),value:_e(m)}),n.push({op:"replace",path:r+"/"+at(p),value:_e(y)}))}else Array.isArray(t)===Array.isArray(e)?(i&&n.push({op:"test",path:r+"/"+at(p),value:_e(m)}),n.push({op:"remove",path:r+"/"+at(p)}),l=!0):(i&&n.push({op:"test",path:r,value:t}),n.push({op:"replace",path:r,value:e}),a=!0)}if(!(!l&&o.length==s.length))for(var c=0;c<o.length;c++){var p=o[c];!Qr(t,p)&&e[p]!==void 0&&n.push({op:"add",path:r+"/"+at(p),value:_e(e[p])})}}}function dm(t,e,n){n===void 0&&(n=!1);var r=[];return Rs(t,e,r,"",n),r}var oi=Object.assign({},ks,Ns,{JsonPatchError:tr,deepClone:_e,escapePathComponent:at,unescapePathComponent:er});var Os=function(t,e){return Os=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(n[i]=r[i])},Os(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");Os(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}function ac(t,e,n,r){function i(o){return o instanceof n?o:new n(function(s){s(o)})}return new(n||(n=Promise))(function(o,s){function a(p){try{c(r.next(p))}catch(m){s(m)}}function l(p){try{c(r.throw(p))}catch(m){s(m)}}function c(p){p.done?o(p.value):i(p.value).then(a,l)}c((r=r.apply(t,e||[])).next())})}function si(t,e){var n={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},r,i,o,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(p){return l([c,p])}}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,i&&(o=c[0]&2?i.return:c[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,c[1])).done)return o;switch(i=0,o&&(c=[c[0]&2,o.value]),c[0]){case 0:case 1:o=c;break;case 4:return n.label++,{value:c[1],done:!1};case 5:n.label++,i=c[1],c=[0];continue;case 7:c=n.ops.pop(),n.trys.pop();continue;default:if(o=n.trys,!(o=o.length>0&&o[o.length-1])&&(c[0]===6||c[0]===2)){n=0;continue}if(c[0]===3&&(!o||c[1]>o[0]&&c[1]<o[3])){n.label=c[1];break}if(c[0]===6&&n.label<o[1]){n.label=o[1],o=c;break}if(o&&n.label<o[2]){n.label=o[2],n.ops.push(c);break}o[2]&&n.ops.pop(),n.trys.pop();continue}c=e.call(t,n)}catch(p){c=[6,p],i=0}finally{r=o=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),i,o=[],s;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)o.push(i.value)}catch(a){s={error:a}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(s)throw s.error}}return o}function Cn(t,e,n){if(n||arguments.length===2)for(var r=0,i=e.length,o;r<i;r++)(o||!(r in e))&&(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);return t.concat(o||Array.prototype.slice.call(e))}function Zt(t){return this instanceof Zt?(this.v=t,this):new Zt(t)}function lc(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(t,e||[]),i,o=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",s),i[Symbol.asyncIterator]=function(){return this},i;function s(f){return function(h){return Promise.resolve(h).then(f,m)}}function a(f,h){r[f]&&(i[f]=function(g){return new Promise(function(x,S){o.push([f,g,x,S])>1||l(f,g)})},h&&(i[f]=h(i[f])))}function l(f,h){try{c(r[f](h))}catch(g){y(o[0][3],g)}}function c(f){f.value instanceof Zt?Promise.resolve(f.value.v).then(p,m):y(o[0][2],f)}function p(f){l("next",f)}function m(f){l("throw",f)}function y(f,h){f(h),o.shift(),o.length&&l(o[0][0],o[0][1])}}function cc(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(o){n[o]=t[o]&&function(s){return new Promise(function(a,l){s=t[o](s),i(a,l,s.done,s.value)})}}function i(o,s,a,l){Promise.resolve(l).then(function(c){o({value:c,done:a})},s)}}function V(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 ai=In(function(t){return function(n){t(this),this.message=n?n.length+` errors occurred during unsubscription:
|
|
3
|
-
`+n.map(function(r,
|
|
4
|
-
`):"",this.name="UnsubscriptionError",this.errors=n}});function rr(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,i,o;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 p=this.initialTeardown;if(V(p))try{p()}catch(g){o=g instanceof ai?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{dc(h)}catch(g){o=o??[],g instanceof ai?o=Cn(Cn([],kn(o)),kn(g.errors)):o.push(g)}}}catch(g){r={error:g}}finally{try{f&&!f.done&&(i=y.return)&&i.call(y)}finally{if(r)throw r.error}}}if(o)throw new ai(o)}},t.prototype.add=function(e){var n;if(e&&e!==this)if(this.closed)dc(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)&&rr(n,e)},t.prototype.remove=function(e){var n=this._finalizers;n&&rr(n,e),e instanceof t&&e._removeParent(this)},t.EMPTY=(function(){var e=new t;return e.closed=!0,e})(),t})();var Ms=Rn.EMPTY;function li(t){return t instanceof Rn||t&&"closed"in t&&V(t.remove)&&V(t.add)&&V(t.unsubscribe)}function dc(t){V(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 i=Nn.delegate;return i?.setTimeout?i.setTimeout.apply(i,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 ci(t){Nn.setTimeout(function(){var e=Ke.onUnhandledError;if(e)e(t);else throw t})}function ir(){}var uc=(function(){return Ls("C",void 0,void 0)})();function pc(t){return Ls("E",void 0,t)}function hc(t){return Ls("N",t,void 0)}function Ls(t,e,n){return{kind:t,value:e,error:n}}var Jt=null;function On(t){if(Ke.useDeprecatedSynchronousErrorHandling){var e=!Jt;if(e&&(Jt={errorThrown:!1,error:null}),t(),e){var n=Jt,r=n.errorThrown,i=n.error;if(Jt=null,r)throw i}}else t()}function fc(t){Ke.useDeprecatedSynchronousErrorHandling&&Jt&&(Jt.errorThrown=!0,Jt.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,li(n)&&n.add(r)):r.destination=fm,r}return e.create=function(n,r,i){return new ui(n,r,i)},e.prototype.next=function(n){this.isStopped?Ds(hc(n),this):this._next(n)},e.prototype.error=function(n){this.isStopped?Ds(pc(n),this):(this.isStopped=!0,this._error(n))},e.prototype.complete=function(){this.isStopped?Ds(uc,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 um=Function.prototype.bind;function Ps(t,e){return um.call(t,e)}var pm=(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){di(r)}},t.prototype.error=function(e){var n=this.partialObserver;if(n.error)try{n.error(e)}catch(r){di(r)}else di(e)},t.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(n){di(n)}},t})(),ui=(function(t){lt(e,t);function e(n,r,i){var o=t.call(this)||this,s;if(V(n)||!n)s={next:n??void 0,error:r??void 0,complete:i??void 0};else{var a;o&&Ke.useDeprecatedNextContext?(a=Object.create(n),a.unsubscribe=function(){return o.unsubscribe()},s={next:n.next&&Ps(n.next,a),error:n.error&&Ps(n.error,a),complete:n.complete&&Ps(n.complete,a)}):s=n}return o.destination=new pm(s),o}return e})(or);function di(t){Ke.useDeprecatedSynchronousErrorHandling?fc(t):ci(t)}function hm(t){throw t}function Ds(t,e){var n=Ke.onStoppedNotification;n&&Nn.setTimeout(function(){return n(t,e)})}var fm={closed:!0,next:ir,error:hm,complete:ir};var Mn=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Ln(t){return t}function pi(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Us(t)}function Us(t){return t.length===0?Ln:t.length===1?t[0]:function(n){return t.reduce(function(r,i){return i(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 i=this,o=gm(e)?e:new ui(e,n,r);return On(function(){var s=i,a=s.operator,l=s.source;o.add(a?a.call(o,l):l?i._subscribe(o):i._trySubscribe(o))}),o},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=mc(n),new n(function(i,o){var s=new ui({next:function(a){try{e(a)}catch(l){o(l),s.unsubscribe()}},error:o,complete:i});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 Us(e)(this)},t.prototype.toPromise=function(e){var n=this;return e=mc(e),new e(function(r,i){var o;n.subscribe(function(s){return o=s},function(s){return i(s)},function(){return r(o)})})},t.create=function(e){return new t(e)},t})();function mc(t){var e;return(e=t??Ke.Promise)!==null&&e!==void 0?e:Promise}function mm(t){return t&&V(t.next)&&V(t.error)&&V(t.complete)}function gm(t){return t&&t instanceof or||mm(t)&&li(t)}function vm(t){return V(t?.lift)}function fe(t){return function(e){if(vm(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,i){return new bm(t,e,n,r,i)}var bm=(function(t){lt(e,t);function e(n,r,i,o,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(p){n.error(p)}}:t.prototype._next,l._error=o?function(c){try{o(c)}catch(p){n.error(p)}finally{this.unsubscribe()}}:t.prototype._error,l._complete=i?function(){try{i()}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 gc=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 vc(this,this);return r.operator=n,r},e.prototype._throwIfClosed=function(){if(this.closed)throw new gc},e.prototype.next=function(n){var r=this;On(function(){var i,o;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){i={error:c}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.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 i=r.observers;i.length;)i.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,i=this,o=i.hasError,s=i.isStopped,a=i.observers;return o||s?Ms:(this.currentObservers=null,a.push(n),new Rn(function(){r.currentObservers=null,rr(a,n)}))},e.prototype._checkFinalizedStatuses=function(n){var r=this,i=r.hasError,o=r.thrownError,s=r.isStopped;i?n.error(o):s&&n.complete()},e.prototype.asObservable=function(){var n=new ne;return n.source=this,n},e.create=function(n,r){return new vc(n,r)},e})(ne);var vc=(function(t){lt(e,t);function e(n,r){var i=t.call(this)||this;return i.destination=n,i.source=r,i}return e.prototype.next=function(n){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.next)===null||i===void 0||i.call(r,n)},e.prototype.error=function(n){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.error)===null||i===void 0||i.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,i;return(i=(r=this.source)===null||r===void 0?void 0:r.subscribe(n))!==null&&i!==void 0?i:Ms},e})(ct);var Hs={now:function(){return(Hs.delegate||Date).now()},delegate:void 0};var hi=(function(t){lt(e,t);function e(n,r,i){n===void 0&&(n=1/0),r===void 0&&(r=1/0),i===void 0&&(i=Hs);var o=t.call(this)||this;return o._bufferSize=n,o._windowTime=r,o._timestampProvider=i,o._buffer=[],o._infiniteTimeWindow=!0,o._infiniteTimeWindow=r===1/0,o._bufferSize=Math.max(1,n),o._windowTime=Math.max(1,r),o}return e.prototype.next=function(n){var r=this,i=r.isStopped,o=r._buffer,s=r._infiniteTimeWindow,a=r._timestampProvider,l=r._windowTime;i||(o.push(n),!s&&o.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),i=this,o=i._infiniteTimeWindow,s=i._buffer,a=s.slice(),l=0;l<a.length&&!n.closed;l+=o?1:2)n.next(a[l]);return this._checkFinalizedStatuses(n),r},e.prototype._trimBuffer=function(){var n=this,r=n._bufferSize,i=n._timestampProvider,o=n._buffer,s=n._infiniteTimeWindow,a=(s?1:2)*r;if(r<1/0&&a<o.length&&o.splice(0,o.length-a),!s){for(var l=i.now(),c=0,p=1;p<o.length&&o[p]<=l;p+=2)c=p;c&&o.splice(0,c+1)}},e})(ct);var fi=new ne(function(t){return t.complete()});function bc(t){return t&&V(t.schedule)}function ym(t){return t[t.length-1]}function yc(t){return bc(ym(t))?t.pop():void 0}var mi=(function(t){return t&&typeof t.length=="number"&&typeof t!="function"});function gi(t){return V(t?.then)}function vi(t){return V(t[Mn])}function bi(t){return Symbol.asyncIterator&&V(t?.[Symbol.asyncIterator])}function yi(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 xi=xm();function wi(t){return V(t?.[xi])}function _i(t){return lc(this,arguments,function(){var n,r,i,o;return si(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(),i=r.value,o=r.done,o?[4,Zt(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,Zt(i)];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 Ei(t){return V(t?.getReader)}function ve(t){if(t instanceof ne)return t;if(t!=null){if(vi(t))return wm(t);if(mi(t))return _m(t);if(gi(t))return Em(t);if(bi(t))return xc(t);if(wi(t))return Tm(t);if(Ei(t))return Sm(t)}throw yi(t)}function wm(t){return new ne(function(e){var n=t[Mn]();if(V(n.subscribe))return n.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function _m(t){return new ne(function(e){for(var n=0;n<t.length&&!e.closed;n++)e.next(t[n]);e.complete()})}function Em(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,ci)})}function Tm(t){return new ne(function(e){var n,r;try{for(var i=gt(t),o=i.next();!o.done;o=i.next()){var s=o.value;if(e.next(s),e.closed)return}}catch(a){n={error:a}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}e.complete()})}function xc(t){return new ne(function(e){Am(t,e).catch(function(n){return e.error(n)})})}function Sm(t){return xc(_i(t))}function Am(t,e){var n,r,i,o;return ac(this,void 0,void 0,function(){var s,a;return si(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),n=cc(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(),i={error:a},[3,11];case 6:return l.trys.push([6,,9,10]),r&&!r.done&&(o=n.return)?[4,o.call(n)]:[3,8];case 7:l.sent(),l.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}})})}function Ve(t,e,n,r,i){r===void 0&&(r=0),i===void 0&&(i=!1);var o=e.schedule(function(){n(),i?t.add(this.schedule(null,r)):this.unsubscribe()},r);if(t.add(o),!i)return o}function Ti(t,e){return e===void 0&&(e=0),fe(function(n,r){n.subscribe(ge(r,function(i){return Ve(r,t,function(){return r.next(i)},e)},function(){return Ve(r,t,function(){return r.complete()},e)},function(i){return Ve(r,t,function(){return r.error(i)},e)}))})}function Si(t,e){return e===void 0&&(e=0),fe(function(n,r){r.add(t.schedule(function(){return n.subscribe(r)},e))})}function wc(t,e){return ve(t).pipe(Si(e),Ti(e))}function _c(t,e){return ve(t).pipe(Si(e),Ti(e))}function Ec(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 Tc(t,e){return new ne(function(n){var r;return Ve(n,e,function(){r=t[xi](),Ve(n,e,function(){var i,o,s;try{i=r.next(),o=i.value,s=i.done}catch(a){n.error(a);return}s?n.complete():n.next(o)},0,!0)}),function(){return V(r?.return)&&r.return()}})}function Ai(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(i){i.done?n.complete():n.next(i.value)})},0,!0)})})}function Sc(t,e){return Ai(_i(t),e)}function Ac(t,e){if(t!=null){if(vi(t))return wc(t,e);if(mi(t))return Ec(t,e);if(gi(t))return _c(t,e);if(bi(t))return Ai(t,e);if(wi(t))return Tc(t,e);if(Ei(t))return Sc(t,e)}throw yi(t)}function Qt(t,e){return e?Ac(t,e):ve(t)}function ue(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=yc(t);return Qt(t,n)}function re(t,e){var n=V(t)?t:function(){return t},r=function(i){return i.error(n())};return new ne(e?function(i){return e.schedule(r,0,i)}:r)}var kc=In(function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}});function ki(t,e){var n=typeof e=="object";return new Promise(function(r,i){var o=!1,s;t.subscribe({next:function(a){s=a,o=!0},error:i,complete:function(){o?r(s):n?r(e.defaultValue):i(new kc)}})})}function en(t,e){return fe(function(n,r){var i=0;n.subscribe(ge(r,function(o){r.next(t.call(e,o,i++))}))})}function Cc(t,e,n,r,i,o,s,a){var l=[],c=0,p=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){o&&e.next(g),c++;var x=!1;ve(n(g,p++)).subscribe(ge(e,function(S){i?.(S),o?f(S):e.next(S)},function(){x=!0},void 0,function(){if(x)try{c--;for(var S=function(){var E=l.shift();s?Ve(e,s,function(){return h(E)}):h(E)};l.length&&c<r;)S();y()}catch(E){e.error(E)}}))};return t.subscribe(ge(e,f,function(){m=!0,y()})),function(){a?.()}}function Le(t,e,n){return n===void 0&&(n=1/0),V(e)?Le(function(r,i){return en(function(o,s){return e(r,o,i,s)})(ve(t(r,i)))},n):(typeof e=="number"&&(n=e),fe(function(r,i){return Cc(r,i,t,n)}))}function zs(t){return t===void 0&&(t=1/0),Le(Ln,t)}function Ci(t){return new ne(function(e){ve(t()).subscribe(e)})}function sr(t){return fe(function(e,n){var r=null,i=!1,o;r=e.subscribe(ge(n,void 0,void 0,function(s){o=ve(t(s,sr(t)(e))),r?(r.unsubscribe(),r=null,o.subscribe(n)):i=!0})),i&&(r.unsubscribe(),r=null,o.subscribe(n))})}function Ii(t,e){return V(e)?Le(t,e,1):Le(t,1)}function Gs(t){return fe(function(e,n){var r=!1;e.subscribe(ge(n,function(i){r=!0,n.next(i)},function(){r||n.next(t),n.complete()}))})}function tn(t){return fe(function(e,n){try{e.subscribe(n)}finally{n.add(t)}})}function Fs(t,e){return fe(function(n,r){var i=null,o=0,s=!1,a=function(){return s&&!i&&r.complete()};n.subscribe(ge(r,function(l){i?.unsubscribe();var c=0,p=o++;ve(t(l,p)).subscribe(i=ge(r,function(m){return r.next(e?e(l,m,p,c++):m)},function(){i=null,a()}))},function(){s=!0,a()}))})}function Ri(t){return fe(function(e,n){ve(t).subscribe(ge(n,function(){return n.complete()},ir)),!n.closed&&e.subscribe(n)})}function $s(t,e,n){var r=V(t)||e||n?{next:t,error:e,complete:n}:t;return r?fe(function(i,o){var s;(s=r.subscribe)===null||s===void 0||s.call(r);var a=!0;i.subscribe(ge(o,function(l){var c;(c=r.next)===null||c===void 0||c.call(r,l),o.next(l)},function(){var l;a=!1,(l=r.complete)===null||l===void 0||l.call(r),o.complete()},function(l){var c;a=!1,(c=r.error)===null||c===void 0||c.call(r,l),o.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 Ic(t){return` \r
|
|
5
|
-
`.indexOf(t)>=0}function Ni(t){for(var e=["topLevel"],n=0,r,i,o,s=function(E){return e.push(E)},a=function(E){return e[e.length-1]=E},l=function(E){r==null&&(r=n,i=e.length,o=E)},c=function(E){E===o&&(r=void 0,i=void 0,o=void 0)},p=function(){return e.pop()},m=function(){return n--},y=function(E){if("0"<=E&&E<="9"){s("number");return}switch(E){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'"':p();break;case"\\":l("stringEscape"),s("stringEscaped");break}break;case"stringEscaped":h==="u"?s("stringUnicode"):(c("stringEscape"),p());break;case"stringUnicode":n-t.lastIndexOf("u",n)===4&&(c("stringEscape"),p());break;case"number":h==="."?a("numberNeedsDigit"):h==="e"||h==="E"?a("numberNeedsExponent"):(h<"0"||h>"9")&&(m(),p());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(),p());break;case"arrayNeedsValue":h==="]"?p():Ic(h)||(c("collectionItem"),a("arrayNeedsComma"),y(h));break;case"arrayNeedsComma":h==="]"?p():h===","&&(l("collectionItem"),a("arrayNeedsValue"));break;case"objectNeedsKey":h==="}"?p():h==='"'&&(l("collectionItem"),a("objectNeedsColon"),s("string"));break;case"objectNeedsColon":h===":"&&a("objectNeedsValue");break;case"objectNeedsValue":Ic(h)||(c("collectionItem"),a("objectNeedsComma"),y(h));break;case"objectNeedsComma":h==="}"?p():h===","&&(l("collectionItem"),a("objectNeedsKey"));break}}i!=null&&(e.length=i);for(var g=[r!=null?t.slice(0,r):t],x=function(E){return g.push(E.slice(t.length-t.lastIndexOf(E[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 Nc(){let t=0,e=0;for(let r=0;r<28;r+=7){let i=this.buf[this.pos++];if(t|=(i&127)<<r,(i&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 i=this.buf[this.pos++];if(e|=(i&127)<<r,(i&128)==0)return this.assertBounds(),[t,e]}throw new Error("invalid varint")}function Mi(t,e,n){for(let o=0;o<28;o=o+7){let s=t>>>o,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,i=e>>3!=0;if(n.push((i?r|128:r)&255),!!i){for(let o=3;o<31;o=o+7){let s=e>>>o,a=!!(s>>>7),l=(a?s|128:s)&255;if(n.push(l),!a)return}n.push(e>>>31&1)}}var Oi=4294967296;function Vs(t){let e=t[0]==="-";e&&(t=t.slice(1));let n=1e6,r=0,i=0;function o(s,a){let l=Number(t.slice(s,a));i*=n,r=r*n+l,r>=Oi&&(i=i+(r/Oi|0),r=r%Oi)}return o(-24,-18),o(-18,-12),o(-12,-6),o(-6),e?Mc(r,i):js(r,i)}function Oc(t,e){let n=js(t,e),r=n.hi&2147483648;r&&(n=Mc(n.lo,n.hi));let i=Bs(n.lo,n.hi);return r?"-"+i:i}function Bs(t,e){if({lo:t,hi:e}=km(t,e),e<=2097151)return String(Oi*e+t);let n=t&16777215,r=(t>>>24|e<<8)&16777215,i=e>>16&65535,o=n+r*6777216+i*6710656,s=r+i*8147497,a=i*2,l=1e7;return o>=l&&(s+=Math.floor(o/l),o%=l),s>=l&&(a+=Math.floor(s/l),s%=l),a.toString()+Rc(s)+Rc(o)}function km(t,e){return{lo:t>>>0,hi:e>>>0}}function js(t,e){return{lo:t|0,hi:e|0}}function Mc(t,e){return e=~e,t?t=~t+1:e+=1,js(t,e)}var Rc=t=>{let e=String(t);return"0000000".slice(e.length)+e};function qs(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 Lc(){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=Cm();function Cm(){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"),i=BigInt("0"),o=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>o||a<i)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()),Pc(n),n},uParse(n){return typeof n!="string"&&(n=n.toString()),Dc(n),n},enc(n){return typeof n!="string"&&(n=n.toString()),Pc(n),Vs(n)},uEnc(n){return typeof n!="string"&&(n=n.toString()),Dc(n),Vs(n)},dec(n,r){return Oc(n,r)},uDec(n,r){return Bs(n,r)}}}function Pc(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function Dc(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}var Ws=Symbol.for("@bufbuild/protobuf/text-encoding");function Xs(){if(globalThis[Ws]==null){let t=new globalThis.TextEncoder,e=new globalThis.TextDecoder,n;globalThis[Ws]={encodeUtf8(r){return t.encode(r)},decodeUtf8(r,i){return i?(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[Ws]}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 Im=34028234663852886e22,Rm=-34028234663852886e22,Nm=4294967295,Om=2147483647,Mm=-2147483648,F=class{constructor(e=Xs().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 i=0;i<this.chunks.length;i++)e+=this.chunks[i].length;let n=new Uint8Array(e),r=0;for(let i=0;i<this.chunks.length;i++)n.set(this.chunks[i],r),r+=this.chunks[i].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(Uc(e);e>127;)this.buf.push(e&127|128),e=e>>>7;return this.buf.push(e),this}int32(e){return Ks(e),qs(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){Lm(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){Uc(e);let n=new Uint8Array(4);return new DataView(n.buffer).setUint32(0,e,!0),this.raw(n)}sfixed32(e){Ks(e);let n=new Uint8Array(4);return new DataView(n.buffer).setInt32(0,e,!0),this.raw(n)}sint32(e){return Ks(e),e=(e<<1^e>>31)>>>0,qs(e,this.buf),this}sfixed64(e){let n=new Uint8Array(8),r=new DataView(n.buffer),i=Ye.enc(e);return r.setInt32(0,i.lo,!0),r.setInt32(4,i.hi,!0),this.raw(n)}fixed64(e){let n=new Uint8Array(8),r=new DataView(n.buffer),i=Ye.uEnc(e);return r.setInt32(0,i.lo,!0),r.setInt32(4,i.hi,!0),this.raw(n)}int64(e){let n=Ye.enc(e);return Mi(n.lo,n.hi,this.buf),this}sint64(e){let n=Ye.enc(e),r=n.hi>>31,i=n.lo<<1^r,o=(n.hi<<1|n.lo>>>31)^r;return Mi(i,o,this.buf),this}uint64(e){let n=Ye.uEnc(e);return Mi(n.lo,n.hi,this.buf),this}},A=class{constructor(e,n=Xs().decodeUtf8){this.decodeUtf8=n,this.varint64=Nc,this.uint32=Lc,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 i=n>>>3,o=n&7;if(i<=0||o>5)throw new Error("illegal tag: field no "+i+" wire type "+o);return[i,o]}skip(e,n,r=100){let i=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 o=this.uint32();this.pos+=o;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(i,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 Ks(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>Om||t<Mm)throw new Error("invalid int32: "+t)}function Uc(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>Nm||t<0)throw new Error("invalid uint32: "+t)}function Lm(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>Im||t<Rm))throw new Error("invalid float32: "+t)}var Pm=(function(t){return t[t.NULL_VALUE=0]="NULL_VALUE",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t})({});function Ys(){return{fields:{}}}var ar={encode(t,e=new F){return Object.entries(t.fields).forEach(([n,r])=>{r!==void 0&&Qs.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,i=Ys();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:{if(o!==10)break;let s=Qs.decode(n,n.uint32());s.value!==void 0&&(i.fields[s.key]=s.value);continue}}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return ar.fromPartial(t??{})},fromPartial(t){let e=Ys();return e.fields=Object.entries(t.fields??{}).reduce((n,[r,i])=>(i!==void 0&&(n[r]=i),n),{}),e},wrap(t){let e=Ys();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 Hc(){return{key:"",value:void 0}}var Qs={encode(t,e=new F){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,i=Hc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.key=n.string();continue;case 2:if(o!==18)break;i.value=O.unwrap(O.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Qs.fromPartial(t??{})},fromPartial(t){let e=Hc();return e.key=t.key??"",e.value=t.value??void 0,e}};function Zs(){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 F){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&&ar.encode(ar.wrap(t.structValue),e.uint32(42).fork()).join(),t.listValue!==void 0&&lr.encode(lr.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,i=Zs();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==8)break;i.nullValue=n.int32();continue;case 2:if(o!==17)break;i.numberValue=n.double();continue;case 3:if(o!==26)break;i.stringValue=n.string();continue;case 4:if(o!==32)break;i.boolValue=n.bool();continue;case 5:if(o!==42)break;i.structValue=ar.unwrap(ar.decode(n,n.uint32()));continue;case 6:if(o!==50)break;i.listValue=lr.unwrap(lr.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return O.fromPartial(t??{})},fromPartial(t){let e=Zs();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=Zs();if(t===null)e.nullValue=Pm.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 Js(){return{values:[]}}var lr={encode(t,e=new F){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,i=Js();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.values.push(O.unwrap(O.decode(n,n.uint32())));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return lr.fromPartial(t??{})},fromPartial(t){let e=Js();return e.values=t.values?.map(n=>n)||[],e},wrap(t){let e=Js();return e.values=t??[],e},unwrap(t){return t?.hasOwnProperty("values")&&globalThis.Array.isArray(t.values)?t.values:t}},Dm=(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 zc(){return{op:0,path:"",from:void 0,value:void 0}}var Pi={encode(t,e=new F){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,i=zc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==8)break;i.op=n.int32();continue;case 2:if(o!==18)break;i.path=n.string();continue;case 3:if(o!==26)break;i.from=n.string();continue;case 4:if(o!==34)break;i.value=O.unwrap(O.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Pi.fromPartial(t??{})},fromPartial(t){let e=zc();return e.op=t.op??0,e.path=t.path??"",e.from=t.from??void 0,e.value=t.value??void 0,e}};function Gc(){return{id:"",type:"",function:void 0}}var Di={encode(t,e=new F){return t.id!==""&&e.uint32(10).string(t.id),t.type!==""&&e.uint32(18).string(t.type),t.function!==void 0&&Ui.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,i=Gc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.id=n.string();continue;case 2:if(o!==18)break;i.type=n.string();continue;case 3:if(o!==26)break;i.function=Ui.decode(n,n.uint32());continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Di.fromPartial(t??{})},fromPartial(t){let e=Gc();return e.id=t.id??"",e.type=t.type??"",e.function=t.function!==void 0&&t.function!==null?Ui.fromPartial(t.function):void 0,e}};function Fc(){return{name:"",arguments:""}}var Ui={encode(t,e=new F){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,i=Fc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.name=n.string();continue;case 2:if(o!==18)break;i.arguments=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Ui.fromPartial(t??{})},fromPartial(t){let e=Fc();return e.name=t.name??"",e.arguments=t.arguments??"",e}};function $c(){return{value:"",mimeType:""}}var Hi={encode(t,e=new F){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,i=$c();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.value=n.string();continue;case 2:if(o!==18)break;i.mimeType=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Hi.fromPartial(t??{})},fromPartial(t){let e=$c();return e.value=t.value??"",e.mimeType=t.mimeType??"",e}};function Vc(){return{value:"",mimeType:void 0}}var zi={encode(t,e=new F){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,i=Vc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.value=n.string();continue;case 2:if(o!==18)break;i.mimeType=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return zi.fromPartial(t??{})},fromPartial(t){let e=Vc();return e.value=t.value??"",e.mimeType=t.mimeType??void 0,e}};function Bc(){return{data:void 0,url:void 0}}var Ue={encode(t,e=new F){return t.data!==void 0&&Hi.encode(t.data,e.uint32(10).fork()).join(),t.url!==void 0&&zi.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,i=Bc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.data=Hi.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.url=zi.decode(n,n.uint32());continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Ue.fromPartial(t??{})},fromPartial(t){let e=Bc();return e.data=t.data!==void 0&&t.data!==null?Hi.fromPartial(t.data):void 0,e.url=t.url!==void 0&&t.url!==null?zi.fromPartial(t.url):void 0,e}};function jc(){return{text:""}}var Gi={encode(t,e=new F){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,i=jc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.text=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Gi.fromPartial(t??{})},fromPartial(t){let e=jc();return e.text=t.text??"",e}};function qc(){return{source:void 0,metadata:void 0}}var Fi={encode(t,e=new F){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,i=qc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.source=Ue.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Fi.fromPartial(t??{})},fromPartial(t){let e=qc();return e.source=t.source!==void 0&&t.source!==null?Ue.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e}};function Wc(){return{source:void 0,metadata:void 0}}var $i={encode(t,e=new F){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,i=Wc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.source=Ue.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return $i.fromPartial(t??{})},fromPartial(t){let e=Wc();return e.source=t.source!==void 0&&t.source!==null?Ue.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e}};function Xc(){return{source:void 0,metadata:void 0}}var Vi={encode(t,e=new F){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,i=Xc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.source=Ue.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Vi.fromPartial(t??{})},fromPartial(t){let e=Xc();return e.source=t.source!==void 0&&t.source!==null?Ue.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e}};function Kc(){return{source:void 0,metadata:void 0}}var Bi={encode(t,e=new F){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,i=Kc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.source=Ue.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Bi.fromPartial(t??{})},fromPartial(t){let e=Kc();return e.source=t.source!==void 0&&t.source!==null?Ue.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e}};function Yc(){return{text:void 0,image:void 0,audio:void 0,video:void 0,document:void 0}}var ji={encode(t,e=new F){return t.text!==void 0&&Gi.encode(t.text,e.uint32(10).fork()).join(),t.image!==void 0&&Fi.encode(t.image,e.uint32(18).fork()).join(),t.audio!==void 0&&$i.encode(t.audio,e.uint32(26).fork()).join(),t.video!==void 0&&Vi.encode(t.video,e.uint32(34).fork()).join(),t.document!==void 0&&Bi.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,i=Yc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.text=Gi.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.image=Fi.decode(n,n.uint32());continue;case 3:if(o!==26)break;i.audio=$i.decode(n,n.uint32());continue;case 4:if(o!==34)break;i.video=Vi.decode(n,n.uint32());continue;case 5:if(o!==42)break;i.document=Bi.decode(n,n.uint32());continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return ji.fromPartial(t??{})},fromPartial(t){let e=Yc();return e.text=t.text!==void 0&&t.text!==null?Gi.fromPartial(t.text):void 0,e.image=t.image!==void 0&&t.image!==null?Fi.fromPartial(t.image):void 0,e.audio=t.audio!==void 0&&t.audio!==null?$i.fromPartial(t.audio):void 0,e.video=t.video!==void 0&&t.video!==null?Vi.fromPartial(t.video):void 0,e.document=t.document!==void 0&&t.document!==null?Bi.fromPartial(t.document):void 0,e}};function Zc(){return{id:"",role:"",content:void 0,name:void 0,toolCalls:[],toolCallId:void 0,error:void 0,contentParts:[]}}var qi={encode(t,e=new F){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)Di.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)ji.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,i=Zc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.id=n.string();continue;case 2:if(o!==18)break;i.role=n.string();continue;case 3:if(o!==26)break;i.content=n.string();continue;case 4:if(o!==34)break;i.name=n.string();continue;case 5:if(o!==42)break;i.toolCalls.push(Di.decode(n,n.uint32()));continue;case 6:if(o!==50)break;i.toolCallId=n.string();continue;case 7:if(o!==58)break;i.error=n.string();continue;case 8:if(o!==66)break;i.contentParts.push(ji.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return qi.fromPartial(t??{})},fromPartial(t){let e=Zc();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=>Di.fromPartial(n))||[],e.toolCallId=t.toolCallId??void 0,e.error=t.error??void 0,e.contentParts=t.contentParts?.map(n=>ji.fromPartial(n))||[],e}};function Jc(){return{id:"",reason:"",message:void 0,toolCallId:void 0,responseSchema:void 0,expiresAt:void 0,metadata:void 0}}var Wi={encode(t,e=new F){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,i=Jc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.id=n.string();continue;case 2:if(o!==18)break;i.reason=n.string();continue;case 3:if(o!==26)break;i.message=n.string();continue;case 4:if(o!==34)break;i.toolCallId=n.string();continue;case 5:if(o!==42)break;i.responseSchema=O.unwrap(O.decode(n,n.uint32()));continue;case 6:if(o!==50)break;i.expiresAt=n.string();continue;case 7:if(o!==58)break;i.metadata=O.unwrap(O.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Wi.fromPartial(t??{})},fromPartial(t){let e=Jc();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}},Um=(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 Qc(){return{type:0,timestamp:void 0,rawEvent:void 0}}var M={encode(t,e=new F){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,i=Qc();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==8)break;i.type=n.int32();continue;case 2:if(o!==16)break;i.timestamp=Hm(n.int64());continue;case 3:if(o!==26)break;i.rawEvent=O.unwrap(O.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return M.fromPartial(t??{})},fromPartial(t){let e=Qc();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 Xi={encode(t,e=new F){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,i=ed();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.messageId=n.string();continue;case 3:if(o!==26)break;i.role=n.string();continue;case 4:if(o!==34)break;i.name=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Xi.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 td(){return{baseEvent:void 0,messageId:"",delta:""}}var Ki={encode(t,e=new F){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,i=td();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.messageId=n.string();continue;case 3:if(o!==26)break;i.delta=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Ki.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.delta=t.delta??"",e}};function nd(){return{baseEvent:void 0,messageId:""}}var Yi={encode(t,e=new F){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,i=nd();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.messageId=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Yi.fromPartial(t??{})},fromPartial(t){let e=nd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messageId=t.messageId??"",e}};function rd(){return{baseEvent:void 0,toolCallId:"",toolCallName:"",parentMessageId:void 0}}var Zi={encode(t,e=new F){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,i=rd();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.toolCallId=n.string();continue;case 3:if(o!==26)break;i.toolCallName=n.string();continue;case 4:if(o!==34)break;i.parentMessageId=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Zi.fromPartial(t??{})},fromPartial(t){let e=rd();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 id(){return{baseEvent:void 0,toolCallId:"",delta:""}}var Ji={encode(t,e=new F){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,i=id();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.toolCallId=n.string();continue;case 3:if(o!==26)break;i.delta=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Ji.fromPartial(t??{})},fromPartial(t){let e=id();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 od(){return{baseEvent:void 0,toolCallId:""}}var Qi={encode(t,e=new F){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,i=od();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.toolCallId=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return Qi.fromPartial(t??{})},fromPartial(t){let e=od();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.toolCallId=t.toolCallId??"",e}};function sd(){return{baseEvent:void 0,snapshot:void 0}}var eo={encode(t,e=new F){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,i=sd();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.snapshot=O.unwrap(O.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return eo.fromPartial(t??{})},fromPartial(t){let e=sd();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.snapshot=t.snapshot??void 0,e}};function ad(){return{baseEvent:void 0,delta:[]}}var to={encode(t,e=new F){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join();for(let n of t.delta)Pi.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,i=ad();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.delta.push(Pi.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return to.fromPartial(t??{})},fromPartial(t){let e=ad();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.delta=t.delta?.map(n=>Pi.fromPartial(n))||[],e}};function ld(){return{baseEvent:void 0,messages:[]}}var no={encode(t,e=new F){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join();for(let n of t.messages)qi.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,i=ld();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.messages.push(qi.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return no.fromPartial(t??{})},fromPartial(t){let e=ld();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messages=t.messages?.map(n=>qi.fromPartial(n))||[],e}};function cd(){return{baseEvent:void 0,event:void 0,source:void 0}}var ro={encode(t,e=new F){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,i=cd();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.event=O.unwrap(O.decode(n,n.uint32()));continue;case 3:if(o!==26)break;i.source=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return ro.fromPartial(t??{})},fromPartial(t){let e=cd();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 dd(){return{baseEvent:void 0,name:"",value:void 0}}var io={encode(t,e=new F){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,i=dd();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.name=n.string();continue;case 3:if(o!==26)break;i.value=O.unwrap(O.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return io.fromPartial(t??{})},fromPartial(t){let e=dd();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 ud(){return{baseEvent:void 0,threadId:"",runId:""}}var oo={encode(t,e=new F){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,i=ud();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.threadId=n.string();continue;case 3:if(o!==26)break;i.runId=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return oo.fromPartial(t??{})},fromPartial(t){let e=ud();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 pd(){return{baseEvent:void 0,threadId:"",runId:"",result:void 0,outcome:"",interrupts:[]}}var so={encode(t,e=new F){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)Wi.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,i=pd();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.threadId=n.string();continue;case 3:if(o!==26)break;i.runId=n.string();continue;case 4:if(o!==34)break;i.result=O.unwrap(O.decode(n,n.uint32()));continue;case 5:if(o!==42)break;i.outcome=n.string();continue;case 6:if(o!==50)break;i.interrupts.push(Wi.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return so.fromPartial(t??{})},fromPartial(t){let e=pd();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=>Wi.fromPartial(n))||[],e}};function hd(){return{baseEvent:void 0,code:void 0,message:""}}var ao={encode(t,e=new F){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,i=hd();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.code=n.string();continue;case 3:if(o!==26)break;i.message=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return ao.fromPartial(t??{})},fromPartial(t){let e=hd();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 fd(){return{baseEvent:void 0,stepName:""}}var lo={encode(t,e=new F){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,i=fd();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.stepName=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return lo.fromPartial(t??{})},fromPartial(t){let e=fd();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,stepName:""}}var co={encode(t,e=new F){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,i=md();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.stepName=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return co.fromPartial(t??{})},fromPartial(t){let e=md();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.stepName=t.stepName??"",e}};function gd(){return{baseEvent:void 0,messageId:void 0,role:void 0,delta:void 0,name:void 0}}var uo={encode(t,e=new F){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,i=gd();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.messageId=n.string();continue;case 3:if(o!==26)break;i.role=n.string();continue;case 4:if(o!==34)break;i.delta=n.string();continue;case 5:if(o!==42)break;i.name=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return uo.fromPartial(t??{})},fromPartial(t){let e=gd();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 vd(){return{baseEvent:void 0,toolCallId:void 0,toolCallName:void 0,parentMessageId:void 0,delta:void 0}}var po={encode(t,e=new F){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,i=vd();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.baseEvent=M.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.toolCallId=n.string();continue;case 3:if(o!==26)break;i.toolCallName=n.string();continue;case 4:if(o!==34)break;i.parentMessageId=n.string();continue;case 5:if(o!==42)break;i.delta=n.string();continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return po.fromPartial(t??{})},fromPartial(t){let e=vd();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 bd(){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 yd={encode(t,e=new F){return t.textMessageStart!==void 0&&Xi.encode(t.textMessageStart,e.uint32(10).fork()).join(),t.textMessageContent!==void 0&&Ki.encode(t.textMessageContent,e.uint32(18).fork()).join(),t.textMessageEnd!==void 0&&Yi.encode(t.textMessageEnd,e.uint32(26).fork()).join(),t.toolCallStart!==void 0&&Zi.encode(t.toolCallStart,e.uint32(34).fork()).join(),t.toolCallArgs!==void 0&&Ji.encode(t.toolCallArgs,e.uint32(42).fork()).join(),t.toolCallEnd!==void 0&&Qi.encode(t.toolCallEnd,e.uint32(50).fork()).join(),t.stateSnapshot!==void 0&&eo.encode(t.stateSnapshot,e.uint32(58).fork()).join(),t.stateDelta!==void 0&&to.encode(t.stateDelta,e.uint32(66).fork()).join(),t.messagesSnapshot!==void 0&&no.encode(t.messagesSnapshot,e.uint32(74).fork()).join(),t.raw!==void 0&&ro.encode(t.raw,e.uint32(82).fork()).join(),t.custom!==void 0&&io.encode(t.custom,e.uint32(90).fork()).join(),t.runStarted!==void 0&&oo.encode(t.runStarted,e.uint32(98).fork()).join(),t.runFinished!==void 0&&so.encode(t.runFinished,e.uint32(106).fork()).join(),t.runError!==void 0&&ao.encode(t.runError,e.uint32(114).fork()).join(),t.stepStarted!==void 0&&lo.encode(t.stepStarted,e.uint32(122).fork()).join(),t.stepFinished!==void 0&&co.encode(t.stepFinished,e.uint32(130).fork()).join(),t.textMessageChunk!==void 0&&uo.encode(t.textMessageChunk,e.uint32(138).fork()).join(),t.toolCallChunk!==void 0&&po.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,i=bd();for(;n.pos<r;){let o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.textMessageStart=Xi.decode(n,n.uint32());continue;case 2:if(o!==18)break;i.textMessageContent=Ki.decode(n,n.uint32());continue;case 3:if(o!==26)break;i.textMessageEnd=Yi.decode(n,n.uint32());continue;case 4:if(o!==34)break;i.toolCallStart=Zi.decode(n,n.uint32());continue;case 5:if(o!==42)break;i.toolCallArgs=Ji.decode(n,n.uint32());continue;case 6:if(o!==50)break;i.toolCallEnd=Qi.decode(n,n.uint32());continue;case 7:if(o!==58)break;i.stateSnapshot=eo.decode(n,n.uint32());continue;case 8:if(o!==66)break;i.stateDelta=to.decode(n,n.uint32());continue;case 9:if(o!==74)break;i.messagesSnapshot=no.decode(n,n.uint32());continue;case 10:if(o!==82)break;i.raw=ro.decode(n,n.uint32());continue;case 11:if(o!==90)break;i.custom=io.decode(n,n.uint32());continue;case 12:if(o!==98)break;i.runStarted=oo.decode(n,n.uint32());continue;case 13:if(o!==106)break;i.runFinished=so.decode(n,n.uint32());continue;case 14:if(o!==114)break;i.runError=ao.decode(n,n.uint32());continue;case 15:if(o!==122)break;i.stepStarted=lo.decode(n,n.uint32());continue;case 16:if(o!==130)break;i.stepFinished=co.decode(n,n.uint32());continue;case 17:if(o!==138)break;i.textMessageChunk=uo.decode(n,n.uint32());continue;case 18:if(o!==146)break;i.toolCallChunk=po.decode(n,n.uint32());continue}if((o&7)===4||o===0)break;n.skip(o&7)}return i},create(t){return yd.fromPartial(t??{})},fromPartial(t){let e=bd();return e.textMessageStart=t.textMessageStart!==void 0&&t.textMessageStart!==null?Xi.fromPartial(t.textMessageStart):void 0,e.textMessageContent=t.textMessageContent!==void 0&&t.textMessageContent!==null?Ki.fromPartial(t.textMessageContent):void 0,e.textMessageEnd=t.textMessageEnd!==void 0&&t.textMessageEnd!==null?Yi.fromPartial(t.textMessageEnd):void 0,e.toolCallStart=t.toolCallStart!==void 0&&t.toolCallStart!==null?Zi.fromPartial(t.toolCallStart):void 0,e.toolCallArgs=t.toolCallArgs!==void 0&&t.toolCallArgs!==null?Ji.fromPartial(t.toolCallArgs):void 0,e.toolCallEnd=t.toolCallEnd!==void 0&&t.toolCallEnd!==null?Qi.fromPartial(t.toolCallEnd):void 0,e.stateSnapshot=t.stateSnapshot!==void 0&&t.stateSnapshot!==null?eo.fromPartial(t.stateSnapshot):void 0,e.stateDelta=t.stateDelta!==void 0&&t.stateDelta!==null?to.fromPartial(t.stateDelta):void 0,e.messagesSnapshot=t.messagesSnapshot!==void 0&&t.messagesSnapshot!==null?no.fromPartial(t.messagesSnapshot):void 0,e.raw=t.raw!==void 0&&t.raw!==null?ro.fromPartial(t.raw):void 0,e.custom=t.custom!==void 0&&t.custom!==null?io.fromPartial(t.custom):void 0,e.runStarted=t.runStarted!==void 0&&t.runStarted!==null?oo.fromPartial(t.runStarted):void 0,e.runFinished=t.runFinished!==void 0&&t.runFinished!==null?so.fromPartial(t.runFinished):void 0,e.runError=t.runError!==void 0&&t.runError!==null?ao.fromPartial(t.runError):void 0,e.stepStarted=t.stepStarted!==void 0&&t.stepStarted!==null?lo.fromPartial(t.stepStarted):void 0,e.stepFinished=t.stepFinished!==void 0&&t.stepFinished!==null?co.fromPartial(t.stepFinished):void 0,e.textMessageChunk=t.textMessageChunk!==void 0&&t.textMessageChunk!==null?uo.fromPartial(t.textMessageChunk):void 0,e.toolCallChunk=t.toolCallChunk!==void 0&&t.toolCallChunk!==null?po.fromPartial(t.toolCallChunk):void 0,e}};function Hm(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 Li=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}}},zm=t=>{if(!(!t||typeof t!="object")){if(t.text)return{type:"text",text:t.text.text};if(t.image)return{type:"image",source:Li(t.image.source),metadata:t.image.metadata};if(t.audio)return{type:"audio",source:Li(t.audio.source),metadata:t.audio.metadata};if(t.video)return{type:"video",source:Li(t.video.source),metadata:t.video.metadata};if(t.document)return{type:"document",source:Li(t.document.source),metadata:t.document.metadata}}};function xd(t){let e=yd.decode(t),n=Object.values(e).find(r=>r!==void 0);if(!n)throw new Error("Invalid event");if(n.type=Um[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 i=r;if(i.role==="user"&&Array.isArray(i.contentParts)){let o=i.contentParts.map(s=>zm(s)).filter(s=>s!==void 0);o.length>0&&(i.content=o)}Array.isArray(i.contentParts)&&i.contentParts.length===0&&(i.contentParts=void 0),i.toolCalls?.length===0&&(i.toolCalls=void 0)}if(n.type===v.RUN_FINISHED){let r=n,i=typeof r.outcome=="string"&&r.outcome!==""?r.outcome:void 0,o=Array.isArray(r.interrupts)?r.interrupts:[];delete r.interrupts,i==="interrupt"?r.outcome={type:"interrupt",interrupts:o}:i==="success"?r.outcome={type:"success"}:delete r.outcome}if(n.type===v.STATE_DELTA)for(let r of n.delta)r.op=Dm[r.op].toLowerCase(),Object.keys(r).forEach(i=>{r[i]===void 0&&delete r[i]});return Object.keys(n).forEach(r=>{n[r]===void 0&&delete n[r]}),Zr.parse(n)}var ea="application/vnd.ag-ui.event+proto";var Fm=/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i,ta=t=>{if(typeof t!="string")throw new TypeError("Invalid argument expected string");let e=t.match(Fm);if(!e)throw new Error(`Invalid argument not valid semver ('${t}' received)`);return e.shift(),e},wd=t=>t==="*"||t==="x"||t==="X",_d=t=>{let e=parseInt(t,10);return isNaN(e)?t:e},$m=(t,e)=>typeof t!=typeof e?[String(t),String(e)]:[t,e],Vm=(t,e)=>{if(wd(t)||wd(e))return 0;let[n,r]=$m(_d(t),_d(e));return n>r?1:n<r?-1:0},na=(t,e)=>{for(let n=0;n<Math.max(t.length,e.length);n++){let r=Vm(t[n]||"0",e[n]||"0");if(r!==0)return r}return 0};var cr=(t,e)=>{let n=ta(t),r=ta(e),i=n.pop(),o=r.pop(),s=na(n,r);return s!==0?s:i&&o?na(i.split("."),o.split(".")):i||o?i?-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 Ee(){return Et()}function oa(t){if(Object.freeze(t),typeof t=="object"&&t)for(let e of Object.values(t))typeof e=="object"&&e&&!Object.isFrozen(e)&&oa(e);return t}var Ed=512*1024;function Td(t,e,n){let r=0,i=[t,e],o=new WeakSet;for(;i.length>0;){let s=i.pop();if(typeof s=="string"){if(r+=s.length,r>n)return!0}else if(typeof s=="object"&&s){if(o.has(s))continue;if(o.add(s),Array.isArray(s))for(let a=0;a<s.length;a++)i.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;i.push(s[c])}}}}return!1}async function Y(t,e,n,r){let i=typeof process<"u"&&process.env!==void 0,o=i&&!!process.env.VITEST_WORKER_ID,s=i&&!!process.env.VITEST_WORKER_ID,a=s&&!Td(e,n,Ed),l=a?q(e):e,c=a?q(n):n,p=!1,m=!1,y;for(let f of t)try{a&&(oa(l),oa(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),p=!0,g=!0),h.state!==void 0&&h.state!==c&&(c=q(h.state),m=!0,g=!0),a&&g&&Td(l,c,Ed)&&(a=!1),y=h.stopPropagation,y===!0)break}catch(h){if(s&&h instanceof TypeError){if(o)throw h;console.error("AG-UI: Subscriber attempted to mutate frozen inputs in-place. Return mutations via AgentStateMutation instead of mutating directly.",h)}else o||console.error("Subscriber error:",h);continue}return{...p?{messages:Object.isFrozen(l)?q(l):l}:{},...m?{state:Object.isFrozen(c)?q(c):c}:{},...y===void 0?{}:{stopPropagation:y}}}function ho(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 dr(t){if(t instanceof sa)return t;if(t===!0)return new sa(ho(!0))}var sa=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 ra(t){return t.enabled?new sa(t):void 0}function Bm(t,e,n){if(e){let i=t.find(s=>s.id===e);if(i?.role==="assistant")return i;i&&console.warn(`TOOL_CALL_START: parentMessageId '${e}' matches a '${i.role}' message, not assistant \u2014 falling back to toolCallId`);let o={id:i?n:e,role:"assistant",toolCalls:[]};return t.push(o),o}let r={id:n,role:"assistant",toolCalls:[]};return t.push(r),r}var Rd=(t,e,n,r,i)=>{let o=dr(i),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)},p=()=>{let m=q(l);return l={},m.messages!==void 0||m.state!==void 0?ue(m):fi};return e.pipe(Ii(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?o?.event("APPLY","Event dropped:",m,{type:m.type,reason:"stopPropagation by subscriber"}):o?.event("APPLY","Event applied:",m,{type:m.type,subscribers:r.length}),y.stopPropagation===!0)return p();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 p()}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}'`),p();let x=await Y(r,s,a,(S,E,I)=>S.onTextMessageContentEvent?.({event:m,messages:E,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})),p()}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})})),p()):(console.warn(`TEXT_MESSAGE_END: No message found with ID '${f}'`),p())}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=Bm(s,x,h);S.toolCalls??=[],S.toolCalls.push({id:h,type:"function",function:{name:g,arguments:""}}),c({messages:s})}return p()}case v.TOOL_CALL_ARGS:{let{toolCallId:f,delta:h}=m,g=s.find(E=>E.toolCalls?.some(I=>I.id===f));if(!g)return console.warn(`TOOL_CALL_ARGS: No message found containing tool call with ID '${f}'`),p();let x=g.toolCalls?.find(E=>E.id===f);if(!x)return console.warn(`TOOL_CALL_ARGS: No tool call found with ID '${f}'`),p();let S=await Y(r,s,a,(E,I,H)=>{let U=x.function.arguments,K=x.function.name,ie={};try{ie=Ni(U)}catch{}return E.onToolCallArgsEvent?.({event:m,messages:I,state:H,agent:n,input:t,toolCallBuffer:U,toolCallName:K,partialToolCallArgs:ie})});return c(S),S.stopPropagation!==!0&&(x.function.arguments+=h,c({messages:s})),p()}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}'`),p();let g=h.toolCalls?.find(x=>x.id===f);return g?(c(await Y(r,s,a,(x,S,E)=>{let I=g.function.arguments,H=g.function.name,U={};try{U=JSON.parse(I)}catch{}return x.onToolCallEndEvent?.({event:m,messages:S,state:E,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})})),p()):(console.warn(`TOOL_CALL_END: No tool call found with ID '${f}'`),p())}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,E={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(E);else{let H=I+1;for(;H<s.length&&s[H].role==="tool";)H++;s.splice(H,0,E)}await Promise.all(r.map(H=>{H.onNewMessage?.({message:E,messages:s,state:a,agent:n,input:t})})),c({messages:s})}return p()}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 p()}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=oi.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:
|
|
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:
|
|
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:
|
|
6
6
|
Current state: ${JSON.stringify(a,null,2)}
|
|
7
7
|
Patch operations: ${JSON.stringify(h,null,2)}
|
|
8
|
-
Error: ${x}`)}}return p()}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 E=new Set(s.map(I=>I.id));for(let I of h)E.has(I.id)||s.push(I);c({messages:s})}return p()}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,E=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(E),E.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 p()}case v.ACTIVITY_DELTA:{let f=m,h=s.findIndex(E=>E.id===f.messageId);if(h===-1)return p();let g=s[h];if(g.role!=="activity")return console.warn(`ACTIVITY_DELTA: Message '${f.messageId}' is not an activity message`),p();let x=g,S=await Y(r,s,a,(E,I,H)=>E.onActivityDeltaEvent?.({event:f,messages:I,state:H,agent:n,input:t,activityMessage:x}));if(c(S),S.stopPropagation!==!0)try{let E=q(x.content??{}),I=oi.applyPatch(E,f.patch??[],!0,!1).newDocument;s[h]={...x,content:q(I),activityType:f.activityType},c({messages:s})}catch(E){let I=E instanceof Error?E.message:String(E);console.warn(`Failed to apply activity patch for '${f.messageId}': ${I}`)}return p()}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}))),p();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}))),p();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 p()}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,E)=>x.onRunFinishedEvent?.({...h,messages:S,state:E,agent:n,input:t}));return c(g),g.stopPropagation!==!0&&(n.pendingInterrupts=h.outcome==="interrupt"?[...h.interrupts]:[]),p()}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}))),p();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}))),p();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}))),p();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 p();case v.THINKING_END:return p();case v.THINKING_TEXT_MESSAGE_START:return p();case v.THINKING_TEXT_MESSAGE_CONTENT:return p();case v.THINKING_TEXT_MESSAGE_END:return p();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}))),p();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 p()}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}'`),p();let x=await Y(r,s,a,(S,E,I)=>S.onReasoningMessageContentEvent?.({event:m,messages:E,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})),p()}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})})),p()):(console.warn(`REASONING_MESSAGE_END: No message found with ID '${f}'`),p())}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}))),p();case v.REASONING_ENCRYPTED_VALUE:{let{subtype:f,entityId:h,encryptedValue:g}=m,x=await Y(r,s,a,(S,E,I)=>S.onReasoningEncryptedValueEvent?.({event:m,messages:E,state:I,agent:n,input:t}));if(c(x),x.stopPropagation!==!0){let S=!1;if(f==="tool-call"){for(let E of s)if(E.role==="assistant"&&E.toolCalls){let I=E.toolCalls.find(H=>H.id===h);if(I){I.encryptedValue=g,S=!0;break}}}else{let E=s.find(I=>I.id===h);E?.role!=="activity"&&E&&(E.encryptedValue=g,S=!0)}S&&(l.messages=s)}return p()}}return m.type,p()}),zs(),r.length>0?Gs({}):m=>m)},ia=t=>e=>{let n=dr(t),r=new Map,i=new Map,o=!1,s=!1,a=!1,l=new Map,c=!1,p=!1,m=!1,y=()=>{r.clear(),i.clear(),l.clear(),c=!1,p=!1,o=!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(o&&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&&!o)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."));o&&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 i.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.`)):(i.set(g,!0),ue(f))}case v.TOOL_CALL_ARGS:{let g=f.toolCallId;return i.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 i.has(g)?(i.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(i.size>0){let g=Array.from(i.keys()).join(", ");return re(()=>new te(`Cannot send 'RUN_FINISHED' while tool calls are still active: ${g}`))}return o=!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?p?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.")):(p=!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 p?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 p?(p=!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})({}),jm=t=>Ci(()=>Qt(t())).pipe(Fs(e=>{if(!e.ok){let i=e.headers.get("content-type")||"";return Qt(e.text()).pipe(Le(o=>{let s=o;if(i.includes("application/json"))try{s=JSON.parse(o)}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(i=>(i.next(n),(async()=>{try{for(;;){let{done:o,value:s}=await r.read();if(o)break;let a={type:nn.DATA,data:s};i.next(a)}i.complete()}catch(o){i.error(o)}})(),()=>{r.cancel().catch(o=>{if(o?.name!=="AbortError")throw o})})):re(()=>Error("Failed to getReader() from response"))})),qm=(t,e)=>{let n=dr(e),r=new ct,i=new TextDecoder("utf-8",{fatal:!1}),o="";t.subscribe({next:a=>{if(a.type!==nn.HEADERS&&a.type===nn.DATA&&a.data){let l=i.decode(a.data,{stream:!0});o+=l;let c=o.split(/\n\n/);o=c.pop()||"";for(let p of c)s(p)}},error:a=>r.error(a),complete:()=>{o&&(o+=i.decode(),s(o)),r.complete()}});function s(a){let l=a.split(`
|
|
9
|
-
`),c=[];for(let
|
|
10
|
-
`),m=JSON.parse(
|
|
11
|
-
`)},ag=(t,e,n)=>r=>{let i={},o=!0,s=!0,a="",l=null,c=null,p=[],m={},y=f=>{typeof f=="object"&&f&&("messages"in f&&delete f.messages,i=f)};return r.pipe(Le(f=>{switch(f.type){case v.TEXT_MESSAGE_START:{let h=f;return[{type:Q.enum.TextMessageStart,messageId:h.messageId,role:h.role}]}case v.TEXT_MESSAGE_CONTENT:{let h=f;return[{type:Q.enum.TextMessageContent,messageId:h.messageId,content:h.delta}]}case v.TEXT_MESSAGE_END:{let h=f;return[{type:Q.enum.TextMessageEnd,messageId:h.messageId}]}case v.TOOL_CALL_START:{let h=f;return p.push({id:h.toolCallId,type:"function",function:{name:h.toolCallName,arguments:""}}),s=!0,m[h.toolCallId]=h.toolCallName,[{type:Q.enum.ActionExecutionStart,actionExecutionId:h.toolCallId,actionName:h.toolCallName,parentMessageId:h.parentMessageId}]}case v.TOOL_CALL_ARGS:{let h=f,g=p.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(E=>E.tool==g.function.name);if(S)try{let E=JSON.parse(Ni(g.function.arguments));S.tool_argument&&S.tool_argument in E?(y({...i,[S.state_key]:E[S.tool_argument]}),x=!0):S.tool_argument||(y({...i,[S.state_key]:E}),x=!0)}catch{}}return[{type:Q.enum.ActionExecutionArgs,actionExecutionId:h.toolCallId,args:h.delta},...x?[{type:Q.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:o,role:"assistant",state:JSON.stringify(i),active:s}]:[]]}case v.TOOL_CALL_END:{let h=f;return[{type:Q.enum.ActionExecutionEnd,actionExecutionId:h.toolCallId}]}case v.TOOL_CALL_RESULT:{let h=f;return[{type:Q.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":o=!1;break;case"PredictState":c=h.value;break}return[{type:Q.enum.MetaEvent,name:h.name,value:h.value}]}case v.STATE_SNAPSHOT:return y(f.snapshot),[{type:Q.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:o,role:"assistant",state:JSON.stringify(i),active:s}];case v.STATE_DELTA:{let h=f,g=oi.applyPatch(i,h.delta,!0,!1);return g?(y(g.newDocument),[{type:Q.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:o,role:"assistant",state:JSON.stringify(i),active:s}]):[]}case v.MESSAGES_SNAPSHOT:return l=f.messages,[{type:Q.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:o,role:"assistant",state:JSON.stringify({...i,...l?{messages:l}:{}}),active:!0}];case v.RUN_STARTED:return[];case v.RUN_FINISHED:return l&&(i.messages=l),Object.keys(i).length===0?[]:[{type:Q.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:o,role:"assistant",state:JSON.stringify({...i,...l?{messages:lg(l)}:{}}),active:!1}];case v.RUN_ERROR:{let h=f;return[{type:Q.enum.RunError,message:h.message,code:h.code}]}case v.STEP_STARTED:return a=f.stepName,p=[],c=null,[{type:Q.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:o,role:"assistant",state:JSON.stringify(i),active:!0}];case v.STEP_FINISHED:return p=[],c=null,[{type:Q.enum.AgentStateMessage,threadId:t,agentName:n,nodeName:a,runId:e,running:o,role:"assistant",state:JSON.stringify(i),active:!1}];default:return[]}}))};function lg(t){let e=[];for(let n of t)if(n.role==="assistant"||n.role==="user"||n.role==="system"){let r=sg(n.content);if(r){let i={id:n.id,role:n.role,content:r};e.push(i)}if(n.role==="assistant"&&n.toolCalls&&n.toolCalls.length>0)for(let i of n.toolCalls){let o={id:i.id,name:i.function.name,arguments:JSON.parse(i.function.arguments),parentMessageId:n.id};e.push(o)}}else if(n.role==="tool"){let r="unknown";for(let o of t)if(o.role==="assistant"&&o.toolCalls?.length){for(let s of o.toolCalls)if(s.id===n.toolCallId){r=s.function.name;break}}let i={id:n.id,result:n.content,actionExecutionId:n.toolCallId,actionName:r};e.push(i)}return e}var fo=t=>e=>{let n=dr(t),r,i,o,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(!i||s!=="tool")throw Error("No tool call to close");let m={type:v.TOOL_CALL_END,toolCallId:i.toolCallId};return s=void 0,i=void 0,n?.event("TRANSFORM","TOOL_CALL_END",m,{toolCallId:m.toolCallId}),m},c=()=>{if(!o||s!=="reasoning")throw Error("No reasoning message to close");let m={type:v.REASONING_MESSAGE_END,messageId:o.messageId};return s=void 0,o=void 0,n?.event("TRANSFORM","REASONING_MESSAGE_END",m,{messageId:m.messageId}),m},p=()=>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[...p(),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(...p()),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 E={type:v.TEXT_MESSAGE_START,messageId:y.messageId,role:y.role||"assistant",...y.name!==void 0&&{name:y.name}};f.push(E),n?.event("TRANSFORM","TEXT_MESSAGE_START",E,{messageId:y.messageId})}if(y.delta!==void 0){let E={type:v.TEXT_MESSAGE_CONTENT,messageId:r.messageId,delta:y.delta};f.push(E),n?.event("TRANSFORM","TEXT_MESSAGE_CONTENT",E,{messageId:r.messageId})}return f;case v.TOOL_CALL_CHUNK:let h=m,g=[];if((s!=="tool"||h.toolCallId!==void 0&&h.toolCallId!==i?.toolCallId)&&g.push(...p()),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");i={toolCallId:h.toolCallId,toolCallName:h.toolCallName,parentMessageId:h.parentMessageId},s="tool";let E={type:v.TOOL_CALL_START,toolCallId:h.toolCallId,toolCallName:h.toolCallName,parentMessageId:h.parentMessageId};g.push(E),n?.event("TRANSFORM","TOOL_CALL_START",E,{toolCallId:h.toolCallId,toolCallName:h.toolCallName})}if(h.delta!==void 0){let E={type:v.TOOL_CALL_ARGS,toolCallId:i.toolCallId,delta:h.delta};g.push(E),n?.event("TRANSFORM","TOOL_CALL_ARGS",E,{toolCallId:i.toolCallId})}return g;case v.REASONING_MESSAGE_CHUNK:let x=m,S=[];if((s!=="reasoning"||x.messageId&&x.messageId!==o?.messageId)&&S.push(...p()),s!=="reasoning"){if(x.messageId===void 0)throw Error("First REASONING_MESSAGE_CHUNK must have a messageId");o={messageId:x.messageId},s="reasoning";let E={type:v.REASONING_MESSAGE_START,messageId:x.messageId};S.push(E),n?.event("TRANSFORM","REASONING_MESSAGE_START",E,{messageId:x.messageId})}if(x.delta!==void 0){let E={type:v.REASONING_MESSAGE_CONTENT,messageId:o.messageId,delta:x.delta};S.push(E),n?.event("TRANSFORM","REASONING_MESSAGE_CONTENT",E,{messageId:o.messageId})}return S}return m.type,[]}),tn(()=>{p()}))};function cg(t,e=new Date){return t.expiresAt===void 0?!1:new Date(t.expiresAt)<=e}function Nd(t,e){let n=new Set(t.map(s=>s.id)),r=new Set(Object.keys(e)),i=[...n].filter(s=>!r.has(s));if(i.length>0)throw Error(`buildResumeArray: missing responses for open interrupts: ${i.join(", ")}`);let o=[...r].filter(s=>!n.has(s));if(o.length>0)throw Error(`buildResumeArray: responses reference unknown interrupt ids: ${o.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 mo=class{runNext(t,e){return e.run(t).pipe(fo(!1))}runNextWithState(t,e){let n=q(t.messages||[]),r=q(t.state||{}),i=new hi;return Rd(t,i,e,[]).subscribe(o=>{o.messages!==void 0&&(n=o.messages),o.state!==void 0&&(r=o.state)}),this.runNext(t,e).pipe(Ii(async o=>(i.next(o),await new Promise(s=>setTimeout(s,0)),{event:o,messages:q(n),state:q(r)})))}},dg=class extends mo{constructor(t){super(),this.fn=t}run(t,e){return this.fn(t,e)}};function ug(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 pg=class extends mo{run(t,e){let{parentRunId:n,...r}=t,i={...r,messages:r.messages.map(ug)};return this.runNext(i,e)}},Sd="THINKING_START",Ad="THINKING_END",kd="THINKING_TEXT_MESSAGE_START",Cd="THINKING_TEXT_MESSAGE_CONTENT",Id="THINKING_TEXT_MESSAGE_END",hg=class extends mo{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 Sd:{this.currentReasoningId=Ee();let{title:e,...n}=t;return this.warnAboutTransformation(Sd,v.REASONING_START),{...n,type:v.REASONING_START,messageId:this.currentReasoningId}}case kd:return this.currentMessageId=Ee(),this.warnAboutTransformation(kd,v.REASONING_MESSAGE_START),{...t,type:v.REASONING_MESSAGE_START,messageId:this.currentMessageId,role:"assistant"};case Cd:{let{delta:e,...n}=t;return this.warnAboutTransformation(Cd,v.REASONING_MESSAGE_CONTENT),{...n,type:v.REASONING_MESSAGE_CONTENT,messageId:this.currentMessageId??Ee(),delta:e}}case Id:{let e=this.currentMessageId??Ee();return this.warnAboutTransformation(Id,v.REASONING_MESSAGE_END),{...t,type:v.REASONING_MESSAGE_END,messageId:e}}case Ad:{let e=this.currentReasoningId??Ee();return this.warnAboutTransformation(Ad,v.REASONING_END),{...t,type:v.REASONING_END,messageId:e}}default:return t}}};function fg(t){return t.startsWith("image/")?"image":t.startsWith("audio/")?"audio":t.startsWith("video/")?"video":"document"}function mg(t){return typeof t=="object"&&!!t&&"type"in t&&t.type==="binary"&&"mimeType"in t&&typeof t.mimeType=="string"}function gg(t){let e=fg(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 vg(t){let e=t.content;if(!Array.isArray(e))return t;let n=e.map(r=>mg(r)?gg(r):r);return{...t,content:n}}var bg=class extends mo{run(t,e){let n={...t,messages:t.messages.map(vg)};return this.runNext(n,e)}},yg="0.0.57",xg=class{get maxVersion(){return yg}get debug(){return this._debug}set debug(t){this._debug=ho(t),this._debugLogger=ra(this._debug)}get debugLogger(){return this._debugLogger}set debugLogger(t){typeof t=="boolean"?this._debugLogger=t?ra(ho(!0)):void 0:this._debugLogger=t}constructor({agentId:t,description:e,threadId:n,initialMessages:r,initialState:i,debug:o}={}){this.subscribers=[],this.isRunning=!1,this.pendingInterrupts=[],this.middlewares=[],this.agentId=t,this.description=e??"",this.threadId=n??Et(),this.messages=q(r??[]),this.state=q(i??{}),this._debug=ho(o),this._debugLogger=ra(this._debug),cr(this.maxVersion,"0.0.39")<=0&&this.middlewares.unshift(new pg),cr(this.maxVersion,"0.0.45")<=0&&this.middlewares.unshift(new hg),cr(this.maxVersion,"0.0.47")<=0&&this.middlewares.unshift(new bg)}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 dg(n):n);return this.middlewares.push(...e),this}async runAgent(t,e){try{this.isRunning=!0,this.agentId=this.agentId??Et();let n=this.prepareRunAgentInput(t);this.debugLogger?.lifecycle("LIFECYCLE","Run started:",{agentId:this.agentId,threadId:this.threadId});let r,i=new Set(this.messages.map(l=>l.id)),o=[{onRunFinishedEvent:l=>{l.outcome==="success"&&(r=l.result)}},...this.subscribers,e??{}];await this.onInitialize(n,o),this.activeRunDetach$=new ct;let s;this.activeRunCompletionPromise=new Promise(l=>{s=l}),await ki(pi(()=>this.middlewares.length===0?this.run(n):this.middlewares.reduceRight((l,c)=>({run:p=>c.run(p,l),get messages(){return l.messages},get state(){return l.state}}),this).run(n),fo(this.debugLogger),ia(this.debugLogger),l=>l.pipe(Ri(this.activeRunDetach$)),l=>this.apply(n,l,o),l=>this.processApplyEvents(n,l,o),sr(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,o))),tn(()=>{this.debugLogger?.lifecycle("LIFECYCLE","Run finished:",{agentId:this.agentId,threadId:this.threadId}),this.isRunning=!1,this.onFinalize(n,o),s?.(),s=void 0,this.activeRunCompletionPromise=void 0,this.activeRunDetach$=void 0}))(ue(null)));let a=q(this.messages).filter(l=>!i.has(l.id));return{result:r,newMessages:a}}finally{this.isRunning=!1}}connect(t){throw new As}async connectAgent(t,e){try{this.isRunning=!0,this.agentId=this.agentId??Et();let n=this.prepareRunAgentInput(t),r,i=new Set(this.messages.map(l=>l.id)),o=[{onRunFinishedEvent:l=>{l.outcome==="success"&&(r=l.result)}},...this.subscribers,e??{}];await this.onInitialize(n,o),this.activeRunDetach$=new ct;let s;this.activeRunCompletionPromise=new Promise(l=>{s=l}),await ki(pi(()=>Ci(()=>this.connect(n)),fo(this.debugLogger),ia(this.debugLogger),l=>l.pipe(Ri(this.activeRunDetach$)),l=>this.apply(n,l,o),l=>this.processApplyEvents(n,l,o),sr(l=>(this.isRunning=!1,l instanceof As?fi:this.onError(n,l,o))),tn(()=>{this.isRunning=!1,this.onFinalize(n,o),s?.(),s=void 0,this.activeRunCompletionPromise=void 0,this.activeRunDetach$=void 0}))(ue(null)),{defaultValue:void 0});let a=q(this.messages).filter(l=>!i.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 Rd(t,e,this,n,this.debugLogger)}processApplyEvents(t,e,n){return e.pipe($s(r=>{r.messages&&(this.messages=r.messages,n.forEach(i=>{i.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:t})})),r.state&&(this.state=r.state,n.forEach(i=>{i.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||Et(),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(o=>o.interruptId)),i=this.pendingInterrupts.map(o=>o.id).filter(o=>!r.has(o));if(i.length>0)throw new te(`Thread has ${i.length} pending interrupt(s) not addressed by resume: ${i.join(", ")}`);for(let o of this.pendingInterrupts)if(cg(o))throw new te(`Interrupt ${o.id} expired at ${o.expiresAt}`)}let n=await Y(e,this.messages,this.state,(r,i,o)=>r.onRunInitialized?.({messages:i,state:o,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 Qt(Y(n,this.messages,this.state,(r,i,o)=>r.onRunFailed?.({error:e,messages:i,state:o,agent:this,input:t}))).pipe(en(r=>{let i=r;if((i.messages!==void 0||i.state!==void 0)&&(i.messages!==void 0&&(this.messages=i.messages,n.forEach(o=>{o.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:t})})),i.state!==void 0&&(this.state=i.state,n.forEach(o=>{o.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:t})}))),i.stopPropagation!==!0){let o=String(e);if(!(e.name==="AbortError"||e.message==="Fetch is aborted"||e.message==="signal is aborted without reason"||e.message==="component unmounted"||o==="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,i,o)=>r.onRunFinalized?.({messages:i,state:o,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??Et();let e=this.prepareRunAgentInput(t);return(this.middlewares.length===0?this.run(e):this.middlewares.reduceRight((n,r)=>({run:i=>r.run(i,n),get messages(){return n.messages},get state(){return n.state}}),this).run(e)).pipe(fo(this.debugLogger),ia(this.debugLogger),ag(this.threadId,e.runId,this.agentId),n=>n.pipe(en(r=>(this.debugLogger?.event("LEGACY","Event:",r,{type:r.type}),r))))}},Od=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 Xm(jm(()=>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 wg=/\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;function Md(t,e){let n=[];return{text:t.replace(wg,(i,o)=>{let s=e[o];return s==null||s===""?(n.includes(o)||n.push(o),i):String(s)}),missing:n}}function _g(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 aa(t){return Array.isArray(t)?t.filter(_g):[]}var ur=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 la(t){return t[Xn]===!0}function go(t){return t[Kn]===!0}function vo(t,e){return Object.getOwnPropertyDescriptor(t,e).set}var Eg=vo(HTMLInputElement.prototype,"value"),Tg=vo(HTMLTextAreaElement.prototype,"value"),Sg=vo(HTMLSelectElement.prototype,"value"),Ag=vo(HTMLInputElement.prototype,"checked");function rn(t,e){t instanceof HTMLTextAreaElement?Tg.call(t,e):t instanceof HTMLSelectElement?Sg.call(t,e):Eg.call(t,e)}function pr(t,e){Ag.call(t,e)}var ca="#4f46e5",kg="rgba(79, 70, 229, 0.4)",Cg="--ag-ui-accent";function hr(t){return new Promise(e=>{setTimeout(e,t)})}function bo(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function da(t){return t<=0||bo()?Promise.resolve():hr(t)}function yo(t,e){let n=window.getComputedStyle(t).getPropertyValue(Cg).trim();return n===""?e:n}function Ld(t){return`0 0 0 3px ${yo(t,kg)}`}async function ua(t,e,n={}){let r=n.charDelayMs??35;rn(t,""),t.dispatchEvent(new Event("input",{bubbles:!0}));for(let i of e)rn(t,t.value+i),t.dispatchEvent(new Event("input",{bubbles:!0})),r>0&&await hr(r);t.dispatchEvent(new Event("change",{bubbles:!0}))}async function pa(t,e={}){let n=e.highlightMs??280,r=t.style.outline,i=t.style.outlineOffset;t.style.outline=`2px solid ${yo(t,ca)}`,t.style.outlineOffset="2px",await hr(n),t.style.outline=r,t.style.outlineOffset=i,t.click()}var Ig=600,Rg=100;function vt(t,e={}){let n=bo();return t.scrollIntoView({block:"center",inline:"nearest",behavior:n?"auto":"smooth"}),n?Promise.resolve():new Promise(r=>{let i,o=()=>{clearTimeout(i),document.removeEventListener("scroll",s,!0),document.removeEventListener("scrollend",o,!0),r()},s=()=>{document.removeEventListener("scroll",s,!0),clearTimeout(i),i=setTimeout(o,e.settleMs??Ig)};i=setTimeout(o,Rg),document.addEventListener("scroll",s,!0),document.addEventListener("scrollend",o,!0)})}var Ng=1200,Og=1/3;async function Pd(t,e,n){(e.focus??n)&&t.focus({preventScroll:!0});let r=e.flashMs??Ng;if(r<=0)return;let i=t.style.outline,o=t.style.outlineOffset,s=t.style.transition,a=e.color??yo(t,ca);t.style.outline=`3px solid ${a}`,t.style.outlineOffset="2px";let l=bo()?0:Math.round(r*Og);await hr(r-l),l>0&&(t.style.transition=`outline-color ${l}ms ease-out`,t.style.outline="3px solid transparent",await hr(l)),t.style.outline=i,t.style.outlineOffset=o,t.style.transition=s}function Mg(t,e={}){return Pd(t,e,!1)}function ha(t,e={}){return Pd(t,e,!0)}async function fa(t,e={}){let n=e.pressMs??140,r=t.style.transform,i=t.style.transition,o=t.style.boxShadow;t.style.transition="transform 80ms ease",t.style.transform="scale(0.96)",t.style.boxShadow=Ld(t),await da(n),t.style.transform=r,t.style.transition=i,t.style.boxShadow=o,t.click()}function Lg(t,e){for(let n of Array.from(t.options))if(n.value===e||n.text===e)return n;return null}async function ma(t,e,n={}){let r=Lg(t,e);if(r===null)throw new Error(`no <option> matching "${e}"`);let i=n.highlightMs??220,o=t.style.outline,s=t.style.outlineOffset;t.style.outline=`2px solid ${yo(t,ca)}`,t.style.outlineOffset="2px",await da(i),rn(t,r.value),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),t.style.outline=o,t.style.outlineOffset=s}async function ga(t,e,n={}){let r=n.flashMs??200,i=t.style.boxShadow;t.style.boxShadow=Ld(t),await da(r),pr(t,e),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),t.style.boxShadow=i}var va={SCROLL:"scroll",DRAG:"drag"};function ba(t,e){let n=[];return t.has(va.SCROLL)&&n.push(Pg(e)),t.has(va.DRAG)&&n.push(Dg(e)),n}function Pg(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 i=n==="top"?0:document.body.scrollHeight;return window.scrollTo({top:i,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 Dg(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??""),i=t(n);if(i===null)throw new Error(`no element matching "${n}"`);let o=t(r);if(o===null)throw new Error(`no element matching "${r}"`);return Ug(i,o),{dragged:!0,from:n,to:r}}}}function Ug(t,e){let n=new DataTransfer;fr(t,"dragstart",n),fr(e,"dragenter",n),fr(e,"dragover",n),fr(e,"drop",n),fr(t,"dragend",n)}function fr(t,e,n){let r=new Event(e,{bubbles:!0,cancelable:!0});r.dataTransfer=n,t.dispatchEvent(r)}function ya(t,e){return!e||t===null?[]:[{description:"page_map",value:JSON.stringify(t())}]}function xo(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 Hg=xo;function xa(t){let e={};if(!Array.isArray(t))return e;for(let n of t){if(n===null||typeof n!="object")continue;let r=n,i=r.name,o=r.summary,s=r.description;typeof i=="string"&&typeof o=="string"&&(e[i]=typeof s=="string"?{name:i,summary:o,description:s}:{name:i,summary:o})}return e}var Dd=/:([A-Za-z_][A-Za-z0-9_]*)/g;function zg(t){return[...t.matchAll(Dd)].map(e=>e[0].slice(1))}function Gg(t,e,n){let r={...n};return{path:e.replace(Dd,(o,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 Fg(t,e){let n=new URLSearchParams;for(let[i,o]of Object.entries(e))n.set(i,String(o));let r=n.toString();return r===""?t:`${t}?${r}`}function wa(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:zg(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,i=t().find(p=>p.id===r);if(i===void 0)throw new Error(`unknown route "${String(r)}"`);let o=n.params??{},{path:s,leftover:a}=Gg(i.id,i.path,o),l=Fg(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",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",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",confirmAction:"Confirm action",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 _a(t){let e={...le};for(let n of Object.keys(t)){let r=t[n];r!==void 0&&(e[n]=r)}return e}function Ud(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 Ea(t,e,n={}){let r=n.strings??le;return new Promise(i=>{let o=document.createElement("div");o.className="approval",o.setAttribute("part","approval"),e.toolName!==void 0&&o.setAttribute("data-tool-name",e.toolName),o.setAttribute("role","group"),o.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=document.createElement("div");a.className="approval-actions",a.setAttribute("part","approval-actions");let l=Ud("deny",r.deny),c=Ud("approve",r.approve),p=!1,m=y=>{p||(p=!0,l.disabled=!0,c.disabled=!0,o.setAttribute("data-resolved",y?"approved":"denied"),i(y))};if(l.addEventListener("click",()=>m(!1)),c.addEventListener("click",()=>m(!0)),n.signal?.addEventListener("abort",()=>m(!1),{once:!0}),a.append(l,c),o.append(s,a),t.appendChild(o),n.signal?.aborted===!0){m(!1);return}c.focus()})}function Ta(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($g(r,e)))}}function $g(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",()=>{Vg(n).then(i=>{Bg(r,i?e.copied:e.copyFailed,e)})}),r}async function Vg(t){let e=navigator.clipboard;if(e===void 0)return!1;try{return await e.writeText(t),!0}catch{return!1}}function Bg(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 Sa(t){let e=document.createElement("div");e.className="attachment-chips",e.setAttribute("part","attachment-chips");for(let n of t)e.appendChild(jg(n));return e}function jg(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=Aa(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 i=document.createElement("span");return i.className="attachment-chip-size",i.setAttribute("part","attachment-chip-size"),i.textContent=wo(t.size),e.append(n,r,i),e}function Aa(t){return t.startsWith("image/")?Hl:t==="application/pdf"?zl:t.startsWith("text/")?Gl:Ul}function wo(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 _o=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:Ee(),file:e,status:De.UPLOADING,progress:0,ref:null,error:"",controller:null};this.#e.push(n);let r=this.#o(e);if(r!==null){n.status=De.ERROR,n.error=r,this.#s(),this.#t.onChange?.();return}this.#s(),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.#s()}clear(){for(let e of this.#e)e.controller?.abort();this.#e=[],this.#s()}dispose(){for(let e of this.#e)e.controller?.abort()}#o(e){return this.#t.maxBytes>0&&e.size>this.#t.maxBytes?this.#r.tooLarge.replace("{size}",wo(this.#t.maxBytes)):qg(this.#t.accept,e)?null:this.#r.fileTypeNotAllowed}#n(e){let n=this.#o(e.file);if(n!==null){e.status=De.ERROR,e.error=n,this.#s(),this.#t.onChange?.();return}e.status=De.UPLOADING,e.progress=0,e.error="";let r=new AbortController;e.controller=r,this.#s(),this.#t.upload(e.file,i=>{e.progress=i,this.#s()},r.signal).then(i=>{e.status=De.READY,e.ref=i}).catch(i=>{e.status=De.ERROR,e.error=i instanceof Error?i.message:this.#r.uploadFailed}).finally(()=>{e.controller=null,this.#s(),this.#t.onChange?.()})}#i(e){e.controller?.abort(),this.#e=this.#e.filter(n=>n!==e),this.#s(),this.#t.onChange?.()}#s(){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=Aa(e.file.type),r.setAttribute("aria-hidden","true");let i=document.createElement("span");i.className="attachment-chip-name",i.setAttribute("part","attachment-chip-name"),i.textContent=e.file.name,i.title=e.file.name;let o=document.createElement("span");if(o.className="attachment-chip-size",o.setAttribute("part","attachment-chip-size"),o.textContent=e.status===De.ERROR?e.error:wo(e.file.size),n.append(r,i,o),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 qg(t,e){let n=t.split(",").map(o=>o.trim().toLowerCase()).filter(o=>o!=="");if(n.length===0)return!0;let r=e.type.toLowerCase(),i=e.name.toLowerCase();return n.some(o=>o.startsWith(".")?i.endsWith(o):o.endsWith("/*")?r.startsWith(o.slice(0,-1)):r===o)}var Wg="http://www.w3.org/2000/svg";var He={top:20,right:12,bottom:30,left:44},To=480-He.left-He.right,Eo=220-He.top-He.bottom,Hd=["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 Hd[t%Hd.length]}function dt(t,e){let n=document.createElementNS(Wg,t);for(let[r,i]of Object.entries(e))n.setAttribute(r,String(i));return n}function zd(t,e){let n=dt("text",{"font-size":10,fill:"currentColor","fill-opacity":.65,...e});return n.textContent=t,n}function Xg(t){let e=[];return t.labels.forEach((n,r)=>{let i=0;for(let o of t.series)i+=o.points[r]??0,e.push(i)}),e}function Kg(t){let e=t.kind==="stacked"?Xg(t):t.series.flatMap(i=>[...i.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+Eo-(t-e)/(n-e)*Eo}function ka(t,e){let n=To/e;return He.left+n*t+n/2}function Yg(t,e,n,r){for(let i of[n,r]){let o=sn(i,n,r);t.appendChild(dt("line",{x1:He.left,y1:o,x2:480-He.right,y2:o,stroke:"currentColor","stroke-opacity":i===n?.35:.12})),t.appendChild(zd(String(Math.round(i)),{x:He.left-6,y:o+4,"text-anchor":"end"}))}e.labels.forEach((i,o)=>{t.appendChild(zd(i,{x:ka(o,e.labels.length),y:220-He.bottom+16,"text-anchor":"middle"}))})}function Zg(t,e,n,r){let i=To/e.labels.length,o=i*.7/e.series.length,s=sn(n,n,r);e.series.forEach((a,l)=>{a.points.forEach((c,p)=>{let m=sn(c,n,r);t.appendChild(dt("rect",{x:He.left+i*p+i*.15+o*l,y:m,width:o,height:Math.max(1,s-m),fill:on(l),rx:2}))})})}function Jg(t,e,n,r){let i=To/e.labels.length,o=i*.7,s=e.labels.map(()=>0);e.series.forEach((a,l)=>{a.points.forEach((c,p)=>{let m=s[p]??0,y=m+c;s[p]=y;let f=sn(y,n,r);t.appendChild(dt("rect",{x:He.left+i*p+i*.15,y:f,width:o,height:Math.max(1,sn(m,n,r)-f),fill:on(l)}))})})}function Qg(t,e,n,r){e.series.forEach((i,o)=>{let s=i.points.map((a,l)=>`${ka(l,e.labels.length)},${sn(a,n,r)}`).join(" ");t.appendChild(dt("polyline",{points:s,fill:"none",stroke:on(o),"stroke-width":2,"stroke-linejoin":"round"}))})}function ev(t,e,n,r){e.series.forEach((i,o)=>{i.points.forEach((s,a)=>{t.appendChild(dt("circle",{cx:ka(a,e.labels.length),cy:sn(s,n,r),r:4,fill:on(o),"fill-opacity":.85}))})})}function tv(t,e){let n=e.reduce((a,l)=>a+l,0),r=480/2,i=He.top+Eo/2,o=Math.min(To,Eo)/2;if(n===0){t.appendChild(dt("circle",{cx:r,cy:i,r:o,fill:"none",stroke:"currentColor","stroke-opacity":.3}));return}let s=-Math.PI/2;e.forEach((a,l)=>{let c=a/n*Math.PI*2,p=s+c;if(c>=Math.PI*2)t.appendChild(dt("circle",{cx:r,cy:i,r:o,fill:on(l)}));else{let m=r+o*Math.cos(s),y=i+o*Math.sin(s),f=r+o*Math.cos(p),h=i+o*Math.sin(p),g=c>Math.PI?1:0;t.appendChild(dt("path",{d:`M ${r} ${i} L ${m} ${y} A ${o} ${o} 0 ${g} 1 ${f} ${h} Z`,fill:on(l)}))}s=p})}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 i=document.createElement("span");i.className="chart-legend-item";let o=document.createElement("span");o.className="chart-legend-swatch",o.style.background=on(r),i.append(o,document.createTextNode(n)),e.appendChild(i)}),e}function mr(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 i=document.createElement("div");i.className="chart-title",i.setAttribute("part","chart-title"),i.textContent=t.title,e.appendChild(i)}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 i=t.series[0];tv(n,i.points.map(o=>Math.max(0,o)))}else{let{min:i,max:o}=Kg(t);Yg(n,t,i,o),t.kind==="bar"?Zg(n,t,i,o):t.kind==="stacked"?Jg(n,t,i,o):t.kind==="line"?Qg(n,t,i,o):ev(n,t,i,o)}e.appendChild(n);let r=nv(t.kind==="pie"?t.labels:t.series.map(i=>i.label));return r!==null&&e.appendChild(r),e}var rv=["bar","line","pie","scatter","stacked"];function iv(t){return rv.includes(t)?t:"bar"}function ov(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 sv(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=sv(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=ov(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 i=iv(e.kind),o=e.title;return typeof o=="string"?{kind:i,title:o,labels:n,series:r}:{kind:i,labels:n,series:r}}var So="render_chart";function av(t){let e=Pn(t);return e===null?null:mr(e)}function lv(t){let e=Pn(t);return e!==null&&e.labels.length>0&&e.series.length>0}var cv="chart not rendered: expected labels (strings) and series, each with one finite number per label";function Gd(){return{name:So,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=>lv(t)?"chart rendered":cv,render:av}}function Ao(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 i=Math.round(r/60);if(i<60)return n.minutesAgo.replace("{n}",String(i));let o=Math.round(i/60);if(o<24)return n.hoursAgo.replace("{n}",String(o));let s=Math.round(o/24);return s<7?n.daysAgo.replace("{n}",String(s)):n.weeksAgo.replace("{n}",String(Math.round(s/7)))}function Fd(t){return t.preview!==void 0&&t.preview!==null&&t.preview!==""?t.preview:null}function $d(t){return t.replace(/\s+/g," ").trim()}var gr=class{element;#t;#r;#e;#o=null;#n;#i=[];constructor(e,n=le){this.#t=e,this.#n=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",i=>this.#u(i))}setRuns(e){this.#i=e,this.#d()}setStrings(e){this.#n=e,this.element.setAttribute("aria-label",e.checkpoints),this.#e.textContent=e.checkpoints,this.#d()}open(){this.open_||(this.#o=this.#s(),this.element.hidden=!1,(this.#c()[0]??this.element).focus())}close(){this.open_&&(this.element.hidden=!0,this.#o?.focus(),this.#o=null)}#s(){return this.element.getRootNode().activeElement}#c(){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.#c(),r=n[0],i=n[n.length-1],o=this.#s();e.shiftKey&&o===r?(e.preventDefault(),i?.focus()):!e.shiftKey&&o===i&&(e.preventDefault(),r?.focus())}get open_(){return!this.element.hidden}#d(){if(this.#r.replaceChildren(),this.#i.length===0){let n=document.createElement("div");n.className="checkpoints-empty",n.setAttribute("part","checkpoints-empty"),n.textContent=this.#n.noCheckpoints,this.#r.append(n);return}let e=this.#h();for(let n of this.#i)this.#r.append(this.#f(n,e))}#h(){let e=new Set,n=new Set;for(let r of this.#i){let i=Fd(r);if(i===null)continue;let o=$d(i);e.has(o)&&n.add(o),e.add(o)}return n}#f(e,n){let r=document.createElement("div");r.className="checkpoint-row",r.setAttribute("part","checkpoint-row");let i=Fd(e),o=e.started_at===null?null:Ao(Date.parse(e.started_at),Date.now(),this.#n),s=document.createElement("span");if(s.className="checkpoint-label",s.setAttribute("part","checkpoint-label"),s.textContent=i??o??e.run_id,r.append(s),i!==null&&o!==null){let l=document.createElement("span");l.className="checkpoint-time",l.setAttribute("part","checkpoint-time"),l.textContent=o,r.append(l)}if((i===null?o!==null:n.has($d(i)))&&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.#n.forkedRun,l.title=e.parent_run_id,r.append(l)}return r.append(this.#p(e.run_id,"resume",this.#n.resumeRun),this.#p(e.run_id,"fork",this.#n.forkRun)),r}#p(e,n,r){let i=document.createElement("button");return i.type="button",i.className=`checkpoint-action checkpoint-${n}`,i.setAttribute("part",`checkpoint-action checkpoint-${n}`),i.textContent=r,i.addEventListener("click",()=>{this.close(),this.#t(e,n)}),i}};function Vd(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 Ca(t,e,n={}){let r=n.strings??le;return new Promise(i=>{let o=document.createElement("div");o.className="confirm",o.setAttribute("part","confirm"),o.setAttribute("data-tool-name",e.toolName),o.setAttribute("role","group"),o.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=Vd("cancel",r.cancel),p=Vd("confirm",r.confirm),m=!1,y=f=>{m||(m=!0,o.remove(),i(f))};if(c.addEventListener("click",()=>y(!1)),p.addEventListener("click",()=>y(!0)),n.signal?.addEventListener("abort",()=>y(!1),{once:!0}),l.append(c,p),o.append(s,a,l),t.appendChild(o),n.signal?.aborted===!0){y(!1);return}p.focus()})}function Ia(t){let e=t.replace(/[._-]+/g," ").trim();return e===""?t:e.charAt(0).toUpperCase()+e.slice(1)}function dv(t){let e=document.createElement("input");return e.type="text",e.className="question-input",e.setAttribute("part","question-input"),e.placeholder=t,e}function Ra(t,e,n={}){let r=n.strings??le,i=e.options??[],o=i.length>0,s=!o||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 p=document.createElement("div");p.className="question-options",p.setAttribute("part","question-options");let m=`q-${i.length}-${e.question.length}`,y=[];for(let U of i){let K=document.createElement("label");K.className="question-choice",K.setAttribute("part","question-choice");let ie=document.createElement("input");ie.type="radio",ie.name=m,ie.value=U,ie.setAttribute("part","question-radio");let qe=document.createElement("span");qe.setAttribute("part","question-choice-text"),qe.textContent=U,K.append(ie,qe),p.appendChild(K),y.push(ie)}let f=null,h=null;if(s){if(h=dv(r.answerPlaceholder),o){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),p.appendChild(U),h.disabled=!0}p.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,E=()=>{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=E()===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=E();K!==null&&H(K)}}),x.addEventListener("click",()=>{let U=E();U!==null&&H(U)}),n.signal?.addEventListener("abort",()=>H(""),{once:!0}),l.append(c,p,g),t.appendChild(l),n.signal?.aborted===!0){H("");return}I(),(o?y[0]:h)?.focus()})}function Bd(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 uv(t){if(Array.isArray(t))return t}function pv(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r,i,o,s,a=[],l=!0,c=!1;try{if(o=(n=n.call(t)).next,e!==0)for(;!(l=(r=o.call(n)).done)&&(a.push(r.value),a.length!==e);l=!0);}catch(p){c=!0,i=p}finally{try{if(!l&&n.return!=null&&(s=n.return(),Object(s)!==s))return}finally{if(c)throw i}}return a}}function hv(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
12
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function fv(t,e){return uv(t)||pv(t,e)||mv(t,e)||hv()}function mv(t,e){if(t){if(typeof t=="string")return Bd(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)?Bd(t,e):void 0}}var ou=Object.entries,jd=Object.setPrototypeOf,gv=Object.isFrozen,vv=Object.getPrototypeOf,bv=Object.getOwnPropertyDescriptor,Te=Object.freeze,Se=Object.seal,Hn=Object.create,su=typeof Reflect<"u"&&Reflect,Da=su.apply,Ua=su.construct;Te||(Te=function(e){return e});Se||(Se=function(e){return e});Da||(Da=function(e,n){for(var r=arguments.length,i=new Array(r>2?r-2:0),o=2;o<r;o++)i[o-2]=arguments[o];return e.apply(n,i)});Ua||(Ua=function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return new e(...r)});var Dn=me(Array.prototype.forEach),yv=me(Array.prototype.lastIndexOf),qd=me(Array.prototype.pop),Un=me(Array.prototype.push),xv=me(Array.prototype.splice),Rt=Array.isArray,yr=me(String.prototype.toLowerCase),Na=me(String.prototype.toString),Wd=me(String.prototype.match),vr=me(String.prototype.replace),Xd=me(String.prototype.indexOf),wv=me(String.prototype.trim),_v=me(Number.prototype.toString),Ev=me(Boolean.prototype.toString),Kd=typeof BigInt>"u"?null:me(BigInt.prototype.toString),Yd=typeof Symbol>"u"?null:me(Symbol.prototype.toString),ye=me(Object.prototype.hasOwnProperty),br=me(Object.prototype.toString),be=me(RegExp.prototype.test),an=Tv(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),i=1;i<n;i++)r[i-1]=arguments[i];return Da(t,e,r)}}function Tv(t){return function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return Ua(t,n)}}function W(t,e){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:yr;if(jd&&jd(t,null),!Rt(e))return t;let r=e.length;for(;r--;){let i=e[r];if(typeof i=="string"){let o=n(i);o!==i&&(gv(e)||(e[r]=o),i=o)}t[i]=!0}return t}function Sv(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 ou(t)){var n=fv(r,2);let i=n[0],o=n[1];ye(t,i)&&(Rt(o)?e[i]=Sv(o):o&&typeof o=="object"&&o.constructor===Object?e[i]=ke(o):e[i]=o)}return e}function Av(t){switch(typeof t){case"string":return t;case"number":return _v(t);case"boolean":return Ev(t);case"bigint":return Kd?Kd(t):"0";case"symbol":return Yd?Yd(t):"Symbol()";case"undefined":return br(t);case"function":case"object":{if(t===null)return br(t);let e=t,n=Ze(e,"toString");if(typeof n=="function"){let r=n(e);return typeof r=="string"?r:br(r)}return br(t)}default:return br(t)}}function Ze(t,e){for(;t!==null;){let r=bv(t,e);if(r){if(r.get)return me(r.get);if(typeof r.value=="function")return me(r.value)}t=vv(t)}function n(){return null}return n}function kv(t){try{return be(t,""),!0}catch{return!1}}var Zd=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"]),Oa=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"]),Ma=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"]),Cv=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"]),La=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"]),Iv=Te(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),Jd=Te(["#text"]),Qd=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"]),Pa=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"]),eu=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"]),ko=Te(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),Rv=Se(/{{[\w\W]*|^[\w\W]*}}/g),Nv=Se(/<%[\w\W]*|^[\w\W]*%>/g),Ov=Se(/\${[\w\W]*/g),Mv=Se(/^data-[\-\w.\u00B7-\uFFFF]+$/),Lv=Se(/^aria-[\-\w]+$/),tu=Se(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Pv=Se(/^(?:\w+script|data):/i),Dv=Se(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Uv=Se(/^html$/i),Hv=Se(/^[a-z][.\w]*(-[.\w]+)+$/i),nu=Se(/<[/\w!]/g),ru=Se(/<[/\w]/g),zv=Se(/<\/no(script|embed|frames)/i),Gv=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},Fv=function(){return typeof window>"u"?null:window},$v=function(e,n){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let r=null,i="data-tt-policy-suffix";n&&n.hasAttribute(i)&&(r=n.getAttribute(i));let o="dompurify"+(r?"#"+r:"");try{return e.createPolicy(o,{createHTML(s){return s},createScriptURL(s){return s}})}catch{return console.warn("TrustedTypes policy "+o+" could not be created."),null}},iu=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},It=function(e,n,r,i){return ye(e,n)&&Rt(e[n])?W(i.base?ke(i.base):{},e[n],i.transform):r};function au(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Fv(),e=T=>au(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,i=r.currentScript;t.DocumentFragment;let o=t.HTMLTemplateElement,s=t.Node,a=t.Element,l=t.NodeFilter,c=t.NamedNodeMap;c===void 0&&(t.NamedNodeMap||t.MozNamedAttrMap),t.HTMLFormElement;let p=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"),E=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 o=="function"){let T=n.createElement("template");T.content&&T.content.ownerDocument&&(n=T.content.ownerDocument)}let ie,qe="",Bo,ol=!1,Vn=0,sl=function(){if(Vn>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(u){sl(),Vn++;try{return ie.createHTML(u)}finally{Vn--}},ju=function(u){sl(),Vn++;try{return ie.createScriptURL(u)}finally{Vn--}},qu=function(){return ol||(Bo=$v(m,i),ol=!0),Bo},Rr=n,jo=Rr.implementation,al=Rr.createNodeIterator,Wu=Rr.createDocumentFragment,Xu=Rr.getElementsByTagName,Ku=r.importNode,oe=iu();e.isSupported=typeof ou=="function"&&typeof S=="function"&&jo&&jo.createHTMLDocument!==void 0;let Yu=Rv,Zu=Nv,Ju=Ov,Qu=Mv,ep=Lv,tp=Pv,ll=Dv,np=Hv,cl=tu,se=null,qo=W({},[...Zd,...Oa,...Ma,...La,...Jd]),ae=null,Wo=W({},[...Qd,...Pa,...eu,...ko]),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}})),Bn=null,dl=null,yt=Object.seal(Hn(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),ul=!0,Xo=!0,pl=!1,hl=!0,xt=!1,wt=!0,Ot=!1,Ko=!1,Nr=null,Or=null,Yo=!1,pn=!1,Mr=!1,Lr=!1,fl=!0,ml=!1,gl="user-content-",Zo=!0,Pr=!1,hn={},tt=null,Jo=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"]),vl=null,bl=W({},["audio","video","img","source","image","track"]),Qo=null,yl=W({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Dr="http://www.w3.org/1998/Math/MathML",Ur="http://www.w3.org/2000/svg",nt="http://www.w3.org/1999/xhtml",fn=nt,es=!1,ts=null,rp=W({},[Dr,Ur,nt],Na),xl=Te(["mi","mo","mn","ms","mtext"]),ns=W({},xl),wl=Te(["annotation-xml"]),rs=W({},wl),ip=W({},["title","style","font","a","script"]),jn=null,op=["application/xhtml+xml","text/html"],sp="text/html",ce=null,mn=null,ap=n.createElement("form"),_l=function(u){return u instanceof RegExp||u instanceof Function},is=function(){let u=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(mn&&mn===u)return;(!u||typeof u!="object")&&(u={}),u=ke(u),jn=op.indexOf(u.PARSER_MEDIA_TYPE)===-1?sp:u.PARSER_MEDIA_TYPE,ce=jn==="application/xhtml+xml"?Na:yr,se=It(u,"ALLOWED_TAGS",qo,{transform:ce}),ae=It(u,"ALLOWED_ATTR",Wo,{transform:ce}),ts=It(u,"ALLOWED_NAMESPACES",rp,{transform:Na}),Qo=It(u,"ADD_URI_SAFE_ATTR",yl,{transform:ce,base:yl}),vl=It(u,"ADD_DATA_URI_TAGS",bl,{transform:ce,base:bl}),tt=It(u,"FORBID_CONTENTS",Jo,{transform:ce}),Bn=It(u,"FORBID_TAGS",ke({}),{transform:ce}),dl=It(u,"FORBID_ATTR",ke({}),{transform:ce}),hn=ye(u,"USE_PROFILES")?u.USE_PROFILES&&typeof u.USE_PROFILES=="object"?ke(u.USE_PROFILES):u.USE_PROFILES:!1,ul=u.ALLOW_ARIA_ATTR!==!1,Xo=u.ALLOW_DATA_ATTR!==!1,pl=u.ALLOW_UNKNOWN_PROTOCOLS||!1,hl=u.ALLOW_SELF_CLOSE_IN_ATTR!==!1,xt=u.SAFE_FOR_TEMPLATES||!1,wt=u.SAFE_FOR_XML!==!1,Ot=u.WHOLE_DOCUMENT||!1,pn=u.RETURN_DOM||!1,Mr=u.RETURN_DOM_FRAGMENT||!1,Lr=u.RETURN_TRUSTED_TYPE||!1,Yo=u.FORCE_BODY||!1,fl=u.SANITIZE_DOM!==!1,ml=u.SANITIZE_NAMED_PROPS||!1,Zo=u.KEEP_CONTENT!==!1,Pr=u.IN_PLACE||!1,cl=kv(u.ALLOWED_URI_REGEXP)?u.ALLOWED_URI_REGEXP:tu,fn=typeof u.NAMESPACE=="string"?u.NAMESPACE:nt,ns=ye(u,"MATHML_TEXT_INTEGRATION_POINTS")&&u.MATHML_TEXT_INTEGRATION_POINTS&&typeof u.MATHML_TEXT_INTEGRATION_POINTS=="object"?ke(u.MATHML_TEXT_INTEGRATION_POINTS):W({},xl),rs=ye(u,"HTML_INTEGRATION_POINTS")&&u.HTML_INTEGRATION_POINTS&&typeof u.HTML_INTEGRATION_POINTS=="object"?ke(u.HTML_INTEGRATION_POINTS):W({},wl);let b=ye(u,"CUSTOM_ELEMENT_HANDLING")&&u.CUSTOM_ELEMENT_HANDLING&&typeof u.CUSTOM_ELEMENT_HANDLING=="object"?ke(u.CUSTOM_ELEMENT_HANDLING):Hn(null);if(pe=Hn(null),ye(b,"tagNameCheck")&&_l(b.tagNameCheck)&&(pe.tagNameCheck=b.tagNameCheck),ye(b,"attributeNameCheck")&&_l(b.attributeNameCheck)&&(pe.attributeNameCheck=b.attributeNameCheck),ye(b,"allowCustomizedBuiltInElements")&&typeof b.allowCustomizedBuiltInElements=="boolean"&&(pe.allowCustomizedBuiltInElements=b.allowCustomizedBuiltInElements),Se(pe),xt&&(Xo=!1),Mr&&(pn=!0),hn&&(se=W({},Jd),ae=Hn(null),hn.html===!0&&(W(se,Zd),W(ae,Qd)),hn.svg===!0&&(W(se,Oa),W(ae,Pa),W(ae,ko)),hn.svgFilters===!0&&(W(se,Ma),W(ae,Pa),W(ae,ko)),hn.mathMl===!0&&(W(se,La),W(ae,eu),W(ae,ko))),yt.tagCheck=null,yt.attributeCheck=null,ye(u,"ADD_TAGS")&&(typeof u.ADD_TAGS=="function"?yt.tagCheck=u.ADD_TAGS:Rt(u.ADD_TAGS)&&(se===qo&&(se=ke(se)),W(se,u.ADD_TAGS,ce))),ye(u,"ADD_ATTR")&&(typeof u.ADD_ATTR=="function"?yt.attributeCheck=u.ADD_ATTR:Rt(u.ADD_ATTR)&&(ae===Wo&&(ae=ke(ae)),W(ae,u.ADD_ATTR,ce))),ye(u,"ADD_URI_SAFE_ATTR")&&Rt(u.ADD_URI_SAFE_ATTR)&&W(Qo,u.ADD_URI_SAFE_ATTR,ce),ye(u,"FORBID_CONTENTS")&&Rt(u.FORBID_CONTENTS)&&(tt===Jo&&(tt=ke(tt)),W(tt,u.FORBID_CONTENTS,ce)),ye(u,"ADD_FORBID_CONTENTS")&&Rt(u.ADD_FORBID_CONTENTS)&&(tt===Jo&&(tt=ke(tt)),W(tt,u.ADD_FORBID_CONTENTS,ce)),Zo&&(se["#text"]=!0),Ot&&W(se,["html","head","body"]),se.table&&(W(se,["tbody"]),delete Bn.tbody),u.TRUSTED_TYPES_POLICY){if(typeof u.TRUSTED_TYPES_POLICY.createHTML!="function")throw an('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof u.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw an('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');let w=ie;ie=u.TRUSTED_TYPES_POLICY;try{qe=un("")}catch(N){throw ie=w,N}}else u.TRUSTED_TYPES_POLICY===null?(ie=void 0,qe=""):(ie===void 0&&(ie=qu()),ie&&typeof qe=="string"&&(qe=un("")));Te&&Te(u),mn=u},El=W({},[...Oa,...Ma,...Cv]),Tl=W({},[...La,...Iv]),lp=function(u,b,w){return b.namespaceURI===nt?u==="svg":b.namespaceURI===Dr?u==="svg"&&(w==="annotation-xml"||ns[w]):!!El[u]},cp=function(u,b,w){return b.namespaceURI===nt?u==="math":b.namespaceURI===Ur?u==="math"&&rs[w]:!!Tl[u]},dp=function(u,b,w){return b.namespaceURI===Ur&&!rs[w]||b.namespaceURI===Dr&&!ns[w]?!1:!Tl[u]&&(ip[u]||!El[u])},up=function(u){let b=S(u);(!b||!b.tagName)&&(b={namespaceURI:fn,tagName:"template"});let w=yr(u.tagName),N=yr(b.tagName);return ts[u.namespaceURI]?u.namespaceURI===Ur?lp(w,b,N):u.namespaceURI===Dr?cp(w,b,N):u.namespaceURI===nt?dp(w,b,N):!!(jn==="application/xhtml+xml"&&ts[u.namespaceURI]):!1},_t=function(u){Un(e.removed,{element:u});try{S(u).removeChild(u)}catch{if(h(u),!S(u))throw an("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},Hr=function(u){qn(u);let b=x(u);if(b){let N=[];Dn(b,L=>{Un(N,L)}),Dn(N,L=>{try{h(L)}catch{}})}let w=I(u);if(w)for(let N=w.length-1;N>=0;--N){let L=w[N],z=L&&L.name;if(typeof z=="string")try{u.removeAttribute(z)}catch{}}},Mt=function(u,b){try{Un(e.removed,{attribute:b.getAttributeNode(u),from:b})}catch{Un(e.removed,{attribute:null,from:b})}if(b.removeAttribute(u),u==="is")if(pn||Mr)try{_t(b)}catch{}else try{b.setAttribute(u,"")}catch{}},pp=function(u){let b=I(u);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{u.removeAttribute(L)}catch{}}},qn=function(u){let b=[u];for(;b.length>0;){let w=b.pop();(H?H(w):w.nodeType)===ze.element&&pp(w);let L=x(w);if(L)for(let z=L.length-1;z>=0;--z)b.push(L[z])}},hp=function(u){if(!wt)return;let b=[u];for(;b.length>0;){let w=b.pop(),N=H?H(w):w.nodeType;if(N===ze.processingInstruction||N===ze.comment&&be(ru,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])}},Sl=function(u){let b=null,w=null;if(Yo)u="<remove></remove>"+u;else{let z=Wd(u,/^[\r\n\t ]+/);w=z&&z[0]}jn==="application/xhtml+xml"&&fn===nt&&(u='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+u+"</body></html>");let N=ie?un(u):u;if(fn===nt)try{b=new p().parseFromString(N,jn)}catch{}if(!b||!b.documentElement){b=jo.createDocument(fn,"template",null);try{b.documentElement.innerHTML=es?qe:N}catch{}}let L=b.body||b.documentElement;return u&&w&&L.insertBefore(n.createTextNode(w),L.childNodes[0]||null),fn===nt?Xu.call(b,Ot?"html":"body")[0]:Ot?b.documentElement:L},Al=function(u){let b=K?K(u):u.ownerDocument;return al.call(b||u,u,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},zr=function(u){return u=vr(u,Yu," "),u=vr(u,Zu," "),u=vr(u,Ju," "),u},os=function(u){var b;u.normalize();let w=K?K(u):u.ownerDocument,N=al.call(w||u,u,l.SHOW_TEXT|l.SHOW_COMMENT|l.SHOW_CDATA_SECTION|l.SHOW_PROCESSING_INSTRUCTION,null),L=N.nextNode();for(;L;)L.data=zr(L.data),L=N.nextNode();let z=(b=u.querySelectorAll)===null||b===void 0?void 0:b.call(u,"template");z&&Dn(z,Z=>{gn(Z.content)&&os(Z.content)})},Gr=function(u){let b=U?U(u):null;return typeof b!="string"||ce(b)!=="form"?!1:typeof u.nodeName!="string"||typeof u.textContent!="string"||typeof u.removeChild!="function"||u.attributes!==I(u)||typeof u.removeAttribute!="function"||typeof u.setAttribute!="function"||typeof u.namespaceURI!="string"||typeof u.insertBefore!="function"||typeof u.hasChildNodes!="function"||u.nodeType!==H(u)||u.childNodes!==x(u)},gn=function(u){if(!H||typeof u!="object"||u===null)return!1;try{return H(u)===ze.documentFragment}catch{return!1}},Wn=function(u){if(!H||typeof u!="object"||u===null)return!1;try{return typeof H(u)=="number"}catch{return!1}};function rt(T,u,b){T.length!==0&&Dn(T,w=>{w.call(e,u,b,mn)})}let fp=function(u,b){return!!(wt&&u.hasChildNodes()&&!Wn(u.firstElementChild)&&be(nu,u.textContent)&&be(nu,u.innerHTML)||wt&&u.namespaceURI===nt&&b==="style"&&Wn(u.firstElementChild)||u.nodeType===ze.processingInstruction||wt&&u.nodeType===ze.comment&&be(ru,u.data))},mp=function(u,b,w){if(!Bn[b]&&Rl(b)&&(pe.tagNameCheck instanceof RegExp&&be(pe.tagNameCheck,b)||pe.tagNameCheck instanceof Function&&pe.tagNameCheck(b)))return!1;if(Zo&&!tt[b]){let N=S(u),L=x(u);if(L&&N){let z=L.length;for(let Z=z-1;Z>=0;--Z){let de=u===w?f(L[Z],!0):L[Z];N.insertBefore(de,g(u))}}}return _t(u),!0},kl=function(u,b,w,N){return u.length===0?b:b===w||b===N?ke(b):b},Cl=function(u,b){if(rt(oe.beforeSanitizeElements,u,null),u!==b&&S(u)===null)return Pr&&qn(u),!0;if(Gr(u))return _t(u),!0;let w=ce(U?U(u):u.nodeName);if(se=kl(oe.uponSanitizeElement,se,qo,Nr),rt(oe.uponSanitizeElement,u,{tagName:w,allowedTags:se}),u!==b&&S(u)===null)return Pr&&qn(u),!0;if(fp(u,w))return _t(u),!0;if(Bn[w]||!(yt.tagCheck instanceof Function&&yt.tagCheck(w))&&!se[w]){let L=mp(u,w,b);return L===!1&&rt(oe.afterSanitizeElements,u,null),L}if((H?H(u):u.nodeType)===ze.element&&!up(u)||(w==="noscript"||w==="noembed"||w==="noframes")&&be(zv,u.innerHTML))return _t(u),!0;if(xt&&u.nodeType===ze.text){let L=zr(u.textContent);u.textContent!==L&&(Un(e.removed,{element:u.cloneNode()}),u.textContent=L)}return rt(oe.afterSanitizeElements,u,null),!1},Il=function(u,b,w){if(dl[b]||wt&&b==="patchsrc"||wt&&b==="for"&&u!=="label"&&u!=="output"||fl&&(b==="id"||b==="name")&&(w in n||w in ap))return!1;let N=ae[b]||yt.attributeCheck instanceof Function&&yt.attributeCheck(b,u);if(!(Xo&&be(Qu,b))){if(!(ul&&be(ep,b))){if(N){if(!Qo[b]){if(!be(cl,vr(w,ll,""))){if(!((b==="src"||b==="xlink:href"||b==="href")&&u!=="script"&&Xd(w,"data:")===0&&vl[u])){if(!(pl&&!be(tp,vr(w,ll,"")))){if(w)return!1}}}}}else if(!(Rl(u)&&(pe.tagNameCheck instanceof RegExp&&be(pe.tagNameCheck,u)||pe.tagNameCheck instanceof Function&&pe.tagNameCheck(u))&&(pe.attributeNameCheck instanceof RegExp&&be(pe.attributeNameCheck,b)||pe.attributeNameCheck instanceof Function&&pe.attributeNameCheck(b,u))||b==="is"&&pe.allowCustomizedBuiltInElements&&(pe.tagNameCheck instanceof RegExp&&be(pe.tagNameCheck,w)||pe.tagNameCheck instanceof Function&&pe.tagNameCheck(w))))return!1}}return!0},gp=W({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),Rl=function(u){return!gp[yr(u)]&&be(np,u)},vp=function(u,b,w,N){if(ie&&typeof m=="object"&&typeof m.getAttributeType=="function"&&!w)switch(m.getAttributeType(u,b)){case"TrustedHTML":return un(N);case"TrustedScriptURL":return ju(N)}return N},bp=function(u,b,w,N){try{w?u.setAttributeNS(w,b,N):u.setAttribute(b,N),Gr(u)?_t(u):qd(e.removed)}catch{Mt(b,u)}},Nl=function(u){rt(oe.beforeSanitizeAttributes,u,null);let b=u.attributes;if(!b||Gr(u))return;ae=kl(oe.uponSanitizeAttribute,ae,Wo,Or);let w={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:ae,forceKeepAttr:void 0},N=b.length,L=ce(u.nodeName);for(;N--;){let z=b[N],Z=z.name,de=z.namespaceURI,Re=z.value,Ne=ce(Z),as=Re,Ie=Z==="value"?as:wv(as);if(w.attrName=Ne,w.attrValue=Ie,w.keepAttr=!0,w.forceKeepAttr=void 0,rt(oe.uponSanitizeAttribute,u,w),Ie=w.attrValue,ml&&(Ne==="id"||Ne==="name")&&Xd(Ie,gl)!==0&&(Mt(Z,u),Ie=gl+Ie),wt&&be(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,Ie)){Mt(Z,u);continue}if(Ne==="attributename"&&Wd(Ie,"href")){Mt(Z,u);continue}if(!w.forceKeepAttr){if(!w.keepAttr){Mt(Z,u);continue}if(!hl&&be(Gv,Ie)){Mt(Z,u);continue}if(xt&&(Ie=zr(Ie)),!Il(L,Ne,Ie)){Mt(Z,u);continue}Ie=vp(L,Ne,de,Ie),Ie!==as&&bp(u,Z,de,Ie)}}rt(oe.afterSanitizeAttributes,u,null)},Fr=function(u){let b=null,w=Al(u);for(rt(oe.beforeSanitizeShadowDOM,u,null);b=w.nextNode();)if(rt(oe.uponSanitizeShadowNode,b,null),Cl(b,u),Nl(b),gn(b.content)&&Fr(b.content),(H?H(b):b.nodeType)===ze.element){let L=E(b);gn(L)&&(ss(L),Fr(L))}rt(oe.afterSanitizeShadowDOM,u,null)},ss=function(u){let b=[{node:u,shadow:null}];for(;b.length>0;){let w=b.pop();if(w.shadow){Fr(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=E(N);gn(de)&&b.push({node:null,shadow:de},{node:de,shadow:null})}}};return e.sanitize=function(T){let u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},b=null,w=null,N=null,L=null;if(es=!T,es&&(T="<!-->"),typeof T!="string"&&!Wn(T)&&(T=Av(T),typeof T!="string"))throw an("dirty is not a string, aborting");if(!e.isSupported)return T;Ko?(se=Nr,ae=Or):is(u),(oe.uponSanitizeElement.length>0||oe.uponSanitizeAttribute.length>0)&&(se=ke(se)),oe.uponSanitizeAttribute.length>0&&(ae=ke(ae)),e.removed=[];let z=Pr&&typeof T!="string"&&Wn(T);if(z){hp(T);let Re=U?U(T):T.nodeName;if(typeof Re=="string"){let Ne=ce(Re);if(!se[Ne]||Bn[Ne])throw Hr(T),an("root node is forbidden and cannot be sanitized in-place")}if(Gr(T))throw Hr(T),an("root node is clobbered and cannot be sanitized in-place");try{ss(T)}catch(Ne){throw Hr(T),Ne}}else if(Wn(T))b=Sl("<!---->"),w=b.ownerDocument.importNode(T,!0),w.nodeType===ze.element&&w.nodeName==="BODY"||w.nodeName==="HTML"?b=w:b.appendChild(w),ss(w);else{if(!pn&&!xt&&!Ot&&T.indexOf("<")===-1)return ie&&Lr?un(T):T;if(b=Sl(T),!b)return pn?null:Lr?qe:""}b&&Yo&&_t(b.firstChild);let Z=z?T:b;try{let Re=Al(Z);for(;N=Re.nextNode();)Cl(N,Z),Nl(N),gn(N.content)&&Fr(N.content)}catch(Re){throw z&&(Hr(T),Dn(e.removed,Ne=>{Ne.element&&qn(Ne.element)})),Re}if(z)return Dn(e.removed,Re=>{Re.element&&qn(Re.element)}),xt&&os(T),T;if(pn){if(xt&&os(b),Mr)for(L=Wu.call(b.ownerDocument);b.firstChild;)L.appendChild(b.firstChild);else L=b;return(ae.shadowroot||ae.shadowrootmode)&&(L=Ku.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(Uv,b.ownerDocument.doctype.name)&&(de="<!DOCTYPE "+b.ownerDocument.doctype.name+`>
|
|
13
|
-
|
|
14
|
-
|
|
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(`
|
|
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(`
|
|
13
|
+
`)).split(`
|
|
14
|
+
`).map(o=>`> ${o}`.trimEnd()).join(`
|
|
15
|
+
`)}
|
|
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=`
|
|
19
|
+
.ag-ui-quote-offer {
|
|
20
|
+
position: fixed;
|
|
21
|
+
z-index: 2147483000;
|
|
22
|
+
transform: translate(-50%, -100%);
|
|
23
|
+
margin: 0;
|
|
24
|
+
padding: 0.25em 0.7em;
|
|
25
|
+
border: 1px solid rgb(0 0 0 / 0.15);
|
|
26
|
+
border-radius: 999px;
|
|
27
|
+
background: Canvas;
|
|
28
|
+
color: CanvasText;
|
|
29
|
+
font: inherit;
|
|
30
|
+
font-size: 0.8rem;
|
|
31
|
+
line-height: 1.6;
|
|
32
|
+
white-space: nowrap;
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
box-shadow: 0 2px 10px rgb(0 0 0 / 0.18);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.ag-ui-quote-offer[data-below="true"] {
|
|
38
|
+
transform: translate(-50%, 0);
|
|
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={"&":"&","<":"<",">":">",'"':""","'":"'"},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(`
|
|
15
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(`
|
|
16
|
-
`)}function
|
|
17
|
-
`).map(
|
|
18
|
-
`)}var
|
|
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(`
|
|
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],`
|
|
19
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],`
|
|
20
49
|
`)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let n=Nt(e[0],`
|
|
21
50
|
`).split(`
|
|
22
|
-
`),r="",
|
|
23
|
-
`),
|
|
51
|
+
`),r="",o="",i=[];for(;n.length>0;){let s=!1,a=[],l;for(l=0;l<n.length;l++)if(this.rules.other.blockquoteStart.test(n[l]))a.push(n[l]),s=!0;else if(!s)a.push(n[l]);else break;n=n.slice(l);let c=a.join(`
|
|
52
|
+
`),u=c.replace(this.rules.other.blockquoteSetextReplace,`
|
|
24
53
|
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");r=r?`${r}
|
|
25
|
-
${c}`:c,
|
|
26
|
-
${
|
|
54
|
+
${c}`:c,o=o?`${o}
|
|
55
|
+
${u}`:u;let m=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(u,i,!0),this.lexer.state.top=m,n.length===0)break;let y=i.at(-1);if(y?.type==="code")break;if(y?.type==="blockquote"){let f=y,h=n.join(`
|
|
27
56
|
`),g=f.raw+`
|
|
28
|
-
`+h.replace(this.rules.other.blockquoteSetextReplace2,""),x=this.blockquote(g);
|
|
29
|
-
${h}`,
|
|
57
|
+
`+h.replace(this.rules.other.blockquoteSetextReplace2,""),x=this.blockquote(g);i[i.length-1]=x,r=`${r}
|
|
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+`
|
|
30
59
|
`+n.join(`
|
|
31
|
-
`),g=this.list(h);
|
|
32
|
-
`);continue}}return{type:"blockquote",raw:r,tokens:
|
|
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(`
|
|
33
62
|
`,1)[0],e[1].length),y=t.split(`
|
|
34
|
-
`,1)[0],f=!m.trim(),h=0;if(this.options.pedantic?(h=2,
|
|
35
|
-
`,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),
|
|
36
|
-
`,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)||
|
|
37
|
-
`+K.slice(h);else{if(f||m.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||S.test(m)||
|
|
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
|
+
`,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+=`
|
|
38
67
|
`+y}f=!y.trim(),c+=U+`
|
|
39
|
-
`,t=t.substring(U.length+1),m=K.slice(h)}}
|
|
40
|
-
`),href:r,title:
|
|
41
|
-
`):[],
|
|
42
|
-
`),header:[],align:[],rows:[]};if(n.length===r.length){for(let s of r)this.rules.other.tableAlignRight.test(s)?
|
|
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(`
|
|
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],`
|
|
43
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)===`
|
|
44
|
-
`?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
|
|
45
|
-
`),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
|
|
46
|
-
`:n.push(
|
|
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,`
|
|
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
|
+
`: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(`
|
|
47
76
|
`)?"":`
|
|
48
|
-
`)+
|
|
49
|
-
`+
|
|
77
|
+
`)+i.raw,a.text+=`
|
|
78
|
+
`+i.text,this.inlineQueue.at(-1).src=a.text):n.push(i);continue}if(i=this.tokenizer.fences(e)){e=e.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.heading(e)){e=e.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.hr(e)){e=e.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.blockquote(e)){e=e.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.list(e)){e=e.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.html(e)){e=e.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.def(e)){e=e.substring(i.raw.length);let a=n.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=(a.raw.endsWith(`
|
|
50
79
|
`)?"":`
|
|
51
|
-
`)+
|
|
52
|
-
`+
|
|
80
|
+
`)+i.raw,a.text+=`
|
|
81
|
+
`+i.raw,this.inlineQueue.at(-1).src=a.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},n.push(i));continue}if(i=this.tokenizer.table(e)){e=e.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.lheading(e)){e=e.substring(i.raw.length),n.push(i);continue}let s=e;if(this.options.extensions?.startBlock){let a=1/0,l=e.slice(1),c;this.options.extensions.startBlock.forEach(u=>{c=u.call({lexer:this},l),typeof c=="number"&&c>=0&&(a=Math.min(a,c))}),a<1/0&&a>=0&&(s=e.substring(0,a+1))}if(this.state.top&&(i=this.tokenizer.paragraph(s))){let a=n.at(-1);r&&a?.type==="paragraph"?(a.raw+=(a.raw.endsWith(`
|
|
53
82
|
`)?"":`
|
|
54
|
-
`)+
|
|
55
|
-
`+
|
|
83
|
+
`)+i.raw,a.text+=`
|
|
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(`
|
|
56
85
|
`)?"":`
|
|
57
|
-
`)+
|
|
58
|
-
`+
|
|
59
|
-
`;return r?'<pre><code class="language-'+ut(r)+'">'+(n?
|
|
60
|
-
`:"<pre><code>"+(n?
|
|
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,"")+`
|
|
88
|
+
`;return r?'<pre><code class="language-'+ut(r)+'">'+(n?o:ut(o,!0))+`</code></pre>
|
|
89
|
+
`:"<pre><code>"+(n?o:ut(o,!0))+`</code></pre>
|
|
61
90
|
`}blockquote({tokens:t}){return`<blockquote>
|
|
62
91
|
${this.parser.parse(t)}</blockquote>
|
|
63
92
|
`}html({text:t}){return t}def(t){return""}heading({tokens:t,depth:e}){return`<h${e}>${this.parser.parseInline(t)}</h${e}>
|
|
64
93
|
`}hr(t){return`<hr>
|
|
65
|
-
`}list(t){let e=t.ordered,n=t.start,r="";for(let s=0;s<t.items.length;s++){let a=t.items[s];r+=this.listitem(a)}let
|
|
66
|
-
`+r+"</"+
|
|
94
|
+
`}list(t){let e=t.ordered,n=t.start,r="";for(let s=0;s<t.items.length;s++){let a=t.items[s];r+=this.listitem(a)}let o=e?"ol":"ul",i=e&&n!==1?' start="'+n+'"':"";return"<"+o+i+`>
|
|
95
|
+
`+r+"</"+o+`>
|
|
67
96
|
`}listitem(t){return`<li>${this.parser.parse(t.tokens)}</li>
|
|
68
97
|
`}checkbox({checked:t}){return"<input "+(t?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:t}){return`<p>${this.parser.parseInline(t)}</p>
|
|
69
|
-
`}table(t){let e="",n="";for(let
|
|
98
|
+
`}table(t){let e="",n="";for(let o=0;o<t.header.length;o++)n+=this.tablecell(t.header[o]);e+=this.tablerow({text:n});let r="";for(let o=0;o<t.rows.length;o++){let i=t.rows[o];n="";for(let s=0;s<i.length;s++)n+=this.tablecell(i[s]);r+=this.tablerow({text:n})}return r&&(r=`<tbody>${r}</tbody>`),`<table>
|
|
70
99
|
<thead>
|
|
71
100
|
`+e+`</thead>
|
|
72
101
|
`+r+`</table>
|
|
73
102
|
`}tablerow({text:t}){return`<tr>
|
|
74
103
|
${t}</tr>
|
|
75
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}>
|
|
76
|
-
`}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),
|
|
77
|
-
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
|
|
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=`
|
|
78
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
|
|
79
108
|
Every public --ag-ui-* token is read here into a private --_* alias, and
|
|
80
109
|
only the alias is used by the rules below.
|
|
@@ -643,6 +672,7 @@ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error
|
|
|
643
672
|
opacity: 0;
|
|
644
673
|
}
|
|
645
674
|
|
|
675
|
+
:host([collapsed]:is([placement="embedded"], [placement="page"])) .messages-wrap,
|
|
646
676
|
:host([collapsed]:is([placement="embedded"], [placement="page"])) .messages,
|
|
647
677
|
:host([collapsed]:is([placement="embedded"], [placement="page"])) .input-row,
|
|
648
678
|
:host([collapsed]:is([placement="embedded"], [placement="page"])) .skill-chips,
|
|
@@ -651,9 +681,113 @@ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error
|
|
|
651
681
|
display: none;
|
|
652
682
|
}
|
|
653
683
|
|
|
684
|
+
/* Jump-to-latest: shown only once the reader has scrolled away *and* missed
|
|
685
|
+
something. Anchored to the panel rather than the list so it does not scroll
|
|
686
|
+
with the content it is offering to scroll to. */
|
|
687
|
+
/* The transcript's own box, and the only one whose foot is the transcript's
|
|
688
|
+
foot. The panel's foot is below the composer, the chips and the footer. */
|
|
689
|
+
.messages-wrap {
|
|
690
|
+
position: relative;
|
|
691
|
+
flex: 1;
|
|
692
|
+
min-height: 0;
|
|
693
|
+
display: flex;
|
|
694
|
+
flex-direction: column;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
.jump-latest {
|
|
698
|
+
position: absolute;
|
|
699
|
+
left: 50%;
|
|
700
|
+
transform: translateX(-50%);
|
|
701
|
+
bottom: var(--_pad);
|
|
702
|
+
z-index: 2;
|
|
703
|
+
display: none;
|
|
704
|
+
align-items: center;
|
|
705
|
+
gap: 0.35em;
|
|
706
|
+
padding: 0.4em 0.9em;
|
|
707
|
+
border: 1px solid var(--_border);
|
|
708
|
+
border-radius: 999px;
|
|
709
|
+
/* A raised surface, not the panel's own background. Reusing --_bg made the
|
|
710
|
+
pill the same colour as everything behind it, leaving a 1px border and a
|
|
711
|
+
shadow to carry the whole affordance -- and a dark-on-dark shadow carries
|
|
712
|
+
nothing. --_hover is the token that already means "lifted off the panel",
|
|
713
|
+
and it separates in both themes without competing with the accent the send
|
|
714
|
+
button owns. */
|
|
715
|
+
background: var(--_hover);
|
|
716
|
+
color: var(--_text);
|
|
717
|
+
font: inherit;
|
|
718
|
+
font-size: 0.85em;
|
|
719
|
+
cursor: pointer;
|
|
720
|
+
box-shadow: 0 2px 10px rgb(0 0 0 / 0.18);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
.jump-latest[data-missed="true"] {
|
|
724
|
+
display: flex;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
.jump-latest:hover {
|
|
728
|
+
border-color: var(--_accent);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/* The offer to quote a selection. Positioned in script against the transcript
|
|
732
|
+
box, which is the only ancestor whose top and foot are the transcript's --
|
|
733
|
+
the same reason .jump-latest lives here. The translate is the half the
|
|
734
|
+
script does not do: script sets the point the offer hangs from, CSS decides
|
|
735
|
+
which corner of the offer that point is. */
|
|
736
|
+
.quote-selection {
|
|
737
|
+
position: absolute;
|
|
738
|
+
z-index: 2;
|
|
739
|
+
transform: translate(-50%, -100%);
|
|
740
|
+
padding: 0.25em 0.7em;
|
|
741
|
+
border: 1px solid var(--_border);
|
|
742
|
+
border-radius: 999px;
|
|
743
|
+
background: var(--_hover);
|
|
744
|
+
color: var(--_text);
|
|
745
|
+
font: inherit;
|
|
746
|
+
font-size: 0.8em;
|
|
747
|
+
line-height: 1.6;
|
|
748
|
+
white-space: nowrap;
|
|
749
|
+
cursor: pointer;
|
|
750
|
+
box-shadow: 0 2px 10px rgb(0 0 0 / 0.18);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/* Flipped under the selection when there was no room above it. Only the
|
|
754
|
+
vertical half of the translate changes: it still hangs from its own centre
|
|
755
|
+
horizontally. */
|
|
756
|
+
.quote-selection[data-below="true"] {
|
|
757
|
+
transform: translate(-50%, 0);
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
.quote-selection:hover {
|
|
761
|
+
border-color: var(--_accent);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/* Screen-reader-only status region. Off-screen rather than display:none or
|
|
765
|
+
visibility:hidden, both of which take the element out of the accessibility
|
|
766
|
+
tree entirely -- a hidden live region announces nothing at all, which is the
|
|
767
|
+
classic way this pattern is written wrong.
|
|
768
|
+
|
|
769
|
+
The 1px box with clip-path, rather than width/height 0, is the shape that
|
|
770
|
+
survives: a zero-sized element is dropped from the tree by some engines. */
|
|
771
|
+
.sr-only {
|
|
772
|
+
position: absolute;
|
|
773
|
+
width: 1px;
|
|
774
|
+
height: 1px;
|
|
775
|
+
margin: -1px;
|
|
776
|
+
padding: 0;
|
|
777
|
+
border: 0;
|
|
778
|
+
overflow: hidden;
|
|
779
|
+
white-space: nowrap;
|
|
780
|
+
clip-path: inset(50%);
|
|
781
|
+
}
|
|
782
|
+
|
|
654
783
|
.messages {
|
|
655
784
|
flex: 1;
|
|
656
785
|
overflow-y: auto;
|
|
786
|
+
/* The browser's own scroll anchoring competes with the scroller for the same
|
|
787
|
+
job and wins unpredictably -- it can hold the view still exactly when we
|
|
788
|
+
want to follow. Turned off so following is decided in one place. Safari
|
|
789
|
+
does not implement it, which is itself a reason not to depend on it. */
|
|
790
|
+
overflow-anchor: none;
|
|
657
791
|
padding: var(--_pad);
|
|
658
792
|
display: flex;
|
|
659
793
|
flex-direction: column;
|
|
@@ -1819,6 +1953,7 @@ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error
|
|
|
1819
1953
|
|
|
1820
1954
|
.confirm-actions {
|
|
1821
1955
|
display: flex;
|
|
1956
|
+
flex-wrap: wrap;
|
|
1822
1957
|
gap: 8px;
|
|
1823
1958
|
justify-content: flex-end;
|
|
1824
1959
|
}
|
|
@@ -1845,6 +1980,99 @@ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error
|
|
|
1845
1980
|
color: #ffffff;
|
|
1846
1981
|
}
|
|
1847
1982
|
|
|
1983
|
+
/* The session waiver. Deliberately the quietest of the three: it is the widest
|
|
1984
|
+
decision on the card, so it should be reachable without being the one the eye
|
|
1985
|
+
lands on when the user means to say yes once. */
|
|
1986
|
+
.confirm-btn--always {
|
|
1987
|
+
font-weight: 500;
|
|
1988
|
+
opacity: 0.85;
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
.confirm-btn--always:hover,
|
|
1992
|
+
.confirm-btn--always:focus-visible {
|
|
1993
|
+
opacity: 1;
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
/* Editable arguments on an approval card. A plain field rather than a code
|
|
1997
|
+
editor: it holds the JSON a card already displays, and the only interaction
|
|
1998
|
+
is correcting a value before letting the call run. */
|
|
1999
|
+
.approval-edit {
|
|
2000
|
+
display: flex;
|
|
2001
|
+
flex-direction: column;
|
|
2002
|
+
gap: 6px;
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
.approval-args {
|
|
2006
|
+
box-sizing: border-box;
|
|
2007
|
+
width: 100%;
|
|
2008
|
+
resize: vertical;
|
|
2009
|
+
border: 1px solid var(--_border);
|
|
2010
|
+
border-radius: 8px;
|
|
2011
|
+
padding: 8px;
|
|
2012
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
2013
|
+
font-size: 0.85em;
|
|
2014
|
+
background: var(--_bg);
|
|
2015
|
+
color: var(--_fg);
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
.approval-args:focus-visible {
|
|
2019
|
+
border-color: var(--_accent);
|
|
2020
|
+
outline: none;
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
.approval-error {
|
|
2024
|
+
font-size: 0.85em;
|
|
2025
|
+
color: var(--_danger);
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2028
|
+
/* Message action row. Sits under a finished assistant bubble.
|
|
2029
|
+
|
|
2030
|
+
The wrap is insurance rather than a fix: these buttons are glyph-only, so at
|
|
2031
|
+
every width tested they fit on one line and removing the wrap changes
|
|
2032
|
+
nothing. It is here because the confirmation row one release earlier did
|
|
2033
|
+
overflow when it gained a third button, off the left edge and outside its own
|
|
2034
|
+
card, and the difference between the two rows is only that this one's labels
|
|
2035
|
+
are icons today. */
|
|
2036
|
+
.message-actions {
|
|
2037
|
+
display: flex;
|
|
2038
|
+
flex-wrap: wrap;
|
|
2039
|
+
gap: 4px;
|
|
2040
|
+
/* Negative, and that is the point. The answer group is a flex column with its
|
|
2041
|
+
own gap, so a positive margin here pushes the row further from the message
|
|
2042
|
+
it acts on than the next card is below it -- the buttons then read as
|
|
2043
|
+
belonging to whatever follows. Pulling back inside the gap is what makes
|
|
2044
|
+
them the message's own. */
|
|
2045
|
+
margin-top: -6px;
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
.message-action {
|
|
2049
|
+
border: none;
|
|
2050
|
+
border-radius: 6px;
|
|
2051
|
+
padding: 2px 6px;
|
|
2052
|
+
font: inherit;
|
|
2053
|
+
line-height: 1.2;
|
|
2054
|
+
cursor: pointer;
|
|
2055
|
+
background: transparent;
|
|
2056
|
+
color: var(--_muted);
|
|
2057
|
+
opacity: 0.75;
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
.message-action:hover,
|
|
2061
|
+
.message-action:focus-visible {
|
|
2062
|
+
opacity: 1;
|
|
2063
|
+
background: var(--_border);
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
.message-action[aria-pressed="true"] {
|
|
2067
|
+
opacity: 1;
|
|
2068
|
+
color: var(--_accent);
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
.message-action--confirmed {
|
|
2072
|
+
opacity: 1;
|
|
2073
|
+
color: var(--_accent);
|
|
2074
|
+
}
|
|
2075
|
+
|
|
1848
2076
|
/* Approval card \u2014 the server-side-tool gate (approve/deny an interrupt). */
|
|
1849
2077
|
.approval {
|
|
1850
2078
|
align-self: stretch;
|
|
@@ -1989,6 +2217,34 @@ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error
|
|
|
1989
2217
|
border-color: var(--_accent);
|
|
1990
2218
|
}
|
|
1991
2219
|
|
|
2220
|
+
/* Follow-up suggestion chips. Deliberately the skill chips' shape rather than a
|
|
2221
|
+
second chip vocabulary -- both are "a question you could ask", and the only
|
|
2222
|
+
difference is who chose it. Inside the transcript, so they scroll with the
|
|
2223
|
+
answer they follow instead of hovering above the composer. */
|
|
2224
|
+
.suggestions {
|
|
2225
|
+
display: flex;
|
|
2226
|
+
flex-wrap: wrap;
|
|
2227
|
+
gap: 6px;
|
|
2228
|
+
align-self: stretch;
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
.suggestion-chip {
|
|
2232
|
+
border: 1px solid var(--_border);
|
|
2233
|
+
border-radius: 999px;
|
|
2234
|
+
padding: 4px 12px;
|
|
2235
|
+
font: inherit;
|
|
2236
|
+
font-size: 0.9em;
|
|
2237
|
+
text-align: left;
|
|
2238
|
+
cursor: pointer;
|
|
2239
|
+
background: var(--_assistant-bg);
|
|
2240
|
+
color: var(--_fg);
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2243
|
+
.suggestion-chip:hover,
|
|
2244
|
+
.suggestion-chip:focus-visible {
|
|
2245
|
+
border-color: var(--_accent);
|
|
2246
|
+
}
|
|
2247
|
+
|
|
1992
2248
|
.skill-palette {
|
|
1993
2249
|
margin: 8px 12px 0;
|
|
1994
2250
|
display: flex;
|
|
@@ -2401,7 +2657,9 @@ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error
|
|
|
2401
2657
|
border-right: none;
|
|
2402
2658
|
box-shadow: none;
|
|
2403
2659
|
}
|
|
2404
|
-
`;var Do=class{element;#t;#r;#e;#o;#n=!1;constructor(e=le){this.#o=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.#o.thoughts,this.#i(!0))}#i(e){this.#n=e,this.#r.hidden=e,this.#e.setAttribute("aria-expanded",String(!e))}};var Uo=class{element;#t;#r;#e;#o;#n;#i;#s=[];#c="";#u=null;constructor(e,n=le){this.#t=e,this.#i=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",o=>this.#h(o));let i=document.createElement("div");i.className="drawer-header",i.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.#o=document.createElement("button"),this.#o.type="button",this.#o.className="drawer-new",this.#o.setAttribute("part","drawer-new"),this.#o.textContent=n.newChat,this.#o.addEventListener("click",()=>{this.close(),this.#t.onNew()}),i.append(this.#e,this.#o),this.#n=document.createElement("div"),this.#n.className="drawer-list",this.#n.setAttribute("part","drawer-list"),this.#r.append(i,this.#n),this.element.append(r,this.#r)}setStrings(e){this.#i=e,this.#r.setAttribute("aria-label",e.chatHistory),this.#e.textContent=e.chats,this.#o.textContent=e.newChat,this.#f()}isOpen(){return!this.element.hidden}open(){this.isOpen()||(this.#u=this.#d(),this.element.hidden=!1,this.#o.focus())}close(){this.isOpen()&&(this.element.hidden=!0,this.#u?.focus(),this.#u=null)}toggle(){this.isOpen()?this.close():this.open()}#d(){return this.element.getRootNode().activeElement}#h(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],i=n[n.length-1],o=this.#d();e.shiftKey&&o===r?(e.preventDefault(),i?.focus()):!e.shiftKey&&o===i&&(e.preventDefault(),r?.focus())}setThreads(e,n){this.#s=e,this.#c=n,this.#f()}#f(){if(this.#n.replaceChildren(),this.#s.length===0){let e=document.createElement("div");e.className="drawer-empty",e.setAttribute("part","drawer-empty"),e.textContent=this.#i.noConversations,this.#n.appendChild(e);return}for(let e of this.#s)this.#n.appendChild(this.#p(e))}#p(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 i=document.createElement("span");i.className="drawer-row-title",i.setAttribute("part","drawer-row-title"),i.textContent=e.title;let o=document.createElement("span");o.className="drawer-row-time",o.setAttribute("part","drawer-row-time"),o.textContent=Ao(e.updatedAt,void 0,this.#i);let s=document.createElement("span");s.className="drawer-row-preview",s.setAttribute("part","drawer-row-preview"),s.textContent=e.preview,r.append(i,o,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.#i.rename,a.setAttribute("aria-label",this.#i.renameConversation),a.textContent="\u270E",a.addEventListener("click",()=>this.#a(n,e));let l=document.createElement("button");l.type="button",l.className="drawer-row-delete",l.setAttribute("part","drawer-row-delete"),l.title=this.#i.delete,l.setAttribute("aria-label",this.#i.deleteConversation),l.textContent="\u{1F5D1}",l.addEventListener("click",()=>this.#l(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}#a(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 i=!1,o=()=>{if(i)return;i=!0;let a=r.value.trim();a===""||a===n.title?this.#f():this.#t.onRename(n.threadId,a)},s=()=>{i||(i=!0,this.#f())};r.addEventListener("keydown",a=>{a.key==="Enter"?(a.preventDefault(),o()):a.key==="Escape"&&(a.preventDefault(),a.stopPropagation(),s())}),r.addEventListener("blur",()=>o()),e.replaceChildren(r),r.focus(),r.select()}#l(e,n){let r=document.createElement("div");r.className="drawer-confirm",r.setAttribute("part","drawer-confirm");let i=document.createElement("span");i.className="drawer-confirm-label",i.setAttribute("part","drawer-confirm-label"),i.textContent=this.#i.deletePrompt;let o=document.createElement("button");o.type="button",o.className="drawer-confirm-yes",o.setAttribute("part","drawer-confirm-yes"),o.textContent=this.#i.delete,o.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.#i.cancel,s.addEventListener("click",()=>this.#f()),r.append(i,o,s),e.replaceChildren(r)}};function Ya(t){return{[ee.PENDING]:t.toolRunning,[ee.DEFERRED]:t.toolDeferred,[ee.DONE]:t.toolDone,[ee.ERROR]:t.toolError,[ee.DECLINED]:t.toolDeclined}}function jb(t){return{[ee.DONE]:t.resultLabel,[ee.ERROR]:t.errorLabel,[ee.DECLINED]:t.declinedLabel}}function qb(t){try{return JSON.stringify(JSON.parse(t),null,2)}catch{return t}}var Tr=class{element;approvalSlot;#t;#r;#e;#o;#n;#i;#s;#c=!1;constructor(e,n,r,i=le){this.#s=i,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 o=document.createElement("div");o.className="tool-call-head",o.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=Ya(i)[ee.PENDING],this.#r=document.createElement("span"),this.#r.className="tool-call-decision",this.#r.setAttribute("part","tool-card-decision"),this.#r.hidden=!0,o.append(s,a,this.#t,this.#r);let l=this.#u("args",i.argumentsLabel);l.body.textContent=JSON.stringify(n,null,2),l.root.hidden=Object.keys(n).length===0;let c=this.#u("result",i.resultLabel);this.#o=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=i.details,this.#e.addEventListener("click",()=>this.#h(!this.#d()));let p=document.createElement("div");p.className="tool-call-body",p.setAttribute("part","tool-card-body"),p.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(o,this.#e,p,this.approvalSlot)}mark(e){this.#c||(this.element.setAttribute("data-status",e),this.#t.textContent=Ya(this.#s)[e])}recordDecision(e){this.element.setAttribute("data-decision",e),this.#r.textContent=e==="approved"?this.#s.decisionApproved:this.#s.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=Ya(this.#s)[e],this.#n.textContent=jb(this.#s)[e],this.#i.textContent=qb(n),this.#o.hidden=!1)}#u(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 i=document.createElement("span");i.className="tool-call-section-label",i.setAttribute("part",`tool-card-section-label tool-card-${e}-label`),i.textContent=n;let o=document.createElement("pre");return o.className=`tool-call-${e}`,o.setAttribute("part",`tool-card-${e}`),r.append(i,o),{root:r,label:i,body:o}}#d(){return this.element.getAttribute("data-expanded")==="true"}#h(e){this.element.setAttribute("data-expanded",String(e)),this.#e.setAttribute("aria-expanded",String(e))}};var Lu=12e4,Ho=class{element;#t;#r;#e;#o="idle";#n=null;#i=null;#s=[];#c=null;#u=!1;#d=!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=Pl,this.element.append(n),this.#C("idle"),this.element.addEventListener("click",()=>{this.toggle()})}async toggle(){if(this.#o==="recording"){this.#f();return}this.#o!=="transcribing"&&await this.#h()}async#h(){let e;try{e=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{this.#g(this.#e.transcriptionFailed);return}this.#i=e,this.#s=[],this.#u=!1;let n=new MediaRecorder(e);n.addEventListener("dataavailable",r=>{this.#s.push(r.data)}),n.addEventListener("stop",()=>{this.#a(n.mimeType)}),this.#n=n,n.start(),this.#c=setTimeout(()=>{this.#u=!0,this.#f()},Lu),this.#C("recording")}#f(){this.#p(),this.#n?.stop()}#p(){this.#c!==null&&(clearTimeout(this.#c),this.#c=null)}dispose(){this.#d=!0,this.#p(),this.#n!==null&&this.#n.state!=="inactive"&&this.#n.stop(),this.#n=null,this.#l()}async#a(e){if(this.#d)return;this.#l(),this.#C("transcribing");let n=new Blob(this.#s,{type:e||"audio/webm"});try{let r=await this.#t(n);this.#C("idle"),this.#u&&(this.element.title=this.#e.recordingLimit.replace("{n}",String(Lu/6e4))),r!==""&&this.#r(r)}catch(r){this.#g(r instanceof Error?r.message:this.#e.transcriptionFailed)}finally{this.#n=null}}#l(){for(let e of this.#i?.getTracks()??[])e.stop();this.#i=null}#g(e){this.#l(),this.#n=null,this.#C("idle"),this.element.title=e}#C(e){this.#o=e,this.element.dataset.state=e;let n=this.#T(e);this.element.title=n,this.element.setAttribute("aria-label",n),this.element.setAttribute("aria-pressed",String(e==="recording")),this.element.disabled=e==="transcribing"}#T(e){return e==="recording"?this.#e.stopRecording:e==="transcribing"?this.#e.transcribing:this.#e.recordVoice}};var zo=class extends Error{constructor(e){super(e),this.name="ConnectionLostError"}},Fn=class{#t;#r;#e;#o;#n;#i;#s;#c=new Set;#u;#d=!1;constructor(e){this.#t=e.agent,this.#r=e.handlers,this.#e=e.getTools??(()=>[]),this.#o=e.getContext??(()=>[]),this.#n=e.executeTool??null,this.#i=e.resolveInterrupts??null,this.#s=e.onPersist??(()=>{}),this.#u=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:Ee(),role:"user",content:e};n.length>0&&(r.attachments=n),this.#t.addMessage(r),this.#s(this.#t.messages),await this.#h()}async resume(){await this.#h()}addToolResult(e,n){this.#t.addMessage({id:Ee(),role:"tool",content:n,toolCallId:e}),this.#s(this.#t.messages)}cancel(){this.#d=!0,this.#t.abortRun()}async#h(){this.#d=!1;try{await this.#p(),this.#d&&this.#f()}catch(e){this.#d||Wb(e)?this.#f():this.#r.onError(e instanceof Error?e.message:String(e))}finally{this.#r.onSettled()}}#f(){this.#s(this.#t.messages),this.#r.onCancelled()}async#p(){let e;for(let n=0;n<gs;n+=1){if(this.#d)return;let r=[],i={terminal:!1,errored:!1,interrupts:[]},o={tools:this.#e(),context:this.#o()};if(e!==void 0&&(o.resume=e),await this.#t.runAgent(o,this.#a(r,i)),e=void 0,this.#s(this.#t.messages),this.#d)return;if(!i.terminal)throw new zo(this.#u);if(i.errored)return;if(i.interrupts.length>0){if(this.#i===null)return;let a=await this.#i(i.interrupts);if(this.#d)return;e=Nd(i.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:Ee(),role:"tool",content:l.content,toolCallId:a.id}),this.#s(this.#t.messages),s=!0}}if(!s)return}}#a(e,n){let r=this.#r,i=this.#c,o=()=>this.#d,s=new Set;return{onRunInitialized(){r.onRunStart()},onTextMessageStartEvent({event:a}){i.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}){i.add(a.messageId),r.onTextEnd(l)},onToolCallEndEvent({event:a,toolCallName:l,toolCallArgs:c}){let p={id:a.toolCallId,name:l,args:c};e.push(p),r.onToolCall(p)},onToolCallResultEvent({event:a}){r.onToolResult(a.toolCallId,a.content)},onActivitySnapshotEvent({event:a,messages:l}){if(l.some(p=>p.id===a.messageId&&p.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)},onMessagesChanged({messages:a}){if(s.size!==0){for(let l of s){let c=a.find(p=>p.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,!o()&&r.onError(a.message)},onRunFinalized(){n.terminal=!0,r.onRunEnd()}}}};function Wb(t){return t instanceof Error?t.name==="AbortError"||t instanceof TypeError&&/abort/i.test(t.message):!1}function Za(t){let e=t.attachments;return Array.isArray(e)?e.filter(Xb):[]}function Xb(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 Pu="ag-ui-chat",$n="thread",Ja="threads",Sr="messages:",Fo="checkpoint:",Ar="minted:",Kb=60,Yb=100,Zb="New conversation",Du=!1;function et(t,e){try{sessionStorage.setItem(t,e)}catch{if(Du)return;Du=!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 Go(t){return t===""?Pu:`${Pu}@${t}`}var Be=class t{#t;constructor(e=""){this.#t=Go(e),e!==""&&t.adopt("",e)}static adopt(e,n){let r=`${Go(e)}:`,i=`${Go(n)}:`;for(let[o,s]of Uu(r)){let a=sessionStorage.getItem(o),l=i+s;a!==null&&sessionStorage.getItem(l)===null&&et(l,a),sessionStorage.removeItem(o)}}static purge(e){for(let[n]of Uu(`${Go(e)}:`))sessionStorage.removeItem(n)}threadId(){return sessionStorage.getItem(this.#n($n))??this.newThread()}newThread(){let e=Ee();return et(this.#n($n),e),et(this.#n(Ar+e),"1"),e}isUnsent(e){return sessionStorage.getItem(this.#n(Ar+e))!==null&&sessionStorage.getItem(this.#n(Sr+e))===null}loadMessages(e){return Promise.resolve(this.#i(this.#n(Sr+e)))}saveMessages(e,n){et(this.#n(Sr+e),JSON.stringify(n)),sessionStorage.removeItem(this.#n(Ar+e)),this.#r(e,n)}loadCheckpoint(e){return this.#i(this.#n(Fo+e))}saveCheckpoint(e,n){let r=this.#n(Fo+e);if(n===null){sessionStorage.removeItem(r);return}et(r,JSON.stringify(n))}clear(e){sessionStorage.removeItem(this.#n(Sr+e)),sessionStorage.removeItem(this.#n(Fo+e)),sessionStorage.removeItem(this.#n(Ar+e)),this.#o(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:i,preview:o})=>({threadId:n,title:r,updatedAt:i,preview:o}));return Promise.resolve(e)}setActiveThread(e){et(this.#n($n),e)}renameThread(e,n){let r=this.#e(),i=r.find(o=>o.threadId===e);i!==void 0&&(i.title=n,i.titleCustom=!0,this.#o(r))}#r(e,n){let r=this.#e(),i=r.find(a=>a.threadId===e),o=Qb(n),s=Date.now();i===void 0?r.push({threadId:e,title:Hu(n),titleCustom:!1,preview:o,updatedAt:s}):(i.preview=o,i.updatedAt=s,i.titleCustom||(i.title=Hu(n))),this.#o(r)}#e(){return this.#i(this.#n(Ja))??[]}#o(e){let n=this.#n(Ja);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 Uu(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 i=r.slice(t.length);Jb(i)&&e.push([r,i])}return e}function Jb(t){return t===$n||t===Ja||t.startsWith(Sr)||t.startsWith(Fo)||t.startsWith(Ar)}function Hu(t){for(let e of t)if(e.role==="user"){let n=zu(e.content);if(n!=="")return Gu(n,Kb)}return Zb}function Qb(t){for(let e of[...t].reverse()){let n=zu(e.content);if(n!=="")return Gu(n,Yb)}return""}function zu(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():""}function Gu(t,e){return t.length<=e?t:`${t.slice(0,e-1).trimEnd()}\u2026`}function je(t,e){return e===void 0?t:{...t,credentials:e}}function $o(t){if(t.newThread!==void 0)return t.newThread();let e=Ee();return t.setActiveThread(e),e}function Vo(t,e,n,r){if(e.length===0)return;let i=new URL(String(t),location.href).origin;i===location.origin||n.includes(i)||r.has(i)||(r.add(i),console.warn(`<ag-ui-chat>: sending host credentials (${e.join(", ")}) to ${i}, 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 Qa(t){let e=t.headers??{},n=new Set;return new Od({url:t.endpoint,headers:e,initialState:{...t.initialState??{}},fetch:(r,i)=>{let o=t.getHeaders?.(),s=[...new Set([...Object.keys(e),...Object.keys(o??{})])].sort();if(Vo(r,s,t.trustedOrigins??[],n),o===void 0)return fetch(r,je(i,t.credentials));let a=new Headers(i?.headers);for(let[l,c]of Object.entries(o))a.set(l,c);return fetch(r,je({...i,headers:a},t.credentials))},...t.threadId!==void 0?{threadId:t.threadId}:{},...t.initialMessages!==void 0?{initialMessages:[...t.initialMessages]}:{}})}var kr=class{#t;#r;#e;#o;#n;#i=new Set;#s=new Map;constructor(e,n=()=>({}),r=new Be,i=()=>{},o=!0){this.#t=e.endsWith("/")?e:`${e}/`,this.#r=n,this.#e=r,this.#o=i,this.#n=o}threadId(){return this.#e.threadId()}setActiveThread(e){this.#e.setActiveThread(e)}newThread(){return $o(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.#s.set(e,n),this.#f(e,"PATCH",{title:n})}clear(e){this.#e.clear(e),this.#i.add(e),this.#f(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.#d(n))}async loadMessages(e){if(this.#e.isUnsent?.(e)===!0)return null;let n=await this.#h(`${this.#t}${encodeURIComponent(e)}/`);if(n===null||!n.ok)return this.#e.loadMessages(e);let r=await this.#u(n);return r===null?this.#e.loadMessages(e):r.messages??null}async#c(){let e=await this.#h(this.#t);if(e===null||!e.ok)return null;let n=await this.#u(e);return n===null?null:n.threads??[]}async#u(e){try{return await e.json()}catch{return null}}#d(e){return{threadId:e.thread_id,title:this.#s.get(e.thread_id)??e.title,updatedAt:e.updated_at===null?Number.NaN:Date.parse(e.updated_at),preview:e.preview}}async#h(e){try{return await fetch(e,je({headers:this.#r()},this.#o()))}catch{return null}}async#f(e,n,r){let i=this.#r();try{await fetch(`${this.#t}${encodeURIComponent(e)}/`,je({method:n,headers:r===void 0?i:{...i,"content-type":"application/json"},body:r===void 0?null:JSON.stringify(r)},this.#o()))}catch{}}};var Cr=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,je({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.#o("resume",e)}forkUrl(e){return this.#o("fork",e)}#o(e,n){return`${this.#t.slice(0,-5)}${e}/${encodeURIComponent(n)}/`}};async function el(t,e){let n=new FormData;n.append("audio",t,"recording.webm");let r=await fetch(e.url,je({method:"POST",headers:{...e.headers??{}},body:n},e.credentials));if(!r.ok)throw new Error(await ey(r));let i=await r.json();if(typeof i=="object"&&i!==null&&typeof i.text=="string")return i.text;throw new Error("transcription returned an unreadable response")}async function ey(t){try{let e=await t.json();if(typeof e.error=="string")return e.error}catch{}return`transcription failed (${t.status})`}function tl(t,e){return new Promise((n,r)=>{let i=new FormData;i.append("file",t);let o=new XMLHttpRequest;o.open("POST",e.url),o.withCredentials=e.credentials==="include";for(let[l,c]of Object.entries(e.headers??{}))o.setRequestHeader(l,c);let s=e.onProgress;s!==void 0&&o.upload.addEventListener("progress",l=>{l.lengthComputable&&s(l.total===0?0:l.loaded/l.total)}),o.addEventListener("load",()=>{if(o.status>=200&&o.status<300)try{n(ty(JSON.parse(o.responseText)))}catch{r(new Error("upload returned an unreadable response"))}else r(new Error(ny(o)))}),o.addEventListener("error",()=>r(new Error("upload failed"))),o.addEventListener("abort",()=>r(new Error("upload cancelled")));let a=e.signal;a!==void 0&&a.addEventListener("abort",()=>o.abort()),o.send(i)})}function ty(t){if(typeof t!="object"||t===null)throw new Error("not an object");let e=t,n=e.id,r=e.name,i=e.mime,o=e.size,s=e.url;if(typeof n!="string"||typeof r!="string"||typeof i!="string"||typeof o!="number")throw new Error("missing fields");return typeof s=="string"?{id:n,name:r,mime:i,size:o,url:s}:{id:n,name:r,mime:i,size:o}}function ny(t){try{let e=JSON.parse(t.responseText);if(typeof e.error=="string")return e.error}catch{}return`upload failed (${t.status})`}var ry=["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"],il=["omit","same-origin","include"];function nl(t){return il.includes(t)}var Fu="ag-ui-chat:collapsed",$u="ag-ui-chat:size",Vu="ag-ui-chat:theme",rl=new Set,Ir=class extends HTMLElement{agentFactory=Qa;headers={};getHeaders=null;trustedOrigins=[];allowImages=!1;autoConfirm=!1;askUser=!1;askUserRenderer=null;approvalRenderer=null;confirmPredicate=null;getTools=()=>[...this.#Pe().map(e=>({name:e.name,description:e.description,parameters:e.parameters})),...this.#n.tools()];getContext=()=>[...ya(this.getPageMap,this.autoInjectPageMap)];routeMap=[];navigate=null;getPageMap=null;autoInjectPageMap=!0;conversationStore=new Be;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;#o=new Set;#n=new ur;#i=new Map;#s=!1;#c=new Map;#u=new Map;#d=new Set;#h=[];#f;#p;#a;#l;#g;#C;#T;#H;#b;#ue=null;#S;#x;#w;#Z;#I;#_;#R;#J=0;#M;#y=null;#Q;#pe=null;#z=!1;#L=null;#G={};#B=!1;#he=null;#A=null;#ee=null;#fe=0;#te="";#P=null;#ne=null;#N=null;#D=null;#m="";#F="";#re=null;#me="";#Ne="";#j=null;#ge=0;#ve=[];#Oe=[];#Me=[];#Le=[];constructor(){super(),this.#f=this.attachShadow({mode:"open"}),this.#p=document.createElement("div"),this.#a=document.createElement("div"),this.#l=document.createElement("textarea"),this.#g=document.createElement("button"),this.#C=document.createElement("span"),this.#S=document.createElement("div"),this.#x=document.createElement("button"),this.#w=document.createElement("input"),this.#Z=document.createElement("div"),this.#Q=document.createElement("span"),this.#I=document.createElement("button"),this.#_=document.createElement("button"),this.#R=document.createElement("span"),this.#M=document.createElement("div"),this.#T=new Po(e=>this.#At(e)),this.#H=new Uo({onSelect:e=>{this.#Ot(e)},onNew:()=>{this.newChat(),this.#K()},onRename:(e,n)=>{this.conversationStore.renameThread(e,n),this.#K()},onDelete:e=>{this.#Mt(e)}}),this.#b=new gr((e,n)=>{this.#at(e,n)})}#be(){let e=this.getAttribute("data-runs-url");return e===null||e===""?null:(this.#ue===null&&(this.#ue=new Cr(e,()=>this.#W(e),()=>this.#ie())),this.#ue)}async#at(e,n){let r=this.#be();if(r===null)return;let i=this.#l.value.trim();if(i==="")return;this.#l.value="",this.#Y();let o=n==="resume"?r.resumeUrl(e):r.forkUrl(e),s=this.agentFactory({endpoint:o,headers:this.#q(),getHeaders:()=>this.#q(),trustedOrigins:this.trustedOrigins,...this.#oe(),threadId:this.#m,initialMessages:[]});await new Fn({agent:s,handlers:this.#tt(),getTools:()=>this.#De(),getContext:()=>this.#We(),executeTool:l=>this.#Qe(l),resolveInterrupts:l=>this.#et(l),connectionLostMessage:this.#e.connectionLost}).send(i)}async#lt(){let e=this.#be();this.#b.setRuns(e===null?[]:await e.continuable())}static get observedAttributes(){return["title-text","placement","credentials","user-key",...ry]}attributeChangedCallback(e,n,r){if(e==="credentials"){r!==null&&!nl(r)&&console.error(`<ag-ui-chat>: credentials="${r}" is not a fetch credentials mode (${il.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.#Ct(),requestAnimationFrame(()=>this.#_e());return}if(e==="title-text"){this.#C.textContent=r??this.#e.title;return}if(e==="user-key"){this.#z&&(n??"")!==(r??"")&&this.#Nt(n??"",r??"");return}n===r||!this.#z||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.#L?.state??this.#G}set sharedState(e){this.#G={...e},this.#L?.setState(this.#G)}registerPageState(e){for(let n of xo(e))this.#n.register(n)}registerStateHook(e){this.registerPageState(e)}#ct(){return this.routeMap.length===0?[]:wa(()=>this.routeMap,()=>this.navigate)}#dt(){let e=this.getPageMap;return e===null?[]:[{name:ms,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()}]}#ut(){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 ba(n,r=>this.resolvePageTarget(r))}#Pe(){return[...this.#ct(),...this.#dt(),...this.#ut(),...this.#pt()]}#pt(){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.#ht(e)}]:[]}async#ht(e){let r={question:typeof e.question=="string"?e.question:""},i=e.options;Array.isArray(i)&&(r.options=i.filter(a=>typeof a=="string")),e.allow_custom===!0&&(r.allowCustom=!0),this.#A=new AbortController;let o=this.#A.signal;this.#k();let s=this.askUserRenderer!==null?await this.askUserRenderer(r,{signal:o}):await Ra(this.#E(),r,{signal:o,strings:this.#e});return this.#A=null,this.#v(),this.#a.scrollTop=this.#a.scrollHeight,s}#De(){let e=this.getTools();return this.#o=new Set(e.map(n=>n.name)),e}#ye(e){let n=this.#Pe().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&&nl(e)?e:null}set credentials(e){if(e===null){this.removeAttribute("credentials");return}if(!nl(e))throw new TypeError(`<ag-ui-chat>: credentials must be one of ${il.map(n=>`"${n}"`).join(", ")} (got ${JSON.stringify(e)}).`);this.setAttribute("credentials",e)}#q(){return{...this.headers,...this.getHeaders?.()}}#W(e){let n=this.#q();return Vo(e,Object.keys(n),this.trustedOrigins,this.#r),n}#ie(){return this.credentials??void 0}#oe(){let e=this.#ie();return e===void 0?{}:{credentials:e}}#Ue(e){return je({headers:this.#W(e)},this.#ie())}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.#F=this.#Rt(),this.#Ee(this.#Be()),requestAnimationFrame(()=>this.#_e()),this.#e=_a({...this.#mt(),...this.strings}),this.getAttribute("data-theme-toggle")!==null){let e=this.#Se(Vu);e!==null&&this.setAttribute("theme",e)}if(this.#zt(),this.#H.setStrings(this.#e),this.#b.setStrings(this.#e),this.#Se(Fu)==="1"&&this.setAttribute("collapsed",""),this.#Ye(),this.#Tt(),this.conversationStore instanceof Be){let e=this.#Te();this.#j=e===""?this.conversationStore:new Be(e),this.conversationStore=this.#j}this.#ze(),this.#gt(),this.#bt(),this.#m=this.conversationStore.threadId(),queueMicrotask(()=>this.#ft()),this.#ae(),this.#z=!0}#ft(){this.#z&&(this.#Ge(),this.#Fe())}async reload(){this.#O(),this.#X(),this.#U(!1),await Promise.all([this.#Ge(),this.#Fe(),this.#ae()])}disconnectedCallback(){this.#z=!1,this.#re!==null&&(rl.delete(this.#re),this.#re=null),this.#O(),this.#y?.dispose(),this.#pe?.dispose()}#He(e){let n=this.getAttribute(e);return n!==null&&n!=="false"}#mt(){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{}}#gt(){let e=this.getAttribute("data-attachments-url"),n=this.uploadHandler??this.#vt(e);if(n===null)return;let r=this.getAttribute("data-attachment-accept")??"",i=new _o({upload:n,maxBytes:this.#wt(),accept:r,strings:this.#e,onChange:()=>this.#Bt(i)});this.#y=i,this.#Z.appendChild(this.#y.element),this.#w.accept=r,this.#x.hidden=!1,this.#Et()}#vt(e){return e===null?null:(n,r,i)=>tl(n,{url:e,headers:this.#W(e),...this.#oe(),onProgress:r,signal:i})}#bt(){let e=this.getAttribute("data-transcribe-url"),n=this.transcribeHandler??this.#yt(e);n!==null&&(this.#pe=new Ho({transcribe:n,onText:r=>this.#xt(r),strings:this.#e}),this.#Q.appendChild(this.#pe.element))}#yt(e){return e===null?null:n=>el(n,{url:e,headers:this.#W(e),...this.#oe()})}#xt(e){let n=this.#l.value.trim();this.#l.value=n===""?e:`${n} ${e}`,this.#Ze(),this.#l.focus()}#wt(){let e=this.getAttribute("data-attachment-max-bytes");if(e===null)return vs;let n=Number.parseInt(e,10);return Number.isFinite(n)&&n>=0?n:vs}#_t(){let e=this.#w.files;if(e!==null)for(let n of Array.from(e))this.#y?.add(n);this.#w.value=""}#Et(){this.#p.addEventListener("dragover",e=>{e.preventDefault(),this.#p.classList.add("chat--dragover")}),this.#p.addEventListener("dragleave",()=>{this.#p.classList.remove("chat--dragover")}),this.#p.addEventListener("drop",e=>{e.preventDefault(),this.#p.classList.remove("chat--dragover");let n=e.dataTransfer?.files;if(n!==void 0)for(let r of Array.from(n))this.#y?.add(r)})}#ze(){let e=this.getAttribute("data-threads-url");e!==null&&(this.conversationStore=new kr(e,()=>this.#W(e),this.conversationStore,()=>this.#ie(),this.getAttribute("data-threads-cache")!=="false"))}async#Ge(){let e=this.getAttribute("data-tools-url");if(e!==null)try{let n=await fetch(e,this.#Ue(e));this.#t=xa(await n.json())}catch{}}setSkills(e){this.#Le=e,this.#xe()}#Tt(){this.#T.enableChips(this.#He("data-prompt-chips")),this.#T.enableSlash(this.#He("data-slash-commands")),this.#Me=this.#St(),this.#xe()}#St(){let e=this.getAttribute("data-skills");if(e===null)return[];try{return aa(JSON.parse(e))}catch{return[]}}async#Fe(){let e=this.getAttribute("data-skills-url");if(e!==null)try{let n=await fetch(e,this.#Ue(e));this.#Oe=aa(await n.json()),this.#xe()}catch{}}#xe(){let e=new Map;for(let n of[...this.#Oe,...this.#Me,...this.#Le])e.set(n.name,n);this.#T.setSkills([...e.values()])}#At(e){if(e.prompt===void 0){this.#S.hidden=!0,this.sendMessage(`/${e.name}`);return}let{text:n,missing:r}=Md(e.prompt,this.skillContext());if(r.length>0){this.#S.textContent=this.#e.skillNeeds.replace("{title}",e.title).replace("{fields}",r.join(", ")),this.#S.hidden=!1,this.#l.value=n,this.#Y(),this.#l.focus(),this.#kt(n);return}if(this.#S.hidden=!0,this.#l.value=n,this.#Y(),e.sendImmediately===!1){this.#l.focus();return}this.#ke()}#kt(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.#se(Fu),e?"1":"0"),this.#ce(0),this.dispatchEvent(new CustomEvent(ds,{detail:{collapsed:e},bubbles:!0,composed:!0}))}get unread(){return this.#J}toggleCollapsed(){this.setCollapsed(!this.collapsed)}toggleTheme(){let e=this.getAttribute("theme")==="dark"?"light":"dark";this.setAttribute("theme",e),et(this.#se(Vu),e),this.#qe()}#we(){switch(this.getAttribute("placement")){case"full":case"page":return"none";case"sidebar":case"side":return"width";default:return"both"}}#$e(){let e=this.getBoundingClientRect(),n=this.style.getPropertyValue("--ag-ui-width"),r=this.style.getPropertyValue("--ag-ui-height");this.#Ee({width:e.width+1,height:e.height+1});let i=this.getBoundingClientRect();return this.#Ve("--ag-ui-width",n),this.#Ve("--ag-ui-height",r),{x:Math.abs(i.left-e.left)<.5?"left":"right",y:Math.abs(i.top-e.top)<.5?"top":"bottom"}}#_e(){if(!this.#z)return;let e=this.#$e();this.setAttribute("data-resize-anchor",`${e.y}-${e.x}`)}#Ve(e,n){if(n===""){this.style.removeProperty(e);return}this.style.setProperty(e,n)}#Ee(e){let n=this.#we();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`))}#Ct(){let e=this.#we();e!=="both"&&this.style.removeProperty("--ag-ui-height"),e==="none"&&this.style.removeProperty("--ag-ui-width")}#It(e){let n={...this.#Be(),...e};et(this.#se($u),JSON.stringify(n))}#Be(){let e=this.#Se($u);if(e===null)return{};try{let n=JSON.parse(e);return typeof n=="object"&&n!==null?n:{}}catch{return{}}}#Rt(){let e=this.id!==""?this.id:this.endpoint;return e===""?"":this.#Ne===e?this.#me:rl.has(e)?(this.#Ne=e,this.#me=`${e}~${Ee()}`,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.#me):(rl.add(e),this.#re=e,e)}#Te(e=this.userKey){return e===""?this.#F:`${this.#F}#${e}`}#Nt(e,n){let r=this.#Te(e),i=this.#Te(n);if(e===""){Be.adopt(r,i),this.#je(i);return}Be.purge(r),this.#je(i),this.#O(),this.#X(),this.#U(!1),this.#ce(0),this.#m=this.conversationStore.threadId(),this.#ae(),this.#K()}#je(e){this.#j!==null&&(this.#j=new Be(e),this.conversationStore=this.#j,this.#ze())}#se(e){return this.#F===""?e:`${e}:${this.#F}`}#Se(e){let n=sessionStorage.getItem(this.#se(e));return n!==null||this.#F===""?n:sessionStorage.getItem(e)}#qe(){let e=this.getAttribute("theme")==="dark";this.#I.textContent=e?"\u2600\uFE0F":"\u{1F319}"}openThreads(){this.#b.close(),this.#K(),this.#H.open()}openCheckpoints(){this.#H.close(),this.#lt(),this.#b.open()}closeCheckpoints(){this.#b.close()}toggleCheckpoints(){if(this.#b.open_){this.#b.close();return}this.openCheckpoints()}newChat(){this.#O(),this.conversationStore.isUnsent?.(this.#m)===!0&&this.conversationStore.clear(this.#m),this.#X(),this.#m=$o(this.conversationStore),this.#U(!1),this.#ce(0)}#X(){this.#L=null,this.#V(),this.#N=null,this.#D=null,this.#k(),this.#i.clear(),this.#d.clear(),this.#c.clear(),this.#u.clear(),this.#ve=[],this.#y?.clear(),this.#a.replaceChildren(this.#M),this.#v()}async#Ot(e){e!==this.#m&&(this.#O(),this.#X(),this.conversationStore.setActiveThread(e),this.#m=e,this.#U(!1),await this.#ae())}#Mt(e){let n=e===this.#m;n&&this.#O(),this.conversationStore.clear(e),n&&(this.#X(),this.#m=this.conversationStore.threadId(),this.#U(!1)),this.#K()}async#K(){this.#H.setThreads(await this.conversationStore.listThreads(),this.#m)}async#ae(){this.#ge+=1;let e=this.#ge,n=await this.conversationStore.loadMessages(this.#m);if(e!==this.#ge)return;if(n!==null){this.#ve=n;for(let i of n)this.#Dt(i)}let r=this.conversationStore.loadCheckpoint(this.#m);if(r!==null){await this.#Ht(r);return}this.#Pt(n)}#We(){return this.#he=window.location.href,this.getContext()}#Lt(){return this.#he!==null&&this.#he!==window.location.href}#Pt(e){let n=e?.at(-1);n===void 0||n.role!==We.USER||this.#de("\u26A0",this.#e.runInterrupted,"interrupted")}#Dt(e){let n=typeof e.content=="string"?e.content:"";if(e.role===We.USER){let r=Za(e);if(n!==""||r.length>0){let i=this.appendMessage(We.USER,n);r.length>0&&i.appendChild(Sa(r))}return}if(e.role===We.ASSISTANT){n!==""&&this.appendMessage(We.ASSISTANT,n).classList.add("message--restored");for(let r of oy(e.toolCalls)){let i={id:r.id,name:r.function.name,args:this.#Ut(r.function.arguments)};if(this.#it(i))continue;this.#c.set(i.id,this.#Re(i).element);let o=this.#ye(i.name)?.render;o!==void 0&&this.#ot(o,i)}return}if(e.role==="activity"){let r=e;r.activityType===Yn&&this.#s&&this.#Ie(e.id,r.content);return}if(e.role==="tool"){let r=this.#i.get(e.toolCallId);r!==void 0&&r.settle(ee.DONE,e.content)}}#Ut(e){if(typeof e!="string")return{};try{let n=JSON.parse(e);if(typeof n=="object"&&n!==null)return n}catch{}return{}}#Xe(e){this.getAttribute("data-text-animation")==="word"&&Nu(e)}async#Ht(e){this.conversationStore.saveCheckpoint(this.#m,null);let n=this.#Je();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===We.ASSISTANT?(r.innerHTML=Lo(n,{allowImages:this.allowImages}),Ta(r,this.#e),this.#E().appendChild(r)):(this.#N=null,r.textContent=n,this.#a.appendChild(r)),this.#v(),this.#a.scrollTop=this.#a.scrollHeight,r}#E(){if(this.#N===null){let e=document.createElement("div");e.className="answer",e.setAttribute("part","answer"),this.#N=e,this.#a.appendChild(e),this.#v()}return this.#N}#zt(){let e=document.createElement("style");e.textContent=Mu,this.#p.className="chat",this.#p.setAttribute("part","panel");let n=document.createElement("div");n.className="header",n.setAttribute("part","header");let r=this.#C;r.className="header-title",r.setAttribute("part","title"),r.textContent=this.getAttribute("title-text")??this.#e.title,(this.querySelector('[slot="icon"]')!==null||this.getAttribute("data-icon-url")!==null)&&n.append(this.#Ke("icon","icon",null));let i=document.createElement("slot");i.name="header-actions";let o=document.createElement("div");o.className="header-controls",o.setAttribute("part","header-controls");let s=this.#le("history",this.#e.chatHistory,"\u2630");s.addEventListener("click",()=>this.openThreads());let a=this.#le("checkpoints",this.#e.checkpoints,"\u21BA");a.addEventListener("click",()=>this.toggleCheckpoints());let l=this.#le("new",this.#e.newChat,"\u271A");l.addEventListener("click",()=>this.newChat());let c=this.#le("collapse",this.#e.collapse,"\u2014");c.addEventListener("click",()=>this.toggleCollapsed()),this.#be()!==null?o.append(s,a,l):o.append(s,l),this.getAttribute("data-theme-toggle")!==null&&(this.#I.type="button",this.#I.className="header-btn header-btn--theme",this.#I.setAttribute("part","header-button theme-toggle"),this.#I.title=this.#e.toggleTheme,this.#I.setAttribute("aria-label",this.#e.toggleTheme),this.#I.addEventListener("click",()=>this.toggleTheme()),this.#qe(),o.append(this.#I)),o.append(c),n.append(r,i,o),this.#a.className="messages",this.#a.setAttribute("part","messages"),this.#a.setAttribute("role","log"),this.#a.setAttribute("aria-live","polite"),this.#a.setAttribute("aria-label",this.#e.conversation),this.#M.className="empty",this.#M.setAttribute("part","empty");let p=document.createElement("slot");p.name="empty",this.#M.append(p),this.#a.append(this.#M);let m=document.createElement("div");m.className="input-row",m.setAttribute("part","composer");let y=document.createElement("div");y.className="composer",y.setAttribute("part","composer-surface");let f=document.createElement("div");f.className="composer-tools",f.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",g=>this.#Vt(g)),this.#l.addEventListener("input",()=>this.#Ze()),this.#g.className="send",this.#g.type="button",this.#g.setAttribute("part","send"),this.#g.append(this.#Ae("icon-send","send-send",Ol),this.#Ae("icon-stop","send-stop",Ml)),this.#g.title=this.#e.send,this.#g.setAttribute("aria-label",this.#e.send),this.#g.dataset.state="idle",this.#g.addEventListener("click",()=>{if(this.#B){this.#O();return}this.#ke()}),this.#S.className="skill-hint",this.#S.setAttribute("part","skill-hint"),this.#S.hidden=!0,this.#x.className="attach-btn",this.#x.type="button",this.#x.setAttribute("part","attach-button"),this.#x.append(this.#Ae("icon-attach","attach-glyph",Ll)),this.#x.title=this.#e.attachFiles,this.#x.setAttribute("aria-label",this.#e.attachFiles),this.#x.hidden=!0,this.#x.addEventListener("click",()=>this.#w.click()),this.#w.className="attach-input",this.#w.type="file",this.#w.multiple=!0,this.#w.hidden=!0,this.#w.addEventListener("change",()=>this.#_t()),this.#Z.className="attachment-slot",this.#Q.className="voice-slot";let h=document.createElement("slot");h.name="footer",f.append(this.#x,this.#Q,this.#g),y.append(this.#l,f),m.append(y,this.#w),this.#p.append(n,this.#a,this.#T.palette,this.#T.chips,this.#S,this.#Z,m,h,this.#H.element,this.#b.element),this.#p.addEventListener("pointerdown",g=>{if(!this.#b.open_)return;let x=g.composedPath();x.includes(this.#b.element)||x.includes(a)||this.#b.close()}),this.#_.className="launcher",this.#_.type="button",this.#_.setAttribute("part","launcher"),this.#_.setAttribute("aria-label",this.#e.expand),this.#R.className="launcher-badge",this.#R.setAttribute("part","launcher-badge"),this.#R.setAttribute("aria-hidden","true"),this.#R.hidden=!0,this.#_.append(this.#Ke("launcher","launcher-icon",Dl,this.#Gt()),this.#R),this.#_.addEventListener("click",()=>this.setCollapsed(!1)),this.#p.append(Iu({axis:()=>this.#we(),anchor:()=>this.#$e(),rect:()=>this.getBoundingClientRect(),apply:g=>this.#Ee(g),commit:g=>{this.#It(g),this.#_e()},label:this.#e.resizePanel})),this.#f.append(e,this.#p,this.#_)}#le(e,n,r){let i=document.createElement("button");i.type="button",i.className=`header-btn header-btn--${e}`,i.setAttribute("part",`header-button ${e}-button`),i.title=n,i.setAttribute("aria-label",n);let o=document.createElement("slot");return o.name=`icon-${e}`,o.append(document.createTextNode(r)),i.append(o),i}#Ae(e,n,r){let i=document.createElement("slot");return i.name=e,i.className=n,i.innerHTML=r,i}#Gt(){return this.getAttribute("data-launcher-icon-url")??this.getAttribute("data-icon-url")}#Ke(e,n,r,i=this.getAttribute("data-icon-url")){let o=document.createElement("span");o.className="icon-holder",o.setAttribute("part",n);let s=document.createElement("slot");if(s.name=e,i!==null){let a=document.createElement("img");a.className="icon-img",a.src=i,a.alt="",s.append(a)}else r!==null&&(s.innerHTML=r);return o.append(s),o}#Ye(){this.#_.setAttribute("aria-expanded",String(!this.collapsed));let e=this.#J;this.#R.textContent=e>9?"9+":String(e),this.#R.hidden=e===0||!this.#Ft();let n=this.#R.hidden?this.#e.expand:this.#e.expandUnread.replace("{count}",String(e));this.#_.setAttribute("aria-label",n),this.#_.title=n}#Ft(){return this.getAttribute("data-unread-badge")!=="false"}#ce(e){this.#J=e,this.#Ye(),this.dispatchEvent(new CustomEvent(us,{detail:{unread:e},bubbles:!0,composed:!0}))}#$t(){this.collapsed&&this.#ce(this.#J+1)}#v(){this.#M.hidden=this.#a.childElementCount>1}#Ze(){this.#T.onInput(this.#l.value),this.#S.hidden=!0,this.#Y()}#Vt(e){if(this.#T.onKeydown(e)){e.preventDefault();return}if(e.key==="Escape"&&this.#B){e.preventDefault(),this.#O();return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),this.#ke())}#O(){this.#A?.abort(),this.#L?.cancel()}#U(e){this.#B=e;let n=e?this.#e.stop:this.#e.send;this.#g.title=n,this.#g.setAttribute("aria-label",n),this.#g.dataset.state=e?"running":"idle"}#Y(){this.#l.style.height="auto",this.#l.style.height=`${this.#l.scrollHeight}px`}async#ke(){if(this.#B)return;let e=this.#l.value.trim(),n=this.#y?.readyRefs()??[];e===""&&n.length===0||(this.#l.value="",this.#Y(),this.#y?.hasPending()===!0&&this.#de("\u{1F4CE}",this.#e.attachmentsStillUploading.replace("{n}",String(this.#y.pendingCount())),"attachment-pending"),this.#y?.clearReady(),await this.sendMessage(e,n))}async sendMessage(e,n=[]){if(this.#B||e===""&&n.length===0)return;let r=this.appendMessage(We.USER,e);n.length>0&&r.appendChild(Sa(n)),this.dispatchEvent(new CustomEvent(cs,{detail:{content:e,attachments:n},bubbles:!0,composed:!0})),await this.#jt(e,n)}attachFile(e){return this.#y===null?!1:(this.#y.add(e),!0)}#Bt(e){this.dispatchEvent(new CustomEvent(hs,{detail:{attachments:e.readyRefs(),pending:e.pendingCount()},bubbles:!0,composed:!0}))}async#jt(e,n){this.endpoint!==""&&await this.#Je().send(e,n)}#Je(){if(this.#L===null){let e=this.agentFactory({endpoint:this.endpoint,headers:this.#q(),getHeaders:()=>this.#q(),trustedOrigins:this.trustedOrigins,...this.#oe(),threadId:this.#m,initialMessages:this.#ve,initialState:this.#G});this.#L=new Fn({agent:e,handlers:this.#tt(),getTools:()=>this.#De(),getContext:()=>this.#We(),executeTool:n=>this.#Qe(n),resolveInterrupts:n=>this.#et(n),onPersist:n=>this.conversationStore.saveMessages(this.#m,n),onStateChanged:n=>this.#qt(n),connectionLostMessage:this.#e.connectionLost})}return this.#L}#qt(e){this.#G={...e},this.dispatchEvent(new CustomEvent(ps,{detail:{state:this.#G},bubbles:!0,composed:!0}))}async#Wt(e,n){return this.autoConfirm?!1:this.confirmPredicate!==null?await this.confirmPredicate(e.name,e.args)===!0:la(n.parameters)}async#Qe(e){if(Bu(e)!==null)return null;let n=this.#Re(e);this.#i.delete(e.id),this.#c.set(e.id,n.element);let r=this.#o.has(e.name)?this.#ye(e.name):null;if(r===null)return this.#d.has(e.id)||n.settle(ee.DONE,this.#e.noResult),null;if(this.getPageMap!==null&&e.name!==ms&&!go(r.parameters)&&this.#Lt()){let o=this.#e.pageMoved;return n.settle(ee.ERROR,o),this.#$(),{content:`Error: ${o}`,error:o}}if(await this.#Wt(e,r)){let o={toolName:e.name,args:e.args},s=r.parameters[Vr];typeof s=="string"&&(o.message=s),this.#A=new AbortController;let a=Ca(this.#E(),o,{signal:this.#A.signal,strings:this.#e});this.#v(),this.#a.scrollTop=this.#a.scrollHeight;let l=await a;if(this.#A=null,n.recordDecision(l?"approved":"declined"),!l){let c=this.#e.declinedAction;return n.settle(ee.DECLINED,c),this.#$(),{content:c}}}let i=go(r.parameters)&&this.navigate===null;i&&this.conversationStore.saveCheckpoint(this.#m,{toolCallId:e.id});try{let o=await r.handler(e.args,e.id);if(r.render!==void 0&&this.#ot(r.render,e),i)return n.settle(ee.DONE,this.#e.navigating),{content:"",halt:!0};let s=JSON.stringify(o??null);return n.settle(ee.DONE,s),this.#$(),{content:s}}catch(o){i&&this.conversationStore.saveCheckpoint(this.#m,null);let s=o instanceof Error?o.message:String(o);return n.settle(ee.ERROR,s),this.#$(),{content:`Error: ${s}`,error:s}}}async#et(e){this.#A=new AbortController,this.#k();let n=this.#A.signal,r=await Promise.all(e.map(async o=>{let s=o.toolCallId!==void 0?this.#i.get(o.toolCallId):void 0,a={},l=iy(o)??o.message;l!==void 0&&(a.message=l);let c=s?.element.getAttribute("data-tool-name");c!=null&&(a.toolName=c),s?.mark(ee.DEFERRED);let p=this.approvalRenderer!==null?await this.approvalRenderer(a,{signal:n}):await Ea(s?.approvalSlot??this.#E(),a,{signal:n,strings:this.#e});return s?.recordDecision(p?"approved":"declined"),p?s?.mark(ee.PENDING):s?.settle(ee.DECLINED,this.#e.declinedAction),{id:o.id,approved:p}}));this.#v(),this.#a.scrollTop=this.#a.scrollHeight,this.#A=null;let i={};for(let{id:o,approved:s}of r)i[o]=s?{status:"resolved",payload:{approved:!0}}:{status:"cancelled"};return i}#tt(){return{onRunStart:()=>{this.#U(!0),this.#E(),this.#$()},onReasoningStart:()=>{this.#k(),this.#nt()},onReasoningDelta:e=>{this.#nt().stream(e)},onReasoningEnd:()=>{},onTextDelta:e=>{this.#k(),this.#D?.collapse(),this.#Yt(e),this.#fe+=1},onTextEnd:e=>{let n=this.#Ce(e);this.#fe<=1&&this.#Xe(n),Ta(n,this.#e),this.#V(),this.#$t()},onToolCall:e=>{this.#k(),!this.#it(e)&&(this.#h.push({id:e.id,name:e.name}),this.#Re(e))},onActivity:(e,n,r)=>{if(e===Yn){this.#s&&this.#Ie(r,n);return}if(e!==bs)return;let i=ay(n);i!==null&&this.#de("\u{1F5DC}",this.#e.historyCompacted.replace("{count}",String(i)),"compaction")},onToolResult:(e,n)=>{let r=this.#i.get(e);r!==void 0&&(r.settle(ee.DONE,n),this.#d.add(e),this.#$())},onActivityChanged:(e,n,r)=>{n===Yn&&this.#s&&this.#Ie(e,r)},onRunEnd:()=>{this.#k(),this.#V()},onError:e=>{this.#k(),this.#Xe(this.appendMessage(We.ASSISTANT,`\u26A0\uFE0F ${e}`)),this.#V()},onCancelled:()=>{this.#k(),this.#Kt(),this.#V()},onSettled:()=>{this.#k(),this.#U(!1),this.#V();for(let e of this.#i.values())e.settled||e.settle(ee.DONE,this.#e.noResult);this.#N!==null&&this.#N.childElementCount===0&&(this.#N.remove(),this.#v()),this.#N=null,this.#D=null,this.#Xt()}}}#Xt(){let e=this.#h.map(({id:n,name:r})=>({name:r,side:this.#d.has(n)?"server":"client"}));this.#h=[],this.dispatchEvent(new CustomEvent(fs,{detail:{tools:e},bubbles:!0,composed:!0}))}#Kt(){let e=document.createElement("div");e.className="stopped-note",e.setAttribute("part","stopped"),e.setAttribute("role","status"),e.textContent=this.#e.stopped,this.#E().appendChild(e),this.#v(),this.#a.scrollTop=this.#a.scrollHeight}#$(){if(this.#ne!==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.#ne=e,this.#E().appendChild(e),this.#v(),this.#a.scrollTop=this.#a.scrollHeight}#k(){this.#ne?.remove(),this.#ne=null}#nt(){if(this.#D===null){this.#D=new Do(this.#e);let e=this.#E();e.insertBefore(this.#D.element,e.firstChild),this.#v(),this.#a.scrollTop=this.#a.scrollHeight}return this.#D}#rt(){return this.#ee===null&&(this.#ee=this.appendMessage(We.ASSISTANT,""),this.#fe=0),this.#ee}#Yt(e){this.#te=e,this.#rt(),this.#P===null&&(this.#P=requestAnimationFrame(()=>{this.#P=null,this.#Ce(this.#te)}))}#Ce(e){this.#P!==null&&(cancelAnimationFrame(this.#P),this.#P=null),this.#te=e;let n=this.#rt();return n.innerHTML=Lo(e,{allowImages:this.allowImages}),this.#a.scrollTop=this.#a.scrollHeight,n}#V(){this.#P!==null&&this.#Ce(this.#te),this.#ee=null}#it(e){let n=Bu(e);return n===null?!1:(this.#de("\u2728",this.#e.usingSkill.replace("{name}",n),"skill"),!0)}#de(e,n,r){this.#E().appendChild(Ou(e,n,r)),this.#v(),this.#a.scrollTop=this.#a.scrollHeight}enableCharts(e=["tool","activity"]){let n=!this.#s&&!this.#n.has(So);e.includes("activity")&&(this.#s=!0),e.includes("tool")&&this.registerTool(Gd()),n&&this.isConnected&&this.reload()}#ot(e,n){let r;try{r=e(n.args)}catch(i){console.warn(`ag-ui-chat: render failed for tool ${n.name}`,i);return}r!==null&&(this.#c.get(n.id)?.after(r),this.#st())}#Ie(e,n){let r=Pn(n),i=r===null?null:mr(r);if(i===null){this.#u.get(e)?.remove(),this.#u.delete(e);return}let o=this.#u.get(e);o===void 0?this.#E().appendChild(i):o.replaceWith(i),this.#u.set(e,i),this.#st()}#st(){this.#v(),this.#a.scrollTop=this.#a.scrollHeight}#Re(e){let n=this.#i.get(e.id);if(n!==void 0)return n;let r=this.#ye(e.name)?.parameters[Pe],i=typeof r=="string"?r:this.toolSummaries[e.name]??this.#t[e.name]?.summary??Ia(e.name),o=new Tr(e.name,e.args,i,this.#e);return this.#i.set(e.id,o),this.#E().appendChild(o.element),this.#v(),this.#a.scrollTop=this.#a.scrollHeight,o}};function iy(t){let e=t.metadata?.[Vr];return typeof e=="string"&&e.trim()!==""?e:void 0}function oy(t){return Array.isArray(t)?t.filter(sy):[]}function sy(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.id=="string"&&typeof e.function?.name=="string"}function Bu(t){if(t.name!==ys)return null;let e=t.args?.id;return typeof e=="string"&&e!==""?e:null}function ay(t){let e=t?.removed;return typeof e=="number"?e:null}function ly(){customElements.get($r)===void 0&&customElements.define($r,Ir)}async function cy(t,e,n={}){await vt(t),await ha(t,{...n,flashMs:n.flashMs??0}),await ua(t,e,n)}async function dy(t,e={}){await vt(t),await pa(t,e)}async function uy(t,e={}){await vt(t),await fa(t,e)}async function py(t,e,n={}){await vt(t),await ma(t,e,n)}async function hy(t,e,n={}){await vt(t),await ga(t,e,n)}function fy(t,e){t instanceof HTMLInputElement&&t.type==="checkbox"?pr(t,!!e):rn(t,String(e)),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0}))}var my="0.28.0";export{hs as ATTACHMENT_EVENT,Ir as AgUiChat,Fn as AgUiClient,Yn as CHART_ACTIVITY_TYPE,So as CHART_TOOL_NAME,bs as COMPACTION_ACTIVITY_TYPE,gr as CheckpointMenu,ur as ClientToolRegistry,zo as ConnectionLostError,le as DEFAULT_UI_STRINGS,$r as ELEMENT_TAG,ys as LOAD_CAPABILITY_TOOL,gs as MAX_TOOL_ROUNDS,We as MESSAGE_ROLE,va as PAGE_ACTIONS,fs as RUN_FINISHED_EVENT,kr as RemoteConversationStore,Cr as RunIndex,ps as STATE_EVENT,cs as SUBMIT_EVENT,Be as SessionStorageStore,ds as TOGGLE_EVENT,ee as TOOL_CALL_STATUS,vn as TOOL_DISPLAY,Tr as ToolCallCard,us as UNREAD_EVENT,my as VERSION,Vr as X_CONFIRM_KEY,Xn as X_DESTRUCTIVE_KEY,Kn as X_NAVIGATES_KEY,Pe as X_SUMMARY_KEY,Pn as chartSpecFrom,dy as clickElement,Qa as createHttpAgent,ba as createPageActionTools,ya as createPageMapContext,xo as createPageStateTools,wa as createRouteTools,Hg as createStateHookTools,ly as defineAgUiChat,cy as fillField,Mg as flash,ha as focusWithFlash,pa as highlightThenClick,la as isDestructive,go as isNavigates,_a as mergeUiStrings,Za as messageAttachments,xa as parseToolCatalog,bo as prefersReducedMotion,uy as pressButton,fa as pressThenClick,Ia as prettifyToolName,mr as renderChart,Lo as renderMarkdown,Ea as requestApproval,Ca as requestConfirmation,Ra as requestQuestion,vt as scrollIntoCenterView,py as selectControl,ma as selectOption,fy as setControlValue,pr as setNativeChecked,rn as setNativeValue,hy as toggleCheckbox,ga as toggleControl,el as transcribeAudio,ua as typeInto,tl as uploadAttachment};
|
|
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}
|
|
2661
|
+
|
|
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};
|
|
2405
2663
|
/*! Bundled license information:
|
|
2406
2664
|
|
|
2407
2665
|
fast-json-patch/module/helpers.mjs:
|