UNPKG

@mastra/core

Version:

Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.

62 lines (60 loc) 1.27 kB
import { WritableStream } from 'stream/web'; // src/tools/stream.ts var ToolStream = class extends 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); } } }; export { ToolStream }; //# sourceMappingURL=chunk-DD2VNRQM.js.map //# sourceMappingURL=chunk-DD2VNRQM.js.map