Show platform sources in desktop sessions
This commit is contained in:
committed by
Teknium
parent
1c68f6f81f
commit
9d6992ee8a
@@ -52,6 +52,14 @@ describe('sessionMatchesSearch', () => {
|
||||
expect(sessionMatchesSearch(session, 'hermes-agent')).toBe(true)
|
||||
})
|
||||
|
||||
it('matches sessions by source platform and aliases', () => {
|
||||
expect(sessionMatchesSearch(makeSession({ source: 'telegram' }), 'Telegram')).toBe(true)
|
||||
expect(sessionMatchesSearch(makeSession({ source: 'whatsapp' }), 'WhatsApp')).toBe(true)
|
||||
expect(sessionMatchesSearch(makeSession({ source: 'whatsapp' }), 'wa')).toBe(true)
|
||||
expect(sessionMatchesSearch(makeSession({ source: 'slack' }), 'slack')).toBe(true)
|
||||
expect(sessionMatchesSearch(makeSession({ source: 'bluebubbles' }), 'imessage')).toBe(true)
|
||||
})
|
||||
|
||||
it('does not match unrelated queries', () => {
|
||||
expect(sessionMatchesSearch(makeSession(), 'totally-unrelated')).toBe(false)
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { SessionInfo } from '@/types/hermes'
|
||||
|
||||
import { sessionTitle } from './chat-runtime'
|
||||
import { sessionSourceSearchTerms } from './session-source'
|
||||
|
||||
export function sessionMatchesSearch(session: SessionInfo, query: string): boolean {
|
||||
const needle = query.trim().toLowerCase()
|
||||
@@ -14,6 +15,7 @@ export function sessionMatchesSearch(session: SessionInfo, query: string): boole
|
||||
session._lineage_root_id ?? '',
|
||||
sessionTitle(session),
|
||||
session.preview ?? '',
|
||||
session.cwd ?? ''
|
||||
session.cwd ?? '',
|
||||
...sessionSourceSearchTerms(session.source)
|
||||
].some(value => value.toLowerCase().includes(needle))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
const SOURCE_LABELS: Record<string, string> = {
|
||||
api_server: 'API',
|
||||
bluebubbles: 'iMessage',
|
||||
cli: 'CLI',
|
||||
codex: 'Codex',
|
||||
desktop: 'Desktop',
|
||||
discord: 'Discord',
|
||||
email: 'Email',
|
||||
gateway: 'Gateway',
|
||||
local: 'Local',
|
||||
matrix: 'Matrix',
|
||||
mattermost: 'Mattermost',
|
||||
qqbot: 'QQ',
|
||||
signal: 'Signal',
|
||||
slack: 'Slack',
|
||||
sms: 'SMS',
|
||||
telegram: 'Telegram',
|
||||
tui: 'TUI',
|
||||
webhook: 'Webhook',
|
||||
weixin: 'WeChat',
|
||||
whatsapp: 'WhatsApp',
|
||||
yuanbao: 'Yuanbao'
|
||||
}
|
||||
|
||||
const SOURCE_ALIASES: Record<string, string[]> = {
|
||||
bluebubbles: ['apple messages', 'imessage'],
|
||||
cli: ['terminal'],
|
||||
desktop: ['app', 'gui'],
|
||||
local: ['machine'],
|
||||
qqbot: ['qq'],
|
||||
telegram: ['tg'],
|
||||
tui: ['terminal'],
|
||||
weixin: ['wechat'],
|
||||
whatsapp: ['wa']
|
||||
}
|
||||
|
||||
export function normalizeSessionSource(source: null | string | undefined): string | null {
|
||||
const id = source?.trim().toLowerCase()
|
||||
|
||||
return id || null
|
||||
}
|
||||
|
||||
export function sessionSourceLabel(source: null | string | undefined): string | null {
|
||||
const id = normalizeSessionSource(source)
|
||||
|
||||
if (!id) {
|
||||
return null
|
||||
}
|
||||
|
||||
return SOURCE_LABELS[id] || id.replace(/[_-]+/g, ' ').replace(/\b\w/g, char => char.toUpperCase())
|
||||
}
|
||||
|
||||
export function sessionSourceSearchTerms(source: null | string | undefined): string[] {
|
||||
const id = normalizeSessionSource(source)
|
||||
const label = sessionSourceLabel(id)
|
||||
|
||||
if (!id) {
|
||||
return []
|
||||
}
|
||||
|
||||
return [id, label ?? '', ...(SOURCE_ALIASES[id] ?? [])].filter(Boolean)
|
||||
}
|
||||
Reference in New Issue
Block a user