chore: replace cloud package with llama-cloud-services (#2145)

Co-authored-by: Thuc Pham <thuc@lingble.com>
This commit is contained in:
Marcus Schiesser
2025-09-15 12:09:17 +08:00
committed by GitHub
parent f648bb7b90
commit d49301555f
69 changed files with 115 additions and 40908 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"llamaindex": minor
---
remove export cloud package from llamaindex
-1
View File
@@ -122,7 +122,6 @@ jobs:
- nextjs-edge-runtime
- nextjs-node-runtime
- waku-query-engine
- llama-parse-browser
- vite-import-llamaindex
runs-on: ubuntu-latest
name: Build LlamaIndex Example (${{ matrix.packages }})
+1 -1
View File
@@ -16,7 +16,7 @@
"@huggingface/transformers": "^3.5.0",
"@icons-pack/react-simple-icons": "^10.1.0",
"@llamaindex/chat-ui-docs": "^0.1.0",
"@llamaindex/cloud": "workspace:*",
"llama-cloud-services": "^0.3.5",
"@llamaindex/core": "workspace:*",
"@llamaindex/node-parser": "workspace:*",
"@llamaindex/openai": "workspace:*",
+1 -1
View File
@@ -1,8 +1,8 @@
import { upsertBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPut } from "@llamaindex/cloud/api";
import fg from "fast-glob";
import { fileGenerator, remarkDocGen, remarkInstall } from "fumadocs-docgen";
import { remarkAutoTypeTable } from "fumadocs-typescript";
import matter from "gray-matter";
import { upsertBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPut } from "llama-cloud-services/api";
import * as fs from "node:fs/promises";
import path, { relative } from "node:path";
import { fileURLToPath } from "node:url";
-109
View File
@@ -1,109 +0,0 @@
import { ClientMDXContent } from "@/components/mdx";
import { BotMessage } from "@/components/message";
import { Skeleton } from "@/components/ui/skeleton";
import { LlamaCloudRetriever } from "@/deps/cloud";
import { ContextChatEngine } from "@llamaindex/core/chat-engine";
import { Settings } from "@llamaindex/core/global";
import { ChatMessage } from "@llamaindex/core/llms";
import { OpenAI } from "@llamaindex/openai";
import { createAI, createStreamableUI, getMutableAIState } from "ai/rsc";
import { ReactNode } from "react";
Settings.llm = new OpenAI({
model: "gpt-4o",
});
const retriever = new LlamaCloudRetriever({
apiKey: process.env.LLAMA_CLOUD_API_KEY!,
baseUrl: "https://api.cloud.llamaindex.ai/",
pipelineId: process.env.LLAMA_CLOUD_PIPELINE_ID!,
});
const initialAIState = {
messages: [],
} as {
messages: ChatMessage[];
};
export type UIMessage = {
id: number;
display: ReactNode;
};
const initialUIState = {
messages: [],
} as {
messages: UIMessage[];
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const runAsyncFnWithoutBlocking = (fn: (...args: any) => Promise<any>) => {
fn().catch((error) => {
console.error(error);
});
};
export const AIProvider = createAI({
initialAIState,
initialUIState,
actions: {
query: async (message: string): Promise<UIMessage> => {
"use server";
const chatEngine = new ContextChatEngine({ retriever });
const id = Date.now();
const aiState = getMutableAIState<typeof AIProvider>();
aiState.update({
...aiState.get(),
messages: [
...aiState.get().messages,
{
role: "user",
content: message,
},
],
});
const ui = createStreamableUI(
<div className="space-y-2">
<Skeleton className="h-4 w-full" />
<Skeleton className="h-4 w-full" />
</div>,
);
runAsyncFnWithoutBlocking(async () => {
const response = await chatEngine.chat({
message,
chatHistory: aiState.get().messages,
stream: true,
});
let content = "";
for await (const { delta } of response) {
content += delta;
ui.update(<ClientMDXContent id={id} content={content} />);
}
ui.done();
aiState.done({
...aiState.get(),
messages: [
...aiState.get().messages,
{
role: "assistant",
content,
},
],
});
});
return {
id,
display: <BotMessage>{ui.value}</BotMessage>,
};
},
},
});
+1 -4
View File
@@ -1,4 +1,3 @@
import { AIProvider } from "@/actions";
import { TooltipProvider } from "@/components/ui/tooltip";
import { GoogleAnalytics, GoogleTagManager } from "@next/third-parties/google";
import { RootProvider } from "fumadocs-ui/provider";
@@ -39,9 +38,7 @@ export default function Layout({ children }: { children: ReactNode }) {
<GoogleTagManager gtmId="GTM-WWRFB36R" />
<body className="flex min-h-screen flex-col">
<TooltipProvider>
<AIProvider>
<RootProvider>{children}</RootProvider>
</AIProvider>
<RootProvider>{children}</RootProvider>
</TooltipProvider>
</body>
<GoogleAnalytics gaId="G-NB9B8LW9W5" />
-143
View File
@@ -1,143 +0,0 @@
"use client";
import type { AIProvider, UIMessage } from "@/actions";
import { UserMessage } from "@/components/message";
import { useActions, useUIState } from "ai/rsc";
import { Info } from "lucide-react";
import { ButtonHTMLAttributes, useState } from "react";
import { Alert, AlertDescription, AlertTitle } from "./ui/alert";
import { Button } from "./ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogOverlay,
DialogPortal,
DialogTitle,
DialogTrigger,
} from "./ui/dialog";
import { Textarea } from "./ui/textarea";
import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
type AITriggerProps = ButtonHTMLAttributes<HTMLButtonElement>;
function ChatList({ messages }: { messages: UIMessage[] }) {
if (messages.length === 0) {
return null;
}
return (
<div className="relative mx-auto w-full px-4">
{messages.map((message, index) => (
<div key={index} className="pb-4">
{message.display}
</div>
))}
</div>
);
}
export const AITrigger = (props: AITriggerProps) => {
const [{ messages }, setUIState] = useUIState<typeof AIProvider>();
const { query } = useActions<typeof AIProvider>();
const [inputValue, setInputValue] = useState("");
return (
<Dialog>
<DialogTrigger {...props} />
<DialogPortal>
<DialogOverlay className="bg-fd-background/50 data-[state=closed]:animate-fd-fade-out data-[state=open]:animate-fd-fade-in fixed inset-0 z-50 backdrop-blur-sm" />
<DialogContent
onOpenAutoFocus={(e) => {
document.getElementById("nd-ai-input")?.focus();
e.preventDefault();
}}
className="bg-fd-popover text-fd-popover-foreground data-[state=closed]:animate-fd-dialog-out data-[state=open]:animate-fd-dialog-in fixed left-1/2 z-50 my-[5vh] flex max-h-[90dvh] w-[98vw] max-w-[860px] origin-left -translate-x-1/2 flex-col rounded-lg border shadow-lg focus-visible:outline-none"
>
<DialogHeader>
<DialogTitle className="sr-only">Search AI</DialogTitle>
<DialogDescription className="sr-only">
Ask AI some questions.
</DialogDescription>
<Alert>
<Info className="size-4" />
<AlertTitle>Heads up!</AlertTitle>
<AlertDescription>
Answers from LlamaCloud may be inaccurate, please use with
discretion.
</AlertDescription>
</Alert>
</DialogHeader>
<div className="mt-4 flex-grow overflow-scroll">
<ChatList messages={messages} />
</div>
<form
className="space-y-4 px-4 py-2"
action={async () => {
const value = inputValue.trim();
setInputValue("");
if (!value) return;
// Add user message UI
setUIState((state) => ({
...state,
messages: [
...state.messages,
{
id: Date.now(),
display: <UserMessage>{value}</UserMessage>,
},
],
}));
try {
// Submit and get response message
const responseMessage = await query(value);
setUIState((state) => ({
...state,
messages: [...state.messages, responseMessage],
}));
} catch (error) {
// You may want to show a toast or trigger an error state.
console.error(error);
}
}}
>
<div className="flex w-full flex-row items-center gap-2">
<Textarea
tabIndex={0}
placeholder="Ask AI about documentation."
className="w-full resize-none bg-transparent px-4 focus-within:outline-none sm:text-sm"
onKeyDown={(event) => {
if (event.key === "Enter" && !event.shiftKey) {
event.preventDefault();
event.currentTarget.form?.requestSubmit(null);
}
}}
autoFocus
spellCheck={false}
autoComplete="off"
autoCorrect="off"
name="message"
rows={1}
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
/>
<Tooltip>
<TooltipTrigger asChild>
<Button
type="submit"
size="icon"
disabled={inputValue === ""}
>
<span className="sr-only">Send message</span>
</Button>
</TooltipTrigger>
<TooltipContent>Send message</TooltipContent>
</Tooltip>
</div>
</form>
</DialogContent>
</DialogPortal>
</Dialog>
);
};
@@ -38,7 +38,8 @@ Here's how to create a simple vector store index and query it using Vercel's AI
import { openai } from "@ai-sdk/openai";
import { llamaindex } from "@llamaindex/vercel";
import { streamText } from "ai";
import { Document, VectorStoreIndex } from "llamaindex";
import { Document } from "llamaindex";
import { LlamaCloudIndex } from "llama-cloud-services";
// Create an index from your documents
const document = new Document({ text: yourText, id_: "unique-id" });
@@ -69,7 +70,7 @@ streamText({
For production deployments, you can use LlamaCloud to store and manage your documents:
```typescript
import { LlamaCloudIndex } from "@llamaindex/cloud";
import { LlamaCloudIndex } from "llama-cloud-services";
// Create a LlamaCloud index
const index = await LlamaCloudIndex.fromDocuments({
@@ -28,5 +28,4 @@ Here's an example of how to use a managed index together with a chat engine:
## API Reference
- [LlamaCloudIndex](/docs/api/classes/LlamaCloudIndex)
- [LlamaCloudRetriever](/docs/api/classes/LlamaCloudRetriever)
- [LlamaCloud Documentation](https://docs.cloud.llamaindex.ai/)
@@ -78,7 +78,7 @@ As the `PDFReader` is not working with the Edge runtime, here's how to use the `
```typescript
import { SimpleDirectoryReader } from "@llamaindex/readers/directory";
import { LlamaParseReader } from "@llamaindex/cloud";
import { LlamaParseReader } from "llama-cloud-services";
export const DATA_DIR = "./data";
@@ -7,7 +7,7 @@ LlamaParse `json` mode supports extracting any images found in a page object by
## Installation
```package-install
npm i llamaindex @llamaindex/cloud @llamaindex/openai
npm i llamaindex llama-cloud-services @llamaindex/openai
```
## Usage
@@ -26,7 +26,7 @@ You can create an index across both text and image nodes by requesting alternati
```ts
import { Document, ImageNode, VectorStoreIndex } from "llamaindex";
import { LlamaParseReader } from "@llamaindex/cloud";
import { LlamaParseReader } from "llama-cloud-services";
import { OpenAI } from "@llamaindex/openai";
import { createMessageContent } from "llamaindex";
@@ -7,7 +7,7 @@ In JSON mode, LlamaParse will return a data structure representing the parsed ob
## Installation
```package-install
npm i llamaindex @llamaindex/cloud
npm i llamaindex llama-cloud-services
```
## Usage
@@ -16,7 +16,7 @@ For Json mode, you need to use `loadJson`. The `resultType` is automatically set
More information about indexing the results on the next page.
```ts
import { LlamaParseReader } from "@llamaindex/cloud";
import { LlamaParseReader } from "llama-cloud-services";
const reader = new LlamaParseReader();
async function main() {
@@ -68,7 +68,7 @@ However, a simple work around is to create a new reader class that extends `Llam
```ts
import { Document } from "llamaindex";
import { LlamaParseReader } from "@llamaindex/cloud";
import { LlamaParseReader } from "llama-cloud-services";
class LlamaParseReaderWithJson extends LlamaParseReader {
// Override the loadData method
@@ -4,7 +4,6 @@ title: Retriever
A retriever in LlamaIndex is what is used to fetch `Node`s from an index using a query string.
- [LlamaCloudRetriever](/docs/api/classes/LlamaCloudRetriever) to retrieve nodes from a [managed index](/docs/llamaindex/modules/data/data_index/managed)
- [VectorIndexRetriever](/docs/api/classes/VectorIndexRetriever) will fetch the top-k most similar nodes. Ideal for dense retrieval to find most relevant nodes.
- [SummaryIndexRetriever](/docs/api/classes/SummaryIndexRetriever) will fetch all nodes no matter the query. Ideal when complete context is necessary, e.g. analyzing large datasets.
- [SummaryIndexLLMRetriever](/docs/api/classes/SummaryIndexLLMRetriever) utilizes an LLM to score and filter nodes based on relevancy to the query.
-96
View File
@@ -1,96 +0,0 @@
import {
type MetadataFilter,
type MetadataFilters,
type RetrievalParams,
runSearchApiV1PipelinesPipelineIdRetrievePost,
type TextNodeWithScore,
} from "@llamaindex/cloud/api";
import { QueryBundle } from "@llamaindex/core/query-engine";
import { BaseRetriever } from "@llamaindex/core/retriever";
import { jsonToNode, NodeWithScore, ObjectType } from "@llamaindex/core/schema";
import { extractText } from "@llamaindex/core/utils";
export type CloudRetrieveParams = Omit<
RetrievalParams,
"query" | "search_filters" | "dense_similarity_top_k"
> & { similarityTopK?: number; filters?: MetadataFilters };
export type LlamaCloudRetrieverParams = {
apiKey: string;
baseUrl: string;
pipelineId: string;
} & CloudRetrieveParams;
export class LlamaCloudRetriever extends BaseRetriever {
baseUrl: string;
apiKey: string;
retrieveParams: CloudRetrieveParams;
organizationId?: string;
pipelineId: string;
private resultNodesToNodeWithScore(
nodes: TextNodeWithScore[],
): NodeWithScore[] {
return nodes.map((node: TextNodeWithScore) => {
const textNode = jsonToNode(node.node, ObjectType.TEXT);
textNode.metadata = {
...textNode.metadata,
...node.node.extra_info,
};
return {
node: textNode,
score: node.score ?? undefined,
};
});
}
private convertFilter(filters?: MetadataFilters): MetadataFilters | null {
if (!filters) return null;
const processFilter = (
filter: MetadataFilter | MetadataFilters,
): MetadataFilter | MetadataFilters => {
if ("filters" in filter) {
// type MetadataFilters
return { ...filter, filters: filter.filters.map(processFilter) };
}
return { ...filter, value: filter.value ?? null };
};
return { ...filters, filters: filters.filters.map(processFilter) };
}
constructor(params: LlamaCloudRetrieverParams) {
super();
this.baseUrl = params.baseUrl;
this.apiKey = params.apiKey;
this.retrieveParams = params;
this.pipelineId = params.pipelineId;
}
override async _retrieve(query: QueryBundle): Promise<NodeWithScore[]> {
const filters = this.convertFilter(this.retrieveParams.filters);
const pipelineId = this.pipelineId;
const { data: results } =
await runSearchApiV1PipelinesPipelineIdRetrievePost({
throwOnError: true,
path: {
pipeline_id: pipelineId,
},
baseUrl: this.baseUrl,
body: {
...this.retrieveParams,
query: extractText(query),
search_filters: filters,
dense_similarity_top_k: this.retrieveParams.similarityTopK!,
},
headers: {
authorization: `Bearer ${this.apiKey}`,
},
});
return this.resultNodesToNodeWithScore(results.retrieval_nodes);
}
}
@@ -1,24 +0,0 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
@@ -1,563 +0,0 @@
# @llamaindex/llama-parse-browser-test
## 0.0.87
### Patch Changes
- @llamaindex/cloud@4.1.3
## 0.0.86
### Patch Changes
- @llamaindex/cloud@4.1.2
## 0.0.85
### Patch Changes
- Updated dependencies [4b51791]
- @llamaindex/cloud@4.1.1
## 0.0.84
### Patch Changes
- Updated dependencies [049471b]
- @llamaindex/cloud@4.1.0
## 0.0.83
### Patch Changes
- Updated dependencies [c3bf3c7]
- @llamaindex/cloud@4.0.28
## 0.0.82
### Patch Changes
- @llamaindex/cloud@4.0.27
## 0.0.81
### Patch Changes
- @llamaindex/cloud@4.0.26
## 0.0.80
### Patch Changes
- Updated dependencies [2967d57]
- @llamaindex/cloud@4.0.25
## 0.0.79
### Patch Changes
- @llamaindex/cloud@4.0.24
## 0.0.78
### Patch Changes
- Updated dependencies [a1b1598]
- @llamaindex/cloud@4.0.23
## 0.0.77
### Patch Changes
- Updated dependencies [d2be868]
- @llamaindex/cloud@4.0.22
## 0.0.76
### Patch Changes
- Updated dependencies [579ca0c]
- @llamaindex/cloud@4.0.21
## 0.0.75
### Patch Changes
- Updated dependencies [48b0d88]
- Updated dependencies [f185772]
- @llamaindex/cloud@4.0.20
## 0.0.74
### Patch Changes
- Updated dependencies [5a0ed1f]
- Updated dependencies [5a0ed1f]
- @llamaindex/cloud@4.0.19
## 0.0.73
### Patch Changes
- Updated dependencies [47a7555]
- @llamaindex/cloud@4.0.18
## 0.0.72
### Patch Changes
- @llamaindex/cloud@4.0.17
## 0.0.71
### Patch Changes
- @llamaindex/cloud@4.0.16
## 0.0.70
### Patch Changes
- @llamaindex/cloud@4.0.15
## 0.0.69
### Patch Changes
- @llamaindex/cloud@4.0.14
## 0.0.68
### Patch Changes
- @llamaindex/cloud@4.0.13
## 0.0.67
### Patch Changes
- @llamaindex/cloud@4.0.12
## 0.0.66
### Patch Changes
- Updated dependencies [76ff23d]
- @llamaindex/cloud@4.0.11
## 0.0.65
### Patch Changes
- @llamaindex/cloud@4.0.10
## 0.0.64
### Patch Changes
- Updated dependencies [3703f90]
- @llamaindex/cloud@4.0.9
## 0.0.63
### Patch Changes
- @llamaindex/cloud@4.0.8
## 0.0.62
### Patch Changes
- Updated dependencies [40f5f41]
- @llamaindex/cloud@4.0.7
## 0.0.61
### Patch Changes
- @llamaindex/cloud@4.0.6
## 0.0.60
### Patch Changes
- Updated dependencies [2225ffd]
- @llamaindex/cloud@4.0.5
## 0.0.59
### Patch Changes
- @llamaindex/cloud@4.0.4
## 0.0.58
### Patch Changes
- Updated dependencies [41191d0]
- @llamaindex/cloud@4.0.3
## 0.0.57
### Patch Changes
- @llamaindex/cloud@4.0.2
## 0.0.56
### Patch Changes
- @llamaindex/cloud@4.0.1
## 0.0.55
### Patch Changes
- Updated dependencies [bf56fc0]
- Updated dependencies [5189b44]
- @llamaindex/cloud@4.0.0
## 0.0.54
### Patch Changes
- @llamaindex/cloud@3.0.9
## 0.0.53
### Patch Changes
- @llamaindex/cloud@3.0.8
## 0.0.52
### Patch Changes
- @llamaindex/cloud@3.0.7
## 0.0.51
### Patch Changes
- @llamaindex/cloud@3.0.6
## 0.0.50
### Patch Changes
- @llamaindex/cloud@3.0.5
## 0.0.49
### Patch Changes
- @llamaindex/cloud@3.0.4
## 0.0.48
### Patch Changes
- @llamaindex/cloud@3.0.3
## 0.0.47
### Patch Changes
- Updated dependencies [c902fcb]
- @llamaindex/cloud@3.0.2
## 0.0.46
### Patch Changes
- @llamaindex/cloud@3.0.1
## 0.0.45
### Patch Changes
- @llamaindex/cloud@3.0.0
## 0.0.44
### Patch Changes
- Updated dependencies [1c908fd]
- @llamaindex/cloud@2.0.24
## 0.0.43
### Patch Changes
- Updated dependencies [cb608b5]
- @llamaindex/cloud@2.0.23
## 0.0.42
### Patch Changes
- Updated dependencies [d6c270e]
- @llamaindex/cloud@2.0.22
## 0.0.41
### Patch Changes
- Updated dependencies [5dec9f9]
- Updated dependencies [fd9c829]
- @llamaindex/cloud@2.0.21
## 0.0.40
### Patch Changes
- Updated dependencies [012495b]
- @llamaindex/cloud@2.0.20
## 0.0.39
### Patch Changes
- @llamaindex/cloud@2.0.19
## 0.0.38
### Patch Changes
- @llamaindex/cloud@2.0.18
## 0.0.37
### Patch Changes
- @llamaindex/cloud@2.0.17
## 0.0.36
### Patch Changes
- Updated dependencies [8be4589]
- @llamaindex/cloud@2.0.16
## 0.0.35
### Patch Changes
- @llamaindex/cloud@2.0.15
## 0.0.34
### Patch Changes
- @llamaindex/cloud@2.0.14
## 0.0.33
### Patch Changes
- Updated dependencies [90d265c]
- @llamaindex/cloud@2.0.13
## 0.0.32
### Patch Changes
- @llamaindex/cloud@2.0.12
## 0.0.31
### Patch Changes
- @llamaindex/cloud@2.0.11
## 0.0.30
### Patch Changes
- @llamaindex/cloud@2.0.10
## 0.0.29
### Patch Changes
- @llamaindex/cloud@2.0.9
## 0.0.28
### Patch Changes
- @llamaindex/cloud@2.0.8
## 0.0.27
### Patch Changes
- @llamaindex/cloud@2.0.7
## 0.0.26
### Patch Changes
- @llamaindex/cloud@2.0.6
## 0.0.25
### Patch Changes
- @llamaindex/cloud@2.0.5
## 0.0.24
### Patch Changes
- @llamaindex/cloud@2.0.4
## 0.0.23
### Patch Changes
- @llamaindex/cloud@2.0.3
## 0.0.22
### Patch Changes
- @llamaindex/cloud@2.0.2
## 0.0.21
### Patch Changes
- @llamaindex/cloud@2.0.1
## 0.0.20
### Patch Changes
- @llamaindex/cloud@2.0.0
## 0.0.19
### Patch Changes
- @llamaindex/cloud@1.0.8
## 0.0.18
### Patch Changes
- @llamaindex/cloud@1.0.7
## 0.0.17
### Patch Changes
- @llamaindex/cloud@1.0.6
## 0.0.16
### Patch Changes
- @llamaindex/cloud@1.0.5
## 0.0.15
### Patch Changes
- Updated dependencies [06f632b]
- @llamaindex/cloud@1.0.4
## 0.0.14
### Patch Changes
- @llamaindex/cloud@1.0.3
## 0.0.13
### Patch Changes
- @llamaindex/cloud@1.0.2
## 0.0.12
### Patch Changes
- Updated dependencies [4c38c1b]
- Updated dependencies [24d065f]
- Updated dependencies [a75af83]
- @llamaindex/cloud@1.0.1
## 0.0.11
### Patch Changes
- @llamaindex/cloud@1.0.0
## 0.0.10
### Patch Changes
- @llamaindex/cloud@0.2.14
## 0.0.9
### Patch Changes
- @llamaindex/cloud@0.2.13
## 0.0.8
### Patch Changes
- @llamaindex/cloud@0.2.12
## 0.0.7
### Patch Changes
- Updated dependencies [0b20ff9]
- @llamaindex/cloud@0.2.11
## 0.0.6
### Patch Changes
- Updated dependencies [981811e]
- @llamaindex/cloud@0.2.10
## 0.0.5
### Patch Changes
- Updated dependencies [df441e2]
- @llamaindex/cloud@0.2.9
## 0.0.4
### Patch Changes
- Updated dependencies [ac41ed3]
- @llamaindex/cloud@0.2.8
## 0.0.3
### Patch Changes
- Updated dependencies [fb36eff]
- Updated dependencies [d24d3d1]
- @llamaindex/cloud@0.2.7
## 0.0.2
### Patch Changes
- Updated dependencies [b42adeb]
- @llamaindex/cloud@0.2.6
## 0.0.1
### Patch Changes
- Updated dependencies [85c2e19]
- @llamaindex/cloud@0.2.5
-111
View File
@@ -1,111 +0,0 @@
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with the LlamaParse Browser Test example.
## Package Overview
The `@llamaindex/llama-parse-browser-test` package is a minimal browser-based example that demonstrates how to use LlamaParse (from `@llamaindex/cloud`) in a web browser environment. This serves as both an integration test and a reference implementation for browser compatibility with LlamaIndexTS cloud services.
## Purpose
This example validates that:
- `@llamaindex/cloud` package works correctly in browser environments
- LlamaParse functionality can be bundled and run in web applications
- The build process properly handles WASM dependencies and browser-specific requirements
- TypeScript compilation works with DOM APIs and modern bundler tooling
## Development Commands
- `npm run dev` - Start Vite development server with hot reload
- `npm run build` - Build for production (TypeScript compilation + Vite build)
- `npm run preview` - Preview the production build locally
## Architecture
### Build Setup
**Bundler**: Vite 6.x with TypeScript support
**WASM Support**: Uses `vite-plugin-wasm` for WebAssembly module handling
**Module System**: ESM-only (`"type": "module"`)
**Target Environment**: Modern browsers (ES2020+)
### Key Configuration
**Vite Config (`vite.config.ts`):**
- `vite-plugin-wasm` - Enables WASM module imports
- `ssr.external: ["tiktoken"]` - Excludes tiktoken from SSR bundling (browser-only)
**TypeScript Config (`tsconfig.json`):**
- Extends root monorepo TypeScript configuration
- DOM and DOM.Iterable libraries enabled for browser APIs
- Bundler module resolution for optimal Vite integration
- References `@llamaindex/cloud` package for type checking
### Application Structure
**Entry Point (`src/main.ts`):**
- Imports `LlamaParseReader` from `@llamaindex/cloud`
- Instantiates the reader to test browser compatibility
- Minimal DOM manipulation for visual feedback
**Styling (`src/style.css`):**
- Modern CSS with light/dark theme support
- Responsive design with flexbox layout
- Clean, minimal UI suitable for testing environment
**HTML (`index.html`):**
- Standard Vite HTML template
- Single-page application structure
- Module script loading for ES6 imports
## Dependencies
**Core Dependency:**
- `@llamaindex/cloud` (workspace) - LlamaCloud integration including LlamaParse
**Development Dependencies:**
- `vite` - Modern build tool and development server
- `vite-plugin-wasm` - WebAssembly support for Vite
- `typescript` - TypeScript compiler and language support
## Testing Integration
This example functions as an end-to-end test by:
1. **Import Validation**: Verifies `@llamaindex/cloud` can be imported in browser context
2. **Instantiation Testing**: Tests that `LlamaParseReader` can be created without errors
3. **Bundle Compatibility**: Ensures the build process handles all dependencies correctly
4. **Runtime Verification**: Validates the application loads and runs in actual browsers
## Browser Compatibility
The application targets modern browsers with:
- ES2020 language features
- ES Modules support
- WebAssembly support (for potential WASM dependencies)
- Modern DOM APIs
## Development Notes
- **Minimal Implementation**: Keeps the example simple to focus on integration testing
- **Cloud Service Focus**: Specifically tests browser compatibility with LlamaCloud services
- **Build Validation**: Ensures the build process works end-to-end without browser-specific issues
- **WASM Preparation**: Configured for WASM dependencies even if not currently used
- **Type Safety**: Full TypeScript integration with proper DOM type definitions
## Common Issues
- **WASM Loading**: The `vite-plugin-wasm` handles WebAssembly module loading complexities
- **SSR Exclusions**: Tiktoken is excluded from SSR to prevent Node.js-specific dependencies in browser builds
- **Module Resolution**: Uses bundler module resolution for optimal compatibility with modern web tooling
This example serves as a foundation for integrating LlamaIndexTS cloud services into web applications and validates that the core cloud functionality works correctly in browser environments.
@@ -1,13 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
@@ -1,19 +0,0 @@
{
"name": "@llamaindex/llama-parse-browser-test",
"private": true,
"version": "0.0.87",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"devDependencies": {
"typescript": "^5.8.3",
"vite": "^6.3.6",
"vite-plugin-wasm": "^3.4.1"
},
"dependencies": {
"@llamaindex/cloud": "workspace:*"
}
}
@@ -1,10 +0,0 @@
import { LlamaParseReader } from "@llamaindex/cloud";
import "./style.css";
new LlamaParseReader();
document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
<div>
Hello, world!
</div>
`;
@@ -1,96 +0,0 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vanilla:hover {
filter: drop-shadow(0 0 2em #3178c6aa);
}
.card {
padding: 2em;
}
.read-the-docs {
color: #888;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
-1
View File
@@ -1 +0,0 @@
/// <reference types="vite/client" />
@@ -1,26 +0,0 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"references": [
{
"path": "../../../packages/cloud/tsconfig.json"
}
]
}
@@ -1,8 +0,0 @@
import wasm from "vite-plugin-wasm";
export default {
plugins: [wasm()],
ssr: {
external: ["tiktoken"],
},
};
+2 -1
View File
@@ -1,7 +1,8 @@
import { stdin as input, stdout as output } from "node:process";
import readline from "node:readline/promises";
import { ContextChatEngine, LlamaCloudIndex } from "llamaindex";
import { LlamaCloudIndex } from "llama-cloud-services";
import { ContextChatEngine } from "llamaindex";
async function main() {
const index = new LlamaCloudIndex({
+2 -1
View File
@@ -4,7 +4,8 @@ import { stdin as input, stdout as output } from "node:process";
import readline from "node:readline/promises";
import { Document, LlamaCloudIndex } from "llamaindex";
import { LlamaCloudIndex } from "llama-cloud-services";
import { Document } from "llamaindex";
async function main() {
const path = "node_modules/llamaindex/examples/abramov.txt";
+1 -1
View File
@@ -1,7 +1,7 @@
import { stdin as input, stdout as output } from "node:process";
import readline from "node:readline/promises";
import { LlamaCloudIndex } from "llamaindex";
import { LlamaCloudIndex } from "llama-cloud-services";
async function main() {
const index = new LlamaCloudIndex({
+2 -1
View File
@@ -1,7 +1,8 @@
import { openai } from "@ai-sdk/openai";
import { llamaindex } from "@llamaindex/vercel";
import { stepCountIs, streamText } from "ai";
import { Document, LlamaCloudIndex } from "llamaindex";
import { LlamaCloudIndex } from "llama-cloud-services";
import { Document } from "llamaindex";
import fs from "node:fs/promises";
async function main() {
+1 -1
View File
@@ -18,7 +18,7 @@
"@llamaindex/bm25-retriever": "^0.0.10",
"@llamaindex/chroma": "^0.0.35",
"@llamaindex/clip": "^0.0.75",
"@llamaindex/cloud": "^4.1.3",
"llama-cloud-services": "^0.3.5",
"@llamaindex/cohere": "^0.0.35",
"@llamaindex/core": "^0.6.21",
"@llamaindex/deepinfra": "^0.0.75",
-4
View File
@@ -9,10 +9,7 @@
"start:html": "node --import tsx ./src/html.ts",
"start:markdown": "node --import tsx ./src/markdown.ts",
"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: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",
"start:json": "node --import tsx ./src/json.ts",
"start:obsidian": "node --import tsx ./src/obsidian.ts",
@@ -20,7 +17,6 @@
"start:excel": "node --import tsx ./src/excel.ts"
},
"dependencies": {
"@llamaindex/cloud": "workspace:* || ^2.0.24",
"@llamaindex/excel": "workspace:*",
"@llamaindex/readers": "workspace:* || ^1.0.25",
"@notionhq/client": "^4.0.0",
-52
View File
@@ -1,52 +0,0 @@
import { Language, LlamaParseReader } from "@llamaindex/cloud";
import fs from "node:fs";
import path from "node:path";
type LlamaParseReaderParams = Partial<
Omit<LlamaParseReader, "language" | "apiKey">
> & {
language?: Language | Language[] | undefined;
apiKey?: string | undefined;
};
async function main() {
const filePath = "../data/pto_policy_employee.docx";
if (!fs.existsSync(filePath)) {
console.error(`File ${filePath} does not exist`);
process.exit(1);
} else {
console.log(`File ${filePath} exists`);
}
const params: LlamaParseReaderParams = {
verbose: true,
parsingInstruction:
"Extract the text from the document a long with any images and tables. This is a document for a course and the contents of the images are important.",
fastMode: false,
gpt4oMode: true,
useVendorMultimodalModel: true,
vendorMultimodalModelName: "anthropic-sonnet-3.5",
premiumMode: true,
resultType: "markdown",
apiKey: process.env.LLAMA_CLOUD_API_KEY,
doNotCache: true,
};
// set up the llamaparse reader
const reader = new LlamaParseReader(params);
const buffer = fs.readFileSync(filePath);
const documents = await reader.loadDataAsContent(
new Uint8Array(buffer),
path.basename(filePath),
);
let allText = "";
documents.forEach((doc) => {
allText += doc.text;
});
console.log(allText);
}
main().catch(console.error);
-72
View File
@@ -1,72 +0,0 @@
import { LlamaParseReader } from "@llamaindex/cloud";
import { OpenAI } from "@llamaindex/openai";
import {
Document,
ImageNode,
PromptTemplate,
VectorStoreIndex,
createMessageContent,
} from "llamaindex";
const reader = new LlamaParseReader();
async function main() {
// Load PDF using LlamaParse JSON mode and return an array of json objects
const jsonObjs = await reader.loadJson("../data/uber_10q_march_2022.pdf");
// Access the first "pages" (=a single parsed file) object in the array
const jsonList = jsonObjs[0]["pages"];
const textDocs = getTextDocs(jsonList);
const imageTextDocs = await getImageTextDocs(jsonObjs);
const documents = [...textDocs, ...imageTextDocs];
// Split text, create embeddings and query the index
const index = await VectorStoreIndex.fromDocuments(documents);
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query({
query:
"What does the bar graph titled 'Monthly Active Platform Consumers' show?",
});
console.log(response.toString());
}
main().catch(console.error);
// Extract and assign text and page number from jsonList, return an array of Document objects
function getTextDocs(jsonList: { text: string; page: number }[]): Document[] {
return jsonList.map(
(page) => new Document({ text: page.text, metadata: { page: page.page } }),
);
}
// Download all images from jsonObjs, send them to OpenAI API to get alt text, return an array of Document objects
async function getImageTextDocs(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
jsonObjs: Record<string, any>[],
): Promise<Document[]> {
const llm = new OpenAI({
model: "gpt-4o",
temperature: 0.2,
maxTokens: 1000,
});
const imageDicts = await reader.getImages(jsonObjs, "images");
const imageDocs = [];
for (const imageDict of imageDicts) {
const imageDoc = new ImageNode({ image: imageDict.path });
const prompt = new PromptTemplate({
template: `Describe the image as alt text`,
});
const message = await createMessageContent(prompt, [imageDoc]);
const response = await llm.complete({
prompt: message,
});
const doc = new Document({
text: response.text,
metadata: { path: imageDict.path },
});
imageDocs.push(doc);
}
return imageDocs;
}
-33
View File
@@ -1,33 +0,0 @@
import { LlamaParseReader } from "@llamaindex/cloud/reader";
import { openai, OpenAIEmbedding } from "@llamaindex/openai";
import { Settings, VectorStoreIndex } from "llamaindex";
Settings.llm = openai({
model: "gpt-4.1",
});
Settings.embedModel = new OpenAIEmbedding({
model: "text-embedding-3-small",
});
async function main() {
// Load PDF using LlamaParse
const reader = new LlamaParseReader({
resultType: "markdown",
baseUrl: "https://api.cloud.llamaindex.ai", // for EU use: https://api.cloud.eu.llamaindex.ai
});
const documents = await reader.loadData("../data/TOS.pdf");
// Split text and create embeddings. Store them in a VectorStoreIndex
const index = await VectorStoreIndex.fromDocuments(documents);
// Query the index
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query({
query: "What is the license grant in the TOS?",
});
// Output response
console.log(response.toString());
}
main().catch(console.error);
@@ -1,33 +0,0 @@
import { LlamaParseReader } from "@llamaindex/cloud/reader";
import { SimpleDirectoryReader } from "@llamaindex/readers/directory";
import { VectorStoreIndex } from "llamaindex";
async function main() {
const reader = new SimpleDirectoryReader();
const docs = await reader.loadData({
directoryPath: "../data/parallel", // brk-2022.pdf split into 6 parts
numWorkers: 2,
// set LlamaParse as the default reader for all file types. Set apiKey here or in environment variable LLAMA_CLOUD_API_KEY
overrideReader: new LlamaParseReader({
language: "en",
resultType: "markdown",
parsingInstruction:
"The provided files is Berkshire Hathaway's 2022 Annual Report. They contain figures, tables and raw data. Capture the data in a structured format. Mathematical equation should be put out as LATEX markdown (between $$).",
}),
});
const index = await VectorStoreIndex.fromDocuments(docs);
// Query the index
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query({
query:
"What is the general strategy for shareholder safety outlined in the report? Use a concrete example with numbers",
});
// Output response
console.log(response.toString());
}
main().catch(console.error);
-723
View File
@@ -1,723 +0,0 @@
# @llamaindex/cloud
## 4.1.3
### Patch Changes
- Updated dependencies [5da1cda]
- @llamaindex/core@0.6.21
## 4.1.2
### Patch Changes
- Updated dependencies [0267bb0]
- @llamaindex/core@0.6.20
## 4.1.1
### Patch Changes
- 4b51791: Add deprecation to README
## 4.1.0
### Minor Changes
- 049471b: Add deprecation warning
## 4.0.28
### Patch Changes
- c3bf3c7: Adding support for citations to beta agent data schema
- Updated dependencies [f9f1de9]
- @llamaindex/core@0.6.19
## 4.0.27
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 4.0.26
### Patch Changes
- Updated dependencies [38da40b]
- @llamaindex/core@0.6.17
## 4.0.25
### Patch Changes
- 2967d57: Default to \_public agent url id
- Updated dependencies [a8ec08c]
- @llamaindex/core@0.6.16
## 4.0.24
### Patch Changes
- Updated dependencies [7ad3411]
- Updated dependencies [5da5b3c]
- @llamaindex/core@0.6.15
## 4.0.23
### Patch Changes
- a1b1598: fix: add generic types into agent data responses
## 4.0.22
### Patch Changes
- d2be868: Bug fixes for new beta agent-data cloud API
## 4.0.21
### Patch Changes
- 579ca0c: chore: bump sdk version
## 4.0.20
### Patch Changes
- 48b0d88: fix: exports in `api` submodule
- f185772: fix(cloud): missing file
## 4.0.19
### Patch Changes
- 5a0ed1f: feat: init agent api on cloud sdk
- 5a0ed1f: feat: init agent api on cloud sdk
- Updated dependencies [8eeac33]
- @llamaindex/core@0.6.14
## 4.0.18
### Patch Changes
- 47a7555: chore: bump sdk version
## 4.0.17
### Patch Changes
- Updated dependencies [d578889]
- Updated dependencies [0fcc92f]
- Updated dependencies [515a8b9]
- @llamaindex/core@0.6.13
## 4.0.16
### Patch Changes
- Updated dependencies [7039e1a]
- Updated dependencies [7039e1a]
- @llamaindex/core@0.6.12
## 4.0.15
### Patch Changes
- Updated dependencies [a89e187]
- Updated dependencies [62699b7]
- Updated dependencies [c5b2691]
- Updated dependencies [d8ac8d3]
- @llamaindex/core@0.6.11
## 4.0.14
### Patch Changes
- Updated dependencies [1b5af14]
- @llamaindex/core@0.6.10
## 4.0.13
### Patch Changes
- Updated dependencies [71598f8]
- @llamaindex/core@0.6.9
## 4.0.12
### Patch Changes
- Updated dependencies [c927457]
- @llamaindex/core@0.6.8
## 4.0.11
### Patch Changes
- 76ff23d: Fix pRetry not working with CommonJS
## 4.0.10
### Patch Changes
- Updated dependencies [59601dd]
- @llamaindex/core@0.6.7
## 4.0.9
### Patch Changes
- 3703f90: feat(parse): add upload API
## 4.0.8
### Patch Changes
- Updated dependencies [680b529]
- Updated dependencies [361a685]
- @llamaindex/core@0.6.6
## 4.0.7
### Patch Changes
- 40f5f41: Improve the loadJson function in LlamaParseReader to align with loadData by allowing URL inputs. Ensures s3://, http://, and https:// paths are not treated as local file paths.
- Updated dependencies [d671ed6]
- @llamaindex/core@0.6.5
## 4.0.6
### Patch Changes
- Updated dependencies [9b2e25a]
- @llamaindex/core@0.6.4
- @llamaindex/env@0.1.30
## 4.0.5
### Patch Changes
- 2225ffd: feat: bump llama cloud sdk
## 4.0.4
### Patch Changes
- Updated dependencies [3ee8c83]
- @llamaindex/core@0.6.3
## 4.0.3
### Patch Changes
- 41191d0: fix(parse): file input
## 4.0.2
### Patch Changes
- Updated dependencies [9c63f3f]
- @llamaindex/core@0.6.2
## 4.0.1
### Patch Changes
- Updated dependencies [1b6f368]
- Updated dependencies [eaf326e]
- @llamaindex/core@0.6.1
## 4.0.0
### Patch Changes
- bf56fc0: chore: bump sdk openapi.json
- 5189b44: fix: add retry handling logic to parser reader and fix lint issues
- Updated dependencies [21bebfc]
- Updated dependencies [93bc0ff]
- Updated dependencies [91a18e7]
- Updated dependencies [5189b44]
- @llamaindex/core@0.6.0
## 3.0.9
### Patch Changes
- Updated dependencies [40ee761]
- @llamaindex/core@0.5.8
## 3.0.8
### Patch Changes
- Updated dependencies [4bac71d]
- @llamaindex/core@0.5.7
## 3.0.7
### Patch Changes
- Updated dependencies [beb922b]
- @llamaindex/env@0.1.29
- @llamaindex/core@0.5.6
## 3.0.6
### Patch Changes
- Updated dependencies [5668970]
- @llamaindex/core@0.5.5
## 3.0.5
### Patch Changes
- Updated dependencies [ad3c7f1]
- @llamaindex/core@0.5.4
## 3.0.4
### Patch Changes
- Updated dependencies [cb021e7]
- @llamaindex/core@0.5.3
## 3.0.3
### Patch Changes
- Updated dependencies [d952e68]
- @llamaindex/core@0.5.2
## 3.0.2
### Patch Changes
- c902fcb: chore: bump llamacloud openapi
## 3.0.1
### Patch Changes
- Updated dependencies [cc50c9c]
- @llamaindex/env@0.1.28
- @llamaindex/core@0.5.1
## 3.0.0
### Patch Changes
- Updated dependencies [6a4a737]
- Updated dependencies [d924c63]
- @llamaindex/core@0.5.0
## 2.0.24
### Patch Changes
- 1c908fd: Revert previous release (not working with CJS)
- Updated dependencies [1c908fd]
- @llamaindex/core@0.4.23
- @llamaindex/env@0.1.27
## 2.0.23
### Patch Changes
- cb608b5: fix: bundle output incorrect
- Updated dependencies [cb608b5]
- @llamaindex/core@0.4.22
- @llamaindex/env@0.1.26
## 2.0.22
### Patch Changes
- d6c270e: feat: support pass project and org id to llama parse reader
- Updated dependencies [9456616]
- Updated dependencies [1931bbc]
- @llamaindex/core@0.4.21
## 2.0.21
### Patch Changes
- 5dec9f9: chore: bump sdk deps version
- fd9c829: chore: bump llamacloud openapi
- Updated dependencies [d211b7a]
- @llamaindex/core@0.4.20
## 2.0.20
### Patch Changes
- 012495b: chore: bump llamacloud sdk
## 2.0.19
### Patch Changes
- Updated dependencies [a9b5b99]
- @llamaindex/core@0.4.19
## 2.0.18
### Patch Changes
- Updated dependencies [b504303]
- Updated dependencies [e0f6cc3]
- @llamaindex/env@0.1.25
- @llamaindex/core@0.4.18
## 2.0.17
### Patch Changes
- Updated dependencies [3d1808b]
- @llamaindex/core@0.4.17
## 2.0.16
### Patch Changes
- 8be4589: chore: bump version
- Updated dependencies [8be4589]
- @llamaindex/core@0.4.16
- @llamaindex/env@0.1.24
## 2.0.15
### Patch Changes
- Updated dependencies [d2b2722]
- @llamaindex/env@0.1.23
- @llamaindex/core@0.4.15
## 2.0.14
### Patch Changes
- Updated dependencies [969365c]
- @llamaindex/env@0.1.22
- @llamaindex/core@0.4.14
## 2.0.13
### Patch Changes
- 90d265c: chore: bump version
- Updated dependencies [90d265c]
- @llamaindex/core@0.4.13
- @llamaindex/env@0.1.21
## 2.0.12
### Patch Changes
- Updated dependencies [ef4f63d]
- @llamaindex/core@0.4.12
## 2.0.11
### Patch Changes
- Updated dependencies [6d22fa2]
- @llamaindex/core@0.4.11
## 2.0.10
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
## 2.0.9
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
## 2.0.8
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
## 2.0.7
### Patch Changes
- Updated dependencies [d89ebe0]
- Updated dependencies [fd8c882]
- @llamaindex/core@0.4.7
## 2.0.6
### Patch Changes
- Updated dependencies [4fc001c]
- @llamaindex/env@0.1.20
- @llamaindex/core@0.4.6
## 2.0.5
### Patch Changes
- Updated dependencies [ad85bd0]
- @llamaindex/core@0.4.5
- @llamaindex/env@0.1.19
## 2.0.4
### Patch Changes
- Updated dependencies [a8d3fa6]
- @llamaindex/env@0.1.18
- @llamaindex/core@0.4.4
## 2.0.3
### Patch Changes
- Updated dependencies [95a5cc6]
- @llamaindex/core@0.4.3
## 2.0.2
### Patch Changes
- Updated dependencies [14cc9eb]
- @llamaindex/env@0.1.17
- @llamaindex/core@0.4.2
## 2.0.1
### Patch Changes
- Updated dependencies [9c73f0a]
- @llamaindex/core@0.4.1
## 2.0.0
### Patch Changes
- Updated dependencies [359fd33]
- Updated dependencies [efb7e1b]
- Updated dependencies [98ba1e7]
- Updated dependencies [620c63c]
- @llamaindex/core@0.4.0
## 1.0.8
### Patch Changes
- Updated dependencies [60b185f]
- @llamaindex/core@0.3.7
## 1.0.7
### Patch Changes
- Updated dependencies [691c5bc]
- @llamaindex/core@0.3.6
## 1.0.6
### Patch Changes
- Updated dependencies [fa60fc6]
- @llamaindex/env@0.1.16
- @llamaindex/core@0.3.5
## 1.0.5
### Patch Changes
- Updated dependencies [e2a0876]
- @llamaindex/core@0.3.4
## 1.0.4
### Patch Changes
- 06f632b: fix(cloud): allow filename in llama parse
## 1.0.3
### Patch Changes
- Updated dependencies [0493f67]
- @llamaindex/core@0.3.3
## 1.0.2
### Patch Changes
- Updated dependencies [4ba2cfe]
- @llamaindex/env@0.1.15
- @llamaindex/core@0.3.2
## 1.0.1
### Patch Changes
- 4c38c1b: fix(cloud): do not detect file type in llama parse
- 24d065f: Log Parse Job Errors when verbose is enabled
- a75af83: refactor: move some llm and embedding to single package
- Updated dependencies [ae49ff4]
- Updated dependencies [a75af83]
- @llamaindex/env@0.1.14
- @llamaindex/core@0.3.1
## 1.0.0
### Patch Changes
- Updated dependencies [1364e8e]
- Updated dependencies [96fc69c]
- @llamaindex/core@0.3.0
## 0.2.14
### Patch Changes
- Updated dependencies [5f67820]
- @llamaindex/core@0.2.12
## 0.2.13
### Patch Changes
- Updated dependencies [ee697fb]
- @llamaindex/core@0.2.11
## 0.2.12
### Patch Changes
- Updated dependencies [3489e7d]
- Updated dependencies [468bda5]
- @llamaindex/core@0.2.10
## 0.2.11
### Patch Changes
- 0b20ff9: fix: package.json format
## 0.2.10
### Patch Changes
- 981811e: fix(cloud): llama parse reader save image incorrectly
## 0.2.9
### Patch Changes
- df441e2: fix: consoleLogger is missing from `@llamaindex/env`
- Updated dependencies [df441e2]
- @llamaindex/core@0.2.8
- @llamaindex/env@0.1.13
## 0.2.8
### Patch Changes
- ac41ed3: feat: bump cloud sdk version
## 0.2.7
### Patch Changes
- fb36eff: fix: backport for node.js 18
There could have one missing API in the node.js 18, so we need to backport it to make it work.
- d24d3d1: fix: print warning when llama parse reader has error
- Updated dependencies [2cd1383]
- @llamaindex/core@0.2.3
## 0.2.6
### Patch Changes
- b42adeb: fix: get job result in llama parse reader
- Updated dependencies [749b43a]
- @llamaindex/core@0.2.2
## 0.2.5
### Patch Changes
- 85c2e19: feat: `@llamaindex/cloud` package update
- Bump to latest openapi schema
- Move LlamaParse class from llamaindex, this will allow you use llamaparse in more non-node.js environment
- Updated dependencies [ac07e3c]
- Updated dependencies [70ccb4a]
- Updated dependencies [1a6137b]
- Updated dependencies [ac07e3c]
- @llamaindex/core@0.2.1
- @llamaindex/env@0.1.11
## 0.2.4
### Patch Changes
- 4810364: fix: bump version
## 0.2.3
### Patch Changes
- 0bf8d80: fix: bump version
## 0.2.2
### Patch Changes
- 58abc57: fix: align version
## 0.2.1
### Patch Changes
- 1f680d7: chore: bump llamacloud api
## 0.2.0
### Minor Changes
- 3ed6acc: feat: cloud api change
## 0.1.4
### Patch Changes
- 36ddec4: fix: typo in custom page separator parameter for LlamaParse
## 0.1.3
### Patch Changes
- 1c444d5: feat(cloud): update openapi.json
## 0.1.2
### Patch Changes
- f326ab8: chore: bump version
## 0.1.1
### Patch Changes
- 321c39d: fix: generate api as class
-10
View File
@@ -1,10 +0,0 @@
# @llamaindex/cloud
> [!WARNING]
> This package has been deprecated since version 4.1.0.
> Please migrate to [llama-cloud-services](https://www.npmjs.com/package/llama-cloud-services).
> See the documentation: https://docs.cloud.llamaindex.ai
## License
MIT
-8
View File
@@ -1,8 +0,0 @@
{
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": "./dist/index.js",
"private": true
}
-8
View File
@@ -1,8 +0,0 @@
{
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": "./dist/index.js",
"private": true
}
-24
View File
@@ -1,24 +0,0 @@
import { defaultPlugins, defineConfig } from "@hey-api/openapi-ts";
export default defineConfig({
// you can download this file to get the latest version of the OpenAPI document
// @link https://api.cloud.llamaindex.ai/api/openapi.json
input: "./openapi.json",
output: {
path: "./src/client",
format: "prettier",
lint: "eslint",
},
plugins: [
...defaultPlugins,
"@hey-api/client-fetch",
"zod",
"@hey-api/schemas",
"@hey-api/sdk",
{
enums: "javascript",
identifierCase: "PascalCase",
name: "@hey-api/typescript",
},
],
});
File diff suppressed because it is too large Load Diff
-97
View File
@@ -1,97 +0,0 @@
{
"name": "@llamaindex/cloud",
"version": "4.1.3",
"type": "module",
"license": "MIT",
"scripts": {
"generate": "./node_modules/.bin/openapi-ts",
"build": "pnpm run generate && bunchee",
"dev": "bunchee --watch"
},
"files": [
"openapi.json",
"./api",
"./reader",
"./parse",
"./beta/agent"
],
"exports": {
"./openapi.json": "./openapi.json",
"./beta/agent": {
"require": {
"types": "./beta/agent/dist/index.d.cts",
"default": "./beta/agent/dist/index.cjs"
},
"import": {
"types": "./beta/agent/dist/index.d.ts",
"default": "./beta/agent/dist/index.js"
},
"default": "./beta/agent/dist/index.js"
},
"./api": {
"require": {
"types": "./api/dist/index.d.cts",
"default": "./api/dist/index.cjs"
},
"import": {
"types": "./api/dist/index.d.ts",
"default": "./api/dist/index.js"
},
"default": "./api/dist/index.js"
},
"./reader": {
"require": {
"types": "./reader/dist/index.d.cts",
"default": "./reader/dist/index.cjs"
},
"import": {
"types": "./reader/dist/index.d.ts",
"default": "./reader/dist/index.js"
},
"default": "./reader/dist/index.js"
},
"./parse": {
"require": {
"types": "./parse/dist/index.d.cts",
"default": "./parse/dist/index.cjs"
},
"import": {
"types": "./parse/dist/index.d.ts",
"default": "./parse/dist/index.js"
},
"default": "./parse/dist/index.js"
},
".": {
"require": {
"types": "./reader/dist/index.d.cts",
"default": "./reader/dist/index.cjs"
},
"import": {
"types": "./reader/dist/index.d.ts",
"default": "./reader/dist/index.js"
},
"default": "./reader/dist/index.js"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
"directory": "packages/cloud"
},
"devDependencies": {
"@hey-api/client-fetch": "^0.10.1",
"@hey-api/openapi-ts": "^0.67.5",
"@llama-flow/core": "^0.4.1",
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*"
},
"peerDependencies": {
"@llama-flow/core": "^0.4.1",
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*"
},
"dependencies": {
"p-retry": "^6.2.1",
"zod": "^3.25.76"
}
}
-8
View File
@@ -1,8 +0,0 @@
{
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": "./dist/index.js",
"private": true
}
-8
View File
@@ -1,8 +0,0 @@
{
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": "./dist/index.js",
"private": true
}
-18
View File
@@ -1,18 +0,0 @@
// Deprecation warning
console.warn(`
The package @llamaindex/cloud has been deprecated since version 4.1.0
* Please migrate to llama-cloud-services.
* See the documentation: https://docs.cloud.llamaindex.ai
`);
import { client } from "./client/client.gen";
client.setConfig({
baseUrl: "https://api.cloud.llamaindex.ai/",
headers: {
"X-SDK-Name": "llamaindex-ts",
},
});
export * from "./client";
export { client };
-329
View File
@@ -1,329 +0,0 @@
import { createClient, createConfig } from "@hey-api/client-fetch";
import { getEnv } from "@llamaindex/env";
import {
aggregateAgentDataApiV1BetaAgentDataAggregatePost,
createAgentDataApiV1BetaAgentDataPost,
deleteAgentDataApiV1BetaAgentDataItemIdDelete,
getAgentDataApiV1BetaAgentDataItemIdGet,
searchAgentDataApiV1BetaAgentDataSearchPost,
updateAgentDataApiV1BetaAgentDataItemIdPut,
type AgentData,
type AggregateGroup,
} from "../../client";
import type {
AggregateAgentDataOptions,
SearchAgentDataOptions,
TypedAgentData,
TypedAgentDataItems,
TypedAggregateGroup,
TypedAggregateGroupItems,
} from "./types";
/**
* Async client for agent data operations
*/
export class AgentClient<T = unknown> {
private client: ReturnType<typeof createClient>;
private baseUrl: string;
private headers: Record<string, string>;
private collection: string;
private agentUrlId: string;
constructor({
apiKey = getEnv("LLAMA_CLOUD_API_KEY"),
baseUrl = "https://api.cloud.llamaindex.ai/",
collection = "default",
agentUrlId = "_public",
}: {
apiKey?: string;
baseUrl?: string;
collection?: string;
agentUrlId?: string;
}) {
this.baseUrl = baseUrl;
this.headers = {
"X-SDK-Name": "llamaindex-ts",
...(apiKey && { Authorization: `Bearer ${apiKey}` }),
};
this.client = createClient(
createConfig({
baseUrl: this.baseUrl,
headers: this.headers,
}),
);
this.collection = collection;
this.agentUrlId = agentUrlId;
}
/**
* Create new agent data
*/
async createItem(data: T): Promise<TypedAgentData<T>> {
const response = await createAgentDataApiV1BetaAgentDataPost({
throwOnError: true,
body: {
agent_slug: this.agentUrlId,
collection: this.collection,
data: data as Record<string, unknown>,
},
client: this.client,
});
return this.transformResponse(response.data);
}
/**
* Get agent data by ID
*/
async getItem(id: string): Promise<TypedAgentData<T> | null> {
try {
const response = await getAgentDataApiV1BetaAgentDataItemIdGet({
throwOnError: true,
path: { item_id: id },
client: this.client,
});
return this.transformResponse(response.data);
} catch (error) {
if (
error instanceof Error &&
"response" in error &&
(error as { response?: { status?: number } }).response?.status === 404
) {
return null;
}
throw error;
}
}
/**
* Update agent data
*/
async updateItem(id: string, data: T): Promise<TypedAgentData<T>> {
const response = await updateAgentDataApiV1BetaAgentDataItemIdPut({
throwOnError: true,
path: { item_id: id },
body: {
data: data as Record<string, unknown>,
},
client: this.client,
});
return this.transformResponse(response.data);
}
/**
* Delete agent data
*/
async deleteItem(id: string): Promise<void> {
await deleteAgentDataApiV1BetaAgentDataItemIdDelete({
throwOnError: true,
path: { item_id: id },
client: this.client,
});
}
/**
* Search agent data
*/
async search(
options: SearchAgentDataOptions,
): Promise<TypedAgentDataItems<T>> {
const response = await searchAgentDataApiV1BetaAgentDataSearchPost({
throwOnError: true,
body: {
agent_slug: this.agentUrlId,
...(this.collection !== undefined && {
collection: this.collection,
}),
...(options.filter !== undefined && { filter: options.filter }),
...(options.orderBy !== undefined && { order_by: options.orderBy }),
...(options.pageSize !== undefined && { page_size: options.pageSize }),
...(options.offset !== undefined && { offset: options.offset }),
...(options.includeTotal !== undefined && {
include_total: options.includeTotal,
}),
},
client: this.client,
});
const result: TypedAgentDataItems<T> = {
items: response.data.items.map((item: AgentData) =>
this.transformResponse(item),
),
};
if (
response.data.total_size !== null &&
response.data.total_size !== undefined
) {
result.totalSize = response.data.total_size;
}
if (
response.data.next_page_token !== null &&
response.data.next_page_token !== undefined
) {
result.nextPageToken = response.data.next_page_token;
}
return result;
}
/**
* Aggregate agent data into groups
*/
async aggregate(
options: AggregateAgentDataOptions,
): Promise<TypedAggregateGroupItems<T>> {
const response = await aggregateAgentDataApiV1BetaAgentDataAggregatePost({
throwOnError: true,
body: {
agent_slug: this.agentUrlId,
...(this.collection !== undefined && {
collection: this.collection,
}),
...(options.filter !== undefined && { filter: options.filter }),
...(options.groupBy !== undefined && { group_by: options.groupBy }),
...(options.count !== undefined && { count: options.count }),
...(options.first !== undefined && { first: options.first }),
...(options.orderBy !== undefined && { order_by: options.orderBy }),
...(options.offset !== undefined && { offset: options.offset }),
...(options.pageSize !== undefined && { page_size: options.pageSize }),
},
client: this.client,
});
const result: TypedAggregateGroupItems<T> = {
items: response.data.items.map((item) =>
this.transformAggregateResponse(item),
),
};
if (
response.data.total_size !== null &&
response.data.total_size !== undefined
) {
result.totalSize = response.data.total_size;
}
if (
response.data.next_page_token !== null &&
response.data.next_page_token !== undefined
) {
result.nextPageToken = response.data.next_page_token;
}
return result;
}
/**
* Transform API response to typed data
*/
private transformResponse(data: AgentData): TypedAgentData<T> {
const result: TypedAgentData<T> = {
id: data.id!,
agentUrlId: data.agent_slug,
data: data.data as T,
createdAt: new Date(data.created_at!),
updatedAt: new Date(data.updated_at!),
};
if (data.collection !== undefined) {
result.collection = data.collection;
}
return result;
}
/**
* Transform API aggregate response to typed data
*/
private transformAggregateResponse(
data: AggregateGroup,
): TypedAggregateGroup<T> {
const result: TypedAggregateGroup<T> = {
groupKey: data.group_key,
};
if (data.count !== null && data.count !== undefined) {
result.count = data.count;
}
if (data.first_item !== null && data.first_item !== undefined) {
result.firstItem = data.first_item as T;
}
return result;
}
}
export interface AgentDataClientOptions<T = unknown> {
/** API key for the client */
apiKey?: string;
/** Base URL for the client */
/** Base URL of the llama cloud api */
baseUrl?: string;
/** If running in an agent runtime, optionally provide the window url to infer the agent url id */
windowUrl?: string;
/** Agent URL ID for the client, if not provided, it will be inferred from the window url, or fall back to "default" */
agentUrlId?: string;
/** Collection name for the client, defaults to "default" */
collection?: string;
}
/**
* Create a new AsyncAgentDataClient instance. Does it's best to infer an agent url id from environment.
* Pass in the window url and/or env to infer the agent url id from them.
* @param options - The options for the client
* @returns A new AgentClient instance
*/
export function createAgentDataClient<T = unknown>({
apiKey,
baseUrl,
windowUrl,
env,
agentUrlId,
collection = "default",
}: {
apiKey?: string;
baseUrl?: string;
windowUrl?: string;
env?: Record<string, string>;
agentUrlId?: string;
collection?: string;
} = {}): AgentClient<T> {
if (env && !agentUrlId) {
agentUrlId =
env.LLAMA_DEPLOY_DEPLOYMENT_NAME ||
env.NEXT_PUBLIC_LLAMA_DEPLOY_DEPLOYMENT_NAME ||
env.VITE_LLAMA_DEPLOY_DEPLOYMENT_NAME;
}
if (windowUrl && !agentUrlId) {
try {
const url = new URL(windowUrl);
const path = url.pathname;
const isLocalhost = // local agents should default to _public, otherwise a full deployment is required
url.hostname.includes("localhost") ||
url.hostname.includes("127.0.0.1");
if (path.startsWith("/deployments/") && !isLocalhost) {
// /deployments/<agent-url-id>/ui/ -> ["", "deployments", "<agent-url-id>", "ui"]
agentUrlId = path.split("/")[2];
}
} catch (error) {
console.warn(
"Failed to infer agent url id from window url, falling back to default",
error,
);
}
}
return new AgentClient({
...(apiKey && { apiKey }),
...(baseUrl && { baseUrl }),
...(agentUrlId && { agentUrlId }),
collection,
});
}
-23
View File
@@ -1,23 +0,0 @@
// Deprecation warning
console.warn(`
The package @llamaindex/cloud has been deprecated since version 4.1.0
* Please migrate to llama-cloud-services.
* See the documentation: https://docs.cloud.llamaindex.ai
`);
export { AgentClient, createAgentDataClient } from "./client";
export type {
AggregateAgentDataOptions,
ComparisonOperator,
ExtractedData,
FilterOperation,
SearchAgentDataOptions,
StatusType,
TypedAgentData,
TypedAgentDataItems,
TypedAggregateGroup,
TypedAggregateGroupItems,
} from "./types";
export { StatusType as StatusTypeEnum } from "./types";
-163
View File
@@ -1,163 +0,0 @@
import type { FilterOperation as RawFilterOperation } from "../../client/types.gen";
/**
* Status types for agent data processing
*/
export const StatusType = {
ERROR: "error",
ACCEPTED: "accepted",
REJECTED: "rejected",
PENDING_REVIEW: "pending_review",
} as const;
export type StatusType = (typeof StatusType)[keyof typeof StatusType];
export const ComparisonOperator = {
GT: "gt",
GTE: "gte",
LT: "lt",
LTE: "lte",
EQ: "eq",
INCLUDES: "includes",
} as const;
export type ComparisonOperator =
(typeof ComparisonOperator)[keyof typeof ComparisonOperator];
/**
* Filter operation for searching/filtering agent data
*/
export type FilterOperation = RawFilterOperation;
/**
* Metadata for an extracted field, including confidence and citation information
*/
export interface ExtractedFieldMetadata {
/** The confidence score for the field, combined with parsing confidence if applicable */
confidence?: number;
/** The confidence score for the field based on the extracted text only */
extracted_confidence?: number;
/** The page number that the field occurred on */
page_number?: number;
/** The original text this field's value was derived from */
matching_text?: string;
}
/**
* Dictionary mapping field names to their metadata
* Values can be ExtractedFieldMetadata objects, nested dictionaries, or arrays
*/
export type ExtractedFieldMetadataDict = Record<
string,
ExtractedFieldMetadata | Record<string, unknown> | unknown[]
>;
/**
* Base extracted data interface
*/
export interface ExtractedData<T = unknown> {
/** The original data that was extracted from the document. For tracking changes. Should not be updated. */
original_data: T;
/** The latest state of the data. Will differ if data has been updated. */
data: T;
/** The status of the extracted data. Prefer to use the StatusType values, but any string is allowed. */
status: StatusType | string;
/** The overall confidence score for the extracted data. */
overall_confidence?: number;
/** Page links, and perhaps eventually bounding boxes, for individual fields in the extracted data. */
field_metadata?: ExtractedFieldMetadataDict;
/** The ID of the file that was used to extract the data. */
file_id?: string;
/** The name of the file that was used to extract the data. */
file_name?: string;
/** The hash of the file that was used to extract the data. */
file_hash?: string;
/** Additional metadata about the extracted data, such as errors, tokens, etc. */
metadata?: Record<string, unknown>;
}
/**
* TypedAgentData interface for typed agent data
*/
export interface TypedAgentData<T = unknown> {
/** The unique ID of the agent data record. */
id: string;
/** The ID of the agent that created the data. */
agentUrlId: string;
/** The collection of the agent data. */
collection?: string;
/** The data of the agent data. Usually an ExtractedData&lt;SomeOtherType&gt; */
data: T;
/** The date and time the data was created. */
createdAt: Date;
/** The date and time the data was last updated. */
updatedAt: Date;
}
/**
* Paginated response of typed agent data items
*/
export interface TypedAgentDataItems<T = unknown> {
items: TypedAgentData<T>[];
totalSize?: number;
nextPageToken?: string;
}
/**
* Options for listing agent data
*/
export interface SearchAgentDataOptions {
/** Filter options for the list. */
filter?: Record<string, FilterOperation>;
/** Order by options for the list. */
orderBy?: string;
/** Page size for the list. */
pageSize?: number;
/** Offset for the list. */
offset?: number;
/**
* Whether to include the total number of items in the response.
* Should use only for first request to build total pagination, and not subsequent requests.
*/
includeTotal?: boolean;
}
/**
* Options for aggregating agent data
*/
export interface AggregateAgentDataOptions {
/** Filter options for the aggregation. */
filter?: Record<string, FilterOperation>;
/** Fields to group by. */
groupBy?: string[];
/** Whether to count the number of items in each group. */
count?: boolean;
/** Whether to return the first item in each group. */
first?: boolean;
/** Order by options for the aggregation. */
orderBy?: string;
/** Offset for the aggregation. */
offset?: number;
/** Page size for the aggregation. */
pageSize?: number;
}
/**
* Single aggregation group result
*/
export interface TypedAggregateGroup<T = unknown> {
/** The group key values */
groupKey: Record<string, unknown>;
/** Count of items in the group */
count?: number;
/** First item in the group */
firstItem?: T;
}
/**
* Paginated response of aggregated agent data
*/
export interface TypedAggregateGroupItems<T = unknown> {
items: TypedAggregateGroup<T>[];
totalSize?: number;
nextPageToken?: string;
}
-55
View File
@@ -1,55 +0,0 @@
import { workflowEvent } from "@llama-flow/core";
import { zodEvent } from "@llama-flow/core/util/zod";
import { z } from "zod";
import { parseFormSchema } from "./schema";
export const uploadEvent = zodEvent(
parseFormSchema.merge(
z.object({
file: z
.string()
.or(z.instanceof(File))
.or(z.instanceof(Blob))
.or(z.instanceof(Uint8Array))
.optional()
.describe("input"),
}),
),
{
debugLabel: "upload",
uniqueId: "52099967-34a8-419b-8950-c859eab60145",
},
);
export const checkStatusEvent = workflowEvent<string>({
debugLabel: "check-status",
uniqueId: "462157fc-1ded-4ba7-9bc4-3e870395bd20",
});
export const checkStatusSuccessEvent = workflowEvent<string>({
debugLabel: "check-status-success",
uniqueId: "360b7641-30f7-456e-851d-104bb5e3f8d2",
});
export const requestMarkdownEvent = workflowEvent<string>({
debugLabel: "markdown-request",
uniqueId: "aa4c2e3c-0f09-4035-aab6-c72719c877cc",
});
export const requestTextEvent = workflowEvent<string>({
debugLabel: "text-request",
uniqueId: "6976536e-5399-4285-9455-0b70f1dfc92b",
});
export const requestJsonEvent = workflowEvent<string>({
debugLabel: "json-request",
uniqueId: "9fc4a330-52ad-4aac-8092-a650998b7f6f",
});
export const markdownResultEvent = workflowEvent<string>({
debugLabel: "markdown-result",
uniqueId: "2dfb57c8-73d1-4394-bea8-f05246d934d4",
});
export const textResultEvent = workflowEvent<string>({
debugLabel: "text-result",
uniqueId: "a27deec6-b24f-4eda-a5ac-ba2fb2bf37c8",
});
export const jsonResultEvent = workflowEvent<unknown>({
debugLabel: "json-result",
uniqueId: "e086e6bd-a612-4f25-ab41-9b31dcb8af86",
});
-232
View File
@@ -1,232 +0,0 @@
// Deprecation warning
console.warn(`
The package @llamaindex/cloud has been deprecated since version 4.1.0
* Please migrate to llama-cloud-services.
* See the documentation: https://docs.cloud.llamaindex.ai
`);
import { createClient, createConfig } from "@hey-api/client-fetch";
import { createWorkflow, type InferWorkflowEventData } from "@llama-flow/core";
import { createStatefulMiddleware } from "@llama-flow/core/middleware/state";
import { withTraceEvents } from "@llama-flow/core/middleware/trace-events";
import { pRetryHandler } from "@llama-flow/core/util/p-retry";
import { fs, getEnv, path } from "@llamaindex/env";
import {
type BodyUploadFileApiV1ParsingUploadPost,
getJobApiV1ParsingJobJobIdGet,
getJobJsonResultApiV1ParsingJobJobIdResultJsonGet,
getJobResultApiV1ParsingJobJobIdResultMarkdownGet,
getJobTextResultApiV1ParsingJobJobIdResultTextGet,
type StatusEnum,
uploadFileApiV1ParsingUploadPost,
} from "./client";
import {
checkStatusEvent,
checkStatusSuccessEvent,
jsonResultEvent,
markdownResultEvent,
requestJsonEvent,
requestMarkdownEvent,
requestTextEvent,
textResultEvent,
uploadEvent,
} from "./events";
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 { withState, getContext } = createStatefulMiddleware(
(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}`,
},
}),
),
};
},
);
const llamaParseWorkflow = withState(withTraceEvents(createWorkflow()));
llamaParseWorkflow.handle([uploadEvent], async ({ data: form }) => {
const { state } = getContext();
const finalForm = { ...form };
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])
: undefined;
}
const {
data: { id, status },
} = await uploadFileApiV1ParsingUploadPost({
throwOnError: true,
body: {
...finalForm,
} as BodyUploadFileApiV1ParsingUploadPost,
client: state.client,
});
state.cache[id] = status;
return checkStatusEvent.with(id);
});
llamaParseWorkflow.handle(
[checkStatusEvent],
pRetryHandler(
async ({ data: uuid }) => {
const { state } = getContext();
if (state.cache[uuid] === "SUCCESS") {
return checkStatusSuccessEvent.with(uuid);
}
const {
data: { status },
} = await getJobApiV1ParsingJobJobIdGet({
throwOnError: true,
path: {
job_id: uuid,
},
client: state.client,
});
state.cache[uuid] = status;
if (status === "SUCCESS") {
return checkStatusSuccessEvent.with(uuid);
}
throw new Error(`LLamaParse status: ${status}`);
},
{
retries: 100,
},
),
);
//#region sub workflow
llamaParseWorkflow.handle([requestMarkdownEvent], async ({ data: job_id }) => {
const { state } = getContext();
const { data } = await getJobResultApiV1ParsingJobJobIdResultMarkdownGet({
throwOnError: true,
path: {
job_id,
},
client: state.client,
});
return markdownResultEvent.with(data.markdown);
});
llamaParseWorkflow.handle([requestTextEvent], async ({ data: job_id }) => {
const { state } = getContext();
const { data } = await getJobTextResultApiV1ParsingJobJobIdResultTextGet({
throwOnError: true,
path: {
job_id,
},
client: state.client,
});
return textResultEvent.with(data.text);
});
llamaParseWorkflow.handle([requestJsonEvent], async ({ data: job_id }) => {
const { state } = getContext();
const { data } = await getJobJsonResultApiV1ParsingJobJobIdResultJsonGet({
throwOnError: true,
path: {
job_id,
},
client: state.client,
});
return jsonResultEvent.with(data.pages);
});
//#endregion
export type ParseJob = {
get jobId(): string;
get signal(): AbortSignal;
get context(): ReturnType<typeof llamaParseWorkflow.createContext>;
get form(): InferWorkflowEventData<typeof uploadEvent>;
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 uploadEvent> & LlamaParseWorkflowParams,
): Promise<ParseJob> => {
//#region upload event
const context = llamaParseWorkflow.createContext(params);
const { stream, sendEvent } = context;
const ev = uploadEvent.with(params);
sendEvent(ev);
const uploadThread = await llamaParseWorkflow
.substream(ev, stream)
.until((ev) => checkStatusSuccessEvent.include(ev))
.toArray();
//#region
const jobId: string = uploadThread.at(-1)!.data;
return {
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);
const { sendEvent, stream } = llamaParseWorkflow.createContext(params);
sendEvent(requestEv);
const markdownThread = await stream.until(markdownResultEvent).toArray();
return markdownThread.at(-1)!.data;
},
async text(): Promise<string> {
const requestEv = requestTextEvent.with(jobId);
const { sendEvent, stream } = llamaParseWorkflow.createContext(params);
sendEvent(requestEv);
const textThread = await stream.until(textResultEvent).toArray();
return textThread.at(-1)!.data;
},
//eslint-disable-next-line @typescript-eslint/no-explicit-any
async json(): Promise<any[]> {
const requestEv = requestJsonEvent.with(jobId);
const { sendEvent, stream } = llamaParseWorkflow.createContext(params);
sendEvent(requestEv);
const jsonThread = await stream
.until((ev) => jsonResultEvent.include(ev))
.toArray();
return jsonThread.at(-1)!.data;
},
};
};
-781
View File
@@ -1,781 +0,0 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { type Client, createClient, createConfig } from "@hey-api/client-fetch";
import { Document, FileReader } from "@llamaindex/core/schema";
import { fs, getEnv, path } from "@llamaindex/env";
import {
type BodyUploadFileApiParsingUploadPost,
type FailPageMode,
type ParserLanguages,
type ParsingMode,
getJobApiV1ParsingJobJobIdGet,
getJobImageResultApiV1ParsingJobJobIdResultImageNameGet,
getJobJsonResultApiV1ParsingJobJobIdResultJsonGet,
getJobResultApiV1ParsingJobJobIdResultMarkdownGet,
getJobTextResultApiV1ParsingJobJobIdResultTextGet,
uploadFileApiV1ParsingUploadPost,
} from "./api";
import { sleep } from "./utils";
export type Language = ParserLanguages;
export type ResultType = "text" | "markdown" | "json";
// Export the backoff pattern type.
export type BackoffPattern = "constant" | "linear" | "exponential";
// TODO: should move into @llamaindex/env
type WriteStream = {
write: (text: string) => void;
};
// Do not modify this variable or cause type errors
// eslint-disable-next-line no-var
var process: any;
/**
* Represents a reader for parsing files using the LlamaParse API.
* See https://github.com/run-llama/llama_parse
*/
export class LlamaParseReader extends FileReader {
project_id?: string | undefined;
organization_id?: string | undefined;
// The API key for the LlamaParse API. Can be set as an environment variable: LLAMA_CLOUD_API_KEY
apiKey: string;
// The base URL of the Llama Cloud Platform.
baseUrl: string = "https://api.cloud.llamaindex.ai";
// The result type for the parser.
resultType: ResultType = "text";
// The interval in seconds to check if the parsing is done.
checkInterval: number = 1;
// The maximum timeout in seconds to wait for the parsing to finish.
maxTimeout = 2000;
// Whether to print the progress of the parsing.
verbose = true;
// The language to parse the file in.
language: ParserLanguages[] = ["en"];
// New polling options:
// Controls the backoff mode: "constant", "linear", or "exponential".
backoffPattern: BackoffPattern = "linear";
// Maximum interval in seconds between polls.
maxCheckInterval: number = 5;
// Maximum number of retryable errors before giving up.
maxErrorCount: number = 4;
// The parsing instruction for the parser. Backend default is an empty string.
parsingInstruction?: string | undefined;
// Whether to ignore diagonal text (when the text rotation in degrees is not 0, 90, 180, or 270). Backend default is false.
skipDiagonalText?: boolean | undefined;
// Whether to ignore the cache and re-process the document. Documents are cached for 48 hours after job completion. Backend default is false.
invalidateCache?: boolean | undefined;
// Whether the document should not be cached. Backend default is false.
doNotCache?: boolean | undefined;
// Whether to use a faster mode to extract text (skipping OCR and table/heading reconstruction). Not compatible with gpt4oMode. Backend default is false.
fastMode?: boolean | undefined;
// Whether to keep columns in the text according to document layout. May reduce reconstruction accuracy and LLM/embedings performance.
doNotUnrollColumns?: boolean | undefined;
// A templated page separator for splitting text. If not set, default is "\n---\n".
pageSeparator?: string | undefined;
// A templated prefix to add at the beginning of each page.
pagePrefix?: string | undefined;
// A templated suffix to add at the end of each page.
pageSuffix?: string | undefined;
// Deprecated. Use vendorMultimodal params. Whether to use gpt-4o to extract text.
gpt4oMode: boolean = false;
// Deprecated. Use vendorMultimodal params. The API key for GPT-4o. Can be set via LLAMA_CLOUD_GPT4O_API_KEY.
gpt4oApiKey?: string | undefined;
// The bounding box margins as a string.
boundingBox?: string | undefined;
// The target pages (comma separated list, starting at 0).
targetPages?: string | undefined;
// Whether to ignore errors during parsing.
ignoreErrors: boolean = true;
// Whether to split by page using the pageSeparator (or "\n---\n" as default).
splitByPage: boolean = true;
// Whether to use the vendor multimodal API.
useVendorMultimodalModel: boolean = false;
// The model name for the vendor multimodal API.
vendorMultimodalModelName?: string | undefined;
// The API key for the multimodal API. Can be set via LLAMA_CLOUD_VENDOR_MULTIMODAL_API_KEY.
vendorMultimodalApiKey?: string | undefined;
webhookUrl?: string | undefined;
premiumMode?: boolean | undefined;
takeScreenshot?: boolean | undefined;
disableOcr?: boolean | undefined;
disableReconstruction?: boolean | undefined;
inputS3Path?: string | undefined;
outputS3PathPrefix?: string | undefined;
continuousMode?: boolean | undefined;
isFormattingInstruction?: boolean | undefined;
annotateLinks?: boolean | undefined;
azureOpenaiDeploymentName?: string | undefined;
azureOpenaiEndpoint?: string | undefined;
azureOpenaiApiVersion?: string | undefined;
azureOpenaiKey?: string | undefined;
auto_mode?: boolean | undefined;
auto_mode_trigger_on_image_in_page?: boolean | undefined;
auto_mode_trigger_on_table_in_page?: boolean | undefined;
auto_mode_trigger_on_text_in_page?: string | undefined;
auto_mode_trigger_on_regexp_in_page?: string | undefined;
bbox_bottom?: number | undefined;
bbox_left?: number | undefined;
bbox_right?: number | undefined;
bbox_top?: number | undefined;
disable_image_extraction?: boolean | undefined;
extract_charts?: boolean | undefined;
guess_xlsx_sheet_name?: boolean | undefined;
html_make_all_elements_visible?: boolean | undefined;
html_remove_fixed_elements?: boolean | undefined;
html_remove_navigation_elements?: boolean | undefined;
http_proxy?: string | undefined;
input_url?: string | undefined;
max_pages?: number | undefined;
output_pdf_of_document?: boolean | undefined;
structured_output?: boolean | undefined;
structured_output_json_schema?: string | undefined;
structured_output_json_schema_name?: string | undefined;
extract_layout?: boolean | undefined;
// numWorkers is implemented in SimpleDirectoryReader
stdout?: WriteStream | undefined;
readonly #client: Client;
output_tables_as_HTML: boolean = false;
input_s3_region?: string | undefined;
output_s3_region?: string | undefined;
preserve_layout_alignment_across_pages?: boolean | undefined;
spreadsheet_extract_sub_tables?: boolean | undefined;
formatting_instruction?: string | undefined;
parse_mode?: ParsingMode | undefined;
system_prompt?: string | undefined;
system_prompt_append?: string | undefined;
user_prompt?: string | undefined;
job_timeout_in_seconds?: number | undefined;
job_timeout_extra_time_per_page_in_seconds?: number | undefined;
strict_mode_image_extraction?: boolean | undefined;
strict_mode_image_ocr?: boolean | undefined;
strict_mode_reconstruction?: boolean | undefined;
strict_mode_buggy_font?: boolean | undefined;
ignore_document_elements_for_layout_detection?: boolean | undefined;
complemental_formatting_instruction?: string | undefined;
content_guideline_instruction?: string | undefined;
adaptive_long_table?: boolean | undefined;
model?: string | undefined;
auto_mode_configuration_json?: string | undefined;
compact_markdown_table?: boolean | undefined;
markdown_table_multiline_header_separator?: string | undefined;
page_error_tolerance?: number | undefined;
replace_failed_page_mode?: FailPageMode | undefined;
replace_failed_page_with_error_message_prefix?: string | undefined;
replace_failed_page_with_error_message_suffix?: string | undefined;
save_images?: boolean | undefined;
preset?: string | undefined;
high_res_ocr?: boolean | undefined;
outlined_table_extraction?: boolean | undefined;
hide_headers?: boolean | undefined;
hide_footers?: boolean | undefined;
page_header_prefix?: string | undefined;
page_header_suffix?: string | undefined;
page_footer_prefix?: string | undefined;
page_footer_suffix?: string | undefined;
merge_tables_across_pages_in_markdown?: boolean | undefined;
constructor(
params: Partial<Omit<LlamaParseReader, "language" | "apiKey">> & {
language?: ParserLanguages | ParserLanguages[] | undefined;
apiKey?: string | undefined;
} = {},
) {
super();
Object.assign(this, params);
this.language = Array.isArray(this.language)
? this.language
: [this.language];
this.stdout =
(params.stdout ?? typeof process !== "undefined")
? process!.stdout
: undefined;
const apiKey = params.apiKey ?? getEnv("LLAMA_CLOUD_API_KEY");
if (!apiKey) {
throw new Error(
"API Key is required for LlamaParseReader. Please pass the apiKey parameter or set the LLAMA_CLOUD_API_KEY environment variable.",
);
}
this.apiKey = apiKey;
if (this.baseUrl.endsWith("/")) {
this.baseUrl = this.baseUrl.slice(0, -1);
}
if (this.baseUrl.endsWith("/api/parsing")) {
this.baseUrl = this.baseUrl.slice(0, -"/api/parsing".length);
}
if (params.gpt4oMode) {
params.gpt4oApiKey =
params.gpt4oApiKey ?? getEnv("LLAMA_CLOUD_GPT4O_API_KEY");
this.gpt4oApiKey = params.gpt4oApiKey;
}
if (params.useVendorMultimodalModel) {
params.vendorMultimodalApiKey =
params.vendorMultimodalApiKey ??
getEnv("LLAMA_CLOUD_VENDOR_MULTIMODAL_API_KEY");
this.vendorMultimodalApiKey = params.vendorMultimodalApiKey;
}
this.#client = createClient(
createConfig({
headers: {
Authorization: `Bearer ${this.apiKey}`,
},
baseUrl: this.baseUrl,
}),
);
}
/**
* Creates a job for the LlamaParse API.
*
* @param data - The file data as a Uint8Array.
* @param filename - Optional filename for the file.
* @returns A Promise resolving to the job ID as a string.
*/
async #createJob(
data: Uint8Array | string,
filename?: string,
): Promise<string> {
if (this.verbose) {
console.log("Started uploading the file");
}
let file: File | Blob | null = null;
let input_s3_path: string | undefined = this.inputS3Path;
let input_url: string | undefined = this.input_url;
if (typeof data !== "string") {
// TODO: remove Blob usage when we drop Node.js 18 support
file =
globalThis.File && filename
? new File([data], filename)
: new Blob([data]);
} else if (data.startsWith("s3://")) {
input_s3_path = data;
} else if (data.startsWith("http://") || data.startsWith("https://")) {
input_url = data;
}
const body = {
file,
input_s3_path,
input_url,
language: this.language,
parsing_instruction: this.parsingInstruction,
skip_diagonal_text: this.skipDiagonalText,
invalidate_cache: this.invalidateCache,
do_not_cache: this.doNotCache,
fast_mode: this.fastMode,
do_not_unroll_columns: this.doNotUnrollColumns,
page_separator: this.pageSeparator,
page_prefix: this.pagePrefix,
page_suffix: this.pageSuffix,
gpt4o_mode: this.gpt4oMode,
gpt4o_api_key: this.gpt4oApiKey,
bounding_box: this.boundingBox,
target_pages: this.targetPages,
use_vendor_multimodal_model: this.useVendorMultimodalModel,
vendor_multimodal_model_name: this.vendorMultimodalModelName,
vendor_multimodal_api_key: this.vendorMultimodalApiKey,
premium_mode: this.premiumMode,
webhook_url: this.webhookUrl,
take_screenshot: this.takeScreenshot,
disable_ocr: this.disableOcr,
disable_reconstruction: this.disableReconstruction,
output_s3_path_prefix: this.outputS3PathPrefix,
continuous_mode: this.continuousMode,
is_formatting_instruction: this.isFormattingInstruction,
annotate_links: this.annotateLinks,
azure_openai_deployment_name: this.azureOpenaiDeploymentName,
azure_openai_endpoint: this.azureOpenaiEndpoint,
azure_openai_api_version: this.azureOpenaiApiVersion,
azure_openai_key: this.azureOpenaiKey,
auto_mode: this.auto_mode,
auto_mode_trigger_on_image_in_page:
this.auto_mode_trigger_on_image_in_page,
auto_mode_trigger_on_table_in_page:
this.auto_mode_trigger_on_table_in_page,
auto_mode_trigger_on_text_in_page: this.auto_mode_trigger_on_text_in_page,
auto_mode_trigger_on_regexp_in_page:
this.auto_mode_trigger_on_regexp_in_page,
bbox_bottom: this.bbox_bottom,
bbox_left: this.bbox_left,
bbox_right: this.bbox_right,
bbox_top: this.bbox_top,
disable_image_extraction: this.disable_image_extraction,
extract_charts: this.extract_charts,
guess_xlsx_sheet_name: this.guess_xlsx_sheet_name,
html_make_all_elements_visible: this.html_make_all_elements_visible,
html_remove_fixed_elements: this.html_remove_fixed_elements,
html_remove_navigation_elements: this.html_remove_navigation_elements,
http_proxy: this.http_proxy,
max_pages: this.max_pages,
output_pdf_of_document: this.output_pdf_of_document,
structured_output: this.structured_output,
structured_output_json_schema: this.structured_output_json_schema,
structured_output_json_schema_name:
this.structured_output_json_schema_name,
extract_layout: this.extract_layout,
output_tables_as_HTML: this.output_tables_as_HTML,
input_s3_region: this.input_s3_region,
output_s3_region: this.output_s3_region,
preserve_layout_alignment_across_pages:
this.preserve_layout_alignment_across_pages,
spreadsheet_extract_sub_tables: this.spreadsheet_extract_sub_tables,
formatting_instruction: this.formatting_instruction,
parse_mode: this.parse_mode,
system_prompt: this.system_prompt,
system_prompt_append: this.system_prompt_append,
user_prompt: this.user_prompt,
job_timeout_in_seconds: this.job_timeout_in_seconds,
job_timeout_extra_time_per_page_in_seconds:
this.job_timeout_extra_time_per_page_in_seconds,
strict_mode_image_extraction: this.strict_mode_image_extraction,
strict_mode_image_ocr: this.strict_mode_image_ocr,
strict_mode_reconstruction: this.strict_mode_reconstruction,
strict_mode_buggy_font: this.strict_mode_buggy_font,
ignore_document_elements_for_layout_detection:
this.ignore_document_elements_for_layout_detection,
complemental_formatting_instruction:
this.complemental_formatting_instruction,
content_guideline_instruction: this.content_guideline_instruction,
adaptive_long_table: this.adaptive_long_table,
model: this.model,
auto_mode_configuration_json: this.auto_mode_configuration_json,
compact_markdown_table: this.compact_markdown_table,
markdown_table_multiline_header_separator:
this.markdown_table_multiline_header_separator,
page_error_tolerance: this.page_error_tolerance,
replace_failed_page_mode: this.replace_failed_page_mode,
replace_failed_page_with_error_message_prefix:
this.replace_failed_page_with_error_message_prefix,
replace_failed_page_with_error_message_suffix:
this.replace_failed_page_with_error_message_suffix,
save_images: this.save_images,
preset: this.preset,
high_res_ocr: this.high_res_ocr,
outlined_table_extraction: this.outlined_table_extraction,
hide_headers: this.hide_headers,
hide_footers: this.hide_footers,
page_header_prefix: this.page_header_prefix,
page_header_suffix: this.page_header_suffix,
page_footer_prefix: this.page_footer_prefix,
page_footer_suffix: this.page_footer_suffix,
merge_tables_across_pages_in_markdown:
this.merge_tables_across_pages_in_markdown,
} satisfies {
[Key in keyof BodyUploadFileApiParsingUploadPost]-?:
| BodyUploadFileApiParsingUploadPost[Key]
| undefined;
} as unknown as BodyUploadFileApiParsingUploadPost;
const response = await uploadFileApiV1ParsingUploadPost({
client: this.#client,
throwOnError: true,
query: {
project_id: this.project_id ?? null,
organization_id: this.organization_id ?? null,
},
signal: AbortSignal.timeout(this.maxTimeout * 1000),
body,
});
return response.data.id;
}
/**
* Retrieves the result of a parsing job.
*
* Uses a polling loop with retry logic. Each API call is retried
* up to maxErrorCount times if it fails with a 5XX or socket error.
* The delay between polls increases according to the specified backoffPattern ("constant", "linear", or "exponential"),
* capped by maxCheckInterval.
*
* @param jobId - The job ID.
* @param resultType - The type of result to fetch ("text", "json", or "markdown").
* @returns A Promise resolving to the job result.
*/
private async getJobResult(
jobId: string,
resultType: "text" | "json" | "markdown",
): Promise<any> {
let tries = 0;
let currentInterval = this.checkInterval;
const { default: pRetry } = await import("p-retry");
while (true) {
await sleep(currentInterval * 1000);
// Wraps the API call in a retry
let result;
try {
result = await pRetry(
() =>
getJobApiV1ParsingJobJobIdGet({
client: this.#client,
throwOnError: true,
path: { job_id: jobId },
signal: AbortSignal.timeout(this.maxTimeout * 1000),
}),
{
retries: this.maxErrorCount,
onFailedAttempt: (error) => {
// Retry only on 5XX or socket errors.
const status = (error.cause as any)?.response?.status;
if (
!(
(status && status >= 500 && status < 600) ||
((error.cause as any)?.code &&
((error.cause as any).code === "ECONNRESET" ||
(error.cause as any).code === "ETIMEDOUT" ||
(error.cause as any).code === "ECONNREFUSED"))
)
) {
throw error;
}
if (this.verbose) {
console.warn(
`Attempting to get job ${jobId} result (attempt ${error.attemptNumber}) failed. Retrying...`,
);
}
},
},
);
} catch (e: any) {
throw new Error(
`Max error count reached for job ${jobId}: ${e.message}`,
);
}
const { data } = result;
const status = (data as Record<string, unknown>)["status"];
if (status === "SUCCESS") {
let resultData;
switch (resultType) {
case "json": {
resultData =
await getJobJsonResultApiV1ParsingJobJobIdResultJsonGet({
client: this.#client,
throwOnError: true,
path: { job_id: jobId },
query: {
organization_id: this.organization_id ?? null,
},
signal: AbortSignal.timeout(this.maxTimeout * 1000),
});
break;
}
case "markdown": {
resultData =
await getJobResultApiV1ParsingJobJobIdResultMarkdownGet({
client: this.#client,
throwOnError: true,
path: { job_id: jobId },
query: {
organization_id: this.organization_id ?? null,
},
signal: AbortSignal.timeout(this.maxTimeout * 1000),
});
break;
}
case "text": {
resultData =
await getJobTextResultApiV1ParsingJobJobIdResultTextGet({
client: this.#client,
throwOnError: true,
path: { job_id: jobId },
query: {
organization_id: this.organization_id ?? null,
},
signal: AbortSignal.timeout(this.maxTimeout * 1000),
});
break;
}
}
return resultData.data;
} else if (status === "PENDING") {
if (this.verbose && tries % 10 === 0) {
this.stdout?.write(".");
}
tries++;
} else {
if (this.verbose) {
console.error(
`Received error response ${status} for job ${jobId}. Got Error Code: ${data.error_code} and Error Message: ${data.error_message}`,
);
}
throw new Error(
`Failed to parse the file: ${jobId}, status: ${status}`,
);
}
// Adjust the polling interval based on the backoff pattern.
if (this.backoffPattern === "exponential") {
currentInterval = Math.min(currentInterval * 2, this.maxCheckInterval);
} else if (this.backoffPattern === "linear") {
currentInterval = Math.min(
currentInterval + this.checkInterval,
this.maxCheckInterval,
);
} else if (this.backoffPattern === "constant") {
currentInterval = this.checkInterval;
}
}
}
override async loadData(filePath?: string): Promise<Document[]> {
if (!filePath) {
if (this.input_url) {
return this.loadDataAsContent(this.input_url, this.input_url);
} else if (this.inputS3Path) {
return this.loadDataAsContent(this.inputS3Path, this.inputS3Path);
} else {
throw new TypeError("File path is required");
}
} else {
const data =
filePath.startsWith("s3://") ||
filePath.startsWith("http://") ||
filePath.startsWith("https://")
? filePath
: await fs.readFile(filePath);
return this.loadDataAsContent(data, filePath);
}
}
/**
* Loads data from a file and returns an array of Document objects.
* To be used with resultType "text" or "markdown".
*
* @param fileContent - The content of the file as a Uint8Array.
* @param filename - Optional filename for the file.
* @returns A Promise that resolves to an array of Document objects.
*/
async loadDataAsContent(
fileContent: Uint8Array | string,
filename?: string,
): Promise<Document[]> {
return this.#createJob(fileContent, filename)
.then(async (jobId) => {
if (this.verbose) {
console.log(`Started parsing the file under job id ${jobId}`);
}
// Return results as Document objects.
const jobResults = await this.getJobResult(jobId, this.resultType);
const resultText = jobResults[this.resultType];
// Split the text by separator if splitByPage is true.
if (this.splitByPage) {
return this.splitTextBySeparator(resultText);
}
return [new Document({ text: resultText })];
})
.catch((error) => {
console.warn(
`Error while parsing the file with: ${error.message ?? error.detail}`,
);
if (this.ignoreErrors) {
return [];
} else {
throw error;
}
});
}
/**
* Loads data from a file and returns an array of JSON objects.
* To be used with resultType "json".
*
* @param filePathOrContent - The file path or the file content as a Uint8Array.
* @returns A Promise that resolves to an array of JSON objects.
*/
async loadJson(
filePathOrContent: string | Uint8Array,
): Promise<Record<string, any>[]> {
let jobId;
const isFilePath =
typeof filePathOrContent === "string" &&
!(
filePathOrContent.startsWith("s3://") ||
filePathOrContent.startsWith("http://") ||
filePathOrContent.startsWith("https://")
);
try {
const data = isFilePath
? await fs.readFile(filePathOrContent)
: filePathOrContent;
// Create a job for the file.
jobId = await this.#createJob(
data,
isFilePath ? path.basename(filePathOrContent) : undefined,
);
if (this.verbose) {
console.log(`Started parsing the file under job id ${jobId}`);
}
// Return results as an array of JSON objects.
const resultJson = await this.getJobResult(jobId, "json");
resultJson.job_id = jobId;
resultJson.file_path = isFilePath ? filePathOrContent : undefined;
return [resultJson];
} catch (e) {
console.error(`Error while parsing the file under job id ${jobId}`, e);
if (this.ignoreErrors) {
return [];
} else {
throw e;
}
}
}
/**
* Downloads and saves images from a given JSON result to a specified download path.
* Currently only supports resultType "json".
*
* @param jsonResult - The JSON result containing image information.
* @param downloadPath - The path where the downloaded images will be saved.
* @returns A Promise that resolves to an array of image objects.
*/
async getImages(
jsonResult: Record<string, any>[],
downloadPath: string,
): Promise<Record<string, any>[]> {
try {
// Create download directory if it doesn't exist (checks for write access).
try {
await fs.access(downloadPath);
} catch {
await fs.mkdir(downloadPath, { recursive: true });
}
const images: Record<string, any>[] = [];
for (const result of jsonResult) {
const jobId = result.job_id;
for (const page of result.pages) {
if (this.verbose) {
console.log(`> Image for page ${page.page}: ${page.images}`);
}
for (const image of page.images) {
const imageName = image.name;
const imagePath = await this.getImagePath(
downloadPath,
jobId,
imageName,
);
await this.fetchAndSaveImage(imageName, imagePath, jobId);
// Assign metadata to the image.
image.path = imagePath;
image.job_id = jobId;
image.original_pdf_path = result.file_path;
image.page_number = page.page;
images.push(image);
}
}
}
return images;
} catch (e) {
console.error(`Error while downloading images from the parsed result`, e);
if (this.ignoreErrors) {
return [];
} else {
throw e;
}
}
}
/**
* Constructs the file path for an image.
*
* @param downloadPath - The base download directory.
* @param jobId - The job ID.
* @param imageName - The image name.
* @returns A Promise that resolves to the full image path.
*/
private async getImagePath(
downloadPath: string,
jobId: string,
imageName: string,
): Promise<string> {
return path.join(downloadPath, `${jobId}-${imageName}`);
}
/**
* Fetches an image from the API and saves it to the specified path.
*
* @param imageName - The name of the image.
* @param imagePath - The local path to save the image.
* @param jobId - The associated job ID.
*/
private async fetchAndSaveImage(
imageName: string,
imagePath: string,
jobId: string,
): Promise<void> {
const response =
await getJobImageResultApiV1ParsingJobJobIdResultImageNameGet({
client: this.#client,
path: {
job_id: jobId,
name: imageName,
},
});
if (response.error) {
throw new Error(`Failed to download image: ${response.error.detail}`);
}
const blob = (await response.data) as Blob;
// Write the image buffer to the specified imagePath.
await fs.writeFile(imagePath, new Uint8Array(await blob.arrayBuffer()));
}
/**
* Filters out invalid values (null, undefined, empty string) for specific parameters.
*
* @param params - The parameters object.
* @param keysToCheck - The keys to check for valid values.
* @returns A new object with filtered parameters.
*/
private filterSpecificParams(
params: Record<string, any>,
keysToCheck: string[],
): Record<string, any> {
const filteredParams: Record<string, any> = {};
for (const [key, value] of Object.entries(params)) {
if (keysToCheck.includes(key)) {
if (value !== null && value !== undefined && value !== "") {
filteredParams[key] = value;
}
} else {
filteredParams[key] = value;
}
}
return filteredParams;
}
/**
* Splits text into Document objects using the page separator.
*
* @param text - The text to be split.
* @returns An array of Document objects.
*/
private splitTextBySeparator(text: string): Document[] {
const separator = this.pageSeparator ?? "\n---\n";
const textChunks = text.split(separator);
return textChunks.map(
(docChunk: string) =>
new Document({
text: docChunk,
}),
);
}
}
-131
View File
@@ -1,131 +0,0 @@
import { FailPageMode, ParserLanguages, ParsingMode } from "./client";
import { z } from "zod";
type Language = 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({
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(),
auto_mode_configuration_json: 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(),
input_s3_path: z.string().optional(),
input_s3_region: z.string().optional(),
input_url: z.string().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(),
save_images: 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(),
compact_markdown_table: z.boolean().optional(),
markdown_table_multiline_header_separator: z.string().optional(),
page_error_tolerance: z.number().min(0).max(1).optional(),
replace_failed_page_mode: z.nativeEnum(FailPageMode).nullable().optional(),
replace_failed_page_with_error_message_prefix: z.string().optional(),
replace_failed_page_with_error_message_suffix: z.string().optional(),
});
-3
View File
@@ -1,3 +0,0 @@
export async function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
-23
View File
@@ -1,23 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist/type",
"tsBuildInfoFile": "./dist/.tsbuildinfo",
"emitDeclarationOnly": true,
"moduleResolution": "Bundler",
"skipLibCheck": true,
"strict": true,
"types": []
},
"include": ["./src"],
"exclude": ["node_modules"],
"references": [
{
"path": "../core/tsconfig.json"
},
{
"path": "../env/tsconfig.json"
}
]
}
-9
View File
@@ -1,9 +0,0 @@
{
"$schema": "https://turbo.build/schema.json",
"extends": ["//"],
"tasks": {
"build": {
"outputs": ["**/dist/**", "src/client/**"]
}
}
}
-8
View File
@@ -1,8 +0,0 @@
{
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": "./dist/index.js",
"private": true
}
-12
View File
@@ -20,7 +20,6 @@
"llamaindex"
],
"dependencies": {
"@llamaindex/cloud": "workspace:*",
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*",
"@llamaindex/node-parser": "workspace:*",
@@ -73,17 +72,6 @@
},
"default": "./agent/dist/index.js"
},
"./cloud": {
"require": {
"types": "./cloud/dist/index.d.cts",
"default": "./cloud/dist/index.cjs"
},
"import": {
"types": "./cloud/dist/index.d.ts",
"default": "./cloud/dist/index.js"
},
"default": "./cloud/dist/index.js"
},
"./engines": {
"require": {
"types": "./engines/dist/index.d.cts",
@@ -1,120 +0,0 @@
import {
addFilesToPipelineApiApiV1PipelinesPipelineIdFilesPut,
getPipelineFileStatusApiV1PipelinesPipelineIdFilesFileIdStatusGet,
listPipelineFilesApiV1PipelinesPipelineIdFilesGet,
listProjectsApiV1ProjectsGet,
readFileContentApiV1FilesIdContentGet,
searchPipelinesApiV1PipelinesGet,
uploadFileApiV1FilesPost,
} from "@llamaindex/cloud/api";
import { initService } from "./utils.js";
export class LLamaCloudFileService {
/**
* Get list of projects, each project contains a list of pipelines
*/
public static async getAllProjectsWithPipelines() {
initService();
try {
const { data: projects } = await listProjectsApiV1ProjectsGet({
throwOnError: true,
});
const { data: pipelines } = await searchPipelinesApiV1PipelinesGet({
throwOnError: true,
});
return projects.map((project) => ({
...project,
pipelines: pipelines.filter((p) => p.project_id === project.id),
}));
} catch (error) {
console.error("Error listing projects and pipelines:", error);
return [];
}
}
/**
* Upload a file to a pipeline in LlamaCloud
*/
public static async addFileToPipeline(
projectId: string,
pipelineId: string,
uploadFile: File | Blob,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
customMetadata: Record<string, any> = {},
) {
initService();
const { data: file } = await uploadFileApiV1FilesPost({
query: { project_id: projectId },
body: {
upload_file: uploadFile,
},
throwOnError: true,
});
const files = [
{
file_id: file.id,
custom_metadata: { file_id: file.id, ...customMetadata },
},
];
await addFilesToPipelineApiApiV1PipelinesPipelineIdFilesPut({
path: {
pipeline_id: pipelineId,
},
body: files,
});
// Wait 2s for the file to be processed
const maxAttempts = 20;
let attempt = 0;
while (attempt < maxAttempts) {
const { data: result } =
await getPipelineFileStatusApiV1PipelinesPipelineIdFilesFileIdStatusGet(
{
path: {
pipeline_id: pipelineId,
file_id: file.id,
},
throwOnError: true,
},
);
if (result.status === "ERROR") {
throw new Error(`File processing failed: ${JSON.stringify(result)}`);
}
if (result.status === "SUCCESS") {
// File is ingested - return the file id
return file.id;
}
attempt += 1;
await new Promise((resolve) => setTimeout(resolve, 100)); // Sleep for 100ms
}
throw new Error(
`File processing did not complete after ${maxAttempts} attempts. Check your LlamaCloud index at https://cloud.llamaindex.ai/project/${projectId}/deploy/${pipelineId} for more details.`,
);
}
/**
* Get download URL for a file in LlamaCloud
*/
public static async getFileUrl(pipelineId: string, filename: string) {
initService();
const { data: allPipelineFiles } =
await listPipelineFilesApiV1PipelinesPipelineIdFilesGet({
path: {
pipeline_id: pipelineId,
},
throwOnError: true,
});
const file = allPipelineFiles.find((file) => file.name === filename);
if (!file?.file_id) return null;
const { data: fileContent } = await readFileContentApiV1FilesIdContentGet({
path: {
id: file.file_id,
},
query: {
project_id: file.project_id,
},
throwOnError: true,
});
return fileContent.url;
}
}
@@ -1,414 +0,0 @@
import type { BaseNodePostprocessor } from "@llamaindex/core/postprocessor";
import type { BaseQueryEngine } from "@llamaindex/core/query-engine";
import type { BaseSynthesizer } from "@llamaindex/core/response-synthesizers";
import type { Document } from "@llamaindex/core/schema";
import { RetrieverQueryEngine } from "../engines/query/RetrieverQueryEngine.js";
import type { CloudRetrieveParams } from "./LlamaCloudRetriever.js";
import { LlamaCloudRetriever } from "./LlamaCloudRetriever.js";
import type { CloudConstructorParams } from "./type.js";
import {
getAppBaseUrl,
getPipelineId,
getProjectId,
initService,
} from "./utils.js";
import {
createBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPost,
deletePipelineDocumentApiV1PipelinesPipelineIdDocumentsDocumentIdDelete,
getPipelineDocumentStatusApiV1PipelinesPipelineIdDocumentsDocumentIdStatusGet,
getPipelineStatusApiV1PipelinesPipelineIdStatusGet,
type PipelineCreateReadable,
searchPipelinesApiV1PipelinesGet,
upsertBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPut,
upsertPipelineApiV1PipelinesPut,
} from "@llamaindex/cloud/api";
import type { BaseRetriever } from "@llamaindex/core/retriever";
import { getEnv } from "@llamaindex/env";
import type { QueryToolParams } from "../indices/BaseIndex.js";
import { Settings } from "../Settings.js";
import { QueryEngineTool } from "../tools/QueryEngineTool.js";
export class LlamaCloudIndex {
params: CloudConstructorParams;
constructor(params: CloudConstructorParams) {
this.params = params;
initService(this.params);
}
private async waitForPipelineIngestion(
verbose = Settings.debug,
raiseOnError = false,
): Promise<void> {
const pipelineId = await this.getPipelineId();
if (verbose) {
console.log("Waiting for pipeline ingestion: ");
}
while (true) {
const { data: pipelineStatus } =
await getPipelineStatusApiV1PipelinesPipelineIdStatusGet({
path: {
pipeline_id: pipelineId,
},
throwOnError: true,
});
if (pipelineStatus.status === "SUCCESS") {
if (verbose) {
console.log("Pipeline ingestion completed successfully");
}
break;
}
if (pipelineStatus.status === "ERROR") {
if (verbose) {
console.error("Pipeline ingestion failed");
}
if (raiseOnError) {
throw new Error("Pipeline ingestion failed");
}
}
if (verbose) {
process.stdout.write(".");
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}
private async waitForDocumentIngestion(
docIds: string[],
verbose = Settings.debug,
raiseOnError = false,
): Promise<void> {
const pipelineId = await this.getPipelineId();
if (verbose) {
console.log("Loading data: ");
}
const pendingDocs = new Set(docIds);
while (pendingDocs.size) {
const docsToRemove = new Set<string>();
for (const doc of pendingDocs) {
const {
data: { status },
} =
await getPipelineDocumentStatusApiV1PipelinesPipelineIdDocumentsDocumentIdStatusGet(
{
path: { pipeline_id: pipelineId, document_id: doc },
throwOnError: true,
},
);
if (status === "NOT_STARTED" || status === "IN_PROGRESS") {
continue;
}
if (status === "ERROR") {
if (verbose) {
console.error(`Document ingestion failed for ${doc}`);
}
if (raiseOnError) {
throw new Error(`Document ingestion failed for ${doc}`);
}
}
docsToRemove.add(doc);
}
for (const doc of docsToRemove) {
pendingDocs.delete(doc);
}
if (pendingDocs.size) {
if (verbose) {
process.stdout.write(".");
}
await new Promise((resolve) => setTimeout(resolve, 500));
}
}
if (verbose) {
console.log("Done!");
}
await this.waitForPipelineIngestion(verbose, raiseOnError);
}
public async getPipelineId(
name?: string,
projectName?: string,
organizationId?: string,
): Promise<string> {
return await getPipelineId(
name ?? this.params.name,
projectName ?? this.params.projectName,
organizationId ?? this.params.organizationId,
);
}
public async getProjectId(
projectName?: string,
organizationId?: string,
): Promise<string> {
return await getProjectId(
projectName ?? this.params.projectName,
organizationId ?? this.params.organizationId,
);
}
/**
* Adds documents to the given index parameters. If the index does not exist, it will be created.
*
* @param params - An object containing the following properties:
* - documents: An array of Document objects to be added to the index.
* - verbose: Optional boolean to enable verbose logging.
* - Additional properties from CloudConstructorParams.
* @returns A Promise that resolves to a new LlamaCloudIndex instance.
*/
static async fromDocuments(
params: {
documents: Document[];
verbose?: boolean;
} & CloudConstructorParams,
config?: {
embedding: PipelineCreateReadable["embedding_config"];
transform: PipelineCreateReadable["transform_config"];
},
): Promise<LlamaCloudIndex> {
const index = new LlamaCloudIndex({ ...params });
await index.ensureIndex({ ...config, verbose: params.verbose ?? false });
await index.addDocuments(params.documents, params.verbose);
return index;
}
async addDocuments(documents: Document[], verbose?: boolean): Promise<void> {
const apiUrl = getAppBaseUrl();
const projectId = await this.getProjectId();
const pipelineId = await this.getPipelineId();
await upsertBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPut({
path: {
pipeline_id: pipelineId,
},
body: documents.map((doc) => ({
metadata: doc.metadata,
text: doc.text,
excluded_embed_metadata_keys: doc.excludedEmbedMetadataKeys,
excluded_llm_metadata_keys: doc.excludedEmbedMetadataKeys,
id: doc.id_,
})),
});
while (true) {
const { data: pipelineStatus } =
await getPipelineStatusApiV1PipelinesPipelineIdStatusGet({
path: { pipeline_id: pipelineId },
throwOnError: true,
});
if (pipelineStatus.status === "SUCCESS") {
console.info(
"Documents ingested successfully, pipeline is ready to use",
);
break;
}
if (pipelineStatus.status === "ERROR") {
console.error(
`Some documents failed to ingest, check your pipeline logs at ${apiUrl}/project/${projectId}/deploy/${pipelineId}`,
);
throw new Error("Some documents failed to ingest");
}
if (pipelineStatus.status === "PARTIAL_SUCCESS") {
console.info(
`Documents ingestion partially succeeded, to check a more complete status check your pipeline at ${apiUrl}/project/${projectId}/deploy/${pipelineId}`,
);
break;
}
if (verbose) {
process.stdout.write(".");
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
if (verbose) {
console.info(
`Ingestion completed, find your index at ${apiUrl}/project/${projectId}/deploy/${pipelineId}`,
);
}
}
asRetriever(params: CloudRetrieveParams = {}): BaseRetriever {
return new LlamaCloudRetriever({ ...this.params, ...params });
}
asQueryEngine(
params?: {
responseSynthesizer?: BaseSynthesizer;
preFilters?: unknown;
nodePostprocessors?: BaseNodePostprocessor[];
} & CloudRetrieveParams,
): BaseQueryEngine {
const retriever = new LlamaCloudRetriever({
...this.params,
...params,
});
return new RetrieverQueryEngine(
retriever,
params?.responseSynthesizer,
params?.nodePostprocessors,
);
}
asQueryTool(params: QueryToolParams): QueryEngineTool {
if (params.options) {
params.retriever = this.asRetriever(params.options);
}
return new QueryEngineTool({
queryEngine: this.asQueryEngine(params),
metadata: params?.metadata,
includeSourceNodes: params?.includeSourceNodes ?? false,
});
}
queryTool(params: QueryToolParams): QueryEngineTool {
return this.asQueryTool(params);
}
async insert(document: Document) {
const pipelineId = await this.getPipelineId();
await createBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPost({
path: {
pipeline_id: pipelineId,
},
body: [
{
metadata: document.metadata,
text: document.text,
excluded_embed_metadata_keys: document.excludedLlmMetadataKeys,
excluded_llm_metadata_keys: document.excludedEmbedMetadataKeys,
id: document.id_,
},
],
});
await this.waitForDocumentIngestion([document.id_]);
}
async delete(document: Document) {
const pipelineId = await this.getPipelineId();
await deletePipelineDocumentApiV1PipelinesPipelineIdDocumentsDocumentIdDelete(
{
path: {
pipeline_id: pipelineId,
document_id: document.id_,
},
},
);
await this.waitForPipelineIngestion();
}
async refreshDoc(document: Document) {
const pipelineId = await this.getPipelineId();
await upsertBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPut({
path: {
pipeline_id: pipelineId,
},
body: [
{
metadata: document.metadata,
text: document.text,
excluded_embed_metadata_keys: document.excludedLlmMetadataKeys,
excluded_llm_metadata_keys: document.excludedEmbedMetadataKeys,
id: document.id_,
},
],
});
await this.waitForDocumentIngestion([document.id_]);
}
public async ensureIndex(config?: {
embedding?: PipelineCreateReadable["embedding_config"];
transform?: PipelineCreateReadable["transform_config"];
verbose?: boolean;
}): Promise<void> {
const projectId = await this.getProjectId();
const { data: pipelines } = await searchPipelinesApiV1PipelinesGet({
query: {
project_id: projectId,
pipeline_name: this.params.name,
},
throwOnError: true,
});
if (pipelines.length === 0) {
// no pipeline found, create a new one
let embeddingConfig = config?.embedding;
if (!embeddingConfig) {
// no embedding config provided, use OpenAI as default
const openAIApiKey = getEnv("OPENAI_API_KEY");
const embeddingModel = getEnv("EMBEDDING_MODEL");
if (!openAIApiKey || !embeddingModel) {
throw new Error(
"No embedding configuration provided. Fallback to OpenAI embedding model. OPENAI_API_KEY and EMBEDDING_MODEL environment variables must be set.",
);
}
embeddingConfig = {
type: "OPENAI_EMBEDDING",
component: {
api_key: openAIApiKey,
model_name: embeddingModel,
},
};
}
let transformConfig = config?.transform;
if (!transformConfig) {
transformConfig = {
mode: "auto",
chunk_size: 1024,
chunk_overlap: 200,
};
}
const { data: pipeline } = await upsertPipelineApiV1PipelinesPut({
query: {
project_id: projectId,
},
body: {
name: this.params.name,
embedding_config: embeddingConfig,
transform_config: transformConfig,
},
throwOnError: true,
});
if (config?.verbose) {
console.log(
`Created pipeline ${pipeline.id} with name ${pipeline.name}`,
);
}
}
}
}
@@ -1,103 +0,0 @@
import {
type MetadataFilter,
type MetadataFilters,
type RetrievalParams,
runSearchApiV1PipelinesPipelineIdRetrievePost,
type TextNodeWithScore,
} from "@llamaindex/cloud/api";
import { DEFAULT_PROJECT_NAME } from "@llamaindex/core/global";
import type { QueryBundle } from "@llamaindex/core/query-engine";
import { BaseRetriever } from "@llamaindex/core/retriever";
import type { NodeWithScore } from "@llamaindex/core/schema";
import { jsonToNode, ObjectType } from "@llamaindex/core/schema";
import { extractText } from "@llamaindex/core/utils";
import type { ClientParams, CloudConstructorParams } from "./type.js";
import { getPipelineId, initService } from "./utils.js";
export type CloudRetrieveParams = Omit<
RetrievalParams,
"query" | "search_filters" | "dense_similarity_top_k"
> & { similarityTopK?: number; filters?: MetadataFilters };
export class LlamaCloudRetriever extends BaseRetriever {
clientParams: ClientParams;
retrieveParams: CloudRetrieveParams;
organizationId?: string;
projectName: string = DEFAULT_PROJECT_NAME;
pipelineName: string;
private resultNodesToNodeWithScore(
nodes: TextNodeWithScore[],
): NodeWithScore[] {
return nodes.map((node: TextNodeWithScore) => {
const textNode = jsonToNode(node.node, ObjectType.TEXT);
textNode.metadata = {
...textNode.metadata,
...node.node.extra_info, // append LlamaCloud extra_info to node metadata (file_name, pipeline_id, etc.)
};
return {
// Currently LlamaCloud only supports text nodes
node: textNode,
score: node.score ?? undefined,
};
});
}
// LlamaCloud expects null values for filters, but LlamaIndexTS uses undefined for empty values
// This function converts the undefined values to null
private convertFilter(filters?: MetadataFilters): MetadataFilters | null {
if (!filters) return null;
const processFilter = (
filter: MetadataFilter | MetadataFilters,
): MetadataFilter | MetadataFilters => {
if ("filters" in filter) {
// type MetadataFilters
return { ...filter, filters: filter.filters.map(processFilter) };
}
return { ...filter, value: filter.value ?? null };
};
return { ...filters, filters: filters.filters.map(processFilter) };
}
constructor(params: CloudConstructorParams & CloudRetrieveParams) {
super();
this.clientParams = { apiKey: params.apiKey, baseUrl: params.baseUrl };
initService(this.clientParams);
this.retrieveParams = params;
this.pipelineName = params.name;
if (params.projectName) {
this.projectName = params.projectName;
}
if (params.organizationId) {
this.organizationId = params.organizationId;
}
}
async _retrieve(query: QueryBundle): Promise<NodeWithScore[]> {
const pipelineId = await getPipelineId(
this.pipelineName,
this.projectName,
this.organizationId,
);
const filters = this.convertFilter(this.retrieveParams.filters);
const { data: results } =
await runSearchApiV1PipelinesPipelineIdRetrievePost({
throwOnError: true,
path: {
pipeline_id: pipelineId,
},
body: {
...this.retrieveParams,
query: extractText(query),
search_filters: filters,
dense_similarity_top_k: this.retrieveParams.similarityTopK!,
},
});
return this.resultNodesToNodeWithScore(results.retrieval_nodes);
}
}
-13
View File
@@ -1,13 +0,0 @@
console.warn(`
The classes LlamaCloudFileService, LlamaCloudIndex and LlamaCloudRetriever have been moved to the package llama-cloud-services.
* Please migrate your imports to llama-cloud-services, e.g. import { LlamaCloudIndex } from "llama-cloud-services";
* See the documentation: https://docs.cloud.llamaindex.ai
`);
export { LLamaCloudFileService } from "./LLamaCloudFileService.js";
export { LlamaCloudIndex } from "./LlamaCloudIndex.js";
export {
LlamaCloudRetriever,
type CloudRetrieveParams,
} from "./LlamaCloudRetriever.js";
export type { CloudConstructorParams } from "./type.js";
-10
View File
@@ -1,10 +0,0 @@
export type ClientParams = {
apiKey?: string | undefined;
baseUrl?: string | undefined;
};
export type CloudConstructorParams = {
name: string;
projectName: string;
organizationId?: string | undefined;
} & ClientParams;
-97
View File
@@ -1,97 +0,0 @@
import {
client,
listProjectsApiV1ProjectsGet,
searchPipelinesApiV1PipelinesGet,
} from "@llamaindex/cloud/api";
import { DEFAULT_BASE_URL } from "@llamaindex/core/global";
import { getEnv } from "@llamaindex/env";
import type { ClientParams } from "./type.js";
function getBaseUrl(baseUrl?: string): string {
return baseUrl ?? getEnv("LLAMA_CLOUD_BASE_URL") ?? DEFAULT_BASE_URL;
}
export function getAppBaseUrl(): string {
return client.getConfig().baseUrl?.replace(/api\./, "") ?? "";
}
// fixme: refactor this to init at the top level or module level
let initOnce = false;
export function initService({ apiKey, baseUrl }: ClientParams = {}) {
if (initOnce) {
return;
}
initOnce = true;
client.setConfig({
baseUrl: getBaseUrl(baseUrl),
throwOnError: true,
});
const token = apiKey ?? getEnv("LLAMA_CLOUD_API_KEY");
client.interceptors.request.use((request) => {
request.headers.set("Authorization", `Bearer ${token}`);
return request;
});
client.interceptors.error.use((error) => {
throw new Error(
`LlamaCloud API request failed. Error details: ${JSON.stringify(error)}`,
);
});
if (!token) {
throw new Error(
"API Key is required for LlamaCloudIndex. Please pass the apiKey parameter",
);
}
}
export async function getProjectId(
projectName: string,
organizationId?: string,
): Promise<string> {
const { data: projects } = await listProjectsApiV1ProjectsGet({
query: {
project_name: projectName,
organization_id: organizationId ?? null,
},
throwOnError: true,
});
if (projects.length === 0) {
throw new Error(
`Unknown project name ${projectName}. Please confirm a managed project with this name exists.`,
);
} else if (projects.length > 1) {
throw new Error(
`Multiple projects found with name ${projectName}. Please specify organization_id.`,
);
}
const project = projects[0]!;
if (!project.id) {
throw new Error(`No project found with name ${projectName}`);
}
return project.id;
}
export async function getPipelineId(
name: string,
projectName: string,
organizationId?: string,
): Promise<string> {
const { data: pipelines } = await searchPipelinesApiV1PipelinesGet({
query: {
project_id: await getProjectId(projectName, organizationId),
pipeline_name: name,
},
throwOnError: true,
});
if (pipelines.length === 0 || !pipelines[0]!.id) {
throw new Error(
`No pipeline found with name ${name} in project ${projectName}`,
);
}
return pipelines[0]!.id;
}
-6
View File
@@ -3,11 +3,6 @@ import { Settings } from "./Settings.js";
//#endregion
export {
LlamaParseReader,
type Language,
type ResultType,
} from "@llamaindex/cloud/reader";
export * from "@llamaindex/core/agent";
export * from "@llamaindex/core/chat-engine";
export * from "@llamaindex/core/data-structs";
@@ -57,7 +52,6 @@ export * from "@llamaindex/core/storage/index-store";
export * from "@llamaindex/core/storage/kv-store";
export * from "@llamaindex/core/utils";
export * from "./agent/index.js";
export * from "./cloud/index.js";
export * from "./engines/index.js";
export * from "./evaluation/index.js";
export * from "./extractors/index.js";
-3
View File
@@ -19,9 +19,6 @@
},
{
"path": "../env/tsconfig.json"
},
{
"path": "../cloud/tsconfig.json"
}
]
}
+89 -258
View File
@@ -83,9 +83,6 @@ importers:
'@llamaindex/chat-ui-docs':
specifier: ^0.1.0
version: 0.1.0
'@llamaindex/cloud':
specifier: workspace:*
version: link:../../packages/cloud
'@llamaindex/core':
specifier: workspace:*
version: link:../../packages/core
@@ -179,6 +176,9 @@ importers:
hast-util-to-jsx-runtime:
specifier: ^2.3.2
version: 2.3.6
llama-cloud-services:
specifier: ^0.3.5
version: 0.3.5(@llamaindex/core@packages+core)(@llamaindex/env@packages+env)(@llamaindex/workflow-core@1.3.2(@modelcontextprotocol/sdk@1.13.0)(hono@4.9.7)(next@15.3.3(@opentelemetry/api@1.9.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(p-retry@6.2.1)(zod@3.25.76))
llamaindex:
specifier: workspace:*
version: link:../../packages/llamaindex
@@ -420,22 +420,6 @@ importers:
specifier: ^3.87.0
version: 3.114.6(@cloudflare/workers-types@4.20250416.0)(bufferutil@4.0.9)
e2e/examples/llama-parse-browser:
dependencies:
'@llamaindex/cloud':
specifier: workspace:*
version: link:../../../packages/cloud
devDependencies:
typescript:
specifier: ^5.8.3
version: 5.8.3
vite:
specifier: ^6.3.6
version: 6.3.6(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.29.3)(terser@5.39.0)(tsx@4.20.3)(yaml@2.7.1)
vite-plugin-wasm:
specifier: ^3.4.1
version: 3.4.1(vite@6.3.6(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.29.3)(terser@5.39.0)(tsx@4.20.3)(yaml@2.7.1))
e2e/examples/nextjs-agent:
dependencies:
ai:
@@ -635,9 +619,6 @@ importers:
'@llamaindex/clip':
specifier: ^0.0.75
version: link:../packages/providers/clip
'@llamaindex/cloud':
specifier: ^4.1.3
version: link:../packages/cloud
'@llamaindex/cohere':
specifier: ^0.0.35
version: link:../packages/providers/cohere
@@ -776,6 +757,9 @@ importers:
js-tiktoken:
specifier: ^1.0.14
version: 1.0.19
llama-cloud-services:
specifier: ^0.3.5
version: 0.3.5(@llamaindex/core@packages+core)(@llamaindex/env@packages+env)(@llamaindex/workflow-core@1.3.2(@modelcontextprotocol/sdk@1.13.0)(hono@4.9.7)(next@15.3.3(@opentelemetry/api@1.9.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(p-retry@6.2.1)(zod@4.1.5))
llamaindex:
specifier: ^0.11.29
version: link:../packages/llamaindex
@@ -869,9 +853,6 @@ importers:
examples/readers:
dependencies:
'@llamaindex/cloud':
specifier: workspace:* || ^2.0.24
version: link:../../packages/cloud
'@llamaindex/excel':
specifier: workspace:*
version: link:../../packages/providers/excel
@@ -968,31 +949,6 @@ importers:
specifier: ^4.20.3
version: 4.20.3
packages/cloud:
dependencies:
p-retry:
specifier: ^6.2.1
version: 6.2.1
zod:
specifier: ^3.25.76
version: 3.25.76
devDependencies:
'@hey-api/client-fetch':
specifier: ^0.10.1
version: 0.10.1(@hey-api/openapi-ts@0.67.5(typescript@5.9.2))
'@hey-api/openapi-ts':
specifier: ^0.67.5
version: 0.67.5(typescript@5.9.2)
'@llama-flow/core':
specifier: ^0.4.1
version: 0.4.1(@modelcontextprotocol/sdk@1.13.0)(hono@4.9.7)(next@15.3.3(@opentelemetry/api@1.9.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(p-retry@6.2.1)(zod@3.25.76)
'@llamaindex/core':
specifier: workspace:*
version: link:../core
'@llamaindex/env':
specifier: workspace:*
version: link:../env
packages/community:
dependencies:
'@aws-sdk/client-bedrock-agent-runtime':
@@ -1116,9 +1072,6 @@ importers:
packages/llamaindex:
dependencies:
'@llamaindex/cloud':
specifier: workspace:*
version: link:../cloud
'@llamaindex/core':
specifier: workspace:*
version: link:../core
@@ -1959,9 +1912,6 @@ importers:
unit:
dependencies:
'@llamaindex/cloud':
specifier: workspace:*
version: link:../packages/cloud
'@llamaindex/core':
specifier: workspace:*
version: link:../packages/core
@@ -3773,23 +3723,6 @@ packages:
peerDependencies:
vue: ^3.2.0
'@hey-api/client-fetch@0.10.1':
resolution: {integrity: sha512-C1XZEnzvOIdXppvMcnO8/V/RpcORxA4rh+5qjuMcItkV++hv7aBz7tSLd0z+bSLFUwttec077WT/nPS+oO4BiA==}
deprecated: Starting with v0.73.0, this package is bundled directly inside @hey-api/openapi-ts.
peerDependencies:
'@hey-api/openapi-ts': < 2
'@hey-api/json-schema-ref-parser@1.0.6':
resolution: {integrity: sha512-yktiFZoWPtEW8QKS65eqKwA5MTKp88CyiL8q72WynrBs/73SAaxlSWlA2zW/DZlywZ5hX1OYzrCC0wFdvO9c2w==}
engines: {node: '>= 16'}
'@hey-api/openapi-ts@0.67.5':
resolution: {integrity: sha512-fZd+3im0038rnK7W0mAfLTrdygCR/k6zq7XfYZj/wu0/3GvIg/aGlOwMUtZinRJBH21W+GoH0MJoce3BagVXsw==}
engines: {node: ^18.18.0 || ^20.9.0 || >=22.10.0}
hasBin: true
peerDependencies:
typescript: ^5.5.3
'@hono/node-server@1.14.0':
resolution: {integrity: sha512-YUCxJwgHRKSqjrdTk9e4VMGKN27MK5r4+MGPyZTgKH+IYbK+KtYbHeOcPGJ91KGGD6RIQiz2dAHxvjauNhOS8g==}
engines: {node: '>=18.14.1'}
@@ -4259,29 +4192,6 @@ packages:
'@lezer/yaml@1.0.3':
resolution: {integrity: sha512-GuBLekbw9jDBDhGur82nuwkxKQ+a3W5H0GfaAthDXcAu+XdpS43VlnxA9E9hllkpSP5ellRDKjLLj7Lu9Wr6xA==}
'@llama-flow/core@0.4.1':
resolution: {integrity: sha512-xHhJMRmY16C1pYPWIonmLWPkkjTGuj1iVQCTXOM6sXajQ3r0+mEVERQCjPqf48tvX0K+szbdgxjg6wx+KwVqcg==}
peerDependencies:
'@modelcontextprotocol/sdk': ^1.7.0
hono: ^4.7.4
next: ^15.2.2
p-retry: ^6.2.1
rxjs: ^7.8.2
zod: ^3.24.2
peerDependenciesMeta:
'@modelcontextprotocol/sdk':
optional: true
hono:
optional: true
next:
optional: true
p-retry:
optional: true
rxjs:
optional: true
zod:
optional: true
'@llamaindex/chat-ui-docs@0.1.0':
resolution: {integrity: sha512-+DwnLSWDOJk2d6lGDhLYtmpeGHho4AjKE2aQMz8J0ZF29RlSqp/Z5HmhQoYIjK0neIM1S9eF7ubuM1zpVpZqrg==}
@@ -6702,6 +6612,10 @@ packages:
peerDependencies:
vue: ^2.7.0 || ^3.0.0
'@tokenizer/inflate@0.2.7':
resolution: {integrity: sha512-MADQgmZT1eKjp06jpI2yozxaU9uVs4GzzgSL+uEq7bVcJ9V1ZXQkeGNql1fsSI0gMy1vhvNTNbUqrx+pZfJVmg==}
engines: {node: '>=18'}
'@tokenizer/token@0.3.0':
resolution: {integrity: sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A==}
@@ -7980,14 +7894,6 @@ packages:
resolution: {integrity: sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==}
engines: {node: '>= 0.8'}
c12@2.0.1:
resolution: {integrity: sha512-Z4JgsKXHG37C6PYUtIxCfLJZvo6FyhHJoClwwb9ftUkLpPSkuYqn6Tr+vnaN8hymm0kIbcg6Ey3kv/Q71k5w/A==}
peerDependencies:
magicast: ^0.3.5
peerDependenciesMeta:
magicast:
optional: true
cac@6.7.14:
resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==}
engines: {node: '>=8'}
@@ -8142,9 +8048,6 @@ packages:
resolution: {integrity: sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==}
engines: {node: '>=8'}
citty@0.1.6:
resolution: {integrity: sha512-tskPPKEs8D2KPafUypv2gxwJP8h/OaJmC82QQGGDQcHvXX43xF2VDACcJVmZ0EuSxkpO9Kc4MlrA3q0+FG58AQ==}
cjs-module-lexer@1.4.3:
resolution: {integrity: sha512-9z8TZaGM1pfswYeXrUpzPrkx8UnWYdhJclsiYMm6x/w5+nN+8Tf/LnAgfLGQCm59qAOxU8WwHEq2vNwF6i4j+Q==}
@@ -8269,10 +8172,6 @@ packages:
resolution: {integrity: sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==}
engines: {node: '>=18'}
commander@13.0.0:
resolution: {integrity: sha512-oPYleIY8wmTVzkvQq10AEok6YcTC4sRUBl8F9gVuwchGVUCTbl/vhLTaQqutuuySYOsu8YTgV+OxKc/8Yvx+mQ==}
engines: {node: '>=18'}
commander@13.1.0:
resolution: {integrity: sha512-/rFeCpNJQbhSZjGVwO9RFV3xPqbnERS8MmIQzCtD/zl6gpJuV/bMLuN92oG3F7d8oDEHHRrujSXNUr8fpjntKw==}
engines: {node: '>=18'}
@@ -8543,9 +8442,6 @@ packages:
resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==}
engines: {node: '>=6'}
destr@2.0.3:
resolution: {integrity: sha512-2N3BOUU4gYMpTP24s5rF5iP7BDr7uNTCs4ozw3kf/eKfvWSIu93GEBi5m427YoyJoeOzQ5smuu4nNAPGb8idSQ==}
detect-indent@6.1.0:
resolution: {integrity: sha512-reYkTUJAZb9gUuZ2RvVCNhVHdg62RHnJ7WJl8ftMi4diZ6NWlciOzQN88pUhSELEwflJht4oQDv0F0BMlwaYtA==}
engines: {node: '>=8'}
@@ -9193,6 +9089,9 @@ packages:
resolution: {integrity: sha512-Lo6UPdMKKc9Ond7yjG2vq0mnocspOLh1oV6+XZdtfdexacvMSz5xm3WoQhTAdoR2+UqPlyMNqcqfecipoD+l/A==}
engines: {node: '>=12'}
fflate@0.8.2:
resolution: {integrity: sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==}
file-entry-cache@8.0.0:
resolution: {integrity: sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==}
engines: {node: '>=16.0.0'}
@@ -9201,6 +9100,10 @@ packages:
resolution: {integrity: sha512-VZR5I7k5wkD0HgFnMsq5hOsSc710MJMu5Nc5QYsbe38NN5iPV/XTObYLc/cpttRTf6lX538+5uO1ZQRhYibiZQ==}
engines: {node: '>=18'}
file-type@21.0.0:
resolution: {integrity: sha512-ek5xNX2YBYlXhiUXui3D/BXa3LdqPmoLJ7rqEx2bKJ7EAUEfmXgW0Das7Dc6Nr9MvqaOnIqiPV0mZk/r/UpNAg==}
engines: {node: '>=20'}
filename-reserved-regex@3.0.0:
resolution: {integrity: sha512-hn4cQfU6GOT/7cFHXBqeBg2TbrMBgdD0kcjLhvSQYYwm3s4B6cjvBfb7nBALJLAXqmU5xajSa7X2NnUud/VCdw==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
@@ -9558,10 +9461,6 @@ packages:
resolution: {integrity: sha512-E1b1lFFLvLgak2whF2xDBcOy6NLVGZBqqjJjsIhvopKfWWEi64pLVTWWehV8KlLerZkfNTA95sTe2OdJKm1OzQ==}
engines: {node: '>= 14'}
giget@1.2.4:
resolution: {integrity: sha512-Wv+daGyispVoA31TrWAVR+aAdP7roubTPEM/8JzRnqXhLbdJH0T9eQyXVFF8fjk3WKTsctII6QcyxILYgNp2DA==}
hasBin: true
github-from-package@0.0.0:
resolution: {integrity: sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==}
@@ -9681,11 +9580,6 @@ packages:
guid-typescript@1.0.9:
resolution: {integrity: sha512-Y8T4vYhEfwJOTbouREvG+3XDsjr8E3kIr7uf+JZ0BYloFsttiHU0WfvANVsR7TxNUJa/WpCnw/Ino/p+DeBhBQ==}
handlebars@4.7.8:
resolution: {integrity: sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==}
engines: {node: '>=0.4.7'}
hasBin: true
happy-dom@15.11.7:
resolution: {integrity: sha512-KyrFvnl+J9US63TEzwoiJOQzZBJY7KgBushJA8X61DMbNsH+2ONkDuLDnCnwUiPTF42tLoEmrPyoqbenVA5zrg==}
engines: {node: '>=18.0.0'}
@@ -10559,6 +10453,13 @@ packages:
resolution: {integrity: sha512-iyAZCeyD+c1gPyE9qpFu8af0Y+MRtmKOncdGoA2S5EY8iFq99dmmvkNnHiWo+pj0s7yH7l3KPIgee77tKpXPWQ==}
engines: {node: '>=18.0.0'}
llama-cloud-services@0.3.5:
resolution: {integrity: sha512-zhVmzi8mTD2wVUzYPKUxMDV91zU21pJ2lRKioqjns5Wnh6+7CswOCilRTVS1f0iuiB+K9D2mQFibcXOdsKY5Nw==}
peerDependencies:
'@llamaindex/core': ^0.6.19
'@llamaindex/env': ^0.1.30
'@llamaindex/workflow-core': ^0.4.1
loader-runner@4.3.0:
resolution: {integrity: sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==}
engines: {node: '>=6.11.5'}
@@ -11060,9 +10961,6 @@ packages:
engines: {node: '>=10'}
hasBin: true
mlly@1.7.4:
resolution: {integrity: sha512-qmdSIPC4bDJXgZTCR7XosJiNKySV7O215tsPtDN9iEO/7q/76b/ijtgRu/+epFXSJhijtTCCGp3DWS549P3xKw==}
mlly@1.8.0:
resolution: {integrity: sha512-l8D9ODSRWLe2KHJSifWGwBqpTZXIXTeo8mlKjY+E2HAakaTeNpqAyBZ8GSqLzHgw4XmHmC8whvpjJNMbFZN7/g==}
@@ -11325,9 +11223,6 @@ packages:
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==}
node-fetch@2.7.0:
resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==}
engines: {node: 4.x || >=6.0.0}
@@ -11391,11 +11286,6 @@ packages:
number-flow@0.3.10:
resolution: {integrity: sha512-BpNMhQnRAHOFbi0giD+dMnDoaPibVW22Vl2CWfZZIlpgTtixmbPm+Cv7a7F7FrEc/dTOECMS/T8V5rltIGI0tw==}
nypm@0.5.2:
resolution: {integrity: sha512-AHzvnyUJYSrrphPhRWWZNcoZfArGNp3Vrc4pm/ZurO74tYNTgAPrEyBQEKy+qioqmWlPXwvMZCG2wOaHlPG0Pw==}
engines: {node: ^14.16.0 || >=16.10.0}
hasBin: true
object-assign@4.1.1:
resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==}
engines: {node: '>=0.10.0'}
@@ -11752,9 +11642,6 @@ packages:
pend@1.2.0:
resolution: {integrity: sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==}
perfect-debounce@1.0.0:
resolution: {integrity: sha512-xCy9V055GLEqoFaHoC1SoLIaLmWctgCUaBaWxDZ7/Zx4CTyX7cJQLJOok/orfjZAh9kEYpjJa4d0KcJmCbctZA==}
pg-cloudflare@1.1.1:
resolution: {integrity: sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==}
@@ -12176,9 +12063,6 @@ packages:
peerDependencies:
webpack: ^4.0.0 || ^5.0.0
rc9@2.1.2:
resolution: {integrity: sha512-btXCnMmRIBINM2LDZoEmOogIZU7Qe7zn4BpomSKZ/ykbLObuBdvG+mFq11DL6fjH1DRwHhrlgtYWG96bJiC7Cg==}
rc@1.2.8:
resolution: {integrity: sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==}
hasBin: true
@@ -13061,6 +12945,10 @@ packages:
strnum@2.1.1:
resolution: {integrity: sha512-7ZvoFTiCnGxBtDqJ//Cu6fWtZtc7Y3x+QOirG15wztbdngGSkht27o2pyGWrVy0b4WAy3jbKmnoK6g5VlVNUUw==}
strtok3@10.3.4:
resolution: {integrity: sha512-KIy5nylvC5le1OdaaoCJ07L+8iQzJHGH6pWDuzS+d07Cu7n1MZ2x26P8ZKIWfbK02+XIL8Mp4RkWeqdUCrDMfg==}
engines: {node: '>=18'}
strtok3@9.1.1:
resolution: {integrity: sha512-FhwotcEqjr241ZbjFzjlIYg6c5/L/s4yBGWSMvJ9UoExiSqL+FnFA/CaeZx17WGaZMS/4SOZp8wH18jSS4R4lw==}
engines: {node: '>=16'}
@@ -13523,11 +13411,6 @@ packages:
ufo@1.6.1:
resolution: {integrity: sha512-9a4/uxlTWJ4+a5i0ooc1rU7C7YOw3wT+UGqdeNNHWnOF9qcMBgLRS+4IYUqbczewFx4mLEig6gawh7X6mFlEkA==}
uglify-js@3.19.3:
resolution: {integrity: sha512-v3Xu+yuwBXisp6QYTcH4UbH+xYJXqnq2m/LtQVWKWzYc1iehYnLixoQDN9FH6/j9/oybfd6W9Ghwkl8+UMKTKQ==}
engines: {node: '>=0.8.0'}
hasBin: true
uint8array-extras@1.4.0:
resolution: {integrity: sha512-ZPtzy0hu4cZjv3z5NW9gfKnNLjoz4y6uv4HlelAjDK7sY/xOkKZv9xK/WQpcsBB3jEybChz9DPC2U/+cusjJVQ==}
engines: {node: '>=18'}
@@ -13726,11 +13609,6 @@ packages:
engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0}
hasBin: true
vite-plugin-wasm@3.4.1:
resolution: {integrity: sha512-ja3nSo2UCkVeitltJGkS3pfQHAanHv/DqGatdI39ja6McgABlpsZ5hVgl6wuR8Qx5etY3T5qgDQhOWzc5RReZA==}
peerDependencies:
vite: ^2 || ^3 || ^4 || ^5 || ^6
vite@5.4.19:
resolution: {integrity: sha512-qO3aKv3HoQC8QKiNSTuUM1l9o/XX3+c+VTgLHbJWHZGeTPVAg2XwazI9UWzoxjIJCGCV2zU60uqMzjeLZuULqA==}
engines: {node: ^18.0.0 || >=20.0.0}
@@ -14174,9 +14052,6 @@ packages:
resolution: {integrity: sha512-zVyFsvE+mq9MCmwXUWHIcpfbrHHClZWZiVOzKSxNJruIcFn2RbY55zkhiAMMxM8zCVSmtNiViq8FsAZSFpMYag==}
engines: {node: '>=0.6.0'}
wordwrap@1.0.0:
resolution: {integrity: sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==}
wordwrapjs@5.1.0:
resolution: {integrity: sha512-JNjcULU2e4KJwUNv6CHgI46UvDGitb6dGryHajXTDiLgg1/RiGoPSDw4kZfYnwGtEXf2ZMeIewDQgFGzkCB2Sg==}
engines: {node: '>=12.17'}
@@ -17000,27 +16875,6 @@ snapshots:
'@tanstack/vue-virtual': 3.13.6(vue@3.5.13(typescript@5.8.3))
vue: 3.5.13(typescript@5.8.3)
'@hey-api/client-fetch@0.10.1(@hey-api/openapi-ts@0.67.5(typescript@5.9.2))':
dependencies:
'@hey-api/openapi-ts': 0.67.5(typescript@5.9.2)
'@hey-api/json-schema-ref-parser@1.0.6':
dependencies:
'@jsdevtools/ono': 7.1.3
'@types/json-schema': 7.0.15
js-yaml: 4.1.0
lodash: 4.17.21
'@hey-api/openapi-ts@0.67.5(typescript@5.9.2)':
dependencies:
'@hey-api/json-schema-ref-parser': 1.0.6
c12: 2.0.1
commander: 13.0.0
handlebars: 4.7.8
typescript: 5.9.2
transitivePeerDependencies:
- magicast
'@hono/node-server@1.14.0(hono@4.7.5)':
dependencies:
hono: 4.7.5
@@ -17425,7 +17279,9 @@ snapshots:
'@lezer/highlight': 1.2.1
'@lezer/lr': 1.4.2
'@llama-flow/core@0.4.1(@modelcontextprotocol/sdk@1.13.0)(hono@4.9.7)(next@15.3.3(@opentelemetry/api@1.9.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(p-retry@6.2.1)(zod@3.25.76)':
'@llamaindex/chat-ui-docs@0.1.0': {}
'@llamaindex/workflow-core@1.3.2(@modelcontextprotocol/sdk@1.13.0)(hono@4.9.7)(next@15.3.3(@opentelemetry/api@1.9.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(p-retry@6.2.1)(zod@3.25.76)':
optionalDependencies:
'@modelcontextprotocol/sdk': 1.13.0
hono: 4.9.7
@@ -17433,8 +17289,6 @@ snapshots:
p-retry: 6.2.1
zod: 3.25.76
'@llamaindex/chat-ui-docs@0.1.0': {}
'@llamaindex/workflow-core@1.3.2(@modelcontextprotocol/sdk@1.13.0)(hono@4.9.7)(next@15.3.3(@opentelemetry/api@1.9.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(p-retry@6.2.1)(zod@4.1.5)':
optionalDependencies:
'@modelcontextprotocol/sdk': 1.13.0
@@ -20190,6 +20044,14 @@ snapshots:
'@tanstack/virtual-core': 3.13.6
vue: 3.5.13(typescript@5.8.3)
'@tokenizer/inflate@0.2.7':
dependencies:
debug: 4.4.1
fflate: 0.8.2
token-types: 6.0.0
transitivePeerDependencies:
- supports-color
'@tokenizer/token@0.3.0': {}
'@tootallnate/once@2.0.0': {}
@@ -21715,21 +21577,6 @@ snapshots:
bytes@3.1.2: {}
c12@2.0.1:
dependencies:
chokidar: 4.0.3
confbox: 0.1.8
defu: 6.1.4
dotenv: 16.6.1
giget: 1.2.4
jiti: 2.4.2
mlly: 1.7.4
ohash: 1.1.6
pathe: 1.1.2
perfect-debounce: 1.0.0
pkg-types: 1.3.1
rc9: 2.1.2
cac@6.7.14: {}
cacheable-lookup@7.0.0: {}
@@ -21859,7 +21706,8 @@ snapshots:
chownr@1.1.4: {}
chownr@2.0.0: {}
chownr@2.0.0:
optional: true
chownr@3.0.0: {}
@@ -21896,10 +21744,6 @@ snapshots:
ci-info@3.9.0: {}
citty@0.1.6:
dependencies:
consola: 3.4.2
cjs-module-lexer@1.4.3: {}
class-variance-authority@0.7.1:
@@ -22058,8 +21902,6 @@ snapshots:
commander@12.1.0: {}
commander@13.0.0: {}
commander@13.1.0: {}
commander@2.20.3: {}
@@ -22278,8 +22120,6 @@ snapshots:
dequal@2.0.3: {}
destr@2.0.3: {}
detect-indent@6.1.0: {}
detect-libc@2.0.3: {}
@@ -23233,6 +23073,8 @@ snapshots:
to-arraybuffer: 1.0.1
tough-cookie: 4.1.4
fflate@0.8.2: {}
file-entry-cache@8.0.0:
dependencies:
flat-cache: 4.0.1
@@ -23244,6 +23086,15 @@ snapshots:
token-types: 6.0.0
uint8array-extras: 1.4.0
file-type@21.0.0:
dependencies:
'@tokenizer/inflate': 0.2.7
strtok3: 10.3.4
token-types: 6.0.0
uint8array-extras: 1.4.0
transitivePeerDependencies:
- supports-color
filename-reserved-regex@3.0.0: {}
filenamify@6.0.0:
@@ -23435,6 +23286,7 @@ snapshots:
fs-minipass@2.1.0:
dependencies:
minipass: 3.3.6
optional: true
fs.realpath@1.0.0: {}
@@ -23724,17 +23576,6 @@ snapshots:
transitivePeerDependencies:
- supports-color
giget@1.2.4:
dependencies:
citty: 0.1.6
consola: 3.4.2
defu: 6.1.4
node-fetch-native: 1.6.6
nypm: 0.5.2
ohash: 1.1.6
pathe: 2.0.3
tar: 6.2.1
github-from-package@0.0.0: {}
github-slugger@2.0.0: {}
@@ -23918,15 +23759,6 @@ snapshots:
guid-typescript@1.0.9: {}
handlebars@4.7.8:
dependencies:
minimist: 1.2.8
neo-async: 2.6.2
source-map: 0.6.1
wordwrap: 1.0.0
optionalDependencies:
uglify-js: 3.19.3
happy-dom@15.11.7:
dependencies:
entities: 4.5.0
@@ -24875,6 +24707,30 @@ snapshots:
rfdc: 1.4.1
wrap-ansi: 9.0.0
llama-cloud-services@0.3.5(@llamaindex/core@packages+core)(@llamaindex/env@packages+env)(@llamaindex/workflow-core@1.3.2(@modelcontextprotocol/sdk@1.13.0)(hono@4.9.7)(next@15.3.3(@opentelemetry/api@1.9.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(p-retry@6.2.1)(zod@3.25.76)):
dependencies:
'@llamaindex/core': link:packages/core
'@llamaindex/env': link:packages/env
'@llamaindex/workflow-core': 1.3.2(@modelcontextprotocol/sdk@1.13.0)(hono@4.9.7)(next@15.3.3(@opentelemetry/api@1.9.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(p-retry@6.2.1)(zod@3.25.76)
ajv: 8.17.1
file-type: 21.0.0
p-retry: 6.2.1
zod: 3.25.76
transitivePeerDependencies:
- supports-color
llama-cloud-services@0.3.5(@llamaindex/core@packages+core)(@llamaindex/env@packages+env)(@llamaindex/workflow-core@1.3.2(@modelcontextprotocol/sdk@1.13.0)(hono@4.9.7)(next@15.3.3(@opentelemetry/api@1.9.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(p-retry@6.2.1)(zod@4.1.5)):
dependencies:
'@llamaindex/core': link:packages/core
'@llamaindex/env': link:packages/env
'@llamaindex/workflow-core': 1.3.2(@modelcontextprotocol/sdk@1.13.0)(hono@4.9.7)(next@15.3.3(@opentelemetry/api@1.9.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(p-retry@6.2.1)(zod@4.1.5)
ajv: 8.17.1
file-type: 21.0.0
p-retry: 6.2.1
zod: 3.25.76
transitivePeerDependencies:
- supports-color
loader-runner@4.3.0: {}
loader-utils@2.0.4:
@@ -25632,8 +25488,10 @@ snapshots:
minipass@3.3.6:
dependencies:
yallist: 4.0.0
optional: true
minipass@5.0.0: {}
minipass@5.0.0:
optional: true
minipass@7.1.2: {}
@@ -25641,6 +25499,7 @@ snapshots:
dependencies:
minipass: 3.3.6
yallist: 4.0.0
optional: true
minizlib@3.0.1:
dependencies:
@@ -25655,17 +25514,11 @@ snapshots:
dependencies:
minimist: 1.2.8
mkdirp@1.0.4: {}
mkdirp@1.0.4:
optional: true
mkdirp@3.0.1: {}
mlly@1.7.4:
dependencies:
acorn: 8.14.1
pathe: 2.0.3
pkg-types: 1.3.1
ufo: 1.6.1
mlly@1.8.0:
dependencies:
acorn: 8.15.0
@@ -25998,8 +25851,6 @@ snapshots:
node-domexception@1.0.0: {}
node-fetch-native@1.6.6: {}
node-fetch@2.7.0:
dependencies:
whatwg-url: 5.0.0
@@ -26053,15 +25904,6 @@ snapshots:
dependencies:
esm-env: 1.2.2
nypm@0.5.2:
dependencies:
citty: 0.1.6
consola: 3.4.2
pathe: 2.0.3
pkg-types: 1.3.1
tinyexec: 0.3.2
ufo: 1.6.1
object-assign@4.1.1: {}
object-hash@3.0.0: {}
@@ -26463,8 +26305,6 @@ snapshots:
pend@1.2.0: {}
perfect-debounce@1.0.0: {}
pg-cloudflare@1.1.1:
optional: true
@@ -26560,7 +26400,7 @@ snapshots:
pkg-types@1.3.1:
dependencies:
confbox: 0.1.8
mlly: 1.7.4
mlly: 1.8.0
pathe: 2.0.3
platform@1.3.6: {}
@@ -26882,11 +26722,6 @@ snapshots:
schema-utils: 3.3.0
webpack: 5.99.5(@swc/core@1.12.11(@swc/helpers@0.5.17))
rc9@2.1.2:
dependencies:
defu: 6.1.4
destr: 2.0.3
rc@1.2.8:
dependencies:
deep-extend: 0.6.0
@@ -28099,6 +27934,10 @@ snapshots:
strnum@2.1.1:
optional: true
strtok3@10.3.4:
dependencies:
'@tokenizer/token': 0.3.0
strtok3@9.1.1:
dependencies:
'@tokenizer/token': 0.3.0
@@ -28242,6 +28081,7 @@ snapshots:
minizlib: 2.1.2
mkdirp: 1.0.4
yallist: 4.0.0
optional: true
tar@7.4.3:
dependencies:
@@ -28607,9 +28447,6 @@ snapshots:
ufo@1.6.1: {}
uglify-js@3.19.3:
optional: true
uint8array-extras@1.4.0: {}
unbox-primitive@1.1.0:
@@ -28919,10 +28756,6 @@ snapshots:
- tsx
- yaml
vite-plugin-wasm@3.4.1(vite@6.3.6(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.29.3)(terser@5.39.0)(tsx@4.20.3)(yaml@2.7.1)):
dependencies:
vite: 6.3.6(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.29.3)(terser@5.39.0)(tsx@4.20.3)(yaml@2.7.1)
vite@5.4.19(@types/node@24.0.13)(lightningcss@1.29.3)(terser@5.39.0):
dependencies:
esbuild: 0.21.5
@@ -29520,8 +29353,6 @@ snapshots:
wordnet-db@3.1.14: {}
wordwrap@1.0.0: {}
wordwrapjs@5.1.0: {}
workerd@1.20241230.0:
-2
View File
@@ -7,7 +7,6 @@ import { z } from "zod";
import { openai } from "@llamaindex/openai";
import { VectorStoreIndex } from "llamaindex";
import { ReActAgent } from "llamaindex/agent";
import { LlamaCloudIndex } from "llamaindex/cloud";
import { BaseChatEngine } from "llamaindex/engines";
import { CorrectnessEvaluator } from "llamaindex/evaluation";
import { BaseExtractor } from "llamaindex/extractors";
@@ -68,7 +67,6 @@ test("LlamaIndex module resolution test", async (t) => {
const allImports = [
VectorStoreIndex,
ReActAgent,
LlamaCloudIndex,
BaseChatEngine,
CorrectnessEvaluator,
BaseExtractor,
-3
View File
@@ -71,9 +71,6 @@
{
"path": "./packages/providers/excel/tsconfig.json"
},
{
"path": "./packages/cloud/tsconfig.json"
},
{
"path": "./packages/core/tsconfig.json"
},
-1
View File
@@ -15,7 +15,6 @@
"vitest": "^2.1.5"
},
"dependencies": {
"@llamaindex/cloud": "workspace:*",
"@llamaindex/core": "workspace:*",
"@llamaindex/node-parser": "workspace:*",
"@llamaindex/openai": "workspace:*",
-176
View File
@@ -1,176 +0,0 @@
/**
* DO NOT PUT THIS TEST CASE FROM VITEST TO NODE.JS TEST RUNNER
*
* msw has side effect that will replace the global fetch function,
* which will cause the test runner to hang indefinitely for some reason.
* but vitest will start new process for each test case, so it's safe to use msw in vitest,
* in the meanwhile, node.js test runner only run in single process.
*/
import { faker } from "@faker-js/faker";
import { http, HttpResponse } from "msw";
import { setupServer } from "msw/node";
import { fileURLToPath } from "node:url";
import { afterAll, afterEach, beforeAll, expect, test } from "vitest";
const jobsHashMap = new Map<string, boolean>();
const handlers = [
http.post("https://api.cloud.llamaindex.ai/api/v1/parsing/upload", () => {
return HttpResponse.json({
id: faker.string.uuid(),
});
}),
http.get(
"https://api.cloud.llamaindex.ai/api/v1/parsing/job/:id",
({ params }): HttpResponse => {
const jobId = params.id as string;
if (jobsHashMap.has(jobId)) {
return HttpResponse.json({
id: jobId,
status: "SUCCESS",
});
} else {
jobsHashMap.set(jobId, true);
}
return HttpResponse.json({
id: jobId,
status: "PENDING",
});
},
),
http.get(
"https://api.cloud.llamaindex.ai/api/v1/parsing/job/:id/result/markdown",
() => {
const job_metadata = {
credits_used: faker.number.int({ min: 1, max: 10 }),
credits_max: 1000,
job_credits_usage: faker.number.int({ min: 1, max: 10 }),
job_pages: faker.number.int({ min: 0, max: 5 }),
job_is_cache_hit: faker.datatype.boolean(),
};
return HttpResponse.json({
markdown: faker.lorem.paragraphs({
min: 3,
max: 1000,
}),
job_metadata,
});
},
),
http.get(
"https://api.cloud.llamaindex.ai/api/v1/parsing/job/:id/result/text",
() => {
const job_metadata = {
credits_used: faker.number.int({ min: 1, max: 10 }),
credits_max: 1000,
job_credits_usage: faker.number.int({ min: 1, max: 10 }),
job_pages: faker.number.int({ min: 0, max: 5 }),
job_is_cache_hit: faker.datatype.boolean(),
};
return HttpResponse.json({
text: faker.lorem.paragraphs({
min: 3,
max: 1000,
}),
job_metadata,
});
},
),
http.get(
"https://api.cloud.llamaindex.ai/api/v1/parsing/job/:id/result/json",
() => {
const pages = Array.from({ length: 1 }, () => ({
page: 1,
text: faker.lorem.paragraphs(2),
md: `# ${faker.lorem.sentence()}\n\n${faker.lorem.paragraph()}`,
images: [
{
name: faker.system.fileName(),
height: faker.number.int({ min: 100, max: 500 }),
width: faker.number.int({ min: 600, max: 1600 }),
x: faker.number.int({ min: 0, max: 50 }),
y: faker.number.int({ min: 0, max: 50 }),
original_width: faker.number.int({ min: 1800, max: 2000 }),
original_height: faker.number.int({ min: 400, max: 600 }),
},
],
items: [
{
type: "heading",
lvl: 1,
value: faker.lorem.sentence(),
md: `# ${faker.lorem.sentence()}`,
bBox: {
x: faker.number.float({ min: 20, max: 40 }),
y: faker.number.float({ min: 20, max: 30 }),
w: faker.number.float({ min: 300, max: 400 }),
h: faker.number.float({ min: 30, max: 50 }),
},
},
{
type: "table",
rows: [
[faker.lorem.word(), faker.lorem.sentence()],
[faker.lorem.word(), faker.lorem.sentence()],
[faker.lorem.word(), faker.lorem.sentence()],
[faker.lorem.word(), faker.lorem.sentence()],
],
md: faker.lorem.sentences(4),
isPerfectTable: faker.datatype.boolean(),
csv: faker.lorem.sentences(4),
},
{
type: "text",
value: faker.lorem.paragraphs(2),
md: faker.lorem.paragraphs(2),
bBox: {
x: faker.number.float({ min: 5, max: 10 }),
y: faker.number.float({ min: 20, max: 30 }),
w: faker.number.float({ min: 800, max: 900 }),
h: faker.number.float({ min: 30, max: 50 }),
},
},
],
}));
const response = {
pages,
job_metadata: {
credits_used: faker.number.int({ min: 1, max: 10 }),
credits_max: 1000,
job_credits_usage: faker.number.int({ min: 1, max: 10 }),
job_pages: faker.number.int({ min: 0, max: 5 }),
job_is_cache_hit: faker.datatype.boolean(),
},
};
return HttpResponse.json(response);
},
),
];
const server = setupServer(...handlers);
beforeAll(() => {
server.listen({
onUnhandledRequest: "error",
});
});
afterEach(() => {
server.resetHandlers();
});
afterAll(() => {
server.close();
});
test("llama parse should return a successful document", async () => {
const { LlamaParseReader } = await import("@llamaindex/cloud/reader");
const reader = new LlamaParseReader({
verbose: false,
apiKey: "llx-fake-api-key",
});
const fileUrl = new URL("../../examples/data/TOS.pdf", import.meta.url);
const documents = await reader.loadData(fileURLToPath(fileUrl));
expect(documents.length).toBe(1);
});