diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-10-13 13:34:39 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-10-13 13:34:39 +0800 |
| commit | 67fb8ec01b351c6c9fd2af321166bb92250b1218 (patch) | |
| tree | 4509509ef932e1009dcd2da25928fcff71a5f29b /crates/vcs_actions/src/registry | |
| parent | 860fb317bca61ce66a2c98df933aa666dae0a43f (diff) | |
feat: Implement JSON-based type-erased action invocation
- Add process_json method to ActionPool for type-agnostic calls using JSON serialization
- Extend ActionContext with action_name and action_args fields and setter methods
- Update action_gen macro to use process_json instead of typed process method
- Implement remote action invocation framework in client_registry and action_service
- Add protocol definitions for remote action communication
- Enable flexible action execution without explicit type specifications
Diffstat (limited to 'crates/vcs_actions/src/registry')
| -rw-r--r-- | crates/vcs_actions/src/registry/client_registry.rs | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/crates/vcs_actions/src/registry/client_registry.rs b/crates/vcs_actions/src/registry/client_registry.rs index d298099..56acdad 100644 --- a/crates/vcs_actions/src/registry/client_registry.rs +++ b/crates/vcs_actions/src/registry/client_registry.rs @@ -1,7 +1,10 @@ use action_system::{action::ActionContext, action_pool::ActionPool}; use tcp_connection::error::TcpTargetError; -use crate::actions::local_actions::register_set_upstream_vault_action; +use crate::{ + actions::local_actions::register_set_upstream_vault_action, + connection::protocol::RemoteActionInvoke, +}; fn register_actions(pool: &mut ActionPool) { // Pool register here @@ -22,18 +25,33 @@ pub fn client_action_pool() -> ActionPool { pool } -async fn on_proc_begin(ctx: &ActionContext) -> Result<(), TcpTargetError> { +async fn on_proc_begin(ctx: &mut ActionContext) -> Result<(), TcpTargetError> { + // Is ctx remote + let is_remote = ctx.is_remote(); + + // Action name and arguments + let action_name = ctx.action_name().to_string(); + let action_args_json = ctx.action_args_json().clone(); + // Get instance - let Some(_instance) = ctx.instance() else { + let Some(instance) = ctx.instance_mut() else { return Err(TcpTargetError::Unsupported( "Missing ConnectionInstance in current context, this ActionPool does not support this call" .to_string())); }; // If it's remote, invoke action at server - if ctx.is_remote() { - // instance.write_text(text) + if is_remote { + // Build protocol message + let msg = RemoteActionInvoke { + action_name: action_name, + action_args_json: action_args_json, + }; + + // Send + instance.write_msgpack(msg).await?; } + // Return OK, wait for client to execute Action locally Ok(()) } |
