mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-25 15:29:34 +00:00
fix(media-understanding): align video base64 byte limits (#96519)
Merged via squash.
Prepared head SHA: e37e577cd4
Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
Reviewed-by: @vincentkoc
This commit is contained in:
28
packages/media-understanding-common/src/video.test.ts
Normal file
28
packages/media-understanding-common/src/video.test.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
// Media Understanding Common tests cover video payload sizing behavior.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DEFAULT_VIDEO_MAX_BASE64_BYTES } from "./defaults.js";
|
||||
import { estimateBase64Size, resolveVideoMaxBase64Bytes } from "./video.js";
|
||||
|
||||
describe("estimateBase64Size", () => {
|
||||
it("rounds byte counts to base64 quanta", () => {
|
||||
expect(estimateBase64Size(1)).toBe(4);
|
||||
expect(estimateBase64Size(2)).toBe(4);
|
||||
expect(estimateBase64Size(3)).toBe(4);
|
||||
expect(estimateBase64Size(4)).toBe(8);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveVideoMaxBase64Bytes", () => {
|
||||
it("allows raw byte limits that expand to valid base64 boundaries", () => {
|
||||
expect(resolveVideoMaxBase64Bytes(1)).toBe(4);
|
||||
expect(resolveVideoMaxBase64Bytes(2)).toBe(4);
|
||||
expect(resolveVideoMaxBase64Bytes(3)).toBe(4);
|
||||
expect(resolveVideoMaxBase64Bytes(4)).toBe(8);
|
||||
});
|
||||
|
||||
it("keeps the shared maximum base64 payload cap", () => {
|
||||
expect(resolveVideoMaxBase64Bytes(DEFAULT_VIDEO_MAX_BASE64_BYTES)).toBe(
|
||||
DEFAULT_VIDEO_MAX_BASE64_BYTES,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -10,6 +10,6 @@ export function estimateBase64Size(bytes: number): number {
|
||||
|
||||
/** Resolve video base64 byte limit from raw byte limit and global cap. */
|
||||
export function resolveVideoMaxBase64Bytes(maxBytes: number): number {
|
||||
const expanded = Math.floor(maxBytes * (4 / 3));
|
||||
const expanded = estimateBase64Size(maxBytes);
|
||||
return Math.min(expanded, DEFAULT_VIDEO_MAX_BASE64_BYTES);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user