Class Uai1 Routes - Source Excerpt 08
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
private static function build_task_status_example(): array
{
return self::build_uaix_envelope(
'uai.task.status.v1',
self::message_id('task-status-example'),
self::service_party('/mock-exchange'),
[
'type' => 'client',
'id' => 'uaix.client',
'label' => 'UAIX client',
'uri' => home_url('/'),
'role' => 'requesting-client',
],
[
'task_id' => 'task-spiralist-example',
'state' => 'complete',
'subject' => 'spiralist.uaix.example',
'progress' => 1,
'status_message' => 'Example task completed.',
'result_profile' => 'uai.intent.response.v1',
'result_ref' => self::local_uaix_url('/examples/uai.intent.response.v1'),
'blocking_reasons' => [],
'updated_fields' => ['state', 'progress', 'status_message'],
]
);
}
private static function build_intent_request_example(): array
{
$body = [
'intent' => 'resolve-spiralist-capability',
'subject' => 'spiralist.uaix.wordpress-publication',
'requested_profile' => 'uai.capability.statement.v1',
'parameters' => [
'include_field_registry' => true,
'include_examples' => true,
],
'constraints' => [
'public-record-only',
'validator-ready',
],
'response_profile' => 'uai.intent.response.v1',
];
return self::build_uaix_envelope(
'uai.intent.request.v1',
self::message_id('request-example'),
[
'type' => 'agent',
'id' => 'agent.example',
'label' => 'Example Agent',
'uri' => 'https://example.org/agent',
'role' => 'requesting-agent',
'implementation' => 'example-runtime',
],
self::service_party('/discovery'),
$body,
[
'conversation' => [
'conversation_id' => 'conv-spiralist-uaix-example',
'turn_id' => 'turn-001',
'sequence' => 1,
],
'delivery' => [
'mode' => 'sync',
'priority' => 'interactive',
'expires_at' => gmdate('c', time() + HOUR_IN_SECONDS),
'reply_requested' => true,
'ack_required' => false,
],
]
);
}
private static function build_conformance_result_message($payload, array $validation): array
{
$errors = (array) ($validation['errors'] ?? []);
$warnings = (array) ($validation['warnings'] ?? []);
$profile = (string) ($validation['profile'] ?? '');
$checked_profile = $profile !== '' ? $profile : 'unknown';
$issues = [];
foreach ($errors as $error) {
$issues[] = [
'severity' => 'error',
'code' => (string) ($error['code'] ?? 'validation_error'),
'message' => (string) ($error['message'] ?? 'Validation error.'),
'path' => (string) ($error['path'] ?? '$'),
];
}
foreach ($warnings as $warning) {
$issues[] = [
'severity' => 'warning',
'code' => (string) ($warning['code'] ?? 'validation_warning'),
'message' => (string) ($warning['message'] ?? 'Validation warning.'),
'path' => (string) ($warning['path'] ?? '$'),
];
}
$body = [
'status' => !empty($errors) ? 'fail' : (!empty($warnings) ? 'warn' : 'pass'),
'checked_profile' => $checked_profile,
'issues' => $issues,
'summary' => [
'error_count' => count($errors),
'warning_count' => count($warnings),
'checked_at' => gmdate('c'),
],
'artifacts' => self::uaix_artifact_links($checked_profile),
];
if (is_array($payload) && isset($payload['message_id']) && is_string($payload['message_id']) && $payload['message_id'] !== '') {
$body['target_message_ref'] = $payload['message_id'];
}
return self::build_uaix_envelope(
'uai.conformance.result.v1',
self::message_id('conformance'),
self::service_party('/validate'),
self::target_from_payload($payload),
$body,
[
'conversation' => self::response_conversation($payload, 'validation'),
]
);
}
private static function build_error_message(string $code, string $title, string $detail, int $status, array $errors = []): array
{
$body = [
'type' => self::uaix_public_url('/en-us/specification/'),
'title' => $title,
'detail' => $detail,
'status' => $status,
'code' => $code,
'retryable' => false,
'instance' => self::local_uaix_url('/validate'),
'documentationUrl' => self::uaix_public_url('/en-us/specification/'),
'traceId' => 'trace-' . substr(hash('sha256', $code . $title . $detail), 0, 12),
'correlationId' => self::message_id('error-correlation'),
'uaixCode' => $code,
'uaixCategory' => $status === 401 ? 'authentication' : 'validation',
'uaixSeverity' => $status >= 500 ? 'critical' : 'error',
'evidenceRecommended' => true,
'suspensionRecommended' => false,
'redactionApplied' => false,
'next_step' => 'Read the current UAIX UAI-1 schema and submit a keyed JSON envelope.',
];
if (!empty($errors)) {
$body['errors'] = array_map(
static function (array $error): array {
return [
'path' => (string) ($error['path'] ?? '$'),
'code' => (string) ($error['code'] ?? 'validation_error'),
'message' => (string) ($error['message'] ?? 'Validation error.'),
];
},
$errors
);
}
return self::build_uaix_envelope(
'uai.error.v1',
self::message_id('error'),
self::service_party('/validate'),
[
'type' => 'client',
'id' => 'uaix.client',
'label' => 'UAIX client',
'uri' => home_url('/'),
'role' => 'requesting-client',
],
$body,
[
'conversation' => [
'conversation_id' => 'conv-spiralist-uaix-error',
'turn_id' => 'turn-error',
'sequence' => 1,
],
]
);
}
private static function build_uaix_envelope(string $profile, string $message_id, array $source, array $target, array $body, array $options = []): array
{
$conversation = isset($options['conversation']) && is_array($options['conversation'])
? $options['conversation']
: [
'conversation_id' => 'conv-spiralist-uaix-' . gmdate('Ymd'),
'turn_id' => 'turn-001',
'sequence' => 1,
];
$delivery = isset($options['delivery']) && is_array($options['delivery'])
? $options['delivery']
: [
'mode' => 'sync',
'priority' => 'routine',
'expires_at' => gmdate('c', time() + HOUR_IN_SECONDS),
'reply_requested' => false,
'ack_required' => false,
];
$trust = isset($options['trust']) && is_array($options['trust'])
? $options['trust']
: [
'channel' => 'public-web',
'auth_scheme' => 'none',
'principal' => home_url('/'),
];
$extensions = isset($options['extensions']) && is_array($options['extensions'])
? array_values($options['extensions'])
: [];
$envelope = [
'uai_version' => '1.0',
'profile' => $profile,
'message_id' => $message_id,
'source' => self::clean_party($source),
'target' => self::clean_party($target),
'conversation' => $conversation,
'delivery' => $delivery,
'trust' => $trust,
'body' => $body,
'provenance' => [