@m4trix/trace-viewer 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/dist/cli.js +1862 -21
- package/dist/cli.js.map +1 -1
- package/dist/client/assets/{anthropic-Cvv_bLk5.js → anthropic-DUwMYY1S.js} +3 -3
- package/dist/client/assets/{bedrock-60CwtBlB.js → bedrock-BIja-RWN.js} +1 -1
- package/dist/client/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/dist/client/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/dist/client/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/client/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/client/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/dist/client/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/dist/client/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/dist/client/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/dist/client/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/dist/client/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/dist/client/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/dist/client/assets/index-Cl5VyaKo.js +274 -0
- package/dist/client/assets/index-DVz5tq4u.css +1 -0
- package/dist/client/assets/{node.browser-BHILlKa5.js → node.browser-C_s9kvmM.js} +1 -1
- package/dist/client/assets/{node.browser-PMfGv8gB.js → node.browser-DWucOsQl.js} +1 -1
- package/dist/client/assets/{openai-eLYIA_xR.js → openai-mbLa3c0B.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/index.d.ts +222 -4
- package/dist/index.js +1833 -5
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
- package/dist/client/assets/index-BF4yi1Kg.js +0 -149
- package/dist/client/assets/index-BZmH_c-_.css +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/node.browser-
|
|
2
|
-
import{_ as ce,g as Fo,P as qt,t as _s,k as cl}from"./index-BF4yi1Kg.js";function lt(n){return typeof n=="object"&&n!==null&&("name"in n&&n.name==="AbortError"||"message"in n&&String(n.message).includes("FetchRequestCanceledException"))}const jn=n=>{if(n instanceof Error)return n;if(typeof n=="object"&&n!==null){try{const r=Object.prototype.toString.call(n);if(r==="[object Error]"||r==="[object DOMException]"){const e=new Error(n.message,n.cause?{cause:n.cause}:{});return n.stack&&(e.stack=n.stack),n.cause&&!e.cause&&(e.cause=n.cause),n.name&&(e.name=n.name),e}}catch{}try{return new Error(JSON.stringify(n))}catch{}}return new Error(n)};var S=(()=>{class n extends Error{}return n})();class z extends S{constructor(r,e,t,s,i){super(`${z.makeMessage(r,e,t)}`),this.status=r,this.headers=s,this.requestID=s?.get("request-id"),this.workspaceID=s?.get("anthropic-workspace-id"),this.error=e,this.type=i??null}static makeMessage(r,e,t){const s=e?.message?typeof e.message=="string"?e.message:JSON.stringify(e.message):e?JSON.stringify(e):t;return r&&s?`${r} ${s}`:r?`${r} status code (no body)`:s||"(no status code or body)"}static generate(r,e,t,s){if(!r||!s)return new ut({message:t,cause:jn(e)});const i=e,a=i?.error?.type;return r===400?new qo(r,i,t,s,a):r===401?new Ko(r,i,t,s,a):r===403?new Vo(r,i,t,s,a):r===404?new Jo(r,i,t,s,a):r===409?new Xo(r,i,t,s,a):r===422?new Go(r,i,t,s,a):r===429?new Qo(r,i,t,s,a):r>=500?new Yo(r,i,t,s,a):new z(r,i,t,s,a)}}class oe extends z{constructor({message:r}={}){super(void 0,void 0,r||"Request was aborted.",void 0)}}class ut extends z{constructor({message:r,cause:e}){super(void 0,void 0,r||"Connection error.",void 0),e&&(this.cause=e)}}class gs extends ut{constructor({message:r}={}){super({message:r??"Request timed out."})}}class ll extends S{constructor(r,{cause:e}={}){super(r??"Retryable error."),e!==void 0&&(this.cause=e)}}class qo extends z{}class Ko extends z{}class Vo extends z{}class Jo extends z{}class Xo extends z{}class Go extends z{}class Qo extends z{}class Yo extends z{}let Or=n=>(Or=Array.isArray,Or(n)),ms=Or;const Zo=Symbol.for("brand.privateNullableHeaders");function*ul(n){if(!n)return;if(Zo in n){const{values:t,nulls:s}=n;yield*t.entries();for(const i of s)yield[i,null];return}let r=!1,e;n instanceof Headers?e=n.entries():ms(n)?e=n:(r=!0,e=Object.entries(n??{}));for(let t of e){const s=t[0];if(typeof s!="string")throw new TypeError("expected header name to be a string");const i=ms(t[1])?t[1]:[t[1]];let a=!1;for(const c of i)c!==void 0&&(r&&!a&&(a=!0,yield[s,Un]),yield[s,c])}}const Un=Symbol("clear"),dl=new Set(["x-stainless-helper"]),hl=(n,r)=>{const e=n?n.split(",").map(t=>t.trim()).filter(Boolean):[];for(const t of r.split(",").map(s=>s.trim()))t&&!e.includes(t)&&e.push(t);return e.join(", ")},ec=n=>{const r=new Headers,e=new Set;for(const t of n){const s=new Set;for(const[i,a]of ul(t)){const c=i.toLowerCase();if(dl.has(c)){if(a===Un)continue;a===null?(r.delete(i),e.add(c)):(r.set(i,hl(r.get(i),a)),e.delete(c));continue}(a===Un||!s.has(c))&&(r.delete(i),s.add(c),a===Un)||(a===null?(r.delete(i),e.add(c)):(r.append(i,a),e.delete(c)))}}return{[Zo]:!0,values:r,nulls:e}};var fl={};const Gt=n=>{if(typeof globalThis.process<"u")return fl?.[n]?.trim()||void 0;if(typeof globalThis.Deno<"u")return globalThis.Deno.env?.get?.(n)?.trim()||void 0};function w(n,r,e,t,s){if(typeof r=="function"?n!==r||!0:!r.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r.set(n,e),e}function o(n,r,e,t){if(e==="a"&&!t)throw new TypeError("Private accessor was defined without a getter");if(typeof r=="function"?n!==r||!t:!r.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?t:e==="a"?t.call(n):t?t.value:r.get(n)}const pl=/^[a-z][a-z0-9+.-]*:/i,_l=n=>pl.test(n);let J=n=>(J=Array.isArray,J(n)),ws=J;function Fn(n){return typeof n!="object"?{}:n??{}}function ys(n){if(!n)return!0;for(const r in n)return!1;return!0}function gl(n,r){return Object.prototype.hasOwnProperty.call(n,r)}function bs(n){return n!=null&&typeof n=="object"&&!Array.isArray(n)}const Gn=(n,r)=>{if(typeof r!="number"||!Number.isInteger(r))throw new S(`${n} must be an integer`);if(r<0)throw new S(`${n} must be a positive integer`);return r},tc=n=>{try{return JSON.parse(n)}catch{return}};const Be=(n,r)=>new Promise(e=>{if(r?.aborted)return e();const t=()=>{clearTimeout(s),e()},s=setTimeout(()=>{r?.removeEventListener("abort",t),e()},n);r?.addEventListener("abort",t,{once:!0})}),ge="0.131.0",ml=()=>typeof window<"u"&&typeof window.document<"u"&&typeof navigator<"u";function wl(){return typeof Deno<"u"&&Deno.build!=null?"deno":typeof EdgeRuntime<"u"?"edge":Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]"?"node":"unknown"}const yl=()=>{const n=wl();if(n==="deno")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ge,"X-Stainless-OS":ks(Deno.build.os),"X-Stainless-Arch":vs(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":typeof Deno.version=="string"?Deno.version:Deno.version?.deno??"unknown"};if(typeof EdgeRuntime<"u")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ge,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":globalThis.process?.version??"unknown"};if(n==="node")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ge,"X-Stainless-OS":ks(globalThis.process.platform??"unknown"),"X-Stainless-Arch":vs(globalThis.process.arch??"unknown"),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":globalThis.process.version??"unknown"};const r=bl();return r?{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ge,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${r.browser}`,"X-Stainless-Runtime-Version":r.version}:{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ge,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}};function bl(){if(typeof navigator>"u"||!navigator)return null;const n=[{key:"edge",pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"chrome",pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"firefox",pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"safari",pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}];for(const{key:r,pattern:e}of n){const t=e.exec(navigator.userAgent);if(t){const s=t[1]||0,i=t[2]||0,a=t[3]||0;return{browser:r,version:`${s}.${i}.${a}`}}}return null}const vs=n=>n==="x32"?"x32":n==="x86_64"||n==="x64"?"x64":n==="arm"?"arm":n==="aarch64"||n==="arm64"?"arm64":n?`other:${n}`:"unknown",ks=n=>(n=n.toLowerCase(),n.includes("ios")?"iOS":n==="android"?"Android":n==="darwin"?"MacOS":n==="win32"?"Windows":n==="freebsd"?"FreeBSD":n==="openbsd"?"OpenBSD":n==="linux"?"Linux":n?`Other:${n}`:"Unknown");let Ss;const es=()=>Ss??(Ss=yl()),qn=new WeakMap,nc=typeof globalThis.FinalizationRegistry=="function"?new globalThis.FinalizationRegistry(n=>De(n)):null;function vl(n,r){return()=>n.removeEventListener("abort",r)}function kl(n,r,e){qn.set(n,vl(r,e))}function Sl(n,r){qn.has(r)&&nc?.register(n,r,r)}function De(n){const r=qn.get(n);r&&(qn.delete(n),nc?.unregister(n),r())}function xl(){if(typeof fetch<"u")return fetch;throw new Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new Anthropic({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}function rc(...n){const r=globalThis.ReadableStream;if(typeof r>"u")throw new Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new r(...n)}function sc(n){let r=Symbol.asyncIterator in n?n[Symbol.asyncIterator]():n[Symbol.iterator]();return rc({start(){},async pull(e){const{done:t,value:s}=await r.next();t?e.close():e.enqueue(s)},async cancel(){await r.return?.()}})}function ts(n){if(n[Symbol.asyncIterator])return n;const r=n.getReader();return{async next(){try{const e=await r.read();return e?.done&&r.releaseLock(),e}catch(e){throw r.releaseLock(),e}},async return(){const e=r.cancel();return r.releaseLock(),await e,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function Rl(n){if(n===null||typeof n!="object")return;if(n[Symbol.asyncIterator]){await n[Symbol.asyncIterator]().return?.();return}const r=n.getReader(),e=r.cancel();r.releaseLock(),await e}const Al=({headers:n,body:r})=>({bodyHeaders:{"content-type":"application/json"},body:JSON.stringify(r)}),ic="RFC3986",ac=n=>String(n),xs={RFC1738:n=>String(n).replace(/%20/g,"+"),RFC3986:ac},El="RFC1738";let Cr=(n,r)=>(Cr=Object.hasOwn??Function.prototype.call.bind(Object.prototype.hasOwnProperty),Cr(n,r));const le=(()=>{const n=[];for(let r=0;r<256;++r)n.push("%"+((r<16?"0":"")+r.toString(16)).toUpperCase());return n})(),Qn=1024,Tl=(n,r,e,t,s)=>{if(n.length===0)return n;let i=n;if(typeof n=="symbol"?i=Symbol.prototype.toString.call(n):typeof n!="string"&&(i=String(n)),e==="iso-8859-1")return escape(i).replace(/%u[0-9a-f]{4}/gi,function(c){return"%26%23"+parseInt(c.slice(2),16)+"%3B"});let a="";for(let c=0;c<i.length;c+=Qn){const u=i.length>=Qn?i.slice(c,c+Qn):i,l=[];for(let p=0;p<u.length;++p){let d=u.charCodeAt(p);if(d===45||d===46||d===95||d===126||d>=48&&d<=57||d>=65&&d<=90||d>=97&&d<=122||s===El&&(d===40||d===41)){l[l.length]=u.charAt(p);continue}if(d<128){l[l.length]=le[d];continue}if(d<2048){l[l.length]=le[192|d>>6]+le[128|d&63];continue}if(d<55296||d>=57344){l[l.length]=le[224|d>>12]+le[128|d>>6&63]+le[128|d&63];continue}p+=1,d=65536+((d&1023)<<10|u.charCodeAt(p)&1023),l[l.length]=le[240|d>>18]+le[128|d>>12&63]+le[128|d>>6&63]+le[128|d&63]}a+=l.join("")}return a};function $l(n){return!n||typeof n!="object"?!1:!!(n.constructor&&n.constructor.isBuffer&&n.constructor.isBuffer(n))}function Rs(n,r){if(J(n)){const e=[];for(let t=0;t<n.length;t+=1)e.push(r(n[t]));return e}return r(n)}const oc={brackets(n){return String(n)+"[]"},comma:"comma",indices(n,r){return String(n)+"["+r+"]"},repeat(n){return String(n)}},cc=function(n,r){Array.prototype.push.apply(n,J(r)?r:[r])};let As;const W={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:Tl,encodeValuesOnly:!1,format:ic,formatter:ac,indices:!1,serializeDate(n){return(As??(As=Function.prototype.call.bind(Date.prototype.toISOString)))(n)},skipNulls:!1,strictNullHandling:!1};function Il(n){return typeof n=="string"||typeof n=="number"||typeof n=="boolean"||typeof n=="symbol"||typeof n=="bigint"}const Yn={};function lc(n,r,e,t,s,i,a,c,u,l,p,d,g,_,m,y,x,E){let b=n,k=E,R=0,T=!1;for(;(k=k.get(Yn))!==void 0&&!T;){const I=k.get(n);if(R+=1,typeof I<"u"){if(I===R)throw new RangeError("Cyclic object value");T=!0}typeof k.get(Yn)>"u"&&(R=0)}if(typeof l=="function"?b=l(r,b):b instanceof Date?b=g?.(b):e==="comma"&&J(b)&&(b=Rs(b,function(I){return I instanceof Date?g?.(I):I})),b===null){if(i)return u&&!y?u(r,W.encoder,x,"key",_):r;b=""}if(Il(b)||$l(b)){if(u){const I=y?r:u(r,W.encoder,x,"key",_);return[m?.(I)+"="+m?.(u(b,W.encoder,x,"value",_))]}return[m?.(r)+"="+m?.(String(b))]}const $=[];if(typeof b>"u")return $;let C;if(e==="comma"&&J(b))y&&u&&(b=Rs(b,u)),C=[{value:b.length>0?b.join(",")||null:void 0}];else if(J(l))C=l;else{const I=Object.keys(b);C=p?I.sort(p):I}const M=c?String(r).replace(/\./g,"%2E"):String(r),L=t&&J(b)&&b.length===1?M+"[]":M;if(s&&J(b)&&b.length===0)return L+"[]";for(let I=0;I<C.length;++I){const ne=C[I],we=typeof ne=="object"&&typeof ne.value<"u"?ne.value:b[ne];if(a&&we===null)continue;const ye=d&&c?ne.replace(/\./g,"%2E"):ne,ol=J(b)?typeof e=="function"?e(L,ye):L:L+(d?"."+ye:"["+ye+"]");E.set(n,R);const ps=new WeakMap;ps.set(Yn,E),cc($,lc(we,ol,e,t,s,i,a,c,e==="comma"&&y&&J(b)?null:u,l,p,d,g,_,m,y,x,ps))}return $}function Pl(n=W){if(typeof n.allowEmptyArrays<"u"&&typeof n.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof n.encodeDotInKeys<"u"&&typeof n.encodeDotInKeys!="boolean")throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(n.encoder!==null&&typeof n.encoder<"u"&&typeof n.encoder!="function")throw new TypeError("Encoder has to be a function.");const r=n.charset||W.charset;if(typeof n.charset<"u"&&n.charset!=="utf-8"&&n.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");let e=ic;if(typeof n.format<"u"){if(!Cr(xs,n.format))throw new TypeError("Unknown format option provided.");e=n.format}const t=xs[e];let s=W.filter;(typeof n.filter=="function"||J(n.filter))&&(s=n.filter);let i;if(n.arrayFormat&&n.arrayFormat in oc?i=n.arrayFormat:"indices"in n?i=n.indices?"indices":"repeat":i=W.arrayFormat,"commaRoundTrip"in n&&typeof n.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");const a=typeof n.allowDots>"u"?n.encodeDotInKeys?!0:W.allowDots:!!n.allowDots;return{addQueryPrefix:typeof n.addQueryPrefix=="boolean"?n.addQueryPrefix:W.addQueryPrefix,allowDots:a,allowEmptyArrays:typeof n.allowEmptyArrays=="boolean"?!!n.allowEmptyArrays:W.allowEmptyArrays,arrayFormat:i,charset:r,charsetSentinel:typeof n.charsetSentinel=="boolean"?n.charsetSentinel:W.charsetSentinel,commaRoundTrip:!!n.commaRoundTrip,delimiter:typeof n.delimiter>"u"?W.delimiter:n.delimiter,encode:typeof n.encode=="boolean"?n.encode:W.encode,encodeDotInKeys:typeof n.encodeDotInKeys=="boolean"?n.encodeDotInKeys:W.encodeDotInKeys,encoder:typeof n.encoder=="function"?n.encoder:W.encoder,encodeValuesOnly:typeof n.encodeValuesOnly=="boolean"?n.encodeValuesOnly:W.encodeValuesOnly,filter:s,format:e,formatter:t,serializeDate:typeof n.serializeDate=="function"?n.serializeDate:W.serializeDate,skipNulls:typeof n.skipNulls=="boolean"?n.skipNulls:W.skipNulls,sort:typeof n.sort=="function"?n.sort:null,strictNullHandling:typeof n.strictNullHandling=="boolean"?n.strictNullHandling:W.strictNullHandling}}function Ml(n,r={}){let e=n;const t=Pl(r);let s,i;typeof t.filter=="function"?(i=t.filter,e=i("",e)):J(t.filter)&&(i=t.filter,s=i);const a=[];if(typeof e!="object"||e===null)return"";const c=oc[t.arrayFormat],u=c==="comma"&&t.commaRoundTrip;s||(s=Object.keys(e)),t.sort&&s.sort(t.sort);const l=new WeakMap;for(let g=0;g<s.length;++g){const _=s[g];t.skipNulls&&e[_]===null||cc(a,lc(e[_],_,c,u,t.allowEmptyArrays,t.strictNullHandling,t.skipNulls,t.encodeDotInKeys,t.encode?t.encoder:null,t.filter,t.sort,t.allowDots,t.serializeDate,t.format,t.formatter,t.encodeValuesOnly,t.charset,l))}const p=a.join(t.delimiter);let d=t.addQueryPrefix===!0?"?":"";return t.charsetSentinel&&(t.charset==="iso-8859-1"?d+="utf8=%26%2310003%3B&":d+="utf8=%E2%9C%93&"),p.length>0?d+p:""}function Ol(n){return Ml(n,{arrayFormat:"brackets"})}const Cl="urn:ietf:params:oauth:grant-type:jwt-bearer",Ll="refresh_token",uc="/v1/oauth/token",Kn="oauth-2025-04-20",Nl="oidc-federation-2026-04-01",Bl=120,ns=30,Dl=5,Es=1<<20;function dc(n){if(!n)return;let r;try{r=new URL(n)}catch(t){throw new B(`Invalid token endpoint base URL "${n}": ${t}`)}if(r.protocol==="https:")return;const e=r.hostname.toLowerCase().replace(/^\[|\]$/g,"");if(!(r.protocol==="http:"&&(e==="localhost"||e==="127.0.0.1"||e==="::1")))throw new B(`Refusing to send credential over non-https token endpoint "${n}"`)}async function hc(n,r){const e=await Hl(n);let t;try{t=JSON.parse(e)}catch{throw new B(`Token endpoint returned non-JSON response (status ${n.status})`,n.status,ie(e),r)}if(!t.access_token)throw new B(`Token endpoint response missing access_token: ${JSON.stringify(ie(t))}`,n.status,ie(t),r);if(t.token_type&&t.token_type.toLowerCase()!=="bearer")throw new B(`Token endpoint response: unsupported token_type "${t.token_type}" (want Bearer)`,n.status,ie(t),r);return t}const Zn=2e3,Ul=new Set(["error","error_description","error_uri"]);function ie(n){if(n==null)return n;if(typeof n=="string"){let r;try{r=JSON.parse(n)}catch{return n.length<=Zn?n:n.slice(0,Zn)+`... <${n.length-Zn} more chars>`}return JSON.stringify(ie(r))}if(typeof n=="object"&&!Array.isArray(n)){const r={};for(const[e,t]of Object.entries(n))Ul.has(e)&&(r[e]=t);return r}return null}async function fc(n,r=e=>console.warn(`anthropic-sdk: ${e}`)){if(typeof process>"u"||process.platform==="win32")return;const{fs:e}=await ce(async()=>{const{fs:a}=await import("./node.browser-BHILlKa5.js");return{fs:a}},__vite__mapDeps([0,1,2]));let t=n,s;try{t=await e.promises.realpath(n),s=await e.promises.stat(t)}catch{return}const i=s.mode&511;if(i&18)throw new B(`Credentials file at ${t} is group/world-writable (mode 0o${i.toString(8)}); this allows other local users to plant tokens. Run \`chmod 600 ${t}\`.`);if(i&36)throw new B(`Credentials file at ${t} is group/world-readable (mode 0o${i.toString(8)}); run \`chmod 600 ${t}\` before retrying.`);typeof process.getuid=="function"&&s.uid!==process.getuid()&&r(`credentials file at ${t} is owned by uid ${s.uid} (current process uid ${process.getuid()}); verify this is intentional.`)}async function pc(n,r){const{fs:e,path:t}=await ce(async()=>{const{fs:a,path:c}=await import("./node.browser-BHILlKa5.js");return{fs:a,path:c}},__vite__mapDeps([0,1,2])),s=t.dirname(n);await e.promises.mkdir(s,{recursive:!0,mode:448});const i=`${n}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;try{const a=await e.promises.open(i,"w",384);try{await a.writeFile(JSON.stringify(r,null,2)),await a.sync()}finally{await a.close()}await e.promises.rename(i,n)}catch(a){throw await e.promises.unlink(i).catch(()=>{}),a}try{const a=await e.promises.open(s,"r");try{await a.sync()}finally{await a.close()}}catch{}}async function Hl(n){if(!n.body)return"";const r=n.body.getReader(),e=[];let t=0;for(;;){const{done:i,value:a}=await r.read();if(i)break;if(t+a.length>Es){const c=Es-t;c>0&&e.push(a.subarray(0,c)),await r.cancel();break}e.push(a),t+=a.length}let s;if(e.length===1)s=e[0];else{s=new Uint8Array(e.reduce((a,c)=>a+c.length,0));let i=0;for(const a of e)s.set(a,i),i+=a.length}return new TextDecoder("utf-8").decode(s)}class B extends S{constructor(r,e=null,t=null,s=null){super(r),this.statusCode=e,this.body=t,this.requestId=s}}function Ue(){return Math.floor(Date.now()/1e3)}class Wl{constructor(r,e){this.cached=null,this.pendingRefresh=null,this.nextForce=!1,this.lastAdvisoryError=0,this.provider=r,this.onAdvisoryRefreshError=e}async getToken(){const r=this.nextForce;this.nextForce=!1;const e=this.cached;if(r||e==null)return(await this.refresh(r)).token;if(e.expiresAt==null)return e.token;const t=e.expiresAt-Ue();return t>Bl?e.token:t>ns?(this.backgroundRefresh(),e.token):(await this.refresh()).token}invalidate(){this.cached=null,this.nextForce=!0}refresh(r=!1){return this.pendingRefresh&&!r?this.pendingRefresh:this.doRefresh(r)}backgroundRefresh(){this.pendingRefresh||Ue()-this.lastAdvisoryError<Dl||this.doRefresh().catch(r=>{this.lastAdvisoryError=Ue(),this.onAdvisoryRefreshError?.(r)})}doRefresh(r=!1){return this.pendingRefresh=this.provider(r?{forceRefresh:!0}:void 0).then(e=>(this.cached=e,this.pendingRefresh=null,e),e=>{throw this.pendingRefresh=null,e}),this.pendingRefresh}}var zl={};const P=n=>{if(typeof globalThis.process<"u")return zl?.[n]?.trim()||void 0;if(typeof globalThis.Deno<"u")return globalThis.Deno.env?.get?.(n)?.trim()||void 0};function jl(n){let r=0;for(const s of n)r+=s.length;const e=new Uint8Array(r);let t=0;for(const s of n)e.set(s,t),t+=s.length;return e}let Ts;function _c(n){let r;return(Ts??(r=new globalThis.TextEncoder,Ts=r.encode.bind(r)))(n)}let $s;function Lr(n){let r;return($s??(r=new globalThis.TextDecoder,$s=r.decode.bind(r)))(n)}const Fl=n=>{if(typeof globalThis.Buffer<"u"){const r=globalThis.Buffer.from(n,"base64");return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}if(typeof atob<"u"){const r=atob(n),e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}throw new S("Cannot decode base64 string; Expected `Buffer` or `atob` to be defined")},Vn="warn",Jn={off:0,error:200,warn:300,info:400,debug:500},Nr=(n,r,e)=>{if(n){if(gl(Jn,n))return n;e.warn(`${r} was set to ${JSON.stringify(n)}, expected one of ${JSON.stringify(Object.keys(Jn))}`)}};function st(){}function Qt(n,r,e){return!r||Jn[n]>Jn[e]?st:r[n].bind(r)}const ql={error:st,warn:st,info:st,debug:st};let Is=new WeakMap;function Br(n,r){const e=Is.get(n);if(e&&e[0]===r)return e[1];const t={error:Qt("error",n,r),warn:Qt("warn",n,r),info:Qt("info",n,r),debug:Qt("debug",n,r)};return Is.set(n,[r,t]),t}function O(n){const r=n.logger,e=n.logLevel??"off";return r?Br(r,e):ql}let Ps,er;function Kl(){const n=P("ANTHROPIC_LOG");return(!er||n!==Ps)&&(Ps=n,er=Br(console,Nr(n,"process.env['ANTHROPIC_LOG']",Br(console,Vn))??Vn)),er}function Ae(n,r,e){n.debug!==st&&n.debug(r,Vl(e))}const Vl=n=>(n.options&&(n.options={...n.options},delete n.options.headers),n.headers&&(n.headers=Object.fromEntries((n.headers instanceof Headers?[...n.headers]:Object.entries(n.headers)).map(([r,e])=>[r,r.toLowerCase()==="authorization"||r.toLowerCase()==="api-key"||r.toLowerCase()==="x-api-key"||r.toLowerCase()==="cookie"||r.toLowerCase()==="set-cookie"?"***":e]))),"retryOfRequestLogID"in n&&(n.retryOfRequestLogID&&(n.retryOf=n.retryOfRequestLogID),delete n.retryOfRequestLogID),n);let Dr=function(){const{crypto:n}=globalThis;if(n?.randomUUID)return Dr=n.randomUUID.bind(n),n.randomUUID();const r=new Uint8Array(1),e=n?()=>n.getRandomValues(r)[0]:()=>Math.random()*255&255;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,t=>(+t^e()&15>>+t/4).toString(16))};const gc="1.0",Jl=/^[A-Za-z0-9_.-]+$/;function mc(n){if(!n)throw new Error("profile name is empty");if(n==="."||n==="..")throw new Error(`profile name "${n}" is not allowed`);if(n.includes("/")||n.includes("\\"))throw new Error(`profile name "${n}" must not contain path separators`);if(!Jl.test(n))throw new Error(`profile name "${n}" contains disallowed characters (allowed: letters, digits, '_', '.', '-')`)}const Xl=async n=>{var r,e;const t=await rs();if(t===null)return null;const s=n??await wc();if(s===null)return null;mc(s);const{fs:i,path:a}=await ce(async()=>{const{fs:d,path:g}=await import("./node.browser-BHILlKa5.js");return{fs:d,path:g}},__vite__mapDeps([0,1,2])),c=a.join(t,"configs",`${s}.json`);let u;try{u=await i.promises.readFile(c,"utf-8")}catch(d){if(d?.code!=="ENOENT")throw new Error(`failed to read config file ${c}: ${d}`);u=null}if(u===null){const d=P("ANTHROPIC_ORGANIZATION_ID"),g=P("ANTHROPIC_IDENTITY_TOKEN_FILE"),_=P("ANTHROPIC_FEDERATION_RULE_ID");return _&&d?{fromFile:!1,config:{organization_id:d,workspace_id:P("ANTHROPIC_WORKSPACE_ID"),base_url:P("ANTHROPIC_BASE_URL"),authentication:{type:"oidc_federation",federation_rule_id:_,service_account_id:P("ANTHROPIC_SERVICE_ACCOUNT_ID"),identity_token:g?{source:"file",path:g}:void 0,scope:P("ANTHROPIC_SCOPE")}}}:null}let l;try{l=JSON.parse(u)}catch(d){throw new Error(`failed to parse config file ${c}: ${d}`)}if(!l.authentication)throw new Error(`config file ${c} is missing "authentication"`);const p=l.authentication.type;if(p!=="oidc_federation"&&p!=="user_oauth")throw new Error(`authentication.type "${p}" is not a known authentication type`);if(l.organization_id??(l.organization_id=P("ANTHROPIC_ORGANIZATION_ID")),l.workspace_id??(l.workspace_id=P("ANTHROPIC_WORKSPACE_ID")),l.base_url??(l.base_url=P("ANTHROPIC_BASE_URL")),(r=l.authentication).scope??(r.scope=P("ANTHROPIC_SCOPE")),l.authentication.type==="oidc_federation"){if(!l.authentication.identity_token){const d=P("ANTHROPIC_IDENTITY_TOKEN_FILE");d&&(l.authentication.identity_token={source:"file",path:d})}l.authentication.federation_rule_id||(l.authentication.federation_rule_id=P("ANTHROPIC_FEDERATION_RULE_ID")??""),(e=l.authentication).service_account_id??(e.service_account_id=P("ANTHROPIC_SERVICE_ACCOUNT_ID"))}return{config:l,fromFile:!0}},Gl=async(n,r)=>{if(n?.authentication.credentials_path)return n.authentication.credentials_path;const e=await rs();if(!e)return null;const t=r??await wc();if(!t)return null;mc(t);const{path:s}=await ce(async()=>{const{path:i}=await import("./node.browser-BHILlKa5.js");return{path:i}},__vite__mapDeps([0,1,2]));return s.join(e,"credentials",`${t}.json`)},rs=async()=>{if(!Ql())return null;const{path:n}=await ce(async()=>{const{path:i}=await import("./node.browser-BHILlKa5.js");return{path:i}},__vite__mapDeps([0,1,2])),r=P("ANTHROPIC_CONFIG_DIR");if(r)return r;if(es()["X-Stainless-OS"]==="Windows"){const i=P("APPDATA");if(i)return n.join(i,"Anthropic");const a=P("USERPROFILE");return a?n.join(a,"AppData","Roaming","Anthropic"):null}const t=P("XDG_CONFIG_HOME");if(t)return n.join(t,"anthropic");const s=P("HOME");return s?n.join(s,".config","anthropic"):null},Ql=()=>{const n=es()["X-Stainless-Runtime"];return n==="node"||n==="deno"},wc=async()=>{const n=await rs();if(!n)return null;const r=P("ANTHROPIC_PROFILE");if(r)return r;const{fs:e,path:t}=await ce(async()=>{const{fs:i,path:a}=await import("./node.browser-BHILlKa5.js");return{fs:i,path:a}},__vite__mapDeps([0,1,2])),s=t.join(n,"active_config");try{return(await e.promises.readFile(s,"utf-8")).trim()||"default"}catch(i){if(i?.code!=="ENOENT")throw new Error(`failed to read ${s}: ${i}`);return"default"}};function Ms(n){if(!n)throw new S("Identity token file path is empty");return async()=>{const{fs:r}=await ce(async()=>{const{fs:s}=await import("./node.browser-BHILlKa5.js");return{fs:s}},__vite__mapDeps([0,1,2]));let e;try{e=await r.promises.readFile(n,"utf-8")}catch(s){throw new S(`Failed to read identity token file at ${n}: ${s}`)}const t=e.trim();if(!t)throw new S(`Identity token file at ${n} is empty`);return t}}function Yl(n){if(!n)throw new S("Identity token value is empty");return()=>n}function Zl(n){return async()=>{dc(n.baseURL);const r=await n.identityTokenProvider();if(r.length>16*1024)throw new B(`Identity token is ${Math.ceil(r.length/1024)} KiB, exceeds the 16 KiB assertion limit`);const e={grant_type:Cl,assertion:r,federation_rule_id:n.federationRuleId,organization_id:n.organizationId};n.serviceAccountId&&(e.service_account_id=n.serviceAccountId),n.workspaceId&&(e.workspace_id=n.workspaceId);const t=`${n.baseURL}${uc}`;let s;try{s=await n.fetch(t,{method:"POST",headers:{"Content-Type":"application/json","anthropic-beta":`${Kn},${Nl}`,"User-Agent":n.userAgent||`anthropic-sdk-typescript/${ge} oidcFederationProvider`},body:JSON.stringify(e)})}catch(u){throw new B(`Failed to reach token endpoint ${t}: ${u}`)}const i=s.headers.get("Request-Id");if(!s.ok){const u=await s.text().catch(()=>""),l=ie(u);let p="";throw s.status===401&&(p=` Ensure your federation rule matches your identity token. ${n.workspaceId?"":"If your federation rule is scoped to multiple workspaces, set the ANTHROPIC_WORKSPACE_ID environment variable, the 'workspace_id' config key, or the `workspaceId` option. "}View your authentication events in the Workload identity page of Claude Console for more details.`),new B(`Token exchange failed with status ${s.status}${i?` (request-id ${i})`:""}: ${l}${p}`,s.status,l,i)}const a=await hc(s,i),c=Number(a.expires_in);if(!Number.isFinite(c))throw new B(`Token endpoint response missing required fields: ${JSON.stringify(ie(a))}`,s.status,ie(a),i);return{token:a.access_token,expiresAt:Ue()+c}}}function eu(n){return async r=>{const{fs:e}=await ce(async()=>{const{fs:x}=await import("./node.browser-BHILlKa5.js");return{fs:x}},__vite__mapDeps([0,1,2]));await fc(n.credentialsPath,n.onSafetyWarning);let t;try{t=await e.promises.readFile(n.credentialsPath,"utf-8")}catch(x){throw new B(`Credentials file not found at ${n.credentialsPath}: ${x}`)}let s;try{s=JSON.parse(t)}catch(x){throw new B(`Credentials file at ${n.credentialsPath} is not valid JSON: ${x}`)}const i=s.access_token;if(!i)throw new B(`Credentials file at ${n.credentialsPath} must include 'access_token'`);const a=s.expires_at;if(!r?.forceRefresh&&(a==null||Ue()<a-ns))return{token:i,expiresAt:a??null};const c=s.refresh_token;if(!n.clientId||!c)throw new B(`Access token at ${n.credentialsPath} has expired and no refresh is available (client_id ${n.clientId?"set":"empty"}, refresh_token ${c?"set":"empty"})`);dc(n.baseURL);const u={grant_type:Ll,refresh_token:c,client_id:n.clientId},l=`${n.baseURL}${uc}`;let p;try{p=await n.fetch(l,{method:"POST",headers:{"Content-Type":"application/json","anthropic-beta":Kn,"User-Agent":n.userAgent||`anthropic-sdk-typescript/${ge} userOAuthProvider`},body:JSON.stringify(u)})}catch(x){throw new B(`User OAuth refresh failed to reach token endpoint: ${x}`)}const d=p.headers.get("Request-Id");if(!p.ok){const x=await p.text().catch(()=>"");throw new B(`User OAuth refresh failed (HTTP ${p.status}): ${ie(x)}`,p.status,ie(x),d)}const g=await hc(p,d),_=Number(g.expires_in);if(!Number.isFinite(_))throw new B(`User OAuth refresh response missing or invalid expires_in: ${JSON.stringify(ie(g))}`,p.status,ie(g),d);const m=Ue()+_,y=g.refresh_token||c;return await pc(n.credentialsPath,{...s,version:gc,type:"oauth_token",access_token:g.access_token,expires_at:m,refresh_token:y}),{token:g.access_token,expiresAt:m}}}function yc(n,r){const e=n.authentication.credentials_path??null,t=(n.base_url||r.baseURL).replace(/\/+$/,""),s=nu(n,e,t,r),i={};return n.workspace_id&&n.authentication.type==="user_oauth"&&(i["anthropic-workspace-id"]=n.workspace_id),{provider:s,extraHeaders:i,baseURL:n.base_url||void 0}}async function tu(n,r){const e=await Xl(r);if(!e)return null;const{config:t,fromFile:s}=e,i=t.authentication.credentials_path||!s?t:{...t,authentication:{...t.authentication,credentials_path:await Gl(t,r)??void 0}};return yc(i,n)}function nu(n,r,e,t){switch(n.authentication.type){case"oidc_federation":{const s=n.authentication,i=ru(s);if(!i)throw new B("oidc_federation config requires an identity token (set authentication.identity_token, ANTHROPIC_IDENTITY_TOKEN_FILE, or ANTHROPIC_IDENTITY_TOKEN)");if(!s.federation_rule_id)throw new B("oidc_federation config requires 'federation_rule_id'. Set it in authentication.federation_rule_id in your profile, or via ANTHROPIC_FEDERATION_RULE_ID (profile takes precedence).");if(!n.organization_id)throw new B("oidc_federation config requires organization_id (set ANTHROPIC_ORGANIZATION_ID or config.organization_id)");const a=Zl({identityTokenProvider:i,federationRuleId:s.federation_rule_id,organizationId:n.organization_id,serviceAccountId:s.service_account_id,workspaceId:n.workspace_id,baseURL:e,fetch:t.fetch,userAgent:t.userAgent});return r?su(a,r,t.onCacheWriteError,t.onSafetyWarning):a}case"user_oauth":{if(!r)throw new B("user_oauth config requires authentication.credentials_path (or load via a profile so it defaults to <config_dir>/credentials/<profile>.json)");return eu({credentialsPath:r,clientId:n.authentication.client_id,baseURL:e,fetch:t.fetch,userAgent:t.userAgent,onSafetyWarning:t.onSafetyWarning})}default:{const s=n.authentication.type;throw new B(`authentication.type "${s}" is not a known authentication type`)}}}function ru(n){if(n.identity_token){const t=n.identity_token.source;if(t!=="file")throw new B(`identity_token.source "${t}" is not supported by this SDK version (only "file")`);if(!n.identity_token.path)throw new B('identity_token.source "file" requires a non-empty path');return Ms(n.identity_token.path)}const r=P("ANTHROPIC_IDENTITY_TOKEN_FILE");if(r)return Ms(r);const e=P("ANTHROPIC_IDENTITY_TOKEN");return e?Yl(e):null}function su(n,r,e,t){return async s=>{const{fs:i}=await ce(async()=>{const{fs:u}=await import("./node.browser-BHILlKa5.js");return{fs:u}},__vite__mapDeps([0,1,2]));await fc(r,t);let a;try{const u=await i.promises.readFile(r,"utf-8");a=JSON.parse(u);const l=a?.access_token;if(l&&!s?.forceRefresh){const p=a?.expires_at;if(p==null||Ue()<p-ns)return{token:l,expiresAt:p??null}}}catch(u){u?.code!=="ENOENT"&&!(u instanceof SyntaxError)&&e?.(u)}const c=await n(s);try{await pc(r,{...a??{},version:gc,type:"oauth_token",access_token:c.token,expires_at:c.expiresAt})}catch(u){e?.(u)}return c}}var G,Q,ss=(()=>{class n{constructor(){G.set(this,void 0),Q.set(this,void 0),w(this,G,new Uint8Array),w(this,Q,null)}decode(e){if(e==null)return[];const t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e=="string"?_c(e):e;w(this,G,jl([o(this,G,"f"),t]));const s=[];let i;for(;(i=iu(o(this,G,"f"),o(this,Q,"f")))!=null;){if(i.carriage&&o(this,Q,"f")==null){w(this,Q,i.index);continue}if(o(this,Q,"f")!=null&&(i.index!==o(this,Q,"f")+1||i.carriage)){s.push(Lr(o(this,G,"f").subarray(0,o(this,Q,"f")-1))),w(this,G,o(this,G,"f").subarray(o(this,Q,"f"))),w(this,Q,null);continue}const a=o(this,Q,"f")!==null?i.preceding-1:i.preceding,c=Lr(o(this,G,"f").subarray(0,a));s.push(c),w(this,G,o(this,G,"f").subarray(i.index)),w(this,Q,null)}return s}flush(){return o(this,G,"f").length?this.decode(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/node.browser-C_s9kvmM.js","assets/index-Cl5VyaKo.js","assets/index-DVz5tq4u.css","assets/node.browser-DWucOsQl.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as ce,g as Fo,P as qt,t as _s,k as cl}from"./index-Cl5VyaKo.js";function lt(n){return typeof n=="object"&&n!==null&&("name"in n&&n.name==="AbortError"||"message"in n&&String(n.message).includes("FetchRequestCanceledException"))}const jn=n=>{if(n instanceof Error)return n;if(typeof n=="object"&&n!==null){try{const r=Object.prototype.toString.call(n);if(r==="[object Error]"||r==="[object DOMException]"){const e=new Error(n.message,n.cause?{cause:n.cause}:{});return n.stack&&(e.stack=n.stack),n.cause&&!e.cause&&(e.cause=n.cause),n.name&&(e.name=n.name),e}}catch{}try{return new Error(JSON.stringify(n))}catch{}}return new Error(n)};var S=(()=>{class n extends Error{}return n})();class z extends S{constructor(r,e,t,s,i){super(`${z.makeMessage(r,e,t)}`),this.status=r,this.headers=s,this.requestID=s?.get("request-id"),this.workspaceID=s?.get("anthropic-workspace-id"),this.error=e,this.type=i??null}static makeMessage(r,e,t){const s=e?.message?typeof e.message=="string"?e.message:JSON.stringify(e.message):e?JSON.stringify(e):t;return r&&s?`${r} ${s}`:r?`${r} status code (no body)`:s||"(no status code or body)"}static generate(r,e,t,s){if(!r||!s)return new ut({message:t,cause:jn(e)});const i=e,a=i?.error?.type;return r===400?new qo(r,i,t,s,a):r===401?new Ko(r,i,t,s,a):r===403?new Vo(r,i,t,s,a):r===404?new Jo(r,i,t,s,a):r===409?new Xo(r,i,t,s,a):r===422?new Go(r,i,t,s,a):r===429?new Qo(r,i,t,s,a):r>=500?new Yo(r,i,t,s,a):new z(r,i,t,s,a)}}class oe extends z{constructor({message:r}={}){super(void 0,void 0,r||"Request was aborted.",void 0)}}class ut extends z{constructor({message:r,cause:e}){super(void 0,void 0,r||"Connection error.",void 0),e&&(this.cause=e)}}class gs extends ut{constructor({message:r}={}){super({message:r??"Request timed out."})}}class ll extends S{constructor(r,{cause:e}={}){super(r??"Retryable error."),e!==void 0&&(this.cause=e)}}class qo extends z{}class Ko extends z{}class Vo extends z{}class Jo extends z{}class Xo extends z{}class Go extends z{}class Qo extends z{}class Yo extends z{}let Or=n=>(Or=Array.isArray,Or(n)),ms=Or;const Zo=Symbol.for("brand.privateNullableHeaders");function*ul(n){if(!n)return;if(Zo in n){const{values:t,nulls:s}=n;yield*t.entries();for(const i of s)yield[i,null];return}let r=!1,e;n instanceof Headers?e=n.entries():ms(n)?e=n:(r=!0,e=Object.entries(n??{}));for(let t of e){const s=t[0];if(typeof s!="string")throw new TypeError("expected header name to be a string");const i=ms(t[1])?t[1]:[t[1]];let a=!1;for(const c of i)c!==void 0&&(r&&!a&&(a=!0,yield[s,Un]),yield[s,c])}}const Un=Symbol("clear"),dl=new Set(["x-stainless-helper"]),hl=(n,r)=>{const e=n?n.split(",").map(t=>t.trim()).filter(Boolean):[];for(const t of r.split(",").map(s=>s.trim()))t&&!e.includes(t)&&e.push(t);return e.join(", ")},ec=n=>{const r=new Headers,e=new Set;for(const t of n){const s=new Set;for(const[i,a]of ul(t)){const c=i.toLowerCase();if(dl.has(c)){if(a===Un)continue;a===null?(r.delete(i),e.add(c)):(r.set(i,hl(r.get(i),a)),e.delete(c));continue}(a===Un||!s.has(c))&&(r.delete(i),s.add(c),a===Un)||(a===null?(r.delete(i),e.add(c)):(r.append(i,a),e.delete(c)))}}return{[Zo]:!0,values:r,nulls:e}};var fl={};const Gt=n=>{if(typeof globalThis.process<"u")return fl?.[n]?.trim()||void 0;if(typeof globalThis.Deno<"u")return globalThis.Deno.env?.get?.(n)?.trim()||void 0};function w(n,r,e,t,s){if(typeof r=="function"?n!==r||!0:!r.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r.set(n,e),e}function o(n,r,e,t){if(e==="a"&&!t)throw new TypeError("Private accessor was defined without a getter");if(typeof r=="function"?n!==r||!t:!r.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?t:e==="a"?t.call(n):t?t.value:r.get(n)}const pl=/^[a-z][a-z0-9+.-]*:/i,_l=n=>pl.test(n);let J=n=>(J=Array.isArray,J(n)),ws=J;function Fn(n){return typeof n!="object"?{}:n??{}}function ys(n){if(!n)return!0;for(const r in n)return!1;return!0}function gl(n,r){return Object.prototype.hasOwnProperty.call(n,r)}function bs(n){return n!=null&&typeof n=="object"&&!Array.isArray(n)}const Gn=(n,r)=>{if(typeof r!="number"||!Number.isInteger(r))throw new S(`${n} must be an integer`);if(r<0)throw new S(`${n} must be a positive integer`);return r},tc=n=>{try{return JSON.parse(n)}catch{return}};const Be=(n,r)=>new Promise(e=>{if(r?.aborted)return e();const t=()=>{clearTimeout(s),e()},s=setTimeout(()=>{r?.removeEventListener("abort",t),e()},n);r?.addEventListener("abort",t,{once:!0})}),ge="0.131.0",ml=()=>typeof window<"u"&&typeof window.document<"u"&&typeof navigator<"u";function wl(){return typeof Deno<"u"&&Deno.build!=null?"deno":typeof EdgeRuntime<"u"?"edge":Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]"?"node":"unknown"}const yl=()=>{const n=wl();if(n==="deno")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ge,"X-Stainless-OS":ks(Deno.build.os),"X-Stainless-Arch":vs(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":typeof Deno.version=="string"?Deno.version:Deno.version?.deno??"unknown"};if(typeof EdgeRuntime<"u")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ge,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":globalThis.process?.version??"unknown"};if(n==="node")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ge,"X-Stainless-OS":ks(globalThis.process.platform??"unknown"),"X-Stainless-Arch":vs(globalThis.process.arch??"unknown"),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":globalThis.process.version??"unknown"};const r=bl();return r?{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ge,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${r.browser}`,"X-Stainless-Runtime-Version":r.version}:{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ge,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}};function bl(){if(typeof navigator>"u"||!navigator)return null;const n=[{key:"edge",pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"chrome",pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"firefox",pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"safari",pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}];for(const{key:r,pattern:e}of n){const t=e.exec(navigator.userAgent);if(t){const s=t[1]||0,i=t[2]||0,a=t[3]||0;return{browser:r,version:`${s}.${i}.${a}`}}}return null}const vs=n=>n==="x32"?"x32":n==="x86_64"||n==="x64"?"x64":n==="arm"?"arm":n==="aarch64"||n==="arm64"?"arm64":n?`other:${n}`:"unknown",ks=n=>(n=n.toLowerCase(),n.includes("ios")?"iOS":n==="android"?"Android":n==="darwin"?"MacOS":n==="win32"?"Windows":n==="freebsd"?"FreeBSD":n==="openbsd"?"OpenBSD":n==="linux"?"Linux":n?`Other:${n}`:"Unknown");let Ss;const es=()=>Ss??(Ss=yl()),qn=new WeakMap,nc=typeof globalThis.FinalizationRegistry=="function"?new globalThis.FinalizationRegistry(n=>De(n)):null;function vl(n,r){return()=>n.removeEventListener("abort",r)}function kl(n,r,e){qn.set(n,vl(r,e))}function Sl(n,r){qn.has(r)&&nc?.register(n,r,r)}function De(n){const r=qn.get(n);r&&(qn.delete(n),nc?.unregister(n),r())}function xl(){if(typeof fetch<"u")return fetch;throw new Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new Anthropic({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}function rc(...n){const r=globalThis.ReadableStream;if(typeof r>"u")throw new Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new r(...n)}function sc(n){let r=Symbol.asyncIterator in n?n[Symbol.asyncIterator]():n[Symbol.iterator]();return rc({start(){},async pull(e){const{done:t,value:s}=await r.next();t?e.close():e.enqueue(s)},async cancel(){await r.return?.()}})}function ts(n){if(n[Symbol.asyncIterator])return n;const r=n.getReader();return{async next(){try{const e=await r.read();return e?.done&&r.releaseLock(),e}catch(e){throw r.releaseLock(),e}},async return(){const e=r.cancel();return r.releaseLock(),await e,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function Rl(n){if(n===null||typeof n!="object")return;if(n[Symbol.asyncIterator]){await n[Symbol.asyncIterator]().return?.();return}const r=n.getReader(),e=r.cancel();r.releaseLock(),await e}const Al=({headers:n,body:r})=>({bodyHeaders:{"content-type":"application/json"},body:JSON.stringify(r)}),ic="RFC3986",ac=n=>String(n),xs={RFC1738:n=>String(n).replace(/%20/g,"+"),RFC3986:ac},El="RFC1738";let Cr=(n,r)=>(Cr=Object.hasOwn??Function.prototype.call.bind(Object.prototype.hasOwnProperty),Cr(n,r));const le=(()=>{const n=[];for(let r=0;r<256;++r)n.push("%"+((r<16?"0":"")+r.toString(16)).toUpperCase());return n})(),Qn=1024,Tl=(n,r,e,t,s)=>{if(n.length===0)return n;let i=n;if(typeof n=="symbol"?i=Symbol.prototype.toString.call(n):typeof n!="string"&&(i=String(n)),e==="iso-8859-1")return escape(i).replace(/%u[0-9a-f]{4}/gi,function(c){return"%26%23"+parseInt(c.slice(2),16)+"%3B"});let a="";for(let c=0;c<i.length;c+=Qn){const u=i.length>=Qn?i.slice(c,c+Qn):i,l=[];for(let p=0;p<u.length;++p){let d=u.charCodeAt(p);if(d===45||d===46||d===95||d===126||d>=48&&d<=57||d>=65&&d<=90||d>=97&&d<=122||s===El&&(d===40||d===41)){l[l.length]=u.charAt(p);continue}if(d<128){l[l.length]=le[d];continue}if(d<2048){l[l.length]=le[192|d>>6]+le[128|d&63];continue}if(d<55296||d>=57344){l[l.length]=le[224|d>>12]+le[128|d>>6&63]+le[128|d&63];continue}p+=1,d=65536+((d&1023)<<10|u.charCodeAt(p)&1023),l[l.length]=le[240|d>>18]+le[128|d>>12&63]+le[128|d>>6&63]+le[128|d&63]}a+=l.join("")}return a};function $l(n){return!n||typeof n!="object"?!1:!!(n.constructor&&n.constructor.isBuffer&&n.constructor.isBuffer(n))}function Rs(n,r){if(J(n)){const e=[];for(let t=0;t<n.length;t+=1)e.push(r(n[t]));return e}return r(n)}const oc={brackets(n){return String(n)+"[]"},comma:"comma",indices(n,r){return String(n)+"["+r+"]"},repeat(n){return String(n)}},cc=function(n,r){Array.prototype.push.apply(n,J(r)?r:[r])};let As;const W={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:Tl,encodeValuesOnly:!1,format:ic,formatter:ac,indices:!1,serializeDate(n){return(As??(As=Function.prototype.call.bind(Date.prototype.toISOString)))(n)},skipNulls:!1,strictNullHandling:!1};function Il(n){return typeof n=="string"||typeof n=="number"||typeof n=="boolean"||typeof n=="symbol"||typeof n=="bigint"}const Yn={};function lc(n,r,e,t,s,i,a,c,u,l,p,d,g,_,m,y,x,E){let b=n,k=E,R=0,T=!1;for(;(k=k.get(Yn))!==void 0&&!T;){const I=k.get(n);if(R+=1,typeof I<"u"){if(I===R)throw new RangeError("Cyclic object value");T=!0}typeof k.get(Yn)>"u"&&(R=0)}if(typeof l=="function"?b=l(r,b):b instanceof Date?b=g?.(b):e==="comma"&&J(b)&&(b=Rs(b,function(I){return I instanceof Date?g?.(I):I})),b===null){if(i)return u&&!y?u(r,W.encoder,x,"key",_):r;b=""}if(Il(b)||$l(b)){if(u){const I=y?r:u(r,W.encoder,x,"key",_);return[m?.(I)+"="+m?.(u(b,W.encoder,x,"value",_))]}return[m?.(r)+"="+m?.(String(b))]}const $=[];if(typeof b>"u")return $;let C;if(e==="comma"&&J(b))y&&u&&(b=Rs(b,u)),C=[{value:b.length>0?b.join(",")||null:void 0}];else if(J(l))C=l;else{const I=Object.keys(b);C=p?I.sort(p):I}const M=c?String(r).replace(/\./g,"%2E"):String(r),L=t&&J(b)&&b.length===1?M+"[]":M;if(s&&J(b)&&b.length===0)return L+"[]";for(let I=0;I<C.length;++I){const ne=C[I],we=typeof ne=="object"&&typeof ne.value<"u"?ne.value:b[ne];if(a&&we===null)continue;const ye=d&&c?ne.replace(/\./g,"%2E"):ne,ol=J(b)?typeof e=="function"?e(L,ye):L:L+(d?"."+ye:"["+ye+"]");E.set(n,R);const ps=new WeakMap;ps.set(Yn,E),cc($,lc(we,ol,e,t,s,i,a,c,e==="comma"&&y&&J(b)?null:u,l,p,d,g,_,m,y,x,ps))}return $}function Pl(n=W){if(typeof n.allowEmptyArrays<"u"&&typeof n.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof n.encodeDotInKeys<"u"&&typeof n.encodeDotInKeys!="boolean")throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(n.encoder!==null&&typeof n.encoder<"u"&&typeof n.encoder!="function")throw new TypeError("Encoder has to be a function.");const r=n.charset||W.charset;if(typeof n.charset<"u"&&n.charset!=="utf-8"&&n.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");let e=ic;if(typeof n.format<"u"){if(!Cr(xs,n.format))throw new TypeError("Unknown format option provided.");e=n.format}const t=xs[e];let s=W.filter;(typeof n.filter=="function"||J(n.filter))&&(s=n.filter);let i;if(n.arrayFormat&&n.arrayFormat in oc?i=n.arrayFormat:"indices"in n?i=n.indices?"indices":"repeat":i=W.arrayFormat,"commaRoundTrip"in n&&typeof n.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");const a=typeof n.allowDots>"u"?n.encodeDotInKeys?!0:W.allowDots:!!n.allowDots;return{addQueryPrefix:typeof n.addQueryPrefix=="boolean"?n.addQueryPrefix:W.addQueryPrefix,allowDots:a,allowEmptyArrays:typeof n.allowEmptyArrays=="boolean"?!!n.allowEmptyArrays:W.allowEmptyArrays,arrayFormat:i,charset:r,charsetSentinel:typeof n.charsetSentinel=="boolean"?n.charsetSentinel:W.charsetSentinel,commaRoundTrip:!!n.commaRoundTrip,delimiter:typeof n.delimiter>"u"?W.delimiter:n.delimiter,encode:typeof n.encode=="boolean"?n.encode:W.encode,encodeDotInKeys:typeof n.encodeDotInKeys=="boolean"?n.encodeDotInKeys:W.encodeDotInKeys,encoder:typeof n.encoder=="function"?n.encoder:W.encoder,encodeValuesOnly:typeof n.encodeValuesOnly=="boolean"?n.encodeValuesOnly:W.encodeValuesOnly,filter:s,format:e,formatter:t,serializeDate:typeof n.serializeDate=="function"?n.serializeDate:W.serializeDate,skipNulls:typeof n.skipNulls=="boolean"?n.skipNulls:W.skipNulls,sort:typeof n.sort=="function"?n.sort:null,strictNullHandling:typeof n.strictNullHandling=="boolean"?n.strictNullHandling:W.strictNullHandling}}function Ml(n,r={}){let e=n;const t=Pl(r);let s,i;typeof t.filter=="function"?(i=t.filter,e=i("",e)):J(t.filter)&&(i=t.filter,s=i);const a=[];if(typeof e!="object"||e===null)return"";const c=oc[t.arrayFormat],u=c==="comma"&&t.commaRoundTrip;s||(s=Object.keys(e)),t.sort&&s.sort(t.sort);const l=new WeakMap;for(let g=0;g<s.length;++g){const _=s[g];t.skipNulls&&e[_]===null||cc(a,lc(e[_],_,c,u,t.allowEmptyArrays,t.strictNullHandling,t.skipNulls,t.encodeDotInKeys,t.encode?t.encoder:null,t.filter,t.sort,t.allowDots,t.serializeDate,t.format,t.formatter,t.encodeValuesOnly,t.charset,l))}const p=a.join(t.delimiter);let d=t.addQueryPrefix===!0?"?":"";return t.charsetSentinel&&(t.charset==="iso-8859-1"?d+="utf8=%26%2310003%3B&":d+="utf8=%E2%9C%93&"),p.length>0?d+p:""}function Ol(n){return Ml(n,{arrayFormat:"brackets"})}const Cl="urn:ietf:params:oauth:grant-type:jwt-bearer",Ll="refresh_token",uc="/v1/oauth/token",Kn="oauth-2025-04-20",Nl="oidc-federation-2026-04-01",Bl=120,ns=30,Dl=5,Es=1<<20;function dc(n){if(!n)return;let r;try{r=new URL(n)}catch(t){throw new B(`Invalid token endpoint base URL "${n}": ${t}`)}if(r.protocol==="https:")return;const e=r.hostname.toLowerCase().replace(/^\[|\]$/g,"");if(!(r.protocol==="http:"&&(e==="localhost"||e==="127.0.0.1"||e==="::1")))throw new B(`Refusing to send credential over non-https token endpoint "${n}"`)}async function hc(n,r){const e=await Hl(n);let t;try{t=JSON.parse(e)}catch{throw new B(`Token endpoint returned non-JSON response (status ${n.status})`,n.status,ie(e),r)}if(!t.access_token)throw new B(`Token endpoint response missing access_token: ${JSON.stringify(ie(t))}`,n.status,ie(t),r);if(t.token_type&&t.token_type.toLowerCase()!=="bearer")throw new B(`Token endpoint response: unsupported token_type "${t.token_type}" (want Bearer)`,n.status,ie(t),r);return t}const Zn=2e3,Ul=new Set(["error","error_description","error_uri"]);function ie(n){if(n==null)return n;if(typeof n=="string"){let r;try{r=JSON.parse(n)}catch{return n.length<=Zn?n:n.slice(0,Zn)+`... <${n.length-Zn} more chars>`}return JSON.stringify(ie(r))}if(typeof n=="object"&&!Array.isArray(n)){const r={};for(const[e,t]of Object.entries(n))Ul.has(e)&&(r[e]=t);return r}return null}async function fc(n,r=e=>console.warn(`anthropic-sdk: ${e}`)){if(typeof process>"u"||process.platform==="win32")return;const{fs:e}=await ce(async()=>{const{fs:a}=await import("./node.browser-C_s9kvmM.js");return{fs:a}},__vite__mapDeps([0,1,2]));let t=n,s;try{t=await e.promises.realpath(n),s=await e.promises.stat(t)}catch{return}const i=s.mode&511;if(i&18)throw new B(`Credentials file at ${t} is group/world-writable (mode 0o${i.toString(8)}); this allows other local users to plant tokens. Run \`chmod 600 ${t}\`.`);if(i&36)throw new B(`Credentials file at ${t} is group/world-readable (mode 0o${i.toString(8)}); run \`chmod 600 ${t}\` before retrying.`);typeof process.getuid=="function"&&s.uid!==process.getuid()&&r(`credentials file at ${t} is owned by uid ${s.uid} (current process uid ${process.getuid()}); verify this is intentional.`)}async function pc(n,r){const{fs:e,path:t}=await ce(async()=>{const{fs:a,path:c}=await import("./node.browser-C_s9kvmM.js");return{fs:a,path:c}},__vite__mapDeps([0,1,2])),s=t.dirname(n);await e.promises.mkdir(s,{recursive:!0,mode:448});const i=`${n}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;try{const a=await e.promises.open(i,"w",384);try{await a.writeFile(JSON.stringify(r,null,2)),await a.sync()}finally{await a.close()}await e.promises.rename(i,n)}catch(a){throw await e.promises.unlink(i).catch(()=>{}),a}try{const a=await e.promises.open(s,"r");try{await a.sync()}finally{await a.close()}}catch{}}async function Hl(n){if(!n.body)return"";const r=n.body.getReader(),e=[];let t=0;for(;;){const{done:i,value:a}=await r.read();if(i)break;if(t+a.length>Es){const c=Es-t;c>0&&e.push(a.subarray(0,c)),await r.cancel();break}e.push(a),t+=a.length}let s;if(e.length===1)s=e[0];else{s=new Uint8Array(e.reduce((a,c)=>a+c.length,0));let i=0;for(const a of e)s.set(a,i),i+=a.length}return new TextDecoder("utf-8").decode(s)}class B extends S{constructor(r,e=null,t=null,s=null){super(r),this.statusCode=e,this.body=t,this.requestId=s}}function Ue(){return Math.floor(Date.now()/1e3)}class Wl{constructor(r,e){this.cached=null,this.pendingRefresh=null,this.nextForce=!1,this.lastAdvisoryError=0,this.provider=r,this.onAdvisoryRefreshError=e}async getToken(){const r=this.nextForce;this.nextForce=!1;const e=this.cached;if(r||e==null)return(await this.refresh(r)).token;if(e.expiresAt==null)return e.token;const t=e.expiresAt-Ue();return t>Bl?e.token:t>ns?(this.backgroundRefresh(),e.token):(await this.refresh()).token}invalidate(){this.cached=null,this.nextForce=!0}refresh(r=!1){return this.pendingRefresh&&!r?this.pendingRefresh:this.doRefresh(r)}backgroundRefresh(){this.pendingRefresh||Ue()-this.lastAdvisoryError<Dl||this.doRefresh().catch(r=>{this.lastAdvisoryError=Ue(),this.onAdvisoryRefreshError?.(r)})}doRefresh(r=!1){return this.pendingRefresh=this.provider(r?{forceRefresh:!0}:void 0).then(e=>(this.cached=e,this.pendingRefresh=null,e),e=>{throw this.pendingRefresh=null,e}),this.pendingRefresh}}var zl={};const P=n=>{if(typeof globalThis.process<"u")return zl?.[n]?.trim()||void 0;if(typeof globalThis.Deno<"u")return globalThis.Deno.env?.get?.(n)?.trim()||void 0};function jl(n){let r=0;for(const s of n)r+=s.length;const e=new Uint8Array(r);let t=0;for(const s of n)e.set(s,t),t+=s.length;return e}let Ts;function _c(n){let r;return(Ts??(r=new globalThis.TextEncoder,Ts=r.encode.bind(r)))(n)}let $s;function Lr(n){let r;return($s??(r=new globalThis.TextDecoder,$s=r.decode.bind(r)))(n)}const Fl=n=>{if(typeof globalThis.Buffer<"u"){const r=globalThis.Buffer.from(n,"base64");return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}if(typeof atob<"u"){const r=atob(n),e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}throw new S("Cannot decode base64 string; Expected `Buffer` or `atob` to be defined")},Vn="warn",Jn={off:0,error:200,warn:300,info:400,debug:500},Nr=(n,r,e)=>{if(n){if(gl(Jn,n))return n;e.warn(`${r} was set to ${JSON.stringify(n)}, expected one of ${JSON.stringify(Object.keys(Jn))}`)}};function st(){}function Qt(n,r,e){return!r||Jn[n]>Jn[e]?st:r[n].bind(r)}const ql={error:st,warn:st,info:st,debug:st};let Is=new WeakMap;function Br(n,r){const e=Is.get(n);if(e&&e[0]===r)return e[1];const t={error:Qt("error",n,r),warn:Qt("warn",n,r),info:Qt("info",n,r),debug:Qt("debug",n,r)};return Is.set(n,[r,t]),t}function O(n){const r=n.logger,e=n.logLevel??"off";return r?Br(r,e):ql}let Ps,er;function Kl(){const n=P("ANTHROPIC_LOG");return(!er||n!==Ps)&&(Ps=n,er=Br(console,Nr(n,"process.env['ANTHROPIC_LOG']",Br(console,Vn))??Vn)),er}function Ae(n,r,e){n.debug!==st&&n.debug(r,Vl(e))}const Vl=n=>(n.options&&(n.options={...n.options},delete n.options.headers),n.headers&&(n.headers=Object.fromEntries((n.headers instanceof Headers?[...n.headers]:Object.entries(n.headers)).map(([r,e])=>[r,r.toLowerCase()==="authorization"||r.toLowerCase()==="api-key"||r.toLowerCase()==="x-api-key"||r.toLowerCase()==="cookie"||r.toLowerCase()==="set-cookie"?"***":e]))),"retryOfRequestLogID"in n&&(n.retryOfRequestLogID&&(n.retryOf=n.retryOfRequestLogID),delete n.retryOfRequestLogID),n);let Dr=function(){const{crypto:n}=globalThis;if(n?.randomUUID)return Dr=n.randomUUID.bind(n),n.randomUUID();const r=new Uint8Array(1),e=n?()=>n.getRandomValues(r)[0]:()=>Math.random()*255&255;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,t=>(+t^e()&15>>+t/4).toString(16))};const gc="1.0",Jl=/^[A-Za-z0-9_.-]+$/;function mc(n){if(!n)throw new Error("profile name is empty");if(n==="."||n==="..")throw new Error(`profile name "${n}" is not allowed`);if(n.includes("/")||n.includes("\\"))throw new Error(`profile name "${n}" must not contain path separators`);if(!Jl.test(n))throw new Error(`profile name "${n}" contains disallowed characters (allowed: letters, digits, '_', '.', '-')`)}const Xl=async n=>{var r,e;const t=await rs();if(t===null)return null;const s=n??await wc();if(s===null)return null;mc(s);const{fs:i,path:a}=await ce(async()=>{const{fs:d,path:g}=await import("./node.browser-C_s9kvmM.js");return{fs:d,path:g}},__vite__mapDeps([0,1,2])),c=a.join(t,"configs",`${s}.json`);let u;try{u=await i.promises.readFile(c,"utf-8")}catch(d){if(d?.code!=="ENOENT")throw new Error(`failed to read config file ${c}: ${d}`);u=null}if(u===null){const d=P("ANTHROPIC_ORGANIZATION_ID"),g=P("ANTHROPIC_IDENTITY_TOKEN_FILE"),_=P("ANTHROPIC_FEDERATION_RULE_ID");return _&&d?{fromFile:!1,config:{organization_id:d,workspace_id:P("ANTHROPIC_WORKSPACE_ID"),base_url:P("ANTHROPIC_BASE_URL"),authentication:{type:"oidc_federation",federation_rule_id:_,service_account_id:P("ANTHROPIC_SERVICE_ACCOUNT_ID"),identity_token:g?{source:"file",path:g}:void 0,scope:P("ANTHROPIC_SCOPE")}}}:null}let l;try{l=JSON.parse(u)}catch(d){throw new Error(`failed to parse config file ${c}: ${d}`)}if(!l.authentication)throw new Error(`config file ${c} is missing "authentication"`);const p=l.authentication.type;if(p!=="oidc_federation"&&p!=="user_oauth")throw new Error(`authentication.type "${p}" is not a known authentication type`);if(l.organization_id??(l.organization_id=P("ANTHROPIC_ORGANIZATION_ID")),l.workspace_id??(l.workspace_id=P("ANTHROPIC_WORKSPACE_ID")),l.base_url??(l.base_url=P("ANTHROPIC_BASE_URL")),(r=l.authentication).scope??(r.scope=P("ANTHROPIC_SCOPE")),l.authentication.type==="oidc_federation"){if(!l.authentication.identity_token){const d=P("ANTHROPIC_IDENTITY_TOKEN_FILE");d&&(l.authentication.identity_token={source:"file",path:d})}l.authentication.federation_rule_id||(l.authentication.federation_rule_id=P("ANTHROPIC_FEDERATION_RULE_ID")??""),(e=l.authentication).service_account_id??(e.service_account_id=P("ANTHROPIC_SERVICE_ACCOUNT_ID"))}return{config:l,fromFile:!0}},Gl=async(n,r)=>{if(n?.authentication.credentials_path)return n.authentication.credentials_path;const e=await rs();if(!e)return null;const t=r??await wc();if(!t)return null;mc(t);const{path:s}=await ce(async()=>{const{path:i}=await import("./node.browser-C_s9kvmM.js");return{path:i}},__vite__mapDeps([0,1,2]));return s.join(e,"credentials",`${t}.json`)},rs=async()=>{if(!Ql())return null;const{path:n}=await ce(async()=>{const{path:i}=await import("./node.browser-C_s9kvmM.js");return{path:i}},__vite__mapDeps([0,1,2])),r=P("ANTHROPIC_CONFIG_DIR");if(r)return r;if(es()["X-Stainless-OS"]==="Windows"){const i=P("APPDATA");if(i)return n.join(i,"Anthropic");const a=P("USERPROFILE");return a?n.join(a,"AppData","Roaming","Anthropic"):null}const t=P("XDG_CONFIG_HOME");if(t)return n.join(t,"anthropic");const s=P("HOME");return s?n.join(s,".config","anthropic"):null},Ql=()=>{const n=es()["X-Stainless-Runtime"];return n==="node"||n==="deno"},wc=async()=>{const n=await rs();if(!n)return null;const r=P("ANTHROPIC_PROFILE");if(r)return r;const{fs:e,path:t}=await ce(async()=>{const{fs:i,path:a}=await import("./node.browser-C_s9kvmM.js");return{fs:i,path:a}},__vite__mapDeps([0,1,2])),s=t.join(n,"active_config");try{return(await e.promises.readFile(s,"utf-8")).trim()||"default"}catch(i){if(i?.code!=="ENOENT")throw new Error(`failed to read ${s}: ${i}`);return"default"}};function Ms(n){if(!n)throw new S("Identity token file path is empty");return async()=>{const{fs:r}=await ce(async()=>{const{fs:s}=await import("./node.browser-C_s9kvmM.js");return{fs:s}},__vite__mapDeps([0,1,2]));let e;try{e=await r.promises.readFile(n,"utf-8")}catch(s){throw new S(`Failed to read identity token file at ${n}: ${s}`)}const t=e.trim();if(!t)throw new S(`Identity token file at ${n} is empty`);return t}}function Yl(n){if(!n)throw new S("Identity token value is empty");return()=>n}function Zl(n){return async()=>{dc(n.baseURL);const r=await n.identityTokenProvider();if(r.length>16*1024)throw new B(`Identity token is ${Math.ceil(r.length/1024)} KiB, exceeds the 16 KiB assertion limit`);const e={grant_type:Cl,assertion:r,federation_rule_id:n.federationRuleId,organization_id:n.organizationId};n.serviceAccountId&&(e.service_account_id=n.serviceAccountId),n.workspaceId&&(e.workspace_id=n.workspaceId);const t=`${n.baseURL}${uc}`;let s;try{s=await n.fetch(t,{method:"POST",headers:{"Content-Type":"application/json","anthropic-beta":`${Kn},${Nl}`,"User-Agent":n.userAgent||`anthropic-sdk-typescript/${ge} oidcFederationProvider`},body:JSON.stringify(e)})}catch(u){throw new B(`Failed to reach token endpoint ${t}: ${u}`)}const i=s.headers.get("Request-Id");if(!s.ok){const u=await s.text().catch(()=>""),l=ie(u);let p="";throw s.status===401&&(p=` Ensure your federation rule matches your identity token. ${n.workspaceId?"":"If your federation rule is scoped to multiple workspaces, set the ANTHROPIC_WORKSPACE_ID environment variable, the 'workspace_id' config key, or the `workspaceId` option. "}View your authentication events in the Workload identity page of Claude Console for more details.`),new B(`Token exchange failed with status ${s.status}${i?` (request-id ${i})`:""}: ${l}${p}`,s.status,l,i)}const a=await hc(s,i),c=Number(a.expires_in);if(!Number.isFinite(c))throw new B(`Token endpoint response missing required fields: ${JSON.stringify(ie(a))}`,s.status,ie(a),i);return{token:a.access_token,expiresAt:Ue()+c}}}function eu(n){return async r=>{const{fs:e}=await ce(async()=>{const{fs:x}=await import("./node.browser-C_s9kvmM.js");return{fs:x}},__vite__mapDeps([0,1,2]));await fc(n.credentialsPath,n.onSafetyWarning);let t;try{t=await e.promises.readFile(n.credentialsPath,"utf-8")}catch(x){throw new B(`Credentials file not found at ${n.credentialsPath}: ${x}`)}let s;try{s=JSON.parse(t)}catch(x){throw new B(`Credentials file at ${n.credentialsPath} is not valid JSON: ${x}`)}const i=s.access_token;if(!i)throw new B(`Credentials file at ${n.credentialsPath} must include 'access_token'`);const a=s.expires_at;if(!r?.forceRefresh&&(a==null||Ue()<a-ns))return{token:i,expiresAt:a??null};const c=s.refresh_token;if(!n.clientId||!c)throw new B(`Access token at ${n.credentialsPath} has expired and no refresh is available (client_id ${n.clientId?"set":"empty"}, refresh_token ${c?"set":"empty"})`);dc(n.baseURL);const u={grant_type:Ll,refresh_token:c,client_id:n.clientId},l=`${n.baseURL}${uc}`;let p;try{p=await n.fetch(l,{method:"POST",headers:{"Content-Type":"application/json","anthropic-beta":Kn,"User-Agent":n.userAgent||`anthropic-sdk-typescript/${ge} userOAuthProvider`},body:JSON.stringify(u)})}catch(x){throw new B(`User OAuth refresh failed to reach token endpoint: ${x}`)}const d=p.headers.get("Request-Id");if(!p.ok){const x=await p.text().catch(()=>"");throw new B(`User OAuth refresh failed (HTTP ${p.status}): ${ie(x)}`,p.status,ie(x),d)}const g=await hc(p,d),_=Number(g.expires_in);if(!Number.isFinite(_))throw new B(`User OAuth refresh response missing or invalid expires_in: ${JSON.stringify(ie(g))}`,p.status,ie(g),d);const m=Ue()+_,y=g.refresh_token||c;return await pc(n.credentialsPath,{...s,version:gc,type:"oauth_token",access_token:g.access_token,expires_at:m,refresh_token:y}),{token:g.access_token,expiresAt:m}}}function yc(n,r){const e=n.authentication.credentials_path??null,t=(n.base_url||r.baseURL).replace(/\/+$/,""),s=nu(n,e,t,r),i={};return n.workspace_id&&n.authentication.type==="user_oauth"&&(i["anthropic-workspace-id"]=n.workspace_id),{provider:s,extraHeaders:i,baseURL:n.base_url||void 0}}async function tu(n,r){const e=await Xl(r);if(!e)return null;const{config:t,fromFile:s}=e,i=t.authentication.credentials_path||!s?t:{...t,authentication:{...t.authentication,credentials_path:await Gl(t,r)??void 0}};return yc(i,n)}function nu(n,r,e,t){switch(n.authentication.type){case"oidc_federation":{const s=n.authentication,i=ru(s);if(!i)throw new B("oidc_federation config requires an identity token (set authentication.identity_token, ANTHROPIC_IDENTITY_TOKEN_FILE, or ANTHROPIC_IDENTITY_TOKEN)");if(!s.federation_rule_id)throw new B("oidc_federation config requires 'federation_rule_id'. Set it in authentication.federation_rule_id in your profile, or via ANTHROPIC_FEDERATION_RULE_ID (profile takes precedence).");if(!n.organization_id)throw new B("oidc_federation config requires organization_id (set ANTHROPIC_ORGANIZATION_ID or config.organization_id)");const a=Zl({identityTokenProvider:i,federationRuleId:s.federation_rule_id,organizationId:n.organization_id,serviceAccountId:s.service_account_id,workspaceId:n.workspace_id,baseURL:e,fetch:t.fetch,userAgent:t.userAgent});return r?su(a,r,t.onCacheWriteError,t.onSafetyWarning):a}case"user_oauth":{if(!r)throw new B("user_oauth config requires authentication.credentials_path (or load via a profile so it defaults to <config_dir>/credentials/<profile>.json)");return eu({credentialsPath:r,clientId:n.authentication.client_id,baseURL:e,fetch:t.fetch,userAgent:t.userAgent,onSafetyWarning:t.onSafetyWarning})}default:{const s=n.authentication.type;throw new B(`authentication.type "${s}" is not a known authentication type`)}}}function ru(n){if(n.identity_token){const t=n.identity_token.source;if(t!=="file")throw new B(`identity_token.source "${t}" is not supported by this SDK version (only "file")`);if(!n.identity_token.path)throw new B('identity_token.source "file" requires a non-empty path');return Ms(n.identity_token.path)}const r=P("ANTHROPIC_IDENTITY_TOKEN_FILE");if(r)return Ms(r);const e=P("ANTHROPIC_IDENTITY_TOKEN");return e?Yl(e):null}function su(n,r,e,t){return async s=>{const{fs:i}=await ce(async()=>{const{fs:u}=await import("./node.browser-C_s9kvmM.js");return{fs:u}},__vite__mapDeps([0,1,2]));await fc(r,t);let a;try{const u=await i.promises.readFile(r,"utf-8");a=JSON.parse(u);const l=a?.access_token;if(l&&!s?.forceRefresh){const p=a?.expires_at;if(p==null||Ue()<p-ns)return{token:l,expiresAt:p??null}}}catch(u){u?.code!=="ENOENT"&&!(u instanceof SyntaxError)&&e?.(u)}const c=await n(s);try{await pc(r,{...a??{},version:gc,type:"oauth_token",access_token:c.token,expires_at:c.expiresAt})}catch(u){e?.(u)}return c}}var G,Q,ss=(()=>{class n{constructor(){G.set(this,void 0),Q.set(this,void 0),w(this,G,new Uint8Array),w(this,Q,null)}decode(e){if(e==null)return[];const t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e=="string"?_c(e):e;w(this,G,jl([o(this,G,"f"),t]));const s=[];let i;for(;(i=iu(o(this,G,"f"),o(this,Q,"f")))!=null;){if(i.carriage&&o(this,Q,"f")==null){w(this,Q,i.index);continue}if(o(this,Q,"f")!=null&&(i.index!==o(this,Q,"f")+1||i.carriage)){s.push(Lr(o(this,G,"f").subarray(0,o(this,Q,"f")-1))),w(this,G,o(this,G,"f").subarray(o(this,Q,"f"))),w(this,Q,null);continue}const a=o(this,Q,"f")!==null?i.preceding-1:i.preceding,c=Lr(o(this,G,"f").subarray(0,a));s.push(c),w(this,G,o(this,G,"f").subarray(i.index)),w(this,Q,null)}return s}flush(){return o(this,G,"f").length?this.decode(`
|
|
3
3
|
`):[]}}return G=new WeakMap,Q=new WeakMap,n.NEWLINE_CHARS=new Set([`
|
|
4
4
|
`,"\r"]),n.NEWLINE_REGEXP=/\r\n|[\n\r]/g,n})();function iu(n,r){for(let s=r??0;s<n.length;s++){if(n[s]===10)return{preceding:s,index:s+1,carriage:!1};if(n[s]===13)return{preceding:s,index:s+1,carriage:!0}}return null}var ht,dt=(()=>{class n{constructor(e,t,s){this.iterator=e,ht.set(this,void 0),this.controller=t,w(this,ht,s)}static rawEvents(e,t=new AbortController){return Os(e,t)}static fromSSEResponse(e,t,s){let i=!1;const a=s?O(s):console;async function*c(){if(i)throw new S("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");i=!0;let u=!1;try{for await(const l of Os(e,t)){if(l.event==="completion")try{yield JSON.parse(l.data)}catch(p){throw a.error("Could not parse message into JSON:",l.data),a.error("From chunk:",l.raw),p}if(l.event==="message_start"||l.event==="message_delta"||l.event==="message_stop"||l.event==="content_block_start"||l.event==="content_block_delta"||l.event==="content_block_stop"||l.event==="message"||l.event==="user.message"||l.event==="user.interrupt"||l.event==="user.tool_confirmation"||l.event==="user.custom_tool_result"||l.event==="user.tool_result"||l.event==="agent.message"||l.event==="agent.thinking"||l.event==="agent.tool_use"||l.event==="agent.tool_result"||l.event==="agent.mcp_tool_use"||l.event==="agent.mcp_tool_result"||l.event==="agent.custom_tool_use"||l.event==="agent.thread_context_compacted"||l.event==="session.status_running"||l.event==="session.status_idle"||l.event==="session.status_rescheduled"||l.event==="session.status_terminated"||l.event==="session.error"||l.event==="session.deleted"||l.event==="session.updated"||l.event==="span.model_request_start"||l.event==="span.model_request_end"||l.event==="span.outcome_evaluation_start"||l.event==="span.outcome_evaluation_ongoing"||l.event==="span.outcome_evaluation_end"||l.event==="user.define_outcome"||l.event==="agent.thread_message_received"||l.event==="agent.thread_message_sent"||l.event==="agent.session_thread_message_received"||l.event==="agent.session_thread_message_sent"||l.event==="session.thread_created"||l.event==="session.thread_status_created"||l.event==="session.thread_status_running"||l.event==="session.thread_status_idle"||l.event==="session.thread_status_rescheduled"||l.event==="session.thread_status_terminated"||l.event==="event_start"||l.event==="event_delta"||l.event==="system.message")try{yield JSON.parse(l.data)}catch(p){throw a.error("Could not parse message into JSON:",l.data),a.error("From chunk:",l.raw),p}if(l.event!=="ping"&&l.event==="error"){const p=tc(l.data)??l.data,d=p?.error?.type;throw new z(void 0,p,void 0,e.headers,d)}}u=!0}catch(l){if(lt(l))return;throw l}finally{u||t.abort(),De(t)}}return new n(c,t,s)}static fromReadableStream(e,t,s){let i=!1;async function*a(){const u=new ss,l=ts(e);for await(const p of l)for(const d of u.decode(p))yield d;for(const p of u.flush())yield p}async function*c(){if(i)throw new S("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");i=!0;let u=!1;try{for await(const l of a())u||l&&(yield JSON.parse(l));u=!0}catch(l){if(lt(l))return;throw l}finally{u||t.abort(),De(t)}}return new n(c,t,s)}[(ht=new WeakMap,Symbol.asyncIterator)](){return this.iterator()}tee(){const e=[],t=[],s=this.iterator(),i=a=>({next:()=>{if(a.length===0){const c=s.next();e.push(c),t.push(c)}return a.shift()}});return[new n(()=>i(e),this.controller,o(this,ht,"f")),new n(()=>i(t),this.controller,o(this,ht,"f"))]}toReadableStream(){const e=this;let t;return rc({async start(){t=e[Symbol.asyncIterator]()},async pull(s){try{const{value:i,done:a}=await t.next();if(a)return s.close();const c=_c(JSON.stringify(i)+`
|
|
5
5
|
`);s.enqueue(c)}catch(i){s.error(i)}},async cancel(){await t.return?.()}})}}return n})();async function*Os(n,r){if(!n.body)throw r.abort(),typeof globalThis.navigator<"u"&&globalThis.navigator.product==="ReactNative"?new S("The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api"):new S("Attempted to iterate over a response with no body");const e=new au,t=new ss,s=ts(n.body);for await(const i of s)for(const a of t.decode(i)){const c=e.decode(a);c&&(yield c)}for(const i of t.flush()){const a=e.decode(i);a&&(yield a)}}class au{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(r){if(r.endsWith("\r")&&(r=r.substring(0,r.length-1)),!r){if(!this.event&&!this.data.length)return null;const i={event:this.event,data:this.data.join(`
|
|
@@ -7,7 +7,7 @@ import{_ as ce,g as Fo,P as qt,t as _s,k as cl}from"./index-BF4yi1Kg.js";functio
|
|
|
7
7
|
${i.map(g=>g.error).join(`
|
|
8
8
|
`)}
|
|
9
9
|
${a}
|
|
10
|
-
${d}`)}return a},h=ku(Tc);class Ds extends v{retrieve(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/deployment_runs/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/deployment_runs?beta=true",A,{query:i,...e,headers:f([{"anthropic-beta":[...t??[],"managed-agents-2026-04-01"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}}class Us extends v{create(r,e){const{betas:t,workspace_id:s,...i}=r;return this._client.post("/v1/deployments?beta=true",{body:i,...e,headers:f([{"anthropic-beta":[...t??[],"managed-agents-2026-04-01"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}retrieve(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/deployments/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}update(r,e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post(h`/v1/deployments/${r}?beta=true`,{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/deployments?beta=true",A,{query:i,...e,headers:f([{"anthropic-beta":[...t??[],"managed-agents-2026-04-01"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}archive(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/deployments/${r}/archive?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}pause(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/deployments/${r}/pause?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}run(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/deployments/${r}/run?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}unpause(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/deployments/${r}/unpause?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}}class Hs extends v{create(r,e){const{betas:t,workspace_id:s,...i}=r;return this._client.post("/v1/dreams?beta=true",{body:i,...e,headers:f([{"anthropic-beta":[...t??[],"dreaming-2026-04-21"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}retrieve(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/dreams/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"dreaming-2026-04-21"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/dreams?beta=true",A,{query:i,...e,headers:f([{"anthropic-beta":[...t??[],"dreaming-2026-04-21"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}archive(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/dreams/${r}/archive?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"dreaming-2026-04-21"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}cancel(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/dreams/${r}/cancel?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"dreaming-2026-04-21"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}}const Xt="x-stainless-helper",os="x-stainless-helper-method";function $c(n){return{[Xt]:n}}const Ee=Symbol("anthropic.sdk.stainlessHelper");function it(n){return typeof n=="object"&&n!==null&&Ee in n}function Ic(n,r){const e=new Set;if(n)for(const t of n)it(t)&&e.add(t[Ee]);if(r)for(const t of r){it(t)&&e.add(t[Ee]);const s=t.content;if(Array.isArray(s))for(const i of s){it(i)&&e.add(i[Ee]);const a=i?.tool?.definition;it(a)&&e.add(a[Ee])}}return Array.from(e)}function Pc(n,r){const e=Ic(n,r);return e.length===0?{}:{[Xt]:e.join(", ")}}function Mc(n){return it(n)?{[Xt]:n[Ee]}:{}}let Ws=class extends v{list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/files?beta=true",A,{query:i,...e,headers:f([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}delete(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.delete(h`/v1/files/${r}?beta=true`,{...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}download(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/files/${r}/content?beta=true`,{...t,headers:f([{Accept:"application/binary",...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers]),__binaryResponse:!0})}retrieveMetadata(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/files/${r}?beta=true`,{...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}upload(r,e){const{betas:t,workspace_id:s,...i}=r;return this._client.post("/v1/files?beta=true",me({body:i,...e,headers:f([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...s!=null?{"anthropic-workspace-id":s}:void 0},Mc(i.file),e?.headers])},this._client))}},zs=class extends v{retrieve(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/models/${r}?beta=true`,{...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/models?beta=true",X,{query:i,...e,headers:f([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}};class js extends v{create(r,e){const{betas:t,workspace_id:s,...i}=r;return this._client.post("/v1/user_profiles?beta=true",{body:i,...e,headers:f([{"anthropic-beta":[...t??[],"user-profiles-2026-08-18"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}retrieve(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/user_profiles/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"user-profiles-2026-08-18"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}update(r,e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post(h`/v1/user_profiles/${r}?beta=true`,{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"user-profiles-2026-08-18"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/user_profiles?beta=true",A,{query:i,...e,headers:f([{"anthropic-beta":[...t??[],"user-profiles-2026-08-18"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}createEnrollmentURL(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/user_profiles/${r}/enrollment_url?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"user-profiles-2026-08-18"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}}var Te={},F={},Fs;function Su(){if(Fs)return F;Fs=1;var n=F&&F.__extends||(function(){var p=function(d,g){return p=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(_,m){_.__proto__=m}||function(_,m){for(var y in m)m.hasOwnProperty(y)&&(_[y]=m[y])},p(d,g)};return function(d,g){p(d,g);function _(){this.constructor=d}d.prototype=g===null?Object.create(g):(_.prototype=g.prototype,new _)}})();Object.defineProperty(F,"__esModule",{value:!0});var r=256,e=(function(){function p(d){d===void 0&&(d="="),this._paddingCharacter=d}return p.prototype.encodedLength=function(d){return this._paddingCharacter?(d+2)/3*4|0:(d*8+5)/6|0},p.prototype.encode=function(d){for(var g="",_=0;_<d.length-2;_+=3){var m=d[_]<<16|d[_+1]<<8|d[_+2];g+=this._encodeByte(m>>>18&63),g+=this._encodeByte(m>>>12&63),g+=this._encodeByte(m>>>6&63),g+=this._encodeByte(m>>>0&63)}var y=d.length-_;if(y>0){var m=d[_]<<16|(y===2?d[_+1]<<8:0);g+=this._encodeByte(m>>>18&63),g+=this._encodeByte(m>>>12&63),y===2?g+=this._encodeByte(m>>>6&63):g+=this._paddingCharacter||"",g+=this._paddingCharacter||""}return g},p.prototype.maxDecodedLength=function(d){return this._paddingCharacter?d/4*3|0:(d*6+7)/8|0},p.prototype.decodedLength=function(d){return this.maxDecodedLength(d.length-this._getPaddingLength(d))},p.prototype.decode=function(d){if(d.length===0)return new Uint8Array(0);for(var g=this._getPaddingLength(d),_=d.length-g,m=new Uint8Array(this.maxDecodedLength(_)),y=0,x=0,E=0,b=0,k=0,R=0,T=0;x<_-4;x+=4)b=this._decodeChar(d.charCodeAt(x+0)),k=this._decodeChar(d.charCodeAt(x+1)),R=this._decodeChar(d.charCodeAt(x+2)),T=this._decodeChar(d.charCodeAt(x+3)),m[y++]=b<<2|k>>>4,m[y++]=k<<4|R>>>2,m[y++]=R<<6|T,E|=b&r,E|=k&r,E|=R&r,E|=T&r;if(x<_-1&&(b=this._decodeChar(d.charCodeAt(x)),k=this._decodeChar(d.charCodeAt(x+1)),m[y++]=b<<2|k>>>4,E|=b&r,E|=k&r),x<_-2&&(R=this._decodeChar(d.charCodeAt(x+2)),m[y++]=k<<4|R>>>2,E|=R&r),x<_-3&&(T=this._decodeChar(d.charCodeAt(x+3)),m[y++]=R<<6|T,E|=T&r),E!==0)throw new Error("Base64Coder: incorrect characters for decoding");return m},p.prototype._encodeByte=function(d){var g=d;return g+=65,g+=25-d>>>8&6,g+=51-d>>>8&-75,g+=61-d>>>8&-15,g+=62-d>>>8&3,String.fromCharCode(g)},p.prototype._decodeChar=function(d){var g=r;return g+=(42-d&d-44)>>>8&-r+d-43+62,g+=(46-d&d-48)>>>8&-r+d-47+63,g+=(47-d&d-58)>>>8&-r+d-48+52,g+=(64-d&d-91)>>>8&-r+d-65+0,g+=(96-d&d-123)>>>8&-r+d-97+26,g},p.prototype._getPaddingLength=function(d){var g=0;if(this._paddingCharacter){for(var _=d.length-1;_>=0&&d[_]===this._paddingCharacter;_--)g++;if(d.length<4||g>2)throw new Error("Base64Coder: incorrect padding")}return g},p})();F.Coder=e;var t=new e;function s(p){return t.encode(p)}F.encode=s;function i(p){return t.decode(p)}F.decode=i;var a=(function(p){n(d,p);function d(){return p!==null&&p.apply(this,arguments)||this}return d.prototype._encodeByte=function(g){var _=g;return _+=65,_+=25-g>>>8&6,_+=51-g>>>8&-75,_+=61-g>>>8&-13,_+=62-g>>>8&49,String.fromCharCode(_)},d.prototype._decodeChar=function(g){var _=r;return _+=(44-g&g-46)>>>8&-r+g-45+62,_+=(94-g&g-96)>>>8&-r+g-95+63,_+=(47-g&g-58)>>>8&-r+g-48+52,_+=(64-g&g-91)>>>8&-r+g-65+0,_+=(96-g&g-123)>>>8&-r+g-97+26,_},d})(e);F.URLSafeCoder=a;var c=new a;function u(p){return c.encode(p)}F.encodeURLSafe=u;function l(p){return c.decode(p)}return F.decodeURLSafe=l,F.encodedLength=function(p){return t.encodedLength(p)},F.maxDecodedLength=function(p){return t.maxDecodedLength(p)},F.decodedLength=function(p){return t.decodedLength(p)},F}var zn={exports:{}},xu=zn.exports,qs;function Ru(){return qs||(qs=1,(function(n){(function(r,e){var t={};e(t);var s=t.default;for(var i in t)s[i]=t[i];n.exports=s})(xu,function(r){r.__esModule=!0,r.digestLength=32,r.blockSize=64;var e=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function t(g,_,m,y,x){for(var E,b,k,R,T,$,C,M,L,I,ne,we,ye;x>=64;){for(E=_[0],b=_[1],k=_[2],R=_[3],T=_[4],$=_[5],C=_[6],M=_[7],I=0;I<16;I++)ne=y+I*4,g[I]=(m[ne]&255)<<24|(m[ne+1]&255)<<16|(m[ne+2]&255)<<8|m[ne+3]&255;for(I=16;I<64;I++)L=g[I-2],we=(L>>>17|L<<15)^(L>>>19|L<<13)^L>>>10,L=g[I-15],ye=(L>>>7|L<<25)^(L>>>18|L<<14)^L>>>3,g[I]=(we+g[I-7]|0)+(ye+g[I-16]|0);for(I=0;I<64;I++)we=(((T>>>6|T<<26)^(T>>>11|T<<21)^(T>>>25|T<<7))+(T&$^~T&C)|0)+(M+(e[I]+g[I]|0)|0)|0,ye=((E>>>2|E<<30)^(E>>>13|E<<19)^(E>>>22|E<<10))+(E&b^E&k^b&k)|0,M=C,C=$,$=T,T=R+we|0,R=k,k=b,b=E,E=we+ye|0;_[0]+=E,_[1]+=b,_[2]+=k,_[3]+=R,_[4]+=T,_[5]+=$,_[6]+=C,_[7]+=M,y+=64,x-=64}return y}var s=(function(){function g(){this.digestLength=r.digestLength,this.blockSize=r.blockSize,this.state=new Int32Array(8),this.temp=new Int32Array(64),this.buffer=new Uint8Array(128),this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this.reset()}return g.prototype.reset=function(){return this.state[0]=1779033703,this.state[1]=3144134277,this.state[2]=1013904242,this.state[3]=2773480762,this.state[4]=1359893119,this.state[5]=2600822924,this.state[6]=528734635,this.state[7]=1541459225,this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this},g.prototype.clean=function(){for(var _=0;_<this.buffer.length;_++)this.buffer[_]=0;for(var _=0;_<this.temp.length;_++)this.temp[_]=0;this.reset()},g.prototype.update=function(_,m){if(m===void 0&&(m=_.length),this.finished)throw new Error("SHA256: can't update because hash was finished.");var y=0;if(this.bytesHashed+=m,this.bufferLength>0){for(;this.bufferLength<64&&m>0;)this.buffer[this.bufferLength++]=_[y++],m--;this.bufferLength===64&&(t(this.temp,this.state,this.buffer,0,64),this.bufferLength=0)}for(m>=64&&(y=t(this.temp,this.state,_,y,m),m%=64);m>0;)this.buffer[this.bufferLength++]=_[y++],m--;return this},g.prototype.finish=function(_){if(!this.finished){var m=this.bytesHashed,y=this.bufferLength,x=m/536870912|0,E=m<<3,b=m%64<56?64:128;this.buffer[y]=128;for(var k=y+1;k<b-8;k++)this.buffer[k]=0;this.buffer[b-8]=x>>>24&255,this.buffer[b-7]=x>>>16&255,this.buffer[b-6]=x>>>8&255,this.buffer[b-5]=x>>>0&255,this.buffer[b-4]=E>>>24&255,this.buffer[b-3]=E>>>16&255,this.buffer[b-2]=E>>>8&255,this.buffer[b-1]=E>>>0&255,t(this.temp,this.state,this.buffer,0,b),this.finished=!0}for(var k=0;k<8;k++)_[k*4+0]=this.state[k]>>>24&255,_[k*4+1]=this.state[k]>>>16&255,_[k*4+2]=this.state[k]>>>8&255,_[k*4+3]=this.state[k]>>>0&255;return this},g.prototype.digest=function(){var _=new Uint8Array(this.digestLength);return this.finish(_),_},g.prototype._saveState=function(_){for(var m=0;m<this.state.length;m++)_[m]=this.state[m]},g.prototype._restoreState=function(_,m){for(var y=0;y<this.state.length;y++)this.state[y]=_[y];this.bytesHashed=m,this.finished=!1,this.bufferLength=0},g})();r.Hash=s;var i=(function(){function g(_){this.inner=new s,this.outer=new s,this.blockSize=this.inner.blockSize,this.digestLength=this.inner.digestLength;var m=new Uint8Array(this.blockSize);if(_.length>this.blockSize)new s().update(_).finish(m).clean();else for(var y=0;y<_.length;y++)m[y]=_[y];for(var y=0;y<m.length;y++)m[y]^=54;this.inner.update(m);for(var y=0;y<m.length;y++)m[y]^=106;this.outer.update(m),this.istate=new Uint32Array(8),this.ostate=new Uint32Array(8),this.inner._saveState(this.istate),this.outer._saveState(this.ostate);for(var y=0;y<m.length;y++)m[y]=0}return g.prototype.reset=function(){return this.inner._restoreState(this.istate,this.inner.blockSize),this.outer._restoreState(this.ostate,this.outer.blockSize),this},g.prototype.clean=function(){for(var _=0;_<this.istate.length;_++)this.ostate[_]=this.istate[_]=0;this.inner.clean(),this.outer.clean()},g.prototype.update=function(_){return this.inner.update(_),this},g.prototype.finish=function(_){return this.outer.finished?this.outer.finish(_):(this.inner.finish(_),this.outer.update(_,this.digestLength).finish(_)),this},g.prototype.digest=function(){var _=new Uint8Array(this.digestLength);return this.finish(_),_},g})();r.HMAC=i;function a(g){var _=new s().update(g),m=_.digest();return _.clean(),m}r.hash=a,r.default=a;function c(g,_){var m=new i(g).update(_),y=m.digest();return m.clean(),y}r.hmac=c;function u(g,_,m,y){var x=y[0];if(x===0)throw new Error("hkdf: cannot expand more");_.reset(),x>1&&_.update(g),m&&_.update(m),_.update(y),_.finish(g),y[0]++}var l=new Uint8Array(r.digestLength);function p(g,_,m,y){_===void 0&&(_=l),y===void 0&&(y=32);for(var x=new Uint8Array([1]),E=c(_,g),b=new i(E),k=new Uint8Array(b.digestLength),R=k.length,T=new Uint8Array(y),$=0;$<y;$++)R===k.length&&(u(k,b,m,x),R=0),T[$]=k[R++];return b.clean(),k.fill(0),x.fill(0),T}r.hkdf=p;function d(g,_,m,y){for(var x=new i(g),E=x.digestLength,b=new Uint8Array(4),k=new Uint8Array(E),R=new Uint8Array(E),T=new Uint8Array(y),$=0;$*E<y;$++){var C=$+1;b[0]=C>>>24&255,b[1]=C>>>16&255,b[2]=C>>>8&255,b[3]=C>>>0&255,x.reset(),x.update(_),x.update(b),x.finish(R);for(var M=0;M<E;M++)k[M]=R[M];for(var M=2;M<=m;M++){x.reset(),x.update(R).finish(R);for(var L=0;L<E;L++)k[L]^=R[L]}for(var M=0;M<E&&$*E+M<y;M++)T[$*E+M]=k[M]}for(var $=0;$<E;$++)k[$]=R[$]=0;for(var $=0;$<4;$++)b[$]=0;return x.clean(),T}r.pbkdf2=d})})(zn)),zn.exports}var Zt={},Ks;function Au(){if(Ks)return Zt;Ks=1,Object.defineProperty(Zt,"__esModule",{value:!0}),Zt.timingSafeEqual=r;function n(e,t=""){if(!e)throw new Error(t)}function r(e,t){if(e.byteLength!==t.byteLength)return!1;e instanceof DataView||(e=new DataView(ArrayBuffer.isView(e)?e.buffer:e)),t instanceof DataView||(t=new DataView(ArrayBuffer.isView(t)?t.buffer:t)),n(e instanceof DataView),n(t instanceof DataView);const s=e.byteLength;let i=0,a=-1;for(;++a<s;)i|=e.getUint8(a)^t.getUint8(a);return i===0}return Zt}var Vs;function Eu(){if(Vs)return Te;Vs=1,Object.defineProperty(Te,"__esModule",{value:!0}),Te.Webhook=Te.WebhookVerificationError=void 0;const n=Su(),r=Ru(),e=Au(),t=300;class s extends Error{constructor(u){super(u),Object.setPrototypeOf(this,s.prototype),this.name="ExtendableError",this.stack=new Error(u).stack}}class i extends s{constructor(u){super(u),Object.setPrototypeOf(this,i.prototype),this.name="WebhookVerificationError"}}Te.WebhookVerificationError=i;class a{constructor(u,l){if(l?.format==="raw")u instanceof Uint8Array?this.key=u:this.key=Uint8Array.from(u,p=>p.charCodeAt(0));else{if(typeof u!="string")throw new Error("Expected secret to be of type string");u.startsWith(a.prefix)&&(u=u.substring(a.prefix.length)),this.key=n.decode(u)}if(this.key.length===0)throw new Error("Secret can't be empty.")}verify(u,l,p){var d;const g=(d=p?.jsonParse)!==null&&d!==void 0?d:!0,_={};for(const $ of Object.keys(l))_[$.toLowerCase()]=l[$];const m=_["webhook-id"],y=_["webhook-signature"],x=_["webhook-timestamp"];if(!y||!m||!x)throw new i("Missing required headers");const E=this.verifyTimestamp(x),k=this.sign(m,E,u).split(",")[1],R=y.split(" "),T=new globalThis.TextEncoder;for(const $ of R){const[C,M]=$.split(",");if(C==="v1"&&(0,e.timingSafeEqual)(T.encode(M),T.encode(k))){const L=u.toString();return L===""?void 0:g?JSON.parse(L):void 0}}throw new i("No matching signature found")}sign(u,l,p){if(typeof p!="string")if(p.constructor.name==="Buffer")p=p.toString();else throw new Error("Expected payload to be of type string or Buffer.");const d=new TextEncoder,g=Math.floor(l.getTime()/1e3),_=d.encode(`${u}.${g}.${p}`);return`v1,${n.encode(r.hmac(this.key,_))}`}verifyTimestamp(u){const l=Math.floor(Date.now()/1e3),p=parseInt(u,10);if(Number.isNaN(p))throw new i("Invalid Signature Headers");if(l-p>t)throw new i("Message timestamp too old");if(p>l+t)throw new i("Message timestamp too new");return new Date(p*1e3)}}return Te.Webhook=a,a.prefix="whsec_",Te}var Tu=Eu();class Js extends v{parseUnverified(r){return JSON.parse(r)}unwrap(r,e){const t=e?.headers;if(t==null)throw new Error("Webhook headers are required in order to verify the signature");const s=e.key===void 0?this._client.webhookKey:e.key;if(!s)throw new Error("Webhook key must not be null or empty in order to unwrap");return new Tu.Webhook(s).verify(r,t),JSON.parse(r)}}let Xs=class extends v{list(r,e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList(h`/v1/agents/${r}/versions?beta=true`,A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}};var Gs=(()=>{class n extends v{constructor(){super(...arguments),this.versions=new Xs(this._client)}create(e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post("/v1/agents?beta=true",{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i,workspace_id:a,...c}=t??{};return this._client.get(h`/v1/agents/${e}?beta=true`,{query:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}update(e,t,s){const{betas:i,workspace_id:a,...c}=t;return this._client.post(h`/v1/agents/${e}?beta=true`,{body:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}list(e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList("/v1/agents?beta=true",A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}archive(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.post(h`/v1/agents/${e}/archive?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}}return n.Versions=Xs,n})();function Vt(n,r){if(!n)return()=>{};if(n.aborted)return r.abort(),()=>{};const e=()=>r.abort();return n.addEventListener("abort",e),()=>n.removeEventListener("abort",e)}function ot(n,r){return n instanceof z&&n.status===r}function $u(n){return n instanceof z&&typeof n.status=="number"&&n.status>=400&&n.status<500}function Xn(n){return $u(n)&&!ot(n,408)&&!ot(n,409)&&!ot(n,429)}function Oc(n,r,e){return Math.min(r*2**n,e)}function Iu(n,r){return n+Math.random()*(r-n)}function Cc(n){return n*(1-Math.random()*.25)}function Lc(n,{authToken:r,helper:e}){if(!r)throw new S(`copyClientForHelper: expected a non-empty authToken but received ${JSON.stringify(r)}`);const t=n,s=t._options.defaultHeaders,i=t._authState?.extraHeaders,a=i?Object.fromEntries(Object.entries(i).filter(([u])=>{const l=u.toLowerCase();return l!=="authorization"&&l!=="x-api-key"})):void 0,c=f([a,s,{[Xt]:e}]);return n.withOptions({apiKey:null,authToken:r,baseURL:n.baseURL,credentials:void 0,defaultHeaders:c})}var He,en,re,tn,nn,rn,pt,_t,We,ze,sn,je,gt;const Pu=999,Mu=1e3,Ou=6e4,Cu=3e5;var Wr=(()=>{class n{constructor(e){He.set(this,void 0),en.set(this,!1),re.set(this,void 0),tn.set(this,void 0),nn.set(this,void 0),rn.set(this,void 0),pt.set(this,void 0),_t.set(this,void 0),We.set(this,void 0),this.client=e.client,this.environmentId=e.environmentId,this.environmentKey=e.environmentKey,this.workerId=e.workerId??Bu(),w(this,He,Lc(e.client,{authToken:e.environmentKey,helper:"environments-work-poller"})),w(this,nn,e.autoStop??!0),w(this,rn,e.drain??!1),w(this,pt,e.blockMs===void 0?Pu:e.blockMs),w(this,_t,e.reclaimOlderThanMs??null),w(this,We,e.requestOptions),w(this,re,new AbortController),w(this,tn,Vt(e.signal,o(this,re,"f")))}get signal(){return o(this,re,"f").signal}abort(){o(this,re,"f").abort()}async*[(He=new WeakMap,en=new WeakMap,re=new WeakMap,tn=new WeakMap,nn=new WeakMap,rn=new WeakMap,pt=new WeakMap,_t=new WeakMap,We=new WeakMap,Symbol.asyncIterator)](){if(o(this,en,"f"))throw new S("Cannot iterate over a consumed WorkPoller");w(this,en,!0);const e=O(this.client);e.info("poller starting",{component:"work-poller",environment_id:this.environmentId});const t=new Nu(e,this.environmentId);try{let s=0;for(;!o(this,re,"f").signal.aborted;){let i;try{i=await o(this,He,"f").beta.environments.work.poll(this.environmentId,{"Anthropic-Worker-ID":this.workerId,...o(this,pt,"f")!==null?{block_ms:o(this,pt,"f")}:{},...o(this,_t,"f")!==null?{reclaim_older_than_ms:o(this,_t,"f")}:{}},{headers:f([o(this,We,"f")?.headers]),signal:o(this,re,"f").signal})}catch(a){if(o(this,re,"f").signal.aborted)return;if(Xn(a))throw e.error("poll failed permanently, stopping poller",{error:String(a)}),a;const c=Cc(Lu(s));e.warn("poll failed, backing off",{error:String(a),backoff_ms:c}),s++,await Be(c,o(this,re,"f").signal);continue}if(s=0,i==null){if(o(this,rn,"f"))return;t.onEmptyPoll(),await Be(Iu(1e3,3e3),o(this,re,"f").signal);continue}t.onClaim(),e.info("claimed work",{component:"work-poller",environment_id:this.environmentId,work_id:i.id,work_type:i.data.type});try{await o(this,He,"f").beta.environments.work.ack(i.id,{environment_id:i.environment_id},{headers:f([o(this,We,"f")?.headers]),signal:o(this,re,"f").signal})}catch(a){e.error("ack failed",{work_id:i.id,error:String(a)});continue}try{yield i}finally{if(o(this,nn,"f"))try{await o(this,He,"f").beta.environments.work.stop(i.id,{environment_id:i.environment_id},{headers:f([o(this,We,"f")?.headers])})}catch(a){ot(a,409)||e.warn("stop failed",{work_id:i.id,error:String(a)})}}}}finally{o(this,tn,"f").call(this)}}}return n})();function Lu(n){return Oc(n,Mu,Ou)}var Nu=(()=>{class n{constructor(e,t){ze.set(this,void 0),sn.set(this,void 0),je.set(this,void 0),gt.set(this,0),w(this,ze,e),w(this,sn,t)}onEmptyPoll(){const e=Date.now(),t={component:"work-poller",environment_id:o(this,sn,"f")};o(this,je,"f")===void 0?(w(this,je,w(this,gt,e,"f")),o(this,ze,"f").info("idle; polling for work",t)):e-o(this,gt,"f")>=Cu?(w(this,gt,e),o(this,ze,"f").info(`still polling; idle for ${Math.round((e-o(this,je,"f"))/1e3)}s`,t)):o(this,ze,"f").debug("poll returned no work",t)}onClaim(){w(this,je,void 0)}}return ze=new WeakMap,sn=new WeakMap,je=new WeakMap,gt=new WeakMap,n})();function Bu(){const r=globalThis.process?.env?.HOSTNAME;return r?`${r}-${Dr()}`:Dr()}var Fe,be,qe,Du=(()=>{class n{constructor(){Fe.set(this,[]),be.set(this,[]),qe.set(this,!1)}push(e){if(o(this,qe,"f"))return!1;const t=o(this,be,"f").shift();return t?t({done:!1,value:e}):o(this,Fe,"f").push(e),!0}close(){if(!o(this,qe,"f"))for(w(this,qe,!0);o(this,be,"f").length>0;)o(this,be,"f").shift()({done:!0,value:void 0})}next(e){return o(this,Fe,"f").length>0?Promise.resolve({done:!1,value:o(this,Fe,"f").shift()}):o(this,qe,"f")||e?.aborted?Promise.resolve({done:!0,value:void 0}):new Promise(t=>{const s=a=>{e?.removeEventListener("abort",i),t(a)},i=()=>{const a=o(this,be,"f").indexOf(s);a>=0&&o(this,be,"f").splice(a,1),t({done:!0,value:void 0})};o(this,be,"f").push(s),e?.addEventListener("abort",i,{once:!0})})}tryShift(){return o(this,Fe,"f").shift()}}return Fe=new WeakMap,be=new WeakMap,qe=new WeakMap,n})(),cs=(()=>{class n extends Error{constructor(e){const t=typeof e=="string"?e:e.map(s=>s.type==="text"?s.text:`[${s.type}]`).join(" ");super(t),this.name="ToolError",this.content=e}}return n})();function Qs(n){return"name"in n?n.name:"mcp_server_name"in n?n.mcp_server_name:n.type}function Uu(n){return n instanceof cs?n.content:`Error: ${n instanceof Error?n.message:String(n)}`}async function Hu(n,r,e){try{const t=n.parse?n.parse(r):r;return{content:await n.run(t,e),isError:!1}}catch(t){return{content:Uu(t),isError:!0}}}var mt,an,Ke,$e,ae,U,on,j,cn,wt,ln,H,Ve,Y,Je,ve,Xe,pe,un,yt,Z,dn,Ys,Zs,ei,ti,tr,ni,hn,fn,nr,ri,si;const ii=500,Wu=1e4,zu=12e4,ju=3e4,Fu=1e3,qu=3e4,Ku=5*6e4,Vu=6e4;function Nc(n){return n.type!=="session.status_idle"?!1:n.stop_reason?.type!=="requires_action"}var Ju=(()=>{class n{constructor(e,t){mt.set(this,void 0),an.set(this,void 0),Ke.set(this,new Set),$e.set(this,!1),ae.set(this,void 0),w(this,mt,e),w(this,an,t)}noteEvent(e){e.type!=="user.tool_confirmation"&&(Nc(e)?this.arm():this.disarm())}block(e){o(this,Ke,"f").add(e),o(this,ae,"f")!==void 0&&(w(this,$e,!0),clearTimeout(o(this,ae,"f")),w(this,ae,void 0))}unblock(e){o(this,Ke,"f").delete(e),o(this,Ke,"f").size===0&&o(this,$e,"f")&&this.arm()}arm(){if(!(o(this,mt,"f")<=0)){if(o(this,Ke,"f").size>0){w(this,$e,!0);return}w(this,$e,!1),o(this,ae,"f")!==void 0&&clearTimeout(o(this,ae,"f")),w(this,ae,setTimeout(o(this,an,"f"),o(this,mt,"f")))}}disarm(){w(this,$e,!1),o(this,ae,"f")!==void 0&&(clearTimeout(o(this,ae,"f")),w(this,ae,void 0))}}return mt=new WeakMap,an=new WeakMap,Ke=new WeakMap,$e=new WeakMap,ae=new WeakMap,n})(),zr=(()=>{class n{constructor(e,t){U.add(this),on.set(this,!1),j.set(this,void 0),cn.set(this,void 0),wt.set(this,void 0),ln.set(this,void 0),H.set(this,void 0),Ve.set(this,new Set),Y.set(this,new Set),Je.set(this,new Map),ve.set(this,new Map),Xe.set(this,new Du),pe.set(this,0),un.set(this,Ku),yt.set(this,null),Z.set(this,void 0),this.client=t.client,this.sessionId=e,this.tools=t.tools,this.maxIdleMs=t.maxIdleMs??Vu,w(this,H,O(t.client)),w(this,ln,new Map(t.tools.map(s=>[Qs(s),s]))),w(this,j,new AbortController),w(this,cn,Vt(t.signal,o(this,j,"f"))),w(this,wt,t.requestOptions),w(this,Z,new Ju(this.maxIdleMs,()=>{o(this,H,"f").info("session idle after its turn ended; stopping",{component:"session-tool-runner",session_id:this.sessionId,max_idle_ms:this.maxIdleMs}),o(this,j,"f").abort()}))}get signal(){return o(this,j,"f").signal}abort(){o(this,j,"f").abort()}_setSendRetryWindow(e){w(this,un,e)}async*[(on=new WeakMap,j=new WeakMap,cn=new WeakMap,wt=new WeakMap,ln=new WeakMap,H=new WeakMap,Ve=new WeakMap,Y=new WeakMap,Je=new WeakMap,ve=new WeakMap,Xe=new WeakMap,pe=new WeakMap,un=new WeakMap,yt=new WeakMap,Z=new WeakMap,U=new WeakSet,Symbol.asyncIterator)](){if(o(this,on,"f"))throw new S("Cannot iterate over a consumed SessionToolRunner");w(this,on,!0),o(this,H,"f").info("session tool runner starting",{component:"session-tool-runner",session_id:this.sessionId});const e=o(this,U,"m",Ys).call(this).catch(t=>{o(this,j,"f").signal.aborted||o(this,H,"f").error("stream loop failed",{error:String(t)}),o(this,j,"f").abort()});try{for(;;){const s=await o(this,Xe,"f").next(o(this,j,"f").signal);if(s.done)break;yield s.value}await e;let t;for(;(t=o(this,Xe,"f").tryShift())!==void 0;)yield t}finally{o(this,j,"f").abort(),o(this,Z,"f").disarm(),await e;try{await o(this,U,"m",si).call(this)}catch(t){o(this,H,"f").warn("drain failed",{error:String(t)})}o(this,Xe,"f").close();for(const t of this.tools)try{await t.close?.()}catch(s){o(this,H,"f").warn("tool.close failed",{tool:Qs(t),error:String(s)})}o(this,cn,"f").call(this)}}}return dn=function(){return{...o(this,wt,"f"),headers:f([$c("session-tool-runner"),o(this,wt,"f")?.headers]),signal:o(this,j,"f").signal}},Ys=async function(){const e=o(this,j,"f");let t=ii;for(;!e.signal.aborted;){try{const s=await this.client.beta.sessions.events.stream(this.sessionId,{},o(this,U,"m",dn).call(this));await o(this,U,"m",Zs).call(this);for await(const i of s)if(t=ii,await o(this,U,"m",ti).call(this,i))return}catch(s){if(e.signal.throwIfAborted(),Xn(s))throw o(this,H,"f").error("permanent stream failure, shutting down",{error:String(s)}),e.abort(),s;o(this,H,"f").warn("stream disconnected, reconnecting",{error:String(s),backoff_ms:t})}e.signal.throwIfAborted(),await Be(t,e.signal),t=Math.min(t*2,Wu)}},Zs=async function(){const e=o(this,j,"f"),t=[];let s=!1;try{for await(const c of this.client.beta.sessions.events.list(this.sessionId,{limit:1e3},o(this,U,"m",dn).call(this)))o(this,U,"m",ei).call(this,c,t),c.type!=="user.tool_confirmation"&&(s=Nc(c))}catch(c){e.signal.throwIfAborted(),o(this,H,"f").warn("reconcile list failed",{error:String(c)});for(const u of t)o(this,Ve,"f").delete(u.id);return}const i=t.filter(c=>!o(this,Y,"f").has(c.id));o(this,Z,"f").disarm();for(const c of i)await o(this,U,"m",tr).call(this,c);for(const c of[...o(this,ve,"f").values()]){const u=o(this,Je,"f").get(c.id);u!==void 0&&await o(this,U,"m",hn).call(this,c,u)}const a=i.filter(c=>!o(this,Y,"f").has(c.id)&&!o(this,ve,"f").has(c.id));s&&a.length===0?o(this,Z,"f").arm():o(this,Z,"f").disarm()},ei=function(e,t){e.type==="agent.tool_use"||e.type==="agent.custom_tool_use"?(o(this,Ve,"f").add(e.id),o(this,Y,"f").has(e.id)||t.push(e)):e.type==="user.tool_result"?o(this,Y,"f").add(e.tool_use_id):e.type==="user.custom_tool_result"?o(this,Y,"f").add(e.custom_tool_use_id):e.type==="user.tool_confirmation"&&(o(this,Y,"f").has(e.tool_use_id)||o(this,Je,"f").set(e.tool_use_id,e.result))},ti=async function(e){switch(o(this,Z,"f").noteEvent(e),e.type){case"agent.tool_use":case"agent.custom_tool_use":return o(this,Ve,"f").has(e.id)||(o(this,Ve,"f").add(e.id),await o(this,U,"m",tr).call(this,e)),!1;case"user.tool_confirmation":return await o(this,U,"m",ni).call(this,e),!1;case"user.tool_result":return o(this,Y,"f").add(e.tool_use_id),!1;case"user.custom_tool_result":return o(this,Y,"f").add(e.custom_tool_use_id),!1;case"session.status_terminated":case"session.deleted":return o(this,H,"f").info("session terminated",{component:"session-tool-runner",session_id:this.sessionId}),o(this,j,"f").abort(),!0;default:return!1}},tr=async function(e){const t=e.evaluated_permission,s=t==="deny"?"deny":o(this,Je,"f").get(e.id);if(s===void 0){t===void 0||t==="allow"?await o(this,U,"m",nr).call(this,e,void 0):o(this,ve,"f").has(e.id)||(o(this,H,"f").info("tool call awaiting confirmation; holding",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),o(this,ve,"f").set(e.id,e),o(this,Z,"f").block(e.id));return}await o(this,U,"m",hn).call(this,e,s)},ni=async function(e){o(this,Je,"f").set(e.tool_use_id,e.result);const t=o(this,ve,"f").get(e.tool_use_id);t!==void 0&&await o(this,U,"m",hn).call(this,t,e.result)},hn=async function(e,t){const s=o(this,ve,"f").delete(e.id);if(t==="allow"){o(this,H,"f").info("tool call confirmed",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),s||o(this,Z,"f").block(e.id);try{await o(this,U,"m",nr).call(this,e,"allow")}finally{o(this,Z,"f").unblock(e.id)}return}s&&o(this,Z,"f").unblock(e.id),o(this,Y,"f").add(e.id),o(this,H,"f").info("tool call denied; not executing",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),o(this,U,"m",fn).call(this,{event:e,toolUseId:e.id,name:e.name,isError:!1,posted:!1,confirmation:"deny"})},fn=function(e){o(this,Xe,"f").push(e)},nr=async function(e,t){var s,i;if(!o(this,Y,"f").has(e.id)){o(this,H,"f").info("executing tool",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),w(this,pe,(s=o(this,pe,"f"),s++,s));try{const a=o(this,ln,"f").get(e.name);if(!a){o(this,H,"f").info("tool not owned by this runner; leaving the tool_use_id pending for its owner",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),t==="allow"&&o(this,Z,"f").disarm(),o(this,U,"m",fn).call(this,{event:e,toolUseId:e.id,name:e.name,isError:!1,posted:!1,confirmation:t});return}let c,u;const l=new AbortController,p=Vt(o(this,j,"f").signal,l),d=setTimeout(()=>l.abort(),zu);try{const m=await Hu(a,e.input,{toolUse:e,toolUseBlock:e,signal:l.signal});c=m.content,u=m.isError}finally{clearTimeout(d),p()}const g=Xu(e,u,Gu(c)),_=await o(this,U,"m",ri).call(this,g,e.id);o(this,U,"m",fn).call(this,{event:e,result:g,toolUseId:e.id,name:e.name,isError:u,posted:_,confirmation:t})}finally{w(this,pe,(i=o(this,pe,"f"),i--,i)),o(this,pe,"f")===0&&o(this,yt,"f")?.call(this)}}},ri=async function(e,t){const s=o(this,j,"f"),i=Date.now();let a,c=0;for(;;){c++,s.signal.throwIfAborted();try{return await this.client.beta.sessions.events.send(this.sessionId,{events:[e]},o(this,U,"m",dn).call(this)),o(this,Y,"f").add(t),!0}catch(u){if(a=u,Xn(u))break;const l=o(this,un,"f")-(Date.now()-i);if(l<=0)break;const p=Math.min(Cc(Oc(c-1,Fu,qu)),l);o(this,H,"f").warn("tool result send failed; retrying",{tool_use_id:t,attempt:c,backoff_ms:p,error:String(u)}),await Be(p,s.signal)}}return o(this,H,"f").error("failed to send tool result",{tool_use_id:t,attempts:c,error:String(a)}),!1},si=async function(){o(this,pe,"f")!==0&&(await Promise.race([new Promise(e=>w(this,yt,e)),Be(ju)]),w(this,yt,null),o(this,pe,"f")>0&&o(this,H,"f").warn("drain timeout exceeded"))},n})();function Xu(n,r,e){return n.type==="agent.custom_tool_use"?{type:"user.custom_tool_result",custom_tool_use_id:n.id,is_error:r,content:e}:{type:"user.tool_result",tool_use_id:n.id,is_error:r,content:e}}function Gu(n){if(typeof n=="string")return[{type:"text",text:n||"(no output)"}];const r=n.map(e=>e.type==="text"?{type:"text",text:e.text||"(no output)"}:e.type==="image"||e.type==="document"?e:e.type==="search_result"?{type:"search_result",source:e.source,title:e.title,content:e.content.map(t=>({type:"text",text:t.text})),citations:{enabled:e.citations?.enabled??!1}}:{type:"text",text:JSON.stringify(e)});return r.length>0?r:[{type:"text",text:"(no output)"}]}const af=15e3,ai=5e3;function Qu(n,r){if(!(n>=ai))throw new S(`${r} must be at least ${ai}ms (got ${n}); to run without memory sync, pass \`memorySyncIntervalMs: null\` to the worker instead`)}var pn,bt,rr,vt,Ge;const oi=3e4,Yu=9e4,Zu="NO_HEARTBEAT";function ed(n){return n.resources.some(r=>r.type==="memory_store")}function td(n){if(!n)return null;let r;try{const t=n.replace(/-/g,"+").replace(/_/g,"/"),s=t.padEnd(Math.ceil(t.length/4)*4,"=");r=JSON.parse(Lr(Fl(s)))}catch{return null}if(r===null||typeof r!="object"||Array.isArray(r))return null;const e=r.sessions_token;return typeof e=="string"&&e!==""?e:null}var ci=(()=>{class n{constructor(e){if(pn.add(this),bt.set(this,void 0),e.unrestrictedPaths!==void 0)throw new S("The `unrestrictedPaths` option you passed to EnvironmentWorker (or client.beta.environments.work.worker()) is no longer supported. The worker's file tools (read, write, edit, glob, grep) are now always confined to `workdir` plus the session's memory folders. Remove `unrestrictedPaths` from your options; to let the file tools reach any other directory, add it to `AgentToolContext.allowedRoots` from a `tools` factory.");this.client=e.client,this.environmentId=e.environmentId,this.environmentKey=e.environmentKey,this.tools=e.tools,this.workdir=e.workdir??process.cwd(),this.maxFileBytes=e.maxFileBytes,this.maxIdleMs=e.maxIdleMs,e.memorySyncIntervalMs!=null&&Qu(e.memorySyncIntervalMs,"memorySyncIntervalMs"),this.memorySyncIntervalMs=e.memorySyncIntervalMs,this.memorySyncDeletions=e.memorySyncDeletions??"enabled",this.workerId=e.workerId,this.requestOptions=e.requestOptions,w(this,bt,e.signal)}async run(e){const{environmentId:t,environmentKey:s}=this;if(t===void 0||s===void 0)throw new S("EnvironmentWorker.run: environmentId and environmentKey are required to poll for work");const i=e??o(this,bt,"f"),a=new Wr({client:this.client,environmentId:t,environmentKey:s,...this.workerId!==void 0?{workerId:this.workerId}:{},...i?{signal:i}:{},...this.requestOptions!==void 0?{requestOptions:this.requestOptions}:{},autoStop:!1});for await(const c of a)try{await o(this,pn,"m",rr).call(this,c,s,a.signal)}catch(u){if(a.signal?.aborted)throw u;O(this.client).error("work item failed",{work_id:c.id,error:String(u)})}}async handleItem(e){const t=e?.workId??P("ANTHROPIC_WORK_ID"),s=e?.environmentId??P("ANTHROPIC_ENVIRONMENT_ID"),i=e?.sessionId??P("ANTHROPIC_SESSION_ID"),a=(e?.environmentKey??this.environmentKey??P("ANTHROPIC_ENVIRONMENT_KEY"))||void 0,c=e?.workSecret||P("ANTHROPIC_WORK_SECRET")||null;if(!t)throw new S("handleItem: workId is required — pass it or set ANTHROPIC_WORK_ID");if(!s)throw new S("handleItem: environmentId is required — pass it or set ANTHROPIC_ENVIRONMENT_ID");if(!i)throw new S("handleItem: sessionId is required — pass it or set ANTHROPIC_SESSION_ID");if(!a&&!c)throw new S("handleItem: environmentKey is required when there is no work secret — pass it, construct the worker with it, or set ANTHROPIC_ENVIRONMENT_KEY");const u={id:t,environment_id:s,secret:c,data:{type:"session",id:i}};await o(this,pn,"m",rr).call(this,u,a,e?.signal??o(this,bt,"f"))}}return bt=new WeakMap,pn=new WeakSet,rr=async function(e,t,s){const i=O(this.client),a=td(e.secret),c=a??t;if(c===void 0)throw new S("handleItem: the work item carried a secret payload but no sessions token could be extracted, and there is no environment key to fall back to; the poller must issue a secret whose payload carries `sessions_token`, or provide the environment key (pass it, construct the worker with it, or set ANTHROPIC_ENVIRONMENT_KEY)");e.secret&&a===null&&i.warn("work item carried a secret payload but no sessions token could be extracted; falling back to the environment key",{work_id:e.id});const u=Lc(this.client,{authToken:c,helper:"environments-worker"}),l=e.data.id,p=new AbortController,d=Vt(s,p),g=new rd(p),_=await ce(()=>import("./node.browser-PMfGv8gB.js"),__vite__mapDeps([3,1,2]));let m,y;const x=id(u,e,g,i,this.requestOptions,R=>{m=R,y?._setSendRetryWindow(R)}).catch(R=>{p.signal.aborted||i.error("heartbeat loop failed",{work_id:e.id,error:String(R)}),p.abort()});let E=async()=>{},b,k=!1;try{if(e.data.type!=="session"){i.debug("skipping non-session work item",{work_id:e.id,type:e.data.type});return}const R=await u.beta.sessions.retrieve(l);if(a===null&&this.memorySyncIntervalMs!==null&&ed(R))throw new _.SessionMemoryError(`cannot mount the session's memories: the work item carried no sessions token (work_id=${e.id}, session_id=${l}); the memory endpoints reject the environment key, so the poller must issue a per-item \`secret\` carrying \`sessions_token\`, or set \`memorySyncIntervalMs: null\` to run without memory`);const T={workdir:this.workdir,client:u,session:R,...this.maxFileBytes!==void 0?{maxFileBytes:this.maxFileBytes}:{}};try{E=await _.setupSkills(T)}catch(C){i.warn("skill setup failed",{session_id:l,work_id:e.id,error:String(C)})}a!==null&&this.memorySyncIntervalMs!==null?(b=new _.SessionMemoryStores(u,{workdir:this.workdir,...this.memorySyncIntervalMs!==void 0?{syncIntervalMs:this.memorySyncIntervalMs}:{},syncDeletions:this.memorySyncDeletions}),await b.download(R),T.allowedRoots=b.roots,T.readOnlyRoots=b.readOnlyRoots):i.debug("memory stores disabled for this item",{work_id:e.id});const $=typeof this.tools=="function"?this.tools(T):this.tools??_.betaAgentToolset20260401(T);y=new zr(l,{client:u,tools:$,...this.maxIdleMs!==void 0?{maxIdleMs:this.maxIdleMs}:{},...this.requestOptions!==void 0?{requestOptions:this.requestOptions}:{},signal:p.signal}),m!==void 0&&y._setSendRetryWindow(m);for await(const C of y)b&&await b.syncIfDue();k=!p.signal.aborted}finally{try{await E().catch(R=>{i.warn("skill cleanup failed",{session_id:l,work_id:e.id,error:String(R)})})}finally{if(b){const R=_.MEMORY_FLUSH_TIMEOUT_MS;k&&await li(b.finish(),R)&&i.warn(`final memory sync cut off after ${R}ms; the flush that follows still uploads changed files`,{session_id:l,work_id:e.id});const T=new AbortController;await li(b.flushWrites(T.signal),R)&&(T.abort(),i.warn(`memory flush cut off after ${R}ms; changed files it had not uploaded yet are not saved`,{session_id:l,work_id:e.id})),await b.dispose().catch(C=>{i.warn("memory store cleanup failed",{session_id:l,work_id:e.id,error:String(C)})})}}g.finish("runner_done"),d(),await x,g.lost?i.info("lease lost; released without stopping it",{session_id:l,work_id:e.id}):await nd(u,e,i,this.requestOptions)}},n})();async function li(n,r){let e;try{return await Promise.race([n.then(()=>!1,()=>!1),new Promise(t=>{e=setTimeout(()=>t(!0),r)})])}finally{e!==void 0&&clearTimeout(e)}}async function nd(n,r,e,t){try{await n.beta.environments.work.stop(r.id,{environment_id:r.environment_id,force:!0},{...t,headers:f([t?.headers])})}catch(s){ot(s,409)||e.error("force-stop on exit failed",{work_id:r.id,error:String(s)})}}var rd=(()=>{class n{constructor(e){vt.set(this,void 0),Ge.set(this,void 0),w(this,vt,e)}get signal(){return o(this,vt,"f").signal}finish(e){w(this,Ge,o(this,Ge,"f")??e),o(this,vt,"f").abort()}get lost(){return o(this,Ge,"f")==="lease_lost"||o(this,Ge,"f")==="assumed_lost"}}return vt=new WeakMap,Ge=new WeakMap,n})();function sd(n){let r=n instanceof z?n.error:void 0;for(const e of["error","details","current_state"]){if(!bs(r))return{};r=r[e]}return bs(r)?r:{}}async function id(n,r,e,t,s,i){let a=oi,c=Yu,u=Date.now(),l=Zu;const p=async()=>{const d=new AbortController,g=Vt(e.signal,d),_=setTimeout(()=>d.abort(),a);try{const m=await n.beta.environments.work.heartbeat(r.id,{environment_id:r.environment_id,expected_last_heartbeat:l},{...s,headers:f([s?.headers]),signal:d.signal});u=Date.now(),l=m.last_heartbeat,m.ttl_seconds>0&&(c=m.ttl_seconds*1e3,a=Math.max(1e3,Math.min(c/2,oi)),i?.(c)),(m.state==="stopping"||m.state==="stopped")&&(t.info("heartbeat signals shutdown",{work_id:r.id,state:m.state}),e.finish("control_plane_stop")),m.lease_extended||(t.warn("lease not extended, shutting down",{work_id:r.id}),e.finish("control_plane_stop"))}catch(m){if(e.signal.throwIfAborted(),ot(m,412)){const y=sd(m);t.error("lease lost: heartbeat precondition failed",{work_id:r.id,server_state:y.state,server_ttl_seconds:y.ttl_seconds,server_last_heartbeat:y.last_heartbeat}),e.finish("lease_lost");return}if(Xn(m))throw t.error("permanent heartbeat failure",{work_id:r.id,error:String(m)}),e.finish("heartbeat_rejected"),m;if(Date.now()-u>c){t.error("lease assumed lost: no successful heartbeat in ttl",{work_id:r.id,ttl_ms:c,error:String(m)}),e.finish("assumed_lost");return}t.warn("transient heartbeat failure",{work_id:r.id,error:String(m)})}finally{clearTimeout(_),g()}};for(await p();!e.signal.aborted;)await Be(a,e.signal),e.signal.throwIfAborted(),await p()}var ui=(()=>{class n extends v{retrieve(e,t,s){const{environment_id:i,betas:a,workspace_id:c}=t;return this._client.get(h`/v1/environments/${i}/work/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...a??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},s?.headers])})}update(e,t,s){const{environment_id:i,betas:a,workspace_id:c,...u}=t;return this._client.post(h`/v1/environments/${i}/work/${e}?beta=true`,{body:u,...s,headers:f([{"anthropic-beta":[...a??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},s?.headers])})}list(e,t={},s){const{betas:i,...a}=t??{};return this._client.getAPIList(h`/v1/environments/${e}/work?beta=true`,A,{query:a,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString()},s?.headers])})}ack(e,t,s){const{environment_id:i,betas:a}=t;return this._client.post(h`/v1/environments/${i}/work/${e}/ack?beta=true`,{...s,headers:f([{"anthropic-beta":[...a??[],"managed-agents-2026-04-01"].toString()},s?.headers])})}heartbeat(e,t,s){const{environment_id:i,desired_ttl_seconds:a,expected_last_heartbeat:c,betas:u}=t;return this._client.post(h`/v1/environments/${i}/work/${e}/heartbeat?beta=true`,{query:{desired_ttl_seconds:a,expected_last_heartbeat:c},...s,headers:f([{"anthropic-beta":[...u??[],"managed-agents-2026-04-01"].toString()},s?.headers])})}poll(e,t={},s){const{betas:i,"Anthropic-Worker-ID":a,...c}=t??{};return this._client.get(h`/v1/environments/${e}/work/poll?beta=true`,{query:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"Anthropic-Worker-ID":a}:void 0},s?.headers])})}stats(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.get(h`/v1/environments/${e}/work/stats?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}stop(e,t,s){const{environment_id:i,betas:a,workspace_id:c,...u}=t;return this._client.post(h`/v1/environments/${i}/work/${e}/stop?beta=true`,{body:u,...s,headers:f([{"anthropic-beta":[...a??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},s?.headers])})}poller(e){return new Wr({...e,client:this._client})}worker(e){return new ci({...e,client:this._client})}}return n.WorkPoller=Wr,n.EnvironmentWorker=ci,n})(),di=(()=>{class n extends v{constructor(){super(...arguments),this.work=new ui(this._client)}create(e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post("/v1/environments?beta=true",{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.get(h`/v1/environments/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}update(e,t,s){const{betas:i,workspace_id:a,...c}=t;return this._client.post(h`/v1/environments/${e}?beta=true`,{body:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}list(e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList("/v1/environments?beta=true",A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.delete(h`/v1/environments/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}archive(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.post(h`/v1/environments/${e}/archive?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}}return n.Work=ui,n})();class hi extends v{create(r,e,t){const{view:s,betas:i,workspace_id:a,...c}=e;return this._client.post(h`/v1/memory_stores/${r}/memories?beta=true`,{query:{view:s},body:c,...t,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}retrieve(r,e,t){const{memory_store_id:s,betas:i,workspace_id:a,...c}=e;return this._client.get(h`/v1/memory_stores/${s}/memories/${r}?beta=true`,{query:c,...t,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}update(r,e,t){const{memory_store_id:s,view:i,betas:a,workspace_id:c,...u}=e;return this._client.post(h`/v1/memory_stores/${s}/memories/${r}?beta=true`,{query:{view:i},body:u,...t,headers:f([{"anthropic-beta":[...a??[],"agent-memory-2026-07-22"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},t?.headers])})}list(r,e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList(h`/v1/memory_stores/${r}/memories?beta=true`,A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(r,e,t){const{memory_store_id:s,expected_content_sha256:i,betas:a,workspace_id:c}=e;return this._client.delete(h`/v1/memory_stores/${s}/memories/${r}?beta=true`,{query:{expected_content_sha256:i},...t,headers:f([{"anthropic-beta":[...a??[],"agent-memory-2026-07-22"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},t?.headers])})}}class fi extends v{retrieve(r,e,t){const{memory_store_id:s,betas:i,workspace_id:a,...c}=e;return this._client.get(h`/v1/memory_stores/${s}/memory_versions/${r}?beta=true`,{query:c,...t,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}list(r,e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList(h`/v1/memory_stores/${r}/memory_versions?beta=true`,A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}redact(r,e,t){const{memory_store_id:s,betas:i,workspace_id:a}=e;return this._client.post(h`/v1/memory_stores/${s}/memory_versions/${r}/redact?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}}var pi=(()=>{class n extends v{constructor(){super(...arguments),this.memories=new hi(this._client),this.memoryVersions=new fi(this._client)}create(e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post("/v1/memory_stores?beta=true",{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.get(h`/v1/memory_stores/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}update(e,t,s){const{betas:i,workspace_id:a,...c}=t;return this._client.post(h`/v1/memory_stores/${e}?beta=true`,{body:c,...s,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}list(e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList("/v1/memory_stores?beta=true",A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.delete(h`/v1/memory_stores/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}archive(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.post(h`/v1/memory_stores/${e}/archive?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}}return n.Memories=hi,n.MemoryVersions=fi,n})(),Bc=(()=>{class n{constructor(e,t){this.iterator=e,this.controller=t}async*decoder(){const e=new ss;for await(const t of this.iterator)for(const s of e.decode(t))yield JSON.parse(s);for(const t of e.flush())yield JSON.parse(t)}[Symbol.asyncIterator](){return this.decoder()}static fromResponse(e,t){if(!e.body)throw t.abort(),typeof globalThis.navigator<"u"&&globalThis.navigator.product==="ReactNative"?new S("The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api"):new S("Attempted to iterate over a response with no body");return new n(ts(e.body),t)}}return n})();let _i=class extends v{create(r,e){const{betas:t,user_profile_id:s,workspace_id:i,...a}=r;return this._client.post("/v1/messages/batches?beta=true",{body:a,...e,headers:f([{"anthropic-beta":[...t??[],"message-batches-2024-09-24"].toString(),...s!=null?{"anthropic-user-profile-id":s}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},e?.headers])})}retrieve(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/messages/batches/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"message-batches-2024-09-24"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/messages/batches?beta=true",X,{query:i,...e,headers:f([{"anthropic-beta":[...t??[],"message-batches-2024-09-24"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}delete(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.delete(h`/v1/messages/batches/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"message-batches-2024-09-24"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}cancel(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/messages/batches/${r}/cancel?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"message-batches-2024-09-24"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}async results(r,e={},t){const s=await this.retrieve(r,e,t);if(!s.results_url)throw new S(`No batch \`results_url\`; Has it finished processing? ${s.processing_status} - ${s.id}`);const{betas:i,workspace_id:a}=e??{};return this._client.get(s.results_url,{...t,headers:f([{"anthropic-beta":[...i??[],"message-batches-2024-09-24"].toString(),Accept:"application/binary",...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers]),stream:!0,__binaryResponse:!0})._thenUnwrap((c,u)=>Bc.fromResponse(u.response,u.controller))}};const Dc={"claude-opus-4@20250514":8192,"anthropic.claude-opus-4-1-20250805-v1:0":8192,"claude-opus-4-1@20250805":8192};function Uc(n){return n?.output_format??n?.output_config?.format}function gi(n,r,e){const t=Uc(r);return!r||!("parse"in(t??{}))?{...n,content:n.content.map(s=>{if(s.type==="text"){const i=Object.defineProperty({...s},"parsed_output",{value:null,enumerable:!1});return Object.defineProperty(i,"parsed",{get(){return e.logger.warn("The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead."),null},enumerable:!1})}return s}),parsed_output:null}:Hc(n,r,e)}function Hc(n,r,e){let t=null;const s=n.content.map(i=>{if(i.type==="text"){const a=ad(r,i.text);t===null&&(t=a);const c=Object.defineProperty({...i},"parsed_output",{value:a,enumerable:!1});return Object.defineProperty(c,"parsed",{get(){return e.logger.warn("The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead."),a},enumerable:!1})}return i});return{...n,content:s,parsed_output:t}}function ad(n,r){const e=Uc(n);if(e?.type!=="json_schema")return null;try{return"parse"in e?e.parse(r):JSON.parse(r)}catch(t){throw new S(`Failed to parse structured output: ${t}`)}}const od=n=>{let r=0,e=[];for(;r<n.length;){let t=n[r];if(t==="\\"){r++;continue}if(t==="{"){e.push({type:"brace",value:"{"}),r++;continue}if(t==="}"){e.push({type:"brace",value:"}"}),r++;continue}if(t==="["){e.push({type:"paren",value:"["}),r++;continue}if(t==="]"){e.push({type:"paren",value:"]"}),r++;continue}if(t===":"){e.push({type:"separator",value:":"}),r++;continue}if(t===","){e.push({type:"delimiter",value:","}),r++;continue}if(t==='"'){const c=r+1;let u=c,l=!1;for(;;){if(u=n.indexOf('"',u),u===-1){l=!0;break}let p=0,d=u-1;for(;d>=c&&n[d]==="\\";)p++,d--;if(p%2===0)break;u++}l?r=n.length:(e.push({type:"string",value:n.slice(c,u)}),r=u+1);continue}if(t&&/\s/.test(t)){r++;continue}let i=/[0-9]/;if(t&&i.test(t)||t==="-"||t==="."){let c="";for(t==="-"&&(c+=t,t=n[++r]);t&&(i.test(t)||t==="."||t==="e"||t==="E"||(t==="-"||t==="+")&&(c[c.length-1]==="e"||c[c.length-1]==="E"));)c+=t,t=n[++r];e.push({type:"number",value:c,unterminated:r===n.length});continue}let a=/[a-z]/i;if(t&&a.test(t)){let c="";for(;t&&a.test(t)&&r!==n.length;)c+=t,t=n[++r];if(c=="true"||c=="false"||c==="null")e.push({type:"name",value:c});else{r++;continue}continue}r++}return e},cd=n=>{let r=[];for(const i of n)(i.type==="brace"||i.type==="paren")&&(i.value==="{"||i.value==="["?r.push(i.value):r.pop());let e=r[r.length-1],t=n.length,s=/^-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-+]?[0-9]+)?$/;for(;t>0;){let i=n[t-1];switch(i.type){case"separator":t--;continue;case"number":if(i.unterminated||!s.test(i.value)){t--;continue}break;case"string":let a=n[t-2];if(e==="{"&&(a?.type==="delimiter"||a?.type==="brace"&&a.value==="{")){t--;continue}break;case"delimiter":t--;break}break}return n.slice(0,t)},ld=n=>{let r=[];return n.map(e=>{e.type==="brace"&&(e.value==="{"?r.push("}"):r.splice(r.lastIndexOf("}"),1)),e.type==="paren"&&(e.value==="["?r.push("]"):r.splice(r.lastIndexOf("]"),1))}),r.length>0&&r.reverse().map(e=>{e==="}"?n.push({type:"brace",value:"}"}):e==="]"&&n.push({type:"paren",value:"]"})}),n},ud=n=>{let r="";return n.map(e=>{e.type==="string"?r+='"'+e.value+'"':r+=e.value}),r},dd=n=>JSON.parse(ud(ld(cd(od(n))))),ct="__json_buf";function Wc(n,r){const e={};for(const i of Object.keys(n))i!=="input"&&(e[i]=n[i]);Object.defineProperty(e,ct,{value:r,enumerable:!1,writable:!0});let t,s=!1;return Object.defineProperty(e,"input",{enumerable:!0,configurable:!0,get(){return s||(t=r?dd(r):{},s=!0),t}}),e}var q,ke,Qe,kt,_n,St,xt,gn,Rt,ue,At,mn,wn,Ie,yn,bn,vn,Et,sr,mi,Tt,ir,ar,or,wi,cr;function lr(n){return n.type==="tool_use"||n.type==="server_tool_use"||n.type==="mcp_tool_use"}var zc=(()=>{class n{constructor(e,t){q.add(this),this.messages=[],this.receivedMessages=[],ke.set(this,void 0),Qe.set(this,null),this.controller=new AbortController,kt.set(this,void 0),_n.set(this,()=>{}),St.set(this,()=>{}),xt.set(this,void 0),gn.set(this,()=>{}),Rt.set(this,()=>{}),ue.set(this,{}),At.set(this,!1),mn.set(this,!1),wn.set(this,!1),Ie.set(this,!1),yn.set(this,void 0),bn.set(this,void 0),vn.set(this,void 0),Et.set(this,void 0),Tt.set(this,s=>{if(w(this,mn,!0),lt(s)&&(s=new oe),s instanceof oe)return w(this,wn,!0),this._emit("abort",s);if(s instanceof S)return this._emit("error",s);if(s instanceof Error){const i=new S(s.message);return i.cause=s,this._emit("error",i)}return this._emit("error",new S(String(s)))}),w(this,kt,new Promise((s,i)=>{w(this,_n,s,"f"),w(this,St,i,"f")})),w(this,xt,new Promise((s,i)=>{w(this,gn,s,"f"),w(this,Rt,i,"f")})),o(this,kt,"f").catch(()=>{}),o(this,xt,"f").catch(()=>{}),w(this,Qe,e),w(this,Et,t?.logger??console)}get response(){return o(this,yn,"f")}get request_id(){return o(this,bn,"f")}get workspace_id(){return o(this,vn,"f")}async withResponse(){w(this,Ie,!0);const e=await o(this,kt,"f");if(!e)throw new Error("Could not resolve a `Response` object");return{data:this,response:e,request_id:e.headers.get("request-id"),workspace_id:e.headers.get("anthropic-workspace-id")}}static fromReadableStream(e){const t=new n(null);return t._run(()=>t._fromReadableStream(e)),t}static createMessage(e,t,s,{logger:i}={}){const a=new n(t,{logger:i});for(const c of t.messages)a._addMessageParam(c);return w(a,Qe,{...t,stream:!0}),a._run(()=>a._createMessage(e,{...t,stream:!0},{...s,headers:{...s?.headers,[os]:"stream"}})),a}_run(e){e().then(()=>{this._emitFinal(),this._emit("end")},o(this,Tt,"f"))}_addMessageParam(e){this.messages.push(e)}_addMessage(e,t=!0){this.receivedMessages.push(e),t&&this._emit("message",e)}async _createMessage(e,t,s){const i=s?.signal;let a;i&&(i.aborted&&this.controller.abort(),a=this.controller.abort.bind(this.controller),i.addEventListener("abort",a));try{o(this,q,"m",ir).call(this);const{response:c,data:u}=await e.create({...t,stream:!0},{...s,signal:this.controller.signal}).withResponse();this._connected(c);for await(const l of u)o(this,q,"m",ar).call(this,l);if(u.controller.signal?.aborted)throw new oe;o(this,q,"m",or).call(this)}finally{i&&a&&i.removeEventListener("abort",a)}}_connected(e){this.ended||(w(this,yn,e),w(this,bn,e?.headers.get("request-id")),w(this,vn,e?.headers.get("anthropic-workspace-id")),o(this,_n,"f").call(this,e),this._emit("connect"))}get ended(){return o(this,At,"f")}get errored(){return o(this,mn,"f")}get aborted(){return o(this,wn,"f")}abort(){this.controller.abort()}on(e,t){return(o(this,ue,"f")[e]||(o(this,ue,"f")[e]=[])).push({listener:t}),this}off(e,t){const s=o(this,ue,"f")[e];if(!s)return this;const i=s.findIndex(a=>a.listener===t);return i>=0&&s.splice(i,1),this}once(e,t){return(o(this,ue,"f")[e]||(o(this,ue,"f")[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,s)=>{w(this,Ie,!0),e!=="error"&&this.once("error",s),this.once(e,t)})}async done(){w(this,Ie,!0),await o(this,xt,"f")}get currentMessage(){return o(this,ke,"f")}async finalMessage(){return await this.done(),o(this,q,"m",sr).call(this)}async finalText(){return await this.done(),o(this,q,"m",mi).call(this)}_emit(e,...t){if(o(this,At,"f"))return;e==="end"&&(w(this,At,!0),o(this,gn,"f").call(this));const s=o(this,ue,"f")[e];if(s&&(o(this,ue,"f")[e]=s.filter(i=>!i.once),s.forEach(({listener:i})=>i(...t))),e==="abort"){const i=t[0];!o(this,Ie,"f")&&!s?.length&&Promise.reject(i),o(this,St,"f").call(this,i),o(this,Rt,"f").call(this,i),this._emit("end");return}if(e==="error"){const i=t[0];!o(this,Ie,"f")&&!s?.length&&Promise.reject(i),o(this,St,"f").call(this,i),o(this,Rt,"f").call(this,i),this._emit("end")}}_emitFinal(){this.receivedMessages.at(-1)&&this._emit("finalMessage",o(this,q,"m",sr).call(this))}async _fromReadableStream(e,t){const s=t?.signal;let i;s&&(s.aborted&&this.controller.abort(),i=this.controller.abort.bind(this.controller),s.addEventListener("abort",i));try{o(this,q,"m",ir).call(this),this._connected(null);const a=dt.fromReadableStream(e,this.controller);for await(const c of a)o(this,q,"m",ar).call(this,c);if(a.controller.signal?.aborted)throw new oe;o(this,q,"m",or).call(this)}finally{s&&i&&s.removeEventListener("abort",i)}}[(ke=new WeakMap,Qe=new WeakMap,kt=new WeakMap,_n=new WeakMap,St=new WeakMap,xt=new WeakMap,gn=new WeakMap,Rt=new WeakMap,ue=new WeakMap,At=new WeakMap,mn=new WeakMap,wn=new WeakMap,Ie=new WeakMap,yn=new WeakMap,bn=new WeakMap,vn=new WeakMap,Et=new WeakMap,Tt=new WeakMap,q=new WeakSet,sr=function(){if(this.receivedMessages.length===0)throw new S("stream ended without producing a Message with role=assistant");return this.receivedMessages.at(-1)},mi=function(){if(this.receivedMessages.length===0)throw new S("stream ended without producing a Message with role=assistant");const t=this.receivedMessages.at(-1).content.filter(s=>s.type==="text").map(s=>s.text);if(t.length===0)throw new S("stream ended without producing a content block with type=text");return t.join(" ")},ir=function(){this.ended||w(this,ke,void 0)},ar=function(t){if(this.ended)return;const s=o(this,q,"m",wi).call(this,t);switch(this._emit("streamEvent",t,s),t.type){case"content_block_delta":{const i=s.content.at(-1);switch(t.delta.type){case"text_delta":{i.type==="text"&&this._emit("text",t.delta.text,i.text||"");break}case"citations_delta":{i.type==="text"&&this._emit("citation",t.delta.citation,i.citations??[]);break}case"input_json_delta":{if(lr(i)&&o(this,ue,"f").inputJson?.length){let a;try{a=i.input}catch(c){o(this,Tt,"f").call(this,o(this,q,"m",cr).call(this,i,c));break}this._emit("inputJson",t.delta.partial_json,a)}break}case"thinking_delta":{i.type==="thinking"&&this._emit("thinking",t.delta.thinking,i.thinking);break}case"signature_delta":{i.type==="thinking"&&this._emit("signature",i.signature);break}case"compaction_delta":{i.type==="compaction"&&i.content&&this._emit("compaction",i.content);break}default:t.delta}break}case"message_stop":{this._addMessageParam(s),this._addMessage(gi(s,o(this,Qe,"f"),{logger:o(this,Et,"f")}),!0);break}case"content_block_stop":{this._emit("contentBlock",s.content.at(-1));break}case"message_start":{w(this,ke,s);break}}},or=function(){if(this.ended)throw new S("stream has ended, this shouldn't happen");const t=o(this,ke,"f");if(!t)throw new S("request ended without sending any chunks");return w(this,ke,void 0),gi(t,o(this,Qe,"f"),{logger:o(this,Et,"f")})},wi=function(t){let s=o(this,ke,"f");if(t.type==="message_start"){if(s)throw new S(`Unexpected event order, got ${t.type} before receiving "message_stop"`);return t.message}if(!s)throw new S(`Unexpected event order, got ${t.type} before "message_start"`);switch(t.type){case"message_stop":return s;case"message_delta":return s.stop_reason=t.delta.stop_reason,s.stop_sequence=t.delta.stop_sequence,s.stop_details=t.delta.stop_details,s.usage.output_tokens=t.usage.output_tokens,t.delta.container!=null&&(s.container=t.delta.container),t.context_management!=null&&(s.context_management=t.context_management),t.input_transformations!=null&&(s.input_transformations=t.input_transformations),t.usage.input_tokens!=null&&(s.usage.input_tokens=t.usage.input_tokens),t.usage.cache_creation_input_tokens!=null&&(s.usage.cache_creation_input_tokens=t.usage.cache_creation_input_tokens),t.usage.cache_read_input_tokens!=null&&(s.usage.cache_read_input_tokens=t.usage.cache_read_input_tokens),t.usage.server_tool_use!=null&&(s.usage.server_tool_use=t.usage.server_tool_use),t.usage.iterations!=null&&(s.usage.iterations=t.usage.iterations),t.usage.fallback_credit!=null&&(s.usage.fallback_credit=t.usage.fallback_credit),t.usage.output_tokens_details!=null&&(s.usage.output_tokens_details=t.usage.output_tokens_details),s;case"content_block_start":return s.content.push(t.content_block),t.content_block.type==="fallback"&&(s.model=t.content_block.to.model),s;case"content_block_delta":{const i=s.content.at(t.index);switch(t.delta.type){case"text_delta":{i?.type==="text"&&(s.content[t.index]={...i,text:(i.text||"")+t.delta.text});break}case"citations_delta":{i?.type==="text"&&(s.content[t.index]={...i,citations:[...i.citations??[],t.delta.citation]});break}case"input_json_delta":{if(i&&lr(i)){const a=(i[ct]||"")+t.delta.partial_json;s.content[t.index]=Wc(i,a)}break}case"thinking_delta":{i?.type==="thinking"&&(s.content[t.index]={...i,thinking:i.thinking+t.delta.thinking});break}case"signature_delta":{i?.type==="thinking"&&(s.content[t.index]={...i,signature:t.delta.signature});break}case"compaction_delta":{if(i?.type==="compaction"){const a={...i,content:t.delta.content};"encrypted_content"in t.delta&&(a.encrypted_content=t.delta.encrypted_content),s.content[t.index]=a}break}default:t.delta}return s}case"content_block_stop":{const i=s.content.at(t.index);if(i&&lr(i)&&ct in i){let a;try{a=i.input}catch(c){a={},o(this,Tt,"f").call(this,o(this,q,"m",cr).call(this,i,c))}Object.defineProperty(i,"input",{value:a,enumerable:!0,configurable:!0,writable:!0})}return s}}},cr=function(t,s){const i=t[ct];return new S(`Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${s}. JSON: ${i}`)},Symbol.asyncIterator)](){const e=[],t=[];let s=!1;return this.on("streamEvent",i=>{const a=t.shift();a?a.resolve(i):e.push(i)}),this.on("end",()=>{s=!0;for(const i of t)i.resolve(void 0);t.length=0}),this.on("abort",i=>{s=!0;for(const a of t)a.reject(i);t.length=0}),this.on("error",i=>{s=!0;for(const a of t)a.reject(i);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:s?{value:void 0,done:!0}:new Promise((a,c)=>t.push({resolve:a,reject:c})).then(a=>a?{value:a,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new dt(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}}return n})();let yi=class extends v{retrieve(r,e){return this._client.get(h`/v1/organizations/api_keys/${r}?beta=true`,e)}update(r,e,t){return this._client.post(h`/v1/organizations/api_keys/${r}?beta=true`,{body:e,...t})}list(r={},e){return this._client.getAPIList("/v1/organizations/api_keys?beta=true",X,{query:r,...e})}};class bi extends v{list(r,e){return this._client.getAPIList("/v1/organizations/analytics/artifacts?beta=true",A,{query:r,...e})}}class vi extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/analytics/connectors?beta=true",A,{query:r,...e})}}class ki extends v{list(r,e){return this._client.getAPIList("/v1/organizations/analytics/cost_report?beta=true",A,{query:r,...e})}}let Si=class extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/analytics/plugins?beta=true",A,{query:r,...e})}},xi=class extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/analytics/skills?beta=true",A,{query:r,...e})}};class Ri extends v{list(r,e){return this._client.getAPIList("/v1/organizations/analytics/summaries?beta=true",A,{query:r,...e})}}class Ai extends v{list(r,e){return this._client.getAPIList("/v1/organizations/analytics/usage_report?beta=true",A,{query:r,...e})}}class Ei extends v{list(r,e){return this._client.getAPIList("/v1/organizations/analytics/user_cost_report?beta=true",A,{query:r,...e})}}class Ti extends v{list(r,e){return this._client.getAPIList("/v1/organizations/analytics/user_usage_report?beta=true",A,{query:r,...e})}}let $i=class extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/analytics/users?beta=true",A,{query:r,...e})}};class Ii extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/analytics/apps/chat/projects?beta=true",A,{query:r,...e})}}var Pi=(()=>{class n extends v{constructor(){super(...arguments),this.projects=new Ii(this._client)}}return n.Projects=Ii,n})(),Mi=(()=>{class n extends v{constructor(){super(...arguments),this.chat=new Pi(this._client)}}return n.Chat=Pi,n})(),Oi=(()=>{class n extends v{constructor(){super(...arguments),this.summaries=new Ri(this._client),this.users=new $i(this._client),this.apps=new Mi(this._client),this.connectors=new vi(this._client),this.plugins=new Si(this._client),this.skills=new xi(this._client),this.artifacts=new bi(this._client),this.usageReport=new Ai(this._client),this.userUsageReport=new Ti(this._client),this.costReport=new ki(this._client),this.userCostReport=new Ei(this._client)}}return n.Summaries=Ri,n.Users=$i,n.Apps=Mi,n.Connectors=vi,n.Plugins=Si,n.Skills=xi,n.Artifacts=bi,n.UsageReport=Ai,n.UserUsageReport=Ti,n.CostReport=ki,n.UserCostReport=Ei,n})();let Ci=class extends v{retrieve(r){return this._client.get("/v1/organizations/compliance_settings?beta=true",r)}update(r,e){return this._client.post("/v1/organizations/compliance_settings?beta=true",{body:r,...e})}},Li=class extends v{create(r,e){return this._client.post("/v1/organizations/external_keys?beta=true",{body:r,...e})}retrieve(r,e){return this._client.get(h`/v1/organizations/external_keys/${r}?beta=true`,e)}update(r,e,t){return this._client.post(h`/v1/organizations/external_keys/${r}?beta=true`,{body:e,...t})}list(r={},e){return this._client.getAPIList("/v1/organizations/external_keys?beta=true",A,{query:r,...e})}delete(r,e){return this._client.delete(h`/v1/organizations/external_keys/${r}?beta=true`,e)}validate(r,e){return this._client.post(h`/v1/organizations/external_keys/${r}/validate?beta=true`,e)}},Ni=class extends v{create(r,e){const{betas:t,...s}=r;return this._client.post("/v1/organizations/federation_issuers?beta=true",{body:s,...e,headers:f([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0},e?.headers])})}retrieve(r,e={},t){const{betas:s}=e??{};return this._client.get(h`/v1/organizations/federation_issuers/${r}?beta=true`,{...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}update(r,e,t){const{betas:s,...i}=e;return this._client.post(h`/v1/organizations/federation_issuers/${r}?beta=true`,{body:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}list(r={},e){const{betas:t,...s}=r??{};return this._client.getAPIList("/v1/organizations/federation_issuers?beta=true",A,{query:s,...e,headers:f([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0},e?.headers])})}archive(r,e={},t){const{betas:s}=e??{};return this._client.post(h`/v1/organizations/federation_issuers/${r}/archive?beta=true`,{...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}},Bi=class extends v{list(r,e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList(h`/v1/organizations/federation_rules/${r}/workspaces?beta=true`,A,{query:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}add(r,e,t){const{betas:s,...i}=e;return this._client.post(h`/v1/organizations/federation_rules/${r}/workspaces?beta=true`,{body:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}remove(r,e,t){const{federation_rule_id:s,betas:i}=e;return this._client.delete(h`/v1/organizations/federation_rules/${s}/workspaces/${r}?beta=true`,{...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}};var Di=(()=>{class n extends v{constructor(){super(...arguments),this.workspaces=new Bi(this._client)}create(e,t){const{betas:s,...i}=e;return this._client.post("/v1/organizations/federation_rules?beta=true",{body:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i}=t??{};return this._client.get(h`/v1/organizations/federation_rules/${e}?beta=true`,{...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},s?.headers])})}update(e,t,s){const{betas:i,...a}=t;return this._client.post(h`/v1/organizations/federation_rules/${e}?beta=true`,{body:a,...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},s?.headers])})}list(e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList("/v1/organizations/federation_rules?beta=true",A,{query:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}archive(e,t={},s){const{betas:i}=t??{};return this._client.post(h`/v1/organizations/federation_rules/${e}/archive?beta=true`,{...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},s?.headers])})}}return n.Workspaces=Bi,n})(),Ui=(()=>{class n extends v{constructor(){super(...arguments),this.issuers=new Ni(this._client),this.rules=new Di(this._client)}}return n.Issuers=Ni,n.Rules=Di,n})();let Hi=class extends v{create(r,e){return this._client.post("/v1/organizations/invites?beta=true",{body:r,...e})}retrieve(r,e){return this._client.get(h`/v1/organizations/invites/${r}?beta=true`,e)}list(r={},e){return this._client.getAPIList("/v1/organizations/invites?beta=true",X,{query:r,...e})}delete(r,e){return this._client.delete(h`/v1/organizations/invites/${r}?beta=true`,e)}};class Wi extends v{retrieve(r,e={},t){const{betas:s,...i}=e??{};return this._client.get(h`/v1/organizations/plugin_marketplaces/${r}?beta=true`,{query:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}update(r,e,t){const{betas:s,...i}=e;return this._client.post(h`/v1/organizations/plugin_marketplaces/${r}?beta=true`,{body:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}list(r={},e){const{betas:t,...s}=r??{};return this._client.getAPIList("/v1/organizations/plugin_marketplaces?beta=true",A,{query:s,...e,headers:f([{"anthropic-beta":[...t??[],"ce-plugins-2026-09-01"].toString()},e?.headers])})}validateArchive(r,e){const{betas:t,...s}=r;return this._client.post("/v1/organizations/plugin_marketplaces/validate_archive?beta=true",me({body:s,...e,headers:f([{"anthropic-beta":[...t??[],"ce-plugins-2026-09-01"].toString()},e?.headers])},this._client))}validateRepository(r,e){const{betas:t,...s}=r;return this._client.post("/v1/organizations/plugin_marketplaces/validate_repository?beta=true",{body:s,...e,headers:f([{"anthropic-beta":[...t??[],"ce-plugins-2026-09-01"].toString()},e?.headers])})}}let zi=class extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/rate_limits?beta=true",A,{query:r,...e})}},ji=class extends v{retrieve(r,e){return this._client.get(h`/v1/organizations/users/${r}?beta=true`,e)}update(r,e,t){return this._client.post(h`/v1/organizations/users/${r}?beta=true`,{body:e,...t})}list(r={},e){return this._client.getAPIList("/v1/organizations/users?beta=true",X,{query:r,...e})}remove(r,e){return this._client.delete(h`/v1/organizations/users/${r}?beta=true`,e)}};class Fi extends v{list(r,e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList(h`/v1/organizations/plugins/${r}/installation_settings?beta=true`,A,{query:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}remove(r,e,t){const{plugin_id:s,betas:i}=e;return this._client.delete(h`/v1/organizations/plugins/${s}/installation_settings/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}set(r,e,t){const{plugin_id:s,betas:i,...a}=e;return this._client.post(h`/v1/organizations/plugins/${s}/installation_settings/${r}?beta=true`,{body:a,...t,headers:f([{"anthropic-beta":[...i??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}}class qi extends v{list(r,e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList(h`/v1/organizations/plugins/${r}/shares?beta=true`,A,{query:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}}let Ki=class extends v{create(r,e,t){const{betas:s,...i}=e;return this._client.post(h`/v1/organizations/plugins/${r}/versions?beta=true`,me({body:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])},this._client))}retrieve(r,e,t){const{plugin_id:s,betas:i,...a}=e;return this._client.get(h`/v1/organizations/plugins/${s}/versions/${r}?beta=true`,{query:a,...t,headers:f([{"anthropic-beta":[...i??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}list(r,e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList(h`/v1/organizations/plugins/${r}/versions?beta=true`,A,{query:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}download(r,e,t){const{plugin_id:s,betas:i,...a}=e;return this._client.get(h`/v1/organizations/plugins/${s}/versions/${r}/content?beta=true`,{query:a,...t,headers:f([{"anthropic-beta":[...i??[],"ce-plugins-2026-09-01"].toString(),Accept:"application/binary"},t?.headers]),__binaryResponse:!0})}};var Vi=(()=>{class n extends v{constructor(){super(...arguments),this.versions=new Ki(this._client),this.installationSettings=new Fi(this._client),this.shares=new qi(this._client)}create(e,t){const{betas:s,...i}=e;return this._client.post("/v1/organizations/plugins?beta=true",me({body:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])},this._client))}retrieve(e,t={},s){const{betas:i,...a}=t??{};return this._client.get(h`/v1/organizations/plugins/${e}?beta=true`,{query:a,...s,headers:f([{"anthropic-beta":[...i??[],"ce-plugins-2026-09-01"].toString()},s?.headers])})}update(e,t,s){const{betas:i,...a}=t;return this._client.post(h`/v1/organizations/plugins/${e}?beta=true`,{body:a,...s,headers:f([{"anthropic-beta":[...i??[],"ce-plugins-2026-09-01"].toString()},s?.headers])})}list(e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList("/v1/organizations/plugins?beta=true",A,{query:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}delete(e,t={},s){const{betas:i}=t??{};return this._client.delete(h`/v1/organizations/plugins/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"ce-plugins-2026-09-01"].toString()},s?.headers])})}}return n.Versions=Ki,n.InstallationSettings=Fi,n.Shares=qi,n})();let Ji=class extends v{list(r,e={},t){return this._client.getAPIList(h`/v1/organizations/rbac_groups/${r}/members?beta=true`,A,{query:e,...t})}add(r,e,t){return this._client.post(h`/v1/organizations/rbac_groups/${r}/members?beta=true`,{body:e,...t})}remove(r,e,t){const{rbac_group_id:s}=e;return this._client.delete(h`/v1/organizations/rbac_groups/${s}/members/${r}?beta=true`,t)}};var Xi=(()=>{class n extends v{constructor(){super(...arguments),this.members=new Ji(this._client)}create(e,t){return this._client.post("/v1/organizations/rbac_groups?beta=true",{body:e,...t})}retrieve(e,t){return this._client.get(h`/v1/organizations/rbac_groups/${e}?beta=true`,t)}update(e,t,s){return this._client.post(h`/v1/organizations/rbac_groups/${e}?beta=true`,{body:t,...s})}list(e={},t){return this._client.getAPIList("/v1/organizations/rbac_groups?beta=true",A,{query:e,...t})}delete(e,t){return this._client.delete(h`/v1/organizations/rbac_groups/${e}?beta=true`,t)}}return n.Members=Ji,n})();class Gi extends v{list(r,e={},t){return this._client.getAPIList(h`/v1/organizations/rbac_roles/${r}/permissions?beta=true`,A,{query:e,...t})}}var Qi=(()=>{class n extends v{constructor(){super(...arguments),this.permissions=new Gi(this._client)}retrieve(e,t){return this._client.get(h`/v1/organizations/rbac_roles/${e}?beta=true`,t)}list(e={},t){return this._client.getAPIList("/v1/organizations/rbac_roles?beta=true",A,{query:e,...t})}}return n.Permissions=Gi,n})();let Yi=class extends v{list(r,e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList(h`/v1/organizations/service_accounts/${r}/workspaces?beta=true`,A,{query:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}add(r,e,t){const{betas:s,...i}=e;return this._client.post(h`/v1/organizations/service_accounts/${r}/workspaces?beta=true`,{body:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}remove(r,e,t){const{service_account_id:s,betas:i}=e;return this._client.delete(h`/v1/organizations/service_accounts/${s}/workspaces/${r}?beta=true`,{...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}};var Zi=(()=>{class n extends v{constructor(){super(...arguments),this.workspaces=new Yi(this._client)}create(e,t){const{betas:s,...i}=e;return this._client.post("/v1/organizations/service_accounts?beta=true",{body:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i}=t??{};return this._client.get(h`/v1/organizations/service_accounts/${e}?beta=true`,{...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},s?.headers])})}update(e,t,s){const{betas:i,...a}=t;return this._client.post(h`/v1/organizations/service_accounts/${e}?beta=true`,{body:a,...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},s?.headers])})}list(e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList("/v1/organizations/service_accounts?beta=true",A,{query:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}archive(e,t={},s){const{betas:i}=t??{};return this._client.post(h`/v1/organizations/service_accounts/${e}/archive?beta=true`,{...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},s?.headers])})}}return n.Workspaces=Yi,n})();class ea extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/spend_limits/effective?beta=true",A,{query:r,...e})}}class ta extends v{retrieve(r,e){return this._client.get(h`/v1/organizations/spend_limit_increase_requests/${r}?beta=true`,e)}list(r={},e){return this._client.getAPIList("/v1/organizations/spend_limit_increase_requests?beta=true",A,{query:r,...e})}approve(r,e,t){return this._client.post(h`/v1/organizations/spend_limit_increase_requests/${r}/approve?beta=true`,{body:e,...t})}deny(r,e,t){return this._client.post(h`/v1/organizations/spend_limit_increase_requests/${r}/deny?beta=true`,{body:e,...t})}}var na=(()=>{class n extends v{constructor(){super(...arguments),this.effective=new ea(this._client),this.increaseRequests=new ta(this._client)}retrieve(e,t){return this._client.get(h`/v1/organizations/spend_limits/${e}?beta=true`,t)}list(e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList("/v1/organizations/spend_limits?beta=true",A,{query:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}delete(e,t){return this._client.delete(h`/v1/organizations/spend_limits/${e}?beta=true`,t)}set(e,t){return this._client.post("/v1/organizations/spend_limits?beta=true",{body:e,...t})}}return n.Effective=ea,n.IncreaseRequests=ta,n})();let ra=class extends v{retrieve(r,e,t){const{workspace_id:s}=e;return this._client.get(h`/v1/organizations/workspaces/${s}/members/${r}?beta=true`,t)}update(r,e,t){const{workspace_id:s,...i}=e;return this._client.post(h`/v1/organizations/workspaces/${s}/members/${r}?beta=true`,{body:i,...t})}list(r,e={},t){return this._client.getAPIList(h`/v1/organizations/workspaces/${r}/members?beta=true`,X,{query:e,...t})}add(r,e,t){return this._client.post(h`/v1/organizations/workspaces/${r}/members?beta=true`,{body:e,...t})}remove(r,e,t){const{workspace_id:s}=e;return this._client.delete(h`/v1/organizations/workspaces/${s}/members/${r}?beta=true`,t)}},sa=class extends v{list(r,e={},t){return this._client.getAPIList(h`/v1/organizations/workspaces/${r}/rate_limits?beta=true`,A,{query:e,...t})}},ia=class extends v{retrieve(r,e,t){const{workspace_id:s,betas:i}=e;return this._client.get(h`/v1/organizations/workspaces/${s}/service_accounts/${r}?beta=true`,{...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}update(r,e,t){const{workspace_id:s,betas:i,...a}=e;return this._client.post(h`/v1/organizations/workspaces/${s}/service_accounts/${r}?beta=true`,{body:a,...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}list(r,e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList(h`/v1/organizations/workspaces/${r}/service_accounts?beta=true`,A,{query:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}add(r,e,t){const{betas:s,...i}=e;return this._client.post(h`/v1/organizations/workspaces/${r}/service_accounts?beta=true`,{body:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}remove(r,e,t){const{workspace_id:s,betas:i}=e;return this._client.delete(h`/v1/organizations/workspaces/${s}/service_accounts/${r}?beta=true`,{...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}};var aa=(()=>{class n extends v{constructor(){super(...arguments),this.rateLimits=new sa(this._client),this.members=new ra(this._client),this.serviceAccounts=new ia(this._client)}create(e,t){const{betas:s,...i}=e;return this._client.post("/v1/organizations/workspaces?beta=true",{body:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}retrieve(e,t){return this._client.get(h`/v1/organizations/workspaces/${e}?beta=true`,t)}update(e,t,s){return this._client.post(h`/v1/organizations/workspaces/${e}?beta=true`,{body:t,...s})}list(e={},t){return this._client.getAPIList("/v1/organizations/workspaces?beta=true",X,{query:e,...t})}archive(e,t){return this._client.post(h`/v1/organizations/workspaces/${e}/archive?beta=true`,t)}}return n.RateLimits=sa,n.Members=ra,n.ServiceAccounts=ia,n})(),oa=(()=>{class n extends v{constructor(){super(...arguments),this.apiKeys=new yi(this._client),this.externalKeys=new Li(this._client),this.federation=new Ui(this._client),this.invites=new Hi(this._client),this.serviceAccounts=new Zi(this._client),this.users=new ji(this._client),this.workspaces=new aa(this._client),this.rateLimits=new zi(this._client),this.complianceSettings=new Ci(this._client),this.analytics=new Oi(this._client),this.spendLimits=new na(this._client),this.rbacGroups=new Xi(this._client),this.rbacRoles=new Qi(this._client),this.plugins=new Vi(this._client),this.pluginMarketplaces=new Wi(this._client)}retrieve(e){return this._client.get("/v1/organizations/me?beta=true",e)}}return n.APIKeys=yi,n.ExternalKeys=Li,n.Federation=Ui,n.Invites=Hi,n.ServiceAccounts=Zi,n.Users=ji,n.Workspaces=aa,n.RateLimits=zi,n.ComplianceSettings=Ci,n.Analytics=Oi,n.SpendLimits=na,n.RBACGroups=Xi,n.RBACRoles=Qi,n.Plugins=Vi,n.PluginMarketplaces=Wi,n})(),ca=(()=>{class n extends v{list(e,t={},s){const{betas:i,workspace_id:a,...c}=t??{};return this._client.getAPIList(h`/v1/sessions/${e}/events?beta=true`,A,{query:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}send(e,t,s){const{betas:i,workspace_id:a,...c}=t;return this._client.post(h`/v1/sessions/${e}/events?beta=true`,{body:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}stream(e,t={},s){const{betas:i,workspace_id:a,...c}=t??{};return this._client.get(h`/v1/sessions/${e}/events/stream?beta=true`,{query:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers]),stream:!0})}toolRunner(e,t){return new zr(e,{...t,client:this._client})}}return n.SessionToolRunner=zr,n})();class la extends v{retrieve(r,e,t){const{session_id:s,betas:i,workspace_id:a}=e;return this._client.get(h`/v1/sessions/${s}/resources/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}update(r,e,t){const{session_id:s,betas:i,workspace_id:a,...c}=e;return this._client.post(h`/v1/sessions/${s}/resources/${r}?beta=true`,{body:c,...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}list(r,e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList(h`/v1/sessions/${r}/resources?beta=true`,A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(r,e,t){const{session_id:s,betas:i,workspace_id:a}=e;return this._client.delete(h`/v1/sessions/${s}/resources/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}add(r,e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post(h`/v1/sessions/${r}/resources?beta=true`,{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}}class ua extends v{list(r,e,t){const{session_id:s,betas:i,workspace_id:a,...c}=e;return this._client.getAPIList(h`/v1/sessions/${s}/threads/${r}/events?beta=true`,A,{query:c,...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}stream(r,e,t){const{session_id:s,betas:i,workspace_id:a,...c}=e;return this._client.get(h`/v1/sessions/${s}/threads/${r}/stream?beta=true`,{query:c,...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers]),stream:!0})}}var da=(()=>{class n extends v{constructor(){super(...arguments),this.events=new ua(this._client)}retrieve(e,t,s){const{session_id:i,betas:a,workspace_id:c}=t;return this._client.get(h`/v1/sessions/${i}/threads/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...a??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},s?.headers])})}list(e,t={},s){const{betas:i,workspace_id:a,...c}=t??{};return this._client.getAPIList(h`/v1/sessions/${e}/threads?beta=true`,A,{query:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}archive(e,t,s){const{session_id:i,betas:a,workspace_id:c}=t;return this._client.post(h`/v1/sessions/${i}/threads/${e}/archive?beta=true`,{...s,headers:f([{"anthropic-beta":[...a??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},s?.headers])})}}return n.Events=ua,n})(),ha=(()=>{class n extends v{constructor(){super(...arguments),this.events=new ca(this._client),this.resources=new la(this._client),this.threads=new da(this._client)}create(e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post("/v1/sessions?beta=true",{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.get(h`/v1/sessions/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}update(e,t,s){const{betas:i,workspace_id:a,...c}=t;return this._client.post(h`/v1/sessions/${e}?beta=true`,{body:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}list(e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList("/v1/sessions?beta=true",hu,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.delete(h`/v1/sessions/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}archive(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.post(h`/v1/sessions/${e}/archive?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}}return n.Events=ca,n.Resources=la,n.Threads=da,n})();let fa=class extends v{create(r,e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post(h`/v1/skills/${r}/versions?beta=true`,me({body:a,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])},this._client,!1))}retrieve(r,e,t){const{skill_id:s,betas:i,workspace_id:a}=e;return this._client.get(h`/v1/skills/${s}/versions/${r}?beta=true`,{...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}list(r,e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList(h`/v1/skills/${r}/versions?beta=true`,A,{query:a,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(r,e,t){const{skill_id:s,betas:i,workspace_id:a}=e;return this._client.delete(h`/v1/skills/${s}/versions/${r}?beta=true`,{...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}download(r,e,t){const{skill_id:s,betas:i,workspace_id:a}=e;return this._client.get(h`/v1/skills/${s}/versions/${r}/content?beta=true`,{...t,headers:f([{Accept:"application/binary",...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers]),__binaryResponse:!0})}};var pa=(()=>{class n extends v{constructor(){super(...arguments),this.versions=new fa(this._client)}create(e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post("/v1/skills?beta=true",me({body:a,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])},this._client,!1))}retrieve(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.get(h`/v1/skills/${e}?beta=true`,{...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}list(e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList("/v1/skills?beta=true",A,{query:a,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.delete(h`/v1/skills/${e}?beta=true`,{...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}}return n.Versions=fa,n})();class _a extends v{create(r,e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post(h`/v1/tunnels/${r}/certificates?beta=true`,{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"mcp-tunnels-2026-06-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(r,e,t){const{tunnel_id:s,betas:i,workspace_id:a}=e;return this._client.get(h`/v1/tunnels/${s}/certificates/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}list(r,e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList(h`/v1/tunnels/${r}/certificates?beta=true`,A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"mcp-tunnels-2026-06-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}archive(r,e,t){const{tunnel_id:s,betas:i,workspace_id:a}=e;return this._client.post(h`/v1/tunnels/${s}/certificates/${r}/archive?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}}var ga=(()=>{class n extends v{constructor(){super(...arguments),this.certificates=new _a(this._client)}create(e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post("/v1/tunnels?beta=true",{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"mcp-tunnels-2026-06-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.get(h`/v1/tunnels/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}list(e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList("/v1/tunnels?beta=true",A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"mcp-tunnels-2026-06-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}archive(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.post(h`/v1/tunnels/${e}/archive?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}revealToken(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.post(h`/v1/tunnels/${e}/reveal_token?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}rotateToken(e,t,s){const{betas:i,workspace_id:a,...c}=t;return this._client.post(h`/v1/tunnels/${e}/rotate_token?beta=true`,{body:c,...s,headers:f([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}}return n.Certificates=_a,n})();class ma extends v{create(r,e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post(h`/v1/vaults/${r}/credentials?beta=true`,{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(r,e,t){const{vault_id:s,betas:i,workspace_id:a}=e;return this._client.get(h`/v1/vaults/${s}/credentials/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}update(r,e,t){const{vault_id:s,betas:i,workspace_id:a,...c}=e;return this._client.post(h`/v1/vaults/${s}/credentials/${r}?beta=true`,{body:c,...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}list(r,e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList(h`/v1/vaults/${r}/credentials?beta=true`,A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(r,e,t){const{vault_id:s,betas:i,workspace_id:a}=e;return this._client.delete(h`/v1/vaults/${s}/credentials/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}archive(r,e,t){const{vault_id:s,betas:i,workspace_id:a}=e;return this._client.post(h`/v1/vaults/${s}/credentials/${r}/archive?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}mcpOAuthValidate(r,e,t){const{vault_id:s,betas:i,workspace_id:a}=e;return this._client.post(h`/v1/vaults/${s}/credentials/${r}/mcp_oauth_validate?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}}var wa=(()=>{class n extends v{constructor(){super(...arguments),this.credentials=new ma(this._client)}create(e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post("/v1/vaults?beta=true",{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.get(h`/v1/vaults/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}update(e,t,s){const{betas:i,workspace_id:a,...c}=t;return this._client.post(h`/v1/vaults/${e}?beta=true`,{body:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}list(e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList("/v1/vaults?beta=true",A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.delete(h`/v1/vaults/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}archive(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.post(h`/v1/vaults/${e}/archive?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}}return n.Credentials=ma,n})(),_e,kn,Pe,Ye,Sn,Me,Ze,xn,ya,Rn,An,ba=(()=>{class n extends zc{constructor(e,t){super(e),_e.add(this),kn.set(this,void 0),Pe.set(this,0),Ye.set(this,[]),Sn.set(this,[]),Me.set(this,void 0),Ze.set(this,[]),xn.set(this,!1),w(this,kn,t)}get toolCalls(){return o(this,Sn,"f")}static start(e,t,s,i){const a=new n({...t,stream:!0},i);for(const c of t.messages)a._addMessageParam(c);return a._run(()=>a._createMessage(e,{...t,stream:!0},{...s,headers:{...s?.headers,[os]:"stream"}})),a}_emit(e,...t){var s;if(e!=="streamEvent"||this.ended){super._emit(e,...t);return}w(this,Pe,(s=o(this,Pe,"f"),s++,s));const[i,a]=t,c=i.type==="content_block_stop"?a.content[i.index]:void 0,u=c?.type==="tool_use"?c:void 0;u&&o(this,Sn,"f").push(u),super._emit(e,...t),o(this,_e,"m",ya).call(this,i,u),o(this,_e,"m",Rn).call(this)}[(kn=new WeakMap,Pe=new WeakMap,Ye=new WeakMap,Sn=new WeakMap,Me=new WeakMap,Ze=new WeakMap,xn=new WeakMap,_e=new WeakSet,Symbol.asyncIterator)](){const e=super[Symbol.asyncIterator](),t={handled:o(this,Pe,"f")};o(this,Ye,"f").push(t);let s=!1;return{next:async()=>{s&&(s=!1,t.handled++,o(this,_e,"m",Rn).call(this));try{const i=await e.next();return s=!i.done,i.done&&o(this,_e,"m",An).call(this,t),i}catch(i){throw o(this,_e,"m",An).call(this,t),i}},return:async()=>{const i=e.return?.();return o(this,_e,"m",An).call(this,t),await i??{value:void 0,done:!0}}}}}return ya=function(e,t){if(o(this,xn,"f"))return;if(e.type==="content_block_start"&&e.content_block.type==="fallback"){w(this,xn,!0),w(this,Me,void 0);return}const s=e.type==="content_block_start"||e.type==="message_delta"&&e.delta.stop_reason==="tool_use";o(this,Me,"f")&&s&&(o(this,Ze,"f").push({toolUse:o(this,Me,"f"),event:o(this,Pe,"f")}),w(this,Me,void 0)),t&&w(this,Me,t)},Rn=function(){if(this.errored||this.controller.signal.aborted)return;const e=Math.min(o(this,Pe,"f"),...o(this,Ye,"f").map(t=>t.handled));for(;o(this,Ze,"f")[0]&&o(this,Ze,"f")[0].event<=e;)o(this,kn,"f").call(this,o(this,Ze,"f").shift().toolUse)},An=function(e){const t=o(this,Ye,"f").indexOf(e);t>=0&&(o(this,Ye,"f").splice(t,1),o(this,_e,"m",Rn).call(this))},n})();function va(){let n,r;return{promise:new Promise((t,s)=>{n=t,r=s}),resolve:n,reject:r}}var D,et,Oe,N,K,V,Se,de,xe,$t,ee,he,tt,nt,Ce,ur,ka,dr,hr,It,En,Sa,fr,pr,xa,_r,Ra=(()=>{class n{constructor(e,t,s){D.add(this),this.client=e,et.set(this,!1),Oe.set(this,!1),N.set(this,void 0),K.set(this,void 0),V.set(this,void 0),Se.set(this,void 0),de.set(this,void 0),xe.set(this,void 0),$t.set(this,0),ee.set(this,{status:"idle"}),he.set(this,void 0),tt.set(this,null),nt.set(this,new Map),Ce.set(this,[]),Aa(t),hd(t),Ea(t),w(this,N,{params:{...t,messages:JSON.parse(JSON.stringify(Ta(t.messages)))}});const i=Ic(t.tools,t.messages);w(this,K,{...s,headers:f([$c("BetaToolRunner"),i.length?{[Xt]:i.join(", ")}:void 0,s?.headers])}),w(this,xe,va())}async*[(et=new WeakMap,Oe=new WeakMap,N=new WeakMap,K=new WeakMap,V=new WeakMap,Se=new WeakMap,de=new WeakMap,xe=new WeakMap,$t=new WeakMap,ee=new WeakMap,he=new WeakMap,tt=new WeakMap,nt=new WeakMap,Ce=new WeakMap,D=new WeakSet,Symbol.asyncIterator)](){var e;if(o(this,et,"f"))throw new S("Cannot iterate over a consumed stream");w(this,et,!0),w(this,Oe,!0),w(this,de,void 0);try{for(;;)try{if(o(this,N,"f").params.max_iterations&&o(this,$t,"f")>=o(this,N,"f").params.max_iterations)break;if(o(this,D,"m",xa).call(this),o(this,ee,"f").status==="scheduled"&&Ia(o(this,tt,"f"))!=="resume"){yield*o(this,D,"m",hr).call(this,o(this,ee,"f").config);continue}w(this,Oe,!1,"f"),w(this,de,void 0,"f"),w(this,$t,(e=o(this,$t,"f"),e++,e),"f"),w(this,V,void 0,"f");const{max_iterations:t,runToolsEagerly:s,...i}=o(this,N,"f").params;if(yield*o(this,D,"m",ur).call(this,i),o(this,Oe,"f"))w(this,tt,null,"f");else{const c=await o(this,V,"f"),u=Ia(c.stop_reason);w(this,tt,c.stop_reason,"f"),o(this,N,"f").params.messages.push({role:c.role,content:c.content});const{container:l}=o(this,N,"f").params;if(c.container&&(l==null?o(this,N,"f").params.container=c.container.id:typeof l=="object"&&l.id==null&&(o(this,N,"f").params.container={...l,id:c.container.id})),u==="stop"){yield*o(this,D,"m",fr).call(this);break}if(u==="resume")continue}const a=await o(this,D,"m",pr).call(this,o(this,N,"f").params.messages.at(-1));if(a)o(this,N,"f").params.messages.push(a);else if(!o(this,Oe,"f")){yield*o(this,D,"m",fr).call(this);break}}finally{o(this,Se,"f")?.abort(),w(this,Se,void 0,"f")}if(await o(this,D,"m",dr).call(this),!o(this,V,"f"))throw new S("ToolRunner concluded without a message from the server");o(this,xe,"f").resolve(await o(this,V,"f"))}catch(t){throw w(this,et,!1),o(this,xe,"f").promise.catch(()=>{}),o(this,xe,"f").reject(t),w(this,xe,va()),t}}setMessagesParams(e){const t=typeof e=="function"?e(o(this,N,"f").params):e;if(Aa(t),Ea(t),o(this,ee,"f").status!=="idle"&&gr(t),o(this,ee,"f").status==="in_flight"&&t.messages!==o(this,N,"f").params.messages)throw new S("Message params can't be changed while the conversation is being compacted, because the compaction response is about to replace them. Change them after this iteration instead.");o(this,N,"f").params=t,w(this,Oe,!0),w(this,de,void 0)}setRequestOptions(e){typeof e=="function"?w(this,K,e(o(this,K,"f"))):w(this,K,{...o(this,K,"f"),...e})}async generateToolResponse(e=o(this,K,"f").signal){const t=await o(this,V,"f")??this.params.messages.at(-1);return t?o(this,D,"m",pr).call(this,t,e):null}deferToolCall(e){const t=typeof e=="string"?e:e.id;o(this,he,"f")&&!o(this,he,"f").has(t)&&o(this,he,"f").set(t,{status:"held"})}get deferredToolCalls(){const e=o(this,Se,"f"),t=o(this,he,"f");return!(e instanceof ba)||!t?[]:e.toolCalls.filter(s=>t.get(s.id)?.status==="held")}done(){return o(this,xe,"f").promise}async runUntilDone(){if(!o(this,et,"f"))for await(const e of this);return this.done()}get params(){return o(this,N,"f").params}pushMessages(...e){this.setMessagesParams(t=>({...t,messages:[...t.messages,...e]}))}compactBeforeNextTurn(e){o(this,ee,"f").status!=="in_flight"&&(gr(o(this,N,"f").params),w(this,ee,{status:"scheduled",config:e??{type:"summarize"}}))}addTools(...e){for(const t of e)"name"in t&&o(this,nt,"f").set(t.name,"run"in t?t:null),o(this,Ce,"f").push({type:"addition",tool:t})}removeTools(...e){for(const t of e){const s=typeof t=="string"?t:t.name;o(this,nt,"f").set(s,null),o(this,Ce,"f").push({type:"removal",name:s})}}then(e,t){return this.runUntilDone().then(e,t)}}return ur=async function*(e){await o(this,D,"m",dr).call(this),w(this,he,void 0),e={...e,...e.tools&&{tools:e.tools.map(jr)},messages:Ta(e.messages)},e.stream?(w(this,Se,o(this,N,"f").params.runToolsEagerly?o(this,D,"m",ka).call(this,e):this.client.beta.messages.stream({...e},o(this,K,"f"))),w(this,V,o(this,Se,"f").finalMessage()),o(this,V,"f").catch(()=>{}),yield o(this,Se,"f")):(w(this,V,this.client.beta.messages.create({...e,stream:!1},o(this,K,"f"))),yield o(this,V,"f"))},ka=function(e){const t=new Map;return w(this,he,t),ba.start(this.client.beta.messages,e,o(this,K,"f"),s=>{if(t.has(s.id))return;const i=jc(o(this,D,"m",It).call(this),o(this,D,"m",En).call(this),s,o(this,K,"f"));i.catch(()=>{}),t.set(s.id,{status:"started",result:i})})},dr=async function(){const e=[...o(this,he,"f")?.values()??[]].filter(t=>t.status==="started");await Promise.allSettled(e.map(t=>t.result))},hr=async function*(e){gr(o(this,N,"f").params);const{max_iterations:t,runToolsEagerly:s,...i}=o(this,N,"f").params,a=fd(i);w(this,ee,{status:"in_flight"}),w(this,de,void 0);const c=o(this,V,"f");try{yield*o(this,D,"m",ur).call(this,{...a,compaction:e});const u=await o(this,V,"f");u.content.some(l=>l.type==="compaction"&&l.content)?(o(this,D,"m",Sa).call(this),o(this,N,"f").params.messages=[{role:u.role,content:u.content}]):(O(this.client).warn("Compaction produced no summary; keeping the conversation as it is."),w(this,V,c,"f"))}finally{w(this,ee,{status:"idle"})}},It=function(){const e=new Map;for(const t of o(this,N,"f").params.tools)"run"in t&&e.set(t.name,t);for(const[t,s]of o(this,nt,"f"))s?e.set(t,s):e.delete(t);return e},En=function(){const e=new Set(o(this,D,"m",It).call(this).keys());for(const t of[...o(this,N,"f").params.messages,o(this,D,"m",_r).call(this)])if(typeof t.content!="string"){for(const s of t.content)if(t.role==="system")$a(s,e);else if(t.role==="assistant"&&s.type==="compaction")for(const i of s.tool_changes??[])$a(i,e)}return e},Sa=function(){const e=o(this,D,"m",En).call(this);for(const t of o(this,D,"m",It).call(this).keys())e.has(t)||o(this,nt,"f").set(t,null)},fr=async function*(){if(o(this,ee,"f").status!=="scheduled")return;const e=o(this,N,"f").params.messages.at(-1)?.content;if(Array.isArray(e)&&e.some(t=>t.type==="tool_use")){O(this.client).warn("The pending compaction was skipped because the last turn ended with tool calls that were not run. Call `compactBeforeNextTurn()` again if you continue the conversation."),w(this,ee,{status:"idle"});return}yield*o(this,D,"m",hr).call(this,o(this,ee,"f").config)},pr=async function(e,t=o(this,K,"f").signal){return o(this,de,"f")!==void 0?o(this,de,"f"):(w(this,de,pd(o(this,D,"m",It).call(this),o(this,D,"m",En).call(this),e,{...o(this,K,"f"),signal:t},o(this,he,"f"))),o(this,de,"f"))},xa=function(){o(this,tt,"f")==="pause_turn"||o(this,Ce,"f").length===0||(o(this,N,"f").params.messages.push(o(this,D,"m",_r).call(this)),w(this,Ce,[]))},_r=function(){const e=[];for(const t of o(this,Ce,"f")){if(t.type==="removal"){e.push({type:"tool_removal",tool:{type:"tool_reference",name:t.name}});continue}const s=jr(t.tool);e.push({type:"tool_addition",tool:{type:"tool_definition",definition:s}})}return{role:"system",content:e}},n})();function Aa(n){if("compaction"in n&&n.compaction!=null)throw new S("`compaction` cannot be set on a tool runner: every request in the loop would compact again. Call `runner.compactBeforeNextTurn()` when the conversation should be compacted instead.")}function hd(n){if("compactionControl"in n&&n.compactionControl!=null)throw new S("`compactionControl` has been removed from the tool runner. Use server-side compaction instead: call `runner.compactBeforeNextTurn()` when the conversation should be compacted.")}function Ea(n){if(n.runToolsEagerly&&!n.stream)throw new TypeError("`runToolsEagerly: true` needs `stream: true` in the tool runner's params, because a reply that isn't streamed arrives whole.")}function gr(n){if(n.context_management?.edits?.some(r=>r.type.startsWith("compact_")))throw new S("`compactBeforeNextTurn()` can't be used while `context_management` has a compaction edit, because the API doesn't accept a compaction block together with one. Remove the edit first.")}function fd(n){const{context_management:r,stop_sequences:e,output_format:t,...s}=n,i=({format:a,...c})=>c;return(s.tool_choice?.type==="any"||s.tool_choice?.type==="tool")&&delete s.tool_choice,s.output_config&&(s.output_config=i(s.output_config)),Array.isArray(s.fallbacks)&&(s.fallbacks=s.fallbacks.map(a=>a.output_config?{...a,output_config:i(a.output_config)}:a)),s}function jr(n){if(!("run"in n))return n;const r=yd;return{...Object.fromEntries(Object.entries(n).filter(([e])=>r.includes(e))),...it(n)&&{[Ee]:n[Ee]}}}function Ta(n){return n.map(r=>{if(r.role!=="system"||typeof r.content=="string")return r;const e=r.content.map(t=>t.type==="tool_addition"&&t.tool.type==="tool_definition"?{...t,tool:{...t.tool,definition:jr(t.tool.definition)}}:t);return{...r,content:e}})}async function pd(n,r,e,t,s){if(!e||e.role!=="assistant"||!e.content||typeof e.content=="string")return null;const i=e.content.filter(c=>c.type==="tool_use");return i.length===0?null:{role:"user",content:await Promise.all(i.map(c=>{const u=s?.get(c.id);if(u?.status==="started")return u.result;const l=jc(n,r,c,t);return s?.set(c.id,{status:"started",result:l}),l}))}}async function jc(n,r,e,t){const s=r.has(e.name)?n.get(e.name):void 0;if(!s)return _d(e);try{let i=e.input;"parse"in s&&s.parse&&(i=s.parse(i));const a=await s.run(i,{toolUse:e,toolUseBlock:e,signal:t?.signal});return{type:"tool_result",tool_use_id:e.id,content:a}}catch(i){return{type:"tool_result",tool_use_id:e.id,content:i instanceof cs?i.content:`Error: ${i instanceof Error?i.message:String(i)}`,is_error:!0}}}function _d(n){return{type:"tool_result",tool_use_id:n.id,content:`Error: Tool '${n.name}' not found`,is_error:!0}}function $a(n,r){switch(n.type){case"tool_removal":case"tool_addition":gd(n,r);break}}function gd(n,r){const e=md(n.tool);e!==void 0&&(n.type==="tool_removal"?r.delete(e):r.add(e))}function md(n){switch(n.type){case"tool_reference":return n.name;case"tool_definition":return"name"in n.definition?n.definition.name:void 0;default:return}}function Ia(n){if(n===null)return"stop";switch(n){case"tool_use":return"run_tools";case"pause_turn":case"compaction":return"resume";case"end_turn":case"stop_sequence":case"max_tokens":case"model_context_window_exceeded":case"refusal":return"stop";default:return"stop"}}const Pa={"claude-sonnet-4-5":"November 30th, 2026","claude-sonnet-4-5-20250929":"November 30th, 2026"},wd=["claude-mythos-preview","claude-opus-4-6"];var Ma=(()=>{class n extends v{constructor(){super(...arguments),this.batches=new _i(this._client)}create(e,t){const s=Oa(e),{betas:i,user_profile_id:a,workspace_id:c,...u}=s;u.model in Pa&&console.warn(`The model '${u.model}' is deprecated and will reach end-of-life on ${Pa[u.model]}
|
|
10
|
+
${d}`)}return a},h=ku(Tc);class Ds extends v{retrieve(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/deployment_runs/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/deployment_runs?beta=true",A,{query:i,...e,headers:f([{"anthropic-beta":[...t??[],"managed-agents-2026-04-01"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}}class Us extends v{create(r,e){const{betas:t,workspace_id:s,...i}=r;return this._client.post("/v1/deployments?beta=true",{body:i,...e,headers:f([{"anthropic-beta":[...t??[],"managed-agents-2026-04-01"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}retrieve(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/deployments/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}update(r,e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post(h`/v1/deployments/${r}?beta=true`,{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/deployments?beta=true",A,{query:i,...e,headers:f([{"anthropic-beta":[...t??[],"managed-agents-2026-04-01"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}archive(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/deployments/${r}/archive?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}pause(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/deployments/${r}/pause?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}run(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/deployments/${r}/run?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}unpause(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/deployments/${r}/unpause?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}}class Hs extends v{create(r,e){const{betas:t,workspace_id:s,...i}=r;return this._client.post("/v1/dreams?beta=true",{body:i,...e,headers:f([{"anthropic-beta":[...t??[],"dreaming-2026-04-21"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}retrieve(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/dreams/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"dreaming-2026-04-21"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/dreams?beta=true",A,{query:i,...e,headers:f([{"anthropic-beta":[...t??[],"dreaming-2026-04-21"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}archive(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/dreams/${r}/archive?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"dreaming-2026-04-21"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}cancel(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/dreams/${r}/cancel?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"dreaming-2026-04-21"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}}const Xt="x-stainless-helper",os="x-stainless-helper-method";function $c(n){return{[Xt]:n}}const Ee=Symbol("anthropic.sdk.stainlessHelper");function it(n){return typeof n=="object"&&n!==null&&Ee in n}function Ic(n,r){const e=new Set;if(n)for(const t of n)it(t)&&e.add(t[Ee]);if(r)for(const t of r){it(t)&&e.add(t[Ee]);const s=t.content;if(Array.isArray(s))for(const i of s){it(i)&&e.add(i[Ee]);const a=i?.tool?.definition;it(a)&&e.add(a[Ee])}}return Array.from(e)}function Pc(n,r){const e=Ic(n,r);return e.length===0?{}:{[Xt]:e.join(", ")}}function Mc(n){return it(n)?{[Xt]:n[Ee]}:{}}let Ws=class extends v{list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/files?beta=true",A,{query:i,...e,headers:f([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}delete(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.delete(h`/v1/files/${r}?beta=true`,{...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}download(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/files/${r}/content?beta=true`,{...t,headers:f([{Accept:"application/binary",...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers]),__binaryResponse:!0})}retrieveMetadata(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/files/${r}?beta=true`,{...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}upload(r,e){const{betas:t,workspace_id:s,...i}=r;return this._client.post("/v1/files?beta=true",me({body:i,...e,headers:f([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...s!=null?{"anthropic-workspace-id":s}:void 0},Mc(i.file),e?.headers])},this._client))}},zs=class extends v{retrieve(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/models/${r}?beta=true`,{...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/models?beta=true",X,{query:i,...e,headers:f([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}};class js extends v{create(r,e){const{betas:t,workspace_id:s,...i}=r;return this._client.post("/v1/user_profiles?beta=true",{body:i,...e,headers:f([{"anthropic-beta":[...t??[],"user-profiles-2026-08-18"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}retrieve(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/user_profiles/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"user-profiles-2026-08-18"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}update(r,e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post(h`/v1/user_profiles/${r}?beta=true`,{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"user-profiles-2026-08-18"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/user_profiles?beta=true",A,{query:i,...e,headers:f([{"anthropic-beta":[...t??[],"user-profiles-2026-08-18"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}createEnrollmentURL(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/user_profiles/${r}/enrollment_url?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"user-profiles-2026-08-18"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}}var Te={},F={},Fs;function Su(){if(Fs)return F;Fs=1;var n=F&&F.__extends||(function(){var p=function(d,g){return p=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(_,m){_.__proto__=m}||function(_,m){for(var y in m)m.hasOwnProperty(y)&&(_[y]=m[y])},p(d,g)};return function(d,g){p(d,g);function _(){this.constructor=d}d.prototype=g===null?Object.create(g):(_.prototype=g.prototype,new _)}})();Object.defineProperty(F,"__esModule",{value:!0});var r=256,e=(function(){function p(d){d===void 0&&(d="="),this._paddingCharacter=d}return p.prototype.encodedLength=function(d){return this._paddingCharacter?(d+2)/3*4|0:(d*8+5)/6|0},p.prototype.encode=function(d){for(var g="",_=0;_<d.length-2;_+=3){var m=d[_]<<16|d[_+1]<<8|d[_+2];g+=this._encodeByte(m>>>18&63),g+=this._encodeByte(m>>>12&63),g+=this._encodeByte(m>>>6&63),g+=this._encodeByte(m>>>0&63)}var y=d.length-_;if(y>0){var m=d[_]<<16|(y===2?d[_+1]<<8:0);g+=this._encodeByte(m>>>18&63),g+=this._encodeByte(m>>>12&63),y===2?g+=this._encodeByte(m>>>6&63):g+=this._paddingCharacter||"",g+=this._paddingCharacter||""}return g},p.prototype.maxDecodedLength=function(d){return this._paddingCharacter?d/4*3|0:(d*6+7)/8|0},p.prototype.decodedLength=function(d){return this.maxDecodedLength(d.length-this._getPaddingLength(d))},p.prototype.decode=function(d){if(d.length===0)return new Uint8Array(0);for(var g=this._getPaddingLength(d),_=d.length-g,m=new Uint8Array(this.maxDecodedLength(_)),y=0,x=0,E=0,b=0,k=0,R=0,T=0;x<_-4;x+=4)b=this._decodeChar(d.charCodeAt(x+0)),k=this._decodeChar(d.charCodeAt(x+1)),R=this._decodeChar(d.charCodeAt(x+2)),T=this._decodeChar(d.charCodeAt(x+3)),m[y++]=b<<2|k>>>4,m[y++]=k<<4|R>>>2,m[y++]=R<<6|T,E|=b&r,E|=k&r,E|=R&r,E|=T&r;if(x<_-1&&(b=this._decodeChar(d.charCodeAt(x)),k=this._decodeChar(d.charCodeAt(x+1)),m[y++]=b<<2|k>>>4,E|=b&r,E|=k&r),x<_-2&&(R=this._decodeChar(d.charCodeAt(x+2)),m[y++]=k<<4|R>>>2,E|=R&r),x<_-3&&(T=this._decodeChar(d.charCodeAt(x+3)),m[y++]=R<<6|T,E|=T&r),E!==0)throw new Error("Base64Coder: incorrect characters for decoding");return m},p.prototype._encodeByte=function(d){var g=d;return g+=65,g+=25-d>>>8&6,g+=51-d>>>8&-75,g+=61-d>>>8&-15,g+=62-d>>>8&3,String.fromCharCode(g)},p.prototype._decodeChar=function(d){var g=r;return g+=(42-d&d-44)>>>8&-r+d-43+62,g+=(46-d&d-48)>>>8&-r+d-47+63,g+=(47-d&d-58)>>>8&-r+d-48+52,g+=(64-d&d-91)>>>8&-r+d-65+0,g+=(96-d&d-123)>>>8&-r+d-97+26,g},p.prototype._getPaddingLength=function(d){var g=0;if(this._paddingCharacter){for(var _=d.length-1;_>=0&&d[_]===this._paddingCharacter;_--)g++;if(d.length<4||g>2)throw new Error("Base64Coder: incorrect padding")}return g},p})();F.Coder=e;var t=new e;function s(p){return t.encode(p)}F.encode=s;function i(p){return t.decode(p)}F.decode=i;var a=(function(p){n(d,p);function d(){return p!==null&&p.apply(this,arguments)||this}return d.prototype._encodeByte=function(g){var _=g;return _+=65,_+=25-g>>>8&6,_+=51-g>>>8&-75,_+=61-g>>>8&-13,_+=62-g>>>8&49,String.fromCharCode(_)},d.prototype._decodeChar=function(g){var _=r;return _+=(44-g&g-46)>>>8&-r+g-45+62,_+=(94-g&g-96)>>>8&-r+g-95+63,_+=(47-g&g-58)>>>8&-r+g-48+52,_+=(64-g&g-91)>>>8&-r+g-65+0,_+=(96-g&g-123)>>>8&-r+g-97+26,_},d})(e);F.URLSafeCoder=a;var c=new a;function u(p){return c.encode(p)}F.encodeURLSafe=u;function l(p){return c.decode(p)}return F.decodeURLSafe=l,F.encodedLength=function(p){return t.encodedLength(p)},F.maxDecodedLength=function(p){return t.maxDecodedLength(p)},F.decodedLength=function(p){return t.decodedLength(p)},F}var zn={exports:{}},xu=zn.exports,qs;function Ru(){return qs||(qs=1,(function(n){(function(r,e){var t={};e(t);var s=t.default;for(var i in t)s[i]=t[i];n.exports=s})(xu,function(r){r.__esModule=!0,r.digestLength=32,r.blockSize=64;var e=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function t(g,_,m,y,x){for(var E,b,k,R,T,$,C,M,L,I,ne,we,ye;x>=64;){for(E=_[0],b=_[1],k=_[2],R=_[3],T=_[4],$=_[5],C=_[6],M=_[7],I=0;I<16;I++)ne=y+I*4,g[I]=(m[ne]&255)<<24|(m[ne+1]&255)<<16|(m[ne+2]&255)<<8|m[ne+3]&255;for(I=16;I<64;I++)L=g[I-2],we=(L>>>17|L<<15)^(L>>>19|L<<13)^L>>>10,L=g[I-15],ye=(L>>>7|L<<25)^(L>>>18|L<<14)^L>>>3,g[I]=(we+g[I-7]|0)+(ye+g[I-16]|0);for(I=0;I<64;I++)we=(((T>>>6|T<<26)^(T>>>11|T<<21)^(T>>>25|T<<7))+(T&$^~T&C)|0)+(M+(e[I]+g[I]|0)|0)|0,ye=((E>>>2|E<<30)^(E>>>13|E<<19)^(E>>>22|E<<10))+(E&b^E&k^b&k)|0,M=C,C=$,$=T,T=R+we|0,R=k,k=b,b=E,E=we+ye|0;_[0]+=E,_[1]+=b,_[2]+=k,_[3]+=R,_[4]+=T,_[5]+=$,_[6]+=C,_[7]+=M,y+=64,x-=64}return y}var s=(function(){function g(){this.digestLength=r.digestLength,this.blockSize=r.blockSize,this.state=new Int32Array(8),this.temp=new Int32Array(64),this.buffer=new Uint8Array(128),this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this.reset()}return g.prototype.reset=function(){return this.state[0]=1779033703,this.state[1]=3144134277,this.state[2]=1013904242,this.state[3]=2773480762,this.state[4]=1359893119,this.state[5]=2600822924,this.state[6]=528734635,this.state[7]=1541459225,this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this},g.prototype.clean=function(){for(var _=0;_<this.buffer.length;_++)this.buffer[_]=0;for(var _=0;_<this.temp.length;_++)this.temp[_]=0;this.reset()},g.prototype.update=function(_,m){if(m===void 0&&(m=_.length),this.finished)throw new Error("SHA256: can't update because hash was finished.");var y=0;if(this.bytesHashed+=m,this.bufferLength>0){for(;this.bufferLength<64&&m>0;)this.buffer[this.bufferLength++]=_[y++],m--;this.bufferLength===64&&(t(this.temp,this.state,this.buffer,0,64),this.bufferLength=0)}for(m>=64&&(y=t(this.temp,this.state,_,y,m),m%=64);m>0;)this.buffer[this.bufferLength++]=_[y++],m--;return this},g.prototype.finish=function(_){if(!this.finished){var m=this.bytesHashed,y=this.bufferLength,x=m/536870912|0,E=m<<3,b=m%64<56?64:128;this.buffer[y]=128;for(var k=y+1;k<b-8;k++)this.buffer[k]=0;this.buffer[b-8]=x>>>24&255,this.buffer[b-7]=x>>>16&255,this.buffer[b-6]=x>>>8&255,this.buffer[b-5]=x>>>0&255,this.buffer[b-4]=E>>>24&255,this.buffer[b-3]=E>>>16&255,this.buffer[b-2]=E>>>8&255,this.buffer[b-1]=E>>>0&255,t(this.temp,this.state,this.buffer,0,b),this.finished=!0}for(var k=0;k<8;k++)_[k*4+0]=this.state[k]>>>24&255,_[k*4+1]=this.state[k]>>>16&255,_[k*4+2]=this.state[k]>>>8&255,_[k*4+3]=this.state[k]>>>0&255;return this},g.prototype.digest=function(){var _=new Uint8Array(this.digestLength);return this.finish(_),_},g.prototype._saveState=function(_){for(var m=0;m<this.state.length;m++)_[m]=this.state[m]},g.prototype._restoreState=function(_,m){for(var y=0;y<this.state.length;y++)this.state[y]=_[y];this.bytesHashed=m,this.finished=!1,this.bufferLength=0},g})();r.Hash=s;var i=(function(){function g(_){this.inner=new s,this.outer=new s,this.blockSize=this.inner.blockSize,this.digestLength=this.inner.digestLength;var m=new Uint8Array(this.blockSize);if(_.length>this.blockSize)new s().update(_).finish(m).clean();else for(var y=0;y<_.length;y++)m[y]=_[y];for(var y=0;y<m.length;y++)m[y]^=54;this.inner.update(m);for(var y=0;y<m.length;y++)m[y]^=106;this.outer.update(m),this.istate=new Uint32Array(8),this.ostate=new Uint32Array(8),this.inner._saveState(this.istate),this.outer._saveState(this.ostate);for(var y=0;y<m.length;y++)m[y]=0}return g.prototype.reset=function(){return this.inner._restoreState(this.istate,this.inner.blockSize),this.outer._restoreState(this.ostate,this.outer.blockSize),this},g.prototype.clean=function(){for(var _=0;_<this.istate.length;_++)this.ostate[_]=this.istate[_]=0;this.inner.clean(),this.outer.clean()},g.prototype.update=function(_){return this.inner.update(_),this},g.prototype.finish=function(_){return this.outer.finished?this.outer.finish(_):(this.inner.finish(_),this.outer.update(_,this.digestLength).finish(_)),this},g.prototype.digest=function(){var _=new Uint8Array(this.digestLength);return this.finish(_),_},g})();r.HMAC=i;function a(g){var _=new s().update(g),m=_.digest();return _.clean(),m}r.hash=a,r.default=a;function c(g,_){var m=new i(g).update(_),y=m.digest();return m.clean(),y}r.hmac=c;function u(g,_,m,y){var x=y[0];if(x===0)throw new Error("hkdf: cannot expand more");_.reset(),x>1&&_.update(g),m&&_.update(m),_.update(y),_.finish(g),y[0]++}var l=new Uint8Array(r.digestLength);function p(g,_,m,y){_===void 0&&(_=l),y===void 0&&(y=32);for(var x=new Uint8Array([1]),E=c(_,g),b=new i(E),k=new Uint8Array(b.digestLength),R=k.length,T=new Uint8Array(y),$=0;$<y;$++)R===k.length&&(u(k,b,m,x),R=0),T[$]=k[R++];return b.clean(),k.fill(0),x.fill(0),T}r.hkdf=p;function d(g,_,m,y){for(var x=new i(g),E=x.digestLength,b=new Uint8Array(4),k=new Uint8Array(E),R=new Uint8Array(E),T=new Uint8Array(y),$=0;$*E<y;$++){var C=$+1;b[0]=C>>>24&255,b[1]=C>>>16&255,b[2]=C>>>8&255,b[3]=C>>>0&255,x.reset(),x.update(_),x.update(b),x.finish(R);for(var M=0;M<E;M++)k[M]=R[M];for(var M=2;M<=m;M++){x.reset(),x.update(R).finish(R);for(var L=0;L<E;L++)k[L]^=R[L]}for(var M=0;M<E&&$*E+M<y;M++)T[$*E+M]=k[M]}for(var $=0;$<E;$++)k[$]=R[$]=0;for(var $=0;$<4;$++)b[$]=0;return x.clean(),T}r.pbkdf2=d})})(zn)),zn.exports}var Zt={},Ks;function Au(){if(Ks)return Zt;Ks=1,Object.defineProperty(Zt,"__esModule",{value:!0}),Zt.timingSafeEqual=r;function n(e,t=""){if(!e)throw new Error(t)}function r(e,t){if(e.byteLength!==t.byteLength)return!1;e instanceof DataView||(e=new DataView(ArrayBuffer.isView(e)?e.buffer:e)),t instanceof DataView||(t=new DataView(ArrayBuffer.isView(t)?t.buffer:t)),n(e instanceof DataView),n(t instanceof DataView);const s=e.byteLength;let i=0,a=-1;for(;++a<s;)i|=e.getUint8(a)^t.getUint8(a);return i===0}return Zt}var Vs;function Eu(){if(Vs)return Te;Vs=1,Object.defineProperty(Te,"__esModule",{value:!0}),Te.Webhook=Te.WebhookVerificationError=void 0;const n=Su(),r=Ru(),e=Au(),t=300;class s extends Error{constructor(u){super(u),Object.setPrototypeOf(this,s.prototype),this.name="ExtendableError",this.stack=new Error(u).stack}}class i extends s{constructor(u){super(u),Object.setPrototypeOf(this,i.prototype),this.name="WebhookVerificationError"}}Te.WebhookVerificationError=i;class a{constructor(u,l){if(l?.format==="raw")u instanceof Uint8Array?this.key=u:this.key=Uint8Array.from(u,p=>p.charCodeAt(0));else{if(typeof u!="string")throw new Error("Expected secret to be of type string");u.startsWith(a.prefix)&&(u=u.substring(a.prefix.length)),this.key=n.decode(u)}if(this.key.length===0)throw new Error("Secret can't be empty.")}verify(u,l,p){var d;const g=(d=p?.jsonParse)!==null&&d!==void 0?d:!0,_={};for(const $ of Object.keys(l))_[$.toLowerCase()]=l[$];const m=_["webhook-id"],y=_["webhook-signature"],x=_["webhook-timestamp"];if(!y||!m||!x)throw new i("Missing required headers");const E=this.verifyTimestamp(x),k=this.sign(m,E,u).split(",")[1],R=y.split(" "),T=new globalThis.TextEncoder;for(const $ of R){const[C,M]=$.split(",");if(C==="v1"&&(0,e.timingSafeEqual)(T.encode(M),T.encode(k))){const L=u.toString();return L===""?void 0:g?JSON.parse(L):void 0}}throw new i("No matching signature found")}sign(u,l,p){if(typeof p!="string")if(p.constructor.name==="Buffer")p=p.toString();else throw new Error("Expected payload to be of type string or Buffer.");const d=new TextEncoder,g=Math.floor(l.getTime()/1e3),_=d.encode(`${u}.${g}.${p}`);return`v1,${n.encode(r.hmac(this.key,_))}`}verifyTimestamp(u){const l=Math.floor(Date.now()/1e3),p=parseInt(u,10);if(Number.isNaN(p))throw new i("Invalid Signature Headers");if(l-p>t)throw new i("Message timestamp too old");if(p>l+t)throw new i("Message timestamp too new");return new Date(p*1e3)}}return Te.Webhook=a,a.prefix="whsec_",Te}var Tu=Eu();class Js extends v{parseUnverified(r){return JSON.parse(r)}unwrap(r,e){const t=e?.headers;if(t==null)throw new Error("Webhook headers are required in order to verify the signature");const s=e.key===void 0?this._client.webhookKey:e.key;if(!s)throw new Error("Webhook key must not be null or empty in order to unwrap");return new Tu.Webhook(s).verify(r,t),JSON.parse(r)}}let Xs=class extends v{list(r,e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList(h`/v1/agents/${r}/versions?beta=true`,A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}};var Gs=(()=>{class n extends v{constructor(){super(...arguments),this.versions=new Xs(this._client)}create(e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post("/v1/agents?beta=true",{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i,workspace_id:a,...c}=t??{};return this._client.get(h`/v1/agents/${e}?beta=true`,{query:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}update(e,t,s){const{betas:i,workspace_id:a,...c}=t;return this._client.post(h`/v1/agents/${e}?beta=true`,{body:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}list(e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList("/v1/agents?beta=true",A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}archive(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.post(h`/v1/agents/${e}/archive?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}}return n.Versions=Xs,n})();function Vt(n,r){if(!n)return()=>{};if(n.aborted)return r.abort(),()=>{};const e=()=>r.abort();return n.addEventListener("abort",e),()=>n.removeEventListener("abort",e)}function ot(n,r){return n instanceof z&&n.status===r}function $u(n){return n instanceof z&&typeof n.status=="number"&&n.status>=400&&n.status<500}function Xn(n){return $u(n)&&!ot(n,408)&&!ot(n,409)&&!ot(n,429)}function Oc(n,r,e){return Math.min(r*2**n,e)}function Iu(n,r){return n+Math.random()*(r-n)}function Cc(n){return n*(1-Math.random()*.25)}function Lc(n,{authToken:r,helper:e}){if(!r)throw new S(`copyClientForHelper: expected a non-empty authToken but received ${JSON.stringify(r)}`);const t=n,s=t._options.defaultHeaders,i=t._authState?.extraHeaders,a=i?Object.fromEntries(Object.entries(i).filter(([u])=>{const l=u.toLowerCase();return l!=="authorization"&&l!=="x-api-key"})):void 0,c=f([a,s,{[Xt]:e}]);return n.withOptions({apiKey:null,authToken:r,baseURL:n.baseURL,credentials:void 0,defaultHeaders:c})}var He,en,re,tn,nn,rn,pt,_t,We,ze,sn,je,gt;const Pu=999,Mu=1e3,Ou=6e4,Cu=3e5;var Wr=(()=>{class n{constructor(e){He.set(this,void 0),en.set(this,!1),re.set(this,void 0),tn.set(this,void 0),nn.set(this,void 0),rn.set(this,void 0),pt.set(this,void 0),_t.set(this,void 0),We.set(this,void 0),this.client=e.client,this.environmentId=e.environmentId,this.environmentKey=e.environmentKey,this.workerId=e.workerId??Bu(),w(this,He,Lc(e.client,{authToken:e.environmentKey,helper:"environments-work-poller"})),w(this,nn,e.autoStop??!0),w(this,rn,e.drain??!1),w(this,pt,e.blockMs===void 0?Pu:e.blockMs),w(this,_t,e.reclaimOlderThanMs??null),w(this,We,e.requestOptions),w(this,re,new AbortController),w(this,tn,Vt(e.signal,o(this,re,"f")))}get signal(){return o(this,re,"f").signal}abort(){o(this,re,"f").abort()}async*[(He=new WeakMap,en=new WeakMap,re=new WeakMap,tn=new WeakMap,nn=new WeakMap,rn=new WeakMap,pt=new WeakMap,_t=new WeakMap,We=new WeakMap,Symbol.asyncIterator)](){if(o(this,en,"f"))throw new S("Cannot iterate over a consumed WorkPoller");w(this,en,!0);const e=O(this.client);e.info("poller starting",{component:"work-poller",environment_id:this.environmentId});const t=new Nu(e,this.environmentId);try{let s=0;for(;!o(this,re,"f").signal.aborted;){let i;try{i=await o(this,He,"f").beta.environments.work.poll(this.environmentId,{"Anthropic-Worker-ID":this.workerId,...o(this,pt,"f")!==null?{block_ms:o(this,pt,"f")}:{},...o(this,_t,"f")!==null?{reclaim_older_than_ms:o(this,_t,"f")}:{}},{headers:f([o(this,We,"f")?.headers]),signal:o(this,re,"f").signal})}catch(a){if(o(this,re,"f").signal.aborted)return;if(Xn(a))throw e.error("poll failed permanently, stopping poller",{error:String(a)}),a;const c=Cc(Lu(s));e.warn("poll failed, backing off",{error:String(a),backoff_ms:c}),s++,await Be(c,o(this,re,"f").signal);continue}if(s=0,i==null){if(o(this,rn,"f"))return;t.onEmptyPoll(),await Be(Iu(1e3,3e3),o(this,re,"f").signal);continue}t.onClaim(),e.info("claimed work",{component:"work-poller",environment_id:this.environmentId,work_id:i.id,work_type:i.data.type});try{await o(this,He,"f").beta.environments.work.ack(i.id,{environment_id:i.environment_id},{headers:f([o(this,We,"f")?.headers]),signal:o(this,re,"f").signal})}catch(a){e.error("ack failed",{work_id:i.id,error:String(a)});continue}try{yield i}finally{if(o(this,nn,"f"))try{await o(this,He,"f").beta.environments.work.stop(i.id,{environment_id:i.environment_id},{headers:f([o(this,We,"f")?.headers])})}catch(a){ot(a,409)||e.warn("stop failed",{work_id:i.id,error:String(a)})}}}}finally{o(this,tn,"f").call(this)}}}return n})();function Lu(n){return Oc(n,Mu,Ou)}var Nu=(()=>{class n{constructor(e,t){ze.set(this,void 0),sn.set(this,void 0),je.set(this,void 0),gt.set(this,0),w(this,ze,e),w(this,sn,t)}onEmptyPoll(){const e=Date.now(),t={component:"work-poller",environment_id:o(this,sn,"f")};o(this,je,"f")===void 0?(w(this,je,w(this,gt,e,"f")),o(this,ze,"f").info("idle; polling for work",t)):e-o(this,gt,"f")>=Cu?(w(this,gt,e),o(this,ze,"f").info(`still polling; idle for ${Math.round((e-o(this,je,"f"))/1e3)}s`,t)):o(this,ze,"f").debug("poll returned no work",t)}onClaim(){w(this,je,void 0)}}return ze=new WeakMap,sn=new WeakMap,je=new WeakMap,gt=new WeakMap,n})();function Bu(){const r=globalThis.process?.env?.HOSTNAME;return r?`${r}-${Dr()}`:Dr()}var Fe,be,qe,Du=(()=>{class n{constructor(){Fe.set(this,[]),be.set(this,[]),qe.set(this,!1)}push(e){if(o(this,qe,"f"))return!1;const t=o(this,be,"f").shift();return t?t({done:!1,value:e}):o(this,Fe,"f").push(e),!0}close(){if(!o(this,qe,"f"))for(w(this,qe,!0);o(this,be,"f").length>0;)o(this,be,"f").shift()({done:!0,value:void 0})}next(e){return o(this,Fe,"f").length>0?Promise.resolve({done:!1,value:o(this,Fe,"f").shift()}):o(this,qe,"f")||e?.aborted?Promise.resolve({done:!0,value:void 0}):new Promise(t=>{const s=a=>{e?.removeEventListener("abort",i),t(a)},i=()=>{const a=o(this,be,"f").indexOf(s);a>=0&&o(this,be,"f").splice(a,1),t({done:!0,value:void 0})};o(this,be,"f").push(s),e?.addEventListener("abort",i,{once:!0})})}tryShift(){return o(this,Fe,"f").shift()}}return Fe=new WeakMap,be=new WeakMap,qe=new WeakMap,n})(),cs=(()=>{class n extends Error{constructor(e){const t=typeof e=="string"?e:e.map(s=>s.type==="text"?s.text:`[${s.type}]`).join(" ");super(t),this.name="ToolError",this.content=e}}return n})();function Qs(n){return"name"in n?n.name:"mcp_server_name"in n?n.mcp_server_name:n.type}function Uu(n){return n instanceof cs?n.content:`Error: ${n instanceof Error?n.message:String(n)}`}async function Hu(n,r,e){try{const t=n.parse?n.parse(r):r;return{content:await n.run(t,e),isError:!1}}catch(t){return{content:Uu(t),isError:!0}}}var mt,an,Ke,$e,ae,U,on,j,cn,wt,ln,H,Ve,Y,Je,ve,Xe,pe,un,yt,Z,dn,Ys,Zs,ei,ti,tr,ni,hn,fn,nr,ri,si;const ii=500,Wu=1e4,zu=12e4,ju=3e4,Fu=1e3,qu=3e4,Ku=5*6e4,Vu=6e4;function Nc(n){return n.type!=="session.status_idle"?!1:n.stop_reason?.type!=="requires_action"}var Ju=(()=>{class n{constructor(e,t){mt.set(this,void 0),an.set(this,void 0),Ke.set(this,new Set),$e.set(this,!1),ae.set(this,void 0),w(this,mt,e),w(this,an,t)}noteEvent(e){e.type!=="user.tool_confirmation"&&(Nc(e)?this.arm():this.disarm())}block(e){o(this,Ke,"f").add(e),o(this,ae,"f")!==void 0&&(w(this,$e,!0),clearTimeout(o(this,ae,"f")),w(this,ae,void 0))}unblock(e){o(this,Ke,"f").delete(e),o(this,Ke,"f").size===0&&o(this,$e,"f")&&this.arm()}arm(){if(!(o(this,mt,"f")<=0)){if(o(this,Ke,"f").size>0){w(this,$e,!0);return}w(this,$e,!1),o(this,ae,"f")!==void 0&&clearTimeout(o(this,ae,"f")),w(this,ae,setTimeout(o(this,an,"f"),o(this,mt,"f")))}}disarm(){w(this,$e,!1),o(this,ae,"f")!==void 0&&(clearTimeout(o(this,ae,"f")),w(this,ae,void 0))}}return mt=new WeakMap,an=new WeakMap,Ke=new WeakMap,$e=new WeakMap,ae=new WeakMap,n})(),zr=(()=>{class n{constructor(e,t){U.add(this),on.set(this,!1),j.set(this,void 0),cn.set(this,void 0),wt.set(this,void 0),ln.set(this,void 0),H.set(this,void 0),Ve.set(this,new Set),Y.set(this,new Set),Je.set(this,new Map),ve.set(this,new Map),Xe.set(this,new Du),pe.set(this,0),un.set(this,Ku),yt.set(this,null),Z.set(this,void 0),this.client=t.client,this.sessionId=e,this.tools=t.tools,this.maxIdleMs=t.maxIdleMs??Vu,w(this,H,O(t.client)),w(this,ln,new Map(t.tools.map(s=>[Qs(s),s]))),w(this,j,new AbortController),w(this,cn,Vt(t.signal,o(this,j,"f"))),w(this,wt,t.requestOptions),w(this,Z,new Ju(this.maxIdleMs,()=>{o(this,H,"f").info("session idle after its turn ended; stopping",{component:"session-tool-runner",session_id:this.sessionId,max_idle_ms:this.maxIdleMs}),o(this,j,"f").abort()}))}get signal(){return o(this,j,"f").signal}abort(){o(this,j,"f").abort()}_setSendRetryWindow(e){w(this,un,e)}async*[(on=new WeakMap,j=new WeakMap,cn=new WeakMap,wt=new WeakMap,ln=new WeakMap,H=new WeakMap,Ve=new WeakMap,Y=new WeakMap,Je=new WeakMap,ve=new WeakMap,Xe=new WeakMap,pe=new WeakMap,un=new WeakMap,yt=new WeakMap,Z=new WeakMap,U=new WeakSet,Symbol.asyncIterator)](){if(o(this,on,"f"))throw new S("Cannot iterate over a consumed SessionToolRunner");w(this,on,!0),o(this,H,"f").info("session tool runner starting",{component:"session-tool-runner",session_id:this.sessionId});const e=o(this,U,"m",Ys).call(this).catch(t=>{o(this,j,"f").signal.aborted||o(this,H,"f").error("stream loop failed",{error:String(t)}),o(this,j,"f").abort()});try{for(;;){const s=await o(this,Xe,"f").next(o(this,j,"f").signal);if(s.done)break;yield s.value}await e;let t;for(;(t=o(this,Xe,"f").tryShift())!==void 0;)yield t}finally{o(this,j,"f").abort(),o(this,Z,"f").disarm(),await e;try{await o(this,U,"m",si).call(this)}catch(t){o(this,H,"f").warn("drain failed",{error:String(t)})}o(this,Xe,"f").close();for(const t of this.tools)try{await t.close?.()}catch(s){o(this,H,"f").warn("tool.close failed",{tool:Qs(t),error:String(s)})}o(this,cn,"f").call(this)}}}return dn=function(){return{...o(this,wt,"f"),headers:f([$c("session-tool-runner"),o(this,wt,"f")?.headers]),signal:o(this,j,"f").signal}},Ys=async function(){const e=o(this,j,"f");let t=ii;for(;!e.signal.aborted;){try{const s=await this.client.beta.sessions.events.stream(this.sessionId,{},o(this,U,"m",dn).call(this));await o(this,U,"m",Zs).call(this);for await(const i of s)if(t=ii,await o(this,U,"m",ti).call(this,i))return}catch(s){if(e.signal.throwIfAborted(),Xn(s))throw o(this,H,"f").error("permanent stream failure, shutting down",{error:String(s)}),e.abort(),s;o(this,H,"f").warn("stream disconnected, reconnecting",{error:String(s),backoff_ms:t})}e.signal.throwIfAborted(),await Be(t,e.signal),t=Math.min(t*2,Wu)}},Zs=async function(){const e=o(this,j,"f"),t=[];let s=!1;try{for await(const c of this.client.beta.sessions.events.list(this.sessionId,{limit:1e3},o(this,U,"m",dn).call(this)))o(this,U,"m",ei).call(this,c,t),c.type!=="user.tool_confirmation"&&(s=Nc(c))}catch(c){e.signal.throwIfAborted(),o(this,H,"f").warn("reconcile list failed",{error:String(c)});for(const u of t)o(this,Ve,"f").delete(u.id);return}const i=t.filter(c=>!o(this,Y,"f").has(c.id));o(this,Z,"f").disarm();for(const c of i)await o(this,U,"m",tr).call(this,c);for(const c of[...o(this,ve,"f").values()]){const u=o(this,Je,"f").get(c.id);u!==void 0&&await o(this,U,"m",hn).call(this,c,u)}const a=i.filter(c=>!o(this,Y,"f").has(c.id)&&!o(this,ve,"f").has(c.id));s&&a.length===0?o(this,Z,"f").arm():o(this,Z,"f").disarm()},ei=function(e,t){e.type==="agent.tool_use"||e.type==="agent.custom_tool_use"?(o(this,Ve,"f").add(e.id),o(this,Y,"f").has(e.id)||t.push(e)):e.type==="user.tool_result"?o(this,Y,"f").add(e.tool_use_id):e.type==="user.custom_tool_result"?o(this,Y,"f").add(e.custom_tool_use_id):e.type==="user.tool_confirmation"&&(o(this,Y,"f").has(e.tool_use_id)||o(this,Je,"f").set(e.tool_use_id,e.result))},ti=async function(e){switch(o(this,Z,"f").noteEvent(e),e.type){case"agent.tool_use":case"agent.custom_tool_use":return o(this,Ve,"f").has(e.id)||(o(this,Ve,"f").add(e.id),await o(this,U,"m",tr).call(this,e)),!1;case"user.tool_confirmation":return await o(this,U,"m",ni).call(this,e),!1;case"user.tool_result":return o(this,Y,"f").add(e.tool_use_id),!1;case"user.custom_tool_result":return o(this,Y,"f").add(e.custom_tool_use_id),!1;case"session.status_terminated":case"session.deleted":return o(this,H,"f").info("session terminated",{component:"session-tool-runner",session_id:this.sessionId}),o(this,j,"f").abort(),!0;default:return!1}},tr=async function(e){const t=e.evaluated_permission,s=t==="deny"?"deny":o(this,Je,"f").get(e.id);if(s===void 0){t===void 0||t==="allow"?await o(this,U,"m",nr).call(this,e,void 0):o(this,ve,"f").has(e.id)||(o(this,H,"f").info("tool call awaiting confirmation; holding",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),o(this,ve,"f").set(e.id,e),o(this,Z,"f").block(e.id));return}await o(this,U,"m",hn).call(this,e,s)},ni=async function(e){o(this,Je,"f").set(e.tool_use_id,e.result);const t=o(this,ve,"f").get(e.tool_use_id);t!==void 0&&await o(this,U,"m",hn).call(this,t,e.result)},hn=async function(e,t){const s=o(this,ve,"f").delete(e.id);if(t==="allow"){o(this,H,"f").info("tool call confirmed",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),s||o(this,Z,"f").block(e.id);try{await o(this,U,"m",nr).call(this,e,"allow")}finally{o(this,Z,"f").unblock(e.id)}return}s&&o(this,Z,"f").unblock(e.id),o(this,Y,"f").add(e.id),o(this,H,"f").info("tool call denied; not executing",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),o(this,U,"m",fn).call(this,{event:e,toolUseId:e.id,name:e.name,isError:!1,posted:!1,confirmation:"deny"})},fn=function(e){o(this,Xe,"f").push(e)},nr=async function(e,t){var s,i;if(!o(this,Y,"f").has(e.id)){o(this,H,"f").info("executing tool",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),w(this,pe,(s=o(this,pe,"f"),s++,s));try{const a=o(this,ln,"f").get(e.name);if(!a){o(this,H,"f").info("tool not owned by this runner; leaving the tool_use_id pending for its owner",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),t==="allow"&&o(this,Z,"f").disarm(),o(this,U,"m",fn).call(this,{event:e,toolUseId:e.id,name:e.name,isError:!1,posted:!1,confirmation:t});return}let c,u;const l=new AbortController,p=Vt(o(this,j,"f").signal,l),d=setTimeout(()=>l.abort(),zu);try{const m=await Hu(a,e.input,{toolUse:e,toolUseBlock:e,signal:l.signal});c=m.content,u=m.isError}finally{clearTimeout(d),p()}const g=Xu(e,u,Gu(c)),_=await o(this,U,"m",ri).call(this,g,e.id);o(this,U,"m",fn).call(this,{event:e,result:g,toolUseId:e.id,name:e.name,isError:u,posted:_,confirmation:t})}finally{w(this,pe,(i=o(this,pe,"f"),i--,i)),o(this,pe,"f")===0&&o(this,yt,"f")?.call(this)}}},ri=async function(e,t){const s=o(this,j,"f"),i=Date.now();let a,c=0;for(;;){c++,s.signal.throwIfAborted();try{return await this.client.beta.sessions.events.send(this.sessionId,{events:[e]},o(this,U,"m",dn).call(this)),o(this,Y,"f").add(t),!0}catch(u){if(a=u,Xn(u))break;const l=o(this,un,"f")-(Date.now()-i);if(l<=0)break;const p=Math.min(Cc(Oc(c-1,Fu,qu)),l);o(this,H,"f").warn("tool result send failed; retrying",{tool_use_id:t,attempt:c,backoff_ms:p,error:String(u)}),await Be(p,s.signal)}}return o(this,H,"f").error("failed to send tool result",{tool_use_id:t,attempts:c,error:String(a)}),!1},si=async function(){o(this,pe,"f")!==0&&(await Promise.race([new Promise(e=>w(this,yt,e)),Be(ju)]),w(this,yt,null),o(this,pe,"f")>0&&o(this,H,"f").warn("drain timeout exceeded"))},n})();function Xu(n,r,e){return n.type==="agent.custom_tool_use"?{type:"user.custom_tool_result",custom_tool_use_id:n.id,is_error:r,content:e}:{type:"user.tool_result",tool_use_id:n.id,is_error:r,content:e}}function Gu(n){if(typeof n=="string")return[{type:"text",text:n||"(no output)"}];const r=n.map(e=>e.type==="text"?{type:"text",text:e.text||"(no output)"}:e.type==="image"||e.type==="document"?e:e.type==="search_result"?{type:"search_result",source:e.source,title:e.title,content:e.content.map(t=>({type:"text",text:t.text})),citations:{enabled:e.citations?.enabled??!1}}:{type:"text",text:JSON.stringify(e)});return r.length>0?r:[{type:"text",text:"(no output)"}]}const af=15e3,ai=5e3;function Qu(n,r){if(!(n>=ai))throw new S(`${r} must be at least ${ai}ms (got ${n}); to run without memory sync, pass \`memorySyncIntervalMs: null\` to the worker instead`)}var pn,bt,rr,vt,Ge;const oi=3e4,Yu=9e4,Zu="NO_HEARTBEAT";function ed(n){return n.resources.some(r=>r.type==="memory_store")}function td(n){if(!n)return null;let r;try{const t=n.replace(/-/g,"+").replace(/_/g,"/"),s=t.padEnd(Math.ceil(t.length/4)*4,"=");r=JSON.parse(Lr(Fl(s)))}catch{return null}if(r===null||typeof r!="object"||Array.isArray(r))return null;const e=r.sessions_token;return typeof e=="string"&&e!==""?e:null}var ci=(()=>{class n{constructor(e){if(pn.add(this),bt.set(this,void 0),e.unrestrictedPaths!==void 0)throw new S("The `unrestrictedPaths` option you passed to EnvironmentWorker (or client.beta.environments.work.worker()) is no longer supported. The worker's file tools (read, write, edit, glob, grep) are now always confined to `workdir` plus the session's memory folders. Remove `unrestrictedPaths` from your options; to let the file tools reach any other directory, add it to `AgentToolContext.allowedRoots` from a `tools` factory.");this.client=e.client,this.environmentId=e.environmentId,this.environmentKey=e.environmentKey,this.tools=e.tools,this.workdir=e.workdir??process.cwd(),this.maxFileBytes=e.maxFileBytes,this.maxIdleMs=e.maxIdleMs,e.memorySyncIntervalMs!=null&&Qu(e.memorySyncIntervalMs,"memorySyncIntervalMs"),this.memorySyncIntervalMs=e.memorySyncIntervalMs,this.memorySyncDeletions=e.memorySyncDeletions??"enabled",this.workerId=e.workerId,this.requestOptions=e.requestOptions,w(this,bt,e.signal)}async run(e){const{environmentId:t,environmentKey:s}=this;if(t===void 0||s===void 0)throw new S("EnvironmentWorker.run: environmentId and environmentKey are required to poll for work");const i=e??o(this,bt,"f"),a=new Wr({client:this.client,environmentId:t,environmentKey:s,...this.workerId!==void 0?{workerId:this.workerId}:{},...i?{signal:i}:{},...this.requestOptions!==void 0?{requestOptions:this.requestOptions}:{},autoStop:!1});for await(const c of a)try{await o(this,pn,"m",rr).call(this,c,s,a.signal)}catch(u){if(a.signal?.aborted)throw u;O(this.client).error("work item failed",{work_id:c.id,error:String(u)})}}async handleItem(e){const t=e?.workId??P("ANTHROPIC_WORK_ID"),s=e?.environmentId??P("ANTHROPIC_ENVIRONMENT_ID"),i=e?.sessionId??P("ANTHROPIC_SESSION_ID"),a=(e?.environmentKey??this.environmentKey??P("ANTHROPIC_ENVIRONMENT_KEY"))||void 0,c=e?.workSecret||P("ANTHROPIC_WORK_SECRET")||null;if(!t)throw new S("handleItem: workId is required — pass it or set ANTHROPIC_WORK_ID");if(!s)throw new S("handleItem: environmentId is required — pass it or set ANTHROPIC_ENVIRONMENT_ID");if(!i)throw new S("handleItem: sessionId is required — pass it or set ANTHROPIC_SESSION_ID");if(!a&&!c)throw new S("handleItem: environmentKey is required when there is no work secret — pass it, construct the worker with it, or set ANTHROPIC_ENVIRONMENT_KEY");const u={id:t,environment_id:s,secret:c,data:{type:"session",id:i}};await o(this,pn,"m",rr).call(this,u,a,e?.signal??o(this,bt,"f"))}}return bt=new WeakMap,pn=new WeakSet,rr=async function(e,t,s){const i=O(this.client),a=td(e.secret),c=a??t;if(c===void 0)throw new S("handleItem: the work item carried a secret payload but no sessions token could be extracted, and there is no environment key to fall back to; the poller must issue a secret whose payload carries `sessions_token`, or provide the environment key (pass it, construct the worker with it, or set ANTHROPIC_ENVIRONMENT_KEY)");e.secret&&a===null&&i.warn("work item carried a secret payload but no sessions token could be extracted; falling back to the environment key",{work_id:e.id});const u=Lc(this.client,{authToken:c,helper:"environments-worker"}),l=e.data.id,p=new AbortController,d=Vt(s,p),g=new rd(p),_=await ce(()=>import("./node.browser-DWucOsQl.js"),__vite__mapDeps([3,1,2]));let m,y;const x=id(u,e,g,i,this.requestOptions,R=>{m=R,y?._setSendRetryWindow(R)}).catch(R=>{p.signal.aborted||i.error("heartbeat loop failed",{work_id:e.id,error:String(R)}),p.abort()});let E=async()=>{},b,k=!1;try{if(e.data.type!=="session"){i.debug("skipping non-session work item",{work_id:e.id,type:e.data.type});return}const R=await u.beta.sessions.retrieve(l);if(a===null&&this.memorySyncIntervalMs!==null&&ed(R))throw new _.SessionMemoryError(`cannot mount the session's memories: the work item carried no sessions token (work_id=${e.id}, session_id=${l}); the memory endpoints reject the environment key, so the poller must issue a per-item \`secret\` carrying \`sessions_token\`, or set \`memorySyncIntervalMs: null\` to run without memory`);const T={workdir:this.workdir,client:u,session:R,...this.maxFileBytes!==void 0?{maxFileBytes:this.maxFileBytes}:{}};try{E=await _.setupSkills(T)}catch(C){i.warn("skill setup failed",{session_id:l,work_id:e.id,error:String(C)})}a!==null&&this.memorySyncIntervalMs!==null?(b=new _.SessionMemoryStores(u,{workdir:this.workdir,...this.memorySyncIntervalMs!==void 0?{syncIntervalMs:this.memorySyncIntervalMs}:{},syncDeletions:this.memorySyncDeletions}),await b.download(R),T.allowedRoots=b.roots,T.readOnlyRoots=b.readOnlyRoots):i.debug("memory stores disabled for this item",{work_id:e.id});const $=typeof this.tools=="function"?this.tools(T):this.tools??_.betaAgentToolset20260401(T);y=new zr(l,{client:u,tools:$,...this.maxIdleMs!==void 0?{maxIdleMs:this.maxIdleMs}:{},...this.requestOptions!==void 0?{requestOptions:this.requestOptions}:{},signal:p.signal}),m!==void 0&&y._setSendRetryWindow(m);for await(const C of y)b&&await b.syncIfDue();k=!p.signal.aborted}finally{try{await E().catch(R=>{i.warn("skill cleanup failed",{session_id:l,work_id:e.id,error:String(R)})})}finally{if(b){const R=_.MEMORY_FLUSH_TIMEOUT_MS;k&&await li(b.finish(),R)&&i.warn(`final memory sync cut off after ${R}ms; the flush that follows still uploads changed files`,{session_id:l,work_id:e.id});const T=new AbortController;await li(b.flushWrites(T.signal),R)&&(T.abort(),i.warn(`memory flush cut off after ${R}ms; changed files it had not uploaded yet are not saved`,{session_id:l,work_id:e.id})),await b.dispose().catch(C=>{i.warn("memory store cleanup failed",{session_id:l,work_id:e.id,error:String(C)})})}}g.finish("runner_done"),d(),await x,g.lost?i.info("lease lost; released without stopping it",{session_id:l,work_id:e.id}):await nd(u,e,i,this.requestOptions)}},n})();async function li(n,r){let e;try{return await Promise.race([n.then(()=>!1,()=>!1),new Promise(t=>{e=setTimeout(()=>t(!0),r)})])}finally{e!==void 0&&clearTimeout(e)}}async function nd(n,r,e,t){try{await n.beta.environments.work.stop(r.id,{environment_id:r.environment_id,force:!0},{...t,headers:f([t?.headers])})}catch(s){ot(s,409)||e.error("force-stop on exit failed",{work_id:r.id,error:String(s)})}}var rd=(()=>{class n{constructor(e){vt.set(this,void 0),Ge.set(this,void 0),w(this,vt,e)}get signal(){return o(this,vt,"f").signal}finish(e){w(this,Ge,o(this,Ge,"f")??e),o(this,vt,"f").abort()}get lost(){return o(this,Ge,"f")==="lease_lost"||o(this,Ge,"f")==="assumed_lost"}}return vt=new WeakMap,Ge=new WeakMap,n})();function sd(n){let r=n instanceof z?n.error:void 0;for(const e of["error","details","current_state"]){if(!bs(r))return{};r=r[e]}return bs(r)?r:{}}async function id(n,r,e,t,s,i){let a=oi,c=Yu,u=Date.now(),l=Zu;const p=async()=>{const d=new AbortController,g=Vt(e.signal,d),_=setTimeout(()=>d.abort(),a);try{const m=await n.beta.environments.work.heartbeat(r.id,{environment_id:r.environment_id,expected_last_heartbeat:l},{...s,headers:f([s?.headers]),signal:d.signal});u=Date.now(),l=m.last_heartbeat,m.ttl_seconds>0&&(c=m.ttl_seconds*1e3,a=Math.max(1e3,Math.min(c/2,oi)),i?.(c)),(m.state==="stopping"||m.state==="stopped")&&(t.info("heartbeat signals shutdown",{work_id:r.id,state:m.state}),e.finish("control_plane_stop")),m.lease_extended||(t.warn("lease not extended, shutting down",{work_id:r.id}),e.finish("control_plane_stop"))}catch(m){if(e.signal.throwIfAborted(),ot(m,412)){const y=sd(m);t.error("lease lost: heartbeat precondition failed",{work_id:r.id,server_state:y.state,server_ttl_seconds:y.ttl_seconds,server_last_heartbeat:y.last_heartbeat}),e.finish("lease_lost");return}if(Xn(m))throw t.error("permanent heartbeat failure",{work_id:r.id,error:String(m)}),e.finish("heartbeat_rejected"),m;if(Date.now()-u>c){t.error("lease assumed lost: no successful heartbeat in ttl",{work_id:r.id,ttl_ms:c,error:String(m)}),e.finish("assumed_lost");return}t.warn("transient heartbeat failure",{work_id:r.id,error:String(m)})}finally{clearTimeout(_),g()}};for(await p();!e.signal.aborted;)await Be(a,e.signal),e.signal.throwIfAborted(),await p()}var ui=(()=>{class n extends v{retrieve(e,t,s){const{environment_id:i,betas:a,workspace_id:c}=t;return this._client.get(h`/v1/environments/${i}/work/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...a??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},s?.headers])})}update(e,t,s){const{environment_id:i,betas:a,workspace_id:c,...u}=t;return this._client.post(h`/v1/environments/${i}/work/${e}?beta=true`,{body:u,...s,headers:f([{"anthropic-beta":[...a??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},s?.headers])})}list(e,t={},s){const{betas:i,...a}=t??{};return this._client.getAPIList(h`/v1/environments/${e}/work?beta=true`,A,{query:a,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString()},s?.headers])})}ack(e,t,s){const{environment_id:i,betas:a}=t;return this._client.post(h`/v1/environments/${i}/work/${e}/ack?beta=true`,{...s,headers:f([{"anthropic-beta":[...a??[],"managed-agents-2026-04-01"].toString()},s?.headers])})}heartbeat(e,t,s){const{environment_id:i,desired_ttl_seconds:a,expected_last_heartbeat:c,betas:u}=t;return this._client.post(h`/v1/environments/${i}/work/${e}/heartbeat?beta=true`,{query:{desired_ttl_seconds:a,expected_last_heartbeat:c},...s,headers:f([{"anthropic-beta":[...u??[],"managed-agents-2026-04-01"].toString()},s?.headers])})}poll(e,t={},s){const{betas:i,"Anthropic-Worker-ID":a,...c}=t??{};return this._client.get(h`/v1/environments/${e}/work/poll?beta=true`,{query:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"Anthropic-Worker-ID":a}:void 0},s?.headers])})}stats(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.get(h`/v1/environments/${e}/work/stats?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}stop(e,t,s){const{environment_id:i,betas:a,workspace_id:c,...u}=t;return this._client.post(h`/v1/environments/${i}/work/${e}/stop?beta=true`,{body:u,...s,headers:f([{"anthropic-beta":[...a??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},s?.headers])})}poller(e){return new Wr({...e,client:this._client})}worker(e){return new ci({...e,client:this._client})}}return n.WorkPoller=Wr,n.EnvironmentWorker=ci,n})(),di=(()=>{class n extends v{constructor(){super(...arguments),this.work=new ui(this._client)}create(e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post("/v1/environments?beta=true",{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.get(h`/v1/environments/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}update(e,t,s){const{betas:i,workspace_id:a,...c}=t;return this._client.post(h`/v1/environments/${e}?beta=true`,{body:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}list(e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList("/v1/environments?beta=true",A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.delete(h`/v1/environments/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}archive(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.post(h`/v1/environments/${e}/archive?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}}return n.Work=ui,n})();class hi extends v{create(r,e,t){const{view:s,betas:i,workspace_id:a,...c}=e;return this._client.post(h`/v1/memory_stores/${r}/memories?beta=true`,{query:{view:s},body:c,...t,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}retrieve(r,e,t){const{memory_store_id:s,betas:i,workspace_id:a,...c}=e;return this._client.get(h`/v1/memory_stores/${s}/memories/${r}?beta=true`,{query:c,...t,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}update(r,e,t){const{memory_store_id:s,view:i,betas:a,workspace_id:c,...u}=e;return this._client.post(h`/v1/memory_stores/${s}/memories/${r}?beta=true`,{query:{view:i},body:u,...t,headers:f([{"anthropic-beta":[...a??[],"agent-memory-2026-07-22"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},t?.headers])})}list(r,e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList(h`/v1/memory_stores/${r}/memories?beta=true`,A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(r,e,t){const{memory_store_id:s,expected_content_sha256:i,betas:a,workspace_id:c}=e;return this._client.delete(h`/v1/memory_stores/${s}/memories/${r}?beta=true`,{query:{expected_content_sha256:i},...t,headers:f([{"anthropic-beta":[...a??[],"agent-memory-2026-07-22"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},t?.headers])})}}class fi extends v{retrieve(r,e,t){const{memory_store_id:s,betas:i,workspace_id:a,...c}=e;return this._client.get(h`/v1/memory_stores/${s}/memory_versions/${r}?beta=true`,{query:c,...t,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}list(r,e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList(h`/v1/memory_stores/${r}/memory_versions?beta=true`,A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}redact(r,e,t){const{memory_store_id:s,betas:i,workspace_id:a}=e;return this._client.post(h`/v1/memory_stores/${s}/memory_versions/${r}/redact?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}}var pi=(()=>{class n extends v{constructor(){super(...arguments),this.memories=new hi(this._client),this.memoryVersions=new fi(this._client)}create(e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post("/v1/memory_stores?beta=true",{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.get(h`/v1/memory_stores/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}update(e,t,s){const{betas:i,workspace_id:a,...c}=t;return this._client.post(h`/v1/memory_stores/${e}?beta=true`,{body:c,...s,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}list(e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList("/v1/memory_stores?beta=true",A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.delete(h`/v1/memory_stores/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}archive(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.post(h`/v1/memory_stores/${e}/archive?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}}return n.Memories=hi,n.MemoryVersions=fi,n})(),Bc=(()=>{class n{constructor(e,t){this.iterator=e,this.controller=t}async*decoder(){const e=new ss;for await(const t of this.iterator)for(const s of e.decode(t))yield JSON.parse(s);for(const t of e.flush())yield JSON.parse(t)}[Symbol.asyncIterator](){return this.decoder()}static fromResponse(e,t){if(!e.body)throw t.abort(),typeof globalThis.navigator<"u"&&globalThis.navigator.product==="ReactNative"?new S("The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api"):new S("Attempted to iterate over a response with no body");return new n(ts(e.body),t)}}return n})();let _i=class extends v{create(r,e){const{betas:t,user_profile_id:s,workspace_id:i,...a}=r;return this._client.post("/v1/messages/batches?beta=true",{body:a,...e,headers:f([{"anthropic-beta":[...t??[],"message-batches-2024-09-24"].toString(),...s!=null?{"anthropic-user-profile-id":s}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},e?.headers])})}retrieve(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/messages/batches/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"message-batches-2024-09-24"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/messages/batches?beta=true",X,{query:i,...e,headers:f([{"anthropic-beta":[...t??[],"message-batches-2024-09-24"].toString(),...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}delete(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.delete(h`/v1/messages/batches/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"message-batches-2024-09-24"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}cancel(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.post(h`/v1/messages/batches/${r}/cancel?beta=true`,{...t,headers:f([{"anthropic-beta":[...s??[],"message-batches-2024-09-24"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}async results(r,e={},t){const s=await this.retrieve(r,e,t);if(!s.results_url)throw new S(`No batch \`results_url\`; Has it finished processing? ${s.processing_status} - ${s.id}`);const{betas:i,workspace_id:a}=e??{};return this._client.get(s.results_url,{...t,headers:f([{"anthropic-beta":[...i??[],"message-batches-2024-09-24"].toString(),Accept:"application/binary",...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers]),stream:!0,__binaryResponse:!0})._thenUnwrap((c,u)=>Bc.fromResponse(u.response,u.controller))}};const Dc={"claude-opus-4@20250514":8192,"anthropic.claude-opus-4-1-20250805-v1:0":8192,"claude-opus-4-1@20250805":8192};function Uc(n){return n?.output_format??n?.output_config?.format}function gi(n,r,e){const t=Uc(r);return!r||!("parse"in(t??{}))?{...n,content:n.content.map(s=>{if(s.type==="text"){const i=Object.defineProperty({...s},"parsed_output",{value:null,enumerable:!1});return Object.defineProperty(i,"parsed",{get(){return e.logger.warn("The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead."),null},enumerable:!1})}return s}),parsed_output:null}:Hc(n,r,e)}function Hc(n,r,e){let t=null;const s=n.content.map(i=>{if(i.type==="text"){const a=ad(r,i.text);t===null&&(t=a);const c=Object.defineProperty({...i},"parsed_output",{value:a,enumerable:!1});return Object.defineProperty(c,"parsed",{get(){return e.logger.warn("The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead."),a},enumerable:!1})}return i});return{...n,content:s,parsed_output:t}}function ad(n,r){const e=Uc(n);if(e?.type!=="json_schema")return null;try{return"parse"in e?e.parse(r):JSON.parse(r)}catch(t){throw new S(`Failed to parse structured output: ${t}`)}}const od=n=>{let r=0,e=[];for(;r<n.length;){let t=n[r];if(t==="\\"){r++;continue}if(t==="{"){e.push({type:"brace",value:"{"}),r++;continue}if(t==="}"){e.push({type:"brace",value:"}"}),r++;continue}if(t==="["){e.push({type:"paren",value:"["}),r++;continue}if(t==="]"){e.push({type:"paren",value:"]"}),r++;continue}if(t===":"){e.push({type:"separator",value:":"}),r++;continue}if(t===","){e.push({type:"delimiter",value:","}),r++;continue}if(t==='"'){const c=r+1;let u=c,l=!1;for(;;){if(u=n.indexOf('"',u),u===-1){l=!0;break}let p=0,d=u-1;for(;d>=c&&n[d]==="\\";)p++,d--;if(p%2===0)break;u++}l?r=n.length:(e.push({type:"string",value:n.slice(c,u)}),r=u+1);continue}if(t&&/\s/.test(t)){r++;continue}let i=/[0-9]/;if(t&&i.test(t)||t==="-"||t==="."){let c="";for(t==="-"&&(c+=t,t=n[++r]);t&&(i.test(t)||t==="."||t==="e"||t==="E"||(t==="-"||t==="+")&&(c[c.length-1]==="e"||c[c.length-1]==="E"));)c+=t,t=n[++r];e.push({type:"number",value:c,unterminated:r===n.length});continue}let a=/[a-z]/i;if(t&&a.test(t)){let c="";for(;t&&a.test(t)&&r!==n.length;)c+=t,t=n[++r];if(c=="true"||c=="false"||c==="null")e.push({type:"name",value:c});else{r++;continue}continue}r++}return e},cd=n=>{let r=[];for(const i of n)(i.type==="brace"||i.type==="paren")&&(i.value==="{"||i.value==="["?r.push(i.value):r.pop());let e=r[r.length-1],t=n.length,s=/^-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-+]?[0-9]+)?$/;for(;t>0;){let i=n[t-1];switch(i.type){case"separator":t--;continue;case"number":if(i.unterminated||!s.test(i.value)){t--;continue}break;case"string":let a=n[t-2];if(e==="{"&&(a?.type==="delimiter"||a?.type==="brace"&&a.value==="{")){t--;continue}break;case"delimiter":t--;break}break}return n.slice(0,t)},ld=n=>{let r=[];return n.map(e=>{e.type==="brace"&&(e.value==="{"?r.push("}"):r.splice(r.lastIndexOf("}"),1)),e.type==="paren"&&(e.value==="["?r.push("]"):r.splice(r.lastIndexOf("]"),1))}),r.length>0&&r.reverse().map(e=>{e==="}"?n.push({type:"brace",value:"}"}):e==="]"&&n.push({type:"paren",value:"]"})}),n},ud=n=>{let r="";return n.map(e=>{e.type==="string"?r+='"'+e.value+'"':r+=e.value}),r},dd=n=>JSON.parse(ud(ld(cd(od(n))))),ct="__json_buf";function Wc(n,r){const e={};for(const i of Object.keys(n))i!=="input"&&(e[i]=n[i]);Object.defineProperty(e,ct,{value:r,enumerable:!1,writable:!0});let t,s=!1;return Object.defineProperty(e,"input",{enumerable:!0,configurable:!0,get(){return s||(t=r?dd(r):{},s=!0),t}}),e}var q,ke,Qe,kt,_n,St,xt,gn,Rt,ue,At,mn,wn,Ie,yn,bn,vn,Et,sr,mi,Tt,ir,ar,or,wi,cr;function lr(n){return n.type==="tool_use"||n.type==="server_tool_use"||n.type==="mcp_tool_use"}var zc=(()=>{class n{constructor(e,t){q.add(this),this.messages=[],this.receivedMessages=[],ke.set(this,void 0),Qe.set(this,null),this.controller=new AbortController,kt.set(this,void 0),_n.set(this,()=>{}),St.set(this,()=>{}),xt.set(this,void 0),gn.set(this,()=>{}),Rt.set(this,()=>{}),ue.set(this,{}),At.set(this,!1),mn.set(this,!1),wn.set(this,!1),Ie.set(this,!1),yn.set(this,void 0),bn.set(this,void 0),vn.set(this,void 0),Et.set(this,void 0),Tt.set(this,s=>{if(w(this,mn,!0),lt(s)&&(s=new oe),s instanceof oe)return w(this,wn,!0),this._emit("abort",s);if(s instanceof S)return this._emit("error",s);if(s instanceof Error){const i=new S(s.message);return i.cause=s,this._emit("error",i)}return this._emit("error",new S(String(s)))}),w(this,kt,new Promise((s,i)=>{w(this,_n,s,"f"),w(this,St,i,"f")})),w(this,xt,new Promise((s,i)=>{w(this,gn,s,"f"),w(this,Rt,i,"f")})),o(this,kt,"f").catch(()=>{}),o(this,xt,"f").catch(()=>{}),w(this,Qe,e),w(this,Et,t?.logger??console)}get response(){return o(this,yn,"f")}get request_id(){return o(this,bn,"f")}get workspace_id(){return o(this,vn,"f")}async withResponse(){w(this,Ie,!0);const e=await o(this,kt,"f");if(!e)throw new Error("Could not resolve a `Response` object");return{data:this,response:e,request_id:e.headers.get("request-id"),workspace_id:e.headers.get("anthropic-workspace-id")}}static fromReadableStream(e){const t=new n(null);return t._run(()=>t._fromReadableStream(e)),t}static createMessage(e,t,s,{logger:i}={}){const a=new n(t,{logger:i});for(const c of t.messages)a._addMessageParam(c);return w(a,Qe,{...t,stream:!0}),a._run(()=>a._createMessage(e,{...t,stream:!0},{...s,headers:{...s?.headers,[os]:"stream"}})),a}_run(e){e().then(()=>{this._emitFinal(),this._emit("end")},o(this,Tt,"f"))}_addMessageParam(e){this.messages.push(e)}_addMessage(e,t=!0){this.receivedMessages.push(e),t&&this._emit("message",e)}async _createMessage(e,t,s){const i=s?.signal;let a;i&&(i.aborted&&this.controller.abort(),a=this.controller.abort.bind(this.controller),i.addEventListener("abort",a));try{o(this,q,"m",ir).call(this);const{response:c,data:u}=await e.create({...t,stream:!0},{...s,signal:this.controller.signal}).withResponse();this._connected(c);for await(const l of u)o(this,q,"m",ar).call(this,l);if(u.controller.signal?.aborted)throw new oe;o(this,q,"m",or).call(this)}finally{i&&a&&i.removeEventListener("abort",a)}}_connected(e){this.ended||(w(this,yn,e),w(this,bn,e?.headers.get("request-id")),w(this,vn,e?.headers.get("anthropic-workspace-id")),o(this,_n,"f").call(this,e),this._emit("connect"))}get ended(){return o(this,At,"f")}get errored(){return o(this,mn,"f")}get aborted(){return o(this,wn,"f")}abort(){this.controller.abort()}on(e,t){return(o(this,ue,"f")[e]||(o(this,ue,"f")[e]=[])).push({listener:t}),this}off(e,t){const s=o(this,ue,"f")[e];if(!s)return this;const i=s.findIndex(a=>a.listener===t);return i>=0&&s.splice(i,1),this}once(e,t){return(o(this,ue,"f")[e]||(o(this,ue,"f")[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,s)=>{w(this,Ie,!0),e!=="error"&&this.once("error",s),this.once(e,t)})}async done(){w(this,Ie,!0),await o(this,xt,"f")}get currentMessage(){return o(this,ke,"f")}async finalMessage(){return await this.done(),o(this,q,"m",sr).call(this)}async finalText(){return await this.done(),o(this,q,"m",mi).call(this)}_emit(e,...t){if(o(this,At,"f"))return;e==="end"&&(w(this,At,!0),o(this,gn,"f").call(this));const s=o(this,ue,"f")[e];if(s&&(o(this,ue,"f")[e]=s.filter(i=>!i.once),s.forEach(({listener:i})=>i(...t))),e==="abort"){const i=t[0];!o(this,Ie,"f")&&!s?.length&&Promise.reject(i),o(this,St,"f").call(this,i),o(this,Rt,"f").call(this,i),this._emit("end");return}if(e==="error"){const i=t[0];!o(this,Ie,"f")&&!s?.length&&Promise.reject(i),o(this,St,"f").call(this,i),o(this,Rt,"f").call(this,i),this._emit("end")}}_emitFinal(){this.receivedMessages.at(-1)&&this._emit("finalMessage",o(this,q,"m",sr).call(this))}async _fromReadableStream(e,t){const s=t?.signal;let i;s&&(s.aborted&&this.controller.abort(),i=this.controller.abort.bind(this.controller),s.addEventListener("abort",i));try{o(this,q,"m",ir).call(this),this._connected(null);const a=dt.fromReadableStream(e,this.controller);for await(const c of a)o(this,q,"m",ar).call(this,c);if(a.controller.signal?.aborted)throw new oe;o(this,q,"m",or).call(this)}finally{s&&i&&s.removeEventListener("abort",i)}}[(ke=new WeakMap,Qe=new WeakMap,kt=new WeakMap,_n=new WeakMap,St=new WeakMap,xt=new WeakMap,gn=new WeakMap,Rt=new WeakMap,ue=new WeakMap,At=new WeakMap,mn=new WeakMap,wn=new WeakMap,Ie=new WeakMap,yn=new WeakMap,bn=new WeakMap,vn=new WeakMap,Et=new WeakMap,Tt=new WeakMap,q=new WeakSet,sr=function(){if(this.receivedMessages.length===0)throw new S("stream ended without producing a Message with role=assistant");return this.receivedMessages.at(-1)},mi=function(){if(this.receivedMessages.length===0)throw new S("stream ended without producing a Message with role=assistant");const t=this.receivedMessages.at(-1).content.filter(s=>s.type==="text").map(s=>s.text);if(t.length===0)throw new S("stream ended without producing a content block with type=text");return t.join(" ")},ir=function(){this.ended||w(this,ke,void 0)},ar=function(t){if(this.ended)return;const s=o(this,q,"m",wi).call(this,t);switch(this._emit("streamEvent",t,s),t.type){case"content_block_delta":{const i=s.content.at(-1);switch(t.delta.type){case"text_delta":{i.type==="text"&&this._emit("text",t.delta.text,i.text||"");break}case"citations_delta":{i.type==="text"&&this._emit("citation",t.delta.citation,i.citations??[]);break}case"input_json_delta":{if(lr(i)&&o(this,ue,"f").inputJson?.length){let a;try{a=i.input}catch(c){o(this,Tt,"f").call(this,o(this,q,"m",cr).call(this,i,c));break}this._emit("inputJson",t.delta.partial_json,a)}break}case"thinking_delta":{i.type==="thinking"&&this._emit("thinking",t.delta.thinking,i.thinking);break}case"signature_delta":{i.type==="thinking"&&this._emit("signature",i.signature);break}case"compaction_delta":{i.type==="compaction"&&i.content&&this._emit("compaction",i.content);break}default:t.delta}break}case"message_stop":{this._addMessageParam(s),this._addMessage(gi(s,o(this,Qe,"f"),{logger:o(this,Et,"f")}),!0);break}case"content_block_stop":{this._emit("contentBlock",s.content.at(-1));break}case"message_start":{w(this,ke,s);break}}},or=function(){if(this.ended)throw new S("stream has ended, this shouldn't happen");const t=o(this,ke,"f");if(!t)throw new S("request ended without sending any chunks");return w(this,ke,void 0),gi(t,o(this,Qe,"f"),{logger:o(this,Et,"f")})},wi=function(t){let s=o(this,ke,"f");if(t.type==="message_start"){if(s)throw new S(`Unexpected event order, got ${t.type} before receiving "message_stop"`);return t.message}if(!s)throw new S(`Unexpected event order, got ${t.type} before "message_start"`);switch(t.type){case"message_stop":return s;case"message_delta":return s.stop_reason=t.delta.stop_reason,s.stop_sequence=t.delta.stop_sequence,s.stop_details=t.delta.stop_details,s.usage.output_tokens=t.usage.output_tokens,t.delta.container!=null&&(s.container=t.delta.container),t.context_management!=null&&(s.context_management=t.context_management),t.input_transformations!=null&&(s.input_transformations=t.input_transformations),t.usage.input_tokens!=null&&(s.usage.input_tokens=t.usage.input_tokens),t.usage.cache_creation_input_tokens!=null&&(s.usage.cache_creation_input_tokens=t.usage.cache_creation_input_tokens),t.usage.cache_read_input_tokens!=null&&(s.usage.cache_read_input_tokens=t.usage.cache_read_input_tokens),t.usage.server_tool_use!=null&&(s.usage.server_tool_use=t.usage.server_tool_use),t.usage.iterations!=null&&(s.usage.iterations=t.usage.iterations),t.usage.fallback_credit!=null&&(s.usage.fallback_credit=t.usage.fallback_credit),t.usage.output_tokens_details!=null&&(s.usage.output_tokens_details=t.usage.output_tokens_details),s;case"content_block_start":return s.content.push(t.content_block),t.content_block.type==="fallback"&&(s.model=t.content_block.to.model),s;case"content_block_delta":{const i=s.content.at(t.index);switch(t.delta.type){case"text_delta":{i?.type==="text"&&(s.content[t.index]={...i,text:(i.text||"")+t.delta.text});break}case"citations_delta":{i?.type==="text"&&(s.content[t.index]={...i,citations:[...i.citations??[],t.delta.citation]});break}case"input_json_delta":{if(i&&lr(i)){const a=(i[ct]||"")+t.delta.partial_json;s.content[t.index]=Wc(i,a)}break}case"thinking_delta":{i?.type==="thinking"&&(s.content[t.index]={...i,thinking:i.thinking+t.delta.thinking});break}case"signature_delta":{i?.type==="thinking"&&(s.content[t.index]={...i,signature:t.delta.signature});break}case"compaction_delta":{if(i?.type==="compaction"){const a={...i,content:t.delta.content};"encrypted_content"in t.delta&&(a.encrypted_content=t.delta.encrypted_content),s.content[t.index]=a}break}default:t.delta}return s}case"content_block_stop":{const i=s.content.at(t.index);if(i&&lr(i)&&ct in i){let a;try{a=i.input}catch(c){a={},o(this,Tt,"f").call(this,o(this,q,"m",cr).call(this,i,c))}Object.defineProperty(i,"input",{value:a,enumerable:!0,configurable:!0,writable:!0})}return s}}},cr=function(t,s){const i=t[ct];return new S(`Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${s}. JSON: ${i}`)},Symbol.asyncIterator)](){const e=[],t=[];let s=!1;return this.on("streamEvent",i=>{const a=t.shift();a?a.resolve(i):e.push(i)}),this.on("end",()=>{s=!0;for(const i of t)i.resolve(void 0);t.length=0}),this.on("abort",i=>{s=!0;for(const a of t)a.reject(i);t.length=0}),this.on("error",i=>{s=!0;for(const a of t)a.reject(i);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:s?{value:void 0,done:!0}:new Promise((a,c)=>t.push({resolve:a,reject:c})).then(a=>a?{value:a,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new dt(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}}return n})();let yi=class extends v{retrieve(r,e){return this._client.get(h`/v1/organizations/api_keys/${r}?beta=true`,e)}update(r,e,t){return this._client.post(h`/v1/organizations/api_keys/${r}?beta=true`,{body:e,...t})}list(r={},e){return this._client.getAPIList("/v1/organizations/api_keys?beta=true",X,{query:r,...e})}};class bi extends v{list(r,e){return this._client.getAPIList("/v1/organizations/analytics/artifacts?beta=true",A,{query:r,...e})}}class vi extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/analytics/connectors?beta=true",A,{query:r,...e})}}class ki extends v{list(r,e){return this._client.getAPIList("/v1/organizations/analytics/cost_report?beta=true",A,{query:r,...e})}}let Si=class extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/analytics/plugins?beta=true",A,{query:r,...e})}},xi=class extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/analytics/skills?beta=true",A,{query:r,...e})}};class Ri extends v{list(r,e){return this._client.getAPIList("/v1/organizations/analytics/summaries?beta=true",A,{query:r,...e})}}class Ai extends v{list(r,e){return this._client.getAPIList("/v1/organizations/analytics/usage_report?beta=true",A,{query:r,...e})}}class Ei extends v{list(r,e){return this._client.getAPIList("/v1/organizations/analytics/user_cost_report?beta=true",A,{query:r,...e})}}class Ti extends v{list(r,e){return this._client.getAPIList("/v1/organizations/analytics/user_usage_report?beta=true",A,{query:r,...e})}}let $i=class extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/analytics/users?beta=true",A,{query:r,...e})}};class Ii extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/analytics/apps/chat/projects?beta=true",A,{query:r,...e})}}var Pi=(()=>{class n extends v{constructor(){super(...arguments),this.projects=new Ii(this._client)}}return n.Projects=Ii,n})(),Mi=(()=>{class n extends v{constructor(){super(...arguments),this.chat=new Pi(this._client)}}return n.Chat=Pi,n})(),Oi=(()=>{class n extends v{constructor(){super(...arguments),this.summaries=new Ri(this._client),this.users=new $i(this._client),this.apps=new Mi(this._client),this.connectors=new vi(this._client),this.plugins=new Si(this._client),this.skills=new xi(this._client),this.artifacts=new bi(this._client),this.usageReport=new Ai(this._client),this.userUsageReport=new Ti(this._client),this.costReport=new ki(this._client),this.userCostReport=new Ei(this._client)}}return n.Summaries=Ri,n.Users=$i,n.Apps=Mi,n.Connectors=vi,n.Plugins=Si,n.Skills=xi,n.Artifacts=bi,n.UsageReport=Ai,n.UserUsageReport=Ti,n.CostReport=ki,n.UserCostReport=Ei,n})();let Ci=class extends v{retrieve(r){return this._client.get("/v1/organizations/compliance_settings?beta=true",r)}update(r,e){return this._client.post("/v1/organizations/compliance_settings?beta=true",{body:r,...e})}},Li=class extends v{create(r,e){return this._client.post("/v1/organizations/external_keys?beta=true",{body:r,...e})}retrieve(r,e){return this._client.get(h`/v1/organizations/external_keys/${r}?beta=true`,e)}update(r,e,t){return this._client.post(h`/v1/organizations/external_keys/${r}?beta=true`,{body:e,...t})}list(r={},e){return this._client.getAPIList("/v1/organizations/external_keys?beta=true",A,{query:r,...e})}delete(r,e){return this._client.delete(h`/v1/organizations/external_keys/${r}?beta=true`,e)}validate(r,e){return this._client.post(h`/v1/organizations/external_keys/${r}/validate?beta=true`,e)}},Ni=class extends v{create(r,e){const{betas:t,...s}=r;return this._client.post("/v1/organizations/federation_issuers?beta=true",{body:s,...e,headers:f([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0},e?.headers])})}retrieve(r,e={},t){const{betas:s}=e??{};return this._client.get(h`/v1/organizations/federation_issuers/${r}?beta=true`,{...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}update(r,e,t){const{betas:s,...i}=e;return this._client.post(h`/v1/organizations/federation_issuers/${r}?beta=true`,{body:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}list(r={},e){const{betas:t,...s}=r??{};return this._client.getAPIList("/v1/organizations/federation_issuers?beta=true",A,{query:s,...e,headers:f([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0},e?.headers])})}archive(r,e={},t){const{betas:s}=e??{};return this._client.post(h`/v1/organizations/federation_issuers/${r}/archive?beta=true`,{...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}},Bi=class extends v{list(r,e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList(h`/v1/organizations/federation_rules/${r}/workspaces?beta=true`,A,{query:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}add(r,e,t){const{betas:s,...i}=e;return this._client.post(h`/v1/organizations/federation_rules/${r}/workspaces?beta=true`,{body:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}remove(r,e,t){const{federation_rule_id:s,betas:i}=e;return this._client.delete(h`/v1/organizations/federation_rules/${s}/workspaces/${r}?beta=true`,{...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}};var Di=(()=>{class n extends v{constructor(){super(...arguments),this.workspaces=new Bi(this._client)}create(e,t){const{betas:s,...i}=e;return this._client.post("/v1/organizations/federation_rules?beta=true",{body:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i}=t??{};return this._client.get(h`/v1/organizations/federation_rules/${e}?beta=true`,{...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},s?.headers])})}update(e,t,s){const{betas:i,...a}=t;return this._client.post(h`/v1/organizations/federation_rules/${e}?beta=true`,{body:a,...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},s?.headers])})}list(e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList("/v1/organizations/federation_rules?beta=true",A,{query:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}archive(e,t={},s){const{betas:i}=t??{};return this._client.post(h`/v1/organizations/federation_rules/${e}/archive?beta=true`,{...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},s?.headers])})}}return n.Workspaces=Bi,n})(),Ui=(()=>{class n extends v{constructor(){super(...arguments),this.issuers=new Ni(this._client),this.rules=new Di(this._client)}}return n.Issuers=Ni,n.Rules=Di,n})();let Hi=class extends v{create(r,e){return this._client.post("/v1/organizations/invites?beta=true",{body:r,...e})}retrieve(r,e){return this._client.get(h`/v1/organizations/invites/${r}?beta=true`,e)}list(r={},e){return this._client.getAPIList("/v1/organizations/invites?beta=true",X,{query:r,...e})}delete(r,e){return this._client.delete(h`/v1/organizations/invites/${r}?beta=true`,e)}};class Wi extends v{retrieve(r,e={},t){const{betas:s,...i}=e??{};return this._client.get(h`/v1/organizations/plugin_marketplaces/${r}?beta=true`,{query:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}update(r,e,t){const{betas:s,...i}=e;return this._client.post(h`/v1/organizations/plugin_marketplaces/${r}?beta=true`,{body:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}list(r={},e){const{betas:t,...s}=r??{};return this._client.getAPIList("/v1/organizations/plugin_marketplaces?beta=true",A,{query:s,...e,headers:f([{"anthropic-beta":[...t??[],"ce-plugins-2026-09-01"].toString()},e?.headers])})}validateArchive(r,e){const{betas:t,...s}=r;return this._client.post("/v1/organizations/plugin_marketplaces/validate_archive?beta=true",me({body:s,...e,headers:f([{"anthropic-beta":[...t??[],"ce-plugins-2026-09-01"].toString()},e?.headers])},this._client))}validateRepository(r,e){const{betas:t,...s}=r;return this._client.post("/v1/organizations/plugin_marketplaces/validate_repository?beta=true",{body:s,...e,headers:f([{"anthropic-beta":[...t??[],"ce-plugins-2026-09-01"].toString()},e?.headers])})}}let zi=class extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/rate_limits?beta=true",A,{query:r,...e})}},ji=class extends v{retrieve(r,e){return this._client.get(h`/v1/organizations/users/${r}?beta=true`,e)}update(r,e,t){return this._client.post(h`/v1/organizations/users/${r}?beta=true`,{body:e,...t})}list(r={},e){return this._client.getAPIList("/v1/organizations/users?beta=true",X,{query:r,...e})}remove(r,e){return this._client.delete(h`/v1/organizations/users/${r}?beta=true`,e)}};class Fi extends v{list(r,e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList(h`/v1/organizations/plugins/${r}/installation_settings?beta=true`,A,{query:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}remove(r,e,t){const{plugin_id:s,betas:i}=e;return this._client.delete(h`/v1/organizations/plugins/${s}/installation_settings/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}set(r,e,t){const{plugin_id:s,betas:i,...a}=e;return this._client.post(h`/v1/organizations/plugins/${s}/installation_settings/${r}?beta=true`,{body:a,...t,headers:f([{"anthropic-beta":[...i??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}}class qi extends v{list(r,e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList(h`/v1/organizations/plugins/${r}/shares?beta=true`,A,{query:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}}let Ki=class extends v{create(r,e,t){const{betas:s,...i}=e;return this._client.post(h`/v1/organizations/plugins/${r}/versions?beta=true`,me({body:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])},this._client))}retrieve(r,e,t){const{plugin_id:s,betas:i,...a}=e;return this._client.get(h`/v1/organizations/plugins/${s}/versions/${r}?beta=true`,{query:a,...t,headers:f([{"anthropic-beta":[...i??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}list(r,e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList(h`/v1/organizations/plugins/${r}/versions?beta=true`,A,{query:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}download(r,e,t){const{plugin_id:s,betas:i,...a}=e;return this._client.get(h`/v1/organizations/plugins/${s}/versions/${r}/content?beta=true`,{query:a,...t,headers:f([{"anthropic-beta":[...i??[],"ce-plugins-2026-09-01"].toString(),Accept:"application/binary"},t?.headers]),__binaryResponse:!0})}};var Vi=(()=>{class n extends v{constructor(){super(...arguments),this.versions=new Ki(this._client),this.installationSettings=new Fi(this._client),this.shares=new qi(this._client)}create(e,t){const{betas:s,...i}=e;return this._client.post("/v1/organizations/plugins?beta=true",me({body:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])},this._client))}retrieve(e,t={},s){const{betas:i,...a}=t??{};return this._client.get(h`/v1/organizations/plugins/${e}?beta=true`,{query:a,...s,headers:f([{"anthropic-beta":[...i??[],"ce-plugins-2026-09-01"].toString()},s?.headers])})}update(e,t,s){const{betas:i,...a}=t;return this._client.post(h`/v1/organizations/plugins/${e}?beta=true`,{body:a,...s,headers:f([{"anthropic-beta":[...i??[],"ce-plugins-2026-09-01"].toString()},s?.headers])})}list(e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList("/v1/organizations/plugins?beta=true",A,{query:i,...t,headers:f([{"anthropic-beta":[...s??[],"ce-plugins-2026-09-01"].toString()},t?.headers])})}delete(e,t={},s){const{betas:i}=t??{};return this._client.delete(h`/v1/organizations/plugins/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"ce-plugins-2026-09-01"].toString()},s?.headers])})}}return n.Versions=Ki,n.InstallationSettings=Fi,n.Shares=qi,n})();let Ji=class extends v{list(r,e={},t){return this._client.getAPIList(h`/v1/organizations/rbac_groups/${r}/members?beta=true`,A,{query:e,...t})}add(r,e,t){return this._client.post(h`/v1/organizations/rbac_groups/${r}/members?beta=true`,{body:e,...t})}remove(r,e,t){const{rbac_group_id:s}=e;return this._client.delete(h`/v1/organizations/rbac_groups/${s}/members/${r}?beta=true`,t)}};var Xi=(()=>{class n extends v{constructor(){super(...arguments),this.members=new Ji(this._client)}create(e,t){return this._client.post("/v1/organizations/rbac_groups?beta=true",{body:e,...t})}retrieve(e,t){return this._client.get(h`/v1/organizations/rbac_groups/${e}?beta=true`,t)}update(e,t,s){return this._client.post(h`/v1/organizations/rbac_groups/${e}?beta=true`,{body:t,...s})}list(e={},t){return this._client.getAPIList("/v1/organizations/rbac_groups?beta=true",A,{query:e,...t})}delete(e,t){return this._client.delete(h`/v1/organizations/rbac_groups/${e}?beta=true`,t)}}return n.Members=Ji,n})();class Gi extends v{list(r,e={},t){return this._client.getAPIList(h`/v1/organizations/rbac_roles/${r}/permissions?beta=true`,A,{query:e,...t})}}var Qi=(()=>{class n extends v{constructor(){super(...arguments),this.permissions=new Gi(this._client)}retrieve(e,t){return this._client.get(h`/v1/organizations/rbac_roles/${e}?beta=true`,t)}list(e={},t){return this._client.getAPIList("/v1/organizations/rbac_roles?beta=true",A,{query:e,...t})}}return n.Permissions=Gi,n})();let Yi=class extends v{list(r,e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList(h`/v1/organizations/service_accounts/${r}/workspaces?beta=true`,A,{query:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}add(r,e,t){const{betas:s,...i}=e;return this._client.post(h`/v1/organizations/service_accounts/${r}/workspaces?beta=true`,{body:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}remove(r,e,t){const{service_account_id:s,betas:i}=e;return this._client.delete(h`/v1/organizations/service_accounts/${s}/workspaces/${r}?beta=true`,{...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}};var Zi=(()=>{class n extends v{constructor(){super(...arguments),this.workspaces=new Yi(this._client)}create(e,t){const{betas:s,...i}=e;return this._client.post("/v1/organizations/service_accounts?beta=true",{body:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i}=t??{};return this._client.get(h`/v1/organizations/service_accounts/${e}?beta=true`,{...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},s?.headers])})}update(e,t,s){const{betas:i,...a}=t;return this._client.post(h`/v1/organizations/service_accounts/${e}?beta=true`,{body:a,...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},s?.headers])})}list(e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList("/v1/organizations/service_accounts?beta=true",A,{query:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}archive(e,t={},s){const{betas:i}=t??{};return this._client.post(h`/v1/organizations/service_accounts/${e}/archive?beta=true`,{...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},s?.headers])})}}return n.Workspaces=Yi,n})();class ea extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/spend_limits/effective?beta=true",A,{query:r,...e})}}class ta extends v{retrieve(r,e){return this._client.get(h`/v1/organizations/spend_limit_increase_requests/${r}?beta=true`,e)}list(r={},e){return this._client.getAPIList("/v1/organizations/spend_limit_increase_requests?beta=true",A,{query:r,...e})}approve(r,e,t){return this._client.post(h`/v1/organizations/spend_limit_increase_requests/${r}/approve?beta=true`,{body:e,...t})}deny(r,e,t){return this._client.post(h`/v1/organizations/spend_limit_increase_requests/${r}/deny?beta=true`,{body:e,...t})}}var na=(()=>{class n extends v{constructor(){super(...arguments),this.effective=new ea(this._client),this.increaseRequests=new ta(this._client)}retrieve(e,t){return this._client.get(h`/v1/organizations/spend_limits/${e}?beta=true`,t)}list(e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList("/v1/organizations/spend_limits?beta=true",A,{query:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}delete(e,t){return this._client.delete(h`/v1/organizations/spend_limits/${e}?beta=true`,t)}set(e,t){return this._client.post("/v1/organizations/spend_limits?beta=true",{body:e,...t})}}return n.Effective=ea,n.IncreaseRequests=ta,n})();let ra=class extends v{retrieve(r,e,t){const{workspace_id:s}=e;return this._client.get(h`/v1/organizations/workspaces/${s}/members/${r}?beta=true`,t)}update(r,e,t){const{workspace_id:s,...i}=e;return this._client.post(h`/v1/organizations/workspaces/${s}/members/${r}?beta=true`,{body:i,...t})}list(r,e={},t){return this._client.getAPIList(h`/v1/organizations/workspaces/${r}/members?beta=true`,X,{query:e,...t})}add(r,e,t){return this._client.post(h`/v1/organizations/workspaces/${r}/members?beta=true`,{body:e,...t})}remove(r,e,t){const{workspace_id:s}=e;return this._client.delete(h`/v1/organizations/workspaces/${s}/members/${r}?beta=true`,t)}},sa=class extends v{list(r,e={},t){return this._client.getAPIList(h`/v1/organizations/workspaces/${r}/rate_limits?beta=true`,A,{query:e,...t})}},ia=class extends v{retrieve(r,e,t){const{workspace_id:s,betas:i}=e;return this._client.get(h`/v1/organizations/workspaces/${s}/service_accounts/${r}?beta=true`,{...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}update(r,e,t){const{workspace_id:s,betas:i,...a}=e;return this._client.post(h`/v1/organizations/workspaces/${s}/service_accounts/${r}?beta=true`,{body:a,...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}list(r,e={},t){const{betas:s,...i}=e??{};return this._client.getAPIList(h`/v1/organizations/workspaces/${r}/service_accounts?beta=true`,A,{query:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}add(r,e,t){const{betas:s,...i}=e;return this._client.post(h`/v1/organizations/workspaces/${r}/service_accounts?beta=true`,{body:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}remove(r,e,t){const{workspace_id:s,betas:i}=e;return this._client.delete(h`/v1/organizations/workspaces/${s}/service_accounts/${r}?beta=true`,{...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}};var aa=(()=>{class n extends v{constructor(){super(...arguments),this.rateLimits=new sa(this._client),this.members=new ra(this._client),this.serviceAccounts=new ia(this._client)}create(e,t){const{betas:s,...i}=e;return this._client.post("/v1/organizations/workspaces?beta=true",{body:i,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0},t?.headers])})}retrieve(e,t){return this._client.get(h`/v1/organizations/workspaces/${e}?beta=true`,t)}update(e,t,s){return this._client.post(h`/v1/organizations/workspaces/${e}?beta=true`,{body:t,...s})}list(e={},t){return this._client.getAPIList("/v1/organizations/workspaces?beta=true",X,{query:e,...t})}archive(e,t){return this._client.post(h`/v1/organizations/workspaces/${e}/archive?beta=true`,t)}}return n.RateLimits=sa,n.Members=ra,n.ServiceAccounts=ia,n})(),oa=(()=>{class n extends v{constructor(){super(...arguments),this.apiKeys=new yi(this._client),this.externalKeys=new Li(this._client),this.federation=new Ui(this._client),this.invites=new Hi(this._client),this.serviceAccounts=new Zi(this._client),this.users=new ji(this._client),this.workspaces=new aa(this._client),this.rateLimits=new zi(this._client),this.complianceSettings=new Ci(this._client),this.analytics=new Oi(this._client),this.spendLimits=new na(this._client),this.rbacGroups=new Xi(this._client),this.rbacRoles=new Qi(this._client),this.plugins=new Vi(this._client),this.pluginMarketplaces=new Wi(this._client)}retrieve(e){return this._client.get("/v1/organizations/me?beta=true",e)}}return n.APIKeys=yi,n.ExternalKeys=Li,n.Federation=Ui,n.Invites=Hi,n.ServiceAccounts=Zi,n.Users=ji,n.Workspaces=aa,n.RateLimits=zi,n.ComplianceSettings=Ci,n.Analytics=Oi,n.SpendLimits=na,n.RBACGroups=Xi,n.RBACRoles=Qi,n.Plugins=Vi,n.PluginMarketplaces=Wi,n})(),ca=(()=>{class n extends v{list(e,t={},s){const{betas:i,workspace_id:a,...c}=t??{};return this._client.getAPIList(h`/v1/sessions/${e}/events?beta=true`,A,{query:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}send(e,t,s){const{betas:i,workspace_id:a,...c}=t;return this._client.post(h`/v1/sessions/${e}/events?beta=true`,{body:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}stream(e,t={},s){const{betas:i,workspace_id:a,...c}=t??{};return this._client.get(h`/v1/sessions/${e}/events/stream?beta=true`,{query:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers]),stream:!0})}toolRunner(e,t){return new zr(e,{...t,client:this._client})}}return n.SessionToolRunner=zr,n})();class la extends v{retrieve(r,e,t){const{session_id:s,betas:i,workspace_id:a}=e;return this._client.get(h`/v1/sessions/${s}/resources/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}update(r,e,t){const{session_id:s,betas:i,workspace_id:a,...c}=e;return this._client.post(h`/v1/sessions/${s}/resources/${r}?beta=true`,{body:c,...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}list(r,e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList(h`/v1/sessions/${r}/resources?beta=true`,A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(r,e,t){const{session_id:s,betas:i,workspace_id:a}=e;return this._client.delete(h`/v1/sessions/${s}/resources/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}add(r,e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post(h`/v1/sessions/${r}/resources?beta=true`,{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}}class ua extends v{list(r,e,t){const{session_id:s,betas:i,workspace_id:a,...c}=e;return this._client.getAPIList(h`/v1/sessions/${s}/threads/${r}/events?beta=true`,A,{query:c,...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}stream(r,e,t){const{session_id:s,betas:i,workspace_id:a,...c}=e;return this._client.get(h`/v1/sessions/${s}/threads/${r}/stream?beta=true`,{query:c,...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers]),stream:!0})}}var da=(()=>{class n extends v{constructor(){super(...arguments),this.events=new ua(this._client)}retrieve(e,t,s){const{session_id:i,betas:a,workspace_id:c}=t;return this._client.get(h`/v1/sessions/${i}/threads/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...a??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},s?.headers])})}list(e,t={},s){const{betas:i,workspace_id:a,...c}=t??{};return this._client.getAPIList(h`/v1/sessions/${e}/threads?beta=true`,A,{query:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}archive(e,t,s){const{session_id:i,betas:a,workspace_id:c}=t;return this._client.post(h`/v1/sessions/${i}/threads/${e}/archive?beta=true`,{...s,headers:f([{"anthropic-beta":[...a??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},s?.headers])})}}return n.Events=ua,n})(),ha=(()=>{class n extends v{constructor(){super(...arguments),this.events=new ca(this._client),this.resources=new la(this._client),this.threads=new da(this._client)}create(e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post("/v1/sessions?beta=true",{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.get(h`/v1/sessions/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}update(e,t,s){const{betas:i,workspace_id:a,...c}=t;return this._client.post(h`/v1/sessions/${e}?beta=true`,{body:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}list(e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList("/v1/sessions?beta=true",hu,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.delete(h`/v1/sessions/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}archive(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.post(h`/v1/sessions/${e}/archive?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}}return n.Events=ca,n.Resources=la,n.Threads=da,n})();let fa=class extends v{create(r,e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post(h`/v1/skills/${r}/versions?beta=true`,me({body:a,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])},this._client,!1))}retrieve(r,e,t){const{skill_id:s,betas:i,workspace_id:a}=e;return this._client.get(h`/v1/skills/${s}/versions/${r}?beta=true`,{...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}list(r,e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList(h`/v1/skills/${r}/versions?beta=true`,A,{query:a,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(r,e,t){const{skill_id:s,betas:i,workspace_id:a}=e;return this._client.delete(h`/v1/skills/${s}/versions/${r}?beta=true`,{...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}download(r,e,t){const{skill_id:s,betas:i,workspace_id:a}=e;return this._client.get(h`/v1/skills/${s}/versions/${r}/content?beta=true`,{...t,headers:f([{Accept:"application/binary",...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers]),__binaryResponse:!0})}};var pa=(()=>{class n extends v{constructor(){super(...arguments),this.versions=new fa(this._client)}create(e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post("/v1/skills?beta=true",me({body:a,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])},this._client,!1))}retrieve(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.get(h`/v1/skills/${e}?beta=true`,{...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}list(e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList("/v1/skills?beta=true",A,{query:a,...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.delete(h`/v1/skills/${e}?beta=true`,{...s,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}}return n.Versions=fa,n})();class _a extends v{create(r,e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post(h`/v1/tunnels/${r}/certificates?beta=true`,{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"mcp-tunnels-2026-06-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(r,e,t){const{tunnel_id:s,betas:i,workspace_id:a}=e;return this._client.get(h`/v1/tunnels/${s}/certificates/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}list(r,e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList(h`/v1/tunnels/${r}/certificates?beta=true`,A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"mcp-tunnels-2026-06-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}archive(r,e,t){const{tunnel_id:s,betas:i,workspace_id:a}=e;return this._client.post(h`/v1/tunnels/${s}/certificates/${r}/archive?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}}var ga=(()=>{class n extends v{constructor(){super(...arguments),this.certificates=new _a(this._client)}create(e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post("/v1/tunnels?beta=true",{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"mcp-tunnels-2026-06-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.get(h`/v1/tunnels/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}list(e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList("/v1/tunnels?beta=true",A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"mcp-tunnels-2026-06-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}archive(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.post(h`/v1/tunnels/${e}/archive?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}revealToken(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.post(h`/v1/tunnels/${e}/reveal_token?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}rotateToken(e,t,s){const{betas:i,workspace_id:a,...c}=t;return this._client.post(h`/v1/tunnels/${e}/rotate_token?beta=true`,{body:c,...s,headers:f([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}}return n.Certificates=_a,n})();class ma extends v{create(r,e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post(h`/v1/vaults/${r}/credentials?beta=true`,{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(r,e,t){const{vault_id:s,betas:i,workspace_id:a}=e;return this._client.get(h`/v1/vaults/${s}/credentials/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}update(r,e,t){const{vault_id:s,betas:i,workspace_id:a,...c}=e;return this._client.post(h`/v1/vaults/${s}/credentials/${r}?beta=true`,{body:c,...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}list(r,e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList(h`/v1/vaults/${r}/credentials?beta=true`,A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(r,e,t){const{vault_id:s,betas:i,workspace_id:a}=e;return this._client.delete(h`/v1/vaults/${s}/credentials/${r}?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}archive(r,e,t){const{vault_id:s,betas:i,workspace_id:a}=e;return this._client.post(h`/v1/vaults/${s}/credentials/${r}/archive?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}mcpOAuthValidate(r,e,t){const{vault_id:s,betas:i,workspace_id:a}=e;return this._client.post(h`/v1/vaults/${s}/credentials/${r}/mcp_oauth_validate?beta=true`,{...t,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},t?.headers])})}}var wa=(()=>{class n extends v{constructor(){super(...arguments),this.credentials=new ma(this._client)}create(e,t){const{betas:s,workspace_id:i,...a}=e;return this._client.post("/v1/vaults?beta=true",{body:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.get(h`/v1/vaults/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}update(e,t,s){const{betas:i,workspace_id:a,...c}=t;return this._client.post(h`/v1/vaults/${e}?beta=true`,{body:c,...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}list(e={},t){const{betas:s,workspace_id:i,...a}=e??{};return this._client.getAPIList("/v1/vaults?beta=true",A,{query:a,...t,headers:f([{"anthropic-beta":[...s??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.delete(h`/v1/vaults/${e}?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}archive(e,t={},s){const{betas:i,workspace_id:a}=t??{};return this._client.post(h`/v1/vaults/${e}/archive?beta=true`,{...s,headers:f([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...a!=null?{"anthropic-workspace-id":a}:void 0},s?.headers])})}}return n.Credentials=ma,n})(),_e,kn,Pe,Ye,Sn,Me,Ze,xn,ya,Rn,An,ba=(()=>{class n extends zc{constructor(e,t){super(e),_e.add(this),kn.set(this,void 0),Pe.set(this,0),Ye.set(this,[]),Sn.set(this,[]),Me.set(this,void 0),Ze.set(this,[]),xn.set(this,!1),w(this,kn,t)}get toolCalls(){return o(this,Sn,"f")}static start(e,t,s,i){const a=new n({...t,stream:!0},i);for(const c of t.messages)a._addMessageParam(c);return a._run(()=>a._createMessage(e,{...t,stream:!0},{...s,headers:{...s?.headers,[os]:"stream"}})),a}_emit(e,...t){var s;if(e!=="streamEvent"||this.ended){super._emit(e,...t);return}w(this,Pe,(s=o(this,Pe,"f"),s++,s));const[i,a]=t,c=i.type==="content_block_stop"?a.content[i.index]:void 0,u=c?.type==="tool_use"?c:void 0;u&&o(this,Sn,"f").push(u),super._emit(e,...t),o(this,_e,"m",ya).call(this,i,u),o(this,_e,"m",Rn).call(this)}[(kn=new WeakMap,Pe=new WeakMap,Ye=new WeakMap,Sn=new WeakMap,Me=new WeakMap,Ze=new WeakMap,xn=new WeakMap,_e=new WeakSet,Symbol.asyncIterator)](){const e=super[Symbol.asyncIterator](),t={handled:o(this,Pe,"f")};o(this,Ye,"f").push(t);let s=!1;return{next:async()=>{s&&(s=!1,t.handled++,o(this,_e,"m",Rn).call(this));try{const i=await e.next();return s=!i.done,i.done&&o(this,_e,"m",An).call(this,t),i}catch(i){throw o(this,_e,"m",An).call(this,t),i}},return:async()=>{const i=e.return?.();return o(this,_e,"m",An).call(this,t),await i??{value:void 0,done:!0}}}}}return ya=function(e,t){if(o(this,xn,"f"))return;if(e.type==="content_block_start"&&e.content_block.type==="fallback"){w(this,xn,!0),w(this,Me,void 0);return}const s=e.type==="content_block_start"||e.type==="message_delta"&&e.delta.stop_reason==="tool_use";o(this,Me,"f")&&s&&(o(this,Ze,"f").push({toolUse:o(this,Me,"f"),event:o(this,Pe,"f")}),w(this,Me,void 0)),t&&w(this,Me,t)},Rn=function(){if(this.errored||this.controller.signal.aborted)return;const e=Math.min(o(this,Pe,"f"),...o(this,Ye,"f").map(t=>t.handled));for(;o(this,Ze,"f")[0]&&o(this,Ze,"f")[0].event<=e;)o(this,kn,"f").call(this,o(this,Ze,"f").shift().toolUse)},An=function(e){const t=o(this,Ye,"f").indexOf(e);t>=0&&(o(this,Ye,"f").splice(t,1),o(this,_e,"m",Rn).call(this))},n})();function va(){let n,r;return{promise:new Promise((t,s)=>{n=t,r=s}),resolve:n,reject:r}}var D,et,Oe,N,K,V,Se,de,xe,$t,ee,he,tt,nt,Ce,ur,ka,dr,hr,It,En,Sa,fr,pr,xa,_r,Ra=(()=>{class n{constructor(e,t,s){D.add(this),this.client=e,et.set(this,!1),Oe.set(this,!1),N.set(this,void 0),K.set(this,void 0),V.set(this,void 0),Se.set(this,void 0),de.set(this,void 0),xe.set(this,void 0),$t.set(this,0),ee.set(this,{status:"idle"}),he.set(this,void 0),tt.set(this,null),nt.set(this,new Map),Ce.set(this,[]),Aa(t),hd(t),Ea(t),w(this,N,{params:{...t,messages:JSON.parse(JSON.stringify(Ta(t.messages)))}});const i=Ic(t.tools,t.messages);w(this,K,{...s,headers:f([$c("BetaToolRunner"),i.length?{[Xt]:i.join(", ")}:void 0,s?.headers])}),w(this,xe,va())}async*[(et=new WeakMap,Oe=new WeakMap,N=new WeakMap,K=new WeakMap,V=new WeakMap,Se=new WeakMap,de=new WeakMap,xe=new WeakMap,$t=new WeakMap,ee=new WeakMap,he=new WeakMap,tt=new WeakMap,nt=new WeakMap,Ce=new WeakMap,D=new WeakSet,Symbol.asyncIterator)](){var e;if(o(this,et,"f"))throw new S("Cannot iterate over a consumed stream");w(this,et,!0),w(this,Oe,!0),w(this,de,void 0);try{for(;;)try{if(o(this,N,"f").params.max_iterations&&o(this,$t,"f")>=o(this,N,"f").params.max_iterations)break;if(o(this,D,"m",xa).call(this),o(this,ee,"f").status==="scheduled"&&Ia(o(this,tt,"f"))!=="resume"){yield*o(this,D,"m",hr).call(this,o(this,ee,"f").config);continue}w(this,Oe,!1,"f"),w(this,de,void 0,"f"),w(this,$t,(e=o(this,$t,"f"),e++,e),"f"),w(this,V,void 0,"f");const{max_iterations:t,runToolsEagerly:s,...i}=o(this,N,"f").params;if(yield*o(this,D,"m",ur).call(this,i),o(this,Oe,"f"))w(this,tt,null,"f");else{const c=await o(this,V,"f"),u=Ia(c.stop_reason);w(this,tt,c.stop_reason,"f"),o(this,N,"f").params.messages.push({role:c.role,content:c.content});const{container:l}=o(this,N,"f").params;if(c.container&&(l==null?o(this,N,"f").params.container=c.container.id:typeof l=="object"&&l.id==null&&(o(this,N,"f").params.container={...l,id:c.container.id})),u==="stop"){yield*o(this,D,"m",fr).call(this);break}if(u==="resume")continue}const a=await o(this,D,"m",pr).call(this,o(this,N,"f").params.messages.at(-1));if(a)o(this,N,"f").params.messages.push(a);else if(!o(this,Oe,"f")){yield*o(this,D,"m",fr).call(this);break}}finally{o(this,Se,"f")?.abort(),w(this,Se,void 0,"f")}if(await o(this,D,"m",dr).call(this),!o(this,V,"f"))throw new S("ToolRunner concluded without a message from the server");o(this,xe,"f").resolve(await o(this,V,"f"))}catch(t){throw w(this,et,!1),o(this,xe,"f").promise.catch(()=>{}),o(this,xe,"f").reject(t),w(this,xe,va()),t}}setMessagesParams(e){const t=typeof e=="function"?e(o(this,N,"f").params):e;if(Aa(t),Ea(t),o(this,ee,"f").status!=="idle"&&gr(t),o(this,ee,"f").status==="in_flight"&&t.messages!==o(this,N,"f").params.messages)throw new S("Message params can't be changed while the conversation is being compacted, because the compaction response is about to replace them. Change them after this iteration instead.");o(this,N,"f").params=t,w(this,Oe,!0),w(this,de,void 0)}setRequestOptions(e){typeof e=="function"?w(this,K,e(o(this,K,"f"))):w(this,K,{...o(this,K,"f"),...e})}async generateToolResponse(e=o(this,K,"f").signal){const t=await o(this,V,"f")??this.params.messages.at(-1);return t?o(this,D,"m",pr).call(this,t,e):null}deferToolCall(e){const t=typeof e=="string"?e:e.id;o(this,he,"f")&&!o(this,he,"f").has(t)&&o(this,he,"f").set(t,{status:"held"})}get deferredToolCalls(){const e=o(this,Se,"f"),t=o(this,he,"f");return!(e instanceof ba)||!t?[]:e.toolCalls.filter(s=>t.get(s.id)?.status==="held")}done(){return o(this,xe,"f").promise}async runUntilDone(){if(!o(this,et,"f"))for await(const e of this);return this.done()}get params(){return o(this,N,"f").params}pushMessages(...e){this.setMessagesParams(t=>({...t,messages:[...t.messages,...e]}))}compactBeforeNextTurn(e){o(this,ee,"f").status!=="in_flight"&&(gr(o(this,N,"f").params),w(this,ee,{status:"scheduled",config:e??{type:"summarize"}}))}addTools(...e){for(const t of e)"name"in t&&o(this,nt,"f").set(t.name,"run"in t?t:null),o(this,Ce,"f").push({type:"addition",tool:t})}removeTools(...e){for(const t of e){const s=typeof t=="string"?t:t.name;o(this,nt,"f").set(s,null),o(this,Ce,"f").push({type:"removal",name:s})}}then(e,t){return this.runUntilDone().then(e,t)}}return ur=async function*(e){await o(this,D,"m",dr).call(this),w(this,he,void 0),e={...e,...e.tools&&{tools:e.tools.map(jr)},messages:Ta(e.messages)},e.stream?(w(this,Se,o(this,N,"f").params.runToolsEagerly?o(this,D,"m",ka).call(this,e):this.client.beta.messages.stream({...e},o(this,K,"f"))),w(this,V,o(this,Se,"f").finalMessage()),o(this,V,"f").catch(()=>{}),yield o(this,Se,"f")):(w(this,V,this.client.beta.messages.create({...e,stream:!1},o(this,K,"f"))),yield o(this,V,"f"))},ka=function(e){const t=new Map;return w(this,he,t),ba.start(this.client.beta.messages,e,o(this,K,"f"),s=>{if(t.has(s.id))return;const i=jc(o(this,D,"m",It).call(this),o(this,D,"m",En).call(this),s,o(this,K,"f"));i.catch(()=>{}),t.set(s.id,{status:"started",result:i})})},dr=async function(){const e=[...o(this,he,"f")?.values()??[]].filter(t=>t.status==="started");await Promise.allSettled(e.map(t=>t.result))},hr=async function*(e){gr(o(this,N,"f").params);const{max_iterations:t,runToolsEagerly:s,...i}=o(this,N,"f").params,a=fd(i);w(this,ee,{status:"in_flight"}),w(this,de,void 0);const c=o(this,V,"f");try{yield*o(this,D,"m",ur).call(this,{...a,compaction:e});const u=await o(this,V,"f");u.content.some(l=>l.type==="compaction"&&l.content)?(o(this,D,"m",Sa).call(this),o(this,N,"f").params.messages=[{role:u.role,content:u.content}]):(O(this.client).warn("Compaction produced no summary; keeping the conversation as it is."),w(this,V,c,"f"))}finally{w(this,ee,{status:"idle"})}},It=function(){const e=new Map;for(const t of o(this,N,"f").params.tools)"run"in t&&e.set(t.name,t);for(const[t,s]of o(this,nt,"f"))s?e.set(t,s):e.delete(t);return e},En=function(){const e=new Set(o(this,D,"m",It).call(this).keys());for(const t of[...o(this,N,"f").params.messages,o(this,D,"m",_r).call(this)])if(typeof t.content!="string"){for(const s of t.content)if(t.role==="system")$a(s,e);else if(t.role==="assistant"&&s.type==="compaction")for(const i of s.tool_changes??[])$a(i,e)}return e},Sa=function(){const e=o(this,D,"m",En).call(this);for(const t of o(this,D,"m",It).call(this).keys())e.has(t)||o(this,nt,"f").set(t,null)},fr=async function*(){if(o(this,ee,"f").status!=="scheduled")return;const e=o(this,N,"f").params.messages.at(-1)?.content;if(Array.isArray(e)&&e.some(t=>t.type==="tool_use")){O(this.client).warn("The pending compaction was skipped because the last turn ended with tool calls that were not run. Call `compactBeforeNextTurn()` again if you continue the conversation."),w(this,ee,{status:"idle"});return}yield*o(this,D,"m",hr).call(this,o(this,ee,"f").config)},pr=async function(e,t=o(this,K,"f").signal){return o(this,de,"f")!==void 0?o(this,de,"f"):(w(this,de,pd(o(this,D,"m",It).call(this),o(this,D,"m",En).call(this),e,{...o(this,K,"f"),signal:t},o(this,he,"f"))),o(this,de,"f"))},xa=function(){o(this,tt,"f")==="pause_turn"||o(this,Ce,"f").length===0||(o(this,N,"f").params.messages.push(o(this,D,"m",_r).call(this)),w(this,Ce,[]))},_r=function(){const e=[];for(const t of o(this,Ce,"f")){if(t.type==="removal"){e.push({type:"tool_removal",tool:{type:"tool_reference",name:t.name}});continue}const s=jr(t.tool);e.push({type:"tool_addition",tool:{type:"tool_definition",definition:s}})}return{role:"system",content:e}},n})();function Aa(n){if("compaction"in n&&n.compaction!=null)throw new S("`compaction` cannot be set on a tool runner: every request in the loop would compact again. Call `runner.compactBeforeNextTurn()` when the conversation should be compacted instead.")}function hd(n){if("compactionControl"in n&&n.compactionControl!=null)throw new S("`compactionControl` has been removed from the tool runner. Use server-side compaction instead: call `runner.compactBeforeNextTurn()` when the conversation should be compacted.")}function Ea(n){if(n.runToolsEagerly&&!n.stream)throw new TypeError("`runToolsEagerly: true` needs `stream: true` in the tool runner's params, because a reply that isn't streamed arrives whole.")}function gr(n){if(n.context_management?.edits?.some(r=>r.type.startsWith("compact_")))throw new S("`compactBeforeNextTurn()` can't be used while `context_management` has a compaction edit, because the API doesn't accept a compaction block together with one. Remove the edit first.")}function fd(n){const{context_management:r,stop_sequences:e,output_format:t,...s}=n,i=({format:a,...c})=>c;return(s.tool_choice?.type==="any"||s.tool_choice?.type==="tool")&&delete s.tool_choice,s.output_config&&(s.output_config=i(s.output_config)),Array.isArray(s.fallbacks)&&(s.fallbacks=s.fallbacks.map(a=>a.output_config?{...a,output_config:i(a.output_config)}:a)),s}function jr(n){if(!("run"in n))return n;const r=yd;return{...Object.fromEntries(Object.entries(n).filter(([e])=>r.includes(e))),...it(n)&&{[Ee]:n[Ee]}}}function Ta(n){return n.map(r=>{if(r.role!=="system"||typeof r.content=="string")return r;const e=r.content.map(t=>t.type==="tool_addition"&&t.tool.type==="tool_definition"?{...t,tool:{...t.tool,definition:jr(t.tool.definition)}}:t);return{...r,content:e}})}async function pd(n,r,e,t,s){if(!e||e.role!=="assistant"||!e.content||typeof e.content=="string")return null;const i=e.content.filter(c=>c.type==="tool_use");return i.length===0?null:{role:"user",content:await Promise.all(i.map(c=>{const u=s?.get(c.id);if(u?.status==="started")return u.result;const l=jc(n,r,c,t);return s?.set(c.id,{status:"started",result:l}),l}))}}async function jc(n,r,e,t){const s=r.has(e.name)?n.get(e.name):void 0;if(!s)return _d(e);try{let i=e.input;"parse"in s&&s.parse&&(i=s.parse(i));const a=await s.run(i,{toolUse:e,toolUseBlock:e,signal:t?.signal});return{type:"tool_result",tool_use_id:e.id,content:a}}catch(i){return{type:"tool_result",tool_use_id:e.id,content:i instanceof cs?i.content:`Error: ${i instanceof Error?i.message:String(i)}`,is_error:!0}}}function _d(n){return{type:"tool_result",tool_use_id:n.id,content:`Error: Tool '${n.name}' not found`,is_error:!0}}function $a(n,r){switch(n.type){case"tool_removal":case"tool_addition":gd(n,r);break}}function gd(n,r){const e=md(n.tool);e!==void 0&&(n.type==="tool_removal"?r.delete(e):r.add(e))}function md(n){switch(n.type){case"tool_reference":return n.name;case"tool_definition":return"name"in n.definition?n.definition.name:void 0;default:return}}function Ia(n){if(n===null)return"stop";switch(n){case"tool_use":return"run_tools";case"pause_turn":case"compaction":return"resume";case"end_turn":case"stop_sequence":case"max_tokens":case"model_context_window_exceeded":case"refusal":return"stop";default:return"stop"}}const Pa={"claude-sonnet-4-5":"November 30th, 2026","claude-sonnet-4-5-20250929":"November 30th, 2026"},wd=["claude-mythos-preview","claude-opus-4-6"];var Ma=(()=>{class n extends v{constructor(){super(...arguments),this.batches=new _i(this._client)}create(e,t){const s=Oa(e),{betas:i,user_profile_id:a,workspace_id:c,...u}=s;u.model in Pa&&console.warn(`The model '${u.model}' is deprecated and will reach end-of-life on ${Pa[u.model]}
|
|
11
11
|
Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`),wd.includes(u.model)&&u.thinking&&u.thinking.type==="enabled"&&console.warn(`Using Claude with ${u.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);let l=t?.timeout??this._client._options.timeout;if(!u.stream&&l==null){const d=Dc[u.model]??void 0;l=this._client.calculateNonstreamingTimeout(u.max_tokens,d)}const p=Pc(u.tools,u.messages);return this._client.post("/v1/messages?beta=true",{body:u,timeout:l??6e5,...t,headers:f([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...a!=null?{"anthropic-user-profile-id":a}:void 0,...c!=null?{"anthropic-workspace-id":c}:void 0},p,t?.headers]),stream:s.stream??!1})}parse(e,t){return t={...t,headers:f([{"anthropic-beta":[...e.betas??[],"structured-outputs-2025-12-15"].toString()},t?.headers])},this.create(e,t).then(s=>Hc(s,e,{logger:this._client.logger??console}))}stream(e,t){return zc.createMessage(this,e,t)}countTokens(e,t){const s=Oa(e),{betas:i,user_profile_id:a,workspace_id:c,...u}=s;return this._client.post("/v1/messages/count_tokens?beta=true",{body:u,...t,headers:f([{"anthropic-beta":[...i??[],"token-counting-2024-11-01"].toString(),...a!=null?{"anthropic-user-profile-id":a}:void 0,...c!=null?{"anthropic-workspace-id":c}:void 0},t?.headers])})}toolRunner(e,t){return new Ra(this._client,e,t)}}return n.Batches=_i,n.BetaToolRunner=Ra,n.ToolError=cs,n})();function Oa(n){if(!n.output_format)return n;if(n.output_config?.format)throw new S("Both output_format and output_config.format were provided. Please use only output_config.format (output_format is deprecated).");const{output_format:r,...e}=n;return{...e,output_config:{...n.output_config,format:r}}}const yd=["input_schema","name","allowed_callers","cache_control","defer_loading","description","eager_input_streaming","input_examples","strict","type","configs","display_height_px","display_width_px","display_number","enable_zoom","max_characters"];var Fr=(()=>{class n extends v{constructor(){super(...arguments),this.models=new zs(this._client),this.messages=new Ma(this._client),this.agents=new Gs(this._client),this.environments=new di(this._client),this.sessions=new ha(this._client),this.deployments=new Us(this._client),this.deploymentRuns=new Ds(this._client),this.vaults=new wa(this._client),this.memoryStores=new pi(this._client),this.files=new Ws(this._client),this.skills=new pa(this._client),this.webhooks=new Js(this._client),this.userProfiles=new js(this._client),this.dreams=new Hs(this._client),this.tunnels=new ga(this._client),this.organization=new oa(this._client)}}return n.Models=zs,n.Messages=Ma,n.Agents=Gs,n.Environments=di,n.Sessions=ha,n.Deployments=Us,n.DeploymentRuns=Ds,n.Vaults=wa,n.MemoryStores=pi,n.Files=Ws,n.Skills=pa,n.Webhooks=Js,n.UserProfiles=js,n.Dreams=Hs,n.Tunnels=ga,n.Organization=oa,n})();class Ca extends v{create(r,e){const{betas:t,workspace_id:s,...i}=r;return this._client.post("/v1/complete",{body:i,timeout:this._client._options.timeout??6e5,...e,headers:f([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers]),stream:r.stream??!1})}}class La extends v{list(r={},e){const{workspace_id:t,...s}=r??{};return this._client.getAPIList("/v1/files",A,{query:s,...e,headers:f([{...t!=null?{"anthropic-workspace-id":t}:void 0},e?.headers])})}delete(r,e={},t){const{workspace_id:s}=e??{};return this._client.delete(h`/v1/files/${r}`,{...t,headers:f([{...s!=null?{"anthropic-workspace-id":s}:void 0},t?.headers])})}download(r,e={},t){const{workspace_id:s}=e??{};return this._client.get(h`/v1/files/${r}/content`,{...t,headers:f([{Accept:"application/binary",...s!=null?{"anthropic-workspace-id":s}:void 0},t?.headers]),__binaryResponse:!0})}retrieveMetadata(r,e={},t){const{workspace_id:s}=e??{};return this._client.get(h`/v1/files/${r}`,{...t,headers:f([{...s!=null?{"anthropic-workspace-id":s}:void 0},t?.headers])})}upload(r,e){const{workspace_id:t,...s}=r;return this._client.post("/v1/files",me({body:s,...e,headers:f([{...t!=null?{"anthropic-workspace-id":t}:void 0},Mc(s.file),e?.headers])},this._client))}}function Fc(n){return n?.output_config?.format}function Na(n,r,e){const t=Fc(r);return!r||!("parse"in(t??{}))?{...n,content:n.content.map(s=>s.type==="text"?Object.defineProperty({...s},"parsed_output",{value:null,enumerable:!1}):s),parsed_output:null}:qc(n,r)}function qc(n,r,e){let t=null;const s=n.content.map(i=>{if(i.type==="text"){const a=bd(r,i.text);return t===null&&(t=a),Object.defineProperty({...i},"parsed_output",{value:a,enumerable:!1})}return i});return{...n,content:s,parsed_output:t}}function bd(n,r){const e=Fc(n);if(e?.type!=="json_schema")return null;try{return"parse"in e?e.parse(r):JSON.parse(r)}catch(t){throw new S(`Failed to parse structured output: ${t}`)}}var se,Re,rt,Pt,Tn,Mt,Ot,$n,Ct,fe,Lt,In,Pn,Le,Mn,On,Cn,Nt,mr,Ba,wr,yr,br,vr,Da;function kr(n){return n.type==="tool_use"||n.type==="server_tool_use"}var vd=(()=>{class n{constructor(e,t){se.add(this),this.messages=[],this.receivedMessages=[],Re.set(this,void 0),rt.set(this,null),this.controller=new AbortController,Pt.set(this,void 0),Tn.set(this,()=>{}),Mt.set(this,()=>{}),Ot.set(this,void 0),$n.set(this,()=>{}),Ct.set(this,()=>{}),fe.set(this,{}),Lt.set(this,!1),In.set(this,!1),Pn.set(this,!1),Le.set(this,!1),Mn.set(this,void 0),On.set(this,void 0),Cn.set(this,void 0),Nt.set(this,void 0),wr.set(this,s=>{if(w(this,In,!0),lt(s)&&(s=new oe),s instanceof oe)return w(this,Pn,!0),this._emit("abort",s);if(s instanceof S)return this._emit("error",s);if(s instanceof Error){const i=new S(s.message);return i.cause=s,this._emit("error",i)}return this._emit("error",new S(String(s)))}),w(this,Pt,new Promise((s,i)=>{w(this,Tn,s,"f"),w(this,Mt,i,"f")})),w(this,Ot,new Promise((s,i)=>{w(this,$n,s,"f"),w(this,Ct,i,"f")})),o(this,Pt,"f").catch(()=>{}),o(this,Ot,"f").catch(()=>{}),w(this,rt,e),w(this,Nt,t?.logger??console)}get response(){return o(this,Mn,"f")}get request_id(){return o(this,On,"f")}get workspace_id(){return o(this,Cn,"f")}async withResponse(){w(this,Le,!0);const e=await o(this,Pt,"f");if(!e)throw new Error("Could not resolve a `Response` object");return{data:this,response:e,request_id:e.headers.get("request-id"),workspace_id:e.headers.get("anthropic-workspace-id")}}static fromReadableStream(e){const t=new n(null);return t._run(()=>t._fromReadableStream(e)),t}static createMessage(e,t,s,{logger:i}={}){const a=new n(t,{logger:i});for(const c of t.messages)a._addMessageParam(c);return w(a,rt,{...t,stream:!0}),a._run(()=>a._createMessage(e,{...t,stream:!0},{...s,headers:{...s?.headers,[os]:"stream"}})),a}_run(e){e().then(()=>{this._emitFinal(),this._emit("end")},o(this,wr,"f"))}_addMessageParam(e){this.messages.push(e)}_addMessage(e,t=!0){this.receivedMessages.push(e),t&&this._emit("message",e)}async _createMessage(e,t,s){const i=s?.signal;let a;i&&(i.aborted&&this.controller.abort(),a=this.controller.abort.bind(this.controller),i.addEventListener("abort",a));try{o(this,se,"m",yr).call(this);const{response:c,data:u}=await e.create({...t,stream:!0},{...s,signal:this.controller.signal}).withResponse();this._connected(c);for await(const l of u)o(this,se,"m",br).call(this,l);if(u.controller.signal?.aborted)throw new oe;o(this,se,"m",vr).call(this)}finally{i&&a&&i.removeEventListener("abort",a)}}_connected(e){this.ended||(w(this,Mn,e),w(this,On,e?.headers.get("request-id")),w(this,Cn,e?.headers.get("anthropic-workspace-id")),o(this,Tn,"f").call(this,e),this._emit("connect"))}get ended(){return o(this,Lt,"f")}get errored(){return o(this,In,"f")}get aborted(){return o(this,Pn,"f")}abort(){this.controller.abort()}on(e,t){return(o(this,fe,"f")[e]||(o(this,fe,"f")[e]=[])).push({listener:t}),this}off(e,t){const s=o(this,fe,"f")[e];if(!s)return this;const i=s.findIndex(a=>a.listener===t);return i>=0&&s.splice(i,1),this}once(e,t){return(o(this,fe,"f")[e]||(o(this,fe,"f")[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,s)=>{w(this,Le,!0),e!=="error"&&this.once("error",s),this.once(e,t)})}async done(){w(this,Le,!0),await o(this,Ot,"f")}get currentMessage(){return o(this,Re,"f")}async finalMessage(){return await this.done(),o(this,se,"m",mr).call(this)}async finalText(){return await this.done(),o(this,se,"m",Ba).call(this)}_emit(e,...t){if(o(this,Lt,"f"))return;e==="end"&&(w(this,Lt,!0),o(this,$n,"f").call(this));const s=o(this,fe,"f")[e];if(s&&(o(this,fe,"f")[e]=s.filter(i=>!i.once),s.forEach(({listener:i})=>i(...t))),e==="abort"){const i=t[0];!o(this,Le,"f")&&!s?.length&&Promise.reject(i),o(this,Mt,"f").call(this,i),o(this,Ct,"f").call(this,i),this._emit("end");return}if(e==="error"){const i=t[0];!o(this,Le,"f")&&!s?.length&&Promise.reject(i),o(this,Mt,"f").call(this,i),o(this,Ct,"f").call(this,i),this._emit("end")}}_emitFinal(){this.receivedMessages.at(-1)&&this._emit("finalMessage",o(this,se,"m",mr).call(this))}async _fromReadableStream(e,t){const s=t?.signal;let i;s&&(s.aborted&&this.controller.abort(),i=this.controller.abort.bind(this.controller),s.addEventListener("abort",i));try{o(this,se,"m",yr).call(this),this._connected(null);const a=dt.fromReadableStream(e,this.controller);for await(const c of a)o(this,se,"m",br).call(this,c);if(a.controller.signal?.aborted)throw new oe;o(this,se,"m",vr).call(this)}finally{s&&i&&s.removeEventListener("abort",i)}}[(Re=new WeakMap,rt=new WeakMap,Pt=new WeakMap,Tn=new WeakMap,Mt=new WeakMap,Ot=new WeakMap,$n=new WeakMap,Ct=new WeakMap,fe=new WeakMap,Lt=new WeakMap,In=new WeakMap,Pn=new WeakMap,Le=new WeakMap,Mn=new WeakMap,On=new WeakMap,Cn=new WeakMap,Nt=new WeakMap,wr=new WeakMap,se=new WeakSet,mr=function(){if(this.receivedMessages.length===0)throw new S("stream ended without producing a Message with role=assistant");return this.receivedMessages.at(-1)},Ba=function(){if(this.receivedMessages.length===0)throw new S("stream ended without producing a Message with role=assistant");const t=this.receivedMessages.at(-1).content.filter(s=>s.type==="text").map(s=>s.text);if(t.length===0)throw new S("stream ended without producing a content block with type=text");return t.join(" ")},yr=function(){this.ended||w(this,Re,void 0)},br=function(t){if(this.ended)return;const s=o(this,se,"m",Da).call(this,t);switch(this._emit("streamEvent",t,s),t.type){case"content_block_delta":{const i=s.content.at(-1);switch(t.delta.type){case"text_delta":{i.type==="text"&&this._emit("text",t.delta.text,i.text||"");break}case"citations_delta":{i.type==="text"&&this._emit("citation",t.delta.citation,i.citations??[]);break}case"input_json_delta":{kr(i)&&o(this,fe,"f").inputJson?.length&&this._emit("inputJson",t.delta.partial_json,i.input);break}case"thinking_delta":{i.type==="thinking"&&this._emit("thinking",t.delta.thinking,i.thinking);break}case"signature_delta":{i.type==="thinking"&&this._emit("signature",i.signature);break}default:t.delta}break}case"message_stop":{this._addMessageParam(s),this._addMessage(Na(s,o(this,rt,"f"),{logger:o(this,Nt,"f")}),!0);break}case"content_block_stop":{this._emit("contentBlock",s.content.at(-1));break}case"message_start":{w(this,Re,s);break}}},vr=function(){if(this.ended)throw new S("stream has ended, this shouldn't happen");const t=o(this,Re,"f");if(!t)throw new S("request ended without sending any chunks");return w(this,Re,void 0),Na(t,o(this,rt,"f"),{logger:o(this,Nt,"f")})},Da=function(t){let s=o(this,Re,"f");if(t.type==="message_start"){if(s)throw new S(`Unexpected event order, got ${t.type} before receiving "message_stop"`);return t.message}if(!s)throw new S(`Unexpected event order, got ${t.type} before "message_start"`);switch(t.type){case"message_stop":return s;case"message_delta":return s.stop_reason=t.delta.stop_reason,s.stop_sequence=t.delta.stop_sequence,s.stop_details=t.delta.stop_details,s.usage.output_tokens=t.usage.output_tokens,t.delta.container!=null&&(s.container=t.delta.container),t.usage.input_tokens!=null&&(s.usage.input_tokens=t.usage.input_tokens),t.usage.cache_creation_input_tokens!=null&&(s.usage.cache_creation_input_tokens=t.usage.cache_creation_input_tokens),t.usage.cache_read_input_tokens!=null&&(s.usage.cache_read_input_tokens=t.usage.cache_read_input_tokens),t.usage.server_tool_use!=null&&(s.usage.server_tool_use=t.usage.server_tool_use),t.usage.output_tokens_details!=null&&(s.usage.output_tokens_details=t.usage.output_tokens_details),s;case"content_block_start":return s.content.push({...t.content_block}),s;case"content_block_delta":{const i=s.content.at(t.index);switch(t.delta.type){case"text_delta":{i?.type==="text"&&(s.content[t.index]={...i,text:(i.text||"")+t.delta.text});break}case"citations_delta":{i?.type==="text"&&(s.content[t.index]={...i,citations:[...i.citations??[],t.delta.citation]});break}case"input_json_delta":{if(i&&kr(i)){const a=(i[ct]||"")+t.delta.partial_json;s.content[t.index]=Wc(i,a)}break}case"thinking_delta":{i?.type==="thinking"&&(s.content[t.index]={...i,thinking:i.thinking+t.delta.thinking});break}case"signature_delta":{i?.type==="thinking"&&(s.content[t.index]={...i,signature:t.delta.signature});break}default:t.delta}return s}case"content_block_stop":{const i=s.content.at(t.index);return i&&kr(i)&&ct in i&&Object.defineProperty(i,"input",{value:i.input,enumerable:!0,configurable:!0,writable:!0}),s}}},Symbol.asyncIterator)](){const e=[],t=[];let s=!1;return this.on("streamEvent",i=>{const a=t.shift();a?a.resolve(i):e.push(i)}),this.on("end",()=>{s=!0;for(const i of t)i.resolve(void 0);t.length=0}),this.on("abort",i=>{s=!0;for(const a of t)a.reject(i);t.length=0}),this.on("error",i=>{s=!0;for(const a of t)a.reject(i);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:s?{value:void 0,done:!0}:new Promise((a,c)=>t.push({resolve:a,reject:c})).then(a=>a?{value:a,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new dt(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}}return n})();class Ua extends v{create(r,e){const{user_profile_id:t,workspace_id:s,...i}=r;return this._client.post("/v1/messages/batches",{body:i,...e,headers:f([{...t!=null?{"anthropic-user-profile-id":t}:void 0,...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}retrieve(r,e={},t){const{workspace_id:s}=e??{};return this._client.get(h`/v1/messages/batches/${r}`,{...t,headers:f([{...s!=null?{"anthropic-workspace-id":s}:void 0},t?.headers])})}list(r={},e){const{workspace_id:t,...s}=r??{};return this._client.getAPIList("/v1/messages/batches",X,{query:s,...e,headers:f([{...t!=null?{"anthropic-workspace-id":t}:void 0},e?.headers])})}delete(r,e={},t){const{workspace_id:s}=e??{};return this._client.delete(h`/v1/messages/batches/${r}`,{...t,headers:f([{...s!=null?{"anthropic-workspace-id":s}:void 0},t?.headers])})}cancel(r,e={},t){const{workspace_id:s}=e??{};return this._client.post(h`/v1/messages/batches/${r}/cancel`,{...t,headers:f([{...s!=null?{"anthropic-workspace-id":s}:void 0},t?.headers])})}async results(r,e={},t){const s=await this.retrieve(r,e,t);if(!s.results_url)throw new S(`No batch \`results_url\`; Has it finished processing? ${s.processing_status} - ${s.id}`);const{workspace_id:i}=e??{};return this._client.get(s.results_url,{...t,headers:f([{Accept:"application/binary",...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers]),stream:!0,__binaryResponse:!0})._thenUnwrap((a,c)=>Bc.fromResponse(c.response,c.controller))}}var qr=(()=>{class n extends v{constructor(){super(...arguments),this.batches=new Ua(this._client)}create(e,t){const{user_profile_id:s,workspace_id:i,...a}=e;a.model in Ha&&console.warn(`The model '${a.model}' is deprecated and will reach end-of-life on ${Ha[a.model]}
|
|
12
12
|
Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`),kd.includes(a.model)&&a.thinking&&a.thinking.type==="enabled"&&console.warn(`Using Claude with ${a.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);let c=t?.timeout??this._client._options.timeout;if(!a.stream&&c==null){const l=Dc[a.model]??void 0;c=this._client.calculateNonstreamingTimeout(a.max_tokens,l)}const u=Pc(a.tools,a.messages);return this._client.post("/v1/messages",{body:a,timeout:c??6e5,...t,headers:f([{...s!=null?{"anthropic-user-profile-id":s}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},u,t?.headers]),stream:e.stream??!1})}parse(e,t){return this.create(e,t).then(s=>qc(s,e,{logger:this._client.logger??console}))}stream(e,t){return vd.createMessage(this,e,t,{logger:this._client.logger??console})}countTokens(e,t){const{user_profile_id:s,workspace_id:i,...a}=e;return this._client.post("/v1/messages/count_tokens",{body:a,...t,headers:f([{...s!=null?{"anthropic-user-profile-id":s}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}}return n.Batches=Ua,n})();const Ha={"claude-sonnet-4-5":"November 30th, 2026","claude-sonnet-4-5-20250929":"November 30th, 2026"},kd=["claude-mythos-preview","claude-opus-4-6"];class Wa extends v{retrieve(r,e={},t){const{betas:s,workspace_id:i}=e??{};return this._client.get(h`/v1/models/${r}`,{...t,headers:f([{...s?.toString()!=null?{"anthropic-beta":s?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(r={},e){const{betas:t,workspace_id:s,...i}=r??{};return this._client.getAPIList("/v1/models",X,{query:i,...e,headers:f([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...s!=null?{"anthropic-workspace-id":s}:void 0},e?.headers])})}}class za extends v{retrieve(r,e){return this._client.get(h`/v1/organizations/api_keys/${r}`,e)}update(r,e,t){return this._client.post(h`/v1/organizations/api_keys/${r}`,{body:e,...t})}list(r={},e){return this._client.getAPIList("/v1/organizations/api_keys",X,{query:r,...e})}}class ja extends v{retrieve(r){return this._client.get("/v1/organizations/compliance_settings",r)}update(r,e){return this._client.post("/v1/organizations/compliance_settings",{body:r,...e})}}class Fa extends v{create(r,e){return this._client.post("/v1/organizations/external_keys",{body:r,...e})}retrieve(r,e){return this._client.get(h`/v1/organizations/external_keys/${r}`,e)}update(r,e,t){return this._client.post(h`/v1/organizations/external_keys/${r}`,{body:e,...t})}list(r={},e){return this._client.getAPIList("/v1/organizations/external_keys",A,{query:r,...e})}delete(r,e){return this._client.delete(h`/v1/organizations/external_keys/${r}`,e)}validate(r,e){return this._client.post(h`/v1/organizations/external_keys/${r}/validate`,e)}}class qa extends v{create(r,e){return this._client.post("/v1/organizations/invites",{body:r,...e})}retrieve(r,e){return this._client.get(h`/v1/organizations/invites/${r}`,e)}list(r={},e){return this._client.getAPIList("/v1/organizations/invites",X,{query:r,...e})}delete(r,e){return this._client.delete(h`/v1/organizations/invites/${r}`,e)}}let Ka=class extends v{list(r={},e){return this._client.getAPIList("/v1/organizations/rate_limits",A,{query:r,...e})}};class Va extends v{retrieve(r,e){return this._client.get(h`/v1/organizations/users/${r}`,e)}update(r,e,t){return this._client.post(h`/v1/organizations/users/${r}`,{body:e,...t})}list(r={},e){return this._client.getAPIList("/v1/organizations/users",X,{query:r,...e})}remove(r,e){return this._client.delete(h`/v1/organizations/users/${r}`,e)}}class Ja extends v{create(r,e){return this._client.post("/v1/organizations/federation_issuers",{body:r,...e})}retrieve(r,e){return this._client.get(h`/v1/organizations/federation_issuers/${r}`,e)}update(r,e,t){return this._client.post(h`/v1/organizations/federation_issuers/${r}`,{body:e,...t})}list(r={},e){return this._client.getAPIList("/v1/organizations/federation_issuers",A,{query:r,...e})}archive(r,e){return this._client.post(h`/v1/organizations/federation_issuers/${r}/archive`,e)}}let Xa=class extends v{list(r,e={},t){return this._client.getAPIList(h`/v1/organizations/federation_rules/${r}/workspaces`,A,{query:e,...t})}add(r,e,t){return this._client.post(h`/v1/organizations/federation_rules/${r}/workspaces`,{body:e,...t})}remove(r,e,t){const{federation_rule_id:s}=e;return this._client.delete(h`/v1/organizations/federation_rules/${s}/workspaces/${r}`,t)}};var Ga=(()=>{class n extends v{constructor(){super(...arguments),this.workspaces=new Xa(this._client)}create(e,t){return this._client.post("/v1/organizations/federation_rules",{body:e,...t})}retrieve(e,t){return this._client.get(h`/v1/organizations/federation_rules/${e}`,t)}update(e,t,s){return this._client.post(h`/v1/organizations/federation_rules/${e}`,{body:t,...s})}list(e={},t){return this._client.getAPIList("/v1/organizations/federation_rules",A,{query:e,...t})}archive(e,t){return this._client.post(h`/v1/organizations/federation_rules/${e}/archive`,t)}}return n.Workspaces=Xa,n})(),Qa=(()=>{class n extends v{constructor(){super(...arguments),this.issuers=new Ja(this._client),this.rules=new Ga(this._client)}}return n.Issuers=Ja,n.Rules=Ga,n})();let Ya=class extends v{list(r,e={},t){return this._client.getAPIList(h`/v1/organizations/service_accounts/${r}/workspaces`,A,{query:e,...t})}add(r,e,t){return this._client.post(h`/v1/organizations/service_accounts/${r}/workspaces`,{body:e,...t})}remove(r,e,t){const{service_account_id:s}=e;return this._client.delete(h`/v1/organizations/service_accounts/${s}/workspaces/${r}`,t)}};var Za=(()=>{class n extends v{constructor(){super(...arguments),this.workspaces=new Ya(this._client)}create(e,t){return this._client.post("/v1/organizations/service_accounts",{body:e,...t})}retrieve(e,t){return this._client.get(h`/v1/organizations/service_accounts/${e}`,t)}update(e,t,s){return this._client.post(h`/v1/organizations/service_accounts/${e}`,{body:t,...s})}list(e={},t){return this._client.getAPIList("/v1/organizations/service_accounts",A,{query:e,...t})}archive(e,t){return this._client.post(h`/v1/organizations/service_accounts/${e}/archive`,t)}}return n.Workspaces=Ya,n})();class eo extends v{retrieve(r,e,t){const{workspace_id:s}=e;return this._client.get(h`/v1/organizations/workspaces/${s}/members/${r}`,t)}update(r,e,t){const{workspace_id:s,...i}=e;return this._client.post(h`/v1/organizations/workspaces/${s}/members/${r}`,{body:i,...t})}list(r,e={},t){return this._client.getAPIList(h`/v1/organizations/workspaces/${r}/members`,X,{query:e,...t})}add(r,e,t){return this._client.post(h`/v1/organizations/workspaces/${r}/members`,{body:e,...t})}remove(r,e,t){const{workspace_id:s}=e;return this._client.delete(h`/v1/organizations/workspaces/${s}/members/${r}`,t)}}class to extends v{list(r,e={},t){return this._client.getAPIList(h`/v1/organizations/workspaces/${r}/rate_limits`,A,{query:e,...t})}}class no extends v{retrieve(r,e,t){const{workspace_id:s}=e;return this._client.get(h`/v1/organizations/workspaces/${s}/service_accounts/${r}`,t)}update(r,e,t){const{workspace_id:s,...i}=e;return this._client.post(h`/v1/organizations/workspaces/${s}/service_accounts/${r}`,{body:i,...t})}list(r,e={},t){return this._client.getAPIList(h`/v1/organizations/workspaces/${r}/service_accounts`,A,{query:e,...t})}add(r,e,t){return this._client.post(h`/v1/organizations/workspaces/${r}/service_accounts`,{body:e,...t})}remove(r,e,t){const{workspace_id:s}=e;return this._client.delete(h`/v1/organizations/workspaces/${s}/service_accounts/${r}`,t)}}var ro=(()=>{class n extends v{constructor(){super(...arguments),this.rateLimits=new to(this._client),this.members=new eo(this._client),this.serviceAccounts=new no(this._client)}create(e,t){return this._client.post("/v1/organizations/workspaces",{body:e,...t})}retrieve(e,t){return this._client.get(h`/v1/organizations/workspaces/${e}`,t)}update(e,t,s){return this._client.post(h`/v1/organizations/workspaces/${e}`,{body:t,...s})}list(e={},t){return this._client.getAPIList("/v1/organizations/workspaces",X,{query:e,...t})}archive(e,t){return this._client.post(h`/v1/organizations/workspaces/${e}/archive`,t)}}return n.RateLimits=to,n.Members=eo,n.ServiceAccounts=no,n})(),so=(()=>{class n extends v{constructor(){super(...arguments),this.apiKeys=new za(this._client),this.externalKeys=new Fa(this._client),this.federation=new Qa(this._client),this.invites=new qa(this._client),this.serviceAccounts=new Za(this._client),this.users=new Va(this._client),this.workspaces=new ro(this._client),this.rateLimits=new Ka(this._client),this.complianceSettings=new ja(this._client)}retrieve(e){return this._client.get("/v1/organizations/me",e)}}return n.APIKeys=za,n.ExternalKeys=Fa,n.Federation=Qa,n.Invites=qa,n.ServiceAccounts=Za,n.Users=Va,n.Workspaces=ro,n.RateLimits=Ka,n.ComplianceSettings=ja,n})();class io extends v{create(r,e,t){const{workspace_id:s,...i}=e;return this._client.post(h`/v1/skills/${r}/versions`,me({body:i,...t,headers:f([{...s!=null?{"anthropic-workspace-id":s}:void 0},t?.headers])},this._client,!1))}retrieve(r,e,t){const{skill_id:s,workspace_id:i}=e;return this._client.get(h`/v1/skills/${s}/versions/${r}`,{...t,headers:f([{...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(r,e={},t){const{workspace_id:s,...i}=e??{};return this._client.getAPIList(h`/v1/skills/${r}/versions`,A,{query:i,...t,headers:f([{...s!=null?{"anthropic-workspace-id":s}:void 0},t?.headers])})}delete(r,e,t){const{skill_id:s,workspace_id:i}=e;return this._client.delete(h`/v1/skills/${s}/versions/${r}`,{...t,headers:f([{...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}}var ao=(()=>{class n extends v{constructor(){super(...arguments),this.versions=new io(this._client)}create(e,t){const{workspace_id:s,...i}=e;return this._client.post("/v1/skills",me({body:i,...t,headers:f([{...s!=null?{"anthropic-workspace-id":s}:void 0},t?.headers])},this._client,!1))}retrieve(e,t={},s){const{workspace_id:i}=t??{};return this._client.get(h`/v1/skills/${e}`,{...s,headers:f([{...i!=null?{"anthropic-workspace-id":i}:void 0},s?.headers])})}list(e={},t){const{workspace_id:s,...i}=e??{};return this._client.getAPIList("/v1/skills",A,{query:i,...t,headers:f([{...s!=null?{"anthropic-workspace-id":s}:void 0},t?.headers])})}delete(e,t={},s){const{workspace_id:i}=t??{};return this._client.delete(h`/v1/skills/${e}`,{...s,headers:f([{...i!=null?{"anthropic-workspace-id":i}:void 0},s?.headers])})}}return n.Versions=io,n})(),Sr,xr,Ln,oo;const Sd="\\n\\nHuman:",xd="\\n\\nAssistant:";var Kc=(()=>{class n{get credentials(){return this._authState.provider}constructor({baseURL:e=P("ANTHROPIC_BASE_URL"),apiKey:t,authToken:s,webhookKey:i=P("ANTHROPIC_WEBHOOK_SIGNING_KEY")??null,...a}={}){if(Sr.add(this),this._requestAuthFlags=new WeakMap,Ln.set(this,void 0),t===void 0&&(t=a.profile!=null?null:P("ANTHROPIC_API_KEY")??null),s===void 0&&(s=a.profile!=null?null:P("ANTHROPIC_AUTH_TOKEN")??null),a.profile!=null&&(a.credentials!=null||a.config!=null))throw new TypeError("Pass at most one of `profile`, `credentials`, or `config`.");const c={apiKey:t,authToken:s,webhookKey:i,...a,baseURL:e||"https://api.anthropic.com"};if(!c.dangerouslyAllowBrowser&&ml())throw new S(`It looks like you're running in a browser-like environment.
|
|
13
13
|
|