Skip to content

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

Attribute title generation usage to its original private conversation

vincente3df8bf5cd3d
diff --git a/server/index.ts b/server/index.ts
index acb5a8477e..08d7b789ec 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -7400,7 +7400,7 @@ function threadTitleGate(bot: BotRecord, ownOnly = false): ThreadTitleGate {
catch (error) { return { ok: false, refusal: error instanceof Error ? error.message : String(error) }; }
const opener = store.taskByThread(bot.id, bot.threadId)?.openedBy?.botId;
const confined = cloudGuestDriven(bot.threadId) || botApiThread(bot.threadId) || linkLimits.held(bot.threadId) || (opener && isLinkedId(opener));
- const instance = sideJobs.text("thread-title", bot.id, { instance: own ?? undefined, modelSelection: bot.modelSelection,
+ const instance = sideJobs.text("thread-title", bot.id, { threadId: bot.threadId, instance: own ?? undefined, modelSelection: bot.modelSelection,
...(ownOnly || confined ? { ownOnly: true } : { titleModel: cfg.threadTitles?.model }) });
return instance?.generateText ? { ok: true, instance } : { ok: false, refusal: "No available model can generate a title for this thread." };
}
diff --git a/server/side-jobs.test.ts b/server/side-jobs.test.ts
index bdc8059291..e3db8d2250 100644
--- a/server/side-jobs.test.ts
+++ b/server/side-jobs.test.ts
@@ -228,11 +228,11 @@ describe("who writes a thread title", () => {
const slots = createJobSlots(1);
const run = vi.spyOn(slots, "run");
const { jobs, state, claude, openrouter } = setup({ slots });
- const writer = jobs.text("thread-title", "claude", { titleModel });
+ const writer = jobs.text("thread-title", "claude", { titleModel, threadId: "private-chat" });
const signal = new AbortController().signal;
expect(await writer!.generateText("title prompt", { signal, maxOutputTokens: 512 })).toBe("openrouter wrote this");
expect(openrouter.calls[0]?.options).toMatchObject({ model: titleModel.model, signal, maxOutputTokens: 512, finalTextOnly: true });
- expect(state.booked[0]?.row).toMatchObject({ instanceId: "openrouter", model: titleModel.model, threadId: expect.stringMatching(/^thread-title-/) });
+ expect(state.booked[0]?.row).toMatchObject({ instanceId: "openrouter", model: titleModel.model, threadId: "private-chat" });
expect(claude.calls).toEqual([]);
expect(run).not.toHaveBeenCalled();
state.cappedBots.add("claude");
diff --git a/server/side-jobs.ts b/server/side-jobs.ts
index 25ddde2332..2bc9f486c4 100644
--- a/server/side-jobs.ts
+++ b/server/side-jobs.ts
@@ -90,6 +90,7 @@ export interface SideJobsDeps {
}
interface SideJobContext {
+ threadId?: string;
instance?: SideJobInstance | null;
modelSelection?: SideJobBot["modelSelection"];
titleModel?: Pick<ModelSelection, "instanceId" | "model"> | null;
@@ -175,7 +176,7 @@ export function createSideJobs(deps: SideJobsDeps): SideJobs {
const { checkModel, ...generation } = fixed();
const budgetBot = job === "thread-title" ? bot.id : undefined;
if (!checkModel) deps.assertWithinBudget(budgetBot);
- const threadId = `${job}-${randomUUID()}`;
+ const threadId = job === "thread-title" ? bot.threadId : `${job}-${randomUUID()}`;
return call(prompt, {
...options,
...generation,
@@ -303,8 +304,9 @@ export function createSideJobs(deps: SideJobsDeps): SideJobs {
: found;
function find(job: SideJob, botId: string, at: SideJobContext): SideJobText | null {
- const bot = deps.bot(botId);
- if (!bot) return null;
+ const record = deps.bot(botId);
+ if (!record) return null;
+ const bot = at.threadId ? { ...record, threadId: at.threadId } : record;
const selection = (job === "thread-title" ? at.modelSelection : undefined) ?? bot.modelSelection;
const own = at.instance ?? deps.instance(selection.instanceId);
if (!own || deps.refusal(own)) return null;