toolcommon

package
v1.53.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const LongRunningThreshold = 60 * time.Second

LongRunningThreshold is the duration after which a running tool call displays a warning hint that it may be blocked on external input.

Variables

This section is empty.

Functions

func ExtractField

func ExtractField[T any](field func(T) string) func(string) string

ExtractField creates an argument extractor function that parses JSON and extracts a field. The field function receives the parsed args and returns the display string. It supports partial JSON parsing for streaming tool calls.

func FormatToolResult

func FormatToolResult(content string, width int) string

func Icon

func Icon(msg *types.Message, inProgress spinner.Spinner) string

func LongRunningWarning added in v1.41.0

func LongRunningWarning(msg *types.Message) string

LongRunningWarning returns a warning string if the tool call has been running longer than LongRunningThreshold, or empty string otherwise.

func NoArgsRenderer added in v1.53.0

func NoArgsRenderer(msg *types.Message, s spinner.Spinner, sessionState service.SessionStateReader, width, _ int) string

NoArgsRenderer is a Renderer that displays only the tool name and status, without arguments or a result. Useful for tools whose arguments aren't worth surfacing in the UI (e.g. user_prompt, todo helpers).

func ParseArgs

func ParseArgs[T any](args string) (T, error)

ParseArgs unmarshals JSON arguments into a typed struct. Returns an error if parsing fails.

func Pluralize added in v1.53.0

func Pluralize(count int, singular, plural string) string

Pluralize formats a count with its singular or plural form, e.g. Pluralize(1, "file", "files") returns "1 file" while Pluralize(3, "file", "files") returns "3 files".

func RenderFriendlyHeader

func RenderFriendlyHeader(msg *types.Message, s spinner.Spinner) (string, bool)

RenderFriendlyHeader renders a friendly description header if present in the tool call arguments. Returns the rendered header string and true if a friendly description was found, empty string and false otherwise. Custom renderers can use this to show the friendly description before their custom content.

func RenderTool

func RenderTool(msg *types.Message, inProgress spinner.Spinner, args, result string, width int, hideToolResults bool) string

func ShortenPath

func ShortenPath(path string) string

ShortenPath replaces home directory with ~ for cleaner display.

func TruncateText

func TruncateText(text string, maxWidth int) string

TruncateText truncates text to fit within maxWidth, adding an ellipsis if needed. Uses a forward-scanning approach for O(n) complexity instead of O(n²). Note: lipgloss.Width returns the maximum line width for multi-line strings.

func WrapLines

func WrapLines(text string, width int) []string

WrapLines wraps text to fit within the given width. Each line that exceeds the width is split at rune boundaries.

func WrapLinesWords

func WrapLinesWords(text string, width int) []string

WrapLinesWords wraps text to fit within the given width, preferring to break at word boundaries (spaces). If a single word exceeds the width, it falls back to splitting at rune boundaries.

Types

type Base

type Base struct {
	// contains filtered or unexported fields
}

Base provides common boilerplate for tool components. It handles spinner management, sizing, and delegates rendering to a custom function.

func NewBase

func NewBase(msg *types.Message, sessionState service.SessionStateReader, render Renderer) *Base

NewBase creates a new base tool component with the given renderer. Accepts SessionStateReader for read-only access (also accepts *SessionState which implements it).

func NewBaseWithCollapsed

func NewBaseWithCollapsed(msg *types.Message, sessionState service.SessionStateReader, render Renderer, collapsedRender CollapsedRenderer) *Base

NewBaseWithCollapsed creates a new base tool component with both regular and collapsed renderers. Accepts SessionStateReader for read-only access (also accepts *SessionState which implements it).

func (*Base) CollapsedView

func (b *Base) CollapsedView() string

CollapsedView returns a simplified view for use in collapsed reasoning blocks. Falls back to the regular View() if no collapsed renderer is provided.

func (*Base) Init

func (b *Base) Init() tea.Cmd

func (*Base) SetSize

func (b *Base) SetSize(width, height int) tea.Cmd

func (*Base) StopAnimation

func (b *Base) StopAnimation()

StopAnimation stops the spinner animation and unregisters from the animation coordinator. This must be called when the view is removed from the UI to avoid leaked animation subscriptions.

func (*Base) Update

func (b *Base) Update(msg tea.Msg) (layout.Model, tea.Cmd)

func (*Base) View

func (b *Base) View() string

type CollapsedRenderer

type CollapsedRenderer func(msg *types.Message, s spinner.Spinner, sessionState service.SessionStateReader, width, height int) string

CollapsedRenderer is a function that renders a simplified view for collapsed reasoning blocks.

type Renderer

type Renderer func(msg *types.Message, s spinner.Spinner, sessionState service.SessionStateReader, width, height int) string

Renderer is a function that renders a tool call view. It receives the message, spinner, session state reader, and available width/height. Note: Uses SessionStateReader interface for read-only access to session state.

func SimpleRenderer

func SimpleRenderer(extractArg func(args string) string) Renderer

SimpleRenderer creates a renderer that extracts a single string argument and renders it with RenderTool. This covers the most common case where tools just display one argument (like path, command, etc.).

func SimpleRendererWithResult

func SimpleRendererWithResult(
	extractArg func(args string) string,
	extractResult func(msg *types.Message) string,
) Renderer

SimpleRendererWithResult creates a renderer that extracts a single string argument and also shows a result/summary after completion.

Jump to

Keyboard shortcuts

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