Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/internal/testutil/automatic_function_calling.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func validateAutomaticToolCall(t *testing.T, toolCalls []ToolCallInfo, apiName s
// Validation for tool call already happened inside WithDualAPITestRetry
// If we reach here, the tool call was successful
// This function just provides additional logging for tool call details

for _, toolCall := range toolCalls {
if toolCall.Name == string(SampleToolTypeTime) {
t.Logf("✅ %s automatic function call: %s", apiName, toolCall.Arguments)
Expand Down
1 change: 0 additions & 1 deletion core/internal/testutil/complete_end_to_end.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"
"testing"


bifrost "github.com/maximhq/bifrost/core"
"github.com/maximhq/bifrost/core/schemas"
)
Expand Down
1 change: 0 additions & 1 deletion core/internal/testutil/embedding.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"
"testing"


bifrost "github.com/maximhq/bifrost/core"
"github.com/maximhq/bifrost/core/schemas"
)
Expand Down
1 change: 0 additions & 1 deletion core/internal/testutil/end_to_end_tool_calling.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"
"testing"


bifrost "github.com/maximhq/bifrost/core"
"github.com/maximhq/bifrost/core/schemas"
)
Expand Down
1 change: 0 additions & 1 deletion core/internal/testutil/image_base64.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"
"testing"


bifrost "github.com/maximhq/bifrost/core"
"github.com/maximhq/bifrost/core/schemas"
)
Expand Down
1 change: 0 additions & 1 deletion core/internal/testutil/image_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"
"testing"


bifrost "github.com/maximhq/bifrost/core"
"github.com/maximhq/bifrost/core/schemas"
)
Expand Down
1 change: 0 additions & 1 deletion core/internal/testutil/list_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"testing"


bifrost "github.com/maximhq/bifrost/core"
"github.com/maximhq/bifrost/core/schemas"
)
Expand Down
22 changes: 11 additions & 11 deletions core/internal/testutil/multi_turn_conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ func RunMultiTurnConversationTest(t *testing.T, client *bifrost.Bifrost, ctx con
expectations2.ShouldContainKeywords = []string{"alice"} // Case insensitive
expectations2.ShouldNotContainWords = []string{"don't know", "can't remember", "forgot"} // Memory failure indicators

response2, bifrostErr := WithChatTestRetry(t, chatRetryConfig2, retryContext2, expectations2, "MultiTurnConversation_Step2", func() (*schemas.BifrostChatResponse, *schemas.BifrostError) {
return client.ChatCompletionRequest(ctx, secondRequest)
})
response2, bifrostErr := WithChatTestRetry(t, chatRetryConfig2, retryContext2, expectations2, "MultiTurnConversation_Step2", func() (*schemas.BifrostChatResponse, *schemas.BifrostError) {
return client.ChatCompletionRequest(ctx, secondRequest)
})

if bifrostErr != nil {
t.Fatalf("❌ MultiTurnConversation_Step2 request failed after retries: %v", GetErrorMessage(bifrostErr))
}
if bifrostErr != nil {
t.Fatalf("❌ MultiTurnConversation_Step2 request failed after retries: %v", GetErrorMessage(bifrostErr))
}

// Validation already happened inside WithChatTestRetry via expectations2
// If we reach here, the model successfully remembered "Alice"
content := GetChatContent(response2)
t.Logf("✅ Model successfully remembered the name: %s", content)
t.Logf("✅ Multi-turn conversation completed successfully")
// Validation already happened inside WithChatTestRetry via expectations2
// If we reach here, the model successfully remembered "Alice"
content := GetChatContent(response2)
t.Logf("✅ Model successfully remembered the name: %s", content)
t.Logf("✅ Multi-turn conversation completed successfully")
})
}
1 change: 0 additions & 1 deletion core/internal/testutil/multiple_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"
"testing"


