domain

package
v1.4.559 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 18 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

Index

Constants

View Source
const (
	DefaultTemperature      = 0.7
	DefaultTopP             = 0.9
	DefaultPresencePenalty  = 0.0
	DefaultFrequencyPenalty = 0.0
)

Default chat options. They must match the defaults in internal/cli/flags.go.

View Source
const (
	// TokenBudgetLow is suitable for basic reasoning or smaller models (e.g., 1k context window).
	TokenBudgetLow int64 = 1024
	// TokenBudgetMedium is suitable for intermediate reasoning or mid-sized models (e.g., 2k context window).
	TokenBudgetMedium int64 = 2048
	// TokenBudgetHigh is suitable for advanced reasoning or large models (e.g., 4k context window).
	TokenBudgetHigh int64 = 4096
)

Token budgets for each ThinkingLevel. Providers send them as the thinking budget of a request. Adjust them when model capabilities change.

View Source
const ChatMessageRoleMeta = "meta"
View Source
const FileChangesMarker = "__CREATE_CODING_FEATURE_FILE_CHANGES__"

FileChangesMarker identifies the start of a file changes section in output

View Source
const (
	// MaxFileSize is the maximum size of a file that can be created (10MB)
	MaxFileSize = 10 * 1024 * 1024
)

Variables

ThinkingBudgets defines standardized token budgets for reasoning-enabled models.

Functions

func ApplyFileChanges

func ApplyFileChanges(projectRoot string, changes []FileChange) error

ApplyFileChanges applies the parsed file changes to the file system.

The change list comes from model output. Thus all writes go through os.Root, which refuses a path that goes out of projectRoot through a symlink. filepath.IsLocal only examines the path text and cannot find this. ApplyFileChanges also refuses a path through a symlink and a path into .git, so that a change cannot write a git hook.

func ExtractFencedCodeBlock added in v1.4.487

func ExtractFencedCodeBlock(text string, last bool) (string, bool)

ExtractFencedCodeBlock returns the content of the first (or, if last is true, the last) Markdown fenced code block in text, without the fence lines.

A fence is a line of three or more backticks or tildes, optionally indented by up to three spaces and followed by an info string such as a language tag. The block is closed by a line of the same character that is at least as long as the opening fence. A block left open at the end of text runs to the end. The second return value is false when text contains no fenced code block.

func NormalizeMessages

func NormalizeMessages(msgs []*chat.ChatCompletionMessage, defaultUserMessage string) (ret []*chat.ChatCompletionMessage)

NormalizeMessages remove empty messages and ensure messages order user-assist-user

func SanitizeTerminalOutput added in v1.4.516

func SanitizeTerminalOutput(s string) string

SanitizeTerminalOutput removes escape sequences and control characters from text before Fabric writes it to the terminal. Model output can contain sequences that move the cursor, clear the screen, set links (OSC 8) or write to the clipboard (OSC 52). The function keeps SGR color sequences, tab, newline and carriage return. Only the displayed copy goes through this function. The session, clipboard and output file keep the full text.

func SplitOpenEscape added in v1.4.516

func SplitOpenEscape(s string) (done, rest string)

SplitOpenEscape divides streamed text before an escape sequence at its end that is not complete. Print SanitizeTerminalOutput(done), and put rest in front of the next chunk. Then a sequence that two chunks divide is removed or kept as one sequence, and its bytes do not show as text.

func StripThinkBlocks added in v1.4.252

func StripThinkBlocks(input, startTag, endTag string) string

StripThinkBlocks removes each start tag, end tag, and the text between them from input. It also removes the whitespace after the end tag, so the output continues at the next non-blank text.

Types

type Attachment

type Attachment struct {
	Type    *string `json:"type,omitempty"`
	Path    *string `json:"path,omitempty"`
	URL     *string `json:"url,omitempty"`
	Content []byte  `json:"content,omitempty"`
	ID      *string `json:"id,omitempty"`
}

func NewAttachment

func NewAttachment(value string) (ret *Attachment, err error)

func (*Attachment) Base64Content

func (a *Attachment) Base64Content() (ret string, err error)

func (*Attachment) ContentBytes

func (a *Attachment) ContentBytes() (ret []byte, err error)

func (*Attachment) GetId

func (a *Attachment) GetId() (ret string, err error)

func (*Attachment) ResolveType

func (a *Attachment) ResolveType() (ret string, err error)

type ChatOptions

type ChatOptions struct {
	Model               string
	Temperature         float64
	TopP                float64
	PresencePenalty     float64
	FrequencyPenalty    float64
	Raw                 bool
	Seed                int
	Thinking            ThinkingLevel
	ModelContextLength  int
	MaxTokens           int
	Search              bool
	SearchLocation      string
	ImageFile           string
	ImageSize           string
	ImageQuality        string
	ImageCompression    int
	ImageBackground     string
	SuppressThink       bool
	ThinkStartTag       string
	ThinkEndTag         string
	AudioOutput         bool
	AudioFormat         string
	Voice               string
	Notification        bool
	NotificationCommand string
	ShowMetadata        bool
	Quiet               bool
	// SessionID is a stable identifier for the current conversation. Providers
	// that support session-based routing (e.g. OpenCode) forward it as a header.
	// It is derived internally and must not be part of the REST API surface.
	SessionID    string            `json:"-"`
	BufferStream bool              // collect streamed content without printing it
	UpdateChan   chan StreamUpdate `json:"-"`
}

type ChatRequest

type ChatRequest struct {
	ContextName           string
	SessionName           string
	PatternName           string
	PatternVariables      map[string]string
	Message               *chat.ChatCompletionMessage
	Language              string
	Meta                  string
	InputHasVars          bool
	NoVariableReplacement bool
	StrategyName          string
}

type FileChange

type FileChange struct {
	Operation string `json:"operation"` // "create" or "update"
	Path      string `json:"path"`      // Relative path from project root
	Content   string `json:"content"`   // New file content
}

FileChange represents a single file change operation to be performed

func ParseFileChanges

func ParseFileChanges(output string) (changeSummary string, changes []FileChange, err error)

ParseFileChanges extracts and parses the file change marker section from LLM output

type ProviderError added in v1.4.550

type ProviderError struct {
	Err error
}

ProviderError is an error that an AI provider sent. Its text can repeat the prompt or other private content.

func (*ProviderError) Error added in v1.4.550

func (e *ProviderError) Error() string

func (*ProviderError) Unwrap added in v1.4.550

func (e *ProviderError) Unwrap() error

type StreamType added in v1.4.367

type StreamType string

StreamType distinguishes between partial text content and metadata events.

const (
	StreamTypeContent StreamType = "content"
	StreamTypeUsage   StreamType = "usage"
	StreamTypeError   StreamType = "error"
)

type StreamUpdate added in v1.4.367

type StreamUpdate struct {
	Type    StreamType     `json:"type"`
	Content string         `json:"content,omitempty"` // For text deltas
	Usage   *UsageMetadata `json:"usage,omitempty"`   // For token counts
}

StreamUpdate is the unified payload sent through the internal channels.

type ThinkingLevel added in v1.4.286

type ThinkingLevel string

ThinkingLevel represents reasoning/thinking levels supported across providers.

const (
	ThinkingOff    ThinkingLevel = "off"
	ThinkingLow    ThinkingLevel = "low"
	ThinkingMedium ThinkingLevel = "medium"
	ThinkingHigh   ThinkingLevel = "high"
)

type UsageMetadata added in v1.4.367

type UsageMetadata struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
	TotalTokens  int `json:"total_tokens"`
}

UsageMetadata normalizes token counts across different providers.

Jump to

Keyboard shortcuts

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