forked from bai/curriculum-project-hub
fix(hub): default to OpenRouter Sonnet model
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { InMemoryModelRegistry } from "./models.js";
|
||||
|
||||
type Env = Readonly<Record<string, string | undefined>>;
|
||||
|
||||
const DEFAULT_SONNET_MODEL = "anthropic/claude-sonnet-5";
|
||||
const DEFAULT_SONNET_LABEL = "Claude Sonnet 5";
|
||||
|
||||
function readEnv(env: Env, name: string): string | undefined {
|
||||
const value = env[name]?.trim();
|
||||
return value === undefined || value === "" ? undefined : value;
|
||||
}
|
||||
|
||||
export function defaultSonnetModel(env: Env = process.env): string {
|
||||
return readEnv(env, "ANTHROPIC_DEFAULT_SONNET_MODEL") ?? DEFAULT_SONNET_MODEL;
|
||||
}
|
||||
|
||||
export function createDefaultModelRegistry(env: Env = process.env): InMemoryModelRegistry {
|
||||
const sonnetModel = defaultSonnetModel(env);
|
||||
const sonnetLabel =
|
||||
readEnv(env, "ANTHROPIC_DEFAULT_SONNET_MODEL_NAME") ??
|
||||
(sonnetModel === DEFAULT_SONNET_MODEL ? DEFAULT_SONNET_LABEL : sonnetModel);
|
||||
|
||||
return new InMemoryModelRegistry(
|
||||
[
|
||||
{ id: sonnetModel, label: sonnetLabel, toolCapable: true },
|
||||
],
|
||||
[
|
||||
{ id: "draft", label: "草稿", defaultModel: sonnetModel },
|
||||
{ id: "review", label: "审校", defaultModel: sonnetModel },
|
||||
],
|
||||
);
|
||||
}
|
||||
+5
-13
@@ -8,12 +8,12 @@
|
||||
* loop are ADR-0003-authorized (chat must match binding).
|
||||
*
|
||||
* Env (see .env.example):
|
||||
* DATABASE_URL, OPENROUTER_API_KEY, FEISHU_APP_ID/SECRET/BOT_OPEN_ID, PORT
|
||||
* DATABASE_URL, ANTHROPIC_AUTH_TOKEN, FEISHU_APP_ID/SECRET/BOT_OPEN_ID, PORT
|
||||
*/
|
||||
import "dotenv/config";
|
||||
import Fastify from "fastify";
|
||||
import { prisma } from "./db.js";
|
||||
import { InMemoryModelRegistry } from "./agent/models.js";
|
||||
import { createDefaultModelRegistry } from "./agent/defaultModels.js";
|
||||
import { createLarkClient, startFeishuListenerWithClient, type FeishuRuntime } from "./feishu/client.js";
|
||||
import { makeTriggerHandler } from "./feishu/trigger.js";
|
||||
|
||||
@@ -54,17 +54,9 @@ async function main(): Promise<void> {
|
||||
|
||||
app.get("/api/healthz", async () => ({ ok: true, ts: Date.now() }));
|
||||
|
||||
// Model registry (role-as-data, ADR-0017). Claude Code SDK uses model
|
||||
// aliases like 'sonnet', 'haiku' — the registry maps roles to these.
|
||||
const models = new InMemoryModelRegistry(
|
||||
[
|
||||
{ id: "claude-sonnet-4-20250514", label: "Claude Sonnet", toolCapable: true },
|
||||
],
|
||||
[
|
||||
{ id: "draft", label: "草稿", defaultModel: "claude-sonnet-4-20250514" },
|
||||
{ id: "review", label: "审校", defaultModel: "claude-sonnet-4-20250514" },
|
||||
],
|
||||
);
|
||||
// Model registry (role-as-data, ADR-0017). Defaults are OpenRouter model
|
||||
// slugs; ANTHROPIC_DEFAULT_SONNET_MODEL can override the role default.
|
||||
const models = createDefaultModelRegistry();
|
||||
|
||||
// --- Feishu listener ---
|
||||
const feishuConfig = { appId: feishuAppId, appSecret: feishuAppSecret, botOpenId: feishuBotOpenId };
|
||||
|
||||
Reference in New Issue
Block a user