2026-02-04 11:06:13 +00:00
|
|
|
package tools
|
|
|
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
|
|
|
|
|
type Message struct {
|
|
|
|
|
Role string `json:"role"`
|
|
|
|
|
Content string `json:"content"`
|
|
|
|
|
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
|
|
|
|
ToolCallID string `json:"tool_call_id,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ToolCall struct {
|
2026-02-18 19:48:23 +00:00
|
|
|
ID string `json:"id"`
|
|
|
|
|
Type string `json:"type"`
|
|
|
|
|
Function *FunctionCall `json:"function,omitempty"`
|
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
|
Arguments map[string]any `json:"arguments,omitempty"`
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type FunctionCall struct {
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Arguments string `json:"arguments"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type LLMResponse struct {
|
|
|
|
|
Content string `json:"content"`
|
|
|
|
|
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
|
|
|
|
FinishReason string `json:"finish_reason"`
|
|
|
|
|
Usage *UsageInfo `json:"usage,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type UsageInfo struct {
|
|
|
|
|
PromptTokens int `json:"prompt_tokens"`
|
|
|
|
|
CompletionTokens int `json:"completion_tokens"`
|
|
|
|
|
TotalTokens int `json:"total_tokens"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type LLMProvider interface {
|
2026-02-18 19:48:23 +00:00
|
|
|
Chat(
|
|
|
|
|
ctx context.Context,
|
|
|
|
|
messages []Message,
|
|
|
|
|
tools []ToolDefinition,
|
|
|
|
|
model string,
|
|
|
|
|
options map[string]any,
|
|
|
|
|
) (*LLMResponse, error)
|
2026-02-04 11:06:13 +00:00
|
|
|
GetDefaultModel() string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ToolDefinition struct {
|
|
|
|
|
Type string `json:"type"`
|
|
|
|
|
Function ToolFunctionDefinition `json:"function"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ToolFunctionDefinition struct {
|
2026-02-18 19:48:23 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
|
Description string `json:"description"`
|
|
|
|
|
Parameters map[string]any `json:"parameters"`
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
feat(tools): add exec tool enhancement with background execution and PTY support (#1752)
- Unified exec tool with actions: run/list/poll/read/write/send-keys/kill
- PTY support using creack/pty library
- Process session management with background execution
- Process group kill for cleaning up child processes
- Session cleanup: 30-minute TTL for old sessions
- Output buffer: 100MB limit with truncation
Actions:
- run: execute command (sync or background)
- list: list all sessions
- poll: check session status
- read: read session output
- write: send input to session stdin
- send-keys: send special keys (up, down, ctrl-c, enter, etc.)
- kill: terminate session
Tests:
- PTY: allowed commands, write/read, poll, kill, process group kill
- Non-PTY: background execution, list, read, write, poll, kill, process group kill
- Session management: add/get/remove/list/cleanup
2026-03-21 14:38:03 +00:00
|
|
|
|
|
|
|
|
type ExecRequest struct {
|
|
|
|
|
Action string `json:"action"`
|
|
|
|
|
Command string `json:"command,omitempty"`
|
|
|
|
|
PTY bool `json:"pty,omitempty"`
|
|
|
|
|
Background bool `json:"background,omitempty"`
|
|
|
|
|
Timeout int `json:"timeout,omitempty"`
|
|
|
|
|
Env map[string]string `json:"env,omitempty"`
|
|
|
|
|
Cwd string `json:"cwd,omitempty"`
|
|
|
|
|
SessionID string `json:"sessionId,omitempty"`
|
|
|
|
|
Data string `json:"data,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ExecResponse struct {
|
|
|
|
|
SessionID string `json:"sessionId,omitempty"`
|
|
|
|
|
Status string `json:"status,omitempty"`
|
|
|
|
|
ExitCode int `json:"exitCode,omitempty"`
|
|
|
|
|
Output string `json:"output,omitempty"`
|
|
|
|
|
Error string `json:"error,omitempty"`
|
|
|
|
|
Sessions []SessionInfo `json:"sessions,omitempty"`
|
|
|
|
|
}
|