kimi-desktop 0.1.6: separate reasoning effort and an optional context input budget for the primary and secondary roles.
The change (f07e7f4a..1d14a185, since the round-6 approval):
- The settings page and API save `<role>ReasoningEffort` and `<role>ContextTokens` for each role. Only efforts and context limits the catalog publishes are offered; an unknown limit allows no custom budget.
- Inference drops Kimi's top-level `thinking`, `reasoning` and `reasoning_effort`, and sends the chosen effort, or none for the provider default. Kimi's native menu aliases no longer choose the model.
- A custom budget counts a copy of the request through magpie's `/v1/messages/count_tokens`. Over the budget gives 400 `context_length_exceeded`; a failed count gives fixed 503 `context_count_unavailable`. No generation is sent in either case. Without a budget, nothing extra is sent.
- Role-scoped worker profiles (`v2:[model, role]`) tell primary from secondary even on the same model. Older roleless profiles keep their binding and use defaults.
- 1d14a185 removes blank lines only.
Run at 1d14a1859f63fd4bb512d492d1de419ad3e6c79a on mote (macOS, Bun 1.4.2, HOME/TMPDIR/XDG in the run's own folder):
- `bun test` in packages/kimi-desktop: 626 pass, 0 fail, 29 files.
- `bun scripts/check.mjs kimi-desktop`: exit 0.
- 14 hand breaks, each red in the package suite:
- drop `applyReasoningOptions`;
- strip thinking fields only when an effort is set;
- drop the budget check, or make it `>=`;
- `useFresh` false, or without its model check;
- a legacy roleless profile treated as primary;
- a profile name without its role;
- no `registerRoles`;
- no `optionsMatch` in save;
- no `refreshLiveModelOptions`;
- count with `redirect: 'follow'`, or with no reply size limit;
- a 131072 fallback for an unknown catalog context.
- CI at the head: test and on-npm pass. The PR merges onto main f379bf90+ with no conflicts.
Not blocking, left for a follow-up:
- Each inference now reads connection.json (adapter.mjs:547) with no fallback to the live connection. An unreadable file turns every request into 502, even without a budget.
- The comment above `applyReasoningOptions` ("Preserve the legacy connection untouched…") no longer matches the always-strip policy.
128 lines
6.6 KiB
JavaScript
128 lines
6.6 KiB
JavaScript
import { test, expect } from 'bun:test';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { KimiAdapter } from './adapter.mjs';
|
|
import { normalizeModels } from './catalog.mjs';
|
|
import { nativeRolePluginPeer } from './test-fixtures/control-peer.mjs';
|
|
|
|
const rows = normalizeModels({ data: ['synthetic/main', 'synthetic/secondary'].map(id => ({ id })) });
|
|
const [primary, secondary] = rows;
|
|
const write = (file, text) => {
|
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
fs.writeFileSync(file, text);
|
|
};
|
|
function fixture() {
|
|
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'kimi-bridge-contract-'));
|
|
const adapter = new KimiAdapter({ home: directory, kimiDir: path.join(directory, 'kimi'), stateDir: path.join(directory, 'state') });
|
|
adapter.state = { active: true, model: primary.id };
|
|
adapter.live = { model: primary.id };
|
|
adapter.catalog = rows;
|
|
write(adapter.connectionFile, JSON.stringify({ enabled: true, model: primary.id,
|
|
secondaryModel: secondary.id, gateway: { key: '' } }));
|
|
const runner = { lifecycleStatus: 'running', kernel: { agentKernel: 'kimi-code-v2' }, activeKernelTurns: 0, activeKernelToolCalls: 0 };
|
|
const plugins = nativeRolePluginPeer(path.dirname(adapter.convertedNativeConfigFile));
|
|
const calls = [];
|
|
adapter.rpcCall = async (_runner, method, params) => {
|
|
calls.push({ method, params });
|
|
if (plugins.handles(method)) return plugins.call(method, params);
|
|
if (method === 'kimiPlugin.reloadActiveSessions') return { sessions: [] };
|
|
if (method === 'kimiPlugin.ReloadSession') return { status: 'reloaded' };
|
|
throw Error('unexpected public RPC');
|
|
};
|
|
return { adapter, runner, plugins, calls, cleanup: () => fs.rmSync(directory, { recursive: true, force: true }) };
|
|
}
|
|
|
|
test('V2 installs declared Agent profiles without depending on converted model definitions', async () => {
|
|
const f = fixture();
|
|
try {
|
|
let writes = 0;
|
|
f.adapter.commitNativeSecondary = () => { writes++; throw Error('unexpected-native-write'); };
|
|
expect(await f.adapter.reconcileSecondary(f.runner, secondary.id, { inheritModel: primary.id })).toEqual({ applied: true });
|
|
expect((await f.adapter.readSettings()).appliedSecondaryModel).toBe(secondary.id);
|
|
expect(f.plugins.calls.map(call => call.method)).toEqual([
|
|
'kimiPlugin.installPlugin', 'kimiPlugin.getPluginInfo', 'kimiPlugin.setPluginEnabled',
|
|
]);
|
|
expect(f.calls.at(-1).method).toBe('kimiPlugin.reloadActiveSessions');
|
|
expect(writes).toBe(0);
|
|
expect(fs.existsSync(f.adapter.nativeConfigFile)).toBe(false);
|
|
expect(fs.existsSync(f.adapter.convertedNativeConfigFile)).toBe(false);
|
|
} finally { f.cleanup(); }
|
|
});
|
|
|
|
for (const family of ['kimi-code', 'future-kernel', undefined]) {
|
|
test(`an explicit secondary remains unsupported on a non-V2 kernel (${family ?? 'missing metadata'})`, async () => {
|
|
const f = fixture();
|
|
try {
|
|
if (family) f.runner.kernel.agentKernel = family; else delete f.runner.kernel;
|
|
await expect(f.adapter.reconcileSecondary(f.runner, secondary.id, { inheritModel: primary.id }))
|
|
.rejects.toThrow('secondary_model_unsupported_runtime');
|
|
expect((await f.adapter.readSettings()).appliedSecondaryModel).toBeUndefined();
|
|
expect(f.plugins.calls).toHaveLength(0);
|
|
expect(f.calls).toHaveLength(0);
|
|
expect(f.adapter.rolesReady).toBe(false);
|
|
expect(await f.adapter.reconcileSecondary(f.runner, '', { inheritModel: primary.id })).toEqual({ applied: true });
|
|
expect(f.adapter.bridgeSecondaryModel).toBe('');
|
|
expect((await f.adapter.readSettings()).appliedSecondaryModel).toBeUndefined();
|
|
} finally { f.cleanup(); }
|
|
});
|
|
}
|
|
|
|
test('native model document rewrites do not replace the confirmed public role plugin', async () => {
|
|
const f = fixture();
|
|
try {
|
|
await f.adapter.reconcileSecondary(f.runner, secondary.id, { inheritModel: primary.id });
|
|
for (const native of ['', 'not a TOML document [', 'default_model = "native"\n[models.native]\nprovider = "unrelated"\n']) {
|
|
write(f.adapter.convertedNativeConfigFile, native);
|
|
expect((await f.adapter.readSettings()).appliedSecondaryModel).toBe(secondary.id);
|
|
await f.adapter.reconcileSecondary(f.runner, secondary.id, { inheritModel: primary.id });
|
|
expect(fs.readFileSync(f.adapter.convertedNativeConfigFile, 'utf8')).toBe(native);
|
|
}
|
|
} finally { f.cleanup(); }
|
|
});
|
|
|
|
test('bridge application still rejects a model outside the gateway catalog', async () => {
|
|
const f = fixture();
|
|
try {
|
|
await expect(f.adapter.reconcileSecondary(f.runner, 'hidden/model', { inheritModel: primary.id }))
|
|
.rejects.toThrow('secondary_model_unavailable');
|
|
expect(f.adapter.bridgeSecondaryModel).toBeUndefined();
|
|
expect(f.adapter.state.secondary).toBeUndefined();
|
|
expect(f.adapter.state.secondaryPool).toBeUndefined();
|
|
} finally { f.cleanup(); }
|
|
});
|
|
|
|
test('a changed bridge selection waits for idle while the current selection remains usable', async () => {
|
|
const f = fixture();
|
|
try {
|
|
await f.adapter.reconcileSecondary(f.runner, secondary.id, { inheritModel: primary.id });
|
|
f.runner.activeKernelTurns = 1;
|
|
expect(await f.adapter.reconcileSecondary(f.runner, '', { inheritModel: primary.id })).toEqual({ waiting: true });
|
|
expect(f.adapter.bridgeSecondaryModel).toBe(secondary.id);
|
|
expect(await f.adapter.reconcileSecondary(f.runner, secondary.id, { inheritModel: primary.id })).toEqual({ applied: true });
|
|
f.runner.activeKernelTurns = 0;
|
|
await f.adapter.reconcileSecondary(f.runner, '', { inheritModel: primary.id });
|
|
expect(f.adapter.bridgeSecondaryModel).toBe('');
|
|
await f.adapter.reconcileSecondary(f.runner, '');
|
|
expect(f.adapter.bridgeSecondaryModel).toBe('');
|
|
} finally { f.cleanup(); }
|
|
});
|
|
|
|
test('the adapter persists one routing secret across reconstruction without storing a native model snapshot', async () => {
|
|
const f = fixture();
|
|
try {
|
|
await f.adapter.reconcileSecondary(f.runner, secondary.id, { inheritModel: primary.id });
|
|
const saved = JSON.parse(fs.readFileSync(f.adapter.stateFile, 'utf8'));
|
|
expect(saved.agentRoutingSecret).toMatch(/^[a-f0-9]{64}$/);
|
|
expect(saved.secondaryPool).toBeUndefined();
|
|
expect(saved.secondary).toBeUndefined();
|
|
const reconstructed = new KimiAdapter({ stateDir: f.adapter.stateDir, kimiDir: f.adapter.kimiDir });
|
|
reconstructed.state = saved;
|
|
reconstructed.catalog = rows;
|
|
reconstructed.rpcCall = f.adapter.rpcCall;
|
|
await reconstructed.reconcileSecondary(f.runner, secondary.id, { inheritModel: primary.id });
|
|
expect(reconstructed.agentRouterSecret).toBe(saved.agentRoutingSecret);
|
|
expect(JSON.parse(fs.readFileSync(f.adapter.stateFile, 'utf8'))).toEqual(saved);
|
|
} finally { f.cleanup(); }
|
|
});
|