@shumai-one/shumai-agent 0.4.2 → 0.4.4

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 (104) hide show
  1. package/bin/chunk-07a5rjnq.js +2 -0
  2. package/bin/chunk-1a493esq.js +2 -0
  3. package/bin/chunk-1y3q1jce.js +2 -0
  4. package/bin/chunk-2mcnt6jh.js +8 -0
  5. package/bin/chunk-33n9p9q4.js +3 -0
  6. package/bin/chunk-40bcg5we.js +2 -0
  7. package/bin/chunk-4926dhzq.js +4 -0
  8. package/bin/chunk-4q9h14c1.js +3 -0
  9. package/bin/chunk-5n4wvh5p.js +3 -0
  10. package/bin/chunk-6195gx01.js +8 -0
  11. package/bin/chunk-8jd9p0bt.js +45 -0
  12. package/bin/chunk-8tj47emj.js +2 -0
  13. package/bin/chunk-9bpp5v13.js +13320 -0
  14. package/bin/chunk-a4xcn19j.js +3 -0
  15. package/bin/chunk-as1vqgag.js +2 -0
  16. package/bin/chunk-b2205272.js +3 -0
  17. package/bin/chunk-bbz8hcag.js +2 -0
  18. package/bin/chunk-cwq65x99.js +2 -0
  19. package/bin/chunk-dc4f80kq.js +2 -0
  20. package/bin/chunk-e7m6nsvr.js +3 -0
  21. package/bin/chunk-edkxjkdy.js +2 -0
  22. package/bin/chunk-fvz08he3.js +2 -0
  23. package/bin/chunk-gekdwjxf.js +2 -0
  24. package/bin/chunk-gqtret3n.js +2 -0
  25. package/bin/chunk-grtavkr4.js +3 -0
  26. package/bin/chunk-h65eqsrp.js +7 -0
  27. package/bin/chunk-hbmbvjjq.js +3 -0
  28. package/bin/chunk-jkx975yd.js +2 -0
  29. package/bin/chunk-jt36jdn3.js +2 -0
  30. package/bin/chunk-k975ym8c.js +7 -0
  31. package/bin/chunk-kd561cva.js +2 -0
  32. package/bin/chunk-m8jmvj7p.js +3 -0
  33. package/bin/chunk-nmxr1m3s.js +2 -0
  34. package/bin/chunk-nwjh8gnr.js +3 -0
  35. package/bin/chunk-s1e2nv5w.js +5 -0
  36. package/bin/chunk-sbtjx4y3.js +2 -0
  37. package/bin/chunk-sfx1j3yr.js +11 -0
  38. package/bin/chunk-sq5rat8t.js +2 -0
  39. package/bin/chunk-td2tpqfb.js +12 -0
  40. package/bin/chunk-tdah647g.js +13 -0
  41. package/bin/chunk-vnn8sej7.js +24 -0
  42. package/bin/chunk-vv932dz6.js +2 -0
  43. package/bin/chunk-vvvkt1vd.js +2 -0
  44. package/bin/chunk-wdvv14a7.js +2 -0
  45. package/bin/chunk-wg6xrc3y.js +3 -0
  46. package/bin/chunk-wzysrq4c.js +16 -0
  47. package/bin/chunk-xp2anj2s.js +3 -0
  48. package/bin/chunk-y2adfzyt.js +2 -0
  49. package/bin/chunk-zdkpvcak.js +4 -0
  50. package/bin/shumai-agent-app.js +912 -666
  51. package/package.json +18 -18
  52. package/prisma/migrations/20260904022457_add_agent_id_to_assets_and_audit_logs/migration.sql +17 -0
  53. package/prisma/migrations/20260906081230_default_denied_tools_delete_asset/migration.sql +15 -0
  54. package/prisma/migrations/20260907021754_add_asset_upload_id/migration.sql +2 -0
  55. package/prisma/schema.prisma +10 -0
  56. package/bin/chunk-1ep7nnzp.js +0 -5
  57. package/bin/chunk-1jq2vgrd.js +0 -3
  58. package/bin/chunk-2ntm65jn.js +0 -3
  59. package/bin/chunk-3nh1p64q.js +0 -12
  60. package/bin/chunk-41gh01qj.js +0 -3
  61. package/bin/chunk-4n1309xp.js +0 -2
  62. package/bin/chunk-616f7y5x.js +0 -8
  63. package/bin/chunk-6a9h5d64.js +0 -3
  64. package/bin/chunk-6dp3ybh2.js +0 -3
  65. package/bin/chunk-6nd8f70y.js +0 -4
  66. package/bin/chunk-6vs3gb9g.js +0 -2
  67. package/bin/chunk-7dyx5m0f.js +0 -6
  68. package/bin/chunk-7j3qbvwc.js +0 -7
  69. package/bin/chunk-9h5qhgqx.js +0 -13
  70. package/bin/chunk-b9s67nd8.js +0 -2
  71. package/bin/chunk-c14kvr2r.js +0 -11
  72. package/bin/chunk-cb5p7shk.js +0 -12240
  73. package/bin/chunk-ccx6803n.js +0 -44
  74. package/bin/chunk-cm4dpd3k.js +0 -4
  75. package/bin/chunk-dd2tfwzy.js +0 -45
  76. package/bin/chunk-dk9vz5tv.js +0 -4
  77. package/bin/chunk-e6691p0v.js +0 -3
  78. package/bin/chunk-e9d2ah8y.js +0 -3
  79. package/bin/chunk-fvmb8en4.js +0 -24
  80. package/bin/chunk-gegf6d3m.js +0 -2
  81. package/bin/chunk-gx9vdcbm.js +0 -2
  82. package/bin/chunk-j427r7a5.js +0 -2
  83. package/bin/chunk-jperx2a8.js +0 -6
  84. package/bin/chunk-k4jm2gt4.js +0 -3
  85. package/bin/chunk-m29dphbf.js +0 -3
  86. package/bin/chunk-mpgy1y53.js +0 -3
  87. package/bin/chunk-n1t3he2k.js +0 -3
  88. package/bin/chunk-pmdb6y7t.js +0 -2
  89. package/bin/chunk-qx9njyk7.js +0 -3
  90. package/bin/chunk-r5h7vczc.js +0 -3
  91. package/bin/chunk-spm76160.js +0 -2
  92. package/bin/chunk-t8k09sgb.js +0 -3
  93. package/bin/chunk-tvef1ck8.js +0 -2
  94. package/bin/chunk-v4j6yxch.js +0 -3
  95. package/bin/chunk-vjzrmneg.js +0 -2
  96. package/bin/chunk-x25enwfz.js +0 -3
  97. package/bin/chunk-xg9xscqz.js +0 -1
  98. package/bin/chunk-xqg06q7q.js +0 -2
  99. package/bin/chunk-xvbd9e2b.js +0 -8
  100. package/bin/chunk-y2z3xj0m.js +0 -12
  101. package/bin/chunk-ywhrsshf.js +0 -2
  102. package/bin/chunk-z512b49m.js +0 -3
  103. package/bin/chunk-z58rb52r.js +0 -3
  104. package/bin/chunk-zazbsz25.js +0 -3
