Files
next-tjwater-agent/src/sessions/history-search.ts
T
jiang 7d47a2df86
Generic Container CI/CD / test-build-publish (push) Failing after 8m25s
Agent CI/CD / build-test-publish-and-deploy (push) Failing after 8m25s
feat: add scoped history and artifacts
2026-10-22 18:40:20 +08:00

22 lines
1.1 KiB
TypeScript

/** Search only visible user/assistant text, never tool arguments or hidden reasoning. */
export function matchHistoryText(messages: unknown[], query: string): string | undefined {
const needle = query.trim().toLocaleLowerCase();
if (!needle) return;
for (const value of messages) {
if (!value || typeof value !== "object") continue;
const message = value as Record<string, unknown>;
if (message.role !== "user" && message.role !== "assistant") continue;
const parts = Array.isArray(message.parts) ? message.parts : [message];
for (const value of parts) {
if (!value || typeof value !== "object") continue;
const part = value as Record<string, unknown>;
if (part.type !== "text" || typeof part.text !== "string") continue;
const index = part.text.toLocaleLowerCase().indexOf(needle);
if (index < 0) continue;
const start = Math.max(0, index - 36);
const end = Math.min(part.text.length, index + needle.length + 80);
return `${start ? "…" : ""}${part.text.slice(start, end).replace(/\s+/g, " ")}${end < part.text.length ? "…" : ""}`;
}
}
}