Add the harness, envs, per-bot models and chat attachments

- Harness: providers, model catalog synced hourly, automatic free picks,
  cooldowns, tool loop with context trimming, MCP computer tools
- Bots queue runs replies and tasks through the harness; jobs wait
  (attempt refunded) while every model is resting
- Envs: Settings > Environment, scoped general/workspace/computer,
  written to computers and redacted from tool output
- Models: Settings > Models, per-harness provider select defaulting to
  OpenRouter, and a models modal on each bot's chat (the coordinator's
  edits the defaults)
- Chat: thinking row while a reply runs, file attachments (upload,
  paste, drop) that replies read as images, audio and document text
- Fix media uploads failing after a user's first file, and private
  files being served from the public media path

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-19 03:38:38 +01:00
co-authored by Claude Opus 5.5
parent d49f524fe8
commit 6a2665dae9
223 changed files with 12342 additions and 162 deletions
+21 -3
View File
@@ -1,6 +1,10 @@
import userAuth from "@/src/functions/backend/auth/user-auth";
import grabUserBot from "@/src/functions/backend/db/bots/grab-user-bot";
import insertUserMessage from "@/src/functions/backend/db/bots/insert-user-message";
import grabAttachableMedia from "@/src/functions/backend/db/bots/grab-attachable-media";
import enqueueBotReply from "@/src/functions/backend/db/bots-queue/enqueue-bot-reply";
import pushBotNotice from "@/src/bots-queue/push-bot-notice";
import wakeBotsQueue from "@/src/bots-queue/wake-bots-queue";
import { SendBotMessageRequestSchema } from "@/src/schemas/bot-schema";
import parseWithSchema from "@/src/utils/parse-with-schema";
import isReadOnlyUser from "@/src/utils/rbac/is-read-only-user";
@@ -12,7 +16,10 @@ import type {
} from "@moduletrace/bunext/types";
/**
* Posts a message from the session user to one of their own bots.
* Posts a message from the session user to one of their own bots and
* queues the bot's reply, which arrives over the WebSocket. The message
* also goes to the user's other open tabs. Files are uploaded first
* (`upload-attachment`) and sent as `media_ids`.
*/
export const handler: BunextAPIRouteHandler<APIResponseObject> = async ({
req,
@@ -37,7 +44,7 @@ export const handler: BunextAPIRouteHandler<APIResponseObject> = async ({
throw new AppError(`This user can only read records.`);
}
const { bot_id, text } = parseWithSchema({
const { bot_id, text, media_ids } = parseWithSchema({
schema: SendBotMessageRequestSchema,
data: body,
});
@@ -48,7 +55,18 @@ export const handler: BunextAPIRouteHandler<APIResponseObject> = async ({
throw new AppError(`Bot not found`);
}
const message = await insertUserMessage({ bot_id: bot.id, text });
const media = await grabAttachableMedia({ user_id: Number(user.id), media_ids });
const message = await insertUserMessage({ bot_id: bot.id, text, media });
await enqueueBotReply({
user_id: user.id,
bot_id: bot.id,
message_id: message.id || 0,
});
wakeBotsQueue();
await pushBotNotice({ bot_id: bot.id, message });
return {
success: true,