bifrost "github.com/maximhq/bifrost/core"
"github.com/maximhq/bifrost/core/schemas"
)
Expand Down
1 change: 0 additions & 1 deletion core/internal/testutil/multiple_tool_calls.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"testing"


bifrost "github.com/maximhq/bifrost/core"
"github.com/maximhq/bifrost/core/schemas"
)
Expand Down
1 change: 0 additions & 1 deletion core/internal/testutil/simple_chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"testing"


bifrost "github.com/maximhq/bifrost/core"
"github.com/maximhq/bifrost/core/schemas"
)
Expand Down
1 change: 0 additions & 1 deletion core/internal/testutil/text_completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"testing"


bifrost "github.com/maximhq/bifrost/core"
"github.com/maximhq/bifrost/core/schemas"
)
Expand Down
1 change: 0 additions & 1 deletion core/internal/testutil/text_completion_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"
"time"


bifrost "github.com/maximhq/bifrost/core"
"github.com/maximhq/bifrost/core/schemas"
)
Expand Down
1 change: 0 additions & 1 deletion core/internal/testutil/tool_calls.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"testing"


bifrost "github.com/maximhq/bifrost/core"
"github.com/maximhq/bifrost/core/schemas"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion core/providers/elevenlabs/speech.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ func ToElevenlabsSpeechRequest(bifrostReq *schemas.BifrostSpeechRequest) *Eleven
}

return elevenlabsReq
}
}
1 change: 0 additions & 1 deletion core/providers/openai/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,3 @@ func TestOpenAIChatRequest_UnmarshalJSON_ValueAssertions(t *testing.T) {
t.Errorf("Expected Stop value ['END', 'STOP'], got %v", req.Stop)
}
}

1 change: 0 additions & 1 deletion core/providers/utils/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,3 @@ func (h *SerialListHelper) HasMoreKeys() bool {
}
return currentKeyIndex < len(h.Keys)-1
}

1 change: 0 additions & 1 deletion core/schemas/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ func NewSerialCursor(keyIndex int, cursor string) *SerialCursor {
Cursor: cursor,
}
}

4 changes: 2 additions & 2 deletions framework/configstore/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type ConfigStoreType string

// ConfigStoreTypeSQLite is the type of config store for SQLite.
const (
ConfigStoreTypeSQLite ConfigStoreType = "sqlite"
ConfigStoreTypePostgres ConfigStoreType = "postgres"
ConfigStoreTypeSQLite ConfigStoreType = "sqlite"
ConfigStoreTypePostgres ConfigStoreType = "postgres"
)

// Config represents the configuration for the config store.
Expand Down
2 changes: 1 addition & 1 deletion framework/configstore/rdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ func (s *RDBConfigStore) GetProvidersConfig(ctx context.Context) (map[schemas.Mo
if processedARN, err := envutils.ProcessEnvValue(*bedrockConfig.ARN); err == nil {
bedrockConfigCopy.ARN = &processedARN
}
}
}
bedrockConfig = &bedrockConfigCopy
}

