mirror of
https://github.com/musistudio/claude-code-router.git
synced 2026-01-30 06:12:06 +00:00
move llms to core package
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
"dependencies": {
|
||||
"@fastify/multipart": "^9.0.0",
|
||||
"@fastify/static": "^8.2.0",
|
||||
"@musistudio/llms": "^1.0.51",
|
||||
"@musistudio/llms": "workspace:*",
|
||||
"adm-zip": "^0.5.16",
|
||||
"dotenv": "^16.4.7",
|
||||
"json5": "^2.2.3",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { existsSync, writeFileSync, unlinkSync } from "fs";
|
||||
import { existsSync } from "fs";
|
||||
import { writeFile } from "fs/promises";
|
||||
import { homedir } from "os";
|
||||
import { join } from "path";
|
||||
@@ -6,7 +6,7 @@ import { initConfig, initDir } from "./utils";
|
||||
import { createServer } from "./server";
|
||||
import { router } from "./utils/router";
|
||||
import { apiKeyAuth } from "./middleware/auth";
|
||||
import { CONFIG_FILE, HOME_DIR } from "@CCR/shared";
|
||||
import {CONFIG_FILE, HOME_DIR, listPresets} from "@CCR/shared";
|
||||
import { createStream } from 'rotating-file-stream';
|
||||
import { sessionUsageCache } from "./utils/cache";
|
||||
import {SSEParserTransform} from "./utils/SSEParser.transform";
|
||||
@@ -16,7 +16,6 @@ import JSON5 from "json5";
|
||||
import { IAgent, ITool } from "./agents/type";
|
||||
import agentsManager from "./agents";
|
||||
import { EventEmitter } from "node:events";
|
||||
import {spawn} from "child_process";
|
||||
|
||||
const event = new EventEmitter()
|
||||
|
||||
@@ -121,6 +120,8 @@ async function getServer(options: RunOptions = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
const presets = await listPresets();
|
||||
|
||||
const serverInstance = await createServer({
|
||||
jsonPath: CONFIG_FILE,
|
||||
initialConfig: {
|
||||
@@ -137,6 +138,11 @@ async function getServer(options: RunOptions = {}) {
|
||||
logger: loggerConfig,
|
||||
});
|
||||
|
||||
presets.forEach(preset => {
|
||||
console.log(preset.name, preset.config);
|
||||
serverInstance.registerNamespace(preset.name, preset.config);
|
||||
})
|
||||
|
||||
// Add async preHandler hook for authentication
|
||||
serverInstance.addHook("preHandler", async (req: any, reply: any) => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
|
||||
@@ -10,8 +10,6 @@ import {
|
||||
readManifestFromDir,
|
||||
manifestToPresetFile,
|
||||
extractPreset,
|
||||
validatePreset,
|
||||
loadPreset,
|
||||
saveManifest,
|
||||
isPresetInstalled,
|
||||
downloadPresetToTemp,
|
||||
@@ -20,16 +18,15 @@ import {
|
||||
type PresetFile,
|
||||
type ManifestFile,
|
||||
type PresetMetadata,
|
||||
MergeStrategy
|
||||
} from "@CCR/shared";
|
||||
import fastifyMultipart from "@fastify/multipart";
|
||||
import AdmZip from "adm-zip";
|
||||
|
||||
export const createServer = async (config: any): Promise<any> => {
|
||||
const server = new Server(config);
|
||||
const app = server.app;
|
||||
|
||||
// Register multipart plugin for file uploads (dynamic import)
|
||||
const fastifyMultipart = await import('@fastify/multipart');
|
||||
app.register(fastifyMultipart.default, {
|
||||
app.register(fastifyMultipart, {
|
||||
limits: {
|
||||
fileSize: 50 * 1024 * 1024, // 50MB
|
||||
},
|
||||
@@ -171,8 +168,6 @@ export const createServer = async (config: any): Promise<any> => {
|
||||
}
|
||||
});
|
||||
|
||||
// ========== Preset 相关 API ==========
|
||||
|
||||
// 获取预设列表
|
||||
app.get("/api/presets", async (req: any, reply: any) => {
|
||||
try {
|
||||
@@ -435,8 +430,13 @@ export const createServer = async (config: any): Promise<any> => {
|
||||
}
|
||||
|
||||
// 解析 GitHub 仓库 URL
|
||||
// 支持格式: https://github.com/owner/repo 或 https://github.com/owner/repo.git
|
||||
const githubRepoMatch = repo.match(/github\.com[:/]([^/]+)\/([^/.]+)/);
|
||||
// 支持格式:
|
||||
// - owner/repo (简短格式,来自市场)
|
||||
// - github.com/owner/repo
|
||||
// - https://github.com/owner/repo
|
||||
// - https://github.com/owner/repo.git
|
||||
// - git@github.com:owner/repo.git
|
||||
const githubRepoMatch = repo.match(/(?:github\.com[:/]|^)([^/]+)\/([^/\s#]+?)(?:\.git)?$/);
|
||||
if (!githubRepoMatch) {
|
||||
reply.status(400).send({ error: "Invalid GitHub repository URL" });
|
||||
return;
|
||||
@@ -484,7 +484,6 @@ export const createServer = async (config: any): Promise<any> => {
|
||||
|
||||
// 辅助函数:从 ZIP 加载预设
|
||||
async function loadPresetFromZip(zipFile: string): Promise<PresetFile> {
|
||||
const AdmZip = (await import('adm-zip')).default;
|
||||
const zip = new AdmZip(zipFile);
|
||||
|
||||
// 首先尝试在根目录查找 manifest.json
|
||||
|
||||
Reference in New Issue
Block a user