MCPcopy Index your code
hub / github.com/simstudioai/sim / checkCanonicalIdContract

Function checkCanonicalIdContract

apps/sim/scripts/check-block-registry.ts:192–238  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

190}
191
192function checkCanonicalIdContract(): CheckResult {
193 const errors: string[] = []
194
195 for (const block of getAllBlocks()) {
196 const access: string[] = block.tools?.access ?? []
197 if (access.length === 0) continue
198
199 // A subBlock with `canonicalParamId` has its raw `id` deleted from `params` during
200 // canonical-group resolution in `extractParams` (serializer/index.ts), so the raw id is
201 // NOT a valid lookup key at execution time — only the canonical is. Tool params must
202 // align with the canonical, not the raw id.
203 const subBlockKeys = new Set<string>()
204 for (const sb of block.subBlocks ?? []) {
205 const canonical = (sb as { canonicalParamId?: string }).canonicalParamId
206 if (canonical) {
207 subBlockKeys.add(canonical)
208 } else if (sb.id) {
209 subBlockKeys.add(sb.id)
210 }
211 }
212
213 for (const toolId of access) {
214 const tool = toolRegistry[toolId]
215 if (!tool) continue
216
217 for (const [paramId, paramConfig] of Object.entries(tool.params ?? {})) {
218 if (!paramConfig || typeof paramConfig !== 'object') continue
219 const required = (paramConfig as { required?: boolean }).required === true
220 const userOnly = (paramConfig as { visibility?: string }).visibility === 'user-only'
221 if (!required || !userOnly) continue
222
223 if (!subBlockKeys.has(paramId)) {
224 errors.push(
225 `Block "${block.type}" → tool "${toolId}": required user-only param "${paramId}" has no subBlock with id or canonicalParamId === "${paramId}".\n` +
226 ' → Rename a subBlock id or canonicalParamId to match the tool param id,\n' +
227 " and update the block's inputs + tools.config.params mapper to read from that key."
228 )
229 }
230 }
231 }
232 }
233
234 if (errors.length === 0) {
235 return { kind: 'pass', message: 'Canonical-id contract check passed' }
236 }
237 return { kind: 'fail', errors }
238}
239
240/**
241 * Every catalog-visible integration block must expose a `BlockMeta` entry in

Callers 1

Calls 3

getAllBlocksFunction · 0.90
addMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected