(body: unknown, hint: OperationFileHint)
| 539 | Option.getOrElse(hint.encoding, () => "base64"); |
| 540 | |
| 541 | const fileFromByteField = (body: unknown, hint: OperationFileHint): ToolFileValue | null => { |
| 542 | if (typeof body !== "object" || body === null || Array.isArray(body)) return null; |
| 543 | const record = body as Record<string, unknown>; |
| 544 | const dataField = readHintString(hint.dataField, "data"); |
| 545 | const rawData = record[dataField]; |
| 546 | if (typeof rawData !== "string") return null; |
| 547 | |
| 548 | const data = normalizeBase64(rawData, readHintEncoding(hint)); |
| 549 | const sizeField = Option.getOrUndefined(hint.sizeField); |
| 550 | const byteLength = |
| 551 | sizeField && typeof record[sizeField] === "number" |
| 552 | ? record[sizeField] |
| 553 | : byteLengthFromBase64(data); |
| 554 | const hintedMimeType = readHintMimeType(hint, "application/octet-stream"); |
| 555 | |
| 556 | return { |
| 557 | _tag: "ToolFile", |
| 558 | mimeType: isGenericMimeType(hintedMimeType) |
| 559 | ? (sniffMimeTypeFromBase64(data) ?? hintedMimeType) |
| 560 | : hintedMimeType, |
| 561 | encoding: "base64", |
| 562 | data, |
| 563 | byteLength, |
| 564 | }; |
| 565 | }; |
| 566 | |
| 567 | const fileFromBinaryBytes = ( |
| 568 | bytes: Uint8Array, |
no test coverage detected