UNPKG

@mastra/core

Version:

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

35 lines (33 loc) 1.22 kB
import { setCurrentSpanResolver, setExecuteWithContext, setExecuteWithContextSync } from './chunk-MJEXAXIO.js'; import { AsyncLocalStorage } from 'async_hooks'; var spanContextStorage = new AsyncLocalStorage(); function getCurrentSpan() { return spanContextStorage.getStore(); } var initialized = false; function initContextStorage() { if (initialized) return; initialized = true; setCurrentSpanResolver(getCurrentSpan); setExecuteWithContext(executeWithContext); setExecuteWithContextSync(executeWithContextSync); } async function executeWithContext(params) { const { span, fn } = params; const wrappedFn = span ? () => spanContextStorage.run(span, fn) : fn; if (span?.executeInContext) { return span.executeInContext(wrappedFn); } return wrappedFn(); } function executeWithContextSync(params) { const { span, fn } = params; const wrappedFn = span ? () => spanContextStorage.run(span, fn) : fn; if (span?.executeInContextSync) { return span.executeInContextSync(wrappedFn); } return wrappedFn(); } export { executeWithContext, executeWithContextSync, getCurrentSpan, initContextStorage }; //# sourceMappingURL=chunk-7F7LYRRK.js.map //# sourceMappingURL=chunk-7F7LYRRK.js.map