History

Update cloud environment configuration and enhance session management

- Added MCP_AUTHKIT_DOMAIN and MCP_RESOURCE_ORIGIN to environment variables for better configuration management. - Updated the McpSessionDO class to utilize the new environment variables for AUTHKIT_DOMAIN and RESOURCE_ORIGIN. - Improved the session handling by integrating the resolveOrganization helper for organization resolution. - Modified package.json files to include a new patched dependency for @cloudflare/vite-plugin. - Adjusted development scripts across various apps to include the --no-tls flag for consistency.

Rhys Sullivan committed 7 months ago

Commit c688e1b1 parent 5693f5d12 files · +72 −14Browse files

Unified · Split

12 files
  1. apps/cloud/package.json +1 −1
  2. apps/cloud/src/env.ts +4 −0
  3. apps/cloud/src/mcp-session.ts +4 −3
  4. apps/cloud/src/mcp.ts +4 −2
  5. apps/local/package.json +1 −1
  6. apps/marketing/package.json +1 −1
  7. bun.lock +1 −0
  8. opencode.json +10 −0
  9. package.json +2 −1
  10. packages/kernel/runtime-dynamic-worker/src/normalize.test.ts +16 −0
  11. packages/kernel/runtime-dynamic-worker/src/normalize.ts +14 −5
  12. patches/@cloudflare%2Fvite-plugin@1.31.2.patch +14 −0
