WIP: CLI running of plugs
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import type { SysCallMapping } from "../../plugos/system.ts";
|
||||
import {
|
||||
ProxyFetchRequest,
|
||||
ProxyFetchResponse,
|
||||
} from "../../common/proxy_fetch.ts";
|
||||
import { base64Encode } from "../asset_bundle/base64.ts";
|
||||
|
||||
export function sandboxFetchSyscalls(): SysCallMapping {
|
||||
return {
|
||||
"sandboxFetch.fetch": async (
|
||||
_ctx,
|
||||
url: string,
|
||||
options: ProxyFetchRequest,
|
||||
): Promise<ProxyFetchResponse> => {
|
||||
// console.log("Got sandbox fetch ", url);
|
||||
const resp = await fetch(url, options);
|
||||
return {
|
||||
status: resp.status,
|
||||
ok: resp.ok,
|
||||
headers: Object.fromEntries(resp.headers.entries()),
|
||||
base64Body: base64Encode(new Uint8Array(await resp.arrayBuffer())),
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
import type { SysCallMapping } from "../system.ts";
|
||||
|
||||
export default function (cwd: string): SysCallMapping {
|
||||
export function shellSyscalls(cwd: string): SysCallMapping {
|
||||
return {
|
||||
"shell.run": async (
|
||||
_ctx,
|
||||
cmd: string,
|
||||
args: string[],
|
||||
): Promise<{ stdout: string; stderr: string }> => {
|
||||
const p = Deno.run({
|
||||
cmd: [cmd, ...args],
|
||||
cwd: cwd,
|
||||
const p = new Deno.Command(cmd, {
|
||||
args: args,
|
||||
cwd,
|
||||
stdout: "piped",
|
||||
stderr: "piped",
|
||||
});
|
||||
await p.status();
|
||||
const stdout = new TextDecoder().decode(await p.output());
|
||||
const stderr = new TextDecoder().decode(await p.stderrOutput());
|
||||
const output = await p.output();
|
||||
const stdout = new TextDecoder().decode(output.stdout);
|
||||
const stderr = new TextDecoder().decode(output.stderr);
|
||||
|
||||
return { stdout, stderr };
|
||||
},
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { SysCallMapping } from "../system.ts";
|
||||
import { DexieKVStore } from "../lib/kv_store.dexie.ts";
|
||||
import { KV } from "../lib/kv_store.ts";
|
||||
import { KV, KVStore } from "../lib/kv_store.ts";
|
||||
|
||||
export function storeSyscalls(
|
||||
db: DexieKVStore,
|
||||
db: KVStore,
|
||||
): SysCallMapping {
|
||||
return {
|
||||
"store.delete": (_ctx, key: string) => {
|
||||
Reference in New Issue
Block a user