coding-agents-sdk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/dist/SdkAgent-a97nkDuR.mjs +1 -0
- package/dist/adapters/claude-code-cli/index.d.mts +1 -1
- package/dist/adapters/claude-code-cli/index.mjs +2 -490
- package/dist/adapters/claude-code-sdk/index.d.mts +1 -1
- package/dist/adapters/claude-code-sdk/index.mjs +4 -483
- package/dist/adapters/codex-cli/index.d.mts +1 -1
- package/dist/adapters/codex-cli/index.mjs +2 -626
- package/dist/adapters/codex-sdk/index.d.mts +1 -1
- package/dist/adapters/codex-sdk/index.mjs +1 -286
- package/dist/adapters/gemini-cli/index.d.mts +1 -1
- package/dist/adapters/gemini-cli/index.mjs +1 -292
- package/dist/classify-error-V6x6jP_R.mjs +8 -0
- package/dist/container/index.d.mts +1 -1
- package/dist/container/index.mjs +1 -24
- package/dist/container-BY7JDOGo.mjs +1 -0
- package/dist/container-DWTITDhL.mjs +1 -0
- package/dist/container-vkn5-3Xl.mjs +1 -0
- package/dist/diff-BCfLDXNN.mjs +1 -0
- package/dist/env-Dkd8Sgjf.mjs +1 -0
- package/dist/errors-XV0frS3r.mjs +1 -0
- package/dist/execution-target-BJ5mWjDM.mjs +4 -0
- package/dist/{index-C3ZxLAd0.d.mts → index-COHwWTg_.d.mts} +6 -6
- package/dist/{index-B3YqrgIp.d.mts → index-CzvanLE_.d.mts} +3 -2
- package/dist/index-DCaZeLrI.d.mts +51 -0
- package/dist/{index-dRVpEAr8.d.mts → index-DNyKelMh.d.mts} +5 -5
- package/dist/{index-nzo1sBiK.d.mts → index-DP4Jxoax.d.mts} +7 -7
- package/dist/{index-ByAOGMUM.d.mts → index-R77YR8ak.d.mts} +1 -1
- package/dist/{index-CFpNOmdA.d.mts → index-jUwKDQ34.d.mts} +2 -1
- package/dist/index.d.mts +10 -9
- package/dist/index.mjs +1 -61
- package/dist/oci-C_S_FKHj.mjs +1 -0
- package/dist/sandbox/index.d.mts +2 -0
- package/dist/sandbox/index.mjs +1 -0
- package/dist/sandbox-DeKpyenZ.mjs +1 -0
- package/dist/schemas/index.d.mts +1 -1
- package/dist/schemas/index.mjs +1 -2
- package/dist/schemas-BM6qORw3.mjs +1 -0
- package/dist/spawner-BJesLc8I.mjs +1 -0
- package/dist/structured-output-DEkBQ-1Z.mjs +1 -0
- package/dist/{types-Cb_EXIEe.d.mts → types-COlDAzs5.d.mts} +9 -24
- package/dist/types-CwvWHEpy.mjs +1 -0
- package/dist/util-CGg8cK92.mjs +1 -0
- package/package.json +5 -1
- package/dist/Agent-D8WkUilj.mjs +0 -262
- package/dist/SdkAgent-B47mJiIE.mjs +0 -38
- package/dist/classify-error-pL6jeu4T.mjs +0 -456
- package/dist/container-2UmPZ0CI.mjs +0 -22
- package/dist/container-CHxKIonn.mjs +0 -440
- package/dist/container-D2Z0ITDJ.mjs +0 -22
- package/dist/diff-De8d3MVb.mjs +0 -333
- package/dist/errors-BAmHDQu8.mjs +0 -45
- package/dist/oci-DMZZQZ47.mjs +0 -438
- package/dist/schemas-DwD4pwJB.mjs +0 -96
- package/dist/spawner-Bw9UBEGX.mjs +0 -54
- package/dist/structured-output-BHtr_zpz.mjs +0 -19
- package/dist/types-aNMD8h3x.mjs +0 -19
- package/dist/util-B4RQZkKr.mjs +0 -77
- /package/dist/{events-nxuRbYIu.d.mts → events-D31_b0sA.d.mts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./util-CGg8cK92.mjs";import{n as t,o as n,r,s as i,t as a}from"./errors-XV0frS3r.mjs";import{n as o,r as s}from"./diff-BCfLDXNN.mjs";import{basename as c,dirname as l,join as u,posix as d}from"node:path";import{mkdir as f,readFile as p,readdir as m,stat as h,writeFile as g}from"node:fs/promises";import{CommandExitError as _,FileType as v,Sandbox as y}from"e2b";const b=(e,t)=>[e,...t].map(s).join(` `),x=e=>e.user,S=(e,t)=>{let n={...e.env,...t};return Object.keys(n).length>0?n:void 0},C=(e,t)=>t??e.workdir,w=new TextEncoder,T=e=>e instanceof Error?e:Error(String(e)),E=e=>typeof e==`string`?e:`SIGKILL`,D=(e,t)=>{let n=e?.stdio?.[t];return n===`ignore`||n===`inherit`||n===`pipe`?n:n===void 0?`pipe`:`ignore`},O=()=>{let e=[],t=[],n=!1,r,i=()=>{for(;t.length>0&&e.length>0;)t.shift().resolve({done:!1,value:e.shift()});if(r){for(;t.length>0;)t.shift().reject(r);return}if(n)for(;t.length>0;)t.shift().resolve({done:!0,value:void 0})};return{iterable:{async*[Symbol.asyncIterator](){for(;;){if(e.length>0){yield e.shift();continue}if(r)throw T(r);if(n)return;let i=await new Promise((e,n)=>{t.push({resolve:e,reject:n})});if(i.done)return;yield i.value}}},push(t){t.length===0||n||r||(e.push(w.encode(t)),i())},end(){n||r||(n=!0,i())},fail(e){n||r||(r=e,i())}}},k=(e,t)=>({spawn:(n,r,i={})=>{let a=D(i,0),o=D(i,1),s=D(i,2),c=o===`pipe`?O():void 0,l=s===`pipe`?O():void 0,u=null,d={background:!0,stdin:a===`pipe`,cwd:C(t,i.cwd),envs:S(t,i.env),user:x(t),requestTimeoutMs:t.requestTimeoutMs,onStdout:e=>{if(o===`inherit`){process.stdout.write(e);return}c?.push(e)},onStderr:e=>{if(s===`inherit`){process.stderr.write(e);return}l?.push(e)}},f=e.commands.run(b(n,r),d);return f.catch(e=>{c?.fail(e),l?.fail(e)}),{stdout:c?.iterable??null,stderr:l?.iterable??null,stdin:a===`pipe`?{write:n=>{f.then(r=>{e.commands.sendStdin(r.pid,n,{requestTimeoutMs:t.requestTimeoutMs})}).catch(()=>{})},end:()=>{f.then(n=>{e.commands.closeStdin(n.pid,{requestTimeoutMs:t.requestTimeoutMs})}).catch(()=>{})}}:null,kill:e=>{u=E(e),f.then(e=>e.kill()).catch(()=>{})},wait:async()=>{try{let e=await(await f).wait();return c?.end(),l?.end(),u?{exitCode:null,signal:u}:{exitCode:e.exitCode,signal:null}}catch(e){if(c?.end(),l?.end(),e instanceof _)return u?{exitCode:null,signal:u}:{exitCode:e.exitCode,signal:null};throw e}}}}}),A=e=>({apiKey:e.apiKey,accessToken:e.accessToken,domain:e.domain,requestTimeoutMs:e.requestTimeoutMs,headers:e.headers}),j=e=>`sandboxId`in e&&typeof e.sandboxId==`string`,M=e=>{let t=A(e);return j(e)?t:{...t,envs:e.env,timeoutMs:e.timeoutMs,metadata:e.metadata,secure:e.secure,allowInternetAccess:e.allowInternetAccess,network:e.network,lifecycle:e.lifecycle}},N=async(e,t)=>{await e.files.makeDir(t.workdir,{user:x(t)})},P=e=>e instanceof Error&&e.name===`AbortError`,F=e=>Uint8Array.from(e).buffer,I=e=>{let t=e.endsWith(`/`)&&e!==`/`?e.slice(0,-1):e;return d.basename(t)},L=async e=>{try{return await h(e)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}},R=async(e,t,n)=>{if(await e.files.exists(t,{user:n}))return e.files.getInfo(t,{user:n})},z=async(e,t,n,r)=>(await R(e,n,r))?.type===v.DIR?d.join(n,c(t)):n,B=async(e,t)=>(await L(t))?.isDirectory()?u(t,I(e)):t,V=async(e,t,n,r)=>{let i=await h(t);if(i.isDirectory()){await e.files.makeDir(n,{user:r});let i=await m(t);await Promise.all(i.map(i=>V(e,u(t,i),d.join(n,i),r)));return}if(!i.isFile())throw Error(`Unsupported local filesystem entry at ${t}.`);let a=await p(t);await e.files.write(n,F(a),{user:r})},H=async(e,t,n,r)=>{if((await e.files.getInfo(t,{user:r})).type===v.DIR){await f(n,{recursive:!0});let i=await e.files.list(t,{user:r});await Promise.all(i.map(t=>H(e,t.path,u(n,t.name),r)));return}let i=await e.files.read(t,{format:`bytes`,user:r});await f(l(n),{recursive:!0}),await g(n,i)},U=async e=>{if(j(e))return y.connect(e.sandboxId,A(e));let t=M(e);return e.template?y.create(e.template,t):y.create(t)},W=async(e,t)=>e.connect(A(t)),G=async(e,t)=>{let n=t.signal;if(n?.aborted){let e=n.reason;throw e instanceof Error?e:new DOMException(`The operation was aborted.`,`AbortError`)}let r=!1,i=()=>{r=!0,e.kill()};n?.addEventListener(`abort`,i,{once:!0});try{let t=await e.wait();if(r)throw new DOMException(`The operation was aborted.`,`AbortError`);return{exitCode:t.exitCode,stdout:t.stdout,stderr:t.stderr}}catch(e){if(r||P(e))throw new DOMException(`The operation was aborted.`,`AbortError`);if(e instanceof _)return{exitCode:e.exitCode,stdout:e.stdout,stderr:e.stderr};throw e}finally{n?.removeEventListener(`abort`,i)}},K=async s=>{let c;try{c=await U(s),await N(c,s)}catch(t){throw new a(`E2B create failed: ${e(t)}`)}let l=s.name??c.sandboxId,d=`running`,p=k(c,s),m={},h=()=>{if(d===`disposed`)throw new r},g=()=>{if(h(),d!==`running`)throw new n},_=o({owner:m,workdir:s.workdir,materialize:async(e,n)=>{g();let r=x(s),i=await R(c,e,r);if(!i)throw new t(`Target path does not exist: ${e}`);if(i.type!==v.DIR)throw new t(`Target path is not a directory: ${e}`);await f(n,{recursive:!0});for(let t of await c.files.list(e,{user:r}))await H(c,t.path,u(n,t.name),r)}}),y={get type(){return`e2b`},get id(){return c.sandboxId},get name(){return l},get config(){return s},get status(){return d},get workdir(){return s.workdir},get spawner(){return p},async start(){if(h(),d!==`running`)try{c=await W(c,s),await N(c,s),p=k(c,s),d=`running`}catch(t){throw new i(`E2B start failed: ${e(t)}`)}},async stop(){h(),d===`running`&&(await c.pause({requestTimeoutMs:s.requestTimeoutMs}),d=`stopped`)},async dispose(){if(d!==`disposed`){try{await c.kill({requestTimeoutMs:s.requestTimeoutMs})}catch{}await _.disposeSnapshots().catch(()=>{}),d=`disposed`}},async exec(e,t,n={}){g();let r={background:!0,cwd:C(s,n.cwd),envs:S(s,n.env),user:x(s),timeoutMs:n.timeoutMs,requestTimeoutMs:s.requestTimeoutMs};return G(await c.commands.run(b(e,t),r),n)},async copyTo(e,t){g();let n=await z(c,e,t,x(s));await V(c,e,n,x(s))},async copyFrom(e,t){g();let n=await B(e,t);await H(c,e,n,x(s))},async writeFile(e,t){g(),await c.files.write(e,typeof t==`string`?t:F(t),{user:x(s)})},async readFile(e){return g(),c.files.read(e,{format:`text`,user:x(s)})},async fileExists(e){return g(),c.files.exists(e,{user:x(s)})},async mkdir(e){g(),await c.files.makeDir(e,{user:x(s)})},async execShell(e,t={}){return y.exec(`sh`,[`-c`,e],t)},async logs(){return``},async syncStatus(){return d},async snapshotWorkdir(e={}){return _.snapshotWorkdir(e)},async diffWorkdir(e){return _.diffWorkdir(e)},async releaseWorkdirSnapshot(e){return _.releaseWorkdirSnapshot(e)},getHost(e){return g(),c.getHost(e)},[Symbol.asyncDispose](){return y.dispose()}};return y};export{K as createE2BContainer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./oci-C_S_FKHj.mjs";const n=async n=>{let r=n.binary??`docker`,i=await e(r,n);return t(`docker`,{binary:r,containerName:n.name,workdir:n.workdir,user:n.user,network:n.network,platform:n.platform,env:n.env,ports:n.ports,mounts:n.mounts,extraArgs:n.extraArgs,image:i,builtImage:n.build!==void 0&&!n.build.tag},n)};export{n as createDockerContainer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./oci-C_S_FKHj.mjs";const n=async n=>{let r=n.binary??`podman`,i=await e(r,n);return t(`podman`,{binary:r,containerName:n.name,workdir:n.workdir,user:n.user,network:n.network,platform:n.platform,env:n.env,ports:n.ports,mounts:n.mounts,extraArgs:n.extraArgs,image:i,builtImage:n.build!==void 0&&!n.build.tag},n)};export{n as createPodmanContainer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./util-CGg8cK92.mjs";import{n as t,o as n,r}from"./errors-XV0frS3r.mjs";import{execFile as i}from"node:child_process";import{dirname as a,isAbsolute as o,join as s,posix as c,relative as l,sep as u}from"node:path";import{promisify as d}from"node:util";import{createReadStream as f}from"node:fs";import{copyFile as p,lstat as m,mkdir as h,mkdtemp as g,readdir as _,readlink as v,rm as y,stat as b,symlink as x}from"node:fs/promises";import{tmpdir as S}from"node:os";import{createHash as C}from"node:crypto";import{pipeline as w}from"node:stream/promises";const T=e=>e instanceof Error&&`code`in e&&(`stdout`in e||`stderr`in e),E=e=>`'${e.replace(/'/g,`'\\''`)}'`,D=d(i),O=e=>e!==`..`&&!e.startsWith(`..${u}`)&&!o(e),k=(e,t)=>{let n=l(e,t);if(O(n))return n.split(u).join(c.sep)},A=(e,n,r)=>{let i=k(n,e);if(i!==void 0)return i;let a=k(r,e);if(a!==void 0)return a;throw new t(`Git diff produced a path outside the materialized trees: ${e}`)},j=e=>e.sort((e,t)=>e.path===t.path?(e.previousPath??``).localeCompare(t.previousPath??``):e.path.localeCompare(t.path)),M=async e=>{let t=await _(e,{withFileTypes:!0});for(let n of t){let t=s(e,n.name);if(n.name===`.git`){await y(t,{recursive:!0,force:!0});continue}n.isDirectory()&&await M(t)}},N=()=>g(s(S(),`cw-workdir-diff-`)),P=async e=>{e&&await y(e,{recursive:!0,force:!0}).catch(()=>{})},F=(e,t)=>{let n={cwd:e.cwd,createdAt:new Date};return t.set(n,e),n},I=(e,n,r)=>{if(typeof n!=`object`||!n)throw new t(`Invalid workdir snapshot.`);let i=r.get(n);if(!i)throw new t(`Invalid workdir snapshot.`);if(i.owner!==e)throw new t(`Workdir snapshot was created by a different container instance.`);return i},L=(e,n)=>{if(!n.has(e))throw new t(`Workdir snapshot has been released.`)},R=e=>C(`sha256`).update(e).digest(`hex`),z=e=>Buffer.isBuffer(e)?e:Buffer.from(e,`utf8`),B=async e=>{let t=C(`sha256`);return await w(f(e),t),t.digest(`hex`)},V=async(e,n,r)=>{let i=`${e}:${n}`;if(r.has(i))return r.get(i);let a=s(e,...n.split(c.sep));try{let e=await m(a),n,o;if(e.isSymbolicLink()){let e=Buffer.from(await v(a));n=R(e),o=e.byteLength}else if(e.isFile())n=await B(a),o=e.size;else throw new t(`Unsupported filesystem entry in diff metadata: ${a}`);let s={hash:n,size:o};return r.set(i,s),s}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`){r.set(i,void 0);return}throw e}},H=(e,n,r)=>{if(e.byteLength===0)return[];let i=e.toString(`utf8`).split(`\0`);i[i.length-1]===``&&i.pop();let a=[];for(let e=0;e<i.length;){let o=i[e++];if(!o)continue;if(o.startsWith(`R`)){let o=i[e++],s=i[e++];if(!o||!s)throw new t(`Failed to parse git rename entry.`);a.push({kind:`renamed`,previousPath:A(o,n,r),path:A(s,n,r)});continue}let s=i[e++];if(!s)throw new t(`Failed to parse git diff entry.`);switch(o){case`A`:a.push({kind:`added`,path:A(s,n,r)});break;case`D`:a.push({kind:`deleted`,path:A(s,n,r)});break;case`M`:a.push({kind:`modified`,path:A(s,n,r)});break;case`T`:a.push({kind:`modified`,path:A(s,n,r)});break;default:throw new t(`Unsupported git diff change kind: ${o}`)}}return a},U=async(n,r)=>{try{return H(z((await D(`git`,[`diff`,`--no-index`,`-z`,`--name-status`,`-M`,`--find-renames=100%`,n,r],{cwd:S(),encoding:`buffer`,maxBuffer:50*1024*1024})).stdout),n,r)}catch(i){if(!T(i))throw new t(`Failed to run git diff: ${e(i)}`);let a=i.code??1,o=Buffer.isBuffer(i.stdout)?i.stdout:Buffer.from(String(i.stdout??``),`utf8`),s=Buffer.isBuffer(i.stderr)?i.stderr:Buffer.from(String(i.stderr??``),`utf8`);if(a===0||a===1)return H(o,n,r);throw new t(`Failed to run git diff: ${s.toString(`utf8`).trim()||o.toString(`utf8`).trim()||`exit code ${a}`}`)}},W=async(e,t,n)=>{let r=new Map;return j(await Promise.all(e.map(async e=>{let i;i=e.kind===`added`?void 0:e.kind===`renamed`?e.previousPath:e.path;let a=e.kind===`deleted`?void 0:e.path,[o,s]=await Promise.all([i===void 0?void 0:V(t,i,r),a===void 0?void 0:V(n,a,r)]);return{path:e.path,previousPath:e.previousPath,kind:e.kind,beforeHash:o?.hash,afterHash:s?.hash,beforeSize:o?.size,afterSize:s?.size}})))},G=e=>{let t=new Set;for(let n of e)t.add(n.path),n.kind===`renamed`&&n.previousPath&&t.add(n.previousPath);return[...t].sort((e,t)=>e.localeCompare(t))},K=(i,a)=>{throw a instanceof t||a instanceof r||a instanceof n?a:new t(`${i}: ${e(a)}`)},q=async(e,n)=>{if(!(await b(e)).isDirectory())throw new t(`Target path is not a directory: ${e}`);await h(n,{recursive:!0});let r=await _(e,{withFileTypes:!0});await Promise.all(r.filter(e=>e.name!==`.git`).map(async r=>{let i=s(e,r.name),o=s(n,r.name);if(r.isDirectory()){await q(i,o);return}if(r.isSymbolicLink()){await h(a(o),{recursive:!0}),await x(await v(i),o);return}if(r.isFile()){await h(a(o),{recursive:!0}),await p(i,o);return}throw new t(`Unsupported filesystem entry in workdir diff: ${i}`)}))},J=e=>{let t=new Set,n=new WeakMap,r=async(r={})=>{let i=r.cwd??e.workdir,a;try{a=await N(),await e.materialize(i,a),await M(a);let r={owner:e.owner,tempDir:a,cwd:i,inFlightDiffs:0,released:!1};return t.add(r),a=void 0,F(r,n)}catch(e){return await P(a),K(`Failed to materialize workdir snapshot`,e)}},i=async r=>{let i=Date.now(),a=I(e.owner,r,n);L(a,t),a.inFlightDiffs++;let o;try{o=await N(),await e.materialize(a.cwd,o),await M(o);let t=await W(await U(a.tempDir,o),a.tempDir,o),n=G(t);return{cwd:a.cwd,changedFiles:n,fileChanges:t,stats:{durationMs:Date.now()-i,filesCompared:n.length}}}catch(e){return K(`Failed to diff workdir snapshot`,e)}finally{a.inFlightDiffs--,a.inFlightDiffs===0&&(a.resolveIdle?.(),a.resolveIdle=void 0),await P(o)}},a=e=>{let n=e;return n.releasePromise?n.releasePromise:(n.released=!0,t.delete(n),n.releasePromise=(async()=>{n.inFlightDiffs>0&&await new Promise(e=>{n.resolveIdle=e}),await P(n.tempDir)})(),n.releasePromise)};return{snapshotWorkdir:r,diffWorkdir:i,releaseWorkdirSnapshot:async t=>{await a(I(e.owner,t,n))},disposeSnapshots:async()=>{await Promise.all(Array.from(t).map(a))}}};export{T as i,J as n,E as r,q as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{delimiter as e}from"node:path";const t=e=>Object.keys(e).find(e=>e.toLowerCase()===`path`)??`PATH`,n=(n={})=>{let r=n.propagateEnv===!1?{}:Object.fromEntries(Object.entries(process.env).filter(e=>e[1]!==void 0)),i=n.extraPaths??[];if(i.length>0){let n=t(r),a=r[n]??``;r[n]=[...i,a].filter(Boolean).join(e)}return r};export{n as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=class extends Error{constructor(e){super(e),this.name=`ContainerError`}},t=class extends e{constructor(e){super(e),this.name=`ContainerCreateError`}},n=class extends e{constructor(e){super(e),this.name=`ContainerStartError`}},r=class extends e{constructor(e){super(e),this.name=`ContainerExecError`}},i=class extends e{constructor(e=`Container is not running.`){super(e),this.name=`ContainerNotRunningError`}},a=class extends e{constructor(e=`Container has been disposed.`){super(e),this.name=`ContainerDisposedError`}},o=class extends e{constructor(e){super(e),this.name=`ContainerDiffError`}};export{r as a,e as i,o as n,i as o,a as r,n as s,t};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{n as e}from"./types-CwvWHEpy.mjs";import{t}from"./util-CGg8cK92.mjs";import{t as n}from"./env-Dkd8Sgjf.mjs";import{t as r}from"./spawner-BJesLc8I.mjs";import{a as i,i as a,n as o,t as s}from"./classify-error-V6x6jP_R.mjs";import{dirname as c}from"node:path";import{createWriteStream as l,mkdirSync as u}from"node:fs";async function*d(e){let t=new TextDecoder,n=``;for await(let r of e){let e=t.decode(r,{stream:!0});n+=e;let i=n.split(`
|
|
2
|
+
`);n=i.pop()??``;for(let e of i){let t=e.trim();t&&(yield t)}}let r=t.decode();r&&(n+=r);let i=n.trim();i&&(yield i)}const f=e=>e.status===`rejected`?t(e.reason):void 0,p=(e,t)=>{if(e.stopReason)return;let n=f(t.stdoutResult);if(n)return{kind:`process`,message:n};let r=f(t.stderrResult);if(r)return{kind:`process`,message:r};let i=f(t.processResult);if(i)return{kind:`spawn`,message:i};if(!e.status&&!e.error){let t=e.processResult,n=e.stderrLines.join(`
|
|
3
|
+
`);if(t&&t.exitCode!==null&&t.exitCode!==0)return{kind:`process`,message:n||`Process exited with code ${t.exitCode}.`};if(!a(e)&&e.stderrLines.length>0)return{kind:`process`,message:n}}},m=e=>{let t=s(e);return t.kind===`provider`?{kind:`process`,message:t.message}:t};var h=class extends o{spawner;defaults;executionTargetRef;autoStartExecutionTarget;autoStopExecutionTarget;executionTargetStopPromise;logStream;sigkillTimer;constructor(e){super({type:e.type,capabilities:e.capabilities,sessionId:e.defaults?.sessionId,onEvent:e.onEvent}),this.spawner=e.spawner??r,this.defaults=e.defaults??{},this.executionTargetRef=e.executionTarget,this.autoStartExecutionTarget=e.autoStartExecutionTarget??!0,this.autoStopExecutionTarget=e.autoStopExecutionTarget??!1,e.logPath&&this.initLogStream(e.logPath)}onParseError(e,n){this.appendRawLog(`[parse-error] ${t(n)} ${e.slice(0,200)}`)}buildDefaultEnv(e){let t=n({propagateEnv:e});return t.CI=t.CI??`true`,this.defaults.env&&Object.assign(t,this.defaults.env),t}async executeRunCore(e,n){let r=this.setupRunLifecycle(e);try{if(r.abortedBeforeStart)return this.buildResult(e,new Date);try{await this.onBeforeRun(e);let t={...n,...e.normalizedRequest},r=this.buildArgs(t,e),i=this.buildEnv(t,e),a=this.defaults.command?.[0]??`claude`,o=[...this.defaults.command?.slice(1)??[],...r];if(e.stopReason)return this.buildResult(e,new Date);this.emitSessionStart(e),e.process=this.spawner.spawn(a,o,{cwd:e.normalizedRequest.cwd,env:i,stdio:[`pipe`,`pipe`,`pipe`]}),e.process.stdin?.end();let[s,c,l]=await Promise.allSettled([this.watchStdout(e),this.watchStderr(e),e.process.wait()]);l.status===`fulfilled`&&(e.processResult=l.value);let u=p(e,{stdoutResult:s,stderrResult:c,processResult:l});u&&(e.error=u)}catch(t){!e.stopReason&&!e.error&&(e.error=m(t))}return this.buildResult(e,new Date)}finally{r.cleanup(),this.sigkillTimer&&=(clearTimeout(this.sigkillTimer),void 0);try{await this.onRunFinished(e)}catch(e){this.appendRawLog(`[cleanup-error] ${t(e)}`)}}}async watchStdout(e){let t=e.process?.stdout;if(t)for await(let n of d(t))this.appendLog(`stdout`,n),this.processLine(e,n)}async watchStderr(e){let t=e.process?.stderr;if(t)for await(let n of d(t))this.appendLog(`stderr`,n),e.stderrLines.push(n),this.emit(e,i(e.runId,`stderr`,{sessionId:e.sessionId,text:n}))}processLine(e,t){let n;try{n=JSON.parse(t)}catch(e){this.onParseError(t,e);return}let r;try{r=this.mapRawEvent(n,{runId:e.runId,requestedSessionId:e.requestedSessionId,sessionId:e.sessionId,schemaRequested:e.normalizedRequest.schema.kind!==`none`,toolCalls:e.toolCalls})}catch(e){this.onParseError(t,e);return}this.applyBatch(e,r)}get runRequestDefaults(){return this.defaults}onHandlerError(e){this.appendRawLog(`[handler-error] ${t(e)}`)}async onDispose(){let e=this.logStream;this.logStream=void 0,e&&await new Promise(t=>{e.end(t)})}onStopRequested(e){e.process?.kill(),this.sigkillTimer=setTimeout(()=>{e.process?.kill(`SIGKILL`)},5e3),this.sigkillTimer.unref?.()}onBeforeRun(e){return this.ensureExecutionTarget()}async onRunFinished(e){this.autoStopExecutionTarget&&this.executionTargetRef&&this.executionTargetRef.status===`running`&&(this.executionTargetStopPromise=this.executionTargetRef.stop().catch(e=>{this.appendRawLog(`[auto-stop-error] ${t(e)}`)}),await this.executionTargetStopPromise)}appendRawLog(e){if(!this.logStream)return;let t=typeof e==`string`?e:JSON.stringify(e);this.logStream.write(`${t}\n`)}initLogStream(e){try{u(c(e),{recursive:!0}),this.logStream=l(e,{flags:`a`}),this.logStream.write(`\n--- ${new Date().toISOString()} ---\n`)}catch{this.logStream=void 0}}appendLog(e,t){if(!this.logStream||!t)return;let n=e===`stderr`?`STDERR`:`STDOUT`,r=new Date().toISOString();for(let e of t.split(`
|
|
4
|
+
`))e&&this.logStream.write(`[${r}] ${n} ${e}\n`)}async ensureExecutionTarget(){this.executionTargetStopPromise&&=(await this.executionTargetStopPromise,void 0),this.autoStartExecutionTarget&&this.executionTargetRef&&this.executionTargetRef.status!==`running`&&await this.executionTargetRef.start()}};const g=t=>{if(t){if(t.container&&t.sandbox)throw new e(`Pass either "container" or "sandbox", not both.`);return t.container??t.sandbox}},_=e=>{let t=g(e);return!e||!t?{executionTarget:t,options:e}:{executionTarget:t,options:{...e,cwd:e.cwd??t.workdir,spawner:t.spawner}}};export{h as n,_ as t};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { S as McpServerConfig } from "./events-
|
|
2
|
-
import {
|
|
3
|
-
import { t as Container } from "./index-
|
|
1
|
+
import { S as McpServerConfig } from "./events-D31_b0sA.mjs";
|
|
2
|
+
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-COlDAzs5.mjs";
|
|
3
|
+
import { t as Container } from "./index-R77YR8ak.mjs";
|
|
4
|
+
import { i as Sandbox } from "./index-DCaZeLrI.mjs";
|
|
4
5
|
import { z } from "zod/v4";
|
|
5
6
|
|
|
6
7
|
//#region src/adapters/claude-code-cli/events/schemas.d.ts
|
|
@@ -289,7 +290,7 @@ interface ClaudeCodeCliRunOptions {
|
|
|
289
290
|
forkSession?: boolean;
|
|
290
291
|
extraArgs?: string[];
|
|
291
292
|
}
|
|
292
|
-
|
|
293
|
+
type ClaudeCodeCliAgentOptions = ClaudeCodeCliRunOptions & ExclusiveExecutionTargetOptions<Container, Sandbox> & {
|
|
293
294
|
command?: string[] | string;
|
|
294
295
|
cwd?: string;
|
|
295
296
|
env?: Record<string, string>;
|
|
@@ -299,10 +300,9 @@ interface ClaudeCodeCliAgentOptions extends ClaudeCodeCliRunOptions {
|
|
|
299
300
|
systemPrompt?: string;
|
|
300
301
|
logPath?: string;
|
|
301
302
|
ci?: boolean;
|
|
302
|
-
container?: Container;
|
|
303
303
|
spawner?: ProcessSpawner;
|
|
304
304
|
onEvent?: AgentEventHandler;
|
|
305
|
-
}
|
|
305
|
+
};
|
|
306
306
|
interface ClaudeCodeCliAgent extends BaseAgent<EnsureDisjoint<ClaudeCodeCliRunOptions>> {
|
|
307
307
|
readonly type: "claude-code-cli";
|
|
308
308
|
fork: () => ClaudeCodeCliAgent;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as McpServerConfig } from "./events-
|
|
2
|
-
import { f as EnsureDisjoint, l as BaseAgent, t as AgentEventHandler } from "./types-
|
|
1
|
+
import { S as McpServerConfig } from "./events-D31_b0sA.mjs";
|
|
2
|
+
import { f as EnsureDisjoint, l as BaseAgent, t as AgentEventHandler } from "./types-COlDAzs5.mjs";
|
|
3
3
|
//#region src/adapters/claude-code-sdk/types.d.ts
|
|
4
4
|
type ClaudeCodeSdkPermissionMode = "acceptEdits" | "bypassPermissions" | "default" | "dontAsk" | "plan";
|
|
5
5
|
type ClaudeCodeSdkExecutable = "bun" | "deno" | "node";
|
|
@@ -23,6 +23,7 @@ interface ClaudeCodeSdkAgentOptions extends ClaudeCodeSdkRunOptions {
|
|
|
23
23
|
settings?: ClaudeCodeSdkSettings;
|
|
24
24
|
settingSources?: ClaudeCodeSdkSettingSource[];
|
|
25
25
|
container?: never;
|
|
26
|
+
sandbox?: never;
|
|
26
27
|
cwd?: string;
|
|
27
28
|
sessionId?: string;
|
|
28
29
|
model?: string;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { D as ProcessSpawner } from "./types-COlDAzs5.mjs";
|
|
2
|
+
import { H as VolumeMount } from "./index-R77YR8ak.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/sandbox/types.d.ts
|
|
5
|
+
type SandboxType = "bubblewrap";
|
|
6
|
+
type SandboxStatus = "created" | "disposed" | "running" | "stopped";
|
|
7
|
+
interface SandboxConfigBase<TType extends SandboxType> {
|
|
8
|
+
type: TType;
|
|
9
|
+
workdir: string;
|
|
10
|
+
}
|
|
11
|
+
interface SandboxIdentity<TType extends SandboxType, TConfig extends SandboxConfigBase<TType>> {
|
|
12
|
+
readonly type: TType;
|
|
13
|
+
readonly config: TConfig;
|
|
14
|
+
readonly status: SandboxStatus;
|
|
15
|
+
readonly workdir: string;
|
|
16
|
+
}
|
|
17
|
+
interface SandboxLifecycle {
|
|
18
|
+
start: () => Promise<void>;
|
|
19
|
+
stop: () => Promise<void>;
|
|
20
|
+
dispose: () => Promise<void>;
|
|
21
|
+
[Symbol.asyncDispose]: () => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
interface SandboxExecution {
|
|
24
|
+
readonly spawner: ProcessSpawner;
|
|
25
|
+
}
|
|
26
|
+
interface SandboxBase<TType extends SandboxType, TConfig extends SandboxConfigBase<TType>> extends SandboxExecution, SandboxIdentity<TType, TConfig>, SandboxLifecycle {}
|
|
27
|
+
interface BubblewrapSandboxConfig extends SandboxConfigBase<"bubblewrap"> {
|
|
28
|
+
binary?: string;
|
|
29
|
+
binds?: VolumeMount[];
|
|
30
|
+
clearEnv?: boolean;
|
|
31
|
+
setEnv?: Record<string, string>;
|
|
32
|
+
unsetEnv?: string[];
|
|
33
|
+
unshareAll?: boolean;
|
|
34
|
+
shareNetwork?: boolean;
|
|
35
|
+
hostname?: string;
|
|
36
|
+
uid?: number;
|
|
37
|
+
gid?: number;
|
|
38
|
+
tmpfs?: string[];
|
|
39
|
+
remountReadonly?: string[];
|
|
40
|
+
proc?: false | string;
|
|
41
|
+
dev?: false | string;
|
|
42
|
+
args?: string[];
|
|
43
|
+
}
|
|
44
|
+
interface BubblewrapSandbox extends SandboxBase<"bubblewrap", BubblewrapSandboxConfig> {}
|
|
45
|
+
type SandboxConfig = BubblewrapSandboxConfig;
|
|
46
|
+
type Sandbox = BubblewrapSandbox;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/sandbox/index.d.ts
|
|
49
|
+
declare function createSandbox(config: BubblewrapSandboxConfig): Promise<BubblewrapSandbox>;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { SandboxBase as a, SandboxExecution as c, SandboxStatus as d, SandboxType as f, Sandbox as i, SandboxIdentity as l, BubblewrapSandbox as n, SandboxConfig as o, BubblewrapSandboxConfig as r, SandboxConfigBase as s, createSandbox as t, SandboxLifecycle as u };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as Container } from "./index-
|
|
1
|
+
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-COlDAzs5.mjs";
|
|
2
|
+
import { t as Container } from "./index-R77YR8ak.mjs";
|
|
3
|
+
import { i as Sandbox } from "./index-DCaZeLrI.mjs";
|
|
3
4
|
import { z } from "zod/v4";
|
|
4
5
|
|
|
5
6
|
//#region src/adapters/gemini-cli/events/schemas.d.ts
|
|
@@ -16,7 +17,7 @@ interface GeminiCliRunOptions {
|
|
|
16
17
|
permissionMode?: GeminiCliPermissionMode;
|
|
17
18
|
extraArgs?: string[];
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
type GeminiCliAgentOptions = ExclusiveExecutionTargetOptions<Container, Sandbox> & GeminiCliRunOptions & {
|
|
20
21
|
command?: string[] | string;
|
|
21
22
|
cwd?: string;
|
|
22
23
|
env?: Record<string, string>;
|
|
@@ -25,10 +26,9 @@ interface GeminiCliAgentOptions extends GeminiCliRunOptions {
|
|
|
25
26
|
model?: string;
|
|
26
27
|
systemPrompt?: string;
|
|
27
28
|
logPath?: string;
|
|
28
|
-
container?: Container;
|
|
29
29
|
spawner?: ProcessSpawner;
|
|
30
30
|
onEvent?: AgentEventHandler;
|
|
31
|
-
}
|
|
31
|
+
};
|
|
32
32
|
interface GeminiCliAgent extends BaseAgent<EnsureDisjoint<GeminiCliRunOptions>> {
|
|
33
33
|
readonly type: "gemini-cli";
|
|
34
34
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { S as McpServerConfig } from "./events-
|
|
2
|
-
import {
|
|
3
|
-
import { t as Container } from "./index-
|
|
1
|
+
import { S as McpServerConfig } from "./events-D31_b0sA.mjs";
|
|
2
|
+
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-COlDAzs5.mjs";
|
|
3
|
+
import { t as Container } from "./index-R77YR8ak.mjs";
|
|
4
|
+
import { i as Sandbox } from "./index-DCaZeLrI.mjs";
|
|
4
5
|
import { z } from "zod/v4";
|
|
5
6
|
|
|
6
7
|
//#region src/adapters/codex-cli/events/schemas.d.ts
|
|
@@ -78,7 +79,7 @@ type CodexErrorEvent = z.infer<typeof codexErrorEventSchema>;
|
|
|
78
79
|
type CodexCliSandboxMode = "danger-full-access" | "read-only" | "workspace-write";
|
|
79
80
|
type CodexCliPermissionMode = "default" | "full-access" | "full-auto";
|
|
80
81
|
interface CodexCliRunOptions {
|
|
81
|
-
|
|
82
|
+
codexSandboxMode?: CodexCliSandboxMode;
|
|
82
83
|
additionalDirectories?: string[];
|
|
83
84
|
skipGitRepoCheck?: boolean;
|
|
84
85
|
permissionMode?: CodexCliPermissionMode;
|
|
@@ -88,7 +89,7 @@ interface CodexCliRunOptions {
|
|
|
88
89
|
extraArgs?: string[];
|
|
89
90
|
systemPrompt?: never;
|
|
90
91
|
}
|
|
91
|
-
|
|
92
|
+
type CodexCliAgentOptions = CodexCliRunOptions & ExclusiveExecutionTargetOptions<Container, Sandbox> & {
|
|
92
93
|
command?: string[] | string;
|
|
93
94
|
cwd?: string;
|
|
94
95
|
env?: Record<string, string>;
|
|
@@ -96,10 +97,9 @@ interface CodexCliAgentOptions extends CodexCliRunOptions {
|
|
|
96
97
|
sessionId?: string;
|
|
97
98
|
model?: string;
|
|
98
99
|
logPath?: string;
|
|
99
|
-
container?: Container;
|
|
100
100
|
spawner?: ProcessSpawner;
|
|
101
101
|
onEvent?: AgentEventHandler;
|
|
102
|
-
}
|
|
102
|
+
};
|
|
103
103
|
interface CodexCliAgent extends BaseAgent<EnsureDisjoint<CodexCliRunOptions>> {
|
|
104
104
|
readonly type: "codex-cli";
|
|
105
105
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as EnsureDisjoint, l as BaseAgent, t as AgentEventHandler } from "./types-
|
|
1
|
+
import { f as EnsureDisjoint, l as BaseAgent, t as AgentEventHandler } from "./types-COlDAzs5.mjs";
|
|
2
2
|
//#region src/adapters/codex-sdk/types.d.ts
|
|
3
3
|
type CodexSdkSandboxMode = "danger-full-access" | "read-only" | "workspace-write";
|
|
4
4
|
type CodexSdkModelReasoningEffort = "high" | "low" | "medium" | "minimal" | "xhigh";
|
|
@@ -128,6 +128,7 @@ interface CodexSdkAgentOptions extends CodexSdkRunOptions {
|
|
|
128
128
|
env?: Record<string, string>;
|
|
129
129
|
propagateEnv?: boolean;
|
|
130
130
|
container?: never;
|
|
131
|
+
sandbox?: never;
|
|
131
132
|
cwd?: string;
|
|
132
133
|
sessionId?: string;
|
|
133
134
|
model?: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { C as OutputSchema, S as McpServerConfig, T as agentCapabilitiesSchema, a as SessionStartEvent, b as ImageContentPart, c as ToolResultEvent, i as SessionEndEvent, n as MessageEvent, o as StderrEvent, r as ReasoningEvent, s as ToolCallEvent, t as AgentEvent, u as eventSchema, v as AgentCapabilities, w as TextContentPart, x as JsonSchema, y as ContentPart } from "./events-
|
|
2
|
-
import { C as
|
|
3
|
-
import { A as ContainerBase, B as ExecResult, C as E2BProviderConfig, D as DockerContainerBase, E as DockerContainer, F as ContainerLifecycle, G as WorkdirDiffStats, H as VolumeMount, I as ContainerObservability, J as WorkdirSnapshotOptions, K as WorkdirFileChange, L as ContainerStatus, M as ContainerExecution, N as ContainerFileSystem, O as DockerContainerConfig, P as ContainerIdentity, R as ContainerType, S as E2BCreateConfig, T as DockerBuildConfig, U as WorkdirChangeKind, V as PortMapping, W as WorkdirDiff, _ as E2BConnectConfig, a as ContainerDiffError, b as E2BContainerBase, c as ContainerExecError, d as PodmanBuildBase, f as PodmanBuildConfig, g as PodmanProviderConfig, h as PodmanContainerConfig, i as ContainerCreateError, j as ContainerConfigBase, k as DockerProviderConfig, l as ContainerNotRunningError, m as PodmanContainerBase, n as ContainerConfig, o as ContainerDisposedError, p as PodmanContainer, q as WorkdirSnapshot, r as createContainer, s as ContainerError, t as Container, u as ContainerStartError, v as E2BConnectionConfig, w as DockerBuildBase, x as E2BContainerConfig, y as E2BContainer, z as ExecOptions } from "./index-
|
|
4
|
-
import { a as
|
|
5
|
-
import { a as
|
|
6
|
-
import { a as
|
|
7
|
-
import { a as
|
|
8
|
-
import { a as
|
|
1
|
+
import { C as OutputSchema, S as McpServerConfig, T as agentCapabilitiesSchema, a as SessionStartEvent, b as ImageContentPart, c as ToolResultEvent, i as SessionEndEvent, n as MessageEvent, o as StderrEvent, r as ReasoningEvent, s as ToolCallEvent, t as AgentEvent, u as eventSchema, v as AgentCapabilities, w as TextContentPart, x as JsonSchema, y as ContentPart } from "./events-D31_b0sA.mjs";
|
|
2
|
+
import { C as RunTiming, E as ZodRunRequest, S as RunStatus, T as StructuredRunRequest, _ as RunProcessInfo, a as AgentValidationError, b as RunResultBase, c as AnyRunResult, d as CompletedRunResult, f as EnsureDisjoint, g as RunError, h as JsonSchemaRunRequest, i as AgentType, l as BaseAgent, m as FailedRunResult, n as AgentMetrics, o as AnyCompletedRunResult, r as AgentRunError, s as AnyRunRequest, t as AgentEventHandler, u as CancelledRunResult, v as RunRequest, w as StopReason, x as RunStats, y as RunResult } from "./types-COlDAzs5.mjs";
|
|
3
|
+
import { A as ContainerBase, B as ExecResult, C as E2BProviderConfig, D as DockerContainerBase, E as DockerContainer, F as ContainerLifecycle, G as WorkdirDiffStats, H as VolumeMount, I as ContainerObservability, J as WorkdirSnapshotOptions, K as WorkdirFileChange, L as ContainerStatus, M as ContainerExecution, N as ContainerFileSystem, O as DockerContainerConfig, P as ContainerIdentity, R as ContainerType, S as E2BCreateConfig, T as DockerBuildConfig, U as WorkdirChangeKind, V as PortMapping, W as WorkdirDiff, _ as E2BConnectConfig, a as ContainerDiffError, b as E2BContainerBase, c as ContainerExecError, d as PodmanBuildBase, f as PodmanBuildConfig, g as PodmanProviderConfig, h as PodmanContainerConfig, i as ContainerCreateError, j as ContainerConfigBase, k as DockerProviderConfig, l as ContainerNotRunningError, m as PodmanContainerBase, n as ContainerConfig, o as ContainerDisposedError, p as PodmanContainer, q as WorkdirSnapshot, r as createContainer, s as ContainerError, t as Container, u as ContainerStartError, v as E2BConnectionConfig, w as DockerBuildBase, x as E2BContainerConfig, y as E2BContainer, z as ExecOptions } from "./index-R77YR8ak.mjs";
|
|
4
|
+
import { a as SandboxBase, c as SandboxExecution, d as SandboxStatus, f as SandboxType, i as Sandbox, l as SandboxIdentity, n as BubblewrapSandbox, o as SandboxConfig, r as BubblewrapSandboxConfig, s as SandboxConfigBase, t as createSandbox, u as SandboxLifecycle } from "./index-DCaZeLrI.mjs";
|
|
5
|
+
import { a as ClaudeCodeCliRunOptions, c as ClaudeRateLimitEvent, d as ClaudeUserEvent, i as ClaudeCodeCliPermissionMode, l as ClaudeResultEvent, n as ClaudeCodeCliAgent, o as ClaudeAssistantEvent, r as ClaudeCodeCliAgentOptions, s as ClaudeEvent, u as ClaudeSystemEvent } from "./index-COHwWTg_.mjs";
|
|
6
|
+
import { a as ClaudeCodeSdkExecutable, c as ClaudeCodeSdkSettingSource, i as ClaudeCodeSdkEvent, l as ClaudeCodeSdkSettings, n as ClaudeCodeSdkAgent, o as ClaudeCodeSdkPermissionMode, r as ClaudeCodeSdkAgentOptions, s as ClaudeCodeSdkRunOptions } from "./index-CzvanLE_.mjs";
|
|
7
|
+
import { a as CodexCliRunOptions, c as CodexEvent, d as CodexItemUpdatedEvent, f as CodexThreadStartedEvent, i as CodexCliPermissionMode, l as CodexItemCompletedEvent, m as CodexTurnFailedEvent, n as CodexCliAgent, o as CodexCliSandboxMode, p as CodexTurnCompletedEvent, r as CodexCliAgentOptions, s as CodexErrorEvent, u as CodexItemStartedEvent } from "./index-DP4Jxoax.mjs";
|
|
8
|
+
import { a as CodexSdkItem, i as CodexSdkEvent, n as CodexSdkAgent, o as CodexSdkPermissionMode, r as CodexSdkAgentOptions, s as CodexSdkRunOptions } from "./index-jUwKDQ34.mjs";
|
|
9
|
+
import { a as GeminiCliRunOptions, i as GeminiCliPermissionMode, n as GeminiCliAgent, o as GeminiEvent, r as GeminiCliAgentOptions } from "./index-DNyKelMh.mjs";
|
|
9
10
|
//#region src/core/agent/create-agent.d.ts
|
|
10
11
|
declare function createAgent(type: "claude-code-cli", options?: ClaudeCodeCliAgentOptions): Promise<ClaudeCodeCliAgent>;
|
|
11
12
|
declare function createAgent(type: "claude-code-sdk", options?: ClaudeCodeSdkAgentOptions): Promise<ClaudeCodeSdkAgent>;
|
|
@@ -13,4 +14,4 @@ declare function createAgent(type: "codex-cli", options?: CodexCliAgentOptions):
|
|
|
13
14
|
declare function createAgent(type: "codex-sdk", options?: CodexSdkAgentOptions): Promise<CodexSdkAgent>;
|
|
14
15
|
declare function createAgent(type: "gemini-cli", options?: GeminiCliAgentOptions): Promise<GeminiCliAgent>;
|
|
15
16
|
//#endregion
|
|
16
|
-
export { type AgentCapabilities, type AgentEvent, type AgentEventHandler, type AgentMetrics, AgentRunError, type AgentType, AgentValidationError, type AnyCompletedRunResult, type AnyRunRequest, type AnyRunResult, type BaseAgent, type CancelledRunResult, type ClaudeAssistantEvent, type ClaudeCodeCliAgent, type ClaudeCodeCliAgentOptions, type ClaudeCodeCliPermissionMode, type ClaudeCodeCliRunOptions, type ClaudeCodeSdkAgent, type ClaudeCodeSdkAgentOptions, type ClaudeCodeSdkEvent, type ClaudeCodeSdkExecutable, type ClaudeCodeSdkPermissionMode, type ClaudeCodeSdkRunOptions, type ClaudeCodeSdkSettingSource, type ClaudeCodeSdkSettings, type ClaudeEvent, type ClaudeRateLimitEvent, type ClaudeResultEvent, type ClaudeSystemEvent, type ClaudeUserEvent, type CodexCliAgent, type CodexCliAgentOptions, type CodexCliPermissionMode, type CodexCliRunOptions, type CodexCliSandboxMode, type CodexErrorEvent, type CodexEvent, type CodexItemCompletedEvent, type CodexItemStartedEvent, type CodexItemUpdatedEvent, type CodexSdkAgent, type CodexSdkAgentOptions, type CodexSdkEvent, type CodexSdkItem, type CodexSdkPermissionMode, type CodexSdkRunOptions, type CodexThreadStartedEvent, type CodexTurnCompletedEvent, type CodexTurnFailedEvent, type CompletedRunResult, type Container, type ContainerBase, type ContainerConfig, type ContainerConfigBase, ContainerCreateError, ContainerDiffError, ContainerDisposedError, ContainerError, ContainerExecError, type ContainerExecution, type ContainerFileSystem, type ContainerIdentity, type ContainerLifecycle, ContainerNotRunningError, type ContainerObservability, ContainerStartError, type ContainerStatus, type ContainerType, type ContentPart, type DockerBuildBase, type DockerBuildConfig, type DockerContainer, type DockerContainerBase, type DockerContainerConfig, type DockerProviderConfig, type E2BConnectConfig, type E2BConnectionConfig, type E2BContainer, type E2BContainerBase, type E2BContainerConfig, type E2BCreateConfig, type E2BProviderConfig, type EnsureDisjoint, type ExecOptions, type ExecResult, type FailedRunResult, type GeminiCliAgent, type GeminiCliAgentOptions, type GeminiCliPermissionMode, type GeminiCliRunOptions, type GeminiEvent, type ImageContentPart, type JsonSchema, type JsonSchemaRunRequest, type McpServerConfig, type MessageEvent, type OutputSchema, type PodmanBuildBase, type PodmanBuildConfig, type PodmanContainer, type PodmanContainerBase, type PodmanContainerConfig, type PodmanProviderConfig, type PortMapping, type ReasoningEvent, type RunError, type RunProcessInfo, type RunRequest, type RunResult, type RunResultBase, type RunStats, type RunStatus, type RunTiming, type SessionEndEvent, type SessionStartEvent, type StderrEvent, type StopReason, type StructuredRunRequest, type TextContentPart, type ToolCallEvent, type ToolResultEvent, type VolumeMount, type WorkdirChangeKind, type WorkdirDiff, type WorkdirDiffStats, type WorkdirFileChange, type WorkdirSnapshot, type WorkdirSnapshotOptions, type ZodRunRequest, agentCapabilitiesSchema, createAgent, createContainer, eventSchema };
|
|
17
|
+
export { type AgentCapabilities, type AgentEvent, type AgentEventHandler, type AgentMetrics, AgentRunError, type AgentType, AgentValidationError, type AnyCompletedRunResult, type AnyRunRequest, type AnyRunResult, type BaseAgent, type BubblewrapSandbox, type BubblewrapSandboxConfig, type CancelledRunResult, type ClaudeAssistantEvent, type ClaudeCodeCliAgent, type ClaudeCodeCliAgentOptions, type ClaudeCodeCliPermissionMode, type ClaudeCodeCliRunOptions, type ClaudeCodeSdkAgent, type ClaudeCodeSdkAgentOptions, type ClaudeCodeSdkEvent, type ClaudeCodeSdkExecutable, type ClaudeCodeSdkPermissionMode, type ClaudeCodeSdkRunOptions, type ClaudeCodeSdkSettingSource, type ClaudeCodeSdkSettings, type ClaudeEvent, type ClaudeRateLimitEvent, type ClaudeResultEvent, type ClaudeSystemEvent, type ClaudeUserEvent, type CodexCliAgent, type CodexCliAgentOptions, type CodexCliPermissionMode, type CodexCliRunOptions, type CodexCliSandboxMode, type CodexErrorEvent, type CodexEvent, type CodexItemCompletedEvent, type CodexItemStartedEvent, type CodexItemUpdatedEvent, type CodexSdkAgent, type CodexSdkAgentOptions, type CodexSdkEvent, type CodexSdkItem, type CodexSdkPermissionMode, type CodexSdkRunOptions, type CodexThreadStartedEvent, type CodexTurnCompletedEvent, type CodexTurnFailedEvent, type CompletedRunResult, type Container, type ContainerBase, type ContainerConfig, type ContainerConfigBase, ContainerCreateError, ContainerDiffError, ContainerDisposedError, ContainerError, ContainerExecError, type ContainerExecution, type ContainerFileSystem, type ContainerIdentity, type ContainerLifecycle, ContainerNotRunningError, type ContainerObservability, ContainerStartError, type ContainerStatus, type ContainerType, type ContentPart, type DockerBuildBase, type DockerBuildConfig, type DockerContainer, type DockerContainerBase, type DockerContainerConfig, type DockerProviderConfig, type E2BConnectConfig, type E2BConnectionConfig, type E2BContainer, type E2BContainerBase, type E2BContainerConfig, type E2BCreateConfig, type E2BProviderConfig, type EnsureDisjoint, type ExecOptions, type ExecResult, type FailedRunResult, type GeminiCliAgent, type GeminiCliAgentOptions, type GeminiCliPermissionMode, type GeminiCliRunOptions, type GeminiEvent, type ImageContentPart, type JsonSchema, type JsonSchemaRunRequest, type McpServerConfig, type MessageEvent, type OutputSchema, type PodmanBuildBase, type PodmanBuildConfig, type PodmanContainer, type PodmanContainerBase, type PodmanContainerConfig, type PodmanProviderConfig, type PortMapping, type ReasoningEvent, type RunError, type RunProcessInfo, type RunRequest, type RunResult, type RunResultBase, type RunStats, type RunStatus, type RunTiming, type Sandbox, type SandboxBase, type SandboxConfig, type SandboxConfigBase, type SandboxExecution, type SandboxIdentity, type SandboxLifecycle, type SandboxStatus, type SandboxType, type SessionEndEvent, type SessionStartEvent, type StderrEvent, type StopReason, type StructuredRunRequest, type TextContentPart, type ToolCallEvent, type ToolResultEvent, type VolumeMount, type WorkdirChangeKind, type WorkdirDiff, type WorkdirDiffStats, type WorkdirFileChange, type WorkdirSnapshot, type WorkdirSnapshotOptions, type ZodRunRequest, agentCapabilitiesSchema, createAgent, createContainer, createSandbox, eventSchema };
|
package/dist/index.mjs
CHANGED
|
@@ -1,61 +1 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import { a as ContainerExecError, i as ContainerError, n as ContainerDiffError, o as ContainerNotRunningError, r as ContainerDisposedError, s as ContainerStartError, t as ContainerCreateError } from "./errors-BAmHDQu8.mjs";
|
|
3
|
-
import { createContainer } from "./container/index.mjs";
|
|
4
|
-
import { n as eventSchema, u as agentCapabilitiesSchema } from "./schemas-DwD4pwJB.mjs";
|
|
5
|
-
//#region src/core/agent/create-agent.ts
|
|
6
|
-
function resolveContainerOptions(options) {
|
|
7
|
-
if (!options?.container) return options;
|
|
8
|
-
return {
|
|
9
|
-
...options,
|
|
10
|
-
cwd: options.cwd ?? options.container.workdir
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
const isMissingModuleError = (error, packageName) => {
|
|
14
|
-
if (!(error instanceof Error) || !error.message.includes(packageName)) return false;
|
|
15
|
-
const code = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
16
|
-
return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND";
|
|
17
|
-
};
|
|
18
|
-
const wrapMissingPeerDependency = (type, packageName, error) => {
|
|
19
|
-
if (isMissingModuleError(error, packageName)) throw new AgentValidationError(`Agent type "${type}" requires the optional peer dependency "${packageName}". Install it to use this adapter.`);
|
|
20
|
-
throw error;
|
|
21
|
-
};
|
|
22
|
-
async function createAgent(type, options) {
|
|
23
|
-
switch (type) {
|
|
24
|
-
case "claude-code-cli": {
|
|
25
|
-
const typedOptions = resolveContainerOptions(options);
|
|
26
|
-
const { createClaudeCodeCliAgent } = await import("./adapters/claude-code-cli/index.mjs");
|
|
27
|
-
return createClaudeCodeCliAgent(typedOptions);
|
|
28
|
-
}
|
|
29
|
-
case "claude-code-sdk": {
|
|
30
|
-
const typedOptions = options;
|
|
31
|
-
try {
|
|
32
|
-
const { createClaudeCodeSdkAgent } = await import("./adapters/claude-code-sdk/index.mjs");
|
|
33
|
-
return createClaudeCodeSdkAgent(typedOptions);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
return wrapMissingPeerDependency("claude-code-sdk", "@anthropic-ai/claude-agent-sdk", error);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
case "codex-cli": {
|
|
39
|
-
const typedOptions = resolveContainerOptions(options);
|
|
40
|
-
const { createCodexCliAgent } = await import("./adapters/codex-cli/index.mjs");
|
|
41
|
-
return createCodexCliAgent(typedOptions);
|
|
42
|
-
}
|
|
43
|
-
case "codex-sdk": {
|
|
44
|
-
const typedOptions = options;
|
|
45
|
-
try {
|
|
46
|
-
const { createCodexSdkAgent } = await import("./adapters/codex-sdk/index.mjs");
|
|
47
|
-
return createCodexSdkAgent(typedOptions);
|
|
48
|
-
} catch (error) {
|
|
49
|
-
return wrapMissingPeerDependency("codex-sdk", "@openai/codex-sdk", error);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
case "gemini-cli": {
|
|
53
|
-
const typedOptions = resolveContainerOptions(options);
|
|
54
|
-
const { createGeminiCliAgent } = await import("./adapters/gemini-cli/index.mjs");
|
|
55
|
-
return createGeminiCliAgent(typedOptions);
|
|
56
|
-
}
|
|
57
|
-
default: throw new AgentValidationError("Unsupported agent type.");
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
export { AgentRunError, AgentValidationError, ContainerCreateError, ContainerDiffError, ContainerDisposedError, ContainerError, ContainerExecError, ContainerNotRunningError, ContainerStartError, agentCapabilitiesSchema, createAgent, createContainer, eventSchema };
|
|
1
|
+
import{n as e,t}from"./types-CwvWHEpy.mjs";import{a as n,i as r,n as i,o as a,r as o,s,t as c}from"./errors-XV0frS3r.mjs";import{createContainer as l}from"./container/index.mjs";import{t as u}from"./sandbox-DeKpyenZ.mjs";import{n as d,u as f}from"./schemas-BM6qORw3.mjs";const p=(e,t)=>{if(!(e instanceof Error)||!e.message.includes(t))return!1;let n=typeof e==`object`&&e&&`code`in e?e.code:void 0;return n===`ERR_MODULE_NOT_FOUND`||n===`MODULE_NOT_FOUND`},m=(t,n,r)=>{throw p(r,n)?new e(`Agent type "${t}" requires the optional peer dependency "${n}". Install it to use this adapter.`):r};async function h(t,n){switch(t){case`claude-code-cli`:{let{createClaudeCodeCliAgent:e}=await import(`./adapters/claude-code-cli/index.mjs`);return e(n)}case`claude-code-sdk`:{let e=n;try{let{createClaudeCodeSdkAgent:t}=await import(`./adapters/claude-code-sdk/index.mjs`);return t(e)}catch(e){return m(`claude-code-sdk`,`@anthropic-ai/claude-agent-sdk`,e)}}case`codex-cli`:{let{createCodexCliAgent:e}=await import(`./adapters/codex-cli/index.mjs`);return e(n)}case`codex-sdk`:{let e=n;try{let{createCodexSdkAgent:t}=await import(`./adapters/codex-sdk/index.mjs`);return t(e)}catch(e){return m(`codex-sdk`,`@openai/codex-sdk`,e)}}case`gemini-cli`:{let{createGeminiCliAgent:e}=await import(`./adapters/gemini-cli/index.mjs`);return e(n)}default:throw new e(`Unsupported agent type.`)}}export{t as AgentRunError,e as AgentValidationError,c as ContainerCreateError,i as ContainerDiffError,o as ContainerDisposedError,r as ContainerError,n as ContainerExecError,a as ContainerNotRunningError,s as ContainerStartError,f as agentCapabilitiesSchema,h as createAgent,l as createContainer,u as createSandbox,d as eventSchema};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./util-CGg8cK92.mjs";import{a as t,n,o as r,r as i,s as a,t as o}from"./errors-XV0frS3r.mjs";import{t as s}from"./spawner-BJesLc8I.mjs";import{i as c,n as l,r as u,t as d}from"./diff-BCfLDXNN.mjs";import{execFile as f}from"node:child_process";import{isAbsolute as p,join as m,posix as h}from"node:path";import{promisify as g}from"node:util";import{mkdtemp as _,rm as v,writeFile as y}from"node:fs/promises";import{tmpdir as b}from"node:os";import{randomBytes as x}from"node:crypto";const S=g(f),C=()=>`cw-${x(6).toString(`hex`)}`,w=async(e,t,n)=>{let r=await S(e,t,{encoding:`utf8`,timeout:n?.timeoutMs,signal:n?.signal,maxBuffer:50*1024*1024});return{stdout:r.stdout,stderr:r.stderr}},T=async(t,n)=>{let r=n.tag??`cw-build-${x(4).toString(`hex`)}`,i=[`build`,`-t`,r];if(n.args)for(let[e,t]of Object.entries(n.args))i.push(`--build-arg`,`${e}=${t}`);`dockerfile`in n&&n.dockerfile&&(i.push(`-f`,n.dockerfile),i.push(n.context??`.`));let a;if(`content`in n&&n.content){a=await _(m(b(),`cw-oci-build-`));let e=m(a,`Dockerfile`);await y(e,n.content,{encoding:`utf8`,mode:384}),i.push(`-f`,e),i.push(n.context??a)}try{await w(t,i)}catch(t){throw new o(`Image build failed: ${e(t)}`)}finally{a&&await v(a,{recursive:!0,force:!0}).catch(()=>{})}return r},E=async(e,t,n)=>{let r=await Promise.all(n.map(async n=>{try{let{container:r,protocol:i=`tcp`}=n,{stdout:a}=await w(e,[`port`,t,`${r}/${i}`]),o=/:(\d+)$/m.exec(a.trim());if(o?.[1])return[r,Number(o[1])]}catch{}})),i=new Map;for(let e of r)e&&i.set(e[0],e[1]);return i},D=(e,t)=>({spawn:(n,r,i={})=>{let a=[`exec`,`-i`];if(i.cwd&&a.push(`-w`,i.cwd),i.env)for(let[e,t]of Object.entries(i.env))a.push(`-e`,`${e}=${t}`);return a.push(e,n,...r),s.spawn(t,a,{stdio:i.stdio})}}),O=(e,t)=>{let n=h.relative(e,t);return n===``||!n.startsWith(`..`)&&!h.isAbsolute(n)},k=(e,t)=>{if(!e||e.length===0)return;let n=h.normalize(t),r;for(let t of e){if(!p(t.source))continue;let e=h.normalize(t.target);O(e,n)&&(!r||e.length>h.normalize(r.target).length)&&(r=t)}if(!r)return;let i=h.relative(h.normalize(r.target),n);return i===``?r.source:m(r.source,...i.split(`/`))},A=async(f,p,m)=>{let{binary:g,builtImage:_,containerName:v,workdir:y,user:b,network:x,platform:S,env:T,ports:O,mounts:A,extraArgs:j,image:M}=p,N=v??C(),P=[`create`,`--name`,N];if(b&&P.push(`--user`,b),x&&P.push(`--network`,x),S&&P.push(`--platform`,S),T)for(let[e,t]of Object.entries(T))P.push(`-e`,`${e}=${t}`);if(O)for(let e of O){let{host:t,container:n,protocol:r=`tcp`}=e;P.push(`-p`,`${t??``}:${n}/${r}`)}if(A)for(let e of A){let{readonly:t,source:n,target:r}=e,i=t?`ro`:`rw`;P.push(`-v`,`${n}:${r}:${i}`)}j&&P.push(...j),P.push(M,`sleep`,`infinity`);let F;try{let{stdout:e}=await w(g,P);F=e.trim()}catch(t){throw new o(`Container create failed: ${e(t)}`)}let I=`created`,L=new Map,R=()=>{if(I===`disposed`)throw new i},z=()=>{if(R(),I!==`running`)throw new r},B=D(F,g),V=l({owner:{},workdir:y,materialize:async(t,r)=>{R();let i=k(A,t);if(i){await d(i,r);return}z();try{await w(g,[`exec`,F,`sh`,`-c`,`test -d ${u(t)}`])}catch{throw new n(`Target path is not a directory: ${t}`)}try{await w(g,[`cp`,`${F}:${t}/.`,r])}catch(r){throw new n(`Failed to materialize container path ${t}: ${e(r)}`)}}}),H={get type(){return f},get id(){return F},get name(){return N},get config(){return m},get status(){return I},get workdir(){return y},get spawner(){return B},async start(){if(R(),I!==`running`){try{await w(g,[`start`,F])}catch(t){throw new a(`Container start failed: ${e(t)}`)}try{await w(g,[`exec`,F,`mkdir`,`-p`,y])}catch(t){try{await w(g,[`stop`,`-t`,`0`,F]),I=`stopped`}catch{try{let{stdout:e}=await w(g,[`inspect`,`--format`,`{{.State.Status}}`,F]);I=e.trim()===`running`?`running`:`stopped`}catch{I=`disposed`}}throw new a(`Container start failed: ${e(t)}`)}I=`running`,O?.length&&(L=await E(g,F,O))}},async stop(){if(R(),I===`running`){try{await w(g,[`stop`,`-t`,`2`,F])}catch{try{let{stdout:e}=await w(g,[`inspect`,`--format`,`{{.State.Status}}`,F]);if(e.trim()===`running`)return}catch{I=`disposed`;return}}I=`stopped`}},async dispose(){if(I!==`disposed`){try{await w(g,[`stop`,`-t`,`0`,F])}catch{}try{await w(g,[`rm`,`-f`,F])}catch{}_&&await w(g,[`rmi`,M]).catch(()=>{}),await V.disposeSnapshots().catch(()=>{}),I=`disposed`}},async exec(e,t,n={}){z();let r=[`exec`];if(n.cwd&&r.push(`-w`,n.cwd),n.env)for(let[e,t]of Object.entries(n.env))r.push(`-e`,`${e}=${t}`);r.push(F,e,...t);try{let{stdout:e,stderr:t}=await w(g,r,{timeoutMs:n.timeoutMs,signal:n.signal});return{exitCode:0,stdout:e,stderr:t}}catch(e){if(c(e))return{exitCode:typeof e.code==`number`?e.code:-1,stdout:String(e.stdout??``),stderr:String(e.stderr??``)};throw e}},async copyTo(e,t){z(),await w(g,[`cp`,e,`${F}:${t}`])},async copyFrom(e,t){z(),await w(g,[`cp`,`${F}:${e}`,t])},async writeFile(e,n){z();let r=h.isAbsolute(e)?e:h.resolve(y,e),i=h.dirname(r),a=typeof n==`string`?Buffer.from(n,`utf8`):n,o=[`exec`,`-i`];b&&o.push(`--user`,b),o.push(F,`sh`,`-c`,`mkdir -p ${u(i)} && cat > ${u(r)}`);let c=s.spawn(g,o,{stdio:[`pipe`,`ignore`,`ignore`]});c.stdin?.write?.(a),c.stdin?.end();let l=await c.wait();if(l.exitCode!==0)throw new t(`writeFile failed for ${r} (exit ${l.exitCode})`)},async readFile(e){z();let t=h.isAbsolute(e)?e:h.resolve(y,e),{stdout:n}=await w(g,[`exec`,F,`cat`,t]);return n},async fileExists(e){z();let t=h.isAbsolute(e)?e:h.resolve(y,e);try{return await w(g,[`exec`,F,`test`,`-e`,t]),!0}catch{return!1}},async mkdir(e){z();let t=h.isAbsolute(e)?e:h.resolve(y,e);await w(g,[`exec`,F,`mkdir`,`-p`,t])},async execShell(e,t={}){return H.exec(`sh`,[`-c`,e],t)},async logs(e={}){R();let t=[`logs`];e.tail!==void 0&&t.push(`--tail`,String(e.tail)),t.push(F);let{stdout:n}=await w(g,t);return n},async syncStatus(){R();try{let{stdout:e}=await w(g,[`inspect`,`--format`,`{{.State.Status}}`,F]),t=e.trim();I=t===`running`?`running`:t===`created`?`created`:`stopped`}catch{I=`disposed`}return I},async snapshotWorkdir(e={}){return V.snapshotWorkdir(e)},async diffWorkdir(e){return V.diffWorkdir(e)},async releaseWorkdirSnapshot(e){return V.releaseWorkdirSnapshot(e)},getMappedPort(e){return L.get(e)},[Symbol.asyncDispose](){return H.dispose()}};return H},j=async(e,t)=>{if(t.image)return t.image;if(t.build)return T(e,t.build);throw new o(`Either image or build must be provided.`)};export{j as n,A as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SandboxBase, c as SandboxExecution, d as SandboxStatus, f as SandboxType, i as Sandbox, l as SandboxIdentity, n as BubblewrapSandbox, o as SandboxConfig, r as BubblewrapSandboxConfig, s as SandboxConfigBase, t as createSandbox, u as SandboxLifecycle } from "../index-DCaZeLrI.mjs";
|
|
2
|
+
export { BubblewrapSandbox, BubblewrapSandboxConfig, Sandbox, SandboxBase, SandboxConfig, SandboxConfigBase, SandboxExecution, SandboxIdentity, SandboxLifecycle, SandboxStatus, SandboxType, createSandbox };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"../sandbox-DeKpyenZ.mjs";export{e as createSandbox};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./util-CGg8cK92.mjs";import{t}from"./env-Dkd8Sgjf.mjs";import{t as n}from"./spawner-BJesLc8I.mjs";import{execFile as r}from"node:child_process";import{posix as i}from"node:path";import{promisify as a}from"node:util";const o=`bwrap`,s=[`/tmp`],c=a(r),l=(e,t)=>e.binds?.some(e=>e.target===t)??!1,u=(e,t)=>{let n=i.relative(e,t);return n===``||!n.startsWith(`..`)&&!i.isAbsolute(n)},d=(e,t)=>e.target.length-t.target.length,f=e=>{let t=l(e,e.workdir)?[...e.binds??[]]:[{source:e.workdir,target:e.workdir},...e.binds??[]],n=e.tmpfs??s,r=t.filter(e=>!n.some(t=>u(t,e.target))).toSorted(d),i=t.filter(e=>n.some(t=>u(t,e.target))).toSorted(d);return[...r,...i]},p=e=>{let t=[`--ro-bind`,`/`,`/`];for(let n of f(e))t.push(n.readonly?`--ro-bind`:`--bind`,n.source,n.target);return t},m=(e,t)=>{let n=[];(e.clearEnv??!0)&&n.push(`--clearenv`);for(let t of e.unsetEnv??[])n.push(`--unsetenv`,t);let r={...e.setEnv,...t.env};for(let[e,t]of Object.entries(r))n.push(`--setenv`,e,t);return n},h=e=>{let t=[`--die-with-parent`,`--new-session`];return(e.unshareAll??!0)&&t.push(`--unshare-all`),e.shareNetwork&&t.push(`--share-net`),e.uid!==void 0&&t.push(`--uid`,String(e.uid)),e.gid!==void 0&&t.push(`--gid`,String(e.gid)),e.hostname&&t.push(`--hostname`,e.hostname),t},g=e=>{let t=[`--ro-bind`,`/`,`/`];e.proc!==!1&&t.push(`--proc`,e.proc??`/proc`),e.dev!==!1&&t.push(`--dev`,e.dev??`/dev`);for(let n of e.tmpfs??s)t.push(`--tmpfs`,n);t.push(...p(e).slice(3));for(let n of e.remountReadonly??[])t.push(`--remount-ro`,n);return t},_=(e,t,n,r={})=>[...h(e),...g(e),...m(e,r),`--chdir`,r.cwd??e.workdir,...e.args??[],`--`,t,...n],v=async n=>{try{await c(n,[`--version`],{env:t(),encoding:`utf8`})}catch(t){throw Error(`Bubblewrap start failed: ${e(t)}`)}},y=(e,n,r,i)=>({spawn(a,s,c={}){return n(),r(i.spawn(e.binary??o,_(e,a,s,c),{env:t(),stdio:c.stdio}))}}),b=async(e,t=n)=>{let r=`created`,i=new Set,a=()=>{if(r===`disposed`)throw Error(`Bubblewrap sandbox has been disposed.`)},s=()=>{if(a(),r!==`running`)throw Error(`Bubblewrap sandbox is not running.`)},c=e=>{let t={process:e,waitPromise:e.wait().finally(()=>{i.delete(t)})};return i.add(t),{...e,wait:()=>t.waitPromise}},l=async()=>{let e=Array.from(i,e=>(e.process.kill(`SIGKILL`),e.waitPromise));await Promise.allSettled(e)},u=y(e,s,c,t),d={type:`bubblewrap`,config:e,get status(){return r},get workdir(){return e.workdir},get spawner(){return u},async start(){a(),r!==`running`&&(await v(e.binary??o),r=`running`)},async stop(){a(),r===`running`&&(r=`stopped`,await l())},async dispose(){r!==`disposed`&&(r=`disposed`,await l())},[Symbol.asyncDispose](){return d.dispose()}};return d};async function x(e){switch(e.type){case`bubblewrap`:return b(e)}throw Error(`Unsupported sandbox type.`)}export{x as t};
|
package/dist/schemas/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as OutputSchema, D as imageContentPartSchema, E as contentPartSchema, O as textContentPartSchema, S as McpServerConfig, T as agentCapabilitiesSchema, _ as toolResultEventSchema, a as SessionStartEvent, b as ImageContentPart, c as ToolResultEvent, d as messageEventSchema, f as reasoningEventSchema, g as toolCallEventSchema, h as stderrEventSchema, i as SessionEndEvent, l as baseEventSchema, m as sessionStartEventSchema, n as MessageEvent, o as StderrEvent, p as sessionEndEventSchema, r as ReasoningEvent, s as ToolCallEvent, t as AgentEvent, u as eventSchema, v as AgentCapabilities, w as TextContentPart, x as JsonSchema, y as ContentPart } from "../events-
|
|
1
|
+
import { C as OutputSchema, D as imageContentPartSchema, E as contentPartSchema, O as textContentPartSchema, S as McpServerConfig, T as agentCapabilitiesSchema, _ as toolResultEventSchema, a as SessionStartEvent, b as ImageContentPart, c as ToolResultEvent, d as messageEventSchema, f as reasoningEventSchema, g as toolCallEventSchema, h as stderrEventSchema, i as SessionEndEvent, l as baseEventSchema, m as sessionStartEventSchema, n as MessageEvent, o as StderrEvent, p as sessionEndEventSchema, r as ReasoningEvent, s as ToolCallEvent, t as AgentEvent, u as eventSchema, v as AgentCapabilities, w as TextContentPart, x as JsonSchema, y as ContentPart } from "../events-D31_b0sA.mjs";
|
|
2
2
|
export { type AgentCapabilities, type AgentEvent, type ContentPart, type ImageContentPart, type JsonSchema, type McpServerConfig, type MessageEvent, type OutputSchema, type ReasoningEvent, type SessionEndEvent, type SessionStartEvent, type StderrEvent, type TextContentPart, type ToolCallEvent, type ToolResultEvent, agentCapabilitiesSchema, baseEventSchema, contentPartSchema, eventSchema, imageContentPartSchema, messageEventSchema, reasoningEventSchema, sessionEndEventSchema, sessionStartEventSchema, stderrEventSchema, textContentPartSchema, toolCallEventSchema, toolResultEventSchema };
|
package/dist/schemas/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export { agentCapabilitiesSchema, baseEventSchema, contentPartSchema, eventSchema, imageContentPartSchema, messageEventSchema, reasoningEventSchema, sessionEndEventSchema, sessionStartEventSchema, stderrEventSchema, textContentPartSchema, toolCallEventSchema, toolResultEventSchema };
|
|
1
|
+
import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,p as c,r as l,s as u,t as d,u as f}from"../schemas-BM6qORw3.mjs";export{f as agentCapabilitiesSchema,d as baseEventSchema,n as contentPartSchema,o as eventSchema,r as imageContentPartSchema,l as messageEventSchema,i as reasoningEventSchema,e as sessionEndEventSchema,s as sessionStartEventSchema,u as stderrEventSchema,c as textContentPartSchema,t as toolCallEventSchema,a as toolResultEventSchema};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as e}from"zod/v4";const t=e.object({type:e.literal(`text`),text:e.string()}),n=e.object({type:e.literal(`image`),path:e.string(),mediaType:e.string().optional()}),r=e.discriminatedUnion(`type`,[t,n]),i=e.object({structuredOutput:e.boolean(),sessionResume:e.boolean(),imageInput:e.boolean(),mcp:e.boolean(),eventStreaming:e.boolean(),sessionFork:e.boolean().optional()}),a=e.object({id:e.string(),runId:e.string(),timestamp:e.date()}),o=a.extend({type:e.literal(`session-start`),requestedSessionId:e.string().optional(),sessionId:e.string().optional(),resumed:e.boolean()}),s=a.extend({type:e.literal(`message`),sessionId:e.string().optional(),model:e.string().nullable(),role:e.enum([`system`,`user`,`assistant`]),content:e.array(r),text:e.string().optional()}),c=a.extend({type:e.literal(`reasoning`),sessionId:e.string().optional(),model:e.string().nullable(),content:e.array(r),text:e.string().optional()}),l=a.extend({type:e.literal(`tool-call`),sessionId:e.string().optional(),model:e.string().nullable(),toolCallId:e.string(),toolName:e.string(),input:e.unknown().optional()}),u=a.extend({type:e.literal(`tool-result`),sessionId:e.string().optional(),toolCallId:e.string(),toolName:e.string().optional(),input:e.unknown().optional(),output:e.unknown(),isError:e.boolean().optional(),error:e.string().optional()}),d=a.extend({type:e.literal(`stderr`),sessionId:e.string().optional(),text:e.string()}),f=a.extend({type:e.literal(`session-end`),sessionId:e.string().optional(),status:e.enum([`completed`,`failed`,`cancelled`]),error:e.string().optional()}),p=e.discriminatedUnion(`type`,[o,s,c,l,u,d,f]);export{f as a,l as c,r as d,n as f,c as i,u as l,p as n,o,t as p,s as r,d as s,a as t,i as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{spawn as e}from"node:child_process";const t=e=>({async*[Symbol.asyncIterator](){for await(let t of e){if(t instanceof Buffer){yield new Uint8Array(t);continue}if(typeof t==`string`){yield new TextEncoder().encode(t);continue}if(t instanceof Uint8Array){yield t;continue}throw Error(`Unsupported stdout/stderr chunk type: ${typeof t}`)}}}),n={spawn:(n,r,i={})=>{let a=e(n,r,{cwd:i.cwd,env:i.env,stdio:i.stdio}),o=new Promise((e,t)=>{let n=(t,n)=>{a.removeListener(`error`,r),e({exitCode:t,signal:n})},r=e=>{a.removeListener(`close`,n),t(e)};a.once(`error`,r),a.once(`close`,n)});return{stdout:a.stdout?t(a.stdout):null,stderr:a.stderr?t(a.stderr):null,stdin:a.stdin?{write:e=>a.stdin?.write(e),end:()=>a.stdin?.end()}:null,kill:e=>a.kill(e),wait:()=>o}}};export{n as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=e=>{let t;for(let[,n]of e)n.toolName===`StructuredOutput`&&n.input!==void 0&&(t=n.input);return t},t=(t,n,r,i)=>{if(t!==void 0)return{value:t};if(!n.schemaRequested)return{};let a=e(n.toolCalls);return a===void 0?r.isSuccess?{error:{kind:`parse`,message:i}}:{}:{value:a}};export{t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as AgentEvent, v as AgentCapabilities, x as JsonSchema, y as ContentPart } from "./events-
|
|
1
|
+
import { t as AgentEvent, v as AgentCapabilities, x as JsonSchema, y as ContentPart } from "./events-D31_b0sA.mjs";
|
|
2
2
|
import { ZodType } from "zod/v4";
|
|
3
3
|
|
|
4
4
|
//#region src/core/process/types.d.ts
|
|
@@ -28,13 +28,9 @@ interface ProcessSpawner {
|
|
|
28
28
|
}
|
|
29
29
|
//#endregion
|
|
30
30
|
//#region src/core/agent/types.d.ts
|
|
31
|
-
/** Supported agents */
|
|
32
31
|
type AgentType = "claude-code-cli" | "claude-code-sdk" | "codex-cli" | "codex-sdk" | "gemini-cli";
|
|
33
|
-
/** Terminal status of a completed agent run */
|
|
34
32
|
type RunStatus = "cancelled" | "completed" | "failed";
|
|
35
|
-
/** Reason an agent run was stopped before completion */
|
|
36
33
|
type StopReason = "abort" | "timeout" | "user";
|
|
37
|
-
/** Usage and performance statistics from an agent run */
|
|
38
34
|
interface RunStats {
|
|
39
35
|
durationMs?: number;
|
|
40
36
|
apiDurationMs?: number;
|
|
@@ -46,13 +42,10 @@ interface RunStats {
|
|
|
46
42
|
outputTokens?: number;
|
|
47
43
|
totalTokens?: number;
|
|
48
44
|
}
|
|
49
|
-
/** Structured error from a failed or cancelled agent run */
|
|
50
45
|
interface RunError {
|
|
51
|
-
/** Error classification: abort (externally stopped), parse (output parsing), process (non-zero exit), provider (api error), spawn (binary not found) */
|
|
52
46
|
kind: "abort" | "parse" | "process" | "provider" | "spawn";
|
|
53
47
|
message: string;
|
|
54
48
|
}
|
|
55
|
-
/** Input parameters for a plain-text agent run. */
|
|
56
49
|
interface RunRequest {
|
|
57
50
|
input: ContentPart[] | string;
|
|
58
51
|
cwd?: string;
|
|
@@ -61,17 +54,13 @@ interface RunRequest {
|
|
|
61
54
|
timeoutMs?: number;
|
|
62
55
|
signal?: AbortSignal;
|
|
63
56
|
}
|
|
64
|
-
/** Input parameters for a raw-JSON-Schema structured-output run. */
|
|
65
57
|
interface JsonSchemaRunRequest extends RunRequest {
|
|
66
58
|
schema: JsonSchema;
|
|
67
59
|
}
|
|
68
|
-
/** Input parameters for a Zod-backed structured-output run. */
|
|
69
60
|
interface ZodRunRequest<TOutput = unknown> extends RunRequest {
|
|
70
61
|
schema: ZodType<TOutput>;
|
|
71
62
|
}
|
|
72
|
-
/** Input parameters for a structured-output run. */
|
|
73
63
|
type StructuredRunRequest<TOutput = unknown> = JsonSchemaRunRequest | ZodRunRequest<TOutput>;
|
|
74
|
-
/** Any supported run request shape. */
|
|
75
64
|
type AnyRunRequest = RunRequest | StructuredRunRequest;
|
|
76
65
|
interface RunTiming {
|
|
77
66
|
startedAt: Date;
|
|
@@ -112,11 +101,8 @@ type CompletedRunResult<TOutput = never> = RunResultBase & ([TOutput] extends [n
|
|
|
112
101
|
error?: undefined;
|
|
113
102
|
cancelReason?: undefined;
|
|
114
103
|
};
|
|
115
|
-
/** Discriminated union result of an agent run. narrow on `status` to access variant-specific fields. */
|
|
116
104
|
type RunResult<TOutput = never> = CancelledRunResult | CompletedRunResult<TOutput> | FailedRunResult;
|
|
117
|
-
/** Result of a run when the request shape is not known ahead of time. */
|
|
118
105
|
type AnyRunResult = RunResult | RunResult<unknown>;
|
|
119
|
-
/** Completed result of a run when the request shape is not known ahead of time. */
|
|
120
106
|
type AnyCompletedRunResult = CompletedRunResult | CompletedRunResult<unknown>;
|
|
121
107
|
type AgentRun<TRunOptions extends object = {}> = {
|
|
122
108
|
<TOutput>(request: TRunOptions & ZodRunRequest<TOutput>): Promise<RunResult<TOutput>>;
|
|
@@ -128,7 +114,6 @@ type AgentRunOrThrow<TRunOptions extends object = {}> = {
|
|
|
128
114
|
(request: JsonSchemaRunRequest & TRunOptions): Promise<CompletedRunResult<unknown>>;
|
|
129
115
|
(request: RunRequest & TRunOptions): Promise<CompletedRunResult>;
|
|
130
116
|
};
|
|
131
|
-
/** Thrown by `runOrThrow()` when the run does not complete successfully. carries the full `RunResult` on `.result`. */
|
|
132
117
|
declare class AgentRunError<TOutput = never> extends Error {
|
|
133
118
|
readonly result: RunResult<TOutput> & {
|
|
134
119
|
status: "cancelled" | "failed";
|
|
@@ -137,7 +122,6 @@ declare class AgentRunError<TOutput = never> extends Error {
|
|
|
137
122
|
status: "cancelled" | "failed";
|
|
138
123
|
});
|
|
139
124
|
}
|
|
140
|
-
/** Thrown when agent configuration or request parameters are invalid (e.g. unsupported capability, empty input) */
|
|
141
125
|
declare class AgentValidationError extends Error {
|
|
142
126
|
constructor(message: string);
|
|
143
127
|
}
|
|
@@ -150,14 +134,15 @@ interface AgentMetrics {
|
|
|
150
134
|
startedAt: Date;
|
|
151
135
|
lastActivityAt: Date;
|
|
152
136
|
}
|
|
153
|
-
/** Excludes keys typed as never (e.g. `systemPrompt?: never` blocker fields) */
|
|
154
137
|
type EffectiveKeys<T> = keyof { [K in keyof T as Required<T>[K] extends never ? never : K]: unknown };
|
|
155
|
-
/** Resolves to T if T has no effective keys overlapping with RunRequest, otherwise never */
|
|
156
138
|
type EnsureDisjoint<T extends object> = EffectiveKeys<T> & keyof RunRequest extends never ? T : never;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
139
|
+
type ExclusiveExecutionTargetOptions<TContainer, TSandbox> = {
|
|
140
|
+
container?: never;
|
|
141
|
+
sandbox?: TSandbox;
|
|
142
|
+
} | {
|
|
143
|
+
container?: TContainer;
|
|
144
|
+
sandbox?: never;
|
|
145
|
+
};
|
|
161
146
|
interface BaseAgent<TRunOptions extends object = {}> {
|
|
162
147
|
readonly type: AgentType;
|
|
163
148
|
readonly capabilities: Readonly<AgentCapabilities>;
|
|
@@ -174,4 +159,4 @@ interface BaseAgent<TRunOptions extends object = {}> {
|
|
|
174
159
|
onEvent: (handler: AgentEventHandler) => () => void;
|
|
175
160
|
}
|
|
176
161
|
//#endregion
|
|
177
|
-
export {
|
|
162
|
+
export { RunTiming as C, ProcessSpawner as D, ZodRunRequest as E, RunStatus as S, StructuredRunRequest as T, RunProcessInfo as _, AgentValidationError as a, RunResultBase as b, AnyRunResult as c, CompletedRunResult as d, EnsureDisjoint as f, RunError as g, JsonSchemaRunRequest as h, AgentType as i, BaseAgent as l, FailedRunResult as m, AgentMetrics as n, AnyCompletedRunResult as o, ExclusiveExecutionTargetOptions as p, AgentRunError as r, AnyRunRequest as s, AgentEventHandler as t, CancelledRunResult as u, RunRequest as v, StopReason as w, RunStats as x, RunResult as y };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=class extends Error{result;constructor(e){super(e.error.message),this.name=`AgentRunError`,this.result=e}},t=class extends Error{constructor(e){super(e),this.name=`AgentValidationError`}};export{t as n,e as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=e=>Array.isArray(e)?e:[e],t=e=>e instanceof Error?e.message:String(e),n=e=>typeof e==`object`&&!!e,r=(...e)=>e.reduce((e,t)=>e+(t??0),0),i=e=>{let t=e.trim();return t.startsWith("```")?t.replace(/^```[\w-]*\s*/i,``).replace(/\s*```$/i,``).trim():t},a=e=>/```[\w-]*\s*([\S\s]*?)\s*```/i.exec(e)?.[1]?.trim(),o=e=>{let t=-1,n=[],r=!1,i=!1;for(let a=0;a<e.length;a++){let o=e[a];if(o){if(t===-1){(o===`{`||o===`[`)&&(t=a,n.push(o));continue}if(r){if(i){i=!1;continue}if(o===`\\`){i=!0;continue}o===`"`&&(r=!1);continue}if(o===`"`){r=!0;continue}if(o===`{`||o===`[`){n.push(o);continue}if(o===`}`||o===`]`){let r=n.pop();if(r===`{`&&o!==`}`||r===`[`&&o!==`]`)return;if(n.length===0)return e.slice(t,a+1).trim()}}}},s=e=>{let t=e.trim(),n=[i(t),a(t),o(t)],r;for(let e of new Set(n))if(e)try{return JSON.parse(e)}catch(e){r=e}throw r instanceof Error?r:SyntaxError(`Failed to parse JSON response text.`)};export{e as a,r as i,n,s as r,t};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coding-agents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/index.d.mts",
|
|
6
6
|
"exports": {
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"types": "./dist/container/index.d.mts",
|
|
17
17
|
"default": "./dist/container/index.mjs"
|
|
18
18
|
},
|
|
19
|
+
"./sandbox": {
|
|
20
|
+
"types": "./dist/sandbox/index.d.mts",
|
|
21
|
+
"default": "./dist/sandbox/index.mjs"
|
|
22
|
+
},
|
|
19
23
|
"./adapters/claude-code-cli": {
|
|
20
24
|
"types": "./dist/adapters/claude-code-cli/index.d.mts",
|
|
21
25
|
"default": "./dist/adapters/claude-code-cli/index.mjs"
|