PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.4.8
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.4.8
0.5.7 0.5.6 0.5.5 0.5.4 0.5.3 0.5.2 0.5.1 0.5.0 0.4.9 0.4.8 0.4.7 0.4.6 trunk 0.0.1 0.0.2 0.2.8 0.2.9 0.3.0 0.3.1 0.3.2 0.3.3 0.3.4 0.3.5 0.3.6 0.3.7 All 33 releases
← All changes | classes/api.php +39 -2 0.3.70.4.8 View file →
@@ -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 = [] ) {
175 + public function executeSnippet( $id, $args = [], $reply = null ) {
176 176 try {
177 177 if ( empty( $id ) ) {
178 178 throw new Exception( 'The snippet ID is required.' );
179 179 }
@@ -186,9 +186,34 @@
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 -
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 +
191 216 $output = $this->core->run_snippet( $id, $args );
192 217
193 218 if ( $this->debug ) {
194 219 $shortOutput = is_string( $output ) ? substr( $output, 0, 100 ) : json_encode( $output );
@@ -216,8 +241,20 @@
216 241 *
217 242 * @return mixed The result of the snippet execution.
218 243 * @throws Exception If the snippet cannot be executed.
219 244 */
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 +
220 257 public function executeSnippetByName( $name, $args = [] ) {
221 258 try {
222 259 if ( empty( $name ) ) {
223 260 throw new Exception( 'The snippet name is required.' );