Skip to content

Commit bbdeee4

Browse files
author
linyuan.yang
committed
model 被引用情况
1 parent 9ce620d commit bbdeee4

6 files changed

Lines changed: 126 additions & 11 deletions

File tree

‎packages/admin/src/components/ResourceRefs.vue‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ const { t } = useI18n()
3434
<SInfoRow v-if="refs.agents.length" :label="t('common.ref_agents')">
3535
<span v-for="a in refs.agents" :key="a.id" class="ref-chip">{{ a.name }}</span>
3636
</SInfoRow>
37+
<SInfoRow v-if="refs.memoryProfiles.length" :label="t('common.ref_memory_profiles')">
38+
<span v-for="p in refs.memoryProfiles" :key="p.id" class="ref-chip">{{ p.name }}</span>
39+
</SInfoRow>
40+
<SInfoRow v-if="refs.agendaProfiles.length" :label="t('common.ref_agenda_profiles')">
41+
<span v-for="p in refs.agendaProfiles" :key="p.id" class="ref-chip">{{ p.name }}</span>
42+
</SInfoRow>
43+
<SInfoRow v-if="refs.notes.length" :label="t('common.ref_notes')">
44+
<span v-for="n in refs.notes" :key="n.id" class="ref-chip">{{ n.name }}</span>
45+
</SInfoRow>
46+
<SInfoRow v-if="refs.wikis.length" :label="t('common.ref_wikis')">
47+
<span v-for="w in refs.wikis" :key="w.id" class="ref-chip">{{ w.name }}</span>
48+
</SInfoRow>
3749
</SInfoTable>
3850
</SCard>
3951
</template>

