Documentation
¶
Overview ¶
Package mock provides mock provider implementation for testing and development.
Index ¶
- Constants
- type AudioURL
- type Config
- type ContentPart
- type DocumentURL
- type FileMockRepository
- type ImageURL
- type InMemoryMockRepository
- func (r *InMemoryMockRepository) GetResponse(ctx context.Context, params ResponseParams) (string, error)
- func (r *InMemoryMockRepository) GetTurn(ctx context.Context, params ResponseParams) (*Turn, error)
- func (r *InMemoryMockRepository) SetResponse(scenarioID string, turnNumber int, response string)
- type MockStreamSession
- func (m *MockStreamSession) Close() error
- func (m *MockStreamSession) Done() <-chan struct{}
- func (m *MockStreamSession) EmitChunk(chunk *providers.StreamChunk)
- func (m *MockStreamSession) EndInput()
- func (m *MockStreamSession) Error() error
- func (m *MockStreamSession) GetChunks() []*types.MediaChunk
- func (m *MockStreamSession) GetTexts() []string
- func (m *MockStreamSession) ReceivedToolResponses() []providers.ToolResponse
- func (m *MockStreamSession) Response() <-chan providers.StreamChunk
- func (m *MockStreamSession) SendChunk(ctx context.Context, chunk *types.MediaChunk) error
- func (m *MockStreamSession) SendSystemContext(ctx context.Context, text string) error
- func (m *MockStreamSession) SendText(ctx context.Context, text string) error
- func (m *MockStreamSession) SendToolResponse(ctx context.Context, toolCallID, result string) error
- func (m *MockStreamSession) SendToolResponses(_ context.Context, responses []providers.ToolResponse) error
- func (m *MockStreamSession) WithAutoRespond(text string) *MockStreamSession
- func (m *MockStreamSession) WithCloseAfterResponse(closeAfter bool) *MockStreamSession
- func (m *MockStreamSession) WithCloseAfterTurns(turns int, noResponse ...bool) *MockStreamSession
- func (m *MockStreamSession) WithError(err error) *MockStreamSession
- func (m *MockStreamSession) WithInterruptOnTurn(turnNumber int) *MockStreamSession
- func (m *MockStreamSession) WithRepository(repo ResponseRepository, baseDir string) *MockStreamSession
- func (m *MockStreamSession) WithResponseChunks(chunks []providers.StreamChunk) *MockStreamSession
- func (m *MockStreamSession) WithScenarioID(scenarioID string) *MockStreamSession
- func (m *MockStreamSession) WithSendChunkError(err error) *MockStreamSession
- func (m *MockStreamSession) WithSendTextError(err error) *MockStreamSession
- type Provider
- func (m *Provider) CalculateCost(inputTokens, outputTokens, cachedTokens int) types.CostInfo
- func (m *Provider) Close() error
- func (m *Provider) ID() string
- func (m *Provider) Model() string
- func (m *Provider) Predict(ctx context.Context, req providers.PredictionRequest) (providers.PredictionResponse, error)
- func (m *Provider) PredictStream(ctx context.Context, req providers.PredictionRequest) (<-chan providers.StreamChunk, error)
- func (m *Provider) ShouldIncludeRawOutput() bool
- func (m *Provider) SupportsStreaming() bool
- type ResponseParams
- type ResponseRepository
- type ScenarioConfig
- type StreamingProvider
- func (p *StreamingProvider) CreateStreamSession(ctx context.Context, req *providers.StreamingInputConfig) (providers.StreamInputSession, error)
- func (p *StreamingProvider) GetSession() *MockStreamSession
- func (p *StreamingProvider) GetSessions() []*MockStreamSession
- func (p *StreamingProvider) GetStreamingCapabilities() providers.StreamingCapabilities
- func (p *StreamingProvider) SupportsStreamInput() []string
- func (p *StreamingProvider) WithAutoRespond(responseText string) *StreamingProvider
- func (p *StreamingProvider) WithCloseAfterTurns(turns int, noResponse ...bool) *StreamingProvider
- func (p *StreamingProvider) WithCreateSessionError(err error) *StreamingProvider
- func (p *StreamingProvider) WithInterruptOnTurn(turnNumber int) *StreamingProvider
- func (p *StreamingProvider) WithMockResponses(repo ResponseRepository, scenarioID, fixtureBaseDir string) *StreamingProvider
- func (p *StreamingProvider) WithResponseChunks(chunks ...providers.StreamChunk) *StreamingProvider
- type ToolCall
- type ToolProvider
- func (m *ToolProvider) BuildTooling(descriptors []*providers.ToolDescriptor) (providers.ProviderTools, error)
- func (m *ToolProvider) PredictStreamWithTools(ctx context.Context, req providers.PredictionRequest, tools interface{}, ...) (<-chan providers.StreamChunk, error)
- func (m *ToolProvider) PredictWithTools(ctx context.Context, req providers.PredictionRequest, ...) (providers.PredictionResponse, []types.MessageToolCall, error)
- type Turn
- type VideoURL
Constants ¶
const (
// DefaultMockStreamingResponse is the default response text for auto-respond mode.
DefaultMockStreamingResponse = "Mock streaming response"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AudioURL ¶ added in v1.1.3
type AudioURL struct {
URL string `yaml:"url"` // URL to the audio file (can be mock://, http://, https://, data:, or file path)
}
AudioURL represents audio content in a mock response.
type Config ¶ added in v1.1.3
type Config struct {
// Default response if no specific match is found
DefaultResponse string `yaml:"defaultResponse"`
// Scenario-specific responses keyed by scenario ID
Scenarios map[string]ScenarioConfig `yaml:"scenarios,omitempty"`
// Selfplay persona responses keyed by persona ID
// Used when generating user messages in selfplay mode
Selfplay map[string]ScenarioConfig `yaml:"selfplay,omitempty"`
}
Config represents the structure of a mock configuration file. This allows scenario-specific and turn-specific responses to be defined.
type ContentPart ¶ added in v1.1.3
type ContentPart struct {
Type string `yaml:"type"` // "text", "image", "audio", "video", or "document"
Text string `yaml:"text,omitempty"` // Text content (for type="text")
ImageURL *ImageURL `yaml:"image_url,omitempty"` // Image URL (for type="image")
AudioURL *AudioURL `yaml:"audio_url,omitempty"` // Audio URL (for type="audio")
VideoURL *VideoURL `yaml:"video_url,omitempty"` // Video URL (for type="video")
DocumentURL *DocumentURL `yaml:"document_url,omitempty"` // Document URL (for type="document")
Metadata map[string]interface{} `yaml:"metadata,omitempty"` // Additional metadata
}
ContentPart represents a single content part in a multimodal mock response. This mirrors the structure of types.ContentPart but with YAML-friendly field names.
func (*ContentPart) ToContentPart ¶ added in v1.1.3
func (m *ContentPart) ToContentPart() *types.ContentPart
ToContentPart converts a ContentPart to types.ContentPart.
type DocumentURL ¶ added in v1.1.9
type DocumentURL struct {
URL string `yaml:"url"` // URL to the document file (can be mock://, http://, https://, data:, or file path)
}
DocumentURL represents document content in a mock response.
type FileMockRepository ¶
type FileMockRepository struct {
// contains filtered or unexported fields
}
FileMockRepository loads mock responses from a YAML configuration file. This is the default implementation for file-based mock configurations.
func NewFileMockRepository ¶
func NewFileMockRepository(configPath string) (*FileMockRepository, error)
NewFileMockRepository creates a repository that loads mock responses from a YAML file. The file should follow the Config structure with scenarios and turn-specific responses.
func (*FileMockRepository) BaseDir ¶ added in v1.4.7
func (r *FileMockRepository) BaseDir() string
BaseDir returns the directory of the mock config file. Relative paths referenced inside the config (e.g. audio_file fixtures) resolve against this directory.
func (*FileMockRepository) GetResponse ¶
func (r *FileMockRepository) GetResponse(ctx context.Context, params ResponseParams) (string, error)
GetResponse retrieves a mock response based on the provided parameters. It follows this priority order: 1. Scenario + Turn specific response 2. Scenario default response 3. Global default response 4. Generic fallback message
func (*FileMockRepository) GetTurn ¶
func (r *FileMockRepository) GetTurn(ctx context.Context, params ResponseParams) (*Turn, error)
GetTurn retrieves a structured mock turn response that may include tool calls. This method supports both backward-compatible string responses and new structured Turn responses.
For selfplay user turns (when ArenaRole == "self_play_user"), it looks up responses from the selfplay section using PersonaID. For regular turns, it uses scenario responses.
type ImageURL ¶ added in v1.1.3
type ImageURL struct {
URL string `yaml:"url"` // URL to the image (can be mock://, http://, https://, data:, or file path)
Detail *string `yaml:"detail,omitempty"` // Detail level: "low", "high", "auto"
}
ImageURL represents image content in a mock response.
type InMemoryMockRepository ¶
type InMemoryMockRepository struct {
// contains filtered or unexported fields
}
InMemoryMockRepository stores mock responses in memory. This is useful for testing and programmatic configuration without files.
func NewInMemoryMockRepository ¶
func NewInMemoryMockRepository(defaultResponse string) *InMemoryMockRepository
NewInMemoryMockRepository creates an in-memory repository with a default response.
func (*InMemoryMockRepository) GetResponse ¶
func (r *InMemoryMockRepository) GetResponse(ctx context.Context, params ResponseParams) (string, error)
GetResponse retrieves a mock response based on the provided parameters.
func (*InMemoryMockRepository) GetTurn ¶
func (r *InMemoryMockRepository) GetTurn(ctx context.Context, params ResponseParams) (*Turn, error)
GetTurn retrieves a structured mock turn response. InMemoryMockRepository currently only supports simple text responses.
func (*InMemoryMockRepository) SetResponse ¶
func (r *InMemoryMockRepository) SetResponse(scenarioID string, turnNumber int, response string)
SetResponse sets a mock response for a specific scenario and turn. Use turnNumber = 0 for scenario default, or -1 for global default.
type MockStreamSession ¶ added in v1.1.6
type MockStreamSession struct {
// BargeInSignal satisfies StreamInputSession.BargeIn(); tests can drive it
// via the promoted SignalBargeIn() to simulate server-side barge-in.
providers.BargeInSignal
// contains filtered or unexported fields
}
MockStreamSession implements providers.StreamInputSession for testing duplex scenarios.
func NewMockStreamSession ¶ added in v1.1.6
func NewMockStreamSession() *MockStreamSession
NewMockStreamSession creates a new mock stream session.
func (*MockStreamSession) Close ¶ added in v1.1.6
func (m *MockStreamSession) Close() error
Close implements StreamInputSession.Close.
func (*MockStreamSession) Done ¶ added in v1.1.6
func (m *MockStreamSession) Done() <-chan struct{}
Done implements StreamInputSession.Done.
func (*MockStreamSession) EmitChunk ¶ added in v1.1.6
func (m *MockStreamSession) EmitChunk(chunk *providers.StreamChunk)
EmitChunk sends a response chunk (for testing).
func (*MockStreamSession) EndInput ¶ added in v1.1.6
func (m *MockStreamSession) EndInput()
EndInput signals the end of input for the current turn. For mock sessions with auto-respond enabled, this triggers the response.
func (*MockStreamSession) Error ¶ added in v1.1.6
func (m *MockStreamSession) Error() error
Error implements StreamInputSession.Error.
func (*MockStreamSession) GetChunks ¶ added in v1.1.6
func (m *MockStreamSession) GetChunks() []*types.MediaChunk
GetChunks returns all received media chunks (for testing).
func (*MockStreamSession) GetTexts ¶ added in v1.1.6
func (m *MockStreamSession) GetTexts() []string
GetTexts returns all received text messages (for testing).
func (*MockStreamSession) ReceivedToolResponses ¶ added in v1.4.11
func (m *MockStreamSession) ReceivedToolResponses() []providers.ToolResponse
ReceivedToolResponses returns a snapshot of every tool response the session has received via SendToolResponse/SendToolResponses. Tests use this to verify the runtime sent back the expected payload for a scripted tool_call.
func (*MockStreamSession) Response ¶ added in v1.1.6
func (m *MockStreamSession) Response() <-chan providers.StreamChunk
Response implements StreamInputSession.Response.
func (*MockStreamSession) SendChunk ¶ added in v1.1.6
func (m *MockStreamSession) SendChunk(ctx context.Context, chunk *types.MediaChunk) error
SendChunk implements StreamInputSession.SendChunk.
Validates PCM16 alignment (even byte count) so tests catch upstream chunking bugs before they reach a real provider. We learned this the hard way — OpenAI Realtime rejected partial chunks from a buggy pumpTTSChunks with a cryptic "Invalid 'audio'... got an invalid value" that took a full bisection against the live API to track down. The mock should fail loudly on the same input shape so a unit test would have caught it.
func (*MockStreamSession) SendSystemContext ¶ added in v1.1.6
func (m *MockStreamSession) SendSystemContext(ctx context.Context, text string) error
SendSystemContext implements StreamInputSession.SendSystemContext. Unlike SendText, this does NOT trigger a response from the model.
func (*MockStreamSession) SendText ¶ added in v1.1.6
func (m *MockStreamSession) SendText(ctx context.Context, text string) error
SendText implements StreamInputSession.SendText.
func (*MockStreamSession) SendToolResponse ¶ added in v1.4.11
func (m *MockStreamSession) SendToolResponse(ctx context.Context, toolCallID, result string) error
SendToolResponse records a single tool result on the mock session and triggers the next scripted turn so the conversation can advance.
Real streaming providers (OpenAI Realtime, Gemini Live) handle tool responses by sending a `function_call_output` event followed by a `response.create` trigger that wakes the model up to produce its continuation. The mock equivalent is: store the response for test introspection, then call emitAutoResponse.
Note: this delegates to the batch method intentionally. Real providers send two separate websocket events per single-response call (one item + one response.create) — assertion-wise a tester observing the mock can't tell the difference, but a future contributor reading just this function should know it's not a behavioral divergence.
Scripted-turn convention: emitAutoResponse increments responseCount, so a tool-result continuation occupies its OWN slot in the scenario's scripted-turn space (different from real providers where the tool continuation extends the original agent turn). Scenarios that script tool flows against the mock should treat each tool round-trip as a discrete scripted entry: e.g. turn 1 = agent emits text+tool_call, turn 2 = agent's continuation after the tool result, turn 3 = agent's response to the next user turn.
func (*MockStreamSession) SendToolResponses ¶ added in v1.4.11
func (m *MockStreamSession) SendToolResponses(_ context.Context, responses []providers.ToolResponse) error
SendToolResponses records a batch of tool results and triggers a single continuation. Parallel tool calls in one agent turn produce one batch; the mock collapses them into a single emit just like the real providers do (one `response.create` after all function_call_output items have been queued).
func (*MockStreamSession) WithAutoRespond ¶ added in v1.1.6
func (m *MockStreamSession) WithAutoRespond(text string) *MockStreamSession
WithAutoRespond configures the session to automatically respond to inputs. The session stays open to handle multiple turns - call Close() when done.
func (*MockStreamSession) WithCloseAfterResponse ¶ added in v1.1.6
func (m *MockStreamSession) WithCloseAfterResponse(closeAfter bool) *MockStreamSession
WithCloseAfterResponse configures whether to close the response channel after auto-responding.
func (*MockStreamSession) WithCloseAfterTurns ¶ added in v1.1.6
func (m *MockStreamSession) WithCloseAfterTurns(turns int, noResponse ...bool) *MockStreamSession
WithCloseAfterTurns configures the session to close unexpectedly after N turns. This simulates Gemini dropping the connection mid-conversation. If noResponse is true, the session closes WITHOUT sending the final response (mimics Gemini closing after interrupted turnComplete).
func (*MockStreamSession) WithError ¶ added in v1.1.6
func (m *MockStreamSession) WithError(err error) *MockStreamSession
WithError sets the error returned by Error().
func (*MockStreamSession) WithInterruptOnTurn ¶ added in v1.1.6
func (m *MockStreamSession) WithInterruptOnTurn(turnNumber int) *MockStreamSession
WithInterruptOnTurn configures the session to simulate an interruption on a specific turn. This mimics Gemini detecting user speech while the model is responding. The turn is 1-indexed (first turn = 1).
func (*MockStreamSession) WithRepository ¶ added in v1.4.7
func (m *MockStreamSession) WithRepository(repo ResponseRepository, baseDir string) *MockStreamSession
WithRepository wires a ResponseRepository into the auto-respond path so that per-turn responses (including optional audio fixtures) come from the same scenario configuration used by the non-streaming mock provider. baseDir is the directory used to resolve relative audio_file paths; pass an empty string to use absolute paths only.
func (*MockStreamSession) WithResponseChunks ¶ added in v1.1.6
func (m *MockStreamSession) WithResponseChunks(chunks []providers.StreamChunk) *MockStreamSession
WithResponseChunks configures custom response chunks to emit.
func (*MockStreamSession) WithScenarioID ¶ added in v1.4.7
func (m *MockStreamSession) WithScenarioID(scenarioID string) *MockStreamSession
WithScenarioID selects which scenario the auto-respond path should consult when looking up turns from the repository. Without a scenario ID the session falls back to the static responseText.
func (*MockStreamSession) WithSendChunkError ¶ added in v1.1.6
func (m *MockStreamSession) WithSendChunkError(err error) *MockStreamSession
WithSendChunkError configures SendChunk to return an error.
func (*MockStreamSession) WithSendTextError ¶ added in v1.1.6
func (m *MockStreamSession) WithSendTextError(err error) *MockStreamSession
WithSendTextError configures SendText to return an error.
type Provider ¶ added in v1.1.3
type Provider struct {
*base.Implementation
// contains filtered or unexported fields
}
Provider is a provider implementation for testing and development. It returns mock responses without making any API calls, using a repository pattern to source responses from various backends (files, memory, databases).
Provider is designed to be reusable across different contexts:
- Arena testing: scenario and turn-specific responses
- SDK examples: simple deterministic responses
- Unit tests: programmatic response configuration
func NewProvider ¶ added in v1.1.3
NewProvider creates a new mock provider with default in-memory responses. This constructor maintains backward compatibility with existing code.
func NewProviderWithRepository ¶ added in v1.1.3
func NewProviderWithRepository(id, model string, includeRawOutput bool, repo ResponseRepository) *Provider
NewProviderWithRepository creates a mock provider with a custom response repository. This allows for advanced scenarios like file-based or database-backed mock responses.
func (*Provider) CalculateCost ¶ added in v1.1.3
CalculateCost calculates cost breakdown for given token counts.
func (*Provider) Close ¶ added in v1.1.3
Close is a no-op for the mock provider. NOSONAR: Intentionally empty - mock provider has no resources to clean up
func (*Provider) Predict ¶ added in v1.1.3
func (m *Provider) Predict(ctx context.Context, req providers.PredictionRequest) (providers.PredictionResponse, error)
Predict returns a mock response using the configured repository.
func (*Provider) PredictStream ¶ added in v1.1.3
func (m *Provider) PredictStream(ctx context.Context, req providers.PredictionRequest) (<-chan providers.StreamChunk, error)
PredictStream returns a mock streaming response using the configured repository.
func (*Provider) ShouldIncludeRawOutput ¶ added in v1.1.3
ShouldIncludeRawOutput returns whether raw API responses should be included.
func (*Provider) SupportsStreaming ¶ added in v1.1.3
SupportsStreaming indicates whether the provider supports streaming.
type ResponseParams ¶ added in v1.1.3
type ResponseParams struct {
ScenarioID string // Optional: ID of the scenario being executed
TurnNumber int // Optional: Turn number in a multi-turn conversation
ProviderID string // Optional: ID of the provider being mocked
ModelName string // Optional: Model name being mocked
PersonaID string // Optional: ID of the persona for selfplay user responses
ArenaRole string // Optional: Role in arena (e.g., "self_play_user")
StepID string // Optional: Composition step ID for per-step mock responses
}
ResponseParams contains parameters for looking up mock responses. Different implementations may use different subsets of these fields.
type ResponseRepository ¶ added in v1.1.3
type ResponseRepository interface {
// GetResponse retrieves a mock response for the given context.
// Parameters can include scenario ID, turn number, provider ID, etc.
// Returns the response text and any error encountered.
GetResponse(ctx context.Context, params ResponseParams) (string, error)
// GetTurn retrieves a mock turn response that may include tool calls.
// This extends GetResponse to support structured turn data with tool call simulation.
GetTurn(ctx context.Context, params ResponseParams) (*Turn, error)
}
ResponseRepository provides an interface for retrieving mock responses. This abstraction allows mock data to come from various sources (files, databases, etc.) and makes MockProvider reusable across different contexts (Arena, SDK examples, unit tests).
type ScenarioConfig ¶ added in v1.1.3
type ScenarioConfig struct {
// Default response for this scenario (overrides global default)
DefaultResponse string `yaml:"defaultResponse,omitempty"`
// Turn-specific responses keyed by turn number (1-indexed)
// Supports both simple string responses (backward compatibility) and structured Turn responses
Turns map[int]interface{} `yaml:"turns,omitempty"`
// Step-specific responses keyed by composition step ID.
// When ResponseParams.StepID is set and matches a key here, this entry is
// returned ahead of any turn-number lookup. Supports the same string or
// structured Turn formats as Turns entries.
Steps map[string]interface{} `yaml:"steps,omitempty"`
}
ScenarioConfig defines mock responses for a specific scenario.
type StreamingProvider ¶ added in v1.1.6
type StreamingProvider struct {
*Provider
// contains filtered or unexported fields
}
StreamingProvider extends Provider with StreamInputSupport for duplex testing.
func NewStreamingProvider ¶ added in v1.1.6
func NewStreamingProvider(id, model string, includeRawOutput bool) *StreamingProvider
NewStreamingProvider creates a mock provider with duplex streaming support.
func NewStreamingProviderWithRepository ¶ added in v1.1.6
func NewStreamingProviderWithRepository( id, model string, includeRawOutput bool, repo ResponseRepository, ) *StreamingProvider
NewStreamingProviderWithRepository creates a mock streaming provider with a custom repository.
func (*StreamingProvider) CreateStreamSession ¶ added in v1.1.6
func (p *StreamingProvider) CreateStreamSession( ctx context.Context, req *providers.StreamingInputConfig, ) (providers.StreamInputSession, error)
CreateStreamSession implements StreamInputSupport.CreateStreamSession.
func (*StreamingProvider) GetSession ¶ added in v1.1.6
func (p *StreamingProvider) GetSession() *MockStreamSession
GetSession returns the first/most recent mock session for testing access to sent chunks/texts. For multiple sessions, use GetSessions() instead.
func (*StreamingProvider) GetSessions ¶ added in v1.1.6
func (p *StreamingProvider) GetSessions() []*MockStreamSession
GetSessions returns all created sessions for testing.
func (*StreamingProvider) GetStreamingCapabilities ¶ added in v1.1.6
func (p *StreamingProvider) GetStreamingCapabilities() providers.StreamingCapabilities
GetStreamingCapabilities implements StreamInputSupport.GetStreamingCapabilities.
func (*StreamingProvider) SupportsStreamInput ¶ added in v1.1.6
func (p *StreamingProvider) SupportsStreamInput() []string
SupportsStreamInput implements StreamInputSupport.SupportsStreamInput.
func (*StreamingProvider) WithAutoRespond ¶ added in v1.1.6
func (p *StreamingProvider) WithAutoRespond(responseText string) *StreamingProvider
WithAutoRespond configures the provider to create sessions that auto-respond to inputs.
func (*StreamingProvider) WithCloseAfterTurns ¶ added in v1.1.6
func (p *StreamingProvider) WithCloseAfterTurns(turns int, noResponse ...bool) *StreamingProvider
WithCloseAfterTurns configures the provider to create sessions that close unexpectedly after N turns. This simulates Gemini dropping the connection. If noResponse is true, the session closes WITHOUT sending the final response.
func (*StreamingProvider) WithCreateSessionError ¶ added in v1.1.6
func (p *StreamingProvider) WithCreateSessionError(err error) *StreamingProvider
WithCreateSessionError configures CreateStreamSession to return an error.
func (*StreamingProvider) WithInterruptOnTurn ¶ added in v1.1.6
func (p *StreamingProvider) WithInterruptOnTurn(turnNumber int) *StreamingProvider
WithInterruptOnTurn configures the provider to create sessions that simulate an interruption on a specific turn. This mimics Gemini detecting user speech while the model is responding.
func (*StreamingProvider) WithMockResponses ¶ added in v1.4.7
func (p *StreamingProvider) WithMockResponses( repo ResponseRepository, scenarioID, fixtureBaseDir string, ) *StreamingProvider
WithMockResponses wires a ResponseRepository, default scenario ID and fixture base directory into every session created by this provider. When auto-respond is enabled, sessions will look up per-turn Turn responses (including audio_file fixtures) from the repository instead of emitting the static responseText.
scenarioID may be overridden per session via the StreamingInputConfig metadata key "mock_scenario_id".
func (*StreamingProvider) WithResponseChunks ¶ added in v1.5.4
func (p *StreamingProvider) WithResponseChunks(chunks ...providers.StreamChunk) *StreamingProvider
WithResponseChunks configures the provider so each created session emits the given StreamChunks on input (instead of auto-respond text). Useful for driving the duplex stage with specific chunks such as reasoning deltas.
type ToolCall ¶ added in v1.1.3
type ToolCall struct {
Name string `yaml:"name"` // Name of the tool to call
Arguments map[string]interface{} `yaml:"arguments"` // Arguments to pass to the tool
}
ToolCall represents a simulated tool call from the LLM.
type ToolProvider ¶ added in v1.1.3
type ToolProvider struct {
*StreamingProvider
}
ToolProvider extends MockProvider to support tool/function calling and duplex streaming. It implements the ToolSupport interface to enable tool call simulation while maintaining compatibility with the existing MockProvider API. By embedding StreamingProvider, it also supports StreamInputSupport for duplex scenarios.
func NewToolProvider ¶ added in v1.1.3
func NewToolProvider(id, model string, includeRawOutput bool, additionalConfig map[string]any) *ToolProvider
NewToolProvider creates a new mock provider with tool support and duplex streaming. This uses default in-memory responses for backward compatibility.
func NewToolProviderWithRepository ¶ added in v1.1.3
func NewToolProviderWithRepository(id, model string, includeRawOutput bool, repo ResponseRepository) *ToolProvider
NewToolProviderWithRepository creates a mock provider with tool support and duplex streaming using a custom response repository for advanced scenarios.
func (*ToolProvider) BuildTooling ¶ added in v1.1.3
func (m *ToolProvider) BuildTooling(descriptors []*providers.ToolDescriptor) (providers.ProviderTools, error)
BuildTooling implements the ToolSupport interface. For mock providers, we just return the tools as-is since we don't need to transform them into a provider-specific format.
func (*ToolProvider) PredictStreamWithTools ¶ added in v1.1.5
func (m *ToolProvider) PredictStreamWithTools( ctx context.Context, req providers.PredictionRequest, tools interface{}, toolChoice string, ) (<-chan providers.StreamChunk, error)
PredictStreamWithTools performs a streaming predict request with tool support. For mock providers, this delegates to PredictWithTools and wraps the response in chunks.
func (*ToolProvider) PredictWithTools ¶ added in v1.1.3
func (m *ToolProvider) PredictWithTools( ctx context.Context, req providers.PredictionRequest, tools providers.ProviderTools, toolChoice string, ) (providers.PredictionResponse, []types.MessageToolCall, error)
PredictWithTools implements the ToolSupport interface. This method handles the initial predict request with tools available, potentially returning tool calls based on the mock configuration.
type Turn ¶ added in v1.1.3
type Turn struct {
Type string `yaml:"type"` // "text", "tool_calls", or "multimodal"
Content string `yaml:"content,omitempty"` // Text content for the response
Parts []ContentPart `yaml:"parts,omitempty"` // Multimodal content parts (text, image, audio, video)
ToolCalls []ToolCall `yaml:"tool_calls,omitempty"` // Tool calls to simulate
// AudioFile is an optional path to a raw PCM audio file (signed 16-bit little-endian, mono).
// When set on a duplex auto-respond turn, the mock streaming provider will emit the file's
// contents as MediaData chunks alongside the text response. The path is resolved relative
// to the directory of the mock-responses.yaml file (when loaded via FileMockRepository).
AudioFile string `yaml:"audio_file,omitempty"`
// AudioSampleRate is the sample rate of the AudioFile in Hz. Defaults to 24000 when zero.
AudioSampleRate int `yaml:"audio_sample_rate,omitempty"`
// AudioMIMEType is the MIME type advertised on emitted audio chunks. Defaults to "audio/pcm".
AudioMIMEType string `yaml:"audio_mime_type,omitempty"`
}
Turn represents a structured mock response that may include tool calls and multimodal content. This extends simple text responses to support tool call simulation and multimodal content parts.
func (*Turn) ToContentParts ¶ added in v1.1.3
func (t *Turn) ToContentParts() []types.ContentPart
ToContentParts converts Turn to a slice of types.ContentPart. This handles both legacy text-only responses and new multimodal responses.