@evolvingmachines/daytona 0.0.67 → 0.0.69
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 +7 -6
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +7 -6
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
'use strict';var sdk=require('@daytonaio/sdk'),crypto=require('crypto');require('fs');var
|
|
2
|
-
`)){let p=
|
|
1
|
+
'use strict';var sdk=require('@daytonaio/sdk'),crypto=require('crypto');require('fs');var k=class extends Error{feature;provider;reason;constructor(t,e,s){super(`${e} does not support ${t}${s?`: ${s}`:""}`),this.name="SandboxFeatureUnsupportedError",this.feature=t,this.provider=e,this.reason=s;}},A=class extends Error{path;provider;constructor(t,e){super(`${e}: no such file or directory: ${t}`),this.name="SandboxPathNotFoundError",this.path=t,this.provider=e;}},_=class extends Error{sandboxId;provider;state;constructor(t,e,s){super(`${e} sandbox ${t} is not running (${s}); inspect never starts or resumes a sandbox`),this.name="SandboxNotRunningError",this.sandboxId=t,this.provider=e,this.state=s;}};function L(n,t){return !!n&&typeof n=="object"&&n.name===t}function Xt(n){return L(n,"SandboxFeatureUnsupportedError")}function Vt(n){return L(n,"SandboxPathNotFoundError")}function Qt(n){return L(n,"SandboxNotRunningError")}var M=2,R=20;function N(n){return `'${n.replace(/'/g,"'\\''")}'`}function U(n){if(!Number.isInteger(n.offset)||n.offset<0)throw new RangeError(`offset must be a non-negative integer, got ${n.offset}`);if(!Number.isInteger(n.length)||n.length<0)throw new RangeError(`length must be a non-negative integer, got ${n.length}`)}function gt(n){if(typeof n=="number")return ut((n&4095).toString(8));if(/^[0-7]{1,4}$/.test(n))return ut(n);throw new RangeError(`not an octal mode: ${n}`)}function ut(n){return n.padStart(4,"0")}function F(n){let t=n instanceof Date?n:typeof n=="number"?new Date(n*1e3):new Date(n);if(Number.isNaN(t.getTime()))throw new RangeError(`not a timestamp: ${String(n)}`);return t.toISOString()}function ft(n,t){return n.endsWith("/")?`${n}${t}`:`${n}/${t}`}async function mt(n,t,e){if(U(t),t.length===0)return new Uint8Array(0);let s=t.offset+t.length-1,r=await fetch(n,{headers:{Range:`bytes=${t.offset}-${s}`},signal:AbortSignal.timeout(e.timeoutMs)});if(r.status===206){let o=new Uint8Array(await r.arrayBuffer());return o.length>t.length?o.subarray(0,t.length):o}if(r.status===200)return Jt(r,t);if(r.status===416)return await r.body?.cancel().catch(()=>{}),new Uint8Array(0);throw await r.body?.cancel().catch(()=>{}),r.status===404?new A(e.path,e.provider):new Error(`${e.provider}: range read of ${e.path} failed (HTTP ${r.status})`)}async function Jt(n,t){if(!n.body)return new Uint8Array(0);let e=n.body.getReader(),s=[],r=0,o=0,a=t.offset+t.length;try{for(;;){let{done:l,value:g}=await e.read();if(l)break;let c=r;if(r+=g.length,r>t.offset){let f=Math.max(0,t.offset-c),u=Math.min(g.length,a-c);u>f&&(s.push(g.subarray(f,u)),o+=u-f);}if(r>=a)break}}finally{await e.cancel().catch(()=>{});}let i=new Uint8Array(o),d=0;for(let l of s)i.set(l,d),d+=l.length;return i}var C="c-73196ff07944";var rt={[`evolve-all-${C}`]:`evolvingmachines/evolve-all:${C}`,"evolve-all":"evolvingmachines/evolve-all"},ne=10,wt=10,yt=20,se=18e4,re=2e3,kt=6e5,It=5e3,oe={pollMinMs:250,pollMaxMs:2e3,drainMs:1e3,killGraceMs:15e3,settleMs:6e4},S=n=>new Promise(t=>setTimeout(t,Math.max(0,n))),ae=100,B=1e4;function ie(n){let t=n.lastIndexOf("/");return t>0?n.substring(0,t):"/"}function de(n){let t=n.lastIndexOf("/");return t>=0?n.substring(t+1):n}var b=class extends Error{reason;destination;constructor(t,e,s){super(e),this.name="DaytonaNetworkPolicyError",this.reason=t,this.destination=s;}},W=class extends Error{image;constructor(t,e){let s=e instanceof Error?e.message:String(e??"unknown error");super(`Failed to pull image "${t}" on Daytona: ${s}. Private registry images require the registry pre-registered in the Daytona dashboard (Registries page) before sandbox creation \u2014 Daytona has no per-call image pull secret; AWS ECR registrations name an IAM role Daytona assumes (no password). Register the registry at https://app.daytona.io, then retry. Also ensure the image is linux/amd64 and pinned to a tag or digest (floating tags like "latest" are rejected by Daytona's snapshot builder).`),this.name="DaytonaImagePullError",this.image=t;}},bt=class extends Error{snapshot;constructor(t){super(`Daytona cannot constrain the GPU type for "${t}": the snapshot already exists and pins its resources \u2014 pre-build a snapshot with the desired GPU type under its own name.`),this.name="DaytonaGpuTypeError",this.snapshot=t;}},I=class extends Error{snapshot;constructor(t){super(`Daytona snapshot "${t}" already exists and pins its cpu/memory/disk sizing \u2014 create-from-snapshot cannot resize it, so the requested \`resources\` cannot be enforced. Pre-build a snapshot with the desired sizing under its own name (sizing-addressed), or omit \`resources\` to accept the snapshot's pinned sizing.`),this.name="DaytonaResourcesError",this.snapshot=t;}},j=class extends Error{constructor(){super("Daytona takes no create-time boot command: it never runs an image entrypoint or any argv at boot (harbor daytona/environment.py:706-708 works around exactly that, starting dockerd by hand). The boot is already inert \u2014 run the process by exec after create."),this.name="DaytonaBootCommandError";}},H=class extends Error{constructor(){super("Daytona has no separate idle timeout: auto-stop IS its only clock and it already measures inactivity, so `timeoutMs` is what sets it (autoStopInterval). Set the inactivity bound with `timeoutMs`; a hard bound on the process itself is enforced in-box instead (see withInBoxTimeout)."),this.name="DaytonaIdleTimeoutError";}},le=new Set(["pending_build","building_snapshot","pulling_snapshot"]);function xt(n){return n!=null&&le.has(n)?"image_pull":"boot"}var q=class extends Error{phase;state;sandboxId;constructor(t,e,s){super(`Daytona sandbox boot abandoned during ${t} (provider state ${e??"not yet reported"}, sandbox ${s??"not yet created"})`),this.name="DaytonaBootAbortedError",this.phase=t,this.state=e,this.sandboxId=s;}},St="evolve_boot",ce=5e3,vt=30;async function Re(n,t,e={}){let s=crypto.randomUUID(),r=e.pollMs??ce,o=null,a=null,i=false,d=(u,m)=>{let p=u==="build_log"?"image_pull":xt(a);e.onProgress?.({signal:u,phase:p,state:a,sandboxId:o?.id??null,...m===void 0?{}:{line:m}});},l=n.create({...t,labels:{...t.labels??{},[St]:s}},{timeout:0,onSnapshotCreateLogs:u=>{for(let m of u.split(`
|
|
2
|
+
`)){let p=m.trimEnd();p.length>0&&d("build_log",p);}}});(async()=>{for(;!i;){try{if(o===null)for await(let m of n.list({labels:{[St]:s}})){o=m;break}else await o.refreshData();let u=o?.state??null;u!==a&&(a=u,d("state"));}catch{}i||await S(r);}})();let c=()=>{let u=new q(xt(a),a,o?.id??null);return l.then(m=>m.delete(vt).catch(()=>{}),()=>{}),o!==null&&o.delete(vt).catch(()=>{}),u},f=new Promise((u,m)=>{let p=e.signal;if(p){if(p.aborted){m(c());return}p.addEventListener("abort",()=>{i||m(c());},{once:true});}});try{return await Promise.race([l,f])}finally{i=true;}}var v=class extends Error{snapshot;constructor(t,e){super(`Daytona snapshot "${t}" exists but could not be activated: ${e}. Daytona deactivates snapshots unused for 2 weeks; activation normally completes in seconds. Retry, or activate it manually in the Daytona dashboard (Snapshots page).`),this.name="DaytonaSnapshotActivationError",this.snapshot=t;}};async function z(n,t,e,s){let r=s?.timeoutMs??se,o=s?.pollMs??re;console.log(`[daytona] Snapshot "${t}" is inactive (unused for 2+ weeks) \u2014 reactivating...`);let a;try{a=await n.snapshot.activate(e);}catch(d){throw new v(t,`the activate call failed (${d instanceof Error?d.message:String(d)})`)}let i=Date.now()+r;for(;a?.state!=="active";){if(a?.state==="error"||a?.state==="build_failed")throw new v(t,`it entered state "${a.state}"`);if(Date.now()>=i)throw new v(t,`still "${a?.state??"unknown"}" after ${r}ms`);await S(o);try{a=await n.snapshot.get(t);}catch(d){throw new v(t,`the activation poll failed (${d instanceof Error?d.message:String(d)})`)}}return console.log(`[daytona] Snapshot "${t}" reactivated.`),a}var T=class extends Error{snapshot;constructor(t,e){super(`Daytona snapshot "${t}" is being created by another process and this run could not wait it out: ${e}.`),this.name="DaytonaSnapshotConflictError",this.snapshot=t;}},_t=Symbol("daytona-snapshot-gone"),Mt=new Set(["pending","pulling","building","snapshotting"]),ue=3;function ot(n){let t=n;return t?.status??t?.statusCode??t?.response?.status}var At=new Set(["error","build_failed"]),ge=new Set(["latest","lts","stable"]);function K(n){let t=rt[n]??n;if(t.includes("@"))return /@[a-z0-9]+(?:[.+_-][a-z0-9]+)*:[0-9a-f]{32,}$/i.test(t);let e=t.substring(t.lastIndexOf("/")+1),s=e.lastIndexOf(":");if(s<0)return false;let r=e.substring(s+1);return r===""?false:!ge.has(r.toLowerCase())}function X(n){let t=n.toLowerCase();return t.includes("not found")||t.includes("404")||t.includes("does not exist")}var Ct=6e4,Ot=2e3;async function Pt(n,t,e,s){let r=e.errorReason?`: ${e.errorReason}`:"";console.warn(`[daytona] Deleting dead snapshot "${t}" (state "${e.state??"unknown"}"${r}) before rebuilding it.`);try{await n.snapshot.delete(e);}catch(d){let l=d instanceof Error?d.message:String(d);if(!X(l))return console.warn(`[daytona] Could not delete dead snapshot "${t}" (${l}) \u2014 delete it in the Daytona dashboard (Snapshots page) to restore the fast path; falling back to a direct image pull for now.`),false}let o=s?.timeoutMs??Ct,a=s?.pollMs??Ot,i=Date.now()+o;for(;;){try{await n.snapshot.get(t);}catch(d){if(X(d instanceof Error?d.message:String(d)))return true}if(Date.now()>=i)return console.warn(`[daytona] Dead snapshot "${t}" still resolves ${o}ms after it was deleted \u2014 leaving the rebuild to the next run rather than racing the removal.`),false;await S(a);}}function Lt(n){if(ot(n)===409)return true;let t=(n instanceof Error?n.message:String(n)).toLowerCase();return t.includes("already exists")||t.includes("conflict")}function fe(n){let t=ot(n);if(t===401||t===403)return true;let e=(n instanceof Error?n.message:String(n)).toLowerCase();return e.includes("unauthorized")||e.includes("forbidden")||e.includes("status code 401")||e.includes("status code 403")}async function Rt(n,t,e){let s=e?.timeoutMs??kt,r=e?.pollMs??It;console.log(`[daytona] Snapshot "${t}" is already being created by another process \u2014 waiting for it (up to ${Math.round(s/1e3)}s) instead of pulling the image directly...`);let o=Date.now()+s,a,i="",d=0;for(;;){try{a=await n.snapshot.get(t),i="",d=0;}catch(l){a=void 0;let g=l instanceof Error?l.message:String(l);if(X(g))return console.log(`[daytona] Snapshot "${t}" no longer exists \u2014 the name is clear, building it.`),_t;if(fe(l))throw new T(t,`the poll was refused (${g}) \u2014 these credentials cannot read the snapshot, so waiting longer cannot help`);if(d=g===i?d+1:1,i=g,d>=ue)throw new T(t,`${d} consecutive polls failed the same way (${g}) \u2014 the control plane is not answering, so waiting longer cannot help`);console.warn(`[daytona] Poll of contended snapshot "${t}" failed, retrying: ${g}`);}if(a!==void 0&&!Mt.has(a.state??""))return a;if(Date.now()>=o)throw new T(t,`it was still "${a?.state??"unknown"}" after ${s}ms \u2014 retry once that build finishes, or check the snapshot in the Daytona dashboard (Snapshots page)`);await S(r);}}function V(n,t){if(!t||t<=0)return n;let e=Buffer.from(n).toString("base64"),s=`/tmp/.evolve-cmd-${Date.now()}-${Math.random().toString(36).slice(2,8)}.sh`;return `sh -c '${`echo ${e} | base64 -d > ${s} && [ -s ${s} ] || { rm -f ${s}; exit 126; }; if command -v timeout >/dev/null 2>&1; then timeout -k 10 ${t} bash ${s}; else bash ${s}; fi; rc=$?; rm -f ${s}; exit $rc`}'`}function Dt(){return `EVOLVE-EOS-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function Q(n,t){return n.trim()?`exec 9>&1 && { :
|
|
3
3
|
${n}
|
|
4
4
|
|
|
5
|
-
}; __evolve_eos=$?; printf '%s' '${t}' 2>/dev/null >&9; exec 9>&-; (exit $__evolve_eos)`:n}function
|
|
6
|
-
`)?n.slice(0,-(t.length+1)):n.endsWith(t)?n.slice(0,-t.length):n}function
|
|
7
|
-
`,s="",o=r=>{for(let a=Math.min(r.length,e.length);a>0;a--)if(e.startsWith(r.slice(r.length-a)))return a;return 0};return {push(r){s+=r;let a=o(s);a!==s.length&&(t(s.slice(0,s.length-a)),s=s.slice(s.length-a));},flush(){let r=s===e||s===n?"":s;s="",r&&t(r);}}}function Z(n,t,e,s){let o=n;return t&&(o=`cd '${t.replace(/'/g,"'\\''")}' && ${o}`),e&&Object.keys(e).length>0&&(o=`${Object.entries(e).filter(([,a])=>a!=null).map(([a,i])=>`export ${a}='${String(i).replace(/'/g,"'\\''")}'`).join("; ")}; ${o}`),s==="root"&&(o=`echo ${Buffer.from(o).toString("base64")} | base64 -d | sudo -n bash`),o}function Nt(n){let t=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(?:\/(\d{1,3}))?$/.exec(n);return !(!t||[t[1],t[2],t[3],t[4]].some(e=>Number(e)>255)||t[5]!==void 0&&Number(t[5])>32)}function me(n){return /^\d{1,3}(\.\d{1,3}){3}(\/\d+)?$/.test(n)&&!Nt(n)}function ge(n){return n.startsWith("[")?true:(n.match(/:/g)?.length??0)>=2}function pe(n){return /^[^:]+:\d+$/.test(n)}function he(n){return n.startsWith("*.")&&n.length>2&&!n.slice(2).includes("*")}function C(n){if(!n||n.outbound==="open"){if(n?.allowedDestinations?.length)throw new Error("network.allowedDestinations is only valid when outbound is blocked");return n?{networkBlockAll:false}:{}}let t=n.allowedDestinations??[];if(t.length===0)return {networkBlockAll:true};for(let r of t){if(r.trim()==="")throw new b("invalid-destination",`network.allowedDestinations contains an empty destination (${JSON.stringify(r)}). Every entry must be a hostname, *.wildcard domain, IPv4 address, or IPv4 CIDR \u2014 remove the blank entry (an empty allowlist would open the sandbox, not seal it).`,r);if(r.includes(","))throw new b("invalid-destination",`network.allowedDestinations entry "${r}" contains a comma. Daytona's allowlists are sent as one comma-joined string, so a comma inside an entry would smuggle extra destinations past the list caps \u2014 pass one destination per array entry.`,r)}let e=[],s=[];for(let r of t)if(Nt(r))e.push(r.includes("/")?r:`${r}/32`);else {if(me(r))throw new b("invalid-ipv4",`"${r}" is not a valid IPv4 address or CIDR (octets must be 0-255, prefix 0-32). Fix the address or list a hostname instead.`,r);if(ge(r))throw new b("ipv6-unsupported",`Daytona's network allowlist supports IPv4 CIDRs only; cannot allow IPv6 destination "${r}".`,r);if(pe(r))throw new b("port-unsupported",`Daytona's network allowlist filters hosts and IPs only and cannot match a port; drop the ":<port>" from "${r}" and list just the host or IP.`,r);if(r.includes("*")&&!he(r))throw new b("wildcard-hostname",`Daytona's domain allowlist supports exactly one wildcard form \u2014 a "*." prefix ("*.example.com" allows example.com and its subdomains) \u2014 and cannot express "${r}". Use a *.prefix wildcard, a concrete hostname, or an IPv4 CIDR instead.`,r);s.push(r);}if(e.length>0&&s.length>0)throw new b("mixed-allowlist",`Daytona's networkAllowList (IPv4 CIDRs) and domainAllowList (DNS names) are mutually exclusive \u2014 at most one may be non-empty per sandbox, and this policy names both kinds (CIDRs: ${e.join(", ")}; domains: ${s.join(", ")}). List only IPs/CIDRs or only hostnames for this sandbox.`);if(s.length>0){let r=[...new Set(s)];if(r.length>ht)throw new b("allowlist-too-large",`Daytona allows at most ${ht} entries in its domain allowlist; this policy names ${r.length} domains (${r.join(", ")}). Consolidate under *.prefix wildcards or reduce the list.`);return {networkBlockAll:false,domainAllowList:r.join(",")}}let o=[...new Set(e)];if(o.length>pt)throw new b("allowlist-too-large",`Daytona allows at most ${pt} entries in its network allowlist; this policy resolved to ${o.length} CIDRs (${o.join(", ")}). Aggregate destinations into broader CIDRs or reduce the list.`);return {networkBlockAll:false,networkAllowList:o.join(",")}}function Rt(n){let t=C(n);return t.networkAllowList!==void 0||t.domainAllowList!==void 0?{networkBlockAll:false,networkAllowList:t.networkAllowList??"",domainAllowList:t.domainAllowList??""}:{networkBlockAll:t.networkBlockAll===true,networkAllowList:"",domainAllowList:""}}function Ut(n){let t=rt(n),e=(n instanceof Error?n.message:String(n)).toLowerCase(),s=e.includes("network policy")||e.includes("network settings")||e.includes("network configuration"),o=e.includes("tier")||e.includes("plan")||e.includes("upgrade")||e.includes("not allowed")||e.includes("not permitted")||e.includes("cannot override");return (t===402||t===403)&&(o||s)?true:s&&o}function Ft(n){let t=n.indexOf("/");if(t<0)return;let e=n.substring(0,t);return e.includes(".")||e.includes(":")||e==="localhost"?e:void 0}function at(n){return {sandboxId:n.id,image:n.snapshot??"",name:n.name,metadata:n.labels??{},startedAt:n.createdAt??""}}function Bt(n){if(n==="started")return "running";if(n==="stopped"||n==="archived"||n==="paused")return "paused"}function Yt(n,t){if(!n||typeof n!="object")return;let e=n;if(typeof e.toolboxProxyUrl=="string"&&(e.toolboxProxyUrl=t),Array.isArray(e.items))for(let s of e.items)Yt(s,t);}function we(n,t){return new Proxy(n,{get(e,s,o){if(s==="getToolboxProxyUrl")return async()=>({data:{url:t}});let r=Reflect.get(e,s,o);return typeof r!="function"?r:function(...a){let i=r.apply(e,a);return i instanceof Promise?i.then(d=>(Yt(d?.data,t),d)):i}}})}var tt=class extends sdk.Daytona{constructor(t,e){super(t);let s=this;s.sandboxApi=we(s.sandboxApi,e);}};function ye(n,t){let e=new Uint8Array(new ArrayBuffer(n.length+t.length));return e.set(n,0),e.set(t,n.length),e}function Dt(n,t,e){t:for(let s=e;s+t.length<=n.length;s++){for(let o=0;o<t.length;o++)if(n[s+o]!==t[o])continue t;return s}return -1}function Gt(n,t){let e=new TextDecoder("utf-8"),s=new TextDecoder("utf-8"),o=new Uint8Array(0),r="stdout",a=i=>{i.length!==0&&(r==="stdout"?n(e.decode(i,{stream:true})):t(s.decode(i,{stream:true})));};return {push(i){for(o=ye(o,i);;){let d=Dt(o,sdk.STDOUT_PREFIX_BYTES,0),u=Dt(o,sdk.STDERR_PREFIX_BYTES,0),m=-1,c="stdout",f=0;if(d!==-1&&(u===-1||d<u)?(m=d,c="stdout",f=sdk.STDOUT_PREFIX_BYTES.length):u!==-1&&(m=u,c="stderr",f=sdk.STDERR_PREFIX_BYTES.length),m===-1){let l=Math.max(0,o.length-(sdk.MAX_PREFIX_LEN-1));a(o.subarray(0,l)),o=o.slice(l);return}a(o.subarray(0,m)),r=c,o=o.slice(m+f);}},flush(){a(o),o=new Uint8Array(0);let i=e.decode();i&&n(i);let d=s.decode();d&&t(d);}}}async function Wt(n,t,e,s,o,r,a){let i=`${n.toolboxUrl.replace(/\/+$/,"")}/${encodeURIComponent(t)}/process/session/${encodeURIComponent(e)}/command/${encodeURIComponent(s)}/logs?follow=true`,d=await fetch(i,{headers:{Authorization:`Bearer ${n.apiKey}`,accept:"application/octet-stream"},...a?{signal:a}:{}});if(!d.ok)throw new Error(`Daytona managed log follow failed: ${d.status} ${await d.text()}`);if(!d.body)return;let u=Gt(o,r),m=d.body.getReader();try{for(;;){let{done:c,value:f}=await m.read();if(c)break;f&&u.push(f);}}finally{u.flush(),await m.cancel().catch(()=>{});}}function Ht(n){let t=n.stdout||"",e=n.stderr||"",s=n.output||"";return !t&&!e&&s?{stdout:s,stderr:""}:{stdout:t,stderr:e}}var et=class{constructor(t,e,s){this.sandbox=t;this.user=e;this.managedStream=s;}streamTimings=oe;followLogs(t,e,s,o,r){return this.managedStream?Wt(this.managedStream,this.sandbox.id,t,e,s,o,r):this.sandbox.process.getSessionCommandLogs(t,e,s,o)}async run(t,e){let s=e?.timeoutMs?Math.floor(e.timeoutMs/1e3):void 0,o=`run-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await this.sandbox.process.createSession(o);try{let r=!!(e?.onStdout||e?.onStderr),a=At(),i=await this.sandbox.process.executeSessionCommand(o,{command:q(Z(Q(t,a),e?.cwd,e?.envs,this.user),s),runAsync:r},s),d=i.cmdId;if(r&&!d)throw new Error("Daytona returned no command id for an async command \u2014 cannot stream it or read its exit code");if(r&&d){let c="",f="",l=!0,g=Date.now(),p=J(a,h=>{c+=h,e?.onStdout?.(h);}),w=new AbortController,y=this.followLogs(o,d,h=>{l&&(g=Date.now(),p.push(h));},h=>{l&&(g=Date.now(),f+=h,e?.onStderr?.(h));},w.signal),x=!1,$,zt=y.then(()=>{},h=>{x||($=h);}),it;try{it=await this.awaitStreamedExit(o,d,y,()=>g,e?.timeoutMs);}finally{x=!0,w.abort(),await Promise.race([zt,S(this.streamTimings.drainMs)]),l=!1,$===void 0&&p.flush();}if($!==void 0){let h;try{let Kt=await this.sandbox.process.getSessionCommandLogs(o,d);h=P(Kt,a);}catch{throw $}if(!h.stdout.startsWith(c)||!h.stderr.startsWith(f))throw $;let I=h.stdout.slice(c.length),dt=h.stderr.slice(f.length);c=h.stdout,f=h.stderr,I&&e?.onStdout?.(I),dt&&e?.onStderr?.(dt);}else if(!c&&!f)try{let h=await this.sandbox.process.getSessionCommandLogs(o,d),I=P(h,a);c=I.stdout,f=I.stderr,c&&e?.onStdout?.(c),f&&e?.onStderr?.(f);}catch{}return {exitCode:it,stdout:c,stderr:f}}let{stdout:u,stderr:m}=P(i,a);if(!u&&!m&&d)try{let c=await this.sandbox.process.getSessionCommandLogs(o,d),f=P(c,a);u=f.stdout,m=f.stderr||m;}catch{}return {exitCode:i.exitCode??0,stdout:u,stderr:m}}finally{try{await this.sandbox.process.deleteSession(o);}catch{}}}async awaitStreamedExit(t,e,s,o,r){let a=this.streamTimings,i,d,u=s.then(()=>{i=Date.now();},f=>{i=Date.now(),d=f;}),m=r!==void 0&&r>0?Date.now()+r+a.killGraceMs:void 0,c=a.pollMinMs;for(;;){let f=await this.sandbox.process.getSessionCommand(t,e);if(f.exitCode!==void 0&&f.exitCode!==null){for(;i===void 0;){let p=Date.now()-o();if(p>=a.drainMs)break;await Promise.race([u,S(a.drainMs-p)]);}return f.exitCode}let l=i!==void 0?i+a.settleMs:void 0,g=m!==void 0&&l!==void 0?Math.min(m,l):m??l;if(g!==void 0&&Date.now()>=g)throw d!==void 0?d:new Error(`Daytona reported no exit code for command ${e} after `+(i!==void 0?"its log stream closed":`${r}ms`));await S(c),c=Math.min(c*2,a.pollMaxMs);}}async spawn(t,e){let s=`evolve-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await this.sandbox.process.createSession(s);let o=e?.timeoutMs?Math.floor(e.timeoutMs/1e3):void 0,r=Date.now(),a=e?.timeoutMs,i=At(),u=(await this.sandbox.process.executeSessionCommand(s,{command:q(Z(Q(t,i),e?.cwd,e?.envs,this.user),o),runAsync:true},o)).cmdId;if(u&&(e?.onStdout||e?.onStderr)){let c=J(i,e.onStdout||(()=>{}));this.followLogs(s,u,f=>c.push(f),e.onStderr||(()=>{})).catch(()=>{}).finally(()=>c.flush());}let m=this.sandbox;return {processId:s,wait:async()=>{if(!u)return {exitCode:0,stdout:"",stderr:""};for(;;){if(a&&Date.now()-r>=a){try{await m.process.deleteSession(s);}catch{}return {exitCode:124,stdout:"",stderr:"operation timed out"}}try{let c=await m.process.getSessionCommand(s,u);if(c.exitCode!==void 0)try{let f=await m.process.getSessionCommandLogs(s,u);return {exitCode:c.exitCode,...P(f,i)}}catch{return {exitCode:c.exitCode,stdout:"",stderr:""}}}catch(c){let f=c instanceof Error?c.message.toLowerCase():String(c).toLowerCase();if(f.includes("not found")){let l=f.includes("sandbox");try{await m.refreshData(),l=!1;}catch(g){(g instanceof Error?g.message.toLowerCase():String(g).toLowerCase()).includes("not found")&&(l=true);}return {exitCode:-1,stdout:"",stderr:l?"sandbox deleted during run":"session terminated"}}throw c}await S(500);}},kill:async()=>{try{return await m.process.deleteSession(s),!0}catch{return false}}}}async list(){try{return (await this.sandbox.process.listSessions()).map(e=>({processId:e.sessionId||"",cmd:"",args:[],envs:{}}))}catch{return []}}async kill(t){try{return await this.sandbox.process.deleteSession(t),!0}catch{return false}}},Pt="%y\\0%s\\0%T@\\0%m\\0%u\\0%g\\0%l\\0%f\\0",Y=8,be=1800*1e3;function xe(n,t){let e=R(n),s=t==="children"?`[ -e ${e} ] || exit ${M}; [ -d ${e} ] || exit ${N};`:`[ -e ${e} ] || [ -L ${e} ] || exit ${M};`,o=t==="children"?`find -H ${e} -mindepth 1 -maxdepth 1 -printf '${Pt}'`:`find ${e} -maxdepth 0 -printf '${Pt}'`;return `sh -c ${R(`${s} ( ${o}; printf 'STATUS:%d' "$?" ) | base64`)}`}function Se(n,t,e){let o=Buffer.from(t.replace(/\s+/g,""),"base64").toString("utf-8").split("\0"),r=o.pop()??"",a=/^STATUS:(\d+)$/.exec(r);if(!a)throw new Error(`daytona: the listing of ${n} ended without find's status (${r.slice(0,40)})`);if(a[1]!=="0")throw new Error(`daytona: find exited ${a[1]} listing ${n}`);let i=[];for(let d=0;d+Y<=o.length;d+=Y){let[u,m,c,f,l,g,p,w]=o.slice(d,d+Y),y=u==="f"?"file":u==="d"?"dir":u==="l"?"symlink":"other",x={name:w,path:e==="children"?ut(n,w):n,type:y,size:Number(m),mtime:F(Number(c)),mode:ct(f),owner:l,group:g};y==="symlink"&&(x.target=p),i.push(x);}return i}var nt=class{constructor(t,e){this.sandbox=t;this.commands=e;}async read(t){let e=new Uint8Array(await this.sandbox.fs.downloadFile(t));if(!e.includes(0))try{return new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(e)}catch{}return e}async write(t,e){let s;if(typeof e=="string")s=Buffer.from(e,"utf-8");else if(Buffer.isBuffer(e))s=e;else if(e instanceof ArrayBuffer)s=Buffer.from(e);else if(e instanceof Uint8Array)s=Buffer.from(e);else throw new Error(`Unsupported content type: ${typeof e}`);await this.sandbox.fs.uploadFile(s,t);}async writeBatch(t){let e=t.map(s=>{let o;if(typeof s.data=="string")o=Buffer.from(s.data,"utf-8");else if(Buffer.isBuffer(s.data))o=s.data;else if(s.data instanceof ArrayBuffer)o=Buffer.from(s.data);else if(s.data instanceof Uint8Array)o=Buffer.from(s.data);else throw new Error(`Unsupported content type: ${typeof s.data}`);return {source:o,destination:s.path}});await this.sandbox.fs.uploadFiles(e);}async writeFromPath(t,e){await this.sandbox.fs.uploadFile(e,t);}async makeDir(t){await this.sandbox.fs.createFolder(t,"755");}async exists(t){try{let e=ae(t),s=ie(t);return (await this.sandbox.fs.listFiles(e)).some(r=>r.name===s)}catch{return false}}async list(t){return this.findListing(t,"children")}async stat(t){let[e]=await this.findListing(t,"self");if(!e)throw new A(t,"daytona");return e}async findListing(t,e){let s=await this.commands.run(xe(t,e));if(s.exitCode===M)throw new A(t,"daytona");if(s.exitCode===N)throw new Error(`daytona: ${t} is not a directory`);if(s.exitCode!==0)throw new Error(`daytona: listing ${t} failed (exit ${s.exitCode}): ${s.stderr.trim()}`);try{return Se(t,s.stdout,e)}catch(o){throw /printf|unrecognized|invalid option/i.test(s.stderr)?new E("files.list","daytona",`this image's find has no -printf (GNU findutils is needed to list entries as themselves): ${s.stderr.trim()}`):o}}async readRange(t,e){if(U(e),e.length===0)return new Uint8Array(0);let s=await this.sandbox.downloadUrl(t);return ft(s,e,{provider:"daytona",path:t,timeoutMs:be})}async watchDir(t,e,s){throw new E("files.watchDir","daytona","the Daytona SDK has no filesystem watcher; poll files.list() on the directories you have open")}async remove(t){await this.sandbox.fs.deleteFile(t,true);}async rename(t,e){await this.sandbox.fs.moveFiles(t,e);}},D=class{constructor(t,e,s){this.sandbox=t;let o=new et(t,e,s);this.commands=o,this.files=new nt(t,o);}commands;files;get sandboxId(){return this.sandbox.id}async getHost(t){return (await this.sandbox.getPreviewLink(t)).url}async isRunning(){try{await this.sandbox.refreshData();}catch{return false}return this.sandbox.state==="started"}async getInfo(){return await this.sandbox.refreshData(),at(this.sandbox)}async metrics(){let t=await this.sandbox.getMetricsLatest();return {cpuPct:t.cpuUsedPct,memUsedMb:t.memUsed/G,memTotalMb:t.memTotal/G,diskUsedMb:t.diskUsed/G,sampledAt:F(t.timestamp),source:"daytona:getMetricsLatest"}}async updateNetwork(t){let e=Rt(t);try{await this.sandbox.updateNetworkSettings(e);}catch(s){throw Ut(s)?new b("org-tier-forbidden",`Daytona refused to change this sandbox's network policy: organizations on Tier 1 or Tier 2 cannot override network policy at the sandbox level. Raise the organization's tier, or run this workload on a provider whose plan permits runtime policy changes (underlying error: ${s instanceof Error?s.message:String(s)}).`):s}}async kill(){await this.sandbox.delete();}async pause(){await this.sandbox.stop();}},st=class{providerType="daytona";name="Daytona";client;defaultTimeoutMs;snapshotName;sandboxUsers=new Map;managedStream;snapshotConflictTiming={timeoutMs:$t,pollMs:It};snapshotDeleteTiming={timeoutMs:_t,pollMs:Mt};constructor(t){let e={apiKey:t.apiKey,apiUrl:t.apiUrl,target:t.target,useDeprecatedPolling:true};this.client=t.managedToolboxUrl?new tt(e,t.managedToolboxUrl):new sdk.Daytona(e),t.managedToolboxUrl&&(this.managedStream={toolboxUrl:t.managedToolboxUrl,apiKey:t.apiKey}),this.defaultTimeoutMs=t.defaultTimeoutMs??36e5,this.snapshotName=t.snapshotName??(t.managedToolboxUrl?"evolve-all":`evolve-all-${O}`);}async create(t){if(t.idleTimeoutMs!==void 0)throw new j;if(t.bootCommand!==void 0)throw new H;for(let l of t.phaseNetworkPolicies??[])C(l);let e=C(t.network),s=t.user,o=s&&s!=="root"?s:void 0,r=t.timeoutMs??this.defaultTimeoutMs,a=Math.max(1,Math.ceil(r/6e4)),i=t.image||this.snapshotName,d={envVars:t.envs,labels:t.metadata,autoStopInterval:a,autoDeleteInterval:ee,...o?{user:o}:{},...e},u,m=t.resources!==void 0&&(t.resources.cpu!==void 0||t.resources.memory!==void 0||t.resources.disk!==void 0||t.resources.gpu!==void 0||t.resources.gpuTypes!==void 0);if(this.managedStream){if(m)throw new k(i);let l=await this.client.create({snapshot:i,...d},{timeout:600});return t.workingDirectory&&await l.fs.createFolder(t.workingDirectory,"755"),s&&this.sandboxUsers.set(l.id,s),new D(l,s,this.managedStream)}let c,f;try{let l=await this.client.snapshot.get(i),g=l?.state;if(l&&kt.has(g??"")&&(c=g),l&&(g==="active"||g==="inactive")&&m)throw new k(i);if(l&&g==="inactive"&&(g=(await K(this.client,i,l)).state),l&&St.has(g??"")&&(X(i)?f=await vt(this.client,i,l,this.snapshotDeleteTiming):console.warn(`[daytona] Snapshot "${i}" is dead (state "${g}") but this provider cannot rebuild that name \u2014 delete it in the Daytona dashboard (Snapshots page), or rebuild it with the tooling that created it.`)),l&&g==="active")console.log(`[daytona] Using cached snapshot: ${i}`),u=await this.client.create({snapshot:i,...d},{timeout:600});else throw new Error("Snapshot not active")}catch(l){if(l instanceof k||l instanceof v)throw l;let g=ot[i]??i,p=c!==void 0&&!m;p?console.log(`[daytona] Snapshot "${i}" is mid-build (state "${c}") \u2014 joining that build rather than starting a second one.`):c!==void 0?console.log(`[daytona] Snapshot "${i}" is mid-build (state "${c}") and cannot carry the requested sizing \u2014 pulling image directly instead: ${g}`):(console.log(`[daytona] Snapshot "${i}" not found, building from image: ${g}`),console.log("[daytona] First run will take a few minutes (this only happens once)..."));try{if(f===!1)throw new Error(`dead snapshot "${i}" was not confirmed removed \u2014 not racing its removal`);let w=()=>this.client.snapshot.create({name:i,image:sdk.Image.base(g),resources:{cpu:t.resources?.cpu??4,memory:t.resources?.memory??4,disk:t.resources?.disk??10,...(t.resources?.gpu??0)>0?{gpu:t.resources.gpu}:{},...t.resources?.gpuTypes?.length?{gpuType:t.resources.gpuTypes}:{}}},{onLogs:x=>console.log(`[daytona] ${x}`)}),y=async()=>{await w(),console.log(`[daytona] Snapshot "${i}" ready (rebuilt here after a dead build).`);};if(c!==void 0){if(!p)throw new Error(`snapshot "${i}" is mid-build (state "${c}") and cannot be resized`);await this.joinInFlightSnapshotBuild(i)&&await y();}else try{await w(),console.log(`[daytona] Snapshot "${i}" ready (built here).`);}catch(x){if(!Ot(x)||m)throw x;await this.joinInFlightSnapshotBuild(i)&&await y();}u=await this.client.create({snapshot:i,...d},{timeout:600});}catch(w){if(w instanceof T||w instanceof v)throw w;console.warn(`[daytona] Snapshot creation failed, falling back to direct image: ${w instanceof Error?w.message:w}`);try{u=await this.client.create({image:g,...d,resources:{cpu:t.resources?.cpu??4,memory:t.resources?.memory??4,disk:t.resources?.disk??10,...(t.resources?.gpu??0)>0?{gpu:t.resources.gpu}:{},...t.resources?.gpuTypes?.length?{gpuType:t.resources.gpuTypes}:{}}},{timeout:600,onSnapshotCreateLogs:y=>console.log(`[daytona] ${y}`)});}catch(y){throw Ft(g)?new W(g,y):y}}}return t.workingDirectory&&await u.fs.createFolder(t.workingDirectory,"755"),s&&this.sandboxUsers.set(u.id,s),new D(u,s,this.managedStream)}async joinInFlightSnapshotBuild(t){let e=await Ct(this.client,t,this.snapshotConflictTiming);if(e===Et)return true;if(e.state==="active")return console.log(`[daytona] Snapshot "${t}" ready (built by another process) \u2014 reusing it.`),false;if(e.state==="inactive")return await K(this.client,t,e),console.log(`[daytona] Snapshot "${t}" ready (built by another process) \u2014 reusing it.`),false;if(St.has(e.state??"")&&X(t)&&await vt(this.client,t,e,this.snapshotDeleteTiming))return true;throw new Error(`the in-flight build of snapshot "${t}" ended in state "${e.state??"unknown"}"`)}async connect(t,e){let s=await this.client.get(t);return s.state!=="started"&&await s.start(),new D(s,this.sandboxUsers.get(t),this.managedStream)}async inspect(t,e){let s=await this.getSandboxRecord(t);if(s.state!=="started")throw new _(t,"daytona",s.state??"unknown");return new D(s,e?.user??this.sandboxUsers.get(t),this.managedStream)}async getSandboxRecord(t){return this.client.get(t)}async list(t){let e=await this.paginate(t);if(e.error&&!e.stoppedAtLimit)throw new Error(e.error);return e.sandboxes}async listAll(t){let{stoppedAtLimit:e,...s}=await this.paginate(t);return s}async paginate(t){return jt(this.listStream(t),t)}listStream(t){let e=t?.state?ve(t.state):void 0,s={limit:re,...t?.metadata?{labels:t.metadata}:{},...e&&e.length>0?{states:e}:{}};return this.client.list(s)}};function ve(n){let t=[];for(let e of n)e==="running"&&t.push("started"),e==="paused"&&t.push("stopped","archived","paused");return t}async function jt(n,t){let e=t?.limit,s=[],o=0,r=new Set;try{for await(let a of n){if(e!==void 0&&s.length>=e)return {sandboxes:s,complete:!1,pagesFetched:o,stoppedAtLimit:!0,error:`stopped at the requested limit of ${e} with more sandboxes available`};if(o+=1,o>B)return {sandboxes:s,complete:!1,pagesFetched:B,stoppedAtLimit:!1,error:`sandbox list exceeded ${B} sandboxes scanned`};if(t?.state){let i=Bt(a.state);if(i===void 0||!t.state.includes(i))continue}r.has(a.id)||(r.add(a.id),s.push(at(a)));}}catch(a){return {sandboxes:s,complete:false,pagesFetched:o,stoppedAtLimit:false,error:`sandbox list failed: ${a instanceof Error?a.message:String(a)}`}}return {sandboxes:s,complete:true,pagesFetched:o,stoppedAtLimit:false}}var Le=jt;function Ne(n={}){let t=n.apiKey??process.env.DAYTONA_API_KEY;if(!t)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 st({...n,apiKey:t})}var Re=Z,Ue=q,Fe=C,Be=Rt,Ye=Ut,Ge=Ft,We=at,He=Bt,je=K,ze=Ct,Ke=Ot,Xe=X,Ve=ot,qe=Q,Qe=Lt,Je=P,Ze=J,tn=Gt,en=Wt,nn=Ht,sn=D,G=1024*1024;
|
|
8
|
-
exports.DAYTONA_AUTO_DELETE_GRACE_MINUTES=ee;exports.DAYTONA_BOOT_LABEL=bt;exports.DAYTONA_BOOT_POLL_MS=le;exports.DAYTONA_LIST_PAGE_SIZE=re;exports.DAYTONA_MAX_DOMAIN_ALLOWLIST=ht;exports.DAYTONA_MAX_LIST_SCAN=B;exports.DAYTONA_MAX_NETWORK_ALLOWLIST=pt;exports.DAYTONA_SNAPSHOT_ACTIVATE_TIMEOUT_MS=ne;exports.DAYTONA_SNAPSHOT_CONFLICT_TIMEOUT_MS=$t;exports.DAYTONA_SNAPSHOT_GONE=Et;exports.DAYTONA_STREAM_TIMINGS=oe;exports.DaytonaBootAbortedError=z;exports.DaytonaBootCommandError=H;exports.DaytonaCommands=et;exports.DaytonaFiles=nt;exports.DaytonaGpuTypeError=wt;exports.DaytonaIdleTimeoutError=j;exports.DaytonaImagePullError=W;exports.DaytonaNetworkPolicyError=b;exports.DaytonaProvider=st;exports.DaytonaResourcesError=k;exports.DaytonaSnapshotActivationError=v;exports.DaytonaSnapshotConflictError=T;exports.EVOLVE_IMAGE_VERSION=O;exports.SandboxFeatureUnsupportedError=E;exports.SandboxNotRunningError=_;exports.SandboxPathNotFoundError=A;exports._testActivateSnapshot=je;exports._testCollectSandboxStream=Le;exports._testCreateLogDemuxer=tn;exports._testCreateSentinelFilter=Ze;exports._testDaytonaSandboxImplCtor=sn;exports._testDaytonaStateToEvolveState=He;exports._testFollowManagedSessionLogs=en;exports._testImageMap=Ve;exports._testImageRegistryHost=Ge;exports._testIsNetworkPolicyTierRefusal=Ye;exports._testIsSnapshotNameConflict=Ke;exports._testMapNetworkPolicy=Fe;exports._testMapNetworkPolicyForUpdate=Be;exports._testProviderCanRebuildSnapshot=Xe;exports._testReadCommandStreams=nn;exports._testSettledStreams=Je;exports._testStripEndOfOutputSentinel=Qe;exports._testToSandboxInfo=We;exports._testWaitForSnapshotConflictWinner=ze;exports._testWithEndOfOutputSentinel=qe;exports._testWithInBoxTimeout=Ue;exports._testWrapCommand=Re;exports.createDaytonaProvider=Ne;exports.createSandboxObserved=Ce;exports.daytonaBootPhaseOf=yt;exports.isSandboxFeatureUnsupportedError=Xt;exports.isSandboxNotRunningError=qt;exports.isSandboxPathNotFoundError=Vt;exports.mapNetworkPolicy=C;
|
|
5
|
+
}; __evolve_eos=$?; printf '%s' '${t}' 2>/dev/null >&9; exec 9>&-; (exit $__evolve_eos)`:n}function Nt(n,t){return n.endsWith(`${t}
|
|
6
|
+
`)?n.slice(0,-(t.length+1)):n.endsWith(t)?n.slice(0,-t.length):n}function D(n,t){let e=dt(n);return {stdout:Nt(e.stdout,t),stderr:e.stderr}}function J(n,t){let e=`${n}
|
|
7
|
+
`,s="",r=o=>{for(let a=Math.min(o.length,e.length);a>0;a--)if(e.startsWith(o.slice(o.length-a)))return a;return 0};return {push(o){s+=o;let a=r(s);a!==s.length&&(t(s.slice(0,s.length-a)),s=s.slice(s.length-a));},flush(){let o=s===e||s===n?"":s;s="",o&&t(o);}}}function Z(n,t,e,s){let r=n;return t&&(r=`cd '${t.replace(/'/g,"'\\''")}' && ${r}`),e&&Object.keys(e).length>0&&(r=`${Object.entries(e).filter(([,a])=>a!=null).map(([a,i])=>`export ${a}='${String(i).replace(/'/g,"'\\''")}'`).join("; ")}; ${r}`),s==="root"&&(r=`echo ${Buffer.from(r).toString("base64")} | base64 -d | sudo -n bash`),r}function Ut(n){let t=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(?:\/(\d{1,3}))?$/.exec(n);return !(!t||[t[1],t[2],t[3],t[4]].some(e=>Number(e)>255)||t[5]!==void 0&&Number(t[5])>32)}function me(n){return /^\d{1,3}(\.\d{1,3}){3}(\/\d+)?$/.test(n)&&!Ut(n)}function pe(n){return n.startsWith("[")?true:(n.match(/:/g)?.length??0)>=2}function he(n){return /^[^:]+:\d+$/.test(n)}function we(n){return n.startsWith("*.")&&n.length>2&&!n.slice(2).includes("*")}function O(n){if(!n||n.outbound==="open"){if(n?.allowedDestinations?.length)throw new Error("network.allowedDestinations is only valid when outbound is blocked");return n?{networkBlockAll:false}:{}}let t=n.allowedDestinations??[];if(t.length===0)return {networkBlockAll:true};for(let o of t){if(o.trim()==="")throw new b("invalid-destination",`network.allowedDestinations contains an empty destination (${JSON.stringify(o)}). Every entry must be a hostname, *.wildcard domain, IPv4 address, or IPv4 CIDR \u2014 remove the blank entry (an empty allowlist would open the sandbox, not seal it).`,o);if(o.includes(","))throw new b("invalid-destination",`network.allowedDestinations entry "${o}" contains a comma. Daytona's allowlists are sent as one comma-joined string, so a comma inside an entry would smuggle extra destinations past the list caps \u2014 pass one destination per array entry.`,o)}let e=[],s=[];for(let o of t)if(Ut(o))e.push(o.includes("/")?o:`${o}/32`);else {if(me(o))throw new b("invalid-ipv4",`"${o}" is not a valid IPv4 address or CIDR (octets must be 0-255, prefix 0-32). Fix the address or list a hostname instead.`,o);if(pe(o))throw new b("ipv6-unsupported",`Daytona's network allowlist supports IPv4 CIDRs only; cannot allow IPv6 destination "${o}".`,o);if(he(o))throw new b("port-unsupported",`Daytona's network allowlist filters hosts and IPs only and cannot match a port; drop the ":<port>" from "${o}" and list just the host or IP.`,o);if(o.includes("*")&&!we(o))throw new b("wildcard-hostname",`Daytona's domain allowlist supports exactly one wildcard form \u2014 a "*." prefix ("*.example.com" allows example.com and its subdomains) \u2014 and cannot express "${o}". Use a *.prefix wildcard, a concrete hostname, or an IPv4 CIDR instead.`,o);s.push(o);}if(e.length>0&&s.length>0)throw new b("mixed-allowlist",`Daytona's networkAllowList (IPv4 CIDRs) and domainAllowList (DNS names) are mutually exclusive \u2014 at most one may be non-empty per sandbox, and this policy names both kinds (CIDRs: ${e.join(", ")}; domains: ${s.join(", ")}). List only IPs/CIDRs or only hostnames for this sandbox.`);if(s.length>0){let o=[...new Set(s)];if(o.length>yt)throw new b("allowlist-too-large",`Daytona allows at most ${yt} entries in its domain allowlist; this policy names ${o.length} domains (${o.join(", ")}). Consolidate under *.prefix wildcards or reduce the list.`);return {networkBlockAll:false,domainAllowList:o.join(",")}}let r=[...new Set(e)];if(r.length>wt)throw new b("allowlist-too-large",`Daytona allows at most ${wt} entries in its network allowlist; this policy resolved to ${r.length} CIDRs (${r.join(", ")}). Aggregate destinations into broader CIDRs or reduce the list.`);return {networkBlockAll:false,networkAllowList:r.join(",")}}function Ft(n){let t=O(n);return t.networkAllowList!==void 0||t.domainAllowList!==void 0?{networkBlockAll:false,networkAllowList:t.networkAllowList??"",domainAllowList:t.domainAllowList??""}:{networkBlockAll:t.networkBlockAll===true,networkAllowList:"",domainAllowList:""}}function Bt(n){let t=ot(n),e=(n instanceof Error?n.message:String(n)).toLowerCase(),s=e.includes("network policy")||e.includes("network settings")||e.includes("network configuration"),r=e.includes("tier")||e.includes("plan")||e.includes("upgrade")||e.includes("not allowed")||e.includes("not permitted")||e.includes("cannot override");return (t===402||t===403)&&(r||s)?true:s&&r}function Yt(n){let t=n.indexOf("/");if(t<0)return;let e=n.substring(0,t);return e.includes(".")||e.includes(":")||e==="localhost"?e:void 0}function at(n){return {sandboxId:n.id,image:n.snapshot??"",name:n.name,metadata:n.labels??{},startedAt:n.createdAt??""}}function Gt(n){if(n==="started")return "running";if(n==="stopped"||n==="archived"||n==="paused")return "paused"}function Wt(n,t){if(!n||typeof n!="object")return;let e=n;if(typeof e.toolboxProxyUrl=="string"&&(e.toolboxProxyUrl=t),Array.isArray(e.items))for(let s of e.items)Wt(s,t);}function ye(n,t,e){return new Proxy(n,{get(s,r,o){if(r==="getToolboxProxyUrl")return async()=>({data:{url:t}});let a=Reflect.get(s,r,o);return typeof a!="function"?a:function(...i){let d=()=>a.apply(s,i),l=r==="createSandbox"&&e?e(()=>d()):d();return l instanceof Promise?l.then(g=>(Wt(g?.data,t),g)):l}}})}var tt=class extends sdk.Daytona{constructor(t,e,s){super(t);let r=this;r.sandboxApi=ye(r.sandboxApi,e,s);}};function be(n,t){let e=new Uint8Array(new ArrayBuffer(n.length+t.length));return e.set(n,0),e.set(t,n.length),e}function Tt(n,t,e){t:for(let s=e;s+t.length<=n.length;s++){for(let r=0;r<t.length;r++)if(n[s+r]!==t[r])continue t;return s}return -1}function it(n,t){let e=new TextDecoder("utf-8"),s=new TextDecoder("utf-8"),r=new Uint8Array(0),o="stdout",a=i=>{i.length!==0&&(o==="stdout"?n(e.decode(i,{stream:true})):t(s.decode(i,{stream:true})));};return {push(i){for(r=be(r,i);;){let d=Tt(r,sdk.STDOUT_PREFIX_BYTES,0),l=Tt(r,sdk.STDERR_PREFIX_BYTES,0),g=-1,c="stdout",f=0;if(d!==-1&&(l===-1||d<l)?(g=d,c="stdout",f=sdk.STDOUT_PREFIX_BYTES.length):l!==-1&&(g=l,c="stderr",f=sdk.STDERR_PREFIX_BYTES.length),g===-1){let u=Math.max(0,r.length-(sdk.MAX_PREFIX_LEN-1));a(r.subarray(0,u)),r=r.slice(u);return}a(r.subarray(0,g)),o=c,r=r.slice(g+f);}},flush(){a(r),r=new Uint8Array(0);let i=e.decode();i&&n(i);let d=s.decode();d&&t(d);}}}async function jt(n,t,e,s,r,o,a){let i=Ht(n,t,e,s,true),d=await fetch(i,{headers:{Authorization:`Bearer ${n.apiKey}`,accept:"application/octet-stream"},...a?{signal:a}:{}});if(!d.ok)throw new Error(`Daytona managed log follow failed: ${d.status} ${await d.text()}`);if(!d.body)return;let l=it(r,o),g=d.body.getReader();try{for(;;){let{done:c,value:f}=await g.read();if(c)break;f&&l.push(f);}}finally{l.flush(),await g.cancel().catch(()=>{});}}function Ht(n,t,e,s,r){return `${n.toolboxUrl.replace(/\/+$/,"")}/${encodeURIComponent(t)}/process/session/${encodeURIComponent(e)}/command/${encodeURIComponent(s)}/logs${r?"?follow=true":""}`}async function xe(n,t,e,s,r){let o=await fetch(Ht(n,t,e,s,false),{headers:{Authorization:`Bearer ${n.apiKey}`,accept:"application/json, text/plain, */*"}});if(!o.ok)throw new Error(`Daytona managed log read failed: ${o.status} ${await o.text()}`);let a;if((o.headers.get("content-type")||"").includes("application/json"))a=dt(await o.json());else {let l="",g="",c=it(f=>{l+=f;},f=>{g+=f;});c.push(new Uint8Array(await o.arrayBuffer())),c.flush(),a={stdout:l,stderr:g};}let i=`${r}
|
|
8
|
+
`,d=a.stdout.indexOf(i);return d!==-1&&d+i.length<a.stdout.length&&(a={stdout:a.stdout.slice(0,d+i.length),stderr:a.stdout.slice(d+i.length)+a.stderr}),{output:"",...a}}function dt(n){let t=n.stdout||"",e=n.stderr||"",s=n.output||"";return !t&&!e&&s?{stdout:s,stderr:""}:{stdout:t,stderr:e}}var et=class{constructor(t,e,s){this.sandbox=t;this.user=e;this.managedStream=s;}streamTimings=oe;followLogs(t,e,s,r,o){return this.managedStream?jt(this.managedStream,this.sandbox.id,t,e,s,r,o):this.sandbox.process.getSessionCommandLogs(t,e,s,r)}readSettledLogs(t,e,s){return this.managedStream?xe(this.managedStream,this.sandbox.id,t,e,s):this.sandbox.process.getSessionCommandLogs(t,e)}async run(t,e){let s=e?.timeoutMs?Math.floor(e.timeoutMs/1e3):void 0,r=`run-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await this.sandbox.process.createSession(r);try{let o=!!(e?.onStdout||e?.onStderr),a=Dt(),i=await this.sandbox.process.executeSessionCommand(r,{command:V(Z(Q(t,a),e?.cwd,e?.envs,this.user),s),runAsync:o},s),d=i.cmdId;if(o&&!d)throw new Error("Daytona returned no command id for an async command \u2014 cannot stream it or read its exit code");if(o&&d){let c="",f="",u=!0,m=Date.now(),p=J(a,h=>{c+=h,e?.onStdout?.(h);}),w=new AbortController,y=this.followLogs(r,d,h=>{u&&(m=Date.now(),p.push(h));},h=>{u&&(m=Date.now(),f+=h,e?.onStderr?.(h));},w.signal),x=!1,$,zt=y.then(()=>{},h=>{x||($=h);}),lt;try{lt=await this.awaitStreamedExit(r,d,y,()=>m,e?.timeoutMs);}finally{x=!0,w.abort(),await Promise.race([zt,S(this.streamTimings.drainMs)]),u=!1,$===void 0&&p.flush();}if($!==void 0){let h;try{let Kt=await this.readSettledLogs(r,d,a);h=D(Kt,a);}catch{throw $}if(!h.stdout.startsWith(c)||!h.stderr.startsWith(f))throw $;let E=h.stdout.slice(c.length),ct=h.stderr.slice(f.length);c=h.stdout,f=h.stderr,E&&e?.onStdout?.(E),ct&&e?.onStderr?.(ct);}else if(!c&&!f)try{let h=await this.readSettledLogs(r,d,a),E=D(h,a);c=E.stdout,f=E.stderr,c&&e?.onStdout?.(c),f&&e?.onStderr?.(f);}catch{}return {exitCode:lt,stdout:c,stderr:f}}let{stdout:l,stderr:g}=D(i,a);if(!l&&!g&&d)try{let c=await this.readSettledLogs(r,d,a),f=D(c,a);l=f.stdout,g=f.stderr||g;}catch{}return {exitCode:i.exitCode??0,stdout:l,stderr:g}}finally{try{await this.sandbox.process.deleteSession(r);}catch{}}}async awaitStreamedExit(t,e,s,r,o){let a=this.streamTimings,i,d,l=s.then(()=>{i=Date.now();},f=>{i=Date.now(),d=f;}),g=o!==void 0&&o>0?Date.now()+o+a.killGraceMs:void 0,c=a.pollMinMs;for(;;){let f=await this.sandbox.process.getSessionCommand(t,e);if(f.exitCode!==void 0&&f.exitCode!==null){for(;i===void 0;){let p=Date.now()-r();if(p>=a.drainMs)break;await Promise.race([l,S(a.drainMs-p)]);}return f.exitCode}let u=i!==void 0?i+a.settleMs:void 0,m=g!==void 0&&u!==void 0?Math.min(g,u):g??u;if(m!==void 0&&Date.now()>=m)throw d!==void 0?d:new Error(`Daytona reported no exit code for command ${e} after `+(i!==void 0?"its log stream closed":`${o}ms`));await S(c),c=Math.min(c*2,a.pollMaxMs);}}async spawn(t,e){let s=`evolve-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await this.sandbox.process.createSession(s);let r=e?.timeoutMs?Math.floor(e.timeoutMs/1e3):void 0,o=Date.now(),a=e?.timeoutMs,i=Dt(),l=(await this.sandbox.process.executeSessionCommand(s,{command:V(Z(Q(t,i),e?.cwd,e?.envs,this.user),r),runAsync:true},r)).cmdId;if(l&&(e?.onStdout||e?.onStderr)){let c=J(i,e.onStdout||(()=>{}));this.followLogs(s,l,f=>c.push(f),e.onStderr||(()=>{})).catch(()=>{}).finally(()=>c.flush());}let g=this.sandbox;return {processId:s,wait:async()=>{if(!l)return {exitCode:0,stdout:"",stderr:""};for(;;){if(a&&Date.now()-o>=a){try{await g.process.deleteSession(s);}catch{}return {exitCode:124,stdout:"",stderr:"operation timed out"}}try{let c=await g.process.getSessionCommand(s,l);if(c.exitCode!==void 0)try{let f=await this.readSettledLogs(s,l,i);return {exitCode:c.exitCode,...D(f,i)}}catch{return {exitCode:c.exitCode,stdout:"",stderr:""}}}catch(c){let f=c instanceof Error?c.message.toLowerCase():String(c).toLowerCase();if(f.includes("not found")){let u=f.includes("sandbox");try{await g.refreshData(),u=!1;}catch(m){(m instanceof Error?m.message.toLowerCase():String(m).toLowerCase()).includes("not found")&&(u=true);}return {exitCode:-1,stdout:"",stderr:u?"sandbox deleted during run":"session terminated"}}throw c}await S(500);}},kill:async()=>{try{return await g.process.deleteSession(s),!0}catch{return false}}}}async list(){try{return (await this.sandbox.process.listSessions()).map(e=>({processId:e.sessionId||"",cmd:"",args:[],envs:{}}))}catch{return []}}async kill(t){try{return await this.sandbox.process.deleteSession(t),!0}catch{return false}}},$t="%y\\0%s\\0%T@\\0%m\\0%u\\0%g\\0%l\\0%f\\0",Y=8,Se=1800*1e3;function ve(n,t){let e=N(n),s=t==="children"?`[ -e ${e} ] || exit ${M}; [ -d ${e} ] || exit ${R};`:`[ -e ${e} ] || [ -L ${e} ] || exit ${M};`,r=t==="children"?`find -H ${e} -mindepth 1 -maxdepth 1 -printf '${$t}'`:`find ${e} -maxdepth 0 -printf '${$t}'`;return `sh -c ${N(`${s} ( ${r}; printf 'STATUS:%d' "$?" ) | base64`)}`}function Ae(n,t,e){let r=Buffer.from(t.replace(/\s+/g,""),"base64").toString("utf-8").split("\0"),o=r.pop()??"",a=/^STATUS:(\d+)$/.exec(o);if(!a)throw new Error(`daytona: the listing of ${n} ended without find's status (${o.slice(0,40)})`);if(a[1]!=="0")throw new Error(`daytona: find exited ${a[1]} listing ${n}`);let i=[];for(let d=0;d+Y<=r.length;d+=Y){let[l,g,c,f,u,m,p,w]=r.slice(d,d+Y),y=l==="f"?"file":l==="d"?"dir":l==="l"?"symlink":"other",x={name:w,path:e==="children"?ft(n,w):n,type:y,size:Number(g),mtime:F(Number(c)),mode:gt(f),owner:u,group:m};y==="symlink"&&(x.target=p),i.push(x);}return i}var nt=class{constructor(t,e){this.sandbox=t;this.commands=e;}async read(t){let e=new Uint8Array(await this.sandbox.fs.downloadFile(t));if(!e.includes(0))try{return new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(e)}catch{}return e}async write(t,e){let s;if(typeof e=="string")s=Buffer.from(e,"utf-8");else if(Buffer.isBuffer(e))s=e;else if(e instanceof ArrayBuffer)s=Buffer.from(e);else if(e instanceof Uint8Array)s=Buffer.from(e);else throw new Error(`Unsupported content type: ${typeof e}`);await this.sandbox.fs.uploadFile(s,t);}async writeBatch(t){let e=t.map(s=>{let r;if(typeof s.data=="string")r=Buffer.from(s.data,"utf-8");else if(Buffer.isBuffer(s.data))r=s.data;else if(s.data instanceof ArrayBuffer)r=Buffer.from(s.data);else if(s.data instanceof Uint8Array)r=Buffer.from(s.data);else throw new Error(`Unsupported content type: ${typeof s.data}`);return {source:r,destination:s.path}});await this.sandbox.fs.uploadFiles(e);}async writeFromPath(t,e){await this.sandbox.fs.uploadFile(e,t);}async makeDir(t){await this.sandbox.fs.createFolder(t,"755");}async exists(t){try{let e=ie(t),s=de(t);return (await this.sandbox.fs.listFiles(e)).some(o=>o.name===s)}catch{return false}}async list(t){return this.findListing(t,"children")}async stat(t){let[e]=await this.findListing(t,"self");if(!e)throw new A(t,"daytona");return e}async findListing(t,e){let s=await this.commands.run(ve(t,e));if(s.exitCode===M)throw new A(t,"daytona");if(s.exitCode===R)throw new Error(`daytona: ${t} is not a directory`);if(s.exitCode!==0)throw new Error(`daytona: listing ${t} failed (exit ${s.exitCode}): ${s.stderr.trim()}`);try{return Ae(t,s.stdout,e)}catch(r){throw /printf|unrecognized|invalid option/i.test(s.stderr)?new k("files.list","daytona",`this image's find has no -printf (GNU findutils is needed to list entries as themselves): ${s.stderr.trim()}`):r}}async readRange(t,e){if(U(e),e.length===0)return new Uint8Array(0);let s=await this.sandbox.downloadUrl(t);return mt(s,e,{provider:"daytona",path:t,timeoutMs:Se})}async watchDir(t,e,s){throw new k("files.watchDir","daytona","the Daytona SDK has no filesystem watcher; poll files.list() on the directories you have open")}async remove(t){await this.sandbox.fs.deleteFile(t,true);}async rename(t,e){await this.sandbox.fs.moveFiles(t,e);}},P=class{constructor(t,e,s){this.sandbox=t;let r=new et(t,e,s);this.commands=r,this.files=new nt(t,r);}commands;files;get sandboxId(){return this.sandbox.id}async getHost(t){return (await this.sandbox.getPreviewLink(t)).url}async isRunning(){try{await this.sandbox.refreshData();}catch{return false}return this.sandbox.state==="started"}async getInfo(){return await this.sandbox.refreshData(),at(this.sandbox)}async metrics(){let t=await this.sandbox.getMetricsLatest();return {cpuPct:t.cpuUsedPct,memUsedMb:t.memUsed/G,memTotalMb:t.memTotal/G,diskUsedMb:t.diskUsed/G,sampledAt:F(t.timestamp),source:"daytona:getMetricsLatest"}}async updateNetwork(t){let e=Ft(t);try{await this.sandbox.updateNetworkSettings(e);}catch(s){throw Bt(s)?new b("org-tier-forbidden",`Daytona refused to change this sandbox's network policy: organizations on Tier 1 or Tier 2 cannot override network policy at the sandbox level. Raise the organization's tier, or run this workload on a provider whose plan permits runtime policy changes (underlying error: ${s instanceof Error?s.message:String(s)}).`):s}}async kill(){await this.sandbox.delete();}async pause(){await this.sandbox.stop();}},st=class{providerType="daytona";name="Daytona";client;defaultTimeoutMs;snapshotName;sandboxUsers=new Map;managedStream;snapshotConflictTiming={timeoutMs:kt,pollMs:It};snapshotDeleteTiming={timeoutMs:Ct,pollMs:Ot};constructor(t){let e={apiKey:t.apiKey,apiUrl:t.apiUrl,target:t.target,useDeprecatedPolling:true};if(t.retryCreateRequest&&!t.managedToolboxUrl)throw new Error("retryCreateRequest rides the managed door: set managedToolboxUrl with it.");this.client=t.managedToolboxUrl?new tt(e,t.managedToolboxUrl,t.retryCreateRequest):new sdk.Daytona(e),t.managedToolboxUrl&&(this.managedStream={toolboxUrl:t.managedToolboxUrl,apiKey:t.apiKey}),this.defaultTimeoutMs=t.defaultTimeoutMs??36e5,this.snapshotName=t.snapshotName??(t.managedToolboxUrl?"evolve-all":`evolve-all-${C}`);}async create(t){if(t.idleTimeoutMs!==void 0)throw new H;if(t.bootCommand!==void 0)throw new j;for(let u of t.phaseNetworkPolicies??[])O(u);let e=O(t.network),s=t.user,r=s&&s!=="root"?s:void 0,o=t.timeoutMs??this.defaultTimeoutMs,a=Math.max(1,Math.ceil(o/6e4)),i=t.image||this.snapshotName,d={envVars:t.envs,labels:t.metadata,autoStopInterval:a,autoDeleteInterval:ne,...r?{user:r}:{},...e},l,g=t.resources!==void 0&&(t.resources.cpu!==void 0||t.resources.memory!==void 0||t.resources.disk!==void 0||t.resources.gpu!==void 0||t.resources.gpuTypes!==void 0);if(this.managedStream){if(g)throw new I(i);let u=await this.client.create({snapshot:i,...d},{timeout:600});return t.workingDirectory&&await u.fs.createFolder(t.workingDirectory,"755"),s&&this.sandboxUsers.set(u.id,s),new P(u,s,this.managedStream)}let c,f;try{let u=await this.client.snapshot.get(i),m=u?.state;if(u&&Mt.has(m??"")&&(c=m),u&&(m==="active"||m==="inactive")&&g)throw new I(i);if(u&&m==="inactive"&&(m=(await z(this.client,i,u)).state),u&&At.has(m??"")&&(K(i)?f=await Pt(this.client,i,u,this.snapshotDeleteTiming):console.warn(`[daytona] Snapshot "${i}" is dead (state "${m}") but this provider cannot rebuild that name \u2014 delete it in the Daytona dashboard (Snapshots page), or rebuild it with the tooling that created it.`)),u&&m==="active")console.log(`[daytona] Using cached snapshot: ${i}`),l=await this.client.create({snapshot:i,...d},{timeout:600});else throw new Error("Snapshot not active")}catch(u){if(u instanceof I||u instanceof v)throw u;let m=rt[i]??i,p=c!==void 0&&!g;p?console.log(`[daytona] Snapshot "${i}" is mid-build (state "${c}") \u2014 joining that build rather than starting a second one.`):c!==void 0?console.log(`[daytona] Snapshot "${i}" is mid-build (state "${c}") and cannot carry the requested sizing \u2014 pulling image directly instead: ${m}`):(console.log(`[daytona] Snapshot "${i}" not found, building from image: ${m}`),console.log("[daytona] First run will take a few minutes (this only happens once)..."));try{if(f===!1)throw new Error(`dead snapshot "${i}" was not confirmed removed \u2014 not racing its removal`);let w=()=>this.client.snapshot.create({name:i,image:sdk.Image.base(m),resources:{cpu:t.resources?.cpu??4,memory:t.resources?.memory??4,disk:t.resources?.disk??10,...(t.resources?.gpu??0)>0?{gpu:t.resources.gpu}:{},...t.resources?.gpuTypes?.length?{gpuType:t.resources.gpuTypes}:{}}},{onLogs:x=>console.log(`[daytona] ${x}`)}),y=async()=>{await w(),console.log(`[daytona] Snapshot "${i}" ready (rebuilt here after a dead build).`);};if(c!==void 0){if(!p)throw new Error(`snapshot "${i}" is mid-build (state "${c}") and cannot be resized`);await this.joinInFlightSnapshotBuild(i)&&await y();}else try{await w(),console.log(`[daytona] Snapshot "${i}" ready (built here).`);}catch(x){if(!Lt(x)||g)throw x;await this.joinInFlightSnapshotBuild(i)&&await y();}l=await this.client.create({snapshot:i,...d},{timeout:600});}catch(w){if(w instanceof T||w instanceof v)throw w;console.warn(`[daytona] Snapshot creation failed, falling back to direct image: ${w instanceof Error?w.message:w}`);try{l=await this.client.create({image:m,...d,resources:{cpu:t.resources?.cpu??4,memory:t.resources?.memory??4,disk:t.resources?.disk??10,...(t.resources?.gpu??0)>0?{gpu:t.resources.gpu}:{},...t.resources?.gpuTypes?.length?{gpuType:t.resources.gpuTypes}:{}}},{timeout:600,onSnapshotCreateLogs:y=>console.log(`[daytona] ${y}`)});}catch(y){throw Yt(m)?new W(m,y):y}}}return t.workingDirectory&&await l.fs.createFolder(t.workingDirectory,"755"),s&&this.sandboxUsers.set(l.id,s),new P(l,s,this.managedStream)}async joinInFlightSnapshotBuild(t){let e=await Rt(this.client,t,this.snapshotConflictTiming);if(e===_t)return true;if(e.state==="active")return console.log(`[daytona] Snapshot "${t}" ready (built by another process) \u2014 reusing it.`),false;if(e.state==="inactive")return await z(this.client,t,e),console.log(`[daytona] Snapshot "${t}" ready (built by another process) \u2014 reusing it.`),false;if(At.has(e.state??"")&&K(t)&&await Pt(this.client,t,e,this.snapshotDeleteTiming))return true;throw new Error(`the in-flight build of snapshot "${t}" ended in state "${e.state??"unknown"}"`)}async connect(t,e){let s=await this.client.get(t);return s.state!=="started"&&await s.start(),new P(s,this.sandboxUsers.get(t),this.managedStream)}async inspect(t,e){let s=await this.getSandboxRecord(t);if(s.state!=="started")throw new _(t,"daytona",s.state??"unknown");return new P(s,e?.user??this.sandboxUsers.get(t),this.managedStream)}async getSandboxRecord(t){return this.client.get(t)}async list(t){let e=await this.paginate(t);if(e.error&&!e.stoppedAtLimit)throw new Error(e.error);return e.sandboxes}async listAll(t){let{stoppedAtLimit:e,...s}=await this.paginate(t);return s}async paginate(t){return qt(this.listStream(t),t)}listStream(t){let e=t?.state?Pe(t.state):void 0,s={limit:ae,...t?.metadata?{labels:t.metadata}:{},...e&&e.length>0?{states:e}:{}};return this.client.list(s)}};function Pe(n){let t=[];for(let e of n)e==="running"&&t.push("started"),e==="paused"&&t.push("stopped","archived","paused");return t}async function qt(n,t){let e=t?.limit,s=[],r=0,o=new Set;try{for await(let a of n){if(e!==void 0&&s.length>=e)return {sandboxes:s,complete:!1,pagesFetched:r,stoppedAtLimit:!0,error:`stopped at the requested limit of ${e} with more sandboxes available`};if(r+=1,r>B)return {sandboxes:s,complete:!1,pagesFetched:B,stoppedAtLimit:!1,error:`sandbox list exceeded ${B} sandboxes scanned`};if(t?.state){let i=Gt(a.state);if(i===void 0||!t.state.includes(i))continue}o.has(a.id)||(o.add(a.id),s.push(at(a)));}}catch(a){return {sandboxes:s,complete:false,pagesFetched:r,stoppedAtLimit:false,error:`sandbox list failed: ${a instanceof Error?a.message:String(a)}`}}return {sandboxes:s,complete:true,pagesFetched:r,stoppedAtLimit:false}}var Ne=qt;function Ue(n={}){let t=n.apiKey??process.env.DAYTONA_API_KEY;if(!t)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 st({...n,apiKey:t})}var Fe=Z,Be=V,Ye=O,Ge=Ft,We=Bt,je=Yt,He=at,qe=Gt,ze=z,Ke=Rt,Xe=Lt,Ve=K,Qe=rt,Je=Q,Ze=Nt,tn=D,en=J,nn=it,sn=jt,rn=dt,on=P,G=1024*1024;
|
|
9
|
+
exports.DAYTONA_AUTO_DELETE_GRACE_MINUTES=ne;exports.DAYTONA_BOOT_LABEL=St;exports.DAYTONA_BOOT_POLL_MS=ce;exports.DAYTONA_LIST_PAGE_SIZE=ae;exports.DAYTONA_MAX_DOMAIN_ALLOWLIST=yt;exports.DAYTONA_MAX_LIST_SCAN=B;exports.DAYTONA_MAX_NETWORK_ALLOWLIST=wt;exports.DAYTONA_SNAPSHOT_ACTIVATE_TIMEOUT_MS=se;exports.DAYTONA_SNAPSHOT_CONFLICT_TIMEOUT_MS=kt;exports.DAYTONA_SNAPSHOT_GONE=_t;exports.DAYTONA_STREAM_TIMINGS=oe;exports.DaytonaBootAbortedError=q;exports.DaytonaBootCommandError=j;exports.DaytonaCommands=et;exports.DaytonaFiles=nt;exports.DaytonaGpuTypeError=bt;exports.DaytonaIdleTimeoutError=H;exports.DaytonaImagePullError=W;exports.DaytonaNetworkPolicyError=b;exports.DaytonaProvider=st;exports.DaytonaResourcesError=I;exports.DaytonaSnapshotActivationError=v;exports.DaytonaSnapshotConflictError=T;exports.EVOLVE_IMAGE_VERSION=C;exports.SandboxFeatureUnsupportedError=k;exports.SandboxNotRunningError=_;exports.SandboxPathNotFoundError=A;exports._testActivateSnapshot=ze;exports._testCollectSandboxStream=Ne;exports._testCreateLogDemuxer=nn;exports._testCreateSentinelFilter=en;exports._testDaytonaSandboxImplCtor=on;exports._testDaytonaStateToEvolveState=qe;exports._testFollowManagedSessionLogs=sn;exports._testImageMap=Qe;exports._testImageRegistryHost=je;exports._testIsNetworkPolicyTierRefusal=We;exports._testIsSnapshotNameConflict=Xe;exports._testMapNetworkPolicy=Ye;exports._testMapNetworkPolicyForUpdate=Ge;exports._testProviderCanRebuildSnapshot=Ve;exports._testReadCommandStreams=rn;exports._testSettledStreams=tn;exports._testStripEndOfOutputSentinel=Ze;exports._testToSandboxInfo=He;exports._testWaitForSnapshotConflictWinner=Ke;exports._testWithEndOfOutputSentinel=Je;exports._testWithInBoxTimeout=Be;exports._testWrapCommand=Fe;exports.createDaytonaProvider=Ue;exports.createSandboxObserved=Re;exports.daytonaBootPhaseOf=xt;exports.isSandboxFeatureUnsupportedError=Xt;exports.isSandboxNotRunningError=Qt;exports.isSandboxPathNotFoundError=Vt;exports.mapNetworkPolicy=O;
|
package/dist/index.d.cts
CHANGED
|
@@ -36,7 +36,7 @@ declare function isSandboxNotRunningError(err: unknown): err is SandboxNotRunnin
|
|
|
36
36
|
* packages/daytona/tests/unit/daytona-image-version.test.ts fails the
|
|
37
37
|
* suite whenever this checked-in copy is stale.
|
|
38
38
|
*/
|
|
39
|
-
declare const EVOLVE_IMAGE_VERSION = "c-
|
|
39
|
+
declare const EVOLVE_IMAGE_VERSION = "c-73196ff07944";
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Daytona Sandbox Provider
|
|
@@ -973,6 +973,8 @@ interface SandboxCreateOptions {
|
|
|
973
973
|
user?: string;
|
|
974
974
|
/** Home directory used by the SDK for agent config paths; not consumed by the provider. */
|
|
975
975
|
homeDir?: string;
|
|
976
|
+
/** Account the SDK hands its agent config files to; not consumed by the provider. */
|
|
977
|
+
homeOwner?: string;
|
|
976
978
|
}
|
|
977
979
|
/** Options for listing sandboxes */
|
|
978
980
|
interface SandboxListOptions {
|
|
@@ -1059,6 +1061,8 @@ interface SandboxProvider {
|
|
|
1059
1061
|
/** The same enumeration for fleet bookkeeping: never throws, reports completeness. */
|
|
1060
1062
|
listAll(options?: SandboxListOptions): Promise<SandboxListPage>;
|
|
1061
1063
|
}
|
|
1064
|
+
/** Wraps the one request that creates a box, for the SDK to retry a door's 429/503 before any box exists. */
|
|
1065
|
+
type CreateRequestRetry = <T>(send: () => Promise<T>) => Promise<T>;
|
|
1062
1066
|
interface DaytonaConfig {
|
|
1063
1067
|
/** Daytona API key. Default: reads from DAYTONA_API_KEY env var */
|
|
1064
1068
|
apiKey?: string;
|
|
@@ -1084,6 +1088,8 @@ interface DaytonaConfig {
|
|
|
1084
1088
|
* @internal
|
|
1085
1089
|
*/
|
|
1086
1090
|
managedToolboxUrl?: string;
|
|
1091
|
+
/** @internal Resolved by the Evolve SDK with managedToolboxUrl; unset means the create request is sent once. */
|
|
1092
|
+
retryCreateRequest?: CreateRequestRetry;
|
|
1087
1093
|
}
|
|
1088
1094
|
interface ResolvedDaytonaConfig {
|
|
1089
1095
|
apiKey: string;
|
|
@@ -1092,6 +1098,7 @@ interface ResolvedDaytonaConfig {
|
|
|
1092
1098
|
defaultTimeoutMs?: number;
|
|
1093
1099
|
snapshotName?: string;
|
|
1094
1100
|
managedToolboxUrl?: string;
|
|
1101
|
+
retryCreateRequest?: CreateRequestRetry;
|
|
1095
1102
|
}
|
|
1096
1103
|
/** What a managed sandbox's streaming log follow needs to reach the Dashboard. */
|
|
1097
1104
|
interface ManagedStreamContext {
|
|
@@ -1175,6 +1182,7 @@ declare class DaytonaCommands implements SandboxCommands {
|
|
|
1175
1182
|
* but not closed; the ephemeral session's delete is what ends it.
|
|
1176
1183
|
*/
|
|
1177
1184
|
private followLogs;
|
|
1185
|
+
private readSettledLogs;
|
|
1178
1186
|
run(command: string, options?: SandboxRunOptions): Promise<SandboxCommandResult>;
|
|
1179
1187
|
/**
|
|
1180
1188
|
* WHAT SAYS A STREAMED RUN IS OVER: the command's record, never the follow.
|
|
@@ -1456,4 +1464,4 @@ type _testDaytonaSandboxImpl = DaytonaSandboxImpl;
|
|
|
1456
1464
|
/** The constructor, for the metrics unit test (a vendor sandbox double goes in). */
|
|
1457
1465
|
declare const _testDaytonaSandboxImplCtor: typeof DaytonaSandboxImpl;
|
|
1458
1466
|
|
|
1459
|
-
export { DAYTONA_AUTO_DELETE_GRACE_MINUTES, DAYTONA_BOOT_LABEL, DAYTONA_BOOT_POLL_MS, DAYTONA_LIST_PAGE_SIZE, DAYTONA_MAX_DOMAIN_ALLOWLIST, DAYTONA_MAX_LIST_SCAN, DAYTONA_MAX_NETWORK_ALLOWLIST, DAYTONA_SNAPSHOT_ACTIVATE_TIMEOUT_MS, DAYTONA_SNAPSHOT_CONFLICT_TIMEOUT_MS, DAYTONA_SNAPSHOT_GONE, DAYTONA_STREAM_TIMINGS, DaytonaBootAbortedError, type DaytonaBootClient, DaytonaBootCommandError, type DaytonaBootPhase, type DaytonaBootProgress, type DaytonaCommandRunner, DaytonaCommands, type DaytonaConfig, DaytonaFiles, DaytonaGpuTypeError, DaytonaIdleTimeoutError, DaytonaImagePullError, DaytonaNetworkPolicyError, type DaytonaNetworkPolicyReason, type DaytonaObservedCreateOptions, DaytonaProvider, DaytonaResourcesError, DaytonaSnapshotActivationError, DaytonaSnapshotConflictError, type DaytonaStreamTimings, EVOLVE_IMAGE_VERSION, type FileInfo, type FileRange, type FilesystemEvent, type ProcessInfo, type SandboxCommandHandle, type SandboxCommandResult, type SandboxCommands, type SandboxCreateOptions, SandboxFeatureUnsupportedError, type SandboxFiles, type SandboxInfo, type SandboxInspectOptions, type SandboxInstance, type SandboxListOptions, type SandboxListPage, type SandboxMetrics, SandboxNotRunningError, SandboxPathNotFoundError, type SandboxProvider, type SandboxResources, type SandboxRunOptions, type SandboxSpawnOptions, type WatchHandle, type WatchOptions, _testActivateSnapshot, _testCollectSandboxStream, _testCreateLogDemuxer, _testCreateSentinelFilter, type _testDaytonaSandboxImpl, _testDaytonaSandboxImplCtor, _testDaytonaStateToEvolveState, _testFollowManagedSessionLogs, _testImageMap, _testImageRegistryHost, _testIsNetworkPolicyTierRefusal, _testIsSnapshotNameConflict, _testMapNetworkPolicy, _testMapNetworkPolicyForUpdate, _testProviderCanRebuildSnapshot, _testReadCommandStreams, _testSettledStreams, _testStripEndOfOutputSentinel, _testToSandboxInfo, _testWaitForSnapshotConflictWinner, _testWithEndOfOutputSentinel, _testWithInBoxTimeout, _testWrapCommand, createDaytonaProvider, createSandboxObserved, daytonaBootPhaseOf, isSandboxFeatureUnsupportedError, isSandboxNotRunningError, isSandboxPathNotFoundError, mapNetworkPolicy };
|
|
1467
|
+
export { type CreateRequestRetry, DAYTONA_AUTO_DELETE_GRACE_MINUTES, DAYTONA_BOOT_LABEL, DAYTONA_BOOT_POLL_MS, DAYTONA_LIST_PAGE_SIZE, DAYTONA_MAX_DOMAIN_ALLOWLIST, DAYTONA_MAX_LIST_SCAN, DAYTONA_MAX_NETWORK_ALLOWLIST, DAYTONA_SNAPSHOT_ACTIVATE_TIMEOUT_MS, DAYTONA_SNAPSHOT_CONFLICT_TIMEOUT_MS, DAYTONA_SNAPSHOT_GONE, DAYTONA_STREAM_TIMINGS, DaytonaBootAbortedError, type DaytonaBootClient, DaytonaBootCommandError, type DaytonaBootPhase, type DaytonaBootProgress, type DaytonaCommandRunner, DaytonaCommands, type DaytonaConfig, DaytonaFiles, DaytonaGpuTypeError, DaytonaIdleTimeoutError, DaytonaImagePullError, DaytonaNetworkPolicyError, type DaytonaNetworkPolicyReason, type DaytonaObservedCreateOptions, DaytonaProvider, DaytonaResourcesError, DaytonaSnapshotActivationError, DaytonaSnapshotConflictError, type DaytonaStreamTimings, EVOLVE_IMAGE_VERSION, type FileInfo, type FileRange, type FilesystemEvent, type ProcessInfo, type SandboxCommandHandle, type SandboxCommandResult, type SandboxCommands, type SandboxCreateOptions, SandboxFeatureUnsupportedError, type SandboxFiles, type SandboxInfo, type SandboxInspectOptions, type SandboxInstance, type SandboxListOptions, type SandboxListPage, type SandboxMetrics, SandboxNotRunningError, SandboxPathNotFoundError, type SandboxProvider, type SandboxResources, type SandboxRunOptions, type SandboxSpawnOptions, type WatchHandle, type WatchOptions, _testActivateSnapshot, _testCollectSandboxStream, _testCreateLogDemuxer, _testCreateSentinelFilter, type _testDaytonaSandboxImpl, _testDaytonaSandboxImplCtor, _testDaytonaStateToEvolveState, _testFollowManagedSessionLogs, _testImageMap, _testImageRegistryHost, _testIsNetworkPolicyTierRefusal, _testIsSnapshotNameConflict, _testMapNetworkPolicy, _testMapNetworkPolicyForUpdate, _testProviderCanRebuildSnapshot, _testReadCommandStreams, _testSettledStreams, _testStripEndOfOutputSentinel, _testToSandboxInfo, _testWaitForSnapshotConflictWinner, _testWithEndOfOutputSentinel, _testWithInBoxTimeout, _testWrapCommand, createDaytonaProvider, createSandboxObserved, daytonaBootPhaseOf, isSandboxFeatureUnsupportedError, isSandboxNotRunningError, isSandboxPathNotFoundError, mapNetworkPolicy };
|
package/dist/index.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ declare function isSandboxNotRunningError(err: unknown): err is SandboxNotRunnin
|
|
|
36
36
|
* packages/daytona/tests/unit/daytona-image-version.test.ts fails the
|
|
37
37
|
* suite whenever this checked-in copy is stale.
|
|
38
38
|
*/
|
|
39
|
-
declare const EVOLVE_IMAGE_VERSION = "c-
|
|
39
|
+
declare const EVOLVE_IMAGE_VERSION = "c-73196ff07944";
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Daytona Sandbox Provider
|
|
@@ -973,6 +973,8 @@ interface SandboxCreateOptions {
|
|
|
973
973
|
user?: string;
|
|
974
974
|
/** Home directory used by the SDK for agent config paths; not consumed by the provider. */
|
|
975
975
|
homeDir?: string;
|
|
976
|
+
/** Account the SDK hands its agent config files to; not consumed by the provider. */
|
|
977
|
+
homeOwner?: string;
|
|
976
978
|
}
|
|
977
979
|
/** Options for listing sandboxes */
|
|
978
980
|
interface SandboxListOptions {
|
|
@@ -1059,6 +1061,8 @@ interface SandboxProvider {
|
|
|
1059
1061
|
/** The same enumeration for fleet bookkeeping: never throws, reports completeness. */
|
|
1060
1062
|
listAll(options?: SandboxListOptions): Promise<SandboxListPage>;
|
|
1061
1063
|
}
|
|
1064
|
+
/** Wraps the one request that creates a box, for the SDK to retry a door's 429/503 before any box exists. */
|
|
1065
|
+
type CreateRequestRetry = <T>(send: () => Promise<T>) => Promise<T>;
|
|
1062
1066
|
interface DaytonaConfig {
|
|
1063
1067
|
/** Daytona API key. Default: reads from DAYTONA_API_KEY env var */
|
|
1064
1068
|
apiKey?: string;
|
|
@@ -1084,6 +1088,8 @@ interface DaytonaConfig {
|
|
|
1084
1088
|
* @internal
|
|
1085
1089
|
*/
|
|
1086
1090
|
managedToolboxUrl?: string;
|
|
1091
|
+
/** @internal Resolved by the Evolve SDK with managedToolboxUrl; unset means the create request is sent once. */
|
|
1092
|
+
retryCreateRequest?: CreateRequestRetry;
|
|
1087
1093
|
}
|
|
1088
1094
|
interface ResolvedDaytonaConfig {
|
|
1089
1095
|
apiKey: string;
|
|
@@ -1092,6 +1098,7 @@ interface ResolvedDaytonaConfig {
|
|
|
1092
1098
|
defaultTimeoutMs?: number;
|
|
1093
1099
|
snapshotName?: string;
|
|
1094
1100
|
managedToolboxUrl?: string;
|
|
1101
|
+
retryCreateRequest?: CreateRequestRetry;
|
|
1095
1102
|
}
|
|
1096
1103
|
/** What a managed sandbox's streaming log follow needs to reach the Dashboard. */
|
|
1097
1104
|
interface ManagedStreamContext {
|
|
@@ -1175,6 +1182,7 @@ declare class DaytonaCommands implements SandboxCommands {
|
|
|
1175
1182
|
* but not closed; the ephemeral session's delete is what ends it.
|
|
1176
1183
|
*/
|
|
1177
1184
|
private followLogs;
|
|
1185
|
+
private readSettledLogs;
|
|
1178
1186
|
run(command: string, options?: SandboxRunOptions): Promise<SandboxCommandResult>;
|
|
1179
1187
|
/**
|
|
1180
1188
|
* WHAT SAYS A STREAMED RUN IS OVER: the command's record, never the follow.
|
|
@@ -1456,4 +1464,4 @@ type _testDaytonaSandboxImpl = DaytonaSandboxImpl;
|
|
|
1456
1464
|
/** The constructor, for the metrics unit test (a vendor sandbox double goes in). */
|
|
1457
1465
|
declare const _testDaytonaSandboxImplCtor: typeof DaytonaSandboxImpl;
|
|
1458
1466
|
|
|
1459
|
-
export { DAYTONA_AUTO_DELETE_GRACE_MINUTES, DAYTONA_BOOT_LABEL, DAYTONA_BOOT_POLL_MS, DAYTONA_LIST_PAGE_SIZE, DAYTONA_MAX_DOMAIN_ALLOWLIST, DAYTONA_MAX_LIST_SCAN, DAYTONA_MAX_NETWORK_ALLOWLIST, DAYTONA_SNAPSHOT_ACTIVATE_TIMEOUT_MS, DAYTONA_SNAPSHOT_CONFLICT_TIMEOUT_MS, DAYTONA_SNAPSHOT_GONE, DAYTONA_STREAM_TIMINGS, DaytonaBootAbortedError, type DaytonaBootClient, DaytonaBootCommandError, type DaytonaBootPhase, type DaytonaBootProgress, type DaytonaCommandRunner, DaytonaCommands, type DaytonaConfig, DaytonaFiles, DaytonaGpuTypeError, DaytonaIdleTimeoutError, DaytonaImagePullError, DaytonaNetworkPolicyError, type DaytonaNetworkPolicyReason, type DaytonaObservedCreateOptions, DaytonaProvider, DaytonaResourcesError, DaytonaSnapshotActivationError, DaytonaSnapshotConflictError, type DaytonaStreamTimings, EVOLVE_IMAGE_VERSION, type FileInfo, type FileRange, type FilesystemEvent, type ProcessInfo, type SandboxCommandHandle, type SandboxCommandResult, type SandboxCommands, type SandboxCreateOptions, SandboxFeatureUnsupportedError, type SandboxFiles, type SandboxInfo, type SandboxInspectOptions, type SandboxInstance, type SandboxListOptions, type SandboxListPage, type SandboxMetrics, SandboxNotRunningError, SandboxPathNotFoundError, type SandboxProvider, type SandboxResources, type SandboxRunOptions, type SandboxSpawnOptions, type WatchHandle, type WatchOptions, _testActivateSnapshot, _testCollectSandboxStream, _testCreateLogDemuxer, _testCreateSentinelFilter, type _testDaytonaSandboxImpl, _testDaytonaSandboxImplCtor, _testDaytonaStateToEvolveState, _testFollowManagedSessionLogs, _testImageMap, _testImageRegistryHost, _testIsNetworkPolicyTierRefusal, _testIsSnapshotNameConflict, _testMapNetworkPolicy, _testMapNetworkPolicyForUpdate, _testProviderCanRebuildSnapshot, _testReadCommandStreams, _testSettledStreams, _testStripEndOfOutputSentinel, _testToSandboxInfo, _testWaitForSnapshotConflictWinner, _testWithEndOfOutputSentinel, _testWithInBoxTimeout, _testWrapCommand, createDaytonaProvider, createSandboxObserved, daytonaBootPhaseOf, isSandboxFeatureUnsupportedError, isSandboxNotRunningError, isSandboxPathNotFoundError, mapNetworkPolicy };
|
|
1467
|
+
export { type CreateRequestRetry, DAYTONA_AUTO_DELETE_GRACE_MINUTES, DAYTONA_BOOT_LABEL, DAYTONA_BOOT_POLL_MS, DAYTONA_LIST_PAGE_SIZE, DAYTONA_MAX_DOMAIN_ALLOWLIST, DAYTONA_MAX_LIST_SCAN, DAYTONA_MAX_NETWORK_ALLOWLIST, DAYTONA_SNAPSHOT_ACTIVATE_TIMEOUT_MS, DAYTONA_SNAPSHOT_CONFLICT_TIMEOUT_MS, DAYTONA_SNAPSHOT_GONE, DAYTONA_STREAM_TIMINGS, DaytonaBootAbortedError, type DaytonaBootClient, DaytonaBootCommandError, type DaytonaBootPhase, type DaytonaBootProgress, type DaytonaCommandRunner, DaytonaCommands, type DaytonaConfig, DaytonaFiles, DaytonaGpuTypeError, DaytonaIdleTimeoutError, DaytonaImagePullError, DaytonaNetworkPolicyError, type DaytonaNetworkPolicyReason, type DaytonaObservedCreateOptions, DaytonaProvider, DaytonaResourcesError, DaytonaSnapshotActivationError, DaytonaSnapshotConflictError, type DaytonaStreamTimings, EVOLVE_IMAGE_VERSION, type FileInfo, type FileRange, type FilesystemEvent, type ProcessInfo, type SandboxCommandHandle, type SandboxCommandResult, type SandboxCommands, type SandboxCreateOptions, SandboxFeatureUnsupportedError, type SandboxFiles, type SandboxInfo, type SandboxInspectOptions, type SandboxInstance, type SandboxListOptions, type SandboxListPage, type SandboxMetrics, SandboxNotRunningError, SandboxPathNotFoundError, type SandboxProvider, type SandboxResources, type SandboxRunOptions, type SandboxSpawnOptions, type WatchHandle, type WatchOptions, _testActivateSnapshot, _testCollectSandboxStream, _testCreateLogDemuxer, _testCreateSentinelFilter, type _testDaytonaSandboxImpl, _testDaytonaSandboxImplCtor, _testDaytonaStateToEvolveState, _testFollowManagedSessionLogs, _testImageMap, _testImageRegistryHost, _testIsNetworkPolicyTierRefusal, _testIsSnapshotNameConflict, _testMapNetworkPolicy, _testMapNetworkPolicyForUpdate, _testProviderCanRebuildSnapshot, _testReadCommandStreams, _testSettledStreams, _testStripEndOfOutputSentinel, _testToSandboxInfo, _testWaitForSnapshotConflictWinner, _testWithEndOfOutputSentinel, _testWithInBoxTimeout, _testWrapCommand, createDaytonaProvider, createSandboxObserved, daytonaBootPhaseOf, isSandboxFeatureUnsupportedError, isSandboxNotRunningError, isSandboxPathNotFoundError, mapNetworkPolicy };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {STDOUT_PREFIX_BYTES,STDERR_PREFIX_BYTES,MAX_PREFIX_LEN,Daytona,Image}from'@daytonaio/sdk';import {randomUUID}from'crypto';import'fs';var
|
|
2
|
-
`)){let p=
|
|
1
|
+
import {STDOUT_PREFIX_BYTES,STDERR_PREFIX_BYTES,MAX_PREFIX_LEN,Daytona,Image}from'@daytonaio/sdk';import {randomUUID}from'crypto';import'fs';var k=class extends Error{feature;provider;reason;constructor(t,e,s){super(`${e} does not support ${t}${s?`: ${s}`:""}`),this.name="SandboxFeatureUnsupportedError",this.feature=t,this.provider=e,this.reason=s;}},A=class extends Error{path;provider;constructor(t,e){super(`${e}: no such file or directory: ${t}`),this.name="SandboxPathNotFoundError",this.path=t,this.provider=e;}},_=class extends Error{sandboxId;provider;state;constructor(t,e,s){super(`${e} sandbox ${t} is not running (${s}); inspect never starts or resumes a sandbox`),this.name="SandboxNotRunningError",this.sandboxId=t,this.provider=e,this.state=s;}};function L(n,t){return !!n&&typeof n=="object"&&n.name===t}function Xt(n){return L(n,"SandboxFeatureUnsupportedError")}function Vt(n){return L(n,"SandboxPathNotFoundError")}function Qt(n){return L(n,"SandboxNotRunningError")}var M=2,R=20;function N(n){return `'${n.replace(/'/g,"'\\''")}'`}function U(n){if(!Number.isInteger(n.offset)||n.offset<0)throw new RangeError(`offset must be a non-negative integer, got ${n.offset}`);if(!Number.isInteger(n.length)||n.length<0)throw new RangeError(`length must be a non-negative integer, got ${n.length}`)}function gt(n){if(typeof n=="number")return ut((n&4095).toString(8));if(/^[0-7]{1,4}$/.test(n))return ut(n);throw new RangeError(`not an octal mode: ${n}`)}function ut(n){return n.padStart(4,"0")}function F(n){let t=n instanceof Date?n:typeof n=="number"?new Date(n*1e3):new Date(n);if(Number.isNaN(t.getTime()))throw new RangeError(`not a timestamp: ${String(n)}`);return t.toISOString()}function ft(n,t){return n.endsWith("/")?`${n}${t}`:`${n}/${t}`}async function mt(n,t,e){if(U(t),t.length===0)return new Uint8Array(0);let s=t.offset+t.length-1,r=await fetch(n,{headers:{Range:`bytes=${t.offset}-${s}`},signal:AbortSignal.timeout(e.timeoutMs)});if(r.status===206){let o=new Uint8Array(await r.arrayBuffer());return o.length>t.length?o.subarray(0,t.length):o}if(r.status===200)return Jt(r,t);if(r.status===416)return await r.body?.cancel().catch(()=>{}),new Uint8Array(0);throw await r.body?.cancel().catch(()=>{}),r.status===404?new A(e.path,e.provider):new Error(`${e.provider}: range read of ${e.path} failed (HTTP ${r.status})`)}async function Jt(n,t){if(!n.body)return new Uint8Array(0);let e=n.body.getReader(),s=[],r=0,o=0,a=t.offset+t.length;try{for(;;){let{done:l,value:g}=await e.read();if(l)break;let c=r;if(r+=g.length,r>t.offset){let f=Math.max(0,t.offset-c),u=Math.min(g.length,a-c);u>f&&(s.push(g.subarray(f,u)),o+=u-f);}if(r>=a)break}}finally{await e.cancel().catch(()=>{});}let i=new Uint8Array(o),d=0;for(let l of s)i.set(l,d),d+=l.length;return i}var C="c-73196ff07944";var rt={[`evolve-all-${C}`]:`evolvingmachines/evolve-all:${C}`,"evolve-all":"evolvingmachines/evolve-all"},ne=10,wt=10,yt=20,se=18e4,re=2e3,kt=6e5,It=5e3,oe={pollMinMs:250,pollMaxMs:2e3,drainMs:1e3,killGraceMs:15e3,settleMs:6e4},S=n=>new Promise(t=>setTimeout(t,Math.max(0,n))),ae=100,B=1e4;function ie(n){let t=n.lastIndexOf("/");return t>0?n.substring(0,t):"/"}function de(n){let t=n.lastIndexOf("/");return t>=0?n.substring(t+1):n}var b=class extends Error{reason;destination;constructor(t,e,s){super(e),this.name="DaytonaNetworkPolicyError",this.reason=t,this.destination=s;}},W=class extends Error{image;constructor(t,e){let s=e instanceof Error?e.message:String(e??"unknown error");super(`Failed to pull image "${t}" on Daytona: ${s}. Private registry images require the registry pre-registered in the Daytona dashboard (Registries page) before sandbox creation \u2014 Daytona has no per-call image pull secret; AWS ECR registrations name an IAM role Daytona assumes (no password). Register the registry at https://app.daytona.io, then retry. Also ensure the image is linux/amd64 and pinned to a tag or digest (floating tags like "latest" are rejected by Daytona's snapshot builder).`),this.name="DaytonaImagePullError",this.image=t;}},bt=class extends Error{snapshot;constructor(t){super(`Daytona cannot constrain the GPU type for "${t}": the snapshot already exists and pins its resources \u2014 pre-build a snapshot with the desired GPU type under its own name.`),this.name="DaytonaGpuTypeError",this.snapshot=t;}},I=class extends Error{snapshot;constructor(t){super(`Daytona snapshot "${t}" already exists and pins its cpu/memory/disk sizing \u2014 create-from-snapshot cannot resize it, so the requested \`resources\` cannot be enforced. Pre-build a snapshot with the desired sizing under its own name (sizing-addressed), or omit \`resources\` to accept the snapshot's pinned sizing.`),this.name="DaytonaResourcesError",this.snapshot=t;}},j=class extends Error{constructor(){super("Daytona takes no create-time boot command: it never runs an image entrypoint or any argv at boot (harbor daytona/environment.py:706-708 works around exactly that, starting dockerd by hand). The boot is already inert \u2014 run the process by exec after create."),this.name="DaytonaBootCommandError";}},H=class extends Error{constructor(){super("Daytona has no separate idle timeout: auto-stop IS its only clock and it already measures inactivity, so `timeoutMs` is what sets it (autoStopInterval). Set the inactivity bound with `timeoutMs`; a hard bound on the process itself is enforced in-box instead (see withInBoxTimeout)."),this.name="DaytonaIdleTimeoutError";}},le=new Set(["pending_build","building_snapshot","pulling_snapshot"]);function xt(n){return n!=null&&le.has(n)?"image_pull":"boot"}var q=class extends Error{phase;state;sandboxId;constructor(t,e,s){super(`Daytona sandbox boot abandoned during ${t} (provider state ${e??"not yet reported"}, sandbox ${s??"not yet created"})`),this.name="DaytonaBootAbortedError",this.phase=t,this.state=e,this.sandboxId=s;}},St="evolve_boot",ce=5e3,vt=30;async function Re(n,t,e={}){let s=randomUUID(),r=e.pollMs??ce,o=null,a=null,i=false,d=(u,m)=>{let p=u==="build_log"?"image_pull":xt(a);e.onProgress?.({signal:u,phase:p,state:a,sandboxId:o?.id??null,...m===void 0?{}:{line:m}});},l=n.create({...t,labels:{...t.labels??{},[St]:s}},{timeout:0,onSnapshotCreateLogs:u=>{for(let m of u.split(`
|
|
2
|
+
`)){let p=m.trimEnd();p.length>0&&d("build_log",p);}}});(async()=>{for(;!i;){try{if(o===null)for await(let m of n.list({labels:{[St]:s}})){o=m;break}else await o.refreshData();let u=o?.state??null;u!==a&&(a=u,d("state"));}catch{}i||await S(r);}})();let c=()=>{let u=new q(xt(a),a,o?.id??null);return l.then(m=>m.delete(vt).catch(()=>{}),()=>{}),o!==null&&o.delete(vt).catch(()=>{}),u},f=new Promise((u,m)=>{let p=e.signal;if(p){if(p.aborted){m(c());return}p.addEventListener("abort",()=>{i||m(c());},{once:true});}});try{return await Promise.race([l,f])}finally{i=true;}}var v=class extends Error{snapshot;constructor(t,e){super(`Daytona snapshot "${t}" exists but could not be activated: ${e}. Daytona deactivates snapshots unused for 2 weeks; activation normally completes in seconds. Retry, or activate it manually in the Daytona dashboard (Snapshots page).`),this.name="DaytonaSnapshotActivationError",this.snapshot=t;}};async function z(n,t,e,s){let r=s?.timeoutMs??se,o=s?.pollMs??re;console.log(`[daytona] Snapshot "${t}" is inactive (unused for 2+ weeks) \u2014 reactivating...`);let a;try{a=await n.snapshot.activate(e);}catch(d){throw new v(t,`the activate call failed (${d instanceof Error?d.message:String(d)})`)}let i=Date.now()+r;for(;a?.state!=="active";){if(a?.state==="error"||a?.state==="build_failed")throw new v(t,`it entered state "${a.state}"`);if(Date.now()>=i)throw new v(t,`still "${a?.state??"unknown"}" after ${r}ms`);await S(o);try{a=await n.snapshot.get(t);}catch(d){throw new v(t,`the activation poll failed (${d instanceof Error?d.message:String(d)})`)}}return console.log(`[daytona] Snapshot "${t}" reactivated.`),a}var T=class extends Error{snapshot;constructor(t,e){super(`Daytona snapshot "${t}" is being created by another process and this run could not wait it out: ${e}.`),this.name="DaytonaSnapshotConflictError",this.snapshot=t;}},_t=Symbol("daytona-snapshot-gone"),Mt=new Set(["pending","pulling","building","snapshotting"]),ue=3;function ot(n){let t=n;return t?.status??t?.statusCode??t?.response?.status}var At=new Set(["error","build_failed"]),ge=new Set(["latest","lts","stable"]);function K(n){let t=rt[n]??n;if(t.includes("@"))return /@[a-z0-9]+(?:[.+_-][a-z0-9]+)*:[0-9a-f]{32,}$/i.test(t);let e=t.substring(t.lastIndexOf("/")+1),s=e.lastIndexOf(":");if(s<0)return false;let r=e.substring(s+1);return r===""?false:!ge.has(r.toLowerCase())}function X(n){let t=n.toLowerCase();return t.includes("not found")||t.includes("404")||t.includes("does not exist")}var Ct=6e4,Ot=2e3;async function Pt(n,t,e,s){let r=e.errorReason?`: ${e.errorReason}`:"";console.warn(`[daytona] Deleting dead snapshot "${t}" (state "${e.state??"unknown"}"${r}) before rebuilding it.`);try{await n.snapshot.delete(e);}catch(d){let l=d instanceof Error?d.message:String(d);if(!X(l))return console.warn(`[daytona] Could not delete dead snapshot "${t}" (${l}) \u2014 delete it in the Daytona dashboard (Snapshots page) to restore the fast path; falling back to a direct image pull for now.`),false}let o=s?.timeoutMs??Ct,a=s?.pollMs??Ot,i=Date.now()+o;for(;;){try{await n.snapshot.get(t);}catch(d){if(X(d instanceof Error?d.message:String(d)))return true}if(Date.now()>=i)return console.warn(`[daytona] Dead snapshot "${t}" still resolves ${o}ms after it was deleted \u2014 leaving the rebuild to the next run rather than racing the removal.`),false;await S(a);}}function Lt(n){if(ot(n)===409)return true;let t=(n instanceof Error?n.message:String(n)).toLowerCase();return t.includes("already exists")||t.includes("conflict")}function fe(n){let t=ot(n);if(t===401||t===403)return true;let e=(n instanceof Error?n.message:String(n)).toLowerCase();return e.includes("unauthorized")||e.includes("forbidden")||e.includes("status code 401")||e.includes("status code 403")}async function Rt(n,t,e){let s=e?.timeoutMs??kt,r=e?.pollMs??It;console.log(`[daytona] Snapshot "${t}" is already being created by another process \u2014 waiting for it (up to ${Math.round(s/1e3)}s) instead of pulling the image directly...`);let o=Date.now()+s,a,i="",d=0;for(;;){try{a=await n.snapshot.get(t),i="",d=0;}catch(l){a=void 0;let g=l instanceof Error?l.message:String(l);if(X(g))return console.log(`[daytona] Snapshot "${t}" no longer exists \u2014 the name is clear, building it.`),_t;if(fe(l))throw new T(t,`the poll was refused (${g}) \u2014 these credentials cannot read the snapshot, so waiting longer cannot help`);if(d=g===i?d+1:1,i=g,d>=ue)throw new T(t,`${d} consecutive polls failed the same way (${g}) \u2014 the control plane is not answering, so waiting longer cannot help`);console.warn(`[daytona] Poll of contended snapshot "${t}" failed, retrying: ${g}`);}if(a!==void 0&&!Mt.has(a.state??""))return a;if(Date.now()>=o)throw new T(t,`it was still "${a?.state??"unknown"}" after ${s}ms \u2014 retry once that build finishes, or check the snapshot in the Daytona dashboard (Snapshots page)`);await S(r);}}function V(n,t){if(!t||t<=0)return n;let e=Buffer.from(n).toString("base64"),s=`/tmp/.evolve-cmd-${Date.now()}-${Math.random().toString(36).slice(2,8)}.sh`;return `sh -c '${`echo ${e} | base64 -d > ${s} && [ -s ${s} ] || { rm -f ${s}; exit 126; }; if command -v timeout >/dev/null 2>&1; then timeout -k 10 ${t} bash ${s}; else bash ${s}; fi; rc=$?; rm -f ${s}; exit $rc`}'`}function Dt(){return `EVOLVE-EOS-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function Q(n,t){return n.trim()?`exec 9>&1 && { :
|
|
3
3
|
${n}
|
|
4
4
|
|
|
5
|
-
}; __evolve_eos=$?; printf '%s' '${t}' 2>/dev/null >&9; exec 9>&-; (exit $__evolve_eos)`:n}function
|
|
6
|
-
`)?n.slice(0,-(t.length+1)):n.endsWith(t)?n.slice(0,-t.length):n}function
|
|
7
|
-
`,s="",o=r=>{for(let a=Math.min(r.length,e.length);a>0;a--)if(e.startsWith(r.slice(r.length-a)))return a;return 0};return {push(r){s+=r;let a=o(s);a!==s.length&&(t(s.slice(0,s.length-a)),s=s.slice(s.length-a));},flush(){let r=s===e||s===n?"":s;s="",r&&t(r);}}}function Z(n,t,e,s){let o=n;return t&&(o=`cd '${t.replace(/'/g,"'\\''")}' && ${o}`),e&&Object.keys(e).length>0&&(o=`${Object.entries(e).filter(([,a])=>a!=null).map(([a,i])=>`export ${a}='${String(i).replace(/'/g,"'\\''")}'`).join("; ")}; ${o}`),s==="root"&&(o=`echo ${Buffer.from(o).toString("base64")} | base64 -d | sudo -n bash`),o}function Nt(n){let t=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(?:\/(\d{1,3}))?$/.exec(n);return !(!t||[t[1],t[2],t[3],t[4]].some(e=>Number(e)>255)||t[5]!==void 0&&Number(t[5])>32)}function me(n){return /^\d{1,3}(\.\d{1,3}){3}(\/\d+)?$/.test(n)&&!Nt(n)}function ge(n){return n.startsWith("[")?true:(n.match(/:/g)?.length??0)>=2}function pe(n){return /^[^:]+:\d+$/.test(n)}function he(n){return n.startsWith("*.")&&n.length>2&&!n.slice(2).includes("*")}function C(n){if(!n||n.outbound==="open"){if(n?.allowedDestinations?.length)throw new Error("network.allowedDestinations is only valid when outbound is blocked");return n?{networkBlockAll:false}:{}}let t=n.allowedDestinations??[];if(t.length===0)return {networkBlockAll:true};for(let r of t){if(r.trim()==="")throw new b("invalid-destination",`network.allowedDestinations contains an empty destination (${JSON.stringify(r)}). Every entry must be a hostname, *.wildcard domain, IPv4 address, or IPv4 CIDR \u2014 remove the blank entry (an empty allowlist would open the sandbox, not seal it).`,r);if(r.includes(","))throw new b("invalid-destination",`network.allowedDestinations entry "${r}" contains a comma. Daytona's allowlists are sent as one comma-joined string, so a comma inside an entry would smuggle extra destinations past the list caps \u2014 pass one destination per array entry.`,r)}let e=[],s=[];for(let r of t)if(Nt(r))e.push(r.includes("/")?r:`${r}/32`);else {if(me(r))throw new b("invalid-ipv4",`"${r}" is not a valid IPv4 address or CIDR (octets must be 0-255, prefix 0-32). Fix the address or list a hostname instead.`,r);if(ge(r))throw new b("ipv6-unsupported",`Daytona's network allowlist supports IPv4 CIDRs only; cannot allow IPv6 destination "${r}".`,r);if(pe(r))throw new b("port-unsupported",`Daytona's network allowlist filters hosts and IPs only and cannot match a port; drop the ":<port>" from "${r}" and list just the host or IP.`,r);if(r.includes("*")&&!he(r))throw new b("wildcard-hostname",`Daytona's domain allowlist supports exactly one wildcard form \u2014 a "*." prefix ("*.example.com" allows example.com and its subdomains) \u2014 and cannot express "${r}". Use a *.prefix wildcard, a concrete hostname, or an IPv4 CIDR instead.`,r);s.push(r);}if(e.length>0&&s.length>0)throw new b("mixed-allowlist",`Daytona's networkAllowList (IPv4 CIDRs) and domainAllowList (DNS names) are mutually exclusive \u2014 at most one may be non-empty per sandbox, and this policy names both kinds (CIDRs: ${e.join(", ")}; domains: ${s.join(", ")}). List only IPs/CIDRs or only hostnames for this sandbox.`);if(s.length>0){let r=[...new Set(s)];if(r.length>ht)throw new b("allowlist-too-large",`Daytona allows at most ${ht} entries in its domain allowlist; this policy names ${r.length} domains (${r.join(", ")}). Consolidate under *.prefix wildcards or reduce the list.`);return {networkBlockAll:false,domainAllowList:r.join(",")}}let o=[...new Set(e)];if(o.length>pt)throw new b("allowlist-too-large",`Daytona allows at most ${pt} entries in its network allowlist; this policy resolved to ${o.length} CIDRs (${o.join(", ")}). Aggregate destinations into broader CIDRs or reduce the list.`);return {networkBlockAll:false,networkAllowList:o.join(",")}}function Rt(n){let t=C(n);return t.networkAllowList!==void 0||t.domainAllowList!==void 0?{networkBlockAll:false,networkAllowList:t.networkAllowList??"",domainAllowList:t.domainAllowList??""}:{networkBlockAll:t.networkBlockAll===true,networkAllowList:"",domainAllowList:""}}function Ut(n){let t=rt(n),e=(n instanceof Error?n.message:String(n)).toLowerCase(),s=e.includes("network policy")||e.includes("network settings")||e.includes("network configuration"),o=e.includes("tier")||e.includes("plan")||e.includes("upgrade")||e.includes("not allowed")||e.includes("not permitted")||e.includes("cannot override");return (t===402||t===403)&&(o||s)?true:s&&o}function Ft(n){let t=n.indexOf("/");if(t<0)return;let e=n.substring(0,t);return e.includes(".")||e.includes(":")||e==="localhost"?e:void 0}function at(n){return {sandboxId:n.id,image:n.snapshot??"",name:n.name,metadata:n.labels??{},startedAt:n.createdAt??""}}function Bt(n){if(n==="started")return "running";if(n==="stopped"||n==="archived"||n==="paused")return "paused"}function Yt(n,t){if(!n||typeof n!="object")return;let e=n;if(typeof e.toolboxProxyUrl=="string"&&(e.toolboxProxyUrl=t),Array.isArray(e.items))for(let s of e.items)Yt(s,t);}function we(n,t){return new Proxy(n,{get(e,s,o){if(s==="getToolboxProxyUrl")return async()=>({data:{url:t}});let r=Reflect.get(e,s,o);return typeof r!="function"?r:function(...a){let i=r.apply(e,a);return i instanceof Promise?i.then(d=>(Yt(d?.data,t),d)):i}}})}var tt=class extends Daytona{constructor(t,e){super(t);let s=this;s.sandboxApi=we(s.sandboxApi,e);}};function ye(n,t){let e=new Uint8Array(new ArrayBuffer(n.length+t.length));return e.set(n,0),e.set(t,n.length),e}function Dt(n,t,e){t:for(let s=e;s+t.length<=n.length;s++){for(let o=0;o<t.length;o++)if(n[s+o]!==t[o])continue t;return s}return -1}function Gt(n,t){let e=new TextDecoder("utf-8"),s=new TextDecoder("utf-8"),o=new Uint8Array(0),r="stdout",a=i=>{i.length!==0&&(r==="stdout"?n(e.decode(i,{stream:true})):t(s.decode(i,{stream:true})));};return {push(i){for(o=ye(o,i);;){let d=Dt(o,STDOUT_PREFIX_BYTES,0),u=Dt(o,STDERR_PREFIX_BYTES,0),m=-1,c="stdout",f=0;if(d!==-1&&(u===-1||d<u)?(m=d,c="stdout",f=STDOUT_PREFIX_BYTES.length):u!==-1&&(m=u,c="stderr",f=STDERR_PREFIX_BYTES.length),m===-1){let l=Math.max(0,o.length-(MAX_PREFIX_LEN-1));a(o.subarray(0,l)),o=o.slice(l);return}a(o.subarray(0,m)),r=c,o=o.slice(m+f);}},flush(){a(o),o=new Uint8Array(0);let i=e.decode();i&&n(i);let d=s.decode();d&&t(d);}}}async function Wt(n,t,e,s,o,r,a){let i=`${n.toolboxUrl.replace(/\/+$/,"")}/${encodeURIComponent(t)}/process/session/${encodeURIComponent(e)}/command/${encodeURIComponent(s)}/logs?follow=true`,d=await fetch(i,{headers:{Authorization:`Bearer ${n.apiKey}`,accept:"application/octet-stream"},...a?{signal:a}:{}});if(!d.ok)throw new Error(`Daytona managed log follow failed: ${d.status} ${await d.text()}`);if(!d.body)return;let u=Gt(o,r),m=d.body.getReader();try{for(;;){let{done:c,value:f}=await m.read();if(c)break;f&&u.push(f);}}finally{u.flush(),await m.cancel().catch(()=>{});}}function Ht(n){let t=n.stdout||"",e=n.stderr||"",s=n.output||"";return !t&&!e&&s?{stdout:s,stderr:""}:{stdout:t,stderr:e}}var et=class{constructor(t,e,s){this.sandbox=t;this.user=e;this.managedStream=s;}streamTimings=oe;followLogs(t,e,s,o,r){return this.managedStream?Wt(this.managedStream,this.sandbox.id,t,e,s,o,r):this.sandbox.process.getSessionCommandLogs(t,e,s,o)}async run(t,e){let s=e?.timeoutMs?Math.floor(e.timeoutMs/1e3):void 0,o=`run-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await this.sandbox.process.createSession(o);try{let r=!!(e?.onStdout||e?.onStderr),a=At(),i=await this.sandbox.process.executeSessionCommand(o,{command:q(Z(Q(t,a),e?.cwd,e?.envs,this.user),s),runAsync:r},s),d=i.cmdId;if(r&&!d)throw new Error("Daytona returned no command id for an async command \u2014 cannot stream it or read its exit code");if(r&&d){let c="",f="",l=!0,g=Date.now(),p=J(a,h=>{c+=h,e?.onStdout?.(h);}),w=new AbortController,y=this.followLogs(o,d,h=>{l&&(g=Date.now(),p.push(h));},h=>{l&&(g=Date.now(),f+=h,e?.onStderr?.(h));},w.signal),x=!1,$,zt=y.then(()=>{},h=>{x||($=h);}),it;try{it=await this.awaitStreamedExit(o,d,y,()=>g,e?.timeoutMs);}finally{x=!0,w.abort(),await Promise.race([zt,S(this.streamTimings.drainMs)]),l=!1,$===void 0&&p.flush();}if($!==void 0){let h;try{let Kt=await this.sandbox.process.getSessionCommandLogs(o,d);h=P(Kt,a);}catch{throw $}if(!h.stdout.startsWith(c)||!h.stderr.startsWith(f))throw $;let I=h.stdout.slice(c.length),dt=h.stderr.slice(f.length);c=h.stdout,f=h.stderr,I&&e?.onStdout?.(I),dt&&e?.onStderr?.(dt);}else if(!c&&!f)try{let h=await this.sandbox.process.getSessionCommandLogs(o,d),I=P(h,a);c=I.stdout,f=I.stderr,c&&e?.onStdout?.(c),f&&e?.onStderr?.(f);}catch{}return {exitCode:it,stdout:c,stderr:f}}let{stdout:u,stderr:m}=P(i,a);if(!u&&!m&&d)try{let c=await this.sandbox.process.getSessionCommandLogs(o,d),f=P(c,a);u=f.stdout,m=f.stderr||m;}catch{}return {exitCode:i.exitCode??0,stdout:u,stderr:m}}finally{try{await this.sandbox.process.deleteSession(o);}catch{}}}async awaitStreamedExit(t,e,s,o,r){let a=this.streamTimings,i,d,u=s.then(()=>{i=Date.now();},f=>{i=Date.now(),d=f;}),m=r!==void 0&&r>0?Date.now()+r+a.killGraceMs:void 0,c=a.pollMinMs;for(;;){let f=await this.sandbox.process.getSessionCommand(t,e);if(f.exitCode!==void 0&&f.exitCode!==null){for(;i===void 0;){let p=Date.now()-o();if(p>=a.drainMs)break;await Promise.race([u,S(a.drainMs-p)]);}return f.exitCode}let l=i!==void 0?i+a.settleMs:void 0,g=m!==void 0&&l!==void 0?Math.min(m,l):m??l;if(g!==void 0&&Date.now()>=g)throw d!==void 0?d:new Error(`Daytona reported no exit code for command ${e} after `+(i!==void 0?"its log stream closed":`${r}ms`));await S(c),c=Math.min(c*2,a.pollMaxMs);}}async spawn(t,e){let s=`evolve-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await this.sandbox.process.createSession(s);let o=e?.timeoutMs?Math.floor(e.timeoutMs/1e3):void 0,r=Date.now(),a=e?.timeoutMs,i=At(),u=(await this.sandbox.process.executeSessionCommand(s,{command:q(Z(Q(t,i),e?.cwd,e?.envs,this.user),o),runAsync:true},o)).cmdId;if(u&&(e?.onStdout||e?.onStderr)){let c=J(i,e.onStdout||(()=>{}));this.followLogs(s,u,f=>c.push(f),e.onStderr||(()=>{})).catch(()=>{}).finally(()=>c.flush());}let m=this.sandbox;return {processId:s,wait:async()=>{if(!u)return {exitCode:0,stdout:"",stderr:""};for(;;){if(a&&Date.now()-r>=a){try{await m.process.deleteSession(s);}catch{}return {exitCode:124,stdout:"",stderr:"operation timed out"}}try{let c=await m.process.getSessionCommand(s,u);if(c.exitCode!==void 0)try{let f=await m.process.getSessionCommandLogs(s,u);return {exitCode:c.exitCode,...P(f,i)}}catch{return {exitCode:c.exitCode,stdout:"",stderr:""}}}catch(c){let f=c instanceof Error?c.message.toLowerCase():String(c).toLowerCase();if(f.includes("not found")){let l=f.includes("sandbox");try{await m.refreshData(),l=!1;}catch(g){(g instanceof Error?g.message.toLowerCase():String(g).toLowerCase()).includes("not found")&&(l=true);}return {exitCode:-1,stdout:"",stderr:l?"sandbox deleted during run":"session terminated"}}throw c}await S(500);}},kill:async()=>{try{return await m.process.deleteSession(s),!0}catch{return false}}}}async list(){try{return (await this.sandbox.process.listSessions()).map(e=>({processId:e.sessionId||"",cmd:"",args:[],envs:{}}))}catch{return []}}async kill(t){try{return await this.sandbox.process.deleteSession(t),!0}catch{return false}}},Pt="%y\\0%s\\0%T@\\0%m\\0%u\\0%g\\0%l\\0%f\\0",Y=8,be=1800*1e3;function xe(n,t){let e=R(n),s=t==="children"?`[ -e ${e} ] || exit ${M}; [ -d ${e} ] || exit ${N};`:`[ -e ${e} ] || [ -L ${e} ] || exit ${M};`,o=t==="children"?`find -H ${e} -mindepth 1 -maxdepth 1 -printf '${Pt}'`:`find ${e} -maxdepth 0 -printf '${Pt}'`;return `sh -c ${R(`${s} ( ${o}; printf 'STATUS:%d' "$?" ) | base64`)}`}function Se(n,t,e){let o=Buffer.from(t.replace(/\s+/g,""),"base64").toString("utf-8").split("\0"),r=o.pop()??"",a=/^STATUS:(\d+)$/.exec(r);if(!a)throw new Error(`daytona: the listing of ${n} ended without find's status (${r.slice(0,40)})`);if(a[1]!=="0")throw new Error(`daytona: find exited ${a[1]} listing ${n}`);let i=[];for(let d=0;d+Y<=o.length;d+=Y){let[u,m,c,f,l,g,p,w]=o.slice(d,d+Y),y=u==="f"?"file":u==="d"?"dir":u==="l"?"symlink":"other",x={name:w,path:e==="children"?ut(n,w):n,type:y,size:Number(m),mtime:F(Number(c)),mode:ct(f),owner:l,group:g};y==="symlink"&&(x.target=p),i.push(x);}return i}var nt=class{constructor(t,e){this.sandbox=t;this.commands=e;}async read(t){let e=new Uint8Array(await this.sandbox.fs.downloadFile(t));if(!e.includes(0))try{return new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(e)}catch{}return e}async write(t,e){let s;if(typeof e=="string")s=Buffer.from(e,"utf-8");else if(Buffer.isBuffer(e))s=e;else if(e instanceof ArrayBuffer)s=Buffer.from(e);else if(e instanceof Uint8Array)s=Buffer.from(e);else throw new Error(`Unsupported content type: ${typeof e}`);await this.sandbox.fs.uploadFile(s,t);}async writeBatch(t){let e=t.map(s=>{let o;if(typeof s.data=="string")o=Buffer.from(s.data,"utf-8");else if(Buffer.isBuffer(s.data))o=s.data;else if(s.data instanceof ArrayBuffer)o=Buffer.from(s.data);else if(s.data instanceof Uint8Array)o=Buffer.from(s.data);else throw new Error(`Unsupported content type: ${typeof s.data}`);return {source:o,destination:s.path}});await this.sandbox.fs.uploadFiles(e);}async writeFromPath(t,e){await this.sandbox.fs.uploadFile(e,t);}async makeDir(t){await this.sandbox.fs.createFolder(t,"755");}async exists(t){try{let e=ae(t),s=ie(t);return (await this.sandbox.fs.listFiles(e)).some(r=>r.name===s)}catch{return false}}async list(t){return this.findListing(t,"children")}async stat(t){let[e]=await this.findListing(t,"self");if(!e)throw new A(t,"daytona");return e}async findListing(t,e){let s=await this.commands.run(xe(t,e));if(s.exitCode===M)throw new A(t,"daytona");if(s.exitCode===N)throw new Error(`daytona: ${t} is not a directory`);if(s.exitCode!==0)throw new Error(`daytona: listing ${t} failed (exit ${s.exitCode}): ${s.stderr.trim()}`);try{return Se(t,s.stdout,e)}catch(o){throw /printf|unrecognized|invalid option/i.test(s.stderr)?new E("files.list","daytona",`this image's find has no -printf (GNU findutils is needed to list entries as themselves): ${s.stderr.trim()}`):o}}async readRange(t,e){if(U(e),e.length===0)return new Uint8Array(0);let s=await this.sandbox.downloadUrl(t);return ft(s,e,{provider:"daytona",path:t,timeoutMs:be})}async watchDir(t,e,s){throw new E("files.watchDir","daytona","the Daytona SDK has no filesystem watcher; poll files.list() on the directories you have open")}async remove(t){await this.sandbox.fs.deleteFile(t,true);}async rename(t,e){await this.sandbox.fs.moveFiles(t,e);}},D=class{constructor(t,e,s){this.sandbox=t;let o=new et(t,e,s);this.commands=o,this.files=new nt(t,o);}commands;files;get sandboxId(){return this.sandbox.id}async getHost(t){return (await this.sandbox.getPreviewLink(t)).url}async isRunning(){try{await this.sandbox.refreshData();}catch{return false}return this.sandbox.state==="started"}async getInfo(){return await this.sandbox.refreshData(),at(this.sandbox)}async metrics(){let t=await this.sandbox.getMetricsLatest();return {cpuPct:t.cpuUsedPct,memUsedMb:t.memUsed/G,memTotalMb:t.memTotal/G,diskUsedMb:t.diskUsed/G,sampledAt:F(t.timestamp),source:"daytona:getMetricsLatest"}}async updateNetwork(t){let e=Rt(t);try{await this.sandbox.updateNetworkSettings(e);}catch(s){throw Ut(s)?new b("org-tier-forbidden",`Daytona refused to change this sandbox's network policy: organizations on Tier 1 or Tier 2 cannot override network policy at the sandbox level. Raise the organization's tier, or run this workload on a provider whose plan permits runtime policy changes (underlying error: ${s instanceof Error?s.message:String(s)}).`):s}}async kill(){await this.sandbox.delete();}async pause(){await this.sandbox.stop();}},st=class{providerType="daytona";name="Daytona";client;defaultTimeoutMs;snapshotName;sandboxUsers=new Map;managedStream;snapshotConflictTiming={timeoutMs:$t,pollMs:It};snapshotDeleteTiming={timeoutMs:_t,pollMs:Mt};constructor(t){let e={apiKey:t.apiKey,apiUrl:t.apiUrl,target:t.target,useDeprecatedPolling:true};this.client=t.managedToolboxUrl?new tt(e,t.managedToolboxUrl):new Daytona(e),t.managedToolboxUrl&&(this.managedStream={toolboxUrl:t.managedToolboxUrl,apiKey:t.apiKey}),this.defaultTimeoutMs=t.defaultTimeoutMs??36e5,this.snapshotName=t.snapshotName??(t.managedToolboxUrl?"evolve-all":`evolve-all-${O}`);}async create(t){if(t.idleTimeoutMs!==void 0)throw new j;if(t.bootCommand!==void 0)throw new H;for(let l of t.phaseNetworkPolicies??[])C(l);let e=C(t.network),s=t.user,o=s&&s!=="root"?s:void 0,r=t.timeoutMs??this.defaultTimeoutMs,a=Math.max(1,Math.ceil(r/6e4)),i=t.image||this.snapshotName,d={envVars:t.envs,labels:t.metadata,autoStopInterval:a,autoDeleteInterval:ee,...o?{user:o}:{},...e},u,m=t.resources!==void 0&&(t.resources.cpu!==void 0||t.resources.memory!==void 0||t.resources.disk!==void 0||t.resources.gpu!==void 0||t.resources.gpuTypes!==void 0);if(this.managedStream){if(m)throw new k(i);let l=await this.client.create({snapshot:i,...d},{timeout:600});return t.workingDirectory&&await l.fs.createFolder(t.workingDirectory,"755"),s&&this.sandboxUsers.set(l.id,s),new D(l,s,this.managedStream)}let c,f;try{let l=await this.client.snapshot.get(i),g=l?.state;if(l&&kt.has(g??"")&&(c=g),l&&(g==="active"||g==="inactive")&&m)throw new k(i);if(l&&g==="inactive"&&(g=(await K(this.client,i,l)).state),l&&St.has(g??"")&&(X(i)?f=await vt(this.client,i,l,this.snapshotDeleteTiming):console.warn(`[daytona] Snapshot "${i}" is dead (state "${g}") but this provider cannot rebuild that name \u2014 delete it in the Daytona dashboard (Snapshots page), or rebuild it with the tooling that created it.`)),l&&g==="active")console.log(`[daytona] Using cached snapshot: ${i}`),u=await this.client.create({snapshot:i,...d},{timeout:600});else throw new Error("Snapshot not active")}catch(l){if(l instanceof k||l instanceof v)throw l;let g=ot[i]??i,p=c!==void 0&&!m;p?console.log(`[daytona] Snapshot "${i}" is mid-build (state "${c}") \u2014 joining that build rather than starting a second one.`):c!==void 0?console.log(`[daytona] Snapshot "${i}" is mid-build (state "${c}") and cannot carry the requested sizing \u2014 pulling image directly instead: ${g}`):(console.log(`[daytona] Snapshot "${i}" not found, building from image: ${g}`),console.log("[daytona] First run will take a few minutes (this only happens once)..."));try{if(f===!1)throw new Error(`dead snapshot "${i}" was not confirmed removed \u2014 not racing its removal`);let w=()=>this.client.snapshot.create({name:i,image:Image.base(g),resources:{cpu:t.resources?.cpu??4,memory:t.resources?.memory??4,disk:t.resources?.disk??10,...(t.resources?.gpu??0)>0?{gpu:t.resources.gpu}:{},...t.resources?.gpuTypes?.length?{gpuType:t.resources.gpuTypes}:{}}},{onLogs:x=>console.log(`[daytona] ${x}`)}),y=async()=>{await w(),console.log(`[daytona] Snapshot "${i}" ready (rebuilt here after a dead build).`);};if(c!==void 0){if(!p)throw new Error(`snapshot "${i}" is mid-build (state "${c}") and cannot be resized`);await this.joinInFlightSnapshotBuild(i)&&await y();}else try{await w(),console.log(`[daytona] Snapshot "${i}" ready (built here).`);}catch(x){if(!Ot(x)||m)throw x;await this.joinInFlightSnapshotBuild(i)&&await y();}u=await this.client.create({snapshot:i,...d},{timeout:600});}catch(w){if(w instanceof T||w instanceof v)throw w;console.warn(`[daytona] Snapshot creation failed, falling back to direct image: ${w instanceof Error?w.message:w}`);try{u=await this.client.create({image:g,...d,resources:{cpu:t.resources?.cpu??4,memory:t.resources?.memory??4,disk:t.resources?.disk??10,...(t.resources?.gpu??0)>0?{gpu:t.resources.gpu}:{},...t.resources?.gpuTypes?.length?{gpuType:t.resources.gpuTypes}:{}}},{timeout:600,onSnapshotCreateLogs:y=>console.log(`[daytona] ${y}`)});}catch(y){throw Ft(g)?new W(g,y):y}}}return t.workingDirectory&&await u.fs.createFolder(t.workingDirectory,"755"),s&&this.sandboxUsers.set(u.id,s),new D(u,s,this.managedStream)}async joinInFlightSnapshotBuild(t){let e=await Ct(this.client,t,this.snapshotConflictTiming);if(e===Et)return true;if(e.state==="active")return console.log(`[daytona] Snapshot "${t}" ready (built by another process) \u2014 reusing it.`),false;if(e.state==="inactive")return await K(this.client,t,e),console.log(`[daytona] Snapshot "${t}" ready (built by another process) \u2014 reusing it.`),false;if(St.has(e.state??"")&&X(t)&&await vt(this.client,t,e,this.snapshotDeleteTiming))return true;throw new Error(`the in-flight build of snapshot "${t}" ended in state "${e.state??"unknown"}"`)}async connect(t,e){let s=await this.client.get(t);return s.state!=="started"&&await s.start(),new D(s,this.sandboxUsers.get(t),this.managedStream)}async inspect(t,e){let s=await this.getSandboxRecord(t);if(s.state!=="started")throw new _(t,"daytona",s.state??"unknown");return new D(s,e?.user??this.sandboxUsers.get(t),this.managedStream)}async getSandboxRecord(t){return this.client.get(t)}async list(t){let e=await this.paginate(t);if(e.error&&!e.stoppedAtLimit)throw new Error(e.error);return e.sandboxes}async listAll(t){let{stoppedAtLimit:e,...s}=await this.paginate(t);return s}async paginate(t){return jt(this.listStream(t),t)}listStream(t){let e=t?.state?ve(t.state):void 0,s={limit:re,...t?.metadata?{labels:t.metadata}:{},...e&&e.length>0?{states:e}:{}};return this.client.list(s)}};function ve(n){let t=[];for(let e of n)e==="running"&&t.push("started"),e==="paused"&&t.push("stopped","archived","paused");return t}async function jt(n,t){let e=t?.limit,s=[],o=0,r=new Set;try{for await(let a of n){if(e!==void 0&&s.length>=e)return {sandboxes:s,complete:!1,pagesFetched:o,stoppedAtLimit:!0,error:`stopped at the requested limit of ${e} with more sandboxes available`};if(o+=1,o>B)return {sandboxes:s,complete:!1,pagesFetched:B,stoppedAtLimit:!1,error:`sandbox list exceeded ${B} sandboxes scanned`};if(t?.state){let i=Bt(a.state);if(i===void 0||!t.state.includes(i))continue}r.has(a.id)||(r.add(a.id),s.push(at(a)));}}catch(a){return {sandboxes:s,complete:false,pagesFetched:o,stoppedAtLimit:false,error:`sandbox list failed: ${a instanceof Error?a.message:String(a)}`}}return {sandboxes:s,complete:true,pagesFetched:o,stoppedAtLimit:false}}var Le=jt;function Ne(n={}){let t=n.apiKey??process.env.DAYTONA_API_KEY;if(!t)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 st({...n,apiKey:t})}var Re=Z,Ue=q,Fe=C,Be=Rt,Ye=Ut,Ge=Ft,We=at,He=Bt,je=K,ze=Ct,Ke=Ot,Xe=X,Ve=ot,qe=Q,Qe=Lt,Je=P,Ze=J,tn=Gt,en=Wt,nn=Ht,sn=D,G=1024*1024;
|
|
8
|
-
export{ee as DAYTONA_AUTO_DELETE_GRACE_MINUTES,bt as DAYTONA_BOOT_LABEL,le as DAYTONA_BOOT_POLL_MS,re as DAYTONA_LIST_PAGE_SIZE,ht as DAYTONA_MAX_DOMAIN_ALLOWLIST,B as DAYTONA_MAX_LIST_SCAN,pt as DAYTONA_MAX_NETWORK_ALLOWLIST,ne as DAYTONA_SNAPSHOT_ACTIVATE_TIMEOUT_MS,$t as DAYTONA_SNAPSHOT_CONFLICT_TIMEOUT_MS,Et as DAYTONA_SNAPSHOT_GONE,oe as DAYTONA_STREAM_TIMINGS,z as DaytonaBootAbortedError,H as DaytonaBootCommandError,et as DaytonaCommands,nt as DaytonaFiles,wt as DaytonaGpuTypeError,j as DaytonaIdleTimeoutError,W as DaytonaImagePullError,b as DaytonaNetworkPolicyError,st as DaytonaProvider,k as DaytonaResourcesError,v as DaytonaSnapshotActivationError,T as DaytonaSnapshotConflictError,O as EVOLVE_IMAGE_VERSION,E as SandboxFeatureUnsupportedError,_ as SandboxNotRunningError,A as SandboxPathNotFoundError,je as _testActivateSnapshot,Le as _testCollectSandboxStream,tn as _testCreateLogDemuxer,Ze as _testCreateSentinelFilter,sn as _testDaytonaSandboxImplCtor,He as _testDaytonaStateToEvolveState,en as _testFollowManagedSessionLogs,Ve as _testImageMap,Ge as _testImageRegistryHost,Ye as _testIsNetworkPolicyTierRefusal,Ke as _testIsSnapshotNameConflict,Fe as _testMapNetworkPolicy,Be as _testMapNetworkPolicyForUpdate,Xe as _testProviderCanRebuildSnapshot,nn as _testReadCommandStreams,Je as _testSettledStreams,Qe as _testStripEndOfOutputSentinel,We as _testToSandboxInfo,ze as _testWaitForSnapshotConflictWinner,qe as _testWithEndOfOutputSentinel,Ue as _testWithInBoxTimeout,Re as _testWrapCommand,Ne as createDaytonaProvider,Ce as createSandboxObserved,yt as daytonaBootPhaseOf,Xt as isSandboxFeatureUnsupportedError,qt as isSandboxNotRunningError,Vt as isSandboxPathNotFoundError,C as mapNetworkPolicy};
|
|
5
|
+
}; __evolve_eos=$?; printf '%s' '${t}' 2>/dev/null >&9; exec 9>&-; (exit $__evolve_eos)`:n}function Nt(n,t){return n.endsWith(`${t}
|
|
6
|
+
`)?n.slice(0,-(t.length+1)):n.endsWith(t)?n.slice(0,-t.length):n}function D(n,t){let e=dt(n);return {stdout:Nt(e.stdout,t),stderr:e.stderr}}function J(n,t){let e=`${n}
|
|
7
|
+
`,s="",r=o=>{for(let a=Math.min(o.length,e.length);a>0;a--)if(e.startsWith(o.slice(o.length-a)))return a;return 0};return {push(o){s+=o;let a=r(s);a!==s.length&&(t(s.slice(0,s.length-a)),s=s.slice(s.length-a));},flush(){let o=s===e||s===n?"":s;s="",o&&t(o);}}}function Z(n,t,e,s){let r=n;return t&&(r=`cd '${t.replace(/'/g,"'\\''")}' && ${r}`),e&&Object.keys(e).length>0&&(r=`${Object.entries(e).filter(([,a])=>a!=null).map(([a,i])=>`export ${a}='${String(i).replace(/'/g,"'\\''")}'`).join("; ")}; ${r}`),s==="root"&&(r=`echo ${Buffer.from(r).toString("base64")} | base64 -d | sudo -n bash`),r}function Ut(n){let t=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(?:\/(\d{1,3}))?$/.exec(n);return !(!t||[t[1],t[2],t[3],t[4]].some(e=>Number(e)>255)||t[5]!==void 0&&Number(t[5])>32)}function me(n){return /^\d{1,3}(\.\d{1,3}){3}(\/\d+)?$/.test(n)&&!Ut(n)}function pe(n){return n.startsWith("[")?true:(n.match(/:/g)?.length??0)>=2}function he(n){return /^[^:]+:\d+$/.test(n)}function we(n){return n.startsWith("*.")&&n.length>2&&!n.slice(2).includes("*")}function O(n){if(!n||n.outbound==="open"){if(n?.allowedDestinations?.length)throw new Error("network.allowedDestinations is only valid when outbound is blocked");return n?{networkBlockAll:false}:{}}let t=n.allowedDestinations??[];if(t.length===0)return {networkBlockAll:true};for(let o of t){if(o.trim()==="")throw new b("invalid-destination",`network.allowedDestinations contains an empty destination (${JSON.stringify(o)}). Every entry must be a hostname, *.wildcard domain, IPv4 address, or IPv4 CIDR \u2014 remove the blank entry (an empty allowlist would open the sandbox, not seal it).`,o);if(o.includes(","))throw new b("invalid-destination",`network.allowedDestinations entry "${o}" contains a comma. Daytona's allowlists are sent as one comma-joined string, so a comma inside an entry would smuggle extra destinations past the list caps \u2014 pass one destination per array entry.`,o)}let e=[],s=[];for(let o of t)if(Ut(o))e.push(o.includes("/")?o:`${o}/32`);else {if(me(o))throw new b("invalid-ipv4",`"${o}" is not a valid IPv4 address or CIDR (octets must be 0-255, prefix 0-32). Fix the address or list a hostname instead.`,o);if(pe(o))throw new b("ipv6-unsupported",`Daytona's network allowlist supports IPv4 CIDRs only; cannot allow IPv6 destination "${o}".`,o);if(he(o))throw new b("port-unsupported",`Daytona's network allowlist filters hosts and IPs only and cannot match a port; drop the ":<port>" from "${o}" and list just the host or IP.`,o);if(o.includes("*")&&!we(o))throw new b("wildcard-hostname",`Daytona's domain allowlist supports exactly one wildcard form \u2014 a "*." prefix ("*.example.com" allows example.com and its subdomains) \u2014 and cannot express "${o}". Use a *.prefix wildcard, a concrete hostname, or an IPv4 CIDR instead.`,o);s.push(o);}if(e.length>0&&s.length>0)throw new b("mixed-allowlist",`Daytona's networkAllowList (IPv4 CIDRs) and domainAllowList (DNS names) are mutually exclusive \u2014 at most one may be non-empty per sandbox, and this policy names both kinds (CIDRs: ${e.join(", ")}; domains: ${s.join(", ")}). List only IPs/CIDRs or only hostnames for this sandbox.`);if(s.length>0){let o=[...new Set(s)];if(o.length>yt)throw new b("allowlist-too-large",`Daytona allows at most ${yt} entries in its domain allowlist; this policy names ${o.length} domains (${o.join(", ")}). Consolidate under *.prefix wildcards or reduce the list.`);return {networkBlockAll:false,domainAllowList:o.join(",")}}let r=[...new Set(e)];if(r.length>wt)throw new b("allowlist-too-large",`Daytona allows at most ${wt} entries in its network allowlist; this policy resolved to ${r.length} CIDRs (${r.join(", ")}). Aggregate destinations into broader CIDRs or reduce the list.`);return {networkBlockAll:false,networkAllowList:r.join(",")}}function Ft(n){let t=O(n);return t.networkAllowList!==void 0||t.domainAllowList!==void 0?{networkBlockAll:false,networkAllowList:t.networkAllowList??"",domainAllowList:t.domainAllowList??""}:{networkBlockAll:t.networkBlockAll===true,networkAllowList:"",domainAllowList:""}}function Bt(n){let t=ot(n),e=(n instanceof Error?n.message:String(n)).toLowerCase(),s=e.includes("network policy")||e.includes("network settings")||e.includes("network configuration"),r=e.includes("tier")||e.includes("plan")||e.includes("upgrade")||e.includes("not allowed")||e.includes("not permitted")||e.includes("cannot override");return (t===402||t===403)&&(r||s)?true:s&&r}function Yt(n){let t=n.indexOf("/");if(t<0)return;let e=n.substring(0,t);return e.includes(".")||e.includes(":")||e==="localhost"?e:void 0}function at(n){return {sandboxId:n.id,image:n.snapshot??"",name:n.name,metadata:n.labels??{},startedAt:n.createdAt??""}}function Gt(n){if(n==="started")return "running";if(n==="stopped"||n==="archived"||n==="paused")return "paused"}function Wt(n,t){if(!n||typeof n!="object")return;let e=n;if(typeof e.toolboxProxyUrl=="string"&&(e.toolboxProxyUrl=t),Array.isArray(e.items))for(let s of e.items)Wt(s,t);}function ye(n,t,e){return new Proxy(n,{get(s,r,o){if(r==="getToolboxProxyUrl")return async()=>({data:{url:t}});let a=Reflect.get(s,r,o);return typeof a!="function"?a:function(...i){let d=()=>a.apply(s,i),l=r==="createSandbox"&&e?e(()=>d()):d();return l instanceof Promise?l.then(g=>(Wt(g?.data,t),g)):l}}})}var tt=class extends Daytona{constructor(t,e,s){super(t);let r=this;r.sandboxApi=ye(r.sandboxApi,e,s);}};function be(n,t){let e=new Uint8Array(new ArrayBuffer(n.length+t.length));return e.set(n,0),e.set(t,n.length),e}function Tt(n,t,e){t:for(let s=e;s+t.length<=n.length;s++){for(let r=0;r<t.length;r++)if(n[s+r]!==t[r])continue t;return s}return -1}function it(n,t){let e=new TextDecoder("utf-8"),s=new TextDecoder("utf-8"),r=new Uint8Array(0),o="stdout",a=i=>{i.length!==0&&(o==="stdout"?n(e.decode(i,{stream:true})):t(s.decode(i,{stream:true})));};return {push(i){for(r=be(r,i);;){let d=Tt(r,STDOUT_PREFIX_BYTES,0),l=Tt(r,STDERR_PREFIX_BYTES,0),g=-1,c="stdout",f=0;if(d!==-1&&(l===-1||d<l)?(g=d,c="stdout",f=STDOUT_PREFIX_BYTES.length):l!==-1&&(g=l,c="stderr",f=STDERR_PREFIX_BYTES.length),g===-1){let u=Math.max(0,r.length-(MAX_PREFIX_LEN-1));a(r.subarray(0,u)),r=r.slice(u);return}a(r.subarray(0,g)),o=c,r=r.slice(g+f);}},flush(){a(r),r=new Uint8Array(0);let i=e.decode();i&&n(i);let d=s.decode();d&&t(d);}}}async function jt(n,t,e,s,r,o,a){let i=Ht(n,t,e,s,true),d=await fetch(i,{headers:{Authorization:`Bearer ${n.apiKey}`,accept:"application/octet-stream"},...a?{signal:a}:{}});if(!d.ok)throw new Error(`Daytona managed log follow failed: ${d.status} ${await d.text()}`);if(!d.body)return;let l=it(r,o),g=d.body.getReader();try{for(;;){let{done:c,value:f}=await g.read();if(c)break;f&&l.push(f);}}finally{l.flush(),await g.cancel().catch(()=>{});}}function Ht(n,t,e,s,r){return `${n.toolboxUrl.replace(/\/+$/,"")}/${encodeURIComponent(t)}/process/session/${encodeURIComponent(e)}/command/${encodeURIComponent(s)}/logs${r?"?follow=true":""}`}async function xe(n,t,e,s,r){let o=await fetch(Ht(n,t,e,s,false),{headers:{Authorization:`Bearer ${n.apiKey}`,accept:"application/json, text/plain, */*"}});if(!o.ok)throw new Error(`Daytona managed log read failed: ${o.status} ${await o.text()}`);let a;if((o.headers.get("content-type")||"").includes("application/json"))a=dt(await o.json());else {let l="",g="",c=it(f=>{l+=f;},f=>{g+=f;});c.push(new Uint8Array(await o.arrayBuffer())),c.flush(),a={stdout:l,stderr:g};}let i=`${r}
|
|
8
|
+
`,d=a.stdout.indexOf(i);return d!==-1&&d+i.length<a.stdout.length&&(a={stdout:a.stdout.slice(0,d+i.length),stderr:a.stdout.slice(d+i.length)+a.stderr}),{output:"",...a}}function dt(n){let t=n.stdout||"",e=n.stderr||"",s=n.output||"";return !t&&!e&&s?{stdout:s,stderr:""}:{stdout:t,stderr:e}}var et=class{constructor(t,e,s){this.sandbox=t;this.user=e;this.managedStream=s;}streamTimings=oe;followLogs(t,e,s,r,o){return this.managedStream?jt(this.managedStream,this.sandbox.id,t,e,s,r,o):this.sandbox.process.getSessionCommandLogs(t,e,s,r)}readSettledLogs(t,e,s){return this.managedStream?xe(this.managedStream,this.sandbox.id,t,e,s):this.sandbox.process.getSessionCommandLogs(t,e)}async run(t,e){let s=e?.timeoutMs?Math.floor(e.timeoutMs/1e3):void 0,r=`run-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await this.sandbox.process.createSession(r);try{let o=!!(e?.onStdout||e?.onStderr),a=Dt(),i=await this.sandbox.process.executeSessionCommand(r,{command:V(Z(Q(t,a),e?.cwd,e?.envs,this.user),s),runAsync:o},s),d=i.cmdId;if(o&&!d)throw new Error("Daytona returned no command id for an async command \u2014 cannot stream it or read its exit code");if(o&&d){let c="",f="",u=!0,m=Date.now(),p=J(a,h=>{c+=h,e?.onStdout?.(h);}),w=new AbortController,y=this.followLogs(r,d,h=>{u&&(m=Date.now(),p.push(h));},h=>{u&&(m=Date.now(),f+=h,e?.onStderr?.(h));},w.signal),x=!1,$,zt=y.then(()=>{},h=>{x||($=h);}),lt;try{lt=await this.awaitStreamedExit(r,d,y,()=>m,e?.timeoutMs);}finally{x=!0,w.abort(),await Promise.race([zt,S(this.streamTimings.drainMs)]),u=!1,$===void 0&&p.flush();}if($!==void 0){let h;try{let Kt=await this.readSettledLogs(r,d,a);h=D(Kt,a);}catch{throw $}if(!h.stdout.startsWith(c)||!h.stderr.startsWith(f))throw $;let E=h.stdout.slice(c.length),ct=h.stderr.slice(f.length);c=h.stdout,f=h.stderr,E&&e?.onStdout?.(E),ct&&e?.onStderr?.(ct);}else if(!c&&!f)try{let h=await this.readSettledLogs(r,d,a),E=D(h,a);c=E.stdout,f=E.stderr,c&&e?.onStdout?.(c),f&&e?.onStderr?.(f);}catch{}return {exitCode:lt,stdout:c,stderr:f}}let{stdout:l,stderr:g}=D(i,a);if(!l&&!g&&d)try{let c=await this.readSettledLogs(r,d,a),f=D(c,a);l=f.stdout,g=f.stderr||g;}catch{}return {exitCode:i.exitCode??0,stdout:l,stderr:g}}finally{try{await this.sandbox.process.deleteSession(r);}catch{}}}async awaitStreamedExit(t,e,s,r,o){let a=this.streamTimings,i,d,l=s.then(()=>{i=Date.now();},f=>{i=Date.now(),d=f;}),g=o!==void 0&&o>0?Date.now()+o+a.killGraceMs:void 0,c=a.pollMinMs;for(;;){let f=await this.sandbox.process.getSessionCommand(t,e);if(f.exitCode!==void 0&&f.exitCode!==null){for(;i===void 0;){let p=Date.now()-r();if(p>=a.drainMs)break;await Promise.race([l,S(a.drainMs-p)]);}return f.exitCode}let u=i!==void 0?i+a.settleMs:void 0,m=g!==void 0&&u!==void 0?Math.min(g,u):g??u;if(m!==void 0&&Date.now()>=m)throw d!==void 0?d:new Error(`Daytona reported no exit code for command ${e} after `+(i!==void 0?"its log stream closed":`${o}ms`));await S(c),c=Math.min(c*2,a.pollMaxMs);}}async spawn(t,e){let s=`evolve-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await this.sandbox.process.createSession(s);let r=e?.timeoutMs?Math.floor(e.timeoutMs/1e3):void 0,o=Date.now(),a=e?.timeoutMs,i=Dt(),l=(await this.sandbox.process.executeSessionCommand(s,{command:V(Z(Q(t,i),e?.cwd,e?.envs,this.user),r),runAsync:true},r)).cmdId;if(l&&(e?.onStdout||e?.onStderr)){let c=J(i,e.onStdout||(()=>{}));this.followLogs(s,l,f=>c.push(f),e.onStderr||(()=>{})).catch(()=>{}).finally(()=>c.flush());}let g=this.sandbox;return {processId:s,wait:async()=>{if(!l)return {exitCode:0,stdout:"",stderr:""};for(;;){if(a&&Date.now()-o>=a){try{await g.process.deleteSession(s);}catch{}return {exitCode:124,stdout:"",stderr:"operation timed out"}}try{let c=await g.process.getSessionCommand(s,l);if(c.exitCode!==void 0)try{let f=await this.readSettledLogs(s,l,i);return {exitCode:c.exitCode,...D(f,i)}}catch{return {exitCode:c.exitCode,stdout:"",stderr:""}}}catch(c){let f=c instanceof Error?c.message.toLowerCase():String(c).toLowerCase();if(f.includes("not found")){let u=f.includes("sandbox");try{await g.refreshData(),u=!1;}catch(m){(m instanceof Error?m.message.toLowerCase():String(m).toLowerCase()).includes("not found")&&(u=true);}return {exitCode:-1,stdout:"",stderr:u?"sandbox deleted during run":"session terminated"}}throw c}await S(500);}},kill:async()=>{try{return await g.process.deleteSession(s),!0}catch{return false}}}}async list(){try{return (await this.sandbox.process.listSessions()).map(e=>({processId:e.sessionId||"",cmd:"",args:[],envs:{}}))}catch{return []}}async kill(t){try{return await this.sandbox.process.deleteSession(t),!0}catch{return false}}},$t="%y\\0%s\\0%T@\\0%m\\0%u\\0%g\\0%l\\0%f\\0",Y=8,Se=1800*1e3;function ve(n,t){let e=N(n),s=t==="children"?`[ -e ${e} ] || exit ${M}; [ -d ${e} ] || exit ${R};`:`[ -e ${e} ] || [ -L ${e} ] || exit ${M};`,r=t==="children"?`find -H ${e} -mindepth 1 -maxdepth 1 -printf '${$t}'`:`find ${e} -maxdepth 0 -printf '${$t}'`;return `sh -c ${N(`${s} ( ${r}; printf 'STATUS:%d' "$?" ) | base64`)}`}function Ae(n,t,e){let r=Buffer.from(t.replace(/\s+/g,""),"base64").toString("utf-8").split("\0"),o=r.pop()??"",a=/^STATUS:(\d+)$/.exec(o);if(!a)throw new Error(`daytona: the listing of ${n} ended without find's status (${o.slice(0,40)})`);if(a[1]!=="0")throw new Error(`daytona: find exited ${a[1]} listing ${n}`);let i=[];for(let d=0;d+Y<=r.length;d+=Y){let[l,g,c,f,u,m,p,w]=r.slice(d,d+Y),y=l==="f"?"file":l==="d"?"dir":l==="l"?"symlink":"other",x={name:w,path:e==="children"?ft(n,w):n,type:y,size:Number(g),mtime:F(Number(c)),mode:gt(f),owner:u,group:m};y==="symlink"&&(x.target=p),i.push(x);}return i}var nt=class{constructor(t,e){this.sandbox=t;this.commands=e;}async read(t){let e=new Uint8Array(await this.sandbox.fs.downloadFile(t));if(!e.includes(0))try{return new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(e)}catch{}return e}async write(t,e){let s;if(typeof e=="string")s=Buffer.from(e,"utf-8");else if(Buffer.isBuffer(e))s=e;else if(e instanceof ArrayBuffer)s=Buffer.from(e);else if(e instanceof Uint8Array)s=Buffer.from(e);else throw new Error(`Unsupported content type: ${typeof e}`);await this.sandbox.fs.uploadFile(s,t);}async writeBatch(t){let e=t.map(s=>{let r;if(typeof s.data=="string")r=Buffer.from(s.data,"utf-8");else if(Buffer.isBuffer(s.data))r=s.data;else if(s.data instanceof ArrayBuffer)r=Buffer.from(s.data);else if(s.data instanceof Uint8Array)r=Buffer.from(s.data);else throw new Error(`Unsupported content type: ${typeof s.data}`);return {source:r,destination:s.path}});await this.sandbox.fs.uploadFiles(e);}async writeFromPath(t,e){await this.sandbox.fs.uploadFile(e,t);}async makeDir(t){await this.sandbox.fs.createFolder(t,"755");}async exists(t){try{let e=ie(t),s=de(t);return (await this.sandbox.fs.listFiles(e)).some(o=>o.name===s)}catch{return false}}async list(t){return this.findListing(t,"children")}async stat(t){let[e]=await this.findListing(t,"self");if(!e)throw new A(t,"daytona");return e}async findListing(t,e){let s=await this.commands.run(ve(t,e));if(s.exitCode===M)throw new A(t,"daytona");if(s.exitCode===R)throw new Error(`daytona: ${t} is not a directory`);if(s.exitCode!==0)throw new Error(`daytona: listing ${t} failed (exit ${s.exitCode}): ${s.stderr.trim()}`);try{return Ae(t,s.stdout,e)}catch(r){throw /printf|unrecognized|invalid option/i.test(s.stderr)?new k("files.list","daytona",`this image's find has no -printf (GNU findutils is needed to list entries as themselves): ${s.stderr.trim()}`):r}}async readRange(t,e){if(U(e),e.length===0)return new Uint8Array(0);let s=await this.sandbox.downloadUrl(t);return mt(s,e,{provider:"daytona",path:t,timeoutMs:Se})}async watchDir(t,e,s){throw new k("files.watchDir","daytona","the Daytona SDK has no filesystem watcher; poll files.list() on the directories you have open")}async remove(t){await this.sandbox.fs.deleteFile(t,true);}async rename(t,e){await this.sandbox.fs.moveFiles(t,e);}},P=class{constructor(t,e,s){this.sandbox=t;let r=new et(t,e,s);this.commands=r,this.files=new nt(t,r);}commands;files;get sandboxId(){return this.sandbox.id}async getHost(t){return (await this.sandbox.getPreviewLink(t)).url}async isRunning(){try{await this.sandbox.refreshData();}catch{return false}return this.sandbox.state==="started"}async getInfo(){return await this.sandbox.refreshData(),at(this.sandbox)}async metrics(){let t=await this.sandbox.getMetricsLatest();return {cpuPct:t.cpuUsedPct,memUsedMb:t.memUsed/G,memTotalMb:t.memTotal/G,diskUsedMb:t.diskUsed/G,sampledAt:F(t.timestamp),source:"daytona:getMetricsLatest"}}async updateNetwork(t){let e=Ft(t);try{await this.sandbox.updateNetworkSettings(e);}catch(s){throw Bt(s)?new b("org-tier-forbidden",`Daytona refused to change this sandbox's network policy: organizations on Tier 1 or Tier 2 cannot override network policy at the sandbox level. Raise the organization's tier, or run this workload on a provider whose plan permits runtime policy changes (underlying error: ${s instanceof Error?s.message:String(s)}).`):s}}async kill(){await this.sandbox.delete();}async pause(){await this.sandbox.stop();}},st=class{providerType="daytona";name="Daytona";client;defaultTimeoutMs;snapshotName;sandboxUsers=new Map;managedStream;snapshotConflictTiming={timeoutMs:kt,pollMs:It};snapshotDeleteTiming={timeoutMs:Ct,pollMs:Ot};constructor(t){let e={apiKey:t.apiKey,apiUrl:t.apiUrl,target:t.target,useDeprecatedPolling:true};if(t.retryCreateRequest&&!t.managedToolboxUrl)throw new Error("retryCreateRequest rides the managed door: set managedToolboxUrl with it.");this.client=t.managedToolboxUrl?new tt(e,t.managedToolboxUrl,t.retryCreateRequest):new Daytona(e),t.managedToolboxUrl&&(this.managedStream={toolboxUrl:t.managedToolboxUrl,apiKey:t.apiKey}),this.defaultTimeoutMs=t.defaultTimeoutMs??36e5,this.snapshotName=t.snapshotName??(t.managedToolboxUrl?"evolve-all":`evolve-all-${C}`);}async create(t){if(t.idleTimeoutMs!==void 0)throw new H;if(t.bootCommand!==void 0)throw new j;for(let u of t.phaseNetworkPolicies??[])O(u);let e=O(t.network),s=t.user,r=s&&s!=="root"?s:void 0,o=t.timeoutMs??this.defaultTimeoutMs,a=Math.max(1,Math.ceil(o/6e4)),i=t.image||this.snapshotName,d={envVars:t.envs,labels:t.metadata,autoStopInterval:a,autoDeleteInterval:ne,...r?{user:r}:{},...e},l,g=t.resources!==void 0&&(t.resources.cpu!==void 0||t.resources.memory!==void 0||t.resources.disk!==void 0||t.resources.gpu!==void 0||t.resources.gpuTypes!==void 0);if(this.managedStream){if(g)throw new I(i);let u=await this.client.create({snapshot:i,...d},{timeout:600});return t.workingDirectory&&await u.fs.createFolder(t.workingDirectory,"755"),s&&this.sandboxUsers.set(u.id,s),new P(u,s,this.managedStream)}let c,f;try{let u=await this.client.snapshot.get(i),m=u?.state;if(u&&Mt.has(m??"")&&(c=m),u&&(m==="active"||m==="inactive")&&g)throw new I(i);if(u&&m==="inactive"&&(m=(await z(this.client,i,u)).state),u&&At.has(m??"")&&(K(i)?f=await Pt(this.client,i,u,this.snapshotDeleteTiming):console.warn(`[daytona] Snapshot "${i}" is dead (state "${m}") but this provider cannot rebuild that name \u2014 delete it in the Daytona dashboard (Snapshots page), or rebuild it with the tooling that created it.`)),u&&m==="active")console.log(`[daytona] Using cached snapshot: ${i}`),l=await this.client.create({snapshot:i,...d},{timeout:600});else throw new Error("Snapshot not active")}catch(u){if(u instanceof I||u instanceof v)throw u;let m=rt[i]??i,p=c!==void 0&&!g;p?console.log(`[daytona] Snapshot "${i}" is mid-build (state "${c}") \u2014 joining that build rather than starting a second one.`):c!==void 0?console.log(`[daytona] Snapshot "${i}" is mid-build (state "${c}") and cannot carry the requested sizing \u2014 pulling image directly instead: ${m}`):(console.log(`[daytona] Snapshot "${i}" not found, building from image: ${m}`),console.log("[daytona] First run will take a few minutes (this only happens once)..."));try{if(f===!1)throw new Error(`dead snapshot "${i}" was not confirmed removed \u2014 not racing its removal`);let w=()=>this.client.snapshot.create({name:i,image:Image.base(m),resources:{cpu:t.resources?.cpu??4,memory:t.resources?.memory??4,disk:t.resources?.disk??10,...(t.resources?.gpu??0)>0?{gpu:t.resources.gpu}:{},...t.resources?.gpuTypes?.length?{gpuType:t.resources.gpuTypes}:{}}},{onLogs:x=>console.log(`[daytona] ${x}`)}),y=async()=>{await w(),console.log(`[daytona] Snapshot "${i}" ready (rebuilt here after a dead build).`);};if(c!==void 0){if(!p)throw new Error(`snapshot "${i}" is mid-build (state "${c}") and cannot be resized`);await this.joinInFlightSnapshotBuild(i)&&await y();}else try{await w(),console.log(`[daytona] Snapshot "${i}" ready (built here).`);}catch(x){if(!Lt(x)||g)throw x;await this.joinInFlightSnapshotBuild(i)&&await y();}l=await this.client.create({snapshot:i,...d},{timeout:600});}catch(w){if(w instanceof T||w instanceof v)throw w;console.warn(`[daytona] Snapshot creation failed, falling back to direct image: ${w instanceof Error?w.message:w}`);try{l=await this.client.create({image:m,...d,resources:{cpu:t.resources?.cpu??4,memory:t.resources?.memory??4,disk:t.resources?.disk??10,...(t.resources?.gpu??0)>0?{gpu:t.resources.gpu}:{},...t.resources?.gpuTypes?.length?{gpuType:t.resources.gpuTypes}:{}}},{timeout:600,onSnapshotCreateLogs:y=>console.log(`[daytona] ${y}`)});}catch(y){throw Yt(m)?new W(m,y):y}}}return t.workingDirectory&&await l.fs.createFolder(t.workingDirectory,"755"),s&&this.sandboxUsers.set(l.id,s),new P(l,s,this.managedStream)}async joinInFlightSnapshotBuild(t){let e=await Rt(this.client,t,this.snapshotConflictTiming);if(e===_t)return true;if(e.state==="active")return console.log(`[daytona] Snapshot "${t}" ready (built by another process) \u2014 reusing it.`),false;if(e.state==="inactive")return await z(this.client,t,e),console.log(`[daytona] Snapshot "${t}" ready (built by another process) \u2014 reusing it.`),false;if(At.has(e.state??"")&&K(t)&&await Pt(this.client,t,e,this.snapshotDeleteTiming))return true;throw new Error(`the in-flight build of snapshot "${t}" ended in state "${e.state??"unknown"}"`)}async connect(t,e){let s=await this.client.get(t);return s.state!=="started"&&await s.start(),new P(s,this.sandboxUsers.get(t),this.managedStream)}async inspect(t,e){let s=await this.getSandboxRecord(t);if(s.state!=="started")throw new _(t,"daytona",s.state??"unknown");return new P(s,e?.user??this.sandboxUsers.get(t),this.managedStream)}async getSandboxRecord(t){return this.client.get(t)}async list(t){let e=await this.paginate(t);if(e.error&&!e.stoppedAtLimit)throw new Error(e.error);return e.sandboxes}async listAll(t){let{stoppedAtLimit:e,...s}=await this.paginate(t);return s}async paginate(t){return qt(this.listStream(t),t)}listStream(t){let e=t?.state?Pe(t.state):void 0,s={limit:ae,...t?.metadata?{labels:t.metadata}:{},...e&&e.length>0?{states:e}:{}};return this.client.list(s)}};function Pe(n){let t=[];for(let e of n)e==="running"&&t.push("started"),e==="paused"&&t.push("stopped","archived","paused");return t}async function qt(n,t){let e=t?.limit,s=[],r=0,o=new Set;try{for await(let a of n){if(e!==void 0&&s.length>=e)return {sandboxes:s,complete:!1,pagesFetched:r,stoppedAtLimit:!0,error:`stopped at the requested limit of ${e} with more sandboxes available`};if(r+=1,r>B)return {sandboxes:s,complete:!1,pagesFetched:B,stoppedAtLimit:!1,error:`sandbox list exceeded ${B} sandboxes scanned`};if(t?.state){let i=Gt(a.state);if(i===void 0||!t.state.includes(i))continue}o.has(a.id)||(o.add(a.id),s.push(at(a)));}}catch(a){return {sandboxes:s,complete:false,pagesFetched:r,stoppedAtLimit:false,error:`sandbox list failed: ${a instanceof Error?a.message:String(a)}`}}return {sandboxes:s,complete:true,pagesFetched:r,stoppedAtLimit:false}}var Ne=qt;function Ue(n={}){let t=n.apiKey??process.env.DAYTONA_API_KEY;if(!t)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 st({...n,apiKey:t})}var Fe=Z,Be=V,Ye=O,Ge=Ft,We=Bt,je=Yt,He=at,qe=Gt,ze=z,Ke=Rt,Xe=Lt,Ve=K,Qe=rt,Je=Q,Ze=Nt,tn=D,en=J,nn=it,sn=jt,rn=dt,on=P,G=1024*1024;
|
|
9
|
+
export{ne as DAYTONA_AUTO_DELETE_GRACE_MINUTES,St as DAYTONA_BOOT_LABEL,ce as DAYTONA_BOOT_POLL_MS,ae as DAYTONA_LIST_PAGE_SIZE,yt as DAYTONA_MAX_DOMAIN_ALLOWLIST,B as DAYTONA_MAX_LIST_SCAN,wt as DAYTONA_MAX_NETWORK_ALLOWLIST,se as DAYTONA_SNAPSHOT_ACTIVATE_TIMEOUT_MS,kt as DAYTONA_SNAPSHOT_CONFLICT_TIMEOUT_MS,_t as DAYTONA_SNAPSHOT_GONE,oe as DAYTONA_STREAM_TIMINGS,q as DaytonaBootAbortedError,j as DaytonaBootCommandError,et as DaytonaCommands,nt as DaytonaFiles,bt as DaytonaGpuTypeError,H as DaytonaIdleTimeoutError,W as DaytonaImagePullError,b as DaytonaNetworkPolicyError,st as DaytonaProvider,I as DaytonaResourcesError,v as DaytonaSnapshotActivationError,T as DaytonaSnapshotConflictError,C as EVOLVE_IMAGE_VERSION,k as SandboxFeatureUnsupportedError,_ as SandboxNotRunningError,A as SandboxPathNotFoundError,ze as _testActivateSnapshot,Ne as _testCollectSandboxStream,nn as _testCreateLogDemuxer,en as _testCreateSentinelFilter,on as _testDaytonaSandboxImplCtor,qe as _testDaytonaStateToEvolveState,sn as _testFollowManagedSessionLogs,Qe as _testImageMap,je as _testImageRegistryHost,We as _testIsNetworkPolicyTierRefusal,Xe as _testIsSnapshotNameConflict,Ye as _testMapNetworkPolicy,Ge as _testMapNetworkPolicyForUpdate,Ve as _testProviderCanRebuildSnapshot,rn as _testReadCommandStreams,tn as _testSettledStreams,Ze as _testStripEndOfOutputSentinel,He as _testToSandboxInfo,Ke as _testWaitForSnapshotConflictWinner,Je as _testWithEndOfOutputSentinel,Be as _testWithInBoxTimeout,Fe as _testWrapCommand,Ue as createDaytonaProvider,Re as createSandboxObserved,xt as daytonaBootPhaseOf,Xt as isSandboxFeatureUnsupportedError,Qt as isSandboxNotRunningError,Vt as isSandboxPathNotFoundError,O as mapNetworkPolicy};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evolvingmachines/daytona",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.69",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"ai",
|
|
6
6
|
"agents",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"build": "tsup --minify",
|
|
34
34
|
"dev": "tsup --watch",
|
|
35
35
|
"type-check": "tsc --noEmit",
|
|
36
|
-
"test:unit": "tsx tests/unit/daytona-commands.test.ts && tsx tests/unit/daytona-provider.test.ts && tsx tests/unit/daytona-managed.test.ts && tsx tests/unit/daytona-list-pagination.test.ts && tsx tests/unit/daytona-image-version.test.ts && tsx tests/unit/daytona-image-refresh.test.ts && tsx tests/unit/daytona-files-read.test.ts && tsx tests/unit/daytona-boot-observed.test.ts && tsx tests/unit/daytona-files-observe.test.ts"
|
|
36
|
+
"test:unit": "tsx tests/unit/daytona-commands.test.ts && tsx tests/unit/daytona-provider.test.ts && tsx tests/unit/daytona-managed.test.ts && tsx tests/unit/daytona-create-request-retry.test.ts && tsx tests/unit/daytona-list-pagination.test.ts && tsx tests/unit/daytona-image-version.test.ts && tsx tests/unit/daytona-image-refresh.test.ts && tsx tests/unit/daytona-files-read.test.ts && tsx tests/unit/daytona-boot-observed.test.ts && tsx tests/unit/daytona-files-observe.test.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@daytonaio/sdk": "^0.203.0"
|