director — Cross-feature transition coordinator
Director
Director
Coordinator of transitions between features (scenes).
The Director is instantiated per incoming request (request-scoped) to capture abstract session and context identifiers. It facilitates the "Stateful Navigation, Stateless Logic" pattern.
Attributes:
| Name | Type | Description |
|---|---|---|
REDIRECT_KEY |
Primary metadata key for-driven navigation. |
|
MAX_REDIRECTS |
int
|
Maximum number of allowed redirects (loop prevention). |
Source code in src/codex_bot/director/director.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
Functions
resolve(data)
async
Analyze incoming data for navigation instructions and resolve redirects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Incoming request payload. |
required |
Returns:
| Type | Description |
|---|---|
UnifiedViewDTO | Any
|
A |
Source code in src/codex_bot/director/director.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
set_scene(feature, payload=None)
async
Execute a cross-feature transition with Guard checks and Auto-Wrapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
str
|
Identifier of the target feature. |
required |
payload
|
Any
|
Ephemeral data for the transition. |
None
|
Source code in src/codex_bot/director/director.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
Protocols
OrchestratorProtocol
Bases: Protocol
Structural protocol for stateless feature orchestrators.
Orchestrators complying with this protocol must be stateless singletons.
They are responsible for transforming incoming payloads into UI responses
using the provided Director context.
Source code in src/codex_bot/director/protocols.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
Functions
handle_entry(director, payload=None)
async
Entry point into the feature.
Source code in src/codex_bot/director/protocols.py
79 80 81 82 83 84 85 | |
render(director, payload=None)
async
Renders content for the passed payload.
Source code in src/codex_bot/director/protocols.py
75 76 77 | |
ContainerProtocol
Bases: Protocol
Minimum contract for the project's DI container.
The Director only requires the features attribute — a dictionary of orchestrators.
The specific BotContainer of the project must provide this attribute.
Attributes:
| Name | Type | Description |
|---|---|---|
features |
dict[str, OrchestratorProtocol]
|
Dictionary of |
Example
class BotContainer:
def __init__(self):
self.features: dict[str, Any] = {}
Source code in src/codex_bot/director/protocols.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
Attributes
transition_guards
property
Sequence of guards to run before any feature transition.
SceneConfig
Bases: NamedTuple
Configuration schema for feature entry points.
Defines the mapping between a logical feature key and its associated Telegram FSM state. Used to drive the orchestration logic in the Director.
Attributes:
| Name | Type | Description |
|---|---|---|
fsm_state |
State
|
The |
entry_service |
str
|
The lookup key for the orchestrator in the DI registry. |
Example
SCENE_ROUTES = {
"main": SceneConfig(fsm_state=Menu.main, entry_service="main_menu")
}
Source code in src/codex_bot/director/protocols.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |