Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions langchain-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
"test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
"format": "prettier --config .prettierrc --write \"src\"",
"format:check": "prettier --config .prettierrc --check \"src\""
"format:check": "prettier --config .prettierrc --check \"src\"",
"type-check": "tsc --noEmit"
},
"author": "LangChain",
"license": "MIT",
Expand Down Expand Up @@ -68,7 +69,8 @@
"release-it": "^18.1.2",
"rimraf": "^5.0.1",
"ts-jest": "^29.1.0",
"typescript": "~5.1.6",
"tsup": "^8.4.0",
"typescript": "^5.4.5",
"web-streams-polyfill": "^4.0.0"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions langchain-core/src/messages/content_blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export function parseBase64DataUrl({
*/
export function parseBase64DataUrl({
dataUrl,
asTypedArray = false,
asTypedArray,
}: {
dataUrl: string;
asTypedArray?: false;
Expand All @@ -243,7 +243,7 @@ export function parseBase64DataUrl({
*/
export function parseBase64DataUrl({
dataUrl: data_url,
asTypedArray = false,
asTypedArray,
}: {
dataUrl: string;
asTypedArray?: boolean;
Expand Down
13 changes: 0 additions & 13 deletions langchain-core/tsconfig.cjs.json

This file was deleted.

6 changes: 3 additions & 3 deletions langchain-core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@tsconfig/recommended",
"extends": "@tsconfig/recommended/tsconfig.json",
"compilerOptions": {
"outDir": "../dist",
"rootDir": "./src",
Expand All @@ -9,7 +9,7 @@
"ES2022.Object",
"DOM"
],
"module": "ES2020",
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
"declaration": true,
Expand All @@ -30,4 +30,4 @@
"dist",
"docs"
]
}
}
87 changes: 87 additions & 0 deletions langchain-core/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { defineConfig } from "tsup";
export default defineConfig({
// Entry points - adjust for your package structure
entry: [
"src/agents.ts",
"src/caches/base.ts",
"src/callbacks/base.ts",
"src/callbacks/dispatch/index.ts",
"src/callbacks/dispatch/web.ts",
"src/callbacks/manager.ts",
"src/callbacks/promises.ts",
"src/chat_history.ts",
"src/context.ts",
"src/documents/index.ts",
"src/document_loaders/base.ts",
"src/document_loaders/langsmith.ts",
"src/embeddings.ts",
"src/example_selectors/index.ts",
"src/indexing/index.ts",
"src/language_models/base.ts",
"src/language_models/chat_models.ts",
"src/language_models/llms.ts",
"src/load/index.ts",
"src/load/serializable.ts",
"src/memory.ts",
"src/messages/index.ts",
"src/messages/tool.ts",
"src/output_parsers/index.ts",
"src/output_parsers/openai_tools/index.ts",
"src/output_parsers/openai_functions/index.ts",
"src/outputs.ts",
"src/prompts/index.ts",
"src/prompt_values.ts",
"src/runnables/index.ts",
"src/runnables/graph.ts",
"src/runnables/remote.ts",
"src/retrievers/index.ts",
"src/retrievers/document_compressors/base.ts",
"src/singletons/index.ts",
"src/stores.ts",
"src/structured_query/index.ts",
"src/tools/index.ts",
"src/tracers/base.ts",
"src/tracers/console.ts",
"src/tracers/initialize.ts",
"src/tracers/log_stream.ts",
"src/tracers/run_collector.ts",
"src/tracers/tracer_langchain.ts",
"src/tracers/tracer_langchain_v1.ts",
"src/types/stream.ts",
"src/utils/async_caller.ts",
"src/utils/chunk_array.ts",
"src/utils/env.ts",
"src/utils/event_source_parse.ts",
"src/utils/function_calling.ts",
"src/utils/hash.ts",
"src/utils/json_patch.ts",
"src/utils/json_schema.ts",
"src/utils/math.ts",
"src/utils/stream.ts",
"src/utils/testing/index.ts",
"src/utils/tiktoken.ts",
"src/utils/types/index.ts",
"src/vectorstores.ts",
],
// Output both ESM and CJS formats
format: ["esm", "cjs"],
// Generate declaration files
dts: true,
// enable treeshaking
treeshake: "safest",
// Generate sourcemaps
sourcemap: true,
// Clean output directory before build
clean: true,
// Specify output directory
outDir: "dist",
// Set output extension based on format
outExtension({ format }) {
return {
js: format === "esm" ? ".js" : ".cjs",
};
},
// Ensure all external dependencies are properly excluded from the bundle
// These will be taken from package.json dependencies/peerDependencies
external: [],
});
51 changes: 51 additions & 0 deletions libs/langchain-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,54 @@ This package contains the LangChain.js shared scripts for our packages.
```bash npm2yarn
npm install @langchain/scripts
```

## Usage

### Build Script

The build script supports both traditional TypeScript compilation and modern tsup-based builds.

```bash
npx lc_build
```

#### Traditional TypeScript Build

By default, the build script uses TypeScript's compiler (tsc) to build both ESM and CJS versions of your package.

#### tsup-based Build

The build script can also use [tsup](https://github.com/egoist/tsup) (a zero-config TypeScript bundler powered by esbuild) which offers significant performance improvements (10-100x faster builds).

To migrate your package to use tsup:

```bash
npx lc_build --migrate-build
```

This command performs several migration steps:
1. Creates a `tsup.config.ts` file with sensible defaults for LangChain packages
2. Updates TypeScript to the latest version in your package.json
3. Ensures your package.json has a `type-check` script
4. Backs up the tsconfig.cjs.json file (which is no longer needed with tsup)
5. Provides guidance on updating build scripts if needed

After migration, simply run the build script normally:

```bash
npx lc_build
```

The script will automatically detect the presence of a tsup configuration file and use it for building.

### Notebooks Type-Checking

```bash
npx notebook_validate
```

### Serialized Field Extraction

```bash
npx extract_serializable_fields
```
11 changes: 7 additions & 4 deletions libs/langchain-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
},
"scripts": {
"build": "yarn clean && yarn turbo:command build:internal --filter=@langchain/scripts",
"build:internal": "tsc --project ./tsconfig.build.json && yarn move:artifacts && yarn build:generated",
"move:artifacts": "rimraf dist && mkdir -p dist && mv dist_build/* dist/",
"build:internal": "tsc --project ./tsconfig.build.json && yarn move:artifacts && yarn build:generated && yarn copy:template",
"move:artifacts": "rimraf dist && mkdir -p dist/build && cp -r dist_build/* dist/ && rimraf dist_build",
"copy:template": "cp src/build/tsup.config.template.ts dist/build/",
"build:generated": "node bin/build.js --create-entrypoints --pre --tree-shaking",
"build:turbo": "yarn turbo:command build --filter=@langchain/scripts",
"lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
Expand All @@ -37,7 +38,8 @@
"test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
"format": "prettier --write \"src\"",
"format:check": "prettier --check \"src\"",
"create:integration:doc": "node dist/cli/docs/index.js"
"create:integration:doc": "node dist/cli/docs/index.js",
"check:types": "tsc --noEmit"
},
"author": "LangChain",
"license": "MIT",
Expand All @@ -52,13 +54,14 @@
"rimraf": "^5.0.1",
"rollup": "^4.5.2",
"ts-morph": "^21.0.1",
"tsup": "^8.4.0",
"typescript": "^5.4.5"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
"@swc/core": "^1.3.90",
"@swc/jest": "^0.2.29",
"@tsconfig/recommended": "^1.0.3",
"@tsconfig/recommended": "^1.0.8",
"@types/lodash": "^4",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
Expand Down
Loading
Loading