-
Notifications
You must be signed in to change notification settings - Fork 3
feat(canonical-formats): public API + v2→v1 projection (#741, half 1 of 2) #841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
54853ed
feat(canonical-formats): public API + v2→v1 projection + closed-set v…
bokelley c58d403
fix(canonical-formats): address expert-review findings on #841
bokelley 80d456a
ci: re-trigger workflows on PR #841
bokelley 1d20865
Merge remote-tracking branch 'origin/main' into bokelley/issue-741-st…
bokelley 202474f
fix(canonical-formats): address Argus review follow-ups + nits on #841
bokelley ca09d4b
fix(canonical-formats): address github-code-quality bot comments on #841
bokelley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| """Pythonic v1↔v2 canonical-formats projection layer. | ||
|
|
||
| AdCP 3.1 introduced canonical formats as the v2 catalog-side vocabulary | ||
| that replaces v1's per-publisher format proliferation. A seller publishes | ||
| ``Product.format_options[]`` carrying ``ProductFormatDeclaration`` entries | ||
| (one per accepted canonical kind); buyer agents reason about creative | ||
| compatibility against the closed canonical set rather than the open v1 | ||
| ``format_ids`` namespace. | ||
|
|
||
| During the migration window both wire shapes coexist: 3.0-era buyers | ||
| read ``Product.format_ids[]`` (v1) and 3.1-aware buyers read | ||
| ``Product.format_options[]`` (v2). This module supplies the projection | ||
| layer the SDK needs to bridge them without adopters hand-rolling | ||
| translation per integration. | ||
|
|
||
| Public surface | ||
| ============== | ||
|
|
||
| * :func:`project_declaration_to_v1` — single ``ProductFormatDeclaration`` | ||
| → ``format_ids[]`` (with advisory ``errors[]`` emission on ambiguity | ||
| / multi-size lossy fan-out). | ||
| * :func:`project_product_to_v1` — fan-out helper across a product's | ||
| ``format_options[]``, accumulating refs and advisories. | ||
| * :func:`validate_format_kind_in_options` — closed-set guard: rejects a | ||
| ``format_kind`` that isn't published in the seller's ``format_options[]``. | ||
| Sellers call this before accepting a ``create_media_buy``. | ||
| * :func:`find_declaration_by_kind` — looks up the matching declaration | ||
| (with optional ``capability_id`` disambiguation). | ||
| * :func:`load_default_registry` — loads the AAO-published v1↔v2 mapping | ||
| registry from the bundled schema cache. | ||
| * :class:`SdkAdvisory` — typed wrapper around the SDK-source ``Error`` | ||
| entries the projection emits on ``errors[]``. | ||
|
|
||
| Resolution-order semantics for v2 → v1 follow ``registries/v1-canonical-mapping.json``: | ||
|
|
||
| 1. ``canonical_formats_only=True`` or ``format_kind=custom`` → no v1 emit, no advisory. | ||
| 2. ``v1_format_ref[]`` set → emit those refs; if ``params.sizes[]`` count exceeds | ||
| ``v1_format_ref[]`` count, emit ``FORMAT_DECLARATION_V1_LOSSY_MULTI_SIZE``. | ||
| 3. Canonical's ``v1_translatable=False`` (``agent_placement``, ``sponsored_placement``, | ||
| ``responsive_creative``, ``image_carousel``) → no v1 emit, no advisory — the | ||
| canonical is structurally v1-unreachable by design. | ||
| 4. Canonical's ``v1_translatable=True`` but no ``v1_format_ref[]`` → emit | ||
| ``FORMAT_DECLARATION_V1_AMBIGUOUS``. SDKs MUST NOT synthesize a v1 ``format_id`` | ||
| from registry structural matches; the registry is authoritative for v1→v2 | ||
| projection only. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from adcp.canonical_formats.advisory import SDK_ID, SdkAdvisory, make_sdk_advisory | ||
| from adcp.canonical_formats.format_options import ( | ||
| FormatKindNotInClosedSetError, | ||
| find_declaration_by_kind, | ||
| find_declaration_by_v1_format_id, | ||
| validate_format_kind_in_options, | ||
| ) | ||
| from adcp.canonical_formats.projection import ( | ||
| V1_TRANSLATABLE, | ||
| V2ToV1Projection, | ||
| project_declaration_to_v1, | ||
| project_product_to_v1, | ||
| ) | ||
| from adcp.canonical_formats.registry import ( | ||
| RegistryLoadError, | ||
| glob_match, | ||
| load_default_registry, | ||
| structural_match, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "FormatKindNotInClosedSetError", | ||
| "RegistryLoadError", | ||
| "SDK_ID", | ||
| "SdkAdvisory", | ||
| "V1_TRANSLATABLE", | ||
| "V2ToV1Projection", | ||
| "find_declaration_by_kind", | ||
| "find_declaration_by_v1_format_id", | ||
| "glob_match", | ||
| "load_default_registry", | ||
| "make_sdk_advisory", | ||
| "project_declaration_to_v1", | ||
| "project_product_to_v1", | ||
| "structural_match", | ||
| "validate_format_kind_in_options", | ||
| ] | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.