Repository navigation
feat(provider): configure several modalities from one connection - #561
Zhangbo-cn wants to merge 11 commits into
Conversation
|
CI 现状:除 关于
如果这是可接受的既有模式,请在 Security 面板把该告警标记为 false positive / dismissed;需要的话我也可以把这个哈希改成非安全敏感的命名(例如 |
A single API key commonly serves chat, image, video and audio models, but the settings form is kind-scoped: the same address and key had to be entered once per modality. Add a connection as a first-class draft: POST /api/model-configs/discover-many reads declarations per modality and reports per-modality errors, and POST /api/model-configs/connections saves the chosen modalities under one providerId with an explicit saved/rejected receipt. Saving replaces only the rows of the modality being written, so adding an image model later no longer drops the chat models that share the provider. UI: a multi-modal connection form reachable from the model settings overview and the per-kind service list, with per-modality protocol, grouped selection after one discovery, and retry for rejected modalities. Docs: docs/architecture/model-connection-multimodal.md Tests: application discovery isolation, connection save across kinds with partial failure and retry, rejected input, and a browser workflow registered in the gate lane. Refs ThinkFlowLab#558
The connection receipt returned the validation exception message, which CodeQL flags as stack-trace exposure on the new endpoint and which the UI could not localise. Return the stable rejection code instead and let the client map it to a bilingual reason, falling back to the code for unknown values.
c2ed770 to
33b1f62
Compare
The timeline workflow failed once with a timeout while waiting for the fixture's editor-save refusal; the backend and timeline code are unchanged by this branch. Re-running the lane to separate a flake from a regression.
|
重跑结果:浏览器三条 lane(isolated / voice / assistant)全部通过,static / frontend / python / route / tests / CodeQL-checks 也通过。之前的 当前唯一未通过的是 |
The connection identity digests the stored credential to tell connections apart; it is not password storage. Move it into a documented helper with an explicitly non-secret name so the intent is visible to readers and static analysis alike, without changing the produced identity.
# Conflicts: # apps/api/src/opendirector_api/models.py # scripts/run-browser-suite.mjs
config never carries a credential field, so the helper changed nothing and CodeQL flagged the SHA-256 of the API key on the modified line. Restore the original expression; voice scoping still keys on apiKey.
# Conflicts: # scripts/ci/python_shards.json
Fixes #558. (The related #477 select-all visibility report is a separate issue and is not touched here.)
Background
One API key usually serves text, image, video and speech models from the same endpoint, but Settings → model access configures one kind at a time: the same URL and key have to be entered for every kind, models discovered and saved separately. The store already groups rows that share a
providerIdinto one connection, but users could only create such a connection indirectly by editing an existing row.Changes
Contracts
POST /api/model-configs/discover-manydiscovers models per kind for one address and key and returns{results: [{kind, protocol, models, error}]}. One kind failing only fills that kind'serrorand does not stop the others; declaration-only protocols (minimax_video_v2, …) make no network request.POST /api/model-configs/connectionssaves several kinds in one request and returns{providerId, saved, rejected, kinds}. Every entry reuses the existingsave_many()validation and commits independently: a rejected kind does not roll back the saved kinds, andrejectedcarries{kind, code}so the UI can retry only the failures. An existingproviderIdis reused, and a credential edit propagates to every kind of that connection.Storage prerequisite fix
save_many()used to replace every row of aproviderId, so adding image models to an existing text connection deleted the text rows. Replacement is now limited to the kinds being written, keeping the legacyvision↔ image/video migration exception.UI
src/canvas/ModelConnectionForm.tsx: address/key/proxy/auto-check, kind checkboxes with a protocol per kind, one "Get models" action, results grouped by kind, and "Save connection"; rejected kinds are listed with their code and can be retried.providerId.Docs:
docs/architecture/model-connection-multimodal.mdrecords the delivered and not-yet-delivered scope.Verification
tests/test_model_catalog.py: per-kind discovery isolation, one kind's failure does not stop the others, an invalid protocol becomes that kind's error, discovery writes nothing.tests/test_model_configs.py: oneproviderIdshared across kinds, partial failure plus retry reusing the connection, duplicate kind / unknown connection / bad address rejected without writing, an all-failed save writes nothing.tests/browser/model_connection.mjs(registered in the gate lane): mocked discovery → two kinds selected → real save → sameproviderId→ the settings page shows one service.npm test,check:i18n,check:browser-manifest,tsc --noEmitandvite buildrun in the Release checks workflow, which is green on this head (checks / python (core|agent-cli|media),checks / frontend,checks / browser (isolated|voice|assistant),checks / desktop/*).Evidence
Captured from the isolated fixture at
e3e39b06(the later9ed4094eis an empty commit that only re-runs CI) with a mocked discovery endpoint where the video kind fails:Video reports
HTTP 401 from the fixturewithout blocking Chat and Image; after saving, the samehttp://127.0.0.1:12345/v1/…connection appears under both Chat and Image.Not included
First-run wizard entry, CLI/agent tool reuse of the new endpoints, and an "add missing modality" entry from an existing connection's list; see the architecture doc.
Corrections from review
domain/voices.pyadded an_identity_digest()helper and readconfig.get('credential'), but model configs have nocredentialfield. The helper was equivalent to the originalapiKeyhash and only moved the line CodeQL scans. It is reverted:domain/voices.pyis byte-identical tomain@4cd524ce, and the voice library still separates connections byapiKey.pytest tests/test_zhipu.py tests/test_model_configs.py tests/test_voice_library.py— 153 passed after the revert.CodeQL status
The non-required
CodeQLstatus still reports one alert atpackages/core/src/opendirector/domain/voices.py:110(SHA-256 over the API key used to derive the voice-library connection fingerprint). The file is not part of this PR's diff; the line has been onmainsincec54d78eb(2026-11-09). The new request models (ConnectionDiscoveryRequest/ConnectionSaveRequest) add one more dataflow source through the existingsave_many() → _public → input_rules → voice_library_capabilitiespath, which is why the check counts a new instance. The hash is a stable identity fingerprint, not password storage; replacing it with a password KDF would change every storedconnectionIdand invalidate saved voice selections, so that change needs its own migration.mergeStateStatusisUNSTABLEat9ed4094erather thanBLOCKEDbecause the repository declares no required status checks; all Release checks are green on9ed4094e(run 47498234238). Dismissing this alert as a false positive, or tracking the KDF migration separately, is the maintainer decision requested in the comments.