bridge

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: MIT Imports: 14 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 {
	AgentID    string `json:"agent_id"`              // Unique identifier for this agent instance
	AgentType  string `json:"agent_type"`            // Type of agent (e.g., "claude", "gemini")
	Model      string `json:"model,omitempty"`       // Model used by the agent
	Name       string `json:"name,omitempty"`        // Display name of the agent
	Prompt     string `json:"prompt,omitempty"`      // System prompt for the agent
	CLIVersion string `json:"cli_version,omitempty"` // Version of the agent CLI
}

AgentParticipant contains information about an agent participating in the conversation

type BridgeConnectedData added in v0.4.0

type BridgeConnectedData struct {
	SystemInfo  SystemInfo `json:"system_info"`
	ConnectedAt string     `json:"connected_at"`
}

BridgeConnectedData contains data for bridge.connected events

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 CommandInfo added in v0.4.1

type CommandInfo struct {
	FullCommand    string            `json:"full_command"`             // Complete command as executed
	Args           []string          `json:"args,omitempty"`           // Command arguments
	Mode           string            `json:"mode,omitempty"`           // Orchestrator mode
	MaxTurns       int               `json:"max_turns,omitempty"`      // Maximum turns
	InitialPrompt  string            `json:"initial_prompt,omitempty"` // Initial prompt
	ConfigFile     string            `json:"config_file,omitempty"`    // Config file path
	TUIEnabled     bool              `json:"tui_enabled"`              // TUI mode enabled
	LoggingEnabled bool              `json:"logging_enabled"`          // Logging enabled
	ShowMetrics    bool              `json:"show_metrics"`             // Show metrics
	Timeout        int               `json:"timeout,omitempty"`        // Timeout in seconds
	Options        map[string]string `json:"options,omitempty"`        // Additional options
}

CommandInfo contains information about the agentpipe command that was run

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"`     // Includes summary tokens
	TotalCost       float64          `json:"total_cost,omitempty"`       // Includes summary cost
	DurationSeconds float64          `json:"duration_seconds,omitempty"` // Does not include summary generation time
	Summary         *SummaryMetadata `json:"summary,omitempty"`          // AI-generated conversation summary with metadata
}

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"`
	Command        *CommandInfo       `json:"command,omitempty"` // Command that started the conversation
}

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 Automatically sends a bridge.connected event to announce the connection

func (*Emitter) Close added in v0.4.1

func (e *Emitter) Close() error

Close closes the emitter and flushes any buffered events

func (*Emitter) EmitConversationCompleted

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

EmitConversationCompleted emits a conversation.completed event Uses synchronous send to ensure the event is fully sent before program exit

func (*Emitter) EmitConversationError

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

EmitConversationError emits a conversation.error event Uses synchronous send to ensure the event is fully sent before program exit

func (*Emitter) EmitConversationStarted

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

EmitConversationStarted emits a conversation.started event

func (*Emitter) EmitMessageCreated

func (e *Emitter) EmitMessageCreated(
	agentID string,
	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

func LoadEventsFromFile added in v0.4.1

func LoadEventsFromFile(filePath string) ([]*Event, error)

LoadEventsFromFile reads events from a JSON Lines file

type EventStore added in v0.4.1

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

EventStore handles local storage of events for later upload

func NewEventStore added in v0.4.1

func NewEventStore(conversationID string, logDir string) (*EventStore, error)

NewEventStore creates a new event store that saves events to a JSON file

func (*EventStore) Close added in v0.4.1

func (s *EventStore) Close() error

Close closes the event log file

func (*EventStore) GetEvents added in v0.4.1

func (s *EventStore) GetEvents() []*Event

GetEvents returns all events stored in memory

func (*EventStore) GetFilePath added in v0.4.1

func (s *EventStore) GetFilePath() string

GetFilePath returns the path to the event log file

func (*EventStore) SaveEvent added in v0.4.1

func (s *EventStore) SaveEvent(event *Event) error

SaveEvent saves an event to the local store (JSON Lines format)

type EventType

type EventType string

EventType represents the type of streaming event

const (
	// EventBridgeConnected is emitted when the bridge connection is established
	EventBridgeConnected EventType = "bridge.connected"
	// 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"`
	AgentID        string  `json:"agent_id"`             // Unique identifier for the agent instance
	AgentType      string  `json:"agent_type"`           // Type of agent (e.g., "claude", "gemini")
	AgentName      string  `json:"agent_name,omitempty"` // Display name of the agent
	Content        string  `json:"content"`              // Message 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 SummaryMetadata added in v0.4.1

type SummaryMetadata struct {
	Text         string  `json:"text"`                    // The summary text
	AgentType    string  `json:"agent_type"`              // Type of agent used to generate summary (e.g., "gemini")
	Model        string  `json:"model,omitempty"`         // Model used for summary generation
	InputTokens  int     `json:"input_tokens,omitempty"`  // Tokens used for input (conversation)
	OutputTokens int     `json:"output_tokens,omitempty"` // Tokens used for output (summary)
	TotalTokens  int     `json:"total_tokens,omitempty"`  // Total tokens used
	Cost         float64 `json:"cost,omitempty"`          // Cost of generating the summary
	DurationMs   int64   `json:"duration_ms,omitempty"`   // Time taken to generate summary
}

SummaryMetadata contains information about the AI-generated conversation summary

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