Reads model output written in Express: conversational text with
Express blocks between <a2ui> and </a2ui> tags.
{:ok, parser} = A2UIAgent.Express.Parser.new(catalogs, surface_id: "main")
{:ok, parts} =
A2UIAgent.Express.Parser.parse_response(parser, """
Here it is.
<a2ui>
root = Text("Hello")
</a2ui>
""")
parts
#=> [{:text, "Here it is."}, {:a2ui, [%{"version" => "v1.0", "createSurface" => ...}]}]Blocks are found with A2UIAgent.BlockLexer (a closing tag inside a
string or comment does not close a block) and compiled with
A2UIAgent.Express.Compiler. Express is not read incrementally: a
response is parsed once it is complete.
Parts are {:text, text} and {:a2ui, messages}. unwrap/1 returns
raw parts, {:text, text} and {:a2ui_raw, block, final?}.
Summary
Functions
Compiles one block (see A2UIAgent.Express.Compiler.compile/3). With
final: false, the statements before the block's first syntax error
compile.
Writes messages back as Express; see A2UIAgent.Express.Decompiler.decompile/3
for the options.
Whether content holds an <a2ui> block; with complete: true, a
block whose closing tag has arrived.
Creates a parser for catalogs. Options: :surface_id, the surface
of statements before any surface line (default "main"), and
:version, the protocol version to write (default: the catalogs').
Parses a complete model response into parts.
Express is read once a response is complete, never chunk by chunk.
Splits model output into text and raw Express blocks.
Writes parts out as model output, joined by newlines: text as it is, each block between tags.
Encloses decompiled blocks in one pair of tags.
Types
A part of a parsed response.
@type t() :: %A2UIAgent.Express.Parser{ catalogs: A2UIAgent.Express.Catalogs.t(), surface_id: String.t() }
Functions
@spec compile(t(), String.t(), keyword()) :: {:ok, [map()]} | {:error, A2UICore.Error.t()}
Compiles one block (see A2UIAgent.Express.Compiler.compile/3). With
final: false, the statements before the block's first syntax error
compile.
@spec decompile(t(), [map()] | map(), keyword()) :: {:ok, String.t()} | {:error, A2UICore.Error.t()}
Writes messages back as Express; see A2UIAgent.Express.Decompiler.decompile/3
for the options.
Whether content holds an <a2ui> block; with complete: true, a
block whose closing tag has arrived.
@spec new([A2UICore.Catalog.t()], keyword()) :: {:ok, t()} | {:error, A2UICore.Error.t()}
Creates a parser for catalogs. Options: :surface_id, the surface
of statements before any surface line (default "main"), and
:version, the protocol version to write (default: the catalogs').
@spec parse_response(t(), String.t(), keyword()) :: {:ok, [part()]} | {:error, A2UICore.Error.t()}
Parses a complete model response into parts.
With wrapped: false the whole response is one block. Otherwise each
block is compiled in turn (a block whose closing tag never came as not
final) and the first failure is returned.
@spec supports_streaming?() :: false
Express is read once a response is complete, never chunk by chunk.
@spec unwrap(String.t()) :: [A2UIAgent.BlockLexer.raw_part()]
Splits model output into text and raw Express blocks.
@spec wrap([A2UIAgent.BlockLexer.raw_part() | {:a2ui_raw, String.t()}]) :: String.t()
Writes parts out as model output, joined by newlines: text as it is, each block between tags.
Encloses decompiled blocks in one pair of tags.