codexToolCard.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div class="codex-step" :class="[`codex-step--${item.kind}`, { 'is-error': item.kind === 'error' }]">
  3. <span class="codex-step__node">
  4. <Icon :icon="icon" :size="13" />
  5. </span>
  6. <div class="codex-step__main">
  7. <div class="codex-step__title">{{ item.title }}</div>
  8. <div v-if="preview" class="codex-step__preview">{{ preview }}</div>
  9. <div v-if="open" class="codex-step__expand" :style="bodyStyle">
  10. <div class="codex-step__cap">{{ item.message.length }} 字 · 点击收起</div>
  11. <pre class="codex-pre"><code>{{ item.message }}</code></pre>
  12. </div>
  13. </div>
  14. <div class="codex-step__side">
  15. <span class="codex-step__time">{{ formatCodexTime(item.timestamp) }}</span>
  16. <button class="codex-step__toggle" type="button" :title="open ? '收起' : '展开详情'" @click="open = !open">
  17. <Icon :icon="open ? 'mdi:chevron-up' : 'mdi:chevron-down'" :size="14" />
  18. </button>
  19. </div>
  20. </div>
  21. </template>
  22. <script lang="ts" setup>
  23. /**
  24. * 执行步骤行:执行过程步骤栈里的一条(命令 / 文件变更 / 计划 / 错误 / 审批留痕)。
  25. *
  26. * 节点图标按 kind 染色;正文预览取第一行(等宽字体、省略号),点击展开完整内容 ——
  27. * 过程信息的价值在「可核对」,不在「占据版面」。
  28. */
  29. import { computed, ref } from 'vue';
  30. import Icon from '@/core/components/Icon/src/Icon.vue';
  31. import type { CodexProcessItem } from '../types/codexTypes';
  32. import { formatCodexTime } from '../utils/codexFormat';
  33. const props = withDefaults(defineProps<{ item: CodexProcessItem; defaultOpen?: boolean }>(), {
  34. defaultOpen: false,
  35. });
  36. const open = ref(props.defaultOpen);
  37. const ICONS: Record<string, string> = {
  38. lifecycle: 'mdi:progress-clock',
  39. thought: 'mdi:head-snowflake-outline',
  40. tool: 'mdi:console-line',
  41. file: 'mdi:file-document-edit-outline',
  42. plan: 'mdi:clipboard-text-outline',
  43. error: 'mdi:alert-circle-outline',
  44. approval: 'mdi:shield-check-outline',
  45. };
  46. const icon = computed(() => ICONS[props.item.kind] ?? 'mdi:information-outline');
  47. const preview = computed(() => {
  48. const text = props.item.message.trim();
  49. if (!text) return '';
  50. const firstLine = text.split('\n')[0] ?? '';
  51. return firstLine.length > 120 ? `${firstLine.slice(0, 120)}…` : firstLine;
  52. });
  53. const bodyStyle = computed(() => (props.item.message.length > 4000 ? { maxHeight: '420px' } : {}));
  54. </script>
  55. <style lang="less">
  56. .codex-step {
  57. display: grid;
  58. grid-template-columns: 22px 1fr auto;
  59. gap: 10px;
  60. align-items: start;
  61. padding: 7px 2px;
  62. & + & {
  63. border-top: 1px dashed var(--codex-border);
  64. }
  65. &__node {
  66. display: inline-flex;
  67. align-items: center;
  68. justify-content: center;
  69. width: 22px;
  70. height: 22px;
  71. margin-top: 1px;
  72. color: #fff;
  73. background: var(--codex-primary);
  74. border-radius: 6px;
  75. .codex-step--file & {
  76. background: var(--codex-warning);
  77. }
  78. .codex-step--plan & {
  79. background: #0e7c86;
  80. }
  81. .codex-step--error &,
  82. .codex-step.is-error & {
  83. background: var(--codex-error);
  84. }
  85. .codex-step--approval & {
  86. background: var(--codex-success);
  87. }
  88. .codex-step.is-error--approval & {
  89. background: var(--codex-error);
  90. }
  91. }
  92. &__main {
  93. min-width: 0;
  94. }
  95. &__title {
  96. overflow: hidden;
  97. font-size: 13px;
  98. font-weight: 500;
  99. color: var(--codex-text);
  100. white-space: nowrap;
  101. text-overflow: ellipsis;
  102. .codex-step.is-error & {
  103. color: var(--codex-error);
  104. }
  105. .codex-step--approval & {
  106. font-weight: 600;
  107. }
  108. }
  109. &__preview {
  110. margin-top: 2px;
  111. overflow: hidden;
  112. font-family: var(--codex-font-mono);
  113. font-size: 12px;
  114. color: var(--codex-text-3);
  115. white-space: nowrap;
  116. text-overflow: ellipsis;
  117. }
  118. &__expand {
  119. margin-top: 8px;
  120. .codex-pre {
  121. max-height: 260px;
  122. margin: 0;
  123. }
  124. }
  125. &__cap {
  126. margin-bottom: 4px;
  127. font-size: 11px;
  128. color: var(--codex-text-3);
  129. }
  130. &__side {
  131. display: flex;
  132. align-items: center;
  133. gap: 4px;
  134. padding-top: 2px;
  135. }
  136. &__time {
  137. font-size: 11px;
  138. color: var(--codex-text-3);
  139. }
  140. &__toggle {
  141. display: inline-flex;
  142. align-items: center;
  143. justify-content: center;
  144. width: 22px;
  145. height: 22px;
  146. color: var(--codex-text-3);
  147. background: transparent;
  148. border: none;
  149. border-radius: 5px;
  150. cursor: pointer;
  151. &:hover {
  152. color: var(--codex-primary);
  153. background: var(--codex-bg-hover);
  154. }
  155. }
  156. }
  157. </style>