Skip to content

Commit 44b5903

Browse files
author
linyuan.yang
committed
整理 admin 代码
1 parent 4e82aef commit 44b5903

11 files changed

Lines changed: 78 additions & 33 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { computed } from 'vue'
2+
import { store } from '@/shared/store'
3+
4+
/** 下拉选项形态(id + 显示名 + provider/model 明细)。 */
5+
export interface EmbeddingOption { id: string; label: string; detail: string }
6+
7+
/**
8+
* 向量模型配置管理:数据来自 settings.embeddings(由 settingsManager 统一刷新),
9+
* 这里只提供跨页面共用的下拉选项与显示名解析。
10+
*/
11+
class EmbeddingManager {
12+
readonly list = computed(() => store.settings.embeddings || {})
13+
14+
/** 向量模型下拉选项(id + 显示名 + provider/model 明细)。 */
15+
readonly options = computed<EmbeddingOption[]>(() =>
16+
Object.entries(this.list.value).map(([id, e]) => ({
17+
id,
18+
label: (e as any).name || id,
19+
detail: `${(e as any).provider} / ${(e as any).model}`,
20+
})),
21+
)
22+
23+
/** 向量模型显示名(找不到时回退 id;空值返回空串)。 */
24+
nameOf(id: string | null | undefined): string {
25+
if (!id) return ''
26+
return (this.list.value as any)[id]?.name || id
27+
}
28+
}
29+
30+
export const embeddingManager = new EmbeddingManager()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { computed } from 'vue'
2+
import { store } from '@/shared/store'
3+
4+
/** 下拉选项形态(id + 显示名)。 */
5+
export interface ModelOption { id: string; label: string }
6+
7+
/**
8+
* 模型配置管理:数据来自 settings.models(由 settingsManager 统一刷新),
9+
* 这里只提供跨页面共用的下拉选项与显示名解析。
10+
*/
11+
class ModelManager {
12+
readonly list = computed(() => store.settings.models || {})
13+
14+
/** 模型下拉选项(id + 显示名)。 */
15+
readonly options = computed<ModelOption[]>(() =>
16+
Object.entries(this.list.value).map(([id, m]) => ({ id, label: (m as any).name || id })),
17+
)
18+
19+
/** 模型显示名(找不到时回退 id;空值返回空串)。 */
20+
nameOf(id: string | null | undefined): string {
21+
if (!id) return ''
22+
return (this.list.value as any)[id]?.name || id
23+
}
24+
}
25+
26+
export const modelManager = new ModelManager()

‎packages/apps/admin/src/views/admin/HeartbeatView.vue‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useToast, useConfirm, SButton, SInput, SSelect, SModal, SFormItem, SBad
66
import type { STableColumn } from '@sbot/ui'
77
import { store } from '@/shared/store'
88
import { channelManager } from '@/managers/channelManager'
9+
import { modelManager } from '@/managers/modelManager'
910
import { promptFileManager } from '@/managers/promptFileManager'
1011
import CreatePromptModal from '@/components/modals/CreatePromptModal.vue'
1112
import SessionSelect from '@/components/SessionSelect.vue'
@@ -92,9 +93,7 @@ const heartbeats = ref<HeartbeatItem[]>([])
9293
const agendaOptions = computed(() =>
9394
Object.entries(store.settings.agendaProfiles || {}).map(([id, p]: [string, any]) => ({ id, label: p?.name || id }))
9495
)
95-
const modelOptions = computed(() =>
96-
Object.entries(store.settings.models || {}).map(([id, m]: [string, any]) => ({ id, label: m?.name || id }))
97-
)
96+
const modelOptions = modelManager.options
9897
9998
const showModal = ref(false)
10099
const editingId = ref<number | null>(null)

‎packages/apps/admin/src/views/agents/AgentsView.vue‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { profileManager } from '@/managers/profileManager'
77
import { mcpManager } from '@/managers/mcpManager'
88
import { skillsManager } from '@/managers/skillsManager'
99
import { settingsManager } from '@/managers/settingsManager'
10+
import { modelManager } from '@/managers/modelManager'
1011
import { useToast, useConfirm, SButton, SCard, SPageToolbar, SPageContent, STable, SInfoTable, SInfoRow, SModal, SInput, SSelect, STagFilter, type STableColumn } from '@sbot/ui'
1112
import AgentModal from './modals/AgentModal.vue'
1213
import AgentMcpModal from './modals/AgentMcpModal.vue'
@@ -71,7 +72,7 @@ const filteredAgentRows = computed<AgentRow[]>(() => {
7172
return activeTagFilters.value.every(t => rowTags.includes(t))
7273
})
7374
})
74-
const modelName = (id: string) => (store.settings.models?.[id] as any)?.name || id
75+
const modelName = (id: string) => modelManager.nameOf(id)
7576
7677
// ── Agent 引用情况(频道 / 会话档案 / 父智能体),方便清理无用资源 ──
7778
interface ProfileLite { id: number; name: string; agentId: string | null; sessionCount?: number }

