# `Alternera.Plugin.Provisional.Calls`
[🔗](https://github.com/10e-ab/alternera-sdk/blob/v0.9.0/alternera_plugin_sdk/lib/alternera/plugin/provisional/calls.ex#L1)

Provisional: added for Script, and a change to it needs a changelog line but
no new major (`docs/USER_PLUGINS_DESIGN.md`). The namespace has nothing to do
with the context's `:provisional?` key.

A step calling a pipeline of its tenant while it runs. `start/1` gives a
handle, or nil where the runner offers none (a Call or For each step, a test,
a preview). `call/3` runs a pipeline on the exchange as the step got it plus
what earlier calls wrote, and gives a new handle. `finish/2` puts the last
handle on the step's extras, and the runner goes on from the exchange the
calls left, with their outcomes nested under the step.

`call/3` must run in the process that runs the step: a plugin that does its
work in a process of its own relays the call back, as `Plugins.Script.Sandbox`
does. A call's time is capped at `time_left_ms`, and a failure the step does
not handle should fail the step with the type `call/3` gave.

The handle is opaque.

# `handle`

```elixir
@opaque handle()
```

# `reply`

```elixir
@type reply() :: %{
  :view =&gt; map(),
  :current =&gt; term(),
  :result =&gt; term(),
  optional(:content_type) =&gt; String.t() | nil
}
```

The exchange after a call: `:view`, the context's view; `:current`, the phase's
message or body as the callee left it; `:result`, the callee's result or nil;
and in a body phase `:content_type`.

# `target`

```elixir
@type target() :: {String.t(), map()}
```

A pipeline's id or name, with the inputs of the call.

# `call`

```elixir
@spec call(handle(), target(), non_neg_integer()) ::
  {{:ok, reply()} | {:error, String.t(), String.t()}, handle()}
```

Calls a pipeline: `{{:ok, reply}, handle}` or `{{:error, type, message}, handle}`.

# `finish`

```elixir
@spec finish(map(), handle()) :: map()
```

`extras` with what the calls left, for the step's result.

# `start`

```elixir
@spec start(map()) :: handle() | nil
```

A handle for the step `context` belongs to, or nil.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
