core

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 22 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 core implements capture, validation, and export for appshot.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgumentFields

func ArgumentFields(data []byte) (map[string]json.RawMessage, error)

ArgumentFields decodes one tool argument object, rejecting duplicate names and null values before field-presence checks. Names use decoded JSON spelling.

func EncodeAttachment

func EncodeAttachment(result Result) (metadata any, fallback, context string, png []byte, err error)

EncodeAttachment validates the capture and returns an independently owned wire copy.

func ErrorCode

func ErrorCode(err error) string

ErrorCode returns the stable code, including cancellation and deadline errors.

func Export

func Export(ctx context.Context, directory string, result Result) error

Export publishes a private artifact directory without replacing an existing path.

func ExportChecked

func ExportChecked(ctx context.Context, directory string, result Result, check func(context.Context) error) error

ExportChecked calls check after preparing all files and immediately before atomic publication. A rejected check removes staging without publishing. The caller supplies live authorization; Export alone validates owned data. Contexts larger than 1 MiB are rejected before staging.

func NewError

func NewError(code string, err error) error

NewError wraps err with a stable appshot error code.

func ValidatePNG

func ValidatePNG(data []byte, m *computeruse.ScreenshotInfo) error

ValidatePNG checks the complete image against its identity and point geometry.

func WriteContext

func WriteContext(w io.Writer, result Result) error

WriteContext writes the already bounded attachment text to w.

Types

type Error

type Error struct {
	Code string
	Err  error
}

Error carries a stable capture failure code and its cause.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ImageInfo

type ImageInfo struct {
	Name     string                     `json:"name"`
	MIMEType string                     `json:"mime_type"`
	Metadata computeruse.ScreenshotInfo `json:"metadata"`
}

ImageInfo describes the separate PNG attachment.

type ModelInput

type ModelInput struct {
	Type     string `json:"type"`
	Text     string `json:"text,omitempty"`
	ImageURL string `json:"image_url,omitempty"`
	Detail   string `json:"detail,omitempty"`
}

ModelInput is a text or image input for a model client. ImageURL is a data URL formed after validating the separate PNG attachment.

func BuildModelInputs

func BuildModelInputs(result Result) ([]ModelInput, error)

BuildModelInputs validates a capture and builds text and any original-size image input.

func DecodeModelInputs

func DecodeModelInputs(metadata, text string, structuredContent any, mimeType string, png []byte, hasImage, validImage bool) ([]ModelInput, error)

DecodeModelInputs checks the metadata and context blocks before building model input.

type Node

type Node struct {
	computeruse.ElementNode
	Subrole         string                `json:"subrole,omitempty"`
	SecureValue     bool                  `json:"secure_value,omitempty"`
	FloatValue      bool                  `json:"float_value,omitempty"`
	ValueType       computeruse.ValueType `json:"value_type,omitzero"`
	Focused         bool                  `json:"focused,omitempty"`
	SelectedText    string                `json:"selected_text,omitempty"`
	WebFocus        *Node                 `json:"web_focus,omitempty"`
	WebDocument     bool                  `json:"web_document,omitempty"`
	RoleDescription string                `json:"role_description,omitempty"`
	// RoleDescriptionPresent distinguishes a present empty button/checkbox label
	// from an unavailable description. Nonempty descriptions take precedence.
	RoleDescriptionPresent bool   `json:"role_description_present,omitempty"`
	URL                    string `json:"url,omitempty"`
	Help                   string `json:"help,omitempty"`
	Placeholder            string `json:"placeholder,omitempty"`
	ValueDescription       string `json:"value_description,omitempty"`
}

Node is a plain accessibility value. Secure fields may contain validated masks.

type Options

type Options struct {
	Image        string `json:"image,omitempty"`
	TimeoutMS    int    `json:"timeout_ms,omitempty"`
	MaxNodes     int    `json:"max_nodes,omitempty"`
	MaxTextBytes int    `json:"max_text_bytes,omitempty"`
}

Options bounds one capture. Normalize applies defaults and checks limits.

func (Options) Normalize

func (o Options) Normalize() (Options, error)

Normalize returns capture options with defaults applied.

type ProcessStart

type ProcessStart struct {
	Seconds      int64 `json:"seconds"`
	Microseconds int64 `json:"microseconds"`
}

ProcessStart identifies the native process birth time.

type Result

type Result struct {
	Version           int                    `json:"version"`
	AppshotID         string                 `json:"appshot_id"`
	CapturedAt        time.Time              `json:"captured_at"`
	CaptureStartedAt  time.Time              `json:"capture_started_at"`
	CaptureFinishedAt time.Time              `json:"capture_finished_at"`
	App               computeruse.AppInfo    `json:"app"`
	ProcessStart      ProcessStart           `json:"process_start"`
	Window            computeruse.WindowInfo `json:"window"`
	Context           string                 `json:"context"`
	Tree              TreeInfo               `json:"tree"`
	Image             *ImageInfo             `json:"image,omitempty"`
	Warnings          []string               `json:"warnings"`
	PNG               []byte                 `json:"-"`
	// contains filtered or unexported fields
}

Result owns copied capture values. PNG is excluded from metadata JSON.

func Build

func Build(app computeruse.AppInfo, window computeruse.WindowInfo, birth ProcessStart, nodes []Node, data []byte, metadata *computeruse.ScreenshotInfo, options Options, started, finished time.Time) (Result, error)

Build copies and validates a capture before formatting its attachment context. Image captures require logical window geometry matching the rounded capture rectangle. Zero screenshot dimensions are filled from the validated PNG.

func (Result) ScreenRecordingRequired

func (r Result) ScreenRecordingRequired() bool

ScreenRecordingRequired reports whether publication requires screen access. It remains true when capture observed a grant but returned text only. The capture-local grant history is not included in wire metadata.

type TreeInfo

type TreeInfo struct {
	NodeCount           int    `json:"node_count"`
	Truncated           bool   `json:"truncated"`
	OmittedSecureValues int    `json:"omitted_secure_values"`
	Limit               string `json:"limit,omitempty"`
}

TreeInfo reports traversal and formatting limits.

Jump to

Keyboard shortcuts

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