@evolvingmachines/daytona 0.0.21 → 0.0.22
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 +2 -2
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +2 -2
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var sdk=require('@daytonaio/sdk');var
|
|
2
|
-
exports.DaytonaProvider=
|
|
1
|
+
'use strict';var sdk=require('@daytonaio/sdk');var x={"evolve-all":"evolvingmachines/evolve-all:latest"},S=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 w(a){let e=a.substring(a.lastIndexOf(".")).toLowerCase();return S.has(e)}function h(a){let e=a.lastIndexOf("/");return e>0?a.substring(0,e):"/"}function v(a){let e=a.lastIndexOf("/");return e>=0?a.substring(e+1):a}function f(a,e,t){let s=a;return e&&(s=`cd '${e.replace(/'/g,"'\\''")}' && ${s}`),t&&Object.keys(t).length>0&&(s=`${Object.entries(t).filter(([,r])=>r!=null).map(([r,o])=>`export ${r}='${o.replace(/'/g,"'\\''")}'`).join("; ")}; ${s}`),s}var I=f,g=class{constructor(e){this.sandbox=e;}async run(e,t){let s=t?.timeoutMs?Math.floor(t.timeoutMs/1e3):void 0,n=`run-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await this.sandbox.process.createSession(n);try{let r=await this.sandbox.process.executeSessionCommand(n,{command:f(e,t?.cwd,t?.envs),runAsync:!1},s),o=r.cmdId;o&&(t?.onStdout||t?.onStderr)&&await this.sandbox.process.getSessionCommandLogs(n,o,t.onStdout||(()=>{}),t.onStderr||(()=>{}));let m=r.stdout??r.output??"",d=r.stderr??"";if(!m&&o&&!t?.onStdout)try{let c=await this.sandbox.process.getSessionCommandLogs(n,o);m=c.stdout??c.output??"",d=c.stderr??d;}catch{}return {exitCode:r.exitCode??0,stdout:m,stderr:d}}finally{try{await this.sandbox.process.deleteSession(n);}catch{}}}async spawn(e,t){let s=`evolve-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await this.sandbox.process.createSession(s);let n=t?.timeoutMs?Math.floor(t.timeoutMs/1e3):void 0,r=Date.now(),o=t?.timeoutMs,d=(await this.sandbox.process.executeSessionCommand(s,{command:f(e,t?.cwd,t?.envs),runAsync:true},n)).cmdId;d&&(t?.onStdout||t?.onStderr)&&this.sandbox.process.getSessionCommandLogs(s,d,t.onStdout||(()=>{}),t.onStderr||(()=>{})).catch(()=>{});let c=this.sandbox;return {processId:s,wait:async()=>{if(!d)return {exitCode:0,stdout:"",stderr:""};for(;;){if(o&&Date.now()-r>=o){try{await c.process.deleteSession(s);}catch{}return {exitCode:-1,stdout:"",stderr:"operation timed out"}}try{let i=await c.process.getSessionCommand(s,d);if(i.exitCode!==void 0)try{let u=await c.process.getSessionCommandLogs(s,d);return {exitCode:i.exitCode,stdout:u.stdout??u.output??"",stderr:u.stderr??""}}catch{return {exitCode:i.exitCode,stdout:"",stderr:""}}}catch(i){if((i instanceof Error?i.message.toLowerCase():String(i).toLowerCase()).includes("not found"))return {exitCode:-1,stdout:"",stderr:"session terminated"};throw i}await new Promise(i=>setTimeout(i,500));}},kill:async()=>{try{return await c.process.deleteSession(s),!0}catch{return false}}}}async list(){try{return (await this.sandbox.process.listSessions()).map(t=>({processId:t.sessionId||"",cmd:"",args:[],envs:{}}))}catch{return []}}async kill(e){try{return await this.sandbox.process.deleteSession(e),!0}catch{return false}}},p=class{constructor(e){this.sandbox=e;}async read(e){let t=await this.sandbox.fs.downloadFile(e);return w(e)?new Uint8Array(t):t.toString("utf-8")}async write(e,t){let s;if(typeof t=="string")s=Buffer.from(t,"utf-8");else if(Buffer.isBuffer(t))s=t;else if(t instanceof ArrayBuffer)s=Buffer.from(t);else if(t instanceof Uint8Array)s=Buffer.from(t);else throw new Error(`Unsupported content type: ${typeof t}`);await this.sandbox.fs.uploadFile(s,e);}async writeBatch(e){let t=e.map(s=>{let n;if(typeof s.data=="string")n=Buffer.from(s.data,"utf-8");else if(Buffer.isBuffer(s.data))n=s.data;else if(s.data instanceof ArrayBuffer)n=Buffer.from(s.data);else if(s.data instanceof Uint8Array)n=Buffer.from(s.data);else throw new Error(`Unsupported content type: ${typeof s.data}`);return {source:n,destination:s.path}});await this.sandbox.fs.uploadFiles(t);}async makeDir(e){await this.sandbox.fs.createFolder(e,"755");}async exists(e){try{let t=h(e),s=v(e);return (await this.sandbox.fs.listFiles(t)).some(r=>r.name===s)}catch{return false}}async list(e){return (await this.sandbox.fs.listFiles(e)).map(s=>({name:s.name,path:e.endsWith("/")?`${e}${s.name}`:`${e}/${s.name}`,type:s.isDir?"dir":"file"}))}async remove(e){await this.sandbox.fs.deleteFile(e,true);}async rename(e,t){await this.sandbox.fs.moveFiles(e,t);}},l=class{constructor(e){this.sandbox=e;this.commands=new g(e),this.files=new p(e);}commands;files;get sandboxId(){return this.sandbox.id}async getHost(e){return (await this.sandbox.getPreviewLink(e)).url}async isRunning(){return this.sandbox.state==="started"}async getInfo(){return {sandboxId:this.sandbox.id,image:this.sandbox.snapshot||"unknown",name:this.sandbox.name,metadata:this.sandbox.labels||{},startedAt:new Date().toISOString()}}async kill(){await this.sandbox.delete();}async pause(){await this.sandbox.stop();}},b=class{providerType="daytona";name="Daytona";client;defaultTimeoutMs;constructor(e){this.client=new sdk.Daytona({apiKey:e.apiKey,apiUrl:e.apiUrl,target:e.target}),this.defaultTimeoutMs=e.defaultTimeoutMs??36e5;}async create(e){let t=e.timeoutMs??this.defaultTimeoutMs,s=Math.max(1,Math.ceil(t/6e4)),n=e.image||"evolve-all",r;try{let o=await this.client.snapshot.get(n);if(o&&o.state==="active")console.log(`[daytona] Using cached snapshot: ${n}`),r=await this.client.create({snapshot:n,envVars:e.envs,labels:e.metadata,autoStopInterval:s},{timeout:600});else throw new Error("Snapshot not active")}catch{let o=x[n];if(!o)throw new Error(`Unknown image "${n}" and no public fallback available. Available images: ${Object.keys(x).join(", ")}`);console.log(`[daytona] Snapshot "${n}" not found, creating from image: ${o}`),console.log("[daytona] First run may take a few minutes (image will be cached for future runs)..."),r=await this.client.create({image:o,envVars:e.envs,labels:e.metadata,autoStopInterval:s,resources:{cpu:e.resources?.cpu??4,memory:e.resources?.memory??4,disk:e.resources?.disk??10}},{timeout:600,onSnapshotCreateLogs:m=>console.log(`[daytona] ${m}`)});}return e.workingDirectory&&await r.fs.createFolder(e.workingDirectory,"755"),new l(r)}async connect(e,t){let s=await this.client.get(e);return s.state!=="started"&&await s.start(),new l(s)}async list(e){let t=e?.limit??100;return (await this.client.list(e?.metadata,1,t)).items.map(n=>({sandboxId:n.id,image:n.snapshot||"unknown",name:n.name,metadata:n.labels||{},startedAt:new Date().toISOString()}))}};function C(a={}){let e=a.apiKey??process.env.DAYTONA_API_KEY;if(!e)throw new Error("Daytona API key required. Set DAYTONA_API_KEY environment variable or pass apiKey in config. Get your key at https://app.daytona.io/dashboard/keys");return new b({...a,apiKey:e})}
|
|
2
|
+
exports.DaytonaProvider=b;exports._testWrapCommand=I;exports.createDaytonaProvider=C;
|
package/dist/index.d.cts
CHANGED
|
@@ -8,6 +8,16 @@
|
|
|
8
8
|
* - Uses public Docker images via IMAGE_MAP
|
|
9
9
|
* - Parallel structure to E2B provider
|
|
10
10
|
*/
|
|
11
|
+
/**
|
|
12
|
+
* Wrap command with cwd and envs shell prefixes.
|
|
13
|
+
*
|
|
14
|
+
* Daytona's executeSessionCommand doesn't support cwd or envs natively,
|
|
15
|
+
* so we inline them as shell commands. Values are single-quoted to handle
|
|
16
|
+
* spaces and special characters safely.
|
|
17
|
+
*/
|
|
18
|
+
declare function wrapCommand(command: string, cwd?: string, envs?: Record<string, string>): string;
|
|
19
|
+
/** @internal Test-only export for unit testing wrapCommand logic. */
|
|
20
|
+
declare const _testWrapCommand: typeof wrapCommand;
|
|
11
21
|
/** Result of a completed sandbox command */
|
|
12
22
|
interface SandboxCommandResult {
|
|
13
23
|
exitCode: number;
|
|
@@ -155,4 +165,4 @@ declare class DaytonaProvider implements SandboxProvider {
|
|
|
155
165
|
*/
|
|
156
166
|
declare function createDaytonaProvider(config?: DaytonaConfig): SandboxProvider;
|
|
157
167
|
|
|
158
|
-
export { type DaytonaConfig, DaytonaProvider, type FileInfo, type ProcessInfo, type SandboxCommandHandle, type SandboxCommandResult, type SandboxCommands, type SandboxCreateOptions, type SandboxFiles, type SandboxInfo, type SandboxInstance, type SandboxListOptions, type SandboxProvider, type SandboxResources, type SandboxRunOptions, type SandboxSpawnOptions, createDaytonaProvider };
|
|
168
|
+
export { type DaytonaConfig, DaytonaProvider, type FileInfo, type ProcessInfo, type SandboxCommandHandle, type SandboxCommandResult, type SandboxCommands, type SandboxCreateOptions, type SandboxFiles, type SandboxInfo, type SandboxInstance, type SandboxListOptions, type SandboxProvider, type SandboxResources, type SandboxRunOptions, type SandboxSpawnOptions, _testWrapCommand, createDaytonaProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,16 @@
|
|
|
8
8
|
* - Uses public Docker images via IMAGE_MAP
|
|
9
9
|
* - Parallel structure to E2B provider
|
|
10
10
|
*/
|
|
11
|
+
/**
|
|
12
|
+
* Wrap command with cwd and envs shell prefixes.
|
|
13
|
+
*
|
|
14
|
+
* Daytona's executeSessionCommand doesn't support cwd or envs natively,
|
|
15
|
+
* so we inline them as shell commands. Values are single-quoted to handle
|
|
16
|
+
* spaces and special characters safely.
|
|
17
|
+
*/
|
|
18
|
+
declare function wrapCommand(command: string, cwd?: string, envs?: Record<string, string>): string;
|
|
19
|
+
/** @internal Test-only export for unit testing wrapCommand logic. */
|
|
20
|
+
declare const _testWrapCommand: typeof wrapCommand;
|
|
11
21
|
/** Result of a completed sandbox command */
|
|
12
22
|
interface SandboxCommandResult {
|
|
13
23
|
exitCode: number;
|
|
@@ -155,4 +165,4 @@ declare class DaytonaProvider implements SandboxProvider {
|
|
|
155
165
|
*/
|
|
156
166
|
declare function createDaytonaProvider(config?: DaytonaConfig): SandboxProvider;
|
|
157
167
|
|
|
158
|
-
export { type DaytonaConfig, DaytonaProvider, type FileInfo, type ProcessInfo, type SandboxCommandHandle, type SandboxCommandResult, type SandboxCommands, type SandboxCreateOptions, type SandboxFiles, type SandboxInfo, type SandboxInstance, type SandboxListOptions, type SandboxProvider, type SandboxResources, type SandboxRunOptions, type SandboxSpawnOptions, createDaytonaProvider };
|
|
168
|
+
export { type DaytonaConfig, DaytonaProvider, type FileInfo, type ProcessInfo, type SandboxCommandHandle, type SandboxCommandResult, type SandboxCommands, type SandboxCreateOptions, type SandboxFiles, type SandboxInfo, type SandboxInstance, type SandboxListOptions, type SandboxProvider, type SandboxResources, type SandboxRunOptions, type SandboxSpawnOptions, _testWrapCommand, createDaytonaProvider };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {Daytona}from'@daytonaio/sdk';var
|
|
2
|
-
export{
|
|
1
|
+
import {Daytona}from'@daytonaio/sdk';var x={"evolve-all":"evolvingmachines/evolve-all:latest"},S=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 w(a){let e=a.substring(a.lastIndexOf(".")).toLowerCase();return S.has(e)}function h(a){let e=a.lastIndexOf("/");return e>0?a.substring(0,e):"/"}function v(a){let e=a.lastIndexOf("/");return e>=0?a.substring(e+1):a}function f(a,e,t){let s=a;return e&&(s=`cd '${e.replace(/'/g,"'\\''")}' && ${s}`),t&&Object.keys(t).length>0&&(s=`${Object.entries(t).filter(([,r])=>r!=null).map(([r,o])=>`export ${r}='${o.replace(/'/g,"'\\''")}'`).join("; ")}; ${s}`),s}var I=f,g=class{constructor(e){this.sandbox=e;}async run(e,t){let s=t?.timeoutMs?Math.floor(t.timeoutMs/1e3):void 0,n=`run-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await this.sandbox.process.createSession(n);try{let r=await this.sandbox.process.executeSessionCommand(n,{command:f(e,t?.cwd,t?.envs),runAsync:!1},s),o=r.cmdId;o&&(t?.onStdout||t?.onStderr)&&await this.sandbox.process.getSessionCommandLogs(n,o,t.onStdout||(()=>{}),t.onStderr||(()=>{}));let m=r.stdout??r.output??"",d=r.stderr??"";if(!m&&o&&!t?.onStdout)try{let c=await this.sandbox.process.getSessionCommandLogs(n,o);m=c.stdout??c.output??"",d=c.stderr??d;}catch{}return {exitCode:r.exitCode??0,stdout:m,stderr:d}}finally{try{await this.sandbox.process.deleteSession(n);}catch{}}}async spawn(e,t){let s=`evolve-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await this.sandbox.process.createSession(s);let n=t?.timeoutMs?Math.floor(t.timeoutMs/1e3):void 0,r=Date.now(),o=t?.timeoutMs,d=(await this.sandbox.process.executeSessionCommand(s,{command:f(e,t?.cwd,t?.envs),runAsync:true},n)).cmdId;d&&(t?.onStdout||t?.onStderr)&&this.sandbox.process.getSessionCommandLogs(s,d,t.onStdout||(()=>{}),t.onStderr||(()=>{})).catch(()=>{});let c=this.sandbox;return {processId:s,wait:async()=>{if(!d)return {exitCode:0,stdout:"",stderr:""};for(;;){if(o&&Date.now()-r>=o){try{await c.process.deleteSession(s);}catch{}return {exitCode:-1,stdout:"",stderr:"operation timed out"}}try{let i=await c.process.getSessionCommand(s,d);if(i.exitCode!==void 0)try{let u=await c.process.getSessionCommandLogs(s,d);return {exitCode:i.exitCode,stdout:u.stdout??u.output??"",stderr:u.stderr??""}}catch{return {exitCode:i.exitCode,stdout:"",stderr:""}}}catch(i){if((i instanceof Error?i.message.toLowerCase():String(i).toLowerCase()).includes("not found"))return {exitCode:-1,stdout:"",stderr:"session terminated"};throw i}await new Promise(i=>setTimeout(i,500));}},kill:async()=>{try{return await c.process.deleteSession(s),!0}catch{return false}}}}async list(){try{return (await this.sandbox.process.listSessions()).map(t=>({processId:t.sessionId||"",cmd:"",args:[],envs:{}}))}catch{return []}}async kill(e){try{return await this.sandbox.process.deleteSession(e),!0}catch{return false}}},p=class{constructor(e){this.sandbox=e;}async read(e){let t=await this.sandbox.fs.downloadFile(e);return w(e)?new Uint8Array(t):t.toString("utf-8")}async write(e,t){let s;if(typeof t=="string")s=Buffer.from(t,"utf-8");else if(Buffer.isBuffer(t))s=t;else if(t instanceof ArrayBuffer)s=Buffer.from(t);else if(t instanceof Uint8Array)s=Buffer.from(t);else throw new Error(`Unsupported content type: ${typeof t}`);await this.sandbox.fs.uploadFile(s,e);}async writeBatch(e){let t=e.map(s=>{let n;if(typeof s.data=="string")n=Buffer.from(s.data,"utf-8");else if(Buffer.isBuffer(s.data))n=s.data;else if(s.data instanceof ArrayBuffer)n=Buffer.from(s.data);else if(s.data instanceof Uint8Array)n=Buffer.from(s.data);else throw new Error(`Unsupported content type: ${typeof s.data}`);return {source:n,destination:s.path}});await this.sandbox.fs.uploadFiles(t);}async makeDir(e){await this.sandbox.fs.createFolder(e,"755");}async exists(e){try{let t=h(e),s=v(e);return (await this.sandbox.fs.listFiles(t)).some(r=>r.name===s)}catch{return false}}async list(e){return (await this.sandbox.fs.listFiles(e)).map(s=>({name:s.name,path:e.endsWith("/")?`${e}${s.name}`:`${e}/${s.name}`,type:s.isDir?"dir":"file"}))}async remove(e){await this.sandbox.fs.deleteFile(e,true);}async rename(e,t){await this.sandbox.fs.moveFiles(e,t);}},l=class{constructor(e){this.sandbox=e;this.commands=new g(e),this.files=new p(e);}commands;files;get sandboxId(){return this.sandbox.id}async getHost(e){return (await this.sandbox.getPreviewLink(e)).url}async isRunning(){return this.sandbox.state==="started"}async getInfo(){return {sandboxId:this.sandbox.id,image:this.sandbox.snapshot||"unknown",name:this.sandbox.name,metadata:this.sandbox.labels||{},startedAt:new Date().toISOString()}}async kill(){await this.sandbox.delete();}async pause(){await this.sandbox.stop();}},b=class{providerType="daytona";name="Daytona";client;defaultTimeoutMs;constructor(e){this.client=new Daytona({apiKey:e.apiKey,apiUrl:e.apiUrl,target:e.target}),this.defaultTimeoutMs=e.defaultTimeoutMs??36e5;}async create(e){let t=e.timeoutMs??this.defaultTimeoutMs,s=Math.max(1,Math.ceil(t/6e4)),n=e.image||"evolve-all",r;try{let o=await this.client.snapshot.get(n);if(o&&o.state==="active")console.log(`[daytona] Using cached snapshot: ${n}`),r=await this.client.create({snapshot:n,envVars:e.envs,labels:e.metadata,autoStopInterval:s},{timeout:600});else throw new Error("Snapshot not active")}catch{let o=x[n];if(!o)throw new Error(`Unknown image "${n}" and no public fallback available. Available images: ${Object.keys(x).join(", ")}`);console.log(`[daytona] Snapshot "${n}" not found, creating from image: ${o}`),console.log("[daytona] First run may take a few minutes (image will be cached for future runs)..."),r=await this.client.create({image:o,envVars:e.envs,labels:e.metadata,autoStopInterval:s,resources:{cpu:e.resources?.cpu??4,memory:e.resources?.memory??4,disk:e.resources?.disk??10}},{timeout:600,onSnapshotCreateLogs:m=>console.log(`[daytona] ${m}`)});}return e.workingDirectory&&await r.fs.createFolder(e.workingDirectory,"755"),new l(r)}async connect(e,t){let s=await this.client.get(e);return s.state!=="started"&&await s.start(),new l(s)}async list(e){let t=e?.limit??100;return (await this.client.list(e?.metadata,1,t)).items.map(n=>({sandboxId:n.id,image:n.snapshot||"unknown",name:n.name,metadata:n.labels||{},startedAt:new Date().toISOString()}))}};function C(a={}){let e=a.apiKey??process.env.DAYTONA_API_KEY;if(!e)throw new Error("Daytona API key required. Set DAYTONA_API_KEY environment variable or pass apiKey in config. Get your key at https://app.daytona.io/dashboard/keys");return new b({...a,apiKey:e})}
|
|
2
|
+
export{b as DaytonaProvider,I as _testWrapCommand,C as createDaytonaProvider};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evolvingmachines/daytona",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"ai",
|
|
6
6
|
"agents",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsup --minify",
|
|
34
34
|
"dev": "tsup --watch",
|
|
35
|
-
"type-check": "tsc --noEmit"
|
|
35
|
+
"type-check": "tsc --noEmit",
|
|
36
|
+
"test:unit": "tsx tests/unit/daytona-commands.test.ts"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
39
|
"@daytonaio/sdk": ">=0.130.0"
|