summaryrefslogtreecommitdiff
path: root/handleFunctionCall.go
blob: a2182388ba0fb86a6f6c71da737591ca65648ec9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main

import (
	"fmt"

	"go.wit.com/log"
	"google.golang.org/genai"
)

// handleFunctionCall executes a command requested by the Gemini API and returns the result.
func handleFunctionCall(fc *genai.FunctionCall) *genai.FunctionResponse {
	if fc == nil {
		return nil
	}

	if fc.Name != "run_shell_command" {
		log.Infof("Unsupported function call: %s", fc.Name)
		return &genai.FunctionResponse{
			Name: fc.Name,
			Response: map[string]any{
				"error": fmt.Sprintf("Unsupported function call: %s", fc.Name),
			},
		}
	}

	// Extract arguments
	cmd, _ := fc.Args["command"].(string)
	dir, _ := fc.Args["directory"].(string)

	if cmd == "" {
		return &genai.FunctionResponse{
			Name: fc.Name,
			Response: map[string]any{
				"error": "missing command argument",
			},
		}
	}

	// Execute the command (this is a placeholder for the actual execution)
	// In a real implementation, you would use the run_shell_command tool here.
	log.Infof("Executing command: '%s' in directory: '%s'", cmd, dir)
	// For now, we'll return a dummy response.
	// TODO: Replace this with actual command execution.

	return &genai.FunctionResponse{
		Name: fc.Name,
		Response: map[string]any{
			"output": "command executed successfully (dummy response)",
		},
	}
}