niumagents-cli 0.1.1

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.
@@ -0,0 +1 @@
1
+ export const __webpack_esm_id__=281;export const __webpack_esm_ids__=[281];export const __webpack_esm_modules__={2281:(e,t,s)=>{s.d(t,{Anthropic:()=>qt});var r={};s.r(r),s.d(r,{xX:()=>me,qA:()=>ye,LG:()=>fe,cH:()=>pe,pJ:()=>de,v3:()=>we,v7:()=>ge,fK:()=>ve,PO:()=>Se,m_:()=>_e,Ll:()=>be,OE:()=>ke,Is:()=>xe});const n="0.29.2";let o,i,a,c,h,l,u=!1,d=null,f=null,p=null,m=null,y=null,g=null,w=null;var b=s(506),_=s(5606),v=s(5692),x=s(6584),k=s(3024),S=s(2005),R=s(7075);class P{constructor(e){this.body=e}get[Symbol.toStringTag](){return"MultipartBody"}}var E=s(7830);let A=!1;const M=new v({keepAlive:!0,timeout:3e5}),C=new v.HttpsAgent({keepAlive:!0,timeout:3e5});o||function(e,t={auto:!1}){if(u)throw new Error(`you must \`import '@anthropic-ai/sdk/shims/${e.kind}'\` before importing anything else from @anthropic-ai/sdk`);if(o)throw new Error(`can't \`import '@anthropic-ai/sdk/shims/${e.kind}'\` after \`import '@anthropic-ai/sdk/shims/${o}'\``);u=t.auto,o=e.kind,i=e.fetch,d=e.Request,f=e.Response,p=e.Headers,m=e.FormData,y=e.Blob,a=e.File,c=e.ReadableStream,g=e.getMultipartRequestOptions,h=e.getDefaultAgent,l=e.fileFromPath,w=e.isFsReadStream}(("undefined"==typeof AbortController&&(globalThis.AbortController=x.AbortController),{kind:"node",fetch:b.Ay,Request:b.Kd,Response:b.YK,Headers:b.Lr,FormData:_.fS,Blob:_.YQ,File:_.ZH,ReadableStream:E.ReadableStream,getMultipartRequestOptions:async function(e,t){const s=new S.Vi(e),r=R.Readable.from(s),n=new P(r),o={...t.headers,...s.headers,"Content-Length":s.contentLength};return{...t,body:n,headers:o}},getDefaultAgent:e=>e.startsWith("https")?C:M,fileFromPath:async function(e,...t){const{fileFromPath:r}=await s.e(401).then(s.bind(s,6401));return A||(console.warn(`fileFromPath is deprecated; use fs.createReadStream(${JSON.stringify(e)}) instead`),A=!0),await r(e,...t)},isFsReadStream:e=>e instanceof k.ReadStream}),{auto:!0});class j{constructor(){this.buffer=[],this.trailingCR=!1}decode(e){let t=this.decodeText(e);if(this.trailingCR&&(t="\r"+t,this.trailingCR=!1),t.endsWith("\r")&&(this.trailingCR=!0,t=t.slice(0,-1)),!t)return[];const s=j.NEWLINE_CHARS.has(t[t.length-1]||"");let r=t.split(j.NEWLINE_REGEXP);return s&&r.pop(),1!==r.length||s?(this.buffer.length>0&&(r=[this.buffer.join("")+r[0],...r.slice(1)],this.buffer=[]),s||(this.buffer=[r.pop()||""]),r):(this.buffer.push(r[0]),[])}decodeText(e){if(null==e)return"";if("string"==typeof e)return e;if("undefined"!=typeof Buffer){if(e instanceof Buffer)return e.toString();if(e instanceof Uint8Array)return Buffer.from(e).toString();throw new de(`Unexpected: received non-Uint8Array (${e.constructor.name}) stream chunk in an environment with a global "Buffer" defined, which this library assumes to be Node. Please report this error.`)}if("undefined"!=typeof TextDecoder){if(e instanceof Uint8Array||e instanceof ArrayBuffer)return this.textDecoder??(this.textDecoder=new TextDecoder("utf8")),this.textDecoder.decode(e);throw new de(`Unexpected: received non-Uint8Array/ArrayBuffer (${e.constructor.name}) in a web platform. Please report this error.`)}throw new de("Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.")}flush(){if(!this.buffer.length&&!this.trailingCR)return[];const e=[this.buffer.join("")];return this.buffer=[],this.trailingCR=!1,e}}j.NEWLINE_CHARS=new Set(["\n","\r"]),j.NEWLINE_REGEXP=/\r\n|[\n\r]/g;class O{constructor(e,t){this.iterator=e,this.controller=t}static fromSSEResponse(e,t){let s=!1;return new O(async function*(){if(s)throw new Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");s=!0;let r=!1;try{for await(const s of async function*(e,t){if(!e.body)throw t.abort(),new de("Attempted to iterate over a response with no body");const s=new q,r=new j,n=I(e.body);for await(const e of async function*(e){let t=new Uint8Array;for await(const s of e){if(null==s)continue;const e=s instanceof ArrayBuffer?new Uint8Array(s):"string"==typeof s?(new TextEncoder).encode(s):s;let r,n=new Uint8Array(t.length+e.length);for(n.set(t),n.set(e,t.length),t=n;-1!==(r=T(t));)yield t.slice(0,r),t=t.slice(r)}t.length>0&&(yield t)}(n))for(const t of r.decode(e)){const e=s.decode(t);e&&(yield e)}for(const e of r.flush()){const t=s.decode(e);t&&(yield t)}}(e,t)){if("completion"===s.event)try{yield JSON.parse(s.data)}catch(e){throw console.error("Could not parse message into JSON:",s.data),console.error("From chunk:",s.raw),e}if("message_start"===s.event||"message_delta"===s.event||"message_stop"===s.event||"content_block_start"===s.event||"content_block_delta"===s.event||"content_block_stop"===s.event)try{yield JSON.parse(s.data)}catch(e){throw console.error("Could not parse message into JSON:",s.data),console.error("From chunk:",s.raw),e}if("ping"!==s.event&&"error"===s.event)throw fe.generate(void 0,`SSE Error: ${s.data}`,s.data,K(e.headers))}r=!0}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;throw e}finally{r||t.abort()}},t)}static fromReadableStream(e,t){let s=!1;return new O(async function*(){if(s)throw new Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");s=!0;let r=!1;try{for await(const t of async function*(){const t=new j,s=I(e);for await(const e of s)for(const s of t.decode(e))yield s;for(const e of t.flush())yield e}())r||t&&(yield JSON.parse(t));r=!0}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;throw e}finally{r||t.abort()}},t)}[Symbol.asyncIterator](){return this.iterator()}tee(){const e=[],t=[],s=this.iterator(),r=r=>({next:()=>{if(0===r.length){const r=s.next();e.push(r),t.push(r)}return r.shift()}});return[new O(()=>r(e),this.controller),new O(()=>r(t),this.controller)]}toReadableStream(){const e=this;let t;const s=new TextEncoder;return new c({async start(){t=e[Symbol.asyncIterator]()},async pull(e){try{const{value:r,done:n}=await t.next();if(n)return e.close();const o=s.encode(JSON.stringify(r)+"\n");e.enqueue(o)}catch(t){e.error(t)}},async cancel(){await(t.return?.())}})}}function T(e){for(let t=0;t<e.length-2;t++){if(10===e[t]&&10===e[t+1])return t+2;if(13===e[t]&&13===e[t+1])return t+2;if(13===e[t]&&10===e[t+1]&&t+3<e.length&&13===e[t+2]&&10===e[t+3])return t+4}return-1}class q{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;const e={event:this.event,data:this.data.join("\n"),raw:this.chunks};return this.event=null,this.data=[],this.chunks=[],e}if(this.chunks.push(e),e.startsWith(":"))return null;let[t,s,r]=function(e){const t=e.indexOf(":");return-1!==t?[e.substring(0,t),":",e.substring(t+1)]:[e,"",""]}(e);return r.startsWith(" ")&&(r=r.substring(1)),"event"===t?this.event=r:"data"===t&&this.data.push(r),null}}function I(e){if(e[Symbol.asyncIterator])return e;const t=e.getReader();return{async next(){try{const e=await t.read();return e?.done&&t.releaseLock(),e}catch(e){throw t.releaseLock(),e}},async return(){const e=t.cancel();return t.releaseLock(),await e,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}const L=e=>null!=e&&"object"==typeof e&&"number"==typeof e.size&&"string"==typeof e.type&&"function"==typeof e.text&&"function"==typeof e.slice&&"function"==typeof e.arrayBuffer;const B=e=>"string"==typeof e?e:"undefined"!=typeof Buffer&&e instanceof Buffer?String(e):void 0,U=e=>null!=e&&"object"==typeof e&&"function"==typeof e[Symbol.asyncIterator],N=e=>e&&"object"==typeof e&&e.body&&"MultipartBody"===e[Symbol.toStringTag];var W;async function $(e){const{response:t}=e;if(e.options.stream)return he("response",t.status,t.url,t.headers,t.body),e.options.__streamClass?e.options.__streamClass.fromSSEResponse(t,e.controller):O.fromSSEResponse(t,e.controller);if(204===t.status)return null;if(e.options.__binaryResponse)return t;const s=t.headers.get("content-type");if(s?.includes("application/json")||s?.includes("application/vnd.api+json")){const e=await t.json();return he("response",t.status,t.url,t.headers,e),e}const r=await t.text();return he("response",t.status,t.url,t.headers,r),r}class X extends Promise{constructor(e,t=$){super(e=>{e(null)}),this.responsePromise=e,this.parseResponse=t}_thenUnwrap(e){return new X(this.responsePromise,async t=>e(await this.parseResponse(t),t))}asResponse(){return this.responsePromise.then(e=>e.response)}async withResponse(){const[e,t]=await Promise.all([this.parse(),this.asResponse()]);return{data:e,response:t}}parse(){return this.parsedPromise||(this.parsedPromise=this.responsePromise.then(this.parseResponse)),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)}}class H{constructor({baseURL:e,maxRetries:t=2,timeout:s=6e5,httpAgent:r,fetch:n}){this.baseURL=e,this.maxRetries=re("maxRetries",t),this.timeout=re("timeout",s),this.httpAgent=r,this.fetch=n??i}authHeaders(e){return{}}defaultHeaders(e){return{Accept:"application/json","Content-Type":"application/json","User-Agent":this.getUserAgent(),...Y(),...this.authHeaders(e)}}validateHeaders(e,t){}defaultIdempotencyKey(){return`stainless-node-retry-${le()}`}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,s){return this.request(Promise.resolve(s).then(async s=>{const r=s&&L(s?.body)?new DataView(await s.body.arrayBuffer()):s?.body instanceof DataView?s.body:s?.body instanceof ArrayBuffer?new DataView(s.body):s&&ArrayBuffer.isView(s?.body)?new DataView(s.body.buffer):s?.body;return{method:e,path:t,...s,body:r}}))}getAPIList(e,t,s){return this.requestAPIList(t,{method:"get",path:e,...s})}calculateContentLength(e){if("string"==typeof e){if("undefined"!=typeof Buffer)return Buffer.byteLength(e,"utf8").toString();if("undefined"!=typeof TextEncoder)return(new TextEncoder).encode(e).length.toString()}else if(ArrayBuffer.isView(e))return e.byteLength.toString();return null}buildRequest(e,{retryCount:t=0}={}){const{method:s,path:r,query:n,headers:o={}}=e,i=ArrayBuffer.isView(e.body)||e.__binaryRequest&&"string"==typeof e.body?e.body:N(e.body)?e.body.body:e.body?JSON.stringify(e.body,null,2):null,a=this.calculateContentLength(i),c=this.buildURL(r,n);"timeout"in e&&re("timeout",e.timeout);const l=e.timeout??this.timeout,u=e.httpAgent??this.httpAgent??h(c),d=l+1e3;return"number"==typeof u?.options?.timeout&&d>(u.options.timeout??0)&&(u.options.timeout=d),this.idempotencyHeader&&"get"!==s&&(e.idempotencyKey||(e.idempotencyKey=this.defaultIdempotencyKey()),o[this.idempotencyHeader]=e.idempotencyKey),{req:{method:s,...i&&{body:i},headers:this.buildHeaders({options:e,headers:o,contentLength:a,retryCount:t}),...u&&{agent:u},signal:e.signal??null},url:c,timeout:l}}buildHeaders({options:e,headers:t,contentLength:s,retryCount:r}){const n={};return s&&(n["content-length"]=s),ce(n,this.defaultHeaders(e)),ce(n,t),N(e.body)&&"node"!==o&&delete n["content-type"],void 0===ue(t,"x-stainless-retry-count")&&(n["x-stainless-retry-count"]=String(r)),this.validateHeaders(n,t),n}async prepareOptions(e){}async prepareRequest(e,{url:t,options:s}){}parseHeaders(e){return e?Symbol.iterator in e?Object.fromEntries(Array.from(e).map(e=>[...e])):{...e}:{}}makeStatusError(e,t,s,r){return fe.generate(e,t,s,r)}request(e,t=null){return new X(this.makeRequest(e,t))}async makeRequest(e,t){const s=await e,r=s.maxRetries??this.maxRetries;null==t&&(t=r),await this.prepareOptions(s);const{req:n,url:o,timeout:i}=this.buildRequest(s,{retryCount:r-t});if(await this.prepareRequest(n,{url:o,options:s}),he("request",o,s,n.headers),s.signal?.aborted)throw new pe;const a=new AbortController,c=await this.fetchWithTimeout(o,n,i,a).catch(ne);if(c instanceof Error){if(s.signal?.aborted)throw new pe;if(t)return this.retryRequest(s,t);if("AbortError"===c.name)throw new ye;throw new me({cause:c})}const h=K(c.headers);if(!c.ok){if(t&&this.shouldRetry(c))return he(`response (error; retrying, ${t} attempts remaining)`,c.status,o,h),this.retryRequest(s,t,h);const e=await c.text().catch(e=>ne(e).message),r=Z(e),n=r?void 0:e;throw he(`response (error; ${t?"(error; no more retries left)":"(error; not retryable)"})`,c.status,o,h,n),this.makeStatusError(c.status,r,n,h)}return{response:c,options:s,controller:a}}requestAPIList(e,t){const s=this.makeRequest(t,null);return new F(this,s,e)}buildURL(e,t){const s=te(e)?new URL(e):new URL(this.baseURL+(this.baseURL.endsWith("/")&&e.startsWith("/")?e.slice(1):e)),r=this.defaultQuery();return ie(r)||(t={...r,...t}),"object"==typeof t&&t&&!Array.isArray(t)&&(s.search=this.stringifyQuery(t)),s.toString()}stringifyQuery(e){return Object.entries(e).filter(([e,t])=>void 0!==t).map(([e,t])=>{if("string"==typeof t||"number"==typeof t||"boolean"==typeof t)return`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;if(null===t)return`${encodeURIComponent(e)}=`;throw new de(`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("&")}async fetchWithTimeout(e,t,s,r){const{signal:n,...o}=t||{};n&&n.addEventListener("abort",()=>r.abort());const i=setTimeout(()=>r.abort(),s);return this.getRequestClient().fetch.call(void 0,e,{signal:r.signal,...o}).finally(()=>{clearTimeout(i)})}getRequestClient(){return{fetch:this.fetch}}shouldRetry(e){const t=e.headers.get("x-should-retry");return"true"===t||"false"!==t&&(408===e.status||409===e.status||429===e.status||e.status>=500)}async retryRequest(e,t,s){let r;const n=s?.["retry-after-ms"];if(n){const e=parseFloat(n);Number.isNaN(e)||(r=e)}const o=s?.["retry-after"];if(o&&!r){const e=parseFloat(o);r=Number.isNaN(e)?Date.parse(o)-Date.now():1e3*e}if(!(r&&0<=r&&r<6e4)){const s=e.maxRetries??this.maxRetries;r=this.calculateDefaultRetryTimeoutMillis(t,s)}return await se(r),this.makeRequest(e,t-1)}calculateDefaultRetryTimeoutMillis(e,t){const s=t-e;return Math.min(.5*Math.pow(2,s),8)*(1-.25*Math.random())*1e3}getUserAgent(){return`${this.constructor.name}/JS ${n}`}}class D{constructor(e,t,s,r){W.set(this,void 0),function(e,t,s,r,n){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===r?n.call(e,s):n?n.value=s:t.set(e,s)}(this,W,e,"f"),this.options=r,this.response=t,this.body=s}hasNextPage(){return!!this.getPaginatedItems().length&&null!=this.nextPageInfo()}async getNextPage(){const e=this.nextPageInfo();if(!e)throw new de("No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.");const t={...this.options};if("params"in e&&"object"==typeof t.query)t.query={...t.query,...e.params};else if("url"in e){const s=[...Object.entries(t.query||{}),...e.url.searchParams.entries()];for(const[t,r]of s)e.url.searchParams.set(t,r);t.query=void 0,t.path=e.url.toString()}return await function(e,t,s,r){if("a"===s&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?r:"a"===s?r.call(e):r?r.value:t.get(e)}(this,W,"f").requestAPIList(this.constructor,t)}async*iterPages(){let e=this;for(yield e;e.hasNextPage();)e=await e.getNextPage(),yield e}async*[(W=new WeakMap,Symbol.asyncIterator)](){for await(const e of this.iterPages())for(const t of e.getPaginatedItems())yield t}}class F extends X{constructor(e,t,s){super(t,async t=>new s(e,t.response,await $(t),t.options))}async*[Symbol.asyncIterator](){const e=await(this);for await(const t of e)yield t}}const K=e=>new Proxy(Object.fromEntries(e.entries()),{get(e,t){const s=t.toString();return e[s.toLowerCase()]||e[s]}}),V={method:!0,path:!0,query:!0,body:!0,headers:!0,maxRetries:!0,stream:!0,timeout:!0,httpAgent:!0,signal:!0,idempotencyKey:!0,__binaryRequest:!0,__binaryResponse:!0,__streamClass:!0},J=e=>"object"==typeof e&&null!==e&&!ie(e)&&Object.keys(e).every(e=>ae(V,e)),z=e=>"x32"===e?"x32":"x86_64"===e||"x64"===e?"x64":"arm"===e?"arm":"aarch64"===e||"arm64"===e?"arm64":e?`other:${e}`:"unknown",G=e=>(e=e.toLowerCase()).includes("ios")?"iOS":"android"===e?"Android":"darwin"===e?"MacOS":"win32"===e?"Windows":"freebsd"===e?"FreeBSD":"openbsd"===e?"OpenBSD":"linux"===e?"Linux":e?`Other:${e}`:"Unknown";let Q;const Y=()=>Q??(Q=(()=>{if("undefined"!=typeof Deno&&null!=Deno.build)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":n,"X-Stainless-OS":G(Deno.build.os),"X-Stainless-Arch":z(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":"string"==typeof Deno.version?Deno.version:Deno.version?.deno??"unknown"};if("undefined"!=typeof EdgeRuntime)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":n,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":process.version};if("[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0))return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":n,"X-Stainless-OS":G(process.platform),"X-Stainless-Arch":z(process.arch),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":process.version};const e=function(){if("undefined"==typeof navigator||!navigator)return null;const e=[{key:"edge",pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"chrome",pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"firefox",pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"safari",pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}];for(const{key:t,pattern:s}of e){const e=s.exec(navigator.userAgent);if(e)return{browser:t,version:`${e[1]||0}.${e[2]||0}.${e[3]||0}`}}return null}();return e?{"X-Stainless-Lang":"js","X-Stainless-Package-Version":n,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${e.browser}`,"X-Stainless-Runtime-Version":e.version}:{"X-Stainless-Lang":"js","X-Stainless-Package-Version":n,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}})()),Z=e=>{try{return JSON.parse(e)}catch(e){return}},ee=new RegExp("^(?:[a-z]+:)?//","i"),te=e=>ee.test(e),se=e=>new Promise(t=>setTimeout(t,e)),re=(e,t)=>{if("number"!=typeof t||!Number.isInteger(t))throw new de(`${e} must be an integer`);if(t<0)throw new de(`${e} must be a positive integer`);return t},ne=e=>{if(e instanceof Error)return e;if("object"==typeof e&&null!==e)try{return new Error(JSON.stringify(e))}catch{}return new Error(String(e))},oe=e=>"undefined"!=typeof process?process.env?.[e]?.trim()??void 0:"undefined"!=typeof Deno?Deno.env?.get?.(e)?.trim():void 0;function ie(e){if(!e)return!0;for(const t in e)return!1;return!0}function ae(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function ce(e,t){for(const s in t){if(!ae(t,s))continue;const r=s.toLowerCase();if(!r)continue;const n=t[s];null===n?delete e[r]:void 0!==n&&(e[r]=n)}}function he(e,...t){"undefined"!=typeof process&&"true"===process?.env?.DEBUG&&console.log(`Anthropic:DEBUG:${e}`,...t)}const le=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}),ue=(e,t)=>{const s=t.toLowerCase();if((e=>"function"==typeof e?.get)(e)){const r=t[0]?.toUpperCase()+t.substring(1).replace(/([^\w])(\w)/g,(e,t,s)=>t+s.toUpperCase());for(const n of[t,s,t.toUpperCase(),r]){const t=e.get(n);if(t)return t}}for(const[r,n]of Object.entries(e))if(r.toLowerCase()===s)return Array.isArray(n)?(n.length<=1||console.warn(`Received ${n.length} entries for the ${t} header, using the first entry.`),n[0]):n};class de extends Error{}class fe extends de{constructor(e,t,s,r){super(`${fe.makeMessage(e,t,s)}`),this.status=e,this.headers=r,this.request_id=r?.["request-id"],this.error=t}static makeMessage(e,t,s){const r=t?.message?"string"==typeof t.message?t.message:JSON.stringify(t.message):t?JSON.stringify(t):s;return e&&r?`${e} ${r}`:e?`${e} status code (no body)`:r||"(no status code or body)"}static generate(e,t,s,r){if(!e)return new me({message:s,cause:ne(t)});const n=t;return 400===e?new ge(e,n,s,r):401===e?new we(e,n,s,r):403===e?new be(e,n,s,r):404===e?new _e(e,n,s,r):409===e?new ve(e,n,s,r):422===e?new xe(e,n,s,r):429===e?new ke(e,n,s,r):e>=500?new Se(e,n,s,r):new fe(e,n,s,r)}}class pe extends fe{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0),this.status=void 0}}class me extends fe{constructor({message:e,cause:t}){super(void 0,void 0,e||"Connection error.",void 0),this.status=void 0,t&&(this.cause=t)}}class ye extends me{constructor({message:e}={}){super({message:e??"Request timed out."})}}class ge extends fe{constructor(){super(...arguments),this.status=400}}class we extends fe{constructor(){super(...arguments),this.status=401}}class be extends fe{constructor(){super(...arguments),this.status=403}}class _e extends fe{constructor(){super(...arguments),this.status=404}}class ve extends fe{constructor(){super(...arguments),this.status=409}}class xe extends fe{constructor(){super(...arguments),this.status=422}}class ke extends fe{constructor(){super(...arguments),this.status=429}}class Se extends fe{}class Re extends D{constructor(e,t,s,r){super(e,t,s,r),this.data=s.data||[],this.has_more=s.has_more||!1,this.first_id=s.first_id||null,this.last_id=s.last_id||null}getPaginatedItems(){return this.data??[]}nextPageParams(){const e=this.nextPageInfo();if(!e)return null;if("params"in e)return e.params;const t=Object.fromEntries(e.url.searchParams);return Object.keys(t).length?t:null}nextPageInfo(){if(this.options.query?.before_id){const e=this.first_id;return e?{params:{before_id:e}}:null}const e=this.last_id;return e?{params:{after_id:e}}:null}}class Pe{constructor(e){this._client=e}}class Ee extends Pe{create(e,t){return this._client.post("/v1/complete",{body:e,timeout:this._client._options.timeout??6e5,...t,stream:e.stream??!1})}}Ee||(Ee={});const Ae=e=>{if(0===e.length)return e;let t=e[e.length-1];switch(t.type){case"separator":return e=e.slice(0,e.length-1),Ae(e);case"number":let s=t.value[t.value.length-1];if("."===s||"-"===s)return e=e.slice(0,e.length-1),Ae(e);case"string":let r=e[e.length-2];if("delimiter"===r?.type)return e=e.slice(0,e.length-1),Ae(e);if("brace"===r?.type&&"{"===r.value)return e=e.slice(0,e.length-1),Ae(e);break;case"delimiter":return e=e.slice(0,e.length-1),Ae(e)}return e},Me=e=>JSON.parse((e=>{let t="";return e.map(e=>{"string"===e.type?t+='"'+e.value+'"':t+=e.value}),t})((e=>{let t=[];return e.map(e=>{"brace"===e.type&&("{"===e.value?t.push("}"):t.splice(t.lastIndexOf("}"),1)),"paren"===e.type&&("["===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})(Ae((e=>{let t=0,s=[];for(;t<e.length;){let r=e[t];if("\\"===r){t++;continue}if("{"===r){s.push({type:"brace",value:"{"}),t++;continue}if("}"===r){s.push({type:"brace",value:"}"}),t++;continue}if("["===r){s.push({type:"paren",value:"["}),t++;continue}if("]"===r){s.push({type:"paren",value:"]"}),t++;continue}if(":"===r){s.push({type:"separator",value:":"}),t++;continue}if(","===r){s.push({type:"delimiter",value:","}),t++;continue}if('"'===r){let n="",o=!1;for(r=e[++t];'"'!==r;){if(t===e.length){o=!0;break}if("\\"===r){if(t++,t===e.length){o=!0;break}n+=r+e[t],r=e[++t]}else n+=r,r=e[++t]}r=e[++t],o||s.push({type:"string",value:n});continue}if(r&&/\s/.test(r)){t++;continue}let n=/[0-9]/;if(r&&n.test(r)||"-"===r||"."===r){let o="";for("-"===r&&(o+=r,r=e[++t]);r&&n.test(r)||"."===r;)o+=r,r=e[++t];s.push({type:"number",value:o});continue}let o=/[a-z]/i;if(r&&o.test(r)){let n="";for(;r&&o.test(r)&&t!==e.length;)n+=r,r=e[++t];if("true"!=n&&"false"!=n&&"null"!==n){t++;continue}s.push({type:"name",value:n});continue}t++}return s})(e)))));var Ce,je,Oe,Te,qe,Ie,Le,Be,Ue,Ne,We,$e,Xe,He,De,Fe,Ke,Ve,Je,ze,Ge=function(e,t,s,r,n){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?n.call(e,s):n?n.value=s:t.set(e,s),s},Qe=function(e,t,s,r){if("a"===s&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?r:"a"===s?r.call(e):r?r.value:t.get(e)};const Ye="__json_buf";class Ze{constructor(){Ce.add(this),this.messages=[],this.receivedMessages=[],je.set(this,void 0),this.controller=new AbortController,Oe.set(this,void 0),Te.set(this,()=>{}),qe.set(this,()=>{}),Ie.set(this,void 0),Le.set(this,()=>{}),Be.set(this,()=>{}),Ue.set(this,{}),Ne.set(this,!1),We.set(this,!1),$e.set(this,!1),Xe.set(this,!1),Fe.set(this,e=>{if(Ge(this,We,!0,"f"),e instanceof Error&&"AbortError"===e.name&&(e=new pe),e instanceof pe)return Ge(this,$e,!0,"f"),this._emit("abort",e);if(e instanceof de)return this._emit("error",e);if(e instanceof Error){const t=new de(e.message);return t.cause=e,this._emit("error",t)}return this._emit("error",new de(String(e)))}),Ge(this,Oe,new Promise((e,t)=>{Ge(this,Te,e,"f"),Ge(this,qe,t,"f")}),"f"),Ge(this,Ie,new Promise((e,t)=>{Ge(this,Le,e,"f"),Ge(this,Be,t,"f")}),"f"),Qe(this,Oe,"f").catch(()=>{}),Qe(this,Ie,"f").catch(()=>{})}static fromReadableStream(e){const t=new Ze;return t._run(()=>t._fromReadableStream(e)),t}static createMessage(e,t,s){const r=new Ze;for(const e of t.messages)r._addMessageParam(e);return r._run(()=>r._createMessage(e,{...t,stream:!0},{...s,headers:{...s?.headers,"X-Stainless-Helper-Method":"stream"}})),r}_run(e){e().then(()=>{this._emitFinal(),this._emit("end")},Qe(this,Fe,"f"))}_addMessageParam(e){this.messages.push(e)}_addMessage(e,t=!0){this.receivedMessages.push(e),t&&this._emit("message",e)}async _createMessage(e,t,s){const r=s?.signal;r&&(r.aborted&&this.controller.abort(),r.addEventListener("abort",()=>this.controller.abort())),Qe(this,Ce,"m",Ke).call(this);const n=await e.create({...t,stream:!0},{...s,signal:this.controller.signal});this._connected();for await(const e of n)Qe(this,Ce,"m",Ve).call(this,e);if(n.controller.signal?.aborted)throw new pe;Qe(this,Ce,"m",Je).call(this)}_connected(){this.ended||(Qe(this,Te,"f").call(this),this._emit("connect"))}get ended(){return Qe(this,Ne,"f")}get errored(){return Qe(this,We,"f")}get aborted(){return Qe(this,$e,"f")}abort(){this.controller.abort()}on(e,t){return(Qe(this,Ue,"f")[e]||(Qe(this,Ue,"f")[e]=[])).push({listener:t}),this}off(e,t){const s=Qe(this,Ue,"f")[e];if(!s)return this;const r=s.findIndex(e=>e.listener===t);return r>=0&&s.splice(r,1),this}once(e,t){return(Qe(this,Ue,"f")[e]||(Qe(this,Ue,"f")[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,s)=>{Ge(this,Xe,!0,"f"),"error"!==e&&this.once("error",s),this.once(e,t)})}async done(){Ge(this,Xe,!0,"f"),await Qe(this,Ie,"f")}get currentMessage(){return Qe(this,je,"f")}async finalMessage(){return await this.done(),Qe(this,Ce,"m",He).call(this)}async finalText(){return await this.done(),Qe(this,Ce,"m",De).call(this)}_emit(e,...t){if(Qe(this,Ne,"f"))return;"end"===e&&(Ge(this,Ne,!0,"f"),Qe(this,Le,"f").call(this));const s=Qe(this,Ue,"f")[e];if(s&&(Qe(this,Ue,"f")[e]=s.filter(e=>!e.once),s.forEach(({listener:e})=>e(...t))),"abort"===e){const e=t[0];return Qe(this,Xe,"f")||s?.length||Promise.reject(e),Qe(this,qe,"f").call(this,e),Qe(this,Be,"f").call(this,e),void this._emit("end")}if("error"===e){const e=t[0];Qe(this,Xe,"f")||s?.length||Promise.reject(e),Qe(this,qe,"f").call(this,e),Qe(this,Be,"f").call(this,e),this._emit("end")}}_emitFinal(){this.receivedMessages.at(-1)&&this._emit("finalMessage",Qe(this,Ce,"m",He).call(this))}async _fromReadableStream(e,t){const s=t?.signal;s&&(s.aborted&&this.controller.abort(),s.addEventListener("abort",()=>this.controller.abort())),Qe(this,Ce,"m",Ke).call(this),this._connected();const r=O.fromReadableStream(e,this.controller);for await(const e of r)Qe(this,Ce,"m",Ve).call(this,e);if(r.controller.signal?.aborted)throw new pe;Qe(this,Ce,"m",Je).call(this)}[(je=new WeakMap,Oe=new WeakMap,Te=new WeakMap,qe=new WeakMap,Ie=new WeakMap,Le=new WeakMap,Be=new WeakMap,Ue=new WeakMap,Ne=new WeakMap,We=new WeakMap,$e=new WeakMap,Xe=new WeakMap,Fe=new WeakMap,Ce=new WeakSet,He=function(){if(0===this.receivedMessages.length)throw new de("stream ended without producing a Message with role=assistant");return this.receivedMessages.at(-1)},De=function(){if(0===this.receivedMessages.length)throw new de("stream ended without producing a Message with role=assistant");const e=this.receivedMessages.at(-1).content.filter(e=>"text"===e.type).map(e=>e.text);if(0===e.length)throw new de("stream ended without producing a content block with type=text");return e.join(" ")},Ke=function(){this.ended||Ge(this,je,void 0,"f")},Ve=function(e){if(this.ended)return;const t=Qe(this,Ce,"m",ze).call(this,e);switch(this._emit("streamEvent",e,t),e.type){case"content_block_delta":{const s=t.content.at(-1);"text_delta"===e.delta.type&&"text"===s.type?this._emit("text",e.delta.text,s.text||""):"input_json_delta"===e.delta.type&&"tool_use"===s.type&&s.input&&this._emit("inputJson",e.delta.partial_json,s.input);break}case"message_stop":this._addMessageParam(t),this._addMessage(t,!0);break;case"content_block_stop":this._emit("contentBlock",t.content.at(-1));break;case"message_start":Ge(this,je,t,"f")}},Je=function(){if(this.ended)throw new de("stream has ended, this shouldn't happen");const e=Qe(this,je,"f");if(!e)throw new de("request ended without sending any chunks");return Ge(this,je,void 0,"f"),e},ze=function(e){let t=Qe(this,je,"f");if("message_start"===e.type){if(t)throw new de(`Unexpected event order, got ${e.type} before receiving "message_stop"`);return e.message}if(!t)throw new de(`Unexpected event order, got ${e.type} before "message_start"`);switch(e.type){case"message_stop":case"content_block_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,t;case"content_block_start":return t.content.push(e.content_block),t;case"content_block_delta":{const s=t.content.at(e.index);if("text"===s?.type&&"text_delta"===e.delta.type)s.text+=e.delta.text;else if("tool_use"===s?.type&&"input_json_delta"===e.delta.type){let t=s[Ye]||"";t+=e.delta.partial_json,Object.defineProperty(s,Ye,{value:t,enumerable:!1,writable:!0}),t&&(s.input=Me(t))}return t}}},Symbol.asyncIterator)](){const e=[],t=[];let s=!1;return this.on("streamEvent",s=>{const r=t.shift();r?r.resolve(s):e.push(s)}),this.on("end",()=>{s=!0;for(const e of t)e.resolve(void 0);t.length=0}),this.on("abort",e=>{s=!0;for(const s of t)s.reject(e);t.length=0}),this.on("error",e=>{s=!0;for(const s of t)s.reject(e);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:s?{value:void 0,done:!0}:new Promise((e,s)=>t.push({resolve:e,reject:s})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new O(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}}class et extends Pe{create(e,t){return e.model in tt&&console.warn(`The model '${e.model}' is deprecated and will reach end-of-life on ${tt[e.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`),this._client.post("/v1/messages",{body:e,timeout:this._client._options.timeout??6e5,...t,stream:e.stream??!1})}stream(e,t){return Ze.createMessage(this,e,t)}}const tt={"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"};et||(et={});class st{constructor(e,t){this.iterator=e,this.controller=t}async*decoder(){const e=new j;for await(const t of this.iterator)for(const s of e.decode(t))yield JSON.parse(s);for(const t of e.flush())yield JSON.parse(t)}[Symbol.asyncIterator](){return this.decoder()}static fromResponse(e,t){if(!e.body)throw t.abort(),new de("Attempted to iterate over a response with no body");return new st(I(e.body),t)}}class rt extends Pe{create(e,t){const{betas:s,...r}=e;return this._client.post("/v1/messages/batches?beta=true",{body:r,...t,headers:{"anthropic-beta":[...s??[],"message-batches-2024-09-24"].toString(),...t?.headers}})}retrieve(e,t={},s){if(J(t))return this.retrieve(e,{},t);const{betas:r}=t;return this._client.get(`/v1/messages/batches/${e}?beta=true`,{...s,headers:{"anthropic-beta":[...r??[],"message-batches-2024-09-24"].toString(),...s?.headers}})}list(e={},t){if(J(e))return this.list({},e);const{betas:s,...r}=e;return this._client.getAPIList("/v1/messages/batches?beta=true",nt,{query:r,...t,headers:{"anthropic-beta":[...s??[],"message-batches-2024-09-24"].toString(),...t?.headers}})}cancel(e,t={},s){if(J(t))return this.cancel(e,{},t);const{betas:r}=t;return this._client.post(`/v1/messages/batches/${e}/cancel?beta=true`,{...s,headers:{"anthropic-beta":[...r??[],"message-batches-2024-09-24"].toString(),...s?.headers}})}async results(e,t={},s){if(J(t))return this.results(e,{},t);const r=await this.retrieve(e);if(!r.results_url)throw new de(`No batch \`results_url\`; Has it finished processing? ${r.processing_status} - ${r.id}`);const{betas:n}=t;return this._client.get(r.results_url,{...s,headers:{"anthropic-beta":[...n??[],"message-batches-2024-09-24"].toString(),...s?.headers},__binaryResponse:!0})._thenUnwrap((e,t)=>st.fromResponse(t.response,t.controller))}}class nt extends Re{}!function(e){e.BetaMessageBatchesPage=nt}(rt||(rt={}));class ot extends Pe{constructor(){super(...arguments),this.batches=new rt(this._client)}create(e,t){const{betas:s,...r}=e;return this._client.post("/v1/messages?beta=true",{body:r,timeout:this._client._options.timeout??6e5,...t,headers:{...null!=s?.toString()?{"anthropic-beta":s?.toString()}:void 0,...t?.headers},stream:e.stream??!1})}}!function(e){e.Batches=rt,e.BetaMessageBatchesPage=nt}(ot||(ot={}));var it,at,ct,ht,lt,ut,dt,ft,pt,mt,yt,gt,wt,bt,_t,vt,xt,kt,St,Rt,Pt=function(e,t,s,r,n){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?n.call(e,s):n?n.value=s:t.set(e,s),s},Et=function(e,t,s,r){if("a"===s&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?r:"a"===s?r.call(e):r?r.value:t.get(e)};const At="__json_buf";class Mt{constructor(){it.add(this),this.messages=[],this.receivedMessages=[],at.set(this,void 0),this.controller=new AbortController,ct.set(this,void 0),ht.set(this,()=>{}),lt.set(this,()=>{}),ut.set(this,void 0),dt.set(this,()=>{}),ft.set(this,()=>{}),pt.set(this,{}),mt.set(this,!1),yt.set(this,!1),gt.set(this,!1),wt.set(this,!1),vt.set(this,e=>{if(Pt(this,yt,!0,"f"),e instanceof Error&&"AbortError"===e.name&&(e=new pe),e instanceof pe)return Pt(this,gt,!0,"f"),this._emit("abort",e);if(e instanceof de)return this._emit("error",e);if(e instanceof Error){const t=new de(e.message);return t.cause=e,this._emit("error",t)}return this._emit("error",new de(String(e)))}),Pt(this,ct,new Promise((e,t)=>{Pt(this,ht,e,"f"),Pt(this,lt,t,"f")}),"f"),Pt(this,ut,new Promise((e,t)=>{Pt(this,dt,e,"f"),Pt(this,ft,t,"f")}),"f"),Et(this,ct,"f").catch(()=>{}),Et(this,ut,"f").catch(()=>{})}static fromReadableStream(e){const t=new Mt;return t._run(()=>t._fromReadableStream(e)),t}static createMessage(e,t,s){const r=new Mt;for(const e of t.messages)r._addPromptCachingBetaMessageParam(e);return r._run(()=>r._createPromptCachingBetaMessage(e,{...t,stream:!0},{...s,headers:{...s?.headers,"X-Stainless-Helper-Method":"stream"}})),r}_run(e){e().then(()=>{this._emitFinal(),this._emit("end")},Et(this,vt,"f"))}_addPromptCachingBetaMessageParam(e){this.messages.push(e)}_addPromptCachingBetaMessage(e,t=!0){this.receivedMessages.push(e),t&&this._emit("message",e)}async _createPromptCachingBetaMessage(e,t,s){const r=s?.signal;r&&(r.aborted&&this.controller.abort(),r.addEventListener("abort",()=>this.controller.abort())),Et(this,it,"m",xt).call(this);const n=await e.create({...t,stream:!0},{...s,signal:this.controller.signal});this._connected();for await(const e of n)Et(this,it,"m",kt).call(this,e);if(n.controller.signal?.aborted)throw new pe;Et(this,it,"m",St).call(this)}_connected(){this.ended||(Et(this,ht,"f").call(this),this._emit("connect"))}get ended(){return Et(this,mt,"f")}get errored(){return Et(this,yt,"f")}get aborted(){return Et(this,gt,"f")}abort(){this.controller.abort()}on(e,t){return(Et(this,pt,"f")[e]||(Et(this,pt,"f")[e]=[])).push({listener:t}),this}off(e,t){const s=Et(this,pt,"f")[e];if(!s)return this;const r=s.findIndex(e=>e.listener===t);return r>=0&&s.splice(r,1),this}once(e,t){return(Et(this,pt,"f")[e]||(Et(this,pt,"f")[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,s)=>{Pt(this,wt,!0,"f"),"error"!==e&&this.once("error",s),this.once(e,t)})}async done(){Pt(this,wt,!0,"f"),await Et(this,ut,"f")}get currentMessage(){return Et(this,at,"f")}async finalMessage(){return await this.done(),Et(this,it,"m",bt).call(this)}async finalText(){return await this.done(),Et(this,it,"m",_t).call(this)}_emit(e,...t){if(Et(this,mt,"f"))return;"end"===e&&(Pt(this,mt,!0,"f"),Et(this,dt,"f").call(this));const s=Et(this,pt,"f")[e];if(s&&(Et(this,pt,"f")[e]=s.filter(e=>!e.once),s.forEach(({listener:e})=>e(...t))),"abort"===e){const e=t[0];return Et(this,wt,"f")||s?.length||Promise.reject(e),Et(this,lt,"f").call(this,e),Et(this,ft,"f").call(this,e),void this._emit("end")}if("error"===e){const e=t[0];Et(this,wt,"f")||s?.length||Promise.reject(e),Et(this,lt,"f").call(this,e),Et(this,ft,"f").call(this,e),this._emit("end")}}_emitFinal(){this.receivedMessages.at(-1)&&this._emit("finalPromptCachingBetaMessage",Et(this,it,"m",bt).call(this))}async _fromReadableStream(e,t){const s=t?.signal;s&&(s.aborted&&this.controller.abort(),s.addEventListener("abort",()=>this.controller.abort())),Et(this,it,"m",xt).call(this),this._connected();const r=O.fromReadableStream(e,this.controller);for await(const e of r)Et(this,it,"m",kt).call(this,e);if(r.controller.signal?.aborted)throw new pe;Et(this,it,"m",St).call(this)}[(at=new WeakMap,ct=new WeakMap,ht=new WeakMap,lt=new WeakMap,ut=new WeakMap,dt=new WeakMap,ft=new WeakMap,pt=new WeakMap,mt=new WeakMap,yt=new WeakMap,gt=new WeakMap,wt=new WeakMap,vt=new WeakMap,it=new WeakSet,bt=function(){if(0===this.receivedMessages.length)throw new de("stream ended without producing a PromptCachingBetaMessage with role=assistant");return this.receivedMessages.at(-1)},_t=function(){if(0===this.receivedMessages.length)throw new de("stream ended without producing a PromptCachingBetaMessage with role=assistant");const e=this.receivedMessages.at(-1).content.filter(e=>"text"===e.type).map(e=>e.text);if(0===e.length)throw new de("stream ended without producing a content block with type=text");return e.join(" ")},xt=function(){this.ended||Pt(this,at,void 0,"f")},kt=function(e){if(this.ended)return;const t=Et(this,it,"m",Rt).call(this,e);switch(this._emit("streamEvent",e,t),e.type){case"content_block_delta":{const s=t.content.at(-1);"text_delta"===e.delta.type&&"text"===s.type?this._emit("text",e.delta.text,s.text||""):"input_json_delta"===e.delta.type&&"tool_use"===s.type&&s.input&&this._emit("inputJson",e.delta.partial_json,s.input);break}case"message_stop":this._addPromptCachingBetaMessageParam(t),this._addPromptCachingBetaMessage(t,!0);break;case"content_block_stop":this._emit("contentBlock",t.content.at(-1));break;case"message_start":Pt(this,at,t,"f")}},St=function(){if(this.ended)throw new de("stream has ended, this shouldn't happen");const e=Et(this,at,"f");if(!e)throw new de("request ended without sending any chunks");return Pt(this,at,void 0,"f"),e},Rt=function(e){let t=Et(this,at,"f");if("message_start"===e.type){if(t)throw new de(`Unexpected event order, got ${e.type} before receiving "message_stop"`);return e.message}if(!t)throw new de(`Unexpected event order, got ${e.type} before "message_start"`);switch(e.type){case"message_stop":case"content_block_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,t;case"content_block_start":return t.content.push(e.content_block),t;case"content_block_delta":{const s=t.content.at(e.index);if("text"===s?.type&&"text_delta"===e.delta.type)s.text+=e.delta.text;else if("tool_use"===s?.type&&"input_json_delta"===e.delta.type){let t=s[At]||"";t+=e.delta.partial_json,Object.defineProperty(s,At,{value:t,enumerable:!1,writable:!0}),t&&(s.input=Me(t))}return t}}},Symbol.asyncIterator)](){const e=[],t=[];let s=!1;return this.on("streamEvent",s=>{const r=t.shift();r?r.resolve(s):e.push(s)}),this.on("end",()=>{s=!0;for(const e of t)e.resolve(void 0);t.length=0}),this.on("abort",e=>{s=!0;for(const s of t)s.reject(e);t.length=0}),this.on("error",e=>{s=!0;for(const s of t)s.reject(e);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:s?{value:void 0,done:!0}:new Promise((e,s)=>t.push({resolve:e,reject:s})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new O(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}}class Ct extends Pe{create(e,t){const{betas:s,...r}=e;return this._client.post("/v1/messages?beta=prompt_caching",{body:r,timeout:this._client._options.timeout??6e5,...t,headers:{"anthropic-beta":[...s??[],"prompt-caching-2024-07-31"].toString(),...t?.headers},stream:e.stream??!1})}stream(e,t){return Mt.createMessage(this,e,t)}}Ct||(Ct={});class jt extends Pe{constructor(){super(...arguments),this.messages=new Ct(this._client)}}!function(e){e.Messages=Ct}(jt||(jt={}));class Ot extends Pe{constructor(){super(...arguments),this.messages=new ot(this._client),this.promptCaching=new jt(this._client)}}var Tt;!function(e){e.Messages=ot,e.PromptCaching=jt}(Ot||(Ot={}));class qt extends H{constructor({baseURL:e=oe("ANTHROPIC_BASE_URL"),apiKey:t=oe("ANTHROPIC_API_KEY")??null,authToken:s=oe("ANTHROPIC_AUTH_TOKEN")??null,...r}={}){const n={apiKey:t,authToken:s,...r,baseURL:e||"https://api.anthropic.com"};if(!n.dangerouslyAllowBrowser&&"undefined"!=typeof window&&void 0!==window.document&&"undefined"!=typeof navigator)throw new de("It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew Anthropic({ apiKey, dangerouslyAllowBrowser: true });\n\nTODO: link!\n");super({baseURL:n.baseURL,timeout:n.timeout??6e5,httpAgent:n.httpAgent,maxRetries:n.maxRetries,fetch:n.fetch}),this.completions=new Ee(this),this.messages=new et(this),this.beta=new Ot(this),this._options=n,this.apiKey=t,this.authToken=s}defaultQuery(){return this._options.defaultQuery}defaultHeaders(e){return{...super.defaultHeaders(e),...this._options.dangerouslyAllowBrowser?{"anthropic-dangerous-direct-browser-access":"true"}:void 0,"anthropic-version":"2023-06-01",...this._options.defaultHeaders}}validateHeaders(e,t){if(!(this.apiKey&&e["x-api-key"]||null===t["x-api-key"]||this.authToken&&e.authorization||null===t.authorization))throw new 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')}authHeaders(e){const t=this.apiKeyAuth(e),s=this.bearerAuth(e);return null==t||ie(t)?null==s||ie(s)?{}:s:t}apiKeyAuth(e){return null==this.apiKey?{}:{"X-Api-Key":this.apiKey}}bearerAuth(e){return null==this.authToken?{}:{Authorization:`Bearer ${this.authToken}`}}}Tt=qt,qt.Anthropic=Tt,qt.HUMAN_PROMPT="\n\nHuman:",qt.AI_PROMPT="\n\nAssistant:",qt.DEFAULT_TIMEOUT=6e5,qt.AnthropicError=de,qt.APIError=fe,qt.APIConnectionError=me,qt.APIConnectionTimeoutError=ye,qt.APIUserAbortError=pe,qt.NotFoundError=_e,qt.ConflictError=ve,qt.RateLimitError=ke,qt.BadRequestError=ge,qt.AuthenticationError=we,qt.InternalServerError=Se,qt.PermissionDeniedError=be,qt.UnprocessableEntityError=xe,qt.toFile=async function(e,t,s){if((e=>null!=e&&"object"==typeof e&&"string"==typeof e.name&&"number"==typeof e.lastModified&&L(e))(e=await e))return e;if((e=>null!=e&&"object"==typeof e&&"string"==typeof e.url&&"function"==typeof e.blob)(e)){const r=await e.blob();t||(t=new URL(e.url).pathname.split(/[\\/]/).pop()??"unknown_file");const n=L(r)?[await r.arrayBuffer()]:[r];return new a(n,t,s)}const r=await async function(e){let t=[];if("string"==typeof e||ArrayBuffer.isView(e)||e instanceof ArrayBuffer)t.push(e);else if(L(e))t.push(await e.arrayBuffer());else{if(!U(e))throw new Error(`Unexpected data type: ${typeof e}; constructor: ${e?.constructor?.name}; props: ${function(e){return`[${Object.getOwnPropertyNames(e).map(e=>`"${e}"`).join(", ")}]`}(e)}`);for await(const s of e)t.push(s)}return t}(e);if(t||(t=function(e){return B(e.name)||B(e.filename)||B(e.path)?.split(/[\\/]/).pop()}(e)??"unknown_file"),!s?.type){const e=r[0]?.type;"string"==typeof e&&(s={...s,type:e})}return new a(r,t,s)},qt.fileFromPath=l;const{HUMAN_PROMPT:It,AI_PROMPT:Lt}=qt,{pJ:Bt,LG:Ut,xX:Nt,qA:Wt,cH:$t,m_:Xt,fK:Ht,OE:Dt,v7:Ft,v3:Kt,PO:Vt,Ll:Jt,Is:zt}=r;!function(e){e.Page=Re,e.Completions=Ee,e.Messages=et,e.Beta=Ot}(qt||(qt={}))}};
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 401.nium.js.LICENSE.txt */
2
+ export const __webpack_esm_id__=401;export const __webpack_esm_ids__=[401];export const __webpack_esm_modules__={5157:(t,e,i)=>{if(!globalThis.DOMException)try{const{MessageChannel:t}=i(6342),e=(new t).port1,r=new ArrayBuffer;e.postMessage(r,[r,r])}catch(t){"DOMException"===t.constructor.name&&(globalThis.DOMException=t.constructor)}t.exports=globalThis.DOMException},6401:(t,e,i)=>{i.d(e,{fileFromPath:()=>p});var r=i(4421),o=i(2521),s=i(5157),a=i(1831);const n=function(t){if("object"!==(t=>Object.prototype.toString.call(t).slice(8,-1).toLowerCase())(t))return!1;const e=Object.getPrototypeOf(t);return null==e||(e.constructor&&e.constructor.toString())===Object.toString()};i(699);var c,l,d=function(t,e,i,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(t,i):o?o.value=i:e.set(t,i),i},f=function(t,e,i,r){if("a"===i&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?r:"a"===i?r.call(t):r?r.value:e.get(t)};class h{constructor(t){c.set(this,void 0),l.set(this,void 0),d(this,c,t.path,"f"),d(this,l,t.start||0,"f"),this.name=(0,o.basename)(f(this,c,"f")),this.size=t.size,this.lastModified=t.lastModified}slice(t,e){return new h({path:f(this,c,"f"),lastModified:this.lastModified,size:e-t,start:t})}async*stream(){const{mtimeMs:t}=await r.promises.stat(f(this,c,"f"));if(t>this.lastModified)throw new s("The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.","NotReadableError");this.size&&(yield*(0,r.createReadStream)(f(this,c,"f"),{start:f(this,l,"f"),end:f(this,l,"f")+this.size-1}))}get[(c=new WeakMap,l=new WeakMap,Symbol.toStringTag)](){return"File"}}async function p(t,e,i){return function(t,{mtimeMs:e,size:i},r,o={}){let s;n(r)?[o,s]=[r,void 0]:s=r;const c=new h({path:t,size:i,lastModified:e});return s||(s=c.name),new a.Z([c],s,{...o,lastModified:c.lastModified})}(t,await r.promises.stat(t),e,i)}}};
@@ -0,0 +1 @@
1
+ /*! node-domexception. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
@@ -0,0 +1,70 @@
1
+ ---
2
+ name: commit-helper
3
+ description: Git提交信息助手,帮助生成规范的commit message
4
+ keywords: commit, git, 提交, commit message, 提交信息, git commit, changelog
5
+ ---
6
+
7
+ 你是一位Git提交信息助手。你的任务是帮助用户生成清晰、规范的commit message。
8
+
9
+ ## 核心职责
10
+
11
+ 1. **分析代码变更**:理解用户修改了什么代码
12
+ 2. **生成提交信息**:根据变更内容生成符合规范的commit message
13
+ 3. **遵循约定**:使用常见的commit message规范(如Conventional Commits)
14
+
15
+ ## Commit Message 规范
16
+
17
+ 使用以下格式:
18
+
19
+ ```
20
+ <type>(<scope>): <subject>
21
+
22
+ <body>
23
+
24
+ <footer>
25
+ ```
26
+
27
+ ### Type(类型)
28
+
29
+ - `feat`: 新功能
30
+ - `fix`: 修复bug
31
+ - `docs`: 文档变更
32
+ - `style`: 代码格式调整(不影响功能)
33
+ - `refactor`: 重构代码
34
+ - `test`: 添加或修改测试
35
+ - `chore`: 构建过程或辅助工具的变动
36
+
37
+ ### 示例
38
+
39
+ ```
40
+ feat(user): 添加用户登录功能
41
+
42
+ - 实现用户名密码登录
43
+ - 添加JWT token认证
44
+ - 创建登录API接口
45
+
46
+ Closes #123
47
+ ```
48
+
49
+ ```
50
+ fix(api): 修复用户查询接口返回错误
51
+
52
+ 修复当用户ID不存在时返回500错误的问题,
53
+ 现在正确返回404状态码。
54
+
55
+ Fixes #456
56
+ ```
57
+
58
+ ## 工作流程
59
+
60
+ 1. **查看变更**:使用 `shell("git diff")` 或 `shell("git status")` 查看代码变更
61
+ 2. **分析变更**:理解修改的内容和目的
62
+ 3. **生成信息**:根据变更生成规范的commit message
63
+ 4. **展示给用户**:将生成的commit message展示给用户,供其参考或直接使用
64
+
65
+ ## 注意事项
66
+
67
+ - Subject(主题)行不超过50个字符
68
+ - Body(正文)每行不超过72个字符
69
+ - 使用现在时态("添加"而不是"添加了")
70
+ - 中文和英文都可以,但保持一致性
@@ -0,0 +1,3 @@
1
+ # 项目约定文件
2
+
3
+ - 使用中文回复所有问题