| @@ -171,9 +171,9 @@ | ||
| 171 | 171 | * |
| 172 | 172 | * @return mixed The result of the snippet execution. |
| 173 | 173 | * @throws Exception If the snippet cannot be executed. |
| 174 | 174 | */ |
| 175 | - public function executeSnippet( $id, $args = [], $reply = null ) { | |
| 175 | + public function executeSnippet( $id, $args = [] ) { | |
| 176 | 176 | try { |
| 177 | 177 | if ( empty( $id ) ) { |
| 178 | 178 | throw new Exception( 'The snippet ID is required.' ); |
| 179 | 179 | } |
| @@ -186,34 +186,9 @@ | ||
| 186 | 186 | $snippet = $this->snippet_module->get_function( $id ); |
| 187 | 187 | if ( empty( $snippet ) ) { |
| 188 | 188 | throw new Exception( sprintf( 'Snippet with ID %d not found.', $id ) ); |
| 189 | 189 | } |
| 190 | - | |
| 191 | - $query = $reply ? $reply->query : null; | |
| 192 | - $array_query = []; | |
| 193 | - if( $query ) { | |
| 194 | - $array_query['envId'] = $query->envId ?? 'No EnvId in Query'; | |
| 195 | - $array_query['botId'] = $query->botId ?? 'No BotId in Query'; | |
| 196 | - $array_query['customId'] = $query->customId ?? 'No CustomId in Query'; | |
| 197 | - $array_query['embeddingsEnvId'] = $query->embeddingsEnvId ?? 'No EmbeddingsEnvId in Query'; | |
| 198 | - | |
| 199 | - | |
| 200 | - $array_query['chatId'] = $query->chatId ?? 'No ChatId in Query'; | |
| 201 | - $array_query['session'] = $query->session ?? 'No Session in Query'; | |
| 202 | - $array_query['scope'] = $query->scope ?? 'No Scope in Query'; | |
| 203 | - | |
| 204 | - $array_query['instructions'] = $query->instructions ?? 'No Instructions in Query'; | |
| 205 | - $array_query['context'] = $query->context ?? 'No Context in Query'; | |
| 206 | - | |
| 207 | - $array_query['messages'] = $query->messages ? json_encode( $query->messages ) : 'No Messages in Query'; | |
| 208 | - $array_query['message'] = $query->message ?? 'No Message in Query'; | |
| 209 | - | |
| 210 | - $array_query['model'] = $query->model ?? 'No Model in Query'; | |
| 211 | - $array_query['feature'] = $query->feature ?? 'No Feature in Query'; | |
| 212 | - } | |
| 213 | - | |
| 214 | - $args['__mwai_query'] = $array_query; | |
| 215 | - | |
| 190 | + | |
| 216 | 191 | $output = $this->core->run_snippet( $id, $args ); |
| 217 | 192 | |
| 218 | 193 | if ( $this->debug ) { |
| 219 | 194 | $shortOutput = is_string( $output ) ? substr( $output, 0, 100 ) : json_encode( $output ); |
| @@ -241,20 +216,8 @@ | ||
| 241 | 216 | * |
| 242 | 217 | * @return mixed The result of the snippet execution. |
| 243 | 218 | * @throws Exception If the snippet cannot be executed. |
| 244 | 219 | */ |
| 245 | - /** | |
| 246 | - * Declare every active PHP function snippet in the current request so they can call | |
| 247 | - * one another, without executing any of them. Idempotent and cheap (runs once per | |
| 248 | - * request). executeSnippet()/executeSnippetByName() already call this internally, so | |
| 249 | - * you only need it to make function snippets callable from your own custom PHP. | |
| 250 | - * | |
| 251 | - * @return void | |
| 252 | - */ | |
| 253 | - public function loadFunctions() { | |
| 254 | - $this->core->define_all_functions(); | |
| 255 | - } | |
| 256 | - | |
| 257 | 220 | public function executeSnippetByName( $name, $args = [] ) { |
| 258 | 221 | try { |
| 259 | 222 | if ( empty( $name ) ) { |
| 260 | 223 | throw new Exception( 'The snippet name is required.' ); |
| @@ -287,9 +250,9 @@ | ||
| 287 | 250 | * Create a new snippet. |
| 288 | 251 | * |
| 289 | 252 | * @param string $name Name of the snippet. |
| 290 | 253 | * @param string $code Code of the snippet. |
| 291 | - * @param string $scope Scope of the snippet: 'function', 'backend', 'frontend', 'scheduled', 'persistent', 'content_php', 'content_js'. | |
| 254 | + * @param string $scope Scope of the snippet: 'function', 'backend', 'frontend', 'scheduled', 'persistent'. | |
| 292 | 255 | * @param array $options Additional options: |
| 293 | 256 | * - target: 'php' or 'js' (for function snippets) |
| 294 | 257 | * - description: Description of the snippet |
| 295 | 258 | * - args: Arguments for function snippets |
| @@ -294,9 +257,8 @@ | ||
| 294 | 257 | * - description: Description of the snippet |
| 295 | 258 | * - args: Arguments for function snippets |
| 296 | 259 | * - argsData: Argument data for function snippets (use 'description' for each argument's description) |
| 297 | 260 | * - behavior: 'dynamic' or 'static' (for function snippets) |
| 298 | - * - mcp: Expose this function as its own MCP tool in AI Engine (for function snippets) | |
| 299 | 261 | * - tags: Array of tags |
| 300 | 262 | * - priority: Execution priority |
| 301 | 263 | * - active: Active status (true/false) |
| 302 | 264 | * - endpoint: REST endpoint |
| @@ -317,13 +279,13 @@ | ||
| 317 | 279 | if ( empty( $code ) ) { |
| 318 | 280 | throw new Exception( 'The snippet code is required.' ); |
| 319 | 281 | } |
| 320 | 282 | |
| 321 | - $validScopes = ['function', 'backend', 'frontend', 'scheduled', 'persistent', 'content_php', 'content_js']; | |
| 283 | + $validScopes = ['function', 'backend', 'frontend', 'scheduled', 'persistent']; | |
| 322 | 284 | if ( !in_array( $scope, $validScopes ) ) { |
| 323 | 285 | throw new Exception( sprintf( 'Invalid scope. Must be one of: %s', implode( ', ', $validScopes ) ) ); |
| 324 | 286 | } |
| 325 | - | |
| 287 | + | |
| 326 | 288 | // Extract options with defaults |
| 327 | 289 | $target = $options['target'] ?? 'php'; |
| 328 | 290 | $description = $options['description'] ?? ''; |
| 329 | 291 | $args = $options['args'] ?? []; |
| @@ -328,9 +290,8 @@ | ||
| 328 | 290 | $description = $options['description'] ?? ''; |
| 329 | 291 | $args = $options['args'] ?? []; |
| 330 | 292 | $argsData = $options['argsData'] ?? []; |
| 331 | 293 | $behavior = $options['behavior'] ?? 'dynamic'; |
| 332 | - $mcp = $options['mcp'] ?? false; | |
| 333 | 294 | $tags = $options['tags'] ?? ['api']; |
| 334 | 295 | $priority = $options['priority'] ?? 10; |
| 335 | 296 | $active = $options['active'] ?? true; |
| 336 | 297 | $endpoint = $options['endpoint'] ?? ''; |
| @@ -374,9 +335,8 @@ | ||
| 374 | 335 | $params['functionTarget'] = $target; |
| 375 | 336 | $params['functionArgs'] = $args; |
| 376 | 337 | $params['functionArgsDict'] = $argsData; |
| 377 | 338 | $params['functionBehavior'] = $behavior; |
| 378 | - $params['functionMcp'] = $mcp; | |
| 379 | 339 | } |
| 380 | 340 | |
| 381 | 341 | // Add scheduled-specific params |
| 382 | 342 | if ( $scope === 'scheduled' ) { |
| @@ -418,9 +378,8 @@ | ||
| 418 | 378 | * - target: 'php' or 'js' (for function snippets) |
| 419 | 379 | * - args: Arguments (for function snippets) |
| 420 | 380 | * - argsData: Argument data (for function snippets) |
| 421 | 381 | * - behavior: 'dynamic' or 'static' (for function snippets) |
| 422 | - * - mcp: Expose this function as its own MCP tool in AI Engine (for function snippets) | |
| 423 | 382 | * - intervalHours: Hours (for scheduled snippets) |
| 424 | 383 | * - intervalMinutes: Minutes (for scheduled snippets) |
| 425 | 384 | * |
| 426 | 385 | * @return array The updated snippet data. |
| @@ -443,9 +402,9 @@ | ||
| 443 | 402 | } |
| 444 | 403 | |
| 445 | 404 | // Validate scope if provided |
| 446 | 405 | if ( isset( $params['scope'] ) ) { |
| 447 | - $validScopes = ['function', 'backend', 'frontend', 'scheduled', 'persistent', 'content_php', 'content_js']; | |
| 406 | + $validScopes = ['function', 'backend', 'frontend', 'scheduled', 'persistent']; | |
| 448 | 407 | if ( !in_array( $params['scope'], $validScopes ) ) { |
| 449 | 408 | throw new Exception( sprintf( 'Invalid scope. Must be one of: %s', implode( ', ', $validScopes ) ) ); |
| 450 | 409 | } |
| 451 | 410 | } |
| @@ -481,12 +440,8 @@ | ||
| 481 | 440 | $updateParams['functionTarget'] = $params['target'] ?? $snippet['functionTarget'] ?? 'php'; |
| 482 | 441 | $updateParams['functionArgs'] = $params['args'] ?? $snippet['functionArgs'] ?? []; |
| 483 | 442 | $updateParams['functionArgsDict'] = $params['argsData'] ?? $snippet['functionArgsDict'] ?? []; |
| 484 | 443 | $updateParams['functionBehavior'] = $params['behavior'] ?? $snippet['functionBehavior'] ?? 'dynamic'; |
| 485 | - // select_one() doesn't carry function metadata, so read the current MCP flag | |
| 486 | - // from the stored function to preserve it when the caller doesn't set it. | |
| 487 | - $existingFn = $this->snippet_module->get_function( $id ); | |
| 488 | - $updateParams['functionMcp'] = $params['mcp'] ?? ( $existingFn['mcp'] ?? false ); | |
| 489 | 444 | } |
| 490 | 445 | |
| 491 | 446 | // Add scheduled-specific params if it's a scheduled snippet |
| 492 | 447 | if ( $scope === 'scheduled' ) { |
| @@ -775,9 +730,9 @@ | ||
| 775 | 730 | |
| 776 | 731 | /** |
| 777 | 732 | * Get snippets by scope. |
| 778 | 733 | * |
| 779 | - * @param string $scope The scope to filter by: 'backend', 'frontend', 'function', 'scheduled', 'persistent', 'content_php', 'content_js'. | |
| 734 | + * @param string $scope The scope to filter by: 'backend', 'frontend', 'function', 'scheduled', 'persistent'. | |
| 780 | 735 | * @param array $filters Additional filters: 'active' (bool), 'tags' (array). |
| 781 | 736 | * @return array The list of snippets matching the criteria. |
| 782 | 737 | * @throws Exception If the scope is invalid. |
| 783 | 738 | */ |