some last minute tweaks

This commit is contained in:
Your Name
2026-05-20 17:56:15 +00:00
parent 604b2dcb6d
commit 6a7a483ef7
3 changed files with 50 additions and 34 deletions

View File

@@ -411,12 +411,23 @@ export class ContextManager {
sentinels: this.sidecar.sentinels,
});
const firstPendingId = pendingHistory[0]?.id;
let splitIndex = renderedHistory.length;
if (firstPendingId) {
const foundIndex = hardenedAllHistory.findIndex(
(h) => h.id === firstPendingId,
);
if (foundIndex !== -1) {
splitIndex = foundIndex;
}
}
const apiHistory = hardenedAllHistory
.slice(0, renderedHistory.length)
.slice(0, splitIndex)
.map((h) => h.content);
const pendingApiHistory = hardenedAllHistory
.slice(renderedHistory.length)
.slice(splitIndex)
.map((h) => h.content);
if (header) {

View File

@@ -644,11 +644,7 @@ export class GeminiClient {
if (this.contextManager) {
const rawPendingRequest = createUserContent(request);
const pendingRequest = {
id:
this.getChatRecordingService()?.recordSyntheticMessage(
'user',
rawPendingRequest.parts || [],
) || randomUUID(),
id: randomUUID(),
content: rawPendingRequest,
};
const {
@@ -676,8 +672,9 @@ export class GeminiClient {
this.getChat().setHistory(newHistory, { silent: true });
// Update the request for turn.run so that the final history record
// matches the processed/cleaned content sent to the API.
// Use the original request for display/recording,
// but the processed one for the API and durable history.
displayContent = rawPendingRequest.parts || [];
request = finalPendingContent.parts || [];
} else {
const newHistory = await this.agentHistoryProvider.manageHistory(

View File

@@ -126,34 +126,42 @@ export function convertSessionToClientHistory(
} else if (msg.type === 'gemini') {
const modelParts: Part[] = [];
// 1. Add thoughts from metadata if present
if (msg.thoughts && msg.thoughts.length > 0) {
for (const thought of msg.thoughts) {
const thoughtText = thought.subject
? `**${thought.subject}** ${thought.description}`
: thought.description;
modelParts.push({
text: thoughtText,
thought: true,
} as Part);
const contentParts = msg.content ? ensurePartArray(msg.content) : [];
const hasCallsInContent = contentParts.some((p) => !!p.functionCall);
const hasThoughtsInContent = contentParts.some((p) => p.thought);
if (hasCallsInContent || hasThoughtsInContent) {
// Modern session: content is the source of truth for all parts
modelParts.push(...contentParts);
} else {
// Legacy session: rebuild from components
// 1. Add thoughts from metadata if present
if (msg.thoughts && msg.thoughts.length > 0) {
for (const thought of msg.thoughts) {
const thoughtText = thought.subject
? `**${thought.subject}** ${thought.description}`
: thought.description;
modelParts.push({
text: thoughtText,
thought: true,
} as Part);
}
}
}
// 2. Add original parts from content (preserving multimodal integrity and synthetic thoughts)
if (msg.content) {
modelParts.push(...ensurePartArray(msg.content));
}
// 2. Add content (usually just text in legacy)
modelParts.push(...contentParts);
// 3. Add tool calls if present
if (msg.toolCalls && msg.toolCalls.length > 0) {
for (const toolCall of msg.toolCalls) {
modelParts.push({
functionCall: {
id: toolCall.id,
name: toolCall.name,
args: toolCall.args,
},
});
// 3. Add tool calls from metadata
if (msg.toolCalls && msg.toolCalls.length > 0) {
for (const toolCall of msg.toolCalls) {
modelParts.push({
functionCall: {
id: toolCall.id,
name: toolCall.name,
args: toolCall.args,
},
});
}
}
}