@composio/llamaindex 0.1.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,243 @@
1
+ # @composio/llamaindex
2
+
3
+ Agentic Provider for Llamaindex in Composio SDK.
4
+
5
+ ## Features
6
+
7
+ - **Seamless LlamaIndex Integration**: Tools are automatically compatible with LlamaIndex agents and workflows
8
+ - **Full Modifier Support**: Support for both schema and execution modifiers with beforeExecute/afterExecute hooks
9
+ - **Streaming Support**: Works with LlamaIndex streaming agents using `agentStreamEvent`
10
+ - **Tool Execution**: Execute tools with proper parameter handling and JSON schema validation
11
+ - **Type Safety**: Full TypeScript support with proper type definitions
12
+ - **Zod Schema Integration**: Automatic conversion from JSON Schema to Zod for LlamaIndex compatibility
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @composio/llamaindex
18
+ # or
19
+ yarn add @composio/llamaindex
20
+ # or
21
+ pnpm add @composio/llamaindex
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ```typescript
27
+ import { Composio } from '@composio/core';
28
+ import { LlamaindexProvider } from '@composio/llamaindex';
29
+
30
+ // Initialize Composio with Llamaindex provider
31
+ const composio = new Composio({
32
+ apiKey: 'your-composio-api-key',
33
+ provider: new LlamaindexProvider(),
34
+ });
35
+
36
+ // Get available tools
37
+ const tools = await composio.tools.get('user123', {
38
+ toolkits: ['gmail', 'googlecalendar'],
39
+ limit: 10,
40
+ });
41
+ ```
42
+
43
+ ## Prerequisites
44
+
45
+ Before using the LlamaIndex provider, make sure you have:
46
+
47
+ 1. **Composio API Key**: Get your API key from [Composio Dashboard](https://app.composio.dev)
48
+ 2. **Environment Setup**: Set up your environment variables
49
+ 3. **LlamaIndex Dependencies**: Install required LlamaIndex packages
50
+
51
+ ```bash
52
+ # Install LlamaIndex dependencies
53
+ npm install @llamaindex/openai @llamaindex/workflow
54
+ ```
55
+
56
+ ```bash
57
+ # Set up environment variables
58
+ export COMPOSIO_API_KEY="your-composio-api-key"
59
+ export OPENAI_API_KEY="your-openai-api-key" # For LlamaIndex OpenAI integration
60
+ ```
61
+
62
+ ## Usage Examples
63
+
64
+ ### Basic Example
65
+
66
+ ```typescript
67
+ import { Composio } from '@composio/core';
68
+ import { LlamaindexProvider } from '@composio/llamaindex';
69
+
70
+ // Initialize Composio
71
+ const composio = new Composio({
72
+ apiKey: process.env.COMPOSIO_API_KEY,
73
+ provider: new LlamaindexProvider(),
74
+ });
75
+
76
+ // Get tools
77
+ const tools = await composio.tools.get('default', {
78
+ toolkits: ['gmail'],
79
+ limit: 10,
80
+ });
81
+
82
+ console.log(`Found ${tools.length} tools`);
83
+ ```
84
+
85
+ ### Complete Agent Example with HackerNews
86
+
87
+ ```typescript
88
+ import { Composio } from '@composio/core';
89
+ import { LlamaindexProvider } from '@composio/llamaindex';
90
+ import { openai } from '@llamaindex/openai';
91
+ import { agent, agentStreamEvent } from '@llamaindex/workflow';
92
+ import 'dotenv/config';
93
+
94
+ // Initialize Composio with LlamaIndex provider
95
+ const composio = new Composio({
96
+ apiKey: process.env.COMPOSIO_API_KEY,
97
+ provider: new LlamaindexProvider(),
98
+ });
99
+
100
+ async function main() {
101
+ try {
102
+ console.log('🚀 Starting LlamaIndex Example...');
103
+
104
+ // Get available tools with modifiers
105
+ const tools = await composio.tools.get(
106
+ 'default',
107
+ {
108
+ toolkits: ['hackernews'],
109
+ limit: 10,
110
+ },
111
+ {
112
+ beforeExecute: ({ toolSlug, toolkitSlug, params }) => {
113
+ console.log(`🔄 Executing tool ${toolSlug}/${toolkitSlug} with params:`, { params });
114
+ return params;
115
+ },
116
+ afterExecute: ({ toolSlug, toolkitSlug, result }) => {
117
+ console.log(`✅ Executed tool ${toolSlug}/${toolkitSlug} with result:`, { result });
118
+ return result;
119
+ },
120
+ }
121
+ );
122
+
123
+ console.log(`✅ Found ${tools.length} tools`);
124
+
125
+ // Create LlamaIndex agent with Composio tools
126
+ const hackernewsAgent = agent({
127
+ name: 'Hackernews Agent',
128
+ description: 'A helpful hackernews assistant',
129
+ llm: openai({ model: 'gpt-4o-mini' }),
130
+ systemPrompt:
131
+ 'You are a helpful hackernews assistant that helps users with their queries related to hackernews',
132
+ tools, // Composio tools are automatically compatible with LlamaIndex
133
+ });
134
+
135
+ // Run the agent with streaming
136
+ const stream = await hackernewsAgent.runStream('Summarize the front page of hackernews');
137
+
138
+ for await (const event of stream) {
139
+ if (agentStreamEvent.include(event)) {
140
+ process.stdout.write(event.data.delta);
141
+ }
142
+ }
143
+ } catch (error) {
144
+ console.error('❌ Error running example:', error);
145
+ }
146
+ }
147
+
148
+ main().catch(console.error);
149
+ ```
150
+
151
+ ### Using Tools with Different Toolkits
152
+
153
+ ```typescript
154
+ import { Composio } from '@composio/core';
155
+ import { LlamaindexProvider } from '@composio/llamaindex';
156
+ import { openai } from '@llamaindex/openai';
157
+ import { agent } from '@llamaindex/workflow';
158
+
159
+ const composio = new Composio({
160
+ apiKey: process.env.COMPOSIO_API_KEY,
161
+ provider: new LlamaindexProvider(),
162
+ });
163
+
164
+ // Get tools from multiple toolkits
165
+ const tools = await composio.tools.get('default', {
166
+ toolkits: ['gmail', 'googlecalendar', 'slack'],
167
+ limit: 20,
168
+ });
169
+
170
+ // Create a multi-purpose agent
171
+ const assistantAgent = agent({
172
+ name: 'Personal Assistant',
173
+ description: 'A helpful personal assistant',
174
+ llm: openai({ model: 'gpt-4' }),
175
+ systemPrompt:
176
+ 'You are a helpful personal assistant that can manage emails, calendar events, and slack messages.',
177
+ tools,
178
+ });
179
+
180
+ // Use the agent
181
+ const response = await assistantAgent.run(
182
+ 'Schedule a meeting for tomorrow at 2 PM and send a slack message about it'
183
+ );
184
+ console.log(response);
185
+ ```
186
+
187
+ ## API Reference
188
+
189
+ ### LlamaindexProvider Class
190
+
191
+ The `LlamaindexProvider` class extends `BaseAgenticProvider` and provides llamaindex-specific functionality.
192
+
193
+ #### Methods
194
+
195
+ ##### `wrapTool(tool: Tool, executeTool: ExecuteToolFn): LlamaindexTool`
196
+
197
+ Wraps a single Composio tool in the LlamaIndex format with proper Zod schema conversion.
198
+
199
+ ```typescript
200
+ const llamaindexTool = provider.wrapTool(composioTool, executeTool);
201
+
202
+ // The wrapped tool has LlamaIndex-compatible structure:
203
+ // - metadata.name: Tool slug
204
+ // - metadata.description: Tool description
205
+ // - metadata.parameters: Zod schema for parameters
206
+ // - call(): Function to execute the tool
207
+ ```
208
+
209
+ ##### `wrapTools(tools: Tool[], executeTool: ExecuteToolFn): LlamaindexTool[]`
210
+
211
+ Wraps multiple Composio tools for use with LlamaIndex agents.
212
+
213
+ ```typescript
214
+ const llamaindexTools = provider.wrapTools(composioTools, executeTool);
215
+
216
+ // Use directly with LlamaIndex agents
217
+ const agent = agent({
218
+ name: 'My Agent',
219
+ llm: openai({ model: 'gpt-4' }),
220
+ tools: llamaindexTools, // Ready to use!
221
+ });
222
+ ```
223
+
224
+ ##### `wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse`
225
+
226
+ Transforms MCP URL responses into the standard format with URL objects.
227
+
228
+ ```typescript
229
+ const mcpServers = provider.wrapMcpServerResponse(urlResponse);
230
+ // Returns: [{ url: URL, name: string }, ...]
231
+ ```
232
+
233
+ ## Contributing
234
+
235
+ We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for more details.
236
+
237
+ ## License
238
+
239
+ ISC License
240
+
241
+ ## Support
242
+
243
+ For support, please visit our [Documentation](https://docs.composio.dev) or join our [Discord Community](https://discord.gg/composio).
package/dist/index.cjs ADDED
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ LlamaindexProvider: () => LlamaindexProvider
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_core = require("@composio/core");
27
+ var import_llamaindex = require("llamaindex");
28
+ var LlamaindexProvider = class extends import_core.BaseAgenticProvider {
29
+ name = "llamaindex";
30
+ /**
31
+ * Wrap a tool in the llamaindex format.
32
+ * @param tool - The tool to wrap.
33
+ * @returns The wrapped tool.
34
+ */
35
+ wrapTool(tool, executeTool) {
36
+ const inputParams = tool.inputParameters;
37
+ const inputParametersSchema = (0, import_core.jsonSchemaToZodSchema)(inputParams ?? {});
38
+ return (0, import_llamaindex.tool)({
39
+ name: tool.slug,
40
+ description: tool.description ?? tool.name ?? "",
41
+ parameters: inputParametersSchema,
42
+ execute: async (input) => {
43
+ const result = await executeTool(tool.slug, input);
44
+ return JSON.stringify(result);
45
+ }
46
+ });
47
+ }
48
+ /**
49
+ * Wrap a list of tools in the llamaindex format.
50
+ * @param tools - The tools to wrap.
51
+ * @returns The wrapped tools.
52
+ */
53
+ wrapTools(tools, executeTool) {
54
+ return tools.map((tool) => this.wrapTool(tool, executeTool));
55
+ }
56
+ /**
57
+ * Transform MCP URL response into Anthropic-specific format.
58
+ * By default, Anthropic uses the standard format (same as default),
59
+ * but this method is here to show providers can customize if needed.
60
+ *
61
+ * @param data - The MCP URL response data
62
+ * @returns Standard MCP server response format
63
+ */
64
+ wrapMcpServerResponse(data) {
65
+ return data.map((item) => ({
66
+ url: new URL(item.url),
67
+ name: item.name
68
+ }));
69
+ }
70
+ };
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ LlamaindexProvider
74
+ });
@@ -0,0 +1,40 @@
1
+ import { BaseAgenticProvider, McpServerGetResponse, Tool, ExecuteToolFn, McpUrlResponse } from '@composio/core';
2
+ import { tool } from 'llamaindex';
3
+
4
+ /**
5
+ * Llamaindex Provider
6
+ *
7
+ * This provider provides a set of tools for interacting with Llamaindex.
8
+ *
9
+ * @packageDocumentation
10
+ * @module providers/llamaindex
11
+ */
12
+
13
+ type LlamaindexTool = ReturnType<typeof tool>;
14
+ type LlamaindexToolCollection = Array<LlamaindexTool>;
15
+ declare class LlamaindexProvider extends BaseAgenticProvider<Array<LlamaindexTool>, LlamaindexTool, McpServerGetResponse> {
16
+ readonly name = "llamaindex";
17
+ /**
18
+ * Wrap a tool in the llamaindex format.
19
+ * @param tool - The tool to wrap.
20
+ * @returns The wrapped tool.
21
+ */
22
+ wrapTool(tool: Tool, executeTool: ExecuteToolFn): LlamaindexTool;
23
+ /**
24
+ * Wrap a list of tools in the llamaindex format.
25
+ * @param tools - The tools to wrap.
26
+ * @returns The wrapped tools.
27
+ */
28
+ wrapTools(tools: Tool[], executeTool: ExecuteToolFn): LlamaindexToolCollection;
29
+ /**
30
+ * Transform MCP URL response into Anthropic-specific format.
31
+ * By default, Anthropic uses the standard format (same as default),
32
+ * but this method is here to show providers can customize if needed.
33
+ *
34
+ * @param data - The MCP URL response data
35
+ * @returns Standard MCP server response format
36
+ */
37
+ wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse;
38
+ }
39
+
40
+ export { LlamaindexProvider, type LlamaindexTool, type LlamaindexToolCollection };
@@ -0,0 +1,40 @@
1
+ import { BaseAgenticProvider, McpServerGetResponse, Tool, ExecuteToolFn, McpUrlResponse } from '@composio/core';
2
+ import { tool } from 'llamaindex';
3
+
4
+ /**
5
+ * Llamaindex Provider
6
+ *
7
+ * This provider provides a set of tools for interacting with Llamaindex.
8
+ *
9
+ * @packageDocumentation
10
+ * @module providers/llamaindex
11
+ */
12
+
13
+ type LlamaindexTool = ReturnType<typeof tool>;
14
+ type LlamaindexToolCollection = Array<LlamaindexTool>;
15
+ declare class LlamaindexProvider extends BaseAgenticProvider<Array<LlamaindexTool>, LlamaindexTool, McpServerGetResponse> {
16
+ readonly name = "llamaindex";
17
+ /**
18
+ * Wrap a tool in the llamaindex format.
19
+ * @param tool - The tool to wrap.
20
+ * @returns The wrapped tool.
21
+ */
22
+ wrapTool(tool: Tool, executeTool: ExecuteToolFn): LlamaindexTool;
23
+ /**
24
+ * Wrap a list of tools in the llamaindex format.
25
+ * @param tools - The tools to wrap.
26
+ * @returns The wrapped tools.
27
+ */
28
+ wrapTools(tools: Tool[], executeTool: ExecuteToolFn): LlamaindexToolCollection;
29
+ /**
30
+ * Transform MCP URL response into Anthropic-specific format.
31
+ * By default, Anthropic uses the standard format (same as default),
32
+ * but this method is here to show providers can customize if needed.
33
+ *
34
+ * @param data - The MCP URL response data
35
+ * @returns Standard MCP server response format
36
+ */
37
+ wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse;
38
+ }
39
+
40
+ export { LlamaindexProvider, type LlamaindexTool, type LlamaindexToolCollection };
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ // src/index.ts
2
+ import {
3
+ BaseAgenticProvider,
4
+ jsonSchemaToZodSchema
5
+ } from "@composio/core";
6
+ import { tool as createLlamaindexTool } from "llamaindex";
7
+ var LlamaindexProvider = class extends BaseAgenticProvider {
8
+ name = "llamaindex";
9
+ /**
10
+ * Wrap a tool in the llamaindex format.
11
+ * @param tool - The tool to wrap.
12
+ * @returns The wrapped tool.
13
+ */
14
+ wrapTool(tool, executeTool) {
15
+ const inputParams = tool.inputParameters;
16
+ const inputParametersSchema = jsonSchemaToZodSchema(inputParams ?? {});
17
+ return createLlamaindexTool({
18
+ name: tool.slug,
19
+ description: tool.description ?? tool.name ?? "",
20
+ parameters: inputParametersSchema,
21
+ execute: async (input) => {
22
+ const result = await executeTool(tool.slug, input);
23
+ return JSON.stringify(result);
24
+ }
25
+ });
26
+ }
27
+ /**
28
+ * Wrap a list of tools in the llamaindex format.
29
+ * @param tools - The tools to wrap.
30
+ * @returns The wrapped tools.
31
+ */
32
+ wrapTools(tools, executeTool) {
33
+ return tools.map((tool) => this.wrapTool(tool, executeTool));
34
+ }
35
+ /**
36
+ * Transform MCP URL response into Anthropic-specific format.
37
+ * By default, Anthropic uses the standard format (same as default),
38
+ * but this method is here to show providers can customize if needed.
39
+ *
40
+ * @param data - The MCP URL response data
41
+ * @returns Standard MCP server response format
42
+ */
43
+ wrapMcpServerResponse(data) {
44
+ return data.map((item) => ({
45
+ url: new URL(item.url),
46
+ name: item.name
47
+ }));
48
+ }
49
+ };
50
+ export {
51
+ LlamaindexProvider
52
+ };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@composio/llamaindex",
3
+ "version": "0.1.53",
4
+ "description": "Agentic Provider for llamaindex in Composio SDK",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "require": "./dist/index.cjs"
15
+ }
16
+ },
17
+ "files": [
18
+ "README.md",
19
+ "dist"
20
+ ],
21
+ "keywords": [
22
+ "composio",
23
+ "provider",
24
+ "llamaindex"
25
+ ],
26
+ "author": "",
27
+ "license": "ISC",
28
+ "peerDependencies": {
29
+ "@composio/core": "0.1.53",
30
+ "llamaindex": "^0.12.0"
31
+ },
32
+ "devDependencies": {
33
+ "tsup": "^8.5.0",
34
+ "typescript": "^5.9.2",
35
+ "@composio/core": "0.1.53"
36
+ },
37
+ "scripts": {
38
+ "build": "tsup",
39
+ "test": "vitest run"
40
+ },
41
+ "types": "dist/index.d.ts"
42
+ }