3232
3333logger = logging .getLogger (__name__ )
3434
35- T = TypeVar ('T' )
35+ T = TypeVar ("T" )
3636
3737
3838class PluginExecutor (Generic [T ]):
3939 """Executes a list of plugins."""
40+
4041 async def execute (
4142 self ,
4243 plugins : list [PluginRef ],
@@ -45,15 +46,15 @@ async def execute(
4546 plugin_run : Callable [[PluginRef , T , PluginContext ], Coroutine [Any , Any , PluginResult [T ]]],
4647 compare : Callable [[T , list [PluginCondition ], GlobalContext ], bool ],
4748 local_contexts : Optional [PluginContextTable ] = None ,
48- ) -> tuple [PluginResult [T ] | None , PluginContextTable | None ]:
49+ ) -> tuple [PluginResult [T ], PluginContextTable | None ]:
4950 """Execute a plugins hook run before a prompt is retrieved and rendered.
5051
5152 Args:
5253 plugins: the list of plugins to execute.
5354 payload: the payload to be analyzed.
5455 global_context: contextual information for all plugins.
5556 plugin_run: async function for executing plugin hook.
56- compare: function for comparing conditional information with context and payload
57+ compare: function for comparing conditional information with context and payload.
5758 local_contexts: context local to a single plugin.
5859
5960 Returns:
@@ -85,11 +86,11 @@ async def execute(
8586 if not result .continue_processing :
8687 # Check execution mode
8788 if pluginref .plugin .mode == PluginMode .ENFORCE :
88- return (PluginResult [T ](continue_processing = False , modified_payload = current_payload , error = result .error , metadata = combined_metadata ), None )
89+ return (PluginResult [T ](continue_processing = False , modified_payload = current_payload , violation = result .violation , metadata = combined_metadata ), None )
8990 elif pluginref .plugin .mode == PluginMode .PERMISSIVE :
90- logger .warning (f"Plugin { pluginref .plugin .name } would block (permissive mode): { result .error } " )
91+ logger .warning (f"Plugin { pluginref .plugin .name } would block (permissive mode): { result .violation . description if result . violation else '' } " )
9192
92- return (PluginResult [T ](continue_processing = True , modified_payload = current_payload , error = None , metadata = combined_metadata ), res_local_contexts )
93+ return (PluginResult [T ](continue_processing = True , modified_payload = current_payload , violation = None , metadata = combined_metadata ), res_local_contexts )
9394
9495
9596async def pre_prompt_fetch (plugin : PluginRef , payload : PromptPrehookPayload , context : PluginContext ) -> PromptPrehookResult :
@@ -176,7 +177,7 @@ async def initialize(self) -> None:
176177 """
177178 if self ._initialized :
178179 return
179-
180+
180181 plugins = self ._config .plugins if self ._config else []
181182
182183 for plugin_config in plugins :
@@ -204,7 +205,7 @@ async def prompt_pre_fetch(
204205 payload : PromptPrehookPayload ,
205206 global_context : GlobalContext ,
206207 local_contexts : Optional [PluginContextTable ] = None ,
207- ) -> tuple [PromptPrehookResult | None , PluginContextTable | None ]:
208+ ) -> tuple [PromptPrehookResult , PluginContextTable | None ]:
208209 """Plugin hook run before a prompt is retrieved and rendered.
209210
210211 Args:
@@ -218,11 +219,9 @@ async def prompt_pre_fetch(
218219 plugins = self ._registry .get_plugins_for_hook (HookType .PROMPT_PRE_FETCH )
219220 return await self ._pre_prompt_executor .execute (plugins , payload , global_context , pre_prompt_fetch , pre_prompt_matches , local_contexts )
220221
221-
222-
223222 async def prompt_post_fetch (
224223 self , payload : PromptPosthookPayload , global_context : GlobalContext , local_contexts : Optional [PluginContextTable ] = None
225- ) -> tuple [PromptPosthookResult | None , PluginContextTable | None ]:
224+ ) -> tuple [PromptPosthookResult , PluginContextTable | None ]:
226225 """Plugin hook run after a prompt is rendered.
227226
228227 Args:
0 commit comments