Files
aigc-home/calliope-web/src/lib/components/settings/MemoryPanel.svelte
T
施工员andmultica-agent 1a7a682cd0 HEL-615: 全部页面统一为 A「片场暗房」界面
- 设置页重写进 AppShell:生成与队列 / 智能体运行 / 存储路径三段,其余设置入口链到模型设置、ComfyUI 连接、智能体;旧 ?tab= 链接跳转到对应新页
- 项目卡状态标签改为按五段真实进度显示(已完成 / 某阶段生成中·待确认 / 进行中 / 待开始)
- 首页生成任务行对齐 a1(来源标签、项目名、进度条、本地时间)
- 连接页:右栏默认新增表单 + 任务使用目标面板,进入页面自动实测各连接;模型页默认新增表单、自动 1-token 实测,去掉双加号
- 生图/生视频:生成参数面板标题、通栏生成按钮、成片预览、按类型的历史标题与 16:9 视频历史、顶栏连接状态胶囊,连接状态改用服务器实测
- 智能体页:五个 Agent / Skill 库 / 已装 Skill 面板标题,内置 Skill 中文名,去掉对话空态 Calliope 字样
- 侧栏底部 ComfyUI 状态修正为真实实测(原查询不响应导致一直测试中)
- 统一样式来源:.a-btn/.a-panel/.a-select/.status-chip 等只在 app.css 定义一次,删除各页重复定义;新增 Switch、Button block、ProgressBar tone
- 旧 Calliope 路由(/projects、/project/:id、/canvas、/library、/build-scene、/playground)重定向到 A 页面;页面标题改为影工坊
- 轮询间隔单位改为秒(7 种语言)

Co-authored-by: multica-agent <github@multica.ai>
2026-09-28 16:25:55 +08:00

246 lines
6.5 KiB
Svelte

