Spaces:
Running
Running
Commit
·
0dfcc22
1
Parent(s):
d8c725b
feat: install uv package when uvx command is detected
Browse files- Added functionality to install the 'uv' package via pip when the 'uvx' command is detected in the chat route.
- Implemented subprocess handling to ensure installation completion before proceeding.
- app/api/chat/route.ts +12 -0
app/api/chat/route.ts
CHANGED
@@ -115,6 +115,18 @@ export async function POST(req: Request) {
|
|
115 |
|
116 |
// Check for uvx pattern and transform to python3 -m uv run
|
117 |
if (mcpServer.command === 'uvx') {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
console.log("Detected uvx pattern, transforming to python3 -m uv run");
|
119 |
mcpServer.command = 'python3';
|
120 |
// Get the tool name (first argument)
|
|
|
115 |
|
116 |
// Check for uvx pattern and transform to python3 -m uv run
|
117 |
if (mcpServer.command === 'uvx') {
|
118 |
+
// install uv
|
119 |
+
const subprocess = spawn('pip3', ['install', 'uv']);
|
120 |
+
subprocess.on('close', (code: number) => {
|
121 |
+
if (code !== 0) {
|
122 |
+
console.error(`Failed to install uv: ${code}`);
|
123 |
+
}
|
124 |
+
});
|
125 |
+
// wait for the subprocess to finish
|
126 |
+
await new Promise((resolve) => {
|
127 |
+
subprocess.on('close', resolve);
|
128 |
+
console.log("installed uv");
|
129 |
+
});
|
130 |
console.log("Detected uvx pattern, transforming to python3 -m uv run");
|
131 |
mcpServer.command = 'python3';
|
132 |
// Get the tool name (first argument)
|