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

Function fileFromByteField

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

Source from the content-addressed store, hash-verified

539 Option.getOrElse(hint.encoding, () => "base64");
540
541const 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
567const fileFromBinaryBytes = (
568 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