Betty API key, sent as the bearer on every request.
OptionalendUserId: stringOptional caller identifier, forwarded as the endUserId request-body field.
Betty records it against the conversation so a caller gets its own attribution row and its
own rate-limit bucket rather than sharing an anonymous per-IP one — the same problem
BettyBotLLM's userId argument solves for the legacy service, and named here for the field
Betty's own API documents.
ATTRIBUTION ONLY, and unverified by design: retrieval scope is pinned server-side from the credential, so this never widens what content the request can reach. Do not use it for authorization.
Omitted, the request body is byte-identical to one built without this parameter.
Note this is reachable only by constructing the provider directly — AIPromptRunner
instantiates through ClassFactory.CreateInstance(BaseLLM, driverClass, apiKey) and passes
the key alone, and ChatParams carries no user identity to fall back on. A caller that wants
attribution does new BettyLLM(key, 'izzy'), exactly as the legacy provider is used from
betty.action.ts.
Protected_Protected property to store additional provider-specific settings
ProtectedthinkingState tracking for streaming thinking extraction Providers should initialize this if they support thinking models
Get the current additional settings
ProtectedapiOnly sub-classes can access the API key
Whether this LLM provider supports assistant prefill (pre-seeding the start of the model's response). Providers that support prefill should override this to return true. This is used as a code-level default when database metadata (AIModelType/AIModel/AIModelVendor.SupportsPrefill) is null. Database values of true/false override this getter.
The API supports SSE when the request sets Accept: text/event-stream, but this provider
does not use it yet — wiring it means implementing the three streaming members below against
Betty's event shape. Declared false so BaseLLM never routes a streaming request here.
Whether this driver implements native tool/function calling — i.e. whether it maps
ChatParams.tools onto its SDK and normalizes tool calls back into
ChatCompletionMessage.toolCalls.
This is a CODE-level capability ("has the mapping been written for this driver?"), distinct
from the METADATA-level capability ModelConfiguration.LLM.SupportsNativeToolCalling
("does this model, on this vendor, support tools at all?"). Both must hold for native mode.
A driver returning false ignores any tools passed to it and records the fact in the
result's modelSpecificResponseDetails — the prompt runner's gate should keep that from
happening, but the layer is safe standalone.
ProtectedaddAdd thinking content to a chat completion message
OptionalthinkingContent: stringProtectedBuildThe 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.
Optionaloptions: { error?: unknown; message?: string; signal?: AbortSignal }Optionalerror?: unknownThe error the abort raised, kept on exception.
Optionalmessage?: stringThe message to report; defaults to one naming the signal's reason.
Optionalsignal?: AbortSignalThe request's abort signal, read for why it was aborted.
Process a chat completion request. If streaming is enabled and supported, this will route to the streaming implementation.
Process multiple chat completion requests in parallel. This is useful for:
Array of chat completion parameter objects
Optionalcallbacks: ParallelChatCompletionsCallbacksOptional callbacks for progress and individual completions
Promise resolving to an array of ChatResults in the same order as the input params
Classification through a driver method is deprecated along with the legacy AI
Actions system, its only caller, and will be removed in the next major version. Most drivers
do not implement it. Run an AI Prompt through AIPromptRunner (@memberjunction/ai-prompts)
instead, which adds model selection, failover and cost tracking.
Clear all additional settings This is useful for resetting the state of the provider or when switching between different configurations.
ProtectedcreateCreate a provider-specific streaming request
Chat parameters
A stream object that can be iterated with for await
ProtectedextractExtract thinking content from non-streaming content This method handles case-insensitive extraction of thinking blocks
ProtectedfinalizeCreate the final response object from streaming results
The complete content accumulated from all chunks
The last chunk received from the stream
The usage information (tokens, etc.)
A complete ChatResult object
ProtectedflushReturns (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 the native file input capabilities of this LLM driver, or null if the driver does not support file attachments. Subclasses that accept files (PDFs, images, etc.) should override this method.
ProtectedgetGet the thinking tag format for this provider Providers can override this to customize the thinking tag format
ProtectedhandleTemplate method for handling streaming chat completion This implements the common pattern across providers while delegating provider-specific logic to abstract methods.
ProtectedinitializeInitialize thinking stream state for streaming extraction
ProtectedIsWhether 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.
Optionalsignal: AbortSignalProtectedIsHttpPost wraps an aborted request in an HttpError flagged IsCancelled. Its own timeout is
flagged IsTimeout instead and is not a cancellation, so it stays retriable.
ProtectedisWhether a message is framework-authored volatile state for this request only: the loop agent's trailing runtime-state fragment (date/time, scratchpad, payload, a relocated specialization), which is rebuilt every iteration and must never sit inside a provider's cached prefix.
The base test is the VolatileStateMessageMetadata.volatileState flag the agent layer
sets. A driver may override to recognise the message by other means (Anthropic also accepts
the fragment's tag literal for callers that pass plain text), but should call super first.
ProtectednonImplementation for non-streaming chat completion
ProtectedprocessProcess streaming chunk with thinking extraction This method handles case-insensitive extraction across chunk boundaries
ProtectedprocessProcess a streaming chunk from the provider
The raw chunk from the provider
Processed content and metadata
ProtectedresetHook invoked at the start AND end (in finally) of every streaming chat
completion to reset per-request streaming state. Default is a no-op;
providers that maintain instance-level streaming state (e.g., Anthropic /
OpenAI thinking-block accumulators) MUST override this. See audit R2-C5
for context — without this, state from a prior request bleeds into the
next one and accumulated buffers grow unbounded across the singleton's
lifetime.
ProtectedresetReset thinking stream state
Set additional provider-specific settings Subclasses should override this method to validate required settings
Provider-specific settings
ProtectedsplitSplits 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.
Summarization through a driver method is deprecated along with the legacy AI
Actions system, its only caller, and will be removed in the next major version. Run a
summarization AI Prompt through AIPromptRunner (@memberjunction/ai-prompts) instead,
which adds model selection, failover and cost tracking.
ProtectedsupportsCheck if the provider supports thinking models Providers should override this to return true if they support thinking extraction
ProtectedtrailingIndex 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.
MemberJunction provider for Betty, the MJ-native organization-scoped assistant.
Why this is a separate class from
BettyBotLLM@memberjunction/ai-betty-bottargets a different service with a different wire protocol: it exchanges its key for a JWT atPOST /settings, then posts{ input }toPOST /response. Betty takes the API key directly as a bearer and posts{ message, conversationId }toPOST /messages. Auth, endpoint, request and response all differ, soBETTY_BOT_BASE_URLcannot bridge them.Making this a separate
DriverClassrather than a mode of the existing one is deliberate:GetAIAPIKey()is keyed by DRIVER CLASS, so a single class serving both protocols would read oneAI_VENDOR_API_KEY__BETTYBOTLLMfor two unrelated services — a misconfiguration would silently send a customer's key to the wrong host. A distinct class gets a distinct variable.@memberjunction/ai-betty-botstays byte-identical, so no existing deployment changes and nobody has to be contacted or given a deadline.AIModelVendor.DriverClass; rolling back is repointing it back.Conversation history
Betty threads conversations server-side via
conversationId, butChatParamscarries no correlation id and a fresh provider instance is constructed for every execution, so there is nothing to thread it through. MJ therefore owns the history: the latest user message is the turn, and everything before it is passed as advisorycontext.text.This is the one thing NOT to copy from the legacy provider, which does
params.messages.find(m => m.role === user)—.findreturns the FIRST match, so on a three-turn exchange it sends the opening question and silently discards the follow-up.