# AI State Loading
> Agent progress as a list of steps with a live log, elapsed time and a summary when done.

## Installation

```bash
npx shadcn@latest add @kokonutui/ai-loading
```

## Props

| Prop                   | Type         | Default | Description                                                                                                          |
|------------------------|--------------|---------|----------------------------------------------------------------------------------------------------------------------|
| `steps?`              | `AgentStep[]`|         | The agent's steps, in order. Update them as work progresses. When omitted, a demo run plays on a loop.            |
| `collapseWhenDone?`   | `boolean`    | `true`  | Collapse the list once every step is done. Defaults to true.                                                       |
| `className?`          | `string`     |         | Extra classes for the root element.                                                                                 |

### AgentStep

| Field  | Type                     | Description                                                                |
|--------|--------------------------|----------------------------------------------------------------------------|
| `id`   | `string`                 |                                                                            |
| `label`| `string`                 |                                                                            |
| `status`| `AgentStepStatus`       |                                                                            |
| `detail?`| `string[]`             | Log lines for the step. The running step shows the latest ones.             |

### AgentStepStatus

```ts
type AgentStepStatus = "pending" | "running" | "done" | "error";
```

### Demo Steps

```ts
const DEMO_STEPS: Omit<AgentStep, "status">[] = [
  {
    id: "search",
    label: "Searching the web",
    detail: [
      "query: loading states in agent UIs",
      "visiting 5 websites",
      "reading emilkowal.ski/ui/great-animations",
      "reading developer.apple.com/design",
    ],
  },
  {
    id: "read",
    label: "Reading 4 sources",
    detail: [
      "extracting key passages",
      "dropping 1 duplicate source",
      "ranking by relevance",
    ],
  },
  {
    id: "compare",
    label: "Comparing approaches",
    detail: [
      "spinners vs. step lists",
      "progress you can verify",
      "checking motion preferences",
    ],
  },
  {
    id: "write",
    label: "Writing the summary",
    detail: ["drafting 3 sections"],
  },
];
```

### API Usage

The AILoadingState component expects a list of AgentSteps as a prop as follows:

```tsx
<AILoadingState steps={DEMO_STEPS} />
```

### Example

An example of how to use the AILoadingState in your React application:

```tsx
import AILoadingState from './AILoadingState';

function MyComponent() {
  return (
    <div>
      <AILoadingState steps={DEMO_STEPS} />
    </div>
  );
}
```

### Conclusion
The AILoadingState component provides a robust solution for managing agent loading states with a visual progression display.
