@frontmcp/plugins 0.6.0 → 0.6.2

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 (119) hide show
  1. package/{src/cache → cache}/cache.types.d.ts +26 -3
  2. package/cache/index.js +412 -0
  3. package/{src/cache → cache}/providers/cache-memory.provider.d.ts +3 -3
  4. package/{src/cache → cache}/providers/cache-redis.provider.d.ts +3 -3
  5. package/cache/providers/cache-vercel-kv.provider.d.ts +24 -0
  6. package/codecall/index.js +2988 -0
  7. package/{src/codecall → codecall}/tools/invoke.schema.d.ts +6 -1
  8. package/esm/cache/index.mjs +395 -0
  9. package/esm/codecall/index.mjs +2959 -0
  10. package/esm/index.mjs +2951 -0
  11. package/esm/package.json +85 -0
  12. package/index.js +2973 -0
  13. package/package.json +49 -10
  14. package/src/cache/README.md +0 -186
  15. package/src/cache/cache.plugin.js +0 -135
  16. package/src/cache/cache.plugin.js.map +0 -1
  17. package/src/cache/cache.symbol.js +0 -5
  18. package/src/cache/cache.symbol.js.map +0 -1
  19. package/src/cache/cache.types.js +0 -3
  20. package/src/cache/cache.types.js.map +0 -1
  21. package/src/cache/index.js +0 -8
  22. package/src/cache/index.js.map +0 -1
  23. package/src/cache/providers/cache-memory.provider.js +0 -110
  24. package/src/cache/providers/cache-memory.provider.js.map +0 -1
  25. package/src/cache/providers/cache-redis.provider.js +0 -69
  26. package/src/cache/providers/cache-redis.provider.js.map +0 -1
  27. package/src/codecall/README.md +0 -999
  28. package/src/codecall/codecall.plugin.js +0 -152
  29. package/src/codecall/codecall.plugin.js.map +0 -1
  30. package/src/codecall/codecall.symbol.js +0 -4
  31. package/src/codecall/codecall.symbol.js.map +0 -1
  32. package/src/codecall/codecall.types.js +0 -262
  33. package/src/codecall/codecall.types.js.map +0 -1
  34. package/src/codecall/errors/index.js +0 -6
  35. package/src/codecall/errors/index.js.map +0 -1
  36. package/src/codecall/errors/tool-call.errors.js +0 -119
  37. package/src/codecall/errors/tool-call.errors.js.map +0 -1
  38. package/src/codecall/index.js +0 -8
  39. package/src/codecall/index.js.map +0 -1
  40. package/src/codecall/providers/code-call.config.js +0 -120
  41. package/src/codecall/providers/code-call.config.js.map +0 -1
  42. package/src/codecall/security/index.js +0 -7
  43. package/src/codecall/security/index.js.map +0 -1
  44. package/src/codecall/security/self-reference-guard.js +0 -70
  45. package/src/codecall/security/self-reference-guard.js.map +0 -1
  46. package/src/codecall/security/tool-access-control.service.js +0 -170
  47. package/src/codecall/security/tool-access-control.service.js.map +0 -1
  48. package/src/codecall/services/audit-logger.service.js +0 -322
  49. package/src/codecall/services/audit-logger.service.js.map +0 -1
  50. package/src/codecall/services/enclave.service.js +0 -214
  51. package/src/codecall/services/enclave.service.js.map +0 -1
  52. package/src/codecall/services/error-enrichment.service.js +0 -387
  53. package/src/codecall/services/error-enrichment.service.js.map +0 -1
  54. package/src/codecall/services/index.js +0 -13
  55. package/src/codecall/services/index.js.map +0 -1
  56. package/src/codecall/services/output-sanitizer.js +0 -260
  57. package/src/codecall/services/output-sanitizer.js.map +0 -1
  58. package/src/codecall/services/synonym-expansion.service.js +0 -374
  59. package/src/codecall/services/synonym-expansion.service.js.map +0 -1
  60. package/src/codecall/services/tool-search.service.js +0 -587
  61. package/src/codecall/services/tool-search.service.js.map +0 -1
  62. package/src/codecall/tools/describe.schema.js +0 -67
  63. package/src/codecall/tools/describe.schema.js.map +0 -1
  64. package/src/codecall/tools/describe.tool.js +0 -207
  65. package/src/codecall/tools/describe.tool.js.map +0 -1
  66. package/src/codecall/tools/execute.schema.js +0 -116
  67. package/src/codecall/tools/execute.schema.js.map +0 -1
  68. package/src/codecall/tools/execute.tool.js +0 -238
  69. package/src/codecall/tools/execute.tool.js.map +0 -1
  70. package/src/codecall/tools/index.js +0 -13
  71. package/src/codecall/tools/index.js.map +0 -1
  72. package/src/codecall/tools/invoke.schema.js +0 -27
  73. package/src/codecall/tools/invoke.schema.js.map +0 -1
  74. package/src/codecall/tools/invoke.tool.js +0 -70
  75. package/src/codecall/tools/invoke.tool.js.map +0 -1
  76. package/src/codecall/tools/search.schema.js +0 -60
  77. package/src/codecall/tools/search.schema.js.map +0 -1
  78. package/src/codecall/tools/search.tool.js +0 -108
  79. package/src/codecall/tools/search.tool.js.map +0 -1
  80. package/src/codecall/utils/describe.utils.js +0 -531
  81. package/src/codecall/utils/describe.utils.js.map +0 -1
  82. package/src/codecall/utils/index.js +0 -7
  83. package/src/codecall/utils/index.js.map +0 -1
  84. package/src/codecall/utils/mcp-result.js +0 -36
  85. package/src/codecall/utils/mcp-result.js.map +0 -1
  86. package/src/index.js +0 -9
  87. package/src/index.js.map +0 -1
  88. /package/{src/cache → cache}/cache.plugin.d.ts +0 -0
  89. /package/{src/cache → cache}/cache.symbol.d.ts +0 -0
  90. /package/{src/cache → cache}/index.d.ts +0 -0
  91. /package/{src/codecall → codecall}/codecall.plugin.d.ts +0 -0
  92. /package/{src/codecall → codecall}/codecall.symbol.d.ts +0 -0
  93. /package/{src/codecall → codecall}/codecall.types.d.ts +0 -0
  94. /package/{src/codecall → codecall}/errors/index.d.ts +0 -0
  95. /package/{src/codecall → codecall}/errors/tool-call.errors.d.ts +0 -0
  96. /package/{src/codecall → codecall}/index.d.ts +0 -0
  97. /package/{src/codecall → codecall}/providers/code-call.config.d.ts +0 -0
  98. /package/{src/codecall → codecall}/security/index.d.ts +0 -0
  99. /package/{src/codecall → codecall}/security/self-reference-guard.d.ts +0 -0
  100. /package/{src/codecall → codecall}/security/tool-access-control.service.d.ts +0 -0
  101. /package/{src/codecall → codecall}/services/audit-logger.service.d.ts +0 -0
  102. /package/{src/codecall → codecall}/services/enclave.service.d.ts +0 -0
  103. /package/{src/codecall → codecall}/services/error-enrichment.service.d.ts +0 -0
  104. /package/{src/codecall → codecall}/services/index.d.ts +0 -0
  105. /package/{src/codecall → codecall}/services/output-sanitizer.d.ts +0 -0
  106. /package/{src/codecall → codecall}/services/synonym-expansion.service.d.ts +0 -0
  107. /package/{src/codecall → codecall}/services/tool-search.service.d.ts +0 -0
  108. /package/{src/codecall → codecall}/tools/describe.schema.d.ts +0 -0
  109. /package/{src/codecall → codecall}/tools/describe.tool.d.ts +0 -0
  110. /package/{src/codecall → codecall}/tools/execute.schema.d.ts +0 -0
  111. /package/{src/codecall → codecall}/tools/execute.tool.d.ts +0 -0
  112. /package/{src/codecall → codecall}/tools/index.d.ts +0 -0
  113. /package/{src/codecall → codecall}/tools/invoke.tool.d.ts +0 -0
  114. /package/{src/codecall → codecall}/tools/search.schema.d.ts +0 -0
  115. /package/{src/codecall → codecall}/tools/search.tool.d.ts +0 -0
  116. /package/{src/codecall → codecall}/utils/describe.utils.d.ts +0 -0
  117. /package/{src/codecall → codecall}/utils/index.d.ts +0 -0
  118. /package/{src/codecall → codecall}/utils/mcp-result.d.ts +0 -0
  119. /package/{src/index.d.ts → index.d.ts} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-search.service.js","sourceRoot":"","sources":["../../../../src/codecall/services/tool-search.service.ts"],"names":[],"mappings":";AAAA,kEAAkE;;;AAGlE,2CAAyE;AAYzE,2EAA8F;AAE9F;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAC;IAC9C,yBAAyB;IACzB,KAAK;IACL,GAAG;IACH,IAAI;IACJ,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IAEP,eAAe;IACf,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,MAAM;IACN,IAAI;IACJ,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,QAAQ;IACR,SAAS;IACT,OAAO;IACP,OAAO;IACP,SAAS;IACT,QAAQ;IACR,SAAS;IAET,eAAe;IACf,KAAK;IACL,IAAI;IACJ,KAAK;IACL,KAAK;IACL,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,MAAM;IACN,IAAI;IACJ,SAAS;IACT,OAAO;IACP,MAAM;IACN,OAA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["// file: libs/plugins/src/codecall/services/tool-search.service.ts\n\nimport { ToolEntry, ScopeEntry } from '@frontmcp/sdk';\nimport { TFIDFVectoria, VectoriaDB, DocumentMetadata } from 'vectoriadb';\nimport type {\n EmbeddingStrategy,\n CodeCallEmbeddingOptions,\n CodeCallMode,\n CodeCallToolMetadata,\n} from '../codecall.types';\nimport type {\n ToolSearch,\n ToolSearchResult as SymbolToolSearchResult,\n ToolSearchOptions as SymbolToolSearchOptions,\n} from '../codecall.symbol';\nimport { SynonymExpansionService, SynonymExpansionConfig } from './synonym-expansion.service';\n\n/**\n * Universal Intent Mapping & Query Normalization\n * - This module defines the semantic knowledge base for the MCP tool search engine.\n * It is designed to bridge the gap between natural language user intents\n * (e.g., \"fix,\" \"chat,\" \"buy\") and technical tool definitions (e.g., \"update,\" \"post,\" \"create\").\n * - Key Parts:\n * 1. DEFAULT_SYNONYM_GROUPS: A domain-agnostic mapping of bidirectional synonyms covering\n * CRUD, DevOps, Financial, Social, and Lifecycle operations. This ensures that a\n * query for \"Show me the bill\" matches a tool named \"get_invoice\".\n * 2. STOP_WORDS: A curated exclusion list strictly optimized for Command-Line/Chat\n * interfaces. Unlike standard NLP stop lists, this PRESERVES action verbs\n * (\"find\", \"start\", \"make\") as they are critical signals of user intent in a\n * tool-execution context.\n */\nconst STOP_WORDS: ReadonlySet<string> = new Set([\n // Articles & Determiners\n 'the',\n 'a',\n 'an',\n 'this',\n 'that',\n 'these',\n 'those',\n\n // Prepositions\n 'in',\n 'on',\n 'at',\n 'to',\n 'for',\n 'of',\n 'with',\n 'by',\n 'from',\n 'into',\n 'over',\n 'after',\n 'before',\n 'between',\n 'under',\n 'about',\n 'against',\n 'during',\n 'through',\n\n // Conjunctions\n 'and',\n 'or',\n 'but',\n 'nor',\n 'so',\n 'yet',\n 'as',\n 'than',\n 'if',\n 'because',\n 'while',\n 'when',\n 'where',\n 'unless',\n\n // Pronouns (Subject/Object/Possessive)\n 'i',\n 'me',\n 'my',\n 'mine',\n 'myself',\n 'you',\n 'your',\n 'yours',\n 'yourself',\n 'he',\n 'him',\n 'his',\n 'himself',\n 'she',\n 'her',\n 'hers',\n 'herself',\n 'it',\n 'its',\n 'itself',\n 'we',\n 'us',\n 'our',\n 'ours',\n 'ourselves',\n 'they',\n 'them',\n 'their',\n 'theirs',\n 'themselves',\n 'who',\n 'whom',\n 'whose',\n 'which',\n 'what',\n\n // Auxiliary/Linking Verbs (State of being is usually noise, Action is signal)\n 'is',\n 'was',\n 'are',\n 'were',\n 'been',\n 'be',\n 'being',\n 'have',\n 'has',\n 'had',\n 'having',\n 'do',\n 'does',\n 'did',\n 'doing', // \"do\" is usually auxiliary (\"do you have...\"). \"run\" or \"execute\" is better.\n 'will',\n 'would',\n 'shall',\n 'should',\n 'can',\n 'could',\n 'may',\n 'might',\n 'must',\n\n // Quantifiers / Adverbs of degree\n 'all',\n 'any',\n 'both',\n 'each',\n 'few',\n 'more',\n 'most',\n 'other',\n 'some',\n 'such',\n 'no',\n 'nor',\n 'not',\n 'only',\n 'own',\n 'same',\n 'too',\n 'very',\n 'just',\n 'even',\n\n // Conversational / Chat Fillers (Common in LLM prompts)\n 'please',\n 'pls',\n 'plz',\n 'thanks',\n 'thank',\n 'thx',\n 'hello',\n 'hi',\n 'hey',\n 'ok',\n 'okay',\n 'yes',\n 'no',\n 'actually',\n 'basically',\n 'literally',\n 'maybe',\n 'perhaps',\n 'now',\n 'then',\n 'here',\n 'there',\n 'again',\n 'once',\n 'back', // \"back\" can be tricky, but usually implies direction not action\n\n // Meta/Structural words\n 'example',\n 'context',\n 'optionally',\n 'optional', // Users rarely search for \"optional\", they search for the thing itself.\n 'etc',\n 'ie',\n 'eg',\n]);\n/**\n * Metadata structure for tool documents in the vector database\n */\n// NOTE: `any` is intentional - ToolEntry has constrained generics that don't work with `unknown`\ninterface ToolMetadata extends DocumentMetadata {\n id: string;\n toolName: string;\n qualifiedName: string;\n appId?: string;\n toolInstance: ToolEntry<any, any>;\n}\n\n/**\n * Search result for tool search\n */\n// NOTE: `any` is intentional - ToolEntry has constrained generics that don't work with `unknown`\nexport interface SearchResult {\n tool: ToolEntry<any, any>;\n score: number;\n toolName: string;\n qualifiedName: string;\n appId?: string;\n}\n\n/**\n * Search options for tool search\n */\nexport interface SearchOptions {\n topK?: number;\n appIds?: string[];\n excludeToolNames?: string[];\n minScore?: number;\n}\n\n/**\n * Filter function type for including tools\n */\nexport type IncludeToolsFilter = (info: {\n name: string;\n appId?: string;\n source?: string;\n description?: string;\n tags?: string[];\n}) => boolean;\n\n/**\n * Configuration for tool search service\n */\nexport interface ToolSearchServiceConfig {\n /**\n * Embedding strategy to use\n * @default 'tfidf'\n */\n strategy?: EmbeddingStrategy;\n\n /**\n * Full embedding options (alternative to just strategy)\n */\n embeddingOptions?: CodeCallEmbeddingOptions;\n\n /**\n * Default number of results to return\n * @default 8\n */\n defaultTopK?: number;\n\n /**\n * Default similarity threshold\n * @default 0.0\n */\n defaultSimilarityThreshold?: number;\n\n /**\n * CodeCall mode for filtering tools\n * @default 'codecall_only'\n */\n mode?: CodeCallMode;\n\n /**\n * Optional filter function for including tools in the search index\n */\n includeTools?: IncludeToolsFilter;\n\n /**\n * Synonym expansion configuration.\n * When enabled, queries are expanded with synonyms to improve search relevance.\n * For example, \"add user\" will also match tools containing \"create user\".\n * Only applies when strategy is 'tfidf' (ML already handles semantic similarity).\n *\n * Set to false to disable, or provide a config object to customize.\n * @default { enabled: true } when strategy is 'tfidf'\n */\n synonymExpansion?: false | (SynonymExpansionConfig & { enabled?: boolean });\n}\n\n/**\n * Service that maintains a searchable index of tools from the ToolRegistry\n * Supports both TF-IDF (lightweight, synchronous) and ML-based (semantic) embeddings\n * Implements the ToolSearch interface for dependency injection\n */\nexport class ToolSearchService implements ToolSearch {\n private static readonly MAX_SUBSCRIPTION_RETRIES = 100;\n private vectorDB: TFIDFVectoria<ToolMetadata> | VectoriaDB<ToolMetadata>;\n private strategy: EmbeddingStrategy;\n private initialized = false;\n private mlInitialized = false;\n private subscriptionRetries = 0;\n private config: Required<Omit<ToolSearchServiceConfig, 'includeTools' | 'mode' | 'synonymExpansion'>> & {\n mode: CodeCallMode;\n includeTools?: IncludeToolsFilter;\n };\n private scope: ScopeEntry;\n private unsubscribe?: () => void;\n private synonymService: SynonymExpansionService | null = null;\n\n constructor(config: ToolSearchServiceConfig = {}, scope: ScopeEntry) {\n this.scope = scope;\n const embeddingOptions: CodeCallEmbeddingOptions = config.embeddingOptions || {\n strategy: 'tfidf',\n modelName: 'Xenova/all-MiniLM-L6-v2',\n cacheDir: './.cache/transformers',\n useHNSW: false,\n synonymExpansion: { enabled: true, replaceDefaults: false, maxExpansionsPerTerm: 5 },\n };\n this.strategy = config.strategy || embeddingOptions.strategy || 'tfidf';\n\n this.config = {\n strategy: this.strategy,\n embeddingOptions,\n defaultTopK: config.defaultTopK ?? 8,\n defaultSimilarityThreshold: config.defaultSimilarityThreshold ?? 0.0,\n mode: config.mode ?? 'codecall_only',\n includeTools: config.includeTools,\n };\n\n // Validate mode parameter at runtime\n const validModes = ['codecall_only', 'codecall_opt_in', 'metadata_driven'] as const;\n if (!validModes.includes(this.config.mode as (typeof validModes)[number])) {\n throw new Error(`Invalid CodeCall mode: ${this.config.mode}. Valid modes: ${validModes.join(', ')}`);\n }\n\n // Initialize the appropriate vector database\n if (this.strategy === 'ml') {\n this.vectorDB = new VectoriaDB<ToolMetadata>({\n modelName: embeddingOptions.modelName || 'Xenova/all-MiniLM-L6-v2',\n cacheDir: embeddingOptions.cacheDir || './.cache/transformers',\n defaultTopK: this.config.defaultTopK,\n defaultSimilarityThreshold: this.config.defaultSimilarityThreshold,\n useHNSW: embeddingOptions.useHNSW || false,\n });\n } else {\n this.vectorDB = new TFIDFVectoria<ToolMetadata>({\n defaultTopK: this.config.defaultTopK,\n defaultSimilarityThreshold: this.config.defaultSimilarityThreshold,\n });\n }\n\n // Initialize synonym expansion for TF-IDF strategy (ML already handles semantic similarity)\n if (config.synonymExpansion === false) {\n this.synonymService = null;\n } else if (this.strategy === 'tfidf') {\n const synonymConfig = typeof config.synonymExpansion === 'object' ? config.synonymExpansion : {};\n // Only enable if not explicitly disabled\n if (synonymConfig.enabled !== false) {\n this.synonymService = new SynonymExpansionService(synonymConfig);\n }\n }\n\n // Defer subscription until scope.tools is available\n // During plugin initialization, scope.tools may not exist yet\n this.setupSubscription();\n }\n\n /**\n * Sets up subscription to tool changes. Handles the case where scope.tools\n * may not be available yet during plugin initialization.\n */\n private setupSubscription(): void {\n // If tools registry is not yet available, retry after a microtask\n if (!this.scope.tools) {\n if (this.subscriptionRetries++ >= ToolSearchService.MAX_SUBSCRIPTION_RETRIES) {\n console.warn('ToolSearchService: scope.tools not available after max retries');\n return;\n }\n // Use queueMicrotask to defer until after current initialization\n queueMicrotask(() => this.setupSubscription());\n return;\n }\n // Reset retry counter on success\n this.subscriptionRetries = 0;\n\n // Subscribe to tool changes with immediate=true to get current snapshot\n // This ensures tools are indexed as they become available, regardless of loading order\n this.unsubscribe = this.scope.tools.subscribe({ immediate: true }, (event) => {\n // Handle tool change event - reindex all tools from the snapshot\n this.handleToolChange(event.snapshot as unknown as ToolEntry<any, any>[]);\n });\n }\n\n /**\n * Handles tool change events by reindexing all tools from the snapshot\n */\n private async handleToolChange(tools: ToolEntry<any, any>[]): Promise<void> {\n // Clear and rebuild index\n this.vectorDB.clear();\n\n if (tools.length === 0) {\n this.initialized = true;\n return;\n }\n\n // Initialize ML model if needed (first time only, and only when we have tools)\n // Deferred initialization avoids async operations when there's nothing to index\n if (!this.mlInitialized && this.strategy === 'ml' && this.vectorDB instanceof VectoriaDB) {\n await this.vectorDB.initialize();\n this.mlInitialized = true;\n }\n\n // Filter tools based on CodeCall config and per-tool metadata\n const filteredTools = tools.filter((tool) => this.shouldIndexTool(tool));\n\n if (filteredTools.length === 0) {\n this.initialized = true;\n return;\n }\n\n const documents = filteredTools.map((tool) => {\n const searchableText = this.extractSearchableText(tool);\n const appId = this.extractAppId(tool);\n const toolName = tool.name;\n const qualifiedName = tool.fullName || toolName;\n\n return {\n id: toolName,\n text: searchableText,\n metadata: {\n id: toolName,\n toolName,\n qualifiedName,\n appId,\n toolInstance: tool,\n },\n };\n });\n\n if (this.strategy === 'ml' && this.vectorDB instanceof VectoriaDB) {\n await this.vectorDB.addMany(documents);\n } else if (this.vectorDB instanceof TFIDFVectoria) {\n this.vectorDB.addDocuments(documents);\n this.vectorDB.reindex();\n }\n\n this.initialized = true;\n }\n\n /**\n * Determines if a tool should be indexed in the search database.\n * Filters based on:\n * - Excludes codecall:* meta-tools (they should not be searchable)\n * - Mode-based filtering (codecall_only, codecall_opt_in, metadata_driven)\n * - Per-tool metadata.codecall.enabledInCodeCall\n * - Custom includeTools filter function\n */\n private shouldIndexTool(tool: ToolEntry<any, any>): boolean {\n const toolName = tool.name || tool.fullName;\n\n // Never index codecall:* meta-tools - they are for orchestration, not for search\n if (toolName.startsWith('codecall:')) {\n return false;\n }\n\n // Get CodeCall-specific metadata from the tool\n const codecallMeta = this.getCodeCallMetadata(tool);\n\n // Apply mode-based filtering\n switch (this.config.mode) {\n case 'codecall_only':\n // In codecall_only mode, all non-codecall tools are searchable\n // unless explicitly disabled via metadata\n if (codecallMeta?.enabledInCodeCall === false) {\n return false;\n }\n break;\n\n case 'codecall_opt_in':\n // In opt_in mode, tools must explicitly opt-in via metadata\n if (codecallMeta?.enabledInCodeCall !== true) {\n return false;\n }\n break;\n\n case 'metadata_driven':\n // In metadata_driven mode, default to enabled unless explicitly disabled\n if (codecallMeta?.enabledInCodeCall === false) {\n return false;\n }\n break;\n\n default:\n // This should never happen due to constructor validation\n // but provides defense-in-depth and satisfies exhaustive checking\n throw new Error(`Unknown CodeCall mode: ${this.config.mode}`);\n }\n\n // Apply custom includeTools filter if provided\n if (this.config.includeTools) {\n const appId = this.extractAppId(tool);\n const filterInfo = {\n name: toolName,\n appId,\n source: codecallMeta?.source,\n description: tool.metadata.description,\n tags: codecallMeta?.tags || tool.metadata.tags,\n };\n\n if (!this.config.includeTools(filterInfo)) {\n return false;\n }\n }\n\n return true;\n }\n\n /**\n * Extract CodeCall-specific metadata from a tool.\n */\n private getCodeCallMetadata(tool: ToolEntry<any, any>): CodeCallToolMetadata | undefined {\n // NOTE: `any` cast is intentional - ToolMetadata has constrained generics\n return (tool.metadata as any)?.codecall as CodeCallToolMetadata | undefined;\n }\n\n /**\n * Initializes the search service by indexing all tools from the registry.\n * NOTE: This method is now a no-op. Initialization is handled reactively\n * via subscription to tool change events in the constructor.\n * This method exists for interface compatibility.\n */\n async initialize(): Promise<void> {\n // Initialization is now handled reactively via subscription\n // The subscription with immediate=true in the constructor ensures tools are indexed\n // This method exists for interface compatibility\n }\n\n /**\n * Cleanup subscription when service is destroyed\n */\n dispose(): void {\n if (this.unsubscribe) {\n this.unsubscribe();\n this.unsubscribe = undefined;\n }\n }\n\n /**\n * Extracts searchable text from a tool instance.\n * Uses term weighting to improve relevance:\n * - Description terms are heavily weighted (most important for semantic matching)\n * - Tool name parts are tokenized and weighted\n * - Tags provide additional context\n */\n private extractSearchableText(tool: ToolEntry<any, any>): string {\n const parts: string[] = [];\n\n // Extract and weight tool name parts\n // Split on common delimiters (: - _ .) to get meaningful tokens\n if (tool.name) {\n const nameParts = tool.name.split(/[:\\-_.]/).filter(Boolean);\n // Add each part twice for moderate weighting\n for (const part of nameParts) {\n parts.push(part, part);\n }\n }\n\n // Description is the most important for semantic matching\n // Weight it heavily by repeating 3x\n if (tool.metadata.description) {\n const description = tool.metadata.description;\n parts.push(description, description, description);\n\n // Also extract key terms from description (words 4+ chars) for extra weight\n const keyTerms = description\n .toLowerCase()\n .split(/\\s+/)\n .filter((word) => word.length >= 4 && !this.isStopWord(word));\n parts.push(...keyTerms);\n }\n\n // Add tags with moderate weight (2x)\n if (tool.metadata.tags && tool.metadata.tags.length > 0) {\n for (const tag of tool.metadata.tags) {\n parts.push(tag, tag);\n }\n }\n\n // Add input schema property names (useful for parameter-based searches)\n if (tool.rawInputSchema && typeof tool.rawInputSchema === 'object') {\n const schema = tool.rawInputSchema as any;\n if (schema.properties) {\n parts.push(...Object.keys(schema.properties));\n }\n }\n\n // Add example descriptions and input values to searchable text\n // Examples help users find tools by use-case descriptions\n const examples = tool.metadata?.examples;\n if (examples && Array.isArray(examples)) {\n for (const ex of examples) {\n // Add example description (2x weight for relevance)\n if (ex.description) {\n parts.push(ex.description, ex.description);\n }\n // Add example input keys and string values\n if (ex.input && typeof ex.input === 'object') {\n for (const [key, value] of Object.entries(ex.input as Record<string, unknown>)) {\n parts.push(key);\n if (typeof value === 'string') {\n parts.push(value);\n }\n }\n }\n }\n }\n\n return parts.join(' ');\n }\n\n /**\n * Checks if a word is a common stop word that should not receive extra weighting.\n * Uses module-level STOP_WORDS constant to avoid recreating the Set on each call.\n */\n private isStopWord(word: string): boolean {\n return STOP_WORDS.has(word);\n }\n\n /**\n * Extracts app ID from tool's owner lineage\n */\n private extractAppId(tool: ToolEntry<any, any>): string | undefined {\n if (!tool.owner) return undefined;\n\n // The owner structure has kind and id\n if (tool.owner.kind === 'app') {\n return tool.owner.id;\n }\n\n // If the tool is owned by a plugin, we need to look at its parent scope\n // For now, we'll return undefined and rely on the lineage if needed\n return undefined;\n }\n\n /**\n * Searches for tools matching the query\n * Implements the ToolSearch interface\n */\n async search(query: string, options: SymbolToolSearchOptions = {}): Promise<SymbolToolSearchResult[]> {\n const { topK = this.config.defaultTopK, appIds, excludeToolNames = [] } = options;\n const minScore = this.config.defaultSimilarityThreshold;\n\n // Build filter function\n const filter = (metadata: ToolMetadata): boolean => {\n // Exclude tools\n if (excludeToolNames.includes(metadata.toolName)) {\n return false;\n }\n\n // Filter by appId if specified\n if (appIds && appIds.length > 0) {\n if (!metadata.appId || !appIds.includes(metadata.appId)) {\n return false;\n }\n }\n\n return true;\n };\n\n // Expand query with synonyms for TF-IDF strategy to improve relevance\n // For example: \"add user\" -> \"add create new insert make user account member profile\"\n const effectiveQuery = this.synonymService ? this.synonymService.expandQuery(query) : query;\n\n // Search using vectoriadb\n const results = await this.vectorDB.search(effectiveQuery, {\n topK,\n threshold: minScore,\n filter,\n });\n\n // Transform results to match the ToolSearch interface\n return results.map((result) => ({\n toolName: result.metadata.toolName,\n appId: result.metadata.appId,\n description: result.metadata.toolInstance.metadata.description || '',\n relevanceScore: result.score,\n }));\n }\n\n /**\n * Gets all indexed tool names\n */\n getAllToolNames(): string[] {\n if (this.vectorDB instanceof VectoriaDB) {\n return this.vectorDB.getAll().map((doc) => doc.id);\n } else {\n return this.vectorDB.getAllDocumentIds();\n }\n }\n\n /**\n * Gets the total number of indexed tools\n */\n getTotalCount(): number {\n if (this.vectorDB instanceof VectoriaDB) {\n return this.vectorDB.size();\n } else {\n return this.vectorDB.getDocumentCount();\n }\n }\n\n /**\n * Checks if a tool exists in the index\n */\n hasTool(toolName: string): boolean {\n if (this.vectorDB instanceof VectoriaDB) {\n return this.vectorDB.has(toolName);\n } else {\n return this.vectorDB.hasDocument(toolName);\n }\n }\n\n /**\n * Clears the entire index\n */\n clear(): void {\n this.vectorDB.clear();\n this.initialized = false;\n }\n\n /**\n * Get the current embedding strategy\n */\n getStrategy(): EmbeddingStrategy {\n return this.strategy;\n }\n\n /**\n * Check if the service is initialized\n */\n isInitialized(): boolean {\n return this.initialized;\n }\n}\n"]}
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.describeToolOutputSchema = exports.describeToolInputSchema = exports.describeToolDescription = void 0;
4
- // file: libs/plugins/src/codecall/tools/describe.schema.ts
5
- const zod_1 = require("zod");
6
- const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
7
- exports.describeToolDescription = `Get input/output schemas for tools from search results.
8
-
9
- INPUT: toolNames: string[] - tool names from search
10
- OUTPUT per tool: inputSchema (JSON Schema), outputSchema (JSON Schema), usageExamples (up to 5 callTool examples)
11
-
12
- IMPORTANT: If notFound array is non-empty → re-search with corrected queries.
13
- FLOW: search → describe → execute/invoke`;
14
- exports.describeToolInputSchema = zod_1.z.object({
15
- toolNames: zod_1.z
16
- .array(zod_1.z.string())
17
- .min(1)
18
- .superRefine((toolNames, ctx) => {
19
- const seen = new Set();
20
- const duplicates = new Set();
21
- for (const name of toolNames) {
22
- if (seen.has(name)) {
23
- duplicates.add(name);
24
- }
25
- seen.add(name);
26
- }
27
- if (duplicates.size > 0) {
28
- ctx.addIssue({
29
- code: zod_1.z.ZodIssueCode.custom,
30
- message: `Duplicate tool names are not allowed: ${Array.from(duplicates).join(', ')}`,
31
- });
32
- }
33
- })
34
- .describe('Array of unique tool names (from codecall:search results) to fetch their detailed schemas and usage examples. Example: ["users:list", "billing:getInvoice"]'),
35
- });
36
- exports.describeToolOutputSchema = zod_1.z.object({
37
- tools: zod_1.z
38
- .array(zod_1.z.object({
39
- name: zod_1.z.string().describe('Tool name to be used in callTool() within codecall:execute scripts'),
40
- appId: zod_1.z.string().describe('The app ID this tool belongs to'),
41
- description: zod_1.z.string().describe('Detailed description of what this tool does'),
42
- inputSchema: zod_1.z
43
- .record(zod_1.z.string(), zod_1.z.unknown())
44
- .nullable()
45
- .describe('JSON Schema object describing the tool input parameters'),
46
- outputSchema: zod_1.z
47
- .record(zod_1.z.string(), zod_1.z.unknown())
48
- .nullable()
49
- .describe('JSON Schema object describing the tool output structure'),
50
- annotations: types_js_1.ToolAnnotationsSchema.optional().describe('MCP tool annotations (metadata)'),
51
- usageExamples: zod_1.z
52
- .array(zod_1.z.object({
53
- description: zod_1.z.string().describe('Description of what this example demonstrates'),
54
- code: zod_1.z
55
- .string()
56
- .describe('JavaScript code example showing how to call this tool using callTool(). Format: const result = await callTool("tool:name", { ...params });'),
57
- }))
58
- .max(5)
59
- .describe('Up to 5 practical examples of how to use this tool in a codecall:execute script'),
60
- }))
61
- .describe('Array of tool descriptions with schemas and usage examples'),
62
- notFound: zod_1.z
63
- .array(zod_1.z.string())
64
- .optional()
65
- .describe('Tool names that were requested but not found in the index. Check these for typos.'),
66
- });
67
- //# sourceMappingURL=describe.schema.js.map
@@ -1 +0,0 @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;QAC/F,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;QAC7D,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6CAA6C,CAAC;QAC/E,WAAW,EAAE,OAAC;aACX,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC;aAC/B,QAAQ,EAAE;aACV,QAAQ,CAAC,yDAAyD,CAAC;QACtE,YAAY,EAAE,OAAC;aACZ,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC;aAC/B,QAAQ,EAAE;aACV,QAAQ,CAAC,yDAAyD,CAAC;QACtE,WAAW,EAAE,gCAAqB,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;QACzF,aAAa,EAAE,OAAC;aACb,KAAK,CACJ,OAAC,CAAC,MAAM,CAAC;YACP,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+CAA+C,CAAC;YACjF,IAAI,EAAE,OAAC;iBACJ,MAAM,EAAE;iBACR,QAAQ,CACP,4IAA4I,CAC7I;SACJ,CAAC,CACH;aACA,GAAG,CAAC,CAAC,CAAC;aACN,QAAQ,CAAC,iFAAiF,CAAC;KAC/F,CAAC,CACH;SACA,QAAQ,CAAC,4DAA4D,CAAC;IACzE,QAAQ,EAAE,OAAC;SACR,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC;SACjB,QAAQ,EAAE;SACV,QAAQ,CAAC,mFAAmF,CAAC;CACjG,CAAC,CAAC","sourcesContent":["// file: libs/plugins/src/codecall/tools/describe.schema.ts\nimport { z } from 'zod';\nimport { ToolAnnotationsSchema } from '@modelcontextprotocol/sdk/types.js';\n\nexport const describeToolDescription = `Get input/output schemas for tools from search results.\n\nINPUT: toolNames: string[] - tool names from search\nOUTPUT per tool: inputSchema (JSON Schema), outputSchema (JSON Schema), usageExamples (up to 5 callTool examples)\n\nIMPORTANT: If notFound array is non-empty → re-search with corrected queries.\nFLOW: search → describe → execute/invoke`;\n\nexport const describeToolInputSchema = z.object({\n toolNames: z\n .array(z.string())\n .min(1)\n .superRefine((toolNames, ctx) => {\n const seen = new Set<string>();\n const duplicates = new Set<string>();\n for (const name of toolNames) {\n if (seen.has(name)) {\n duplicates.add(name);\n }\n seen.add(name);\n }\n if (duplicates.size > 0) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `Duplicate tool names are not allowed: ${Array.from(duplicates).join(', ')}`,\n });\n }\n })\n .describe(\n 'Array of unique tool names (from codecall:search results) to fetch their detailed schemas and usage examples. Example: [\"users:list\", \"billing:getInvoice\"]',\n ),\n});\n\nexport type DescribeToolInput = z.infer<typeof describeToolInputSchema>;\n\nexport const describeToolOutputSchema = z.object({\n tools: z\n .array(\n z.object({\n name: z.string().describe('Tool name to be used in callTool() within codecall:execute scripts'),\n appId: z.string().describe('The app ID this tool belongs to'),\n description: z.string().describe('Detailed description of what this tool does'),\n inputSchema: z\n .record(z.string(), z.unknown())\n .nullable()\n .describe('JSON Schema object describing the tool input parameters'),\n outputSchema: z\n .record(z.string(), z.unknown())\n .nullable()\n .describe('JSON Schema object describing the tool output structure'),\n annotations: ToolAnnotationsSchema.optional().describe('MCP tool annotations (metadata)'),\n usageExamples: z\n .array(\n z.object({\n description: z.string().describe('Description of what this example demonstrates'),\n code: z\n .string()\n .describe(\n 'JavaScript code example showing how to call this tool using callTool(). Format: const result = await callTool(\"tool:name\", { ...params });',\n ),\n }),\n )\n .max(5)\n .describe('Up to 5 practical examples of how to use this tool in a codecall:execute script'),\n }),\n )\n .describe('Array of tool descriptions with schemas and usage examples'),\n notFound: z\n .array(z.string())\n .optional()\n .describe('Tool names that were requested but not found in the index. Check these for typos.'),\n});\n\nexport type DescribeToolOutput = z.infer<typeof describeToolOutputSchema>;\n"]}
@@ -1,207 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- // file: libs/plugins/src/codecall/tools/describe.tool.ts
5
- const sdk_1 = require("@frontmcp/sdk");
6
- const v4_1 = require("zod/v4");
7
- const zod_1 = require("zod");
8
- const describe_schema_1 = require("./describe.schema");
9
- const utils_1 = require("../utils");
10
- const security_1 = require("../security");
11
- let DescribeTool = class DescribeTool extends sdk_1.ToolContext {
12
- async execute(input) {
13
- const { toolNames } = input;
14
- const tools = [];
15
- const notFound = [];
16
- // Get all available tools from the registry
17
- const allTools = this.scope.tools.getTools(true);
18
- const toolMap = new Map(allTools.map((t) => [t.name, t]));
19
- const fullNameMap = new Map(allTools.map((t) => [t.fullName, t]));
20
- for (const toolName of toolNames) {
21
- // Security: Don't allow describing CodeCall tools themselves
22
- if ((0, security_1.isBlockedSelfReference)(toolName)) {
23
- notFound.push(toolName);
24
- continue;
25
- }
26
- // Find the tool by name or fullName
27
- const tool = toolMap.get(toolName) || fullNameMap.get(toolName);
28
- if (!tool) {
29
- notFound.push(toolName);
30
- continue;
31
- }
32
- // Extract app ID from tool owner or metadata
33
- const appId = this.extractAppId(tool);
34
- // Get input schema - convert from Zod to ensure descriptions are included
35
- const inputSchema = this.getInputSchema(tool);
36
- // Get output schema - convert from Zod if needed
37
- const outputSchema = this.toJsonSchema(tool.outputSchema);
38
- // Generate usage examples: user-provided > smart generation > basic fallback
39
- const usageExamples = this.generateExamples(tool, inputSchema ?? undefined);
40
- tools.push({
41
- name: tool.name,
42
- appId,
43
- description: tool.metadata?.description || `Tool: ${tool.name}`,
44
- inputSchema: inputSchema || null,
45
- outputSchema: outputSchema || null,
46
- annotations: tool.metadata?.annotations,
47
- usageExamples,
48
- });
49
- }
50
- return {
51
- tools,
52
- notFound: notFound.length > 0 ? notFound : undefined,
53
- };
54
- }
55
- /**
56
- * Get the input schema for a tool, converting from Zod to JSON Schema.
57
- * This ensures that property descriptions from .describe() are included.
58
- *
59
- * Priority:
60
- * 1. Convert from tool.inputSchema (Zod) to get descriptions
61
- * 2. Fall back to rawInputSchema if conversion fails
62
- * 3. Return null if no schema available
63
- */
64
- getInputSchema(tool) {
65
- // First, try to convert from the Zod inputSchema to ensure descriptions are included
66
- if (tool.inputSchema && typeof tool.inputSchema === 'object' && Object.keys(tool.inputSchema).length > 0) {
67
- try {
68
- // tool.inputSchema is a ZodRawShape (Record<string, ZodType>)
69
- const firstValue = Object.values(tool.inputSchema)[0];
70
- if (firstValue instanceof zod_1.ZodType) {
71
- // Convert Zod shape to JSON Schema - this preserves .describe() annotations
72
- return (0, v4_1.toJSONSchema)(zod_1.z.object(tool.inputSchema));
73
- }
74
- }
75
- catch {
76
- // Fall through to rawInputSchema
77
- }
78
- }
79
- // Fall back to rawInputSchema if available
80
- if (tool.rawInputSchema) {
81
- return tool.rawInputSchema;
82
- }
83
- return null;
84
- }
85
- /**
86
- * Convert a schema to JSON Schema format.
87
- * Handles Zod schemas, raw shapes, and already-JSON-Schema objects.
88
- *
89
- * Uses Zod v4's built-in z.toJSONSchema() for conversion.
90
- */
91
- toJsonSchema(schema) {
92
- if (!schema) {
93
- return null;
94
- }
95
- // Check if it's a Zod schema
96
- if (schema instanceof zod_1.ZodType) {
97
- try {
98
- // Use Zod v4's toJSONSchema conversion
99
- return (0, v4_1.toJSONSchema)(schema);
100
- }
101
- catch {
102
- // If conversion fails, return null
103
- return null;
104
- }
105
- }
106
- // Check if it's a raw Zod shape (Record<string, ZodTypeAny>)
107
- if (typeof schema === 'object' && schema !== null && !Array.isArray(schema)) {
108
- const obj = schema;
109
- const firstValue = Object.values(obj)[0];
110
- // If the first value is a ZodType, treat the whole thing as a raw shape
111
- if (firstValue instanceof zod_1.ZodType) {
112
- try {
113
- // Wrap in z.object and convert using Zod v4's toJSONSchema
114
- return (0, v4_1.toJSONSchema)(zod_1.z.object(obj));
115
- }
116
- catch {
117
- return null;
118
- }
119
- }
120
- // Already a JSON Schema object
121
- if ('type' in obj || 'properties' in obj || '$schema' in obj) {
122
- return schema;
123
- }
124
- }
125
- // String literal output schemas (like 'text', 'json', etc.) - not a JSON Schema
126
- if (typeof schema === 'string') {
127
- return null;
128
- }
129
- // Array output schemas - not directly convertible
130
- if (Array.isArray(schema)) {
131
- return null;
132
- }
133
- return null;
134
- }
135
- /**
136
- * Extract app ID from tool metadata or owner.
137
- */
138
- extractAppId(tool) {
139
- // Check codecall metadata first
140
- if (tool.metadata?.codecall?.appId) {
141
- return tool.metadata.codecall.appId;
142
- }
143
- // Check source metadata
144
- if (tool.metadata?.source) {
145
- return tool.metadata.source;
146
- }
147
- // Check owner
148
- if (tool.owner?.id) {
149
- return tool.owner.id;
150
- }
151
- // Extract from tool name (namespace:name -> namespace)
152
- const nameParts = tool.name?.split(':');
153
- if (nameParts && nameParts.length > 1) {
154
- return nameParts[0];
155
- }
156
- return 'unknown';
157
- }
158
- /**
159
- * Generate up to 5 usage examples for a tool.
160
- *
161
- * Priority:
162
- * 1. User-provided examples from @Tool decorator metadata (up to 5)
163
- * 2. Smart intent-based generation to fill remaining slots
164
- * 3. Returns at least 1 example
165
- */
166
- generateExamples(tool, inputSchema) {
167
- const result = [];
168
- // Priority 1: Use user-provided examples from metadata (up to 5)
169
- const examples = tool.metadata?.examples;
170
- if (examples && Array.isArray(examples)) {
171
- for (const ex of examples.slice(0, 5)) {
172
- result.push({
173
- description: ex.description || 'Example usage',
174
- code: `const result = await callTool('${tool.name}', ${JSON.stringify(ex.input, null, 2)});
175
- return result;`,
176
- });
177
- }
178
- }
179
- // Priority 2: If fewer than 5 user examples, add smart-generated example
180
- if (result.length < 5) {
181
- result.push((0, utils_1.generateSmartExample)(tool.name, inputSchema, tool.metadata?.description));
182
- }
183
- return result.slice(0, 5);
184
- }
185
- };
186
- DescribeTool = tslib_1.__decorate([
187
- (0, sdk_1.Tool)({
188
- name: 'codecall:describe',
189
- cache: {
190
- ttl: 60, // 1 minute
191
- slideWindow: false,
192
- },
193
- codecall: {
194
- enabledInCodeCall: false,
195
- visibleInListTools: true,
196
- },
197
- description: describe_schema_1.describeToolDescription,
198
- inputSchema: describe_schema_1.describeToolInputSchema,
199
- outputSchema: describe_schema_1.describeToolOutputSchema,
200
- annotations: {
201
- readOnlyHint: true,
202
- openWorldHint: true,
203
- },
204
- })
205
- ], DescribeTool);
206
- exports.default = DescribeTool;
207
- //# sourceMappingURL=describe.tool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"describe.tool.js","sourceRoot":"","sources":["../../../../src/codecall/tools/describe.tool.ts"],"names":[],"mappings":";;;AAAA,yDAAyD;AACzD,uCAA6D;AAE7D,+BAAsC;AAItC,6BAAiC;AACjC,uDAM2B;AAC3B,oCAAgD;AAChD,0CAAqD;AAoBtC,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,iBAAW;IACnD,KAAK,CAAC,OAAO,CAAC,KAAwB;QACpC,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;QAE5B,MAAM,KAAK,GAAgC,EAAE,CAAC;QAC9C,MAAM,QAAQ,GAAa,EAAE,CAAC;QAE9B,4CAA4C;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1D,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAElE,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,6DAA6D;YAC7D,IAAI,IAAA,iCAAsB,EAAC,QAAQ,CAAC,EAAE,CAAC;gBACrC,QAAQ,CAAC,IAAI,CAAC,QAAQ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,WAAW,EAAE,yCAAuB;QACpC,WAAW,EAAE,yCAAuB;QACpC,YAAY,EAAE,0CAAwB;QACtC,WAAW,EAAE;YACX,YAAY,EAAE,IAAI;YAClB,aAAa,EAAE,IAAI;SACpB;KACF,CAAC;GACmB,YAAY,CAiNhC;kBAjNoB,YAAY","sourcesContent":["// file: libs/plugins/src/codecall/tools/describe.tool.ts\nimport { Tool, ToolContext, ToolEntry } from '@frontmcp/sdk';\nimport type { JSONSchema } from 'zod/v4/core';\nimport { toJSONSchema } from 'zod/v4';\n\n/** JSON Schema type from Zod v4 */\ntype JsonSchema = JSONSchema.JSONSchema;\nimport { z, ZodType } from 'zod';\nimport {\n DescribeToolInput,\n describeToolInputSchema,\n DescribeToolOutput,\n describeToolOutputSchema,\n describeToolDescription,\n} from './describe.schema';\nimport { generateSmartExample } from '../utils';\nimport { isBlockedSelfReference } from '../security';\n\n@Tool({\n name: 'codecall:describe',\n cache: {\n ttl: 60, // 1 minute\n slideWindow: false,\n },\n codecall: {\n enabledInCodeCall: false,\n visibleInListTools: true,\n },\n description: describeToolDescription,\n inputSchema: describeToolInputSchema,\n outputSchema: describeToolOutputSchema,\n annotations: {\n readOnlyHint: true,\n openWorldHint: true,\n },\n})\nexport default class DescribeTool extends ToolContext {\n async execute(input: DescribeToolInput): Promise<DescribeToolOutput> {\n const { toolNames } = input;\n\n const tools: DescribeToolOutput['tools'] = [];\n const notFound: string[] = [];\n\n // Get all available tools from the registry\n const allTools = this.scope.tools.getTools(true);\n const toolMap = new Map(allTools.map((t) => [t.name, t]));\n const fullNameMap = new Map(allTools.map((t) => [t.fullName, t]));\n\n for (const toolName of toolNames) {\n // Security: Don't allow describing CodeCall tools themselves\n if (isBlockedSelfReference(toolName)) {\n notFound.push(toolName);\n continue;\n }\n\n // Find the tool by name or fullName\n const tool = toolMap.get(toolName) || fullNameMap.get(toolName);\n\n if (!tool) {\n notFound.push(toolName);\n continue;\n }\n\n // Extract app ID from tool owner or metadata\n const appId = this.extractAppId(tool);\n\n // Get input schema - convert from Zod to ensure descriptions are included\n const inputSchema = this.getInputSchema(tool);\n\n // Get output schema - convert from Zod if needed\n const outputSchema = this.toJsonSchema(tool.outputSchema);\n\n // Generate usage examples: user-provided > smart generation > basic fallback\n const usageExamples = this.generateExamples(tool, inputSchema ?? undefined);\n\n tools.push({\n name: tool.name,\n appId,\n description: tool.metadata?.description || `Tool: ${tool.name}`,\n inputSchema: (inputSchema as Record<string, unknown>) || null,\n outputSchema: (outputSchema as Record<string, unknown>) || null,\n annotations: tool.metadata?.annotations,\n usageExamples,\n });\n }\n\n return {\n tools,\n notFound: notFound.length > 0 ? notFound : undefined,\n };\n }\n\n /**\n * Get the input schema for a tool, converting from Zod to JSON Schema.\n * This ensures that property descriptions from .describe() are included.\n *\n * Priority:\n * 1. Convert from tool.inputSchema (Zod) to get descriptions\n * 2. Fall back to rawInputSchema if conversion fails\n * 3. Return null if no schema available\n */\n private getInputSchema(tool: ToolEntry<any, any>): JsonSchema | null {\n // First, try to convert from the Zod inputSchema to ensure descriptions are included\n if (tool.inputSchema && typeof tool.inputSchema === 'object' && Object.keys(tool.inputSchema).length > 0) {\n try {\n // tool.inputSchema is a ZodRawShape (Record<string, ZodType>)\n const firstValue = Object.values(tool.inputSchema)[0];\n if (firstValue instanceof ZodType) {\n // Convert Zod shape to JSON Schema - this preserves .describe() annotations\n return toJSONSchema(z.object(tool.inputSchema as Record<string, ZodType>)) as JsonSchema;\n }\n } catch {\n // Fall through to rawInputSchema\n }\n }\n\n // Fall back to rawInputSchema if available\n if (tool.rawInputSchema) {\n return tool.rawInputSchema as JsonSchema;\n }\n\n return null;\n }\n\n /**\n * Convert a schema to JSON Schema format.\n * Handles Zod schemas, raw shapes, and already-JSON-Schema objects.\n *\n * Uses Zod v4's built-in z.toJSONSchema() for conversion.\n */\n private toJsonSchema(schema: unknown): JsonSchema | null {\n if (!schema) {\n return null;\n }\n\n // Check if it's a Zod schema\n if (schema instanceof ZodType) {\n try {\n // Use Zod v4's toJSONSchema conversion\n return toJSONSchema(schema);\n } catch {\n // If conversion fails, return null\n return null;\n }\n }\n\n // Check if it's a raw Zod shape (Record<string, ZodTypeAny>)\n if (typeof schema === 'object' && schema !== null && !Array.isArray(schema)) {\n const obj = schema as Record<string, unknown>;\n const firstValue = Object.values(obj)[0];\n\n // If the first value is a ZodType, treat the whole thing as a raw shape\n if (firstValue instanceof ZodType) {\n try {\n // Wrap in z.object and convert using Zod v4's toJSONSchema\n return toJSONSchema(z.object(obj as Record<string, ZodType>) as any) as JsonSchema;\n } catch {\n return null;\n }\n }\n\n // Already a JSON Schema object\n if ('type' in obj || 'properties' in obj || '$schema' in obj) {\n return schema as JsonSchema;\n }\n }\n\n // String literal output schemas (like 'text', 'json', etc.) - not a JSON Schema\n if (typeof schema === 'string') {\n return null;\n }\n\n // Array output schemas - not directly convertible\n if (Array.isArray(schema)) {\n return null;\n }\n\n return null;\n }\n\n /**\n * Extract app ID from tool metadata or owner.\n */\n private extractAppId(tool: {\n name?: string;\n metadata?: { codecall?: { appId?: string }; source?: string };\n owner?: { id?: string };\n }): string {\n // Check codecall metadata first\n if (tool.metadata?.codecall?.appId) {\n return tool.metadata.codecall.appId;\n }\n\n // Check source metadata\n if (tool.metadata?.source) {\n return tool.metadata.source;\n }\n\n // Check owner\n if (tool.owner?.id) {\n return tool.owner.id;\n }\n\n // Extract from tool name (namespace:name -> namespace)\n const nameParts = tool.name?.split(':');\n if (nameParts && nameParts.length > 1) {\n return nameParts[0];\n }\n\n return 'unknown';\n }\n\n /**\n * Generate up to 5 usage examples for a tool.\n *\n * Priority:\n * 1. User-provided examples from @Tool decorator metadata (up to 5)\n * 2. Smart intent-based generation to fill remaining slots\n * 3. Returns at least 1 example\n */\n private generateExamples(\n tool: ToolEntry<any, any>,\n inputSchema?: JsonSchema,\n ): Array<{ description: string; code: string }> {\n const result: Array<{ description: string; code: string }> = [];\n\n // Priority 1: Use user-provided examples from metadata (up to 5)\n const examples = tool.metadata?.examples;\n if (examples && Array.isArray(examples)) {\n for (const ex of examples.slice(0, 5)) {\n result.push({\n description: ex.description || 'Example usage',\n code: `const result = await callTool('${tool.name}', ${JSON.stringify(ex.input, null, 2)});\nreturn result;`,\n });\n }\n }\n\n // Priority 2: If fewer than 5 user examples, add smart-generated example\n if (result.length < 5) {\n result.push(generateSmartExample(tool.name, inputSchema, tool.metadata?.description));\n }\n\n return result.slice(0, 5);\n }\n}\n"]}
@@ -1,116 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeToolOutputSchema = exports.codeCallTimeoutResultSchema = exports.codeCallToolErrorResultSchema = exports.codeCallRuntimeErrorResultSchema = exports.codeCallIllegalAccessResultSchema = exports.codeCallSyntaxErrorResultSchema = exports.codeCallOkResultSchema = exports.executeToolInputSchema = exports.executeToolDescription = void 0;
4
- // file: libs/plugins/src/codecall/tools/execute.schema.ts
5
- const zod_1 = require("zod");
6
- /** Minimum script length - at least a simple callTool invocation */
7
- const MIN_EXECUTE_SCRIPT_LENGTH = 'return callTool("a",{})'.length;
8
- exports.executeToolDescription = `Execute AgentScript (safe JS subset) for multi-tool orchestration.
9
-
10
- API: await callTool(name, args, opts?)
11
- - Default: throws on error
12
- - Safe mode: { throwOnError: false } → returns { success, data?, error? }
13
-
14
- EXAMPLE:
15
- const users = await callTool('users:list', { active: true });
16
- const results = [];
17
- for (const u of users.items) {
18
- const orders = await callTool('orders:list', { userId: u.id });
19
- results.push({ id: u.id, total: orders.items.reduce((s,o) => s + o.amount, 0) });
20
- }
21
- return results;
22
-
23
- ALLOWED: for, for-of, arrow fn, map/filter/reduce/find, Math.*, JSON.*, if/else, destructuring, spread, template literals
24
- BLOCKED: while, do-while, function decl, eval, require, fetch, setTimeout, process, globalThis
25
-
26
- ERRORS: NOT_FOUND | VALIDATION | EXECUTION | TIMEOUT | ACCESS_DENIED
27
- STATUS: ok | syntax_error | illegal_access | runtime_error | tool_error | timeout
28
- LIMITS: 10K iter/loop, 30s timeout, 100 calls max`;
29
- exports.executeToolInputSchema = zod_1.z.object({
30
- script: zod_1.z
31
- .string()
32
- .min(MIN_EXECUTE_SCRIPT_LENGTH)
33
- .max(100 * 1024) // 100 KB
34
- .describe('JavaScript code to execute in the sandbox. Must return a value (implicitly or via explicit return). Use callTool(name, input) to invoke tools.'),
35
- allowedTools: zod_1.z
36
- .array(zod_1.z.string())
37
- .optional()
38
- .describe('Optional whitelist of tool names that can be called from this script. If not provided, all indexed tools are available. Example: ["users:list", "billing:getInvoice"]'),
39
- });
40
- /**
41
- * Shared "payload" schemas
42
- */
43
- const syntaxErrorPayloadSchema = zod_1.z.object({
44
- message: zod_1.z.string(),
45
- location: zod_1.z
46
- .object({
47
- line: zod_1.z.number(),
48
- column: zod_1.z.number(),
49
- })
50
- .optional(),
51
- });
52
- const illegalAccessErrorPayloadSchema = zod_1.z.object({
53
- message: zod_1.z.string(),
54
- kind: zod_1.z.union([
55
- zod_1.z.literal('IllegalBuiltinAccess'),
56
- zod_1.z.literal('DisallowedGlobal'),
57
- zod_1.z.string(), // same as your original type: 'A' | 'B' | string
58
- ]),
59
- });
60
- const runtimeErrorPayloadSchema = zod_1.z.object({
61
- source: zod_1.z.literal('script'),
62
- message: zod_1.z.string(),
63
- name: zod_1.z.string().optional(),
64
- stack: zod_1.z.string().optional(),
65
- });
66
- const toolErrorPayloadSchema = zod_1.z.object({
67
- source: zod_1.z.literal('tool'),
68
- toolName: zod_1.z.string(),
69
- toolInput: zod_1.z.unknown(),
70
- message: zod_1.z.string(),
71
- code: zod_1.z.string().optional(),
72
- details: zod_1.z.unknown().optional(),
73
- });
74
- const timeoutErrorPayloadSchema = zod_1.z.object({
75
- message: zod_1.z.string(),
76
- });
77
- /**
78
- * Result variants
79
- */
80
- exports.codeCallOkResultSchema = zod_1.z.object({
81
- status: zod_1.z.literal('ok'),
82
- result: zod_1.z.unknown(),
83
- logs: zod_1.z.array(zod_1.z.string()).optional(),
84
- });
85
- exports.codeCallSyntaxErrorResultSchema = zod_1.z.object({
86
- status: zod_1.z.literal('syntax_error'),
87
- error: syntaxErrorPayloadSchema,
88
- });
89
- exports.codeCallIllegalAccessResultSchema = zod_1.z.object({
90
- status: zod_1.z.literal('illegal_access'),
91
- error: illegalAccessErrorPayloadSchema,
92
- });
93
- exports.codeCallRuntimeErrorResultSchema = zod_1.z.object({
94
- status: zod_1.z.literal('runtime_error'),
95
- error: runtimeErrorPayloadSchema,
96
- });
97
- exports.codeCallToolErrorResultSchema = zod_1.z.object({
98
- status: zod_1.z.literal('tool_error'),
99
- error: toolErrorPayloadSchema,
100
- });
101
- exports.codeCallTimeoutResultSchema = zod_1.z.object({
102
- status: zod_1.z.literal('timeout'),
103
- error: timeoutErrorPayloadSchema,
104
- });
105
- /**
106
- * Discriminated union for the whole result
107
- */
108
- exports.executeToolOutputSchema = zod_1.z.discriminatedUnion('status', [
109
- exports.codeCallOkResultSchema,
110
- exports.codeCallSyntaxErrorResultSchema,
111
- exports.codeCallIllegalAccessResultSchema,
112
- exports.codeCallRuntimeErrorResultSchema,
113
- exports.codeCallToolErrorResultSchema,
114
- exports.codeCallTimeoutResultSchema,
115
- ]);
116
- //# sourceMappingURL=execute.schema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"execute.schema.js","sourceRoot":"","sources":["../../../../src/codecall/tools/execute.schema.ts"],"names":[],"mappings":";;;AAAA,0DAA0D;AAC1D,6BAAwB;AAExB,oEAAoE;AACpE,MAAM,yBAAyB,GAAG,yBAAyB,CAAC,MAAM,CAAC;AAEtD,QAAA,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;kDAoBY,CAAC;AAEtC,QAAA,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC7C,MAAM,EAAE,OAAC;SACN,MAAM,EAAE;SACR,GAAG,CAAC,yBAAyB,CAAC;SAC9B,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,SAAS;SACzB,QAAQ,CACP,gJAAgJ,CACjJ;IACH,YAAY,EAAE,OA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EAAE,yBAAyB;CACjC,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,uBAAuB,GAAG,OAAC,CAAC,kBAAkB,CAAC,QAAQ,EAAE;IACpE,8BAAsB;IACtB,uCAA+B;IAC/B,yCAAiC;IACjC,wCAAgC;IAChC,qCAA6B;IAC7B,mCAA2B;CAC5B,CAAC,CAAC","sourcesContent":["// file: libs/plugins/src/codecall/tools/execute.schema.ts\nimport { z } from 'zod';\n\n/** Minimum script length - at least a simple callTool invocation */\nconst MIN_EXECUTE_SCRIPT_LENGTH = 'return callTool(\"a\",{})'.length;\n\nexport const executeToolDescription = `Execute AgentScript (safe JS subset) for multi-tool orchestration.\n\nAPI: await callTool(name, args, opts?)\n- Default: throws on error\n- Safe mode: { throwOnError: false } → returns { success, data?, error? }\n\nEXAMPLE:\nconst users = await callTool('users:list', { active: true });\nconst results = [];\nfor (const u of users.items) {\n const orders = await callTool('orders:list', { userId: u.id });\n results.push({ id: u.id, total: orders.items.reduce((s,o) => s + o.amount, 0) });\n}\nreturn results;\n\nALLOWED: for, for-of, arrow fn, map/filter/reduce/find, Math.*, JSON.*, if/else, destructuring, spread, template literals\nBLOCKED: while, do-while, function decl, eval, require, fetch, setTimeout, process, globalThis\n\nERRORS: NOT_FOUND | VALIDATION | EXECUTION | TIMEOUT | ACCESS_DENIED\nSTATUS: ok | syntax_error | illegal_access | runtime_error | tool_error | timeout\nLIMITS: 10K iter/loop, 30s timeout, 100 calls max`;\n\nexport const executeToolInputSchema = z.object({\n script: z\n .string()\n .min(MIN_EXECUTE_SCRIPT_LENGTH)\n .max(100 * 1024) // 100 KB\n .describe(\n 'JavaScript code to execute in the sandbox. Must return a value (implicitly or via explicit return). Use callTool(name, input) to invoke tools.',\n ),\n allowedTools: z\n .array(z.string())\n .optional()\n .describe(\n 'Optional whitelist of tool names that can be called from this script. If not provided, all indexed tools are available. Example: [\"users:list\", \"billing:getInvoice\"]',\n ),\n});\n\nexport type ExecuteToolInput = z.infer<typeof executeToolInputSchema>;\n\n/**\n * Shared \"payload\" schemas\n */\nconst syntaxErrorPayloadSchema = z.object({\n message: z.string(),\n location: z\n .object({\n line: z.number(),\n column: z.number(),\n })\n .optional(),\n});\n\nconst illegalAccessErrorPayloadSchema = z.object({\n message: z.string(),\n kind: z.union([\n z.literal('IllegalBuiltinAccess'),\n z.literal('DisallowedGlobal'),\n z.string(), // same as your original type: 'A' | 'B' | string\n ]),\n});\n\nconst runtimeErrorPayloadSchema = z.object({\n source: z.literal('script'),\n message: z.string(),\n name: z.string().optional(),\n stack: z.string().optional(),\n});\n\nconst toolErrorPayloadSchema = z.object({\n source: z.literal('tool'),\n toolName: z.string(),\n toolInput: z.unknown(),\n message: z.string(),\n code: z.string().optional(),\n details: z.unknown().optional(),\n});\n\nconst timeoutErrorPayloadSchema = z.object({\n message: z.string(),\n});\n\n/**\n * Result variants\n */\nexport const codeCallOkResultSchema = z.object({\n status: z.literal('ok'),\n result: z.unknown(),\n logs: z.array(z.string()).optional(),\n});\n\nexport const codeCallSyntaxErrorResultSchema = z.object({\n status: z.literal('syntax_error'),\n error: syntaxErrorPayloadSchema,\n});\n\nexport const codeCallIllegalAccessResultSchema = z.object({\n status: z.literal('illegal_access'),\n error: illegalAccessErrorPayloadSchema,\n});\n\nexport const codeCallRuntimeErrorResultSchema = z.object({\n status: z.literal('runtime_error'),\n error: runtimeErrorPayloadSchema,\n});\n\nexport const codeCallToolErrorResultSchema = z.object({\n status: z.literal('tool_error'),\n error: toolErrorPayloadSchema,\n});\n\nexport const codeCallTimeoutResultSchema = z.object({\n status: z.literal('timeout'),\n error: timeoutErrorPayloadSchema,\n});\n\n/**\n * Discriminated union for the whole result\n */\nexport const executeToolOutputSchema = z.discriminatedUnion('status', [\n codeCallOkResultSchema,\n codeCallSyntaxErrorResultSchema,\n codeCallIllegalAccessResultSchema,\n codeCallRuntimeErrorResultSchema,\n codeCallToolErrorResultSchema,\n codeCallTimeoutResultSchema,\n]);\n\n/**\n * Inferred types\n * (you can export whichever ones you actually need)\n */\nexport type CodeCallOkResult = z.infer<typeof codeCallOkResultSchema>;\nexport type CodeCallSyntaxErrorResult = z.infer<typeof codeCallSyntaxErrorResultSchema>;\nexport type CodeCallIllegalAccessResult = z.infer<typeof codeCallIllegalAccessResultSchema>;\nexport type CodeCallRuntimeErrorResult = z.infer<typeof codeCallRuntimeErrorResultSchema>;\nexport type CodeCallToolErrorResult = z.infer<typeof codeCallToolErrorResultSchema>;\nexport type CodeCallTimeoutResult = z.infer<typeof codeCallTimeoutResultSchema>;\n\nexport type CodeCallExecuteResult =\n | CodeCallOkResult\n | CodeCallSyntaxErrorResult\n | CodeCallIllegalAccessResult\n | CodeCallRuntimeErrorResult\n | CodeCallToolErrorResult\n | CodeCallTimeoutResult;\n"]}