CLARIXO · Integration Skeleton Pack

Implementation-ready skeletons plus minimal working examples for request, degraded, observability, and structured failure outcomes.

This pack gives host teams reference skeletons for role ownership and copy-paste-ready examples for the most important integration outcomes. These are reference implementations for logical roles, not mandatory file names.
Required Host Roles

Every production integration should make these roles explicit

Role ownership matters more than file names. The host may use different routes, modules, or files, but each of these responsibilities should have a clearly owned implementation path.
Role 1

Assistant Surface Module

User-facing entry that collects a message and sends a contract-compliant request.
Role 2

Chat Execution Endpoint

Backend route that validates request shape, preserves metadata, executes CLARIXO, and returns a normalized response.
Role 3

Operations Aggregation Endpoint

Internal data endpoint for summary, queues, and breakdowns used by operator-facing overview pages.
Role 4

Runtime Diagnostic Page

Internal operator-facing surface for latest runtime telemetry, degraded causes, and detailed diagnosis.
Skeleton 1

Assistant Surface Module

This role may be implemented as a page, component, or frontend module. The name may vary, but it MUST send a contract-compliant request to the chat execution endpoint.
<form id="clarixo-assistant-form">
  <textarea id="clarixo-message" placeholder="Ask CLARIXO..."></textarea>
  <button type="submit">Send</button>
</form>

<script>
  document.getElementById('clarixo-assistant-form').addEventListener('submit', async function (event) {
    event.preventDefault();

    const payload = {
      action: 'message',
      message: document.getElementById('clarixo-message').value,
      integration: {
        source: 'example_app',
        module: 'assistant',
        scene: 'customer_chat',
        version: 'v1',
        environment: 'production'
      },
      context: {
        lang: 'en',
        session_id: 'host-session-id',
        page: 'assistant_page',
        is_logged_in: true,
        client: {
          channel: 'admin_web',
          surface: 'assistant_surface'
        }
      }
    };

    const response = await fetch('/ai_chat.php', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      credentials: 'same-origin',
      body: JSON.stringify(payload)
    });

    const data = await response.json();
    console.log('CLARIXO_REPLY', data);
  });
</script>
Skeleton 2

Chat Execution Endpoint

This role receives the request, validates the contract, preserves integration and context metadata, executes CLARIXO, and returns a normalized response.
<?php
declare(strict_types=1);

header('Content-Type: application/json; charset=utf-8');

$raw = file_get_contents('php://input');
$data = json_decode($raw ?: '{}', true);

$action = (string)($data['action'] ?? '');
$message = (string)($data['message'] ?? '');
$integration = is_array($data['integration'] ?? null) ? $data['integration'] : [];
$context = is_array($data['context'] ?? null) ? $data['context'] : [];

