MCPcopy
hub / github.com/wavetermdev/waveterm / GetTermGetScrollbackToolDefinition

Function GetTermGetScrollbackToolDefinition

pkg/aiusechat/tools_term.go:154–215  ·  view source on GitHub ↗
(tabId string)

Source from the content-addressed store, hash-verified

152}
153
154func GetTermGetScrollbackToolDefinition(tabId string) uctypes.ToolDefinition {
155 return uctypes.ToolDefinition{
156 Name: "term_get_scrollback",
157 DisplayName: "Get Terminal Scrollback",
158 Description: "Fetch terminal scrollback from a widget as plain text. Index 0 is the most recent line; indices increase going upward (older lines). Also returns last command and exit code if shell integration is enabled.",
159 ToolLogName: "term:getscrollback",
160 InputSchema: map[string]any{
161 "type": "object",
162 "properties": map[string]any{
163 "widget_id": map[string]any{
164 "type": "string",
165 "description": "8-character widget ID of the terminal widget",
166 },
167 "line_start": map[string]any{
168 "type": "integer",
169 "minimum": 0,
170 "description": "Logical start index where 0 = most recent line (default: 0).",
171 },
172 "count": map[string]any{
173 "type": "integer",
174 "minimum": 1,
175 "description": "Number of lines to return from line_start (default: 200).",
176 },
177 },
178 "required": []string{"widget_id"},
179 "additionalProperties": false,
180 },
181 ToolCallDesc: func(input any, output any, toolUseData *uctypes.UIMessageDataToolUse) string {
182 parsed, err := parseTermGetScrollbackInput(input)
183 if err != nil {
184 return fmt.Sprintf("error parsing input: %v", err)
185 }
186
187 if parsed.LineStart == 0 && parsed.Count == 200 {
188 return fmt.Sprintf("reading terminal output from %s (most recent %d lines)", parsed.WidgetId, parsed.Count)
189 }
190 lineEnd := parsed.LineStart + parsed.Count
191 return fmt.Sprintf("reading terminal output from %s (lines %d-%d)", parsed.WidgetId, parsed.LineStart, lineEnd)
192 },
193 ToolAnyCallback: func(input any, toolUseData *uctypes.UIMessageDataToolUse) (any, error) {
194 parsed, err := parseTermGetScrollbackInput(input)
195 if err != nil {
196 return nil, err
197 }
198
199 lineEnd := parsed.LineStart + parsed.Count
200 output, err := getTermScrollbackOutput(
201 tabId,
202 parsed.WidgetId,
203 wshrpc.CommandTermGetScrollbackLinesData{
204 LineStart: parsed.LineStart,
205 LineEnd: lineEnd,
206 LastCommand: false,
207 },
208 )
209 if err != nil {
210 return nil, fmt.Errorf("failed to get terminal scrollback: %w", err)
211 }

Callers 1

GenerateTabStateAndToolsFunction · 0.85

Calls 2

getTermScrollbackOutputFunction · 0.85

Tested by

no test coverage detected