/** * dsh-ask-router — interaction routing for ask-user questions. * * Answerers compose on the scoped 'user-questions/request' cordis waterfall, * where a listener answers by returning a value and delegates by calling * `next()`. This plugin registers as one waterfall answerer. * * The plugin provides `ctx.askSurfaces`, a registry where UIs register as * surfaces with a `claim(request)` predicate ("the asking session is mine"); * on ask it fans the question out to every claiming surface (when nobody * claims, to every registered surface — visible somewhere beats failing), * and the FIRST completed answer wins; every other surface gets * `settled(request, winnerName)` so it can dismiss its UI; an aborted ask * rejects everywhere (surfaces also observe the request's own signal). * * Coexistence is the point: UIs answer side by side on the waterfall, so the * router can even multiplex for a web profile; with zero surfaces it * delegates via next(). */ import { Context } from '@deepseek-ai/cordis'; import type { AskUserQuestionAnswer, AskUserQuestionRequest } from '@deepseek-ai/dsh-user-questions'; /** One interaction surface able to render and answer ask-user questions. */ export interface AskSurface { /** Stable display name (used in "answered on X" notices). */ readonly name: string; /** Whether this surface currently drives the asking agent's session. */ claim(request: AskUserQuestionRequest): boolean; /** Render the question and resolve with the human's answer. */ ask(request: AskUserQuestionRequest): Promise; /** Another surface answered first — dismiss the rendered question. */ settled?(request: AskUserQuestionRequest, by: string): void; } /** The registry surface UIs register against (ctx.get('askSurfaces')). */ export interface AskSurfaces { register(surface: AskSurface): () => void; } declare module '@deepseek-ai/cordis' { interface Context { askSurfaces: AskSurfaceRegistry; } } /** * Plain registry (no Service base — trivially unit-testable); apply() * provides it under `askSurfaces` so surfaces find it via ctx.get(). */ export declare class AskSurfaceRegistry { private readonly surfaces; register(surface: AskSurface): () => void; /** Snapshot of the registered surfaces in registration order. */ list(): readonly AskSurface[]; } /** Best-effort settled() dispatcher shape shared by raceAsk and routeAsk. */ type SettleSurface = (surface: AskSurface, request: AskUserQuestionRequest, by: string) => void; /** * Race the router's own surfaces against the rest of the waterfall. * * The host 0.2.2-rc.x client bridge claims and consumes `user-questions/request` * without ever calling `next()`, so a tail-registered router answerer is * silently skipped on sessions the GUI has opened. Registering with * `{ prepend: true }` puts us ahead of that bridge; this arbiter then lets the * two answerers coexist: both branches are forked in the same tick and the * first terminal outcome wins, exactly one `next()` is ever issued. * * - surface branch wins -> return its answer; a late downstream result or * rejection is swallowed (the losing surfaces are already settled inside * routeAsk). * - downstream wins -> dismiss every surface via settled(), return its * answer. A late surface answer is ignored by the one-way gate. * - surface rejects (non-abort) -> that branch is dead; fall back to and wait * for downstream. If both reject, surface's error code wins unless the * request signal was aborted, in which case ASK_ABORTED is propagated. * * `request.signal` is never aborted by us — it belongs to the dispatcher. */ export declare function raceAsk(surfaces: readonly AskSurface[], request: AskUserQuestionRequest, next: () => Promise): Promise; /** * Route one ask: fan out to the claiming surfaces (all registered when * nobody claims), first answer wins, losers get settled(). Resolves the * outer promise exactly once; failures only reject when EVERY target failed. */ export declare function routeAsk(surfaces: readonly AskSurface[], request: AskUserQuestionRequest, settle?: SettleSurface): Promise; export declare const inject: string[]; export declare function apply(ctx: Context): void; export {};