UNPKG

@datastax/langflow-client

Version:
49 lines 1.59 kB
import { Log } from "./log.js"; export class Logs { client; constructor(client) { this.client = client; } async fetch(options) { const query = {}; let signal; if (options) { Object.entries(options).forEach(([key, value]) => { query[key] = value.toString(); }); signal = options.signal; } const headers = new Headers(); headers.set("Accept", "application/json"); const response = (await this.client.request({ path: "/logs", method: "GET", headers, query, signal, })); return Object.entries(response) .map(([timestamp, message]) => new Log(timestamp, message)) .sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()); } async stream(options) { const signal = options?.signal; const headers = new Headers(); headers.set("Accept", "text/event-stream"); const streamingResponse = await this.client.stream({ path: "/logs-stream", headers, method: "GET", signal, }); const streamToLog = new TransformStream({ transform(chunk, controller) { Object.entries(chunk).forEach(([timestamp, message]) => { controller.enqueue(new Log(timestamp, message)); }); }, }); return streamingResponse.pipeThrough(streamToLog, { signal }); } } //# sourceMappingURL=logs.js.map