/**
 * Scriptable async iterator over a fixed event array. Honours `close()` by
 * short-circuiting iteration on the next pull.
 */
class MockAgentQuery {
    events;
    record;
    accountInfoValue;
    supportedModelsValue;
    closed = false;
    constructor(events, record, accountInfoValue, supportedModelsValue) {
        this.events = events;
        this.record = record;
        this.accountInfoValue = accountInfoValue;
        this.supportedModelsValue = supportedModelsValue;
    }
    async *[Symbol.asyncIterator]() {
        for (const event of this.events) {
            if (this.closed)
                return;
            this.record.events.push(event);
            yield event;
        }
    }
    async accountInfo() {
        return this.accountInfoValue;
    }
    async supportedModels() {
        return this.supportedModelsValue;
    }
    async close() {
        this.closed = true;
        this.record.closed = true;
    }
}
export class MockAgentProvider {
    kind = "mock";
    /** Records of every `query()` call made; tests can inspect these. */
    queryRecords = [];
    /** Every spec passed to `buildToolServer`; tests can inspect these. */
    toolSpecs = [];
    defaultEvents;
    scripts;
    scriptIndex = 0;
    accountInfoValue;
    supportedModelsValue;
    constructor(options = {}) {
        this.defaultEvents = options.events ?? [];
        this.scripts = options.eventScripts ?? [];
        this.accountInfoValue = options.accountInfo ?? null;
        this.supportedModelsValue = options.supportedModels ?? [];
    }
    query(req) {
        const events = this.scriptIndex < this.scripts.length ? this.scripts[this.scriptIndex++] : this.defaultEvents;
        const record = { request: req, events: [], closed: false };
        this.queryRecords.push(record);
        return new MockAgentQuery(events, record, this.accountInfoValue, this.supportedModelsValue);
    }
    buildToolServer(spec) {
        this.toolSpecs.push(spec);
        return { mock: true, spec };
    }
}
