// Production-side port adapters. GatewayModelPort wraps the ADR-0003 Gateway and
// propagates the run's AbortSignal as GatewayRequest.cancellationSignal. DryRunToolPort
// records tool calls without executing them — the Wave-1 no-op executor that keeps the
// CLI dry-run path free of any side effect (real executors land in issue #6).
import { CancelledError, } from "@oscharko-dev/keiko-model-gateway";
export class GatewayModelPort {
    gateway;
    constructor(gateway) {
        this.gateway = gateway;
    }
    async call(request, signal) {
        return this.gateway.chat({ ...request, cancellationSignal: signal });
    }
    // #152 — propagate the run's AbortSignal as GatewayRequest.cancellationSignal, mirroring `call`.
    // The concrete Gateway always exposes chatStream; defaultModelPortFactory only ever constructs
    // this port with a real Gateway, so the non-null assertion is sound at the production call site.
    callStream(request, signal) {
        const stream = this.gateway.chatStream;
        if (stream === undefined) {
            throw new Error("gateway does not support streaming");
        }
        return stream.call(this.gateway, { ...request, cancellationSignal: signal });
    }
}
export class DryRunToolPort {
    tools;
    recorded = [];
    constructor(tools = []) {
        this.tools = tools;
    }
    execute(request) {
        if (request.signal.aborted) {
            return Promise.reject(new CancelledError("tool execution aborted before start"));
        }
        this.recorded.push({
            toolCallId: request.toolCallId,
            toolName: request.toolName,
            arguments: request.arguments,
        });
        return Promise.resolve({ toolCallId: request.toolCallId, output: "", durationMs: 0 });
    }
    listTools() {
        return this.tools;
    }
    calls() {
        return this.recorded;
    }
}
