@frontmcp/plugins 0.4.1 → 0.5.1
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/package.json +8 -3
- package/src/cache/cache.plugin.js +27 -25
- package/src/cache/cache.plugin.js.map +1 -1
- package/src/cache/providers/cache-memory.provider.js +2 -1
- package/src/cache/providers/cache-memory.provider.js.map +1 -1
- package/src/cache/providers/cache-redis.provider.js +1 -0
- package/src/cache/providers/cache-redis.provider.js.map +1 -1
- package/src/codecall/README.md +999 -0
- package/src/codecall/codecall.plugin.d.ts +41 -0
- package/src/codecall/codecall.plugin.js +152 -0
- package/src/codecall/codecall.plugin.js.map +1 -0
- package/src/codecall/codecall.symbol.d.ts +106 -0
- package/src/codecall/codecall.symbol.js +4 -0
- package/src/codecall/codecall.symbol.js.map +1 -0
- package/src/codecall/codecall.types.d.ts +289 -0
- package/src/codecall/codecall.types.js +258 -0
- package/src/codecall/codecall.types.js.map +1 -0
- package/src/codecall/errors/index.d.ts +1 -0
- package/src/codecall/errors/index.js +6 -0
- package/src/codecall/errors/index.js.map +1 -0
- package/src/codecall/errors/tool-call.errors.d.ts +79 -0
- package/src/codecall/errors/tool-call.errors.js +119 -0
- package/src/codecall/errors/tool-call.errors.js.map +1 -0
- package/src/codecall/index.d.ts +2 -0
- package/src/codecall/index.js +8 -0
- package/src/codecall/index.js.map +1 -0
- package/src/codecall/providers/code-call.config.d.ts +29 -0
- package/src/codecall/providers/code-call.config.js +120 -0
- package/src/codecall/providers/code-call.config.js.map +1 -0
- package/src/codecall/security/index.d.ts +2 -0
- package/src/codecall/security/index.js +7 -0
- package/src/codecall/security/index.js.map +1 -0
- package/src/codecall/security/self-reference-guard.d.ts +32 -0
- package/src/codecall/security/self-reference-guard.js +70 -0
- package/src/codecall/security/self-reference-guard.js.map +1 -0
- package/src/codecall/security/tool-access-control.service.d.ts +104 -0
- package/src/codecall/security/tool-access-control.service.js +170 -0
- package/src/codecall/security/tool-access-control.service.js.map +1 -0
- package/src/codecall/services/audit-logger.service.d.ts +186 -0
- package/src/codecall/services/audit-logger.service.js +322 -0
- package/src/codecall/services/audit-logger.service.js.map +1 -0
- package/src/codecall/services/enclave.service.d.ts +62 -0
- package/src/codecall/services/enclave.service.js +214 -0
- package/src/codecall/services/enclave.service.js.map +1 -0
- package/src/codecall/services/error-enrichment.service.d.ts +94 -0
- package/src/codecall/services/error-enrichment.service.js +387 -0
- package/src/codecall/services/error-enrichment.service.js.map +1 -0
- package/src/codecall/services/index.d.ts +6 -0
- package/src/codecall/services/index.js +13 -0
- package/src/codecall/services/index.js.map +1 -0
- package/src/codecall/services/output-sanitizer.d.ts +86 -0
- package/src/codecall/services/output-sanitizer.js +260 -0
- package/src/codecall/services/output-sanitizer.js.map +1 -0
- package/src/codecall/services/synonym-expansion.service.d.ts +66 -0
- package/src/codecall/services/synonym-expansion.service.js +374 -0
- package/src/codecall/services/synonym-expansion.service.js.map +1 -0
- package/src/codecall/services/tool-search.service.d.ts +175 -0
- package/src/codecall/services/tool-search.service.js +587 -0
- package/src/codecall/services/tool-search.service.js.map +1 -0
- package/src/codecall/tools/describe.schema.d.ts +28 -0
- package/src/codecall/tools/describe.schema.js +67 -0
- package/src/codecall/tools/describe.schema.js.map +1 -0
- package/src/codecall/tools/describe.tool.d.ts +35 -0
- package/src/codecall/tools/describe.tool.js +207 -0
- package/src/codecall/tools/describe.tool.js.map +1 -0
- package/src/codecall/tools/execute.schema.d.ts +115 -0
- package/src/codecall/tools/execute.schema.js +116 -0
- package/src/codecall/tools/execute.schema.js.map +1 -0
- package/src/codecall/tools/execute.tool.d.ts +5 -0
- package/src/codecall/tools/execute.tool.js +238 -0
- package/src/codecall/tools/execute.tool.js.map +1 -0
- package/src/codecall/tools/index.d.ts +4 -0
- package/src/codecall/tools/index.js +13 -0
- package/src/codecall/tools/index.js.map +1 -0
- package/src/codecall/tools/invoke.schema.d.ts +99 -0
- package/src/codecall/tools/invoke.schema.js +27 -0
- package/src/codecall/tools/invoke.schema.js.map +1 -0
- package/src/codecall/tools/invoke.tool.d.ts +13 -0
- package/src/codecall/tools/invoke.tool.js +70 -0
- package/src/codecall/tools/invoke.tool.js.map +1 -0
- package/src/codecall/tools/search.schema.d.ts +30 -0
- package/src/codecall/tools/search.schema.js +60 -0
- package/src/codecall/tools/search.schema.js.map +1 -0
- package/src/codecall/tools/search.tool.d.ts +5 -0
- package/src/codecall/tools/search.tool.js +108 -0
- package/src/codecall/tools/search.tool.js.map +1 -0
- package/src/codecall/utils/describe.utils.d.ts +86 -0
- package/src/codecall/utils/describe.utils.js +531 -0
- package/src/codecall/utils/describe.utils.js.map +1 -0
- package/src/codecall/utils/index.d.ts +2 -0
- package/src/codecall/utils/index.js +7 -0
- package/src/codecall/utils/index.js.map +1 -0
- package/src/codecall/utils/mcp-result.d.ts +6 -0
- package/src/codecall/utils/mcp-result.js +36 -0
- package/src/codecall/utils/mcp-result.js.map +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +3 -1
- package/src/index.js.map +1 -1
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// file: libs/plugins/src/codecall/services/synonym-expansion.service.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SynonymExpansionService = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Universal Synonym groups for MCP Tool searching.
|
|
7
|
+
*
|
|
8
|
+
* DESIGN PRINCIPLE:
|
|
9
|
+
* These groups bridge the gap between "User Intent" (Natural Language)
|
|
10
|
+
* and "System Function" (API/Tool Names).
|
|
11
|
+
*
|
|
12
|
+
* STRUCTURE:
|
|
13
|
+
* 1. Core Data Operations (CRUD+)
|
|
14
|
+
* 2. State & Lifecycle
|
|
15
|
+
* 3. Transfer & IO
|
|
16
|
+
* 4. DevOps & Technical
|
|
17
|
+
* 5. Commerce & Business Logic
|
|
18
|
+
* 6. Communication & Social
|
|
19
|
+
* 7. Universal Entities (Nouns)
|
|
20
|
+
*/
|
|
21
|
+
const DEFAULT_SYNONYM_GROUPS = [
|
|
22
|
+
// ===========================================================================
|
|
23
|
+
// 1. CORE DATA OPERATIONS (CRUD+)
|
|
24
|
+
// ===========================================================================
|
|
25
|
+
// Creation / Instantiation
|
|
26
|
+
[
|
|
27
|
+
'create',
|
|
28
|
+
'add',
|
|
29
|
+
'new',
|
|
30
|
+
'insert',
|
|
31
|
+
'make',
|
|
32
|
+
'append',
|
|
33
|
+
'register',
|
|
34
|
+
'generate',
|
|
35
|
+
'produce',
|
|
36
|
+
'build',
|
|
37
|
+
'construct',
|
|
38
|
+
'provision',
|
|
39
|
+
'instantiate',
|
|
40
|
+
'define',
|
|
41
|
+
'compose',
|
|
42
|
+
'draft',
|
|
43
|
+
],
|
|
44
|
+
// Destructive Removal
|
|
45
|
+
[
|
|
46
|
+
'delete',
|
|
47
|
+
'remove',
|
|
48
|
+
'destroy',
|
|
49
|
+
'drop',
|
|
50
|
+
'erase',
|
|
51
|
+
'clear',
|
|
52
|
+
'purge',
|
|
53
|
+
'discard',
|
|
54
|
+
'eliminate',
|
|
55
|
+
'nuke',
|
|
56
|
+
'unbind',
|
|
57
|
+
'unregister',
|
|
58
|
+
],
|
|
59
|
+
// Retrieval / Access
|
|
60
|
+
['get', 'fetch', 'retrieve', 'read', 'obtain', 'load', 'pull', 'access', 'grab', 'snag', 'receive'],
|
|
61
|
+
// Modification
|
|
62
|
+
[
|
|
63
|
+
'update',
|
|
64
|
+
'edit',
|
|
65
|
+
'modify',
|
|
66
|
+
'change',
|
|
67
|
+
'patch',
|
|
68
|
+
'alter',
|
|
69
|
+
'revise',
|
|
70
|
+
'refresh',
|
|
71
|
+
'correct',
|
|
72
|
+
'amend',
|
|
73
|
+
'adjust',
|
|
74
|
+
'tweak',
|
|
75
|
+
'rectify',
|
|
76
|
+
'refine',
|
|
77
|
+
],
|
|
78
|
+
// Viewing / Listing
|
|
79
|
+
[
|
|
80
|
+
'list',
|
|
81
|
+
'show',
|
|
82
|
+
'display',
|
|
83
|
+
'enumerate',
|
|
84
|
+
'browse',
|
|
85
|
+
'view',
|
|
86
|
+
'peek',
|
|
87
|
+
'index',
|
|
88
|
+
'catalog',
|
|
89
|
+
'survey',
|
|
90
|
+
'inspect',
|
|
91
|
+
'ls',
|
|
92
|
+
'dir',
|
|
93
|
+
],
|
|
94
|
+
// Searching / Discovery
|
|
95
|
+
[
|
|
96
|
+
'find',
|
|
97
|
+
'search',
|
|
98
|
+
'lookup',
|
|
99
|
+
'query',
|
|
100
|
+
'locate',
|
|
101
|
+
'filter',
|
|
102
|
+
'scan',
|
|
103
|
+
'explore',
|
|
104
|
+
'investigate',
|
|
105
|
+
'detect',
|
|
106
|
+
'scout',
|
|
107
|
+
'seek',
|
|
108
|
+
],
|
|
109
|
+
// Soft Delete / Archival
|
|
110
|
+
['archive', 'shelve', 'retire', 'hide', 'suppress', 'mute'],
|
|
111
|
+
['unarchive', 'restore', 'recover', 'undelete', 'unhide'],
|
|
112
|
+
// ===========================================================================
|
|
113
|
+
// 2. STATE & LIFECYCLE
|
|
114
|
+
// ===========================================================================
|
|
115
|
+
// Activation
|
|
116
|
+
[
|
|
117
|
+
'enable',
|
|
118
|
+
'activate',
|
|
119
|
+
'start',
|
|
120
|
+
'turn on',
|
|
121
|
+
'switch on',
|
|
122
|
+
'boot',
|
|
123
|
+
'init',
|
|
124
|
+
'initialize',
|
|
125
|
+
'setup',
|
|
126
|
+
'spin up',
|
|
127
|
+
'resume',
|
|
128
|
+
'unpause',
|
|
129
|
+
],
|
|
130
|
+
// Deactivation
|
|
131
|
+
[
|
|
132
|
+
'disable',
|
|
133
|
+
'deactivate',
|
|
134
|
+
'stop',
|
|
135
|
+
'turn off',
|
|
136
|
+
'switch off',
|
|
137
|
+
'shutdown',
|
|
138
|
+
'halt',
|
|
139
|
+
'kill',
|
|
140
|
+
'terminate',
|
|
141
|
+
'suspend',
|
|
142
|
+
'pause',
|
|
143
|
+
'cease',
|
|
144
|
+
],
|
|
145
|
+
// Execution
|
|
146
|
+
['run', 'execute', 'invoke', 'trigger', 'launch', 'call', 'perform', 'operate', 'handle', 'process', 'fire'],
|
|
147
|
+
// Reset cycles
|
|
148
|
+
['restart', 'reboot', 'reset', 'reload', 'bounce', 'recycle', 'refresh'],
|
|
149
|
+
// Validation & Check
|
|
150
|
+
['validate', 'verify', 'check', 'confirm', 'assert', 'test', 'audit', 'assess', 'healthcheck', 'ping'],
|
|
151
|
+
// Analysis & Math
|
|
152
|
+
[
|
|
153
|
+
'analyze',
|
|
154
|
+
'interpret',
|
|
155
|
+
'diagnose',
|
|
156
|
+
'evaluate',
|
|
157
|
+
'review',
|
|
158
|
+
'summarize',
|
|
159
|
+
'count',
|
|
160
|
+
'calculate',
|
|
161
|
+
'compute',
|
|
162
|
+
'measure',
|
|
163
|
+
'aggregate',
|
|
164
|
+
'summarise',
|
|
165
|
+
],
|
|
166
|
+
// ===========================================================================
|
|
167
|
+
// 3. TRANSFER, IO & MANIPULATION
|
|
168
|
+
// ===========================================================================
|
|
169
|
+
// Duplication
|
|
170
|
+
['copy', 'duplicate', 'clone', 'replicate', 'mirror', 'fork', 'repro'],
|
|
171
|
+
// Movement
|
|
172
|
+
['move', 'transfer', 'migrate', 'relocate', 'rename', 'shift', 'mv', 'slide'],
|
|
173
|
+
// Persistence
|
|
174
|
+
['save', 'store', 'write', 'persist', 'commit', 'stash', 'record', 'log'],
|
|
175
|
+
// Synchronization
|
|
176
|
+
['sync', 'synchronize', 'resync', 'reconcile', 'align', 'pair'],
|
|
177
|
+
// Import/Export
|
|
178
|
+
['import', 'ingest', 'upload', 'push', 'feed'],
|
|
179
|
+
['export', 'download', 'dump', 'backup', 'extract'],
|
|
180
|
+
// Connection
|
|
181
|
+
['connect', 'link', 'bind', 'attach', 'join', 'bridge', 'associate', 'mount', 'map'],
|
|
182
|
+
['disconnect', 'unlink', 'unbind', 'detach', 'leave', 'dissociate', 'unmount', 'unmap'],
|
|
183
|
+
// ===========================================================================
|
|
184
|
+
// 4. DEVOPS, SECURITY & TECHNICAL
|
|
185
|
+
// ===========================================================================
|
|
186
|
+
// Auth
|
|
187
|
+
['login', 'log in', 'sign in', 'authenticate', 'auth'],
|
|
188
|
+
['logout', 'log out', 'sign out', 'disconnect'],
|
|
189
|
+
// Permissions
|
|
190
|
+
['approve', 'authorize', 'grant', 'permit', 'allow', 'sanction', 'whitelist'],
|
|
191
|
+
['deny', 'reject', 'revoke', 'forbid', 'block', 'ban', 'blacklist'],
|
|
192
|
+
// Encryption
|
|
193
|
+
['encrypt', 'secure', 'lock', 'seal', 'protect', 'scramble', 'hash'],
|
|
194
|
+
['decrypt', 'unlock', 'unseal', 'reveal', 'decode'],
|
|
195
|
+
// Deployment
|
|
196
|
+
['deploy', 'release', 'ship', 'publish', 'roll out', 'promote', 'distribute', 'install'],
|
|
197
|
+
// Development
|
|
198
|
+
['debug', 'troubleshoot', 'fix', 'repair', 'resolve', 'trace'],
|
|
199
|
+
['compile', 'transpile', 'build', 'assemble', 'package', 'bundle', 'minify'],
|
|
200
|
+
// ===========================================================================
|
|
201
|
+
// 5. COMMERCE & BUSINESS LOGIC
|
|
202
|
+
// ===========================================================================
|
|
203
|
+
// Financial Transactions
|
|
204
|
+
['buy', 'purchase', 'order', 'pay', 'checkout', 'spend'],
|
|
205
|
+
['sell', 'refund', 'reimburse', 'charge', 'invoice', 'bill'],
|
|
206
|
+
['subscribe', 'upgrade', 'upsell'],
|
|
207
|
+
['unsubscribe', 'cancel', 'downgrade'],
|
|
208
|
+
// Scheduling
|
|
209
|
+
['schedule', 'book', 'appoint', 'reserve', 'plan', 'calendar'],
|
|
210
|
+
['reschedule', 'postpone', 'delay', 'defer'],
|
|
211
|
+
// ===========================================================================
|
|
212
|
+
// 6. COMMUNICATION & SOCIAL
|
|
213
|
+
// ===========================================================================
|
|
214
|
+
// Outbound
|
|
215
|
+
[
|
|
216
|
+
'send',
|
|
217
|
+
'dispatch',
|
|
218
|
+
'deliver',
|
|
219
|
+
'transmit',
|
|
220
|
+
'post',
|
|
221
|
+
'broadcast',
|
|
222
|
+
'notify',
|
|
223
|
+
'alert',
|
|
224
|
+
'email',
|
|
225
|
+
'text',
|
|
226
|
+
'message',
|
|
227
|
+
'chat',
|
|
228
|
+
],
|
|
229
|
+
// Social Interactions
|
|
230
|
+
['reply', 'respond', 'answer', 'retort'],
|
|
231
|
+
['share', 'forward', 'retweet', 'repost'],
|
|
232
|
+
['like', 'favorite', 'star', 'upvote', 'heart'],
|
|
233
|
+
['dislike', 'downvote'],
|
|
234
|
+
['follow', 'watch', 'track'],
|
|
235
|
+
['unfollow', 'ignore', 'mute'],
|
|
236
|
+
// ===========================================================================
|
|
237
|
+
// 7. COMMON ENTITIES (NOUNS)
|
|
238
|
+
// ===========================================================================
|
|
239
|
+
// Users & Roles
|
|
240
|
+
[
|
|
241
|
+
'user',
|
|
242
|
+
'account',
|
|
243
|
+
'member',
|
|
244
|
+
'profile',
|
|
245
|
+
'identity',
|
|
246
|
+
'customer',
|
|
247
|
+
'principal',
|
|
248
|
+
'admin',
|
|
249
|
+
'operator',
|
|
250
|
+
'client',
|
|
251
|
+
'employee',
|
|
252
|
+
'staff',
|
|
253
|
+
],
|
|
254
|
+
['role', 'group', 'team', 'squad', 'unit', 'department'],
|
|
255
|
+
// Data Artifacts
|
|
256
|
+
['file', 'document', 'attachment', 'blob', 'asset', 'object', 'resource', 'content', 'media'],
|
|
257
|
+
['image', 'picture', 'photo', 'screenshot'],
|
|
258
|
+
['video', 'clip', 'recording', 'footage'],
|
|
259
|
+
// System Artifacts
|
|
260
|
+
['message', 'notification', 'alert', 'event', 'signal', 'webhook', 'ping'],
|
|
261
|
+
['log', 'trace', 'metric', 'telemetry', 'audit trail', 'history'],
|
|
262
|
+
['settings', 'config', 'configuration', 'preferences', 'options', 'params', 'env', 'environment', 'variables'],
|
|
263
|
+
['permission', 'privilege', 'access right', 'policy', 'rule', 'scope'],
|
|
264
|
+
// Business Artifacts
|
|
265
|
+
['organization', 'company', 'tenant', 'workspace', 'org', 'project', 'repo', 'repository'],
|
|
266
|
+
['product', 'item', 'sku', 'inventory', 'stock'],
|
|
267
|
+
['task', 'ticket', 'issue', 'bug', 'story', 'epic', 'todo', 'job', 'workitem'],
|
|
268
|
+
// Identification
|
|
269
|
+
['id', 'identifier', 'key', 'uuid', 'guid', 'token', 'hash', 'fingerprint'],
|
|
270
|
+
];
|
|
271
|
+
/**
|
|
272
|
+
* Lightweight synonym expansion service for improving TF-IDF search relevance.
|
|
273
|
+
* Zero dependencies, synchronous, and easily extensible.
|
|
274
|
+
*
|
|
275
|
+
* This service provides query-time synonym expansion to help TF-IDF-based
|
|
276
|
+
* search understand that semantically similar terms (like "add" and "create")
|
|
277
|
+
* should match the same tools.
|
|
278
|
+
*/
|
|
279
|
+
class SynonymExpansionService {
|
|
280
|
+
synonymMap;
|
|
281
|
+
maxExpansions;
|
|
282
|
+
constructor(config = {}) {
|
|
283
|
+
this.maxExpansions = config.maxExpansionsPerTerm ?? 5;
|
|
284
|
+
// Build synonym map from groups
|
|
285
|
+
const groups = config.replaceDefaults
|
|
286
|
+
? config.additionalSynonyms || []
|
|
287
|
+
: [...DEFAULT_SYNONYM_GROUPS, ...(config.additionalSynonyms || [])];
|
|
288
|
+
this.synonymMap = this.buildSynonymMap(groups);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Build a bidirectional synonym map from groups.
|
|
292
|
+
* Each term maps to all other terms in its group(s).
|
|
293
|
+
*/
|
|
294
|
+
buildSynonymMap(groups) {
|
|
295
|
+
const map = new Map();
|
|
296
|
+
for (const group of groups) {
|
|
297
|
+
const normalizedGroup = group.map((term) => term.toLowerCase());
|
|
298
|
+
for (const term of normalizedGroup) {
|
|
299
|
+
if (!map.has(term)) {
|
|
300
|
+
map.set(term, new Set());
|
|
301
|
+
}
|
|
302
|
+
const synonyms = map.get(term);
|
|
303
|
+
// Add all other terms in the group as synonyms
|
|
304
|
+
for (const synonym of normalizedGroup) {
|
|
305
|
+
if (synonym !== term) {
|
|
306
|
+
synonyms.add(synonym);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return map;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Get synonyms for a single term.
|
|
315
|
+
* Returns empty array if no synonyms found.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* getSynonyms('add') // ['create', 'new', 'insert', 'make']
|
|
319
|
+
*/
|
|
320
|
+
getSynonyms(term) {
|
|
321
|
+
const normalized = term.toLowerCase();
|
|
322
|
+
const synonyms = this.synonymMap.get(normalized);
|
|
323
|
+
if (!synonyms) {
|
|
324
|
+
return [];
|
|
325
|
+
}
|
|
326
|
+
// Return limited synonyms to prevent query explosion
|
|
327
|
+
return Array.from(synonyms).slice(0, this.maxExpansions);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Expand a query string by adding synonyms for each term.
|
|
331
|
+
* Returns the expanded query string with original terms and their synonyms.
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* expandQuery('add user') // 'add create new insert make user account member profile'
|
|
335
|
+
*/
|
|
336
|
+
expandQuery(query) {
|
|
337
|
+
const terms = query
|
|
338
|
+
.toLowerCase()
|
|
339
|
+
.split(/\s+/)
|
|
340
|
+
.filter((term) => term.length > 1);
|
|
341
|
+
const expandedTerms = [];
|
|
342
|
+
for (const term of terms) {
|
|
343
|
+
// Always include the original term first
|
|
344
|
+
expandedTerms.push(term);
|
|
345
|
+
// Add synonyms
|
|
346
|
+
const synonyms = this.getSynonyms(term);
|
|
347
|
+
expandedTerms.push(...synonyms);
|
|
348
|
+
}
|
|
349
|
+
return expandedTerms.join(' ');
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Check if synonym expansion is available for any term in the query.
|
|
353
|
+
*/
|
|
354
|
+
hasExpansions(query) {
|
|
355
|
+
const terms = query.toLowerCase().split(/\s+/);
|
|
356
|
+
return terms.some((term) => this.synonymMap.has(term));
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Get statistics about the synonym dictionary.
|
|
360
|
+
*/
|
|
361
|
+
getStats() {
|
|
362
|
+
const termCount = this.synonymMap.size;
|
|
363
|
+
let totalSynonyms = 0;
|
|
364
|
+
for (const synonyms of this.synonymMap.values()) {
|
|
365
|
+
totalSynonyms += synonyms.size;
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
termCount,
|
|
369
|
+
avgSynonymsPerTerm: termCount > 0 ? totalSynonyms / termCount : 0,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
exports.SynonymExpansionService = SynonymExpansionService;
|
|
374
|
+
//# sourceMappingURL=synonym-expansion.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synonym-expansion.service.js","sourceRoot":"","sources":["../../../../src/codecall/services/synonym-expansion.service.ts"],"names":[],"mappings":";AAAA,wEAAwE;;;AAExE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,sBAAsB,GAAyC;IACnE,8EAA8E;IAC9E,kCAAkC;IAClC,8EAA8E;IAE9E,2BAA2B;IAC3B;QACE,QAAQ;QACR,KAAK;QACL,KAAK;QACL,QAAQ;QACR,MAAM;QACN,QAAQ;QACR,UAAU;QACV,UAAU;QACV,SAAS;QACT,OAAO;QACP,WAAW;QACX,WAAW;QACX,aAAa;QACb,QAAQ;QACR,SAAS;QACT,OAAO;KACR;IAED,sBAAsB;IACtB;QACE,QAAQ;QACR,QAAQ;QACR,SAAS;QACT,MAAM;QACN,OAAO;QACP,OAAO;QACP,OAAO;QACP,SAAS;QACT,WAAW;QACX,MAAM;QACN,QAAQ;QACR,YAAY;KACb;IAED,qBAAqB;IACrB,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC;IAEn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,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;SAClE,CAAC;IACJ,CAAC;CACF;AAjHD,0DAiHC","sourcesContent":["// file: libs/plugins/src/codecall/services/synonym-expansion.service.ts\n\n/**\n * Universal Synonym groups for MCP Tool searching.\n *\n * DESIGN PRINCIPLE:\n * These groups bridge the gap between \"User Intent\" (Natural Language)\n * and \"System Function\" (API/Tool Names).\n *\n * STRUCTURE:\n * 1. Core Data Operations (CRUD+)\n * 2. State & Lifecycle\n * 3. Transfer & IO\n * 4. DevOps & Technical\n * 5. Commerce & Business Logic\n * 6. Communication & Social\n * 7. Universal Entities (Nouns)\n */\nconst DEFAULT_SYNONYM_GROUPS: ReadonlyArray<ReadonlyArray<string>> = [\n // ===========================================================================\n // 1. CORE DATA OPERATIONS (CRUD+)\n // ===========================================================================\n\n // Creation / Instantiation\n [\n 'create',\n 'add',\n 'new',\n 'insert',\n 'make',\n 'append',\n 'register',\n 'generate',\n 'produce',\n 'build',\n 'construct',\n 'provision',\n 'instantiate',\n 'define',\n 'compose',\n 'draft',\n ],\n\n // Destructive Removal\n [\n 'delete',\n 'remove',\n 'destroy',\n 'drop',\n 'erase',\n 'clear',\n 'purge',\n 'discard',\n 'eliminate',\n 'nuke',\n 'unbind',\n 'unregister',\n ],\n\n // Retrieval / Access\n ['get', 'fetch', 'retrieve', 'read', 'obtain', 'load', 'pull', 'access', 'grab', 'snag', 'receive'],\n\n // Modification\n [\n 'update',\n 'edit',\n 'modify',\n 'change',\n 'patch',\n 'alter',\n 'revise',\n 'refresh',\n 'correct',\n 'amend',\n 'adjust',\n 'tweak',\n 'rectify',\n 'refine',\n ],\n\n // Viewing / Listing\n [\n 'list',\n 'show',\n 'display',\n 'enumerate',\n 'browse',\n 'view',\n 'peek',\n 'index',\n 'catalog',\n 'survey',\n 'inspect',\n 'ls',\n 'dir',\n ],\n\n // Searching / Discovery\n [\n 'find',\n 'search',\n 'lookup',\n 'query',\n 'locate',\n 'filter',\n 'scan',\n 'explore',\n 'investigate',\n 'detect',\n 'scout',\n 'seek',\n ],\n\n // Soft Delete / Archival\n ['archive', 'shelve', 'retire', 'hide', 'suppress', 'mute'],\n ['unarchive', 'restore', 'recover', 'undelete', 'unhide'],\n\n // ===========================================================================\n // 2. STATE & LIFECYCLE\n // ===========================================================================\n\n // Activation\n [\n 'enable',\n 'activate',\n 'start',\n 'turn on',\n 'switch on',\n 'boot',\n 'init',\n 'initialize',\n 'setup',\n 'spin up',\n 'resume',\n 'unpause',\n ],\n\n // Deactivation\n [\n 'disable',\n 'deactivate',\n 'stop',\n 'turn off',\n 'switch off',\n 'shutdown',\n 'halt',\n 'kill',\n 'terminate',\n 'suspend',\n 'pause',\n 'cease',\n ],\n\n // Execution\n ['run', 'execute', 'invoke', 'trigger', 'launch', 'call', 'perform', 'operate', 'handle', 'process', 'fire'],\n\n // Reset cycles\n ['restart', 'reboot', 'reset', 'reload', 'bounce', 'recycle', 'refresh'],\n\n // Validation & Check\n ['validate', 'verify', 'check', 'confirm', 'assert', 'test', 'audit', 'assess', 'healthcheck', 'ping'],\n\n // Analysis & Math\n [\n 'analyze',\n 'interpret',\n 'diagnose',\n 'evaluate',\n 'review',\n 'summarize',\n 'count',\n 'calculate',\n 'compute',\n 'measure',\n 'aggregate',\n 'summarise',\n ],\n\n // ===========================================================================\n // 3. TRANSFER, IO & MANIPULATION\n // ===========================================================================\n\n // Duplication\n ['copy', 'duplicate', 'clone', 'replicate', 'mirror', 'fork', 'repro'],\n\n // Movement\n ['move', 'transfer', 'migrate', 'relocate', 'rename', 'shift', 'mv', 'slide'],\n\n // Persistence\n ['save', 'store', 'write', 'persist', 'commit', 'stash', 'record', 'log'],\n\n // Synchronization\n ['sync', 'synchronize', 'resync', 'reconcile', 'align', 'pair'],\n\n // Import/Export\n ['import', 'ingest', 'upload', 'push', 'feed'],\n ['export', 'download', 'dump', 'backup', 'extract'],\n\n // Connection\n ['connect', 'link', 'bind', 'attach', 'join', 'bridge', 'associate', 'mount', 'map'],\n ['disconnect', 'unlink', 'unbind', 'detach', 'leave', 'dissociate', 'unmount', 'unmap'],\n\n // ===========================================================================\n // 4. DEVOPS, SECURITY & TECHNICAL\n // ===========================================================================\n\n // Auth\n ['login', 'log in', 'sign in', 'authenticate', 'auth'],\n ['logout', 'log out', 'sign out', 'disconnect'],\n\n // Permissions\n ['approve', 'authorize', 'grant', 'permit', 'allow', 'sanction', 'whitelist'],\n ['deny', 'reject', 'revoke', 'forbid', 'block', 'ban', 'blacklist'],\n\n // Encryption\n ['encrypt', 'secure', 'lock', 'seal', 'protect', 'scramble', 'hash'],\n ['decrypt', 'unlock', 'unseal', 'reveal', 'decode'],\n\n // Deployment\n ['deploy', 'release', 'ship', 'publish', 'roll out', 'promote', 'distribute', 'install'],\n\n // Development\n ['debug', 'troubleshoot', 'fix', 'repair', 'resolve', 'trace'],\n ['compile', 'transpile', 'build', 'assemble', 'package', 'bundle', 'minify'],\n\n // ===========================================================================\n // 5. COMMERCE & BUSINESS LOGIC\n // ===========================================================================\n\n // Financial Transactions\n ['buy', 'purchase', 'order', 'pay', 'checkout', 'spend'],\n ['sell', 'refund', 'reimburse', 'charge', 'invoice', 'bill'],\n ['subscribe', 'upgrade', 'upsell'],\n ['unsubscribe', 'cancel', 'downgrade'],\n\n // Scheduling\n ['schedule', 'book', 'appoint', 'reserve', 'plan', 'calendar'],\n ['reschedule', 'postpone', 'delay', 'defer'],\n\n // ===========================================================================\n // 6. COMMUNICATION & SOCIAL\n // ===========================================================================\n\n // Outbound\n [\n 'send',\n 'dispatch',\n 'deliver',\n 'transmit',\n 'post',\n 'broadcast',\n 'notify',\n 'alert',\n 'email',\n 'text',\n 'message',\n 'chat',\n ],\n\n // Social Interactions\n ['reply', 'respond', 'answer', 'retort'],\n ['share', 'forward', 'retweet', 'repost'],\n ['like', 'favorite', 'star', 'upvote', 'heart'],\n ['dislike', 'downvote'],\n ['follow', 'watch', 'track'],\n ['unfollow', 'ignore', 'mute'],\n\n // ===========================================================================\n // 7. COMMON ENTITIES (NOUNS)\n // ===========================================================================\n\n // Users & Roles\n [\n 'user',\n 'account',\n 'member',\n 'profile',\n 'identity',\n 'customer',\n 'principal',\n 'admin',\n 'operator',\n 'client',\n 'employee',\n 'staff',\n ],\n ['role', 'group', 'team', 'squad', 'unit', 'department'],\n\n // Data Artifacts\n ['file', 'document', 'attachment', 'blob', 'asset', 'object', 'resource', 'content', 'media'],\n ['image', 'picture', 'photo', 'screenshot'],\n ['video', 'clip', 'recording', 'footage'],\n\n // System Artifacts\n ['message', 'notification', 'alert', 'event', 'signal', 'webhook', 'ping'],\n ['log', 'trace', 'metric', 'telemetry', 'audit trail', 'history'],\n ['settings', 'config', 'configuration', 'preferences', 'options', 'params', 'env', 'environment', 'variables'],\n ['permission', 'privilege', 'access right', 'policy', 'rule', 'scope'],\n\n // Business Artifacts\n ['organization', 'company', 'tenant', 'workspace', 'org', 'project', 'repo', 'repository'],\n ['product', 'item', 'sku', 'inventory', 'stock'],\n ['task', 'ticket', 'issue', 'bug', 'story', 'epic', 'todo', 'job', 'workitem'],\n\n // Identification\n ['id', 'identifier', 'key', 'uuid', 'guid', 'token', 'hash', 'fingerprint'],\n];\n\n/**\n * Configuration for the SynonymExpansionService\n */\nexport interface SynonymExpansionConfig {\n /**\n * Additional synonym groups to include beyond defaults.\n * Each group is an array of related terms.\n */\n additionalSynonyms?: ReadonlyArray<ReadonlyArray<string>>;\n\n /**\n * If true, completely replace default synonyms with additionalSynonyms.\n * @default false\n */\n replaceDefaults?: boolean;\n\n /**\n * Maximum number of expanded terms per input term.\n * Prevents query explosion.\n * @default 5\n */\n maxExpansionsPerTerm?: number;\n}\n\n/**\n * Lightweight synonym expansion service for improving TF-IDF search relevance.\n * Zero dependencies, synchronous, and easily extensible.\n *\n * This service provides query-time synonym expansion to help TF-IDF-based\n * search understand that semantically similar terms (like \"add\" and \"create\")\n * should match the same tools.\n */\nexport class SynonymExpansionService {\n private synonymMap: Map<string, Set<string>>;\n private maxExpansions: number;\n\n constructor(config: SynonymExpansionConfig = {}) {\n this.maxExpansions = config.maxExpansionsPerTerm ?? 5;\n\n // Build synonym map from groups\n const groups = config.replaceDefaults\n ? config.additionalSynonyms || []\n : [...DEFAULT_SYNONYM_GROUPS, ...(config.additionalSynonyms || [])];\n\n this.synonymMap = this.buildSynonymMap(groups);\n }\n\n /**\n * Build a bidirectional synonym map from groups.\n * Each term maps to all other terms in its group(s).\n */\n private buildSynonymMap(groups: ReadonlyArray<ReadonlyArray<string>>): Map<string, Set<string>> {\n const map = new Map<string, Set<string>>();\n\n for (const group of groups) {\n const normalizedGroup = group.map((term) => term.toLowerCase());\n\n for (const term of normalizedGroup) {\n if (!map.has(term)) {\n map.set(term, new Set());\n }\n const synonyms = map.get(term)!;\n\n // Add all other terms in the group as synonyms\n for (const synonym of normalizedGroup) {\n if (synonym !== term) {\n synonyms.add(synonym);\n }\n }\n }\n }\n\n return map;\n }\n\n /**\n * Get synonyms for a single term.\n * Returns empty array if no synonyms found.\n *\n * @example\n * getSynonyms('add') // ['create', 'new', 'insert', 'make']\n */\n getSynonyms(term: string): string[] {\n const normalized = term.toLowerCase();\n const synonyms = this.synonymMap.get(normalized);\n\n if (!synonyms) {\n return [];\n }\n\n // Return limited synonyms to prevent query explosion\n return Array.from(synonyms).slice(0, this.maxExpansions);\n }\n\n /**\n * Expand a query string by adding synonyms for each term.\n * Returns the expanded query string with original terms and their synonyms.\n *\n * @example\n * expandQuery('add user') // 'add create new insert make user account member profile'\n */\n expandQuery(query: string): string {\n const terms = query\n .toLowerCase()\n .split(/\\s+/)\n .filter((term) => term.length > 1);\n\n const expandedTerms: string[] = [];\n\n for (const term of terms) {\n // Always include the original term first\n expandedTerms.push(term);\n\n // Add synonyms\n const synonyms = this.getSynonyms(term);\n expandedTerms.push(...synonyms);\n }\n\n return expandedTerms.join(' ');\n }\n\n /**\n * Check if synonym expansion is available for any term in the query.\n */\n hasExpansions(query: string): boolean {\n const terms = query.toLowerCase().split(/\\s+/);\n return terms.some((term) => this.synonymMap.has(term));\n }\n\n /**\n * Get statistics about the synonym dictionary.\n */\n getStats(): { termCount: number; avgSynonymsPerTerm: number } {\n const termCount = this.synonymMap.size;\n let totalSynonyms = 0;\n\n for (const synonyms of this.synonymMap.values()) {\n totalSynonyms += synonyms.size;\n }\n\n return {\n termCount,\n avgSynonymsPerTerm: termCount > 0 ? totalSynonyms / termCount : 0,\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { ToolEntry, ScopeEntry } from '@frontmcp/sdk';
|
|
2
|
+
import type { EmbeddingStrategy, CodeCallEmbeddingOptions, CodeCallMode } from '../codecall.types';
|
|
3
|
+
import type { ToolSearch, ToolSearchResult as SymbolToolSearchResult, ToolSearchOptions as SymbolToolSearchOptions } from '../codecall.symbol';
|
|
4
|
+
import { SynonymExpansionConfig } from './synonym-expansion.service';
|
|
5
|
+
/**
|
|
6
|
+
* Search result for tool search
|
|
7
|
+
*/
|
|
8
|
+
export interface SearchResult {
|
|
9
|
+
tool: ToolEntry<any, any>;
|
|
10
|
+
score: number;
|
|
11
|
+
toolName: string;
|
|
12
|
+
qualifiedName: string;
|
|
13
|
+
appId?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Search options for tool search
|
|
17
|
+
*/
|
|
18
|
+
export interface SearchOptions {
|
|
19
|
+
topK?: number;
|
|
20
|
+
appIds?: string[];
|
|
21
|
+
excludeToolNames?: string[];
|
|
22
|
+
minScore?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Filter function type for including tools
|
|
26
|
+
*/
|
|
27
|
+
export type IncludeToolsFilter = (info: {
|
|
28
|
+
name: string;
|
|
29
|
+
appId?: string;
|
|
30
|
+
source?: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
tags?: string[];
|
|
33
|
+
}) => boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Configuration for tool search service
|
|
36
|
+
*/
|
|
37
|
+
export interface ToolSearchServiceConfig {
|
|
38
|
+
/**
|
|
39
|
+
* Embedding strategy to use
|
|
40
|
+
* @default 'tfidf'
|
|
41
|
+
*/
|
|
42
|
+
strategy?: EmbeddingStrategy;
|
|
43
|
+
/**
|
|
44
|
+
* Full embedding options (alternative to just strategy)
|
|
45
|
+
*/
|
|
46
|
+
embeddingOptions?: CodeCallEmbeddingOptions;
|
|
47
|
+
/**
|
|
48
|
+
* Default number of results to return
|
|
49
|
+
* @default 8
|
|
50
|
+
*/
|
|
51
|
+
defaultTopK?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Default similarity threshold
|
|
54
|
+
* @default 0.0
|
|
55
|
+
*/
|
|
56
|
+
defaultSimilarityThreshold?: number;
|
|
57
|
+
/**
|
|
58
|
+
* CodeCall mode for filtering tools
|
|
59
|
+
* @default 'codecall_only'
|
|
60
|
+
*/
|
|
61
|
+
mode?: CodeCallMode;
|
|
62
|
+
/**
|
|
63
|
+
* Optional filter function for including tools in the search index
|
|
64
|
+
*/
|
|
65
|
+
includeTools?: IncludeToolsFilter;
|
|
66
|
+
/**
|
|
67
|
+
* Synonym expansion configuration.
|
|
68
|
+
* When enabled, queries are expanded with synonyms to improve search relevance.
|
|
69
|
+
* For example, "add user" will also match tools containing "create user".
|
|
70
|
+
* Only applies when strategy is 'tfidf' (ML already handles semantic similarity).
|
|
71
|
+
*
|
|
72
|
+
* Set to false to disable, or provide a config object to customize.
|
|
73
|
+
* @default { enabled: true } when strategy is 'tfidf'
|
|
74
|
+
*/
|
|
75
|
+
synonymExpansion?: false | (SynonymExpansionConfig & {
|
|
76
|
+
enabled?: boolean;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Service that maintains a searchable index of tools from the ToolRegistry
|
|
81
|
+
* Supports both TF-IDF (lightweight, synchronous) and ML-based (semantic) embeddings
|
|
82
|
+
* Implements the ToolSearch interface for dependency injection
|
|
83
|
+
*/
|
|
84
|
+
export declare class ToolSearchService implements ToolSearch {
|
|
85
|
+
private static readonly MAX_SUBSCRIPTION_RETRIES;
|
|
86
|
+
private vectorDB;
|
|
87
|
+
private strategy;
|
|
88
|
+
private initialized;
|
|
89
|
+
private mlInitialized;
|
|
90
|
+
private subscriptionRetries;
|
|
91
|
+
private config;
|
|
92
|
+
private scope;
|
|
93
|
+
private unsubscribe?;
|
|
94
|
+
private synonymService;
|
|
95
|
+
constructor(config: ToolSearchServiceConfig | undefined, scope: ScopeEntry);
|
|
96
|
+
/**
|
|
97
|
+
* Sets up subscription to tool changes. Handles the case where scope.tools
|
|
98
|
+
* may not be available yet during plugin initialization.
|
|
99
|
+
*/
|
|
100
|
+
private setupSubscription;
|
|
101
|
+
/**
|
|
102
|
+
* Handles tool change events by reindexing all tools from the snapshot
|
|
103
|
+
*/
|
|
104
|
+
private handleToolChange;
|
|
105
|
+
/**
|
|
106
|
+
* Determines if a tool should be indexed in the search database.
|
|
107
|
+
* Filters based on:
|
|
108
|
+
* - Excludes codecall:* meta-tools (they should not be searchable)
|
|
109
|
+
* - Mode-based filtering (codecall_only, codecall_opt_in, metadata_driven)
|
|
110
|
+
* - Per-tool metadata.codecall.enabledInCodeCall
|
|
111
|
+
* - Custom includeTools filter function
|
|
112
|
+
*/
|
|
113
|
+
private shouldIndexTool;
|
|
114
|
+
/**
|
|
115
|
+
* Extract CodeCall-specific metadata from a tool.
|
|
116
|
+
*/
|
|
117
|
+
private getCodeCallMetadata;
|
|
118
|
+
/**
|
|
119
|
+
* Initializes the search service by indexing all tools from the registry.
|
|
120
|
+
* NOTE: This method is now a no-op. Initialization is handled reactively
|
|
121
|
+
* via subscription to tool change events in the constructor.
|
|
122
|
+
* This method exists for interface compatibility.
|
|
123
|
+
*/
|
|
124
|
+
initialize(): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Cleanup subscription when service is destroyed
|
|
127
|
+
*/
|
|
128
|
+
dispose(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Extracts searchable text from a tool instance.
|
|
131
|
+
* Uses term weighting to improve relevance:
|
|
132
|
+
* - Description terms are heavily weighted (most important for semantic matching)
|
|
133
|
+
* - Tool name parts are tokenized and weighted
|
|
134
|
+
* - Tags provide additional context
|
|
135
|
+
*/
|
|
136
|
+
private extractSearchableText;
|
|
137
|
+
/**
|
|
138
|
+
* Checks if a word is a common stop word that should not receive extra weighting.
|
|
139
|
+
* Uses module-level STOP_WORDS constant to avoid recreating the Set on each call.
|
|
140
|
+
*/
|
|
141
|
+
private isStopWord;
|
|
142
|
+
/**
|
|
143
|
+
* Extracts app ID from tool's owner lineage
|
|
144
|
+
*/
|
|
145
|
+
private extractAppId;
|
|
146
|
+
/**
|
|
147
|
+
* Searches for tools matching the query
|
|
148
|
+
* Implements the ToolSearch interface
|
|
149
|
+
*/
|
|
150
|
+
search(query: string, options?: SymbolToolSearchOptions): Promise<SymbolToolSearchResult[]>;
|
|
151
|
+
/**
|
|
152
|
+
* Gets all indexed tool names
|
|
153
|
+
*/
|
|
154
|
+
getAllToolNames(): string[];
|
|
155
|
+
/**
|
|
156
|
+
* Gets the total number of indexed tools
|
|
157
|
+
*/
|
|
158
|
+
getTotalCount(): number;
|
|
159
|
+
/**
|
|
160
|
+
* Checks if a tool exists in the index
|
|
161
|
+
*/
|
|
162
|
+
hasTool(toolName: string): boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Clears the entire index
|
|
165
|
+
*/
|
|
166
|
+
clear(): void;
|
|
167
|
+
/**
|
|
168
|
+
* Get the current embedding strategy
|
|
169
|
+
*/
|
|
170
|
+
getStrategy(): EmbeddingStrategy;
|
|
171
|
+
/**
|
|
172
|
+
* Check if the service is initialized
|
|
173
|
+
*/
|
|
174
|
+
isInitialized(): boolean;
|
|
175
|
+
}
|