# Chat Confirmation

> 让用户批准或拒绝一次宿主操作，保留提交失败后的重试入口。

网页来源：/components/chat-confirmation

版本：@quirekit/ui 0.3.1；源码修订：d79a6b48d00e+worktree。此文档对应当前源码构建，接入方式以开始使用为准。

接入前置：[开始使用](/raw/components/getting-started.md)（Vue、样式、主题与图标 Provider）。

`QuireChatConfirmation` 呈现一个明确的授权请求。`decide` 只表达“允许”或“拒绝”的用户意图，不代表权限已经生效；宿主必须用原 `requestId` 提交并更新 `state`。`submitting` 禁止重复操作，`failed` 保留原请求和两个决策入口，`approved`、`rejected`、`expired` 为只读终态。

### 示例：chat-confirmation/basic

文件：`basic.vue`

```vue
<script setup lang="ts">
import { onBeforeUnmount, ref } from 'vue';
import type { QuireKitChatConfirmationState } from '@quirekit/ui';
import { QuireButton, QuireChatConfirmation } from '@quirekit/ui/vue';

const state = ref<QuireKitChatConfirmationState>('pending');
const failNext = ref(true);
let timer: ReturnType<typeof setTimeout> | undefined;

/** Simulate the host's response without granting actual permissions. */
function decide(details: { decision: 'approve' | 'reject' }): void {
  state.value = 'submitting';
  timer = setTimeout(() => {
    state.value = failNext.value ? 'failed' : details.decision === 'approve' ? 'approved' : 'rejected';
    failNext.value = false;
  }, 500);
}

/** Restore the local demonstration request. */
function reset(): void {
  if (timer) clearTimeout(timer);
  state.value = 'pending';
  failNext.value = true;
}
onBeforeUnmount(() => { if (timer) clearTimeout(timer); });
</script>

<template>
  <div class="grid max-w-[34rem] gap-qk-group p-qk-surface" data-chat-confirmation-basic>
    <QuireChatConfirmation request-id="approval-demo" title="允许读取当前工作区的文件？"
      description="仅用于生成这次回答；不会修改文件。" :state="state" error="连接中断，决定尚未提交。" @decide="decide">
      <p class="m-0 text-qk-compact text-qk-text-secondary">产品说明.docx · 会议纪要.docx</p>
    </QuireChatConfirmation>
    <div><QuireButton size="xs" variant="ghost" @click="reset">重新演示</QuireButton></div>
  </div>
</template>
```

默认插槽放本次操作的文件清单、差异或预览，位于说明之后、决策按钮之前。内容与操作共用一个
审阅区域，终态仍保留预览；组件不会读取或执行插槽中的业务数据。

在消息中可使用 `kind: 'confirmation'` 的 MessagePart。Message / MessageList 会转发 `confirmationDecision`，带上 `messageId`、`partId` 与 `requestId`；AI/工具授权逻辑不进入公共 UI。

## API

### QuireChatConfirmation

#### Props

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| requestId | 是 | — | Stable request identity, distinct from message or tool identity. |
| title | 是 | — | Action the user is being asked to authorize. |
| state | 是 | — | Host-owned state; clicks never imply approval. |
| description | 否 | — | Concise scope or consequence of the action. |
| error | 否 | — | Failure reason, retained while the same request can be retried. |
| intent | 否 | — | Wording of the decision; defaults to \`permission\`. |

**requestId**

```ts
string
```

**title**

```ts
string
```

**state**

```ts
QuireKitChatConfirmationState
```

```ts
"pending" | "submitting" | "approved" | "rejected" | "expired" | "failed"
```

**description**

```ts
string | undefined
```

```ts
undefined | string
```

**error**

```ts
string | undefined
```

```ts
undefined | string
```

**intent**

```ts
QuireKitChatConfirmationIntent | undefined
```

```ts
undefined | "permission" | "review"
```

#### Events

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| decide | 否 | — |  |

**decide**

```ts
[details: QuireKitChatConfirmationDecision]
```

#### Slots

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| default | 否 | — | Evidence or preview between the description and decision actions; the host owns its data. |

**default**

```ts
any
```

#### 公开实例成员

无。

#### 相关类型

```ts
type QuireKitChatConfirmationState = "pending" | "submitting" | "approved" | "rejected" | "expired" | "failed";
```
