api

package
v0.80.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleSystem    = "system"
	RoleAssistant = "assistant"
	RoleUser      = "user"
)
View Source
const (
	VarsEnvContainer = "container"
	VarsEnvHost      = "host"
)
View Source
const (
	ContentTypeImageB64 = "img/base64"
)

Variables

View Source
var Levels = []Level{L1, L2, L3, Image, TTS}
View Source
var TemplateMimeTypes = []string{"text/x-go-template", "x-go-template", "template", "tpl"}

Functions

func Abbreviate added in v0.1.1

func Abbreviate(s string, maxLen int) string

Abbreviate trims the string, keeping the beginning and end if exceeding maxLen. after replacing newlines with '.'

func Cat added in v0.1.1

func Cat(a, b, sep string) string

func DataURL added in v0.1.1

func DataURL(mime string, raw []byte) string

https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data data:[<media-type>][;base64],<data>

func DecodeDataURL added in v0.1.1

func DecodeDataURL(dataURL string) (string, error)

DecodeDataURL decodes a data URL and extracts the data as a string. It supports optional media types and base64 encoding, ensuring the "data:" prefix is present.

func GetArrayProp added in v0.1.1

func GetArrayProp(key string, props map[string]any) ([]string, error)

func GetBoolProp added in v0.1.1

func GetBoolProp(key string, props map[string]any) (bool, error)

func GetIntProp added in v0.1.1

func GetIntProp(key string, props map[string]any) (int, error)

func GetMapProp added in v0.1.1

func GetMapProp(key string, props map[string]any) (map[string]any, error)

func GetStrProp added in v0.1.1

func GetStrProp(key string, props map[string]any) (string, error)

func IsRequired added in v0.1.1

func IsRequired(key string, props map[string]any) bool

if required properties is not missing and is an array of strings check if the required properties are present

func IsTemplate added in v0.1.1

func IsTemplate(v any) bool

check #! or // magic for large block of text {{ contained within for oneliner

func IsURI added in v0.1.1

func IsURI(s string) bool

Check if ':' exists within the first 8 characters e.g: data:, file:/// https://

func LoadURIContent added in v0.1.1

func LoadURIContent(ws Workspace, uri string) (string, error)

Load data from uri. Support file:// and data: protocols TODO enforce protocol requiremnt? If no protocol is specified, assumse local file path.

func LogLevelToString added in v0.1.1

func LogLevelToString(level LogLevel) string

func MimeToString added in v0.1.1

func MimeToString(mime string, content []byte) string

func NewBadRequestError added in v0.1.1

func NewBadRequestError(msg string) error

func NewInternalServerError added in v0.1.1

func NewInternalServerError(msg string) error

func NewNotFoundError added in v0.1.1

func NewNotFoundError(msg string) error

func NewUnauthorizedError added in v0.1.1

func NewUnauthorizedError(msg string) error

func NewUnsupportedError added in v0.1.1

func NewUnsupportedError(msg string) error

func ParseMimeType added in v0.1.1

func ParseMimeType(s string) (string, string)

Check for mime-type specification. Returns content and mime type. remove first line for multiline text

func ParseStringArray added in v0.1.1

func ParseStringArray(s string) []string

try parse string into an array of string in the following formats: a,b,c... [a,b,c,] intended for parsing commandline actins list

func ToError added in v0.1.1

func ToError(v any) error

func ToInt added in v0.1.1

func ToInt(data any) int

func ToMap added in v0.1.1

func ToMap(obj any) (map[string]any, error)

func ToString added in v0.1.1

func ToString(data any) string

func ToStringArray added in v0.1.1

func ToStringArray(obj any) []string

return an array of strings. try unmarshal obj if it is encoded in json format. return an empty array if obj is neither an array nor json array.

Types

type ATMSupport added in v0.1.1

type ATMSupport interface {
	AssetStore
	RetrieveAgent(owner, pack string) (*Record, error)
	ListAgents(owner string) ([]*Record, error)
	// SearchAgent(owner, pack string) (*Record, error)
	RetrieveTool(owner, kit string) (*Record, error)
	ListTools(owner string) ([]*Record, error)
	RetrieveModel(owner, alias string) (*Record, error)
	ListModels(owner string) ([]*Record, error)
}

agent/tool/model methods

type Action added in v0.1.1

type Action struct {
	// unique tool call identifier
	ID string `json:"id"`

	// command name: (agent/tool/command)
	// agent:pack/sub
	// kit:name
	// bin:/command
	Name string `json:"name"`

	// arguments including name
	Arguments Arguments `json:"arguments"`
}

TODO split name into kit, name|pack/sub|command command line: [ACTION] [OPTIONS] MESSAGE...

type ActionRunner added in v0.1.1

type ActionRunner interface {
	Run(context.Context, string, map[string]any) (any, error)
}

type AdapterRegistry added in v0.1.1

type AdapterRegistry interface {
	Get(key string) (LLMAdapter, error)
}

type Agent