<script lang="ts">
import { createMutation, createQuery, useQueryClient } from '@tanstack/svelte-query';
import { agentApi, projects } from '$lib/api';
import Button from '$lib/components/ui/Button.svelte';
import Icon from '$lib/components/ui/Icon.svelte';
import { toast } from '$lib/toast';
import { t } from '$lib/i18n.svelte';
const client = useQueryClient();
const memoriesQuery = createQuery({
queryKey: ['agent-memories'],
queryFn: agentApi.listMemories,
});
const projectsQuery = createQuery({
queryKey: ['projects'],
queryFn: projects.list,
});
let newContent = $state('');
let newScope = $state<'global' | 'project'>('global');
let newProjectId = $state<number | null>(null);
let newKind = $state('preference');
const addMutation = createMutation({
mutationFn: () =>
agentApi.addMemory({
content: newContent.trim(),
scope: newScope,
project_id: newScope === 'project' ? newProjectId : null,
kind: newKind,
}),
onSuccess: () => {
newContent = '';
client.invalidateQueries({ queryKey: ['agent-memories'] });
toast.success(t('memory.saved'));
},
onError: (err) => toast.error(err instanceof Error ? err.message : t('memory.saveFailed')),
});
const deleteMutation = createMutation({
mutationFn: (id: number) => agentApi.deleteMemory(id),
onSuccess: () => client.invalidateQueries({ queryKey: ['agent-memories'] }),
onError: (err) => toast.error(err instanceof Error ? err.message : t('memory.deleteFailed')),
});
const canAdd = $derived(
newContent.trim().length > 0 && (newScope === 'global' || newProjectId != null),
);
const globalMemories = $derived(
($memoriesQuery.data ?? []).filter((m) => m.scope === 'global'),
);
const projectMemories = $derived(
($memoriesQuery.data ?? []).filter((m) => m.scope === 'project'),
);
const KIND_KEYS: Record<string, string> = {
preference: 'memory.kindPreference',
convention: 'memory.kindConvention',
correction: 'memory.kindCorrection',
};
function kindLabel(kind: string): string {
return KIND_KEYS[kind] ? t(KIND_KEYS[kind]) : kind;
}
</script>
<section class="a-panel">
<h2 class="a-panel-title">{t('memory.title')}</h2>
<p class="a-panel-lead lead">{t('memory.lead')}</p>
<div class="add-row">
<input
class="a-input add-input"
placeholder={t('memory.placeholder')}
maxlength={500}
bind:value={newContent}
onkeydown={(e) => {
if (e.key === 'Enter' && canAdd) $addMutation.mutate();
}}
/>
<select class="a-select scope-select" bind:value={newScope}>
<option value="global">{t('memory.scopeGlobal')}</option>
<option value="project">{t('memory.scopeProject')}</option>
</select>
{#if newScope === 'project'}
<select class="a-select scope-select" bind:value={newProjectId}>
<option value={null}>{t('memory.chooseProject')}</option>
{#each ($projectsQuery.data ?? []) as p (p.id)}
<option value={p.id}>{p.title}</option>
{/each}
</select>
{/if}
<select class="a-select scope-select" bind:value={newKind}>
<option value="preference">{t('memory.kindPreference')}</option>
<option value="convention">{t('memory.kindConvention')}</option>
<option value="correction">{t('memory.kindCorrection')}</option>
</select>
<Button
variant="secondary"
size="sm"
disabled={!canAdd || $addMutation.isPending}
onclick={() => $addMutation.mutate()}
>
{t('common.add')}
</Button>
</div>
{#if $memoriesQuery.isLoading}
<p class="muted">{t('memory.loading')}</p>
{:else if globalMemories.length === 0 && projectMemories.length === 0}
<p class="muted">{t('memory.empty')}</p>
{:else}
{#if globalMemories.length > 0}
<h3 class="group-head">{t('memory.groupGlobal')}</h3>
<div class="mem-list">
{#each globalMemories as m (m.id)}
<div class="mem-row">
<span class="mem-kind">{kindLabel(m.kind)}</span>
<span class="mem-content">{m.content}</span>
<span class="mem-meta">
{m.source === 'user' ? t('memory.sourceYou') : t('memory.sourceAgent')} · {t('memory.usedCount', { count: m.use_count })}
</span>
<button
type="button"
class="mem-del"
title={t('memory.forget')}
onclick={() => $deleteMutation.mutate(m.id)}
>
<Icon name="trash" size={13} />
</button>
</div>
{/each}
</div>
{/if}
{#if projectMemories.length > 0}
<h3 class="group-head">{t('memory.groupProject')}</h3>
<div class="mem-list">
{#each projectMemories as m (m.id)}
<div class="mem-row">
<span class="mem-kind">{kindLabel(m.kind)}</span>
<span class="mem-project">{m.project_title ?? `#${m.project_id}`}</span>
<span class="mem-content">{m.content}</span>
<span class="mem-meta">
{m.source === 'user' ? t('memory.sourceYou') : t('memory.sourceAgent')} · {t('memory.usedCount', { count: m.use_count })}
</span>
<button
type="button"
class="mem-del"
title={t('memory.forget')}
onclick={() => $deleteMutation.mutate(m.id)}
>
<Icon name="trash" size={13} />
</button>
</div>
{/each}
</div>
{/if}
{/if}
</section>
<style>
.lead {
margin-bottom: 16px;
}
.add-row {
display: flex;
gap: 8px;
align-items: center;
margin-bottom: var(--space-md);
flex-wrap: wrap;
}
.add-input {
flex: 1;
min-width: 220px;
}
.scope-select {
width: auto;
max-width: 160px;
}
.group-head {
margin: var(--space-md) 0 6px;
font-size: 11px;
font-weight: 600;
color: var(--text-3);
}
.mem-list {
display: flex;
flex-direction: column;
gap: 6px;
}
.mem-row {
display: flex;
align-items: center;
gap: 10px;
padding: 8px 12px;
border: 1px solid var(--border);
border-radius: 8px;
background: var(--surface-2);
font-size: 12.5px;
}
.mem-kind {
flex-shrink: 0;
font-size: 10.5px;
color: var(--info);
background: var(--info-dim);
border-radius: 999px;
padding: 1px 8px;
}
.mem-project {
flex-shrink: 0;
font-weight: 600;
color: var(--text-secondary);
max-width: 160px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.mem-content {
flex: 1;
min-width: 0;
color: var(--text-primary);
}
.mem-meta {
flex-shrink: 0;
font-size: 11px;
color: var(--text-muted);
}
.mem-del {
flex-shrink: 0;
border: none;
background: transparent;
color: var(--text-muted);
cursor: pointer;
padding: 4px;
border-radius: var(--radius-sm);
}
.mem-del:hover {
color: var(--error);
background: var(--error-dim);
}
.muted {
color: var(--text-muted);
font-size: 13px;
}
</style>