Action Engine
Loading...
Searching...
No Matches
schema.h
Go to the documentation of this file.
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef ACTIONENGINE_ACTIONS_SCHEMA_H_
16#define ACTIONENGINE_ACTIONS_SCHEMA_H_
17
18#include <functional>
19#include <memory>
20#include <string>
21#include <string_view>
22#include <utility>
23#include <vector>
24
25#include <absl/container/flat_hash_map.h>
26#include <absl/status/status.h>
27#include <absl/strings/str_cat.h>
28#include <absl/strings/str_format.h>
29#include <absl/strings/str_join.h>
30
32
33namespace act {
34class Action;
35}
36
47
48namespace act {
49
50using ActionHandler =
51 std::function<absl::Status(const std::shared_ptr<Action>&)>;
52
53// A type for Python and other bindings that cannot use absl::Status
54using VoidActionHandler = std::function<void(const std::shared_ptr<Action>&)>;
55
56using NameAndMimetype = std::pair<std::string, std::string>;
57using NameToMimetype = absl::flat_hash_map<std::string, std::string>;
58
81 [[nodiscard]] ActionMessage GetActionMessage(
82 std::string_view action_id) const;
83
85 std::string name;
86
93 NameToMimetype inputs;
94
101 NameToMimetype outputs;
102};
103
105template <typename Sink>
106void AbslStringify(Sink& sink, const ActionSchema& schema) {
107 std::vector<std::string> input_reprs;
108 input_reprs.reserve(schema.inputs.size());
109 for (const auto& [name, type] : schema.inputs) {
110 input_reprs.push_back(absl::StrCat(name, ":", type));
111 }
112
113 std::vector<std::string> output_reprs;
114 output_reprs.reserve(schema.outputs.size());
115 for (const auto& [name, type] : schema.outputs) {
116 output_reprs.push_back(absl::StrCat(name, ":", type));
117 }
118
119 absl::Format(&sink, "ActionSchema{name: %s, inputs: %s, outputs: %s}",
120 schema.name, absl::StrJoin(input_reprs, ", "),
121 absl::StrJoin(output_reprs, ", "));
122}
123
124} // namespace act
125
126#endif // ACTIONENGINE_ACTIONS_SCHEMA_H_
Definition action.h:63
Definition types.h:232
Definition schema.h:68
NameToMimetype inputs
Definition schema.h:93
std::string name
Definition schema.h:85
NameToMimetype outputs
Definition schema.h:101
ActionMessage GetActionMessage(std::string_view action_id) const
Creates an ActionMessage to create an action instance with the given ID.
Definition schema.cc:23
ActionEngine data structures used to implement actions and nodes (data streams).