if ($action !== 'message' || $message === '') {
    http_response_code(400);
    echo json_encode([
        'ok' => false,
        'error' => [
            'type' => 'integration_error',
            'code' => 'invalid_request',
            'message' => 'The request is missing a valid action or message.',
            'retryable' => false
        ]
    ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    exit;
}

$integrationSource = (string)($integration['source'] ?? '');
$integrationModule = (string)($integration['module'] ?? '');
$integrationScene = (string)($integration['scene'] ?? '');

if ($integrationSource === '' || $integrationModule === '' || $integrationScene === '') {
    http_response_code(400);
    echo json_encode([
        'ok' => false,
        'error' => [
            'type' => 'integration_error',
            'code' => 'missing_integration_identity',
            'message' => 'source, module, and scene are required.',
            'retryable' => false
        ]
    ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    exit;
}

$response = [
    'ok' => true,
    'reply' => 'Example CLARIXO response placeholder.',
    'actions' => [],
    'meta' => [
        'source' => 'clarixo',
        'provider' => 'clarixo-native',
        'integration_source' => $integrationSource,
        'integration_module' => $integrationModule,
        'integration_scene' => $integrationScene,
        'ops_final_status' => 'healthy',
        'ops_needs_review' => 0
    ]
];

echo json_encode($response, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
Skeleton 3

Operations Aggregation Endpoint

This role provides operator-facing summary, queue, and breakdown data for overview surfaces.
<?php
declare(strict_types=1);

header('Content-Type: application/json; charset=utf-8');

$payload = [
    'ok' => true,
    'window' => ['range' => '24h'],
    'summary' => [
        'total_conversations' => 12,
        'healthy_count' => 9,
        'healthy_rate' => 0.75,
        'fallback_count' => 2,
        'fallback_rate' => 0.1667,
        'low_confidence_count' => 1,
        'low_confidence_rate' => 0.0833,
        'manual_review_count' => 0,
        'manual_review_rate' => 0.0,
        'contract_issue_count' => 0,
        'contract_issue_rate' => 0.0
    ],
    'queues' => [
        'manual_review_pending' => 0,
        'fallback' => 2,
        'low_confidence' => 1
    ],
    'breakdowns' => [
        'by_module' => [
            ['key' => 'assistant', 'label' => 'assistant', 'count' => 12]
        ],
        'by_scene' => [
            ['key' => 'customer_chat', 'label' => 'customer_chat', 'count' => 12]
        ],
        'by_status' => [
            ['key' => 'healthy', 'label' => 'healthy', 'count' => 9, 'rate' => 0.75],
            ['key' => 'fallback', 'label' => 'fallback', 'count' => 2, 'rate' => 0.1667],
            ['key' => 'low_confidence', 'label' => 'low_confidence', 'count' => 1, 'rate' => 0.0833]
        ]
    ]
];

echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
Skeleton 4

Runtime Diagnostic Page

This role gives operators the latest runtime telemetry for deeper diagnosis.
<section class="clarixo-runtime-detail">
  <h2>Latest CLARIXO Runtime</h2>
  <dl>
    <dt>Integration Source</dt>
    <dd>tgtracing</dd>
    <dt>Integration Module</dt>
    <dd>assistant</dd>
    <dt>Integration Scene</dt>
    <dd>customer_chat</dd>
    <dt>Provider</dt>
    <dd>clarixo-native</dd>
    <dt>Final Status</dt>
    <dd>healthy</dd>
    <dt>Needs Review</dt>
    <dd>0</dd>
  </dl>
</section>
Minimal Working Examples

Copy-paste-ready request, healthy, degraded, observability, and structured failure samples

These examples are intentionally small. They are designed to show the minimum structurally valid outcomes that still respect the CLARIXO contract and remain usable during first-pass implementation. In the response examples below, meta.mode describes execution or response behavior such as direct, fallback, or guarded. That is different from integration.mode, which is integration attribution mode and may be normalized to first_party or third_party.
Example A · Success

Healthy success

{
  "ok": true,
  "reply": "The order is currently in transit and should arrive soon.",
  "actions": [],
  "meta": {
    "source": "clarixo",
    "provider": "clarixo-native",
    "intent": "customer_chat",
    "mode": "direct",
    "decision_state": "healthy",
    "integration_source": "example_app",
    "integration_module": "assistant",
    "integration_scene": "customer_chat",
    "ops_final_status": "healthy",
    "ops_needs_review": 0
  }
}
Example B · Degraded

Degraded success

{
  "ok": true,
  "reply": "I can provide a limited summary right now. Please verify details before sending.",
  "actions": [],
  "meta": {
    "source": "clarixo",
    "provider": "fallback-provider",
    "intent": "customer_chat",
    "mode": "fallback",
    "decision_state": "degraded",
    "degradation_reason": "provider_unavailable",
    "integration_source": "example_app",
    "integration_module": "assistant",
    "integration_scene": "customer_chat",
    "ops_final_status": "fallback",
    "ops_needs_review": 1
  }
}
Example C · Observability

Observability-rich success

{
  "ok": true,
  "reply": "The conversation can continue, but confidence is moderate.",
  "actions": [],
  "meta": {
    "source": "clarixo",
    "provider": "clarixo-native",
    "intent": "customer_chat",
    "mode": "guarded",
    "decision_state": "watch",
    "confidence": 0.73,
    "integration_source": "example_app",
    "integration_module": "assistant",
    "integration_scene": "customer_chat",
    "ops_final_status": "watch",
    "ops_needs_review": 0,
    "observability": {
      "trace_id": "trace_01",
      "guard_state": "watch",
      "fallback_used": false
    }
  }
}
Example D · Protocol Failure

Structured contract failure

{
  "ok": false,
  "error": {
    "type": "protocol_error",
    "code": "missing_required_field",
    "message": "Required response field 'reply' was not present.",
    "retryable": false,
    "hint": "Return a valid JSON object containing ok:boolean and reply:string"
  }
}
Implementation rule: request examples, healthy success, degraded success, observability-rich success, and structured contract failure MUST all remain structurally valid. Hosts may add local UX fields, but they must not overwrite the CLARIXO contract.
Host Notes

What these examples are meant to teach

Role clarity
Make the Assistant Surface Module, Chat Execution Endpoint, Operations Aggregation Endpoint, and Runtime Diagnostic Page explicit in your host architecture.
Metadata continuity
Preserve source, module, scene, version, login state, channel, and surface metadata from entry to execution and into observability output.
Degraded honesty
Do not label fallback or low-confidence replies as healthy. Degraded success is still success, but it must remain explicitly degraded.
Failure discipline
Do not collapse protocol failures into empty replies or silent success responses. Keep error type, code, and message structured.