mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-07-09 17:29:12 +00:00
Add `packages/server-v2`, a minimal Fastify server bootstrapped through the
`agent-core-v2` DI engine (`bootstrap()` -> Core `Scope`), speaking the same
`/api/v1` interface as the v1 server. Route handlers resolve Core services
via `core.accessor.get(IXxx)`.
- Serve healthz, meta, auth, oauth (login poll/start/cancel/logout) and
shutdown with the standard `{code, msg, data, request_id}` envelope.
- Re-point root `pnpm dev:server` to server-v2 and add a `src/main.ts`
foreground entry.
- Add `build/hash-imports-loader.mjs` so tsx resolves `agent-core-v2`'s `#/`
array-fallback subpath imports.
- `agent-core-v2` Phase 0 fixes so it compiles and boots: add the `event`
domain (`IEventService`), fix `gateway` `event.subscribe` -> `event.on`, fix
the `wireRecord` fallback `BlobStoreService` construction, export the
`provider` barrel, and fix a `tooldedup` test import casing.
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'],
|
|
},
|
|
});
|