mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-18 13:23:33 +08:00
Fix #845 by starting a lightweight standalone provider proxy for CLI-only OpenAI-compatible desktop providers, avoiding a fixed localhost:3456 proxy when the desktop server is not running. Fix #847 by passing explicit --permission-mode bypassPermissions for scheduled task subprocesses alongside the dangerous-skip flag. Tested: bun test src/utils/managedEnv.test.ts src/server/__tests__/provider-runtime-env.test.ts src/server/__tests__/cron-scheduler-launcher.test.ts Tested: bun run check:server Confidence: high Scope-risk: moderate
32 lines
850 B
TypeScript
32 lines
850 B
TypeScript
import { handleProxyRequest } from './handler.js'
|
|
|
|
let standaloneProviderProxy: ReturnType<typeof Bun.serve> | null = null
|
|
|
|
export function ensureStandaloneProviderProxy(): number {
|
|
if (standaloneProviderProxy) {
|
|
return standaloneProviderProxy.port
|
|
}
|
|
|
|
standaloneProviderProxy = Bun.serve({
|
|
port: 0,
|
|
hostname: '127.0.0.1',
|
|
async fetch(req) {
|
|
const url = new URL(req.url)
|
|
if (url.pathname === '/health') {
|
|
return Response.json({ status: 'ok' })
|
|
}
|
|
if (url.pathname.startsWith('/proxy/')) {
|
|
return handleProxyRequest(req, url)
|
|
}
|
|
return Response.json({ error: 'Not Found' }, { status: 404 })
|
|
},
|
|
})
|
|
|
|
return standaloneProviderProxy.port
|
|
}
|
|
|
|
export function stopStandaloneProviderProxyForTests(): void {
|
|
standaloneProviderProxy?.stop(true)
|
|
standaloneProviderProxy = null
|
|
}
|