package main import ( "errors" "fmt" "strings" "time" "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" stdio "git.novox.be/novox/mesh-sdk/go" "mesh-delivery-builder/internal/build" "mesh-delivery-builder/internal/versions" ) // reservedTools are builder_reserved and builder_reserved_drop (design 47 G section 369), served as tools of the bundle. The drop is a hand act: it is recorded in the hand-act log first, then written to // reasks for the builder, which owns the reservations, to answer. // // The seat's verb reserved is the builder's process's (design 47 G A-115, A-127), not the bundle's. func reservedTools(rr versions.Reader, ask queueAsker, now func() time.Time, acts meshhandactsclient.Recorder) []stdio.Tool { str := func(args map[string]any, k string) string { s, _ := args[k].(string); return strings.TrimSpace(s) } return []stdio.Tool{ {Name: versions.ReservedTool, Description: versions.ReservedDescription, Input: map[string]any{"type": "object", "properties": map[string]any{ "module": map[string]any{"type": "string", "description": "only this module's reservations"}}}, Run: func(args map[string]any) (any, error) { return versions.AnswerReserved(rr, str(args, "module")) }}, {Name: versions.ReservedDropTool, Description: versions.ReservedDropDescription, Input: map[string]any{"type": "object", "required": []string{"module", "series", "why"}, "properties": map[string]any{ "module": map[string]any{"type": "string", "description": "the module"}, "series": map[string]any{"type": "string", "description": "its MAJOR.MINOR"}, "why": map[string]any{"type": "string", "description": "why, in plain words"}}}, Run: func(args map[string]any) (any, error) { key, value, err := build.NewReservedDrop(str(args, "module"), str(args, "series"), str(args, "why"), stdio.CallerOf(args), now()) if err != nil { return nil, err } if _, err := acts.Record(meshhandactsclient.Request{What: fmt.Sprintf("dropped the reservation of %s %s by hand", str(args, "module"), str(args, "series")), Why: str(args, "why"), Cause: versions.ReservedDropTool, Verb: "reserved-drop"}); err != nil { return nil, fmt.Errorf("the hand act was not recorded through mesh-hand-acts, so nothing was dropped: %w", err) } raw, err := ask(key, value) if err != nil { return nil, err } a, err := build.DecodeReAsk(raw) if err != nil { return nil, err } if a.Refused { return nil, errors.New(a.Answer) } return map[string]any{"key": key, "answer": a.Answer}, nil }}, } }