panel

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0 modules, 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 panel is what an agent may ask of the right pane of its own tab and what the pane answers: the command parser, the cleaning of a page's answer, and the bridge that carries a command to the person's page over the sync socket and the answer back to the agent that waits for it.

Index

Constants

View Source
const (
	MaxArg     = 512
	MaxMessage = 400
)
View Source
const (
	ReasonConnect = "connect"
	ReasonEmbed   = "embed"
	ReasonAccount = "account"
)

The reasons a Link opens in no tab.

Variables

View Source
var TabKinds = Kinds()

TabKinds are Kinds, for the callers that range over them.

Functions

func CleanState

func CleanState(v any) *jsvalue.Object

CleanState keeps only a well-formed pane state.

func ConnTarget

func ConnTarget(conn, kind, key string) string

ConnTarget is the target of the task tab for an issue ("issue") or a page ("page") of a connection: the connection's id and the key exactly as the provider writes it, never derived from an address.

func IsTabKind

func IsTabKind(v any) bool

IsTabKind says whether v names a kind of the registry.

func Kinds added in v0.16.86

func Kinds() []string

Kinds are the kinds of tab the pane can hold, in the order the pane lists them.

func ParseConnTarget

func ParseConnTarget(target string) (conn, kind, key string, ok bool)

ParseConnTarget is ConnTarget's inverse; ok is false for a target that names no connection.

func RateDecision

func RateDecision(stamps []int64, now int64, limit int, windowMs int64) (bool, []int64)

RateDecision is a sliding window over the times of the commands let through; a refused one is not counted.

func UUID

func UUID() string

UUID is a random version-4 UUID in lowercase.

Types

type Bridge

type Bridge struct {
	// Publish sends an event to every page; Subscribers counts the pages (and relays) connected.
	Publish     func(event *jsvalue.Object)
	Subscribers func() int
	Now         func() time.Time
	// contains filtered or unexported fields
}

Bridge holds the commands waiting for an answer and each tab's recent commands.

func NewBridge

func NewBridge(publish func(*jsvalue.Object), subscribers func() int) *Bridge

NewBridge is a bridge publishing through publish.

func (*Bridge) Answer

func (b *Bridge) Answer(id string, r Result) bool

Answer settles a command with the first answer; false for a later one or an id never issued.

func (*Bridge) Dispatch

func (b *Bridge) Dispatch(tabID string, cmd Command, timeout time.Duration) Outcome

Dispatch asks the page that shows the tab right now and waits for its answer; timeout 0 is the default 8 s.

func (*Bridge) RateAllowed

func (b *Bridge) RateAllowed(tabID string) bool

RateAllowed counts a command of the tab against its limit (12 a minute); a refused one is not counted.

type Command

type Command struct {
	Kind   string // open, show, hide, status
	Tab    string
	Target string // "" for none
	// Auto: the runtime asked, seeing what the agent works on, not the agent; the person may switch these off.
	Auto bool
	// Reload: the thing changed, a tab that shows it reloads; nothing opens for it.
	Reload bool
	// Place: where in the file to show (a range of cells, a time, a page); "" for none.
	Place string
}

func (Command) JSON

func (c Command) JSON() *jsvalue.Object

JSON is the command as the sync socket carries it.

type Link struct {
	Tab, Target, Reason string
	Choices             []LinkChoice // Exact native task targets, only when Reason is ReasonAccount.
}

Link is where one address opens. Tab "link" is an address that opens in no tab of the pane: Reason says why (ReasonConnect: the connection that reads it has no working sign-in; ReasonEmbed: its service cannot be framed) and Target is the address itself, which the person may open by choice, never in the remote browser by itself.

type LinkChoice

type LinkChoice struct {
	Target, Label, Detail string
}

type Outcome

type Outcome struct {
	Kind   string
	Result Result
}

Outcome is how a command ended: answered (with Result), no-ui, timeout, busy or rate-limited.

type Result

type Result struct {
	OK      bool
	Message string
	State   *jsvalue.Object // {visible, open, active}; nil when the page sent none
}

Result is a page's answer to a command, shape-checked, cleaned and clipped: the browser is not trusted.

func ParseResult

func ParseResult(input any) *Result

ParseResult reads a page's answer; nil when the body is not one.

type Targets

