// --------------------------------------------------------------------------- // Cloud executor — stateless, per-request, from Postgres // --------------------------------------------------------------------------- import { Effect } from "effect"; import { createExecutor } from "@executor/sdk"; import { makePgConfig, makePgKv } from "@executor/storage-postgres"; import { openApiPlugin, makeKvOperationStore } from "@executor/plugin-openapi"; import { mcpPlugin, makeKvBindingStore } from "@executor/plugin-mcp"; import { googleDiscoveryPlugin, makeKvBindingStore as makeKvGoogleDiscoveryBindingStore, } from "@executor/plugin-google-discovery"; import { graphqlPlugin, makeKvOperationStore as makeKvGraphqlOperationStore, } from "@executor/plugin-graphql"; import { DbService } from "./db"; // --------------------------------------------------------------------------- // Create a fresh executor for an organization (stateless, per-request) // --------------------------------------------------------------------------- export const createOrgExecutor = ( organizationId: string, organizationName: string, encryptionKey: string, ) => Effect.gen(function* () { const db = yield* DbService; const kv = makePgKv(db, organizationId); const config = makePgConfig(db, { organizationId, organizationName, encryptionKey, plugins: [ openApiPlugin({ operationStore: makeKvOperationStore(kv, "openapi"), }), mcpPlugin({ bindingStore: makeKvBindingStore(kv, "mcp"), }), googleDiscoveryPlugin({ bindingStore: makeKvGoogleDiscoveryBindingStore(kv, "google-discovery"), }), graphqlPlugin({ operationStore: makeKvGraphqlOperationStore(kv, "graphql"), }), ] as const, }); return yield* createExecutor(config); });