Move project and host queries into native MCP with host-owned OAuth/context, while retaining memory, skills, actions and publication plugins. Add nearby-model queries and explicit chat/task/learning model defaults. Adopt Responses HTTP/SSE and native steer/queue inbox delivery, preserving scoped session ownership, pending input edits and investigation communication. Disable local-provider discovery: Server /health allowed native vLLM to probe /v1/models on port 8000. A native before/after regression prevents recurrence. Validation: 170 focused Bun tests; service/plugin typechecks; native discovery, provider-discovery and input-inbox smoke checks; no paid model inference.
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import type { Router } from "express";
|
|
import { config } from "../config.js";
|
|
import { isSupportedModel } from "../chat/models.js";
|
|
import { createPromptSuggestionService, promptSuggestionRequestSchema } from "../chat/prompt-suggestions.js";
|
|
import { getLocalAgentContext } from "../context/localContext.js";
|
|
import type { OpencodeRuntimeAdapter } from "../runtime/opencode.js";
|
|
import { logger } from "../logger.js";
|
|
|
|
export function registerChatSuggestionRoutes(router: Router, runtime: OpencodeRuntimeAdapter) {
|
|
const generate = createPromptSuggestionService(runtime);
|
|
router.post("/suggestions", async (req, res) => {
|
|
const parsed = promptSuggestionRequestSchema.safeParse(req.body);
|
|
if (!parsed.success) {
|
|
res.status(400).json({ message: "invalid suggestion request" });
|
|
return;
|
|
}
|
|
const model = parsed.data.model ?? config.OPENCODE_MODEL;
|
|
if (!isSupportedModel(model)) {
|
|
res.status(400).json({ message: "unsupported model" });
|
|
return;
|
|
}
|
|
res.setHeader("Cache-Control", "no-store");
|
|
try {
|
|
const result = await generate(getLocalAgentContext(req), parsed.data, model);
|
|
if (!res.destroyed) res.json(result);
|
|
} catch {
|
|
logger.warn("prompt suggestion generation unavailable");
|
|
if (!res.destroyed) res.status(503).json({ message: "prompt suggestions unavailable" });
|
|
}
|
|
});
|
|
}
|