Documentation
¶
Overview ¶
Adapted from https://github.com/justinas/alice/blob/master/chain.go
Index ¶
- Constants
- Variables
- func AgentLister(app *api.AppConfig) (func() map[string]*api.AgentsConfig, error)
- func Aider(ctx context.Context, models map[llm.Level]*api.Model, ...) error
- func CallKit(tool any, kit string, method string, args ...any) (any, error)
- func CallMcpTool(ctx context.Context, tf *api.ToolFunc, vars *api.Vars, name string, ...) (string, error)
- func CallTool(ctx context.Context, vars *api.Vars, name string, args map[string]any) (*api.Result, error)
- func Chat(ctx context.Context, req *llm.Request) (*llm.Response, error)
- func CreateAgent(vars *api.Vars, name, command string, input *api.UserInput) (*api.Agent, error)
- func Default(def, value any) any
- func GenerateReport(ctx context.Context, m *api.Model, reportType, tone, input string) (string, error)
- func GetArrayProp(key string, props map[string]any) ([]string, error)
- func GetIntProp(key string, props map[string]any) (int, error)
- func GetStrProp(key string, props map[string]any) (string, error)
- func ImageGen(ctx context.Context, req *llm.Request) (*llm.Response, error)
- func InitVars(app *api.AppConfig) (*api.Vars, error)
- func ListAgents(app *api.AppConfig) (map[string]*api.AgentsConfig, error)
- func ListMcpTools(cfg *api.ToolsConfig) ([]*api.ToolFunc, error)
- func ListModels(app *api.AppConfig) (map[string]*api.ModelsConfig, error)
- func ListTools(app *api.AppConfig) (map[string]*api.ToolFunc, error)
- func LoadAgentsAsset(as api.AssetStore, root string, groups map[string]*api.AgentsConfig) error
- func LoadAgentsConfig(app *api.AppConfig) (map[string]*api.AgentsConfig, error)
- func LoadAgentsData(data [][]byte) (*api.AgentsConfig, error)
- func LoadFileAgentsConfig(base string, groups map[string]*api.AgentsConfig) error
- func LoadFileModelsConfig(base string, aliases map[string]*api.ModelsConfig) error
- func LoadFileToolsConfig(base string, kits map[string]*api.ToolsConfig) error
- func LoadModelsAsset(as api.AssetStore, base string, m map[string]*api.ModelsConfig) error
- func LoadModelsData(data [][]byte) (*api.ModelsConfig, error)
- func LoadResourceAgentsConfig(fs embed.FS, groups map[string]*api.AgentsConfig) error
- func LoadResourceModelsConfig(fs embed.FS, aliases map[string]*api.ModelsConfig) error
- func LoadResourceToolsConfig(fs embed.FS, kits map[string]*api.ToolsConfig) error
- func LoadToolData(data [][]byte) (*api.ToolsConfig, error)
- func LoadToolsAsset(as api.AssetStore, base string, kits map[string]*api.ToolsConfig) error
- func LoadToolsConfig(app *api.AppConfig) (map[string]*api.ToolsConfig, error)
- func LoadWebAgentsConfig(resources []*api.Resource, groups map[string]*api.AgentsConfig) error
- func LoadWebModelsConfig(resources []*api.Resource, aliases map[string]*api.ModelsConfig) error
- func LoadWebToolsConfig(resources []*api.Resource, kits map[string]*api.ToolsConfig) error
- func MaxLogHandler(n int) func(Handler) Handler
- func OpenHands(ctx context.Context, model *api.Model, workspace string, in *api.UserInput) error
- func Spread(val any) string
- func Vars(app *api.AppConfig) (*api.Vars, error)
- type Chain
- type CommandCheck
- type Constructor
- type FileContent
- type FileStore
- type FuncKit
- func (r *FuncKit) AgentInfo(ctx context.Context, vars *api.Vars, _ string, args map[string]any) (string, error)
- func (r *FuncKit) BingSearch(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *FuncKit) BraveSearch(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *FuncKit) ConvertTime(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *FuncKit) DdgSearch(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *FuncKit) DownloadContent(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *FuncKit) FetchContent(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *FuncKit) GetCurrentTime(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *FuncKit) GetLocalTimezone(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *FuncKit) GoogleSearch(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *FuncKit) ListAgents(ctx context.Context, vars *api.Vars, _ string, _ map[string]any) (string, error)
- type Handler
- type HandlerFunc
- type LLMAdapter
- type LocalSystem
- type McpClient
- type ResourceStore
- type Swarm
- type SystemKit
- func (r *SystemKit) Cd(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) CopyToClipboard(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) CopyToClipboardAppend(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) CreateDirectory(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) Env(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) Exec(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) GetFileContentInput(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) GetFileInfo(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) GetUserChoiceInput(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) GetUserConfirmation(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) GetUserTextInput(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) HomeDir(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) ListCommands(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) ListDirectory(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) Man(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) PasteFromClipboard(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) PasteFromClipboardWait(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) Pwd(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) ReadFile(ctx context.Context, vars *api.Vars, name string, args map[string]any) (*FileContent, error)
- func (r *SystemKit) RenameFile(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) RepoDir(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) SearchFiles(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) TempDir(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) Uname(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) Which(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) WhoAmI(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) WorkspaceDir(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) WriteFile(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- func (r *SystemKit) WriteStdout(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
- type WSInput
- type WebStore
Constants ¶
const ( ToolTypeSystem = "system" // ToolTypeTemplate = "template" // ToolTypeShell = "shell" // ToolTypeSql = "sql" ToolTypeMcp = "mcp" // ToolTypeAgent = "agent" ToolTypeFunc = "func" )
Variables ¶
var ErrHandlerTimeout = errors.New("Agent service timeout")
ErrHandlerTimeout is returned on [Response] in handlers which have timed out.
Functions ¶
func AgentLister ¶ added in v0.0.2
func CallMcpTool ¶ added in v0.0.2
func CreateAgent ¶
func Default ¶
Default returns the given value if it's non-nil and non-zero value; otherwise, it returns the default value provided.
func GenerateReport ¶
func ListAgents ¶
func ListMcpTools ¶ added in v0.0.2
func ListMcpTools(cfg *api.ToolsConfig) ([]*api.ToolFunc, error)
func ListModels ¶
func LoadAgentsAsset ¶
func LoadAgentsAsset(as api.AssetStore, root string, groups map[string]*api.AgentsConfig) error
func LoadAgentsConfig ¶
func LoadAgentsData ¶
func LoadAgentsData(data [][]byte) (*api.AgentsConfig, error)
LoadAgentsConfig loads the agent configuration from the provided YAML data.
func LoadFileAgentsConfig ¶
func LoadFileAgentsConfig(base string, groups map[string]*api.AgentsConfig) error
func LoadFileModelsConfig ¶
func LoadFileModelsConfig(base string, aliases map[string]*api.ModelsConfig) error
func LoadFileToolsConfig ¶
func LoadFileToolsConfig(base string, kits map[string]*api.ToolsConfig) error
func LoadModelsAsset ¶
func LoadModelsAsset(as api.AssetStore, base string, m map[string]*api.ModelsConfig) error
func LoadModelsData ¶
func LoadModelsData(data [][]byte) (*api.ModelsConfig, error)
func LoadResourceToolsConfig ¶
func LoadToolData ¶
func LoadToolData(data [][]byte) (*api.ToolsConfig, error)
func LoadToolsAsset ¶
func LoadToolsAsset(as api.AssetStore, base string, kits map[string]*api.ToolsConfig) error
func LoadToolsConfig ¶
func LoadWebAgentsConfig ¶
func LoadWebModelsConfig ¶
func LoadWebToolsConfig ¶
func MaxLogHandler ¶
MaxLogHandler returns a Handler that logs the request and response
Types ¶
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain acts as a list of Handler constructors. Chain is effectively immutable: once created, it will always hold the same set of constructors in the same order.
func NewChain ¶
func NewChain(constructors ...Constructor) Chain
New creates a new chain, memorizing the given list of middleware constructors. New serves no other function, constructors are only called upon a call to Then().
func (Chain) Append ¶
func (c Chain) Append(constructors ...Constructor) Chain
Append extends a chain, adding the specified constructors as the last ones in the request flow.
Append returns a new chain, leaving the original one untouched.
stdChain := alice.New(m1, m2) extChain := stdChain.Append(m3, m4) // requests in stdChain go m1 -> m2 // requests in extChain go m1 -> m2 -> m3 -> m4
func (Chain) Extend ¶
Extend extends a chain by adding the specified chain as the last one in the request flow.
Extend returns a new chain, leaving the original one untouched.
stdChain := alice.New(m1, m2) ext1Chain := alice.New(m3, m4) ext2Chain := stdChain.Extend(ext1Chain) // requests in stdChain go m1 -> m2 // requests in ext1Chain go m3 -> m4 // requests in ext2Chain go m1 -> m2 -> m3 -> m4
Another example:
aHtmlAfterNosurf := alice.New(m2)
aHtml := alice.New(m1, func(h Handler) Handler {
csrf := nosurf.New(h)
csrf.SetFailureHandler(aHtmlAfterNosurf.ThenFunc(csrfFail))
return csrf
}).Extend(aHtmlAfterNosurf)
// requests to aHtml hitting nosurfs success handler go m1 -> nosurf -> m2 -> target-handler
// requests to aHtml hitting nosurfs failure handler go m1 -> nosurf -> m2 -> csrfFail
func (Chain) Then ¶
Then chains the middleware and returns the final Handler.
New(m1, m2, m3).Then(h)
is equivalent to:
m1(m2(m3(h)))
When the request comes in, it will be passed to m1, then m2, then m3 and finally, the given handler (assuming every middleware calls the following one).
A chain can be safely reused by calling Then() several times.
stdStack := alice.New(ratelimitHandler, csrfHandler) indexPipe = stdStack.Then(indexHandler) authPipe = stdStack.Then(authHandler)
Note that constructors are called on every call to Then() and thus several instances of the same middleware will be created when a chain is reused in this way. For proper middleware, this should cause no problems.
Then() treats nil as DefaultServeMux.
func (Chain) ThenFunc ¶
func (c Chain) ThenFunc(fn HandlerFunc) Handler
ThenFunc works identically to Then, but takes a HandlerFunc instead of a Handler.
The following two statements are equivalent:
c.Then(HandlerFunc(fn)) c.ThenFunc(fn)
ThenFunc provides all the guarantees of Then.
type CommandCheck ¶
type Constructor ¶
A constructor for a piece of middleware. Some middleware use this constructor out of the box, so in most cases you can just pass somepackage.New
type FileContent ¶
type FuncKit ¶
type FuncKit struct {
}
func (*FuncKit) BingSearch ¶
func (r *FuncKit) BingSearch(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
Search the web using Bing.
func (*FuncKit) BraveSearch ¶
func (r *FuncKit) BraveSearch(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
Search the web using Brave.
func (*FuncKit) ConvertTime ¶
func (*FuncKit) DdgSearch ¶
func (r *FuncKit) DdgSearch(ctx context.Context, vars *api.Vars, name string, args map[string]any) (string, error)
Search the web using DuckDuckGo.
func (*FuncKit) DownloadContent ¶
func (*FuncKit) FetchContent ¶
func (*FuncKit) GetCurrentTime ¶
func (*FuncKit) GetLocalTimezone ¶
type Handler ¶
A Handler responds to a request.
[Handler.Serve] should write reply headers and data to the [ResponseWriter] and then return. Returning signals that the request is finished; it is not valid to use the [ResponseWriter] or read from the [Request.Body] after or concurrently with the completion of the Serve call.
Depending on the client software, protocol version, and any intermediaries between the client and the Go server, it may not be possible to read from the [Request.Body] after writing to the [ResponseWriter]. Cautious handlers should read the [Request.Body] first, and then reply.
Except for reading the body, handlers should not modify the provided Request.
If Serve panics, the server (the caller of Serve) assumes that the effect of the panic was isolated to the active request. It recovers the panic, logs a stack trace to the server error log, and either closes the network connection or sends an HTTP/2 RST_STREAM, depending on the protocol. To abort a handler so the client sees an interrupted response but the server doesn't log an error, panic with the value [ErrAbortHandler].
func TimeoutHandler ¶
TimeoutHandler returns a Handler that times out if the time limit is reached.
The new Handler calls thext next handler's Serve to handle each request, but if a call runs for longer than its time limit, the handler responds with a timeout error.
type HandlerFunc ¶
The HandlerFunc type is an adapter to allow the use of ordinary functions as handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.
type LocalSystem ¶ added in v0.0.2
type LocalSystem struct {
// contains filtered or unexported fields
}
func NewLocalSystem ¶ added in v0.0.2
func NewLocalSystem(app *api.AppConfig) *LocalSystem
type McpClient ¶
type McpClient struct {
// contains filtered or unexported fields
}
func NewMcpClient ¶
func NewMcpClient(cfg *api.ConnectorConfig) *McpClient
type ResourceStore ¶
func (*ResourceStore) ReadDir ¶
func (rs *ResourceStore) ReadDir(name string) ([]api.DirEntry, error)
func (*ResourceStore) Resolve ¶
func (rs *ResourceStore) Resolve(dir, name string) string
type SystemKit ¶
type SystemKit struct {
}
func (*SystemKit) CopyToClipboard ¶
func (*SystemKit) CopyToClipboardAppend ¶
func (*SystemKit) CreateDirectory ¶
func (*SystemKit) GetFileContentInput ¶
func (*SystemKit) GetFileInfo ¶
func (*SystemKit) GetUserChoiceInput ¶
func (*SystemKit) GetUserConfirmation ¶
func (*SystemKit) GetUserTextInput ¶
func (*SystemKit) ListCommands ¶
func (*SystemKit) ListDirectory ¶
func (*SystemKit) PasteFromClipboard ¶
func (*SystemKit) PasteFromClipboardWait ¶
func (*SystemKit) ReadFile ¶
func (r *SystemKit) ReadFile(ctx context.Context, vars *api.Vars, name string, args map[string]any) (*FileContent, error)
ReadFile returns mime type and the raw file content