@olane/o-tool-registry 0.6.12 → 0.6.13
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 +6 -6
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { oVirtualTool } from '@olane/o-tool';
|
|
2
|
+
import { oAddress } from '@olane/o-core';
|
|
3
|
+
import { oauthMethods } from './methods/auth.methods.js';
|
|
4
|
+
export class OAuthTool extends oVirtualTool {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
super({
|
|
7
|
+
...config,
|
|
8
|
+
address: new oAddress('o://oauth'),
|
|
9
|
+
description: 'Generic OAuth client tool for custom OAuth provider services',
|
|
10
|
+
methods: oauthMethods,
|
|
11
|
+
});
|
|
12
|
+
this.oauthConfigs = new Map();
|
|
13
|
+
this.tokenStore = new Map();
|
|
14
|
+
}
|
|
15
|
+
// Tool methods
|
|
16
|
+
async _tool_configure(request) {
|
|
17
|
+
const { serviceName, ...config } = request.params;
|
|
18
|
+
if (!serviceName) {
|
|
19
|
+
throw new Error('Service name is required');
|
|
20
|
+
}
|
|
21
|
+
const oauthConfig = {
|
|
22
|
+
clientId: config.clientId,
|
|
23
|
+
clientSecret: config.clientSecret,
|
|
24
|
+
redirectUri: config.redirectUri,
|
|
25
|
+
authorizationUrl: config.authorizationUrl,
|
|
26
|
+
tokenUrl: config.tokenUrl,
|
|
27
|
+
userInfoUrl: config.userInfoUrl,
|
|
28
|
+
scope: config.scope || 'openid profile email',
|
|
29
|
+
responseType: config.responseType || 'code',
|
|
30
|
+
grantType: config.grantType || 'authorization_code',
|
|
31
|
+
tokenValidationUrl: config.tokenValidationUrl,
|
|
32
|
+
tokenRevocationUrl: config.tokenRevocationUrl,
|
|
33
|
+
};
|
|
34
|
+
this.oauthConfigs.set(serviceName, oauthConfig);
|
|
35
|
+
this.logger.info(`OAuth configuration saved for service: ${serviceName}`);
|
|
36
|
+
return {
|
|
37
|
+
success: true,
|
|
38
|
+
serviceName,
|
|
39
|
+
message: `OAuth configuration saved for service: ${serviceName}`,
|
|
40
|
+
endpoints: {
|
|
41
|
+
authorization: config.authorizationUrl,
|
|
42
|
+
token: config.tokenUrl,
|
|
43
|
+
userInfo: config.userInfoUrl,
|
|
44
|
+
tokenValidation: config.tokenValidationUrl,
|
|
45
|
+
tokenRevocation: config.tokenRevocationUrl,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async _tool_getAuthorizationUrl(request) {
|
|
50
|
+
const { serviceName, state, scope, additionalParams } = request.params;
|
|
51
|
+
const config = this.oauthConfigs.get(serviceName);
|
|
52
|
+
if (!config) {
|
|
53
|
+
throw new Error(`OAuth configuration not found for service: ${serviceName}`);
|
|
54
|
+
}
|
|
55
|
+
const url = new URL(config.authorizationUrl);
|
|
56
|
+
url.searchParams.set('client_id', config.clientId);
|
|
57
|
+
url.searchParams.set('redirect_uri', config.redirectUri);
|
|
58
|
+
url.searchParams.set('response_type', config.responseType || 'code');
|
|
59
|
+
url.searchParams.set('scope', scope || config.scope);
|
|
60
|
+
if (state) {
|
|
61
|
+
url.searchParams.set('state', state);
|
|
62
|
+
}
|
|
63
|
+
// Add PKCE support for authorization code flow
|
|
64
|
+
if (config.responseType === 'code') {
|
|
65
|
+
const codeVerifier = this.generateCodeVerifier();
|
|
66
|
+
const codeChallenge = await this.generateCodeChallenge(codeVerifier);
|
|
67
|
+
url.searchParams.set('code_challenge', codeChallenge);
|
|
68
|
+
url.searchParams.set('code_challenge_method', 'S256');
|
|
69
|
+
// Store code verifier for later use
|
|
70
|
+
this.tokenStore.set(`${serviceName}_code_verifier`, {
|
|
71
|
+
code_verifier: codeVerifier,
|
|
72
|
+
access_token: '',
|
|
73
|
+
token_type: '',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
// Add any additional parameters
|
|
77
|
+
if (additionalParams && typeof additionalParams === 'object') {
|
|
78
|
+
Object.entries(additionalParams).forEach(([key, value]) => {
|
|
79
|
+
if (typeof value === 'string') {
|
|
80
|
+
url.searchParams.set(key, value);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
authorizationUrl: url.toString(),
|
|
86
|
+
serviceName,
|
|
87
|
+
state,
|
|
88
|
+
scope: scope || config.scope,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async _tool_exchangeCode(request) {
|
|
92
|
+
const { serviceName, code, state } = request.params;
|
|
93
|
+
const config = this.oauthConfigs.get(serviceName);
|
|
94
|
+
if (!config) {
|
|
95
|
+
throw new Error(`OAuth configuration not found for service: ${serviceName}`);
|
|
96
|
+
}
|
|
97
|
+
const tokenData = {
|
|
98
|
+
grant_type: config.grantType,
|
|
99
|
+
client_id: config.clientId,
|
|
100
|
+
redirect_uri: config.redirectUri,
|
|
101
|
+
code,
|
|
102
|
+
};
|
|
103
|
+
if (config.clientSecret) {
|
|
104
|
+
tokenData.client_secret = config.clientSecret;
|
|
105
|
+
}
|
|
106
|
+
// Add PKCE code verifier if available
|
|
107
|
+
const storedVerifier = this.tokenStore.get(`${serviceName}_code_verifier`);
|
|
108
|
+
if (storedVerifier?.code_verifier) {
|
|
109
|
+
tokenData.code_verifier = storedVerifier.code_verifier;
|
|
110
|
+
this.tokenStore.delete(`${serviceName}_code_verifier`);
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
const response = await fetch(config.tokenUrl, {
|
|
114
|
+
method: 'POST',
|
|
115
|
+
headers: {
|
|
116
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
117
|
+
},
|
|
118
|
+
body: new URLSearchParams(tokenData),
|
|
119
|
+
});
|
|
120
|
+
if (!response.ok) {
|
|
121
|
+
const errorText = await response.text();
|
|
122
|
+
throw new Error(`Token exchange failed: ${response.status} ${errorText}`);
|
|
123
|
+
}
|
|
124
|
+
const tokens = (await response.json());
|
|
125
|
+
// Store tokens
|
|
126
|
+
this.tokenStore.set(`${serviceName}_tokens`, tokens);
|
|
127
|
+
this.logger.info(`Token exchange successful for service: ${serviceName}`);
|
|
128
|
+
return {
|
|
129
|
+
success: true,
|
|
130
|
+
serviceName,
|
|
131
|
+
tokens: {
|
|
132
|
+
access_token: tokens.access_token,
|
|
133
|
+
refresh_token: tokens.refresh_token,
|
|
134
|
+
token_type: tokens.token_type,
|
|
135
|
+
expires_in: tokens.expires_in,
|
|
136
|
+
scope: tokens.scope,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
this.logger.error(`Token exchange failed for service ${serviceName}:`, error);
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async _tool_refreshToken(request) {
|
|
146
|
+
const { serviceName, refreshToken } = request.params;
|
|
147
|
+
const config = this.oauthConfigs.get(serviceName);
|
|
148
|
+
if (!config) {
|
|
149
|
+
throw new Error(`OAuth configuration not found for service: ${serviceName}`);
|
|
150
|
+
}
|
|
151
|
+
const tokenData = {
|
|
152
|
+
grant_type: 'refresh_token',
|
|
153
|
+
client_id: config.clientId,
|
|
154
|
+
refresh_token: refreshToken,
|
|
155
|
+
};
|
|
156
|
+
if (config.clientSecret) {
|
|
157
|
+
tokenData.client_secret = config.clientSecret;
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const response = await fetch(config.tokenUrl, {
|
|
161
|
+
method: 'POST',
|
|
162
|
+
headers: {
|
|
163
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
164
|
+
},
|
|
165
|
+
body: new URLSearchParams(tokenData),
|
|
166
|
+
});
|
|
167
|
+
if (!response.ok) {
|
|
168
|
+
const errorText = await response.text();
|
|
169
|
+
throw new Error(`Token refresh failed: ${response.status} ${errorText}`);
|
|
170
|
+
}
|
|
171
|
+
const tokens = (await response.json());
|
|
172
|
+
// Update stored tokens
|
|
173
|
+
const existingTokens = this.tokenStore.get(`${serviceName}_tokens`);
|
|
174
|
+
if (existingTokens) {
|
|
175
|
+
existingTokens.access_token = tokens.access_token;
|
|
176
|
+
existingTokens.expires_in = tokens.expires_in;
|
|
177
|
+
if (tokens.refresh_token) {
|
|
178
|
+
existingTokens.refresh_token = tokens.refresh_token;
|
|
179
|
+
}
|
|
180
|
+
this.tokenStore.set(`${serviceName}_tokens`, existingTokens);
|
|
181
|
+
}
|
|
182
|
+
this.logger.info(`Token refresh successful for service: ${serviceName}`);
|
|
183
|
+
return {
|
|
184
|
+
success: true,
|
|
185
|
+
serviceName,
|
|
186
|
+
tokens: {
|
|
187
|
+
access_token: tokens.access_token,
|
|
188
|
+
refresh_token: tokens.refresh_token,
|
|
189
|
+
token_type: tokens.token_type,
|
|
190
|
+
expires_in: tokens.expires_in,
|
|
191
|
+
scope: tokens.scope,
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
this.logger.error(`Token refresh failed for service ${serviceName}:`, error);
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
async _tool_getUserInfo(request) {
|
|
201
|
+
const { serviceName, accessToken, userInfoUrl } = request.params;
|
|
202
|
+
const config = this.oauthConfigs.get(serviceName);
|
|
203
|
+
if (!config) {
|
|
204
|
+
throw new Error(`OAuth configuration not found for service: ${serviceName}`);
|
|
205
|
+
}
|
|
206
|
+
const url = userInfoUrl || config.userInfoUrl;
|
|
207
|
+
if (!url) {
|
|
208
|
+
throw new Error(`No user info URL configured for service: ${serviceName}`);
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
const response = await fetch(url, {
|
|
212
|
+
headers: {
|
|
213
|
+
Authorization: `Bearer ${accessToken}`,
|
|
214
|
+
Accept: 'application/json',
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
if (!response.ok) {
|
|
218
|
+
const errorText = await response.text();
|
|
219
|
+
throw new Error(`User info request failed: ${response.status} ${errorText}`);
|
|
220
|
+
}
|
|
221
|
+
const userInfo = (await response.json());
|
|
222
|
+
return {
|
|
223
|
+
success: true,
|
|
224
|
+
serviceName,
|
|
225
|
+
userInfo,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
this.logger.error(`User info request failed for service ${serviceName}:`, error);
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async _tool_validateToken(request) {
|
|
234
|
+
const { serviceName, accessToken, tokenValidationUrl } = request.params;
|
|
235
|
+
const config = this.oauthConfigs.get(serviceName);
|
|
236
|
+
if (!config) {
|
|
237
|
+
throw new Error(`OAuth configuration not found for service: ${serviceName}`);
|
|
238
|
+
}
|
|
239
|
+
const url = tokenValidationUrl || config.tokenValidationUrl;
|
|
240
|
+
if (!url) {
|
|
241
|
+
throw new Error(`No token validation URL configured for service: ${serviceName}`);
|
|
242
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
const response = await fetch(url, {
|
|
245
|
+
headers: {
|
|
246
|
+
Authorization: `Bearer ${accessToken}`,
|
|
247
|
+
Accept: 'application/json',
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
const isValid = response.ok;
|
|
251
|
+
return {
|
|
252
|
+
success: true,
|
|
253
|
+
serviceName,
|
|
254
|
+
isValid,
|
|
255
|
+
status: response.status,
|
|
256
|
+
statusText: response.statusText,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
this.logger.error(`Token validation failed for service ${serviceName}:`, error);
|
|
261
|
+
return {
|
|
262
|
+
success: true,
|
|
263
|
+
serviceName,
|
|
264
|
+
isValid: false,
|
|
265
|
+
error: error.message,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async _tool_revokeToken(request) {
|
|
270
|
+
const { serviceName, token, tokenType = 'access_token', tokenRevocationUrl, } = request.params;
|
|
271
|
+
const config = this.oauthConfigs.get(serviceName);
|
|
272
|
+
if (!config) {
|
|
273
|
+
throw new Error(`OAuth configuration not found for service: ${serviceName}`);
|
|
274
|
+
}
|
|
275
|
+
const url = tokenRevocationUrl || config.tokenRevocationUrl;
|
|
276
|
+
if (!url) {
|
|
277
|
+
throw new Error(`No token revocation URL configured for service: ${serviceName}`);
|
|
278
|
+
}
|
|
279
|
+
const revocationData = {
|
|
280
|
+
token,
|
|
281
|
+
client_id: config.clientId,
|
|
282
|
+
};
|
|
283
|
+
if (config.clientSecret) {
|
|
284
|
+
revocationData.client_secret = config.clientSecret;
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
const response = await fetch(url, {
|
|
288
|
+
method: 'POST',
|
|
289
|
+
headers: {
|
|
290
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
291
|
+
},
|
|
292
|
+
body: new URLSearchParams(revocationData),
|
|
293
|
+
});
|
|
294
|
+
const isRevoked = response.ok;
|
|
295
|
+
// Remove tokens from storage if revoked
|
|
296
|
+
if (isRevoked) {
|
|
297
|
+
const storedTokens = this.tokenStore.get(`${serviceName}_tokens`);
|
|
298
|
+
if (storedTokens) {
|
|
299
|
+
if (tokenType === 'access_token' &&
|
|
300
|
+
storedTokens.access_token === token) {
|
|
301
|
+
this.tokenStore.delete(`${serviceName}_tokens`);
|
|
302
|
+
}
|
|
303
|
+
else if (tokenType === 'refresh_token' &&
|
|
304
|
+
storedTokens.refresh_token === token) {
|
|
305
|
+
delete storedTokens.refresh_token;
|
|
306
|
+
this.tokenStore.set(`${serviceName}_tokens`, storedTokens);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
success: true,
|
|
312
|
+
serviceName,
|
|
313
|
+
isRevoked,
|
|
314
|
+
tokenType,
|
|
315
|
+
status: response.status,
|
|
316
|
+
statusText: response.statusText,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
this.logger.error(`Token revocation failed for service ${serviceName}:`, error);
|
|
321
|
+
return {
|
|
322
|
+
success: true,
|
|
323
|
+
serviceName,
|
|
324
|
+
isRevoked: false,
|
|
325
|
+
tokenType,
|
|
326
|
+
error: error.message,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
async _tool_listServices(request) {
|
|
331
|
+
const services = Array.from(this.oauthConfigs.keys());
|
|
332
|
+
return {
|
|
333
|
+
success: true,
|
|
334
|
+
services,
|
|
335
|
+
count: services.length,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
async _tool_getStoredTokens(request) {
|
|
339
|
+
const { serviceName } = request.params;
|
|
340
|
+
if (serviceName) {
|
|
341
|
+
const tokens = this.tokenStore.get(`${serviceName}_tokens`);
|
|
342
|
+
return {
|
|
343
|
+
success: true,
|
|
344
|
+
serviceName,
|
|
345
|
+
hasTokens: !!tokens,
|
|
346
|
+
tokens: tokens
|
|
347
|
+
? {
|
|
348
|
+
access_token: tokens.access_token,
|
|
349
|
+
refresh_token: tokens.refresh_token,
|
|
350
|
+
token_type: tokens.token_type,
|
|
351
|
+
expires_in: tokens.expires_in,
|
|
352
|
+
scope: tokens.scope,
|
|
353
|
+
}
|
|
354
|
+
: null,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
const allTokens = {};
|
|
359
|
+
for (const [key, value] of this.tokenStore.entries()) {
|
|
360
|
+
if (key.endsWith('_tokens')) {
|
|
361
|
+
const serviceName = key.replace('_tokens', '');
|
|
362
|
+
allTokens[serviceName] = {
|
|
363
|
+
access_token: value.access_token,
|
|
364
|
+
refresh_token: value.refresh_token,
|
|
365
|
+
token_type: value.token_type,
|
|
366
|
+
expires_in: value.expires_in,
|
|
367
|
+
scope: value.scope,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
success: true,
|
|
373
|
+
tokens: allTokens,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
async _tool_clearTokens(request) {
|
|
378
|
+
const { serviceName } = request.params;
|
|
379
|
+
if (serviceName) {
|
|
380
|
+
this.tokenStore.delete(`${serviceName}_tokens`);
|
|
381
|
+
this.tokenStore.delete(`${serviceName}_code_verifier`);
|
|
382
|
+
return {
|
|
383
|
+
success: true,
|
|
384
|
+
serviceName,
|
|
385
|
+
message: `Tokens cleared for service: ${serviceName}`,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
// Clear all tokens
|
|
390
|
+
for (const key of this.tokenStore.keys()) {
|
|
391
|
+
if (key.endsWith('_tokens') || key.endsWith('_code_verifier')) {
|
|
392
|
+
this.tokenStore.delete(key);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return {
|
|
396
|
+
success: true,
|
|
397
|
+
message: 'All tokens cleared',
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
// Helper methods
|
|
402
|
+
generateCodeVerifier() {
|
|
403
|
+
const array = new Uint8Array(32);
|
|
404
|
+
crypto.getRandomValues(array);
|
|
405
|
+
return this.base64URLEncode(array);
|
|
406
|
+
}
|
|
407
|
+
async generateCodeChallenge(verifier) {
|
|
408
|
+
const encoder = new TextEncoder();
|
|
409
|
+
const data = encoder.encode(verifier);
|
|
410
|
+
const digest = await crypto.subtle.digest('SHA-256', data);
|
|
411
|
+
return this.base64URLEncode(new Uint8Array(digest));
|
|
412
|
+
}
|
|
413
|
+
base64URLEncode(buffer) {
|
|
414
|
+
return btoa(String.fromCharCode(...buffer))
|
|
415
|
+
.replace(/\+/g, '-')
|
|
416
|
+
.replace(/\//g, '_')
|
|
417
|
+
.replace(/=/g, '');
|
|
418
|
+
}
|
|
419
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeddings.tool.d.ts","sourceRoot":"","sources":["../../src/embeddings/embeddings.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,YAAY,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,cAAe,SAAQ,YAAY;gBAClC,MAAM,EAAE,WAAW;CAQhC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { oVirtualTool } from '@olane/o-tool';
|
|
2
|
+
import { oAddress } from '@olane/o-core';
|
|
3
|
+
export class EmbeddingsTool extends oVirtualTool {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
super({
|
|
6
|
+
...config,
|
|
7
|
+
address: new oAddress('o://embeddings'),
|
|
8
|
+
description: config.description || 'Generic base class for embeddings tools',
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { oRequest } from '@olane/o-core';
|
|
2
|
+
import { TextEmbeddingsTool } from './text-embeddings.tool.js';
|
|
3
|
+
export declare class HuggingfaceTextEmbeddingsTool extends TextEmbeddingsTool {
|
|
4
|
+
private model;
|
|
5
|
+
initialize(): Promise<void>;
|
|
6
|
+
_tool_embed_documents(request: oRequest): Promise<number[][]>;
|
|
7
|
+
_tool_embed_query(request: oRequest): Promise<number[]>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=huggingface-text-embeddings.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"huggingface-text-embeddings.tool.d.ts","sourceRoot":"","sources":["../../src/embeddings/huggingface-text-embeddings.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAG/D,qBAAa,6BAA8B,SAAQ,kBAAkB;IACnE,OAAO,CAAC,KAAK,CAAqC;IAE5C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAO3B,qBAAqB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IAM7D,iBAAiB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAM9D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TextEmbeddingsTool } from './text-embeddings.tool.js';
|
|
2
|
+
import { HuggingFaceTransformersEmbeddings } from '@langchain/community/embeddings/huggingface_transformers';
|
|
3
|
+
export class HuggingfaceTextEmbeddingsTool extends TextEmbeddingsTool {
|
|
4
|
+
async initialize() {
|
|
5
|
+
await super.initialize();
|
|
6
|
+
this.model = new HuggingFaceTransformersEmbeddings({
|
|
7
|
+
model: 'Xenova/all-MiniLM-L6-v2', // TODO: make this configurable
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
async _tool_embed_documents(request) {
|
|
11
|
+
const { documents } = request.params;
|
|
12
|
+
const result = await this.model.embedDocuments(documents);
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
async _tool_embed_query(request) {
|
|
16
|
+
const { query } = request.params;
|
|
17
|
+
console.log('Embedding query: ', request.params);
|
|
18
|
+
const result = await this.model.embedQuery(query);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/embeddings/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-embeddings.method.d.ts","sourceRoot":"","sources":["../../../src/embeddings/methods/text-embeddings.method.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,eAAO,MAAM,sBAAsB,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CA4B5D,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const TEXT_EMBEDDINGS_PARAMS = {
|
|
2
|
+
embed_documents: {
|
|
3
|
+
name: 'embed_documents',
|
|
4
|
+
description: 'Embed documents',
|
|
5
|
+
dependencies: [],
|
|
6
|
+
parameters: [
|
|
7
|
+
{
|
|
8
|
+
name: 'documents',
|
|
9
|
+
type: 'array',
|
|
10
|
+
value: 'string[]',
|
|
11
|
+
description: 'The documents to embed',
|
|
12
|
+
required: true,
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
embed_query: {
|
|
17
|
+
name: 'embed_query',
|
|
18
|
+
description: 'Embed a query',
|
|
19
|
+
dependencies: [],
|
|
20
|
+
parameters: [
|
|
21
|
+
{
|
|
22
|
+
name: 'query',
|
|
23
|
+
type: 'string',
|
|
24
|
+
value: 'string',
|
|
25
|
+
description: 'The query to embed',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { oVirtualTool } from '@olane/o-tool';
|
|
2
|
+
import { oRequest } from '@olane/o-core';
|
|
3
|
+
import { oToolConfig } from '@olane/o-tool';
|
|
4
|
+
export declare abstract class TextEmbeddingsTool extends oVirtualTool {
|
|
5
|
+
constructor(config: oToolConfig);
|
|
6
|
+
abstract _tool_embed_documents(request: oRequest): Promise<number[][]>;
|
|
7
|
+
abstract _tool_embed_query(request: oRequest): Promise<number[]>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=text-embeddings.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-embeddings.tool.d.ts","sourceRoot":"","sources":["../../src/embeddings/text-embeddings.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAY,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,8BAAsB,kBAAmB,SAAQ,YAAY;gBAC/C,MAAM,EAAE,WAAW;IAS/B,QAAQ,CAAC,qBAAqB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IACtE,QAAQ,CAAC,iBAAiB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CACjE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { oVirtualTool } from '@olane/o-tool';
|
|
2
|
+
import { oAddress } from '@olane/o-core';
|
|
3
|
+
import { TEXT_EMBEDDINGS_PARAMS } from './methods/text-embeddings.method.js';
|
|
4
|
+
export class TextEmbeddingsTool extends oVirtualTool {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
super({
|
|
7
|
+
...config,
|
|
8
|
+
address: new oAddress('o://embeddings-text'),
|
|
9
|
+
methods: TEXT_EMBEDDINGS_PARAMS,
|
|
10
|
+
description: config.description || 'Tool to generate text embeddings',
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
package/dist/init.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,eAAO,MAAM,iBAAiB,UAAW,YAAY,KAAG,IA8BvD,CAAC"}
|
package/dist/init.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { NERTool } from './nlp/ner.tool.js';
|
|
2
|
+
import { HuggingfaceTextEmbeddingsTool } from './embeddings/index.js';
|
|
3
|
+
import { LangchainMemoryVectorStoreTool } from './vector-store/index.js';
|
|
4
|
+
import { IntelligenceTool } from './intelligence/index.js';
|
|
5
|
+
import { McpBridgeTool } from './mcp/index.js';
|
|
6
|
+
export const initRegistryTools = (oNode) => {
|
|
7
|
+
const params = {
|
|
8
|
+
parent: oNode.address,
|
|
9
|
+
leader: oNode.address,
|
|
10
|
+
};
|
|
11
|
+
const tools = [
|
|
12
|
+
new NERTool({
|
|
13
|
+
name: 'ner',
|
|
14
|
+
...params,
|
|
15
|
+
}),
|
|
16
|
+
new IntelligenceTool({
|
|
17
|
+
name: 'intelligence',
|
|
18
|
+
...params,
|
|
19
|
+
}),
|
|
20
|
+
new HuggingfaceTextEmbeddingsTool({
|
|
21
|
+
name: 'embeddings-text',
|
|
22
|
+
...params,
|
|
23
|
+
}),
|
|
24
|
+
new LangchainMemoryVectorStoreTool({
|
|
25
|
+
name: 'vector-store',
|
|
26
|
+
...params,
|
|
27
|
+
}),
|
|
28
|
+
new McpBridgeTool({
|
|
29
|
+
name: 'mcp',
|
|
30
|
+
...params,
|
|
31
|
+
}),
|
|
32
|
+
];
|
|
33
|
+
tools.forEach((tool) => {
|
|
34
|
+
oNode.addChildNode(tool);
|
|
35
|
+
});
|
|
36
|
+
};
|