Files
Hermes-ui/packages/client/src/views/hermes/LogsView.vue
T
ekko cd14bb1963 feat: add Anthropic format conversion for chat runs and improvements (#347)
* fix: improve chat compression and tool display

Context Compression Fixes:
- Remove duplicate token calculation in compress()
- Simplify compress() to only execute compression, not judge
- Add buildConversationHistory() to preserve tool calls in LLM context
- Remove unused estimateMessagesTokens() and contextLength parameter
- Move all judgment logic to chat-run-socket.ts (uses accurate DB tokens)

Tool Call Display Improvements:
- Add tool execution duration display (format: 1.272s)
- Add success/error status icons with circular backgrounds
- Replace text error with SVG icon (X in red circle)
- Replace old checkmark with polished green checkmark icon
- Add i18n key 'chat.executionDuration' for all locales

Bug Fixes:
- Fix streaming-indicator stuck by adding try-finally in handleEvent
- Add debug logging for compression flow diagnosis
- Fix template syntax error in MessageList.vue

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(chat): convert conversation history to Anthropic format before sending to Gateway

- Add convertToAnthropicFormat() to transform OpenAI format to Anthropic format
- Handle DeepSeek reasoning_content in thinking blocks
- Properly convert tool_use and tool_result blocks
- Add convertFromAnthropicFormat() for parsing SSE responses
- Handle stringified Python arrays in resume messages
- Record debug history files for troubleshooting (original vs converted)
- Fix tool_call_id validation to prevent empty ID errors
- Clean internal Hermes fields (call_id, response_item_id) from tool_calls

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(chat): optimize message parsing and add debug logging

- Only check for stringified arrays in assistant messages (performance)
- Improve parsing error handling: keep original content on parse failure
- Add debug logging for upstream events (reasoning/thinking tracking)
- Log run.completed event keys for troubleshooting

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(chat): add message pagination and reasoning sync improvements

**Message Pagination:**
- Add getSessionDetailPaginated() for paginated message loading
- Query with DESC order then reverse in code for optimal performance
- Remove listSessionsPaginated() (not needed)

**Reasoning Sync:**
- Add bidirectional reasoning merge in syncFromHermes
  - Memory → DB: preserve streamed reasoning from SSE events
  - DB → Memory: restore reasoning if Hermes Gateway fixes storage
- Send resumed event after sync completes with complete messages
- Fix reasoning field inconsistency: use unified 'reasoning' field

**Message Parsing:**
- Only parse stringified arrays for assistant messages (performance)
- Improve parse error handling: keep original content on failure
- Add debug logging for upstream reasoning/thinking events

**Bug Fixes:**
- Fix reasoning content display: now works on both SSE and resume
- Ensure reasoning is preserved across page refreshes via sync + resumed event

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: increase default pagination limit for messages to 500

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: remove auto-resumed event trigger and clean up debug code

- Remove automatic resumed event trigger in syncFromHermes to avoid timing issues
- Clean up unused imports (fs, join)
- Remove debug history file logging code
- Fix socket parameter passing in handleAbort, markCompleted, and syncFromHermes
- Change usage emit from room broadcast to socket-only emit
- Remove console.log debug statement

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: use reasoning field in convertToAnthropicFormat

Change convertToAnthropicFormat to read from reasoning field instead
of reasoning_content for consistency with database schema and frontend.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: parse stringified array content and improve logs

- Parse stringified array format in run.completed to extract thinking/text/tool_use
- Send parsed content to frontend via parsed_content/parsed_reasoning/parsed_tool_calls
- Frontend updates last assistant message with parsed content
- Remove ellipsis from log messages, show full content
- Add detailed logging for conversion and parsing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: move finalOutputTrimmed outside else block

* fix(chat): handle double-serialized content in resumeSession

- Remove outer quotes before parsing stringified array format
- Updated changelog for v0.5.2 and v0.5.3 with multilingual support
- Fixed message pagination with DESC query + array reverse

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(chat): improve error logging for resume parsing

- Add detailed logging for double-serialized content parsing
- Log content preview when parsing fails to diagnose issues

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* revert(chat): use simple Python-to-JSON replacement

- Revert to simple .replace(/'/g, '"') approach
- Parsing failures will keep original content as-is

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-30 16:40:37 +08:00

295 lines
7.1 KiB
Vue

<script setup lang="ts">
import { ref, onMounted, computed } from 'vue'
import { NSelect, NButton, NSpin, useMessage } from 'naive-ui'
import { useI18n } from 'vue-i18n'
import { fetchLogFiles, fetchLogs, type LogEntry } from '@/api/hermes/logs'
const { t } = useI18n()
const message = useMessage()
const logFiles = ref<{ name: string; size: string; modified: string }[]>([])
const selectedLog = ref('agent')
const entries = ref<LogEntry[]>([])
const loading = ref(false)
const lineCount = ref(100)
const levelFilter = ref<string>('')
const searchQuery = ref('')
const logOptions = computed(() =>
logFiles.value.map(f => ({ label: `${f.name} (${f.size})`, value: f.name })),
)
const levelOptions = computed(() => [
{ label: t('logs.all'), value: '' },
{ label: 'ERROR', value: 'ERROR' },
{ label: 'WARNING', value: 'WARNING' },
{ label: 'INFO', value: 'INFO' },
{ label: 'DEBUG', value: 'DEBUG' },
])
const lineOptions = [
{ label: '50', value: 50 },
{ label: '100', value: 100 },
{ label: '200', value: 200 },
{ label: '500', value: 500 },
]
const filteredEntries = computed(() => {
if (!searchQuery.value) return entries.value
const q = searchQuery.value.toLowerCase()
return entries.value.filter(e =>
e.message.toLowerCase().includes(q) ||
e.logger.toLowerCase().includes(q) ||
e.raw.toLowerCase().includes(q),
)
})
function levelClass(level: string): string {
switch (level) {
case 'ERROR': return 'level-error'
case 'WARNING': return 'level-warning'
case 'DEBUG': return 'level-debug'
default: return 'level-info'
}
}
function formatTime(ts: string): string {
const match = ts.match(/\d{2}:\d{2}:\d{2}/)
return match ? match[0] : ts
}
function parseAccessLog(msg: string) {
const match = msg.match(/"(\w+)\s+(\S+)\s+HTTP\/[^"]+"\s+(\d+)/)
if (match) return { method: match[1], path: match[2], status: match[3] }
return null
}
async function loadLogs() {
loading.value = true
try {
const data = await fetchLogs(selectedLog.value, {
lines: lineCount.value,
level: levelFilter.value || undefined,
})
entries.value = data.filter((e): e is LogEntry => e !== null)
} catch (e: any) {
message.error(e.message)
} finally {
loading.value = false
}
}
onMounted(async () => {
logFiles.value = await fetchLogFiles()
await loadLogs()
})
</script>
<template>
<div class="logs-view">
<header class="page-header">
<h2 class="header-title">{{ t('logs.title') }}</h2>
<div class="header-actions">
<NSelect
v-model:value="selectedLog"
:options="logOptions"
size="small"
class="input-md"
@update:value="loadLogs"
/>
<NSelect
:value="levelFilter"
:options="levelOptions"
size="small"
class="input-sm"
@update:value="(v: string) => { levelFilter = v; loadLogs() }"
/>
<NSelect
:value="lineCount"
:options="lineOptions"
size="small"
class="input-sm"
@update:value="(v: number) => { lineCount = v; loadLogs() }"
/>
<input
v-model="searchQuery"
class="search-input"
:placeholder="t('logs.searchPlaceholder')"
/>
<NButton size="small" :loading="loading" @click="loadLogs">{{ t('logs.refresh') }}</NButton>
</div>
</header>
<div class="logs-body">
<NSpin :show="loading">
<div v-if="filteredEntries.length === 0 && !loading" class="logs-empty">
{{ t('logs.noEntries') }}
</div>
<div class="log-list">
<div
v-for="(entry, idx) in filteredEntries"
:key="idx"
class="log-entry"
:class="levelClass(entry.level)"
>
<span class="log-time">{{ formatTime(entry.timestamp) }}</span>
<span class="log-level" :class="levelClass(entry.level)">{{ entry.level }}</span>
<span class="log-logger">{{ entry.logger }}</span>
<template v-if="parseAccessLog(entry.message)">
<span class="access-method">{{ parseAccessLog(entry.message)!.method }}</span>
<span class="access-path">{{ parseAccessLog(entry.message)!.path }}</span>
<span class="access-status" :class="'status-' + (parseAccessLog(entry.message)!.status?.[0] || 'x')">
{{ parseAccessLog(entry.message)!.status }}
</span>
</template>
<span v-else class="log-message">{{ entry.message }}</span>
</div>
</div>
</NSpin>
</div>
</div>
</template>
<style scoped lang="scss">
@use '@/styles/variables' as *;
.logs-view {
height: calc(100 * var(--vh));
display: flex;
flex-direction: column;
}
.page-header {
gap: 12px;
flex-wrap: wrap;
}
.header-actions {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
}
.search-input {
padding: 4px 10px;
border: 1px solid $border-color;
border-radius: $radius-sm;
background: $bg-input;
color: $text-primary;
font-size: 13px;
outline: none;
width: 160px;
transition: border-color $transition-fast;
&:focus { border-color: $accent-primary; }
&::placeholder { color: $text-muted; }
}
.logs-body {
flex: 1;
overflow-y: auto;
min-height: 0;
}
.logs-empty {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
color: $text-muted;
font-size: 13px;
}
.log-list {
padding: 4px 0;
}
.log-entry {
display: flex;
align-items: center;
gap: 8px;
padding: 3px 20px;
font-family: $font-code;
font-size: 12px;
line-height: 1.6;
border-left: 2px solid transparent;
&:hover {
background-color: rgba(var(--accent-primary-rgb), 0.03);
}
&.level-error {
border-left-color: $error;
.log-message { color: $error; }
}
&.level-warning {
border-left-color: $warning;
.log-message { color: $warning; }
}
}
.log-time {
color: $text-muted;
flex-shrink: 0;
font-variant-numeric: tabular-nums;
}
.log-level {
flex-shrink: 0;
font-weight: 600;
font-size: 10px;
padding: 0 4px;
border-radius: 2px;
min-width: 42px;
text-align: center;
&.level-error { background: rgba(var(--error-rgb), 0.12); color: $error; }
&.level-warning { background: rgba(var(--warning-rgb), 0.12); color: $warning; }
&.level-debug { background: rgba(var(--accent-primary-rgb), 0.06); color: $text-muted; }
&.level-info { background: rgba(var(--accent-primary-rgb), 0.06); color: $text-muted; }
}
.log-logger {
color: $text-muted;
flex-shrink: 0;
max-width: 160px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.log-message {
color: $text-secondary;
overflow: visible;
white-space: normal;
word-break: break-word;
min-width: 0;
}
.access-method {
font-weight: 600;
color: $text-primary;
flex-shrink: 0;
}
.access-path {
color: $accent-primary;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
}
.access-status {
font-weight: 600;
flex-shrink: 0;
font-size: 11px;
&.status-2 { color: $success; }
&.status-3 { color: $warning; }
&.status-4 { color: $error; }
&.status-5 { color: $error; }
}
</style>