@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,309 @@
|
|
|
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
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Chat completion with Perplexity
|
|
16
|
+
*/
|
|
17
|
+
async _tool_completion(request) {
|
|
18
|
+
try {
|
|
19
|
+
const params = request.params;
|
|
20
|
+
const { model = this.defaultModel, messages, max_tokens, temperature, top_p, top_k, presence_penalty, frequency_penalty, apiKey, search_domain, return_citations, return_images, return_related_questions, } = params;
|
|
21
|
+
if (!messages || !Array.isArray(messages)) {
|
|
22
|
+
return {
|
|
23
|
+
success: false,
|
|
24
|
+
error: '"messages" array is required',
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (!apiKey) {
|
|
28
|
+
return {
|
|
29
|
+
success: false,
|
|
30
|
+
error: 'Perplexity API key is required',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const chatRequest = {
|
|
34
|
+
model: model,
|
|
35
|
+
messages: messages,
|
|
36
|
+
stream: false,
|
|
37
|
+
};
|
|
38
|
+
// Add optional parameters if provided
|
|
39
|
+
if (max_tokens !== undefined)
|
|
40
|
+
chatRequest.max_tokens = max_tokens;
|
|
41
|
+
if (temperature !== undefined)
|
|
42
|
+
chatRequest.temperature = temperature;
|
|
43
|
+
if (top_p !== undefined)
|
|
44
|
+
chatRequest.top_p = top_p;
|
|
45
|
+
if (top_k !== undefined)
|
|
46
|
+
chatRequest.top_k = top_k;
|
|
47
|
+
if (presence_penalty !== undefined)
|
|
48
|
+
chatRequest.presence_penalty = presence_penalty;
|
|
49
|
+
if (frequency_penalty !== undefined)
|
|
50
|
+
chatRequest.frequency_penalty = frequency_penalty;
|
|
51
|
+
if (search_domain !== undefined)
|
|
52
|
+
chatRequest.search_domain = search_domain;
|
|
53
|
+
if (return_citations !== undefined)
|
|
54
|
+
chatRequest.return_citations = return_citations;
|
|
55
|
+
if (return_images !== undefined)
|
|
56
|
+
chatRequest.return_images = return_images;
|
|
57
|
+
if (return_related_questions !== undefined)
|
|
58
|
+
chatRequest.return_related_questions = return_related_questions;
|
|
59
|
+
const response = await fetch(`https://api.perplexity.ai/chat/completions`, {
|
|
60
|
+
method: 'POST',
|
|
61
|
+
headers: {
|
|
62
|
+
'Content-Type': 'application/json',
|
|
63
|
+
Authorization: `Bearer ${apiKey}`,
|
|
64
|
+
},
|
|
65
|
+
body: JSON.stringify(chatRequest),
|
|
66
|
+
});
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
const errorText = await response.text();
|
|
69
|
+
return {
|
|
70
|
+
success: false,
|
|
71
|
+
error: `Perplexity API error: ${response.status} - ${errorText}`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const result = (await response.json());
|
|
75
|
+
return {
|
|
76
|
+
success: true,
|
|
77
|
+
response: result.choices[0]?.message?.content || '',
|
|
78
|
+
model: result.model,
|
|
79
|
+
usage: result.usage,
|
|
80
|
+
finish_reason: result.choices[0]?.finish_reason,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
return {
|
|
85
|
+
success: false,
|
|
86
|
+
error: `Failed to complete chat: ${error.message}`,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Generate text with Perplexity (alias for completion)
|
|
92
|
+
*/
|
|
93
|
+
async _tool_generate(request) {
|
|
94
|
+
try {
|
|
95
|
+
const params = request.params;
|
|
96
|
+
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, } = params;
|
|
97
|
+
if (!prompt) {
|
|
98
|
+
return {
|
|
99
|
+
success: false,
|
|
100
|
+
error: 'Prompt is required',
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (!apiKey) {
|
|
104
|
+
return {
|
|
105
|
+
success: false,
|
|
106
|
+
error: 'Perplexity API key is required',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
// Convert prompt to messages format
|
|
110
|
+
const messages = [];
|
|
111
|
+
if (system) {
|
|
112
|
+
messages.push({ role: 'system', content: system });
|
|
113
|
+
}
|
|
114
|
+
messages.push({ role: 'user', content: prompt });
|
|
115
|
+
const chatRequest = {
|
|
116
|
+
model: model,
|
|
117
|
+
messages,
|
|
118
|
+
stream: false,
|
|
119
|
+
};
|
|
120
|
+
// Add optional parameters if provided
|
|
121
|
+
if (max_tokens !== undefined)
|
|
122
|
+
chatRequest.max_tokens = max_tokens;
|
|
123
|
+
if (temperature !== undefined)
|
|
124
|
+
chatRequest.temperature = temperature;
|
|
125
|
+
if (top_p !== undefined)
|
|
126
|
+
chatRequest.top_p = top_p;
|
|
127
|
+
if (top_k !== undefined)
|
|
128
|
+
chatRequest.top_k = top_k;
|
|
129
|
+
if (presence_penalty !== undefined)
|
|
130
|
+
chatRequest.presence_penalty = presence_penalty;
|
|
131
|
+
if (frequency_penalty !== undefined)
|
|
132
|
+
chatRequest.frequency_penalty = frequency_penalty;
|
|
133
|
+
if (search_domain !== undefined)
|
|
134
|
+
chatRequest.search_domain = search_domain;
|
|
135
|
+
if (return_citations !== undefined)
|
|
136
|
+
chatRequest.return_citations = return_citations;
|
|
137
|
+
if (return_images !== undefined)
|
|
138
|
+
chatRequest.return_images = return_images;
|
|
139
|
+
if (return_related_questions !== undefined)
|
|
140
|
+
chatRequest.return_related_questions = return_related_questions;
|
|
141
|
+
const response = await fetch(`https://api.perplexity.ai/chat/completions`, {
|
|
142
|
+
method: 'POST',
|
|
143
|
+
headers: {
|
|
144
|
+
'Content-Type': 'application/json',
|
|
145
|
+
Authorization: `Bearer ${apiKey}`,
|
|
146
|
+
},
|
|
147
|
+
body: JSON.stringify(chatRequest),
|
|
148
|
+
});
|
|
149
|
+
if (!response.ok) {
|
|
150
|
+
const errorText = await response.text();
|
|
151
|
+
return {
|
|
152
|
+
success: false,
|
|
153
|
+
error: `Perplexity API error: ${response.status} - ${errorText}`,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const result = (await response.json());
|
|
157
|
+
return {
|
|
158
|
+
success: true,
|
|
159
|
+
response: result.choices[0]?.message?.content || '',
|
|
160
|
+
model: result.model,
|
|
161
|
+
usage: result.usage,
|
|
162
|
+
finish_reason: result.choices[0]?.finish_reason,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
return {
|
|
167
|
+
success: false,
|
|
168
|
+
error: `Failed to generate text: ${error.message}`,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* List available models
|
|
174
|
+
*/
|
|
175
|
+
async _tool_list_models(request) {
|
|
176
|
+
try {
|
|
177
|
+
const params = request.params;
|
|
178
|
+
const { apiKey } = params;
|
|
179
|
+
if (!apiKey) {
|
|
180
|
+
return {
|
|
181
|
+
success: false,
|
|
182
|
+
error: 'Perplexity API key is required',
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const response = await fetch(`https://api.perplexity.ai/models`, {
|
|
186
|
+
method: 'GET',
|
|
187
|
+
headers: {
|
|
188
|
+
Authorization: `Bearer ${apiKey}`,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
if (!response.ok) {
|
|
192
|
+
const errorText = await response.text();
|
|
193
|
+
return {
|
|
194
|
+
success: false,
|
|
195
|
+
error: `Perplexity API error: ${response.status} - ${errorText}`,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const result = (await response.json());
|
|
199
|
+
return {
|
|
200
|
+
success: true,
|
|
201
|
+
models: result.data,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
return {
|
|
206
|
+
success: false,
|
|
207
|
+
error: `Failed to list models: ${error.message}`,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Search with Perplexity
|
|
213
|
+
*/
|
|
214
|
+
async _tool_search(request) {
|
|
215
|
+
try {
|
|
216
|
+
const params = request.params;
|
|
217
|
+
const { query, search_domain, include_domains, exclude_domains, use_autoprompt, type, apiKey, } = params;
|
|
218
|
+
if (!query) {
|
|
219
|
+
return {
|
|
220
|
+
success: false,
|
|
221
|
+
error: 'Query is required',
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
if (!apiKey) {
|
|
225
|
+
return {
|
|
226
|
+
success: false,
|
|
227
|
+
error: 'Perplexity API key is required',
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
const searchRequest = {
|
|
231
|
+
query: query,
|
|
232
|
+
};
|
|
233
|
+
// Add optional parameters if provided
|
|
234
|
+
if (search_domain !== undefined)
|
|
235
|
+
searchRequest.search_domain = search_domain;
|
|
236
|
+
if (include_domains !== undefined)
|
|
237
|
+
searchRequest.include_domains = include_domains;
|
|
238
|
+
if (exclude_domains !== undefined)
|
|
239
|
+
searchRequest.exclude_domains = exclude_domains;
|
|
240
|
+
if (use_autoprompt !== undefined)
|
|
241
|
+
searchRequest.use_autoprompt = use_autoprompt;
|
|
242
|
+
if (type !== undefined)
|
|
243
|
+
searchRequest.type = type;
|
|
244
|
+
const response = await fetch(`https://api.perplexity.ai/search`, {
|
|
245
|
+
method: 'POST',
|
|
246
|
+
headers: {
|
|
247
|
+
'Content-Type': 'application/json',
|
|
248
|
+
Authorization: `Bearer ${apiKey}`,
|
|
249
|
+
},
|
|
250
|
+
body: JSON.stringify(searchRequest),
|
|
251
|
+
});
|
|
252
|
+
if (!response.ok) {
|
|
253
|
+
const errorText = await response.text();
|
|
254
|
+
return {
|
|
255
|
+
success: false,
|
|
256
|
+
error: `Perplexity API error: ${response.status} - ${errorText}`,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
const result = (await response.json());
|
|
260
|
+
return {
|
|
261
|
+
success: true,
|
|
262
|
+
response: result.choices[0]?.message?.content || '',
|
|
263
|
+
model: result.model,
|
|
264
|
+
usage: result.usage,
|
|
265
|
+
finish_reason: result.choices[0]?.finish_reason,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
return {
|
|
270
|
+
success: false,
|
|
271
|
+
error: `Failed to search: ${error.message}`,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Check Perplexity API status
|
|
277
|
+
*/
|
|
278
|
+
async _tool_status(request) {
|
|
279
|
+
try {
|
|
280
|
+
const params = request.params;
|
|
281
|
+
const { apiKey } = params;
|
|
282
|
+
if (!apiKey) {
|
|
283
|
+
return {
|
|
284
|
+
success: false,
|
|
285
|
+
status: 'error',
|
|
286
|
+
error: 'Perplexity API key is required',
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
const response = await fetch(`https://api.perplexity.ai/models`, {
|
|
290
|
+
method: 'GET',
|
|
291
|
+
headers: {
|
|
292
|
+
Authorization: `Bearer ${apiKey}`,
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
return {
|
|
296
|
+
success: response.ok,
|
|
297
|
+
status: response.ok ? 'online' : 'offline',
|
|
298
|
+
status_code: response.status,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
return {
|
|
303
|
+
success: false,
|
|
304
|
+
status: 'offline',
|
|
305
|
+
error: `Connection failed: ${error.message}`,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
@@ -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_add_remote_server(request: oRequest): Promise<ToolResult>;
|
|
8
|
+
_tool_add_remote_server_with_api_key(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,EAAE,MAAM,eAAe,CAAC;AACnD,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,uBAAuB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAiC/D,oCAAoC,CACxC,OAAO,EAAE,QAAQ,GAChB,OAAO,CAAC,UAAU,CAAC;IAmDhB,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;CAsBpB"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { oVirtualTool } from '@olane/o-tool';
|
|
2
|
+
import { oAddress } 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_add_remote_server(request) {
|
|
18
|
+
const params = request.params;
|
|
19
|
+
// params have already been validated
|
|
20
|
+
const { mcpServerUrl } = params;
|
|
21
|
+
try {
|
|
22
|
+
this.logger.debug('Adding MCP server: ' + mcpServerUrl);
|
|
23
|
+
const transport = new StreamableHTTPClientTransport(new URL(mcpServerUrl));
|
|
24
|
+
const mcpClient = new Client({
|
|
25
|
+
name: 'o-node:mcp:' + this.peerId.toString(),
|
|
26
|
+
version: '1.0.0',
|
|
27
|
+
});
|
|
28
|
+
await mcpClient.connect(transport);
|
|
29
|
+
await this.createMcpTool(mcpClient, mcpServerUrl);
|
|
30
|
+
return {
|
|
31
|
+
message: 'Successfully added MCP server with ' +
|
|
32
|
+
this.childNodes.length +
|
|
33
|
+
' tools',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
throw new Error('Error when trying to add MCP server (' +
|
|
38
|
+
mcpServerUrl +
|
|
39
|
+
') to the network: ' +
|
|
40
|
+
e?.message);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async _tool_add_remote_server_with_api_key(request) {
|
|
44
|
+
const params = request.params;
|
|
45
|
+
// params have already been validated
|
|
46
|
+
const { mcpServerUrl, apiKey } = params;
|
|
47
|
+
try {
|
|
48
|
+
// let apiKey = apiKeyInput as string;
|
|
49
|
+
// if (apiKey.indexOf('o://') > -1) {
|
|
50
|
+
// const {
|
|
51
|
+
// result: { data },
|
|
52
|
+
// }: any = await this.use(new oAddress('o://vault'), {
|
|
53
|
+
// method: 'get',
|
|
54
|
+
// params: { key: apiKeyInput },
|
|
55
|
+
// });
|
|
56
|
+
// apiKey = data.value;
|
|
57
|
+
// }
|
|
58
|
+
this.logger.debug('Adding API keyed MCP server: ' + mcpServerUrl, apiKey);
|
|
59
|
+
const transport = new StreamableHTTPClientTransport(new URL(mcpServerUrl), {
|
|
60
|
+
requestInit: {
|
|
61
|
+
headers: {
|
|
62
|
+
Authorization: `Bearer ${apiKey}`,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const mcpClient = new Client({
|
|
67
|
+
name: 'o-node:mcp:' + this.peerId.toString(),
|
|
68
|
+
version: '1.0.0',
|
|
69
|
+
});
|
|
70
|
+
await mcpClient.connect(transport);
|
|
71
|
+
await this.createMcpTool(mcpClient, mcpServerUrl);
|
|
72
|
+
return {
|
|
73
|
+
_save: true,
|
|
74
|
+
message: 'Successfully added MCP server with ' +
|
|
75
|
+
this.childNodes.length +
|
|
76
|
+
' tools',
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
throw new Error('Error when trying to add MCP server (' +
|
|
81
|
+
mcpServerUrl +
|
|
82
|
+
') to the network: ' +
|
|
83
|
+
e?.message);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async _tool_add_local_server(request) {
|
|
87
|
+
const params = request.params;
|
|
88
|
+
this.logger.debug('Adding local MCP server: ', params);
|
|
89
|
+
// params have already been validated
|
|
90
|
+
const { command, args, name } = params;
|
|
91
|
+
// this.logger.debug('Adding local MCP server: ' + mcpServerUrl);
|
|
92
|
+
const transport = new StdioClientTransport({
|
|
93
|
+
command: command,
|
|
94
|
+
args: args,
|
|
95
|
+
});
|
|
96
|
+
const mcpClient = new Client({
|
|
97
|
+
name: 'o-node:mcp:' + this.peerId.toString(),
|
|
98
|
+
version: '1.0.0',
|
|
99
|
+
});
|
|
100
|
+
await mcpClient.connect(transport);
|
|
101
|
+
await this.createMcpTool(mcpClient, args.join(' '), name);
|
|
102
|
+
return {
|
|
103
|
+
_save: true,
|
|
104
|
+
message: 'Successfully added local MCP server',
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async createMcpTool(mcpClient, url, name) {
|
|
108
|
+
this.logger.debug('Creating MCP tool: ', name, url);
|
|
109
|
+
const mcpTool = new McpTool({
|
|
110
|
+
name: name || 'mcp-' + Date.now(),
|
|
111
|
+
description: 'MCP server for ' + url,
|
|
112
|
+
address: new oAddress(`o://${name || `mcp-${Date.now()}`}`),
|
|
113
|
+
mcpClient: mcpClient,
|
|
114
|
+
dependencies: [],
|
|
115
|
+
leader: this.config.leader,
|
|
116
|
+
parent: this.address,
|
|
117
|
+
});
|
|
118
|
+
this.addChildNode(mcpTool);
|
|
119
|
+
await this.startChildren();
|
|
120
|
+
await this.use(mcpTool.address, {
|
|
121
|
+
method: 'index_network',
|
|
122
|
+
params: {},
|
|
123
|
+
});
|
|
124
|
+
return mcpTool;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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(mcpClient: Client): Promise<void>;
|
|
11
|
+
index(): Promise<any>;
|
|
12
|
+
whoami(): Promise<any>;
|
|
13
|
+
}
|
|
14
|
+
//# 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;IAepE,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA2B5C,KAAK;IA2BL,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC;CAe7B"}
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
this.setupTools(this.mcpClient).catch((err) => {
|
|
14
|
+
this.logger.error('Error setting up MCP tools: ', err);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
// _tool_ functions are dynamically added to the tool based on the MCP server's methods
|
|
18
|
+
async setupTools(mcpClient) {
|
|
19
|
+
this.logger.debug('Setting up MCP tools');
|
|
20
|
+
const tools = await mcpClient.listTools();
|
|
21
|
+
this.logger.debug('MCP tools: ', tools);
|
|
22
|
+
tools.tools.forEach((tool) => {
|
|
23
|
+
this.logger.debug('Setting up MCP server tool: ' + tool.name);
|
|
24
|
+
this.methods[tool.name] = {
|
|
25
|
+
name: tool.name,
|
|
26
|
+
description: tool.description || '',
|
|
27
|
+
parameters: tool.inputSchema,
|
|
28
|
+
dependencies: [],
|
|
29
|
+
};
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
this[`_tool_${tool.name}`] = async (request) => {
|
|
32
|
+
this.logger.debug('Calling MCP tool: ' + tool.name, request);
|
|
33
|
+
const params = request.params;
|
|
34
|
+
const result = await this.mcpClient.callTool({
|
|
35
|
+
name: tool.name,
|
|
36
|
+
arguments: params,
|
|
37
|
+
});
|
|
38
|
+
return result.content;
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
await this.startChildren();
|
|
42
|
+
}
|
|
43
|
+
// let's customize the index functionality to ensure we capture MCP insights
|
|
44
|
+
async index() {
|
|
45
|
+
const result = await super.index();
|
|
46
|
+
// add each mcp tool to the vector store
|
|
47
|
+
const tools = await this.mcpClient.listTools();
|
|
48
|
+
await Promise.all(tools.tools.map((tool) => {
|
|
49
|
+
return this.use(new oAddress('o://vector-store'), {
|
|
50
|
+
method: 'add_documents',
|
|
51
|
+
params: {
|
|
52
|
+
documents: [
|
|
53
|
+
{
|
|
54
|
+
pageContent: tool.description,
|
|
55
|
+
metadata: {
|
|
56
|
+
address: this.address?.toString() + '/' + tool.name,
|
|
57
|
+
id: uuidv4(),
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
})).catch((err) => {
|
|
64
|
+
this.logger.error('Error adding MCP tools to vector store: ', err);
|
|
65
|
+
});
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
async whoami() {
|
|
69
|
+
// do nothing
|
|
70
|
+
const tools = await this.mcpClient.listTools();
|
|
71
|
+
console.log('mcp+tools: ', tools);
|
|
72
|
+
return {
|
|
73
|
+
tools: tools.tools.map((tool) => {
|
|
74
|
+
return {
|
|
75
|
+
name: tool.name,
|
|
76
|
+
description: tool.description,
|
|
77
|
+
title: tool.title,
|
|
78
|
+
inputSchema: tool.inputSchema,
|
|
79
|
+
};
|
|
80
|
+
}),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -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;CAiFxD,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export const MCP_BRIDGE_METHODS = {
|
|
2
|
+
add_remote_server_with_api_key: {
|
|
3
|
+
name: 'add_remote_server_with_api_key',
|
|
4
|
+
description: 'Add a MCP server that requires an API key to the bridge',
|
|
5
|
+
dependencies: [],
|
|
6
|
+
parameters: [
|
|
7
|
+
{
|
|
8
|
+
name: 'mcpServerUrl',
|
|
9
|
+
type: 'string',
|
|
10
|
+
value: 'string',
|
|
11
|
+
description: 'The URL of the MCP server to use',
|
|
12
|
+
required: true,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'apiKey',
|
|
16
|
+
type: 'string',
|
|
17
|
+
value: 'string',
|
|
18
|
+
description: 'The API key to use for the MCP server',
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
add_remote_server_with_oauth: {
|
|
24
|
+
name: 'add_remote_server_with_oauth',
|
|
25
|
+
description: 'Add a MCP server that requires an OAuth authentication token to the bridge',
|
|
26
|
+
dependencies: [],
|
|
27
|
+
parameters: [
|
|
28
|
+
{
|
|
29
|
+
name: 'mcpServerUrl',
|
|
30
|
+
type: 'string',
|
|
31
|
+
value: 'string',
|
|
32
|
+
description: 'The URL of the MCP server to use',
|
|
33
|
+
required: true,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
add_remote_server: {
|
|
38
|
+
name: 'add_remote_server',
|
|
39
|
+
description: 'Add a MCP server that does not require authentication to the bridge',
|
|
40
|
+
dependencies: [],
|
|
41
|
+
parameters: [
|
|
42
|
+
{
|
|
43
|
+
name: 'mcpServerUrl',
|
|
44
|
+
type: 'string',
|
|
45
|
+
value: 'string',
|
|
46
|
+
description: 'The URL of the MCP server to use',
|
|
47
|
+
required: true,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
add_local_server: {
|
|
52
|
+
name: 'add_local_server',
|
|
53
|
+
description: 'Add a local MCP server to the bridge using command and arguments',
|
|
54
|
+
dependencies: [],
|
|
55
|
+
parameters: [
|
|
56
|
+
{
|
|
57
|
+
name: 'command',
|
|
58
|
+
type: 'string',
|
|
59
|
+
value: 'string',
|
|
60
|
+
description: 'The command to execute for the local MCP server',
|
|
61
|
+
required: true,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'args',
|
|
65
|
+
type: 'array',
|
|
66
|
+
value: 'string[]',
|
|
67
|
+
description: 'The arguments to pass to the command',
|
|
68
|
+
required: true,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'name',
|
|
72
|
+
type: 'string',
|
|
73
|
+
value: 'string',
|
|
74
|
+
description: 'The name for the MCP server',
|
|
75
|
+
required: true,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nlp/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ner.tool.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nlp.methods.d.ts","sourceRoot":"","sources":["../../../src/nlp/methods/nlp.methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,eAAO,MAAM,UAAU,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAchD,CAAC"}
|