Skip to content

Commit 5b02733

Browse files
committed
work
1 parent ad97d34 commit 5b02733

15 files changed

Lines changed: 100 additions & 50 deletions

File tree

apps/code/src/main/services/agent/schemas.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const sessionConfigSelectGroupSchema = z
8282
})
8383
.passthrough();
8484

85-
export const sessionConfigOptionSchema = z
85+
const sessionConfigSelectSchema = z
8686
.object({
8787
id: z.string(),
8888
name: z.string(),
@@ -97,6 +97,23 @@ export const sessionConfigOptionSchema = z
9797
})
9898
.passthrough();
9999

100+
const sessionConfigBooleanSchema = z
101+
.object({
102+
id: z.string(),
103+
name: z.string(),
104+
type: z.literal("boolean"),
105+
currentValue: z.boolean(),
106+
category: z.string().nullish(),
107+
description: z.string().nullish(),
108+
_meta: z.record(z.string(), z.unknown()).nullish(),
109+
})
110+
.passthrough();
111+
112+
export const sessionConfigOptionSchema = z.union([
113+
sessionConfigSelectSchema,
114+
sessionConfigBooleanSchema,
115+
]);
116+
100117
export type SessionConfigOption = z.infer<typeof sessionConfigOptionSchema>;
101118

