@olane/o-tool-registry 0.6.7 → 0.6.9
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/auth/index.d.ts +4 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +3 -0
- package/dist/auth/interfaces/index.d.ts +4 -0
- package/dist/auth/interfaces/index.d.ts.map +1 -0
- package/dist/auth/interfaces/index.js +3 -0
- package/dist/auth/interfaces/oAuth-tokens.interface.d.ts +9 -0
- package/dist/auth/interfaces/oAuth-tokens.interface.d.ts.map +1 -0
- package/dist/auth/interfaces/oAuth-tokens.interface.js +1 -0
- package/dist/auth/interfaces/oAuth-user-info.interface.d.ts +8 -0
- package/dist/auth/interfaces/oAuth-user-info.interface.d.ts.map +1 -0
- package/dist/auth/interfaces/oAuth-user-info.interface.js +1 -0
- package/dist/auth/interfaces/oAuth.config.d.ts +14 -0
- package/dist/auth/interfaces/oAuth.config.d.ts.map +1 -0
- package/dist/auth/interfaces/oAuth.config.js +1 -0
- package/dist/auth/methods/auth.methods.d.ts +5 -0
- package/dist/auth/methods/auth.methods.d.ts.map +1 -0
- package/dist/auth/methods/auth.methods.js +302 -0
- package/dist/auth/oAuth.tool.d.ts +20 -0
- package/dist/auth/oAuth.tool.d.ts.map +1 -0
- package/dist/auth/oAuth.tool.js +419 -0
- package/dist/embeddings/embeddings.tool.d.ts +6 -0
- package/dist/embeddings/embeddings.tool.d.ts.map +1 -0
- package/dist/embeddings/embeddings.tool.js +11 -0
- package/dist/embeddings/huggingface-text-embeddings.tool.d.ts +9 -0
- package/dist/embeddings/huggingface-text-embeddings.tool.d.ts.map +1 -0
- package/dist/embeddings/huggingface-text-embeddings.tool.js +21 -0
- package/dist/embeddings/index.d.ts +4 -0
- package/dist/embeddings/index.d.ts.map +1 -0
- package/dist/embeddings/index.js +3 -0
- package/dist/embeddings/methods/text-embeddings.method.d.ts +5 -0
- package/dist/embeddings/methods/text-embeddings.method.d.ts.map +1 -0
- package/dist/embeddings/methods/text-embeddings.method.js +29 -0
- package/dist/embeddings/text-embeddings.tool.d.ts +9 -0
- package/dist/embeddings/text-embeddings.tool.d.ts.map +1 -0
- package/dist/embeddings/text-embeddings.tool.js +13 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/init.d.ts +3 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +36 -0
- package/dist/intelligence/anthropic-intelligence.tool.d.ts +224 -0
- package/dist/intelligence/anthropic-intelligence.tool.d.ts.map +1 -0
- package/dist/intelligence/anthropic-intelligence.tool.js +477 -0
- package/dist/intelligence/gemini-intelligence.tool.d.ts +29 -0
- package/dist/intelligence/gemini-intelligence.tool.d.ts.map +1 -0
- package/dist/intelligence/gemini-intelligence.tool.js +267 -0
- package/dist/intelligence/index.d.ts +6 -0
- package/dist/intelligence/index.d.ts.map +1 -0
- package/dist/intelligence/index.js +5 -0
- package/dist/intelligence/intelligence.tool.d.ts +11 -0
- package/dist/intelligence/intelligence.tool.d.ts.map +1 -0
- package/dist/intelligence/intelligence.tool.js +120 -0
- package/dist/intelligence/methods/intelligence.methods.d.ts +5 -0
- package/dist/intelligence/methods/intelligence.methods.d.ts.map +1 -0
- package/dist/intelligence/methods/intelligence.methods.js +98 -0
- package/dist/intelligence/ollama-intelligence.tool.d.ts +36 -0
- package/dist/intelligence/ollama-intelligence.tool.d.ts.map +1 -0
- package/dist/intelligence/ollama-intelligence.tool.js +312 -0
- package/dist/intelligence/openai-intelligence.tool.d.ts +30 -0
- package/dist/intelligence/openai-intelligence.tool.d.ts.map +1 -0
- package/dist/intelligence/openai-intelligence.tool.js +255 -0
- package/dist/intelligence/perplexity-intelligence.tool.d.ts +27 -0
- package/dist/intelligence/perplexity-intelligence.tool.d.ts.map +1 -0
- package/dist/intelligence/perplexity-intelligence.tool.js +309 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/mcp-bridge.tool.d.ts +12 -0
- package/dist/mcp/mcp-bridge.tool.d.ts.map +1 -0
- package/dist/mcp/mcp-bridge.tool.js +126 -0
- package/dist/mcp/mcp.tool.d.ts +14 -0
- package/dist/mcp/mcp.tool.d.ts.map +1 -0
- package/dist/mcp/mcp.tool.js +83 -0
- package/dist/mcp/methods/mcp-bridge.methods.d.ts +5 -0
- package/dist/mcp/methods/mcp-bridge.methods.d.ts.map +1 -0
- package/dist/mcp/methods/mcp-bridge.methods.js +79 -0
- package/dist/nlp/index.d.ts +2 -0
- package/dist/nlp/index.d.ts.map +1 -0
- package/dist/nlp/index.js +1 -0
- package/dist/nlp/methods/nlp.methods.d.ts +5 -0
- package/dist/nlp/methods/nlp.methods.d.ts.map +1 -0
- package/dist/nlp/methods/nlp.methods.js +15 -0
- package/dist/nlp/ner.tool.d.ts +7 -0
- package/dist/nlp/ner.tool.d.ts.map +1 -0
- package/dist/nlp/ner.tool.js +25 -0
- package/dist/src/intelligence/anthropic-intelligence.tool.d.ts +224 -0
- package/dist/src/intelligence/anthropic-intelligence.tool.d.ts.map +1 -0
- package/dist/src/intelligence/anthropic-intelligence.tool.js +477 -0
- package/dist/src/intelligence/gemini-intelligence.tool.d.ts +29 -0
- package/dist/src/intelligence/gemini-intelligence.tool.d.ts.map +1 -0
- package/dist/src/intelligence/gemini-intelligence.tool.js +267 -0
- package/dist/src/intelligence/index.d.ts +6 -0
- package/dist/src/intelligence/index.d.ts.map +1 -0
- package/dist/src/intelligence/index.js +5 -0
- package/dist/src/intelligence/intelligence.tool.d.ts +11 -0
- package/dist/src/intelligence/intelligence.tool.d.ts.map +1 -0
- package/dist/src/intelligence/intelligence.tool.js +134 -0
- package/dist/src/intelligence/methods/intelligence.methods.d.ts +5 -0
- package/dist/src/intelligence/methods/intelligence.methods.d.ts.map +1 -0
- package/dist/src/intelligence/methods/intelligence.methods.js +132 -0
- package/dist/src/intelligence/ollama-intelligence.tool.d.ts +36 -0
- package/dist/src/intelligence/ollama-intelligence.tool.d.ts.map +1 -0
- package/dist/src/intelligence/ollama-intelligence.tool.js +312 -0
- package/dist/src/intelligence/openai-intelligence.tool.d.ts +30 -0
- package/dist/src/intelligence/openai-intelligence.tool.d.ts.map +1 -0
- package/dist/src/intelligence/openai-intelligence.tool.js +255 -0
- package/dist/src/intelligence/perplexity-intelligence.tool.d.ts +28 -0
- package/dist/src/intelligence/perplexity-intelligence.tool.d.ts.map +1 -0
- package/dist/src/intelligence/perplexity-intelligence.tool.js +310 -0
- package/dist/src/mcp/index.d.ts +3 -0
- package/dist/src/mcp/index.d.ts.map +1 -0
- package/dist/src/mcp/index.js +2 -0
- package/dist/src/mcp/mcp-bridge.tool.d.ts +12 -0
- package/dist/src/mcp/mcp-bridge.tool.d.ts.map +1 -0
- package/dist/src/mcp/mcp-bridge.tool.js +107 -0
- package/dist/src/mcp/mcp.tool.d.ts +15 -0
- package/dist/src/mcp/mcp.tool.d.ts.map +1 -0
- package/dist/src/mcp/mcp.tool.js +85 -0
- package/dist/src/mcp/methods/mcp-bridge.methods.d.ts +5 -0
- package/dist/src/mcp/methods/mcp-bridge.methods.d.ts.map +1 -0
- package/dist/src/mcp/methods/mcp-bridge.methods.js +58 -0
- package/dist/vector-store/index.d.ts +3 -0
- package/dist/vector-store/index.d.ts.map +1 -0
- package/dist/vector-store/index.js +2 -0
- package/dist/vector-store/langchain-memory.vector-store.tool.d.ts +14 -0
- package/dist/vector-store/langchain-memory.vector-store.tool.d.ts.map +1 -0
- package/dist/vector-store/langchain-memory.vector-store.tool.js +60 -0
- package/dist/vector-store/methods/vector-store.methods.d.ts +5 -0
- package/dist/vector-store/methods/vector-store.methods.d.ts.map +1 -0
- package/dist/vector-store/methods/vector-store.methods.js +60 -0
- package/dist/vector-store/vector-memory.tool.d.ts +11 -0
- package/dist/vector-store/vector-memory.tool.d.ts.map +1 -0
- package/dist/vector-store/vector-memory.tool.js +13 -0
- package/package.json +7 -7
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { oAddress } from '@olane/o-core';
|
|
2
|
+
import { oVirtualTool } from '@olane/o-tool';
|
|
3
|
+
import { INTELLIGENCE_PARAMS } from './methods/intelligence.methods.js';
|
|
4
|
+
export class PerplexityIntelligenceTool extends oVirtualTool {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
super({
|
|
7
|
+
...config,
|
|
8
|
+
address: new oAddress('o://perplexity'),
|
|
9
|
+
description: 'Intelligence tool using Perplexity LLM suite of models',
|
|
10
|
+
methods: INTELLIGENCE_PARAMS,
|
|
11
|
+
dependencies: [],
|
|
12
|
+
});
|
|
13
|
+
this.defaultApiKey = process.env.SONAR_API_KEY || '';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Chat completion with Perplexity
|
|
17
|
+
*/
|
|
18
|
+
async _tool_completion(request) {
|
|
19
|
+
try {
|
|
20
|
+
const params = request.params;
|
|
21
|
+
const { model = this.defaultModel, messages, max_tokens, temperature, top_p, top_k, presence_penalty, frequency_penalty, apiKey = this.defaultApiKey, search_domain, return_citations, return_images, return_related_questions, } = params;
|
|
22
|
+
if (!messages || !Array.isArray(messages)) {
|
|
23
|
+
return {
|
|
24
|
+
success: false,
|
|
25
|
+
error: '"messages" array is required',
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (!apiKey) {
|
|
29
|
+
return {
|
|
30
|
+
success: false,
|
|
31
|
+
error: 'Perplexity API key is required',
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const chatRequest = {
|
|
35
|
+
model: model,
|
|
36
|
+
messages: messages,
|
|
37
|
+
stream: false,
|
|
38
|
+
};
|
|
39
|
+
// Add optional parameters if provided
|
|
40
|
+
if (max_tokens !== undefined)
|
|
41
|
+
chatRequest.max_tokens = max_tokens;
|
|
42
|
+
if (temperature !== undefined)
|
|
43
|
+
chatRequest.temperature = temperature;
|
|
44
|
+
if (top_p !== undefined)
|
|
45
|
+
chatRequest.top_p = top_p;
|
|
46
|
+
if (top_k !== undefined)
|
|
47
|
+
chatRequest.top_k = top_k;
|
|
48
|
+
if (presence_penalty !== undefined)
|
|
49
|
+
chatRequest.presence_penalty = presence_penalty;
|
|
50
|
+
if (frequency_penalty !== undefined)
|
|
51
|
+
chatRequest.frequency_penalty = frequency_penalty;
|
|
52
|
+
if (search_domain !== undefined)
|
|
53
|
+
chatRequest.search_domain = search_domain;
|
|
54
|
+
if (return_citations !== undefined)
|
|
55
|
+
chatRequest.return_citations = return_citations;
|
|
56
|
+
if (return_images !== undefined)
|
|
57
|
+
chatRequest.return_images = return_images;
|
|
58
|
+
if (return_related_questions !== undefined)
|
|
59
|
+
chatRequest.return_related_questions = return_related_questions;
|
|
60
|
+
const response = await fetch(`https://api.perplexity.ai/chat/completions`, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: {
|
|
63
|
+
'Content-Type': 'application/json',
|
|
64
|
+
Authorization: `Bearer ${apiKey}`,
|
|
65
|
+
},
|
|
66
|
+
body: JSON.stringify(chatRequest),
|
|
67
|
+
});
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
const errorText = await response.text();
|
|
70
|
+
return {
|
|
71
|
+
success: false,
|
|
72
|
+
error: `Perplexity API error: ${response.status} - ${errorText}`,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const result = (await response.json());
|
|
76
|
+
return {
|
|
77
|
+
success: true,
|
|
78
|
+
message: result.choices[0]?.message?.content || '',
|
|
79
|
+
model: result.model,
|
|
80
|
+
usage: result.usage,
|
|
81
|
+
finish_reason: result.choices[0]?.finish_reason,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
return {
|
|
86
|
+
success: false,
|
|
87
|
+
error: `Failed to complete chat: ${error.message}`,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Generate text with Perplexity (alias for completion)
|
|
93
|
+
*/
|
|
94
|
+
async _tool_generate(request) {
|
|
95
|
+
try {
|
|
96
|
+
const params = request.params;
|
|
97
|
+
const { model = this.defaultModel, prompt, system, max_tokens, temperature, top_p, top_k, presence_penalty, frequency_penalty, search_domain, return_citations, return_images, return_related_questions, apiKey = this.defaultApiKey, } = params;
|
|
98
|
+
if (!prompt) {
|
|
99
|
+
return {
|
|
100
|
+
success: false,
|
|
101
|
+
error: 'Prompt is required',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (!apiKey) {
|
|
105
|
+
return {
|
|
106
|
+
success: false,
|
|
107
|
+
error: 'Perplexity API key is required',
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
// Convert prompt to messages format
|
|
111
|
+
const messages = [];
|
|
112
|
+
if (system) {
|
|
113
|
+
messages.push({ role: 'system', content: system });
|
|
114
|
+
}
|
|
115
|
+
messages.push({ role: 'user', content: prompt });
|
|
116
|
+
const chatRequest = {
|
|
117
|
+
model: model,
|
|
118
|
+
messages,
|
|
119
|
+
stream: false,
|
|
120
|
+
};
|
|
121
|
+
// Add optional parameters if provided
|
|
122
|
+
if (max_tokens !== undefined)
|
|
123
|
+
chatRequest.max_tokens = max_tokens;
|
|
124
|
+
if (temperature !== undefined)
|
|
125
|
+
chatRequest.temperature = temperature;
|
|
126
|
+
if (top_p !== undefined)
|
|
127
|
+
chatRequest.top_p = top_p;
|
|
128
|
+
if (top_k !== undefined)
|
|
129
|
+
chatRequest.top_k = top_k;
|
|
130
|
+
if (presence_penalty !== undefined)
|
|
131
|
+
chatRequest.presence_penalty = presence_penalty;
|
|
132
|
+
if (frequency_penalty !== undefined)
|
|
133
|
+
chatRequest.frequency_penalty = frequency_penalty;
|
|
134
|
+
if (search_domain !== undefined)
|
|
135
|
+
chatRequest.search_domain = search_domain;
|
|
136
|
+
if (return_citations !== undefined)
|
|
137
|
+
chatRequest.return_citations = return_citations;
|
|
138
|
+
if (return_images !== undefined)
|
|
139
|
+
chatRequest.return_images = return_images;
|
|
140
|
+
if (return_related_questions !== undefined)
|
|
141
|
+
chatRequest.return_related_questions = return_related_questions;
|
|
142
|
+
const response = await fetch(`https://api.perplexity.ai/chat/completions`, {
|
|
143
|
+
method: 'POST',
|
|
144
|
+
headers: {
|
|
145
|
+
'Content-Type': 'application/json',
|
|
146
|
+
Authorization: `Bearer ${apiKey}`,
|
|
147
|
+
},
|
|
148
|
+
body: JSON.stringify(chatRequest),
|
|
149
|
+
});
|
|
150
|
+
if (!response.ok) {
|
|
151
|
+
const errorText = await response.text();
|
|
152
|
+
return {
|
|
153
|
+
success: false,
|
|
154
|
+
error: `Perplexity API error: ${response.status} - ${errorText}`,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const result = (await response.json());
|
|
158
|
+
return {
|
|
159
|
+
success: true,
|
|
160
|
+
response: result.choices[0]?.message?.content || '',
|
|
161
|
+
model: result.model,
|
|
162
|
+
usage: result.usage,
|
|
163
|
+
finish_reason: result.choices[0]?.finish_reason,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
return {
|
|
168
|
+
success: false,
|
|
169
|
+
error: `Failed to generate text: ${error.message}`,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* List available models
|
|
175
|
+
*/
|
|
176
|
+
async _tool_list_models(request) {
|
|
177
|
+
try {
|
|
178
|
+
const params = request.params;
|
|
179
|
+
const { apiKey = this.defaultApiKey } = params;
|
|
180
|
+
if (!apiKey) {
|
|
181
|
+
return {
|
|
182
|
+
success: false,
|
|
183
|
+
error: 'Perplexity API key is required',
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
const response = await fetch(`https://api.perplexity.ai/models`, {
|
|
187
|
+
method: 'GET',
|
|
188
|
+
headers: {
|
|
189
|
+
Authorization: `Bearer ${apiKey}`,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
if (!response.ok) {
|
|
193
|
+
const errorText = await response.text();
|
|
194
|
+
return {
|
|
195
|
+
success: false,
|
|
196
|
+
error: `Perplexity API error: ${response.status} - ${errorText}`,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
const result = (await response.json());
|
|
200
|
+
return {
|
|
201
|
+
success: true,
|
|
202
|
+
models: result.data,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
return {
|
|
207
|
+
success: false,
|
|
208
|
+
error: `Failed to list models: ${error.message}`,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Search with Perplexity
|
|
214
|
+
*/
|
|
215
|
+
async _tool_search(request) {
|
|
216
|
+
try {
|
|
217
|
+
const params = request.params;
|
|
218
|
+
const { query, search_domain, include_domains, exclude_domains, use_autoprompt, type, apiKey = this.defaultApiKey, } = params;
|
|
219
|
+
if (!query) {
|
|
220
|
+
return {
|
|
221
|
+
success: false,
|
|
222
|
+
error: 'Query is required',
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
if (!apiKey) {
|
|
226
|
+
return {
|
|
227
|
+
success: false,
|
|
228
|
+
error: 'Perplexity API key is required',
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
const searchRequest = {
|
|
232
|
+
query: query,
|
|
233
|
+
};
|
|
234
|
+
// Add optional parameters if provided
|
|
235
|
+
if (search_domain !== undefined)
|
|
236
|
+
searchRequest.search_domain = search_domain;
|
|
237
|
+
if (include_domains !== undefined)
|
|
238
|
+
searchRequest.include_domains = include_domains;
|
|
239
|
+
if (exclude_domains !== undefined)
|
|
240
|
+
searchRequest.exclude_domains = exclude_domains;
|
|
241
|
+
if (use_autoprompt !== undefined)
|
|
242
|
+
searchRequest.use_autoprompt = use_autoprompt;
|
|
243
|
+
if (type !== undefined)
|
|
244
|
+
searchRequest.type = type;
|
|
245
|
+
const response = await fetch(`https://api.perplexity.ai/search`, {
|
|
246
|
+
method: 'POST',
|
|
247
|
+
headers: {
|
|
248
|
+
'Content-Type': 'application/json',
|
|
249
|
+
Authorization: `Bearer ${apiKey}`,
|
|
250
|
+
},
|
|
251
|
+
body: JSON.stringify(searchRequest),
|
|
252
|
+
});
|
|
253
|
+
if (!response.ok) {
|
|
254
|
+
const errorText = await response.text();
|
|
255
|
+
return {
|
|
256
|
+
success: false,
|
|
257
|
+
error: `Perplexity API error: ${response.status} - ${errorText}`,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
const result = (await response.json());
|
|
261
|
+
return {
|
|
262
|
+
success: true,
|
|
263
|
+
response: result.choices[0]?.message?.content || '',
|
|
264
|
+
model: result.model,
|
|
265
|
+
usage: result.usage,
|
|
266
|
+
finish_reason: result.choices[0]?.finish_reason,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
return {
|
|
271
|
+
success: false,
|
|
272
|
+
error: `Failed to search: ${error.message}`,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Check Perplexity API status
|
|
278
|
+
*/
|
|
279
|
+
async _tool_status(request) {
|
|
280
|
+
try {
|
|
281
|
+
const params = request.params;
|
|
282
|
+
const { apiKey = this.defaultApiKey } = params;
|
|
283
|
+
if (!apiKey) {
|
|
284
|
+
return {
|
|
285
|
+
success: false,
|
|
286
|
+
status: 'error',
|
|
287
|
+
error: 'Perplexity API key is required',
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
const response = await fetch(`https://api.perplexity.ai/models`, {
|
|
291
|
+
method: 'GET',
|
|
292
|
+
headers: {
|
|
293
|
+
Authorization: `Bearer ${apiKey}`,
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
return {
|
|
297
|
+
success: response.ok,
|
|
298
|
+
status: response.ok ? 'online' : 'offline',
|
|
299
|
+
status_code: response.status,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
return {
|
|
304
|
+
success: false,
|
|
305
|
+
status: 'offline',
|
|
306
|
+
error: `Connection failed: ${error.message}`,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { oToolConfig, oVirtualTool, ToolResult } from '@olane/o-tool';
|
|
2
|
+
import { oRequest } from '@olane/o-core';
|
|
3
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
|
+
import { McpTool } from './mcp.tool.js';
|
|
5
|
+
export declare class McpBridgeTool extends oVirtualTool {
|
|
6
|
+
constructor(config: oToolConfig);
|
|
7
|
+
_tool_validate_url(request: oRequest): Promise<ToolResult>;
|
|
8
|
+
_tool_add_remote_server(request: oRequest): Promise<ToolResult>;
|
|
9
|
+
_tool_add_local_server(request: oRequest): Promise<ToolResult>;
|
|
10
|
+
createMcpTool(mcpClient: Client, url: string, name?: string): Promise<McpTool>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=mcp-bridge.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-bridge.tool.d.ts","sourceRoot":"","sources":["../../../src/mcp/mcp-bridge.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAY,QAAQ,EAAc,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAEnE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAIxC,qBAAa,aAAc,SAAQ,YAAY;gBACjC,MAAM,EAAE,WAAW;IASzB,kBAAkB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IA2B1D,uBAAuB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAiC/D,sBAAsB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IA+B9D,aAAa,CACjB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,OAAO,CAAC;CAuBpB"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { oVirtualTool } from '@olane/o-tool';
|
|
2
|
+
import { oAddress, oToolError } from '@olane/o-core';
|
|
3
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
|
+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
5
|
+
import { McpTool } from './mcp.tool.js';
|
|
6
|
+
import { MCP_BRIDGE_METHODS } from './methods/mcp-bridge.methods.js';
|
|
7
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
8
|
+
export class McpBridgeTool extends oVirtualTool {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super({
|
|
11
|
+
...config,
|
|
12
|
+
address: new oAddress('o://mcp'),
|
|
13
|
+
description: 'Tool to help add MCP servers to the network',
|
|
14
|
+
methods: MCP_BRIDGE_METHODS,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
async _tool_validate_url(request) {
|
|
18
|
+
const params = request.params;
|
|
19
|
+
const { mcpServerUrl } = params;
|
|
20
|
+
// check the URL contents to see if it is a valid MCP server or a link describing one
|
|
21
|
+
const response = await this.use(new oAddress('o://perplexity'), {
|
|
22
|
+
method: 'completion',
|
|
23
|
+
params: {
|
|
24
|
+
model: 'sonar',
|
|
25
|
+
messages: [
|
|
26
|
+
{
|
|
27
|
+
role: 'user',
|
|
28
|
+
content: `Is this url an MCP server: ${mcpServerUrl}? Be concise in your answer.`,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
if (response.result.error) {
|
|
34
|
+
throw new oToolError(response.result.error.code, response.result.error.message);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
result: response.result.data.message,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async _tool_add_remote_server(request) {
|
|
41
|
+
const params = request.params;
|
|
42
|
+
// params have already been validated
|
|
43
|
+
const { mcpServerUrl } = params;
|
|
44
|
+
try {
|
|
45
|
+
this.logger.debug('Adding MCP server: ' + mcpServerUrl);
|
|
46
|
+
const transport = new StreamableHTTPClientTransport(new URL(mcpServerUrl));
|
|
47
|
+
const mcpClient = new Client({
|
|
48
|
+
name: 'o-node:mcp:' + this.peerId.toString(),
|
|
49
|
+
version: '1.0.0',
|
|
50
|
+
});
|
|
51
|
+
await mcpClient.connect(transport);
|
|
52
|
+
await this.createMcpTool(mcpClient, mcpServerUrl);
|
|
53
|
+
return {
|
|
54
|
+
message: 'Successfully added MCP server with ' +
|
|
55
|
+
this.childNodes.length +
|
|
56
|
+
' tools',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
throw new Error('Error when trying to add MCP server (' +
|
|
61
|
+
mcpServerUrl +
|
|
62
|
+
') to the network: ' +
|
|
63
|
+
e?.message);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async _tool_add_local_server(request) {
|
|
67
|
+
const params = request.params;
|
|
68
|
+
this.logger.debug('Adding local MCP server: ', params);
|
|
69
|
+
// params have already been validated
|
|
70
|
+
const { command, args, name } = params;
|
|
71
|
+
// this.logger.debug('Adding local MCP server: ' + mcpServerUrl);
|
|
72
|
+
const transport = new StdioClientTransport({
|
|
73
|
+
command: command,
|
|
74
|
+
args: args,
|
|
75
|
+
});
|
|
76
|
+
const mcpClient = new Client({
|
|
77
|
+
name: 'o-node:mcp:' + this.peerId.toString(),
|
|
78
|
+
version: '1.0.0',
|
|
79
|
+
});
|
|
80
|
+
await mcpClient.connect(transport);
|
|
81
|
+
await this.createMcpTool(mcpClient, args.join(' '), name);
|
|
82
|
+
return {
|
|
83
|
+
_save: true,
|
|
84
|
+
message: 'Successfully added local MCP server',
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
async createMcpTool(mcpClient, url, name) {
|
|
88
|
+
this.logger.debug('Creating MCP tool: ', name, url);
|
|
89
|
+
const mcpTool = new McpTool({
|
|
90
|
+
name: name || 'mcp-' + Date.now(),
|
|
91
|
+
description: 'MCP server for ' + url,
|
|
92
|
+
address: new oAddress(`o://${name || `mcp-${Date.now()}`}`),
|
|
93
|
+
mcpClient: mcpClient,
|
|
94
|
+
dependencies: [],
|
|
95
|
+
leader: this.config.leader,
|
|
96
|
+
parent: this.address,
|
|
97
|
+
});
|
|
98
|
+
this.addChildNode(mcpTool);
|
|
99
|
+
await this.startChildren();
|
|
100
|
+
await mcpTool.setupTools();
|
|
101
|
+
await this.use(new oAddress(mcpTool.address.toString()), {
|
|
102
|
+
method: 'index_network',
|
|
103
|
+
params: {},
|
|
104
|
+
});
|
|
105
|
+
return mcpTool;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { oToolConfig, oVirtualTool } from '@olane/o-tool';
|
|
2
|
+
import { oAddress } from '@olane/o-core';
|
|
3
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
|
+
export declare class McpTool extends oVirtualTool {
|
|
5
|
+
private mcpClient;
|
|
6
|
+
constructor(config: oToolConfig & {
|
|
7
|
+
address: oAddress;
|
|
8
|
+
mcpClient: Client;
|
|
9
|
+
});
|
|
10
|
+
setupTools(): Promise<void>;
|
|
11
|
+
myTools(): Promise<string[]>;
|
|
12
|
+
index(): Promise<any>;
|
|
13
|
+
whoami(): Promise<any>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=mcp.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.tool.d.ts","sourceRoot":"","sources":["../../../src/mcp/mcp.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAY,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGnE,qBAAa,OAAQ,SAAQ,YAAY;IACvC,OAAO,CAAC,SAAS,CAAS;gBAEd,MAAM,EAAE,WAAW,GAAG;QAAE,OAAO,EAAE,QAAQ,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IAYpE,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA0B3B,OAAO;IAQP,KAAK;IA2BL,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC;CAmB7B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { oVirtualTool } from '@olane/o-tool';
|
|
2
|
+
import { oAddress } from '@olane/o-core';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
export class McpTool extends oVirtualTool {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
super({
|
|
7
|
+
...config,
|
|
8
|
+
address: config.address,
|
|
9
|
+
description: config.description ||
|
|
10
|
+
'Tool for wrapping MCP servers to be used as tools in the network',
|
|
11
|
+
});
|
|
12
|
+
this.mcpClient = config.mcpClient;
|
|
13
|
+
}
|
|
14
|
+
// _tool_ functions are dynamically added to the tool based on the MCP server's methods
|
|
15
|
+
async setupTools() {
|
|
16
|
+
this.logger.debug('Setting up MCP tools');
|
|
17
|
+
const tools = await this.mcpClient.listTools();
|
|
18
|
+
this.logger.debug('MCP tools: ', tools);
|
|
19
|
+
tools.tools.forEach((tool) => {
|
|
20
|
+
this.logger.debug('Setting up MCP server tool: ' + tool.name);
|
|
21
|
+
this.methods[tool.name] = {
|
|
22
|
+
name: tool.name,
|
|
23
|
+
description: tool.description || '',
|
|
24
|
+
parameters: tool.inputSchema.properties,
|
|
25
|
+
dependencies: [],
|
|
26
|
+
};
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
this[`_tool_${tool.name}`] = async (request) => {
|
|
29
|
+
this.logger.debug('Calling MCP tool: ' + tool.name, request);
|
|
30
|
+
const params = request.params;
|
|
31
|
+
const result = await this.mcpClient.callTool({
|
|
32
|
+
name: tool.name,
|
|
33
|
+
arguments: params,
|
|
34
|
+
});
|
|
35
|
+
return result.content;
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
await this.startChildren();
|
|
39
|
+
}
|
|
40
|
+
async myTools() {
|
|
41
|
+
const tools = await this.mcpClient.listTools();
|
|
42
|
+
return tools.tools.map((tool) => {
|
|
43
|
+
return tool.name;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
// let's customize the index functionality to ensure we capture MCP insights
|
|
47
|
+
async index() {
|
|
48
|
+
const result = await super.index();
|
|
49
|
+
// add each mcp tool to the vector store
|
|
50
|
+
const tools = await this.mcpClient.listTools();
|
|
51
|
+
await Promise.all(tools.tools.map((tool) => {
|
|
52
|
+
return this.use(new oAddress('o://vector-store'), {
|
|
53
|
+
method: 'add_documents',
|
|
54
|
+
params: {
|
|
55
|
+
documents: [
|
|
56
|
+
{
|
|
57
|
+
pageContent: tool.description,
|
|
58
|
+
metadata: {
|
|
59
|
+
address: this.address?.toString() + '/' + tool.name,
|
|
60
|
+
id: uuidv4(),
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
})).catch((err) => {
|
|
67
|
+
this.logger.error('Error adding MCP tools to vector store: ', err);
|
|
68
|
+
});
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
async whoami() {
|
|
72
|
+
// do nothing
|
|
73
|
+
const tools = await this.mcpClient.listTools();
|
|
74
|
+
return {
|
|
75
|
+
tools: tools.tools.map((tool) => {
|
|
76
|
+
this.logger.debug('MCP Tool Definition: ', tool.name, tool.description, tool.inputSchema);
|
|
77
|
+
return {
|
|
78
|
+
name: tool.name,
|
|
79
|
+
description: tool.description,
|
|
80
|
+
inputSchema: tool.inputSchema.properties,
|
|
81
|
+
};
|
|
82
|
+
}),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-bridge.methods.d.ts","sourceRoot":"","sources":["../../../../src/mcp/methods/mcp-bridge.methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,eAAO,MAAM,kBAAkB,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CA2DxD,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const MCP_BRIDGE_METHODS = {
|
|
2
|
+
validate_url: {
|
|
3
|
+
name: 'validate_url',
|
|
4
|
+
description: 'Validate if a URL is a valid MCP server or a link to something else.',
|
|
5
|
+
dependencies: [],
|
|
6
|
+
parameters: [
|
|
7
|
+
{
|
|
8
|
+
name: 'mcpServerUrl',
|
|
9
|
+
type: 'string',
|
|
10
|
+
value: 'string',
|
|
11
|
+
description: 'The URL of the MCP server to validate',
|
|
12
|
+
required: true,
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
add_remote_server: {
|
|
17
|
+
name: 'add_remote_server',
|
|
18
|
+
description: 'Add a MCP server that is hosted on a remote server',
|
|
19
|
+
dependencies: [],
|
|
20
|
+
parameters: [
|
|
21
|
+
{
|
|
22
|
+
name: 'mcpServerUrl',
|
|
23
|
+
type: 'string',
|
|
24
|
+
value: 'string',
|
|
25
|
+
description: 'The URL of the MCP server to use',
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
add_local_server: {
|
|
31
|
+
name: 'add_local_server',
|
|
32
|
+
description: 'Add a local MCP server to the bridge using command and arguments',
|
|
33
|
+
dependencies: [],
|
|
34
|
+
parameters: [
|
|
35
|
+
{
|
|
36
|
+
name: 'command',
|
|
37
|
+
type: 'string',
|
|
38
|
+
value: 'string',
|
|
39
|
+
description: 'The command to execute for the local MCP server',
|
|
40
|
+
required: true,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'args',
|
|
44
|
+
type: 'array',
|
|
45
|
+
value: 'string[]',
|
|
46
|
+
description: 'The arguments to pass to the command',
|
|
47
|
+
required: true,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'name',
|
|
51
|
+
type: 'string',
|
|
52
|
+
value: 'string',
|
|
53
|
+
description: 'The name for the MCP server',
|
|
54
|
+
required: true,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vector-store/index.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC;AACxD,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { oRequest } from '@olane/o-core';
|
|
2
|
+
import { oToolConfig } from '@olane/o-tool';
|
|
3
|
+
import { VectorMemoryStorageTool } from './vector-memory.tool.js';
|
|
4
|
+
export declare class LangchainMemoryVectorStoreTool extends VectorMemoryStorageTool {
|
|
5
|
+
private vectorStore;
|
|
6
|
+
constructor(config: oToolConfig);
|
|
7
|
+
private embeddingsTool;
|
|
8
|
+
initialize(): Promise<void>;
|
|
9
|
+
_tool_add_documents(request: oRequest): Promise<any>;
|
|
10
|
+
_tool_delete_documents(request: oRequest): Promise<any>;
|
|
11
|
+
_tool_update_documents(request: oRequest): Promise<any>;
|
|
12
|
+
_tool_search_similar(request: oRequest): Promise<any>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=langchain-memory.vector-store.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langchain-memory.vector-store.tool.d.ts","sourceRoot":"","sources":["../../src/vector-store/langchain-memory.vector-store.tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAKlE,qBAAa,8BAA+B,SAAQ,uBAAuB;IACzE,OAAO,CAAC,WAAW,CAAqB;gBAE5B,MAAM,EAAE,WAAW;IAO/B,OAAO,CAAC,cAAc;IAwBhB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B,mBAAmB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAOpD,sBAAsB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAIvD,sBAAsB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAIvD,oBAAoB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;CAQ5D"}
|