Skip to content
Merged
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
60 changes: 60 additions & 0 deletions apps/web/src/lib/ai-gateway/providers/openrouter/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,66 @@ describe('reasoning variants', () => {
});
});

describe('virtual router tool support', () => {
afterEach(() => {
global.fetch = originalFetch;
});

function buildVirtualModel(overrides: Partial<OpenRouterModel>): OpenRouterModel {
return buildModel({
architecture: {
input_modalities: ['text'],
output_modalities: ['text'],
tokenizer: 'Router',
},
pricing: { prompt: '-1', completion: '-1' },
supported_parameters: [],
...overrides,
});
}

async function supportedParametersById(models: OpenRouterModel[]) {
global.fetch = jest.fn(() =>
Promise.resolve(createMockResponse({ jsonData: { data: models } }))
) as unknown as typeof fetch;
const catalog = await getEnhancedOpenRouterModels();
return new Map(catalog.data.map(model => [model.id, model.supported_parameters]));
}

it('adds tools to the allowlisted virtual routers', async () => {
const params = await supportedParametersById([
buildVirtualModel({ id: 'typesafe/jev-router', name: 'TypeSafe: Jev Router' }),
buildVirtualModel({
id: 'openrouter/pareto-code',
name: 'Pareto Code Router',
supported_parameters: undefined,
}),
]);

expect(params.get('typesafe/jev-router')).toEqual(['tools']);
expect(params.get('openrouter/pareto-code')).toEqual(['tools']);
});

it('does not duplicate tools when upstream already lists it', async () => {
const upstream = ['max_tokens', 'tools'];
const params = await supportedParametersById([
buildVirtualModel({ id: 'typesafe/jev-router', supported_parameters: upstream }),
]);

expect(params.get('typesafe/jev-router')).toEqual(upstream);
});

it('does not add tools to other virtual models', async () => {
const params = await supportedParametersById([
buildVirtualModel({ id: 'openrouter/fusion', name: 'OpenRouter: Fusion' }),
buildVirtualModel({ id: 'vendor/other-router', name: 'Other Router' }),
]);

expect(params.get('openrouter/fusion')).toEqual([]);
expect(params.get('vendor/other-router')).toEqual([]);
});
});

describe('mayTrainOnYourPrompts', () => {
afterEach(() => {
global.fetch = originalFetch;
Expand Down
14 changes: 13 additions & 1 deletion apps/web/src/lib/ai-gateway/providers/openrouter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ export function formatName(model: OpenRouterModel, preferredIndex: number) {
return name;
}

// OpenRouter lists these virtual routers with empty supported_parameters, which makes Kilo
// clients drop them, even though they route to regular chat models that accept tools.
const TOOL_CAPABLE_VIRTUAL_ROUTER_IDS = new Set(['typesafe/jev-router', 'openrouter/pareto-code']);

function addVirtualRouterToolSupport(model: OpenRouterModel): OpenRouterModel {
const supportedParameters = model.supported_parameters ?? [];
if (supportedParameters.includes('tools') || !TOOL_CAPABLE_VIRTUAL_ROUTER_IDS.has(model.id)) {
return model;
}
return { ...model, supported_parameters: [...supportedParameters, 'tools'] };
}

export function shouldSuppressOpenRouterModel(model: KiloExclusiveModel): boolean {
return model.status !== 'disabled' || model.pricing === null;
}
Expand Down Expand Up @@ -146,7 +158,7 @@ async function enhancedModelList(models: OpenRouterModel[]) {
const pricing = getModelDisplayPricing(rawPricing);
const terminalBench = terminalBenchFor(summaries, model.id);
return {
...model,
...addVirtualRouterToolSupport(model),
...(pricing && { pricing }),
...(terminalBench && { terminalBench }),
};
Expand Down