toolcommon

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractField added in v1.16.0

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.

func FormatToolResult

func FormatToolResult(content string, width int) string

func Icon

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

func ParseArgs added in v1.16.0

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

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

func RenderTool added in v1.9.22

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

func ShortenPath added in v1.16.0

func ShortenPath(path string) string

ShortenPath replaces home directory with ~ for cleaner display.

func TruncateText added in v1.16.0

func TruncateText(text string, maxWidth int) string

TruncateText truncates text to fit within maxWidth, adding an ellipsis if needed. Uses lipgloss.Width for proper Unicode handling.

Types

type Base added in v1.16.0

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 added in v1.16.0

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

NewBase creates a new base tool component with the given renderer.

func (*Base) Height added in v1.16.0

func (b *Base) Height() int

Height returns the current height.

func (*Base) Init added in v1.16.0

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

func (*Base) Message added in v1.16.0

func (b *Base) Message() *types.Message

Message returns the tool message.

func (*Base) SessionState added in v1.16.0

func (b *Base) SessionState() *service.SessionState

SessionState returns the session state.

func (*Base) SetSize added in v1.16.0

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

func (*Base) Spinner added in v1.16.0

func (b *Base) Spinner() spinner.Spinner

Spinner returns the spinner.

func (*Base) Update added in v1.16.0

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

func (*Base) View added in v1.16.0

func (b *Base) View() string

func (*Base) Width added in v1.16.0

func (b *Base) Width() int

Width returns the current width.

type Renderer added in v1.16.0

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

Renderer is a function that renders a tool call view. It receives the message, spinner, session state, and available width/height.

func SimpleRenderer added in v1.16.0

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 added in v1.16.0

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