A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
runtime.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 The A11 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef A11_FLOW_RUNTIME_H_
18#define A11_FLOW_RUNTIME_H_
19
20#include <cstddef>
21#include <memory>
22#include <string>
23#include <string_view>
24#include <vector>
25
26#include <absl/base/nullability.h>
27#include <absl/status/status.h>
28#include <absl/status/statusor.h>
29
30#include "a11/actions/action.h"
31#include "a11/actions/schema.h"
32#include "a11/flow/graph.h"
33#include "a11/flow/parser.h"
34#include "a11/flow/plan.h"
35#include "a11/flow/resolve.h"
36#include "a11/flow/values.h"
37
38namespace a11::net {
39class WireStream;
40} // namespace a11::net
41
42namespace a11::flow {
43
48inline constexpr size_t kQueueDepth = 8;
49
50// One flow file, compiled: the plans, the graphs, and the tree they borrow. A
51// graph points into the parse tree it was resolved from, so the two have one
52// owner and one lifetime.
60 public:
67 static absl::StatusOr<std::shared_ptr<CompiledProgram>> Compile(
68 std::string source, std::string source_name = {});
69
70 [[nodiscard]] const Program& program() const { return resolved_.program; }
71
72 [[nodiscard]] const std::string& source() const { return source_; }
73
74 [[nodiscard]] const std::string& source_name() const { return source_name_; }
75
76 [[nodiscard]] const std::vector<Diagnostic>& diagnostics() const {
77 return resolved_.diagnostics;
78 }
79
81 [[nodiscard]] const std::vector<ResolvedFlow>& flows() const {
82 return resolved_.flows;
83 }
84
86 [[nodiscard]] const ResolvedFlow* absl_nullable Flow(
87 std::string_view name) const;
88
90 [[nodiscard]] const ResolvedFlow* absl_nullable Entry() const;
91
92 private:
93 CompiledProgram() = default;
94
95 std::string source_;
96 std::string source_name_;
97 ParseResult parsed_;
98 ResolveResult resolved_;
99};
100
105absl::StatusOr<actions::ActionSchema> FlowSchema(const FlowPlan& plan);
106
112 std::shared_ptr<HostBridge> bridge;
113
114 // For a flow a **client** runs over a session it already holds: the `call`
115 // steps that belong to the peer are bound to this stream, and the flow's own
116 // action is not.
125 std::shared_ptr<net::WireStream> dispatch_stream;
126};
127
133absl::StatusOr<actions::ActionHandler> MakeHandler(
134 std::shared_ptr<const CompiledProgram> program, std::string_view flow,
135 RunOptions options = {});
136
144absl::StatusOr<actions::ActionHandler> MakeEntryHandler(
145 std::shared_ptr<const CompiledProgram> program, RunOptions options = {});
146
147} // namespace a11::flow
148
149#endif // A11_FLOW_RUNTIME_H_
A11's unit of work: the Action and its supporting types.
Schemas describing an action's typed interface and its settings.
One flow file, compiled: the plans, the graphs, and the tree they borrow.
Definition runtime.h:59
const std::string & source_name() const
Definition runtime.h:74
const Program & program() const
Definition runtime.h:70
const std::vector< ResolvedFlow > & flows() const
The flows in the order they were declared.
Definition runtime.h:81
const ResolvedFlow *absl_nullable Entry() const
The file's entry point – flow { ... } – or nullptr.
Definition runtime.cc:4241
static absl::StatusOr< std::shared_ptr< CompiledProgram > > Compile(std::string source, std::string source_name={})
Compile source, or fail with the first error the way flow.loads does.
Definition runtime.cc:4207
const ResolvedFlow *absl_nullable Flow(std::string_view name) const
The flow of this name, or nullptr. Never the entry flow.
Definition runtime.cc:4226
const std::string & source() const
Definition runtime.h:72
const std::vector< Diagnostic > & diagnostics() const
Definition runtime.h:76
std::string name
The name and its colon, which travel together because they always do.
Definition format.cc:49
Definition boundary.cc:32
constexpr size_t kQueueDepth
How many values a pipe may run ahead of its reader.
Definition runtime.h:48
absl::StatusOr< actions::ActionHandler > MakeEntryHandler(std::shared_ptr< const CompiledProgram > program, RunOptions options)
The action handler that runs the program's entry flow.
Definition runtime.cc:4348
absl::StatusOr< actions::ActionSchema > FlowSchema(const FlowPlan &plan)
The [actions::ActionSchema] a flow presents.
Definition runtime.cc:4282
absl::StatusOr< actions::ActionHandler > MakeHandler(std::shared_ptr< const CompiledProgram > program, std::string_view flow, RunOptions options)
The action handler that runs one flow of program.
Definition runtime.cc:4309
Definition action.h:65
The flows a file declares, and everything wrong with it.
Definition parser.h:32
Every flow and shape one source file declares.
Definition plan.h:185
A whole file, resolved.
Definition resolve.h:146
Program program
Definition resolve.h:147
std::vector< ResolvedFlow > flows
Definition resolve.h:148
std::vector< Diagnostic > diagnostics
Definition resolve.h:149
One flow, resolved: its plan, its names, and what is wrong with it.
Definition resolve.h:126
What a run needs besides the program.
Definition runtime.h:108
std::shared_ptr< net::WireStream > dispatch_stream
For a flow a client runs over a session it already holds: the call steps that belong to the peer are ...
Definition runtime.h:125
std::shared_ptr< HostBridge > bridge
Who answers the questions only the host can: coercion into a registered type, and reading and writing...
Definition runtime.h:112