resources

package
v0.1.49 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 59 Imported by: 1

Documentation

Index

Constants

View Source
const Name = "resources"

Name identifies the resources tool service namespace

Variables

This section is empty.

Functions

func BindingDocuments added in v0.1.48

func BindingDocuments(documents []embSchema.Document, selection DocumentSelection) []*binding.Document

BindingDocuments maps structured semantic-match results to ordinary binding documents. Document metadata is preserved from the resource index so callers can use neutral keys such as document.title and source.url without reopening source files at request time.

func WithAgentFinder

func WithAgentFinder(f agmodel.Finder) func(*Service)

WithAgentFinder attaches an agent finder to resolve agent resources in context.

func WithConversationClient

func WithConversationClient(c apiconv.Client) func(*Service)

WithConversationClient attaches a conversation client for context-aware filtering.

func WithDefaultEmbedder

func WithDefaultEmbedder(id string) func(*Service)

WithDefaultEmbedder specifies a default embedder ID to use when the caller does not provide one. This typically comes from executor config defaults.

func WithDefaults

func WithDefaults(d ResourcesDefaults) func(*Service)

WithDefaults configures default roots and presentation hints.

func WithMCPManager

func WithMCPManager(m *mcpmgr.Manager) func(*Service)

WithMCPManager attaches an MCP manager for listing/downloading MCP

func WithSkillService added in v0.1.8

func WithSkillService(skillSvc *skillsvc.Service) func(*Service)

Types

type DocumentSelection added in v0.1.48

type DocumentSelection struct {
	MinScore      *float64
	MaxDocuments  int
	MaxTotalBytes int
}

DocumentSelection is a generic post-match policy. It operates only on documents already returned by resources:match; it does not interpret the user query or source-specific document formats.

type ExportFormat added in v0.1.39

type ExportFormat struct {
	Format string `json:"format"`
	DPI    int    `json:"dpi,omitempty"`
}

type ExportInput added in v0.1.39

type ExportInput struct {
	URI             string             `json:"uri,omitempty"`
	Path            string             `json:"path,omitempty"`
	RootID          string             `json:"rootId,omitempty"`
	Select          *ResourceSelection `json:"select,omitempty"`
	Operation       string             `json:"operation"`
	Output          ExportFormat       `json:"output"`
	Options         *ResourceOptions   `json:"options,omitempty"`
	ExpectedVersion string             `json:"expectedVersion,omitempty"`
}

type ExportOutput added in v0.1.39

type ExportOutput struct {
	Warnings      []string                            `json:"warnings,omitempty"`
	Resources     []*scratchpadsvc.ArtifactDescriptor `json:"resources"`
	SourceVersion string                              `json:"sourceVersion"`
	Complete      bool                                `json:"complete"`
}

type GrepInput

type GrepInput struct {
	// Pattern is a required search expression. Internally it may be split on
	// simple OR separators ("|" or " or ") into multiple patterns which are
	// combined using logical OR.
	Pattern string `json:"pattern" description:"search pattern; supports OR via '|' or textual 'or' (case-insensitive)"`
	// ExcludePattern optionally defines patterns that, when matched, cause a
	// file or snippet to be excluded. It follows the same splitting rules as
	// Pattern.
	ExcludePattern string `json:"excludePattern,omitempty" description:"exclude pattern; same OR semantics as pattern"`

	// RootURI is the normalized or user-provided root URI. Prefer using
	// RootID when possible; RootURI is retained for backward compatibility.
	RootURI string `json:"root,omitempty"`
	// RootID is a stable identifier corresponding to a root returned by
	// roots. When provided, it is resolved to the underlying
	// normalized URI before enforcement and grep operations.
	RootID    string   `json:"rootId,omitempty"`
	Path      string   `json:"path"`
	Recursive bool     `json:"recursive,omitempty"`
	Include   []string `` /* 143-byte string literal not displayed */
	Exclude   []string `json:"exclude,omitempty" description:"optional file/path globs to exclude; supports ** for any depth"`

	CaseInsensitive bool `json:"caseInsensitive,omitempty"`

	Mode      string `` /* 159-byte string literal not displayed */
	Bytes     int    `json:"bytes,omitempty"`
	Lines     int    `json:"lines,omitempty"`
	MaxFiles  int    `json:"maxFiles,omitempty"`
	MaxBlocks int    `json:"maxBlocks,omitempty"`

	SkipBinary  bool `json:"skipBinary,omitempty"`
	MaxSize     int  `json:"maxSize,omitempty"`
	Concurrency int  `json:"concurrency,omitempty"`
}

type GrepOutput

type GrepOutput struct {
	Stats textutil.GrepStats  `json:"stats"`
	Files []textutil.GrepFile `json:"files,omitempty"`
}

type InspectInput added in v0.1.39

type InspectInput struct {
	URI             string             `json:"uri,omitempty"`
	Path            string             `json:"path,omitempty"`
	RootID          string             `json:"rootId,omitempty"`
	Select          *ResourceSelection `json:"select,omitempty"`
	Cursor          string             `json:"cursor,omitempty"`
	Limit           int                `json:"limit,omitempty"`
	ExpectedVersion string             `json:"expectedVersion,omitempty"`
}

type InspectOutput added in v0.1.39

type InspectOutput struct {
	ColumnsInferred               bool                `json:"columnsInferred,omitempty"`
	NativeRequiresProviderSupport bool                `json:"nativeRequiresProviderSupport,omitempty"`
	URI                           string              `json:"uri"`
	Name                          string              `json:"name"`
	MimeType                      string              `json:"mimeType"`
	Kind                          string              `json:"kind"`
	SizeBytes                     int                 `json:"sizeBytes"`
	Version                       string              `json:"version"`
	Components                    []ResourceComponent `json:"components,omitempty"`
	Columns                       []string            `json:"columns,omitempty"`
	PageCount                     int                 `json:"pageCount,omitempty"`
	Width                         int                 `json:"width,omitempty"`
	Height                        int                 `json:"height,omitempty"`
	Capabilities                  map[string][]string `json:"capabilities"`
	Complete                      bool                `json:"complete"`
	NextCursor                    string              `json:"nextCursor,omitempty"`
}

type ListInput

type ListInput struct {
	URI    string `json:"uri,omitempty"`
	Scope  string `json:"scope,omitempty" description:"artifacts lists user-owned uploaded/generated resources without a root"`
	Cursor string `json:"cursor,omitempty"`
	// RootURI is the normalized or user-provided root URI. Prefer using
	// RootID when possible; RootURI is retained for backward compatibility
	// but hidden from public schemas.
	RootURI string `json:"root,omitempty" internal:"true" description:"normalized or user-provided root URI; prefer rootId when available"`
	// RootID is a stable identifier corresponding to a root returned by
	// roots. When provided, it is resolved to the underlying
	// normalized URI before enforcement and listing.
	RootID string `json:"rootId,omitempty" description:"resource root id returned by roots"`
	// Path is an optional subpath under the selected root. When empty, the
	// root itself is listed. Paths may be relative to the root or
	// absolute-like; absolute-like paths must remain under the root.
	Path string `json:"path,omitempty" description:"optional subpath under the root to list"`
	// Recursive controls whether the listing should walk the subtree under
	// Path. When false, only immediate children are returned.
	Recursive bool `json:"recursive,omitempty" description:"when true, walk recursively under path"`
	// Include defines optional file or path globs to include. When provided,
	// only items whose relative path or base name matches at least one
	// pattern are returned. Globs use path-style matching rules and support
	// globstar ("**") to match any directory depth.
	Include []string `json:"include,omitempty" description:"optional file/path globs to include (relative to root+path); supports ** for any depth"`
	// Exclude defines optional file or path globs to exclude. When provided,
	// any item whose relative path or base name matches a pattern is
	// filtered out.
	Exclude []string `json:"exclude,omitempty" description:"optional file/path globs to exclude; supports ** for any depth"`
	// MaxItems caps the number of items returned. When zero or negative, no
	// explicit limit is applied.
	MaxItems int `json:"maxItems,omitempty" description:"maximum number of items to return; 0 means no limit"`
	// contains filtered or unexported fields
}

type ListItem

type ListItem struct {
	MimeType string    `json:"mimeType,omitempty"`
	URI      string    `json:"uri"`
	Path     string    `json:"path"`
	Name     string    `json:"name"`
	Size     int64     `json:"size"`
	Modified time.Time `json:"modified"`
	RootID   string    `json:"rootId,omitempty"`
}

type ListOutput

type ListOutput struct {
	NextCursor string     `json:"nextCursor,omitempty"`
	Items      []ListItem `json:"items"`
	Total      int        `json:"total"`
}

type MatchDocumentsInput

