A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
registry.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
29#ifndef A11_ACTIONS_REGISTRY_H_
30#define A11_ACTIONS_REGISTRY_H_
31
32#include <memory>
33#include <string>
34#include <string_view>
35#include <vector>
36
37#include <absl/base/thread_annotations.h>
38#include <absl/container/flat_hash_map.h>
39#include <absl/status/status.h>
40#include <absl/status/statusor.h>
41
42#include "a11/actions/action.h"
43#include "a11/actions/schema.h"
44#include "a11/data/types.h"
45#include "thread/boost_primitives.h"
46
47namespace a11::actions {
48
49class AuthorizationContextStore;
50
59class ActionRegistry : public std::enable_shared_from_this<ActionRegistry> {
60 public:
73 absl::Status Register(std::string action_name, ActionSchema schema,
74 ActionHandler handler = {});
80 absl::Status RegisterSync(std::string action_name, ActionSchema schema,
81 SyncActionHandler handler);
83 absl::Status Unregister(std::string_view action_name);
85 [[nodiscard]] bool IsRegistered(std::string_view action_name) const;
87 absl::StatusOr<ActionSchema> GetSchema(std::string_view action_name) const;
89 absl::StatusOr<ActionHandler> GetHandler(std::string_view action_name) const;
100 absl::StatusOr<std::shared_ptr<Action>> MakeAction(
101 std::string_view action_name, std::string action_id = {},
102 std::shared_ptr<nodes::NodeMap> node_map = nullptr,
103 std::shared_ptr<net::WireStream> stream = nullptr,
104 std::shared_ptr<service::Session> session = nullptr);
110 absl::StatusOr<data::ActionMessage> MakeActionMessage(
111 std::string_view action_name, std::string action_id = {});
113 [[nodiscard]] std::vector<std::string> ListRegisteredActions() const;
118 std::shared_ptr<ActionRegistry> Copy(bool clear_autofills = true) const;
121 std::shared_ptr<AuthorizationContextStore> contexts);
123 absl::Status ResolveAuthorization(
124 const std::shared_ptr<Action>& action) const;
125
126 private:
127 mutable thread::Mutex mu_;
128 absl::flat_hash_map<std::string, ActionSchema> schemas_ ABSL_GUARDED_BY(mu_);
129 absl::flat_hash_map<std::string, ActionHandler> handlers_
130 ABSL_GUARDED_BY(mu_);
131 std::shared_ptr<AuthorizationContextStore> authorization_contexts_
132 ABSL_GUARDED_BY(mu_);
133};
134
135} // namespace a11::actions
136
137#endif // A11_ACTIONS_REGISTRY_H_
A11's unit of work: the Action and its supporting types.
Schemas describing an action's typed interface and its settings.
std::shared_ptr< service::Session > session
Definition authorization.cc:326
A thread-safe catalogue mapping action names to schema and handler.
Definition registry.h:59
absl::StatusOr< data::ActionMessage > MakeActionMessage(std::string_view action_name, std::string action_id={})
Builds the wire a11::data::ActionMessage for a registered action.
Definition registry.cc:177
std::vector< std::string > ListRegisteredActions() const
Returns the names of all registered actions.
Definition registry.cc:184
absl::Status Unregister(std::string_view action_name)
Removes the registration for action_name.
Definition registry.cc:77
void SetAuthorizationContexts(std::shared_ptr< AuthorizationContextStore > contexts)
Require incoming application actions to resolve installed authorization.
Definition registry.cc:229
absl::Status RegisterSync(std::string action_name, ActionSchema schema, SyncActionHandler handler)
Registers an action with a synchronous handler.
Definition registry.cc:67
absl::StatusOr< std::shared_ptr< Action > > MakeAction(std::string_view action_name, std::string action_id={}, std::shared_ptr< nodes::NodeMap > node_map=nullptr, std::shared_ptr< net::WireStream > stream=nullptr, std::shared_ptr< service::Session > session=nullptr)
Builds a runnable Action for a registered action.
Definition registry.cc:150
std::shared_ptr< ActionRegistry > Copy(bool clear_autofills=true) const
Returns a copy of this registry.
Definition registry.cc:202
absl::Status Register(std::string action_name, ActionSchema schema, ActionHandler handler={})
Registers an action under action_name.
Definition registry.cc:38
bool IsRegistered(std::string_view action_name) const
Whether action_name is registered.
Definition registry.cc:95
absl::StatusOr< ActionSchema > GetSchema(std::string_view action_name) const
Returns the schema for action_name, or NotFound.
Definition registry.cc:106
absl::StatusOr< ActionHandler > GetHandler(std::string_view action_name) const
Returns the handler for action_name, or NotFound.
Definition registry.cc:127
absl::Status ResolveAuthorization(const std::shared_ptr< Action > &action) const
Bind the configured authorization context before an action starts.
Definition registry.cc:235
Definition action.cc:63
std::function< absl::Status(std::shared_ptr< Action >)> SyncActionHandler
Synchronous action handler returning a completion status.
Definition action.h:92
std::function< a11::Task(std::shared_ptr< Action >)> ActionHandler
Asynchronous action handler: runs the action, returns an awaitable.
Definition action.h:90
The full typed interface of an action.
Definition schema.h:138
A11's core wire value types: chunks, node fragments and messages.