import { getDeltaForEventTypes } from "./eventTypeUtils.js";
import { isOutputTextOrContentPartDone } from "./isOutputTextOrContentPartDone.js";
/** Text delta from event; *.done ignored to avoid duplicate accumulation. */
export function getTextDeltaFromStreamEvent(event) {
    var _a;
    if (!event) {
        return null;
    }
    const e = event;
    const data = e.data;
    if (isOutputTextOrContentPartDone(e, data)) {
        return null;
    }
    const outputTextDelta = getDeltaForEventTypes(e, data, ['response.output_text.delta']);
    if (outputTextDelta !== null)
        return outputTextDelta;
    const contentPartDelta = getDeltaForEventTypes(e, data, ['response.content_part.delta']);
    if (contentPartDelta !== null)
        return contentPartDelta;
    const refusalDelta = 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
