An open-source, faster Devin alternative
TypeScript
Deployment region from opencomputer.toml (#872)
calvin-by-opencomputer[bot]4c861ff93620
diff --git a/cli/src/api.ts b/cli/src/api.tsindex c76c9626..2e9ba8f2 100644--- a/cli/src/api.ts+++ b/cli/src/api.ts@@ -1447,6 +1447,7 @@ export class OpenComputerClient {}>;memory: MemoryDeclaration[];models: Array<{ provider: string; model: string }>;+ region?: string;projectDeployment?: {id: string;digest: string;diff --git a/cli/src/dev.ts b/cli/src/dev.tsindex f127b39f..ba70a716 100644--- a/cli/src/dev.ts+++ b/cli/src/dev.ts@@ -76,6 +76,7 @@ async function registerBuiltDeployment(githubConnections: built.githubConnections,memory: built.memory,models: built.models,+ ...(built.region ? { region: built.region } : {}),...(projectDeployment ? { projectDeployment } : {}),source: {digest: built.digest,diff --git a/cli/src/project.test.ts b/cli/src/project.test.tsindex 0bd4ad6c..cb8fe361 100644--- a/cli/src/project.test.ts+++ b/cli/src/project.test.ts@@ -19,6 +19,7 @@ import {initializeAgentProject,agentRuntimeDirectory,prepareAgent,+ readManifest,readProjectResources,} from "./project.js";@@ -3060,3 +3061,24 @@ test("prepareAgent builds into a cache under node_modules, never into the agent'await rm(root, { recursive: true, force: true });}});++test("opencomputer.toml region is optional, accepts au, and rejects anything else", async () => {+ const root = await mkdtemp(resolve(tmpdir(), "opencomputer-region-"));+ const manifest = (extra: string) =>+ writeFile(+ resolve(root, "opencomputer.toml"),+ `schema = 1\nid = "cypen"\nname = "Cypen"\n${extra}`,+ );+ try {+ await manifest("");+ assert.equal((await readManifest(root)).region, undefined);+ await manifest('region = "au"\n');+ assert.equal((await readManifest(root)).region, "au");+ await manifest('region = "us-east-1"\n');+ await assert.rejects(readManifest(root), /region "us-east-1" is not supported; use one of: au/);+ await manifest("region = au\n");+ await assert.rejects(readManifest(root), /region must be a quoted string/);+ } finally {+ await rm(root, { recursive: true, force: true });+ }+});diff --git a/cli/src/project.ts b/cli/src/project.tsindex 3ec8505c..7e17cce8 100644--- a/cli/src/project.ts+++ b/cli/src/project.ts@@ -28,10 +28,16 @@ import {type MemoryProvider,} from "./memory.js";+/** Regions a deployment may name in `opencomputer.toml` (work 057). */+export const DEPLOYMENT_REGIONS = ["au"] as const;+export type DeploymentRegion = (typeof DEPLOYMENT_REGIONS)[number];+export interface AgentManifest {schema: 1;id: string;name: string;+ /** Where the deployment's sessions run; absent means the platform default. */+ region?: DeploymentRegion;}export interface BuiltAgentArtifact {@@ -43,6 +49,7 @@ export interface BuiltAgentArtifact {githubConnections: GitHubConnectionManifest[];memory: MemoryDeclaration[];models: Array<{ provider: string; model: string }>;+ region?: DeploymentRegion;body: Buffer;digest: string;elapsedMs: number;@@ -295,10 +302,23 @@ export async function readManifest(root: string): Promise<AgentManifest> {"opencomputer.toml must contain schema = 1 and a valid id and name",);}+ const region = tomlString(source, "region");+ if (/^\s*region\s*=/m.test(source) && region === undefined) {+ throw new Error('opencomputer.toml region must be a quoted string, e.g. region = "au"');+ }+ if (+ region !== undefined &&+ !(DEPLOYMENT_REGIONS as readonly string[]).includes(region)+ ) {+ throw new Error(+ `opencomputer.toml region ${JSON.stringify(region)} is not supported; use one of: ${DEPLOYMENT_REGIONS.join(", ")}`,+ );+ }return {schema: 1,id,name,+ ...(region ? { region: region as DeploymentRegion } : {}),};}@@ -3914,6 +3934,7 @@ export async function buildAgentArtifact(githubConnections,memory,models,+ ...(manifest.region ? { region: manifest.region } : {}),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 063a7185..67127d1a 100644--- a/cli/src/template.ts+++ b/cli/src/template.ts@@ -53,6 +53,7 @@ export interface TemplateBuildArtifact {githubConnections: GitHubConnectionManifest[];memory: MemoryDeclaration[];models: Array<{ provider: string; model: string }>;+ region?: string;}export interface TemplateBuildBundle {@@ -332,6 +333,7 @@ export async function buildTemplateProject(githubConnections: built.githubConnections,memory: built.memory,models: built.models,+ ...(built.region ? { region: built.region } : {}),});for (const connection of built.connections)compiledConnections.add(connection);diff --git a/cloudflare-workers/api-edge/src/managed_agents.test.ts b/cloudflare-workers/api-edge/src/managed_agents.test.tsindex 4db813ab..4ff571e2 100644--- a/cloudflare-workers/api-edge/src/managed_agents.test.ts+++ b/cloudflare-workers/api-edge/src/managed_agents.test.ts@@ -3108,6 +3108,7 @@ describe("managed agents proxy", () => {},],createdAt: "2026-07-30T00:00:00.000Z",+ region: "au",artifact: { bucket: "private-bucket" },imageArn: "arn:aws:private",},@@ -3166,6 +3167,7 @@ describe("managed agents proxy", () => {model: "anthropic/claude-sonnet-5",},],+ region: "au",source: {digest,size: source.length,@@ -3230,7 +3232,12 @@ describe("managed agents proxy", () => {},],});- expect(JSON.stringify(await response.json())).not.toMatch(+ expect(+ JSON.parse(String((fetchSpy.mock.calls[2]?.[1] as RequestInit).body)),+ ).toMatchObject({ region: "au" });+ const published = await response.json();+ expect(published).toMatchObject({ region: "au" });+ expect(JSON.stringify(published)).not.toMatch(/bucket|imageArn|arn:aws|uploads\.test/i,);});diff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.tsindex ef56038e..c046004b 100644--- a/cloudflare-workers/api-edge/src/managed_agents.ts+++ b/cloudflare-workers/api-edge/src/managed_agents.ts@@ -314,7 +314,9 @@ async function publicErrorResponse(? "externalReference must be a non-empty string of at most 256 bytes of UTF-8 without control characters.": backendCode === "invalid_cursor"? "The cursor is invalid or was issued for different filters. Start again from the first page."- : "The agent request was invalid.";+ : backendCode === "unsupported_region"+ ? 'The region in opencomputer.toml is not supported. Supported: "au".'+ : "The agent request was invalid.";} else if (upstream.status === 401 || upstream.status === 403) {message = "The agent request was not authorized.";} else if (upstream.status === 404) {@@ -572,6 +574,7 @@ function publicDeployment(value: unknown): Record<string, unknown> {channels: strings(deployment.channels),connections: strings(deployment.connections),createdAt: deployment.createdAt,+ ...(typeof deployment.region === "string" ? { region: deployment.region } : {}),...(Array.isArray(deployment.models)? {models: deployment.models.flatMap((value) => {@@ -2623,6 +2626,8 @@ async function deploySourceAgent(: [],memory: Array.isArray(body.memory) ? body.memory : [],models,+ // Validated by the service, which answers 400 unsupported_region (work 057).+ ...(body.region !== undefined ? { region: body.region } : {}),...(body.projectDeployment && typeof body.projectDeployment === "object"? { projectDeployment: body.projectDeployment }: {}),diff --git a/docs/agents/deployments.mdx b/docs/agents/deployments.mdxindex 3b33e13c..7b4abdd3 100644--- a/docs/agents/deployments.mdx+++ b/docs/agents/deployments.mdx@@ -39,6 +39,32 @@ the same resolution under `resolution`, before invoking a deployment agent.The CLI builds the current source, creates an immutable deployment, and movesthe `production` alias to it. Development remains available for further work.+## Choose a region++By default an agent's sandboxes run in the United States. To run its sessions closer to+your users or systems, set `region` in the agent's `opencomputer.toml` and+deploy again:++```toml+schema = 1+id = "support"+name = "Support"+region = "au"+```++| Region | Where sessions run |+| --- | --- |+| `au` | Australia |++The region applies to the agent's sandbox and its session state. It covers+sessions started after the deploy; existing sessions stay where they started.+Session state placement is best effort. Account-level data, such as project+and deployment records, is not moved. An unsupported value fails the deploy+with `unsupported_region`.++Each agent in a project has its own `opencomputer.toml`, so agents in one+project can run in different regions.+## Select an agent and environmentClients identify an agent with `agent-id@alias`: