shared

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvConfig config location
	EnvConfig = "SECAI_CONFIG"
	// EnvAgentDir secai monorepo dir
	EnvAgentDir = "SECAI_AGENT_DIR"
	EnvNoDotEnv = "SECAI_NO_DOTENV"
)
View Source
const APrefix = "secai"

Variables

View Source
var (
	FromAssistant = From{"assistant"}
	FromSystem    = From{"system"}
	FromUser      = From{"user"}
	FromNarrator  = From{"narrator"}

	FromEnum = enum.New(FromAssistant, FromSystem, FromUser)
)

Functions

func LogArgs added in v0.2.0

func LogArgs(args am.A) map[string]string

LogArgs is an args logger for A and [secai.A].

func MachTelemetry

func MachTelemetry(mach *am.Machine, logArgs am.LogArgsMapperFn)

func Map

func Map[A, B any](vals []A, f func(A) B) []B

Map maps vals through f and returns a list of returned values from f.

func NumRef added in v0.2.0

func NumRef(text string) int

NumRef returns a number reference from the passed text, or -1 if none found.

func P

func P(txt string, args ...any)

P formats and prints the given string after de-denting and trimming it, and returns the number of bytes written and any error.

func PascalCase added in v0.2.0

func PascalCase(in string) string

PascalCase converts the input string to pascal case, matching the naming convention of state names.

func Pass added in v0.2.0

func Pass(args *A) am.A

Pass prepares am.A from A to pass to further mutations.

func PassRpc added in v0.2.0

func PassRpc(args *A) am.A

PassRpc prepares am.A from A to pass over RPC.

func RemoveStyling added in v0.2.0

func RemoveStyling(str string) string

func RevertPascalCase added in v0.2.0

func RevertPascalCase(in string) string

func Sj

func Sj(parts ...string) string

Sj is a string join and will join passed string args with a space.

func Sl

func Sl(txt string, args ...any) string

Sl is a string line - expands txt with args and ends with a newline.

func SlicesWithout added in v0.2.0

func SlicesWithout[S ~[]E, E comparable](coll S, el E) S

func Sp

func Sp(txt string, args ...any) string

Sp formats a de-dented and trimmed string using the provided arguments, similar to fmt.Sprintf.

Types

type A added in v0.2.0

type A struct {
	// ID is a general string ID param.
	ID string `log:"id"`
	// Addr is a network address.
	Addr string `log:"addr"`
	// Timeout is a generic timeout.
	Timeout time.Duration `log:"timeout"`
	// Prompt is a prompt to be sent to LLM.
	Prompt string `log:"prompt"`
	// IntByTimeout means the interruption was caused by timeout.
	IntByTimeout bool `log:"int_by_timeout"`
	// Msg is a single message with an author and text.
	Msg *Msg `log:"msg"`
	// Perform additional checks via LLM
	CheckLLM bool `log:"check_llm"`
	// List of choices
	Choices []string
	// Actions are a list of buttons to be displayed in the UI.
	Actions    []StoryAction `log:"actions"`
	Stories    []StoryInfo   `log:"stories"`
	StatesList []string      `log:"states_list"`
	// ActivateList is a list of booleans for StatesList, indicating an active state at the given index.
	ActivateList []bool `log:"activate_list"`

	// Result is a buffered channel to be closed by the receiver
	Result chan<- am.Result
	// DBQuery is a function that executes a query on the database.
	DBQuery func(ctx context.Context) error
	// RetStr returns dereferenced user prompts based on the list of offer.
	RetOfferRef chan<- *OfferRef
	SSHServer   *ssh.Server
	SSHSess     ssh.Session
	// Done is a buffered channel to be closed by the receiver
	Done chan<- struct{}
}

A is a struct for node arguments. It's a typesafe alternative to am.A.

func ParseArgs added in v0.2.0

func ParseArgs(args am.A) *A

ParseArgs extracts A from am.Event.ArgsAPrefix.

type ARpc added in v0.2.0

type ARpc struct {
	// ID is a general string ID param.
	ID string `log:"id"`
	// Addr is a network address.
	Addr string `log:"addr"`
	// Timeout is a generic timeout.
	Timeout time.Duration `log:"timeout"`
	// Prompt is a prompt to be sent to LLM.
	Prompt string `log:"prompt"`
	// IntByTimeout means the interruption was caused by timeout.
	IntByTimeout bool `log:"int_by_timeout"`
	// Msg is a single message with an author and text.
	Msg *Msg `log:"msg"`
	// Perform additional checks via LLM
	CheckLLM bool `log:"check_llm"`
	// List of choices
	Choices []string
	// Buttons are a list of buttons to be displayed in the UI.
	Buttons      []StoryAction `log:"buttons"`
	Stories      []StoryInfo   `log:"stories"`
	StatesList   []string      `log:"states_list"`
	ActivateList []bool        `log:"activate_list"`
	Result       am.Result
}

ARpc is a subset of am.A that can be passed over RPC.

type Config added in v0.4.0

type Config struct {
	AI    ConfigAI
	Agent ConfigAgent
	TUI   ConfigTUI
	Tools ConfigTools
	Debug ConfigDebug
}

func ConfigDefault added in v0.4.0

func ConfigDefault() Config

type ConfigAI added in v0.4.0

type ConfigAI struct {
	OpenAI []ConfigAIOpenAI `kdl:"OpenAI,multiple"`
	Gemini []ConfigAIGemini `kdl:"Gemini,multiple"`
	// Max LLM requests per session.
	ReqLimit int
}

