* feat: add file browser and file download with multi-backend support Adds a built-in File Browser page and a File Download system to Hermes Web UI, enabling users to browse, edit, preview, upload, and download files from the workspace directly from the web dashboard. File Browser (/hermes/files): - New view FilesView.vue plus components under components/hermes/files/ (FileTree, FileList, FileBreadcrumb, FileToolbar, FileContextMenu, FileEditor, FilePreview, FileRenameModal, FileUploadModal) - New Pinia store stores/hermes/files.ts for directory tree, selection, and editing state - New API module api/hermes/files.ts - New server routes routes/hermes/files.ts with CRUD, rename, upload, and directory listing - New service services/hermes/file-provider.ts with a pluggable provider architecture (local filesystem + multi-terminal backends) File Download: - New server route routes/hermes/download.ts and client API api/hermes/download.ts - Integration in chat messages (MessageItem.vue, MarkdownRenderer.vue) to surface downloadable file references Packaging: - package.json: add a prepare script so the package can be installed directly from a git URL with dist/ built automatically i18n: add files/download translations to en.ts and zh.ts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: use clipboard fallback for non-secure HTTP contexts navigator.clipboard is undefined on HTTP intranet deployments (only available in secure contexts). The previous synchronous calls threw silently and the success toast still fired, making 'copy' actions appear broken. - Add packages/client/src/utils/clipboard.ts with execCommand fallback via a hidden textarea - Use the helper in FileContextMenu (copy file path), CodexLoginModal (copy user code), NousLoginModal (copy user code), ChatPanel (copy session id) - Each call now awaits the result and shows success/failure based on the actual outcome Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
136 lines
3.2 KiB
Vue
136 lines
3.2 KiB
Vue
<script setup lang="ts">
|
|
import { ref, onMounted, onBeforeUnmount } from 'vue'
|
|
import { NButton, NSpace, useMessage, useDialog } from 'naive-ui'
|
|
import { useI18n } from 'vue-i18n'
|
|
import { useFilesStore } from '@/stores/hermes/files'
|
|
import * as monaco from 'monaco-editor'
|
|
|
|
// Configure Monaco workers using import.meta.url
|
|
;(self as any).MonacoEnvironment = {
|
|
getWorker(_: any, _label: string) {
|
|
return new Worker(
|
|
new URL('monaco-editor/esm/vs/editor/editor.worker.js', import.meta.url),
|
|
{ type: 'module' }
|
|
)
|
|
},
|
|
}
|
|
|
|
const { t } = useI18n()
|
|
const message = useMessage()
|
|
const dialogApi = useDialog()
|
|
const filesStore = useFilesStore()
|
|
|
|
const editorContainer = ref<HTMLElement | null>(null)
|
|
let editor: monaco.editor.IStandaloneCodeEditor | null = null
|
|
const saving = ref(false)
|
|
|
|
onMounted(() => {
|
|
if (!editorContainer.value || !filesStore.editingFile) return
|
|
|
|
editor = monaco.editor.create(editorContainer.value, {
|
|
value: filesStore.editingFile.content,
|
|
language: filesStore.editingFile.language,
|
|
theme: document.documentElement.classList.contains('dark') ? 'vs-dark' : 'vs',
|
|
minimap: { enabled: false },
|
|
fontSize: 13,
|
|
lineNumbers: 'on',
|
|
scrollBeyondLastLine: false,
|
|
automaticLayout: true,
|
|
tabSize: 2,
|
|
wordWrap: 'on',
|
|
})
|
|
|
|
editor.onDidChangeModelContent(() => {
|
|
if (filesStore.editingFile) {
|
|
filesStore.editingFile.content = editor!.getValue()
|
|
}
|
|
})
|
|
|
|
// Ctrl/Cmd + S to save
|
|
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, () => {
|
|
handleSave()
|
|
})
|
|
})
|
|
|
|
onBeforeUnmount(() => {
|
|
editor?.dispose()
|
|
editor = null
|
|
})
|
|
|
|
async function handleSave() {
|
|
saving.value = true
|
|
try {
|
|
await filesStore.saveEditor()
|
|
message.success(t('files.saved'))
|
|
} catch {
|
|
message.error(t('files.saveFailed'))
|
|
} finally {
|
|
saving.value = false
|
|
}
|
|
}
|
|
|
|
function handleClose() {
|
|
if (filesStore.hasUnsavedChanges) {
|
|
dialogApi.warning({
|
|
title: t('files.unsavedChanges'),
|
|
positiveText: t('common.ok'),
|
|
negativeText: t('common.cancel'),
|
|
onPositiveClick: () => {
|
|
filesStore.closeEditor()
|
|
},
|
|
})
|
|
} else {
|
|
filesStore.closeEditor()
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="file-editor">
|
|
<div class="editor-header">
|
|
<span class="editor-filename">{{ filesStore.editingFile?.path }}</span>
|
|
<NSpace>
|
|
<NButton size="small" type="primary" :loading="saving" @click="handleSave">
|
|
{{ t('files.saveFile') }}
|
|
</NButton>
|
|
<NButton size="small" @click="handleClose">
|
|
{{ t('files.closeEditor') }}
|
|
</NButton>
|
|
</NSpace>
|
|
</div>
|
|
<div ref="editorContainer" class="editor-container" />
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped lang="scss">
|
|
@use '@/styles/variables' as *;
|
|
|
|
.file-editor {
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100%;
|
|
}
|
|
|
|
.editor-header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 8px 16px;
|
|
border-bottom: 1px solid $border-color;
|
|
background-color: $bg-card;
|
|
}
|
|
|
|
.editor-filename {
|
|
font-size: 13px;
|
|
color: $text-secondary;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.editor-container {
|
|
flex: 1;
|
|
min-height: 0;
|
|
}
|
|
</style>
|