@frontmcp/plugins 0.6.1 → 0.6.3

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.
Files changed (121) hide show
  1. package/cache/index.js +412 -0
  2. package/codecall/index.js +2988 -0
  3. package/esm/cache/index.mjs +395 -0
  4. package/esm/codecall/index.mjs +2959 -0
  5. package/esm/index.mjs +2951 -0
  6. package/esm/package.json +82 -0
  7. package/index.js +2973 -0
  8. package/package.json +38 -10
  9. package/src/cache/README.md +0 -186
  10. package/src/cache/cache.plugin.js +0 -167
  11. package/src/cache/cache.plugin.js.map +0 -1
  12. package/src/cache/cache.symbol.js +0 -5
  13. package/src/cache/cache.symbol.js.map +0 -1
  14. package/src/cache/cache.types.js +0 -3
  15. package/src/cache/cache.types.js.map +0 -1
  16. package/src/cache/index.js +0 -8
  17. package/src/cache/index.js.map +0 -1
  18. package/src/cache/providers/cache-memory.provider.js +0 -110
  19. package/src/cache/providers/cache-memory.provider.js.map +0 -1
  20. package/src/cache/providers/cache-redis.provider.js +0 -69
  21. package/src/cache/providers/cache-redis.provider.js.map +0 -1
  22. package/src/cache/providers/cache-vercel-kv.provider.js +0 -85
  23. package/src/cache/providers/cache-vercel-kv.provider.js.map +0 -1
  24. package/src/codecall/README.md +0 -999
  25. package/src/codecall/codecall.plugin.js +0 -152
  26. package/src/codecall/codecall.plugin.js.map +0 -1
  27. package/src/codecall/codecall.symbol.js +0 -4
  28. package/src/codecall/codecall.symbol.js.map +0 -1
  29. package/src/codecall/codecall.types.js +0 -262
  30. package/src/codecall/codecall.types.js.map +0 -1
  31. package/src/codecall/errors/index.js +0 -6
  32. package/src/codecall/errors/index.js.map +0 -1
  33. package/src/codecall/errors/tool-call.errors.js +0 -119
  34. package/src/codecall/errors/tool-call.errors.js.map +0 -1
  35. package/src/codecall/index.js +0 -8
  36. package/src/codecall/index.js.map +0 -1
  37. package/src/codecall/providers/code-call.config.js +0 -120
  38. package/src/codecall/providers/code-call.config.js.map +0 -1
  39. package/src/codecall/security/index.js +0 -7
  40. package/src/codecall/security/index.js.map +0 -1
  41. package/src/codecall/security/self-reference-guard.js +0 -70
  42. package/src/codecall/security/self-reference-guard.js.map +0 -1
  43. package/src/codecall/security/tool-access-control.service.js +0 -170
  44. package/src/codecall/security/tool-access-control.service.js.map +0 -1
  45. package/src/codecall/services/audit-logger.service.js +0 -322
  46. package/src/codecall/services/audit-logger.service.js.map +0 -1
  47. package/src/codecall/services/enclave.service.js +0 -214
  48. package/src/codecall/services/enclave.service.js.map +0 -1
  49. package/src/codecall/services/error-enrichment.service.js +0 -387
  50. package/src/codecall/services/error-enrichment.service.js.map +0 -1
  51. package/src/codecall/services/index.js +0 -13
  52. package/src/codecall/services/index.js.map +0 -1
  53. package/src/codecall/services/output-sanitizer.js +0 -260
  54. package/src/codecall/services/output-sanitizer.js.map +0 -1
  55. package/src/codecall/services/synonym-expansion.service.js +0 -374
  56. package/src/codecall/services/synonym-expansion.service.js.map +0 -1
  57. package/src/codecall/services/tool-search.service.js +0 -587
  58. package/src/codecall/services/tool-search.service.js.map +0 -1
  59. package/src/codecall/tools/describe.schema.js +0 -67
  60. package/src/codecall/tools/describe.schema.js.map +0 -1
  61. package/src/codecall/tools/describe.tool.js +0 -207
  62. package/src/codecall/tools/describe.tool.js.map +0 -1
  63. package/src/codecall/tools/execute.schema.js +0 -116
  64. package/src/codecall/tools/execute.schema.js.map +0 -1
  65. package/src/codecall/tools/execute.tool.js +0 -238
  66. package/src/codecall/tools/execute.tool.js.map +0 -1
  67. package/src/codecall/tools/index.js +0 -13
  68. package/src/codecall/tools/index.js.map +0 -1
  69. package/src/codecall/tools/invoke.schema.js +0 -27
  70. package/src/codecall/tools/invoke.schema.js.map +0 -1
  71. package/src/codecall/tools/invoke.tool.js +0 -70
  72. package/src/codecall/tools/invoke.tool.js.map +0 -1
  73. package/src/codecall/tools/search.schema.js +0 -60
  74. package/src/codecall/tools/search.schema.js.map +0 -1
  75. package/src/codecall/tools/search.tool.js +0 -108
  76. package/src/codecall/tools/search.tool.js.map +0 -1
  77. package/src/codecall/utils/describe.utils.js +0 -531
  78. package/src/codecall/utils/describe.utils.js.map +0 -1
  79. package/src/codecall/utils/index.js +0 -7
  80. package/src/codecall/utils/index.js.map +0 -1
  81. package/src/codecall/utils/mcp-result.js +0 -36
  82. package/src/codecall/utils/mcp-result.js.map +0 -1
  83. package/src/index.js +0 -9
  84. package/src/index.js.map +0 -1
  85. /package/{src/cache → cache}/cache.plugin.d.ts +0 -0
  86. /package/{src/cache → cache}/cache.symbol.d.ts +0 -0
  87. /package/{src/cache → cache}/cache.types.d.ts +0 -0
  88. /package/{src/cache → cache}/index.d.ts +0 -0
  89. /package/{src/cache → cache}/providers/cache-memory.provider.d.ts +0 -0
  90. /package/{src/cache → cache}/providers/cache-redis.provider.d.ts +0 -0
  91. /package/{src/cache → cache}/providers/cache-vercel-kv.provider.d.ts +0 -0
  92. /package/{src/codecall → codecall}/codecall.plugin.d.ts +0 -0
  93. /package/{src/codecall → codecall}/codecall.symbol.d.ts +0 -0
  94. /package/{src/codecall → codecall}/codecall.types.d.ts +0 -0
  95. /package/{src/codecall → codecall}/errors/index.d.ts +0 -0
  96. /package/{src/codecall → codecall}/errors/tool-call.errors.d.ts +0 -0
  97. /package/{src/codecall → codecall}/index.d.ts +0 -0
  98. /package/{src/codecall → codecall}/providers/code-call.config.d.ts +0 -0
  99. /package/{src/codecall → codecall}/security/index.d.ts +0 -0
  100. /package/{src/codecall → codecall}/security/self-reference-guard.d.ts +0 -0
  101. /package/{src/codecall → codecall}/security/tool-access-control.service.d.ts +0 -0
  102. /package/{src/codecall → codecall}/services/audit-logger.service.d.ts +0 -0
  103. /package/{src/codecall → codecall}/services/enclave.service.d.ts +0 -0
  104. /package/{src/codecall → codecall}/services/error-enrichment.service.d.ts +0 -0
  105. /package/{src/codecall → codecall}/services/index.d.ts +0 -0
  106. /package/{src/codecall → codecall}/services/output-sanitizer.d.ts +0 -0
  107. /package/{src/codecall → codecall}/services/synonym-expansion.service.d.ts +0 -0
  108. /package/{src/codecall → codecall}/services/tool-search.service.d.ts +0 -0
  109. /package/{src/codecall → codecall}/tools/describe.schema.d.ts +0 -0
  110. /package/{src/codecall → codecall}/tools/describe.tool.d.ts +0 -0
  111. /package/{src/codecall → codecall}/tools/execute.schema.d.ts +0 -0
  112. /package/{src/codecall → codecall}/tools/execute.tool.d.ts +0 -0
  113. /package/{src/codecall → codecall}/tools/index.d.ts +0 -0
  114. /package/{src/codecall → codecall}/tools/invoke.schema.d.ts +0 -0
  115. /package/{src/codecall → codecall}/tools/invoke.tool.d.ts +0 -0
  116. /package/{src/codecall → codecall}/tools/search.schema.d.ts +0 -0
  117. /package/{src/codecall → codecall}/tools/search.tool.d.ts +0 -0
  118. /package/{src/codecall → codecall}/utils/describe.utils.d.ts +0 -0
  119. /package/{src/codecall → codecall}/utils/index.d.ts +0 -0
  120. /package/{src/codecall → codecall}/utils/mcp-result.d.ts +0 -0
  121. /package/{src/index.d.ts → index.d.ts} +0 -0
