Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion services/cloud-agent-next/src/session-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ import {
restoreWorkspace as mockRestoreWorkspace,
cleanupWorkspace as mockCleanupWorkspace,
} from './workspace.js';
import { InvalidSessionMetadataError, SessionService } from './session-service.js';
import {
buildAgentEntryFromRuntimeAgent,
InvalidSessionMetadataError,
SessionService,
} from './session-service.js';
import type { SandboxInstance, SessionId, SessionContext, ExecutionSession } from './types.js';
import type { PersistenceEnv, CloudAgentSessionState } from './persistence/types.js';

Expand Down Expand Up @@ -3922,3 +3926,58 @@ describe('SessionService', () => {
});
});
});

describe('buildAgentEntryFromRuntimeAgent', () => {
it('normalizes model with kilo/ prefix when not already prefixed', () => {
const result = buildAgentEntryFromRuntimeAgent({
slug: 'test-agent',
name: 'Test Agent',
config: { model: 'anthropic/claude-opus-4.7', mode: 'subagent' },
});
expect(result.model).toBe('kilo/anthropic/claude-opus-4.7');
});

it('does not double-prefix models that already have kilo/', () => {
const result = buildAgentEntryFromRuntimeAgent({
slug: 'test-agent',
name: 'Test Agent',
config: { model: 'kilo/code', mode: 'subagent' },
});
expect(result.model).toBe('kilo/code');
});

it('handles null model', () => {
const result = buildAgentEntryFromRuntimeAgent({
slug: 'test-agent',
name: 'Test Agent',
config: { model: null, mode: 'subagent' },
});
expect(result.model).toBeUndefined();
});

it('handles undefined model', () => {
const result = buildAgentEntryFromRuntimeAgent({
slug: 'test-agent',
name: 'Test Agent',
config: { mode: 'subagent' },
});
expect(result.model).toBeUndefined();
});

it('passes through other config fields unchanged', () => {
const result = buildAgentEntryFromRuntimeAgent({
slug: 'test-agent',
name: 'Test Agent',
config: {
model: 'anthropic/claude-sonnet-4',
mode: 'subagent',
temperature: 0.7,
prompt: 'You are a test agent',
},
});
expect(result.model).toBe('kilo/anthropic/claude-sonnet-4');
expect(result.temperature).toBe(0.7);
expect(result.prompt).toBe('You are a test agent');
expect(result.mode).toBe('subagent');
});
});
3 changes: 2 additions & 1 deletion services/cloud-agent-next/src/session-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
} from './types.js';
import type { ExecutionParams as _ExecutionParams } from './schema.js';
import { generateSandboxId } from './sandbox-id.js';
import { normalizeKilocodeModel } from './persistence/model-utils.js';
import {
checkDiskAndCleanBeforeSetup,
cloneGitHubRepo,
Expand Down Expand Up @@ -512,7 +513,7 @@ export function buildAgentEntryFromRuntimeAgent(agent: RuntimeAgent): Record<str
};
if (config.prompt !== undefined) entry.prompt = config.prompt;
if (config.description !== undefined) entry.description = config.description;
if (config.model !== undefined) entry.model = config.model;
if (config.model !== undefined) entry.model = normalizeKilocodeModel(config.model);
if (config.variant !== undefined) entry.variant = config.variant;
if (config.temperature !== undefined) entry.temperature = config.temperature;
if (config.top_p !== undefined) entry.top_p = config.top_p;
Expand Down