Mount IM RPC channels via plugin webServer to fix HTTP 405.

connection.rpc.handle looks up webServer on a Cordis fiber that does not inject it, so channel routes never registered after host restart.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-09-14 21:32:43 +08:00
parent dd2365407e
commit 6107692418
18 changed files with 666 additions and 330 deletions

View file

@ -23,6 +23,8 @@ export const inject = [
'connection',
'credentials',
'typertGateway',
// Plugin-side RPC mounts use ctx.webServer.register (see connection-rpc-mount.mjs).
'webServer',
];
function channelConfig(config, name, deliveryService) {
@ -188,21 +190,11 @@ export function createImHostPlugin(internals = {}) {
},
}));
}
const activate = async (readyCtx) => {
await activateChannels(readyCtx, config, deliveryService);
};
if (typeof ctx?.inject === 'function') {
const modern = typeof ctx?.typertGateway?.stream === 'function';
await ctx.inject(
modern ? ['sessionController', 'workspaceController'] : ['apiProxy'],
activate,
);
ctx.inject(['webServer'], (httpCtx) => {
startDeliveryHttp(httpCtx, deliveryService);
});
return;
}
await activate(ctx);
// Activate on this fiber (already injects webServer). Do not defer to a
// sessionController child fiber — that fiber cannot read webServer, so
// every channel rpc.handle throws and the UI sees HTTP 405.
await activateChannels(ctx, config, deliveryService);
if (ctx?.webServer?.register && typeof ctx?.effect === 'function') {
startDeliveryHttp(ctx, deliveryService);
}