@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
40 lines (37 loc) • 1.34 kB
JavaScript
;
var chunkD3BJ5NBH_cjs = require('./chunk-D3BJ5NBH.cjs');
var async_hooks = require('async_hooks');
var spanContextStorage = new async_hooks.AsyncLocalStorage();
function getCurrentSpan() {
return spanContextStorage.getStore();
}
var initialized = false;
function initContextStorage() {
if (initialized) return;
initialized = true;
chunkD3BJ5NBH_cjs.setCurrentSpanResolver(getCurrentSpan);
chunkD3BJ5NBH_cjs.setExecuteWithContext(executeWithContext);
chunkD3BJ5NBH_cjs.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();
}
exports.executeWithContext = executeWithContext;
exports.executeWithContextSync = executeWithContextSync;
exports.getCurrentSpan = getCurrentSpan;
exports.initContextStorage = initContextStorage;
//# sourceMappingURL=chunk-OEHE67DI.cjs.map
//# sourceMappingURL=chunk-OEHE67DI.cjs.map