Member Junction
    Preparing search index...

    Base class for all LLM sub-class implementations. Not all sub-classes will support all methods. If a method is not supported an exception will be thrown.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _additionalSettings: Record<string, any>

    Protected property to store additional provider-specific settings

    thinkingStreamState: ThinkingStreamState

    State tracking for streaming thinking extraction Providers should initialize this if they support thinking models

    Accessors

    • get AdditionalSettings(): Record<string, any>

      Get the current additional settings

      Returns Record<string, any>

    • get apiKey(): string

      Only sub-classes can access the API key

      Returns string

    Methods

    • The result of a cancelled request, the same for every driver: a failed result with no choices, statusText 'cancelled', and an errorInfo that says Cancelled (Fatal, never failed over) — or, when the signal was aborted by a timeout, a retriable NetworkError.

      Parameters

      • startTime: Date
      • Optionaloptions: { error?: unknown; message?: string; signal?: AbortSignal }
        • Optionalerror?: unknown

          The error the abort raised, kept on exception.

        • Optionalmessage?: string

          The message to report; defaults to one naming the signal's reason.

        • Optionalsignal?: AbortSignal

          The request's abort signal, read for why it was aborted.

      Returns ChatResult

    • Process a chat completion request. If streaming is enabled and supported, this will route to the streaming implementation.

      Parameters

      Returns Promise<ChatResult>

    • Process multiple chat completion requests in parallel. This is useful for:

      • Generating multiple variations with different parameters (temperature, etc.)
      • Getting multiple responses to compare or select from
      • Improving reliability by sending the same request multiple times

      Parameters

      Returns Promise<ChatResult[]>

      Promise resolving to an array of ChatResults in the same order as the input params

    • Clear all additional settings This is useful for resetting the state of the provider or when switching between different configurations.

      Returns void

    • Utility method to map a MemberJunction role to OpenAI role

      • user maps to user
      • assistant maps to assistant
      • anything else maps to user While the above is a direct 1:1 mapping, it is possible that OpenAI may have more roles in the future and this method will need to be updated for flexibility

      Parameters

      Returns "user" | "assistant"

    • Extract thinking content from non-streaming content This method handles case-insensitive extraction of thinking blocks

      Parameters

      • content: string

      Returns { content: string; thinking?: string }

    • Returns (and clears) any user-visible content the thinking-tag stripper is still holding back at the end of a stream. Mid-stream, processStreamChunkWithThinking holds back a trailing fragment that could be the start of a <think>/</think> tag so a split tag never leaks as partial text; once the stream ends, such a fragment is real content and must be emitted (bug A5).

      Only flushes when NOT inside a thinking block: an unterminated <think> block's buffered text is reasoning, not answer, and is left held back (never surfaced as visible content). Returns '' when thinking extraction isn't active (no state) or there's nothing to flush.

      Returns string

    • Format messages for Anthropic API with caching support. Handles both text and multi-modal content (images).

      Parameters

      • messages: ChatMessage[]

        Messages to format

      • enableCaching: boolean = true

        Whether to enable caching

      Returns any[]

      Formatted messages

    • Format system messages for Anthropic API with caching support. System messages support multi-modal content (images).

      Parameters

      • messages: ChatMessage[]

        Messages to format

      • enableCaching: boolean = true

        Whether to enable caching

      Returns any[]

      Flattened array of formatted content blocks

    • Get the thinking tag format for this provider Providers can override this to customize the thinking tag format

      Returns { close: string; open: string }

    • Template method for handling streaming chat completion This implements the common pattern across providers while delegating provider-specific logic to abstract methods.

      Parameters

      Returns Promise<ChatResult>

    • Initialize thinking stream state for streaming extraction

      Returns void

    • Whether a request ended because it was aborted: its signal is aborted, the error is an abort by name (AbortError, APIUserAbortError, RequestAbortedError), or IsProviderAbortError recognizes it.

      Parameters

      • error: unknown
      • Optionalsignal: AbortSignal

      Returns boolean

    • Recognizes an abort error the shared names miss. A driver whose SDK raises its own class for an aborted request overrides this. Default: false.

      Parameters

      • _error: unknown

      Returns boolean

    • Extends the framework's metadata-flag test with a text fallback: a message whose text opens with the runtime-state or agent-specialization tag literal is treated as the trailing fragment even when the caller passed plain ChatMessages without metadata. Forged tags in history cannot reach here as an opening literal because the agent layer escapes them before sending.

      Parameters

      Returns boolean

    • Process streaming chunk with thinking extraction This method handles case-insensitive extraction across chunk boundaries

      Parameters

      • rawContent: string

      Returns string

    • Reset streaming state for a new request. Overrides the base-class hook so BaseLLM.handleStreamingChatCompletion calls this both at the start of a request AND in its finally block — the latter releases accumulated thinking buffers (which can grow to 100k+ chars on extended-thinking outputs) and prevents state from a prior request bleeding into the next. See audit R2-C5.

      Returns void

    • Reset thinking stream state

      Returns void

    • Set additional provider-specific settings Subclasses should override this method to validate required settings

      Parameters

      • settings: Record<string, any>

        Provider-specific settings

      Returns void

    • Splits an outgoing request around its trailing volatile-state message, so a driver can place its cache boundary on the last message of head and send tail uncached. Returns null when the request has no trailing volatile state, in which case the driver formats the whole list as usual. Neither array is a copy of the input's messages; only the list is new.

      Parameters

      Returns TrailingVolatileStateSplit

    • Check if the provider supports thinking models Providers should override this to return true if they support thinking extraction

      Returns boolean

    • Index of the trailing volatile-state message in an outgoing request, or -1 when there is none. The fragment is the LAST message, or the one before it when an assistant prefill has been appended after it. -1 is also returned when nothing precedes the fragment, because then there is no stable history for a provider to cache ahead of it.

      Parameters

      Returns number