diff --git a/netlify/functions/agent-proxy.js b/netlify/functions/agent-proxy.js index 1c087ba..98131c1 100644 --- a/netlify/functions/agent-proxy.js +++ b/netlify/functions/agent-proxy.js @@ -12,18 +12,6 @@ import Anthropic from '@anthropic-ai/sdk' * synchronous execution limit. */ -// --------------------------------------------------------------------------- -// Managed Agent configuration -// --------------------------------------------------------------------------- -// The Managed Agent ID and Environment ID come from the Claude Console. -// Optionally, vault IDs may be passed for MCP credential access. -const AGENT_ID = process.env.ANTHROPIC_AGENT_ID -const ENVIRONMENT_ID = process.env.ANTHROPIC_ENVIRONMENT_ID -const VAULT_IDS = (process.env.ANTHROPIC_VAULT_IDS || '') - .split(',') - .map((s) => s.trim()) - .filter(Boolean) - // All Managed Agents endpoints require this beta header. const MANAGED_AGENTS_BETA = 'managed-agents-2026-04-01' @@ -71,11 +59,21 @@ export default async (req /*, context */) => { return new Response('Invalid station website URL', { status: 400 }) } - if (!AGENT_ID || !ENVIRONMENT_ID) { - return new Response( - 'Server is missing ANTHROPIC_AGENT_ID or ANTHROPIC_ENVIRONMENT_ID', - { status: 500 }, - ) + // Read env vars at request time (Netlify makes them available per-invocation). + const AGENT_ID = process.env.ANTHROPIC_AGENT_ID + const ENVIRONMENT_ID = process.env.ANTHROPIC_ENVIRONMENT_ID + const VAULT_IDS = (process.env.ANTHROPIC_VAULT_IDS || '') + .split(',') + .map((s) => s.trim()) + .filter(Boolean) + + const missing = [] + if (!AGENT_ID) missing.push('ANTHROPIC_AGENT_ID') + if (!ENVIRONMENT_ID) missing.push('ANTHROPIC_ENVIRONMENT_ID') + if (missing.length) { + return new Response(`Server is missing env var(s): ${missing.join(', ')}`, { + status: 500, + }) } let client