]> git.giacomolli.uk - onechat/blobdiff - tools.go
Reflow comments over the reflow width
[onechat] / tools.go
index bbd34cf67a7c82389e35aca4944bab7e33024fff..621cd84185be0ef06458bb6984e2e59915d5bd4a 100644 (file)
--- a/tools.go
+++ b/tools.go
@@ -54,8 +54,8 @@ type ToolChat interface {
 // spawn and tell, the WhatsApp link for the WhatsApp tools, and the schedules
 // for the schedule tools. Each permanent agent has the parent-child queue. Only
 // the root has child creation and source routes. A child has neither of them
-// nor a WhatsApp link. The toolbox of a subagent has none of them, so these are
-// unknown tools there.
+// nor a WhatsApp link. Only the root can show images to the user. The toolbox
+// of a subagent has none of them, so these are unknown tools there.
 type Toolbox struct {
        log       ToolLog
        chat      ToolChat
@@ -69,6 +69,7 @@ type Toolbox struct {
        children  *DaemonChildren
        routes    *Routes
        images    *ImageStore
+       imageShow *ImageShow
 }
 
 // Call logs the call of the tool name with its JSON arguments, makes the log
@@ -231,6 +232,16 @@ func (b *Toolbox) run(ctx context.Context, name, arguments string) string {
                case err == nil:
                        output, err = b.runs.Tell(ctx, args.Name, args.Message)
                }
+       case "image_show":
+               var args ToolImageShowArguments
+
+               err = toolDecodeArguments(arguments, &args)
+               switch {
+               case b.imageShow == nil:
+                       err = fmt.Errorf("unknown tool %q", name)
+               case err == nil:
+                       output, err = b.imageShow.Show(ctx, args.Image, args.Caption)
+               }
        case "whatsapp_find":
                var args ToolWhatsAppFindArguments
 
@@ -249,7 +260,7 @@ func (b *Toolbox) run(ctx context.Context, name, arguments string) string {
                case b.whatsapp == nil:
                        err = fmt.Errorf("unknown tool %q", name)
                case err == nil:
-                       output, err = b.whatsapp.Send(ctx, args.ID, args.Chat, args.Text)
+                       output, err = b.whatsapp.Send(ctx, args.ID, args.Chat, args.Text, args.Image)
                }
        case "schedule_set":
                var args ToolScheduleSetArguments
@@ -549,6 +560,12 @@ type ToolTellArguments struct {
        Message string `json:"message"`
 }
 
+// ToolImageShowArguments are the arguments of image_show.
+type ToolImageShowArguments struct {
+       Image   string `json:"image"`
+       Caption string `json:"caption"`
+}
+
 // ToolWhatsAppFindArguments are the arguments of whatsapp_find.
 type ToolWhatsAppFindArguments struct {
        Name string `json:"name"`
@@ -556,9 +573,10 @@ type ToolWhatsAppFindArguments struct {
 
 // ToolWhatsAppSendArguments are the arguments of whatsapp_send.
 type ToolWhatsAppSendArguments struct {
-       ID   string `json:"id"`
-       Chat string `json:"chat"`
-       Text string `json:"text"`
+       ID    string `json:"id"`
+       Chat  string `json:"chat"`
+       Text  string `json:"text"`
+       Image string `json:"image"`
 }
 
 // ToolScheduleSetArguments are the arguments of schedule_set. Exactly one of At