files

package
v2.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package files serves the text contents of Mattermost file attachments to the LLM on demand. It exists because the server-extracted text (FileInfo.Content, used for PDFs and Office documents) is tagged json:"-" and is never returned over the REST API, so the MCP server's user-scoped client cannot read it. This service reaches that content through the admin plugin API and therefore must enforce the requesting session's file-download policy and the user's channel permissions itself.

Index

Constants

View Source
const (
	// DefaultReadRunes is the window size returned when a caller omits a limit.
	DefaultReadRunes = 6000
	// MaxReadRunes caps a single read so one tool call cannot re-blow the
	// context window the lazy-loading design is meant to protect.
	MaxReadRunes = 20000
)

Variables

View Source
var ErrForbidden = errors.New("you do not have permission to access this file")

ErrForbidden is returned when the requesting session is denied the file or the user lacks permission to read the file's channel. Callers map it to a 403 / access-denied tool result.

Functions

This section is empty.

Types

type Content

type Content struct {
	Name       string
	MimeType   string
	TotalRunes int
	Offset     int
	Returned   int
	HasMore    bool
	HasText    bool // false means the file has no extractable text (e.g. a binary with no server-side extraction)
	Text       string
}

Content is a ranged slice of a file's text plus the metadata needed to page through the rest of it. Offsets are measured in runes, not bytes, so a multi-byte character is never split across reads.

func Slice

func Slice(name, mimeType, text string, offset, limit int) Content

Slice returns the [offset, offset+limit) rune window of text as a Content, applying the default and maximum read sizes. Offsets are measured in runes so a multibyte character is never split, and they are clamped into range.

type Service

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

Service is the shared plugin-side file reader behind both the embedded read_file tool and the /files/content HTTP endpoint.

func New

func New(mm mmapi.Client) *Service

New creates a file content service backed by the given Mattermost client.

func (*Service) GetContent

func (s *Service) GetContent(ctx context.Context, userID, fileID string, offset, limit int) (Content, error)

GetContent returns the [offset, offset+limit) rune window of a file's text for userID, after verifying the requesting session's file policy and the user's channel permission. Documents use the server-extracted text; plain text files fall back to the raw bytes.

Jump to

Keyboard shortcuts

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