fix: properly pass env vars to cached tools and add extensive logging
PROBLEM: - Tool wrappers cached env vars in closure, so cached tools used stale env - Client env vars weren't reaching Railway executor even when provided - No visibility into env var flow through the system SOLUTION: 1. Store env vars per conversation in conversationEnv Map 2. Tool execute functions look up latest env from Map (not closure) 3. Chat API calls setConversationEnv() on each request 4. Added logging at every step 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
1bf7879c1e
commit
377f90989d
3 changed files with 65 additions and 10 deletions
|
|
@ -173,6 +173,14 @@ async function executeTool(req: Request): Promise<Response> {
|
|||
const body = await req.json();
|
||||
const { packageName, exportName, version, importUrl, params, env } = body;
|
||||
|
||||
console.log(`📥 Execute request:`, {
|
||||
packageName,
|
||||
exportName,
|
||||
version,
|
||||
envKeys: env ? Object.keys(env) : [],
|
||||
envValues: env || {},
|
||||
});
|
||||
|
||||
if (!packageName || !exportName || !version) {
|
||||
return Response.json(
|
||||
{
|
||||
|
|
@ -220,8 +228,15 @@ async function executeTool(req: Request): Promise<Response> {
|
|||
console.log(`🔐 Injecting ${envKeys.length} environment variables:`, envKeys);
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
Deno.env.set(key, String(value));
|
||||
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)}...`));
|
||||
} else {
|
||||
console.log(`⚠️ No env vars provided in request`);
|
||||
}
|
||||
} else {
|
||||
console.log(`⚠️ No env object in request body`);
|
||||
}
|
||||
|
||||
// Execute the tool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue