UNPKG

parea-ai

Version:

Client SDK library to connect to Parea AI.

98 lines (97 loc) 3.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pareaLogger = exports.PareaLogger = void 0; const helpers_1 = require("./helpers"); const project_1 = require("./project"); const LOG_ENDPOINT = '/trace_log'; const VENDOR_LOG_ENDPOINT = '/trace_log/{vendor}'; /** * PareaLogger class for handling logging operations. */ class PareaLogger { constructor() { this.client = null; this.project_uuid = null; } /** * Sets the HTTP client for the logger. * @param client - The HTTP client to be used for requests. */ setClient(client) { this.client = client; } /** * Sets the project UUID for the logger. * @param project_uuid - The project UUID to be set. */ setProjectUUID(project_uuid) { this.project_uuid = project_uuid; } /** * Retrieves the project UUID. * @returns A promise that resolves to the project UUID. */ async getProjectUUID() { const project_uuid = await project_1.pareaProject.getProjectUUID(); this.project_uuid = project_uuid; return project_uuid; } /** * Records a log entry. * @param data - The trace log data to be recorded. * @throws Will throw an error if the Parea Client is not instantiated. */ async recordLog(data) { if (!this.client) { console.error('Parea Client not instantiated'); return; } const log = { ...data, project_uuid: this.project_uuid || (await this.getProjectUUID()) }; await this.client.request({ method: 'POST', endpoint: LOG_ENDPOINT, data: (0, helpers_1.serializeMetadataValues)(log), }); return; } /** * Records a vendor-specific log entry. * @param data - The Langchain run data to be recorded. * @param vendor - The trace integration vendor. * @throws Will throw an error if the Parea Client is not instantiated. */ async recordVendorLog(data, vendor) { if (!this.client) { console.error('Parea Client not instantiated'); return; } await this.client.request({ method: 'POST', endpoint: VENDOR_LOG_ENDPOINT.replace('{vendor}', vendor), data: { ...data, project_uuid: this.project_uuid || (await this.getProjectUUID()) }, }); return; } /** * Updates an existing log entry. * @param data - The update log data. * @throws Will throw an error if the Parea Client is not instantiated. */ async updateLog(data) { if (!this.client) { console.error('Parea Client not instantiated'); return; } await this.client.request({ method: 'PUT', endpoint: LOG_ENDPOINT, data: (0, helpers_1.serializeMetadataValuesUpdate)(data), }); return; } } exports.PareaLogger = PareaLogger; /** * Singleton instance of PareaLogger. */ exports.pareaLogger = new PareaLogger();