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