package stdio import ( "encoding/json" "fmt" "strings" "time" ) // busStateCalls are the method prefixes of the calls a bundle makes on its own bus state through the runtime (novox/hq // ADR 0595 §9, design 25 § 12.5): their shapes and names are package buscalls's, and package busstate the typed way // to make them. var busStateCalls = []string{"mesh/objects.", "mesh/stream.", "mesh/workqueue.", "mesh/ledger."} // BusState asks the runtime one call on this bundle's own bus state, an entry its module asks for in `requires`, named // by its local name in params; the runtime serves it from the module's own bindings only. A method that is none of // those calls is refused here, before the runtime is asked. func BusState(method string, params any) (json.RawMessage, error) { known := false for _, p := range busStateCalls { known = known || strings.HasPrefix(method, p) } if !known { return nil, fmt.Errorf("%s is no call on a bundle's own bus state (%s)", method, strings.Join(busStateCalls, ", ")) } c, err := live() if err != nil { return nil, err } return c.ask(method, params, 60*time.Second) }