pluginapi

package
v0.1.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 17 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 pluginapi is the versioned, platform-neutral contract for built-in plugins. Sessions must honor context cancellation and must not leave goroutines behind.

Index

Constants

View Source
const APIVersion = 1

Variables

View Source
var ErrInvalid = errors.New("invalid content")
View Source
var ErrUnsupported = errors.New("unsupported capability")

Functions

func RedactingLogger

func RedactingLogger(base *slog.Logger, creds Credentials) *slog.Logger

RedactingLogger removes this workspace's resolved credential values from both messages and structured attributes, including nested groups and error values.

func Register

func Register(p Plugin)

func ValidateManifest

func ValidateManifest(m Manifest) error

func ValidateSchema

func ValidateSchema(raw json.RawMessage) error

ValidateSchema accepts only the form-rendering subset; parsing remains authoritative.

Types

type ArchiveManifest

type ArchiveManifest struct {
	// CleanupProof links this generation to the journal whose receipts it folded.
	CleanupProof string            `json:"cleanup_proof,omitempty"`
	Schema       int               `json:"schema"`
	Platform     string            `json:"platform,omitempty"`
	TeamID       string            `json:"team_id"`
	Channel      string            `json:"channel"`
	RootTS       string            `json:"root_ts"`
	Permalink    string            `json:"permalink"`
	MessageCount int               `json:"message_count"`
	Objects      map[string]Object `json:"objects"`
	Files        []Attachment      `json:"files"`
}

type Attachment

type Attachment struct {
	ID     string `json:"id"`
	Path   string `json:"path"`
	Name   string `json:"name"`
	Size   int64  `json:"size"`
	SHA256 string `json:"sha256"`
	URL    string `json:"url"`
}

type Blob

type Blob struct {
	Size   int64
	SHA256 string
	Data   []byte
	Source *FileSource
}

Blob carries inline bytes or a confined, verified local file reference. Both forms are plain serializable data; a future RPC adapter can stream refs.

func (Blob) Open

func (b Blob) Open() (io.ReadCloser, error)

Open rechecks size and digest on every use; the caller owns the returned handle. File references are opened through os.Root and all symlink components are refused.

type Capabilities

type Capabilities struct{ ReadHistory, Realtime, Delete bool }

type Channel

type Channel struct{ ID, Name string }

type ChannelInspector

type ChannelInspector interface {
	InspectChannels(context.Context, []string) ([]ChannelStatus, error)
}

ChannelInspector is an optional Session extension used by diagnostics.

type ChannelStatus

type ChannelStatus struct {
	ID, Name string
	Member   bool
	Problem  string
}

ChannelStatus reports whether the connected account can read a channel.

type Check

type Check struct {
	Label, Detail string
	OK            bool
	Optional      bool
}

Check is one line of a connection test result.

type Choice

type Choice struct {
	ID, Label           string
	Glyph, Image, Group string
	Keywords            string
}

Choice is a selectable option. Glyph, Image and Group are optional display hints (for example an emoji character, a custom image URL and a picker category).

type CleanupBoundary

type CleanupBoundary interface {
	CleanupBoundary(Workspace, ArchiveManifest) string
}

CleanupBoundary validates source-specific workspace identity offline.

type CleanupError

type CleanupError struct{ Status, Reason string }

CleanupStatus classifies safe mutation failures without leaking transport details.

func (*CleanupError) Error

func (e *CleanupError) Error() string

type CleanupOffline

type CleanupOffline interface {
	CleanupReason(Workspace, Message) string
}

CleanupOffline checks platform policy without credentials or network access.

type CleanupPolicy

type CleanupPolicy struct {
	Enabled     bool
	AllowOthers bool
	OwnOnly     bool
	MinAge      time.Duration
	TokenEnv    string
}

type ContentHooks

type ContentHooks interface {
	Validate(context.Context, Snapshot) error
	Text(context.Context, Message, map[string]Message) (string, error)
	Author(context.Context, Message) (string, error)
}

type Credentials

type Credentials map[string]string

func (Credentials) Format

func (Credentials) Format(s fmt.State, _ rune)

func (Credentials) LogValue

func (Credentials) LogValue() slog.Value

func (Credentials) MarshalJSON

func (Credentials) MarshalJSON() ([]byte, error)

type Env

type Env struct {
	Credentials Credentials
	Log         *slog.Logger
	HTTP        *http.Client
	StateDir    string
	Now         func() time.Time
}

type Event

type Event struct{ Channel, RootTS, Kind, ItemTS string }

Event is a capture hint. ItemTS, when set and different from RootTS, names the message inside the thread that a reaction event was about (a reply); the runtime re-reads it through ItemReader before it may authorize an archive.

type EventSink

type EventSink func(Event) bool

type FileSource

type FileSource struct{ Root, Path string }

type Identity

type Identity struct{ TeamID, UserID string }

type ItemReader

type ItemReader interface {
	Item(ctx context.Context, channel, rootTS, ts string) (Root, error)
}

ItemReader is an optional Session extension for realtime reply reactions: it re-reads the reactions on one message of a thread and must verify that the message belongs to rootTS. It returns a zero Root when the message is gone.

type Key

type Key struct{ Channel, RootTS string }
type Link struct{ Label, URL string }

type Manifest

type Manifest struct {
	ID, Name, Version string
	APIVersion        int
	Capabilities      Capabilities
	ClaimsLegacy      bool

	DefaultReactions []string
}

