/** * Workspace file defaults. * * Default content for SOUL.md, AGENTS.md, and TOOLS.md is stored in the * `workspace_templates` database table so it can be edited without redeploying. * * TOOLS.md is always auto-generated: * base template from DB + per-package tool sections appended dynamically. */ import { getWorkspaceTemplate } from "./db"; import { PACKAGE_CATALOG } from "./packages"; // ── Hardcoded fallbacks (used only if DB templates are missing) ───────────── const FALLBACK_SOUL = `# AI Assistant You are a helpful AI assistant. You are professional, concise, and friendly. ## Guidelines - Answer questions accurately and helpfully - If you don't know something, say so - Keep responses clear and to the point - Respect privacy and confidentiality `; const FALLBACK_AGENTS = `# Agents On session start, read the following workspace files in order: 1. SOUL.md — your personality and behavioural guidelines 2. TOOLS.md — available tools and how to use them 3. USER.md — information about the current user (if present) Follow the instructions in SOUL.md for every interaction. `; const FALLBACK_TOOLS = `# Tools The following tools are available to you as an AI assistant. ## LLM You have access to a large language model for text generation, summarisation, translation, and general question answering. `; // ── Per-package TOOLS.md appendices ───────────────────────────────────────── const PACKAGE_TOOL_SECTIONS: Record = { "web-search": ` ## Web Search (SearXNG) You can search the web using the integrated SearXNG instance. Use this to find current information, verify facts, or research topics that go beyond your training data. `, "document-processing": ` ## Document Processing You can parse, summarise, and extract information from uploaded documents including PDF, DOCX, XLSX, and plain text files. `, telegram: ` ## Telegram You are connected to a Telegram bot. Messages from users arrive as chat messages. Respond naturally and follow the guidelines in SOUL.md. `, discord: ` ## Discord You are connected to a Discord bot. Messages from server members arrive as chat messages. Respond naturally and follow the guidelines in SOUL.md. `, email: ` ## Email You can send and receive email. Use this to respond to enquiries, send notifications, or process incoming messages according to SOUL.md. `, }; // ── Public API ────────────────────────────────────────────────────────────── /** * Fetch the default SOUL.md content. * Substitutes {company} with the given org name. */ export async function getDefaultSoulMd(orgName: string): Promise { const tpl = await getWorkspaceTemplate("SOUL.md"); const content = tpl ?? FALLBACK_SOUL; return content.replace(/\{company\}/g, orgName); } /** * Fetch the default AGENTS.md content. */ export async function getDefaultAgentsMd(): Promise { const tpl = await getWorkspaceTemplate("AGENTS.md"); return tpl ?? FALLBACK_AGENTS; } /** * Build the TOOLS.md content for a given set of enabled packages. * Base template from DB (or fallback) + per-package appendices. */ export async function generateToolsMd( enabledPackages: string[] ): Promise { const base = (await getWorkspaceTemplate("TOOLS.md")) ?? FALLBACK_TOOLS; const sections = enabledPackages .filter((id) => PACKAGE_TOOL_SECTIONS[id]) .map((id) => PACKAGE_TOOL_SECTIONS[id]); return [base.trimEnd(), ...sections].join("\n"); }