Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sandbox loading config via env #4

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S deno run --allow-env --allow-net --allow-sys --allow-read --allow-write --allow-ffi --allow-run --unstable-worker-options
#!/usr/bin/env -S deno run --allow-env --allow-net --allow-sys --allow-read --allow-write --allow-ffi --allow-run --unstable-worker-options --no-prompt
// TODO limit --allow-ffi to just lancedb
// TODO limit --deny-net on localhost except ollama/db
// TODO limit --allow-run needed for Deno.exit
Expand Down
3 changes: 2 additions & 1 deletion src/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ const ProjectEntrypointGen = <T extends TObject>(t: T) =>

export async function getProjectFromEntrypoint(
entrypoint: unknown,
providedConfig?: Record<string, string>,
): Promise<IProject> {
if (!entrypoint) {
throw new Error("Project entry is invalid");
}
// Validate the entrypoint
if (validateProjectEntry(entrypoint)) {
const config = loadConfigFromEnv(entrypoint.configType);
const config = loadConfigFromEnv(entrypoint.configType, providedConfig);

// Check that the constructed project is valid
const project = await entrypoint.projectFactory(config);
Expand Down
2 changes: 1 addition & 1 deletion src/sandbox/webWorker/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type IProjectJson = Omit<IProject, "tools"> & { tools: Tool[] };
// Framework -> Sandbox
export const Load = new rpc.RequestType<string, void, string>("load");
export const Init = new rpc.RequestType<
Record<string, unknown>,
Record<string, string>,
IProjectJson,
string
>("init");
Expand Down
2 changes: 1 addition & 1 deletion src/sandbox/webWorker/webWorkerSandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class WebWorkerSandbox implements ISandbox {
type: "module",
deno: {
permissions: {
env: true, // TODO limit this
env: false, // Should be passed through in loadConfigFromEnv below
// hrtime: false,
net: "inherit", // TODO remove localhost
ffi: true, // Needed for node js ffi
Expand Down
3 changes: 2 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { brightBlue } from "@std/fmt/colors";

export function loadConfigFromEnv<T extends TSchema>(
schema?: T,
envObj?: Record<string, string>,
): Static<T> | undefined {
if (!schema) return undefined;
const envObj = Deno.env.toObject();
envObj ??= Deno.env.toObject();
return Value.Parse(schema, envObj);
}

Expand Down