htmlpreview

package
v0.99.13 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package htmlpreview provides the chatagent tool for sandboxed HTML artifacts.

Index

Constants

View Source
const (
	// ToolName is the agent tool name for presenting HTML artifacts.
	ToolName = "present_html"
	// MaxHTMLBytes rejects html arguments above this size.
	MaxHTMLBytes = 256 << 10
	// DefaultTitle is used when the model omits title.
	DefaultTitle = "HTML"
	// PreviewCSP is injected into the preview document. It is the network lock
	// complementing iframe sandbox="allow-scripts" (without allow-same-origin).
	PreviewCSP = "" /* 217-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func ActiveToolNames

func ActiveToolNames() []string

ActiveToolNames returns the default htmlpreview tool names.

func FormatResult

func FormatResult(parsed ParsedArgs) string

FormatResult builds the stub tool result shown to the model and stored as stdout.

func HTMLAndTitleFromArguments

func HTMLAndTitleFromArguments(raw string) (html, title string)

HTMLAndTitleFromArguments reads html and title from a tool-call JSON string without generating an id or re-validating size (for UI / SSE hydration).

func HashHTML

func HashHTML(html string) string

HashHTML returns the hex SHA-256 of html (full digest).

func PrepareDocument

func PrepareDocument(html, title string) string

PrepareDocument wraps html as a complete document with CSP meta in <head>.

func Register

func Register(registry *tool.Registry) error

Register registers present_html on the given registry.

Types

type ParsedArgs

type ParsedArgs struct {
	HTML  string
	Title string
	ID    string
	Bytes int
	Hash  string
}

ParsedArgs is the validated present_html payload.

func ParseArgs

func ParseArgs(args map[string]any) (ParsedArgs, error)

ParseArgs validates tool arguments and fills id/title defaults.

type ResultMeta

type ResultMeta struct {
	ID    string
	Title string
}

ResultMeta is parsed from a present_html stub result.

func ParseResultMeta

func ParseResultMeta(text string) ResultMeta

ParseResultMeta extracts id/title from a present_html stub result.

type Tool

type Tool struct{}

Tool upserts a session HTML artifact. The full document lives in the tool-call arguments; the result is a short stub for the model.

func (Tool) Description

func (Tool) Description() string

Description explains the tool to the model.

func (Tool) Execute

func (Tool) Execute(_ context.Context, callID string, args map[string]any, _ tool.UpdateHandler) (msg.ToolResultMessage, error)

Execute validates html, assigns an id when missing, and returns a stub summary.

func (Tool) Name

func (Tool) Name() string

Name returns the tool identifier.

func (Tool) Parameters

func (Tool) Parameters() map[string]any

Parameters returns the JSON schema for tool arguments.

Jump to

Keyboard shortcuts

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