feat(chat): expose model options config
This commit is contained in:
+17
-3
@@ -1,6 +1,13 @@
|
||||
import { Router } from "express";
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
agentModelOptions,
|
||||
isSupportedModel,
|
||||
resolveDefaultModel,
|
||||
type SupportedModel,
|
||||
} from "../chat/models.js";
|
||||
import { config } from "../config.js";
|
||||
import { type LearningOrchestrator } from "../learning/orchestrator.js";
|
||||
import { type SessionTranscriptStore } from "../sessions/transcriptStore.js";
|
||||
import { logger } from "../logger.js";
|
||||
@@ -28,8 +35,6 @@ import {
|
||||
type PermissionRequestPayload,
|
||||
type QuestionRequestPayload,
|
||||
streamPromptResponse,
|
||||
supportedModels,
|
||||
type SupportedModel,
|
||||
type TodoUpdatePayload,
|
||||
} from "./chatStream.js";
|
||||
import {
|
||||
@@ -54,7 +59,9 @@ import {
|
||||
const payloadSchema = z.object({
|
||||
message: z.string().min(1).max(10000),
|
||||
session_id: z.string().max(128).optional(),
|
||||
model: z.enum(supportedModels).optional(),
|
||||
model: z.string().refine(isSupportedModel, {
|
||||
message: "unsupported model",
|
||||
}).optional(),
|
||||
approval_mode: z.enum(["request", "always"]).optional().default("request"),
|
||||
});
|
||||
|
||||
@@ -115,6 +122,13 @@ export const buildChatRouter = (
|
||||
) => {
|
||||
const chatRouter = Router();
|
||||
|
||||
chatRouter.get("/models", (_req, res) => {
|
||||
res.json({
|
||||
default_model: resolveDefaultModel(config.OPENCODE_MODEL),
|
||||
models: agentModelOptions,
|
||||
});
|
||||
});
|
||||
|
||||
chatRouter.post("/session", async (req, res) => {
|
||||
const parsed = createSessionPayloadSchema.safeParse(req.body ?? {});
|
||||
if (!parsed.success) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Event as OpencodeEvent, Part } from "@opencode-ai/sdk/v2";
|
||||
|
||||
import { writeLlmRequestAuditLog } from "../audit/llmRequestAudit.js";
|
||||
import { type SupportedModel } from "../chat/models.js";
|
||||
import { logger } from "../logger.js";
|
||||
import {
|
||||
type PermissionReply,
|
||||
@@ -54,12 +55,6 @@ export {
|
||||
type TodoUpdatePayload,
|
||||
} from "./chatStreamEvents.js";
|
||||
|
||||
export const supportedModels = [
|
||||
"deepseek/deepseek-v4-flash",
|
||||
"deepseek/deepseek-v4-pro",
|
||||
] as const;
|
||||
|
||||
export type SupportedModel = (typeof supportedModels)[number];
|
||||
export type ApprovalMode = "request" | "always";
|
||||
|
||||
type StreamPromptOptions = {
|
||||
|
||||
Reference in New Issue
Block a user