|
| 1 | +import type { LoadedResources } from "./types.ts"; |
| 2 | +import type { ValidationFinding } from "./validate.ts"; |
| 3 | + |
| 4 | +export function validateTransferNumbers( |
| 5 | + resources: LoadedResources, |
| 6 | +): ValidationFinding[] { |
| 7 | + const findings: ValidationFinding[] = []; |
| 8 | + for (const type of ["tools", "assistants", "squads"] as const) { |
| 9 | + for (const resource of resources[type]) { |
| 10 | + const visit = (value: unknown, path: string): void => { |
| 11 | + if (!value || typeof value !== "object") return; |
| 12 | + if (Array.isArray(value)) { |
| 13 | + value.forEach((entry, index) => visit(entry, `${path}[${index}]`)); |
| 14 | + return; |
| 15 | + } |
| 16 | + const object = value as Record<string, unknown>; |
| 17 | + if ( |
| 18 | + object.type === "transferCall" && |
| 19 | + Array.isArray(object.destinations) |
| 20 | + ) { |
| 21 | + object.destinations.forEach((destination, index) => { |
| 22 | + const number = destination?.number; |
| 23 | + if (typeof number !== "string" || !/{{|{%/.test(number)) return; |
| 24 | + // Vapi: libs/core/src/types/tool.types/transferCallTool.types.ts (TransferDestinationNumber). |
| 25 | + findings.push({ |
| 26 | + severity: "error", |
| 27 | + type, |
| 28 | + resourceId: resource.resourceId, |
| 29 | + rule: "transfer-number-liquid", |
| 30 | + fieldPath: `${path ? `${path}.` : ""}destinations[${index}].number`, |
| 31 | + message: |
| 32 | + "The API rejects Liquid in transfer numbers: E.164 validation applies, and numberE164CheckEnabled:false still requires ^\\+?[a-zA-Z0-9]+$. Use a per-practice literal number, e.g. an inline tool in the squad's membersOverrides['tools:append']; see examples/nhs-shared-squads.", |
| 33 | + }); |
| 34 | + }); |
| 35 | + } |
| 36 | + for (const [key, child] of Object.entries(object)) { |
| 37 | + visit(child, path ? `${path}.${key}` : key); |
| 38 | + } |
| 39 | + }; |
| 40 | + visit(resource.data, ""); |
| 41 | + } |
| 42 | + } |
| 43 | + return findings; |
| 44 | +} |
0 commit comments