feat(runner): migrate vibn-agent-runner to use frontend MCP proxy tools and updated headless prompt
This commit is contained in:
55
patch_sessions_route.js
Normal file
55
patch_sessions_route.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const file = 'vibn-frontend/app/api/projects/[projectId]/agent/sessions/route.ts';
|
||||
let code = fs.readFileSync(file, 'utf8');
|
||||
|
||||
// Inject the workspace API key fetching logic
|
||||
if (!code.includes('listWorkspaceApiKeys')) {
|
||||
code = code.replace(
|
||||
'import { query } from "@/lib/db-postgres";',
|
||||
'import { query } from "@/lib/db-postgres";\nimport { listWorkspaceApiKeys, mintWorkspaceApiKey, revealWorkspaceApiKey } from "@/lib/auth/workspace-auth";'
|
||||
);
|
||||
|
||||
const injectCode = `
|
||||
const wsResult = await query<{ workspace_id: string }>(
|
||||
\`SELECT vibn_workspace_id as workspace_id FROM fs_projects WHERE id = $1 LIMIT 1\`,
|
||||
[projectId]
|
||||
);
|
||||
if (!wsResult.length) {
|
||||
return NextResponse.json({ error: "Project not found" }, { status: 404 });
|
||||
}
|
||||
const workspaceId = wsResult[0].workspace_id;
|
||||
|
||||
// Grab or mint a default API key for the runner to use
|
||||
let mcpToken = "";
|
||||
const keys = await listWorkspaceApiKeys(workspaceId);
|
||||
let defaultKey = keys.find((k: any) => k.name === 'default' && !k.revoked_at);
|
||||
if (!defaultKey) {
|
||||
const minted = await mintWorkspaceApiKey({ workspaceId, name: 'default', createdBy: session.user.id, scopes: ['workspace:*'] });
|
||||
mcpToken = minted.token;
|
||||
} else {
|
||||
const revealed = await revealWorkspaceApiKey(workspaceId, defaultKey.id);
|
||||
if (revealed) mcpToken = revealed.token;
|
||||
else {
|
||||
const minted = await mintWorkspaceApiKey({ workspaceId, name: 'default', createdBy: session.user.id, scopes: ['workspace:*'] });
|
||||
mcpToken = minted.token;
|
||||
}
|
||||
}
|
||||
|
||||
// Add VIBN_API_URL so the runner knows where to send MCP requests
|
||||
const vibnApiUrl = process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000";
|
||||
`;
|
||||
|
||||
code = code.replace(
|
||||
'const sessionId = rows[0].id;',
|
||||
'const sessionId = rows[0].id;\n' + injectCode
|
||||
);
|
||||
|
||||
code = code.replace(
|
||||
'coolifyAppUuid,\n }),',
|
||||
'coolifyAppUuid,\n mcpToken,\n vibnApiUrl\n }),'
|
||||
);
|
||||
|
||||
fs.writeFileSync(file, code);
|
||||
console.log("Patched session route to forward MCP token");
|
||||
}
|
||||
Reference in New Issue
Block a user