@@ -1 +0,0 @@
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,qBAA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AAM,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;YAChD,aAAa,IAAI,QAAQ,CAAC,IAAI,CAAC;QACjC,CAAC;QAED,OAAO;YACL,SAAS;YACT,kBAAkB,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"]}
@@ -1,587 +0,0 @@
1
- "use strict";
2
- // file: libs/plugins/src/codecall/services/tool-search.service.ts
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ToolSearchService = void 0;
5
- const vectoriadb_1 = require("vectoriadb");
6
- const synonym_expansion_service_1 = require("./synonym-expansion.service");
7
- /**
8
- * Universal Intent Mapping & Query Normalization
9
- * - This module defines the semantic knowledge base for the MCP tool search engine.
10
- * It is designed to bridge the gap between natural language user intents
11
- * (e.g., "fix," "chat," "buy") and technical tool definitions (e.g., "update," "post," "create").
12
- * - Key Parts:
13
- * 1. DEFAULT_SYNONYM_GROUPS: A domain-agnostic mapping of bidirectional synonyms covering
14
- * CRUD, DevOps, Financial, Social, and Lifecycle operations. This ensures that a
15
- * query for "Show me the bill" matches a tool named "get_invoice".
16
- * 2. STOP_WORDS: A curated exclusion list strictly optimized for Command-Line/Chat
17
- * interfaces. Unlike standard NLP stop lists, this PRESERVES action verbs
18
- * ("find", "start", "make") as they are critical signals of user intent in a
19
- * tool-execution context.
20
- */
21
- const STOP_WORDS = new Set([
22
- // Articles & Determiners
23
- 'the',
24
- 'a',
25
- 'an',
26
- 'this',
27
- 'that',
28
- 'these',
29
- 'those',
30
- // Prepositions
31
- 'in',
32
- 'on',
33
- 'at',
34
- 'to',
35
- 'for',
36
- 'of',
37
- 'with',
38
- 'by',
39
- 'from',
40
- 'into',
41
- 'over',
42
- 'after',
43
- 'before',
44
- 'between',
45
- 'under',
46
- 'about',
47
- 'against',
48
- 'during',
49
- 'through',
50
- // Conjunctions
51
- 'and',
52
- 'or',
53
- 'but',
54
- 'nor',
55
- 'so',
56
- 'yet',
57
- 'as',
58
- 'than',
59
- 'if',
60
- 'because',
61
- 'while',
62
- 'when',
63
- 'where',
64
- 'unless',
65
- // Pronouns (Subject/Object/Possessive)
66
- 'i',
67
- 'me',
68
- 'my',
69
- 'mine',
70
- 'myself',
71
- 'you',
72
- 'your',
73
- 'yours',
74
- 'yourself',
75
- 'he',
76
- 'him',
77
- 'his',
78
- 'himself',
79
- 'she',
80
- 'her',
81
- 'hers',
82
- 'herself',
83
- 'it',
84
- 'its',
85
- 'itself',
86
- 'we',
87
- 'us',
88
- 'our',
89
- 'ours',
90
- 'ourselves',
91
- 'they',
92
- 'them',
93
- 'their',
94
- 'theirs',
95
- 'themselves',
96
- 'who',
97
- 'whom',
98
- 'whose',
99
- 'which',
100
- 'what',
101
- // Auxiliary/Linking Verbs (State of being is usually noise, Action is signal)
102
- 'is',
103
- 'was',
104
- 'are',
105
- 'were',
106
- 'been',
107
- 'be',
108
- 'being',
109
- 'have',
110
- 'has',
111
- 'had',
112
- 'having',
113
- 'do',
114
- 'does',
115
- 'did',
116
- 'doing', // "do" is usually auxiliary ("do you have..."). "run" or "execute" is better.
117
- 'will',
118
- 'would',
119
- 'shall',
120
- 'should',
121
- 'can',
122
- 'could',
123
- 'may',
124
- 'might',
125
- 'must',
126
- // Quantifiers / Adverbs of degree
127
- 'all',
128
- 'any',
129
- 'both',
130
- 'each',
131
- 'few',
132
- 'more',
133
- 'most',
134
- 'other',
135
- 'some',
136
- 'such',
137
- 'no',
138
- 'nor',
139
- 'not',
140
- 'only',
141
- 'own',
142
- 'same',
143
- 'too',
144
- 'very',
145
- 'just',
146
- 'even',
147
- // Conversational / Chat Fillers (Common in LLM prompts)
148
- 'please',
149
- 'pls',
150
- 'plz',
151
- 'thanks',
152
- 'thank',
153
- 'thx',
154
- 'hello',
155
- 'hi',
156
- 'hey',
157
- 'ok',
158
- 'okay',
159
- 'yes',
160
- 'no',
161
- 'actually',
162
- 'basically',
163
- 'literally',
164
- 'maybe',
165
- 'perhaps',
166
- 'now',
167
- 'then',
168
- 'here',
169
- 'there',
170
- 'again',
171
- 'once',
172
- 'back', // "back" can be tricky, but usually implies direction not action
173
- // Meta/Structural words
174
- 'example',
175
- 'context',
176
- 'optionally',
177
- 'optional', // Users rarely search for "optional", they search for the thing itself.
178
- 'etc',
179
- 'ie',
180
- 'eg',
181
- ]);
182
- /**
183
- * Service that maintains a searchable index of tools from the ToolRegistry
184
- * Supports both TF-IDF (lightweight, synchronous) and ML-based (semantic) embeddings
185
- * Implements the ToolSearch interface for dependency injection
186
- */
187
- class ToolSearchService {
188
- static MAX_SUBSCRIPTION_RETRIES = 100;
189
- vectorDB;
190
- strategy;
191
- initialized = false;
192
- mlInitialized = false;
193
- subscriptionRetries = 0;
194
- config;
195
- scope;
196
- unsubscribe;
197
- synonymService = null;
198
- constructor(config = {}, scope) {
199
- this.scope = scope;
200
- const embeddingOptions = config.embeddingOptions || {
201
- strategy: 'tfidf',
202
- modelName: 'Xenova/all-MiniLM-L6-v2',
203
- cacheDir: './.cache/transformers',
204
- useHNSW: false,
205
- synonymExpansion: { enabled: true, replaceDefaults: false, maxExpansionsPerTerm: 5 },
206
- };
207
- this.strategy = config.strategy || embeddingOptions.strategy || 'tfidf';
208
- this.config = {
209
- strategy: this.strategy,
210
- embeddingOptions,
211
- defaultTopK: config.defaultTopK ?? 8,
212
- defaultSimilarityThreshold: config.defaultSimilarityThreshold ?? 0.0,
213
- mode: config.mode ?? 'codecall_only',
214
- includeTools: config.includeTools,
215
- };
216
- // Validate mode parameter at runtime
217
- const validModes = ['codecall_only', 'codecall_opt_in', 'metadata_driven'];
218
- if (!validModes.includes(this.config.mode)) {
219
- throw new Error(`Invalid CodeCall mode: ${this.config.mode}. Valid modes: ${validModes.join(', ')}`);
220
- }
221
- // Initialize the appropriate vector database
222
- if (this.strategy === 'ml') {
223
- this.vectorDB = new vectoriadb_1.VectoriaDB({
224
- modelName: embeddingOptions.modelName || 'Xenova/all-MiniLM-L6-v2',
225
- cacheDir: embeddingOptions.cacheDir || './.cache/transformers',
226
- defaultTopK: this.config.defaultTopK,
227
- defaultSimilarityThreshold: this.config.defaultSimilarityThreshold,
228
- useHNSW: embeddingOptions.useHNSW || false,
229
- });
230
- }
231
- else {
232
- this.vectorDB = new vectoriadb_1.TFIDFVectoria({
233
- defaultTopK: this.config.defaultTopK,
234
- defaultSimilarityThreshold: this.config.defaultSimilarityThreshold,
235
- });
236
- }
237
- // Initialize synonym expansion for TF-IDF strategy (ML already handles semantic similarity)
238
- if (config.synonymExpansion === false) {
239
- this.synonymService = null;
240
- }
241
- else if (this.strategy === 'tfidf') {
242
- const synonymConfig = typeof config.synonymExpansion === 'object' ? config.synonymExpansion : {};
243
- // Only enable if not explicitly disabled
244
- if (synonymConfig.enabled !== false) {
245
- this.synonymService = new synonym_expansion_service_1.SynonymExpansionService(synonymConfig);
246
- }
247
- }
248
- // Defer subscription until scope.tools is available
249
- // During plugin initialization, scope.tools may not exist yet
250
- this.setupSubscription();
251
- }
252
- /**
253
- * Sets up subscription to tool changes. Handles the case where scope.tools
254
- * may not be available yet during plugin initialization.
255
- */
256
- setupSubscription() {
257
- // If tools registry is not yet available, retry after a microtask
258
- if (!this.scope.tools) {
259
- if (this.subscriptionRetries++ >= ToolSearchService.MAX_SUBSCRIPTION_RETRIES) {
260
- console.warn('ToolSearchService: scope.tools not available after max retries');
261
- return;
262
- }
263
- // Use queueMicrotask to defer until after current initialization
264
- queueMicrotask(() => this.setupSubscription());
265
- return;
266
- }
267
- // Reset retry counter on success
268
- this.subscriptionRetries = 0;
269
- // Subscribe to tool changes with immediate=true to get current snapshot
270
- // This ensures tools are indexed as they become available, regardless of loading order
271
- this.unsubscribe = this.scope.tools.subscribe({ immediate: true }, (event) => {
272
- // Handle tool change event - reindex all tools from the snapshot
273
- this.handleToolChange(event.snapshot);
274
- });
275
- }
276
- /**
277
- * Handles tool change events by reindexing all tools from the snapshot
278
- */
279
- async handleToolChange(tools) {
280
- // Clear and rebuild index
281
- this.vectorDB.clear();
282
- if (tools.length === 0) {
283
- this.initialized = true;
284
- return;
285
- }
286
- // Initialize ML model if needed (first time only, and only when we have tools)
287
- // Deferred initialization avoids async operations when there's nothing to index
288
- if (!this.mlInitialized && this.strategy === 'ml' && this.vectorDB instanceof vectoriadb_1.VectoriaDB) {
289
- await this.vectorDB.initialize();
290
- this.mlInitialized = true;
291
- }
292
- // Filter tools based on CodeCall config and per-tool metadata
293
- const filteredTools = tools.filter((tool) => this.shouldIndexTool(tool));
294
- if (filteredTools.length === 0) {
295
- this.initialized = true;
296
- return;
297
- }
298
- const documents = filteredTools.map((tool) => {
299
- const searchableText = this.extractSearchableText(tool);
300
- const appId = this.extractAppId(tool);
301
- const toolName = tool.name;
302
- const qualifiedName = tool.fullName || toolName;
303
- return {
304
- id: toolName,
305
- text: searchableText,
306
- metadata: {
307
- id: toolName,
308
- toolName,
309
- qualifiedName,
310
- appId,
311
- toolInstance: tool,
312
- },
313
- };
314
- });
315
- if (this.strategy === 'ml' && this.vectorDB instanceof vectoriadb_1.VectoriaDB) {
316
- await this.vectorDB.addMany(documents);
317
- }
318
- else if (this.vectorDB instanceof vectoriadb_1.TFIDFVectoria) {
319
- this.vectorDB.addDocuments(documents);
320
- this.vectorDB.reindex();
321
- }
322
- this.initialized = true;
323
- }
324
- /**
325
- * Determines if a tool should be indexed in the search database.
326
- * Filters based on:
327
- * - Excludes codecall:* meta-tools (they should not be searchable)
328
- * - Mode-based filtering (codecall_only, codecall_opt_in, metadata_driven)
329
- * - Per-tool metadata.codecall.enabledInCodeCall
330
- * - Custom includeTools filter function
331
- */
332
- shouldIndexTool(tool) {
333
- const toolName = tool.name || tool.fullName;
334
- // Never index codecall:* meta-tools - they are for orchestration, not for search
335
- if (toolName.startsWith('codecall:')) {
336
- return false;
337
- }
338
- // Get CodeCall-specific metadata from the tool
339
- const codecallMeta = this.getCodeCallMetadata(tool);
340
- // Apply mode-based filtering
341
- switch (this.config.mode) {
342
- case 'codecall_only':
343
- // In codecall_only mode, all non-codecall tools are searchable
344
- // unless explicitly disabled via metadata
345
- if (codecallMeta?.enabledInCodeCall === false) {
346
- return false;
347
- }
348
- break;
349
- case 'codecall_opt_in':
350
- // In opt_in mode, tools must explicitly opt-in via metadata
351
- if (codecallMeta?.enabledInCodeCall !== true) {
352
- return false;
353
- }
354
- break;
355
- case 'metadata_driven':
356
- // In metadata_driven mode, default to enabled unless explicitly disabled
357
- if (codecallMeta?.enabledInCodeCall === false) {
358
- return false;
359
- }
360
- break;
361
- default:
362
- // This should never happen due to constructor validation
363
- // but provides defense-in-depth and satisfies exhaustive checking
364
- throw new Error(`Unknown CodeCall mode: ${this.config.mode}`);
365
- }
366
- // Apply custom includeTools filter if provided
367
- if (this.config.includeTools) {
368
- const appId = this.extractAppId(tool);
369
- const filterInfo = {
370
- name: toolName,
371
- appId,
372
- source: codecallMeta?.source,
373
- description: tool.metadata.description,
374
- tags: codecallMeta?.tags || tool.metadata.tags,
375
- };
376
- if (!this.config.includeTools(filterInfo)) {
377
- return false;
378
- }
379
- }
380
- return true;
381
- }
382
- /**
383
- * Extract CodeCall-specific metadata from a tool.
384
- */
385
- getCodeCallMetadata(tool) {
386
- // NOTE: `any` cast is intentional - ToolMetadata has constrained generics
387
- return tool.metadata?.codecall;
388
- }
389
- /**
390
- * Initializes the search service by indexing all tools from the registry.
391
- * NOTE: This method is now a no-op. Initialization is handled reactively
392
- * via subscription to tool change events in the constructor.
393
- * This method exists for interface compatibility.
394
- */
395
- async initialize() {
396
- // Initialization is now handled reactively via subscription
397
- // The subscription with immediate=true in the constructor ensures tools are indexed
398
- // This method exists for interface compatibility
399
- }
400
- /**
401
- * Cleanup subscription when service is destroyed
402
- */
403
- dispose() {
404
- if (this.unsubscribe) {
405
- this.unsubscribe();
406
- this.unsubscribe = undefined;
407
- }
408
- }
409
- /**
410
- * Extracts searchable text from a tool instance.
411
- * Uses term weighting to improve relevance:
412
- * - Description terms are heavily weighted (most important for semantic matching)
413
- * - Tool name parts are tokenized and weighted
414
- * - Tags provide additional context
415
- */
416
- extractSearchableText(tool) {
417
- const parts = [];
418
- // Extract and weight tool name parts
419
- // Split on common delimiters (: - _ .) to get meaningful tokens
420
- if (tool.name) {
421
- const nameParts = tool.name.split(/[:\-_.]/).filter(Boolean);
422
- // Add each part twice for moderate weighting
423
- for (const part of nameParts) {
424
- parts.push(part, part);
425
- }
426
- }
427
- // Description is the most important for semantic matching
428
- // Weight it heavily by repeating 3x
429
- if (tool.metadata.description) {
430
- const description = tool.metadata.description;
431
- parts.push(description, description, description);
432
- // Also extract key terms from description (words 4+ chars) for extra weight
433
- const keyTerms = description
434
- .toLowerCase()
435
- .split(/\s+/)
436
- .filter((word) => word.length >= 4 && !this.isStopWord(word));
437
- parts.push(...keyTerms);
438
- }
439
- // Add tags with moderate weight (2x)
440
- if (tool.metadata.tags && tool.metadata.tags.length > 0) {
441
- for (const tag of tool.metadata.tags) {
442
- parts.push(tag, tag);
443
- }
444
- }
445
- // Add input schema property names (useful for parameter-based searches)
446
- if (tool.rawInputSchema && typeof tool.rawInputSchema === 'object') {
447
- const schema = tool.rawInputSchema;
448
- if (schema.properties) {
449
- parts.push(...Object.keys(schema.properties));
450
- }
451
- }
452
- // Add example descriptions and input values to searchable text
453
- // Examples help users find tools by use-case descriptions
454
- const examples = tool.metadata?.examples;
455
- if (examples && Array.isArray(examples)) {
456
- for (const ex of examples) {
457
- // Add example description (2x weight for relevance)
458
- if (ex.description) {
459
- parts.push(ex.description, ex.description);
460
- }
461
- // Add example input keys and string values
462
- if (ex.input && typeof ex.input === 'object') {
463
- for (const [key, value] of Object.entries(ex.input)) {
464
- parts.push(key);
465
- if (typeof value === 'string') {
466
- parts.push(value);
467
- }
468
- }
469
- }
470
- }
471
- }
472
- return parts.join(' ');
473
- }
474
- /**
475
- * Checks if a word is a common stop word that should not receive extra weighting.
476
- * Uses module-level STOP_WORDS constant to avoid recreating the Set on each call.
477
- */
478
- isStopWord(word) {
479
- return STOP_WORDS.has(word);
480
- }
481
- /**
482
- * Extracts app ID from tool's owner lineage
483
- */
484
- extractAppId(tool) {
485
- if (!tool.owner)
486
- return undefined;
487
- // The owner structure has kind and id
488
- if (tool.owner.kind === 'app') {
489
- return tool.owner.id;
490
- }
491
- // If the tool is owned by a plugin, we need to look at its parent scope
492
- // For now, we'll return undefined and rely on the lineage if needed
493
- return undefined;
494
- }
495
- /**
496
- * Searches for tools matching the query
497
- * Implements the ToolSearch interface
498
- */
499
- async search(query, options = {}) {
500
- const { topK = this.config.defaultTopK, appIds, excludeToolNames = [] } = options;
501
- const minScore = this.config.defaultSimilarityThreshold;
502
- // Build filter function
503
- const filter = (metadata) => {
504
- // Exclude tools
505
- if (excludeToolNames.includes(metadata.toolName)) {
506
- return false;
507
- }
508
- // Filter by appId if specified
509
- if (appIds && appIds.length > 0) {
510
- if (!metadata.appId || !appIds.includes(metadata.appId)) {
511
- return false;
512
- }
513
- }
514
- return true;
515
- };
516
- // Expand query with synonyms for TF-IDF strategy to improve relevance
517
- // For example: "add user" -> "add create new insert make user account member profile"
518
- const effectiveQuery = this.synonymService ? this.synonymService.expandQuery(query) : query;
519
- // Search using vectoriadb
520
- const results = await this.vectorDB.search(effectiveQuery, {
521
- topK,
522
- threshold: minScore,
523
- filter,
524
- });
525
- // Transform results to match the ToolSearch interface
526
- return results.map((result) => ({
527
- toolName: result.metadata.toolName,
528
- appId: result.metadata.appId,
529
- description: result.metadata.toolInstance.metadata.description || '',
530
- relevanceScore: result.score,
531
- }));
532
- }
533
- /**
534
- * Gets all indexed tool names
535
- */
536
- getAllToolNames() {
537
- if (this.vectorDB instanceof vectoriadb_1.VectoriaDB) {
538
- return this.vectorDB.getAll().map((doc) => doc.id);
539
- }
540
- else {
541
- return this.vectorDB.getAllDocumentIds();
542
- }
543
- }
544
- /**
545
- * Gets the total number of indexed tools
546
- */
547
- getTotalCount() {
548
- if (this.vectorDB instanceof vectoriadb_1.VectoriaDB) {
549
- return this.vectorDB.size();
550
- }
551
- else {
552
- return this.vectorDB.getDocumentCount();
553
- }
554
- }
555
- /**
556
- * Checks if a tool exists in the index
557
- */
558
- hasTool(toolName) {
559
- if (this.vectorDB instanceof vectoriadb_1.VectoriaDB) {
560
- return this.vectorDB.has(toolName);
561
- }
562
- else {
563
- return this.vectorDB.hasDocument(toolName);
564
- }
565
- }
566
- /**
567
- * Clears the entire index
568
- */
569
- clear() {
570
- this.vectorDB.clear();
571
- this.initialized = false;
572
- }
573
- /**
574
- * Get the current embedding strategy
575
- */
576
- getStrategy() {
577
- return this.strategy;
578
- }
579
- /**
580
- * Check if the service is initialized
581
- */
582
- isInitialized() {
583
- return this.initialized;
584
- }
585
- }
586
- exports.ToolSearchService = ToolSearchService;
587
- //# sourceMappingURL=tool-search.service.js.map