@artooi/ag-ui-web-component 0.1.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 (65) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/LICENSE +21 -0
  3. package/README.md +471 -0
  4. package/dist/ag-ui-web-component.bundle.js +319 -0
  5. package/dist/ag-ui-web-component.bundle.js.map +7 -0
  6. package/dist/ag_ui_chat.d.ts +85 -0
  7. package/dist/ag_ui_chat.d.ts.map +1 -0
  8. package/dist/agui_client.d.ts +99 -0
  9. package/dist/agui_client.d.ts.map +1 -0
  10. package/dist/animations.d.ts +33 -0
  11. package/dist/animations.d.ts.map +1 -0
  12. package/dist/client_tool_registry.d.ts +32 -0
  13. package/dist/client_tool_registry.d.ts.map +1 -0
  14. package/dist/confirmation_modal.d.ts +14 -0
  15. package/dist/confirmation_modal.d.ts.map +1 -0
  16. package/dist/constants.d.ts +40 -0
  17. package/dist/constants.d.ts.map +1 -0
  18. package/dist/conversation_store.d.ts +54 -0
  19. package/dist/conversation_store.d.ts.map +1 -0
  20. package/dist/create_http_agent.d.ts +22 -0
  21. package/dist/create_http_agent.d.ts.map +1 -0
  22. package/dist/define_ag_ui_chat.d.ts +9 -0
  23. package/dist/define_ag_ui_chat.d.ts.map +1 -0
  24. package/dist/dom_driver.d.ts +24 -0
  25. package/dist/dom_driver.d.ts.map +1 -0
  26. package/dist/index.d.ts +18 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +1159 -0
  29. package/dist/index.js.map +7 -0
  30. package/dist/is_destructive.d.ts +8 -0
  31. package/dist/is_destructive.d.ts.map +1 -0
  32. package/dist/is_navigates.d.ts +9 -0
  33. package/dist/is_navigates.d.ts.map +1 -0
  34. package/dist/page_map.d.ts +16 -0
  35. package/dist/page_map.d.ts.map +1 -0
  36. package/dist/route_map.d.ts +27 -0
  37. package/dist/route_map.d.ts.map +1 -0
  38. package/dist/state_hook.d.ts +23 -0
  39. package/dist/state_hook.d.ts.map +1 -0
  40. package/dist/styles.d.ts +2 -0
  41. package/dist/styles.d.ts.map +1 -0
  42. package/dist/tool_call_card.d.ts +29 -0
  43. package/dist/tool_call_card.d.ts.map +1 -0
  44. package/dist/version.d.ts +2 -0
  45. package/dist/version.d.ts.map +1 -0
  46. package/package.json +79 -0
  47. package/src/ag_ui_chat.ts +411 -0
  48. package/src/agui_client.ts +212 -0
  49. package/src/animations.ts +86 -0
  50. package/src/client_tool_registry.ts +56 -0
  51. package/src/confirmation_modal.ts +69 -0
  52. package/src/constants.ts +48 -0
  53. package/src/conversation_store.ts +103 -0
  54. package/src/create_http_agent.ts +40 -0
  55. package/src/define_ag_ui_chat.ts +15 -0
  56. package/src/dom_driver.ts +60 -0
  57. package/src/index.ts +60 -0
  58. package/src/is_destructive.ts +11 -0
  59. package/src/is_navigates.ts +12 -0
  60. package/src/page_map.ts +25 -0
  61. package/src/route_map.ts +83 -0
  62. package/src/state_hook.ts +44 -0
  63. package/src/styles.ts +296 -0
  64. package/src/tool_call_card.ts +95 -0
  65. package/src/version.ts +1 -0
