Buckets:
| import { createHash } from 'node:crypto'; | |
| const FASTMCP_HASH_LENGTH = 12; | |
| export function rewriteProxyAppToolMeta(meta, proxyId, upstreamToolName) { | |
| if (!meta) { | |
| return {}; | |
| } | |
| const ui = meta.ui; | |
| if (!isRecord(ui) || typeof ui.resourceUri !== 'string' || !ui.resourceUri.startsWith('ui://')) { | |
| return { meta }; | |
| } | |
| const localUri = createProxyAppResourceUri(proxyId, ui.resourceUri); | |
| const rewrittenMeta = { | |
| ...meta, | |
| ui: { | |
| ...ui, | |
| resourceUri: localUri, | |
| }, | |
| }; | |
| return { | |
| meta: rewrittenMeta, | |
| resourceMapping: { | |
| localUri, | |
| upstreamUri: ui.resourceUri, | |
| proxyId, | |
| upstreamToolName, | |
| }, | |
| }; | |
| } | |
| export function createProxyAppResourceUri(proxyId, upstreamUri) { | |
| const safeProxyId = proxyId.replace(/[^a-zA-Z0-9_-]+/g, '-').replace(/^-+|-+$/g, '') || 'proxy'; | |
| const encodedUri = Buffer.from(upstreamUri, 'utf8').toString('base64url'); | |
| return `ui://hf-mcp-proxy/${safeProxyId}/${encodedUri}`; | |
| } | |
| export function discoverProxyAppToolCalls(value, appName) { | |
| if (!appName) { | |
| return []; | |
| } | |
| const found = new Map(); | |
| visitForToolCalls(value, appName, found); | |
| return Array.from(found.entries()).map(([toolName, argumentKeys]) => ({ | |
| toolName, | |
| argumentKeys: Array.from(argumentKeys), | |
| })); | |
| } | |
| export function isFastMcpAppBackendTool(toolName, appName) { | |
| const parsed = parseFastMcpBackendToolName(toolName); | |
| if (!parsed) { | |
| return false; | |
| } | |
| return parsed.digest === hashFastMcpTool(appName, parsed.localName); | |
| } | |
| function visitForToolCalls(value, appName, found) { | |
| if (Array.isArray(value)) { | |
| value.forEach((item) => { | |
| visitForToolCalls(item, appName, found); | |
| }); | |
| return; | |
| } | |
| if (!isRecord(value)) { | |
| return; | |
| } | |
| if (value.action === 'toolCall' && typeof value.tool === 'string' && isFastMcpAppBackendTool(value.tool, appName)) { | |
| const argumentKeys = isRecord(value.arguments) ? Object.keys(value.arguments) : []; | |
| const current = found.get(value.tool) ?? new Set(); | |
| argumentKeys.forEach((key) => current.add(key)); | |
| found.set(value.tool, current); | |
| } | |
| Object.values(value).forEach((child) => { | |
| visitForToolCalls(child, appName, found); | |
| }); | |
| } | |
| function parseFastMcpBackendToolName(toolName) { | |
| if (toolName.length <= FASTMCP_HASH_LENGTH + 1 || toolName[FASTMCP_HASH_LENGTH] !== '_') { | |
| return null; | |
| } | |
| const digest = toolName.slice(0, FASTMCP_HASH_LENGTH); | |
| if (!/^[0-9a-f]+$/.test(digest)) { | |
| return null; | |
| } | |
| return { | |
| digest, | |
| localName: toolName.slice(FASTMCP_HASH_LENGTH + 1), | |
| }; | |
| } | |
| function hashFastMcpTool(appName, toolName) { | |
| return createHash('sha256').update(`${appName}\0${toolName}`).digest('hex').slice(0, FASTMCP_HASH_LENGTH); | |
| } | |
| function isRecord(value) { | |
| return typeof value === 'object' && value !== null && !Array.isArray(value); | |
| } | |
| //# sourceMappingURL=proxy-apps.js.map |
Xet Storage Details
- Size:
- 3.08 kB
- Xet hash:
- 5c05840083943369b3c1bc851d4ea708774c0a30c8cb3a89ad15600dedc33c8b
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.