Documentation
¶
Overview ¶
Package workspace is a registry of workspaces: sets of resources, such as a folder, or a vault of notes, which are listed, and later read, searched and watched, and served, such as over MCP.
Index ¶
- Constants
- func IsTree(c *client.Client) bool
- func ReadMarkdown(ctx context.Context, resource llm.Resource, offset, limit uint64) (*schema.Markdown, error)
- type Available
- type Describer
- type Opt
- type Reader
- type Registry
- func (r *Registry) Add(name string, ws Workspace) error
- func (r *Registry) All() iter.Seq2[string, Workspace]
- func (r *Registry) Close() error
- func (r *Registry) GetWorkspace(ctx context.Context, name string) (result *schema.Workspace, err error)
- func (r *Registry) ListResources(ctx context.Context, name string, req schema.ListRequest) (result *schema.ListResponse, err error)
- func (r *Registry) ListWorkspaces(ctx context.Context) *schema.WorkspaceList
- func (r *Registry) Read(ctx context.Context, name, uri string) (resource llm.Resource, err error)
- func (r *Registry) Remove(name string) (Workspace, error)
- func (r *Registry) RemoveIf(name string, ws Workspace) bool
- func (r *Registry) Resolve(ctx context.Context, uri string) (_ llm.Resource, err error)
- func (r *Registry) Run(ctx context.Context, logger *slog.Logger) error
- func (r *Registry) Running() bool
- func (r *Registry) With(name string, fn func(Workspace) error) error
- type ResourceEvent
- type Rooted
- type Subscriber
- type Tree
- type Watcher
- type Workspace
Constants ¶
const ( // DefaultMarkdownLimit is how much of a resource's Markdown is read, // when it isn't said, and MaxMarkdownLimit the most, so a part doesn't // fill a model's context DefaultMarkdownLimit = 16 * 1024 // MaxLengthSize is the largest resource whose first part has the length // of all of its Markdown, which converts all of it MaxLengthSize = 4 * 1024 * 1024 MaxMarkdownLimit = 64 * 1024 // NoTextNote is the note of a resource which has no text, though it's // read as Markdown, such as a page which its scripts render, as an MCP // app's is, of which only its metadata is returned NoTextNote = "" /* 137-byte string literal not displayed */ )
const ( // EventSchema is the schema of the registry's events EventSchema = "workspace" // WorkspaceTable is the table of the events of the workspaces which // are added, and removed, whose rows are their names WorkspaceTable = "workspace" // WatchTimeout is how long Add waits for a workspace which is a Watcher // to say it's watching, before it's said to be added WatchTimeout = 5 * time.Second // ResourceTable is the table of the events of the workspaces' folders, // and resources, which change, whose rows are the workspaces' names, // and whose data is a ResourceEvent ResourceTable = "resource" )
const ChunkSize = 4 * 1024 * 1024
ChunkSize is the most bytes of a resource's content which are read from an MCP server at once, which is less than its server's MaxChunk, so its JSON-RPC frame, in base64, is less than the SDK reads
Variables ¶
This section is empty.
Functions ¶
func IsTree ¶
IsTree returns true when the client's server says its folders are listed on their own, in its workspace capability
func ReadMarkdown ¶
func ReadMarkdown(ctx context.Context, resource llm.Resource, offset, limit uint64) (*schema.Markdown, error)
ReadMarkdown reads the resource as Markdown, with go-metadata, which reads text, HTML, PDFs, Office documents, email and more: a part of it, from the byte of its Markdown at the offset, of at most the limit, which is DefaultMarkdownLimit, when it's zero, and at most MaxMarkdownLimit, and, with the first part, its metadata. Returns ErrNotImplemented when it has no Markdown, such as audio, or it isn't text, and ErrBadParameter when the offset is beyond its end, or it isn't what its type says.
Types ¶
type Available ¶
type Available interface {
Workspace
// Available returns true when it's a workspace, now
Available() bool
}
Available is a workspace which is one only some of the time, such as an MCP server's namespace, which is while it's connected to a server which says it's a workspace. A registry has it only while it's available.
type Opt ¶
type Opt func(*opt) error
Opt is an option of a registry
func WithBroadcaster ¶
func WithBroadcaster(b *broadcaster.Broadcaster) Opt
WithBroadcaster publishes the registry's changes: a workspace which is added, or removed, in WorkspaceTable, whose row is its name, and the folders and resources of a Watcher which change, in ResourceTable, whose row is the workspace's name, and whose data is the change's URI
func WithTracer ¶
WithTracer traces the registry's operations, such as listing, and reading, its workspaces' resources
type Reader ¶
type Reader interface {
Workspace
// Read returns the resource, or artwork, with the URI which a listed
// resource, or its artwork, has, whose content is read as it's read.
// Returns ErrNotFound when there's none, and ErrBadParameter for a
// folder, which has no content.
Read(ctx context.Context, uri string) (llm.Resource, error)
}
Reader is a workspace whose resources, and artwork, are read, by their URIs, which a workspace doesn't need to be
func NewClient ¶
NewClient returns the workspace of the resources of the MCP server, whose client is connected. A server which is a workspace, as its capability says, lists its folders; one which isn't lists all its resources. Its name, title, and description are the server's, or its namespace's. Returns ErrBadParameter when there's no client.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the workspaces, by their names. It's safe to use concurrently.
func New ¶
New returns a registry, with no workspaces, with the options, such as the broadcaster its changes are published to, with WithBroadcaster
func (*Registry) Add ¶
Add adds the workspace, with the name, such as its namespace's. Returns ErrBadParameter when there's no workspace, or the name isn't an identifier, and ErrConflict when the registry has a workspace with the name.
func (*Registry) All ¶
All returns the workspaces which are available, by their names, in order of their names, as they were when it's ranged over, which can add, or remove, workspaces, as it ranges
func (*Registry) GetWorkspace ¶
func (r *Registry) GetWorkspace(ctx context.Context, name string) (result *schema.Workspace, err error)
GetWorkspace returns the workspace with the name, with whether it reads its resources, and is watched. Returns ErrNotFound when there's none.
func (*Registry) ListResources ¶
func (r *Registry) ListResources(ctx context.Context, name string, req schema.ListRequest) (result *schema.ListResponse, err error)
ListResources returns a page of the folders, and resources, of the workspace with the name, whose URIs, and their artwork's, are the workspace's, resource://<workspace>/<uri>. Returns ErrNotFound when there's none.
func (*Registry) ListWorkspaces ¶
func (r *Registry) ListWorkspaces(ctx context.Context) *schema.WorkspaceList
ListWorkspaces returns the workspaces which are available, in order of their names, with whether each reads its resources, and is watched now
func (*Registry) Read ¶
Read returns the resource, or artwork, with the URI, which is the workspace's, resource://<workspace>/<uri>, or its own, of the workspace with the name, whose URI is the workspace's. Returns ErrNotFound when there's no workspace with the name, or the URI is another's, and ErrNotImplemented when it isn't a Reader, so its resources aren't read.
func (*Registry) Remove ¶
Remove removes the workspace with the name, and returns it. Returns ErrNotFound when there's none.
func (*Registry) RemoveIf ¶
RemoveIf removes the workspace with the name, when it's the workspace, rather than one which replaced it, and returns true, or returns false
func (*Registry) Resolve ¶
Resolve returns the resource, or artwork, with the URI, which is a workspace's, resource://<workspace>/<uri>, which is read from it, or its own URI, which is read from whichever of the workspaces, in order of their names, which read their resources, has it. Its URI is the workspace's. Returns ErrNotFound when none has it.
func (*Registry) Run ¶
Run logs the registry's changes, with the logger, as they're published to its broadcaster: the workspaces which are added, or removed, and their folders, and resources, which change, until the context is cancelled, when it returns nil. Without a broadcaster, it waits until then. Returns ErrConflict when it's running already.
func (*Registry) Running ¶
Running returns true while the registry runs, once Run, which is started in a goroutine, has started, and until it stops
type ResourceEvent ¶
type ResourceEvent struct {
URI string `json:"uri,omitempty"`
}
ResourceEvent is the data of an event of a workspace's folders, and resources, which changed: the URI of the folder, or resource, or none, when it isn't known which
type Rooted ¶
type Rooted interface {
Workspace
// Root returns the root of its resources' URIs, which ends with a
// slash, or nothing, when it has none
Root() string
}
Rooted is a workspace whose resources' URIs are under a root, such as file:///, which a registry leaves out of their URIs, such as resource://files/notes/a.md, of file:///notes/a.md
type Subscriber ¶
type Subscriber interface {
Watcher
// Subscribe asks for the resource with the URI's updates
Subscribe(ctx context.Context, uri string) error
// Unsubscribe stops asking for the resource with the URI's updates
Unsubscribe(ctx context.Context, uri string) error
}
Subscriber is a watcher which says a resource is updated only once it's subscribed to, such as an MCP server's, which a server of it subscribes to, as its own clients do
type Tree ¶
type Tree interface {
Workspace
// Tree returns true when its folders are listed on their own, now
Tree() bool
}
Describer is a workspace which says what it is, for people: its title, description, and version, such as an MCP connector's namespace, whose title, and version, are its server's, and whose description is its namespace's, which a workspace doesn't need to be Tree is a workspace whose folders are listed on their own, by their type, FolderType, and have their paths, so they're shown as a tree
type Watcher ¶
type Watcher interface {
Workspace
// WatchResources sends each folder, and resource, which is created, updated, or
// deleted, to the channel, until the context is cancelled, when it
// returns nil, or it fails. Each is waited for the channel to receive,
// so none is missed, and the channel is read until the context is
// cancelled. A change without a URI says the workspace changed, but not
// where, so it's listed again, which it sends first, once it's watching,
// so a change after that isn't missed.
WatchResources(ctx context.Context, ch chan<- schema.Change) error
}
Watcher is a workspace whose folders, and resources, change, which it says, which a workspace doesn't need to be
type Workspace ¶
type Workspace interface {
// List returns the workspace's folders and resources, in a folder, or
// under it, a page at a time, in an order which is the same each time,
// so its pages don't overlap. A folder is a resource whose type is
// schema.FolderType, so a tree is made of what's listed.
List(ctx context.Context, req schema.ListRequest) (*schema.ListResponse, error)
}
Workspace is a set of resources, such as a folder, or a vault of notes. Its name, title and description are its namespace's, or MCP server's, and it's added to a registry by its name.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cmd has the workspaces' flags, and their registry, for the server
|
Package cmd has the workspaces' flags, and their registry, for the server |
|
Package filer is a workspace of a go-filer backend, such as a directory, or a bucket, which lists its folders and files, reads them, and watches them, when the backend can, and an MCP server of it
|
Package filer is a workspace of a go-filer backend, such as a directory, or a bucket, which lists its folders and files, reads them, and watches them, when the backend can, and an MCP server of it |
|
Package httpclient is a client of the workspaces' API
|
Package httpclient is a client of the workspaces' API |
|
Package schema has the types of workspaces: what's listed of their folders and resources, with their metadata and artwork
|
Package schema has the types of workspaces: what's listed of their folders and resources, with their metadata and artwork |