type MatchDocumentsInput struct {
	Query        string          `json:"query" description:"semantic search query" required:"true"`
	RootIDs      []string        `json:"rootIds,omitempty" description:"resource root ids returned by roots"`
	Path         string          `json:"path,omitempty" description:"optional subpath relative to selected roots"`
	Model        string          `json:"model,omitempty" internal:"true"`
	MaxDocuments int             `json:"maxDocuments,omitempty" description:"maximum number of matched documents (distinct URIs); defaults to 5"`
	Match        *embopt.Options `json:"match,omitempty" internal:"true"`
	Exclude      []string        `json:"exclude,omitempty" description:"optional file/path globs to exclude from match results; supports ** for any depth"`
}

type MatchDocumentsOutput

type MatchDocumentsOutput struct {
	Documents []MatchedDocument `json:"documents"`
}

type MatchInput

type MatchInput struct {
	Query string `json:"query"`
	// RootURI/Roots are retained for backward compatibility but will default to all accessible roots when omitted.
	RootURI []string `json:"rootUri,omitempty" internal:"true"`
	Roots   []string `json:"roots,omitempty" internal:"true"`
	// RootIDs contains stable identifiers corresponding to roots returned by
	// roots. When provided, they are resolved to URIs before
	// enforcement and search.
	RootIDs                 []string        `json:"rootIds,omitempty" description:"resource root ids returned by roots"`
	Path                    string          `json:"path,omitempty"`
	Model                   string          `json:"model" internal:"true"`
	MaxDocuments            int             `json:"maxDocuments,omitempty" `
	NeighborFragmentsBefore int             `json:"neighborFragmentsBefore,omitempty" description:"Adjacent indexed fragments to include before each semantic hit."`
	NeighborFragmentsAfter  int             `json:"neighborFragmentsAfter,omitempty" description:"Adjacent indexed fragments to include after each semantic hit."`
	IncludeFile             bool            `json:"includeFile,omitempty" internal:"true"`
	Match                   *embopt.Options `json:"match,omitempty"`
	Exclude                 []string        `json:"exclude,omitempty" description:"optional file/path globs to exclude from match results; supports ** for any depth"`
	// LimitBytes controls the maximum total bytes of matched content returned for the current cursor page.
	LimitBytes int `json:"limitBytes,omitempty" description:"Max total bytes per page of matched content. Default: 7000."`
	// Cursor selects the page (1..N) over the ranked documents, grouped by LimitBytes.
	Cursor int `json:"cursor,omitempty" description:"Result page selector (1..N). Default: 1."`
}

MatchInput defines parameters for semantic search across one or more roots.

type MatchOutput

type MatchOutput struct {
	aug.AugmentDocsOutput
	// NextCursor points to the next page (cursor+1) when more content is available; 0 means no further pages.
	NextCursor int `json:"nextCursor,omitempty" description:"Next page cursor when available; 0 when none."`
	// Cursor echoes the selected page.
	Cursor int `json:"cursor,omitempty" description:"Selected page cursor (1..N)."`
	// LimitBytes echoes the applied byte limit per page.
	LimitBytes int `json:"limitBytes,omitempty" description:"Applied byte cap per page."`
	// SystemContent mirrors Content but only includes system-role documents so callers can surface
	// protected context as system messages.
	SystemContent string `json:"systemContent,omitempty" description:"Formatted content for system resources only."`
	// DocumentRoots maps document SourceURI values to their originating root IDs.
	DocumentRoots map[string]string `json:"documentRoots,omitempty" description:"Maps document source URIs to their root IDs."`
}

MatchOutput mirrors augmenter.AugmentDocsOutput for convenience.

type MatchedDocument

type MatchedDocument struct {
	URI    string  `json:"uri"`
	RootID string  `json:"rootId,omitempty"`
	Score  float32 `json:"score"`
}

type NativeResource added in v0.1.39

type NativeResource struct {
	URI      string `json:"uri"`
	Name     string `json:"name"`
	MimeType string `json:"mimeType"`
	SHA256   string `json:"sha256"`
}

NativeResource is an internal presentation request emitted only by resources:read. The executor opens this immutable snapshot; the model sees no binary payload.

type ReadImageInput

