]> git.giacomolli.uk - onechat/blobdiff - daemon.go
Test the commit message wrapping boundaries
[onechat] / daemon.go
index ea253180228d342a5343a3915a6efcbdb88afe18..b6595c7624a12ef316f0c01a892584791a5b4637 100644 (file)
--- a/daemon.go
+++ b/daemon.go
@@ -201,6 +201,61 @@ func (h *DaemonHub) CloseAll() {
        h.workers.Wait()
 }
 
+// daemonRunRequest runs one request of a client. The answers of a WhatsApp
+// command go to answer.
+func daemonRunRequest(l *TurnLoop, whatsapp *WhatsApp, request SocketRequest, answer func(text string)) error {
+       switch request.Type {
+       case "send":
+               if request.Text == "" {
+                       return errors.New("empty message")
+               }
+
+               _, err := l.Submit(terminalSource, request.Text)
+
+               return err
+       case "image":
+               if !filepath.IsAbs(request.Path) {
+                       return errors.New("use /image PATH [caption]")
+               }
+
+               data, err := imageReadFile(request.Path)
+               if err != nil {
+                       return fmt.Errorf("read terminal image: %w", err)
+               }
+
+               name, err := l.agent.Images().Save(data)
+               if err != nil {
+                       return fmt.Errorf("store terminal image: %w", err)
+               }
+
+               _, err = l.Submit(terminalSource, imageText([]string{name}, request.Text))
+               if err != nil {
+                       return fmt.Errorf("submit terminal image: %w", err)
+               }
+
+               return nil
+       case "interrupt":
+               if !l.Interrupt() {
+                       return errors.New("no turn runs")
+               }
+
+               return nil
+       case "whatsapp":
+               whatsapp.Command(request.Text, answer)
+
+               return nil
+       case "stop":
+               found, err := l.StopSubagent(request.Text)
+               if err == nil && !found {
+                       err = fmt.Errorf("no subagent %s runs", request.Text)
+               }
+
+               return err
+       default:
+               return fmt.Errorf("unknown request %q", request.Type)
+       }
+}
+
 // daemon runs "onechat daemon": it owns the root, its children, and their
 // files, and serves the clients on the Unix socket in the data directory until
 // ctx ends. When telegram.json exists, it also runs the Telegram bot. It also
@@ -489,58 +544,3 @@ func daemonRunChild(ctx context.Context, loop *TurnLoop, schedules *Schedules) e
 
        return errors.Join(err, <-done)
 }
-
-// daemonRunRequest runs one request of a client. The answers of a WhatsApp
-// command go to answer.
-func daemonRunRequest(l *TurnLoop, whatsapp *WhatsApp, request SocketRequest, answer func(text string)) error {
-       switch request.Type {
-       case "send":
-               if request.Text == "" {
-                       return errors.New("empty message")
-               }
-
-               _, err := l.Submit(terminalSource, request.Text)
-
-               return err
-       case "image":
-               if !filepath.IsAbs(request.Path) {
-                       return errors.New("use /image PATH [caption]")
-               }
-
-               data, err := imageReadFile(request.Path)
-               if err != nil {
-                       return fmt.Errorf("read terminal image: %w", err)
-               }
-
-               name, err := l.agent.Images().Save(data)
-               if err != nil {
-                       return fmt.Errorf("store terminal image: %w", err)
-               }
-
-               _, err = l.Submit(terminalSource, imageText([]string{name}, request.Text))
-               if err != nil {
-                       return fmt.Errorf("submit terminal image: %w", err)
-               }
-
-               return nil
-       case "interrupt":
-               if !l.Interrupt() {
-                       return errors.New("no turn runs")
-               }
-
-               return nil
-       case "whatsapp":
-               whatsapp.Command(request.Text, answer)
-
-               return nil
-       case "stop":
-               found, err := l.StopSubagent(request.Text)
-               if err == nil && !found {
-                       err = fmt.Errorf("no subagent %s runs", request.Text)
-               }
-
-               return err
-       default:
-               return fmt.Errorf("unknown request %q", request.Type)
-       }
-}