chatluna-plugin-livingmemory 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/client/index.ts +1 -0
- package/client/locales/en.yml +14 -3
- package/client/locales/zh.yml +15 -4
- package/client/page.css +65 -0
- package/client/page.tsx +246 -131
- package/dist/.vite/manifest.json +5 -1
- package/dist/client.css +3 -1
- package/dist/client.js +1 -1
- package/dist/page-Cv573unw.js +7 -0
- package/lib/contracts/rpc.d.ts +3 -1
- package/lib/contracts/rpc.d.ts.map +1 -1
- package/lib/contracts/webui.d.ts +3 -1
- package/lib/contracts/webui.d.ts.map +1 -1
- package/lib/contracts/webui_live.d.ts +2 -1
- package/lib/contracts/webui_live.d.ts.map +1 -1
- package/lib/index.js +49 -8
- package/lib/index.js.map +1 -1
- package/lib/query.d.ts +3 -3
- package/lib/query.d.ts.map +1 -1
- package/lib/service/app/admin_service.d.ts +2 -2
- package/lib/service/app/admin_service.d.ts.map +1 -1
- package/lib/service/app/webui.d.ts.map +1 -1
- package/lib/service/persistence/repository.d.ts +3 -0
- package/lib/service/persistence/repository.d.ts.map +1 -1
- package/lib/service.d.ts.map +1 -1
- package/package.json +4 -1
- package/src/contracts/rpc.ts +6 -1
- package/src/contracts/webui.ts +3 -1
- package/src/contracts/webui_live.ts +2 -0
- package/dist/page-EGG2hcC3.js +0 -3
package/README.md
CHANGED
package/client/index.ts
CHANGED
package/client/locales/en.yml
CHANGED
|
@@ -79,10 +79,14 @@ jobs.dreamRunning: 'Dream is already running for “{preset}”'
|
|
|
79
79
|
jobs.dreamInsufficient: 'Not enough memories in “{preset}” to run Dream'
|
|
80
80
|
jobs.rebuildIndex: Rebuild vector index
|
|
81
81
|
jobs.empty: No jobs recorded yet
|
|
82
|
-
|
|
82
|
+
jobs.startedAt: Started
|
|
83
|
+
jobs.finishedAt: Finished
|
|
84
|
+
jobs.id: Job ID
|
|
85
|
+
jobs.detail: View original record
|
|
86
|
+
job.kind.extract: Memory extraction
|
|
83
87
|
job.kind.dream: Dream
|
|
84
|
-
job.kind.recall:
|
|
85
|
-
job.kind.index: Index
|
|
88
|
+
job.kind.recall: Memory recall
|
|
89
|
+
job.kind.index: Index maintenance
|
|
86
90
|
job.status.pending: Pending
|
|
87
91
|
job.status.running: Running
|
|
88
92
|
job.status.completed: Completed
|
|
@@ -106,6 +110,13 @@ tab.profiles: Profiles
|
|
|
106
110
|
tab.snapshots: Snapshots
|
|
107
111
|
|
|
108
112
|
profiles.empty: No user profile has been generated for this preset
|
|
113
|
+
profiles.directory: User directory
|
|
114
|
+
profiles.linkedMemories: Linked memories
|
|
115
|
+
profiles.search: Search by name or user ID
|
|
116
|
+
profiles.clearSearch: Clear search
|
|
117
|
+
profiles.noMatch: No matching users
|
|
118
|
+
profiles.noMemories: This profile has no linked memories.
|
|
119
|
+
profiles.unavailableMemories: 'Linked memories no longer available: {count}.'
|
|
109
120
|
profiles.hint: The profile is distilled from linked memories; once saved it is no longer overwritten automatically.
|
|
110
121
|
profiles.sourceCount: '{count} linked memories'
|
|
111
122
|
profiles.regenerate: Regenerate
|
package/client/locales/zh.yml
CHANGED
|
@@ -119,10 +119,14 @@ jobs.dreamRunning: 「{preset}」已有 Dream 在运行
|
|
|
119
119
|
jobs.dreamInsufficient: 「{preset}」可整理的记忆不足
|
|
120
120
|
jobs.rebuildIndex: 重建向量索引
|
|
121
121
|
jobs.empty: 还没有任务记录
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
jobs.startedAt: 开始
|
|
123
|
+
jobs.finishedAt: 结束
|
|
124
|
+
jobs.id: 任务 ID
|
|
125
|
+
jobs.detail: 查看原始记录
|
|
126
|
+
job.kind.extract: 记忆提取
|
|
127
|
+
job.kind.dream: Dream 整理
|
|
128
|
+
job.kind.recall: 记忆召回
|
|
129
|
+
job.kind.index: 索引维护
|
|
126
130
|
job.status.pending: 排队中
|
|
127
131
|
job.status.running: 运行中
|
|
128
132
|
job.status.completed: 已完成
|
|
@@ -146,6 +150,13 @@ tab.profiles: 用户画像
|
|
|
146
150
|
tab.snapshots: 快照
|
|
147
151
|
|
|
148
152
|
profiles.empty: 还没有为这个预设生成过用户画像
|
|
153
|
+
profiles.directory: 用户目录
|
|
154
|
+
profiles.linkedMemories: 关联记忆
|
|
155
|
+
profiles.search: 搜索昵称或用户 ID
|
|
156
|
+
profiles.clearSearch: 清除搜索
|
|
157
|
+
profiles.noMatch: 没有找到匹配的用户
|
|
158
|
+
profiles.noMemories: 这份画像没有关联记忆。
|
|
159
|
+
profiles.unavailableMemories: '有 {count} 条关联记忆已无法查看。'
|
|
149
160
|
profiles.hint: 画像由模型从关联记忆提炼;保存后不再被自动生成覆盖。
|
|
150
161
|
profiles.sourceCount: '关联 {count} 条记忆'
|
|
151
162
|
profiles.regenerate: 重新生成
|
package/client/page.css
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
main:has(.livingmemory-page),
|
|
2
|
+
.livingmemory-page,
|
|
3
|
+
.livingmemory-page .overflow-y-auto {
|
|
4
|
+
scrollbar-width: none;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.livingmemory-profile {
|
|
8
|
+
--disclosure-duration: 280ms;
|
|
9
|
+
--group-inset: clamp(1rem, 2.5cqi, 2rem);
|
|
10
|
+
max-width: 64rem;
|
|
11
|
+
margin-inline: auto;
|
|
12
|
+
padding-inline: clamp(1rem, 3%, 2.5rem);
|
|
13
|
+
padding-block-start: clamp(1rem, 3cqi, 3rem);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.livingmemory-profile-group {
|
|
17
|
+
border-radius: 1.125rem;
|
|
18
|
+
background: color-mix(in srgb, var(--card) 85%, var(--muted));
|
|
19
|
+
color: var(--card-foreground);
|
|
20
|
+
box-shadow: 0 0 0 1px color-mix(in srgb, var(--border) 60%, transparent),
|
|
21
|
+
0 2px 8px rgb(0 0 0 / 4%);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.livingmemory-profile-reading {
|
|
25
|
+
padding: var(--group-inset);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.livingmemory-profile-trigger {
|
|
29
|
+
border-radius: inherit;
|
|
30
|
+
padding: 1rem var(--group-inset);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.livingmemory-profile-list {
|
|
34
|
+
padding: 0 var(--group-inset) .5rem;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.livingmemory-profile-sources {
|
|
38
|
+
height: var(--collapsible-panel-height);
|
|
39
|
+
overflow: hidden;
|
|
40
|
+
transition: height var(--disclosure-duration) linear, opacity var(--disclosure-duration) linear;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.livingmemory-profile-sources:is([data-starting-style], [data-ending-style]) {
|
|
44
|
+
height: 0;
|
|
45
|
+
opacity: 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.livingmemory-profile-chevron {
|
|
49
|
+
width: .5rem;
|
|
50
|
+
height: .5rem;
|
|
51
|
+
border: solid currentColor;
|
|
52
|
+
border-width: 1.5px 1.5px 0 0;
|
|
53
|
+
transform: rotate(45deg);
|
|
54
|
+
transition: transform var(--disclosure-duration) linear;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
[aria-expanded="true"] > .livingmemory-profile-chevron {
|
|
58
|
+
transform: rotate(135deg);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@media (prefers-reduced-motion: reduce) {
|
|
62
|
+
.livingmemory-profile {
|
|
63
|
+
--disclosure-duration: 0s;
|
|
64
|
+
}
|
|
65
|
+
}
|
package/client/page.tsx
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
|
+
import type {} from '@chatluna/adapter-webui'
|
|
3
|
+
import { findDirectoryEntity } from '@chatluna/adapter-webui/client/entity-directory'
|
|
4
|
+
import { skipToken, useQuery } from '@tanstack/react-query'
|
|
2
5
|
import {
|
|
6
|
+
Alert,
|
|
7
|
+
Avatar,
|
|
8
|
+
AvatarFallback,
|
|
9
|
+
AvatarImage,
|
|
3
10
|
Badge,
|
|
4
11
|
Button,
|
|
5
12
|
Checkbox,
|
|
13
|
+
Collapsible,
|
|
14
|
+
CollapsibleContent,
|
|
15
|
+
CollapsibleTrigger,
|
|
6
16
|
Dialog,
|
|
7
17
|
DialogContent,
|
|
8
18
|
DialogDescription,
|
|
@@ -12,11 +22,14 @@ import {
|
|
|
12
22
|
Field,
|
|
13
23
|
FieldLabel,
|
|
14
24
|
Input,
|
|
25
|
+
SearchBox,
|
|
26
|
+
Skeleton,
|
|
15
27
|
Select,
|
|
16
28
|
SelectContent,
|
|
17
29
|
SelectItem,
|
|
18
30
|
SelectTrigger,
|
|
19
31
|
SelectValue,
|
|
32
|
+
SlidingHighlight,
|
|
20
33
|
Textarea,
|
|
21
34
|
Tooltip,
|
|
22
35
|
TooltipContent,
|
|
@@ -57,11 +70,12 @@ const useT = (): Translate => useTranslate(LOCALE_NS)
|
|
|
57
70
|
|
|
58
71
|
const report = (error: unknown) => toast.error(apiErrorMessage(error))
|
|
59
72
|
|
|
73
|
+
const calendarDate = (date: Date) => `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`
|
|
74
|
+
const clockTime = (date: Date) => [date.getHours(), date.getMinutes()].map(n => String(n).padStart(2, '0')).join(':')
|
|
60
75
|
const formatTime = (at: number | null | undefined) => {
|
|
61
76
|
if (at == null) return '—'
|
|
62
77
|
const date = new Date(at)
|
|
63
|
-
|
|
64
|
-
return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()} ${pad(date.getHours())}:${pad(date.getMinutes())}`
|
|
78
|
+
return `${calendarDate(date)} ${clockTime(date)}`
|
|
65
79
|
}
|
|
66
80
|
|
|
67
81
|
type StatusFilter = 'active' | 'archived' | 'all'
|
|
@@ -113,7 +127,7 @@ export function LivingMemoryPage() {
|
|
|
113
127
|
return <EntriesPanel key={`${selection.revision}:${active}`} presetId={active} initialStatus={selection.status}
|
|
114
128
|
onCreate={() => setCreating(true)} />
|
|
115
129
|
case 'profiles':
|
|
116
|
-
return <ProfilesPanel presetId={active} />
|
|
130
|
+
return <ProfilesPanel key={active} presetId={active} />
|
|
117
131
|
case 'personas':
|
|
118
132
|
return <PersonaPanel key={active} presetId={active} />
|
|
119
133
|
case 'snapshots':
|
|
@@ -126,7 +140,7 @@ export function LivingMemoryPage() {
|
|
|
126
140
|
}
|
|
127
141
|
|
|
128
142
|
return (
|
|
129
|
-
<div className="flex h-full min-w-0 flex-col gap-4 overflow-y-auto p-4 sm:p-6">
|
|
143
|
+
<div className="livingmemory-page flex h-full min-w-0 flex-col gap-4 overflow-y-auto p-4 sm:p-6">
|
|
130
144
|
<header className="flex flex-wrap items-center justify-between gap-x-4 gap-y-2 border-b border-border pb-2">
|
|
131
145
|
<nav className="flex max-w-full items-center gap-1 overflow-x-auto" aria-label={t('tab.navigation')}>
|
|
132
146
|
{tabs.map(key => (
|
|
@@ -239,6 +253,11 @@ function Warnings({
|
|
|
239
253
|
)
|
|
240
254
|
}
|
|
241
255
|
|
|
256
|
+
function useSpeakerNames(presetId: string) {
|
|
257
|
+
const speakers = useLive('livingmemory.speakers', { presetId })
|
|
258
|
+
return new Map(speakers.data?.map(speaker => [speaker.speakerKey, speaker.speakerLabel]))
|
|
259
|
+
}
|
|
260
|
+
|
|
242
261
|
function EntriesPanel({ presetId, initialStatus, onCreate }: { presetId: string; initialStatus: StatusFilter; onCreate(): void }) {
|
|
243
262
|
const t = useT()
|
|
244
263
|
const [status, setStatus] = React.useState<StatusFilter>(initialStatus)
|
|
@@ -247,8 +266,7 @@ function EntriesPanel({ presetId, initialStatus, onCreate }: { presetId: string;
|
|
|
247
266
|
const filter: MemoryListFilter = { presetId, status }
|
|
248
267
|
if (type !== 'all') filter.type = type as MemoryEntryRecord['type']
|
|
249
268
|
if (keyword.trim()) filter.keyword = keyword.trim()
|
|
250
|
-
const
|
|
251
|
-
const names = new Map(speakers.data?.map((speaker) => [speaker.speakerKey, speaker.speakerLabel]))
|
|
269
|
+
const names = useSpeakerNames(presetId)
|
|
252
270
|
|
|
253
271
|
return (
|
|
254
272
|
<div className="flex min-h-0 flex-1 flex-col gap-3">
|
|
@@ -458,7 +476,6 @@ interface MemoryCardProps {
|
|
|
458
476
|
|
|
459
477
|
function MemoryCard({ entry, names, selected, selecting, onSelect, onEdit, onArchive, onDelete }: MemoryCardProps) {
|
|
460
478
|
const t = useT()
|
|
461
|
-
const speakers = entry.speakerKeys.map(key => names.get(key) ?? key).join(', ')
|
|
462
479
|
|
|
463
480
|
return (
|
|
464
481
|
<li data-selected={selected}
|
|
@@ -473,24 +490,7 @@ function MemoryCard({ entry, names, selected, selecting, onSelect, onEdit, onArc
|
|
|
473
490
|
{entry.summary && <h2 className="px-3 pb-1.5 text-base font-semibold leading-snug [overflow-wrap:anywhere]">{entry.summary}</h2>}
|
|
474
491
|
<div className="row-start-3 flex flex-col gap-2.5 px-3 pb-3">
|
|
475
492
|
<MemoryBody content={entry.content} />
|
|
476
|
-
{entry
|
|
477
|
-
<ul className="flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-foreground">
|
|
478
|
-
{entry.keywords.map(word => <li key={word} className="min-w-0 [overflow-wrap:anywhere]">#{word}</li>)}
|
|
479
|
-
</ul>
|
|
480
|
-
)}
|
|
481
|
-
<div className="border-t border-border pt-2 text-xs leading-relaxed [overflow-wrap:anywhere]">
|
|
482
|
-
<dl className="grid grid-cols-[auto_1fr] items-baseline gap-x-3 gap-y-0.5">
|
|
483
|
-
<dt className="text-muted-foreground">{t('field.importance')}</dt>
|
|
484
|
-
<dd>{entry.importance ?? '—'}</dd>
|
|
485
|
-
{entry.sentiment && <>
|
|
486
|
-
<dt className="text-muted-foreground">{t('field.sentiment')}</dt>
|
|
487
|
-
<dd>{entry.sentiment}</dd>
|
|
488
|
-
</>}
|
|
489
|
-
<dt className="text-muted-foreground">{t('field.speakers')}</dt>
|
|
490
|
-
<dd>{speakers || t('entries.noSpeakers')}</dd>
|
|
491
|
-
</dl>
|
|
492
|
-
<p className="mt-0.5">{entry.sourceLabel}</p>
|
|
493
|
-
</div>
|
|
493
|
+
<MemoryFields entry={entry} names={names} />
|
|
494
494
|
</div>
|
|
495
495
|
<footer className="row-start-4 flex flex-wrap items-center justify-between gap-2 rounded-b-xl border-t border-border bg-muted/30 px-3 py-1.5">
|
|
496
496
|
<span className="text-xs text-muted-foreground">{t('field.updatedAt')} {formatTime(entry.updatedAt)}</span>
|
|
@@ -507,6 +507,33 @@ function MemoryCard({ entry, names, selected, selecting, onSelect, onEdit, onArc
|
|
|
507
507
|
)
|
|
508
508
|
}
|
|
509
509
|
|
|
510
|
+
function MemoryFields({ entry, names }: Pick<MemoryCardProps, 'entry' | 'names'>) {
|
|
511
|
+
const t = useT()
|
|
512
|
+
const speakers = entry.speakerKeys.map(key => names.get(key) ?? key).join(', ')
|
|
513
|
+
return (
|
|
514
|
+
<>
|
|
515
|
+
{entry.keywords.length > 0 && (
|
|
516
|
+
<ul className="flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-foreground">
|
|
517
|
+
{entry.keywords.map(word => <li key={word} className="min-w-0 [overflow-wrap:anywhere]">#{word}</li>)}
|
|
518
|
+
</ul>
|
|
519
|
+
)}
|
|
520
|
+
<div className="border-t border-border pt-2 text-xs leading-relaxed [overflow-wrap:anywhere]">
|
|
521
|
+
<dl className="grid grid-cols-[auto_1fr] items-baseline gap-x-3 gap-y-0.5">
|
|
522
|
+
<dt className="text-muted-foreground">{t('field.importance')}</dt>
|
|
523
|
+
<dd>{entry.importance ?? '—'}</dd>
|
|
524
|
+
{entry.sentiment && <>
|
|
525
|
+
<dt className="text-muted-foreground">{t('field.sentiment')}</dt>
|
|
526
|
+
<dd>{entry.sentiment}</dd>
|
|
527
|
+
</>}
|
|
528
|
+
<dt className="text-muted-foreground">{t('field.speakers')}</dt>
|
|
529
|
+
<dd>{speakers || t('entries.noSpeakers')}</dd>
|
|
530
|
+
</dl>
|
|
531
|
+
<p className="mt-0.5">{entry.sourceLabel}</p>
|
|
532
|
+
</div>
|
|
533
|
+
</>
|
|
534
|
+
)
|
|
535
|
+
}
|
|
536
|
+
|
|
510
537
|
function MemoryBody({ content }: { content: string }) {
|
|
511
538
|
const text = React.useRef<HTMLParagraphElement>(null)
|
|
512
539
|
const popup = React.useRef<HTMLDivElement>(null)
|
|
@@ -558,96 +585,161 @@ function MemoryBody({ content }: { content: string }) {
|
|
|
558
585
|
)
|
|
559
586
|
}
|
|
560
587
|
|
|
588
|
+
const profileName = ({ speakerLabel, speakerId }: LivingMemoryProfileView) =>
|
|
589
|
+
speakerId ? `${speakerLabel}(${speakerId})` : speakerLabel
|
|
590
|
+
|
|
591
|
+
function ProfileAvatar({ profile, selfId }: { profile: LivingMemoryProfileView; selfId: string | undefined }) {
|
|
592
|
+
const { platform, speakerId } = profile
|
|
593
|
+
const { data } = useQuery({
|
|
594
|
+
queryKey: ['directory', 'entity', 'user', platform, selfId, speakerId],
|
|
595
|
+
queryFn: platform && selfId && speakerId
|
|
596
|
+
? ({ signal }) => findDirectoryEntity({ kind: 'user', platform, selfId, id: speakerId }, signal)
|
|
597
|
+
: skipToken,
|
|
598
|
+
staleTime: 60_000
|
|
599
|
+
})
|
|
600
|
+
return <Avatar aria-hidden="true" style={{ width: 32, height: 32, overflow: 'hidden' }}>
|
|
601
|
+
{data?.avatar && <AvatarImage src={data.avatar} alt="" referrerPolicy="no-referrer" />}
|
|
602
|
+
<AvatarFallback>{Array.from(profile.speakerLabel)[0]}</AvatarFallback>
|
|
603
|
+
</Avatar>
|
|
604
|
+
}
|
|
605
|
+
|
|
561
606
|
function ProfilesPanel({ presetId }: { presetId: string }) {
|
|
562
607
|
const t = useT()
|
|
563
608
|
const [page, setPage] = React.useState(1)
|
|
609
|
+
const [keyword, setKeyword] = React.useState('')
|
|
610
|
+
const [selectedId, setSelectedId] = React.useState<string>()
|
|
564
611
|
const [editing, setEditing] = React.useState<LivingMemoryProfileView>()
|
|
565
|
-
const
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
pageSize: PAGE_SIZE
|
|
569
|
-
})
|
|
570
|
-
const items = profiles.data?.profiles ?? []
|
|
612
|
+
const bots = useLive('adapters.bots').data?.bots
|
|
613
|
+
const { data, error } = useLive('livingmemory.profiles', { presetId, keyword, page, pageSize: PAGE_SIZE })
|
|
614
|
+
const profile = data?.profiles.find(item => item.id === selectedId) ?? data?.profiles[0]
|
|
571
615
|
|
|
572
|
-
React.useEffect(() =>
|
|
616
|
+
React.useEffect(() => {
|
|
617
|
+
if (data && page > 1 && !data.profiles.length) {
|
|
618
|
+
setPage(Math.max(1, Math.ceil(data.total / PAGE_SIZE)))
|
|
619
|
+
}
|
|
620
|
+
}, [data, page])
|
|
573
621
|
|
|
574
|
-
|
|
622
|
+
function renderAvatar(profile: LivingMemoryProfileView) {
|
|
623
|
+
const selfId = bots?.find(bot => bot.platform === profile.platform)?.selfId
|
|
624
|
+
return <ProfileAvatar profile={profile} selfId={selfId} />
|
|
625
|
+
}
|
|
575
626
|
|
|
576
627
|
return (
|
|
577
|
-
<div className="
|
|
578
|
-
<
|
|
579
|
-
{
|
|
580
|
-
<
|
|
581
|
-
|
|
582
|
-
className="
|
|
583
|
-
>
|
|
584
|
-
<
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
{
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
628
|
+
<div className="@container min-h-0 flex-1">
|
|
629
|
+
<div className="grid gap-5 @2xl:h-full @2xl:grid-cols-[minmax(0,1fr)_15rem] @2xl:gap-6">
|
|
630
|
+
<nav aria-label={t('profiles.directory')} className="flex min-h-0 min-w-0 flex-col gap-2 border-b border-border pb-4 @2xl:col-start-2 @2xl:row-start-1 @2xl:border-b-0 @2xl:border-l @2xl:pb-0 @2xl:pl-4">
|
|
631
|
+
<h2 className="text-sm font-semibold">{t('profiles.directory')}</h2>
|
|
632
|
+
<SearchBox value={keyword} onChange={value => { setKeyword(value); setPage(1) }}
|
|
633
|
+
placeholder={t('profiles.search')} clearLabel={t('profiles.clearSearch')} className="sm:w-full" />
|
|
634
|
+
<div className="relative isolate max-h-44 overflow-y-auto @2xl:max-h-none">
|
|
635
|
+
<SlidingHighlight hover="[data-profile-row]" className="rounded-lg bg-sidebar-accent/60 duration-150" />
|
|
636
|
+
<SlidingHighlight attribute="aria-current" className="rounded-lg bg-sidebar-accent" />
|
|
637
|
+
<ul className="space-y-0.5">
|
|
638
|
+
{data?.profiles.map(item => (
|
|
639
|
+
<li key={item.id}>
|
|
640
|
+
<button type="button" data-profile-row aria-current={item.id === profile?.id ? 'true' : undefined}
|
|
641
|
+
onClick={() => setSelectedId(item.id)}
|
|
642
|
+
className="flex w-full items-center gap-3 rounded-lg px-2 py-2 text-left transition-colors hover:text-sidebar-accent-foreground aria-current:text-sidebar-accent-foreground focus-visible:-outline-offset-2">
|
|
643
|
+
{renderAvatar(item)}
|
|
644
|
+
<span className="min-w-0">
|
|
645
|
+
<span className="block text-sm font-medium [overflow-wrap:anywhere]">{profileName(item)}</span>
|
|
646
|
+
<span className="block text-xs text-muted-foreground">{t('profiles.sourceCount', { count: item.sourceMemoryCount })}</span>
|
|
647
|
+
</span>
|
|
648
|
+
</button>
|
|
649
|
+
</li>
|
|
650
|
+
))}
|
|
651
|
+
</ul>
|
|
652
|
+
</div>
|
|
653
|
+
<Pager page={page} pageSize={PAGE_SIZE} total={data?.total ?? 0} onChange={setPage} />
|
|
654
|
+
</nav>
|
|
655
|
+
<div key={profile?.id} className="min-w-0 overflow-y-auto @2xl:col-start-1 @2xl:row-start-1">
|
|
656
|
+
{error && <Alert variant="destructive">{error}</Alert>}
|
|
657
|
+
{!error && !data && <Skeleton className="h-32 w-full" />}
|
|
658
|
+
{!error && data && !profile && <EmptyState title={t(keyword.trim() ? 'profiles.noMatch' : 'profiles.empty')} />}
|
|
659
|
+
{profile && (
|
|
660
|
+
<article className="livingmemory-profile space-y-4 pb-8">
|
|
661
|
+
<header className="flex flex-wrap items-center justify-between gap-4 px-1 pb-1">
|
|
662
|
+
<div className="flex min-w-0 items-center gap-4">
|
|
663
|
+
{renderAvatar(profile)}
|
|
664
|
+
<div className="min-w-0">
|
|
665
|
+
<h1 className="text-2xl font-semibold tracking-tight [overflow-wrap:anywhere]">{profileName(profile)}</h1>
|
|
666
|
+
<p className="mt-1 text-xs tabular-nums text-muted-foreground">{t('field.updatedAt')} · {formatTime(profile.updatedAt)}</p>
|
|
667
|
+
</div>
|
|
668
|
+
</div>
|
|
669
|
+
<div className="flex flex-wrap gap-2">
|
|
670
|
+
<Button size="sm" variant="outline" onClick={() => setEditing(profile)}>{t('common.edit')}</Button>
|
|
671
|
+
<Button size="sm" variant="outline" onClick={() => void callAction('livingmemory.regenerateProfile', {
|
|
672
|
+
presetId, speakerKey: profile.speakerKey
|
|
673
|
+
}).catch(report)}>{t('profiles.regenerate')}</Button>
|
|
674
|
+
<Button size="sm" variant="outline" onClick={() => void callAction('livingmemory.deleteProfile', { id: profile.id }).catch(report)}>
|
|
675
|
+
{t('profiles.delete')}
|
|
676
|
+
</Button>
|
|
677
|
+
</div>
|
|
678
|
+
</header>
|
|
679
|
+
<section className="livingmemory-profile-group livingmemory-profile-reading">
|
|
680
|
+
<h2 className="mb-3 text-sm font-semibold text-muted-foreground">{t('tab.profiles')}</h2>
|
|
681
|
+
<p className="whitespace-pre-wrap text-base leading-8 [overflow-wrap:anywhere]">{profile.content}</p>
|
|
682
|
+
</section>
|
|
683
|
+
<ProfileMemories presetId={presetId} profile={profile} />
|
|
684
|
+
</article>
|
|
685
|
+
)}
|
|
686
|
+
</div>
|
|
687
|
+
</div>
|
|
688
|
+
{editing && <ProfileDialog profile={editing} onClose={() => setEditing(undefined)} />}
|
|
689
|
+
</div>
|
|
690
|
+
)
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
function ProfileMemories({ presetId, profile }: { presetId: string; profile: LivingMemoryProfileView }) {
|
|
694
|
+
const t = useT()
|
|
695
|
+
const count = profile.sourceMemoryCount
|
|
696
|
+
if (!count) return <p className="livingmemory-profile-group px-5 py-4 text-sm text-muted-foreground">{t('profiles.noMemories')}</p>
|
|
697
|
+
return (
|
|
698
|
+
<Collapsible className="livingmemory-profile-group">
|
|
699
|
+
<CollapsibleTrigger className="livingmemory-profile-trigger flex w-full items-center gap-3 text-left text-sm font-semibold hover:bg-muted/50 focus-visible:-outline-offset-2">
|
|
700
|
+
<svg aria-hidden="true" className="size-5 shrink-0 text-muted-foreground" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinejoin="round">
|
|
701
|
+
<path d="M3 5.5c3.5-1 6-.7 9 1.2 3-1.9 5.5-2.2 9-1.2V19c-3.5-1-6-.7-9 1.2-3-1.9-5.5-2.2-9-1.2zM12 6.7v13.5" />
|
|
702
|
+
</svg>
|
|
703
|
+
{t('profiles.linkedMemories')}
|
|
704
|
+
<span className="ml-auto text-sm font-normal tabular-nums text-muted-foreground">{count}</span>
|
|
705
|
+
<span aria-hidden="true" className="livingmemory-profile-chevron" />
|
|
706
|
+
</CollapsibleTrigger>
|
|
707
|
+
<CollapsibleContent className="livingmemory-profile-sources">
|
|
708
|
+
<ProfileMemoryList presetId={presetId} profileId={profile.id} count={count} />
|
|
709
|
+
</CollapsibleContent>
|
|
710
|
+
</Collapsible>
|
|
711
|
+
)
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
function ProfileMemoryList({ presetId, profileId, count }: { presetId: string; profileId: string; count: number }) {
|
|
715
|
+
const t = useT()
|
|
716
|
+
const { data, error } = useLive('livingmemory.profileMemories', { presetId, profileId })
|
|
717
|
+
const names = useSpeakerNames(presetId)
|
|
718
|
+
if (error) return <Alert variant="destructive">{error}</Alert>
|
|
719
|
+
if (!data) return <Skeleton className="mx-5 mb-4 h-16" />
|
|
720
|
+
return (
|
|
721
|
+
<div className="livingmemory-profile-list">
|
|
722
|
+
<ol className="divide-y divide-border/50">
|
|
723
|
+
{data.map((entry, index) => (
|
|
724
|
+
<li key={entry.id} className="flex gap-4 py-4">
|
|
725
|
+
<span aria-hidden="true" className="pt-0.5 text-xs tabular-nums text-muted-foreground">{String(index + 1).padStart(2, '0')}</span>
|
|
726
|
+
<div className="min-w-0 flex-1">
|
|
727
|
+
<Badge variant="secondary">{t(`type.${entry.type}`)}</Badge>
|
|
728
|
+
<span className="ml-2 text-xs text-muted-foreground">{t(`status.${entry.status}`)}</span>
|
|
729
|
+
{entry.summary && <h3 className="mt-2 font-semibold [overflow-wrap:anywhere]">{entry.summary}</h3>}
|
|
730
|
+
<p className="mt-2 whitespace-pre-wrap text-sm leading-6 [overflow-wrap:anywhere]">{entry.content}</p>
|
|
731
|
+
<div className="mt-3 space-y-2">
|
|
732
|
+
<MemoryFields entry={entry} names={names} />
|
|
733
|
+
<p className="flex flex-wrap gap-x-4 text-xs text-muted-foreground">
|
|
734
|
+
<span>{t('field.createdAt')} {formatTime(entry.createdAt)}</span>
|
|
735
|
+
<span>{t('field.updatedAt')} {formatTime(entry.updatedAt)}</span>
|
|
736
|
+
</p>
|
|
737
|
+
</div>
|
|
635
738
|
</div>
|
|
636
739
|
</li>
|
|
637
740
|
))}
|
|
638
|
-
</
|
|
639
|
-
<
|
|
640
|
-
page={page}
|
|
641
|
-
pageSize={PAGE_SIZE}
|
|
642
|
-
total={profiles.data?.total ?? 0}
|
|
643
|
-
onChange={setPage}
|
|
644
|
-
/>
|
|
645
|
-
{editing !== undefined && (
|
|
646
|
-
<ProfileDialog
|
|
647
|
-
profile={editing}
|
|
648
|
-
onClose={() => setEditing(undefined)}
|
|
649
|
-
/>
|
|
650
|
-
)}
|
|
741
|
+
</ol>
|
|
742
|
+
{count > data.length && <p className="py-3 text-sm text-muted-foreground">{t('profiles.unavailableMemories', { count: count - data.length })}</p>}
|
|
651
743
|
</div>
|
|
652
744
|
)
|
|
653
745
|
}
|
|
@@ -665,7 +757,7 @@ function ProfileDialog({
|
|
|
665
757
|
<Dialog open onOpenChange={(open) => (open ? undefined : onClose())}>
|
|
666
758
|
<DialogContent className="max-h-[85dvh] overflow-y-auto sm:max-w-2xl">
|
|
667
759
|
<DialogHeader>
|
|
668
|
-
<DialogTitle>{profile
|
|
760
|
+
<DialogTitle>{profileName(profile)}</DialogTitle>
|
|
669
761
|
<DialogDescription>
|
|
670
762
|
{t('profiles.hint')}
|
|
671
763
|
</DialogDescription>
|
|
@@ -916,39 +1008,62 @@ function RunDreamButton({ presetId }: { presetId: string }) {
|
|
|
916
1008
|
|
|
917
1009
|
function JobsPanel({ presetId }: { presetId: string }) {
|
|
918
1010
|
const t = useT()
|
|
919
|
-
const
|
|
920
|
-
|
|
921
|
-
if (
|
|
1011
|
+
const { data, error } = useLive('livingmemory.jobs', { presetId })
|
|
1012
|
+
if (error) return <Alert variant="destructive">{error}</Alert>
|
|
1013
|
+
if (!data) return <Skeleton className="h-12 w-full" />
|
|
1014
|
+
if (!data.length) return <EmptyState title={t('jobs.empty')} />
|
|
1015
|
+
const days = Map.groupBy(data, job => calendarDate(new Date(job.createdAt)))
|
|
922
1016
|
return (
|
|
923
|
-
<
|
|
924
|
-
|
|
925
|
-
|
|
1017
|
+
<div className="@container min-h-0 flex-1 overflow-y-auto">
|
|
1018
|
+
<div className="mx-auto max-w-6xl space-y-7 px-1 py-2">
|
|
1019
|
+
{Array.from(days, ([day, jobs]) => (
|
|
1020
|
+
<section key={day}>
|
|
1021
|
+
<h2 className="mb-1 border-b border-border pb-2 text-sm font-semibold tabular-nums">{day}</h2>
|
|
1022
|
+
<ul className="divide-y divide-border/60">
|
|
1023
|
+
{jobs.map(job => <JobRow key={job.id} job={job} />)}
|
|
1024
|
+
</ul>
|
|
1025
|
+
</section>
|
|
1026
|
+
))}
|
|
1027
|
+
</div>
|
|
1028
|
+
</div>
|
|
926
1029
|
)
|
|
927
1030
|
}
|
|
928
1031
|
|
|
929
1032
|
function JobRow({ job }: { job: LivingMemoryJobView }) {
|
|
930
1033
|
const t = useT()
|
|
1034
|
+
const [summary, ...detailLines] = job.detail.split('\n', 3)
|
|
1035
|
+
const operations = job.kind === 'dream' && job.detail !== job.error ? detailLines.shift() : undefined
|
|
1036
|
+
const error = job.error?.split('\n', 1)[0]
|
|
1037
|
+
const rawDetail = detailLines.length ? job.detail : ''
|
|
1038
|
+
const stack = job.error && job.error !== error && !rawDetail.includes(job.error) ? job.error : ''
|
|
1039
|
+
const record = [rawDetail, stack].filter(Boolean).join('\n\n')
|
|
1040
|
+
const created = new Date(job.createdAt)
|
|
931
1041
|
return (
|
|
932
|
-
<li
|
|
933
|
-
<
|
|
934
|
-
<
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1042
|
+
<li>
|
|
1043
|
+
<details className="group">
|
|
1044
|
+
<summary className="grid cursor-pointer list-none grid-cols-[3rem_1fr_auto_1rem] items-baseline gap-x-3 gap-y-1 rounded-md px-2 py-3 text-sm hover:bg-muted/40 focus-visible:outline-ring @xl:grid-cols-[3rem_7rem_5rem_minmax(0,1fr)_1rem] [&::-webkit-details-marker]:hidden">
|
|
1045
|
+
<time dateTime={created.toISOString()} className="text-xs tabular-nums text-muted-foreground">{clockTime(created)}</time>
|
|
1046
|
+
<span className="font-medium">{t(`job.kind.${job.kind}`)}</span>
|
|
1047
|
+
<span data-status={job.status} className="text-xs font-medium text-muted-foreground data-[status=failed]:text-destructive data-[status=running]:text-primary data-[status=partial]:text-foreground">{t(`job.status.${job.status}`)}</span>
|
|
1048
|
+
<span className="col-span-full row-start-2 min-w-0 space-y-0.5 @xl:col-span-1 @xl:col-start-4 @xl:row-start-1">
|
|
1049
|
+
{summary && summary !== error && <span className="line-clamp-1 text-muted-foreground group-open:line-clamp-none [overflow-wrap:anywhere]">{summary}</span>}
|
|
1050
|
+
{error && <span className="line-clamp-1 text-destructive group-open:line-clamp-none [overflow-wrap:anywhere]">{error}</span>}
|
|
1051
|
+
</span>
|
|
1052
|
+
<span aria-hidden="true" className="col-start-4 row-start-1 self-center justify-self-center text-muted-foreground transition-transform group-open:rotate-90 motion-reduce:transition-none @xl:col-start-5">›</span>
|
|
1053
|
+
</summary>
|
|
1054
|
+
<div className="mb-3 ml-2 space-y-3 border-l-2 border-border py-1 pl-4 text-sm">
|
|
1055
|
+
<dl className="flex flex-wrap gap-x-6 gap-y-1 text-xs text-muted-foreground">
|
|
1056
|
+
{job.startedAt !== null && <div><dt className="inline">{t('jobs.startedAt')} · </dt><dd className="inline">{formatTime(job.startedAt)}</dd></div>}
|
|
1057
|
+
{job.finishedAt !== null && <div><dt className="inline">{t('jobs.finishedAt')} · </dt><dd className="inline">{formatTime(job.finishedAt)}</dd></div>}
|
|
1058
|
+
<div><dt className="inline">{t('jobs.id')} · </dt><dd className="inline font-mono [overflow-wrap:anywhere]">{job.id}</dd></div>
|
|
1059
|
+
</dl>
|
|
1060
|
+
{operations && <p className="text-muted-foreground [overflow-wrap:anywhere]">{operations}</p>}
|
|
1061
|
+
{record && <details>
|
|
1062
|
+
<summary className="cursor-pointer text-muted-foreground">{t('jobs.detail')}</summary>
|
|
1063
|
+
<pre className="mt-2 max-h-64 overflow-y-auto whitespace-pre-wrap bg-muted/40 p-3 text-xs leading-relaxed [overflow-wrap:anywhere]">{record}</pre>
|
|
1064
|
+
</details>}
|
|
1065
|
+
</div>
|
|
1066
|
+
</details>
|
|
952
1067
|
</li>
|
|
953
1068
|
)
|
|
954
1069
|
}
|