‎packages/apps/admin/src/views/agents/modals/AgentModal.vue‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useI18n } from 'vue-i18n'
44
import { apiFetch } from '@/shared/api'
55
import { store } from '@/shared/store'
66
import { settingsManager } from '@/managers/settingsManager'
7+
import { modelManager } from '@/managers/modelManager'
78
import { useToast, useConfirm } from '@sbot/ui'
89
import { AgentMode, ACPSessionMode } from '@/shared/types'
910
import type { AgentConfig, SubAgentRef } from '@/shared/types'
@@ -45,9 +46,7 @@ const allTagSuggestions = computed(() => {
4546
}
4647
return Array.from(set).sort()
4748
})
48-
const modelOptions = computed(() =>
49-
Object.entries(store.settings.models || {}).map(([id, m]) => ({ id, label: m.name || id }))
50-
)
49+
const modelOptions = modelManager.options
5150
const agentOptions = computed(() =>
5251
Object.entries(store.settings.agents || {}).map(([id, a]) => ({ id, label: (a as any).name || id, type: (a as any).type || '' }))
5352
)

‎packages/apps/admin/src/views/automation/AgendaProfilesView.vue‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useI18n } from 'vue-i18n'
44
import { apiFetch } from '@/shared/api'
55
import { store } from '@/shared/store'
66
import { settingsManager } from '@/managers/settingsManager'
7+
import { modelManager } from '@/managers/modelManager'
78
import { promptFileManager } from '@/managers/promptFileManager'
89
import { useToast, useConfirm, SButton, SInput, SSelect, SModal, SFormItem, SBadge, SPageToolbar, SPageContent, STable, type STableColumn } from '@sbot/ui'
910
import AgendaListModal from '@/components/modals/AgendaListModal.vue'
@@ -26,9 +27,7 @@ const profileList = computed(() =>
2627
Object.entries(profiles.value).map(([id, p]) => ({ id, ...p })),
2728
)
2829
29-
const modelOptions = computed(() =>
30-
Object.entries(store.settings.models || {}).map(([id, m]) => ({ id, label: (m as any).name || id })),
31-
)
30+
const modelOptions = modelManager.options
3231
3332
// ── 被引用情况(频道 / 会话档案) ──
3433
const { loadProfiles, makeResourceRefs } = useResourceRefs()
@@ -152,7 +151,7 @@ async function refresh() {
152151
</SBadge>
153152
</template>
154153
<template #syncModel="{ row }">
155-
<span v-if="row.syncModel">{{ modelOptions.find(m => m.id === row.syncModel)?.label || row.syncModel }}</span>
154+
<span v-if="row.syncModel">{{ modelManager.nameOf(row.syncModel) }}</span>
156155
<span v-else class="muted">{{ t('agenda_profiles.sync_disabled') }}</span>
157156
</template>
158157
<template #prompt="{ row }">

‎packages/apps/admin/src/views/automation/MemoryProfilesView.vue‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useI18n } from 'vue-i18n'
44
import { apiFetch } from '@/shared/api'
55
import { store } from '@/shared/store'
66
import { settingsManager } from '@/managers/settingsManager'
7+
import { modelManager } from '@/managers/modelManager'
78
import { promptFileManager } from '@/managers/promptFileManager'
89
import { useToast, useConfirm, SButton, SInput, SSelect, SModal, SFormItem, SBadge, SPageToolbar, SPageContent, STable, type STableColumn } from '@sbot/ui'
910
import MemoryListModal from '@/components/modals/MemoryListModal.vue'
@@ -28,9 +29,7 @@ const profileList = computed(() =>
2829
Object.entries(profiles.value).map(([id, p]) => ({ id, ...p })),
2930
)
3031
31-
const modelOptions = computed(() =>
32-
Object.entries(store.settings.models || {}).map(([id, m]) => ({ id, label: (m as any).name || id })),
33-
)
32+
const modelOptions = modelManager.options
3433
3534
// ── 被引用情况(频道 / 会话档案) ──
3635
const { loadProfiles, makeResourceRefs } = useResourceRefs()
@@ -160,7 +159,7 @@ function openMemoryViewer(id: string) {
160159
161160
function modelLabel(id: string | undefined | null): string {
162161
if (!id) return '-'
163-
return modelOptions.value.find(m => m.id === id)?.label || id
162+
return modelManager.nameOf(id)
164163
}
165164
</script>
166165

‎packages/apps/admin/src/views/chat/ChannelsView.vue‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { apiFetch } from '@/shared/api'
55
import { store } from '@/shared/store'
66
import { profileManager } from '@/managers/profileManager'
77
import { settingsManager } from '@/managers/settingsManager'
8+
import { modelManager } from '@/managers/modelManager'
89
import { saverManager } from '@/managers/saverManager'
910
import { useToast, useConfirm, SButton, SModal, SInput, STextarea, SSelect, SFormItem, SFormSection, SFormDetails, SPageToolbar, SPageContent, SMultiSelect, SEntityList, STabBar, STab } from '@sbot/ui'
1011
import QRCode from 'qrcode'
@@ -147,7 +148,7 @@ const agentOptions = computed(() => Object.entries(store.settings.agents || {
147148
const saverOptions = computed(() => Object.entries(store.settings.savers || {}).map(([id, s]) => ({ id, label: (s as any).name || id })))
148149
const noteOptions = computed(() => Object.entries(store.settings.notes || {}).map(([id, n]) => ({ id, label: n.name || id })))
149150
const wikiOptions = computed(() => Object.entries(store.settings.wikis || {}).map(([id, w]) => ({ id, label: (w as any).name || id })))
150-
const modelOptions = computed(() => Object.entries(store.settings.models || {}).map(([id, m]) => ({ id, label: (m as any).name || id })))
151+
const modelOptions = modelManager.options
151152
const memoryProfileOptions = computed(() => Object.entries(store.settings.memoryProfiles || {}).map(([id, p]) => ({ id, label: (p as any).name || id })))
152153
const agendaProfileOptions = computed(() => Object.entries(store.settings.agendaProfiles || {}).map(([id, p]) => ({ id, label: (p as any).name || id })))
153154
@@ -835,7 +836,7 @@ async function refresh() {
835836
<span v-if="c.askTimeout != null && c.askTimeout > 0" class="session-meta-chip">{{ t('channels.ask_timeout') }}: {{ c.askTimeout }}</span>
836837
<span v-if="c.mergeWindow != null && c.mergeWindow > 0" class="session-meta-chip">{{ t('channels.merge_window') }}: {{ c.mergeWindow }}ms</span>
837838
<span v-if="showIntentFilterModeChip(c.intentFilterMode, c.intentModel)" class="session-meta-chip" :class="intentFilterModeClass(c.intentFilterMode)">{{ t('channels.intent_filter_mode') }}: {{ formatIntentFilterMode(c.intentFilterMode) }}</span>
838-
<span v-if="(c.intentFilterMode ?? IntentFilterMode.Auto) === IntentFilterMode.Auto && c.intentModel" class="session-meta-chip">{{ t('channels.intent_model') }}: {{ modelOptions.find(m => m.id === c.intentModel)?.label || c.intentModel }}</span>
839+
<span v-if="(c.intentFilterMode ?? IntentFilterMode.Auto) === IntentFilterMode.Auto && c.intentModel" class="session-meta-chip">{{ t('channels.intent_model') }}: {{ modelManager.nameOf(c.intentModel) }}</span>
839840
<span v-if="c.tools !== undefined" class="session-meta-chip" :class="c.tools.length ? '' : 'orange'">{{ t('channels.tools') }}: {{ c.tools.length ? c.tools.map(n => plugins.find(p => p.type === c.type)?.tools?.find(t => t.name === n)?.label || n).join(', ') : t('channels.tools_blocked') }}</span>
840841
<span v-if="c.triggerTools !== undefined" class="session-meta-chip" :class="c.triggerTools.length ? '' : 'orange'">{{ t('channels.trigger_tools') }}: {{ c.triggerTools.length ? c.triggerTools.map(n => plugins.find(p => p.type === c.type)?.tools?.find(t => t.name === n)?.label || n).join(', ') : t('channels.tools_blocked') }}</span>
841842
</template>
@@ -879,7 +880,7 @@ async function refresh() {
879880
<span v-if="s.approvalTimeout != null && s.approvalTimeout > 0" class="session-meta-chip">{{ t('channels.approval_timeout') }}: {{ s.approvalTimeout }} / {{ s.approvalTimeoutValue === ApprovalTimeoutValue.Allow ? t('channels.approval_timeout_value_allow') : t('channels.approval_timeout_value_deny') }}</span>
880881
<span v-if="s.askTimeout != null && s.askTimeout > 0" class="session-meta-chip">{{ t('channels.ask_timeout') }}: {{ s.askTimeout }}</span>
881882
<span v-if="showIntentFilterModeChip(s.intentFilterMode, s.intentModel)" class="session-meta-chip" :class="intentFilterModeClass(s.intentFilterMode)">{{ t('channels.intent_filter_mode') }}: {{ formatIntentFilterMode(s.intentFilterMode) }}</span>
882-
<span v-if="(s.intentFilterMode ?? IntentFilterMode.Auto) === IntentFilterMode.Auto && s.intentModel" class="session-meta-chip">{{ t('channels.intent_model') }}: {{ modelOptions.find(m => m.id === s.intentModel)?.label || s.intentModel }}{{ s.intentThreshold != null ? ` · ${s.intentThreshold}` : '' }}</span>
883+
<span v-if="(s.intentFilterMode ?? IntentFilterMode.Auto) === IntentFilterMode.Auto && s.intentModel" class="session-meta-chip">{{ t('channels.intent_model') }}: {{ modelManager.nameOf(s.intentModel) }}{{ s.intentThreshold != null ? ` · ${s.intentThreshold}` : '' }}</span>
883884
</template>
884885
</SEntityList>
885886
<SEntityList

‎packages/apps/admin/src/views/chat/SessionProfilesView.vue‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useI18n } from 'vue-i18n'
44
import { apiFetch } from '@/shared/api'
55
import { store } from '@/shared/store'
66
import { profileManager } from '@/managers/profileManager'
7+
import { modelManager } from '@/managers/modelManager'
78
import { useToast, useConfirm, SButton, SInput, SFormItem, SPageToolbar, SPageContent, STable, SModal } from '@sbot/ui'
89
import type { STableColumn } from '@sbot/ui'
910
import { ApprovalTimeoutValue, IntentFilterMode } from '@sbot/shared'
@@ -100,7 +101,7 @@ const agentOptions = computed(() => Object.entries(store.settings.agents || {}).
100101
const saverOptions = computed(() => Object.entries(store.settings.savers || {}).map(([id, s]) => ({ id, label: (s as any).name || id })))
101102
const noteOptions = computed(() => Object.entries(store.settings.notes || {}).map(([id, n]: [string, any]) => ({ id, label: n.name || id })))
102103
const wikiOptions = computed(() => Object.entries(store.settings.wikis || {}).map(([id, w]) => ({ id, label: (w as any).name || id })))
103-
const modelOptions = computed(() => Object.entries(store.settings.models || {}).map(([id, m]) => ({ id, label: (m as any).name || id })))
104+
const modelOptions = modelManager.options
104105
const memoryProfileOptions = computed(() => Object.entries(store.settings.memoryProfiles || {}).map(([id, p]) => ({ id, label: (p as any).name || id })))
105106
const agendaProfileOptions = computed(() => Object.entries(store.settings.agendaProfiles || {}).map(([id, p]) => ({ id, label: (p as any).name || id })))
106107

‎packages/apps/admin/src/views/note/NotesView.vue‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useI18n } from 'vue-i18n'
44
import { apiFetch } from '@/shared/api'
55
import { store } from '@/shared/store'
66
import { settingsManager } from '@/managers/settingsManager'
7+
import { embeddingManager } from '@/managers/embeddingManager'
78
import { useToast, useConfirm, SButton, SInput, SSelect, SModal, SFormItem, SBadge, SPageToolbar, SPageContent, STable, type STableColumn } from '@sbot/ui'
89
import type { NoteConfig } from '@/shared/types'
910
import NoteViewModal from './NoteViewModal.vue'
@@ -24,13 +25,7 @@ const columns = computed<STableColumn[]>(() => [
2425
{ key: 'count', label: t('notes.count_col'), width: '70px', align: 'center' },
2526
{ key: 'ops', label: t('common.ops'), ops: true, width: '180px', align: 'center' },
2627
])
27-
const embeddingOptions = computed(() =>
28-
Object.entries(store.settings.embeddings || {}).map(([id, e]) => ({
29-
id,
30-
label: e.name || id,
31-
detail: `${e.provider} / ${e.model}`,
32-
}))
33-
)
28+
const embeddingOptions = embeddingManager.options
3429
// ── 被引用情况(频道 / 会话档案) ──
3530
const { loadProfiles, makeResourceRefs } = useResourceRefs()
3631
const refs = makeResourceRefs({

0 commit comments

Comments
 (0)