Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat(model-connections): preserve capability intent through check and…
… save

Reconstruct saved local capability facts from stored values and bases so a
label-only edit keeps unknown optional capabilities, explicit values survive
restart, and an exact same-ID catalog candidate no longer replaces the saved
local row.

Separate editor suggestions from the facts serialized by Check and Save in the
Desktop model-connection flow. Suggestions stay in editor context, explicit
field edits and Apply suggestions declare UserDeclared values, clearing yields
unknown, and selection rows report catalog membership separately from this
check's directory observation.

Extend the production model-connection product journey with a controlled
directory covering an observed-only eligible ID, label-only and explicit field
edits including false, explicit adoption, partial directory and a per-model
tool test.

Signed-off-by: nillikechatchat <yuanhenglizhen2050@163.com>
Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
  • Loading branch information
nillikechatchat and MonkeyCode-AI committed Nov 9, 2026
commit a860a2861c375ef9ce0bb4eb86cfd5f4dc8a2da6
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { confirmDiscard, useDiscardGuard } from '../../ui/discard-guard';
import { saveFailureDefinitelyPreAdmission } from '../subscriptions/model';
import {
blankModel,
withCapabilityFallback,
toWireModel,
withSuggestions,
withRegisteredModels,
buildCheckDraft,
buildSaveChange,
Expand All @@ -39,7 +40,7 @@ import type {
ProviderMetadataRecord,
UpstreamProtocol,
} from './types';
import { checkFailureCode, modelAvailabilityMessage } from './copy';
import { checkFailureCode, modelAvailabilityMessage, modelObservationMessage } from './copy';
import { metadataModelPrefill } from './metadata-prefill';
import { customApiPrefillOptions, initialRegisteredOption, metadataProviderCandidates, metadataProviderOption, registeredModelCandidates, sortRegisteredOptions, templateEndpointForProtocol } from './registered-metadata';
import { ConnectionDirectory } from './ConnectionDirectory';
Expand Down Expand Up @@ -254,12 +255,11 @@ export function ModelConnectionForm(props: ModelConnectionFormProps) {
additional_endpoints,
models: candidates.map(candidate => {
const record = records.get(candidate.upstream_model_id);
if (candidate.capability_prefill) return {
...blankModel(candidate.upstream_model_id, candidate.display_name),
capabilities: candidate.capability_prefill,
};
return record ? withCapabilityFallback(metadataModelPrefill(record, clientOperationId('model')))
: blankModel(candidate.upstream_model_id, candidate.display_name);
if (record) return metadataModelPrefill(record, clientOperationId('model'));
return withSuggestions(
blankModel(candidate.upstream_model_id, candidate.display_name),
candidate.capability_prefill,
);
}),
});
if (credentialContextChanged) editingSession.current.beginPrefillFromContext(editingKey.current, metadataPrefillKey, `provider:${provider.provider_record_key}`, withProvider);
Expand Down Expand Up @@ -606,9 +606,9 @@ export function ModelConnectionForm(props: ModelConnectionFormProps) {
const selectedModels = automaticInferenceModel
? [...base.models, blankModel(automaticInferenceModel)] : base.models;
const current = { ...base, inference_model_id: inferenceModelId, models: selectedModels };
// The check needs complete execution defaults, but the editable draft must
// retain the user's declarations (including an explicit unknown value).
const checkedModels = selectedModels.map(withCapabilityFallback);
// Submit the draft's actual declarations. Untouched suggestions and unknown fields stay
// unknown; the daemon resolves any applicable trusted catalog defaults on its own.
const checkedModels = selectedModels;
if (current.display_name.trim().length > 60 || (!current.existing_source_id && (props.existingNames ?? []).includes(current.display_name.trim()))) { setError('CONNECTION_NAME_CONFLICT'); return; }
const allowedIds = new Set([...preservedModelIds.current,
...(!custom ? registeredCandidates.map(model => model.upstream_model_id) : [])]);
Expand Down Expand Up @@ -683,7 +683,7 @@ export function ModelConnectionForm(props: ModelConnectionFormProps) {
: await backend.checkRegisteredModelConnection({
display_name: checkingDraft.display_name,
inference_model_id: inferenceModelId,
models: checkedModels.filter(model => model.upstream_model_id).map(({ client_id: _clientId, ...model }) => ({ ...model, display_name: model.display_name.trim() || model.upstream_model_id })),
models: checkedModels.filter(model => model.upstream_model_id).map(toWireModel),
connection_option_id: registeredOption!.connection_option_id,
expected_catalog: connectionOptions!.catalog,
candidate_ref: checkingDraft.candidate_ref,
Expand Down Expand Up @@ -931,8 +931,8 @@ export function ModelConnectionForm(props: ModelConnectionFormProps) {

</select></label>
{selectedPrefill && <p className="field-help">{zh
? `已收录 ${metadataCandidates.length} 个模型,检查接入后统一选择;未知能力采用可编辑兜底:上下文 200K、输出 32K、工具与流式开启、视觉关闭、思考开关。`
: `${metadataCandidates.length} models in this catalog. Choose after checking the connection; missing capabilities use editable defaults (200K context, 32K output, tools and streaming on, vision off, reasoning toggle).`}</p>}
? `已收录 ${metadataCandidates.length} 个模型,检查接入后统一选择。资料中的能力只作为可编辑建议显示,需你确认后才提交;未填写的保持未知。`
: `${metadataCandidates.length} models in this catalog. Choose them after checking the connection. Catalog facts appear only as editable suggestions and stay unknown until you confirm them.`}</p>}
</div></Disclosure>}
</> : optionsLoading
? <div className="oc-status-row" role="status"><span className="oc-spinner" /><div className="row-main"><strong>{zh ? '正在读取接入方式' : 'Loading connection'}</strong><p>{zh ? '从本机可信目录确认当前支持的产品。' : 'Checking supported products in the local trusted catalog.'}</p></div></div>
Expand Down Expand Up @@ -991,7 +991,8 @@ export function ModelConnectionForm(props: ModelConnectionFormProps) {
{result.directory === 'partial' && <div className="callout warn"><UiIcon name="warning" /><span>{zh ? '模型目录只读取到一部分。可以先保存已确认的模型,稍后再重新检查。' : 'Only part of the model catalog was read. You can save confirmed models and check again later.'}</span></div>}
<fieldset className="v3-catalog model-result-list" disabled={!props.mutable}><legend className="sr-only">{zh ? '选择保存的模型' : 'Select models to save'}</legend>{result.candidate.models.map((model, index) => {
const canSelect = modelCanBeSelected(result, model, true);
return <div className="model-result-row" key={model.model_ref}><label className="check-row"><input type="checkbox" data-autofocus={index === 0 || undefined} disabled={!canSelect} checked={canSelect && selected.has(model.model_ref)} onChange={event => { const next = new Set(selected); if (event.target.checked) next.add(model.model_ref); else next.delete(model.model_ref); selectionRef.current = { result, refs: next }; setSelected(next); setError(''); }} /><div><strong>{model.display_name}</strong><span>{draft.display_name}{model.fact_basis === 'runtime_fallback' ? ` · ${zh ? '运行时保守兜底' : 'Conservative runtime fallback'}` : ''}{!canSelect ? ` · ${modelAvailabilityMessage(model.reason, zh)}` : ''}</span></div></label>{custom && !canSelect && <button className="btn btn-quiet" type="button" onClick={() => {
const observation = modelObservationMessage(result, model, zh);
return <div className="model-result-row" key={model.model_ref}><label className="check-row"><input type="checkbox" data-autofocus={index === 0 || undefined} disabled={!canSelect} checked={canSelect && selected.has(model.model_ref)} onChange={event => { const next = new Set(selected); if (event.target.checked) next.add(model.model_ref); else next.delete(model.model_ref); selectionRef.current = { result, refs: next }; setSelected(next); setError(''); }} /><div><strong>{model.display_name}</strong><span>{observation ? `${observation} · ` : ''}{draft.display_name}{model.fact_basis === 'runtime_fallback' ? ` · ${zh ? '运行时保守兜底' : 'Conservative runtime fallback'}` : ''}{!canSelect ? ` · ${modelAvailabilityMessage(model.reason, zh)}` : ''}</span></div></label>{custom && !canSelect && <button className="btn btn-quiet" type="button" onClick={() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Show official catalog match alongside directory observation.

This row renders the current directory observation without using membership. In a partial-directory browser fixture, the catalog-matched row and the observed-only row both showed “Returned by this check” with no indication of their different origins. A row with a local display name also hid its exact upstream ID.

Render the catalog match from membership independently of the observation label, and show the upstream ID when the label differs. This is part of the Phase 1 selection contract in #411.

const prefilled = draftRef.current.models.find(value => value.upstream_model_id === model.upstream_model_id);
const manualDraft = { ...draftRef.current, edit_revision: draftRef.current.edit_revision + 1, check_id: '', models: [prefilled ?? blankModel(model.upstream_model_id, model.display_name)] };
draftRef.current = manualDraft; setDraft(manualDraft); setResult(null); setScreen('manual'); setError('');
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/features/model-connections/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ discovered, removed, or unavailable models are never automatically selected.

The composition owner must provide the real Tauri/Client Core adapter, open/return navigation, current revision set, protected-input lifecycle, and save recovery callbacks. The feature intentionally does not implement storage, transaction recovery, routing compilation, or the “My models” page.

The connection-options response also carries the daemon-selected complete metadata snapshot. The directory uses executable native API options; model candidates and capability prefill come from the selected option and its matching metadata. Custom API prefill offers those same native options and keeps the configuration editable. Unknown capabilities use the form's editable defaults. Credentials are never inferred, lifecycle data is warning-only, and nested cost hints are explicitly presented as “not a price.” A connection check remains mandatory before selected metadata can be saved.
The connection-options response also carries the daemon-selected complete metadata snapshot. The directory uses executable native API options; model candidates and capability prefill come from the selected option and its matching metadata. Custom API prefill offers those same native options and keeps the configuration editable. Capability prefill from a template or metadata record is presented as editable suggestions held in the current editor context; a new local model's serialized facts start `value: null` and `basis: unknown`, and only an explicit field edit or **Apply suggestions** writes `UserDeclared` for the affected fields. Clearing a field yields unknown and is remembered so Apply suggestions will not silently refill it. `state.ts` owns this boundary through `unknownCapabilities`/`suggestedCapabilities`, `displayCapabilities`, `declareCapability`, `applySuggestedCapabilities` and `toWireModel`; `toWireModel` strips client-only fields and suggestions before the wire draft. The selection list labels a row from current directory observation (`modelObservationMessage`): membership identifies an official match, `observed_model_ids` identifies a return from this check, and a complete reachable directory distinguishes **Not returned by this check** from the **Not confirmed by this check** used for a partial, unavailable, invalid or omitted directory. Credentials are never inferred, lifecycle data is warning-only, and nested cost hints are explicitly presented as “not a price.” A connection check remains mandatory before selected metadata can be saved.

Exact registered prefill/check and new publication use the shared scoped-default resolver.
User/ambiguous declarations retain saved intent; connector-verified authority is preserved.
Expand Down
23 changes: 22 additions & 1 deletion apps/desktop/src/features/model-connections/copy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ModelConnectionCheckView } from './types';
import type { CandidateModelView, ModelConnectionCheckView } from './types';

export function checkFailureCode(check: Pick<ModelConnectionCheckView, 'authentication' | 'inference' | 'issues'>): string | null {
if (check.authentication === 'rejected') return 'MODEL_CONNECTION_AUTHENTICATION_REJECTED';
Expand Down Expand Up @@ -42,3 +42,24 @@ export function modelAvailabilityMessage(reason: string | null | undefined, zh:
? '当前不可选择,请检查模型能力与接入状态。'
: 'Unavailable; check model capabilities and connection status.';
}


/**
* Independent current-observation label from the exact directory result. Catalog membership and
* selection eligibility stay separate from whether this check actually returned the ID.
*/
export function modelObservationMessage(
result: Pick<ModelConnectionCheckView, 'directory' | 'reachability' | 'observed_model_ids'>,
model: Pick<CandidateModelView, 'upstream_model_id'>,
zh: boolean,
): string | null {
const observed = new Set(result.observed_model_ids ?? []);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Build the observed ID set once per Check result.

The list calls this helper for each candidate on each render, including when the user toggles a selection. At 1,000 returned IDs and 1,000 candidate rows, that is about one million set insertions per render. In a local measurement, label computation alone took about 19 ms per pass at that size. Reuse the set across rows and selection changes.

if (observed.has(model.upstream_model_id)) {
return zh ? '本次检查已返回' : 'Returned by this check';
}
const complete = result.reachability === 'reachable'
&& (result.directory === 'available' || result.directory === 'empty');
return complete
? (zh ? '本次检查未返回' : 'Not returned by this check')
: (zh ? '本次检查未能确认' : 'Not confirmed by this check');
}
21 changes: 15 additions & 6 deletions apps/desktop/src/features/model-connections/form-support.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type {
CapabilityKey,
ComputeConnectionOption,
ModelCapabilities,
ModelDeclaration,
NativeReasoning,
TriState,
} from './types';
import { Disclosure } from '../../ui/Disclosure';
import { applySuggestedCapabilities, capabilityKeys, declareCapability, displayCapabilities } from './state';

export { safeConnectionErrorCode } from './copy';
export { blankModel } from './state';
Expand Down Expand Up @@ -182,9 +185,14 @@ export function ManualModelEditor({ model, language, disabled, catalogManaged =
onChange(next: ModelDeclaration): void;
}) {
const zh = language === 'zh';
const updateCapability = <K extends keyof ModelDeclaration['capabilities'],>(key: K, value: ModelDeclaration['capabilities'][K]) =>
onChange({ ...model, capabilities: { ...model.capabilities, [key]: value } });
const reasoning = model.capabilities.native_reasoning.value;
const shown = displayCapabilities(model);
const updateCapability = <K extends CapabilityKey,>(key: K, value: ModelCapabilities[K]) =>
onChange(declareCapability(model, key, value));
const hasSuggestions = model.suggested_capabilities !== undefined
&& capabilityKeys.some(key => model.capabilities[key].basis === 'unknown'
&& !(model.cleared_capabilities ?? []).includes(key)
&& model.suggested_capabilities![key].value !== null);
const reasoning = shown.native_reasoning.value;
const reasoningKind = reasoning?.kind ?? 'unknown';

return <fieldset className="connection-fields manual-capability-fields" disabled={disabled}>
Expand All @@ -202,13 +210,13 @@ export function ManualModelEditor({ model, language, disabled, catalogManaged =
['tool', zh ? '工具调用' : 'Tool calling'],
['vision', zh ? '图片输入' : 'Image input'],
['streaming', zh ? '流式输出' : 'Streaming'],
] as const).map(([key, label]) => <label className="field" key={key}><span className="field-label">{label}</span><select className="select" value={triState(model.capabilities[key].value)} onChange={event => updateCapability(key, booleanFact(event.target.value as TriState))}><option value="unknown">{zh ? '未知' : 'Unknown'}</option><option value="supported">{zh ? '支持' : 'Supported'}</option><option value="unsupported">{zh ? '不支持' : 'Not supported'}</option></select></label>)}
] as const).map(([key, label]) => <label className="field" key={key}><span className="field-label">{label}</span><select className="select" value={triState(shown[key].value)} onChange={event => updateCapability(key, booleanFact(event.target.value as TriState))}><option value="unknown">{zh ? '未知' : 'Unknown'}</option><option value="supported">{zh ? '支持' : 'Supported'}</option><option value="unsupported">{zh ? '不支持' : 'Not supported'}</option></select></label>)}
<label className="field"><span className="field-label">{zh ? '思考能力' : 'Reasoning capability'}</span><select className="select" value={reasoningKind} onChange={event => {
const value = reasoningValue(event.target.value as NativeReasoning['kind'], reasoning);
updateCapability('native_reasoning', { value, basis: value ? 'user_declared' : 'unknown' });
}}><option value="unknown">{zh ? '未知' : 'Unknown'}</option><option value="fixed">{zh ? '供应商固定' : 'Provider fixed'}</option><option value="toggle">{zh ? '开关' : 'On / off'}</option><option value="discrete">{zh ? '可选档位' : 'Discrete levels'}</option><option value="budget">{zh ? 'Token 预算' : 'Token budget'}</option></select></label>
<label className="field"><span className="field-label">{zh ? '上下文上限 · tokens' : 'Context limit · tokens'}</span><input className="input" type="number" min="1" value={model.capabilities.context_tokens.value ?? ''} onChange={event => updateCapability('context_tokens', numberFact(event.target.value))} /></label>
<label className="field"><span className="field-label">{zh ? '输出上限 · tokens' : 'Output limit · tokens'}</span><input className="input" type="number" min="1" value={model.capabilities.max_output_tokens.value ?? ''} onChange={event => updateCapability('max_output_tokens', numberFact(event.target.value))} /></label>
<label className="field"><span className="field-label">{zh ? '上下文上限 · tokens' : 'Context limit · tokens'}</span><input className="input" type="number" min="1" value={shown.context_tokens.value ?? ''} onChange={event => updateCapability('context_tokens', numberFact(event.target.value))} /></label>
<label className="field"><span className="field-label">{zh ? '输出上限 · tokens' : 'Output limit · tokens'}</span><input className="input" type="number" min="1" value={shown.max_output_tokens.value ?? ''} onChange={event => updateCapability('max_output_tokens', numberFact(event.target.value))} /></label>
</div>
{reasoning?.kind === 'discrete' && <label className="field"><span className="field-label">{zh ? '支持的档位 · 从低到高,逗号分隔' : 'Supported levels · low to high, comma separated'}</span><input className="input" value={reasoning.profiles.join(', ')} placeholder="low, medium, high" onChange={event => {
const profiles = event.target.value.split(',').map(value => value.trim()).filter(Boolean);
Expand All @@ -224,6 +232,7 @@ export function ManualModelEditor({ model, language, disabled, catalogManaged =
] as const).map(([key, label]) => <label className="field" key={key}><span className="field-label">{label}</span><input className="input" type="number" min="1" value={reasoning[key]} onChange={event => updateCapability('native_reasoning', { value: { ...reasoning, [key]: Number(event.target.value) }, basis: 'user_declared' })} /></label>)}
</div>}
</Disclosure>
{hasSuggestions && <div className="manual-capability-suggestions"><button className="btn btn-quiet" type="button" onClick={() => onChange(applySuggestedCapabilities(model))}>{zh ? '采纳建议值' : 'Apply suggested values'}</button><span className="field-help">{zh ? '建议值仅填充仍为“未知”的能力,不会覆盖你的填写。' : 'Suggestions fill only values still marked Unknown and never overwrite your edits.'}</span></div>}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Show the suggestions before they can be adopted.

I could click “Apply suggested values” with “Capabilities and limits” collapsed, adopting values I had not seen. Phase 1 calls for explicit adoption of the displayed suggestions. Put the action alongside the visible values and indicate which fields still contain pending suggestions. The regression should also confirm that adoption preserves fields the user edited or cleared.

</>}
</fieldset>;
}
Loading
Loading