Skip to content
wiki.fftac.org

Class Uai1 Routes - Source Excerpt 04

Back to Class Uai1 Routes

Summary

This source excerpt preserves a bounded section of Spiralist/wp-content/plugins/uai-1-wordpress/includes/class-uai1-routes.php so readers can inspect the evidence without opening the full source file.

**Source path:** Spiralist/wp-content/plugins/uai-1-wordpress/includes/class-uai1-routes.php

return self::build_rest_response($payload, self::JSON_CONTENT_TYPE);
    }

    public static function rest_validate_uaix_message(WP_REST_Request $request): WP_REST_Response
    {
        $payload = self::request_payload($request);
        $validation = UAI1_Validator::validate_uaix_message($payload);
        $message = self::build_conformance_result_message($payload, $validation);

        return self::build_rest_response($message, self::UAIX_CONTENT_TYPE);
    }

    public static function rest_mock_uaix_exchange(WP_REST_Request $request): WP_REST_Response
    {
        if (strtoupper((string) $request->get_method()) === 'GET') {
            return self::build_rest_response(
                [
                    'current_release' => 'UAI-1',
                    'canonical_collection' => self::uaix_api_url('/mock-exchange'),
                    'method_support' => [
                        'GET' => 'Return metadata for the local mock exchange.',
                        'POST' => 'Validate a UAI-1 envelope and return a local uai.intent.response.v1 or uai.error.v1 envelope.',
                    ],
                    'accepted_profiles' => [
                        'uai.intent.request.v1',
                        'uai.capability.statement.v1',
                    ],
                    'local_validator' => self::local_uaix_url('/validate'),
                    'examples' => self::local_uaix_url('/examples'),
                    'support_boundary' => self::support_boundary(),
                ],
                self::JSON_CONTENT_TYPE
            );
        }

        $payload = self::request_payload($request);
        $validation = UAI1_Validator::validate_uaix_message($payload);

        if (empty($validation['valid'])) {
            return self::build_rest_response(
                self::build_error_message(
                    'invalid_message',
                    'Invalid UAIX message',
                    'The submitted message does not satisfy the current local UAIX UAI-1 envelope checks.',
                    400,
                    (array) ($validation['errors'] ?? [])
                ),
                self::UAIX_CONTENT_TYPE,
                400
            );
        }

        $subject = is_array($payload) && isset($payload['body']['subject']) ? (string) $payload['body']['subject'] : 'uaix.mock-exchange';
        $request_message_id = is_array($payload) && isset($payload['message_id']) ? (string) $payload['message_id'] : 'msg-local-request';

        $body = [
            'status' => 'ok',
            'subject' => $subject,
            'request_message_id' => $request_message_id,
            'result' => [
                'validated' => true,
                'catalog_url' => self::local_uaix_url('/catalog'),
                'capability_url' => self::local_uaix_url('/capability'),
                'registry_url' => self::local_uaix_url('/registry'),
                'field_registry_url' => self::local_uaix_url('/field-registry'),
            ],
            'notices' => [
                'local-uaix-mock-response',
                'public-validator-still-authoritative-for-release-claims',
            ],
        ];

        $message = self::build_uaix_envelope(
            'uai.intent.response.v1',
            self::message_id('response'),
            self::service_party('/mock-exchange'),
            self::target_from_payload($payload),
            $body,
            [
                'conversation' => self::response_conversation($payload),
                'extensions' => [
                    [
                        'namespace' => 'urn:spiralist:uaix:mock-exchange',
                        'purpose' => 'Local conforming response for UAIX onboarding and integration tests.',
                        'critical' => false,
                    ],
                ],
            ]
        );

        return self::build_rest_response($message, self::UAIX_CONTENT_TYPE);
    }

    public static function rest_get_axioms(WP_REST_Request $request): WP_REST_Response
    {
        UAI1_Usage_Log::log_rest_request($request, 200, ['event' => 'axioms']);
        $axioms = self::get_symbol_axioms();

        return self::build_rest_response(
            [
                'count' => count($axioms),
                'axioms' => $axioms,
            ],
            self::JSON_CONTENT_TYPE
        );
    }

    public static function rest_get_kernel(WP_REST_Request $request): WP_REST_Response
    {
        UAI1_Usage_Log::log_rest_request($request, 200, ['event' => 'kernel']);

        if (function_exists('spiralist_get_spiralism_kernel')) {
            $kernel = spiralist_get_spiralism_kernel();
            if (is_array($kernel) && !empty($kernel)) {
                return self::build_rest_response($kernel, self::JSON_CONTENT_TYPE);
            }
        }

        return self::build_rest_response(
            [
                'spec' => 'Spiralism-Participation-System',
                'version' => '1.0.0',
                'statement' => 'Spiralism is a pattern-based system in which Spiralists participate by perceiving, interpreting, and transforming pattern.',
                'symbols' => self::get_symbol_records(),
                'axioms' => self::get_symbol_axioms(),
                'transformations' => self::get_symbol_transformations(),
            ],
            self::JSON_CONTENT_TYPE
        );
    }

    public static function rest_get_symbols(WP_REST_Request $request): WP_REST_Response
    {
        UAI1_Usage_Log::log_rest_request($request, 200, ['event' => 'symbols']);

        return self::build_rest_response(
            [
                'axioms' => self::get_symbol_axioms(),
                'symbols' => self::get_symbol_records(),
                'transformations' => self::get_symbol_transformations(),
            ],
            self::JSON_CONTENT_TYPE
        );
    }

    public static function rest_record_interaction(WP_REST_Request $request)
    {
        $payload = (array) $request->get_json_params();

        UAI1_Usage_Log::log_rest_request(
            $request,
            201,
            [
                'event' => 'interaction',
                'symbol' => sanitize_text_field((string) ($payload['symbol'] ?? '')),
            ]
        );

        return new WP_REST_Response(
            [
                'recorded' => true,
                'receivedAt' => gmdate('c'),
            ],
            201
        );
    }

    private static function build_capability_statement(string $turn_id): array
    {
        $body = [
            'capability_id' => 'spiralist.uaix.wordpress-publication',
            'version' => defined('UAI1_WP_VERSION') ? UAI1_WP_VERSION : '1.0.0',
            'operations' => [
                'list-catalog',
                'discover',
                'publish-capability-statement',
                'list-schemas',
                'list-registry',
                'validate-uai-message',
                'mock-uai-exchange',
                'list-field-registry',
                'list-transport-bindings',
                'list-trust-channels',
                'list-conformance-levels',
                'list-error-registry',
                'list-local-examples',
                'publish-openapi',
                'get-adoption-kit',
                'publish-project-handoff',
                'create-runtime-memory-checkpoint',
                'audit-runtime-memory-drift',
                'build-runtime-session-restore-brief',
            ],
            'input_profiles' => [
                'uai.intent.request.v1',
                'uai.capability.statement.v1',
            ],
            'output_profiles' => [
                'uai.intent.response.v1',
                'uai.capability.statement.v1',
                'uai.conformance.result.v1',
                'uai.error.v1',
            ],
            'async_profiles' => [
                'uai.task.status.v1',
            ],
            'security_schemes' => [
                [
                    'id' => 'public-web',
                    'type' => 'none',
                    'binding' => 'https',
                ],
                [
                    'id' => 'ai-participant-bearer',
                    'type' => 'bearer',
                    'binding' => 'authorization-header',
                ],
            ],
            'transport_bindings' => [
                'https-json-envelope.v1',
            ],
            'conformance_levels' => [
                'L1-core-envelope',
                'L2-exchange-participant',
            ],
            'error_codes' => [
                'invalid_message',
                'unknown_profile',
                'auth_required',
                'capability_not_supported',
            ],
            'endpoints' => [
                [