An open-source, faster Devin alternative
TypeScript
cli: [egress] fixed_ips = "<region>" (work 073)
Mohamed Habib via Computerb18d99a3658f
diff --git a/cli/src/api.ts b/cli/src/api.tsindex 4d2d3b2d..4f34b304 100644--- a/cli/src/api.ts+++ b/cli/src/api.ts@@ -1458,6 +1458,7 @@ export class OpenComputerClient {models: Array<{ provider: string; model: string }>;region?: string;egress?: { domains: string[]; cidrs: string[] };+ fixedIps?: string;projectDeployment?: {id: string;digest: string;diff --git a/cli/src/dev.ts b/cli/src/dev.tsindex 4780ad2a..69d6764f 100644--- a/cli/src/dev.ts+++ b/cli/src/dev.ts@@ -78,6 +78,7 @@ async function registerBuiltDeployment(models: built.models,...(built.region ? { region: built.region } : {}),...(built.egress ? { egress: built.egress } : {}),+ ...(built.fixedIps ? { fixedIps: built.fixedIps } : {}),...(projectDeployment ? { projectDeployment } : {}),source: {digest: built.digest,diff --git a/cli/src/project.test.ts b/cli/src/project.test.tsindex 8101950b..85cd43b6 100644--- a/cli/src/project.test.ts+++ b/cli/src/project.test.ts@@ -3110,7 +3110,7 @@ test("opencomputer.toml [egress] allow is split into domains and CIDRs and valid"",].join("\n"),);- const read = await readManifest(root);+ let read = await readManifest(root);assert.equal(read.region, "au");assert.deepEqual(read.egress, {domains: ["*.cypen.io", "api.github.com"],@@ -3130,6 +3130,16 @@ test("opencomputer.toml [egress] allow is split into domains and CIDRs and validawait assert.rejects(readManifest(root), /is not a domain/);await manifest('[egress]\nallow = "api.github.com"\n');await assert.rejects(readManifest(root), /allow must be a list/);+ await manifest('[egress]\nfixed_ips = "au"\n');+ assert.deepEqual(await readManifest(root), { schema: 1, id: "cypen", name: "Cypen", fixedIps: "au" });+ await manifest('[egress]\nfixed_ips = "au"\nallow = ["api.github.com"]\n');+ read = await readManifest(root);+ assert.equal(read.fixedIps, "au");+ assert.deepEqual(read.egress, { domains: ["api.github.com"], cidrs: [] });+ await manifest('[egress]\nfixed_ips = true\n');+ await assert.rejects(readManifest(root), /fixed_ips must be a region/);+ await manifest('[egress]\nfixed_ips = "Sydney"\n');+ await assert.rejects(readManifest(root), /fixed_ips must be a region/);await manifest('[egress]\ndeny = ["a.com"]\n');await assert.rejects(readManifest(root), /unknown key "deny"/);await manifest('egress = ["a.com"]\n');diff --git a/cli/src/project.ts b/cli/src/project.tsindex ea4b263f..543a20b1 100644--- a/cli/src/project.ts+++ b/cli/src/project.ts@@ -68,6 +68,8 @@ export interface AgentManifest {region?: DeploymentRegion;/** `[egress] allow`, split; absent means an open network. */egress?: DeploymentEgress;+ /** `[egress] fixed_ips`: the region whose fixed IPs sandboxes leave from. */+ fixedIps?: string;}export interface BuiltAgentArtifact {@@ -81,6 +83,7 @@ export interface BuiltAgentArtifact {models: Array<{ provider: string; model: string }>;region?: DeploymentRegion;egress?: DeploymentEgress;+ fixedIps?: string;body: Buffer;digest: string;elapsedMs: number;@@ -347,29 +350,41 @@ export async function readManifest(root: string): Promise<AgentManifest> {`opencomputer.toml region ${JSON.stringify(region)} is not supported; use one of: ${DEPLOYMENT_REGIONS.join(", ")}`,);}- const egress = manifestEgress(toml.egress);+ const { egress, fixedIps } = manifestEgress(toml.egress);return {schema: 1,id,name,...(region ? { region: region as DeploymentRegion } : {}),...(egress ? { egress } : {}),+ ...(fixedIps ? { fixedIps } : {}),};}-/** The `[egress]` table, or undefined when the manifest has none. */-function manifestEgress(table: unknown): DeploymentEgress | undefined {- if (table === undefined) return undefined;+/**+ * The `[egress]` table. `allow` restricts the network; `fixed_ips` sends it+ * out through a region's fixed IPs (the service lists them at+ * /v1/egress-ips and refuses a region without them). With `fixed_ips` and no+ * `allow` the network stays open; a table with neither allows only the+ * platform's own hosts.+ */+function manifestEgress(table: unknown): { egress?: DeploymentEgress; fixedIps?: string } {+ if (table === undefined) return {};if (typeof table !== "object" || table === null || Array.isArray(table)) {throw new Error("opencomputer.toml egress must be a table: [egress]");}- const unknown = Object.keys(table).filter((key) => key !== "allow");+ const unknown = Object.keys(table).filter((key) => key !== "allow" && key !== "fixed_ips");if (unknown.length) {throw new Error(- `opencomputer.toml [egress] has unknown key ${JSON.stringify(unknown[0])}; only allow is supported`,+ `opencomputer.toml [egress] has unknown key ${JSON.stringify(unknown[0])}; only allow and fixed_ips are supported`,);}- return splitEgressAllow((table as { allow?: unknown }).allow ?? []);+ const { allow, fixed_ips: fixedIps } = table as { allow?: unknown; fixed_ips?: unknown };+ if (fixedIps !== undefined && (typeof fixedIps !== "string" || !/^[a-z]{2,3}$/.test(fixedIps))) {+ throw new Error('opencomputer.toml [egress] fixed_ips must be a region, e.g. fixed_ips = "au"');+ }+ if (fixedIps === undefined) return { egress: splitEgressAllow(allow ?? []) };+ return { ...(allow !== undefined ? { egress: splitEgressAllow(allow) } : {}), fixedIps };}export async function findAgentRoot(@@ -3986,6 +4001,7 @@ export async function buildAgentArtifact(models,...(manifest.region ? { region: manifest.region } : {}),...(manifest.egress ? { egress: manifest.egress } : {}),+ ...(manifest.fixedIps ? { fixedIps: manifest.fixedIps } : {}),body,digest: createHash("sha256").update(body).digest("hex"),elapsedMs: Math.round(performance.now() - startedAt),diff --git a/cli/src/template.ts b/cli/src/template.tsindex a588597c..200852f5 100644--- a/cli/src/template.ts+++ b/cli/src/template.ts@@ -55,6 +55,7 @@ export interface TemplateBuildArtifact {models: Array<{ provider: string; model: string }>;region?: string;egress?: { domains: string[]; cidrs: string[] };+ fixedIps?: string;}export interface TemplateBuildBundle {@@ -336,6 +337,7 @@ export async function buildTemplateProject(models: built.models,...(built.region ? { region: built.region } : {}),...(built.egress ? { egress: built.egress } : {}),+ ...(built.fixedIps ? { fixedIps: built.fixedIps } : {}),});for (const connection of built.connections)compiledConnections.add(connection);