mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-13 08:15:17 +00:00
fix(cursor): use process.execPath and add safeResolve to model fetcher
- Replace 'node' with process.execPath for cross-platform reliability - Add safeResolve guard in fetchModelsFromDaemon matching startDaemon pattern
This commit is contained in:
1 parent
36f0308a72
commit
94789676b9
2 files changed
+14
-7
No files matched your search
@@ -184,7 +184,7 @@ export async function startDaemon(
|
|||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
|
||||||
proc = spawn('node', args, {
|
proc = spawn(process.execPath, args, {
|
||||||
stdio: ['ignore', 'pipe', 'pipe'],
|
stdio: ['ignore', 'pipe', 'pipe'],
|
||||||
detached: true,
|
detached: true,
|
||||||
shell: process.platform === 'win32',
|
shell: process.platform === 'win32',
|
||||||
|
|||||||
@@ -78,6 +78,13 @@ export const DEFAULT_CURSOR_MODELS: CursorModel[] = [
|
|||||||
*/
|
*/
|
||||||
export async function fetchModelsFromDaemon(port: number): Promise<CursorModel[]> {
|
export async function fetchModelsFromDaemon(port: number): Promise<CursorModel[]> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
let resolved = false;
|
||||||
|
const safeResolve = (models: CursorModel[]) => {
|
||||||
|
if (resolved) return;
|
||||||
|
resolved = true;
|
||||||
|
resolve(models);
|
||||||
|
};
|
||||||
|
|
||||||
const req = http.request(
|
const req = http.request(
|
||||||
{
|
{
|
||||||
// Use 127.0.0.1 instead of localhost for more reliable local connections
|
// Use 127.0.0.1 instead of localhost for more reliable local connections
|
||||||
@@ -95,7 +102,7 @@ export async function fetchModelsFromDaemon(port: number): Promise<CursorModel[]
|
|||||||
data += chunk;
|
data += chunk;
|
||||||
if (data.length > MAX_BODY_SIZE) {
|
if (data.length > MAX_BODY_SIZE) {
|
||||||
req.destroy();
|
req.destroy();
|
||||||
resolve(DEFAULT_CURSOR_MODELS);
|
safeResolve(DEFAULT_CURSOR_MODELS);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -109,24 +116,24 @@ export async function fetchModelsFromDaemon(port: number): Promise<CursorModel[]
|
|||||||
provider: detectProvider(m.id),
|
provider: detectProvider(m.id),
|
||||||
isDefault: m.id === DEFAULT_CURSOR_MODEL,
|
isDefault: m.id === DEFAULT_CURSOR_MODEL,
|
||||||
}));
|
}));
|
||||||
resolve(models.length > 0 ? models : DEFAULT_CURSOR_MODELS);
|
safeResolve(models.length > 0 ? models : DEFAULT_CURSOR_MODELS);
|
||||||
} else {
|
} else {
|
||||||
resolve(DEFAULT_CURSOR_MODELS);
|
safeResolve(DEFAULT_CURSOR_MODELS);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
resolve(DEFAULT_CURSOR_MODELS);
|
safeResolve(DEFAULT_CURSOR_MODELS);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
req.on('error', () => {
|
req.on('error', () => {
|
||||||
resolve(DEFAULT_CURSOR_MODELS);
|
safeResolve(DEFAULT_CURSOR_MODELS);
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('timeout', () => {
|
req.on('timeout', () => {
|
||||||
req.destroy();
|
req.destroy();
|
||||||
resolve(DEFAULT_CURSOR_MODELS);
|
safeResolve(DEFAULT_CURSOR_MODELS);
|
||||||
});
|
});
|
||||||
|
|
||||||
req.end();
|
req.end();
|
||||||
|
|||||||
Reference in new issue
Block a user