"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "GeminiVertexSession", {
    enumerable: true,
    get: function() {
        return GeminiVertexSession;
    }
});
const _vertexai = require("@google-cloud/vertexai");
const _env = require("@llamaindex/env");
const _utils = require("../utils.js");
const _utils1 = require("./utils.js");
class GeminiVertexSession {
    vertex;
    preview = false;
    constructor(options){
        const project = options?.project ?? (0, _env.getEnv)("GOOGLE_VERTEX_PROJECT");
        const location = options?.location ?? (0, _env.getEnv)("GOOGLE_VERTEX_LOCATION");
        if (!project || !location) {
            throw new Error("Set Google Vertex project and location in GOOGLE_VERTEX_PROJECT and GOOGLE_VERTEX_LOCATION env variables");
        }
        this.vertex = new _vertexai.VertexAI({
            ...options,
            project,
            location
        });
        this.preview = options?.preview ?? false;
    }
    getGenerativeModel(metadata) {
        if (this.preview) return this.vertex.preview.getGenerativeModel(metadata);
        return this.vertex.getGenerativeModel(metadata);
    }
    getResponseText(response) {
        return (0, _utils1.getText)(response);
    }
    async *getChatStream(result) {
        yield* (0, _utils.streamConverter)(result.stream, (response)=>({
                delta: this.getResponseText(response),
                raw: response
            }));
    }
    getCompletionStream(result) {
        return (0, _utils.streamConverter)(result.stream, (response)=>({
                text: this.getResponseText(response),
                raw: response
            }));
    }
}
