mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix: leave agent temperature and top_p unset unless the user sets them (OM-179)
The agent dialog no longer writes temperature 0.7 and top_p 1 on every save. The fields start empty with a Default placeholder when the agent stores no value; an empty field is omitted, or removed with a merge-patch null when the agent stored it, so the provider default applies.
This commit is contained in:
1 parent
670c66f85b
commit
58a9fcdc8e
2 files changed
+63
-14
No files matched your search
@@ -359,6 +359,31 @@ describe('AgentDialog', () => {
|
||||
const agent = onSubmit.mock.calls[0][1]
|
||||
expect(agent.system).toBe('Review code carefully')
|
||||
expect(agent).not.toHaveProperty('permissions')
|
||||
expect(agent).not.toHaveProperty('request')
|
||||
})
|
||||
|
||||
it('leaves sampling values unset by default and removes a cleared stored value', async () => {
|
||||
const onSubmit = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
render(
|
||||
<AgentDialog
|
||||
open
|
||||
onOpenChange={vi.fn()}
|
||||
onSubmit={onSubmit}
|
||||
editingAgent={{
|
||||
name: 'reviewer',
|
||||
agent: { system: 'Review code', request: { body: { temperature: 0.2, reasoning_effort: 'high' } } },
|
||||
}}
|
||||
/>,
|
||||
)
|
||||
|
||||
expect(screen.getByLabelText('Top P')).toHaveValue(null)
|
||||
|
||||
await user.clear(screen.getByLabelText('Temperature'))
|
||||
await user.click(screen.getByRole('button', { name: 'Update' }))
|
||||
|
||||
const agent = onSubmit.mock.calls[0][1]
|
||||
expect(agent.request).toEqual({ body: { temperature: null, reasoning_effort: 'high' } })
|
||||
})
|
||||
|
||||
it('shows the last matching wildcard effect and applies the form effect to every occurrence', async () => {
|
||||
|
||||
@@ -67,18 +67,45 @@ const withManagedPermissionEffects = (
|
||||
return [...fallbacks, ...updated]
|
||||
}
|
||||
|
||||
const optionalNumber = (value: string): number | undefined => {
|
||||
const parsed = parseFloat(value)
|
||||
return Number.isNaN(parsed) ? undefined : parsed
|
||||
}
|
||||
|
||||
const requestBodyNumber = (agent: OpenCodeAgentConfig | undefined, key: string): number | undefined => {
|
||||
const value = agent?.request?.body?.[key]
|
||||
return typeof value === 'number' ? value : undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes each sampling value the form sets into `request.body`. A cleared value
|
||||
* is removed with a merge-patch `null` when the agent stored it and omitted
|
||||
* otherwise, so the provider default applies.
|
||||
*/
|
||||
const withSamplingValues = (
|
||||
previous: OpenCodeAgentConfig | undefined,
|
||||
values: Record<'temperature' | 'top_p', number | undefined>,
|
||||
): Pick<OpenCodeAgentPatch, 'request'> => {
|
||||
const previousBody = previous?.request?.body ?? {}
|
||||
const body: NonNullable<NonNullable<OpenCodeAgentConfig['request']>['body']> = { ...previousBody }
|
||||
for (const [key, value] of Object.entries(values)) {
|
||||
if (value !== undefined) {
|
||||
body[key] = value
|
||||
} else if (key in previousBody) {
|
||||
body[key] = null
|
||||
}
|
||||
}
|
||||
if (!previous?.request && Object.keys(body).length === 0) return {}
|
||||
return { request: { ...previous?.request, body } }
|
||||
}
|
||||
|
||||
const agentFormSchema = z.object({
|
||||
name: z.string().min(1, 'Agent name is required').regex(/^[a-z0-9-]+$/, 'Must be lowercase letters, numbers, and hyphens only'),
|
||||
description: z.string().optional(),
|
||||
prompt: z.string().min(1, 'Prompt is required'),
|
||||
mode: z.enum(['subagent', 'primary', 'all']),
|
||||
temperature: z.number().min(0).max(2),
|
||||
topP: z.number().min(0).max(1),
|
||||
temperature: z.number().min(0).max(2).optional(),
|
||||
topP: z.number().min(0).max(1).optional(),
|
||||
model: z.string().optional(),
|
||||
editPermission: z.enum(['inherit', 'ask', 'allow', 'deny']),
|
||||
shellPermission: z.enum(['inherit', 'ask', 'allow', 'deny']),
|
||||
@@ -109,8 +136,8 @@ export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: Agen
|
||||
description: agent?.agent.description || '',
|
||||
prompt: agent?.agent.system || '',
|
||||
mode: agent?.agent.mode || 'subagent',
|
||||
temperature: requestBodyNumber(agent?.agent, 'temperature') ?? 0.7,
|
||||
topP: requestBodyNumber(agent?.agent, 'top_p') ?? 1,
|
||||
temperature: requestBodyNumber(agent?.agent, 'temperature'),
|
||||
topP: requestBodyNumber(agent?.agent, 'top_p'),
|
||||
model: modelRef ? formatOpenCodeModelRef(modelRef) : '',
|
||||
editPermission: permissionEffect(agent?.agent.permissions, 'edit'),
|
||||
shellPermission: permissionEffect(agent?.agent.permissions, 'shell'),
|
||||
@@ -141,14 +168,7 @@ export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: Agen
|
||||
model: values.model?.trim() || null,
|
||||
disabled: values.disable,
|
||||
...(permissions.length > 0 || previous?.permissions ? { permissions } : {}),
|
||||
request: {
|
||||
...previous?.request,
|
||||
body: {
|
||||
...previous?.request?.body,
|
||||
temperature: values.temperature,
|
||||
top_p: values.topP,
|
||||
},
|
||||
},
|
||||
...withSamplingValues(previous, { temperature: values.temperature, top_p: values.topP }),
|
||||
}
|
||||
|
||||
onSubmit(values.name, agent)
|
||||
@@ -268,7 +288,9 @@ export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: Agen
|
||||
min="0"
|
||||
max="2"
|
||||
step="0.1"
|
||||
onChange={(e) => field.onChange(parseFloat(e.target.value))}
|
||||
placeholder="Default"
|
||||
value={field.value ?? ''}
|
||||
onChange={(e) => field.onChange(optionalNumber(e.target.value))}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
@@ -289,7 +311,9 @@ export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: Agen
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.1"
|
||||
onChange={(e) => field.onChange(parseFloat(e.target.value))}
|
||||
placeholder="Default"
|
||||
value={field.value ?? ''}
|
||||
onChange={(e) => field.onChange(optionalNumber(e.target.value))}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
|
||||
Reference in new issue
Block a user