Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(titles): ask for the title in the conversation's language (#7646)

Ooi Pin Jun22bd7149b3e1
diff --git a/server/testing/fake-claude-cli.ts b/server/testing/fake-claude-cli.ts
index 442db5cd70..bc8008f16f 100755
--- a/server/testing/fake-claude-cli.ts
+++ b/server/testing/fake-claude-cli.ts
@@ -550,7 +550,7 @@ if (["text", "json"].includes(argAfter("--output-format") ?? "")) {
// Every new thread asks its engine for a title (server/thread-title-generate.ts), so that call stays out of the captures
// below unless a test answers it: by FAKE_CLAUDE_TEXT_FILE or a FAKE_CLAUDE_TEXT_ROUTES marker. Otherwise it fails at
// once and the thread keeps its first-message title. Answered, it still never overwrites the turn dump.
- const titleCall = prompt.includes("Reply with only a short title: 3 to 6 words");
+ const titleCall = prompt.includes("Reply with only a short title");
const routes = process.env.FAKE_CLAUDE_TEXT_ROUTES;
const routed = () => {
try { return Object.keys(JSON.parse(readFileSync(routes!, "utf8"))).some((marker) => prompt.includes(marker)); } catch { return false; }
diff --git a/server/testing/title-call.ts b/server/testing/title-call.ts
index 18a34b3f33..6632716d97 100644
--- a/server/testing/title-call.ts
+++ b/server/testing/title-call.ts
@@ -2,5 +2,5 @@
// scripts model calls answers that one-shot with a failure first, on the request body it received, so the thread keeps
// its first-message title and the test sees only the calls it makes.
export function isTitleCall(body: unknown): boolean {
- return JSON.stringify(body ?? null).includes("Reply with only a short title: 3 to 6 words");
+ return JSON.stringify(body ?? null).includes("Reply with only a short title");
}
diff --git a/server/thread-title.test.ts b/server/thread-title.test.ts
index 7753693fb8..4d9e5e63e5 100644
--- a/server/thread-title.test.ts
+++ b/server/thread-title.test.ts
@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from "vitest";
import { createJobSlots } from "./job-slots.ts";
import type { Message } from "./store.ts";
-import { callTitleExcerpt, threadTitlePrompt, titleConversationExcerpt, titleFromMessage, TITLE_INPUT_MAX_CHARS, UNTITLED_TASK } from "./thread-title.ts";
+import { callTitleExcerpt, threadTitlePrompt, titleConversationExcerpt, titleFromMessage, TITLE_INPUT_MAX_CHARS, UNTITLED_TASK, type ThreadTitleSource } from "./thread-title.ts";
import { AUTO_RETRY_LEAD } from "./incidents.ts";
import { AUTHORITY, botWho, fromNote, fromNoteWith, routineWho } from "./provenance-label.ts";
import { generateThreadTitle, THREAD_TITLE_TIMEOUT_MS } from "./thread-title-generate.ts";
@@ -112,6 +112,22 @@ describe("threadTitlePrompt", () => {
expect(prompt).toContain("Conversation:\nUser: fix the login");
expect(prompt.length).toBeLessThan(TITLE_INPUT_MAX_CHARS + 300);
});
+
+ it.each<[ThreadTitleSource, string]>([
+ ["first-message", "为什么 OpenMausBot 返回 HTTP 403?"],
+ ["call", "为什么 OpenMausBot 返回 HTTP 403?"],
+ ["conversation", titleConversationExcerpt([
+ message("user", "为什么 OpenMausBot 返回 HTTP 403?"),
+ message("bot", "权限不足时接口返回 403。"),
+ ])],
+ ])("asks for the title in the same language as the user's request, from %s", (source, text) => {
+ const prompt = threadTitlePrompt(text, source);
+ expect(prompt).toContain("为什么 OpenMausBot 返回 HTTP 403?");
+ const instruction = prompt.split("\n")[1]!;
+ expect(instruction).toContain("same language as the user's request");
+ expect(instruction).toContain("at most 48 characters");
+ expect(instruction).not.toContain("3 to 6 words");
+ });
});
describe("a Live call's title", () => {
@@ -119,7 +135,7 @@ describe("a Live call's title", () => {
const prompt = threadTitlePrompt("what is the weather in Pune\nand tomorrow?", "call");
expect(prompt.split("\n").slice(0, 3)).toEqual([
"Name the voice call below by what was asked on it.",
- "Reply with only a short title: 3 to 6 words, plain text, no quotes, no trailing period.",
+ "Reply with only a short title in the same language as the user's request. Use a concise phrase of at most 48 characters, in plain text, with no quotes or trailing period.",
"Requests:",
]);
expect(prompt.endsWith("Requests:\nwhat is the weather in Pune\nand tomorrow?")).toBe(true);
diff --git a/server/thread-title.ts b/server/thread-title.ts
index 1f1ef60127..ba08a3c0bc 100644
--- a/server/thread-title.ts
+++ b/server/thread-title.ts
@@ -46,7 +46,7 @@ export function threadTitlePrompt(text: string, source: ThreadTitleSource = "fir
const { ask, label } = TITLE_PROMPT[source];
return [
ask,
- "Reply with only a short title: 3 to 6 words, plain text, no quotes, no trailing period.",
+ "Reply with only a short title in the same language as the user's request. Use a concise phrase of at most 48 characters, in plain text, with no quotes or trailing period.",
label,
text.trim().slice(0, TITLE_INPUT_MAX_CHARS),
].join("\n");
diff --git a/src/lib/friendly-activity.ts b/src/lib/friendly-activity.ts
index 147fa4e0c7..755e101b0f 100644
--- a/src/lib/friendly-activity.ts
+++ b/src/lib/friendly-activity.ts
@@ -71,7 +71,6 @@ const TOOL_TALK: ReadonlySet<LocaleKey> = new Set(["chat.friendly.code", "chat.f
/** Titles the app gives a conversation itself (task-title.ts localizes the last two). */
const FACTORY_TITLES: ReadonlySet<string> = new Set(["New task", "New thread", "Conversation", "work", SHARED_CHAT_TITLE]);
-/** A generated title is 3 to 6 words; a longer one is a hand-off's brief or a message's opening cut short. */
const TITLE_MAX = 48;
/** The conversation's title as the name of the work, only when it is a title the engine generated. Anything else, or