histoire
Version:
A fast story book powered by Vite
24 lines (23 loc) • 1.04 kB
JavaScript
import { getMcpObserver } from '../mcp/observer/context.js';
import { getContextRegistry } from '../runtime/registry.js';
import { createAcpManager } from './manager.js';
/** Managers belong to exact dev generations; retired contexts retain no process. */
const managers = new WeakMap();
/** Provides a lazy manager shared by the UI channel and comment dispatcher. */
export function getAcpManager(ctx) {
if (ctx.mode !== 'dev')
throw new Error('ACP agents are unavailable in static builds');
let manager = managers.get(ctx);
if (!manager) {
manager = createAcpManager({ root: ctx.root, config: ctx.config.agents, mcpEndpoint: () => getMcpObserver(ctx)?.snapshot().endpoint });
managers.set(ctx, manager);
const captured = manager;
getContextRegistry(ctx).cleanup.add(async () => {
if (managers.get(ctx) === captured)
managers.delete(ctx);
await captured.close();
});
}
return manager;
}
export { createAcpManager } from './manager.js';