Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/api/src/opendirector_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from opendirector_api.localization import localized_error
from opendirector_api.models import (ModelConfigInput, ModelConfigPublic, AgentModelTest,
ModelCapabilityRequest, ModelDiscoveryRequest, ModelBatchInput,
ConnectionDiscoveryRequest, ConnectionSaveRequest,
ToolTaskCreate, ToolPlacement, ImageSelectionCreate, AvailabilityRefresh, AvailabilityCatalog,
ModelAvailability as ModelAvailabilityResponse)

Expand Down Expand Up @@ -282,6 +283,23 @@ async def discover_models(value: ModelDiscoveryRequest):
protocol=value.protocol, auth_mode=value.authMode, proxy_mode=value.proxyMode)
return {'models': models}

@app.post('/api/model-configs/discover-many')
async def discover_connection_models(value: ConnectionDiscoveryRequest):
return {'results': await catalog.discover_many(
[{'kind': entry.kind, 'protocol': entry.protocol} for entry in value.kinds],
value.url, value.apiKey.get_secret_value(), connection_type=value.connectionType,
auth_mode=value.authMode, proxy_mode=value.proxyMode)}

@app.post('/api/model-configs/connections')
def save_connection(value: ConnectionSaveRequest):
return catalog.save_connection(
[{'kind': entry.kind, 'protocol': entry.protocol, 'modelIds': entry.modelIds,
'modelOptions': entry.modelOptions} for entry in value.entries],
value.url, value.apiKey.get_secret_value(), connection_type=value.connectionType,
auth_mode=value.authMode, proxy_mode=value.proxyMode,
capability_auto_check=value.capabilityAutoCheck,
provider_id=str(value.providerId) if value.providerId else None)
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

