Compare commits

..

19 Commits

Author SHA1 Message Date
github-actions[bot] 6d7bc4ccbb Release (#1883)
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-23 17:24:54 +07:00
Huu Le 294f502441 feat: support SSE for MCP tools adapter (#1882) 2025-04-23 15:54:37 +07:00
github-actions[bot] 056594452c Release @llamaindex/readers@3.1.0 (#1880)
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-22 19:14:09 +07:00
Huu Le 1e59695cef Restructure reader packages (#1877)
Co-authored-by: Marcus Schiesser <mail@marcusschiesser.de>
2025-04-22 17:20:08 +07:00
Marcus Schiesser f463efd8a5 docs: fix agentic rag tutorial 2025-04-22 12:13:06 +02:00
Alex Yang cf95af40d9 make docs great again - 2nd time (#1876) 2025-04-21 15:07:16 -07:00
Alex Yang ddc910dc73 docs: no validate links 2025-04-21 12:50:10 -07:00
Alex Yang f12af27760 docs: fix turbo.json 2025-04-21 12:35:31 -07:00
Alex Yang ffdbc8f5e8 docs: disable typedoc 2025-04-21 12:27:08 -07:00
Alex Yang ea8817f7e4 fix(docs): search page id (#1875) 2025-04-21 12:10:42 -07:00
Alex Yang 359698d04b docs: remove links on docs detail page 2025-04-21 09:53:26 -07:00
Huu Le b49fb24948 docs: fix search function on the documentation site is not working. (#1872) 2025-04-21 09:49:48 -07:00
Alex Yang 78841495aa docs: fix meta.json 2025-04-21 09:43:28 -07:00
Alex Yang c81dd21472 chore: bump llama-flow docs 2025-04-21 09:38:14 -07:00
Alex Yang 52868ea0f9 docs: remove llamacloud section (#1851) 2025-04-21 09:37:40 -07:00
Logan e0a730e44e docs: replace with llama-flow docs (#1874)
Co-authored-by: Alex Yang <himself65@outlook.com>
2025-04-21 09:37:27 -07:00
Alex Yang eda486bb52 chore: bump pnpm (#1871) 2025-04-21 09:25:48 -07:00
Alex Yang 10d9c708db ci: enable turbo cache (#1873) 2025-04-21 09:25:38 -07:00
Alex Yang 556027705e chore(docs): fix inputs 2025-04-21 04:13:46 -07:00
82 changed files with 539 additions and 944 deletions
@@ -8,6 +8,11 @@ on:
branches:
- main
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
TURBO_REMOTE_ONLY: true
jobs:
lint:
runs-on: ubuntu-latest
+5
View File
@@ -1,6 +1,11 @@
name: Publish Preview
on: [pull_request]
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
TURBO_REMOTE_ONLY: true
jobs:
pre_release:
name: Pre Release
+7
View File
@@ -1,5 +1,12 @@
# @llamaindex/doc
## 0.2.14
### Patch Changes
- Updated dependencies [1e59695]
- @llamaindex/readers@3.1.0
## 0.2.13
### Patch Changes
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/doc",
"version": "0.2.13",
"version": "0.2.14",
"private": true,
"scripts": {
"postinstall": "fumadocs-mdx",
@@ -15,7 +15,7 @@
"dependencies": {
"@huggingface/transformers": "^3.5.0",
"@icons-pack/react-simple-icons": "^10.1.0",
"@llama-flow/docs": "0.0.3",
"@llama-flow/docs": "0.0.5",
"@llamaindex/chat-ui": "0.2.0",
"@llamaindex/cloud": "workspace:*",
"@llamaindex/core": "workspace:*",
@@ -90,9 +90,9 @@
"remark-stringify": "^11.0.0",
"tailwindcss": "^4.0.9",
"tsx": "^4.19.3",
"typedoc": "0.28.2",
"typedoc": "0.28.3",
"typedoc-plugin-markdown": "^4.6.2",
"typedoc-plugin-merge-modules": "^7.0.0",
"typedoc-plugin-merge-modules": " ^7.0.0",
"typescript": "^5.7.3"
}
}
+12 -16
View File
@@ -1,4 +1,3 @@
import { generateFiles as openapiGenerateFiles } from "fumadocs-openapi";
import {
createGenerator,
generateFiles as typescriptGenerateFiles,
@@ -14,18 +13,12 @@ const apiRefOut = "./src/content/docs/api";
// clean generated files
rimrafSync(out, {
filter(v) {
return !v.endsWith("index.mdx") && !v.endsWith("meta.json");
return !v.endsWith("index.md") && !v.endsWith("meta.json");
},
});
void openapiGenerateFiles({
input: ["../../packages/cloud/openapi.json"],
output: "./src/content/docs/cloud/api",
groupBy: "tag",
});
void typescriptGenerateFiles(generator, {
input: ["./src/content/docs/api/**/*.mdx"],
input: ["./src/content/docs/api/**/*.md"],
output: (file) => path.resolve(path.dirname(file), path.basename(file)),
transformOutput,
});
@@ -34,19 +27,22 @@ function transformOutput(filePath: string, content: string) {
const fileName = path.basename(filePath);
let title = fileName.split(".")[0];
if (title === "index") title = "LlamaIndex API Reference";
return `---\ntitle: ${title}\n---\n\n${transformAbsoluteUrl(content, filePath)}`;
return `---\ntitle: ${title}\n---\n\n${transformAbsoluteUrl(
content.replace(/(?<!\\)\{([^}]+)(?<!\\)}/g, "\\{$1\\}"),
filePath,
)}`;
}
/**
* Transforms the content by converting relative MDX links to absolute docs API links
* Example: [text](../type-aliases/TaskHandler.mdx) -> [text](/docs/api/type-aliases/TaskHandler)
* [text](BaseChatEngine.mdx) -> [text](/docs/api/classes/BaseChatEngine)
* [text](BaseVectorStore.mdx#constructors) -> [text](/docs/api/classes/BaseVectorStore#constructors)
* [text](TaskStep.mdx) -> [text](/docs/api/type-aliases/TaskStep)
* Transforms the content by converting relative MD links to absolute docs API links
* Example: [text](../type-aliases/TaskHandler.md) -> [text](/docs/api/type-aliases/TaskHandler)
* [text](BaseChatEngine.md) -> [text](/docs/api/classes/BaseChatEngine)
* [text](BaseVectorStore.md#constructors) -> [text](/docs/api/classes/BaseVectorStore#constructors)
* [text](TaskStep.md) -> [text](/docs/api/type-aliases/TaskStep)
*/
function transformAbsoluteUrl(content: string, filePath: string) {
const group = path.dirname(filePath).split(path.sep).pop();
return content.replace(/\]\(([^)]+)\.mdx([^)]*)\)/g, (_, slug, anchor) => {
return content.replace(/\]\(([^)]+)\.md([^)]*)\)/g, (_, slug, anchor) => {
const slugParts = slug.split("/");
const fileName = slugParts[slugParts.length - 1];
const fileGroup = slugParts[slugParts.length - 2] ?? group;
+4 -4
View File
@@ -28,14 +28,14 @@ interface RelativeLinkResult {
* Get all valid documentation routes from the content directory
*/
async function getValidRoutes(): Promise<Set<string>> {
const mdxFiles = await glob("**/*.mdx", { cwd: CONTENT_DIR });
const mdxFiles = await glob("**/*.mdx?", { cwd: CONTENT_DIR });
const routes = new Set<string>();
// Add each MDX file as a valid route
for (const file of mdxFiles) {
// Remove .mdx extension and normalize to route format
let route = file.replace(/\.mdx$/, "");
let route = file.replace(/\.mdx?$/, "");
// Handle index files
if (route.endsWith("/index")) {
@@ -131,7 +131,7 @@ function findRelativeLinksInFile(
* Find relative links in all MDX files
*/
async function findRelativeLinks(): Promise<RelativeLinkResult[]> {
const mdxFiles = await glob("**/*.mdx", { cwd: CONTENT_DIR });
const mdxFiles = await glob("**/*.mdx?", { cwd: CONTENT_DIR });
const results: RelativeLinkResult[] = [];
for (const file of mdxFiles) {
@@ -150,7 +150,7 @@ async function findRelativeLinks(): Promise<RelativeLinkResult[]> {
}
async function validateLinks(): Promise<LinkValidationResult[]> {
const mdxFiles = await glob("**/*.mdx", { cwd: CONTENT_DIR });
const mdxFiles = await glob("**/*.mdx?", { cwd: CONTENT_DIR });
const validRoutes = await getValidRoutes();
const results: LinkValidationResult[] = [];
+6 -7
View File
@@ -1,8 +1,10 @@
import { rehypeCodeDefaultOptions } from "fumadocs-core/mdx-plugins";
import {
rehypeCodeDefaultOptions,
remarkStructure,
} from "fumadocs-core/mdx-plugins";
import { fileGenerator, remarkDocGen, remarkInstall } from "fumadocs-docgen";
import { defineConfig, defineDocs } from "fumadocs-mdx/config";
import { transformerTwoslash } from "fumadocs-twoslash";
import { createFileSystemTypesCache } from "fumadocs-twoslash/cache-fs";
import rehypeKatex from "rehype-katex";
import remarkMath from "remark-math";
@@ -24,11 +26,7 @@ export default defineConfig({
},
transformers: [
...(rehypeCodeDefaultOptions.transformers ?? []),
transformerTwoslash({
typesCache: createFileSystemTypesCache({
dir: ".next/cache/twoslash",
}),
}),
transformerTwoslash(),
{
name: "transformers:remove-notation-escape",
code(hast) {
@@ -49,6 +47,7 @@ export default defineConfig({
],
},
remarkPlugins: [
remarkStructure,
remarkMath,
[remarkInstall, { persist: { id: "package-manager" } }],
[remarkDocGen, { generators: [fileGenerator()] }],
+1 -1
View File
@@ -4,7 +4,7 @@ import { createFromSource } from "fumadocs-core/search/server";
// TODO: migrate to another search service, I don't think Vercel can handle that many of documents.
export const { GET } = createFromSource(source, (page) => ({
id: page.url,
id: page.file.path,
title: page.data.title,
description: page.data.description,
url: page.url,
+1
View File
@@ -9,6 +9,7 @@ export default function Layout({ children }: { children: ReactNode }) {
<DocsLayout
tree={source.pageTree}
{...baseOptions}
links={[]}
nav={{
...baseOptions.nav,
}}
+11 -1
View File
@@ -27,9 +27,19 @@ export const baseOptions: BaseLayoutProps = {
githubUrl: "https://github.com/run-llama/LlamaIndexTS",
links: [
{
text: "Docs",
text: "TypeScript",
url: DOCUMENT_URL,
active: "nested-url",
},
{
text: "Python",
url: "https://docs.llamaindex.ai",
active: "url",
},
{
text: "LlamaCloud",
url: "https://docs.cloud.llamaindex.ai/",
active: "url",
},
],
};
+1 -5
View File
@@ -13,11 +13,7 @@ import remarkStringify from "remark-stringify";
export const revalidate = false;
export async function GET() {
const files = await fg([
"./src/content/docs/**/*.mdx",
// remove generated openapi files
"!./src/content/docs/cloud/api/**/*",
]);
const files = await fg(["./src/content/docs/**/*.mdx"]);
const scan = files.map(async (file) => {
const fileContent = await fs.readFile(file);
@@ -1,8 +0,0 @@
---
title: LlamaCloud
description: LlamaCloud is a new generation of managed parsing, ingestion, and retrieval services, designed to bring production-grade context-augmentation to your LLM and RAG applications.
---
This is TypeScript binding for LlamaCloud API. It provides a simple way to interact with LlamaCloud API.
If you are looking for the official documentation, please visit the [Official Document](https://docs.cloud.llamaindex.ai/)
@@ -1,6 +0,0 @@
{
"title": "LlamaCloud",
"description": "The Cloud framework for LLM",
"root": true,
"pages": ["---Guide---", "index", "..."]
}
@@ -57,6 +57,41 @@ const researchAgent = agent({
});
```
## MCP tools
If you have a MCP server running, you can fetch tools from the server and use them in your agents.
```ts
// 1. Import MCP tools adapter
import { mcp } from "@llamaindex/tools";
import { agent } from "llamaindex";
// 2. Initialize a MCP client
// by npx
const server = mcp({
command: "npx",
args: ["-y", "@modelcontextprotocol/server-filesystem", "."],
verbose: true,
});
// or by SSE
const server = mcp({
url: "http://localhost:8000/mcp",
verbose: true,
});
// 3. Get tools from MCP server
const tools = await server.tools();
// Now you can create an agent with the tools
const agent = agent({
name: "My Agent",
systemPrompt: "You are a helpful assistant that can use the provided tools to answer questions.",
llm: openai({ model: "gpt-4o" }),
tools: tools,
});
```
## Function tool
You can still use the `FunctionTool` class to define a tool.
@@ -5,6 +5,12 @@ title: DiscordReader
DiscordReader is a simple data loader that reads all messages in a given Discord channel and returns them as Document objects.
It uses the [@discordjs/rest](https://github.com/discordjs/discord.js/tree/main/packages/rest) library to fetch the messages.
## Installation
```package-install
npm install @llamaindex/discord
```
## Usage
First step is to create a Discord Application and generating a bot token [here](https://discord.com/developers/applications).
@@ -12,7 +18,7 @@ In your Discord Application, go to the `OAuth2` tab and generate an invite URL b
This will invite the bot with the necessary permissions to read messages.
Copy the URL in your browser and select the server you want your bot to join.
<include cwd>../../examples/readers/src/discord.ts</include>
<include cwd>../../examples/discord/reader.ts</include>
### Params
@@ -21,27 +21,18 @@ To install readers call:
We offer readers for different file formats.
```ts twoslash
import { CSVReader } from '@llamaindex/readers/csv'
import { PDFReader } from '@llamaindex/readers/pdf'
import { JSONReader } from '@llamaindex/readers/json'
import { MarkdownReader } from '@llamaindex/readers/markdown'
import { HTMLReader } from '@llamaindex/readers/html'
// you can find more readers in the documentation
```ts twoslash
import { CSVReader } from '@llamaindex/readers/csv';
import { DocxReader } from '@llamaindex/readers/docx';
import { HTMLReader } from '@llamaindex/readers/html';
import { ImageReader } from '@llamaindex/readers/image';
import { JSONReader } from '@llamaindex/readers/json';
import { MarkdownReader } from '@llamaindex/readers/markdown';
import { ObsidianReader } from '@llamaindex/readers/obsidian';
import { PDFReader } from '@llamaindex/readers/pdf';
import { TextFileReader } from '@llamaindex/readers/text';
```
Additionally the following loaders exist without separate documentation:
- `AssemblyAIReader` transcribes audio using [AssemblyAI](https://www.assemblyai.com/).
- [AudioTranscriptReader](/docs/api/classes/AudioTranscriptReader): loads entire transcript as a single document.
- [AudioTranscriptParagraphsReader](/docs/api/classes/AudioTranscriptParagraphsReader): creates a document per paragraph.
- [AudioTranscriptSentencesReader](/docs/api/classes/AudioTranscriptSentencesReader): creates a document per sentence.
- [AudioSubtitlesReader](/docs/api/classes/AudioTranscriptParagraphsReader): creates a document containing the subtitles of a transcript.
- [NotionReader](/docs/api/classes/NotionReader) loads [Notion](https://www.notion.so/) pages.
- [SimpleMongoReader](/docs/api/classes/SimpleMongoReader) loads data from a [MongoDB](https://www.mongodb.com/).
Check the [LlamaIndexTS Github](https://github.com/run-llama/LlamaIndexTS) for the most up to date overview of integrations.
## SimpleDirectoryReader
[Open in StackBlitz](https://stackblitz.com/github/run-llama/LlamaIndexTS/tree/main/examples/readers?file=src/simple-directory-reader.ts&title=Simple%20Directory%20Reader)
@@ -112,6 +112,3 @@ The returned `imageDocs` have the alt text assigned as text and the image path a
You can see the full example file [here](https://github.com/run-llama/LlamaIndexTS/blob/main/examples/readers/src/llamaparse-json.ts).
## API Reference
- [LlamaParseReader](/docs/api/classes/LlamaParseReader)
@@ -32,7 +32,7 @@ They can be divided into two groups.
#### Advanced params:
- `resultType` can be set to `markdown`, `text` or `json`. Defaults to `text`. More information about `json` mode on the next pages.
- `language` primarily helps with OCR recognition. Defaults to `en`. Click [here](/docs/api/type-aliases/Language) for a list of supported languages.
- `language` primarily helps with OCR recognition. Defaults to `en`.
- `parsingInstructions?` Optional. Can help with complicated document structures. See this [LlamaIndex Blog Post](https://www.llamaindex.ai/blog/launching-the-first-genai-native-document-parsing-platform) for an example.
- `skipDiagonalText?` Optional. Set to true to ignore diagonal text. (Text that is not rotated 0, 90, 180 or 270 degrees)
- `invalidateCache?` Optional. Set to true to ignore the LlamaCloud cache. All document are kept in cache for 48hours after the job was completed to avoid processing the same document twice. Can be useful for testing when trying to re-parse the same document with, e.g. different `parsingInstructions`.
@@ -61,4 +61,3 @@ Below a full example of `LlamaParse` integrated in `SimpleDirectoryReader` with
## API Reference
- [SimpleDirectoryReader](/docs/api/classes/SimpleDirectoryReader)
- [LlamaParseReader](/docs/api/classes/LlamaParseReader)
@@ -98,5 +98,4 @@ You can assign any other values of the JSON response to the Document as needed.
## API Reference
- [LlamaParseReader](/docs/api/classes/LlamaParseReader)
- [SimpleDirectoryReader](/docs/api/classes/SimpleDirectoryReader)
@@ -58,25 +58,9 @@ We will convert our text into embeddings using the `VectorStoreIndex` class thro
const index = await VectorStoreIndex.fromDocuments(documents);
```
### Configure a retriever
Before LlamaIndex can send a query to the LLM, it needs to find the most relevant chunks to send. That's the purpose of a `Retriever`. We're going to get `VectorStoreIndex` to act as a retriever for us
```javascript
const retriever = await index.asRetriever();
```
### Configure how many documents to retrieve
By default LlamaIndex will retrieve just the 2 most relevant chunks of text. This document is complex though, so we'll ask for more context.
```javascript
retriever.similarityTopK = 10;
```
### Use index.queryTool
`index.queryTool` creates a `QueryEngineTool` that can be used be an agent to query data from the index.
`index.queryTool` creates a `QueryEngineTool` that can be used be an agent to query data from the index:
```javascript
const tools = [
@@ -85,9 +69,17 @@ const tools = [
name: "san_francisco_budget_tool",
description: `This tool can answer detailed questions about the individual components of the budget of San Francisco in 2023-2024.`,
},
options: { similarityTopK: 10 },
}),
];
```
The `metadata` that we're setting helps the agent to decide when to use the tool.
Note that by default LlamaIndex will retrieve just the 2 most relevant chunks of text. This document is complex though, so we'll ask for more context by setting `similarityTopK` to 10.
Now, we can create an agent using the `QueryEngineTool`:
```javascript
// Create an agent using the tools array
const ragAgent = agent({ tools });
@@ -12,6 +12,7 @@ const tools = [
name: "san_francisco_budget_tool",
description: `This tool can answer detailed questions about the individual components of the budget of San Francisco in 2023-2024.`,
},
options: { similarityTopK: 10 },
}),
tool({
name: "sumNumbers",
@@ -4,7 +4,7 @@
"basic_agent",
"rag",
"agents",
"workflow",
"../../llamaflow",
"local_llm",
"chatbot",
"structured_data_extraction"
@@ -1,224 +0,0 @@
---
title: Inputs / Outputs
description: Learn how to use different inputs and outputs in your workflows.
---
Inputs and outputs are the way to communicate between steps in a workflow. In the previous example,
we used `StartEvent` and `StopEvent` to communicate between steps. However, you can use any type of event to communicate between steps.
## Multiple inputs
You can define multiple inputs for a step.
In the following example, we define a complex workflow with multiple inputs and outputs.
```ts twoslash
import { Workflow, StartEvent, StopEvent, WorkflowEvent } from '@llamaindex/workflow';
class AEvent extends WorkflowEvent<string> {
constructor(data: string) {
super(data);
}
}
class BEvent extends WorkflowEvent<number> {
constructor(data: number) {
super(data);
}
}
class ResultEvent extends WorkflowEvent<string> {
constructor(data: string) {
super(data);
}
}
```
First, let's define the events that we will use in the workflow.
```ts twoslash
import { Workflow, StartEvent, StopEvent, WorkflowEvent } from '@llamaindex/workflow';
class AEvent extends WorkflowEvent<string> {
constructor(data: string) {
super(data);
}
}
class BEvent extends WorkflowEvent<number> {
constructor(data: number) {
super(data);
}
}
class ResultEvent extends WorkflowEvent<string> {
constructor(data: string) {
super(data);
}
}
const workflow = new Workflow<never, string, string>();
workflow.addStep({
inputs: [StartEvent<string>],
outputs: [StopEvent<string>]
}, async (
context,
startEvent
) => {
const input = startEvent.data;
const aEvent = await context.requireEvent(AEvent);
const bEvent = await context.requireEvent(BEvent);
const a = aEvent.data;
const b = bEvent.data;
return new StopEvent(`Hello, ${input}! A: ${a}, B: ${b}`);
});
// ---cut---
workflow.addStep({
inputs: [AEvent, BEvent],
outputs: [ResultEvent]
}, async (
context,
aEvent,
bEvent
) => {
const a = aEvent.data;
const b = bEvent.data;
return new ResultEvent(`A: ${a}, B: ${b}`);
});
```
This step means that it requires two events: `AEvent` and `BEvent`. It will return a `ResultEvent` with the data `A: ${a}, B: ${b}`.
## A or B input
If we want to have a step that can accept either `AEvent` or `BEvent`, we can define the step like this:
```ts twoslash
import { Workflow, StartEvent, StopEvent, WorkflowEvent } from '@llamaindex/workflow';
class AEvent extends WorkflowEvent<string> {
constructor(data: string) {
super(data);
}
}
class BEvent extends WorkflowEvent<number> {
constructor(data: number) {
super(data);
}
}
class ResultEvent extends WorkflowEvent<string> {
constructor(data: string) {
super(data);
}
}
const workflow = new Workflow<never, string, string>();
workflow.addStep({
inputs: [StartEvent<string>],
outputs: [StopEvent<string>]
}, async (
context,
startEvent
) => {
const input = startEvent.data;
const aEvent = await context.requireEvent(AEvent);
const bEvent = await context.requireEvent(BEvent);
const a = aEvent.data;
const b = bEvent.data;
return new StopEvent(`Hello, ${input}! A: ${a}, B: ${b}`);
});
// ---cut---
workflow.addStep({
inputs: [WorkflowEvent.or(AEvent, BEvent)],
outputs: [ResultEvent]
}, async (
context,
aOrBEvent
) => {
if (aOrBEvent instanceof AEvent) {
// ^?
const a = aOrBEvent.data;
// ^?
return new ResultEvent(`A: ${a}`);
} else {
const b = aOrBEvent.data;
// ^?
return new ResultEvent(`B: ${b}`);
}
});
```
This step means that it requires either `AEvent` or `BEvent`. It will return a `ResultEvent` with the data `A: ${a}` or `B: ${b}`.
You can still combine the logic with `context.requireEvent` to get the data from the event.
<Accordions>
<Accordion title="Under the hood">
We use JavaScript Inheritance and the prototype chain to implement the `or` logic.
The `or` method creates a new class that extends the two classes that you pass to it.
<a
target="_blank"
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain"
>
MDN - Inheritance and the prototype chain
</a>
</Accordion>
</Accordions>
## Multiple outputs
You can define multiple outputs for a step.
```ts twoslash
import { Workflow, StartEvent, StopEvent, WorkflowEvent } from '@llamaindex/workflow';
class AEvent extends WorkflowEvent<string> {
constructor(data: string) {
super(data);
}
}
class BEvent extends WorkflowEvent<number> {
constructor(data: number) {
super(data);
}
}
class ResultEvent extends WorkflowEvent<string> {
constructor(data: string) {
super(data);
}
}
const workflow = new Workflow<never, string, string>();
// ---cut---
workflow.addStep({
inputs: [StartEvent<string>],
outputs: [AEvent, BEvent]
}, async (
context,
startEvent
) => {
const input = startEvent.data;
if (Math.random() > 0.5) {
return new AEvent(`Hello, ${input}!`);
} else {
return new BEvent(42);
}
});
```
This step will return either an `AEvent` or a `BEvent` based on a random number.
@@ -1,196 +0,0 @@
---
title: Basic Usage
description: Learn how to use the LlamaIndex workflow.
---
A `Workflow` in LlamaIndex.TS is an event-driven abstraction used to chain together several events.
Workflows are made up of steps, with each step responsible for handling certain event types and emitting new events.
Workflows are designed for any cases that benefit from event-driven programming, not only for LLM and AI tasks.
```package-install
npm i @llamaindex/workflow
```
## Start from scratch
Let's start from a Hello World workflow.
```ts twoslash
import { Workflow } from '@llamaindex/workflow';
type ContextData = {
counter: number;
}
// ---cut---
const contextData: ContextData = { counter: 0 };
const workflow = new Workflow<ContextData, string, string>();
// ^?
```
First, we define a workflow with 3 generic types: `ContextData`, `Input`, and `Output`.
In general, `ContextData` is used to store the shared data between steps, `Input` is the type of the input event, and `Output` is the type of the output event.
In you code logic, you should **share state between steps via `ContextData`**.
```ts twoslash
import { Workflow, StartEvent, StopEvent } from '@llamaindex/workflow';
type ContextData = {
counter: number;
}
const contextData: ContextData = { counter: 0 };
const workflow = new Workflow<ContextData, string, string>();
// ---cut---
workflow.addStep({
inputs: [StartEvent<string>],
outputs: [StopEvent<string>]
}, async (context, startEvent) => {
const input = startEvent.data;
context.data.counter++;
return new StopEvent(`Hello, ${input}!`);
});
```
In the workflow, we add a step that listens to `StartEvent<string>` and emits `StopEvent<string>`.
The step is an async function that takes two arguments: `context` and `event`.
### `context` type
<AutoTypeTable path="./src/deps/type.ts" name="HandlerContext" />
There are two more properties in `HandlerContext`:
- `sendEvent`: invoke another event in the workflow, other than `StartEvent`, `StopEvent`, or the current event. (Or there will have circular reference)
- `requireEvent`: wait for a specific event to be emitted.
You can use `sendEvent` and `requireEvent` to build complex workflows.
```ts twoslash
import { Workflow, StartEvent, StopEvent, WorkflowEvent } from '@llamaindex/workflow';
type ContextData = {
counter: number;
}
const contextData: ContextData = { counter: 0 };
const workflow = new Workflow<ContextData, string, string>();
// ---cut---
class AnalysisStartEvent extends WorkflowEvent<string> {}
class AnalysisStopEvent extends WorkflowEvent<boolean> {}
workflow.addStep({
inputs: [AnalysisStartEvent],
outputs: [AnalysisStopEvent]
}, async (...args) => {
// do some analysis
return new AnalysisStopEvent(true);
})
workflow.addStep({
inputs: [StartEvent<string>],
outputs: [StopEvent<string>]
}, async (context, startEvent) => {
const input = startEvent.data;
context.sendEvent(new AnalysisStartEvent('start'));
context.data.counter++;
const { data } = await context.requireEvent(AnalysisStopEvent);
return new StopEvent(`Hello, ${input}! Analysis result: ${data ? 'success' : 'fail'}`);
});
```
For example, you can compile `requireEvent` with `waitUntil` in [Vercel Functions](https://vercel.com/docs/functions/functions-api-reference#waituntil) or [Cloudflare Worker](https://developers.cloudflare.com/workers/runtime-apis/context/#waituntil)
```ts twoslash
import { waitUntil } from '@vercel/functions';
import { Workflow, StartEvent, StopEvent, WorkflowEvent } from '@llamaindex/workflow';
type ContextData = {
counter: number;
}
const contextData: ContextData = { counter: 0 };
const workflow = new Workflow<ContextData, string, string>();
class AnalysisStartEvent extends WorkflowEvent<string> {}
class AnalysisStopEvent extends WorkflowEvent<boolean> {}
// ---cut---
workflow.addStep({
inputs: [StartEvent<string>],
outputs: [StopEvent<string>]
}, async (context, startEvent) => {
const input = startEvent.data;
context.sendEvent(new AnalysisStartEvent('start'));
context.data.counter++;
waitUntil(context.requireEvent(AnalysisStopEvent));
// note that `waitUntil` is not a promise, it will extend the lifetime of the workflow
// you can wait for some background tasks to finish
return new StopEvent(`Hello, ${input}!`);
});
```
## Multiple runs
You can run the same workflow multiple times with different inputs.
```ts twoslash
import { Workflow, StartEvent, StopEvent } from '@llamaindex/workflow';
type ContextData = {
counter: number;
}
const contextData: ContextData = { counter: 0 };
const workflow = new Workflow<ContextData, string, string>();
workflow.addStep({
inputs: [StartEvent<string>],
outputs: [StopEvent<string>]
}, async (context, startEvent) => {
const input = startEvent.data;
context.data.counter++;
return new StopEvent(`Hello, ${input}!`);
});
// ---cut---
{
const ret = await workflow.run('Alex', contextData);
console.log(ret.data); // Hello, Alex!
}
{
const ret = await workflow.run('World', contextData);
console.log(ret.data); // Hello, World!
}
```
Context is shared between runs, so the counter will be increased.
Ideally, it should be serializable to make sure it can be recovered from HTTP requests or other storage.
### Full example
<iframe
className="w-full h-[440px]"
aria-label="Workflow example"
src="https://stackblitz.com/github/run-llama/LlamaIndexTS/tree/main/examples?file=node/workflow/basic.ts"
/>
## `Workflow` type
<AutoTypeTable path="./src/deps/type.ts" name="Workflow" />
## `WorkflowContext` type
<AutoTypeTable path="./src/deps/type.ts" name="WorkflowContext" />
@@ -1,6 +0,0 @@
{
"title": "Workflow",
"description": "See how to use @llamaindex/workflow",
"defaultOpen": false,
"pages": ["index", "different-inputs-outputs", "streaming"]
}
@@ -1,198 +0,0 @@
---
title: Streaming
description: Learn how to use the LlamaIndex workflow with streaming.
---
`Workflow` API by default is designed for streaming data. In this guide, we will show you how to use the `Workflow` API with streaming data.
Each `workflow.run` call returns `WorkflowContext`, which implements `AsyncIterable` interface. You can use it to stream data.
```ts twoslash
import { Workflow, WorkflowEvent, StartEvent, StopEvent } from '@llamaindex/workflow';
class ComputeEvent extends WorkflowEvent<number> {
constructor(data: number) {
super(data);
}
}
class ComputeResultEvent extends WorkflowEvent<number> {
constructor(data: number) {
super(data);
}
}
type ContextData = {
sum: number;
}
const workflow = new Workflow<ContextData, number, number>();
workflow.addStep({
inputs: [StartEvent<number>],
outputs: [StopEvent<number>]
}, async (context, startEvent) => {
const total = startEvent.data;
for (let i = 0; i < total; i++) {
context.sendEvent(new ComputeEvent(i));
}
const computeResults = await Promise.all(Array.from({ length: total }).map(() => context.requireEvent(ComputeResultEvent)));
// Workflow API allows you to start events in parallel and wait for all of them to finish
context.data.sum = computeResults.reduce((acc, curr) => acc + curr.data, 0);
return new StopEvent(context.data.sum);
});
```
We define a parallel computation workflow that computes the sum of numbers from 0 to `total`.
The workflow sends `ComputeEvent` events for each number and waits for `ComputeResultEvent` events. After receiving all `ComputeResultEvent` events, the workflow returns the sum as a `StopEvent`.
What if we want cutoff if the sum exceeds a certain value?
## Streaming
```ts twoslash
import { Workflow, WorkflowEvent, StartEvent, StopEvent } from '@llamaindex/workflow';
import { StopCircle } from 'lucide-react';
class ComputeEvent extends WorkflowEvent<number> {
constructor(data: number) {
super(data);
}
}
class ComputeResultEvent extends WorkflowEvent<number> {
constructor(data: number) {
super(data);
}
}
type ContextData = {
sum: number;
}
const workflow = new Workflow<ContextData, number, number>();
// ---cut---
const context = workflow.run(1000, {
sum: 0
});
for await (const event of context) {
if (event instanceof ComputeEvent) {
if (context.data.sum > 100) {
throw new Error('Sum exceeds 100');
}
}
if (event instanceof StopEvent) {
console.log('result', event.data);
}
}
```
You can define more custom logic using `AsyncIterable` interface.
For example. I just want to stop the workflow if I get a `ComputeResultEvent`
```ts twoslash
import { Workflow, WorkflowEvent, StartEvent, StopEvent } from '@llamaindex/workflow';
import { StopCircle } from 'lucide-react';
class ComputeEvent extends WorkflowEvent<number> {
constructor(data: number) {
super(data);
}
}
class ComputeResultEvent extends WorkflowEvent<number> {
constructor(data: number) {
super(data);
}
}
type ContextData = {
sum: number;
}
const workflow = new Workflow<ContextData, number, number>();
// ---cut---
async function compute() {
const context = workflow.run(1000, {
sum: 0
});
for await (const event of context) {
if (event instanceof ComputeResultEvent) {
return event.data;
}
}
throw new Error('UNREACHABLE');
}
const result = await compute();
```
### Streaming with UI
You can use the `Workflow` API with UI libraries like React.
```tsx twoslash
// @filename: utils.ts
export async function runWithoutBlocking(fn: () => Promise<void>) {
fn();
}
// @filename: action.ts
// ---cut---
'use server';
// "use server" is required to enable server side feature in React
import { createStreamableUI } from 'ai/rsc';
import { runWithoutBlocking } from './utils';
// ---cut-start---
import { Workflow, WorkflowEvent, StartEvent, StopEvent } from '@llamaindex/workflow';
class ComputeEvent extends WorkflowEvent<number> {
constructor(data: number) {
super(data);
}
}
class ComputeResultEvent extends WorkflowEvent<number> {
constructor(data: number) {
super(data);
}
}
type ContextData = {
sum: number;
}
const workflow = new Workflow<ContextData, number, number>();
const min = 100;
const max = 1000;
workflow.addStep(
{
inputs: [ComputeEvent],
outputs: [ComputeResultEvent]
},
async (context, event) => {
await new Promise((resolve) =>
setTimeout(resolve, Math.floor(Math.random() * (max - min + 1) + min))
);
return new ComputeResultEvent(event.data);
}
);
// ---cut-end---
export async function compute() {
'use server';
const ui = createStreamableUI();
const context = workflow.run(100, {
sum: 0
});
runWithoutBlocking(async () => {
for await (const event of context) {
if (event instanceof ComputeResultEvent) {
// Update UI
} else if (event instanceof StopEvent) {
// Update UI
}
// ...
}
});
return ui.value;
}
```
<WorkflowStreamingDemo />
+1 -1
View File
@@ -1,3 +1,3 @@
{
"pages": ["llamaindex", "llamaflow", "cloud", "api"]
"pages": ["llamaindex", "api"]
}
+9 -2
View File
@@ -3,12 +3,19 @@
"extends": ["//"],
"tasks": {
"build": {
"inputs": [
"node_modules/@llama-flow/docs/**",
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.mdx",
"src/**/*.md"
],
"outputs": [
".next",
".source",
"next-env.d.ts",
"src/content/docs/cloud/api/**",
"src/content/docs/api/**"
"src/content/docs/api/**",
"tsconfig.json"
],
"env": [
"LLAMA_CLOUD_API_KEY",
+2 -4
View File
@@ -2,12 +2,10 @@
"plugin": ["typedoc-plugin-markdown", "typedoc-plugin-merge-modules"],
"entryPoints": [
"../../packages/{,**/}index.ts",
"../../packages/readers/src/*.ts",
"../../packages/cloud/src/{reader,utils}.ts"
"../../packages/readers/src/*.ts"
],
"exclude": [
"../../packages/autotool/**/src/index.ts",
"../../packages/cloud/src/client/index.ts",
"**/node_modules/**",
"**/dist/**",
"**/test/**",
@@ -22,7 +20,7 @@
"categoryOrder": ["Classes", "Enums", "Functions", "Interfaces", "Types"],
"sort": ["source-order"],
"entryFileName": "index.md",
"fileExtension": ".mdx",
"fileExtension": ".md",
"hidePageTitle": true,
"hidePageHeader": true,
"hideGroupHeadings": true,
@@ -1,5 +1,12 @@
# @llamaindex/next-node-runtime
## 0.1.23
### Patch Changes
- Updated dependencies [1e59695]
- @llamaindex/readers@3.1.0
## 0.1.22
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/next-node-runtime-test",
"version": "0.1.22",
"version": "0.1.23",
"private": true,
"scripts": {
"dev": "next dev",
+24
View File
@@ -1,5 +1,29 @@
# examples
## 0.3.11
### Patch Changes
- Updated dependencies [294f502]
- @llamaindex/tools@0.0.6
## 0.3.10
### Patch Changes
- Updated dependencies [1e59695]
- Updated dependencies [1e59695]
- Updated dependencies [1e59695]
- Updated dependencies [1e59695]
- Updated dependencies [1e59695]
- Updated dependencies [1e59695]
- @llamaindex/assemblyai@0.1.1
- @llamaindex/mongodb@0.0.17
- @llamaindex/azure@0.1.12
- @llamaindex/readers@3.1.0
- @llamaindex/notion@0.1.1
- @llamaindex/discord@0.1.1
## 0.3.9
### Patch Changes
+7 -3
View File
@@ -9,6 +9,12 @@ async function main() {
args: ["-y", "@modelcontextprotocol/server-filesystem", "."],
verbose: true,
});
// You can also connect to the MCP server using SSE
// See: https://modelcontextprotocol.io/docs/concepts/transports#server-sent-events-sse
// const server = mcp({
// url: "http://localhost:8000/mcp",
// verbose: true,
// });
try {
// Create an agent that uses the MCP tools
@@ -21,9 +27,7 @@ async function main() {
});
// Run a task
const response = await myAgent.run(
"what are the files in the current directory?",
);
const response = await myAgent.run("What are the available tools?");
console.log("Agent response:", response.data);
} finally {
@@ -1,7 +1,7 @@
import {
AudioTranscriptReader,
TranscribeParams,
} from "@llamaindex/readers/assembly-ai";
} from "@llamaindex/assemblyai";
import { program } from "commander";
import { VectorStoreIndex } from "llamaindex";
import { stdin as input, stdout as output } from "node:process";
+3 -3
View File
@@ -1,11 +1,11 @@
import { CosmosClient } from "@azure/cosmos";
import { DefaultAzureCredential } from "@azure/identity";
import { AzureCosmosDBNoSQLConfig } from "@llamaindex/azure";
import { OpenAI, OpenAIEmbedding } from "@llamaindex/openai";
import {
AzureCosmosDBNoSQLConfig,
SimpleCosmosDBReader,
SimpleCosmosDBReaderLoaderConfig,
} from "@llamaindex/readers/cosmosdb";
} from "@llamaindex/azure";
import { OpenAI, OpenAIEmbedding } from "@llamaindex/openai";
import * as dotenv from "dotenv";
import {
Settings,
@@ -1,4 +1,4 @@
import { DiscordReader } from "@llamaindex/readers/discord";
import { DiscordReader } from "@llamaindex/discord";
async function main() {
// Create an instance of the DiscordReader. Set token here or DISCORD_TOKEN environment variable
+1 -1
View File
@@ -1,4 +1,4 @@
import { SimpleMongoReader } from "@llamaindex/readers/mongo";
import { SimpleMongoReader } from "@llamaindex/mongodb";
import { Document, VectorStoreIndex } from "llamaindex";
import { MongoClient } from "mongodb";
+4 -2
View File
@@ -1,5 +1,7 @@
import { MongoDBAtlasVectorSearch } from "@llamaindex/mongodb";
import { SimpleMongoReader } from "@llamaindex/readers/mongo";
import {
MongoDBAtlasVectorSearch,
SimpleMongoReader,
} from "@llamaindex/mongodb";
import * as dotenv from "dotenv";
import { storageContextFromDefaults, VectorStoreIndex } from "llamaindex";
import { MongoClient } from "mongodb";
@@ -1,4 +1,4 @@
import { NotionReader } from "@llamaindex/readers/notion";
import { NotionReader } from "@llamaindex/notion";
import { Client } from "@notionhq/client";
import { program } from "commander";
import { VectorStoreIndex } from "llamaindex";
@@ -8,8 +8,6 @@ import { createInterface } from "node:readline/promises";
program
.argument("[page]", "Notion page id (must be provided)")
.action(async (page, _options) => {
// Initializing a client
if (!process.env.NOTION_TOKEN) {
console.log(
"No NOTION_TOKEN found in environment variables. You will need to register an integration https://www.notion.com/my-integrations and put it in your NOTION_TOKEN environment variable.",
@@ -64,10 +62,8 @@ program
const documents = await reader.loadData(page);
console.log(documents);
// Split text and create embeddings. Store them in a VectorStoreIndex
const index = await VectorStoreIndex.fromDocuments(documents);
// Create query engine
const queryEngine = index.asQueryEngine();
const rl = createInterface({ input, output });
@@ -80,7 +76,6 @@ program
const response = await queryEngine.query({ query });
// Output response
console.log(response.toString());
}
});
+8 -5
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/examples",
"version": "0.3.9",
"version": "0.3.11",
"private": true,
"scripts": {
"lint": "eslint .",
@@ -13,7 +13,7 @@
"@azure/search-documents": "^12.1.0",
"@llamaindex/anthropic": "^0.3.3",
"@llamaindex/astra": "^0.0.16",
"@llamaindex/azure": "^0.1.11",
"@llamaindex/azure": "^0.1.12",
"@llamaindex/chroma": "^0.0.16",
"@llamaindex/clip": "^0.0.52",
"@llamaindex/cloud": "^4.0.3",
@@ -28,7 +28,7 @@
"@llamaindex/milvus": "^0.1.11",
"@llamaindex/mistral": "^0.1.2",
"@llamaindex/mixedbread": "^0.0.16",
"@llamaindex/mongodb": "^0.0.16",
"@llamaindex/mongodb": "^0.0.17",
"@llamaindex/elastic-search": "^0.1.2",
"@llamaindex/node-parser": "^2.0.2",
"@llamaindex/ollama": "^0.1.2",
@@ -37,7 +37,7 @@
"@llamaindex/portkey-ai": "^0.0.44",
"@llamaindex/postgres": "^0.0.45",
"@llamaindex/qdrant": "^0.1.11",
"@llamaindex/readers": "^3.0.2",
"@llamaindex/readers": "^3.1.0",
"@llamaindex/replicate": "^0.0.44",
"@llamaindex/upstash": "^0.0.16",
"@llamaindex/vercel": "^0.1.2",
@@ -51,9 +51,12 @@
"@llamaindex/jinaai": "^0.0.12",
"@llamaindex/perplexity": "^0.0.9",
"@llamaindex/supabase": "^0.1.1",
"@llamaindex/tools": "^0.0.5",
"@llamaindex/tools": "^0.0.6",
"@notionhq/client": "^2.2.15",
"@pinecone-database/pinecone": "^4.0.0",
"@llamaindex/assemblyai": "^0.1.1",
"@llamaindex/discord": "^0.1.1",
"@llamaindex/notion": "^0.1.1",
"@vercel/postgres": "^0.10.0",
"ai": "^4.0.0",
"ajv": "^8.17.1",
-1
View File
@@ -11,7 +11,6 @@
"start:pdf": "node --import tsx ./src/pdf.ts",
"start:llamaparse": "node --import tsx ./src/llamaparse.ts",
"start:notion": "node --import tsx ./src/notion.ts",
"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:discord": "node --import tsx ./src/discord.ts",
+3 -4
View File
@@ -21,12 +21,14 @@
},
"devDependencies": {
"@changesets/cli": "^2.27.5",
"@eslint/js": "^9.25.0",
"bunchee": "6.4.0",
"eslint": "9.22.0",
"eslint-config-next": "^15.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-turbo": "^2.3.3",
"eslint-plugin-react": "7.37.2",
"eslint-plugin-turbo": "^2.5.0",
"globals": "^15.12.0",
"husky": "^9.1.7",
"lint-staged": "^15.2.11",
@@ -39,7 +41,7 @@
"typescript-eslint": "^8.18.0",
"vitest": "^3.1.1"
},
"packageManager": "pnpm@9.12.3",
"packageManager": "pnpm@10.8.1",
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix",
@@ -48,8 +50,5 @@
"*.{json,md,yml}": [
"prettier --write"
]
},
"dependencies": {
"p-retry": "^6.2.1"
}
}
+3
View File
@@ -63,5 +63,8 @@
"peerDependencies": {
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*"
},
"dependencies": {
"p-retry": "^6.2.1"
}
}
@@ -0,0 +1,7 @@
# @llamaindex/assemblyai
## 0.1.1
### Patch Changes
- 1e59695: Introduce an independent package for assemblyai
@@ -0,0 +1,32 @@
{
"name": "@llamaindex/assemblyai",
"description": "AssemblyAI Reader for LlamaIndex",
"version": "0.1.1",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
"module": "dist/index.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
"directory": "packages/providers/assemblyai"
},
"scripts": {
"build": "bunchee",
"dev": "bunchee --watch"
},
"dependencies": {
"assemblyai": "^4.8.0",
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*"
}
}
@@ -0,0 +1 @@
export * from "./reader";
@@ -0,0 +1,19 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"outDir": "./lib",
"tsBuildInfoFile": "./lib/.tsbuildinfo"
},
"include": ["./src"],
"references": [
{
"path": "../../core/tsconfig.json"
},
{
"path": "../../env/tsconfig.json"
}
]
}
+7
View File
@@ -0,0 +1,7 @@
# @llamaindex/discord
## 0.1.1
### Patch Changes
- 1e59695: Introduce an independent package for discord
+33
View File
@@ -0,0 +1,33 @@
{
"name": "@llamaindex/discord",
"description": "Discord Reader for LlamaIndex",
"version": "0.1.1",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
"module": "dist/index.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
"directory": "packages/providers/discord"
},
"scripts": {
"build": "bunchee",
"dev": "bunchee --watch"
},
"dependencies": {
"@discordjs/rest": "^2.3.0",
"discord-api-types": "^0.37.105",
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*"
}
}
+1
View File
@@ -0,0 +1 @@
export * from "./reader";
@@ -1,4 +1,3 @@
// todo: move to `providers`
import { REST, type RESTOptions } from "@discordjs/rest";
import { Document, type BaseReader } from "@llamaindex/core/schema";
import { getEnv } from "@llamaindex/env";
+19
View File
@@ -0,0 +1,19 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"outDir": "./lib",
"tsBuildInfoFile": "./lib/.tsbuildinfo"
},
"include": ["./src"],
"references": [
{
"path": "../../core/tsconfig.json"
},
{
"path": "../../env/tsconfig.json"
}
]
}
+7
View File
@@ -0,0 +1,7 @@
# @llamaindex/notion
## 0.1.1
### Patch Changes
- 1e59695: Introduce an independent package for notion
+32
View File
@@ -0,0 +1,32 @@
{
"name": "@llamaindex/notion",
"description": "Notion Reader for LlamaIndex",
"version": "0.1.1",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
"module": "dist/index.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
"directory": "packages/providers/notion"
},
"scripts": {
"build": "bunchee",
"dev": "bunchee --watch"
},
"dependencies": {
"notion-md-crawler": "^1.0.0",
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*"
}
}
+1
View File
@@ -0,0 +1 @@
export * from "./reader";
+19
View File
@@ -0,0 +1,19 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"outDir": "./lib",
"tsBuildInfoFile": "./lib/.tsbuildinfo"
},
"include": ["./src"],
"references": [
{
"path": "../../core/tsconfig.json"
},
{
"path": "../../env/tsconfig.json"
}
]
}
@@ -1,5 +1,11 @@
# @llamaindex/azure
## 0.1.12
### Patch Changes
- 1e59695: Add CosmosDB reader
## 0.1.11
### Patch Changes
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/azure",
"description": "Azure Storage for LlamaIndex",
"version": "0.1.11",
"version": "0.1.12",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -7,3 +7,5 @@ export * from "./vectorStore/AzureCosmosDBNoSqlVectorStore.js";
export * from "./vectorStore/AzureQueryResultSearch.js";
export * from "./tools/AzureDynamicSessionTool.node.js";
export * from "./readers/index.js";
@@ -0,0 +1 @@
export * from "./cosmosdb";
@@ -1,10 +1,10 @@
import { CosmosClient } from "@azure/cosmos";
import { Document } from "@llamaindex/core/schema";
import { describe, expect, it, vi } from "vitest";
import {
SimpleCosmosDBReader,
type SimpleCosmosDBReaderLoaderConfig,
} from "@llamaindex/readers/cosmosdb";
import { describe, expect, it, vi } from "vitest";
} from "../src/readers/cosmosdb";
const createMockClient = (mockData?: unknown[]) => {
const client = {
@@ -1,5 +1,11 @@
# @llamaindex/mongodb
## 0.0.17
### Patch Changes
- 1e59695: Add MongoDB reader
## 0.0.16
### Patch Changes
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/mongodb",
"description": "MongoDB Storage for LlamaIndex",
"version": "0.0.16",
"version": "0.0.17",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -1,3 +1,4 @@
export * from "./docStore/MongoDBDocumentStore";
export * from "./kvStore/MongoKVStore";
export * from "./MongoDBAtlasVectorStore";
export * from "./readers/index.js";
@@ -0,0 +1 @@
export * from "./mongo";
@@ -1,4 +1,3 @@
// todo: should move to providers
import type { Metadata } from "@llamaindex/core/schema";
import { type BaseReader, Document } from "@llamaindex/core/schema";
import type { Filter, MongoClient, Document as MongoDocument } from "mongodb";
+6
View File
@@ -1,5 +1,11 @@
# @llamaindex/readers
## 3.1.0
### Minor Changes
- 1e59695: Move MongoDB, CosmosDB, AssemblyAI, Notion, and Discord to their own packages
## 3.0.2
### Patch Changes
-14
View File
@@ -1,14 +0,0 @@
{
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"edge-light": "./dist/index.edge-light.js",
"workerd": "./dist/index.workerd.js",
"default": "./dist/index.js"
}
},
"private": true
}
-14
View File
@@ -1,14 +0,0 @@
{
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"edge-light": "./dist/index.edge-light.js",
"workerd": "./dist/index.workerd.js",
"default": "./dist/index.js"
}
},
"private": true
}
-14
View File
@@ -1,14 +0,0 @@
{
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"edge-light": "./dist/index.edge-light.js",
"workerd": "./dist/index.workerd.js",
"default": "./dist/index.js"
}
},
"private": true
}
-14
View File
@@ -1,14 +0,0 @@
{
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"edge-light": "./dist/index.edge-light.js",
"workerd": "./dist/index.workerd.js",
"default": "./dist/index.js"
}
},
"private": true
}
-14
View File
@@ -1,14 +0,0 @@
{
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"edge-light": "./dist/index.edge-light.js",
"workerd": "./dist/index.workerd.js",
"default": "./dist/index.js"
}
},
"private": true
}
+1 -62
View File
@@ -1,31 +1,11 @@
{
"name": "@llamaindex/readers",
"description": "LlamaIndex Readers",
"version": "3.0.2",
"version": "3.1.0",
"type": "module",
"exports": {
"./node/hook": "./node/dist/hook.js",
"./node": "./node/dist/index.js",
"./assembly-ai": {
"require": {
"types": "./assembly-ai/dist/index.d.cts",
"default": "./assembly-ai/dist/index.cjs"
},
"import": {
"types": "./assembly-ai/dist/index.d.ts",
"default": "./assembly-ai/dist/index.js"
}
},
"./cosmosdb": {
"require": {
"types": "./cosmosdb/dist/index.d.cts",
"default": "./cosmosdb/dist/index.cjs"
},
"import": {
"types": "./cosmosdb/dist/index.d.ts",
"default": "./cosmosdb/dist/index.js"
}
},
"./csv": {
"edge-light": {
"types": "./csv/dist/index.edge-light.d.ts",
@@ -62,16 +42,6 @@
"default": "./directory/dist/index.js"
}
},
"./discord": {
"require": {
"types": "./discord/dist/index.d.cts",
"default": "./discord/dist/index.cjs"
},
"import": {
"types": "./discord/dist/index.d.ts",
"default": "./discord/dist/index.js"
}
},
"./docx": {
"require": {
"types": "./docx/dist/index.d.cts",
@@ -122,26 +92,6 @@
"default": "./markdown/dist/index.js"
}
},
"./mongo": {
"require": {
"types": "./mongo/dist/index.d.cts",
"default": "./mongo/dist/index.cjs"
},
"import": {
"types": "./mongo/dist/index.d.ts",
"default": "./mongo/dist/index.js"
}
},
"./notion": {
"require": {
"types": "./notion/dist/index.d.cts",
"default": "./notion/dist/index.cjs"
},
"import": {
"types": "./notion/dist/index.d.ts",
"default": "./notion/dist/index.js"
}
},
"./obsidian": {
"edge-light": {
"types": "./obsidian/dist/index.edge-light.d.ts",
@@ -182,18 +132,13 @@
}
},
"files": [
"assembly-ai",
"cosmosdb",
"csv",
"directory",
"discord",
"docx",
"html",
"image",
"json",
"markdown",
"mongo",
"notion",
"obsidian",
"pdf",
"text",
@@ -220,15 +165,9 @@
"@llamaindex/env": "workspace:*"
},
"dependencies": {
"@azure/cosmos": "^4.1.1",
"@discordjs/rest": "^2.3.0",
"@discoveryjs/json-ext": "^0.6.1",
"assemblyai": "^4.8.0",
"csv-parse": "^5.5.6",
"discord-api-types": "^0.37.105",
"mammoth": "^1.7.2",
"mongodb": "^6.7.0",
"notion-md-crawler": "^1.0.0",
"unpdf": "^0.12.1"
}
}
+6
View File
@@ -1,5 +1,11 @@
# @llamaindex/tools
## 0.0.6
### Patch Changes
- 294f502: Support SSE for MCP tools adapter
## 0.0.5
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/tools",
"description": "LlamaIndex Tools",
"version": "0.0.5",
"version": "0.0.6",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+35 -6
View File
@@ -2,6 +2,10 @@ 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 {
SSEClientTransport,
type SSEClientTransportOptions,
} from "@modelcontextprotocol/sdk/client/sse.js";
import {
StdioClientTransport,
type StdioServerParameters,
@@ -13,7 +17,7 @@ interface ToolInput {
[key: string]: unknown;
}
type MCPClientOptions = StdioServerParameters & {
type MCPCommonOptions = {
/**
* The prefix to add to the tool name
*/
@@ -32,11 +36,20 @@ type MCPClientOptions = StdioServerParameters & {
verbose?: boolean;
};
type StdioMCPClientOptions = StdioServerParameters & MCPCommonOptions;
type SSEMCPClientOptions = SSEClientTransportOptions &
MCPCommonOptions & {
url: string;
};
type MCPClientOptions = StdioMCPClientOptions | SSEMCPClientOptions;
class MCPClient {
private mcp: Client;
private transport: StdioClientTransport | null = null;
private transport: StdioClientTransport | SSEClientTransport | null = null;
private verbose: boolean;
private toolNamePrefix?: string | undefined;
private connected: boolean = false;
constructor(options: MCPClientOptions) {
this.mcp = new Client({
@@ -46,18 +59,34 @@ class MCPClient {
this.verbose = options.verbose ?? false;
this.toolNamePrefix = options.toolNamePrefix;
this.connectToSever(options);
if ("url" in options) {
this.transport = new SSEClientTransport(
new URL(options.url),
options as SSEClientTransportOptions,
);
} else {
this.transport = new StdioClientTransport(
options as StdioServerParameters,
);
}
this.connected = false;
}
async connectToSever(options: StdioServerParameters) {
async connectToSever() {
if (this.verbose) {
console.log("Connecting to MCP server...");
}
this.transport = new StdioClientTransport(options);
if (!this.transport) {
throw new Error("Initialized with invalid options");
}
await this.mcp.connect(this.transport);
this.connected = true;
}
async listTools(): Promise<Tool[]> {
private async listTools(): Promise<Tool[]> {
if (!this.connected) {
await this.connectToSever();
}
const tools = await this.mcp.listTools();
return tools.tools;
}
+86 -43
View File
@@ -7,14 +7,13 @@ settings:
importers:
.:
dependencies:
p-retry:
specifier: ^6.2.1
version: 6.2.1
devDependencies:
'@changesets/cli':
specifier: ^2.27.5
version: 2.29.1
'@eslint/js':
specifier: ^9.25.0
version: 9.25.0
bunchee:
specifier: 6.4.0
version: 6.4.0(typescript@5.7.3)
@@ -33,6 +32,9 @@ importers:
eslint-plugin-react:
specifier: 7.37.2
version: 7.37.2(eslint@9.22.0(jiti@2.4.2))
eslint-plugin-turbo:
specifier: ^2.5.0
version: 2.5.0(eslint@9.22.0(jiti@2.4.2))(turbo@2.5.0)
globals:
specifier: ^15.12.0
version: 15.15.0
@@ -76,8 +78,8 @@ importers:
specifier: ^10.1.0
version: 10.2.0(react@19.1.0)
'@llama-flow/docs':
specifier: 0.0.3
version: 0.0.3
specifier: 0.0.5
version: 0.0.5
'@llamaindex/chat-ui':
specifier: 0.2.0
version: 0.2.0(@types/react-dom@19.0.4(@types/react@19.0.10))(@types/react@19.0.10)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)
@@ -296,14 +298,14 @@ importers:
specifier: ^4.19.3
version: 4.19.3
typedoc:
specifier: 0.28.2
version: 0.28.2(typescript@5.7.3)
specifier: 0.28.3
version: 0.28.3(typescript@5.7.3)
typedoc-plugin-markdown:
specifier: ^4.6.2
version: 4.6.2(typedoc@0.28.2(typescript@5.7.3))
version: 4.6.2(typedoc@0.28.3(typescript@5.7.3))
typedoc-plugin-merge-modules:
specifier: ^7.0.0
version: 7.0.0(typedoc@0.28.2(typescript@5.7.3))
specifier: ' ^7.0.0'
version: 7.0.0(typedoc@0.28.3(typescript@5.7.3))
typescript:
specifier: ^5.7.3
version: 5.7.3
@@ -609,11 +611,14 @@ importers:
'@llamaindex/anthropic':
specifier: ^0.3.3
version: link:../packages/providers/anthropic
'@llamaindex/assemblyai':
specifier: ^0.1.1
version: link:../packages/providers/assemblyai
'@llamaindex/astra':
specifier: ^0.0.16
version: link:../packages/providers/storage/astra
'@llamaindex/azure':
specifier: ^0.1.11
specifier: ^0.1.12
version: link:../packages/providers/storage/azure
'@llamaindex/chroma':
specifier: ^0.0.16
@@ -636,6 +641,9 @@ importers:
'@llamaindex/deepseek':
specifier: ^0.0.12
version: link:../packages/providers/deepseek
'@llamaindex/discord':
specifier: ^0.1.1
version: link:../packages/providers/discord
'@llamaindex/elastic-search':
specifier: ^0.1.2
version: link:../packages/providers/storage/elastic-search
@@ -670,11 +678,14 @@ importers:
specifier: ^0.0.16
version: link:../packages/providers/mixedbread
'@llamaindex/mongodb':
specifier: ^0.0.16
specifier: ^0.0.17
version: link:../packages/providers/storage/mongodb
'@llamaindex/node-parser':
specifier: ^2.0.2
version: link:../packages/node-parser
'@llamaindex/notion':
specifier: ^0.1.1
version: link:../packages/providers/notion
'@llamaindex/ollama':
specifier: ^0.1.2
version: link:../packages/providers/ollama
@@ -697,7 +708,7 @@ importers:
specifier: ^0.1.11
version: link:../packages/providers/storage/qdrant
'@llamaindex/readers':
specifier: ^3.0.2
specifier: ^3.1.0
version: link:../packages/readers
'@llamaindex/replicate':
specifier: ^0.0.44
@@ -709,7 +720,7 @@ importers:
specifier: ^0.0.12
version: link:../packages/providers/together
'@llamaindex/tools':
specifier: ^0.0.5
specifier: ^0.0.6
version: link:../packages/tools
'@llamaindex/upstash':
specifier: ^0.0.16
@@ -875,6 +886,10 @@ importers:
version: 4.19.3
packages/cloud:
dependencies:
p-retry:
specifier: ^6.2.1
version: 6.2.1
devDependencies:
'@hey-api/client-fetch':
specifier: ^0.6.0
@@ -1096,6 +1111,18 @@ importers:
specifier: ^2.1.5
version: 2.1.5(@edge-runtime/vm@5.0.0)(@types/node@22.14.1)(happy-dom@17.4.4)(lightningcss@1.29.3)(msw@2.7.4(@types/node@22.14.1)(typescript@5.8.3))(terser@5.39.0)
packages/providers/assemblyai:
dependencies:
'@llamaindex/core':
specifier: workspace:*
version: link:../../core
'@llamaindex/env':
specifier: workspace:*
version: link:../../env
assemblyai:
specifier: ^4.8.0
version: 4.9.0(bufferutil@4.0.9)
packages/providers/clip:
dependencies:
'@huggingface/transformers':
@@ -1144,6 +1171,21 @@ importers:
specifier: workspace:*
version: link:../openai
packages/providers/discord:
dependencies:
'@discordjs/rest':
specifier: ^2.3.0
version: 2.4.3
'@llamaindex/core':
specifier: workspace:*
version: link:../../core
'@llamaindex/env':
specifier: workspace:*
version: link:../../env
discord-api-types:
specifier: ^0.37.105
version: 0.37.120
packages/providers/fireworks:
dependencies:
'@llamaindex/env':
@@ -1241,6 +1283,18 @@ importers:
specifier: ^2.2.11
version: 2.2.11
packages/providers/notion:
dependencies:
'@llamaindex/core':
specifier: workspace:*
version: link:../../core
'@llamaindex/env':
specifier: workspace:*
version: link:../../env
notion-md-crawler:
specifier: ^1.0.0
version: 1.0.1
packages/providers/ollama:
dependencies:
'@llamaindex/core':
@@ -1597,33 +1651,15 @@ importers:
packages/readers:
dependencies:
'@azure/cosmos':
specifier: ^4.1.1
version: 4.3.0
'@discordjs/rest':
specifier: ^2.3.0
version: 2.4.3
'@discoveryjs/json-ext':
specifier: ^0.6.1
version: 0.6.3
assemblyai:
specifier: ^4.8.0
version: 4.9.0(bufferutil@4.0.9)
csv-parse:
specifier: ^5.5.6
version: 5.6.0
discord-api-types:
specifier: ^0.37.105
version: 0.37.120
mammoth:
specifier: ^1.7.2
version: 1.9.0
mongodb:
specifier: ^6.7.0
version: 6.7.0(@aws-sdk/credential-providers@3.787.0)(socks@2.8.4)
notion-md-crawler:
specifier: ^1.0.0
version: 1.0.1
unpdf:
specifier: ^0.12.1
version: 0.12.1
@@ -3296,6 +3332,10 @@ packages:
resolution: {integrity: sha512-vLFajx9o8d1/oL2ZkpMYbkLv8nDB6yaIwFNt7nI4+I80U/z03SxmfOMsLbvWr3p7C+Wnoh//aOu2pQW8cS0HCQ==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
'@eslint/js@9.25.0':
resolution: {integrity: sha512-iWhsUS8Wgxz9AXNfvfOPFSW4VfMXdVhp1hjkZVhXCrpgh/aLcc45rX6MPu+tIVUWDw0HfNwth7O28M1xDxNf9w==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
'@eslint/object-schema@2.1.6':
resolution: {integrity: sha512-RBMg5FRL0I0gs51M/guSAj5/e14VQ4tpZnQNWwuDT66P14I43ItmPfIZRhO9fUVIPOAQXU47atlywZ/czoqFPA==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
@@ -3818,8 +3858,8 @@ packages:
zod:
optional: true
'@llama-flow/docs@0.0.3':
resolution: {integrity: sha512-5BFSbaWY7Ps5djzXilgyy9t7OYElyoojvEmLy/FC1azUnn6poIxvr04Ctsoi0PR44sYyqWb7hkuU5iJap6uLyA==}
'@llama-flow/docs@0.0.5':
resolution: {integrity: sha512-iAEqqWgPnJNxm4syNSxudDE1aHYNi1eTrxHg+FjcPeZhxyksLYRzpmzUikcZv0uhxgLwRinF7UPTnH9ioKlaEw==}
'@llamaindex/chat-ui@0.2.0':
resolution: {integrity: sha512-9U5+9l2UVBaOG8fSuMjnere5R2QSNxCEcixMwBgt4L4b0evo8jU4ZzlSxLPunWfpn1PWFVMUwKLlSSwa1qTTyA==}
@@ -10431,6 +10471,7 @@ packages:
node-domexception@1.0.0:
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
engines: {node: '>=10.5.0'}
deprecated: Use your platform's native DOMException instead
node-fetch-native@1.6.6:
resolution: {integrity: sha512-8Mc2HhqPdlIfedsuZoc3yioPuzp6b+L5jRCRY1QzuWZh2EGJVQrGppC6V6cF0bLdbW0+O2YpqCA25aF/1lvipQ==}
@@ -12656,8 +12697,8 @@ packages:
peerDependencies:
typescript: 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x
typedoc@0.28.2:
resolution: {integrity: sha512-9Giuv+eppFKnJ0oi+vxqLM817b/IrIsEMYgy3jj6zdvppAfDqV3d6DXL2vXUg2TnlL62V48th25Zf/tcQKAJdg==}
typedoc@0.28.3:
resolution: {integrity: sha512-5svOCTfXvVSh6zbZKSQluZhR8yN2tKpTeHZxlmWpE6N5vc3R8k/jhg9nnD6n5tN9/ObuQTojkONrOxFdUFUG9w==}
engines: {node: '>= 18', pnpm: '>= 10'}
hasBin: true
peerDependencies:
@@ -15390,6 +15431,8 @@ snapshots:
'@eslint/js@9.22.0': {}
'@eslint/js@9.25.0': {}
'@eslint/object-schema@2.1.6': {}
'@eslint/plugin-kit@0.2.7':
@@ -15914,7 +15957,7 @@ snapshots:
p-retry: 6.2.1
zod: 3.24.2
'@llama-flow/docs@0.0.3': {}
'@llama-flow/docs@0.0.5': {}
'@llamaindex/chat-ui@0.2.0(@types/react-dom@19.0.4(@types/react@19.0.10))(@types/react@19.0.10)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)':
dependencies:
@@ -27172,13 +27215,13 @@ snapshots:
optionalDependencies:
rxjs: 7.8.1
typedoc-plugin-markdown@4.6.2(typedoc@0.28.2(typescript@5.7.3)):
typedoc-plugin-markdown@4.6.2(typedoc@0.28.3(typescript@5.7.3)):
dependencies:
typedoc: 0.28.2(typescript@5.7.3)
typedoc: 0.28.3(typescript@5.7.3)
typedoc-plugin-merge-modules@7.0.0(typedoc@0.28.2(typescript@5.7.3)):
typedoc-plugin-merge-modules@7.0.0(typedoc@0.28.3(typescript@5.7.3)):
dependencies:
typedoc: 0.28.2(typescript@5.7.3)
typedoc: 0.28.3(typescript@5.7.3)
typedoc@0.26.11(typescript@5.7.3):
dependencies:
@@ -27189,7 +27232,7 @@ snapshots:
typescript: 5.7.3
yaml: 2.7.1
typedoc@0.28.2(typescript@5.7.3):
typedoc@0.28.3(typescript@5.7.3):
dependencies:
'@gerrit0/mini-shiki': 3.2.3
lunr: 2.3.9
+7
View File
@@ -1,5 +1,12 @@
# @llamaindex/unit-test
## 0.1.23
### Patch Changes
- Updated dependencies [1e59695]
- @llamaindex/readers@3.1.0
## 0.1.22
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/unit-test",
"private": true,
"version": "0.1.22",
"version": "0.1.23",
"type": "module",
"scripts": {
"test": "vitest run"