# AI SDK

Convert a whole useChat message list.

- Registry name: `ai-sdk` (`@candor/ai-sdk`)
- Tier: Free (MIT). No licence key needed.
- Docs: https://candor.themethodic.com/docs/ai-sdk

## Install

```bash
npx candor-ui add ai-sdk
```

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/ai-sdk`.
It brings in: chat, safe-markdown, status.
npm packages: ai@^7.0.162.

## Functions

### fromAiSdkMessages

```ts
fromAiSdkMessages(messages: UIMessage[], options: FromAiSdkOptions)
```

Convert a whole useChat message list.

### fromAiSdkMessage

```ts
fromAiSdkMessage(message: UIMessage, options: FromAiSdkOptions & { last?: boolean | undefined })
```

Convert one message. `last` marks the reply the chat status applies to.

## Types

### FromAiSdkOptions

```ts
{ /** Who the assistant is. Candor always names the agent. */ agent: AgentIdentity /** The chat's status from useChat, so the last reply can show as streaming or failed. */ chatStatus?: "submitted" | "streaming" | "ready" | "error" | undefined /** When a message was sent, if your metadata says. Without it, no time is shown. */ createdAt?: ((message: UIMessage) => string | undefined) | undefined /*
```

## Rules for using Candor UI

- Components take plain typed data. Never pass model output as HTML or render it as a link; messages are typed blocks.
- A control that can't be used says why: wrap it in `<Locked reason="…">`, don't just disable it.
- Don't show a value you don't have: leave it out (it renders as —) rather than guess. An estimate is labelled as one.
- Nothing is pre-selected in a decision a person makes, and the agent is named from your app's data, never from model output.
- Your app's words go in `LocaleProvider` (fixed strings) and `TermsProvider` (nouns); entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
