fix(webui): use consistent chat names for scheduled tasks

This commit is contained in:
Xubin Ren committed 2026-10-07 01:12:23 +08:00
1 parent 61ab136e58
commit 9a5542bc15
17 files changed
+138 -27

No files matched your search

@@ -41,7 +41,7 @@ import { RuntimeConfigSettings } from "@/components/settings/system/RuntimeConfi
import { RuntimeSettings } from "@/components/settings/system/RuntimeSettings";
import type { SettingsController } from "@/components/settings/useSettingsController";
import type { SendAttachment, SendOptions } from "@/hooks/useNanobotStream";
import type { SessionAutomationJob, SkillSummary } from "@/lib/types";
import type { ChatSummary, SessionAutomationJob, SkillSummary } from "@/lib/types";
import { cn } from "@/lib/utils";
interface SettingsPageProps {
@@ -60,6 +60,7 @@ interface SettingsPageProps {
modelPreset?: string | null,
) => boolean | void | Promise<boolean | void>;
titleOverrides?: Record<string, string>;
sessions?: ChatSummary[];
onLogout?: () => void;
isRestarting: boolean;
hostChromeInset: boolean;
@@ -76,6 +77,7 @@ export function SettingsPage({
skills,
onStartAutomationChat,
titleOverrides,
sessions,
onLogout,
isRestarting,
hostChromeInset,
@@ -584,6 +586,7 @@ export function SettingsPage({
token={token}
payload={automations}
titleOverrides={titleOverrides}
sessions={sessions}
settingsSnapshot={controller.settings}
onStartChat={onStartAutomationChat}
loading={automationsLoading}
@@ -2,7 +2,7 @@ import { SettingsPage } from "@/components/settings/SettingsPage";
import type { SettingsExitGuard, SettingsSectionKey } from "@/components/settings/contracts";
import { useSettingsController } from "@/components/settings/useSettingsController";
import type { SendAttachment, SendOptions } from "@/hooks/useNanobotStream";
import type { SettingsPayload, SkillSummary } from "@/lib/types";
import type { ChatSummary, SettingsPayload, SkillSummary } from "@/lib/types";
export type { SettingsSectionKey } from "@/components/settings/contracts";
@@ -25,6 +25,7 @@ interface SettingsViewProps {
modelPreset?: string | null,
) => boolean | void | Promise<boolean | void>;
titleOverrides?: Record<string, string>;
sessions?: ChatSummary[];
onSectionChange?: (section: SettingsSectionKey) => void;
onLogout?: () => void;
onRestart?: () => void;
@@ -47,6 +48,7 @@ export function SettingsView({
skills = [],
onStartAutomationChat,
titleOverrides,
sessions,
onSectionChange,
onLogout,
onRestart,
@@ -76,6 +78,7 @@ export function SettingsView({
skills={skills}
onStartAutomationChat={onStartAutomationChat}
titleOverrides={titleOverrides}
sessions={sessions}
onLogout={onLogout}
isRestarting={isRestarting}
hostChromeInset={hostChromeInset}
@@ -12,8 +12,9 @@ import { readLocalPreferences } from "@/lib/local-preferences";
import type { AutomationChat, AutomationChatsPayload, AutomationChatUpdate, NanobotFeatureInfo, SessionAutomationJob } from "@/lib/types";
export type ChangeAutomationChat = (job: SessionAutomationJob, values: AutomationChatUpdate) => Promise<void>;
export type AutomationChatNames = ReadonlyMap<string, { title: string; handle: string }>;
function ChatIdentity({ chat }: { chat: AutomationChat }) {
function ChatIdentity({ chat, title }: { chat: AutomationChat; title: string }) {
const { t } = useTranslation();
const owner = channelUiOwner(chat.channel);
const presentation = channelUiPresentation(chat.channel);
@@ -29,13 +30,14 @@ function ChatIdentity({ chat }: { chat: AutomationChat }) {
: <span className="absolute left-0 top-0 origin-top-left scale-75"><ChannelLogo feature={feature} showBrandLogos={readLocalPreferences().brandLogos} /></span>}
</span>
<span className="flex min-w-0 flex-wrap items-baseline gap-x-2 text-[13px] leading-5">
<span className="min-w-0 break-words">{chat.title}</span><span className="text-[12px] text-muted-foreground">{platform}</span>
<span className="min-w-0 break-words">{title}</span><span className="text-[12px] text-muted-foreground">{platform}</span>
</span>
</span>;
}
export function AutomationChatBinding({ job, token, onSave, children }: {
export function AutomationChatBinding({ job, token, chatNames, onSave, children }: {
job: SessionAutomationJob; token: string; onSave: ChangeAutomationChat;
chatNames?: AutomationChatNames;
children: (picker: ReactNode) => ReactNode;
}) {
const { t } = useTranslation();
@@ -72,6 +74,18 @@ export function AutomationChatBinding({ job, token, onSave, children }: {
const back = () => { returning.current = true; setDraft(null); };
const current = data?.current;
const fallback: AutomationChat = { id: "current", title: job.origin?.title || tx("current"), channel: job.origin?.channel || "websocket" };
const baseTitle = (chat: AutomationChat) => chatNames?.get(chat.id)?.title ?? chat.title;
const counts = new Map<string, number>();
for (const chat of data?.chats ?? []) {
const title = baseTitle(chat);
counts.set(title, (counts.get(title) ?? 0) + 1);
}
const chatTitle = (chat: AutomationChat) => {
const title = baseTitle(chat);
const name = chatNames?.get(chat.id);
return name && (counts.get(title) ?? 0) > 1 ? `${title} · @${name.handle}` : title;
};
const identity = (chat: AutomationChat) => <ChatIdentity chat={chat} title={chatTitle(chat)} />;
const targetUnavailable = Boolean(draft && data && !data.chats.some(chat => chat.id === draft.target.id && !chat.unavailable));
const picker = (review: boolean) => <Select value={review ? draft?.target.id : current?.id ?? "current"}
disabled={pickerDisabled} onValueChange={id => {
@@ -85,13 +99,13 @@ export function AutomationChatBinding({ job, token, onSave, children }: {
}}>
<SelectTrigger ref={review ? undefined : trigger} aria-label={tx(review ? "new" : "label")}
className="h-auto min-h-11 w-full py-2 [&>span:first-child]:min-w-0 [&>span:first-child]:flex-1 [&>span:first-child]:text-start">
<SelectValue><ChatIdentity chat={(review ? draft?.target : current) ?? fallback} /></SelectValue>
<SelectValue>{identity((review ? draft?.target : current) ?? fallback)}</SelectValue>
</SelectTrigger>
<SelectContent>
{!current ? <SelectItem value="current" disabled><ChatIdentity chat={fallback} /></SelectItem> : null}
{data?.chats.map(chat => <SelectItem key={chat.id} value={chat.id} textValue={`${chat.title} ${chat.channel}`}
{!current ? <SelectItem value="current" disabled>{identity(fallback)}</SelectItem> : null}
{data?.chats.map(chat => <SelectItem key={chat.id} value={chat.id} textValue={`${chatTitle(chat)} ${chat.channel}`}
disabled={chat.unavailable || (review && chat.id === current?.id)}
className="h-auto min-h-11 py-2 [&>span:first-child]:min-w-0 [&>span:first-child]:max-w-[calc(100vw-5rem)] [&>span:first-child]:w-full"><ChatIdentity chat={chat} /></SelectItem>)}
className="h-auto min-h-11 py-2 [&>span:first-child]:min-w-0 [&>span:first-child]:max-w-[calc(100vw-5rem)] [&>span:first-child]:w-full">{identity(chat)}</SelectItem>)}
</SelectContent>
</Select>;
const save = async () => {
@@ -113,14 +127,14 @@ export function AutomationChatBinding({ job, token, onSave, children }: {
<p className="text-[13px] font-medium">{tx("label")}</p>
{picker(false)}
<p role={saved ? "status" : undefined} className="text-[12px] leading-5 text-muted-foreground">
{job.state.pending ? tx("busy") : saved ? tx("saved", { chat: saved.target.title }) : tx("hint")}
{job.state.pending ? tx("busy") : saved ? tx("saved", { chat: chatTitle(saved.target) }) : tx("hint")}
</p>
{saved && current?.id === saved.target.id && data?.chats.some(chat => chat.id === saved.previous.id && !chat.unavailable) ? (
<Button variant="link" size="sm" className="h-11 justify-start whitespace-normal p-0 text-start text-[12px] sm:h-auto" disabled={pickerDisabled}
onClick={() => {
setError("");
setDraft({ target: saved.previous, previous: current, revision: data.revision, message: job.payload.message });
}}>{tx("changeBack", { chat: saved.previous.title })}</Button>
}}>{tx("changeBack", { chat: chatTitle(saved.previous) })}</Button>
) : null}
{loadError ? <Button variant="link" size="sm" onClick={() => setReload(value => value + 1)}>{tx("retry")}</Button> : null}
{data && data.chats.length <= (current ? 1 : 0) ? <p className="text-[12px] leading-5 text-muted-foreground">{tx("available")}</p> : null}
@@ -133,7 +147,7 @@ export function AutomationChatBinding({ job, token, onSave, children }: {
<div className="space-y-2">
<div role="group" aria-label={tx("previous")} className="flex min-w-0 items-start gap-3 pb-1 text-muted-foreground">
<span className="shrink-0 text-[12px] leading-6">{tx("previous")}</span>
<ChatIdentity chat={draft.previous} />
{identity(draft.previous)}
</div>
<p className="text-[13px] font-medium">{tx("new")}</p>
{picker(true)}
@@ -15,7 +15,7 @@ import { useTranslation } from "react-i18next";
import { channelTranslator } from "@/channel-plugins/i18n";
import { channelUiOwner, channelUiPresentation } from "@/channel-plugins/registry";
import { AutomationCalendar } from "@/components/settings/system/AutomationCalendar";
import { AutomationChatBinding, type ChangeAutomationChat } from "@/components/settings/system/AutomationChatBinding";
import { AutomationChatBinding, type AutomationChatNames, type ChangeAutomationChat } from "@/components/settings/system/AutomationChatBinding";
import { AutomationRunAtPicker, parseAutomationRunAt } from "@/components/settings/system/AutomationRunAtPicker";
import {
modelPresetOptionsFromSettings,
@@ -46,6 +46,7 @@ import type { SendAttachment, SendOptions } from "@/hooks/useNanobotStream";
import type {
AutomationsPayload,
AutomationUpdatePayload,
ChatSummary,
SessionAutomationJob,
SettingsPayload,
} from "@/lib/types";
@@ -55,11 +56,13 @@ export type AutomationFilter = "all" | "active" | "paused" | "failed" | "system"
export type AutomationAction = "enable" | "disable" | "delete" | "run";
const EMPTY_TITLE_OVERRIDES: Record<string, string> = {};
const EMPTY_SESSIONS: ChatSummary[] = [];
export function AutomationsSettings({
token = "",
payload, loading, filter, actionKey, error,
titleOverrides = EMPTY_TITLE_OVERRIDES,
sessions = EMPTY_SESSIONS,
settingsSnapshot = null,
onFilterChange, onAction,
onRequestEdit, onRequestDelete, onStartChat, onManageModels,
@@ -69,6 +72,7 @@ export function AutomationsSettings({
token?: string;
payload: AutomationsPayload | null;
titleOverrides?: Record<string, string>;
sessions?: ChatSummary[];
settingsSnapshot?: SettingsPayload | null;
loading: boolean;
filter: AutomationFilter;
@@ -92,6 +96,13 @@ export function AutomationsSettings({
const { t, i18n } = useTranslation();
const tx = (key: string, fallback: string, values?: Record<string, unknown>) =>
t(key, { defaultValue: fallback, ...(values ?? {}) });
// Join display names by the server-owned handle ID, never by a mutable title.
const chatNames: AutomationChatNames = useMemo(() => new Map(sessions.flatMap(session => (
session.handle ? [[session.handle.id, {
title: displayTitle(session, titleOverrides, t("chat.newChat")),
handle: session.handle.name,
}] as const] : []
))), [sessions, titleOverrides, t]);
const jobs = useMemo(() => (payload?.jobs ?? []).map((job) => {
const origin = job.origin;
if (origin?.channel !== "websocket") return job;
@@ -367,6 +378,7 @@ export function AutomationsSettings({
<AutomationDetailDialog
token={token}
chatNames={chatNames}
onChangeChat={onChangeChat}
job={selectedJob}
open={detailOpen}
@@ -395,6 +407,7 @@ export function AutomationsSettings({
export function AutomationDetailDialog({
token = "",
chatNames,
onChangeChat,
job,
open,
@@ -408,6 +421,7 @@ export function AutomationDetailDialog({
onCloseAutoFocus,
}: {
token?: string;
chatNames?: AutomationChatNames;
onChangeChat?: ChangeAutomationChat;
job: SessionAutomationJob | null;
open: boolean;
@@ -438,7 +452,7 @@ export function AutomationDetailDialog({
onCloseAutoFocus={onCloseAutoFocus}
>
{job.chat_binding_revision && onChangeChat ? (
<AutomationChatBinding key={job.id} job={job} token={token} onSave={onChangeChat}>{panel}</AutomationChatBinding>
<AutomationChatBinding key={job.id} job={job} token={token} chatNames={chatNames} onSave={onChangeChat}>{panel}</AutomationChatBinding>
) : panel()}
</DialogContent>
) : null}