Current section

Files

Jump to
aion_flow src aion@awl@runtime.erl
Raw

src/aion@awl@runtime.erl

-module(aion@awl@runtime).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/aion/awl/runtime.gleam").
-export([run/4, index/3]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" The generic run shell and literal-list indexing hoisted out of every\n"
" generated AWL module (AWL-BC-0, hoist-only).\n"
"\n"
" `run` is the engine entry point's body: it reproduces the three-stage\n"
" decode/execute/encode case tree with the exact failure strings the emitter\n"
" used to inline. Each generated module keeps a three-line `run/1` wrapper\n"
" (the engine invokes it by name) that forwards to this function with the\n"
" module's own codecs and `execute`.\n"
).
-file("src/aion/awl/runtime.gleam", 60).
?DOC(
" Encode a typed AWL failure with the fixed `AwlError` codec, the one wire\n"
" shape `aion/awl/error`'s decoder round-trips.\n"
).
-spec encode_error(aion@awl@error:awl_error()) -> binary().
encode_error(Workflow_error) ->
Error_codec = aion@awl@error:codec(),
(erlang:element(2, Error_codec))(Workflow_error).
-file("src/aion/awl/runtime.gleam", 28).
?DOC(
" Decode the raw engine input to a string, decode it with `input_codec`, run\n"
" `execute`, and encode the outcome with `output_codec`. Failure strings are\n"
" byte-identical to the code the emitter used to inline.\n"
"\n"
" A failure is returned as the `AwlError` codec's OWN encoding (the\n"
" `{\"tag\":…}` JSON object), exactly like `workflow.entrypoint` encodes a\n"
" definition's typed error. The engine records that text as the run's\n"
" failure details, and an awaiting parent decodes it back with the same\n"
" `aion/awl/error` codec it already holds — so typed kinds such as\n"
" `AwlVisitsExceeded` survive the parent-child boundary instead of leaking\n"
" the raw error record (whose term-to-JSON image is a *list*, which the\n"
" codec's object decoder can never accept).\n"
).
-spec run(
gleam@dynamic:dynamic_(),
aion@codec:codec(EKZ),
aion@codec:codec(ELB),
fun((EKZ) -> {ok, ELB} | {error, aion@awl@error:awl_error()})
) -> {ok, binary()} | {error, binary()}.
run(Raw_input, Input_codec, Output_codec, Execute) ->
case gleam@dynamic@decode:run(
Raw_input,
{decoder, fun gleam@dynamic@decode:decode_string/1}
) of
{ok, Raw_json} ->
case (erlang:element(3, Input_codec))(Raw_json) of
{ok, Input} ->
case Execute(Input) of
{ok, Result} ->
{ok, (erlang:element(2, Output_codec))(Result)};
{error, Workflow_error} ->
{error, encode_error(Workflow_error)}
end;
{error, {decode_error, Reason, _}} ->
{error,
encode_error(
{awl_decode_input_failed,
<<"failed to decode workflow input: "/utf8,
Reason/binary>>}
)}
end;
{error, _} ->
{error,
encode_error(
{awl_decode_input_failed,
<<"workflow input payload was not a string"/utf8>>}
)}
end.
-file("src/aion/awl/runtime.gleam", 67).
?DOC(
" Literal-only list indexing; out of range is a step failure carrying the\n"
" source-anchored label the emitter built.\n"
).
-spec index(list(ELH), integer(), binary()) -> {ok, ELH} |
{error, aion@awl@error:awl_error()}.
index(Items, Index, Label) ->
case begin
_pipe = gleam@list:drop(Items, Index),
gleam@list:first(_pipe)
end of
{ok, Value} ->
{ok, Value};
{error, _} ->
{error, {awl_index_out_of_range, Label}}
end.