( texts: string[], entityTypes: string[], language?: string )
| 30 | * its own fail-safe (scrubbing rather than leaking). |
| 31 | */ |
| 32 | export async function maskPIIBatchViaHttp( |
| 33 | texts: string[], |
| 34 | entityTypes: string[], |
| 35 | language?: string |
| 36 | ): Promise<string[]> { |
| 37 | if (texts.length === 0) return [] |
| 38 | |
| 39 | const url = `${getInternalApiBaseUrl()}/api/guardrails/mask-batch` |
| 40 | const masked = new Array<string>(texts.length) |
| 41 | |
| 42 | await mapWithConcurrency(chunkIndicesByBudget(texts), CHUNK_CONCURRENCY, async (indices) => { |
| 43 | const chunk = indices.map((i) => texts[i]) |
| 44 | const out = await postChunk(url, chunk, entityTypes, language) |
| 45 | if (out.length !== chunk.length) { |
| 46 | throw new Error('PII mask-batch returned an unexpected result') |
| 47 | } |
| 48 | indices.forEach((originalIndex, k) => { |
| 49 | masked[originalIndex] = out[k] |
| 50 | }) |
| 51 | }) |
| 52 | |
| 53 | return masked |
| 54 | } |
| 55 | |
| 56 | async function postChunk( |
| 57 | url: string, |
no test coverage detected