‎packages/admin/src/composables/useResourceRefs.ts‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// 计算某个资源(事项/记忆档案、笔记库、知识库、存储)被频道 / 会话档案 / 智能体引用的情况,
1+
// 计算配置资源被频道、会话档案、会话及其他配置资源引用的情况,
22
// 供各资源页复刻 AgentsView 的「被引用情况」展示(见 ResourceRefs.vue)。
33
import { ref } from 'vue'
44
import { apiFetch } from '@/shared/api'
@@ -10,6 +10,7 @@ interface ProfileLite {
1010
name: string
1111
agentId: string | null
1212
saver: string | null
13+
intentModel: string | null
1314
notes: string | null // JSON 字符串
1415
wikis: string | null // JSON 字符串
1516
memory: string | null
@@ -31,6 +32,7 @@ interface SessionLite {
3132
autoSessionName: string
3233
agentId: string | null
3334
saver: string | null
35+
intentModel: string | null
3436
notes: string[] | null
3537
wikis: string[] | null
3638
memory: string | null
@@ -40,12 +42,16 @@ interface SessionLite {
4042
/** 单个引用方。 */
4143
export interface RefItem { id: string | number; name: string; sessionCount?: number }
4244

43-
/** 某资源的全部引用方,分频道 / 会话档案 / 会话 / 智能体四类。 */
45+
/** 某资源的全部引用方,按引用方类型分类。 */
4446
export interface ResourceRefsValue {
4547
channels: RefItem[]
4648
profiles: RefItem[]
4749
sessions: RefItem[]
4850
agents: RefItem[]
51+
memoryProfiles: RefItem[]
52+
agendaProfiles: RefItem[]
53+
notes: RefItem[]
54+
wikis: RefItem[]
4955
total: number
5056
}
5157

@@ -59,6 +65,10 @@ export interface RefMatchers {
5965
profile: (p: ProfileLite, id: string) => boolean
6066
session?: (s: SessionLite, id: string) => boolean
6167
agent?: (a: any, id: string) => boolean
68+
memoryProfile?: (p: any, id: string) => boolean
69+
agendaProfile?: (p: any, id: string) => boolean
70+
note?: (n: any, id: string) => boolean
71+
wiki?: (w: any, id: string) => boolean
6272
}
6373

6474
/** 会话档案的 notes/wikis 是 JSON 字符串,解析为 string[](同 SessionProfilesView 的 parseList)。 */
@@ -105,9 +115,30 @@ export function useResourceRefs() {
105115
.filter(([, a]) => matchers.agent!(a as any, id))
106116
.map(([aid, a]) => ({ id: aid, name: (a as any).name || aid }))
107117
: []
118+
const memoryProfiles = matchers.memoryProfile
119+
? Object.entries(store.settings.memoryProfiles || {})
120+
.filter(([, p]) => matchers.memoryProfile!(p as any, id))
121+
.map(([pid, p]) => ({ id: pid, name: (p as any).name || pid }))
122+
: []
123+
const agendaProfiles = matchers.agendaProfile
124+
? Object.entries(store.settings.agendaProfiles || {})
125+
.filter(([, p]) => matchers.agendaProfile!(p as any, id))
126+
.map(([pid, p]) => ({ id: pid, name: (p as any).name || pid }))
127+
: []
128+
const notes = matchers.note
129+
? Object.entries(store.settings.notes || {})
130+
.filter(([, n]) => matchers.note!(n as any, id))
131+
.map(([nid, n]) => ({ id: nid, name: (n as any).name || nid }))
132+
: []
133+
const wikis = matchers.wiki
134+
? Object.entries(store.settings.wikis || {})
135+
.filter(([, w]) => matchers.wiki!(w as any, id))
136+
.map(([wid, w]) => ({ id: wid, name: (w as any).name || wid }))
137+
: []
108138
return {
109-
channels, profiles, sessions, agents,
110-
total: channels.length + profiles.length + sessions.length + agents.length,
139+
channels, profiles, sessions, agents, memoryProfiles, agendaProfiles, notes, wikis,
140+
total: channels.length + profiles.length + sessions.length + agents.length
141+
+ memoryProfiles.length + agendaProfiles.length + notes.length + wikis.length,
111142
}
112143
}
113144
}

‎packages/admin/src/i18n/en.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,15 @@ export default {
7575
references: 'References',
7676
ref_count: '{n} reference(s)',
7777
ref_unused: 'Unused',
78-
ref_unused_hint: 'This item is not referenced by any channel, session profile, or agent — safe to delete.',
78+
ref_unused_hint: 'This item is not referenced by any configuration and is safe to delete.',
7979
ref_channels: 'Channels',
8080
ref_profiles: 'Session Profiles',
8181
ref_sessions: 'Sessions (private override)',
8282
ref_agents: 'Agents',
83+
ref_memory_profiles: 'Memory Profiles',
84+
ref_agenda_profiles: 'Agenda Profiles',
85+
ref_notes: 'Notes',
86+
ref_wikis: 'Knowledge Bases',
8387
ref_profile_sessions: '{n} session(s)',
8488
enabled: 'Enabled',
8589
disabled: 'Disabled',

‎packages/admin/src/i18n/zh.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,15 @@ export default {
7575
references: '被引用情况',
7676
ref_count: '{n} 处引用',
7777
ref_unused: '未被引用',
78-
ref_unused_hint: '该项未被任何频道、会话档案或智能体引用,可安全删除。',
78+
ref_unused_hint: '该项未被任何配置引用,可安全删除。',
7979
ref_channels: '频道',
8080
ref_profiles: '会话档案',
8181
ref_sessions: '会话(私有覆盖)',
8282
ref_agents: '智能体',
83+
ref_memory_profiles: '长期记忆模板',
84+
ref_agenda_profiles: '事项模板',
85+
ref_notes: '笔记库',
86+
ref_wikis: '知识库',
8387
ref_profile_sessions: '{n} 个会话',
8488
enabled: '启用',
8589
disabled: '禁用',

‎packages/admin/src/views/models/EmbeddingsView.vue‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { useToast, useConfirm, SButton, SInput, SSelect, SModal, SFormItem, SPag
77
import type { STableColumn } from 'sbot-ui'
88
import { EmbeddingProvider } from '@/shared/types'
99
import type { EmbeddingConfig } from '@/shared/types'
10+
import ResourceRefs from '@/components/ResourceRefs.vue'
11+
import { useResourceRefs } from '@/composables/useResourceRefs'
1012
1113
const { t } = useI18n()
1214
const { show } = useToast()
@@ -24,6 +26,15 @@ const embeddingColumns = computed<STableColumn[]>(() => [
2426
{ key: 'ops', label: t('common.ops'), ops: true },
2527
])
2628
29+
const { makeResourceRefs } = useResourceRefs()
30+
const refs = makeResourceRefs({
31+
channel: () => false,
32+
profile: () => false,
33+
note: (n, id) => n.embedding === id,
34+
wiki: (w, id) => w.embedding === id,
35+
})
36+
const expandedIds = ref<string[]>([])
37+
2738
const providerDefaults: Record<string, { baseURL: string; apiKey: string; model: string }> = {
2839
[EmbeddingProvider.OpenAI]: { baseURL: 'https://api.openai.com/v1', apiKey: 'sk-...', model: 'text-embedding-ada-002' },
2940
[EmbeddingProvider.Ollama]: { baseURL: 'http://localhost:11434', apiKey: '', model: 'nomic-embed-text' },
@@ -148,12 +159,27 @@ async function refresh() {
148159
<SButton type="primary" size="sm" @click="openAdd">{{ t('embeddings.add') }}</SButton>
149160
</SPageToolbar>
150161
<SPageContent>
151-
<STable :columns="embeddingColumns" :rows="embeddingRows" row-key="id" :empty-text="t('embeddings.empty')">
152-
<template #name="{ row }">{{ row.name || row.id }}</template>
162+
<STable
163+
:columns="embeddingColumns"
164+
:rows="embeddingRows"
165+
row-key="id"
166+
expandable
167+
v-model:expandedKeys="expandedIds"
168+
:empty-text="t('embeddings.empty')"
169+
>
170+
<template #name="{ row }">
171+
{{ row.name || row.id }}
172+
<ResourceRefs mode="badge" :refs="refs(row.id)" />
173+
</template>
153174
<template #ops="{ row }">
154175
<SButton type="outline" size="sm" @click="openEdit(row.id)">{{ t('common.edit') }}</SButton>
155176
<SButton type="danger" size="sm" @click="remove(row.id)">{{ t('common.delete') }}</SButton>
156177
</template>
178+
<template #_expanded="{ row }">
179+
<div class="refs-expanded">
180+
<ResourceRefs mode="card" :refs="refs(row.id)" />
181+
</div>
182+
</template>
157183
</STable>
158184
</SPageContent>
159185

@@ -210,6 +236,10 @@ async function refresh() {
210236
</template>
211237

212238
<style scoped>
239+
.refs-expanded {
240+
padding: var(--sui-sp-4) var(--sui-sp-6);
241+
background: var(--sui-bg-subtle);
242+
}
213243
.apikey-field, .model-field {
214244
display: flex;
215245
gap: var(--sui-sp-2);

‎packages/admin/src/views/models/ModelsView.vue‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<script setup lang="ts">
2-
import { ref, computed } from 'vue'
2+
import { ref, computed, onMounted } from 'vue'
33
import { useI18n } from 'vue-i18n'
44
import { apiFetch } from '@/shared/api'
55
import { store } from '@/shared/store'
66
import { useToast, useConfirm, SButton, SInput, SSelect, SModal, SFormItem, SPageToolbar, SPageContent, STable } from 'sbot-ui'
77
import type { STableColumn } from 'sbot-ui'
88
import { ModelProvider } from '@/shared/types'
99
import type { ModelConfig } from '@/shared/types'
10+
import ResourceRefs from '@/components/ResourceRefs.vue'
11+
import { useResourceRefs } from '@/composables/useResourceRefs'
1012
1113
const { t } = useI18n()
1214
const { show } = useToast()
@@ -24,6 +26,18 @@ const modelColumns = computed<STableColumn[]>(() => [
2426
{ key: 'ops', label: t('common.ops'), ops: true },
2527
])
2628
29+
const { loadProfiles, makeResourceRefs } = useResourceRefs()
30+
const refs = makeResourceRefs({
31+
channel: (c, id) => c.intentModel === id,
32+
profile: (p, id) => p.intentModel === id,
33+
session: (s, id) => s.intentModel === id,
34+
agent: (a, id) => a.model === id || a.compactModel === id,
35+
memoryProfile: (p, id) => p.writerModel === id,
36+
agendaProfile: (p, id) => p.syncModel === id,
37+
})
38+
const expandedIds = ref<string[]>([])
39+
onMounted(loadProfiles)
40+
2741
const showModal = ref(false)
2842
const editingName = ref<string | null>(null)
2943
const showApiKey = ref(false)
@@ -168,6 +182,7 @@ async function refresh() {
168182
try {
169183
const res = await apiFetch('/api/settings')
170184
Object.assign(store.settings, res.data)
185+
await loadProfiles()
171186
} catch (e: any) {
172187
show(e.message, 'error')
173188
}
@@ -181,12 +196,27 @@ async function refresh() {
181196
<SButton type="primary" size="sm" @click="openAdd">{{ t('models.add') }}</SButton>
182197
</SPageToolbar>
183198
<SPageContent>
184-
<STable :columns="modelColumns" :rows="modelRows" row-key="id" :empty-text="t('models.empty')">
185-
<template #name="{ row }">{{ row.name || row.id }}</template>
199+
<STable
200+
:columns="modelColumns"
201+
:rows="modelRows"
202+
row-key="id"
203+
expandable
204+
v-model:expandedKeys="expandedIds"
205+
:empty-text="t('models.empty')"
206+
>
207+
<template #name="{ row }">
208+
{{ row.name || row.id }}
209+
<ResourceRefs mode="badge" :refs="refs(row.id)" />
210+
</template>
186211
<template #ops="{ row }">
187212
<SButton type="outline" size="sm" @click="openEdit(row.id)">{{ t('common.edit') }}</SButton>
188213
<SButton type="danger" size="sm" @click="remove(row.id)">{{ t('common.delete') }}</SButton>
189214
</template>
215+
<template #_expanded="{ row }">
216+
<div class="refs-expanded">
217+
<ResourceRefs mode="card" :refs="refs(row.id)" />
218+
</div>
219+
</template>
190220
</STable>
191221
</SPageContent>
192222

@@ -273,6 +303,10 @@ async function refresh() {
273303
</template>
274304

275305
<style scoped>
306+
.refs-expanded {
307+
padding: var(--sui-sp-4) var(--sui-sp-6);
308+
background: var(--sui-bg-subtle);
309+
}
276310
.apikey-field, .model-field {
277311
display: flex;
278312
gap: var(--sui-sp-2);

0 commit comments

Comments
 (0)