UNPKG

@mastra/core

Version:
54 lines (53 loc) • 1.14 kB
let stream_web = require("stream/web"); // src/tools/stream.ts var ToolStream = class extends stream_web.WritableStream { prefix; callId; name; runId; writeFn; constructor({ prefix, callId, name, runId }, writeFn) { super({ async write(chunk) { await getInstance()._write(chunk); } }); const self = this; function getInstance() { return self; } this.prefix = prefix; this.callId = callId; this.name = name; this.runId = runId; this.writeFn = writeFn; } async _write(data) { if (this.writeFn) await this.writeFn({ type: `${this.prefix}-output`, runId: this.runId, from: "USER", payload: { output: data, ...this.prefix === "workflow-step" ? { runId: this.runId, stepName: this.name } : { [`${this.prefix}CallId`]: this.callId, [`${this.prefix}Name`]: this.name } } }); } async write(data) { await this._write(data); } async custom(data) { if (this.writeFn) await this.writeFn(data); } }; Object.defineProperty(exports, "ToolStream", { enumerable: true, get: function() { return ToolStream; } }); //# sourceMappingURL=stream-BGbj9jAU.cjs.map