/** * DshEventBridge — IEventBridge adapter for the dsh (DeepSeek Harness) platform. * * Bridges dsh's cordis event bus (`ctx.on` / `ctx.emit`) plus the dsh * session/tools service events into CanonicalEvents, following the same * pattern as PiEventBridge on the Pi side. * * Subscribed dsh events (verified against `docs/dsh-plugin-contract.md`): * * - session service (`@deepseek-ai/dsh-session`, §4.1): * `session/created`, `session/disposed`, `session/event`, `session/flush` * - tools service (`@deepseek-ai/dsh-tools`, §3.5): * `tools/result` (frozen final outcome), `tools/change` (registry change) * - skill service (`@deepseek-ai/dsh-skill`): * `skills/change` (unfiltered catalog-invalidation notification) * * `tools/pre-execute` / `tools/post-execute` are deliberately NOT bridged * here — those are the tool lifecycle extension points owned by * DshHookProvider (hook-provider.ts), which maps rolebox `tool-before` / * `tool-after` onto them. * * `session/event` carries per-event `SessionEvent` payloads whose own `type` * field (e.g. `user/message`, `turn/end`, `todo/write`) refines the canonical * mapping; the raw sub-type is preserved as `rawType`. * * The cordis ctx is consumed structurally (duck-typed). This module does NOT * import `@deepseek-ai/cordis` or any `@deepseek-ai/*` package, and MUST NOT * import from `@opencode-ai/*`. * * @module */ import type { CanonicalEvent, CanonicalEventHandler, CanonicalEventType, IEventBridge } from "../../ports/event-bridge.ts"; /** * Minimal structural surface of a cordis `Context` event bus. * * Only `on` / `emit` are required — the two event operations the bridge uses * (cordis `Context` proxies both to its `EventsService`; see * `dsh-plugin-contract.md` §2.5). `on` returns a disposer, matching cordis. */ export interface DshCordisContext { /** Subscribe to a cordis/dsh event. Returns an unsubscribe disposer. */ on(event: string, listener: (...args: unknown[]) => void): (() => void) | void; /** Emit a cordis/dsh event. */ emit(event: string, ...args: unknown[]): void; } /** * Map a dsh event type string to a CanonicalEventType. * Unknown or unmapped types resolve to "unknown". */ export declare function mapDshEventType(dshType: string): CanonicalEventType; /** Top-level dsh session service events the bridge subscribes to. */ export declare const DSH_SESSION_EVENTS: readonly ["session/created", "session/disposed", "session/event", "session/flush"]; /** Top-level dsh tools service events the bridge subscribes to. */ export declare const DSH_TOOLS_EVENTS: readonly ["tools/result", "tools/change"]; /** * Top-level dsh skill service events the bridge subscribes to. * * `skills/change` is the unfiltered catalog-invalidation notification emitted * when a skill provider, runtime contribution, or provider-backed catalog * changes (`@deepseek-ai/dsh-skill` index.ts:298). */ export declare const DSH_SKILL_EVENTS: readonly ["skills/change"]; /** * IEventBridge implementation that adapts dsh cordis events into the * canonical event system. * * Subscribes to the dsh session/tools/skill service events on construction and * forwards each normalized event to registered handlers. General-purpose * handlers receive every event; type-specific handlers only receive events * matching their canonical type. */ export declare class DshEventBridge implements IEventBridge { /** General-purpose handlers invoked for every emitted event. */ private readonly handlers; /** Type-specific handlers, keyed by canonical event type. */ private readonly typeHandlers; /** Cordis disposers returned by `ctx.on` — released by `dispose()`. */ private readonly disposers; private readonly _log; /** * @param ctx - Structural cordis context (`ctx.on` / `ctx.emit`). */ constructor(ctx: DshCordisContext); /** * Subscribe a general-purpose event handler. * The handler receives all emitted canonical events. * * @param handler - Callback receiving the canonical event. * @returns An unsubscribe function that removes the handler. */ on(handler: CanonicalEventHandler): () => void; /** * Subscribe a type-specific event handler. * The handler only receives events matching the specified canonical type. * * @param type - The canonical event type to subscribe to. * @param handler - Callback receiving the canonical event. * @returns An unsubscribe function that removes the handler. */ onType(type: CanonicalEventType, handler: CanonicalEventHandler): () => void; /** * Normalize a raw dsh event into a CanonicalEvent. * * Accepts two structural shapes (no SDK import needed): * * - an object with a `type` string — the dsh event name (e.g. * `session/created`) or a `SessionEvent` sub-type (e.g. `turn/end`); * every other enumerable key becomes a `properties` entry. * - a descriptor `{ event: , payload: }` — the * form produced by the bridge's own dsh listeners; `payload` is merged * into `properties`. * * @param rawEvent - The raw dsh event (unknown shape). * @returns A normalized CanonicalEvent. */ normalize(rawEvent: unknown): CanonicalEvent; /** * Emit a canonical event to all matching subscribers. * * Dispatches to both general-purpose handlers and type-specific handlers. * All handlers are invoked and awaited; if any handler rejects, the error * is captured and re-thrown after all handlers have settled. * * @param event - The canonical event to dispatch. */ emit(event: CanonicalEvent): Promise; /** * Unsubscribe every dsh event listener registered on the cordis ctx. * Idempotent — safe to call multiple times. */ dispose(): void; /** * Subscribe the dsh session/tools service events and forward normalized * events into the handler fan-out. */ private wire; /** * Subscribe a single dsh event, building a canonical event from the raw * listener args and dispatching it (fire-and-forget; failures are logged). */ private register; } //# sourceMappingURL=event-bridge.d.ts.map