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:
@@ -0,0 +1,63 @@
|
||||
import type { BUN_SQLITE_COBBLE_BOTS } from "@/db/types/db";
|
||||
import { AppData } from "@/src/data/app-data";
|
||||
import { ChatReplyNote, CoordinatorReplyNote } from "@/src/data/harness-prompts";
|
||||
import grabBotMessages from "@/src/functions/backend/db/bots/grab-bot-messages";
|
||||
import grabBotPrompt from "@/src/functions/backend/db/bots/grab-bot-prompt";
|
||||
import runTextLoop from "@/src/harness/text/run-text-loop";
|
||||
import grabBotChatTools from "@/src/harness/tools/bot/grab-bot-chat-tools";
|
||||
import botMessagesToHarness from "./bot-messages-to-harness";
|
||||
import loadAttachmentParts from "./load-attachment-parts";
|
||||
import type { BotJobContext, BotJobOutcome } from "./types";
|
||||
|
||||
type Params = BotJobContext & {
|
||||
bot: BUN_SQLITE_COBBLE_BOTS & { id: number; user_id: number };
|
||||
};
|
||||
|
||||
/**
|
||||
* Answers the user in chat: the bot reads the recent conversation (and
|
||||
* the files of the latest messages, `loadAttachmentParts`) and
|
||||
* replies, with its chat tools (memory, instructions, start_task, and for
|
||||
* the coordinator delegate_task). Finishes silently when the last message
|
||||
* is already the bot's, i.e. an earlier reply answered everything.
|
||||
*/
|
||||
export default async function runBotReply({
|
||||
bot,
|
||||
job,
|
||||
signal,
|
||||
}: Params): Promise<BotJobOutcome> {
|
||||
const history = await grabBotMessages({
|
||||
bot_id: bot.id,
|
||||
limit: AppData.BotReplyHistoryMessages,
|
||||
});
|
||||
|
||||
if (history[history.length - 1]?.author != "user") {
|
||||
return { result: "", silent: true };
|
||||
}
|
||||
|
||||
const prompt = await grabBotPrompt({ bot_id: bot.id, user_id: bot.user_id });
|
||||
|
||||
const result = await runTextLoop({
|
||||
system: [
|
||||
prompt,
|
||||
ChatReplyNote,
|
||||
bot.kind == "coordinator" ? CoordinatorReplyNote : "",
|
||||
`Now: ${new Date().toUTCString()}.`,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n\n"),
|
||||
messages: botMessagesToHarness({
|
||||
messages: history,
|
||||
parts: await loadAttachmentParts({ messages: history }),
|
||||
}),
|
||||
tools: await grabBotChatTools({
|
||||
bot,
|
||||
user_id: bot.user_id,
|
||||
message_id: job.message_id || undefined,
|
||||
}),
|
||||
max_steps: AppData.BotReplyMaxToolSteps,
|
||||
bot_id: bot.id,
|
||||
signal,
|
||||
});
|
||||
|
||||
return { result: result.text };
|
||||
}
|
||||
Reference in New Issue
Block a user