Documentation
¶
Overview ¶
Package goim provides a platform-agnostic IM gateway that bridges any Runtime (agent backend) to multiple chat platforms via cc-connect.
Index ¶
- Constants
- func CreatePlatforms(cfg Config) ([]core.Platform, error)
- func ResolveDataDir(cfg Config) string
- func ResolveLang(lang string) core.Language
- func SaveChannelsJSON(path string, cfg ChannelsConfig) error
- func SetupIMLogger() (cleanup func(), err error)
- type Agent
- type ChannelsConfig
- type Config
- type ContentBlock
- type Delta
- type Engine
- type IMController
- func (c *IMController) DeleteChannel(platform string) error
- func (c *IMController) Running() bool
- func (c *IMController) SaveChannel(platform string, opts map[string]any) error
- func (c *IMController) Start(runtime Runtime, name, platform, token, allowFrom, configPath string) error
- func (c *IMController) StartWithOpts(runtime Runtime, name, platform string, opts map[string]any) error
- func (c *IMController) Status() string
- func (c *IMController) Stop() error
- type LogConfig
- type PlatformConfig
- type ProjectConfig
- type Request
- type Runtime
- type Session
- func (s *Session) Alive() bool
- func (s *Session) Close() error
- func (s *Session) CurrentSessionID() string
- func (s *Session) Events() <-chan core.Event
- func (s *Session) RespondPermission(_ string, _ core.PermissionResult) error
- func (s *Session) Send(prompt string, images []core.ImageAttachment, files []core.FileAttachment) error
- type StreamEvent
- type StreamPreviewConfig
- type StreamPreviewJSON
Constants ¶
const ( EventContentBlockDelta = "content_block_delta" EventToolExecutionStart = "tool_execution_start" EventToolExecutionResult = "tool_execution_result" EventToolExecutionOutput = "tool_execution_output" EventError = "error" EventMessageStop = "message_stop" )
Stream event type constants.
Variables ¶
This section is empty.
Functions ¶
func CreatePlatforms ¶
CreatePlatforms instantiates cc-connect Platform objects from config.
func ResolveDataDir ¶
ResolveDataDir returns the data directory, defaulting to .animus/connect.
func ResolveLang ¶
ResolveLang converts a language string to a cc-connect Language constant.
func SaveChannelsJSON ¶
func SaveChannelsJSON(path string, cfg ChannelsConfig) error
SaveChannelsJSON writes the channels config to a JSON file, creating parent directories as needed.
func SetupIMLogger ¶
func SetupIMLogger() (cleanup func(), err error)
SetupIMLogger configures slog to write IM bridge logs to rotated JSON files under ~/.animus/logs/. Logs are NOT written to the terminal. Returns a cleanup function that restores the original slog handler and closes the log file.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent implements core.Agent by wrapping a Runtime.
func (*Agent) ListSessions ¶
func (*Agent) StartSession ¶
type ChannelsConfig ¶
type ChannelsConfig struct {
Channels map[string]map[string]any `json:"channels"`
Language string `json:"language,omitempty"`
StreamPreview *StreamPreviewJSON `json:"stream_preview,omitempty"`
}
ChannelsConfig is the JSON-native config format stored in ~/.animus/channels.json (user-global). Each key in Channels is a platform name (e.g. "telegram", "feishu") and the value is passed directly to core.CreatePlatform as options.
func LoadChannelsJSON ¶
func LoadChannelsJSON(path string) (ChannelsConfig, error)
LoadChannelsJSON reads a channels.json file. Returns an empty config (not an error) if the file does not exist.
func (ChannelsConfig) LookupChannel ¶
func (c ChannelsConfig) LookupChannel(platform string) map[string]any
LookupChannel returns the options for a specific channel from a ChannelsConfig. Returns nil if the channel is not found or is disabled.
func (ChannelsConfig) ToConfig ¶
func (c ChannelsConfig) ToConfig() Config
ToConfig converts a ChannelsConfig to the internal Config format used by CreatePlatforms. Channels with enabled=false are skipped.
type Config ¶
type Config struct {
DataDir string `toml:"data_dir"`
Language string `toml:"language"`
Log LogConfig `toml:"log"`
StreamPreview StreamPreviewConfig `toml:"stream_preview"`
Project ProjectConfig `toml:"project"`
}
Config is a simplified subset of cc-connect's config.toml focused on the fields needed to run an IM bridge.
func ConfigFromFlags ¶
ConfigFromFlags builds a minimal Config from CLI flags for the common case of a single platform without a config file.
func LoadConfig ¶
LoadConfig reads a config file. Returns defaults if path is empty.
type ContentBlock ¶
type ContentBlock struct {
Type string // e.g. "image"
MediaType string // e.g. "image/png"
Data string // base64-encoded data
}
ContentBlock carries multimodal content (e.g., images).
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine wraps cc-connect's core.Engine with goim-specific configuration.
func NewEngine ¶
NewEngine creates a cc-connect Engine binding the given Agent adapter and Platforms.
type IMController ¶
type IMController struct {
ChannelsPath string // path to ~/.animus/channels.json
// contains filtered or unexported fields
}
IMController manages the lifecycle of an IM bridge Engine.
func NewIMController ¶
func NewIMController(channelsPath string) *IMController
NewIMController creates a new controller with no active bridge. channelsPath is the path to ~/.animus/channels.json for auto-load/save.
func (*IMController) DeleteChannel ¶
func (c *IMController) DeleteChannel(platform string) error
DeleteChannel removes a platform from channels.json.
func (*IMController) Running ¶
func (c *IMController) Running() bool
Running reports whether the bridge is active.
func (*IMController) SaveChannel ¶
func (c *IMController) SaveChannel(platform string, opts map[string]any) error
SaveChannel persists a platform's credentials to channels.json.
func (*IMController) Start ¶
func (c *IMController) Start(runtime Runtime, name, platform, token, allowFrom, configPath string) error
Start launches the IM bridge. If already running, returns an error.
Priority for resolving configuration:
- platform + token provided directly (dialog mode) -> use immediately
- platform provided without token -> look up saved config in channels.json
- configPath non-empty -> load TOML config (legacy compatibility)
- no platform -> load all enabled channels from channels.json
func (*IMController) StartWithOpts ¶
func (c *IMController) StartWithOpts(runtime Runtime, name, platform string, opts map[string]any) error
StartWithOpts launches the IM bridge using raw platform options (from tool credentials).
func (*IMController) Status ¶
func (c *IMController) Status() string
Status returns a human-readable status string.
func (*IMController) Stop ¶
func (c *IMController) Stop() error
Stop shuts down the IM bridge. No-op if not running.
type PlatformConfig ¶
type ProjectConfig ¶
type ProjectConfig struct {
Name string `toml:"name"`
Platforms []PlatformConfig `toml:"platforms"`
}
type Request ¶
type Request struct {
Prompt string
SessionID string
ContentBlocks []ContentBlock
}
Request represents a user message forwarded from an IM platform.
type Runtime ¶
type Runtime interface {
RunStream(ctx context.Context, req Request) (<-chan StreamEvent, error)
}
Runtime is the interface that host applications must implement to integrate with goim. It receives user messages from IM platforms and streams back responses.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session implements core.AgentSession by calling Runtime.RunStream for each user message and converting StreamEvent to core.Event.
func (*Session) CurrentSessionID ¶
func (*Session) RespondPermission ¶
func (s *Session) RespondPermission(_ string, _ core.PermissionResult) error
func (*Session) Send ¶
func (s *Session) Send(prompt string, images []core.ImageAttachment, files []core.FileAttachment) error
type StreamEvent ¶
type StreamEvent struct {
Type string
Name string // tool name (for tool events)
Delta *Delta // text delta (for content events)
Output interface{} // tool output or error message
SessionID string
}
StreamEvent is a single event in a streaming response.
type StreamPreviewConfig ¶
type StreamPreviewConfig struct {
Enabled *bool `toml:"enabled"`
IntervalMs *int `toml:"interval_ms"`
MinDeltaChars *int `toml:"min_delta_chars"`
MaxChars *int `toml:"max_chars"`
}
func (StreamPreviewConfig) ToStreamPreviewCfg ¶
func (sp StreamPreviewConfig) ToStreamPreviewCfg() core.StreamPreviewCfg
ToStreamPreviewCfg converts to cc-connect's core.StreamPreviewCfg.
type StreamPreviewJSON ¶
type StreamPreviewJSON struct {
Enabled *bool `json:"enabled,omitempty"`
IntervalMs *int `json:"interval_ms,omitempty"`
MinDeltaChars *int `json:"min_delta_chars,omitempty"`
MaxChars *int `json:"max_chars,omitempty"`
}
StreamPreviewJSON is the JSON variant of StreamPreviewConfig.