function listModes(modes) {
    if (modes === undefined) {
        return "unknown";
    }
    return modes.length > 0 ? modes.join(", ") : "(none)";
}
export function resolveAndValidateCreateAgentMode(input) {
    const { requestedMode, targetProvider, parent, availableModes } = input;
    if (requestedMode !== undefined) {
        if (availableModes !== undefined && !availableModes.includes(requestedMode)) {
            throw new Error(`Invalid mode '${requestedMode}' for provider '${targetProvider}'. Available modes: ${listModes(availableModes)}`);
        }
        return requestedMode;
    }
    if (!parent) {
        return undefined;
    }
    if (parent.provider === targetProvider) {
        return parent.modeId ?? undefined;
    }
    if (parent.isUnattended && input.targetUnattendedMode !== undefined) {
        return input.targetUnattendedMode;
    }
    throw new Error(`cannot inherit mode '${parent.modeId ?? "<none>"}' from caller (provider '${parent.provider}') for new agent (provider '${targetProvider}'). Pass an explicit mode. Available modes for '${targetProvider}': ${listModes(availableModes)}`);
}
//# sourceMappingURL=create-agent-mode.js.map