fix(core): fix three JIT context bugs in read_file, read_many_files, and memoryDiscovery (#22679)

This commit is contained in:
Sandy Tao
2026-03-16 13:10:50 -07:00
committed by GitHub
parent dfe22aae21
commit b91f75cd6d
7 changed files with 221 additions and 12 deletions

View File

@@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import type { Part, PartListUnion, PartUnion } from '@google/genai';
import type { Config } from '../config/config.js';
/**
@@ -63,3 +64,24 @@ export function appendJitContext(
}
return `${llmContent}${JIT_CONTEXT_PREFIX}${jitContext}${JIT_CONTEXT_SUFFIX}`;
}
/**
* Appends JIT context to non-string tool content (e.g., images, PDFs) by
* wrapping both the original content and the JIT context into a Part array.
*
* @param llmContent - The original non-string tool output content.
* @param jitContext - The discovered JIT context string.
* @returns A Part array containing the original content and JIT context.
*/
export function appendJitContextToParts(
llmContent: PartListUnion,
jitContext: string,
): PartUnion[] {
const jitPart: Part = {
text: `${JIT_CONTEXT_PREFIX}${jitContext}${JIT_CONTEXT_SUFFIX}`,
};
const existingParts: PartUnion[] = Array.isArray(llmContent)
? llmContent
: [llmContent];
return [...existingParts, jitPart];
}