@langchain/core
Version:
Core LangChain.js abstractions and schemas
1 lines • 3.29 kB
Source Map (JSON)
{"version":3,"file":"env.cjs","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["// Inlined from https://github.com/flexdinesh/browser-or-node\ndeclare global {\n const Deno:\n | {\n version: {\n deno: string;\n };\n env: {\n get: (name: string) => string | undefined;\n };\n }\n | undefined;\n}\n\nexport const isBrowser = () =>\n typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\nexport const isWebWorker = () =>\n typeof globalThis === \"object\" &&\n globalThis.constructor &&\n globalThis.constructor.name === \"DedicatedWorkerGlobalScope\";\n\nexport const isJsDom = () =>\n (typeof window !== \"undefined\" && window.name === \"nodejs\") ||\n (typeof navigator !== \"undefined\" && navigator.userAgent.includes(\"jsdom\"));\n\n// Supabase Edge Function provides a `Deno` global object\n// without `version` property\nexport const isDeno = () => typeof Deno !== \"undefined\";\n\n// Mark not-as-node if in Supabase Edge Function\nexport const isNode = () =>\n typeof process !== \"undefined\" &&\n typeof process.versions !== \"undefined\" &&\n typeof process.versions.node !== \"undefined\" &&\n !isDeno();\n\nexport const getEnv = () => {\n let env: string;\n if (isBrowser()) {\n env = \"browser\";\n } else if (isNode()) {\n env = \"node\";\n } else if (isWebWorker()) {\n env = \"webworker\";\n } else if (isJsDom()) {\n env = \"jsdom\";\n } else if (isDeno()) {\n env = \"deno\";\n } else {\n env = \"other\";\n }\n\n return env;\n};\n\nexport type RuntimeEnvironment = {\n library: string;\n libraryVersion?: string;\n runtime: string;\n runtimeVersion?: string;\n};\n\nlet runtimeEnvironment: RuntimeEnvironment | undefined;\n\nexport function getRuntimeEnvironment(): RuntimeEnvironment {\n if (runtimeEnvironment === undefined) {\n const env = getEnv();\n\n runtimeEnvironment = {\n library: \"langchain-js\",\n runtime: env,\n };\n }\n return runtimeEnvironment;\n}\n\nexport function getEnvironmentVariable(name: string): string | undefined {\n // Certain Deno setups will throw an error if you try to access environment variables\n // https://github.com/langchain-ai/langchainjs/issues/1412\n try {\n if (typeof process !== \"undefined\") {\n // eslint-disable-next-line no-process-env\n return process.env?.[name];\n } else if (isDeno()) {\n return Deno?.env.get(name);\n } else {\n return undefined;\n }\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,kBACX,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AAE9D,MAAa,oBACX,OAAO,eAAe,YACtB,WAAW,eACX,WAAW,YAAY,SAAS;AAElC,MAAa,gBACV,OAAO,WAAW,eAAe,OAAO,SAAS,YACjD,OAAO,cAAc,eAAe,UAAU,UAAU,SAAS,QAAQ;AAI5E,MAAa,eAAe,OAAO,SAAS;AAG5C,MAAa,eACX,OAAO,YAAY,eACnB,OAAO,QAAQ,aAAa,eAC5B,OAAO,QAAQ,SAAS,SAAS,eACjC,CAAC,QAAQ;AAEX,MAAa,eAAe;CAC1B,IAAI;AACJ,KAAI,WAAW,CACb,OAAM;UACG,QAAQ,CACjB,OAAM;UACG,aAAa,CACtB,OAAM;UACG,SAAS,CAClB,OAAM;UACG,QAAQ,CACjB,OAAM;KAEN,OAAM;AAGR,QAAO;;AAUT,IAAI;AAEJ,SAAgB,wBAA4C;AAC1D,KAAI,uBAAuB,OAGzB,sBAAqB;EACnB,SAAS;EACT,SAJU,QAAQ;EAKnB;AAEH,QAAO;;AAGT,SAAgB,uBAAuB,MAAkC;AAGvE,KAAI;AACF,MAAI,OAAO,YAAY,YAErB,QAAO,QAAQ,MAAM;WACZ,QAAQ,CACjB,QAAO,MAAM,IAAI,IAAI,KAAK;MAE1B;SAEI;AACN"}