cc-haha/src/server/proxy/standaloneProviderProxy.ts
程序员阿江(Relakkes) a090070352 fix(server): repair provider proxy and cron permissions
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
2026-06-22 23:45:15 +08:00

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
}