type Agent struct {

	// Package name
	Pack string `json:"pack"`

	// Agent name
	Name string `json:"name"`

	Display     string `json:"display"`
	Description string `json:"description"`

	// templated values
	// these should not be in the args map
	Instruction string `json:"instruction"`
	Context     string `json:"context"`
	Message     string `json:"message"`

	// The model to be used by the agent
	// TODO map or list for supporting multi features
	Model *Model `json:"model"`

	// Functions that the agent can call
	Tools []*ToolFunc `json:"tools"`

	// LLM adapter
	Adapter string `json:"adapter"`

	// inheritance
	Embed []*Agent `json:"-"`

	// exported global values
	// Environment map[string]any
	Environment *Environment `json:"environment"`

	// default values
	Arguments Arguments `json:"arguments"`

	Parameters Parameters `json:"parameters"`

	// assigned at buildtime/runtime
	Parent   *Agent             `json:"-"`
	Runner   ActionRunner       `json:"-"`
	Shell    ActionRunner       `json:"-"`
	Template *template.Template `json:"-"`

	Config *AppConfig `json:"-"`
}

func (*Agent) Clone added in v0.5.0

func (a *Agent) Clone() *Agent

for reusing cached agent

type AgentConfig

type AgentConfig struct {
	Display     string `yaml:"display" json:"display"`
	Description string `yaml:"description" json:"description"`

	// tools defined in tools config
	// kit:name
	Functions []string `yaml:"functions" json:"functions"`

	// chat|image|docker/aider oh gptr
	Adapter string `yaml:"adapter" json:"adapter"`

	// default agents config
	// sub name only
	Name      string         `yaml:"name" json:"name"`
	Arguments map[string]any `yaml:"arguments" json:"arguments"`

	//
	Instruction string `yaml:"instruction" json:"instruction"`
	Context     string `yaml:"context" json:"context"`
	Message     string `yaml:"message" json:"message"`

	Model string `yaml:"model" json:"model"`

	//
	MaxTurns int `yaml:"max_turns" json:"max_turns"`
	MaxTime  int `yaml:"max_time" json:"max_time"`

	// memory
	// max history: 0 max span: 0
	// New        *bool  `yaml:"new,omitempty"`
	MaxHistory int `yaml:"max_history" json:"max_history"`
	MaxSpan    int `yaml:"max_span" json:"max_span"`

	// logging: quiet | info[rmative] | verbose | trace
	LogLevel string `yaml:"log_level" json:"log_level"`

	// agent as tool
	Parameters Parameters `yaml:"parameters" json:"parameters"`

	// agent global vars
	Environment map[string]any `yaml:"environment" json:"environment"`

	// inherit from embedded parent:
	// + environment
	// + instruction
	// + context
	//
	// + model
	// + functions
	// local scope:
	// - arguments
	// - message
	// - parameters
	Embed []string `yaml:"embed" json:"embed"`

	//
	Entrypoint []string `yaml:"entrypoint" json:"entrypoint"`

	Config *AppConfig `json:"-"`
}

func (*AgentConfig) ToMap added in v0.1.1

func (ac *AgentConfig) ToMap() map[string]any

type App added in v0.1.1

type App struct {
	// app root. default: $HOME/.ai/
	Base string

	// auth email
	User string

	Session string
}

type AppConfig

type AppConfig struct {

	// ActionConfig
	//
	// kit specifies a namespace for the action
	// examples:
	// class name
	// MCP server name
	// file system
	// container name
	// virtual machine name
	// tool/function (Gemini)
	Kit string `yaml:"kit" json:"kit"`

	// action type:
	// func, system, agent...
	Type string `yaml:"type" json:"type"`

	// user message
	Message string `yaml:"message" json:"message"`

	// system prompt
	Instruction string `yaml:"instruction" json:"instruction"`

	// set/level key - not the LLM model
	Model string `yaml:"model" json:"model"`

	//
	MaxTurns int `yaml:"max_turns" json:"max_turns"`
	MaxTime  int `yaml:"max_time" json:"max_time"`

	// output format: json | text
	Format string `yaml:"format" json:"format"`

	// memory context
	MaxHistory int    `yaml:"max_history" json:"max_history"`
	MaxSpan    int    `yaml:"max_span" json:"max_span"`
	Context    string `yaml:"context" json:"context"`

	// logging: quiet | informative | verbose
	LogLevel string `yaml:"log_level" json:"log_level"`

	//
	Pack string `yaml:"pack" json:"pack"`

	Agents []*AgentConfig `yaml:"agents" json:"agents"`

	// tool / model provider
	Provider string `yaml:"provider" json:"provider"`
	BaseUrl  string `yaml:"base_url" json:"base_url"`

	// api token lookup key
	ApiKey string `yaml:"api_key" json:"api_key"`

	// action type:
	// func, system, agent...
	// Type  string        `yaml:"type"`
	Tools []*ToolConfig `yaml:"tools" json:"tools"`

	// modelset name
	Set    string                  `yaml:"set" json:"set"`
	Models map[string]*ModelConfig `yaml:"models" json:"models"`

	// The raw data for this config
	RawContent []byte `yaml:"-" json:"-"`

	// TODO for debugging
	Source string `yaml:"-" json:"-"`

	Store AssetStore `yaml:"-" json:"-"`
	// relative to store root
	BaseDir string `yaml:"-" json:"-"`
}

func (*AppConfig) HasInput

func (cfg *AppConfig) HasInput() bool

func (*AppConfig) IsInformative added in v0.1.1

func (cfg *AppConfig) IsInformative() bool

func (*AppConfig) IsQuiet added in v0.1.1

func (cfg *AppConfig) IsQuiet() bool

func (*AppConfig) IsTracing added in v0.1.1

func (cfg *AppConfig) IsTracing() bool

