Skip to content

Commit 805dd83

Browse files
committed
fix(config): apply replace mode to custom TOML serializers and read the typed request body
1 parent ebcb414 commit 805dd83

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

packages/agent-core-v2/src/app/config/toml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function applySectionToToml(
6565
}
6666

6767
if (toToml !== undefined) {
68-
const rawSub = cloneRecord(rawSnake[snakeKey]);
68+
const rawSub = mode === 'replace' ? undefined : cloneRecord(rawSnake[snakeKey]);
6969
const converted = toToml(value, rawSub);
7070
if (converted === undefined || converted === null) {
7171
delete rawSnake[snakeKey];

packages/agent-core-v2/test/app/config/config.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,18 @@ describe('ConfigService replaceSections', () => {
26592659
disposables.dispose();
26602660
});
26612661

2662+
it('replace drops omitted keys from a section with a custom TOML serializer', async () => {
2663+
const seed = ['[loop_control]', 'max_steps_per_turn = 5', 'max_attempts_per_step = 3', ''].join('\n');
2664+
const { config, disposables, storage } = await createSectionsConfig(seed);
2665+
await config.replace(LOOP_CONTROL_SECTION, { maxStepsPerTurn: 7 });
2666+
const onDisk = new TextDecoder().decode(await storage.read('', 'config.toml'));
2667+
expect(onDisk).toContain('max_steps_per_turn = 7');
2668+
expect(onDisk).not.toContain('max_attempts_per_step');
2669+
await config.reload();
2670+
expect(config.get(LOOP_CONTROL_SECTION)).toEqual({ maxStepsPerTurn: 7 });
2671+
disposables.dispose();
2672+
});
2673+
26622674
it('replace and replaceSections drop keys the new value does not carry from disk', async () => {
26632675
const seed = [
26642676
'[secondary_model]',

packages/agent-gateway/src/routes/config.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,9 @@ export function registerConfigRoutes(app: ConfigRouteHost, core: Scope): void {
7070
const config = core.accessor.get(IConfigService);
7171
const registry = core.accessor.get(IConfigRegistry);
7272
await config.ready;
73-
const body = req.body as Record<string, unknown>;
74-
const secondaryModel = body['secondary_model'] as
75-
| LegacySecondaryModelRequest
76-
| null
77-
| undefined;
78-
const ordinary = { ...body };
79-
delete ordinary['secondary_model'];
80-
const camelPatch = convertKeysSnakeToCamel(ordinary) as Record<string, unknown>;
73+
const { secondary_model: secondaryModel, ...ordinary } = req.body;
74+
const converted = convertKeysSnakeToCamel(ordinary);
75+
const camelPatch: Record<string, unknown> = isPlainObject(converted) ? converted : {};
8176
if (camelPatch['yolo'] === true) {
8277
camelPatch['defaultPermissionMode'] = 'yolo';
8378
}

0 commit comments

Comments
 (0)