Documentation
¶
Overview ¶
Package registry has the providers of models, by names which the registry gives them, and finds the models across them
Index ¶
- Constants
- Variables
- type AgentStore
- type CredentialsProvider
- type EventBuilder
- type EventStore
- type Opt
- func WithAgentStore(store AgentStore) Opt
- func WithBroadcaster(b *broadcaster.Broadcaster) Opt
- func WithClientOpts(opts ...client.ClientOpt) Opt
- func WithCredentialsProvider(credentials CredentialsProvider) Opt
- func WithEventBuilder(fn EventBuilder) Opt
- func WithEventStore(store EventStore) Opt
- func WithMaxEvents(n uint) Opt
- func WithProviderStore(store ProviderStore) Opt
- func WithReplies(fn ReplyFunc) Opt
- func WithResources(resources Resources) Opt
- func WithSessionRetention(d time.Duration, keep func(context.Context, uuid.UUID) (bool, error)) Opt
- func WithSessionStore(store SessionStore) Opt
- func WithTimes(zone func() *time.Location, namespaces ...string) Opt
- func WithToolkit(tools *toolkit.Toolkit) Opt
- func WithTracer(tracer trace.Tracer) Opt
- type ProviderOpt
- type ProviderStore
- type Registry
- func (r *Registry) Add(name string, provider llm.Provider, opts ...ProviderOpt) error
- func (r *Registry) AgentLoop(ctx context.Context, model llm.Model, messages []llm.Message, tools []llm.Tool, ...) (_ []providerschema.Message, _ llm.Usage, err error)
- func (r *Registry) AgentStore() AgentStore
- func (r *Registry) Ask(ctx context.Context, req schema.AskRequest, stream llm.GeneratorStreamFn) (_ *schema.AskResponse, err error)
- func (r *Registry) Broadcaster() *broadcaster.Broadcaster
- func (r *Registry) Chat(ctx context.Context, id uuid.UUID, messages []llm.Message, ...) (_ *schema.ChatResponse, err error)
- func (r *Registry) CreateAgent(ctx context.Context, meta schema.AgentMeta) (_ *schema.Agent, created bool, err error)
- func (r *Registry) CreateProvider(ctx context.Context, req schema.Provider) (_ *schema.ProviderStatus, err error)
- func (r *Registry) CreateSession(ctx context.Context, meta schema.SessionMeta) (_ *schema.Session, err error)
- func (r *Registry) DeleteAgent(ctx context.Context, name string) (_ *schema.Agent, err error)
- func (r *Registry) DeleteEvent(ctx context.Context, id uuid.UUID) (_ *schema.Event, err error)
- func (r *Registry) DeleteModel(ctx context.Context, model llm.Model) (err error)
- func (r *Registry) DeleteProvider(ctx context.Context, name string) (_ *schema.ProviderStatus, err error)
- func (r *Registry) DeleteSession(ctx context.Context, id uuid.UUID) (_ *schema.Session, err error)
- func (r *Registry) Embed(ctx context.Context, model llm.Model, messages []llm.Message, opts ...llm.Opt) (_ []llm.Vector, _ llm.Usage, err error)
- func (r *Registry) EventStore() EventStore
- func (r *Registry) ForgetSessionMessages(ctx context.Context, id uuid.UUID) (_ *schema.Session, err error)
- func (r *Registry) GetAgent(ctx context.Context, name string) (_ *schema.Agent, err error)
- func (r *Registry) GetEvent(ctx context.Context, id uuid.UUID) (_ *schema.Event, err error)
- func (r *Registry) GetModel(ctx context.Context, name string) (_ llm.Model, err error)
- func (r *Registry) GetProvider(ctx context.Context, name string) (_ *schema.ProviderStatus, err error)
- func (r *Registry) GetSession(ctx context.Context, id uuid.UUID) (_ *schema.Session, err error)
- func (r *Registry) Illustrate(ctx context.Context, model llm.Model, prompt string, images []llm.Resource, ...) (_ []llm.Resource, _ llm.Usage, err error)
- func (r *Registry) Keep(ctx context.Context, session uuid.UUID, resource llm.Resource, name string) (toolschema.ResourceLink, bool, error)
- func (r *Registry) ListAgents(ctx context.Context, req schema.AgentListRequest) (_ *schema.AgentList, err error)
- func (r *Registry) ListEvents(ctx context.Context, req schema.EventListRequest) (_ *schema.EventList, err error)
- func (r *Registry) ListModels(ctx context.Context, providers ...string) (_ []llm.Model, err error)
- func (r *Registry) ListProviders(ctx context.Context, req schema.ProviderListRequest) (_ *schema.ProviderList, err error)
- func (r *Registry) ListSessionMessages(ctx context.Context, id uuid.UUID, req schema.MessageListRequest) (_ *schema.MessageList, err error)
- func (r *Registry) ListSessions(ctx context.Context, req schema.SessionListRequest) (_ *schema.SessionList, err error)
- func (r *Registry) LoadModel(ctx context.Context, name string, progress llm.DownloadProgressFn) (_ llm.Model, err error)
- func (r *Registry) Measure(ctx context.Context, model llm.Model, text string) (_ uint, err error)
- func (r *Registry) Model(model llm.Model) *schema.Model
- func (r *Registry) Name(model llm.Model) string
- func (r *Registry) Names() []string
- func (r *Registry) Ping(ctx context.Context) (err error)
- func (r *Registry) Provider(name string) llm.Provider
- func (r *Registry) Providers() []llm.Provider
- func (r *Registry) Ready() <-chan struct{}
- func (r *Registry) Recognize(ctx context.Context, model llm.Model, resource llm.Resource, opts ...llm.Opt) (_ llm.Document, _ llm.Usage, err error)
- func (r *Registry) Remove(name string) (llm.Provider, error)
- func (r *Registry) Run(ctx context.Context, logger *slog.Logger) error
- func (r *Registry) RunAgent(ctx context.Context, name string, req schema.RunAgentRequest, ...) (_ *schema.RunAgentResponse, err error)
- func (r *Registry) RunEvent(ctx context.Context, id uuid.UUID, req schema.RunEventRequest, ...) (_ *schema.RunEventResponse, err error)
- func (r *Registry) SessionStore() SessionStore
- func (r *Registry) SetSessionStatus(ctx context.Context, id uuid.UUID, value schema.SessionStatus) (_ *schema.Session, err error)
- func (r *Registry) Speak(ctx context.Context, model llm.Model, text string, opts ...llm.Opt) (_ llm.Resource, _ llm.Usage, err error)
- func (r *Registry) Toolkit() *toolkit.Toolkit
- func (r *Registry) Transcribe(ctx context.Context, model llm.Model, audio llm.Resource, ...) (_ llm.Transcript, _ llm.Usage, err error)
- func (r *Registry) Translate(ctx context.Context, model llm.Model, audio llm.Resource, ...) (_ llm.Transcript, _ llm.Usage, err error)
- func (r *Registry) TriggerEvent(ctx context.Context, req schema.EventRequest) (_ *schema.TriggerEventResponse, err error)
- func (r *Registry) UnloadModel(ctx context.Context, model llm.Model) (err error)
- func (r *Registry) UpdateAgent(ctx context.Context, name string, meta schema.AgentMeta) (_ *schema.Agent, err error)
- func (r *Registry) UpdateProvider(ctx context.Context, name string, meta schema.ProviderMeta) (_ *schema.ProviderStatus, err error)
- func (r *Registry) UpdateSession(ctx context.Context, id uuid.UUID, meta schema.SessionMeta) (_ *schema.Session, err error)
- func (r *Registry) Watch(ctx context.Context, ch chan<- schema.Event) (<-chan error, error)
- func (r *Registry) WithSession(ctx context.Context, session schema.Session, messages []llm.Message, ...) (_ *schema.SessionResponse, err error)
- func (r *Registry) WithoutSession(ctx context.Context, model llm.Model, messages []llm.Message, tools []llm.Tool, ...) (_ llm.Message, _ llm.Usage, err error)
- type Reply
- type ReplyFunc
- type Resources
- type SessionStore
Constants ¶
const ( // DefaultMaxIterations is how many times the agent loop asks a model for // its reply, when it isn't told how many DefaultMaxIterations = 10 // DefaultToolTimeout is the most time a tool the agent loop runs has to // return, when it isn't told how long DefaultToolTimeout = 30 * time.Second )
const ( // EventSchema is the schema of the registry's events, which the // toolkit's events share EventSchema = "llm" // ProviderTable is the table of the events of providers, whose rows are // their names in the registry ProviderTable = "provider" // SessionTable is the table of the events of sessions, whose rows are // their identifiers SessionTable = "session" )
const ( // AgentNamespace is the name of the namespace of the toolkit's tools // which are the registry's agents AgentNamespace = "agent" )
const DefaultEventAgent = "event"
DefaultEventAgent is the agent which runs an event, unless another is given
const DefaultMaxDepth = 3
DefaultMaxDepth is the most agents which run in one another, as an agent calls another, or itself, as a tool, when the max_depth option of the session, or agent, which runs them, doesn't say
const DefaultMaxEvents = 2
DefaultMaxEvents is the most events which run at once, unless WithMaxEvents sets it
const ( // DefaultToolResultLimit is the most tokens of a tool's result the agent // loop sends to the model, when the model's context isn't known DefaultToolResultLimit = 8192 )
const EventTable = "event"
EventTable is the table of the registry's events of the outcomes of events, whose rows are their identifiers, and whose data, unless they were deleted, is an EventChange
const ( // RetentionInterval is how often the sessions which haven't changed for // longer than they're kept are deleted, as the registry runs RetentionInterval = time.Hour )
Variables ¶
var ( // PingInterval is how long the result of a provider's ping is used, and // how often Run pings the providers, so whether one can be reached is // known within it. A provider decides how often it asks its server, so // one of an API, such as OpenAI's, which is rarely unreachable, can keep // its ping's result for longer. A provider which downloads models, such // as Ollama, has its models listed again as often, as they can be // downloaded or deleted without the registry, and listing them is quick. PingInterval = 30 * time.Second // ModelCacheInterval is how long a provider's models are cached, unless // it downloads models ModelCacheInterval = 6 * time.Hour )
var MaxAttachmentsSize int64 = 64 << 20
MaxAttachmentsSize is the most content of the resources which a request's attachments refer to, together, which is read into memory, as it's sent to a model, which is more than any provider accepts
var TypingTimeout = 10 * time.Second
TypingTimeout is how long a session is typing, after a client last says someone is, before it's idle, so a client which goes away doesn't leave it typing
Functions ¶
This section is empty.
Types ¶
type AgentStore ¶ added in v0.6.0
type AgentStore interface {
// Create creates an agent with the definition, and returns it, with its
// serial, and when it was created. Returns ErrConflict when there's an
// agent with its name.
Create(context.Context, schema.AgentMeta) (schema.Agent, error)
// Get returns the agent with the name. Returns ErrNotFound when there's
// none.
Get(ctx context.Context, name string) (schema.Agent, error)
// List returns the agents, in the store's order, from the request's
// offset, and at most its limit of them, and how many there are
List(context.Context, schema.AgentListRequest) (schema.AgentList, error)
// Put replaces the agent with its name, when its serial is that agent's,
// and returns it, with its new serial, and when it was modified. Returns
// ErrNotFound when there's none, and ErrConflict when its serial isn't
// the agent's, as it was changed since it was seen.
Put(context.Context, schema.Agent) (schema.Agent, error)
// Delete deletes the agent with the name, when the serial is its serial,
// or does nothing when there's none. Returns ErrConflict when the serial
// isn't its serial, as it was changed since it was seen.
Delete(ctx context.Context, name string, serial uint64) error
}
AgentStore has agents, each by its name, with its serial, which the store sets, and changes each time the agent is stored, so a change is made to the agent as it was last seen, rather than a newer one, such as one which another server made. An agent's serial is never one which an agent with its name had before, including one which was deleted, and created again, so a change to the agent as it was isn't made to the new one.
type CredentialsProvider ¶
type CredentialsProvider interface {
// Expand returns the value with each placeholder replaced with its
// credential, or an error when a credential doesn't exist
Expand(ctx context.Context, value string) (string, error)
}
CredentialsProvider expands credentials, such as a provider's API key, whose placeholders, such as ${OPENAI_KEY} or $OPENAI_KEY, are replaced with the credentials they name
type EventBuilder ¶ added in v1.2.0
type EventBuilder func(context.Context, schema.EventRequest) (schema.RunEventRequest, error)
EventBuilder returns how an event is run: its agent's input, the namespaces of the tools it's run without, and what it's for, and when it was due, and fired, for RunEvent
type EventStore ¶ added in v1.2.0
type EventStore interface {
// Create creates an event with the outcome, and a new identifier, and
// returns it, with its serial, and when it was created
Create(context.Context, schema.EventMeta) (schema.Event, error)
// Get returns the event with the identifier. Returns ErrNotFound when
// there's none.
Get(ctx context.Context, id uuid.UUID) (schema.Event, error)
// List returns the events which the request selects, the most recently
// created first, from its offset, and at most its limit of them, and how
// many it selects
List(context.Context, schema.EventListRequest) (schema.EventList, error)
// Put replaces the event with its identifier, when its serial is that
// event's, and returns it, with its new serial, and when it was
// modified. Returns ErrNotFound when there's none, and ErrConflict when
// its serial isn't the event's, as it was changed since it was seen.
Put(context.Context, schema.Event) (schema.Event, error)
// Delete deletes the event with the identifier, when the serial is its
// serial, or does nothing when there's none. Returns ErrConflict when
// the serial isn't its serial.
Delete(ctx context.Context, id uuid.UUID, serial uint64) error
}
EventStore has the outcomes of the events which the registry runs, such as heartbeats which fire, each with its identifier and serial, which the store sets, and changes each time it's stored, so a change is made to the event as it was last seen, such as when it's delivered
type Opt ¶
type Opt func(*opt) error
Opt is a functional option for the registry
func WithAgentStore ¶ added in v0.6.0
func WithAgentStore(store AgentStore) Opt
WithAgentStore sets the store of the agents, such as a database, which other servers share, or files, so they're kept when the server restarts
func WithBroadcaster ¶ added in v0.6.0
func WithBroadcaster(b *broadcaster.Broadcaster) Opt
WithBroadcaster sets the broadcaster which the registry publishes its events to, such as one which others share, so a server's events are served together. Its owner runs it. Without it, the registry has its own, which isn't run, so its watches end only when they're cancelled.
func WithClientOpts ¶
WithClientOpts sets the options of the HTTP clients of the providers which the registry creates, such as their tracer, user agent and timeout
func WithCredentialsProvider ¶
func WithCredentialsProvider(credentials CredentialsProvider) Opt
WithCredentialsProvider sets the provider which expands credentials, such as the API key of a provider which is created, whose placeholders, such as ${OPENAI_KEY}, are replaced with the credentials they name. Without one, or with nil, the credentials are environment variables.
func WithEventBuilder ¶ added in v1.2.0
func WithEventBuilder(fn EventBuilder) Opt
WithEventBuilder sets the function which returns how an event, which TriggerEvent is given, is run, such as with what the system says of the person, and the tools it's run without. Without one, its input says only the time, in UTC, and it's run with every tool of the session it's for.
func WithEventStore ¶ added in v1.2.0
func WithEventStore(store EventStore) Opt
WithEventStore sets the store of the outcomes of the events which the registry runs, such as heartbeats which fire, so they can be seen, and delivered. Without one, an event's outcome is only in the session it ran in.
func WithMaxEvents ¶ added in v1.2.0
WithMaxEvents sets the most events, such as heartbeats which fire, and events which are triggered, which run at once, which is DefaultMaxEvents, unless it's set. Those which are run once these are, wait until one of them has, and an event which was triggered is scheduled until it runs. Returns ErrBadParameter when it's zero.
func WithProviderStore ¶ added in v0.6.0
func WithProviderStore(store ProviderStore) Opt
WithProviderStore sets the store of the providers, which the registry's providers are kept the same as, both ways, as Run syncs them, such as a database, which other servers share, or a file, so they're kept when the server restarts
func WithReplies ¶ added in v1.4.4
WithReplies sets the function which is called with each reply which Chat adds to a session, once it's stored, and each event's outcome which is delivered to one, with its text, and the resources it made, such as to send it to the session's channels, with a context which isn't cancelled when the chat's is, so it can take longer than its request
func WithResources ¶ added in v1.3.0
WithResources sets the resources, which messages' attachments, and the audio, documents and images which are transcribed, recognized, or embedded, refer to by their URIs, which are resource:///<hash>, whose content is read, as they're sent to a model, or none, when attachments can't refer to resources
func WithSessionRetention ¶ added in v1.4.1
WithSessionRetention deletes the sessions which haven't changed for the duration, as the registry runs, unless one is replying, or the function, when it isn't nil, says it's kept, such as one with a heartbeat. Zero keeps sessions until they're deleted.
func WithSessionStore ¶ added in v0.6.0
func WithSessionStore(store SessionStore) Opt
WithSessionStore sets the store of the sessions, such as a database, which other servers share, or files, so they're kept when the server restarts
func WithTimes ¶ added in v1.4.1
WithTimes tells a model when each of the person's messages was sent, at its start, such as (Saturday 2026-11-07T12:38+01:00), in the time zone the function returns, or UTC, when it's nil, or returns nil, when the model can call a tool of one of the namespaces, such as memory, which makes a chat an assistant's, so the model knows the time, and how long it's been since an earlier message, without its system prompt changing
func WithToolkit ¶
WithToolkit sets the toolkit of the tools which the registry's models can call
func WithTracer ¶
WithTracer sets the tracer, which traces the registry's operations, such as listing models, and generating messages
type ProviderOpt ¶
type ProviderOpt func(*cached) error
ProviderOpt is an option of a provider which is added to the registry
func WithExclude ¶
func WithExclude(patterns ...string) ProviderOpt
WithExclude excludes the models whose names match one of the patterns, which are regular expressions, such as -mini$
func WithInclude ¶
func WithInclude(patterns ...string) ProviderOpt
WithInclude includes only the models whose names match one of the patterns, which are regular expressions, such as ^gpt-, or every model when there are none
type ProviderStore ¶ added in v0.6.0
type ProviderStore interface {
// List returns the providers, with their serials, in any order
List(context.Context) ([]schema.Provider, error)
// Put creates the provider, when its serial is zero, and the store has
// no provider with its name, or replaces the provider with its name,
// when its serial is that provider's, and returns it, with its new
// serial. Returns ErrConflict when its serial isn't the provider's, as
// the provider was changed, or created, since it was seen.
Put(context.Context, schema.Provider) (schema.Provider, error)
// Delete deletes the provider with the name, when the serial is its
// serial, or does nothing when there's none. Returns ErrConflict when
// the serial isn't its serial, as it was changed since it was seen.
Delete(ctx context.Context, name string, serial uint64) error
// Watch sends the store's events to the channel, when its providers are
// changed by others, such as other servers, from when it returns, until
// the context is cancelled, as the registry's Watch does. It returns a
// channel which is sent nil, or an error when the store stops, once the
// watch has ended. A store which isn't changed by others, such as a
// file, sends no events, as its providers are listed periodically.
Watch(context.Context, chan<- eventschema.Event) (<-chan error, error)
}
ProviderStore has the definitions of providers, with their names, and their API keys' placeholders, such as ${OPENAI_KEY}, rather than their credentials, by their names, each with its serial, which the store sets, and changes each time the provider does, so a change is made to the provider as it was last seen, rather than a newer one, such as one which another server made
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the providers of models, by names which it gives them, so there can be more than one provider of a type, such as two Ollama servers. Providers can be added and removed. It's safe to use concurrently.
func New ¶
New returns a registry without providers, which are added with Add, with the options, such as its tracer
func (*Registry) Add ¶
Add adds the provider, with the name, which must be an identifier, such as my-ollama, which starts with a letter, followed by letters, numbers, underscores or hyphens, or with its own name, such as its type, when the name is empty, and the options, such as the patterns of the names of the models which are included, or excluded. Returns ErrConflict when a provider with the name, or the provider itself, is added already, and ErrBadParameter when a pattern isn't valid. Watchers are sent that it was created.
func (*Registry) AgentLoop ¶ added in v0.6.0
func (r *Registry) AgentLoop(ctx context.Context, model llm.Model, messages []llm.Message, tools []llm.Tool, stream llm.GeneratorStreamFn, opts ...llm.Opt) (_ []providerschema.Message, _ llm.Usage, err error)
AgentLoop asks the model for its reply to the messages, runs the tools it calls, and asks it again with their results, until it replies, its reply is truncated as it reached the most tokens it can generate, or it's been asked as many times as the max_iterations option, or DefaultMaxIterations times when it isn't set.
When the json_schema option is set, the model replies by calling the respond tool, which is added to the tools, with a result which conforms to the schema, and the system prompt says so. The reply is then the result, as JSON text, rather than the call, so each tool call in the conversation has its result. A model which replies with text is asked to call the tool, and a result which doesn't conform, or a call with other tools, is returned to the model as an error, each of which counts as an iteration, until it's been asked as many times as it can be.
Each tool has the tool_timeout option to return, or DefaultToolTimeout when it isn't set, after which its result is that it timed out. The results are truncated, as toolkit.TruncateResult does, as the model's provider measures them, or as they're estimated, so the model's context, which is the smaller of its input token limit and the context_window option, is at most two thirds full with them, or to DefaultToolResultLimit tokens each, when the model's context isn't known.
The max_iterations, tool_timeout and json_schema options are the loop's, so aren't passed to the model, unlike the other options. Returns the messages added to the conversation: each of the model's replies, followed by the results of the tools it called, or the request to call the respond tool, except the last, which is the model's last reply, whose result is why the loop stopped: stop, or another reason the model stopped; or max_tokens, blocked, error or max_iterations, when the tools it called aren't run, as its input may be incomplete, or it didn't finish, or it's been asked as many times as it can be, so are left out of it. So each tool call has its result, and the messages can be sent to a model again, as the rest of a conversation. When the reply has a schema, its result is stop only when it's the result. A tool which the model calls, and which isn't one of the tools, or fails, has its error returned to the model as its result. The replies are streamed to the function as they're generated, when it isn't nil, each separated by a blank line, until the loop returns, when nothing more is streamed, though a tool which didn't return in time may still log. Returns ErrBadParameter when a message is nil, an option isn't valid, or a tool is named as the respond tool when the reply has a schema, the errors of WithoutSession, and the context's error when it's done while a tool runs.
func (*Registry) AgentStore ¶ added in v0.6.0
func (r *Registry) AgentStore() AgentStore
AgentStore returns the store of the registry's agents, or nil when it has none, when it has no agents
func (*Registry) Ask ¶
func (r *Registry) Ask(ctx context.Context, req schema.AskRequest, stream llm.GeneratorStreamFn) (_ *schema.AskResponse, err error)
Ask returns the reply of the request's model to its messages, which include earlier turns of the conversation, as the agent loop does, but which stops when the model calls tools, whose calls are in its reply, for the caller to run, rather than run. The model replies after the system prompt, with the options, and can call the tools, which are got from the registry's toolkit. When the request has a schema, the model replies by calling the respond tool, whose result is the reply's result: a model which replies with text is asked to call it, and a result which doesn't conform to the schema is returned to the model to correct, until it's been asked respondAttempts times, or as many times as the max_iterations option. The messages are compacted, as the agent loop does, to fit the model's context, without changing them, and when they don't fit, however compacted, the model isn't asked, and the reply is empty, with max_context as its result. The reply is streamed to the function as it's generated, when it isn't nil, with each of the model's replies separated by a blank line. Returns ErrBadParameter when the request isn't valid, ErrNotFound when the model, or a tool, isn't found, and the errors of WithoutSession.
func (*Registry) Broadcaster ¶ added in v0.6.0
func (r *Registry) Broadcaster() *broadcaster.Broadcaster
Broadcaster returns the broadcaster which the registry publishes its events to, so its events can be served, and it can be run
func (*Registry) Chat ¶ added in v0.6.0
func (r *Registry) Chat(ctx context.Context, id uuid.UUID, messages []llm.Message, stream llm.GeneratorStreamFn) (_ *schema.ChatResponse, err error)
Chat adds the messages to the session with the identifier, and the messages which its model, asked as WithSession asks it, adds, which are its reply, the results of the tools it called, and the rest, and stores it, with its usage: the tokens used by every request to its model, and the tokens of its conversation, as of the reply. The reply is streamed to the function as it's generated, when it isn't nil. Returns what was added, with the session's serial, as it was stored. Returns ErrNotFound when there's no session, ErrForbidden when it's an event's, which isn't chatted in, ErrConflict when it was changed as the model replied, as the reply is to the conversation as it was, so isn't stored, apart from when messages were only added to it, such as an event's outcome, which was delivered, which then follow the reply, ErrServiceUnavailable when the registry has no session store, and the errors of WithSession. The session is replying until the model has replied, and its reply is stored.
func (*Registry) CreateAgent ¶ added in v0.6.0
func (r *Registry) CreateAgent(ctx context.Context, meta schema.AgentMeta) (_ *schema.Agent, created bool, err error)
CreateAgent creates an agent with the definition, in the registry's agent store, or replaces the agent with its name, with the definition, as it is, rather than merging them, when it's changed, and returns it, as it's stored, or the agent as it is, when it hasn't changed, so creating agents each time a server starts, such as its examples, changes only those which have, and whether it was created, rather than replaced, or kept. Its name must be an identifier, such as segment, which refers to it. Its input, when it has one, must be a JSON schema of an object, and its prompt a Go template, which is executed with the input. Its model, when it has one, is the registry's, by its canonical name, and its tools are the toolkit's, by their canonical names, as a session's are. It needn't have a model, as one can be given when it's run. Returns ErrBadParameter when the definition isn't valid, ErrNotFound when the model isn't the registry's, or a tool isn't the toolkit's, ErrConflict when the agent was changed as it was replaced, or a name is ambiguous, and ErrServiceUnavailable when the registry has no agent store.
func (*Registry) CreateProvider ¶
func (r *Registry) CreateProvider(ctx context.Context, req schema.Provider) (_ *schema.ProviderStatus, err error)
CreateProvider creates a provider of the type, such as ollama, and adds it to the registry, with its name, or its type when it has none, once it's validated, as newProvider does, and pinged. The request is kept, as the provider's definition, with its API key's placeholder, rather than its credentials, and its serial is 1, whatever the request's. Returns ErrBadParameter when the type is unknown, ErrServiceUnavailable when it can't be reached, as it can't be used, and ErrConflict when a provider with its name is added already.
func (*Registry) CreateSession ¶ added in v0.6.0
func (r *Registry) CreateSession(ctx context.Context, meta schema.SessionMeta) (_ *schema.Session, err error)
CreateSession creates a session with the settings, in the registry's session store, and returns it, with no messages. Its model, when it has one, is the registry's, by its canonical name, such as ollama:llama3.2:latest, and its tools are the toolkit's, by their canonical names, such as weatherapi:current, or a namespace and "*", or "*", as they are. It needn't have a model, as it can be inherited. Returns ErrBadParameter when the settings aren't valid, ErrNotFound when the model isn't the registry's, or a tool isn't the toolkit's, ErrConflict when a name is ambiguous, and ErrServiceUnavailable when the registry has no session store.
func (*Registry) DeleteAgent ¶ added in v0.6.0
DeleteAgent deletes the agent with the name, and returns it, as it was. Returns ErrNotFound when there's none, ErrConflict when it was changed as it was deleted, and ErrServiceUnavailable when the registry has no agent store.
func (*Registry) DeleteEvent ¶ added in v1.2.0
DeleteEvent deletes the outcome of the event with the identifier, and returns it, as it was. Returns ErrNotFound when there's none, ErrConflict when it was changed as it was deleted, and ErrServiceUnavailable when the registry has no event store.
func (*Registry) DeleteModel ¶
DeleteModel deletes the model, with its provider, which must be in the registry, and download models
func (*Registry) DeleteProvider ¶
func (r *Registry) DeleteProvider(ctx context.Context, name string) (_ *schema.ProviderStatus, err error)
DeleteProvider removes the provider with the name from the registry, and returns it, or returns ErrNotFound when there's none. It isn't pinged.
func (*Registry) DeleteSession ¶ added in v0.6.0
DeleteSession deletes the session with the identifier, with its messages, and returns it, as it was, without them, such as an event's, which is created again, when the event runs again. Returns ErrNotFound when there's none, ErrConflict when its model is replying, such as when an event runs in it, so it's deleted once it's replied, or when it was changed as it was deleted, and ErrServiceUnavailable when the registry has no session store.
func (*Registry) Embed ¶
func (r *Registry) Embed(ctx context.Context, model llm.Model, messages []llm.Message, opts ...llm.Opt) (_ []llm.Vector, _ llm.Usage, err error)
Embed returns a vector for each of the messages, from the model's provider, which must be in the registry, and embed messages, whose attachments which refer to resources on their own, by their URIs, are read. Returns ErrNotImplemented when the model is known not to embed, and the provider's error as providerErr does.
func (*Registry) EventStore ¶ added in v1.2.0
func (r *Registry) EventStore() EventStore
EventStore returns the store of the outcomes of the events which the registry runs, or nil when it has none
func (*Registry) ForgetSessionMessages ¶ added in v1.0.0
func (r *Registry) ForgetSessionMessages(ctx context.Context, id uuid.UUID) (_ *schema.Session, err error)
ForgetSessionMessages forgets the messages of the session with the identifier, keeping its settings, so its conversation starts again, and returns it, without them. The tokens of its conversation are none, and the tokens used by every request to its model are kept. Returns ErrNotFound when there's none, ErrConflict when it was changed as they were forgotten, and ErrServiceUnavailable when the registry has no session store. A reply which is being waited for, as they're forgotten, isn't stored.
func (*Registry) GetAgent ¶ added in v0.6.0
GetAgent returns the agent with the name. Returns ErrNotFound when there's none, and ErrServiceUnavailable when the registry has no agent store.
func (*Registry) GetEvent ¶ added in v1.2.0
GetEvent returns the outcome of the event with the identifier. Returns ErrNotFound when there's none, and ErrServiceUnavailable when the registry has no event store.
func (*Registry) GetModel ¶
GetModel returns the model with the name, which is its canonical name, such as ollama:llama3.2:latest, which is its provider's name in the registry, and its name, or otherwise its name, or an alias, which every provider's models are searched for at once. A model must match its provider's patterns. The models are cached, as ListModels does. Returns ErrNotFound when no provider has it, and ErrConflict when more than one does, so its canonical name is needed. When no provider has it, and a provider can't be asked, such as when it can't be reached, that provider's error is returned.
func (*Registry) GetProvider ¶
func (r *Registry) GetProvider(ctx context.Context, name string) (_ *schema.ProviderStatus, err error)
GetProvider returns the provider with the name, with whether it can be reached, when it was last pinged, within PingInterval, or ErrNotFound when there's none
func (*Registry) GetSession ¶ added in v0.6.0
GetSession returns the session with the identifier, without its messages, which ListSessionMessages lists. Returns ErrNotFound when there's none, and ErrServiceUnavailable when the registry has no session store.
func (*Registry) Illustrate ¶ added in v1.4.0
func (r *Registry) Illustrate(ctx context.Context, model llm.Model, prompt string, images []llm.Resource, opts ...llm.Opt) (_ []llm.Resource, _ llm.Usage, err error)
Illustrate returns the images the model makes from the prompt, or by changing, or combining, the images, which can refer to resources, by their URIs, as the prompt says, from the model's provider, which must be in the registry, and make images. Returns ErrNotImplemented when the model is known not to make images, ErrBadParameter when one of the images isn't an image, or they're larger than MaxAttachmentsSize, together, and the provider's error as providerErr does.
func (*Registry) Keep ¶ added in v1.4.0
func (r *Registry) Keep(ctx context.Context, session uuid.UUID, resource llm.Resource, name string) (toolschema.ResourceLink, bool, error)
Keep keeps the resource, such as an image a model made, as a resource of the session, or, without one, on its own, with its name, or one of its type, such as image.png, when it's empty, and returns the link to it, and whether it was kept, which it isn't when the registry has no resources.
func (*Registry) ListAgents ¶ added in v0.6.0
func (r *Registry) ListAgents(ctx context.Context, req schema.AgentListRequest) (_ *schema.AgentList, err error)
ListAgents returns the agents, in the store's order, as the request selects. Returns ErrServiceUnavailable when the registry has no agent store.
func (*Registry) ListEvents ¶ added in v1.2.0
func (r *Registry) ListEvents(ctx context.Context, req schema.EventListRequest) (_ *schema.EventList, err error)
ListEvents returns the outcomes of the events which the request selects, those for its session, and of its status, when it has them, the most recent first, from its offset, and at most its limit of them, and how many it selects. Returns ErrBadParameter when the session isn't a UUID, and ErrServiceUnavailable when the registry has no event store.
func (*Registry) ListModels ¶
ListModels returns the models of every provider, or of the providers with the names, when there are any, which must exist, which match their patterns, in order of their providers' names, and then their names. The models are cached, and are listed again, at once, when they're stale. When a provider's models can't be listed, such as when it can't be reached, and none are cached, the others' models are returned, with an error saying which providers' couldn't be.
func (*Registry) ListProviders ¶
func (r *Registry) ListProviders(ctx context.Context, req schema.ProviderListRequest) (_ *schema.ProviderList, err error)
ListProviders returns the providers, in order of their names, of the type which the request selects, or every type, which are pinged at once, so it's known which can't be reached
func (*Registry) ListSessionMessages ¶ added in v0.6.0
func (r *Registry) ListSessionMessages(ctx context.Context, id uuid.UUID, req schema.MessageListRequest) (_ *schema.MessageList, err error)
ListSessionMessages returns the messages of the session with the identifier, oldest first, as the request selects: of its role, or every role, from its offset, and at most its limit of them, and how many there are. Returns ErrNotFound when there's no session, and ErrServiceUnavailable when the registry has no session store.
func (*Registry) ListSessions ¶ added in v0.6.0
func (r *Registry) ListSessions(ctx context.Context, req schema.SessionListRequest) (_ *schema.SessionList, err error)
ListSessions returns the sessions, without their messages, most recently modified first, as the request selects. Returns ErrServiceUnavailable when the registry has no session store.
func (*Registry) LoadModel ¶
func (r *Registry) LoadModel(ctx context.Context, name string, progress llm.DownloadProgressFn) (_ llm.Model, err error)
LoadModel downloads the model with the name, with its provider, which must download models, and returns it. As the model may not exist yet, the name must be its canonical name, such as ollama:llama3.2:latest, unless only one of the providers downloads models.
func (*Registry) Measure ¶ added in v0.6.0
Measure returns how many tokens the text is, for the model, from the model's provider, which must be in the registry, when it measures text, or otherwise an estimate, of a token for every bytesPerToken bytes, or part of one. Returns the provider's error as providerErr does.
func (*Registry) Model ¶
Model returns the model, with the name of its provider in the registry, and its canonical name
func (*Registry) Name ¶
Name returns the canonical name of the model, which is the name of its provider in the registry, and its name, such as my-ollama:llama3.2:latest, or its provider's own name, when its provider isn't in the registry
func (*Registry) Ping ¶
Ping pings every provider at once, and returns when they've replied, with the errors of those which failed joined, each saying which provider it is, or nil when every ping succeeded. The providers are pinged, whenever they were last.
func (*Registry) Ready ¶ added in v1.1.0
func (r *Registry) Ready() <-chan struct{}
Ready returns a channel which is closed once Run has loaded the stored agents, and synced the providers, and their models, when it starts, so what needs them, such as heartbeats which are overdue, waits for it
func (*Registry) Recognize ¶
func (r *Registry) Recognize(ctx context.Context, model llm.Model, resource llm.Resource, opts ...llm.Opt) (_ llm.Document, _ llm.Usage, err error)
Recognize returns the text in the resource, such as an image or a PDF, as a document, from the model's provider, which must be in the registry, and recognize text. Returns ErrNotImplemented when the model is known not to recognize text, and the provider's error as providerErr does.
func (*Registry) Remove ¶
Remove removes the provider with the name, and returns it, so it can be closed, or returns ErrNotFound when there's none. Calls which have started already, such as listing models, still use it. Watchers are sent that it was deleted.
func (*Registry) Run ¶
Run keeps the registry current, until the context is cancelled, when it returns nil: it pings the providers, and lists the models of those whose models are stale, when it starts, and every PingInterval, so the providers' state, and their models, are kept current, and with a store, it syncs the registry's providers with the store's, when it starts, as either changes, and every PingInterval, as an event can be missed. The errors syncing them, which are synced again later, are logged with the logger, or aren't when it's nil. When the store stops, it returns its error. The registry is used without it, when its models are listed as they're needed. With a store of sessions, the changes others make to them, which it sends as events, are published as the registry's own. With a store of agents, and a toolkit, the stored agents are made tools, when it starts. With a store of sessions, and WithSessionRetention, the sessions which haven't changed for longer than they're kept are deleted, when it starts, and every RetentionInterval.
func (*Registry) RunAgent ¶ added in v0.6.0
func (r *Registry) RunAgent(ctx context.Context, name string, req schema.RunAgentRequest, stream llm.GeneratorStreamFn) (_ *schema.RunAgentResponse, err error)
RunAgent runs the agent with the name: the request's input is validated against its input schema, and its prompt is executed with it, as the message to its model, which is its own, or, when it has none, the model of the session it's run from, which is asked as its settings say, without its history, and runs the tools it calls, until it replies. Its reply is streamed to the function as it's generated, when it isn't nil. Returns what the agent did: the messages it added, the tokens used, and its reply, as JSON, which is its text, or what it replied, when it has a schema.
The agents which are running, as an agent calls another, or itself, as a tool, are in the context, with the most which can run in one another, which is the max_depth option of the session, or agent, which runs them, or the least of them, or DefaultMaxDepth, so an agent isn't run deeper, as agents could call one another without end.
Returns ErrNotFound when there's no agent with the name, or session, ErrForbidden when it would run deeper than the most agents which can run in one another, ErrBadParameter when its input isn't valid, or its prompt can't be executed with it, or it has no model, nor has the session it's run from, and ErrServiceUnavailable when the registry has no agent store, and the errors of WithSession.
func (*Registry) RunEvent ¶ added in v1.1.0
func (r *Registry) RunEvent(ctx context.Context, id uuid.UUID, req schema.RunEventRequest, stream llm.GeneratorStreamFn) (_ *schema.RunEventResponse, err error)
RunEvent runs the event with the identifier, such as a heartbeat which fired, with the request's agent, or the event agent, and its input, from the event's session, whose identifier is the event's, so an event which happens again, such as a heartbeat on a schedule, has the one session, and returns the session, and what the agent did, and replied, which is added to the session, with its usage, so it has each run, which is shown as it's replying, as the agent runs. The session is created, when there's none, with the model of the session the event is for, and the event's title, and takes them again, when they've changed, each time it's run, and an agent which has no model, such as the event agent, is run with it, and with the tools of the session the event is for, apart from those of the namespaces it's without, such as heartbeat, so an event doesn't schedule events. Returns ErrBadParameter when the identifier, or the session, is the nil UUID, or they're the same, or the session has no model, ErrNotFound when there's no session, or agent, ErrConflict when the event's session was changed as the agent ran, such as when its messages were forgotten, so what it did isn't stored, ErrServiceUnavailable when the registry has no session store, or agent store, and the errors of RunAgent.
func (*Registry) SessionStore ¶ added in v0.6.0
func (r *Registry) SessionStore() SessionStore
SessionStore returns the store of the registry's sessions, or nil when it has none, when it has no sessions
func (*Registry) SetSessionStatus ¶ added in v0.6.0
func (r *Registry) SetSessionStatus(ctx context.Context, id uuid.UUID, value schema.SessionStatus) (_ *schema.Session, err error)
SetSessionStatus sets the status of the session with the identifier, as a client says someone is typing a message, which it is until TypingTimeout after it was last said, or they stopped, when it's idle, unless its model is replying, which it is until it has replied. A change of the status is published as an update of the session. Returns the session, without its messages, with its status. Returns ErrBadParameter when the status isn't typing or idle, ErrNotFound when there's no session, and ErrServiceUnavailable when the registry has no session store.
func (*Registry) Speak ¶ added in v1.3.0
func (r *Registry) Speak(ctx context.Context, model llm.Model, text string, opts ...llm.Opt) (_ llm.Resource, _ llm.Usage, err error)
Speak returns the text, spoken, as audio, from the model's provider, which must be in the registry, and speak text. Returns ErrNotImplemented when the model is known not to speak, and the provider's error as providerErr does.
func (*Registry) Toolkit ¶
Toolkit returns the toolkit of the tools which the registry's models can call, or nil when it has none
func (*Registry) Transcribe ¶
func (r *Registry) Transcribe(ctx context.Context, model llm.Model, audio llm.Resource, stream llm.TranscriberStreamFn, opts ...llm.Opt) (_ llm.Transcript, _ llm.Usage, err error)
Transcribe returns the speech in the audio, from the model's provider, which must be in the registry, and transcribe audio, and streams its pieces to the function, when it isn't nil. Returns ErrNotImplemented when the model is known not to transcribe, and the provider's error as providerErr does.
func (*Registry) Translate ¶
func (r *Registry) Translate(ctx context.Context, model llm.Model, audio llm.Resource, stream llm.TranscriberStreamFn, opts ...llm.Opt) (_ llm.Transcript, _ llm.Usage, err error)
Translate returns the speech in the audio as English text, from the model's provider, which must be in the registry, and transcribe audio. Returns ErrNotImplemented when the model can't translate, or is known not to, and the provider's error as providerErr does.
func (*Registry) TriggerEvent ¶ added in v1.2.0
func (r *Registry) TriggerEvent(ctx context.Context, req schema.EventRequest) (_ *schema.TriggerEventResponse, err error)
TriggerEvent schedules the event, from a source other than a heartbeat, such as a file which changed, or a webhook, to run, in the background, in the session of its source, for the session it's for, or a session of its own, when it has no source, as RunEvent runs it, and returns its outcome, which is scheduled, until it's run, when it's updated, as it's pending, or ignored, or failed, when it couldn't be run, with the error as its message. An event of a source which is scheduled already, for the session, isn't scheduled, so a burst of them runs once, and the outcome of that event is returned. Returns ErrBadParameter when it has no session, or prompt, ErrNotFound when there's no session, and ErrServiceUnavailable when the registry has no event store, in which its outcome is kept, or session store.
func (*Registry) UnloadModel ¶
UnloadModel unloads the model from memory, with its provider, which must be in the registry, and load models, keeping it stored, so its provider's models aren't listed again. Returns ErrNotImplemented when the provider doesn't load models, or can't unload them.
func (*Registry) UpdateAgent ¶ added in v0.6.0
func (r *Registry) UpdateAgent(ctx context.Context, name string, meta schema.AgentMeta) (_ *schema.Agent, err error)
UpdateAgent changes the definition of the agent with the name, as AgentMeta.Merge does: what the update sets is changed, its options are set, or removed, when they're null, and the rest is kept. Its name isn't changed: the update has no name, or the agent's, such as when it's the agent's whole definition. The definition, as changed, must be valid, as CreateAgent says, and a model, or tools, which are changed are the registry's, by their canonical names. Returns the agent. Returns ErrBadParameter when the update has another name, or changes nothing, or the definition, as changed, isn't valid, ErrNotFound when there's no agent, or the model, or a tool, isn't the registry's, ErrConflict when it was changed as it was updated, or a name is ambiguous, and ErrServiceUnavailable when the registry has no agent store.
func (*Registry) UpdateProvider ¶
func (r *Registry) UpdateProvider(ctx context.Context, name string, meta schema.ProviderMeta) (_ *schema.ProviderStatus, err error)
UpdateProvider changes the provider with the name: its fields which can be set are replaced with the meta, apart from its API key, which is kept when the meta has none, as it isn't returned. Its type and name aren't changed. The provider is created again, as CreateProvider does, and replaces it, whether it can be reached or not, which it says, with its serial incremented, and watchers are sent that it was updated. A provider whose fields are the same is left as it is. Returns ErrNotFound when there's no provider with the name, ErrBadParameter when the meta isn't valid, and ErrConflict when the provider was added without a definition, such as with Add.
func (*Registry) UpdateSession ¶ added in v0.6.0
func (r *Registry) UpdateSession(ctx context.Context, id uuid.UUID, meta schema.SessionMeta) (_ *schema.Session, err error)
UpdateSession changes the settings of the session with the identifier, as SessionMeta.Merge does: what the update sets is changed, its options are set, or removed, when they're null, and the rest is kept, as are the session's messages. A model, or tools, which are changed are the registry's, by their canonical names, as CreateSession says. Returns the session. Returns ErrBadParameter when the update changes nothing, or the settings, as changed, aren't valid, ErrNotFound when there's no session, or the model, or a tool, isn't the registry's, ErrConflict when it was changed as it was updated, and ErrServiceUnavailable when the registry has no session store.
func (*Registry) Watch ¶
Watch sends the registry's broadcaster's events to the channel, as the broadcaster's Watch does. The registry's events are of providers: when one is created, or deleted, and updated, when whether it can be reached changes, or its models do, and of sessions: when one is created, deleted, or updated, as its settings change, messages are added to it, or its status changes. A broadcaster which others share sends their events too.
func (*Registry) WithSession ¶ added in v0.6.0
func (r *Registry) WithSession(ctx context.Context, session schema.Session, messages []llm.Message, stream llm.GeneratorStreamFn) (_ *schema.SessionResponse, err error)
WithSession asks the session's model, after its system prompt, with its options, tools and the schema of the reply, for its reply to the conversation, which is the session's messages, each with its tokens, when it has them, and the messages, as the agent loop does, which runs the tools the model calls. The messages can be any messages, which are kept as messages of the provider schema, with the data of their attachments read. Returns the messages to add to the session: the messages, and those the loop added, the last of which is the model's reply, each with its tokens; the tokens of the conversation, with them, of the messages sent to the model, of its replies, and of what's sent with them; and the usage. With a schema, the model's reply, when its result is stop, is JSON which conforms to it. The session isn't changed. The reply is streamed to the function as it's generated, when it isn't nil. Returns ErrBadParameter when the session, or the messages, aren't valid, ErrNotFound when the model, or a tool, isn't found, and the errors of AgentLoop.
func (*Registry) WithoutSession ¶
func (r *Registry) WithoutSession(ctx context.Context, model llm.Model, messages []llm.Message, tools []llm.Tool, stream llm.GeneratorStreamFn, opts ...llm.Opt) (_ llm.Message, _ llm.Usage, err error)
WithoutSession returns the model's reply to the messages, from the model's provider, which must be in the registry, and generate messages, or the provider's error as providerErr does. Returns ErrNotImplemented, without asking the provider, when the model is known not to reply, or there are tools, and it's known not to call them, or it's asked to think, and it's known not to, or the messages have images, and it's known not to see them.
type Reply ¶ added in v1.5.0
type Reply struct {
Text string
Resources []toolschema.ResourceLink
}
Reply is a reply in a session: its text, and the resources it made, such as an image, or speech, which are the session's
type ReplyFunc ¶ added in v1.4.4
ReplyFunc is called with the session, and its model's reply, once Chat has stored it, or an event's outcome, once it's delivered to it
type Resources ¶ added in v1.3.0
type Resources interface {
// Resource returns the resource with the URI, in the session, or on its
// own, when it's nil, whose content is read from where it's kept.
// Returns ErrNotFound when there's none.
Resource(ctx context.Context, uri string, session *uuid.UUID) (llm.Resource, error)
// Link links the resource with the URI, which is on its own, to the
// session, so it's kept with it, and returns it, as the session's.
// Returns ErrNotFound when there's no resource on its own with it, or
// the session doesn't exist.
Link(ctx context.Context, uri string, session uuid.UUID) (resourceschema.Resource, error)
// Copy copies the resource with the URI, of the session it's from, to
// the other session, so it's kept with it too, and returns it, as the
// other session's. Returns ErrNotFound when the session it's from has no
// resource with it, or the other session doesn't exist.
Copy(ctx context.Context, uri string, from, to uuid.UUID) (resourceschema.Resource, error)
// List returns the resources the request selects, such as a session's,
// a page at a time
List(ctx context.Context, req resourceschema.ResourceListRequest) (resourceschema.ResourceList, error)
// Create keeps the content, as it's read, as a resource, which is what
// the meta says, in its session, or on its own, and returns it, and
// whether it was created, rather than there being one with its content
// already
Create(ctx context.Context, meta resourceschema.ResourceMeta, content io.Reader) (resourceschema.Resource, bool, error)
}
Resources are content, such as images, documents and audio, which is kept once, and referred to by its URI, which is resource:///<hash>, which is in a session, or on its own, such as the resource package's manager
type SessionStore ¶ added in v0.6.0
type SessionStore interface {
// Create creates a session with the identifier, or a new one, when it's
// the nil UUID, with the settings, and no messages, and returns it, with
// its identifier, serial, and when it was created. Returns ErrConflict
// when there's a session with the identifier.
Create(ctx context.Context, id uuid.UUID, meta schema.SessionMeta) (schema.Session, error)
// Get returns the session with the identifier, with its messages.
// Returns ErrNotFound when there's none.
Get(ctx context.Context, id uuid.UUID) (schema.Session, error)
// List returns the sessions, without their messages, most recently
// modified first, from the request's offset, and at most its limit of
// them, and how many there are
List(context.Context, schema.SessionListRequest) (schema.SessionList, error)
// Put replaces the session with its identifier, when its serial is that
// session's, and returns it, with its new serial, and when it was
// modified. Returns ErrNotFound when there's none, and ErrConflict when
// its serial isn't the session's, as it was changed since it was seen.
Put(context.Context, schema.Session) (schema.Session, error)
// Delete deletes the session with the identifier, when the serial is its
// serial, or does nothing when there's none. Returns ErrConflict when the
// serial isn't its serial, as it was changed since it was seen.
Delete(ctx context.Context, id uuid.UUID, serial uint64) error
// Watch sends the store's events to the channel, when its sessions are
// changed by others, such as other servers, from when it returns, until
// the context is cancelled, as the registry's Watch does: the table is
// SessionTable, the row the session's identifier, and when it was
// created or updated, the data is its serial, as a SessionEvent. It
// returns a channel which is sent nil, or an error when the store stops,
// once the watch has ended. A store which isn't changed by others, such
// as files which only its server writes, sends no events.
Watch(context.Context, chan<- eventschema.Event) (<-chan error, error)
}
SessionStore has sessions, each with its identifier and serial, which the store sets, and changes each time the session is stored, so a change is made to the session as it was last seen, rather than a newer one, such as when two replies are added to it at once
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cmd has the registry's commands and flags
|
Package cmd has the registry's commands and flags |
|
tui
Package tui is a terminal interface to chat in a session, which is a throwaway, until there's a better one
|
Package tui is a terminal interface to chat in a session, which is a throwaway, until there's a better one |
|
Package httpclient is a client of the registry's HTTP API
|
Package httpclient is a client of the registry's HTTP API |
|
Package httphandler has the registry's HTTP API
|
Package httphandler has the registry's HTTP API |
|
Package schema has the requests and responses of the registry's API
|
Package schema has the requests and responses of the registry's API |
|
Package test has a registry and a HTTP server of its API, for tests
|
Package test has a registry and a HTTP server of its API, for tests |