@@ -0,0 +1,319 @@
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=`
12
+ :host {
13
+ /* Colors */
14
+ --ag-ui-bg: #ffffff;
15
+ --ag-ui-fg: #1a1a2e;
16
+ --ag-ui-accent: #4f46e5;
17
+ --ag-ui-user-bg: #4f46e5;
18
+ --ag-ui-user-fg: #ffffff;
19
+ --ag-ui-assistant-bg: #f1f1f6;
20
+ --ag-ui-input-bg: var(--ag-ui-bg);
21
+ --ag-ui-tool-bg: var(--ag-ui-assistant-bg);
22
+ --ag-ui-tool-fg: var(--ag-ui-accent);
23
+ --ag-ui-header-bg: var(--ag-ui-accent);
24
+ --ag-ui-header-fg: #ffffff;
25
+ --ag-ui-border: #e2e2ec;
26
+ --ag-ui-radius: 12px;
27
+
28
+ /* Status accents for tool-call cards. */
29
+ --ag-ui-success: #15803d;
30
+ --ag-ui-danger: #b91c1c;
31
+ --ag-ui-muted: #6b7280;
32
+
33
+ /* Surface \u2014 set --ag-ui-shadow: none for a flush, embedded panel. */
34
+ --ag-ui-shadow: 0 12px 32px rgba(20, 20, 50, 0.18);
35
+ --ag-ui-font: inherit;
36
+ --ag-ui-font-size: 14px;
37
+
38
+ /* Layout \u2014 override from outside to dock the widget anywhere.
39
+ Set --ag-ui-position: static (and place this element in your own
40
+ grid/flex layout) to embed it in the page flow instead of floating. */
41
+ --ag-ui-position: fixed;
42
+ --ag-ui-z-index: 2147483000;
43
+ --ag-ui-width: 380px;
44
+ --ag-ui-height: 560px;
45
+ --ag-ui-inset: auto 24px 24px auto;
46
+ --ag-ui-max-width: calc(100vw - 48px);
47
+ --ag-ui-max-height: calc(100vh - 48px);
48
+
49
+ position: var(--ag-ui-position);
50
+ inset: var(--ag-ui-inset);
51
+ z-index: var(--ag-ui-z-index);
52
+ width: var(--ag-ui-width);
53
+ max-width: var(--ag-ui-max-width);
54
+ height: var(--ag-ui-height);
55
+ max-height: var(--ag-ui-max-height);
56
+ display: flex;
57
+ font-family: var(--ag-ui-font);
58
+ font-size: var(--ag-ui-font-size);
59
+ color: var(--ag-ui-fg);
60
+ }
61
+
62
+ .chat {
63
+ position: relative;
64
+ display: flex;
65
+ flex-direction: column;
66
+ flex: 1;
67
+ min-height: 0;
68
+ background: var(--ag-ui-bg);
69
+ border: 1px solid var(--ag-ui-border);
70
+ border-radius: var(--ag-ui-radius);
71
+ box-shadow: var(--ag-ui-shadow);
72
+ overflow: hidden;
73
+ }
74
+
75
+ .header {
76
+ padding: 12px 16px;
77
+ font-weight: 600;
78
+ border-bottom: 1px solid var(--ag-ui-border);
79
+ background: var(--ag-ui-header-bg);
80
+ color: var(--ag-ui-header-fg);
81
+ }
82
+
83
+ .messages {
84
+ flex: 1;
85
+ overflow-y: auto;
86
+ padding: 16px;
87
+ display: flex;
88
+ flex-direction: column;
89
+ gap: 10px;
90
+ }
91
+
92
+ .message {
93
+ max-width: 80%;
94
+ padding: 8px 12px;
95
+ border-radius: 14px;
96
+ line-height: 1.4;
97
+ white-space: pre-wrap;
98
+ word-break: break-word;
99
+ }
100
+
101
+ .message--user {
102
+ align-self: flex-end;
103
+ background: var(--ag-ui-user-bg);
104
+ color: var(--ag-ui-user-fg);
105
+ border-bottom-right-radius: 4px;
106
+ }
107
+
108
+ .message--assistant {
109
+ align-self: flex-start;
110
+ background: var(--ag-ui-assistant-bg);
111
+ border-bottom-left-radius: 4px;
112
+ }
113
+
114
+ .tool-call {
115
+ align-self: flex-start;
116
+ max-width: 80%;
117
+ box-sizing: border-box;
118
+ display: flex;
119
+ flex-direction: column;
120
+ gap: 6px;
121
+ font-size: 12px;
122
+ font-family: ui-monospace, "SF Mono", Menlo, monospace;
123
+ padding: 8px 10px;
124
+ border-radius: 8px;
125
+ background: var(--ag-ui-tool-bg);
126
+ border: 1px solid var(--ag-ui-border);
127
+ color: var(--ag-ui-tool-fg);
128
+ }
129
+
130
+ .tool-call-head {
131
+ display: flex;
132
+ align-items: center;
133
+ justify-content: space-between;
134
+ gap: 8px;
135
+ }
136
+
137
+ .tool-call-name {
138
+ font-weight: 600;
139
+ word-break: break-word;
140
+ }
141
+
142
+ .tool-call-status {
143
+ flex: none;
144
+ padding: 1px 8px;
145
+ border-radius: 999px;
146
+ font-size: 11px;
147
+ font-weight: 600;
148
+ background: rgba(127, 127, 127, 0.16);
149
+ color: var(--ag-ui-muted);
150
+ }
151
+
152
+ .tool-call[data-status="done"] .tool-call-status {
153
+ color: var(--ag-ui-success);
154
+ }
155
+
156
+ .tool-call[data-status="error"] .tool-call-status {
157
+ color: var(--ag-ui-danger);
158
+ }
159
+
160
+ .tool-call[data-status="declined"] .tool-call-status {
161
+ color: var(--ag-ui-muted);
162
+ }
163
+
164
+ .tool-call-args,
165
+ .tool-call-result {
166
+ margin: 0;
167
+ padding: 6px 8px;
168
+ max-height: 160px;
169
+ overflow: auto;
170
+ background: var(--ag-ui-bg);
171
+ border: 1px solid var(--ag-ui-border);
172
+ border-radius: 6px;
173
+ white-space: pre-wrap;
174
+ word-break: break-word;
175
+ color: var(--ag-ui-fg);
176
+ }
177
+
178
+ .tool-call-toggle {
179
+ align-self: flex-start;
180
+ border: none;
181
+ padding: 0;
182
+ background: none;
183
+ font: inherit;
184
+ font-weight: 600;
185
+ color: var(--ag-ui-accent);
186
+ cursor: pointer;
187
+ }
188
+
189
+ .tool-call-toggle::before {
190
+ content: "\u25B8 ";
191
+ }
192
+
193
+ .tool-call-toggle[aria-expanded="true"]::before {
194
+ content: "\u25BE ";
195
+ }
196
+
197
+ .input-row {
198
+ display: flex;
199
+ gap: 8px;
200
+ padding: 12px;
201
+ border-top: 1px solid var(--ag-ui-border);
202
+ }
203
+
204
+ .input {
205
+ flex: 1;
206
+ resize: none;
207
+ background: var(--ag-ui-input-bg);
208
+ border: 1px solid var(--ag-ui-border);
209
+ border-radius: 8px;
210
+ padding: 8px 10px;
211
+ font: inherit;
212
+ color: inherit;
213
+ outline: none;
214
+ }
215
+
216
+ .input:focus {
217
+ border-color: var(--ag-ui-accent);
218
+ }
219
+
220
+ .send {
221
+ border: none;
222
+ border-radius: 8px;
223
+ padding: 0 16px;
224
+ background: var(--ag-ui-accent);
225
+ color: #ffffff;
226
+ font: inherit;
227
+ font-weight: 600;
228
+ cursor: pointer;
229
+ }
230
+
231
+ .send:disabled {
232
+ opacity: 0.5;
233
+ cursor: default;
234
+ }
235
+
236
+ .modal-overlay {
237
+ position: absolute;
238
+ inset: 0;
239
+ 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;
250
+ background: var(--ag-ui-bg);
251
+ border-radius: 12px;
252
+ box-shadow: 0 16px 40px rgba(20, 20, 50, 0.3);
253
+ overflow: hidden;
254
+ }
255
+
256
+ .modal-title {
257
+ padding: 12px 16px;
258
+ font-weight: 600;
259
+ border-bottom: 1px solid var(--ag-ui-border);
260
+ }
261
+
262
+ .modal-body {
263
+ padding: 12px 16px 4px;
264
+ }
265
+
266
+ .modal-args {
267
+ margin: 0 16px 12px;
268
+ padding: 8px 10px;
269
+ max-height: 140px;
270
+ overflow: auto;
271
+ font-size: 12px;
272
+ font-family: ui-monospace, "SF Mono", Menlo, monospace;
273
+ background: var(--ag-ui-assistant-bg);
274
+ border-radius: 8px;
275
+ white-space: pre-wrap;
276
+ word-break: break-word;
277
+ }
278
+
279
+ .modal-actions {
280
+ display: flex;
281
+ gap: 8px;
282
+ padding: 0 16px 16px;
283
+ justify-content: flex-end;
284
+ }
285
+
286
+ .modal-btn {
287
+ border: 1px solid var(--ag-ui-border);
288
+ border-radius: 8px;
289
+ padding: 8px 14px;
290
+ font: inherit;
291
+ font-weight: 600;
292
+ cursor: pointer;
293
+ background: var(--ag-ui-bg);
294
+ color: var(--ag-ui-fg);
295
+ }
296
+
297
+ .modal-btn--confirm {
298
+ border-color: var(--ag-ui-accent);
299
+ background: var(--ag-ui-accent);
300
+ color: #ffffff;
301
+ }
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};
303
+ /*! Bundled license information:
304
+
305
+ fast-json-patch/module/helpers.mjs:
306
+ (*!
307
+ * https://github.com/Starcounter-Jack/JSON-Patch
308
+ * (c) 2017-2022 Joachim Wester
309
+ * MIT licensed
310
+ *)
311
+
312
+ fast-json-patch/module/duplex.mjs:
313
+ (*!
314
+ * https://github.com/Starcounter-Jack/JSON-Patch
315
+ * (c) 2017-2021 Joachim Wester
316
+ * MIT license
317
+ *)
318
+ */
319
+ //# sourceMappingURL=ag-ui-web-component.bundle.js.map