wasm_tools_registry (wasm_tools v0.1.0)
View SourceA registry: named tools from several components, in one process you supervise.
This module is internal: you reach it through wasm_tools, and it can change
in any release. The README lists the supported API.
You need one when an application manages several components, or wants a
bound on concurrent calls, or counters, or to expose tools through MCP. For a
single component, call it directly (wasm_tools:call/3).
{ok, Reg} = wasm_tools:start_link(#{max_concurrency => 64}),
{ok, Calc} = wasm_tools:load({file, "calculator.wasm"}),
{ok, [<<"calc_add">>, <<"calc_multiply">>]} =
wasm_tools:add(Reg, Calc, #{namespace => <<"calc">>}),
{ok, 42} = wasm_tools:call(Reg, <<"calc_add">>, #{<<"a">> => 20, <<"b">> => 22}).- Registries are independent: each has its own names, components, counters and bound. There is no global registry.
add/3keeps a holder of its own for the component, so the registry does not depend on the process that loaded it.namespaceprefixes each name withNamespace_;exportspicks which exports become tools (export names or tool names; every callable export by default). Names are computed among the exports picked, so twoopsinterfaces can be added one at a time. A name that collides, inside the selection or with a tool already there, refuses the wholeadd: nothing is renamed or replaced.- A call checks the tool out of the registry (one message), which refuses it
with
#{class := overloaded}pastmax_concurrency, then runs in processes of its own, as any call. Its watchdog checks it back in when it ends. remove/2returns once the names are gone: no call starts on them after it. Calls already running finish, unlessremove/3is givenkill => true.- When the registry stops, every call it started is stopped, and the holders it kept are released.
stats/1reads counters kept with OTPcounters:active,calls,ok,errorsby class,rejected.
Summary
Functions
Add a component's exports as tools. Returns the names given.
A child spec for your supervisor.
Remove tools. With kill => true, calls running on them are stopped.
Start a registry linked to the caller. name registers it locally.
Types
-type opts() :: #{name => atom(), max_concurrency => pos_integer() | infinity, observer => wasm_tools_call:observer()}.
Functions
-spec add(registry(), wasm_tools_component:component(), map()) -> {ok, [binary()]} | {error, map()}.
Add a component's exports as tools. Returns the names given.
-spec child_spec(opts()) -> supervisor:child_spec().
A child spec for your supervisor.
Remove tools. With kill => true, calls running on them are stopped.
Start a registry linked to the caller. name registers it locally.
-spec stop(registry()) -> ok.