shared

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const APrefix = "secai"

Variables

View Source
var (
	FromAssistant = From{"assistant"}
	FromSystem    = From{"system"}
	FromUser      = From{"user"}
	FromNarrator  = From{"narrator"}
	FromKind      = 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
	// Buttons are a list of buttons to be displayed in the UI.
	Buttons    []StoryButton `log:"buttons"`
	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
	// UI is a UI implementation.
	UI UI
	// 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      []StoryButton `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 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 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 StoryButsByIdx added in v0.2.0

type StoryButsByIdx []StoryButton

func (StoryButsByIdx) Len added in v0.2.0

func (s StoryButsByIdx) Len() int

func (StoryButsByIdx) Less added in v0.2.0

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

func (StoryButsByIdx) Swap added in v0.2.0

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

type StoryButton added in v0.2.0

type StoryButton 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 (StoryButton) String added in v0.2.0

func (s StoryButton) String() string

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 Agent machine.
	LastActiveTicks uint64
}

func (StoryInfo) String added in v0.2.0

func (s StoryInfo) String() string

type UI added in v0.2.0

type UI interface {
	Start(dispose func() error) error
	Stop() error
	Mach() *am.Machine
	UIMach() *am.Machine
	Init(ui UI, screen tcell.Screen, name string) error
	BindHandlers() error
	Redraw()
	Logger() *slog.Logger
}

UI is the common interface for all UI implementations.

Jump to

Keyboard shortcuts

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