T1b verb-timeout-serve: a verb served from a bundle waits the timeout its definition names
Tool gains RunWithin and Within; a bundle's tool call waits `within` where the seat verb it serves names a timeout, else CallTimeout. serveSeats takes the bound of a verb's key beside `chunked`. Builds: design 47 H §760, H-A-43 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -46,6 +46,20 @@ type Tool struct {
|
||||
// Run calls the tool for caller: the bus user the call's subject named, or "" when it named none. A
|
||||
// caller is handed to the bundle in the call's `_meta` (MetaCaller), never among its arguments.
|
||||
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)
|
||||
}
|
||||
|
||||
// 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
|
||||
// within, and a tool that has no RunWithin, are the tool as it is.
|
||||
func (t Tool) Within(within time.Duration) Tool {
|
||||
if within <= 0 || t.RunWithin == nil {
|
||||
return t
|
||||
}
|
||||
run := t.RunWithin
|
||||
t.Run = func(caller string, args json.RawMessage) (json.RawMessage, error) { return run(caller, args, within) }
|
||||
return t
|
||||
}
|
||||
|
||||
// MetaCaller is where in a `tools/call`'s `_meta` the runtime names the caller it took from the subject the
|
||||
@@ -799,13 +813,17 @@ 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: func(caller string, args json.RawMessage) (json.RawMessage, error) {
|
||||
Run: nil, RunWithin: func(caller string, args json.RawMessage, within time.Duration) (json.RawMessage, error) {
|
||||
if len(args) == 0 || string(args) == "null" {
|
||||
args = json.RawMessage("{}")
|
||||
}
|
||||
call, end := mesh.Begin(caller)
|
||||
defer end()
|
||||
res, err := asking("tools/call", callParams(full, caller, call, args), CallTimeout)
|
||||
bound := CallTimeout
|
||||
if within > 0 {
|
||||
bound = within
|
||||
}
|
||||
res, err := asking("tools/call", callParams(full, caller, call, 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).
|
||||
@@ -841,6 +859,9 @@ func Start(module, entry string, env []string, mesh Bus, logf func(string, ...an
|
||||
b, _ := json.Marshal(text)
|
||||
return b, nil
|
||||
}}
|
||||
tool.Run = func(caller string, args json.RawMessage) (json.RawMessage, error) {
|
||||
return tool.RunWithin(caller, args, 0)
|
||||
}
|
||||
if _, seen := groups[under]; !seen {
|
||||
order = append(order, under)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user