HEX
Server: Apache/2.4.65 (Debian)
System: Linux 88f31f35b0b8 6.1.0-38-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.147-1 (2025-08-02) x86_64
User: www-data (33)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/ai-engine/classes/data/function-call.php
<?php

/**
* Value object representing a function call request from an AI model
*/
class Meow_MWAI_Data_FunctionCall {
  public string $id;
  public string $name;
  public string $arguments;

  public function __construct( string $id, string $name, string $arguments ) {
    $this->id = $id;
    $this->name = $name;
    $this->arguments = $arguments;
  }

  /**
  * Create from OpenAI tool call format
  */
  public static function from_tool_call( array $toolCall ): self {
    return new self(
      $toolCall['id'],
      $toolCall['function']['name'],
      $toolCall['function']['arguments']
    );
  }

  /**
  * Create from Anthropic tool use format
  */
  public static function from_tool_use( array $toolUse ): self {
    return new self(
      $toolUse['id'],
      $toolUse['name'],
      json_encode( $toolUse['input'] )
    );
  }

  /**
  * Get arguments as JSON string
  */
  public function get_arguments_json(): string {
    return $this->arguments;
  }

  /**
  * Get arguments as array
  */
  public function get_arguments_array(): array {
    return json_decode( $this->arguments, true ) ?? [];
  }
}