This commit is contained in:
seb
2026-10-10 02:08:10 +02:00
parent d4e2b05cb0
commit 7f8661be3e
43 changed files with 3312 additions and 2339 deletions

View File

@@ -4,6 +4,8 @@ import { RETIRED_MODELS, resolveDefaultModel } from '../../tools/llm-key.js';
import { emit } from '../sse.js';
import { getOrCreateManager, removeManager } from '../../services/conversationManager.js';
// #region Helpers
function requireSelectedCompany(req) {
const companyId = req.user?.selectedCompanyId;
if (companyId == null) {
@@ -32,6 +34,8 @@ function modelConversationErrorStatus(error) {
return 500;
}
// #endregion
/**
* Registers model conversation routes. Conversations are private to the
* authenticated user within their selected company.
@@ -79,6 +83,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /modelconversation
app.get(`${basePath}/modelconversation`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -95,6 +101,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /modelconversation:
@@ -140,6 +148,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region POST /modelconversation
app.post(`${basePath}/modelconversation`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -168,6 +178,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /modelconversation/{id}:
@@ -219,6 +231,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /modelconversation/:id
app.get(`${basePath}/modelconversation/:id`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -240,6 +254,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /modelconversation/{id}:
@@ -285,6 +301,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region DELETE /modelconversation/:id
app.delete(`${basePath}/modelconversation/:id`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -308,6 +326,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /modelconversation/{id}/stream:
@@ -384,6 +404,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /modelconversation/:id/stream
app.get(`${basePath}/modelconversation/:id/stream`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -410,6 +432,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /modelconversation/{id}/message:
@@ -463,6 +487,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /modelconversation/:id/message
app.get(`${basePath}/modelconversation/:id/message`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -484,6 +510,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /modelconversation/{id}/message:
@@ -550,6 +578,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region POST /modelconversation/:id/message
app.post(`${basePath}/modelconversation/:id/message`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -596,4 +626,6 @@ export function register(app, basePath = '') {
res.status(status).json({ error: error.message });
}
});
// #endregion
}