@app.post('/api/model-configs/test-agent')
async def test_agent_model(value: AgentModelTest):
elapsed = await catalog.test_agent(value.url, value.modelId, value.apiKey.get_secret_value(),
Expand Down
42 changes: 41 additions & 1 deletion apps/api/src/opendirector_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class Model(BaseModel):
model_config = ConfigDict(extra="forbid")


Protocol = Literal['openai', 'volcengine', 'higgsfield_open', 'bigmodel_video', 'kling_video', 'minimax_video_v2', 'vllm_omni', 'vllm_omni_segmentation', 'vllm_omni_music', 'vllm_omni_depth', 'vllm_omni_score', 'vllm_omni_bodies']


class Session(Model):
projectId: UUID

Expand All @@ -29,7 +32,7 @@ class UrlSource(Model):

class ModelConnection(Model):
connectionType: Literal['api', 'self_hosted'] = 'api'
protocol: Literal['openai', 'volcengine', 'higgsfield_open', 'bigmodel_video', 'kling_video', 'minimax_video_v2', 'vllm_omni', 'vllm_omni_segmentation', 'vllm_omni_music', 'vllm_omni_depth', 'vllm_omni_score', 'vllm_omni_bodies'] | None = None
protocol: "Protocol" = None
authMode: Literal['none', 'bearer'] | None = None
proxyMode: Literal['system', 'direct'] | None = None
capabilityAutoCheck: bool | None = Field(default=None, strict=True, exclude_if=lambda value: value is None)
Expand Down Expand Up @@ -68,6 +71,43 @@ class ModelDiscoveryRequest(ModelConfigInput):
configId: UUID | None = None


MODEL_KIND = Literal["agent", "image", "video", "audio", "vision"]


class ConnectionDiscoveryKind(Model):
kind: MODEL_KIND
protocol: "Protocol" = None


class ConnectionDiscoveryRequest(Model):
"""Discover models for several modalities of one address and credential."""
url: str = Field(max_length=2048)
apiKey: SecretStr = SecretStr("")
connectionType: Literal['api', 'self_hosted'] = 'api'
authMode: Literal['none', 'bearer'] | None = None
proxyMode: Literal['system', 'direct'] | None = None
kinds: list[ConnectionDiscoveryKind] = Field(min_length=1, max_length=5)


class ConnectionEntry(Model):
"""One modality saved as part of a connection."""
kind: MODEL_KIND
protocol: "Protocol" = None
modelIds: list[str] = Field(min_length=1, max_length=200)
modelOptions: dict[str, ModelOptions] = Field(default_factory=dict, max_length=200)


class ConnectionSaveRequest(Model):
url: str = Field(max_length=2048)
apiKey: SecretStr = SecretStr("")
connectionType: Literal['api', 'self_hosted'] = 'api'
authMode: Literal['none', 'bearer'] | None = None
proxyMode: Literal['system', 'direct'] | None = None
capabilityAutoCheck: bool | None = Field(default=None, strict=True)
providerId: UUID | None = None
entries: list[ConnectionEntry] = Field(min_length=1, max_length=5)


class AgentModelTest(ModelConfigInput):
kind: Literal["agent"] = "agent"
configId: UUID | None = None
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This directory is the entry point for the repository's shared documentation. The
| [Desktop architecture](architecture/desktop.md) ([中文](architecture/desktop.zh-CN.md)) | Electron, the Python Host, project storage, and shutdown behavior | Process, request, storage, or lifecycle boundaries change |
| [Test contracts](architecture/test-contracts.md) | Test/production boundaries, how to avoid stale assertions and environment-dependent red runs | Test infrastructure, capability gates, or contract ownership change |
| [Capability mapping contract](architecture/capability-contract.md) | Evidenced upstream vocabulary, the `(operation, profile) → capability` table, the untranslatable declarations, and how it feeds discovery | Upstream vocabulary, capability ids, or discovery matching change |
| [Multimodal model connections](architecture/model-connection-multimodal.md) | One connection (address + credentials) that adds text, image, video and audio models in one pass, with per-kind discovery and partial-save semantics | The connection object, its endpoints, or multi-kind save rules change |
| [Roadmap](development/roadmap.md) | Capability dependencies and delivery criteria | Scope, dependencies, or acceptance criteria change |
| [Validation guide](development/validation.md) | Reproducible checks and evidence requirements | Tools, runtime requirements, or validation entry points change |
| [Agent turn timing](development/agent-timing.md) ([中文](development/agent-timing.zh-CN.md)) | Where one agent turn spends its time, and the pre-registered bands that decide the next optimization | The ledger, its reader, or a decision band changes |
Expand Down
128 changes: 128 additions & 0 deletions docs/architecture/model-connection-multimodal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Multimodal model connections

## 摘要(中文)

同一 API Key 往往同时提供语言、图片、视频、语音模型,但当前配置流程是「按模态建服务」:语言、图片、视频、音频各填一次地址与密钥、各自发现模型、各自保存。本文设计「连接(connection)」为第一次类对象:一次填写地址与凭据,按模态分别发现并分组的模型,一次保存为多个 `model-configs`(同一 `providerId`),并对部分失败、能力检查、协议差异和兼容性给出明确语义。本文只描述设计,不代表已实现。

Status: implemented for the settings entry point; the first-run wizard and the business CLI still use the per-kind form (see “Delivered scope”).

## Delivered scope

Implemented in this repository:

- `POST /api/model-configs/discover-many` and `POST /api/model-configs/connections`, backed by
`ModelCatalog.discover_many` / `ModelCatalog.save_connection` (`packages/core/src/opendirector/application/model_catalog.py`)
and `ModelConfigs.save_connection` (`packages/core/src/opendirector/infrastructure/model_configs.py`).
- Per-kind saving now replaces only rows of that kind, so a connection can grow kind by kind without
dropping its peers (`save_many` filters `previous` by kind).
- `src/canvas/ModelConnectionForm.tsx`, reachable from Settings → model connections →
“Add a connection (multi-modal)” and from the per-kind service list.
- Tests: `tests/test_model_catalog.py` (discovery isolation), `tests/test_model_configs.py`
(one providerId across kinds, partial failure, retry reusing the connection, rejected input) and the
browser workflow `tests/browser/model_connection.mjs`.

Not delivered yet: first-run wizard entry, CLI/agent tool parity, reusing an existing connection to add
only a missing kind from the settings list, and translating the panel into the per-kind forms.

## Problem

Configuration is currently kind-scoped end to end:

- UI: `src/canvas/ModelServiceForm.tsx` holds one `kind`; entering the first-run wizard for a MiniMax account with text, image, video and speech models means repeating the same URL and key four times.
- Discovery: `POST /api/model-configs/discover` takes a single `kind` and derives one protocol via `connection_fields()` (`packages/core/src/opendirector/domain/model_connection.py`), so `/models` is read under one protocol only.
- Save: `POST /api/model-configs/batch` accepts one `kind` plus `modelIds` (`apps/api/src/opendirector_api/main.py`).

The storage layer already models the missing concept: `providerId` groups configurations of different kinds that share `url`, `apiKey`, `connectionType`, `authMode` and `proxyMode` (`packages/core/src/opendirector/infrastructure/model_configs.py`). Today a user can only reach a shared connection by editing an existing configuration, never by creating one.

## Goals

1. One form fills address, authentication, proxy mode, capability-check policy, then adds models for several kinds in one pass.
2. Everything saved in that pass belongs to one `providerId`, so later credential edits apply to all kinds.
3. Model ability remains per-kind: a connection is not a claim that every model supports every operation.
4. Partial success is explicit: the user sees which kinds saved, which were rejected and why, and can retry only the failed part.
5. UI, CLI and agent tools keep using the same application service; no entry point gets a private shortcut.

Non-goals: automatic protocol guessing for self-hosted servers, cross-kind capability inference from model names, credential storage changes, migration of existing configurations.

## Object model

```
Connection (draft or stored providerId)
url, apiKey, connectionType, authMode, proxyMode, capabilityAutoCheck
└── KindEntry (kind, protocol, modelIds[]) # one per kind in this pass
└── ModelConfig (existing object, unchanged) # id, kind, modelId, protocol, ...
```

- A connection is identified by `providerId` only after the first successful save; drafts never persist identity.
- `protocol` stays on the kind entry, not on the connection: `openai` for agent/image/audio and `minimax_video_v2`/`kling_video`/`bigmodel_video`/`vllm_omni` for video are not interchangeable.
- A connection may exist with only some kinds configured. Missing kinds are absent, not empty.

## Discovery

For each kind the client asks the server to discover models for that kind's candidate protocol:

- `openai` kinds use `GET {url}/models` through `read_service_models()` (`packages/core/src/opendirector/integrations/model_capabilities.py`).
- Built-in-declaration protocols (`minimax_video_v2`, `kling_video`, `bigmodel_video`, `higgsfield_open`) return the declared list without a network call, as they do today.
- Model ids that appear in several kinds are kept per kind; a shared id is not evidence of shared input rules.

New endpoint: `POST /api/model-configs/discover-many` with `{url, apiKey, connectionType, authMode, proxyMode, kinds: [{kind, protocol}]}` returning
`{results: [{kind, protocol, models: [id], error: null | {code, message}}]}`.

Rules:

- One kind failing does not abort the others; each result carries its own error.
- Total discovery is bounded (kinds requested, response sizes, timeout) so a hung upstream cannot block the form.
- The draft is never written to disk; a failed discovery leaves configuration untouched (same contract as `read_service_models` today).

## Save

New endpoint: `POST /api/model-configs/connections` with
`{url, apiKey, connectionType, authMode, proxyMode, capabilityAutoCheck, providerId?, entries: [{kind, protocol, modelIds, modelOptions?}]}`.

Server behavior:

1. Validate the connection once (`model_fields`, `connection_fields` per entry).
2. Allocate or reuse `providerId`.
3. Save each entry through the existing `save_many()` path so per-kind rules, duplicate checks and capability declarations still apply.
4. Apply the connection fields to every peer carrying that `providerId`, as `save()` already does.
5. Return `{providerId, saved: [ModelConfig], rejected: [{kind, code, message}], remaining: [...]}`.

Failure semantics: entries are independent commits. A rejected entry (invalid model id, missing capability declaration, key rejected for that kind) does not roll back the saved ones; the response reports both sets and the UI offers "retry failed kinds" which reuses the same connection fields. This must not be described as all-or-nothing success.

Idempotency: the request carries an operation id; replaying it with identical input returns the original receipt, and replaying it with different input is rejected, consistent with other mutations.

## Capability checks

- `capabilityAutoCheck` stays a connection-level default but each model keeps its own availability record (`docs/guides/model-availability.md`).
- A saved model never blocks on capability probing; probing failure produces an explainable unavailable state, not a failed save.
- Video entries keep explicit `videoCapabilities` requirements; a connection with video models still needs output declarations or manual configuration.

## UI flow

1. `添加服务` becomes `添加连接`: provider preset, address, auth, proxy, capability-check policy.
2. `获取模型` runs discovery for every supported kind in one request; results render as collapsible kind sections with per-kind counts and errors.
3. Selecting models across sections enables one `保存连接` action; the footer reports `将启用 N 个模型(语言 x、图片 y、视频 z)`.
4. Save result screen lists saved kinds and rejected kinds with reasons, each with `重试` and `编辑`.
5. First-run wizard (`src/canvas/WelcomeScreen.tsx`) reuses the same component: after saving, the task step only asks for kinds the connection did not provide.
6. Settings → model access lists connections with their kinds, so the user can add a missing kind to an existing connection instead of creating a duplicate service.

Existing single-kind editing stays available for configurations that are not part of a connection and for self-hosted servers.

## Bilingual and accessibility

- Every new message key ships in `zh-CN` and `en-US`; stable values (`providerId`, kind ids, protocol ids) are never translated.
- Kind counts and partial-failure summaries use plural messages, not string concatenation.
- The save footer and the partial-failure list are announced via `role="status"`/`role="alert"`; focus moves to the first rejected entry.

## Testing

- Application tests: connection save creates one `providerId` across kinds; credential edit propagates to peers; duplicate model ids within a kind rejected; partially failing entries report saved/rejected sets and stay retryable.
- Discovery tests: one kind returning HTTP 401 while another succeeds; built-in declaration protocols skip the network; oversized responses rejected.
- Browser workflow: `tests/browser/first_run.mjs`-style isolated journey that configures text+image through one connection and asserts the assistant and image selections point at different kinds of the same `providerId`.
- CLI/agent parity: creating the same connection through the business CLI produces identical configuration rows.

## Compatibility and rollout

- Existing per-kind endpoints and configurations keep working; no migration, no rewriting of stored `providerId` values.
- The new connection entry point ships behind the same capability contract, so agent tools and CLI gain it only after the application service exists.
- Open question: whether `audio` and `vision` kinds should appear in the default multi-kind discovery, or only after the user picks a task that needs them.
Loading
Loading