typings/lib2/llmtransformation/llmTransformationContext.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LlmTransformationContext = void 0;
const provider_1 = require("../../common/provider");
/**
 * The Bots LlmTransformationContext is a class with convenience methods for transforming the request and response of LLM REST services
 * </p>
 * A LlmTransformationContext class instance is passed as an argument to every rest service event handler function.
 * @memberof module:Lib
 * @alias LlmTransformationContext
 */
class LlmTransformationContext {
    /**
     * Constructor of rest service context.
     * DO NOT USE - INSTANCE IS ALREADY PASSED TO EVENT HANDLERS
     * @param {object} request
     */
    constructor(request) {
        // Initilize the response
        const response = Object.assign({}, {
            requestPayload: request.requestPayload,
            responsePayload: request.responsePayload,
        });
        this._request = request;
        this._response = response;
        this._logger = provider_1.CommonProvider.getLogger();
        this._llmTransformationContext = request.llmTransformationContext;
    }
    /**
     * Retrieves the request object.
     * @return {object} The request object.
     */
    getRequest() {
        return this._request;
    }
    /**
     * Retrieves the response object.
     * @return {object} The response object.
     */
    getResponse() {
        return this._response;
    }
    /**
     * Retrieves the logger object.
     * @return {object} The logger object.
     */
    logger() {
        // this function is replaced with mixin logger when deployed to embedded functions to enable viewing logs in bots UI
        return this._logger;
    }
    /**
     * Returns the name of the REST service method
     * @return {string} method name
     */
    getMethod() {
        return this._llmTransformationContext.method;
    }
    /**
     * Returns REST service URL
     * @return the URL
     */
    getEndPoint() {
        return this._llmTransformationContext.endpoint;
    }
    /**
     * Returns the request  payload
     * @return the payload
     */
    getRequestPayload() {
        return this.getResponse().requestPayload;
    }
    /**
     * Set the request payload
     */
    setRequestPayload(payload) {
        this.getResponse().requestPayload = payload;
    }
    /**
     * Returns the response payload
     * @return the payload
     */
    getResponsePayload() {
        return this.getResponse().responsePayload;
    }
    /**
     * Set the response payload
     */
    setResponsePayload(payload) {
        this.getResponse().responsePayload = payload;
    }
}
exports.LlmTransformationContext = LlmTransformationContext;