@agentionai/agents 0.6.1 → 0.8.0
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/dist/agents/BaseAgent.d.ts +0 -39
- package/dist/agents/BaseAgent.js +1 -100
- package/dist/agents/anthropic/ClaudeAgent.d.ts +2 -0
- package/dist/agents/anthropic/ClaudeAgent.js +4 -8
- package/dist/agents/google/GeminiAgent.d.ts +2 -0
- package/dist/agents/google/GeminiAgent.js +4 -4
- package/dist/agents/mistral/MistralAgent.d.ts +2 -0
- package/dist/agents/mistral/MistralAgent.js +4 -4
- package/dist/agents/openai/OpenAiAgent.d.ts +2 -0
- package/dist/agents/openai/OpenAiAgent.js +4 -4
- package/dist/chunkers/Chunker.d.ts +1 -1
- package/dist/chunkers/Chunker.js +19 -20
- package/dist/chunkers/TokenChunker.d.ts +1 -1
- package/dist/chunkers/TokenChunker.js +2 -3
- package/dist/chunkers/types.d.ts +17 -11
- package/dist/core.d.ts +1 -0
- package/dist/core.js +2 -0
- package/dist/graph/planning/PlanExecutor.d.ts +0 -12
- package/dist/graph/planning/PlanExecutor.js +19 -74
- package/dist/graph/planning/PlanStore.js +2 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/mcp/MCPClient.d.ts +106 -0
- package/dist/mcp/MCPClient.js +264 -0
- package/dist/mcp/index.d.ts +64 -0
- package/dist/mcp/index.js +67 -0
- package/dist/mcp/types.d.ts +51 -0
- package/dist/mcp/types.js +3 -0
- package/dist/vectorstore/LanceDBVectorStore.d.ts +102 -54
- package/dist/vectorstore/LanceDBVectorStore.js +231 -135
- package/dist/vectorstore/VectorStore.d.ts +2 -2
- package/dist/vectorstore/VectorStore.js +3 -3
- package/package.json +7 -3
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MCP (Model Context Protocol) support for agention-lib.
|
|
4
|
+
*
|
|
5
|
+
* Connects to any MCP server — local stdio processes or remote HTTP endpoints —
|
|
6
|
+
* and exposes their tools as agention-lib {@link Tool} instances compatible with
|
|
7
|
+
* all agent types (ClaudeAgent, OpenAiAgent, MistralAgent, GeminiAgent).
|
|
8
|
+
*
|
|
9
|
+
* @requires @modelcontextprotocol/sdk - Optional peer dependency, install when needed:
|
|
10
|
+
* ```
|
|
11
|
+
* npm install @modelcontextprotocol/sdk
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @example Stdio (local process)
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { MCPClient, ClaudeAgent } from "@agentionai/agents";
|
|
17
|
+
*
|
|
18
|
+
* const mcp = MCPClient.fromStdio({
|
|
19
|
+
* command: "npx",
|
|
20
|
+
* args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* await mcp.connect();
|
|
24
|
+
*
|
|
25
|
+
* const agent = new ClaudeAgent({
|
|
26
|
+
* id: "file-agent",
|
|
27
|
+
* name: "File Agent",
|
|
28
|
+
* description: "An agent that can work with files",
|
|
29
|
+
* apiKey: process.env.ANTHROPIC_API_KEY!,
|
|
30
|
+
* tools: mcp.getTools(),
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* const result = await agent.execute("List the files in /tmp");
|
|
34
|
+
* await mcp.disconnect();
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example HTTP with static API key
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { MCPClient } from "@agentionai/agents";
|
|
40
|
+
*
|
|
41
|
+
* const mcp = MCPClient.fromUrl("https://my-mcp-server.com/mcp", {
|
|
42
|
+
* headers: { Authorization: "Bearer my-api-key" },
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* await mcp.connect();
|
|
46
|
+
* agent.addTools(mcp.getTools());
|
|
47
|
+
* await mcp.disconnect();
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example HTTP with OAuth
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { MCPClient } from "@agentionai/agents";
|
|
53
|
+
* import type { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
54
|
+
*
|
|
55
|
+
* // Implement OAuthClientProvider from the MCP SDK
|
|
56
|
+
* const myOAuthProvider: OAuthClientProvider = { ... };
|
|
57
|
+
*
|
|
58
|
+
* const mcp = MCPClient.fromUrl("https://my-mcp-server.com/mcp", {
|
|
59
|
+
* authProvider: myOAuthProvider,
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
+
exports.MCPClient = void 0;
|
|
65
|
+
var MCPClient_1 = require("./MCPClient");
|
|
66
|
+
Object.defineProperty(exports, "MCPClient", { enumerable: true, get: function () { return MCPClient_1.MCPClient; } });
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for connecting to an MCP server via stdio (local process).
|
|
3
|
+
*/
|
|
4
|
+
export interface MCPStdioConfig {
|
|
5
|
+
/** The command to spawn (e.g. "node", "python", "npx") */
|
|
6
|
+
command: string;
|
|
7
|
+
/** Arguments to pass to the command */
|
|
8
|
+
args?: string[];
|
|
9
|
+
/** Environment variables for the spawned process */
|
|
10
|
+
env?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Configuration for connecting to an MCP server via HTTP (remote URL).
|
|
14
|
+
*/
|
|
15
|
+
export interface MCPHttpConfig {
|
|
16
|
+
/** Full URL to the MCP endpoint */
|
|
17
|
+
url: string;
|
|
18
|
+
/** Optional HTTP headers for static auth tokens or API keys */
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
/**
|
|
21
|
+
* Optional OAuth provider for dynamic authorization.
|
|
22
|
+
* Implement the `OAuthClientProvider` interface from `@modelcontextprotocol/sdk`
|
|
23
|
+
* and pass it here for OAuth 2.0 + PKCE flows.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
28
|
+
*
|
|
29
|
+
* const mcp = MCPClient.fromUrl("https://my-server.com/mcp", {
|
|
30
|
+
* authProvider: myOAuthProvider,
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
authProvider?: unknown;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Options shared by all MCPClient connection types.
|
|
38
|
+
*/
|
|
39
|
+
export interface MCPClientOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Name to identify this MCP client (sent during SDK handshake).
|
|
42
|
+
* @default "agention-mcp-client"
|
|
43
|
+
*/
|
|
44
|
+
clientName?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Version string for the MCP client.
|
|
47
|
+
* @default "1.0.0"
|
|
48
|
+
*/
|
|
49
|
+
clientVersion?: string;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -18,7 +18,7 @@ export type MetadataFieldType = "string" | "number" | "boolean";
|
|
|
18
18
|
* Definition for a metadata field that will be stored as a separate column.
|
|
19
19
|
*/
|
|
20
20
|
export interface MetadataFieldDefinition {
|
|
21
|
-
/** Name of the metadata field */
|
|
21
|
+
/** Name of the metadata field. Use snake_case (e.g. `tenant_id`) to avoid SQL filter issues. */
|
|
22
22
|
name: string;
|
|
23
23
|
/** Data type for the field */
|
|
24
24
|
type: MetadataFieldType;
|
|
@@ -42,73 +42,84 @@ export interface LanceDBVectorStoreConfig {
|
|
|
42
42
|
/** Additional connection options */
|
|
43
43
|
connectionOptions?: Partial<ConnectionOptions>;
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
45
|
+
* User-defined metadata field definitions.
|
|
46
|
+
*
|
|
47
|
+
* When provided, these fields are stored as typed Arrow columns and are
|
|
48
|
+
* filterable via SQL predicates in `search()`. The table is created on
|
|
49
|
+
* first insert using an explicit Arrow schema built from these definitions.
|
|
50
|
+
*
|
|
51
|
+
* **Important:** Use `snake_case` for field names (e.g. `tenant_id`, not
|
|
52
|
+
* `tenantId`). LanceDB uses DataFusion for SQL filtering, which normalizes
|
|
53
|
+
* unquoted identifiers to lowercase. Mixed-case names like `tenantId` will
|
|
54
|
+
* fail to match the column `tenantId` because the filter resolves to
|
|
55
|
+
* `tenantid`.
|
|
56
|
+
*
|
|
57
|
+
* Chunk metadata fields (index, hash, prev_id, etc.) are handled
|
|
58
|
+
* automatically via a `chunk_metadata` struct column — they do not need
|
|
59
|
+
* to be listed here.
|
|
60
|
+
*
|
|
61
|
+
* When omitted, the store connects to a **pre-existing** table (created
|
|
62
|
+
* independently, e.g. via the LanceDB CLI or another tool). In that case
|
|
63
|
+
* the schema is not managed by this class and all non-system columns are
|
|
64
|
+
* returned as metadata on read.
|
|
48
65
|
*/
|
|
49
66
|
metadataFields?: MetadataFieldDefinition[];
|
|
50
67
|
}
|
|
51
68
|
/**
|
|
52
69
|
* LanceDB implementation of the VectorStore interface.
|
|
53
70
|
*
|
|
54
|
-
*
|
|
55
|
-
* ```typescript
|
|
56
|
-
* import { LanceDBVectorStore, OpenAIEmbeddings } from "@agentionai/agents";
|
|
71
|
+
* Supports two modes of operation:
|
|
57
72
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* const store = await LanceDBVectorStore.create({
|
|
64
|
-
* name: "knowledge_base",
|
|
65
|
-
* uri: "./my-database",
|
|
66
|
-
* tableName: "documents",
|
|
67
|
-
* embeddings,
|
|
68
|
-
* });
|
|
73
|
+
* **Managed mode** (`metadataFields` provided): The store creates the LanceDB
|
|
74
|
+
* table on first insert using an explicit Arrow schema derived from
|
|
75
|
+
* `metadataFields`. User-defined fields are stored as typed top-level columns.
|
|
76
|
+
* Chunk metadata (from chunkers) is automatically packed into a `chunk_metadata`
|
|
77
|
+
* struct column.
|
|
69
78
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* ]);
|
|
79
|
+
* **Pre-existing table mode** (`metadataFields` omitted): The store connects
|
|
80
|
+
* to a table that was created independently (e.g. via LanceDB CLI or another
|
|
81
|
+
* tool). No schema management is performed; all non-system columns are returned
|
|
82
|
+
* as metadata on read.
|
|
75
83
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
84
|
+
* @example Managed mode — user-defined metadata fields
|
|
85
|
+
* ```typescript
|
|
86
|
+
* import { LanceDBVectorStore } from "@agentionai/agents";
|
|
87
|
+
* import { OpenAIEmbeddings } from "@agentionai/agents/embeddings";
|
|
78
88
|
*
|
|
79
|
-
*
|
|
80
|
-
* const searchTool = store.toRetrievalTool("Search the knowledge base");
|
|
81
|
-
* ```
|
|
89
|
+
* const embeddings = new OpenAIEmbeddings({ model: "text-embedding-3-small" });
|
|
82
90
|
*
|
|
83
|
-
* @example With filterable metadata fields
|
|
84
|
-
* ```typescript
|
|
85
91
|
* const store = await LanceDBVectorStore.create({
|
|
86
92
|
* name: "knowledge_base",
|
|
87
93
|
* uri: "./my-database",
|
|
88
|
-
* tableName: "
|
|
94
|
+
* tableName: "chunks",
|
|
89
95
|
* embeddings,
|
|
90
96
|
* metadataFields: [
|
|
91
|
-
* { name: "
|
|
92
|
-
* { name: "
|
|
93
|
-
* { name: "year", type: "number" },
|
|
94
|
-
* { name: "verified", type: "boolean" },
|
|
95
|
-
* { name: "hash", type: "string" }, // Enables efficient deduplication
|
|
97
|
+
* { name: "author", type: "string", nullable: true },
|
|
98
|
+
* { name: "category", type: "string", nullable: true },
|
|
96
99
|
* ],
|
|
97
100
|
* });
|
|
98
101
|
*
|
|
99
|
-
* //
|
|
102
|
+
* // Chunk metadata (index, hash, prev_id, etc.) is stored automatically
|
|
103
|
+
* // in a chunk_metadata struct column — no need to declare it.
|
|
100
104
|
* await store.addDocuments([
|
|
101
|
-
* {
|
|
102
|
-
* id: "1",
|
|
103
|
-
* content: "LanceDB is a vector database",
|
|
104
|
-
* metadata: { category: "database", source: "docs", year: 2024, verified: true },
|
|
105
|
-
* },
|
|
105
|
+
* { id: "1", content: "LanceDB is a vector database", metadata: { category: "db" } },
|
|
106
106
|
* ]);
|
|
107
107
|
*
|
|
108
|
-
* // Search with filters on metadata columns
|
|
108
|
+
* // Search with filters on user metadata columns
|
|
109
109
|
* const results = await store.search("vector database", {
|
|
110
110
|
* limit: 5,
|
|
111
|
-
* filter: { category: "
|
|
111
|
+
* filter: { category: "db" },
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @example Pre-existing table mode — connect to externally managed table
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const store = await LanceDBVectorStore.create({
|
|
118
|
+
* name: "my_store",
|
|
119
|
+
* uri: "./my-database",
|
|
120
|
+
* tableName: "existing_table", // table already exists with its own schema
|
|
121
|
+
* embeddings,
|
|
122
|
+
* // metadataFields omitted — schema is not managed by this class
|
|
112
123
|
* });
|
|
113
124
|
* ```
|
|
114
125
|
*/
|
|
@@ -124,14 +135,25 @@ export declare class LanceDBVectorStore extends VectorStore {
|
|
|
124
135
|
/**
|
|
125
136
|
* Create a new LanceDBVectorStore instance.
|
|
126
137
|
*
|
|
127
|
-
*
|
|
138
|
+
* - If the table already exists it is opened immediately.
|
|
139
|
+
* - If `metadataFields` is provided and the table does not exist yet, it
|
|
140
|
+
* will be created on the first insert with an explicit Arrow schema.
|
|
141
|
+
* - If `metadataFields` is **not** provided and the table does not exist,
|
|
142
|
+
* an error is thrown — the store cannot manage an unknown schema.
|
|
128
143
|
*
|
|
129
144
|
* @param config - Configuration for the store
|
|
130
145
|
* @returns A configured LanceDBVectorStore instance
|
|
131
146
|
*
|
|
132
147
|
* @throws Error if @lancedb/lancedb is not installed
|
|
148
|
+
* @throws Error if the table does not exist and no metadataFields are provided
|
|
133
149
|
*/
|
|
134
150
|
static create(config: LanceDBVectorStoreConfig): Promise<LanceDBVectorStore>;
|
|
151
|
+
/**
|
|
152
|
+
* Create the table with an explicit Arrow schema derived from `metadataFields`
|
|
153
|
+
* plus a `chunk_metadata` struct column.
|
|
154
|
+
* Called on the first insert when operating in managed mode.
|
|
155
|
+
*/
|
|
156
|
+
private createManagedTable;
|
|
135
157
|
/**
|
|
136
158
|
* Add documents to the vector store.
|
|
137
159
|
* If an embeddings provider is configured, embeddings are generated automatically.
|
|
@@ -139,8 +161,29 @@ export declare class LanceDBVectorStore extends VectorStore {
|
|
|
139
161
|
addDocuments(documents: Document[], _options?: AddDocumentsOptions): Promise<string[]>;
|
|
140
162
|
/**
|
|
141
163
|
* Add documents with pre-computed embeddings.
|
|
164
|
+
*
|
|
165
|
+
* In managed mode, chunk metadata fields are packed into a `chunk_metadata`
|
|
166
|
+
* struct and user-defined fields are projected to their declared columns.
|
|
167
|
+
* The table is created on the first call; subsequent calls append directly.
|
|
168
|
+
*
|
|
169
|
+
* In pre-existing table mode all metadata is spread flat as-is.
|
|
142
170
|
*/
|
|
143
171
|
addEmbeddedDocuments(documents: EmbeddedDocument[], _options?: AddDocumentsOptions): Promise<string[]>;
|
|
172
|
+
/**
|
|
173
|
+
* Pack chunk metadata fields from flat metadata into a struct object.
|
|
174
|
+
* Returns a plain object for the `chunk_metadata` column, or null if
|
|
175
|
+
* no chunk metadata fields are present.
|
|
176
|
+
*/
|
|
177
|
+
private packChunkMetadata;
|
|
178
|
+
/**
|
|
179
|
+
* Unpack a chunk_metadata struct value back to flat metadata keys.
|
|
180
|
+
*/
|
|
181
|
+
private unpackChunkMetadata;
|
|
182
|
+
/**
|
|
183
|
+
* Project a record to only the columns declared in the schema
|
|
184
|
+
* (id, text, vector, chunk_metadata, plus all metadataFields).
|
|
185
|
+
*/
|
|
186
|
+
private projectToSchema;
|
|
144
187
|
/**
|
|
145
188
|
* Search for documents similar to the query.
|
|
146
189
|
*/
|
|
@@ -165,8 +208,9 @@ export declare class LanceDBVectorStore extends VectorStore {
|
|
|
165
208
|
* Get existing documents by their content hashes.
|
|
166
209
|
* Used for deduplication during ingestion.
|
|
167
210
|
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
211
|
+
* Requires that documents were stored with chunk metadata containing
|
|
212
|
+
* a `hash` field (automatically present when using chunkers from this library).
|
|
213
|
+
* Queries the `chunk_metadata.hash` struct sub-field.
|
|
170
214
|
*/
|
|
171
215
|
getByHashes(hashes: string[], _options?: DeleteOptions): Promise<Map<string, string>>;
|
|
172
216
|
/**
|
|
@@ -174,9 +218,9 @@ export declare class LanceDBVectorStore extends VectorStore {
|
|
|
174
218
|
*/
|
|
175
219
|
getConnection(): Connection;
|
|
176
220
|
/**
|
|
177
|
-
* Get the underlying LanceDB table.
|
|
221
|
+
* Get the underlying LanceDB table, or null if no data has been inserted yet.
|
|
178
222
|
*/
|
|
179
|
-
getTable(): Table;
|
|
223
|
+
getTable(): Table | null;
|
|
180
224
|
/**
|
|
181
225
|
* Get the configured embeddings provider.
|
|
182
226
|
*/
|
|
@@ -194,6 +238,10 @@ export declare class LanceDBVectorStore extends VectorStore {
|
|
|
194
238
|
* Optimize the table for better performance.
|
|
195
239
|
*/
|
|
196
240
|
optimize(): Promise<void>;
|
|
241
|
+
/**
|
|
242
|
+
* Get the configured metadata fields.
|
|
243
|
+
*/
|
|
244
|
+
getMetadataFields(): MetadataFieldDefinition[] | undefined;
|
|
197
245
|
/**
|
|
198
246
|
* Build a SQL filter string from a filter object.
|
|
199
247
|
*/
|
|
@@ -203,12 +251,12 @@ export declare class LanceDBVectorStore extends VectorStore {
|
|
|
203
251
|
*/
|
|
204
252
|
private processResults;
|
|
205
253
|
/**
|
|
206
|
-
* Extract metadata from a row
|
|
254
|
+
* Extract metadata from a row.
|
|
255
|
+
*
|
|
256
|
+
* In managed mode: returns user-defined fields plus unpacked chunk_metadata.
|
|
257
|
+
* In pre-existing table mode: returns all non-system columns, with
|
|
258
|
+
* chunk_metadata unpacked if present.
|
|
207
259
|
*/
|
|
208
260
|
private extractMetadata;
|
|
209
|
-
/**
|
|
210
|
-
* Get the configured metadata fields.
|
|
211
|
-
*/
|
|
212
|
-
getMetadataFields(): MetadataFieldDefinition[] | undefined;
|
|
213
261
|
}
|
|
214
262
|
//# sourceMappingURL=LanceDBVectorStore.d.ts.map
|