From d6367fd7d63aa07f1c926fd5aadb4562c3a859c8 Mon Sep 17 00:00:00 2001 From: huijiro Date: Sun, 29 Mar 2026 15:51:35 -0300 Subject: [PATCH 1/5] fix: apply gateway env patching before agent discovery in dev mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent discovery imports eval files at build time, which may import LLM SDKs (e.g. groq-sdk) at module scope. These SDKs check for API keys like GROQ_API_KEY at import time, but the gateway env patching that sets these keys was only running later (inside createApp → applyDevPatches). Move SDK key loading, AGENTUITY_TRANSPORT_URL setup, and gateway env patching (GROQ_API_KEY, OPENAI_API_KEY, ANTHROPIC_API_KEY) to a new Step 0b that runs before discoverAgents(), matching the same gateway logic from runtime/src/dev-patches/gateway.ts. Also includes template fixes: - Remove deprecated agentuity.config.ts - Update vite.config.ts - Add workbench config to app.ts --- packages/cli/src/cmd/dev/index.ts | 83 +++++++++++++++++++++++------ templates/_base/agentuity.config.ts | 31 ----------- templates/_base/app.ts | 3 ++ templates/_base/vite.config.ts | 5 +- 4 files changed, 72 insertions(+), 50 deletions(-) delete mode 100644 templates/_base/agentuity.config.ts diff --git a/packages/cli/src/cmd/dev/index.ts b/packages/cli/src/cmd/dev/index.ts index 6721ae574..9c3732123 100644 --- a/packages/cli/src/cmd/dev/index.ts +++ b/packages/cli/src/cmd/dev/index.ts @@ -710,6 +710,68 @@ export const command = createCommand({ releaseLockSync(rootDir); }); + // ================================================================ + // Step 0b: Early environment setup + // ================================================================ + // Load SDK key and set gateway env vars BEFORE agent discovery. + // Agent discovery imports eval files, which may import LLM SDKs at + // module scope. Those SDKs check for API keys (e.g. GROQ_API_KEY) + // at import time, so the gateway env patching must happen first. + + if (!process.env.AGENTUITY_SDK_KEY) { + const sdkKey = await loadProjectSDKKey(logger, rootDir); + if (sdkKey) { + process.env.AGENTUITY_SDK_KEY = sdkKey; + } else if (project) { + tui.warning( + 'AGENTUITY_SDK_KEY not found in .env file. Numerous features will be unavailable.' + ); + tui.bullet( + `Run "${getCommand('cloud env pull')}" to sync your SDK key, or add AGENTUITY_SDK_KEY to your .env file.` + ); + } + } + + process.env.NODE_ENV = 'development'; + process.env.AGENTUITY_ENV = 'development'; + + if (project) { + const earlyServiceUrls = getServiceUrls(project.region); + if (!process.env.AGENTUITY_TRANSPORT_URL) { + process.env.AGENTUITY_TRANSPORT_URL = earlyServiceUrls.catalyst; + } + } + + // Apply gateway env patching so LLM SDK API keys are set before + // agent discovery imports eval files that may reference them. + { + const sdkKey = process.env.AGENTUITY_SDK_KEY; + const gatewayUrl = + process.env.AGENTUITY_AIGATEWAY_URL || + process.env.AGENTUITY_TRANSPORT_URL || + (sdkKey ? 'https://catalyst.agentuity.cloud' : ''); + + const gatewayConfigs = [ + { + apiKeyEnv: 'ANTHROPIC_API_KEY', + baseUrlEnv: 'ANTHROPIC_BASE_URL', + provider: 'anthropic', + }, + { apiKeyEnv: 'GROQ_API_KEY', baseUrlEnv: 'GROQ_BASE_URL', provider: 'groq' }, + { apiKeyEnv: 'OPENAI_API_KEY', baseUrlEnv: 'OPENAI_BASE_URL', provider: 'openai' }, + ]; + + for (const cfg of gatewayConfigs) { + const currentKey = process.env[cfg.apiKeyEnv]; + if (currentKey && currentKey !== sdkKey) continue; + if (gatewayUrl && sdkKey) { + process.env[cfg.apiKeyEnv] = sdkKey; + process.env[cfg.baseUrlEnv] = `${gatewayUrl}/gateway/${cfg.provider}`; + logger.debug('Enabled Agentuity AI Gateway for %s', cfg.provider); + } + } + } + // ================================================================ // Step 1: Prepare dev server (once) // ================================================================ @@ -793,27 +855,14 @@ export const command = createCommand({ }); // ================================================================ - // Step 2: Set environment variables + // Step 2: Set remaining environment variables // ================================================================ - - if (!process.env.AGENTUITY_SDK_KEY) { - const sdkKey = await loadProjectSDKKey(logger, rootDir); - if (sdkKey) { - process.env.AGENTUITY_SDK_KEY = sdkKey; - } else if (project) { - tui.warning( - 'AGENTUITY_SDK_KEY not found in .env file. Numerous features will be unavailable.' - ); - tui.bullet( - `Run "${getCommand('cloud env pull')}" to sync your SDK key, or add AGENTUITY_SDK_KEY to your .env file.` - ); - } - } + // Note: AGENTUITY_SDK_KEY, NODE_ENV, AGENTUITY_ENV, and + // AGENTUITY_TRANSPORT_URL are already set in Step 0b (before + // agent discovery) to support gateway env patching. process.env.AGENTUITY_SDK_DEV_MODE = 'true'; process.env.AGENTUITY_RUNTIME = 'yes'; - process.env.AGENTUITY_ENV = 'development'; - process.env.NODE_ENV = 'development'; process.env.AGENTUITY_PROJECT_DIR = rootDir; if (project?.region) { process.env.AGENTUITY_REGION = project.region; diff --git a/templates/_base/agentuity.config.ts b/templates/_base/agentuity.config.ts deleted file mode 100644 index 876a1df69..000000000 --- a/templates/_base/agentuity.config.ts +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Agentuity Configuration - * - */ - -import type { AgentuityConfig } from '@agentuity/cli'; -import react from '@vitejs/plugin-react'; - -export default { - /** - * Workbench (development only) - * - * Visual UI for testing agents during development. Not included in production builds. - * Omit this section to disable. Access at http://localhost:3500/workbench - */ - workbench: { - route: '/workbench', - headers: {}, - }, - - /** - * Vite Plugins - * - * Plugins for the client build (src/web/). - * The React plugin is included by default — replace it with your - * framework of choice (e.g., @sveltejs/vite-plugin-svelte). - * - * @see https://vitejs.dev/plugins/ - */ - plugins: [react()], -} satisfies AgentuityConfig; diff --git a/templates/_base/app.ts b/templates/_base/app.ts index 01ca57231..18219afd3 100644 --- a/templates/_base/app.ts +++ b/templates/_base/app.ts @@ -5,6 +5,9 @@ import agents from './src/agent'; const app = await createApp({ router: { path: '/api', router: api }, agents, + workbench: { + route: "/workbench", + }, }); const {logger, server} = app; diff --git a/templates/_base/vite.config.ts b/templates/_base/vite.config.ts index e8d137a92..37047939b 100644 --- a/templates/_base/vite.config.ts +++ b/templates/_base/vite.config.ts @@ -1,13 +1,14 @@ import react from '@vitejs/plugin-react'; +import tailwindcss from '@tailwindcss/vite'; import { defineConfig } from 'vite'; import { join } from 'node:path'; export default defineConfig({ - plugins: [react()], + plugins: [react(), tailwindcss()], root: '.', build: { rollupOptions: { input: join(__dirname, 'src/web/index.html'), }, }, -}); \ No newline at end of file +}); From 90ff6b6c67a766972bfd41600d244465a35916d5 Mon Sep 17 00:00:00 2001 From: huijiro Date: Sun, 29 Mar 2026 15:59:15 -0300 Subject: [PATCH 2/5] fix(templates): add Tailwind CSS import to _base template The _base template enables @tailwindcss/vite in vite.config.ts but never imports Tailwind, so utilities are never generated. Add src/web/App.css with the Tailwind import directive and import it from frontend.tsx (the entry point), matching the pattern used in the default template. --- templates/_base/src/web/App.css | 1 + templates/_base/src/web/frontend.tsx | 1 + 2 files changed, 2 insertions(+) create mode 100644 templates/_base/src/web/App.css diff --git a/templates/_base/src/web/App.css b/templates/_base/src/web/App.css new file mode 100644 index 000000000..f1d8c73cd --- /dev/null +++ b/templates/_base/src/web/App.css @@ -0,0 +1 @@ +@import "tailwindcss"; diff --git a/templates/_base/src/web/frontend.tsx b/templates/_base/src/web/frontend.tsx index eaa6517d3..ad2bc3822 100644 --- a/templates/_base/src/web/frontend.tsx +++ b/templates/_base/src/web/frontend.tsx @@ -9,6 +9,7 @@ import React, { StrictMode } from 'react'; import { createRoot } from 'react-dom/client'; import { AgentuityProvider } from '@agentuity/react'; import { App } from './App'; +import './App.css'; function init() { const elem = document.getElementById('root'); From 46f580f3acab3a171887cfa05498a5791e80e00c Mon Sep 17 00:00:00 2001 From: huijiro Date: Sun, 29 Mar 2026 16:01:39 -0300 Subject: [PATCH 3/5] fix(templates): move Tailwind vite plugin from _base to default template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The _base template uses inline