MCPcopy
hub / github.com/simstudioai/sim / postChunk

Function postChunk

apps/sim/lib/guardrails/mask-client.ts:56–86  ·  view source on GitHub ↗
(
  url: string,
  texts: string[],
  entityTypes: string[],
  language: string | undefined
)

Source from the content-addressed store, hash-verified

54}
55
56async function postChunk(
57 url: string,
58 texts: string[],
59 entityTypes: string[],
60 language: string | undefined
61): Promise<string[]> {
62 // Mint per request: a single token (5min TTL) can expire mid-batch when a
63 // large execution fans out into many sequential chunk requests.
64 const token = await generateInternalToken()
65
66 // boundary-raw-fetch: internal server-to-server call to the app container (internal JWT auth, configurable base URL)
67 const response = await fetch(url, {
68 method: 'POST',
69 headers: {
70 'content-type': 'application/json',
71 authorization: `Bearer ${token}`,
72 },
73 body: JSON.stringify({ texts, entityTypes, language }),
74 })
75
76 if (!response.ok) {
77 const detail = await response.text().catch(() => '')
78 throw new Error(`PII mask-batch request failed (${response.status}): ${detail.slice(0, 200)}`)
79 }
80
81 const data = (await response.json()) as GuardrailsMaskBatchResult
82 if (!Array.isArray(data.masked)) {
83 throw new Error('PII mask-batch returned an unexpected result')
84 }
85 return data.masked
86}

Callers 1

maskPIIBatchViaHttpFunction · 0.85

Calls 2

generateInternalTokenFunction · 0.90
textMethod · 0.80

Tested by

no test coverage detected