/** * Manager Utilities - Helper functions for managers and agent processing * * Features: * - Unique ID generation for events and messages using crypto.randomUUID() * - Chat ID generation using nanoid for human-readable IDs * - Manager-specific utility functions for string manipulation and processing * - String manipulation utilities (kebab-case conversion for IDs and names) * - Agent and message processing utilities with world-aware operations * - LLM message preparation with conversation history and system prompts * - Mention extraction with first-mention-only logic and case-insensitive matching * - Sender type detection for humans, agents, and system messages * - Agent memory filtering for LLM context (prevents irrelevant message pollution) * * Core Utilities: * - generateId: Crypto-based unique ID generation for messages and events * - generateChatId: Nanoid-based short ID generation for chat history * - toKebabCase: String conversion for consistent naming conventions * - getWorldTurnLimit: World-specific turn limit retrieval with fallback defaults * - extractMentions: Case-insensitive mention extraction with first-mention-only logic * - 2026-03-01: Fixed parseParagraphBeginningMention to only extend with next TitleCase word when mention starts uppercase (prevents @a2 Hi → a2-hi) * - determineSenderType: Sender classification for message filtering and processing * - prepareMessagesForLLM: Message formatting for LLM calls with history and system prompts * - wouldAgentHaveRespondedToHistoricalMessage: Filters irrelevant messages from LLM context * * Implementation Details: * - Uses native crypto.randomUUID() for ID generation ensuring uniqueness * - Uses nanoid for human-readable chat IDs (8 characters, URL-safe) * - Self-contained utility functions with no external dependencies * - Ready for manager module integration with consistent interfaces * - All types imported from types.ts for better organization and reusability * - World-aware functions that respect world-specific configurations * - Message processing utilities that handle AI SDK compatibility * - Agent memory filtering prevents LLM context pollution from irrelevant messages * * Recent Changes: * - 2026-03-06: Suppressed empty Agent Skills injections and grouped runtime prompt sections behind a structural separator. * - 2026-03-01: Added explicit `grep` prompt guidance to require `includePattern` (no leading dot) and reduce tool-parameter validation failures. * - 2026-03-01: Added global pre-tool planning guidance so all tool-enabled agents narrate next steps before calling tools. * - 2026-03-01: Added `available_skills` prompt rule requiring explicit post-`load_skill` acknowledgment before taking action. * - 2026-02-21: Added `list_files` prompt guidance to prefer `includePattern` and bounded `maxEntries` for file-type searches to reduce oversized tool results and continuation churn. * - 2026-02-21: Excluded persisted shell stdout stream assistant messages (messageId suffix `-stdout`) from LLM-history relevance filtering to prevent tool-continuation token amplification loops. * - 2026-02-20: Updated HITL tool system-prompt guidance to enforce options-only HITL usage. * - 2026-02-20: Added `buildToolUsagePromptSection()` for centralized, tool-aware system-prompt guidance (including HITL usage guidance when available). * - 2026-02-19: Replaced raw `working directory: ` system-prompt suffix with explicit `shell_cmd` scope instructions and a no-echo directive. * - 2026-02-16: Added env-driven global/project skill-scope filtering for the `## Agent Skills` system prompt section. * - 2026-02-15: prepareMessagesForLLM now appends a concise, strict cross-agent addressing rule requiring `@, ` when targeting a specific agent. * - 2026-02-14: prepareMessagesForLLM now injects an `## Agent Skills` section with registry-backed `` entries and `load_skill` guidance. * - 2026-02-14: Added shared default working-directory resolver (env override -> user home -> `./`) and switched missing world `working_directory` fallback from `./` to user home. * - 2026-02-13: prepareMessagesForLLM began appending execution-directory context from world `working_directory`. * - 2026-02-08: Fixed wouldAgentHaveRespondedToHistoricalMessage to include assistant messages with tool_calls * (prevents OpenAI error: "messages with role 'tool' must be a response to a preceeding message with 'tool_calls'") * - Enhanced comment documentation with detailed feature descriptions * - Improved function descriptions with implementation details * - Added details about world-aware operations and LLM integration * - Added nanoid support for chat ID generation * - Added wouldAgentHaveRespondedToHistoricalMessage for LLM context filtering * - Updated prepareMessagesForLLM to filter irrelevant conversation history * - Consolidated with message-prep.ts filtering for client-side tool calls */ /** * Resolve default working directory when world variable is not configured. * Priority: * 1) AGENT_WORLD_DEFAULT_WORKING_DIRECTORY (runtime override) * 2) OS user home directory * 3) "./" hard fallback */ export declare function getDefaultWorkingDirectory(): string; /** * Generate unique ID for messages and events */ export declare function generateId(): string; /** * Generate short, human-readable ID for chat history */ export declare function generateChatId(): string; /** * Simple runtime environment detection * Returns true for Node.js, false for browser */ export declare function isNodeEnvironment(): boolean; /** * Convert a string to kebab-case * @param str - The string to convert * @returns The kebab-case version of the string */ export declare function toKebabCase(str: string): string; /** * Parse .env-style text into key-value map. * Supported: * - Comments: # comment * - Blank lines * - KEY=value entries (optional whitespace around '=') * Invalid lines are ignored. */ export declare function parseEnvText(variablesText?: string): Record; /** * Get a single env value from .env-style text */ export declare function getEnvValueFromText(variablesText: string | undefined, key: string): string | undefined; /** * Build tool-usage guidance section for the system prompt. * Guidance is tool-aware and only includes HITL instructions when HITL tool names are present. */ export declare function buildToolUsagePromptSection(options: { toolNames: string[]; }): string; /** * Interpolate template variables in form {{ variable }} from env map. * Missing variables are replaced with empty string. */ export declare function interpolateTemplateVariables(template: string, envMap: Record): string; import { World, Agent, SenderType, MessageData, AgentMessage } from './types.js'; /** * Get world-specific turn limit or default value */ export declare function getWorldTurnLimit(world: World): number; /** * Extract @mentions from message content - returns only first valid mention * Implements first-mention-only logic to prevent multiple agent responses */ export declare function extractMentions(content: string): string[]; /** * Extract @mentions that appear at the beginning of paragraphs * Implements paragraph-beginning-only logic for agent response triggering * * @param content - The message content to search for mentions * @returns Array of mention names (lowercase) that appear at paragraph beginnings */ export declare function extractParagraphBeginningMentions(content: string): string[]; /** * Determine sender type based on sender name (matches src/agent.ts logic) */ export declare function determineSenderType(sender: string | undefined): SenderType; /** * Check if agent would have responded to a historical message * Replicates shouldAgentRespond logic for saved messages to filter LLM context * * @param agent - The agent to check response logic for * @param message - The historical message to evaluate * @returns true if agent would have responded to this message */ export declare function wouldAgentHaveRespondedToHistoricalMessage(agent: Agent, message: AgentMessage): boolean; /** * Convert MessageData to AgentMessage for memory storage */ export declare function messageDataToAgentMessage(messageData: MessageData): AgentMessage; /** * Prepare messages array for LLM using standard chat message format * Filters conversation history by chatId if provided and excludes messages * the agent would not have responded to (prevents irrelevant context pollution) */ export declare function prepareMessagesForLLM(worldId: string, agent: Agent, chatId: string | null, includeCurrentMessage?: MessageData): Promise;