Copy the kept call's ask id from its request header into the call's _meta as mesh/ask

Every tool call and seat verb the tool runner serves hands the bundle the ask id the kept call set
in the header x-ask (stdio.AskHeader) under _meta mesh/ask (stdio.MetaAsk), beside mesh/call; a call
whose header carries none names none.

Builds: design 47 H2 §775, H-A-351
This commit is contained in:
2026-11-21 23:14:53 +01:00
parent f7269d9812
commit 2365e41811
9 changed files with 87 additions and 27 deletions
+26 -7
View File
@@ -48,7 +48,19 @@ type Tool struct {
Run func(caller string, args json.RawMessage) (json.RawMessage, error)
// RunWithin is Run that waits within for the bundle's answer, the `timeout` the verb's seat definition names (design 47 H §760,
// H-A-43); zero waits CallTimeout. A tool the runtime serves itself has none: Run is its call.
RunWithin func(caller string, args json.RawMessage, within time.Duration) (json.RawMessage, error)
RunWithin func(caller, ask string, args json.RawMessage, within time.Duration) (json.RawMessage, error)
// within is the wait Within set, which Call hands RunWithin.
within time.Duration
}
// Call runs the tool for caller, handing a bundle the ask id the call carried in its request header (stdio.AskHeader; design 47 H2
// §775, H-A-351), which the runtime names in the call's `_meta` under stdio.MetaAsk; "" when it carried none. A tool the runtime
// serves itself is its Run.
func (t Tool) Call(caller, ask string, args json.RawMessage) (json.RawMessage, error) {
if t.RunWithin == nil {
return t.Run(caller, args)
}
return t.RunWithin(caller, ask, args, t.within)
}
// Within is the tool as called for a verb whose definition names a timeout: its Run waits within for the bundle's answer. A zero
@@ -58,7 +70,10 @@ func (t Tool) Within(within time.Duration) Tool {
return t
}
run := t.RunWithin
t.Run = func(caller string, args json.RawMessage) (json.RawMessage, error) { return run(caller, args, within) }
t.Run = func(caller string, args json.RawMessage) (json.RawMessage, error) {
return run(caller, "", args, within)
}
t.within = within
return t
}
@@ -70,8 +85,9 @@ const MetaCaller = "mesh/caller"
// callParams is a `tools/call`'s params: the tool, its arguments as the caller sent them, and in `_meta`, which the
// runtime writes and no caller can, the caller — only when the subject named one — and the id of the call in flight
// (mesh-sdk buscalls.MetaCall), which a ledger's apply names so the runtime stamps the caller it proved (novox/hq ADR
// 0597 §7).
func callParams(name, caller, call string, args json.RawMessage) map[string]any {
// 0597 §7), and the ask id the call carried in its request header, only when it carried one (stdio.MetaAsk; design 47 H2
// §775, H-A-351).
func callParams(name, caller, call, ask string, args json.RawMessage) map[string]any {
params := map[string]any{"name": name, "arguments": args}
meta := map[string]any{}
if caller != "" {
@@ -80,6 +96,9 @@ func callParams(name, caller, call string, args json.RawMessage) map[string]any
if call != "" {
meta[buscalls.MetaCall] = call
}
if ask != "" {
meta[stdio.MetaAsk] = ask
}
if len(meta) > 0 {
params["_meta"] = meta
}
@@ -813,7 +832,7 @@ func Start(module, entry string, env []string, mesh Bus, logf func(string, ...an
input = json.RawMessage("{}")
}
tool := Tool{Name: name, Description: t.Description, Input: input,
Run: nil, RunWithin: func(caller string, args json.RawMessage, within time.Duration) (json.RawMessage, error) {
Run: nil, RunWithin: func(caller, ask string, args json.RawMessage, within time.Duration) (json.RawMessage, error) {
if len(args) == 0 || string(args) == "null" {
args = json.RawMessage("{}")
}
@@ -823,7 +842,7 @@ func Start(module, entry string, env []string, mesh Bus, logf func(string, ...an
if within > 0 {
bound = within
}
res, err := asking("tools/call", callParams(full, caller, call, args), bound)
res, err := asking("tools/call", callParams(full, caller, call, ask, args), bound)
if err != nil {
if errors.Is(err, errNoAnswer) {
// Its caller is gone by now and nobody else would hear of it (issue 1966).
@@ -860,7 +879,7 @@ func Start(module, entry string, env []string, mesh Bus, logf func(string, ...an
return b, nil
}}
tool.Run = func(caller string, args json.RawMessage) (json.RawMessage, error) {
return tool.RunWithin(caller, args, 0)
return tool.RunWithin(caller, "", args, 0)
}
if _, seen := groups[under]; !seen {
order = append(order, under)