Documentation
¶
Overview ¶
Package fake provides a VCR-based proxy for replaying recorded AI API responses. This is useful for E2E testing without making real API calls.
Index ¶
- func APIKeyHeaderUpdater(host string, req *http.Request)
- func CustomMatcher(onError func(err error)) recorder.MatcherFunc
- func Handle(transport http.RoundTripper, ...) echo.HandlerFunc
- func IsStreamResponse(resp *http.Response) bool
- func RemoveHeadersHook(i *cassette.Interaction) error
- func StartProxy(cassettePath string) (string, func() error, error)
- func StartProxyWithOptions(cassettePath string, mode recorder.Mode, matcher recorder.MatcherFunc, ...) (string, func() error, error)
- func StartRecordingProxy(cassettePath string) (string, func() error, error)
- func StreamCopy(c echo.Context, resp *http.Response) error
- func TargetURLForHost(host string) func(req *http.Request) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APIKeyHeaderUpdater ¶ added in v1.15.2
APIKeyHeaderUpdater injects API keys from environment variables into request headers. This is used when recording API interactions to ensure real API calls succeed.
func CustomMatcher ¶
func CustomMatcher(onError func(err error)) recorder.MatcherFunc
CustomMatcher creates a matcher that normalizes tool call IDs for consistent matching. The onError callback is called if reading the request body fails (nil logs and returns false).
func Handle ¶
func Handle(transport http.RoundTripper, headerUpdater func(host string, req *http.Request)) echo.HandlerFunc
Handle creates an echo handler that proxies requests through the VCR transport. The headerUpdater is called with the host and request to update headers (e.g., for adding API keys).
func IsStreamResponse ¶
IsStreamResponse checks if the response should be streamed.
func RemoveHeadersHook ¶
func RemoveHeadersHook(i *cassette.Interaction) error
RemoveHeadersHook strips headers from recorded interactions for security.
func StartProxy ¶
StartProxy starts an internal HTTP proxy that replays cassette responses. It returns the proxy URL and a cleanup function that should be called when done.
func StartProxyWithOptions ¶
func StartProxyWithOptions( cassettePath string, mode recorder.Mode, matcher recorder.MatcherFunc, headerUpdater func(host string, req *http.Request), ) (string, func() error, error)
StartProxyWithOptions starts an internal HTTP proxy with configurable options. - mode: recorder mode (ModeReplayOnly, ModeRecordOnce, etc.) - matcher: custom matcher function (nil uses default CustomMatcher) - headerUpdater: optional function to update request headers (for recording with real API keys)
func StartRecordingProxy ¶ added in v1.15.2
StartRecordingProxy starts a proxy that records AI API interactions to a cassette file. It injects API keys from environment variables for the actual API calls. The recorded cassette can later be replayed using StartProxy.
func StreamCopy ¶
StreamCopy copies a streaming response to the client.
Types ¶
This section is empty.