import { buildOutboundMediaLoadOptions, type OutboundMediaAccess } from "../media/load-options.js"; import { loadWebMedia } from "./web-media.js"; export type OutboundMediaLoadOptions = { /** Maximum allowed media payload size before the load is rejected. */ maxBytes?: number; /** Whether callers may load remote URLs, local files, or both. */ mediaAccess?: OutboundMediaAccess; /** Approved local roots for file/path media; `"any"` disables root restriction. */ mediaLocalRoots?: readonly string[] | "any"; /** Optional local file reader used by tests or plugin-specific filesystem adapters. */ mediaReadFile?: (filePath: string) => Promise; /** Workspace root used when resolving relative local media paths. */ workspaceDir?: string; /** Explicit proxy URL forwarded to shared outbound media loading policy. */ proxyUrl?: string; /** Fetch implementation for remote media loads. */ fetchImpl?: (input: RequestInfo | URL, init?: RequestInit) => Promise; /** Extra fetch options merged into remote media requests. */ requestInit?: RequestInit; /** Allows explicit proxy DNS behavior to be trusted by the media fetch guard. */ trustExplicitProxyDns?: boolean; }; /** Load outbound media from a remote URL or approved local path using the shared web-media policy. */ export async function loadOutboundMediaFromUrl( mediaUrl: string, options: OutboundMediaLoadOptions = {}, ) { return await loadWebMedia( mediaUrl, buildOutboundMediaLoadOptions({ maxBytes: options.maxBytes, mediaAccess: options.mediaAccess, mediaLocalRoots: options.mediaLocalRoots, mediaReadFile: options.mediaReadFile, workspaceDir: options.workspaceDir, proxyUrl: options.proxyUrl, fetchImpl: options.fetchImpl, requestInit: options.requestInit, trustExplicitProxyDns: options.trustExplicitProxyDns, }), ); }