MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / fileFromByteField

Function fileFromByteField

packages/plugins/openapi/src/sdk/invoke.ts:495–519  ·  view source on GitHub ↗
(body: unknown, hint: OperationFileHint)

Source from the content-addressed store, hash-verified

493 Option.getOrElse(hint.encoding, () => "base64");
494
495const 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
521const fileFromBinaryBytes = (
522 bytes: Uint8Array,

Callers 1

invoke.tsFile · 0.85

Calls 7

readHintStringFunction · 0.85
normalizeBase64Function · 0.85
readHintEncodingFunction · 0.85
byteLengthFromBase64Function · 0.85
readHintMimeTypeFunction · 0.85
isGenericMimeTypeFunction · 0.85
sniffMimeTypeFromBase64Function · 0.85

Tested by

no test coverage detected