Live CortexUI Surface

This block renders live CortexUI contract metadata in the docs DOM so AI View can inspect real machine-readable elements instead of only code examples.

AI View can now inspect a live status region, form fields, actions, and table entities on every docs page.
AI-addressable docs entities
ItemState
Search docsReady
Inspect metadataVisible in AI View

getRecentEvents()

Returns a chronological log of recent AI-contract events emitted on the current page.

Signature

window.__CORTEX_UI__.getRecentEvents(): RuntimeEventLogEntry[]

Return Type

interface RuntimeEventLogEntry {
  type: 'action_triggered' | 'action_completed' | 'action_failed' | 'form_submitted' | 'field_updated';
  actionId?: string;
  formId?: string;
  fieldId?: string;
  result?: 'success' | 'error';
  message?: string;
  timestamp: number; // Unix timestamp ms
}

Example Output

[
  {
    "type": "action_triggered",
    "actionId": "save-profile",
    "timestamp": 1700000001000
  },
  {
    "type": "action_completed",
    "actionId": "save-profile",
    "result": "success",
    "timestamp": 1700000003200
  }
]

Usage: Verifying an action succeeded

// After triggering save-profile, verify it succeeded
function waitForActionResult(actionId, timeoutMs = 10000) {
  return new Promise((resolve, reject) => {
    const start = Date.now();
    const check = setInterval(() => {
      const events = window.__CORTEX_UI__.getRecentEvents();
      const completed = events.find(
        e => e.actionId === actionId && e.type === 'action_completed'
      );
      const failed = events.find(
        e => e.actionId === actionId && e.type === 'action_failed'
      );
      if (completed) { clearInterval(check); resolve(completed); }
      if (failed) { clearInterval(check); reject(failed); }
      if (Date.now() - start > timeoutMs) { clearInterval(check); reject(new Error('Timeout')); }
    }, 200);
  });
}

// Use it
await document.querySelector('[data-ai-id="save-profile"]').click();
const result = await waitForActionResult('save-profile');
console.log(result.result); // "success"
Best Practice

The event log is the most reliable way for AI agents to verify that an action completed. Don't assume success — always check the event log.

Event Types Reference

EventWhenKey fields
action_triggeredWhen user/agent initiates actionactionId
action_completedWhen action resolves successfullyactionId, result: 'success'
action_failedWhen action resolves with erroractionId, result: 'error', message
form_submittedWhen form submit firesformId
field_updatedWhen field value changesfieldId