mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 04:47:03 -06:00
refactor(media): trim internal exports (#107756)
* refactor(media): privatize internal parsing helpers * chore(deadcode): refresh unused-export baseline
This commit is contained in:
committed by
GitHub
parent
6495523a02
commit
e2ad943ebd
@@ -380,8 +380,6 @@ export const KNIP_UNUSED_EXPORT_BASELINE = [
|
||||
"src/mcp/openclaw-tools-serve-config.ts: resolveOpenClawToolsMcpSystemAgentApproval",
|
||||
"src/mcp/openclaw-tools-serve-config.ts: resolveOpenClawToolsMcpSystemAgentSurface",
|
||||
"src/mcp/openclaw-tools-serve-config.ts: resolveOpenClawToolsMcpToolSelection",
|
||||
"src/media/input-files.ts: fetchWithGuard",
|
||||
"src/media/parse.ts: SplitMediaFromOutputOptions",
|
||||
"src/music-generation/capabilities.ts: resolveMusicGenerationMode",
|
||||
"src/music-generation/runtime.ts: MusicGenerationRuntimeDeps",
|
||||
"src/node-host/invoke.ts: testing",
|
||||
|
||||
@@ -28,12 +28,11 @@ async function waitForMicrotaskTurn(): Promise<void> {
|
||||
});
|
||||
}
|
||||
|
||||
let fetchWithGuard: typeof import("./input-files.js").fetchWithGuard;
|
||||
let extractImageContentFromSource: typeof import("./input-files.js").extractImageContentFromSource;
|
||||
let extractFileContentFromSource: typeof import("./input-files.js").extractFileContentFromSource;
|
||||
|
||||
beforeAll(async () => {
|
||||
({ fetchWithGuard, extractImageContentFromSource, extractFileContentFromSource } =
|
||||
({ extractImageContentFromSource, extractFileContentFromSource } =
|
||||
await import("./input-files.js"));
|
||||
});
|
||||
|
||||
@@ -241,7 +240,7 @@ describe("HEIC input image normalization", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("fetchWithGuard", () => {
|
||||
describe("guarded input file URL fetches", () => {
|
||||
it("cancels ignored HTTP error bodies", async () => {
|
||||
let canceled = false;
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
@@ -263,11 +262,12 @@ describe("fetchWithGuard", () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
fetchWithGuard({
|
||||
url: "https://example.com/file.bin",
|
||||
maxBytes: 1024,
|
||||
timeoutMs: 1000,
|
||||
maxRedirects: 0,
|
||||
extractFileContentFromSource({
|
||||
source: { type: "url", url: "https://example.com/file.bin" },
|
||||
limits: {
|
||||
...createFileSourceLimits(["application/octet-stream"], true),
|
||||
maxBytes: 1024,
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow("Failed to fetch: 503 Service Unavailable");
|
||||
|
||||
@@ -296,11 +296,12 @@ describe("fetchWithGuard", () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
fetchWithGuard({
|
||||
url: "https://example.com/file.bin",
|
||||
maxBytes: 1024,
|
||||
timeoutMs: 1000,
|
||||
maxRedirects: 0,
|
||||
extractFileContentFromSource({
|
||||
source: { type: "url", url: "https://example.com/file.bin" },
|
||||
limits: {
|
||||
...createFileSourceLimits(["application/octet-stream"], true),
|
||||
maxBytes: 1024,
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow("Content too large: 2048 bytes");
|
||||
|
||||
@@ -329,11 +330,12 @@ describe("fetchWithGuard", () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
fetchWithGuard({
|
||||
url: "https://example.com/file.bin",
|
||||
maxBytes: 1024,
|
||||
timeoutMs: 1000,
|
||||
maxRedirects: 0,
|
||||
extractFileContentFromSource({
|
||||
source: { type: "url", url: "https://example.com/file.bin" },
|
||||
limits: {
|
||||
...createFileSourceLimits(["application/octet-stream"], true),
|
||||
maxBytes: 1024,
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow("invalid content-length header: 1e9");
|
||||
|
||||
@@ -371,11 +373,12 @@ describe("fetchWithGuard", () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
fetchWithGuard({
|
||||
url: "https://example.com/file.bin",
|
||||
maxBytes: 6,
|
||||
timeoutMs: 1000,
|
||||
maxRedirects: 0,
|
||||
extractFileContentFromSource({
|
||||
source: { type: "url", url: "https://example.com/file.bin" },
|
||||
limits: {
|
||||
...createFileSourceLimits(["application/octet-stream"], true),
|
||||
maxBytes: 6,
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow("Content too large");
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ export function resolveInputFileLimits(config?: InputFileLimitsConfig): InputFil
|
||||
}
|
||||
|
||||
/** Fetches an input source URL through SSRF, redirect, timeout, and byte-limit guards. */
|
||||
export async function fetchWithGuard(params: {
|
||||
async function fetchWithGuard(params: {
|
||||
url: string;
|
||||
maxBytes: number;
|
||||
timeoutMs: number;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Media parse tests cover media reference parsing from text and payloads.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { splitMediaFromOutput, type SplitMediaFromOutputOptions } from "./parse.js";
|
||||
import { splitMediaFromOutput } from "./parse.js";
|
||||
|
||||
type SplitMediaFromOutputOptions = NonNullable<Parameters<typeof splitMediaFromOutput>[1]>;
|
||||
|
||||
describe("splitMediaFromOutput", () => {
|
||||
function expectParsedMediaOutputCase(
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ type ParsedMediaOutputSegment =
|
||||
};
|
||||
|
||||
/** Controls which non-MEDIA syntaxes may be lifted into media attachments. */
|
||||
export type SplitMediaFromOutputOptions = {
|
||||
type SplitMediaFromOutputOptions = {
|
||||
extractMarkdownImages?: boolean;
|
||||
extractMediaDirectives?: boolean;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user