(app: ConfigRouteHost, ix: IInstantiationService)
| 28 | } |
| 29 | |
| 30 | export function registerConfigRoutes(app: ConfigRouteHost, ix: IInstantiationService): void { |
| 31 | const getRoute = defineRoute( |
| 32 | { |
| 33 | method: 'GET', |
| 34 | path: '/config', |
| 35 | success: { data: configResponseSchema }, |
| 36 | description: 'Get the global Kimi configuration (secrets redacted)', |
| 37 | tags: ['config'], |
| 38 | }, |
| 39 | async (req, reply) => { |
| 40 | const config = await ix.invokeFunction((a) => a.get(IConfigService).get()); |
| 41 | reply.send(okEnvelope(config, req.id)); |
| 42 | }, |
| 43 | ); |
| 44 | app.get(getRoute.path, getRoute.options, getRoute.handler as Parameters<ConfigRouteHost['get']>[2]); |
| 45 | |
| 46 | const setRoute = defineRoute( |
| 47 | { |
| 48 | method: 'POST', |
| 49 | path: '/config', |
| 50 | body: patchConfigRequestSchema, |
| 51 | success: { data: configResponseSchema }, |
| 52 | errors: { |
| 53 | [ErrorCode.VALIDATION_FAILED]: {}, |
| 54 | }, |
| 55 | description: 'Update the global Kimi configuration (merge semantics)', |
| 56 | tags: ['config'], |
| 57 | }, |
| 58 | async (req, reply) => { |
| 59 | try { |
| 60 | const config = await ix.invokeFunction((a) => |
| 61 | a.get(IConfigService).set(req.body), |
| 62 | ); |
| 63 | reply.send(okEnvelope(config, req.id)); |
| 64 | } catch (err) { |
| 65 | const message = err instanceof Error ? err.message : String(err); |
| 66 | reply.send(errEnvelope(ErrorCode.VALIDATION_FAILED, message, req.id)); |
| 67 | } |
| 68 | }, |
| 69 | ); |
| 70 | app.post(setRoute.path, setRoute.options, setRoute.handler as Parameters<ConfigRouteHost['post']>[2]); |
| 71 | } |
no test coverage detected