From 5f83a2f93d96de77b1ad4c25d2a35788b37378e7 Mon Sep 17 00:00:00 2001 From: RainbowBird Date: Mon, 23 Nov 2026 21:04:38 +0800 Subject: [PATCH] feat(stage-ui,i18n): show the conversations of the current character only (#3583) --- packages/i18n/src/locales/en/stage.yaml | 7 - packages/i18n/src/locales/zh-Hans/stage.yaml | 7 - .../sessions-dialog.browser.test.ts | 3 - .../chat/components/sessions-dialog.vue | 12 +- .../sessions-drawer.browser.test.ts | 6 + .../chat/components/sessions-drawer.vue | 20 +- .../chat/components/sessions-list.story.vue | 37 ++-- .../chat/components/sessions-list.vue | 183 ++---------------- .../src/stores/chat/sessions-view-store.ts | 5 +- 9 files changed, 54 insertions(+), 226 deletions(-) diff --git a/packages/i18n/src/locales/en/stage.yaml b/packages/i18n/src/locales/en/stage.yaml index 8ebc62e90..35e4bcd89 100644 --- a/packages/i18n/src/locales/en/stage.yaml +++ b/packages/i18n/src/locales/en/stage.yaml @@ -279,10 +279,8 @@ chat: done-selecting: Done delete-selected: Delete {count} confirm-delete-selected: Confirm delete {count} - all: All all-conversations: All conversations switch-place: Switch view - filter-by-character: Filter by character unknown-character: Unknown character pinned: Pinned folders: Folders @@ -297,8 +295,6 @@ chat: new-folder: New folder create-folder: Create new-in-folder: New conversation in {folder} - new-with-character: New conversation with {name} - new-in-folder-with-character: New conversation with {name} in {folder} folder-name: Folder name folder-name-placeholder: Enter a folder name save-folder: Save folder @@ -309,10 +305,7 @@ chat: confirm-delete-folder: Confirm delete folder selected: '{count} selected' empty-folder: '{folder} is empty. Use the button above to start a conversation here, or choose Move to folder in the menu of a conversation.' - empty-folder-character: '{folder} has no conversations with {name} yet. Use the button above to start one.' empty-archive: No archived conversations. Archived conversations stay here. - empty-archive-character: No archived conversations with {name}. Archived conversations stay here. - empty-character: No conversations with {name} yet. Use the button above to start the first one. save-failed: The change could not be saved avatar-model-missing: title: No model selected diff --git a/packages/i18n/src/locales/zh-Hans/stage.yaml b/packages/i18n/src/locales/zh-Hans/stage.yaml index 4050b6841..b00edbbf3 100644 --- a/packages/i18n/src/locales/zh-Hans/stage.yaml +++ b/packages/i18n/src/locales/zh-Hans/stage.yaml @@ -285,10 +285,8 @@ chat: done-selecting: 完成 delete-selected: 删除 {count} 个对话 confirm-delete-selected: 确认删除 {count} 个对话 - all: 全部 all-conversations: 全部对话 switch-place: 切换位置 - filter-by-character: 按角色筛选 unknown-character: 未知角色 pinned: 置顶 folders: 文件夹 @@ -303,8 +301,6 @@ chat: new-folder: 新建文件夹 create-folder: 创建 new-in-folder: 在“{folder}”新建对话 - new-with-character: 新建 {name} 的对话 - new-in-folder-with-character: 在“{folder}”新建 {name} 的对话 folder-name: 文件夹名称 folder-name-placeholder: 输入文件夹名称 save-folder: 保存文件夹 @@ -315,10 +311,7 @@ chat: confirm-delete-folder: 确认删除文件夹 selected: 已选 {count} 个 empty-folder: “{folder}”还是空的。点上面的按钮新建,或在对话的菜单里选“移到文件夹”。 - empty-folder-character: “{folder}”里还没有和 {name} 的对话。点上面的按钮开始。 empty-archive: 没有归档的对话。归档的对话放在这里。 - empty-archive-character: 没有和 {name} 的归档对话。归档的对话放在这里。 - empty-character: 还没有和 {name} 的对话。点上面的按钮开始第一段。 save-failed: 这次修改没能保存 avatar-model-missing: title: 还没有选择模型 diff --git a/packages/stage-ui/src/components/scenarios/chat/components/sessions-dialog.browser.test.ts b/packages/stage-ui/src/components/scenarios/chat/components/sessions-dialog.browser.test.ts index a85c47067..5223255fe 100644 --- a/packages/stage-ui/src/components/scenarios/chat/components/sessions-dialog.browser.test.ts +++ b/packages/stage-ui/src/components/scenarios/chat/components/sessions-dialog.browser.test.ts @@ -85,7 +85,6 @@ function createHarness(rows = [ :open="true" :rows="rows" :folders="[]" - :characters="[]" :is-desktop="isDesktop" :is-creating-session="false" @new-session="created += 1" @@ -115,7 +114,6 @@ describe('sessions dialog actions', () => { v-model:open="open" :rows="rows" :folders="[]" - :characters="[]" :is-desktop="true" :is-creating-session="false" desktop-mode="popover" @@ -150,7 +148,6 @@ describe('sessions dialog actions', () => { v-model:open="open" :rows="rows" :folders="[]" - :characters="[]" :is-desktop="true" :is-creating-session="false" desktop-mode="popover" diff --git a/packages/stage-ui/src/components/scenarios/chat/components/sessions-dialog.vue b/packages/stage-ui/src/components/scenarios/chat/components/sessions-dialog.vue index 81ff5f248..db5226066 100644 --- a/packages/stage-ui/src/components/scenarios/chat/components/sessions-dialog.vue +++ b/packages/stage-ui/src/components/scenarios/chat/components/sessions-dialog.vue @@ -12,7 +12,6 @@ import SessionsList from './sessions-list.vue' const props = withDefaults(defineProps<{ open: boolean rows: SessionRow[] - characters: Array<{ id: string, name: string, preview?: string }> folders: readonly ChatSessionFolder[] isDesktop: boolean isCreatingSession: boolean @@ -24,7 +23,7 @@ const props = withDefaults(defineProps<{ const emit = defineEmits<{ 'deleteSession': [sessionId: string] 'deleteSessions': [sessionIds: string[]] - 'newSession': [payload: { folderId?: string, characterId?: string }] + 'newSession': [payload: { folderId?: string }] 'renameSession': [payload: { sessionId: string, title: string }] 'selectSession': [sessionId: string] 'pinSession': [payload: { sessionId: string, pinned: boolean }] @@ -36,9 +35,8 @@ const emit = defineEmits<{ 'update:open': [open: boolean] }>() -/** The place and the character of the list. The owner can keep them, so the list opens where the user left it. */ +/** The place of the list. The owner can keep it, so the list opens where the user left it. */ const place = defineModel('place', { default: () => ({ kind: 'all' }) }) -const characterId = defineModel('characterId') const { t } = useI18n() // Every open starts outside selection mode, so a closed list never keeps a selection. @@ -69,9 +67,7 @@ function preserveTriggerFocus(event: Event) { { chatSession.sessionMessages['session-b'] = [ { id: 'b', role: 'user', content: 'Earlier', createdAt: now - 14_400_000 }, ] + // The list shows the current character only. A chat with another character stays out of it. + chatSession.sessionMetas['session-other'] = { ...sessionMeta('session-other', 'Chat of another character', 4), characterId: 'other' } + chatSession.sessionMessages['session-other'] = [] vi.spyOn(chatSession, 'loadSession').mockResolvedValue(true) await screen.rerender({ modelValue: true }) await expect.element(screen.getByRole('button', { name: /^Chat A/ })).toHaveTextContent('2 hours ago') @@ -154,6 +157,9 @@ describe('sessions drawer orchestration', () => { { id: 'undated', role: 'user', content: 'No date' }, { id: 'invalid', role: 'user', content: 'Invalid date', createdAt: Number.NaN }, ] + // The list shows the current character only. A chat with another character stays out of it. + chatSession.sessionMetas['session-other'] = { ...sessionMeta('session-other', 'Chat of another character', 4), characterId: 'other' } + chatSession.sessionMessages['session-other'] = [] vi.spyOn(chatSession, 'loadSession').mockResolvedValue(true) await screen.rerender({ modelValue: true }) await expect.element(screen.getByRole('button', { name: /^Chat A/ })).toHaveTextContent('2 hours ago') diff --git a/packages/stage-ui/src/components/scenarios/chat/components/sessions-drawer.vue b/packages/stage-ui/src/components/scenarios/chat/components/sessions-drawer.vue index b31f1ba60..836ba98be 100644 --- a/packages/stage-ui/src/components/scenarios/chat/components/sessions-drawer.vue +++ b/packages/stage-ui/src/components/scenarios/chat/components/sessions-drawer.vue @@ -42,8 +42,8 @@ const chatSession = useChatSessionStore() const chat = useChatStore() const { sessionMetas, sessionMessages, activeSessionId, index } = storeToRefs(chatSession) const { activeCardId, cards } = storeToRefs(useAiriCardStore()) -// The list keeps its place and filter in memory, so a closed and reopened list shows them again. -const { place: listPlace, characterId: listCharacterId } = storeToRefs(useChatSessionsViewStore()) +// The list keeps its place in memory, so a closed and reopened list shows it again. +const { place: listPlace } = storeToRefs(useChatSessionsViewStore()) const characterPreviews = useCharacterPreviews() const { userId } = storeToRefs(useAuthStore()) const { activeModel } = storeToRefs(useConsciousnessStore()) @@ -55,10 +55,13 @@ const isCreatingSession = ref(false) const effectiveUserId = computed(() => userId.value || 'local') +const currentCharacterId = computed(() => activeCardId.value || 'default') + +// The list shows the conversations of the current character only. The user changes the character to see the others. // Keep another account's sessions hidden while an account swap rehydrates. // Background recipe sessions are hidden too. Their results reach the conversation as notices. const ownedSessions = computed(() => Object.values(sessionMetas.value) - .filter(meta => meta.userId === effectiveUserId.value && !meta.hidden)) + .filter(meta => meta.userId === effectiveUserId.value && !meta.hidden && chatSession.characterMembersOf(meta.sessionId).includes(currentCharacterId.value))) /** * Normalizes a session into its one-line drawer preview. @@ -124,9 +127,6 @@ const rows = computed(() => { })) }) -/** Every character card, so the filter can pick a character that has no conversation yet. */ -const characters = computed(() => [...cards.value].map(([id, card]) => ({ id, name: card.name, preview: characterPreviews.value.get(id) }))) - /** * Runs an action of the list and explains a failure with a toast, as the other chat controls do. The list keeps its * state, so the user can try again. @@ -154,15 +154,15 @@ async function selectSession(sessionId: string) { } /** - * Creates a conversation and opens it. Without a character ID, it belongs to the active character. + * Creates a conversation with the current character and opens it. * A folder ID puts the conversation into that folder. */ -async function startNewSession(payload: { folderId?: string, characterId?: string }) { +async function startNewSession(payload: { folderId?: string }) { if (isCreatingSession.value) return isCreatingSession.value = true try { - const characterId = payload.characterId ?? (activeCardId.value || 'default') + const characterId = currentCharacterId.value const selectionBeforeCreation = activeSessionId.value // Creation runs in the synchronized leader, while navigation belongs to // this window. Activating inside createSession would navigate the leader. @@ -252,9 +252,7 @@ watch(showDialog, async (open) => { & { label: string, isActive?: boolean }): SessionRow { +function rowOf(sessionId: string, title: string, details: Partial & { label: string, isActive?: boolean }): SessionRow { const { label, isActive = false, ...meta } = details return { - meta: { sessionId, userId: 'local', characterId, title, createdAt: CREATED_AT, updatedAt: CREATED_AT, ...meta }, + meta: { sessionId, userId: 'local', characterId: 'airi', title, createdAt: CREATED_AT, updatedAt: CREATED_AT, ...meta }, preview: title, isActive, activityAtLabel: label, - characterName: characters.find(character => character.id === characterId)?.name ?? 'Unknown character', + characterName: 'AIRI', } } const rows: SessionRow[] = [ - rowOf('weekend', 'Weekend trip ideas', 'airi', { label: '2 minutes ago', isActive: true, folderId: 'trips' }), - rowOf('book', 'Notes on the new book', 'airi', { label: '1 hour ago', pinnedAt: CREATED_AT }), - rowOf('review', 'Review a pull request', 'mira', { label: '3 hours ago', folderId: 'work', cloudChatId: 'cloud-review' }), - rowOf('bug', 'Draft a bug report', 'mira', { label: 'yesterday', folderId: 'work' }), - rowOf('groceries', 'Grocery list for the week', 'airi', { label: '2 days ago' }), - rowOf('intro', 'Practice a self-introduction', 'mira', { label: 'last week', archivedAt: CREATED_AT }), + rowOf('weekend', 'Weekend trip ideas', { label: '2 minutes ago', isActive: true, folderId: 'trips' }), + rowOf('book', 'Notes on the new book', { label: '1 hour ago', pinnedAt: CREATED_AT }), + rowOf('review', 'Review a pull request', { label: '3 hours ago', folderId: 'work', cloudChatId: 'cloud-review' }), + rowOf('bug', 'Draft a bug report', { label: 'yesterday', folderId: 'work' }), + rowOf('groceries', 'Grocery list for the week', { label: '2 days ago' }), + rowOf('intro', 'Practice a self-introduction', { label: 'last week', archivedAt: CREATED_AT }), ] const popoverPlace = ref({ kind: 'all' }) @@ -47,34 +41,33 @@ const drawerPlace = ref({ kind: 'all' }) const folderPlace = ref({ kind: 'folder', folderId: 'work' }) const archivePlace = ref({ kind: 'archive' }) const emptyPlace = ref({ kind: 'all' }) -const filteredCharacter = ref('mira')