integration

package
v0.5.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package integration provides coordination and lifecycle management for intelligent systems. It integrates Memory, Heartbeat, Steering, and Hooks into the main server lifecycle.

Package integration provides coordination and lifecycle management for intelligent systems.

Package integration provides coordination and lifecycle management for intelligent systems.

Package integration provides coordination and lifecycle management for intelligent systems.

Package integration provides coordination and lifecycle management for intelligent systems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertHeartbeatConfig

func ConvertHeartbeatConfig(cfg *config.HeartbeatConfig) *heartbeat.HeartbeatConfig

ConvertHeartbeatConfig converts config.HeartbeatConfig to heartbeat.HeartbeatConfig. It parses duration strings and applies defaults for invalid values.

func RegisterProviderCheckers

func RegisterProviderCheckers(monitor heartbeat.HeartbeatMonitor, cfg *config.Config) error

RegisterProviderCheckers registers health checkers for all configured providers. It creates appropriate checker instances based on the main configuration.

Types

type EventBusIntegrator

type EventBusIntegrator struct {
	// contains filtered or unexported fields
}

EventBusIntegrator connects system events to the hooks event bus. It bridges heartbeat events, routing events, and provider events to the hooks system, allowing hooks to react to these events.

func NewEventBusIntegrator

func NewEventBusIntegrator(
	eventBus *hooks.EventBus,
	hooksMgr *hooks.HookManager,
	hbMonitor heartbeat.HeartbeatMonitor,
) *EventBusIntegrator

NewEventBusIntegrator creates a new event bus integrator. All parameters are optional - if nil, the corresponding functionality is disabled.

func (*EventBusIntegrator) ConnectHeartbeatEvents

func (ebi *EventBusIntegrator) ConnectHeartbeatEvents() error

ConnectHeartbeatEvents connects heartbeat monitor events to the hooks event bus. It registers a heartbeat event handler that translates heartbeat events to hook events. Returns an error if the heartbeat monitor or event bus is not available.

func (*EventBusIntegrator) ConnectProviderEvents

func (ebi *EventBusIntegrator) ConnectProviderEvents() error

ConnectProviderEvents connects provider failure events to the hooks event bus. This is a no-op since provider events are emitted through heartbeat events. This method exists for API completeness and future extensibility.

func (*EventBusIntegrator) ConnectRoutingEvents

func (ebi *EventBusIntegrator) ConnectRoutingEvents() error

ConnectRoutingEvents connects routing decision events to the hooks event bus. This is a no-op since routing events are emitted directly by the RequestPipelineIntegrator. This method exists for API completeness and future extensibility.

func (*EventBusIntegrator) EmitEvent

func (ebi *EventBusIntegrator) EmitEvent(event *hooks.EventContext) error

EmitEvent emits a custom event to the hooks event bus. This is a convenience method for emitting events from other parts of the system. If the event bus is not available, it logs a debug message and returns nil.

func (*EventBusIntegrator) EmitRequestFailedEvent

func (ebi *EventBusIntegrator) EmitRequestFailedEvent(
	provider string,
	model string,
	errorMsg string,
	decision *memory.RoutingDecision,
) error

EmitRequestFailedEvent is a convenience method to emit a request failed event. This can be called from API handlers when a request fails.

func (*EventBusIntegrator) EmitRequestReceivedEvent

func (ebi *EventBusIntegrator) EmitRequestReceivedEvent(
	provider string,
	model string,
	apiKeyHash string,
) error

EmitRequestReceivedEvent is a convenience method to emit a request received event. This can be called from API handlers when a request is received.

type HandlerAdapter

type HandlerAdapter struct {
	// contains filtered or unexported fields
}

HandlerAdapter adapts RequestPipelineIntegrator to the interface expected by BaseAPIHandler. This avoids circular dependencies between sdk/api/handlers and internal/integration.

func NewHandlerAdapter

func NewHandlerAdapter(integrator *RequestPipelineIntegrator) *HandlerAdapter

NewHandlerAdapter creates a new handler adapter.

func (*HandlerAdapter) ApplySteering

func (ha *HandlerAdapter) ApplySteering(ctx interface{}, messages []map[string]string) (string, []map[string]string, error)

ApplySteering evaluates steering rules and modifies the request if rules match. The ctx parameter should be a *steering.RoutingContext.

func (*HandlerAdapter) EmitRoutingEvent

func (ha *HandlerAdapter) EmitRoutingEvent(decision interface{}) error

