fix(patch): cherry-pick 07056c8 to release/v0.28.0-preview.6-pr-18656 to patch version v0.28.0-preview.6 and create version 0.28.0-preview.7 (#18672)

Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
gemini-cli-robot
2026-02-09 16:14:18 -05:00
committed by GitHub
parent b27fd49c16
commit 39eea4b11a
2 changed files with 17 additions and 3 deletions

View File

@@ -331,6 +331,16 @@ describe('converter', () => {
const genaiRes = fromGenerateContentResponse(codeAssistRes);
expect(genaiRes.responseId).toBeUndefined();
});
it('should handle missing response property gracefully', () => {
const invalidRes = {
traceId: 'some-trace-id',
} as unknown as CaGenerateContentResponse;
const genaiRes = fromGenerateContentResponse(invalidRes);
expect(genaiRes.responseId).toEqual('some-trace-id');
expect(genaiRes.candidates).toEqual([]);
});
});
describe('toContents', () => {

View File

@@ -133,14 +133,18 @@ export function toGenerateContentRequest(
export function fromGenerateContentResponse(
res: CaGenerateContentResponse,
): GenerateContentResponse {
const inres = res.response;
const out = new GenerateContentResponse();
out.candidates = inres.candidates;
out.responseId = res.traceId;
const inres = res.response;
if (!inres) {
out.candidates = [];
return out;
}
out.candidates = inres.candidates ?? [];
out.automaticFunctionCallingHistory = inres.automaticFunctionCallingHistory;
out.promptFeedback = inres.promptFeedback;
out.usageMetadata = inres.usageMetadata;
out.modelVersion = inres.modelVersion;
out.responseId = res.traceId;
return out;
}