feat: make context compaction visible in channels (#5656)
* feat: surface context compaction lifecycle * fix: complete and simplify context compaction notifications
This commit is contained in:
1 parent
455533169d
commit
5229989f28
52 files changed
+1849
-140
No files matched your search
@@ -2,13 +2,15 @@ import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { runInNewContext } from "node:vm";
|
||||
|
||||
import { act, render, screen, waitFor } from "@testing-library/react";
|
||||
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { LanguageSwitcher } from "@/components/LanguageSwitcher";
|
||||
import { MessageBubble } from "@/components/MessageBubble";
|
||||
import { ContextCompactionNotice } from "@/components/thread/ContextCompactionNotice";
|
||||
import { ThreadComposer } from "@/components/thread/ThreadComposer";
|
||||
import { resources } from "@/i18n";
|
||||
import { resources, setAppLanguage } from "@/i18n";
|
||||
import {
|
||||
LOCALE_STORAGE_KEY,
|
||||
resolveInitialLocale,
|
||||
@@ -20,6 +22,7 @@ const IMAGE_QUICK_ACTION_KEYS = ["icon", "sticker", "poster", "product", "portra
|
||||
const HERO_GREETING_KEYS = ["workOn", "start", "build", "tackle"];
|
||||
const SLASH_COMMAND_KEYS = [
|
||||
"new",
|
||||
"compact",
|
||||
"stop",
|
||||
"restart",
|
||||
"status",
|
||||
@@ -418,6 +421,30 @@ describe("webui i18n", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.each(supportedLocales)("localizes compaction states in $code", async ({ code }) => {
|
||||
await setAppLanguage(code);
|
||||
const copy = resources[code].common.thread.compaction;
|
||||
const { container, rerender } = render(
|
||||
<ContextCompactionNotice compaction={{ id: "compact-1", phase: "started", announce: true }} />,
|
||||
);
|
||||
for (const phase of ["started", "succeeded", "failed", "cancelled"] as const) {
|
||||
rerender(<ContextCompactionNotice compaction={{
|
||||
id: "compact-1", phase, announce: true,
|
||||
}} />);
|
||||
const notice = container.querySelector("[data-context-compaction]");
|
||||
expect(copy[phase]).toBeTruthy();
|
||||
expect(notice?.textContent).toBe(copy[phase]);
|
||||
expect(notice).toHaveAttribute("aria-busy", String(phase === "started"));
|
||||
}
|
||||
for (const compactReply of ["empty", "failed"] as const) {
|
||||
rerender(<MessageBubble message={{
|
||||
id: "reply", role: "assistant", content: "original command reply",
|
||||
compactReply, createdAt: 1,
|
||||
}} />);
|
||||
expect(screen.getByText(copy[compactReply])).toBeInTheDocument();
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps preboot copy aligned with every registered locale", () => {
|
||||
for (const { code } of supportedLocales) {
|
||||
const result = runPrebootLocale(code);
|
||||
@@ -499,6 +526,36 @@ describe("webui i18n", () => {
|
||||
expect(screen.getByLabelText("メッセージ入力欄")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("localizes a backend-provided compact slash command", async () => {
|
||||
await act(async () => {
|
||||
const { setAppLanguage } = await import("@/i18n");
|
||||
await setAppLanguage("zh-CN");
|
||||
});
|
||||
|
||||
render(
|
||||
<ThreadComposer
|
||||
onSend={vi.fn()}
|
||||
slashCommands={[{
|
||||
command: "/compact",
|
||||
title: "Compact context",
|
||||
description: "Compact this chat's context and continue the conversation.",
|
||||
icon: "archive",
|
||||
lifecycle: "side_channel",
|
||||
acceptsArgs: false,
|
||||
}]}
|
||||
/>,
|
||||
);
|
||||
|
||||
fireEvent.change(screen.getByLabelText("消息输入框"), {
|
||||
target: { value: "/co" },
|
||||
});
|
||||
|
||||
expect(screen.getByRole("listbox", { name: "斜杠命令" })).toBeInTheDocument();
|
||||
expect(screen.getByText("压缩上下文")).toBeInTheDocument();
|
||||
expect(screen.getByText("压缩当前对话的上下文并继续对话。")).toBeInTheDocument();
|
||||
expect(screen.getByText("/compact")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps empty landing resources localized for every registered locale", () => {
|
||||
for (const resource of Object.values(resources)) {
|
||||
const empty = resource.common.thread.empty;
|
||||
|
||||
Reference in new issue
Block a user