miaopanel
1<script setup lang="ts">
2import { computed } from 'vue'
3import type { AIAction } from '../../types'
4
5const props = defineProps<{ action: AIAction; busy?: boolean }>()
6const emit = defineEmits<{ (e: 'decide', approve: boolean): void }>()
7
8const prettyArgs = computed(() => {
9 try {
10 return JSON.stringify(JSON.parse(props.action.arguments || '{}'), null, 2)
11 } catch {
12 return props.action.arguments
13 }
14})
15
16const danger = computed(() => props.action.risk === 'danger')
17</script>
18
19<template>
20 <div class="action-card" :class="{ danger }">
21 <div class="action-head">
22 <span class="risk-badge" :class="{ danger }">{{ danger ? '危险操作' : '需要确认' }}</span>
23 <b>{{ action.summary }}</b>
24 </div>
25 <pre class="mono action-args">{{ prettyArgs }}</pre>
26 <div class="action-foot">
27 <span class="hint">AI 请求执行工具 <code>{{ action.tool_name }}</code></span>
28 <div class="spacer"></div>
29 <button class="btn btn-sm btn-ghost" :disabled="busy" @click="emit('decide', false)">拒绝</button>
30 <button class="btn btn-sm" :class="danger ? 'btn-danger' : 'btn-primary'" :disabled="busy" @click="emit('decide', true)">
31 <span v-if="busy" class="spin"></span>
32 执行
33 </button>
34 </div>
35 </div>
36</template>
37
38<style scoped>
39.action-card {
40 margin-top: 10px;
41 padding: 12px 14px;
42 border-radius: 12px;
43 border: 1px solid rgba(245, 158, 11, 0.35);
44 background: #fffaf0;
45}
46.action-card.danger {
47 border-color: rgba(239, 68, 68, 0.35);
48 background: #fff5f5;
49}
50.action-head {
51 display: flex;
52 align-items: center;
53 gap: 8px;
54 margin-bottom: 8px;
55}
56.risk-badge {
57 padding: 2px 8px;
58 border-radius: 999px;
59 font-size: 11px;
60 color: #b45309;
61 background: rgba(245, 158, 11, 0.15);
62}
63.risk-badge.danger {
64 color: #b91c1c;
65 background: rgba(239, 68, 68, 0.12);
66}
67.action-args {
68 margin: 0 0 10px;
69 padding: 8px 10px;
70 border-radius: 8px;
71 background: rgba(255, 255, 255, 0.75);
72 border: 1px solid var(--line);
73 font-size: 12px;
74 max-height: 180px;
75 overflow: auto;
76 white-space: pre-wrap;
77}
78.action-foot {
79 display: flex;
80 align-items: center;
81 gap: 8px;
82}
83.action-foot code {
84 font-family: 'JetBrains Mono', Consolas, monospace;
85}
86</style>