|
11 | 11 | import java.nio.charset.StandardCharsets; |
12 | 12 | import java.util.LinkedHashMap; |
13 | 13 | import java.util.Map; |
| 14 | +import java.util.UUID; |
14 | 15 |
|
15 | 16 | public final class AxmeClient { |
16 | 17 | private final String baseUrl; |
@@ -656,6 +657,82 @@ public Map<String, Object> getBillingInvoice(String invoiceId, RequestOptions op |
656 | 657 | return requestJson("GET", "/v1/billing/invoices/" + invoiceId, Map.of(), null, normalizeOptions(options)); |
657 | 658 | } |
658 | 659 |
|
| 660 | + public String sendIntent(Map<String, Object> payload, RequestOptions options) |
| 661 | + throws IOException, InterruptedException { |
| 662 | + Map<String, Object> body = new LinkedHashMap<>(payload); |
| 663 | + if (!body.containsKey("correlation_id")) { |
| 664 | + body.put("correlation_id", UUID.randomUUID().toString()); |
| 665 | + } |
| 666 | + Map<String, Object> result = createIntent(body, options); |
| 667 | + return (String) result.get("intent_id"); |
| 668 | + } |
| 669 | + |
| 670 | + public Map<String, Object> applyScenario(Map<String, Object> bundle, RequestOptions options) |
| 671 | + throws IOException, InterruptedException { |
| 672 | + return requestJson("POST", "/v1/scenarios/apply", Map.of(), bundle, normalizeOptions(options)); |
| 673 | + } |
| 674 | + |
| 675 | + public Map<String, Object> validateScenario(Map<String, Object> bundle, RequestOptions options) |
| 676 | + throws IOException, InterruptedException { |
| 677 | + return requestJson("POST", "/v1/scenarios/validate", Map.of(), bundle, normalizeOptions(options)); |
| 678 | + } |
| 679 | + |
| 680 | + public Map<String, Object> health(RequestOptions options) |
| 681 | + throws IOException, InterruptedException { |
| 682 | + return requestJson("GET", "/v1/health", Map.of(), null, normalizeOptions(options)); |
| 683 | + } |
| 684 | + |
| 685 | + @SuppressWarnings("unchecked") |
| 686 | + public Map<String, Object> mcpInitialize(RequestOptions options) |
| 687 | + throws IOException, InterruptedException { |
| 688 | + Map<String, Object> rpcRequest = new LinkedHashMap<>(); |
| 689 | + rpcRequest.put("jsonrpc", "2.0"); |
| 690 | + rpcRequest.put("id", UUID.randomUUID().toString()); |
| 691 | + rpcRequest.put("method", "initialize"); |
| 692 | + rpcRequest.put("params", Map.of()); |
| 693 | + Map<String, Object> response = requestJson("POST", "/mcp", Map.of(), rpcRequest, normalizeOptions(options)); |
| 694 | + if (response.containsKey("error")) { |
| 695 | + throw new AxmeHttpException(0, String.valueOf(response.get("error"))); |
| 696 | + } |
| 697 | + Object result = response.get("result"); |
| 698 | + return result instanceof Map ? (Map<String, Object>) result : response; |
| 699 | + } |
| 700 | + |
| 701 | + @SuppressWarnings("unchecked") |
| 702 | + public Map<String, Object> mcpListTools(RequestOptions options) |
| 703 | + throws IOException, InterruptedException { |
| 704 | + Map<String, Object> rpcRequest = new LinkedHashMap<>(); |
| 705 | + rpcRequest.put("jsonrpc", "2.0"); |
| 706 | + rpcRequest.put("id", UUID.randomUUID().toString()); |
| 707 | + rpcRequest.put("method", "tools/list"); |
| 708 | + rpcRequest.put("params", Map.of()); |
| 709 | + Map<String, Object> response = requestJson("POST", "/mcp", Map.of(), rpcRequest, normalizeOptions(options)); |
| 710 | + if (response.containsKey("error")) { |
| 711 | + throw new AxmeHttpException(0, String.valueOf(response.get("error"))); |
| 712 | + } |
| 713 | + Object result = response.get("result"); |
| 714 | + return result instanceof Map ? (Map<String, Object>) result : response; |
| 715 | + } |
| 716 | + |
| 717 | + @SuppressWarnings("unchecked") |
| 718 | + public Map<String, Object> mcpCallTool(String name, Map<String, Object> arguments, RequestOptions options) |
| 719 | + throws IOException, InterruptedException { |
| 720 | + Map<String, Object> params = new LinkedHashMap<>(); |
| 721 | + params.put("name", name); |
| 722 | + params.put("arguments", arguments != null ? arguments : Map.of()); |
| 723 | + Map<String, Object> rpcRequest = new LinkedHashMap<>(); |
| 724 | + rpcRequest.put("jsonrpc", "2.0"); |
| 725 | + rpcRequest.put("id", UUID.randomUUID().toString()); |
| 726 | + rpcRequest.put("method", "tools/call"); |
| 727 | + rpcRequest.put("params", params); |
| 728 | + Map<String, Object> response = requestJson("POST", "/mcp", Map.of(), rpcRequest, normalizeOptions(options)); |
| 729 | + if (response.containsKey("error")) { |
| 730 | + throw new AxmeHttpException(0, String.valueOf(response.get("error"))); |
| 731 | + } |
| 732 | + Object result = response.get("result"); |
| 733 | + return result instanceof Map ? (Map<String, Object>) result : response; |
| 734 | + } |
| 735 | + |
659 | 736 | private Map<String, Object> requestJson( |
660 | 737 | String method, |
661 | 738 | String path, |
|
0 commit comments