2026-07-25 13:06:40 +08:00
|
|
|
/** Host HTTP bridge for browser-client RPC. */
|
2026-07-25 01:19:10 +08:00
|
|
|
import type { Context } from 'cordis'
|
2026-07-25 13:06:40 +08:00
|
|
|
// Activates the httpServer Context merge used below.
|
2026-07-25 01:19:10 +08:00
|
|
|
import type { WebRoute } from '@deepseek-ai/dsh-host-webserver'
|
|
|
|
|
import { toFetchHandler } from '@deepseek-ai/dsh-host-apiproxy'
|
|
|
|
|
import { API_PATH } from './api-path.ts'
|
|
|
|
|
import { bridge } from './http-bridge.ts'
|
2026-07-19 21:17:57 +08:00
|
|
|
|
2026-07-25 01:19:10 +08:00
|
|
|
export { API_PATH } from './api-path.ts'
|
|
|
|
|
|
2026-07-25 13:06:40 +08:00
|
|
|
/** Stable Cordis plugin name. */
|
2026-07-25 01:19:10 +08:00
|
|
|
export const name = 'client-connection'
|
|
|
|
|
|
2026-07-25 13:06:40 +08:00
|
|
|
/** Services required before mounting the route. */
|
2026-07-25 01:19:10 +08:00
|
|
|
export const inject = ['httpServer', 'apiProxy']
|
|
|
|
|
|
|
|
|
|
/**
|
2026-07-25 13:06:40 +08:00
|
|
|
* Mounts the API gateway under the browser transport prefix.
|
|
|
|
|
* @param ctx - Host plugin context.
|
2026-07-25 01:19:10 +08:00
|
|
|
*/
|
|
|
|
|
export function apply(ctx: Context): void {
|
|
|
|
|
const apiHandler = toFetchHandler(ctx.apiProxy)
|
|
|
|
|
const route: WebRoute = {
|
|
|
|
|
kind: 'prefix',
|
|
|
|
|
path: API_PATH,
|
|
|
|
|
handler: (req, res) => bridge(req, res, apiHandler),
|
|
|
|
|
}
|
|
|
|
|
ctx.effect(() => ctx.httpServer.register(route), 'client-connection: /api route')
|
|
|
|
|
}
|