102119
export const sessionResponseSchema = z.object({

apps/code/src/main/services/agent/service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,10 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
10221022
const updatedModeOption = session.configOptions?.find(
10231023
(opt) => opt.category === "mode",
10241024
);
1025-
if (updatedModeOption) {
1025+
if (
1026+
updatedModeOption &&
1027+
typeof updatedModeOption.currentValue === "string"
1028+
) {
10261029
session.config.permissionMode = updatedModeOption.currentValue;
10271030
}
10281031

apps/code/src/renderer/features/message-editor/components/AttachmentMenu.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ export function AttachmentMenu({
147147
</div>
148148
) : (
149149
<div className="issue-picker">
150-
<IssuePicker repoPath={repoPath!} onSelect={handleIssueSelect} />
150+
<IssuePicker
151+
repoPath={repoPath ?? ""}
152+
onSelect={handleIssueSelect}
153+
/>
151154
</div>
152155
)}
153156
</Popover.Content>

apps/code/src/renderer/features/message-editor/components/ModeIndicatorInput.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {
22
SessionConfigOption,
33
SessionConfigSelectGroup,
44
SessionConfigSelectOption,
5+
SessionConfigSelectOptions,
56
} from "@agentclientprotocol/sdk";
67
import {
78
Circle,
@@ -60,7 +61,7 @@ interface ModeIndicatorInputProps {
6061
}
6162

6263
function flattenOptions(
63-
options: SessionConfigOption["options"],
64+
options: SessionConfigSelectOptions,
6465
): SessionConfigSelectOption[] {
6566
if (options.length === 0) return [];
6667
if ("group" in options[0]) {
@@ -75,7 +76,7 @@ export function ModeIndicatorInput({
7576
modeOption,
7677
onCycleMode,
7778
}: ModeIndicatorInputProps) {
78-
if (!modeOption) return null;
79+
if (!modeOption || modeOption.type !== "select") return null;
7980

8081
const id = modeOption.currentValue;
8182

apps/code/src/renderer/features/onboarding/components/TutorialStep.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ export function TutorialStep({ onComplete, onBack }: TutorialStepProps) {
109109
const currentExecutionMode =
110110
getCurrentModeFromConfigOptions(modeOption ? [modeOption] : undefined) ??
111111
"plan";
112-
const currentReasoningLevel = thoughtOption?.currentValue;
112+
const currentReasoningLevel =
113+
thoughtOption?.type === "select" ? thoughtOption.currentValue : undefined;
113114

114115
// Task creation — use whatever model the user picked
115116
const { isCreatingTask, canSubmit, handleSubmit } = useTaskCreation({

apps/code/src/renderer/features/sessions/components/ModelSelector.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,33 @@ export function ModelSelector({
2424
const session = useSessionForTask(taskId);
2525
const modelOption = useModelConfigOptionForTask(taskId);
2626

27-
const options = modelOption ? flattenSelectOptions(modelOption.options) : [];
27+
const selectOption = modelOption?.type === "select" ? modelOption : undefined;
28+
const options = selectOption
29+
? flattenSelectOptions(selectOption.options)
30+
: [];
2831
const groupedOptions = useMemo(() => {
29-
if (!modelOption || modelOption.options.length === 0) return [];
30-
if ("group" in modelOption.options[0]) {
31-
return modelOption.options as SessionConfigSelectGroup[];
32+
if (!selectOption || selectOption.options.length === 0) return [];
33+
if ("group" in selectOption.options[0]) {
34+
return selectOption.options as SessionConfigSelectGroup[];
3235
}
3336
return [];
34-
}, [modelOption]);
37+
}, [selectOption]);
3538

36-
if (!modelOption || options.length === 0) return null;
39+
if (!selectOption || options.length === 0) return null;
3740

3841
const handleChange = (value: string) => {
3942
onModelChange?.(value);
4043

4144
if (taskId && session?.status === "connected") {
42-
getSessionService().setSessionConfigOption(taskId, modelOption.id, value);
45+
getSessionService().setSessionConfigOption(
46+
taskId,
47+
selectOption.id,
48+
value,
49+
);
4350
}
4451
};
4552

46-
const currentValue = modelOption.currentValue;
53+
const currentValue = selectOption.currentValue;
4754
const currentLabel =
4855
options.find((opt) => opt.value === currentValue)?.name ?? currentValue;
4956

apps/code/src/renderer/features/sessions/components/ReasoningLevelSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function ReasoningLevelSelector({
2020
const thoughtOption = useThoughtLevelConfigOptionForTask(taskId);
2121
const adapter = useAdapterForTask(taskId);
2222

23-
if (!thoughtOption) {
23+
if (!thoughtOption || thoughtOption.type !== "select") {
2424
return null;
2525
}
2626

apps/code/src/renderer/features/sessions/components/UnifiedModelSelector.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,19 @@ export function UnifiedModelSelector({
5050
const session = useSessionForTask(taskId);
5151
const modelOption = useModelConfigOptionForTask(taskId);
5252

53-
const options = modelOption ? flattenSelectOptions(modelOption.options) : [];
53+
const selectOption = modelOption?.type === "select" ? modelOption : undefined;
54+
const options = selectOption
55+
? flattenSelectOptions(selectOption.options)
56+
: [];
5457
const groupedOptions = useMemo(() => {
55-
if (!modelOption || modelOption.options.length === 0) return [];
56-
if ("group" in modelOption.options[0]) {
57-
return modelOption.options as SessionConfigSelectGroup[];
58+
if (!selectOption || selectOption.options.length === 0) return [];
59+
if ("group" in selectOption.options[0]) {
60+
return selectOption.options as SessionConfigSelectGroup[];
5861
}
5962
return [];
60-
}, [modelOption]);
63+
}, [selectOption]);
6164

62-
const currentValue = modelOption?.currentValue;
65+
const currentValue = selectOption?.currentValue;
6366
const currentLabel =
6467
options.find((opt) => opt.value === currentValue)?.name ?? currentValue;
6568

apps/code/src/renderer/features/sessions/service/service.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,9 @@ export class SessionService {
355355
this.subscribeToChannel(taskRunId);
356356

357357
try {
358-
const persistedMode = getConfigOptionByCategory(
359-
persistedConfigOptions,
360-
"mode",
361-
)?.currentValue;
358+
const modeOpt = getConfigOptionByCategory(persistedConfigOptions, "mode");
359+
const persistedMode =
360+
modeOpt?.type === "select" ? modeOpt.currentValue : undefined;
362361

363362
trpcClient.workspace.verify
364363
.query({ taskId })
@@ -429,7 +428,7 @@ export class SessionService {
429428
.mutate({
430429
sessionId: taskRunId,
431430
configId: opt.id,
432-
value: opt.currentValue,
431+
value: String(opt.currentValue),
433432
})
434433
.catch((error) => {
435434
log.warn(
@@ -1636,7 +1635,9 @@ export class SessionService {
16361635

16371636
// Optimistic update
16381637
const updatedOptions = configOptions.map((opt) =>
1639-
opt.id === configId ? { ...opt, currentValue: value } : opt,
1638+
opt.id === configId
1639+
? ({ ...opt, currentValue: value } as SessionConfigOption)
1640+
: opt,
16401641
);
16411642
sessionStoreSetters.updateSession(session.taskRunId, {
16421643
configOptions: updatedOptions,
@@ -1652,15 +1653,17 @@ export class SessionService {
16521653
} catch (error) {
16531654
// Rollback on error
16541655
const rolledBackOptions = configOptions.map((opt) =>
1655-
opt.id === configId ? { ...opt, currentValue: previousValue } : opt,
1656+
opt.id === configId
1657+
? ({ ...opt, currentValue: previousValue } as SessionConfigOption)
1658+
: opt,
16561659
);
16571660
sessionStoreSetters.updateSession(session.taskRunId, {
16581661
configOptions: rolledBackOptions,
16591662
});
16601663
updatePersistedConfigOptionValue(
16611664
session.taskRunId,
16621665
configId,
1663-
previousValue,
1666+
String(previousValue),
16641667
);
16651668
log.error("Failed to set session config option", {
16661669
taskId,
@@ -1697,7 +1700,7 @@ export class SessionService {
16971700
track(ANALYTICS_EVENTS.SESSION_CONFIG_CHANGED, {
16981701
task_id: taskId,
16991702
category,
1700-
from_value: configOption.currentValue,
1703+
from_value: String(configOption.currentValue),
17011704
to_value: value,
17021705
});
17031706
}

apps/code/src/renderer/features/sessions/stores/sessionConfigStore.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ export const useSessionConfigStore = create<SessionConfigStore>()(
4949
if (!existing) return state;
5050

5151
const updated = existing.map((opt) =>
52-
opt.id === configId ? { ...opt, currentValue: value } : opt,
52+
opt.id === configId
53+
? ({ ...opt, currentValue: value } as SessionConfigOption)
54+
: opt,
5355
);
5456

5557
return {

0 commit comments

Comments
 (0)