formatter

package
v1.209.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorInfo

type ErrorInfo struct {
	// Message is the error message.
	Message string `json:"message"`

	// Type categorizes the error (ai_error, tool_error, config_error, etc.).
	Type string `json:"type"`

	// Details contains additional error context.
	Details map[string]interface{} `json:"details,omitempty"`
}

ErrorInfo contains error information.

type ExecutionMetadata

type ExecutionMetadata struct {
	// Model is the AI model that was used.
	Model string `json:"model"`

	// Provider is the AI provider (anthropic, openai, etc.).
	Provider string `json:"provider"`

	// SessionID is the session identifier (if using sessions).
	SessionID string `json:"session_id,omitempty"`

	// DurationMs is the total execution time in milliseconds.
	DurationMs int64 `json:"duration_ms"`

	// Timestamp is when the execution started.
	Timestamp time.Time `json:"timestamp"`

	// ToolsEnabled indicates if tool execution was enabled.
	ToolsEnabled bool `json:"tools_enabled"`

	// StopReason indicates why the model stopped generating.
	StopReason types.StopReason `json:"stop_reason,omitempty"`
}

ExecutionMetadata contains metadata about the execution.

type ExecutionResult

type ExecutionResult struct {
	// Success indicates if the execution completed successfully.
	Success bool `json:"success"`

	// Response is the final text response from the AI.
	Response string `json:"response"`

	// ToolCalls contains information about any tools that were executed.
	ToolCalls []ToolCallResult `json:"tool_calls,omitempty"`

	// Tokens contains token usage information.
	Tokens TokenUsage `json:"tokens"`

	// Metadata contains execution metadata.
	Metadata ExecutionMetadata `json:"metadata"`

	// Error contains error information if the execution failed.
	Error *ErrorInfo `json:"error,omitempty"`
}

ExecutionResult contains the complete result of an AI execution.

type Format

type Format string

Format represents the output format type.

const (
	// FormatJSON outputs structured JSON.
	FormatJSON Format = "json"

	// FormatText outputs plain text (default).
	FormatText Format = "text"

	// FormatMarkdown outputs formatted markdown.
	FormatMarkdown Format = "markdown"
)

type Formatter

type Formatter interface {
	// Format writes the formatted response to the writer.
	Format(w io.Writer, result *ExecutionResult) error
}

Formatter defines the interface for formatting AI responses in different output formats.

func NewFormatter

func NewFormatter(format Format) Formatter

NewFormatter creates a formatter for the specified format.

type JSONFormatter

type JSONFormatter struct{}

JSONFormatter formats responses as JSON.

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(w io.Writer, result *ExecutionResult) error

Format writes the execution result as pretty-printed JSON.

type MarkdownFormatter

type MarkdownFormatter struct{}

MarkdownFormatter formats responses as markdown.

func (*MarkdownFormatter) Format

func (f *MarkdownFormatter) Format(w io.Writer, result *ExecutionResult) error

Format writes the execution result as formatted markdown.

type TextFormatter

type TextFormatter struct{}

TextFormatter formats responses as plain text.

func (*TextFormatter) Format

func (f *TextFormatter) Format(w io.Writer, result *ExecutionResult) error

Format writes the execution result as plain text (just the AI response).

type TokenUsage

type TokenUsage struct {
	// Prompt tokens used in the request.
	Prompt int64 `json:"prompt"`

	// Completion tokens used in the response.
	Completion int64 `json:"completion"`

	// Total tokens used (prompt + completion).
	Total int64 `json:"total"`

	// Cached tokens read from prompt cache (if supported).
	Cached int64 `json:"cached,omitempty"`

	// CacheCreation tokens used to create cache (if supported).
	CacheCreation int64 `json:"cache_creation,omitempty"`
}

TokenUsage contains token usage statistics.

type ToolCallResult

type ToolCallResult struct {
	// Tool is the name of the tool that was called.
	Tool string `json:"tool"`

	// Args contains the arguments passed to the tool.
	Args map[string]interface{} `json:"args,omitempty"`

	// DurationMs is the execution time in milliseconds.
	DurationMs int64 `json:"duration_ms"`

	// Success indicates if the tool executed successfully.
	Success bool `json:"success"`

	// Result contains the tool's output (if successful).
	Result interface{} `json:"result,omitempty"`

	// Error contains error information (if failed).
	Error string `json:"error,omitempty"`
}

ToolCallResult contains the result of a tool execution.

Jump to

Keyboard shortcuts

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