import type { Entity, IAgentRuntime, Memory, State, TemplateType } from "./types";
import { ContentType, type UUID } from "./types";
/**
 * Default max tokens for conversation context in the recentMessages provider.
 *
 * This budget must leave room within the overall prompt token limit
 * (`DEFAULT_MAX_PROMPT_TOKENS`) for all other state providers (character,
 * facts, knowledge, actions, relationships, etc.) and template formatting.
 * Those typically consume 20-60 K tokens, so keeping conversation under
 * 50 K provides a safe margin.
 */
export declare const DEFAULT_MAX_CONVERSATION_TOKENS = 50000;
/** Max tokens for embedding input text */
export declare const MAX_EMBEDDING_TOKENS = 8000;
/** Max character equivalent for embedding text (tokens * ~4 chars/token) */
export declare const MAX_EMBEDDING_CHARS: number;
/** Default max tokens for the assembled prompt sent to the model */
export declare const DEFAULT_MAX_PROMPT_TOKENS = 128000;
/**
 * Fast synchronous token estimation.
 * Uses ~4 characters per token average for English text.
 * Avoids async model calls — suitable for hot-path budget checks.
 */
export declare function estimateTokens(text: string): number;
/**
 * Trims an array of messages to fit within a token budget.
 * Messages should be ordered most-recent-first.
 * Always keeps at least the first (most recent) message.
 * Returns a new array (does not mutate the input).
 */
export declare function trimMessagesByTokenBudget(messages: Memory[], maxTokens: number): Memory[];
/**
 * Strips names, timestamps, entity IDs, and formatting from conversation text.
 * Returns just the raw conversational content — useful for embedding generation
 * where semantic meaning matters more than structure.
 */
export declare function stripMessageFormatting(text: string): string;
/**
 * Composes a context string by replacing placeholders in a template with corresponding values from the state.
 *
 * This function takes a template string with placeholders in the format `{{placeholder}}` and a state object.
 * It replaces each placeholder with the value from the state object that matches the placeholder's name.
 * If a matching key is not found in the state object for a given placeholder, the placeholder is replaced with an empty string.
 *
 * @param {Object} params - The parameters for composing the context.
 * @param {State} params.state - The state object containing values to replace the placeholders in the template.
 * @param {TemplateType} params.template - The template string or function containing placeholders to be replaced with state values.
 * @returns {string} The composed context string with placeholders replaced by corresponding state values.
 *
 * @example
 * // Given a state object and a template
 * const state = { userName: "Alice", userAge: 30 };
 * const template = "Hello, {{userName}}! You are {{userAge}} years old";
 *
 * // Composing the context with simple string replacement will result in:
 * // "Hello, Alice! You are 30 years old."
 * const contextSimple = composePromptFromState({ state, template });
 *
 * // Using composePromptFromState with a template function for dynamic template
 * const template = ({ state }) => {
 * const tone = Math.random() > 0.5 ? "kind" : "rude";
 *   return `Hello, {{userName}}! You are {{userAge}} years old. Be ${tone}`;
 * };
 * const contextSimple = composePromptFromState({ state, template });
 */
/**
 * Function to compose a prompt using a provided template and state.
 * It compiles the template (upgrading double braces to triple braces for non-HTML escaping)
 * and then populates it with values from the state. Additionally, it processes the
 * resulting string with `composeRandomUser` to replace placeholders like `{{nameX}}`.
 *
 * @param {Object} options - Object containing state and template information.
 * @param {State} options.state - The state object containing values to fill the template.
 * @param {TemplateType} options.template - The template string or function to be used for composing the prompt.
 * @returns {string} The composed prompt output, with state values and random user names populated.
 */
export declare const composePrompt: ({ state, template, }: {
    state: {
        [key: string]: string;
    };
    template: TemplateType;
}) => string;
/**
 * Function to compose a prompt using a provided template and state.
 *
 * @param {Object} options - Object containing state and template information.
 * @param {State} options.state - The state object containing values to fill the template.
 * @param {TemplateType} options.template - The template to be used for composing the prompt.
 * @returns {string} The composed prompt output.
 */
export declare const composePromptFromState: ({ state, template, }: {
    state: State;
    template: TemplateType;
}) => string;
/**
 * Adds a header to a body of text.
 *
 * This function takes a header string and a body string and returns a new string with the header prepended to the body.
 * If the body string is empty, the header is returned as is.
 *
 * @param {string} header - The header to add to the body.
 * @param {string} body - The body to which to add the header.
 * @returns {string} The body with the header prepended.
 *
 * @example
 * // Given a header and a body
 * const header = "Header";
 * const body = "Body";
 *
 * // Adding the header to the body will result in:
 * // "Header\nBody"
 * const text = addHeader(header, body);
 */
