bridge

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultURL = "http://localhost:3000"

DefaultURL is the default base URL for development builds

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentParticipant

type AgentParticipant struct {
	AgentType  string `json:"agent_type"`
	Model      string `json:"model,omitempty"`
	Name       string `json:"name,omitempty"`
	Prompt     string `json:"prompt,omitempty"`
	CLIVersion string `json:"cli_version,omitempty"`
}

AgentParticipant contains information about an agent participating in the conversation

type BridgeTestData added in v0.3.4

type BridgeTestData struct {
	Message    string     `json:"message"`
	SystemInfo SystemInfo `json:"system_info"`
}

BridgeTestData contains data for bridge.test events

type Client

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

Client is an HTTP client for sending streaming events to AgentPipe Web

func NewClient

func NewClient(config *Config) *Client

NewClient creates a new bridge client with the given configuration

func (*Client) SendEvent

func (c *Client) SendEvent(event *Event) error

SendEvent sends an event to the streaming endpoint with retry logic Returns an error if all retry attempts fail, but logs errors instead of failing the conversation

func (*Client) SendEventAsync

func (c *Client) SendEventAsync(event *Event)

SendEventAsync sends an event asynchronously in a goroutine (non-blocking) Errors are logged at debug level but do not block or fail the conversation

type Config

type Config struct {
	Enabled       bool   `mapstructure:"enabled"`
	URL           string `mapstructure:"url"`
	APIKey        string `mapstructure:"api_key"`
	TimeoutMs     int    `mapstructure:"timeout_ms"`
	RetryAttempts int    `mapstructure:"retry_attempts"`
	LogLevel      string `mapstructure:"log_level"`
}

Config holds the configuration for the bridge streaming functionality

func LoadConfig

func LoadConfig() *Config

LoadConfig loads bridge configuration from viper, environment variables, and defaults Precedence: environment variables > viper config > defaults

type ConversationCompletedData

type ConversationCompletedData struct {
	ConversationID  string  `json:"conversation_id"`
	Status          string  `json:"status"` // "completed", "interrupted", "error"
	TotalMessages   int     `json:"total_messages,omitempty"`
	TotalTurns      int     `json:"total_turns,omitempty"`
	TotalTokens     int     `json:"total_tokens,omitempty"`
	TotalCost       float64 `json:"total_cost,omitempty"`
	DurationSeconds float64 `json:"duration_seconds,omitempty"`
}

ConversationCompletedData contains data for conversation.completed events

type ConversationErrorData

type ConversationErrorData struct {
	ConversationID string `json:"conversation_id"`
	ErrorMessage   string `json:"error_message"`
	ErrorType      string `json:"error_type,omitempty"`
	AgentType      string `json:"agent_type,omitempty"`
}

ConversationErrorData contains data for conversation.error events

type ConversationStartedData

type ConversationStartedData struct {
	ConversationID string             `json:"conversation_id"`
	Mode           string             `json:"mode"`
	InitialPrompt  string             `json:"initial_prompt"`
	MaxTurns       int                `json:"max_turns,omitempty"`
	Participants   []AgentParticipant `json:"participants"`
	SystemInfo     SystemInfo         `json:"system_info"`
}

ConversationStartedData contains data for conversation.started events

type Emitter

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

Emitter provides high-level methods for emitting streaming events

func NewEmitter

func NewEmitter(config *Config, agentpipeVersion string) *Emitter

NewEmitter creates a new event emitter for a conversation

func (*Emitter) EmitConversationCompleted

func (e *Emitter) EmitConversationCompleted(
	status string,
	totalMessages int,
	totalTurns int,
	totalTokens int,
	totalCost float64,
	duration time.Duration,
)

EmitConversationCompleted emits a conversation.completed event

func (*Emitter) EmitConversationError

func (e *Emitter) EmitConversationError(
	errorMessage string,
	errorType string,
	agentType string,
)

EmitConversationError emits a conversation.error event

func (*Emitter) EmitConversationStarted

func (e *Emitter) EmitConversationStarted(
	mode string,
	initialPrompt string,
	maxTurns int,
	agents []AgentParticipant,
)

EmitConversationStarted emits a conversation.started event

func (*Emitter) EmitMessageCreated

func (e *Emitter) EmitMessageCreated(
	agentType string,
	agentName string,
	content string,
	model string,
	turnNumber int,
	tokensUsed int,
	inputTokens int,
	outputTokens int,
	cost float64,
	duration time.Duration,
)

EmitMessageCreated emits a message.created event

func (*Emitter) GetConversationID

func (e *Emitter) GetConversationID() string

GetConversationID returns the conversation ID for this emitter

type Event

type Event struct {
	Type      EventType   `json:"type"`
	Timestamp UTCTime     `json:"timestamp"`
	Data      interface{} `json:"data"`
}

Event represents a streaming event sent to the web app

type EventType

type EventType string

EventType represents the type of streaming event

const (
	// EventConversationStarted is emitted when a conversation begins
	EventConversationStarted EventType = "conversation.started"
	// EventMessageCreated is emitted after each agent completes a message
	EventMessageCreated EventType = "message.created"
	// EventConversationCompleted is emitted when conversation ends normally or reaches max turns
	EventConversationCompleted EventType = "conversation.completed"
	// EventConversationError is emitted when an error occurs during the conversation
	EventConversationError EventType = "conversation.error"
	// EventBridgeTest is emitted when testing the bridge connection
	EventBridgeTest EventType = "bridge.test"
)

type MessageCreatedData

type MessageCreatedData struct {
	ConversationID string  `json:"conversation_id"`
	MessageID      string  `json:"message_id"`
	AgentType      string  `json:"agent_type"`
	AgentName      string  `json:"agent_name,omitempty"`
	Content        string  `json:"content"`
	SequenceNumber int     `json:"sequence_number,omitempty"`
	TurnNumber     int     `json:"turn_number,omitempty"`
	TokensUsed     int     `json:"tokens_used,omitempty"`
	InputTokens    int     `json:"input_tokens,omitempty"`
	OutputTokens   int     `json:"output_tokens,omitempty"`
	Cost           float64 `json:"cost,omitempty"`
	Model          string  `json:"model,omitempty"`
	DurationMs     int64   `json:"duration_ms,omitempty"`
}

MessageCreatedData contains data for message.created events

type SystemInfo

type SystemInfo struct {
	AgentPipeVersion string `json:"agentpipe_version"`
	OS               string `json:"os"`
	OSVersion        string `json:"os_version"`
	GoVersion        string `json:"go_version"`
	Architecture     string `json:"architecture"`
}

SystemInfo contains system information collected for streaming events

func CollectSystemInfo

func CollectSystemInfo(version string) SystemInfo

CollectSystemInfo collects system information for the current environment

type UTCTime added in v0.3.2

type UTCTime struct {
	time.Time
}

UTCTime wraps time.Time to ensure JSON marshaling always uses UTC with Z suffix

func (UTCTime) MarshalJSON added in v0.3.2

func (t UTCTime) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler to output time in UTC with Z suffix

Jump to

Keyboard shortcuts

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