chat-agent-toolkit 1.2.32 → 1.2.34
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/research-agent.cjs.js +1 -1
- package/dist/research-agent.cjs.js.map +1 -1
- package/dist/research-agent.es.js +1 -1
- package/dist/research-agent.es.js.map +1 -1
- package/package.json +1 -1
- package/src/config/config-manager.ts +295 -295
- package/src/config/config-types.ts +65 -65
- package/src/config/environment-variables.ts +16 -16
- package/src/config/index.ts +26 -26
- package/src/config/language-models-database.ts +1434 -1434
- package/src/config/mcp-server-registry.ts +24 -24
- package/src/config/model-registry.ts +271 -271
- package/src/config/model-tester.ts +211 -211
- package/src/config/model-utils.ts +193 -193
- package/src/config/provider-ui-config.ts +196 -196
- package/src/connectors/open-connector.json +130 -130
- package/src/index.ts +26 -26
- package/src/memory/ARCHITECTURE.md +302 -302
- package/src/memory/README.md +224 -224
- package/src/memory/agent-memory-manager.ts +416 -416
- package/src/memory/example.ts +343 -343
- package/src/memory/index.ts +47 -47
- package/src/memory/mastra-integration.ts +604 -604
- package/src/memory/storage/drizzle-storage.ts +236 -236
- package/src/memory/storage/in-memory-storage.ts +551 -551
- package/src/memory/storage/storage-interface.ts +68 -68
- package/src/memory/types.ts +125 -125
- package/src/models/types.ts +4 -4
- package/src/provider-logos/01-ai.png +0 -0
- package/src/provider-logos/anthropic.png +0 -0
- package/src/provider-logos/aws-bedrock.png +0 -0
- package/src/provider-logos/aws-sagemaker.png +0 -0
- package/src/provider-logos/azure-openai-service.png +0 -0
- package/src/provider-logos/chatglm.png +0 -0
- package/src/provider-logos/cohere.png +0 -0
- package/src/provider-logos/gemini.png +0 -0
- package/src/provider-logos/groqcloud.png +0 -0
- package/src/provider-logos/huggingface.png +0 -0
- package/src/provider-logos/jina.png +0 -0
- package/src/provider-logos/localai.png +0 -0
- package/src/provider-logos/mistral-ai.png +0 -0
- package/src/provider-logos/moonshot-ai.png +0 -0
- package/src/provider-logos/ollama.png +0 -0
- package/src/provider-logos/openai.png +0 -0
- package/src/provider-logos/openllm.png +0 -0
- package/src/provider-logos/openrouter.png +0 -0
- package/src/provider-logos/replicate.png +0 -0
- package/src/provider-logos/together-ai.png +0 -0
- package/src/provider-logos/tongyi.png +0 -0
- package/src/provider-logos/xorbits-inference.png +0 -0
- package/src/provider-logos/zhipu-ai.png +0 -0
- package/src/tools/index.ts +13 -13
- package/src/tools/open-connector-mastra.ts +270 -270
- package/src/tools/open-connector-mcp.ts +170 -170
- package/src/tools/qwksearch-api-tools.ts +326 -326
- package/src/tools/search/doc-utils.ts +139 -139
- package/src/tools/search/document.ts +47 -47
- package/src/tools/search/index.ts +14 -14
- package/src/tools/search/link-summarizer.ts +112 -112
- package/src/tools/search/meta-search-types.ts +62 -62
- package/src/tools/search/metaSearchAgent.ts +465 -465
- package/src/tools/search/search-handlers.ts +97 -97
- package/src/tools/search/suggestionGeneratorAgent.ts +56 -56
- package/src/types.d.ts +137 -137
- package/src/utils/index.ts +2 -2
- package/src/utils/markdown-to-html.ts +53 -53
- package/src/utils/outputParser.ts +73 -73
|
@@ -1,170 +1,170 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview OpenConnector MCP Integration for AI SDK v5
|
|
3
|
-
*
|
|
4
|
-
* OpenConnector is a self-hosted Cloudflare Workers integration platform
|
|
5
|
-
* that provides OAuth-managed access to 100+ apps. This module creates
|
|
6
|
-
* MCP clients connected to OpenConnector's HTTP endpoints, fetches
|
|
7
|
-
* available tools, and passes them to AI SDK models.
|
|
8
|
-
*
|
|
9
|
-
* Architecture:
|
|
10
|
-
* 1. Connect to OpenConnector Worker URL at /mcp/sse
|
|
11
|
-
* 2. Authenticate with admin token via Authorization header
|
|
12
|
-
* 3. Fetch tools with client.tools()
|
|
13
|
-
* 4. Pass to streamText/generateText
|
|
14
|
-
*
|
|
15
|
-
* @see https://github.com/OpenSourceAGI/open-connector
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { createMCPClient } from '@ai-sdk/mcp';
|
|
19
|
-
import type { MCPClient } from '@ai-sdk/mcp';
|
|
20
|
-
import type { ToolSet } from 'ai';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Configuration for OpenConnector MCP session
|
|
24
|
-
*/
|
|
25
|
-
export interface OpenConnectorMCPConfig {
|
|
26
|
-
/** OpenConnector admin token (OPEN_CONNECTOR_ADMIN_TOKEN) */
|
|
27
|
-
adminToken: string;
|
|
28
|
-
/** Base URL of the deployed OpenConnector Worker */
|
|
29
|
-
baseUrl: string;
|
|
30
|
-
/** User ID to scope the session */
|
|
31
|
-
userId: string;
|
|
32
|
-
/** Apps to enable (e.g., ['gmail', 'notion', 'slack']) */
|
|
33
|
-
apps: string[];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* OpenConnector MCP session wrapper
|
|
38
|
-
* Manages the lifecycle of MCP client connections to OpenConnector
|
|
39
|
-
*/
|
|
40
|
-
export class OpenConnectorMCPSession {
|
|
41
|
-
private client: MCPClient | null = null;
|
|
42
|
-
|
|
43
|
-
constructor(private config: OpenConnectorMCPConfig) {}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Get or create the MCP client connection
|
|
47
|
-
* Uses HTTP SSE transport as provided by OpenConnector
|
|
48
|
-
*/
|
|
49
|
-
async getClient(): Promise<MCPClient> {
|
|
50
|
-
if (this.client) {
|
|
51
|
-
return this.client;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Construct MCP endpoint URL
|
|
55
|
-
const mcpUrl = `${this.config.baseUrl}/mcp/sse`;
|
|
56
|
-
|
|
57
|
-
// Connect to OpenConnector MCP endpoint via HTTP
|
|
58
|
-
this.client = await createMCPClient({
|
|
59
|
-
transport: {
|
|
60
|
-
type: 'http',
|
|
61
|
-
url: mcpUrl,
|
|
62
|
-
headers: {
|
|
63
|
-
Authorization: `Bearer ${this.config.adminToken}`,
|
|
64
|
-
},
|
|
65
|
-
redirect: 'error',
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
return this.client;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Get all available tools from OpenConnector MCP
|
|
74
|
-
* These tools can be passed directly to streamText/generateText
|
|
75
|
-
*
|
|
76
|
-
* @returns Tools object compatible with AI SDK
|
|
77
|
-
*/
|
|
78
|
-
async getTools(): Promise<ToolSet> {
|
|
79
|
-
const client = await this.getClient();
|
|
80
|
-
return (await client.tools()) as ToolSet;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Close the MCP connection
|
|
85
|
-
* Should be called after request completion or in finally block
|
|
86
|
-
*/
|
|
87
|
-
async close() {
|
|
88
|
-
if (this.client) {
|
|
89
|
-
await this.client.close();
|
|
90
|
-
this.client = null;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Health check for the OpenConnector Worker
|
|
96
|
-
*/
|
|
97
|
-
async healthCheck(): Promise<boolean> {
|
|
98
|
-
try {
|
|
99
|
-
const response = await fetch(`${this.config.baseUrl}/health`, {
|
|
100
|
-
headers: {
|
|
101
|
-
Authorization: `Bearer ${this.config.adminToken}`,
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
return response.ok;
|
|
105
|
-
} catch {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Helper function to create a one-shot OpenConnector MCP session
|
|
113
|
-
* For quick tool usage without managing session lifecycle
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```ts
|
|
117
|
-
* const tools = await getOpenConnectorTools({
|
|
118
|
-
* adminToken: process.env.OPEN_CONNECTOR_ADMIN_TOKEN!,
|
|
119
|
-
* baseUrl: 'https://open-connector.example.workers.dev',
|
|
120
|
-
* userId: 'user-123',
|
|
121
|
-
* apps: ['gmail', 'slack'],
|
|
122
|
-
* });
|
|
123
|
-
*
|
|
124
|
-
* const result = await generateText({
|
|
125
|
-
* model: openai('gpt-4o'),
|
|
126
|
-
* prompt: 'Check my unread emails',
|
|
127
|
-
* tools,
|
|
128
|
-
* });
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
export async function getOpenConnectorTools(
|
|
132
|
-
config: OpenConnectorMCPConfig
|
|
133
|
-
): Promise<ToolSet> {
|
|
134
|
-
const session = new OpenConnectorMCPSession(config);
|
|
135
|
-
try {
|
|
136
|
-
return await session.getTools();
|
|
137
|
-
} finally {
|
|
138
|
-
await session.close();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Create a reusable OpenConnector MCP session
|
|
144
|
-
* Better for multiple requests with the same apps
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```ts
|
|
148
|
-
* const session = await createOpenConnectorSession({
|
|
149
|
-
* adminToken: process.env.OPEN_CONNECTOR_ADMIN_TOKEN!,
|
|
150
|
-
* baseUrl: 'https://open-connector.example.workers.dev',
|
|
151
|
-
* userId: 'user-123',
|
|
152
|
-
* apps: ['gmail', 'notion'],
|
|
153
|
-
* });
|
|
154
|
-
*
|
|
155
|
-
* try {
|
|
156
|
-
* const tools = await session.getTools();
|
|
157
|
-
* const result = await streamText({ model, messages, tools });
|
|
158
|
-
* } finally {
|
|
159
|
-
* await session.close();
|
|
160
|
-
* }
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
export async function createOpenConnectorSession(
|
|
164
|
-
config: OpenConnectorMCPConfig
|
|
165
|
-
): Promise<OpenConnectorMCPSession> {
|
|
166
|
-
const session = new OpenConnectorMCPSession(config);
|
|
167
|
-
// Pre-initialize the connection
|
|
168
|
-
await session.getClient();
|
|
169
|
-
return session;
|
|
170
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview OpenConnector MCP Integration for AI SDK v5
|
|
3
|
+
*
|
|
4
|
+
* OpenConnector is a self-hosted Cloudflare Workers integration platform
|
|
5
|
+
* that provides OAuth-managed access to 100+ apps. This module creates
|
|
6
|
+
* MCP clients connected to OpenConnector's HTTP endpoints, fetches
|
|
7
|
+
* available tools, and passes them to AI SDK models.
|
|
8
|
+
*
|
|
9
|
+
* Architecture:
|
|
10
|
+
* 1. Connect to OpenConnector Worker URL at /mcp/sse
|
|
11
|
+
* 2. Authenticate with admin token via Authorization header
|
|
12
|
+
* 3. Fetch tools with client.tools()
|
|
13
|
+
* 4. Pass to streamText/generateText
|
|
14
|
+
*
|
|
15
|
+
* @see https://github.com/OpenSourceAGI/open-connector
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { createMCPClient } from '@ai-sdk/mcp';
|
|
19
|
+
import type { MCPClient } from '@ai-sdk/mcp';
|
|
20
|
+
import type { ToolSet } from 'ai';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Configuration for OpenConnector MCP session
|
|
24
|
+
*/
|
|
25
|
+
export interface OpenConnectorMCPConfig {
|
|
26
|
+
/** OpenConnector admin token (OPEN_CONNECTOR_ADMIN_TOKEN) */
|
|
27
|
+
adminToken: string;
|
|
28
|
+
/** Base URL of the deployed OpenConnector Worker */
|
|
29
|
+
baseUrl: string;
|
|
30
|
+
/** User ID to scope the session */
|
|
31
|
+
userId: string;
|
|
32
|
+
/** Apps to enable (e.g., ['gmail', 'notion', 'slack']) */
|
|
33
|
+
apps: string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* OpenConnector MCP session wrapper
|
|
38
|
+
* Manages the lifecycle of MCP client connections to OpenConnector
|
|
39
|
+
*/
|
|
40
|
+
export class OpenConnectorMCPSession {
|
|
41
|
+
private client: MCPClient | null = null;
|
|
42
|
+
|
|
43
|
+
constructor(private config: OpenConnectorMCPConfig) {}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Get or create the MCP client connection
|
|
47
|
+
* Uses HTTP SSE transport as provided by OpenConnector
|
|
48
|
+
*/
|
|
49
|
+
async getClient(): Promise<MCPClient> {
|
|
50
|
+
if (this.client) {
|
|
51
|
+
return this.client;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Construct MCP endpoint URL
|
|
55
|
+
const mcpUrl = `${this.config.baseUrl}/mcp/sse`;
|
|
56
|
+
|
|
57
|
+
// Connect to OpenConnector MCP endpoint via HTTP
|
|
58
|
+
this.client = await createMCPClient({
|
|
59
|
+
transport: {
|
|
60
|
+
type: 'http',
|
|
61
|
+
url: mcpUrl,
|
|
62
|
+
headers: {
|
|
63
|
+
Authorization: `Bearer ${this.config.adminToken}`,
|
|
64
|
+
},
|
|
65
|
+
redirect: 'error',
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return this.client;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get all available tools from OpenConnector MCP
|
|
74
|
+
* These tools can be passed directly to streamText/generateText
|
|
75
|
+
*
|
|
76
|
+
* @returns Tools object compatible with AI SDK
|
|
77
|
+
*/
|
|
78
|
+
async getTools(): Promise<ToolSet> {
|
|
79
|
+
const client = await this.getClient();
|
|
80
|
+
return (await client.tools()) as ToolSet;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Close the MCP connection
|
|
85
|
+
* Should be called after request completion or in finally block
|
|
86
|
+
*/
|
|
87
|
+
async close() {
|
|
88
|
+
if (this.client) {
|
|
89
|
+
await this.client.close();
|
|
90
|
+
this.client = null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Health check for the OpenConnector Worker
|
|
96
|
+
*/
|
|
97
|
+
async healthCheck(): Promise<boolean> {
|
|
98
|
+
try {
|
|
99
|
+
const response = await fetch(`${this.config.baseUrl}/health`, {
|
|
100
|
+
headers: {
|
|
101
|
+
Authorization: `Bearer ${this.config.adminToken}`,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
return response.ok;
|
|
105
|
+
} catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Helper function to create a one-shot OpenConnector MCP session
|
|
113
|
+
* For quick tool usage without managing session lifecycle
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const tools = await getOpenConnectorTools({
|
|
118
|
+
* adminToken: process.env.OPEN_CONNECTOR_ADMIN_TOKEN!,
|
|
119
|
+
* baseUrl: 'https://open-connector.example.workers.dev',
|
|
120
|
+
* userId: 'user-123',
|
|
121
|
+
* apps: ['gmail', 'slack'],
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* const result = await generateText({
|
|
125
|
+
* model: openai('gpt-4o'),
|
|
126
|
+
* prompt: 'Check my unread emails',
|
|
127
|
+
* tools,
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export async function getOpenConnectorTools(
|
|
132
|
+
config: OpenConnectorMCPConfig
|
|
133
|
+
): Promise<ToolSet> {
|
|
134
|
+
const session = new OpenConnectorMCPSession(config);
|
|
135
|
+
try {
|
|
136
|
+
return await session.getTools();
|
|
137
|
+
} finally {
|
|
138
|
+
await session.close();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Create a reusable OpenConnector MCP session
|
|
144
|
+
* Better for multiple requests with the same apps
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* const session = await createOpenConnectorSession({
|
|
149
|
+
* adminToken: process.env.OPEN_CONNECTOR_ADMIN_TOKEN!,
|
|
150
|
+
* baseUrl: 'https://open-connector.example.workers.dev',
|
|
151
|
+
* userId: 'user-123',
|
|
152
|
+
* apps: ['gmail', 'notion'],
|
|
153
|
+
* });
|
|
154
|
+
*
|
|
155
|
+
* try {
|
|
156
|
+
* const tools = await session.getTools();
|
|
157
|
+
* const result = await streamText({ model, messages, tools });
|
|
158
|
+
* } finally {
|
|
159
|
+
* await session.close();
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export async function createOpenConnectorSession(
|
|
164
|
+
config: OpenConnectorMCPConfig
|
|
165
|
+
): Promise<OpenConnectorMCPSession> {
|
|
166
|
+
const session = new OpenConnectorMCPSession(config);
|
|
167
|
+
// Pre-initialize the connection
|
|
168
|
+
await session.getClient();
|
|
169
|
+
return session;
|
|
170
|
+
}
|