export declare const addHeader: (header: string, body: string) => string;
export declare const formatPosts: ({ messages, entities, conversationHeader, }: {
    messages: Memory[];
    entities: Entity[];
    conversationHeader?: boolean;
}) => string;
/**
 * Format messages into a string
 * @param {Object} params - The formatting parameters
 * @param {Memory[]} params.messages - List of messages to format
 * @param {Entity[]} params.entities - List of entities for name resolution
 * @returns {string} Formatted message string with timestamps and user information
 */
export declare const formatMessages: ({ messages, entities, }: {
    messages: Memory[];
    entities: Entity[];
}) => string;
export declare const formatTimestamp: (messageDate: number) => string;
/**
 * Parses key-value pairs from a simple XML structure within a given text.
 * It looks for an XML block (e.g., <response>...</response>) and extracts
 * text content from direct child elements (e.g., <key>value</key>).
 *
 * Uses regex - suitable for simple XML. For complex XML, use a proper parser.
 *
 * @typeParam T - The expected shape of the parsed result. Defaults to Record<string, unknown>.
 * @param text - The input text containing the XML structure.
 * @returns The parsed object cast to type T, or null if parsing fails.
 *
 * @example
 * interface MyResponse { thought: string; message: string; }
 * const result = parseKeyValueXml<MyResponse>(xmlText);
 * // result is MyResponse | null
 */
export declare function parseKeyValueXml<T = Record<string, unknown>>(text: string): T | null;
/**
 * Parses a JSON object from a given text. The function looks for a JSON block wrapped in triple backticks
 * with `json` language identifier, and if not found, it searches for an object pattern within the text.
 * It then attempts to parse the JSON string into a JavaScript object. If parsing is successful and the result
 * is an object (but not an array), it returns the object; otherwise, it tries to parse an array if the result
 * is an array, or returns null if parsing is unsuccessful or the result is neither an object nor an array.
 *
 * @param text - The input text from which to extract and parse the JSON object.
 * @returns An object parsed from the JSON string if successful; otherwise, null or the result of parsing an array.
 */
export declare function parseJSONObjectFromText(text: string): Record<string, unknown> | null;
/**
 * Normalizes a JSON-like string by correcting formatting issues:
 * - Removes extra spaces after '{' and before '}'.
 * - Wraps unquoted values in double quotes.
 * - Converts single-quoted values to double-quoted.
 * - Ensures consistency in key-value formatting.
 * - Normalizes mixed adjacent quote pairs.
 *
 * This is useful for cleaning up improperly formatted JSON strings
 * before parsing them into valid JSON.
 *
 * @param str - The JSON-like string to normalize.
 * @returns A properly formatted JSON string.
 */
export declare const normalizeJsonString: (str: string) => string;
/**
 * Truncate text to fit within the character limit, ensuring it ends at a complete sentence.
 */
export declare function truncateToCompleteSentence(text: string, maxLength: number): string;
export declare function splitChunks(content: string, chunkSize?: number, bleed?: number): Promise<string[]>;
/**
 * Trims the provided text prompt to a specified token limit using a tokenizer model and type.
 */
export declare function trimTokens(prompt: string, maxTokens: number, runtime: IAgentRuntime): Promise<string>;
export declare function safeReplacer(): (_key: string, value: unknown) => unknown;
/**
 * Parses a string to determine its boolean equivalent.
 *
 * Recognized affirmative values: "YES", "Y", "TRUE", "T", "1", "ON", "ENABLE"
 * Recognized negative values: "NO", "N", "FALSE", "F", "0", "OFF", "DISABLE"
 *
 * @param {string | undefined | null} value - The input text to parse
 * @returns {boolean} - Returns `true` for affirmative inputs, `false` for negative or unrecognized inputs
 */
export declare function parseBooleanFromText(value: string | boolean | undefined | null): boolean;
/**
 * Validates a UUID value.
 *
 * @param {unknown} value - The value to validate.
 * @returns {UUID | null} Returns the validated UUID value or null if validation fails.
 */
export declare function validateUuid(value: unknown): UUID | null;
/**
 * Converts a string or number to a UUID.
 *
 * @param {string | number} target - The string or number to convert to a UUID.
 * @returns {UUID} The UUID generated from the input target.
 * @throws {TypeError} Throws an error if the input target is not a string.
 */
export declare function stringToUuid(target: string | number): UUID;
/**
 * Pre-warm the SHA-1 cache with common values using WebCrypto
 * Call this during initialization to improve performance
 */
export declare function prewarmUuidCache(values: string[]): Promise<void>;
export declare const getContentTypeFromMimeType: (mimeType: string) => ContentType | undefined;
export declare function getLocalServerUrl(path: string): string;
//# sourceMappingURL=utils.d.ts.map