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

Function fileFromByteField

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

Source from the content-addressed store, hash-verified

534 Option.getOrElse(hint.encoding, () => "base64");
535
536const 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
562const fileFromBinaryBytes = (
563 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