fix: use function body in DefaultChatTransport to send latest env vars

PROBLEM:
DefaultChatTransport body is cloned ONCE on mount, so env vars
were always empty {} even after localStorage loaded them.

SOLUTION:
Use a function for body instead of an object. AI SDK v6 calls
body() on each request, ensuring latest env vars are sent.

Changes:
- useChat.ts: body: { env } → body: () => ({ env: buildEnvObject() })
- buildEnvObject() is called fresh on each request
- Env vars now sent correctly to /api/chat

Credit: ChatGPT for identifying the exact AI SDK v6 pattern

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ajax Davis 2025-12-04 14:25:59 +10:00
parent 377f90989d
commit 6e7c75dd14
5 changed files with 111 additions and 14 deletions

View file

@ -231,7 +231,10 @@ async function executeTool(req: Request): Promise<Response> {
console.log(` ✅ Set ${key} = ${String(value).substring(0, 10)}...`);
}
// Verify they're set
console.log(`🔍 Verification - Deno.env has:`, envKeys.map(k => `${k}=${Deno.env.get(k)?.substring(0, 10)}...`));
console.log(
`🔍 Verification - Deno.env has:`,
envKeys.map((k) => `${k}=${Deno.env.get(k)?.substring(0, 10)}...`)
);
} else {
console.log(`⚠️ No env vars provided in request`);
}