import type { CollaborationBus, InjectedToolResult } from '../coordination/collab-bus.js'; import type { ToolCallPipelinePayload } from '../core/agent.js'; import type { Middleware } from '../kernel/pipeline.js'; /** * collabPauseMiddleware — gates the agent's `toolCall` pipeline on * the collaboration pause signal. * * Position: must be installed as the *first* middleware in the * `toolCall` pipeline so it runs before permission checks, retries, * and the tool itself. That way the controller can halt an agent * regardless of what the model is about to do. * * Semantics: * - When the bus is not paused: pass through (`next()`). * - When the bus is paused: await `bus.waitForResume(timeoutMs)`. * The default timeout is 60s — long enough for a human to think, * short enough that a forgotten controller doesn't pin the agent * forever. The auto-resume on timeout is logged below. * * Phase 3 of idea #13. Manual tool-call injection (a controller * "writing" a tool result) is *not* in scope for this middleware — * that requires splicing the injected result into the agent's * message stream and is a follow-up. */ export interface CollabPauseMiddlewareOptions { /** * How long to wait for a resume before auto-resuming the bus. * Defaults to 60_000 ms. Set to 0 for an unbounded wait (the * caller is then responsible for cancellation via the bus itself). */ defaultTimeoutMs?: number | undefined; /** * Optional logger — receives a debug line on pause entry and on * timeout-driven auto-resume. Matches the `Logger` token surface * so the runtime can pass its existing logger. */ logger?: { debug?: ((msg: string) => void) | undefined; warn?: ((msg: string) => void) | undefined; }; } export declare function collabPauseMiddleware(bus: CollaborationBus, opts?: CollabPauseMiddlewareOptions): Middleware; /** * collabInjectMiddleware — Phase 4 of idea #13. Splices * controller-injected tool results into the toolCall pipeline. * * Position: should run AFTER `collabPauseMiddleware` so the * controller has a chance to pause + inject before the next tool * executes. Install order: * - `pipeline.toolCall.prepend(collabInject)` * - `pipeline.toolCall.prepend(collabPause)` // runs first * * Semantics: * - On every tool call, the middleware asks the bus for an * injection matching `payload.toolUse.id`. * - If one is queued, the payload's `result` is overwritten with * a synthetic ToolResultBlock carrying the injected content + * `is_error` flag. The real `next()` is NOT called; downstream * middleware sees the controller's synthetic result. * - The injection is consumed once and removed from the bus. * * Why this shape: the agent loop's existing `tool.executed` event still * fires (carrying the injected content), so the session log + observers see * a normal-looking call — just with the controller's intent in the result. */ export declare function collabInjectMiddleware(bus: CollaborationBus, opts?: { logger?: { debug?: ((msg: string) => void) | undefined; warn?: ((msg: string) => void) | undefined; }; }): Middleware; export type { InjectedToolResult }; //# sourceMappingURL=collab-pause.d.ts.map