mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-07-10 01:39:25 +00:00
- rename packages/server-v2 to packages/kap-server and update every @moonshot-ai/server-v2 reference across apps, packages, flake.nix, and build scripts - remove the experimental `kimi v2` CLI prefix and its tests from the apps/kimi-code main entry - add legacy BackgroundTask protocol types and the `blocked` turn interrupt reason for cross-engine compatibility
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { existsSync } from 'node:fs';
|
|
import { dirname, join } from 'node:path';
|
|
|
|
import { defineConfig, type Plugin } from 'vitest/config';
|
|
|
|
import { rawTextPlugin } from '../../build/raw-text-plugin.mjs';
|
|
|
|
function findPackageRoot(importer: string | undefined): string | undefined {
|
|
if (!importer) return undefined;
|
|
let dir = dirname(importer.split('?')[0] ?? importer);
|
|
for (;;) {
|
|
if (existsSync(join(dir, 'package.json'))) return dir;
|
|
const parent = dirname(dir);
|
|
if (parent === dir) return undefined;
|
|
dir = parent;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Resolve `#/` subpath imports the way Node's package.json `imports` field does,
|
|
* scoped to the importer's owning package. server-v2 inlines
|
|
* `@moonshot-ai/agent-core-v2` source (and transitively kosong/kaos), whose
|
|
* internal `#/foo` imports must resolve against each package's own `src/`.
|
|
*
|
|
* Mirrors `packages/agent-core-v2/vitest.config.ts`.
|
|
*/
|
|
function hashImportsPlugin(): Plugin {
|
|
return {
|
|
name: 'resolve-hash-imports',
|
|
enforce: 'pre',
|
|
resolveId(id, importer) {
|
|
if (!id.startsWith('#/')) return null;
|
|
const pkgRoot = findPackageRoot(importer);
|
|
if (!pkgRoot) return null;
|
|
const sub = id.slice(2);
|
|
for (const candidate of [`src/${sub}.ts`, `src/${sub}/index.ts`]) {
|
|
const full = join(pkgRoot, candidate);
|
|
if (existsSync(full)) return full;
|
|
}
|
|
return null;
|
|
},
|
|
};
|
|
}
|
|
|
|
export default defineConfig({
|
|
// `rawTextPlugin` is required because server-v2 pulls in agent-core-v2's full
|
|
// barrel, which imports `*.md?raw` prompt templates.
|
|
plugins: [rawTextPlugin(), hashImportsPlugin()],
|
|
test: {
|
|
name: 'server-v2',
|
|
include: ['test/**/*.{test,e2e}.ts'],
|
|
},
|
|
});
|