Files
netbird/proxy/internal/middleware/builtin/llm_response_parser/factory.go
T
mlsmaycon 6ade3839aa [proxy] LLM parsers, pricing, and builtin middlewares (OpenAI, Anthropic, Vertex AI, AWS Bedrock)
Request/response parsers and SSE/event-stream metering, the embedded pricing
table, and the builtin middleware set: request parser, router, policy
limit-check/record, cost meter, guardrail, identity inject, response parser.
Includes the path-routed providers — Google Vertex AI (keyfile:: service-account
OAuth minting) and AWS Bedrock (bearer auth, invoke/converse/streaming, optional
/bedrock prefix) — plus the Models allowlist and unmeterable-publisher deny.
2026-06-27 00:43:35 +02:00

44 lines
1.1 KiB
Go

package llm_response_parser
import (
"bytes"
"encoding/json"
"fmt"
"github.com/netbirdio/netbird/proxy/internal/middleware"
"github.com/netbirdio/netbird/proxy/internal/middleware/builtin"
)
// Factory constructs configured Middleware instances for the registry.
type Factory struct{}
// ID returns the registry identifier.
func (Factory) ID() string { return ID }
// New decodes RawConfig (empty / null / "{}" all accepted) and returns
// a configured Middleware. Construction never fails on a well-formed
// empty config; only structurally invalid JSON is rejected.
func (Factory) New(rawConfig []byte) (middleware.Middleware, error) {
cfg, err := decodeConfig(rawConfig)
if err != nil {
return nil, fmt.Errorf("decode config: %w", err)
}
return New(cfg), nil
}
func decodeConfig(raw []byte) (config, error) {
trimmed := bytes.TrimSpace(raw)
if len(trimmed) == 0 || bytes.Equal(trimmed, []byte("null")) {
return config{}, nil
}
var cfg config
if err := json.Unmarshal(trimmed, &cfg); err != nil {
return config{}, err
}
return cfg, nil
}
func init() {
builtin.Register(Factory{})
}