@flue/sdk 0.1.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/LICENSE +200 -0
- package/README.md +194 -0
- package/dist/client.d.mts +30 -0
- package/dist/client.mjs +62 -0
- package/dist/cloudflare/index.d.mts +36 -0
- package/dist/cloudflare/index.mjs +206 -0
- package/dist/index.d.mts +26 -0
- package/dist/index.mjs +775 -0
- package/dist/sandbox.d.mts +28 -0
- package/dist/sandbox.mjs +101 -0
- package/dist/session-BD0MEuO3.mjs +1300 -0
- package/dist/types-xNvqlohs.d.mts +327 -0
- package/package.json +50 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { b as SessionEnv, c as CommandDef, r as BashLike, u as FileStat, v as SandboxFactory, w as ShellResult } from "./types-xNvqlohs.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/sandbox.d.ts
|
|
4
|
+
declare function bashToSessionEnv(bash: BashLike): SessionEnv;
|
|
5
|
+
/** Interface that remote sandbox providers must implement. */
|
|
6
|
+
interface SandboxApi {
|
|
7
|
+
readFile(path: string): Promise<string>;
|
|
8
|
+
readFileBuffer(path: string): Promise<Uint8Array>;
|
|
9
|
+
writeFile(path: string, content: string | Uint8Array): Promise<void>;
|
|
10
|
+
stat(path: string): Promise<FileStat>;
|
|
11
|
+
readdir(path: string): Promise<string[]>;
|
|
12
|
+
exists(path: string): Promise<boolean>;
|
|
13
|
+
mkdir(path: string, options?: {
|
|
14
|
+
recursive?: boolean;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
rm(path: string, options?: {
|
|
17
|
+
recursive?: boolean;
|
|
18
|
+
force?: boolean;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
exec(command: string, options?: {
|
|
21
|
+
cwd?: string;
|
|
22
|
+
env?: Record<string, string>;
|
|
23
|
+
}): Promise<ShellResult>;
|
|
24
|
+
}
|
|
25
|
+
/** Wrap a SandboxApi into SessionEnv. No just-bash, no intermediate filesystem layer. */
|
|
26
|
+
declare function createSandboxSessionEnv(api: SandboxApi, cwd: string, cleanup?: () => Promise<void>): SessionEnv;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { type CommandDef, type FileStat, SandboxApi, type SandboxFactory, type SessionEnv, bashToSessionEnv, createSandboxSessionEnv };
|
package/dist/sandbox.mjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { r as normalizePath } from "./session-BD0MEuO3.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/sandbox.ts
|
|
4
|
+
function bashToSessionEnv(bash) {
|
|
5
|
+
const fs = bash.fs;
|
|
6
|
+
const cwd = bash.getCwd();
|
|
7
|
+
const resolve = (p) => p.startsWith("/") ? p : fs.resolvePath(cwd, p);
|
|
8
|
+
let commandSupport;
|
|
9
|
+
if (typeof bash.registerCommand === "function") {
|
|
10
|
+
const registerCommand = bash.registerCommand.bind(bash);
|
|
11
|
+
commandSupport = {
|
|
12
|
+
register(cmd) {
|
|
13
|
+
registerCommand({
|
|
14
|
+
name: cmd.name,
|
|
15
|
+
execute: cmd.execute
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
unregister(name) {
|
|
19
|
+
registerCommand({
|
|
20
|
+
name,
|
|
21
|
+
execute: async () => ({
|
|
22
|
+
stdout: "",
|
|
23
|
+
stderr: name + ": command not available (not registered for this call)",
|
|
24
|
+
exitCode: 127
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
exec: (cmd, opts) => bash.exec(cmd, opts),
|
|
32
|
+
readFile: (p) => fs.readFile(resolve(p)),
|
|
33
|
+
readFileBuffer: (p) => fs.readFileBuffer(resolve(p)),
|
|
34
|
+
writeFile: async (p, content) => {
|
|
35
|
+
const resolved = resolve(p);
|
|
36
|
+
const dir = resolved.replace(/\/[^/]*$/, "");
|
|
37
|
+
if (dir && dir !== resolved) try {
|
|
38
|
+
await fs.mkdir(dir, { recursive: true });
|
|
39
|
+
} catch {}
|
|
40
|
+
await fs.writeFile(resolved, content);
|
|
41
|
+
},
|
|
42
|
+
stat: (p) => fs.stat(resolve(p)),
|
|
43
|
+
readdir: (p) => fs.readdir(resolve(p)),
|
|
44
|
+
exists: (p) => fs.exists(resolve(p)),
|
|
45
|
+
mkdir: (p, o) => fs.mkdir(resolve(p), o),
|
|
46
|
+
rm: (p, o) => fs.rm(resolve(p), o),
|
|
47
|
+
cwd,
|
|
48
|
+
resolvePath: resolve,
|
|
49
|
+
commandSupport,
|
|
50
|
+
cleanup: async () => {}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Wrap a SandboxApi into SessionEnv. No just-bash, no intermediate filesystem layer. */
|
|
54
|
+
function createSandboxSessionEnv(api, cwd, cleanup) {
|
|
55
|
+
const resolvePath = (p) => {
|
|
56
|
+
if (p.startsWith("/")) return normalizePath(p);
|
|
57
|
+
if (cwd === "/") return normalizePath("/" + p);
|
|
58
|
+
return normalizePath(cwd + "/" + p);
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
async exec(command, options) {
|
|
62
|
+
return api.exec(command, {
|
|
63
|
+
cwd: options?.cwd ?? cwd,
|
|
64
|
+
env: options?.env
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
async readFile(path) {
|
|
68
|
+
return api.readFile(resolvePath(path));
|
|
69
|
+
},
|
|
70
|
+
async readFileBuffer(path) {
|
|
71
|
+
return api.readFileBuffer(resolvePath(path));
|
|
72
|
+
},
|
|
73
|
+
async writeFile(path, content) {
|
|
74
|
+
return api.writeFile(resolvePath(path), content);
|
|
75
|
+
},
|
|
76
|
+
async stat(path) {
|
|
77
|
+
return api.stat(resolvePath(path));
|
|
78
|
+
},
|
|
79
|
+
async readdir(path) {
|
|
80
|
+
return api.readdir(resolvePath(path));
|
|
81
|
+
},
|
|
82
|
+
async exists(path) {
|
|
83
|
+
return api.exists(resolvePath(path));
|
|
84
|
+
},
|
|
85
|
+
async mkdir(path, options) {
|
|
86
|
+
return api.mkdir(resolvePath(path), options);
|
|
87
|
+
},
|
|
88
|
+
async rm(path, options) {
|
|
89
|
+
return api.rm(resolvePath(path), options);
|
|
90
|
+
},
|
|
91
|
+
cwd,
|
|
92
|
+
resolvePath,
|
|
93
|
+
commandSupport: void 0,
|
|
94
|
+
async cleanup() {
|
|
95
|
+
if (cleanup) await cleanup();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
export { bashToSessionEnv, createSandboxSessionEnv };
|