EmitRoutingEvent emits a routing decision event to the event bus. The decision parameter can be either a *memory.RoutingDecision or a map[string]interface{}.

func (*HandlerAdapter) RecordRouting

func (ha *HandlerAdapter) RecordRouting(decision interface{}) error

RecordRouting records a routing decision to the memory system. The decision parameter can be either a *memory.RoutingDecision or a map[string]interface{}.

func (*HandlerAdapter) UpdateOutcome

func (ha *HandlerAdapter) UpdateOutcome(decision interface{}) error

UpdateOutcome updates a routing decision with its outcome. The decision parameter can be either a *memory.RoutingDecision or a map[string]interface{}.

type IntegrationConfig

type IntegrationConfig struct {
	Memory    *memory.MemoryConfig
	Heartbeat *heartbeat.HeartbeatConfig
	Steering  *config.SteeringConfig
	Hooks     *config.HooksConfig

	// MainConfig is the full application configuration, used for provider registration
	MainConfig *config.Config
}

IntegrationConfig holds configuration for all intelligent systems.

type RequestPipelineIntegrator

type RequestPipelineIntegrator struct {
	// contains filtered or unexported fields
}

RequestPipelineIntegrator integrates steering and memory into request processing. It applies steering rules before routing, records routing decisions to memory, and emits routing events to the event bus.

func NewRequestPipelineIntegrator

func NewRequestPipelineIntegrator(
	steeringEngine *steering.SteeringEngine,
	memoryManager memory.MemoryManager,
	eventBus *hooks.EventBus,
) *RequestPipelineIntegrator

NewRequestPipelineIntegrator creates a new request pipeline integrator. All parameters are optional - if nil, the corresponding functionality is disabled.

func (*RequestPipelineIntegrator) ApplySteering

func (rpi *RequestPipelineIntegrator) ApplySteering(
	ctx interface{},
	messages []map[string]string,
) (string, []map[string]string, error)

ApplySteering evaluates steering rules and modifies the request if rules match. It returns the selected model (or empty string if no override) and modified messages. If steering is disabled or evaluation fails, it returns empty model and original messages.

Parameters:

  • ctx: The routing context containing request metadata (should be *steering.RoutingContext)
  • messages: The original request messages

Returns:

  • selectedModel: The model selected by steering rules (empty if no override)
  • modifiedMessages: The messages after context injection (same as input if no injection)
  • error: Any error that occurred during evaluation (non-fatal, caller should continue)

func (*RequestPipelineIntegrator) EmitRoutingEvent

func (rpi *RequestPipelineIntegrator) EmitRoutingEvent(decision interface{}) error

EmitRoutingEvent emits a routing decision event to the event bus. This allows hooks to react to routing decisions. If the event bus is not available or emission fails, it logs the error and continues. This method is non-blocking and fail-safe.

Parameters:

  • decision: The routing decision to emit as an event (should be *memory.RoutingDecision)

Returns:

  • error: Any error that occurred during emission (non-fatal, logged internally)

func (*RequestPipelineIntegrator) RecordRouting

func (rpi *RequestPipelineIntegrator) RecordRouting(decision interface{}) error

RecordRouting records a routing decision to the memory system. If memory is disabled or recording fails, it logs the error and continues. This method is non-blocking and fail-safe.

Parameters:

  • decision: The routing decision to record (should be *memory.RoutingDecision)

Returns:

  • error: Any error that occurred during recording (non-fatal, logged internally)

func (*RequestPipelineIntegrator) UpdateOutcome

func (rpi *RequestPipelineIntegrator) UpdateOutcome(decision interface{}) error

UpdateOutcome updates a routing decision with its outcome. This should be called after the request completes (success or failure). If memory is disabled or update fails, it logs the error and continues. This method is non-blocking and fail-safe.

Parameters:

  • decision: The routing decision with updated outcome information (should be *memory.RoutingDecision)

Returns:

  • error: Any error that occurred during update (non-fatal, logged internally)

type RoutingDecisionBuilder

type RoutingDecisionBuilder struct {
	// contains filtered or unexported fields
}

RoutingDecisionBuilder helps build routing decisions from handler context.

func NewRoutingDecisionBuilder

func NewRoutingDecisionBuilder() *RoutingDecisionBuilder

NewRoutingDecisionBuilder creates a new routing decision builder.

func (*RoutingDecisionBuilder) Build

Build returns the constructed routing decision.

func (*RoutingDecisionBuilder) WithAPIKeyHash