func (*AppConfig) IsVerbose added in v0.1.1

func (cfg *AppConfig) IsVerbose() bool

func (*AppConfig) ToMap added in v0.1.1

func (ac *AppConfig) ToMap() map[string]any

ToMap converts AppConfig to a map[string]any map only the fileds common in action config and only for non zero values.

type ArgMap added in v0.1.1

type ArgMap map[string]any

func NewArgMap added in v0.1.1

func NewArgMap() ArgMap

func (ArgMap) Action added in v0.1.1

func (a ArgMap) Action() *Action

func (ArgMap) Actions added in v0.1.1

func (a ArgMap) Actions() []string

func (ArgMap) Agent added in v0.1.1

func (a ArgMap) Agent() *Agent

check and return an instance of agent.

func (ArgMap) Arg added in v0.1.1

func (a ArgMap) Arg(key string) any

func (ArgMap) DeleteHitory added in v0.1.1

func (a ArgMap) DeleteHitory()

func (ArgMap) FlowType added in v0.30.0

func (a ArgMap) FlowType() FlowType

func (ArgMap) Get added in v0.1.1

func (v ArgMap) Get(key string) any

taken from viper@1.21.0

func (ArgMap) GetBool added in v0.1.1

func (v ArgMap) GetBool(key string) bool

func (ArgMap) GetDuration added in v0.1.1

func (v ArgMap) GetDuration(key string) time.Duration

func (ArgMap) GetFloat64 added in v0.1.1

func (v ArgMap) GetFloat64(key string) float64

func (ArgMap) GetInt added in v0.1.1

func (v ArgMap) GetInt(key string) int

func (ArgMap) GetInt32 added in v0.1.1

func (v ArgMap) GetInt32(key string) int32

func (ArgMap) GetInt64 added in v0.1.1

func (v ArgMap) GetInt64(key string) int64

func (ArgMap) GetIntSlice added in v0.1.1

func (v ArgMap) GetIntSlice(key string) []int

func (ArgMap) GetString added in v0.1.1

func (v ArgMap) GetString(key string) string

func (ArgMap) GetStringMap added in v0.1.1

func (v ArgMap) GetStringMap(key string) map[string]any

func (ArgMap) GetStringMapString added in v0.1.1

func (v ArgMap) GetStringMapString(key string) map[string]string

func (ArgMap) GetStringMapStringSlice added in v0.1.1

func (v ArgMap) GetStringMapStringSlice(key string) map[string][]string

func (ArgMap) GetStringSlice added in v0.1.1

func (v ArgMap) GetStringSlice(key string) []string

func (ArgMap) GetTime added in v0.1.1

func (v ArgMap) GetTime(key string) time.Time

func (ArgMap) GetUint added in v0.1.1

func (v ArgMap) GetUint(key string) uint

func (ArgMap) GetUint8 added in v0.1.1

func (v ArgMap) GetUint8(key string) uint8

func (ArgMap) GetUint16 added in v0.1.1

func (v ArgMap) GetUint16(key string) uint16

func (ArgMap) GetUint32 added in v0.1.1

func (v ArgMap) GetUint32(key string) uint32

func (ArgMap) GetUint64 added in v0.1.1

func (v ArgMap) GetUint64(key string) uint64

func (ArgMap) HasHistory added in v0.1.1

func (a ArgMap) HasHistory() bool

func (ArgMap) HasPrompt added in v0.1.1

func (a ArgMap) HasPrompt() bool

func (ArgMap) HasQuery added in v0.1.1

func (a ArgMap) HasQuery() bool

func (ArgMap) History added in v0.1.1

func (a ArgMap) History() []*Message

func (ArgMap) Kitname added in v0.1.1

func (a ArgMap) Kitname() Kitname

func (ArgMap) Message added in v0.1.1

func (a ArgMap) Message() string

func (ArgMap) Prompt added in v0.1.1

func (a ArgMap) Prompt() string

func (ArgMap) Query added in v0.1.1

func (a ArgMap) Query() string

func (ArgMap) SetArg added in v0.1.1

func (a ArgMap) SetArg(key string, value any) ArgMap

func (ArgMap) SetHistory added in v0.1.1

func (a ArgMap) SetHistory(messages []*Message) ArgMap

func (ArgMap) SetPrompt added in v0.1.1

func (a ArgMap) SetPrompt(prompt any) ArgMap

func (ArgMap) SetQuery added in v0.1.1

func (a ArgMap) SetQuery(query any) ArgMap

func (ArgMap) Type added in v0.1.1

func (a ArgMap) Type() string

type Arguments added in v0.1.1

type Arguments = ArgMap

func NewArguments added in v0.1.1

func NewArguments() Arguments

func (Arguments) AddArgs added in v0.1.1

func (r Arguments) AddArgs(args map[string]any) Arguments

func (Arguments) Clone added in v0.11.1

func (r Arguments) Clone() Arguments

func (Arguments) Copy added in v0.1.1

func (r Arguments) Copy(dst map[string]any) Arguments

Copye all key/value pairs to dst

func (Arguments) Get2 added in v0.1.1

func (r Arguments) Get2(key string) (any, bool)

TODO get rid of this

func (Arguments) GetArgs added in v0.1.1

func (r Arguments) GetArgs(keys []string) map[string]any

Return args specified by keys

func (Arguments) SetArgs added in v0.1.1

