Skip to content

Commit 2910ea4

Browse files
morgmartnpub1d6t84ajeg9skp2609l2k6axgcme8x7g7u7luj352r03hcwreg7lqnxcsexnpub1s654z6utm59mkg4tjdqw69tlen05y2hrrwajlck4n2ar0jyx7hfsmp60kf
authored
Redesign agent AI configuration and defaults (#1935)
Signed-off-by: npub1d6t84ajeg9skp2609l2k6axgcme8x7g7u7luj352r03hcwreg7lqnxcsex <6e967af659416160ab4f2fd56d74c8c6f273791ee7bfc9468a1be37c387947be@sprout-oss.stage.blox.sqprod.co> Signed-off-by: npub1s654z6utm59mkg4tjdqw69tlen05y2hrrwajlck4n2ar0jyx7hfsmp60kf <86a9516b8bdd0bbb22ab9340ed157fccdf422ae31bbb2fe2d59aba37c886f5d3@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1d6t84ajeg9skp2609l2k6axgcme8x7g7u7luj352r03hcwreg7lqnxcsex <6e967af659416160ab4f2fd56d74c8c6f273791ee7bfc9468a1be37c387947be@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1s654z6utm59mkg4tjdqw69tlen05y2hrrwajlck4n2ar0jyx7hfsmp60kf <86a9516b8bdd0bbb22ab9340ed157fccdf422ae31bbb2fe2d59aba37c886f5d3@sprout-oss.stage.blox.sqprod.co>
1 parent 0722346 commit 2910ea4

30 files changed

Lines changed: 1041 additions & 535 deletions
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Tabs, TabsList, TabsTrigger } from "@/shared/ui/tabs";
2+
import type { AgentAiConfigurationMode } from "./agentAiConfigurationPolicy";
3+
4+
export type { AgentAiConfigurationMode } from "./agentAiConfigurationPolicy";
5+
6+
export function AgentAiConfigurationModeField({
7+
mode,
8+
onModeChange,
9+
}: {
10+
mode: AgentAiConfigurationMode;
11+
onModeChange: (mode: AgentAiConfigurationMode) => void;
12+
}) {
13+
return (
14+
<div className="space-y-1.5">
15+
<p className="text-sm font-medium text-foreground">AI configuration</p>
16+
<Tabs
17+
onValueChange={(value) =>
18+
onModeChange(value as AgentAiConfigurationMode)
19+
}
20+
value={mode}
21+
>
22+
<TabsList>
23+
<TabsTrigger value="defaults">Use AI defaults</TabsTrigger>
24+
<TabsTrigger value="custom">Customize for this agent</TabsTrigger>
25+
</TabsList>
26+
</Tabs>
27+
{mode === "custom" ? (
28+
<p className="text-xs text-muted-foreground">
29+
Provider and model changes apply only to this agent.
30+
</p>
31+
) : null}
32+
</div>
33+
);
34+
}