apps/cloud/package.json+1−1
@@ -5,7 +5,7 @@ · 4 unmodified lines
55 "type": "module",
66 "scripts": {
77 "dev": "bun run dev:proxy && concurrently -n db,vite -c blue,green \"bun run dev:db\" \"bun run dev:vite\"",
8− "dev:proxy": "portless proxy start --port 1355 || true",
8+ "dev:proxy": "portless proxy start --port 1355 --no-tls || true",
99 "dev:db": "bun run scripts/dev-db.ts",
1010 "dev:vite": "CLOUDFLARE_INCLUDE_PROCESS_ENV=true op run --env-file=.env.op -- portless run --name executor-cloud vite dev",
1111 "db:generate": "drizzle-kit generate",
apps/cloud/src/env.ts+4−0
@@ -10,6 +10,8 @@ const serverShape = { · 9 unmodified lines
1010 WORKOS_CLIENT_ID: Env.string("WORKOS_CLIENT_ID"),
1111 WORKOS_COOKIE_PASSWORD: Env.string("WORKOS_COOKIE_PASSWORD"),
1212 VITE_PUBLIC_SITE_URL: Env.stringOr("VITE_PUBLIC_SITE_URL", ""),
13+ MCP_AUTHKIT_DOMAIN: Env.stringOr("MCP_AUTHKIT_DOMAIN", "https://signin.executor.sh"),
14+ MCP_RESOURCE_ORIGIN: Env.stringOr("MCP_RESOURCE_ORIGIN", "https://executor.sh"),
1315 AUTUMN_SECRET_KEY: Env.stringOr("AUTUMN_SECRET_KEY", ""),
1416 SENTRY_DSN: Env.stringOr("SENTRY_DSN", ""),
1517 AXIOM_TOKEN: Env.stringOr("AXIOM_TOKEN", ""),
@@ -27,6 +29,8 @@ type ServerEnv = SharedEnv & · 11 unmodified lines
2729 WORKOS_CLIENT_ID: string;
2830 WORKOS_COOKIE_PASSWORD: string;
2931 VITE_PUBLIC_SITE_URL: string;
32+ MCP_AUTHKIT_DOMAIN: string;
33+ MCP_RESOURCE_ORIGIN: string;
3034 AUTUMN_SECRET_KEY: string;
3135 SENTRY_DSN: string;
3236 AXIOM_TOKEN: string;
apps/cloud/src/mcp-session.ts+4−3
@@ -15,6 +15,8 @@ import type { DrizzleDb } from "@executor/storage-postgres"; · 14 unmodified lines
1515 import * as sharedSchema from "@executor/storage-postgres/schema";
1616
1717 import { UserStoreService } from "./auth/context";
18+import { resolveOrganization } from "./auth/resolve-organization";
19+import { WorkOSAuth } from "./auth/workos";
1820 import { server } from "./env";
1921 import { createOrgExecutor } from "./services/executor";
2022 import { DbService } from "./services/db";
@@ -105,11 +107,10 @@ export class McpSessionDO extends DurableObject { · 84 unmodified lines
105107
106108 const DbLive = Layer.succeed(DbService, this.dbHandle.db);
107109 const UserStoreLive = UserStoreService.Live.pipe(Layer.provide(DbLive));
108− const Services = Layer.mergeAll(DbLive, UserStoreLive);
110+ const Services = Layer.mergeAll(DbLive, UserStoreLive, WorkOSAuth.Default);
109111
110112 const program = Effect.gen(function* () {
111− const users = yield* UserStoreService;
112− const org = yield* users.use((store) => store.getOrganization(token.organizationId));
113+ const org = yield* resolveOrganization(token.organizationId);
113114 if (!org)
114115 return yield* new OrganizationNotFoundError({ organizationId: token.organizationId });
115116
apps/cloud/src/mcp.ts+4−2
@@ -5,12 +5,14 @@ · 4 unmodified lines
55 import { env } from "cloudflare:workers";
66 import { createRemoteJWKSet, jwtVerify } from "jose";
77
8+import { server } from "./env";
9+
810 // ---------------------------------------------------------------------------
911 // Constants
1012 // ---------------------------------------------------------------------------
1113
12−const AUTHKIT_DOMAIN = "https://signin.executor.sh";
13−const RESOURCE_ORIGIN = "https://executor.sh";
14+const AUTHKIT_DOMAIN = server.MCP_AUTHKIT_DOMAIN;
15+const RESOURCE_ORIGIN = server.MCP_RESOURCE_ORIGIN;
1416 const JWKS_URL = new URL(`${AUTHKIT_DOMAIN}/oauth2/jwks`);
1517
1618 const jwks = createRemoteJWKSet(JWKS_URL);
apps/local/package.json+1−1
@@ -7,7 +7,7 @@ · 6 unmodified lines
77 ".": "./src/index.ts"
88 },
99 "scripts": {
10− "dev": "portless run --name executor-local bunx --bun vite dev",
10+ "dev": "portless run --no-tls --name executor-local bunx --bun vite dev",
1111 "build": "bunx --bun vite build",
1212 "start": "bun run src/serve.ts",
1313 "typecheck": "tsgo --noEmit",
apps/marketing/package.json+1−1
@@ -3,7 +3,7 @@ · 2 unmodified lines
33 "version": "0.0.4",
44 "type": "module",
55 "scripts": {
6− "dev": "portless run --name executor-marketing astro dev",
6+ "dev": "portless run --no-tls --name executor-marketing astro dev",
77 "build": "astro build",
88 "preview": "astro preview",
99 "deploy": "astro build && npx wrangler deploy --config dist/server/wrangler.json",
bun.lock+1−0
@@ -686,6 +686,7 @@ · 685 unmodified lines
686686 },
687687 },
688688 "patchedDependencies": {
689+ "@cloudflare/vite-plugin@1.31.2": "patches/@cloudflare%2Fvite-plugin@1.31.2.patch",
689690 "postgres@3.4.9": "patches/postgres@3.4.9.patch",
690691 },
691692 "catalog": {
opencode.json+10−0
@@ -0,0 +1,10 @@
1+{
2+ "$schema": "https://opencode.ai/config.json",
3+ "mcp": {
4+ "executor": {
5+ "type": "remote",
6+ "url": "http://executor-cloud.localhost:1355/mcp",
7+ "enabled": true
8+ }
9+ }
10+}
package.json+2−1
@@ -104,6 +104,7 @@ · 103 unmodified lines
104104 "tsup": "^8.5.0"
105105 },
106106 "patchedDependencies": {
107− "postgres@3.4.9": "patches/postgres@3.4.9.patch"
107+ "postgres@3.4.9": "patches/postgres@3.4.9.patch",
108+ "@cloudflare/vite-plugin@1.31.2": "patches/@cloudflare%2Fvite-plugin@1.31.2.patch"
108109 }
109110 }
packages/kernel/runtime-dynamic-worker/src/normalize.test.ts+16−0
@@ -12,6 +12,11 @@ describe("normalizeCode", () => { · 11 unmodified lines
1212 expect(normalizeCode(code)).toBe(code);
1313 });
1414
15+ it("strips export default from an async arrow", () => {
16+ const code = "export default async () => 42";
17+ expect(normalizeCode(code)).toBe("async () => 42");
18+ });
19+
1520 it("wraps a bare expression in an async arrow", () => {
1621 const result = normalizeCode("1 + 2");
1722 expect(result).toContain("async () =>");
@@ -30,6 +35,17 @@ describe("normalizeCode", () => { · 12 unmodified lines
3035 expect(result).toContain("return run();");
3136 });
3237
38+ it("wraps an exported default named async function declaration", () => {
39+ const result = normalizeCode("export default async function run() { return 'ok'; }");
40+ expect(result).toContain("async function run()");
41+ expect(result).toContain("return run();");
42+ });
43+
44+ it("wraps an exported default anonymous async function declaration", () => {
45+ const result = normalizeCode("export default async function () { return 'ok'; }");
46+ expect(result).toBe("async () => (async function () { return 'ok'; })()");
47+ });
48+
3349 it("strips markdown code fences", () => {
3450 const code = "```js\nasync () => 42\n```";
3551 expect(normalizeCode(code)).toBe("async () => 42");
packages/kernel/runtime-dynamic-worker/src/normalize.ts+14−5
@@ -12,6 +12,9 @@ const stripCodeFences = (code: string): string => { · 11 unmodified lines
1212 return match ? match[1]! : code;
1313 };
1414
15+const stripDefaultExport = (source: string): string =>
16+ source.replace(/^export\s+default\s+/, "").trim();
17+
1518 /**
1619 * Detect whether `source` is already an async arrow function expression.
1720 *
@@ -27,7 +30,7 @@ const looksLikeArrowFunction = (source: string): boolean => · 9 unmodified lines
2730 * Detect a single named function declaration (sync or async).
2831 */
2932 const looksLikeFunctionDeclaration = (source: string): boolean =>
30− /^(async\s+)?function\s+[a-zA-Z_$]/.test(source);
33+ /^(async\s+)?function(?:\s+[a-zA-Z_$][a-zA-Z0-9_$]*)?\s*\(/.test(source);
3134
3235 /**
3336 * Normalize user code into an async arrow function body.
@@ -39,15 +42,21 @@ export const normalizeCode = (code: string): string => { · 5 unmodified lines
3942 if (!trimmed) return "async () => {}";
4043
4144 const source = trimmed.trim();
45+ const withoutDefaultExport = stripDefaultExport(source);
4246
4347 // Already an arrow function — pass through.
44− if (looksLikeArrowFunction(source)) return source;
48+ if (looksLikeArrowFunction(withoutDefaultExport)) return withoutDefaultExport;
4549
4650 // Single named function declaration — wrap and call.
47− if (looksLikeFunctionDeclaration(source)) {
48− const nameMatch = source.match(/^(?:async\s+)?function\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/);
51+ if (looksLikeFunctionDeclaration(withoutDefaultExport)) {
52+ const nameMatch = withoutDefaultExport.match(
53+ /^(?:async\s+)?function\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/,
54+ );
4955 const name = nameMatch?.[1] ?? "fn";
50− return `async () => {\n${source}\nreturn ${name}();\n}`;
56+ if (!nameMatch) {
57+ return `async () => (${withoutDefaultExport})()`;
58+ }
59+ return `async () => {\n${withoutDefaultExport}\nreturn ${name}();\n}`;
5160 }
5261
5362 // Treat everything else as statement(s) — wrap in an async arrow.
patches/@cloudflare%2Fvite-plugin@1.31.2.patch+14−0
@@ -0,0 +1,14 @@
1+diff --git a/dist/index.mjs b/dist/index.mjs
2+index 800006118105cd58707159d0a98dc5329a719dc3..9048678fce39d66d56b5bad63b7c7c94a5e3dc94 100644
3+--- a/dist/index.mjs
4++++ b/dist/index.mjs
5+@@ -11166,7 +11166,8 @@ function toMiniflareRequest(request$1) {
6+ headers: [["accept-encoding", "identity"], ...request$1.headers],
7+ body: request$1.body,
8+ duplex: "half",
9+- signal: request$1.signal
10++ signal: request$1.signal,
11++ credentials: "omit"
12+ });
13+ }
14+ const isRolldown = "rolldownVersion" in vite;