8d89a762fb
Cada tool ahora vive en su propio subpackage dentro de tools/ (clock, file, http, knowledgetools, matrix, memorytools, ssh, weather) en lugar de archivos planos en el paquete raíz tools/. Esto mejora la organización, permite imports selectivos y reduce acoplamiento entre tools. El paquete tools/ raíz conserva los tipos base (Def, Param, Result, ToolFunc, Tool, Registry). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package matrix
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/enmanuel/agents/tools"
|
|
)
|
|
|
|
// MatrixSender is the interface for sending Matrix messages.
|
|
// Satisfied by shell/matrix.Client.
|
|
type MatrixSender interface {
|
|
SendText(ctx context.Context, roomID, text string) error
|
|
SendMarkdown(ctx context.Context, roomID, markdown string) error
|
|
}
|
|
|
|
// NewMatrixSend creates a matrix_send tool that sends a message to a Matrix room.
|
|
func NewMatrixSend(sender MatrixSender) tools.Tool {
|
|
return tools.Tool{
|
|
Def: tools.Def{
|
|
Name: "matrix_send",
|
|
Description: "Send a text message to a Matrix room.",
|
|
Parameters: []tools.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) tools.Result {
|
|
roomID := tools.GetString(args, "room_id")
|
|
message := tools.GetString(args, "message")
|
|
if roomID == "" || message == "" {
|
|
return tools.Result{Err: fmt.Errorf("matrix_send: room_id and message are required")}
|
|
}
|
|
|
|
if err := sender.SendMarkdown(ctx, roomID, message); err != nil {
|
|
return tools.Result{Err: fmt.Errorf("matrix_send: %w", err)}
|
|
}
|
|
|
|
return tools.Result{Output: fmt.Sprintf("message sent to %s", roomID)}
|
|
},
|
|
}
|
|
}
|