type ReadImageInput struct {
	// URI is an absolute URI; when provided, RootURI/RootID/Path are ignored.
	URI string `json:"uri,omitempty"`
	// RootURI/RootID + Path select an image under a root.
	RootURI string `json:"root,omitempty"`
	RootID  string `json:"rootId,omitempty"`
	Path    string `json:"path,omitempty"`

	// MaxWidth/MaxHeight define a resize-to-fit box; default 2048x768.
	MaxWidth  int `json:"maxWidth,omitempty"`
	MaxHeight int `json:"maxHeight,omitempty"`
	// MaxBytes caps the encoded output bytes; default 4MB.
	MaxBytes int `json:"maxBytes,omitempty"`

	// Format optionally forces output encoding: "png" or "jpeg".
	Format string `json:"format,omitempty"`

	// IncludeData controls whether dataBase64 is returned in the tool response.
	// When false (default), the tool writes the encoded image to EncodedURI and
	// omits dataBase64 to keep tool output small.
	IncludeData bool `json:"includeData,omitempty"`
	// DestURL optionally specifies where to write the encoded image (file://...).
	DestURL string `json:"destURL,omitempty"`
}

type ReadImageOutput

type ReadImageOutput struct {
	URI      string `json:"uri"`
	Encoded  string `json:"encodedURI,omitempty"`
	Path     string `json:"path"`
	Name     string `json:"name,omitempty"`
	MimeType string `json:"mimeType"`
	Width    int    `json:"width"`
	Height   int    `json:"height"`
	Bytes    int    `json:"bytes"`
	Base64   string `json:"dataBase64,omitempty"`
}

type ReadInput

type ReadInput struct {
	Representation  string             `json:"representation,omitempty"`
	Select          *ResourceSelection `json:"select,omitempty"`
	Options         *ResourceOptions   `json:"options,omitempty"`
	Limits          *ResourceLimits    `json:"limits,omitempty"`
	ExpectedVersion string             `json:"expectedVersion,omitempty"`
	Cursor          string             `json:"cursor,omitempty"`
	// RootURI is the normalized or user-provided root URI. Prefer using
	// RootID when possible; RootURI is retained for backward compatibility
	// but hidden from public schemas.
	RootURI string `json:"root,omitempty" internal:"true"`
	// RootID is a stable identifier corresponding to a root returned by
	// roots. When provided (and URI is empty), it is resolved to
	// the underlying normalized URI before enforcement and reading.
	RootID string `json:"rootId,omitempty"`
	Path   string `json:"path,omitempty"`
	URI    string `json:"uri,omitempty"`

	// Range selectors; nested objects accepted by JSON schema
	BytesRange textutil.BytesRange `json:"bytesRange,omitempty"`
	textutil.LineRange

	// MaxBytes caps the returned payload when neither byte nor line ranges are provided.
	// When zero, defaults are applied.
	MaxBytes int `json:"maxBytes,omitempty"`

	// Mode provides lightweight previews without full reads:
	// head (default), tail, signatures.
	Mode string `json:"mode,omitempty"`
}

type ReadOutput

type ReadOutput struct {
	Warnings  []string          `json:"warnings,omitempty"`
	Version   string            `json:"version,omitempty"`
	Table     *ResourceTable    `json:"table,omitempty"`
	Native    *NativeResource   `json:"native,omitempty"`
	Coverage  *ResourceCoverage `json:"coverage,omitempty"`
	Cursor    string            `json:"cursor,omitempty"`
	URI       string            `json:"uri"`
	Path      string            `json:"path"`
	Content   string            `json:"content"`
	SkillName string            `json:"skillName,omitempty"`
	Size      int               `json:"size"`
	// Returned and Remaining describe how much of the original payload was
	// returned after applying caps/ranges.
	Returned  int `json:"returned,omitempty"`
	Remaining int `json:"remaining,omitempty"`
	// StartLine and EndLine are 1-based line numbers describing the selected
	// slice when Offset/Limit were provided. They are zero when the entire
	// (possibly MaxBytes-truncated) file content is returned.
	StartLine int `json:"startLine,omitempty"`
	EndLine   int `json:"endLine,omitempty"`
	// Binary is true when the content was detected as binary and not fully returned.
	Binary bool `json:"binary,omitempty"`
	// ModeApplied echoes the preview mode applied.
	ModeApplied string `json:"modeApplied,omitempty"`
	// Continuation carries paging/truncation hints when content was clipped.
	Continuation *extension.Continuation `json:"continuation,omitempty"`
	// Observation records the full resource hash used by patch tools to enforce read-before-modify.
	Observation *observation.Metadata `json:"observation,omitempty"`
}

