@illuma-ai/agents 1.4.0-alpha.4 → 1.4.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/content/ArtifactStore.cjs +579 -0
- package/dist/cjs/content/ArtifactStore.cjs.map +1 -0
- package/dist/cjs/content/ContentStore.cjs +638 -0
- package/dist/cjs/content/ContentStore.cjs.map +1 -0
- package/dist/cjs/content/contentAnalyzer.cjs +91 -0
- package/dist/cjs/content/contentAnalyzer.cjs.map +1 -0
- package/dist/cjs/content/index.cjs +20 -0
- package/dist/cjs/content/index.cjs.map +1 -0
- package/dist/cjs/content/mcpAutoCache.cjs +115 -0
- package/dist/cjs/content/mcpAutoCache.cjs.map +1 -0
- package/dist/cjs/main.cjs +10 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/providers/tools-server/ToolsServerCapabilityProvider.cjs +4 -1
- package/dist/cjs/providers/tools-server/ToolsServerCapabilityProvider.cjs.map +1 -1
- package/dist/cjs/tools/proxyTool.cjs +7 -5
- package/dist/cjs/tools/proxyTool.cjs.map +1 -1
- package/dist/esm/content/ArtifactStore.mjs +576 -0
- package/dist/esm/content/ArtifactStore.mjs.map +1 -0
- package/dist/esm/content/ContentStore.mjs +635 -0
- package/dist/esm/content/ContentStore.mjs.map +1 -0
- package/dist/esm/content/contentAnalyzer.mjs +87 -0
- package/dist/esm/content/contentAnalyzer.mjs.map +1 -0
- package/dist/esm/content/index.mjs +5 -0
- package/dist/esm/content/index.mjs.map +1 -0
- package/dist/esm/content/mcpAutoCache.mjs +111 -0
- package/dist/esm/content/mcpAutoCache.mjs.map +1 -0
- package/dist/esm/main.mjs +3 -0
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/providers/tools-server/ToolsServerCapabilityProvider.mjs +4 -1
- package/dist/esm/providers/tools-server/ToolsServerCapabilityProvider.mjs.map +1 -1
- package/dist/esm/tools/proxyTool.mjs +7 -5
- package/dist/esm/tools/proxyTool.mjs.map +1 -1
- package/dist/types/content/ArtifactStore.d.ts +223 -0
- package/dist/types/content/ContentStore.d.ts +140 -0
- package/dist/types/content/contentAnalyzer.d.ts +38 -0
- package/dist/types/content/index.d.ts +24 -0
- package/dist/types/content/mcpAutoCache.d.ts +89 -0
- package/dist/types/content/types.d.ts +75 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/providers/tools-server/ToolsServerCapabilityProvider.d.ts +14 -0
- package/dist/types/tools/proxyTool.d.ts +7 -0
- package/package.json +6 -1
- package/src/content/ArtifactStore.ts +782 -0
- package/src/content/ContentStore.ts +753 -0
- package/src/content/contentAnalyzer.ts +105 -0
- package/src/content/index.ts +51 -0
- package/src/content/mcpAutoCache.ts +185 -0
- package/src/content/types.ts +82 -0
- package/src/index.ts +19 -0
- package/src/providers/__tests__/ToolsServerCapabilityProvider.test.ts +65 -0
- package/src/providers/tools-server/ToolsServerCapabilityProvider.ts +21 -0
- package/src/tools/proxyTool.ts +25 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentStore.cjs","sources":["../../../src/content/ContentStore.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport type Keyv from 'keyv';\nimport type {\n StoreEntry,\n StoredEntry,\n ContentMetadata,\n ReadResult,\n ReadAllResult,\n SearchMatch,\n EditResult,\n} from './types';\n\n/**\n * Default 3-minute TTL for ephemeral content entries. Resets on every\n * access. Kept short to reduce cache-backing memory pressure — callers\n * that persist to durable storage (see {@link ArtifactStore}) rely on\n * lazy restore from the durable backend on cache miss.\n *\n * Exported so consumers can construct their injected {@link Keyv}\n * instance with a matching TTL without hard-coding the number.\n */\nexport const CONTENT_TTL_MS = 180_000;\n\n/** Default number of lines returned by readLines(). */\nconst DEFAULT_READ_LINES = 200;\n\n/** Maximum lines that can be read in a single call. */\nconst MAX_READ_LINES = 500;\n\n/** Maximum search results returned per call. */\nconst MAX_SEARCH_RESULTS = 50;\n\n/** Lines of context to show around a failed edit match for diagnostics. */\nconst ERROR_CONTEXT_LINES = 5;\n\n/**\n * Normalize line endings: CRLF → LF, stray CR → LF.\n * Prevents invisible mismatches when content originates from Windows/Office tools.\n */\nfunction normalizeNewlines(text: string): string {\n return text.replace(/\\r\\n/g, '\\n').replace(/\\r/g, '\\n');\n}\n\n/**\n * Trim trailing whitespace from each line — used as a fallback when\n * exact matching fails due to invisible trailing spaces.\n */\nfunction trimTrailingPerLine(text: string): string {\n return text\n .split('\\n')\n .map((l) => l.trimEnd())\n .join('\\n');\n}\n\n/**\n * Fuzzy indentation-normalized matching. Compares line content after stripping\n * all leading whitespace, then maps back to the real line range in the content.\n * Returns `{ start, end }` character offsets in `content` if a unique match is found,\n * or `null` if no match or ambiguous (multiple matches).\n */\nfunction findIndentationNormalizedMatch(\n content: string,\n oldStr: string\n): { start: number; end: number } | null {\n const contentLines = content.split('\\n');\n const oldLines = oldStr.split('\\n');\n\n // Strip leading whitespace for comparison — keep non-empty lines only for matching key\n const oldTrimmed = oldLines.map((l) => l.trimStart());\n\n // Need at least 1 non-empty line to match on\n const nonEmptyOldLines = oldTrimmed.filter((l) => l.length > 0);\n if (nonEmptyOldLines.length === 0) return null;\n\n const matches: { start: number; end: number }[] = [];\n\n // Slide a window of oldLines.length across contentLines\n for (let i = 0; i <= contentLines.length - oldLines.length; i++) {\n let matched = true;\n for (let j = 0; j < oldLines.length; j++) {\n const contentTrimmed = contentLines[i + j].trimStart();\n if (contentTrimmed !== oldTrimmed[j]) {\n matched = false;\n break;\n }\n }\n if (matched) {\n // Calculate character offsets for the matched region\n let charStart = 0;\n for (let k = 0; k < i; k++) {\n charStart += contentLines[k].length + 1; // +1 for \\n\n }\n let charEnd = charStart;\n for (let k = 0; k < oldLines.length; k++) {\n charEnd +=\n contentLines[i + k].length + (k < oldLines.length - 1 ? 1 : 0);\n }\n matches.push({ start: charStart, end: charEnd });\n }\n }\n\n // Only return if exactly one match (unambiguous)\n return matches.length === 1 ? matches[0] : null;\n}\n\n/** Minimum fraction of lines that must match for partial fuzzy matching. */\nconst FUZZY_MATCH_THRESHOLD = 0.6;\n\n/**\n * Partial fuzzy matching — tolerates some lines being slightly different.\n * LLMs often reconstruct code from memory with subtle differences on a few lines\n * (e.g., changed variable name, missing semicolon). This layer finds the best-scoring\n * region where at least FUZZY_MATCH_THRESHOLD of lines match after trimming.\n *\n * Returns `{ start, end }` character offsets if a single high-confidence region is found.\n */\nfunction findPartialFuzzyMatch(\n content: string,\n oldStr: string\n): { start: number; end: number } | null {\n const contentLines = content.split('\\n');\n const oldLines = oldStr.split('\\n');\n\n // Need at least 3 lines for fuzzy matching to be meaningful\n if (oldLines.length < 3) return null;\n\n const oldTrimmed = oldLines.map((l) => l.trim());\n const minScore = Math.ceil(oldLines.length * FUZZY_MATCH_THRESHOLD);\n\n let bestScore = 0;\n let bestIdx = -1;\n let secondBestScore = 0;\n\n for (let i = 0; i <= contentLines.length - oldLines.length; i++) {\n let score = 0;\n for (let j = 0; j < oldLines.length; j++) {\n const contentTrimmed = contentLines[i + j].trim();\n // Exact match after trimming all whitespace\n if (contentTrimmed === oldTrimmed[j]) {\n score++;\n } else if (\n // Substring match — one contains the other (handles minor edits)\n contentTrimmed.length > 0 &&\n oldTrimmed[j].length > 0 &&\n (contentTrimmed.includes(oldTrimmed[j]) ||\n oldTrimmed[j].includes(contentTrimmed))\n ) {\n score += 0.5;\n }\n }\n if (score > bestScore) {\n secondBestScore = bestScore;\n bestScore = score;\n bestIdx = i;\n } else if (score > secondBestScore) {\n secondBestScore = score;\n }\n }\n\n // Require: meets threshold AND is clearly better than second-best (unique match)\n if (\n bestIdx < 0 ||\n bestScore < minScore ||\n secondBestScore >= bestScore * 0.9\n ) {\n return null;\n }\n\n // Calculate character offsets\n let charStart = 0;\n for (let k = 0; k < bestIdx; k++) {\n charStart += contentLines[k].length + 1;\n }\n let charEnd = charStart;\n for (let k = 0; k < oldLines.length; k++) {\n charEnd +=\n contentLines[bestIdx + k].length + (k < oldLines.length - 1 ? 1 : 0);\n }\n return { start: charStart, end: charEnd };\n}\n\n/**\n * Find the best approximate match location for `needle` in `haystack` using\n * overlapping line content. Returns the 1-based line number of the best match\n * region, or 0 if no reasonable overlap is found.\n */\nfunction findApproximateLocation(haystack: string, needle: string): number {\n const needleLines = needle\n .split('\\n')\n .map((l) => l.trim())\n .filter(Boolean);\n if (needleLines.length === 0) return 0;\n\n const haystackLines = haystack.split('\\n');\n let bestScore = 0;\n let bestLine = 0;\n\n for (let i = 0; i < haystackLines.length; i++) {\n let score = 0;\n for (\n let j = 0;\n j < needleLines.length && i + j < haystackLines.length;\n j++\n ) {\n if (\n haystackLines[i + j].trim().includes(needleLines[j]) ||\n needleLines[j].includes(haystackLines[i + j].trim())\n ) {\n score++;\n }\n }\n if (score > bestScore) {\n bestScore = score;\n bestLine = i + 1; // 1-based\n }\n }\n\n // Require at least 1 matching line to report a location\n return bestScore >= 1 ? bestLine : 0;\n}\n\n/**\n * Build a diagnostic error message showing nearby content when an edit match fails.\n */\nfunction buildEditDiagnostic(content: string, oldStr: string): string {\n const approxLine = findApproximateLocation(content, oldStr);\n const lines = content.split('\\n');\n\n let contextSnippet = '';\n if (approxLine > 0) {\n const start = Math.max(\n 0,\n approxLine - 1 - Math.floor(ERROR_CONTEXT_LINES / 2)\n );\n const end = Math.min(lines.length, start + ERROR_CONTEXT_LINES);\n const padWidth = String(end).length;\n const snippet = lines\n .slice(start, end)\n .map((l, i) => `${String(start + i + 1).padStart(padWidth, ' ')} | ${l}`)\n .join('\\n');\n contextSnippet = `\\nNearest content (around line ${approxLine}):\\n${snippet}`;\n }\n\n return `old_str not found in content. Re-read the file with content_tool read before retrying.${contextSnippet}`;\n}\n\n/**\n * Strip line-number prefixes (\" N | \") that readLines() adds.\n * Agents may copy these when constructing old_str for edits.\n */\nfunction stripLineNumberPrefixes(text: string): string {\n return text\n .split('\\n')\n .map((line) => {\n const match = line.match(/^\\s*\\d+\\s*\\|\\s?(.*)/);\n return match ? match[1] : line;\n })\n .join('\\n');\n}\n\n/**\n * Generates a short, URL-safe random ID.\n * @param length - Number of random bytes (output is hex, so 2x chars). Default 5 → 10 hex chars.\n */\nfunction generateId(length = 5): string {\n return crypto.randomBytes(length).toString('hex');\n}\n\n/**\n * Per-conversation content store backed by a caller-provided {@link Keyv}\n * cache (typically Keyv + @keyv/redis, with in-memory fallback).\n *\n * Stores large content (MCP results, artifacts, agent-generated text)\n * outside the LLM context window. Entries inherit the TTL configured on\n * the injected {@link Keyv} instance — {@link CONTENT_TTL_MS} is the\n * recommended default.\n *\n * The caller is responsible for namespacing the Keyv instance per\n * conversation so content_ids don't collide across threads.\n *\n * @example\n * ```ts\n * import Keyv from 'keyv';\n * const cache = new Keyv({ namespace: `content-store::${conversationId}`, ttl: CONTENT_TTL_MS });\n * const store = new ContentStore(cache);\n * const id = await store.store({ name: 'report.csv', type: 'text/plain', content: csv, source: 'mcp:sharepoint' });\n * const result = await store.readLines(id, 1, 50);\n * ```\n */\nexport class ContentStore {\n protected indexKey = '_index';\n\n /**\n * @param cache - A pre-namespaced {@link Keyv} instance. The store\n * writes both content entries and a per-store `_index` key, so\n * callers MUST namespace the Keyv per conversation to avoid\n * cross-thread collisions.\n */\n constructor(protected cache: Keyv) {}\n\n /**\n * Store new content and return a content ID.\n * @param entry - The content to store with metadata.\n * @returns The generated content ID.\n */\n async store(entry: StoreEntry): Promise<string> {\n const id = generateId();\n const lines = entry.content.split('\\n');\n\n const metadata: ContentMetadata = {\n id,\n name: entry.name,\n type: entry.type,\n source: entry.source,\n totalLines: lines.length,\n totalChars: entry.content.length,\n createdAt: Date.now(),\n };\n\n const stored: StoredEntry = { content: entry.content, metadata };\n await this.cache.set(id, JSON.stringify(stored));\n\n // Update the index\n const index = await this.getIndex();\n index[id] = metadata;\n await this.cache.set(this.indexKey, JSON.stringify(index));\n\n return id;\n }\n\n /**\n * Get metadata for a content entry without loading the full content.\n * @param contentId - The content entry ID.\n * @returns Metadata or null if not found.\n */\n async info(contentId: string): Promise<ContentMetadata | null> {\n const stored = await this.getStored(contentId);\n if (!stored) {\n return null;\n }\n // Touch both content entry and index to reset TTL\n await this.touchEntry(contentId, stored);\n return stored.metadata;\n }\n\n /**\n * Read lines from a content entry with optional range.\n * Lines are 1-based and inclusive. Returns formatted content with line numbers.\n *\n * @param contentId - The content entry ID.\n * @param startLine - First line to read (1-based, default 1).\n * @param endLine - Last line to read (inclusive, default startLine + DEFAULT_READ_LINES - 1).\n * @returns Read result with formatted content and range info, or null if not found.\n */\n async readLines(\n contentId: string,\n startLine?: number,\n endLine?: number\n ): Promise<ReadResult | null> {\n const stored = await this.getStored(contentId);\n if (!stored) {\n return null;\n }\n\n const lines = stored.content.split('\\n');\n const totalLines = lines.length;\n\n // Clamp start to valid range\n const start = Math.max(1, startLine ?? 1);\n // Clamp end: default to start + DEFAULT_READ_LINES - 1, cap at totalLines and start + MAX_READ_LINES - 1\n let end = endLine ?? start + DEFAULT_READ_LINES - 1;\n end = Math.min(end, totalLines, start + MAX_READ_LINES - 1);\n\n // Slice is 0-based, our line numbers are 1-based\n const slice = lines.slice(start - 1, end);\n\n // Format with line numbers (padded for alignment)\n const padWidth = String(end).length;\n const formatted = slice\n .map((line, i) => {\n const lineNum = String(start + i).padStart(padWidth, ' ');\n return `${lineNum} | ${line}`;\n })\n .join('\\n');\n\n // Touch both content entry and index to reset TTL\n await this.touchEntry(contentId, stored);\n\n return {\n content: formatted,\n startLine: start,\n endLine: end,\n totalLines,\n totalChars: stored.content.length,\n truncated: end < totalLines,\n };\n }\n\n /**\n * Read the full content of an entry without line-number formatting or line caps.\n * Used by API endpoints that serve complete content to the frontend (e.g., CodeViz).\n * Unlike readLines(), this has no MAX_READ_LINES cap and returns raw content.\n *\n * @param contentId - The content entry ID.\n * @returns Raw content with total line/char counts, or null if not found.\n */\n async readAll(contentId: string): Promise<ReadAllResult | null> {\n const stored = await this.getStored(contentId);\n if (!stored) {\n return null;\n }\n\n // Touch both content entry and index to reset TTL\n await this.touchEntry(contentId, stored);\n\n return {\n content: stored.content,\n totalLines: stored.content.split('\\n').length,\n totalChars: stored.content.length,\n };\n }\n\n /**\n * Search for a pattern within a content entry.\n * Supports plain text matching and regex patterns.\n *\n * @param contentId - The content entry ID.\n * @param pattern - Text or regex pattern to match.\n * @param maxResults - Maximum matches to return (default MAX_SEARCH_RESULTS).\n * @returns Array of matches with line numbers, or null if content not found.\n */\n async search(\n contentId: string,\n pattern: string,\n maxResults = MAX_SEARCH_RESULTS\n ): Promise<SearchMatch[] | null> {\n const stored = await this.getStored(contentId);\n if (!stored) {\n return null;\n }\n\n const lines = stored.content.split('\\n');\n const matches: SearchMatch[] = [];\n\n // Try regex first, fall back to plain string match\n let regex: RegExp | null = null;\n try {\n regex = new RegExp(pattern, 'i');\n } catch {\n // Invalid regex — use plain string matching below\n }\n\n for (let i = 0; i < lines.length && matches.length < maxResults; i++) {\n const line = lines[i];\n const isMatch = regex ? regex.test(line) : line.includes(pattern);\n if (isMatch) {\n matches.push({ lineNumber: i + 1, content: line });\n }\n }\n\n // Touch both content entry and index to reset TTL\n await this.touchEntry(contentId, stored);\n\n return matches;\n }\n\n /**\n * Surgical string replacement within a content entry.\n * Fails if old_str is not found or appears more than once (ambiguous).\n *\n * Uses layered matching: exact → line-number-stripped → CRLF-normalized → trailing-whitespace-trimmed.\n * On failure, returns diagnostic context showing nearby content to help the agent self-correct.\n *\n * @param contentId - The content entry ID.\n * @param oldStr - Exact string to find.\n * @param newStr - Replacement string.\n * @returns Edit result with diff and affected line info.\n */\n async strReplace(\n contentId: string,\n oldStr: string,\n newStr: string\n ): Promise<EditResult> {\n const stored = await this.getStored(contentId);\n if (!stored) {\n return {\n success: false,\n diff: '',\n lineNumber: 0,\n linesAffected: 0,\n error: `Content \"${contentId}\" not found`,\n };\n }\n\n const content = stored.content;\n let effectiveOldStr = oldStr;\n let firstIdx = content.indexOf(effectiveOldStr);\n\n // Layer 1: Strip line-number prefixes that readLines() adds.\n // Agents often copy formatted output (e.g., \" 1 | import React\") into old_str.\n if (firstIdx === -1) {\n const stripped = stripLineNumberPrefixes(oldStr);\n if (stripped !== oldStr) {\n firstIdx = content.indexOf(stripped);\n if (firstIdx !== -1) {\n effectiveOldStr = stripped;\n }\n }\n }\n\n // Layer 2: Normalize CRLF → LF (content from Windows/Office/MCP tools may have \\r\\n)\n if (firstIdx === -1) {\n const normContent = normalizeNewlines(content);\n const normOld = normalizeNewlines(effectiveOldStr);\n if (normContent !== content || normOld !== effectiveOldStr) {\n const normIdx = normContent.indexOf(normOld);\n if (normIdx !== -1) {\n // Normalize stored content permanently so future edits don't hit this again\n stored.content = normContent;\n effectiveOldStr = normOld;\n firstIdx = normIdx;\n }\n }\n }\n\n // Layer 3: Trim trailing whitespace per line (invisible trailing spaces cause mismatches)\n if (firstIdx === -1) {\n const trimmedContent = trimTrailingPerLine(stored.content);\n const trimmedOld = trimTrailingPerLine(effectiveOldStr);\n if (trimmedContent !== stored.content || trimmedOld !== effectiveOldStr) {\n const trimIdx = trimmedContent.indexOf(trimmedOld);\n if (trimIdx !== -1) {\n // Use trimmed content for matching; map back to actual content position\n // by finding the equivalent position in the original\n stored.content = trimmedContent;\n effectiveOldStr = trimmedOld;\n firstIdx = trimIdx;\n }\n }\n }\n\n // Layer 4: Indentation-normalized line-by-line matching.\n // Agent often gets the right code but with different indentation (e.g., 2 vs 4 spaces).\n // Match lines by trimmed content, then replace the actual content range.\n let rangeMatch: { start: number; end: number } | null = null;\n if (firstIdx === -1) {\n rangeMatch = findIndentationNormalizedMatch(\n stored.content,\n effectiveOldStr\n );\n if (rangeMatch) {\n effectiveOldStr = stored.content.substring(\n rangeMatch.start,\n rangeMatch.end\n );\n firstIdx = rangeMatch.start;\n }\n }\n\n // Layer 5: Partial fuzzy matching — tolerates some lines being slightly different.\n // LLMs reconstruct code from memory and often get 80-90% of lines right but miss a few.\n // This layer finds the best-scoring unique region above a match threshold.\n if (firstIdx === -1) {\n rangeMatch = findPartialFuzzyMatch(stored.content, effectiveOldStr);\n if (rangeMatch) {\n effectiveOldStr = stored.content.substring(\n rangeMatch.start,\n rangeMatch.end\n );\n firstIdx = rangeMatch.start;\n }\n }\n\n if (firstIdx === -1) {\n const diagnostic = buildEditDiagnostic(stored.content, oldStr);\n return {\n success: false,\n diff: '',\n lineNumber: 0,\n linesAffected: 0,\n error: diagnostic,\n };\n }\n\n // For range-matched edits (layers 4/5), skip the ambiguity check (already verified unique)\n const lastIdx = rangeMatch\n ? firstIdx\n : stored.content.lastIndexOf(effectiveOldStr);\n if (firstIdx !== lastIdx) {\n return {\n success: false,\n diff: '',\n lineNumber: 0,\n linesAffected: 0,\n error: 'old_str appears multiple times — make it more specific',\n };\n }\n\n // Find the line number where the match starts\n const currentContent = stored.content;\n const beforeMatch = currentContent.substring(0, firstIdx);\n const lineNumber = beforeMatch.split('\\n').length;\n\n // Perform replacement\n const newContent =\n currentContent.substring(0, firstIdx) +\n newStr +\n currentContent.substring(firstIdx + effectiveOldStr.length);\n\n // Build a simple diff\n const oldLines = effectiveOldStr.split('\\n');\n const newLines = newStr.split('\\n');\n let diff = '';\n for (const line of oldLines) {\n diff += `- ${line}\\n`;\n }\n for (const line of newLines) {\n diff += `+ ${line}\\n`;\n }\n\n const linesAffected = Math.max(oldLines.length, newLines.length);\n\n // Update stored content and metadata\n stored.content = newContent;\n stored.metadata.totalLines = newContent.split('\\n').length;\n stored.metadata.totalChars = newContent.length;\n await this.cache.set(contentId, JSON.stringify(stored));\n\n // Update index metadata\n const index = await this.getIndex();\n if (index[contentId]) {\n index[contentId] = stored.metadata;\n await this.cache.set(this.indexKey, JSON.stringify(index));\n }\n\n return { success: true, diff: diff.trimEnd(), lineNumber, linesAffected };\n }\n\n /**\n * Overwrite content for an existing entry, preserving its name/source/type.\n * @param contentId - The content entry ID.\n * @param content - New content to write.\n * @throws If content ID is not found.\n */\n async write(contentId: string, content: string): Promise<void> {\n const stored = await this.getStored(contentId);\n if (!stored) {\n throw new Error(`Content \"${contentId}\" not found`);\n }\n\n stored.content = content;\n stored.metadata.totalLines = content.split('\\n').length;\n stored.metadata.totalChars = content.length;\n await this.cache.set(contentId, JSON.stringify(stored));\n\n // Update index metadata\n const index = await this.getIndex();\n if (index[contentId]) {\n index[contentId] = stored.metadata;\n await this.cache.set(this.indexKey, JSON.stringify(index));\n }\n }\n\n /**\n * List all content entries in this conversation's store.\n * @returns Array of metadata for all entries.\n */\n async list(): Promise<ContentMetadata[]> {\n const index = await this.getIndex();\n // Touch index to reset TTL on access\n if (Object.keys(index).length > 0) {\n await this.cache.set(this.indexKey, JSON.stringify(index));\n }\n return Object.values(index);\n }\n\n /**\n * Get the raw content string for a content entry, without line-number formatting.\n * Resets TTL on access. Used by code edit wrapper to retrieve stored code for execution.\n *\n * @param contentId - The content entry ID.\n * @returns Raw content string, or null if not found/expired.\n */\n async getRawContent(contentId: string): Promise<string | null> {\n const stored = await this.getStored(contentId);\n if (!stored) {\n return null;\n }\n await this.touchEntry(contentId, stored);\n return stored.content;\n }\n\n /**\n * Delete a content entry.\n * @param contentId - The content entry ID.\n */\n async delete(contentId: string): Promise<void> {\n await this.cache.delete(contentId);\n\n const index = await this.getIndex();\n delete index[contentId];\n await this.cache.set(this.indexKey, JSON.stringify(index));\n }\n\n /**\n * Reset TTL on both a content entry and the index.\n * Called on every access to keep active content alive.\n * @param contentId - The content entry ID.\n * @param stored - The stored entry to re-set (resets TTL via Keyv).\n */\n protected async touchEntry(\n contentId: string,\n stored: StoredEntry\n ): Promise<void> {\n await this.cache.set(contentId, JSON.stringify(stored));\n const index = await this.getIndex();\n if (Object.keys(index).length > 0) {\n await this.cache.set(this.indexKey, JSON.stringify(index));\n }\n }\n\n /**\n * Retrieve the full stored entry (content + metadata) from Redis.\n * Returns null if the entry has expired or doesn't exist.\n */\n protected async getStored(contentId: string): Promise<StoredEntry | null> {\n const raw = (await this.cache.get(contentId)) as string | undefined;\n if (!raw) {\n return null;\n }\n try {\n return JSON.parse(raw) as StoredEntry;\n } catch {\n return null;\n }\n }\n\n /**\n * Retrieve the conversation's content index from Redis.\n * The index maps content IDs to their metadata.\n */\n protected async getIndex(): Promise<Record<string, ContentMetadata>> {\n const raw = (await this.cache.get(this.indexKey)) as string | undefined;\n if (!raw) {\n return {};\n }\n try {\n return JSON.parse(raw) as Record<string, ContentMetadata>;\n } catch {\n return {};\n }\n }\n}\n"],"names":[],"mappings":";;;;AAYA;;;;;;;;AAQG;AACI,MAAM,cAAc,GAAG;AAE9B;AACA,MAAM,kBAAkB,GAAG,GAAG;AAE9B;AACA,MAAM,cAAc,GAAG,GAAG;AAE1B;AACA,MAAM,kBAAkB,GAAG,EAAE;AAE7B;AACA,MAAM,mBAAmB,GAAG,CAAC;AAE7B;;;AAGG;AACH,SAAS,iBAAiB,CAAC,IAAY,EAAA;AACrC,IAAA,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC;AACzD;AAEA;;;AAGG;AACH,SAAS,mBAAmB,CAAC,IAAY,EAAA;AACvC,IAAA,OAAO;SACJ,KAAK,CAAC,IAAI;SACV,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE;SACtB,IAAI,CAAC,IAAI,CAAC;AACf;AAEA;;;;;AAKG;AACH,SAAS,8BAA8B,CACrC,OAAe,EACf,MAAc,EAAA;IAEd,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;IACxC,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;;AAGnC,IAAA,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;;AAGrD,IAAA,MAAM,gBAAgB,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAC/D,IAAA,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,IAAI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,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAgB;QACvC;AAAE,QAAA,MAAM;AACN,YAAA,OAAO,IAAI;QACb;IACF;AAEA;;;AAGG;AACO,IAAA,MAAM,QAAQ,GAAA;AACtB,QAAA,MAAM,GAAG,IAAI,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAuB;QACvE,IAAI,CAAC,GAAG,EAAE;AACR,YAAA,OAAO,EAAE;QACX;AACA,QAAA,IAAI;AACF,YAAA,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAoC;QAC3D;AAAE,QAAA,MAAM;AACN,YAAA,OAAO,EAAE;QACX;IACF;AACD;;;;;"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Utilities for measuring, classifying, and previewing content.
|
|
5
|
+
* Used by the content_tool and MCP auto-caching (Phase 2) to decide
|
|
6
|
+
* when content is "large" and how to summarize it for the LLM.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Threshold in characters above which content is considered "large"
|
|
10
|
+
* and should be stored in ContentStore rather than inlined.
|
|
11
|
+
* 50K chars ~ 12.5K tokens ~ 6% of 200K context window.
|
|
12
|
+
*/
|
|
13
|
+
const LARGE_CONTENT_THRESHOLD = 50_000;
|
|
14
|
+
/**
|
|
15
|
+
* Measure content size and determine if it exceeds the large-content threshold.
|
|
16
|
+
* @param text - The content to measure.
|
|
17
|
+
* @returns Measurement with char count, line count, and large flag.
|
|
18
|
+
*/
|
|
19
|
+
function measureContent(text) {
|
|
20
|
+
return {
|
|
21
|
+
totalChars: text.length,
|
|
22
|
+
totalLines: text.split('\n').length,
|
|
23
|
+
isLarge: text.length > LARGE_CONTENT_THRESHOLD,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Detect the structural type of content.
|
|
28
|
+
* @param text - The content to classify.
|
|
29
|
+
* @returns The detected type: 'json_array', 'json_object', 'text', or 'mixed'.
|
|
30
|
+
*/
|
|
31
|
+
function detectContentType(text) {
|
|
32
|
+
const trimmed = text.trim();
|
|
33
|
+
if (!trimmed) {
|
|
34
|
+
return 'text';
|
|
35
|
+
}
|
|
36
|
+
// Fast check: does it look like JSON?
|
|
37
|
+
if (trimmed[0] === '[' || trimmed[0] === '{') {
|
|
38
|
+
try {
|
|
39
|
+
const parsed = JSON.parse(trimmed);
|
|
40
|
+
if (Array.isArray(parsed)) {
|
|
41
|
+
return 'json_array';
|
|
42
|
+
}
|
|
43
|
+
if (typeof parsed === 'object' && parsed !== null) {
|
|
44
|
+
return 'json_object';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// Not valid JSON — might be mixed content
|
|
49
|
+
if (trimmed[0] === '[' || trimmed[0] === '{') {
|
|
50
|
+
return 'mixed';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return 'text';
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Generate a preview/summary of content for the LLM context.
|
|
58
|
+
* For JSON arrays, shows the first N items. For text, truncates with an ellipsis.
|
|
59
|
+
*
|
|
60
|
+
* @param text - The full content to preview.
|
|
61
|
+
* @param opts - Options controlling preview size.
|
|
62
|
+
* @returns A truncated preview string.
|
|
63
|
+
*/
|
|
64
|
+
function generatePreview(text, opts) {
|
|
65
|
+
const maxItems = opts?.maxItems ?? 5;
|
|
66
|
+
const maxChars = opts?.maxChars ?? 2048;
|
|
67
|
+
const contentType = detectContentType(text);
|
|
68
|
+
if (contentType === 'json_array') {
|
|
69
|
+
try {
|
|
70
|
+
const arr = JSON.parse(text.trim());
|
|
71
|
+
if (arr.length <= maxItems) {
|
|
72
|
+
return text.trim();
|
|
73
|
+
}
|
|
74
|
+
const preview = arr.slice(0, maxItems);
|
|
75
|
+
const result = JSON.stringify(preview, null, 2);
|
|
76
|
+
return `${result}\n... (${arr.length - maxItems} more items, ${arr.length} total)`;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
// Fall through to text truncation
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (text.length <= maxChars) {
|
|
83
|
+
return text;
|
|
84
|
+
}
|
|
85
|
+
return `${text.substring(0, maxChars)}\n... (truncated, ${text.length} chars total)`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
exports.detectContentType = detectContentType;
|
|
89
|
+
exports.generatePreview = generatePreview;
|
|
90
|
+
exports.measureContent = measureContent;
|
|
91
|
+
//# sourceMappingURL=contentAnalyzer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contentAnalyzer.cjs","sources":["../../../src/content/contentAnalyzer.ts"],"sourcesContent":["/**\n * Utilities for measuring, classifying, and previewing content.\n * Used by the content_tool and MCP auto-caching (Phase 2) to decide\n * when content is \"large\" and how to summarize it for the LLM.\n */\n\n/**\n * Threshold in characters above which content is considered \"large\"\n * and should be stored in ContentStore rather than inlined.\n * 50K chars ~ 12.5K tokens ~ 6% of 200K context window.\n */\nconst LARGE_CONTENT_THRESHOLD = 50_000;\n\n/** Content size measurements. */\nexport interface ContentMeasurement {\n totalChars: number;\n totalLines: number;\n /** True if content exceeds the large-content threshold. */\n isLarge: boolean;\n}\n\n/** Detected content type. */\nexport type ContentType = 'json_array' | 'json_object' | 'text' | 'mixed';\n\n/**\n * Measure content size and determine if it exceeds the large-content threshold.\n * @param text - The content to measure.\n * @returns Measurement with char count, line count, and large flag.\n */\nexport function measureContent(text: string): ContentMeasurement {\n return {\n totalChars: text.length,\n totalLines: text.split('\\n').length,\n isLarge: text.length > LARGE_CONTENT_THRESHOLD,\n };\n}\n\n/**\n * Detect the structural type of content.\n * @param text - The content to classify.\n * @returns The detected type: 'json_array', 'json_object', 'text', or 'mixed'.\n */\nexport function detectContentType(text: string): ContentType {\n const trimmed = text.trim();\n if (!trimmed) {\n return 'text';\n }\n\n // Fast check: does it look like JSON?\n if (trimmed[0] === '[' || trimmed[0] === '{') {\n try {\n const parsed = JSON.parse(trimmed);\n if (Array.isArray(parsed)) {\n return 'json_array';\n }\n if (typeof parsed === 'object' && parsed !== null) {\n return 'json_object';\n }\n } catch {\n // Not valid JSON — might be mixed content\n if (trimmed[0] === '[' || trimmed[0] === '{') {\n return 'mixed';\n }\n }\n }\n\n return 'text';\n}\n\n/**\n * Generate a preview/summary of content for the LLM context.\n * For JSON arrays, shows the first N items. For text, truncates with an ellipsis.\n *\n * @param text - The full content to preview.\n * @param opts - Options controlling preview size.\n * @returns A truncated preview string.\n */\nexport function generatePreview(\n text: string,\n opts?: { maxItems?: number; maxChars?: number }\n): string {\n const maxItems = opts?.maxItems ?? 5;\n const maxChars = opts?.maxChars ?? 2048;\n const contentType = detectContentType(text);\n\n if (contentType === 'json_array') {\n try {\n const arr = JSON.parse(text.trim()) as unknown[];\n if (arr.length <= maxItems) {\n return text.trim();\n }\n const preview = arr.slice(0, maxItems);\n const result = JSON.stringify(preview, null, 2);\n return `${result}\\n... (${arr.length - maxItems} more items, ${arr.length} total)`;\n } catch {\n // Fall through to text truncation\n }\n }\n\n if (text.length <= maxChars) {\n return text;\n }\n\n return `${text.substring(0, maxChars)}\\n... (truncated, ${text.length} chars total)`;\n}\n"],"names":[],"mappings":";;AAAA;;;;AAIG;AAEH;;;;AAIG;AACH,MAAM,uBAAuB,GAAG,MAAM;AAatC;;;;AAIG;AACG,SAAU,cAAc,CAAC,IAAY,EAAA;IACzC,OAAO;QACL,UAAU,EAAE,IAAI,CAAC,MAAM;QACvB,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM;AACnC,QAAA,OAAO,EAAE,IAAI,CAAC,MAAM,GAAG,uBAAuB;KAC/C;AACH;AAEA;;;;AAIG;AACG,SAAU,iBAAiB,CAAC,IAAY,EAAA;AAC5C,IAAA,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE;IAC3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,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAC/C,YAAA,OAAO,CAAA,EAAG,MAAM,CAAA,OAAA,EAAU,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAA,aAAA,EAAgB,GAAG,CAAC,MAAM,SAAS;QACpF;AAAE,QAAA,MAAM;;QAER;IACF;AAEA,IAAA,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ,EAAE;AAC3B,QAAA,OAAO,IAAI;IACb;AAEA,IAAA,OAAO,CAAA,EAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA,kBAAA,EAAqB,IAAI,CAAC,MAAM,eAAe;AACtF;;;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ContentStore = require('./ContentStore.cjs');
|
|
4
|
+
var ArtifactStore = require('./ArtifactStore.cjs');
|
|
5
|
+
var contentAnalyzer = require('./contentAnalyzer.cjs');
|
|
6
|
+
var mcpAutoCache = require('./mcpAutoCache.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.CONTENT_TTL_MS = ContentStore.CONTENT_TTL_MS;
|
|
11
|
+
exports.ContentStore = ContentStore.ContentStore;
|
|
12
|
+
exports.ArtifactStore = ArtifactStore.ArtifactStore;
|
|
13
|
+
exports.sanitizeName = ArtifactStore.sanitizeName;
|
|
14
|
+
exports.detectContentType = contentAnalyzer.detectContentType;
|
|
15
|
+
exports.generatePreview = contentAnalyzer.generatePreview;
|
|
16
|
+
exports.measureContent = contentAnalyzer.measureContent;
|
|
17
|
+
exports.buildCachedResponse = mcpAutoCache.buildCachedResponse;
|
|
18
|
+
exports.extractUiMarkers = mcpAutoCache.extractUiMarkers;
|
|
19
|
+
exports.interceptMcpResult = mcpAutoCache.interceptMcpResult;
|
|
20
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var contentAnalyzer = require('./contentAnalyzer.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* MCP Auto-Caching Interceptor
|
|
7
|
+
*
|
|
8
|
+
* When an MCP tool returns a large text result (>50K chars / ~12.5K tokens),
|
|
9
|
+
* stores it in the caller-provided {@link ContentStore} and returns a
|
|
10
|
+
* compact metadata reference. The LLM then uses a `content_reader` tool
|
|
11
|
+
* (read/search/list/info) to pull relevant pieces of the stored result
|
|
12
|
+
* without burning tokens on the full payload.
|
|
13
|
+
*
|
|
14
|
+
* Gate: callers MUST pass `contentReaderEnabled: true` on the context —
|
|
15
|
+
* otherwise the interceptor returns the original text unchanged, because
|
|
16
|
+
* caching without a reader tool leaves the agent with a content_id it
|
|
17
|
+
* cannot dereference.
|
|
18
|
+
*
|
|
19
|
+
* Design:
|
|
20
|
+
* - Only text content is cached. Images and UI resources pass through.
|
|
21
|
+
* - UI resource markers (\ui{...}) are preserved in the returned text.
|
|
22
|
+
* - Artifacts (second element of the tuple) are never modified.
|
|
23
|
+
* - Cached response is a compact one-liner (~30 tokens) — no preview blob.
|
|
24
|
+
* - If the store write fails, degrades gracefully — returns original text.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Regex to detect UI resource markers: \ui{...}
|
|
28
|
+
* These MUST be preserved in the returned text even after caching.
|
|
29
|
+
*/
|
|
30
|
+
const UI_MARKER_REGEX = /\\ui\{[^}]+\}/g;
|
|
31
|
+
/**
|
|
32
|
+
* Extract all UI resource markers from text.
|
|
33
|
+
* @param text - The text to scan.
|
|
34
|
+
* @returns Array of marker strings (e.g. ['\\ui{abc123}', '\\ui{def456}'])
|
|
35
|
+
*/
|
|
36
|
+
function extractUiMarkers(text) {
|
|
37
|
+
return text.match(UI_MARKER_REGEX) ?? [];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build a compact metadata reference for the cached content.
|
|
41
|
+
* Keeps token usage minimal (~30 tokens) while giving the LLM all it needs
|
|
42
|
+
* to access the data via content_tool.
|
|
43
|
+
*
|
|
44
|
+
* @param contentId - ContentStore entry ID.
|
|
45
|
+
* @param measurement - Size data.
|
|
46
|
+
* @param toolName - The MCP tool that produced the result.
|
|
47
|
+
* @param uiMarkers - UI markers extracted from the original text.
|
|
48
|
+
*/
|
|
49
|
+
function buildCachedResponse(contentId, measurement, toolName, uiMarkers) {
|
|
50
|
+
const sizeKB = (measurement.totalChars / 1024).toFixed(0);
|
|
51
|
+
let response = `[Stored: ${toolName} result | ${sizeKB}KB | ${measurement.totalLines} lines | content_id: ${contentId}]\nUse content_reader (action: read or search) with this content_id to access the full result — do NOT re-run the MCP tool.`;
|
|
52
|
+
if (uiMarkers.length > 0) {
|
|
53
|
+
response += '\n\n' + uiMarkers.join('\n');
|
|
54
|
+
}
|
|
55
|
+
return response;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Core auto-cache interceptor for MCP tool results.
|
|
59
|
+
*
|
|
60
|
+
* If the text exceeds the large-content threshold (50K chars), stores it
|
|
61
|
+
* in ContentStore and returns a preview + content_id. Otherwise passes through.
|
|
62
|
+
*
|
|
63
|
+
* @param text - The text content from the MCP tool result.
|
|
64
|
+
* @param context - MCP tool and conversation context.
|
|
65
|
+
* @returns AutoCacheResult with possibly-modified text and caching metadata.
|
|
66
|
+
*/
|
|
67
|
+
async function interceptMcpResult(text, context) {
|
|
68
|
+
const measurement = contentAnalyzer.measureContent(text);
|
|
69
|
+
const log = context.logger;
|
|
70
|
+
if (!measurement.isLarge) {
|
|
71
|
+
return { text, cached: false, measurement };
|
|
72
|
+
}
|
|
73
|
+
// Gate: caching only makes sense when the agent can read back the stub.
|
|
74
|
+
// If content_reader is disabled, returning a content_id the agent can't
|
|
75
|
+
// dereference is strictly worse than returning the full text — the model
|
|
76
|
+
// would either hallucinate tool calls or flag the result as inaccessible.
|
|
77
|
+
if (!context.contentReaderEnabled) {
|
|
78
|
+
log?.debug(`[MCP Auto-Cache] Skipped caching for ${context.serverName}:${context.toolName} — content_reader disabled on this agent`, {
|
|
79
|
+
totalChars: measurement.totalChars,
|
|
80
|
+
totalLines: measurement.totalLines,
|
|
81
|
+
conversationId: context.conversationId,
|
|
82
|
+
});
|
|
83
|
+
return { text, cached: false, measurement };
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const contentType = contentAnalyzer.detectContentType(text);
|
|
87
|
+
const contentId = await context.store.store({
|
|
88
|
+
name: `${context.toolName} result`,
|
|
89
|
+
type: contentType === 'text' ? 'text/plain' : 'application/json',
|
|
90
|
+
content: text,
|
|
91
|
+
source: `mcp:${context.serverName}`,
|
|
92
|
+
});
|
|
93
|
+
const uiMarkers = extractUiMarkers(text);
|
|
94
|
+
const replacementText = buildCachedResponse(contentId, measurement, context.toolName, uiMarkers);
|
|
95
|
+
log?.debug(`[MCP Auto-Cache] Cached large result from ${context.serverName}:${context.toolName}`, {
|
|
96
|
+
contentId,
|
|
97
|
+
totalChars: measurement.totalChars,
|
|
98
|
+
totalLines: measurement.totalLines,
|
|
99
|
+
conversationId: context.conversationId,
|
|
100
|
+
contentType,
|
|
101
|
+
uiMarkersPreserved: uiMarkers.length,
|
|
102
|
+
});
|
|
103
|
+
return { text: replacementText, cached: true, contentId, measurement };
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
// PERF: If caching fails, fall through silently — full content goes to LLM
|
|
107
|
+
log?.warn(`[MCP Auto-Cache] Failed to cache result from ${context.serverName}:${context.toolName}, passing through`, { error: error.message });
|
|
108
|
+
return { text, cached: false, measurement };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
exports.buildCachedResponse = buildCachedResponse;
|
|
113
|
+
exports.extractUiMarkers = extractUiMarkers;
|
|
114
|
+
exports.interceptMcpResult = interceptMcpResult;
|
|
115
|
+
//# sourceMappingURL=mcpAutoCache.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpAutoCache.cjs","sources":["../../../src/content/mcpAutoCache.ts"],"sourcesContent":["/**\n * MCP Auto-Caching Interceptor\n *\n * When an MCP tool returns a large text result (>50K chars / ~12.5K tokens),\n * stores it in the caller-provided {@link ContentStore} and returns a\n * compact metadata reference. The LLM then uses a `content_reader` tool\n * (read/search/list/info) to pull relevant pieces of the stored result\n * without burning tokens on the full payload.\n *\n * Gate: callers MUST pass `contentReaderEnabled: true` on the context —\n * otherwise the interceptor returns the original text unchanged, because\n * caching without a reader tool leaves the agent with a content_id it\n * cannot dereference.\n *\n * Design:\n * - Only text content is cached. Images and UI resources pass through.\n * - UI resource markers (\\ui{...}) are preserved in the returned text.\n * - Artifacts (second element of the tuple) are never modified.\n * - Cached response is a compact one-liner (~30 tokens) — no preview blob.\n * - If the store write fails, degrades gracefully — returns original text.\n */\n\nimport { ContentStore } from './ContentStore';\nimport { measureContent, detectContentType } from './contentAnalyzer';\nimport type { Logger } from './ArtifactStore';\nimport type { ContentMeasurement } from './contentAnalyzer';\n\n/** Context for the auto-cache interceptor. */\nexport interface AutoCacheContext {\n /**\n * Pre-constructed {@link ContentStore} instance scoped to the current\n * conversation. Caller owns the underlying cache lifecycle.\n */\n store: ContentStore;\n /** MCP server name (e.g. \"sharepoint\", \"github\"). */\n serverName: string;\n /** MCP tool name (e.g. \"read_file\", \"search_code\"). */\n toolName: string;\n /**\n * Whether the current agent has `content_reader` available. When false,\n * the interceptor passes the large text through unchanged — caching\n * without a reader tool leaves the agent with a content_id it cannot\n * dereference, which is worse than returning the raw text.\n */\n contentReaderEnabled: boolean;\n /**\n * Optional diagnostic echo. Typically the conversation ID so operators\n * can correlate the log line with upstream traces.\n */\n conversationId?: string;\n /** Optional logger; defaults to silence. */\n logger?: Logger;\n}\n\n/** Result of the auto-cache interception. */\nexport interface AutoCacheResult {\n /** The (possibly modified) text content to return to the LLM. */\n text: string;\n /** Whether the content was cached. */\n cached: boolean;\n /** The content_id if cached. */\n contentId?: string;\n /** Content measurement data. */\n measurement?: ContentMeasurement;\n}\n\n/**\n * Regex to detect UI resource markers: \\ui{...}\n * These MUST be preserved in the returned text even after caching.\n */\nconst UI_MARKER_REGEX = /\\\\ui\\{[^}]+\\}/g;\n\n/**\n * Extract all UI resource markers from text.\n * @param text - The text to scan.\n * @returns Array of marker strings (e.g. ['\\\\ui{abc123}', '\\\\ui{def456}'])\n */\nexport function extractUiMarkers(text: string): string[] {\n return text.match(UI_MARKER_REGEX) ?? [];\n}\n\n/**\n * Build a compact metadata reference for the cached content.\n * Keeps token usage minimal (~30 tokens) while giving the LLM all it needs\n * to access the data via content_tool.\n *\n * @param contentId - ContentStore entry ID.\n * @param measurement - Size data.\n * @param toolName - The MCP tool that produced the result.\n * @param uiMarkers - UI markers extracted from the original text.\n */\nexport function buildCachedResponse(\n contentId: string,\n measurement: ContentMeasurement,\n toolName: string,\n uiMarkers: string[]\n): string {\n const sizeKB = (measurement.totalChars / 1024).toFixed(0);\n let response = `[Stored: ${toolName} result | ${sizeKB}KB | ${measurement.totalLines} lines | content_id: ${contentId}]\\nUse content_reader (action: read or search) with this content_id to access the full result — do NOT re-run the MCP tool.`;\n\n if (uiMarkers.length > 0) {\n response += '\\n\\n' + uiMarkers.join('\\n');\n }\n\n return response;\n}\n\n/**\n * Core auto-cache interceptor for MCP tool results.\n *\n * If the text exceeds the large-content threshold (50K chars), stores it\n * in ContentStore and returns a preview + content_id. Otherwise passes through.\n *\n * @param text - The text content from the MCP tool result.\n * @param context - MCP tool and conversation context.\n * @returns AutoCacheResult with possibly-modified text and caching metadata.\n */\nexport async function interceptMcpResult(\n text: string,\n context: AutoCacheContext\n): Promise<AutoCacheResult> {\n const measurement = measureContent(text);\n const log = context.logger;\n\n if (!measurement.isLarge) {\n return { text, cached: false, measurement };\n }\n\n // Gate: caching only makes sense when the agent can read back the stub.\n // If content_reader is disabled, returning a content_id the agent can't\n // dereference is strictly worse than returning the full text — the model\n // would either hallucinate tool calls or flag the result as inaccessible.\n if (!context.contentReaderEnabled) {\n log?.debug(\n `[MCP Auto-Cache] Skipped caching for ${context.serverName}:${context.toolName} — content_reader disabled on this agent`,\n {\n totalChars: measurement.totalChars,\n totalLines: measurement.totalLines,\n conversationId: context.conversationId,\n }\n );\n return { text, cached: false, measurement };\n }\n\n try {\n const contentType = detectContentType(text);\n\n const contentId = await context.store.store({\n name: `${context.toolName} result`,\n type: contentType === 'text' ? 'text/plain' : 'application/json',\n content: text,\n source: `mcp:${context.serverName}`,\n });\n\n const uiMarkers = extractUiMarkers(text);\n\n const replacementText = buildCachedResponse(\n contentId,\n measurement,\n context.toolName,\n uiMarkers\n );\n\n log?.debug(\n `[MCP Auto-Cache] Cached large result from ${context.serverName}:${context.toolName}`,\n {\n contentId,\n totalChars: measurement.totalChars,\n totalLines: measurement.totalLines,\n conversationId: context.conversationId,\n contentType,\n uiMarkersPreserved: uiMarkers.length,\n }\n );\n\n return { text: replacementText, cached: true, contentId, measurement };\n } catch (error) {\n // PERF: If caching fails, fall through silently — full content goes to LLM\n log?.warn(\n `[MCP Auto-Cache] Failed to cache result from ${context.serverName}:${context.toolName}, passing through`,\n { error: (error as Error).message }\n );\n return { text, cached: false, measurement };\n }\n}\n"],"names":["measureContent","detectContentType"],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;;AAoBG;AA8CH;;;AAGG;AACH,MAAM,eAAe,GAAG,gBAAgB;AAExC;;;;AAIG;AACG,SAAU,gBAAgB,CAAC,IAAY,EAAA;IAC3C,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,EAAE;AAC1C;AAEA;;;;;;;;;AASG;AACG,SAAU,mBAAmB,CACjC,SAAiB,EACjB,WAA+B,EAC/B,QAAgB,EAChB,SAAmB,EAAA;AAEnB,IAAA,MAAM,MAAM,GAAG,CAAC,WAAW,CAAC,UAAU,G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,QAAQ,CAAA,OAAA,CAAS;YAClC,IAAI,EAAE,WAAW,KAAK,MAAM,GAAG,YAAY,GAAG,kBAAkB;AAChE,YAAA,OAAO,EAAE,IAAI;AACb,YAAA,MAAM,EAAE,CAAA,IAAA,EAAO,OAAO,CAAC,UAAU,CAAA,CAAE;AACpC,SAAA,CAAC;AAEF,QAAA,MAAM,SAAS,GAAG,gBAAgB,CAAC,IAAI,CAAC;AAExC,QAAA,MAAM,eAAe,GAAG,mBAAmB,CACzC,SAAS,EACT,WAAW,EACX,OAAO,CAAC,QAAQ,EAChB,SAAS,CACV;AAED,QAAA,GAAG,EAAE,KAAK,CACR,CAAA,0CAAA,EAA6C,OAAO,CAAC,UAAU,CAAA,CAAA,EAAI,OAAO,CAAC,QAAQ,CAAA,CAAE,EACrF;YACE,SAAS;YACT,UAAU,EAAE,WAAW,CAAC,UAAU;YAClC,UAAU,EAAE,WAAW,CAAC,UAAU;YAClC,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,WAAW;YACX,kBAAkB,EAAE,SAAS,CAAC,MAAM;AACrC,SAAA,CACF;AAED,QAAA,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE;IACxE;IAAE,OAAO,KAAK,EAAE;;QAEd,GAAG,EAAE,IAAI,CACP,CAAA,6CAAA,EAAgD,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,QAAQ,CAAA,iBAAA,CAAmB,EACzG,EAAE,KAAK,EAAG,KAAe,CAAC,OAAO,EAAE,CACpC;QACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE;IAC7C;AACF;;;;;;"}
|
package/dist/cjs/main.cjs
CHANGED
|
@@ -44,6 +44,9 @@ var config$1 = require('./providers/mcp/config.cjs');
|
|
|
44
44
|
var A2ACapabilityProvider = require('./providers/a2a/A2ACapabilityProvider.cjs');
|
|
45
45
|
var client = require('./providers/a2a/client.cjs');
|
|
46
46
|
var config = require('./providers/a2a/config.cjs');
|
|
47
|
+
var ContentStore = require('./content/ContentStore.cjs');
|
|
48
|
+
var ArtifactStore = require('./content/ArtifactStore.cjs');
|
|
49
|
+
var mcpAutoCache = require('./content/mcpAutoCache.cjs');
|
|
47
50
|
var constants$2 = require('./memory/constants.cjs');
|
|
48
51
|
var paths = require('./memory/paths.cjs');
|
|
49
52
|
var pgvectorStore = require('./memory/pgvectorStore.cjs');
|
|
@@ -268,6 +271,13 @@ exports.extractTaskText = client.extractTaskText;
|
|
|
268
271
|
exports.generateRpcId = client.generateRpcId;
|
|
269
272
|
exports.a2aConsoleLogger = config.consoleLogger;
|
|
270
273
|
exports.getA2AEnvDefaults = config.getA2AEnvDefaults;
|
|
274
|
+
exports.CONTENT_TTL_MS = ContentStore.CONTENT_TTL_MS;
|
|
275
|
+
exports.ContentStore = ContentStore.ContentStore;
|
|
276
|
+
exports.ArtifactStore = ArtifactStore.ArtifactStore;
|
|
277
|
+
exports.sanitizeName = ArtifactStore.sanitizeName;
|
|
278
|
+
exports.buildCachedResponse = mcpAutoCache.buildCachedResponse;
|
|
279
|
+
exports.extractUiMarkers = mcpAutoCache.extractUiMarkers;
|
|
280
|
+
exports.interceptMcpResult = mcpAutoCache.interceptMcpResult;
|
|
271
281
|
exports.DEFAULT_CITATIONS_MODE = constants$2.DEFAULT_CITATIONS_MODE;
|
|
272
282
|
exports.DEFAULT_FLUSH_RESERVE_FLOOR_TOKENS = constants$2.DEFAULT_FLUSH_RESERVE_FLOOR_TOKENS;
|
|
273
283
|
exports.DEFAULT_FLUSH_SOFT_THRESHOLD_TOKENS = constants$2.DEFAULT_FLUSH_SOFT_THRESHOLD_TOKENS;
|
package/dist/cjs/main.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -22,9 +22,10 @@ class ToolsServerCapabilityProvider {
|
|
|
22
22
|
manifestPath;
|
|
23
23
|
executePath;
|
|
24
24
|
cache;
|
|
25
|
+
getExecuteAuthHeaders;
|
|
25
26
|
constructor(config) {
|
|
26
27
|
this.config = config;
|
|
27
|
-
const { baseUrl, apiKey, manifestPath = '/manifest', executePath = '/execute/:name', timeoutMs = 30_000, manifestTtlMs = 60_000, client, proxy, } = config;
|
|
28
|
+
const { baseUrl, apiKey, manifestPath = '/manifest', executePath = '/execute/:name', timeoutMs = 30_000, manifestTtlMs = 60_000, client, proxy, getExecuteAuthHeaders, } = config;
|
|
28
29
|
if (!baseUrl) {
|
|
29
30
|
throw new Error('ToolsServerCapabilityProvider: baseUrl is required');
|
|
30
31
|
}
|
|
@@ -35,6 +36,7 @@ class ToolsServerCapabilityProvider {
|
|
|
35
36
|
this.manifestPath = manifestPath;
|
|
36
37
|
this.executePath = executePath;
|
|
37
38
|
this.cache = new toolManifest.ManifestCache({ ttlMs: manifestTtlMs });
|
|
39
|
+
this.getExecuteAuthHeaders = getExecuteAuthHeaders;
|
|
38
40
|
if (client) {
|
|
39
41
|
this.client = client;
|
|
40
42
|
}
|
|
@@ -81,6 +83,7 @@ class ToolsServerCapabilityProvider {
|
|
|
81
83
|
return capabilities.map((cap) => proxyTool.buildProxyTool(cap, credentials, {
|
|
82
84
|
client: this.client,
|
|
83
85
|
executePath: this.executePath,
|
|
86
|
+
getAuthHeaders: this.getExecuteAuthHeaders,
|
|
84
87
|
}));
|
|
85
88
|
}
|
|
86
89
|
/** Force a manifest refresh on next fetchManifest call. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolsServerCapabilityProvider.cjs","sources":["../../../../src/providers/tools-server/ToolsServerCapabilityProvider.ts"],"sourcesContent":["/**\n * ToolsServerCapabilityProvider — capabilities sourced from a tools-server\n * HTTP endpoint.\n *\n * Fetches the manifest via GET /manifest, builds proxy StructuredTools via\n * POST /execute/:tool. Manifest is cached (TTL-configurable) so repeated\n * init cycles don't refetch.\n *\n * See docs/architecture-capability-layer.md for the design rationale.\n */\n\nimport type { AxiosInstance } from 'axios';\nimport type { StructuredToolInterface } from '@langchain/core/tools';\nimport {\n CapabilityKind,\n type Capability,\n type CapabilityFilter,\n type CapabilityProvider,\n type CredentialMap,\n} from '@/providers/types';\nimport {\n createHttpClient,\n type HttpClientConfig,\n assertOk,\n} from '@/utils/httpClient';\nimport {\n ManifestCache,\n filterToCacheKey,\n applyFilter,\n} from '@/utils/toolManifest';\nimport { buildProxyTool } from '@/tools/proxyTool';\n\n/** Configuration for ToolsServerCapabilityProvider. */\nexport interface ToolsServerConfig {\n /** Tools-server base URL (e.g., https://tools.illuma.ai or http://localhost:3500). */\n baseUrl: string;\n /** API key sent as x-api-key header on all requests. Required. */\n apiKey: string;\n /** Optional override for manifest path. Defaults to `/manifest`. */\n manifestPath?: string;\n /** Optional override for execute path template. Defaults to `/execute/:name`. */\n executePath?: string;\n /** Request timeout in ms. Defaults to 30_000. */\n timeoutMs?: number;\n /** Manifest cache TTL in ms. 0 disables. Defaults to 60_000 (1 min). */\n manifestTtlMs?: number;\n /** Optional pre-built axios instance (for testing). */\n client?: AxiosInstance;\n /** Optional proxy override (defaults to process.env.PROXY). */\n proxy?: string | null;\n}\n\n/**\n * Shape of a single entry from tools-server's /manifest response.\n *\n * Matches the tools-server ManifestToolEntry type. We define our own here\n * to avoid cross-package coupling — the shape is a stable HTTP contract.\n */\ninterface ToolsServerManifestEntry {\n pluginKey: string;\n name: string;\n description: string;\n icon?: string;\n authConfig?: Array<{\n authField: string;\n label?: string;\n description?: string;\n source?: string;\n required?: boolean;\n prod?: boolean;\n admin?: boolean;\n hide?: boolean;\n }>;\n /** Input schema as JSON Schema (tools-server emits `schema`). */\n schema?: unknown;\n /** Legacy alias accepted for backwards compatibility. */\n jsonSchema?: unknown;\n category?: string;\n tags?: string[];\n toolkit?: string;\n endpoint?: string;\n /** Governance flags forwarded by tools-server getManifest(). */\n hidden?: boolean;\n admin?: boolean;\n env?: Array<'development' | 'production' | 'test' | 'staging'>;\n}\n\nexport class ToolsServerCapabilityProvider implements CapabilityProvider {\n readonly providerId: string;\n private readonly client: AxiosInstance;\n private readonly manifestPath: string;\n private readonly executePath: string;\n private readonly cache: ManifestCache;\n\n constructor(private readonly config: ToolsServerConfig) {\n const {\n baseUrl,\n apiKey,\n manifestPath = '/manifest',\n executePath = '/execute/:name',\n timeoutMs = 30_000,\n manifestTtlMs = 60_000,\n client,\n proxy,\n } = config;\n\n if (!baseUrl) {\n throw new Error('ToolsServerCapabilityProvider: baseUrl is required');\n }\n if (!apiKey) {\n throw new Error('ToolsServerCapabilityProvider: apiKey is required');\n }\n\n this.providerId = `tools-server:${baseUrl}`;\n this.manifestPath = manifestPath;\n this.executePath = executePath;\n this.cache = new ManifestCache({ ttlMs: manifestTtlMs });\n\n if (client) {\n this.client = client;\n } else {\n const httpConfig: HttpClientConfig = {\n baseURL: baseUrl,\n apiKey,\n timeoutMs,\n proxy,\n };\n this.client = createHttpClient(httpConfig);\n }\n }\n\n async fetchManifest(filter?: CapabilityFilter): Promise<Capability[]> {\n const cacheKey = filterToCacheKey(filter);\n const cached = this.cache.get(cacheKey);\n if (cached) {\n // DEBUG: cache hit (remove after stabilization)\n // eslint-disable-next-line no-console\n console.debug(\n `[${this.providerId}] manifest cache hit — ${cached.length} caps`\n );\n return cached;\n }\n\n // DEBUG\n // eslint-disable-next-line no-console\n console.debug(\n `[${this.providerId}] fetching manifest from ${this.manifestPath}`\n );\n\n const res = await this.client.get<ToolsServerManifestEntry[]>(\n this.manifestPath\n );\n assertOk(res.status, this.manifestPath, res.data);\n\n const entries = Array.isArray(res.data) ? res.data : [];\n const capabilities: Capability[] = entries.map((entry) =>\n normalizeEntry(entry)\n );\n\n // Apply filter before caching the full list separately so unfiltered\n // refetches don't re-hit the network.\n const fullCacheKey = filterToCacheKey();\n this.cache.set(fullCacheKey, capabilities);\n\n const filtered = applyFilter(capabilities, filter);\n if (cacheKey !== fullCacheKey) {\n this.cache.set(cacheKey, filtered);\n }\n\n // DEBUG\n // eslint-disable-next-line no-console\n console.debug(\n `[${this.providerId}] manifest loaded — ${capabilities.length} caps, ${filtered.length} after filter`\n );\n\n return filtered;\n }\n\n async createRunnables(\n capabilities: Capability[],\n credentials: CredentialMap\n ): Promise<StructuredToolInterface[]> {\n return capabilities.map((cap) =>\n buildProxyTool(cap, credentials, {\n client: this.client,\n executePath: this.executePath,\n })\n );\n }\n\n /** Force a manifest refresh on next fetchManifest call. */\n invalidateCache(): void {\n this.cache.clear();\n }\n}\n\n/**\n * Translate a raw tools-server manifest entry into a typed Capability.\n * Defensive — tools-server may add fields; we pull only what we need.\n */\nfunction normalizeEntry(entry: ToolsServerManifestEntry): Capability {\n return {\n kind: CapabilityKind.TOOL,\n name: entry.pluginKey,\n description: entry.description ?? '',\n schema: entry.schema ?? entry.jsonSchema,\n authConfig: (entry.authConfig ?? []).map((ac) => ({\n authField: ac.authField,\n label: ac.label,\n description: ac.description,\n required: ac.required,\n prod: ac.prod,\n admin: ac.admin,\n hide: ac.hide,\n // Source is a string in wire format; downstream consumers coerce to AuthSource.\n source: ac.source as Capability['authConfig'][number]['source'],\n })),\n metadata: {\n icon: entry.icon,\n category: entry.category,\n tags: entry.tags,\n // Governance — hosts use these to gate UI/role/environment.\n hidden: entry.hidden,\n admin: entry.admin,\n env: entry.env,\n },\n };\n}\n"],"names":["ManifestCache","createHttpClient","filterToCacheKey","assertOk","applyFilter","buildProxyTool","CapabilityKind"],"mappings":";;;;;;;AAAA;;;;;;;;;AASG;MA8EU,6BAA6B,CAAA;AAOX,IAAA,MAAA;AANpB,IAAA,UAAU;AACF,IAAA,MAAM;AACN,IAAA,YAAY;AACZ,IAAA,WAAW;AACX,IAAA,KAAK;AAEtB,IAAA,WAAA,CAA6B,MAAyB,EAAA;QAAzB,IAAA,CAAA,MAAM,GAAN,MAAM;QACjC,MAAM,EACJ,OAAO,EACP,MAAM,EACN,YAAY,GAAG,WAAW,EAC1B,WAAW,GAAG,gBAAgB,EAC9B,SAAS,GAAG,MAAM,EAClB,aAAa,GAAG,MAAM,EACtB,MAAM,EACN,KAAK,GACN,GAAG,MAAM;QAEV,IAAI,CAAC,OAAO,EAAE;AACZ,YAAA,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC;QACvE;QACA,IAAI,CAAC,MAAM,EAAE;AACX,YAAA,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC;QACtE;AAEA,QAAA,IAAI,CAAC,UAAU,GAAG,CAAA,aAAA,EAAgB,OAAO,EAAE;AAC3C,QAAA,IAAI,CAAC,YAAY,GAAG,YAAY;AAChC,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW;AAC9B,QAAA,IAAI,CAAC,KAAK,GAAG,IAAIA,0BAAa,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;QAExD,IAAI,MAAM,EAAE;AACV,YAAA,IAA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AE,EAAE,CAAC,IAAI;YACb,KAAK,EAAE,EAAE,CAAC,KAAK;YACf,IAAI,EAAE,EAAE,CAAC,IAAI;;YAEb,MAAM,EAAE,EAAE,CAAC,MAAoD;AAChE,SAAA,CAAC,CAAC;AACH,QAAA,QAAQ,EAAE;YACR,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,IAAI,EAAE,KAAK,CAAC,IAAI;;YAEhB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,GAAG,EAAE,KAAK,CAAC,GAAG;AACf,SAAA;KACF;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"ToolsServerCapabilityProvider.cjs","sources":["../../../../src/providers/tools-server/ToolsServerCapabilityProvider.ts"],"sourcesContent":["/**\n * ToolsServerCapabilityProvider — capabilities sourced from a tools-server\n * HTTP endpoint.\n *\n * Fetches the manifest via GET /manifest, builds proxy StructuredTools via\n * POST /execute/:tool. Manifest is cached (TTL-configurable) so repeated\n * init cycles don't refetch.\n *\n * See docs/architecture-capability-layer.md for the design rationale.\n */\n\nimport type { AxiosInstance } from 'axios';\nimport type { StructuredToolInterface } from '@langchain/core/tools';\nimport {\n CapabilityKind,\n type Capability,\n type CapabilityFilter,\n type CapabilityProvider,\n type CredentialMap,\n} from '@/providers/types';\nimport {\n createHttpClient,\n type HttpClientConfig,\n assertOk,\n} from '@/utils/httpClient';\nimport {\n ManifestCache,\n filterToCacheKey,\n applyFilter,\n} from '@/utils/toolManifest';\nimport { buildProxyTool } from '@/tools/proxyTool';\n\n/** Configuration for ToolsServerCapabilityProvider. */\nexport interface ToolsServerConfig {\n /** Tools-server base URL (e.g., https://tools.illuma.ai or http://localhost:3500). */\n baseUrl: string;\n /** API key sent as x-api-key header on all requests. Required. */\n apiKey: string;\n /** Optional override for manifest path. Defaults to `/manifest`. */\n manifestPath?: string;\n /** Optional override for execute path template. Defaults to `/execute/:name`. */\n executePath?: string;\n /** Request timeout in ms. Defaults to 30_000. */\n timeoutMs?: number;\n /** Manifest cache TTL in ms. 0 disables. Defaults to 60_000 (1 min). */\n manifestTtlMs?: number;\n /** Optional pre-built axios instance (for testing). */\n client?: AxiosInstance;\n /** Optional proxy override (defaults to process.env.PROXY). */\n proxy?: string | null;\n /**\n * Optional per-request auth header builder — invoked on every tool\n * invocation (NOT on the manifest fetch, which is service-to-service).\n * When provided, the returned headers are merged into the `/execute`\n * request so the host can pass user-scoped identity (e.g.,\n * `Authorization: Bearer <jwt>`) that tools-server verifies for\n * admin-gated tools.\n *\n * Typical host wiring: mint a short-lived JWT per call carrying the\n * authenticated user's `{ userId, role }` claims; tools-server's\n * `TOOLS_SERVER_JWT_SECRET` validates.\n */\n getExecuteAuthHeaders?: () =>\n | Record<string, string>\n | Promise<Record<string, string>>;\n}\n\n/**\n * Shape of a single entry from tools-server's /manifest response.\n *\n * Matches the tools-server ManifestToolEntry type. We define our own here\n * to avoid cross-package coupling — the shape is a stable HTTP contract.\n */\ninterface ToolsServerManifestEntry {\n pluginKey: string;\n name: string;\n description: string;\n icon?: string;\n authConfig?: Array<{\n authField: string;\n label?: string;\n description?: string;\n source?: string;\n required?: boolean;\n prod?: boolean;\n admin?: boolean;\n hide?: boolean;\n }>;\n /** Input schema as JSON Schema (tools-server emits `schema`). */\n schema?: unknown;\n /** Legacy alias accepted for backwards compatibility. */\n jsonSchema?: unknown;\n category?: string;\n tags?: string[];\n toolkit?: string;\n endpoint?: string;\n /** Governance flags forwarded by tools-server getManifest(). */\n hidden?: boolean;\n admin?: boolean;\n env?: Array<'development' | 'production' | 'test' | 'staging'>;\n}\n\nexport class ToolsServerCapabilityProvider implements CapabilityProvider {\n readonly providerId: string;\n private readonly client: AxiosInstance;\n private readonly manifestPath: string;\n private readonly executePath: string;\n private readonly cache: ManifestCache;\n private readonly getExecuteAuthHeaders?: () =>\n | Record<string, string>\n | Promise<Record<string, string>>;\n\n constructor(private readonly config: ToolsServerConfig) {\n const {\n baseUrl,\n apiKey,\n manifestPath = '/manifest',\n executePath = '/execute/:name',\n timeoutMs = 30_000,\n manifestTtlMs = 60_000,\n client,\n proxy,\n getExecuteAuthHeaders,\n } = config;\n\n if (!baseUrl) {\n throw new Error('ToolsServerCapabilityProvider: baseUrl is required');\n }\n if (!apiKey) {\n throw new Error('ToolsServerCapabilityProvider: apiKey is required');\n }\n\n this.providerId = `tools-server:${baseUrl}`;\n this.manifestPath = manifestPath;\n this.executePath = executePath;\n this.cache = new ManifestCache({ ttlMs: manifestTtlMs });\n this.getExecuteAuthHeaders = getExecuteAuthHeaders;\n\n if (client) {\n this.client = client;\n } else {\n const httpConfig: HttpClientConfig = {\n baseURL: baseUrl,\n apiKey,\n timeoutMs,\n proxy,\n };\n this.client = createHttpClient(httpConfig);\n }\n }\n\n async fetchManifest(filter?: CapabilityFilter): Promise<Capability[]> {\n const cacheKey = filterToCacheKey(filter);\n const cached = this.cache.get(cacheKey);\n if (cached) {\n // DEBUG: cache hit (remove after stabilization)\n // eslint-disable-next-line no-console\n console.debug(\n `[${this.providerId}] manifest cache hit — ${cached.length} caps`\n );\n return cached;\n }\n\n // DEBUG\n // eslint-disable-next-line no-console\n console.debug(\n `[${this.providerId}] fetching manifest from ${this.manifestPath}`\n );\n\n const res = await this.client.get<ToolsServerManifestEntry[]>(\n this.manifestPath\n );\n assertOk(res.status, this.manifestPath, res.data);\n\n const entries = Array.isArray(res.data) ? res.data : [];\n const capabilities: Capability[] = entries.map((entry) =>\n normalizeEntry(entry)\n );\n\n // Apply filter before caching the full list separately so unfiltered\n // refetches don't re-hit the network.\n const fullCacheKey = filterToCacheKey();\n this.cache.set(fullCacheKey, capabilities);\n\n const filtered = applyFilter(capabilities, filter);\n if (cacheKey !== fullCacheKey) {\n this.cache.set(cacheKey, filtered);\n }\n\n // DEBUG\n // eslint-disable-next-line no-console\n console.debug(\n `[${this.providerId}] manifest loaded — ${capabilities.length} caps, ${filtered.length} after filter`\n );\n\n return filtered;\n }\n\n async createRunnables(\n capabilities: Capability[],\n credentials: CredentialMap\n ): Promise<StructuredToolInterface[]> {\n return capabilities.map((cap) =>\n buildProxyTool(cap, credentials, {\n client: this.client,\n executePath: this.executePath,\n getAuthHeaders: this.getExecuteAuthHeaders,\n })\n );\n }\n\n /** Force a manifest refresh on next fetchManifest call. */\n invalidateCache(): void {\n this.cache.clear();\n }\n}\n\n/**\n * Translate a raw tools-server manifest entry into a typed Capability.\n * Defensive — tools-server may add fields; we pull only what we need.\n */\nfunction normalizeEntry(entry: ToolsServerManifestEntry): Capability {\n return {\n kind: CapabilityKind.TOOL,\n name: entry.pluginKey,\n description: entry.description ?? '',\n schema: entry.schema ?? entry.jsonSchema,\n authConfig: (entry.authConfig ?? []).map((ac) => ({\n authField: ac.authField,\n label: ac.label,\n description: ac.description,\n required: ac.required,\n prod: ac.prod,\n admin: ac.admin,\n hide: ac.hide,\n // Source is a string in wire format; downstream consumers coerce to AuthSource.\n source: ac.source as Capability['authConfig'][number]['source'],\n })),\n metadata: {\n icon: entry.icon,\n category: entry.category,\n tags: entry.tags,\n // Governance — hosts use these to gate UI/role/environment.\n hidden: entry.hidden,\n admin: entry.admin,\n env: entry.env,\n },\n };\n}\n"],"names":["ManifestCache","createHttpClient","filterToCacheKey","assertOk","applyFilter","buildProxyTool","CapabilityKind"],"mappings":";;;;;;;AAAA;;;;;;;;;AASG;MA6FU,6BAA6B,CAAA;AAUX,IAAA,MAAA;AATpB,IAAA,UAAU;AACF,IAAA,MAAM;AACN,IAAA,YAAY;AACZ,IAAA,WAAW;AACX,IAAA,KAAK;AACL,IAAA,qBAAqB;AAItC,IAAA,WAAA,CAA6B,MAAyB,EAAA;QAAzB,IAAA,CAAA,MAAM,GAAN,MAAM;AACjC,QAAA,MAAM,EACJ,OAAO,EACP,MAAM,EACN,YAAY,GAAG,WAAW,EAC1B,WAAW,GAAG,gBAAgB,EAC9B,SAAS,GAAG,MAAM,EAClB,aAAa,GAAG,MAAM,EACtB,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;;IAGA,eAAe,GAAA;AACb,QAAA,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE;IACpB;AACD;AAED;;;AAGG;AACH,SAAS,cAAc,CAAC,KAA+B,EAAA;IACrD,OAAO;QACL,IAAI,EAAEC,oBAAc,CAAC,IAAI;QACzB,IAAI,EAAE,KAAK,CAAC,SAAS;AACrB,QAAA,WAAW,EAAE,KAAK,CAAC,WAAW,IAAI,EAAE;AACpC,QAAA,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,UAAU;AACxC,QAAA,UAAU,EAAE,CAAC,KAAK,CAAC,UAAU,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC,EAAE,MAAM;YAChD,SAAS,EAAE,EAAE,CAAC,SAAS;YACvB,KAAK,EAAE,EAAE,CAAC,KAAK;YACf,WAAW,EAAE,EAAE,CAAC,WAAW;YAC3B,QAAQ,EAAE,EAAE,CAAC,QAAQ;YACrB,IAAI,EAAE,EAAE,CAAC,IAAI;YACb,KAAK,EAAE,EAAE,CAAC,KAAK;YACf,IAAI,EAAE,EAAE,CAAC,IAAI;;YAEb,MAAM,EAAE,EAAE,CAAC,MAAoD;AAChE,SAAA,CAAC,CAAC;AACH,QAAA,QAAQ,EAAE;YACR,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,IAAI,EAAE,KAAK,CAAC,IAAI;;YAEhB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,GAAG,EAAE,KAAK,CAAC,GAAG;AACf,SAAA;KACF;AACH;;;;"}
|
|
@@ -24,7 +24,7 @@ var httpClient = require('../utils/httpClient.cjs');
|
|
|
24
24
|
* per-invocation credential rotation should rebuild the tool.
|
|
25
25
|
*/
|
|
26
26
|
function buildProxyTool(capability, credentials, options) {
|
|
27
|
-
const { client, executePath = '/execute/:name', onExecute } = options;
|
|
27
|
+
const { client, executePath = '/execute/:name', onExecute, getAuthHeaders, } = options;
|
|
28
28
|
const url = executePath.replace(':name', encodeURIComponent(capability.name));
|
|
29
29
|
return tools.tool(async (input) => {
|
|
30
30
|
const startMs = Date.now();
|
|
@@ -33,10 +33,12 @@ function buildProxyTool(capability, credentials, options) {
|
|
|
33
33
|
// DEBUG: log (remove after POC stabilizes)
|
|
34
34
|
// eslint-disable-next-line no-console
|
|
35
35
|
console.debug(`${debugPrefix} invoking — inputKeys=${input && typeof input === 'object' ? Object.keys(input).length : 0}`);
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
})
|
|
36
|
+
const extraHeaders = getAuthHeaders
|
|
37
|
+
? await getAuthHeaders()
|
|
38
|
+
: undefined;
|
|
39
|
+
const res = await client.post(url, { input, credentials }, extraHeaders && Object.keys(extraHeaders).length > 0
|
|
40
|
+
? { headers: extraHeaders }
|
|
41
|
+
: undefined);
|
|
40
42
|
const durationMs = Date.now() - startMs;
|
|
41
43
|
if (res.status < 200 || res.status >= 300) {
|
|
42
44
|
throw new httpClient.HttpError(res.status, url, res.data);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxyTool.cjs","sources":["../../../src/tools/proxyTool.ts"],"sourcesContent":["/**\n * proxyTool — wraps a Capability into a LangChain StructuredTool that\n * dispatches execution to a remote backend (e.g., tools-server) over HTTP.\n *\n * The LLM sees this tool identically to a locally-implemented tool:\n * - same name\n * - same description\n * - same input schema (JSON Schema)\n * - same invoke(input) contract\n *\n * Under the hood, invoke() POSTs to the backend's execute endpoint with\n * the input and a caller-supplied credential map. The backend returns\n * { success, result, error, timing } which this wrapper unpacks.\n */\n\nimport type { AxiosInstance } from 'axios';\nimport { tool, type StructuredToolInterface } from '@langchain/core/tools';\nimport type { Capability, CredentialMap } from '@/providers/types';\nimport { HttpError } from '@/utils/httpClient';\n\n/** Shape of the backend's execute response. Matches tools-server. */\nexport interface ExecuteResponse {\n success: boolean;\n result?: unknown;\n error?: string;\n timing?: { durationMs: number };\n}\n\n/** Options passed to buildProxyTool. */\nexport interface ProxyToolOptions {\n /** HTTP client configured with backend base URL + auth. */\n client: AxiosInstance;\n /**\n * Path template for execution. The literal `:name` is replaced with the\n * capability's name. Defaults to `/execute/:name` (tools-server convention).\n */\n executePath?: string;\n /**\n * Optional callback invoked on every execution — used for metrics,\n * telemetry, debug logging. Errors in the hook are swallowed.\n */\n onExecute?: (ctx: ExecuteCallbackContext) => void;\n}\n\nexport interface ExecuteCallbackContext {\n capabilityName: string;\n input: unknown;\n response?: ExecuteResponse;\n error?: Error;\n durationMs: number;\n}\n\n/**\n * Build a StructuredTool that proxies to a remote backend.\n *\n * The credentialMap is baked into the closure — callers that need\n * per-invocation credential rotation should rebuild the tool.\n */\nexport function buildProxyTool(\n capability: Capability,\n credentials: CredentialMap,\n options: ProxyToolOptions\n): StructuredToolInterface {\n const {
|
|
1
|
+
{"version":3,"file":"proxyTool.cjs","sources":["../../../src/tools/proxyTool.ts"],"sourcesContent":["/**\n * proxyTool — wraps a Capability into a LangChain StructuredTool that\n * dispatches execution to a remote backend (e.g., tools-server) over HTTP.\n *\n * The LLM sees this tool identically to a locally-implemented tool:\n * - same name\n * - same description\n * - same input schema (JSON Schema)\n * - same invoke(input) contract\n *\n * Under the hood, invoke() POSTs to the backend's execute endpoint with\n * the input and a caller-supplied credential map. The backend returns\n * { success, result, error, timing } which this wrapper unpacks.\n */\n\nimport type { AxiosInstance } from 'axios';\nimport { tool, type StructuredToolInterface } from '@langchain/core/tools';\nimport type { Capability, CredentialMap } from '@/providers/types';\nimport { HttpError } from '@/utils/httpClient';\n\n/** Shape of the backend's execute response. Matches tools-server. */\nexport interface ExecuteResponse {\n success: boolean;\n result?: unknown;\n error?: string;\n timing?: { durationMs: number };\n}\n\n/** Options passed to buildProxyTool. */\nexport interface ProxyToolOptions {\n /** HTTP client configured with backend base URL + auth. */\n client: AxiosInstance;\n /**\n * Path template for execution. The literal `:name` is replaced with the\n * capability's name. Defaults to `/execute/:name` (tools-server convention).\n */\n executePath?: string;\n /**\n * Optional callback invoked on every execution — used for metrics,\n * telemetry, debug logging. Errors in the hook are swallowed.\n */\n onExecute?: (ctx: ExecuteCallbackContext) => void;\n /**\n * Optional per-invocation auth header builder. Called on every tool\n * invocation before POSTing; returned headers are merged into the\n * request alongside the base client's headers. Typical use: pass a\n * freshly minted per-user JWT for admin-gated tools.\n */\n getAuthHeaders?: () =>\n | Record<string, string>\n | Promise<Record<string, string>>;\n}\n\nexport interface ExecuteCallbackContext {\n capabilityName: string;\n input: unknown;\n response?: ExecuteResponse;\n error?: Error;\n durationMs: number;\n}\n\n/**\n * Build a StructuredTool that proxies to a remote backend.\n *\n * The credentialMap is baked into the closure — callers that need\n * per-invocation credential rotation should rebuild the tool.\n */\nexport function buildProxyTool(\n capability: Capability,\n credentials: CredentialMap,\n options: ProxyToolOptions\n): StructuredToolInterface {\n const {\n client,\n executePath = '/execute/:name',\n onExecute,\n getAuthHeaders,\n } = options;\n const url = executePath.replace(':name', encodeURIComponent(capability.name));\n\n return tool(\n async (input: unknown): Promise<string> => {\n const startMs = Date.now();\n const debugPrefix = `[proxyTool:${capability.name}]`;\n\n try {\n // DEBUG: log (remove after POC stabilizes)\n // eslint-disable-next-line no-console\n console.debug(\n `${debugPrefix} invoking — inputKeys=${input && typeof input === 'object' ? Object.keys(input as object).length : 0}`\n );\n\n const extraHeaders = getAuthHeaders\n ? await getAuthHeaders()\n : undefined;\n const res = await client.post<ExecuteResponse>(\n url,\n { input, credentials },\n extraHeaders && Object.keys(extraHeaders).length > 0\n ? { headers: extraHeaders }\n : undefined\n );\n\n const durationMs = Date.now() - startMs;\n\n if (res.status < 200 || res.status >= 300) {\n throw new HttpError(res.status, url, res.data);\n }\n\n const body = res.data;\n if (onExecute) {\n try {\n onExecute({\n capabilityName: capability.name,\n input,\n response: body,\n durationMs,\n });\n } catch {\n // hook errors are non-fatal\n }\n }\n\n if (!body.success) {\n // DEBUG\n // eslint-disable-next-line no-console\n console.debug(\n `${debugPrefix} backend reported failure — ${body.error}`\n );\n throw new Error(body.error ?? 'Tool execution failed');\n }\n\n // LangChain tools typically return strings; stringify non-string results\n if (typeof body.result === 'string') {\n return body.result;\n }\n return JSON.stringify(body.result);\n } catch (err) {\n const durationMs = Date.now() - startMs;\n const error = err instanceof Error ? err : new Error(String(err));\n if (onExecute) {\n try {\n onExecute({\n capabilityName: capability.name,\n input,\n error,\n durationMs,\n });\n } catch {\n // hook errors are non-fatal\n }\n }\n throw error;\n }\n },\n {\n name: capability.name,\n description: capability.description,\n schema: (capability.schema as object) ?? {\n type: 'object',\n properties: {},\n },\n responseFormat: 'content',\n }\n );\n}\n"],"names":["tool","HttpError"],"mappings":";;;;;AAAA;;;;;;;;;;;;;AAaG;AAgDH;;;;;AAKG;SACa,cAAc,CAC5B,UAAsB,EACtB,WAA0B,EAC1B,OAAyB,EAAA;AAEzB,IAAA,MAAM,EACJ,MAAM,EACN,WAAW,GAAG,gBAAgB,EAC9B,SAAS,EACT,cAAc,GACf,GAAG,OAAO;AACX,IAAA,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,kBAAkB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AAE7E,IAAA,OAAOA,UAAI,CACT,OAAO,KAAc,KAAqB;AACxC,QAAA,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE;AAC1B,QAAA,MAAM,WAAW,GAAG,CAAA,WAAA,EAAc,UAAU,CAAC,IAAI,GAAG;AAEpD,QAAA,IAAI;;;AAGF,YAAA,OAAO,CAAC,KAAK,CACX,CAAA,EAAG,WAAW,CAAA,sBAAA,EAAyB,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,KAAe,CAAC,CAAC,MAAM,GAAG,CAAC,CAAA,CAAE,CACtH;YAED,MAAM,YAAY,GAAG;kBACjB,MAAM,cAAc;kBACpB,SAAS;YACb,MAAM,GAAG,GAAG,MAAM,MAAM,CA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