v0.4.9 de90baf

call_tool.go RawHistoryFolder

1package ext
2
3import (
4	"context"
5	"encoding/json"
6	"fmt"
7	"time"
8
9	"github.com/patriceckhart/zot/packages/agent/extproto"
10)
11
12type parentCallKey struct{}
13
14// CallTool asks zot to invoke an active built-in or extension tool. Tool
15// failures are returned as ToolResult.IsError, transport failures as err.
16// Calls made from tool handlers inherit their parent call for cycle detection
17// and cancellation.
18func (e *Extension) CallTool(ctx context.Context, name string, args any) (ToolResult, error) {
19	if !e.callToolReady.Load() {
20		return ToolResult{}, fmt.Errorf("host does not support call_tool")
21	}
22	if ctx == nil {
23		return ToolResult{}, fmt.Errorf("call_tool requires a context")
24	}
25	data, err := json.Marshal(args)
26	if err != nil {
27		return ToolResult{}, fmt.Errorf("encode tool args: %w", err)
28	}
29	if len(data) == 0 || data[0] != '{' {
30		return ToolResult{}, fmt.Errorf("call_tool args must be a JSON object")
31	}
32	ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
33	defer cancel()
34	id := fmt.Sprintf("sdk-%d", e.callSeq.Add(1))
35	ch := make(chan extproto.ToolResultFromHost, 1)
36	e.mu.Lock()
37	e.pendingCalls[id] = ch
38	e.mu.Unlock()
39	defer func() {
40		e.mu.Lock()
41		delete(e.pendingCalls, id)
42		e.mu.Unlock()
43	}()
44	parent, _ := ctx.Value(parentCallKey{}).(string)
45	if err := e.send(extproto.CallToolFromExt{Type: "call_tool", ID: id, Name: name, Args: data, ParentID: parent}); err != nil {
46		return ToolResult{}, err
47	}
48	select {
49	case reply := <-ch:
50		out := ToolResult{IsError: reply.IsError}
51		for _, block := range reply.Content {
52			out.Content = append(out.Content, ToolContent{Type: block.Type, Text: block.Text, MimeType: block.MimeType, Data: block.Data})
53		}
54		if reply.Truncated {
55			out.Content = append(out.Content, Text("[tool result truncated by host]"))
56		}
57		return out, nil
58	case <-ctx.Done():
59		_ = e.send(extproto.Frame{Type: "call_tool_cancel", ID: id})
60		return ToolResult{}, ctx.Err()
61	case <-e.done:
62		return ToolResult{}, fmt.Errorf("host disconnected")
63	}
64}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close