mux

package
v0.3.20 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

ABOUTME: Backend wrapper around mux agent for Jeff ABOUTME: Provides simplified event streaming interface over agent orchestration

ABOUTME: Event types and conversion from orchestrator events ABOUTME: Provides simplified event interface for Jeff's UI layer

Index

Constants

View Source
const (
	ProviderAnthropic  = "anthropic"
	ProviderOpenAI     = "openai"
	ProviderGemini     = "gemini"
	ProviderOpenRouter = "openrouter"
	ProviderOllama     = "ollama"
)

Provider constants

Variables

View Source
var DefaultModels = map[string]string{
	ProviderAnthropic:  "claude-sonnet-4-5-20250929",
	ProviderOpenAI:     "gpt-5",
	ProviderGemini:     "gemini-2.5-flash",
	ProviderOpenRouter: "anthropic/claude-sonnet-4.5",
	ProviderOllama:     "llama3.3",
}

Default models per provider (updated January 2026)

Functions

func GetAPIKeyForProvider added in v0.3.18

func GetAPIKeyForProvider(providerName, fallbackKey string) string

GetAPIKeyForProvider returns the API key for the given provider. It checks provider-specific environment variables first. The fallbackKey (from config) is only used for Anthropic since that's the default.

Types

type ApprovalRequest

type ApprovalRequest struct {
	ToolName string
	ToolID   string
	Params   map[string]any
	Response chan<- bool
}

ApprovalRequest is sent when a tool needs interactive approval. The Response channel must receive exactly one bool value.

type Backend

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

Backend wraps a mux agent and provides event streaming

func NewBackend

func NewBackend(cfg Config) *Backend

NewBackend creates a new Backend with the given configuration. Panics if APIKey is empty (except for ollama which doesn't need one).

func NewInteractiveBackend

func NewInteractiveBackend(cfg InteractiveConfig) *Backend

NewInteractiveBackend creates a Backend configured for interactive use. The approval flow uses channels instead of callbacks, allowing the UI to handle approval prompts asynchronously.

func (*Backend) Run

func (b *Backend) Run(ctx context.Context, prompt string) <-chan Event

Run executes the agent with the given prompt and returns an event channel. The channel will be closed when the agent completes or the context is cancelled. Events are transformed from orchestrator events to mux events. This method auto-approves all tools based on the Config.ApprovalFunc.

func (*Backend) RunInteractive

func (b *Backend) RunInteractive(
	ctx context.Context,
	prompt string,
	needsApproval func(toolName string, params map[string]any) bool,
) (<-chan Event, <-chan ApprovalRequest)

RunInteractive executes the agent with interactive approval support. Returns two channels:

  • events: mux events (text, tool calls, results, completion)
  • approvals: requests for tool approval (send response on Request.Response)

When a tool needs approval, an ApprovalRequest is sent on the approvals channel. The caller must send exactly one bool on Request.Response to approve/deny. The agent blocks until the response is received.

The needsApproval function determines which tools require approval. If nil, all tools require approval.

type Config

type Config struct {
	// APIKey is the API key for the LLM provider
	APIKey string

	// Provider is the LLM provider to use (anthropic, openai, gemini, openrouter, ollama)
	// Defaults to "anthropic"
	Provider string

	// Model is the model to use (defaults based on provider)
	Model string

	// BaseURL is the base URL for the API (optional, used for ollama or custom endpoints)
	BaseURL string

	// SystemPrompt is the system prompt for the agent
	SystemPrompt string

	// Tools is the list of Jeff tools to make available
	// Can be []tools.Tool or []interface{} for testing
	Tools interface{}

	// ApprovalFunc is called when a tool requires approval
	// If nil, all tools are auto-approved
	ApprovalFunc func(toolName string, params map[string]any) bool
}

Config holds configuration for creating a Backend

type Event

type Event struct {
	// Type identifies what kind of event this is
	Type EventType

	// Text content (for EventText and EventComplete)
	Text string

	// Tool information (for EventToolCall)
	ToolName   string
	ToolID     string
	ToolParams map[string]any

	// Tool result (for EventToolResult)
	ToolOutput string
	Success    bool

	// Error (for EventError and failed EventToolResult)
	Error error
}

Event represents a simplified orchestrator event for Jeff's UI

func FromOrchestratorEvent

func FromOrchestratorEvent(orchEvent orchestrator.Event) Event

FromOrchestratorEvent converts an orchestrator event to a mux event

type EventType

type EventType string

EventType identifies the kind of event

const (
	// EventText represents streaming text content from the assistant
	EventText EventType = "text"
	// EventToolCall represents a tool being called
	EventToolCall EventType = "tool_call"
	// EventToolResult represents the result of a tool execution
	EventToolResult EventType = "tool_result"
	// EventComplete represents successful completion
	EventComplete EventType = "complete"
	// EventError represents an error
	EventError EventType = "error"
)

type InteractiveConfig

type InteractiveConfig struct {
	Config

	// NeedsApproval returns true if the given tool requires user approval.
	// If nil, all tools require approval.
	NeedsApproval func(toolName string, params map[string]any) bool
}

InteractiveConfig extends Config with interactive-mode settings

Jump to

Keyboard shortcuts

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