fix: track agent config changes and health-check selected models only
This commit is contained in:
1 parent
4d32f58ee2
commit
02c6fac72a
8 files changed
+180
-59
No files matched your search
@@ -0,0 +1,68 @@
|
||||
export type AgentConfigurationClientId =
|
||||
| 'claude-code'
|
||||
| 'claude-desktop'
|
||||
| 'codex'
|
||||
| 'opencode'
|
||||
| 'openclaw'
|
||||
| 'hermes'
|
||||
| 'pi';
|
||||
|
||||
export type AgentConfigurationModificationState = 'unconfigured' | 'applied' | 'invalid';
|
||||
|
||||
export type AgentConfigurationAction = 'apply' | 'update' | 'close';
|
||||
|
||||
export type AgentModelMappings = {
|
||||
opus: string;
|
||||
sonnet: string;
|
||||
haiku: string;
|
||||
};
|
||||
|
||||
type ResolveAgentConfigurationActionOptions = {
|
||||
client: AgentConfigurationClientId;
|
||||
modificationState: AgentConfigurationModificationState;
|
||||
selectedModel: string;
|
||||
appliedModel: string;
|
||||
oauthConfiguration: boolean;
|
||||
appliedOauthConfiguration: boolean;
|
||||
modelMappings: AgentModelMappings;
|
||||
appliedModelMappings: AgentModelMappings;
|
||||
};
|
||||
|
||||
const normalizedModel = (value: string) => value.trim().toLocaleLowerCase();
|
||||
|
||||
export const sameAgentModel = (left: string, right: string) => (
|
||||
normalizedModel(left) === normalizedModel(right)
|
||||
);
|
||||
|
||||
export const sameAgentModelMappings = (
|
||||
left: AgentModelMappings,
|
||||
right: AgentModelMappings,
|
||||
) => sameAgentModel(left.opus, right.opus)
|
||||
&& sameAgentModel(left.sonnet, right.sonnet)
|
||||
&& sameAgentModel(left.haiku, right.haiku);
|
||||
|
||||
export function resolveAgentConfigurationAction({
|
||||
client,
|
||||
modificationState,
|
||||
selectedModel,
|
||||
appliedModel,
|
||||
oauthConfiguration,
|
||||
appliedOauthConfiguration,
|
||||
modelMappings,
|
||||
appliedModelMappings,
|
||||
}: ResolveAgentConfigurationActionOptions): AgentConfigurationAction {
|
||||
if (modificationState !== 'applied') return 'apply';
|
||||
if (client === 'pi') return 'close';
|
||||
|
||||
const modelChanged = client === 'claude-code' || client === 'claude-desktop'
|
||||
? !sameAgentModelMappings(modelMappings, appliedModelMappings)
|
||||
: Boolean(
|
||||
selectedModel.trim()
|
||||
&& appliedModel.trim()
|
||||
&& !sameAgentModel(selectedModel, appliedModel),
|
||||
);
|
||||
const oauthChanged = client === 'codex'
|
||||
&& oauthConfiguration !== appliedOauthConfiguration;
|
||||
|
||||
return modelChanged || oauthChanged ? 'update' : 'close';
|
||||
}
|
||||
Reference in new issue
Block a user