Skip to content

Commit 22ff083

Browse files
authored
feat: init @llamaindex/core (#938)
1 parent 74d7e05 commit 22ff083

File tree

127 files changed

+1093
-771
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+1093
-771
lines changed

.github/workflows/test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ jobs:
128128
run: pnpm run build
129129
- name: Copy examples
130130
run: rsync -rv --exclude=node_modules ./examples ${{ runner.temp }}
131+
- name: Pack @llamaindex/core
132+
run: pnpm pack --pack-destination ${{ runner.temp }}
133+
working-directory: packages/core
131134
- name: Pack @llamaindex/env
132135
run: pnpm pack --pack-destination ${{ runner.temp }}
133136
working-directory: packages/env

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
"eslint": "^8.57.0",
2525
"eslint-config-next": "^14.2.4",
2626
"eslint-config-prettier": "^9.1.0",
27-
"eslint-config-turbo": "^1.13.4",
27+
"eslint-config-turbo": "^2.0.5",
2828
"eslint-plugin-react": "7.34.1",
2929
"husky": "^9.0.11",
3030
"lint-staged": "^15.2.7",
3131
"madge": "^7.0.0",
3232
"prettier": "^3.3.2",
3333
"prettier-plugin-organize-imports": "^3.2.4",
34-
"turbo": "^1.13.4",
34+
"turbo": "^2.0.5",
3535
"typescript": "^5.5.2"
3636
},
3737
"packageManager": "[email protected]",
@@ -40,6 +40,9 @@
4040
"trim": "1.0.1",
4141
"@babel/traverse": "7.23.2",
4242
"protobufjs": "7.2.6"
43+
},
44+
"patchedDependencies": {
45+
4346
}
4447
},
4548
"lint-staged": {

packages/community/jsr.json

-8
This file was deleted.

packages/core/package.json

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"name": "@llamaindex/core",
3+
"type": "module",
4+
"version": "0.0.1",
5+
"description": "LlamaIndex Core Module",
6+
"exports": {
7+
"./decorator": {
8+
"require": {
9+
"types": "./dist/decorator/index.d.cts",
10+
"default": "./dist/decorator/index.cjs"
11+
},
12+
"import": {
13+
"types": "./dist/decorator/index.d.ts",
14+
"default": "./dist/decorator/index.js"
15+
},
16+
"default": {
17+
"types": "./dist/decorator/index.d.ts",
18+
"default": "./dist/decorator/index.js"
19+
}
20+
},
21+
"./global": {
22+
"require": {
23+
"types": "./dist/global/index.d.cts",
24+
"default": "./dist/global/index.cjs"
25+
},
26+
"import": {
27+
"types": "./dist/global/index.d.ts",
28+
"default": "./dist/global/index.js"
29+
},
30+
"default": {
31+
"types": "./dist/global/index.d.ts",
32+
"default": "./dist/global/index.js"
33+
}
34+
},
35+
"./schema": {
36+
"require": {
37+
"types": "./dist/schema/index.d.cts",
38+
"default": "./dist/schema/index.cjs"
39+
},
40+
"import": {
41+
"types": "./dist/schema/index.d.ts",
42+
"default": "./dist/schema/index.js"
43+
},
44+
"default": {
45+
"types": "./dist/schema/index.d.ts",
46+
"default": "./dist/schema/index.js"
47+
}
48+
}
49+
},
50+
"scripts": {
51+
"dev": "bunchee --watch",
52+
"build": "bunchee"
53+
},
54+
"repository": {
55+
"type": "git",
56+
"directory": "packages/core",
57+
"url": "https://github.com/himself65/LlamaIndexTS.git"
58+
},
59+
"devDependencies": {
60+
"bunchee": "^5.2.1"
61+
},
62+
"dependencies": {
63+
"@llamaindex/env": "workspace:*",
64+
"@types/node": "^20.14.9",
65+
"zod": "^3.23.8"
66+
}
67+
}

packages/llamaindex/src/internal/decorator/node.ts renamed to packages/core/src/decorator/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { getEnv } from "@llamaindex/env";
2-
import type { BaseNode } from "../../Node.js";
3-
import { getChunkSize } from "../settings/chunk-size.js";
2+
import { Settings } from "../global";
3+
import type { BaseNode } from "../schema/node";
44

55
const emitOnce = false;
66

77
export function chunkSizeCheck<
8-
This extends BaseNode,
8+
This extends { id_: string },
99
Args extends any[],
1010
Return,
1111
>(
@@ -17,15 +17,15 @@ export function chunkSizeCheck<
1717
) {
1818
return function (this: This, ...args: Args) {
1919
const content = contentGetter.call(this, ...args);
20-
const chunkSize = getChunkSize();
20+
const chunkSize = Settings.chunkSize;
2121
const enableChunkSizeCheck = getEnv("ENABLE_CHUNK_SIZE_CHECK") === "true";
2222
if (
2323
enableChunkSizeCheck &&
2424
chunkSize !== undefined &&
2525
content.length > chunkSize
2626
) {
2727
console.warn(
28-
`Node (${this.id_}) is larger than chunk size: ${content.length}`,
28+
`Node (${this.id_}) is larger than chunk size: ${content.length} > ${chunkSize}`,
2929
);
3030
if (!emitOnce) {
3131
console.warn(

packages/core/src/global/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Settings } from "./settings";

packages/core/src/global/settings.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {
2+
getChunkSize,
3+
setChunkSize,
4+
withChunkSize,
5+
} from "./settings/chunk-size";
6+
7+
export const Settings = {
8+
get chunkSize(): number | undefined {
9+
return getChunkSize();
10+
},
11+
set chunkSize(chunkSize: number | undefined) {
12+
setChunkSize(chunkSize);
13+
},
14+
withChunkSize<Result>(chunkSize: number, fn: () => Result): Result {
15+
return withChunkSize(chunkSize, fn);
16+
},
17+
};

packages/llamaindex/src/internal/settings/chunk-size.ts renamed to packages/core/src/global/settings/chunk-size.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { AsyncLocalStorage } from "@llamaindex/env";
22

33
const chunkSizeAsyncLocalStorage = new AsyncLocalStorage<number | undefined>();
4-
const globalChunkSize: number | null = null;
4+
let globalChunkSize: number | null = null;
55

66
export function getChunkSize(): number | undefined {
77
return globalChunkSize ?? chunkSizeAsyncLocalStorage.getStore();
88
}
99

1010
export function setChunkSize(chunkSize: number | undefined) {
11-
chunkSizeAsyncLocalStorage.enterWith(chunkSize);
11+
if (chunkSize !== undefined) {
12+
globalChunkSize = chunkSize;
13+
}
1214
}
1315

1416
export function withChunkSize<Result>(

packages/core/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./schema";

packages/core/src/schema/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./node";
2+
export * from "./zod";

0 commit comments

Comments
 (0)