sliccy 2.22.1 → 2.22.2
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/dist/ui/assets/anthropic-CePl-niV.js +39 -0
- package/dist/ui/assets/azure-openai-responses-B0ars-Hm.js +1 -0
- package/dist/ui/assets/{dist-BOSN53wj2.js → dist-DY89ppnG.js} +2 -2
- package/dist/ui/assets/{es-B7F4vMGM.js → es-Ctukg7Pf.js} +3 -3
- package/dist/ui/assets/{fs-C8YYTJOZ.js → fs-C0vsW7YS.js} +1 -1
- package/dist/ui/assets/github-copilot-headers-B6Fvsk-Y.js +1 -0
- package/dist/ui/assets/{google-BJYq8RB-.js → google-CgTHsA2_.js} +1 -1
- package/dist/ui/assets/{google-shared-Cu4bgtNm.js → google-shared-nj0IYXjb.js} +3 -3
- package/dist/ui/assets/google-vertex-cqyT1zM2.js +1 -0
- package/dist/ui/assets/{index-C_F1DRoS.js → index-n7dM8Ny6.js} +900 -900
- package/dist/ui/assets/{mistral-Psfiyuyg.js → mistral-DPFFr-1D.js} +2 -2
- package/dist/ui/assets/{onboarding-orchestrator-C2nsOQmV.js → onboarding-orchestrator-DX-WA9oh.js} +1 -1
- package/dist/ui/assets/{openai-codex-responses-BqWXAH5A.js → openai-codex-responses-DjTLNv18.js} +1 -1
- package/dist/ui/assets/openai-completions-BnCyVXK7.js +5 -0
- package/dist/ui/assets/openai-responses-9MflKa27.js +1 -0
- package/dist/ui/assets/{openai-responses-shared-D7Iy5EFQ.js → openai-responses-shared-D8Vix6-m.js} +1 -1
- package/dist/ui/assets/{provider-settings-DCcbCHgM.js → provider-settings-DY_N8CBx.js} +16 -16
- package/dist/ui/assets/{pyodide-CYVFNkgG.js → pyodide-B0OcGzKl.js} +2 -2
- package/dist/ui/assets/simple-options-CRMUB9za.js +1 -0
- package/dist/ui/assets/{skills-DBi1lWWR.js → skills-Cp2_zExC.js} +1 -1
- package/dist/ui/assets/{sql-wasm-CjYU-RUL.js → sql-wasm-BaMgQAJZ.js} +1 -1
- package/dist/ui/index.html +14 -13
- package/dist/ui/packages/webapp/index.html +14 -13
- package/package.json +1 -1
- package/dist/ui/assets/anthropic-BBdzKe_5.js +0 -39
- package/dist/ui/assets/azure-openai-responses-C_P8NgJ8.js +0 -1
- package/dist/ui/assets/github-copilot-headers-BuUn5v2j.js +0 -1
- package/dist/ui/assets/google-gemini-cli-BZEjJgF7.js +0 -2
- package/dist/ui/assets/google-vertex-CfBb7__M.js +0 -1
- package/dist/ui/assets/openai-completions-CbSb9DNR.js +0 -5
- package/dist/ui/assets/openai-responses-32eOEVfr.js +0 -1
- package/dist/ui/assets/simple-options-p0Mmb-pN.js +0 -1
- /package/dist/ui/assets/{__vite-browser-external-zdR8bj89.js → __vite-browser-external-BD_HvDfc.js} +0 -0
- /package/dist/ui/assets/{addon-fit-Dq6sROpn.js → addon-fit-_YHcqy0h.js} +0 -0
- /package/dist/ui/assets/{browser-Cpl52X72.js → browser-Cl7Q1LkV.js} +0 -0
- /package/dist/ui/assets/{bsh-watchdog-B07eNo5F.js → bsh-watchdog-5FY6DxLX.js} +0 -0
- /package/dist/ui/assets/{chat-fixture-BPoXQA7f.js → chat-fixture-Dp2mIM1B.js} +0 -0
- /package/dist/ui/assets/{db-Dir1_tnZ.js → db-CDfQGWkv.js} +0 -0
- /package/dist/ui/assets/{fetch-body-T80zl4z4.js → fetch-body-DJGM6_Jl.js} +0 -0
- /package/dist/ui/assets/{global-db-DVnWv0oM.js → global-db-D767Oa4m.js} +0 -0
- /package/dist/ui/assets/{lick-manager-proxy-BZUMVDTP.js → lick-manager-proxy-DYlDsj9K.js} +0 -0
- /package/dist/ui/assets/{magick-wasm-kVMRnisO.js → magick-wasm-CNSmo9gu.js} +0 -0
- /package/dist/ui/assets/{oauth-service-38tFqQEB.js → oauth-service-CKR4S63v.js} +0 -0
- /package/dist/ui/assets/{offscreen-client-82Pn8cmc.js → offscreen-client-BM0UHxmA.js} +0 -0
- /package/dist/ui/assets/{openai-BSNYAgA1.js → openai-CQsomflW.js} +0 -0
- /package/dist/ui/assets/{path-utils-BqLAyaya.js → path-utils-CNNVZ3-O.js} +0 -0
- /package/dist/ui/assets/{pdfjs-CFev-Ohh.js → pdfjs-BGlny-4w.js} +0 -0
- /package/dist/ui/assets/{rum-wVO4iYd-.js → rum-C22a_afY.js} +0 -0
- /package/dist/ui/assets/{secret-masking-DYVLKOtn.js → secret-masking-D8cHWx2y.js} +0 -0
- /package/dist/ui/assets/{slicc-editor-CuCrLc0u.js → slicc-editor-Bv8eZLtW.js} +0 -0
- /package/dist/ui/assets/{src-CtySarJL.js → src-Bd0ucr8W.js} +0 -0
- /package/dist/ui/assets/{xterm-BS-IjYp6.js → xterm-GX0WTpdZ.js} +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import{a as e,i as t,n,s as r,t as i}from"./simple-options-CRMUB9za.js";import{d as a,l as o,u as s}from"./index-n7dM8Ny6.js";import{t as c}from"./headers-DkHU-pcw.js";import{t as l}from"./sanitize-unicode-BD2XKRoV.js";import{i as u,n as ee,t as d}from"./github-copilot-headers-B6Fvsk-Y.js";function f(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n}function p(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)}var te=function(){let{crypto:e}=globalThis;if(e?.randomUUID)return te=e.randomUUID.bind(e),e.randomUUID();let t=new Uint8Array(1),n=e?()=>e.getRandomValues(t)[0]:()=>Math.random()*255&255;return`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(e^n()&15>>e/4).toString(16))};function m(e){return typeof e==`object`&&!!e&&(`name`in e&&e.name===`AbortError`||`message`in e&&String(e.message).includes(`FetchRequestCanceledException`))}var h=e=>{if(e instanceof Error)return e;if(typeof e==`object`&&e){try{if(Object.prototype.toString.call(e)===`[object Error]`){let t=Error(e.message,e.cause?{cause:e.cause}:{});return e.stack&&(t.stack=e.stack),e.cause&&!t.cause&&(t.cause=e.cause),e.name&&(t.name=e.name),t}}catch{}try{return Error(JSON.stringify(e))}catch{}}return Error(e)},g=class extends Error{},_=class e extends g{constructor(t,n,r,i,a){super(`${e.makeMessage(t,n,r)}`),this.status=t,this.headers=i,this.requestID=i?.get(`request-id`),this.error=n,this.type=a??null}static makeMessage(e,t,n){let r=t?.message?typeof t.message==`string`?t.message:JSON.stringify(t.message):t?JSON.stringify(t):n;return e&&r?`${e} ${r}`:e?`${e} status code (no body)`:r||`(no status code or body)`}static generate(t,n,r,i){if(!t||!i)return new ne({message:r,cause:h(n)});let a=n,o=a?.error?.type;return t===400?new ie(t,a,r,i,o):t===401?new ae(t,a,r,i,o):t===403?new oe(t,a,r,i,o):t===404?new se(t,a,r,i,o):t===409?new ce(t,a,r,i,o):t===422?new le(t,a,r,i,o):t===429?new ue(t,a,r,i,o):t>=500?new de(t,a,r,i,o):new e(t,a,r,i,o)}},v=class extends _{constructor({message:e}={}){super(void 0,void 0,e||`Request was aborted.`,void 0)}},ne=class extends _{constructor({message:e,cause:t}){super(void 0,void 0,e||`Connection error.`,void 0),t&&(this.cause=t)}},re=class extends ne{constructor({message:e}={}){super({message:e??`Request timed out.`})}},ie=class extends _{},ae=class extends _{},oe=class extends _{},se=class extends _{},ce=class extends _{},le=class extends _{},ue=class extends _{},de=class extends _{},fe=/^[a-z][a-z0-9+.-]*:/i,pe=e=>fe.test(e),me=e=>(me=Array.isArray,me(e)),he=me;function ge(e){return typeof e==`object`?e??{}:{}}function _e(e){if(!e)return!0;for(let t in e)return!1;return!0}function ve(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var ye=(e,t)=>{if(typeof t!=`number`||!Number.isInteger(t))throw new g(`${e} must be an integer`);if(t<0)throw new g(`${e} must be a positive integer`);return t},be=e=>{try{return JSON.parse(e)}catch{return}},xe=e=>new Promise(t=>setTimeout(t,e)),y=`0.91.1`,Se=()=>typeof window<`u`&&window.document!==void 0&&typeof navigator<`u`;function Ce(){return typeof Deno<`u`&&Deno.build!=null?`deno`:typeof EdgeRuntime<`u`?`edge`:Object.prototype.toString.call(globalThis.process===void 0?0:globalThis.process)===`[object process]`?`node`:`unknown`}var we=()=>{let e=Ce();if(e===`deno`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":y,"X-Stainless-OS":De(Deno.build.os),"X-Stainless-Arch":Ee(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":y,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":`edge`,"X-Stainless-Runtime-Version":globalThis.process.version};if(e===`node`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":y,"X-Stainless-OS":De(globalThis.process.platform??`unknown`),"X-Stainless-Arch":Ee(globalThis.process.arch??`unknown`),"X-Stainless-Runtime":`node`,"X-Stainless-Runtime-Version":globalThis.process.version??`unknown`};let t=Te();return t?{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":y,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`unknown`,"X-Stainless-Runtime":`browser:${t.browser}`,"X-Stainless-Runtime-Version":t.version}:{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":y,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`unknown`,"X-Stainless-Runtime":`unknown`,"X-Stainless-Runtime-Version":`unknown`}};function Te(){if(typeof navigator>`u`||!navigator)return null;for(let{key:e,pattern:t}of[{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/}]){let n=t.exec(navigator.userAgent);if(n)return{browser:e,version:`${n[1]||0}.${n[2]||0}.${n[3]||0}`}}return null}var Ee=e=>e===`x32`?`x32`:e===`x86_64`||e===`x64`?`x64`:e===`arm`?`arm`:e===`aarch64`||e===`arm64`?`arm64`:e?`other:${e}`:`unknown`,De=e=>(e=e.toLowerCase(),e.includes(`ios`)?`iOS`:e===`android`?`Android`:e===`darwin`?`MacOS`:e===`win32`?`Windows`:e===`freebsd`?`FreeBSD`:e===`openbsd`?`OpenBSD`:e===`linux`?`Linux`:e?`Other:${e}`:`Unknown`),Oe,ke=()=>Oe??=we();function Ae(){if(typeof fetch<`u`)return fetch;throw 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 je(...e){let t=globalThis.ReadableStream;if(t===void 0)throw Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new t(...e)}function Me(e){let t=Symbol.asyncIterator in e?e[Symbol.asyncIterator]():e[Symbol.iterator]();return je({start(){},async pull(e){let{done:n,value:r}=await t.next();n?e.close():e.enqueue(r)},async cancel(){await t.return?.()}})}function Ne(e){if(e[Symbol.asyncIterator])return e;let t=e.getReader();return{async next(){try{let e=await t.read();return e?.done&&t.releaseLock(),e}catch(e){throw t.releaseLock(),e}},async return(){let e=t.cancel();return t.releaseLock(),await e,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function Pe(e){if(typeof e!=`object`||!e)return;if(e[Symbol.asyncIterator]){await e[Symbol.asyncIterator]().return?.();return}let t=e.getReader(),n=t.cancel();t.releaseLock(),await n}var Fe=({headers:e,body:t})=>({bodyHeaders:{"content-type":`application/json`},body:JSON.stringify(t)});function Ie(e){return Object.entries(e).filter(([e,t])=>t!==void 0).map(([e,t])=>{if(typeof t==`string`||typeof t==`number`||typeof t==`boolean`)return`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;if(t===null)return`${encodeURIComponent(e)}=`;throw new g(`Cannot stringify type ${typeof t}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`)}).join(`&`)}function Le(e){let t=0;for(let n of e)t+=n.length;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}var Re;function ze(e){let t;return(Re??=(t=new globalThis.TextEncoder,t.encode.bind(t)))(e)}var Be;function Ve(e){let t;return(Be??=(t=new globalThis.TextDecoder,t.decode.bind(t)))(e)}var b,x,He=class{constructor(){b.set(this,void 0),x.set(this,void 0),f(this,b,new Uint8Array,`f`),f(this,x,null,`f`)}decode(e){if(e==null)return[];let t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e==`string`?ze(e):e;f(this,b,Le([p(this,b,`f`),t]),`f`);let n=[],r;for(;(r=Ue(p(this,b,`f`),p(this,x,`f`)))!=null;){if(r.carriage&&p(this,x,`f`)==null){f(this,x,r.index,`f`);continue}if(p(this,x,`f`)!=null&&(r.index!==p(this,x,`f`)+1||r.carriage)){n.push(Ve(p(this,b,`f`).subarray(0,p(this,x,`f`)-1))),f(this,b,p(this,b,`f`).subarray(p(this,x,`f`)),`f`),f(this,x,null,`f`);continue}let e=p(this,x,`f`)===null?r.preceding:r.preceding-1,t=Ve(p(this,b,`f`).subarray(0,e));n.push(t),f(this,b,p(this,b,`f`).subarray(r.index),`f`),f(this,x,null,`f`)}return n}flush(){return p(this,b,`f`).length?this.decode(`
|
|
2
|
+
`):[]}};b=new WeakMap,x=new WeakMap,He.NEWLINE_CHARS=new Set([`
|
|
3
|
+
`,`\r`]),He.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function Ue(e,t){for(let n=t??0;n<e.length;n++){if(e[n]===10)return{preceding:n,index:n+1,carriage:!1};if(e[n]===13)return{preceding:n,index:n+1,carriage:!0}}return null}function We(e){for(let t=0;t<e.length-1;t++){if(e[t]===10&&e[t+1]===10||e[t]===13&&e[t+1]===13)return t+2;if(e[t]===13&&e[t+1]===10&&t+3<e.length&&e[t+2]===13&&e[t+3]===10)return t+4}return-1}var Ge={off:0,error:200,warn:300,info:400,debug:500},Ke=(e,t,n)=>{if(e){if(ve(Ge,e))return e;S(n).warn(`${t} was set to ${JSON.stringify(e)}, expected one of ${JSON.stringify(Object.keys(Ge))}`)}};function qe(){}function Je(e,t,n){return!t||Ge[e]>Ge[n]?qe:t[e].bind(t)}var Ye={error:qe,warn:qe,info:qe,debug:qe},Xe=new WeakMap;function S(e){let t=e.logger,n=e.logLevel??`off`;if(!t)return Ye;let r=Xe.get(t);if(r&&r[0]===n)return r[1];let i={error:Je(`error`,t,n),warn:Je(`warn`,t,n),info:Je(`info`,t,n),debug:Je(`debug`,t,n)};return Xe.set(t,[n,i]),i}var C=e=>(e.options&&(e.options={...e.options},delete e.options.headers),e.headers&&=Object.fromEntries((e.headers instanceof Headers?[...e.headers]:Object.entries(e.headers)).map(([e,t])=>[e,e.toLowerCase()===`x-api-key`||e.toLowerCase()===`authorization`||e.toLowerCase()===`cookie`||e.toLowerCase()===`set-cookie`?`***`:t])),`retryOfRequestLogID`in e&&(e.retryOfRequestLogID&&(e.retryOf=e.retryOfRequestLogID),delete e.retryOfRequestLogID),e),Ze,Qe=class e{constructor(e,t,n){this.iterator=e,Ze.set(this,void 0),this.controller=t,f(this,Ze,n,`f`)}static fromSSEResponse(t,n,r){let i=!1,a=r?S(r):console;async function*o(){if(i)throw new g("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");i=!0;let e=!1;try{for await(let e of $e(t,n)){if(e.event===`completion`)try{yield JSON.parse(e.data)}catch(t){throw a.error(`Could not parse message into JSON:`,e.data),a.error(`From chunk:`,e.raw),t}if(e.event===`message_start`||e.event===`message_delta`||e.event===`message_stop`||e.event===`content_block_start`||e.event===`content_block_delta`||e.event===`content_block_stop`||e.event===`message`||e.event===`user.message`||e.event===`user.interrupt`||e.event===`user.tool_confirmation`||e.event===`user.custom_tool_result`||e.event===`agent.message`||e.event===`agent.thinking`||e.event===`agent.tool_use`||e.event===`agent.tool_result`||e.event===`agent.mcp_tool_use`||e.event===`agent.mcp_tool_result`||e.event===`agent.custom_tool_use`||e.event===`agent.thread_context_compacted`||e.event===`session.status_running`||e.event===`session.status_idle`||e.event===`session.status_rescheduled`||e.event===`session.status_terminated`||e.event===`session.error`||e.event===`session.deleted`||e.event===`span.model_request_start`||e.event===`span.model_request_end`)try{yield JSON.parse(e.data)}catch(t){throw a.error(`Could not parse message into JSON:`,e.data),a.error(`From chunk:`,e.raw),t}if(e.event!==`ping`&&e.event===`error`){let n=be(e.data)??e.data,r=n?.error?.type;throw new _(void 0,n,void 0,t.headers,r)}}e=!0}catch(e){if(m(e))return;throw e}finally{e||n.abort()}}return new e(o,n,r)}static fromReadableStream(t,n,r){let i=!1;async function*a(){let e=new He,n=Ne(t);for await(let t of n)for(let n of e.decode(t))yield n;for(let t of e.flush())yield t}async function*o(){if(i)throw new g("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");i=!0;let e=!1;try{for await(let t of a())e||t&&(yield JSON.parse(t));e=!0}catch(e){if(m(e))return;throw e}finally{e||n.abort()}}return new e(o,n,r)}[(Ze=new WeakMap,Symbol.asyncIterator)](){return this.iterator()}tee(){let t=[],n=[],r=this.iterator(),i=e=>({next:()=>{if(e.length===0){let e=r.next();t.push(e),n.push(e)}return e.shift()}});return[new e(()=>i(t),this.controller,p(this,Ze,`f`)),new e(()=>i(n),this.controller,p(this,Ze,`f`))]}toReadableStream(){let e=this,t;return je({async start(){t=e[Symbol.asyncIterator]()},async pull(e){try{let{value:n,done:r}=await t.next();if(r)return e.close();let i=ze(JSON.stringify(n)+`
|
|
4
|
+
`);e.enqueue(i)}catch(t){e.error(t)}},async cancel(){await t.return?.()}})}};async function*$e(e,t){if(!e.body)throw t.abort(),globalThis.navigator!==void 0&&globalThis.navigator.product===`ReactNative`?new g(`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 g(`Attempted to iterate over a response with no body`);let n=new tt,r=new He,i=Ne(e.body);for await(let e of et(i))for(let t of r.decode(e)){let e=n.decode(t);e&&(yield e)}for(let e of r.flush()){let t=n.decode(e);t&&(yield t)}}async function*et(e){let t=new Uint8Array;for await(let n of e){if(n==null)continue;let e=n instanceof ArrayBuffer?new Uint8Array(n):typeof n==`string`?ze(n):n,r=new Uint8Array(t.length+e.length);r.set(t),r.set(e,t.length),t=r;let i;for(;(i=We(t))!==-1;)yield t.slice(0,i),t=t.slice(i)}t.length>0&&(yield t)}var tt=class{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(e){if(e.endsWith(`\r`)&&(e=e.substring(0,e.length-1)),!e){if(!this.event&&!this.data.length)return null;let e={event:this.event,data:this.data.join(`
|
|
5
|
+
`),raw:this.chunks};return this.event=null,this.data=[],this.chunks=[],e}if(this.chunks.push(e),e.startsWith(`:`))return null;let[t,n,r]=nt(e,`:`);return r.startsWith(` `)&&(r=r.substring(1)),t===`event`?this.event=r:t===`data`&&this.data.push(r),null}};function nt(e,t){let n=e.indexOf(t);return n===-1?[e,``,``]:[e.substring(0,n),t,e.substring(n+t.length)]}async function rt(e,t){let{response:n,requestLogID:r,retryOfRequestLogID:i,startTime:a}=t,o=await(async()=>{if(t.options.stream)return S(e).debug(`response`,n.status,n.url,n.headers,n.body),t.options.__streamClass?t.options.__streamClass.fromSSEResponse(n,t.controller):Qe.fromSSEResponse(n,t.controller);if(n.status===204)return null;if(t.options.__binaryResponse)return n;let r=n.headers.get(`content-type`)?.split(`;`)[0]?.trim();return r?.includes(`application/json`)||r?.endsWith(`+json`)?n.headers.get(`content-length`)===`0`?void 0:it(await n.json(),n):await n.text()})();return S(e).debug(`[${r}] response parsed`,C({retryOfRequestLogID:i,url:n.url,status:n.status,body:o,durationMs:Date.now()-a})),o}function it(e,t){return!e||typeof e!=`object`||Array.isArray(e)?e:Object.defineProperty(e,`_request_id`,{value:t.headers.get(`request-id`),enumerable:!1})}var at,ot=class e extends Promise{constructor(e,t,n=rt){super(e=>{e(null)}),this.responsePromise=t,this.parseResponse=n,at.set(this,void 0),f(this,at,e,`f`)}_thenUnwrap(t){return new e(p(this,at,`f`),this.responsePromise,async(e,n)=>it(t(await this.parseResponse(e,n),n),n.response))}asResponse(){return this.responsePromise.then(e=>e.response)}async withResponse(){let[e,t]=await Promise.all([this.parse(),this.asResponse()]);return{data:e,response:t,request_id:t.headers.get(`request-id`)}}parse(){return this.parsedPromise||=this.responsePromise.then(e=>this.parseResponse(p(this,at,`f`),e)),this.parsedPromise}then(e,t){return this.parse().then(e,t)}catch(e){return this.parse().catch(e)}finally(e){return this.parse().finally(e)}};at=new WeakMap;var st,ct=class{constructor(e,t,n,r){st.set(this,void 0),f(this,st,e,`f`),this.options=r,this.response=t,this.body=n}hasNextPage(){return this.getPaginatedItems().length?this.nextPageRequestOptions()!=null:!1}async getNextPage(){let e=this.nextPageRequestOptions();if(!e)throw new g("No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.");return await p(this,st,`f`).requestAPIList(this.constructor,e)}async*iterPages(){let e=this;for(yield e;e.hasNextPage();)e=await e.getNextPage(),yield e}async*[(st=new WeakMap,Symbol.asyncIterator)](){for await(let e of this.iterPages())for(let t of e.getPaginatedItems())yield t}},lt=class extends ot{constructor(e,t,n){super(e,t,async(e,t)=>new n(e,t.response,await rt(e,t),t.options))}async*[Symbol.asyncIterator](){let e=await this;for await(let t of e)yield t}},w=class extends ct{constructor(e,t,n,r){super(e,t,n,r),this.data=n.data||[],this.has_more=n.has_more||!1,this.first_id=n.first_id||null,this.last_id=n.last_id||null}getPaginatedItems(){return this.data??[]}hasNextPage(){return this.has_more===!1?!1:super.hasNextPage()}nextPageRequestOptions(){if(this.options.query?.before_id){let e=this.first_id;return e?{...this.options,query:{...ge(this.options.query),before_id:e}}:null}let e=this.last_id;return e?{...this.options,query:{...ge(this.options.query),after_id:e}}:null}},T=class extends ct{constructor(e,t,n,r){super(e,t,n,r),this.data=n.data||[],this.next_page=n.next_page||null}getPaginatedItems(){return this.data??[]}nextPageRequestOptions(){let e=this.next_page;return e?{...this.options,query:{...ge(this.options.query),page:e}}:null}},ut=()=>{if(typeof File>`u`){let{process:e}=globalThis,t=typeof e?.versions?.node==`string`&&parseInt(e.versions.node.split(`.`))<20;throw Error("`File` is not defined as a global, which is required for file uploads."+(t?" Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`.":``))}};function E(e,t,n){return ut(),new File(e,t??`unknown_file`,n)}function dt(e,t){let n=typeof e==`object`&&!!e&&(`name`in e&&e.name&&String(e.name)||`url`in e&&e.url&&String(e.url)||`filename`in e&&e.filename&&String(e.filename)||`path`in e&&e.path&&String(e.path))||``;return t?n.split(/[\\/]/).pop()||void 0:n}var ft=e=>typeof e==`object`&&!!e&&typeof e[Symbol.asyncIterator]==`function`,pt=async(e,t,n=!0)=>({...e,body:await gt(e.body,t,n)}),mt=new WeakMap;function ht(e){let t=typeof e==`function`?e:e.fetch,n=mt.get(t);if(n)return n;let r=(async()=>{try{let e=`Response`in t?t.Response:(await t(`data:,`)).constructor,n=new FormData;return n.toString()!==await new e(n).text()}catch{return!0}})();return mt.set(t,r),r}var gt=async(e,t,n=!0)=>{if(!await ht(t))throw TypeError(`The provided fetch function does not support file uploads with the current global FormData class.`);let r=new FormData;return await Promise.all(Object.entries(e||{}).map(([e,t])=>vt(r,e,t,n))),r},_t=e=>e instanceof Blob&&`name`in e,vt=async(e,t,n,r)=>{if(n!==void 0){if(n==null)throw TypeError(`Received null for "${t}"; to pass null in FormData, you must use the string 'null'`);if(typeof n==`string`||typeof n==`number`||typeof n==`boolean`)e.append(t,String(n));else if(n instanceof Response){let i={},a=n.headers.get(`Content-Type`);a&&(i={type:a}),e.append(t,E([await n.blob()],dt(n,r),i))}else if(ft(n))e.append(t,E([await new Response(Me(n)).blob()],dt(n,r)));else if(_t(n))e.append(t,E([n],dt(n,r),{type:n.type}));else if(Array.isArray(n))await Promise.all(n.map(n=>vt(e,t+`[]`,n,r)));else if(typeof n==`object`)await Promise.all(Object.entries(n).map(([n,i])=>vt(e,`${t}[${n}]`,i,r)));else throw TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${n} instead`)}},yt=e=>typeof e==`object`&&!!e&&typeof e.size==`number`&&typeof e.type==`string`&&typeof e.text==`function`&&typeof e.slice==`function`&&typeof e.arrayBuffer==`function`,bt=e=>typeof e==`object`&&!!e&&typeof e.name==`string`&&typeof e.lastModified==`number`&&yt(e),xt=e=>typeof e==`object`&&!!e&&typeof e.url==`string`&&typeof e.blob==`function`;async function St(e,t,n){if(ut(),e=await e,t||=dt(e,!0),bt(e))return e instanceof File&&t==null&&n==null?e:E([await e.arrayBuffer()],t??e.name,{type:e.type,lastModified:e.lastModified,...n});if(xt(e)){let r=await e.blob();return t||=new URL(e.url).pathname.split(/[\\/]/).pop(),E(await Ct(r),t,n)}let r=await Ct(e);if(!n?.type){let e=r.find(e=>typeof e==`object`&&`type`in e&&e.type);typeof e==`string`&&(n={...n,type:e})}return E(r,t,n)}async function Ct(e){let t=[];if(typeof e==`string`||ArrayBuffer.isView(e)||e instanceof ArrayBuffer)t.push(e);else if(yt(e))t.push(e instanceof Blob?e:await e.arrayBuffer());else if(ft(e))for await(let n of e)t.push(...await Ct(n));else{let t=e?.constructor?.name;throw Error(`Unexpected data type: ${typeof e}${t?`; constructor: ${t}`:``}${wt(e)}`)}return t}function wt(e){return typeof e!=`object`||!e?``:`; props: [${Object.getOwnPropertyNames(e).map(e=>`"${e}"`).join(`, `)}]`}var D=class{constructor(e){this._client=e}},Tt=Symbol.for(`brand.privateNullableHeaders`);function*Et(e){if(!e)return;if(Tt in e){let{values:t,nulls:n}=e;yield*t.entries();for(let e of n)yield[e,null];return}let t=!1,n;e instanceof Headers?n=e.entries():he(e)?n=e:(t=!0,n=Object.entries(e??{}));for(let e of n){let n=e[0];if(typeof n!=`string`)throw TypeError(`expected header name to be a string`);let r=he(e[1])?e[1]:[e[1]],i=!1;for(let e of r)e!==void 0&&(t&&!i&&(i=!0,yield[n,null]),yield[n,e])}}var O=e=>{let t=new Headers,n=new Set;for(let r of e){let e=new Set;for(let[i,a]of Et(r)){let r=i.toLowerCase();e.has(r)||(t.delete(i),e.add(r)),a===null?(t.delete(i),n.add(r)):(t.append(i,a),n.delete(r))}}return{[Tt]:!0,values:t,nulls:n}};function Dt(e){return e.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g,encodeURIComponent)}var Ot=Object.freeze(Object.create(null)),k=((e=Dt)=>function(t,...n){if(t.length===1)return t[0];let r=!1,i=[],a=t.reduce((t,a,o)=>{/[?#]/.test(a)&&(r=!0);let s=n[o],c=(r?encodeURIComponent:e)(``+s);return o!==n.length&&(s==null||typeof s==`object`&&s.toString===Object.getPrototypeOf(Object.getPrototypeOf(s.hasOwnProperty??Ot)??Ot)?.toString)&&(c=s+``,i.push({start:t.length+a.length,length:c.length,error:`Value of type ${Object.prototype.toString.call(s).slice(8,-1)} is not a valid path parameter`})),t+a+(o===n.length?``:c)},``),o=a.split(/[?#]/,1)[0],s=/(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi,c;for(;(c=s.exec(o))!==null;)i.push({start:c.index,length:c[0].length,error:`Value "${c[0]}" can\'t be safely passed as a path parameter`});if(i.sort((e,t)=>e.start-t.start),i.length>0){let e=0,t=i.reduce((t,n)=>{let r=` `.repeat(n.start-e),i=`^`.repeat(n.length);return e=n.start+n.length,t+r+i},``);throw new g(`Path parameters result in path with invalid segments:\n${i.map(e=>e.error).join(`
|
|
6
|
+
`)}\n${a}\n${t}`)}return a})(Dt),kt=class extends D{create(e,t){let{betas:n,...r}=e;return this._client.post(`/v1/environments?beta=true`,{body:r,...t,headers:O([{"anthropic-beta":[...n??[],`managed-agents-2026-04-01`].toString()},t?.headers])})}retrieve(e,t={},n){let{betas:r}=t??{};return this._client.get(k`/v1/environments/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}update(e,t,n){let{betas:r,...i}=t;return this._client.post(k`/v1/environments/${e}?beta=true`,{body:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}list(e={},t){let{betas:n,...r}=e??{};return this._client.getAPIList(`/v1/environments?beta=true`,T,{query:r,...t,headers:O([{"anthropic-beta":[...n??[],`managed-agents-2026-04-01`].toString()},t?.headers])})}delete(e,t={},n){let{betas:r}=t??{};return this._client.delete(k`/v1/environments/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}archive(e,t={},n){let{betas:r}=t??{};return this._client.post(k`/v1/environments/${e}/archive?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}},At=Symbol(`anthropic.sdk.stainlessHelper`);function jt(e){return typeof e==`object`&&!!e&&At in e}function Mt(e,t){let n=new Set;if(e)for(let t of e)jt(t)&&n.add(t[At]);if(t){for(let e of t)if(jt(e)&&n.add(e[At]),Array.isArray(e.content))for(let t of e.content)jt(t)&&n.add(t[At])}return Array.from(n)}function Nt(e,t){let n=Mt(e,t);return n.length===0?{}:{"x-stainless-helper":n.join(`, `)}}function Pt(e){return jt(e)?{"x-stainless-helper":e[At]}:{}}var Ft=class extends D{list(e={},t){let{betas:n,...r}=e??{};return this._client.getAPIList(`/v1/files?beta=true`,w,{query:r,...t,headers:O([{"anthropic-beta":[...n??[],`files-api-2025-04-14`].toString()},t?.headers])})}delete(e,t={},n){let{betas:r}=t??{};return this._client.delete(k`/v1/files/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`files-api-2025-04-14`].toString()},n?.headers])})}download(e,t={},n){let{betas:r}=t??{};return this._client.get(k`/v1/files/${e}/content?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`files-api-2025-04-14`].toString(),Accept:`application/binary`},n?.headers]),__binaryResponse:!0})}retrieveMetadata(e,t={},n){let{betas:r}=t??{};return this._client.get(k`/v1/files/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`files-api-2025-04-14`].toString()},n?.headers])})}upload(e,t){let{betas:n,...r}=e;return this._client.post(`/v1/files?beta=true`,pt({body:r,...t,headers:O([{"anthropic-beta":[...n??[],`files-api-2025-04-14`].toString()},Pt(r.file),t?.headers])},this._client))}},It=class extends D{retrieve(e,t={},n){let{betas:r}=t??{};return this._client.get(k`/v1/models/${e}?beta=true`,{...n,headers:O([{...r?.toString()==null?void 0:{"anthropic-beta":r?.toString()}},n?.headers])})}list(e={},t){let{betas:n,...r}=e??{};return this._client.getAPIList(`/v1/models?beta=true`,w,{query:r,...t,headers:O([{...n?.toString()==null?void 0:{"anthropic-beta":n?.toString()}},t?.headers])})}},Lt=class extends D{create(e,t){let{betas:n,...r}=e;return this._client.post(`/v1/user_profiles?beta=true`,{body:r,...t,headers:O([{"anthropic-beta":[...n??[],`user-profiles-2026-03-24`].toString()},t?.headers])})}retrieve(e,t={},n){let{betas:r}=t??{};return this._client.get(k`/v1/user_profiles/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`user-profiles-2026-03-24`].toString()},n?.headers])})}update(e,t,n){let{betas:r,...i}=t;return this._client.post(k`/v1/user_profiles/${e}?beta=true`,{body:i,...n,headers:O([{"anthropic-beta":[...r??[],`user-profiles-2026-03-24`].toString()},n?.headers])})}list(e={},t){let{betas:n,...r}=e??{};return this._client.getAPIList(`/v1/user_profiles?beta=true`,T,{query:r,...t,headers:O([{"anthropic-beta":[...n??[],`user-profiles-2026-03-24`].toString()},t?.headers])})}createEnrollmentURL(e,t={},n){let{betas:r}=t??{};return this._client.post(k`/v1/user_profiles/${e}/enrollment_url?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`user-profiles-2026-03-24`].toString()},n?.headers])})}},Rt=class extends D{list(e,t={},n){let{betas:r,...i}=t??{};return this._client.getAPIList(k`/v1/agents/${e}/versions?beta=true`,T,{query:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}},zt=class extends D{constructor(){super(...arguments),this.versions=new Rt(this._client)}create(e,t){let{betas:n,...r}=e;return this._client.post(`/v1/agents?beta=true`,{body:r,...t,headers:O([{"anthropic-beta":[...n??[],`managed-agents-2026-04-01`].toString()},t?.headers])})}retrieve(e,t={},n){let{betas:r,...i}=t??{};return this._client.get(k`/v1/agents/${e}?beta=true`,{query:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}update(e,t,n){let{betas:r,...i}=t;return this._client.post(k`/v1/agents/${e}?beta=true`,{body:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}list(e={},t){let{betas:n,...r}=e??{};return this._client.getAPIList(`/v1/agents?beta=true`,T,{query:r,...t,headers:O([{"anthropic-beta":[...n??[],`managed-agents-2026-04-01`].toString()},t?.headers])})}archive(e,t={},n){let{betas:r}=t??{};return this._client.post(k`/v1/agents/${e}/archive?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}};zt.Versions=Rt;var Bt=class extends D{create(e,t,n){let{view:r,betas:i,...a}=t;return this._client.post(k`/v1/memory_stores/${e}/memories?beta=true`,{query:{view:r},body:a,...n,headers:O([{"anthropic-beta":[...i??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}retrieve(e,t,n){let{memory_store_id:r,betas:i,...a}=t;return this._client.get(k`/v1/memory_stores/${r}/memories/${e}?beta=true`,{query:a,...n,headers:O([{"anthropic-beta":[...i??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}update(e,t,n){let{memory_store_id:r,view:i,betas:a,...o}=t;return this._client.post(k`/v1/memory_stores/${r}/memories/${e}?beta=true`,{query:{view:i},body:o,...n,headers:O([{"anthropic-beta":[...a??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}list(e,t={},n){let{betas:r,...i}=t??{};return this._client.getAPIList(k`/v1/memory_stores/${e}/memories?beta=true`,T,{query:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}delete(e,t,n){let{memory_store_id:r,expected_content_sha256:i,betas:a}=t;return this._client.delete(k`/v1/memory_stores/${r}/memories/${e}?beta=true`,{query:{expected_content_sha256:i},...n,headers:O([{"anthropic-beta":[...a??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}},Vt=class extends D{retrieve(e,t,n){let{memory_store_id:r,betas:i,...a}=t;return this._client.get(k`/v1/memory_stores/${r}/memory_versions/${e}?beta=true`,{query:a,...n,headers:O([{"anthropic-beta":[...i??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}list(e,t={},n){let{betas:r,...i}=t??{};return this._client.getAPIList(k`/v1/memory_stores/${e}/memory_versions?beta=true`,T,{query:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}redact(e,t,n){let{memory_store_id:r,betas:i}=t;return this._client.post(k`/v1/memory_stores/${r}/memory_versions/${e}/redact?beta=true`,{...n,headers:O([{"anthropic-beta":[...i??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}},Ht=class extends D{constructor(){super(...arguments),this.memories=new Bt(this._client),this.memoryVersions=new Vt(this._client)}create(e,t){let{betas:n,...r}=e;return this._client.post(`/v1/memory_stores?beta=true`,{body:r,...t,headers:O([{"anthropic-beta":[...n??[],`managed-agents-2026-04-01`].toString()},t?.headers])})}retrieve(e,t={},n){let{betas:r}=t??{};return this._client.get(k`/v1/memory_stores/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}update(e,t,n){let{betas:r,...i}=t;return this._client.post(k`/v1/memory_stores/${e}?beta=true`,{body:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}list(e={},t){let{betas:n,...r}=e??{};return this._client.getAPIList(`/v1/memory_stores?beta=true`,T,{query:r,...t,headers:O([{"anthropic-beta":[...n??[],`managed-agents-2026-04-01`].toString()},t?.headers])})}delete(e,t={},n){let{betas:r}=t??{};return this._client.delete(k`/v1/memory_stores/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}archive(e,t={},n){let{betas:r}=t??{};return this._client.post(k`/v1/memory_stores/${e}/archive?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}};Ht.Memories=Bt,Ht.MemoryVersions=Vt;var Ut={"claude-opus-4-20250514":8192,"claude-opus-4-0":8192,"claude-4-opus-20250514":8192,"anthropic.claude-opus-4-20250514-v1:0":8192,"claude-opus-4@20250514":8192,"claude-opus-4-1-20250805":8192,"anthropic.claude-opus-4-1-20250805-v1:0":8192,"claude-opus-4-1@20250805":8192};function Wt(e){return e?.output_format??e?.output_config?.format}function Gt(e,t,n){let r=Wt(t);return!t||!(`parse`in(r??{}))?{...e,content:e.content.map(e=>{if(e.type===`text`){let t=Object.defineProperty({...e},`parsed_output`,{value:null,enumerable:!1});return Object.defineProperty(t,`parsed`,{get(){return n.logger.warn("The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead."),null},enumerable:!1})}return e}),parsed_output:null}:Kt(e,t,n)}function Kt(e,t,n){let r=null,i=e.content.map(e=>{if(e.type===`text`){let i=qt(t,e.text);r===null&&(r=i);let a=Object.defineProperty({...e},`parsed_output`,{value:i,enumerable:!1});return Object.defineProperty(a,`parsed`,{get(){return n.logger.warn("The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead."),i},enumerable:!1})}return e});return{...e,content:i,parsed_output:r}}function qt(e,t){let n=Wt(e);if(n?.type!==`json_schema`)return null;try{return`parse`in n?n.parse(t):JSON.parse(t)}catch(e){throw new g(`Failed to parse structured output: ${e}`)}}var Jt=e=>{let t=0,n=[];for(;t<e.length;){let r=e[t];if(r===`\\`){t++;continue}if(r===`{`){n.push({type:`brace`,value:`{`}),t++;continue}if(r===`}`){n.push({type:`brace`,value:`}`}),t++;continue}if(r===`[`){n.push({type:`paren`,value:`[`}),t++;continue}if(r===`]`){n.push({type:`paren`,value:`]`}),t++;continue}if(r===`:`){n.push({type:`separator`,value:`:`}),t++;continue}if(r===`,`){n.push({type:`delimiter`,value:`,`}),t++;continue}if(r===`"`){let i=``,a=!1;for(r=e[++t];r!==`"`;){if(t===e.length){a=!0;break}if(r===`\\`){if(t++,t===e.length){a=!0;break}i+=r+e[t],r=e[++t]}else i+=r,r=e[++t]}r=e[++t],a||n.push({type:`string`,value:i});continue}if(r&&/\s/.test(r)){t++;continue}let i=/[0-9]/;if(r&&i.test(r)||r===`-`||r===`.`){let a=``;for(r===`-`&&(a+=r,r=e[++t]);r&&i.test(r)||r===`.`;)a+=r,r=e[++t];n.push({type:`number`,value:a});continue}let a=/[a-z]/i;if(r&&a.test(r)){let i=``;for(;r&&a.test(r)&&t!==e.length;)i+=r,r=e[++t];if(i==`true`||i==`false`||i===`null`)n.push({type:`name`,value:i});else{t++;continue}continue}t++}return n},Yt=e=>{if(e.length===0)return e;let t=e[e.length-1];switch(t.type){case`separator`:return e=e.slice(0,e.length-1),Yt(e);case`number`:let n=t.value[t.value.length-1];if(n===`.`||n===`-`)return e=e.slice(0,e.length-1),Yt(e);case`string`:let r=e[e.length-2];if(r?.type===`delimiter`||r?.type===`brace`&&r.value===`{`)return e=e.slice(0,e.length-1),Yt(e);break;case`delimiter`:return e=e.slice(0,e.length-1),Yt(e)}return e},Xt=e=>{let t=[];return e.map(e=>{e.type===`brace`&&(e.value===`{`?t.push(`}`):t.splice(t.lastIndexOf(`}`),1)),e.type===`paren`&&(e.value===`[`?t.push(`]`):t.splice(t.lastIndexOf(`]`),1))}),t.length>0&&t.reverse().map(t=>{t===`}`?e.push({type:`brace`,value:`}`}):t===`]`&&e.push({type:`paren`,value:`]`})}),e},Zt=e=>{let t=``;return e.map(e=>{switch(e.type){case`string`:t+=`"`+e.value+`"`;break;default:t+=e.value;break}}),t},Qt=e=>JSON.parse(Zt(Xt(Yt(Jt(e))))),A,j,M,$t,en,N,tn,nn,P,F,I,rn,an,L,on,sn,R,cn,ln,un,dn,fn,pn,mn,hn=`__json_buf`;function gn(e){return e.type===`tool_use`||e.type===`server_tool_use`||e.type===`mcp_tool_use`}var _n=class e{constructor(e,t){A.add(this),this.messages=[],this.receivedMessages=[],j.set(this,void 0),M.set(this,null),this.controller=new AbortController,$t.set(this,void 0),en.set(this,()=>{}),N.set(this,()=>{}),tn.set(this,void 0),nn.set(this,()=>{}),P.set(this,()=>{}),F.set(this,{}),I.set(this,!1),rn.set(this,!1),an.set(this,!1),L.set(this,!1),on.set(this,void 0),sn.set(this,void 0),R.set(this,void 0),un.set(this,e=>{if(f(this,rn,!0,`f`),m(e)&&(e=new v),e instanceof v)return f(this,an,!0,`f`),this._emit(`abort`,e);if(e instanceof g)return this._emit(`error`,e);if(e instanceof Error){let t=new g(e.message);return t.cause=e,this._emit(`error`,t)}return this._emit(`error`,new g(String(e)))}),f(this,$t,new Promise((e,t)=>{f(this,en,e,`f`),f(this,N,t,`f`)}),`f`),f(this,tn,new Promise((e,t)=>{f(this,nn,e,`f`),f(this,P,t,`f`)}),`f`),p(this,$t,`f`).catch(()=>{}),p(this,tn,`f`).catch(()=>{}),f(this,M,e,`f`),f(this,R,t?.logger??console,`f`)}get response(){return p(this,on,`f`)}get request_id(){return p(this,sn,`f`)}async withResponse(){f(this,L,!0,`f`);let e=await p(this,$t,`f`);if(!e)throw Error("Could not resolve a `Response` object");return{data:this,response:e,request_id:e.headers.get(`request-id`)}}static fromReadableStream(t){let n=new e(null);return n._run(()=>n._fromReadableStream(t)),n}static createMessage(t,n,r,{logger:i}={}){let a=new e(n,{logger:i});for(let e of n.messages)a._addMessageParam(e);return f(a,M,{...n,stream:!0},`f`),a._run(()=>a._createMessage(t,{...n,stream:!0},{...r,headers:{...r?.headers,"X-Stainless-Helper-Method":`stream`}})),a}_run(e){e().then(()=>{this._emitFinal(),this._emit(`end`)},p(this,un,`f`))}_addMessageParam(e){this.messages.push(e)}_addMessage(e,t=!0){this.receivedMessages.push(e),t&&this._emit(`message`,e)}async _createMessage(e,t,n){let r=n?.signal,i;r&&(r.aborted&&this.controller.abort(),i=this.controller.abort.bind(this.controller),r.addEventListener(`abort`,i));try{p(this,A,`m`,dn).call(this);let{response:r,data:i}=await e.create({...t,stream:!0},{...n,signal:this.controller.signal}).withResponse();this._connected(r);for await(let e of i)p(this,A,`m`,fn).call(this,e);if(i.controller.signal?.aborted)throw new v;p(this,A,`m`,pn).call(this)}finally{r&&i&&r.removeEventListener(`abort`,i)}}_connected(e){this.ended||(f(this,on,e,`f`),f(this,sn,e?.headers.get(`request-id`),`f`),p(this,en,`f`).call(this,e),this._emit(`connect`))}get ended(){return p(this,I,`f`)}get errored(){return p(this,rn,`f`)}get aborted(){return p(this,an,`f`)}abort(){this.controller.abort()}on(e,t){return(p(this,F,`f`)[e]||(p(this,F,`f`)[e]=[])).push({listener:t}),this}off(e,t){let n=p(this,F,`f`)[e];if(!n)return this;let r=n.findIndex(e=>e.listener===t);return r>=0&&n.splice(r,1),this}once(e,t){return(p(this,F,`f`)[e]||(p(this,F,`f`)[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,n)=>{f(this,L,!0,`f`),e!==`error`&&this.once(`error`,n),this.once(e,t)})}async done(){f(this,L,!0,`f`),await p(this,tn,`f`)}get currentMessage(){return p(this,j,`f`)}async finalMessage(){return await this.done(),p(this,A,`m`,cn).call(this)}async finalText(){return await this.done(),p(this,A,`m`,ln).call(this)}_emit(e,...t){if(p(this,I,`f`))return;e===`end`&&(f(this,I,!0,`f`),p(this,nn,`f`).call(this));let n=p(this,F,`f`)[e];if(n&&(p(this,F,`f`)[e]=n.filter(e=>!e.once),n.forEach(({listener:e})=>e(...t))),e===`abort`){let e=t[0];!p(this,L,`f`)&&!n?.length&&Promise.reject(e),p(this,N,`f`).call(this,e),p(this,P,`f`).call(this,e),this._emit(`end`);return}if(e===`error`){let e=t[0];!p(this,L,`f`)&&!n?.length&&Promise.reject(e),p(this,N,`f`).call(this,e),p(this,P,`f`).call(this,e),this._emit(`end`)}}_emitFinal(){this.receivedMessages.at(-1)&&this._emit(`finalMessage`,p(this,A,`m`,cn).call(this))}async _fromReadableStream(e,t){let n=t?.signal,r;n&&(n.aborted&&this.controller.abort(),r=this.controller.abort.bind(this.controller),n.addEventListener(`abort`,r));try{p(this,A,`m`,dn).call(this),this._connected(null);let t=Qe.fromReadableStream(e,this.controller);for await(let e of t)p(this,A,`m`,fn).call(this,e);if(t.controller.signal?.aborted)throw new v;p(this,A,`m`,pn).call(this)}finally{n&&r&&n.removeEventListener(`abort`,r)}}[(j=new WeakMap,M=new WeakMap,$t=new WeakMap,en=new WeakMap,N=new WeakMap,tn=new WeakMap,nn=new WeakMap,P=new WeakMap,F=new WeakMap,I=new WeakMap,rn=new WeakMap,an=new WeakMap,L=new WeakMap,on=new WeakMap,sn=new WeakMap,R=new WeakMap,un=new WeakMap,A=new WeakSet,cn=function(){if(this.receivedMessages.length===0)throw new g(`stream ended without producing a Message with role=assistant`);return this.receivedMessages.at(-1)},ln=function(){if(this.receivedMessages.length===0)throw new g(`stream ended without producing a Message with role=assistant`);let e=this.receivedMessages.at(-1).content.filter(e=>e.type===`text`).map(e=>e.text);if(e.length===0)throw new g(`stream ended without producing a content block with type=text`);return e.join(` `)},dn=function(){this.ended||f(this,j,void 0,`f`)},fn=function(e){if(this.ended)return;let t=p(this,A,`m`,mn).call(this,e);switch(this._emit(`streamEvent`,e,t),e.type){case`content_block_delta`:{let n=t.content.at(-1);switch(e.delta.type){case`text_delta`:n.type===`text`&&this._emit(`text`,e.delta.text,n.text||``);break;case`citations_delta`:n.type===`text`&&this._emit(`citation`,e.delta.citation,n.citations??[]);break;case`input_json_delta`:gn(n)&&n.input&&this._emit(`inputJson`,e.delta.partial_json,n.input);break;case`thinking_delta`:n.type===`thinking`&&this._emit(`thinking`,e.delta.thinking,n.thinking);break;case`signature_delta`:n.type===`thinking`&&this._emit(`signature`,n.signature);break;case`compaction_delta`:n.type===`compaction`&&n.content&&this._emit(`compaction`,n.content);break;default:e.delta}break}case`message_stop`:this._addMessageParam(t),this._addMessage(Gt(t,p(this,M,`f`),{logger:p(this,R,`f`)}),!0);break;case`content_block_stop`:this._emit(`contentBlock`,t.content.at(-1));break;case`message_start`:f(this,j,t,`f`);break;case`content_block_start`:case`message_delta`:break}},pn=function(){if(this.ended)throw new g(`stream has ended, this shouldn't happen`);let e=p(this,j,`f`);if(!e)throw new g(`request ended without sending any chunks`);return f(this,j,void 0,`f`),Gt(e,p(this,M,`f`),{logger:p(this,R,`f`)})},mn=function(e){let t=p(this,j,`f`);if(e.type===`message_start`){if(t)throw new g(`Unexpected event order, got ${e.type} before receiving "message_stop"`);return e.message}if(!t)throw new g(`Unexpected event order, got ${e.type} before "message_start"`);switch(e.type){case`message_stop`:return t;case`message_delta`:return t.container=e.delta.container,t.stop_reason=e.delta.stop_reason,t.stop_sequence=e.delta.stop_sequence,t.usage.output_tokens=e.usage.output_tokens,t.context_management=e.context_management,e.usage.input_tokens!=null&&(t.usage.input_tokens=e.usage.input_tokens),e.usage.cache_creation_input_tokens!=null&&(t.usage.cache_creation_input_tokens=e.usage.cache_creation_input_tokens),e.usage.cache_read_input_tokens!=null&&(t.usage.cache_read_input_tokens=e.usage.cache_read_input_tokens),e.usage.server_tool_use!=null&&(t.usage.server_tool_use=e.usage.server_tool_use),e.usage.iterations!=null&&(t.usage.iterations=e.usage.iterations),t;case`content_block_start`:return t.content.push(e.content_block),t;case`content_block_delta`:{let n=t.content.at(e.index);switch(e.delta.type){case`text_delta`:n?.type===`text`&&(t.content[e.index]={...n,text:(n.text||``)+e.delta.text});break;case`citations_delta`:n?.type===`text`&&(t.content[e.index]={...n,citations:[...n.citations??[],e.delta.citation]});break;case`input_json_delta`:if(n&&gn(n)){let r=n[hn]||``;r+=e.delta.partial_json;let i={...n};if(Object.defineProperty(i,hn,{value:r,enumerable:!1,writable:!0}),r)try{i.input=Qt(r)}catch(e){let t=new g(`Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${e}. JSON: ${r}`);p(this,un,`f`).call(this,t)}t.content[e.index]=i}break;case`thinking_delta`:n?.type===`thinking`&&(t.content[e.index]={...n,thinking:n.thinking+e.delta.thinking});break;case`signature_delta`:n?.type===`thinking`&&(t.content[e.index]={...n,signature:e.delta.signature});break;case`compaction_delta`:n?.type===`compaction`&&(t.content[e.index]={...n,content:(n.content||``)+e.delta.content});break;default:e.delta}return t}case`content_block_stop`:return t}},Symbol.asyncIterator)](){let e=[],t=[],n=!1;return this.on(`streamEvent`,n=>{let r=t.shift();r?r.resolve(n):e.push(n)}),this.on(`end`,()=>{n=!0;for(let e of t)e.resolve(void 0);t.length=0}),this.on(`abort`,e=>{n=!0;for(let n of t)n.reject(e);t.length=0}),this.on(`error`,e=>{n=!0;for(let n of t)n.reject(e);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:n?{value:void 0,done:!0}:new Promise((e,n)=>t.push({resolve:e,reject:n})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new Qe(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}},vn=class extends Error{constructor(e){let t=typeof e==`string`?e:e.map(e=>e.type===`text`?e.text:`[${e.type}]`).join(` `);super(t),this.name=`ToolError`,this.content=e}},yn=`You have been working on the task described above but have not yet completed it. Write a continuation summary that will allow you (or another instance of yourself) to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable. Include:
|
|
7
|
+
1. Task Overview
|
|
8
|
+
The user's core request and success criteria
|
|
9
|
+
Any clarifications or constraints they specified
|
|
10
|
+
2. Current State
|
|
11
|
+
What has been completed so far
|
|
12
|
+
Files created, modified, or analyzed (with paths if relevant)
|
|
13
|
+
Key outputs or artifacts produced
|
|
14
|
+
3. Important Discoveries
|
|
15
|
+
Technical constraints or requirements uncovered
|
|
16
|
+
Decisions made and their rationale
|
|
17
|
+
Errors encountered and how they were resolved
|
|
18
|
+
What approaches were tried that didn't work (and why)
|
|
19
|
+
4. Next Steps
|
|
20
|
+
Specific actions needed to complete the task
|
|
21
|
+
Any blockers or open questions to resolve
|
|
22
|
+
Priority order if multiple steps remain
|
|
23
|
+
5. Context to Preserve
|
|
24
|
+
User preferences or style requirements
|
|
25
|
+
Domain-specific details that aren't obvious
|
|
26
|
+
Any promises made to the user
|
|
27
|
+
Be concise but complete—err on the side of including information that would prevent duplicate work or repeated mistakes. Write in a way that enables immediate resumption of the task.
|
|
28
|
+
Wrap your summary in <summary></summary> tags.`,bn,z,B,V,H,U,W,G,xn,Sn,Cn;function wn(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}var Tn=class{constructor(e,t,n){bn.add(this),this.client=e,z.set(this,!1),B.set(this,!1),V.set(this,void 0),H.set(this,void 0),U.set(this,void 0),W.set(this,void 0),G.set(this,void 0),xn.set(this,0),f(this,V,{params:{...t,messages:structuredClone(t.messages)}},`f`);let r=[`BetaToolRunner`,...Mt(t.tools,t.messages)].join(`, `);f(this,H,{...n,headers:O([{"x-stainless-helper":r},n?.headers])},`f`),f(this,G,wn(),`f`),t.compactionControl?.enabled&&console.warn('Anthropic: The `compactionControl` parameter is deprecated and will be removed in a future version. Use server-side compaction instead by passing `edits: [{ type: "compact_20260112" }]` in the params passed to `toolRunner()`. See https://platform.claude.com/docs/en/build-with-claude/compaction')}async*[(z=new WeakMap,B=new WeakMap,V=new WeakMap,H=new WeakMap,U=new WeakMap,W=new WeakMap,G=new WeakMap,xn=new WeakMap,bn=new WeakSet,Sn=async function(){let e=p(this,V,`f`).params.compactionControl;if(!e||!e.enabled)return!1;let t=0;if(p(this,U,`f`)!==void 0)try{let e=await p(this,U,`f`);t=e.usage.input_tokens+(e.usage.cache_creation_input_tokens??0)+(e.usage.cache_read_input_tokens??0)+e.usage.output_tokens}catch{return!1}let n=e.contextTokenThreshold??1e5;if(t<n)return!1;let r=e.model??p(this,V,`f`).params.model,i=e.summaryPrompt??yn,a=p(this,V,`f`).params.messages;if(a[a.length-1].role===`assistant`){let e=a[a.length-1];if(Array.isArray(e.content)){let t=e.content.filter(e=>e.type!==`tool_use`);t.length===0?a.pop():e.content=t}}let o=await this.client.beta.messages.create({model:r,messages:[...a,{role:`user`,content:[{type:`text`,text:i}]}],max_tokens:p(this,V,`f`).params.max_tokens},{signal:p(this,H,`f`).signal,headers:O([p(this,H,`f`).headers,{"x-stainless-helper":`compaction`}])});if(o.content[0]?.type!==`text`)throw new g(`Expected text response for compaction`);return p(this,V,`f`).params.messages=[{role:`user`,content:o.content}],!0},Symbol.asyncIterator)](){var e;if(p(this,z,`f`))throw new g(`Cannot iterate over a consumed stream`);f(this,z,!0,`f`),f(this,B,!0,`f`),f(this,W,void 0,`f`);try{for(;;){let t;try{if(p(this,V,`f`).params.max_iterations&&p(this,xn,`f`)>=p(this,V,`f`).params.max_iterations)break;f(this,B,!1,`f`),f(this,W,void 0,`f`),f(this,xn,(e=p(this,xn,`f`),e++,e),`f`),f(this,U,void 0,`f`);let{max_iterations:n,compactionControl:r,...i}=p(this,V,`f`).params;if(i.stream?(t=this.client.beta.messages.stream({...i},p(this,H,`f`)),f(this,U,t.finalMessage(),`f`),p(this,U,`f`).catch(()=>{}),yield t):(f(this,U,this.client.beta.messages.create({...i,stream:!1},p(this,H,`f`)),`f`),yield p(this,U,`f`)),!await p(this,bn,`m`,Sn).call(this)){if(!p(this,B,`f`)){let{role:e,content:t}=await p(this,U,`f`);p(this,V,`f`).params.messages.push({role:e,content:t})}let e=await p(this,bn,`m`,Cn).call(this,p(this,V,`f`).params.messages.at(-1));if(e)p(this,V,`f`).params.messages.push(e);else if(!p(this,B,`f`))break}}finally{t&&t.abort()}}if(!p(this,U,`f`))throw new g(`ToolRunner concluded without a message from the server`);p(this,G,`f`).resolve(await p(this,U,`f`))}catch(e){throw f(this,z,!1,`f`),p(this,G,`f`).promise.catch(()=>{}),p(this,G,`f`).reject(e),f(this,G,wn(),`f`),e}}setMessagesParams(e){typeof e==`function`?p(this,V,`f`).params=e(p(this,V,`f`).params):p(this,V,`f`).params=e,f(this,B,!0,`f`),f(this,W,void 0,`f`)}setRequestOptions(e){typeof e==`function`?f(this,H,e(p(this,H,`f`)),`f`):f(this,H,{...p(this,H,`f`),...e},`f`)}async generateToolResponse(e=p(this,H,`f`).signal){let t=await p(this,U,`f`)??this.params.messages.at(-1);return t?p(this,bn,`m`,Cn).call(this,t,e):null}done(){return p(this,G,`f`).promise}async runUntilDone(){if(!p(this,z,`f`))for await(let e of this);return this.done()}get params(){return p(this,V,`f`).params}pushMessages(...e){this.setMessagesParams(t=>({...t,messages:[...t.messages,...e]}))}then(e,t){return this.runUntilDone().then(e,t)}};Cn=async function(e,t=p(this,H,`f`).signal){return p(this,W,`f`)===void 0&&f(this,W,En(p(this,V,`f`).params,e,{...p(this,H,`f`),signal:t}),`f`),p(this,W,`f`)};async function En(e,t=e.messages.at(-1),n){if(!t||t.role!==`assistant`||!t.content||typeof t.content==`string`)return null;let r=t.content.filter(e=>e.type===`tool_use`);return r.length===0?null:{role:`user`,content:await Promise.all(r.map(async t=>{let r=e.tools.find(e=>(`name`in e?e.name:e.mcp_server_name)===t.name);if(!r||!(`run`in r))return{type:`tool_result`,tool_use_id:t.id,content:`Error: Tool '${t.name}' not found`,is_error:!0};try{let e=t.input;`parse`in r&&r.parse&&(e=r.parse(e));let i=await r.run(e,{toolUseBlock:t,signal:n?.signal});return{type:`tool_result`,tool_use_id:t.id,content:i}}catch(e){return{type:`tool_result`,tool_use_id:t.id,content:e instanceof vn?e.content:`Error: ${e instanceof Error?e.message:String(e)}`,is_error:!0}}}))}}var Dn=class e{constructor(e,t){this.iterator=e,this.controller=t}async*decoder(){let e=new He;for await(let t of this.iterator)for(let n of e.decode(t))yield JSON.parse(n);for(let t of e.flush())yield JSON.parse(t)}[Symbol.asyncIterator](){return this.decoder()}static fromResponse(t,n){if(!t.body)throw n.abort(),globalThis.navigator!==void 0&&globalThis.navigator.product===`ReactNative`?new g(`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 g(`Attempted to iterate over a response with no body`);return new e(Ne(t.body),n)}},On=class extends D{create(e,t){let{betas:n,...r}=e;return this._client.post(`/v1/messages/batches?beta=true`,{body:r,...t,headers:O([{"anthropic-beta":[...n??[],`message-batches-2024-09-24`].toString()},t?.headers])})}retrieve(e,t={},n){let{betas:r}=t??{};return this._client.get(k`/v1/messages/batches/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`message-batches-2024-09-24`].toString()},n?.headers])})}list(e={},t){let{betas:n,...r}=e??{};return this._client.getAPIList(`/v1/messages/batches?beta=true`,w,{query:r,...t,headers:O([{"anthropic-beta":[...n??[],`message-batches-2024-09-24`].toString()},t?.headers])})}delete(e,t={},n){let{betas:r}=t??{};return this._client.delete(k`/v1/messages/batches/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`message-batches-2024-09-24`].toString()},n?.headers])})}cancel(e,t={},n){let{betas:r}=t??{};return this._client.post(k`/v1/messages/batches/${e}/cancel?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`message-batches-2024-09-24`].toString()},n?.headers])})}async results(e,t={},n){let r=await this.retrieve(e);if(!r.results_url)throw new g(`No batch \`results_url\`; Has it finished processing? ${r.processing_status} - ${r.id}`);let{betas:i}=t??{};return this._client.get(r.results_url,{...n,headers:O([{"anthropic-beta":[...i??[],`message-batches-2024-09-24`].toString(),Accept:`application/binary`},n?.headers]),stream:!0,__binaryResponse:!0})._thenUnwrap((e,t)=>Dn.fromResponse(t.response,t.controller))}},kn={"claude-1.3":`November 6th, 2024`,"claude-1.3-100k":`November 6th, 2024`,"claude-instant-1.1":`November 6th, 2024`,"claude-instant-1.1-100k":`November 6th, 2024`,"claude-instant-1.2":`November 6th, 2024`,"claude-3-sonnet-20240229":`July 21st, 2025`,"claude-3-opus-20240229":`January 5th, 2026`,"claude-2.1":`July 21st, 2025`,"claude-2.0":`July 21st, 2025`,"claude-3-7-sonnet-latest":`February 19th, 2026`,"claude-3-7-sonnet-20250219":`February 19th, 2026`},An=[`claude-mythos-preview`,`claude-opus-4-6`],jn=class extends D{constructor(){super(...arguments),this.batches=new On(this._client)}create(e,t){let n=Mn(e),{betas:r,...i}=n;i.model in kn&&console.warn(`The model '${i.model}' is deprecated and will reach end-of-life on ${kn[i.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`),An.includes(i.model)&&i.thinking&&i.thinking.type===`enabled`&&console.warn(`Using Claude with ${i.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 a=this._client._options.timeout;if(!i.stream&&a==null){let e=Ut[i.model]??void 0;a=this._client.calculateNonstreamingTimeout(i.max_tokens,e)}let o=Nt(i.tools,i.messages);return this._client.post(`/v1/messages?beta=true`,{body:i,timeout:a??6e5,...t,headers:O([{...r?.toString()==null?void 0:{"anthropic-beta":r?.toString()}},o,t?.headers]),stream:n.stream??!1})}parse(e,t){return t={...t,headers:O([{"anthropic-beta":[...e.betas??[],`structured-outputs-2025-12-15`].toString()},t?.headers])},this.create(e,t).then(t=>Kt(t,e,{logger:this._client.logger??console}))}stream(e,t){return _n.createMessage(this,e,t)}countTokens(e,t){let{betas:n,...r}=Mn(e);return this._client.post(`/v1/messages/count_tokens?beta=true`,{body:r,...t,headers:O([{"anthropic-beta":[...n??[],`token-counting-2024-11-01`].toString()},t?.headers])})}toolRunner(e,t){return new Tn(this._client,e,t)}};function Mn(e){if(!e.output_format)return e;if(e.output_config?.format)throw new g(`Both output_format and output_config.format were provided. Please use only output_config.format (output_format is deprecated).`);let{output_format:t,...n}=e;return{...n,output_config:{...e.output_config,format:t}}}jn.Batches=On,jn.BetaToolRunner=Tn,jn.ToolError=vn;var Nn=class extends D{list(e,t={},n){let{betas:r,...i}=t??{};return this._client.getAPIList(k`/v1/sessions/${e}/events?beta=true`,T,{query:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}send(e,t,n){let{betas:r,...i}=t;return this._client.post(k`/v1/sessions/${e}/events?beta=true`,{body:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}stream(e,t={},n){let{betas:r}=t??{};return this._client.get(k`/v1/sessions/${e}/events/stream?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers]),stream:!0})}},Pn=class extends D{retrieve(e,t,n){let{session_id:r,betas:i}=t;return this._client.get(k`/v1/sessions/${r}/resources/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...i??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}update(e,t,n){let{session_id:r,betas:i,...a}=t;return this._client.post(k`/v1/sessions/${r}/resources/${e}?beta=true`,{body:a,...n,headers:O([{"anthropic-beta":[...i??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}list(e,t={},n){let{betas:r,...i}=t??{};return this._client.getAPIList(k`/v1/sessions/${e}/resources?beta=true`,T,{query:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}delete(e,t,n){let{session_id:r,betas:i}=t;return this._client.delete(k`/v1/sessions/${r}/resources/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...i??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}add(e,t,n){let{betas:r,...i}=t;return this._client.post(k`/v1/sessions/${e}/resources?beta=true`,{body:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}},Fn=class extends D{constructor(){super(...arguments),this.events=new Nn(this._client),this.resources=new Pn(this._client)}create(e,t){let{betas:n,...r}=e;return this._client.post(`/v1/sessions?beta=true`,{body:r,...t,headers:O([{"anthropic-beta":[...n??[],`managed-agents-2026-04-01`].toString()},t?.headers])})}retrieve(e,t={},n){let{betas:r}=t??{};return this._client.get(k`/v1/sessions/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}update(e,t,n){let{betas:r,...i}=t;return this._client.post(k`/v1/sessions/${e}?beta=true`,{body:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}list(e={},t){let{betas:n,...r}=e??{};return this._client.getAPIList(`/v1/sessions?beta=true`,T,{query:r,...t,headers:O([{"anthropic-beta":[...n??[],`managed-agents-2026-04-01`].toString()},t?.headers])})}delete(e,t={},n){let{betas:r}=t??{};return this._client.delete(k`/v1/sessions/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}archive(e,t={},n){let{betas:r}=t??{};return this._client.post(k`/v1/sessions/${e}/archive?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}};Fn.Events=Nn,Fn.Resources=Pn;var In=class extends D{create(e,t={},n){let{betas:r,...i}=t??{};return this._client.post(k`/v1/skills/${e}/versions?beta=true`,pt({body:i,...n,headers:O([{"anthropic-beta":[...r??[],`skills-2025-10-02`].toString()},n?.headers])},this._client))}retrieve(e,t,n){let{skill_id:r,betas:i}=t;return this._client.get(k`/v1/skills/${r}/versions/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...i??[],`skills-2025-10-02`].toString()},n?.headers])})}list(e,t={},n){let{betas:r,...i}=t??{};return this._client.getAPIList(k`/v1/skills/${e}/versions?beta=true`,T,{query:i,...n,headers:O([{"anthropic-beta":[...r??[],`skills-2025-10-02`].toString()},n?.headers])})}delete(e,t,n){let{skill_id:r,betas:i}=t;return this._client.delete(k`/v1/skills/${r}/versions/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...i??[],`skills-2025-10-02`].toString()},n?.headers])})}},Ln=class extends D{constructor(){super(...arguments),this.versions=new In(this._client)}create(e={},t){let{betas:n,...r}=e??{};return this._client.post(`/v1/skills?beta=true`,pt({body:r,...t,headers:O([{"anthropic-beta":[...n??[],`skills-2025-10-02`].toString()},t?.headers])},this._client,!1))}retrieve(e,t={},n){let{betas:r}=t??{};return this._client.get(k`/v1/skills/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`skills-2025-10-02`].toString()},n?.headers])})}list(e={},t){let{betas:n,...r}=e??{};return this._client.getAPIList(`/v1/skills?beta=true`,T,{query:r,...t,headers:O([{"anthropic-beta":[...n??[],`skills-2025-10-02`].toString()},t?.headers])})}delete(e,t={},n){let{betas:r}=t??{};return this._client.delete(k`/v1/skills/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`skills-2025-10-02`].toString()},n?.headers])})}};Ln.Versions=In;var Rn=class extends D{create(e,t,n){let{betas:r,...i}=t;return this._client.post(k`/v1/vaults/${e}/credentials?beta=true`,{body:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}retrieve(e,t,n){let{vault_id:r,betas:i}=t;return this._client.get(k`/v1/vaults/${r}/credentials/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...i??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}update(e,t,n){let{vault_id:r,betas:i,...a}=t;return this._client.post(k`/v1/vaults/${r}/credentials/${e}?beta=true`,{body:a,...n,headers:O([{"anthropic-beta":[...i??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}list(e,t={},n){let{betas:r,...i}=t??{};return this._client.getAPIList(k`/v1/vaults/${e}/credentials?beta=true`,T,{query:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}delete(e,t,n){let{vault_id:r,betas:i}=t;return this._client.delete(k`/v1/vaults/${r}/credentials/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...i??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}archive(e,t,n){let{vault_id:r,betas:i}=t;return this._client.post(k`/v1/vaults/${r}/credentials/${e}/archive?beta=true`,{...n,headers:O([{"anthropic-beta":[...i??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}},zn=class extends D{constructor(){super(...arguments),this.credentials=new Rn(this._client)}create(e,t){let{betas:n,...r}=e;return this._client.post(`/v1/vaults?beta=true`,{body:r,...t,headers:O([{"anthropic-beta":[...n??[],`managed-agents-2026-04-01`].toString()},t?.headers])})}retrieve(e,t={},n){let{betas:r}=t??{};return this._client.get(k`/v1/vaults/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}update(e,t,n){let{betas:r,...i}=t;return this._client.post(k`/v1/vaults/${e}?beta=true`,{body:i,...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}list(e={},t){let{betas:n,...r}=e??{};return this._client.getAPIList(`/v1/vaults?beta=true`,T,{query:r,...t,headers:O([{"anthropic-beta":[...n??[],`managed-agents-2026-04-01`].toString()},t?.headers])})}delete(e,t={},n){let{betas:r}=t??{};return this._client.delete(k`/v1/vaults/${e}?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}archive(e,t={},n){let{betas:r}=t??{};return this._client.post(k`/v1/vaults/${e}/archive?beta=true`,{...n,headers:O([{"anthropic-beta":[...r??[],`managed-agents-2026-04-01`].toString()},n?.headers])})}};zn.Credentials=Rn;var K=class extends D{constructor(){super(...arguments),this.models=new It(this._client),this.messages=new jn(this._client),this.agents=new zt(this._client),this.environments=new kt(this._client),this.sessions=new Fn(this._client),this.vaults=new zn(this._client),this.memoryStores=new Ht(this._client),this.files=new Ft(this._client),this.skills=new Ln(this._client),this.userProfiles=new Lt(this._client)}};K.Models=It,K.Messages=jn,K.Agents=zt,K.Environments=kt,K.Sessions=Fn,K.Vaults=zn,K.MemoryStores=Ht,K.Files=Ft,K.Skills=Ln,K.UserProfiles=Lt;var Bn=class extends D{create(e,t){let{betas:n,...r}=e;return this._client.post(`/v1/complete`,{body:r,timeout:this._client._options.timeout??6e5,...t,headers:O([{...n?.toString()==null?void 0:{"anthropic-beta":n?.toString()}},t?.headers]),stream:e.stream??!1})}};function Vn(e){return e?.output_config?.format}function Hn(e,t,n){let r=Vn(t);return!t||!(`parse`in(r??{}))?{...e,content:e.content.map(e=>e.type===`text`?Object.defineProperty({...e},`parsed_output`,{value:null,enumerable:!1}):e),parsed_output:null}:Un(e,t,n)}function Un(e,t,n){let r=null,i=e.content.map(e=>{if(e.type===`text`){let n=Wn(t,e.text);return r===null&&(r=n),Object.defineProperty({...e},`parsed_output`,{value:n,enumerable:!1})}return e});return{...e,content:i,parsed_output:r}}function Wn(e,t){let n=Vn(e);if(n?.type!==`json_schema`)return null;try{return`parse`in n?n.parse(t):JSON.parse(t)}catch(e){throw new g(`Failed to parse structured output: ${e}`)}}var q,J,Y,Gn,Kn,qn,Jn,Yn,Xn,X,Zn,Qn,$n,Z,er,tr,nr,rr,ir,ar,or,sr,cr,lr,ur=`__json_buf`;function dr(e){return e.type===`tool_use`||e.type===`server_tool_use`}var fr=class e{constructor(e,t){q.add(this),this.messages=[],this.receivedMessages=[],J.set(this,void 0),Y.set(this,null),this.controller=new AbortController,Gn.set(this,void 0),Kn.set(this,()=>{}),qn.set(this,()=>{}),Jn.set(this,void 0),Yn.set(this,()=>{}),Xn.set(this,()=>{}),X.set(this,{}),Zn.set(this,!1),Qn.set(this,!1),$n.set(this,!1),Z.set(this,!1),er.set(this,void 0),tr.set(this,void 0),nr.set(this,void 0),ar.set(this,e=>{if(f(this,Qn,!0,`f`),m(e)&&(e=new v),e instanceof v)return f(this,$n,!0,`f`),this._emit(`abort`,e);if(e instanceof g)return this._emit(`error`,e);if(e instanceof Error){let t=new g(e.message);return t.cause=e,this._emit(`error`,t)}return this._emit(`error`,new g(String(e)))}),f(this,Gn,new Promise((e,t)=>{f(this,Kn,e,`f`),f(this,qn,t,`f`)}),`f`),f(this,Jn,new Promise((e,t)=>{f(this,Yn,e,`f`),f(this,Xn,t,`f`)}),`f`),p(this,Gn,`f`).catch(()=>{}),p(this,Jn,`f`).catch(()=>{}),f(this,Y,e,`f`),f(this,nr,t?.logger??console,`f`)}get response(){return p(this,er,`f`)}get request_id(){return p(this,tr,`f`)}async withResponse(){f(this,Z,!0,`f`);let e=await p(this,Gn,`f`);if(!e)throw Error("Could not resolve a `Response` object");return{data:this,response:e,request_id:e.headers.get(`request-id`)}}static fromReadableStream(t){let n=new e(null);return n._run(()=>n._fromReadableStream(t)),n}static createMessage(t,n,r,{logger:i}={}){let a=new e(n,{logger:i});for(let e of n.messages)a._addMessageParam(e);return f(a,Y,{...n,stream:!0},`f`),a._run(()=>a._createMessage(t,{...n,stream:!0},{...r,headers:{...r?.headers,"X-Stainless-Helper-Method":`stream`}})),a}_run(e){e().then(()=>{this._emitFinal(),this._emit(`end`)},p(this,ar,`f`))}_addMessageParam(e){this.messages.push(e)}_addMessage(e,t=!0){this.receivedMessages.push(e),t&&this._emit(`message`,e)}async _createMessage(e,t,n){let r=n?.signal,i;r&&(r.aborted&&this.controller.abort(),i=this.controller.abort.bind(this.controller),r.addEventListener(`abort`,i));try{p(this,q,`m`,or).call(this);let{response:r,data:i}=await e.create({...t,stream:!0},{...n,signal:this.controller.signal}).withResponse();this._connected(r);for await(let e of i)p(this,q,`m`,sr).call(this,e);if(i.controller.signal?.aborted)throw new v;p(this,q,`m`,cr).call(this)}finally{r&&i&&r.removeEventListener(`abort`,i)}}_connected(e){this.ended||(f(this,er,e,`f`),f(this,tr,e?.headers.get(`request-id`),`f`),p(this,Kn,`f`).call(this,e),this._emit(`connect`))}get ended(){return p(this,Zn,`f`)}get errored(){return p(this,Qn,`f`)}get aborted(){return p(this,$n,`f`)}abort(){this.controller.abort()}on(e,t){return(p(this,X,`f`)[e]||(p(this,X,`f`)[e]=[])).push({listener:t}),this}off(e,t){let n=p(this,X,`f`)[e];if(!n)return this;let r=n.findIndex(e=>e.listener===t);return r>=0&&n.splice(r,1),this}once(e,t){return(p(this,X,`f`)[e]||(p(this,X,`f`)[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,n)=>{f(this,Z,!0,`f`),e!==`error`&&this.once(`error`,n),this.once(e,t)})}async done(){f(this,Z,!0,`f`),await p(this,Jn,`f`)}get currentMessage(){return p(this,J,`f`)}async finalMessage(){return await this.done(),p(this,q,`m`,rr).call(this)}async finalText(){return await this.done(),p(this,q,`m`,ir).call(this)}_emit(e,...t){if(p(this,Zn,`f`))return;e===`end`&&(f(this,Zn,!0,`f`),p(this,Yn,`f`).call(this));let n=p(this,X,`f`)[e];if(n&&(p(this,X,`f`)[e]=n.filter(e=>!e.once),n.forEach(({listener:e})=>e(...t))),e===`abort`){let e=t[0];!p(this,Z,`f`)&&!n?.length&&Promise.reject(e),p(this,qn,`f`).call(this,e),p(this,Xn,`f`).call(this,e),this._emit(`end`);return}if(e===`error`){let e=t[0];!p(this,Z,`f`)&&!n?.length&&Promise.reject(e),p(this,qn,`f`).call(this,e),p(this,Xn,`f`).call(this,e),this._emit(`end`)}}_emitFinal(){this.receivedMessages.at(-1)&&this._emit(`finalMessage`,p(this,q,`m`,rr).call(this))}async _fromReadableStream(e,t){let n=t?.signal,r;n&&(n.aborted&&this.controller.abort(),r=this.controller.abort.bind(this.controller),n.addEventListener(`abort`,r));try{p(this,q,`m`,or).call(this),this._connected(null);let t=Qe.fromReadableStream(e,this.controller);for await(let e of t)p(this,q,`m`,sr).call(this,e);if(t.controller.signal?.aborted)throw new v;p(this,q,`m`,cr).call(this)}finally{n&&r&&n.removeEventListener(`abort`,r)}}[(J=new WeakMap,Y=new WeakMap,Gn=new WeakMap,Kn=new WeakMap,qn=new WeakMap,Jn=new WeakMap,Yn=new WeakMap,Xn=new WeakMap,X=new WeakMap,Zn=new WeakMap,Qn=new WeakMap,$n=new WeakMap,Z=new WeakMap,er=new WeakMap,tr=new WeakMap,nr=new WeakMap,ar=new WeakMap,q=new WeakSet,rr=function(){if(this.receivedMessages.length===0)throw new g(`stream ended without producing a Message with role=assistant`);return this.receivedMessages.at(-1)},ir=function(){if(this.receivedMessages.length===0)throw new g(`stream ended without producing a Message with role=assistant`);let e=this.receivedMessages.at(-1).content.filter(e=>e.type===`text`).map(e=>e.text);if(e.length===0)throw new g(`stream ended without producing a content block with type=text`);return e.join(` `)},or=function(){this.ended||f(this,J,void 0,`f`)},sr=function(e){if(this.ended)return;let t=p(this,q,`m`,lr).call(this,e);switch(this._emit(`streamEvent`,e,t),e.type){case`content_block_delta`:{let n=t.content.at(-1);switch(e.delta.type){case`text_delta`:n.type===`text`&&this._emit(`text`,e.delta.text,n.text||``);break;case`citations_delta`:n.type===`text`&&this._emit(`citation`,e.delta.citation,n.citations??[]);break;case`input_json_delta`:dr(n)&&n.input&&this._emit(`inputJson`,e.delta.partial_json,n.input);break;case`thinking_delta`:n.type===`thinking`&&this._emit(`thinking`,e.delta.thinking,n.thinking);break;case`signature_delta`:n.type===`thinking`&&this._emit(`signature`,n.signature);break;default:e.delta}break}case`message_stop`:this._addMessageParam(t),this._addMessage(Hn(t,p(this,Y,`f`),{logger:p(this,nr,`f`)}),!0);break;case`content_block_stop`:this._emit(`contentBlock`,t.content.at(-1));break;case`message_start`:f(this,J,t,`f`);break;case`content_block_start`:case`message_delta`:break}},cr=function(){if(this.ended)throw new g(`stream has ended, this shouldn't happen`);let e=p(this,J,`f`);if(!e)throw new g(`request ended without sending any chunks`);return f(this,J,void 0,`f`),Hn(e,p(this,Y,`f`),{logger:p(this,nr,`f`)})},lr=function(e){let t=p(this,J,`f`);if(e.type===`message_start`){if(t)throw new g(`Unexpected event order, got ${e.type} before receiving "message_stop"`);return e.message}if(!t)throw new g(`Unexpected event order, got ${e.type} before "message_start"`);switch(e.type){case`message_stop`:return t;case`message_delta`:return t.stop_reason=e.delta.stop_reason,t.stop_sequence=e.delta.stop_sequence,t.usage.output_tokens=e.usage.output_tokens,e.usage.input_tokens!=null&&(t.usage.input_tokens=e.usage.input_tokens),e.usage.cache_creation_input_tokens!=null&&(t.usage.cache_creation_input_tokens=e.usage.cache_creation_input_tokens),e.usage.cache_read_input_tokens!=null&&(t.usage.cache_read_input_tokens=e.usage.cache_read_input_tokens),e.usage.server_tool_use!=null&&(t.usage.server_tool_use=e.usage.server_tool_use),t;case`content_block_start`:return t.content.push({...e.content_block}),t;case`content_block_delta`:{let n=t.content.at(e.index);switch(e.delta.type){case`text_delta`:n?.type===`text`&&(t.content[e.index]={...n,text:(n.text||``)+e.delta.text});break;case`citations_delta`:n?.type===`text`&&(t.content[e.index]={...n,citations:[...n.citations??[],e.delta.citation]});break;case`input_json_delta`:if(n&&dr(n)){let r=n[ur]||``;r+=e.delta.partial_json;let i={...n};Object.defineProperty(i,ur,{value:r,enumerable:!1,writable:!0}),r&&(i.input=Qt(r)),t.content[e.index]=i}break;case`thinking_delta`:n?.type===`thinking`&&(t.content[e.index]={...n,thinking:n.thinking+e.delta.thinking});break;case`signature_delta`:n?.type===`thinking`&&(t.content[e.index]={...n,signature:e.delta.signature});break;default:e.delta}return t}case`content_block_stop`:return t}},Symbol.asyncIterator)](){let e=[],t=[],n=!1;return this.on(`streamEvent`,n=>{let r=t.shift();r?r.resolve(n):e.push(n)}),this.on(`end`,()=>{n=!0;for(let e of t)e.resolve(void 0);t.length=0}),this.on(`abort`,e=>{n=!0;for(let n of t)n.reject(e);t.length=0}),this.on(`error`,e=>{n=!0;for(let n of t)n.reject(e);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:n?{value:void 0,done:!0}:new Promise((e,n)=>t.push({resolve:e,reject:n})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new Qe(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}},pr=class extends D{create(e,t){return this._client.post(`/v1/messages/batches`,{body:e,...t})}retrieve(e,t){return this._client.get(k`/v1/messages/batches/${e}`,t)}list(e={},t){return this._client.getAPIList(`/v1/messages/batches`,w,{query:e,...t})}delete(e,t){return this._client.delete(k`/v1/messages/batches/${e}`,t)}cancel(e,t){return this._client.post(k`/v1/messages/batches/${e}/cancel`,t)}async results(e,t){let n=await this.retrieve(e);if(!n.results_url)throw new g(`No batch \`results_url\`; Has it finished processing? ${n.processing_status} - ${n.id}`);return this._client.get(n.results_url,{...t,headers:O([{Accept:`application/binary`},t?.headers]),stream:!0,__binaryResponse:!0})._thenUnwrap((e,t)=>Dn.fromResponse(t.response,t.controller))}},mr=class extends D{constructor(){super(...arguments),this.batches=new pr(this._client)}create(e,t){e.model in hr&&console.warn(`The model '${e.model}' is deprecated and will reach end-of-life on ${hr[e.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`),gr.includes(e.model)&&e.thinking&&e.thinking.type===`enabled`&&console.warn(`Using Claude with ${e.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 n=this._client._options.timeout;if(!e.stream&&n==null){let t=Ut[e.model]??void 0;n=this._client.calculateNonstreamingTimeout(e.max_tokens,t)}let r=Nt(e.tools,e.messages);return this._client.post(`/v1/messages`,{body:e,timeout:n??6e5,...t,headers:O([r,t?.headers]),stream:e.stream??!1})}parse(e,t){return this.create(e,t).then(t=>Un(t,e,{logger:this._client.logger??console}))}stream(e,t){return fr.createMessage(this,e,t,{logger:this._client.logger??console})}countTokens(e,t){return this._client.post(`/v1/messages/count_tokens`,{body:e,...t})}},hr={"claude-1.3":`November 6th, 2024`,"claude-1.3-100k":`November 6th, 2024`,"claude-instant-1.1":`November 6th, 2024`,"claude-instant-1.1-100k":`November 6th, 2024`,"claude-instant-1.2":`November 6th, 2024`,"claude-3-sonnet-20240229":`July 21st, 2025`,"claude-3-opus-20240229":`January 5th, 2026`,"claude-2.1":`July 21st, 2025`,"claude-2.0":`July 21st, 2025`,"claude-3-7-sonnet-latest":`February 19th, 2026`,"claude-3-7-sonnet-20250219":`February 19th, 2026`,"claude-3-5-haiku-latest":`February 19th, 2026`,"claude-3-5-haiku-20241022":`February 19th, 2026`,"claude-opus-4-0":`June 15th, 2026`,"claude-opus-4-20250514":`June 15th, 2026`,"claude-sonnet-4-0":`June 15th, 2026`,"claude-sonnet-4-20250514":`June 15th, 2026`},gr=[`claude-mythos-preview`,`claude-opus-4-6`];mr.Batches=pr;var _r=class extends D{retrieve(e,t={},n){let{betas:r}=t??{};return this._client.get(k`/v1/models/${e}`,{...n,headers:O([{...r?.toString()==null?void 0:{"anthropic-beta":r?.toString()}},n?.headers])})}list(e={},t){let{betas:n,...r}=e??{};return this._client.getAPIList(`/v1/models`,w,{query:r,...t,headers:O([{...n?.toString()==null?void 0:{"anthropic-beta":n?.toString()}},t?.headers])})}},vr=e=>{if(globalThis.process!==void 0)return{}?.[e]?.trim()||void 0;if(globalThis.Deno!==void 0)return globalThis.Deno.env?.get?.(e)?.trim()||void 0},yr,br,xr,Sr,Cr=`\\n\\nHuman:`,wr=`\\n\\nAssistant:`,Q=class{constructor({baseURL:e=vr(`ANTHROPIC_BASE_URL`),apiKey:t=vr(`ANTHROPIC_API_KEY`)??null,authToken:n=vr(`ANTHROPIC_AUTH_TOKEN`)??null,...r}={}){yr.add(this),xr.set(this,void 0);let i={apiKey:t,authToken:n,...r,baseURL:e||`https://api.anthropic.com`};if(!i.dangerouslyAllowBrowser&&Se())throw new g(`It looks like you're running in a browser-like environment.
|
|
29
|
+
|
|
30
|
+
This is disabled by default, as it risks exposing your secret API credentials to attackers.
|
|
31
|
+
If you understand the risks and have appropriate mitigations in place,
|
|
32
|
+
you can set the \`dangerouslyAllowBrowser\` option to \`true\`, e.g.,
|
|
33
|
+
|
|
34
|
+
new Anthropic({ apiKey, dangerouslyAllowBrowser: true });
|
|
35
|
+
`);this.baseURL=i.baseURL,this.timeout=i.timeout??br.DEFAULT_TIMEOUT,this.logger=i.logger??console;let a=`warn`;this.logLevel=a,this.logLevel=Ke(i.logLevel,`ClientOptions.logLevel`,this)??Ke(vr(`ANTHROPIC_LOG`),`process.env['ANTHROPIC_LOG']`,this)??a,this.fetchOptions=i.fetchOptions,this.maxRetries=i.maxRetries??2,this.fetch=i.fetch??Ae(),f(this,xr,Fe,`f`),this._options=i,this.apiKey=typeof t==`string`?t:null,this.authToken=n}withOptions(e){return new this.constructor({...this._options,baseURL:this.baseURL,maxRetries:this.maxRetries,timeout:this.timeout,logger:this.logger,logLevel:this.logLevel,fetch:this.fetch,fetchOptions:this.fetchOptions,apiKey:this.apiKey,authToken:this.authToken,...e})}defaultQuery(){return this._options.defaultQuery}validateHeaders({values:e,nulls:t}){if(!(e.get(`x-api-key`)||e.get(`authorization`))&&!(this.apiKey&&e.get(`x-api-key`))&&!t.has(`x-api-key`)&&!(this.authToken&&e.get(`authorization`))&&!t.has(`authorization`))throw Error(`Could not resolve authentication method. Expected either apiKey or authToken to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted`)}async authHeaders(e){return O([await this.apiKeyAuth(e),await this.bearerAuth(e)])}async apiKeyAuth(e){if(this.apiKey!=null)return O([{"X-Api-Key":this.apiKey}])}async bearerAuth(e){if(this.authToken!=null)return O([{Authorization:`Bearer ${this.authToken}`}])}stringifyQuery(e){return Ie(e)}getUserAgent(){return`${this.constructor.name}/JS ${y}`}defaultIdempotencyKey(){return`stainless-node-retry-${te()}`}makeStatusError(e,t,n,r){return _.generate(e,t,n,r)}buildURL(e,t,n){let r=!p(this,yr,`m`,Sr).call(this)&&n||this.baseURL,i=pe(e)?new URL(e):new URL(r+(r.endsWith(`/`)&&e.startsWith(`/`)?e.slice(1):e)),a=this.defaultQuery(),o=Object.fromEntries(i.searchParams);return(!_e(a)||!_e(o))&&(t={...o,...a,...t}),typeof t==`object`&&t&&!Array.isArray(t)&&(i.search=this.stringifyQuery(t)),i.toString()}_calculateNonstreamingTimeout(e){if(3600*e/128e3>600)throw new g(`Streaming is required for operations that may take longer than 10 minutes. See https://github.com/anthropics/anthropic-sdk-typescript#streaming-responses for more details`);return 600*1e3}async prepareOptions(e){}async prepareRequest(e,{url:t,options:n}){}get(e,t){return this.methodRequest(`get`,e,t)}post(e,t){return this.methodRequest(`post`,e,t)}patch(e,t){return this.methodRequest(`patch`,e,t)}put(e,t){return this.methodRequest(`put`,e,t)}delete(e,t){return this.methodRequest(`delete`,e,t)}methodRequest(e,t,n){return this.request(Promise.resolve(n).then(n=>({method:e,path:t,...n})))}request(e,t=null){return new ot(this,this.makeRequest(e,t,void 0))}async makeRequest(e,t,n){let r=await e,i=r.maxRetries??this.maxRetries;t??=i,await this.prepareOptions(r);let{req:a,url:o,timeout:s}=await this.buildRequest(r,{retryCount:i-t});await this.prepareRequest(a,{url:o,options:r});let c=`log_`+(Math.random()*(1<<24)|0).toString(16).padStart(6,`0`),l=n===void 0?``:`, retryOf: ${n}`,u=Date.now();if(S(this).debug(`[${c}] sending request`,C({retryOfRequestLogID:n,method:r.method,url:o,options:r,headers:a.headers})),r.signal?.aborted)throw new v;let ee=new AbortController,d=await this.fetchWithTimeout(o,a,s,ee).catch(h),f=Date.now();if(d instanceof globalThis.Error){let e=`retrying, ${t} attempts remaining`;if(r.signal?.aborted)throw new v;let i=m(d)||/timed? ?out/i.test(String(d)+(`cause`in d?String(d.cause):``));if(t)return S(this).info(`[${c}] connection ${i?`timed out`:`failed`} - ${e}`),S(this).debug(`[${c}] connection ${i?`timed out`:`failed`} (${e})`,C({retryOfRequestLogID:n,url:o,durationMs:f-u,message:d.message})),this.retryRequest(r,t,n??c);throw S(this).info(`[${c}] connection ${i?`timed out`:`failed`} - error; no more retries left`),S(this).debug(`[${c}] connection ${i?`timed out`:`failed`} (error; no more retries left)`,C({retryOfRequestLogID:n,url:o,durationMs:f-u,message:d.message})),i?new re:new ne({cause:d})}let p=`[${c}${l}${[...d.headers.entries()].filter(([e])=>e===`request-id`).map(([e,t])=>`, `+e+`: `+JSON.stringify(t)).join(``)}] ${a.method} ${o} ${d.ok?`succeeded`:`failed`} with status ${d.status} in ${f-u}ms`;if(!d.ok){let e=await this.shouldRetry(d);if(t&&e){let e=`retrying, ${t} attempts remaining`;return await Pe(d.body),S(this).info(`${p} - ${e}`),S(this).debug(`[${c}] response error (${e})`,C({retryOfRequestLogID:n,url:d.url,status:d.status,headers:d.headers,durationMs:f-u})),this.retryRequest(r,t,n??c,d.headers)}let i=e?`error; no more retries left`:`error; not retryable`;S(this).info(`${p} - ${i}`);let a=await d.text().catch(e=>h(e).message),o=be(a),s=o?void 0:a;throw S(this).debug(`[${c}] response error (${i})`,C({retryOfRequestLogID:n,url:d.url,status:d.status,headers:d.headers,message:s,durationMs:Date.now()-u})),this.makeStatusError(d.status,o,s,d.headers)}return S(this).info(p),S(this).debug(`[${c}] response start`,C({retryOfRequestLogID:n,url:d.url,status:d.status,headers:d.headers,durationMs:f-u})),{response:d,options:r,controller:ee,requestLogID:c,retryOfRequestLogID:n,startTime:u}}getAPIList(e,t,n){return this.requestAPIList(t,n&&`then`in n?n.then(t=>({method:`get`,path:e,...t})):{method:`get`,path:e,...n})}requestAPIList(e,t){let n=this.makeRequest(t,null,void 0);return new lt(this,n,e)}async fetchWithTimeout(e,t,n,r){let{signal:i,method:a,...o}=t||{},s=this._makeAbort(r);i&&i.addEventListener(`abort`,s,{once:!0});let c=setTimeout(s,n),l=globalThis.ReadableStream&&o.body instanceof globalThis.ReadableStream||typeof o.body==`object`&&o.body!==null&&Symbol.asyncIterator in o.body,u={signal:r.signal,...l?{duplex:`half`}:{},method:`GET`,...o};a&&(u.method=a.toUpperCase());try{return await this.fetch.call(void 0,e,u)}finally{clearTimeout(c)}}async shouldRetry(e){let t=e.headers.get(`x-should-retry`);return t===`true`?!0:t===`false`?!1:e.status===408||e.status===409||e.status===429||e.status>=500}async retryRequest(e,t,n,r){let i,a=r?.get(`retry-after-ms`);if(a){let e=parseFloat(a);Number.isNaN(e)||(i=e)}let o=r?.get(`retry-after`);if(o&&!i){let e=parseFloat(o);i=Number.isNaN(e)?Date.parse(o)-Date.now():e*1e3}if(i===void 0){let n=e.maxRetries??this.maxRetries;i=this.calculateDefaultRetryTimeoutMillis(t,n)}return await xe(i),this.makeRequest(e,t-1,n)}calculateDefaultRetryTimeoutMillis(e,t){let n=t-e;return Math.min(.5*2**n,8)*(1-Math.random()*.25)*1e3}calculateNonstreamingTimeout(e,t){let n=600*1e3;if(36e5*e/128e3>n||t!=null&&e>t)throw new g(`Streaming is required for operations that may take longer than 10 minutes. See https://github.com/anthropics/anthropic-sdk-typescript#long-requests for more details`);return n}async buildRequest(e,{retryCount:t=0}={}){let n={...e},{method:r,path:i,query:a,defaultBaseURL:o}=n,s=this.buildURL(i,a,o);`timeout`in n&&ye(`timeout`,n.timeout),n.timeout=n.timeout??this.timeout;let{bodyHeaders:c,body:l}=this.buildBody({options:n});return{req:{method:r,headers:await this.buildHeaders({options:e,method:r,bodyHeaders:c,retryCount:t}),...n.signal&&{signal:n.signal},...globalThis.ReadableStream&&l instanceof globalThis.ReadableStream&&{duplex:`half`},...l&&{body:l},...this.fetchOptions??{},...n.fetchOptions??{}},url:s,timeout:n.timeout}}async buildHeaders({options:e,method:t,bodyHeaders:n,retryCount:r}){let i={};this.idempotencyHeader&&t!==`get`&&(e.idempotencyKey||=this.defaultIdempotencyKey(),i[this.idempotencyHeader]=e.idempotencyKey);let a=O([i,{Accept:`application/json`,"User-Agent":this.getUserAgent(),"X-Stainless-Retry-Count":String(r),...e.timeout?{"X-Stainless-Timeout":String(Math.trunc(e.timeout/1e3))}:{},...ke(),...this._options.dangerouslyAllowBrowser?{"anthropic-dangerous-direct-browser-access":`true`}:void 0,"anthropic-version":`2023-06-01`},await this.authHeaders(e),this._options.defaultHeaders,n,e.headers]);return this.validateHeaders(a),a.values}_makeAbort(e){return()=>e.abort()}buildBody({options:{body:e,headers:t}}){if(!e)return{bodyHeaders:void 0,body:void 0};let n=O([t]);return ArrayBuffer.isView(e)||e instanceof ArrayBuffer||e instanceof DataView||typeof e==`string`&&n.values.has(`content-type`)||globalThis.Blob&&e instanceof globalThis.Blob||e instanceof FormData||e instanceof URLSearchParams||globalThis.ReadableStream&&e instanceof globalThis.ReadableStream?{bodyHeaders:void 0,body:e}:typeof e==`object`&&(Symbol.asyncIterator in e||Symbol.iterator in e&&`next`in e&&typeof e.next==`function`)?{bodyHeaders:void 0,body:Me(e)}:typeof e==`object`&&n.values.get(`content-type`)===`application/x-www-form-urlencoded`?{bodyHeaders:{"content-type":`application/x-www-form-urlencoded`},body:this.stringifyQuery(e)}:p(this,xr,`f`).call(this,{body:e,headers:n})}};br=Q,xr=new WeakMap,yr=new WeakSet,Sr=function(){return this.baseURL!==`https://api.anthropic.com`},Q.Anthropic=br,Q.HUMAN_PROMPT=Cr,Q.AI_PROMPT=wr,Q.DEFAULT_TIMEOUT=6e5,Q.AnthropicError=g,Q.APIError=_,Q.APIConnectionError=ne,Q.APIConnectionTimeoutError=re,Q.APIUserAbortError=v,Q.NotFoundError=se,Q.ConflictError=ce,Q.RateLimitError=ue,Q.BadRequestError=ie,Q.AuthenticationError=ae,Q.InternalServerError=de,Q.PermissionDeniedError=oe,Q.UnprocessableEntityError=le,Q.toFile=St;var $=class extends Q{constructor(){super(...arguments),this.completions=new Bn(this),this.messages=new mr(this),this.models=new _r(this),this.beta=new K(this)}};$.Completions=Bn,$.Messages=mr,$.Models=_r,$.Beta=K;function Tr(e){return e||(typeof process<`u`&&{}.PI_CACHE_RETENTION===`long`?`long`:`short`)}function Er(e,t){let n=Tr(t);if(n===`none`)return{retention:n};let r=n===`long`&&Pr(e).supportsLongCacheRetention?`1h`:void 0;return{retention:n,cacheControl:{type:`ephemeral`,...r&&{ttl:r}}}}var Dr=`2.1.75`,Or=new Map([`Read`,`Write`,`Edit`,`Bash`,`Grep`,`Glob`,`AskUserQuestion`,`EnterPlanMode`,`ExitPlanMode`,`KillShell`,`NotebookEdit`,`Skill`,`Task`,`TaskOutput`,`TodoWrite`,`WebFetch`,`WebSearch`].map(e=>[e.toLowerCase(),e])),kr=e=>Or.get(e.toLowerCase())??e,Ar=(e,t)=>{if(t&&t.length>0){let n=e.toLowerCase(),r=t.find(e=>e.name.toLowerCase()===n);if(r)return r.name}return e};function jr(e){if(!e.some(e=>e.type===`image`))return l(e.map(e=>e.text).join(`
|
|
36
|
+
`));let t=e.map(e=>e.type===`text`?{type:`text`,text:l(e.text)}:{type:`image`,source:{type:`base64`,media_type:e.mimeType,data:e.data}});return t.some(e=>e.type===`text`)||t.unshift({type:`text`,text:`(see attached image)`}),t}var Mr=`fine-grained-tool-streaming-2025-05-14`,Nr=`interleaved-thinking-2025-05-14`;function Pr(e){return{supportsEagerToolInputStreaming:e.compat?.supportsEagerToolInputStreaming??!0,supportsLongCacheRetention:e.compat?.supportsLongCacheRetention??!0}}function Fr(...e){let t={};for(let n of e)n&&Object.assign(t,n);return t}var Ir=new Set([`message_start`,`message_delta`,`message_stop`,`content_block_start`,`content_block_delta`,`content_block_stop`]);function Lr(e){if(!e.event&&e.data.length===0)return null;let t={event:e.event,data:e.data.join(`
|
|
37
|
+
`),raw:[...e.raw]};return e.event=null,e.data=[],e.raw=[],t}function Rr(e,t){if(e===``)return Lr(t);if(t.raw.push(e),e.startsWith(`:`))return null;let n=e.indexOf(`:`),r=n===-1?e:e.slice(0,n),i=n===-1?``:e.slice(n+1);return i.startsWith(` `)&&(i=i.slice(1)),r===`event`?t.event=i:r===`data`&&t.data.push(i),null}function zr(e){let t=e.indexOf(`\r`),n=e.indexOf(`
|
|
38
|
+
`);return t===-1?n:n===-1?t:Math.min(t,n)}function Br(e){let t=zr(e);if(t===-1)return null;let n=t+1;return e[t]===`\r`&&e[n]===`
|
|
39
|
+
`&&(n+=1),{line:e.slice(0,t),rest:e.slice(n)}}async function*Vr(e,t){let n=e.getReader(),r=new TextDecoder,i={event:null,data:[],raw:[]},a=``;try{for(;;){if(t?.aborted)throw Error(`Request was aborted`);let{value:e,done:o}=await n.read();if(o)break;a+=r.decode(e,{stream:!0});let s=Br(a);for(;s;){a=s.rest;let e=Rr(s.line,i);e&&(yield e),s=Br(a)}}a+=r.decode();let e=Br(a);for(;e;){a=e.rest;let t=Rr(e.line,i);t&&(yield t),e=Br(a)}if(a.length>0){let e=Rr(a,i);e&&(yield e)}let o=Lr(i);o&&(yield o)}finally{n.releaseLock()}}async function*Hr(e,t){if(!e.body)throw Error(`Attempted to iterate over an Anthropic response with no body`);let n=!1,r=!1;for await(let i of Vr(e.body,t)){if(i.event===`error`)throw Error(i.data);if(Ir.has(i.event??``))try{let e=o(i.data);e.type===`message_start`?n=!0:e.type===`message_stop`&&(r=!0),yield e}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Could not parse Anthropic SSE event ${i.event}: ${t}; data=${i.data}; raw=${i.raw.join(`\\n`)}`)}}if(n&&!r)throw Error(`Anthropic stream ended before message_stop`)}var Ur=(t,n,i)=>{let o=new e;return(async()=>{let e={role:`assistant`,content:[],api:t.api,provider:t.provider,model:t.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:Date.now()};try{let l,u;if(i?.client)l=i.client,u=!1;else{let e=i?.apiKey??a(t.provider)??``,r;if(t.provider===`github-copilot`){let e=ee(n.messages);r=d({messages:n.messages,hasImages:e})}let o=Jr(t,e,i?.interleavedThinking??!0,Qr(t,n),i?.headers,r);l=o.client,u=o.isOAuthToken}let f=Yr(t,n,u,i),p=await i?.onPayload?.(f,t);p!==void 0&&(f=p);let te={...i?.signal?{signal:i.signal}:{},...i?.timeoutMs===void 0?{}:{timeout:i.timeoutMs},...i?.maxRetries===void 0?{}:{maxRetries:i.maxRetries}},m=await l.messages.create({...f,stream:!0},te).asResponse();await i?.onResponse?.({status:m.status,headers:c(m.headers)},t),o.push({type:`start`,partial:e});let h=e.content;for await(let a of Hr(m,i?.signal))if(a.type===`message_start`)e.responseId=a.message.id,e.usage.input=a.message.usage.input_tokens||0,e.usage.output=a.message.usage.output_tokens||0,e.usage.cacheRead=a.message.usage.cache_read_input_tokens||0,e.usage.cacheWrite=a.message.usage.cache_creation_input_tokens||0,e.usage.totalTokens=e.usage.input+e.usage.output+e.usage.cacheRead+e.usage.cacheWrite,r(t,e.usage);else if(a.type===`content_block_start`){if(a.content_block.type===`text`){let t={type:`text`,text:``,index:a.index};e.content.push(t),o.push({type:`text_start`,contentIndex:e.content.length-1,partial:e})}else if(a.content_block.type===`thinking`){let t={type:`thinking`,thinking:``,thinkingSignature:``,index:a.index};e.content.push(t),o.push({type:`thinking_start`,contentIndex:e.content.length-1,partial:e})}else if(a.content_block.type===`redacted_thinking`){let t={type:`thinking`,thinking:`[Reasoning redacted]`,thinkingSignature:a.content_block.data,redacted:!0,index:a.index};e.content.push(t),o.push({type:`thinking_start`,contentIndex:e.content.length-1,partial:e})}else if(a.content_block.type===`tool_use`){let t={type:`toolCall`,id:a.content_block.id,name:u?Ar(a.content_block.name,n.tools):a.content_block.name,arguments:a.content_block.input??{},partialJson:``,index:a.index};e.content.push(t),o.push({type:`toolcall_start`,contentIndex:e.content.length-1,partial:e})}}else if(a.type===`content_block_delta`){if(a.delta.type===`text_delta`){let t=h.findIndex(e=>e.index===a.index),n=h[t];n&&n.type===`text`&&(n.text+=a.delta.text,o.push({type:`text_delta`,contentIndex:t,delta:a.delta.text,partial:e}))}else if(a.delta.type===`thinking_delta`){let t=h.findIndex(e=>e.index===a.index),n=h[t];n&&n.type===`thinking`&&(n.thinking+=a.delta.thinking,o.push({type:`thinking_delta`,contentIndex:t,delta:a.delta.thinking,partial:e}))}else if(a.delta.type===`input_json_delta`){let t=h.findIndex(e=>e.index===a.index),n=h[t];n&&n.type===`toolCall`&&(n.partialJson+=a.delta.partial_json,n.arguments=s(n.partialJson),o.push({type:`toolcall_delta`,contentIndex:t,delta:a.delta.partial_json,partial:e}))}else if(a.delta.type===`signature_delta`){let e=h[h.findIndex(e=>e.index===a.index)];e&&e.type===`thinking`&&(e.thinkingSignature=e.thinkingSignature||``,e.thinkingSignature+=a.delta.signature)}}else if(a.type===`content_block_stop`){let t=h.findIndex(e=>e.index===a.index),n=h[t];n&&(delete n.index,n.type===`text`?o.push({type:`text_end`,contentIndex:t,content:n.text,partial:e}):n.type===`thinking`?o.push({type:`thinking_end`,contentIndex:t,content:n.thinking,partial:e}):n.type===`toolCall`&&(n.arguments=s(n.partialJson),delete n.partialJson,o.push({type:`toolcall_end`,contentIndex:t,toolCall:n,partial:e})))}else a.type===`message_delta`&&(a.delta.stop_reason&&(e.stopReason=ei(a.delta.stop_reason)),a.usage.input_tokens!=null&&(e.usage.input=a.usage.input_tokens),a.usage.output_tokens!=null&&(e.usage.output=a.usage.output_tokens),a.usage.cache_read_input_tokens!=null&&(e.usage.cacheRead=a.usage.cache_read_input_tokens),a.usage.cache_creation_input_tokens!=null&&(e.usage.cacheWrite=a.usage.cache_creation_input_tokens),e.usage.totalTokens=e.usage.input+e.usage.output+e.usage.cacheRead+e.usage.cacheWrite,r(t,e.usage));if(i?.signal?.aborted)throw Error(`Request was aborted`);if(e.stopReason===`aborted`||e.stopReason===`error`)throw Error(`An unknown error occurred`);o.push({type:`done`,reason:e.stopReason,message:e}),o.end()}catch(t){for(let t of e.content)delete t.index,delete t.partialJson;e.stopReason=i?.signal?.aborted?`aborted`:`error`,e.errorMessage=t instanceof Error?t.message:JSON.stringify(t),o.push({type:`error`,reason:e.stopReason,error:e}),o.end()}})(),o};function Wr(e){return e.includes(`opus-4-6`)||e.includes(`opus-4.6`)||e.includes(`opus-4-7`)||e.includes(`opus-4.7`)||e.includes(`sonnet-4-6`)||e.includes(`sonnet-4.6`)}function Gr(e,t){switch(e){case`minimal`:return`low`;case`low`:return`low`;case`medium`:return`medium`;case`high`:return`high`;case`xhigh`:return t.includes(`opus-4-6`)||t.includes(`opus-4.6`)?`max`:t.includes(`opus-4-7`)||t.includes(`opus-4.7`)?`xhigh`:`high`;default:return`high`}}var Kr=(e,t,r)=>{let o=r?.apiKey||a(e.provider);if(!o)throw Error(`No API key for provider: ${e.provider}`);let s=n(e,r,o);if(!r?.reasoning)return Ur(e,t,{...s,thinkingEnabled:!1});if(Wr(e.id)){let n=Gr(r.reasoning,e.id);return Ur(e,t,{...s,thinkingEnabled:!0,effort:n})}let c=i(s.maxTokens||0,e.maxTokens,r.reasoning,r.thinkingBudgets);return Ur(e,t,{...s,maxTokens:c.maxTokens,thinkingEnabled:!0,thinkingBudgetTokens:c.thinkingBudget})};function qr(e){return e.includes(`sk-ant-oat`)}function Jr(e,t,n,r,i,a){let o=n&&!Wr(e.id),s=[];return r&&s.push(Mr),o&&s.push(Nr),e.provider===`cloudflare-ai-gateway`?{client:new $({apiKey:null,authToken:null,baseURL:u(e),dangerouslyAllowBrowser:!0,defaultHeaders:Fr({accept:`application/json`,"anthropic-dangerous-direct-browser-access":`true`,"cf-aig-authorization":`Bearer ${t}`,"x-api-key":null,Authorization:null,...s.length>0?{"anthropic-beta":s.join(`,`)}:{}},e.headers,i)}),isOAuthToken:!1}:e.provider===`github-copilot`?{client:new $({apiKey:null,authToken:t,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:Fr({accept:`application/json`,"anthropic-dangerous-direct-browser-access":`true`,...s.length>0?{"anthropic-beta":s.join(`,`)}:{}},e.headers,a,i)}),isOAuthToken:!1}:qr(t)?{client:new $({apiKey:null,authToken:t,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:Fr({accept:`application/json`,"anthropic-dangerous-direct-browser-access":`true`,"anthropic-beta":[`claude-code-20250219`,`oauth-2025-04-20`,...s].join(`,`),"user-agent":`claude-cli/${Dr}`,"x-app":`cli`},e.headers,i)}),isOAuthToken:!0}:{client:new $({apiKey:t,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:Fr({accept:`application/json`,"anthropic-dangerous-direct-browser-access":`true`,...s.length>0?{"anthropic-beta":s.join(`,`)}:{}},e.headers,i)}),isOAuthToken:!1}}function Yr(e,t,n,r){let{cacheControl:i}=Er(e,r?.cacheRetention),a={model:e.id,messages:Zr(t.messages,e,n,i),max_tokens:r?.maxTokens||e.maxTokens/3|0,stream:!0};if(n?(a.system=[{type:`text`,text:`You are Claude Code, Anthropic's official CLI for Claude.`,...i?{cache_control:i}:{}}],t.systemPrompt&&a.system.push({type:`text`,text:l(t.systemPrompt),...i?{cache_control:i}:{}})):t.systemPrompt&&(a.system=[{type:`text`,text:l(t.systemPrompt),...i?{cache_control:i}:{}}]),r?.temperature!==void 0&&!r?.thinkingEnabled&&(a.temperature=r.temperature),t.tools&&t.tools.length>0&&(a.tools=$r(t.tools,n,Pr(e).supportsEagerToolInputStreaming,i)),e.reasoning)if(r?.thinkingEnabled){let t=r.thinkingDisplay??`summarized`;Wr(e.id)?(a.thinking={type:`adaptive`,display:t},r.effort&&(a.output_config=(r.effort,{effort:r.effort}))):a.thinking={type:`enabled`,budget_tokens:r.thinkingBudgetTokens||1024,display:t}}else r?.thinkingEnabled===!1&&(a.thinking={type:`disabled`});if(r?.metadata){let e=r.metadata.user_id;typeof e==`string`&&(a.metadata={user_id:e})}return r?.toolChoice&&(typeof r.toolChoice==`string`?a.tool_choice={type:r.toolChoice}:a.tool_choice=r.toolChoice),a}function Xr(e){return e.replace(/[^a-zA-Z0-9_-]/g,`_`).slice(0,64)}function Zr(e,n,r,i){let a=[],o=t(e,n,Xr);for(let e=0;e<o.length;e++){let t=o[e];if(t.role===`user`)if(typeof t.content==`string`)t.content.trim().length>0&&a.push({role:`user`,content:l(t.content)});else{let e=t.content.map(e=>e.type===`text`?{type:`text`,text:l(e.text)}:{type:`image`,source:{type:`base64`,media_type:e.mimeType,data:e.data}}).filter(e=>e.type===`text`?e.text.trim().length>0:!0);if(e.length===0)continue;a.push({role:`user`,content:e})}else if(t.role===`assistant`){let e=[];for(let n of t.content)if(n.type===`text`){if(n.text.trim().length===0)continue;e.push({type:`text`,text:l(n.text)})}else if(n.type===`thinking`){if(n.redacted){e.push({type:`redacted_thinking`,data:n.thinkingSignature});continue}if(n.thinking.trim().length===0)continue;!n.thinkingSignature||n.thinkingSignature.trim().length===0?e.push({type:`text`,text:l(n.thinking)}):e.push({type:`thinking`,thinking:l(n.thinking),signature:n.thinkingSignature})}else n.type===`toolCall`&&e.push({type:`tool_use`,id:n.id,name:r?kr(n.name):n.name,input:n.arguments??{}});if(e.length===0)continue;a.push({role:`assistant`,content:e})}else if(t.role===`toolResult`){let n=[];n.push({type:`tool_result`,tool_use_id:t.toolCallId,content:jr(t.content),is_error:t.isError});let r=e+1;for(;r<o.length&&o[r].role===`toolResult`;){let e=o[r];n.push({type:`tool_result`,tool_use_id:e.toolCallId,content:jr(e.content),is_error:e.isError}),r++}e=r-1,a.push({role:`user`,content:n})}}if(i&&a.length>0){let e=a[a.length-1];if(e.role===`user`)if(Array.isArray(e.content)){let t=e.content[e.content.length-1];t&&(t.type===`text`||t.type===`image`||t.type===`tool_result`)&&(t.cache_control=i)}else typeof e.content==`string`&&(e.content=[{type:`text`,text:e.content,cache_control:i}])}return a}function Qr(e,t){return!!t.tools?.length&&!Pr(e).supportsEagerToolInputStreaming}function $r(e,t,n,r){return e?e.map((i,a)=>{let o=i.parameters;return{name:t?kr(i.name):i.name,description:i.description,...n?{eager_input_streaming:!0}:{},input_schema:{type:`object`,properties:o.properties??{},required:o.required??[]},...r&&a===e.length-1?{cache_control:r}:{}}}):[]}function ei(e){switch(e){case`end_turn`:return`stop`;case`max_tokens`:return`length`;case`tool_use`:return`toolUse`;case`refusal`:return`error`;case`pause_turn`:return`stop`;case`stop_sequence`:return`stop`;case`sensitive`:return`error`;default:throw Error(`Unhandled stop reason: ${e}`)}}export{Ur as streamAnthropic,Kr as streamSimpleAnthropic};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,d as t,n,r}from"./simple-options-CRMUB9za.js";import{t as i}from"./openai-CQsomflW.js";import{d as a}from"./index-n7dM8Ny6.js";import{t as o}from"./headers-DkHU-pcw.js";import{n as s,r as c,t as l}from"./openai-responses-shared-D8Vix6-m.js";var u=`v1`,d=new Set([`openai`,`openai-codex`,`opencode`,`azure-openai-responses`]);function f(e){let t=new Map;if(!e)return t;for(let n of e.split(`,`)){let e=n.trim();if(!e)continue;let[r,i]=e.split(`=`,2);!r||!i||t.set(r.trim(),i.trim())}return t}function p(e,t){return t?.azureDeploymentName?t.azureDeploymentName:f({}.AZURE_OPENAI_DEPLOYMENT_NAME_MAP).get(e.id)||e.id}var m=(t,n,r)=>{let i=new e;return(async()=>{let e=p(t,r),s={role:`assistant`,content:[],api:`azure-openai-responses`,provider:t.provider,model:t.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:Date.now()};try{let l=y(t,r?.apiKey||a(t.provider)||``,r),u=b(t,n,r,e),d=await r?.onPayload?.(u,t);d!==void 0&&(u=d);let f={...r?.signal?{signal:r.signal}:{},...r?.timeoutMs===void 0?{}:{timeout:r.timeoutMs},...r?.maxRetries===void 0?{}:{maxRetries:r.maxRetries}},{data:p,response:m}=await l.responses.create(u,f).withResponse();if(await r?.onResponse?.({status:m.status,headers:o(m.headers)},t),i.push({type:`start`,partial:s}),await c(p,s,i,t),r?.signal?.aborted)throw Error(`Request was aborted`);if(s.stopReason===`aborted`||s.stopReason===`error`)throw Error(`An unknown error occurred`);i.push({type:`done`,reason:s.stopReason,message:s}),i.end()}catch(e){for(let e of s.content)delete e.index,delete e.partialJson;s.stopReason=r?.signal?.aborted?`aborted`:`error`,s.errorMessage=e instanceof Error?e.message:JSON.stringify(e),i.push({type:`error`,reason:s.stopReason,error:s}),i.end()}})(),i},h=(e,i,o)=>{let s=o?.apiKey||a(e.provider);if(!s)throw Error(`No API key for provider: ${e.provider}`);let c=n(e,o,s),l=t(e)?o?.reasoning:r(o?.reasoning);return m(e,i,{...c,reasoningEffort:l})};function g(e){let t=e.trim().replace(/\/+$/,``),n;try{n=new URL(t)}catch{throw Error(`Invalid Azure OpenAI base URL: ${e}`)}let r=n.hostname.endsWith(`.openai.azure.com`)||n.hostname.endsWith(`.cognitiveservices.azure.com`),i=n.pathname.replace(/\/+$/,``);return r&&(i===``||i===`/`||i===`/openai`)&&(n.pathname=`/openai/v1`,n.search=``),n.toString().replace(/\/+$/,``)}function _(e){return`https://${e}.openai.azure.com/openai/v1`}function v(e,t){let n=t?.azureApiVersion||{}.AZURE_OPENAI_API_VERSION||u,r=t?.azureBaseUrl?.trim()||{}.AZURE_OPENAI_BASE_URL?.trim()||void 0,i=t?.azureResourceName||{}.AZURE_OPENAI_RESOURCE_NAME,a=r;if(!a&&i&&(a=_(i)),!a&&e.baseUrl&&(a=e.baseUrl),!a)throw Error(`Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or pass azureBaseUrl, azureResourceName, or model.baseUrl.`);return{baseUrl:g(a),apiVersion:n}}function y(e,t,n){if(!t){if(!{}.AZURE_OPENAI_API_KEY)throw Error(`Azure OpenAI API key is required. Set AZURE_OPENAI_API_KEY environment variable or pass it as an argument.`);t={}.AZURE_OPENAI_API_KEY}let r={...e.headers};n?.headers&&Object.assign(r,n.headers);let{baseUrl:a,apiVersion:o}=v(e,n);return new i({apiKey:t,apiVersion:o,dangerouslyAllowBrowser:!0,defaultHeaders:r,baseURL:a})}function b(e,t,n,r){let i={model:r,input:l(e,t,d),stream:!0,prompt_cache_key:n?.sessionId};return n?.maxTokens&&(i.max_output_tokens=n?.maxTokens),n?.temperature!==void 0&&(i.temperature=n?.temperature),t.tools&&t.tools.length>0&&(i.tools=s(t.tools)),e.reasoning&&(n?.reasoningEffort||n?.reasoningSummary?(i.reasoning={effort:n?.reasoningEffort||`medium`,summary:n?.reasoningSummary||`auto`},i.include=[`reasoning.encrypted_content`]):i.reasoning={effort:`none`}),i}export{m as streamAzureOpenAIResponses,h as streamSimpleAzureOpenAIResponses};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdfjs-
|
|
2
|
-
import{t as e}from"./preload-helper-ca-nBW7U.js";var t,n=globalThis.process?.release?.name===`node`,r=typeof window<`u`;async function i(e,t={}){let{getDocument:n}=await a();return await n({data:e,isEvalSupported:!1,useSystemFonts:!0,...t}).promise}async function a(){return t||await o(),t}async function o(n,{reload:r=!1}={}){if(!(t&&!r)){if(n)try{t=await c(n());return}catch(e){throw Error(`PDF.js could not be resolved: ${e}`)}try{t=await e(()=>import(`./pdfjs-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdfjs-BGlny-4w.js","assets/preload-helper-ca-nBW7U.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{t as e}from"./preload-helper-ca-nBW7U.js";var t,n=globalThis.process?.release?.name===`node`,r=typeof window<`u`;async function i(e,t={}){let{getDocument:n}=await a();return await n({data:e,isEvalSupported:!1,useSystemFonts:!0,...t}).promise}async function a(){return t||await o(),t}async function o(n,{reload:r=!1}={}){if(!(t&&!r)){if(n)try{t=await c(n());return}catch(e){throw Error(`PDF.js could not be resolved: ${e}`)}try{t=await e(()=>import(`./pdfjs-BGlny-4w.js`),__vite__mapDeps([0,1]))}catch(e){throw Error(`Serverless PDF.js bundle could not be resolved: ${e}`)}}}function s(e){return typeof e==`object`&&!!e&&`_pdfInfo`in e}async function c(e){let t=await e;return t.default||t}var l,u=class{#e=!1;constructor({enableHWA:e=!1}={}){this.#e=e}create(e,t){let n=this._createCanvas(e,t);return{canvas:n,context:n.getContext(`2d`,{willReadFrequently:!this.#e})}}reset({canvas:e},t,n){if(!e)throw Error(`Canvas is not specified`);e.width=t,e.height=n}destroy(e){if(!e.canvas)throw Error(`Canvas is not specified`);e.canvas.width=0,e.canvas.height=0,e.canvas=void 0,e.context=void 0}_createCanvas(e,t){throw Error(`Not implemented`)}},d=class extends u{_document;constructor({ownerDocument:e=globalThis.document,enableHWA:t=!1}={}){super({enableHWA:t}),this._document=e}_createCanvas(e,t){let n=this._document.createElement(`canvas`);return n.width=e,n.height=t,n}},f=class extends u{constructor({enableHWA:e=!1}={}){super({enableHWA:e})}_createCanvas(e,t){if(!l)throw Error(`@napi-rs/canvas module is not resolved`);return l.createCanvas(e,t)}};async function p(e){l??=await c(e())}function m(){l&&(globalThis.DOMMatrix===void 0&&(globalThis.DOMMatrix=l.DOMMatrix),globalThis.ImageData===void 0&&(globalThis.ImageData=l.ImageData),globalThis.Path2D===void 0&&(globalThis.Path2D=l.Path2D))}async function h(e,t){let n=s(e)?e:await i(e);if(t<1||t>n.numPages)throw Error(`Invalid page number. Must be between 1 and ${n.numPages}.`);let r=await n.getPage(t),o=await r.getOperatorList(),{OPS:c}=await a(),l=[];for(let e=0;e<o.fnArray.length;e++){if(o.fnArray[e]!==c.paintImageXObject)continue;let t=o.argsArray[e][0],n=await new Promise(e=>(t.startsWith(`g_`)?r.commonObjs:r.objs).get(t,e));if(!n||!n.data||!n.width||!n.height)continue;let{width:i,height:a,data:s}=n,u=s.length/(i*a);if(![1,3,4].includes(u))continue;let d=u;l.push({data:s,width:i,height:a,channels:d,key:t})}return l}async function g(e,t,n={}){let r=await _(n.canvasImport),a=s(e)?e:await i(e,{CanvasFactory:r}),o=await a.getPage(t);if(t<1||t>a.numPages)throw Error(`Invalid page number. Must be between 1 and ${a.numPages}.`);let c=o.getViewport({scale:1}),l=n.scale||1;n.width?l=n.width/c.width:n.height&&(l=n.height/c.height);let u=o.getViewport({scale:Math.max(0,l)}),d=new r().create(u.width,u.height);await o.render({canvas:d.canvas,canvasContext:d.context,viewport:u}).promise;let f=d.canvas.toDataURL();return n.toDataURL?f:await(await fetch(f)).arrayBuffer()}async function _(e){if(r)return d;if(n){if(!e)throw Error(`Parameter "canvasImport" is required in Node.js environment.`);return await p(e),m(),f}throw Error(`Unsupported environment for canvas creation.`)}async function v(e){let t=s(e)?e:await i(e),n=await Promise.all(Array.from({length:t.numPages},(e,n)=>y(t,n+1)));return{totalPages:t.numPages,links:n.flat()}}async function y(e,t){let n=await(await e.getPage(t)).getAnnotations(),r=[];for(let e of n)e.subtype===`Link`&&e.url&&r.push(e.url);return r}var b=[`xmp:createdate`,`xmp:modifydate`,`xmp:metadatadate`,`xap:createdate`,`xap:modifydate`,`xap:metadatadate`];async function x(e,t={}){let n=await(s(e)?e:await i(e)).getMetadata(),r=n?.info||{};if(t.parseDates){let{PDFDateString:e}=await a();r?.CreationDate&&(r.CreationDate=e.toDateObject(r?.CreationDate)),r?.ModDate&&(r.ModDate=e.toDateObject(r?.ModDate)),n.metadata&&=new Proxy(n.metadata,{get(e,t){return t===`get`?t=>{let n=e.get(t);return b.includes(t)&&n?S(n):n}:e[t]}})}return{info:r,metadata:n?.metadata||{}}}function S(e){if(!e)return;let t=Date.parse(e);if(!Number.isNaN(t))return new Date(t)}async function C(e,t={}){let{mergePages:n=!1}=t,r=s(e)?e:await i(e),a=await Promise.all(Array.from({length:r.numPages},(e,t)=>w(r,t+1)));return{totalPages:r.numPages,text:n?a.join(`
|
|
3
3
|
`).replace(/\s+/g,` `):a}}async function w(e,t){return(await(await e.getPage(t)).getTextContent()).items.filter(e=>e.str!=null).map(e=>e.str+(e.hasEOL?`
|
|
4
4
|
`:``)).join(``)}async function T(e){await o(e,{reload:!0})}async function E(e){await o(e.pdfjs,{reload:!0})}var D=async(...e)=>(await o(),await x(...e)),O=async(...e)=>(await o(),await C(...e)),k=async(...e)=>(await o(),await h(...e)),A=async(...e)=>(await o(),await g(...e)),j=async(...e)=>(await o(),await v(...e));export{E as configureUnPDF,_ as createIsomorphicCanvasFactory,T as definePDFJSModule,k as extractImages,j as extractLinks,O as extractText,i as getDocumentProxy,D as getMeta,a as getResolvedPDFJS,A as renderPageAsImage,o as resolvePDFJSImport};
|