d22a5ef5a8e410bcb3d4ec2a55b07dbdaa7c129fbc3fd2a42313b06287f0dfe8.json 6.3 KB

1
  1. {"ast":null,"code":"import { isRunTree } from \"../run_trees.js\";\nclass MockAsyncLocalStorage {\n getStore() {\n return undefined;\n }\n run(_, callback) {\n return callback();\n }\n}\nconst TRACING_ALS_KEY = Symbol.for(\"ls:tracing_async_local_storage\");\nconst mockAsyncLocalStorage = new MockAsyncLocalStorage();\nclass AsyncLocalStorageProvider {\n getInstance() {\n var _globalThis$TRACING_A;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (_globalThis$TRACING_A = globalThis[TRACING_ALS_KEY]) !== null && _globalThis$TRACING_A !== void 0 ? _globalThis$TRACING_A : mockAsyncLocalStorage;\n }\n initializeGlobalInstance(instance) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if (globalThis[TRACING_ALS_KEY] === undefined) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n globalThis[TRACING_ALS_KEY] = instance;\n }\n }\n}\nexport const AsyncLocalStorageProviderSingleton = new AsyncLocalStorageProvider();\n/**\n * Return the current run tree from within a traceable-wrapped function.\n * Will throw an error if called outside of a traceable function.\n *\n * @returns The run tree for the given context.\n */\nexport const getCurrentRunTree = () => {\n const runTree = AsyncLocalStorageProviderSingleton.getInstance().getStore();\n if (!isRunTree(runTree)) {\n throw new Error([\"Could not get the current run tree.\", \"\", \"Please make sure you are calling this method within a traceable function or the tracing is enabled.\"].join(\"\\n\"));\n }\n return runTree;\n};\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withRunTree(runTree, fn) {\n const storage = AsyncLocalStorageProviderSingleton.getInstance();\n return new Promise((resolve, reject) => {\n storage.run(runTree, () => void Promise.resolve(fn()).then(resolve).catch(reject));\n });\n}\nexport const ROOT = Symbol.for(\"langsmith:traceable:root\");\nexport function isTraceableFunction(x\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\n) {\n return typeof x === \"function\" && \"langsmith:traceable\" in x;\n}","map":{"version":3,"names":["isRunTree","MockAsyncLocalStorage","getStore","undefined","run","_","callback","TRACING_ALS_KEY","Symbol","for","mockAsyncLocalStorage","AsyncLocalStorageProvider","getInstance","_globalThis$TRACING_A","globalThis","initializeGlobalInstance","instance","AsyncLocalStorageProviderSingleton","getCurrentRunTree","runTree","Error","join","withRunTree","fn","storage","Promise","resolve","reject","then","catch","ROOT","isTraceableFunction","x"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/langsmith/dist/singletons/traceable.js"],"sourcesContent":["import { isRunTree } from \"../run_trees.js\";\nclass MockAsyncLocalStorage {\n getStore() {\n return undefined;\n }\n run(_, callback) {\n return callback();\n }\n}\nconst TRACING_ALS_KEY = Symbol.for(\"ls:tracing_async_local_storage\");\nconst mockAsyncLocalStorage = new MockAsyncLocalStorage();\nclass AsyncLocalStorageProvider {\n getInstance() {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return globalThis[TRACING_ALS_KEY] ?? mockAsyncLocalStorage;\n }\n initializeGlobalInstance(instance) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if (globalThis[TRACING_ALS_KEY] === undefined) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n globalThis[TRACING_ALS_KEY] = instance;\n }\n }\n}\nexport const AsyncLocalStorageProviderSingleton = new AsyncLocalStorageProvider();\n/**\n * Return the current run tree from within a traceable-wrapped function.\n * Will throw an error if called outside of a traceable function.\n *\n * @returns The run tree for the given context.\n */\nexport const getCurrentRunTree = () => {\n const runTree = AsyncLocalStorageProviderSingleton.getInstance().getStore();\n if (!isRunTree(runTree)) {\n throw new Error([\n \"Could not get the current run tree.\",\n \"\",\n \"Please make sure you are calling this method within a traceable function or the tracing is enabled.\",\n ].join(\"\\n\"));\n }\n return runTree;\n};\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withRunTree(runTree, fn) {\n const storage = AsyncLocalStorageProviderSingleton.getInstance();\n return new Promise((resolve, reject) => {\n storage.run(runTree, () => void Promise.resolve(fn()).then(resolve).catch(reject));\n });\n}\nexport const ROOT = Symbol.for(\"langsmith:traceable:root\");\nexport function isTraceableFunction(x\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\n) {\n return typeof x === \"function\" && \"langsmith:traceable\" in x;\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,iBAAiB;AAC3C,MAAMC,qBAAqB,CAAC;EACxBC,QAAQA,CAAA,EAAG;IACP,OAAOC,SAAS;EACpB;EACAC,GAAGA,CAACC,CAAC,EAAEC,QAAQ,EAAE;IACb,OAAOA,QAAQ,CAAC,CAAC;EACrB;AACJ;AACA,MAAMC,eAAe,GAAGC,MAAM,CAACC,GAAG,CAAC,gCAAgC,CAAC;AACpE,MAAMC,qBAAqB,GAAG,IAAIT,qBAAqB,CAAC,CAAC;AACzD,MAAMU,yBAAyB,CAAC;EAC5BC,WAAWA,CAAA,EAAG;IAAA,IAAAC,qBAAA;IACV;IACA,QAAAA,qBAAA,GAAOC,UAAU,CAACP,eAAe,CAAC,cAAAM,qBAAA,cAAAA,qBAAA,GAAIH,qBAAqB;EAC/D;EACAK,wBAAwBA,CAACC,QAAQ,EAAE;IAC/B;IACA,IAAIF,UAAU,CAACP,eAAe,CAAC,KAAKJ,SAAS,EAAE;MAC3C;MACAW,UAAU,CAACP,eAAe,CAAC,GAAGS,QAAQ;IAC1C;EACJ;AACJ;AACA,OAAO,MAAMC,kCAAkC,GAAG,IAAIN,yBAAyB,CAAC,CAAC;AACjF;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMO,iBAAiB,GAAGA,CAAA,KAAM;EACnC,MAAMC,OAAO,GAAGF,kCAAkC,CAACL,WAAW,CAAC,CAAC,CAACV,QAAQ,CAAC,CAAC;EAC3E,IAAI,CAACF,SAAS,CAACmB,OAAO,CAAC,EAAE;IACrB,MAAM,IAAIC,KAAK,CAAC,CACZ,qCAAqC,EACrC,EAAE,EACF,qGAAqG,CACxG,CAACC,IAAI,CAAC,IAAI,CAA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