(body: unknown, hint: OperationFileHint)
| 493 | Option.getOrElse(hint.encoding, () => "base64"); |
| 494 | |
| 495 | const fileFromByteField = (body: unknown, hint: OperationFileHint): ToolFileValue | null => { |
| 496 | if (typeof body !== "object" || body === null || Array.isArray(body)) return null; |
| 497 | const record = body as Record<string, unknown>; |
| 498 | const dataField = readHintString(hint.dataField, "data"); |
| 499 | const rawData = record[dataField]; |
| 500 | if (typeof rawData !== "string") return null; |
| 501 | |
| 502 | const data = normalizeBase64(rawData, readHintEncoding(hint)); |
| 503 | const sizeField = Option.getOrUndefined(hint.sizeField); |
| 504 | const byteLength = |
| 505 | sizeField && typeof record[sizeField] === "number" |
| 506 | ? record[sizeField] |
| 507 | : byteLengthFromBase64(data); |
| 508 | const hintedMimeType = readHintMimeType(hint, "application/octet-stream"); |
| 509 | |
| 510 | return { |
| 511 | _tag: "ToolFile", |
| 512 | mimeType: isGenericMimeType(hintedMimeType) |
| 513 | ? (sniffMimeTypeFromBase64(data) ?? hintedMimeType) |
| 514 | : hintedMimeType, |
| 515 | encoding: "base64", |
| 516 | data, |
| 517 | byteLength, |
| 518 | }; |
| 519 | }; |
| 520 | |
| 521 | const fileFromBinaryBytes = ( |
| 522 | bytes: Uint8Array, |
no test coverage detected