func (b *RoutingDecisionBuilder) WithAPIKeyHash(hash string) *RoutingDecisionBuilder

WithAPIKeyHash sets the API key hash.

func (*RoutingDecisionBuilder) WithConfidence

func (b *RoutingDecisionBuilder) WithConfidence(confidence float64) *RoutingDecisionBuilder

WithConfidence sets the routing confidence.

func (*RoutingDecisionBuilder) WithContentHash

func (b *RoutingDecisionBuilder) WithContentHash(hash string) *RoutingDecisionBuilder

WithContentHash sets the content hash.

func (*RoutingDecisionBuilder) WithContentLength

func (b *RoutingDecisionBuilder) WithContentLength(length int) *RoutingDecisionBuilder

WithContentLength sets the content length.

func (*RoutingDecisionBuilder) WithError

WithError sets the error message.

func (*RoutingDecisionBuilder) WithIntent

func (b *RoutingDecisionBuilder) WithIntent(intent string) *RoutingDecisionBuilder

WithIntent sets the request intent.

func (*RoutingDecisionBuilder) WithLatency

func (b *RoutingDecisionBuilder) WithLatency(latencyMs int64) *RoutingDecisionBuilder

WithLatency sets the routing latency in milliseconds.

func (*RoutingDecisionBuilder) WithModel

WithModel sets the requested model.

func (*RoutingDecisionBuilder) WithQualityScore

func (b *RoutingDecisionBuilder) WithQualityScore(score float64) *RoutingDecisionBuilder

WithQualityScore sets the quality score.

func (*RoutingDecisionBuilder) WithResponseTime

func (b *RoutingDecisionBuilder) WithResponseTime(responseTimeMs int64) *RoutingDecisionBuilder

WithResponseTime sets the response time in milliseconds.

func (*RoutingDecisionBuilder) WithSelectedModel

func (b *RoutingDecisionBuilder) WithSelectedModel(model string) *RoutingDecisionBuilder

WithSelectedModel sets the selected model.

func (*RoutingDecisionBuilder) WithSuccess

func (b *RoutingDecisionBuilder) WithSuccess(success bool) *RoutingDecisionBuilder

WithSuccess sets the outcome success status.

func (*RoutingDecisionBuilder) WithTier

WithTier sets the routing tier.

type ServiceCoordinator

type ServiceCoordinator struct {
	// contains filtered or unexported fields
}

ServiceCoordinator manages the lifecycle of all four intelligent systems. It handles initialization, startup, shutdown, and provides access to system instances.

func NewServiceCoordinator

func NewServiceCoordinator(cfg *IntegrationConfig) (*ServiceCoordinator, error)

NewServiceCoordinator creates a new service coordinator with the given configuration. It initializes all systems but does not start them. Call Start() to begin operations.

func (*ServiceCoordinator) GetEventBus

func (sc *ServiceCoordinator) GetEventBus() interface{}

GetEventBus returns the Event Bus instance. The event bus is always initialized, even if hooks are disabled.

func (*ServiceCoordinator) GetHeartbeat

func (sc *ServiceCoordinator) GetHeartbeat() interface{}

GetHeartbeat returns the Heartbeat Monitor instance. Returns nil if the heartbeat monitor is disabled or failed to initialize.

func (*ServiceCoordinator) GetHooks

func (sc *ServiceCoordinator) GetHooks() interface{}

GetHooks returns the Hooks Manager instance. Returns nil if the hooks manager failed to initialize.

func (*ServiceCoordinator) GetMemory

func (sc *ServiceCoordinator) GetMemory() interface{}

GetMemory returns the Memory Manager instance. Returns nil if the memory system is disabled or failed to initialize.

func (*ServiceCoordinator) GetSteering

func (sc *ServiceCoordinator) GetSteering() interface{}

GetSteering returns the Steering Engine instance. Returns nil if the steering engine failed to initialize.

func (*ServiceCoordinator) IsStarted

func (sc *ServiceCoordinator) IsStarted() bool

IsStarted returns true if the coordinator has been started.

func (*ServiceCoordinator) Start

func (sc *ServiceCoordinator) Start(ctx context.Context) error

Start begins operations for all enabled systems. It starts background services and file watchers. This method is idempotent - calling it multiple times has no effect.

func (*ServiceCoordinator) Stop

func (sc *ServiceCoordinator) Stop(ctx context.Context) error

Stop gracefully shuts down all systems. It stops background services, closes file watchers, and releases resources. Systems are stopped in reverse initialization order. This method is idempotent - calling it multiple times has no effect.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL