> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pastures.farm/llms.txt
> Use this file to discover all available pages before exploring further.

# Ask AI Buttons

> Contextual 'Diagnose →' links open the AI drawer pre-filled with diagnostic queries.

Several Pastures pages include **"Diagnose →"** links that open the AI drawer with a pre-filled query, giving users one-click access to AI diagnostics for a specific issue.

## Pages with Ask AI buttons

| Page                 | Trigger             | Example pre-filled query                      |
| -------------------- | ------------------- | --------------------------------------------- |
| Advisories           | Each advisory card  | "Diagnose: etcd cluster has only 1 member"    |
| Cluster Intelligence | Each detected issue | "Diagnose: Longhorn replica count degraded"   |
| Monitoring           | Each active alert   | "Diagnose: Node memory pressure on worker-03" |
| Harvester VMs        | VM error states     | "Diagnose: VM stuck in Starting state"        |

## How it works

When a user clicks a "Diagnose →" link, the page dispatches a `CustomEvent` on the `window` object:

```typescript theme={null}
window.dispatchEvent(
  new CustomEvent('pastures:drawer:open', {
    detail: { query: 'Diagnose: etcd cluster has only 1 member' },
  })
);
```

The AI drawer listens for this event. When received, it:

1. Opens the drawer (if not already open)
2. Pre-fills the input textarea with `detail.query`
3. Automatically submits the query

This means the user sees the drawer open and immediately begin generating a diagnosis — no manual typing required.

## Integration pattern

To add a "Diagnose →" button to any Pastures page, dispatch the event with the relevant diagnostic text:

```vue theme={null}
<template>
  <button @click="diagnose">Diagnose →</button>
</template>

<script setup lang="ts">
function diagnose() {
  window.dispatchEvent(
    new CustomEvent('pastures:drawer:open', {
      detail: { query: `Diagnose: ${issue.title}` },
    })
  );
}
</script>
```

<Tip>
  The event-based pattern means any page — including custom pages added by contributors — can integrate with Pastures AI without importing drawer components directly.
</Tip>

## Behavior details

* If the drawer is already open, a new event replaces the current input and submits
* The pre-filled query appears in the user's message history as if they typed it
* Context awareness still applies — if the user is on the Advisories page, page-specific suggestions remain available after the conversation
