@mastra/core
Version:
49 lines (48 loc) • 1.05 kB
JavaScript
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 as t };
//# sourceMappingURL=stream-D9JOykz7.js.map