"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.driveDialogStream = driveDialogStream;
exports.emitSayingEventsBridge = emitSayingEventsBridge;
exports.supplyResponseToAskerDialog = supplyResponseToAskerDialog;
exports.driveDialogStreamCore = driveDialogStreamCore;
exports.supplyResponseToSideDialogBridge = supplyResponseToSideDialogBridge;
const drive_1 = require("./drive");
const events_1 = require("./events");
const flow_1 = require("./flow");
const sideDialog_1 = require("./sideDialog");
const types_1 = require("./types");
function dispatchDrive(dialog, options) {
    if (options.humanPrompt) {
        return driveDialogStream(dialog, options.humanPrompt, options.waitInQue, options.driveOptions);
    }
    return driveDialogStream(dialog, undefined, options.waitInQue, options.driveOptions);
}
async function driveDialogStream(...driveArgs) {
    const runtime = (0, types_1.createKernelDriverRuntimeState)();
    return await (0, flow_1.executeDriveRound)({
        runtime,
        driveArgs,
        scheduleDrive: (dialog, options) => {
            void dispatchDrive(dialog, options);
        },
        driveDialog: async (dialog, options) => {
            return await dispatchDrive(dialog, options);
        },
    });
}
async function emitSayingEventsBridge(...args) {
    const [dlg, content] = args;
    return await (0, events_1.emitSayingEvents)(dlg, content);
}
async function supplyResponseToAskerDialog(...args) {
    const [callerDialog, sideDialogId, responseText, callType, callId, status, calleeResponseRef, directFallbackSource,] = args;
    return await (0, sideDialog_1.supplyResponseToAskerDialog)({
        callerDialog,
        sideDialogId,
        responseText,
        callType,
        callId,
        status,
        calleeResponseRef,
        directFallbackSource,
        scheduleDrive: (dialog, options) => {
            void dispatchDrive(dialog, options);
        },
    });
}
async function driveDialogStreamCore(dlg, callbacks, humanPrompt, driveOptions) {
    return await (0, drive_1.driveDialogStreamCore)(dlg, callbacks, humanPrompt, driveOptions);
}
async function supplyResponseToSideDialogBridge(callerDialog, sideDialogId, responseText, callType, callId, status, calleeResponseRef, directFallbackSource) {
    await (0, sideDialog_1.supplyResponseToAskerDialog)({
        callerDialog,
        sideDialogId,
        responseText,
        callType,
        callId,
        status,
        calleeResponseRef,
        directFallbackSource,
        scheduleDrive: (dialog, options) => {
            void dispatchDrive(dialog, options);
        },
    });
}
