@uibot/execution-microsandbox 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/microsandbox-runtime.d.ts +4 -0
- package/dist/types.d.ts +53 -0
- package/package.json +43 -4
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { createMicrosandboxRuntime, type MicrosandboxRuntime, } from "./microsandbox-runtime.js";
|
|
2
|
+
export type { MicrosandboxRuntimeOptions, MicrosandboxLoader, MicrosandboxModule, MicrosandboxSandboxCreateOptions, MicrosandboxSandboxInstance, MicrosandboxSandboxOutput, MicrosandboxSandboxStatic, } from "./types.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var A={javascript:"node",typescript:"node",python:"python",shell:"bash"};function D(){return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function C(t,r,a){switch(t){case"javascript":{let o=Buffer.from(r,"utf8").toString("base64"),c=`__UIBOT_RETURN_${a}__:`;return{cmd:"node",args:["-e",`(async()=>{const __src=Buffer.from("${o}","base64").toString("utf8");const __f=new Function("return (async()=>{"+__src+"\\n})();");let __r;try{__r=await __f();}catch(e){process.stderr.write(String(e&&e.stack||e));process.exit(1);}if(__r!==undefined)process.stdout.write("\\n${c}"+JSON.stringify(__r));})();`]}}case"typescript":return{cmd:"node",args:["-e",r]};case"python":return{cmd:"python",args:["-c",r]};case"shell":return{cmd:"bash",args:["-c",r]}}}function P(t,r){let a=`__UIBOT_RETURN_${r}__:`,o=t.lastIndexOf(a);if(o===-1)return{stdout:t,returnValue:void 0};let c=t.slice(0,o).replace(/\n$/,""),n=t.slice(o+a.length).trim();try{return{stdout:c,returnValue:JSON.parse(n)}}catch{return{stdout:t,returnValue:void 0}}}function k(){return import("microsandbox")}function F(t={}){let r=t.__loader??k,a=t.defaultTimeoutMs??30000,o=t.defaultMemoryMib??256,c=t.defaultCpus??1,n=null;async function R(){if(!n)n=r();try{return await n}catch(e){return n=null,{errorMessage:e instanceof Error?e.message:String(e)}}}return{async run(e){let i=Date.now();if(!e.code||e.code.trim().length===0)return{success:!1,stdout:"",stderr:"",durationMs:0,errorCode:"bad-input",errorMessage:"code is empty"};let d=await R();if("errorMessage"in d)return{success:!1,stdout:"",stderr:"",durationMs:Date.now()-i,errorCode:"runtime-not-installed",errorMessage:`microsandbox package not installed: ${d.errorMessage}`};let w=t.sandboxImage??A[e.language],S=e.memoryMib??o,m=e.timeout??a,M=D(),{cmd:T,args:h}=C(e.language,e.code,M),x={...e.env??{}};if(e.fetchAllowed===!0)x.UIBOT_FETCH_ALLOWED="1";let u=null;try{u=await d.Sandbox.create({name:`uibot-${i}`,image:w,cpus:c,memoryMib:S});let s=null,I=u.exec(T,h,{env:x}),L=new Promise((U)=>{s=setTimeout(()=>U("__timeout__"),m)}),f=await Promise.race([I,L]);if(s)clearTimeout(s);if(f==="__timeout__")return{success:!1,stdout:"",stderr:"",durationMs:Date.now()-i,errorCode:"exec-timeout",errorMessage:`execution exceeded ${m}ms`};let l=f,g=l.stdout(),_=l.stderr(),b=l.exitCode??0,O=b===0,{stdout:p,returnValue:y}=e.language==="javascript"?P(g,M):{stdout:g,returnValue:void 0};if(!O)return{success:!1,stdout:p,stderr:_,durationMs:Date.now()-i,errorCode:"exec-failed",errorMessage:`sandbox exited with code ${b}`};let E={success:!0,stdout:p,stderr:_,durationMs:Date.now()-i};if(y!==void 0)E.returnValue=y;return E}catch(s){return{success:!1,stdout:"",stderr:"",durationMs:Date.now()-i,errorCode:"internal-error",errorMessage:s instanceof Error?s.message:String(s)}}finally{if(u)await u.stopAndWait().catch(()=>{return})}},async dispose(){n=null}}}export{F as createMicrosandboxRuntime};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ExecutionRuntime } from "@uibot/contracts";
|
|
2
|
+
import type { MicrosandboxRuntimeOptions } from "./types.js";
|
|
3
|
+
export type MicrosandboxRuntime = ExecutionRuntime;
|
|
4
|
+
export declare function createMicrosandboxRuntime(options?: MicrosandboxRuntimeOptions): MicrosandboxRuntime;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal structural types describing the slice of the `microsandbox` Node
|
|
3
|
+
* SDK that `createMicrosandboxRuntime` depends on. Kept narrow so tests can
|
|
4
|
+
* stub the module without pulling in the real SDK.
|
|
5
|
+
*
|
|
6
|
+
* Upstream shape (v0.3.14, beta — captured 2026-04-19):
|
|
7
|
+
* const sb = await Sandbox.create({ image, cpus, memoryMib });
|
|
8
|
+
* const out = await sb.exec("node", ["-e", code]);
|
|
9
|
+
* out.stdout(); // string (method, not property)
|
|
10
|
+
* out.stderr(); // string
|
|
11
|
+
* await sb.stopAndWait();
|
|
12
|
+
*/
|
|
13
|
+
export interface MicrosandboxSandboxOutput {
|
|
14
|
+
stdout(): string;
|
|
15
|
+
stderr(): string;
|
|
16
|
+
exitCode?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface MicrosandboxExecOptions {
|
|
19
|
+
env?: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
export interface MicrosandboxSandboxInstance {
|
|
22
|
+
exec(cmd: string, args: string[], options?: MicrosandboxExecOptions): Promise<MicrosandboxSandboxOutput>;
|
|
23
|
+
stopAndWait(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export interface MicrosandboxSandboxCreateOptions {
|
|
26
|
+
name?: string;
|
|
27
|
+
image: string;
|
|
28
|
+
cpus?: number;
|
|
29
|
+
memoryMib?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface MicrosandboxSandboxStatic {
|
|
32
|
+
create(options: MicrosandboxSandboxCreateOptions): Promise<MicrosandboxSandboxInstance>;
|
|
33
|
+
}
|
|
34
|
+
export interface MicrosandboxModule {
|
|
35
|
+
Sandbox: MicrosandboxSandboxStatic;
|
|
36
|
+
}
|
|
37
|
+
/** Loader shape — the runtime calls this once, lazily, to obtain the SDK. */
|
|
38
|
+
export type MicrosandboxLoader = () => Promise<MicrosandboxModule>;
|
|
39
|
+
export interface MicrosandboxRuntimeOptions {
|
|
40
|
+
/** OCI image override for non-default languages. Rarely needed. */
|
|
41
|
+
sandboxImage?: string;
|
|
42
|
+
/** Default execution deadline (ms). Falls through to 30_000 when absent. */
|
|
43
|
+
defaultTimeoutMs?: number;
|
|
44
|
+
/** Default memory limit (MiB). Falls through to 256 when absent. */
|
|
45
|
+
defaultMemoryMib?: number;
|
|
46
|
+
/** Default CPU count. Falls through to 1. */
|
|
47
|
+
defaultCpus?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Test / DI hook for providing a pre-resolved SDK. When omitted the runtime
|
|
50
|
+
* dynamically imports `microsandbox`. Underscored to mark as internal.
|
|
51
|
+
*/
|
|
52
|
+
__loader?: MicrosandboxLoader;
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uibot/execution-microsandbox",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/Foundj/uibot.git",
|
|
8
|
+
"directory": "packages/execution-microsandbox"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"!dist/**/*.map",
|
|
23
|
+
"!dist/**/*.test.d.ts",
|
|
24
|
+
"!dist/**/*.spec.d.ts"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@uibot/contracts": "^0.2.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"microsandbox": "^0.3.14"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"microsandbox": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "rm -rf dist && bun build --minify ./src/index.ts --outdir ./dist --format esm --target bun && bun x tsc -p tsconfig.json",
|
|
42
|
+
"typecheck": "bun x tsc -p tsconfig.json --noEmit",
|
|
43
|
+
"test": "bun test"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/README.md
DELETED