func (r Arguments) SetArgs(args map[string]any) Arguments

clear all entries and copy args while maintaining the same old reference

type AssetFS added in v0.1.1

type AssetFS interface {
	AssetStore
	ReadDir(name string) ([]DirEntry, error)
	ReadFile(name string) ([]byte, error)
	Resolve(parent string, name string) string
}

type AssetManager added in v0.1.1

type AssetManager interface {
	// GetStore(key string) (AssetStore, error)
	AddStore(store AssetStore)

	// SearchAgent(owner, pack string) (*Record, error)
	ListAgent(owner string) (map[string]*AppConfig, error)
	FindAgent(owner, pack string) (*AppConfig, error)
	ListToolkit(owner string) (map[string]*AppConfig, error)
	FindToolkit(owner string, kit string) (*AppConfig, error)
	ListModels(owner string) (map[string]*AppConfig, error)
	FindModels(owner string, alias string) (*AppConfig, error)
}

type AssetStore

type AssetStore any

type BadRequestError added in v0.1.1

type BadRequestError struct {
	Message string
}

func (*BadRequestError) Error added in v0.1.1

func (e *BadRequestError) Error() string

type Blob added in v0.1.1

type Blob struct {
	ID       string         `json:"id"`
	MimeType string         `json:"mime_type"`
	Content  []byte         `json:"content"`
	Meta     map[string]any `json:"meta"`
}

https://en.wikipedia.org/wiki/Media_type https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types https://mimesniff.spec.whatwg.org/

type BlobStore added in v0.1.1

type BlobStore interface {
	Put(ID string, blob *Blob) error
	Get(ID string) (*Blob, error)
	Presign(ID string) (string, error)
}

Object store

type CallLogEntry added in v0.1.1

type CallLogEntry struct {
	// tool call
	Kit       string         `json:"kit"`
	Name      string         `json:"name"`
	Arguments map[string]any `json:"arguments"`

	// active agent
	Agent string `json:"agent"`

	// failure
	Error error `json:"error"`

	// success
	Result *Result `json:"result"`

	Started time.Time `json:"started"`
	Ended   time.Time `json:"ended"`
}

type CallLogger added in v0.1.1

type CallLogger interface {
	Base() string
	Save(*CallLogEntry)
}

type ClipboardProvider

type ClipboardProvider interface {
	Clear() error
	Read() (string, error)
	Get() (string, error)
	Write(string) error
	Append(string) error
}

type ConnectorConfig added in v0.0.2

type ConnectorConfig struct {

	// optional as of now
	Provider string `yaml:"provider"`

	BaseUrl string `yaml:"base_url"`
	// name of api lookup key
	ApiKey string `yaml:"api_key"`
}

type ContextKey added in v0.1.1

type ContextKey string
const SwarmUserContextKey ContextKey = "swarm_user"

type DHNTConfig added in v0.1.1

type DHNTConfig struct {
	// base where this config loaded from. default $HOME/.ai/
	// filename: dhnt.json
	Base string `json:"-"`

	// additional work spaces
	Roots *Roots `json:"roots"`

	Blob   *ResourceConfig   `json:"blob"`
	Assets []*ResourceConfig `json:"assets"`
}

func LoadDHNTConfig added in v0.1.1

func LoadDHNTConfig(conf string) (*DHNTConfig, error)

func (*DHNTConfig) GetRoots added in v0.1.1

func (r *DHNTConfig) GetRoots() ([]*Root, error)

Return root paths

type DirEntry

type DirEntry = fs.DirEntry

Resource Store

func NewDirEntry

func NewDirEntry(
	name string,
	isDir bool,
	mode uint32,
	info *FileInfo,
) DirEntry

type DirEntryInfo

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

func FsDirEntryInfo

func FsDirEntryInfo(de fs.DirEntry) *DirEntryInfo

func (*DirEntryInfo) Info

func (r *DirEntryInfo) Info() (fs.FileInfo, error)

func (*DirEntryInfo) IsDir

func (r *DirEntryInfo) IsDir() bool

func (DirEntryInfo) MarshalJSON

func (r DirEntryInfo) MarshalJSON() ([]byte, error)

func (*DirEntryInfo) Name

func (r *DirEntryInfo) Name() string

func (*DirEntryInfo) Type

func (r *DirEntryInfo) Type() fs.FileMode

func (*DirEntryInfo) UnmarshalJSON

func (r *DirEntryInfo) UnmarshalJSON(data []byte) error

type EditorProvider

type EditorProvider interface {
	Launch(string) (string, error)
}

type Environment added in v0.1.1

type Environment struct {
	Env map[string]any `json:"env"`
	// contains filtered or unexported fields
}

func NewEnvironment added in v0.1.1

func NewEnvironment() *Environment

func (*Environment) AddEnvs added in v0.1.1

func (g *Environment) AddEnvs(src map[string]any)

copy all src values to the environment env

func (*Environment) Apply added in v0.1.1

func (g *Environment) Apply(fn func(map[string]any) error) error

thread safe access to the env

func (*Environment) Clone added in v0.11.1

func (g *Environment) Clone() *Environment

func (*Environment) Copy added in v0.1.1

func (g *Environment) Copy(dst map[string]any)

copy all environment env to dst

func (*Environment) Get added in v0.1.1

func (g *Environment) Get(key string) (any, bool)

Return value for key

