The seat mesh-wants' definition gains the state asks (template state, history 5, view), its key forms the seven kinds' keys as the assigner's asks package writes them (hold, restore, backup, record, outside, revert, assignments) and its value the ask as the assigner composes it; its wants gains view. The assigner's first-view tool asks replaces assigner_read_asks, its callers the teller and the status view; the status view joins the callers of wants and assignments. The teller follows the asks by seat:mesh-wants.views.asks and invokes nothing of the assigner's. The status view's part waits on a question (its tools ask assigner_read_wants). Builds: design 47 G §717, A-299 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
101 lines
4.5 KiB
Go
101 lines
4.5 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
|
|
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-teller/tellerevents"
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
|
|
"mesh-delivery-assigner/internal/assign"
|
|
"mesh-delivery-assigner/internal/buckets"
|
|
"mesh-delivery-assigner/internal/puts"
|
|
)
|
|
|
|
// askAgainTool asks one of the assigner's asks again by hand (issue 1966, ADR 0668 §5): the recovery of an ask that ended at
|
|
// the operator channel without an answer when the event that would have asked it again was not heard.
|
|
const askAgainTool = "assigner_ask_again"
|
|
|
|
// asksState and answersState are the assigner's asks and the teller's answers, as the runtime names them.
|
|
const (
|
|
asksState = "asks"
|
|
answersState = buckets.TellerModule + ".answers"
|
|
)
|
|
|
|
// askAgainByHand writes the ask at key again under a new asking, by the rules the teller's ask-ended writes it by (assign.AskedAgain:
|
|
// a proposal's authorising ask and a put's record ask are not), so the teller asks it again; an asking the operator answered
|
|
// is refused, naming the answer. The act is recorded through the seat mesh-hand-acts.
|
|
func askAgainByHand(st store, ask func(string, any) (json.RawMessage, error), key, why, by string, now time.Time) (any, error) {
|
|
switch {
|
|
case key == "":
|
|
return nil, errors.New("name the ask's key, as the tool asks lists it")
|
|
case why == "":
|
|
return nil, errors.New("a hand ask again says why")
|
|
case by == "" || by == stdio.Unproven:
|
|
return nil, errors.New("a hand ask again names who asks it, and the runtime proved no caller")
|
|
}
|
|
current, _, found, err := st.get(asksState, key)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if !found {
|
|
return nil, fmt.Errorf("the assigner holds no ask under %s: the tool asks lists them", key)
|
|
}
|
|
_, routerAsk, err := assign.DecodeAsk(key, current)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if raw, _, found, err := st.get(answersState, key); err == nil && found {
|
|
if a, err := meshdeliveryclient.DecodeAnswer(raw); err == nil && strings.HasPrefix(a.Warrant, routerAsk.ID+"@") {
|
|
return nil, fmt.Errorf("the asking %s was answered %q (%s): it is not asked again", routerAsk.ID, a.Option, a.Words)
|
|
}
|
|
}
|
|
var put *puts.Put
|
|
if k, err := asks.ParseAnyAskKey(key); err == nil && k.Kind == asks.AskKindRecord {
|
|
if pkey, err := puts.Key(k.Node, k.Module); err == nil {
|
|
if raw, _, found, err := st.get(putsState, pkey); err == nil && found {
|
|
if p, err := puts.Decode(raw); err == nil {
|
|
put = &p
|
|
}
|
|
}
|
|
}
|
|
}
|
|
value, refused := assign.AskedAgain(tellerevents.Ended{Key: key, Ask: routerAsk.ID, Outcome: occ.OutcomeCancelled}, current, put, now)
|
|
if refused != "" {
|
|
return nil, errors.New(refused)
|
|
}
|
|
if err := st.put(asksState, key, value); err != nil {
|
|
return nil, fmt.Errorf("the ask %s is not written again: %w", key, err)
|
|
}
|
|
_, next, _ := assign.DecodeAsk(key, value)
|
|
taken, rerr := meshhandactsclient.Recorder{Ask: ask}.Record(meshhandactsclient.Request{What: askAgainTool + " " + key, Why: why + " (" + by + ")", Cause: "ask-again"})
|
|
recorded := taken.Log
|
|
if rerr != nil {
|
|
recorded = "not recorded: " + rerr.Error()
|
|
}
|
|
return map[string]any{"key": key, "ended": routerAsk.ID, "asked": next.ID, "by": by, "hand-act": recorded}, nil
|
|
}
|
|
|
|
// askAgainTools is the tool over the runtime's states.
|
|
func askAgainTools(st store, ask func(string, any) (json.RawMessage, error), now func() time.Time) []stdio.Tool {
|
|
return []stdio.Tool{{Name: askAgainTool, Description: "Ask one of the assigner's asks of the operator again (issue 1966): the ask " +
|
|
"under key is written again under a new asking, which the teller asks on the operator channel, as when the channel says it " +
|
|
"ended without an answer. Refused for an asking the operator answered, a proposal's authorising ask (the seat's verb again " +
|
|
"asks it) and a record ask a put asked. Recorded as a hand act.",
|
|
Input: schema(map[string]string{"key": "the ask's key, as the tool asks lists it", "why": "why it is asked again"},
|
|
[]string{"key", "why"}),
|
|
Run: func(a map[string]any) (any, error) {
|
|
key, _ := a["key"].(string)
|
|
why, _ := a["why"].(string)
|
|
return askAgainByHand(st, ask, key, why, stdio.CallerOf(a), now())
|
|
}}}
|
|
}
|