FunctionModel
Callback-based mock model for complex test scenarios. Implements LanguageModelV3.
Delegates every model call to a user-supplied function that receives the full message context and can return any response — text, tool calls, or errors.
Example
Section titled “Example”const model = new FunctionModel((messages, { callIndex }) => { if (callIndex === 0) return { toolCalls: [...], usage: ..., finishReason: "tool-calls" } return { text: "Done!", usage: ..., finishReason: "stop" }})Implements
Section titled “Implements”LanguageModelV3
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new FunctionModel(
handler):FunctionModel
Parameters
Section titled “Parameters”handler
Section titled “handler”Returns
Section titled “Returns”FunctionModel
Properties
Section titled “Properties”modelId
Section titled “modelId”
readonlymodelId:"function-model"="function-model"
Provider-specific model ID.
Implementation of
Section titled “Implementation of”LanguageModelV3.modelId
provider
Section titled “provider”
readonlyprovider:"function"="function"
Provider ID.
Implementation of
Section titled “Implementation of”LanguageModelV3.provider
specificationVersion
Section titled “specificationVersion”
readonlyspecificationVersion:"v3"
The language model must specify which language model interface version it implements.
Implementation of
Section titled “Implementation of”LanguageModelV3.specificationVersion
supportedUrls
Section titled “supportedUrls”
readonlysupportedUrls:object={}
Supported URL patterns by media type for the provider.
The keys are media type patterns or full media types (e.g. */* for everything, audio/*, video/*, or application/pdf).
and the values are arrays of regular expressions that match the URL paths.
The matching should be against lower-case URLs.
Matched URLs are supported natively by the model and are not downloaded.
Returns
Section titled “Returns”A map of supported URL patterns by media type (as a promise or a plain object).
Implementation of
Section titled “Implementation of”LanguageModelV3.supportedUrls
Methods
Section titled “Methods”doGenerate()
Section titled “doGenerate()”doGenerate(
options):Promise<LanguageModelV3GenerateResult>
Generates a language model output (non-streaming).
Naming: “do” prefix to prevent accidental direct usage of the method by the user.
Parameters
Section titled “Parameters”options
Section titled “options”LanguageModelV3CallOptions
Returns
Section titled “Returns”Promise<LanguageModelV3GenerateResult>
Implementation of
Section titled “Implementation of”LanguageModelV3.doGenerate
doStream()
Section titled “doStream()”doStream():
Promise<never>
Generates a language model output (streaming).
Naming: “do” prefix to prevent accidental direct usage of the method by the user.
Returns
Section titled “Returns”Promise<never>
A stream of higher-level language model output parts.
Implementation of
Section titled “Implementation of”LanguageModelV3.doStream
reset()
Section titled “reset()”reset():
void
Reset call index for reuse across tests.
Returns
Section titled “Returns”void