ReadOutput contains the resolved URI, relative path and optionally truncated content.

type ResourceComponent added in v0.1.39

type ResourceComponent struct {
	UsedRangeEstimated bool   `json:"usedRangeEstimated,omitempty"`
	ID                 string `json:"id"`
	Kind               string `json:"kind"`
	Name               string `json:"name"`
	UsedRange          string `json:"usedRange,omitempty"`
}

type ResourceCoverage added in v0.1.39

type ResourceCoverage struct {
	Selection    *ResourceSelection `json:"selection,omitempty"`
	ReturnedRows int                `json:"returnedRows,omitempty"`
	Truncated    bool               `json:"truncated"`
	NextRow      int                `json:"nextRow,omitempty"`
}

type ResourceLimits added in v0.1.39

type ResourceLimits struct {
	MaxRows        int `json:"maxRows,omitempty"`
	MaxOutputBytes int `json:"maxOutputBytes,omitempty"`
}

type ResourceOptions added in v0.1.39

type ResourceOptions struct {
	Values    string `json:"values,omitempty"`
	HeaderRow int    `json:"headerRow,omitempty"`
	Encoding  string `json:"encoding,omitempty"`
	Delimiter string `json:"delimiter,omitempty"`
	OCR       string `json:"ocr,omitempty"`
}

type ResourceSelection added in v0.1.39

type ResourceSelection struct {
	ComponentID string `json:"componentId,omitempty"`
	Sheet       string `json:"sheet,omitempty"`
	Range       string `json:"range,omitempty"`
	Pages       []int  `json:"pages,omitempty"`
}

type ResourceTable added in v0.1.39

type ResourceTable struct {
	Sheet       string     `json:"sheet,omitempty"`
	Rows        [][]string `json:"rows"`
	RowNumbers  []int      `json:"rowNumbers"`
	StartColumn int        `json:"startColumn"`
	HeaderRow   int        `json:"headerRow,omitempty"`
}

type ResourcesDefaults

type ResourcesDefaults struct {
	Locations    []string
	TrimPath     string
	SummaryFiles []string
	DescribeMCP  bool
	SnapshotPath string
}

type Root

type Root struct {
	// ID is a stable identifier for this root when available. When the
	// underlying agent resource entry defines an explicit id, it is surfaced
	// here. Otherwise, the normalized URI is used as a fallback id so callers
	// can still use rootId as an alias for the URI.
	ID string `json:"id"`

	URI         string `json:"uri"`
	Description string `json:"description,omitempty"`
	// UpstreamRef is an internal-only reference used to resolve local upstream sync.
	UpstreamRef string `json:"-"`
	// DB is an optional embedius sqlite database path override for this root.
	DB string `json:"-"`
	// Match carries per-root match options (include/exclude/max file size).
	Match *embopt.Options `json:"match,omitempty"`
	// Metadata carries generic indexed document metadata extraction settings.
	Metadata metadata.Config `json:"-"`
	// AllowedSemanticSearch reports whether semantic match (match)
	// is permitted for this root in the current agent configuration.
	AllowedSemanticSearch bool `json:"allowedSemanticSearch"`
	// AllowedGrepSearch reports whether lexical grep (grepFiles)
	// is permitted for this root in the current agent configuration.
	AllowedGrepSearch bool   `json:"allowedGrepSearch"`
	Role              string `json:"role,omitempty"`
}

type RootsInput

type RootsInput struct {
	MaxRoots int `json:"maxRoots,omitempty"`
}

type RootsOutput

type RootsOutput struct {
	Roots []Root `json:"roots"`
}

type Service

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

Service exposes resource roots, listing, reading and semantic match over filesystem and MCP

func New

func New(augmenter *aug.Service, opts ...func(*Service)) *Service

New returns a resources service using a shared augmenter instance.

func (*Service) CacheableMethods added in v0.1.7

func (s *Service) CacheableMethods() map[string]bool

CacheableMethods declares which methods produce cacheable outputs.

func (*Service) Method

func (s *Service) Method(name string) (svc.Executable, error)

Method resolves an executable method by name

func (*Service) Methods

func (s *Service) Methods() svc.Signatures

Methods declares available tool methods

func (*Service) Name

func (s *Service) Name() string

Name returns service name

func (*Service) ToolTimeout

func (s *Service) ToolTimeout() time.Duration

ToolTimeout suggests a longer timeout for resources tools that may index large roots.

Jump to

Keyboard shortcuts

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