feat: implement tool registry and add various tools for HTTP, file operations, SSH, and Matrix messaging
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// MatrixSender is the interface for sending Matrix messages.
|
||||
// Satisfied by shell/matrix.Client.
|
||||
type MatrixSender interface {
|
||||
SendText(ctx context.Context, roomID, text string) error
|
||||
}
|
||||
|
||||
// NewMatrixSend creates a matrix_send tool that sends a message to a Matrix room.
|
||||
func NewMatrixSend(sender MatrixSender) Tool {
|
||||
return Tool{
|
||||
Def: Def{
|
||||
Name: "matrix_send",
|
||||
Description: "Send a text message to a Matrix room.",
|
||||
Parameters: []Param{
|
||||
{Name: "room_id", Type: "string", Description: "The Matrix room ID to send to", Required: true},
|
||||
{Name: "message", Type: "string", Description: "The text message to send", Required: true},
|
||||
},
|
||||
},
|
||||
Exec: func(ctx context.Context, args map[string]any) Result {
|
||||
roomID := getString(args, "room_id")
|
||||
message := getString(args, "message")
|
||||
if roomID == "" || message == "" {
|
||||
return Result{Err: fmt.Errorf("matrix_send: room_id and message are required")}
|
||||
}
|
||||
|
||||
if err := sender.SendText(ctx, roomID, message); err != nil {
|
||||
return Result{Err: fmt.Errorf("matrix_send: %w", err)}
|
||||
}
|
||||
|
||||
return Result{Output: fmt.Sprintf("message sent to %s", roomID)}
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user