‎desktop/src/features/agents/ui/AgentAiDefaults.tsx‎

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useAppNavigation } from "@/app/navigation/useAppNavigation";
1+
import type * as React from "react";
22
import type { InheritedDefault } from "./bakedEnvHelpers";
33
import { getPersonaProviderOptions } from "./personaDialogPickers";
44
import { Button } from "@/shared/ui/button";
@@ -26,78 +26,45 @@ export function formatAiDefaultsSummary({
2626
}
2727

2828
export function AgentAiDefaultsNotice({
29-
confirmNavigation = false,
29+
onEditDefaults,
30+
triggerRef,
3031
explicitModel,
3132
explicitProvider,
3233
inheritedModel,
3334
inheritedProvider,
3435
}: {
35-
confirmNavigation?: boolean;
36+
onEditDefaults: () => void;
37+
triggerRef?: React.Ref<HTMLButtonElement>;
3638
explicitModel: string;
3739
explicitProvider: string;
3840
inheritedModel: InheritedDefault;
3941
inheritedProvider: InheritedDefault;
4042
}) {
41-
const { goSettings } = useAppNavigation();
42-
const inheritsProvider = explicitProvider.trim().length === 0;
43-
const inheritsModel = explicitModel.trim().length === 0;
44-
45-
const usesCustomConfig = !inheritsProvider && !inheritsModel;
46-
const requiredProviderMissing = inheritsProvider && !inheritedProvider.value;
47-
48-
const inheritedParts = [
49-
inheritsProvider
50-
? inheritedProvider.value
51-
? `Provider ${providerLabel(inheritedProvider.value)}`
52-
: "Provider not configured"
53-
: null,
54-
inheritsModel
55-
? inheritedModel.value
56-
? `Model ${inheritedModel.value}`
57-
: "Model not configured"
58-
: null,
59-
].filter((value): value is string => Boolean(value));
43+
const provider = explicitProvider.trim() || inheritedProvider.value;
44+
const model = explicitModel.trim() || inheritedModel.value;
6045

6146
return (
62-
<div
63-
className="flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border/60 bg-muted/30 px-3 py-2"
64-
data-testid="agent-ai-defaults-notice"
65-
>
66-
<div className="min-w-0">
67-
<p className="text-xs font-medium text-foreground">
68-
{usesCustomConfig
69-
? "Custom AI configuration"
70-
: requiredProviderMissing
71-
? "AI defaults aren’t configured"
72-
: inheritsProvider && inheritsModel
73-
? "Uses AI defaults"
74-
: "Partially uses AI defaults"}
75-
</p>
76-
<p className="text-xs text-muted-foreground">
77-
{usesCustomConfig
78-
? "This agent won’t follow provider or model default changes."
79-
: requiredProviderMissing
80-
? "Choose a provider in AI defaults to use this agent."
81-
: `${inheritedParts.join(" · ")}. Inherited fields follow future changes.`}
82-
</p>
83-
</div>
47+
<div className="space-y-1" data-testid="agent-ai-defaults-notice">
48+
<dl className="grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 text-sm">
49+
<dt className="text-muted-foreground">Provider</dt>
50+
<dd className="truncate text-foreground">
51+
{provider ? providerLabel(provider) : "Not configured"}
52+
</dd>
53+
<dt className="text-muted-foreground">Model</dt>
54+
<dd className="truncate text-foreground">
55+
{model || "Not configured"}
56+
</dd>
57+
</dl>
8458
<Button
85-
onClick={() => {
86-
if (
87-
confirmNavigation &&
88-
!window.confirm(
89-
"Leave this agent without saving? Your changes will be discarded.",
90-
)
91-
) {
92-
return;
93-
}
94-
void goSettings("agents");
95-
}}
59+
className="h-auto px-0 py-1"
60+
data-testid="edit-ai-defaults"
61+
onClick={onEditDefaults}
62+
ref={triggerRef}
9663
size="xs"
9764
type="button"
9865
variant="link"
9966
>
100-
Edit AI defaults
67+
Edit global defaults
10168
</Button>
10269
</div>
10370
);
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import * as React from "react";
2+
3+
import {
4+
GlobalAgentConfigEditor,
5+
type GlobalAgentConfigSaveResult,
6+
} from "./GlobalAgentConfigEditor";
7+
import {
8+
AlertDialog,
9+
AlertDialogAction,
10+
AlertDialogCancel,
11+
AlertDialogContent,
12+
AlertDialogDescription,
13+
AlertDialogFooter,
14+
AlertDialogHeader,
15+
AlertDialogTitle,
16+
} from "@/shared/ui/alert-dialog";
17+
import { Button } from "@/shared/ui/button";
18+
import {
19+
Dialog,
20+
DialogContent,
21+
DialogDescription,
22+
DialogHeader,
23+
DialogTitle,
24+
} from "@/shared/ui/dialog";
25+
26+
export function AgentAiDefaultsDialog({
27+
open,
28+
onOpenChange,
29+
returnFocusRef,
30+
}: {
31+
open: boolean;
32+
onOpenChange: (open: boolean) => void;
33+
returnFocusRef: React.RefObject<HTMLButtonElement | null>;
34+
}) {
35+
const [dirty, setDirty] = React.useState(false);
36+
const [saving, setSaving] = React.useState(false);
37+
const [confirmDiscard, setConfirmDiscard] = React.useState(false);
38+
const [restartFailures, setRestartFailures] = React.useState(0);
39+
const secondaryActionRef = React.useRef<HTMLButtonElement>(null);
40+
const restoreDefaultsFocusRef = React.useRef(false);
41+
42+
const closeAndRestoreFocus = React.useCallback(() => {
43+
onOpenChange(false);
44+
requestAnimationFrame(() => returnFocusRef.current?.focus());
45+
}, [onOpenChange, returnFocusRef]);
46+
47+
const requestClose = React.useCallback(() => {
48+
if (saving) return;
49+
if (dirty) {
50+
setConfirmDiscard(true);
51+
return;
52+
}
53+
closeAndRestoreFocus();
54+
}, [closeAndRestoreFocus, dirty, saving]);
55+
56+
function handleSaveSuccess(result: GlobalAgentConfigSaveResult) {
57+
if (result.failed_restart_count > 0) {
58+
setRestartFailures(result.failed_restart_count);
59+
return;
60+
}
61+
closeAndRestoreFocus();
62+
}
63+
64+
React.useEffect(() => {
65+
if (open) {
66+
setDirty(false);
67+
setConfirmDiscard(false);
68+
setRestartFailures(0);
69+
}
70+
}, [open]);
71+
72+
return (
73+
<>
74+
<Dialog
75+
open={open}
76+
onOpenChange={(nextOpen) => {
77+
if (!nextOpen) requestClose();
78+
}}
79+
>
80+
<DialogContent
81+
className="max-h-[calc(100vh-2rem)] max-w-2xl overflow-y-auto"
82+
data-testid="agent-ai-defaults-dialog"
83+
onCloseAutoFocus={(event) => {
84+
event.preventDefault();
85+
returnFocusRef.current?.focus();
86+
}}
87+
>
88+
<DialogHeader>
89+
<DialogTitle>AI defaults</DialogTitle>
90+
<DialogDescription>
91+
These settings are inherited by agents using AI defaults. Saving
92+
may restart affected running agents.
93+
</DialogDescription>
94+
</DialogHeader>
95+
<GlobalAgentConfigEditor
96+
onDirtyChange={setDirty}
97+
onSaveSuccess={handleSaveSuccess}
98+
onSavingChange={setSaving}
99+
secondaryAction={
100+
<Button
101+
disabled={saving}
102+
ref={secondaryActionRef}
103+
onClick={
104+
restartFailures > 0 ? closeAndRestoreFocus : requestClose
105+
}
106+
size="sm"
107+
type="button"
108+
variant="outline"
109+
>
110+
{restartFailures > 0 ? "Done" : "Cancel"}
111+
</Button>
112+
}
113+
/>
114+
</DialogContent>
115+
</Dialog>
116+
117+
<AlertDialog open={confirmDiscard} onOpenChange={setConfirmDiscard}>
118+
<AlertDialogContent
119+
data-testid="discard-ai-defaults-dialog"
120+
onCloseAutoFocus={(event) => {
121+
if (!restoreDefaultsFocusRef.current) return;
122+
event.preventDefault();
123+
restoreDefaultsFocusRef.current = false;
124+
requestAnimationFrame(() => secondaryActionRef.current?.focus());
125+
}}
126+
>
127+
<AlertDialogHeader>
128+
<AlertDialogTitle>Discard changes to AI defaults?</AlertDialogTitle>
129+
<AlertDialogDescription>
130+
Unsaved changes made to AI defaults will be lost.
131+
</AlertDialogDescription>
132+
</AlertDialogHeader>
133+
<AlertDialogFooter>
134+
<AlertDialogCancel
135+
onClick={() => {
136+
restoreDefaultsFocusRef.current = true;
137+
}}
138+
>
139+
Keep editing
140+
</AlertDialogCancel>
141+
<AlertDialogAction asChild>
142+
<Button
143+
onClick={() => {
144+
setConfirmDiscard(false);
145+
closeAndRestoreFocus();
146+
}}
147+
variant="destructive"
148+
>
149+
Discard changes
150+
</Button>
151+
</AlertDialogAction>
152+
</AlertDialogFooter>
153+
</AlertDialogContent>
154+
</AlertDialog>
155+
</>
156+
);
157+
}

0 commit comments

Comments
 (0)