From 5116ad8d088d0956ab2f1a7be0c97179d197f4ad Mon Sep 17 00:00:00 2001
From: Alex Yang <himself65@outlook.com>
Date: Sat, 2 Mar 2024 18:40:01 -0600
Subject: [PATCH] fix: compatibility issue with Deno (#598)

---
 .changeset/lucky-sheep-taste.md               |  6 ++++
 .gitignore                                    |  1 +
 packages/core/jsr.json                        |  8 +++++
 packages/core/src/cloud/utils.ts              |  5 ++--
 packages/core/src/embeddings/fireworks.ts     |  3 +-
 packages/core/src/embeddings/together.ts      |  3 +-
 packages/core/src/llm/anthropic.ts            |  5 ++--
 packages/core/src/llm/azure.ts                | 30 ++++++++++---------
 packages/core/src/llm/fireworks.ts            |  3 +-
 packages/core/src/llm/groq.ts                 |  3 +-
 packages/core/src/llm/mistral.ts              |  5 ++--
 packages/core/src/llm/open_ai.ts              |  5 ++--
 packages/core/src/llm/portkey.ts              | 15 ++--------
 packages/core/src/llm/replicate_ai.ts         |  5 ++--
 packages/core/src/llm/together.ts             |  3 +-
 packages/core/src/readers/AssemblyAIReader.ts |  3 +-
 packages/core/src/readers/LlamaParseReader.ts |  5 ++--
 .../storage/vectorStore/AstraDBVectorStore.ts |  8 ++---
 .../vectorStore/MongoDBAtlasVectorStore.ts    |  3 +-
 .../vectorStore/PineconeVectorStore.ts        |  8 ++---
 packages/core/tests/tsconfig.json             | 10 ++++++-
 packages/core/tsconfig.json                   |  8 ++++-
 packages/env/jsr.json                         |  8 +++++
 packages/env/src/index.polyfill.ts            |  1 +
 packages/env/src/index.ts                     |  3 +-
 packages/env/src/type.ts                      |  3 +-
 packages/env/src/utils.ts                     | 12 ++++++++
 packages/env/tsconfig.json                    |  1 +
 tsconfig.json                                 |  8 ++++-
 29 files changed, 118 insertions(+), 63 deletions(-)
 create mode 100644 .changeset/lucky-sheep-taste.md
 create mode 100644 packages/core/jsr.json
 create mode 100644 packages/env/jsr.json
 create mode 100644 packages/env/src/utils.ts

diff --git a/.changeset/lucky-sheep-taste.md b/.changeset/lucky-sheep-taste.md
new file mode 100644
index 000000000..adef8040e
--- /dev/null
+++ b/.changeset/lucky-sheep-taste.md
@@ -0,0 +1,6 @@
+---
+"llamaindex": patch
+"@llamaindex/env": patch
+---
+
+fix: compatibility issue with Deno
diff --git a/.gitignore b/.gitignore
index 3e17caf04..8f37f7c04 100644
--- a/.gitignore
+++ b/.gitignore
@@ -44,6 +44,7 @@ test-results/
 playwright-report/
 blob-report/
 playwright/.cache/
+.tsbuildinfo
 
 # intellij
 **/.idea
diff --git a/packages/core/jsr.json b/packages/core/jsr.json
new file mode 100644
index 000000000..41e21f3ed
--- /dev/null
+++ b/packages/core/jsr.json
@@ -0,0 +1,8 @@
+{
+  "name": "@llamaindex/core",
+  "version": "0.1.19",
+  "exports": "./src/index.ts",
+  "imports": {
+    "@llamaindex/env": "jsr:@llamaindex/env@0.0.4"
+  }
+}
diff --git a/packages/core/src/cloud/utils.ts b/packages/core/src/cloud/utils.ts
index 69a80861f..323e622fb 100644
--- a/packages/core/src/cloud/utils.ts
+++ b/packages/core/src/cloud/utils.ts
@@ -1,4 +1,5 @@
 import type { PlatformApiClient } from "@llamaindex/cloud";
+import { getEnv } from "@llamaindex/env";
 import type { ClientParams } from "./types.js";
 import { DEFAULT_BASE_URL } from "./types.js";
 
@@ -7,8 +8,8 @@ export async function getClient({
   baseUrl,
 }: ClientParams = {}): Promise<PlatformApiClient> {
   // Get the environment variables or use defaults
-  baseUrl = baseUrl ?? process.env.LLAMA_CLOUD_BASE_URL ?? DEFAULT_BASE_URL;
-  apiKey = apiKey ?? process.env.LLAMA_CLOUD_API_KEY;
+  baseUrl = baseUrl ?? getEnv("LLAMA_CLOUD_BASE_URL") ?? DEFAULT_BASE_URL;
+  apiKey = apiKey ?? getEnv("LLAMA_CLOUD_API_KEY");
 
   const { PlatformApiClient } = await import("@llamaindex/cloud");
 
diff --git a/packages/core/src/embeddings/fireworks.ts b/packages/core/src/embeddings/fireworks.ts
index 651e3919b..a48039e10 100644
--- a/packages/core/src/embeddings/fireworks.ts
+++ b/packages/core/src/embeddings/fireworks.ts
@@ -1,9 +1,10 @@
+import { getEnv } from "@llamaindex/env";
 import { OpenAIEmbedding } from "./OpenAIEmbedding.js";
 
 export class FireworksEmbedding extends OpenAIEmbedding {
   constructor(init?: Partial<OpenAIEmbedding>) {
     const {
-      apiKey = process.env.FIREWORKS_API_KEY,
+      apiKey = getEnv("FIREWORKS_API_KEY"),
       additionalSessionOptions = {},
       model = "nomic-ai/nomic-embed-text-v1.5",
       ...rest
diff --git a/packages/core/src/embeddings/together.ts b/packages/core/src/embeddings/together.ts
index 4c2ca91c6..b284daf6a 100644
--- a/packages/core/src/embeddings/together.ts
+++ b/packages/core/src/embeddings/together.ts
@@ -1,9 +1,10 @@
+import { getEnv } from "@llamaindex/env";
 import { OpenAIEmbedding } from "./OpenAIEmbedding.js";
 
 export class TogetherEmbedding extends OpenAIEmbedding {
   constructor(init?: Partial<OpenAIEmbedding>) {
     const {
-      apiKey = process.env.TOGETHER_API_KEY,
+      apiKey = getEnv("TOGETHER_API_KEY"),
       additionalSessionOptions = {},
       model = "togethercomputer/m2-bert-80M-32k-retrieval",
       ...rest
diff --git a/packages/core/src/llm/anthropic.ts b/packages/core/src/llm/anthropic.ts
index a8dd6c114..629e3335c 100644
--- a/packages/core/src/llm/anthropic.ts
+++ b/packages/core/src/llm/anthropic.ts
@@ -1,5 +1,6 @@
 import type { ClientOptions } from "@anthropic-ai/sdk";
 import Anthropic, { AI_PROMPT, HUMAN_PROMPT } from "@anthropic-ai/sdk";
+import { getEnv } from "@llamaindex/env";
 import _ from "lodash";
 
 export class AnthropicSession {
@@ -7,9 +8,7 @@ export class AnthropicSession {
 
   constructor(options: ClientOptions = {}) {
     if (!options.apiKey) {
-      if (typeof process !== undefined) {
-        options.apiKey = process.env.ANTHROPIC_API_KEY;
-      }
+      options.apiKey = getEnv("ANTHROPIC_API_KEY");
     }
 
     if (!options.apiKey) {
diff --git a/packages/core/src/llm/azure.ts b/packages/core/src/llm/azure.ts
index 2bcd11bcb..36b90e541 100644
--- a/packages/core/src/llm/azure.ts
+++ b/packages/core/src/llm/azure.ts
@@ -1,3 +1,5 @@
+import { getEnv } from "@llamaindex/env";
+
 export interface AzureOpenAIConfig {
   apiKey?: string;
   endpoint?: string;
@@ -67,24 +69,24 @@ export function getAzureConfigFromEnv(
   return {
     apiKey:
       init?.apiKey ??
-      process.env.AZURE_OPENAI_KEY ?? // From Azure docs
-      process.env.OPENAI_API_KEY ?? // Python compatible
-      process.env.AZURE_OPENAI_API_KEY, // LCJS compatible
+      getEnv("AZURE_OPENAI_KEY") ?? // From Azure docs
+      getEnv("OPENAI_API_KEY") ?? // Python compatible
+      getEnv("AZURE_OPENAI_API_KEY"), // LCJS compatible
     endpoint:
       init?.endpoint ??
-      process.env.AZURE_OPENAI_ENDPOINT ?? // From Azure docs
-      process.env.OPENAI_API_BASE ?? // Python compatible
-      process.env.AZURE_OPENAI_API_INSTANCE_NAME, // LCJS compatible
+      getEnv("AZURE_OPENAI_ENDPOINT") ?? // From Azure docs
+      getEnv("OPENAI_API_BASE") ?? // Python compatible
+      getEnv("AZURE_OPENAI_API_INSTANCE_NAME"), // LCJS compatible
     apiVersion:
       init?.apiVersion ??
-      process.env.AZURE_OPENAI_API_VERSION ?? // From Azure docs
-      process.env.OPENAI_API_VERSION ?? // Python compatible
-      process.env.AZURE_OPENAI_API_VERSION ?? // LCJS compatible
+      getEnv("AZURE_OPENAI_API_VERSION") ?? // From Azure docs
+      getEnv("OPENAI_API_VERSION") ?? // Python compatible
+      getEnv("AZURE_OPENAI_API_VERSION") ?? // LCJS compatible
       DEFAULT_API_VERSION,
     deploymentName:
       init?.deploymentName ??
-      process.env.AZURE_OPENAI_DEPLOYMENT ?? // From Azure docs
-      process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME ?? // LCJS compatible
+      getEnv("AZURE_OPENAI_DEPLOYMENT") ?? // From Azure docs
+      getEnv("AZURE_OPENAI_API_DEPLOYMENT_NAME") ?? // LCJS compatible
       init?.model, // Fall back to model name, Python compatible
   };
 }
@@ -113,8 +115,8 @@ export function getAzureModel(openAIModel: string) {
 
 export function shouldUseAzure() {
   return (
-    process.env.AZURE_OPENAI_ENDPOINT ||
-    process.env.AZURE_OPENAI_API_INSTANCE_NAME ||
-    process.env.OPENAI_API_TYPE === "azure"
+    getEnv("AZURE_OPENAI_ENDPOINT") ||
+    getEnv("AZURE_OPENAI_API_INSTANCE_NAME") ||
+    getEnv("OPENAI_API_TYPE") === "azure"
   );
 }
diff --git a/packages/core/src/llm/fireworks.ts b/packages/core/src/llm/fireworks.ts
index f6ad6b713..8621dd01f 100644
--- a/packages/core/src/llm/fireworks.ts
+++ b/packages/core/src/llm/fireworks.ts
@@ -1,9 +1,10 @@
+import { getEnv } from "@llamaindex/env";
 import { OpenAI } from "./LLM.js";
 
 export class FireworksLLM extends OpenAI {
   constructor(init?: Partial<OpenAI>) {
     const {
-      apiKey = process.env.FIREWORKS_API_KEY,
+      apiKey = getEnv("FIREWORKS_API_KEY"),
       additionalSessionOptions = {},
       model = "accounts/fireworks/models/mixtral-8x7b-instruct",
       ...rest
diff --git a/packages/core/src/llm/groq.ts b/packages/core/src/llm/groq.ts
index 0d287f56d..b29431749 100644
--- a/packages/core/src/llm/groq.ts
+++ b/packages/core/src/llm/groq.ts
@@ -1,9 +1,10 @@
+import { getEnv } from "@llamaindex/env";
 import { OpenAI } from "./LLM.js";
 
 export class Groq extends OpenAI {
   constructor(init?: Partial<OpenAI>) {
     const {
-      apiKey = process.env.GROQ_API_KEY,
+      apiKey = getEnv("GROQ_API_KEY"),
       additionalSessionOptions = {},
       model = "mixtral-8x7b-32768",
       ...rest
diff --git a/packages/core/src/llm/mistral.ts b/packages/core/src/llm/mistral.ts
index 47478ca5b..3de5c0898 100644
--- a/packages/core/src/llm/mistral.ts
+++ b/packages/core/src/llm/mistral.ts
@@ -1,3 +1,4 @@
+import { getEnv } from "@llamaindex/env";
 import type {
   CallbackManager,
   Event,
@@ -27,9 +28,7 @@ export class MistralAISession {
     if (init?.apiKey) {
       this.apiKey = init?.apiKey;
     } else {
-      if (typeof process !== undefined) {
-        this.apiKey = process.env.MISTRAL_API_KEY;
-      }
+      this.apiKey = getEnv("MISTRAL_API_KEY");
     }
     if (!this.apiKey) {
       throw new Error("Set Mistral API key in MISTRAL_API_KEY env variable"); // Overriding MistralAI package's error message
diff --git a/packages/core/src/llm/open_ai.ts b/packages/core/src/llm/open_ai.ts
index 9deaffbde..336844aaa 100644
--- a/packages/core/src/llm/open_ai.ts
+++ b/packages/core/src/llm/open_ai.ts
@@ -1,3 +1,4 @@
+import { getEnv } from "@llamaindex/env";
 import _ from "lodash";
 import type { ClientOptions } from "openai";
 import OpenAI from "openai";
@@ -13,9 +14,7 @@ export class OpenAISession {
 
   constructor(options: ClientOptions & { azure?: boolean } = {}) {
     if (!options.apiKey) {
-      if (typeof process !== undefined) {
-        options.apiKey = process.env.OPENAI_API_KEY;
-      }
+      options.apiKey = getEnv("OPENAI_API_KEY");
     }
 
     if (!options.apiKey) {
diff --git a/packages/core/src/llm/portkey.ts b/packages/core/src/llm/portkey.ts
index 9d47e979e..d0d90253e 100644
--- a/packages/core/src/llm/portkey.ts
+++ b/packages/core/src/llm/portkey.ts
@@ -1,17 +1,8 @@
+import { getEnv } from "@llamaindex/env";
 import _ from "lodash";
 import type { LLMOptions } from "portkey-ai";
 import { Portkey } from "portkey-ai";
 
-export const readEnv = (
-  env: string,
-  default_val?: string,
-): string | undefined => {
-  if (typeof process !== "undefined") {
-    return process.env?.[env] ?? default_val;
-  }
-  return default_val;
-};
-
 interface PortkeyOptions {
   apiKey?: string;
   baseURL?: string;
@@ -24,11 +15,11 @@ export class PortkeySession {
 
   constructor(options: PortkeyOptions = {}) {
     if (!options.apiKey) {
-      options.apiKey = readEnv("PORTKEY_API_KEY");
+      options.apiKey = getEnv("PORTKEY_API_KEY");
     }
 
     if (!options.baseURL) {
-      options.baseURL = readEnv("PORTKEY_BASE_URL", "https://api.portkey.ai");
+      options.baseURL = getEnv("PORTKEY_BASE_URL") ?? "https://api.portkey.ai";
     }
 
     this.portkey = new Portkey({});
diff --git a/packages/core/src/llm/replicate_ai.ts b/packages/core/src/llm/replicate_ai.ts
index d452df38e..5c3d51f56 100644
--- a/packages/core/src/llm/replicate_ai.ts
+++ b/packages/core/src/llm/replicate_ai.ts
@@ -1,3 +1,4 @@
+import { getEnv } from "@llamaindex/env";
 import Replicate from "replicate";
 
 export class ReplicateSession {
@@ -7,8 +8,8 @@ export class ReplicateSession {
   constructor(replicateKey: string | null = null) {
     if (replicateKey) {
       this.replicateKey = replicateKey;
-    } else if (process.env.REPLICATE_API_TOKEN) {
-      this.replicateKey = process.env.REPLICATE_API_TOKEN;
+    } else if (getEnv("REPLICATE_API_TOKEN")) {
+      this.replicateKey = getEnv("REPLICATE_API_TOKEN") as string;
     } else {
       throw new Error(
         "Set Replicate token in REPLICATE_API_TOKEN env variable",
diff --git a/packages/core/src/llm/together.ts b/packages/core/src/llm/together.ts
index 96df3cef8..65651cdf7 100644
--- a/packages/core/src/llm/together.ts
+++ b/packages/core/src/llm/together.ts
@@ -1,9 +1,10 @@
+import { getEnv } from "@llamaindex/env";
 import { OpenAI } from "./LLM.js";
 
 export class TogetherLLM extends OpenAI {
   constructor(init?: Partial<OpenAI>) {
     const {
-      apiKey = process.env.TOGETHER_API_KEY,
+      apiKey = getEnv("TOGETHER_API_KEY"),
       additionalSessionOptions = {},
       model = "togethercomputer/llama-2-7b-chat",
       ...rest
diff --git a/packages/core/src/readers/AssemblyAIReader.ts b/packages/core/src/readers/AssemblyAIReader.ts
index b038ce220..4a128b5c8 100644
--- a/packages/core/src/readers/AssemblyAIReader.ts
+++ b/packages/core/src/readers/AssemblyAIReader.ts
@@ -1,3 +1,4 @@
+import { getEnv } from "@llamaindex/env";
 import type {
   BaseServiceParams,
   SubtitleFormat,
@@ -28,7 +29,7 @@ abstract class AssemblyAIReader implements BaseReader {
       options = {};
     }
     if (!options.apiKey) {
-      options.apiKey = process.env.ASSEMBLYAI_API_KEY;
+      options.apiKey = getEnv("ASSEMBLYAI_API_KEY");
     }
     if (!options.apiKey) {
       throw new Error(
diff --git a/packages/core/src/readers/LlamaParseReader.ts b/packages/core/src/readers/LlamaParseReader.ts
index 70deec769..066f88bee 100644
--- a/packages/core/src/readers/LlamaParseReader.ts
+++ b/packages/core/src/readers/LlamaParseReader.ts
@@ -1,5 +1,4 @@
-import type { GenericFileSystem } from "@llamaindex/env";
-import { defaultFS } from "@llamaindex/env";
+import { defaultFS, getEnv, type GenericFileSystem } from "@llamaindex/env";
 import { Document } from "../Node.js";
 import type { FileReader } from "./type.js";
 
@@ -24,7 +23,7 @@ export class LlamaParseReader implements FileReader {
 
   constructor(params: Partial<LlamaParseReader> = {}) {
     Object.assign(this, params);
-    params.apiKey = params.apiKey ?? process.env.LLAMA_CLOUD_API_KEY;
+    params.apiKey = params.apiKey ?? getEnv("LLAMA_CLOUD_API_KEY");
     if (!params.apiKey) {
       throw new Error(
         "API Key is required for LlamaParseReader. Please pass the apiKey parameter or set the LLAMA_CLOUD_API_KEY environment variable.",
diff --git a/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts b/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts
index 17c0170c3..77c1b5bb0 100644
--- a/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts
+++ b/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts
@@ -1,5 +1,6 @@
 import { AstraDB } from "@datastax/astra-db-ts";
 import type { Collection } from "@datastax/astra-db-ts/dist/collections";
+import { getEnv } from "@llamaindex/env";
 import type { BaseNode } from "../../Node.js";
 import { MetadataMode } from "../../Node.js";
 import type {
@@ -34,9 +35,8 @@ export class AstraDBVectorStore implements VectorStore {
     if (init?.astraDBClient) {
       this.astraDBClient = init.astraDBClient;
     } else {
-      const token =
-        init?.params?.token ?? process.env.ASTRA_DB_APPLICATION_TOKEN;
-      const endpoint = init?.params?.endpoint ?? process.env.ASTRA_DB_ENDPOINT;
+      const token = init?.params?.token ?? getEnv("ASTRA_DB_APPLICATION_TOKEN");
+      const endpoint = init?.params?.endpoint ?? getEnv("ASTRA_DB_ENDPOINT");
 
       if (!token) {
         throw new Error(
@@ -48,7 +48,7 @@ export class AstraDBVectorStore implements VectorStore {
       }
       const namespace =
         init?.params?.namespace ??
-        process.env.ASTRA_DB_NAMESPACE ??
+        getEnv("ASTRA_DB_NAMESPACE") ??
         "default_keyspace";
       this.astraDBClient = new AstraDB(token, endpoint, namespace);
     }
diff --git a/packages/core/src/storage/vectorStore/MongoDBAtlasVectorStore.ts b/packages/core/src/storage/vectorStore/MongoDBAtlasVectorStore.ts
index 491d5fd10..b37fe6769 100644
--- a/packages/core/src/storage/vectorStore/MongoDBAtlasVectorStore.ts
+++ b/packages/core/src/storage/vectorStore/MongoDBAtlasVectorStore.ts
@@ -1,3 +1,4 @@
+import { getEnv } from "@llamaindex/env";
 import type { BulkWriteOptions, Collection } from "mongodb";
 import { MongoClient } from "mongodb";
 import type { BaseNode } from "../../Node.js";
@@ -44,7 +45,7 @@ export class MongoDBAtlasVectorSearch implements VectorStore {
     if (init.mongodbClient) {
       this.mongodbClient = init.mongodbClient;
     } else {
-      const mongoUri = process.env.MONGODB_URI;
+      const mongoUri = getEnv("MONGODB_URI");
       if (!mongoUri) {
         throw new Error(
           "Must specify MONGODB_URI via env variable if not directly passing in client.",
diff --git a/packages/core/src/storage/vectorStore/PineconeVectorStore.ts b/packages/core/src/storage/vectorStore/PineconeVectorStore.ts
index ae4f6923b..74c325529 100644
--- a/packages/core/src/storage/vectorStore/PineconeVectorStore.ts
+++ b/packages/core/src/storage/vectorStore/PineconeVectorStore.ts
@@ -6,7 +6,7 @@ import type {
   VectorStoreQueryResult,
 } from "./types.js";
 
-import type { GenericFileSystem } from "@llamaindex/env";
+import { getEnv, type GenericFileSystem } from "@llamaindex/env";
 import type {
   FetchResponse,
   Index,
@@ -45,11 +45,11 @@ export class PineconeVectorStore implements VectorStore {
 
   constructor(params?: PineconeParams) {
     this.indexName =
-      params?.indexName ?? process.env.PINECONE_INDEX_NAME ?? "llama";
-    this.namespace = params?.namespace ?? process.env.PINECONE_NAMESPACE ?? "";
+      params?.indexName ?? getEnv("PINECONE_INDEX_NAME") ?? "llama";
+    this.namespace = params?.namespace ?? getEnv("PINECONE_NAMESPACE") ?? "";
     this.chunkSize =
       params?.chunkSize ??
-      Number.parseInt(process.env.PINECONE_CHUNK_SIZE ?? "100");
+      Number.parseInt(getEnv("PINECONE_CHUNK_SIZE") ?? "100");
     this.textKey = params?.textKey ?? "text";
   }
 
diff --git a/packages/core/tests/tsconfig.json b/packages/core/tests/tsconfig.json
index 6576baf06..c1b0f9adf 100644
--- a/packages/core/tests/tsconfig.json
+++ b/packages/core/tests/tsconfig.json
@@ -6,5 +6,13 @@
     "moduleResolution": "node16",
     "target": "ESNext"
   },
-  "include": ["./**/*.ts"]
+  "include": ["./**/*.ts"],
+  "references": [
+    {
+      "path": "../../core/tsconfig.json"
+    },
+    {
+      "path": "../../env/tsconfig.json"
+    }
+  ]
 }
diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json
index 6367996de..3867a74e0 100644
--- a/packages/core/tsconfig.json
+++ b/packages/core/tsconfig.json
@@ -3,6 +3,7 @@
   "compilerOptions": {
     "rootDir": "./src",
     "outDir": "./dist/type",
+    "tsBuildInfoFile": ".tsbuildinfo",
     "emitDeclarationOnly": true,
     "module": "node16",
     "moduleResolution": "node16",
@@ -10,5 +11,10 @@
     "strict": true
   },
   "include": ["./src"],
-  "exclude": ["node_modules"]
+  "exclude": ["node_modules"],
+  "references": [
+    {
+      "path": "../env/tsconfig.json"
+    }
+  ]
 }
diff --git a/packages/env/jsr.json b/packages/env/jsr.json
new file mode 100644
index 000000000..6dec8c04c
--- /dev/null
+++ b/packages/env/jsr.json
@@ -0,0 +1,8 @@
+{
+  "name": "@llamaindex/env",
+  "version": "0.0.4",
+  "exports": {
+    ".": "./src/index.ts",
+    "./type": "./src/type.ts"
+  }
+}
diff --git a/packages/env/src/index.polyfill.ts b/packages/env/src/index.polyfill.ts
index 6c3c4131b..7a844d7a2 100644
--- a/packages/env/src/index.polyfill.ts
+++ b/packages/env/src/index.polyfill.ts
@@ -39,3 +39,4 @@ export function randomUUID(): string {
   return crypto.randomUUID();
 }
 export * from "./type.js";
+export { getEnv } from "./utils.js";
diff --git a/packages/env/src/index.ts b/packages/env/src/index.ts
index bd5095def..e2692d3cc 100644
--- a/packages/env/src/index.ts
+++ b/packages/env/src/index.ts
@@ -34,5 +34,6 @@ export const defaultFS: CompleteFileSystem = {
   stat: fs.stat,
 };
 
-export * from "./type.js";
+export type * from "./type.js";
+export { getEnv } from "./utils.js";
 export { EOL, ok, path, randomUUID };
diff --git a/packages/env/src/type.ts b/packages/env/src/type.ts
index 00fb0a613..303676dad 100644
--- a/packages/env/src/type.ts
+++ b/packages/env/src/type.ts
@@ -58,9 +58,8 @@ export class InMemoryFileSystem implements CompleteFileSystem {
     }
   }
 
-  async mkdir(path: string) {
+  async mkdir(path: string): Promise<undefined> {
     this.files[path] = _.get(this.files, path, null);
-    return undefined;
   }
 
   async readdir(path: string): Promise<string[]> {
diff --git a/packages/env/src/utils.ts b/packages/env/src/utils.ts
new file mode 100644
index 000000000..48b1efccf
--- /dev/null
+++ b/packages/env/src/utils.ts
@@ -0,0 +1,12 @@
+export function getEnv(name: string): string | undefined {
+  if (typeof process === "undefined" || typeof process.env === "undefined") {
+    // @ts-expect-error
+    if (typeof Deno === "undefined") {
+      throw new Error("Current environment is not supported");
+    } else {
+      // @ts-expect-error
+      return Deno.env.get(name);
+    }
+  }
+  return process.env[name];
+}
diff --git a/packages/env/tsconfig.json b/packages/env/tsconfig.json
index 373c74079..c81013f82 100644
--- a/packages/env/tsconfig.json
+++ b/packages/env/tsconfig.json
@@ -3,6 +3,7 @@
   "compilerOptions": {
     "rootDir": "./src",
     "outDir": "./dist/type",
+    "tsBuildInfoFile": ".tsbuildinfo",
     "emitDeclarationOnly": true,
     "module": "node16",
     "moduleResolution": "node16",
diff --git a/tsconfig.json b/tsconfig.json
index 561b01dd2..ee2dbb531 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -11,7 +11,13 @@
     "outDir": "./lib",
     "tsBuildInfoFile": "./lib/.tsbuildinfo",
     "incremental": true,
-    "composite": true
+    "composite": true,
+    "paths": {
+      "llamaindex": ["./packages/core/src/index.ts"],
+      "llamaindex/*": ["./packages/core/src/*.ts"],
+      "@llamaindex/env": ["./packages/env/src/index.ts"],
+      "@llamaindex/env/*": ["./packages/env/src/*.ts"]
+    }
   },
   "files": [],
   "references": [
-- 
GitLab