39 lines
2.4 KiB
TypeScript
39 lines
2.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import type { Message } from "@langchain/langgraph-sdk";
|
|
|
|
import { buildQuestionItems } from "../../components/workspace/question-navigator-data";
|
|
import { groupMessages, isHiddenFromUIMessage } from "./utils";
|
|
|
|
const user: Message = { type: "human", id: "question", content: "画一张态势图" };
|
|
const answer: Message = { type: "ai", id: "answer", content: "地图已生成" };
|
|
|
|
test("new and historical Todo reminders never create chat groups or navigator questions", () => {
|
|
const reminders: Message[] = [
|
|
{ type: "human", id: "legacy-recall", name: "todo_reminder", content: "Internal recall" },
|
|
{ type: "human", id: "legacy-completion", name: "todo_completion_reminder", content: "Internal completion" },
|
|
{ type: "human", id: "new-completion", name: "todo_completion_reminder", content: "Internal completion", additional_kwargs: { hide_from_ui: true, lc_source: "todo" } },
|
|
];
|
|
for (const reminder of reminders) assert.equal(isHiddenFromUIMessage(reminder), true);
|
|
const messages = [user, answer, ...reminders, { ...answer, id: "followup" }];
|
|
assert.deepEqual(groupMessages(messages, (group) => group.type), ["human", "assistant", "assistant"]);
|
|
assert.deepEqual(buildQuestionItems(messages), [{ anchorId: "message-question", summary: "画一张态势图" }]);
|
|
});
|
|
|
|
test("users quoting reminder tags or similar names remain visible and navigable", () => {
|
|
const quoted: Message = { type: "human", id: "quote", content: "解释 <system_reminder>todo_reminder</system_reminder> 的意思" };
|
|
const similar: Message = { type: "human", id: "similar", name: "todo_completion_reminder_example", content: "这是用户的问题" };
|
|
for (const message of [quoted, similar]) assert.equal(isHiddenFromUIMessage(message), false);
|
|
assert.deepEqual(groupMessages([quoted, similar], (group) => group.type), ["human", "human"]);
|
|
assert.deepEqual(buildQuestionItems([quoted, similar]).map((question) => question.anchorId), ["message-quote", "message-similar"]);
|
|
assert.match(buildQuestionItems([quoted])[0]!.summary, /<system_reminder>/);
|
|
});
|
|
|
|
test("navigator preserves raw fallback indexes when hidden context precedes a real question", () => {
|
|
assert.deepEqual(buildQuestionItems([
|
|
{ type: "human", content: "Model context", additional_kwargs: { hide_from_ui: true } },
|
|
{ type: "human", content: "# 第二个问题" },
|
|
]), [{ anchorId: "message-1", summary: "第二个问题" }]);
|
|
});
|