Raven-1/scripts/refresh_dmxapi_mark.py
Kevin Hu 8bb47a6eae
feat(providers): expand the provider catalog to 55 and give each a brand mark (#393)
## Summary

Takes the provider registry from 24 specs to 55 and gives the web UI a
brand mark for every provider and model family.

<img width="1998" height="1356" alt="image"
src="https://github.com/user-attachments/assets/dd909dd3-c742-45d0-a94d-61ccb1e30a0e"
/>

Four groups of providers are added: Western labs and inference hosts
(xAI, Mistral, Together AI, Fireworks AI, Perplexity, Cerebras, Hugging
Face, Poe), CN vendors (Xiaomi MiMo, Baichuan, Baidu Cloud, StepFun,
LongCat, ModelScope, Qiniu), resale gateways (302.AI, DMXAPI, BurnCloud,
ocoolai, PPIO, Lanyun, AlayaNew, SophNet, TokenHub, Xirang, PH8, AIOnly,
AMD GPU Cloud) and self-hosted servers (GPUStack, OpenVINO Model
Server). BigModel, Zhipu's CN platform, joins Z.ai, and the two Zhipu
platforms fold into a single row in the provider rail.

LiteLLM routes nine of them from a key plus a prefixed id. The other
twenty-one speak OpenAI's API with no driver of their own, so each
borrows OpenAI's driver and is told apart by its address, the way
SiliconFlow already was.

On the web UI side the provider rail gains name and connection-state
filtering, drops the generic Custom row, and keeps its scrollbar off the
connection dots. Provider marks move from Lobe Icons to the vendors' own
colour marks, and LICENSES/README.md records the new attribution.

Three decisions worth a reviewer's attention:

- The two "read-only exec allowlist and approval grants" commits from
the source branch are left out, because that work is already on main.
This was verified by symbol rather than by commit subject: every def and
class the commits add is already present.
- The README prose edits are dropped. They updated a "Providers and
Gateways" paragraph that main no longer carries after the readme
restructure, so the text had no correct place to land. Only prose was
affected; no code was lost.
- The LICENSES/README.md conflicts were resolved by merging both sides
rather than taking one. The new Cherry Studio attribution entry and the
DMXAPI resampling note are kept, while main's sub-agent mark count
(fourteen, including this project's own raven.svg) is kept over the
incoming "thirteen", because fourteen is what the tree holds.

Three fixes landed on this branch after review, beyond the provider work
itself:

- Poe ships no default and no shortlist. Its ids were the maker's
spelling, and only the outer "poe/" comes off on the way out, so the
shipped default reached Poe as a model it does not have. Routing is
unchanged and a real bot id still works.
- The upgrade marker path is read from raven.home rather than through
raven.config, whose package imports pydantic. The handoff writes that
marker from the tool environment it is replacing, which has no such
dependency, so `raven upgrade` aborted before the helper was spawned.
This one is a pre-existing bug on main, merged in here rather than left
to a separate PR.
- Two pre-existing CI gates are repaired: check-page counted two inline
script blocks where page.html has carried three since the asset digest
was added, and a doctor test asserted a path that rich folds at a column
decided by the tmp directory's length. Both were failing on main as well
as here.


## Type

- [ ] Fix
- [x] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

Ran the provider, catalogue, resolution, RPC, onboarding, doctor and
upgrade suites together: 1240 passed, 103 skipped, no errors. An earlier
run of these reported a collection error in
tests/test_cli_onboard_commands.py for a missing raven_everos; that was
an incomplete local environment, resolved by the uv sync that builds
plugins-dist, and not a property of this branch.

ui-web vitest: 104 files, 1704 tests, all pass. ui-tui: lint, lint:rpc,
lint:i18n, type-check, build all clean and 2072 tests pass.

The page gate was run end to end from a clean build: npm build,
build.py, then check-page, count-shared-globals and check-css, all three
green.

Ran `make check-large-files`: passes, nothing over the limit. The
largest touched file is 340 KB. `uv run ruff check` and `ruff format
--check`: clean.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed

## Risk

User-visible changes: the onboarding catalog and the settings page list
55 providers instead of 24, the provider rail gains a filter, the
generic Custom row is gone, and provider marks are now the vendors' own
colour marks.

Security: the twenty-one providers that borrow OpenAI's LiteLLM driver
inherit its built-in default endpoint, api.openai.com. A spec that kept
its own address to itself would post someone else's key there, so a test
sweep asserts every borrowed-driver provider either hands LiteLLM its
own default or is reached by address.

Backward compatibility: existing provider configuration keeps its names
and fields, so current configs continue to resolve.

Rollback: revert the squash commit. No migration or config rewrite is
involved.

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

## Related Issues

N/A

---------

Co-authored-by: Claude (claude-opus-5) <noreply@anthropic.com>
2026-09-15 22:56:47 -07:00

78 lines
2.9 KiB
Python

"""Re-encode DMXAPI's brand mark at the size the provider rail draws it.
Every other mark under ``ui-web/src/assets/providers`` is a vector copied
verbatim, and ``LICENSES/README.md`` stakes the attribution on that: each is
byte-identical to what ``@cherrystudio/ui`` ships, checkable with ``cmp``.
DMXAPI is the one upstream publishes as a raster inside an SVG wrapper -- a
342x342 PNG for a mark the rail draws 20px wide, and 143 KB of the bundle for
one row, a third again the whole icon set.
So this file is the exception, and this script is what makes the exception
reviewable rather than a hand-edited blob. The wrapper is upstream's, byte for
byte; the artwork keeps its design and its colours; only the embedded PNG is
resampled. Rerunning against a newer upstream reproduces the shipped file.
uv run python scripts/refresh_dmxapi_mark.py [--cherry <path to cherry-studio>]
"""
from __future__ import annotations
import argparse
import base64
import io
import re
import sys
from pathlib import Path
#: Generous for a mark drawn at roughly 11 CSS px -- the artwork fills 65 of a
#: 120 viewBox in a 20px slot -- with headroom for a 3x display and for any
#: surface that later draws it larger.
SIDE = 96
ROOT = Path(__file__).resolve().parents[1]
DST = ROOT / "ui-web" / "src" / "assets" / "providers" / "dmxapi.svg"
UPSTREAM = Path("packages/ui/icons/providers/light/dmxapi.svg")
def _without_payload(text: str) -> str:
"""The wrapper alone, so it can be compared across a re-encode."""
return re.sub(r'base64,[^"]+"', 'base64,PAYLOAD"', text)
def rebuild(svg: str, side: int) -> bytes:
from PIL import Image
payload = re.search(r'base64,([^"]+)"', svg)
if not payload:
raise SystemExit("upstream no longer embeds a base64 raster; check whether it ships a vector now")
image = Image.open(io.BytesIO(base64.b64decode(payload.group(1)))).convert("RGBA")
buffer = io.BytesIO()
image.resize((side, side), Image.LANCZOS).save(buffer, format="PNG", optimize=True)
encoded = base64.b64encode(buffer.getvalue()).decode()
return re.sub(r'base64,[^"]+"', f'base64,{encoded}"', svg, count=1).encode("utf-8")
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--cherry", type=Path, default=Path.home() / "github" / "cherry-studio")
args = parser.parse_args()
source = args.cherry / UPSTREAM
if not source.is_file():
print(f"upstream mark not found at {source}", file=sys.stderr)
return 1
svg = source.read_text(encoding="utf-8")
out = rebuild(svg, SIDE)
DST.write_bytes(out)
# The geometry is upstream's; only the payload differs.
if _without_payload(svg) != _without_payload(out.decode("utf-8")):
raise SystemExit("the wrapper changed, which this script is not allowed to do")
print(f"{len(svg):,} bytes upstream -> {len(out):,} bytes shipped, wrapper unchanged")
return 0
if __name__ == "__main__":
raise SystemExit(main())