UNPKG

@anthropic-ai/claude-agent-sdk

Version:

SDK for building AI agents with Claude Code's capabilities. Programmatically interact with Claude to build autonomous agents that can understand codebases, edit files, and execute workflows.

17 lines (14 loc) • 3.21 kB
// (c) Anthropic PBC. All rights reserved. Use is subject to the Legal Agreements outlined here: https://code.claude.com/docs/en/legal-and-compliance. // Version: 0.3.333 //! symbol-dispose-prelude: defines Symbol.dispose and Symbol.asyncDispose if missing, for this bundle's `using`. if (typeof Symbol.dispose !== 'symbol') { try { Symbol.dispose = Symbol.for('Symbol.dispose') } catch {} } if (typeof Symbol.asyncDispose !== 'symbol') { try { Symbol.asyncDispose = Symbol.for('Symbol.asyncDispose') } catch {} } import{n,ot}from"./core-7ryne2zb.mjs";import{pt,gn,U}from"./core-4k0vthr8.mjs";import{AsyncLocalStorage as h}from"async_hooks";import{constants as P}from"fs";import{appendFile as k,copyFile as F,lstat as y,mkdir as S,open as d,readdir as f,readFile as b,stat as B,unlink as E,writeFile as m}from"fs/promises";class w{read(e){return b(e,"utf8")}readBytes(e){return b(e)}write(e,t,r){return m(e,t,{encoding:"utf8",mode:r})}async mkdir(e,t){try{await S(e,{recursive:!0,mode:t})}catch(r){if(n(r)!=="EEXIST")throw r}}atomicWrite(e,t,r,i){return i?.refuseLinks===!0?gn(e,t,{mode:r,refuseLinks:!0}):pt(e,t,r)}delete(e){return E(e)}list(e){return f(e)}append(e,t,r){return k(e,t,{encoding:"utf8",mode:r})}writeExclusive(e,t,r){return m(e,t,{encoding:"utf8",flag:"wx",mode:r})}writeBytesExclusive(e,t,r){return m(e,t,{flag:"wx",mode:r})}copy(e,t){return F(e,t)}async stat(e){return{mtimeMs:(await B(e)).mtimeMs}}async lstat(e){try{let t=await y(e);return{isSymbolicLink:t.isSymbolicLink(),isFile:t.isFile(),isDirectory:t.isDirectory(),mtimeMs:t.mtimeMs,nlink:t.nlink,size:t.size}}catch(t){if(n(t)==="ENOENT")return;throw t}}async listEntries(e){return(await f(e,{withFileTypes:!0})).map((r)=>({name:r.name,isDirectory:r.isDirectory(),isFile:r.isFile()}))}async readRange(e,t,r){g("readRange","offset",t),g("readRange","length",r);let i=await d(e,"r");try{return await p(i,t,r)}finally{await i.close()}}async readTail(e,t,r){g("readTail","maxBytes",t);let i=r?.noFollow?P.O_RDONLY|U:"r",o=r?.noFollow===!0&&r.recheckName===!0&&U===0,s=await d(e,i);try{let a=o?await s.stat({bigint:!0}):await s.stat();if(r?.noFollow&&!a.isFile())throw Object.assign(Error("ENXIO: not a regular file"),{code:"ENXIO",path:e,isFIFO:a.isFIFO()});let u=o?await v(e,a):"the opened file";if(u==="a link")throw Object.assign(Error("ELOOP: refusing a link or other special file"),{code:"ELOOP",path:e});if(u==="another file")throw Object.assign(Error("EAGAIN: the name changed during the read; read again"),{code:"EAGAIN",path:e});let l=Number(a.size),c=Math.min(t,l);return await p(s,l-c,c)}finally{await s.close()}}}async function v(e,t){try{let r=await y(e,{bigint:!0});if(!r.isFile())return"a link";return ot(r,t)?"another file":"the opened file"}catch(r){if(n(r)==="ENOENT")return"another file";throw r}}function g(e,t,r){if(!Number.isInteger(r)||r<0)throw RangeError(`${e}: ${t} must be a non-negative integer, got ${r}`)}async function p(e,t,r){if(r===0)return Buffer.alloc(0);let i=Buffer.alloc(r),o=0;while(o<r){let{bytesRead:s}=await e.read(i,o,r-o,t+o);if(s===0)break;o+=s}return o===r?i:Buffer.from(i.subarray(0,o))}var L=new h;function M(){return L.getStore()??new w}export{M as getStorageBackend};