Skip to content
Merged
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
34 changes: 21 additions & 13 deletions crates/dim-modality/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use rutis::host::{BoxFuture, CtxHost, DynPlugin, Effect, Key, TypeKey};
use serde::{Deserialize, Deserializer, Serialize};
use std::collections::BTreeMap;
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::{Arc, OnceLock};
use std::time::Duration;
pub use targets::{ModalityTargets, TargetError, TargetReply, TargetRequest};
pub use task::{TaskRecord, TaskState};
Expand Down Expand Up @@ -454,6 +454,7 @@ pub(crate) struct Evaluation {
global: Option<ModelId>,
/// The process context adapter copies are read from per call (A.2).
ctx: Ctx,
has_resolved_adapter: OnceLock<bool>,
/// Whether this daemon holds a HostPlatform, which a host task runs on
/// (A14).
host_platform: bool,
Expand Down Expand Up @@ -638,11 +639,17 @@ impl Evaluation {
.is_some_and(|adapter| adapter.0.available())
})
}
/// Whether an adapter serves any candidate provider at all, whatever it
/// claims: an adapter that serves no candidate model is not "no adapter".
fn has_adapter(&self) -> bool {
self.candidates()
.any(|model| self.adapter(&model.provider_id).is_some())
fn image_adapter_reason(&self, unserved: &str) -> Reason {
let has_adapter = *self.has_resolved_adapter.get_or_init(|| {
self.candidates()
.any(|model| self.adapter(&model.provider_id).is_some())
});
let detail = if has_adapter {
unserved
} else {
"No image adapter in this build"
};
reason("adapter", detail)
}
/// Whether the adapter of some candidate model serves this category; its
/// `operations` then decides the category's options.
Expand Down Expand Up @@ -696,7 +703,9 @@ impl Evaluation {
Err(reason("runtime", "The adapter is unavailable"))
};
}
if category != "image" && !self.adapter_serves(category) {
if category == "image" {
Err(self.image_adapter_reason("No available adapter serves the model"))
} else if !self.adapter_serves(category) {
Err(reason("build", "Not in this build"))
} else {
Err(reason("adapter", "No available adapter serves the model"))
Expand Down Expand Up @@ -884,12 +893,10 @@ impl Evaluation {
)],
)
} else if category == "image" {
let detail = if self.has_adapter() {
"The adapter serves no image model Provider lists"
} else {
"No image adapter in this build"
};
(false, vec![reason("adapter", detail)])
(
false,
vec![self.image_adapter_reason("The adapter serves no image model Provider lists")],
)
} else {
(false, vec![reason("build", "Not in this build")])
};
Expand Down Expand Up @@ -1082,6 +1089,7 @@ pub(crate) async fn evaluate(
declared,
global,
ctx: ctx.clone(),
has_resolved_adapter: OnceLock::new(),
host_platform: ctx
.get::<dim_agent_capabilities::host_platform::HostPlatform>()
.is_some(),
Expand Down
5 changes: 3 additions & 2 deletions crates/dim-modality/tests/modality_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,10 +1700,11 @@ async fn the_product_build_reports_image_operations_without_an_adapter() {
for name in ["generate", "edit", "enhance"] {
let entry = operation(&snapshot, name);
assert_eq!(entry["available"], false, "{entry}");
assert_eq!(entry["reasons"][0]["dimension"], "adapter");
let reason = json!({"dimension": "adapter", "detail": "No image adapter in this build"});
assert_eq!(entry["reasons"], json!([reason]));
let unserved = |model_id: &str| {
json!({"providerId": PROVIDER, "modelId": model_id, "available": false,
"reason": {"dimension": "adapter", "detail": "No available adapter serves the model"}})
"reason": reason})
};
assert_eq!(
entry["options"],
Expand Down
2 changes: 2 additions & 0 deletions docs/design/plugins/Modality.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ A session ends on `close`; when the opening client connection ends, silently, be

The image operations are the first implementation slice, and the product build now ships an adapter for part of it: the built-in `dim-modality-aimux` adapter (A.2) serves `generate` and, where the provider's package reads an edit's input files, `edit` through aimux, and `enhance` remains an adapter operation no build serves, so it reports `unavailable` with an `adapter` reason. Availability is a property of the runtime and is answered per model: `available` is true once the adapter is installed, and `operations` decides what it serves for the model a task names. The built-in family copy answers image `operations` for the bundled catalog providers listed in A.2. A created provider whose UUID has no provider copy still resolves the family copy; its image models get the `adapter` reason because that copy's `operations` returns no image operation for them, not because no binding exists. A resolved adapter that serves none of the models Provider lists is not a missing adapter and says so: the image operations keep the `adapter` dimension with "the adapter serves no image model Provider lists", and their options are the declared models, each `available: false` with the reason no adapter runs it, so an option never claims a run its operation refuses. `understand` resolves the target for its Session consumer (§9.4). Configurability is a property of settings: `configure` accepts a default for every A.1 operation that has a default key whenever the model is in that operation's options, served or not, so defaults can be persisted before a runtime lands; the saved default then reads `available: false` with its reason, and an operation this build cannot run keeps `available: false` with its `build` or `adapter` reason. A host target is the exception: it is configurable only while it can run here (A.2.1). Flow tests configure the fixture adapter to serve the adapter operations they exercise, and the end-to-end flows run the built-in adapter against a stub provider.

When Modality resolves no adapter for any Provider candidate, the image task operation, its declared options and any default among those options all report `adapter` with "No image adapter in this build".

Realtime options follow Provider's transport declarations rather than narrowing through the resolved adapter's `operations`. A specialized provider copy that does not serve realtime can therefore leave a declared model in the option list while `realtime.open` rejects it as `unavailable`; resolution does not retry the family copy when a present provider copy lacks an operation.

`dimcode modality set-default image.generate <provider>/<model>` and the Web page call `modality.configure`, which validates the model against the operation's options (A.3). A Provider model offered for the operation can be saved with `available: false`. An OCR host target must be able to run on this host (A.2.1). It then writes the operation key in Modality's own `modality` settings document through its owner write (Settings CAS). `model: null` clears that key. The reply is the same snapshot `modality.capabilities` returns, including the new `revision`, so a client applies it without a second read.
Expand Down
2 changes: 2 additions & 0 deletions docs/zh/design/plugins/Modality.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ sequenceDiagram

图像操作是第一个实现切片,产品构建现在为该切片的一部分内置了适配器:内置 `dim-modality-aimux` 适配器(A.2)经 aimux 服务 `generate`,并在提供方的包读取编辑输入文件时服务 `edit`,而 `enhance` 仍是没有任何构建服务的适配器操作,因此以 `adapter` 原因报告 `unavailable`。可用性是运行时的属性,并按模型回答:安装后 `available` 即为 true,具体服务什么由 `operations` 针对任务所指的模型决定。内置家族名副本为 A.2 列出的内建目录提供方回答图像 `operations`。自建提供方的 UUID 没有专属副本时,仍会解析到家族名副本;其图像模型报 `adapter` 原因是因为该副本的 `operations` 不为它们返回图像操作,而不是没有绑定。已解析的适配器若不为 Provider 列出的任何模型服务,不算缺少适配器,并如实说明:图像操作仍用 `adapter` 维度,报“the adapter serves no image model Provider lists”,其选项是已声明的模型,每个都 `available: false` 并带上没有适配器运行它的原因,因此选项从不声称能运行一个其操作会拒绝的模型。`understand` 为 Session 使用方解析目标(§9.4)。可配置性是设置的属性:只要模型在该操作的选项中(无论是否有适配器服务),`configure` 就接受任何有默认 key 的 A.1 操作的默认值,因此默认值可以在运行时落地之前持久化;保存后的默认值显示 `available: false` 及其原因,本构建不能运行的操作仍保持 `available: false` 及其 `build` 或 `adapter` 原因。主机目标例外:只有在本机能运行时才可配置(A.2.1)。流程测试配置 fixture 适配器服务它们所覆盖的适配器操作,端到端流程则让内置适配器对着桩提供方运行。

当 Modality 无法为任何 Provider 候选模型解析到适配器时,图像任务操作、其已声明的选项以及这些选项中的默认值都报告 `adapter`,详情为 “No image adapter in this build”。

Realtime 选项跟随 Provider 的传输声明,不经解析到的适配器的 `operations` 收窄。因此,不服务 realtime 的提供方专属副本可能让声明过的模型仍出现在选项中,但 `realtime.open` 以 `unavailable` 拒绝;已存在的提供方副本缺少某个操作时,不会重试家族名副本。

`dimcode modality set-default image.generate <provider>/<model>` 和 Web 页调用 `modality.configure`,由它按操作的选项校验模型(A.3)。该操作提供的 Provider 模型即使标为 `available: false` 也可以保存。OCR 宿主目标必须能在本机运行(A.2.1)。随后经所有者写入(Settings CAS)把默认值写入 Modality 自己的 `modality` 设置文档。`model: null` 清除该默认值。回复与 `modality.capabilities` 返回的是同一个快照,含新的 `revision`,客户端无需再读一次。
Expand Down