fix(chat): recall the current session's prompts by default; tidy the six merged PRs

Input history (#3035) shipped with "All projects" as the default scope and
only recorded prompts sent after the upgrade, so ArrowUp showed other
sessions' prompts and, once switched to "Current session", nothing at all.
Default to the current session and merge the visible transcript's prompts
with the persisted bucket. Existing sessions recall as they did before
#3035, while new prompts keep their attachments and stay recallable after
a revert hides them from the transcript.

Cleanup across #1855, #2297, #3072, #3178, #3035 and #3135: drop the
duplicate poll guards in the file content poller, the zod schema the
VS Code package cannot depend on, a copied file-URL helper and stray
whitespace; move the Enter-to-send strings into the settings namespace;
document OPENCHAMBER_CHATS_DIR, resolve the chats root once on the server
and warm it alongside the other bootstrap calls.
This commit is contained in:
Bohdan Triapitsyn
2026-09-05 20:16:14 +03:00
parent 3df97908fe
commit f46fb718c5
73 changed files with 513 additions and 242 deletions
+25 -25
View File
@@ -8,6 +8,8 @@ import {
type InputHistorySubmission,
} from '@/stores/useInputHistoryStore';
import type { AttachedFile } from '@/stores/types/sessionTypes';
import type { TranscriptPrompt } from '@/sync/user-message-history';
import { toServerFileUrl } from './composer/attachments/filePaths';
type HistoryQueuedMessage = {
content: string;
@@ -22,30 +24,6 @@ type BuildHistorySubmissionsArgs = {
includeComposer: boolean;
};
const FILE_URI_PREFIX = 'file://';
const encodeFilePath = (filepath: string): string => {
let normalized = filepath.replace(/\\/g, '/');
if (/^[A-Za-z]:/.test(normalized)) {
normalized = `/${normalized}`;
}
return normalized
.split('/')
.map((segment, index) => {
if (index === 1 && /^[A-Za-z]:$/.test(segment)) return segment;
return encodeURIComponent(segment);
})
.join('/');
};
const toFileUrl = (filepath: string): string => {
const normalized = filepath.replace(/\\/g, '/').trim();
if (normalized.toLowerCase().startsWith(FILE_URI_PREFIX)) {
return normalized;
}
return `${FILE_URI_PREFIX}${encodeFilePath(normalized)}`;
};
export function buildChatInputHistorySubmissions({
inputMode,
queuedMessages,
@@ -85,7 +63,7 @@ function materializeHistoryAttachment(attachment: InputHistoryAttachment): Attac
return {
id: `history-${attachment.key}`,
file: new File([], attachment.filename, { type: attachment.mimeType }),
dataUrl: toFileUrl(attachment.reference),
dataUrl: toServerFileUrl(attachment.reference),
mimeType: attachment.mimeType,
filename: attachment.filename,
size: attachment.size,
@@ -109,6 +87,28 @@ export function mapInputHistoryEntriesToValues(
}));
}
/**
* Session-scoped recall: the visible transcript's prompts (so sessions older
* than the persisted store still recall) merged with the persisted bucket
* (attachments, and prompts a revert hid from the transcript), oldest first.
* A prompt present in both collapses to the persisted entry.
*/
export function mergeSessionInputHistory(
transcript: readonly TranscriptPrompt[],
entries: readonly InputHistoryEntry[],
): Array<MessageHistoryValue<AttachedFile>> {
const persistedTexts = new Set(entries.map((entry) => entry.text));
const timed: Array<{ at: number; value: MessageHistoryValue<AttachedFile> }> = [
...transcript
.filter((prompt) => !persistedTexts.has(prompt.text))
.map((prompt) => ({ at: prompt.createdAt, value: { text: prompt.text, attachments: [] } })),
...mapInputHistoryEntriesToValues(entries)
// submittedAt is milliseconds × 1000 plus a sequence number.
.map((value, index) => ({ at: Math.floor(entries[index]!.submittedAt / 1000), value })),
];
return timed.sort((left, right) => left.at - right.at).map((item) => item.value);
}
export function buildInputHistoryNavigatorIdentity(
scope: InputHistoryScope,
identity: InputHistoryIdentity | null,