type Message

type Message map[string]any

type Object

type Object struct {
	Size   int64  `json:"size"`
	SHA256 string `json:"sha256"`
}

type Plugin

type Plugin interface {
	Manifest() Manifest
	ConfigSchema() json.RawMessage
	CredentialSchema() json.RawMessage
	ParseWorkspace(context.Context, json.RawMessage, Credentials) (Settings, error)
	ValidateWorkspaces(context.Context, []Settings) error
	SetupFlow() []SetupStep
	NewSession(context.Context, Workspace, Env) (Session, error)
	NewCleanupDriver(context.Context, Workspace, Env) (CleanupDriver, error)
	Content() ContentHooks
}

func Legacy

func Legacy() (Plugin, bool)

func Lookup

func Lookup(id string) (Plugin, bool)

func Plugins

func Plugins() []Plugin

type Reaction

type Reaction struct {
	Name  string
	Users []string
	Count int
}

type ReactionRenderer

type ReactionRenderer interface {
	Reactions(context.Context, Message) ([]ReactionView, error)
}

ReactionRenderer is an optional ContentHooks extension for viewers.

type ReactionView

type ReactionView struct {
	Name, Glyph, Image string
	// MatchNames are trigger names that match this reaction, supplied by the platform.
	MatchNames []string
	Count      int
}

ReactionView describes a stored reaction for display.

type RealtimeReporter

type RealtimeReporter interface {
	RealtimeStatus() (connected bool, detail string)
}

RealtimeReporter is an optional Session extension describing the live event connection. Detail is a short user-facing explanation.

type ReplyInspector

type ReplyInspector interface {
	ReplyReactions(context.Context, []RootRef, []string) ([]ReplyReaction, error)
}

ReplyInspector is an optional Session extension: it lists reactions placed on replies of the given roots so diagnostics can explain why they never match.

type ReplyReaction

type ReplyReaction struct {
	Channel, RootTS, TS, Name string
}

ReplyReaction is a reaction on a non-root message, reported by diagnostics only.

type Root

type Root struct {
	TS, ThreadTS string
	Reactions    []Reaction
	Raw          Message
}

type RootRef

type RootRef struct {
	Channel, RootTS string
	Reactions       []Reaction
	Replies         int
}

type Session

type Session interface {
	Capabilities() Capabilities
	VerifyIdentity(context.Context) (Identity, error)
	Channels(context.Context) ([]Channel, error)
	History(context.Context, string, string) ([]RootRef, error)
	Root(context.Context, string, string) (Root, error)
	Snapshot(context.Context, string, Root, *Snapshot) (Snapshot, error)
	Start(context.Context, EventSink) error
	Stop(context.Context) error
	Reconfigure(context.Context, Workspace) (bool, error)
}

type Settings

type Settings json.RawMessage

type SetupState

type SetupState map[string]json.RawMessage

type SetupStep

type SetupStep struct {
	ID, Title, Kind, Body string
	Links                 []Link
	Schema                json.RawMessage
	Run                   func(context.Context, SetupState, json.RawMessage, Env) (StepResult, error)
	Prepare               func(context.Context, SetupState, Env) (StepResult, error)
	Test                  func(context.Context, SetupState, json.RawMessage, Env) (StepResult, error)
	Skip, SkipNote        string
}

SetupStep is one wizard page. Run validates a submission. Optional hooks: Prepare runs when the page is shown (dynamic links, choices); Test runs the "Test connection" action without advancing. Skip, when set, labels an explicit fallback action that clears this step's secret fields and then calls Run.

type Snapshot

type Snapshot struct {
	// CleanupStatus summarizes the journal state for archive readers.
	CleanupStatus string `json:"cleanup_status,omitempty"`
	// SourceDeletedAt projects verified journal and persisted deletion markers.
	SourceDeletedAt map[string]string `json:"source_deleted_at,omitempty"`
	Manifest        ArchiveManifest
	Messages        []Message
	Users           map[string]Message
	// RawUsers retains optional malformed non-author metadata without rendering it.
	RawUsers  map[string]any
	Blobs     map[string]Blob
	Documents map[string][]byte
}

type StepResult

type StepResult struct {
	OK          bool
	FieldErrors map[string]string
	Messages    []string
	Data        json.RawMessage
	Choices     []Choice
	// Links and Checks are optional: Prepare may compute links from earlier
	// steps, and Test/Run may report itemized connection results.
	Links  []Link
	Checks []Check
}

type Trigger

type Trigger struct {
	Reactions []string `json:"reactions" yaml:"reactions"`
	Who       string   `json:"who" yaml:"who"`
	Owners    []string `json:"owners" yaml:"owners"`
	Match     string   `json:"match,omitempty" yaml:"match,omitempty"`
}

Trigger selects roots to archive. Match "all" (the default, kept for legacy configurations) requires every listed reaction; "any" requires at least one.

type Workspace

type Workspace struct {
	Cleanup               CleanupPolicy
	ID, Platform, Storage string
	Channels              []string
	AutoChannels          bool
	Trigger               Trigger
	PollInterval          time.Duration
	Settings              Settings
}

Directories

Path Synopsis
Package plugintest checks contract-v1 manifests, schemas and lifecycle behavior.
Package plugintest checks contract-v1 manifests, schemas and lifecycle behavior.

Jump to

Keyboard shortcuts

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