"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTextDeltaFromStreamEvent = getTextDeltaFromStreamEvent;
const eventTypeUtils_1 = require("./eventTypeUtils.js");
const isOutputTextOrContentPartDone_1 = require("./isOutputTextOrContentPartDone.js");
/** Text delta from event; *.done ignored to avoid duplicate accumulation. */
function getTextDeltaFromStreamEvent(event) {
    var _a;
    if (!event) {
        return null;
    }
    const e = event;
    const data = e.data;
    if ((0, isOutputTextOrContentPartDone_1.isOutputTextOrContentPartDone)(e, data)) {
        return null;
    }
    const outputTextDelta = (0, eventTypeUtils_1.getDeltaForEventTypes)(e, data, ['response.output_text.delta']);
    if (outputTextDelta !== null)
        return outputTextDelta;
    const contentPartDelta = (0, eventTypeUtils_1.getDeltaForEventTypes)(e, data, ['response.content_part.delta']);
    if (contentPartDelta !== null)
        return contentPartDelta;
    const refusalDelta = (0, eventTypeUtils_1.getDeltaForEventTypes)(e, data, ['response.refusal.delta']);
    if (refusalDelta !== null)
        return refusalDelta;
    if (typeof (data === null || data === void 0 ? void 0 : data.text) === 'string') {
        return data.text;
    }
    if (typeof e.text === 'string') {
        return e.text;
    }
    // Legacy: event.event === 'content' && event.data.content
    if (e.event === 'content' && ((_a = e.data) === null || _a === void 0 ? void 0 : _a.content)) {
        return e.data.content;
    }
    return null;
}
//# sourceMappingURL=getTextDeltaFromStreamEvent.js.map
