command

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package command implements shared slash-command handling for chat UIs.

The Handler processes commands like /model, /session, /reset, /help etc. and works with any ui.Context so the same logic can be used by terminal, Telegram, and other frontends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	GetSession(ctx context.Context, id string) (*schema.Session, error)
	CreateSession(ctx context.Context, meta schema.SessionMeta) (*schema.Session, error)
	UpdateSession(ctx context.Context, id string, meta schema.SessionMeta) (*schema.Session, error)
	DeleteSession(ctx context.Context, id string) error
	ListSessions(ctx context.Context, opts ...opt.Opt) (*schema.ListSessionResponse, error)
	ListModels(ctx context.Context, opts ...opt.Opt) (*schema.ListModelsResponse, error)
	ListTools(ctx context.Context, opts ...opt.Opt) (*schema.ListToolResponse, error)
}

Client is the minimal API surface needed by the command handler. *httpclient.Client satisfies this interface.

type Handler

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

Handler processes slash commands against the API.

func New

func New(client Client, hooks Hooks) *Handler

New creates a command handler with the given API client and optional hooks.

func (*Handler) Handle

func (h *Handler) Handle(ctx context.Context, evt ui.Event, sessionID *string) error

Handle processes a slash command event and returns an error if the command fails. The sessionID pointer is updated in place when the session changes.

type Hooks

type Hooks interface {
	// OnSessionChanged is called when the active session changes
	// (via /session <id> or /reset). The frontend can persist the
	// new session ID or update its display.
	OnSessionChanged(sessionID string)

	// OnSessionReset is called after /reset creates a new session.
	// The frontend can clear its message history.
	OnSessionReset()

	// ResetMeta returns extra session metadata to include when /reset
	// creates a new session (e.g. labels, name). Return nil for defaults.
	ResetMeta() *schema.SessionMeta
}

Hooks allows frontends to inject UI-specific behaviour into certain commands. All methods are optional - nil Hooks is safe.

Jump to

Keyboard shortcuts

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