59 lines
2.5 KiB
TypeScript
59 lines
2.5 KiB
TypeScript
import { areCLIFlagsEqual } from "@/lib/cli-flags";
|
|
import { areConfigOptionsEqual } from "@/lib/config-options";
|
|
import { arePermissionsDirty } from "@/lib/agent-permissions";
|
|
import { areEnvVarsEqual } from "@/components/settings/profile-edit/profile-env-vars-section";
|
|
import type { AgentProfile, PermissionSetting } from "@/lib/types/http";
|
|
|
|
/** True when any OpenAI-compatible provider field of the draft differs. */
|
|
export function isProviderConfigDirty(draft: AgentProfile, savedProfile: AgentProfile): boolean {
|
|
return (
|
|
(draft.providerKind ?? "") !== (savedProfile.providerKind ?? "") ||
|
|
(draft.providerBaseUrl ?? "") !== (savedProfile.providerBaseUrl ?? "") ||
|
|
(draft.providerApiKeySecretId ?? "") !== (savedProfile.providerApiKeySecretId ?? "")
|
|
);
|
|
}
|
|
|
|
/**
|
|
* True when any editable field of the profile editor draft differs from the
|
|
* last-saved profile. Drives the settings save bar's dirty state.
|
|
*/
|
|
export function isProfileDirty(
|
|
draft: AgentProfile,
|
|
savedProfile: AgentProfile,
|
|
permissionSettings: Record<string, PermissionSetting>,
|
|
): boolean {
|
|
return (
|
|
hasCoreProfileFieldsChanged(draft, savedProfile) ||
|
|
hasExecutionProfileFieldsChanged(draft, savedProfile, permissionSettings)
|
|
);
|
|
}
|
|
|
|
function hasCoreProfileFieldsChanged(draft: AgentProfile, savedProfile: AgentProfile): boolean {
|
|
return [
|
|
draft.name !== savedProfile.name,
|
|
draft.model !== savedProfile.model,
|
|
(draft.fallbackModel ?? "") !== (savedProfile.fallbackModel ?? ""),
|
|
(draft.autoFallback ?? false) !== (savedProfile.autoFallback ?? false),
|
|
(draft.requireExactModel ?? false) !== (savedProfile.requireExactModel ?? false),
|
|
(draft.mode ?? "") !== (savedProfile.mode ?? ""),
|
|
!areConfigOptionsEqual(draft.configOptions, savedProfile.configOptions),
|
|
].some(Boolean);
|
|
}
|
|
|
|
function hasExecutionProfileFieldsChanged(
|
|
draft: AgentProfile,
|
|
savedProfile: AgentProfile,
|
|
permissionSettings: Record<string, PermissionSetting>,
|
|
): boolean {
|
|
return [
|
|
arePermissionsDirty(draft, savedProfile, permissionSettings),
|
|
draft.cliPassthrough !== savedProfile.cliPassthrough,
|
|
(draft.cursorMcpAuthEnabled ?? true) !== (savedProfile.cursorMcpAuthEnabled ?? true),
|
|
(draft.enabled ?? true) !== (savedProfile.enabled ?? true),
|
|
!areCLIFlagsEqual(draft.cliFlags ?? [], savedProfile.cliFlags ?? []),
|
|
(draft.commandPrefix ?? "") !== (savedProfile.commandPrefix ?? ""),
|
|
isProviderConfigDirty(draft, savedProfile),
|
|
!areEnvVarsEqual(draft.envVars, savedProfile.envVars),
|
|
].some(Boolean);
|
|
}
|