@artooi/ag-ui-web-component 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +102 -2
  2. package/README.md +235 -47
  3. package/dist/ag-ui-web-component.bundle.js +451 -46
  4. package/dist/ag-ui-web-component.bundle.js.map +4 -4
  5. package/dist/constants.d.ts +34 -0
  6. package/dist/constants.d.ts.map +1 -1
  7. package/dist/{ag_ui_chat.d.ts → core/ag_ui_chat.d.ts} +63 -6
  8. package/dist/core/ag_ui_chat.d.ts.map +1 -0
  9. package/dist/core/agui_client.d.ts.map +1 -0
  10. package/dist/core/conversation_store.d.ts.map +1 -0
  11. package/dist/core/create_http_agent.d.ts.map +1 -0
  12. package/dist/core/define_ag_ui_chat.d.ts.map +1 -0
  13. package/dist/dom/animations.d.ts +71 -0
  14. package/dist/dom/animations.d.ts.map +1 -0
  15. package/dist/{dom_driver.d.ts → dom/dom_driver.d.ts} +7 -1
  16. package/dist/dom/dom_driver.d.ts.map +1 -0
  17. package/dist/dom/native_setter.d.ts +5 -0
  18. package/dist/dom/native_setter.d.ts.map +1 -0
  19. package/dist/index.d.ts +19 -16
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +3886 -388
  22. package/dist/index.js.map +4 -4
  23. package/dist/skills/fill_template.d.ts +17 -0
  24. package/dist/skills/fill_template.d.ts.map +1 -0
  25. package/dist/skills/parse_skills.d.ts +8 -0
  26. package/dist/skills/parse_skills.d.ts.map +1 -0
  27. package/dist/skills/skill.d.ts +24 -0
  28. package/dist/skills/skill.d.ts.map +1 -0
  29. package/dist/{client_tool_registry.d.ts → tools/client_tool_registry.d.ts} +6 -1
  30. package/dist/tools/client_tool_registry.d.ts.map +1 -0
  31. package/dist/tools/is_destructive.d.ts.map +1 -0
  32. package/dist/tools/is_navigates.d.ts.map +1 -0
  33. package/dist/tools/page_map.d.ts.map +1 -0
  34. package/dist/tools/route_map.d.ts +40 -0
  35. package/dist/tools/route_map.d.ts.map +1 -0
  36. package/dist/tools/state_hook.d.ts.map +1 -0
  37. package/dist/ui/confirmation_card.d.ts +22 -0
  38. package/dist/ui/confirmation_card.d.ts.map +1 -0
  39. package/dist/ui/render_markdown.d.ts +13 -0
  40. package/dist/ui/render_markdown.d.ts.map +1 -0
  41. package/dist/ui/reveal_words.d.ts +8 -0
  42. package/dist/ui/reveal_words.d.ts.map +1 -0
  43. package/dist/ui/skills_menu.d.ts +35 -0
  44. package/dist/ui/skills_menu.d.ts.map +1 -0
  45. package/dist/ui/styles.d.ts +2 -0
  46. package/dist/ui/styles.d.ts.map +1 -0
  47. package/dist/ui/tool_call_card.d.ts +35 -0
  48. package/dist/ui/tool_call_card.d.ts.map +1 -0
  49. package/package.json +5 -3
  50. package/src/constants.ts +38 -0
  51. package/src/core/ag_ui_chat.ts +786 -0
  52. package/src/{agui_client.ts → core/agui_client.ts} +1 -1
  53. package/src/{define_ag_ui_chat.ts → core/define_ag_ui_chat.ts} +1 -1
  54. package/src/dom/animations.ts +201 -0
  55. package/src/{dom_driver.ts → dom/dom_driver.ts} +35 -2
  56. package/src/dom/native_setter.ts +42 -0
  57. package/src/index.ts +61 -32
  58. package/src/skills/fill_template.ts +32 -0
  59. package/src/skills/parse_skills.ts +26 -0
  60. package/src/skills/skill.ts +23 -0
  61. package/src/{client_tool_registry.ts → tools/client_tool_registry.ts} +6 -4
  62. package/src/{is_destructive.ts → tools/is_destructive.ts} +1 -1
  63. package/src/{is_navigates.ts → tools/is_navigates.ts} +1 -1
  64. package/src/tools/route_map.ts +140 -0
  65. package/src/{state_hook.ts → tools/state_hook.ts} +1 -1
  66. package/src/ui/confirmation_card.ts +71 -0
  67. package/src/ui/render_markdown.ts +68 -0
  68. package/src/ui/reveal_words.ts +41 -0
  69. package/src/ui/skills_menu.ts +171 -0
  70. package/src/ui/styles.ts +631 -0
  71. package/src/{tool_call_card.ts → ui/tool_call_card.ts} +50 -19
  72. package/src/version.ts +1 -1
  73. package/dist/ag_ui_chat.d.ts.map +0 -1
  74. package/dist/agui_client.d.ts.map +0 -1
  75. package/dist/animations.d.ts +0 -33
  76. package/dist/animations.d.ts.map +0 -1
  77. package/dist/client_tool_registry.d.ts.map +0 -1
  78. package/dist/confirmation_modal.d.ts +0 -14
  79. package/dist/confirmation_modal.d.ts.map +0 -1
  80. package/dist/conversation_store.d.ts.map +0 -1
  81. package/dist/create_http_agent.d.ts.map +0 -1
  82. package/dist/define_ag_ui_chat.d.ts.map +0 -1
  83. package/dist/dom_driver.d.ts.map +0 -1
  84. package/dist/is_destructive.d.ts.map +0 -1
  85. package/dist/is_navigates.d.ts.map +0 -1
  86. package/dist/page_map.d.ts.map +0 -1
  87. package/dist/route_map.d.ts +0 -27
  88. package/dist/route_map.d.ts.map +0 -1
  89. package/dist/state_hook.d.ts.map +0 -1
  90. package/dist/styles.d.ts +0 -2
  91. package/dist/styles.d.ts.map +0 -1
  92. package/dist/tool_call_card.d.ts +0 -29
  93. package/dist/tool_call_card.d.ts.map +0 -1
  94. package/src/ag_ui_chat.ts +0 -411
  95. package/src/animations.ts +0 -86
  96. package/src/confirmation_modal.ts +0 -69
  97. package/src/route_map.ts +0 -83
  98. package/src/styles.ts +0 -296
  99. /package/dist/{agui_client.d.ts → core/agui_client.d.ts} +0 -0
  100. /package/dist/{conversation_store.d.ts → core/conversation_store.d.ts} +0 -0
  101. /package/dist/{create_http_agent.d.ts → core/create_http_agent.d.ts} +0 -0
  102. /package/dist/{define_ag_ui_chat.d.ts → core/define_ag_ui_chat.d.ts} +0 -0
  103. /package/dist/{is_destructive.d.ts → tools/is_destructive.d.ts} +0 -0
  104. /package/dist/{is_navigates.d.ts → tools/is_navigates.d.ts} +0 -0
  105. /package/dist/{page_map.d.ts → tools/page_map.d.ts} +0 -0
  106. /package/dist/{state_hook.d.ts → tools/state_hook.d.ts} +0 -0
  107. /package/src/{conversation_store.ts → core/conversation_store.ts} +0 -0
  108. /package/src/{create_http_agent.ts → core/create_http_agent.ts} +0 -0
  109. /package/src/{page_map.ts → tools/page_map.ts} +0 -0
@@ -1,14 +1,69 @@
1
- var ca=Object.defineProperty;var fn=(e,t)=>{for(var r in t)ca(e,r,{get:t[r],enumerable:!0})};var Z=[];for(let e=0;e<256;++e)Z.push((e+256).toString(16).slice(1));function yo(e,t=0){return(Z[e[t+0]]+Z[e[t+1]]+Z[e[t+2]]+Z[e[t+3]]+"-"+Z[e[t+4]]+Z[e[t+5]]+"-"+Z[e[t+6]]+Z[e[t+7]]+"-"+Z[e[t+8]]+Z[e[t+9]]+"-"+Z[e[t+10]]+Z[e[t+11]]+Z[e[t+12]]+Z[e[t+13]]+Z[e[t+14]]+Z[e[t+15]]).toLowerCase()}var pn,da=new Uint8Array(16);function mn(){if(!pn){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");pn=crypto.getRandomValues.bind(crypto)}return pn(da)}var fa=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),hn={randomUUID:fa};function pa(e,t,r){if(hn.randomUUID&&!t&&!e)return hn.randomUUID();e=e||{};let n=e.random??e.rng?.()??mn();if(n.length<16)throw new Error("Random bytes length must be >= 16");if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){if(r=r||0,r<0||r+16>t.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let s=0;s<16;++s)t[r+s]=n[s];return t}return yo(n)}var we=pa;var i={};fn(i,{BRAND:()=>Fa,DIRTY:()=>Oe,EMPTY_PATH:()=>va,INVALID:()=>N,NEVER:()=>Si,OK:()=>J,ParseStatus:()=>W,Schema:()=>R,ZodAny:()=>Ne,ZodArray:()=>be,ZodBigInt:()=>Me,ZodBoolean:()=>Pe,ZodBranded:()=>yt,ZodCatch:()=>ze,ZodDate:()=>Le,ZodDefault:()=>Be,ZodDiscriminatedUnion:()=>Vt,ZodEffects:()=>ae,ZodEnum:()=>$e,ZodError:()=>ee,ZodFirstPartyTypeKind:()=>C,ZodFunction:()=>$t,ZodIntersection:()=>Fe,ZodIssueCode:()=>y,ZodLazy:()=>Ve,ZodLiteral:()=>He,ZodMap:()=>st,ZodNaN:()=>it,ZodNativeEnum:()=>je,ZodNever:()=>le,ZodNull:()=>Ue,ZodNullable:()=>me,ZodNumber:()=>Re,ZodObject:()=>te,ZodOptional:()=>oe,ZodParsedType:()=>b,ZodPipeline:()=>Et,ZodPromise:()=>Ce,ZodReadonly:()=>Xe,ZodRecord:()=>Ht,ZodSchema:()=>R,ZodSet:()=>at,ZodString:()=>Ae,ZodSymbol:()=>nt,ZodTransformer:()=>ae,ZodTuple:()=>pe,ZodType:()=>R,ZodUndefined:()=>De,ZodUnion:()=>Ge,ZodUnknown:()=>xe,ZodVoid:()=>ot,addIssueToContext:()=>x,any:()=>Za,array:()=>Ja,bigint:()=>ja,boolean:()=>Co,coerce:()=>bi,custom:()=>Io,date:()=>Ba,datetimeRegex:()=>To,defaultErrorMap:()=>Ee,discriminatedUnion:()=>ri,effect:()=>mi,enum:()=>di,function:()=>li,getErrorMap:()=>et,getParsedType:()=>fe,instanceof:()=>Ha,intersection:()=>ni,isAborted:()=>Gt,isAsync:()=>tt,isDirty:()=>Ft,isValid:()=>Ie,late:()=>Va,lazy:()=>ui,literal:()=>ci,makeIssue:()=>vt,map:()=>ai,nan:()=>$a,nativeEnum:()=>fi,never:()=>Ya,null:()=>Ka,nullable:()=>gi,number:()=>No,object:()=>Qa,objectUtil:()=>gn,oboolean:()=>xi,onumber:()=>_i,optional:()=>hi,ostring:()=>Ei,pipeline:()=>yi,preprocess:()=>vi,promise:()=>pi,quotelessJson:()=>ma,record:()=>si,set:()=>ii,setErrorMap:()=>ga,strictObject:()=>ei,string:()=>Ao,symbol:()=>za,transformer:()=>mi,tuple:()=>oi,undefined:()=>Xa,union:()=>ti,unknown:()=>Wa,util:()=>P,void:()=>qa});var P;(function(e){e.assertEqual=s=>{};function t(s){}e.assertIs=t;function r(s){throw new Error}e.assertNever=r,e.arrayToEnum=s=>{let o={};for(let a of s)o[a]=a;return o},e.getValidEnumValues=s=>{let o=e.objectKeys(s).filter(l=>typeof s[s[l]]!="number"),a={};for(let l of o)a[l]=s[l];return e.objectValues(a)},e.objectValues=s=>e.objectKeys(s).map(function(o){return s[o]}),e.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{let o=[];for(let a in s)Object.prototype.hasOwnProperty.call(s,a)&&o.push(a);return o},e.find=(s,o)=>{for(let a of s)if(o(a))return a},e.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function n(s,o=" | "){return s.map(a=>typeof a=="string"?`'${a}'`:a).join(o)}e.joinValues=n,e.jsonStringifyReplacer=(s,o)=>typeof o=="bigint"?o.toString():o})(P||(P={}));var gn;(function(e){e.mergeShapes=(t,r)=>({...t,...r})})(gn||(gn={}));var b=P.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),fe=e=>{switch(typeof e){case"undefined":return b.undefined;case"string":return b.string;case"number":return Number.isNaN(e)?b.nan:b.number;case"boolean":return b.boolean;case"function":return b.function;case"bigint":return b.bigint;case"symbol":return b.symbol;case"object":return Array.isArray(e)?b.array:e===null?b.null:e.then&&typeof e.then=="function"&&e.catch&&typeof e.catch=="function"?b.promise:typeof Map<"u"&&e instanceof Map?b.map:typeof Set<"u"&&e instanceof Set?b.set:typeof Date<"u"&&e instanceof Date?b.date:b.object;default:return b.unknown}};var y=P.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"]),ma=e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:"),ee=class e extends Error{get errors(){return this.issues}constructor(t){super(),this.issues=[],this.addIssue=n=>{this.issues=[...this.issues,n]},this.addIssues=(n=[])=>{this.issues=[...this.issues,...n]};let r=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,r):this.__proto__=r,this.name="ZodError",this.issues=t}format(t){let r=t||function(o){return o.message},n={_errors:[]},s=o=>{for(let a of o.issues)if(a.code==="invalid_union")a.unionErrors.map(s);else if(a.code==="invalid_return_type")s(a.returnTypeError);else if(a.code==="invalid_arguments")s(a.argumentsError);else if(a.path.length===0)n._errors.push(r(a));else{let l=n,u=0;for(;u<a.path.length;){let c=a.path[u];u===a.path.length-1?(l[c]=l[c]||{_errors:[]},l[c]._errors.push(r(a))):l[c]=l[c]||{_errors:[]},l=l[c],u++}}};return s(this),n}static assert(t){if(!(t instanceof e))throw new Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,P.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(t=r=>r.message){let r={},n=[];for(let s of this.issues)if(s.path.length>0){let o=s.path[0];r[o]=r[o]||[],r[o].push(t(s))}else n.push(t(s));return{formErrors:n,fieldErrors:r}}get formErrors(){return this.flatten()}};ee.create=e=>new ee(e);var ha=(e,t)=>{let r;switch(e.code){case y.invalid_type:e.received===b.undefined?r="Required":r=`Expected ${e.expected}, received ${e.received}`;break;case y.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(e.expected,P.jsonStringifyReplacer)}`;break;case y.unrecognized_keys:r=`Unrecognized key(s) in object: ${P.joinValues(e.keys,", ")}`;break;case y.invalid_union:r="Invalid input";break;case y.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${P.joinValues(e.options)}`;break;case y.invalid_enum_value:r=`Invalid enum value. Expected ${P.joinValues(e.options)}, received '${e.received}'`;break;case y.invalid_arguments:r="Invalid function arguments";break;case y.invalid_return_type:r="Invalid function return type";break;case y.invalid_date:r="Invalid date";break;case y.invalid_string:typeof e.validation=="object"?"includes"in e.validation?(r=`Invalid input: must include "${e.validation.includes}"`,typeof e.validation.position=="number"&&(r=`${r} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?r=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?r=`Invalid input: must end with "${e.validation.endsWith}"`:P.assertNever(e.validation):e.validation!=="regex"?r=`Invalid ${e.validation}`:r="Invalid";break;case y.too_small:e.type==="array"?r=`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:e.type==="string"?r=`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:e.type==="number"?r=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="bigint"?r=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="date"?r=`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:r="Invalid input";break;case y.too_big:e.type==="array"?r=`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:e.type==="string"?r=`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:e.type==="number"?r=`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="bigint"?r=`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="date"?r=`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:r="Invalid input";break;case y.custom:r="Invalid input";break;case y.invalid_intersection_types:r="Intersection results could not be merged";break;case y.not_multiple_of:r=`Number must be a multiple of ${e.multipleOf}`;break;case y.not_finite:r="Number must be finite";break;default:r=t.defaultError,P.assertNever(e)}return{message:r}},Ee=ha;var Eo=Ee;function ga(e){Eo=e}function et(){return Eo}var vt=e=>{let{data:t,path:r,errorMaps:n,issueData:s}=e,o=[...r,...s.path||[]],a={...s,path:o};if(s.message!==void 0)return{...s,path:o,message:s.message};let l="",u=n.filter(c=>!!c).slice().reverse();for(let c of u)l=c(a,{data:t,defaultError:l}).message;return{...s,path:o,message:l}},va=[];function x(e,t){let r=et(),n=vt({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,r,r===Ee?void 0:Ee].filter(s=>!!s)});e.common.issues.push(n)}var W=class e{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(t,r){let n=[];for(let s of r){if(s.status==="aborted")return N;s.status==="dirty"&&t.dirty(),n.push(s.value)}return{status:t.value,value:n}}static async mergeObjectAsync(t,r){let n=[];for(let s of r){let o=await s.key,a=await s.value;n.push({key:o,value:a})}return e.mergeObjectSync(t,n)}static mergeObjectSync(t,r){let n={};for(let s of r){let{key:o,value:a}=s;if(o.status==="aborted"||a.status==="aborted")return N;o.status==="dirty"&&t.dirty(),a.status==="dirty"&&t.dirty(),o.value!=="__proto__"&&(typeof a.value<"u"||s.alwaysSet)&&(n[o.value]=a.value)}return{status:t.value,value:n}}},N=Object.freeze({status:"aborted"}),Oe=e=>({status:"dirty",value:e}),J=e=>({status:"valid",value:e}),Gt=e=>e.status==="aborted",Ft=e=>e.status==="dirty",Ie=e=>e.status==="valid",tt=e=>typeof Promise<"u"&&e instanceof Promise;var T;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t?.message})(T||(T={}));var se=class{constructor(t,r,n,s){this._cachedPath=[],this.parent=t,this.data=r,this._path=n,this._key=s}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}},_o=(e,t)=>{if(Ie(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let r=new ee(e.common.issues);return this._error=r,this._error}}};function k(e){if(!e)return{};let{errorMap:t,invalid_type_error:r,required_error:n,description:s}=e;if(t&&(r||n))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return t?{errorMap:t,description:s}:{errorMap:(a,l)=>{let{message:u}=e;return a.code==="invalid_enum_value"?{message:u??l.defaultError}:typeof l.data>"u"?{message:u??n??l.defaultError}:a.code!=="invalid_type"?{message:l.defaultError}:{message:u??r??l.defaultError}},description:s}}var R=class{get description(){return this._def.description}_getType(t){return fe(t.data)}_getOrReturnCtx(t,r){return r||{common:t.parent.common,data:t.data,parsedType:fe(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new W,ctx:{common:t.parent.common,data:t.data,parsedType:fe(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){let r=this._parse(t);if(tt(r))throw new Error("Synchronous parse encountered promise.");return r}_parseAsync(t){let r=this._parse(t);return Promise.resolve(r)}parse(t,r){let n=this.safeParse(t,r);if(n.success)return n.data;throw n.error}safeParse(t,r){let n={common:{issues:[],async:r?.async??!1,contextualErrorMap:r?.errorMap},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:fe(t)},s=this._parseSync({data:t,path:n.path,parent:n});return _o(n,s)}"~validate"(t){let r={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:fe(t)};if(!this["~standard"].async)try{let n=this._parseSync({data:t,path:[],parent:r});return Ie(n)?{value:n.value}:{issues:r.common.issues}}catch(n){n?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),r.common={issues:[],async:!0}}return this._parseAsync({data:t,path:[],parent:r}).then(n=>Ie(n)?{value:n.value}:{issues:r.common.issues})}async parseAsync(t,r){let n=await this.safeParseAsync(t,r);if(n.success)return n.data;throw n.error}async safeParseAsync(t,r){let n={common:{issues:[],contextualErrorMap:r?.errorMap,async:!0},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:fe(t)},s=this._parse({data:t,path:n.path,parent:n}),o=await(tt(s)?s:Promise.resolve(s));return _o(n,o)}refine(t,r){let n=s=>typeof r=="string"||typeof r>"u"?{message:r}:typeof r=="function"?r(s):r;return this._refinement((s,o)=>{let a=t(s),l=()=>o.addIssue({code:y.custom,...n(s)});return typeof Promise<"u"&&a instanceof Promise?a.then(u=>u?!0:(l(),!1)):a?!0:(l(),!1)})}refinement(t,r){return this._refinement((n,s)=>t(n)?!0:(s.addIssue(typeof r=="function"?r(n,s):r),!1))}_refinement(t){return new ae({schema:this,typeName:C.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}constructor(t){this.spa=this.safeParseAsync,this._def=t,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:r=>this["~validate"](r)}}optional(){return oe.create(this,this._def)}nullable(){return me.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return be.create(this)}promise(){return Ce.create(this,this._def)}or(t){return Ge.create([this,t],this._def)}and(t){return Fe.create(this,t,this._def)}transform(t){return new ae({...k(this._def),schema:this,typeName:C.ZodEffects,effect:{type:"transform",transform:t}})}default(t){let r=typeof t=="function"?t:()=>t;return new Be({...k(this._def),innerType:this,defaultValue:r,typeName:C.ZodDefault})}brand(){return new yt({typeName:C.ZodBranded,type:this,...k(this._def)})}catch(t){let r=typeof t=="function"?t:()=>t;return new ze({...k(this._def),innerType:this,catchValue:r,typeName:C.ZodCatch})}describe(t){let r=this.constructor;return new r({...this._def,description:t})}pipe(t){return Et.create(this,t)}readonly(){return Xe.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},ya=/^c[^\s-]{8,}$/i,Ea=/^[0-9a-z]+$/,_a=/^[0-9A-HJKMNP-TV-Z]{26}$/i,xa=/^[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,ba=/^[a-z0-9_-]{21}$/i,Sa=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Ta=/^[-+]?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)?)??$/,wa=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Ia="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",vn,Aa=/^(?:(?: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])$/,Na=/^(?:(?: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])$/,Ca=/^(([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]))$/,ka=/^(([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])$/,Oa=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Ra=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,bo="((\\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])))",Ma=new RegExp(`^${bo}$`);function So(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:e.precision==null&&(t=`${t}(\\.\\d+)?`);let r=e.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${r}`}function Pa(e){return new RegExp(`^${So(e)}$`)}function To(e){let t=`${bo}T${So(e)}`,r=[];return r.push(e.local?"Z?":"Z"),e.offset&&r.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${r.join("|")})`,new RegExp(`^${t}$`)}function La(e,t){return!!((t==="v4"||!t)&&Aa.test(e)||(t==="v6"||!t)&&Ca.test(e))}function Da(e,t){if(!Sa.test(e))return!1;try{let[r]=e.split(".");if(!r)return!1;let n=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),s=JSON.parse(atob(n));return!(typeof s!="object"||s===null||"typ"in s&&s?.typ!=="JWT"||!s.alg||t&&s.alg!==t)}catch{return!1}}function Ua(e,t){return!!((t==="v4"||!t)&&Na.test(e)||(t==="v6"||!t)&&ka.test(e))}var Ae=class e extends R{_parse(t){if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==b.string){let o=this._getOrReturnCtx(t);return x(o,{code:y.invalid_type,expected:b.string,received:o.parsedType}),N}let n=new W,s;for(let o of this._def.checks)if(o.kind==="min")t.data.length<o.value&&(s=this._getOrReturnCtx(t,s),x(s,{code:y.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),n.dirty());else if(o.kind==="max")t.data.length>o.value&&(s=this._getOrReturnCtx(t,s),x(s,{code:y.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),n.dirty());else if(o.kind==="length"){let a=t.data.length>o.value,l=t.data.length<o.value;(a||l)&&(s=this._getOrReturnCtx(t,s),a?x(s,{code:y.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}):l&&x(s,{code:y.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}),n.dirty())}else if(o.kind==="email")wa.test(t.data)||(s=this._getOrReturnCtx(t,s),x(s,{validation:"email",code:y.invalid_string,message:o.message}),n.dirty());else if(o.kind==="emoji")vn||(vn=new RegExp(Ia,"u")),vn.test(t.data)||(s=this._getOrReturnCtx(t,s),x(s,{validation:"emoji",code:y.invalid_string,message:o.message}),n.dirty());else if(o.kind==="uuid")xa.test(t.data)||(s=this._getOrReturnCtx(t,s),x(s,{validation:"uuid",code:y.invalid_string,message:o.message}),n.dirty());else if(o.kind==="nanoid")ba.test(t.data)||(s=this._getOrReturnCtx(t,s),x(s,{validation:"nanoid",code:y.invalid_string,message:o.message}),n.dirty());else if(o.kind==="cuid")ya.test(t.data)||(s=this._getOrReturnCtx(t,s),x(s,{validation:"cuid",code:y.invalid_string,message:o.message}),n.dirty());else if(o.kind==="cuid2")Ea.test(t.data)||(s=this._getOrReturnCtx(t,s),x(s,{validation:"cuid2",code:y.invalid_string,message:o.message}),n.dirty());else if(o.kind==="ulid")_a.test(t.data)||(s=this._getOrReturnCtx(t,s),x(s,{validation:"ulid",code:y.invalid_string,message:o.message}),n.dirty());else if(o.kind==="url")try{new URL(t.data)}catch{s=this._getOrReturnCtx(t,s),x(s,{validation:"url",code:y.invalid_string,message:o.message}),n.dirty()}else o.kind==="regex"?(o.regex.lastIndex=0,o.regex.test(t.data)||(s=this._getOrReturnCtx(t,s),x(s,{validation:"regex",code:y.invalid_string,message:o.message}),n.dirty())):o.kind==="trim"?t.data=t.data.trim():o.kind==="includes"?t.data.includes(o.value,o.position)||(s=this._getOrReturnCtx(t,s),x(s,{code:y.invalid_string,validation:{includes:o.value,position:o.position},message:o.message}),n.dirty()):o.kind==="toLowerCase"?t.data=t.data.toLowerCase():o.kind==="toUpperCase"?t.data=t.data.toUpperCase():o.kind==="startsWith"?t.data.startsWith(o.value)||(s=this._getOrReturnCtx(t,s),x(s,{code:y.invalid_string,validation:{startsWith:o.value},message:o.message}),n.dirty()):o.kind==="endsWith"?t.data.endsWith(o.value)||(s=this._getOrReturnCtx(t,s),x(s,{code:y.invalid_string,validation:{endsWith:o.value},message:o.message}),n.dirty()):o.kind==="datetime"?To(o).test(t.data)||(s=this._getOrReturnCtx(t,s),x(s,{code:y.invalid_string,validation:"datetime",message:o.message}),n.dirty()):o.kind==="date"?Ma.test(t.data)||(s=this._getOrReturnCtx(t,s),x(s,{code:y.invalid_string,validation:"date",message:o.message}),n.dirty()):o.kind==="time"?Pa(o).test(t.data)||(s=this._getOrReturnCtx(t,s),x(s,{code:y.invalid_string,validation:"time",message:o.message}),n.dirty()):o.kind==="duration"?Ta.test(t.data)||(s=this._getOrReturnCtx(t,s),x(s,{validation:"duration",code:y.invalid_string,message:o.message}),n.dirty()):o.kind==="ip"?La(t.data,o.version)||(s=this._getOrReturnCtx(t,s),x(s,{validation:"ip",code:y.invalid_string,message:o.message}),n.dirty()):o.kind==="jwt"?Da(t.data,o.alg)||(s=this._getOrReturnCtx(t,s),x(s,{validation:"jwt",code:y.invalid_string,message:o.message}),n.dirty()):o.kind==="cidr"?Ua(t.data,o.version)||(s=this._getOrReturnCtx(t,s),x(s,{validation:"cidr",code:y.invalid_string,message:o.message}),n.dirty()):o.kind==="base64"?Oa.test(t.data)||(s=this._getOrReturnCtx(t,s),x(s,{validation:"base64",code:y.invalid_string,message:o.message}),n.dirty()):o.kind==="base64url"?Ra.test(t.data)||(s=this._getOrReturnCtx(t,s),x(s,{validation:"base64url",code:y.invalid_string,message:o.message}),n.dirty()):P.assertNever(o);return{status:n.value,value:t.data}}_regex(t,r,n){return this.refinement(s=>t.test(s),{validation:r,code:y.invalid_string,...T.errToObj(n)})}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...T.errToObj(t)})}url(t){return this._addCheck({kind:"url",...T.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...T.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...T.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...T.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...T.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...T.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...T.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...T.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...T.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...T.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...T.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...T.errToObj(t)})}datetime(t){return typeof t=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:typeof t?.precision>"u"?null:t?.precision,offset:t?.offset??!1,local:t?.local??!1,...T.errToObj(t?.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return typeof t=="string"?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:typeof t?.precision>"u"?null:t?.precision,...T.errToObj(t?.message)})}duration(t){return this._addCheck({kind:"duration",...T.errToObj(t)})}regex(t,r){return this._addCheck({kind:"regex",regex:t,...T.errToObj(r)})}includes(t,r){return this._addCheck({kind:"includes",value:t,position:r?.position,...T.errToObj(r?.message)})}startsWith(t,r){return this._addCheck({kind:"startsWith",value:t,...T.errToObj(r)})}endsWith(t,r){return this._addCheck({kind:"endsWith",value:t,...T.errToObj(r)})}min(t,r){return this._addCheck({kind:"min",value:t,...T.errToObj(r)})}max(t,r){return this._addCheck({kind:"max",value:t,...T.errToObj(r)})}length(t,r){return this._addCheck({kind:"length",value:t,...T.errToObj(r)})}nonempty(t){return this.min(1,T.errToObj(t))}trim(){return new e({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new e({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new e({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(t=>t.kind==="datetime")}get isDate(){return!!this._def.checks.find(t=>t.kind==="date")}get isTime(){return!!this._def.checks.find(t=>t.kind==="time")}get isDuration(){return!!this._def.checks.find(t=>t.kind==="duration")}get isEmail(){return!!this._def.checks.find(t=>t.kind==="email")}get isURL(){return!!this._def.checks.find(t=>t.kind==="url")}get isEmoji(){return!!this._def.checks.find(t=>t.kind==="emoji")}get isUUID(){return!!this._def.checks.find(t=>t.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(t=>t.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(t=>t.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(t=>t.kind==="cuid2")}get isULID(){return!!this._def.checks.find(t=>t.kind==="ulid")}get isIP(){return!!this._def.checks.find(t=>t.kind==="ip")}get isCIDR(){return!!this._def.checks.find(t=>t.kind==="cidr")}get isBase64(){return!!this._def.checks.find(t=>t.kind==="base64")}get isBase64url(){return!!this._def.checks.find(t=>t.kind==="base64url")}get minLength(){let t=null;for(let r of this._def.checks)r.kind==="min"&&(t===null||r.value>t)&&(t=r.value);return t}get maxLength(){let t=null;for(let r of this._def.checks)r.kind==="max"&&(t===null||r.value<t)&&(t=r.value);return t}};Ae.create=e=>new Ae({checks:[],typeName:C.ZodString,coerce:e?.coerce??!1,...k(e)});function Ga(e,t){let r=(e.toString().split(".")[1]||"").length,n=(t.toString().split(".")[1]||"").length,s=r>n?r:n,o=Number.parseInt(e.toFixed(s).replace(".","")),a=Number.parseInt(t.toFixed(s).replace(".",""));return o%a/10**s}var Re=class e extends R{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==b.number){let o=this._getOrReturnCtx(t);return x(o,{code:y.invalid_type,expected:b.number,received:o.parsedType}),N}let n,s=new W;for(let o of this._def.checks)o.kind==="int"?P.isInteger(t.data)||(n=this._getOrReturnCtx(t,n),x(n,{code:y.invalid_type,expected:"integer",received:"float",message:o.message}),s.dirty()):o.kind==="min"?(o.inclusive?t.data<o.value:t.data<=o.value)&&(n=this._getOrReturnCtx(t,n),x(n,{code:y.too_small,minimum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),s.dirty()):o.kind==="max"?(o.inclusive?t.data>o.value:t.data>=o.value)&&(n=this._getOrReturnCtx(t,n),x(n,{code:y.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),s.dirty()):o.kind==="multipleOf"?Ga(t.data,o.value)!==0&&(n=this._getOrReturnCtx(t,n),x(n,{code:y.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):o.kind==="finite"?Number.isFinite(t.data)||(n=this._getOrReturnCtx(t,n),x(n,{code:y.not_finite,message:o.message}),s.dirty()):P.assertNever(o);return{status:s.value,value:t.data}}gte(t,r){return this.setLimit("min",t,!0,T.toString(r))}gt(t,r){return this.setLimit("min",t,!1,T.toString(r))}lte(t,r){return this.setLimit("max",t,!0,T.toString(r))}lt(t,r){return this.setLimit("max",t,!1,T.toString(r))}setLimit(t,r,n,s){return new e({...this._def,checks:[...this._def.checks,{kind:t,value:r,inclusive:n,message:T.toString(s)}]})}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:T.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:T.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:T.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:T.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:T.toString(t)})}multipleOf(t,r){return this._addCheck({kind:"multipleOf",value:t,message:T.toString(r)})}finite(t){return this._addCheck({kind:"finite",message:T.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:T.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:T.toString(t)})}get minValue(){let t=null;for(let r of this._def.checks)r.kind==="min"&&(t===null||r.value>t)&&(t=r.value);return t}get maxValue(){let t=null;for(let r of this._def.checks)r.kind==="max"&&(t===null||r.value<t)&&(t=r.value);return t}get isInt(){return!!this._def.checks.find(t=>t.kind==="int"||t.kind==="multipleOf"&&P.isInteger(t.value))}get isFinite(){let t=null,r=null;for(let n of this._def.checks){if(n.kind==="finite"||n.kind==="int"||n.kind==="multipleOf")return!0;n.kind==="min"?(r===null||n.value>r)&&(r=n.value):n.kind==="max"&&(t===null||n.value<t)&&(t=n.value)}return Number.isFinite(r)&&Number.isFinite(t)}};Re.create=e=>new Re({checks:[],typeName:C.ZodNumber,coerce:e?.coerce||!1,...k(e)});var Me=class e extends R{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){if(this._def.coerce)try{t.data=BigInt(t.data)}catch{return this._getInvalidInput(t)}if(this._getType(t)!==b.bigint)return this._getInvalidInput(t);let n,s=new W;for(let o of this._def.checks)o.kind==="min"?(o.inclusive?t.data<o.value:t.data<=o.value)&&(n=this._getOrReturnCtx(t,n),x(n,{code:y.too_small,type:"bigint",minimum:o.value,inclusive:o.inclusive,message:o.message}),s.dirty()):o.kind==="max"?(o.inclusive?t.data>o.value:t.data>=o.value)&&(n=this._getOrReturnCtx(t,n),x(n,{code:y.too_big,type:"bigint",maximum:o.value,inclusive:o.inclusive,message:o.message}),s.dirty()):o.kind==="multipleOf"?t.data%o.value!==BigInt(0)&&(n=this._getOrReturnCtx(t,n),x(n,{code:y.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):P.assertNever(o);return{status:s.value,value:t.data}}_getInvalidInput(t){let r=this._getOrReturnCtx(t);return x(r,{code:y.invalid_type,expected:b.bigint,received:r.parsedType}),N}gte(t,r){return this.setLimit("min",t,!0,T.toString(r))}gt(t,r){return this.setLimit("min",t,!1,T.toString(r))}lte(t,r){return this.setLimit("max",t,!0,T.toString(r))}lt(t,r){return this.setLimit("max",t,!1,T.toString(r))}setLimit(t,r,n,s){return new e({...this._def,checks:[...this._def.checks,{kind:t,value:r,inclusive:n,message:T.toString(s)}]})}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:T.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:T.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:T.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:T.toString(t)})}multipleOf(t,r){return this._addCheck({kind:"multipleOf",value:t,message:T.toString(r)})}get minValue(){let t=null;for(let r of this._def.checks)r.kind==="min"&&(t===null||r.value>t)&&(t=r.value);return t}get maxValue(){let t=null;for(let r of this._def.checks)r.kind==="max"&&(t===null||r.value<t)&&(t=r.value);return t}};Me.create=e=>new Me({checks:[],typeName:C.ZodBigInt,coerce:e?.coerce??!1,...k(e)});var Pe=class extends R{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==b.boolean){let n=this._getOrReturnCtx(t);return x(n,{code:y.invalid_type,expected:b.boolean,received:n.parsedType}),N}return J(t.data)}};Pe.create=e=>new Pe({typeName:C.ZodBoolean,coerce:e?.coerce||!1,...k(e)});var Le=class e extends R{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==b.date){let o=this._getOrReturnCtx(t);return x(o,{code:y.invalid_type,expected:b.date,received:o.parsedType}),N}if(Number.isNaN(t.data.getTime())){let o=this._getOrReturnCtx(t);return x(o,{code:y.invalid_date}),N}let n=new W,s;for(let o of this._def.checks)o.kind==="min"?t.data.getTime()<o.value&&(s=this._getOrReturnCtx(t,s),x(s,{code:y.too_small,message:o.message,inclusive:!0,exact:!1,minimum:o.value,type:"date"}),n.dirty()):o.kind==="max"?t.data.getTime()>o.value&&(s=this._getOrReturnCtx(t,s),x(s,{code:y.too_big,message:o.message,inclusive:!0,exact:!1,maximum:o.value,type:"date"}),n.dirty()):P.assertNever(o);return{status:n.value,value:new Date(t.data.getTime())}}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}min(t,r){return this._addCheck({kind:"min",value:t.getTime(),message:T.toString(r)})}max(t,r){return this._addCheck({kind:"max",value:t.getTime(),message:T.toString(r)})}get minDate(){let t=null;for(let r of this._def.checks)r.kind==="min"&&(t===null||r.value>t)&&(t=r.value);return t!=null?new Date(t):null}get maxDate(){let t=null;for(let r of this._def.checks)r.kind==="max"&&(t===null||r.value<t)&&(t=r.value);return t!=null?new Date(t):null}};Le.create=e=>new Le({checks:[],coerce:e?.coerce||!1,typeName:C.ZodDate,...k(e)});var nt=class extends R{_parse(t){if(this._getType(t)!==b.symbol){let n=this._getOrReturnCtx(t);return x(n,{code:y.invalid_type,expected:b.symbol,received:n.parsedType}),N}return J(t.data)}};nt.create=e=>new nt({typeName:C.ZodSymbol,...k(e)});var De=class extends R{_parse(t){if(this._getType(t)!==b.undefined){let n=this._getOrReturnCtx(t);return x(n,{code:y.invalid_type,expected:b.undefined,received:n.parsedType}),N}return J(t.data)}};De.create=e=>new De({typeName:C.ZodUndefined,...k(e)});var Ue=class extends R{_parse(t){if(this._getType(t)!==b.null){let n=this._getOrReturnCtx(t);return x(n,{code:y.invalid_type,expected:b.null,received:n.parsedType}),N}return J(t.data)}};Ue.create=e=>new Ue({typeName:C.ZodNull,...k(e)});var Ne=class extends R{constructor(){super(...arguments),this._any=!0}_parse(t){return J(t.data)}};Ne.create=e=>new Ne({typeName:C.ZodAny,...k(e)});var xe=class extends R{constructor(){super(...arguments),this._unknown=!0}_parse(t){return J(t.data)}};xe.create=e=>new xe({typeName:C.ZodUnknown,...k(e)});var le=class extends R{_parse(t){let r=this._getOrReturnCtx(t);return x(r,{code:y.invalid_type,expected:b.never,received:r.parsedType}),N}};le.create=e=>new le({typeName:C.ZodNever,...k(e)});var ot=class extends R{_parse(t){if(this._getType(t)!==b.undefined){let n=this._getOrReturnCtx(t);return x(n,{code:y.invalid_type,expected:b.void,received:n.parsedType}),N}return J(t.data)}};ot.create=e=>new ot({typeName:C.ZodVoid,...k(e)});var be=class e extends R{_parse(t){let{ctx:r,status:n}=this._processInputParams(t),s=this._def;if(r.parsedType!==b.array)return x(r,{code:y.invalid_type,expected:b.array,received:r.parsedType}),N;if(s.exactLength!==null){let a=r.data.length>s.exactLength.value,l=r.data.length<s.exactLength.value;(a||l)&&(x(r,{code:a?y.too_big:y.too_small,minimum:l?s.exactLength.value:void 0,maximum:a?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),n.dirty())}if(s.minLength!==null&&r.data.length<s.minLength.value&&(x(r,{code:y.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),n.dirty()),s.maxLength!==null&&r.data.length>s.maxLength.value&&(x(r,{code:y.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),n.dirty()),r.common.async)return Promise.all([...r.data].map((a,l)=>s.type._parseAsync(new se(r,a,r.path,l)))).then(a=>W.mergeArray(n,a));let o=[...r.data].map((a,l)=>s.type._parseSync(new se(r,a,r.path,l)));return W.mergeArray(n,o)}get element(){return this._def.type}min(t,r){return new e({...this._def,minLength:{value:t,message:T.toString(r)}})}max(t,r){return new e({...this._def,maxLength:{value:t,message:T.toString(r)}})}length(t,r){return new e({...this._def,exactLength:{value:t,message:T.toString(r)}})}nonempty(t){return this.min(1,t)}};be.create=(e,t)=>new be({type:e,minLength:null,maxLength:null,exactLength:null,typeName:C.ZodArray,...k(t)});function rt(e){if(e instanceof te){let t={};for(let r in e.shape){let n=e.shape[r];t[r]=oe.create(rt(n))}return new te({...e._def,shape:()=>t})}else return e instanceof be?new be({...e._def,type:rt(e.element)}):e instanceof oe?oe.create(rt(e.unwrap())):e instanceof me?me.create(rt(e.unwrap())):e instanceof pe?pe.create(e.items.map(t=>rt(t))):e}var te=class e extends R{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let t=this._def.shape(),r=P.objectKeys(t);return this._cached={shape:t,keys:r},this._cached}_parse(t){if(this._getType(t)!==b.object){let c=this._getOrReturnCtx(t);return x(c,{code:y.invalid_type,expected:b.object,received:c.parsedType}),N}let{status:n,ctx:s}=this._processInputParams(t),{shape:o,keys:a}=this._getCached(),l=[];if(!(this._def.catchall instanceof le&&this._def.unknownKeys==="strip"))for(let c in s.data)a.includes(c)||l.push(c);let u=[];for(let c of a){let p=o[c],g=s.data[c];u.push({key:{status:"valid",value:c},value:p._parse(new se(s,g,s.path,c)),alwaysSet:c in s.data})}if(this._def.catchall instanceof le){let c=this._def.unknownKeys;if(c==="passthrough")for(let p of l)u.push({key:{status:"valid",value:p},value:{status:"valid",value:s.data[p]}});else if(c==="strict")l.length>0&&(x(s,{code:y.unrecognized_keys,keys:l}),n.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{let c=this._def.catchall;for(let p of l){let g=s.data[p];u.push({key:{status:"valid",value:p},value:c._parse(new se(s,g,s.path,p)),alwaysSet:p in s.data})}}return s.common.async?Promise.resolve().then(async()=>{let c=[];for(let p of u){let g=await p.key,w=await p.value;c.push({key:g,value:w,alwaysSet:p.alwaysSet})}return c}).then(c=>W.mergeObjectSync(n,c)):W.mergeObjectSync(n,u)}get shape(){return this._def.shape()}strict(t){return T.errToObj,new e({...this._def,unknownKeys:"strict",...t!==void 0?{errorMap:(r,n)=>{let s=this._def.errorMap?.(r,n).message??n.defaultError;return r.code==="unrecognized_keys"?{message:T.errToObj(t).message??s}:{message:s}}}:{}})}strip(){return new e({...this._def,unknownKeys:"strip"})}passthrough(){return new e({...this._def,unknownKeys:"passthrough"})}extend(t){return new e({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new e({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:C.ZodObject})}setKey(t,r){return this.augment({[t]:r})}catchall(t){return new e({...this._def,catchall:t})}pick(t){let r={};for(let n of P.objectKeys(t))t[n]&&this.shape[n]&&(r[n]=this.shape[n]);return new e({...this._def,shape:()=>r})}omit(t){let r={};for(let n of P.objectKeys(this.shape))t[n]||(r[n]=this.shape[n]);return new e({...this._def,shape:()=>r})}deepPartial(){return rt(this)}partial(t){let r={};for(let n of P.objectKeys(this.shape)){let s=this.shape[n];t&&!t[n]?r[n]=s:r[n]=s.optional()}return new e({...this._def,shape:()=>r})}required(t){let r={};for(let n of P.objectKeys(this.shape))if(t&&!t[n])r[n]=this.shape[n];else{let o=this.shape[n];for(;o instanceof oe;)o=o._def.innerType;r[n]=o}return new e({...this._def,shape:()=>r})}keyof(){return wo(P.objectKeys(this.shape))}};te.create=(e,t)=>new te({shape:()=>e,unknownKeys:"strip",catchall:le.create(),typeName:C.ZodObject,...k(t)});te.strictCreate=(e,t)=>new te({shape:()=>e,unknownKeys:"strict",catchall:le.create(),typeName:C.ZodObject,...k(t)});te.lazycreate=(e,t)=>new te({shape:e,unknownKeys:"strip",catchall:le.create(),typeName:C.ZodObject,...k(t)});var Ge=class extends R{_parse(t){let{ctx:r}=this._processInputParams(t),n=this._def.options;function s(o){for(let l of o)if(l.result.status==="valid")return l.result;for(let l of o)if(l.result.status==="dirty")return r.common.issues.push(...l.ctx.common.issues),l.result;let a=o.map(l=>new ee(l.ctx.common.issues));return x(r,{code:y.invalid_union,unionErrors:a}),N}if(r.common.async)return Promise.all(n.map(async o=>{let a={...r,common:{...r.common,issues:[]},parent:null};return{result:await o._parseAsync({data:r.data,path:r.path,parent:a}),ctx:a}})).then(s);{let o,a=[];for(let u of n){let c={...r,common:{...r.common,issues:[]},parent:null},p=u._parseSync({data:r.data,path:r.path,parent:c});if(p.status==="valid")return p;p.status==="dirty"&&!o&&(o={result:p,ctx:c}),c.common.issues.length&&a.push(c.common.issues)}if(o)return r.common.issues.push(...o.ctx.common.issues),o.result;let l=a.map(u=>new ee(u));return x(r,{code:y.invalid_union,unionErrors:l}),N}}get options(){return this._def.options}};Ge.create=(e,t)=>new Ge({options:e,typeName:C.ZodUnion,...k(t)});var _e=e=>e instanceof Ve?_e(e.schema):e instanceof ae?_e(e.innerType()):e instanceof He?[e.value]:e instanceof $e?e.options:e instanceof je?P.objectValues(e.enum):e instanceof Be?_e(e._def.innerType):e instanceof De?[void 0]:e instanceof Ue?[null]:e instanceof oe?[void 0,..._e(e.unwrap())]:e instanceof me?[null,..._e(e.unwrap())]:e instanceof yt||e instanceof Xe?_e(e.unwrap()):e instanceof ze?_e(e._def.innerType):[],Vt=class e extends R{_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==b.object)return x(r,{code:y.invalid_type,expected:b.object,received:r.parsedType}),N;let n=this.discriminator,s=r.data[n],o=this.optionsMap.get(s);return o?r.common.async?o._parseAsync({data:r.data,path:r.path,parent:r}):o._parseSync({data:r.data,path:r.path,parent:r}):(x(r,{code:y.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[n]}),N)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,r,n){let s=new Map;for(let o of r){let a=_e(o.shape[t]);if(!a.length)throw new Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(let l of a){if(s.has(l))throw new Error(`Discriminator property ${String(t)} has duplicate value ${String(l)}`);s.set(l,o)}}return new e({typeName:C.ZodDiscriminatedUnion,discriminator:t,options:r,optionsMap:s,...k(n)})}};function yn(e,t){let r=fe(e),n=fe(t);if(e===t)return{valid:!0,data:e};if(r===b.object&&n===b.object){let s=P.objectKeys(t),o=P.objectKeys(e).filter(l=>s.indexOf(l)!==-1),a={...e,...t};for(let l of o){let u=yn(e[l],t[l]);if(!u.valid)return{valid:!1};a[l]=u.data}return{valid:!0,data:a}}else if(r===b.array&&n===b.array){if(e.length!==t.length)return{valid:!1};let s=[];for(let o=0;o<e.length;o++){let a=e[o],l=t[o],u=yn(a,l);if(!u.valid)return{valid:!1};s.push(u.data)}return{valid:!0,data:s}}else return r===b.date&&n===b.date&&+e==+t?{valid:!0,data:e}:{valid:!1}}var Fe=class extends R{_parse(t){let{status:r,ctx:n}=this._processInputParams(t),s=(o,a)=>{if(Gt(o)||Gt(a))return N;let l=yn(o.value,a.value);return l.valid?((Ft(o)||Ft(a))&&r.dirty(),{status:r.value,value:l.data}):(x(n,{code:y.invalid_intersection_types}),N)};return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([o,a])=>s(o,a)):s(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}};Fe.create=(e,t,r)=>new Fe({left:e,right:t,typeName:C.ZodIntersection,...k(r)});var pe=class e extends R{_parse(t){let{status:r,ctx:n}=this._processInputParams(t);if(n.parsedType!==b.array)return x(n,{code:y.invalid_type,expected:b.array,received:n.parsedType}),N;if(n.data.length<this._def.items.length)return x(n,{code:y.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),N;!this._def.rest&&n.data.length>this._def.items.length&&(x(n,{code:y.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let o=[...n.data].map((a,l)=>{let u=this._def.items[l]||this._def.rest;return u?u._parse(new se(n,a,n.path,l)):null}).filter(a=>!!a);return n.common.async?Promise.all(o).then(a=>W.mergeArray(r,a)):W.mergeArray(r,o)}get items(){return this._def.items}rest(t){return new e({...this._def,rest:t})}};pe.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new pe({items:e,typeName:C.ZodTuple,rest:null,...k(t)})};var Ht=class e extends R{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){let{status:r,ctx:n}=this._processInputParams(t);if(n.parsedType!==b.object)return x(n,{code:y.invalid_type,expected:b.object,received:n.parsedType}),N;let s=[],o=this._def.keyType,a=this._def.valueType;for(let l in n.data)s.push({key:o._parse(new se(n,l,n.path,l)),value:a._parse(new se(n,n.data[l],n.path,l)),alwaysSet:l in n.data});return n.common.async?W.mergeObjectAsync(r,s):W.mergeObjectSync(r,s)}get element(){return this._def.valueType}static create(t,r,n){return r instanceof R?new e({keyType:t,valueType:r,typeName:C.ZodRecord,...k(n)}):new e({keyType:Ae.create(),valueType:t,typeName:C.ZodRecord,...k(r)})}},st=class extends R{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){let{status:r,ctx:n}=this._processInputParams(t);if(n.parsedType!==b.map)return x(n,{code:y.invalid_type,expected:b.map,received:n.parsedType}),N;let s=this._def.keyType,o=this._def.valueType,a=[...n.data.entries()].map(([l,u],c)=>({key:s._parse(new se(n,l,n.path,[c,"key"])),value:o._parse(new se(n,u,n.path,[c,"value"]))}));if(n.common.async){let l=new Map;return Promise.resolve().then(async()=>{for(let u of a){let c=await u.key,p=await u.value;if(c.status==="aborted"||p.status==="aborted")return N;(c.status==="dirty"||p.status==="dirty")&&r.dirty(),l.set(c.value,p.value)}return{status:r.value,value:l}})}else{let l=new Map;for(let u of a){let c=u.key,p=u.value;if(c.status==="aborted"||p.status==="aborted")return N;(c.status==="dirty"||p.status==="dirty")&&r.dirty(),l.set(c.value,p.value)}return{status:r.value,value:l}}}};st.create=(e,t,r)=>new st({valueType:t,keyType:e,typeName:C.ZodMap,...k(r)});var at=class e extends R{_parse(t){let{status:r,ctx:n}=this._processInputParams(t);if(n.parsedType!==b.set)return x(n,{code:y.invalid_type,expected:b.set,received:n.parsedType}),N;let s=this._def;s.minSize!==null&&n.data.size<s.minSize.value&&(x(n,{code:y.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),r.dirty()),s.maxSize!==null&&n.data.size>s.maxSize.value&&(x(n,{code:y.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),r.dirty());let o=this._def.valueType;function a(u){let c=new Set;for(let p of u){if(p.status==="aborted")return N;p.status==="dirty"&&r.dirty(),c.add(p.value)}return{status:r.value,value:c}}let l=[...n.data.values()].map((u,c)=>o._parse(new se(n,u,n.path,c)));return n.common.async?Promise.all(l).then(u=>a(u)):a(l)}min(t,r){return new e({...this._def,minSize:{value:t,message:T.toString(r)}})}max(t,r){return new e({...this._def,maxSize:{value:t,message:T.toString(r)}})}size(t,r){return this.min(t,r).max(t,r)}nonempty(t){return this.min(1,t)}};at.create=(e,t)=>new at({valueType:e,minSize:null,maxSize:null,typeName:C.ZodSet,...k(t)});var $t=class e extends R{constructor(){super(...arguments),this.validate=this.implement}_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==b.function)return x(r,{code:y.invalid_type,expected:b.function,received:r.parsedType}),N;function n(l,u){return vt({data:l,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,et(),Ee].filter(c=>!!c),issueData:{code:y.invalid_arguments,argumentsError:u}})}function s(l,u){return vt({data:l,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,et(),Ee].filter(c=>!!c),issueData:{code:y.invalid_return_type,returnTypeError:u}})}let o={errorMap:r.common.contextualErrorMap},a=r.data;if(this._def.returns instanceof Ce){let l=this;return J(async function(...u){let c=new ee([]),p=await l._def.args.parseAsync(u,o).catch(d=>{throw c.addIssue(n(u,d)),c}),g=await Reflect.apply(a,this,p);return await l._def.returns._def.type.parseAsync(g,o).catch(d=>{throw c.addIssue(s(g,d)),c})})}else{let l=this;return J(function(...u){let c=l._def.args.safeParse(u,o);if(!c.success)throw new ee([n(u,c.error)]);let p=Reflect.apply(a,this,c.data),g=l._def.returns.safeParse(p,o);if(!g.success)throw new ee([s(p,g.error)]);return g.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new e({...this._def,args:pe.create(t).rest(xe.create())})}returns(t){return new e({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,r,n){return new e({args:t||pe.create([]).rest(xe.create()),returns:r||xe.create(),typeName:C.ZodFunction,...k(n)})}},Ve=class extends R{get schema(){return this._def.getter()}_parse(t){let{ctx:r}=this._processInputParams(t);return this._def.getter()._parse({data:r.data,path:r.path,parent:r})}};Ve.create=(e,t)=>new Ve({getter:e,typeName:C.ZodLazy,...k(t)});var He=class extends R{_parse(t){if(t.data!==this._def.value){let r=this._getOrReturnCtx(t);return x(r,{received:r.data,code:y.invalid_literal,expected:this._def.value}),N}return{status:"valid",value:t.data}}get value(){return this._def.value}};He.create=(e,t)=>new He({value:e,typeName:C.ZodLiteral,...k(t)});function wo(e,t){return new $e({values:e,typeName:C.ZodEnum,...k(t)})}var $e=class e extends R{_parse(t){if(typeof t.data!="string"){let r=this._getOrReturnCtx(t),n=this._def.values;return x(r,{expected:P.joinValues(n),received:r.parsedType,code:y.invalid_type}),N}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(t.data)){let r=this._getOrReturnCtx(t),n=this._def.values;return x(r,{received:r.data,code:y.invalid_enum_value,options:n}),N}return J(t.data)}get options(){return this._def.values}get enum(){let t={};for(let r of this._def.values)t[r]=r;return t}get Values(){let t={};for(let r of this._def.values)t[r]=r;return t}get Enum(){let t={};for(let r of this._def.values)t[r]=r;return t}extract(t,r=this._def){return e.create(t,{...this._def,...r})}exclude(t,r=this._def){return e.create(this.options.filter(n=>!t.includes(n)),{...this._def,...r})}};$e.create=wo;var je=class extends R{_parse(t){let r=P.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(t);if(n.parsedType!==b.string&&n.parsedType!==b.number){let s=P.objectValues(r);return x(n,{expected:P.joinValues(s),received:n.parsedType,code:y.invalid_type}),N}if(this._cache||(this._cache=new Set(P.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){let s=P.objectValues(r);return x(n,{received:n.data,code:y.invalid_enum_value,options:s}),N}return J(t.data)}get enum(){return this._def.values}};je.create=(e,t)=>new je({values:e,typeName:C.ZodNativeEnum,...k(t)});var Ce=class extends R{unwrap(){return this._def.type}_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==b.promise&&r.common.async===!1)return x(r,{code:y.invalid_type,expected:b.promise,received:r.parsedType}),N;let n=r.parsedType===b.promise?r.data:Promise.resolve(r.data);return J(n.then(s=>this._def.type.parseAsync(s,{path:r.path,errorMap:r.common.contextualErrorMap})))}};Ce.create=(e,t)=>new Ce({type:e,typeName:C.ZodPromise,...k(t)});var ae=class extends R{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===C.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){let{status:r,ctx:n}=this._processInputParams(t),s=this._def.effect||null,o={addIssue:a=>{x(n,a),a.fatal?r.abort():r.dirty()},get path(){return n.path}};if(o.addIssue=o.addIssue.bind(o),s.type==="preprocess"){let a=s.transform(n.data,o);if(n.common.async)return Promise.resolve(a).then(async l=>{if(r.value==="aborted")return N;let u=await this._def.schema._parseAsync({data:l,path:n.path,parent:n});return u.status==="aborted"?N:u.status==="dirty"?Oe(u.value):r.value==="dirty"?Oe(u.value):u});{if(r.value==="aborted")return N;let l=this._def.schema._parseSync({data:a,path:n.path,parent:n});return l.status==="aborted"?N:l.status==="dirty"?Oe(l.value):r.value==="dirty"?Oe(l.value):l}}if(s.type==="refinement"){let a=l=>{let u=s.refinement(l,o);if(n.common.async)return Promise.resolve(u);if(u instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return l};if(n.common.async===!1){let l=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return l.status==="aborted"?N:(l.status==="dirty"&&r.dirty(),a(l.value),{status:r.value,value:l.value})}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(l=>l.status==="aborted"?N:(l.status==="dirty"&&r.dirty(),a(l.value).then(()=>({status:r.value,value:l.value}))))}if(s.type==="transform")if(n.common.async===!1){let a=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!Ie(a))return N;let l=s.transform(a.value,o);if(l instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:l}}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(a=>Ie(a)?Promise.resolve(s.transform(a.value,o)).then(l=>({status:r.value,value:l})):N);P.assertNever(s)}};ae.create=(e,t,r)=>new ae({schema:e,typeName:C.ZodEffects,effect:t,...k(r)});ae.createWithPreprocess=(e,t,r)=>new ae({schema:t,effect:{type:"preprocess",transform:e},typeName:C.ZodEffects,...k(r)});var oe=class extends R{_parse(t){return this._getType(t)===b.undefined?J(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}};oe.create=(e,t)=>new oe({innerType:e,typeName:C.ZodOptional,...k(t)});var me=class extends R{_parse(t){return this._getType(t)===b.null?J(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}};me.create=(e,t)=>new me({innerType:e,typeName:C.ZodNullable,...k(t)});var Be=class extends R{_parse(t){let{ctx:r}=this._processInputParams(t),n=r.data;return r.parsedType===b.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:r.path,parent:r})}removeDefault(){return this._def.innerType}};Be.create=(e,t)=>new Be({innerType:e,typeName:C.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...k(t)});var ze=class extends R{_parse(t){let{ctx:r}=this._processInputParams(t),n={...r,common:{...r.common,issues:[]}},s=this._def.innerType._parse({data:n.data,path:n.path,parent:{...n}});return tt(s)?s.then(o=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new ee(n.common.issues)},input:n.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new ee(n.common.issues)},input:n.data})}}removeCatch(){return this._def.innerType}};ze.create=(e,t)=>new ze({innerType:e,typeName:C.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...k(t)});var it=class extends R{_parse(t){if(this._getType(t)!==b.nan){let n=this._getOrReturnCtx(t);return x(n,{code:y.invalid_type,expected:b.nan,received:n.parsedType}),N}return{status:"valid",value:t.data}}};it.create=e=>new it({typeName:C.ZodNaN,...k(e)});var Fa=Symbol("zod_brand"),yt=class extends R{_parse(t){let{ctx:r}=this._processInputParams(t),n=r.data;return this._def.type._parse({data:n,path:r.path,parent:r})}unwrap(){return this._def.type}},Et=class e extends R{_parse(t){let{status:r,ctx:n}=this._processInputParams(t);if(n.common.async)return(async()=>{let o=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return o.status==="aborted"?N:o.status==="dirty"?(r.dirty(),Oe(o.value)):this._def.out._parseAsync({data:o.value,path:n.path,parent:n})})();{let s=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return s.status==="aborted"?N:s.status==="dirty"?(r.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:n.path,parent:n})}}static create(t,r){return new e({in:t,out:r,typeName:C.ZodPipeline})}},Xe=class extends R{_parse(t){let r=this._def.innerType._parse(t),n=s=>(Ie(s)&&(s.value=Object.freeze(s.value)),s);return tt(r)?r.then(s=>n(s)):n(r)}unwrap(){return this._def.innerType}};Xe.create=(e,t)=>new Xe({innerType:e,typeName:C.ZodReadonly,...k(t)});function xo(e,t){let r=typeof e=="function"?e(t):typeof e=="string"?{message:e}:e;return typeof r=="string"?{message:r}:r}function Io(e,t={},r){return e?Ne.create().superRefine((n,s)=>{let o=e(n);if(o instanceof Promise)return o.then(a=>{if(!a){let l=xo(t,n),u=l.fatal??r??!0;s.addIssue({code:"custom",...l,fatal:u})}});if(!o){let a=xo(t,n),l=a.fatal??r??!0;s.addIssue({code:"custom",...a,fatal:l})}}):Ne.create()}var Va={object:te.lazycreate},C;(function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"})(C||(C={}));var Ha=(e,t={message:`Input not instance of ${e.name}`})=>Io(r=>r instanceof e,t),Ao=Ae.create,No=Re.create,$a=it.create,ja=Me.create,Co=Pe.create,Ba=Le.create,za=nt.create,Xa=De.create,Ka=Ue.create,Za=Ne.create,Wa=xe.create,Ya=le.create,qa=ot.create,Ja=be.create,Qa=te.create,ei=te.strictCreate,ti=Ge.create,ri=Vt.create,ni=Fe.create,oi=pe.create,si=Ht.create,ai=st.create,ii=at.create,li=$t.create,ui=Ve.create,ci=He.create,di=$e.create,fi=je.create,pi=Ce.create,mi=ae.create,hi=oe.create,gi=me.create,vi=ae.createWithPreprocess,yi=Et.create,Ei=()=>Ao().optional(),_i=()=>No().optional(),xi=()=>Co().optional(),bi={string:(e=>Ae.create({...e,coerce:!0})),number:(e=>Re.create({...e,coerce:!0})),boolean:(e=>Pe.create({...e,coerce:!0})),bigint:(e=>Me.create({...e,coerce:!0})),date:(e=>Le.create({...e,coerce:!0}))};var Si=N;var Ti=i.object({name:i.string(),arguments:i.string()}),wi=i.object({id:i.string(),type:i.literal("function"),function:Ti,encryptedValue:i.string().optional()}),jt=i.object({id:i.string(),role:i.string(),content:i.string().optional(),name:i.string().optional(),encryptedValue:i.string().optional()}),Ii=i.object({type:i.literal("text"),text:i.string()}),Ai=i.object({type:i.literal("data"),value:i.string(),mimeType:i.string()}),Ni=i.object({type:i.literal("url"),value:i.string(),mimeType:i.string().optional()}),Bt=i.discriminatedUnion("type",[Ai,Ni]),Ci=i.object({type:i.literal("image"),source:Bt,metadata:i.unknown().optional()}),ki=i.object({type:i.literal("audio"),source:Bt,metadata:i.unknown().optional()}),Oi=i.object({type:i.literal("video"),source:Bt,metadata:i.unknown().optional()}),Ri=i.object({type:i.literal("document"),source:Bt,metadata:i.unknown().optional()});var ko=i.object({type:i.literal("binary"),mimeType:i.string(),id:i.string().optional(),url:i.string().optional(),data:i.string().optional(),filename:i.string().optional()}),Oo=(e,t)=>{!e.id&&!e.url&&!e.data&&t.addIssue({code:i.ZodIssueCode.custom,message:"BinaryInputContent requires at least one of id, url, or data.",path:["id"]})},rd=ko.superRefine((e,t)=>{Oo(e,t)}),Mi=i.discriminatedUnion("type",[Ii,Ci,ki,Oi,Ri,ko]),Pi=Mi.superRefine((e,t)=>{e.type==="binary"&&Oo(e,t)}),Li=jt.extend({role:i.literal("developer"),content:i.string()}),Di=jt.extend({role:i.literal("system"),content:i.string()}),Ui=jt.extend({role:i.literal("assistant"),content:i.string().optional(),toolCalls:i.array(wi).optional()}),Gi=jt.extend({role:i.literal("user"),content:i.union([i.string(),i.array(Pi)])}),Fi=i.object({id:i.string(),content:i.string(),role:i.literal("tool"),toolCallId:i.string(),error:i.string().optional(),encryptedValue:i.string().optional()}),Vi=i.object({id:i.string(),role:i.literal("activity"),activityType:i.string(),content:i.record(i.any())}),Hi=i.object({id:i.string(),role:i.literal("reasoning"),content:i.string(),encryptedValue:i.string().optional()}),Ro=i.discriminatedUnion("role",[Li,Di,Ui,Gi,Fi,Vi,Hi]),nd=i.union([i.literal("developer"),i.literal("system"),i.literal("assistant"),i.literal("user"),i.literal("tool"),i.literal("activity"),i.literal("reasoning")]),$i=i.object({description:i.string(),value:i.string()}),Mo=i.object({name:i.string(),description:i.string(),parameters:i.any(),metadata:i.record(i.any()).optional()}),ji=i.object({id:i.string(),reason:i.string(),message:i.string().optional(),toolCallId:i.string().optional(),responseSchema:i.record(i.any()).optional(),expiresAt:i.string().optional(),metadata:i.record(i.any()).optional()}),Bi=i.object({interruptId:i.string(),status:i.enum(["resolved","cancelled"]),payload:i.any().optional()}),zi=i.object({threadId:i.string(),runId:i.string(),parentRunId:i.string().optional(),state:i.any(),messages:i.array(Ro),tools:i.array(Mo),context:i.array($i),forwardedProps:i.any(),resume:i.array(Bi).optional()}),Xi=i.any(),V=class extends Error{constructor(e){super(e)}},En=class extends V{constructor(){super("Connect not implemented. This method is not supported by the current agent.")}},Ki=i.object({name:i.string(),description:i.string().optional()}),Zi=i.object({name:i.string().optional(),type:i.string().optional(),description:i.string().optional(),version:i.string().optional(),provider:i.string().optional(),documentationUrl:i.string().optional(),metadata:i.record(i.unknown()).optional()}),Wi=i.object({streaming:i.boolean().optional(),websocket:i.boolean().optional(),httpBinary:i.boolean().optional(),pushNotifications:i.boolean().optional(),resumable:i.boolean().optional()}),Yi=i.object({supported:i.boolean().optional(),items:i.array(Mo).optional(),parallelCalls:i.boolean().optional(),clientProvided:i.boolean().optional()}),qi=i.object({structuredOutput:i.boolean().optional(),supportedMimeTypes:i.array(i.string()).optional()}),Ji=i.object({snapshots:i.boolean().optional(),deltas:i.boolean().optional(),memory:i.boolean().optional(),persistentState:i.boolean().optional()}),Qi=i.object({supported:i.boolean().optional(),delegation:i.boolean().optional(),handoffs:i.boolean().optional(),subAgents:i.array(Ki).optional()}),el=i.object({supported:i.boolean().optional(),streaming:i.boolean().optional(),encrypted:i.boolean().optional()}),tl=i.object({image:i.boolean().optional(),audio:i.boolean().optional(),video:i.boolean().optional(),pdf:i.boolean().optional(),file:i.boolean().optional()}),rl=i.object({image:i.boolean().optional(),audio:i.boolean().optional()}),nl=i.object({input:tl.optional(),output:rl.optional()}),ol=i.object({codeExecution:i.boolean().optional(),sandboxed:i.boolean().optional(),maxIterations:i.number().optional(),maxExecutionTime:i.number().optional()}),sl=i.object({supported:i.boolean().optional(),approvals:i.boolean().optional(),interventions:i.boolean().optional(),feedback:i.boolean().optional(),interrupts:i.boolean().optional(),approveWithEdits:i.boolean().optional()}),od=i.object({identity:Zi.optional(),transport:Wi.optional(),tools:Yi.optional(),output:qi.optional(),state:Ji.optional(),multiAgent:Qi.optional(),reasoning:el.optional(),multimodal:nl.optional(),execution:ol.optional(),humanInTheLoop:sl.optional(),custom:i.record(i.unknown()).optional()}),Po=i.union([i.literal("developer"),i.literal("system"),i.literal("assistant"),i.literal("user")]),h=(function(e){return e.TEXT_MESSAGE_START="TEXT_MESSAGE_START",e.TEXT_MESSAGE_CONTENT="TEXT_MESSAGE_CONTENT",e.TEXT_MESSAGE_END="TEXT_MESSAGE_END",e.TEXT_MESSAGE_CHUNK="TEXT_MESSAGE_CHUNK",e.TOOL_CALL_START="TOOL_CALL_START",e.TOOL_CALL_ARGS="TOOL_CALL_ARGS",e.TOOL_CALL_END="TOOL_CALL_END",e.TOOL_CALL_CHUNK="TOOL_CALL_CHUNK",e.TOOL_CALL_RESULT="TOOL_CALL_RESULT",e.THINKING_START="THINKING_START",e.THINKING_END="THINKING_END",e.THINKING_TEXT_MESSAGE_START="THINKING_TEXT_MESSAGE_START",e.THINKING_TEXT_MESSAGE_CONTENT="THINKING_TEXT_MESSAGE_CONTENT",e.THINKING_TEXT_MESSAGE_END="THINKING_TEXT_MESSAGE_END",e.STATE_SNAPSHOT="STATE_SNAPSHOT",e.STATE_DELTA="STATE_DELTA",e.MESSAGES_SNAPSHOT="MESSAGES_SNAPSHOT",e.ACTIVITY_SNAPSHOT="ACTIVITY_SNAPSHOT",e.ACTIVITY_DELTA="ACTIVITY_DELTA",e.RAW="RAW",e.CUSTOM="CUSTOM",e.RUN_STARTED="RUN_STARTED",e.RUN_FINISHED="RUN_FINISHED",e.RUN_ERROR="RUN_ERROR",e.STEP_STARTED="STEP_STARTED",e.STEP_FINISHED="STEP_FINISHED",e.REASONING_START="REASONING_START",e.REASONING_MESSAGE_START="REASONING_MESSAGE_START",e.REASONING_MESSAGE_CONTENT="REASONING_MESSAGE_CONTENT",e.REASONING_MESSAGE_END="REASONING_MESSAGE_END",e.REASONING_MESSAGE_CHUNK="REASONING_MESSAGE_CHUNK",e.REASONING_END="REASONING_END",e.REASONING_ENCRYPTED_VALUE="REASONING_ENCRYPTED_VALUE",e})({}),U=i.object({type:i.nativeEnum(h),timestamp:i.number().optional(),rawEvent:i.any().optional()}).passthrough(),al=U.extend({type:i.literal(h.TEXT_MESSAGE_START),messageId:i.string(),role:Po.default("assistant"),name:i.string().optional()}),Lo=U.extend({type:i.literal(h.TEXT_MESSAGE_CONTENT),messageId:i.string(),delta:i.string()}),il=U.extend({type:i.literal(h.TEXT_MESSAGE_END),messageId:i.string()}),ll=U.extend({type:i.literal(h.TEXT_MESSAGE_CHUNK),messageId:i.string().optional(),role:Po.optional(),delta:i.string().optional(),name:i.string().optional()}),ul=U.extend({type:i.literal(h.THINKING_TEXT_MESSAGE_START)}),cl=Lo.omit({messageId:!0,type:!0}).extend({type:i.literal(h.THINKING_TEXT_MESSAGE_CONTENT)}),dl=U.extend({type:i.literal(h.THINKING_TEXT_MESSAGE_END)}),fl=U.extend({type:i.literal(h.TOOL_CALL_START),toolCallId:i.string(),toolCallName:i.string(),parentMessageId:i.string().optional()}),pl=U.extend({type:i.literal(h.TOOL_CALL_ARGS),toolCallId:i.string(),delta:i.string()}),ml=U.extend({type:i.literal(h.TOOL_CALL_END),toolCallId:i.string()}),hl=U.extend({messageId:i.string(),type:i.literal(h.TOOL_CALL_RESULT),toolCallId:i.string(),content:i.string(),role:i.literal("tool").optional()}),gl=U.extend({type:i.literal(h.TOOL_CALL_CHUNK),toolCallId:i.string().optional(),toolCallName:i.string().optional(),parentMessageId:i.string().optional(),delta:i.string().optional()}),vl=U.extend({type:i.literal(h.THINKING_START),title:i.string().optional()}),yl=U.extend({type:i.literal(h.THINKING_END)}),El=U.extend({type:i.literal(h.STATE_SNAPSHOT),snapshot:Xi}),_l=U.extend({type:i.literal(h.STATE_DELTA),delta:i.array(i.any())}),xl=U.extend({type:i.literal(h.MESSAGES_SNAPSHOT),messages:i.array(Ro)}),bl=U.extend({type:i.literal(h.ACTIVITY_SNAPSHOT),messageId:i.string(),activityType:i.string(),content:i.record(i.any()),replace:i.boolean().optional().default(!0)}),Sl=U.extend({type:i.literal(h.ACTIVITY_DELTA),messageId:i.string(),activityType:i.string(),patch:i.array(i.any())}),Tl=U.extend({type:i.literal(h.RAW),event:i.any(),source:i.string().optional()}),wl=U.extend({type:i.literal(h.CUSTOM),name:i.string(),value:i.any()}),Il=U.extend({type:i.literal(h.RUN_STARTED),threadId:i.string(),runId:i.string(),parentRunId:i.string().optional(),input:zi.optional()}),Al=i.object({type:i.literal("success")}).strict(),Nl=i.object({type:i.literal("interrupt"),interrupts:i.array(ji).min(1)}).strict(),Cl=i.discriminatedUnion("type",[Al,Nl]),kl=U.extend({type:i.literal(h.RUN_FINISHED),threadId:i.string(),runId:i.string(),result:i.any().optional(),outcome:Cl.nullable().optional().transform(e=>e??void 0)}),Ol=U.extend({type:i.literal(h.RUN_ERROR),message:i.string(),code:i.string().optional()}),Rl=U.extend({type:i.literal(h.STEP_STARTED),stepName:i.string()}),Ml=U.extend({type:i.literal(h.STEP_FINISHED),stepName:i.string()}),Pl=i.union([i.literal("tool-call"),i.literal("message")]),Ll=U.extend({type:i.literal(h.REASONING_START),messageId:i.string()}),Dl=U.extend({type:i.literal(h.REASONING_MESSAGE_START),messageId:i.string(),role:i.literal("reasoning")}),Ul=U.extend({type:i.literal(h.REASONING_MESSAGE_CONTENT),messageId:i.string(),delta:i.string()}),Gl=U.extend({type:i.literal(h.REASONING_MESSAGE_END),messageId:i.string()}),Fl=U.extend({type:i.literal(h.REASONING_MESSAGE_CHUNK),messageId:i.string().optional(),delta:i.string().optional()}),Vl=U.extend({type:i.literal(h.REASONING_END),messageId:i.string()}),Hl=U.extend({type:i.literal(h.REASONING_ENCRYPTED_VALUE),subtype:Pl,entityId:i.string(),encryptedValue:i.string()}),zt=i.discriminatedUnion("type",[al,Lo,il,ll,vl,yl,ul,cl,dl,fl,pl,ml,gl,hl,El,_l,xl,bl,Sl,Tl,wl,Il,kl,Ol,Rl,Ml,Ll,Dl,Ul,Gl,Fl,Vl,Hl]);var _n={};fn(_n,{JsonPatchError:()=>B,_areEquals:()=>bt,applyOperation:()=>Ke,applyPatch:()=>Jt,applyReducer:()=>Xl,deepClone:()=>Bl,getValueByPointer:()=>Yt,validate:()=>Uo,validator:()=>qt});var $l=(function(){var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,s){n.__proto__=s}||function(n,s){for(var o in s)s.hasOwnProperty(o)&&(n[o]=s[o])},e(t,r)};return function(t,r){e(t,r);function n(){this.constructor=t}t.prototype=r===null?Object.create(r):(n.prototype=r.prototype,new n)}})(),jl=Object.prototype.hasOwnProperty;function Kt(e,t){return jl.call(e,t)}function Zt(e){if(Array.isArray(e)){for(var t=new Array(e.length),r=0;r<t.length;r++)t[r]=""+r;return t}if(Object.keys)return Object.keys(e);var n=[];for(var s in e)Kt(e,s)&&n.push(s);return n}function Y(e){switch(typeof e){case"object":return JSON.parse(JSON.stringify(e));case"undefined":return null;default:return e}}function Wt(e){for(var t=0,r=e.length,n;t<r;){if(n=e.charCodeAt(t),n>=48&&n<=57){t++;continue}return!1}return!0}function he(e){return e.indexOf("/")===-1&&e.indexOf("~")===-1?e:e.replace(/~/g,"~0").replace(/\//g,"~1")}function _t(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Xt(e){if(e===void 0)return!0;if(e){if(Array.isArray(e)){for(var t=0,r=e.length;t<r;t++)if(Xt(e[t]))return!0}else if(typeof e=="object"){for(var n=Zt(e),s=n.length,o=0;o<s;o++)if(Xt(e[n[o]]))return!0}}return!1}function Do(e,t){var r=[e];for(var n in t){var s=typeof t[n]=="object"?JSON.stringify(t[n],null,2):t[n];typeof s<"u"&&r.push(n+": "+s)}return r.join(`
2
- `)}var xt=(function(e){$l(t,e);function t(r,n,s,o,a){var l=this.constructor,u=e.call(this,Do(r,{name:n,index:s,operation:o,tree:a}))||this;return u.name=n,u.index=s,u.operation=o,u.tree=a,Object.setPrototypeOf(u,l.prototype),u.message=Do(r,{name:n,index:s,operation:o,tree:a}),u}return t})(Error);var B=xt,Bl=Y,lt={add:function(e,t,r){return e[t]=this.value,{newDocument:r}},remove:function(e,t,r){var n=e[t];return delete e[t],{newDocument:r,removed:n}},replace:function(e,t,r){var n=e[t];return e[t]=this.value,{newDocument:r,removed:n}},move:function(e,t,r){var n=Yt(r,this.path);n&&(n=Y(n));var s=Ke(r,{op:"remove",path:this.from}).removed;return Ke(r,{op:"add",path:this.path,value:s}),{newDocument:r,removed:n}},copy:function(e,t,r){var n=Yt(r,this.from);return Ke(r,{op:"add",path:this.path,value:Y(n)}),{newDocument:r}},test:function(e,t,r){return{newDocument:r,test:bt(e[t],this.value)}},_get:function(e,t,r){return this.value=e[t],{newDocument:r}}},zl={add:function(e,t,r){return Wt(t)?e.splice(t,0,this.value):e[t]=this.value,{newDocument:r,index:t}},remove:function(e,t,r){var n=e.splice(t,1);return{newDocument:r,removed:n[0]}},replace:function(e,t,r){var n=e[t];return e[t]=this.value,{newDocument:r,removed:n}},move:lt.move,copy:lt.copy,test:lt.test,_get:lt._get};function Yt(e,t){if(t=="")return e;var r={op:"_get",path:t};return Ke(e,r),r.value}function Ke(e,t,r,n,s,o){if(r===void 0&&(r=!1),n===void 0&&(n=!0),s===void 0&&(s=!0),o===void 0&&(o=0),r&&(typeof r=="function"?r(t,0,e,t.path):qt(t,0)),t.path===""){var a={newDocument:e};if(t.op==="add")return a.newDocument=t.value,a;if(t.op==="replace")return a.newDocument=t.value,a.removed=e,a;if(t.op==="move"||t.op==="copy")return a.newDocument=Yt(e,t.from),t.op==="move"&&(a.removed=e),a;if(t.op==="test"){if(a.test=bt(e,t.value),a.test===!1)throw new B("Test operation failed","TEST_OPERATION_FAILED",o,t,e);return a.newDocument=e,a}else{if(t.op==="remove")return a.removed=e,a.newDocument=null,a;if(t.op==="_get")return t.value=e,a;if(r)throw new B("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",o,t,e);return a}}else{n||(e=Y(e));var l=t.path||"",u=l.split("/"),c=e,p=1,g=u.length,w=void 0,d=void 0,f=void 0;for(typeof r=="function"?f=r:f=qt;;){if(d=u[p],d&&d.indexOf("~")!=-1&&(d=_t(d)),s&&(d=="__proto__"||d=="prototype"&&p>0&&u[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(r&&w===void 0&&(c[d]===void 0?w=u.slice(0,p).join("/"):p==g-1&&(w=t.path),w!==void 0&&f(t,0,e,w)),p++,Array.isArray(c)){if(d==="-")d=c.length;else{if(r&&!Wt(d))throw new B("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,t,e);Wt(d)&&(d=~~d)}if(p>=g){if(r&&t.op==="add"&&d>c.length)throw new B("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",o,t,e);var a=zl[t.op].call(t,c,d,e);if(a.test===!1)throw new B("Test operation failed","TEST_OPERATION_FAILED",o,t,e);return a}}else if(p>=g){var a=lt[t.op].call(t,c,d,e);if(a.test===!1)throw new B("Test operation failed","TEST_OPERATION_FAILED",o,t,e);return a}if(c=c[d],r&&p<g&&(!c||typeof c!="object"))throw new B("Cannot perform operation at the desired path","OPERATION_PATH_UNRESOLVABLE",o,t,e)}}}function Jt(e,t,r,n,s){if(n===void 0&&(n=!0),s===void 0&&(s=!0),r&&!Array.isArray(t))throw new B("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");n||(e=Y(e));for(var o=new Array(t.length),a=0,l=t.length;a<l;a++)o[a]=Ke(e,t[a],r,!0,s,a),e=o[a].newDocument;return o.newDocument=e,o}function Xl(e,t,r){var n=Ke(e,t);if(n.test===!1)throw new B("Test operation failed","TEST_OPERATION_FAILED",r,t,e);return n.newDocument}function qt(e,t,r,n){if(typeof e!="object"||e===null||Array.isArray(e))throw new B("Operation is not an object","OPERATION_NOT_AN_OBJECT",t,e,r);if(lt[e.op]){if(typeof e.path!="string")throw new B("Operation `path` property is not a string","OPERATION_PATH_INVALID",t,e,r);if(e.path.indexOf("/")!==0&&e.path.length>0)throw new B('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",t,e,r);if((e.op==="move"||e.op==="copy")&&typeof e.from!="string")throw new B("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",t,e,r);if((e.op==="add"||e.op==="replace"||e.op==="test")&&e.value===void 0)throw new B("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",t,e,r);if((e.op==="add"||e.op==="replace"||e.op==="test")&&Xt(e.value))throw new B("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",t,e,r);if(r){if(e.op=="add"){var s=e.path.split("/").length,o=n.split("/").length;if(s!==o+1&&s!==o)throw new B("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",t,e,r)}else if(e.op==="replace"||e.op==="remove"||e.op==="_get"){if(e.path!==n)throw new B("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",t,e,r)}else if(e.op==="move"||e.op==="copy"){var a={op:"_get",path:e.from,value:void 0},l=Uo([a],r);if(l&&l.name==="OPERATION_PATH_UNRESOLVABLE")throw new B("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",t,e,r)}}}else throw new B("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",t,e,r)}function Uo(e,t,r){try{if(!Array.isArray(e))throw new B("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(t)Jt(Y(t),Y(e),r||!0);else{r=r||qt;for(var n=0;n<e.length;n++)r(e[n],n,t,void 0)}}catch(s){if(s instanceof B)return s;throw s}}function bt(e,t){if(e===t)return!0;if(e&&t&&typeof e=="object"&&typeof t=="object"){var r=Array.isArray(e),n=Array.isArray(t),s,o,a;if(r&&n){if(o=e.length,o!=t.length)return!1;for(s=o;s--!==0;)if(!bt(e[s],t[s]))return!1;return!0}if(r!=n)return!1;var l=Object.keys(e);if(o=l.length,o!==Object.keys(t).length)return!1;for(s=o;s--!==0;)if(!t.hasOwnProperty(l[s]))return!1;for(s=o;s--!==0;)if(a=l[s],!bt(e[a],t[a]))return!1;return!0}return e!==e&&t!==t}var Tn={};fn(Tn,{compare:()=>eu,generate:()=>xn,observe:()=>Ql,unobserve:()=>Jl});var bn=new WeakMap,Kl=(function(){function e(t){this.observers=new Map,this.obj=t}return e})(),Zl=(function(){function e(t,r){this.callback=t,this.observer=r}return e})();function Wl(e){return bn.get(e)}function Yl(e,t){return e.observers.get(t)}function ql(e,t){e.observers.delete(t.callback)}function Jl(e,t){t.unobserve()}function Ql(e,t){var r=[],n,s=Wl(e);if(!s)s=new Kl(e),bn.set(e,s);else{var o=Yl(s,t);n=o&&o.observer}if(n)return n;if(n={},s.value=Y(e),t){n.callback=t,n.next=null;var a=function(){xn(n)},l=function(){clearTimeout(n.next),n.next=setTimeout(a)};typeof window<"u"&&(window.addEventListener("mouseup",l),window.addEventListener("keyup",l),window.addEventListener("mousedown",l),window.addEventListener("keydown",l),window.addEventListener("change",l))}return n.patches=r,n.object=e,n.unobserve=function(){xn(n),clearTimeout(n.next),ql(s,n),typeof window<"u"&&(window.removeEventListener("mouseup",l),window.removeEventListener("keyup",l),window.removeEventListener("mousedown",l),window.removeEventListener("keydown",l),window.removeEventListener("change",l))},s.observers.set(t,new Zl(t,n)),n}function xn(e,t){t===void 0&&(t=!1);var r=bn.get(e.object);Sn(r.value,e.object,e.patches,"",t),e.patches.length&&Jt(r.value,e.patches);var n=e.patches;return n.length>0&&(e.patches=[],e.callback&&e.callback(n)),n}function Sn(e,t,r,n,s){if(t!==e){typeof t.toJSON=="function"&&(t=t.toJSON());for(var o=Zt(t),a=Zt(e),l=!1,u=!1,c=a.length-1;c>=0;c--){var p=a[c],g=e[p];if(Kt(t,p)&&!(t[p]===void 0&&g!==void 0&&Array.isArray(t)===!1)){var w=t[p];typeof g=="object"&&g!=null&&typeof w=="object"&&w!=null&&Array.isArray(g)===Array.isArray(w)?Sn(g,w,r,n+"/"+he(p),s):g!==w&&(l=!0,s&&r.push({op:"test",path:n+"/"+he(p),value:Y(g)}),r.push({op:"replace",path:n+"/"+he(p),value:Y(w)}))}else Array.isArray(e)===Array.isArray(t)?(s&&r.push({op:"test",path:n+"/"+he(p),value:Y(g)}),r.push({op:"remove",path:n+"/"+he(p)}),u=!0):(s&&r.push({op:"test",path:n,value:e}),r.push({op:"replace",path:n,value:t}),l=!0)}if(!(!u&&o.length==a.length))for(var c=0;c<o.length;c++){var p=o[c];!Kt(e,p)&&t[p]!==void 0&&r.push({op:"add",path:n+"/"+he(p),value:Y(t[p])})}}}function eu(e,t,r){r===void 0&&(r=!1);var n=[];return Sn(e,t,n,"",r),n}var Qt=Object.assign({},_n,Tn,{JsonPatchError:xt,deepClone:Y,escapePathComponent:he,unescapePathComponent:_t});var wn=function(e,t){return wn=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(r[s]=n[s])},wn(e,t)};function ge(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");wn(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}function Go(e,t,r,n){function s(o){return o instanceof r?o:new r(function(a){a(o)})}return new(r||(r=Promise))(function(o,a){function l(p){try{c(n.next(p))}catch(g){a(g)}}function u(p){try{c(n.throw(p))}catch(g){a(g)}}function c(p){p.done?o(p.value):s(p.value).then(l,u)}c((n=n.apply(e,t||[])).next())})}function er(e,t){var r={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},n,s,o,a=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return a.next=l(0),a.throw=l(1),a.return=l(2),typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function l(c){return function(p){return u([c,p])}}function u(c){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(r=0)),r;)try{if(n=1,s&&(o=c[0]&2?s.return:c[0]?s.throw||((o=s.return)&&o.call(s),0):s.next)&&!(o=o.call(s,c[1])).done)return o;switch(s=0,o&&(c=[c[0]&2,o.value]),c[0]){case 0:case 1:o=c;break;case 4:return r.label++,{value:c[1],done:!1};case 5:r.label++,s=c[1],c=[0];continue;case 7:c=r.ops.pop(),r.trys.pop();continue;default:if(o=r.trys,!(o=o.length>0&&o[o.length-1])&&(c[0]===6||c[0]===2)){r=0;continue}if(c[0]===3&&(!o||c[1]>o[0]&&c[1]<o[3])){r.label=c[1];break}if(c[0]===6&&r.label<o[1]){r.label=o[1],o=c;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(c);break}o[2]&&r.ops.pop(),r.trys.pop();continue}c=t.call(e,r)}catch(p){c=[6,p],s=0}finally{n=o=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}function Se(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function ut(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var n=r.call(e),s,o=[],a;try{for(;(t===void 0||t-- >0)&&!(s=n.next()).done;)o.push(s.value)}catch(l){a={error:l}}finally{try{s&&!s.done&&(r=n.return)&&r.call(n)}finally{if(a)throw a.error}}return o}function ct(e,t,r){if(r||arguments.length===2)for(var n=0,s=t.length,o;n<s;n++)(o||!(n in t))&&(o||(o=Array.prototype.slice.call(t,0,n)),o[n]=t[n]);return e.concat(o||Array.prototype.slice.call(t))}function Ze(e){return this instanceof Ze?(this.v=e,this):new Ze(e)}function Fo(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),s,o=[];return s=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),l("next"),l("throw"),l("return",a),s[Symbol.asyncIterator]=function(){return this},s;function a(d){return function(f){return Promise.resolve(f).then(d,g)}}function l(d,f){n[d]&&(s[d]=function(m){return new Promise(function(E,S){o.push([d,m,E,S])>1||u(d,m)})},f&&(s[d]=f(s[d])))}function u(d,f){try{c(n[d](f))}catch(m){w(o[0][3],m)}}function c(d){d.value instanceof Ze?Promise.resolve(d.value.v).then(p,g):w(o[0][2],d)}function p(d){u("next",d)}function g(d){u("throw",d)}function w(d,f){d(f),o.shift(),o.length&&u(o[0][0],o[0][1])}}function Vo(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof Se=="function"?Se(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=e[o]&&function(a){return new Promise(function(l,u){a=e[o](a),s(l,u,a.done,a.value)})}}function s(o,a,l,u){Promise.resolve(u).then(function(c){o({value:c,done:l})},a)}}function M(e){return typeof e=="function"}function dt(e){var t=function(n){Error.call(n),n.stack=new Error().stack},r=e(t);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var tr=dt(function(e){return function(r){e(this),this.message=r?r.length+` errors occurred during unsubscription:
3
- `+r.map(function(n,s){return s+1+") "+n.toString()}).join(`
4
- `):"",this.name="UnsubscriptionError",this.errors=r}});function St(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var ft=(function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,r,n,s,o;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var l=Se(a),u=l.next();!u.done;u=l.next()){var c=u.value;c.remove(this)}}catch(m){t={error:m}}finally{try{u&&!u.done&&(r=l.return)&&r.call(l)}finally{if(t)throw t.error}}else a.remove(this);var p=this.initialTeardown;if(M(p))try{p()}catch(m){o=m instanceof tr?m.errors:[m]}var g=this._finalizers;if(g){this._finalizers=null;try{for(var w=Se(g),d=w.next();!d.done;d=w.next()){var f=d.value;try{Ho(f)}catch(m){o=o??[],m instanceof tr?o=ct(ct([],ut(o)),ut(m.errors)):o.push(m)}}}catch(m){n={error:m}}finally{try{d&&!d.done&&(s=w.return)&&s.call(w)}finally{if(n)throw n.error}}}if(o)throw new tr(o)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)Ho(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(t)}},e.prototype._hasParent=function(t){var r=this._parentage;return r===t||Array.isArray(r)&&r.includes(t)},e.prototype._addParent=function(t){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(t),r):r?[r,t]:t},e.prototype._removeParent=function(t){var r=this._parentage;r===t?this._parentage=null:Array.isArray(r)&&St(r,t)},e.prototype.remove=function(t){var r=this._finalizers;r&&St(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=(function(){var t=new e;return t.closed=!0,t})(),e})();var In=ft.EMPTY;function rr(e){return e instanceof ft||e&&"closed"in e&&M(e.remove)&&M(e.add)&&M(e.unsubscribe)}function Ho(e){M(e)?e():e.unsubscribe()}var ue={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var pt={setTimeout:function(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var s=pt.delegate;return s?.setTimeout?s.setTimeout.apply(s,ct([e,t],ut(r))):setTimeout.apply(void 0,ct([e,t],ut(r)))},clearTimeout:function(e){var t=pt.delegate;return(t?.clearTimeout||clearTimeout)(e)},delegate:void 0};function nr(e){pt.setTimeout(function(){var t=ue.onUnhandledError;if(t)t(e);else throw e})}function Tt(){}var $o=(function(){return An("C",void 0,void 0)})();function jo(e){return An("E",void 0,e)}function Bo(e){return An("N",e,void 0)}function An(e,t,r){return{kind:e,value:t,error:r}}var We=null;function mt(e){if(ue.useDeprecatedSynchronousErrorHandling){var t=!We;if(t&&(We={errorThrown:!1,error:null}),e(),t){var r=We,n=r.errorThrown,s=r.error;if(We=null,n)throw s}}else e()}function zo(e){ue.useDeprecatedSynchronousErrorHandling&&We&&(We.errorThrown=!0,We.error=e)}var wt=(function(e){ge(t,e);function t(r){var n=e.call(this)||this;return n.isStopped=!1,r?(n.destination=r,rr(r)&&r.add(n)):n.destination=ou,n}return t.create=function(r,n,s){return new sr(r,n,s)},t.prototype.next=function(r){this.isStopped?Cn(Bo(r),this):this._next(r)},t.prototype.error=function(r){this.isStopped?Cn(jo(r),this):(this.isStopped=!0,this._error(r))},t.prototype.complete=function(){this.isStopped?Cn($o,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(r){this.destination.next(r)},t.prototype._error=function(r){try{this.destination.error(r)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(ft);var tu=Function.prototype.bind;function Nn(e,t){return tu.call(e,t)}var ru=(function(){function e(t){this.partialObserver=t}return e.prototype.next=function(t){var r=this.partialObserver;if(r.next)try{r.next(t)}catch(n){or(n)}},e.prototype.error=function(t){var r=this.partialObserver;if(r.error)try{r.error(t)}catch(n){or(n)}else or(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(r){or(r)}},e})(),sr=(function(e){ge(t,e);function t(r,n,s){var o=e.call(this)||this,a;if(M(r)||!r)a={next:r??void 0,error:n??void 0,complete:s??void 0};else{var l;o&&ue.useDeprecatedNextContext?(l=Object.create(r),l.unsubscribe=function(){return o.unsubscribe()},a={next:r.next&&Nn(r.next,l),error:r.error&&Nn(r.error,l),complete:r.complete&&Nn(r.complete,l)}):a=r}return o.destination=new ru(a),o}return t})(wt);function or(e){ue.useDeprecatedSynchronousErrorHandling?zo(e):nr(e)}function nu(e){throw e}function Cn(e,t){var r=ue.onStoppedNotification;r&&pt.setTimeout(function(){return r(e,t)})}var ou={closed:!0,next:Tt,error:nu,complete:Tt};var ht=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function gt(e){return e}function ar(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return kn(e)}function kn(e){return e.length===0?gt:e.length===1?e[0]:function(r){return e.reduce(function(n,s){return s(n)},r)}}var H=(function(){function e(t){t&&(this._subscribe=t)}return e.prototype.lift=function(t){var r=new e;return r.source=this,r.operator=t,r},e.prototype.subscribe=function(t,r,n){var s=this,o=au(t)?t:new sr(t,r,n);return mt(function(){var a=s,l=a.operator,u=a.source;o.add(l?l.call(o,u):u?s._subscribe(o):s._trySubscribe(o))}),o},e.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(r){t.error(r)}},e.prototype.forEach=function(t,r){var n=this;return r=Xo(r),new r(function(s,o){var a=new sr({next:function(l){try{t(l)}catch(u){o(u),a.unsubscribe()}},error:o,complete:s});n.subscribe(a)})},e.prototype._subscribe=function(t){var r;return(r=this.source)===null||r===void 0?void 0:r.subscribe(t)},e.prototype[ht]=function(){return this},e.prototype.pipe=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return kn(t)(this)},e.prototype.toPromise=function(t){var r=this;return t=Xo(t),new t(function(n,s){var o;r.subscribe(function(a){return o=a},function(a){return s(a)},function(){return n(o)})})},e.create=function(t){return new e(t)},e})();function Xo(e){var t;return(t=e??ue.Promise)!==null&&t!==void 0?t:Promise}function su(e){return e&&M(e.next)&&M(e.error)&&M(e.complete)}function au(e){return e&&e instanceof wt||su(e)&&rr(e)}function iu(e){return M(e?.lift)}function z(e){return function(t){if(iu(t))return t.lift(function(r){try{return e(r,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function X(e,t,r,n,s){return new lu(e,t,r,n,s)}var lu=(function(e){ge(t,e);function t(r,n,s,o,a,l){var u=e.call(this,r)||this;return u.onFinalize=a,u.shouldUnsubscribe=l,u._next=n?function(c){try{n(c)}catch(p){r.error(p)}}:e.prototype._next,u._error=o?function(c){try{o(c)}catch(p){r.error(p)}finally{this.unsubscribe()}}:e.prototype._error,u._complete=s?function(){try{s()}catch(c){r.error(c)}finally{this.unsubscribe()}}:e.prototype._complete,u}return t.prototype.unsubscribe=function(){var r;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;e.prototype.unsubscribe.call(this),!n&&((r=this.onFinalize)===null||r===void 0||r.call(this))}},t})(wt);var Ko=dt(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}});var ve=(function(e){ge(t,e);function t(){var r=e.call(this)||this;return r.closed=!1,r.currentObservers=null,r.observers=[],r.isStopped=!1,r.hasError=!1,r.thrownError=null,r}return t.prototype.lift=function(r){var n=new Zo(this,this);return n.operator=r,n},t.prototype._throwIfClosed=function(){if(this.closed)throw new Ko},t.prototype.next=function(r){var n=this;mt(function(){var s,o;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var a=Se(n.currentObservers),l=a.next();!l.done;l=a.next()){var u=l.value;u.next(r)}}catch(c){s={error:c}}finally{try{l&&!l.done&&(o=a.return)&&o.call(a)}finally{if(s)throw s.error}}}})},t.prototype.error=function(r){var n=this;mt(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=r;for(var s=n.observers;s.length;)s.shift().error(r)}})},t.prototype.complete=function(){var r=this;mt(function(){if(r._throwIfClosed(),!r.isStopped){r.isStopped=!0;for(var n=r.observers;n.length;)n.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var r;return((r=this.observers)===null||r===void 0?void 0:r.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(r){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,r)},t.prototype._subscribe=function(r){return this._throwIfClosed(),this._checkFinalizedStatuses(r),this._innerSubscribe(r)},t.prototype._innerSubscribe=function(r){var n=this,s=this,o=s.hasError,a=s.isStopped,l=s.observers;return o||a?In:(this.currentObservers=null,l.push(r),new ft(function(){n.currentObservers=null,St(l,r)}))},t.prototype._checkFinalizedStatuses=function(r){var n=this,s=n.hasError,o=n.thrownError,a=n.isStopped;s?r.error(o):a&&r.complete()},t.prototype.asObservable=function(){var r=new H;return r.source=this,r},t.create=function(r,n){return new Zo(r,n)},t})(H);var Zo=(function(e){ge(t,e);function t(r,n){var s=e.call(this)||this;return s.destination=r,s.source=n,s}return t.prototype.next=function(r){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.next)===null||s===void 0||s.call(n,r)},t.prototype.error=function(r){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.error)===null||s===void 0||s.call(n,r)},t.prototype.complete=function(){var r,n;(n=(r=this.destination)===null||r===void 0?void 0:r.complete)===null||n===void 0||n.call(r)},t.prototype._subscribe=function(r){var n,s;return(s=(n=this.source)===null||n===void 0?void 0:n.subscribe(r))!==null&&s!==void 0?s:In},t})(ve);var On={now:function(){return(On.delegate||Date).now()},delegate:void 0};var ir=(function(e){ge(t,e);function t(r,n,s){r===void 0&&(r=1/0),n===void 0&&(n=1/0),s===void 0&&(s=On);var o=e.call(this)||this;return o._bufferSize=r,o._windowTime=n,o._timestampProvider=s,o._buffer=[],o._infiniteTimeWindow=!0,o._infiniteTimeWindow=n===1/0,o._bufferSize=Math.max(1,r),o._windowTime=Math.max(1,n),o}return t.prototype.next=function(r){var n=this,s=n.isStopped,o=n._buffer,a=n._infiniteTimeWindow,l=n._timestampProvider,u=n._windowTime;s||(o.push(r),!a&&o.push(l.now()+u)),this._trimBuffer(),e.prototype.next.call(this,r)},t.prototype._subscribe=function(r){this._throwIfClosed(),this._trimBuffer();for(var n=this._innerSubscribe(r),s=this,o=s._infiniteTimeWindow,a=s._buffer,l=a.slice(),u=0;u<l.length&&!r.closed;u+=o?1:2)r.next(l[u]);return this._checkFinalizedStatuses(r),n},t.prototype._trimBuffer=function(){var r=this,n=r._bufferSize,s=r._timestampProvider,o=r._buffer,a=r._infiniteTimeWindow,l=(a?1:2)*n;if(n<1/0&&l<o.length&&o.splice(0,o.length-l),!a){for(var u=s.now(),c=0,p=1;p<o.length&&o[p]<=u;p+=2)c=p;c&&o.splice(0,c+1)}},t})(ve);var lr=new H(function(e){return e.complete()});function Wo(e){return e&&M(e.schedule)}function uu(e){return e[e.length-1]}function Yo(e){return Wo(uu(e))?e.pop():void 0}var ur=(function(e){return e&&typeof e.length=="number"&&typeof e!="function"});function cr(e){return M(e?.then)}function dr(e){return M(e[ht])}function fr(e){return Symbol.asyncIterator&&M(e?.[Symbol.asyncIterator])}function pr(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function cu(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var mr=cu();function hr(e){return M(e?.[mr])}function gr(e){return Fo(this,arguments,function(){var r,n,s,o;return er(this,function(a){switch(a.label){case 0:r=e.getReader(),a.label=1;case 1:a.trys.push([1,,9,10]),a.label=2;case 2:return[4,Ze(r.read())];case 3:return n=a.sent(),s=n.value,o=n.done,o?[4,Ze(void 0)]:[3,5];case 4:return[2,a.sent()];case 5:return[4,Ze(s)];case 6:return[4,a.sent()];case 7:return a.sent(),[3,2];case 8:return[3,10];case 9:return r.releaseLock(),[7];case 10:return[2]}})})}function vr(e){return M(e?.getReader)}function K(e){if(e instanceof H)return e;if(e!=null){if(dr(e))return du(e);if(ur(e))return fu(e);if(cr(e))return pu(e);if(fr(e))return qo(e);if(hr(e))return mu(e);if(vr(e))return hu(e)}throw pr(e)}function du(e){return new H(function(t){var r=e[ht]();if(M(r.subscribe))return r.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function fu(e){return new H(function(t){for(var r=0;r<e.length&&!t.closed;r++)t.next(e[r]);t.complete()})}function pu(e){return new H(function(t){e.then(function(r){t.closed||(t.next(r),t.complete())},function(r){return t.error(r)}).then(null,nr)})}function mu(e){return new H(function(t){var r,n;try{for(var s=Se(e),o=s.next();!o.done;o=s.next()){var a=o.value;if(t.next(a),t.closed)return}}catch(l){r={error:l}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}t.complete()})}function qo(e){return new H(function(t){gu(e,t).catch(function(r){return t.error(r)})})}function hu(e){return qo(gr(e))}function gu(e,t){var r,n,s,o;return Go(this,void 0,void 0,function(){var a,l;return er(this,function(u){switch(u.label){case 0:u.trys.push([0,5,6,11]),r=Vo(e),u.label=1;case 1:return[4,r.next()];case 2:if(n=u.sent(),!!n.done)return[3,4];if(a=n.value,t.next(a),t.closed)return[2];u.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return l=u.sent(),s={error:l},[3,11];case 6:return u.trys.push([6,,9,10]),n&&!n.done&&(o=r.return)?[4,o.call(r)]:[3,8];case 7:u.sent(),u.label=8;case 8:return[3,10];case 9:if(s)throw s.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function ie(e,t,r,n,s){n===void 0&&(n=0),s===void 0&&(s=!1);var o=t.schedule(function(){r(),s?e.add(this.schedule(null,n)):this.unsubscribe()},n);if(e.add(o),!s)return o}function yr(e,t){return t===void 0&&(t=0),z(function(r,n){r.subscribe(X(n,function(s){return ie(n,e,function(){return n.next(s)},t)},function(){return ie(n,e,function(){return n.complete()},t)},function(s){return ie(n,e,function(){return n.error(s)},t)}))})}function Er(e,t){return t===void 0&&(t=0),z(function(r,n){n.add(e.schedule(function(){return r.subscribe(n)},t))})}function Jo(e,t){return K(e).pipe(Er(t),yr(t))}function Qo(e,t){return K(e).pipe(Er(t),yr(t))}function es(e,t){return new H(function(r){var n=0;return t.schedule(function(){n===e.length?r.complete():(r.next(e[n++]),r.closed||this.schedule())})})}function ts(e,t){return new H(function(r){var n;return ie(r,t,function(){n=e[mr](),ie(r,t,function(){var s,o,a;try{s=n.next(),o=s.value,a=s.done}catch(l){r.error(l);return}a?r.complete():r.next(o)},0,!0)}),function(){return M(n?.return)&&n.return()}})}function _r(e,t){if(!e)throw new Error("Iterable cannot be null");return new H(function(r){ie(r,t,function(){var n=e[Symbol.asyncIterator]();ie(r,t,function(){n.next().then(function(s){s.done?r.complete():r.next(s.value)})},0,!0)})})}function rs(e,t){return _r(gr(e),t)}function ns(e,t){if(e!=null){if(dr(e))return Jo(e,t);if(ur(e))return es(e,t);if(cr(e))return Qo(e,t);if(fr(e))return _r(e,t);if(hr(e))return ts(e,t);if(vr(e))return rs(e,t)}throw pr(e)}function Ye(e,t){return t?ns(e,t):K(e)}function j(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=Yo(e);return Ye(e,r)}function $(e,t){var r=M(e)?e:function(){return e},n=function(s){return s.error(r())};return new H(t?function(s){return t.schedule(n,0,s)}:n)}var os=dt(function(e){return function(){e(this),this.name="EmptyError",this.message="no elements in sequence"}});function xr(e,t){var r=typeof t=="object";return new Promise(function(n,s){var o=!1,a;e.subscribe({next:function(l){a=l,o=!0},error:s,complete:function(){o?n(a):r?n(t.defaultValue):s(new os)}})})}function qe(e,t){return z(function(r,n){var s=0;r.subscribe(X(n,function(o){n.next(e.call(t,o,s++))}))})}function ss(e,t,r,n,s,o,a,l){var u=[],c=0,p=0,g=!1,w=function(){g&&!u.length&&!c&&t.complete()},d=function(m){return c<n?f(m):u.push(m)},f=function(m){o&&t.next(m),c++;var E=!1;K(r(m,p++)).subscribe(X(t,function(S){s?.(S),o?d(S):t.next(S)},function(){E=!0},void 0,function(){if(E)try{c--;for(var S=function(){var v=u.shift();a?ie(t,a,function(){return f(v)}):f(v)};u.length&&c<n;)S();w()}catch(v){t.error(v)}}))};return e.subscribe(X(t,d,function(){g=!0,w()})),function(){l?.()}}function re(e,t,r){return r===void 0&&(r=1/0),M(t)?re(function(n,s){return qe(function(o,a){return t(n,o,s,a)})(K(e(n,s)))},r):(typeof t=="number"&&(r=t),z(function(n,s){return ss(n,s,e,r)}))}function Rn(e){return e===void 0&&(e=1/0),re(gt,e)}function br(e){return new H(function(t){K(e()).subscribe(t)})}function It(e){return z(function(t,r){var n=null,s=!1,o;n=t.subscribe(X(r,void 0,void 0,function(a){o=K(e(a,It(e)(t))),n?(n.unsubscribe(),n=null,o.subscribe(r)):s=!0})),s&&(n.unsubscribe(),n=null,o.subscribe(r))})}function Sr(e,t){return M(t)?re(e,t,1):re(e,1)}function Mn(e){return z(function(t,r){var n=!1;t.subscribe(X(r,function(s){n=!0,r.next(s)},function(){n||r.next(e),r.complete()}))})}function Je(e){return z(function(t,r){try{t.subscribe(r)}finally{r.add(e)}})}function Pn(e,t){return z(function(r,n){var s=null,o=0,a=!1,l=function(){return a&&!s&&n.complete()};r.subscribe(X(n,function(u){s?.unsubscribe();var c=0,p=o++;K(e(u,p)).subscribe(s=X(n,function(g){return n.next(t?t(u,g,p,c++):g)},function(){s=null,l()}))},function(){a=!0,l()}))})}function Tr(e){return z(function(t,r){K(e).subscribe(X(r,function(){return r.complete()},Tt)),!r.closed&&t.subscribe(r)})}function Ln(e,t,r){var n=M(e)||t||r?{next:e,error:t,complete:r}:e;return n?z(function(s,o){var a;(a=n.subscribe)===null||a===void 0||a.call(n);var l=!0;s.subscribe(X(o,function(u){var c;(c=n.next)===null||c===void 0||c.call(n,u),o.next(u)},function(){var u;l=!1,(u=n.complete)===null||u===void 0||u.call(n),o.complete()},function(u){var c;l=!1,(c=n.error)===null||c===void 0||c.call(n,u),o.error(u)},function(){var u,c;l&&((u=n.unsubscribe)===null||u===void 0||u.call(n)),(c=n.finalize)===null||c===void 0||c.call(n)}))}):gt}function as(e){return` \r
5
- `.indexOf(e)>=0}function wr(e){for(var t=["topLevel"],r=0,n,s,o,a=function(v){return t.push(v)},l=function(v){return t[t.length-1]=v},u=function(v){n==null&&(n=r,s=t.length,o=v)},c=function(v){v===o&&(n=void 0,s=void 0,o=void 0)},p=function(){return t.pop()},g=function(){return r--},w=function(v){if("0"<=v&&v<="9"){a("number");return}switch(v){case'"':a("string");return;case"-":a("numberNeedsDigit");return;case"t":a("true");return;case"f":a("false");return;case"n":a("null");return;case"[":a("arrayNeedsValue");return;case"{":a("objectNeedsKey");return}},d=e.length;r<d;r++){var f=e[r];switch(t[t.length-1]){case"topLevel":w(f);break;case"string":switch(f){case'"':p();break;case"\\":u("stringEscape"),a("stringEscaped");break}break;case"stringEscaped":f==="u"?a("stringUnicode"):(c("stringEscape"),p());break;case"stringUnicode":r-e.lastIndexOf("u",r)===4&&(c("stringEscape"),p());break;case"number":f==="."?l("numberNeedsDigit"):f==="e"||f==="E"?l("numberNeedsExponent"):(f<"0"||f>"9")&&(g(),p());break;case"numberNeedsDigit":l("number");break;case"numberNeedsExponent":l(f==="+"||f==="-"?"numberNeedsDigit":"number");break;case"true":case"false":case"null":(f<"a"||f>"z")&&(g(),p());break;case"arrayNeedsValue":f==="]"?p():as(f)||(c("collectionItem"),l("arrayNeedsComma"),w(f));break;case"arrayNeedsComma":f==="]"?p():f===","&&(u("collectionItem"),l("arrayNeedsValue"));break;case"objectNeedsKey":f==="}"?p():f==='"'&&(u("collectionItem"),l("objectNeedsColon"),a("string"));break;case"objectNeedsColon":f===":"&&l("objectNeedsValue");break;case"objectNeedsValue":as(f)||(c("collectionItem"),l("objectNeedsComma"),w(f));break;case"objectNeedsComma":f==="}"?p():f===","&&(u("collectionItem"),l("objectNeedsKey"));break}}s!=null&&(t.length=s);for(var m=[n!=null?e.slice(0,n):e],E=function(v){return m.push(v.slice(e.length-e.lastIndexOf(v[0])))},S=t.length-1;S>=0;S--)switch(t[S]){case"string":m.push('"');break;case"numberNeedsDigit":case"numberNeedsExponent":m.push("0");break;case"true":E("true");break;case"false":E("false");break;case"null":E("null");break;case"arrayNeedsValue":case"arrayNeedsComma":m.push("]");break;case"objectNeedsKey":case"objectNeedsColon":case"objectNeedsValue":case"objectNeedsComma":m.push("}");break}return m.join("")}function ls(){let e=0,t=0;for(let n=0;n<28;n+=7){let s=this.buf[this.pos++];if(e|=(s&127)<<n,(s&128)==0)return this.assertBounds(),[e,t]}let r=this.buf[this.pos++];if(e|=(r&15)<<28,t=(r&112)>>4,(r&128)==0)return this.assertBounds(),[e,t];for(let n=3;n<=31;n+=7){let s=this.buf[this.pos++];if(t|=(s&127)<<n,(s&128)==0)return this.assertBounds(),[e,t]}throw new Error("invalid varint")}function Ar(e,t,r){for(let o=0;o<28;o=o+7){let a=e>>>o,l=!(!(a>>>7)&&t==0),u=(l?a|128:a)&255;if(r.push(u),!l)return}let n=e>>>28&15|(t&7)<<4,s=t>>3!=0;if(r.push((s?n|128:n)&255),!!s){for(let o=3;o<31;o=o+7){let a=t>>>o,l=!!(a>>>7),u=(l?a|128:a)&255;if(r.push(u),!l)return}r.push(t>>>31&1)}}var Ir=4294967296;function Dn(e){let t=e[0]==="-";t&&(e=e.slice(1));let r=1e6,n=0,s=0;function o(a,l){let u=Number(e.slice(a,l));s*=r,n=n*r+u,n>=Ir&&(s=s+(n/Ir|0),n=n%Ir)}return o(-24,-18),o(-18,-12),o(-12,-6),o(-6),t?cs(n,s):Gn(n,s)}function us(e,t){let r=Gn(e,t),n=r.hi&2147483648;n&&(r=cs(r.lo,r.hi));let s=Un(r.lo,r.hi);return n?"-"+s:s}function Un(e,t){if({lo:e,hi:t}=vu(e,t),t<=2097151)return String(Ir*t+e);let r=e&16777215,n=(e>>>24|t<<8)&16777215,s=t>>16&65535,o=r+n*6777216+s*6710656,a=n+s*8147497,l=s*2,u=1e7;return o>=u&&(a+=Math.floor(o/u),o%=u),a>=u&&(l+=Math.floor(a/u),a%=u),l.toString()+is(a)+is(o)}function vu(e,t){return{lo:e>>>0,hi:t>>>0}}function Gn(e,t){return{lo:e|0,hi:t|0}}function cs(e,t){return t=~t,e?e=~e+1:t+=1,Gn(e,t)}var is=e=>{let t=String(e);return"0000000".slice(t.length)+t};function Fn(e,t){if(e>=0){for(;e>127;)t.push(e&127|128),e=e>>>7;t.push(e)}else{for(let r=0;r<9;r++)t.push(e&127|128),e=e>>7;t.push(1)}}function ds(){let e=this.buf[this.pos++],t=e&127;if((e&128)==0)return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(e&127)<<7,(e&128)==0)return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(e&127)<<14,(e&128)==0)return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(e&127)<<21,(e&128)==0)return this.assertBounds(),t;e=this.buf[this.pos++],t|=(e&15)<<28;for(let r=5;(e&128)!==0&&r<10;r++)e=this.buf[this.pos++];if((e&128)!=0)throw new Error("invalid varint");return this.assertBounds(),t>>>0}var ce=yu();function yu(){let e=new DataView(new ArrayBuffer(8));if(typeof BigInt=="function"&&typeof e.getBigInt64=="function"&&typeof e.getBigUint64=="function"&&typeof e.setBigInt64=="function"&&typeof e.setBigUint64=="function"&&(!!globalThis.Deno||typeof process!="object"||typeof process.env!="object"||process.env.BUF_BIGINT_DISABLE!=="1")){let r=BigInt("-9223372036854775808"),n=BigInt("9223372036854775807"),s=BigInt("0"),o=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(a){let l=typeof a=="bigint"?a:BigInt(a);if(l>n||l<r)throw new Error(`invalid int64: ${a}`);return l},uParse(a){let l=typeof a=="bigint"?a:BigInt(a);if(l>o||l<s)throw new Error(`invalid uint64: ${a}`);return l},enc(a){return e.setBigInt64(0,this.parse(a),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},uEnc(a){return e.setBigInt64(0,this.uParse(a),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},dec(a,l){return e.setInt32(0,a,!0),e.setInt32(4,l,!0),e.getBigInt64(0,!0)},uDec(a,l){return e.setInt32(0,a,!0),e.setInt32(4,l,!0),e.getBigUint64(0,!0)}}}return{zero:"0",supported:!1,parse(r){return typeof r!="string"&&(r=r.toString()),fs(r),r},uParse(r){return typeof r!="string"&&(r=r.toString()),ps(r),r},enc(r){return typeof r!="string"&&(r=r.toString()),fs(r),Dn(r)},uEnc(r){return typeof r!="string"&&(r=r.toString()),ps(r),Dn(r)},dec(r,n){return us(r,n)},uDec(r,n){return Un(r,n)}}}function fs(e){if(!/^-?[0-9]+$/.test(e))throw new Error("invalid int64: "+e)}function ps(e){if(!/^[0-9]+$/.test(e))throw new Error("invalid uint64: "+e)}var Vn=Symbol.for("@bufbuild/protobuf/text-encoding");function Hn(){if(globalThis[Vn]==null){let e=new globalThis.TextEncoder,t=new globalThis.TextDecoder,r;globalThis[Vn]={encodeUtf8(n){return e.encode(n)},decodeUtf8(n,s){return s?(r===void 0&&(r=new globalThis.TextDecoder("utf-8",{fatal:!0})),r.decode(n)):t.decode(n)},checkUtf8(n){try{return encodeURIComponent(n),!0}catch{return!1}}}}return globalThis[Vn]}var ke;(function(e){e[e.Varint=0]="Varint",e[e.Bit64=1]="Bit64",e[e.LengthDelimited=2]="LengthDelimited",e[e.StartGroup=3]="StartGroup",e[e.EndGroup=4]="EndGroup",e[e.Bit32=5]="Bit32"})(ke||(ke={}));var Eu=34028234663852886e22,_u=-34028234663852886e22,xu=4294967295,bu=2147483647,Su=-2147483648,O=class{constructor(t=Hn().encodeUtf8){this.encodeUtf8=t,this.stack=[],this.chunks=[],this.buf=[]}finish(){this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]);let t=0;for(let s=0;s<this.chunks.length;s++)t+=this.chunks[s].length;let r=new Uint8Array(t),n=0;for(let s=0;s<this.chunks.length;s++)r.set(this.chunks[s],n),n+=this.chunks[s].length;return this.chunks=[],r}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let t=this.finish(),r=this.stack.pop();if(!r)throw new Error("invalid state, fork stack empty");return this.chunks=r.chunks,this.buf=r.buf,this.uint32(t.byteLength),this.raw(t)}tag(t,r){return this.uint32((t<<3|r)>>>0)}raw(t){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(t),this}uint32(t){for(ms(t);t>127;)this.buf.push(t&127|128),t=t>>>7;return this.buf.push(t),this}int32(t){return $n(t),Fn(t,this.buf),this}bool(t){return this.buf.push(t?1:0),this}bytes(t){return this.uint32(t.byteLength),this.raw(t)}string(t){let r=this.encodeUtf8(t);return this.uint32(r.byteLength),this.raw(r)}float(t){Tu(t);let r=new Uint8Array(4);return new DataView(r.buffer).setFloat32(0,t,!0),this.raw(r)}double(t){let r=new Uint8Array(8);return new DataView(r.buffer).setFloat64(0,t,!0),this.raw(r)}fixed32(t){ms(t);let r=new Uint8Array(4);return new DataView(r.buffer).setUint32(0,t,!0),this.raw(r)}sfixed32(t){$n(t);let r=new Uint8Array(4);return new DataView(r.buffer).setInt32(0,t,!0),this.raw(r)}sint32(t){return $n(t),t=(t<<1^t>>31)>>>0,Fn(t,this.buf),this}sfixed64(t){let r=new Uint8Array(8),n=new DataView(r.buffer),s=ce.enc(t);return n.setInt32(0,s.lo,!0),n.setInt32(4,s.hi,!0),this.raw(r)}fixed64(t){let r=new Uint8Array(8),n=new DataView(r.buffer),s=ce.uEnc(t);return n.setInt32(0,s.lo,!0),n.setInt32(4,s.hi,!0),this.raw(r)}int64(t){let r=ce.enc(t);return Ar(r.lo,r.hi,this.buf),this}sint64(t){let r=ce.enc(t),n=r.hi>>31,s=r.lo<<1^n,o=(r.hi<<1|r.lo>>>31)^n;return Ar(s,o,this.buf),this}uint64(t){let r=ce.uEnc(t);return Ar(r.lo,r.hi,this.buf),this}},_=class{constructor(t,r=Hn().decodeUtf8){this.decodeUtf8=r,this.varint64=ls,this.uint32=ds,this.buf=t,this.len=t.length,this.pos=0,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength)}tag(){let t=this.pos,r=this.uint32(),n=this.pos-t;if(n>5||n==5&&this.buf[this.pos-1]>15)throw new Error("illegal tag: varint overflows uint32");let s=r>>>3,o=r&7;if(s<=0||o>5)throw new Error("illegal tag: field no "+s+" wire type "+o);return[s,o]}skip(t,r){let n=this.pos;switch(t){case ke.Varint:for(;this.buf[this.pos++]&128;);break;case ke.Bit64:this.pos+=4;case ke.Bit32:this.pos+=4;break;case ke.LengthDelimited:let s=this.uint32();this.pos+=s;break;case ke.StartGroup:for(;;){let[o,a]=this.tag();if(a===ke.EndGroup){if(r!==void 0&&o!==r)throw new Error("invalid end group tag");break}this.skip(a,o)}break;default:throw new Error("cant skip wire type "+t)}return this.assertBounds(),this.buf.subarray(n,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)}int64(){return ce.dec(...this.varint64())}uint64(){return ce.uDec(...this.varint64())}sint64(){let[t,r]=this.varint64(),n=-(t&1);return t=(t>>>1|(r&1)<<31)^n,r=r>>>1^n,ce.dec(t,r)}bool(){let[t,r]=this.varint64();return t!==0||r!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return ce.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return ce.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 t=this.uint32(),r=this.pos;return this.pos+=t,this.assertBounds(),this.buf.subarray(r,r+t)}string(t){return this.decodeUtf8(this.bytes(),t)}};function $n(e){if(typeof e=="string")e=Number(e);else if(typeof e!="number")throw new Error("invalid int32: "+typeof e);if(!Number.isInteger(e)||e>bu||e<Su)throw new Error("invalid int32: "+e)}function ms(e){if(typeof e=="string")e=Number(e);else if(typeof e!="number")throw new Error("invalid uint32: "+typeof e);if(!Number.isInteger(e)||e>xu||e<0)throw new Error("invalid uint32: "+e)}function Tu(e){if(typeof e=="string"){let t=e;if(e=Number(e),Number.isNaN(e)&&t!=="NaN")throw new Error("invalid float32: "+t)}else if(typeof e!="number")throw new Error("invalid float32: "+typeof e);if(Number.isFinite(e)&&(e>Eu||e<_u))throw new Error("invalid float32: "+e)}var wu=(function(e){return e[e.NULL_VALUE=0]="NULL_VALUE",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED",e})({});function jn(){return{fields:{}}}var At={encode(e,t=new O){return Object.entries(e.fields).forEach(([r,n])=>{n!==void 0&&Xn.encode({key:r,value:n},t.uint32(10).fork()).join()}),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=jn();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:{if(o!==10)break;let a=Xn.decode(r,r.uint32());a.value!==void 0&&(s.fields[a.key]=a.value);continue}}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return At.fromPartial(e??{})},fromPartial(e){let t=jn();return t.fields=Object.entries(e.fields??{}).reduce((r,[n,s])=>(s!==void 0&&(r[n]=s),r),{}),t},wrap(e){let t=jn();if(e!==void 0)for(let r of Object.keys(e))t.fields[r]=e[r];return t},unwrap(e){let t={};if(e.fields)for(let r of Object.keys(e.fields))t[r]=e.fields[r];return t}};function hs(){return{key:"",value:void 0}}var Xn={encode(e,t=new O){return e.key!==""&&t.uint32(10).string(e.key),e.value!==void 0&&I.encode(I.wrap(e.value),t.uint32(18).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=hs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.key=r.string();continue;case 2:if(o!==18)break;s.value=I.unwrap(I.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Xn.fromPartial(e??{})},fromPartial(e){let t=hs();return t.key=e.key??"",t.value=e.value??void 0,t}};function Bn(){return{nullValue:void 0,numberValue:void 0,stringValue:void 0,boolValue:void 0,structValue:void 0,listValue:void 0}}var I={encode(e,t=new O){return e.nullValue!==void 0&&t.uint32(8).int32(e.nullValue),e.numberValue!==void 0&&t.uint32(17).double(e.numberValue),e.stringValue!==void 0&&t.uint32(26).string(e.stringValue),e.boolValue!==void 0&&t.uint32(32).bool(e.boolValue),e.structValue!==void 0&&At.encode(At.wrap(e.structValue),t.uint32(42).fork()).join(),e.listValue!==void 0&&Nt.encode(Nt.wrap(e.listValue),t.uint32(50).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Bn();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==8)break;s.nullValue=r.int32();continue;case 2:if(o!==17)break;s.numberValue=r.double();continue;case 3:if(o!==26)break;s.stringValue=r.string();continue;case 4:if(o!==32)break;s.boolValue=r.bool();continue;case 5:if(o!==42)break;s.structValue=At.unwrap(At.decode(r,r.uint32()));continue;case 6:if(o!==50)break;s.listValue=Nt.unwrap(Nt.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return I.fromPartial(e??{})},fromPartial(e){let t=Bn();return t.nullValue=e.nullValue??void 0,t.numberValue=e.numberValue??void 0,t.stringValue=e.stringValue??void 0,t.boolValue=e.boolValue??void 0,t.structValue=e.structValue??void 0,t.listValue=e.listValue??void 0,t},wrap(e){let t=Bn();if(e===null)t.nullValue=wu.NULL_VALUE;else if(typeof e=="boolean")t.boolValue=e;else if(typeof e=="number")t.numberValue=e;else if(typeof e=="string")t.stringValue=e;else if(globalThis.Array.isArray(e))t.listValue=e;else if(typeof e=="object")t.structValue=e;else if(typeof e<"u")throw new globalThis.Error("Unsupported any value type: "+typeof e);return t},unwrap(e){if(e.stringValue!==void 0)return e.stringValue;if(e?.numberValue!==void 0)return e.numberValue;if(e?.boolValue!==void 0)return e.boolValue;if(e?.structValue!==void 0)return e.structValue;if(e?.listValue!==void 0)return e.listValue;if(e?.nullValue!==void 0)return null}};function zn(){return{values:[]}}var Nt={encode(e,t=new O){for(let r of e.values)I.encode(I.wrap(r),t.uint32(10).fork()).join();return t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=zn();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.values.push(I.unwrap(I.decode(r,r.uint32())));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Nt.fromPartial(e??{})},fromPartial(e){let t=zn();return t.values=e.values?.map(r=>r)||[],t},wrap(e){let t=zn();return t.values=e??[],t},unwrap(e){return e?.hasOwnProperty("values")&&globalThis.Array.isArray(e.values)?e.values:e}},Iu=(function(e){return e[e.ADD=0]="ADD",e[e.REMOVE=1]="REMOVE",e[e.REPLACE=2]="REPLACE",e[e.MOVE=3]="MOVE",e[e.COPY=4]="COPY",e[e.TEST=5]="TEST",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED",e})({});function gs(){return{op:0,path:"",from:void 0,value:void 0}}var Cr={encode(e,t=new O){return e.op!==0&&t.uint32(8).int32(e.op),e.path!==""&&t.uint32(18).string(e.path),e.from!==void 0&&t.uint32(26).string(e.from),e.value!==void 0&&I.encode(I.wrap(e.value),t.uint32(34).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=gs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==8)break;s.op=r.int32();continue;case 2:if(o!==18)break;s.path=r.string();continue;case 3:if(o!==26)break;s.from=r.string();continue;case 4:if(o!==34)break;s.value=I.unwrap(I.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Cr.fromPartial(e??{})},fromPartial(e){let t=gs();return t.op=e.op??0,t.path=e.path??"",t.from=e.from??void 0,t.value=e.value??void 0,t}};function vs(){return{id:"",type:"",function:void 0}}var kr={encode(e,t=new O){return e.id!==""&&t.uint32(10).string(e.id),e.type!==""&&t.uint32(18).string(e.type),e.function!==void 0&&Or.encode(e.function,t.uint32(26).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=vs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.id=r.string();continue;case 2:if(o!==18)break;s.type=r.string();continue;case 3:if(o!==26)break;s.function=Or.decode(r,r.uint32());continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return kr.fromPartial(e??{})},fromPartial(e){let t=vs();return t.id=e.id??"",t.type=e.type??"",t.function=e.function!==void 0&&e.function!==null?Or.fromPartial(e.function):void 0,t}};function ys(){return{name:"",arguments:""}}var Or={encode(e,t=new O){return e.name!==""&&t.uint32(10).string(e.name),e.arguments!==""&&t.uint32(18).string(e.arguments),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=ys();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.name=r.string();continue;case 2:if(o!==18)break;s.arguments=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Or.fromPartial(e??{})},fromPartial(e){let t=ys();return t.name=e.name??"",t.arguments=e.arguments??"",t}};function Es(){return{value:"",mimeType:""}}var Rr={encode(e,t=new O){return e.value!==""&&t.uint32(10).string(e.value),e.mimeType!==""&&t.uint32(18).string(e.mimeType),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Es();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.value=r.string();continue;case 2:if(o!==18)break;s.mimeType=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Rr.fromPartial(e??{})},fromPartial(e){let t=Es();return t.value=e.value??"",t.mimeType=e.mimeType??"",t}};function _s(){return{value:"",mimeType:void 0}}var Mr={encode(e,t=new O){return e.value!==""&&t.uint32(10).string(e.value),e.mimeType!==void 0&&t.uint32(18).string(e.mimeType),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=_s();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.value=r.string();continue;case 2:if(o!==18)break;s.mimeType=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Mr.fromPartial(e??{})},fromPartial(e){let t=_s();return t.value=e.value??"",t.mimeType=e.mimeType??void 0,t}};function xs(){return{data:void 0,url:void 0}}var ne={encode(e,t=new O){return e.data!==void 0&&Rr.encode(e.data,t.uint32(10).fork()).join(),e.url!==void 0&&Mr.encode(e.url,t.uint32(18).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=xs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.data=Rr.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.url=Mr.decode(r,r.uint32());continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return ne.fromPartial(e??{})},fromPartial(e){let t=xs();return t.data=e.data!==void 0&&e.data!==null?Rr.fromPartial(e.data):void 0,t.url=e.url!==void 0&&e.url!==null?Mr.fromPartial(e.url):void 0,t}};function bs(){return{text:""}}var Pr={encode(e,t=new O){return e.text!==""&&t.uint32(10).string(e.text),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=bs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.text=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Pr.fromPartial(e??{})},fromPartial(e){let t=bs();return t.text=e.text??"",t}};function Ss(){return{source:void 0,metadata:void 0}}var Lr={encode(e,t=new O){return e.source!==void 0&&ne.encode(e.source,t.uint32(10).fork()).join(),e.metadata!==void 0&&I.encode(I.wrap(e.metadata),t.uint32(18).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Ss();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.source=ne.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.metadata=I.unwrap(I.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Lr.fromPartial(e??{})},fromPartial(e){let t=Ss();return t.source=e.source!==void 0&&e.source!==null?ne.fromPartial(e.source):void 0,t.metadata=e.metadata??void 0,t}};function Ts(){return{source:void 0,metadata:void 0}}var Dr={encode(e,t=new O){return e.source!==void 0&&ne.encode(e.source,t.uint32(10).fork()).join(),e.metadata!==void 0&&I.encode(I.wrap(e.metadata),t.uint32(18).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Ts();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.source=ne.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.metadata=I.unwrap(I.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Dr.fromPartial(e??{})},fromPartial(e){let t=Ts();return t.source=e.source!==void 0&&e.source!==null?ne.fromPartial(e.source):void 0,t.metadata=e.metadata??void 0,t}};function ws(){return{source:void 0,metadata:void 0}}var Ur={encode(e,t=new O){return e.source!==void 0&&ne.encode(e.source,t.uint32(10).fork()).join(),e.metadata!==void 0&&I.encode(I.wrap(e.metadata),t.uint32(18).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=ws();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.source=ne.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.metadata=I.unwrap(I.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Ur.fromPartial(e??{})},fromPartial(e){let t=ws();return t.source=e.source!==void 0&&e.source!==null?ne.fromPartial(e.source):void 0,t.metadata=e.metadata??void 0,t}};function Is(){return{source:void 0,metadata:void 0}}var Gr={encode(e,t=new O){return e.source!==void 0&&ne.encode(e.source,t.uint32(10).fork()).join(),e.metadata!==void 0&&I.encode(I.wrap(e.metadata),t.uint32(18).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Is();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.source=ne.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.metadata=I.unwrap(I.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Gr.fromPartial(e??{})},fromPartial(e){let t=Is();return t.source=e.source!==void 0&&e.source!==null?ne.fromPartial(e.source):void 0,t.metadata=e.metadata??void 0,t}};function As(){return{text:void 0,image:void 0,audio:void 0,video:void 0,document:void 0}}var Fr={encode(e,t=new O){return e.text!==void 0&&Pr.encode(e.text,t.uint32(10).fork()).join(),e.image!==void 0&&Lr.encode(e.image,t.uint32(18).fork()).join(),e.audio!==void 0&&Dr.encode(e.audio,t.uint32(26).fork()).join(),e.video!==void 0&&Ur.encode(e.video,t.uint32(34).fork()).join(),e.document!==void 0&&Gr.encode(e.document,t.uint32(42).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=As();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.text=Pr.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.image=Lr.decode(r,r.uint32());continue;case 3:if(o!==26)break;s.audio=Dr.decode(r,r.uint32());continue;case 4:if(o!==34)break;s.video=Ur.decode(r,r.uint32());continue;case 5:if(o!==42)break;s.document=Gr.decode(r,r.uint32());continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Fr.fromPartial(e??{})},fromPartial(e){let t=As();return t.text=e.text!==void 0&&e.text!==null?Pr.fromPartial(e.text):void 0,t.image=e.image!==void 0&&e.image!==null?Lr.fromPartial(e.image):void 0,t.audio=e.audio!==void 0&&e.audio!==null?Dr.fromPartial(e.audio):void 0,t.video=e.video!==void 0&&e.video!==null?Ur.fromPartial(e.video):void 0,t.document=e.document!==void 0&&e.document!==null?Gr.fromPartial(e.document):void 0,t}};function Ns(){return{id:"",role:"",content:void 0,name:void 0,toolCalls:[],toolCallId:void 0,error:void 0,contentParts:[]}}var Vr={encode(e,t=new O){e.id!==""&&t.uint32(10).string(e.id),e.role!==""&&t.uint32(18).string(e.role),e.content!==void 0&&t.uint32(26).string(e.content),e.name!==void 0&&t.uint32(34).string(e.name);for(let r of e.toolCalls)kr.encode(r,t.uint32(42).fork()).join();e.toolCallId!==void 0&&t.uint32(50).string(e.toolCallId),e.error!==void 0&&t.uint32(58).string(e.error);for(let r of e.contentParts)Fr.encode(r,t.uint32(66).fork()).join();return t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Ns();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.id=r.string();continue;case 2:if(o!==18)break;s.role=r.string();continue;case 3:if(o!==26)break;s.content=r.string();continue;case 4:if(o!==34)break;s.name=r.string();continue;case 5:if(o!==42)break;s.toolCalls.push(kr.decode(r,r.uint32()));continue;case 6:if(o!==50)break;s.toolCallId=r.string();continue;case 7:if(o!==58)break;s.error=r.string();continue;case 8:if(o!==66)break;s.contentParts.push(Fr.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Vr.fromPartial(e??{})},fromPartial(e){let t=Ns();return t.id=e.id??"",t.role=e.role??"",t.content=e.content??void 0,t.name=e.name??void 0,t.toolCalls=e.toolCalls?.map(r=>kr.fromPartial(r))||[],t.toolCallId=e.toolCallId??void 0,t.error=e.error??void 0,t.contentParts=e.contentParts?.map(r=>Fr.fromPartial(r))||[],t}};function Cs(){return{id:"",reason:"",message:void 0,toolCallId:void 0,responseSchema:void 0,expiresAt:void 0,metadata:void 0}}var Hr={encode(e,t=new O){return e.id!==""&&t.uint32(10).string(e.id),e.reason!==""&&t.uint32(18).string(e.reason),e.message!==void 0&&t.uint32(26).string(e.message),e.toolCallId!==void 0&&t.uint32(34).string(e.toolCallId),e.responseSchema!==void 0&&I.encode(I.wrap(e.responseSchema),t.uint32(42).fork()).join(),e.expiresAt!==void 0&&t.uint32(50).string(e.expiresAt),e.metadata!==void 0&&I.encode(I.wrap(e.metadata),t.uint32(58).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Cs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.id=r.string();continue;case 2:if(o!==18)break;s.reason=r.string();continue;case 3:if(o!==26)break;s.message=r.string();continue;case 4:if(o!==34)break;s.toolCallId=r.string();continue;case 5:if(o!==42)break;s.responseSchema=I.unwrap(I.decode(r,r.uint32()));continue;case 6:if(o!==50)break;s.expiresAt=r.string();continue;case 7:if(o!==58)break;s.metadata=I.unwrap(I.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Hr.fromPartial(e??{})},fromPartial(e){let t=Cs();return t.id=e.id??"",t.reason=e.reason??"",t.message=e.message??void 0,t.toolCallId=e.toolCallId??void 0,t.responseSchema=e.responseSchema??void 0,t.expiresAt=e.expiresAt??void 0,t.metadata=e.metadata??void 0,t}},Au=(function(e){return e[e.TEXT_MESSAGE_START=0]="TEXT_MESSAGE_START",e[e.TEXT_MESSAGE_CONTENT=1]="TEXT_MESSAGE_CONTENT",e[e.TEXT_MESSAGE_END=2]="TEXT_MESSAGE_END",e[e.TOOL_CALL_START=3]="TOOL_CALL_START",e[e.TOOL_CALL_ARGS=4]="TOOL_CALL_ARGS",e[e.TOOL_CALL_END=5]="TOOL_CALL_END",e[e.STATE_SNAPSHOT=6]="STATE_SNAPSHOT",e[e.STATE_DELTA=7]="STATE_DELTA",e[e.MESSAGES_SNAPSHOT=8]="MESSAGES_SNAPSHOT",e[e.RAW=9]="RAW",e[e.CUSTOM=10]="CUSTOM",e[e.RUN_STARTED=11]="RUN_STARTED",e[e.RUN_FINISHED=12]="RUN_FINISHED",e[e.RUN_ERROR=13]="RUN_ERROR",e[e.STEP_STARTED=14]="STEP_STARTED",e[e.STEP_FINISHED=15]="STEP_FINISHED",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED",e})({});function ks(){return{type:0,timestamp:void 0,rawEvent:void 0}}var A={encode(e,t=new O){return e.type!==0&&t.uint32(8).int32(e.type),e.timestamp!==void 0&&t.uint32(16).int64(e.timestamp),e.rawEvent!==void 0&&I.encode(I.wrap(e.rawEvent),t.uint32(26).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=ks();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==8)break;s.type=r.int32();continue;case 2:if(o!==16)break;s.timestamp=Nu(r.int64());continue;case 3:if(o!==26)break;s.rawEvent=I.unwrap(I.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return A.fromPartial(e??{})},fromPartial(e){let t=ks();return t.type=e.type??0,t.timestamp=e.timestamp??void 0,t.rawEvent=e.rawEvent??void 0,t}};function Os(){return{baseEvent:void 0,messageId:"",role:void 0,name:void 0}}var $r={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.messageId!==""&&t.uint32(18).string(e.messageId),e.role!==void 0&&t.uint32(26).string(e.role),e.name!==void 0&&t.uint32(34).string(e.name),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Os();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.messageId=r.string();continue;case 3:if(o!==26)break;s.role=r.string();continue;case 4:if(o!==34)break;s.name=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return $r.fromPartial(e??{})},fromPartial(e){let t=Os();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.messageId=e.messageId??"",t.role=e.role??void 0,t.name=e.name??void 0,t}};function Rs(){return{baseEvent:void 0,messageId:"",delta:""}}var jr={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.messageId!==""&&t.uint32(18).string(e.messageId),e.delta!==""&&t.uint32(26).string(e.delta),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Rs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.messageId=r.string();continue;case 3:if(o!==26)break;s.delta=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return jr.fromPartial(e??{})},fromPartial(e){let t=Rs();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.messageId=e.messageId??"",t.delta=e.delta??"",t}};function Ms(){return{baseEvent:void 0,messageId:""}}var Br={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.messageId!==""&&t.uint32(18).string(e.messageId),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Ms();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.messageId=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Br.fromPartial(e??{})},fromPartial(e){let t=Ms();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.messageId=e.messageId??"",t}};function Ps(){return{baseEvent:void 0,toolCallId:"",toolCallName:"",parentMessageId:void 0}}var zr={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.toolCallId!==""&&t.uint32(18).string(e.toolCallId),e.toolCallName!==""&&t.uint32(26).string(e.toolCallName),e.parentMessageId!==void 0&&t.uint32(34).string(e.parentMessageId),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Ps();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.toolCallId=r.string();continue;case 3:if(o!==26)break;s.toolCallName=r.string();continue;case 4:if(o!==34)break;s.parentMessageId=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return zr.fromPartial(e??{})},fromPartial(e){let t=Ps();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.toolCallId=e.toolCallId??"",t.toolCallName=e.toolCallName??"",t.parentMessageId=e.parentMessageId??void 0,t}};function Ls(){return{baseEvent:void 0,toolCallId:"",delta:""}}var Xr={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.toolCallId!==""&&t.uint32(18).string(e.toolCallId),e.delta!==""&&t.uint32(26).string(e.delta),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Ls();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.toolCallId=r.string();continue;case 3:if(o!==26)break;s.delta=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Xr.fromPartial(e??{})},fromPartial(e){let t=Ls();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.toolCallId=e.toolCallId??"",t.delta=e.delta??"",t}};function Ds(){return{baseEvent:void 0,toolCallId:""}}var Kr={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.toolCallId!==""&&t.uint32(18).string(e.toolCallId),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Ds();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.toolCallId=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Kr.fromPartial(e??{})},fromPartial(e){let t=Ds();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.toolCallId=e.toolCallId??"",t}};function Us(){return{baseEvent:void 0,snapshot:void 0}}var Zr={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.snapshot!==void 0&&I.encode(I.wrap(e.snapshot),t.uint32(18).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Us();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.snapshot=I.unwrap(I.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Zr.fromPartial(e??{})},fromPartial(e){let t=Us();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.snapshot=e.snapshot??void 0,t}};function Gs(){return{baseEvent:void 0,delta:[]}}var Wr={encode(e,t=new O){e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join();for(let r of e.delta)Cr.encode(r,t.uint32(18).fork()).join();return t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Gs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.delta.push(Cr.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Wr.fromPartial(e??{})},fromPartial(e){let t=Gs();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.delta=e.delta?.map(r=>Cr.fromPartial(r))||[],t}};function Fs(){return{baseEvent:void 0,messages:[]}}var Yr={encode(e,t=new O){e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join();for(let r of e.messages)Vr.encode(r,t.uint32(18).fork()).join();return t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Fs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.messages.push(Vr.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Yr.fromPartial(e??{})},fromPartial(e){let t=Fs();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.messages=e.messages?.map(r=>Vr.fromPartial(r))||[],t}};function Vs(){return{baseEvent:void 0,event:void 0,source:void 0}}var qr={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.event!==void 0&&I.encode(I.wrap(e.event),t.uint32(18).fork()).join(),e.source!==void 0&&t.uint32(26).string(e.source),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Vs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.event=I.unwrap(I.decode(r,r.uint32()));continue;case 3:if(o!==26)break;s.source=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return qr.fromPartial(e??{})},fromPartial(e){let t=Vs();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.event=e.event??void 0,t.source=e.source??void 0,t}};function Hs(){return{baseEvent:void 0,name:"",value:void 0}}var Jr={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.name!==""&&t.uint32(18).string(e.name),e.value!==void 0&&I.encode(I.wrap(e.value),t.uint32(26).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Hs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.name=r.string();continue;case 3:if(o!==26)break;s.value=I.unwrap(I.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Jr.fromPartial(e??{})},fromPartial(e){let t=Hs();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.name=e.name??"",t.value=e.value??void 0,t}};function $s(){return{baseEvent:void 0,threadId:"",runId:""}}var Qr={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.threadId!==""&&t.uint32(18).string(e.threadId),e.runId!==""&&t.uint32(26).string(e.runId),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=$s();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.threadId=r.string();continue;case 3:if(o!==26)break;s.runId=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Qr.fromPartial(e??{})},fromPartial(e){let t=$s();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.threadId=e.threadId??"",t.runId=e.runId??"",t}};function js(){return{baseEvent:void 0,threadId:"",runId:"",result:void 0,outcome:"",interrupts:[]}}var en={encode(e,t=new O){e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.threadId!==""&&t.uint32(18).string(e.threadId),e.runId!==""&&t.uint32(26).string(e.runId),e.result!==void 0&&I.encode(I.wrap(e.result),t.uint32(34).fork()).join(),e.outcome!==""&&t.uint32(42).string(e.outcome);for(let r of e.interrupts)Hr.encode(r,t.uint32(50).fork()).join();return t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=js();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.threadId=r.string();continue;case 3:if(o!==26)break;s.runId=r.string();continue;case 4:if(o!==34)break;s.result=I.unwrap(I.decode(r,r.uint32()));continue;case 5:if(o!==42)break;s.outcome=r.string();continue;case 6:if(o!==50)break;s.interrupts.push(Hr.decode(r,r.uint32()));continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return en.fromPartial(e??{})},fromPartial(e){let t=js();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.threadId=e.threadId??"",t.runId=e.runId??"",t.result=e.result??void 0,t.outcome=e.outcome??"",t.interrupts=e.interrupts?.map(r=>Hr.fromPartial(r))||[],t}};function Bs(){return{baseEvent:void 0,code:void 0,message:""}}var tn={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.code!==void 0&&t.uint32(18).string(e.code),e.message!==""&&t.uint32(26).string(e.message),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Bs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.code=r.string();continue;case 3:if(o!==26)break;s.message=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return tn.fromPartial(e??{})},fromPartial(e){let t=Bs();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.code=e.code??void 0,t.message=e.message??"",t}};function zs(){return{baseEvent:void 0,stepName:""}}var rn={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.stepName!==""&&t.uint32(18).string(e.stepName),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=zs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.stepName=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return rn.fromPartial(e??{})},fromPartial(e){let t=zs();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.stepName=e.stepName??"",t}};function Xs(){return{baseEvent:void 0,stepName:""}}var nn={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.stepName!==""&&t.uint32(18).string(e.stepName),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Xs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.stepName=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return nn.fromPartial(e??{})},fromPartial(e){let t=Xs();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.stepName=e.stepName??"",t}};function Ks(){return{baseEvent:void 0,messageId:void 0,role:void 0,delta:void 0,name:void 0}}var on={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.messageId!==void 0&&t.uint32(18).string(e.messageId),e.role!==void 0&&t.uint32(26).string(e.role),e.delta!==void 0&&t.uint32(34).string(e.delta),e.name!==void 0&&t.uint32(42).string(e.name),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Ks();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.messageId=r.string();continue;case 3:if(o!==26)break;s.role=r.string();continue;case 4:if(o!==34)break;s.delta=r.string();continue;case 5:if(o!==42)break;s.name=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return on.fromPartial(e??{})},fromPartial(e){let t=Ks();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.messageId=e.messageId??void 0,t.role=e.role??void 0,t.delta=e.delta??void 0,t.name=e.name??void 0,t}};function Zs(){return{baseEvent:void 0,toolCallId:void 0,toolCallName:void 0,parentMessageId:void 0,delta:void 0}}var sn={encode(e,t=new O){return e.baseEvent!==void 0&&A.encode(e.baseEvent,t.uint32(10).fork()).join(),e.toolCallId!==void 0&&t.uint32(18).string(e.toolCallId),e.toolCallName!==void 0&&t.uint32(26).string(e.toolCallName),e.parentMessageId!==void 0&&t.uint32(34).string(e.parentMessageId),e.delta!==void 0&&t.uint32(42).string(e.delta),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Zs();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.baseEvent=A.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.toolCallId=r.string();continue;case 3:if(o!==26)break;s.toolCallName=r.string();continue;case 4:if(o!==34)break;s.parentMessageId=r.string();continue;case 5:if(o!==42)break;s.delta=r.string();continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return sn.fromPartial(e??{})},fromPartial(e){let t=Zs();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?A.fromPartial(e.baseEvent):void 0,t.toolCallId=e.toolCallId??void 0,t.toolCallName=e.toolCallName??void 0,t.parentMessageId=e.parentMessageId??void 0,t.delta=e.delta??void 0,t}};function Ws(){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 Ys={encode(e,t=new O){return e.textMessageStart!==void 0&&$r.encode(e.textMessageStart,t.uint32(10).fork()).join(),e.textMessageContent!==void 0&&jr.encode(e.textMessageContent,t.uint32(18).fork()).join(),e.textMessageEnd!==void 0&&Br.encode(e.textMessageEnd,t.uint32(26).fork()).join(),e.toolCallStart!==void 0&&zr.encode(e.toolCallStart,t.uint32(34).fork()).join(),e.toolCallArgs!==void 0&&Xr.encode(e.toolCallArgs,t.uint32(42).fork()).join(),e.toolCallEnd!==void 0&&Kr.encode(e.toolCallEnd,t.uint32(50).fork()).join(),e.stateSnapshot!==void 0&&Zr.encode(e.stateSnapshot,t.uint32(58).fork()).join(),e.stateDelta!==void 0&&Wr.encode(e.stateDelta,t.uint32(66).fork()).join(),e.messagesSnapshot!==void 0&&Yr.encode(e.messagesSnapshot,t.uint32(74).fork()).join(),e.raw!==void 0&&qr.encode(e.raw,t.uint32(82).fork()).join(),e.custom!==void 0&&Jr.encode(e.custom,t.uint32(90).fork()).join(),e.runStarted!==void 0&&Qr.encode(e.runStarted,t.uint32(98).fork()).join(),e.runFinished!==void 0&&en.encode(e.runFinished,t.uint32(106).fork()).join(),e.runError!==void 0&&tn.encode(e.runError,t.uint32(114).fork()).join(),e.stepStarted!==void 0&&rn.encode(e.stepStarted,t.uint32(122).fork()).join(),e.stepFinished!==void 0&&nn.encode(e.stepFinished,t.uint32(130).fork()).join(),e.textMessageChunk!==void 0&&on.encode(e.textMessageChunk,t.uint32(138).fork()).join(),e.toolCallChunk!==void 0&&sn.encode(e.toolCallChunk,t.uint32(146).fork()).join(),t},decode(e,t){let r=e instanceof _?e:new _(e),n=t===void 0?r.len:r.pos+t,s=Ws();for(;r.pos<n;){let o=r.uint32();switch(o>>>3){case 1:if(o!==10)break;s.textMessageStart=$r.decode(r,r.uint32());continue;case 2:if(o!==18)break;s.textMessageContent=jr.decode(r,r.uint32());continue;case 3:if(o!==26)break;s.textMessageEnd=Br.decode(r,r.uint32());continue;case 4:if(o!==34)break;s.toolCallStart=zr.decode(r,r.uint32());continue;case 5:if(o!==42)break;s.toolCallArgs=Xr.decode(r,r.uint32());continue;case 6:if(o!==50)break;s.toolCallEnd=Kr.decode(r,r.uint32());continue;case 7:if(o!==58)break;s.stateSnapshot=Zr.decode(r,r.uint32());continue;case 8:if(o!==66)break;s.stateDelta=Wr.decode(r,r.uint32());continue;case 9:if(o!==74)break;s.messagesSnapshot=Yr.decode(r,r.uint32());continue;case 10:if(o!==82)break;s.raw=qr.decode(r,r.uint32());continue;case 11:if(o!==90)break;s.custom=Jr.decode(r,r.uint32());continue;case 12:if(o!==98)break;s.runStarted=Qr.decode(r,r.uint32());continue;case 13:if(o!==106)break;s.runFinished=en.decode(r,r.uint32());continue;case 14:if(o!==114)break;s.runError=tn.decode(r,r.uint32());continue;case 15:if(o!==122)break;s.stepStarted=rn.decode(r,r.uint32());continue;case 16:if(o!==130)break;s.stepFinished=nn.decode(r,r.uint32());continue;case 17:if(o!==138)break;s.textMessageChunk=on.decode(r,r.uint32());continue;case 18:if(o!==146)break;s.toolCallChunk=sn.decode(r,r.uint32());continue}if((o&7)===4||o===0)break;r.skip(o&7)}return s},create(e){return Ys.fromPartial(e??{})},fromPartial(e){let t=Ws();return t.textMessageStart=e.textMessageStart!==void 0&&e.textMessageStart!==null?$r.fromPartial(e.textMessageStart):void 0,t.textMessageContent=e.textMessageContent!==void 0&&e.textMessageContent!==null?jr.fromPartial(e.textMessageContent):void 0,t.textMessageEnd=e.textMessageEnd!==void 0&&e.textMessageEnd!==null?Br.fromPartial(e.textMessageEnd):void 0,t.toolCallStart=e.toolCallStart!==void 0&&e.toolCallStart!==null?zr.fromPartial(e.toolCallStart):void 0,t.toolCallArgs=e.toolCallArgs!==void 0&&e.toolCallArgs!==null?Xr.fromPartial(e.toolCallArgs):void 0,t.toolCallEnd=e.toolCallEnd!==void 0&&e.toolCallEnd!==null?Kr.fromPartial(e.toolCallEnd):void 0,t.stateSnapshot=e.stateSnapshot!==void 0&&e.stateSnapshot!==null?Zr.fromPartial(e.stateSnapshot):void 0,t.stateDelta=e.stateDelta!==void 0&&e.stateDelta!==null?Wr.fromPartial(e.stateDelta):void 0,t.messagesSnapshot=e.messagesSnapshot!==void 0&&e.messagesSnapshot!==null?Yr.fromPartial(e.messagesSnapshot):void 0,t.raw=e.raw!==void 0&&e.raw!==null?qr.fromPartial(e.raw):void 0,t.custom=e.custom!==void 0&&e.custom!==null?Jr.fromPartial(e.custom):void 0,t.runStarted=e.runStarted!==void 0&&e.runStarted!==null?Qr.fromPartial(e.runStarted):void 0,t.runFinished=e.runFinished!==void 0&&e.runFinished!==null?en.fromPartial(e.runFinished):void 0,t.runError=e.runError!==void 0&&e.runError!==null?tn.fromPartial(e.runError):void 0,t.stepStarted=e.stepStarted!==void 0&&e.stepStarted!==null?rn.fromPartial(e.stepStarted):void 0,t.stepFinished=e.stepFinished!==void 0&&e.stepFinished!==null?nn.fromPartial(e.stepFinished):void 0,t.textMessageChunk=e.textMessageChunk!==void 0&&e.textMessageChunk!==null?on.fromPartial(e.textMessageChunk):void 0,t.toolCallChunk=e.toolCallChunk!==void 0&&e.toolCallChunk!==null?sn.fromPartial(e.toolCallChunk):void 0,t}};function Nu(e){let t=globalThis.Number(e.toString());if(t>globalThis.Number.MAX_SAFE_INTEGER)throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");if(t<globalThis.Number.MIN_SAFE_INTEGER)throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");return t}var Nr=e=>{if(!(!e||typeof e!="object")){if(e.data)return{type:"data",value:e.data.value,mimeType:e.data.mimeType};if(e.url)return{type:"url",value:e.url.value,mimeType:e.url.mimeType}}},Cu=e=>{if(!(!e||typeof e!="object")){if(e.text)return{type:"text",text:e.text.text};if(e.image)return{type:"image",source:Nr(e.image.source),metadata:e.image.metadata};if(e.audio)return{type:"audio",source:Nr(e.audio.source),metadata:e.audio.metadata};if(e.video)return{type:"video",source:Nr(e.video.source),metadata:e.video.metadata};if(e.document)return{type:"document",source:Nr(e.document.source),metadata:e.document.metadata}}};function qs(e){let t=Ys.decode(e),r=Object.values(t).find(n=>n!==void 0);if(!r)throw new Error("Invalid event");if(r.type=Au[r.baseEvent.type],r.timestamp=r.baseEvent.timestamp,r.rawEvent=r.baseEvent.rawEvent,delete r.baseEvent,r.type===h.MESSAGES_SNAPSHOT)for(let n of r.messages){let s=n;if(s.role==="user"&&Array.isArray(s.contentParts)){let o=s.contentParts.map(a=>Cu(a)).filter(a=>a!==void 0);o.length>0&&(s.content=o)}Array.isArray(s.contentParts)&&s.contentParts.length===0&&(s.contentParts=void 0),s.toolCalls?.length===0&&(s.toolCalls=void 0)}if(r.type===h.RUN_FINISHED){let n=r,s=typeof n.outcome=="string"&&n.outcome!==""?n.outcome:void 0,o=Array.isArray(n.interrupts)?n.interrupts:[];delete n.interrupts,s==="interrupt"?n.outcome={type:"interrupt",interrupts:o}:s==="success"?n.outcome={type:"success"}:delete n.outcome}if(r.type===h.STATE_DELTA)for(let n of r.delta)n.op=Iu[n.op].toLowerCase(),Object.keys(n).forEach(s=>{n[s]===void 0&&delete n[s]});return Object.keys(r).forEach(n=>{r[n]===void 0&&delete r[n]}),zt.parse(r)}var Kn="application/vnd.ag-ui.event+proto";var Ou=/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i,Zn=e=>{if(typeof e!="string")throw new TypeError("Invalid argument expected string");let t=e.match(Ou);if(!t)throw new Error(`Invalid argument not valid semver ('${e}' received)`);return t.shift(),t},Js=e=>e==="*"||e==="x"||e==="X",Qs=e=>{let t=parseInt(e,10);return isNaN(t)?e:t},Ru=(e,t)=>typeof e!=typeof t?[String(e),String(t)]:[e,t],Mu=(e,t)=>{if(Js(e)||Js(t))return 0;let[r,n]=Ru(Qs(e),Qs(t));return r>n?1:r<n?-1:0},Wn=(e,t)=>{for(let r=0;r<Math.max(e.length,t.length);r++){let n=Mu(e[r]||"0",t[r]||"0");if(n!==0)return n}return 0};var Ct=(e,t)=>{let r=Zn(e),n=Zn(t),s=r.pop(),o=n.pop(),a=Wn(r,n);return a!==0?a:s&&o?Wn(s.split("."),o.split(".")):s||o?s?-1:1:0};var L=e=>{if(typeof structuredClone=="function")return structuredClone(e);try{return JSON.parse(JSON.stringify(e))}catch{return Array.isArray(e)?[...e]:{...e}}};function de(){return we()}function Jn(e){if(Object.freeze(e),typeof e=="object"&&e)for(let t of Object.values(e))typeof t=="object"&&t&&!Object.isFrozen(t)&&Jn(t);return e}async function G(e,t,r,n){let s=typeof process<"u"&&process.env!==void 0,o=s&&!!process.env.VITEST_WORKER_ID,a=s&&!!process.env.VITEST_WORKER_ID,l=L(t),u=L(r),c=l,p=u,g;for(let w of e)try{a&&(Jn(c),Jn(p));let d=await n(w,c,p);if(d===void 0)continue;if(d.messages!==void 0&&d.messages!==c&&(c=L(d.messages)),d.state!==void 0&&d.state!==p&&(p=L(d.state)),g=d.stopPropagation,g===!0)break}catch(d){if(a&&d instanceof TypeError){if(o)throw d;console.error("AG-UI: Subscriber attempted to mutate frozen inputs in-place. Return mutations via AgentStateMutation instead of mutating directly.",d)}else o||console.error("Subscriber error:",d);continue}return{...c===l?{}:{messages:a&&Object.isFrozen(c)?L(c):c},...p===u?{}:{state:a&&Object.isFrozen(p)?L(p):p},...g===void 0?{}:{stopPropagation:g}}}function an(e){if(!e)return{enabled:!1,events:!1,lifecycle:!1,verbose:!1};if(e===!0)return{enabled:!0,events:!0,lifecycle:!0,verbose:!0};let t=e.events??!0,r=e.lifecycle??!0,n=e.verbose??!1;return{enabled:t||r,events:t,lifecycle:r,verbose:n}}function kt(e){if(e instanceof Qn)return e;if(e===!0)return new Qn(an(!0))}var Qn=class{constructor(e){this.config=e}event(e,t,r,n){this.config.events&&(this.config.verbose?console.debug(`[${e}] ${t}`,typeof r=="string"?r:JSON.stringify(r)):console.debug(`[${e}] ${t}`,n??r))}lifecycle(e,t,r){this.config.lifecycle&&(r?console.debug(`[${e}] ${t}`,r):console.debug(`[${e}] ${t}`))}get eventsEnabled(){return this.config.events}get lifecycleEnabled(){return this.config.lifecycle}get enabled(){return this.config.enabled}};function Yn(e){return e.enabled?new Qn(e):void 0}function Pu(e,t,r){if(t){let s=e.find(a=>a.id===t);if(s?.role==="assistant")return s;s&&console.warn(`TOOL_CALL_START: parentMessageId '${t}' matches a '${s.role}' message, not assistant \u2014 falling back to toolCallId`);let o={id:s?r:t,role:"assistant",toolCalls:[]};return e.push(o),o}let n={id:r,role:"assistant",toolCalls:[]};return e.push(n),n}var sa=(e,t,r,n,s)=>{let o=kt(s),a=L(r.messages),l=L(e.state),u={},c=g=>{g.messages!==void 0&&(a=g.messages,u.messages=g.messages),g.state!==void 0&&(l=g.state,u.state=g.state)},p=()=>{let g=L(u);return u={},g.messages!==void 0||g.state!==void 0?j(g):lr};return t.pipe(Sr(async g=>{let w=await G(n,a,l,(d,f,m)=>d.onEvent?.({event:g,agent:r,input:e,messages:f,state:m}));if(c(w),w.stopPropagation===!0?o?.event("APPLY","Event dropped:",g,{type:g.type,reason:"stopPropagation by subscriber"}):o?.event("APPLY","Event applied:",g,{type:g.type,subscribers:n.length}),w.stopPropagation===!0)return p();switch(g.type){case h.TEXT_MESSAGE_START:{let d=await G(n,a,l,(f,m,E)=>f.onTextMessageStartEvent?.({event:g,messages:m,state:E,agent:r,input:e}));if(c(d),d.stopPropagation!==!0){let{messageId:f,role:m="assistant",name:E}=g;if(!a.find(S=>S.id===f)){let S={id:f,role:m,content:"",...E!==void 0&&{name:E}};a.push(S),c({messages:a})}}return p()}case h.TEXT_MESSAGE_CONTENT:{let{messageId:d,delta:f}=g,m=a.find(S=>S.id===d);if(!m)return console.warn(`TEXT_MESSAGE_CONTENT: No message found with ID '${d}'`),p();let E=await G(n,a,l,(S,v,D)=>S.onTextMessageContentEvent?.({event:g,messages:v,state:D,agent:r,input:e,textMessageBuffer:typeof m.content=="string"?m.content:""}));return c(E),E.stopPropagation!==!0&&(m.content=`${typeof m.content=="string"?m.content:""}${f}`,c({messages:a})),p()}case h.TEXT_MESSAGE_END:{let{messageId:d}=g,f=a.find(m=>m.id===d);return f?(c(await G(n,a,l,(m,E,S)=>m.onTextMessageEndEvent?.({event:g,messages:E,state:S,agent:r,input:e,textMessageBuffer:typeof f.content=="string"?f.content:""}))),await Promise.all(n.map(m=>{m.onNewMessage?.({message:f,messages:a,state:l,agent:r,input:e})})),p()):(console.warn(`TEXT_MESSAGE_END: No message found with ID '${d}'`),p())}case h.TOOL_CALL_START:{let d=await G(n,a,l,(f,m,E)=>f.onToolCallStartEvent?.({event:g,messages:m,state:E,agent:r,input:e}));if(c(d),d.stopPropagation!==!0){let{toolCallId:f,toolCallName:m,parentMessageId:E}=g,S=Pu(a,E,f);S.toolCalls??=[],S.toolCalls.push({id:f,type:"function",function:{name:m,arguments:""}}),c({messages:a})}return p()}case h.TOOL_CALL_ARGS:{let{toolCallId:d,delta:f}=g,m=a.find(v=>v.toolCalls?.some(D=>D.id===d));if(!m)return console.warn(`TOOL_CALL_ARGS: No message found containing tool call with ID '${d}'`),p();let E=m.toolCalls?.find(v=>v.id===d);if(!E)return console.warn(`TOOL_CALL_ARGS: No tool call found with ID '${d}'`),p();let S=await G(n,a,l,(v,D,Q)=>{let ye=E.function.arguments,ua=E.function.name,vo={};try{vo=wr(ye)}catch{}return v.onToolCallArgsEvent?.({event:g,messages:D,state:Q,agent:r,input:e,toolCallBuffer:ye,toolCallName:ua,partialToolCallArgs:vo})});return c(S),S.stopPropagation!==!0&&(E.function.arguments+=f,c({messages:a})),p()}case h.TOOL_CALL_END:{let{toolCallId:d}=g,f=a.find(E=>E.toolCalls?.some(S=>S.id===d));if(!f)return console.warn(`TOOL_CALL_END: No message found containing tool call with ID '${d}'`),p();let m=f.toolCalls?.find(E=>E.id===d);return m?(c(await G(n,a,l,(E,S,v)=>{let D=m.function.arguments,Q=m.function.name,ye={};try{ye=JSON.parse(D)}catch{}return E.onToolCallEndEvent?.({event:g,messages:S,state:v,agent:r,input:e,toolCallName:Q,toolCallArgs:ye})})),await Promise.all(n.map(E=>{E.onNewToolCall?.({toolCall:m,messages:a,state:l,agent:r,input:e})})),p()):(console.warn(`TOOL_CALL_END: No tool call found with ID '${d}'`),p())}case h.TOOL_CALL_RESULT:{let d=await G(n,a,l,(f,m,E)=>f.onToolCallResultEvent?.({event:g,messages:m,state:E,agent:r,input:e}));if(c(d),d.stopPropagation!==!0){let{messageId:f,toolCallId:m,content:E,role:S}=g,v={id:f,toolCallId:m,role:S||"tool",content:E};a.push(v),await Promise.all(n.map(D=>{D.onNewMessage?.({message:v,messages:a,state:l,agent:r,input:e})})),c({messages:a})}return p()}case h.STATE_SNAPSHOT:{let d=await G(n,a,l,(f,m,E)=>f.onStateSnapshotEvent?.({event:g,messages:m,state:E,agent:r,input:e}));if(c(d),d.stopPropagation!==!0){let{snapshot:f}=g;l=f,c({state:l})}return p()}case h.STATE_DELTA:{let d=await G(n,a,l,(f,m,E)=>f.onStateDeltaEvent?.({event:g,messages:m,state:E,agent:r,input:e}));if(c(d),d.stopPropagation!==!0){let{delta:f}=g;try{l=Qt.applyPatch(l,f,!0,!1).newDocument,c({state:l})}catch(m){let E=m instanceof Error?m.message:String(m);console.warn(`Failed to apply state patch:
6
- Current state: ${JSON.stringify(l,null,2)}
7
- Patch operations: ${JSON.stringify(f,null,2)}
8
- Error: ${E}`)}}return p()}case h.MESSAGES_SNAPSHOT:{let d=await G(n,a,l,(f,m,E)=>f.onMessagesSnapshotEvent?.({event:g,messages:m,state:E,agent:r,input:e}));if(c(d),d.stopPropagation!==!0){let{messages:f}=g,m=new Map(f.map(v=>[v.id,v])),E=v=>v==="activity"||v==="reasoning";a=a.filter(v=>E(v.role)||m.has(v.id)).map(v=>E(v.role)?v:m.get(v.id));let S=new Set(a.map(v=>v.id));for(let v of f)S.has(v.id)||a.push(v);c({messages:a})}return p()}case h.ACTIVITY_SNAPSHOT:{let d=g,f=a.findIndex(D=>D.id===d.messageId),m=f>=0?a[f]:void 0,E=m?.role==="activity"?m:void 0,S=d.replace??!0,v=await G(n,a,l,(D,Q,ye)=>D.onActivitySnapshotEvent?.({event:d,messages:Q,state:ye,agent:r,input:e,activityMessage:E,existingMessage:m}));if(c(v),v.stopPropagation!==!0){let D={id:d.messageId,role:"activity",activityType:d.activityType,content:L(d.content)},Q;f===-1?(a.push(D),Q=D):E?S&&(a[f]={...E,activityType:d.activityType,content:L(d.content)}):S&&(a[f]=D,Q=D),c({messages:a}),Q&&await Promise.all(n.map(ye=>ye.onNewMessage?.({message:Q,messages:a,state:l,agent:r,input:e})))}return p()}case h.ACTIVITY_DELTA:{let d=g,f=a.findIndex(v=>v.id===d.messageId);if(f===-1)return p();let m=a[f];if(m.role!=="activity")return console.warn(`ACTIVITY_DELTA: Message '${d.messageId}' is not an activity message`),p();let E=m,S=await G(n,a,l,(v,D,Q)=>v.onActivityDeltaEvent?.({event:d,messages:D,state:Q,agent:r,input:e,activityMessage:E}));if(c(S),S.stopPropagation!==!0)try{let v=L(E.content??{}),D=Qt.applyPatch(v,d.patch??[],!0,!1).newDocument;a[f]={...E,content:L(D),activityType:d.activityType},c({messages:a})}catch(v){let D=v instanceof Error?v.message:String(v);console.warn(`Failed to apply activity patch for '${d.messageId}': ${D}`)}return p()}case h.RAW:return c(await G(n,a,l,(d,f,m)=>d.onRawEvent?.({event:g,messages:f,state:m,agent:r,input:e}))),p();case h.CUSTOM:return c(await G(n,a,l,(d,f,m)=>d.onCustomEvent?.({event:g,messages:f,state:m,agent:r,input:e}))),p();case h.RUN_STARTED:{let d=await G(n,a,l,(f,m,E)=>f.onRunStartedEvent?.({event:g,messages:m,state:E,agent:r,input:e}));if(c(d),d.stopPropagation!==!0){let f=g;if(f.input?.messages){for(let m of f.input.messages)a.find(E=>E.id===m.id)||a.push(m);c({messages:a})}}return p()}case h.RUN_FINISHED:{let d=g,f=d.outcome?.type==="interrupt"?{event:d,outcome:"interrupt",interrupts:d.outcome.interrupts}:{event:d,outcome:"success",result:d.result},m=await G(n,a,l,(E,S,v)=>E.onRunFinishedEvent?.({...f,messages:S,state:v,agent:r,input:e}));return c(m),m.stopPropagation!==!0&&(r.pendingInterrupts=f.outcome==="interrupt"?[...f.interrupts]:[]),p()}case h.RUN_ERROR:return c(await G(n,a,l,(d,f,m)=>d.onRunErrorEvent?.({event:g,messages:f,state:m,agent:r,input:e}))),p();case h.STEP_STARTED:return c(await G(n,a,l,(d,f,m)=>d.onStepStartedEvent?.({event:g,messages:f,state:m,agent:r,input:e}))),p();case h.STEP_FINISHED:return c(await G(n,a,l,(d,f,m)=>d.onStepFinishedEvent?.({event:g,messages:f,state:m,agent:r,input:e}))),p();case h.TEXT_MESSAGE_CHUNK:throw Error("TEXT_MESSAGE_CHUNK must be tranformed before being applied");case h.TOOL_CALL_CHUNK:throw Error("TOOL_CALL_CHUNK must be tranformed before being applied");case h.THINKING_START:return p();case h.THINKING_END:return p();case h.THINKING_TEXT_MESSAGE_START:return p();case h.THINKING_TEXT_MESSAGE_CONTENT:return p();case h.THINKING_TEXT_MESSAGE_END:return p();case h.REASONING_START:return c(await G(n,a,l,(d,f,m)=>d.onReasoningStartEvent?.({event:g,messages:f,state:m,agent:r,input:e}))),p();case h.REASONING_MESSAGE_START:{let d=await G(n,a,l,(f,m,E)=>f.onReasoningMessageStartEvent?.({event:g,messages:m,state:E,agent:r,input:e}));if(c(d),d.stopPropagation!==!0){let{messageId:f}=g;if(!a.find(m=>m.id===f)){let m={id:f,role:"reasoning",content:""};a.push(m),c({messages:a})}}return p()}case h.REASONING_MESSAGE_CONTENT:{let{messageId:d,delta:f}=g,m=a.find(S=>S.id===d);if(!m)return console.warn(`REASONING_MESSAGE_CONTENT: No message found with ID '${d}'`),p();let E=await G(n,a,l,(S,v,D)=>S.onReasoningMessageContentEvent?.({event:g,messages:v,state:D,agent:r,input:e,reasoningMessageBuffer:typeof m.content=="string"?m.content:""}));return c(E),E.stopPropagation!==!0&&(m.content=`${typeof m.content=="string"?m.content:""}${f}`,c({messages:a})),p()}case h.REASONING_MESSAGE_END:{let{messageId:d}=g,f=a.find(m=>m.id===d);return f?(c(await G(n,a,l,(m,E,S)=>m.onReasoningMessageEndEvent?.({event:g,messages:E,state:S,agent:r,input:e,reasoningMessageBuffer:typeof f.content=="string"?f.content:""}))),await Promise.all(n.map(m=>{m.onNewMessage?.({message:f,messages:a,state:l,agent:r,input:e})})),p()):(console.warn(`REASONING_MESSAGE_END: No message found with ID '${d}'`),p())}case h.REASONING_MESSAGE_CHUNK:throw Error("REASONING_MESSAGE_CHUNK must be transformed before being applied");case h.REASONING_END:return c(await G(n,a,l,(d,f,m)=>d.onReasoningEndEvent?.({event:g,messages:f,state:m,agent:r,input:e}))),p();case h.REASONING_ENCRYPTED_VALUE:{let{subtype:d,entityId:f,encryptedValue:m}=g,E=await G(n,a,l,(S,v,D)=>S.onReasoningEncryptedValueEvent?.({event:g,messages:v,state:D,agent:r,input:e}));if(c(E),E.stopPropagation!==!0){let S=!1;if(d==="tool-call"){for(let v of a)if(v.role==="assistant"&&v.toolCalls){let D=v.toolCalls.find(Q=>Q.id===f);if(D){D.encryptedValue=m,S=!0;break}}}else{let v=a.find(D=>D.id===f);v?.role!=="activity"&&v&&(v.encryptedValue=m,S=!0)}S&&(u.messages=a)}return p()}}return g.type,p()}),Rn(),n.length>0?Mn({}):g=>g)},qn=e=>t=>{let r=kt(e),n=new Map,s=new Map,o=!1,a=!1,l=!1,u=new Map,c=!1,p=!1,g=!1,w=()=>{n.clear(),s.clear(),u.clear(),c=!1,p=!1,o=!1,a=!1,g=!0};return t.pipe(re(d=>{let f=d.type;if(r?.event("VERIFY","Event:",d,{type:d.type}),a)return $(()=>new V(`Cannot send event type '${f}': The run has already errored with 'RUN_ERROR'. No further events can be sent.`));if(o&&f!==h.RUN_ERROR&&f!==h.RUN_STARTED)return $(()=>new V(`Cannot send event type '${f}': The run has already finished with 'RUN_FINISHED'. Start a new run with 'RUN_STARTED'.`));if(l){if(f===h.RUN_STARTED){if(g&&!o)return $(()=>new V("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&&w()}}else if(l=!0,f!==h.RUN_STARTED&&f!==h.RUN_ERROR)return $(()=>new V("First event must be 'RUN_STARTED'"));switch(f){case h.TEXT_MESSAGE_START:{let m=d.messageId;return n.has(m)?$(()=>new V(`Cannot send 'TEXT_MESSAGE_START' event: A text message with ID '${m}' is already in progress. Complete it with 'TEXT_MESSAGE_END' first.`)):(n.set(m,!0),j(d))}case h.TEXT_MESSAGE_CONTENT:{let m=d.messageId;return n.has(m)?j(d):$(()=>new V(`Cannot send 'TEXT_MESSAGE_CONTENT' event: No active text message found with ID '${m}'. Start a text message with 'TEXT_MESSAGE_START' first.`))}case h.TEXT_MESSAGE_END:{let m=d.messageId;return n.has(m)?(n.delete(m),j(d)):$(()=>new V(`Cannot send 'TEXT_MESSAGE_END' event: No active text message found with ID '${m}'. A 'TEXT_MESSAGE_START' event must be sent first.`))}case h.TOOL_CALL_START:{let m=d.toolCallId;return s.has(m)?$(()=>new V(`Cannot send 'TOOL_CALL_START' event: A tool call with ID '${m}' is already in progress. Complete it with 'TOOL_CALL_END' first.`)):(s.set(m,!0),j(d))}case h.TOOL_CALL_ARGS:{let m=d.toolCallId;return s.has(m)?j(d):$(()=>new V(`Cannot send 'TOOL_CALL_ARGS' event: No active tool call found with ID '${m}'. Start a tool call with 'TOOL_CALL_START' first.`))}case h.TOOL_CALL_END:{let m=d.toolCallId;return s.has(m)?(s.delete(m),j(d)):$(()=>new V(`Cannot send 'TOOL_CALL_END' event: No active tool call found with ID '${m}'. A 'TOOL_CALL_START' event must be sent first.`))}case h.STEP_STARTED:{let m=d.stepName;return u.has(m)?$(()=>new V(`Step "${m}" is already active for 'STEP_STARTED'`)):(u.set(m,!0),j(d))}case h.STEP_FINISHED:{let m=d.stepName;return u.has(m)?(u.delete(m),j(d)):$(()=>new V(`Cannot send 'STEP_FINISHED' for step "${m}" that was not started`))}case h.RUN_STARTED:return g=!0,j(d);case h.RUN_FINISHED:if(u.size>0){let m=Array.from(u.keys()).join(", ");return $(()=>new V(`Cannot send 'RUN_FINISHED' while steps are still active: ${m}`))}if(n.size>0){let m=Array.from(n.keys()).join(", ");return $(()=>new V(`Cannot send 'RUN_FINISHED' while text messages are still active: ${m}`))}if(s.size>0){let m=Array.from(s.keys()).join(", ");return $(()=>new V(`Cannot send 'RUN_FINISHED' while tool calls are still active: ${m}`))}return o=!0,j(d);case h.RUN_ERROR:return a=!0,j(d);case h.CUSTOM:return j(d);case h.THINKING_TEXT_MESSAGE_START:return c?p?$(()=>new V("Cannot send 'THINKING_TEXT_MESSAGE_START' event: A thinking message is already in progress. Complete it with 'THINKING_TEXT_MESSAGE_END' first.")):(p=!0,j(d)):$(()=>new V("Cannot send 'THINKING_TEXT_MESSAGE_START' event: A thinking step is not in progress. Create one with 'THINKING_START' first."));case h.THINKING_TEXT_MESSAGE_CONTENT:return p?j(d):$(()=>new V("Cannot send 'THINKING_TEXT_MESSAGE_CONTENT' event: No active thinking message found. Start a message with 'THINKING_TEXT_MESSAGE_START' first."));case h.THINKING_TEXT_MESSAGE_END:return p?(p=!1,j(d)):$(()=>new V("Cannot send 'THINKING_TEXT_MESSAGE_END' event: No active thinking message found. A 'THINKING_TEXT_MESSAGE_START' event must be sent first."));case h.THINKING_START:return c?$(()=>new V("Cannot send 'THINKING_START' event: A thinking step is already in progress. End it with 'THINKING_END' first.")):(c=!0,j(d));case h.THINKING_END:return c?(c=!1,j(d)):$(()=>new V("Cannot send 'THINKING_END' event: No active thinking step found. A 'THINKING_START' event must be sent first."));default:return j(d)}}))},Qe=(function(e){return e.HEADERS="headers",e.DATA="data",e})({}),Lu=e=>br(()=>Ye(e())).pipe(Pn(t=>{if(!t.ok){let s=t.headers.get("content-type")||"";return Ye(t.text()).pipe(re(o=>{let a=o;if(s.includes("application/json"))try{a=JSON.parse(o)}catch{}let l=Error(`HTTP ${t.status}: ${typeof a=="string"?a:JSON.stringify(a)}`);return l.status=t.status,l.payload=a,$(()=>l)}))}let r={type:Qe.HEADERS,status:t.status,headers:t.headers},n=t.body?.getReader();return n?new H(s=>(s.next(r),(async()=>{try{for(;;){let{done:o,value:a}=await n.read();if(o)break;let l={type:Qe.DATA,data:a};s.next(l)}s.complete()}catch(o){s.error(o)}})(),()=>{n.cancel().catch(o=>{if(o?.name!=="AbortError")throw o})})):$(()=>Error("Failed to getReader() from response"))})),Du=(e,t)=>{let r=kt(t),n=new ve,s=new TextDecoder("utf-8",{fatal:!1}),o="";e.subscribe({next:l=>{if(l.type!==Qe.HEADERS&&l.type===Qe.DATA&&l.data){let u=s.decode(l.data,{stream:!0});o+=u;let c=o.split(/\n\n/);o=c.pop()||"";for(let p of c)a(p)}},error:l=>n.error(l),complete:()=>{o&&(o+=s.decode(),a(o)),n.complete()}});function a(l){let u=l.split(`
9
- `),c=[];for(let p of u)p.startsWith("data:")&&c.push(p.slice(5).replace(/^ /,""));if(c.length>0)try{let p=c.join(`
10
- `),g=JSON.parse(p);r?.event("SSE","Event received:",g,{type:g.type}),n.next(g)}catch(p){n.error(p)}}return n.asObservable()},Uu=e=>{let t=new ve,r=new Uint8Array;e.subscribe({next:s=>{if(s.type!==Qe.HEADERS&&s.type===Qe.DATA&&s.data){let o=new Uint8Array(r.length+s.data.length);o.set(r,0),o.set(s.data,r.length),r=o,n()}},error:s=>t.error(s),complete:()=>{if(r.length>0)try{n()}catch{console.warn("Incomplete or invalid protocol buffer data at stream end")}t.complete()}});function n(){for(;r.length>=4;){let s=4+new DataView(r.buffer,r.byteOffset,4).getUint32(0,!1);if(r.length<s)break;try{let o=r.slice(4,s),a=qs(o);t.next(a),r=r.slice(s)}catch(o){let a=o instanceof Error?o.message:String(o);t.error(Error(`Failed to decode protocol buffer message: ${a}`));return}}}return t.asObservable()},Gu=(e,t)=>{let r=kt(t),n=new ve,s=new ir,o=!1;return e.subscribe({next:a=>{if(s.next(a),a.type===Qe.HEADERS&&!o){o=!0;let l=a.headers.get("content-type");r?.lifecycle("HTTP","Stream format detected:",{contentType:l,parser:l===Kn?"protobuf":"sse"}),l===Kn?Uu(s).subscribe({next:u=>n.next(u),error:u=>n.error(u),complete:()=>n.complete()}):Du(s,r).subscribe({next:u=>{try{let c=zt.parse(u);r?.event("HTTP","Event validated:",c,{type:c.type,valid:!0}),n.next(c)}catch(c){r?.event("HTTP","Event invalid:",{json:u,error:String(c)}),n.error(c)}},error:u=>{if(u?.name==="AbortError"){n.next({type:h.RUN_ERROR,message:u.message||"Request aborted",code:"abort",rawEvent:u}),n.complete();return}return n.error(u)},complete:()=>n.complete()})}else o||n.error(Error("No headers event received before data events"))},error:a=>{s.error(a),n.error(a)},complete:()=>{s.complete()}}),n.asObservable()},F=i.enum(["TextMessageStart","TextMessageContent","TextMessageEnd","ActionExecutionStart","ActionExecutionArgs","ActionExecutionEnd","ActionExecutionResult","AgentStateMessage","MetaEvent","RunStarted","RunFinished","RunError","NodeStarted","NodeFinished"]),Fu=i.enum(["LangGraphInterruptEvent","PredictState","Exit"]),Vu=i.object({type:i.literal(F.enum.TextMessageStart),messageId:i.string(),parentMessageId:i.string().optional(),role:i.string().optional()}),Hu=i.object({type:i.literal(F.enum.TextMessageContent),messageId:i.string(),content:i.string()}),$u=i.object({type:i.literal(F.enum.TextMessageEnd),messageId:i.string()}),ju=i.object({type:i.literal(F.enum.ActionExecutionStart),actionExecutionId:i.string(),actionName:i.string(),parentMessageId:i.string().optional()}),Bu=i.object({type:i.literal(F.enum.ActionExecutionArgs),actionExecutionId:i.string(),args:i.string()}),zu=i.object({type:i.literal(F.enum.ActionExecutionEnd),actionExecutionId:i.string()}),Xu=i.object({type:i.literal(F.enum.ActionExecutionResult),actionName:i.string(),actionExecutionId:i.string(),result:i.string()}),Ku=i.object({type:i.literal(F.enum.AgentStateMessage),threadId:i.string(),agentName:i.string(),nodeName:i.string(),runId:i.string(),active:i.boolean(),role:i.string(),state:i.string(),running:i.boolean()}),Zu=i.object({type:i.literal(F.enum.MetaEvent),name:Fu,value:i.any()}),Wu=i.object({type:i.literal(F.enum.RunError),message:i.string(),code:i.string().optional()});i.discriminatedUnion("type",[Vu,Hu,$u,ju,Bu,zu,Xu,Ku,Zu,Wu]),i.object({id:i.string(),role:i.string(),content:i.string(),parentMessageId:i.string().optional()}),i.object({id:i.string(),name:i.string(),arguments:i.any(),parentMessageId:i.string().optional()}),i.object({id:i.string(),result:i.any(),actionExecutionId:i.string(),actionName:i.string()});var Yu=e=>{if(typeof e=="string")return e;if(!Array.isArray(e))return;let t=e.filter(r=>r.type==="text").map(r=>r.text).filter(r=>r.length>0);if(t.length!==0)return t.join(`
11
- `)},qu=(e,t,r)=>n=>{let s={},o=!0,a=!0,l="",u=null,c=null,p=[],g={},w=d=>{typeof d=="object"&&d&&("messages"in d&&delete d.messages,s=d)};return n.pipe(re(d=>{switch(d.type){case h.TEXT_MESSAGE_START:{let f=d;return[{type:F.enum.TextMessageStart,messageId:f.messageId,role:f.role}]}case h.TEXT_MESSAGE_CONTENT:{let f=d;return[{type:F.enum.TextMessageContent,messageId:f.messageId,content:f.delta}]}case h.TEXT_MESSAGE_END:{let f=d;return[{type:F.enum.TextMessageEnd,messageId:f.messageId}]}case h.TOOL_CALL_START:{let f=d;return p.push({id:f.toolCallId,type:"function",function:{name:f.toolCallName,arguments:""}}),a=!0,g[f.toolCallId]=f.toolCallName,[{type:F.enum.ActionExecutionStart,actionExecutionId:f.toolCallId,actionName:f.toolCallName,parentMessageId:f.parentMessageId}]}case h.TOOL_CALL_ARGS:{let f=d,m=p.find(S=>S.id===f.toolCallId);if(!m)return console.warn(`TOOL_CALL_ARGS: No tool call found with ID '${f.toolCallId}'`),[];m.function.arguments+=f.delta;let E=!1;if(c){let S=c.find(v=>v.tool==m.function.name);if(S)try{let v=JSON.parse(wr(m.function.arguments));S.tool_argument&&S.tool_argument in v?(w({...s,[S.state_key]:v[S.tool_argument]}),E=!0):S.tool_argument||(w({...s,[S.state_key]:v}),E=!0)}catch{}}return[{type:F.enum.ActionExecutionArgs,actionExecutionId:f.toolCallId,args:f.delta},...E?[{type:F.enum.AgentStateMessage,threadId:e,agentName:r,nodeName:l,runId:t,running:o,role:"assistant",state:JSON.stringify(s),active:a}]:[]]}case h.TOOL_CALL_END:{let f=d;return[{type:F.enum.ActionExecutionEnd,actionExecutionId:f.toolCallId}]}case h.TOOL_CALL_RESULT:{let f=d;return[{type:F.enum.ActionExecutionResult,actionExecutionId:f.toolCallId,result:f.content,actionName:g[f.toolCallId]||"unknown"}]}case h.RAW:return[];case h.CUSTOM:{let f=d;switch(f.name){case"Exit":o=!1;break;case"PredictState":c=f.value;break}return[{type:F.enum.MetaEvent,name:f.name,value:f.value}]}case h.STATE_SNAPSHOT:return w(d.snapshot),[{type:F.enum.AgentStateMessage,threadId:e,agentName:r,nodeName:l,runId:t,running:o,role:"assistant",state:JSON.stringify(s),active:a}];case h.STATE_DELTA:{let f=d,m=Qt.applyPatch(s,f.delta,!0,!1);return m?(w(m.newDocument),[{type:F.enum.AgentStateMessage,threadId:e,agentName:r,nodeName:l,runId:t,running:o,role:"assistant",state:JSON.stringify(s),active:a}]):[]}case h.MESSAGES_SNAPSHOT:return u=d.messages,[{type:F.enum.AgentStateMessage,threadId:e,agentName:r,nodeName:l,runId:t,running:o,role:"assistant",state:JSON.stringify({...s,...u?{messages:u}:{}}),active:!0}];case h.RUN_STARTED:return[];case h.RUN_FINISHED:return u&&(s.messages=u),Object.keys(s).length===0?[]:[{type:F.enum.AgentStateMessage,threadId:e,agentName:r,nodeName:l,runId:t,running:o,role:"assistant",state:JSON.stringify({...s,...u?{messages:Ju(u)}:{}}),active:!1}];case h.RUN_ERROR:{let f=d;return[{type:F.enum.RunError,message:f.message,code:f.code}]}case h.STEP_STARTED:return l=d.stepName,p=[],c=null,[{type:F.enum.AgentStateMessage,threadId:e,agentName:r,nodeName:l,runId:t,running:o,role:"assistant",state:JSON.stringify(s),active:!0}];case h.STEP_FINISHED:return p=[],c=null,[{type:F.enum.AgentStateMessage,threadId:e,agentName:r,nodeName:l,runId:t,running:o,role:"assistant",state:JSON.stringify(s),active:!1}];default:return[]}}))};function Ju(e){let t=[];for(let r of e)if(r.role==="assistant"||r.role==="user"||r.role==="system"){let n=Yu(r.content);if(n){let s={id:r.id,role:r.role,content:n};t.push(s)}if(r.role==="assistant"&&r.toolCalls&&r.toolCalls.length>0)for(let s of r.toolCalls){let o={id:s.id,name:s.function.name,arguments:JSON.parse(s.function.arguments),parentMessageId:r.id};t.push(o)}}else if(r.role==="tool"){let n="unknown";for(let o of e)if(o.role==="assistant"&&o.toolCalls?.length){for(let a of o.toolCalls)if(a.id===r.toolCallId){n=a.function.name;break}}let s={id:r.id,result:r.content,actionExecutionId:r.toolCallId,actionName:n};t.push(s)}return t}var ln=e=>t=>{let r=kt(e),n,s,o,a,l=()=>{if(!n||a!=="text")throw Error("No text message to close");let g={type:h.TEXT_MESSAGE_END,messageId:n.messageId};return a=void 0,n=void 0,r?.event("TRANSFORM","TEXT_MESSAGE_END",g,{messageId:g.messageId}),g},u=()=>{if(!s||a!=="tool")throw Error("No tool call to close");let g={type:h.TOOL_CALL_END,toolCallId:s.toolCallId};return a=void 0,s=void 0,r?.event("TRANSFORM","TOOL_CALL_END",g,{toolCallId:g.toolCallId}),g},c=()=>{if(!o||a!=="reasoning")throw Error("No reasoning message to close");let g={type:h.REASONING_MESSAGE_END,messageId:o.messageId};return a=void 0,o=void 0,r?.event("TRANSFORM","REASONING_MESSAGE_END",g,{messageId:g.messageId}),g},p=()=>a==="text"?[l()]:a==="tool"?[u()]:a==="reasoning"?[c()]:[];return t.pipe(re(g=>{switch(g.type){case h.TEXT_MESSAGE_START:case h.TEXT_MESSAGE_CONTENT:case h.TEXT_MESSAGE_END:case h.TOOL_CALL_START:case h.TOOL_CALL_ARGS:case h.TOOL_CALL_END:case h.TOOL_CALL_RESULT:case h.STATE_SNAPSHOT:case h.STATE_DELTA:case h.MESSAGES_SNAPSHOT:case h.CUSTOM:case h.RUN_STARTED:case h.RUN_FINISHED:case h.RUN_ERROR:case h.STEP_STARTED:case h.STEP_FINISHED:case h.THINKING_START:case h.THINKING_END:case h.THINKING_TEXT_MESSAGE_START:case h.THINKING_TEXT_MESSAGE_CONTENT:case h.THINKING_TEXT_MESSAGE_END:case h.REASONING_START:case h.REASONING_MESSAGE_START:case h.REASONING_MESSAGE_CONTENT:case h.REASONING_MESSAGE_END:case h.REASONING_END:return[...p(),g];case h.RAW:case h.ACTIVITY_SNAPSHOT:case h.ACTIVITY_DELTA:case h.REASONING_ENCRYPTED_VALUE:return[g];case h.TEXT_MESSAGE_CHUNK:let w=g,d=[];if((a!=="text"||w.messageId!==void 0&&w.messageId!==n?.messageId)&&d.push(...p()),a!=="text"){if(w.messageId===void 0)throw Error("First TEXT_MESSAGE_CHUNK must have a messageId");n={messageId:w.messageId,name:w.name},a="text";let v={type:h.TEXT_MESSAGE_START,messageId:w.messageId,role:w.role||"assistant",...w.name!==void 0&&{name:w.name}};d.push(v),r?.event("TRANSFORM","TEXT_MESSAGE_START",v,{messageId:w.messageId})}if(w.delta!==void 0){let v={type:h.TEXT_MESSAGE_CONTENT,messageId:n.messageId,delta:w.delta};d.push(v),r?.event("TRANSFORM","TEXT_MESSAGE_CONTENT",v,{messageId:n.messageId})}return d;case h.TOOL_CALL_CHUNK:let f=g,m=[];if((a!=="tool"||f.toolCallId!==void 0&&f.toolCallId!==s?.toolCallId)&&m.push(...p()),a!=="tool"){if(f.toolCallId===void 0)throw Error("First TOOL_CALL_CHUNK must have a toolCallId");if(f.toolCallName===void 0)throw Error("First TOOL_CALL_CHUNK must have a toolCallName");s={toolCallId:f.toolCallId,toolCallName:f.toolCallName,parentMessageId:f.parentMessageId},a="tool";let v={type:h.TOOL_CALL_START,toolCallId:f.toolCallId,toolCallName:f.toolCallName,parentMessageId:f.parentMessageId};m.push(v),r?.event("TRANSFORM","TOOL_CALL_START",v,{toolCallId:f.toolCallId,toolCallName:f.toolCallName})}if(f.delta!==void 0){let v={type:h.TOOL_CALL_ARGS,toolCallId:s.toolCallId,delta:f.delta};m.push(v),r?.event("TRANSFORM","TOOL_CALL_ARGS",v,{toolCallId:s.toolCallId})}return m;case h.REASONING_MESSAGE_CHUNK:let E=g,S=[];if((a!=="reasoning"||E.messageId&&E.messageId!==o?.messageId)&&S.push(...p()),a!=="reasoning"){if(E.messageId===void 0)throw Error("First REASONING_MESSAGE_CHUNK must have a messageId");o={messageId:E.messageId},a="reasoning";let v={type:h.REASONING_MESSAGE_START,messageId:E.messageId};S.push(v),r?.event("TRANSFORM","REASONING_MESSAGE_START",v,{messageId:E.messageId})}if(E.delta!==void 0){let v={type:h.REASONING_MESSAGE_CONTENT,messageId:o.messageId,delta:E.delta};S.push(v),r?.event("TRANSFORM","REASONING_MESSAGE_CONTENT",v,{messageId:o.messageId})}return S}return g.type,[]}),Je(()=>{p()}))};function Qu(e,t=new Date){return e.expiresAt===void 0?!1:new Date(e.expiresAt)<=t}var un=class{runNext(e,t){return t.run(e).pipe(ln(!1))}runNextWithState(e,t){let r=L(e.messages||[]),n=L(e.state||{}),s=new ir;return sa(e,s,t,[]).subscribe(o=>{o.messages!==void 0&&(r=o.messages),o.state!==void 0&&(n=o.state)}),this.runNext(e,t).pipe(Sr(async o=>(s.next(o),await new Promise(a=>setTimeout(a,0)),{event:o,messages:L(r),state:L(n)})))}},ec=class extends un{constructor(e){super(),this.fn=e}run(e,t){return this.fn(e,t)}};function tc(e){let t=e.content;if(Array.isArray(t)){let r=t.filter(n=>typeof n=="object"&&!!n&&"type"in n&&n.type==="text"&&typeof n.text=="string").map(n=>n.text).join("");return{...e,content:r}}return typeof t=="string"?e:{...e,content:""}}var rc=class extends un{run(e,t){let{parentRunId:r,...n}=e,s={...n,messages:n.messages.map(tc)};return this.runNext(s,t)}},ea="THINKING_START",ta="THINKING_END",ra="THINKING_TEXT_MESSAGE_START",na="THINKING_TEXT_MESSAGE_CONTENT",oa="THINKING_TEXT_MESSAGE_END",nc=class extends un{constructor(...e){super(...e),this.currentReasoningId=null,this.currentMessageId=null}warnAboutTransformation(e,t){typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(`AG-UI is converting ${e} to ${t}. 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(e,t){return this.currentReasoningId=null,this.currentMessageId=null,this.runNext(e,t).pipe(qe(r=>this.transformEvent(r)))}transformEvent(e){switch(e.type){case ea:{this.currentReasoningId=de();let{title:t,...r}=e;return this.warnAboutTransformation(ea,h.REASONING_START),{...r,type:h.REASONING_START,messageId:this.currentReasoningId}}case ra:return this.currentMessageId=de(),this.warnAboutTransformation(ra,h.REASONING_MESSAGE_START),{...e,type:h.REASONING_MESSAGE_START,messageId:this.currentMessageId,role:"assistant"};case na:{let{delta:t,...r}=e;return this.warnAboutTransformation(na,h.REASONING_MESSAGE_CONTENT),{...r,type:h.REASONING_MESSAGE_CONTENT,messageId:this.currentMessageId??de(),delta:t}}case oa:{let t=this.currentMessageId??de();return this.warnAboutTransformation(oa,h.REASONING_MESSAGE_END),{...e,type:h.REASONING_MESSAGE_END,messageId:t}}case ta:{let t=this.currentReasoningId??de();return this.warnAboutTransformation(ta,h.REASONING_END),{...e,type:h.REASONING_END,messageId:t}}default:return e}}};function oc(e){return e.startsWith("image/")?"image":e.startsWith("audio/")?"audio":e.startsWith("video/")?"video":"document"}function sc(e){return typeof e=="object"&&!!e&&"type"in e&&e.type==="binary"&&"mimeType"in e&&typeof e.mimeType=="string"}function ac(e){let t=oc(e.mimeType);return e.data?{type:t,source:{type:"data",value:e.data,mimeType:e.mimeType},...e.filename?{metadata:{filename:e.filename}}:{}}:e.url?{type:t,source:{type:"url",value:e.url,mimeType:e.mimeType},...e.filename?{metadata:{filename:e.filename}}:{}}:e}function ic(e){let t=e.content;if(!Array.isArray(t))return e;let r=t.map(n=>sc(n)?ac(n):n);return{...e,content:r}}var lc=class extends un{run(e,t){let r={...e,messages:e.messages.map(ic)};return this.runNext(r,t)}},uc="0.0.54",cc=class{get maxVersion(){return uc}get debug(){return this._debug}set debug(e){this._debug=an(e),this._debugLogger=Yn(this._debug)}get debugLogger(){return this._debugLogger}set debugLogger(e){typeof e=="boolean"?this._debugLogger=e?Yn(an(!0)):void 0:this._debugLogger=e}constructor({agentId:e,description:t,threadId:r,initialMessages:n,initialState:s,debug:o}={}){this.subscribers=[],this.isRunning=!1,this.pendingInterrupts=[],this.middlewares=[],this.agentId=e,this.description=t??"",this.threadId=r??we(),this.messages=L(n??[]),this.state=L(s??{}),this._debug=an(o),this._debugLogger=Yn(this._debug),Ct(this.maxVersion,"0.0.39")<=0&&this.middlewares.unshift(new rc),Ct(this.maxVersion,"0.0.45")<=0&&this.middlewares.unshift(new nc),Ct(this.maxVersion,"0.0.47")<=0&&this.middlewares.unshift(new lc)}subscribe(e){return this.subscribers.push(e),{unsubscribe:()=>{this.subscribers=this.subscribers.filter(t=>t!==e)}}}use(...e){let t=e.map(r=>typeof r=="function"?new ec(r):r);return this.middlewares.push(...t),this}async runAgent(e,t){try{this.isRunning=!0,this.agentId=this.agentId??we();let r=this.prepareRunAgentInput(e);this.debugLogger?.lifecycle("LIFECYCLE","Run started:",{agentId:this.agentId,threadId:this.threadId});let n,s=new Set(this.messages.map(u=>u.id)),o=[{onRunFinishedEvent:u=>{u.outcome==="success"&&(n=u.result)}},...this.subscribers,t??{}];await this.onInitialize(r,o),this.activeRunDetach$=new ve;let a;this.activeRunCompletionPromise=new Promise(u=>{a=u}),await xr(ar(()=>this.middlewares.length===0?this.run(r):this.middlewares.reduceRight((u,c)=>({run:p=>c.run(p,u),get messages(){return u.messages},get state(){return u.state}}),this).run(r),ln(this.debugLogger),qn(this.debugLogger),u=>u.pipe(Tr(this.activeRunDetach$)),u=>this.apply(r,u,o),u=>this.processApplyEvents(r,u,o),It(u=>(this.debugLogger?.lifecycle("LIFECYCLE","Run errored:",{agentId:this.agentId,error:u instanceof Error?u.message:String(u)}),this.isRunning=!1,this.onError(r,u,o))),Je(()=>{this.debugLogger?.lifecycle("LIFECYCLE","Run finished:",{agentId:this.agentId,threadId:this.threadId}),this.isRunning=!1,this.onFinalize(r,o),a?.(),a=void 0,this.activeRunCompletionPromise=void 0,this.activeRunDetach$=void 0}))(j(null)));let l=L(this.messages).filter(u=>!s.has(u.id));return{result:n,newMessages:l}}finally{this.isRunning=!1}}connect(e){throw new En}async connectAgent(e,t){try{this.isRunning=!0,this.agentId=this.agentId??we();let r=this.prepareRunAgentInput(e),n,s=new Set(this.messages.map(u=>u.id)),o=[{onRunFinishedEvent:u=>{u.outcome==="success"&&(n=u.result)}},...this.subscribers,t??{}];await this.onInitialize(r,o),this.activeRunDetach$=new ve;let a;this.activeRunCompletionPromise=new Promise(u=>{a=u}),await xr(ar(()=>br(()=>this.connect(r)),ln(this.debugLogger),qn(this.debugLogger),u=>u.pipe(Tr(this.activeRunDetach$)),u=>this.apply(r,u,o),u=>this.processApplyEvents(r,u,o),It(u=>(this.isRunning=!1,u instanceof En?lr:this.onError(r,u,o))),Je(()=>{this.isRunning=!1,this.onFinalize(r,o),a?.(),a=void 0,this.activeRunCompletionPromise=void 0,this.activeRunDetach$=void 0}))(j(null)),{defaultValue:void 0});let l=L(this.messages).filter(u=>!s.has(u.id));return{result:n,newMessages:l}}finally{this.isRunning=!1}}abortRun(){}async detachActiveRun(){if(!this.activeRunDetach$)return;let e=this.activeRunCompletionPromise??Promise.resolve();this.activeRunDetach$.next(),this.activeRunDetach$?.complete(),await e}apply(e,t,r){return sa(e,t,this,r,this.debugLogger)}processApplyEvents(e,t,r){return t.pipe(Ln(n=>{n.messages&&(this.messages=n.messages,r.forEach(s=>{s.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:e})})),n.state&&(this.state=n.state,r.forEach(s=>{s.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:e})}))}))}prepareRunAgentInput(e){let t=L(this.messages).filter(r=>r.role!=="activity");return{threadId:this.threadId,runId:e?.runId||we(),tools:L(e?.tools??[]),context:L(e?.context??[]),forwardedProps:L(e?.forwardedProps??{}),state:L(this.state),messages:t,...e?.resume===void 0?{}:{resume:L(e.resume)}}}async onInitialize(e,t){if(this.pendingInterrupts.length>0){let n=new Set((e.resume??[]).map(o=>o.interruptId)),s=this.pendingInterrupts.map(o=>o.id).filter(o=>!n.has(o));if(s.length>0)throw new V(`Thread has ${s.length} pending interrupt(s) not addressed by resume: ${s.join(", ")}`);for(let o of this.pendingInterrupts)if(Qu(o))throw new V(`Interrupt ${o.id} expired at ${o.expiresAt}`)}let r=await G(t,this.messages,this.state,(n,s,o)=>n.onRunInitialized?.({messages:s,state:o,agent:this,input:e}));(r.messages!==void 0||r.state!==void 0)&&(r.messages&&(this.messages=r.messages,e.messages=r.messages,t.forEach(n=>{n.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:e})})),r.state&&(this.state=r.state,e.state=r.state,t.forEach(n=>{n.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:e})})))}onError(e,t,r){return Ye(G(r,this.messages,this.state,(n,s,o)=>n.onRunFailed?.({error:t,messages:s,state:o,agent:this,input:e}))).pipe(qe(n=>{let s=n;if((s.messages!==void 0||s.state!==void 0)&&(s.messages!==void 0&&(this.messages=s.messages,r.forEach(o=>{o.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:e})})),s.state!==void 0&&(this.state=s.state,r.forEach(o=>{o.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:e})}))),s.stopPropagation!==!0){let o=String(t);if(!(t.name==="AbortError"||t.message==="Fetch is aborted"||t.message==="signal is aborted without reason"||t.message==="component unmounted"||o==="component unmounted"))throw console.error("Agent execution failed:",t),t}return{}}))}async onFinalize(e,t){let r=await G(t,this.messages,this.state,(n,s,o)=>n.onRunFinalized?.({messages:s,state:o,agent:this,input:e}));(r.messages!==void 0||r.state!==void 0)&&(r.messages!==void 0&&(this.messages=r.messages,t.forEach(n=>{n.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:e})})),r.state!==void 0&&(this.state=r.state,t.forEach(n=>{n.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:e})})))}clone(){let e=Object.create(Object.getPrototypeOf(this));return e.agentId=this.agentId,e.description=this.description,e.threadId=this.threadId,e.messages=L(this.messages),e.state=L(this.state),e._debug=this._debug,e._debugLogger=this._debugLogger,e.isRunning=this.isRunning,e.subscribers=[...this.subscribers],e.middlewares=[...this.middlewares],e.pendingInterrupts=L(this.pendingInterrupts),e}addMessage(e){this.messages.push(e),(async()=>{for(let t of this.subscribers)await t.onNewMessage?.({message:e,messages:this.messages,state:this.state,agent:this});if(e.role==="assistant"&&e.toolCalls)for(let t of e.toolCalls)for(let r of this.subscribers)await r.onNewToolCall?.({toolCall:t,messages:this.messages,state:this.state,agent:this});for(let t of this.subscribers)await t.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}addMessages(e){this.messages.push(...e),(async()=>{for(let t of e){for(let r of this.subscribers)await r.onNewMessage?.({message:t,messages:this.messages,state:this.state,agent:this});if(t.role==="assistant"&&t.toolCalls)for(let r of t.toolCalls)for(let n of this.subscribers)await n.onNewToolCall?.({toolCall:r,messages:this.messages,state:this.state,agent:this})}for(let t of this.subscribers)await t.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}setMessages(e){this.messages=L(e),(async()=>{for(let t of this.subscribers)await t.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}setState(e){this.state=L(e),(async()=>{for(let t of this.subscribers)await t.onStateChanged?.({messages:this.messages,state:this.state,agent:this})})()}legacy_to_be_removed_runAgentBridged(e){this.agentId=this.agentId??we();let t=this.prepareRunAgentInput(e);return(this.middlewares.length===0?this.run(t):this.middlewares.reduceRight((r,n)=>({run:s=>n.run(s,r),get messages(){return r.messages},get state(){return r.state}}),this).run(t)).pipe(ln(this.debugLogger),qn(this.debugLogger),qu(this.threadId,t.runId,this.agentId),r=>r.pipe(qe(n=>(this.debugLogger?.event("LEGACY","Event:",n,{type:n.type}),n))))}},aa=class extends cc{requestInit(e){return{method:"POST",headers:{...this.headers,"Content-Type":"application/json",Accept:"text/event-stream"},body:JSON.stringify(e),signal:this.abortController.signal}}runAgent(e,t){return this.abortController=e?.abortController??new AbortController,super.runAgent(e,t)}abortRun(){this.abortController.abort(),super.abortRun()}constructor(e){super(e),this.abortController=new AbortController,this.url=e.url,this.headers=L(e.headers??{}),this.fetch=e.fetch??fetch}run(e){return Gu(Lu(()=>this.fetch(this.url,this.requestInit(e))),this.debugLogger)}clone(){let e=super.clone();e.url=this.url,e.headers=L(this.headers??{}),e.fetch=this.fetch;let t=new AbortController,r=this.abortController.signal;return r.aborted&&t.abort(r.reason),e.abortController=t,e}};var cn="ag-ui-chat",eo="ag-ui-submit",Te={USER:"user",ASSISTANT:"assistant"},Ot="x-destructive",Rt="x-navigates",to=10,q={PENDING:"pending",DONE:"done",ERROR:"error",DECLINED:"declined"};var Mt=class{#e;#i;#l;#o;#t;#r;constructor(t){this.#e=t.agent,this.#i=t.handlers,this.#l=t.getTools??(()=>[]),this.#o=t.getContext??(()=>[]),this.#t=t.executeTool??null,this.#r=t.onPersist??(()=>{})}get running(){return this.#e.isRunning}get messages(){return this.#e.messages}async send(t){this.#e.addMessage({id:de(),role:"user",content:t}),this.#r(this.#e.messages),await this.#n()}async resume(){await this.#n()}addToolResult(t,r){this.#e.addMessage({id:de(),role:"tool",content:r,toolCallId:t}),this.#r(this.#e.messages)}async#n(){try{await this.#u()}catch(t){this.#i.onError(t instanceof Error?t.message:String(t))}}async#u(){for(let t=0;t<to;t+=1){let r=[];if(await this.#e.runAgent({tools:this.#l(),context:this.#o()},this.#s(r)),this.#r(this.#e.messages),this.#t===null||r.length===0)return;let n=!1;for(let s of r){let o=await this.#t(s);if(o!==null){if(o.halt===!0)return;this.#e.addMessage({id:de(),role:"tool",content:o.content,toolCallId:s.id}),this.#r(this.#e.messages),n=!0}}if(!n)return}}#s(t){let r=this.#i;return{onRunInitialized(){r.onRunStart()},onTextMessageContentEvent({textMessageBuffer:n}){r.onTextDelta(n)},onTextMessageEndEvent({textMessageBuffer:n}){r.onTextEnd(n)},onToolCallEndEvent({event:n,toolCallName:s,toolCallArgs:o}){let a={id:n.toolCallId,name:s,args:o};t.push(a),r.onToolCall(a)},onRunErrorEvent({event:n}){r.onError(n.message)},onRunFinalized(){r.onRunEnd()}}}};var Pt=class{#e=new Map;register(t){if(this.#e.has(t.name))throw new Error(`tool "${t.name}" already registered`);this.#e.set(t.name,t)}has(t){return this.#e.has(t)}get(t){let r=this.#e.get(t);if(r===void 0)throw new Error(`tool "${t}" is not registered`);return r}tools(){return[...this.#e.values()].map(t=>({name:t.name,description:t.description,parameters:t.parameters}))}};function ro(e,t){return new Promise(r=>{let n=document.createElement("div");n.className="modal-overlay";let s=document.createElement("div");s.className="modal";let o=document.createElement("div");o.className="modal-title",o.textContent="Confirm action";let a=document.createElement("div");a.className="modal-body",a.textContent=`Run \u201C${t.toolName}\u201D?`;let l=document.createElement("pre");l.className="modal-args",l.textContent=JSON.stringify(t.args,null,2);let u=document.createElement("div");u.className="modal-actions";let c=document.createElement("button");c.className="modal-btn modal-btn--cancel",c.type="button",c.textContent="Cancel";let p=document.createElement("button");p.className="modal-btn modal-btn--confirm",p.type="button",p.textContent="Run";let g=w=>{n.remove(),r(w)};c.addEventListener("click",()=>g(!1)),p.addEventListener("click",()=>g(!0)),n.addEventListener("click",w=>{w.target===n&&g(!1)}),u.append(c,p),s.append(o,a,l,u),n.append(s),e.appendChild(n),p.focus()})}var no="ag-ui-chat:thread",oo="ag-ui-chat:messages:",so="ag-ui-chat:checkpoint:",Lt=class{threadId(){let t=sessionStorage.getItem(no);if(t!==null)return t;let r=de();return sessionStorage.setItem(no,r),r}loadMessages(t){return Promise.resolve(this.#e(oo+t))}saveMessages(t,r){sessionStorage.setItem(oo+t,JSON.stringify(r))}loadCheckpoint(t){return this.#e(so+t)}saveCheckpoint(t,r){let n=so+t;if(r===null){sessionStorage.removeItem(n);return}sessionStorage.setItem(n,JSON.stringify(r))}clear(t){sessionStorage.removeItem(oo+t),sessionStorage.removeItem(so+t),sessionStorage.removeItem(no)}#e(t){let r=sessionStorage.getItem(t);if(r===null)return null;try{return JSON.parse(r)}catch{return null}}};function ao(e){return new aa({url:e.endpoint,headers:e.headers??{},fetch:(t,r)=>fetch(t,r),...e.threadId!==void 0?{threadId:e.threadId}:{},...e.initialMessages!==void 0?{initialMessages:[...e.initialMessages]}:{}})}function io(e){return e[Ot]===!0}function lo(e){return e[Rt]===!0}function uo(e,t){return!t||e===null?[]:[{description:"page_map",value:JSON.stringify(e())}]}function dc(e,t){if(t===void 0)return e;let r=new URLSearchParams;for(let[s,o]of Object.entries(t))r.set(s,String(o));let n=r.toString();return n===""?e:`${e}?${n}`}function co(e,t){return[{name:"list_routes",description:"List the routes the app can navigate to.",parameters:{type:"object",properties:{},required:[]},handler:()=>e()},{name:"navigate_to_route",description:"Navigate to one of the app's routes by its id.",parameters:{type:"object",properties:{route_id:{type:"string"},params:{type:"object"}},required:["route_id"],[Rt]:!0},handler:r=>{let n=r.route_id,s=e().find(l=>l.id===n);if(s===void 0)throw new Error(`unknown route "${String(n)}"`);let o=dc(s.path,r.params),a=t();return a!==null?a(o):window.location.assign(o),{navigated:!0,path:o}}}]}function fo(e){let t=[{name:`read_${e.name}`,description:`Read the "${e.name}" state.`,parameters:{type:"object",properties:{},required:[]},handler:()=>e.read()}],r=e.write;return r!==void 0&&t.push({name:`set_${e.name}`,description:`Update the "${e.name}" state.`,parameters:{...e.schema??{type:"object"},[Ot]:!0},handler:n=>r(n)}),t}var ia=`
1
+ var lu=Object.defineProperty;var hs=(e,t)=>{for(var n in t)lu(e,n,{get:t[n],enumerable:!0})};var mr="ag-ui-chat",ms="ag-ui-submit",gs="ag-ui-toggle",We={USER:"user",ASSISTANT:"assistant"},Cn="x-destructive",vs="x-confirm",ys="x-summary",Nn="x-navigates",bs=10,me={PENDING:"pending",DONE:"done",ERROR:"error",DECLINED:"declined"},Xe={MINIMAL:"minimal",COMPACT:"compact",FULL:"full"};var cu=/\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;function ha(e,t){let n=[];return{text:e.replace(cu,(o,s)=>{let i=t[s];return i==null||i===""?(n.includes(s)||n.push(s),o):String(i)}),missing:n}}function uu(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.name=="string"&&typeof t.title=="string"&&typeof t.prompt=="string"}function xs(e){return Array.isArray(e)?e.filter(uu):[]}var Rn=class{#e=new Map;register(t){this.#e.set(t.name,t)}has(t){return this.#e.has(t)}get(t){let n=this.#e.get(t);if(n===void 0)throw new Error(`tool "${t}" is not registered`);return n}tools(){return[...this.#e.values()].map(t=>({name:t.name,description:t.description,parameters:t.parameters}))}};function Es(e){return e[Cn]===!0}function _s(e){return e[Nn]===!0}function Ts(e,t){return!t||e===null?[]:[{description:"page_map",value:JSON.stringify(e())}]}var ma=/:([A-Za-z_][A-Za-z0-9_]*)/g;function du(e){let t=[];for(let n of e.matchAll(ma)){let r=n[1];r!==void 0&&t.push(r)}return t}function pu(e,t,n){let r={...n};return{path:t.replace(ma,(s,i)=>{let a=n[i];if(a==null||String(a)==="")throw new Error(`route "${e}" requires path param "${i}"`);return delete r[i],encodeURIComponent(String(a))}),leftover:r}}function fu(e,t){let n=new URLSearchParams;for(let[o,s]of Object.entries(t))n.set(o,String(s));let r=n.toString();return r===""?e:`${e}?${r}`}function Ss(e,t){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:[]},handler:()=>e().map(n=>({...n,pathParams:du(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"],[Nn]:!0},handler:n=>{let r=n.route_id,o=e().find(p=>p.id===r);if(o===void 0)throw new Error(`unknown route "${String(r)}"`);let s=n.params??{},{path:i,leftover:a}=pu(o.id,o.path,s),u=fu(i,a),c=t();return c!==null?c(u):window.location.assign(u),{navigated:!0,path:u}}}]}function ws(e){let t=[{name:`read_${e.name}`,description:`Read the "${e.name}" state.`,parameters:{type:"object",properties:{},required:[]},handler:()=>e.read()}],n=e.write;return n!==void 0&&t.push({name:`set_${e.name}`,description:`Update the "${e.name}" state.`,parameters:{...e.schema??{type:"object"},[Cn]:!0},handler:r=>n(r)}),t}function ga(e,t){let n=document.createElement("button");return n.type="button",n.className=`confirm-btn confirm-btn--${e}`,n.textContent=t,n}function ks(e,t){return new Promise(n=>{let r=document.createElement("div");r.className="confirm",r.setAttribute("data-tool-name",t.toolName),r.setAttribute("role","group"),r.setAttribute("aria-label","Confirm action");let o=document.createElement("div");o.className="confirm-body",o.textContent=t.message??`Run \u201C${t.toolName}\u201D?`;let s=document.createElement("pre");s.className="confirm-args",s.textContent=JSON.stringify(t.args,null,2);let i=document.createElement("div");i.className="confirm-actions";let a=ga("cancel","Cancel"),u=ga("confirm","Confirm"),c=p=>{a.disabled=!0,u.disabled=!0,r.setAttribute("data-resolved",p?"confirmed":"declined"),n(p)};a.addEventListener("click",()=>c(!1)),u.addEventListener("click",()=>c(!0)),i.append(a,u),r.append(o,s,i),e.appendChild(r),u.focus()})}function va(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function hu(e){if(Array.isArray(e))return e}function mu(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r,o,s,i,a=[],u=!0,c=!1;try{if(s=(n=n.call(e)).next,t!==0)for(;!(u=(r=s.call(n)).done)&&(a.push(r.value),a.length!==t);u=!0);}catch(p){c=!0,o=p}finally{try{if(!u&&n.return!=null&&(i=n.return(),Object(i)!==i))return}finally{if(c)throw o}}return a}}function gu(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
2
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function vu(e,t){return hu(e)||mu(e,t)||yu(e,t)||gu()}function yu(e,t){if(e){if(typeof e=="string")return va(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?va(e,t):void 0}}var Na=Object.entries,ya=Object.setPrototypeOf,bu=Object.isFrozen,xu=Object.getPrototypeOf,Eu=Object.getOwnPropertyDescriptor,Se=Object.freeze,Ne=Object.seal,rn=Object.create,Ra=typeof Reflect<"u"&&Reflect,Os=Ra.apply,Ms=Ra.construct;Se||(Se=function(t){return t});Ne||(Ne=function(t){return t});Os||(Os=function(t,n){for(var r=arguments.length,o=new Array(r>2?r-2:0),s=2;s<r;s++)o[s-2]=arguments[s];return t.apply(n,o)});Ms||(Ms=function(t){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 t(...r)});var en=ce(Array.prototype.forEach),_u=ce(Array.prototype.lastIndexOf),ba=ce(Array.prototype.pop),tn=ce(Array.prototype.push),Tu=ce(Array.prototype.splice),Te=Array.isArray,Ln=ce(String.prototype.toLowerCase),As=ce(String.prototype.toString),xa=ce(String.prototype.match),nn=ce(String.prototype.replace),Ea=ce(String.prototype.indexOf),Su=ce(String.prototype.trim),wu=ce(Number.prototype.toString),ku=ce(Boolean.prototype.toString),_a=typeof BigInt>"u"?null:ce(BigInt.prototype.toString),Ta=typeof Symbol>"u"?null:ce(Symbol.prototype.toString),ne=ce(Object.prototype.hasOwnProperty),On=ce(Object.prototype.toString),ge=ce(RegExp.prototype.test),Mn=Au(TypeError);function ce(e){return function(t){t instanceof RegExp&&(t.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 Os(e,t,r)}}function Au(e){return function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return Ms(e,n)}}function P(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Ln;if(ya&&ya(e,null),!Te(t))return e;let r=t.length;for(;r--;){let o=t[r];if(typeof o=="string"){let s=n(o);s!==o&&(bu(t)||(t[r]=s),o=s)}e[o]=!0}return e}function Iu(e){for(let t=0;t<e.length;t++)ne(e,t)||(e[t]=null);return e}function xe(e){let t=rn(null);for(let r of Na(e)){var n=vu(r,2);let o=n[0],s=n[1];ne(e,o)&&(Te(s)?t[o]=Iu(s):s&&typeof s=="object"&&s.constructor===Object?t[o]=xe(s):t[o]=s)}return t}function Cu(e){switch(typeof e){case"string":return e;case"number":return wu(e);case"boolean":return ku(e);case"bigint":return _a?_a(e):"0";case"symbol":return Ta?Ta(e):"Symbol()";case"undefined":return On(e);case"function":case"object":{if(e===null)return On(e);let t=e,n=Ke(t,"toString");if(typeof n=="function"){let r=n(t);return typeof r=="string"?r:On(r)}return On(e)}default:return On(e)}}function Ke(e,t){for(;e!==null;){let r=Eu(e,t);if(r){if(r.get)return ce(r.get);if(typeof r.value=="function")return ce(r.value)}e=xu(e)}function n(){return null}return n}function Nu(e){try{return ge(e,""),!0}catch{return!1}}var Sa=Se(["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"]),Is=Se(["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"]),Cs=Se(["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"]),Ru=Se(["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"]),Ns=Se(["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"]),Ou=Se(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),wa=Se(["#text"]),ka=Se(["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"]),Rs=Se(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),Aa=Se(["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"]),gr=Se(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),Mu=Ne(/{{[\w\W]*|^[\w\W]*}}/g),Lu=Ne(/<%[\w\W]*|^[\w\W]*%>/g),Pu=Ne(/\${[\w\W]*/g),Du=Ne(/^data-[\-\w.\u00B7-\uFFFF]+$/),Uu=Ne(/^aria-[\-\w]+$/),Ia=Ne(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Gu=Ne(/^(?:\w+script|data):/i),Fu=Ne(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Hu=Ne(/^html$/i),$u=Ne(/^[a-z][.\w]*(-[.\w]+)+$/i),Ze={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,progressingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},zu=function(){return typeof window>"u"?null:window},Bu=function(t,n){if(typeof t!="object"||typeof t.createPolicy!="function")return null;let r=null,o="data-tt-policy-suffix";n&&n.hasAttribute(o)&&(r=n.getAttribute(o));let s="dompurify"+(r?"#"+r:"");try{return t.createPolicy(s,{createHTML(i){return i},createScriptURL(i){return i}})}catch{return console.warn("TrustedTypes policy "+s+" could not be created."),null}},Ca=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function Oa(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:zu(),t=C=>Oa(C);if(t.version="3.4.7",t.removed=[],!e||!e.document||e.document.nodeType!==Ze.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,o=r.currentScript;e.DocumentFragment;let s=e.HTMLTemplateElement,i=e.Node,a=e.Element,u=e.NodeFilter,c=e.NamedNodeMap;c===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let p=e.DOMParser,m=e.trustedTypes,x=a.prototype,f=Ke(x,"cloneNode"),h=Ke(x,"remove"),g=Ke(x,"nextSibling"),_=Ke(x,"childNodes"),S=Ke(x,"parentNode"),b=Ke(x,"shadowRoot"),F=Ke(x,"attributes"),Z=i&&i.prototype?Ke(i.prototype,"nodeType"):null,ae=i&&i.prototype?Ke(i.prototype,"nodeName"):null;if(typeof s=="function"){let C=n.createElement("template");C.content&&C.content.ownerDocument&&(n=C.content.ownerDocument)}let ee,ct="",rr=n,Qo=rr.implementation,Vi=rr.createNodeIterator,Zc=rr.createDocumentFragment,Kc=rr.getElementsByTagName,Yc=r.importNode,de=Ca();t.isSupported=typeof Na=="function"&&typeof S=="function"&&Qo&&Qo.createHTMLDocument!==void 0;let or=Mu,sr=Lu,ir=Pu,qc=Du,Jc=Uu,Qc=Gu,ji=Fu,eu=$u,Wi=Ia,oe=null,es=P({},[...Sa,...Is,...Cs,...Ns,...wa]),le=null,ts=P({},[...ka,...Rs,...Aa,...gr]),se=Object.seal(rn(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}})),Sn=null,ar=null,ut=Object.seal(rn(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),Xi=!0,ns=!0,Zi=!1,Ki=!0,dt=!1,wn=!0,bt=!1,rs=!1,os=!1,Kt=!1,lr=!1,cr=!1,Yi=!0,qi=!1,Ji="user-content-",ss=!0,kn=!1,Yt={},Be=null,is=P({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]),Qi=null,ea=P({},["audio","video","img","source","image","track"]),as=null,ta=P({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),ur="http://www.w3.org/1998/Math/MathML",dr="http://www.w3.org/2000/svg",Ve="http://www.w3.org/1999/xhtml",qt=Ve,ls=!1,cs=null,tu=P({},[ur,dr,Ve],As),us=P({},["mi","mo","mn","ms","mtext"]),ds=P({},["annotation-xml"]),nu=P({},["title","style","font","a","script"]),An=null,ru=["application/xhtml+xml","text/html"],ou="text/html",ie=null,Jt=null,su=n.createElement("form"),na=function(d){return d instanceof RegExp||d instanceof Function},ps=function(){let d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(Jt&&Jt===d)return;(!d||typeof d!="object")&&(d={}),d=xe(d),An=ru.indexOf(d.PARSER_MEDIA_TYPE)===-1?ou:d.PARSER_MEDIA_TYPE,ie=An==="application/xhtml+xml"?As:Ln,oe=ne(d,"ALLOWED_TAGS")&&Te(d.ALLOWED_TAGS)?P({},d.ALLOWED_TAGS,ie):es,le=ne(d,"ALLOWED_ATTR")&&Te(d.ALLOWED_ATTR)?P({},d.ALLOWED_ATTR,ie):ts,cs=ne(d,"ALLOWED_NAMESPACES")&&Te(d.ALLOWED_NAMESPACES)?P({},d.ALLOWED_NAMESPACES,As):tu,as=ne(d,"ADD_URI_SAFE_ATTR")&&Te(d.ADD_URI_SAFE_ATTR)?P(xe(ta),d.ADD_URI_SAFE_ATTR,ie):ta,Qi=ne(d,"ADD_DATA_URI_TAGS")&&Te(d.ADD_DATA_URI_TAGS)?P(xe(ea),d.ADD_DATA_URI_TAGS,ie):ea,Be=ne(d,"FORBID_CONTENTS")&&Te(d.FORBID_CONTENTS)?P({},d.FORBID_CONTENTS,ie):is,Sn=ne(d,"FORBID_TAGS")&&Te(d.FORBID_TAGS)?P({},d.FORBID_TAGS,ie):xe({}),ar=ne(d,"FORBID_ATTR")&&Te(d.FORBID_ATTR)?P({},d.FORBID_ATTR,ie):xe({}),Yt=ne(d,"USE_PROFILES")?d.USE_PROFILES&&typeof d.USE_PROFILES=="object"?xe(d.USE_PROFILES):d.USE_PROFILES:!1,Xi=d.ALLOW_ARIA_ATTR!==!1,ns=d.ALLOW_DATA_ATTR!==!1,Zi=d.ALLOW_UNKNOWN_PROTOCOLS||!1,Ki=d.ALLOW_SELF_CLOSE_IN_ATTR!==!1,dt=d.SAFE_FOR_TEMPLATES||!1,wn=d.SAFE_FOR_XML!==!1,bt=d.WHOLE_DOCUMENT||!1,Kt=d.RETURN_DOM||!1,lr=d.RETURN_DOM_FRAGMENT||!1,cr=d.RETURN_TRUSTED_TYPE||!1,os=d.FORCE_BODY||!1,Yi=d.SANITIZE_DOM!==!1,qi=d.SANITIZE_NAMED_PROPS||!1,ss=d.KEEP_CONTENT!==!1,kn=d.IN_PLACE||!1,Wi=Nu(d.ALLOWED_URI_REGEXP)?d.ALLOWED_URI_REGEXP:Ia,qt=typeof d.NAMESPACE=="string"?d.NAMESPACE:Ve,us=ne(d,"MATHML_TEXT_INTEGRATION_POINTS")&&d.MATHML_TEXT_INTEGRATION_POINTS&&typeof d.MATHML_TEXT_INTEGRATION_POINTS=="object"?xe(d.MATHML_TEXT_INTEGRATION_POINTS):P({},["mi","mo","mn","ms","mtext"]),ds=ne(d,"HTML_INTEGRATION_POINTS")&&d.HTML_INTEGRATION_POINTS&&typeof d.HTML_INTEGRATION_POINTS=="object"?xe(d.HTML_INTEGRATION_POINTS):P({},["annotation-xml"]);let y=ne(d,"CUSTOM_ELEMENT_HANDLING")&&d.CUSTOM_ELEMENT_HANDLING&&typeof d.CUSTOM_ELEMENT_HANDLING=="object"?xe(d.CUSTOM_ELEMENT_HANDLING):rn(null);if(se=rn(null),ne(y,"tagNameCheck")&&na(y.tagNameCheck)&&(se.tagNameCheck=y.tagNameCheck),ne(y,"attributeNameCheck")&&na(y.attributeNameCheck)&&(se.attributeNameCheck=y.attributeNameCheck),ne(y,"allowCustomizedBuiltInElements")&&typeof y.allowCustomizedBuiltInElements=="boolean"&&(se.allowCustomizedBuiltInElements=y.allowCustomizedBuiltInElements),dt&&(ns=!1),lr&&(Kt=!0),Yt&&(oe=P({},wa),le=rn(null),Yt.html===!0&&(P(oe,Sa),P(le,ka)),Yt.svg===!0&&(P(oe,Is),P(le,Rs),P(le,gr)),Yt.svgFilters===!0&&(P(oe,Cs),P(le,Rs),P(le,gr)),Yt.mathMl===!0&&(P(oe,Ns),P(le,Aa),P(le,gr))),ut.tagCheck=null,ut.attributeCheck=null,ne(d,"ADD_TAGS")&&(typeof d.ADD_TAGS=="function"?ut.tagCheck=d.ADD_TAGS:Te(d.ADD_TAGS)&&(oe===es&&(oe=xe(oe)),P(oe,d.ADD_TAGS,ie))),ne(d,"ADD_ATTR")&&(typeof d.ADD_ATTR=="function"?ut.attributeCheck=d.ADD_ATTR:Te(d.ADD_ATTR)&&(le===ts&&(le=xe(le)),P(le,d.ADD_ATTR,ie))),ne(d,"ADD_URI_SAFE_ATTR")&&Te(d.ADD_URI_SAFE_ATTR)&&P(as,d.ADD_URI_SAFE_ATTR,ie),ne(d,"FORBID_CONTENTS")&&Te(d.FORBID_CONTENTS)&&(Be===is&&(Be=xe(Be)),P(Be,d.FORBID_CONTENTS,ie)),ne(d,"ADD_FORBID_CONTENTS")&&Te(d.ADD_FORBID_CONTENTS)&&(Be===is&&(Be=xe(Be)),P(Be,d.ADD_FORBID_CONTENTS,ie)),ss&&(oe["#text"]=!0),bt&&P(oe,["html","head","body"]),oe.table&&(P(oe,["tbody"]),delete Sn.tbody),d.TRUSTED_TYPES_POLICY){if(typeof d.TRUSTED_TYPES_POLICY.createHTML!="function")throw Mn('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof d.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Mn('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');ee=d.TRUSTED_TYPES_POLICY,ct=ee.createHTML("")}else ee===void 0&&(ee=Bu(m,o)),ee!==null&&typeof ct=="string"&&(ct=ee.createHTML(""));(de.uponSanitizeElement.length>0||de.uponSanitizeAttribute.length>0)&&oe===es&&(oe=xe(oe)),de.uponSanitizeAttribute.length>0&&le===ts&&(le=xe(le)),Se&&Se(d),Jt=d},ra=P({},[...Is,...Cs,...Ru]),oa=P({},[...Ns,...Ou]),iu=function(d){let y=S(d);(!y||!y.tagName)&&(y={namespaceURI:qt,tagName:"template"});let k=Ln(d.tagName),W=Ln(y.tagName);return cs[d.namespaceURI]?d.namespaceURI===dr?y.namespaceURI===Ve?k==="svg":y.namespaceURI===ur?k==="svg"&&(W==="annotation-xml"||us[W]):!!ra[k]:d.namespaceURI===ur?y.namespaceURI===Ve?k==="math":y.namespaceURI===dr?k==="math"&&ds[W]:!!oa[k]:d.namespaceURI===Ve?y.namespaceURI===dr&&!ds[W]||y.namespaceURI===ur&&!us[W]?!1:!oa[k]&&(nu[k]||!ra[k]):!!(An==="application/xhtml+xml"&&cs[d.namespaceURI]):!1},Pe=function(d){tn(t.removed,{element:d});try{S(d).removeChild(d)}catch{h(d)}},xt=function(d,y){try{tn(t.removed,{attribute:y.getAttributeNode(d),from:y})}catch{tn(t.removed,{attribute:null,from:y})}if(y.removeAttribute(d),d==="is")if(Kt||lr)try{Pe(y)}catch{}else try{y.setAttribute(d,"")}catch{}},sa=function(d){let y=null,k=null;if(os)d="<remove></remove>"+d;else{let Y=xa(d,/^[\r\n\t ]+/);k=Y&&Y[0]}An==="application/xhtml+xml"&&qt===Ve&&(d='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+d+"</body></html>");let W=ee?ee.createHTML(d):d;if(qt===Ve)try{y=new p().parseFromString(W,An)}catch{}if(!y||!y.documentElement){y=Qo.createDocument(qt,"template",null);try{y.documentElement.innerHTML=ls?ct:W}catch{}}let $=y.body||y.documentElement;return d&&k&&$.insertBefore(n.createTextNode(k),$.childNodes[0]||null),qt===Ve?Kc.call(y,bt?"html":"body")[0]:bt?y.documentElement:$},ia=function(d){return Vi.call(d.ownerDocument||d,d,u.SHOW_ELEMENT|u.SHOW_COMMENT|u.SHOW_TEXT|u.SHOW_PROCESSING_INSTRUCTION|u.SHOW_CDATA_SECTION,null)},aa=function(d){d.normalize();let y=Vi.call(d.ownerDocument||d,d,u.SHOW_TEXT|u.SHOW_COMMENT|u.SHOW_CDATA_SECTION|u.SHOW_PROCESSING_INSTRUCTION,null),k=y.nextNode();for(;k;){let W=k.data;en([or,sr,ir],$=>{W=nn(W,$," ")}),k.data=W,k=y.nextNode()}},pr=function(d){let y=ae?ae(d):null;return typeof y!="string"||ie(y)!=="form"?!1:typeof d.nodeName!="string"||typeof d.textContent!="string"||typeof d.removeChild!="function"||d.attributes!==F(d)||typeof d.removeAttribute!="function"||typeof d.setAttribute!="function"||typeof d.namespaceURI!="string"||typeof d.insertBefore!="function"||typeof d.hasChildNodes!="function"||d.nodeType!==Z(d)||d.childNodes!==_(d)},In=function(d){if(!Z||typeof d!="object"||d===null)return!1;try{return Z(d)===Ze.documentFragment}catch{return!1}},fr=function(d){if(!Z||typeof d!="object"||d===null)return!1;try{return typeof Z(d)=="number"}catch{return!1}};function rt(C,d,y){en(C,k=>{k.call(t,d,y,Jt)})}let la=function(d){let y=null;if(rt(de.beforeSanitizeElements,d,null),pr(d))return Pe(d),!0;let k=ie(d.nodeName);if(rt(de.uponSanitizeElement,d,{tagName:k,allowedTags:oe}),wn&&d.hasChildNodes()&&!fr(d.firstElementChild)&&ge(/<[/\w!]/g,d.innerHTML)&&ge(/<[/\w!]/g,d.textContent)||wn&&d.namespaceURI===Ve&&k==="style"&&fr(d.firstElementChild)||d.nodeType===Ze.progressingInstruction||wn&&d.nodeType===Ze.comment&&ge(/<[/\w]/g,d.data))return Pe(d),!0;if(Sn[k]||!(ut.tagCheck instanceof Function&&ut.tagCheck(k))&&!oe[k]){if(!Sn[k]&&ua(k)&&(se.tagNameCheck instanceof RegExp&&ge(se.tagNameCheck,k)||se.tagNameCheck instanceof Function&&se.tagNameCheck(k)))return!1;if(ss&&!Be[k]){let $=S(d),Y=_(d);if(Y&&$){let Ce=Y.length;for(let je=Ce-1;je>=0;--je){let De=f(Y[je],!0);$.insertBefore(De,g(d))}}}return Pe(d),!0}return(Z?Z(d):d.nodeType)===Ze.element&&!iu(d)||(k==="noscript"||k==="noembed"||k==="noframes")&&ge(/<\/no(script|embed|frames)/i,d.innerHTML)?(Pe(d),!0):(dt&&d.nodeType===Ze.text&&(y=d.textContent,en([or,sr,ir],$=>{y=nn(y,$," ")}),d.textContent!==y&&(tn(t.removed,{element:d.cloneNode()}),d.textContent=y)),rt(de.afterSanitizeElements,d,null),!1)},ca=function(d,y,k){if(ar[y]||Yi&&(y==="id"||y==="name")&&(k in n||k in su))return!1;let W=le[y]||ut.attributeCheck instanceof Function&&ut.attributeCheck(y,d);if(!(ns&&!ar[y]&&ge(qc,y))){if(!(Xi&&ge(Jc,y))){if(!W||ar[y]){if(!(ua(d)&&(se.tagNameCheck instanceof RegExp&&ge(se.tagNameCheck,d)||se.tagNameCheck instanceof Function&&se.tagNameCheck(d))&&(se.attributeNameCheck instanceof RegExp&&ge(se.attributeNameCheck,y)||se.attributeNameCheck instanceof Function&&se.attributeNameCheck(y,d))||y==="is"&&se.allowCustomizedBuiltInElements&&(se.tagNameCheck instanceof RegExp&&ge(se.tagNameCheck,k)||se.tagNameCheck instanceof Function&&se.tagNameCheck(k))))return!1}else if(!as[y]){if(!ge(Wi,nn(k,ji,""))){if(!((y==="src"||y==="xlink:href"||y==="href")&&d!=="script"&&Ea(k,"data:")===0&&Qi[d])){if(!(Zi&&!ge(Qc,nn(k,ji,"")))){if(k)return!1}}}}}}return!0},au=P({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),ua=function(d){return!au[Ln(d)]&&ge(eu,d)},da=function(d){rt(de.beforeSanitizeAttributes,d,null);let y=d.attributes;if(!y||pr(d))return;let k={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:le,forceKeepAttr:void 0},W=y.length;for(;W--;){let $=y[W],Y=$.name,Ce=$.namespaceURI,je=$.value,De=ie(Y),fs=je,pe=Y==="value"?fs:Su(fs);if(k.attrName=De,k.attrValue=pe,k.keepAttr=!0,k.forceKeepAttr=void 0,rt(de.uponSanitizeAttribute,d,k),pe=k.attrValue,qi&&(De==="id"||De==="name")&&Ea(pe,Ji)!==0&&(xt(Y,d),pe=Ji+pe),wn&&ge(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,pe)){xt(Y,d);continue}if(De==="attributename"&&xa(pe,"href")){xt(Y,d);continue}if(k.forceKeepAttr)continue;if(!k.keepAttr){xt(Y,d);continue}if(!Ki&&ge(/\/>/i,pe)){xt(Y,d);continue}dt&&en([or,sr,ir],fa=>{pe=nn(pe,fa," ")});let pa=ie(d.nodeName);if(!ca(pa,De,pe)){xt(Y,d);continue}if(ee&&typeof m=="object"&&typeof m.getAttributeType=="function"&&!Ce)switch(m.getAttributeType(pa,De)){case"TrustedHTML":{pe=ee.createHTML(pe);break}case"TrustedScriptURL":{pe=ee.createScriptURL(pe);break}}if(pe!==fs)try{Ce?d.setAttributeNS(Ce,Y,pe):d.setAttribute(Y,pe),pr(d)?Pe(d):ba(t.removed)}catch{xt(Y,d)}}rt(de.afterSanitizeAttributes,d,null)},hr=function(d){let y=null,k=ia(d);for(rt(de.beforeSanitizeShadowDOM,d,null);y=k.nextNode();)if(rt(de.uponSanitizeShadowNode,y,null),la(y),da(y),In(y.content)&&hr(y.content),(Z?Z(y):y.nodeType)===Ze.element){let $=b?b(y):y.shadowRoot;In($)&&(Qt($),hr($))}rt(de.afterSanitizeShadowDOM,d,null)},Qt=function(d){let y=Z?Z(d):d.nodeType;if(y===Ze.element){let $=b?b(d):d.shadowRoot;In($)&&(Qt($),hr($))}let k=_?_(d):d.childNodes;if(!k)return;let W=[];en(k,$=>{tn(W,$)});for(let $ of W)Qt($);if(y===Ze.element){let $=ae?ae(d):null;if(typeof $=="string"&&ie($)==="template"){let Y=d.content;In(Y)&&Qt(Y)}}};return t.sanitize=function(C){let d=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},y=null,k=null,W=null,$=null;if(ls=!C,ls&&(C="<!-->"),typeof C!="string"&&!fr(C)&&(C=Cu(C),typeof C!="string"))throw Mn("dirty is not a string, aborting");if(!t.isSupported)return C;if(rs||ps(d),t.removed=[],typeof C=="string"&&(kn=!1),kn){let je=ae?ae(C):C.nodeName;if(typeof je=="string"){let De=ie(je);if(!oe[De]||Sn[De])throw Mn("root node is forbidden and cannot be sanitized in-place")}if(pr(C))throw Mn("root node is clobbered and cannot be sanitized in-place");Qt(C)}else if(fr(C))y=sa("<!---->"),k=y.ownerDocument.importNode(C,!0),k.nodeType===Ze.element&&k.nodeName==="BODY"||k.nodeName==="HTML"?y=k:y.appendChild(k),Qt(k);else{if(!Kt&&!dt&&!bt&&C.indexOf("<")===-1)return ee&&cr?ee.createHTML(C):C;if(y=sa(C),!y)return Kt?null:cr?ct:""}y&&os&&Pe(y.firstChild);let Y=ia(kn?C:y);for(;W=Y.nextNode();)la(W),da(W),In(W.content)&&hr(W.content);if(kn)return dt&&aa(C),C;if(Kt){if(dt&&aa(y),lr)for($=Zc.call(y.ownerDocument);y.firstChild;)$.appendChild(y.firstChild);else $=y;return(le.shadowroot||le.shadowrootmode)&&($=Yc.call(r,$,!0)),$}let Ce=bt?y.outerHTML:y.innerHTML;return bt&&oe["!doctype"]&&y.ownerDocument&&y.ownerDocument.doctype&&y.ownerDocument.doctype.name&&ge(Hu,y.ownerDocument.doctype.name)&&(Ce="<!DOCTYPE "+y.ownerDocument.doctype.name+`>
3
+ `+Ce),dt&&en([or,sr,ir],je=>{Ce=nn(Ce,je," ")}),ee&&cr?ee.createHTML(Ce):Ce},t.setConfig=function(){let C=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};ps(C),rs=!0},t.clearConfig=function(){Jt=null,rs=!1},t.isValidAttribute=function(C,d,y){Jt||ps({});let k=ie(C),W=ie(d);return ca(k,W,y)},t.addHook=function(C,d){typeof d=="function"&&tn(de[C],d)},t.removeHook=function(C,d){if(d!==void 0){let y=_u(de[C],d);return y===-1?void 0:Tu(de[C],y,1)[0]}return ba(de[C])},t.removeHooks=function(C){de[C]=[]},t.removeAllHooks=function(){de=Ca()},t}var Ma=Oa();function Us(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Tt=Us();function $a(e){Tt=e}var Et={exec:()=>null};function on(e){let t=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),o=t[r];return o||(o=e(r),t[r]=o),o}}function z(e,t=""){let n=typeof e=="string"?e:e.source,r={replace:(o,s)=>{let i=typeof s=="string"?s:s.source;return i=i.replace(Ee.caret,"$1"),n=n.replace(o,i),r},getRegex:()=>new RegExp(n,t)};return r}var Vu=((e="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+e)}catch{return!1}})(),Ee={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:e=>new RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:on(e=>new RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:on(e=>new RegExp(`^ {0,${e}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:on(e=>new RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:on(e=>new RegExp(`^ {0,${e}}#`)),htmlBeginRegex:on(e=>new RegExp(`^ {0,${e}}<(?:[a-z].*>|!--)`,"i")),blockquoteBeginRegex:on(e=>new RegExp(`^ {0,${e}}>`))},ju=/^(?:[ \t]*(?:\n|$))+/,Wu=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Xu=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Un=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Zu=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Gs=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,za=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Ba=z(za).replace(/bull/g,Gs).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Ku=z(za).replace(/bull/g,Gs).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Fs=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Yu=/^[^\n]+/,Hs=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,qu=z(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Hs).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Ju=z(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Gs).getRegex(),Er="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",$s=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Qu=z("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",$s).replace("tag",Er).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Va=z(Fs).replace("hr",Un).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Er).getRegex(),ed=z(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Va).getRegex(),zs={blockquote:ed,code:Wu,def:qu,fences:Xu,heading:Zu,hr:Un,html:Qu,lheading:Ba,list:Ju,newline:ju,paragraph:Va,table:Et,text:Yu},La=z("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Un).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Er).getRegex(),td={...zs,lheading:Ku,table:La,paragraph:z(Fs).replace("hr",Un).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",La).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Er).getRegex()},nd={...zs,html:z(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",$s).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:Et,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:z(Fs).replace("hr",Un).replace("heading",` *#{1,6} *[^
4
+ ]`).replace("lheading",Ba).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},rd=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,od=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ja=/^( {2,}|\\)\n(?!\s*$)/,sd=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,sn=/[\p{P}\p{S}]/u,_r=/[\s\p{P}\p{S}]/u,Bs=/[^\s\p{P}\p{S}]/u,id=z(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,_r).getRegex(),Wa=/(?!~)[\p{P}\p{S}]/u,ad=/(?!~)[\s\p{P}\p{S}]/u,ld=/(?:[^\s\p{P}\p{S}]|~)/u,cd=z(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",Vu?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),Xa=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,ud=z(Xa,"u").replace(/punct/g,sn).getRegex(),dd=z(Xa,"u").replace(/punct/g,Wa).getRegex(),Za="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",pd=z(Za,"gu").replace(/notPunctSpace/g,Bs).replace(/punctSpace/g,_r).replace(/punct/g,sn).getRegex(),fd=z(Za,"gu").replace(/notPunctSpace/g,ld).replace(/punctSpace/g,ad).replace(/punct/g,Wa).getRegex(),hd=z("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Bs).replace(/punctSpace/g,_r).replace(/punct/g,sn).getRegex(),md=z(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,sn).getRegex(),gd="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",vd=z(gd,"gu").replace(/notPunctSpace/g,Bs).replace(/punctSpace/g,_r).replace(/punct/g,sn).getRegex(),yd=z(/\\(punct)/,"gu").replace(/punct/g,sn).getRegex(),bd=z(/^<(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(),xd=z($s).replace("(?:-->|$)","-->").getRegex(),Ed=z("^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",xd).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),yr=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,_d=z(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",yr).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Ka=z(/^!?\[(label)\]\[(ref)\]/).replace("label",yr).replace("ref",Hs).getRegex(),Ya=z(/^!?\[(ref)\](?:\[\])?/).replace("ref",Hs).getRegex(),Td=z("reflink|nolink(?!\\()","g").replace("reflink",Ka).replace("nolink",Ya).getRegex(),Pa=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,Vs={_backpedal:Et,anyPunctuation:yd,autolink:bd,blockSkip:cd,br:ja,code:od,del:Et,delLDelim:Et,delRDelim:Et,emStrongLDelim:ud,emStrongRDelimAst:pd,emStrongRDelimUnd:hd,escape:rd,link:_d,nolink:Ya,punctuation:id,reflink:Ka,reflinkSearch:Td,tag:Ed,text:sd,url:Et},Sd={...Vs,link:z(/^!?\[(label)\]\((.*?)\)/).replace("label",yr).getRegex(),reflink:z(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",yr).getRegex()},Ls={...Vs,emStrongRDelimAst:fd,emStrongLDelim:dd,delLDelim:md,delRDelim:vd,url:z(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Pa).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:z(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Pa).getRegex()},wd={...Ls,br:z(ja).replace("{2,}","*").getRegex(),text:z(Ls.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},vr={normal:zs,gfm:td,pedantic:nd},Pn={normal:Vs,gfm:Ls,breaks:wd,pedantic:Sd},kd={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Da=e=>kd[e];function Ye(e,t){if(t){if(Ee.escapeTest.test(e))return e.replace(Ee.escapeReplace,Da)}else if(Ee.escapeTestNoEncode.test(e))return e.replace(Ee.escapeReplaceNoEncode,Da);return e}function Ua(e){try{e=encodeURI(e).replace(Ee.percentDecode,"%")}catch{return null}return e}function Ga(e,t){let n=e.replace(Ee.findPipe,(s,i,a)=>{let u=!1,c=i;for(;--c>=0&&a[c]==="\\";)u=!u;return u?"|":" |"}),r=n.split(Ee.splitPipe),o=0;if(r[0].trim()||r.shift(),r.length>0&&!r.at(-1)?.trim()&&r.pop(),t)if(r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(Ee.slashPipe,"|");return r}function pt(e,t,n){let r=e.length;if(r===0)return"";let o=0;for(;o<r;){let s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function Fa(e){let t=e.split(`
5
+ `),n=t.length-1;for(;n>=0&&Ee.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
6
+ `)}function Ad(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]==="\\")r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function Id(e,t=0){let n=t,r="";for(let o of e)if(o===" "){let s=4-n%4;r+=" ".repeat(s),n+=s}else r+=o,n++;return r}function Ha(e,t,n,r,o){let s=t.href,i=t.title||null,a=e[1].replace(o.other.outputLinkReplace,"$1");r.state.inLink=!0;let u={type:e[0].charAt(0)==="!"?"image":"link",raw:n,href:s,title:i,text:a,tokens:r.inlineTokens(a)};return r.state.inLink=!1,u}function Cd(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let o=r[1];return t.split(`
7
+ `).map(s=>{let i=s.match(n.other.beginningSpace);if(i===null)return s;let[a]=i;return a.length>=o.length?s.slice(o.length):s}).join(`
8
+ `)}var br=class{options;rules;lexer;constructor(e){this.options=e||Tt}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let n=this.options.pedantic?t[0]:Fa(t[0]),r=n.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:n,codeBlockStyle:"indented",text:r}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let n=t[0],r=Cd(n,t[3]||"",this.rules);return{type:"code",raw:n,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:r}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let n=t[2].trim();if(this.rules.other.endingHash.test(n)){let r=pt(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:pt(t[0],`
9
+ `),depth:t[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:pt(t[0],`
10
+ `)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let n=pt(t[0],`
11
+ `).split(`
12
+ `),r="",o="",s=[];for(;n.length>0;){let i=!1,a=[],u;for(u=0;u<n.length;u++)if(this.rules.other.blockquoteStart.test(n[u]))a.push(n[u]),i=!0;else if(!i)a.push(n[u]);else break;n=n.slice(u);let c=a.join(`
13
+ `),p=c.replace(this.rules.other.blockquoteSetextReplace,`
14
+ $1`).replace(this.rules.other.blockquoteSetextReplace2,"");r=r?`${r}
15
+ ${c}`:c,o=o?`${o}
16
+ ${p}`:p;let m=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(p,s,!0),this.lexer.state.top=m,n.length===0)break;let x=s.at(-1);if(x?.type==="code")break;if(x?.type==="blockquote"){let f=x,h=f.raw+`
17
+ `+n.join(`
18
+ `),g=this.blockquote(h);s[s.length-1]=g,r=r.substring(0,r.length-f.raw.length)+g.raw,o=o.substring(0,o.length-f.text.length)+g.text;break}else if(x?.type==="list"){let f=x,h=f.raw+`
19
+ `+n.join(`
20
+ `),g=this.list(h);s[s.length-1]=g,r=r.substring(0,r.length-x.raw.length)+g.raw,o=o.substring(0,o.length-f.raw.length)+g.raw,n=h.substring(s.at(-1).raw.length).split(`
21
+ `);continue}}return{type:"blockquote",raw:r,tokens:s,text:o}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[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 s=this.rules.other.listItemRegex(n),i=!1;for(;e;){let u=!1,c="",p="";if(!(t=s.exec(e))||this.rules.block.hr.test(e))break;c=t[0],e=e.substring(c.length);let m=Id(t[2].split(`
22
+ `,1)[0],t[1].length),x=e.split(`
23
+ `,1)[0],f=!m.trim(),h=0;if(this.options.pedantic?(h=2,p=m.trimStart()):f?h=t[1].length+1:(h=m.search(this.rules.other.nonSpaceChar),h=h>4?1:h,p=m.slice(h),h+=t[1].length),f&&this.rules.other.blankLine.test(x)&&(c+=x+`
24
+ `,e=e.substring(x.length+1),u=!0),!u){let g=this.rules.other.nextBulletRegex(h),_=this.rules.other.hrRegex(h),S=this.rules.other.fencesBeginRegex(h),b=this.rules.other.headingBeginRegex(h),F=this.rules.other.htmlBeginRegex(h),Z=this.rules.other.blockquoteBeginRegex(h);for(;e;){let ae=e.split(`
25
+ `,1)[0],ee;if(x=ae,this.options.pedantic?(x=x.replace(this.rules.other.listReplaceNesting," "),ee=x):ee=x.replace(this.rules.other.tabCharGlobal," "),S.test(x)||b.test(x)||F.test(x)||Z.test(x)||g.test(x)||_.test(x))break;if(ee.search(this.rules.other.nonSpaceChar)>=h||!x.trim())p+=`
26
+ `+ee.slice(h);else{if(f||m.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||S.test(m)||b.test(m)||_.test(m))break;p+=`
27
+ `+x}f=!x.trim(),c+=ae+`
28
+ `,e=e.substring(ae.length+1),m=ee.slice(h)}}o.loose||(i?o.loose=!0:this.rules.other.doubleBlankLine.test(c)&&(i=!0)),o.items.push({type:"list_item",raw:c,task:!!this.options.gfm&&this.rules.other.listIsTask.test(p),loose:!1,text:p,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 u of o.items){this.lexer.state.top=!1,u.tokens=this.lexer.blockTokens(u.text,[]);let c=u.tokens[0];if(u.task&&(c?.type==="text"||c?.type==="paragraph")){u.text=u.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 p=this.rules.other.listTaskCheckbox.exec(u.raw);if(p){let m={type:"checkbox",raw:p[0]+" ",checked:p[0]!=="[ ]"};u.checked=m.checked,o.loose?u.tokens[0]&&["paragraph","text"].includes(u.tokens[0].type)&&"tokens"in u.tokens[0]&&u.tokens[0].tokens?(u.tokens[0].raw=m.raw+u.tokens[0].raw,u.tokens[0].text=m.raw+u.tokens[0].text,u.tokens[0].tokens.unshift(m)):u.tokens.unshift({type:"paragraph",raw:m.raw,text:m.raw,tokens:[m]}):u.tokens.unshift(m)}}else u.task&&(u.task=!1);if(!o.loose){let p=u.tokens.filter(x=>x.type==="space"),m=p.length>0&&p.some(x=>this.rules.other.anyLine.test(x.raw));o.loose=m}}if(o.loose)for(let u of o.items){u.loose=!0;for(let c of u.tokens)c.type==="text"&&(c.type="paragraph")}return o}}html(e){let t=this.rules.block.html.exec(e);if(t){let n=Fa(t[0]);return{type:"html",block:!0,raw:n,pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:n}}}def(e){let t=this.rules.block.def.exec(e);if(t){let n=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),r=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",o=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:n,raw:pt(t[0],`
29
+ `),href:r,title:o}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=Ga(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),o=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split(`
30
+ `):[],s={type:"table",raw:pt(t[0],`
31
+ `),header:[],align:[],rows:[]};if(n.length===r.length){for(let i of r)this.rules.other.tableAlignRight.test(i)?s.align.push("right"):this.rules.other.tableAlignCenter.test(i)?s.align.push("center"):this.rules.other.tableAlignLeft.test(i)?s.align.push("left"):s.align.push(null);for(let i=0;i<n.length;i++)s.header.push({text:n[i],tokens:this.lexer.inline(n[i]),header:!0,align:s.align[i]});for(let i of o)s.rows.push(Ga(i,s.header.length).map((a,u)=>({text:a,tokens:this.lexer.inline(a),header:!1,align:s.align[u]})));return s}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t){let n=t[1].trim();return{type:"heading",raw:pt(t[0],`
32
+ `),depth:t[2].charAt(0)==="="?1:2,text:n,tokens:this.lexer.inline(n)}}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let n=t[1].charAt(t[1].length-1)===`
33
+ `?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:n,tokens:this.lexer.inline(n)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let n=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let s=pt(n.slice(0,-1),"\\");if((n.length-s.length)%2===0)return}else{let s=Ad(t[2],"()");if(s===-2)return;if(s>-1){let i=(t[0].indexOf("!")===0?5:4)+t[1].length+s;t[2]=t[2].substring(0,s),t[0]=t[0].substring(0,i).trim(),t[3]=""}}let r=t[2],o="";if(this.options.pedantic){let s=this.rules.other.pedanticHrefTitle.exec(r);s&&(r=s[1],o=s[3])}else o=t[3]?t[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)),Ha(t,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:o&&o.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let r=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),o=t[r.toLowerCase()];if(!o){let s=n[0].charAt(0);return{type:"text",raw:s,text:s}}return Ha(n,o,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);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,s,i,a=o,u=0,c=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,t=t.slice(-1*e.length+o);(r=c.exec(t))!==null;){if(s=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!s)continue;if(i=[...s].length,r[3]||r[4]){a+=i;continue}else if((r[5]||r[6])&&o%3&&!((o+i)%3)){u+=i;continue}if(a-=i,a>0)continue;i=Math.min(i,i+a+u);let p=[...r[0]][0].length,m=e.slice(0,o+r.index+p+i);if(Math.min(o,i)%2){let f=m.slice(1,-1);return{type:"em",raw:m,text:f,tokens:this.lexer.inlineTokens(f)}}let x=m.slice(2,-2);return{type:"strong",raw:m,text:x,tokens:this.lexer.inlineTokens(x)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let n=t[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:t[0],text:n}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e,t,n=""){let r=this.rules.inline.delLDelim.exec(e);if(r&&(!r[1]||!n||this.rules.inline.punctuation.exec(n))){let o=[...r[0]].length-1,s,i,a=o,u=this.rules.inline.delRDelim;for(u.lastIndex=0,t=t.slice(-1*e.length+o);(r=u.exec(t))!==null;){if(s=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!s||(i=[...s].length,i!==o))continue;if(r[3]||r[4]){a+=i;continue}if(a-=i,a>0)continue;i=Math.min(i,i+a);let c=[...r[0]][0].length,p=e.slice(0,o+r.index+c+i),m=p.slice(o,-o);return{type:"del",raw:p,text:m,tokens:this.lexer.inlineTokens(m)}}}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let n,r;return t[2]==="@"?(n=t[1],r="mailto:"+n):(n=t[1],r=n),{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let n,r;if(t[2]==="@")n=t[0],r="mailto:"+n;else{let o;do o=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??"";while(o!==t[0]);n=t[0],t[1]==="www."?r="http://"+t[0]:r=t[0]}return{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let n=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:n}}}},Ue=class Ps{tokens;options;state;inlineQueue;tokenizer;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Tt,this.options.tokenizer=this.options.tokenizer||new br,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:Ee,block:vr.normal,inline:Pn.normal};this.options.pedantic?(n.block=vr.pedantic,n.inline=Pn.pedantic):this.options.gfm&&(n.block=vr.gfm,this.options.breaks?n.inline=Pn.breaks:n.inline=Pn.gfm),this.tokenizer.rules=n}static get rules(){return{block:vr,inline:Pn}}static lex(t,n){return new Ps(n).lex(t)}static lexInline(t,n){return new Ps(n).inlineTokens(t)}lex(t){t=t.replace(Ee.carriageReturn,`
34
+ `),this.blockTokens(t,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(t,n=[],r=!1){this.tokenizer.lexer=this,this.options.pedantic&&(t=t.replace(Ee.tabCharGlobal," ").replace(Ee.spaceLine,""));let o=1/0;for(;t;){if(t.length<o)o=t.length;else{this.infiniteLoopError(t.charCodeAt(0));break}let s;if(this.options.extensions?.block?.some(a=>(s=a.call({lexer:this},t,n))?(t=t.substring(s.raw.length),n.push(s),!0):!1))continue;if(s=this.tokenizer.space(t)){t=t.substring(s.raw.length);let a=n.at(-1);s.raw.length===1&&a!==void 0?a.raw+=`
35
+ `:n.push(s);continue}if(s=this.tokenizer.code(t)){t=t.substring(s.raw.length);let a=n.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=(a.raw.endsWith(`
36
+ `)?"":`
37
+ `)+s.raw,a.text+=`
38
+ `+s.text,this.inlineQueue.at(-1).src=a.text):n.push(s);continue}if(s=this.tokenizer.fences(t)){t=t.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.heading(t)){t=t.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.hr(t)){t=t.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.blockquote(t)){t=t.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.list(t)){t=t.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.html(t)){t=t.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.def(t)){t=t.substring(s.raw.length);let a=n.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=(a.raw.endsWith(`
39
+ `)?"":`
40
+ `)+s.raw,a.text+=`
41
+ `+s.raw,this.inlineQueue.at(-1).src=a.text):this.tokens.links[s.tag]||(this.tokens.links[s.tag]={href:s.href,title:s.title},n.push(s));continue}if(s=this.tokenizer.table(t)){t=t.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.lheading(t)){t=t.substring(s.raw.length),n.push(s);continue}let i=t;if(this.options.extensions?.startBlock){let a=1/0,u=t.slice(1),c;this.options.extensions.startBlock.forEach(p=>{c=p.call({lexer:this},u),typeof c=="number"&&c>=0&&(a=Math.min(a,c))}),a<1/0&&a>=0&&(i=t.substring(0,a+1))}if(this.state.top&&(s=this.tokenizer.paragraph(i))){let a=n.at(-1);r&&a?.type==="paragraph"?(a.raw+=(a.raw.endsWith(`
42
+ `)?"":`
43
+ `)+s.raw,a.text+=`
44
+ `+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):n.push(s),r=i.length!==t.length,t=t.substring(s.raw.length);continue}if(s=this.tokenizer.text(t)){t=t.substring(s.raw.length);let a=n.at(-1);a?.type==="text"?(a.raw+=(a.raw.endsWith(`
45
+ `)?"":`
46
+ `)+s.raw,a.text+=`
47
+ `+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):n.push(s);continue}if(t){this.infiniteLoopError(t.charCodeAt(0));break}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){this.tokenizer.lexer=this;let r=t,o=null;if(this.tokens.links){let c=Object.keys(this.tokens.links);if(c.length>0)for(;(o=this.tokenizer.rules.inline.reflinkSearch.exec(r))!==null;)c.includes(o[0].slice(o[0].lastIndexOf("[")+1,-1))&&(r=r.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(o=this.tokenizer.rules.inline.anyPunctuation.exec(r))!==null;)r=r.slice(0,o.index)+"++"+r.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let s;for(;(o=this.tokenizer.rules.inline.blockSkip.exec(r))!==null;)s=o[2]?o[2].length:0,r=r.slice(0,o.index+s)+"["+"a".repeat(o[0].length-s-2)+"]"+r.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);r=this.options.hooks?.emStrongMask?.call({lexer:this},r)??r;let i=!1,a="",u=1/0;for(;t;){if(t.length<u)u=t.length;else{this.infiniteLoopError(t.charCodeAt(0));break}i||(a=""),i=!1;let c;if(this.options.extensions?.inline?.some(m=>(c=m.call({lexer:this},t,n))?(t=t.substring(c.raw.length),n.push(c),!0):!1))continue;if(c=this.tokenizer.escape(t)){t=t.substring(c.raw.length),n.push(c);continue}if(c=this.tokenizer.tag(t)){t=t.substring(c.raw.length),n.push(c);continue}if(c=this.tokenizer.link(t)){t=t.substring(c.raw.length),n.push(c);continue}if(c=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(c.raw.length);let m=n.at(-1);c.type==="text"&&m?.type==="text"?(m.raw+=c.raw,m.text+=c.text):n.push(c);continue}if(c=this.tokenizer.emStrong(t,r,a)){t=t.substring(c.raw.length),n.push(c);continue}if(c=this.tokenizer.codespan(t)){t=t.substring(c.raw.length),n.push(c);continue}if(c=this.tokenizer.br(t)){t=t.substring(c.raw.length),n.push(c);continue}if(c=this.tokenizer.del(t,r,a)){t=t.substring(c.raw.length),n.push(c);continue}if(c=this.tokenizer.autolink(t)){t=t.substring(c.raw.length),n.push(c);continue}if(!this.state.inLink&&(c=this.tokenizer.url(t))){t=t.substring(c.raw.length),n.push(c);continue}let p=t;if(this.options.extensions?.startInline){let m=1/0,x=t.slice(1),f;this.options.extensions.startInline.forEach(h=>{f=h.call({lexer:this},x),typeof f=="number"&&f>=0&&(m=Math.min(m,f))}),m<1/0&&m>=0&&(p=t.substring(0,m+1))}if(c=this.tokenizer.inlineText(p)){t=t.substring(c.raw.length),c.raw.slice(-1)!=="_"&&(a=c.raw.slice(-1)),i=!0;let m=n.at(-1);m?.type==="text"?(m.raw+=c.raw,m.text+=c.text):n.push(c);continue}if(t){this.infiniteLoopError(t.charCodeAt(0));break}}return n}infiniteLoopError(t){let n="Infinite loop on byte: "+t;if(this.options.silent)console.error(n);else throw new Error(n)}},xr=class{options;parser;constructor(e){this.options=e||Tt}space(e){return""}code({text:e,lang:t,escaped:n}){let r=(t||"").match(Ee.notSpaceStart)?.[0],o=e.replace(Ee.endingNewline,"")+`
48
+ `;return r?'<pre><code class="language-'+Ye(r)+'">'+(n?o:Ye(o,!0))+`</code></pre>
49
+ `:"<pre><code>"+(n?o:Ye(o,!0))+`</code></pre>
50
+ `}blockquote({tokens:e}){return`<blockquote>
51
+ ${this.parser.parse(e)}</blockquote>
52
+ `}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
53
+ `}hr(e){return`<hr>
54
+ `}list(e){let t=e.ordered,n=e.start,r="";for(let i=0;i<e.items.length;i++){let a=e.items[i];r+=this.listitem(a)}let o=t?"ol":"ul",s=t&&n!==1?' start="'+n+'"':"";return"<"+o+s+`>
55
+ `+r+"</"+o+`>
56
+ `}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>
57
+ `}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
58
+ `}table(e){let t="",n="";for(let o=0;o<e.header.length;o++)n+=this.tablecell(e.header[o]);t+=this.tablerow({text:n});let r="";for(let o=0;o<e.rows.length;o++){let s=e.rows[o];n="";for(let i=0;i<s.length;i++)n+=this.tablecell(s[i]);r+=this.tablerow({text:n})}return r&&(r=`<tbody>${r}</tbody>`),`<table>
59
+ <thead>
60
+ `+t+`</thead>
61
+ `+r+`</table>
62
+ `}tablerow({text:e}){return`<tr>
63
+ ${e}</tr>
64
+ `}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
65
+ `}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${Ye(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),o=Ua(e);if(o===null)return r;e=o;let s='<a href="'+e+'"';return t&&(s+=' title="'+Ye(t)+'"'),s+=">"+r+"</a>",s}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let o=Ua(e);if(o===null)return Ye(n);e=o;let s=`<img src="${e}" alt="${Ye(n)}"`;return t&&(s+=` title="${Ye(t)}"`),s+=">",s}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:Ye(e.text)}},js=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}checkbox({raw:e}){return e}},Ge=class Ds{options;renderer;textRenderer;constructor(t){this.options=t||Tt,this.options.renderer=this.options.renderer||new xr,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new js}static parse(t,n){return new Ds(n).parse(t)}static parseInline(t,n){return new Ds(n).parseInline(t)}parse(t){this.renderer.parser=this;let n="";for(let r=0;r<t.length;r++){let o=t[r];if(this.options.extensions?.renderers?.[o.type]){let i=o,a=this.options.extensions.renderers[i.type].call({parser:this},i);if(a!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(i.type)){n+=a||"";continue}}let s=o;switch(s.type){case"space":{n+=this.renderer.space(s);break}case"hr":{n+=this.renderer.hr(s);break}case"heading":{n+=this.renderer.heading(s);break}case"code":{n+=this.renderer.code(s);break}case"table":{n+=this.renderer.table(s);break}case"blockquote":{n+=this.renderer.blockquote(s);break}case"list":{n+=this.renderer.list(s);break}case"checkbox":{n+=this.renderer.checkbox(s);break}case"html":{n+=this.renderer.html(s);break}case"def":{n+=this.renderer.def(s);break}case"paragraph":{n+=this.renderer.paragraph(s);break}case"text":{n+=this.renderer.text(s);break}default:{let i='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(i),"";throw new Error(i)}}}return n}parseInline(t,n=this.renderer){this.renderer.parser=this;let r="";for(let o=0;o<t.length;o++){let s=t[o];if(this.options.extensions?.renderers?.[s.type]){let a=this.options.extensions.renderers[s.type].call({parser:this},s);if(a!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type)){r+=a||"";continue}}let i=s;switch(i.type){case"escape":{r+=n.text(i);break}case"html":{r+=n.html(i);break}case"link":{r+=n.link(i);break}case"image":{r+=n.image(i);break}case"checkbox":{r+=n.checkbox(i);break}case"strong":{r+=n.strong(i);break}case"em":{r+=n.em(i);break}case"codespan":{r+=n.codespan(i);break}case"br":{r+=n.br(i);break}case"del":{r+=n.del(i);break}case"text":{r+=n.text(i);break}default:{let a='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return r}},Dn=class{options;block;constructor(e){this.options=e||Tt}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?Ue.lex:Ue.lexInline}provideParser(e=this.block){return e?Ge.parse:Ge.parseInline}},Nd=class{defaults=Us();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Ge;Renderer=xr;TextRenderer=js;Lexer=Ue;Tokenizer=br;Hooks=Dn;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case"table":{let o=r;for(let s of o.header)n=n.concat(this.walkTokens(s.tokens,t));for(let s of o.rows)for(let i of s)n=n.concat(this.walkTokens(i.tokens,t));break}case"list":{let o=r;n=n.concat(this.walkTokens(o.items,t));break}default:{let o=r;this.defaults.extensions?.childTokens?.[o.type]?this.defaults.extensions.childTokens[o.type].forEach(s=>{let i=o[s].flat(1/0);n=n.concat(this.walkTokens(i,t))}):o.tokens&&(n=n.concat(this.walkTokens(o.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.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 s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.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 s=t[o.level];s?s.unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}"childTokens"in o&&o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){let o=this.defaults.renderer||new xr(this.defaults);for(let s in n.renderer){if(!(s in o))throw new Error(`renderer '${s}' does not exist`);if(["options","parser"].includes(s))continue;let i=s,a=n.renderer[i],u=o[i];o[i]=(...c)=>{let p=a.apply(o,c);return p===!1&&(p=u.apply(o,c)),p||""}}r.renderer=o}if(n.tokenizer){let o=this.defaults.tokenizer||new br(this.defaults);for(let s in n.tokenizer){if(!(s in o))throw new Error(`tokenizer '${s}' does not exist`);if(["options","rules","lexer"].includes(s))continue;let i=s,a=n.tokenizer[i],u=o[i];o[i]=(...c)=>{let p=a.apply(o,c);return p===!1&&(p=u.apply(o,c)),p}}r.tokenizer=o}if(n.hooks){let o=this.defaults.hooks||new Dn;for(let s in n.hooks){if(!(s in o))throw new Error(`hook '${s}' does not exist`);if(["options","block"].includes(s))continue;let i=s,a=n.hooks[i],u=o[i];Dn.passThroughHooks.has(s)?o[i]=c=>{if(this.defaults.async&&Dn.passThroughHooksRespectAsync.has(s))return(async()=>{let m=await a.call(o,c);return u.call(o,m)})();let p=a.call(o,c);return u.call(o,p)}:o[i]=(...c)=>{if(this.defaults.async)return(async()=>{let m=await a.apply(o,c);return m===!1&&(m=await u.apply(o,c)),m})();let p=a.apply(o,c);return p===!1&&(p=u.apply(o,c)),p}}r.hooks=o}if(n.walkTokens){let o=this.defaults.walkTokens,s=n.walkTokens;r.walkTokens=function(i){let a=[];return a.push(s.call(this,i)),o&&(a=a.concat(o.call(this,i))),a}}this.defaults={...this.defaults,...r}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return Ue.lex(e,t??this.defaults)}parser(e,t){return Ge.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},o={...this.defaults,...r},s=this.onError(!!o.silent,!!o.async);if(this.defaults.async===!0&&r.async===!1)return s(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 t>"u"||t===null)return s(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return s(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(o.hooks&&(o.hooks.options=o,o.hooks.block=e),o.async)return(async()=>{let i=o.hooks?await o.hooks.preprocess(t):t,a=await(o.hooks?await o.hooks.provideLexer(e):e?Ue.lex:Ue.lexInline)(i,o),u=o.hooks?await o.hooks.processAllTokens(a):a;o.walkTokens&&await Promise.all(this.walkTokens(u,o.walkTokens));let c=await(o.hooks?await o.hooks.provideParser(e):e?Ge.parse:Ge.parseInline)(u,o);return o.hooks?await o.hooks.postprocess(c):c})().catch(s);try{o.hooks&&(t=o.hooks.preprocess(t));let i=(o.hooks?o.hooks.provideLexer(e):e?Ue.lex:Ue.lexInline)(t,o);o.hooks&&(i=o.hooks.processAllTokens(i)),o.walkTokens&&this.walkTokens(i,o.walkTokens);let a=(o.hooks?o.hooks.provideParser(e):e?Ge.parse:Ge.parseInline)(i,o);return o.hooks&&(a=o.hooks.postprocess(a)),a}catch(i){return s(i)}}}onError(e,t){return n=>{if(n.message+=`
66
+ Please report this to https://github.com/markedjs/marked.`,e){let r="<p>An error occurred:</p><pre>"+Ye(n.message+"",!0)+"</pre>";return t?Promise.resolve(r):r}if(t)return Promise.reject(n);throw n}}},_t=new Nd;function j(e,t){return _t.parse(e,t)}j.options=j.setOptions=function(e){return _t.setOptions(e),j.defaults=_t.defaults,$a(j.defaults),j};j.getDefaults=Us;j.defaults=Tt;j.use=function(...e){return _t.use(...e),j.defaults=_t.defaults,$a(j.defaults),j};j.walkTokens=function(e,t){return _t.walkTokens(e,t)};j.parseInline=_t.parseInline;j.Parser=Ge;j.parser=Ge.parse;j.Renderer=xr;j.TextRenderer=js;j.Lexer=Ue;j.lexer=Ue.lex;j.Tokenizer=br;j.Hooks=Dn;j.parse=j;var ug=j.options,dg=j.setOptions,pg=j.use,fg=j.walkTokens,hg=j.parseInline;var mg=Ge.parse,gg=Ue.lex;j.setOptions({gfm:!0,breaks:!0});var Rd=["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","img"],Od=["href","title","class","src","alt","width","height"];function Tr(e){let t=j.parse(e,{async:!1}),n=Ma.sanitize(t,{ALLOWED_TAGS:Rd,ALLOWED_ATTR:Od}),r=document.createElement("template");r.innerHTML=n;for(let o of r.content.querySelectorAll("a[href]"))o.setAttribute("target","_blank"),o.setAttribute("rel","noopener noreferrer");return r.innerHTML.trim()}function qa(e,t){for(let n of Array.from(e.childNodes))n.nodeType===Node.TEXT_NODE?t.push({node:n,parent:e}):qa(n,t)}function Ja(e){let t=[];qa(e,t);let n=0;for(let{node:r,parent:o}of t){let s=document.createDocumentFragment();for(let i of r.data.split(/(\s+)/)){if(i==="")continue;if(/\s/.test(i)){s.appendChild(document.createTextNode(i));continue}let a=document.createElement("span");a.className="word",a.style.setProperty("--ag-ui-word-index",String(n)),a.textContent=i,s.appendChild(a),n+=1}o.replaceChild(s,r)}}var Sr=class{chips;palette;#e;#r=[];#i=!1;#l=!1;#t=[];#n=0;constructor(t){this.#e=t,this.chips=document.createElement("div"),this.chips.className="skill-chips",this.chips.hidden=!0,this.palette=document.createElement("div"),this.palette.className="skill-palette",this.palette.setAttribute("role","listbox"),this.palette.hidden=!0}setSkills(t){this.#r=t,this.#a()}enableChips(t){this.#i=t,this.#a()}enableSlash(t){this.#l=t}isOpen(){return!this.palette.hidden}onInput(t){this.#l&&t.startsWith("/")?this.#o(t.slice(1)):this.close()}onKeydown(t){return this.isOpen()?t.key==="ArrowDown"?(this.#u(1),!0):t.key==="ArrowUp"?(this.#u(-1),!0):t.key==="Escape"?(this.close(),!0):t.key==="Enter"?(this.#t.slice(this.#n,this.#n+1).forEach(n=>{this.#s(n)}),!0):!1:!1}close(){this.palette.hidden=!0,this.palette.replaceChildren()}#o(t){let n=t.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.#t=r,this.#n=0,this.#p(),this.palette.hidden=!1}#u(t){let n=this.#t.length;this.#n=(this.#n+t+n)%n,this.#p()}#s(t){this.close(),this.#e(t)}#a(){this.chips.replaceChildren();let t=this.#i?this.#r.filter(n=>n.chip===!0):[];this.chips.hidden=t.length===0;for(let n of t){let r=document.createElement("button");r.type="button",r.className="skill-chip",r.textContent=n.title,r.addEventListener("click",()=>this.#s(n)),this.chips.appendChild(r)}}#p(){this.palette.replaceChildren(),this.#t.forEach((t,n)=>{let r=document.createElement("button");r.type="button",r.className="skill-item",r.setAttribute("role","option"),r.setAttribute("aria-selected",n===this.#n?"true":"false");let o=document.createElement("span");if(o.className="skill-item-title",o.textContent=t.title,r.appendChild(o),t.description!==void 0){let s=document.createElement("span");s.className="skill-item-desc",s.textContent=t.description,r.appendChild(s)}r.addEventListener("click",()=>this.#s(t)),this.palette.appendChild(r)})}};var Qa=`
12
67
  :host {
13
68
  /* Colors */
14
69
  --ag-ui-bg: #ffffff;
@@ -34,6 +89,13 @@ Error: ${E}`)}}return p()}case h.MESSAGES_SNAPSHOT:{let d=await G(n,a,l,(f,m,E)=
34
89
  --ag-ui-shadow: 0 12px 32px rgba(20, 20, 50, 0.18);
35
90
  --ag-ui-font: inherit;
36
91
  --ag-ui-font-size: 14px;
92
+ --ag-ui-code-font: ui-monospace, "SF Mono", Menlo, monospace;
93
+
94
+ /* Spacing \u2014 the density preset overrides these. */
95
+ --ag-ui-space: 10px;
96
+ --ag-ui-pad: 16px;
97
+ --ag-ui-msg-pad: 8px 12px;
98
+ --ag-ui-msg-radius: 14px;
37
99
 
38
100
  /* Layout \u2014 override from outside to dock the widget anywhere.
39
101
  Set --ag-ui-position: static (and place this element in your own
@@ -59,6 +121,91 @@ Error: ${E}`)}}return p()}case h.MESSAGES_SNAPSHOT:{let d=await G(n,a,l,(f,m,E)=
59
121
  color: var(--ag-ui-fg);
60
122
  }
61
123
 
124
+ /* \u2500\u2500 Themes \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\u2500\u2500\u2500\u2500
125
+ Themes only re-set the colour variables; layout/spacing are unaffected.
126
+ theme="auto" follows the OS via prefers-color-scheme. */
127
+ :host([theme="dark"]) {
128
+ --ag-ui-bg: #15151f;
129
+ --ag-ui-fg: #e8e8f2;
130
+ --ag-ui-assistant-bg: #25253a;
131
+ --ag-ui-header-bg: #1f1f30;
132
+ --ag-ui-header-fg: #e8e8f2;
133
+ --ag-ui-border: #33334a;
134
+ --ag-ui-muted: #9aa0b4;
135
+ --ag-ui-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
136
+ }
137
+
138
+ @media (prefers-color-scheme: dark) {
139
+ :host([theme="auto"]) {
140
+ --ag-ui-bg: #15151f;
141
+ --ag-ui-fg: #e8e8f2;
142
+ --ag-ui-assistant-bg: #25253a;
143
+ --ag-ui-header-bg: #1f1f30;
144
+ --ag-ui-header-fg: #e8e8f2;
145
+ --ag-ui-border: #33334a;
146
+ --ag-ui-muted: #9aa0b4;
147
+ --ag-ui-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
148
+ }
149
+ }
150
+
151
+ /* A terminal-flavoured "code" theme: dark, monospace, green accent. */
152
+ :host([theme="code"]) {
153
+ --ag-ui-bg: #0d1117;
154
+ --ag-ui-fg: #c9d1d9;
155
+ --ag-ui-accent: #3fb950;
156
+ --ag-ui-user-bg: #238636;
157
+ --ag-ui-assistant-bg: #161b22;
158
+ --ag-ui-header-bg: #010409;
159
+ --ag-ui-header-fg: #c9d1d9;
160
+ --ag-ui-border: #30363d;
161
+ --ag-ui-muted: #8b949e;
162
+ --ag-ui-font: var(--ag-ui-code-font);
163
+ --ag-ui-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
164
+ }
165
+
166
+ /* \u2500\u2500 Density \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\u2500\u2500\u2500\u2500\u2500 */
167
+ :host([density="compact"]) {
168
+ --ag-ui-font-size: 13px;
169
+ --ag-ui-space: 6px;
170
+ --ag-ui-pad: 10px;
171
+ --ag-ui-msg-pad: 5px 9px;
172
+ --ag-ui-msg-radius: 10px;
173
+ }
174
+
175
+ /* \u2500\u2500 Placement presets \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 */
176
+ :host([placement="bottom-left"]) {
177
+ --ag-ui-inset: auto auto 24px 24px;
178
+ }
179
+
180
+ :host([placement="side"]) {
181
+ --ag-ui-inset: 0 0 0 auto;
182
+ --ag-ui-width: 420px;
183
+ --ag-ui-height: 100vh;
184
+ --ag-ui-max-height: 100vh;
185
+ --ag-ui-radius: 0;
186
+ }
187
+
188
+ :host([placement="full"]) {
189
+ --ag-ui-inset: 0;
190
+ --ag-ui-width: 100vw;
191
+ --ag-ui-height: 100vh;
192
+ --ag-ui-max-width: 100vw;
193
+ --ag-ui-max-height: 100vh;
194
+ --ag-ui-radius: 0;
195
+ }
196
+
197
+ /* Embedded: drop the floating chrome and the high z-index stacking context so
198
+ the widget lives in the host's own layout (fixes overlay/z-index clashes). */
199
+ :host([placement="embedded"]) {
200
+ --ag-ui-position: static;
201
+ --ag-ui-width: 100%;
202
+ --ag-ui-height: 100%;
203
+ --ag-ui-max-width: 100%;
204
+ --ag-ui-max-height: 100%;
205
+ --ag-ui-shadow: none;
206
+ --ag-ui-z-index: auto;
207
+ }
208
+
62
209
  .chat {
63
210
  position: relative;
64
211
  display: flex;
@@ -73,31 +220,114 @@ Error: ${E}`)}}return p()}case h.MESSAGES_SNAPSHOT:{let d=await G(n,a,l,(f,m,E)=
73
220
  }
74
221
 
75
222
  .header {
76
- padding: 12px 16px;
77
- font-weight: 600;
223
+ display: flex;
224
+ align-items: center;
225
+ justify-content: space-between;
226
+ gap: 8px;
227
+ padding: 10px 14px;
78
228
  border-bottom: 1px solid var(--ag-ui-border);
79
229
  background: var(--ag-ui-header-bg);
80
230
  color: var(--ag-ui-header-fg);
81
231
  }
82
232
 
233
+ .header-title {
234
+ font-weight: 600;
235
+ overflow: hidden;
236
+ text-overflow: ellipsis;
237
+ white-space: nowrap;
238
+ }
239
+
240
+ .header-controls {
241
+ display: flex;
242
+ gap: 2px;
243
+ flex: none;
244
+ }
245
+
246
+ .header-btn {
247
+ border: none;
248
+ background: transparent;
249
+ color: inherit;
250
+ font: inherit;
251
+ line-height: 1;
252
+ padding: 4px 7px;
253
+ border-radius: 6px;
254
+ cursor: pointer;
255
+ opacity: 0.85;
256
+ }
257
+
258
+ .header-btn:hover {
259
+ opacity: 1;
260
+ background: rgba(255, 255, 255, 0.18);
261
+ }
262
+
263
+ /* Collapsed: keep just the header bar \u2014 hide the whole body, and let the host
264
+ shrink to the header. (A host can also fully hide the element itself.) */
265
+ :host([collapsed]) {
266
+ height: auto;
267
+ max-height: none;
268
+ }
269
+
270
+ :host([collapsed]) .messages,
271
+ :host([collapsed]) .input-row,
272
+ :host([collapsed]) .skill-chips,
273
+ :host([collapsed]) .skill-palette,
274
+ :host([collapsed]) .skill-hint {
275
+ display: none;
276
+ }
277
+
278
+ /* Edge-docked placements pin top *and* bottom, which would otherwise keep the
279
+ panel full-height when collapsed; unpin the bottom so it shrinks to the
280
+ header. (Floating/bottom-left pin only the bottom, so they already shrink.) */
281
+ :host([collapsed][placement="side"]),
282
+ :host([collapsed][placement="full"]) {
283
+ bottom: auto;
284
+ }
285
+
83
286
  .messages {
84
287
  flex: 1;
85
288
  overflow-y: auto;
86
- padding: 16px;
289
+ padding: var(--ag-ui-pad);
87
290
  display: flex;
88
291
  flex-direction: column;
89
- gap: 10px;
292
+ gap: var(--ag-ui-space);
90
293
  }
91
294
 
92
295
  .message {
93
296
  max-width: 80%;
94
- padding: 8px 12px;
95
- border-radius: 14px;
297
+ padding: var(--ag-ui-msg-pad);
298
+ border-radius: var(--ag-ui-msg-radius);
96
299
  line-height: 1.4;
97
300
  white-space: pre-wrap;
98
301
  word-break: break-word;
99
302
  }
100
303
 
304
+ /* \u2500\u2500 Incoming-text animations (data-text-animation) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
305
+ :host([data-text-animation="fade"]) .message--assistant {
306
+ animation: ag-ui-msg-fade 0.25s ease both;
307
+ }
308
+
309
+ @keyframes ag-ui-msg-fade {
310
+ from { opacity: 0; transform: translateY(4px); }
311
+ to { opacity: 1; transform: none; }
312
+ }
313
+
314
+ .message--assistant .word {
315
+ animation: ag-ui-word-in 0.3s ease both;
316
+ animation-delay: calc(var(--ag-ui-word-index, 0) * 35ms);
317
+ }
318
+
319
+ @keyframes ag-ui-word-in {
320
+ from { opacity: 0; }
321
+ to { opacity: 1; }
322
+ }
323
+
324
+ @media (prefers-reduced-motion: reduce) {
325
+ :host([data-text-animation="fade"]) .message--assistant,
326
+ .message--assistant .word {
327
+ animation: none;
328
+ }
329
+ }
330
+
101
331
  .message--user {
102
332
  align-self: flex-end;
103
333
  background: var(--ag-ui-user-bg);
@@ -109,6 +339,102 @@ Error: ${E}`)}}return p()}case h.MESSAGES_SNAPSHOT:{let d=await G(n,a,l,(f,m,E)=
109
339
  align-self: flex-start;
110
340
  background: var(--ag-ui-assistant-bg);
111
341
  border-bottom-left-radius: 4px;
342
+ /* Assistant bubbles hold rendered markdown/HTML, so collapse the source
343
+ whitespace the renderer leaves between block tags. */
344
+ white-space: normal;
345
+ }
346
+
347
+ /* Rendered-markdown elements inside an assistant bubble. */
348
+ .message--assistant > :first-child {
349
+ margin-top: 0;
350
+ }
351
+
352
+ .message--assistant > :last-child {
353
+ margin-bottom: 0;
354
+ }
355
+
356
+ .message--assistant p,
357
+ .message--assistant ul,
358
+ .message--assistant ol,
359
+ .message--assistant blockquote,
360
+ .message--assistant pre {
361
+ margin: 0.5em 0;
362
+ }
363
+
364
+ .message--assistant ul,
365
+ .message--assistant ol {
366
+ padding-left: 1.3em;
367
+ }
368
+
369
+ .message--assistant a {
370
+ color: var(--ag-ui-accent);
371
+ text-decoration: underline;
372
+ }
373
+
374
+ .message--assistant code {
375
+ font-family: ui-monospace, "SF Mono", Menlo, monospace;
376
+ font-size: 0.92em;
377
+ background: rgba(127, 127, 127, 0.16);
378
+ padding: 1px 4px;
379
+ border-radius: 4px;
380
+ }
381
+
382
+ .message--assistant pre {
383
+ padding: 8px 10px;
384
+ overflow: auto;
385
+ background: var(--ag-ui-bg);
386
+ border: 1px solid var(--ag-ui-border);
387
+ border-radius: 6px;
388
+ }
389
+
390
+ .message--assistant pre code {
391
+ background: none;
392
+ padding: 0;
393
+ }
394
+
395
+ .message--assistant blockquote {
396
+ padding-left: 10px;
397
+ border-left: 3px solid var(--ag-ui-border);
398
+ color: var(--ag-ui-muted);
399
+ }
400
+
401
+ .pending {
402
+ align-self: flex-start;
403
+ display: inline-flex;
404
+ gap: 4px;
405
+ align-items: center;
406
+ padding: 12px 14px;
407
+ background: var(--ag-ui-assistant-bg);
408
+ border-radius: 14px;
409
+ border-bottom-left-radius: 4px;
410
+ }
411
+
412
+ .pending-dot {
413
+ width: 6px;
414
+ height: 6px;
415
+ border-radius: 50%;
416
+ background: var(--ag-ui-muted);
417
+ animation: ag-ui-pending 1.2s infinite ease-in-out both;
418
+ }
419
+
420
+ .pending-dot:nth-child(2) {
421
+ animation-delay: 0.16s;
422
+ }
423
+
424
+ .pending-dot:nth-child(3) {
425
+ animation-delay: 0.32s;
426
+ }
427
+
428
+ @keyframes ag-ui-pending {
429
+ 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
430
+ 40% { opacity: 1; transform: translateY(-3px); }
431
+ }
432
+
433
+ @media (prefers-reduced-motion: reduce) {
434
+ .pending-dot {
435
+ animation: none;
436
+ opacity: 0.6;
437
+ }
112
438
  }
113
439
 
114
440
  .tool-call {
@@ -233,38 +559,30 @@ Error: ${E}`)}}return p()}case h.MESSAGES_SNAPSHOT:{let d=await G(n,a,l,(f,m,E)=
233
559
  cursor: default;
234
560
  }
235
561
 
236
- .modal-overlay {
237
- position: absolute;
238
- inset: 0;
562
+ /* Inline confirmation card \u2014 lives in the transcript, no focus-stealing overlay. */
563
+ .confirm {
564
+ align-self: stretch;
565
+ box-sizing: border-box;
239
566
  display: flex;
240
- align-items: center;
241
- justify-content: center;
242
- padding: 16px;
243
- background: rgba(20, 20, 50, 0.4);
244
- backdrop-filter: blur(2px);
245
- }
246
-
247
- .modal {
248
- width: 100%;
249
- max-width: 320px;
567
+ flex-direction: column;
568
+ gap: 8px;
569
+ padding: 12px;
250
570
  background: var(--ag-ui-bg);
251
- border-radius: 12px;
252
- box-shadow: 0 16px 40px rgba(20, 20, 50, 0.3);
253
- overflow: hidden;
571
+ border: 1px solid var(--ag-ui-accent);
572
+ border-radius: 10px;
254
573
  }
255
574
 
256
- .modal-title {
257
- padding: 12px 16px;
258
- font-weight: 600;
259
- border-bottom: 1px solid var(--ag-ui-border);
575
+ .confirm[data-resolved] {
576
+ opacity: 0.7;
577
+ border-color: var(--ag-ui-border);
260
578
  }
261
579
 
262
- .modal-body {
263
- padding: 12px 16px 4px;
580
+ .confirm-body {
581
+ font-weight: 600;
264
582
  }
265
583
 
266
- .modal-args {
267
- margin: 0 16px 12px;
584
+ .confirm-args {
585
+ margin: 0;
268
586
  padding: 8px 10px;
269
587
  max-height: 140px;
270
588
  overflow: auto;
@@ -276,14 +594,13 @@ Error: ${E}`)}}return p()}case h.MESSAGES_SNAPSHOT:{let d=await G(n,a,l,(f,m,E)=
276
594
  word-break: break-word;
277
595
  }
278
596
 
279
- .modal-actions {
597
+ .confirm-actions {
280
598
  display: flex;
281
599
  gap: 8px;
282
- padding: 0 16px 16px;
283
600
  justify-content: flex-end;
284
601
  }
285
602
 
286
- .modal-btn {
603
+ .confirm-btn {
287
604
  border: 1px solid var(--ag-ui-border);
288
605
  border-radius: 8px;
289
606
  padding: 8px 14px;
@@ -294,14 +611,102 @@ Error: ${E}`)}}return p()}case h.MESSAGES_SNAPSHOT:{let d=await G(n,a,l,(f,m,E)=
294
611
  color: var(--ag-ui-fg);
295
612
  }
296
613
 
297
- .modal-btn--confirm {
614
+ .confirm-btn:disabled {
615
+ cursor: default;
616
+ opacity: 0.6;
617
+ }
618
+
619
+ .confirm-btn--confirm {
298
620
  border-color: var(--ag-ui-accent);
299
621
  background: var(--ag-ui-accent);
300
622
  color: #ffffff;
301
623
  }
302
- `;var la={[q.PENDING]:"running\u2026",[q.DONE]:"\u2713 done",[q.ERROR]:"\u26A0 error",[q.DECLINED]:"\u2298 declined"},fc={[q.DONE]:"Result",[q.ERROR]:"Error",[q.DECLINED]:"Declined"},Dt=class{element;#e;constructor(t,r){this.element=document.createElement("div"),this.element.className="tool-call",this.element.setAttribute("data-tool-name",t),this.element.setAttribute("data-status",q.PENDING);let n=document.createElement("div");n.className="tool-call-head";let s=document.createElement("span");s.className="tool-call-name",s.textContent=`\u{1F527} ${t}`,this.#e=document.createElement("span"),this.#e.className="tool-call-status",this.#e.textContent=la[q.PENDING],n.append(s,this.#e);let o=document.createElement("pre");o.className="tool-call-args",o.textContent=JSON.stringify(r,null,2),this.element.append(n,o)}settle(t,r){this.element.setAttribute("data-status",t),this.#e.textContent=la[t];let n=document.createElement("button");n.type="button",n.className="tool-call-toggle",n.setAttribute("aria-expanded","false"),n.textContent=fc[t];let s=document.createElement("pre");s.className="tool-call-result",s.textContent=r,s.hidden=!0,n.addEventListener("click",()=>{let o=s.hidden;s.hidden=!o,n.setAttribute("aria-expanded",String(o))}),this.element.append(n,s)}};var Ut=class extends HTMLElement{agentFactory=ao;headers={};autoConfirm=!1;getTools=()=>[...this.#d().map(t=>({name:t.name,description:t.description,parameters:t.parameters})),...this.#e.tools()];getContext=()=>uo(this.getPageMap,this.autoInjectPageMap);routeMap=[];navigate=null;getPageMap=null;autoInjectPageMap=!0;conversationStore=new Lt;navigationResult=()=>({navigated:!0,url:window.location.href});#e=new Pt;#i=new Map;#l;#o;#t;#r;#n;#u=null;#s=null;#a="";#c=[];constructor(){super(),this.#l=this.attachShadow({mode:"open"}),this.#o=document.createElement("div"),this.#t=document.createElement("div"),this.#r=document.createElement("textarea"),this.#n=document.createElement("button")}registerTool(t){this.#e.register(t)}registerStateHook(t){for(let r of fo(t))this.#e.register(r)}#d(){return this.routeMap.length===0?[]:co(()=>this.routeMap,()=>this.navigate)}#g(t){let r=this.#d().find(n=>n.name===t);return r!==void 0?r:this.#e.has(t)?this.#e.get(t):null}get endpoint(){return this.getAttribute("endpoint")??""}connectedCallback(){this.#_(),this.#a=this.conversationStore.threadId(),this.#v()}async#v(){let t=await this.conversationStore.loadMessages(this.#a);if(t!==null){this.#c=t;for(let n of t)this.#y(n)}let r=this.conversationStore.loadCheckpoint(this.#a);r!==null&&await this.#E(r)}#y(t){typeof t.content!="string"||t.content===""||(t.role===Te.USER?this.appendMessage(Te.USER,t.content):t.role===Te.ASSISTANT&&this.appendMessage(Te.ASSISTANT,t.content))}async#E(t){this.conversationStore.saveCheckpoint(this.#a,null);let r=this.#p();r.addToolResult(t.toolCallId,JSON.stringify(this.navigationResult(t))),await r.resume()}appendMessage(t,r){let n=document.createElement("div");return n.className=`message message--${t}`,n.textContent=r,this.#t.appendChild(n),this.#t.scrollTop=this.#t.scrollHeight,n}#_(){let t=document.createElement("style");t.textContent=ia,this.#o.className="chat";let r=document.createElement("div");r.className="header",r.textContent=this.getAttribute("title-text")??"Assistant",this.#t.className="messages";let n=document.createElement("div");n.className="input-row",this.#r.className="input",this.#r.rows=2,this.#r.placeholder="Ask anything\u2026",this.#r.addEventListener("keydown",s=>this.#x(s)),this.#n.className="send",this.#n.type="button",this.#n.textContent="Send",this.#n.addEventListener("click",()=>{this.#f()}),n.append(this.#r,this.#n),this.#o.append(r,this.#t,n),this.#l.append(t,this.#o)}#x(t){t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),this.#f())}async#f(){let t=this.#r.value.trim();t!==""&&(this.appendMessage(Te.USER,t),this.#r.value="",this.dispatchEvent(new CustomEvent(eo,{detail:{content:t},bubbles:!0,composed:!0})),await this.#b(t))}async#b(t){this.endpoint!==""&&await this.#p().send(t)}#p(){if(this.#u===null){let t=this.agentFactory({endpoint:this.endpoint,headers:this.headers,threadId:this.#a,initialMessages:this.#c});this.#u=new Mt({agent:t,handlers:this.#T(),getTools:()=>this.getTools(),getContext:()=>this.getContext(),executeTool:r=>this.#S(r),onPersist:r=>this.conversationStore.saveMessages(this.#a,r)})}return this.#u}async#S(t){let r=this.#h(t);this.#i.delete(t.id);let n=this.#g(t.name);if(n===null)return r.settle(q.DONE,"Executed on the server."),null;if(io(n.parameters)&&!this.autoConfirm&&!await ro(this.#o,{toolName:t.name,args:t.args})){let a="User declined the action.";return r.settle(q.DECLINED,a),{content:a}}let s=lo(n.parameters)&&this.navigate===null;s&&this.conversationStore.saveCheckpoint(this.#a,{toolCallId:t.id});try{let o=await n.handler(t.args);if(s)return r.settle(q.DONE,"Navigating\u2026"),{content:"",halt:!0};let a=JSON.stringify(o??null);return r.settle(q.DONE,a),{content:a}}catch(o){s&&this.conversationStore.saveCheckpoint(this.#a,null);let a=o instanceof Error?o.message:String(o);return r.settle(q.ERROR,a),{content:`Error: ${a}`,error:a}}}#T(){return{onRunStart:()=>{this.#n.disabled=!0},onTextDelta:t=>{this.#m(t)},onTextEnd:t=>{this.#m(t),this.#s=null},onToolCall:t=>{this.#h(t)},onRunEnd:()=>{this.#n.disabled=!1,this.#s=null},onError:t=>{this.appendMessage(Te.ASSISTANT,`\u26A0\uFE0F ${t}`),this.#n.disabled=!1,this.#s=null}}}#m(t){this.#s===null&&(this.#s=this.appendMessage(Te.ASSISTANT,"")),this.#s.textContent=t,this.#t.scrollTop=this.#t.scrollHeight}#h(t){let r=this.#i.get(t.id);if(r!==void 0)return r;let n=new Dt(t.name,t.args);return this.#i.set(t.id,n),this.#t.appendChild(n.element),this.#t.scrollTop=this.#t.scrollHeight,n}};var pc="#4f46e5";function po(e){return new Promise(t=>{setTimeout(t,e)})}async function mo(e,t,r={}){let n=r.charDelayMs??35;e.value="",e.dispatchEvent(new Event("input",{bubbles:!0}));for(let s of t)e.value+=s,e.dispatchEvent(new Event("input",{bubbles:!0})),n>0&&await po(n);e.dispatchEvent(new Event("change",{bubbles:!0}))}async function ho(e,t={}){let r=t.highlightMs??280,n=e.style.outline,s=e.style.outlineOffset;e.style.outline=`2px solid ${pc}`,e.style.outlineOffset="2px",await po(r),e.style.outline=n,e.style.outlineOffset=s,e.click()}function dn(e){e.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}async function go(e,t={}){let r=t.flashMs??200;e.focus();let n=e.style.boxShadow;e.style.boxShadow="0 0 0 3px rgba(79, 70, 229, 0.4)",await po(r),e.style.boxShadow=n}function mc(){customElements.get(cn)===void 0&&customElements.define(cn,Ut)}async function hc(e,t,r={}){dn(e),await go(e,{flashMs:r.flashMs??0}),await mo(e,t,r)}async function gc(e,t={}){dn(e),await ho(e,t)}function vc(e,t){e instanceof HTMLInputElement&&e.type==="checkbox"?e.checked=!!t:e.value=String(t),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}var yc="0.1.0";export{Ut as AgUiChat,Mt as AgUiClient,Pt as ClientToolRegistry,cn as ELEMENT_TAG,to as MAX_TOOL_ROUNDS,Te as MESSAGE_ROLE,eo as SUBMIT_EVENT,Lt as SessionStorageStore,q as TOOL_CALL_STATUS,Dt as ToolCallCard,yc as VERSION,Ot as X_DESTRUCTIVE_KEY,Rt as X_NAVIGATES_KEY,gc as clickElement,ao as createHttpAgent,uo as createPageMapContext,co as createRouteTools,fo as createStateHookTools,mc as defineAgUiChat,hc as fillField,go as focusWithFlash,ho as highlightThenClick,io as isDestructive,lo as isNavigates,ro as requestConfirmation,dn as scrollIntoCenterView,vc as setControlValue,mo as typeInto};
624
+
625
+ /* Skills \u2014 chips row + the /-command palette, above the input. */
626
+ .skill-chips {
627
+ display: flex;
628
+ flex-wrap: wrap;
629
+ gap: 6px;
630
+ padding: 10px 12px;
631
+ }
632
+
633
+ .skill-chip {
634
+ border: 1px solid var(--ag-ui-border);
635
+ border-radius: 999px;
636
+ padding: 4px 12px;
637
+ font: inherit;
638
+ font-size: 0.9em;
639
+ cursor: pointer;
640
+ background: var(--ag-ui-assistant-bg);
641
+ color: var(--ag-ui-fg);
642
+ }
643
+
644
+ .skill-chip:hover {
645
+ border-color: var(--ag-ui-accent);
646
+ }
647
+
648
+ .skill-palette {
649
+ margin: 8px 12px 0;
650
+ display: flex;
651
+ flex-direction: column;
652
+ max-height: 220px;
653
+ overflow: auto;
654
+ background: var(--ag-ui-bg);
655
+ border: 1px solid var(--ag-ui-border);
656
+ border-radius: 8px;
657
+ box-shadow: 0 8px 24px rgba(20, 20, 50, 0.16);
658
+ }
659
+
660
+ .skill-item {
661
+ display: flex;
662
+ flex-direction: column;
663
+ gap: 2px;
664
+ align-items: flex-start;
665
+ padding: 8px 12px;
666
+ border: none;
667
+ background: none;
668
+ font: inherit;
669
+ text-align: left;
670
+ cursor: pointer;
671
+ color: var(--ag-ui-fg);
672
+ }
673
+
674
+ .skill-item[aria-selected="true"] {
675
+ background: var(--ag-ui-assistant-bg);
676
+ }
677
+
678
+ .skill-item-title {
679
+ font-weight: 600;
680
+ }
681
+
682
+ .skill-item-desc {
683
+ font-size: 0.85em;
684
+ color: var(--ag-ui-muted);
685
+ }
686
+
687
+ .skill-hint {
688
+ margin: 8px 12px 0;
689
+ font-size: 0.85em;
690
+ color: var(--ag-ui-danger);
691
+ }
692
+ `;var el={[me.PENDING]:"running\u2026",[me.DONE]:"\u2713 done",[me.ERROR]:"\u26A0 error",[me.DECLINED]:"\u2298 declined"},Md={[me.DONE]:"Result",[me.ERROR]:"Error",[me.DECLINED]:"Declined"},Gn=class{element;#e;#r;#i;constructor(t,n,r=Xe.FULL,o){this.#r=r,this.#i=n,this.element=document.createElement("div"),this.element.className="tool-call",this.element.setAttribute("data-tool-name",t),this.element.setAttribute("data-status",me.PENDING),this.element.setAttribute("data-display",r);let s=document.createElement("div");s.className="tool-call-head";let i=document.createElement("span");if(i.className="tool-call-name",i.textContent=`\u{1F527} ${o??t}`,this.#e=document.createElement("span"),this.#e.className="tool-call-status",this.#e.textContent=el[me.PENDING],s.append(i,this.#e),this.element.append(s),r===Xe.FULL){let a=document.createElement("pre");a.className="tool-call-args",a.textContent=JSON.stringify(n,null,2),this.element.append(a)}}settle(t,n){if(this.element.setAttribute("data-status",t),this.#e.textContent=el[t],this.#r===Xe.MINIMAL)return;let r=document.createElement("button");r.type="button",r.className="tool-call-toggle",r.setAttribute("aria-expanded","false");let o=document.createElement("pre");o.className="tool-call-result",o.hidden=!0,this.#r===Xe.COMPACT?(r.textContent="Details",o.textContent=`args: ${JSON.stringify(this.#i)}
693
+
694
+ ${n}`):(r.textContent=Md[t],o.textContent=n),r.addEventListener("click",()=>{let s=o.hidden;o.hidden=!s,r.setAttribute("aria-expanded",String(s))}),this.element.append(r,o)}};var ve=[];for(let e=0;e<256;++e)ve.push((e+256).toString(16).slice(1));function tl(e,t=0){return(ve[e[t+0]]+ve[e[t+1]]+ve[e[t+2]]+ve[e[t+3]]+"-"+ve[e[t+4]]+ve[e[t+5]]+"-"+ve[e[t+6]]+ve[e[t+7]]+"-"+ve[e[t+8]]+ve[e[t+9]]+"-"+ve[e[t+10]]+ve[e[t+11]]+ve[e[t+12]]+ve[e[t+13]]+ve[e[t+14]]+ve[e[t+15]]).toLowerCase()}var Ws,Ld=new Uint8Array(16);function Xs(){if(!Ws){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ws=crypto.getRandomValues.bind(crypto)}return Ws(Ld)}var Pd=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Zs={randomUUID:Pd};function Dd(e,t,n){if(Zs.randomUUID&&!t&&!e)return Zs.randomUUID();e=e||{};let r=e.random??e.rng?.()??Xs();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,t){if(n=n||0,n<0||n+16>t.length)throw new RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let o=0;o<16;++o)t[n+o]=r[o];return t}return tl(r)}var ft=Dd;var l={};hs(l,{BRAND:()=>lp,DIRTY:()=>St,EMPTY_PATH:()=>Hd,INVALID:()=>O,NEVER:()=>Wp,OK:()=>_e,ParseStatus:()=>ye,Schema:()=>U,ZodAny:()=>gt,ZodArray:()=>at,ZodBigInt:()=>kt,ZodBoolean:()=>At,ZodBranded:()=>Hn,ZodCatch:()=>Gt,ZodDate:()=>It,ZodDefault:()=>Ut,ZodDiscriminatedUnion:()=>Ar,ZodEffects:()=>Me,ZodEnum:()=>Pt,ZodError:()=>we,ZodFirstPartyTypeKind:()=>M,ZodFunction:()=>Cr,ZodIntersection:()=>Ot,ZodIssueCode:()=>E,ZodLazy:()=>Mt,ZodLiteral:()=>Lt,ZodMap:()=>pn,ZodNaN:()=>hn,ZodNativeEnum:()=>Dt,ZodNever:()=>Fe,ZodNull:()=>Nt,ZodNullable:()=>Qe,ZodNumber:()=>wt,ZodObject:()=>ke,ZodOptional:()=>Re,ZodParsedType:()=>A,ZodPipeline:()=>$n,ZodPromise:()=>vt,ZodReadonly:()=>Ft,ZodRecord:()=>Ir,ZodSchema:()=>U,ZodSet:()=>fn,ZodString:()=>mt,ZodSymbol:()=>un,ZodTransformer:()=>Me,ZodTuple:()=>Je,ZodType:()=>U,ZodUndefined:()=>Ct,ZodUnion:()=>Rt,ZodUnknown:()=>it,ZodVoid:()=>dn,addIssueToContext:()=>w,any:()=>vp,array:()=>Ep,bigint:()=>pp,boolean:()=>pl,coerce:()=>jp,custom:()=>cl,date:()=>fp,datetimeRegex:()=>al,defaultErrorMap:()=>ot,discriminatedUnion:()=>wp,effect:()=>Up,enum:()=>Lp,function:()=>Rp,getErrorMap:()=>an,getParsedType:()=>qe,instanceof:()=>up,intersection:()=>kp,isAborted:()=>wr,isAsync:()=>ln,isDirty:()=>kr,isValid:()=>ht,late:()=>cp,lazy:()=>Op,literal:()=>Mp,makeIssue:()=>Fn,map:()=>Cp,nan:()=>dp,nativeEnum:()=>Pp,never:()=>bp,null:()=>gp,nullable:()=>Fp,number:()=>dl,object:()=>_p,objectUtil:()=>Ks,oboolean:()=>Vp,onumber:()=>Bp,optional:()=>Gp,ostring:()=>zp,pipeline:()=>$p,preprocess:()=>Hp,promise:()=>Dp,quotelessJson:()=>Ud,record:()=>Ip,set:()=>Np,setErrorMap:()=>Fd,strictObject:()=>Tp,string:()=>ul,symbol:()=>hp,transformer:()=>Up,tuple:()=>Ap,undefined:()=>mp,union:()=>Sp,unknown:()=>yp,util:()=>H,void:()=>xp});var H;(function(e){e.assertEqual=o=>{};function t(o){}e.assertIs=t;function n(o){throw new Error}e.assertNever=n,e.arrayToEnum=o=>{let s={};for(let i of o)s[i]=i;return s},e.getValidEnumValues=o=>{let s=e.objectKeys(o).filter(a=>typeof o[o[a]]!="number"),i={};for(let a of s)i[a]=o[a];return e.objectValues(i)},e.objectValues=o=>e.objectKeys(o).map(function(s){return o[s]}),e.objectKeys=typeof Object.keys=="function"?o=>Object.keys(o):o=>{let s=[];for(let i in o)Object.prototype.hasOwnProperty.call(o,i)&&s.push(i);return s},e.find=(o,s)=>{for(let i of o)if(s(i))return i},e.isInteger=typeof Number.isInteger=="function"?o=>Number.isInteger(o):o=>typeof o=="number"&&Number.isFinite(o)&&Math.floor(o)===o;function r(o,s=" | "){return o.map(i=>typeof i=="string"?`'${i}'`:i).join(s)}e.joinValues=r,e.jsonStringifyReplacer=(o,s)=>typeof s=="bigint"?s.toString():s})(H||(H={}));var Ks;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(Ks||(Ks={}));var A=H.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),qe=e=>{switch(typeof e){case"undefined":return A.undefined;case"string":return A.string;case"number":return Number.isNaN(e)?A.nan:A.number;case"boolean":return A.boolean;case"function":return A.function;case"bigint":return A.bigint;case"symbol":return A.symbol;case"object":return Array.isArray(e)?A.array:e===null?A.null:e.then&&typeof e.then=="function"&&e.catch&&typeof e.catch=="function"?A.promise:typeof Map<"u"&&e instanceof Map?A.map:typeof Set<"u"&&e instanceof Set?A.set:typeof Date<"u"&&e instanceof Date?A.date:A.object;default:return A.unknown}};var E=H.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"]),Ud=e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:"),we=class e extends Error{get errors(){return this.issues}constructor(t){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=t}format(t){let n=t||function(s){return s.message},r={_errors:[]},o=s=>{for(let i of s.issues)if(i.code==="invalid_union")i.unionErrors.map(o);else if(i.code==="invalid_return_type")o(i.returnTypeError);else if(i.code==="invalid_arguments")o(i.argumentsError);else if(i.path.length===0)r._errors.push(n(i));else{let a=r,u=0;for(;u<i.path.length;){let c=i.path[u];u===i.path.length-1?(a[c]=a[c]||{_errors:[]},a[c]._errors.push(n(i))):a[c]=a[c]||{_errors:[]},a=a[c],u++}}};return o(this),r}static assert(t){if(!(t instanceof e))throw new Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,H.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(t=n=>n.message){let n={},r=[];for(let o of this.issues)if(o.path.length>0){let s=o.path[0];n[s]=n[s]||[],n[s].push(t(o))}else r.push(t(o));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}};we.create=e=>new we(e);var Gd=(e,t)=>{let n;switch(e.code){case E.invalid_type:e.received===A.undefined?n="Required":n=`Expected ${e.expected}, received ${e.received}`;break;case E.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,H.jsonStringifyReplacer)}`;break;case E.unrecognized_keys:n=`Unrecognized key(s) in object: ${H.joinValues(e.keys,", ")}`;break;case E.invalid_union:n="Invalid input";break;case E.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${H.joinValues(e.options)}`;break;case E.invalid_enum_value:n=`Invalid enum value. Expected ${H.joinValues(e.options)}, received '${e.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 e.validation=="object"?"includes"in e.validation?(n=`Invalid input: must include "${e.validation.includes}"`,typeof e.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?n=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?n=`Invalid input: must end with "${e.validation.endsWith}"`:H.assertNever(e.validation):e.validation!=="regex"?n=`Invalid ${e.validation}`:n="Invalid";break;case E.too_small:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="bigint"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:n="Invalid input";break;case E.too_big:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="bigint"?n=`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.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 ${e.multipleOf}`;break;case E.not_finite:n="Number must be finite";break;default:n=t.defaultError,H.assertNever(e)}return{message:n}},ot=Gd;var nl=ot;function Fd(e){nl=e}function an(){return nl}var Fn=e=>{let{data:t,path:n,errorMaps:r,issueData:o}=e,s=[...n,...o.path||[]],i={...o,path:s};if(o.message!==void 0)return{...o,path:s,message:o.message};let a="",u=r.filter(c=>!!c).slice().reverse();for(let c of u)a=c(i,{data:t,defaultError:a}).message;return{...o,path:s,message:a}},Hd=[];function w(e,t){let n=an(),r=Fn({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,n,n===ot?void 0:ot].filter(o=>!!o)});e.common.issues.push(r)}var ye=class e{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(t,n){let r=[];for(let o of n){if(o.status==="aborted")return O;o.status==="dirty"&&t.dirty(),r.push(o.value)}return{status:t.value,value:r}}static async mergeObjectAsync(t,n){let r=[];for(let o of n){let s=await o.key,i=await o.value;r.push({key:s,value:i})}return e.mergeObjectSync(t,r)}static mergeObjectSync(t,n){let r={};for(let o of n){let{key:s,value:i}=o;if(s.status==="aborted"||i.status==="aborted")return O;s.status==="dirty"&&t.dirty(),i.status==="dirty"&&t.dirty(),s.value!=="__proto__"&&(typeof i.value<"u"||o.alwaysSet)&&(r[s.value]=i.value)}return{status:t.value,value:r}}},O=Object.freeze({status:"aborted"}),St=e=>({status:"dirty",value:e}),_e=e=>({status:"valid",value:e}),wr=e=>e.status==="aborted",kr=e=>e.status==="dirty",ht=e=>e.status==="valid",ln=e=>typeof Promise<"u"&&e instanceof Promise;var I;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t?.message})(I||(I={}));var Oe=class{constructor(t,n,r,o){this._cachedPath=[],this.parent=t,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}},rl=(e,t)=>{if(ht(t))return{success:!0,data:t.value};if(!e.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 we(e.common.issues);return this._error=n,this._error}}};function L(e){if(!e)return{};let{errorMap:t,invalid_type_error:n,required_error:r,description:o}=e;if(t&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return t?{errorMap:t,description:o}:{errorMap:(i,a)=>{let{message:u}=e;return i.code==="invalid_enum_value"?{message:u??a.defaultError}:typeof a.data>"u"?{message:u??r??a.defaultError}:i.code!=="invalid_type"?{message:a.defaultError}:{message:u??n??a.defaultError}},description:o}}var U=class{get description(){return this._def.description}_getType(t){return qe(t.data)}_getOrReturnCtx(t,n){return n||{common:t.parent.common,data:t.data,parsedType:qe(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new ye,ctx:{common:t.parent.common,data:t.data,parsedType:qe(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){let n=this._parse(t);if(ln(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(t){let n=this._parse(t);return Promise.resolve(n)}parse(t,n){let r=this.safeParse(t,n);if(r.success)return r.data;throw r.error}safeParse(t,n){let r={common:{issues:[],async:n?.async??!1,contextualErrorMap:n?.errorMap},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:qe(t)},o=this._parseSync({data:t,path:r.path,parent:r});return rl(r,o)}"~validate"(t){let n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:qe(t)};if(!this["~standard"].async)try{let r=this._parseSync({data:t,path:[],parent:n});return ht(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:t,path:[],parent:n}).then(r=>ht(r)?{value:r.value}:{issues:n.common.issues})}async parseAsync(t,n){let r=await this.safeParseAsync(t,n);if(r.success)return r.data;throw r.error}async safeParseAsync(t,n){let r={common:{issues:[],contextualErrorMap:n?.errorMap,async:!0},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:qe(t)},o=this._parse({data:t,path:r.path,parent:r}),s=await(ln(o)?o:Promise.resolve(o));return rl(r,s)}refine(t,n){let r=o=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(o):n;return this._refinement((o,s)=>{let i=t(o),a=()=>s.addIssue({code:E.custom,...r(o)});return typeof Promise<"u"&&i instanceof Promise?i.then(u=>u?!0:(a(),!1)):i?!0:(a(),!1)})}refinement(t,n){return this._refinement((r,o)=>t(r)?!0:(o.addIssue(typeof n=="function"?n(r,o):n),!1))}_refinement(t){return new Me({schema:this,typeName:M.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}constructor(t){this.spa=this.safeParseAsync,this._def=t,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 Re.create(this,this._def)}nullable(){return Qe.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return at.create(this)}promise(){return vt.create(this,this._def)}or(t){return Rt.create([this,t],this._def)}and(t){return Ot.create(this,t,this._def)}transform(t){return new Me({...L(this._def),schema:this,typeName:M.ZodEffects,effect:{type:"transform",transform:t}})}default(t){let n=typeof t=="function"?t:()=>t;return new Ut({...L(this._def),innerType:this,defaultValue:n,typeName:M.ZodDefault})}brand(){return new Hn({typeName:M.ZodBranded,type:this,...L(this._def)})}catch(t){let n=typeof t=="function"?t:()=>t;return new Gt({...L(this._def),innerType:this,catchValue:n,typeName:M.ZodCatch})}describe(t){let n=this.constructor;return new n({...this._def,description:t})}pipe(t){return $n.create(this,t)}readonly(){return Ft.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},$d=/^c[^\s-]{8,}$/i,zd=/^[0-9a-z]+$/,Bd=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Vd=/^[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,jd=/^[a-z0-9_-]{21}$/i,Wd=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Xd=/^[-+]?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)?)??$/,Zd=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Kd="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",Ys,Yd=/^(?:(?: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])$/,qd=/^(?:(?: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])$/,Jd=/^(([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]))$/,Qd=/^(([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])$/,ep=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,tp=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,sl="((\\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])))",np=new RegExp(`^${sl}$`);function il(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:e.precision==null&&(t=`${t}(\\.\\d+)?`);let n=e.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${n}`}function rp(e){return new RegExp(`^${il(e)}$`)}function al(e){let t=`${sl}T${il(e)}`,n=[];return n.push(e.local?"Z?":"Z"),e.offset&&n.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${n.join("|")})`,new RegExp(`^${t}$`)}function op(e,t){return!!((t==="v4"||!t)&&Yd.test(e)||(t==="v6"||!t)&&Jd.test(e))}function sp(e,t){if(!Wd.test(e))return!1;try{let[n]=e.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||t&&o.alg!==t)}catch{return!1}}function ip(e,t){return!!((t==="v4"||!t)&&qd.test(e)||(t==="v6"||!t)&&Qd.test(e))}var mt=class e extends U{_parse(t){if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==A.string){let s=this._getOrReturnCtx(t);return w(s,{code:E.invalid_type,expected:A.string,received:s.parsedType}),O}let r=new ye,o;for(let s of this._def.checks)if(s.kind==="min")t.data.length<s.value&&(o=this._getOrReturnCtx(t,o),w(o,{code:E.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if(s.kind==="max")t.data.length>s.value&&(o=this._getOrReturnCtx(t,o),w(o,{code:E.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if(s.kind==="length"){let i=t.data.length>s.value,a=t.data.length<s.value;(i||a)&&(o=this._getOrReturnCtx(t,o),i?w(o,{code:E.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):a&&w(o,{code:E.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),r.dirty())}else if(s.kind==="email")Zd.test(t.data)||(o=this._getOrReturnCtx(t,o),w(o,{validation:"email",code:E.invalid_string,message:s.message}),r.dirty());else if(s.kind==="emoji")Ys||(Ys=new RegExp(Kd,"u")),Ys.test(t.data)||(o=this._getOrReturnCtx(t,o),w(o,{validation:"emoji",code:E.invalid_string,message:s.message}),r.dirty());else if(s.kind==="uuid")Vd.test(t.data)||(o=this._getOrReturnCtx(t,o),w(o,{validation:"uuid",code:E.invalid_string,message:s.message}),r.dirty());else if(s.kind==="nanoid")jd.test(t.data)||(o=this._getOrReturnCtx(t,o),w(o,{validation:"nanoid",code:E.invalid_string,message:s.message}),r.dirty());else if(s.kind==="cuid")$d.test(t.data)||(o=this._getOrReturnCtx(t,o),w(o,{validation:"cuid",code:E.invalid_string,message:s.message}),r.dirty());else if(s.kind==="cuid2")zd.test(t.data)||(o=this._getOrReturnCtx(t,o),w(o,{validation:"cuid2",code:E.invalid_string,message:s.message}),r.dirty());else if(s.kind==="ulid")Bd.test(t.data)||(o=this._getOrReturnCtx(t,o),w(o,{validation:"ulid",code:E.invalid_string,message:s.message}),r.dirty());else if(s.kind==="url")try{new URL(t.data)}catch{o=this._getOrReturnCtx(t,o),w(o,{validation:"url",code:E.invalid_string,message:s.message}),r.dirty()}else s.kind==="regex"?(s.regex.lastIndex=0,s.regex.test(t.data)||(o=this._getOrReturnCtx(t,o),w(o,{validation:"regex",code:E.invalid_string,message:s.message}),r.dirty())):s.kind==="trim"?t.data=t.data.trim():s.kind==="includes"?t.data.includes(s.value,s.position)||(o=this._getOrReturnCtx(t,o),w(o,{code:E.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),r.dirty()):s.kind==="toLowerCase"?t.data=t.data.toLowerCase():s.kind==="toUpperCase"?t.data=t.data.toUpperCase():s.kind==="startsWith"?t.data.startsWith(s.value)||(o=this._getOrReturnCtx(t,o),w(o,{code:E.invalid_string,validation:{startsWith:s.value},message:s.message}),r.dirty()):s.kind==="endsWith"?t.data.endsWith(s.value)||(o=this._getOrReturnCtx(t,o),w(o,{code:E.invalid_string,validation:{endsWith:s.value},message:s.message}),r.dirty()):s.kind==="datetime"?al(s).test(t.data)||(o=this._getOrReturnCtx(t,o),w(o,{code:E.invalid_string,validation:"datetime",message:s.message}),r.dirty()):s.kind==="date"?np.test(t.data)||(o=this._getOrReturnCtx(t,o),w(o,{code:E.invalid_string,validation:"date",message:s.message}),r.dirty()):s.kind==="time"?rp(s).test(t.data)||(o=this._getOrReturnCtx(t,o),w(o,{code:E.invalid_string,validation:"time",message:s.message}),r.dirty()):s.kind==="duration"?Xd.test(t.data)||(o=this._getOrReturnCtx(t,o),w(o,{validation:"duration",code:E.invalid_string,message:s.message}),r.dirty()):s.kind==="ip"?op(t.data,s.version)||(o=this._getOrReturnCtx(t,o),w(o,{validation:"ip",code:E.invalid_string,message:s.message}),r.dirty()):s.kind==="jwt"?sp(t.data,s.alg)||(o=this._getOrReturnCtx(t,o),w(o,{validation:"jwt",code:E.invalid_string,message:s.message}),r.dirty()):s.kind==="cidr"?ip(t.data,s.version)||(o=this._getOrReturnCtx(t,o),w(o,{validation:"cidr",code:E.invalid_string,message:s.message}),r.dirty()):s.kind==="base64"?ep.test(t.data)||(o=this._getOrReturnCtx(t,o),w(o,{validation:"base64",code:E.invalid_string,message:s.message}),r.dirty()):s.kind==="base64url"?tp.test(t.data)||(o=this._getOrReturnCtx(t,o),w(o,{validation:"base64url",code:E.invalid_string,message:s.message}),r.dirty()):H.assertNever(s);return{status:r.value,value:t.data}}_regex(t,n,r){return this.refinement(o=>t.test(o),{validation:n,code:E.invalid_string,...I.errToObj(r)})}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...I.errToObj(t)})}url(t){return this._addCheck({kind:"url",...I.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...I.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...I.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...I.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...I.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...I.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...I.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...I.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...I.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...I.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...I.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...I.errToObj(t)})}datetime(t){return typeof t=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:typeof t?.precision>"u"?null:t?.precision,offset:t?.offset??!1,local:t?.local??!1,...I.errToObj(t?.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return typeof t=="string"?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:typeof t?.precision>"u"?null:t?.precision,...I.errToObj(t?.message)})}duration(t){return this._addCheck({kind:"duration",...I.errToObj(t)})}regex(t,n){return this._addCheck({kind:"regex",regex:t,...I.errToObj(n)})}includes(t,n){return this._addCheck({kind:"includes",value:t,position:n?.position,...I.errToObj(n?.message)})}startsWith(t,n){return this._addCheck({kind:"startsWith",value:t,...I.errToObj(n)})}endsWith(t,n){return this._addCheck({kind:"endsWith",value:t,...I.errToObj(n)})}min(t,n){return this._addCheck({kind:"min",value:t,...I.errToObj(n)})}max(t,n){return this._addCheck({kind:"max",value:t,...I.errToObj(n)})}length(t,n){return this._addCheck({kind:"length",value:t,...I.errToObj(n)})}nonempty(t){return this.min(1,I.errToObj(t))}trim(){return new e({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new e({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new e({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(t=>t.kind==="datetime")}get isDate(){return!!this._def.checks.find(t=>t.kind==="date")}get isTime(){return!!this._def.checks.find(t=>t.kind==="time")}get isDuration(){return!!this._def.checks.find(t=>t.kind==="duration")}get isEmail(){return!!this._def.checks.find(t=>t.kind==="email")}get isURL(){return!!this._def.checks.find(t=>t.kind==="url")}get isEmoji(){return!!this._def.checks.find(t=>t.kind==="emoji")}get isUUID(){return!!this._def.checks.find(t=>t.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(t=>t.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(t=>t.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(t=>t.kind==="cuid2")}get isULID(){return!!this._def.checks.find(t=>t.kind==="ulid")}get isIP(){return!!this._def.checks.find(t=>t.kind==="ip")}get isCIDR(){return!!this._def.checks.find(t=>t.kind==="cidr")}get isBase64(){return!!this._def.checks.find(t=>t.kind==="base64")}get isBase64url(){return!!this._def.checks.find(t=>t.kind==="base64url")}get minLength(){let t=null;for(let n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxLength(){let t=null;for(let n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}};mt.create=e=>new mt({checks:[],typeName:M.ZodString,coerce:e?.coerce??!1,...L(e)});function ap(e,t){let n=(e.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,o=n>r?n:r,s=Number.parseInt(e.toFixed(o).replace(".","")),i=Number.parseInt(t.toFixed(o).replace(".",""));return s%i/10**o}var wt=class e extends U{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==A.number){let s=this._getOrReturnCtx(t);return w(s,{code:E.invalid_type,expected:A.number,received:s.parsedType}),O}let r,o=new ye;for(let s of this._def.checks)s.kind==="int"?H.isInteger(t.data)||(r=this._getOrReturnCtx(t,r),w(r,{code:E.invalid_type,expected:"integer",received:"float",message:s.message}),o.dirty()):s.kind==="min"?(s.inclusive?t.data<s.value:t.data<=s.value)&&(r=this._getOrReturnCtx(t,r),w(r,{code:E.too_small,minimum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),o.dirty()):s.kind==="max"?(s.inclusive?t.data>s.value:t.data>=s.value)&&(r=this._getOrReturnCtx(t,r),w(r,{code:E.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),o.dirty()):s.kind==="multipleOf"?ap(t.data,s.value)!==0&&(r=this._getOrReturnCtx(t,r),w(r,{code:E.not_multiple_of,multipleOf:s.value,message:s.message}),o.dirty()):s.kind==="finite"?Number.isFinite(t.data)||(r=this._getOrReturnCtx(t,r),w(r,{code:E.not_finite,message:s.message}),o.dirty()):H.assertNever(s);return{status:o.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,I.toString(n))}gt(t,n){return this.setLimit("min",t,!1,I.toString(n))}lte(t,n){return this.setLimit("max",t,!0,I.toString(n))}lt(t,n){return this.setLimit("max",t,!1,I.toString(n))}setLimit(t,n,r,o){return new e({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:I.toString(o)}]})}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:I.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:I.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:I.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:I.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:I.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:I.toString(n)})}finite(t){return this._addCheck({kind:"finite",message:I.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:I.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:I.toString(t)})}get minValue(){let t=null;for(let n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(let n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}get isInt(){return!!this._def.checks.find(t=>t.kind==="int"||t.kind==="multipleOf"&&H.isInteger(t.value))}get isFinite(){let t=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"&&(t===null||r.value<t)&&(t=r.value)}return Number.isFinite(n)&&Number.isFinite(t)}};wt.create=e=>new wt({checks:[],typeName:M.ZodNumber,coerce:e?.coerce||!1,...L(e)});var kt=class e extends U{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){if(this._def.coerce)try{t.data=BigInt(t.data)}catch{return this._getInvalidInput(t)}if(this._getType(t)!==A.bigint)return this._getInvalidInput(t);let r,o=new ye;for(let s of this._def.checks)s.kind==="min"?(s.inclusive?t.data<s.value:t.data<=s.value)&&(r=this._getOrReturnCtx(t,r),w(r,{code:E.too_small,type:"bigint",minimum:s.value,inclusive:s.inclusive,message:s.message}),o.dirty()):s.kind==="max"?(s.inclusive?t.data>s.value:t.data>=s.value)&&(r=this._getOrReturnCtx(t,r),w(r,{code:E.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),o.dirty()):s.kind==="multipleOf"?t.data%s.value!==BigInt(0)&&(r=this._getOrReturnCtx(t,r),w(r,{code:E.not_multiple_of,multipleOf:s.value,message:s.message}),o.dirty()):H.assertNever(s);return{status:o.value,value:t.data}}_getInvalidInput(t){let n=this._getOrReturnCtx(t);return w(n,{code:E.invalid_type,expected:A.bigint,received:n.parsedType}),O}gte(t,n){return this.setLimit("min",t,!0,I.toString(n))}gt(t,n){return this.setLimit("min",t,!1,I.toString(n))}lte(t,n){return this.setLimit("max",t,!0,I.toString(n))}lt(t,n){return this.setLimit("max",t,!1,I.toString(n))}setLimit(t,n,r,o){return new e({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:I.toString(o)}]})}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:I.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:I.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:I.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:I.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:I.toString(n)})}get minValue(){let t=null;for(let n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(let n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}};kt.create=e=>new kt({checks:[],typeName:M.ZodBigInt,coerce:e?.coerce??!1,...L(e)});var At=class extends U{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==A.boolean){let r=this._getOrReturnCtx(t);return w(r,{code:E.invalid_type,expected:A.boolean,received:r.parsedType}),O}return _e(t.data)}};At.create=e=>new At({typeName:M.ZodBoolean,coerce:e?.coerce||!1,...L(e)});var It=class e extends U{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==A.date){let s=this._getOrReturnCtx(t);return w(s,{code:E.invalid_type,expected:A.date,received:s.parsedType}),O}if(Number.isNaN(t.data.getTime())){let s=this._getOrReturnCtx(t);return w(s,{code:E.invalid_date}),O}let r=new ye,o;for(let s of this._def.checks)s.kind==="min"?t.data.getTime()<s.value&&(o=this._getOrReturnCtx(t,o),w(o,{code:E.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),r.dirty()):s.kind==="max"?t.data.getTime()>s.value&&(o=this._getOrReturnCtx(t,o),w(o,{code:E.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),r.dirty()):H.assertNever(s);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}min(t,n){return this._addCheck({kind:"min",value:t.getTime(),message:I.toString(n)})}max(t,n){return this._addCheck({kind:"max",value:t.getTime(),message:I.toString(n)})}get minDate(){let t=null;for(let n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t!=null?new Date(t):null}get maxDate(){let t=null;for(let n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t!=null?new Date(t):null}};It.create=e=>new It({checks:[],coerce:e?.coerce||!1,typeName:M.ZodDate,...L(e)});var un=class extends U{_parse(t){if(this._getType(t)!==A.symbol){let r=this._getOrReturnCtx(t);return w(r,{code:E.invalid_type,expected:A.symbol,received:r.parsedType}),O}return _e(t.data)}};un.create=e=>new un({typeName:M.ZodSymbol,...L(e)});var Ct=class extends U{_parse(t){if(this._getType(t)!==A.undefined){let r=this._getOrReturnCtx(t);return w(r,{code:E.invalid_type,expected:A.undefined,received:r.parsedType}),O}return _e(t.data)}};Ct.create=e=>new Ct({typeName:M.ZodUndefined,...L(e)});var Nt=class extends U{_parse(t){if(this._getType(t)!==A.null){let r=this._getOrReturnCtx(t);return w(r,{code:E.invalid_type,expected:A.null,received:r.parsedType}),O}return _e(t.data)}};Nt.create=e=>new Nt({typeName:M.ZodNull,...L(e)});var gt=class extends U{constructor(){super(...arguments),this._any=!0}_parse(t){return _e(t.data)}};gt.create=e=>new gt({typeName:M.ZodAny,...L(e)});var it=class extends U{constructor(){super(...arguments),this._unknown=!0}_parse(t){return _e(t.data)}};it.create=e=>new it({typeName:M.ZodUnknown,...L(e)});var Fe=class extends U{_parse(t){let n=this._getOrReturnCtx(t);return w(n,{code:E.invalid_type,expected:A.never,received:n.parsedType}),O}};Fe.create=e=>new Fe({typeName:M.ZodNever,...L(e)});var dn=class extends U{_parse(t){if(this._getType(t)!==A.undefined){let r=this._getOrReturnCtx(t);return w(r,{code:E.invalid_type,expected:A.void,received:r.parsedType}),O}return _e(t.data)}};dn.create=e=>new dn({typeName:M.ZodVoid,...L(e)});var at=class e extends U{_parse(t){let{ctx:n,status:r}=this._processInputParams(t),o=this._def;if(n.parsedType!==A.array)return w(n,{code:E.invalid_type,expected:A.array,received:n.parsedType}),O;if(o.exactLength!==null){let i=n.data.length>o.exactLength.value,a=n.data.length<o.exactLength.value;(i||a)&&(w(n,{code:i?E.too_big:E.too_small,minimum:a?o.exactLength.value:void 0,maximum:i?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&&(w(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&&(w(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((i,a)=>o.type._parseAsync(new Oe(n,i,n.path,a)))).then(i=>ye.mergeArray(r,i));let s=[...n.data].map((i,a)=>o.type._parseSync(new Oe(n,i,n.path,a)));return ye.mergeArray(r,s)}get element(){return this._def.type}min(t,n){return new e({...this._def,minLength:{value:t,message:I.toString(n)}})}max(t,n){return new e({...this._def,maxLength:{value:t,message:I.toString(n)}})}length(t,n){return new e({...this._def,exactLength:{value:t,message:I.toString(n)}})}nonempty(t){return this.min(1,t)}};at.create=(e,t)=>new at({type:e,minLength:null,maxLength:null,exactLength:null,typeName:M.ZodArray,...L(t)});function cn(e){if(e instanceof ke){let t={};for(let n in e.shape){let r=e.shape[n];t[n]=Re.create(cn(r))}return new ke({...e._def,shape:()=>t})}else return e instanceof at?new at({...e._def,type:cn(e.element)}):e instanceof Re?Re.create(cn(e.unwrap())):e instanceof Qe?Qe.create(cn(e.unwrap())):e instanceof Je?Je.create(e.items.map(t=>cn(t))):e}var ke=class e extends U{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let t=this._def.shape(),n=H.objectKeys(t);return this._cached={shape:t,keys:n},this._cached}_parse(t){if(this._getType(t)!==A.object){let c=this._getOrReturnCtx(t);return w(c,{code:E.invalid_type,expected:A.object,received:c.parsedType}),O}let{status:r,ctx:o}=this._processInputParams(t),{shape:s,keys:i}=this._getCached(),a=[];if(!(this._def.catchall instanceof Fe&&this._def.unknownKeys==="strip"))for(let c in o.data)i.includes(c)||a.push(c);let u=[];for(let c of i){let p=s[c],m=o.data[c];u.push({key:{status:"valid",value:c},value:p._parse(new Oe(o,m,o.path,c)),alwaysSet:c in o.data})}if(this._def.catchall instanceof Fe){let c=this._def.unknownKeys;if(c==="passthrough")for(let p of a)u.push({key:{status:"valid",value:p},value:{status:"valid",value:o.data[p]}});else if(c==="strict")a.length>0&&(w(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 p of a){let m=o.data[p];u.push({key:{status:"valid",value:p},value:c._parse(new Oe(o,m,o.path,p)),alwaysSet:p in o.data})}}return o.common.async?Promise.resolve().then(async()=>{let c=[];for(let p of u){let m=await p.key,x=await p.value;c.push({key:m,value:x,alwaysSet:p.alwaysSet})}return c}).then(c=>ye.mergeObjectSync(r,c)):ye.mergeObjectSync(r,u)}get shape(){return this._def.shape()}strict(t){return I.errToObj,new e({...this._def,unknownKeys:"strict",...t!==void 0?{errorMap:(n,r)=>{let o=this._def.errorMap?.(n,r).message??r.defaultError;return n.code==="unrecognized_keys"?{message:I.errToObj(t).message??o}:{message:o}}}:{}})}strip(){return new e({...this._def,unknownKeys:"strip"})}passthrough(){return new e({...this._def,unknownKeys:"passthrough"})}extend(t){return new e({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new e({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:M.ZodObject})}setKey(t,n){return this.augment({[t]:n})}catchall(t){return new e({...this._def,catchall:t})}pick(t){let n={};for(let r of H.objectKeys(t))t[r]&&this.shape[r]&&(n[r]=this.shape[r]);return new e({...this._def,shape:()=>n})}omit(t){let n={};for(let r of H.objectKeys(this.shape))t[r]||(n[r]=this.shape[r]);return new e({...this._def,shape:()=>n})}deepPartial(){return cn(this)}partial(t){let n={};for(let r of H.objectKeys(this.shape)){let o=this.shape[r];t&&!t[r]?n[r]=o:n[r]=o.optional()}return new e({...this._def,shape:()=>n})}required(t){let n={};for(let r of H.objectKeys(this.shape))if(t&&!t[r])n[r]=this.shape[r];else{let s=this.shape[r];for(;s instanceof Re;)s=s._def.innerType;n[r]=s}return new e({...this._def,shape:()=>n})}keyof(){return ll(H.objectKeys(this.shape))}};ke.create=(e,t)=>new ke({shape:()=>e,unknownKeys:"strip",catchall:Fe.create(),typeName:M.ZodObject,...L(t)});ke.strictCreate=(e,t)=>new ke({shape:()=>e,unknownKeys:"strict",catchall:Fe.create(),typeName:M.ZodObject,...L(t)});ke.lazycreate=(e,t)=>new ke({shape:e,unknownKeys:"strip",catchall:Fe.create(),typeName:M.ZodObject,...L(t)});var Rt=class extends U{_parse(t){let{ctx:n}=this._processInputParams(t),r=this._def.options;function o(s){for(let a of s)if(a.result.status==="valid")return a.result;for(let a of s)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;let i=s.map(a=>new we(a.ctx.common.issues));return w(n,{code:E.invalid_union,unionErrors:i}),O}if(n.common.async)return Promise.all(r.map(async s=>{let i={...n,common:{...n.common,issues:[]},parent:null};return{result:await s._parseAsync({data:n.data,path:n.path,parent:i}),ctx:i}})).then(o);{let s,i=[];for(let u of r){let c={...n,common:{...n.common,issues:[]},parent:null},p=u._parseSync({data:n.data,path:n.path,parent:c});if(p.status==="valid")return p;p.status==="dirty"&&!s&&(s={result:p,ctx:c}),c.common.issues.length&&i.push(c.common.issues)}if(s)return n.common.issues.push(...s.ctx.common.issues),s.result;let a=i.map(u=>new we(u));return w(n,{code:E.invalid_union,unionErrors:a}),O}}get options(){return this._def.options}};Rt.create=(e,t)=>new Rt({options:e,typeName:M.ZodUnion,...L(t)});var st=e=>e instanceof Mt?st(e.schema):e instanceof Me?st(e.innerType()):e instanceof Lt?[e.value]:e instanceof Pt?e.options:e instanceof Dt?H.objectValues(e.enum):e instanceof Ut?st(e._def.innerType):e instanceof Ct?[void 0]:e instanceof Nt?[null]:e instanceof Re?[void 0,...st(e.unwrap())]:e instanceof Qe?[null,...st(e.unwrap())]:e instanceof Hn||e instanceof Ft?st(e.unwrap()):e instanceof Gt?st(e._def.innerType):[],Ar=class e extends U{_parse(t){let{ctx:n}=this._processInputParams(t);if(n.parsedType!==A.object)return w(n,{code:E.invalid_type,expected:A.object,received:n.parsedType}),O;let r=this.discriminator,o=n.data[r],s=this.optionsMap.get(o);return s?n.common.async?s._parseAsync({data:n.data,path:n.path,parent:n}):s._parseSync({data:n.data,path:n.path,parent:n}):(w(n,{code:E.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),O)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,n,r){let o=new Map;for(let s of n){let i=st(s.shape[t]);if(!i.length)throw new Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(let a of i){if(o.has(a))throw new Error(`Discriminator property ${String(t)} has duplicate value ${String(a)}`);o.set(a,s)}}return new e({typeName:M.ZodDiscriminatedUnion,discriminator:t,options:n,optionsMap:o,...L(r)})}};function qs(e,t){let n=qe(e),r=qe(t);if(e===t)return{valid:!0,data:e};if(n===A.object&&r===A.object){let o=H.objectKeys(t),s=H.objectKeys(e).filter(a=>o.indexOf(a)!==-1),i={...e,...t};for(let a of s){let u=qs(e[a],t[a]);if(!u.valid)return{valid:!1};i[a]=u.data}return{valid:!0,data:i}}else if(n===A.array&&r===A.array){if(e.length!==t.length)return{valid:!1};let o=[];for(let s=0;s<e.length;s++){let i=e[s],a=t[s],u=qs(i,a);if(!u.valid)return{valid:!1};o.push(u.data)}return{valid:!0,data:o}}else return n===A.date&&r===A.date&&+e==+t?{valid:!0,data:e}:{valid:!1}}var Ot=class extends U{_parse(t){let{status:n,ctx:r}=this._processInputParams(t),o=(s,i)=>{if(wr(s)||wr(i))return O;let a=qs(s.value,i.value);return a.valid?((kr(s)||kr(i))&&n.dirty(),{status:n.value,value:a.data}):(w(r,{code:E.invalid_intersection_types}),O)};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(([s,i])=>o(s,i)):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}))}};Ot.create=(e,t,n)=>new Ot({left:e,right:t,typeName:M.ZodIntersection,...L(n)});var Je=class e extends U{_parse(t){let{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==A.array)return w(r,{code:E.invalid_type,expected:A.array,received:r.parsedType}),O;if(r.data.length<this._def.items.length)return w(r,{code:E.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),O;!this._def.rest&&r.data.length>this._def.items.length&&(w(r,{code:E.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());let s=[...r.data].map((i,a)=>{let u=this._def.items[a]||this._def.rest;return u?u._parse(new Oe(r,i,r.path,a)):null}).filter(i=>!!i);return r.common.async?Promise.all(s).then(i=>ye.mergeArray(n,i)):ye.mergeArray(n,s)}get items(){return this._def.items}rest(t){return new e({...this._def,rest:t})}};Je.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Je({items:e,typeName:M.ZodTuple,rest:null,...L(t)})};var Ir=class e extends U{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){let{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==A.object)return w(r,{code:E.invalid_type,expected:A.object,received:r.parsedType}),O;let o=[],s=this._def.keyType,i=this._def.valueType;for(let a in r.data)o.push({key:s._parse(new Oe(r,a,r.path,a)),value:i._parse(new Oe(r,r.data[a],r.path,a)),alwaysSet:a in r.data});return r.common.async?ye.mergeObjectAsync(n,o):ye.mergeObjectSync(n,o)}get element(){return this._def.valueType}static create(t,n,r){return n instanceof U?new e({keyType:t,valueType:n,typeName:M.ZodRecord,...L(r)}):new e({keyType:mt.create(),valueType:t,typeName:M.ZodRecord,...L(n)})}},pn=class extends U{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){let{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==A.map)return w(r,{code:E.invalid_type,expected:A.map,received:r.parsedType}),O;let o=this._def.keyType,s=this._def.valueType,i=[...r.data.entries()].map(([a,u],c)=>({key:o._parse(new Oe(r,a,r.path,[c,"key"])),value:s._parse(new Oe(r,u,r.path,[c,"value"]))}));if(r.common.async){let a=new Map;return Promise.resolve().then(async()=>{for(let u of i){let c=await u.key,p=await u.value;if(c.status==="aborted"||p.status==="aborted")return O;(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 u of i){let c=u.key,p=u.value;if(c.status==="aborted"||p.status==="aborted")return O;(c.status==="dirty"||p.status==="dirty")&&n.dirty(),a.set(c.value,p.value)}return{status:n.value,value:a}}}};pn.create=(e,t,n)=>new pn({valueType:t,keyType:e,typeName:M.ZodMap,...L(n)});var fn=class e extends U{_parse(t){let{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==A.set)return w(r,{code:E.invalid_type,expected:A.set,received:r.parsedType}),O;let o=this._def;o.minSize!==null&&r.data.size<o.minSize.value&&(w(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&&(w(r,{code:E.too_big,maximum:o.maxSize.value,type:"set",inclusive:!0,exact:!1,message:o.maxSize.message}),n.dirty());let s=this._def.valueType;function i(u){let c=new Set;for(let p of u){if(p.status==="aborted")return O;p.status==="dirty"&&n.dirty(),c.add(p.value)}return{status:n.value,value:c}}let a=[...r.data.values()].map((u,c)=>s._parse(new Oe(r,u,r.path,c)));return r.common.async?Promise.all(a).then(u=>i(u)):i(a)}min(t,n){return new e({...this._def,minSize:{value:t,message:I.toString(n)}})}max(t,n){return new e({...this._def,maxSize:{value:t,message:I.toString(n)}})}size(t,n){return this.min(t,n).max(t,n)}nonempty(t){return this.min(1,t)}};fn.create=(e,t)=>new fn({valueType:e,minSize:null,maxSize:null,typeName:M.ZodSet,...L(t)});var Cr=class e extends U{constructor(){super(...arguments),this.validate=this.implement}_parse(t){let{ctx:n}=this._processInputParams(t);if(n.parsedType!==A.function)return w(n,{code:E.invalid_type,expected:A.function,received:n.parsedType}),O;function r(a,u){return Fn({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,an(),ot].filter(c=>!!c),issueData:{code:E.invalid_arguments,argumentsError:u}})}function o(a,u){return Fn({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,an(),ot].filter(c=>!!c),issueData:{code:E.invalid_return_type,returnTypeError:u}})}let s={errorMap:n.common.contextualErrorMap},i=n.data;if(this._def.returns instanceof vt){let a=this;return _e(async function(...u){let c=new we([]),p=await a._def.args.parseAsync(u,s).catch(f=>{throw c.addIssue(r(u,f)),c}),m=await Reflect.apply(i,this,p);return await a._def.returns._def.type.parseAsync(m,s).catch(f=>{throw c.addIssue(o(m,f)),c})})}else{let a=this;return _e(function(...u){let c=a._def.args.safeParse(u,s);if(!c.success)throw new we([r(u,c.error)]);let p=Reflect.apply(i,this,c.data),m=a._def.returns.safeParse(p,s);if(!m.success)throw new we([o(p,m.error)]);return m.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new e({...this._def,args:Je.create(t).rest(it.create())})}returns(t){return new e({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,n,r){return new e({args:t||Je.create([]).rest(it.create()),returns:n||it.create(),typeName:M.ZodFunction,...L(r)})}},Mt=class extends U{get schema(){return this._def.getter()}_parse(t){let{ctx:n}=this._processInputParams(t);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}};Mt.create=(e,t)=>new Mt({getter:e,typeName:M.ZodLazy,...L(t)});var Lt=class extends U{_parse(t){if(t.data!==this._def.value){let n=this._getOrReturnCtx(t);return w(n,{received:n.data,code:E.invalid_literal,expected:this._def.value}),O}return{status:"valid",value:t.data}}get value(){return this._def.value}};Lt.create=(e,t)=>new Lt({value:e,typeName:M.ZodLiteral,...L(t)});function ll(e,t){return new Pt({values:e,typeName:M.ZodEnum,...L(t)})}var Pt=class e extends U{_parse(t){if(typeof t.data!="string"){let n=this._getOrReturnCtx(t),r=this._def.values;return w(n,{expected:H.joinValues(r),received:n.parsedType,code:E.invalid_type}),O}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(t.data)){let n=this._getOrReturnCtx(t),r=this._def.values;return w(n,{received:n.data,code:E.invalid_enum_value,options:r}),O}return _e(t.data)}get options(){return this._def.values}get enum(){let t={};for(let n of this._def.values)t[n]=n;return t}get Values(){let t={};for(let n of this._def.values)t[n]=n;return t}get Enum(){let t={};for(let n of this._def.values)t[n]=n;return t}extract(t,n=this._def){return e.create(t,{...this._def,...n})}exclude(t,n=this._def){return e.create(this.options.filter(r=>!t.includes(r)),{...this._def,...n})}};Pt.create=ll;var Dt=class extends U{_parse(t){let n=H.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==A.string&&r.parsedType!==A.number){let o=H.objectValues(n);return w(r,{expected:H.joinValues(o),received:r.parsedType,code:E.invalid_type}),O}if(this._cache||(this._cache=new Set(H.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){let o=H.objectValues(n);return w(r,{received:r.data,code:E.invalid_enum_value,options:o}),O}return _e(t.data)}get enum(){return this._def.values}};Dt.create=(e,t)=>new Dt({values:e,typeName:M.ZodNativeEnum,...L(t)});var vt=class extends U{unwrap(){return this._def.type}_parse(t){let{ctx:n}=this._processInputParams(t);if(n.parsedType!==A.promise&&n.common.async===!1)return w(n,{code:E.invalid_type,expected:A.promise,received:n.parsedType}),O;let r=n.parsedType===A.promise?n.data:Promise.resolve(n.data);return _e(r.then(o=>this._def.type.parseAsync(o,{path:n.path,errorMap:n.common.contextualErrorMap})))}};vt.create=(e,t)=>new vt({type:e,typeName:M.ZodPromise,...L(t)});var Me=class extends U{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===M.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){let{status:n,ctx:r}=this._processInputParams(t),o=this._def.effect||null,s={addIssue:i=>{w(r,i),i.fatal?n.abort():n.dirty()},get path(){return r.path}};if(s.addIssue=s.addIssue.bind(s),o.type==="preprocess"){let i=o.transform(r.data,s);if(r.common.async)return Promise.resolve(i).then(async a=>{if(n.value==="aborted")return O;let u=await this._def.schema._parseAsync({data:a,path:r.path,parent:r});return u.status==="aborted"?O:u.status==="dirty"?St(u.value):n.value==="dirty"?St(u.value):u});{if(n.value==="aborted")return O;let a=this._def.schema._parseSync({data:i,path:r.path,parent:r});return a.status==="aborted"?O:a.status==="dirty"?St(a.value):n.value==="dirty"?St(a.value):a}}if(o.type==="refinement"){let i=a=>{let u=o.refinement(a,s);if(r.common.async)return Promise.resolve(u);if(u 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"?O:(a.status==="dirty"&&n.dirty(),i(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"?O:(a.status==="dirty"&&n.dirty(),i(a.value).then(()=>({status:n.value,value:a.value}))))}if(o.type==="transform")if(r.common.async===!1){let i=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!ht(i))return O;let a=o.transform(i.value,s);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(i=>ht(i)?Promise.resolve(o.transform(i.value,s)).then(a=>({status:n.value,value:a})):O);H.assertNever(o)}};Me.create=(e,t,n)=>new Me({schema:e,typeName:M.ZodEffects,effect:t,...L(n)});Me.createWithPreprocess=(e,t,n)=>new Me({schema:t,effect:{type:"preprocess",transform:e},typeName:M.ZodEffects,...L(n)});var Re=class extends U{_parse(t){return this._getType(t)===A.undefined?_e(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}};Re.create=(e,t)=>new Re({innerType:e,typeName:M.ZodOptional,...L(t)});var Qe=class extends U{_parse(t){return this._getType(t)===A.null?_e(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}};Qe.create=(e,t)=>new Qe({innerType:e,typeName:M.ZodNullable,...L(t)});var Ut=class extends U{_parse(t){let{ctx:n}=this._processInputParams(t),r=n.data;return n.parsedType===A.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}};Ut.create=(e,t)=>new Ut({innerType:e,typeName:M.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...L(t)});var Gt=class extends U{_parse(t){let{ctx:n}=this._processInputParams(t),r={...n,common:{...n.common,issues:[]}},o=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return ln(o)?o.then(s=>({status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new we(r.common.issues)},input:r.data})})):{status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new we(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}};Gt.create=(e,t)=>new Gt({innerType:e,typeName:M.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...L(t)});var hn=class extends U{_parse(t){if(this._getType(t)!==A.nan){let r=this._getOrReturnCtx(t);return w(r,{code:E.invalid_type,expected:A.nan,received:r.parsedType}),O}return{status:"valid",value:t.data}}};hn.create=e=>new hn({typeName:M.ZodNaN,...L(e)});var lp=Symbol("zod_brand"),Hn=class extends U{_parse(t){let{ctx:n}=this._processInputParams(t),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}},$n=class e extends U{_parse(t){let{status:n,ctx:r}=this._processInputParams(t);if(r.common.async)return(async()=>{let s=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?O:s.status==="dirty"?(n.dirty(),St(s.value)):this._def.out._parseAsync({data:s.value,path:r.path,parent:r})})();{let o=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?O:o.status==="dirty"?(n.dirty(),{status:"dirty",value:o.value}):this._def.out._parseSync({data:o.value,path:r.path,parent:r})}}static create(t,n){return new e({in:t,out:n,typeName:M.ZodPipeline})}},Ft=class extends U{_parse(t){let n=this._def.innerType._parse(t),r=o=>(ht(o)&&(o.value=Object.freeze(o.value)),o);return ln(n)?n.then(o=>r(o)):r(n)}unwrap(){return this._def.innerType}};Ft.create=(e,t)=>new Ft({innerType:e,typeName:M.ZodReadonly,...L(t)});function ol(e,t){let n=typeof e=="function"?e(t):typeof e=="string"?{message:e}:e;return typeof n=="string"?{message:n}:n}function cl(e,t={},n){return e?gt.create().superRefine((r,o)=>{let s=e(r);if(s instanceof Promise)return s.then(i=>{if(!i){let a=ol(t,r),u=a.fatal??n??!0;o.addIssue({code:"custom",...a,fatal:u})}});if(!s){let i=ol(t,r),a=i.fatal??n??!0;o.addIssue({code:"custom",...i,fatal:a})}}):gt.create()}var cp={object:ke.lazycreate},M;(function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"})(M||(M={}));var up=(e,t={message:`Input not instance of ${e.name}`})=>cl(n=>n instanceof e,t),ul=mt.create,dl=wt.create,dp=hn.create,pp=kt.create,pl=At.create,fp=It.create,hp=un.create,mp=Ct.create,gp=Nt.create,vp=gt.create,yp=it.create,bp=Fe.create,xp=dn.create,Ep=at.create,_p=ke.create,Tp=ke.strictCreate,Sp=Rt.create,wp=Ar.create,kp=Ot.create,Ap=Je.create,Ip=Ir.create,Cp=pn.create,Np=fn.create,Rp=Cr.create,Op=Mt.create,Mp=Lt.create,Lp=Pt.create,Pp=Dt.create,Dp=vt.create,Up=Me.create,Gp=Re.create,Fp=Qe.create,Hp=Me.createWithPreprocess,$p=$n.create,zp=()=>ul().optional(),Bp=()=>dl().optional(),Vp=()=>pl().optional(),jp={string:(e=>mt.create({...e,coerce:!0})),number:(e=>wt.create({...e,coerce:!0})),boolean:(e=>At.create({...e,coerce:!0})),bigint:(e=>kt.create({...e,coerce:!0})),date:(e=>It.create({...e,coerce:!0}))};var Wp=O;var Xp=l.object({name:l.string(),arguments:l.string()}),Zp=l.object({id:l.string(),type:l.literal("function"),function:Xp,encryptedValue:l.string().optional()}),Nr=l.object({id:l.string(),role:l.string(),content:l.string().optional(),name:l.string().optional(),encryptedValue:l.string().optional()}),Kp=l.object({type:l.literal("text"),text:l.string()}),Yp=l.object({type:l.literal("data"),value:l.string(),mimeType:l.string()}),qp=l.object({type:l.literal("url"),value:l.string(),mimeType:l.string().optional()}),Rr=l.discriminatedUnion("type",[Yp,qp]),Jp=l.object({type:l.literal("image"),source:Rr,metadata:l.unknown().optional()}),Qp=l.object({type:l.literal("audio"),source:Rr,metadata:l.unknown().optional()}),ef=l.object({type:l.literal("video"),source:Rr,metadata:l.unknown().optional()}),tf=l.object({type:l.literal("document"),source:Rr,metadata:l.unknown().optional()});var fl=l.object({type:l.literal("binary"),mimeType:l.string(),id:l.string().optional(),url:l.string().optional(),data:l.string().optional(),filename:l.string().optional()}),hl=(e,t)=>{!e.id&&!e.url&&!e.data&&t.addIssue({code:l.ZodIssueCode.custom,message:"BinaryInputContent requires at least one of id, url, or data.",path:["id"]})},fv=fl.superRefine((e,t)=>{hl(e,t)}),nf=l.discriminatedUnion("type",[Kp,Jp,Qp,ef,tf,fl]),rf=nf.superRefine((e,t)=>{e.type==="binary"&&hl(e,t)}),of=Nr.extend({role:l.literal("developer"),content:l.string()}),sf=Nr.extend({role:l.literal("system"),content:l.string()}),af=Nr.extend({role:l.literal("assistant"),content:l.string().optional(),toolCalls:l.array(Zp).optional()}),lf=Nr.extend({role:l.literal("user"),content:l.union([l.string(),l.array(rf)])}),cf=l.object({id:l.string(),content:l.string(),role:l.literal("tool"),toolCallId:l.string(),error:l.string().optional(),encryptedValue:l.string().optional()}),uf=l.object({id:l.string(),role:l.literal("activity"),activityType:l.string(),content:l.record(l.any())}),df=l.object({id:l.string(),role:l.literal("reasoning"),content:l.string(),encryptedValue:l.string().optional()}),ml=l.discriminatedUnion("role",[of,sf,af,lf,cf,uf,df]),hv=l.union([l.literal("developer"),l.literal("system"),l.literal("assistant"),l.literal("user"),l.literal("tool"),l.literal("activity"),l.literal("reasoning")]),pf=l.object({description:l.string(),value:l.string()}),gl=l.object({name:l.string(),description:l.string(),parameters:l.any(),metadata:l.record(l.any()).optional()}),ff=l.object({id:l.string(),reason:l.string(),message:l.string().optional(),toolCallId:l.string().optional(),responseSchema:l.record(l.any()).optional(),expiresAt:l.string().optional(),metadata:l.record(l.any()).optional()}),hf=l.object({interruptId:l.string(),status:l.enum(["resolved","cancelled"]),payload:l.any().optional()}),mf=l.object({threadId:l.string(),runId:l.string(),parentRunId:l.string().optional(),state:l.any(),messages:l.array(ml),tools:l.array(gl),context:l.array(pf),forwardedProps:l.any(),resume:l.array(hf).optional()}),gf=l.any(),q=class extends Error{constructor(e){super(e)}},Js=class extends q{constructor(){super("Connect not implemented. This method is not supported by the current agent.")}},vf=l.object({name:l.string(),description:l.string().optional()}),yf=l.object({name:l.string().optional(),type:l.string().optional(),description:l.string().optional(),version:l.string().optional(),provider:l.string().optional(),documentationUrl:l.string().optional(),metadata:l.record(l.unknown()).optional()}),bf=l.object({streaming:l.boolean().optional(),websocket:l.boolean().optional(),httpBinary:l.boolean().optional(),pushNotifications:l.boolean().optional(),resumable:l.boolean().optional()}),xf=l.object({supported:l.boolean().optional(),items:l.array(gl).optional(),parallelCalls:l.boolean().optional(),clientProvided:l.boolean().optional()}),Ef=l.object({structuredOutput:l.boolean().optional(),supportedMimeTypes:l.array(l.string()).optional()}),_f=l.object({snapshots:l.boolean().optional(),deltas:l.boolean().optional(),memory:l.boolean().optional(),persistentState:l.boolean().optional()}),Tf=l.object({supported:l.boolean().optional(),delegation:l.boolean().optional(),handoffs:l.boolean().optional(),subAgents:l.array(vf).optional()}),Sf=l.object({supported:l.boolean().optional(),streaming:l.boolean().optional(),encrypted:l.boolean().optional()}),wf=l.object({image:l.boolean().optional(),audio:l.boolean().optional(),video:l.boolean().optional(),pdf:l.boolean().optional(),file:l.boolean().optional()}),kf=l.object({image:l.boolean().optional(),audio:l.boolean().optional()}),Af=l.object({input:wf.optional(),output:kf.optional()}),If=l.object({codeExecution:l.boolean().optional(),sandboxed:l.boolean().optional(),maxIterations:l.number().optional(),maxExecutionTime:l.number().optional()}),Cf=l.object({supported:l.boolean().optional(),approvals:l.boolean().optional(),interventions:l.boolean().optional(),feedback:l.boolean().optional(),interrupts:l.boolean().optional(),approveWithEdits:l.boolean().optional()}),mv=l.object({identity:yf.optional(),transport:bf.optional(),tools:xf.optional(),output:Ef.optional(),state:_f.optional(),multiAgent:Tf.optional(),reasoning:Sf.optional(),multimodal:Af.optional(),execution:If.optional(),humanInTheLoop:Cf.optional(),custom:l.record(l.unknown()).optional()}),vl=l.union([l.literal("developer"),l.literal("system"),l.literal("assistant"),l.literal("user")]),v=(function(e){return e.TEXT_MESSAGE_START="TEXT_MESSAGE_START",e.TEXT_MESSAGE_CONTENT="TEXT_MESSAGE_CONTENT",e.TEXT_MESSAGE_END="TEXT_MESSAGE_END",e.TEXT_MESSAGE_CHUNK="TEXT_MESSAGE_CHUNK",e.TOOL_CALL_START="TOOL_CALL_START",e.TOOL_CALL_ARGS="TOOL_CALL_ARGS",e.TOOL_CALL_END="TOOL_CALL_END",e.TOOL_CALL_CHUNK="TOOL_CALL_CHUNK",e.TOOL_CALL_RESULT="TOOL_CALL_RESULT",e.THINKING_START="THINKING_START",e.THINKING_END="THINKING_END",e.THINKING_TEXT_MESSAGE_START="THINKING_TEXT_MESSAGE_START",e.THINKING_TEXT_MESSAGE_CONTENT="THINKING_TEXT_MESSAGE_CONTENT",e.THINKING_TEXT_MESSAGE_END="THINKING_TEXT_MESSAGE_END",e.STATE_SNAPSHOT="STATE_SNAPSHOT",e.STATE_DELTA="STATE_DELTA",e.MESSAGES_SNAPSHOT="MESSAGES_SNAPSHOT",e.ACTIVITY_SNAPSHOT="ACTIVITY_SNAPSHOT",e.ACTIVITY_DELTA="ACTIVITY_DELTA",e.RAW="RAW",e.CUSTOM="CUSTOM",e.RUN_STARTED="RUN_STARTED",e.RUN_FINISHED="RUN_FINISHED",e.RUN_ERROR="RUN_ERROR",e.STEP_STARTED="STEP_STARTED",e.STEP_FINISHED="STEP_FINISHED",e.REASONING_START="REASONING_START",e.REASONING_MESSAGE_START="REASONING_MESSAGE_START",e.REASONING_MESSAGE_CONTENT="REASONING_MESSAGE_CONTENT",e.REASONING_MESSAGE_END="REASONING_MESSAGE_END",e.REASONING_MESSAGE_CHUNK="REASONING_MESSAGE_CHUNK",e.REASONING_END="REASONING_END",e.REASONING_ENCRYPTED_VALUE="REASONING_ENCRYPTED_VALUE",e})({}),V=l.object({type:l.nativeEnum(v),timestamp:l.number().optional(),rawEvent:l.any().optional()}).passthrough(),Nf=V.extend({type:l.literal(v.TEXT_MESSAGE_START),messageId:l.string(),role:vl.default("assistant"),name:l.string().optional()}),yl=V.extend({type:l.literal(v.TEXT_MESSAGE_CONTENT),messageId:l.string(),delta:l.string()}),Rf=V.extend({type:l.literal(v.TEXT_MESSAGE_END),messageId:l.string()}),Of=V.extend({type:l.literal(v.TEXT_MESSAGE_CHUNK),messageId:l.string().optional(),role:vl.optional(),delta:l.string().optional(),name:l.string().optional()}),Mf=V.extend({type:l.literal(v.THINKING_TEXT_MESSAGE_START)}),Lf=yl.omit({messageId:!0,type:!0}).extend({type:l.literal(v.THINKING_TEXT_MESSAGE_CONTENT)}),Pf=V.extend({type:l.literal(v.THINKING_TEXT_MESSAGE_END)}),Df=V.extend({type:l.literal(v.TOOL_CALL_START),toolCallId:l.string(),toolCallName:l.string(),parentMessageId:l.string().optional()}),Uf=V.extend({type:l.literal(v.TOOL_CALL_ARGS),toolCallId:l.string(),delta:l.string()}),Gf=V.extend({type:l.literal(v.TOOL_CALL_END),toolCallId:l.string()}),Ff=V.extend({messageId:l.string(),type:l.literal(v.TOOL_CALL_RESULT),toolCallId:l.string(),content:l.string(),role:l.literal("tool").optional()}),Hf=V.extend({type:l.literal(v.TOOL_CALL_CHUNK),toolCallId:l.string().optional(),toolCallName:l.string().optional(),parentMessageId:l.string().optional(),delta:l.string().optional()}),$f=V.extend({type:l.literal(v.THINKING_START),title:l.string().optional()}),zf=V.extend({type:l.literal(v.THINKING_END)}),Bf=V.extend({type:l.literal(v.STATE_SNAPSHOT),snapshot:gf}),Vf=V.extend({type:l.literal(v.STATE_DELTA),delta:l.array(l.any())}),jf=V.extend({type:l.literal(v.MESSAGES_SNAPSHOT),messages:l.array(ml)}),Wf=V.extend({type:l.literal(v.ACTIVITY_SNAPSHOT),messageId:l.string(),activityType:l.string(),content:l.record(l.any()),replace:l.boolean().optional().default(!0)}),Xf=V.extend({type:l.literal(v.ACTIVITY_DELTA),messageId:l.string(),activityType:l.string(),patch:l.array(l.any())}),Zf=V.extend({type:l.literal(v.RAW),event:l.any(),source:l.string().optional()}),Kf=V.extend({type:l.literal(v.CUSTOM),name:l.string(),value:l.any()}),Yf=V.extend({type:l.literal(v.RUN_STARTED),threadId:l.string(),runId:l.string(),parentRunId:l.string().optional(),input:mf.optional()}),qf=l.object({type:l.literal("success")}).strict(),Jf=l.object({type:l.literal("interrupt"),interrupts:l.array(ff).min(1)}).strict(),Qf=l.discriminatedUnion("type",[qf,Jf]),eh=V.extend({type:l.literal(v.RUN_FINISHED),threadId:l.string(),runId:l.string(),result:l.any().optional(),outcome:Qf.nullable().optional().transform(e=>e??void 0)}),th=V.extend({type:l.literal(v.RUN_ERROR),message:l.string(),code:l.string().optional()}),nh=V.extend({type:l.literal(v.STEP_STARTED),stepName:l.string()}),rh=V.extend({type:l.literal(v.STEP_FINISHED),stepName:l.string()}),oh=l.union([l.literal("tool-call"),l.literal("message")]),sh=V.extend({type:l.literal(v.REASONING_START),messageId:l.string()}),ih=V.extend({type:l.literal(v.REASONING_MESSAGE_START),messageId:l.string(),role:l.literal("reasoning")}),ah=V.extend({type:l.literal(v.REASONING_MESSAGE_CONTENT),messageId:l.string(),delta:l.string()}),lh=V.extend({type:l.literal(v.REASONING_MESSAGE_END),messageId:l.string()}),ch=V.extend({type:l.literal(v.REASONING_MESSAGE_CHUNK),messageId:l.string().optional(),delta:l.string().optional()}),uh=V.extend({type:l.literal(v.REASONING_END),messageId:l.string()}),dh=V.extend({type:l.literal(v.REASONING_ENCRYPTED_VALUE),subtype:oh,entityId:l.string(),encryptedValue:l.string()}),Or=l.discriminatedUnion("type",[Nf,yl,Rf,Of,$f,zf,Mf,Lf,Pf,Df,Uf,Gf,Hf,Ff,Bf,Vf,jf,Wf,Xf,Zf,Kf,Yf,eh,th,nh,rh,sh,ih,ah,lh,ch,uh,dh]);var Qs={};hs(Qs,{JsonPatchError:()=>re,_areEquals:()=>Vn,applyOperation:()=>Ht,applyPatch:()=>Fr,applyReducer:()=>gh,deepClone:()=>hh,getValueByPointer:()=>Ur,validate:()=>xl,validator:()=>Gr});var ph=(function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,o){r.__proto__=o}||function(r,o){for(var s in o)o.hasOwnProperty(s)&&(r[s]=o[s])},e(t,n)};return function(t,n){e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}})(),fh=Object.prototype.hasOwnProperty;function Lr(e,t){return fh.call(e,t)}function Pr(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n<t.length;n++)t[n]=""+n;return t}if(Object.keys)return Object.keys(e);var r=[];for(var o in e)Lr(e,o)&&r.push(o);return r}function be(e){switch(typeof e){case"object":return JSON.parse(JSON.stringify(e));case"undefined":return null;default:return e}}function Dr(e){for(var t=0,n=e.length,r;t<n;){if(r=e.charCodeAt(t),r>=48&&r<=57){t++;continue}return!1}return!0}function et(e){return e.indexOf("/")===-1&&e.indexOf("~")===-1?e:e.replace(/~/g,"~0").replace(/\//g,"~1")}function zn(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Mr(e){if(e===void 0)return!0;if(e){if(Array.isArray(e)){for(var t=0,n=e.length;t<n;t++)if(Mr(e[t]))return!0}else if(typeof e=="object"){for(var r=Pr(e),o=r.length,s=0;s<o;s++)if(Mr(e[r[s]]))return!0}}return!1}function bl(e,t){var n=[e];for(var r in t){var o=typeof t[r]=="object"?JSON.stringify(t[r],null,2):t[r];typeof o<"u"&&n.push(r+": "+o)}return n.join(`
695
+ `)}var Bn=(function(e){ph(t,e);function t(n,r,o,s,i){var a=this.constructor,u=e.call(this,bl(n,{name:r,index:o,operation:s,tree:i}))||this;return u.name=r,u.index=o,u.operation=s,u.tree=i,Object.setPrototypeOf(u,a.prototype),u.message=bl(n,{name:r,index:o,operation:s,tree:i}),u}return t})(Error);var re=Bn,hh=be,mn={add:function(e,t,n){return e[t]=this.value,{newDocument:n}},remove:function(e,t,n){var r=e[t];return delete e[t],{newDocument:n,removed:r}},replace:function(e,t,n){var r=e[t];return e[t]=this.value,{newDocument:n,removed:r}},move:function(e,t,n){var r=Ur(n,this.path);r&&(r=be(r));var o=Ht(n,{op:"remove",path:this.from}).removed;return Ht(n,{op:"add",path:this.path,value:o}),{newDocument:n,removed:r}},copy:function(e,t,n){var r=Ur(n,this.from);return Ht(n,{op:"add",path:this.path,value:be(r)}),{newDocument:n}},test:function(e,t,n){return{newDocument:n,test:Vn(e[t],this.value)}},_get:function(e,t,n){return this.value=e[t],{newDocument:n}}},mh={add:function(e,t,n){return Dr(t)?e.splice(t,0,this.value):e[t]=this.value,{newDocument:n,index:t}},remove:function(e,t,n){var r=e.splice(t,1);return{newDocument:n,removed:r[0]}},replace:function(e,t,n){var r=e[t];return e[t]=this.value,{newDocument:n,removed:r}},move:mn.move,copy:mn.copy,test:mn.test,_get:mn._get};function Ur(e,t){if(t=="")return e;var n={op:"_get",path:t};return Ht(e,n),n.value}function Ht(e,t,n,r,o,s){if(n===void 0&&(n=!1),r===void 0&&(r=!0),o===void 0&&(o=!0),s===void 0&&(s=0),n&&(typeof n=="function"?n(t,0,e,t.path):Gr(t,0)),t.path===""){var i={newDocument:e};if(t.op==="add")return i.newDocument=t.value,i;if(t.op==="replace")return i.newDocument=t.value,i.removed=e,i;if(t.op==="move"||t.op==="copy")return i.newDocument=Ur(e,t.from),t.op==="move"&&(i.removed=e),i;if(t.op==="test"){if(i.test=Vn(e,t.value),i.test===!1)throw new re("Test operation failed","TEST_OPERATION_FAILED",s,t,e);return i.newDocument=e,i}else{if(t.op==="remove")return i.removed=e,i.newDocument=null,i;if(t.op==="_get")return t.value=e,i;if(n)throw new re("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",s,t,e);return i}}else{r||(e=be(e));var a=t.path||"",u=a.split("/"),c=e,p=1,m=u.length,x=void 0,f=void 0,h=void 0;for(typeof n=="function"?h=n:h=Gr;;){if(f=u[p],f&&f.indexOf("~")!=-1&&(f=zn(f)),o&&(f=="__proto__"||f=="prototype"&&p>0&&u[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&&x===void 0&&(c[f]===void 0?x=u.slice(0,p).join("/"):p==m-1&&(x=t.path),x!==void 0&&h(t,0,e,x)),p++,Array.isArray(c)){if(f==="-")f=c.length;else{if(n&&!Dr(f))throw new re("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",s,t,e);Dr(f)&&(f=~~f)}if(p>=m){if(n&&t.op==="add"&&f>c.length)throw new re("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",s,t,e);var i=mh[t.op].call(t,c,f,e);if(i.test===!1)throw new re("Test operation failed","TEST_OPERATION_FAILED",s,t,e);return i}}else if(p>=m){var i=mn[t.op].call(t,c,f,e);if(i.test===!1)throw new re("Test operation failed","TEST_OPERATION_FAILED",s,t,e);return i}if(c=c[f],n&&p<m&&(!c||typeof c!="object"))throw new re("Cannot perform operation at the desired path","OPERATION_PATH_UNRESOLVABLE",s,t,e)}}}function Fr(e,t,n,r,o){if(r===void 0&&(r=!0),o===void 0&&(o=!0),n&&!Array.isArray(t))throw new re("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");r||(e=be(e));for(var s=new Array(t.length),i=0,a=t.length;i<a;i++)s[i]=Ht(e,t[i],n,!0,o,i),e=s[i].newDocument;return s.newDocument=e,s}function gh(e,t,n){var r=Ht(e,t);if(r.test===!1)throw new re("Test operation failed","TEST_OPERATION_FAILED",n,t,e);return r.newDocument}function Gr(e,t,n,r){if(typeof e!="object"||e===null||Array.isArray(e))throw new re("Operation is not an object","OPERATION_NOT_AN_OBJECT",t,e,n);if(mn[e.op]){if(typeof e.path!="string")throw new re("Operation `path` property is not a string","OPERATION_PATH_INVALID",t,e,n);if(e.path.indexOf("/")!==0&&e.path.length>0)throw new re('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",t,e,n);if((e.op==="move"||e.op==="copy")&&typeof e.from!="string")throw new re("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",t,e,n);if((e.op==="add"||e.op==="replace"||e.op==="test")&&e.value===void 0)throw new re("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",t,e,n);if((e.op==="add"||e.op==="replace"||e.op==="test")&&Mr(e.value))throw new re("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",t,e,n);if(n){if(e.op=="add"){var o=e.path.split("/").length,s=r.split("/").length;if(o!==s+1&&o!==s)throw new re("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",t,e,n)}else if(e.op==="replace"||e.op==="remove"||e.op==="_get"){if(e.path!==r)throw new re("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",t,e,n)}else if(e.op==="move"||e.op==="copy"){var i={op:"_get",path:e.from,value:void 0},a=xl([i],n);if(a&&a.name==="OPERATION_PATH_UNRESOLVABLE")throw new re("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",t,e,n)}}}else throw new re("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",t,e,n)}function xl(e,t,n){try{if(!Array.isArray(e))throw new re("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(t)Fr(be(t),be(e),n||!0);else{n=n||Gr;for(var r=0;r<e.length;r++)n(e[r],r,t,void 0)}}catch(o){if(o instanceof re)return o;throw o}}function Vn(e,t){if(e===t)return!0;if(e&&t&&typeof e=="object"&&typeof t=="object"){var n=Array.isArray(e),r=Array.isArray(t),o,s,i;if(n&&r){if(s=e.length,s!=t.length)return!1;for(o=s;o--!==0;)if(!Vn(e[o],t[o]))return!1;return!0}if(n!=r)return!1;var a=Object.keys(e);if(s=a.length,s!==Object.keys(t).length)return!1;for(o=s;o--!==0;)if(!t.hasOwnProperty(a[o]))return!1;for(o=s;o--!==0;)if(i=a[o],!Vn(e[i],t[i]))return!1;return!0}return e!==e&&t!==t}var ri={};hs(ri,{compare:()=>Sh,generate:()=>ei,observe:()=>Th,unobserve:()=>_h});var ti=new WeakMap,vh=(function(){function e(t){this.observers=new Map,this.obj=t}return e})(),yh=(function(){function e(t,n){this.callback=t,this.observer=n}return e})();function bh(e){return ti.get(e)}function xh(e,t){return e.observers.get(t)}function Eh(e,t){e.observers.delete(t.callback)}function _h(e,t){t.unobserve()}function Th(e,t){var n=[],r,o=bh(e);if(!o)o=new vh(e),ti.set(e,o);else{var s=xh(o,t);r=s&&s.observer}if(r)return r;if(r={},o.value=be(e),t){r.callback=t,r.next=null;var i=function(){ei(r)},a=function(){clearTimeout(r.next),r.next=setTimeout(i)};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=e,r.unobserve=function(){ei(r),clearTimeout(r.next),Eh(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(t,new yh(t,r)),r}function ei(e,t){t===void 0&&(t=!1);var n=ti.get(e.object);ni(n.value,e.object,e.patches,"",t),e.patches.length&&Fr(n.value,e.patches);var r=e.patches;return r.length>0&&(e.patches=[],e.callback&&e.callback(r)),r}function ni(e,t,n,r,o){if(t!==e){typeof t.toJSON=="function"&&(t=t.toJSON());for(var s=Pr(t),i=Pr(e),a=!1,u=!1,c=i.length-1;c>=0;c--){var p=i[c],m=e[p];if(Lr(t,p)&&!(t[p]===void 0&&m!==void 0&&Array.isArray(t)===!1)){var x=t[p];typeof m=="object"&&m!=null&&typeof x=="object"&&x!=null&&Array.isArray(m)===Array.isArray(x)?ni(m,x,n,r+"/"+et(p),o):m!==x&&(a=!0,o&&n.push({op:"test",path:r+"/"+et(p),value:be(m)}),n.push({op:"replace",path:r+"/"+et(p),value:be(x)}))}else Array.isArray(e)===Array.isArray(t)?(o&&n.push({op:"test",path:r+"/"+et(p),value:be(m)}),n.push({op:"remove",path:r+"/"+et(p)}),u=!0):(o&&n.push({op:"test",path:r,value:e}),n.push({op:"replace",path:r,value:t}),a=!0)}if(!(!u&&s.length==i.length))for(var c=0;c<s.length;c++){var p=s[c];!Lr(e,p)&&t[p]!==void 0&&n.push({op:"add",path:r+"/"+et(p),value:be(t[p])})}}}function Sh(e,t,n){n===void 0&&(n=!1);var r=[];return ni(e,t,r,"",n),r}var Hr=Object.assign({},Qs,ri,{JsonPatchError:Bn,deepClone:be,escapePathComponent:et,unescapePathComponent:zn});var oi=function(e,t){return oi=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])},oi(e,t)};function tt(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");oi(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}function El(e,t,n,r){function o(s){return s instanceof n?s:new n(function(i){i(s)})}return new(n||(n=Promise))(function(s,i){function a(p){try{c(r.next(p))}catch(m){i(m)}}function u(p){try{c(r.throw(p))}catch(m){i(m)}}function c(p){p.done?s(p.value):o(p.value).then(a,u)}c((r=r.apply(e,t||[])).next())})}function $r(e,t){var n={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,o,s,i=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function a(c){return function(p){return u([c,p])}}function u(c){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(n=0)),n;)try{if(r=1,o&&(s=c[0]&2?o.return:c[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,c[1])).done)return s;switch(o=0,s&&(c=[c[0]&2,s.value]),c[0]){case 0:case 1:s=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(s=n.trys,!(s=s.length>0&&s[s.length-1])&&(c[0]===6||c[0]===2)){n=0;continue}if(c[0]===3&&(!s||c[1]>s[0]&&c[1]<s[3])){n.label=c[1];break}if(c[0]===6&&n.label<s[1]){n.label=s[1],s=c;break}if(s&&n.label<s[2]){n.label=s[2],n.ops.push(c);break}s[2]&&n.ops.pop(),n.trys.pop();continue}c=t.call(e,n)}catch(p){c=[6,p],o=0}finally{r=s=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}function lt(e){var t=typeof Symbol=="function"&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function gn(e,t){var n=typeof Symbol=="function"&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),o,s=[],i;try{for(;(t===void 0||t-- >0)&&!(o=r.next()).done;)s.push(o.value)}catch(a){i={error:a}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return s}function vn(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}function $t(e){return this instanceof $t?(this.v=e,this):new $t(e)}function _l(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),o,s=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(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(_,S){s.push([f,g,_,S])>1||u(f,g)})},h&&(o[f]=h(o[f])))}function u(f,h){try{c(r[f](h))}catch(g){x(s[0][3],g)}}function c(f){f.value instanceof $t?Promise.resolve(f.value.v).then(p,m):x(s[0][2],f)}function p(f){u("next",f)}function m(f){u("throw",f)}function x(f,h){f(h),s.shift(),s.length&&u(s[0][0],s[0][1])}}function Tl(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof lt=="function"?lt(e):e[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(s){n[s]=e[s]&&function(i){return new Promise(function(a,u){i=e[s](i),o(a,u,i.done,i.value)})}}function o(s,i,a,u){Promise.resolve(u).then(function(c){s({value:c,done:a})},i)}}function G(e){return typeof e=="function"}function yn(e){var t=function(r){Error.call(r),r.stack=new Error().stack},n=e(t);return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var zr=yn(function(e){return function(n){e(this),this.message=n?n.length+` errors occurred during unsubscription:
696
+ `+n.map(function(r,o){return o+1+") "+r.toString()}).join(`
697
+ `):"",this.name="UnsubscriptionError",this.errors=n}});function jn(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var bn=(function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,n,r,o,s;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var a=lt(i),u=a.next();!u.done;u=a.next()){var c=u.value;c.remove(this)}}catch(g){t={error:g}}finally{try{u&&!u.done&&(n=a.return)&&n.call(a)}finally{if(t)throw t.error}}else i.remove(this);var p=this.initialTeardown;if(G(p))try{p()}catch(g){s=g instanceof zr?g.errors:[g]}var m=this._finalizers;if(m){this._finalizers=null;try{for(var x=lt(m),f=x.next();!f.done;f=x.next()){var h=f.value;try{Sl(h)}catch(g){s=s??[],g instanceof zr?s=vn(vn([],gn(s)),gn(g.errors)):s.push(g)}}}catch(g){r={error:g}}finally{try{f&&!f.done&&(o=x.return)&&o.call(x)}finally{if(r)throw r.error}}}if(s)throw new zr(s)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)Sl(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(n=this._finalizers)!==null&&n!==void 0?n:[]).push(t)}},e.prototype._hasParent=function(t){var n=this._parentage;return n===t||Array.isArray(n)&&n.includes(t)},e.prototype._addParent=function(t){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(t),n):n?[n,t]:t},e.prototype._removeParent=function(t){var n=this._parentage;n===t?this._parentage=null:Array.isArray(n)&&jn(n,t)},e.prototype.remove=function(t){var n=this._finalizers;n&&jn(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=(function(){var t=new e;return t.closed=!0,t})(),e})();var si=bn.EMPTY;function Br(e){return e instanceof bn||e&&"closed"in e&&G(e.remove)&&G(e.add)&&G(e.unsubscribe)}function Sl(e){G(e)?e():e.unsubscribe()}var He={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var xn={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=xn.delegate;return o?.setTimeout?o.setTimeout.apply(o,vn([e,t],gn(n))):setTimeout.apply(void 0,vn([e,t],gn(n)))},clearTimeout:function(e){var t=xn.delegate;return(t?.clearTimeout||clearTimeout)(e)},delegate:void 0};function Vr(e){xn.setTimeout(function(){var t=He.onUnhandledError;if(t)t(e);else throw e})}function Wn(){}var wl=(function(){return ii("C",void 0,void 0)})();function kl(e){return ii("E",void 0,e)}function Al(e){return ii("N",e,void 0)}function ii(e,t,n){return{kind:e,value:t,error:n}}var zt=null;function En(e){if(He.useDeprecatedSynchronousErrorHandling){var t=!zt;if(t&&(zt={errorThrown:!1,error:null}),e(),t){var n=zt,r=n.errorThrown,o=n.error;if(zt=null,r)throw o}}else e()}function Il(e){He.useDeprecatedSynchronousErrorHandling&&zt&&(zt.errorThrown=!0,zt.error=e)}var Xn=(function(e){tt(t,e);function t(n){var r=e.call(this)||this;return r.isStopped=!1,n?(r.destination=n,Br(n)&&n.add(r)):r.destination=Ih,r}return t.create=function(n,r,o){return new Wr(n,r,o)},t.prototype.next=function(n){this.isStopped?li(Al(n),this):this._next(n)},t.prototype.error=function(n){this.isStopped?li(kl(n),this):(this.isStopped=!0,this._error(n))},t.prototype.complete=function(){this.isStopped?li(wl,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(n){this.destination.next(n)},t.prototype._error=function(n){try{this.destination.error(n)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(bn);var wh=Function.prototype.bind;function ai(e,t){return wh.call(e,t)}var kh=(function(){function e(t){this.partialObserver=t}return e.prototype.next=function(t){var n=this.partialObserver;if(n.next)try{n.next(t)}catch(r){jr(r)}},e.prototype.error=function(t){var n=this.partialObserver;if(n.error)try{n.error(t)}catch(r){jr(r)}else jr(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(n){jr(n)}},e})(),Wr=(function(e){tt(t,e);function t(n,r,o){var s=e.call(this)||this,i;if(G(n)||!n)i={next:n??void 0,error:r??void 0,complete:o??void 0};else{var a;s&&He.useDeprecatedNextContext?(a=Object.create(n),a.unsubscribe=function(){return s.unsubscribe()},i={next:n.next&&ai(n.next,a),error:n.error&&ai(n.error,a),complete:n.complete&&ai(n.complete,a)}):i=n}return s.destination=new kh(i),s}return t})(Xn);function jr(e){He.useDeprecatedSynchronousErrorHandling?Il(e):Vr(e)}function Ah(e){throw e}function li(e,t){var n=He.onStoppedNotification;n&&xn.setTimeout(function(){return n(e,t)})}var Ih={closed:!0,next:Wn,error:Ah,complete:Wn};var _n=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Tn(e){return e}function Xr(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return ci(e)}function ci(e){return e.length===0?Tn:e.length===1?e[0]:function(n){return e.reduce(function(r,o){return o(r)},n)}}var J=(function(){function e(t){t&&(this._subscribe=t)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(t,n,r){var o=this,s=Nh(t)?t:new Wr(t,n,r);return En(function(){var i=o,a=i.operator,u=i.source;s.add(a?a.call(s,u):u?o._subscribe(s):o._trySubscribe(s))}),s},e.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(n){t.error(n)}},e.prototype.forEach=function(t,n){var r=this;return n=Cl(n),new n(function(o,s){var i=new Wr({next:function(a){try{t(a)}catch(u){s(u),i.unsubscribe()}},error:s,complete:o});r.subscribe(i)})},e.prototype._subscribe=function(t){var n;return(n=this.source)===null||n===void 0?void 0:n.subscribe(t)},e.prototype[_n]=function(){return this},e.prototype.pipe=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return ci(t)(this)},e.prototype.toPromise=function(t){var n=this;return t=Cl(t),new t(function(r,o){var s;n.subscribe(function(i){return s=i},function(i){return o(i)},function(){return r(s)})})},e.create=function(t){return new e(t)},e})();function Cl(e){var t;return(t=e??He.Promise)!==null&&t!==void 0?t:Promise}function Ch(e){return e&&G(e.next)&&G(e.error)&&G(e.complete)}function Nh(e){return e&&e instanceof Xn||Ch(e)&&Br(e)}function Rh(e){return G(e?.lift)}function ue(e){return function(t){if(Rh(t))return t.lift(function(n){try{return e(n,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function fe(e,t,n,r,o){return new Oh(e,t,n,r,o)}var Oh=(function(e){tt(t,e);function t(n,r,o,s,i,a){var u=e.call(this,n)||this;return u.onFinalize=i,u.shouldUnsubscribe=a,u._next=r?function(c){try{r(c)}catch(p){n.error(p)}}:e.prototype._next,u._error=s?function(c){try{s(c)}catch(p){n.error(p)}finally{this.unsubscribe()}}:e.prototype._error,u._complete=o?function(){try{o()}catch(c){n.error(c)}finally{this.unsubscribe()}}:e.prototype._complete,u}return t.prototype.unsubscribe=function(){var n;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;e.prototype.unsubscribe.call(this),!r&&((n=this.onFinalize)===null||n===void 0||n.call(this))}},t})(Xn);var Nl=yn(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}});var nt=(function(e){tt(t,e);function t(){var n=e.call(this)||this;return n.closed=!1,n.currentObservers=null,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return t.prototype.lift=function(n){var r=new Rl(this,this);return r.operator=n,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new Nl},t.prototype.next=function(n){var r=this;En(function(){var o,s;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var i=lt(r.currentObservers),a=i.next();!a.done;a=i.next()){var u=a.value;u.next(n)}}catch(c){o={error:c}}finally{try{a&&!a.done&&(s=i.return)&&s.call(i)}finally{if(o)throw o.error}}}})},t.prototype.error=function(n){var r=this;En(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)}})},t.prototype.complete=function(){var n=this;En(function(){if(n._throwIfClosed(),!n.isStopped){n.isStopped=!0;for(var r=n.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var n;return((n=this.observers)===null||n===void 0?void 0:n.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(n){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,n)},t.prototype._subscribe=function(n){return this._throwIfClosed(),this._checkFinalizedStatuses(n),this._innerSubscribe(n)},t.prototype._innerSubscribe=function(n){var r=this,o=this,s=o.hasError,i=o.isStopped,a=o.observers;return s||i?si:(this.currentObservers=null,a.push(n),new bn(function(){r.currentObservers=null,jn(a,n)}))},t.prototype._checkFinalizedStatuses=function(n){var r=this,o=r.hasError,s=r.thrownError,i=r.isStopped;o?n.error(s):i&&n.complete()},t.prototype.asObservable=function(){var n=new J;return n.source=this,n},t.create=function(n,r){return new Rl(n,r)},t})(J);var Rl=(function(e){tt(t,e);function t(n,r){var o=e.call(this)||this;return o.destination=n,o.source=r,o}return t.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)},t.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)},t.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)},t.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:si},t})(nt);var ui={now:function(){return(ui.delegate||Date).now()},delegate:void 0};var Zr=(function(e){tt(t,e);function t(n,r,o){n===void 0&&(n=1/0),r===void 0&&(r=1/0),o===void 0&&(o=ui);var s=e.call(this)||this;return s._bufferSize=n,s._windowTime=r,s._timestampProvider=o,s._buffer=[],s._infiniteTimeWindow=!0,s._infiniteTimeWindow=r===1/0,s._bufferSize=Math.max(1,n),s._windowTime=Math.max(1,r),s}return t.prototype.next=function(n){var r=this,o=r.isStopped,s=r._buffer,i=r._infiniteTimeWindow,a=r._timestampProvider,u=r._windowTime;o||(s.push(n),!i&&s.push(a.now()+u)),this._trimBuffer(),e.prototype.next.call(this,n)},t.prototype._subscribe=function(n){this._throwIfClosed(),this._trimBuffer();for(var r=this._innerSubscribe(n),o=this,s=o._infiniteTimeWindow,i=o._buffer,a=i.slice(),u=0;u<a.length&&!n.closed;u+=s?1:2)n.next(a[u]);return this._checkFinalizedStatuses(n),r},t.prototype._trimBuffer=function(){var n=this,r=n._bufferSize,o=n._timestampProvider,s=n._buffer,i=n._infiniteTimeWindow,a=(i?1:2)*r;if(r<1/0&&a<s.length&&s.splice(0,s.length-a),!i){for(var u=o.now(),c=0,p=1;p<s.length&&s[p]<=u;p+=2)c=p;c&&s.splice(0,c+1)}},t})(nt);var Kr=new J(function(e){return e.complete()});function Ol(e){return e&&G(e.schedule)}function Mh(e){return e[e.length-1]}function Ml(e){return Ol(Mh(e))?e.pop():void 0}var Yr=(function(e){return e&&typeof e.length=="number"&&typeof e!="function"});function qr(e){return G(e?.then)}function Jr(e){return G(e[_n])}function Qr(e){return Symbol.asyncIterator&&G(e?.[Symbol.asyncIterator])}function eo(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Lh(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var to=Lh();function no(e){return G(e?.[to])}function ro(e){return _l(this,arguments,function(){var n,r,o,s;return $r(this,function(i){switch(i.label){case 0:n=e.getReader(),i.label=1;case 1:i.trys.push([1,,9,10]),i.label=2;case 2:return[4,$t(n.read())];case 3:return r=i.sent(),o=r.value,s=r.done,s?[4,$t(void 0)]:[3,5];case 4:return[2,i.sent()];case 5:return[4,$t(o)];case 6:return[4,i.sent()];case 7:return i.sent(),[3,2];case 8:return[3,10];case 9:return n.releaseLock(),[7];case 10:return[2]}})})}function oo(e){return G(e?.getReader)}function he(e){if(e instanceof J)return e;if(e!=null){if(Jr(e))return Ph(e);if(Yr(e))return Dh(e);if(qr(e))return Uh(e);if(Qr(e))return Ll(e);if(no(e))return Gh(e);if(oo(e))return Fh(e)}throw eo(e)}function Ph(e){return new J(function(t){var n=e[_n]();if(G(n.subscribe))return n.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Dh(e){return new J(function(t){for(var n=0;n<e.length&&!t.closed;n++)t.next(e[n]);t.complete()})}function Uh(e){return new J(function(t){e.then(function(n){t.closed||(t.next(n),t.complete())},function(n){return t.error(n)}).then(null,Vr)})}function Gh(e){return new J(function(t){var n,r;try{for(var o=lt(e),s=o.next();!s.done;s=o.next()){var i=s.value;if(t.next(i),t.closed)return}}catch(a){n={error:a}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}t.complete()})}function Ll(e){return new J(function(t){Hh(e,t).catch(function(n){return t.error(n)})})}function Fh(e){return Ll(ro(e))}function Hh(e,t){var n,r,o,s;return El(this,void 0,void 0,function(){var i,a;return $r(this,function(u){switch(u.label){case 0:u.trys.push([0,5,6,11]),n=Tl(e),u.label=1;case 1:return[4,n.next()];case 2:if(r=u.sent(),!!r.done)return[3,4];if(i=r.value,t.next(i),t.closed)return[2];u.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=u.sent(),o={error:a},[3,11];case 6:return u.trys.push([6,,9,10]),r&&!r.done&&(s=n.return)?[4,s.call(n)]:[3,8];case 7:u.sent(),u.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function Le(e,t,n,r,o){r===void 0&&(r=0),o===void 0&&(o=!1);var s=t.schedule(function(){n(),o?e.add(this.schedule(null,r)):this.unsubscribe()},r);if(e.add(s),!o)return s}function so(e,t){return t===void 0&&(t=0),ue(function(n,r){n.subscribe(fe(r,function(o){return Le(r,e,function(){return r.next(o)},t)},function(){return Le(r,e,function(){return r.complete()},t)},function(o){return Le(r,e,function(){return r.error(o)},t)}))})}function io(e,t){return t===void 0&&(t=0),ue(function(n,r){r.add(e.schedule(function(){return n.subscribe(r)},t))})}function Pl(e,t){return he(e).pipe(io(t),so(t))}function Dl(e,t){return he(e).pipe(io(t),so(t))}function Ul(e,t){return new J(function(n){var r=0;return t.schedule(function(){r===e.length?n.complete():(n.next(e[r++]),n.closed||this.schedule())})})}function Gl(e,t){return new J(function(n){var r;return Le(n,t,function(){r=e[to](),Le(n,t,function(){var o,s,i;try{o=r.next(),s=o.value,i=o.done}catch(a){n.error(a);return}i?n.complete():n.next(s)},0,!0)}),function(){return G(r?.return)&&r.return()}})}function ao(e,t){if(!e)throw new Error("Iterable cannot be null");return new J(function(n){Le(n,t,function(){var r=e[Symbol.asyncIterator]();Le(n,t,function(){r.next().then(function(o){o.done?n.complete():n.next(o.value)})},0,!0)})})}function Fl(e,t){return ao(ro(e),t)}function Hl(e,t){if(e!=null){if(Jr(e))return Pl(e,t);if(Yr(e))return Ul(e,t);if(qr(e))return Dl(e,t);if(Qr(e))return ao(e,t);if(no(e))return Gl(e,t);if(oo(e))return Fl(e,t)}throw eo(e)}function Bt(e,t){return t?Hl(e,t):he(e)}function te(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=Ml(e);return Bt(e,n)}function Q(e,t){var n=G(e)?e:function(){return e},r=function(o){return o.error(n())};return new J(t?function(o){return t.schedule(r,0,o)}:r)}var $l=yn(function(e){return function(){e(this),this.name="EmptyError",this.message="no elements in sequence"}});function lo(e,t){var n=typeof t=="object";return new Promise(function(r,o){var s=!1,i;e.subscribe({next:function(a){i=a,s=!0},error:o,complete:function(){s?r(i):n?r(t.defaultValue):o(new $l)}})})}function Vt(e,t){return ue(function(n,r){var o=0;n.subscribe(fe(r,function(s){r.next(e.call(t,s,o++))}))})}function zl(e,t,n,r,o,s,i,a){var u=[],c=0,p=0,m=!1,x=function(){m&&!u.length&&!c&&t.complete()},f=function(g){return c<r?h(g):u.push(g)},h=function(g){s&&t.next(g),c++;var _=!1;he(n(g,p++)).subscribe(fe(t,function(S){o?.(S),s?f(S):t.next(S)},function(){_=!0},void 0,function(){if(_)try{c--;for(var S=function(){var b=u.shift();i?Le(t,i,function(){return h(b)}):h(b)};u.length&&c<r;)S();x()}catch(b){t.error(b)}}))};return e.subscribe(fe(t,f,function(){m=!0,x()})),function(){a?.()}}function Ae(e,t,n){return n===void 0&&(n=1/0),G(t)?Ae(function(r,o){return Vt(function(s,i){return t(r,s,o,i)})(he(e(r,o)))},n):(typeof t=="number"&&(n=t),ue(function(r,o){return zl(r,o,e,n)}))}function di(e){return e===void 0&&(e=1/0),Ae(Tn,e)}function co(e){return new J(function(t){he(e()).subscribe(t)})}function Zn(e){return ue(function(t,n){var r=null,o=!1,s;r=t.subscribe(fe(n,void 0,void 0,function(i){s=he(e(i,Zn(e)(t))),r?(r.unsubscribe(),r=null,s.subscribe(n)):o=!0})),o&&(r.unsubscribe(),r=null,s.subscribe(n))})}function uo(e,t){return G(t)?Ae(e,t,1):Ae(e,1)}function pi(e){return ue(function(t,n){var r=!1;t.subscribe(fe(n,function(o){r=!0,n.next(o)},function(){r||n.next(e),n.complete()}))})}function jt(e){return ue(function(t,n){try{t.subscribe(n)}finally{n.add(e)}})}function fi(e,t){return ue(function(n,r){var o=null,s=0,i=!1,a=function(){return i&&!o&&r.complete()};n.subscribe(fe(r,function(u){o?.unsubscribe();var c=0,p=s++;he(e(u,p)).subscribe(o=fe(r,function(m){return r.next(t?t(u,m,p,c++):m)},function(){o=null,a()}))},function(){i=!0,a()}))})}function po(e){return ue(function(t,n){he(e).subscribe(fe(n,function(){return n.complete()},Wn)),!n.closed&&t.subscribe(n)})}function hi(e,t,n){var r=G(e)||t||n?{next:e,error:t,complete:n}:e;return r?ue(function(o,s){var i;(i=r.subscribe)===null||i===void 0||i.call(r);var a=!0;o.subscribe(fe(s,function(u){var c;(c=r.next)===null||c===void 0||c.call(r,u),s.next(u)},function(){var u;a=!1,(u=r.complete)===null||u===void 0||u.call(r),s.complete()},function(u){var c;a=!1,(c=r.error)===null||c===void 0||c.call(r,u),s.error(u)},function(){var u,c;a&&((u=r.unsubscribe)===null||u===void 0||u.call(r)),(c=r.finalize)===null||c===void 0||c.call(r)}))}):Tn}function Bl(e){return` \r
698
+ `.indexOf(e)>=0}function fo(e){for(var t=["topLevel"],n=0,r,o,s,i=function(b){return t.push(b)},a=function(b){return t[t.length-1]=b},u=function(b){r==null&&(r=n,o=t.length,s=b)},c=function(b){b===s&&(r=void 0,o=void 0,s=void 0)},p=function(){return t.pop()},m=function(){return n--},x=function(b){if("0"<=b&&b<="9"){i("number");return}switch(b){case'"':i("string");return;case"-":i("numberNeedsDigit");return;case"t":i("true");return;case"f":i("false");return;case"n":i("null");return;case"[":i("arrayNeedsValue");return;case"{":i("objectNeedsKey");return}},f=e.length;n<f;n++){var h=e[n];switch(t[t.length-1]){case"topLevel":x(h);break;case"string":switch(h){case'"':p();break;case"\\":u("stringEscape"),i("stringEscaped");break}break;case"stringEscaped":h==="u"?i("stringUnicode"):(c("stringEscape"),p());break;case"stringUnicode":n-e.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():Bl(h)||(c("collectionItem"),a("arrayNeedsComma"),x(h));break;case"arrayNeedsComma":h==="]"?p():h===","&&(u("collectionItem"),a("arrayNeedsValue"));break;case"objectNeedsKey":h==="}"?p():h==='"'&&(u("collectionItem"),a("objectNeedsColon"),i("string"));break;case"objectNeedsColon":h===":"&&a("objectNeedsValue");break;case"objectNeedsValue":Bl(h)||(c("collectionItem"),a("objectNeedsComma"),x(h));break;case"objectNeedsComma":h==="}"?p():h===","&&(u("collectionItem"),a("objectNeedsKey"));break}}o!=null&&(t.length=o);for(var g=[r!=null?e.slice(0,r):e],_=function(b){return g.push(b.slice(e.length-e.lastIndexOf(b[0])))},S=t.length-1;S>=0;S--)switch(t[S]){case"string":g.push('"');break;case"numberNeedsDigit":case"numberNeedsExponent":g.push("0");break;case"true":_("true");break;case"false":_("false");break;case"null":_("null");break;case"arrayNeedsValue":case"arrayNeedsComma":g.push("]");break;case"objectNeedsKey":case"objectNeedsColon":case"objectNeedsValue":case"objectNeedsComma":g.push("}");break}return g.join("")}function jl(){let e=0,t=0;for(let r=0;r<28;r+=7){let o=this.buf[this.pos++];if(e|=(o&127)<<r,(o&128)==0)return this.assertBounds(),[e,t]}let n=this.buf[this.pos++];if(e|=(n&15)<<28,t=(n&112)>>4,(n&128)==0)return this.assertBounds(),[e,t];for(let r=3;r<=31;r+=7){let o=this.buf[this.pos++];if(t|=(o&127)<<r,(o&128)==0)return this.assertBounds(),[e,t]}throw new Error("invalid varint")}function mo(e,t,n){for(let s=0;s<28;s=s+7){let i=e>>>s,a=!(!(i>>>7)&&t==0),u=(a?i|128:i)&255;if(n.push(u),!a)return}let r=e>>>28&15|(t&7)<<4,o=t>>3!=0;if(n.push((o?r|128:r)&255),!!o){for(let s=3;s<31;s=s+7){let i=t>>>s,a=!!(i>>>7),u=(a?i|128:i)&255;if(n.push(u),!a)return}n.push(t>>>31&1)}}var ho=4294967296;function mi(e){let t=e[0]==="-";t&&(e=e.slice(1));let n=1e6,r=0,o=0;function s(i,a){let u=Number(e.slice(i,a));o*=n,r=r*n+u,r>=ho&&(o=o+(r/ho|0),r=r%ho)}return s(-24,-18),s(-18,-12),s(-12,-6),s(-6),t?Xl(r,o):vi(r,o)}function Wl(e,t){let n=vi(e,t),r=n.hi&2147483648;r&&(n=Xl(n.lo,n.hi));let o=gi(n.lo,n.hi);return r?"-"+o:o}function gi(e,t){if({lo:e,hi:t}=$h(e,t),t<=2097151)return String(ho*t+e);let n=e&16777215,r=(e>>>24|t<<8)&16777215,o=t>>16&65535,s=n+r*6777216+o*6710656,i=r+o*8147497,a=o*2,u=1e7;return s>=u&&(i+=Math.floor(s/u),s%=u),i>=u&&(a+=Math.floor(i/u),i%=u),a.toString()+Vl(i)+Vl(s)}function $h(e,t){return{lo:e>>>0,hi:t>>>0}}function vi(e,t){return{lo:e|0,hi:t|0}}function Xl(e,t){return t=~t,e?e=~e+1:t+=1,vi(e,t)}var Vl=e=>{let t=String(e);return"0000000".slice(t.length)+t};function yi(e,t){if(e>=0){for(;e>127;)t.push(e&127|128),e=e>>>7;t.push(e)}else{for(let n=0;n<9;n++)t.push(e&127|128),e=e>>7;t.push(1)}}function Zl(){let e=this.buf[this.pos++],t=e&127;if((e&128)==0)return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(e&127)<<7,(e&128)==0)return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(e&127)<<14,(e&128)==0)return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(e&127)<<21,(e&128)==0)return this.assertBounds(),t;e=this.buf[this.pos++],t|=(e&15)<<28;for(let n=5;(e&128)!==0&&n<10;n++)e=this.buf[this.pos++];if((e&128)!=0)throw new Error("invalid varint");return this.assertBounds(),t>>>0}var $e=zh();function zh(){let e=new DataView(new ArrayBuffer(8));if(typeof BigInt=="function"&&typeof e.getBigInt64=="function"&&typeof e.getBigUint64=="function"&&typeof e.setBigInt64=="function"&&typeof e.setBigUint64=="function"&&(!!globalThis.Deno||typeof process!="object"||typeof process.env!="object"||process.env.BUF_BIGINT_DISABLE!=="1")){let n=BigInt("-9223372036854775808"),r=BigInt("9223372036854775807"),o=BigInt("0"),s=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(i){let a=typeof i=="bigint"?i:BigInt(i);if(a>r||a<n)throw new Error(`invalid int64: ${i}`);return a},uParse(i){let a=typeof i=="bigint"?i:BigInt(i);if(a>s||a<o)throw new Error(`invalid uint64: ${i}`);return a},enc(i){return e.setBigInt64(0,this.parse(i),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},uEnc(i){return e.setBigInt64(0,this.uParse(i),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},dec(i,a){return e.setInt32(0,i,!0),e.setInt32(4,a,!0),e.getBigInt64(0,!0)},uDec(i,a){return e.setInt32(0,i,!0),e.setInt32(4,a,!0),e.getBigUint64(0,!0)}}}return{zero:"0",supported:!1,parse(n){return typeof n!="string"&&(n=n.toString()),Kl(n),n},uParse(n){return typeof n!="string"&&(n=n.toString()),Yl(n),n},enc(n){return typeof n!="string"&&(n=n.toString()),Kl(n),mi(n)},uEnc(n){return typeof n!="string"&&(n=n.toString()),Yl(n),mi(n)},dec(n,r){return Wl(n,r)},uDec(n,r){return gi(n,r)}}}function Kl(e){if(!/^-?[0-9]+$/.test(e))throw new Error("invalid int64: "+e)}function Yl(e){if(!/^[0-9]+$/.test(e))throw new Error("invalid uint64: "+e)}var bi=Symbol.for("@bufbuild/protobuf/text-encoding");function xi(){if(globalThis[bi]==null){let e=new globalThis.TextEncoder,t=new globalThis.TextDecoder,n;globalThis[bi]={encodeUtf8(r){return e.encode(r)},decodeUtf8(r,o){return o?(n===void 0&&(n=new globalThis.TextDecoder("utf-8",{fatal:!0})),n.decode(r)):t.decode(r)},checkUtf8(r){try{return encodeURIComponent(r),!0}catch{return!1}}}}return globalThis[bi]}var yt;(function(e){e[e.Varint=0]="Varint",e[e.Bit64=1]="Bit64",e[e.LengthDelimited=2]="LengthDelimited",e[e.StartGroup=3]="StartGroup",e[e.EndGroup=4]="EndGroup",e[e.Bit32=5]="Bit32"})(yt||(yt={}));var Bh=34028234663852886e22,Vh=-34028234663852886e22,jh=4294967295,Wh=2147483647,Xh=-2147483648,D=class{constructor(t=xi().encodeUtf8){this.encodeUtf8=t,this.stack=[],this.chunks=[],this.buf=[]}finish(){this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]);let t=0;for(let o=0;o<this.chunks.length;o++)t+=this.chunks[o].length;let n=new Uint8Array(t),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 t=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(t.byteLength),this.raw(t)}tag(t,n){return this.uint32((t<<3|n)>>>0)}raw(t){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(t),this}uint32(t){for(ql(t);t>127;)this.buf.push(t&127|128),t=t>>>7;return this.buf.push(t),this}int32(t){return Ei(t),yi(t,this.buf),this}bool(t){return this.buf.push(t?1:0),this}bytes(t){return this.uint32(t.byteLength),this.raw(t)}string(t){let n=this.encodeUtf8(t);return this.uint32(n.byteLength),this.raw(n)}float(t){Zh(t);let n=new Uint8Array(4);return new DataView(n.buffer).setFloat32(0,t,!0),this.raw(n)}double(t){let n=new Uint8Array(8);return new DataView(n.buffer).setFloat64(0,t,!0),this.raw(n)}fixed32(t){ql(t);let n=new Uint8Array(4);return new DataView(n.buffer).setUint32(0,t,!0),this.raw(n)}sfixed32(t){Ei(t);let n=new Uint8Array(4);return new DataView(n.buffer).setInt32(0,t,!0),this.raw(n)}sint32(t){return Ei(t),t=(t<<1^t>>31)>>>0,yi(t,this.buf),this}sfixed64(t){let n=new Uint8Array(8),r=new DataView(n.buffer),o=$e.enc(t);return r.setInt32(0,o.lo,!0),r.setInt32(4,o.hi,!0),this.raw(n)}fixed64(t){let n=new Uint8Array(8),r=new DataView(n.buffer),o=$e.uEnc(t);return r.setInt32(0,o.lo,!0),r.setInt32(4,o.hi,!0),this.raw(n)}int64(t){let n=$e.enc(t);return mo(n.lo,n.hi,this.buf),this}sint64(t){let n=$e.enc(t),r=n.hi>>31,o=n.lo<<1^r,s=(n.hi<<1|n.lo>>>31)^r;return mo(o,s,this.buf),this}uint64(t){let n=$e.uEnc(t);return mo(n.lo,n.hi,this.buf),this}},T=class{constructor(t,n=xi().decodeUtf8){this.decodeUtf8=n,this.varint64=jl,this.uint32=Zl,this.buf=t,this.len=t.length,this.pos=0,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength)}tag(){let t=this.pos,n=this.uint32(),r=this.pos-t;if(r>5||r==5&&this.buf[this.pos-1]>15)throw new Error("illegal tag: varint overflows uint32");let o=n>>>3,s=n&7;if(o<=0||s>5)throw new Error("illegal tag: field no "+o+" wire type "+s);return[o,s]}skip(t,n){let r=this.pos;switch(t){case yt.Varint:for(;this.buf[this.pos++]&128;);break;case yt.Bit64:this.pos+=4;case yt.Bit32:this.pos+=4;break;case yt.LengthDelimited:let o=this.uint32();this.pos+=o;break;case yt.StartGroup:for(;;){let[s,i]=this.tag();if(i===yt.EndGroup){if(n!==void 0&&s!==n)throw new Error("invalid end group tag");break}this.skip(i,s)}break;default:throw new Error("cant skip wire type "+t)}return this.assertBounds(),this.buf.subarray(r,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)}int64(){return $e.dec(...this.varint64())}uint64(){return $e.uDec(...this.varint64())}sint64(){let[t,n]=this.varint64(),r=-(t&1);return t=(t>>>1|(n&1)<<31)^r,n=n>>>1^r,$e.dec(t,n)}bool(){let[t,n]=this.varint64();return t!==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 $e.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return $e.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 t=this.uint32(),n=this.pos;return this.pos+=t,this.assertBounds(),this.buf.subarray(n,n+t)}string(t){return this.decodeUtf8(this.bytes(),t)}};function Ei(e){if(typeof e=="string")e=Number(e);else if(typeof e!="number")throw new Error("invalid int32: "+typeof e);if(!Number.isInteger(e)||e>Wh||e<Xh)throw new Error("invalid int32: "+e)}function ql(e){if(typeof e=="string")e=Number(e);else if(typeof e!="number")throw new Error("invalid uint32: "+typeof e);if(!Number.isInteger(e)||e>jh||e<0)throw new Error("invalid uint32: "+e)}function Zh(e){if(typeof e=="string"){let t=e;if(e=Number(e),Number.isNaN(e)&&t!=="NaN")throw new Error("invalid float32: "+t)}else if(typeof e!="number")throw new Error("invalid float32: "+typeof e);if(Number.isFinite(e)&&(e>Bh||e<Vh))throw new Error("invalid float32: "+e)}var Kh=(function(e){return e[e.NULL_VALUE=0]="NULL_VALUE",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED",e})({});function _i(){return{fields:{}}}var Kn={encode(e,t=new D){return Object.entries(e.fields).forEach(([n,r])=>{r!==void 0&&wi.encode({key:n,value:r},t.uint32(10).fork()).join()}),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=_i();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:{if(s!==10)break;let i=wi.decode(n,n.uint32());i.value!==void 0&&(o.fields[i.key]=i.value);continue}}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Kn.fromPartial(e??{})},fromPartial(e){let t=_i();return t.fields=Object.entries(e.fields??{}).reduce((n,[r,o])=>(o!==void 0&&(n[r]=o),n),{}),t},wrap(e){let t=_i();if(e!==void 0)for(let n of Object.keys(e))t.fields[n]=e[n];return t},unwrap(e){let t={};if(e.fields)for(let n of Object.keys(e.fields))t[n]=e.fields[n];return t}};function Jl(){return{key:"",value:void 0}}var wi={encode(e,t=new D){return e.key!==""&&t.uint32(10).string(e.key),e.value!==void 0&&N.encode(N.wrap(e.value),t.uint32(18).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=Jl();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.key=n.string();continue;case 2:if(s!==18)break;o.value=N.unwrap(N.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return wi.fromPartial(e??{})},fromPartial(e){let t=Jl();return t.key=e.key??"",t.value=e.value??void 0,t}};function Ti(){return{nullValue:void 0,numberValue:void 0,stringValue:void 0,boolValue:void 0,structValue:void 0,listValue:void 0}}var N={encode(e,t=new D){return e.nullValue!==void 0&&t.uint32(8).int32(e.nullValue),e.numberValue!==void 0&&t.uint32(17).double(e.numberValue),e.stringValue!==void 0&&t.uint32(26).string(e.stringValue),e.boolValue!==void 0&&t.uint32(32).bool(e.boolValue),e.structValue!==void 0&&Kn.encode(Kn.wrap(e.structValue),t.uint32(42).fork()).join(),e.listValue!==void 0&&Yn.encode(Yn.wrap(e.listValue),t.uint32(50).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=Ti();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==8)break;o.nullValue=n.int32();continue;case 2:if(s!==17)break;o.numberValue=n.double();continue;case 3:if(s!==26)break;o.stringValue=n.string();continue;case 4:if(s!==32)break;o.boolValue=n.bool();continue;case 5:if(s!==42)break;o.structValue=Kn.unwrap(Kn.decode(n,n.uint32()));continue;case 6:if(s!==50)break;o.listValue=Yn.unwrap(Yn.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return N.fromPartial(e??{})},fromPartial(e){let t=Ti();return t.nullValue=e.nullValue??void 0,t.numberValue=e.numberValue??void 0,t.stringValue=e.stringValue??void 0,t.boolValue=e.boolValue??void 0,t.structValue=e.structValue??void 0,t.listValue=e.listValue??void 0,t},wrap(e){let t=Ti();if(e===null)t.nullValue=Kh.NULL_VALUE;else if(typeof e=="boolean")t.boolValue=e;else if(typeof e=="number")t.numberValue=e;else if(typeof e=="string")t.stringValue=e;else if(globalThis.Array.isArray(e))t.listValue=e;else if(typeof e=="object")t.structValue=e;else if(typeof e<"u")throw new globalThis.Error("Unsupported any value type: "+typeof e);return t},unwrap(e){if(e.stringValue!==void 0)return e.stringValue;if(e?.numberValue!==void 0)return e.numberValue;if(e?.boolValue!==void 0)return e.boolValue;if(e?.structValue!==void 0)return e.structValue;if(e?.listValue!==void 0)return e.listValue;if(e?.nullValue!==void 0)return null}};function Si(){return{values:[]}}var Yn={encode(e,t=new D){for(let n of e.values)N.encode(N.wrap(n),t.uint32(10).fork()).join();return t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=Si();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.values.push(N.unwrap(N.decode(n,n.uint32())));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Yn.fromPartial(e??{})},fromPartial(e){let t=Si();return t.values=e.values?.map(n=>n)||[],t},wrap(e){let t=Si();return t.values=e??[],t},unwrap(e){return e?.hasOwnProperty("values")&&globalThis.Array.isArray(e.values)?e.values:e}},Yh=(function(e){return e[e.ADD=0]="ADD",e[e.REMOVE=1]="REMOVE",e[e.REPLACE=2]="REPLACE",e[e.MOVE=3]="MOVE",e[e.COPY=4]="COPY",e[e.TEST=5]="TEST",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED",e})({});function Ql(){return{op:0,path:"",from:void 0,value:void 0}}var vo={encode(e,t=new D){return e.op!==0&&t.uint32(8).int32(e.op),e.path!==""&&t.uint32(18).string(e.path),e.from!==void 0&&t.uint32(26).string(e.from),e.value!==void 0&&N.encode(N.wrap(e.value),t.uint32(34).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=Ql();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==8)break;o.op=n.int32();continue;case 2:if(s!==18)break;o.path=n.string();continue;case 3:if(s!==26)break;o.from=n.string();continue;case 4:if(s!==34)break;o.value=N.unwrap(N.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return vo.fromPartial(e??{})},fromPartial(e){let t=Ql();return t.op=e.op??0,t.path=e.path??"",t.from=e.from??void 0,t.value=e.value??void 0,t}};function ec(){return{id:"",type:"",function:void 0}}var yo={encode(e,t=new D){return e.id!==""&&t.uint32(10).string(e.id),e.type!==""&&t.uint32(18).string(e.type),e.function!==void 0&&bo.encode(e.function,t.uint32(26).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=ec();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.id=n.string();continue;case 2:if(s!==18)break;o.type=n.string();continue;case 3:if(s!==26)break;o.function=bo.decode(n,n.uint32());continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return yo.fromPartial(e??{})},fromPartial(e){let t=ec();return t.id=e.id??"",t.type=e.type??"",t.function=e.function!==void 0&&e.function!==null?bo.fromPartial(e.function):void 0,t}};function tc(){return{name:"",arguments:""}}var bo={encode(e,t=new D){return e.name!==""&&t.uint32(10).string(e.name),e.arguments!==""&&t.uint32(18).string(e.arguments),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=tc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.name=n.string();continue;case 2:if(s!==18)break;o.arguments=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return bo.fromPartial(e??{})},fromPartial(e){let t=tc();return t.name=e.name??"",t.arguments=e.arguments??"",t}};function nc(){return{value:"",mimeType:""}}var xo={encode(e,t=new D){return e.value!==""&&t.uint32(10).string(e.value),e.mimeType!==""&&t.uint32(18).string(e.mimeType),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=nc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.value=n.string();continue;case 2:if(s!==18)break;o.mimeType=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return xo.fromPartial(e??{})},fromPartial(e){let t=nc();return t.value=e.value??"",t.mimeType=e.mimeType??"",t}};function rc(){return{value:"",mimeType:void 0}}var Eo={encode(e,t=new D){return e.value!==""&&t.uint32(10).string(e.value),e.mimeType!==void 0&&t.uint32(18).string(e.mimeType),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=rc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.value=n.string();continue;case 2:if(s!==18)break;o.mimeType=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Eo.fromPartial(e??{})},fromPartial(e){let t=rc();return t.value=e.value??"",t.mimeType=e.mimeType??void 0,t}};function oc(){return{data:void 0,url:void 0}}var Ie={encode(e,t=new D){return e.data!==void 0&&xo.encode(e.data,t.uint32(10).fork()).join(),e.url!==void 0&&Eo.encode(e.url,t.uint32(18).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=oc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.data=xo.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.url=Eo.decode(n,n.uint32());continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Ie.fromPartial(e??{})},fromPartial(e){let t=oc();return t.data=e.data!==void 0&&e.data!==null?xo.fromPartial(e.data):void 0,t.url=e.url!==void 0&&e.url!==null?Eo.fromPartial(e.url):void 0,t}};function sc(){return{text:""}}var _o={encode(e,t=new D){return e.text!==""&&t.uint32(10).string(e.text),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=sc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.text=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return _o.fromPartial(e??{})},fromPartial(e){let t=sc();return t.text=e.text??"",t}};function ic(){return{source:void 0,metadata:void 0}}var To={encode(e,t=new D){return e.source!==void 0&&Ie.encode(e.source,t.uint32(10).fork()).join(),e.metadata!==void 0&&N.encode(N.wrap(e.metadata),t.uint32(18).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=ic();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.source=Ie.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.metadata=N.unwrap(N.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return To.fromPartial(e??{})},fromPartial(e){let t=ic();return t.source=e.source!==void 0&&e.source!==null?Ie.fromPartial(e.source):void 0,t.metadata=e.metadata??void 0,t}};function ac(){return{source:void 0,metadata:void 0}}var So={encode(e,t=new D){return e.source!==void 0&&Ie.encode(e.source,t.uint32(10).fork()).join(),e.metadata!==void 0&&N.encode(N.wrap(e.metadata),t.uint32(18).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=ac();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.source=Ie.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.metadata=N.unwrap(N.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return So.fromPartial(e??{})},fromPartial(e){let t=ac();return t.source=e.source!==void 0&&e.source!==null?Ie.fromPartial(e.source):void 0,t.metadata=e.metadata??void 0,t}};function lc(){return{source:void 0,metadata:void 0}}var wo={encode(e,t=new D){return e.source!==void 0&&Ie.encode(e.source,t.uint32(10).fork()).join(),e.metadata!==void 0&&N.encode(N.wrap(e.metadata),t.uint32(18).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=lc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.source=Ie.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.metadata=N.unwrap(N.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return wo.fromPartial(e??{})},fromPartial(e){let t=lc();return t.source=e.source!==void 0&&e.source!==null?Ie.fromPartial(e.source):void 0,t.metadata=e.metadata??void 0,t}};function cc(){return{source:void 0,metadata:void 0}}var ko={encode(e,t=new D){return e.source!==void 0&&Ie.encode(e.source,t.uint32(10).fork()).join(),e.metadata!==void 0&&N.encode(N.wrap(e.metadata),t.uint32(18).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=cc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.source=Ie.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.metadata=N.unwrap(N.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return ko.fromPartial(e??{})},fromPartial(e){let t=cc();return t.source=e.source!==void 0&&e.source!==null?Ie.fromPartial(e.source):void 0,t.metadata=e.metadata??void 0,t}};function uc(){return{text:void 0,image:void 0,audio:void 0,video:void 0,document:void 0}}var Ao={encode(e,t=new D){return e.text!==void 0&&_o.encode(e.text,t.uint32(10).fork()).join(),e.image!==void 0&&To.encode(e.image,t.uint32(18).fork()).join(),e.audio!==void 0&&So.encode(e.audio,t.uint32(26).fork()).join(),e.video!==void 0&&wo.encode(e.video,t.uint32(34).fork()).join(),e.document!==void 0&&ko.encode(e.document,t.uint32(42).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=uc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.text=_o.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.image=To.decode(n,n.uint32());continue;case 3:if(s!==26)break;o.audio=So.decode(n,n.uint32());continue;case 4:if(s!==34)break;o.video=wo.decode(n,n.uint32());continue;case 5:if(s!==42)break;o.document=ko.decode(n,n.uint32());continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Ao.fromPartial(e??{})},fromPartial(e){let t=uc();return t.text=e.text!==void 0&&e.text!==null?_o.fromPartial(e.text):void 0,t.image=e.image!==void 0&&e.image!==null?To.fromPartial(e.image):void 0,t.audio=e.audio!==void 0&&e.audio!==null?So.fromPartial(e.audio):void 0,t.video=e.video!==void 0&&e.video!==null?wo.fromPartial(e.video):void 0,t.document=e.document!==void 0&&e.document!==null?ko.fromPartial(e.document):void 0,t}};function dc(){return{id:"",role:"",content:void 0,name:void 0,toolCalls:[],toolCallId:void 0,error:void 0,contentParts:[]}}var Io={encode(e,t=new D){e.id!==""&&t.uint32(10).string(e.id),e.role!==""&&t.uint32(18).string(e.role),e.content!==void 0&&t.uint32(26).string(e.content),e.name!==void 0&&t.uint32(34).string(e.name);for(let n of e.toolCalls)yo.encode(n,t.uint32(42).fork()).join();e.toolCallId!==void 0&&t.uint32(50).string(e.toolCallId),e.error!==void 0&&t.uint32(58).string(e.error);for(let n of e.contentParts)Ao.encode(n,t.uint32(66).fork()).join();return t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=dc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.id=n.string();continue;case 2:if(s!==18)break;o.role=n.string();continue;case 3:if(s!==26)break;o.content=n.string();continue;case 4:if(s!==34)break;o.name=n.string();continue;case 5:if(s!==42)break;o.toolCalls.push(yo.decode(n,n.uint32()));continue;case 6:if(s!==50)break;o.toolCallId=n.string();continue;case 7:if(s!==58)break;o.error=n.string();continue;case 8:if(s!==66)break;o.contentParts.push(Ao.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Io.fromPartial(e??{})},fromPartial(e){let t=dc();return t.id=e.id??"",t.role=e.role??"",t.content=e.content??void 0,t.name=e.name??void 0,t.toolCalls=e.toolCalls?.map(n=>yo.fromPartial(n))||[],t.toolCallId=e.toolCallId??void 0,t.error=e.error??void 0,t.contentParts=e.contentParts?.map(n=>Ao.fromPartial(n))||[],t}};function pc(){return{id:"",reason:"",message:void 0,toolCallId:void 0,responseSchema:void 0,expiresAt:void 0,metadata:void 0}}var Co={encode(e,t=new D){return e.id!==""&&t.uint32(10).string(e.id),e.reason!==""&&t.uint32(18).string(e.reason),e.message!==void 0&&t.uint32(26).string(e.message),e.toolCallId!==void 0&&t.uint32(34).string(e.toolCallId),e.responseSchema!==void 0&&N.encode(N.wrap(e.responseSchema),t.uint32(42).fork()).join(),e.expiresAt!==void 0&&t.uint32(50).string(e.expiresAt),e.metadata!==void 0&&N.encode(N.wrap(e.metadata),t.uint32(58).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=pc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.id=n.string();continue;case 2:if(s!==18)break;o.reason=n.string();continue;case 3:if(s!==26)break;o.message=n.string();continue;case 4:if(s!==34)break;o.toolCallId=n.string();continue;case 5:if(s!==42)break;o.responseSchema=N.unwrap(N.decode(n,n.uint32()));continue;case 6:if(s!==50)break;o.expiresAt=n.string();continue;case 7:if(s!==58)break;o.metadata=N.unwrap(N.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Co.fromPartial(e??{})},fromPartial(e){let t=pc();return t.id=e.id??"",t.reason=e.reason??"",t.message=e.message??void 0,t.toolCallId=e.toolCallId??void 0,t.responseSchema=e.responseSchema??void 0,t.expiresAt=e.expiresAt??void 0,t.metadata=e.metadata??void 0,t}},qh=(function(e){return e[e.TEXT_MESSAGE_START=0]="TEXT_MESSAGE_START",e[e.TEXT_MESSAGE_CONTENT=1]="TEXT_MESSAGE_CONTENT",e[e.TEXT_MESSAGE_END=2]="TEXT_MESSAGE_END",e[e.TOOL_CALL_START=3]="TOOL_CALL_START",e[e.TOOL_CALL_ARGS=4]="TOOL_CALL_ARGS",e[e.TOOL_CALL_END=5]="TOOL_CALL_END",e[e.STATE_SNAPSHOT=6]="STATE_SNAPSHOT",e[e.STATE_DELTA=7]="STATE_DELTA",e[e.MESSAGES_SNAPSHOT=8]="MESSAGES_SNAPSHOT",e[e.RAW=9]="RAW",e[e.CUSTOM=10]="CUSTOM",e[e.RUN_STARTED=11]="RUN_STARTED",e[e.RUN_FINISHED=12]="RUN_FINISHED",e[e.RUN_ERROR=13]="RUN_ERROR",e[e.STEP_STARTED=14]="STEP_STARTED",e[e.STEP_FINISHED=15]="STEP_FINISHED",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED",e})({});function fc(){return{type:0,timestamp:void 0,rawEvent:void 0}}var R={encode(e,t=new D){return e.type!==0&&t.uint32(8).int32(e.type),e.timestamp!==void 0&&t.uint32(16).int64(e.timestamp),e.rawEvent!==void 0&&N.encode(N.wrap(e.rawEvent),t.uint32(26).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=fc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==8)break;o.type=n.int32();continue;case 2:if(s!==16)break;o.timestamp=Jh(n.int64());continue;case 3:if(s!==26)break;o.rawEvent=N.unwrap(N.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return R.fromPartial(e??{})},fromPartial(e){let t=fc();return t.type=e.type??0,t.timestamp=e.timestamp??void 0,t.rawEvent=e.rawEvent??void 0,t}};function hc(){return{baseEvent:void 0,messageId:"",role:void 0,name:void 0}}var No={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.messageId!==""&&t.uint32(18).string(e.messageId),e.role!==void 0&&t.uint32(26).string(e.role),e.name!==void 0&&t.uint32(34).string(e.name),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=hc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.messageId=n.string();continue;case 3:if(s!==26)break;o.role=n.string();continue;case 4:if(s!==34)break;o.name=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return No.fromPartial(e??{})},fromPartial(e){let t=hc();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.messageId=e.messageId??"",t.role=e.role??void 0,t.name=e.name??void 0,t}};function mc(){return{baseEvent:void 0,messageId:"",delta:""}}var Ro={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.messageId!==""&&t.uint32(18).string(e.messageId),e.delta!==""&&t.uint32(26).string(e.delta),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=mc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.messageId=n.string();continue;case 3:if(s!==26)break;o.delta=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Ro.fromPartial(e??{})},fromPartial(e){let t=mc();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.messageId=e.messageId??"",t.delta=e.delta??"",t}};function gc(){return{baseEvent:void 0,messageId:""}}var Oo={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.messageId!==""&&t.uint32(18).string(e.messageId),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=gc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.messageId=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Oo.fromPartial(e??{})},fromPartial(e){let t=gc();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.messageId=e.messageId??"",t}};function vc(){return{baseEvent:void 0,toolCallId:"",toolCallName:"",parentMessageId:void 0}}var Mo={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.toolCallId!==""&&t.uint32(18).string(e.toolCallId),e.toolCallName!==""&&t.uint32(26).string(e.toolCallName),e.parentMessageId!==void 0&&t.uint32(34).string(e.parentMessageId),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=vc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.toolCallId=n.string();continue;case 3:if(s!==26)break;o.toolCallName=n.string();continue;case 4:if(s!==34)break;o.parentMessageId=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Mo.fromPartial(e??{})},fromPartial(e){let t=vc();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.toolCallId=e.toolCallId??"",t.toolCallName=e.toolCallName??"",t.parentMessageId=e.parentMessageId??void 0,t}};function yc(){return{baseEvent:void 0,toolCallId:"",delta:""}}var Lo={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.toolCallId!==""&&t.uint32(18).string(e.toolCallId),e.delta!==""&&t.uint32(26).string(e.delta),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=yc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.toolCallId=n.string();continue;case 3:if(s!==26)break;o.delta=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Lo.fromPartial(e??{})},fromPartial(e){let t=yc();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.toolCallId=e.toolCallId??"",t.delta=e.delta??"",t}};function bc(){return{baseEvent:void 0,toolCallId:""}}var Po={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.toolCallId!==""&&t.uint32(18).string(e.toolCallId),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=bc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.toolCallId=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Po.fromPartial(e??{})},fromPartial(e){let t=bc();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.toolCallId=e.toolCallId??"",t}};function xc(){return{baseEvent:void 0,snapshot:void 0}}var Do={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.snapshot!==void 0&&N.encode(N.wrap(e.snapshot),t.uint32(18).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=xc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.snapshot=N.unwrap(N.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Do.fromPartial(e??{})},fromPartial(e){let t=xc();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.snapshot=e.snapshot??void 0,t}};function Ec(){return{baseEvent:void 0,delta:[]}}var Uo={encode(e,t=new D){e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join();for(let n of e.delta)vo.encode(n,t.uint32(18).fork()).join();return t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=Ec();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.delta.push(vo.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Uo.fromPartial(e??{})},fromPartial(e){let t=Ec();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.delta=e.delta?.map(n=>vo.fromPartial(n))||[],t}};function _c(){return{baseEvent:void 0,messages:[]}}var Go={encode(e,t=new D){e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join();for(let n of e.messages)Io.encode(n,t.uint32(18).fork()).join();return t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=_c();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.messages.push(Io.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Go.fromPartial(e??{})},fromPartial(e){let t=_c();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.messages=e.messages?.map(n=>Io.fromPartial(n))||[],t}};function Tc(){return{baseEvent:void 0,event:void 0,source:void 0}}var Fo={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.event!==void 0&&N.encode(N.wrap(e.event),t.uint32(18).fork()).join(),e.source!==void 0&&t.uint32(26).string(e.source),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=Tc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.event=N.unwrap(N.decode(n,n.uint32()));continue;case 3:if(s!==26)break;o.source=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Fo.fromPartial(e??{})},fromPartial(e){let t=Tc();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.event=e.event??void 0,t.source=e.source??void 0,t}};function Sc(){return{baseEvent:void 0,name:"",value:void 0}}var Ho={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.name!==""&&t.uint32(18).string(e.name),e.value!==void 0&&N.encode(N.wrap(e.value),t.uint32(26).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=Sc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.name=n.string();continue;case 3:if(s!==26)break;o.value=N.unwrap(N.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Ho.fromPartial(e??{})},fromPartial(e){let t=Sc();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.name=e.name??"",t.value=e.value??void 0,t}};function wc(){return{baseEvent:void 0,threadId:"",runId:""}}var $o={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.threadId!==""&&t.uint32(18).string(e.threadId),e.runId!==""&&t.uint32(26).string(e.runId),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=wc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.threadId=n.string();continue;case 3:if(s!==26)break;o.runId=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return $o.fromPartial(e??{})},fromPartial(e){let t=wc();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.threadId=e.threadId??"",t.runId=e.runId??"",t}};function kc(){return{baseEvent:void 0,threadId:"",runId:"",result:void 0,outcome:"",interrupts:[]}}var zo={encode(e,t=new D){e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.threadId!==""&&t.uint32(18).string(e.threadId),e.runId!==""&&t.uint32(26).string(e.runId),e.result!==void 0&&N.encode(N.wrap(e.result),t.uint32(34).fork()).join(),e.outcome!==""&&t.uint32(42).string(e.outcome);for(let n of e.interrupts)Co.encode(n,t.uint32(50).fork()).join();return t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=kc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.threadId=n.string();continue;case 3:if(s!==26)break;o.runId=n.string();continue;case 4:if(s!==34)break;o.result=N.unwrap(N.decode(n,n.uint32()));continue;case 5:if(s!==42)break;o.outcome=n.string();continue;case 6:if(s!==50)break;o.interrupts.push(Co.decode(n,n.uint32()));continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return zo.fromPartial(e??{})},fromPartial(e){let t=kc();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.threadId=e.threadId??"",t.runId=e.runId??"",t.result=e.result??void 0,t.outcome=e.outcome??"",t.interrupts=e.interrupts?.map(n=>Co.fromPartial(n))||[],t}};function Ac(){return{baseEvent:void 0,code:void 0,message:""}}var Bo={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.code!==void 0&&t.uint32(18).string(e.code),e.message!==""&&t.uint32(26).string(e.message),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=Ac();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.code=n.string();continue;case 3:if(s!==26)break;o.message=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Bo.fromPartial(e??{})},fromPartial(e){let t=Ac();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.code=e.code??void 0,t.message=e.message??"",t}};function Ic(){return{baseEvent:void 0,stepName:""}}var Vo={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.stepName!==""&&t.uint32(18).string(e.stepName),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=Ic();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.stepName=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Vo.fromPartial(e??{})},fromPartial(e){let t=Ic();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.stepName=e.stepName??"",t}};function Cc(){return{baseEvent:void 0,stepName:""}}var jo={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.stepName!==""&&t.uint32(18).string(e.stepName),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=Cc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.stepName=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return jo.fromPartial(e??{})},fromPartial(e){let t=Cc();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.stepName=e.stepName??"",t}};function Nc(){return{baseEvent:void 0,messageId:void 0,role:void 0,delta:void 0,name:void 0}}var Wo={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.messageId!==void 0&&t.uint32(18).string(e.messageId),e.role!==void 0&&t.uint32(26).string(e.role),e.delta!==void 0&&t.uint32(34).string(e.delta),e.name!==void 0&&t.uint32(42).string(e.name),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=Nc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.messageId=n.string();continue;case 3:if(s!==26)break;o.role=n.string();continue;case 4:if(s!==34)break;o.delta=n.string();continue;case 5:if(s!==42)break;o.name=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Wo.fromPartial(e??{})},fromPartial(e){let t=Nc();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.messageId=e.messageId??void 0,t.role=e.role??void 0,t.delta=e.delta??void 0,t.name=e.name??void 0,t}};function Rc(){return{baseEvent:void 0,toolCallId:void 0,toolCallName:void 0,parentMessageId:void 0,delta:void 0}}var Xo={encode(e,t=new D){return e.baseEvent!==void 0&&R.encode(e.baseEvent,t.uint32(10).fork()).join(),e.toolCallId!==void 0&&t.uint32(18).string(e.toolCallId),e.toolCallName!==void 0&&t.uint32(26).string(e.toolCallName),e.parentMessageId!==void 0&&t.uint32(34).string(e.parentMessageId),e.delta!==void 0&&t.uint32(42).string(e.delta),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=Rc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.baseEvent=R.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.toolCallId=n.string();continue;case 3:if(s!==26)break;o.toolCallName=n.string();continue;case 4:if(s!==34)break;o.parentMessageId=n.string();continue;case 5:if(s!==42)break;o.delta=n.string();continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Xo.fromPartial(e??{})},fromPartial(e){let t=Rc();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?R.fromPartial(e.baseEvent):void 0,t.toolCallId=e.toolCallId??void 0,t.toolCallName=e.toolCallName??void 0,t.parentMessageId=e.parentMessageId??void 0,t.delta=e.delta??void 0,t}};function Oc(){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 Mc={encode(e,t=new D){return e.textMessageStart!==void 0&&No.encode(e.textMessageStart,t.uint32(10).fork()).join(),e.textMessageContent!==void 0&&Ro.encode(e.textMessageContent,t.uint32(18).fork()).join(),e.textMessageEnd!==void 0&&Oo.encode(e.textMessageEnd,t.uint32(26).fork()).join(),e.toolCallStart!==void 0&&Mo.encode(e.toolCallStart,t.uint32(34).fork()).join(),e.toolCallArgs!==void 0&&Lo.encode(e.toolCallArgs,t.uint32(42).fork()).join(),e.toolCallEnd!==void 0&&Po.encode(e.toolCallEnd,t.uint32(50).fork()).join(),e.stateSnapshot!==void 0&&Do.encode(e.stateSnapshot,t.uint32(58).fork()).join(),e.stateDelta!==void 0&&Uo.encode(e.stateDelta,t.uint32(66).fork()).join(),e.messagesSnapshot!==void 0&&Go.encode(e.messagesSnapshot,t.uint32(74).fork()).join(),e.raw!==void 0&&Fo.encode(e.raw,t.uint32(82).fork()).join(),e.custom!==void 0&&Ho.encode(e.custom,t.uint32(90).fork()).join(),e.runStarted!==void 0&&$o.encode(e.runStarted,t.uint32(98).fork()).join(),e.runFinished!==void 0&&zo.encode(e.runFinished,t.uint32(106).fork()).join(),e.runError!==void 0&&Bo.encode(e.runError,t.uint32(114).fork()).join(),e.stepStarted!==void 0&&Vo.encode(e.stepStarted,t.uint32(122).fork()).join(),e.stepFinished!==void 0&&jo.encode(e.stepFinished,t.uint32(130).fork()).join(),e.textMessageChunk!==void 0&&Wo.encode(e.textMessageChunk,t.uint32(138).fork()).join(),e.toolCallChunk!==void 0&&Xo.encode(e.toolCallChunk,t.uint32(146).fork()).join(),t},decode(e,t){let n=e instanceof T?e:new T(e),r=t===void 0?n.len:n.pos+t,o=Oc();for(;n.pos<r;){let s=n.uint32();switch(s>>>3){case 1:if(s!==10)break;o.textMessageStart=No.decode(n,n.uint32());continue;case 2:if(s!==18)break;o.textMessageContent=Ro.decode(n,n.uint32());continue;case 3:if(s!==26)break;o.textMessageEnd=Oo.decode(n,n.uint32());continue;case 4:if(s!==34)break;o.toolCallStart=Mo.decode(n,n.uint32());continue;case 5:if(s!==42)break;o.toolCallArgs=Lo.decode(n,n.uint32());continue;case 6:if(s!==50)break;o.toolCallEnd=Po.decode(n,n.uint32());continue;case 7:if(s!==58)break;o.stateSnapshot=Do.decode(n,n.uint32());continue;case 8:if(s!==66)break;o.stateDelta=Uo.decode(n,n.uint32());continue;case 9:if(s!==74)break;o.messagesSnapshot=Go.decode(n,n.uint32());continue;case 10:if(s!==82)break;o.raw=Fo.decode(n,n.uint32());continue;case 11:if(s!==90)break;o.custom=Ho.decode(n,n.uint32());continue;case 12:if(s!==98)break;o.runStarted=$o.decode(n,n.uint32());continue;case 13:if(s!==106)break;o.runFinished=zo.decode(n,n.uint32());continue;case 14:if(s!==114)break;o.runError=Bo.decode(n,n.uint32());continue;case 15:if(s!==122)break;o.stepStarted=Vo.decode(n,n.uint32());continue;case 16:if(s!==130)break;o.stepFinished=jo.decode(n,n.uint32());continue;case 17:if(s!==138)break;o.textMessageChunk=Wo.decode(n,n.uint32());continue;case 18:if(s!==146)break;o.toolCallChunk=Xo.decode(n,n.uint32());continue}if((s&7)===4||s===0)break;n.skip(s&7)}return o},create(e){return Mc.fromPartial(e??{})},fromPartial(e){let t=Oc();return t.textMessageStart=e.textMessageStart!==void 0&&e.textMessageStart!==null?No.fromPartial(e.textMessageStart):void 0,t.textMessageContent=e.textMessageContent!==void 0&&e.textMessageContent!==null?Ro.fromPartial(e.textMessageContent):void 0,t.textMessageEnd=e.textMessageEnd!==void 0&&e.textMessageEnd!==null?Oo.fromPartial(e.textMessageEnd):void 0,t.toolCallStart=e.toolCallStart!==void 0&&e.toolCallStart!==null?Mo.fromPartial(e.toolCallStart):void 0,t.toolCallArgs=e.toolCallArgs!==void 0&&e.toolCallArgs!==null?Lo.fromPartial(e.toolCallArgs):void 0,t.toolCallEnd=e.toolCallEnd!==void 0&&e.toolCallEnd!==null?Po.fromPartial(e.toolCallEnd):void 0,t.stateSnapshot=e.stateSnapshot!==void 0&&e.stateSnapshot!==null?Do.fromPartial(e.stateSnapshot):void 0,t.stateDelta=e.stateDelta!==void 0&&e.stateDelta!==null?Uo.fromPartial(e.stateDelta):void 0,t.messagesSnapshot=e.messagesSnapshot!==void 0&&e.messagesSnapshot!==null?Go.fromPartial(e.messagesSnapshot):void 0,t.raw=e.raw!==void 0&&e.raw!==null?Fo.fromPartial(e.raw):void 0,t.custom=e.custom!==void 0&&e.custom!==null?Ho.fromPartial(e.custom):void 0,t.runStarted=e.runStarted!==void 0&&e.runStarted!==null?$o.fromPartial(e.runStarted):void 0,t.runFinished=e.runFinished!==void 0&&e.runFinished!==null?zo.fromPartial(e.runFinished):void 0,t.runError=e.runError!==void 0&&e.runError!==null?Bo.fromPartial(e.runError):void 0,t.stepStarted=e.stepStarted!==void 0&&e.stepStarted!==null?Vo.fromPartial(e.stepStarted):void 0,t.stepFinished=e.stepFinished!==void 0&&e.stepFinished!==null?jo.fromPartial(e.stepFinished):void 0,t.textMessageChunk=e.textMessageChunk!==void 0&&e.textMessageChunk!==null?Wo.fromPartial(e.textMessageChunk):void 0,t.toolCallChunk=e.toolCallChunk!==void 0&&e.toolCallChunk!==null?Xo.fromPartial(e.toolCallChunk):void 0,t}};function Jh(e){let t=globalThis.Number(e.toString());if(t>globalThis.Number.MAX_SAFE_INTEGER)throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");if(t<globalThis.Number.MIN_SAFE_INTEGER)throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");return t}var go=e=>{if(!(!e||typeof e!="object")){if(e.data)return{type:"data",value:e.data.value,mimeType:e.data.mimeType};if(e.url)return{type:"url",value:e.url.value,mimeType:e.url.mimeType}}},Qh=e=>{if(!(!e||typeof e!="object")){if(e.text)return{type:"text",text:e.text.text};if(e.image)return{type:"image",source:go(e.image.source),metadata:e.image.metadata};if(e.audio)return{type:"audio",source:go(e.audio.source),metadata:e.audio.metadata};if(e.video)return{type:"video",source:go(e.video.source),metadata:e.video.metadata};if(e.document)return{type:"document",source:go(e.document.source),metadata:e.document.metadata}}};function Lc(e){let t=Mc.decode(e),n=Object.values(t).find(r=>r!==void 0);if(!n)throw new Error("Invalid event");if(n.type=qh[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 s=o.contentParts.map(i=>Qh(i)).filter(i=>i!==void 0);s.length>0&&(o.content=s)}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,s=Array.isArray(r.interrupts)?r.interrupts:[];delete r.interrupts,o==="interrupt"?r.outcome={type:"interrupt",interrupts:s}:o==="success"?r.outcome={type:"success"}:delete r.outcome}if(n.type===v.STATE_DELTA)for(let r of n.delta)r.op=Yh[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]}),Or.parse(n)}var ki="application/vnd.ag-ui.event+proto";var tm=/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i,Ai=e=>{if(typeof e!="string")throw new TypeError("Invalid argument expected string");let t=e.match(tm);if(!t)throw new Error(`Invalid argument not valid semver ('${e}' received)`);return t.shift(),t},Pc=e=>e==="*"||e==="x"||e==="X",Dc=e=>{let t=parseInt(e,10);return isNaN(t)?e:t},nm=(e,t)=>typeof e!=typeof t?[String(e),String(t)]:[e,t],rm=(e,t)=>{if(Pc(e)||Pc(t))return 0;let[n,r]=nm(Dc(e),Dc(t));return n>r?1:n<r?-1:0},Ii=(e,t)=>{for(let n=0;n<Math.max(e.length,t.length);n++){let r=rm(e[n]||"0",t[n]||"0");if(r!==0)return r}return 0};var qn=(e,t)=>{let n=Ai(e),r=Ai(t),o=n.pop(),s=r.pop(),i=Ii(n,r);return i!==0?i:o&&s?Ii(o.split("."),s.split(".")):o||s?o?-1:1:0};var B=e=>{if(typeof structuredClone=="function")return structuredClone(e);try{return JSON.parse(JSON.stringify(e))}catch{return Array.isArray(e)?[...e]:{...e}}};function ze(){return ft()}function Ri(e){if(Object.freeze(e),typeof e=="object"&&e)for(let t of Object.values(e))typeof t=="object"&&t&&!Object.isFrozen(t)&&Ri(t);return e}async function X(e,t,n,r){let o=typeof process<"u"&&process.env!==void 0,s=o&&!!process.env.VITEST_WORKER_ID,i=o&&!!process.env.VITEST_WORKER_ID,a=B(t),u=B(n),c=a,p=u,m;for(let x of e)try{i&&(Ri(c),Ri(p));let f=await r(x,c,p);if(f===void 0)continue;if(f.messages!==void 0&&f.messages!==c&&(c=B(f.messages)),f.state!==void 0&&f.state!==p&&(p=B(f.state)),m=f.stopPropagation,m===!0)break}catch(f){if(i&&f instanceof TypeError){if(s)throw f;console.error("AG-UI: Subscriber attempted to mutate frozen inputs in-place. Return mutations via AgentStateMutation instead of mutating directly.",f)}else s||console.error("Subscriber error:",f);continue}return{...c===a?{}:{messages:i&&Object.isFrozen(c)?B(c):c},...p===u?{}:{state:i&&Object.isFrozen(p)?B(p):p},...m===void 0?{}:{stopPropagation:m}}}function Zo(e){if(!e)return{enabled:!1,events:!1,lifecycle:!1,verbose:!1};if(e===!0)return{enabled:!0,events:!0,lifecycle:!0,verbose:!0};let t=e.events??!0,n=e.lifecycle??!0,r=e.verbose??!1;return{enabled:t||n,events:t,lifecycle:n,verbose:r}}function Jn(e){if(e instanceof Oi)return e;if(e===!0)return new Oi(Zo(!0))}var Oi=class{constructor(e){this.config=e}event(e,t,n,r){this.config.events&&(this.config.verbose?console.debug(`[${e}] ${t}`,typeof n=="string"?n:JSON.stringify(n)):console.debug(`[${e}] ${t}`,r??n))}lifecycle(e,t,n){this.config.lifecycle&&(n?console.debug(`[${e}] ${t}`,n):console.debug(`[${e}] ${t}`))}get eventsEnabled(){return this.config.events}get lifecycleEnabled(){return this.config.lifecycle}get enabled(){return this.config.enabled}};function Ci(e){return e.enabled?new Oi(e):void 0}function om(e,t,n){if(t){let o=e.find(i=>i.id===t);if(o?.role==="assistant")return o;o&&console.warn(`TOOL_CALL_START: parentMessageId '${t}' matches a '${o.role}' message, not assistant \u2014 falling back to toolCallId`);let s={id:o?n:t,role:"assistant",toolCalls:[]};return e.push(s),s}let r={id:n,role:"assistant",toolCalls:[]};return e.push(r),r}var zc=(e,t,n,r,o)=>{let s=Jn(o),i=B(n.messages),a=B(e.state),u={},c=m=>{m.messages!==void 0&&(i=m.messages,u.messages=m.messages),m.state!==void 0&&(a=m.state,u.state=m.state)},p=()=>{let m=B(u);return u={},m.messages!==void 0||m.state!==void 0?te(m):Kr};return t.pipe(uo(async m=>{let x=await X(r,i,a,(f,h,g)=>f.onEvent?.({event:m,agent:n,input:e,messages:h,state:g}));if(c(x),x.stopPropagation===!0?s?.event("APPLY","Event dropped:",m,{type:m.type,reason:"stopPropagation by subscriber"}):s?.event("APPLY","Event applied:",m,{type:m.type,subscribers:r.length}),x.stopPropagation===!0)return p();switch(m.type){case v.TEXT_MESSAGE_START:{let f=await X(r,i,a,(h,g,_)=>h.onTextMessageStartEvent?.({event:m,messages:g,state:_,agent:n,input:e}));if(c(f),f.stopPropagation!==!0){let{messageId:h,role:g="assistant",name:_}=m;if(!i.find(S=>S.id===h)){let S={id:h,role:g,content:"",..._!==void 0&&{name:_}};i.push(S),c({messages:i})}}return p()}case v.TEXT_MESSAGE_CONTENT:{let{messageId:f,delta:h}=m,g=i.find(S=>S.id===f);if(!g)return console.warn(`TEXT_MESSAGE_CONTENT: No message found with ID '${f}'`),p();let _=await X(r,i,a,(S,b,F)=>S.onTextMessageContentEvent?.({event:m,messages:b,state:F,agent:n,input:e,textMessageBuffer:typeof g.content=="string"?g.content:""}));return c(_),_.stopPropagation!==!0&&(g.content=`${typeof g.content=="string"?g.content:""}${h}`,c({messages:i})),p()}case v.TEXT_MESSAGE_END:{let{messageId:f}=m,h=i.find(g=>g.id===f);return h?(c(await X(r,i,a,(g,_,S)=>g.onTextMessageEndEvent?.({event:m,messages:_,state:S,agent:n,input:e,textMessageBuffer:typeof h.content=="string"?h.content:""}))),await Promise.all(r.map(g=>{g.onNewMessage?.({message:h,messages:i,state:a,agent:n,input:e})})),p()):(console.warn(`TEXT_MESSAGE_END: No message found with ID '${f}'`),p())}case v.TOOL_CALL_START:{let f=await X(r,i,a,(h,g,_)=>h.onToolCallStartEvent?.({event:m,messages:g,state:_,agent:n,input:e}));if(c(f),f.stopPropagation!==!0){let{toolCallId:h,toolCallName:g,parentMessageId:_}=m,S=om(i,_,h);S.toolCalls??=[],S.toolCalls.push({id:h,type:"function",function:{name:g,arguments:""}}),c({messages:i})}return p()}case v.TOOL_CALL_ARGS:{let{toolCallId:f,delta:h}=m,g=i.find(b=>b.toolCalls?.some(F=>F.id===f));if(!g)return console.warn(`TOOL_CALL_ARGS: No message found containing tool call with ID '${f}'`),p();let _=g.toolCalls?.find(b=>b.id===f);if(!_)return console.warn(`TOOL_CALL_ARGS: No tool call found with ID '${f}'`),p();let S=await X(r,i,a,(b,F,Z)=>{let ae=_.function.arguments,ee=_.function.name,ct={};try{ct=fo(ae)}catch{}return b.onToolCallArgsEvent?.({event:m,messages:F,state:Z,agent:n,input:e,toolCallBuffer:ae,toolCallName:ee,partialToolCallArgs:ct})});return c(S),S.stopPropagation!==!0&&(_.function.arguments+=h,c({messages:i})),p()}case v.TOOL_CALL_END:{let{toolCallId:f}=m,h=i.find(_=>_.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(_=>_.id===f);return g?(c(await X(r,i,a,(_,S,b)=>{let F=g.function.arguments,Z=g.function.name,ae={};try{ae=JSON.parse(F)}catch{}return _.onToolCallEndEvent?.({event:m,messages:S,state:b,agent:n,input:e,toolCallName:Z,toolCallArgs:ae})})),await Promise.all(r.map(_=>{_.onNewToolCall?.({toolCall:g,messages:i,state:a,agent:n,input:e})})),p()):(console.warn(`TOOL_CALL_END: No tool call found with ID '${f}'`),p())}case v.TOOL_CALL_RESULT:{let f=await X(r,i,a,(h,g,_)=>h.onToolCallResultEvent?.({event:m,messages:g,state:_,agent:n,input:e}));if(c(f),f.stopPropagation!==!0){let{messageId:h,toolCallId:g,content:_,role:S}=m,b={id:h,toolCallId:g,role:S||"tool",content:_};i.push(b),await Promise.all(r.map(F=>{F.onNewMessage?.({message:b,messages:i,state:a,agent:n,input:e})})),c({messages:i})}return p()}case v.STATE_SNAPSHOT:{let f=await X(r,i,a,(h,g,_)=>h.onStateSnapshotEvent?.({event:m,messages:g,state:_,agent:n,input:e}));if(c(f),f.stopPropagation!==!0){let{snapshot:h}=m;a=h,c({state:a})}return p()}case v.STATE_DELTA:{let f=await X(r,i,a,(h,g,_)=>h.onStateDeltaEvent?.({event:m,messages:g,state:_,agent:n,input:e}));if(c(f),f.stopPropagation!==!0){let{delta:h}=m;try{a=Hr.applyPatch(a,h,!0,!1).newDocument,c({state:a})}catch(g){let _=g instanceof Error?g.message:String(g);console.warn(`Failed to apply state patch:
699
+ Current state: ${JSON.stringify(a,null,2)}
700
+ Patch operations: ${JSON.stringify(h,null,2)}
701
+ Error: ${_}`)}}return p()}case v.MESSAGES_SNAPSHOT:{let f=await X(r,i,a,(h,g,_)=>h.onMessagesSnapshotEvent?.({event:m,messages:g,state:_,agent:n,input:e}));if(c(f),f.stopPropagation!==!0){let{messages:h}=m,g=new Map(h.map(b=>[b.id,b])),_=b=>b==="activity"||b==="reasoning";i=i.filter(b=>_(b.role)||g.has(b.id)).map(b=>_(b.role)?b:g.get(b.id));let S=new Set(i.map(b=>b.id));for(let b of h)S.has(b.id)||i.push(b);c({messages:i})}return p()}case v.ACTIVITY_SNAPSHOT:{let f=m,h=i.findIndex(F=>F.id===f.messageId),g=h>=0?i[h]:void 0,_=g?.role==="activity"?g:void 0,S=f.replace??!0,b=await X(r,i,a,(F,Z,ae)=>F.onActivitySnapshotEvent?.({event:f,messages:Z,state:ae,agent:n,input:e,activityMessage:_,existingMessage:g}));if(c(b),b.stopPropagation!==!0){let F={id:f.messageId,role:"activity",activityType:f.activityType,content:B(f.content)},Z;h===-1?(i.push(F),Z=F):_?S&&(i[h]={..._,activityType:f.activityType,content:B(f.content)}):S&&(i[h]=F,Z=F),c({messages:i}),Z&&await Promise.all(r.map(ae=>ae.onNewMessage?.({message:Z,messages:i,state:a,agent:n,input:e})))}return p()}case v.ACTIVITY_DELTA:{let f=m,h=i.findIndex(b=>b.id===f.messageId);if(h===-1)return p();let g=i[h];if(g.role!=="activity")return console.warn(`ACTIVITY_DELTA: Message '${f.messageId}' is not an activity message`),p();let _=g,S=await X(r,i,a,(b,F,Z)=>b.onActivityDeltaEvent?.({event:f,messages:F,state:Z,agent:n,input:e,activityMessage:_}));if(c(S),S.stopPropagation!==!0)try{let b=B(_.content??{}),F=Hr.applyPatch(b,f.patch??[],!0,!1).newDocument;i[h]={..._,content:B(F),activityType:f.activityType},c({messages:i})}catch(b){let F=b instanceof Error?b.message:String(b);console.warn(`Failed to apply activity patch for '${f.messageId}': ${F}`)}return p()}case v.RAW:return c(await X(r,i,a,(f,h,g)=>f.onRawEvent?.({event:m,messages:h,state:g,agent:n,input:e}))),p();case v.CUSTOM:return c(await X(r,i,a,(f,h,g)=>f.onCustomEvent?.({event:m,messages:h,state:g,agent:n,input:e}))),p();case v.RUN_STARTED:{let f=await X(r,i,a,(h,g,_)=>h.onRunStartedEvent?.({event:m,messages:g,state:_,agent:n,input:e}));if(c(f),f.stopPropagation!==!0){let h=m;if(h.input?.messages){for(let g of h.input.messages)i.find(_=>_.id===g.id)||i.push(g);c({messages:i})}}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 X(r,i,a,(_,S,b)=>_.onRunFinishedEvent?.({...h,messages:S,state:b,agent:n,input:e}));return c(g),g.stopPropagation!==!0&&(n.pendingInterrupts=h.outcome==="interrupt"?[...h.interrupts]:[]),p()}case v.RUN_ERROR:return c(await X(r,i,a,(f,h,g)=>f.onRunErrorEvent?.({event:m,messages:h,state:g,agent:n,input:e}))),p();case v.STEP_STARTED:return c(await X(r,i,a,(f,h,g)=>f.onStepStartedEvent?.({event:m,messages:h,state:g,agent:n,input:e}))),p();case v.STEP_FINISHED:return c(await X(r,i,a,(f,h,g)=>f.onStepFinishedEvent?.({event:m,messages:h,state:g,agent:n,input:e}))),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 X(r,i,a,(f,h,g)=>f.onReasoningStartEvent?.({event:m,messages:h,state:g,agent:n,input:e}))),p();case v.REASONING_MESSAGE_START:{let f=await X(r,i,a,(h,g,_)=>h.onReasoningMessageStartEvent?.({event:m,messages:g,state:_,agent:n,input:e}));if(c(f),f.stopPropagation!==!0){let{messageId:h}=m;if(!i.find(g=>g.id===h)){let g={id:h,role:"reasoning",content:""};i.push(g),c({messages:i})}}return p()}case v.REASONING_MESSAGE_CONTENT:{let{messageId:f,delta:h}=m,g=i.find(S=>S.id===f);if(!g)return console.warn(`REASONING_MESSAGE_CONTENT: No message found with ID '${f}'`),p();let _=await X(r,i,a,(S,b,F)=>S.onReasoningMessageContentEvent?.({event:m,messages:b,state:F,agent:n,input:e,reasoningMessageBuffer:typeof g.content=="string"?g.content:""}));return c(_),_.stopPropagation!==!0&&(g.content=`${typeof g.content=="string"?g.content:""}${h}`,c({messages:i})),p()}case v.REASONING_MESSAGE_END:{let{messageId:f}=m,h=i.find(g=>g.id===f);return h?(c(await X(r,i,a,(g,_,S)=>g.onReasoningMessageEndEvent?.({event:m,messages:_,state:S,agent:n,input:e,reasoningMessageBuffer:typeof h.content=="string"?h.content:""}))),await Promise.all(r.map(g=>{g.onNewMessage?.({message:h,messages:i,state:a,agent:n,input:e})})),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 X(r,i,a,(f,h,g)=>f.onReasoningEndEvent?.({event:m,messages:h,state:g,agent:n,input:e}))),p();case v.REASONING_ENCRYPTED_VALUE:{let{subtype:f,entityId:h,encryptedValue:g}=m,_=await X(r,i,a,(S,b,F)=>S.onReasoningEncryptedValueEvent?.({event:m,messages:b,state:F,agent:n,input:e}));if(c(_),_.stopPropagation!==!0){let S=!1;if(f==="tool-call"){for(let b of i)if(b.role==="assistant"&&b.toolCalls){let F=b.toolCalls.find(Z=>Z.id===h);if(F){F.encryptedValue=g,S=!0;break}}}else{let b=i.find(F=>F.id===h);b?.role!=="activity"&&b&&(b.encryptedValue=g,S=!0)}S&&(u.messages=i)}return p()}}return m.type,p()}),di(),r.length>0?pi({}):m=>m)},Ni=e=>t=>{let n=Jn(e),r=new Map,o=new Map,s=!1,i=!1,a=!1,u=new Map,c=!1,p=!1,m=!1,x=()=>{r.clear(),o.clear(),u.clear(),c=!1,p=!1,s=!1,i=!1,m=!0};return t.pipe(Ae(f=>{let h=f.type;if(n?.event("VERIFY","Event:",f,{type:f.type}),i)return Q(()=>new q(`Cannot send event type '${h}': The run has already errored with 'RUN_ERROR'. No further events can be sent.`));if(s&&h!==v.RUN_ERROR&&h!==v.RUN_STARTED)return Q(()=>new q(`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&&!s)return Q(()=>new q("Cannot send 'RUN_STARTED' while a run is still active. The previous run must be finished with 'RUN_FINISHED' before starting a new run."));s&&x()}}else if(a=!0,h!==v.RUN_STARTED&&h!==v.RUN_ERROR)return Q(()=>new q("First event must be 'RUN_STARTED'"));switch(h){case v.TEXT_MESSAGE_START:{let g=f.messageId;return r.has(g)?Q(()=>new q(`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),te(f))}case v.TEXT_MESSAGE_CONTENT:{let g=f.messageId;return r.has(g)?te(f):Q(()=>new q(`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),te(f)):Q(()=>new q(`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)?Q(()=>new q(`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),te(f))}case v.TOOL_CALL_ARGS:{let g=f.toolCallId;return o.has(g)?te(f):Q(()=>new q(`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),te(f)):Q(()=>new q(`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 u.has(g)?Q(()=>new q(`Step "${g}" is already active for 'STEP_STARTED'`)):(u.set(g,!0),te(f))}case v.STEP_FINISHED:{let g=f.stepName;return u.has(g)?(u.delete(g),te(f)):Q(()=>new q(`Cannot send 'STEP_FINISHED' for step "${g}" that was not started`))}case v.RUN_STARTED:return m=!0,te(f);case v.RUN_FINISHED:if(u.size>0){let g=Array.from(u.keys()).join(", ");return Q(()=>new q(`Cannot send 'RUN_FINISHED' while steps are still active: ${g}`))}if(r.size>0){let g=Array.from(r.keys()).join(", ");return Q(()=>new q(`Cannot send 'RUN_FINISHED' while text messages are still active: ${g}`))}if(o.size>0){let g=Array.from(o.keys()).join(", ");return Q(()=>new q(`Cannot send 'RUN_FINISHED' while tool calls are still active: ${g}`))}return s=!0,te(f);case v.RUN_ERROR:return i=!0,te(f);case v.CUSTOM:return te(f);case v.THINKING_TEXT_MESSAGE_START:return c?p?Q(()=>new q("Cannot send 'THINKING_TEXT_MESSAGE_START' event: A thinking message is already in progress. Complete it with 'THINKING_TEXT_MESSAGE_END' first.")):(p=!0,te(f)):Q(()=>new q("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?te(f):Q(()=>new q("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,te(f)):Q(()=>new q("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?Q(()=>new q("Cannot send 'THINKING_START' event: A thinking step is already in progress. End it with 'THINKING_END' first.")):(c=!0,te(f));case v.THINKING_END:return c?(c=!1,te(f)):Q(()=>new q("Cannot send 'THINKING_END' event: No active thinking step found. A 'THINKING_START' event must be sent first."));default:return te(f)}}))},Wt=(function(e){return e.HEADERS="headers",e.DATA="data",e})({}),sm=e=>co(()=>Bt(e())).pipe(fi(t=>{if(!t.ok){let o=t.headers.get("content-type")||"";return Bt(t.text()).pipe(Ae(s=>{let i=s;if(o.includes("application/json"))try{i=JSON.parse(s)}catch{}let a=Error(`HTTP ${t.status}: ${typeof i=="string"?i:JSON.stringify(i)}`);return a.status=t.status,a.payload=i,Q(()=>a)}))}let n={type:Wt.HEADERS,status:t.status,headers:t.headers},r=t.body?.getReader();return r?new J(o=>(o.next(n),(async()=>{try{for(;;){let{done:s,value:i}=await r.read();if(s)break;let a={type:Wt.DATA,data:i};o.next(a)}o.complete()}catch(s){o.error(s)}})(),()=>{r.cancel().catch(s=>{if(s?.name!=="AbortError")throw s})})):Q(()=>Error("Failed to getReader() from response"))})),im=(e,t)=>{let n=Jn(t),r=new nt,o=new TextDecoder("utf-8",{fatal:!1}),s="";e.subscribe({next:a=>{if(a.type!==Wt.HEADERS&&a.type===Wt.DATA&&a.data){let u=o.decode(a.data,{stream:!0});s+=u;let c=s.split(/\n\n/);s=c.pop()||"";for(let p of c)i(p)}},error:a=>r.error(a),complete:()=>{s&&(s+=o.decode(),i(s)),r.complete()}});function i(a){let u=a.split(`
702
+ `),c=[];for(let p of u)p.startsWith("data:")&&c.push(p.slice(5).replace(/^ /,""));if(c.length>0)try{let p=c.join(`
703
+ `),m=JSON.parse(p);n?.event("SSE","Event received:",m,{type:m.type}),r.next(m)}catch(p){r.error(p)}}return r.asObservable()},am=e=>{let t=new nt,n=new Uint8Array;e.subscribe({next:o=>{if(o.type!==Wt.HEADERS&&o.type===Wt.DATA&&o.data){let s=new Uint8Array(n.length+o.data.length);s.set(n,0),s.set(o.data,n.length),n=s,r()}},error:o=>t.error(o),complete:()=>{if(n.length>0)try{r()}catch{console.warn("Incomplete or invalid protocol buffer data at stream end")}t.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 s=n.slice(4,o),i=Lc(s);t.next(i),n=n.slice(o)}catch(s){let i=s instanceof Error?s.message:String(s);t.error(Error(`Failed to decode protocol buffer message: ${i}`));return}}}return t.asObservable()},lm=(e,t)=>{let n=Jn(t),r=new nt,o=new Zr,s=!1;return e.subscribe({next:i=>{if(o.next(i),i.type===Wt.HEADERS&&!s){s=!0;let a=i.headers.get("content-type");n?.lifecycle("HTTP","Stream format detected:",{contentType:a,parser:a===ki?"protobuf":"sse"}),a===ki?am(o).subscribe({next:u=>r.next(u),error:u=>r.error(u),complete:()=>r.complete()}):im(o,n).subscribe({next:u=>{try{let c=Or.parse(u);n?.event("HTTP","Event validated:",c,{type:c.type,valid:!0}),r.next(c)}catch(c){n?.event("HTTP","Event invalid:",{json:u,error:String(c)}),r.error(c)}},error:u=>{if(u?.name==="AbortError"){r.next({type:v.RUN_ERROR,message:u.message||"Request aborted",code:"abort",rawEvent:u}),r.complete();return}return r.error(u)},complete:()=>r.complete()})}else s||r.error(Error("No headers event received before data events"))},error:i=>{o.error(i),r.error(i)},complete:()=>{o.complete()}}),r.asObservable()},K=l.enum(["TextMessageStart","TextMessageContent","TextMessageEnd","ActionExecutionStart","ActionExecutionArgs","ActionExecutionEnd","ActionExecutionResult","AgentStateMessage","MetaEvent","RunStarted","RunFinished","RunError","NodeStarted","NodeFinished"]),cm=l.enum(["LangGraphInterruptEvent","PredictState","Exit"]),um=l.object({type:l.literal(K.enum.TextMessageStart),messageId:l.string(),parentMessageId:l.string().optional(),role:l.string().optional()}),dm=l.object({type:l.literal(K.enum.TextMessageContent),messageId:l.string(),content:l.string()}),pm=l.object({type:l.literal(K.enum.TextMessageEnd),messageId:l.string()}),fm=l.object({type:l.literal(K.enum.ActionExecutionStart),actionExecutionId:l.string(),actionName:l.string(),parentMessageId:l.string().optional()}),hm=l.object({type:l.literal(K.enum.ActionExecutionArgs),actionExecutionId:l.string(),args:l.string()}),mm=l.object({type:l.literal(K.enum.ActionExecutionEnd),actionExecutionId:l.string()}),gm=l.object({type:l.literal(K.enum.ActionExecutionResult),actionName:l.string(),actionExecutionId:l.string(),result:l.string()}),vm=l.object({type:l.literal(K.enum.AgentStateMessage),threadId:l.string(),agentName:l.string(),nodeName:l.string(),runId:l.string(),active:l.boolean(),role:l.string(),state:l.string(),running:l.boolean()}),ym=l.object({type:l.literal(K.enum.MetaEvent),name:cm,value:l.any()}),bm=l.object({type:l.literal(K.enum.RunError),message:l.string(),code:l.string().optional()});l.discriminatedUnion("type",[um,dm,pm,fm,hm,mm,gm,vm,ym,bm]),l.object({id:l.string(),role:l.string(),content:l.string(),parentMessageId:l.string().optional()}),l.object({id:l.string(),name:l.string(),arguments:l.any(),parentMessageId:l.string().optional()}),l.object({id:l.string(),result:l.any(),actionExecutionId:l.string(),actionName:l.string()});var xm=e=>{if(typeof e=="string")return e;if(!Array.isArray(e))return;let t=e.filter(n=>n.type==="text").map(n=>n.text).filter(n=>n.length>0);if(t.length!==0)return t.join(`
704
+ `)},Em=(e,t,n)=>r=>{let o={},s=!0,i=!0,a="",u=null,c=null,p=[],m={},x=f=>{typeof f=="object"&&f&&("messages"in f&&delete f.messages,o=f)};return r.pipe(Ae(f=>{switch(f.type){case v.TEXT_MESSAGE_START:{let h=f;return[{type:K.enum.TextMessageStart,messageId:h.messageId,role:h.role}]}case v.TEXT_MESSAGE_CONTENT:{let h=f;return[{type:K.enum.TextMessageContent,messageId:h.messageId,content:h.delta}]}case v.TEXT_MESSAGE_END:{let h=f;return[{type:K.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:""}}),i=!0,m[h.toolCallId]=h.toolCallName,[{type:K.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 _=!1;if(c){let S=c.find(b=>b.tool==g.function.name);if(S)try{let b=JSON.parse(fo(g.function.arguments));S.tool_argument&&S.tool_argument in b?(x({...o,[S.state_key]:b[S.tool_argument]}),_=!0):S.tool_argument||(x({...o,[S.state_key]:b}),_=!0)}catch{}}return[{type:K.enum.ActionExecutionArgs,actionExecutionId:h.toolCallId,args:h.delta},..._?[{type:K.enum.AgentStateMessage,threadId:e,agentName:n,nodeName:a,runId:t,running:s,role:"assistant",state:JSON.stringify(o),active:i}]:[]]}case v.TOOL_CALL_END:{let h=f;return[{type:K.enum.ActionExecutionEnd,actionExecutionId:h.toolCallId}]}case v.TOOL_CALL_RESULT:{let h=f;return[{type:K.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":s=!1;break;case"PredictState":c=h.value;break}return[{type:K.enum.MetaEvent,name:h.name,value:h.value}]}case v.STATE_SNAPSHOT:return x(f.snapshot),[{type:K.enum.AgentStateMessage,threadId:e,agentName:n,nodeName:a,runId:t,running:s,role:"assistant",state:JSON.stringify(o),active:i}];case v.STATE_DELTA:{let h=f,g=Hr.applyPatch(o,h.delta,!0,!1);return g?(x(g.newDocument),[{type:K.enum.AgentStateMessage,threadId:e,agentName:n,nodeName:a,runId:t,running:s,role:"assistant",state:JSON.stringify(o),active:i}]):[]}case v.MESSAGES_SNAPSHOT:return u=f.messages,[{type:K.enum.AgentStateMessage,threadId:e,agentName:n,nodeName:a,runId:t,running:s,role:"assistant",state:JSON.stringify({...o,...u?{messages:u}:{}}),active:!0}];case v.RUN_STARTED:return[];case v.RUN_FINISHED:return u&&(o.messages=u),Object.keys(o).length===0?[]:[{type:K.enum.AgentStateMessage,threadId:e,agentName:n,nodeName:a,runId:t,running:s,role:"assistant",state:JSON.stringify({...o,...u?{messages:_m(u)}:{}}),active:!1}];case v.RUN_ERROR:{let h=f;return[{type:K.enum.RunError,message:h.message,code:h.code}]}case v.STEP_STARTED:return a=f.stepName,p=[],c=null,[{type:K.enum.AgentStateMessage,threadId:e,agentName:n,nodeName:a,runId:t,running:s,role:"assistant",state:JSON.stringify(o),active:!0}];case v.STEP_FINISHED:return p=[],c=null,[{type:K.enum.AgentStateMessage,threadId:e,agentName:n,nodeName:a,runId:t,running:s,role:"assistant",state:JSON.stringify(o),active:!1}];default:return[]}}))};function _m(e){let t=[];for(let n of e)if(n.role==="assistant"||n.role==="user"||n.role==="system"){let r=xm(n.content);if(r){let o={id:n.id,role:n.role,content:r};t.push(o)}if(n.role==="assistant"&&n.toolCalls&&n.toolCalls.length>0)for(let o of n.toolCalls){let s={id:o.id,name:o.function.name,arguments:JSON.parse(o.function.arguments),parentMessageId:n.id};t.push(s)}}else if(n.role==="tool"){let r="unknown";for(let s of e)if(s.role==="assistant"&&s.toolCalls?.length){for(let i of s.toolCalls)if(i.id===n.toolCallId){r=i.function.name;break}}let o={id:n.id,result:n.content,actionExecutionId:n.toolCallId,actionName:r};t.push(o)}return t}var Ko=e=>t=>{let n=Jn(e),r,o,s,i,a=()=>{if(!r||i!=="text")throw Error("No text message to close");let m={type:v.TEXT_MESSAGE_END,messageId:r.messageId};return i=void 0,r=void 0,n?.event("TRANSFORM","TEXT_MESSAGE_END",m,{messageId:m.messageId}),m},u=()=>{if(!o||i!=="tool")throw Error("No tool call to close");let m={type:v.TOOL_CALL_END,toolCallId:o.toolCallId};return i=void 0,o=void 0,n?.event("TRANSFORM","TOOL_CALL_END",m,{toolCallId:m.toolCallId}),m},c=()=>{if(!s||i!=="reasoning")throw Error("No reasoning message to close");let m={type:v.REASONING_MESSAGE_END,messageId:s.messageId};return i=void 0,s=void 0,n?.event("TRANSFORM","REASONING_MESSAGE_END",m,{messageId:m.messageId}),m},p=()=>i==="text"?[a()]:i==="tool"?[u()]:i==="reasoning"?[c()]:[];return t.pipe(Ae(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 x=m,f=[];if((i!=="text"||x.messageId!==void 0&&x.messageId!==r?.messageId)&&f.push(...p()),i!=="text"){if(x.messageId===void 0)throw Error("First TEXT_MESSAGE_CHUNK must have a messageId");r={messageId:x.messageId,name:x.name},i="text";let b={type:v.TEXT_MESSAGE_START,messageId:x.messageId,role:x.role||"assistant",...x.name!==void 0&&{name:x.name}};f.push(b),n?.event("TRANSFORM","TEXT_MESSAGE_START",b,{messageId:x.messageId})}if(x.delta!==void 0){let b={type:v.TEXT_MESSAGE_CONTENT,messageId:r.messageId,delta:x.delta};f.push(b),n?.event("TRANSFORM","TEXT_MESSAGE_CONTENT",b,{messageId:r.messageId})}return f;case v.TOOL_CALL_CHUNK:let h=m,g=[];if((i!=="tool"||h.toolCallId!==void 0&&h.toolCallId!==o?.toolCallId)&&g.push(...p()),i!=="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},i="tool";let b={type:v.TOOL_CALL_START,toolCallId:h.toolCallId,toolCallName:h.toolCallName,parentMessageId:h.parentMessageId};g.push(b),n?.event("TRANSFORM","TOOL_CALL_START",b,{toolCallId:h.toolCallId,toolCallName:h.toolCallName})}if(h.delta!==void 0){let b={type:v.TOOL_CALL_ARGS,toolCallId:o.toolCallId,delta:h.delta};g.push(b),n?.event("TRANSFORM","TOOL_CALL_ARGS",b,{toolCallId:o.toolCallId})}return g;case v.REASONING_MESSAGE_CHUNK:let _=m,S=[];if((i!=="reasoning"||_.messageId&&_.messageId!==s?.messageId)&&S.push(...p()),i!=="reasoning"){if(_.messageId===void 0)throw Error("First REASONING_MESSAGE_CHUNK must have a messageId");s={messageId:_.messageId},i="reasoning";let b={type:v.REASONING_MESSAGE_START,messageId:_.messageId};S.push(b),n?.event("TRANSFORM","REASONING_MESSAGE_START",b,{messageId:_.messageId})}if(_.delta!==void 0){let b={type:v.REASONING_MESSAGE_CONTENT,messageId:s.messageId,delta:_.delta};S.push(b),n?.event("TRANSFORM","REASONING_MESSAGE_CONTENT",b,{messageId:s.messageId})}return S}return m.type,[]}),jt(()=>{p()}))};function Tm(e,t=new Date){return e.expiresAt===void 0?!1:new Date(e.expiresAt)<=t}var Yo=class{runNext(e,t){return t.run(e).pipe(Ko(!1))}runNextWithState(e,t){let n=B(e.messages||[]),r=B(e.state||{}),o=new Zr;return zc(e,o,t,[]).subscribe(s=>{s.messages!==void 0&&(n=s.messages),s.state!==void 0&&(r=s.state)}),this.runNext(e,t).pipe(uo(async s=>(o.next(s),await new Promise(i=>setTimeout(i,0)),{event:s,messages:B(n),state:B(r)})))}},Sm=class extends Yo{constructor(e){super(),this.fn=e}run(e,t){return this.fn(e,t)}};function wm(e){let t=e.content;if(Array.isArray(t)){let n=t.filter(r=>typeof r=="object"&&!!r&&"type"in r&&r.type==="text"&&typeof r.text=="string").map(r=>r.text).join("");return{...e,content:n}}return typeof t=="string"?e:{...e,content:""}}var km=class extends Yo{run(e,t){let{parentRunId:n,...r}=e,o={...r,messages:r.messages.map(wm)};return this.runNext(o,t)}},Uc="THINKING_START",Gc="THINKING_END",Fc="THINKING_TEXT_MESSAGE_START",Hc="THINKING_TEXT_MESSAGE_CONTENT",$c="THINKING_TEXT_MESSAGE_END",Am=class extends Yo{constructor(...e){super(...e),this.currentReasoningId=null,this.currentMessageId=null}warnAboutTransformation(e,t){typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(`AG-UI is converting ${e} to ${t}. 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(e,t){return this.currentReasoningId=null,this.currentMessageId=null,this.runNext(e,t).pipe(Vt(n=>this.transformEvent(n)))}transformEvent(e){switch(e.type){case Uc:{this.currentReasoningId=ze();let{title:t,...n}=e;return this.warnAboutTransformation(Uc,v.REASONING_START),{...n,type:v.REASONING_START,messageId:this.currentReasoningId}}case Fc:return this.currentMessageId=ze(),this.warnAboutTransformation(Fc,v.REASONING_MESSAGE_START),{...e,type:v.REASONING_MESSAGE_START,messageId:this.currentMessageId,role:"assistant"};case Hc:{let{delta:t,...n}=e;return this.warnAboutTransformation(Hc,v.REASONING_MESSAGE_CONTENT),{...n,type:v.REASONING_MESSAGE_CONTENT,messageId:this.currentMessageId??ze(),delta:t}}case $c:{let t=this.currentMessageId??ze();return this.warnAboutTransformation($c,v.REASONING_MESSAGE_END),{...e,type:v.REASONING_MESSAGE_END,messageId:t}}case Gc:{let t=this.currentReasoningId??ze();return this.warnAboutTransformation(Gc,v.REASONING_END),{...e,type:v.REASONING_END,messageId:t}}default:return e}}};function Im(e){return e.startsWith("image/")?"image":e.startsWith("audio/")?"audio":e.startsWith("video/")?"video":"document"}function Cm(e){return typeof e=="object"&&!!e&&"type"in e&&e.type==="binary"&&"mimeType"in e&&typeof e.mimeType=="string"}function Nm(e){let t=Im(e.mimeType);return e.data?{type:t,source:{type:"data",value:e.data,mimeType:e.mimeType},...e.filename?{metadata:{filename:e.filename}}:{}}:e.url?{type:t,source:{type:"url",value:e.url,mimeType:e.mimeType},...e.filename?{metadata:{filename:e.filename}}:{}}:e}function Rm(e){let t=e.content;if(!Array.isArray(t))return e;let n=t.map(r=>Cm(r)?Nm(r):r);return{...e,content:n}}var Om=class extends Yo{run(e,t){let n={...e,messages:e.messages.map(Rm)};return this.runNext(n,t)}},Mm="0.0.54",Lm=class{get maxVersion(){return Mm}get debug(){return this._debug}set debug(e){this._debug=Zo(e),this._debugLogger=Ci(this._debug)}get debugLogger(){return this._debugLogger}set debugLogger(e){typeof e=="boolean"?this._debugLogger=e?Ci(Zo(!0)):void 0:this._debugLogger=e}constructor({agentId:e,description:t,threadId:n,initialMessages:r,initialState:o,debug:s}={}){this.subscribers=[],this.isRunning=!1,this.pendingInterrupts=[],this.middlewares=[],this.agentId=e,this.description=t??"",this.threadId=n??ft(),this.messages=B(r??[]),this.state=B(o??{}),this._debug=Zo(s),this._debugLogger=Ci(this._debug),qn(this.maxVersion,"0.0.39")<=0&&this.middlewares.unshift(new km),qn(this.maxVersion,"0.0.45")<=0&&this.middlewares.unshift(new Am),qn(this.maxVersion,"0.0.47")<=0&&this.middlewares.unshift(new Om)}subscribe(e){return this.subscribers.push(e),{unsubscribe:()=>{this.subscribers=this.subscribers.filter(t=>t!==e)}}}use(...e){let t=e.map(n=>typeof n=="function"?new Sm(n):n);return this.middlewares.push(...t),this}async runAgent(e,t){try{this.isRunning=!0,this.agentId=this.agentId??ft();let n=this.prepareRunAgentInput(e);this.debugLogger?.lifecycle("LIFECYCLE","Run started:",{agentId:this.agentId,threadId:this.threadId});let r,o=new Set(this.messages.map(u=>u.id)),s=[{onRunFinishedEvent:u=>{u.outcome==="success"&&(r=u.result)}},...this.subscribers,t??{}];await this.onInitialize(n,s),this.activeRunDetach$=new nt;let i;this.activeRunCompletionPromise=new Promise(u=>{i=u}),await lo(Xr(()=>this.middlewares.length===0?this.run(n):this.middlewares.reduceRight((u,c)=>({run:p=>c.run(p,u),get messages(){return u.messages},get state(){return u.state}}),this).run(n),Ko(this.debugLogger),Ni(this.debugLogger),u=>u.pipe(po(this.activeRunDetach$)),u=>this.apply(n,u,s),u=>this.processApplyEvents(n,u,s),Zn(u=>(this.debugLogger?.lifecycle("LIFECYCLE","Run errored:",{agentId:this.agentId,error:u instanceof Error?u.message:String(u)}),this.isRunning=!1,this.onError(n,u,s))),jt(()=>{this.debugLogger?.lifecycle("LIFECYCLE","Run finished:",{agentId:this.agentId,threadId:this.threadId}),this.isRunning=!1,this.onFinalize(n,s),i?.(),i=void 0,this.activeRunCompletionPromise=void 0,this.activeRunDetach$=void 0}))(te(null)));let a=B(this.messages).filter(u=>!o.has(u.id));return{result:r,newMessages:a}}finally{this.isRunning=!1}}connect(e){throw new Js}async connectAgent(e,t){try{this.isRunning=!0,this.agentId=this.agentId??ft();let n=this.prepareRunAgentInput(e),r,o=new Set(this.messages.map(u=>u.id)),s=[{onRunFinishedEvent:u=>{u.outcome==="success"&&(r=u.result)}},...this.subscribers,t??{}];await this.onInitialize(n,s),this.activeRunDetach$=new nt;let i;this.activeRunCompletionPromise=new Promise(u=>{i=u}),await lo(Xr(()=>co(()=>this.connect(n)),Ko(this.debugLogger),Ni(this.debugLogger),u=>u.pipe(po(this.activeRunDetach$)),u=>this.apply(n,u,s),u=>this.processApplyEvents(n,u,s),Zn(u=>(this.isRunning=!1,u instanceof Js?Kr:this.onError(n,u,s))),jt(()=>{this.isRunning=!1,this.onFinalize(n,s),i?.(),i=void 0,this.activeRunCompletionPromise=void 0,this.activeRunDetach$=void 0}))(te(null)),{defaultValue:void 0});let a=B(this.messages).filter(u=>!o.has(u.id));return{result:r,newMessages:a}}finally{this.isRunning=!1}}abortRun(){}async detachActiveRun(){if(!this.activeRunDetach$)return;let e=this.activeRunCompletionPromise??Promise.resolve();this.activeRunDetach$.next(),this.activeRunDetach$?.complete(),await e}apply(e,t,n){return zc(e,t,this,n,this.debugLogger)}processApplyEvents(e,t,n){return t.pipe(hi(r=>{r.messages&&(this.messages=r.messages,n.forEach(o=>{o.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:e})})),r.state&&(this.state=r.state,n.forEach(o=>{o.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:e})}))}))}prepareRunAgentInput(e){let t=B(this.messages).filter(n=>n.role!=="activity");return{threadId:this.threadId,runId:e?.runId||ft(),tools:B(e?.tools??[]),context:B(e?.context??[]),forwardedProps:B(e?.forwardedProps??{}),state:B(this.state),messages:t,...e?.resume===void 0?{}:{resume:B(e.resume)}}}async onInitialize(e,t){if(this.pendingInterrupts.length>0){let r=new Set((e.resume??[]).map(s=>s.interruptId)),o=this.pendingInterrupts.map(s=>s.id).filter(s=>!r.has(s));if(o.length>0)throw new q(`Thread has ${o.length} pending interrupt(s) not addressed by resume: ${o.join(", ")}`);for(let s of this.pendingInterrupts)if(Tm(s))throw new q(`Interrupt ${s.id} expired at ${s.expiresAt}`)}let n=await X(t,this.messages,this.state,(r,o,s)=>r.onRunInitialized?.({messages:o,state:s,agent:this,input:e}));(n.messages!==void 0||n.state!==void 0)&&(n.messages&&(this.messages=n.messages,e.messages=n.messages,t.forEach(r=>{r.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:e})})),n.state&&(this.state=n.state,e.state=n.state,t.forEach(r=>{r.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:e})})))}onError(e,t,n){return Bt(X(n,this.messages,this.state,(r,o,s)=>r.onRunFailed?.({error:t,messages:o,state:s,agent:this,input:e}))).pipe(Vt(r=>{let o=r;if((o.messages!==void 0||o.state!==void 0)&&(o.messages!==void 0&&(this.messages=o.messages,n.forEach(s=>{s.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:e})})),o.state!==void 0&&(this.state=o.state,n.forEach(s=>{s.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:e})}))),o.stopPropagation!==!0){let s=String(t);if(!(t.name==="AbortError"||t.message==="Fetch is aborted"||t.message==="signal is aborted without reason"||t.message==="component unmounted"||s==="component unmounted"))throw console.error("Agent execution failed:",t),t}return{}}))}async onFinalize(e,t){let n=await X(t,this.messages,this.state,(r,o,s)=>r.onRunFinalized?.({messages:o,state:s,agent:this,input:e}));(n.messages!==void 0||n.state!==void 0)&&(n.messages!==void 0&&(this.messages=n.messages,t.forEach(r=>{r.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:e})})),n.state!==void 0&&(this.state=n.state,t.forEach(r=>{r.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:e})})))}clone(){let e=Object.create(Object.getPrototypeOf(this));return e.agentId=this.agentId,e.description=this.description,e.threadId=this.threadId,e.messages=B(this.messages),e.state=B(this.state),e._debug=this._debug,e._debugLogger=this._debugLogger,e.isRunning=this.isRunning,e.subscribers=[...this.subscribers],e.middlewares=[...this.middlewares],e.pendingInterrupts=B(this.pendingInterrupts),e}addMessage(e){this.messages.push(e),(async()=>{for(let t of this.subscribers)await t.onNewMessage?.({message:e,messages:this.messages,state:this.state,agent:this});if(e.role==="assistant"&&e.toolCalls)for(let t of e.toolCalls)for(let n of this.subscribers)await n.onNewToolCall?.({toolCall:t,messages:this.messages,state:this.state,agent:this});for(let t of this.subscribers)await t.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}addMessages(e){this.messages.push(...e),(async()=>{for(let t of e){for(let n of this.subscribers)await n.onNewMessage?.({message:t,messages:this.messages,state:this.state,agent:this});if(t.role==="assistant"&&t.toolCalls)for(let n of t.toolCalls)for(let r of this.subscribers)await r.onNewToolCall?.({toolCall:n,messages:this.messages,state:this.state,agent:this})}for(let t of this.subscribers)await t.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}setMessages(e){this.messages=B(e),(async()=>{for(let t of this.subscribers)await t.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}setState(e){this.state=B(e),(async()=>{for(let t of this.subscribers)await t.onStateChanged?.({messages:this.messages,state:this.state,agent:this})})()}legacy_to_be_removed_runAgentBridged(e){this.agentId=this.agentId??ft();let t=this.prepareRunAgentInput(e);return(this.middlewares.length===0?this.run(t):this.middlewares.reduceRight((n,r)=>({run:o=>r.run(o,n),get messages(){return n.messages},get state(){return n.state}}),this).run(t)).pipe(Ko(this.debugLogger),Ni(this.debugLogger),Em(this.threadId,t.runId,this.agentId),n=>n.pipe(Vt(r=>(this.debugLogger?.event("LEGACY","Event:",r,{type:r.type}),r))))}},Bc=class extends Lm{requestInit(e){return{method:"POST",headers:{...this.headers,"Content-Type":"application/json",Accept:"text/event-stream"},body:JSON.stringify(e),signal:this.abortController.signal}}runAgent(e,t){return this.abortController=e?.abortController??new AbortController,super.runAgent(e,t)}abortRun(){this.abortController.abort(),super.abortRun()}constructor(e){super(e),this.abortController=new AbortController,this.url=e.url,this.headers=B(e.headers??{}),this.fetch=e.fetch??fetch}run(e){return lm(sm(()=>this.fetch(this.url,this.requestInit(e))),this.debugLogger)}clone(){let e=super.clone();e.url=this.url,e.headers=B(this.headers??{}),e.fetch=this.fetch;let t=new AbortController,n=this.abortController.signal;return n.aborted&&t.abort(n.reason),e.abortController=t,e}};var Qn=class{#e;#r;#i;#l;#t;#n;constructor(t){this.#e=t.agent,this.#r=t.handlers,this.#i=t.getTools??(()=>[]),this.#l=t.getContext??(()=>[]),this.#t=t.executeTool??null,this.#n=t.onPersist??(()=>{})}get running(){return this.#e.isRunning}get messages(){return this.#e.messages}async send(t){this.#e.addMessage({id:ze(),role:"user",content:t}),this.#n(this.#e.messages),await this.#o()}async resume(){await this.#o()}addToolResult(t,n){this.#e.addMessage({id:ze(),role:"tool",content:n,toolCallId:t}),this.#n(this.#e.messages)}async#o(){try{await this.#u()}catch(t){this.#r.onError(t instanceof Error?t.message:String(t))}}async#u(){for(let t=0;t<bs;t+=1){let n=[];if(await this.#e.runAgent({tools:this.#i(),context:this.#l()},this.#s(n)),this.#n(this.#e.messages),this.#t===null||n.length===0)return;let r=!1;for(let o of n){let s=await this.#t(o);if(s!==null){if(s.halt===!0)return;this.#e.addMessage({id:ze(),role:"tool",content:s.content,toolCallId:o.id}),this.#n(this.#e.messages),r=!0}}if(!r)return}}#s(t){let n=this.#r;return{onRunInitialized(){n.onRunStart()},onTextMessageContentEvent({textMessageBuffer:r}){n.onTextDelta(r)},onTextMessageEndEvent({textMessageBuffer:r}){n.onTextEnd(r)},onToolCallEndEvent({event:r,toolCallName:o,toolCallArgs:s}){let i={id:r.toolCallId,name:o,args:s};t.push(i),n.onToolCall(i)},onRunErrorEvent({event:r}){n.onError(r.message)},onRunFinalized(){n.onRunEnd()}}}};var Mi="ag-ui-chat:thread",Li="ag-ui-chat:messages:",Pi="ag-ui-chat:checkpoint:",er=class{threadId(){let t=sessionStorage.getItem(Mi);if(t!==null)return t;let n=ze();return sessionStorage.setItem(Mi,n),n}loadMessages(t){return Promise.resolve(this.#e(Li+t))}saveMessages(t,n){sessionStorage.setItem(Li+t,JSON.stringify(n))}loadCheckpoint(t){return this.#e(Pi+t)}saveCheckpoint(t,n){let r=Pi+t;if(n===null){sessionStorage.removeItem(r);return}sessionStorage.setItem(r,JSON.stringify(n))}clear(t){sessionStorage.removeItem(Li+t),sessionStorage.removeItem(Pi+t),sessionStorage.removeItem(Mi)}#e(t){let n=sessionStorage.getItem(t);if(n===null)return null;try{return JSON.parse(n)}catch{return null}}};function Di(e){return new Bc({url:e.endpoint,headers:e.headers??{},fetch:(t,n)=>fetch(t,n),...e.threadId!==void 0?{threadId:e.threadId}:{},...e.initialMessages!==void 0?{initialMessages:[...e.initialMessages]}:{}})}var Vc="ag-ui-chat:collapsed",tr=class extends HTMLElement{agentFactory=Di;headers={};autoConfirm=!1;confirmPredicate=null;getTools=()=>[...this.#T().map(t=>({name:t.name,description:t.description,parameters:t.parameters})),...this.#e.tools()];getContext=()=>Ts(this.getPageMap,this.autoInjectPageMap);routeMap=[];navigate=null;getPageMap=null;autoInjectPageMap=!0;conversationStore=new er;navigationResult=()=>({navigated:!0,url:window.location.href});skillContext=()=>({});#e=new Rn;#r=new Map;#i;#l;#t;#n;#o;#u;#s;#a;#p=null;#d=null;#m=null;#c="";#g=[];#x=[];#E=[];#_=[];constructor(){super(),this.#i=this.attachShadow({mode:"open"}),this.#l=document.createElement("div"),this.#t=document.createElement("div"),this.#n=document.createElement("textarea"),this.#o=document.createElement("button"),this.#u=document.createElement("span"),this.#a=document.createElement("div"),this.#s=new Sr(t=>this.#M(t))}static get observedAttributes(){return["title-text"]}attributeChangedCallback(t,n,r){this.#u.textContent=r??"Assistant"}registerTool(t){this.#e.register(t)}registerStateHook(t){for(let n of ws(t))this.#e.register(n)}#I(){return this.routeMap.length===0?[]:Ss(()=>this.routeMap,()=>this.navigate)}#C(){let t=this.getPageMap;return t===null?[]:[{name:"read_page",description:"Read the current page's structure (fields, buttons, route). Call after acting to observe the result within the same turn.",parameters:{type:"object",properties:{},required:[]},handler:()=>t()}]}#T(){return[...this.#I(),...this.#C()]}#S(t){let n=this.#T().find(r=>r.name===t);return n!==void 0?n:this.#e.has(t)?this.#e.get(t):null}get endpoint(){return this.getAttribute("endpoint")??""}set endpoint(t){this.setAttribute("endpoint",t)}get toolDisplay(){let t=this.getAttribute("data-tool-display");return t===Xe.MINIMAL||t===Xe.COMPACT?t:Xe.FULL}set toolDisplay(t){this.setAttribute("data-tool-display",t)}connectedCallback(){this.#U(),sessionStorage.getItem(Vc)==="1"&&this.setAttribute("collapsed",""),this.#N(),this.#c=this.conversationStore.threadId(),this.#L()}setSkills(t){this.#_=t,this.#v()}#N(){this.#s.enableChips(this.getAttribute("data-prompt-chips")==="true"),this.#s.enableSlash(this.getAttribute("data-slash-commands")==="true"),this.#E=this.#R(),this.#v(),this.#O()}#R(){let t=this.getAttribute("data-skills");if(t===null)return[];try{return xs(JSON.parse(t))}catch{return[]}}async#O(){let t=this.getAttribute("data-skills-url");if(t!==null)try{let n=await fetch(t,{headers:this.headers});this.#x=xs(await n.json()),this.#v()}catch{}}#v(){let t=new Map;for(let n of[...this.#x,...this.#E,...this.#_])t.set(n.name,n);this.#s.setSkills([...t.values()])}#M(t){let{text:n,missing:r}=ha(t.prompt,this.skillContext());if(r.length>0){this.#a.textContent=`\u201C${t.title}\u201D needs: ${r.join(", ")}`,this.#a.hidden=!1;return}this.#a.hidden=!0,this.#n.value=n,t.sendImmediately===!0?this.#b():this.#n.focus()}get collapsed(){return this.hasAttribute("collapsed")}set collapsed(t){this.setCollapsed(t)}setCollapsed(t){t?this.setAttribute("collapsed",""):this.removeAttribute("collapsed"),sessionStorage.setItem(Vc,t?"1":"0"),this.dispatchEvent(new CustomEvent(gs,{detail:{collapsed:t},bubbles:!0,composed:!0}))}toggleCollapsed(){this.setCollapsed(!this.collapsed)}newChat(){this.conversationStore.clear(this.#c),this.#p=null,this.#d=null,this.#h(),this.#r.clear(),this.#g=[],this.#t.replaceChildren(),this.#c=this.conversationStore.threadId(),this.#o.disabled=!1}async#L(){let t=await this.conversationStore.loadMessages(this.#c);if(t!==null){this.#g=t;for(let r of t)this.#P(r)}let n=this.conversationStore.loadCheckpoint(this.#c);n!==null&&await this.#D(n)}#P(t){typeof t.content!="string"||t.content===""||(t.role===We.USER?this.appendMessage(We.USER,t.content):t.role===We.ASSISTANT&&this.#y(this.appendMessage(We.ASSISTANT,t.content)))}#y(t){this.getAttribute("data-text-animation")==="word"&&Ja(t)}async#D(t){this.conversationStore.saveCheckpoint(this.#c,null);let n=this.#w();n.addToolResult(t.toolCallId,JSON.stringify(this.navigationResult(t))),await n.resume()}appendMessage(t,n){let r=document.createElement("div");return r.className=`message message--${t}`,t===We.ASSISTANT?r.innerHTML=Tr(n):r.textContent=n,this.#t.appendChild(r),this.#t.scrollTop=this.#t.scrollHeight,r}#U(){let t=document.createElement("style");t.textContent=Qa,this.#l.className="chat";let n=document.createElement("div");n.className="header";let r=this.#u;r.className="header-title",r.textContent=this.getAttribute("title-text")??"Assistant";let o=document.createElement("div");o.className="header-controls";let s=document.createElement("button");s.type="button",s.className="header-btn header-btn--new",s.title="New chat",s.setAttribute("aria-label","New chat"),s.textContent="\u271A",s.addEventListener("click",()=>this.newChat());let i=document.createElement("button");i.type="button",i.className="header-btn header-btn--collapse",i.title="Collapse",i.setAttribute("aria-label","Collapse"),i.textContent="\u2014",i.addEventListener("click",()=>this.toggleCollapsed()),o.append(s,i),n.append(r,o),this.#t.className="messages",this.#t.setAttribute("role","log"),this.#t.setAttribute("aria-live","polite"),this.#t.setAttribute("aria-label","Conversation");let a=document.createElement("div");a.className="input-row",this.#n.className="input",this.#n.setAttribute("aria-label","Message"),this.#n.rows=2,this.#n.placeholder="Ask anything\u2026",this.#n.addEventListener("keydown",u=>this.#F(u)),this.#n.addEventListener("input",()=>this.#G()),this.#o.className="send",this.#o.type="button",this.#o.textContent="Send",this.#o.addEventListener("click",()=>{this.#b()}),this.#a.className="skill-hint",this.#a.hidden=!0,a.append(this.#n,this.#o),this.#l.append(n,this.#t,this.#s.palette,this.#s.chips,this.#a,a),this.#i.append(t,this.#l)}#G(){this.#s.onInput(this.#n.value),this.#a.hidden=!0}#F(t){if(this.#s.onKeydown(t)){t.preventDefault();return}t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),this.#b())}async#b(){let t=this.#n.value.trim();t!==""&&(this.appendMessage(We.USER,t),this.#n.value="",this.dispatchEvent(new CustomEvent(ms,{detail:{content:t},bubbles:!0,composed:!0})),await this.#H(t))}async#H(t){this.endpoint!==""&&await this.#w().send(t)}#w(){if(this.#p===null){let t=this.agentFactory({endpoint:this.endpoint,headers:this.headers,threadId:this.#c,initialMessages:this.#g});this.#p=new Qn({agent:t,handlers:this.#B(),getTools:()=>this.getTools(),getContext:()=>this.getContext(),executeTool:n=>this.#z(n),onPersist:n=>this.conversationStore.saveMessages(this.#c,n)})}return this.#p}async#$(t,n){return this.autoConfirm?!1:this.confirmPredicate!==null?await this.confirmPredicate(t.name,t.args)===!0:Es(n.parameters)}async#z(t){let n=this.#A(t);this.#r.delete(t.id);let r=this.#S(t.name);if(r===null)return n.settle(me.DONE,"Executed on the server."),this.#f(),null;if(await this.#$(t,r)){let s={toolName:t.name,args:t.args},i=r.parameters[vs];typeof i=="string"&&(s.message=i);let a=ks(this.#t,s);if(this.#t.scrollTop=this.#t.scrollHeight,!await a){let c="User declined the action.";return n.settle(me.DECLINED,c),this.#f(),{content:c}}}let o=_s(r.parameters)&&this.navigate===null;o&&this.conversationStore.saveCheckpoint(this.#c,{toolCallId:t.id});try{let s=await r.handler(t.args);if(o)return n.settle(me.DONE,"Navigating\u2026"),{content:"",halt:!0};let i=JSON.stringify(s??null);return n.settle(me.DONE,i),this.#f(),{content:i}}catch(s){o&&this.conversationStore.saveCheckpoint(this.#c,null);let i=s instanceof Error?s.message:String(s);return n.settle(me.ERROR,i),this.#f(),{content:`Error: ${i}`,error:i}}}#B(){return{onRunStart:()=>{this.#o.disabled=!0,this.#f()},onTextDelta:t=>{this.#h(),this.#k(t)},onTextEnd:t=>{this.#y(this.#k(t)),this.#d=null},onToolCall:t=>{this.#h(),this.#A(t)},onRunEnd:()=>{this.#h(),this.#o.disabled=!1,this.#d=null},onError:t=>{this.#h(),this.#y(this.appendMessage(We.ASSISTANT,`\u26A0\uFE0F ${t}`)),this.#o.disabled=!1,this.#d=null}}}#f(){if(this.#m!==null)return;let t=document.createElement("div");t.className="pending",t.setAttribute("role","status"),t.setAttribute("aria-label","Assistant is thinking\u2026");for(let n=0;n<3;n+=1){let r=document.createElement("span");r.className="pending-dot",t.appendChild(r)}this.#m=t,this.#t.appendChild(t),this.#t.scrollTop=this.#t.scrollHeight}#h(){this.#m?.remove(),this.#m=null}#k(t){return this.#d===null&&(this.#d=this.appendMessage(We.ASSISTANT,"")),this.#d.innerHTML=Tr(t),this.#t.scrollTop=this.#t.scrollHeight,this.#d}#A(t){let n=this.#r.get(t.id);if(n!==void 0)return n;let r=this.#S(t.name)?.parameters[ys],o=new Gn(t.name,t.args,this.toolDisplay,typeof r=="string"?r:void 0);return this.#r.set(t.id,o),this.#t.appendChild(o.element),this.#t.scrollTop=this.#t.scrollHeight,o}};function Pm(){customElements.get(mr)===void 0&&customElements.define(mr,tr)}function qo(e,t){return Object.getOwnPropertyDescriptor(e,t).set}var Dm=qo(HTMLInputElement.prototype,"value"),Um=qo(HTMLTextAreaElement.prototype,"value"),Gm=qo(HTMLSelectElement.prototype,"value"),Fm=qo(HTMLInputElement.prototype,"checked");function Xt(e,t){e instanceof HTMLTextAreaElement?Um.call(e,t):e instanceof HTMLSelectElement?Gm.call(e,t):Dm.call(e,t)}function nr(e,t){Fm.call(e,t)}var jc="#4f46e5";function Jo(e){return new Promise(t=>{setTimeout(t,e)})}async function Ui(e,t,n={}){let r=n.charDelayMs??35;Xt(e,""),e.dispatchEvent(new Event("input",{bubbles:!0}));for(let o of t)Xt(e,e.value+o),e.dispatchEvent(new Event("input",{bubbles:!0})),r>0&&await Jo(r);e.dispatchEvent(new Event("change",{bubbles:!0}))}async function Gi(e,t={}){let n=t.highlightMs??280,r=e.style.outline,o=e.style.outlineOffset;e.style.outline=`2px solid ${jc}`,e.style.outlineOffset="2px",await Jo(n),e.style.outline=r,e.style.outlineOffset=o,e.click()}function Zt(e){e.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}async function Fi(e,t={}){let n=t.flashMs??200;e.focus();let r=e.style.boxShadow;e.style.boxShadow="0 0 0 3px rgba(79, 70, 229, 0.4)",await Jo(n),e.style.boxShadow=r}var Wc="0 0 0 3px rgba(79, 70, 229, 0.4)";function Xc(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function Hi(e){return e<=0||Xc()?Promise.resolve():Jo(e)}async function $i(e,t={}){let n=t.pressMs??140,r=e.style.transform,o=e.style.transition,s=e.style.boxShadow;e.style.transition="transform 80ms ease",e.style.transform="scale(0.96)",e.style.boxShadow=Wc,await Hi(n),e.style.transform=r,e.style.transition=o,e.style.boxShadow=s,e.click()}function Hm(e,t){for(let n of Array.from(e.options))if(n.value===t||n.text===t)return n;return null}async function zi(e,t,n={}){let r=Hm(e,t);if(r===null)throw new Error(`no <option> matching "${t}"`);let o=n.highlightMs??220,s=e.style.outline,i=e.style.outlineOffset;e.style.outline=`2px solid ${jc}`,e.style.outlineOffset="2px",await Hi(o),Xt(e,r.value),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),e.style.outline=s,e.style.outlineOffset=i}async function Bi(e,t,n={}){let r=n.flashMs??200,o=e.style.boxShadow;e.style.boxShadow=Wc,await Hi(r),nr(e,t),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),e.style.boxShadow=o}async function $m(e,t,n={}){Zt(e),await Fi(e,{flashMs:n.flashMs??0}),await Ui(e,t,n)}async function zm(e,t={}){Zt(e),await Gi(e,t)}async function Bm(e,t={}){Zt(e),await $i(e,t)}async function Vm(e,t,n={}){Zt(e),await zi(e,t,n)}async function jm(e,t,n={}){Zt(e),await Bi(e,t,n)}function Wm(e,t){e instanceof HTMLInputElement&&e.type==="checkbox"?nr(e,!!t):Xt(e,String(t)),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}var Xm="0.2.0";export{tr as AgUiChat,Qn as AgUiClient,Rn as ClientToolRegistry,mr as ELEMENT_TAG,bs as MAX_TOOL_ROUNDS,We as MESSAGE_ROLE,ms as SUBMIT_EVENT,er as SessionStorageStore,gs as TOGGLE_EVENT,me as TOOL_CALL_STATUS,Xe as TOOL_DISPLAY,Gn as ToolCallCard,Xm as VERSION,vs as X_CONFIRM_KEY,Cn as X_DESTRUCTIVE_KEY,Nn as X_NAVIGATES_KEY,ys as X_SUMMARY_KEY,zm as clickElement,Di as createHttpAgent,Ts as createPageMapContext,Ss as createRouteTools,ws as createStateHookTools,Pm as defineAgUiChat,$m as fillField,Fi as focusWithFlash,Gi as highlightThenClick,Es as isDestructive,_s as isNavigates,Xc as prefersReducedMotion,Bm as pressButton,$i as pressThenClick,Tr as renderMarkdown,ks as requestConfirmation,Zt as scrollIntoCenterView,Vm as selectControl,zi as selectOption,Wm as setControlValue,nr as setNativeChecked,Xt as setNativeValue,jm as toggleCheckbox,Bi as toggleControl,Ui as typeInto};
303
705
  /*! Bundled license information:
304
706
 
707
+ dompurify/dist/purify.es.mjs:
708
+ (*! @license DOMPurify 3.4.7 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.7/LICENSE *)
709
+
305
710
  fast-json-patch/module/helpers.mjs:
306
711
  (*!
307
712
  * https://github.com/Starcounter-Jack/JSON-Patch