45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package console
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"strings"
|
|
|
|
"git.novox.be/novox/mesh-delivery/sdk/views"
|
|
)
|
|
|
|
// FirstViewer is the tool runner's four first views as the console shows them (novox/hq ADR 0615 §6; issue 1966 TLS-6): a
|
|
// Source that also is one is asked by mesh_first_views and mesh_first_view_again.
|
|
type FirstViewer interface {
|
|
Status() []views.Status
|
|
Again(ctx context.Context, why string) []error
|
|
}
|
|
|
|
// firstViewsAnswer is mesh_first_views and mesh_first_view_again.
|
|
func (s *Surface) firstViewsAnswer(ctx context.Context, name string, args map[string]any) map[string]any {
|
|
fv, ok := s.src.(FirstViewer)
|
|
if !ok {
|
|
return failure("this tool runner holds no first views: it reads the indexer's and the assigner's states through " +
|
|
"another source")
|
|
}
|
|
if name == verbFirstViews {
|
|
return answerText(map[string]any{"first views": fv.Status()})
|
|
}
|
|
why, _ := args["why"].(string)
|
|
if why = strings.TrimSpace(why); why == "" {
|
|
why = "asked by hand with no reason given"
|
|
}
|
|
// A hand act, recorded in the runner's log with who asked and why (novox/hq ADR 0615 §6).
|
|
log.Printf("[mesh-tools] hand act: %s asked the four first views again: %s", s.who, why)
|
|
out := map[string]any{"asked again": why}
|
|
if errs := fv.Again(ctx, why); len(errs) > 0 {
|
|
var msgs []string
|
|
for _, e := range errs {
|
|
msgs = append(msgs, e.Error())
|
|
}
|
|
out["not answered"] = msgs
|
|
}
|
|
out["first views"] = fv.Status()
|
|
return answerText(out)
|
|
}
|