Documentation
¶
Index ¶
- Constants
- Variables
- func AuthenticateKey(snap *snapshot.Snapshot, rawKey string) (snapshot.APIKey, error)
- func CopyResponse(w http.ResponseWriter, resp *http.Response) error
- func HeadersForPolicy(h http.Header) map[string]string
- func ParseAFITags(header string) map[string]string
- func TagsFromRequest(r *http.Request) map[string]string
- type AfterCallHook
- type AfterCallInfo
- type AfterChatHook
- type AfterChatInfo
- type AnthropicTransport
- type AnthropicTransportProvider
- type AudioBackend
- type AudioTransportProvider
- type BeforeCallHook
- type BuiltinFactory
- type CallContext
- type CallDecision
- type ChatHook
- type ChatProvider
- type CompositeCounters
- type CounterStore
- type EmbeddingsBackend
- type Holder
- type HookChain
- func (c *HookChain) Infos() []HookInfo
- func (c *HookChain) Names() []string
- func (c *HookChain) PrependBeforeCall(h BeforeCallHook) *HookChain
- func (c *HookChain) Register(h ChatHook) *HookChain
- func (c *HookChain) RegisterAfter(h AfterChatHook) *HookChain
- func (c *HookChain) RegisterAfterCall(h AfterCallHook) *HookChain
- func (c *HookChain) RegisterBeforeCall(h BeforeCallHook) *HookChain
- func (c *HookChain) RegisterHook(h any) *HookChain
- func (c *HookChain) RunAfterCall(ctx context.Context, call *CallContext, info AfterCallInfo)
- func (c *HookChain) RunAfterChat(ctx context.Context, info AfterChatInfo)
- func (c *HookChain) RunBeforeCall(ctx context.Context, call *CallContext) (CallDecision, error)
- func (c *HookChain) RunBeforeChat(ctx context.Context, req ir.ChatRequest) (ir.ChatRequest, error)
- type HookInfo
- type IRChatProvider
- type ImagesBackend
- type MessagesBackend
- type OpenAITransport
- type OpenAITransportProvider
- type Pipeline
- type Principal
- type ProviderCaps
- type Registry
- func (r *Registry) AnthropicTransport(typ string) (AnthropicTransport, bool)
- func (r *Registry) AudioBackend(typ string) (AudioBackend, bool)
- func (r *Registry) EmbeddingsBackend(typ string) (EmbeddingsBackend, bool)
- func (r *Registry) Get(typ string) (ChatProvider, bool)
- func (r *Registry) ImagesBackend(typ string) (ImagesBackend, bool)
- func (r *Registry) MessagesBackend(typ string) (MessagesBackend, bool)
- func (r *Registry) OpenAITransport(typ string) (OpenAITransport, bool)
- func (r *Registry) Register(p ChatProvider) *Registry
- func (r *Registry) RegisterSDK(p sdkprovider.ChatProvider) *Registry
- func (r *Registry) Types() []string
- type ReplayStore
- type RouteContext
- type UsageEvent
- type WasmRunner
- func (r *WasmRunner) RunAfterCall(ctx context.Context, snap *snapshot.Snapshot, call *CallContext, ...)
- func (r *WasmRunner) RunBeforeCall(ctx context.Context, snap *snapshot.Snapshot, call *CallContext) (CallDecision, error)
- func (r *WasmRunner) RunBeforeChat(ctx context.Context, snap *snapshot.Snapshot, orgID string, req chatir.Request) (chatir.Request, error)
Constants ¶
const ( ModalityChat = "chat" ModalityMessages = "messages" ModalityGenerateContent = "generate_content" ModalityTTS = "tts" ModalitySTT = "stt" ModalityEmbedding = "embedding" ModalityImage = "image" ModalityMCP = "mcp" ModalityA2A = "a2a" )
const AFITagsHeader = "X-AFI-Tags"
AFITagsHeader is the request header for external user tags.
Variables ¶
var ErrStreamUnsupported = errors.New("streaming is not supported for this provider")
ErrStreamUnsupported is returned when the provider capabilities disallow streaming.
Functions ¶
func AuthenticateKey ¶
AuthenticateKey is exported for unit tests.
func CopyResponse ¶
func CopyResponse(w http.ResponseWriter, resp *http.Response) error
CopyResponse copies an upstream response to the client writer.
func HeadersForPolicy ¶
HeadersForPolicy copies inbound headers for CEL as lowercased key → first value. Sensitive headers (authorization, cookie, set-cookie) are omitted.
func ParseAFITags ¶
ParseAFITags parses "key:value,key:value" tag headers. Pairs are comma-separated; each pair splits on the first ':'. Keys and values are trimmed; empty keys are skipped; last duplicate key wins.
Types ¶
type AfterCallHook ¶
type AfterCallHook = sdkhook.AfterCallHook
Re-export SDK hook types so existing extensions can keep importing dataplane.
type AfterCallInfo ¶
type AfterCallInfo = sdkhook.AfterCallInfo
Re-export SDK hook types so existing extensions can keep importing dataplane.
type AfterChatHook ¶
type AfterChatHook = sdkhook.AfterChatHook
Re-export SDK hook types so existing extensions can keep importing dataplane.
type AfterChatInfo ¶
type AfterChatInfo = sdkhook.AfterChatInfo
Re-export SDK hook types so existing extensions can keep importing dataplane.
type AnthropicTransport ¶
type AnthropicTransport interface {
PassThrough(ctx context.Context, provider snapshot.Provider, targetModel string, body []byte, stream bool) (*http.Response, error)
Messages(ctx context.Context, provider snapshot.Provider, targetModel string, body []byte, stream bool) (*http.Response, error)
}
AnthropicTransport is the outbound Anthropic HTTP surface used by chat + /v1/messages.
type AnthropicTransportProvider ¶
type AnthropicTransportProvider interface {
AnthropicTransport() AnthropicTransport
}
AnthropicTransportProvider is implemented by ChatProvider adapters that expose Anthropic HTTP.
type AudioBackend ¶
type AudioBackend interface {
AudioSpeech(ctx context.Context, provider snapshot.Provider, targetModel string, body []byte) (*http.Response, error)
AudioTranscriptions(ctx context.Context, provider snapshot.Provider, targetModel, contentType string, body io.Reader) (*http.Response, error)
}
AudioBackend is the modality port for TTS/STT.
type AudioTransportProvider ¶
type AudioTransportProvider interface {
AudioBackend() AudioBackend
}
AudioTransportProvider is implemented by ChatProvider adapters that expose TTS/STT without a full OpenAI transport (e.g. elevenlabs).
type BeforeCallHook ¶
type BeforeCallHook = sdkhook.BeforeCallHook
Re-export SDK hook types so existing extensions can keep importing dataplane.
type BuiltinFactory ¶
type BuiltinFactory func(sec secrets.Resolver) ChatProvider
BuiltinFactory builds a ChatProvider from a secret resolver.
type CallContext ¶
type CallContext = sdkhook.CallContext
Re-export SDK hook types so existing extensions can keep importing dataplane.
type CallDecision ¶
type CallDecision = sdkhook.CallDecision
Re-export SDK hook types so existing extensions can keep importing dataplane.
type ChatProvider ¶
type ChatProvider interface {
Type() string
Capabilities() ProviderCaps
Chat(ctx context.Context, p snapshot.Provider, targetModel string, body []byte, stream bool) (*http.Response, error)
}
ChatProvider is the in-process adapter contract for gateway chat HTTP transport.
type CompositeCounters ¶
type CompositeCounters struct {
Total CounterStore // Postgres (window=total)
Timed CounterStore // Redis (minute/hour/day)
}
CompositeCounters routes lifetime quotas to Postgres and timed windows to Redis.
type CounterStore ¶
type CounterStore interface {
Get(ctx context.Context, scopeType, scopeID, metric, window string) (int64, error)
Incr(ctx context.Context, scopeType, scopeID, metric, window string, delta int64) (int64, error)
}
CounterStore reads/writes durable quota counters (not config).
type EmbeddingsBackend ¶
type EmbeddingsBackend interface {
Embeddings(ctx context.Context, provider snapshot.Provider, targetModel string, body []byte) (*http.Response, error)
}
EmbeddingsBackend is the modality port for /v1/embeddings (OpenAI-compatible).
type Holder ¶
type Holder struct {
// contains filtered or unexported fields
}
Holder keeps the current immutable snapshot for the request path.
type HookChain ¶
type HookChain struct {
// contains filtered or unexported fields
}
HookChain runs BeforeCall / AfterCall / BeforeChat / AfterChat hooks in registration order.
func NewHookChain ¶
func NewHookChain() *HookChain
func (*HookChain) PrependBeforeCall ¶
func (c *HookChain) PrependBeforeCall(h BeforeCallHook) *HookChain
PrependBeforeCall inserts a BeforeCall hook at the front of the chain.
func (*HookChain) RegisterAfter ¶
func (c *HookChain) RegisterAfter(h AfterChatHook) *HookChain
RegisterAfter adds an AfterChat hook.
func (*HookChain) RegisterAfterCall ¶
func (c *HookChain) RegisterAfterCall(h AfterCallHook) *HookChain
RegisterAfterCall adds an AfterCall hook.
func (*HookChain) RegisterBeforeCall ¶
func (c *HookChain) RegisterBeforeCall(h BeforeCallHook) *HookChain
RegisterBeforeCall adds a BeforeCall hook (appended; runs after earlier entries).
func (*HookChain) RegisterHook ¶
RegisterHook registers a value that may implement any of the hook interfaces.
func (*HookChain) RunAfterCall ¶
func (c *HookChain) RunAfterCall(ctx context.Context, call *CallContext, info AfterCallInfo)
RunAfterCall runs AfterCall hooks (errors ignored).
func (*HookChain) RunAfterChat ¶
func (c *HookChain) RunAfterChat(ctx context.Context, info AfterChatInfo)
func (*HookChain) RunBeforeCall ¶
func (c *HookChain) RunBeforeCall(ctx context.Context, call *CallContext) (CallDecision, error)
RunBeforeCall runs BeforeCall hooks. First deny wins. Mutates call in place.
func (*HookChain) RunBeforeChat ¶
func (c *HookChain) RunBeforeChat(ctx context.Context, req ir.ChatRequest) (ir.ChatRequest, error)
RunBeforeChat runs typed chat hooks in registration order.
type HookInfo ¶
type HookInfo struct {
Name string `json:"name"`
BeforeCall bool `json:"before_call"`
AfterCall bool `json:"after_call"`
BeforeChat bool `json:"before_chat"`
AfterChat bool `json:"after_chat"`
}
HookInfo describes a registered hook for healthz / UI.
type IRChatProvider ¶
type IRChatProvider interface {
ChatIR(ctx context.Context, p snapshot.Provider, targetModel string, req ir.ChatRequest) (ir.ChatResult, error)
}
IRChatProvider is implemented by built-in adapters that speak chat IR.
type ImagesBackend ¶
type ImagesBackend interface {
Images(ctx context.Context, provider snapshot.Provider, targetModel string, body []byte) (*http.Response, error)
}
ImagesBackend is the modality port for /v1/images/generations (OpenAI-compatible).
type MessagesBackend ¶
type MessagesBackend interface {
PassThrough(ctx context.Context, provider snapshot.Provider, targetModel string, body []byte, stream bool) (*http.Response, error)
}
MessagesBackend is retained for Anthropic transport PassThrough (used by ChatIR). Client Anthropic dialect traffic goes through chat IR, not this port directly.
type OpenAITransport ¶
type OpenAITransport interface {
ChatCompletions(ctx context.Context, provider snapshot.Provider, targetModel string, body []byte, stream bool) (*http.Response, error)
AudioSpeech(ctx context.Context, provider snapshot.Provider, targetModel string, body []byte) (*http.Response, error)
AudioTranscriptions(ctx context.Context, provider snapshot.Provider, targetModel, contentType string, body io.Reader) (*http.Response, error)
Embeddings(ctx context.Context, provider snapshot.Provider, targetModel string, body []byte) (*http.Response, error)
Images(ctx context.Context, provider snapshot.Provider, targetModel string, body []byte) (*http.Response, error)
}
OpenAITransport is the outbound OpenAI-compatible HTTP surface used by chat + audio + embeddings + images.
type OpenAITransportProvider ¶
type OpenAITransportProvider interface {
OpenAITransport() OpenAITransport
}
OpenAITransportProvider is implemented by ChatProvider adapters that expose OpenAI HTTP.
type Pipeline ¶
type Pipeline struct {
Holder *Holder
Providers *Registry
Hooks *HookChain
Wasm *WasmRunner
Log *slog.Logger
Usage func(UsageEvent)
Counters CounterStore
Policies *policy.Evaluator
Credentials secrets.CredentialOpener
Secrets secrets.Resolver
HTTP *http.Client
Replay ReplayStore
Metrics *telemetry.GatewayMetrics
// RouteRand optional RNG for weighted routing (tests); nil uses math/rand global.
RouteRand *rand.Rand
// RouteSignals optional gateway-local EWMA store for latency/cost adaptive routing.
RouteSignals routing.SignalStore
}
func NewPipeline ¶
NewPipeline builds a pipeline with an explicit provider registry. Built-in LLM adapters are registered from cmd/gateway via adapters/llm.
func NewPipelineWithRegistry ¶
NewPipelineWithRegistry uses an explicit provider registry.
type ProviderCaps ¶
ProviderCaps mirrors snapshot capabilities for adapters.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps provider type strings to ChatProvider implementations.
func DefaultRegistry ¶
func DefaultRegistry() *Registry
DefaultRegistry registers all in-tree adapters via registerBuiltin factories.
func NewRegistry ¶
func NewRegistry() *Registry
func RegistryWithOpenAI ¶
func RegistryWithOpenAI(openai *llm.OpenAIClient) *Registry
RegistryWithOpenAI builds DefaultRegistry but uses the given OpenAI client for type "openai" (tests inject mock HTTP transports).
func RegistryWithSecrets ¶
RegistryWithSecrets builds the builtin registry with a custom secret resolver.
func (*Registry) AnthropicTransport ¶
func (r *Registry) AnthropicTransport(typ string) (AnthropicTransport, bool)
AnthropicTransport looks up an Anthropic transport by provider type.
func (*Registry) AudioBackend ¶
func (r *Registry) AudioBackend(typ string) (AudioBackend, bool)
AudioBackend returns the TTS/STT port for a provider type.
func (*Registry) EmbeddingsBackend ¶
func (r *Registry) EmbeddingsBackend(typ string) (EmbeddingsBackend, bool)
EmbeddingsBackend returns the /v1/embeddings port for a provider type (OpenAI-compatible only).
func (*Registry) ImagesBackend ¶
func (r *Registry) ImagesBackend(typ string) (ImagesBackend, bool)
ImagesBackend returns the /v1/images/generations port for a provider type (OpenAI-compatible only).
func (*Registry) MessagesBackend ¶
func (r *Registry) MessagesBackend(typ string) (MessagesBackend, bool)
MessagesBackend returns the native /v1/messages port for a provider type.
func (*Registry) OpenAITransport ¶
func (r *Registry) OpenAITransport(typ string) (OpenAITransport, bool)
OpenAITransport looks up an OpenAI-compatible transport by provider type.
func (*Registry) Register ¶
func (r *Registry) Register(p ChatProvider) *Registry
func (*Registry) RegisterSDK ¶
func (r *Registry) RegisterSDK(p sdkprovider.ChatProvider) *Registry
RegisterSDK wraps an SDK ChatProvider into the gateway registry.
type ReplayStore ¶ added in v0.3.0
type RouteContext ¶
type RouteContext = sdkhook.RouteContext
Re-export SDK hook types so existing extensions can keep importing dataplane.
type UsageEvent ¶
UsageEvent is an alias for the canonical usage.Event emitted on the request path.
type WasmRunner ¶
type WasmRunner struct {
Cache *afiWasm.ModuleCache
Log *slog.Logger
}
WasmRunner executes org-scoped snapshot WASM bindings via a module cache.
func (*WasmRunner) RunAfterCall ¶
func (r *WasmRunner) RunAfterCall(ctx context.Context, snap *snapshot.Snapshot, call *CallContext, info AfterCallInfo)
func (*WasmRunner) RunBeforeCall ¶
func (r *WasmRunner) RunBeforeCall(ctx context.Context, snap *snapshot.Snapshot, call *CallContext) (CallDecision, error)
Source Files
¶
- a2a.go
- audio.go
- auth_signed.go
- backends.go
- builtin_registry.go
- call_hooks.go
- chat_exec.go
- composite_counters.go
- embeddings.go
- headers.go
- hooks.go
- http_copy.go
- images.go
- mcp.go
- multipart_form.go
- observe.go
- pipeline.go
- provider.go
- quota.go
- register_builtins.go
- retry.go
- sdk_bridge.go
- snapshotholder.go
- tags.go
- wasm_bindings.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package dialect encodes/decodes client wire formats against chat IR.
|
Package dialect encodes/decodes client wire formats against chat IR. |
|
Package ir defines the gateway-owned chat internal representation.
|
Package ir defines the gateway-owned chat internal representation. |