Skip to content

Commit 3980eb5

Browse files
committed
refactor: Remove result view and enhance logging in tool command
This commit removes the `resultView` state and associated logic from the application, streamlining the user experience by eliminating unnecessary state transitions. Additionally, it improves logging by adding separators in the output for better readability when displaying tool results and calling tool arguments. Key changes: - Removed the `resultView` state and related update logic. - Enhanced logging for tool results and tool calls to improve clarity in the debug panel.
1 parent c389c61 commit 3980eb5

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

main.go

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ type viewState int
131131
const (
132132
toolSelectionView viewState = iota
133133
argumentInputView
134-
resultView
135134
)
136135

137136
type AppModel struct {
@@ -222,9 +221,8 @@ func (m *AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
222221
if verbose {
223222
m.logf("Tool result received")
224223
}
225-
m.logf("Result:\n%s", msg.result)
224+
m.logf("Result:\n========\n%s", msg.result)
226225
m.result = msg.result
227-
m.state = resultView
228226
case tea.KeyMsg:
229227
if verbose {
230228
m.logf("Key pressed: %s", msg.String())
@@ -252,13 +250,6 @@ func (m *AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
252250
m.debugViewport, cmd = m.debugViewport.Update(msg)
253251
cmds = append(cmds, cmd)
254252
return model, tea.Batch(cmds...)
255-
case resultView:
256-
var model tea.Model
257-
model, cmd = m.updateResultView(msg)
258-
cmds = append(cmds, cmd)
259-
m.debugViewport, cmd = m.debugViewport.Update(msg)
260-
cmds = append(cmds, cmd)
261-
return model, tea.Batch(cmds...)
262253
}
263254

264255
case tea.WindowSizeMsg:
@@ -318,18 +309,6 @@ func (m *AppModel) updateToolSelectionView(msg tea.Msg) (tea.Model, tea.Cmd) {
318309
return m, cmd
319310
}
320311

321-
func (m *AppModel) updateResultView(msg tea.Msg) (tea.Model, tea.Cmd) {
322-
if keyMsg, ok := msg.(tea.KeyMsg); ok {
323-
if keyMsg.Type == tea.KeyEnter {
324-
if verbose {
325-
m.logf("State change: resultView -> argumentInputView")
326-
}
327-
m.state = argumentInputView
328-
}
329-
}
330-
return m, nil
331-
}
332-
333312
func (m *AppModel) updateArgumentInputView(msg tea.Msg) (tea.Model, tea.Cmd) {
334313
keyMsg, ok := msg.(tea.KeyMsg)
335314
if !ok {
@@ -395,8 +374,6 @@ func (m AppModel) View() string {
395374
}
396375
b.WriteString("\nPress Enter to submit, Tab to switch fields, Esc to go back to tool selection.")
397376
mainContent.WriteString(b.String())
398-
case resultView:
399-
mainContent.WriteString(fmt.Sprintf("Tool Result:\n\n%s\n\nPress Enter to return to the argument input.", m.result))
400377
}
401378

402379
mainPanel := lipgloss.NewStyle().
@@ -431,20 +408,32 @@ func (m *AppModel) callToolCmd() tea.Cmd {
431408
if prop, ok := m.selectedTool.InputSchema.Properties[name]; ok {
432409
switch prop.Type {
433410
case "number":
411+
if valueStr == "" {
412+
finalValue = 0
413+
continue
414+
}
434415
f, err := strconv.ParseFloat(valueStr, 64)
435416
if err == nil {
436417
finalValue = f
437418
} else {
438419
m.logf("Error converting arg '%s' to number: %v", name, err)
439420
}
440421
case "integer":
422+
if valueStr == "" {
423+
finalValue = 0
424+
continue
425+
}
441426
i, err := strconv.Atoi(valueStr)
442427
if err == nil {
443428
finalValue = i
444429
} else {
445430
m.logf("Error converting arg '%s' to integer: %v", name, err)
446431
}
447432
case "boolean":
433+
if valueStr == "" {
434+
finalValue = false
435+
continue
436+
}
448437
b, err := strconv.ParseBool(valueStr)
449438
if err == nil {
450439
finalValue = b
@@ -460,7 +449,7 @@ func (m *AppModel) callToolCmd() tea.Cmd {
460449
if err != nil {
461450
m.logf("Error marshalling args: %v", err)
462451
}
463-
m.logf("Calling tool '%s' with args:\n%s", m.selectedTool.Name, string(prettyArgs))
452+
m.logf("========\nCalling tool '%s' with args:\n%s", m.selectedTool.Name, string(prettyArgs))
464453

465454
params := &mcp.CallToolParams{
466455
Name: m.selectedTool.Name,

0 commit comments

Comments
 (0)