UNPKG

@mastra/core

Version:
75 lines (74 loc) 1.62 kB
let stream_web = require("stream/web"); //#region 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); } }; //#endregion //#region src/tools/types.ts /** * A no-op ToolObserve implementation. `span` runs the function * directly; `log` does nothing. Used as the default when no * collector/tracing context is active, so user code never needs to * null-check `observe`. */ const noopObserve = { async span(_name, fn) { return fn(); }, log() {} }; //#endregion Object.defineProperty(exports, "ToolStream", { enumerable: true, get: function() { return ToolStream; } }); Object.defineProperty(exports, "noopObserve", { enumerable: true, get: function() { return noopObserve; } }); //# sourceMappingURL=types-CepZ83u8.cjs.map