Skip to content

feat(provider): configure several modalities from one connection - #561

Open
Zhangbo-cn wants to merge 11 commits into
ThinkFlowLab:mainfrom
Zhangbo-cn:feat/model-connection-multimodal
Open

Zhangbo-cn wants to merge 11 commits into
ThinkFlowLab:mainfrom
Zhangbo-cn:feat/model-connection-multimodal

Conversation

@Zhangbo-cn

@Zhangbo-cn Zhangbo-cn commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

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 providerId into one connection, but users could only create such a connection indirectly by editing an existing row.

Changes

Contracts

  • POST /api/model-configs/discover-many discovers models per kind for one address and key and returns {results: [{kind, protocol, models, error}]}. One kind failing only fills that kind's error and does not stop the others; declaration-only protocols (minimax_video_v2, …) make no network request.
  • POST /api/model-configs/connections saves several kinds in one request and returns {providerId, saved, rejected, kinds}. Every entry reuses the existing save_many() validation and commits independently: a rejected kind does not roll back the saved kinds, and rejected carries {kind, code} so the UI can retry only the failures. An existing providerId is reused, and a credential edit propagates to every kind of that connection.

Storage prerequisite fix

save_many() used to replace every row of a providerId, so adding image models to an existing text connection deleted the text rows. Replacement is now limited to the kinds being written, keeping the legacy vision ↔ image/video migration exception.

UI

  • New 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.
  • Entry points: Settings → model access overview and each kind's service list.
  • The service list still renders one connection as one service, grouped by providerId.

Docs: docs/architecture/model-connection-multimodal.md records 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: one providerId shared 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 → same providerId → the settings page shows one service.
  • The full Python suite, npm test, check:i18n, check:browser-manifest, tsc --noEmit and vite build run 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 later 9ed4094e is an empty commit that only re-runs CI) with a mocked discovery endpoint where the video kind fails:

One kind fails, the others succeed Two kinds selected
Video discovery error Chat and image selected
Chat tab: saved connection Image tab: the same connection
Chat tab connection Image tab same connection

Video reports HTTP 401 from the fixture without blocking Chat and Image; after saving, the same http://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

  • An earlier revision of domain/voices.py added an _identity_digest() helper and read config.get('credential'), but model configs have no credential field. The helper was equivalent to the original apiKey hash and only moved the line CodeQL scans. It is reverted: domain/voices.py is byte-identical to main@4cd524ce, and the voice library still separates connections by apiKey.
  • 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 CodeQL status still reports one alert at packages/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 on main since c54d78eb (2026-11-09). The new request models (ConnectionDiscoveryRequest / ConnectionSaveRequest) add one more dataflow source through the existing save_many() → _public → input_rules → voice_library_capabilities path, 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 stored connectionId and invalidate saved voice selections, so that change needs its own migration. mergeStateStatus is UNSTABLE at 9ed4094e rather than BLOCKED because the repository declares no required status checks; all Release checks are green on 9ed4094e (run 47498234238). Dismissing this alert as a false positive, or tracking the KDF migration separately, is the maintainer decision requested in the comments.

@github-actions github-actions Bot added area:provider Model providers and generation protocols type:feat New capability or behaviour labels Nov 28, 2026
@Zhangbo-cn

Copy link
Copy Markdown
Contributor Author

CI 现状:除 CodeQL 外全部通过(static / frontend / python / browser assistant / browser isolated / browser voice / route / tests / CodeQL-checks)。

关于 CodeQL 唯一剩余告警,做一点说明,请求维护者判断:

  • 告警位置:packages/core/src/opendirector/domain/voices.py:110
    account = hashlib.sha256((config.get('apiKey', '') if config.get('authMode') != 'none' else '').encode()).hexdigest()
    这是既有的「用 Key 派生连接身份指纹」实现,本 PR 没有修改这一行或该文件。
  • 本 PR 只新增了两个请求模型(ConnectionDiscoveryRequest / ConnectionSaveRequest,都带 apiKey: SecretStr),它们经 save_connection → save_many → _public → input_rules → voice_library_capabilities 进入同一个既有 sink,因此被视为新的数据流实例,而非新缺陷。
  • 上一轮 CI 里 main.py:276 的 stack-trace 告警已通过 c2ed770 修掉(rejected 只返回稳定 code,由前端本地化原因文案)。
  • 同轮 canvas progressive load 的失败在本次重跑中通过(32/33 → 33/33),属于时序抖动。

如果这是可接受的既有模式,请在 Security 面板把该告警标记为 false positive / dismissed;需要的话我也可以把这个哈希改成非安全敏感的命名(例如 connection_fingerprint),但那会改动本 PR 范围之外的既有行为,所以先征询意见。

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.
@Zhangbo-cn
Zhangbo-cn force-pushed the feat/model-connection-multimodal branch from c2ed770 to 33b1f62 Compare November 29, 2026 03:55
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.
@github-actions github-actions Bot added the area:docs Documentation / 文档 label Nov 29, 2026
@github-actions
github-actions Bot requested a review from wuzhf9 November 29, 2026 06:18
@Zhangbo-cn

Copy link
Copy Markdown
Contributor Author

重跑结果:浏览器三条 lane(isolated / voice / assistant)全部通过,static / frontend / python / route / tests / CodeQL-checks 也通过。之前的 timeline workflow 失败是一次性超时(等待 fixture 的 editor-save 拒绝提示),与本分支改动无关(本 PR 不改时间线代码)。

当前唯一未通过的是 CodeQL 的 1 条告警,位置在 packages/core/src/opendirector/domain/voices.py:110(既有实现,本 PR 未修改该文件)。它是「用 Key 派生连接身份指纹」的既有模式,本 PR 新增的两个请求模型让数据流多了一个来源,因此被算作新告警实例。已在上面说明过;如果认可,请在 Security 面板 dismiss 该告警,或告诉我按非敏感命名(如 connection_fingerprint)重写那一行,我再补一个 commit。

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.
Zhangbo-cn and others added 7 commits December 5, 2026 14:17
# 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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Documentation / 文档 area:provider Model providers and generation protocols type:feat New capability or behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] 模型接入:一个 API Key 一次配置多个模态(连接)

2 participants