| @@ -193,14 +193,22 @@ | ||
| 193 | 193 | 'methods' => WP_REST_Server::CREATABLE, |
| 194 | 194 | 'permission_callback' => 'openstation_agents_rest_invoke_permission', |
| 195 | 195 | 'callback' => 'openstation_agents_rest_invoke', |
| 196 | 196 | 'args' => array( |
| 197 | - 'message' => array( | |
| 197 | + 'async' => array( | |
| 198 | + 'type' => 'boolean', | |
| 199 | + 'default' => false, | |
| 200 | + ), | |
| 201 | + 'requestId' => array( | |
| 202 | + 'type' => 'string', | |
| 203 | + 'format' => 'uuid', | |
| 204 | + ), | |
| 205 | + 'message' => array( | |
| 198 | 206 | 'type' => 'string', |
| 199 | 207 | 'required' => true, |
| 200 | 208 | 'sanitize_callback' => 'sanitize_textarea_field', |
| 201 | 209 | ), |
| 202 | - 'source' => array( | |
| 210 | + 'source' => array( | |
| 203 | 211 | 'type' => 'string', |
| 204 | 212 | 'default' => 'chat', |
| 205 | 213 | 'enum' => array( 'chat', 'drag', 'send-to' ), |
| 206 | 214 | 'sanitize_callback' => 'sanitize_key', |
| @@ -208,9 +216,9 @@ | ||
| 208 | 216 | // Prior conversation turns, oldest first. Without these |
| 209 | 217 | // every message is a contextless run — a follow-up like |
| 210 | 218 | // "yes, do it" would be resolved against nothing and the |
| 211 | 219 | // agent could act on the wrong entity entirely. |
| 212 | - 'history' => array( | |
| 220 | + 'history' => array( | |
| 213 | 221 | 'type' => 'array', |
| 214 | 222 | 'default' => array(), |
| 215 | 223 | 'items' => array( |
| 216 | 224 | 'type' => 'object', |
| @@ -479,8 +487,12 @@ | ||
| 479 | 487 | 'openstation_agents_forbidden', |
| 480 | 488 | __( 'You do not have permission to invoke this agent.', 'desktop-mode' ), |
| 481 | 489 | array( 'status' => rest_authorization_required_code() ) |
| 482 | 490 | ); |
| 491 | + } | |
| 492 | + | |
| 493 | + if ( $request['async'] ) { | |
| 494 | + return openstation_agents_rest_enqueue_job( $request ); | |
| 483 | 495 | } |
| 484 | 496 | |
| 485 | 497 | $result = openstation_agent_invoke( |
| 486 | 498 | (int) $user->ID, |