Documentation
¶
Overview ¶
Package core implements capture, validation, and export for appshot.
Index ¶
- func ArgumentFields(data []byte) (map[string]json.RawMessage, error)
- func EncodeAttachment(result Result) (metadata any, fallback, context string, png []byte, err error)
- func ErrorCode(err error) string
- func Export(ctx context.Context, directory string, result Result) error
- func ExportChecked(ctx context.Context, directory string, result Result, ...) error
- func NewError(code string, err error) error
- func ValidatePNG(data []byte, m *computeruse.ScreenshotInfo) error
- func WriteContext(w io.Writer, result Result) error
- type Error
- type ImageInfo
- type ModelInput
- type Node
- type Options
- type ProcessStart
- type Result
- type TreeInfo
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 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 ValidatePNG ¶
func ValidatePNG(data []byte, m *computeruse.ScreenshotInfo) error
ValidatePNG checks the complete image against its identity and point geometry.
Types ¶
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.
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 ¶
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.