Documentation
¶
Overview ¶
Package core runs conversations: it chooses the agent, queues prompts, applies the permission policy, tracks cost and takes checkpoints.
The core is independent of any chat platform and any agent vendor. It declares the small interfaces it needs (UI, Store, ToolHost, Checkpointer) and is wired to implementations by the caller.
Index ¶
- type Approval
- type Checkpointer
- type ConvID
- type Core
- func (c *Core) AgentNames() []string
- func (c *Core) AgentType(name string) string
- func (c *Core) Answer(id, optionID string) bool
- func (c *Core) Caps(conv ConvID) agent.Caps
- func (c *Core) Diff(ctx context.Context, conv ConvID, all bool) (string, error)
- func (c *Core) Models(conv ConvID) []string
- func (c *Core) NewSession(conv ConvID)
- func (c *Core) ResumeSession(conv ConvID, id string) (store.SessionRecord, error)
- func (c *Core) Running(conv ConvID) (running bool, queued int)
- func (c *Core) Sessions(conv ConvID) []store.SessionRecord
- func (c *Core) SetAgent(conv ConvID, name string) error
- func (c *Core) SetCwd(conv ConvID, dir string) (string, error)
- func (c *Core) SetMode(conv ConvID, mode agent.Mode) error
- func (c *Core) SetModel(conv ConvID, model string)
- func (c *Core) SetProject(conv ConvID, name string) error
- func (c *Core) SetUI(ui UI)
- func (c *Core) Settings(conv ConvID) Settings
- func (c *Core) Stop(conv ConvID) (stopped bool, dropped int)
- func (c *Core) Submit(conv ConvID, in Input)
- func (c *Core) ToggleVoice(conv ConvID) (bool, error)
- func (c *Core) Undo(ctx context.Context, conv ConvID) (store.Checkpoint, error)
- func (c *Core) Usage(user string) (today, month float64)
- type Deps
- type Input
- type Messenger
- type Progress
- type Settings
- type Store
- type ToolHost
- type UI
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Approval ¶ added in v0.6.0
type Approval interface {
Resolve(outcome string)
}
Approval is a permission request on screen.
type Checkpointer ¶ added in v0.6.0
type Checkpointer interface {
Snapshot(ctx context.Context, dir string) (id string, err error)
Diff(ctx context.Context, dir, from string) (string, error)
Restore(ctx context.Context, dir, id string) error
}
Checkpointer snapshots a working tree so a turn can be shown and undone.
type ConvID ¶ added in v0.6.0
type ConvID string
ConvID identifies a conversation. The frontend chooses the format (for example a chat plus a thread); the core treats it as opaque.
type Core ¶
type Core struct {
Deps
// contains filtered or unexported fields
}
func (*Core) AgentNames ¶ added in v0.6.0
AgentNames lists the configured agents, sorted.
func (*Core) Answer ¶
Answer delivers the user's choice for an approval. It returns false if the request is no longer pending.
func (*Core) NewSession ¶
func (*Core) ResumeSession ¶
func (*Core) Submit ¶
Submit runs the input now, or queues it if the conversation is busy. While an approval is pending, text input denies it with that text as the reason.
type Deps ¶ added in v0.6.0
type Deps struct {
Config *config.Config
Agents map[string]agent.Agent
Store Store
Tools ToolHost
Checkpointer Checkpointer
Transcriber stt.Transcriber
Speaker tts.Speaker
}
Deps are the core's collaborators. Transcriber, Speaker and Checkpointer may be nil to disable those features.
type Input ¶
type Input struct {
User string // opaque user id, used for budgets
Blocks []agent.Block
Text string // the text part, used for titles and "deny with reason"
}
Input is one user message.
type Messenger ¶ added in v0.6.0
type Messenger interface {
Reply(conv ConvID, markdown string) // agent output; long replies may become a file
Notice(conv ConvID, text string) // a short status line
SendFile(ctx context.Context, conv ConvID, path, caption string) error
SendVoice(ctx context.Context, conv ConvID, ogg []byte) error
}
Messenger sends things to a conversation.
type Progress ¶
type Progress interface {
ToolCall(title string)
Flush() // called before agent text is sent, so tool lines stay above it
Done(summary string)
}
Progress shows what the agent is doing during one turn.
type Settings ¶
type Settings struct {
Agent, Model, Cwd, Project string
Mode agent.Mode
SessionID string
Voice bool
AlwaysAllow []string
TotalCost float64
}
Settings is a conversation's effective configuration: conversation overrides, then the project, then the defaults.
type Store ¶ added in v0.6.0
type Store interface {
Get(key string) store.Conversation
Update(key string, fn func(*store.Conversation)) error
AddSpend(user string, usd float64) error
Spend(user string) (today, month float64)
}
Store persists conversations and spend.