Keep a machine's discovery answer under the bus's message limit
Every tool's schema in one $SRV.INFO reply outgrew max_payload on machines serving 137-206 tools, and the refused reply was dropped silently, so search and a machine's view went empty. Module tools now announce without schema; describe and tools/list ask the module for it. An answer still too large has its descriptions cut to a line, and a failed reply is logged.
This commit is contained in:
@@ -125,7 +125,15 @@ func (s *Surface) Handle(r Request) *Reply {
|
||||
return refuse(r.ID, -32603, "the mesh's discovery failed: "+err.Error())
|
||||
}
|
||||
tools := make([]map[string]any, 0, len(l.Tools))
|
||||
for _, t := range l.Tools {
|
||||
inputs := map[string]map[string]json.RawMessage{} // module → tool → input, asked once per module
|
||||
for i, t := range l.Tools {
|
||||
if !t.Seat && len(t.Input) == 0 {
|
||||
if inputs[t.Module] == nil {
|
||||
inputs[t.Module] = toolInputs(s.conn, t.Module)
|
||||
}
|
||||
l.Tools[i].Input = inputs[t.Module][t.Name]
|
||||
t = l.Tools[i]
|
||||
}
|
||||
var schema map[string]any
|
||||
switch {
|
||||
case t.Seat && t.Scope != "node":
|
||||
@@ -295,3 +303,24 @@ func (s *Surface) instructions() string {
|
||||
"arguments; mesh_call calls it. " + grammar + " What may be called was fixed when this account " +
|
||||
"was issued, so a refusal means the account, not the tool."
|
||||
}
|
||||
|
||||
// toolInputs is every tool's input schema of one module, asked of a runtime that serves it.
|
||||
func toolInputs(conn *bus.Conn, module string) map[string]json.RawMessage {
|
||||
out := map[string]json.RawMessage{}
|
||||
got, err := conn.Ask(module+".tools", map[string]any{}, "")
|
||||
if err != nil {
|
||||
return out
|
||||
}
|
||||
var answer struct {
|
||||
Tools []struct {
|
||||
Name string `json:"name"`
|
||||
Input json.RawMessage `json:"input"`
|
||||
} `json:"tools"`
|
||||
}
|
||||
if json.Unmarshal(got.Result, &answer) == nil {
|
||||
for _, t := range answer.Tools {
|
||||
out[t.Name] = t.Input
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user