Compare commits

...

10 Commits

Author SHA1 Message Date
Alex Yang def2b92686 fix: 2025-04-08 13:34:14 -07:00
Alex Yang 6c75b13154 feat: fix type 2025-04-08 13:22:36 -07:00
Alex Yang cd07b034bf feat: workflow-based llama-reader 2025-04-08 12:28:30 -07:00
Alex Yang 739323032b feat: workflow-based llama-reader 2025-04-07 00:50:16 -07:00
Thuc Pham 3534c373f2 feat: support multi-resolution compatibility (#1816) 2025-04-05 18:41:39 +07:00
github-actions[bot] 2cbdf71669 Release 0.9.16 (#1811)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: marcusschiesser <17126+marcusschiesser@users.noreply.github.com>
2025-04-04 11:12:27 +02:00
Huu Le ead657aedd feat: add MCP tools integration and example usage (#1819) 2025-04-04 11:03:10 +02:00
Marcus Schiesser f5e4d098b0 chore: remove gpt-tokenizer (#1815) 2025-04-03 14:23:31 +02:00
dependabot[bot] 4d97226e50 chore(deps): bump next from 15.2.3 to 15.2.4 (#1812)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-03 13:57:39 +07:00
Marcus Schiesser 4999df18cc chore: bump nextjs to "^15.2.3" (#1810) 2025-04-02 21:24:57 +07:00
57 changed files with 1602 additions and 519 deletions
+6
View File
@@ -0,0 +1,6 @@
---
"llamaindex": patch
"@llamaindex/workflow": patch
---
feat: support multi-resolution compatibility
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/doc
## 0.2.5
### Patch Changes
- 4999df1: bump nextjs
- Updated dependencies [f5e4d09]
- llamaindex@0.9.16
## 0.2.4
### Patch Changes
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/doc",
"version": "0.2.4",
"version": "0.2.5",
"private": true,
"scripts": {
"postinstall": "fumadocs-mdx",
@@ -46,7 +46,7 @@
"hast-util-to-jsx-runtime": "^2.3.2",
"llamaindex": "workspace:*",
"lucide-react": "^0.460.0",
"next": "^15.2.1",
"next": "^15.2.4",
"next-themes": "^0.4.3",
"react": "^19.0.0",
"react-dom": "^19.0.0",
@@ -58,7 +58,7 @@ FunctionTool.from<Input>((input) => {
{
compilerOptions: {
// ⬇️ add this line to your tsconfig.json
moduleResolution: "bundler", // or "node16"
moduleResolution: "bundler", // or "nodenext" | "node16" | "node"
},
}
```
@@ -89,6 +89,22 @@ In old module resolution, TypeScript will not be able to find the module because
See more about [moduleResolution](https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution) or
[TypeScript 5.0 blog](https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#--moduleresolution-bundler7).
Note for `"moduleResolution": "node"`:
`moduleResolution: node` does not strictly follow package.json exports. We still support `moduleResolution: node` with a limited import path. When using `moduleResolution: node`, you may encounter type errors when importing like this:
```ts
import { Settings } from "llamaindex/Settings";
// Cannot find module 'llamaindex/Settings' or its corresponding type declarations.
// There are types at '.../node_modules/llamaindex/dist/type/Settings.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.
```
The simplest way to fix this without changing `moduleResolution` is to import directly from `llamaindex`:
```ts
import { Settings } from "llamaindex";
```
</Accordion>
</Accordions>
@@ -1,5 +1,12 @@
# @llamaindex/cloudflare-worker-agent-test
## 0.0.150
### Patch Changes
- Updated dependencies [f5e4d09]
- llamaindex@0.9.16
## 0.0.149
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/cloudflare-worker-agent-test",
"version": "0.0.149",
"version": "0.0.150",
"type": "module",
"private": true,
"scripts": {
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/next-agent-test
## 0.1.150
### Patch Changes
- 4999df1: bump nextjs
- Updated dependencies [f5e4d09]
- llamaindex@0.9.16
## 0.1.149
### Patch Changes
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/next-agent-test",
"version": "0.1.149",
"version": "0.1.150",
"private": true,
"scripts": {
"dev": "next dev",
@@ -10,7 +10,7 @@
"dependencies": {
"ai": "^4.0.0",
"llamaindex": "workspace:*",
"next": "15.2.0",
"next": "^15.2.4",
"react": "19.0.0",
"react-dom": "19.0.0"
},
@@ -1,5 +1,13 @@
# test-edge-runtime
## 0.1.149
### Patch Changes
- 4999df1: bump nextjs
- Updated dependencies [f5e4d09]
- llamaindex@0.9.16
## 0.1.148
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/nextjs-edge-runtime-test",
"version": "0.1.148",
"version": "0.1.149",
"private": true,
"scripts": {
"dev": "next dev",
@@ -9,7 +9,7 @@
},
"dependencies": {
"llamaindex": "workspace:*",
"next": "15.2.0",
"next": "^15.2.4",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
@@ -1,5 +1,13 @@
# @llamaindex/next-node-runtime
## 0.1.16
### Patch Changes
- 4999df1: bump nextjs
- Updated dependencies [f5e4d09]
- llamaindex@0.9.16
## 0.1.15
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/next-node-runtime-test",
"version": "0.1.15",
"version": "0.1.16",
"private": true,
"scripts": {
"dev": "next dev",
@@ -11,7 +11,7 @@
"@llamaindex/huggingface": "workspace:*",
"@llamaindex/readers": "workspace:*",
"llamaindex": "workspace:*",
"next": "15.2.0",
"next": "^15.2.4",
"react": "19.0.0",
"react-dom": "19.0.0"
},
@@ -1,5 +1,12 @@
# vite-import-llamaindex
## 0.0.16
### Patch Changes
- Updated dependencies [f5e4d09]
- llamaindex@0.9.16
## 0.0.15
### Patch Changes
@@ -1,7 +1,7 @@
{
"name": "vite-import-llamaindex",
"private": true,
"version": "0.0.15",
"version": "0.0.16",
"type": "module",
"scripts": {
"build": "vite build",
@@ -1,5 +1,12 @@
# @llamaindex/waku-query-engine-test
## 0.0.150
### Patch Changes
- Updated dependencies [f5e4d09]
- llamaindex@0.9.16
## 0.0.149
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/waku-query-engine-test",
"version": "0.0.149",
"version": "0.0.150",
"type": "module",
"private": true,
"scripts": {
+9
View File
@@ -1,5 +1,14 @@
# examples
## 0.3.3
### Patch Changes
- Updated dependencies [f5e4d09]
- Updated dependencies [ead657a]
- llamaindex@0.9.16
- @llamaindex/tools@0.0.5
## 0.3.2
### Patch Changes
+34
View File
@@ -0,0 +1,34 @@
import { openai } from "@llamaindex/openai";
import { mcp } from "@llamaindex/tools";
import { agent } from "llamaindex";
async function main() {
// Create an MCP server for filesystem tools
const server = mcp({
command: "npx",
args: ["-y", "@modelcontextprotocol/server-filesystem", "."],
verbose: true,
});
try {
// Create an agent that uses the MCP tools
const myAgent = agent({
name: "Assistant",
systemPrompt: "Use the tools to achieve the task.",
tools: await server.tools(),
llm: openai({ model: "gpt-4o" }),
verbose: true,
});
// Run a task
const response = await myAgent.run(
"what are the files in the current directory?",
);
console.log("Agent response:", response.data);
} finally {
await server.cleanup();
}
}
main().catch(console.error);
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/examples",
"version": "0.3.2",
"version": "0.3.3",
"private": true,
"scripts": {
"lint": "eslint .",
@@ -51,7 +51,7 @@
"@llamaindex/jinaai": "^0.0.8",
"@llamaindex/perplexity": "^0.0.5",
"@llamaindex/supabase": "^0.1.1",
"@llamaindex/tools": "^0.0.4",
"@llamaindex/tools": "^0.0.5",
"@notionhq/client": "^2.2.15",
"@pinecone-database/pinecone": "^4.0.0",
"@vercel/postgres": "^0.10.0",
@@ -60,7 +60,7 @@
"commander": "^12.1.0",
"dotenv": "^16.4.5",
"js-tiktoken": "^1.0.14",
"llamaindex": "^0.9.15",
"llamaindex": "^0.9.16",
"mongodb": "6.7.0",
"postgres": "^3.4.4",
"wikipedia": "^2.1.2",
+1
View File
@@ -14,6 +14,7 @@
"start:assemblyai": "node --import tsx ./src/assemblyai.ts",
"start:llamaparse-dir": "node --import tsx ./src/simple-directory-reader-with-llamaparse.ts",
"start:llamaparse-json": "node --import tsx ./src/llamaparse-json.ts",
"start:llamaparse-workflow": "node --import tsx ./src/llamaparse-workflow.ts",
"start:discord": "node --import tsx ./src/discord.ts",
"start:json": "node --import tsx ./src/json.ts",
"start:obsidian": "node --import tsx ./src/obsidian.ts"
@@ -0,0 +1,26 @@
import { uploadFile } from "@llamaindex/cloud/reader-workflow";
async function main() {
const job = await uploadFile({
file: "../data/basic.pdf",
});
console.log("job id", job.jobId);
job.signal.addEventListener("abort", () => {
console.error("ERROR:", job.signal.reason);
});
const markdown = await job.markdown();
console.log("--markdown--");
console.log(markdown);
const text = await job.text();
console.log("--text--");
console.log(text);
const json = await job.json();
console.log("--json--");
console.log(json);
}
main();
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/autotool
## 6.0.16
### Patch Changes
- 4999df1: bump nextjs
- Updated dependencies [f5e4d09]
- llamaindex@0.9.16
## 6.0.15
### Patch Changes
@@ -1,5 +1,14 @@
# @llamaindex/autotool-01-node-example
## 0.0.97
### Patch Changes
- Updated dependencies [4999df1]
- Updated dependencies [f5e4d09]
- @llamaindex/autotool@6.0.16
- llamaindex@0.9.16
## 0.0.96
### Patch Changes
@@ -13,5 +13,5 @@
"scripts": {
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
},
"version": "0.0.96"
"version": "0.0.97"
}
+2 -2
View File
@@ -6,7 +6,7 @@
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
"directory": "packages/autotool"
},
"version": "6.0.15",
"version": "6.0.16",
"description": "auto transpile your JS function to LLM Agent compatible",
"files": [
"dist",
@@ -77,7 +77,7 @@
"@types/node": "^22.9.0",
"bunchee": "6.4.0",
"llamaindex": "workspace:*",
"next": "15.2.0",
"next": "^15.2.4",
"rollup": "^4.28.1",
"tsx": "^4.19.3",
"typescript": "^5.7.3",
+17
View File
@@ -47,6 +47,17 @@
"default": "./reader/dist/index.js"
},
"default": "./reader/dist/index.js"
},
"./reader-workflow": {
"require": {
"types": "./reader/dist/workflow.d.cts",
"default": "./reader/dist/workflow.cjs"
},
"import": {
"types": "./reader/dist/workflow.d.ts",
"default": "./reader/dist/workflow.js"
},
"default": "./reader/dist/workflow.js"
}
},
"repository": {
@@ -59,10 +70,16 @@
"@hey-api/openapi-ts": "^0.61.0",
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*",
"@types/node": "^22.14.0",
"bunchee": "6.4.0"
},
"peerDependencies": {
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*"
},
"dependencies": {
"fluere": "^0.3.3",
"stable-hash": "^0.0.5",
"zod": "^3.24.2"
}
}
+300
View File
@@ -0,0 +1,300 @@
import { createClient, createConfig } from "@hey-api/client-fetch";
import { fs, getEnv, path } from "@llamaindex/env";
import {
createWorkflow,
type WorkflowEvent,
workflowEvent,
type WorkflowEventData,
} from "fluere";
import { withStore } from "fluere/middleware/store";
import { withTraceEvents } from "fluere/middleware/trace-events";
import { collect } from "fluere/stream/consumer";
import { until } from "fluere/stream/until";
import { pRetryHandler } from "fluere/util/p-retry";
import { zodEvent } from "fluere/util/zod";
import hash from "stable-hash";
import { z } from "zod";
import {
type Body_upload_file_api_v1_parsing_upload_post,
getJobApiV1ParsingJobJobIdGet,
getJobJsonResultApiV1ParsingJobJobIdResultJsonGet,
getJobResultApiV1ParsingJobJobIdResultMarkdownGet,
getJobTextResultApiV1ParsingJobJobIdResultTextGet,
type StatusEnum,
uploadFileApiV1ParsingUploadPost,
} from "./api";
import { parseFormSchema } from "./schema";
type InferWorkflowEventData<T> =
T extends WorkflowEventData<infer U>
? U
: T extends WorkflowEvent<infer U>
? U
: never;
const startEvent = zodEvent(
z.union([
parseFormSchema.merge(
z.object({
file: z
.string()
.or(z.instanceof(File))
.or(z.instanceof(Blob))
.or(z.instanceof(Uint8Array))
.optional()
.describe("input"),
}),
),
parseFormSchema.merge(
z.object({
input_s3_path: z.string().optional(),
}),
),
parseFormSchema.merge(
z.object({
input_url: z.string().optional(),
}),
),
]),
);
const checkStatusEvent = workflowEvent<string>();
const checkStatusSuccessEvent = workflowEvent<string>();
const requestMarkdownEvent = workflowEvent<string>();
const requestTextEvent = workflowEvent<string>();
const requestJsonEvent = workflowEvent<string>();
const markdownResultEvent = workflowEvent<string>();
const textResultEvent = workflowEvent<string>();
const jsonResultEvent = workflowEvent<unknown>();
export type LlamaParseWorkflowParams = {
region?: "us" | "eu" | "us-staging";
apiKey?: string;
};
const URLS = {
us: "https://api.cloud.llamaindex.ai",
eu: "https://api.cloud.eu.llamaindex.ai",
"us-staging": "https://api.staging.llamaindex.ai",
} as const;
const llamaParseWorkflow = withStore((params: LlamaParseWorkflowParams) => {
const apiKey = params.apiKey ?? getEnv("LLAMA_CLOUD_API_KEY");
const region = params.region ?? "us";
if (!apiKey) {
throw new Error("LLAMA_CLOUD_API_KEY is not set");
}
return {
cache: {} as Record<string, StatusEnum>,
client: createClient(
createConfig({
baseUrl: URLS[region],
headers: {
Authorization: `Bearer ${apiKey}`,
},
}),
),
};
}, withTraceEvents(createWorkflow()));
llamaParseWorkflow.handle([startEvent], async ({ data: form }) => {
const store = llamaParseWorkflow.getStore();
const finalForm = { ...form } as Body_upload_file_api_v1_parsing_upload_post;
if ("file" in form) {
// support loads from the file system
const file = form?.file;
const isFilePath = typeof file === "string";
const data = isFilePath ? await fs.readFile(file) : file;
const filename: string | undefined = isFilePath
? path.basename(file)
: undefined;
finalForm.file = data
? globalThis.File && filename
? new File([data], filename)
: new Blob([data])
: null;
}
const {
data: { id, status },
} = await uploadFileApiV1ParsingUploadPost({
throwOnError: true,
body: {
...finalForm,
} satisfies {
[Key in keyof Body_upload_file_api_v1_parsing_upload_post]:
| Body_upload_file_api_v1_parsing_upload_post[Key]
| undefined;
} as Body_upload_file_api_v1_parsing_upload_post,
client: store.client,
});
store.cache[id] = status;
return checkStatusEvent.with(id);
});
llamaParseWorkflow.handle(
[checkStatusEvent],
pRetryHandler(
async ({ data: uuid }) => {
const store = llamaParseWorkflow.getStore();
if (store.cache[uuid] === "SUCCESS") {
{
return checkStatusSuccessEvent.with(uuid);
}
}
const {
data: { status },
} = await getJobApiV1ParsingJobJobIdGet({
throwOnError: true,
path: {
job_id: uuid,
},
client: store.client,
});
store.cache[uuid] = status;
if (status === "SUCCESS") {
return checkStatusSuccessEvent.with(uuid);
}
throw new Error(`LLamaParse status: ${status}`);
},
{
retries: 100,
},
),
);
llamaParseWorkflow.handle([requestMarkdownEvent], async ({ data: job_id }) => {
const store = llamaParseWorkflow.getStore();
const { data } = await getJobResultApiV1ParsingJobJobIdResultMarkdownGet({
throwOnError: true,
path: {
job_id,
},
client: store.client,
});
return markdownResultEvent.with(data.markdown);
});
llamaParseWorkflow.handle([requestTextEvent], async ({ data: job_id }) => {
const store = llamaParseWorkflow.getStore();
const { data } = await getJobTextResultApiV1ParsingJobJobIdResultTextGet({
throwOnError: true,
path: {
job_id,
},
client: store.client,
});
return textResultEvent.with(data.text);
});
llamaParseWorkflow.handle([requestJsonEvent], async ({ data: job_id }) => {
const store = llamaParseWorkflow.getStore();
const { data } = await getJobJsonResultApiV1ParsingJobJobIdResultJsonGet({
throwOnError: true,
path: {
job_id,
},
client: store.client,
});
return jsonResultEvent.with(data.pages);
});
const cacheMap = new Map<
string,
ReturnType<typeof llamaParseWorkflow.createContext>
>();
export type ParseJob = {
get jobId(): string;
get signal(): AbortSignal;
get context(): ReturnType<typeof llamaParseWorkflow.createContext>;
get form(): InferWorkflowEventData<typeof startEvent>;
markdown(): Promise<string>;
text(): Promise<string>;
//eslint-disable-next-line @typescript-eslint/no-explicit-any
json(): Promise<any[]>;
};
export const upload = async (
params: InferWorkflowEventData<typeof startEvent> & LlamaParseWorkflowParams,
): Promise<ParseJob> => {
//#region cache
const key = hash({ apiKey: params.apiKey, region: params.region });
if (!cacheMap.has(key)) {
const context = llamaParseWorkflow.createContext(params);
cacheMap.set(key, context);
}
//#endregion
//#region upload event
const context = cacheMap.get(key)!;
const { stream, sendEvent, createFilter } = context;
const ev = startEvent.with(params);
sendEvent(ev);
const uploadThread = await collect(
until(
stream,
createFilter(ev, (ev) => checkStatusSuccessEvent.include(ev)),
),
);
//#region
const jobId: string = uploadThread.at(-1)!.data;
const job = {
get signal() {
// lazy load
return context.signal;
},
get jobId() {
return jobId;
},
get form() {
return ev.data;
},
get context() {
return context;
},
async markdown(): Promise<string> {
const requestEv = requestMarkdownEvent.with(jobId);
sendEvent(requestEv);
const markdownThread = await collect(
until(
stream,
createFilter(requestEv, (ev) => markdownResultEvent.include(ev)),
),
);
return markdownThread.at(-1)!.data;
},
async text(): Promise<string> {
const requestEv = requestTextEvent.with(jobId);
sendEvent(requestEv);
const textThread = await collect(
until(
stream,
createFilter(requestEv, (ev) => textResultEvent.include(ev)),
),
);
return textThread.at(-1)!.data;
},
//eslint-disable-next-line @typescript-eslint/no-explicit-any
async json(): Promise<any[]> {
const requestEv = requestJsonEvent.with(jobId);
sendEvent(requestEv);
const jsonThread = await collect(
until(
stream,
createFilter(requestEv, (ev) => jsonResultEvent.include(ev)),
),
);
return jsonThread.at(-1)!.data;
},
async images(): Promise<void> {
const json = await job.json();
const images = json.flatMap(({ images }) => images);
images.map((image) => {
// todo
});
},
};
return job;
};
+121
View File
@@ -0,0 +1,121 @@
import { ParserLanguages, ParsingMode } from "./api";
import { z } from "zod";
type Language = (typeof ParserLanguages)[keyof typeof ParserLanguages];
const VALUES: [Language, ...Language[]] = [
ParserLanguages.EN,
...Object.values(ParserLanguages),
];
const languageSchema = z.enum(VALUES);
const PARSE_PRESETS = [
"fast",
"balanced",
"premium",
"structured",
"auto",
"scientific",
"invoice",
"slides",
"_carlyle",
] as const;
export const parsePresetSchema = z.enum(PARSE_PRESETS);
export const parseFormSchema = z.object({
input_s3_region: z.string().optional(),
adaptive_long_table: z.boolean().optional(),
annotate_links: z.boolean().optional(),
auto_mode: z.boolean().optional(),
auto_mode_trigger_on_image_in_page: z.boolean().optional(),
auto_mode_trigger_on_table_in_page: z.boolean().optional(),
auto_mode_trigger_on_text_in_page: z.string().optional(),
auto_mode_trigger_on_regexp_in_page: z.string().optional(),
azure_openai_api_version: z.string().optional(),
azure_openai_deployment_name: z.string().optional(),
azure_openai_endpoint: z.string().optional(),
azure_openai_key: z.string().optional(),
bbox_bottom: z.number().min(0).max(1).optional(),
bbox_left: z.number().min(0).max(1).optional(),
bbox_right: z.number().min(0).max(1).optional(),
bbox_top: z.number().min(0).max(1).optional(),
disable_ocr: z.boolean().optional(),
disable_reconstruction: z.boolean().optional(),
disable_image_extraction: z.boolean().optional(),
do_not_cache: z.coerce.boolean().optional(),
do_not_unroll_columns: z.coerce.boolean().optional(),
extract_charts: z.boolean().optional(),
guess_xlsx_sheet_name: z.boolean().optional(),
html_make_all_elements_visible: z.boolean().optional(),
html_remove_fixed_elements: z.boolean().optional(),
html_remove_navigation_elements: z.boolean().optional(),
http_proxy: z
.string()
.url(
'Set a valid URL for the HTTP proxy, e.g., "http://proxy.example.com:8080"',
)
.refine(
(url) => {
try {
const parsedUrl = new URL(url);
return (
parsedUrl.protocol === "http:" || parsedUrl.protocol === "https:"
);
} catch {
return false;
}
},
{
message: "Invalid HTTP proxy URL",
},
)
.optional(),
invalidate_cache: z.boolean().optional(),
language: z.array(languageSchema).optional(),
extract_layout: z.boolean().optional(),
max_pages: z.number().nullable().optional(),
output_pdf_of_document: z.boolean().optional(),
output_s3_path_prefix: z.string().optional(),
output_s3_region: z.string().optional(),
page_prefix: z.string().optional(),
page_separator: z.string().optional(),
page_suffix: z.string().optional(),
preserve_layout_alignment_across_pages: z.boolean().optional(),
skip_diagonal_text: z.boolean().optional(),
spreadsheet_extract_sub_tables: z.boolean().optional(),
structured_output: z.boolean().optional(),
structured_output_json_schema: z.string().optional(),
structured_output_json_schema_name: z.string().optional(),
take_screenshot: z.boolean().optional(),
target_pages: z.string().optional(),
vendor_multimodal_api_key: z.string().optional(),
vendor_multimodal_model_name: z.string().optional(),
model: z.string().optional(),
webhook_url: z.string().url().optional(),
parse_mode: z.nativeEnum(ParsingMode).nullable().optional(),
system_prompt: z.string().optional(),
system_prompt_append: z.string().optional(),
user_prompt: z.string().optional(),
job_timeout_in_seconds: z.number().optional(),
job_timeout_extra_time_per_page_in_seconds: z.number().optional(),
strict_mode_image_extraction: z.boolean().optional(),
strict_mode_image_ocr: z.boolean().optional(),
strict_mode_reconstruction: z.boolean().optional(),
strict_mode_buggy_font: z.boolean().optional(),
ignore_document_elements_for_layout_detection: z.boolean().optional(),
output_tables_as_HTML: z.boolean().optional(),
use_vendor_multimodal_model: z.boolean().optional(),
bounding_box: z.string().optional(),
gpt4o_mode: z.boolean().optional(),
gpt4o_api_key: z.string().optional(),
complemental_formatting_instruction: z.string().optional(),
content_guideline_instruction: z.string().optional(),
premium_mode: z.boolean().optional(),
is_formatting_instruction: z.boolean().optional(),
continuous_mode: z.boolean().optional(),
parsing_instruction: z.string().optional(),
fast_mode: z.boolean().optional(),
formatting_instruction: z.string().optional(),
preset: parsePresetSchema.optional(),
});
+1 -1
View File
@@ -8,7 +8,7 @@
"moduleResolution": "Bundler",
"skipLibCheck": true,
"strict": true,
"types": []
"types": ["node"]
},
"include": ["./src"],
"exclude": ["node_modules"],
+7
View File
@@ -1,5 +1,12 @@
# @llamaindex/experimental
## 0.0.166
### Patch Changes
- Updated dependencies [f5e4d09]
- llamaindex@0.9.16
## 0.0.165
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/experimental",
"description": "Experimental package for LlamaIndexTS",
"version": "0.0.165",
"version": "0.0.166",
"type": "module",
"types": "dist/type/index.d.ts",
"main": "dist/cjs/index.js",
+6
View File
@@ -1,5 +1,11 @@
# llamaindex
## 0.9.16
### Patch Changes
- f5e4d09: Remove gpt-tokenizer from llamaindex
## 0.9.15
### Patch Changes
+1 -2
View File
@@ -1,6 +1,6 @@
{
"name": "llamaindex",
"version": "0.9.15",
"version": "0.9.16",
"license": "MIT",
"type": "module",
"keywords": [
@@ -29,7 +29,6 @@
"@types/lodash": "^4.17.7",
"@types/node": "^22.9.0",
"ajv": "^8.17.1",
"gpt-tokenizer": "^2.6.2",
"lodash": "^4.17.21",
"magic-bytes.js": "^1.10.0"
},
-1
View File
@@ -68,7 +68,6 @@ export * from "@llamaindex/core/storage/kv-store";
export * from "@llamaindex/core/utils";
export * from "@llamaindex/openai";
export * from "@llamaindex/workflow";
export * from "@llamaindex/workflow/agent";
export * from "./agent/index.js";
export * from "./cloud/index.js";
export * from "./engines/chat/index.js";
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/server
## 0.0.7
### Patch Changes
- 4999df1: bump nextjs
- Updated dependencies [f5e4d09]
- llamaindex@0.9.16
## 0.0.6
### Patch Changes
+2 -2
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/server",
"description": "LlamaIndex Server",
"version": "0.0.6",
"version": "0.0.7",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -56,7 +56,7 @@
"ai": "^4.2.0",
"@llamaindex/env": "workspace:*",
"llamaindex": "workspace:*",
"next": "15.2.3",
"next": "^15.2.4",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"@radix-ui/react-tabs": "^1.1.0",
+6
View File
@@ -1,5 +1,11 @@
# @llamaindex/tools
## 0.0.5
### Patch Changes
- ead657a: Add adapter to use stdio MCP server as tools
## 0.0.4
### Patch Changes
+2 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/tools",
"description": "LlamaIndex Tools",
"version": "0.0.4",
"version": "0.0.5",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -41,6 +41,7 @@
"@apidevtools/swagger-parser": "^10.1.0",
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*",
"@modelcontextprotocol/sdk": "^1.8.0",
"@e2b/code-interpreter": "^1.0.4",
"duck-duck-scrape": "^2.2.5",
"papaparse": "^5.4.1",
+1
View File
@@ -4,6 +4,7 @@ export * from "./tools/duckduckgo";
export * from "./tools/form-filling";
export * from "./tools/img-gen";
export * from "./tools/interpreter";
export * from "./tools/mcp";
export * from "./tools/openapi-action";
export * from "./tools/weather";
export * from "./tools/wiki";
+113
View File
@@ -0,0 +1,113 @@
import type { JSONValue } from "@llamaindex/core/global";
import type { BaseToolWithCall } from "@llamaindex/core/llms";
import { FunctionTool } from "@llamaindex/core/tools";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import {
StdioClientTransport,
type StdioServerParameters,
} from "@modelcontextprotocol/sdk/client/stdio.js";
import type { Tool } from "@modelcontextprotocol/sdk/types.js";
import type { JSONSchemaType } from "ajv";
interface ToolInput {
[key: string]: unknown;
}
type MCPClientOptions = StdioServerParameters & {
/**
* The prefix to add to the tool name
*/
toolNamePrefix?: string;
/**
* The name of the client
*/
clientName?: string;
/**
* The version of the client
*/
clientVersion?: string;
/**
* Whether to log verbose output
*/
verbose?: boolean;
};
class MCPClient {
private mcp: Client;
private transport: StdioClientTransport | null = null;
private verbose: boolean;
private toolNamePrefix?: string | undefined;
constructor(options: MCPClientOptions) {
this.mcp = new Client({
name: options.clientName ?? "mcp-client-cli",
version: options.clientVersion ?? "1.0.0",
});
this.verbose = options.verbose ?? false;
this.toolNamePrefix = options.toolNamePrefix;
this.connectToSever(options);
}
async connectToSever(options: StdioServerParameters) {
if (this.verbose) {
console.log("Connecting to MCP server...");
}
this.transport = new StdioClientTransport(options);
await this.mcp.connect(this.transport);
}
async listTools(): Promise<Tool[]> {
const tools = await this.mcp.listTools();
return tools.tools;
}
async cleanup() {
await this.mcp.close();
this.transport?.close();
}
/**
* Get the tools from the MCP server and map to LlamaIndex tools
*/
async tools(): Promise<BaseToolWithCall[]> {
const mcpTools = await this.listTools();
return mcpTools.map((tool) => {
const parameters =
tool.inputSchema as unknown as JSONSchemaType<ToolInput>;
const functionTool = FunctionTool.from(
async (input: unknown) => {
if (this.verbose) {
console.log("Calling tool:", tool.name, "with input:", input);
}
const result = await this.mcp.callTool({
name: tool.name,
arguments: input as unknown as Record<string, unknown>,
});
if (this.verbose) {
console.log("Tool result:", result);
}
return result as JSONValue;
},
{
name: this.toolNamePrefix
? `${this.toolNamePrefix}_${tool.name}`
: tool.name,
description: tool.description ?? "",
parameters,
},
);
return functionTool;
});
}
}
/**
* Create a MCP client
* @param options - The options for the MCP client
* @returns A MCP client
*/
export function mcp(options: MCPClientOptions) {
return new MCPClient(options);
}
+48
View File
@@ -0,0 +1,48 @@
import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { mcp } from "../src/tools/mcp";
describe("MCP Tools", () => {
let server: ReturnType<typeof mcp>;
let tempDir: string;
beforeAll(async () => {
// Create a temporary directory for tests
tempDir = await mkdtemp(join(tmpdir(), "mcp-test-"));
server = mcp({
command: "npx",
args: ["-y", "@modelcontextprotocol/server-filesystem", tempDir],
toolNamePrefix: "test",
verbose: true,
});
// Wait for server to be ready by calling tools() once
await server.tools();
}, 20000);
afterAll(async () => {
// Clean up server resources
await server.cleanup();
// Remove temporary directory
await rm(tempDir, { recursive: true, force: true });
}, 20000);
test("MCP should list tools", async () => {
const tools = await server.tools();
expect(tools.length).toBeGreaterThan(0);
}, 20000);
test("MCP should call a tool to list files in a directory", async () => {
const tools = await server.tools();
const listDirectoryTool = tools.find(
(tool) => tool.metadata.name === "test_list_directory",
);
const result = await listDirectoryTool?.call({
path: tempDir,
});
expect(result).toBeDefined();
}, 20000);
});
-28
View File
@@ -37,34 +37,6 @@
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./agent": {
"node": {
"types": "./dist/agent/index.d.ts",
"import": "./dist/agent/index.js",
"require": "./dist/agent/index.cjs",
"default": "./dist/agent/index.cjs"
},
"workerd": {
"types": "./dist/agent/index.workerd.d.ts",
"default": "./dist/agent/index.workerd.js"
},
"edge-light": {
"types": "./dist/agent/index.edge-light.d.ts",
"default": "./dist/agent/index.edge-light.js"
},
"browser": {
"types": "./dist/agent/index.browser.d.ts",
"default": "./dist/agent/index.browser.js"
},
"import": {
"types": "./dist/agent/index.d.ts",
"default": "./dist/agent/index.js"
},
"require": {
"types": "./dist/agent/index.d.cts",
"default": "./dist/agent/index.cjs"
}
}
},
"files": [
-10
View File
@@ -50,13 +50,3 @@ export interface BaseWorkflowAgent {
memory: BaseMemory,
): Promise<AgentOutput>;
}
/**
* Parameters for creating an AgentWorkflow
*/
export interface AgentWorkflowParams {
// Using strict typing for optional properties
verbose?: boolean;
timeout?: number;
validate?: boolean;
}
+1
View File
@@ -1,3 +1,4 @@
export * from "./agent-workflow";
export * from "./base";
export * from "./events";
export * from "./function-agent";
+1 -1
View File
@@ -1,4 +1,4 @@
export { type AgentWorkflowContext } from "./agent/base.js";
export * from "./agent/index.js";
export {
WorkflowContext,
type HandlerContext,
+636 -453
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -2,6 +2,7 @@ packages:
- "unit"
- "apps/*"
- "e2e"
- "resolution-tests"
- "e2e/examples/*"
- "packages/*"
- "packages/providers/*"
+23
View File
@@ -0,0 +1,23 @@
{
"name": "@llamaindex/resolution-tests",
"private": true,
"version": "0.0.1",
"type": "module",
"scripts": {
"test": "pnpm run test:node && pnpm run test:node16 && pnpm run test:nodenext && pnpm run test:bundler",
"build": "pnpm run build:node16 && pnpm run build:nodenext && pnpm run build:bundler && pnpm run build:node",
"build:node16": "tsc -p src/tsconfig.node16.json --outDir dist/node16",
"test:node16": "pnpm run build:node16 && node --test dist/node16/index.e2e.js",
"build:nodenext": "tsc -p src/tsconfig.nodenext.json --outDir dist/nodenext",
"test:nodenext": "pnpm run build:nodenext && node --test dist/nodenext/index.e2e.js",
"build:bundler": "tsc -p src/tsconfig.bundler.json --outDir dist/bundler",
"test:bundler": "pnpm run build:bundler && node --test dist/bundler/index.e2e.js",
"build:node": "tsc -p src/tsconfig.node.json --outDir dist/node",
"test:node": "pnpm run build:node && node --test dist/node/index.e2e.js"
},
"devDependencies": {
"@types/node": "^22.9.0",
"llamaindex": "workspace:*",
"zod": "^3.24.2"
}
}
+43
View File
@@ -0,0 +1,43 @@
import { agent, Document, tool } from "llamaindex";
import { ok } from "node:assert";
import { test } from "node:test";
import { z } from "zod";
test("LlamaIndex module resolution test", async (t) => {
await t.test("works with Document class", () => {
const doc = new Document({ text: "This is a test document" });
ok(doc.text === "This is a test document");
const sumNumbers = tool({
name: "sumNumbers",
description: "Use this function to sum two numbers",
parameters: z.object({
a: z.number().describe("The first number"),
b: z.number().describe("The second number"),
}),
execute: ({ a, b }) => `${a + b}`,
});
const myAgent = agent({ tools: [sumNumbers] });
ok(myAgent !== undefined);
});
await t.test("works with dynamic imports", async () => {
const mod = await import("llamaindex"); // simulate commonjs
const doc = new mod.Document({ text: "This is a test document" });
ok(doc.text === "This is a test document");
const sumNumbers = mod.tool({
name: "sumNumbers",
description: "Use this function to sum two numbers",
parameters: z.object({
a: z.number().describe("The first number"),
b: z.number().describe("The second number"),
}),
execute: ({ a, b }) => `${a + b}`,
});
const myAgent = mod.agent({ tools: [sumNumbers] });
ok(myAgent !== undefined);
});
});
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "esnext",
"moduleResolution": "bundler",
"target": "esnext",
"outDir": "dist",
"rootDir": ".",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist"]
}
+14
View File
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "esnext",
"moduleResolution": "node",
"target": "esnext",
"outDir": "dist",
"rootDir": ".",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist"]
}
+14
View File
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "node16",
"moduleResolution": "node16",
"target": "esnext",
"outDir": "dist",
"rootDir": ".",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist"]
}
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "nodenext",
"moduleResolution": "nodenext",
"target": "esnext",
"outDir": "dist",
"rootDir": ".",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist"]
}
+16
View File
@@ -0,0 +1,16 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "./lib",
"module": "node16",
"moduleResolution": "node16",
"target": "ESNext",
"types": ["node"]
},
"include": ["./src"],
"references": [
{
"path": "../packages/llamaindex/tsconfig.json"
}
]
}
+3
View File
@@ -202,6 +202,9 @@
},
{
"path": "./packages/server/tsconfig.json"
},
{
"path": "./resolution-tests/tsconfig.json"
}
]
}
+7
View File
@@ -1,5 +1,12 @@
# @llamaindex/unit-test
## 0.1.16
### Patch Changes
- Updated dependencies [f5e4d09]
- llamaindex@0.9.16
## 0.1.15
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/unit-test",
"private": true,
"version": "0.1.15",
"version": "0.1.16",
"type": "module",
"scripts": {
"test": "vitest run"