state

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager manages persistent state with atomic saves.

Several managers can share one state file — the agent's, the heartbeat's and the device service's — so a manager reads the file again on every get and before every set: each sees what the others wrote.

func NewManager

func NewManager(workspace string) *Manager

NewManager creates a new state manager for the given workspace.

func (*Manager) GetLastChannel

func (sm *Manager) GetLastChannel() string

GetLastChannel returns the last channel from the state.

func (*Manager) GetLastChatID

func (sm *Manager) GetLastChatID() string

GetLastChatID returns the last chat ID from the state.

func (*Manager) GetOwnerChat

func (sm *Manager) GetOwnerChat() (channel, chatID string)

GetOwnerChat returns the chat the owner last wrote from; both are empty when none is known.

func (*Manager) GetTimestamp

func (sm *Manager) GetTimestamp() time.Time

GetTimestamp returns the timestamp of the last state update.

func (*Manager) SetLastChannel

func (sm *Manager) SetLastChannel(channel string) error

SetLastChannel records the last channel and saves the state. The file is written only when the channel changed: every turn records its channel, and most turns come from the channel the previous one did.

func (*Manager) SetLastChatID

func (sm *Manager) SetLastChatID(chatID string) error

SetLastChatID records the last chat ID and saves the state when it changed.

func (*Manager) SetOwnerChat

func (sm *Manager) SetOwnerChat(channel, chatID string) error

SetOwnerChat records the chat the owner last wrote from, saving the state when it changed.

type State

type State struct {
	// LastChannel is the last channel used for communication
	LastChannel string `json:"last_channel,omitempty"`

	// LastChatID is the last chat ID used for communication
	LastChatID string `json:"last_chat_id,omitempty"`

	// OwnerChannel and OwnerChatID name the chat the owner last wrote from:
	// where notices meant for the owner, and approval requests, go.
	OwnerChannel string `json:"owner_channel,omitempty"`
	OwnerChatID  string `json:"owner_chat_id,omitempty"`

	// Timestamp is the last time this state was updated
	Timestamp time.Time `json:"timestamp"`
}

State represents the persistent state for a workspace. It includes information about the last active channel/chat.

Jump to

Keyboard shortcuts

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