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

Function fileFromByteField

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

Source from the content-addressed store, hash-verified

500 Option.getOrElse(hint.encoding, () => "base64");
501
502const fileFromByteField = (body: unknown, hint: OperationFileHint): ToolFileValue | null => {
503 if (typeof body !== "object" || body === null || Array.isArray(body)) return null;
504 const record = body as Record<string, unknown>;
505 const dataField = readHintString(hint.dataField, "data");
506 const rawData = record[dataField];
507 if (typeof rawData !== "string") return null;
508
509 const data = normalizeBase64(rawData, readHintEncoding(hint));
510 const sizeField = Option.getOrUndefined(hint.sizeField);
511 const byteLength =
512 sizeField && typeof record[sizeField] === "number"
513 ? record[sizeField]
514 : byteLengthFromBase64(data);
515 const hintedMimeType = readHintMimeType(hint, "application/octet-stream");
516
517 return {
518 _tag: "ToolFile",
519 mimeType: isGenericMimeType(hintedMimeType)
520 ? (sniffMimeTypeFromBase64(data) ?? hintedMimeType)
521 : hintedMimeType,
522 encoding: "base64",
523 data,
524 byteLength,
525 };
526};
527
528const fileFromBinaryBytes = (
529 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