Documentation
¶
Index ¶
- Constants
- Variables
- func AppConfig(ctx context.Context) api.ThreadConfig
- func AppFilesConfig(ctx context.Context) api.FilesConfig
- func AppIslandConfig(ctx context.Context) api.IslandConfig
- func AppProvider(ctx context.Context) api.Provider
- func AppSystem(ctx context.Context) []string
- func AppUploadStorage(ctx context.Context) api.UploadStorage
- func AttachThread(ctx context.Context, from context.Context) context.Context
- func BackendForced(opts []Option) bool
- func ConfigDefaults(c api.ThreadConfig) api.ThreadConfig
- func FilesConfigDefaults(c api.FilesConfig) api.FilesConfig
- func IslandConfigDefaults(c api.IslandConfig) api.IslandConfig
- type Answer
- type Backend
- func (b *Backend) Config() api.ThreadConfig
- func (b *Backend) Context() context.Context
- func (b *Backend) FilesConfig() api.FilesConfig
- func (b *Backend) Modules() []ModuleFactory
- func (b *Backend) Provider() api.Provider
- func (b *Backend) Storage() api.MessageStorage
- func (b *Backend) System() []string
- func (b *Backend) UploadStorage() api.UploadStorage
- func (b *Backend) WorkspaceStorage() api.WorkspaceStorage
- type ConfigKey
- type Controller
- type ErrorWithOutput
- type FilesConfigKey
- type IslandConfigKey
- type IslandDirKey
- type IslandFSKey
- type IslandFilesConfigKey
- type IslandIDKey
- type IslandScopeKey
- type IslandWidget
- type Module
- type ModuleFactory
- type ModulesKey
- type Option
- func OptionFilesConfig(c api.FilesConfig) Option
- func OptionForce() Option
- func OptionMessageStorage(s api.MessageStorage) Option
- func OptionModule(register func(ctx context.Context) Module) Option
- func OptionModules(registers []ModuleFactory) Option
- func OptionProvider(p api.Provider) Option
- func OptionSystem(prompt []string) Option
- func OptionUploadStorage(s api.UploadStorage) Option
- type ProviderKey
- type SystemKey
- type Task
- type Tool
- type UploadStorageKey
Constants ¶
const ( KeySession ctxKey = iota KeyInstance KeySpace KeyController KeyIslandStore KeyIslandWidget KeyIslandScript )
const IslandIDAttr = "data-neui-island"
Variables ¶
var ErrRelinked = errors.New("the chat moved to a new page, by a reload or in another tab, which ended what ran on the old page")
Functions ¶
func AppFilesConfig ¶
func AppFilesConfig(ctx context.Context) api.FilesConfig
func AppIslandConfig ¶
func AppIslandConfig(ctx context.Context) api.IslandConfig
func AppUploadStorage ¶
func AppUploadStorage(ctx context.Context) api.UploadStorage
func BackendForced ¶
func ConfigDefaults ¶
func ConfigDefaults(c api.ThreadConfig) api.ThreadConfig
func FilesConfigDefaults ¶
func FilesConfigDefaults(c api.FilesConfig) api.FilesConfig
func IslandConfigDefaults ¶
func IslandConfigDefaults(c api.IslandConfig) api.IslandConfig
Types ¶
type Answer ¶
type Answer[O any] interface { // Submit ends the call with output as its result and removes the // question from the chat; ctx is the answering event handler's. Submit(ctx context.Context, output O) // Fail ends the call with err and removes the question from the chat; // ctx is the answering event handler's. Fail(ctx context.Context, err error) }
Answer is how an Ask's form returns the user's answer to the waiting tool call. Only the first Submit or Fail counts; later calls, and calls after the tool call has ended, do nothing.
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
func NewBackend ¶
func NewBackend( ctx context.Context, messageStorage api.MessageStorage, workspaceStorage api.WorkspaceStorage, uploadStorage api.UploadStorage, opts []Option, ) *Backend
func (*Backend) Config ¶
func (b *Backend) Config() api.ThreadConfig
func (*Backend) FilesConfig ¶
func (b *Backend) FilesConfig() api.FilesConfig
func (*Backend) Modules ¶
func (b *Backend) Modules() []ModuleFactory
func (*Backend) Storage ¶
func (b *Backend) Storage() api.MessageStorage
func (*Backend) UploadStorage ¶
func (b *Backend) UploadStorage() api.UploadStorage
func (*Backend) WorkspaceStorage ¶
func (b *Backend) WorkspaceStorage() api.WorkspaceStorage
type Controller ¶
type Controller interface {
ID() api.ThreadID
Context() context.Context
PageContext() context.Context
Modules() iter.Seq[Module]
Config() api.ThreadConfig
FilesConfig() api.FilesConfig
Model() api.Model
FS() api.FS
Task(comment string, attrs map[string]any, cancel context.CancelCauseFunc) (Task, error)
Ask(ask api.ChatAsk) (done func(ctx context.Context), err error)
Rename(ctx context.Context, name string) error
}
func GetController ¶
func GetController(ctx context.Context) Controller
type ErrorWithOutput ¶
type ErrorWithOutput struct {
Err error
Output json.RawMessage
}
func (ErrorWithOutput) Error ¶
func (e ErrorWithOutput) Error() string
func (ErrorWithOutput) Unwrap ¶
func (e ErrorWithOutput) Unwrap() error
type FilesConfigKey ¶
type FilesConfigKey struct{}
type IslandConfigKey ¶
type IslandConfigKey struct{}
type IslandDirKey ¶
type IslandDirKey struct{}
type IslandFSKey ¶
type IslandFSKey struct{}
type IslandFilesConfigKey ¶
type IslandFilesConfigKey struct{}
type IslandIDKey ¶
type IslandIDKey struct{}
type IslandScopeKey ¶
type IslandScopeKey struct{}
type IslandWidget ¶
type Module ¶
type Module interface {
// Name is the module's name; its tools reach the agent as name__tool.
Name() string
// Desc is the module's guidance, added to the system prompt; empty adds
// nothing.
Desc() string
// List returns the module's tools.
List() []Tool
// Get returns the tool with that name and whether there is one.
Get(name string) (Tool, bool)
}
Module is what a ModuleFactory returns: a named set of tools. A host implements it directly only to serve tools it builds itself. The runtime calls its methods from several goroutines and reads Desc and List again for every request, so a change shows up at the next one.
type ModuleFactory ¶
ModuleFactory returns the module a thread uses: a fresh one or a shared one. The runtime calls it each time a thread opens, with a context that lasts while the thread stays open and carries no tool call. When two modules of a thread share a name, the later one is skipped and an error is logged; the built-in chat, time and files modules come first.
func AppModules ¶
func AppModules(ctx context.Context) []ModuleFactory
type ModulesKey ¶
type ModulesKey struct{}
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures one session in Enable. Options apply in order on top of the app-wide values.
func OptionFilesConfig ¶
func OptionFilesConfig(c api.FilesConfig) Option
func OptionForce ¶
func OptionForce() Option
func OptionMessageStorage ¶
func OptionMessageStorage(s api.MessageStorage) Option
func OptionModules ¶
func OptionModules(registers []ModuleFactory) Option
func OptionProvider ¶
func OptionSystem ¶
func OptionUploadStorage ¶
func OptionUploadStorage(s api.UploadStorage) Option
type ProviderKey ¶
type ProviderKey struct{}
type Task ¶
type Task interface {
// ID is the task's id within the thread, as the agent and the UI see it.
ID() uint
// Ok ends the task with output, a JSON value, as its result; it reaches
// the agent as a <task_result> block in the conversation.
Ok(output json.RawMessage)
// Err ends the task with the error as its result.
Err(error)
// Notify delivers data, a JSON value, as an interim report with meta
// attributes, while the task keeps running.
Notify(data json.RawMessage, meta map[string]any)
}
Task is a background task registered with ToolTask. Ok or Err delivers its final result and ends it. Notify delivers an interim record while the task keeps running; it is dropped once the task has finished. All methods are safe to call from any goroutine.
type Tool ¶
type Tool interface {
// Params is the JSON schema of the tool's input.
Params() []byte
// Name is the tool's name within its module.
Name() string
// Desc is the description the tool was defined with.
Desc() string
// Summary is the description the agent sees: Desc with the output
// schema appended.
Summary() string
// Output is the JSON schema of the tool's result.
Output() []byte
// Agent calls the tool as a direct tool call and returns its result as
// content for the model.
Agent(ctx context.Context, input json.RawMessage) (api.UserContents, error)
// JS returns the tool as a function a script calls with one JSON
// argument.
JS(ctx context.Context) quickjs.HostFunc
}
Tool is one tool as the runtime sees it, the result of a Tool or Ask definition.
type UploadStorageKey ¶
type UploadStorageKey struct{}