Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Keep first-message thread titles valid when clipped
focuspointsc0b82f272d6d
diff --git a/server/store.ts b/server/store.tsindex ada2b32ea8..6f92dec00d 100644--- a/server/store.ts+++ b/server/store.ts@@ -41,6 +41,7 @@ import { sameModelSelection } from "../shared/thread-model.ts";import { initialGreetingMessage } from "./initial-greeting.ts"; import { createDefaultBot, defaultBotRefusal, type DefaultBotIntro } from "./default-bot.ts";import { appsFromCreator } from "./inherited-apps.ts";import { ThreadCache, type ThreadState } from "./thread-cache.ts";+import { toolResultPrefix } from "./tool-results.ts";export type {BotActivity, GroupDefaultResponder, OptionCardData,SecretRequestCardData, Surface, TaskClosedBy, TaskOpenedBy, TaskUsage,@@ -147,7 +148,7 @@ export function threadTitleFrom(title?: string): string {export function titleFromMessage(text: string): string {const line = text.trim().split("\n")[0]!.trim();- return line.length > 48 ? `${line.slice(0, 47)}…` : line || UNTITLED_TASK;+ return line.length > 48 ? `${toolResultPrefix(line, 47)}…` : line || UNTITLED_TASK;}export function titleFromLlm(raw: string): string | null {diff --git a/server/tasks.test.ts b/server/tasks.test.tsindex 7904d79838..72e4930198 100644--- a/server/tasks.test.ts+++ b/server/tasks.test.ts@@ -88,6 +88,24 @@ describe("tasks", () => {expect(titleFromMessage("x".repeat(80))).toHaveLength(48);});+ it("clips first-message titles at complete code points within 48 UTF-16 units", async () => {+ const { store, titleFromMessage } = await freshStore();+ const bot = store.createBot();+ for (const [text, expected] of [+ ["中".repeat(44) + "𠮷收尾", "中".repeat(44) + "𠮷收尾"],+ ["中".repeat(45) + "𠮷收尾", "中".repeat(45) + "𠮷…"],+ ["中".repeat(46) + "𠮷收尾", "中".repeat(46) + "…"],+ ["中".repeat(47) + "𠮷收尾", "中".repeat(47) + "…"],+ ["x".repeat(46) + " trailing words", "x".repeat(46) + " …"],+ ]) {+ const title = titleFromMessage(text);+ expect(title).toBe(expected);+ expect(title.length).toBeLessThanOrEqual(48);+ const task = store.createTask(bot.id)!;+ expect(store.titleTaskFromFirstMessage(bot.id, text, task.threadId)?.title).toBe(expected);+ }+ });+it("returns the task it named, so a caller knows which title it may replace", async () => {const { store } = await freshStore();const bot = store.createBot();