func (*Environment) GetAllEnvs added in v0.1.1

func (g *Environment) GetAllEnvs() map[string]any

Return all envs

func (*Environment) GetEnvs added in v0.1.1

func (g *Environment) GetEnvs(keys []string) map[string]any

Return envs specified by keys

func (*Environment) GetInt added in v0.1.1

func (g *Environment) GetInt(key string) int

Return int value for key, 0 if key is not set or value can not be converted to int

func (*Environment) GetString added in v0.1.1

func (g *Environment) GetString(key string) string

Return string value for key, empty if key it not set or value can not be converted to string

func (*Environment) Set added in v0.1.1

func (g *Environment) Set(key string, val any)

func (*Environment) SetEnvs added in v0.1.1

func (g *Environment) SetEnvs(envs map[string]any)

Clear all entries from the map and copy the new values while maintaining the same old reference.

func (*Environment) Unset added in v0.1.1

func (g *Environment) Unset(key string)

func (*Environment) UnsetEnvs added in v0.1.1

func (g *Environment) UnsetEnvs(keys []string)

type FileInfo

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

func FsFileInfo

func FsFileInfo(fi fs.FileInfo) *FileInfo

func NewFileInfo

func NewFileInfo(
	name string,
	size int64,
	mode uint32,
	modTime time.Time,
	isDir bool,
) *FileInfo

func (*FileInfo) IsDir

func (r *FileInfo) IsDir() bool

func (FileInfo) MarshalJSON

func (fi FileInfo) MarshalJSON() ([]byte, error)

func (*FileInfo) ModTime

func (r *FileInfo) ModTime() time.Time

func (*FileInfo) Mode

func (r *FileInfo) Mode() fs.FileMode

func (*FileInfo) Name

func (r *FileInfo) Name() string

func (*FileInfo) Size

func (r *FileInfo) Size() int64

func (*FileInfo) Sys

func (r *FileInfo) Sys() any

func (*FileInfo) UnmarshalJSON

func (fi *FileInfo) UnmarshalJSON(data []byte) error

type FlowType added in v0.1.1

type FlowType string
const (
	// FlowTypeSequence executes actions one after another, where each
	// subsequent action uses the previous action's response as input.
	FlowTypeSequence FlowType = "sequence"

	// FlowTypeChain Executes a series of actions consecutively, similar to the `sequence` flow.
	// The chain returns the result or error from the final action executed.
	// Chain actions ["a1", "a2", "a3", ...] translate to nested function calls: a1(a2(a3(...))).
	// Each action in the chain should accept a sub-action through the "action" parameter.
	FlowTypeChain FlowType = "chain"

	// FlowTypeChoice randomly selects and executes a single action.
	FlowTypeChoice FlowType = "choice"

	// FlowTypeParallel executes actions simultaneously, returning the combined results as a list.
	// This allows for concurrent processing of independent actions.
	FlowTypeParallel FlowType = "parallel"
)

func ToFlowType added in v0.30.0

func ToFlowType(v any) FlowType

type FuncBody added in v0.1.1

type FuncBody struct {
	// A MIME type (now properly called "media type", but also sometimes "content type")
	// is a string sent along with a file indicating the type of the file
	// (describing the content format, for example, a sound file might be labeled audio/ogg,
	// or an image file image/png).
	// https://developer.mozilla.org/en-US/docs/Glossary/MIME_type
	// tpl   text/x-go-template
	// uri   text/uri-list
	// md    text/markdown
	// txt   text/plain
	// go    application/x-go
	// yaml  application/yaml
	// sh    application/x-sh
	// json  application/json
	// js    text/javascript
	MimeType string `yaml:"mime_type" json:"mime_type"`
	Script   string `yaml:"script" json:"script"`
}

type Handler added in v0.1.0

type Handler interface {
	Serve(*Request, *Response) error
}

Action handler

type HandlerFunc added in v0.1.1

type HandlerFunc func(req *Request, res *Response) error

func (HandlerFunc) Serve added in v0.1.1

func (f HandlerFunc) Serve(req *Request, res *Response) error

type InputConfig added in v0.1.1

type InputConfig struct {
	Message string
	Args    []string

	Clipin     bool
	ClipWait   bool
	Clipout    bool
	ClipAppend bool
	Stdin      bool
}

type InternalServerError added in v0.1.1

type InternalServerError struct {
	Message string
}

func (*InternalServerError) Error added in v0.1.1

func (e *InternalServerError) Error() string

type Kitname added in v0.1.1

type Kitname string

Took Kit and Name ^[a-z0-9_]+$

func NewKitname added in v0.1.1

func NewKitname(kit, name string) Kitname

func (Kitname) Clean added in v0.1.1

func (r Kitname) Clean() Kitname

func (Kitname) Decode added in v0.1.1

func (r Kitname) Decode() (string, string)

kit__name kit:* kit:name agent:name @name @:name Decode removes slash command prefix and decodes the string into kit and name. For agents, the kit is literal "agent"

func (Kitname) ID added in v0.1.1

func (r Kitname) ID() string

^[a-z0-9_]+$

func (Kitname) String added in v0.1.1

func (r Kitname) String() string

type LLMAdapter added in v0.1.1

type LLMAdapter interface {
	Call(context.Context, *Request) (*Response, error)
}

type Level added in v0.0.3

type Level = string

