Repository navigation
Preserve capability intent when checking and saving a model connection #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
a860a28
3a0b0ac
c87c03a
94c657c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
… 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
There are no files selected for viewing
| 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'; | ||
|
|
@@ -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 ?? []); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'); | ||
| } | ||
| 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'; | ||
|
|
@@ -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}> | ||
|
|
@@ -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); | ||
|
|
@@ -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>} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>; | ||
| } | ||
There was a problem hiding this comment.
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
membershipindependently of the observation label, and show the upstream ID when the label differs. This is part of the Phase 1 selection contract in #411.