type Targets struct {
	// StandDomain is the domain of the feature stands (".preview.example.org"); "" opens none.
	StandDomain string
	// PortalHost publishes documents (/a/<slug>) and boards (/b/<slug>); ReaderHost is the platform, whose reader
	// shows a document at ReaderPath<slug>.
	PortalHost, ReaderHost string
	// ArtifactsHost and BoardsHost are the hosts of a deployment that serves documents (/a/<slug>) and boards (/b/<slug>)
	// from separate servers; PortalHost is the one host that serves both.
	ArtifactsHost, BoardsHost string
	ReaderPath                string
	// GitLabHosts are the GitLab servers whose merge requests and commits a tab shows; the first is named in hints.
	GitLabHosts []string
	// GitHubHost is the GitHub whose pull requests, commits and issues the same tab shows ("" is github.com).
	GitHubHost string
	// TaskKey matches a key of the tracker; TaskExamples are named in the hint.
	TaskKey      *regexp.Regexp
	TaskExamples string
	// TrackerHosts are the tracker's servers: the page of a task there opens the task tab, as its key does.
	TrackerHosts []string
	// DesignRef is the id of the machine's design that a text names (its id, its folder or a file in it, its title),
	// "" for none; nil: the machine has no design library and "open design" takes no target.
	DesignRef func(text string) string
	// DesignBoard is the design of the machine's library an absolute path lies in and the board of it the path is (a
	// page under the design's project/, as its viewer names it; "" for the design's other files), ("", "") outside the
	// library; nil: no library. A file of a design opens in the design's tab, never as a file.
	DesignBoard func(path string) (design, board string)
	// AppRef is the canonical "<app id>[/<view>]" of an installed app's pane view that a text names, "" for none; nil:
	// the machine has no apps and "open app" takes no target.
	AppRef func(text string) string
	// AppWhyNot says why an installed app the text names opens no pane view when it is the app's state (it waits for
	// the person's consent, it is turned off), "" otherwise; nil says nothing more than the hint.
	AppWhyNot func(text string) string
	// Resolve asks what the deployment's connections (an issue tracker, a wiki) and its documents provider make of an
	// address, before any generic site: a zero Link is "none of mine". nil: nothing is asked.
	Resolve func(ctx context.Context, text string) Link
}

Targets are the deployment's addresses a command may point a tab at.

func (Targets) Classify added in v0.15.40

func (t Targets) Classify(text string) (tab, target string)

The kinds of addresses (docs/pane-opening.md), each by its exact pattern:

document       https://<PortalHost|ArtifactsHost>/a/<slug>, https://<ReaderHost><ReaderPath><slug>  artifacts
board          https://<PortalHost|BoardsHost>/b/<slug>[?k=<key>]                                   artifacts
stand          https://<one label><StandDomain>/…, no port; ai-… and auth are not stands            browser
dev server     http(s)://localhost:<port> (127.0.0.1, 0.0.0.0), a bare port                          browser
MR, commit     https://<GitLabHosts>/<project>/-/merge_requests/<n>, /-/commit/<sha>; GitHub's        gitlab
task           a TaskKey (PROJ-12), https://<TrackerHosts>/issue/<key>                              task

A document is never the browser: a page of the portal or the platform that is none of these is a plain site.

Classify is the tab a link or a name the agent wrote opens in, by the rules of open: a tracker key is the task tab, a GitLab merge request or commit or a GitHub pull request, commit or issue the gitlab tab, a document or a board of the portal the artifacts tab, and any other http(s) address the browser. "" for what opens nothing. The chat's chips and the pane's links ask it, so the pane has one set of rules for the agent's open command and for what the person clicks.

func (t Targets) ClassifyLink(ctx context.Context, text string) Link

ClassifyLink is Classify with the reason an address opens in no tab (Tab "link"). The connections and the documents provider are asked after the fixed rules and before the generic site, so an address one of them reads never reaches the browser.

func (Targets) DesignOf

func (t Targets) DesignOf(p string) (Command, bool)

DesignOf is the command that opens the file at an absolute path where it belongs when it is a design's: the design's tab, on its board (Place) when the path is one. ok is false for a path outside the library: an agent that opens `<library>/<id>/project/Board.dc.html` as a file gets the design, not its source.

func (Targets) DocTarget

func (t Targets) DocTarget(slug string) string

DocTarget is the target of the artifacts tab for a document or a board of the provider, by its local name.

func (Targets) Parse

func (t Targets) Parse(input any) (Command, string)

Parse reduces a request body to a command the pane knows; the error is the text the agent reads. Unknown keys, kinds and values are refused, never passed on.

Jump to

Keyboard shortcuts

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