feat: implement fixed local API port settings for desktop app, allowing users to specify a port for consistent access, with corresponding UI and translations
This commit is contained in:
@@ -36,3 +36,13 @@ func (a *App) GetAPIBaseURL() string {
|
||||
}
|
||||
return strings.TrimRight(a.backendURL, "/") + "/api/v1"
|
||||
}
|
||||
|
||||
// GetDesktopHTTPPortSetting returns the saved local API port (0 = random port each launch).
|
||||
func (a *App) GetDesktopHTTPPortSetting() int {
|
||||
return LoadDesktopPrefsHTTPPort()
|
||||
}
|
||||
|
||||
// SetDesktopHTTPPortSetting saves the preferred local API port to application support. Restart the app for it to take effect unless it matches the current listener.
|
||||
func (a *App) SetDesktopHTTPPortSetting(port int) error {
|
||||
return SaveDesktopHTTPPortPreference(port)
|
||||
}
|
||||
|
||||
+14
-6
@@ -214,18 +214,15 @@ func main() {
|
||||
) error {
|
||||
server := &http.Server{Handler: router}
|
||||
|
||||
// Use port 0 to assign a random free port for the desktop app
|
||||
// Force localhost binding to prevent firewall popups on macOS
|
||||
addr := "127.0.0.1:0"
|
||||
// 127.0.0.1 + saved port from settings (desktop-prefs.json), or :0 for random free port.
|
||||
addr := desktopBackendListenAddr()
|
||||
|
||||
listener, err := listenWithRetry(addr, 10, 300*time.Millisecond)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to start server: %v", err)
|
||||
}
|
||||
|
||||
// Get the actual assigned port
|
||||
actualPort := listener.Addr().(*net.TCPAddr).Port
|
||||
actualAddr := fmt.Sprintf("127.0.0.1:%d", actualPort)
|
||||
actualAddr := listener.Addr().(*net.TCPAddr).String()
|
||||
|
||||
// Store the backend URL so Wails can load it
|
||||
app.backendURL = fmt.Sprintf("http://%s", actualAddr)
|
||||
@@ -413,6 +410,17 @@ func resolveDesktopDataPath(rawPath, defaultRelativePath, appSupportDir string)
|
||||
return filepath.Join(appSupportDir, filepath.Clean(trimmed))
|
||||
}
|
||||
|
||||
// desktopBackendListenAddr returns the TCP address for the embedded Gin server (Wails desktop).
|
||||
// Always binds loopback 127.0.0.1. Uses saved UI preference (desktop-prefs.json) when set, else ephemeral port :0.
|
||||
func desktopBackendListenAddr() string {
|
||||
const host = "127.0.0.1"
|
||||
pref := LoadDesktopPrefsHTTPPort()
|
||||
if pref >= 1 && pref <= 65535 {
|
||||
return net.JoinHostPort(host, strconv.Itoa(pref))
|
||||
}
|
||||
return net.JoinHostPort(host, "0")
|
||||
}
|
||||
|
||||
func migrateLegacyDesktopData(resourcesDir, targetDataDir string) {
|
||||
legacyDataDir := filepath.Join(resourcesDir, "data")
|
||||
if info, err := os.Stat(legacyDataDir); err != nil || !info.IsDir() {
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const desktopPrefsFileName = "desktop-prefs.json"
|
||||
|
||||
type desktopPrefs struct {
|
||||
HTTPPort int `json:"http_port"`
|
||||
}
|
||||
|
||||
func desktopPrefsDir() (string, error) {
|
||||
cfg, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
dir := filepath.Join(cfg, "WeKnora Lite")
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dir, nil
|
||||
}
|
||||
|
||||
func desktopPrefsFilePath() (string, error) {
|
||||
dir, err := desktopPrefsDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(dir, desktopPrefsFileName), nil
|
||||
}
|
||||
|
||||
// LoadDesktopPrefsHTTPPort returns http_port from prefs file, or 0 if unset / invalid (ephemeral port on each launch).
|
||||
func LoadDesktopPrefsHTTPPort() int {
|
||||
path, err := desktopPrefsFilePath()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
var p desktopPrefs
|
||||
if json.Unmarshal(data, &p) != nil {
|
||||
return 0
|
||||
}
|
||||
if p.HTTPPort < 0 || p.HTTPPort > 65535 {
|
||||
return 0
|
||||
}
|
||||
return p.HTTPPort
|
||||
}
|
||||
|
||||
// SaveDesktopHTTPPortPreference persists listen port preference. port 0 means use a random free port on each launch.
|
||||
func SaveDesktopHTTPPortPreference(port int) error {
|
||||
if port < 0 || port > 65535 {
|
||||
return fmt.Errorf("invalid port")
|
||||
}
|
||||
path, err := desktopPrefsFilePath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p := desktopPrefs{HTTPPort: port}
|
||||
data, err := json.MarshalIndent(p, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, data, 0o600)
|
||||
}
|
||||
@@ -163,3 +163,16 @@ data/
|
||||
```
|
||||
|
||||
备份只需复制整个 `data/` 目录。
|
||||
|
||||
## 桌面版(Wails)与 Chrome 扩展
|
||||
|
||||
桌面 **WeKnora Lite** 内置的 HTTP API 默认监听 **`127.0.0.1` 上的随机端口**(避免每次启动占用固定端口、并减少系统防火墙提示)。浏览器里的 **Chrome 扩展**与网页不同,需要你在扩展里填写明确的 API 地址(例如 `http://127.0.0.1:<端口>/api/v1`),因此会遇到两类问题:
|
||||
|
||||
1. **端口每次变**:重启桌面应用后端口可能变化,扩展里保存的地址会失效。
|
||||
2. **扩展权限**:上架的扩展须在 `manifest.json` 的 `host_permissions`(或同类字段)中声明对 **`http://127.0.0.1/*`** 和/或 **`http://localhost/*`** 的访问,否则无法请求本机 Lite服务。
|
||||
|
||||
**推荐做法**
|
||||
|
||||
- 在桌面应用内打开 **设置 → API 信息**,在 **「本地 API 端口(桌面版)」** 中填写固定端口(如 `37841`)并保存,**重启应用** 后端口即固定;配置会写入用户配置目录下的 `desktop-prefs.json`。
|
||||
- 启动桌面应用后,在同一页复制 **API 根路径**(与 `http://127.0.0.1:<端口>/api/v1` 一致),粘贴到扩展配置;扩展侧 API Key 与网页版租户 API Key 相同。
|
||||
- 若扩展仍无法连接:确认扩展已声明上述 `host_permissions`;可尝试把地址里的主机从 `localhost` 改成 **`127.0.0.1`**(或反之)以排除解析差异。
|
||||
|
||||
@@ -22,10 +22,6 @@
|
||||
<t-icon name="control-platform" class="menu-icon" />
|
||||
<span>{{ $t('settings.modelManagement') }}</span>
|
||||
</div>
|
||||
<div class="menu-item" @click="handleQuickNav('ollama')">
|
||||
<t-icon name="server" class="menu-icon" />
|
||||
<span>Ollama</span>
|
||||
</div>
|
||||
<div class="menu-item" @click="handleQuickNav('websearch')">
|
||||
<svg
|
||||
width="16"
|
||||
@@ -47,36 +43,16 @@
|
||||
<t-icon name="tools" class="menu-icon" />
|
||||
<span>{{ $t('settings.mcpService') }}</span>
|
||||
</div>
|
||||
<div class="menu-item" @click="handleQuickNav('api')">
|
||||
<t-icon name="secured" class="menu-icon" />
|
||||
<span>{{ $t('settings.apiInfo') }}</span>
|
||||
</div>
|
||||
<div class="menu-divider"></div>
|
||||
<div class="menu-item" @click="handleSettings">
|
||||
<t-icon name="setting" class="menu-icon" />
|
||||
<span>{{ $t('general.allSettings') }}</span>
|
||||
</div>
|
||||
<div class="menu-divider"></div>
|
||||
<div class="menu-item" @click="openApiDoc">
|
||||
<t-icon name="book" class="menu-icon" />
|
||||
<span class="menu-text-with-icon">
|
||||
<span>{{ $t('tenant.apiDocument') }}</span>
|
||||
<svg class="menu-external-icon" viewBox="0 0 16 16" aria-hidden="true">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M12.667 8a.667.667 0 0 1 .666.667v4a2.667 2.667 0 0 1-2.666 2.666H4.667a2.667 2.667 0 0 1-2.667-2.666V5.333a2.667 2.667 0 0 1 2.667-2.666h4a.667.667 0 1 1 0 1.333h-4a1.333 1.333 0 0 0-1.333 1.333v7.334A1.333 1.333 0 0 0 4.667 13.333h6a1.333 1.333 0 0 0 1.333-1.333v-4A.667.667 0 0 1 12.667 8Zm2.666-6.667v4a.667.667 0 0 1-1.333 0V3.276l-5.195 5.195a.667.667 0 0 1-.943-.943l5.195-5.195h-2.057a.667.667 0 0 1 0-1.333h4a.667.667 0 0 1 .666.666Z"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
<div class="menu-item" @click="openWebsite">
|
||||
<t-icon name="home" class="menu-icon" />
|
||||
<span class="menu-text-with-icon">
|
||||
<span>{{ $t('common.website') }}</span>
|
||||
<svg class="menu-external-icon" viewBox="0 0 16 16" aria-hidden="true">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M12.667 8a.667.667 0 0 1 .666.667v4a2.667 2.667 0 0 1-2.666 2.666H4.667a2.667 2.667 0 0 1-2.667-2.666V5.333a2.667 2.667 0 0 1 2.667-2.666h4a.667.667 0 1 1 0 1.333h-4a1.333 1.333 0 0 0-1.333 1.333v7.334A1.333 1.333 0 0 0 4.667 13.333h6a1.333 1.333 0 0 0 1.333-1.333v-4A.667.667 0 0 1 12.667 8Zm2.666-6.667v4a.667.667 0 0 1-1.333 0V3.276l-5.195 5.195a.667.667 0 0 1-.943-.943l5.195-5.195h-2.057a.667.667 0 0 1 0-1.333h4a.667.667 0 0 1 .666.666Z"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
<div class="menu-item" @click="openClawhubSkill">
|
||||
<span class="menu-icon menu-icon--emoji" role="img" :aria-label="$t('common.clawhubSkill')">🦞</span>
|
||||
<span class="menu-text-with-icon">
|
||||
@@ -187,18 +163,6 @@ const handleSettings = () => {
|
||||
router.push('/platform/settings')
|
||||
}
|
||||
|
||||
// 打开 API 文档
|
||||
const openApiDoc = () => {
|
||||
menuVisible.value = false
|
||||
window.open('https://github.com/Tencent/WeKnora/blob/main/docs/api/README.md', '_blank')
|
||||
}
|
||||
|
||||
// 打开官网
|
||||
const openWebsite = () => {
|
||||
menuVisible.value = false
|
||||
window.open('https://weknora.weixin.qq.com/', '_blank')
|
||||
}
|
||||
|
||||
const CHROME_EXTENSION_URL =
|
||||
'https://chromewebstore.google.com/detail/jpemjbopikggjlmikmclgbmkhhopjdgd?utm_source=item-share-cb'
|
||||
|
||||
|
||||
@@ -1979,7 +1979,14 @@ export default {
|
||||
createdAtDescription: 'Time when the account was created',
|
||||
noKey: 'No API Key available',
|
||||
copySuccess: 'API Key copied to clipboard',
|
||||
copyFailed: 'Copy failed, please copy manually'
|
||||
copyFailed: 'Copy failed, please copy manually',
|
||||
desktopPortLabel: 'Local API port (desktop)',
|
||||
desktopPortDescription:
|
||||
'Use a fixed port (e.g. 37841) so tools like the Chrome extension can keep the same API URL. 0 means a random port each launch. Restart the app after saving.',
|
||||
desktopPortSave: 'Save',
|
||||
desktopPortSaved: 'Saved. Restart the app for it to take effect.',
|
||||
desktopPortSaveFailed: 'Save failed',
|
||||
desktopPortInvalid: 'Enter a port between 0 and 65535',
|
||||
}
|
||||
},
|
||||
system: {
|
||||
|
||||
@@ -1428,6 +1428,13 @@ export default {
|
||||
noKey: "API 키 없음",
|
||||
copySuccess: "API 키가 클립보드에 복사되었습니다",
|
||||
copyFailed: "복사 실패, 수동으로 복사해주세요",
|
||||
desktopPortLabel: "로컬 API 포트 (데스크톱)",
|
||||
desktopPortDescription:
|
||||
"Chrome 확장 프로그램 등에서 동일한 API 주소를 쓰려면 고정 포트(예: 37841)를 지정하세요. 0이면 매번 다른 포트입니다. 저장 후 앱을 다시 시작하세요.",
|
||||
desktopPortSave: "저장",
|
||||
desktopPortSaved: "저장되었습니다. 적용하려면 앱을 다시 시작하세요.",
|
||||
desktopPortSaveFailed: "저장 실패",
|
||||
desktopPortInvalid: "0~65535 사이의 포트를 입력하세요",
|
||||
},
|
||||
},
|
||||
system: {
|
||||
|
||||
@@ -1274,7 +1274,14 @@ export default {
|
||||
createdAtDescription: 'Время создания учётной записи',
|
||||
noKey: 'API Key отсутствует',
|
||||
copySuccess: 'API Key скопирован в буфер обмена',
|
||||
copyFailed: 'Не удалось скопировать, пожалуйста, сделайте это вручную'
|
||||
copyFailed: 'Не удалось скопировать, пожалуйста, сделайте это вручную',
|
||||
desktopPortLabel: 'Локальный порт API (desktop)',
|
||||
desktopPortDescription:
|
||||
'Укажите фиксированный порт (например, 37841), чтобы расширение Chrome и другие инструменты всегда использовали один URL API. 0 — случайный порт при каждом запуске. После сохранения перезапустите приложение.',
|
||||
desktopPortSave: 'Сохранить',
|
||||
desktopPortSaved: 'Сохранено. Перезапустите приложение, чтобы применить.',
|
||||
desktopPortSaveFailed: 'Не удалось сохранить',
|
||||
desktopPortInvalid: 'Введите порт от 0 до 65535',
|
||||
}
|
||||
},
|
||||
system: {
|
||||
|
||||
@@ -1422,6 +1422,13 @@ export default {
|
||||
noKey: "暂无 API Key",
|
||||
copySuccess: "API Key 已复制到剪贴板",
|
||||
copyFailed: "复制失败,请手动复制",
|
||||
desktopPortLabel: "本地 API 端口(桌面版)",
|
||||
desktopPortDescription:
|
||||
"填写固定端口(如 37841)后,Chrome 扩展等工具可长期使用同一 API 地址;0 表示每次启动随机端口。保存后请重启应用生效。",
|
||||
desktopPortSave: "保存",
|
||||
desktopPortSaved: "已保存,请重启应用后生效",
|
||||
desktopPortSaveFailed: "保存失败",
|
||||
desktopPortInvalid: "请输入 0–65535 之间的端口",
|
||||
},
|
||||
},
|
||||
system: {
|
||||
|
||||
@@ -81,6 +81,29 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Desktop (Wails): fixed local API port for Chrome extension etc. -->
|
||||
<div v-if="showDesktopPortSetting" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('tenant.api.desktopPortLabel') }}</label>
|
||||
<p class="desc">{{ $t('tenant.api.desktopPortDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="api-key-control">
|
||||
<div class="desktop-port-input-wrap">
|
||||
<t-input-number
|
||||
v-model="desktopPortInput"
|
||||
:min="0"
|
||||
:max="65535"
|
||||
theme="normal"
|
||||
/>
|
||||
</div>
|
||||
<t-button size="small" variant="text" @click="saveDesktopPort">
|
||||
{{ $t('tenant.api.desktopPortSave') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- API docs -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
@@ -163,6 +186,8 @@ const error = ref('')
|
||||
const showApiKey = ref(false)
|
||||
/** WeKnora Lite (Wails): real API origin is loopback + dynamic port, not window.location.origin */
|
||||
const wailsApiBaseURL = ref<string | null>(null)
|
||||
const showDesktopPortSetting = ref(false)
|
||||
const desktopPortInput = ref<number | undefined>(0)
|
||||
|
||||
// Computed
|
||||
const displayApiKey = computed(() => {
|
||||
@@ -196,6 +221,8 @@ type WeKnoraDesktopWindow = Window & {
|
||||
main?: {
|
||||
App?: {
|
||||
GetAPIBaseURL?: () => Promise<string> | string
|
||||
GetDesktopHTTPPortSetting?: () => Promise<number> | number
|
||||
SetDesktopHTTPPortSetting?: (port: number) => Promise<void> | void
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -225,6 +252,41 @@ async function tryLoadWailsApiBaseURL() {
|
||||
}
|
||||
}
|
||||
|
||||
function desktopPortBindingsAvailable(win: WeKnoraDesktopWindow) {
|
||||
const app = win.go?.main?.App
|
||||
return typeof app?.GetDesktopHTTPPortSetting === 'function' && typeof app?.SetDesktopHTTPPortSetting === 'function'
|
||||
}
|
||||
|
||||
async function loadDesktopPortPrefs() {
|
||||
const win = window as WeKnoraDesktopWindow
|
||||
if (!desktopPortBindingsAvailable(win)) return
|
||||
showDesktopPortSetting.value = true
|
||||
try {
|
||||
const p = await Promise.resolve(win.go!.main!.App!.GetDesktopHTTPPortSetting!())
|
||||
desktopPortInput.value = typeof p === 'number' ? p : 0
|
||||
} catch {
|
||||
desktopPortInput.value = 0
|
||||
}
|
||||
}
|
||||
|
||||
const saveDesktopPort = async () => {
|
||||
const v = desktopPortInput.value
|
||||
const port = typeof v === 'number' && !Number.isNaN(v) ? Math.floor(v) : 0
|
||||
if (port < 0 || port > 65535) {
|
||||
MessagePlugin.warning(t('tenant.api.desktopPortInvalid'))
|
||||
return
|
||||
}
|
||||
const win = window as WeKnoraDesktopWindow
|
||||
const fn = win.go?.main?.App?.SetDesktopHTTPPortSetting
|
||||
if (typeof fn !== 'function') return
|
||||
try {
|
||||
await Promise.resolve(fn(port))
|
||||
MessagePlugin.success(t('tenant.api.desktopPortSaved'))
|
||||
} catch (err: unknown) {
|
||||
MessagePlugin.error(err instanceof Error ? err.message : t('tenant.api.desktopPortSaveFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
// Methods
|
||||
const loadInfo = async () => {
|
||||
try {
|
||||
@@ -314,8 +376,9 @@ const formatDate = (dateStr: string | undefined) => {
|
||||
}
|
||||
|
||||
// Lifecycle
|
||||
onMounted(() => {
|
||||
void tryLoadWailsApiBaseURL()
|
||||
onMounted(async () => {
|
||||
await tryLoadWailsApiBaseURL()
|
||||
await loadDesktopPortPrefs()
|
||||
loadInfo()
|
||||
})
|
||||
</script>
|
||||
@@ -421,7 +484,7 @@ onMounted(() => {
|
||||
min-width: 280px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
align-items: flex-start;
|
||||
|
||||
.info-value {
|
||||
font-size: 14px;
|
||||
@@ -449,5 +512,24 @@ onMounted(() => {
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* 与 API Key / API 地址 行一致:输入区占满 flex 剩余宽度,文案按钮贴右 */
|
||||
.desktop-port-input-wrap {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
:deep(.t-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
:deep(.t-input__wrap) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
:deep(input) {
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -3,37 +3,31 @@
|
||||
<div class="section-header">
|
||||
<h2>{{ $t('modelSettings.title') }}</h2>
|
||||
<p class="section-description">{{ $t('modelSettings.description') }}</p>
|
||||
|
||||
<!-- 内置模型说明 -->
|
||||
<div class="builtin-models-info">
|
||||
<div class="info-box">
|
||||
<div class="info-header">
|
||||
<t-icon name="info-circle" class="info-icon" />
|
||||
<span class="info-title">{{ $t('modelSettings.builtinModels.title') }}</span>
|
||||
</div>
|
||||
<div class="info-content">
|
||||
<p>{{ $t('modelSettings.builtinModels.description') }}</p>
|
||||
<p class="doc-link">
|
||||
<t-icon name="link" class="link-icon" />
|
||||
<a href="https://github.com/Tencent/WeKnora/blob/main/docs/BUILTIN_MODELS.md" target="_blank" rel="noopener noreferrer">
|
||||
{{ $t('modelSettings.builtinModels.viewGuide') }}
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="builtin-models-hint" role="note">
|
||||
<p class="builtin-hint-label">{{ $t('modelSettings.builtinModels.title') }}</p>
|
||||
<p class="builtin-hint-text">{{ $t('modelSettings.builtinModels.description') }}</p>
|
||||
<a
|
||||
class="builtin-hint-link"
|
||||
href="https://github.com/Tencent/WeKnora/blob/main/docs/BUILTIN_MODELS.md"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{{ $t('modelSettings.builtinModels.viewGuide') }}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 对话模型 -->
|
||||
<div class="model-category-section" data-model-type="chat">
|
||||
<div class="category-header">
|
||||
<div class="header-info">
|
||||
<div class="settings-group model-type-group" data-model-type="chat">
|
||||
<div class="section-subheader">
|
||||
<div class="subheader-text">
|
||||
<h3>{{ $t('modelSettings.chat.title') }}</h3>
|
||||
<p>{{ $t('modelSettings.chat.desc') }}</p>
|
||||
<p class="section-desc">{{ $t('modelSettings.chat.desc') }}</p>
|
||||
</div>
|
||||
<t-button size="small" theme="primary" @click="openAddDialog('chat')" class="add-model-btn">
|
||||
<t-button theme="primary" size="small" @click="openAddDialog('chat')">
|
||||
<template #icon>
|
||||
<t-icon name="add" class="add-icon" />
|
||||
<add-icon />
|
||||
</template>
|
||||
{{ $t('modelSettings.actions.addModel') }}
|
||||
</t-button>
|
||||
@@ -65,24 +59,27 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty-state">
|
||||
<p class="empty-text">{{ $t('modelSettings.chat.empty') }}</p>
|
||||
<t-button theme="default" variant="outline" size="small" @click="openAddDialog('chat')">
|
||||
<div v-else class="empty-models">
|
||||
<p>{{ $t('modelSettings.chat.empty') }}</p>
|
||||
<t-button theme="primary" size="small" @click="openAddDialog('chat')">
|
||||
<template #icon>
|
||||
<add-icon />
|
||||
</template>
|
||||
{{ $t('modelSettings.actions.addModel') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Embedding 模型 -->
|
||||
<div class="model-category-section" data-model-type="embedding">
|
||||
<div class="category-header">
|
||||
<div class="header-info">
|
||||
<div class="settings-group model-type-group" data-model-type="embedding">
|
||||
<div class="section-subheader">
|
||||
<div class="subheader-text">
|
||||
<h3>{{ $t('modelSettings.embedding.title') }}</h3>
|
||||
<p>{{ $t('modelSettings.embedding.desc') }}</p>
|
||||
<p class="section-desc">{{ $t('modelSettings.embedding.desc') }}</p>
|
||||
</div>
|
||||
<t-button size="small" theme="primary" @click="openAddDialog('embedding')" class="add-model-btn">
|
||||
<t-button theme="primary" size="small" @click="openAddDialog('embedding')">
|
||||
<template #icon>
|
||||
<t-icon name="add" class="add-icon" />
|
||||
<add-icon />
|
||||
</template>
|
||||
{{ $t('modelSettings.actions.addModel') }}
|
||||
</t-button>
|
||||
@@ -115,24 +112,27 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty-state">
|
||||
<p class="empty-text">{{ $t('modelSettings.embedding.empty') }}</p>
|
||||
<t-button theme="default" variant="outline" size="small" @click="openAddDialog('embedding')">
|
||||
<div v-else class="empty-models">
|
||||
<p>{{ $t('modelSettings.embedding.empty') }}</p>
|
||||
<t-button theme="primary" size="small" @click="openAddDialog('embedding')">
|
||||
<template #icon>
|
||||
<add-icon />
|
||||
</template>
|
||||
{{ $t('modelSettings.actions.addModel') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ReRank 模型 -->
|
||||
<div class="model-category-section" data-model-type="rerank">
|
||||
<div class="category-header">
|
||||
<div class="header-info">
|
||||
<div class="settings-group model-type-group" data-model-type="rerank">
|
||||
<div class="section-subheader">
|
||||
<div class="subheader-text">
|
||||
<h3>{{ $t('modelSettings.rerank.title') }}</h3>
|
||||
<p>{{ $t('modelSettings.rerank.desc') }}</p>
|
||||
<p class="section-desc">{{ $t('modelSettings.rerank.desc') }}</p>
|
||||
</div>
|
||||
<t-button size="small" theme="primary" @click="openAddDialog('rerank')" class="add-model-btn">
|
||||
<t-button theme="primary" size="small" @click="openAddDialog('rerank')">
|
||||
<template #icon>
|
||||
<t-icon name="add" class="add-icon" />
|
||||
<add-icon />
|
||||
</template>
|
||||
{{ $t('modelSettings.actions.addModel') }}
|
||||
</t-button>
|
||||
@@ -164,24 +164,27 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty-state">
|
||||
<p class="empty-text">{{ $t('modelSettings.rerank.empty') }}</p>
|
||||
<t-button theme="default" variant="outline" size="small" @click="openAddDialog('rerank')">
|
||||
<div v-else class="empty-models">
|
||||
<p>{{ $t('modelSettings.rerank.empty') }}</p>
|
||||
<t-button theme="primary" size="small" @click="openAddDialog('rerank')">
|
||||
<template #icon>
|
||||
<add-icon />
|
||||
</template>
|
||||
{{ $t('modelSettings.actions.addModel') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- VLLM 视觉模型 -->
|
||||
<div class="model-category-section" data-model-type="vllm">
|
||||
<div class="category-header">
|
||||
<div class="header-info">
|
||||
<div class="settings-group model-type-group" data-model-type="vllm">
|
||||
<div class="section-subheader">
|
||||
<div class="subheader-text">
|
||||
<h3>{{ $t('modelSettings.vllm.title') }}</h3>
|
||||
<p>{{ $t('modelSettings.vllm.desc') }}</p>
|
||||
<p class="section-desc">{{ $t('modelSettings.vllm.desc') }}</p>
|
||||
</div>
|
||||
<t-button size="small" theme="primary" @click="openAddDialog('vllm')" class="add-model-btn">
|
||||
<t-button theme="primary" size="small" @click="openAddDialog('vllm')">
|
||||
<template #icon>
|
||||
<t-icon name="add" class="add-icon" />
|
||||
<add-icon />
|
||||
</template>
|
||||
{{ $t('modelSettings.actions.addModel') }}
|
||||
</t-button>
|
||||
@@ -213,24 +216,27 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty-state">
|
||||
<p class="empty-text">{{ $t('modelSettings.vllm.empty') }}</p>
|
||||
<t-button theme="default" variant="outline" size="small" @click="openAddDialog('vllm')">
|
||||
<div v-else class="empty-models">
|
||||
<p>{{ $t('modelSettings.vllm.empty') }}</p>
|
||||
<t-button theme="primary" size="small" @click="openAddDialog('vllm')">
|
||||
<template #icon>
|
||||
<add-icon />
|
||||
</template>
|
||||
{{ $t('modelSettings.actions.addModel') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- STT 语音模型 -->
|
||||
<div class="model-category-section" data-model-type="asr">
|
||||
<div class="category-header">
|
||||
<div class="header-info">
|
||||
<div class="settings-group model-type-group" data-model-type="asr">
|
||||
<div class="section-subheader">
|
||||
<div class="subheader-text">
|
||||
<h3>{{ $t('modelSettings.asr.title') }}</h3>
|
||||
<p>{{ $t('modelSettings.asr.desc') }}</p>
|
||||
<p class="section-desc">{{ $t('modelSettings.asr.desc') }}</p>
|
||||
</div>
|
||||
<t-button size="small" theme="primary" @click="openAddDialog('asr')" class="add-model-btn">
|
||||
<t-button theme="primary" size="small" @click="openAddDialog('asr')">
|
||||
<template #icon>
|
||||
<t-icon name="add" class="add-icon" />
|
||||
<add-icon />
|
||||
</template>
|
||||
{{ $t('modelSettings.actions.addModel') }}
|
||||
</t-button>
|
||||
@@ -261,9 +267,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty-state">
|
||||
<p class="empty-text">{{ $t('modelSettings.asr.empty') }}</p>
|
||||
<t-button theme="default" variant="outline" size="small" @click="openAddDialog('asr')">
|
||||
<div v-else class="empty-models">
|
||||
<p>{{ $t('modelSettings.asr.empty') }}</p>
|
||||
<t-button theme="primary" size="small" @click="openAddDialog('asr')">
|
||||
<template #icon>
|
||||
<add-icon />
|
||||
</template>
|
||||
{{ $t('modelSettings.actions.addModel') }}
|
||||
</t-button>
|
||||
</div>
|
||||
@@ -283,6 +292,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { AddIcon } from 'tdesign-icons-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import ModelEditorDialog from '@/components/ModelEditorDialog.vue'
|
||||
import { listModels, createModel, updateModel as updateModelAPI, deleteModel as deleteModelAPI, type ModelConfig } from '@/api/model'
|
||||
@@ -553,63 +563,90 @@ onMounted(() => {
|
||||
.section-description {
|
||||
font-size: 14px;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin: 0 0 20px 0;
|
||||
margin: 0 0 16px 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.model-category-section {
|
||||
.builtin-models-hint {
|
||||
margin-top: 4px;
|
||||
padding: 10px 12px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.builtin-hint-label {
|
||||
margin: 0 0 4px 0;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-placeholder);
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.builtin-hint-text {
|
||||
margin: 0 0 6px 0;
|
||||
font-size: 13px;
|
||||
line-height: 1.55;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
.builtin-hint-link {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary);
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: var(--td-brand-color);
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.model-type-group {
|
||||
margin-bottom: 32px;
|
||||
padding-bottom: 32px;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
|
||||
&:last-child {
|
||||
&:last-of-type {
|
||||
margin-bottom: 0;
|
||||
padding-bottom: 0;
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.category-header {
|
||||
.section-subheader {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
margin-bottom: 16px;
|
||||
|
||||
.header-info {
|
||||
.subheader-text {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
margin: 0 0 4px 0;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 添加模型按钮样式优化
|
||||
:deep(.add-model-btn) {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-weight: 500;
|
||||
height: 32px;
|
||||
padding: 0 16px;
|
||||
font-size: 14px;
|
||||
flex-shrink: 0;
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
margin: 0 0 4px 0;
|
||||
}
|
||||
|
||||
.add-icon {
|
||||
font-size: 14px;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
.section-desc {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
:deep(.t-button) {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -623,29 +660,24 @@ onMounted(() => {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 12px 16px;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: 6px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
transition: all 0.15s ease;
|
||||
border-radius: 8px;
|
||||
background: var(--td-bg-color-container);
|
||||
transition: border-color 0.2s ease, background-color 0.2s ease;
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
background: var(--td-bg-color-container);
|
||||
box-shadow: 0 1px 4px rgba(7, 192, 95, 0.08);
|
||||
}
|
||||
|
||||
// 内置模型样式
|
||||
&.builtin-model {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-color: var(--td-component-border);
|
||||
border-color: var(--td-component-stroke);
|
||||
|
||||
&:hover {
|
||||
border-color: var(--td-component-stroke);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
box-shadow: none;
|
||||
border-color: var(--td-brand-color-light);
|
||||
}
|
||||
|
||||
.model-info {
|
||||
@@ -655,7 +687,7 @@ onMounted(() => {
|
||||
|
||||
.model-meta {
|
||||
.source-tag {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
background: var(--td-bg-color-container);
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
}
|
||||
@@ -708,8 +740,6 @@ onMounted(() => {
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
flex-shrink: 0;
|
||||
opacity: 0;
|
||||
transition: opacity 0.15s ease;
|
||||
position: relative;
|
||||
z-index: 1001;
|
||||
|
||||
@@ -724,125 +754,20 @@ onMounted(() => {
|
||||
}
|
||||
}
|
||||
|
||||
.model-card:hover .model-actions {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
padding: 48px 0;
|
||||
.empty-models {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 32px;
|
||||
text-align: center;
|
||||
color: var(--td-text-color-placeholder);
|
||||
border: 1px dashed var(--td-component-stroke);
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
|
||||
.empty-text {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
margin: 0 0 16px 0;
|
||||
}
|
||||
}
|
||||
|
||||
.builtin-models-info {
|
||||
margin-top: 16px;
|
||||
|
||||
.info-box {
|
||||
background: var(--td-success-color-light);
|
||||
border: 1px solid var(--td-success-color-focus);
|
||||
border-left: 3px solid var(--td-brand-color);
|
||||
border-radius: 6px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.info-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
|
||||
.info-icon {
|
||||
font-size: 16px;
|
||||
color: var(--td-brand-color);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.info-title {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--td-brand-color-active);
|
||||
}
|
||||
}
|
||||
|
||||
.info-content {
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
color: var(--td-success-color);
|
||||
|
||||
p {
|
||||
margin: 0 0 6px 0;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
&.doc-link {
|
||||
margin-top: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
|
||||
.link-icon {
|
||||
font-size: 13px;
|
||||
color: var(--td-brand-color);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--td-brand-color);
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
transition: color 0.15s;
|
||||
|
||||
&:hover {
|
||||
color: var(--td-brand-color-active);
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TDesign 组件样式覆盖
|
||||
:deep(.t-button) {
|
||||
&.add-model-btn {
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
transition: all 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
background: var(--td-brand-color);
|
||||
border-color: var(--td-brand-color);
|
||||
}
|
||||
|
||||
&:active {
|
||||
background: var(--td-brand-color-active);
|
||||
border-color: var(--td-brand-color-active);
|
||||
}
|
||||
}
|
||||
|
||||
&.t-size-s {
|
||||
height: 32px;
|
||||
padding: 0 12px;
|
||||
font-size: 13px;
|
||||
border-radius: 6px;
|
||||
|
||||
&.t-button--variant-outline {
|
||||
color: var(--td-text-color-secondary);
|
||||
border-color: var(--td-component-stroke);
|
||||
|
||||
&:hover {
|
||||
color: var(--td-brand-color);
|
||||
border-color: var(--td-brand-color);
|
||||
background: rgba(7, 192, 95, 0.04);
|
||||
}
|
||||
}
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -2,3 +2,7 @@
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
export function GetAPIBaseURL():Promise<string>;
|
||||
|
||||
export function GetDesktopHTTPPortSetting():Promise<number>;
|
||||
|
||||
export function SetDesktopHTTPPortSetting(arg1:number):Promise<void>;
|
||||
|
||||
@@ -5,3 +5,11 @@
|
||||
export function GetAPIBaseURL() {
|
||||
return window['go']['main']['App']['GetAPIBaseURL']();
|
||||
}
|
||||
|
||||
export function GetDesktopHTTPPortSetting() {
|
||||
return window['go']['main']['App']['GetDesktopHTTPPortSetting']();
|
||||
}
|
||||
|
||||
export function SetDesktopHTTPPortSetting(arg1) {
|
||||
return window['go']['main']['App']['SetDesktopHTTPPortSetting'](arg1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user