@farm.js/cf-agent 0.1.0-beta.59 → 0.1.0-beta.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -126,6 +126,10 @@ function createGeneratedWranglerConfig(input) {
126
126
  ...environments,
127
127
  [input.environment]: {
128
128
  ...selected,
129
+ // `main` is inheritable per environment: if the selected env overrides
130
+ // it, the raw agent entry survives and the deploy serves only the agent
131
+ // Worker. Rewrite it to the combined wrapper like the top-level main.
132
+ main: toConfigRelativePath(input.configDirectory, input.wrapperPath),
129
133
  compatibility_flags: withNodeCompatibility(
130
134
  selected.compatibility_flags ?? config.compatibility_flags
131
135
  ),
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/output.ts"],"sourcesContent":["import { resolve } from \"node:path\";\nimport {\n createAgentRuntimeIntegration,\n findAvailableAgentRuntimePort,\n resolveProjectPackageBin,\n startManagedAgentRuntime,\n type FarmAgentRuntimeInstance,\n} from \"@farm.js/core/agent-runtime\";\nimport { writeCloudflareAgentOutput } from \"./output\";\n\nconst DEFAULT_CONFIG = \"wrangler.jsonc\";\nconst DEFAULT_ROUTE_PREFIX = \"/agents\";\n\nexport interface CloudflareAgentDevOptions {\n /** Fixed Wrangler port. Farm chooses an available loopback port by default. */\n port?: number;\n /** Run Wrangler against Cloudflare's remote development environment. */\n remote?: boolean;\n /** Forward Wrangler output through Farm's logger. Defaults to true. */\n logs?: boolean;\n /** Maximum time to wait for Wrangler. Defaults to 60 seconds. */\n timeoutMs?: number;\n}\n\nexport interface CloudflareAgentOptions {\n /** Wrangler configuration, relative to farm.config.ts. Defaults to wrangler.jsonc. */\n config?: string;\n /** Same-origin route owned by Cloudflare Agents. Defaults to /agents. */\n routePrefix?: string;\n /** Use an already-running Workers runtime instead of starting Wrangler in development. */\n origin?: string;\n /** Wrangler environment passed to development and deployment commands. */\n environment?: string;\n /** Disable managed local development or configure the Wrangler process. */\n dev?: false | CloudflareAgentDevOptions;\n}\n\nexport interface CloudflareAgentRuntime extends FarmAgentRuntimeInstance {\n readonly config: string;\n readonly environment?: string;\n}\n\ntype BaseCloudflareAgentIntegration = ReturnType<typeof createAgentRuntimeIntegration>;\nexport type CloudflareAgentIntegration = Omit<BaseCloudflareAgentIntegration, \"instance\"> & {\n readonly instance: CloudflareAgentRuntime;\n};\n\n/**\n * Runs Cloudflare Agents beside Farm in development and composes both into one Worker build.\n *\n * @example\n * integrations: { agent: cfAgent() }\n */\nexport function cfAgent(options: CloudflareAgentOptions = {}): CloudflareAgentIntegration {\n const config = options.config || DEFAULT_CONFIG;\n const routePrefix = options.routePrefix || DEFAULT_ROUTE_PREFIX;\n const devOptions = options.dev === false ? undefined : options.dev || {};\n const externalOrigin = options.origin || process.env.CF_AGENT_ORIGIN?.trim();\n\n return createAgentRuntimeIntegration({\n provider: \"cloudflare\",\n routePrefix,\n serverRuntime: Boolean(externalOrigin),\n origin: options.origin,\n originEnv: \"CF_AGENT_ORIGIN\",\n webSockets: true,\n instance: {\n config,\n environment: options.environment,\n },\n ...(devOptions\n ? {\n async startDev(context) {\n assertCloudflareAgentNodeVersion();\n const binary = await resolveProjectPackageBin(context.root, \"wrangler\", \"wrangler\");\n const port = devOptions.port ?? (await findAvailableAgentRuntimePort());\n assertPort(port);\n const origin = `http://127.0.0.1:${port}`;\n const showLogs = devOptions.logs !== false;\n\n return startManagedAgentRuntime({\n command: process.execPath,\n args: createWranglerDevArgs({\n binary,\n config: resolve(context.root, config),\n port,\n remote: devOptions.remote,\n environment: options.environment,\n }),\n cwd: context.root,\n label: \"Cloudflare Agents development server\",\n origin,\n healthPath: \"/\",\n timeoutMs: devOptions.timeoutMs ?? 60_000,\n onOutput: showLogs\n ? (line, stream) => {\n const message = `[cloudflare] ${line}`;\n if (stream === \"stderr\") context.log.warn(message);\n else context.log.info(message);\n }\n : undefined,\n });\n },\n }\n : {}),\n ...(!externalOrigin\n ? {\n async afterBuild(context) {\n if (context.preset !== \"cloudflare-module\") {\n throw new Error(\n \"@farm.js/cf-agent requires deploy.preset to be cloudflare-module so Farm and Durable Objects can share one Worker.\",\n );\n }\n if (!context.outputDir) {\n throw new Error(\"Farm did not report a Cloudflare build output directory.\");\n }\n\n await writeCloudflareAgentOutput({\n root: context.root,\n outputDir: context.outputDir,\n config,\n routePrefix: context.routePrefix,\n environment: options.environment,\n });\n },\n }\n : {}),\n }) as CloudflareAgentIntegration;\n}\n\nexport function createWranglerDevArgs(input: {\n binary: string;\n config: string;\n port: number;\n remote?: boolean;\n environment?: string;\n}): string[] {\n return [\n input.binary,\n \"dev\",\n \"--config\",\n input.config,\n \"--ip\",\n \"127.0.0.1\",\n \"--port\",\n String(input.port),\n \"--show-interactive-dev-session=false\",\n ...(input.remote ? [\"--remote\"] : []),\n ...(input.environment ? [\"--env\", input.environment] : []),\n ];\n}\n\nexport function assertCloudflareAgentNodeVersion(version = process.versions.node): void {\n const major = Number.parseInt(version.split(\".\")[0] || \"0\", 10);\n if (!Number.isFinite(major) || major < 22) {\n throw new Error(\n `Cloudflare Agents and Wrangler require Node.js 22 or newer. Farm is running Node.js ${version}.`,\n );\n }\n}\n\nfunction assertPort(port: number): void {\n if (!Number.isInteger(port) || port < 1 || port > 65_535) {\n throw new Error(\"Cloudflare Agents dev.port must be an integer from 1 through 65535.\");\n }\n}\n\nexport { writeCloudflareAgentOutput } from \"./output\";\nexport type {\n CloudflareAgentDeployMetadata,\n CloudflareAgentOutput,\n CloudflareAgentOutputOptions,\n} from \"./output\";\n","import { access, mkdir, readFile, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"node:path\";\nimport { parse, printParseErrorCode, type ParseError } from \"jsonc-parser\";\nimport { normalizeAgentRoutePrefix } from \"@farm.js/core/agent-runtime\";\n\nconst GENERATED_CONFIG_NAME = \".farm-cf-agent.wrangler.jsonc\";\n\nexport interface CloudflareAgentOutputOptions {\n root: string;\n outputDir: string;\n config: string;\n routePrefix: string;\n environment?: string;\n}\n\nexport interface CloudflareAgentDeployMetadata {\n version: 1;\n provider: \"cloudflare-agents\";\n config: string;\n environment?: string;\n}\n\nexport interface CloudflareAgentOutput {\n wrapperPath: string;\n configPath: string;\n metadataPath: string;\n}\n\ntype JsonObject = Record<string, unknown>;\n\n/** Compose Farm's Cloudflare module output with a Cloudflare Agents Worker. */\nexport async function writeCloudflareAgentOutput(\n options: CloudflareAgentOutputOptions,\n): Promise<CloudflareAgentOutput> {\n const root = resolve(options.root);\n const outputDir = resolve(root, options.outputDir);\n const configPath = resolve(root, options.config);\n assertInsideRoot(root, configPath, \"Wrangler config\");\n\n const configDirectory = dirname(configPath);\n const config = await readWranglerConfig(configPath);\n const agentEntryValue = config.main;\n if (typeof agentEntryValue !== \"string\" || !agentEntryValue.trim()) {\n throw new Error(`${configPath} must define a non-empty Wrangler main entry.`);\n }\n if (config.no_bundle === true) {\n throw new Error(\"@farm.js/cf-agent requires Wrangler bundling; remove no_bundle: true.\");\n }\n\n const agentEntry = resolve(configDirectory, agentEntryValue);\n const farmEntry = join(outputDir, \"server\", \"index.mjs\");\n const publicDirectory = join(outputDir, \"public\");\n await assertFile(agentEntry, \"Cloudflare agent entry\");\n await assertFile(farmEntry, \"Farm Cloudflare module entry\");\n await assertDirectory(publicDirectory, \"Farm public output\");\n\n const generatedDirectory = join(root, \".farm\", \"cf-agent\");\n const wrapperPath = join(generatedDirectory, \"worker.mjs\");\n const generatedConfigPath = join(configDirectory, GENERATED_CONFIG_NAME);\n const metadataPath = join(generatedDirectory, \"deploy.json\");\n await mkdir(generatedDirectory, { recursive: true });\n\n const routePrefix = normalizeAgentRoutePrefix(options.routePrefix);\n await writeFile(\n wrapperPath,\n createCombinedWorkerSource({\n wrapperPath,\n farmEntry,\n agentEntry,\n routePrefix,\n }),\n );\n\n const generatedConfig = createGeneratedWranglerConfig({\n config,\n configDirectory,\n wrapperPath,\n publicDirectory,\n environment: options.environment,\n });\n await writeFile(generatedConfigPath, `${JSON.stringify(generatedConfig, null, 2)}\\n`);\n\n const metadata: CloudflareAgentDeployMetadata = {\n version: 1,\n provider: \"cloudflare-agents\",\n config: toRootRelativePath(root, generatedConfigPath),\n ...(options.environment ? { environment: options.environment } : {}),\n };\n await writeFile(metadataPath, `${JSON.stringify(metadata, null, 2)}\\n`);\n\n return {\n wrapperPath,\n configPath: generatedConfigPath,\n metadataPath,\n };\n}\n\nfunction createCombinedWorkerSource(input: {\n wrapperPath: string;\n farmEntry: string;\n agentEntry: string;\n routePrefix: string;\n}): string {\n const farmSpecifier = JSON.stringify(toImportSpecifier(input.wrapperPath, input.farmEntry));\n const agentSpecifier = JSON.stringify(toImportSpecifier(input.wrapperPath, input.agentEntry));\n const routePrefix = JSON.stringify(input.routePrefix);\n\n return `import farmWorker from ${farmSpecifier};\nimport agentWorker from ${agentSpecifier};\nexport * from ${agentSpecifier};\n\nconst agentRoutePrefix = ${routePrefix};\n\nfunction callFetch(worker, request, env, context, label) {\n const handler = typeof worker === \"function\" ? worker : worker?.fetch;\n if (typeof handler !== \"function\") {\n throw new TypeError(label + \" does not export a fetch handler.\");\n }\n return handler.call(worker, request, env, context);\n}\n\nconst worker = {\n ...agentWorker,\n ...farmWorker,\n fetch(request, env, context) {\n const pathname = new URL(request.url).pathname;\n if (pathname === agentRoutePrefix || pathname.startsWith(agentRoutePrefix + \"/\")) {\n return callFetch(agentWorker, request, env, context, \"Cloudflare agent Worker\");\n }\n return callFetch(farmWorker, request, env, context, \"Farm Worker\");\n },\n};\n\nexport default worker;\n`;\n}\n\nfunction createGeneratedWranglerConfig(input: {\n config: JsonObject;\n configDirectory: string;\n wrapperPath: string;\n publicDirectory: string;\n environment?: string;\n}): JsonObject {\n const { $schema: _schema, ...config } = input.config;\n const assets = readObject(config.assets, \"Wrangler assets\");\n const generated: JsonObject = {\n ...config,\n main: toConfigRelativePath(input.configDirectory, input.wrapperPath),\n compatibility_flags: withNodeCompatibility(config.compatibility_flags),\n assets: {\n ...assets,\n directory: toConfigRelativePath(input.configDirectory, input.publicDirectory),\n },\n };\n\n if (input.environment) {\n const environments = readObject(config.env, \"Wrangler env\");\n const selected = readObject(\n environments[input.environment],\n `Wrangler env.${input.environment}`,\n );\n generated.env = {\n ...environments,\n [input.environment]: {\n ...selected,\n compatibility_flags: withNodeCompatibility(\n selected.compatibility_flags ?? config.compatibility_flags,\n ),\n assets: {\n ...readObject(\n selected.assets ?? config.assets,\n `Wrangler env.${input.environment}.assets`,\n ),\n directory: toConfigRelativePath(input.configDirectory, input.publicDirectory),\n },\n },\n };\n }\n\n return generated;\n}\n\nasync function readWranglerConfig(configPath: string): Promise<JsonObject> {\n let source: string;\n try {\n source = await readFile(configPath, \"utf8\");\n } catch {\n throw new Error(`Wrangler config was not found at ${configPath}.`);\n }\n\n const errors: ParseError[] = [];\n const value = parse(source, errors, { allowTrailingComma: true });\n if (errors.length) {\n const details = errors\n .map((error) => `${printParseErrorCode(error.error)} at offset ${error.offset}`)\n .join(\", \");\n throw new Error(`Unable to parse ${basename(configPath)}: ${details}.`);\n }\n if (!isObject(value)) {\n throw new Error(`${configPath} must contain a Wrangler configuration object.`);\n }\n return value;\n}\n\nfunction withNodeCompatibility(value: unknown): string[] {\n if (value === undefined) return [\"nodejs_compat\"];\n if (!Array.isArray(value) || !value.every((entry) => typeof entry === \"string\")) {\n throw new Error(\"Wrangler compatibility_flags must be an array of strings.\");\n }\n return value.includes(\"nodejs_compat\") ? [...value] : [...value, \"nodejs_compat\"];\n}\n\nfunction readObject(value: unknown, label: string): JsonObject {\n if (value === undefined) return {};\n if (!isObject(value)) {\n throw new Error(`${label} must be an object.`);\n }\n return value;\n}\n\nfunction isObject(value: unknown): value is JsonObject {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction toImportSpecifier(fromFile: string, target: string): string {\n const value = normalizePath(relative(dirname(fromFile), target));\n return hasRelativePrefix(value) ? value : `./${value}`;\n}\n\nfunction toConfigRelativePath(configDirectory: string, target: string): string {\n const value = normalizePath(relative(configDirectory, target));\n return hasRelativePrefix(value) ? value : `./${value}`;\n}\n\nfunction toRootRelativePath(root: string, target: string): string {\n return normalizePath(relative(root, target));\n}\n\nfunction normalizePath(value: string): string {\n return sep === \"/\" ? value : value.split(sep).join(\"/\");\n}\n\nfunction hasRelativePrefix(value: string): boolean {\n return value.startsWith(\"./\") || value.startsWith(\"../\");\n}\n\nfunction assertInsideRoot(root: string, target: string, label: string): void {\n const pathFromRoot = relative(root, target);\n if (pathFromRoot === \"..\" || pathFromRoot.startsWith(`..${sep}`) || isAbsolute(pathFromRoot)) {\n throw new Error(`${label} must be inside the Farm project root.`);\n }\n}\n\nasync function assertFile(path: string, label: string): Promise<void> {\n try {\n await access(path);\n } catch {\n throw new Error(`${label} was not found at ${path}.`);\n }\n}\n\nasync function assertDirectory(path: string, label: string): Promise<void> {\n try {\n if (!(await stat(path)).isDirectory()) throw new Error();\n } catch {\n throw new Error(`${label} was not found at ${path}.`);\n }\n}\n"],"mappings":";AAAA,SAAS,WAAAA,gBAAe;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;ACPP,SAAS,QAAQ,OAAO,UAAU,MAAM,iBAAiB;AACzD,SAAS,UAAU,SAAS,YAAY,MAAM,UAAU,SAAS,WAAW;AAC5E,SAAS,OAAO,2BAA4C;AAC5D,SAAS,iCAAiC;AAE1C,IAAM,wBAAwB;AA0B9B,eAAsB,2BACpB,SACgC;AAChC,QAAM,OAAO,QAAQ,QAAQ,IAAI;AACjC,QAAM,YAAY,QAAQ,MAAM,QAAQ,SAAS;AACjD,QAAM,aAAa,QAAQ,MAAM,QAAQ,MAAM;AAC/C,mBAAiB,MAAM,YAAY,iBAAiB;AAEpD,QAAM,kBAAkB,QAAQ,UAAU;AAC1C,QAAM,SAAS,MAAM,mBAAmB,UAAU;AAClD,QAAM,kBAAkB,OAAO;AAC/B,MAAI,OAAO,oBAAoB,YAAY,CAAC,gBAAgB,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"version":3,"sources":["../src/index.ts","../src/output.ts"],"sourcesContent":["import { resolve } from \"node:path\";\nimport {\n createAgentRuntimeIntegration,\n findAvailableAgentRuntimePort,\n resolveProjectPackageBin,\n startManagedAgentRuntime,\n type FarmAgentRuntimeInstance,\n} from \"@farm.js/core/agent-runtime\";\nimport { writeCloudflareAgentOutput } from \"./output\";\n\nconst DEFAULT_CONFIG = \"wrangler.jsonc\";\nconst DEFAULT_ROUTE_PREFIX = \"/agents\";\n\nexport interface CloudflareAgentDevOptions {\n /** Fixed Wrangler port. Farm chooses an available loopback port by default. */\n port?: number;\n /** Run Wrangler against Cloudflare's remote development environment. */\n remote?: boolean;\n /** Forward Wrangler output through Farm's logger. Defaults to true. */\n logs?: boolean;\n /** Maximum time to wait for Wrangler. Defaults to 60 seconds. */\n timeoutMs?: number;\n}\n\nexport interface CloudflareAgentOptions {\n /** Wrangler configuration, relative to farm.config.ts. Defaults to wrangler.jsonc. */\n config?: string;\n /** Same-origin route owned by Cloudflare Agents. Defaults to /agents. */\n routePrefix?: string;\n /** Use an already-running Workers runtime instead of starting Wrangler in development. */\n origin?: string;\n /** Wrangler environment passed to development and deployment commands. */\n environment?: string;\n /** Disable managed local development or configure the Wrangler process. */\n dev?: false | CloudflareAgentDevOptions;\n}\n\nexport interface CloudflareAgentRuntime extends FarmAgentRuntimeInstance {\n readonly config: string;\n readonly environment?: string;\n}\n\ntype BaseCloudflareAgentIntegration = ReturnType<typeof createAgentRuntimeIntegration>;\nexport type CloudflareAgentIntegration = Omit<BaseCloudflareAgentIntegration, \"instance\"> & {\n readonly instance: CloudflareAgentRuntime;\n};\n\n/**\n * Runs Cloudflare Agents beside Farm in development and composes both into one Worker build.\n *\n * @example\n * integrations: { agent: cfAgent() }\n */\nexport function cfAgent(options: CloudflareAgentOptions = {}): CloudflareAgentIntegration {\n const config = options.config || DEFAULT_CONFIG;\n const routePrefix = options.routePrefix || DEFAULT_ROUTE_PREFIX;\n const devOptions = options.dev === false ? undefined : options.dev || {};\n const externalOrigin = options.origin || process.env.CF_AGENT_ORIGIN?.trim();\n\n return createAgentRuntimeIntegration({\n provider: \"cloudflare\",\n routePrefix,\n serverRuntime: Boolean(externalOrigin),\n origin: options.origin,\n originEnv: \"CF_AGENT_ORIGIN\",\n webSockets: true,\n instance: {\n config,\n environment: options.environment,\n },\n ...(devOptions\n ? {\n async startDev(context) {\n assertCloudflareAgentNodeVersion();\n const binary = await resolveProjectPackageBin(context.root, \"wrangler\", \"wrangler\");\n const port = devOptions.port ?? (await findAvailableAgentRuntimePort());\n assertPort(port);\n const origin = `http://127.0.0.1:${port}`;\n const showLogs = devOptions.logs !== false;\n\n return startManagedAgentRuntime({\n command: process.execPath,\n args: createWranglerDevArgs({\n binary,\n config: resolve(context.root, config),\n port,\n remote: devOptions.remote,\n environment: options.environment,\n }),\n cwd: context.root,\n label: \"Cloudflare Agents development server\",\n origin,\n healthPath: \"/\",\n timeoutMs: devOptions.timeoutMs ?? 60_000,\n onOutput: showLogs\n ? (line, stream) => {\n const message = `[cloudflare] ${line}`;\n if (stream === \"stderr\") context.log.warn(message);\n else context.log.info(message);\n }\n : undefined,\n });\n },\n }\n : {}),\n ...(!externalOrigin\n ? {\n async afterBuild(context) {\n if (context.preset !== \"cloudflare-module\") {\n throw new Error(\n \"@farm.js/cf-agent requires deploy.preset to be cloudflare-module so Farm and Durable Objects can share one Worker.\",\n );\n }\n if (!context.outputDir) {\n throw new Error(\"Farm did not report a Cloudflare build output directory.\");\n }\n\n await writeCloudflareAgentOutput({\n root: context.root,\n outputDir: context.outputDir,\n config,\n routePrefix: context.routePrefix,\n environment: options.environment,\n });\n },\n }\n : {}),\n }) as CloudflareAgentIntegration;\n}\n\nexport function createWranglerDevArgs(input: {\n binary: string;\n config: string;\n port: number;\n remote?: boolean;\n environment?: string;\n}): string[] {\n return [\n input.binary,\n \"dev\",\n \"--config\",\n input.config,\n \"--ip\",\n \"127.0.0.1\",\n \"--port\",\n String(input.port),\n \"--show-interactive-dev-session=false\",\n ...(input.remote ? [\"--remote\"] : []),\n ...(input.environment ? [\"--env\", input.environment] : []),\n ];\n}\n\nexport function assertCloudflareAgentNodeVersion(version = process.versions.node): void {\n const major = Number.parseInt(version.split(\".\")[0] || \"0\", 10);\n if (!Number.isFinite(major) || major < 22) {\n throw new Error(\n `Cloudflare Agents and Wrangler require Node.js 22 or newer. Farm is running Node.js ${version}.`,\n );\n }\n}\n\nfunction assertPort(port: number): void {\n if (!Number.isInteger(port) || port < 1 || port > 65_535) {\n throw new Error(\"Cloudflare Agents dev.port must be an integer from 1 through 65535.\");\n }\n}\n\nexport { writeCloudflareAgentOutput } from \"./output\";\nexport type {\n CloudflareAgentDeployMetadata,\n CloudflareAgentOutput,\n CloudflareAgentOutputOptions,\n} from \"./output\";\n","import { access, mkdir, readFile, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"node:path\";\nimport { parse, printParseErrorCode, type ParseError } from \"jsonc-parser\";\nimport { normalizeAgentRoutePrefix } from \"@farm.js/core/agent-runtime\";\n\nconst GENERATED_CONFIG_NAME = \".farm-cf-agent.wrangler.jsonc\";\n\nexport interface CloudflareAgentOutputOptions {\n root: string;\n outputDir: string;\n config: string;\n routePrefix: string;\n environment?: string;\n}\n\nexport interface CloudflareAgentDeployMetadata {\n version: 1;\n provider: \"cloudflare-agents\";\n config: string;\n environment?: string;\n}\n\nexport interface CloudflareAgentOutput {\n wrapperPath: string;\n configPath: string;\n metadataPath: string;\n}\n\ntype JsonObject = Record<string, unknown>;\n\n/** Compose Farm's Cloudflare module output with a Cloudflare Agents Worker. */\nexport async function writeCloudflareAgentOutput(\n options: CloudflareAgentOutputOptions,\n): Promise<CloudflareAgentOutput> {\n const root = resolve(options.root);\n const outputDir = resolve(root, options.outputDir);\n const configPath = resolve(root, options.config);\n assertInsideRoot(root, configPath, \"Wrangler config\");\n\n const configDirectory = dirname(configPath);\n const config = await readWranglerConfig(configPath);\n const agentEntryValue = config.main;\n if (typeof agentEntryValue !== \"string\" || !agentEntryValue.trim()) {\n throw new Error(`${configPath} must define a non-empty Wrangler main entry.`);\n }\n if (config.no_bundle === true) {\n throw new Error(\"@farm.js/cf-agent requires Wrangler bundling; remove no_bundle: true.\");\n }\n\n const agentEntry = resolve(configDirectory, agentEntryValue);\n const farmEntry = join(outputDir, \"server\", \"index.mjs\");\n const publicDirectory = join(outputDir, \"public\");\n await assertFile(agentEntry, \"Cloudflare agent entry\");\n await assertFile(farmEntry, \"Farm Cloudflare module entry\");\n await assertDirectory(publicDirectory, \"Farm public output\");\n\n const generatedDirectory = join(root, \".farm\", \"cf-agent\");\n const wrapperPath = join(generatedDirectory, \"worker.mjs\");\n const generatedConfigPath = join(configDirectory, GENERATED_CONFIG_NAME);\n const metadataPath = join(generatedDirectory, \"deploy.json\");\n await mkdir(generatedDirectory, { recursive: true });\n\n const routePrefix = normalizeAgentRoutePrefix(options.routePrefix);\n await writeFile(\n wrapperPath,\n createCombinedWorkerSource({\n wrapperPath,\n farmEntry,\n agentEntry,\n routePrefix,\n }),\n );\n\n const generatedConfig = createGeneratedWranglerConfig({\n config,\n configDirectory,\n wrapperPath,\n publicDirectory,\n environment: options.environment,\n });\n await writeFile(generatedConfigPath, `${JSON.stringify(generatedConfig, null, 2)}\\n`);\n\n const metadata: CloudflareAgentDeployMetadata = {\n version: 1,\n provider: \"cloudflare-agents\",\n config: toRootRelativePath(root, generatedConfigPath),\n ...(options.environment ? { environment: options.environment } : {}),\n };\n await writeFile(metadataPath, `${JSON.stringify(metadata, null, 2)}\\n`);\n\n return {\n wrapperPath,\n configPath: generatedConfigPath,\n metadataPath,\n };\n}\n\nfunction createCombinedWorkerSource(input: {\n wrapperPath: string;\n farmEntry: string;\n agentEntry: string;\n routePrefix: string;\n}): string {\n const farmSpecifier = JSON.stringify(toImportSpecifier(input.wrapperPath, input.farmEntry));\n const agentSpecifier = JSON.stringify(toImportSpecifier(input.wrapperPath, input.agentEntry));\n const routePrefix = JSON.stringify(input.routePrefix);\n\n return `import farmWorker from ${farmSpecifier};\nimport agentWorker from ${agentSpecifier};\nexport * from ${agentSpecifier};\n\nconst agentRoutePrefix = ${routePrefix};\n\nfunction callFetch(worker, request, env, context, label) {\n const handler = typeof worker === \"function\" ? worker : worker?.fetch;\n if (typeof handler !== \"function\") {\n throw new TypeError(label + \" does not export a fetch handler.\");\n }\n return handler.call(worker, request, env, context);\n}\n\nconst worker = {\n ...agentWorker,\n ...farmWorker,\n fetch(request, env, context) {\n const pathname = new URL(request.url).pathname;\n if (pathname === agentRoutePrefix || pathname.startsWith(agentRoutePrefix + \"/\")) {\n return callFetch(agentWorker, request, env, context, \"Cloudflare agent Worker\");\n }\n return callFetch(farmWorker, request, env, context, \"Farm Worker\");\n },\n};\n\nexport default worker;\n`;\n}\n\nfunction createGeneratedWranglerConfig(input: {\n config: JsonObject;\n configDirectory: string;\n wrapperPath: string;\n publicDirectory: string;\n environment?: string;\n}): JsonObject {\n const { $schema: _schema, ...config } = input.config;\n const assets = readObject(config.assets, \"Wrangler assets\");\n const generated: JsonObject = {\n ...config,\n main: toConfigRelativePath(input.configDirectory, input.wrapperPath),\n compatibility_flags: withNodeCompatibility(config.compatibility_flags),\n assets: {\n ...assets,\n directory: toConfigRelativePath(input.configDirectory, input.publicDirectory),\n },\n };\n\n if (input.environment) {\n const environments = readObject(config.env, \"Wrangler env\");\n const selected = readObject(\n environments[input.environment],\n `Wrangler env.${input.environment}`,\n );\n generated.env = {\n ...environments,\n [input.environment]: {\n ...selected,\n // `main` is inheritable per environment: if the selected env overrides\n // it, the raw agent entry survives and the deploy serves only the agent\n // Worker. Rewrite it to the combined wrapper like the top-level main.\n main: toConfigRelativePath(input.configDirectory, input.wrapperPath),\n compatibility_flags: withNodeCompatibility(\n selected.compatibility_flags ?? config.compatibility_flags,\n ),\n assets: {\n ...readObject(\n selected.assets ?? config.assets,\n `Wrangler env.${input.environment}.assets`,\n ),\n directory: toConfigRelativePath(input.configDirectory, input.publicDirectory),\n },\n },\n };\n }\n\n return generated;\n}\n\nasync function readWranglerConfig(configPath: string): Promise<JsonObject> {\n let source: string;\n try {\n source = await readFile(configPath, \"utf8\");\n } catch {\n throw new Error(`Wrangler config was not found at ${configPath}.`);\n }\n\n const errors: ParseError[] = [];\n const value = parse(source, errors, { allowTrailingComma: true });\n if (errors.length) {\n const details = errors\n .map((error) => `${printParseErrorCode(error.error)} at offset ${error.offset}`)\n .join(\", \");\n throw new Error(`Unable to parse ${basename(configPath)}: ${details}.`);\n }\n if (!isObject(value)) {\n throw new Error(`${configPath} must contain a Wrangler configuration object.`);\n }\n return value;\n}\n\nfunction withNodeCompatibility(value: unknown): string[] {\n if (value === undefined) return [\"nodejs_compat\"];\n if (!Array.isArray(value) || !value.every((entry) => typeof entry === \"string\")) {\n throw new Error(\"Wrangler compatibility_flags must be an array of strings.\");\n }\n return value.includes(\"nodejs_compat\") ? [...value] : [...value, \"nodejs_compat\"];\n}\n\nfunction readObject(value: unknown, label: string): JsonObject {\n if (value === undefined) return {};\n if (!isObject(value)) {\n throw new Error(`${label} must be an object.`);\n }\n return value;\n}\n\nfunction isObject(value: unknown): value is JsonObject {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction toImportSpecifier(fromFile: string, target: string): string {\n const value = normalizePath(relative(dirname(fromFile), target));\n return hasRelativePrefix(value) ? value : `./${value}`;\n}\n\nfunction toConfigRelativePath(configDirectory: string, target: string): string {\n const value = normalizePath(relative(configDirectory, target));\n return hasRelativePrefix(value) ? value : `./${value}`;\n}\n\nfunction toRootRelativePath(root: string, target: string): string {\n return normalizePath(relative(root, target));\n}\n\nfunction normalizePath(value: string): string {\n return sep === \"/\" ? value : value.split(sep).join(\"/\");\n}\n\nfunction hasRelativePrefix(value: string): boolean {\n return value.startsWith(\"./\") || value.startsWith(\"../\");\n}\n\nfunction assertInsideRoot(root: string, target: string, label: string): void {\n const pathFromRoot = relative(root, target);\n if (pathFromRoot === \"..\" || pathFromRoot.startsWith(`..${sep}`) || isAbsolute(pathFromRoot)) {\n throw new Error(`${label} must be inside the Farm project root.`);\n }\n}\n\nasync function assertFile(path: string, label: string): Promise<void> {\n try {\n await access(path);\n } catch {\n throw new Error(`${label} was not found at ${path}.`);\n }\n}\n\nasync function assertDirectory(path: string, label: string): Promise<void> {\n try {\n if (!(await stat(path)).isDirectory()) throw new Error();\n } catch {\n throw new Error(`${label} was not found at ${path}.`);\n }\n}\n"],"mappings":";AAAA,SAAS,WAAAA,gBAAe;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;ACPP,SAAS,QAAQ,OAAO,UAAU,MAAM,iBAAiB;AACzD,SAAS,UAAU,SAAS,YAAY,MAAM,UAAU,SAAS,WAAW;AAC5E,SAAS,OAAO,2BAA4C;AAC5D,SAAS,iCAAiC;AAE1C,IAAM,wBAAwB;AA0B9B,eAAsB,2BACpB,SACgC;AAChC,QAAM,OAAO,QAAQ,QAAQ,IAAI;AACjC,QAAM,YAAY,QAAQ,MAAM,QAAQ,SAAS;AACjD,QAAM,aAAa,QAAQ,MAAM,QAAQ,MAAM;AAC/C,mBAAiB,MAAM,YAAY,iBAAiB;AAEpD,QAAM,kBAAkB,QAAQ,UAAU;AAC1C,QAAM,SAAS,MAAM,mBAAmB,UAAU;AAClD,QAAM,kBAAkB,OAAO;AAC/B,MAAI,OAAO,oBAAoB,YAAY,CAAC,gBAAgB,KAAK,GAAG;AAClE,UAAM,IAAI,MAAM,GAAG,UAAU,+CAA+C;AAAA,EAC9E;AACA,MAAI,OAAO,cAAc,MAAM;AAC7B,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AAEA,QAAM,aAAa,QAAQ,iBAAiB,eAAe;AAC3D,QAAM,YAAY,KAAK,WAAW,UAAU,WAAW;AACvD,QAAM,kBAAkB,KAAK,WAAW,QAAQ;AAChD,QAAM,WAAW,YAAY,wBAAwB;AACrD,QAAM,WAAW,WAAW,8BAA8B;AAC1D,QAAM,gBAAgB,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0DAA0D;AAAA,QAC5E;AAEA,cAAM,2BAA2B;AAAA,UAC/B,MAAM,QAAQ;AAAA,UACd,WAAW,QAAQ;AAAA,UACnB;AAAA,UACA,aAAa,QAAQ;AAAA,UACrB,aAAa,QAAQ;AAAA,QACvB,CAAC;AAAA,MACH;AAAA,IACF,IACA,CAAC;AAAA,EACP,CAAC;AACH;AAEO,SAAS,sBAAsB,OAMzB;AACX,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,MAAM,IAAI;AAAA,IACjB;AAAA,IACA,GAAI,MAAM,SAAS,CAAC,UAAU,IAAI,CAAC;AAAA,IACnC,GAAI,MAAM,cAAc,CAAC,SAAS,MAAM,WAAW,IAAI,CAAC;AAAA,EAC1D;AACF;AAEO,SAAS,iCAAiC,UAAU,QAAQ,SAAS,MAAY;AACtF,QAAM,QAAQ,OAAO,SAAS,QAAQ,MAAM,GAAG,EAAE,CAAC,KAAK,KAAK,EAAE;AAC9D,MAAI,CAAC,OAAO,SAAS,KAAK,KAAK,QAAQ,IAAI;AACzC,UAAM,IAAI;AAAA,MACR,uFAAuF,OAAO;AAAA,IAChG;AAAA,EACF;AACF;AAEA,SAAS,WAAW,MAAoB;AACtC,MAAI,CAAC,OAAO,UAAU,IAAI,KAAK,OAAO,KAAK,OAAO,OAAQ;AACxD,UAAM,IAAI,MAAM,qEAAqE;AAAA,EACvF;AACF;","names":["resolve","resolve"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/cf-agent",
3
- "version": "0.1.0-beta.59",
3
+ "version": "0.1.0-beta.60",
4
4
  "description": "First-class Cloudflare Agents integration for Farm.js",
5
5
  "keywords": [
6
6
  "agents",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "jsonc-parser": "^3.3.1",
35
- "@farm.js/core": "0.1.0-beta.59"
35
+ "@farm.js/core": "0.1.0-beta.60"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "^20.10.5",