Interface

IUtilityAI Defines the contract for a comprehensive Utility AI service.

Implements

Constructors

Methods

  • The JSON the text holds, read as StatisticalUtilityAI reads it (parseReplyJson: the text as it is, else inside the first Markdown code fence it holds, backticks inside a sentence opening none, with a language tag or none and with words before or after it, up to the first later line that starts with as many backticks as opened the fence or more), then a check against targetSchema with Ajv when given, as StatisticalUtilityAI checks it: the standard formats checked, a keyword or a format Ajv does not know passed over, and a value coerced to the type its schema names where it can (targetSchemaChecks). With attemptFixWithLLM, a text that fails either is sent for repair, up to maxRepairAttempts times (1 unless it is a whole number of 1 or more), each repair on the text the last one answered, whose answer is read the same way, on llmModelIdForFix (else jsonFixerModelId, else defaultModelId) and llmProviderIdForFix (else defaultProviderId). A repair request names targetSchema when given, and the schema's errors when the text parsed and failed it. Answers null when no repair parses and passes the schema, or a repair call fails. No text can pass a targetSchema that Ajv cannot compile, that takes the draft-07 meta-schema's $id or that is marked $async: the call answers null at once, with a warning, and asks for no repair.

    Type Parameters

    • T = any

    Parameters

    Returns Promise<null | T>

  • Summarizes conversation history to fit within token constraints, attempting to preserve key information.

    Parameters

    • messages: readonly ConversationMessage[]

      The array of conversation messages to summarize.

    • targetTokenCount: number

      The desired maximum token count for the summary.

    • modelInfo: Readonly<ModelTargetInfo>

      Information about the model for which the summary is being prepared.

    • Optional preserveImportantMessages: boolean

      If true, attempt to identify and keep important messages verbatim.

    Returns Promise<{
        summaryMessages: ConversationMessage[];
        originalTokenCount: number;
        finalTokenCount: number;
        messagesSummarized: number;
    }>

    A summary (which might be a single system message or a condensed list of messages), and metadata about the summarization.

  • Summarizes retrieved RAG context to fit token limits, ideally preserving source attribution if possible.

    Parameters

    • context: string | readonly {
          source: string;
          content: string;
          relevance?: number;
      }[]

      The RAG context to summarize.

    • targetTokenCount: number

      The desired maximum token count for the summarized context.

    • modelInfo: Readonly<ModelTargetInfo>

      Information about the model.

    • Optional preserveSourceAttribution: boolean

      If true, attempt to retain source information in the summary.

    Returns Promise<{
        summary: string;
        originalTokenCount: number;
        finalTokenCount: number;
        preservedSources?: string[];
    }>

    The summarized text and metadata.

  • Returns Promise<{
        isHealthy: boolean;
        details?: any;
        dependencies?: {
            name: string;
            isHealthy: boolean;
            details?: any;
        }[];
    }>

Properties

utilityId: string