UNPKG

@mastra/core

Version:

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

64 lines (61 loc) 1.29 kB
'use strict'; var web = require('stream/web'); // src/tools/stream.ts var ToolStream = class extends 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); } } }; exports.ToolStream = ToolStream; //# sourceMappingURL=chunk-KJBMTK5B.cjs.map //# sourceMappingURL=chunk-KJBMTK5B.cjs.map