Level represents the "intelligence" level of the model. i.e. basic, regular, advanced for example, OpenAI: gpt-4.1-mini, gpt-4.1, o3

const (
	// any of L1/L2/L3
	Any Level = "any"

	L1 Level = "L1"
	L2 Level = "L2"
	L3 Level = "L3"
	//
	Image Level = "image"
	TTS   Level = "tts"
)

type LogLevel added in v0.1.1

type LogLevel int
const (
	Quiet LogLevel = iota + 1
	Informative
	Verbose
	Tracing
)

func ToLogLevel added in v0.1.1

func ToLogLevel(level any) LogLevel

func (LogLevel) String added in v0.1.1

func (r LogLevel) String() string

type MemOption added in v0.0.3

type MemOption struct {
	MaxHistory int
	MaxSpan    int
	Offset     int
	Roles      []string
}

Memory store

func (*MemOption) String added in v0.1.1

func (r *MemOption) String() string

type MemStore added in v0.0.3

type MemStore interface {
	Save([]*Message) error
	Load(*MemOption) ([]*Message, error)
	Get(string) (*Message, error)
}

type Message

type Message struct {
	// message id
	ID string `json:"id"`

	// thread id
	Session string    `json:"session"`
	Created time.Time `json:"created"`

	// data
	ContentType string `json:"content_type"`
	Content     string `json:"content"`

	// system | assistant | user
	Role string `json:"role"`

	// user/provider
	Sender string `json:"sender"`

	// active/responsible agent
	Agent Packname `json:"agent"`

	//
	// TODO
	// context of recursive irrelevant historical context messages
	// rot the real intent of user
	// new context messages are created and sent as user role message to LLM but persisteed as "context"
	Context bool `json:"context"`
}

func ToMessages added in v0.1.1

func ToMessages(data any) []*Message

type Middleware added in v0.1.1

type Middleware func(*Agent, Handler) Handler

type Model

type Model struct {
	Set   string `json:"set"`
	Level Level  `json:"level"`

	Description string `json:"description"`

	// model @agent or resolved provider model name
	// example:
	//   @model
	//   gemini-2.0-flash-lite
	Model string `json:"model"`

	Provider string `json:"provider"`
	BaseUrl  string `json:"base_url"`

	// api token lookup key
	ApiKey string `json:"api_key"`
}

func (*Model) String added in v0.1.1

func (r *Model) String() string

type ModelConfig

type ModelConfig struct {
	// LLM model
	Model string `yaml:"model" json:"model"`

	// LLM service provider: openai | gemini | anthropic
	Provider string `yaml:"provider" json:"provider"`
	BaseUrl  string `yaml:"base_url" json:"base_url"`

	// name of api key for looking up api access token
	ApiKey string `yaml:"api_key" json:"api_key"`

	Description string `json:"description"`
}

type NotFoundError added in v0.1.1

type NotFoundError struct {
	Message string
}

func (*NotFoundError) Error added in v0.1.1

func (e *NotFoundError) Error() string

type Output

type Output struct {
	// agent emoji and name
	Display string `json:"display"`

	Content     string `json:"content"`
	ContentType string `json:"content_type"`
}

type Packname added in v0.1.1

type Packname string

@pack[/sub] agent:pack[/sub] @* name: ^[a-z0-9_:/]+$ id: ^[a-z0-9_]+$

func NewPackname added in v0.1.1

func NewPackname(pack, sub string) Packname

func (Packname) Clean added in v0.1.1

func (r Packname) Clean() Packname

Return a normalized version: pack/sub after removing slash command char '/', prefix and suffix [/]@pack[/sub] [/]agent:pack[/sub] ^[a-z0-9_/]+$

func (Packname) Decode added in v0.1.1

func (r Packname) Decode() (string, string)

return normalized pack/sub after cleaning. sub is the same as pack if empty

func (Packname) Equal added in v0.1.1

func (r Packname) Equal(s string) bool

func (Packname) ID added in v0.1.1

func (r Packname) ID() string

Return valid id for the agent suitable for use with external systems, e.g. LLM providers. agent:pack/sub is converted to agent__pack__sub ^[a-z0-9_]+$

func (Packname) String added in v0.1.1

func (r Packname) String() string

type Parameters added in v0.1.1

type Parameters map[string]any

type Record added in v0.1.1

type Record struct {
	ID uuid.UUID

	Owner   string
	Name    string
	Display string
	Content string

	// source
	Store AssetStore
}

type Request

type Request struct {
	// parent agent
	Agent *Agent `json:"-"`

	// active action name
	Name      string    `json:"name"`
	Arguments Arguments `json:"arguments"`

	// LLM
	Model *Model      `json:"model"`
	Tools []*ToolFunc `json:"tools"`

	Messages []*Message `json:"messages"`

	Runner ActionRunner `json:"-"`

	// get api token for LLM model
	Token func() string `json:"-"`

	//
	Prompt  string     `json:"prompt"`
	Query   string     `json:"query"`
	History []*Message `json:"history"`
	// contains filtered or unexported fields
}

func NewRequest added in v0.1.1

func NewRequest(ctx context.Context, name string, args map[string]any) *Request

func (*Request) Clone

func (r *Request) Clone() *Request

Clone returns a shallow copy of r while ensuring proper copying of slices and maps

func (*Request) Context

func (r *Request) Context() context.Context

Context returns the request's context. To change the context, use Request.WithContext.

