Skip to content

Commit 4243f03

Browse files
committed
fix: drop the model roles table when the role map is cleared
1 parent 1e1559e commit 4243f03

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,9 @@ export function configToTomlData(config: PythinkerConfig): Record<string, unknow
492492

493493
setRecordSection(out, 'providers', config.providers, providerToToml);
494494
setRecordSection(out, 'models', config.models, modelToToml);
495-
if (config.modelRoles !== undefined) {
495+
if (config.modelRoles === undefined) {
496+
delete out['model_roles'];
497+
} else {
496498
out['model_roles'] = cloneUnknown(config.modelRoles);
497499
}
498500
setSection(out, 'thinking', config.thinking, thinkingToToml);

packages/agent-core/test/config/configs.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,18 @@ source = { kind = "apiJson", url = "https://registry.example/api.json", apiKey =
260260
expect(readConfigFile(configPath).modelRoles).toEqual({ small: '' });
261261
});
262262

263+
it('removes model roles when the role map is cleared', async () => {
264+
const configPath = join(makeTempDir(), 'model-roles-removed.toml');
265+
await writeFile(configPath, '[model_roles]\nsmall = "old"\n');
266+
const config = readConfigFile(configPath);
267+
268+
await writeConfigFile(configPath, { ...config, modelRoles: undefined });
269+
270+
const text = await readFile(configPath, 'utf-8');
271+
expect(text).not.toContain('[model_roles]');
272+
expect(readConfigFile(configPath).modelRoles).toBeUndefined();
273+
});
274+
263275
it('round-trips an API key environment reference without an API key', async () => {
264276
const configPath = join(makeTempDir(), 'api-key-env-var.toml');
265277
const config = parseConfigString(

0 commit comments

Comments
 (0)