From 552828020d4c6e6bf2fa3ba790a566f86b6577d2 Mon Sep 17 00:00:00 2001 From: colorlink Date: Fri, 16 Oct 2026 04:42:43 +0000 Subject: [PATCH] Batch35: Amelia booking tools (guarded, net-new) Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg --- includes/Extensions/Batch35.php | 71 +++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 includes/Extensions/Batch35.php diff --git a/includes/Extensions/Batch35.php b/includes/Extensions/Batch35.php new file mode 100644 index 0000000..0ee5b7b --- /dev/null +++ b/includes/Extensions/Batch35.php @@ -0,0 +1,71 @@ + 'object', 'properties' => $props ?: new \stdClass()]; + if ($required) $schema['required'] = $required; + return ['name' => $name, 'description' => $desc, 'scope' => $scope, + 'handler' => 'AskTamMCP\\Extensions\\Batch35::' . $method, 'inputSchema' => $schema]; + }; + + $registry->register($def('amelia_detect', 'Report whether Amelia is active and its version.', [], [], 'read', 'detect')); + $registry->register($def('amelia_list_services', 'List Amelia services (id, name, price, duration).', + ['per_page' => ['type' => 'integer', 'default' => 100]], [], 'read', 'listServices')); + $registry->register($def('amelia_list_appointments', 'List Amelia appointments (newest first): id, status, booking start.', + ['per_page' => ['type' => 'integer', 'default' => 30]], [], 'read', 'listAppointments')); + $registry->register($def('amelia_list_employees', 'List Amelia employees/providers (id, name, email).', [], [], 'read', 'listEmployees')); + } + + public static function detect(array $args): array { + return ['active' => defined('AMELIA_VERSION'), 'version' => defined('AMELIA_VERSION') ? AMELIA_VERSION : null]; + } + + private static function tableExists(string $t): bool { + global $wpdb; + return $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $t)) === $t; + } + + public static function listServices(array $args): array { + global $wpdb; + $t = $wpdb->prefix . 'amelia_services'; + if (!self::tableExists($t)) return ['supported' => false, 'note' => 'amelia_services table not found.', 'services' => []]; + $per = max(1, (int) ($args['per_page'] ?? 100)); + $rows = $wpdb->get_results($wpdb->prepare("SELECT id, name, price, duration, status FROM {$t} ORDER BY id DESC LIMIT %d", $per), ARRAY_A); + $out = []; + foreach ((array) $rows as $r) $out[] = ['id' => (int) $r['id'], 'name' => $r['name'], 'price' => $r['price'], 'duration' => (int) $r['duration'], 'status' => $r['status']]; + return ['supported' => true, 'count' => count($out), 'services' => $out]; + } + + public static function listAppointments(array $args): array { + global $wpdb; + $t = $wpdb->prefix . 'amelia_appointments'; + if (!self::tableExists($t)) return ['supported' => false, 'note' => 'amelia_appointments table not found.', 'appointments' => []]; + $per = max(1, (int) ($args['per_page'] ?? 30)); + $rows = $wpdb->get_results($wpdb->prepare("SELECT id, status, bookingStart FROM {$t} ORDER BY id DESC LIMIT %d", $per), ARRAY_A); + $out = []; + foreach ((array) $rows as $r) $out[] = ['id' => (int) $r['id'], 'status' => $r['status'], 'start' => $r['bookingStart']]; + return ['supported' => true, 'count' => count($out), 'appointments' => $out]; + } + + public static function listEmployees(array $args): array { + global $wpdb; + $t = $wpdb->prefix . 'amelia_users'; + if (!self::tableExists($t)) return ['supported' => false, 'note' => 'amelia_users table not found.', 'employees' => []]; + $rows = $wpdb->get_results("SELECT id, firstName, lastName, email FROM {$t} WHERE type = 'provider' ORDER BY id ASC LIMIT 200", ARRAY_A); + $out = []; + foreach ((array) $rows as $r) $out[] = ['id' => (int) $r['id'], 'name' => trim(($r['firstName'] ?? '') . ' ' . ($r['lastName'] ?? '')), 'email' => $r['email'] ?? '']; + return ['supported' => true, 'count' => count($out), 'employees' => $out]; + } +}