feat: add registry-driven Kimi provider

This commit is contained in:
tommy0103
2026-07-20 22:43:23 +08:00
parent 21c3a1b9fc
commit 3ee44de4e5
39 changed files with 2240 additions and 732 deletions
+48
View File
@@ -0,0 +1,48 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import { readFileSync } from 'node:fs';
import { createQueryApi } from '../packages/core/src/query.ts';
import { createProviderRegistry } from '../packages/core/src/providers/registry.ts';
const require = createRequire(import.meta.url);
const { DatabaseSync } = require('node:sqlite');
const SCHEMA = readFileSync(new URL('../packages/core/src/schema.sql', import.meta.url), 'utf8');
test('raw query delegates source semantics to the registered provider', () => {
const calls = [];
const registry = createProviderRegistry([{
name: 'alpha',
descriptor: { id: 'alpha', name: 'Alpha', vendor: 'Test', defaultRoot: '/alpha', color: '#123456' },
watchRoots: () => [],
discover: () => [],
*parse() { yield* []; return null; },
raw(input) {
calls.push(input);
return { text: '0123456789', totalLength: 10 };
},
}]);
const db = new DatabaseSync(':memory:');
db.exec(SCHEMA);
db.prepare('INSERT INTO sessions (id,jsonl_path,source) VALUES (?,?,?)')
.run('alpha:session', '/alpha/session.data', 'alpha');
db.prepare('INSERT INTO messages (uuid,session_id,agent_id,source) VALUES (?,?,?,?)')
.run('alpha:message', 'alpha:session', 'alpha:agent', 'alpha');
db.prepare('INSERT INTO subagents (agent_id,session_id,description) VALUES (?,?,?)')
.run('alpha:agent', 'alpha:session', 'agent metadata');
const result = createQueryApi(db, { providerRegistry: registry }).raw('alpha:message', {
offset: 2,
limit: 4,
});
assert.deepEqual(result, {
text: '2345', totalLength: 10, offset: 2, limit: 4, hasMore: true,
});
assert.equal(calls.length, 1);
assert.equal(calls[0].source, 'alpha');
assert.equal(calls[0].session.id, 'alpha:session');
assert.equal(calls[0].subagent.description, 'agent metadata');
db.close();
});