Repository navigation
Conversation
Adds the media/formats method: a client asks the host which downloadable
video/audio qualities a page offers, so a browser-extension quality picker
can show real options before the user submits.
- MediaFormatsParamsSchema: strict { url, cookies? }; the host fetches the
URL itself, so it is restricted to http(s) and the cookie list is bounded
to 256 { name, value } pairs.
- MediaFormatsResultSchema: non-strict { available, reason?, title?,
durationSec?, entries[] } where an entry key is the quality token echoed
back as download/submit.meta.qualityLabel - never a raw extractor
selector. An unproducible listing is a successful available:false with a
machine-readable reason, not a protocol error.
- Registered in Methods/Tools as a non-agent-facing client to server method
(extension WS only; not exposed on unary HTTP), and gated on the new
capabilities.mediaFormats server flag.
- Exports HttpUrlSchema from resource.ts so every method that makes the host
fetch a caller-supplied URL shares one http(s)-only policy.
- README (EN + zh-CN): methods table row, usage example, and the
data-sharing/transport-exposure contract.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and contract
agalwood/Motrix#2365adds a yt-dlp quality picker to the browser extension.The picker needs to ask the desktop which qualities a page offers, and the
review of that PR asked for exactly one thing before it can merge:
Today
@motrix/mdxp@0.8.1has no format-listing method, so#2365carries afork-local
declare module '@motrix/mdxp'augmentation plus a hand-mirroredschema in the extension. This PR defines the method instead, so both apps can
delete their local copies and import the published contract.
This is the same additive shape as
download/directories(0.7.0) and thein-flight
downloadHandoffcontract (#4): schemas + typed RPC entry + toolregistry entry + a bilingual normative contract. It deliberately does not
implement an extractor, a media-site policy, a picker or a cache.
What is added
MediaFormatsParamsSchema— strict{ url, cookies? }.MediaFormatsResultSchema— non-strict{ available, reason?, title?, durationSec?, entries[] }.Methods.MediaFormats = 'media/formats', anMdxpRequestMapentry, theinferred types in the
typesbarrel, and aToolsentry.capabilities.mediaFormats— optional, absent means unsupported.HttpUrlSchemaexported fromresource.ts, so every method that makes thehost fetch a caller-supplied URL shares one policy.
docs/media-formats.md+docs/media-formats.zh-CN.md, shipped in thepackage (
docs/media-formats*.md), plus a README section and usage example.Parameter validation and bounds
urlis restricted tohttp:/https:(reusing the existingHttpUrlSchema),because the listing is a host-side fetch that spawns the host's extractor:
file:,data:andjavascript:are rejected at the contract boundary. Thisis tighter than the app-local draft, which accepted any non-empty string.
Cookies are
{ name, value }only — the pair needed to build aCookie:header— bounded to 256 entries, with a bounded name and value. Params are strict, so
unknown keys (e.g. a raw format selector) are rejected rather than ignored.
Quality tokens
An entry's
keyis the token the client echoes back asdownload/submit.meta.qualityLabel, validated by^(\d{3,4}p|mp3)$. It isnever a raw extractor selector, so a client cannot smuggle arbitrary format
syntax into a download through this method, and
media/formatsneverauthorizes a download: the following
download/submitis validated on its own.Data sharing
Cookies are disclosed to the extractor for that single URL only and are never
persisted, echoed back or logged. The result carries a title, duration and
option list — no extractor stderr, no filesystem paths. The contract also
states that a host must apply the same media-site, permission and rate policy
it applies to a submitted download, so a URL the submit path refuses is refused
here too and the picker can never promise a quality the submit would decline.
Transport exposure
media/formatsis extension-only: registered inToolsfor schema discoverywith
agentFacing: false, absent fromtoAgentToolCatalog(), and must not bereachable over the unary
POST /mdxptransport. The contract states explicitlythat
agentFacing: falseis not authorization and that the transport mustauthenticate the principal as a paired extension session before dispatch.
Capability negotiation and failure semantics
A client calls the method only when initialize returns
capabilities.mediaFormats === true; absence means unsupported. An unproduciblelisting is a successful
available: falsewith a machine-readablereason(
disabled,not-allowed,binary-missing,unsupported,failed, …) andempty
entries— never a protocol error, andreasonis documented as opaquewith a non-exhaustive value set. Only transport/protocol errors (
MethodNotFoundfrom an older host) are failures, and the compatibility matrix covers every
old/new combination in both directions.
Version
0.9.0— additive new method, no breaking change toprotocolVersion1.0,to
download/submit, or to any existing initialize/task/pairing shape.Validation
pnpm test), including 13 new cases: strict params,http(s)-only enforcement, cookie bounds, raw-selector rejection,forward-compatible result stripping, non-agent-facing registration, and
capability absence.
pnpm lint(Biome) andpnpm build(tsc,exactOptionalPropertyTypes) pass.npm packverified: the contract docs ship in the tarball.This repository has no CI workflow today; #4 adds one ("MDXP contract checks").
I ran the equivalent steps locally and am happy to rebase on #4 so this branch
picks up that workflow rather than adding a second, conflicting copy.
Follow-ups once this is published
agalwood/Motrix#2365: depend on the published version, advertisecapabilities.mediaFormats, validate params with the exported schema, anddelete
src/core/bridge/mdxp-local-methods.d.ts+src/shared/schemas/media-formats.ts.motrixapp/motrix-extension#56: import the param/result types from@motrix/mdxpand dropsrc/shared/mediaFormats.ts's mirrored wire shapes +src/shared/mdxp-media-formats.d.ts, keeping only the picker-local helpers.I am not asking for a release before review; the intent is a reviewed contract
that both apps can then consume.