The returned context is always non-nil; it defaults to the background context.

For outgoing client requests, the context controls cancellation.

For incoming server requests, the context is canceled when the client's connection closes, the request is canceled (with HTTP/2), or when the ServeHTTP method returns.

func (*Request) MaxTurns added in v0.1.1

func (r *Request) MaxTurns() int

func (*Request) MemOption added in v0.1.1

func (r *Request) MemOption() *MemOption

func (*Request) Message added in v0.1.1

func (r *Request) Message() string

func (*Request) SetMaxTurns added in v0.1.1

func (r *Request) SetMaxTurns(max int) *Request

func (*Request) WithContext

func (r *Request) WithContext(ctx context.Context) *Request

WithContext returns a shallow copy of r with its context changed to ctx. The provided ctx must be non-nil.

For outgoing client request, the context controls the entire lifetime of a request and its response: obtaining a connection, sending the request, and reading the response headers and body.

To create a new request with a context, use NewRequest. To make a deep copy of a request with a new context, use Request.Clone.

type Resource

type Resource struct {
	// web resource base url
	// http://localhost:18080/resource
	// https://ai.dhnt.io/resource
	Base string `json:"base"`

	// access token
	Token string `json:"token"`
}

type ResourceConfig added in v0.1.1

type ResourceConfig struct {
	Type  string `json:"type"`
	Base  string `json:"base"`
	Token string `json:"token"`
}

type Response

type Response struct {
	// A list of message objects generated during the conversation
	// with a sender field indicating which Agent the message originated from.
	Messages []*Message `json:"messages"`

	// The last agent to handle a message
	Agent *Agent `json:"agent"`

	Result *Result `json:"result"`
}

type Result

type Result struct {
	// author of the reponse: assistant
	Role string `json:"role"`
	// The result value as a string
	Value string `json:"value"`

	// media content
	// https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types
	MimeType string `json:"mime_type"`
	Content  []byte `json:"content"`

	// transition
	// The agent state
	State State `json:"state"`
	// The agent name to transfer to for StateTransfer
	NextAgent string `json:"next_agent"`

	//
	Actions []*ToolCall `json:"actions"`
}

Result encapsulates the possible return values for agent/function.

func Exec added in v0.1.1

func Exec(ctx context.Context, runner ActionRunner, args ArgMap) (*Result, error)

func ToResult added in v0.1.1

func ToResult(data any) *Result

func (*Result) String

func (r *Result) String() string

type Root added in v0.1.1

type Root struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	// Scheme      string `json:"scheme"`
	Path string `json:"path"`
}

https://modelcontextprotocol.io/specification/2025-06-18/client/roots https://www.rfc-editor.org/rfc/rfc3986 https://en.wikipedia.org/wiki/Uniform_Resource_Identifier URI = scheme ":" ["//" authority] path ["?" query] ["#" fragment]

type Roots added in v0.1.1

type Roots struct {
	// primary working directory for the agents
	Workspace *Root `json:"workspace"`

	// Add the current working directory to the root list
	// where ai is started
	Cwd *Root `json:"cwd"`

	// Add system temporary directory to the root list
	Temp *Root `json:"temp"`

	// Additional paths
	Dirs []*Root `json:"dirs"`
}

func (*Roots) AllowedDirs added in v0.1.1

func (r *Roots) AllowedDirs() ([]string, error)

convenience helper for collecting all accessible paths including symlink of the original path

func (*Roots) ResolveRoots added in v0.12.1

func (r *Roots) ResolveRoots() ([]*Root, error)

type SecretStore added in v0.1.1

type SecretStore interface {
	Get(owner, key string) (string, error)
}

type Setlevel added in v0.1.1

type Setlevel string

Model set and level ^[a-zA-Z0-9_]+$

func NewSetlevel added in v0.1.1

func NewSetlevel(set, level string) Setlevel

func (Setlevel) Decode added in v0.1.1

func (r Setlevel) Decode() (string, string)

return default/any for empty string

func (Setlevel) Equal added in v0.1.1

func (r Setlevel) Equal(s string) bool

func (Setlevel) String added in v0.1.1

func (r Setlevel) String() string

type State

type State int
const (
	StateExit State = iota

	// TODO terminate state for early tool call termination/cancclation
	StateTransfer
	StateInputWait
	StateToolCall
)

func ParseState

func ParseState(state string) State

func (State) Equal

func (s State) Equal(state string) bool

func (State) String

func (s State) String() string

type System added in v0.1.1

type System = vos.System

type TemplateFuncMap

type TemplateFuncMap = template.FuncMap

type ToolCall added in v0.1.1

type ToolCall Action

openai: ChatCompletionMessageToolCallUnion genai: FunctionCall anthropic: ToolUseBlock

func NewToolCall added in v0.1.1

func NewToolCall(id string, name string, args map[string]any) *ToolCall

type ToolCallEntry added in v0.1.1

type ToolCallEntry struct {
	ID        string         `json:"id"`
	Kit       string         `json:"kit"`
	Name      string         `json:"name"`
	Arguments map[string]any `json:"arguments"`

	Error  error `json:"error"`
	Result any   `json:"result"`

	Timestamp time.Time `json:"timestamp"`
}

func (*ToolCallEntry) ToJSON added in v0.1.1

func (r *ToolCallEntry) ToJSON() (string, error)

type ToolConfig

