@flue/sdk 0.2.0 → 0.3.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/README.md +135 -15
- package/package.json +2 -2
- package/dist/agent-BYG0nVbQ.mjs +0 -432
- package/dist/client.d.mts +0 -25
- package/dist/client.mjs +0 -59
- package/dist/cloudflare/index.d.mts +0 -40
- package/dist/cloudflare/index.mjs +0 -230
- package/dist/command-helpers-C8SHLdaA.d.mts +0 -21
- package/dist/command-helpers-CxRhK1my.mjs +0 -37
- package/dist/index.d.mts +0 -35
- package/dist/index.mjs +0 -1001
- package/dist/internal.d.mts +0 -15
- package/dist/internal.mjs +0 -6
- package/dist/node/index.d.mts +0 -14
- package/dist/node/index.mjs +0 -75
- package/dist/sandbox.d.mts +0 -28
- package/dist/sandbox.mjs +0 -102
- package/dist/session-CiAMTsLZ.mjs +0 -943
- package/dist/types-C0nqbu6Z.d.mts +0 -358
package/dist/internal.d.mts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { S as SessionStore, y as SessionData } from "./types-C0nqbu6Z.mjs";
|
|
2
|
-
import { FlueContextConfig, FlueContextInternal, createFlueContext } from "./client.mjs";
|
|
3
|
-
import { bashToSessionEnv } from "./sandbox.mjs";
|
|
4
|
-
import "valibot";
|
|
5
|
-
|
|
6
|
-
//#region src/session.d.ts
|
|
7
|
-
/** In-memory session store. Sessions persist for the lifetime of the process. */
|
|
8
|
-
declare class InMemorySessionStore implements SessionStore {
|
|
9
|
-
private store;
|
|
10
|
-
save(id: string, data: SessionData): Promise<void>;
|
|
11
|
-
load(id: string): Promise<SessionData | null>;
|
|
12
|
-
delete(id: string): Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
//#endregion
|
|
15
|
-
export { type FlueContextConfig, type FlueContextInternal, InMemorySessionStore, bashToSessionEnv, createFlueContext };
|
package/dist/internal.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import "./agent-BYG0nVbQ.mjs";
|
|
2
|
-
import { t as InMemorySessionStore } from "./session-CiAMTsLZ.mjs";
|
|
3
|
-
import { bashToSessionEnv } from "./sandbox.mjs";
|
|
4
|
-
import { createFlueContext } from "./client.mjs";
|
|
5
|
-
|
|
6
|
-
export { InMemorySessionStore, bashToSessionEnv, createFlueContext };
|
package/dist/node/index.d.mts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { s as Command } from "../types-C0nqbu6Z.mjs";
|
|
2
|
-
import { t as CommandExecutor } from "../command-helpers-C8SHLdaA.mjs";
|
|
3
|
-
import { execFile } from "node:child_process";
|
|
4
|
-
|
|
5
|
-
//#region src/node/define-command.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* Options forwarded directly to Node's `child_process.execFile`. Full pass-through.
|
|
8
|
-
*/
|
|
9
|
-
type CommandOptions = NonNullable<Parameters<typeof execFile>[2]>;
|
|
10
|
-
declare function defineCommand(name: string): Command;
|
|
11
|
-
declare function defineCommand(name: string, options: CommandOptions): Command;
|
|
12
|
-
declare function defineCommand(name: string, execute: CommandExecutor): Command;
|
|
13
|
-
//#endregion
|
|
14
|
-
export { type CommandOptions, defineCommand };
|
package/dist/node/index.mjs
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { t as normalizeExecutor } from "../command-helpers-CxRhK1my.mjs";
|
|
2
|
-
import { execFile } from "node:child_process";
|
|
3
|
-
import { promisify } from "node:util";
|
|
4
|
-
|
|
5
|
-
//#region src/node/define-command.ts
|
|
6
|
-
/**
|
|
7
|
-
* Node-specific `defineCommand`. Supports three forms:
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* defineCommand('agent-browser');
|
|
11
|
-
* defineCommand('gh', { env: { GH_TOKEN: process.env.GH_TOKEN } });
|
|
12
|
-
* defineCommand('gh', async (args) => ({ stdout: '...' }));
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* Forms A and B shell out via `child_process.execFile`. Form C lets the user
|
|
16
|
-
* implement the command however they like. All three forms benefit from
|
|
17
|
-
* return-shape normalization and throw-catching — no `try`/`catch` or
|
|
18
|
-
* `return { stdout, stderr, exitCode: 0 }` boilerplate required.
|
|
19
|
-
*/
|
|
20
|
-
const execFileAsync = promisify(execFile);
|
|
21
|
-
/**
|
|
22
|
-
* Essential, non-sensitive environment variables automatically forwarded to
|
|
23
|
-
* pass-through commands (forms A and B). Users can override any of these —
|
|
24
|
-
* or add their own (e.g. `GH_TOKEN`) — via `options.env`. Anything not listed
|
|
25
|
-
* here (API keys, tokens, secrets, etc.) stays on the host and is NEVER
|
|
26
|
-
* exposed to the spawned process unless the caller opts in explicitly.
|
|
27
|
-
*
|
|
28
|
-
* If you need full control over the env, use the function form:
|
|
29
|
-
* `defineCommand('gh', async (args) => { ... })`.
|
|
30
|
-
*/
|
|
31
|
-
const DEFAULT_ENV = {
|
|
32
|
-
PATH: process.env.PATH,
|
|
33
|
-
HOME: process.env.HOME,
|
|
34
|
-
USER: process.env.USER,
|
|
35
|
-
LOGNAME: process.env.LOGNAME,
|
|
36
|
-
HOSTNAME: process.env.HOSTNAME,
|
|
37
|
-
SHELL: process.env.SHELL,
|
|
38
|
-
LANG: process.env.LANG,
|
|
39
|
-
LC_ALL: process.env.LC_ALL,
|
|
40
|
-
LC_CTYPE: process.env.LC_CTYPE,
|
|
41
|
-
TZ: process.env.TZ,
|
|
42
|
-
TERM: process.env.TERM,
|
|
43
|
-
TMPDIR: process.env.TMPDIR,
|
|
44
|
-
TMP: process.env.TMP,
|
|
45
|
-
TEMP: process.env.TEMP
|
|
46
|
-
};
|
|
47
|
-
function defineCommand(name, arg) {
|
|
48
|
-
if (typeof arg === "function") return {
|
|
49
|
-
name,
|
|
50
|
-
execute: normalizeExecutor(arg)
|
|
51
|
-
};
|
|
52
|
-
const userOpts = arg ?? {};
|
|
53
|
-
const mergedOpts = {
|
|
54
|
-
maxBuffer: 50 * 1024 * 1024,
|
|
55
|
-
...userOpts,
|
|
56
|
-
env: {
|
|
57
|
-
...DEFAULT_ENV,
|
|
58
|
-
...userOpts.env ?? {}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const executor = async (args) => {
|
|
62
|
-
const { stdout, stderr } = await execFileAsync(name, args, mergedOpts);
|
|
63
|
-
return {
|
|
64
|
-
stdout: String(stdout ?? ""),
|
|
65
|
-
stderr: String(stderr ?? "")
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
return {
|
|
69
|
-
name,
|
|
70
|
-
execute: normalizeExecutor(executor)
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
//#endregion
|
|
75
|
-
export { defineCommand };
|
package/dist/sandbox.d.mts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { b as SessionEnv, c as CommandDef, r as BashLike, u as FileStat, v as SandboxFactory, w as ShellResult } from "./types-C0nqbu6Z.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
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import "./agent-BYG0nVbQ.mjs";
|
|
2
|
-
import { r as normalizePath } from "./session-CiAMTsLZ.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/sandbox.ts
|
|
5
|
-
function bashToSessionEnv(bash) {
|
|
6
|
-
const fs = bash.fs;
|
|
7
|
-
const cwd = bash.getCwd();
|
|
8
|
-
const resolve = (p) => p.startsWith("/") ? p : fs.resolvePath(cwd, p);
|
|
9
|
-
let commandSupport;
|
|
10
|
-
if (typeof bash.registerCommand === "function") {
|
|
11
|
-
const registerCommand = bash.registerCommand.bind(bash);
|
|
12
|
-
commandSupport = {
|
|
13
|
-
register(cmd) {
|
|
14
|
-
registerCommand({
|
|
15
|
-
name: cmd.name,
|
|
16
|
-
execute: cmd.execute
|
|
17
|
-
});
|
|
18
|
-
},
|
|
19
|
-
unregister(name) {
|
|
20
|
-
registerCommand({
|
|
21
|
-
name,
|
|
22
|
-
execute: async () => ({
|
|
23
|
-
stdout: "",
|
|
24
|
-
stderr: name + ": command not available (not registered for this call)",
|
|
25
|
-
exitCode: 127
|
|
26
|
-
})
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
exec: (cmd, opts) => bash.exec(cmd, opts),
|
|
33
|
-
readFile: (p) => fs.readFile(resolve(p)),
|
|
34
|
-
readFileBuffer: (p) => fs.readFileBuffer(resolve(p)),
|
|
35
|
-
writeFile: async (p, content) => {
|
|
36
|
-
const resolved = resolve(p);
|
|
37
|
-
const dir = resolved.replace(/\/[^/]*$/, "");
|
|
38
|
-
if (dir && dir !== resolved) try {
|
|
39
|
-
await fs.mkdir(dir, { recursive: true });
|
|
40
|
-
} catch {}
|
|
41
|
-
await fs.writeFile(resolved, content);
|
|
42
|
-
},
|
|
43
|
-
stat: (p) => fs.stat(resolve(p)),
|
|
44
|
-
readdir: (p) => fs.readdir(resolve(p)),
|
|
45
|
-
exists: (p) => fs.exists(resolve(p)),
|
|
46
|
-
mkdir: (p, o) => fs.mkdir(resolve(p), o),
|
|
47
|
-
rm: (p, o) => fs.rm(resolve(p), o),
|
|
48
|
-
cwd,
|
|
49
|
-
resolvePath: resolve,
|
|
50
|
-
commandSupport,
|
|
51
|
-
cleanup: async () => {}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/** Wrap a SandboxApi into SessionEnv. No just-bash, no intermediate filesystem layer. */
|
|
55
|
-
function createSandboxSessionEnv(api, cwd, cleanup) {
|
|
56
|
-
const resolvePath = (p) => {
|
|
57
|
-
if (p.startsWith("/")) return normalizePath(p);
|
|
58
|
-
if (cwd === "/") return normalizePath("/" + p);
|
|
59
|
-
return normalizePath(cwd + "/" + p);
|
|
60
|
-
};
|
|
61
|
-
return {
|
|
62
|
-
async exec(command, options) {
|
|
63
|
-
return api.exec(command, {
|
|
64
|
-
cwd: options?.cwd ?? cwd,
|
|
65
|
-
env: options?.env
|
|
66
|
-
});
|
|
67
|
-
},
|
|
68
|
-
async readFile(path) {
|
|
69
|
-
return api.readFile(resolvePath(path));
|
|
70
|
-
},
|
|
71
|
-
async readFileBuffer(path) {
|
|
72
|
-
return api.readFileBuffer(resolvePath(path));
|
|
73
|
-
},
|
|
74
|
-
async writeFile(path, content) {
|
|
75
|
-
return api.writeFile(resolvePath(path), content);
|
|
76
|
-
},
|
|
77
|
-
async stat(path) {
|
|
78
|
-
return api.stat(resolvePath(path));
|
|
79
|
-
},
|
|
80
|
-
async readdir(path) {
|
|
81
|
-
return api.readdir(resolvePath(path));
|
|
82
|
-
},
|
|
83
|
-
async exists(path) {
|
|
84
|
-
return api.exists(resolvePath(path));
|
|
85
|
-
},
|
|
86
|
-
async mkdir(path, options) {
|
|
87
|
-
return api.mkdir(resolvePath(path), options);
|
|
88
|
-
},
|
|
89
|
-
async rm(path, options) {
|
|
90
|
-
return api.rm(resolvePath(path), options);
|
|
91
|
-
},
|
|
92
|
-
cwd,
|
|
93
|
-
resolvePath,
|
|
94
|
-
commandSupport: void 0,
|
|
95
|
-
async cleanup() {
|
|
96
|
-
if (cleanup) await cleanup();
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
//#endregion
|
|
102
|
-
export { bashToSessionEnv, createSandboxSessionEnv };
|