type ConfigAIGemini added in v0.4.0

type ConfigAIGemini struct {
	Key      string
	Disabled bool
	Model    string
	Tags     []string
	Retries  int
}

func ConfigDefaultGemini added in v0.4.0

func ConfigDefaultGemini() ConfigAIGemini

type ConfigAIOpenAI added in v0.4.0

type ConfigAIOpenAI struct {
	Key      string
	Disabled bool
	URL      string
	Model    string
	Tags     []string
	Retries  int
}

func ConfigDefaultOpenAI added in v0.4.0

func ConfigDefaultOpenAI() ConfigAIOpenAI

type ConfigAgent added in v0.4.0

type ConfigAgent struct {
	// bot ID
	ID    string
	Label string
	// // dir for tmp files, defaults to CWD
	Dir     string
	Intro   string
	Log     ConfigAgentLog
	History ConfigAgentHistory
}

type ConfigAgentHistory added in v0.4.0

type ConfigAgentHistory struct {
	Backend string
	// TODO BackendParsed enum
	Max int
}

type ConfigAgentLog added in v0.4.0

type ConfigAgentLog struct {
	// duplicate to state-machine log
	Machine bool
	// path to the log file
	File string
	// log level 0-5
	Level   am.LogLevel
	Prompts bool
}

type ConfigDebug added in v0.4.0

type ConfigDebug struct {
	// display extra info about these stories in the machine log
	Story []string `kdl:",multiple"`
	// Run the mock scenarios (if any)
	Mock bool
	// Enable misc debugging modes (eg SQL history)
	Misc bool
	// Enable REPL for each machine
	REPL bool
	// Enable debugging in am-dbg ("1" expands to default). am-dbg has to be started BEFORE the bot.
	DBGAddr string
}

type ConfigSearXNG added in v0.4.0

type ConfigSearXNG struct {
	// Port to start a local instance on
	Port string
	// URL of an existing instance (disabled Port).
	URL string
}

type ConfigTUI added in v0.4.0

type ConfigTUI struct {
	// SSH port
	Port int
	// SSH host
	Host string
	// Number of transitions to show on the clock
	ClockRange int
}

type ConfigTools added in v0.4.0

type ConfigTools struct {
	SearXNG ConfigSearXNG
}

type From

type From enum.Member[string]

type Msg added in v0.2.0

type Msg struct {
	From      From
	Text      string
	CreatedAt time.Time
}

func NewMsg added in v0.2.0

func NewMsg(text string, from From) *Msg

func (*Msg) String added in v0.2.0

func (m *Msg) String() string

type OfferRef added in v0.2.0

type OfferRef struct {
	// Index from 0
	Index int
	Text  string
}

type Story added in v0.2.0

type Story[G any] struct {
	StoryInfo

	// If is an optional function used to confirm that this story can activate. It has access to the whole story struct,
	// so all the involved state machines and their historical snapshots (relative to activation and deactivation of
	// this story).
	CanActivate func(s *G) bool
}

func (*Story[G]) Check added in v0.2.0

func (s *Story[G]) Check() bool

func (*Story[G]) Clone added in v0.2.0

func (s *Story[G]) Clone() *Story[G]

func (*Story[G]) String added in v0.2.0

func (s *Story[G]) String() string

type StoryAction added in v0.4.0

type StoryAction struct {

	// Current value.
	Value func() int
	// Maximum value.
	ValueEnd func() int

	Label string
	Desc  string

	StateAdd    string
	StateRemove string

	VisibleCook amhelp.Cond
	VisibleMem  amhelp.Cond
	Action      func()
	IsDisabled  func() bool
	LabelEnd    string

	Pos         int
	PosInferred bool
}

func (StoryAction) String added in v0.4.0

func (s StoryAction) String() string

type StoryActionsByIdx added in v0.4.0

type StoryActionsByIdx []StoryAction

func (StoryActionsByIdx) Len added in v0.4.0

func (s StoryActionsByIdx) Len() int

func (StoryActionsByIdx) Less added in v0.4.0

func (s StoryActionsByIdx) Less(i, j int) bool

func (StoryActionsByIdx) Swap added in v0.4.0

func (s StoryActionsByIdx) Swap(i, j int)

type StoryActor added in v0.2.0

type StoryActor struct {
	Mach *am.Machine

	// actor's time when the story activated
	TimeActivated   am.Time
	TimeDeactivated am.Time

	// When these conditions are met, the story will activate itself.
	Trigger amhelp.Cond
}

StoryActor is a binding between a Story and an actor (state machine).

type StoryImpl added in v0.2.0

type StoryImpl[G any] interface {
	Clone() *G
}

type StoryInfo added in v0.2.0

type StoryInfo struct {
	// Name of the bound state (eg StoryFoo).
	State string
	// Tick is the current tick of the bound state.
	Tick uint64
	// Epoch is the sum of all previous memories, before a replacement.
	Epoch uint64

	// Title of this story.
	Title string
	// Description of this story.
	Desc string

	// The story was last deactivated at this human time.
	DeactivatedAt time.Time
	// The story was last active for this many ticks of the AgentLLM machine.
	LastActiveTicks uint64
}

func (StoryInfo) String added in v0.2.0

func (s StoryInfo) String() string

Jump to

Keyboard shortcuts

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