@evolvingmachines/e2b 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var codeInterpreter=require('@e2b/code-interpreter');var
|
|
1
|
+
'use strict';var codeInterpreter=require('@e2b/code-interpreter');var g=new Set([".xlsx",".xls",".docx",".doc",".pptx",".ppt",".pdf",".zip",".tar",".gz",".7z",".rar",".png",".jpg",".jpeg",".gif",".webp",".ico",".bmp",".mp3",".wav",".ogg",".flac",".aac",".mp4",".avi",".mov",".mkv",".webm",".woff",".woff2",".ttf",".otf",".eot",".exe",".dll",".so",".dylib",".sqlite",".db",".pickle",".pkl",".parquet"]);function a(s){return s instanceof Date?s.toISOString():String(s)}function l(s){if(typeof s=="string"||s instanceof ArrayBuffer)return s;if(s instanceof Buffer)return new Uint8Array(s).buffer;if(s instanceof Uint8Array)return new Uint8Array(s).buffer;throw new Error(`Unsupported data type for file upload: ${typeof s}. Expected string, Buffer, ArrayBuffer, or Uint8Array.`)}function x(s){let t=s.substring(s.lastIndexOf(".")).toLowerCase();return g.has(t)}var m=class{constructor(t){this.sandbox=t;}async run(t,e){try{let n=await this.sandbox.commands.run(t,{timeoutMs:e?.timeoutMs,envs:e?.envs,cwd:e?.cwd,onStdout:e?.onStdout,onStderr:e?.onStderr});return {exitCode:n.exitCode,stdout:n.stdout,stderr:n.stderr}}catch(n){if(n&&typeof n=="object"&&"exitCode"in n){let r=n;return {exitCode:r.exitCode,stdout:r.stdout??"",stderr:r.stderr??""}}throw n}}async spawn(t,e){let n=await this.sandbox.commands.run(t,{background:true,stdin:e?.stdin??true,timeoutMs:e?.timeoutMs,envs:e?.envs,cwd:e?.cwd,onStdout:e?.onStdout,onStderr:e?.onStderr});return {processId:String(n.pid),wait:async()=>{try{let r=await n.wait();return {exitCode:r.exitCode,stdout:r.stdout,stderr:r.stderr}}catch(r){if(r&&typeof r=="object"&&"exitCode"in r){let i=r;return {exitCode:i.exitCode,stdout:i.stdout??"",stderr:i.stderr??""}}throw r}},kill:()=>this.sandbox.commands.kill(n.pid)}}async list(){return (await this.sandbox.commands.list()).map(e=>({...e,processId:String(e.pid)}))}async connect(t,e){let n=await this.sandbox.commands.connect(Number(t),{onStdout:e?.onStdout,onStderr:e?.onStderr,timeoutMs:e?.timeoutMs});return {processId:String(n.pid),wait:async()=>{try{let r=await n.wait();return {exitCode:r.exitCode,stdout:r.stdout,stderr:r.stderr}}catch(r){if(r&&typeof r=="object"&&"exitCode"in r){let i=r;return {exitCode:i.exitCode,stdout:i.stdout??"",stderr:i.stderr??""}}throw r}},kill:()=>this.sandbox.commands.kill(n.pid)}}async sendStdin(t,e){await this.sandbox.commands.sendStdin(Number(t),e);}async kill(t){return this.sandbox.commands.kill(Number(t))}},c=class{constructor(t){this.sandbox=t;}async read(t){return x(t)?this.sandbox.files.read(t,{format:"bytes",requestTimeoutMs:3e5}):this.sandbox.files.read(t,{format:"text",requestTimeoutMs:3e5})}async write(t,e){await this.sandbox.files.write(t,l(e),{requestTimeoutMs:3e5});}async writeBatch(t){let e=t.map(n=>({path:n.path,data:l(n.data)}));await this.sandbox.files.write(e,{requestTimeoutMs:3e5});}async makeDir(t){await this.sandbox.files.makeDir(t);}async uploadUrl(t,e){return this.sandbox.uploadUrl(t,e?{useSignatureExpiration:e}:void 0)}async downloadUrl(t,e){return this.sandbox.downloadUrl(t,e?{useSignatureExpiration:e}:void 0)}async exists(t){return this.sandbox.files.exists(t)}async list(t){return (await this.sandbox.files.list(t)).map(n=>({name:n.name,path:n.path,type:n.type==="dir"?"dir":"file"}))}async remove(t){await this.sandbox.files.remove(t);}async rename(t,e){await this.sandbox.files.rename(t,e);}async readStream(t){return this.sandbox.files.read(t,{format:"stream"})}async writeStream(t,e){await this.sandbox.files.write(t,e);}async watchDir(t,e,n){let r=await this.sandbox.files.watchDir(t,e,{recursive:n?.recursive,timeoutMs:n?.timeoutMs,onExit:n?.onExit});return {stop:()=>r.stop()}}},o=class{constructor(t){this.sandbox=t;this.commands=new m(t),this.files=new c(t);}commands;files;get sandboxId(){return this.sandbox.sandboxId}getHost(t){return Promise.resolve(this.sandbox.getHost(t))}async isRunning(){return this.sandbox.isRunning()}async getInfo(){let t=await this.sandbox.getInfo();return {sandboxId:t.sandboxId,image:t.templateId,name:t.name,metadata:t.metadata??{},startedAt:a(t.startedAt),endAt:t.endAt?a(t.endAt):void 0}}async kill(){try{await this.sandbox.kill();}catch{await new Promise(t=>setTimeout(t,500)),await this.sandbox.kill();}}async pause(){await this.sandbox.betaPause();}},u=class{providerType="e2b";apiKey;defaultTimeoutMs;templateId;constructor(t){this.apiKey=t.apiKey,this.defaultTimeoutMs=t.defaultTimeoutMs??36e5,this.templateId=t.templateId;}async create(t){let e=t.timeoutMs??this.defaultTimeoutMs,n=t.image??this.templateId??"evolve-all",r=await codeInterpreter.Sandbox.create(n,{apiKey:this.apiKey,envs:t.envs,metadata:t.metadata,timeoutMs:e});return t.workingDirectory&&await r.files.makeDir(t.workingDirectory),new o(r)}async connect(t,e){let n=await codeInterpreter.Sandbox.connect(t,{apiKey:this.apiKey,timeoutMs:e??this.defaultTimeoutMs});return new o(n)}async list(t){return (await codeInterpreter.Sandbox.list({apiKey:this.apiKey,query:{state:t?.state,metadata:t?.metadata},limit:t?.limit??100}).nextItems()).map(r=>({sandboxId:r.sandboxId,image:r.templateId,name:r.name,metadata:r.metadata??{},startedAt:a(r.startedAt),endAt:r.endAt?a(r.endAt):void 0}))}};function f(s={}){let t=s.apiKey??process.env.E2B_API_KEY;if(!t)throw new Error("E2B API key required. Set E2B_API_KEY environment variable or pass apiKey in config. Get your key at https://e2b.dev/sign-in");return new u({...s,apiKey:t})}
|
|
2
2
|
exports.E2BProvider=u;exports.createE2BProvider=f;
|
package/dist/index.d.cts
CHANGED
|
@@ -175,16 +175,20 @@ interface E2BConfig {
|
|
|
175
175
|
/** E2B API key. Default: reads from E2B_API_KEY env var */
|
|
176
176
|
apiKey?: string;
|
|
177
177
|
defaultTimeoutMs?: number;
|
|
178
|
+
/** E2B template ID (default: 'evolve-all'). Create custom templates at https://e2b.dev/docs/sandbox-template */
|
|
179
|
+
templateId?: string;
|
|
178
180
|
}
|
|
179
181
|
/** Internal resolved config with required apiKey */
|
|
180
182
|
interface ResolvedE2BConfig {
|
|
181
183
|
apiKey: string;
|
|
182
184
|
defaultTimeoutMs?: number;
|
|
185
|
+
templateId?: string;
|
|
183
186
|
}
|
|
184
187
|
declare class E2BProvider implements SandboxProvider {
|
|
185
188
|
readonly providerType: "e2b";
|
|
186
189
|
private readonly apiKey;
|
|
187
190
|
private readonly defaultTimeoutMs;
|
|
191
|
+
private readonly templateId?;
|
|
188
192
|
constructor(config: ResolvedE2BConfig);
|
|
189
193
|
create(options: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
190
194
|
connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
|
package/dist/index.d.ts
CHANGED
|
@@ -175,16 +175,20 @@ interface E2BConfig {
|
|
|
175
175
|
/** E2B API key. Default: reads from E2B_API_KEY env var */
|
|
176
176
|
apiKey?: string;
|
|
177
177
|
defaultTimeoutMs?: number;
|
|
178
|
+
/** E2B template ID (default: 'evolve-all'). Create custom templates at https://e2b.dev/docs/sandbox-template */
|
|
179
|
+
templateId?: string;
|
|
178
180
|
}
|
|
179
181
|
/** Internal resolved config with required apiKey */
|
|
180
182
|
interface ResolvedE2BConfig {
|
|
181
183
|
apiKey: string;
|
|
182
184
|
defaultTimeoutMs?: number;
|
|
185
|
+
templateId?: string;
|
|
183
186
|
}
|
|
184
187
|
declare class E2BProvider implements SandboxProvider {
|
|
185
188
|
readonly providerType: "e2b";
|
|
186
189
|
private readonly apiKey;
|
|
187
190
|
private readonly defaultTimeoutMs;
|
|
191
|
+
private readonly templateId?;
|
|
188
192
|
constructor(config: ResolvedE2BConfig);
|
|
189
193
|
create(options: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
190
194
|
connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {Sandbox}from'@e2b/code-interpreter';var
|
|
1
|
+
import {Sandbox}from'@e2b/code-interpreter';var g=new Set([".xlsx",".xls",".docx",".doc",".pptx",".ppt",".pdf",".zip",".tar",".gz",".7z",".rar",".png",".jpg",".jpeg",".gif",".webp",".ico",".bmp",".mp3",".wav",".ogg",".flac",".aac",".mp4",".avi",".mov",".mkv",".webm",".woff",".woff2",".ttf",".otf",".eot",".exe",".dll",".so",".dylib",".sqlite",".db",".pickle",".pkl",".parquet"]);function a(s){return s instanceof Date?s.toISOString():String(s)}function l(s){if(typeof s=="string"||s instanceof ArrayBuffer)return s;if(s instanceof Buffer)return new Uint8Array(s).buffer;if(s instanceof Uint8Array)return new Uint8Array(s).buffer;throw new Error(`Unsupported data type for file upload: ${typeof s}. Expected string, Buffer, ArrayBuffer, or Uint8Array.`)}function x(s){let t=s.substring(s.lastIndexOf(".")).toLowerCase();return g.has(t)}var m=class{constructor(t){this.sandbox=t;}async run(t,e){try{let n=await this.sandbox.commands.run(t,{timeoutMs:e?.timeoutMs,envs:e?.envs,cwd:e?.cwd,onStdout:e?.onStdout,onStderr:e?.onStderr});return {exitCode:n.exitCode,stdout:n.stdout,stderr:n.stderr}}catch(n){if(n&&typeof n=="object"&&"exitCode"in n){let r=n;return {exitCode:r.exitCode,stdout:r.stdout??"",stderr:r.stderr??""}}throw n}}async spawn(t,e){let n=await this.sandbox.commands.run(t,{background:true,stdin:e?.stdin??true,timeoutMs:e?.timeoutMs,envs:e?.envs,cwd:e?.cwd,onStdout:e?.onStdout,onStderr:e?.onStderr});return {processId:String(n.pid),wait:async()=>{try{let r=await n.wait();return {exitCode:r.exitCode,stdout:r.stdout,stderr:r.stderr}}catch(r){if(r&&typeof r=="object"&&"exitCode"in r){let i=r;return {exitCode:i.exitCode,stdout:i.stdout??"",stderr:i.stderr??""}}throw r}},kill:()=>this.sandbox.commands.kill(n.pid)}}async list(){return (await this.sandbox.commands.list()).map(e=>({...e,processId:String(e.pid)}))}async connect(t,e){let n=await this.sandbox.commands.connect(Number(t),{onStdout:e?.onStdout,onStderr:e?.onStderr,timeoutMs:e?.timeoutMs});return {processId:String(n.pid),wait:async()=>{try{let r=await n.wait();return {exitCode:r.exitCode,stdout:r.stdout,stderr:r.stderr}}catch(r){if(r&&typeof r=="object"&&"exitCode"in r){let i=r;return {exitCode:i.exitCode,stdout:i.stdout??"",stderr:i.stderr??""}}throw r}},kill:()=>this.sandbox.commands.kill(n.pid)}}async sendStdin(t,e){await this.sandbox.commands.sendStdin(Number(t),e);}async kill(t){return this.sandbox.commands.kill(Number(t))}},c=class{constructor(t){this.sandbox=t;}async read(t){return x(t)?this.sandbox.files.read(t,{format:"bytes",requestTimeoutMs:3e5}):this.sandbox.files.read(t,{format:"text",requestTimeoutMs:3e5})}async write(t,e){await this.sandbox.files.write(t,l(e),{requestTimeoutMs:3e5});}async writeBatch(t){let e=t.map(n=>({path:n.path,data:l(n.data)}));await this.sandbox.files.write(e,{requestTimeoutMs:3e5});}async makeDir(t){await this.sandbox.files.makeDir(t);}async uploadUrl(t,e){return this.sandbox.uploadUrl(t,e?{useSignatureExpiration:e}:void 0)}async downloadUrl(t,e){return this.sandbox.downloadUrl(t,e?{useSignatureExpiration:e}:void 0)}async exists(t){return this.sandbox.files.exists(t)}async list(t){return (await this.sandbox.files.list(t)).map(n=>({name:n.name,path:n.path,type:n.type==="dir"?"dir":"file"}))}async remove(t){await this.sandbox.files.remove(t);}async rename(t,e){await this.sandbox.files.rename(t,e);}async readStream(t){return this.sandbox.files.read(t,{format:"stream"})}async writeStream(t,e){await this.sandbox.files.write(t,e);}async watchDir(t,e,n){let r=await this.sandbox.files.watchDir(t,e,{recursive:n?.recursive,timeoutMs:n?.timeoutMs,onExit:n?.onExit});return {stop:()=>r.stop()}}},o=class{constructor(t){this.sandbox=t;this.commands=new m(t),this.files=new c(t);}commands;files;get sandboxId(){return this.sandbox.sandboxId}getHost(t){return Promise.resolve(this.sandbox.getHost(t))}async isRunning(){return this.sandbox.isRunning()}async getInfo(){let t=await this.sandbox.getInfo();return {sandboxId:t.sandboxId,image:t.templateId,name:t.name,metadata:t.metadata??{},startedAt:a(t.startedAt),endAt:t.endAt?a(t.endAt):void 0}}async kill(){try{await this.sandbox.kill();}catch{await new Promise(t=>setTimeout(t,500)),await this.sandbox.kill();}}async pause(){await this.sandbox.betaPause();}},u=class{providerType="e2b";apiKey;defaultTimeoutMs;templateId;constructor(t){this.apiKey=t.apiKey,this.defaultTimeoutMs=t.defaultTimeoutMs??36e5,this.templateId=t.templateId;}async create(t){let e=t.timeoutMs??this.defaultTimeoutMs,n=t.image??this.templateId??"evolve-all",r=await Sandbox.create(n,{apiKey:this.apiKey,envs:t.envs,metadata:t.metadata,timeoutMs:e});return t.workingDirectory&&await r.files.makeDir(t.workingDirectory),new o(r)}async connect(t,e){let n=await Sandbox.connect(t,{apiKey:this.apiKey,timeoutMs:e??this.defaultTimeoutMs});return new o(n)}async list(t){return (await Sandbox.list({apiKey:this.apiKey,query:{state:t?.state,metadata:t?.metadata},limit:t?.limit??100}).nextItems()).map(r=>({sandboxId:r.sandboxId,image:r.templateId,name:r.name,metadata:r.metadata??{},startedAt:a(r.startedAt),endAt:r.endAt?a(r.endAt):void 0}))}};function f(s={}){let t=s.apiKey??process.env.E2B_API_KEY;if(!t)throw new Error("E2B API key required. Set E2B_API_KEY environment variable or pass apiKey in config. Get your key at https://e2b.dev/sign-in");return new u({...s,apiKey:t})}
|
|
2
2
|
export{u as E2BProvider,f as createE2BProvider};
|