type ToolConfig struct {
	Type string `yaml:"type" json:"type"`

	Name        string `yaml:"name" json:"name"`
	Description string `yaml:"description" json:"description"`

	Parameters Parameters `yaml:"parameters" json:"parameters"`

	Body *FuncBody `yaml:"body" json:"body"`

	// agent name for agent tool type
	// description/parameters defined here take precedence
	Agent string `yaml:"agent" json:"agent"`

	//
	Provider string `yaml:"provider" json:"provider"`
	BaseUrl  string `yaml:"base_url" json:"base_url"`
	// api lookup key
	ApiKey string `yaml:"api_key" json:"api_key"`

	// filter by match key=values (comma, separated)
	// include all tools that match
	Filter map[string]string `yaml:"filter" json:"filter"`

	//
	Config *AppConfig `json:"-"`
}

type ToolFunc

type ToolFunc struct {
	Type        ToolType   `json:"type"`
	Kit         string     `json:"kit"`         // kit
	Name        string     `json:"name"`        // name
	Description string     `json:"description"` // description
	Parameters  Parameters `json:"parameters"`  // parameters

	Body *FuncBody `json:"body"` // body

	// agent name if this tool references an agent
	Agent string `json:"agent"`

	//
	State State `json:"state"`

	//
	Provider string `json:"provider"`
	BaseUrl  string `json:"base_url"` // base url
	// name of api key - used to resolve api key/token before tool call
	ApiKey string `json:"api_key"`

	// extra features.
	// e.g labels for mcp for filtering tools
	Extra map[string]any `json:"extra"`

	// default arguments
	Arguments map[string]any `json:"arguments"`

	//
	Config *AppConfig `json:"-"`
}

func (*ToolFunc) Clone added in v0.11.0

func (r *ToolFunc) Clone() *ToolFunc

func (*ToolFunc) ID

func (r *ToolFunc) ID() string

ID returns a unique identifier for the tool, combining the tool kit and name. A string that must match the pattern '^[a-zA-Z0-9_-]+$'."

type ToolGuard added in v0.1.1

type ToolGuard struct {
	Agent string
}

type ToolKit added in v0.1.1

type ToolKit interface {
	Call(context.Context, *Vars, *Agent, *ToolFunc, map[string]any) (any, error)
}

type ToolSystem added in v0.0.2

type ToolSystem interface {
	GetKit(key any) (ToolKit, error)
	AddKit(key any, kit ToolKit)
}

type ToolType added in v0.1.1

type ToolType string

TODO revisit real type func/web/system/*, mcp, agent, bin, ai???

const (
	// script/template
	ToolTypeFunc ToolType = "func"

	ToolTypeSystem ToolType = "system"

	ToolTypeWeb ToolType = "web"

	ToolTypeMcp ToolType = "mcp"

	ToolTypeAgent ToolType = "agent"

	ToolTypeAI ToolType = "ai"

	//
	ToolTypeBin ToolType = "bin"

	ToolTypeAlias ToolType = "alias"
)

type UnauthorizedError added in v0.1.1

type UnauthorizedError struct {
	Message string
}

func (*UnauthorizedError) Error added in v0.1.1

func (e *UnauthorizedError) Error() string

type UnsupportedError added in v0.1.1

type UnsupportedError struct {
	Message string
}

func (*UnsupportedError) Error added in v0.1.1

func (e *UnsupportedError) Error() string

type User

type User struct {
	// uuid
	ID string `json:"id"`

	// emoji + nickname
	Display string `json:"display"`

	Email string `json:"email"`

	// full/first,last
	Name string `json:"name"`

	Avatar string `json:"avatar"`

	Settings map[string]any `json:"settings"`
}

func (*User) Agent added in v0.1.1

func (r *User) Agent() string

func (*User) SetAgent added in v0.1.1

func (r *User) SetAgent(s string)

type UserInput

type UserInput struct {
	// cached media contents
	Messages []*Message `json:"-"`

	Message string
}

type Vars

type Vars struct {
	Global *Environment `json:"global"`

	RootAgent *Agent `json:"root_agent"`

	Base string

	ID string

	User      *User
	Roots     *Roots
	Workspace Workspace
	OS        System
	Secrets   SecretStore
	Assets    AssetManager
	Blobs     BlobStore
	Tools     ToolSystem
	Adapters  AdapterRegistry
	History   MemStore
	Log       CallLogger
}

global context

func (*Vars) DefaultPrompt added in v0.1.1

func (r *Vars) DefaultPrompt(argm ArgMap) (string, error)

Return default prompt using instruction. Return error if instruction is a template Return empty string if no instruction if found Preprocessing is required for templates using [ai:build_prompt]

func (*Vars) DefaultQuery added in v0.1.1

func (r *Vars) DefaultQuery(argm ArgMap) (string, error)

Return default query from message and content. Return error if either message or content is a template Preprocessing is required for templates using [ai:build_query]

func (*Vars) LoadScript added in v0.1.1

func (r *Vars) LoadScript(s string) (string, error)

func (*Vars) Open added in v0.1.1

func (r *Vars) Open(s string) (fs.File, error)

fs.FS interface

func (*Vars) Token added in v0.1.1

func (r *Vars) Token(key string) (string, error)

Return secret token for the current user

type Workspace added in v0.1.1

type Workspace = vfs.Workspace

Jump to

Keyboard shortcuts

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