Expand Down
4 changes: 2 additions & 2 deletions framework/configstore/tables/budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ type TableBudget struct {
func (TableBudget) TableName() string { return "governance_budgets" }

// BeforeSave hook for Budget to validate reset duration format and max limit
func (b *TableBudget) BeforeSave(tx *gorm.DB) error {
func (b *TableBudget) BeforeSave(tx *gorm.DB) error {
// Validate that ResetDuration is in correct format (e.g., "30s", "5m", "1h", "1d", "1w", "1M", "1Y")
if d, err := ParseDuration(b.ResetDuration); err != nil {
return fmt.Errorf("invalid reset duration format: %s", b.ResetDuration)
}else if d <= 0 {
} else if d <= 0 {
return fmt.Errorf("reset duration must be > 0: %s", b.ResetDuration)
}
// Validate that MaxLimit is not negative (budgets should be positive)
Expand Down
6 changes: 3 additions & 3 deletions framework/configstore/tables/clientconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type TableClientConfig struct {
AllowedOriginsJSON string `gorm:"type:text" json:"-"` // JSON serialized []string
InitialPoolSize int `gorm:"default:300" json:"initial_pool_size"`
EnableLogging bool `gorm:"" json:"enable_logging"`
DisableContentLogging bool `gorm:"default:false" json:"disable_content_logging"` // DisableContentLogging controls whether sensitive content (inputs, outputs, embeddings, etc.) is logged
LogRetentionDays int `gorm:"default:365" json:"log_retention_days" validate:"min=1"` // Number of days to retain logs (minimum 1 day)
DisableContentLogging bool `gorm:"default:false" json:"disable_content_logging"` // DisableContentLogging controls whether sensitive content (inputs, outputs, embeddings, etc.) is logged
LogRetentionDays int `gorm:"default:365" json:"log_retention_days" validate:"min=1"` // Number of days to retain logs (minimum 1 day)
EnableGovernance bool `gorm:"" json:"enable_governance"`
EnforceGovernanceHeader bool `gorm:"" json:"enforce_governance_header"`
AllowDirectKeys bool `gorm:"" json:"allow_direct_keys"`
Expand All @@ -33,7 +33,7 @@ type TableClientConfig struct {

// Virtual fields for runtime use (not stored in DB)
PrometheusLabels []string `gorm:"-" json:"prometheus_labels"`
AllowedOrigins []string `gorm:"-" json:"allowed_origins,omitempty"`
AllowedOrigins []string `gorm:"-" json:"allowed_origins,omitempty"`
}

// TableName sets the table name for each model
Expand Down
18 changes: 8 additions & 10 deletions framework/configstore/tables/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ const (
ConfigProxyKey = "proxy_config"
)



// GlobalProxyConfig represents the global proxy configuration
type GlobalProxyConfig struct {
Enabled bool `json:"enabled"`
Type network.GlobalProxyType `json:"type"` // "http", "socks5", "tcp"
URL string `json:"url"` // Proxy URL (e.g., http://proxy.example.com:8080)
Username string `json:"username,omitempty"` // Optional authentication username
Password string `json:"password,omitempty"` // Optional authentication password
NoProxy string `json:"no_proxy,omitempty"` // Comma-separated list of hosts to bypass proxy
Timeout int `json:"timeout,omitempty"` // Connection timeout in seconds
SkipTLSVerify bool `json:"skip_tls_verify,omitempty"`// Skip TLS certificate verification
Enabled bool `json:"enabled"`
Type network.GlobalProxyType `json:"type"` // "http", "socks5", "tcp"
URL string `json:"url"` // Proxy URL (e.g., http://proxy.example.com:8080)
Username string `json:"username,omitempty"` // Optional authentication username
Password string `json:"password,omitempty"` // Optional authentication password
NoProxy string `json:"no_proxy,omitempty"` // Comma-separated list of hosts to bypass proxy
Timeout int `json:"timeout,omitempty"` // Connection timeout in seconds
SkipTLSVerify bool `json:"skip_tls_verify,omitempty"` // Skip TLS certificate verification
// Entity enablement flags
EnableForSCIM bool `json:"enable_for_scim"` // Enable proxy for SCIM requests (enterprise only)
EnableForInference bool `json:"enable_for_inference"` // Enable proxy for inference requests
Expand Down
14 changes: 7 additions & 7 deletions framework/configstore/tables/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ type TableKey struct {
VertexDeploymentsJSON *string `gorm:"type:text" json:"-"` // JSON serialized map[string]string

// Bedrock config fields (embedded)
BedrockAccessKey *string `gorm:"type:varchar(255)" json:"bedrock_access_key,omitempty"`
BedrockSecretKey *string `gorm:"type:text" json:"bedrock_secret_key,omitempty"`
BedrockSessionToken *string `gorm:"type:text" json:"bedrock_session_token,omitempty"`
BedrockRegion *string `gorm:"type:varchar(100)" json:"bedrock_region,omitempty"`
BedrockARN *string `gorm:"type:text" json:"bedrock_arn,omitempty"`
BedrockDeploymentsJSON *string `gorm:"type:text" json:"-"` // JSON serialized map[string]string
BedrockBatchS3ConfigJSON *string `gorm:"type:text" json:"-"` // JSON serialized schemas.BatchS3Config
BedrockAccessKey *string `gorm:"type:varchar(255)" json:"bedrock_access_key,omitempty"`
BedrockSecretKey *string `gorm:"type:text" json:"bedrock_secret_key,omitempty"`
BedrockSessionToken *string `gorm:"type:text" json:"bedrock_session_token,omitempty"`
BedrockRegion *string `gorm:"type:varchar(100)" json:"bedrock_region,omitempty"`
BedrockARN *string `gorm:"type:text" json:"bedrock_arn,omitempty"`
BedrockDeploymentsJSON *string `gorm:"type:text" json:"-"` // JSON serialized map[string]string
BedrockBatchS3ConfigJSON *string `gorm:"type:text" json:"-"` // JSON serialized schemas.BatchS3Config

// Batch API configuration
UseForBatchAPI *bool `gorm:"default:false" json:"use_for_batch_api,omitempty"` // Whether this key can be used for batch API operations
Expand Down
16 changes: 8 additions & 8 deletions framework/configstore/tables/mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (

// TableMCPClient represents an MCP client configuration in the database
type TableMCPClient struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"` // ID is used as the internal primary key and is also accessed by public methods, so it must be present.
ClientID string `gorm:"type:varchar(255);uniqueIndex;not null" json:"client_id"`
Name string `gorm:"type:varchar(255);uniqueIndex;not null" json:"name"`
ConnectionType string `gorm:"type:varchar(20);not null" json:"connection_type"` // schemas.MCPConnectionType
ConnectionString *string `gorm:"type:text" json:"connection_string,omitempty"`
StdioConfigJSON *string `gorm:"type:text" json:"-"` // JSON serialized schemas.MCPStdioConfig
ToolsToExecuteJSON string `gorm:"type:text" json:"-"` // JSON serialized []string
HeadersJSON string `gorm:"type:text" json:"-"` // JSON serialized map[string]string
ID uint `gorm:"primaryKey;autoIncrement" json:"id"` // ID is used as the internal primary key and is also accessed by public methods, so it must be present.
ClientID string `gorm:"type:varchar(255);uniqueIndex;not null" json:"client_id"`
Name string `gorm:"type:varchar(255);uniqueIndex;not null" json:"name"`
ConnectionType string `gorm:"type:varchar(20);not null" json:"connection_type"` // schemas.MCPConnectionType
ConnectionString *string `gorm:"type:text" json:"connection_string,omitempty"`
StdioConfigJSON *string `gorm:"type:text" json:"-"` // JSON serialized schemas.MCPStdioConfig
ToolsToExecuteJSON string `gorm:"type:text" json:"-"` // JSON serialized []string
HeadersJSON string `gorm:"type:text" json:"-"` // JSON serialized map[string]string

// Config hash is used to detect the changes synced from config.json file
// Every time we sync the config.json file, we will update the config hash
Expand Down
2 changes: 1 addition & 1 deletion framework/encrypt/encrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func TestKDFDeterministic(t *testing.T) {

// Re-initialize with same passphrase (simulating restart)
Init(passphrase, bifrost.NewDefaultLogger(schemas.LogLevelInfo))

// Should be able to decrypt the previously encrypted data
decrypted, err := Decrypt(encrypted1)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions plugins/jsonparser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (p *JsonParserPlugin) GetName() string {
// - url: The URL of the request
// - headers: The request headers
// - body: The request body
//
// Returns:
// - map[string]string: The updated request headers
// - map[string]any: The updated request body
Expand All @@ -101,6 +102,7 @@ func (p *JsonParserPlugin) TransportInterceptor(ctx *schemas.BifrostContext, url
// Parameters:
// - ctx: The Bifrost context
// - req: The Bifrost request
//
// Returns:
// - *schemas.BifrostRequest: The processed request
// - *schemas.PluginShortCircuit: The plugin short circuit if the request is not allowed
Expand All @@ -114,6 +116,7 @@ func (p *JsonParserPlugin) PreHook(ctx *schemas.BifrostContext, req *schemas.Bif
// - ctx: The Bifrost context
// - result: The Bifrost response to be processed
// - err: The Bifrost error to be processed
//
// Returns:
// - *schemas.BifrostResponse: The processed response
// - *schemas.BifrostError: The processed error
Expand Down
2 changes: 1 addition & 1 deletion plugins/logging/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (p *LoggerPlugin) PreHook(ctx *schemas.BifrostContext, req *schemas.Bifrost
initialData.SpeechInput = req.SpeechRequest.Input
case schemas.TranscriptionRequest, schemas.TranscriptionStreamRequest:
initialData.Params = req.TranscriptionRequest.Params
initialData.TranscriptionInput = req.TranscriptionRequest.Input
initialData.TranscriptionInput = req.TranscriptionRequest.Input
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/semanticcache/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (plugin *Plugin) PreHook(ctx *schemas.BifrostContext, req *schemas.BifrostR
ctx.SetValue(requestIDKey, requestID)
ctx.SetValue(requestModelKey, model)
ctx.SetValue(requestProviderKey, provider)

performDirectSearch, performSemanticSearch := true, true
if (*ctx).Value(CacheTypeKey) != nil {
cacheTypeVal, ok := (*ctx).Value(CacheTypeKey).(CacheType)
Expand Down
6 changes: 3 additions & 3 deletions plugins/semanticcache/plugin_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestSemanticCacheBasicFlow(t *testing.T) {

ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline)
ctx.SetValue(CacheKey, "test-cache-enabled")

// Test request
request := &schemas.BifrostRequest{
RequestType: schemas.ChatCompletionRequest,
Expand Down Expand Up @@ -309,7 +309,7 @@ func TestSemanticCacheStreamingFlow(t *testing.T) {
setup := NewTestSetup(t)
defer setup.Cleanup()

ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline)
ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline)
ctx.SetValue(CacheKey, "test-cache-enabled")

request := &schemas.BifrostRequest{
Expand Down Expand Up @@ -547,7 +547,7 @@ func TestSemanticCache_CustomThresholdHandling(t *testing.T) {
defer setup.Cleanup()

// Configure plugin with custom threshold key
ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline)
ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline)
ctx.SetValue(CacheKey, "test-cache-enabled")
ctx.SetValue(CacheThresholdKey, 0.95) // Very high threshold

Expand Down
2 changes: 1 addition & 1 deletion plugins/semanticcache/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (plugin *Plugin) buildStreamingResponseFromResult(ctx *schemas.BifrostConte
// Mark cache-hit once to avoid concurrent ctx writes
ctx.SetValue(isCacheHitKey, true)
ctx.SetValue(cacheHitTypeKey, cacheType)

// Create stream channel
streamChan := make(chan *schemas.BifrostStream)

Expand Down
4 changes: 2 additions & 2 deletions plugins/semanticcache/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func (plugin *Plugin) processAccumulatedStream(ctx context.Context, requestID st

accumulator := accumulatorInterface.(*StreamAccumulator)
accumulator.mu.Lock()

// Ensure unlock happens after cleanup
defer accumulator.mu.Unlock()
// Ensure cleanup happens
defer plugin.cleanupStreamAccumulator(requestID)
defer plugin.cleanupStreamAccumulator(requestID)

// STEP 1: Check if any chunk in the entire stream had an error
if accumulator.HasError {
Expand Down
Loading