]> git.giacomolli.uk - onechat/blobdiff - subagent_run.go
Show the subagents in the clients
[onechat] / subagent_run.go
index 20b15f24dbd4374329ff3cb138912fca9da5b53b..4a88800c3bed065aace3c242510d302a01ea9325 100644 (file)
@@ -19,6 +19,13 @@ const (
        subagentNoteEffort = " at effort "
 )
 
        subagentNoteEffort = " at effort "
 )
 
+// The statuses of the end of a run, in the work event of its report.
+const (
+       subagentFinished = "finished"
+       subagentStopped  = "stopped"
+       subagentFailed   = "failed"
+)
+
 // errSubagentClosed tells that the runs of the subagents ended with the loop.
 var errSubagentClosed = errors.New("the daemon stops, so no subagent starts")
 
 // errSubagentClosed tells that the runs of the subagents ended with the loop.
 var errSubagentClosed = errors.New("the daemon stops, so no subagent starts")
 
@@ -43,7 +50,7 @@ type SubagentRuns struct {
        layout    *ViewLayout
        client    ChainClient
        state     func() string
        layout    *ViewLayout
        client    ChainClient
        state     func() string
-       report    func(text string, stopped bool)
+       report    func(name, text, status string)
        note      func(text string) error
        notify    func(Event)
 
        note      func(text string) error
        notify    func(Event)
 
@@ -302,6 +309,7 @@ func (r *SubagentRuns) run(ctx context.Context, run *SubagentRun) {
 
        var replies []string
        stopped := false
 
        var replies []string
        stopped := false
+       status := subagentFinished
        for more := true; more; {
                reply, err := r.chain(ctx, run)
 
        for more := true; more; {
                reply, err := r.chain(ctx, run)
 
@@ -312,6 +320,7 @@ func (r *SubagentRuns) run(ctx context.Context, run *SubagentRun) {
                        reply = "stopped"
                case err != nil:
                        reply = "failed: " + err.Error()
                        reply = "stopped"
                case err != nil:
                        reply = "failed: " + err.Error()
+                       status = subagentFailed
                }
 
                more = err == nil && ctx.Err() == nil && len(run.pending) > 0
                }
 
                more = err == nil && ctx.Err() == nil && len(run.pending) > 0
@@ -328,7 +337,11 @@ func (r *SubagentRuns) run(ctx context.Context, run *SubagentRun) {
                return
        }
 
                return
        }
 
-       r.report(subagentReport(run.subagent.name, replies), stopped)
+       if stopped {
+               status = subagentStopped
+       }
+
+       r.report(run.subagent.name, subagentReport(run.subagent.name, replies), status)
 }
 
 // chain runs one request chain of run and returns its final answer.
 }
 
 // chain runs one request chain of run and returns its final answer.