@@ -0,0 +1,3 @@
1
+ // @bun
2
+ function d(e){return e.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g,"")}function We(e,n,t){let r=n[t];if(typeof r!=="string")throw Error(`Grammar tool call "${e}" requires argument "${t}" to be a string.`);return r}function He(e,n,t,r){if(e.closed){if(r&&t===e.input)return;throw Error(`grammar tool input for property "${n}" changed after it was closed`)}if(!t.startsWith(e.input))throw Error(`grammar tool input for property "${n}" changed non-monotonically`);let o=t.slice(e.input.length);if(!r&&o.length===0)return;let i="";if(!e.started)i+=`{${JSON.stringify(n)}:"`,e.started=!0;if(i+=JSON.stringify(o).slice(1,-1),e.input=t,r)i+='"}',e.closed=!0;return i}function D(e){let n=e.parameters;if(n.type!=="object")throw Error("grammar constrained sampling requires an object parameter schema");if(!Array.isArray(n.required)||n.required.length!==1||typeof n.required[0]!=="string")throw Error("grammar constrained sampling requires exactly one required string property");let t=n.required[0];if(!n.properties?.[t])throw Error(`grammar constrained sampling requires a properties entry for ${t}`);if(n.properties[t]?.type!=="string")throw Error(`grammar constrained sampling property ${t} must have type string`);return t}function M(e,n){let t=e.constrainedSampling;if(!t||t.type!=="json_schema")return;if(n)return!0;if(t.strict==="require")throw Error(`Tool "${e.name}" requires JSON-schema constrained sampling, but strict tools are unsupported.`);return}function Ue(e,n){let t=e.constrainedSampling;if(!t||t.type!=="grammar")return;if(!n)return;let r=t.variants.openai_lark,o=t.variants.openai_regex,i=typeof r==="string"&&r.trim().length>0,m=typeof o==="string"&&o.trim().length>0;if(!i&&!m)throw Error(`Tool "${e.name}" cannot use grammar constrained sampling: no supported grammar variant was provided.`);try{return{format:i?"lark":"regex",definition:i?r:o,inputProperty:D(e)}}catch(l){let c=l instanceof Error?l.message:String(l);throw Error(`Tool "${e.name}" cannot use grammar constrained sampling: ${c}.`)}}function L(e,n){let t=new Map;for(let r of e??[]){let o=Ue(r,n);if(o)t.set(r.name,o.inputProperty)}return t}function k(e){return e.totalTokens||e.input+e.output+e.cacheRead+e.cacheWrite}function w(e){try{return JSON.stringify(e)??"undefined"}catch{return"[unserializable]"}}function P(e){if(typeof e==="string")return e.length;let n=0;for(let t of e)n+=t.type==="text"?t.text.length:4800;return n}function _(e){return Math.ceil(e.length/4)}function I(e){return Math.ceil(P(e)/4)}function E(e){let n=0;if(e.role==="user")return I(e.content);if(e.role==="toolResult")return I(e.content);for(let t of e.content)if(t.type==="text")n+=t.text.length;else if(t.type==="thinking")n+=t.thinking.length;else n+=t.name.length+w(t.arguments).length;return Math.ceil(n/4)}function v(e){let n=Number.NEGATIVE_INFINITY,t;for(let r=0;r<e.length;r++){let o=e[r];if(o.role==="assistant"){let i=o;if(i.timestamp>=n&&i.stopReason!=="aborted"&&i.stopReason!=="error"&&k(i.usage)>0)t={usage:i.usage,index:r}}n=Math.max(n,o.timestamp)}return t}function R(e){let n=v(e);if(n){let r=k(n.usage),o=0;for(let i=n.index+1;i<e.length;i++)o+=E(e[i]);return{tokens:r+o,usageTokens:r,trailingTokens:o,lastUsageIndex:n.index}}let t=0;for(let r of e)t+=E(r);return{tokens:t,usageTokens:0,trailingTokens:t,lastUsageIndex:null}}function S(e){if(!e||e.length===0)return 0;return _(w(e))}function F(e){return Array.isArray(e)}function A(e){if(F(e))return R(e);let n=R(e.messages);if(n.lastUsageIndex!==null){let r=new Set(e.messages.slice(n.lastUsageIndex+1).filter((i)=>i.role==="toolResult").flatMap((i)=>i.addedToolNames??[])),o=S(e.tools?.filter((i)=>r.has(i.name)));return{tokens:n.tokens+o,usageTokens:n.usageTokens,trailingTokens:n.trailingTokens+o,lastUsageIndex:n.lastUsageIndex}}let t=(e.systemPrompt?_(e.systemPrompt):0)+S(e.tools);return{tokens:n.tokens+t,usageTokens:n.usageTokens,trailingTokens:n.trailingTokens+t,lastUsageIndex:n.lastUsageIndex}}var G=4096,C=1;function dt(e,n,t){if(e.contextWindow<=0)return Math.max(C,t);let r=e.contextWindow-A(n).tokens-G;return Math.min(t,Math.max(C,r))}function B(e,n,t,r){return{temperature:t?.temperature,maxTokens:dt(e,n,t?.maxTokens??e.maxTokens),signal:t?.signal,apiKey:r||t?.apiKey,transport:t?.transport,cacheRetention:t?.cacheRetention,sessionId:t?.sessionId,headers:t?.headers,onPayload:t?.onPayload,onResponse:t?.onResponse,timeoutMs:t?.timeoutMs,websocketConnectTimeoutMs:t?.websocketConnectTimeoutMs,maxRetries:t?.maxRetries,maxRetryDelayMs:t?.maxRetryDelayMs,metadata:t?.metadata,env:t?.env}}function U(e){return e==="xhigh"||e==="max"?"high":e}function _t(e,n,t,r){let i={...{minimal:1024,low:2048,medium:8192,high:16384},...r},m=1024,l=U(t),c=i[l],f=e===void 0?n:Math.min(e+c,n);if(f<=c)c=Math.max(0,f-1024);return{maxTokens:f,thinkingBudget:c}}function N(e,n){let t=[],r=!1;for(let o of e){if(o.type==="image"){if(!r)t.push({type:"text",text:n});r=!0;continue}t.push(o),r=o.text===n}return t}function q(e,n){if(n.input.includes("image"))return e;return e.map((t)=>{if(t.role==="user"&&Array.isArray(t.content))return{...t,content:N(t.content,"(image omitted: model does not support images)")};if(t.role==="toolResult")return{...t,content:N(t.content,"(tool image omitted: model does not support images)")};return t})}function O(e,n,t){let r=new Map,o=e.map((a)=>a.content==null?{...a,content:[]}:a),m=q(o,n).map((a)=>{if(a.role==="user")return a;if(a.role==="toolResult"){let s=r.get(a.toolCallId);if(s&&s!==a.toolCallId)return{...a,toolCallId:s};return a}if(a.role==="assistant"){let s=a,p=s.provider===n.provider&&s.api===n.api&&s.model===n.id,T=s.content.flatMap((u)=>{if(u.type==="thinking"){if(u.redacted)return p?u:[];if(p&&u.thinkingSignature)return u;if(!u.thinking||u.thinking.trim()==="")return[];if(p)return u;return{type:"text",text:u.thinking}}if(u.type==="text"){if(p)return u;return{type:"text",text:u.text}}if(u.type==="toolCall"){let g=u,h=g;if(!p&&g.thoughtSignature)h={...g},delete h.thoughtSignature;if(!p&&t){let y=t(g.id,n,s);if(y!==g.id)r.set(g.id,y),h={...h,id:y}}return h}return u});return{...s,content:T}}return a}),l=[],c=[],f=new Set,x=()=>{if(c.length>0){for(let a of c)if(!f.has(a.id))l.push({role:"toolResult",toolCallId:a.id,toolName:a.name,content:[{type:"text",text:"No result provided"}],isError:!0,timestamp:Date.now()});c=[],f=new Set}};for(let a=0;a<m.length;a++){let s=m[a];if(s.role==="assistant"){x();let p=s;if(p.stopReason==="error"||p.stopReason==="aborted")continue;let T=p.content.filter((u)=>u.type==="toolCall");if(T.length>0)c=T,f=new Set;l.push(s)}else if(s.role==="toolResult")f.add(s.toolCallId),l.push(s);else if(s.role==="user")x(),l.push(s);else l.push(s)}return x(),l}
3
+ export{d,We,He,M,Ue,L,dt,B,_t,O};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ var zr=Object.create;var{getPrototypeOf:Vr,defineProperty:wt,getOwnPropertyNames:Gr}=Object;var qt=Object.prototype.hasOwnProperty;function Fr(e){return this[e]}var Xr,Yr,i=(e,t,r)=>{var o=e!=null&&typeof e==="object";if(o){var s=t?Xr??=new WeakMap:Yr??=new WeakMap,p=s.get(e);if(p)return p}r=e!=null?zr(Vr(e)):{};let c=t||!e||!e.__esModule||!qt.call(e,"default")?wt(r,"default",{value:e,enumerable:!0}):r;if(e&&typeof e==="object"||typeof e==="function"){for(let d of Gr(e))if(!qt.call(c,d))wt(c,d,{get:Fr.bind(e,d),enumerable:!0})}if(o)s.set(e,c);return c};var n=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var qr=(e)=>e;function Zr(e,t){this[e]=qr.bind(null,t)}var te=(e,t)=>{for(var r in t)wt(e,r,{get:t[r],enumerable:!0,configurable:!0,set:Zr.bind(t,r)})};var a=import.meta.require;var Je=new TextEncoder,ae=new TextDecoder,fe=new TextDecoder("utf-8",{fatal:!0});function W(...e){let t=e.reduce((s,{length:p})=>s+p,0),r=new Uint8Array(t),o=0;for(let s of e)r.set(s,o),o+=s.length;return r}function gt(e,t,r){if(t<0||t>=4294967296)throw RangeError(`value must be >= 0 and <= 4294967295. Received ${t}`);e.set([t>>>24,t>>>16,t>>>8,t&255],r)}function Et(e){let t=Math.floor(e/4294967296),r=e%4294967296,o=new Uint8Array(8);return gt(o,t,0),gt(o,r,4),o}function ke(e){let t=new Uint8Array(4);return gt(t,e),t}function K(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++){let o=e.charCodeAt(r);if(o>127)throw TypeError("non-ASCII string encountered in encode()");t[r]=o}return t}var Be=(e,t="algorithm.name")=>TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);function bt(e,t){if(t&&!e.usages.includes(t))throw TypeError(`CryptoKey does not support this operation, its usages must include ${t}.`)}function Me(e,t){let{modulusLength:r}=t.algorithm;if(typeof r!=="number"||r<2048)throw TypeError(`${e} requires key modulusLength to be 2048 bits or larger`)}function V(e,t,r){let o=e.algorithm;if(o.name!==t.name)throw Be(t.name);if(t.hash&&o.hash?.name!==t.hash)throw Be(t.hash,"algorithm.hash");if(t.namedCurve&&o.namedCurve!==t.namedCurve)throw Be(t.namedCurve,"algorithm.namedCurve");if(t.length!==void 0&&o.length!==t.length)throw Be(t.length,"algorithm.length");bt(e,r)}function Zt(e,t,...r){if(r.length>2){let o=r.pop();e+=`one of type ${r.join(", ")}, or ${o}.`}else if(r.length===2)e+=`one of type ${r[0]} or ${r[1]}.`;else e+=`of type ${r[0]}.`;if(t==null)e+=` Received ${t}`;else if(typeof t==="function"&&t.name)e+=` Received function ${t.name}`;else if(typeof t==="object"&&t!=null){if(t.constructor?.name)e+=` Received an instance of ${t.constructor.name}`}return e}var G=(e,...t)=>Zt("Key must be ",e,...t),We=(e,t,...r)=>Zt(`Key for the ${e} algorithm must be `,t,...r);class v extends Error{static code="ERR_JOSE_GENERIC";code="ERR_JOSE_GENERIC";constructor(e,t){super(e,t);this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}}class k extends v{static code="ERR_JWT_CLAIM_VALIDATION_FAILED";code="ERR_JWT_CLAIM_VALIDATION_FAILED";claim;reason;payload;constructor(e,t,r="unspecified",o="unspecified"){super(e,{cause:{claim:r,reason:o,payload:t}});this.claim=r,this.reason=o,this.payload=t}}class Fe extends v{static code="ERR_JWT_EXPIRED";code="ERR_JWT_EXPIRED";claim;reason;payload;constructor(e,t,r="unspecified",o="unspecified"){super(e,{cause:{claim:r,reason:o,payload:t}});this.claim=r,this.reason=o,this.payload=t}}class ue extends v{static code="ERR_JOSE_ALG_NOT_ALLOWED";code="ERR_JOSE_ALG_NOT_ALLOWED"}class w extends v{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"}class Le extends v{static code="ERR_JWE_DECRYPTION_FAILED";code="ERR_JWE_DECRYPTION_FAILED";constructor(e="decryption operation failed",t){super(e,t)}}class m extends v{static code="ERR_JWE_INVALID";code="ERR_JWE_INVALID"}class b extends v{static code="ERR_JWS_INVALID";code="ERR_JWS_INVALID"}class A extends v{static code="ERR_JWT_INVALID";code="ERR_JWT_INVALID"}class je extends v{static code="ERR_JWK_INVALID";code="ERR_JWK_INVALID"}class ze extends v{static code="ERR_JWKS_INVALID";code="ERR_JWKS_INVALID"}class Ce extends v{static code="ERR_JWKS_NO_MATCHING_KEY";code="ERR_JWKS_NO_MATCHING_KEY";constructor(e="no applicable key found in the JSON Web Key Set",t){super(e,t)}}class At extends v{[Symbol.asyncIterator]=async function*(){};static code="ERR_JWKS_MULTIPLE_MATCHING_KEYS";code="ERR_JWKS_MULTIPLE_MATCHING_KEYS";constructor(e="multiple matching keys found in the JSON Web Key Set",t){super(e,t)}}class Kt extends v{static code="ERR_JWKS_TIMEOUT";code="ERR_JWKS_TIMEOUT";constructor(e="request timed out",t){super(e,t)}}class Jt extends v{static code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";constructor(e="signature verification failed",t){super(e,t)}}function Ve(e){if(!F(e))throw Error("CryptoKey instance expected")}var F=(e)=>{if(e?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return e instanceof CryptoKey}catch{return!1}},Wt=(e)=>e?.[Symbol.toStringTag]==="KeyObject",Ge=(e)=>F(e)||Wt(e);var X=(e)=>crypto.getRandomValues(new Uint8Array(e.cekBits>>3));function Qt(e,t){let r=e.byteLength<<3;if(r!==t)throw new m(`Invalid Content Encryption Key length. Expected ${t} bits, got ${r} bits`)}var Qr=(e)=>crypto.getRandomValues(new Uint8Array(e.ivBits>>3));function er(e,t){if(t.length<<3!==e.ivBits)throw new m("Invalid Initialization Vector length")}async function tr(e,t,r){if(!(t instanceof Uint8Array))throw TypeError(G(t,"Uint8Array"));let o=e.cekBits>>1,s=await crypto.subtle.importKey("raw",t.subarray(o>>3),"AES-CBC",!1,[r]),p=await crypto.subtle.importKey("raw",t.subarray(0,o>>3),{hash:`SHA-${o<<1}`,name:"HMAC"},!1,["sign"]);return[s,p,o]}async function rr(e,t,r){return new Uint8Array((await crypto.subtle.sign("HMAC",e,t)).slice(0,r>>3))}async function en(e,t,r,o,s){let[p,c,d]=await tr(e,r,"encrypt"),f=new Uint8Array(await crypto.subtle.encrypt({iv:o,name:"AES-CBC"},p,t)),u=W(s,o,f,Et(s.length*8)),l=await rr(c,u,d);return{ciphertext:f,tag:l,iv:o}}async function tn(e,t){let r={name:"HMAC",hash:"SHA-256"},o=await crypto.subtle.generateKey(r,!1,["sign","verify"]),s=await crypto.subtle.sign(r,o,e);return crypto.subtle.verify(r,o,s,t)}async function rn(e,t,r,o,s,p){let[c,d,f]=await tr(e,t,"decrypt"),u=W(p,o,r,Et(p.length*8)),l=await rr(d,u,f);try{if(await tn(s,l))return new Uint8Array(await crypto.subtle.decrypt({iv:o,name:"AES-CBC"},c,r))}catch{}throw new Le}async function nn(e,t,r,o,s){let p=r instanceof Uint8Array?await crypto.subtle.importKey("raw",r,"AES-GCM",!1,["encrypt"]):(V(r,e.subtle,"encrypt"),r),c=new Uint8Array(await crypto.subtle.encrypt({additionalData:s,iv:o,name:"AES-GCM",tagLength:128},p,t)),d=c.slice(-16);return{ciphertext:c.slice(0,-16),tag:d,iv:o}}async function on(e,t,r,o,s,p){let c=t instanceof Uint8Array?await crypto.subtle.importKey("raw",t,"AES-GCM",!1,["decrypt"]):(V(t,e.subtle,"decrypt"),t);try{return new Uint8Array(await crypto.subtle.decrypt({additionalData:p,iv:o,name:"AES-GCM",tagLength:128},c,W(r,s)))}catch{throw new Le}}async function Xe(e,t,r,o,s){if(!F(r)&&!(r instanceof Uint8Array))throw TypeError(G(r,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(o)er(e,o);else o=Qr(e);if(r instanceof Uint8Array)Qt(r,e.cekBits);return e.cbc?en(e,t,r,o,s):nn(e,t,r,o,s)}async function Ye(e,t,r,o,s,p){if(!F(t)&&!(t instanceof Uint8Array))throw TypeError(G(t,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(!o)throw new m("JWE Initialization Vector missing");if(!s)throw new m("JWE Authentication Tag missing");if(!e.cbc&&s.length!==16)throw new m("Invalid Authentication Tag length");if(er(e,o),t instanceof Uint8Array)Qt(t,e.cekBits);return e.cbc?rn(e,t,r,o,s,p):on(e,t,r,o,s,p)}var yt={};te(yt,{decode:()=>B,encode:()=>C});function Ct(e){if(Uint8Array.prototype.toBase64)return e.toBase64();let t=32768,r=[];for(let o=0;o<e.length;o+=t)r.push(String.fromCharCode.apply(null,e.subarray(o,o+t)));return btoa(r.join(""))}function Ze(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(e);let t=atob(e),r=new Uint8Array(t.length);for(let o=0;o<t.length;o++)r[o]=t.charCodeAt(o);return r}var vt="The input to be decoded is not correctly encoded.";function B(e){if(Uint8Array.fromBase64)try{return Uint8Array.fromBase64(typeof e==="string"?e:ae.decode(e),{alphabet:"base64url"})}catch(r){throw TypeError(vt,{cause:r})}let t=e;if(t instanceof Uint8Array)t=ae.decode(t);if(t.includes("+")||t.includes("/"))throw TypeError(vt);t=t.replace(/-/g,"+").replace(/_/g,"/");try{return Ze(t)}catch{throw TypeError(vt)}}function C(e){let t=e;if(typeof t==="string")t=Je.encode(t);if(Uint8Array.prototype.toBase64)return t.toBase64({alphabet:"base64url",omitPadding:!0});return Ct(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function se(e,t){if(!(e instanceof Uint8Array))throw TypeError(`${t} must be an instance of Uint8Array`)}function J(e){if(typeof e!=="object"||e===null||Object.prototype.toString.call(e)!=="[object Object]")return!1;let t=Object.getPrototypeOf(e);return t===null||Object.getPrototypeOf(t)===null}function Qe(e){return J(e)&&Array.isArray(e.keys)&&Array.from(e.keys).every(J)}function nr(...e){let t=new Set;for(let r of e){if(!r)continue;for(let o of Object.keys(r)){if(t.has(o))return!1;t.add(o)}}return!0}var or=Symbol();function ce(e,t){if(e!==void 0)throw TypeError(`${t} can only be called once`)}function I(e,t,r){try{return B(e)}catch{throw new r(`Failed to base64url decode the ${t}`)}}function Tt(e,t,r){try{return K(e)}catch{throw new r(`The ${t} is not a valid base64url string`)}}async function tt(e,t){let r=`SHA-${e.slice(-3)}`;return new Uint8Array(await crypto.subtle.digest(r,t))}function re(e,t,r){let o;try{o=JSON.parse(fe.decode(B(e)))}catch{throw new t(r)}if(!J(o))throw new t(r);return o}async function Y(e,t){if(t.kty==="RSA"&&"oth"in t&&t.oth!==void 0)throw new w('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');if(!e.kty.includes(t.kty))throw new w('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');let r=e.resolve?.({kty:t.kty,crv:t.crv})??e.subtle,o=!!(t.d||t.priv),s={...t};if(s.kty!=="AKP")delete s.alg;return delete s.use,crypto.subtle.importKey("jwk",s,r,t.ext??!o,t.key_ops??e.usages[o?1:0])}function le(e){return{__proto__:null,...e}}function rt(e){let t=le(e);if(t.ext!==void 0&&typeof t.ext!=="boolean")throw TypeError('"ext" (Extractable) Parameter must be a boolean');if(t.key_ops!==void 0){let r=t.key_ops,o=Array.isArray(r)?[...r]:void 0;if(!o||o.some((s)=>typeof s!=="string")||new Set(o).size!==o.length)throw TypeError('"key_ops" (Key Operations) Parameter must be an array of unique strings');t.key_ops=o}return t}var Pt=(e)=>e[Symbol.toStringTag],an=(e,t,r)=>{let{alg:o}=e;if(t.use!==void 0){let s=r==="sign"||r==="verify"?"sig":"enc";if(t.use!==s)throw TypeError(`Invalid key for this operation, its "use" must be "${s}" when present`)}if(t.alg!==void 0&&t.alg!==o)throw TypeError(`Invalid key for this operation, its "alg" must be "${o}" when present`);if(Array.isArray(t.key_ops)){let s=r==="encrypt"||r==="decrypt"?e.ops?.[r==="encrypt"?0:1]:r;if(s&&!t.key_ops.includes(s))throw TypeError(`Invalid key for this operation, its "key_ops" must include "${s}" when present`)}};function sn(e,t,r){let{alg:o,secret:s}=e,p=r==="decrypt"||r==="sign";if(s&&t instanceof Uint8Array)return[ar,t];if(J(t)){let c=rt(t);if(typeof c.kty!=="string")throw TypeError(s?We(o,t,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"):We(o,t,"CryptoKey","KeyObject","JSON Web Key"));if(!(s?c.kty==="oct"&&typeof c.k==="string":c.kty!=="oct"&&(p?c.kty==="AKP"&&typeof c.priv==="string"||typeof c.d==="string":c.d===void 0&&c.priv===void 0)))throw TypeError(s?'JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present':`JSON Web Key for this operation must be a ${p?"private":"public"} JWK`);return an(e,c,r),[pr,t,c]}if(!Ge(t))throw TypeError(s?We(o,t,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"):We(o,t,"CryptoKey","KeyObject","JSON Web Key"));if(s){if(t.type!=="secret")throw TypeError(`${Pt(t)} instances for symmetric algorithms must be of type "secret"`)}else{if(t.type==="secret")throw TypeError(`${Pt(t)} instances for asymmetric algorithms must not be of type "secret"`);let c=p?"private":"public";if((t.type==="public"||t.type==="private")&&t.type!==c){let d=r==="sign"?"signing":r==="verify"?"verifying":`${r.slice(0,-1)}tion`;throw TypeError(`${Pt(t)} instances for asymmetric algorithm ${d} must be of type "${c}"`)}}return F(t)?[sr,t]:[cr,t]}var ar=0,sr=1,cr=2,pr=3,It,cn={__proto__:null,prime256v1:"P-256",secp384r1:"P-384",secp521r1:"P-521"};function nt(e,t,r){It||=new WeakMap;let o=It.get(e);if(r)if(o)o[t]=r;else It.set(e,{[t]:r});return r??o?.[t]}var ir=async(e,t,r)=>nt(e,r.alg)??nt(e,r.alg,await Y(r,{...t,alg:r.alg})),pn=(e,t)=>{let r=nt(e,t.alg);if(r)return r;let o=e.type==="public",s=t.usages[o?0:1],{asymmetricKeyType:p}=e,c=cn[e.asymmetricKeyDetails?.namedCurve],d=t.resolve?.({crv:c,asymmetricKeyType:p})??t.subtle;return nt(e,t.alg,e.toCryptoKey(d,o,s))};async function M(e,t,r){let o=sn(e,t,r);switch(o[0]){case ar:case sr:return o[1];case pr:{let s=o[1],p=o[2];if(p.kty==="oct")return B(p.k);if(!Object.isFrozen(s)){let{key_ops:c}=s;if(Array.isArray(c))Object.freeze(c);Object.freeze(s)}return ir(s,p,e)}case cr:{let s=o[1];if(s.type==="secret")return s.export();if("toCryptoKey"in s&&typeof s.toCryptoKey==="function")return pn(s,e);return ir(s,s.export({format:"jwk"}),e)}}}function ve(e){let t={__proto__:null};for(let r in e)t[r]={...e[r],alg:r};return t}var dn=[["encrypt","wrapKey"],["decrypt","unwrapKey"]],fn=[[],["deriveBits"]],st=[[],[]];function ot(e){return{kty:["RSA"],subtle:{name:"RSA-OAEP",hash:`SHA-${e}`},usages:dn,ops:["wrapKey","unwrapKey"]}}function it(){return{kty:["EC","OKP"],subtle:{name:"ECDH"},resolve:({kty:e,crv:t,asymmetricKeyType:r})=>{if(t==="X25519"||r==="x25519")return{name:"X25519"};if(e==="OKP")throw new w('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');return{name:"ECDH",namedCurve:t}},usages:fn,ops:[void 0,"deriveBits"]}}function me(e,t=!1){return{kty:["oct"],secret:!0,subtle:{name:t?"AES-GCM":"AES-KW",length:e},usages:st,ops:t?["encrypt","decrypt"]:["wrapKey","unwrapKey"]}}function Ot(){return{kty:["oct"],secret:!0,subtle:{name:"PBKDF2"},usages:st,ops:["deriveBits","deriveBits"]}}var _t=ve({dir:{kty:["oct"],secret:!0,subtle:{name:"AES-GCM"},usages:st,ops:["encrypt","decrypt"]},"RSA-OAEP":ot(1),"RSA-OAEP-256":ot(256),"RSA-OAEP-384":ot(384),"RSA-OAEP-512":ot(512),"ECDH-ES":it(),"ECDH-ES+A128KW":it(),"ECDH-ES+A192KW":it(),"ECDH-ES+A256KW":it(),A128KW:me(128),A192KW:me(192),A256KW:me(256),A128GCMKW:me(128,!0),A192GCMKW:me(192,!0),A256GCMKW:me(256,!0),"PBES2-HS256+A128KW":Ot(),"PBES2-HS384+A192KW":Ot(),"PBES2-HS512+A256KW":Ot()}),un=["encrypt","decrypt"];function ye(e,t=!1){return{kty:["oct"],secret:!0,subtle:{name:t?"AES-CBC":"AES-GCM",length:e},usages:st,ops:un,cekBits:e,ivBits:t?128:96,cbc:t}}var ln=ve({A128GCM:ye(128),A192GCM:ye(192),A256GCM:ye(256),"A128CBC-HS256":ye(256,!0),"A192CBC-HS384":ye(384,!0),"A256CBC-HS512":ye(512,!0)});function dr(e,t){throw new w(`Invalid or unsupported "${e}" (JWE ${t}) header value`)}function L(e){return(typeof e==="string"?_t[e]:void 0)??dr("alg","Algorithm")}function pe(e){return(typeof e==="string"?ln[e]:void 0)??dr("enc","Encryption Algorithm")}function fr(e,t){if(e.algorithm.name!=="ECDH"&&e.algorithm.name!=="X25519")throw TypeError("CryptoKey does not support this operation, its algorithm.name must be ECDH or X25519");bt(e,t)}async function lr(e,t,r){let o=L(t).subtle,s=e instanceof Uint8Array?await crypto.subtle.importKey("raw",e,"AES-KW",!0,[r]):e;return V(s,o,r),s}async function Dt(e,t,r){let o=await lr(t,e,"wrapKey"),s=await crypto.subtle.importKey("raw",r,{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.wrapKey("raw",s,o,"AES-KW"))}async function Ut(e,t,r){let o=await lr(t,e,"unwrapKey"),s=await crypto.subtle.unwrapKey("raw",r,o,"AES-KW",{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.exportKey("raw",s))}function mr(e,t,r){V(t,L(e).subtle,r),Me(e,t)}function mn(e,t){if(e instanceof Uint8Array)return crypto.subtle.importKey("raw",e,"PBKDF2",!1,["deriveBits"]);return V(e,L(t).subtle,"deriveBits"),e}async function yr(e,t,r,o){if(!(e instanceof Uint8Array)||e.length<8)throw new m("PBES2 Salt Input must be 8 or more octets");if(!Number.isSafeInteger(r)||Math.sign(r)!==1)throw new m("PBES2 Count Input must be a positive integer");let s=W(K(t),Uint8Array.of(0),e),p=parseInt(t.slice(13,16),10),c={hash:`SHA-${t.slice(8,11)}`,iterations:r,name:"PBKDF2",salt:s},d=await mn(o,t);return new Uint8Array(await crypto.subtle.deriveBits(c,d,p))}function Rt(e){return W(ke(e.length),e)}async function yn(e,t,r){let o=t>>3,s=32,p=Math.ceil(o/32),c=new Uint8Array(p*32);for(let d=1;d<=p;d++){let f=await tt("sha256",W(ke(d),e,r));c.set(f,(d-1)*32)}return c.slice(0,o)}async function hr(e,t,r,o,s=new Uint8Array,p=new Uint8Array){fr(e),fr(t,"deriveBits");let c=W(Rt(K(r)),Rt(s),Rt(p),ke(o)),d=new Uint8Array(await crypto.subtle.deriveBits({name:e.algorithm.name,public:e},t,e.algorithm.name==="X25519"?256:Math.ceil(parseInt(e.algorithm.namedCurve.slice(-3),10)/8)<<3));return yn(d,o,c)}function wr(e){Ve(e);let t=e.algorithm.namedCurve;if(t!=="P-256"&&t!=="P-384"&&t!=="P-521"&&e.algorithm.name!=="X25519")throw new w("ECDH with the provided key is not allowed or not supported by your javascript runtime")}function Te(e){if(e===void 0)throw new m("JWE Encrypted Key missing")}function ur(e){if(e!==void 0)throw new m("Encountered unexpected JWE Encrypted Key")}async function gr(e,t,r,o,s,p){let c=L(e);if(e==="dir")return ur(o),r;switch(c.subtle.name){case"ECDH":{if(e==="ECDH-ES")ur(o);if(!J(s.epk))throw new m('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');wr(r);let d=await Y(c,s.epk),f,u;if(s.apu!==void 0){if(typeof s.apu!=="string")throw new m('JOSE Header "apu" (Agreement PartyUInfo) invalid');f=I(s.apu,"apu",m)}if(s.apv!==void 0){if(typeof s.apv!=="string")throw new m('JOSE Header "apv" (Agreement PartyVInfo) invalid');u=I(s.apv,"apv",m)}let l=await hr(d,r,e==="ECDH-ES"?t.alg:e,e==="ECDH-ES"?t.cekBits:parseInt(e.slice(-5,-2),10),f,u);if(e==="ECDH-ES")return l;return Te(o),Ut(e.slice(-6),l,o)}case"RSA-OAEP":return Te(o),Ve(r),mr(e,r,"decrypt"),new Uint8Array(await crypto.subtle.decrypt("RSA-OAEP",r,o));case"PBKDF2":{if(Te(o),typeof s.p2c!=="number")throw new m('JOSE Header "p2c" (PBES2 Count) missing or invalid');let d=p||1e4;if(s.p2c>d)throw new m('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');if(typeof s.p2s!=="string")throw new m('JOSE Header "p2s" (PBES2 Salt) missing or invalid');let f=I(s.p2s,"p2s",m),u=await yr(f,e,s.p2c,r);return Ut(e.slice(-6),u,o)}case"AES-KW":return Te(o),Ut(e,r,o);case"AES-GCM":{if(Te(o),typeof s.iv!=="string")throw new m('JOSE Header "iv" (Initialization Vector) missing or invalid');if(typeof s.tag!=="string")throw new m('JOSE Header "tag" (Authentication Tag) missing or invalid');let d;d=I(s.iv,"iv",m);let f;return f=I(s.tag,"tag",m),Ye(pe(e.slice(0,-2)),r,o,d,f,new Uint8Array)}}}async function Er(e,t,r,o,s={}){let p,c,d,f=L(e);if(e==="dir")return[r,void 0,void 0];switch(f.subtle.name){case"ECDH":{wr(r);let{apu:u,apv:l}=s;if(u!==void 0)se(u,'"apu"');if(l!==void 0)se(l,'"apv"');let y;if(s.epk!==void 0)y=await M(f,s.epk,"decrypt");else y=(await crypto.subtle.generateKey(r.algorithm,!0,["deriveBits"])).privateKey;let h=crypto.subtle,T=y;if(!T.extractable){if(typeof h.getPublicKey!=="function")throw TypeError('CryptoKey for "epk" must be extractable');T=await h.getPublicKey(y,[])}let{x:U,y:S,crv:E,kty:_}=await h.exportKey("jwk",T),g=await hr(r,y,e==="ECDH-ES"?t.alg:e,e==="ECDH-ES"?t.cekBits:parseInt(e.slice(-5,-2),10),u,l);if(c={epk:{x:U,crv:E,kty:_}},_==="EC")c.epk.y=S;if(u)c.apu=C(u);if(l)c.apv=C(l);if(e==="ECDH-ES"){d=g;break}d=o||X(t);let P=e.slice(-6);p=await Dt(P,g,d);break}case"RSA-OAEP":{d=o||X(t),Ve(r),mr(e,r,"encrypt"),p=new Uint8Array(await crypto.subtle.encrypt("RSA-OAEP",r,d));break}case"PBKDF2":{d=o||X(t);let{p2c:u=2048,p2s:l=crypto.getRandomValues(new Uint8Array(16))}=s,y=await yr(l,e,u,r);p=await Dt(e.slice(-6),y,d),c={p2c:u,p2s:C(l)};break}case"AES-KW":{d=o||X(t),p=await Dt(e,r,d);break}case"AES-GCM":{d=o||X(t);let{iv:u}=s,l=await Xe(pe(e.slice(0,-2)),d,r,u,new Uint8Array);p=l.ciphertext,c={iv:C(l.iv),tag:C(l.tag)};break}}return[d,p,c]}var he={__proto__:null,b64:!0},ct={__proto__:null};function Pe(e,t){if(t!==void 0&&(!Array.isArray(t)||t.some((r)=>typeof r!=="string")))throw TypeError(`"${e}" option must be an array of strings`);if(!t)return;return new Set(t)}function pt(e,t){let{crit:r}=t??{};if(Array.isArray(r)&&new Set(r).size!==r.length)throw new e('"crit" (Critical) Header Parameter MUST NOT contain duplicate values')}function j(e,t,r,o,s){if(s.crit!==void 0&&o?.crit===void 0)throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');if(!o||o.crit===void 0)return[];if(!Array.isArray(o.crit)||o.crit.length===0||o.crit.some((c)=>typeof c!=="string"||c.length===0))throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');let p=r===void 0?t:{__proto__:null,...r,...t};for(let c of o.crit){if(!(c in p))throw new w(`Extension Header Parameter "${c}" is not recognized`);if(!Object.hasOwn(s,c)||s[c]===void 0)throw new e(`Extension Header Parameter "${c}" is missing`);if(p[c]&&(!Object.hasOwn(o,c)||o[c]===void 0))throw new e(`Extension Header Parameter "${c}" MUST be integrity protected`)}return o.crit}function we(e,t){if(t.includes("b64")){let r=e.b64;if(typeof r!=="boolean")throw new b('The "b64" (base64url-encode payload) Header Parameter must be a boolean');return r}return!0}function ge(e,t){let r,o;try{r=JSON.stringify(t),o=JSON.parse(r)}catch(s){throw new e("JOSE Header is not valid JSON",{cause:s})}if(!J(o))throw new e("JOSE Header is not a JSON object");return[o,r]}function dt(e,t){if(e.zip!==void 0&&e.zip!=="DEF")throw new w('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(e.zip!==void 0&&!t?.zip)throw new m('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.')}function br(e){if(typeof globalThis[e]>"u")throw new w(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${e} API.`)}async function Sr(e){br("CompressionStream");let t=new CompressionStream("deflate-raw"),r=t.writable.getWriter();r.write(e).catch(()=>{}),r.close().catch(()=>{});let o=[],s=t.readable.getReader();for(;;){let{value:p,done:c}=await s.read();if(c)break;o.push(p)}return W(...o)}async function Ar(e,t){br("DecompressionStream");let r=new DecompressionStream("deflate-raw"),o=r.writable.getWriter();o.write(e).catch(()=>{}),o.close().catch(()=>{});let s=[],p=0,c=r.readable.getReader();for(;;){let{value:d,done:f}=await c.read();if(f)break;if(s.push(d),p+=d.byteLength,t!==1/0&&p>t)throw new m("Decompressed plaintext exceeded the configured limit")}return W(...s)}function xr(e){return[e&&Pe("keyManagementAlgorithms",e.keyManagementAlgorithms),e&&Pe("contentEncryptionAlgorithms",e.contentEncryptionAlgorithms),e?.crit,e?.maxPBES2Count,e?.maxDecompressedLength]}async function hn(e,t,r,o,s){let[p,c,d,f,u]=r,[l,y,h,T,U]=t,{encrypted_key:S}=e;j(m,ct,d,l,s),dt(s,l);let{alg:E,enc:_}=s;if(typeof E!=="string"||!E)throw new m("missing JWE Algorithm (alg) in JWE Header");if(typeof _!=="string"||!_)throw new m("missing JWE Encryption Algorithm (enc) in JWE Header");if(p&&!p.has(E)||!p&&E.startsWith("PBES2"))throw new ue('"alg" (Algorithm) Header Parameter value not allowed');if(c&&!c.has(_))throw new ue('"enc" (Encryption Algorithm) Header Parameter value not allowed');let g=pe(_),P;if(S!==void 0)P=I(S,"encrypted_key",m);let R=!1;if(typeof o==="function")o=await o(l,e),R=!0;let z=L(E),H=await M(E==="dir"?g:z,o,"decrypt"),N;try{if(N=await gr(E,g,H,P,s,f),S!==void 0&&N instanceof Uint8Array&&N.byteLength<<3!==g.cekBits)N=X(g)}catch(O){if(O instanceof TypeError||O instanceof m||O instanceof w)throw O;N=X(g)}let ne=await Ye(g,N,y,h,T,U);if(s.zip==="DEF"){let O=u??250000;if(O===0)throw new w('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');if(O!==1/0&&(!Number.isSafeInteger(O)||O<1))throw TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");ne=await Ar(ne,O).catch((ie)=>{if(ie instanceof m)throw ie;throw new m("Failed to decompress plaintext",{cause:ie})})}return[ne,l,H,R]}async function Kr(e,t,r){if(e instanceof Uint8Array)e=ae.decode(e);if(typeof e!=="string")throw new m("Compact JWE must be a string or Uint8Array");let{0:o,1:s,2:p,3:c,4:d,length:f}=e.split(".");if(f!==5)throw new m("Invalid Compact JWE");let u={ciphertext:c,iv:p||void 0,protected:o,tag:d||void 0,encrypted_key:s||void 0},l=re(o,m,"JWE Protected Header is invalid"),y=K(o),h=[l,I(c,"ciphertext",m),p?I(p,"iv",m):void 0,d?I(d,"tag",m):void 0,y];return hn(u,h,t,r,l)}function Jr(e,t,r){if(!nr(e,t,r))throw new m("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint")}function wn(e){let[,t,r,o,s,p,c,d,f]=e;if(s!==void 0)se(s,"JWE Additional Authenticated Data");if(p!==void 0)se(p,"JWE Content Encryption Key");if(c!==void 0)se(c,"JWE Initialization Vector");if(t!==void 0)t=ge(m,t)[0],e[1]=t;if(r!==void 0)r=ge(m,r)[0],e[2]=r;if(o!==void 0)o=ge(m,o)[0],e[3]=o;if(d!==void 0&&!J(d))throw TypeError("JWE Key Management Parameters must be an object");Jr(t,r,o);let u={...t,...r,...o};pt(m,t),j(m,ct,f,t,u),dt(u,t);let{alg:l,enc:y}=u;if(typeof l!=="string"||!l)throw new m('JWE "alg" (Algorithm) Header Parameter missing or invalid');if(typeof y!=="string"||!y)throw new m('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');return[u,l,y,pe(y)]}async function gn(e,t,r){let[o,s,,p]=t,[c,d,f,u,l,y,h,T,,U]=e,S=d,E=f;if(y&&(s==="dir"||s==="ECDH-ES"))throw TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${s}`);let _=L(s),g=await M(s==="dir"?p:_,r,"encrypt"),[P,R,z]=await Er(s,p,g,y,T);if(z){if(U)E=E?{...E,...z}:z;else S=S?{...S,...z}:z;Jr(S,E,u)}let H,N;if(S)H=C(JSON.stringify(S)),N=K(H);else H="",N=new Uint8Array;let ne,O;if(l?.byteLength)O=C(l),ne=W(N,K("."),K(O));else ne=N;let ie=c;if(o.zip==="DEF")ie=await Sr(ie).catch((jr)=>{throw new m("Failed to compress plaintext",{cause:jr})});let{ciphertext:Lr,tag:Xt,iv:Yt}=await Xe(p,ie,P,h,ne),ee={ciphertext:C(Lr)};if(Yt)ee.iv=C(Yt);if(Xt)ee.tag=C(Xt);if(R)ee.encrypted_key=C(R);if(O)ee.aad=O;if(S)ee.protected=H;if(u)ee.unprotected=u;if(E)ee.header=E;return ee}async function Wr(e,t,r){if(!e[1]&&!e[2]&&!e[3])throw new m("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");if(r!==void 0)e[8]=r?.crit,e[9]=r?or in r:!1;return gn(e,wn(e),t)}async function Cr(e,t,r){if(t instanceof Uint8Array)return crypto.subtle.importKey("raw",t,e.subtle,!1,[r]);if(V(t,e.subtle,r),e.minRsaBits)Me(e.alg,t);return t}async function vr(e,t,r){let o=await Cr(e,t,"sign"),s=await crypto.subtle.sign(e.signing,o,r);return new Uint8Array(s)}async function Tr(e,t,r,o){let s=await Cr(e,t,"verify");try{return await crypto.subtle.verify(e.signing,s,r,o)}catch{return!1}}var Ie=[["verify"],["sign"]];function Nt(e){let t={name:"HMAC",hash:`SHA-${e}`};return{kty:["oct"],secret:!0,subtle:t,signing:t,usages:Ie}}function Ee(e,t){let o={name:t?"RSA-PSS":"RSASSA-PKCS1-v1_5",hash:`SHA-${e}`};return{kty:["RSA"],subtle:o,signing:t?{...o,saltLength:t}:o,usages:Ie,minRsaBits:2048}}function Ht(e,t){return{kty:["EC"],crv:e,subtle:{name:"ECDSA",namedCurve:e},signing:{name:"ECDSA",hash:`SHA-${t}`},usages:Ie}}function Pr(){let e={name:"Ed25519"};return{kty:["OKP"],crv:"Ed25519",subtle:e,signing:e,usages:Ie}}function kt(e){let r={name:`ML-DSA-${e}`};return{kty:["AKP"],subtle:r,signing:r,usages:Ie}}var Oe=ve({HS256:Nt(256),HS384:Nt(384),HS512:Nt(512),RS256:Ee(256),RS384:Ee(384),RS512:Ee(512),PS256:Ee(256,32),PS384:Ee(384,48),PS512:Ee(512,64),ES256:Ht("P-256",256),ES384:Ht("P-384",384),ES512:Ht("P-521",512),EdDSA:Pr(),Ed25519:Pr(),"ML-DSA-44":kt(44),"ML-DSA-65":kt(65),"ML-DSA-87":kt(87)});function ft(e){let t=typeof e==="string"?Oe[e]:void 0;if(!t)throw new w(`alg ${e} is not supported either by JOSE or your javascript runtime`);return t}function Ir(e){return[e&&Pe("algorithms",e.algorithms),e?.crit]}function En(e,t=e===void 0?{}:re(e,b,"JWS Protected Header is invalid")){return t}function bn(e,t,r){let o=we(e,j(b,he,r[1],e,t)),s=t.alg;if(typeof s!=="string"||!s)throw new b('JWS "alg" (Algorithm) Header Parameter missing or invalid');if(r[0]&&!r[0].has(s))throw new ue('"alg" (Algorithm) Header Parameter value not allowed');return[o,s]}function Sn(e){try{return K(e)}catch{throw new b("JWS Compact Serialization payload must use only ASCII characters")}}async function An(e,t,r,o,s,p,c){let d=!1;if(typeof r==="function")r=await r(s,e),d=!0;let f=typeof c==="string",u=ft(p),l=W(o!==void 0?K(o):new Uint8Array,K("."),f?t[2]??=Tt(c,"payload",b):c),y=I(e.signature,"signature",b),h=await M(u,r,"verify");if(!await Tr(u,h,y,l))throw new Jt;return[f?I(c,"payload",b):c,s,f,h,d]}async function Or(e,t,r){if(e instanceof Uint8Array)e=ae.decode(e);if(typeof e!=="string")throw new b("Compact JWS must be a string or Uint8Array");let{0:o,1:s,2:p,length:c}=e.split(".");if(c!==3)throw new b("Invalid Compact JWS");let d={payload:s,protected:o,signature:p},f=En(o),[u,l]=bn(f,f,t),y=u?s:Sn(s);return An(d,t,r,o,f,l,y)}var _e=(e)=>Math.floor(e.getTime()/1000),xn={s:1,m:60,h:3600,d:86400,w:604800,y:31557600},Kn=/^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i,be="check_failed";function Bt(){throw TypeError("Invalid time period format")}function ut(e){if(typeof e!=="string")Bt();let t=Kn.exec(e);if(!t||t[4]&&t[1])Bt();let r=parseFloat(t[2]),o=Math.round(r*xn[t[3][0].toLowerCase()]);if(!Number.isFinite(o))Bt();if(t[1]==="-"||t[4]==="ago")return-o;return o}function Se(e,t){if(!Number.isFinite(t))throw TypeError(`Invalid ${e} input`);return t}function Mt(e,t){if(typeof t!=="string")throw TypeError(`"${e}" claim must be a string`)}function Jn(e){if(typeof e!=="string"&&(!Array.isArray(e)||Array.from(e).some((t)=>typeof t!=="string")))throw TypeError('"aud" claim must be a string or an array of strings')}function $t(e,t){if(typeof e==="number")return Se(t,e);if(e instanceof Date)return Se(t,_e(e));return _e(new Date)+ut(e)}var _r=(e)=>{let t=e.toLowerCase();return e.includes("/")?t:`application/${t}`},Wn=(e,t)=>{if(typeof e==="string")return t.includes(e);if(Array.isArray(e))return t.some((r)=>e.includes(r));return!1};function Lt(e,t,r=!1){let o=e[t];if(o===void 0&&!r)return;if(typeof o!=="number")throw new k(`"${t}" claim must be a number`,e,t,"invalid");return o}function jt(e,t){throw new k(`unexpected "${t}" claim value`,e,t,be)}function Ae(e,t,r={}){let o;try{o=JSON.parse(fe.decode(t))}catch{}if(!J(o))throw new A("JWT Claims Set must be a top-level JSON object");let{typ:s}=r;if(s!==void 0&&(typeof e.typ!=="string"||_r(e.typ)!==_r(s)))throw new k('unexpected "typ" JWT header value',o,"typ",be);let{requiredClaims:p=[],issuer:c,subject:d,audience:f,maxTokenAge:u}=r,l=[...p];if(u!==void 0)l.push("iat");if(f!==void 0)l.push("aud");if(d!==void 0)l.push("sub");if(c!==void 0)l.push("iss");for(let g of new Set(l.reverse()))if(!Object.hasOwn(o,g))throw new k(`missing required "${g}" claim`,o,g,"missing");if(c!==void 0&&!(Array.isArray(c)?c:[c]).includes(o.iss))jt(o,"iss");if(d!==void 0&&o.sub!==d)jt(o,"sub");if(f!==void 0&&!Wn(o.aud,typeof f==="string"?[f]:f))jt(o,"aud");let{clockTolerance:y}=r,h=0;if(typeof y==="string")h=ut(y);else if(y!==void 0){if(typeof y!=="number")throw TypeError("Invalid clockTolerance option type");h=y}Se("clockTolerance option",h);let{currentDate:T}=r,U=Se("currentDate option",_e(T===void 0?new Date:T)),S=Lt(o,"iat",u!==void 0),E=Lt(o,"nbf");if(E!==void 0){if(E>U+h)throw new k('"nbf" claim timestamp check failed',o,"nbf",be)}let _=Lt(o,"exp");if(_!==void 0){if(_<=U-h)throw new Fe('"exp" claim timestamp check failed',o,"exp",be)}if(u!==void 0){let g=U-S,P=Se("maxTokenAge option",typeof u==="number"?u:ut(u));if(g-h>P)throw new Fe('"iat" claim timestamp check failed (too far in the past)',o,"iat",be);if(g<-h)throw new k('"iat" claim timestamp check failed (it should be in the past)',o,"iat",be)}return o}var Dr;function q(e){return Dr.get(e)}function xe(e){let t=q(e);for(let r of["iat","nbf","exp"]){let o=t[r];if(typeof o==="number"&&!Number.isFinite(o))throw TypeError(`"${r}" claim must be a finite number`)}return Je.encode(JSON.stringify(t))}function mt(e,t){return q(e)[t]}class de{constructor(e={}){if(!J(e))throw TypeError("JWT Claims Set MUST be an object");(Dr||=new WeakMap).set(this,structuredClone(e))}setIssuer(e){return Mt("iss",e),q(this).iss=e,this}setSubject(e){return Mt("sub",e),q(this).sub=e,this}setAudience(e){return Jn(e),q(this).aud=e,this}setJti(e){return Mt("jti",e),q(this).jti=e,this}setNotBefore(e){return q(this).nbf=$t(e,"setNotBefore"),this}setExpirationTime(e){return q(this).exp=$t(e,"setExpirationTime"),this}setIssuedAt(e){let t=q(this);if(e===void 0)t.iat=_e(new Date);else if(typeof e==="string")t.iat=Se("setIssuedAt",_e(new Date)+ut(e));else t.iat=$t(e,"setIssuedAt");return this}}async function D(e,t,r){let o=await Or(e,Ir(r),t);if(!o[2])throw new A("JWTs MUST NOT use unencoded payload");let p={payload:Ae(o[1],o[0],r),protectedHeader:o[1]};if(typeof t==="function")return{...p,key:o[3]};return p}async function qe(e,t,r){let o=await Kr(e,xr(r),t),s=o[1],p=Ae(s,o[0],r);for(let d of["iss","sub","aud"])if(s[d]!==void 0&&(d==="aud"?JSON.stringify(s.aud)!==JSON.stringify(p.aud):s[d]!==p[d]))throw new k(`replicated "${d}" claim header parameter mismatch`,p,d,"mismatch");let c={payload:p,protectedHeader:s};if(typeof t==="function")return{...c,key:o[2]};return c}function Cn(e){if(e===void 0)return[void 0,""];let t=ge(b,e);return[t[0],C(t[1])]}function vn(e,t,r){return pt(b,e),we(e,j(b,he,r,e,t))}function Tn(e){let t=e.alg;if(typeof t!=="string"||!t)throw new b('JWS "alg" (Algorithm) Header Parameter missing or invalid');return ft(t)}async function Pn(e,t,r,o){let s=W(K(e),K("."),t),p=await M(r,o,"sign");return C(await vr(r,p,s))}async function Ur(e,t,r,o,s){let[p,c]=Cn(t);if(!p)throw new b("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!vn(p,p,r))s();let f=Tn(p),u=C(e),l=await Pn(c,K(u),f,o);return`${c}.${u}.${l}`}var In=de;class Ke extends In{#e;setProtectedHeader(e){return ce(this.#e,"setProtectedHeader"),this.#e=e,this}async sign(e,t){return Ur(xe(this),this.#e,t?.crit,e,()=>{throw new A("JWTs MUST NOT use unencoded payload")})}}var On=de;class $e extends On{#e;#r;#n;#t;#o;#i;#a;setProtectedHeader(e){return ce(this.#t,"setProtectedHeader"),this.#t=e,this}setKeyManagementParameters(e){return ce(this.#n,"setKeyManagementParameters"),this.#n=e,this}setContentEncryptionKey(e){return ce(this.#e,"setContentEncryptionKey"),this.#e=e,this}setInitializationVector(e){return ce(this.#r,"setInitializationVector"),this.#r=e,this}replicateIssuerAsHeader(){return this.#o=!0,this}replicateSubjectAsHeader(){return this.#i=!0,this}replicateAudienceAsHeader(){return this.#a=!0,this}async encrypt(e,t){let r=xe(this);if(this.#t&&(this.#o||this.#i||this.#a))this.#t={...this.#t,iss:this.#o?mt(this,"iss"):void 0,sub:this.#i?mt(this,"sub"):void 0,aud:this.#a?mt(this,"aud"):void 0};let o=await Wr([r,this.#t,void 0,void 0,void 0,this.#e,this.#r,this.#n,void 0,!1],e,t);return[o.protected,o.encrypted_key,o.iv,o.ciphertext,o.tag].join(".")}}var zt='"alg" (Algorithm)';function Vt(e='JWK "alg" (Algorithm) Parameter'){throw new w(`Invalid or unsupported ${e} value`)}function De(e,t){return(typeof e==="string"?Oe[e]??_t[e]:void 0)??Vt(t)}function ht(e){if(e!==void 0&&typeof e!=="boolean")throw TypeError('"extractable" option must be a boolean');return e}var Ue=(e,t)=>{if(e.byteLength!==t.length)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0},_n=(e)=>({data:e,pos:0}),Gt=(e)=>{let t=e.data[e.pos++];if(t===void 0)throw Error("Unexpected end of ASN.1 input");return t},Re=(e)=>{let t=Gt(e);if(t&128){let r=t&127,o=0;for(let s=0;s<r;s++)o=o<<8|Gt(e);return o}return t};var Ne=(e,t,r)=>{if(Gt(e)!==t)throw Error(r)},Rr=(e,t)=>{if(t<0||e.pos+t>e.data.length)throw Error("Unexpected end of ASN.1 input");let r=e.data.subarray(e.pos,e.pos+t);return e.pos+=t,r},Dn=(e)=>{Ne(e,6,"Expected algorithm OID");let t=Re(e);return Rr(e,t)};function Un(e,t){if(Ne(e,48,`Invalid ${t==="spki"?"SPKI":"PKCS#8"} structure`),Re(e),t==="pkcs8"){Ne(e,2,"Expected version field");let r=Re(e);e.pos+=r}Ne(e,48,"Expected algorithm identifier"),Re(e)}var Rn=(e)=>{let t=Dn(e);if(Ue(t,[43,101,110]))return"X25519";if(!Ue(t,[42,134,72,206,61,2,1]))throw Error("Unsupported key algorithm");Ne(e,6,"Expected curve OID");let r=Re(e),o=Rr(e,r);if(Ue(o,[42,134,72,206,61,3,1,7]))return"P-256";if(Ue(o,[43,129,4,0,34]))return"P-384";if(Ue(o,[43,129,4,0,35]))return"P-521";throw Error("Unsupported named curve")},Nn=async(e,t,r,o)=>{let s=ht(o?.extractable),p=De(r,zt);if(p.secret)Vt(zt);let c=e==="spki",d;if(p.resolve)try{let f=_n(t);Un(f,e),d=p.resolve({crv:Rn(f)})}catch{throw new w("Invalid or unsupported key format")}else d=p.subtle;return crypto.subtle.importKey(e,t,d,s??c,p.usages[c?0:1])},Hn=(e,t)=>Ze(e.replace(t,"")),Nr=(e,t,r)=>{let o=Hn(e,/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);return Nn("pkcs8",o,t,r)};function kn(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}async function Bn(e){if(Wt(e))if(e.type==="secret")e=e.export();else return e.export({format:"jwk"});if(e instanceof Uint8Array)return{kty:"oct",k:C(e)};if(!F(e))throw TypeError(G(e,"CryptoKey","KeyObject","Uint8Array"));if(!e.extractable)throw TypeError("non-extractable CryptoKey cannot be exported as a JWK");let{ext:t,key_ops:r,alg:o,use:s,...p}=kn(await crypto.subtle.exportKey("jwk",e));if(p.kty==="AKP")p.alg=o;return p}function Hr(e){return Bn(e)}var Q=(e,t)=>{if(typeof e!=="string"||!e)throw new je(`${t} missing or invalid`)};async function et(e,t){let r;if(J(e)){if(r=le(e),typeof r.kty!=="string")throw TypeError(G(e,"CryptoKey","KeyObject","JSON Web Key"))}else if(Ge(e))r=le(await Hr(e));else throw TypeError(G(e,"CryptoKey","KeyObject","JSON Web Key"));if(t??="sha256",t!=="sha256"&&t!=="sha384"&&t!=="sha512")throw TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');let o;switch(r.kty){case"AKP":Q(r.alg,'"alg" (Algorithm) Parameter'),Q(r.pub,'"pub" (Public key) Parameter'),o={alg:r.alg,kty:r.kty,pub:r.pub};break;case"EC":Q(r.crv,'"crv" (Curve) Parameter'),Q(r.x,'"x" (X Coordinate) Parameter'),Q(r.y,'"y" (Y Coordinate) Parameter'),o={crv:r.crv,kty:r.kty,x:r.x,y:r.y};break;case"OKP":Q(r.crv,'"crv" (Subtype of Key Pair) Parameter'),Q(r.x,'"x" (Public Key) Parameter'),o={crv:r.crv,kty:r.kty,x:r.x};break;case"RSA":Q(r.e,'"e" (Exponent) Parameter'),Q(r.n,'"n" (Modulus) Parameter'),o={e:r.e,kty:r.kty,n:r.n};break;case"oct":if(typeof r.k!=="string")throw new je('"k" (Key Value) Parameter missing or invalid');o={k:r.k,kty:r.kty};break;default:throw new w('"kty" (Key Type) Parameter missing or unsupported')}let s=K(JSON.stringify(o));return C(await tt(t,s))}function Mn(e,t,r,o){let{kty:s,key_ops:p,ext:c,kid:d,alg:f,use:u,crv:l}=le(e),y=Array.isArray(p)?[...p]:p;return(c===void 0||typeof c==="boolean")&&(y===void 0||Array.isArray(y)&&y.every((h,T)=>typeof h==="string"&&y.indexOf(h)===T)&&y.includes("verify"))&&t.kty.includes(s)&&(o===void 0||typeof o==="string"&&o===d)&&(f===void 0?s!=="AKP":r===f)&&(u===void 0||u==="sig")&&(!t.crv||l===t.crv)}async function kr(e,t,r){let o=e.get(t)||e.set(t,{}).get(t),{alg:s}=r;if(o[s]===void 0){let p=await Y(r,{...t,alg:s,ext:!0});if(p.type!=="public")throw new ze("JSON Web Key Set members must be public keys");o[s]=p}return o[s]}function at(e){let t;try{t=structuredClone(e)}catch{}if(!Qe(t))throw new ze("JSON Web Key Set malformed");let r=new WeakMap;return Object.defineProperty(async(s,p)=>{let{alg:c,kid:d}={...s,...p?.header},f=typeof c==="string"?Oe[c]:void 0;if(!f||f.secret)throw new w('Unsupported "alg" value for a JSON Web Key Set');let u=t.keys.filter((h)=>Mn(h,f,c,d)),{0:l,length:y}=u;if(!y)throw new Ce;if(y!==1){let h=new At;throw h[Symbol.asyncIterator]=async function*(){for(let T of u)try{yield await kr(r,T,f)}catch{}},h}return kr(r,l,f)},"jwks",{value:()=>structuredClone(t)})}function $n(){return typeof WebSocketPair<"u"||typeof navigator<"u"&&navigator.userAgent==="Cloudflare-Workers"||typeof EdgeRuntime<"u"&&EdgeRuntime==="vercel"}var Ft;if(typeof navigator>"u"||!navigator.userAgent?.startsWith?.("Mozilla/5.0 "))Ft="jose/v6.2.10";var Mr=Symbol();async function Ln(e,t,r,o=fetch){let s=await o(e,{method:"GET",signal:r,redirect:"manual",headers:t}).catch((p)=>{if(p.name==="TimeoutError")throw new Kt;throw p});if(s.status!==200)throw new v("Expected 200 OK from the JSON Web Key Set HTTP response");try{return await s.json()}catch{throw new v("Failed to parse the JSON Web Key Set HTTP response as JSON")}}var $r=Symbol();function He(e,t){return Number.isFinite(e)&&Date.now()<e+t}function Br(e,t,r){if(Number.isNaN(e))throw TypeError(`"${r}" option must not be NaN`);return typeof e==="number"?e:t}function lt(e,t){if(!(e instanceof URL))throw TypeError("url must be an instance of URL");let r=new URL(e.href).href,o=t??{},s=o.timeoutDuration;if(typeof s==="number"&&(!Number.isInteger(s)||s<0))throw TypeError('"timeoutDuration" option must be a non-negative integer');let p=typeof s==="number"?s:5000,c=Br(o.cooldownDuration,30000,"cooldownDuration"),d=Br(o.cacheMaxAge,600000,"cacheMaxAge"),f=new Headers(o.headers);if(Ft&&!f.has("User-Agent"))f.set("User-Agent",Ft);if(!f.has("accept"))f.set("accept","application/json, application/jwk-set+json");let u=o[Mr],l=o[$r],y,h,T=0,U=0,S;if(l&&typeof l==="object"){let{uat:g,jwks:P}=l;if(He(g,d)&&Qe(P))y=g,S=at(P)}let E=async()=>{if(h&&$n())h=void 0;if(!h){let g=++T,P=h=Ln(r,f,AbortSignal.timeout(p),u).then((R)=>{let z=at(R);if(g<=U)return;S=z;let H=Date.now();if(l)l.uat=H,l.jwks=R;y=H,U=g}).finally(()=>{if(h===P)h=void 0})}await h};return Object.defineProperties(async(g,P)=>{if(!S||!He(y,d))await E();try{return await S(g,P)}catch(R){if(R instanceof Ce&&!He(y,c))return await E(),S(g,P);throw R}},{coolingDown:{get:()=>He(y,c),enumerable:!0},fresh:{get:()=>He(y,d),enumerable:!0},reload:{value:E,enumerable:!0},reloading:{get:()=>!!h,enumerable:!0},jwks:{value:()=>S?.jwks(),enumerable:!0}})}var jn=de;class St extends jn{encode(){let e=C(JSON.stringify({alg:"none"})),t=C(xe(this));return`${e}.${t}.`}static decode(e,t){if(typeof e!=="string")throw new A("Unsecured JWT must be a string");let{0:r,1:o,2:s,length:p}=e.split(".");if(p!==3||s!=="")throw new A("Invalid Unsecured JWT");let c,d;try{c=re(r,b,"JWS Protected Header is invalid");let u=j(b,he,void 0,c,c);d=we(c,u)}catch(u){if(!(u instanceof b))throw u;throw new A("Invalid Unsecured JWT",{cause:u})}if(c.alg!=="none")throw new A("Invalid Unsecured JWT");if(!d)throw new A("JWTs MUST NOT use unencoded payload");return{payload:Ae(c,I(o,"payload",A),t),header:c}}}async function xt(e,t,r){if(typeof e!=="string"||e.indexOf("-----BEGIN PRIVATE KEY-----")!==0)throw TypeError('"pkcs8" must be PKCS#8 formatted string');return Nr(e,t,r)}async function oe(e,t,r){if(!J(e))throw TypeError("JWK must be an object");let o=rt(e),s=ht(r?.extractable),{alg:p}=o;t??=p;let c=s??o.ext;if(o.kty!=="oct"&&!t)throw TypeError('"alg" argument is required when "jwk.alg" is not present');switch(o.kty){case"oct":if(typeof o.k!=="string")throw TypeError('missing "k" (Key Value) Parameter value');return B(o.k);case"AKP":{if(typeof p!=="string"||!p)throw TypeError('missing "alg" (Algorithm) Parameter value');if(t!==p)throw TypeError("JWK alg and alg option value mismatch");return Y(De(t),{...o,ext:c})}case"RSA":case"EC":case"OKP":return Y(De(t),{...o,alg:t,ext:c});default:throw new w('Unsupported "kty" (Key Type) Parameter value')}}function Z(e){let t;if(typeof e==="string"){let o=e.split(".");if(o.length===3||o.length===5)[t]=o}else if(typeof e==="object"&&e)if("protected"in e)t=e.protected;else throw TypeError("Token does not contain a Protected Header");let r="Invalid Token or Protected Header formatting";if(typeof t!=="string"||!t)throw TypeError(r);return re(t,TypeError,r)}function x(e){if(typeof e!=="string")throw new A("JWTs must use Compact JWS serialization, JWT must be a string");let{1:t,length:r}=e.split(".");if(r===5)throw new A("Only JWTs using Compact JWS serialization can be decoded");if(r!==3)throw new A("Invalid JWT");if(!t)throw new A("JWTs must contain a payload");let o;try{o=B(t)}catch{throw new A("Failed to base64url decode the payload")}let s;try{s=JSON.parse(fe.decode(o))}catch{throw new A("Failed to parse the decoded payload as JSON")}if(!J(s))throw new A("Invalid JWT Claims Set");return s}export{i,n,te,a,Fe,C,yt,D,qe,Ke,$e,et,at,lt,St,xt,oe,Z,x};
@@ -0,0 +1,4 @@
1
+ // @bun
2
+ import*as x from"zod/v4";function e(n,i){let a={};if(!Object.keys(i).length)return a=n,a;for(let[h,d]of Object.entries(n)){let S=i[h];if(S===null)continue;a[S??h]=d}return a}function t(n){let i={};for(let[a,h]of Object.entries(n))if(typeof h<"u")i[a]=h;return i}import*as ye from"zod/v4";import*as B from"zod/v4/core";class q extends Error{rawValue;rawMessage;static[Symbol.hasInstance](n){if(!(n instanceof Error))return!1;if(!("rawValue"in n))return!1;if(!("rawMessage"in n))return!1;if(!("pretty"in n))return!1;if(typeof n.pretty!=="function")return!1;return!0}constructor(n,i,a){super(`${n}: ${i}`);this.name="SDKValidationError",this.cause=i,this.rawValue=a,this.rawMessage=n}pretty(){if(this.cause instanceof B.$ZodError)return`${this.rawMessage}
3
+ ${ct(this.cause)}`;else return this.toString()}}function ct(n){return B.prettifyError(n)}function Be(n){return{ok:!0,value:n}}function X(n){return{ok:!1,error:n}}async function s(n){let i=await n;if(!i.ok)throw i.error;return i.value}function r(n,i,a){try{return Be(i(n))}catch(h){return X(new q(a,h,n))}}var W=x.object({prompt_tokens:x.int().default(0),completion_tokens:x.int().default(0),total_tokens:x.int().default(0),prompt_audio_seconds:x.nullable(x.int()).optional()}).catchall(x.any()).transform((n)=>e(n,{prompt_tokens:"promptTokens",completion_tokens:"completionTokens",total_tokens:"totalTokens",prompt_audio_seconds:"promptAudioSeconds"})),Ve=x.object({promptTokens:x.int().default(0),completionTokens:x.int().default(0),totalTokens:x.int().default(0),promptAudioSeconds:x.nullable(x.int()).optional()}).catchall(x.any()).transform((n)=>({...e(n,{promptTokens:"prompt_tokens",completionTokens:"completion_tokens",totalTokens:"total_tokens",promptAudioSeconds:"prompt_audio_seconds"})}));import*as R from"zod/v4";import*as L from"zod/v4";import*as O from"zod/v4";function G(n){return v++,n}var v=0,te=0;function P(){te++;let n=v;return{end:(i)=>{let a=v-n;if(v=n+(i??a),--te===0)v=0;return a}}}function l(n){let i=Object.values(n);return O.union([...i.map((a)=>O.literal(a)),O.string().transform((a)=>G(a))])}function Re(n){let i=Object.values(n).filter((a)=>typeof a==="number");return O.union([...i.map((a)=>O.literal(a)),O.int().transform((a)=>G(a))])}function g(n){return O.string()}function Ct(n){return O.int()}import*as m from"zod/v4";import*as Z from"zod/v4";import*as ne from"zod/v4";var oe=Symbol("UNKNOWN");function re(n){return typeof n==="object"&&n!==null&&oe in n}function p(n,i,a={}){let{unknownValue:h="UNKNOWN",outputPropertyName:d}=a;return ne.unknown().transform((S)=>{let _=Object.defineProperties({raw:S,[d??n]:h,isUnknown:!0},{[oe]:{value:!0,enumerable:!1,configurable:!1}});if(!(typeof S==="object"&&S!==null))return _;let D=S[n];if(typeof D!=="string")return _;if(!(D in i))return _;let Y=i[D];if(!Y)return _;let E=P(),A=Y.safeParse(S);if(!A.success)return E.end(0),_;if(E.end(),d)A.data[d]=D;return A.data})}var ue=/^\d{4}-\d{2}-\d{2}$/;class V{serialized;static today(){return new V(new Date)}constructor(n){if(typeof n==="string"&&!ue.test(n))throw RangeError("RFCDate: date strings must be in the format YYYY-MM-DD: "+n);let i=new Date(n);if(isNaN(+i))throw RangeError("RFCDate: invalid date provided: "+n);if(this.serialized=i.toISOString().slice(0,10),!ue.test(this.serialized))throw TypeError(`RFCDate: failed to build valid date with given value: ${n} serialized to ${this.serialized}`)}toJSON(){return this.toString()}toString(){return this.serialized}}function o(n){return Z.unknown().transform((i,a)=>{let h=[],d=n.map(()=>[]),S=P();for(let[w,D]of n.entries()){let Y=P(),E=D.safeParse(i),A=Y.end(),je=0;if(E.success){h.push({data:E.data,inexactCount:A,zeroDefaultCount:0,fieldCount:-1});continue}d[w].push(...E.error.issues)}if(h.length===0)return S.end(0),a.addIssue({input:i,code:"invalid_union",errors:d}),Z.NEVER;let _=h[0];for(let w of h){if(h.length>1)w.fieldCount=_e(w.data);_=$e(w,_)}return S.end(_.inexactCount),_.data})}function $e(n,i){let a=n.inexactCount===0,h=i.inexactCount===0;if(a!==h)return a?n:i;let d=n.fieldCount-n.zeroDefaultCount,S=i.fieldCount-i.zeroDefaultCount;if(d!==S)return d>S?n:i;return n.inexactCount<i.inexactCount?n:i}function _e(n){let i=0,a=[n],h=0;while(h<a.length){let d=a[h++];if(d===void 0||re(d))continue;let S=typeof d;if(d===null||S==="number"||S==="string"||S==="boolean"||S==="bigint"||d instanceof Date||d instanceof V){i++;continue}if(Array.isArray(d)){a.push(...d);continue}if(S==="object")a.push(...Object.values(d))}return i}import*as u from"zod/v4";import*as F from"zod/v4";var ce=F.object({type:F.literal("input_audio"),input_audio:F.string()}).transform((n)=>e(n,{input_audio:"inputAudio"})),pe=F.object({type:F.literal("input_audio"),inputAudio:F.string()}).transform((n)=>e(n,{inputAudio:"input_audio"}));import*as k from"zod/v4";var me=k.object({type:k.literal("document_url").default("document_url"),document_url:k.string(),document_name:k.nullable(k.string()).optional()}).transform((n)=>e(n,{document_url:"documentUrl",document_name:"documentName"})),se=k.object({type:k.literal("document_url").default("document_url"),documentUrl:k.string(),documentName:k.nullable(k.string()).optional()}).transform((n)=>e(n,{documentUrl:"document_url",documentName:"document_name"}));import*as U from"zod/v4";var de=U.object({type:U.literal("file").default("file"),file_id:U.string()}).transform((n)=>e(n,{file_id:"fileId"})),Oe=U.object({type:U.literal("file").default("file"),fileId:U.string()}).transform((n)=>e(n,{fileId:"file_id"}));import*as N from"zod/v4";import*as j from"zod/v4";var ze={Low:"low",Auto:"auto",High:"high"},be=l(ze),xe=g(ze);var Q=j.object({url:j.string(),detail:j.nullable(be).optional()}),ee=j.object({url:j.string(),detail:j.nullable(xe).optional()});var zt=o([Q,N.string()]),St=o([ee,N.string()]);var ge=N.object({type:N.literal("image_url").default("image_url"),image_url:o([Q,N.string()])}).transform((n)=>e(n,{image_url:"imageUrl"})),ie=N.object({type:N.literal("image_url").default("image_url"),imageUrl:o([ee,N.string()])}).transform((n)=>e(n,{imageUrl:"image_url"}));import*as b from"zod/v4";var Ot=o([b.int(),b.string()]),Nt=o([b.int(),b.string()]);var M=b.object({type:b.literal("reference").default("reference"),reference_ids:b.array(o([b.int(),b.string()]))}).transform((n)=>e(n,{reference_ids:"referenceIds"})),K=b.object({type:b.literal("reference").default("reference"),referenceIds:b.array(o([b.int(),b.string()]))}).transform((n)=>e(n,{referenceIds:"reference_ids"}));import*as I from"zod/v4";var z=I.object({type:I.literal("text").default("text"),text:I.string()}),J=I.object({type:I.literal("text").default("text"),text:I.string()});import*as C from"zod/v4";import*as c from"zod/v4";var Ce={WebSearch:"web_search",WebSearchPremium:"web_search_premium",CodeInterpreter:"code_interpreter",ImageGeneration:"image_generation",DocumentLibrary:"document_library"},T=l(Ce),ae=g(Ce);var Ft=o([T,c.string()]),Ut=o([ae,c.string()]);var Se=c.object({type:c.literal("tool_reference").default("tool_reference"),tool:o([T,c.string()]),title:c.string(),url:c.nullable(c.string()).optional(),favicon:c.nullable(c.string()).optional(),description:c.nullable(c.string()).optional()}),Pe=c.object({type:c.literal("tool_reference").default("tool_reference"),tool:o([ae,c.string()]),title:c.string(),url:c.nullable(c.string()).optional(),favicon:c.nullable(c.string()).optional(),description:c.nullable(c.string()).optional()});var Lt=o([Se,z,M]),At=o([Pe,J,K]);var fe=C.object({type:C.literal("thinking").default("thinking"),thinking:C.array(o([Se,z,M])),signature:C.nullable(C.string()).optional(),closed:C.boolean().optional()}),he=C.object({type:C.literal("thinking").default("thinking"),thinking:C.array(o([Pe,J,K])),signature:C.nullable(C.string()).optional(),closed:C.boolean().optional()});var Te=p("type",{image_url:ge.and(u.object({type:u.literal("image_url")})),document_url:me.and(u.object({type:u.literal("document_url")})),text:z.and(u.object({type:u.literal("text")})),reference:M.and(u.object({type:u.literal("reference")})),file:de.and(u.object({type:u.literal("file")})),thinking:fe.and(u.object({type:u.literal("thinking")})),input_audio:ce}),le=u.union([ie.and(u.object({type:u.literal("image_url")})),se.and(u.object({type:u.literal("document_url")})),J.and(u.object({type:u.literal("text")})),K.and(u.object({type:u.literal("reference")})),Oe.and(u.object({type:u.literal("file")})),he.and(u.object({type:u.literal("thinking")})),pe]);import*as y from"zod/v4";import*as f from"zod/v4";var Ht=o([f.record(f.string(),f.any()),f.string()]),Qt=o([f.record(f.string(),f.any()),f.string()]);var ke=f.object({name:f.string(),arguments:o([f.record(f.string(),f.any()),f.string()])}),Ne=f.object({name:f.string(),arguments:o([f.record(f.string(),f.any()),f.string()])});var tt=y.object({id:y.string().default("null"),type:y.string().optional(),function:ke,index:y.int().default(0)}),bt=y.object({id:y.string().default("null"),type:y.string().optional(),function:Ne,index:y.int().default(0)});var un=o([m.string(),m.array(Te)]);var rt=m.object({role:m.nullable(m.string()).optional(),content:m.nullable(o([m.string(),m.array(Te)])).optional(),tool_calls:m.nullable(m.array(tt)).optional(),tool_call_id:m.nullable(m.string()).optional(),index:m.nullable(m.int()).optional(),metadata:m.nullable(m.record(m.string(),m.any())).optional()}).transform((n)=>e(n,{tool_calls:"toolCalls",tool_call_id:"toolCallId"}));var Fe={Stop:"stop",Length:"length",Error:"error",ToolCalls:"tool_calls"},Ue=l(Fe),Je=L.object({index:L.int(),delta:rt,finish_reason:L.nullable(Ue)}).transform((n)=>e(n,{finish_reason:"finishReason"}));var ut=R.object({id:R.string(),object:R.string().optional(),created:R.int().optional(),model:R.string(),usage:W.optional(),choices:R.array(Je)});function Et(n){return r(n,(i)=>ut.parse(JSON.parse(i)),"Failed to parse 'CompletionChunk' from JSON")}
4
+ export{ct,Be,X,s,r,e,t,l,Re,g,Ct,p,o,me,se,Oe,ge,ie,z,J,T,ae,Se,Pe,fe,he,Te,le,tt,bt,rt,W,Ve,ut,Et};