Harded code assist converter. (#18656)

This commit is contained in:
Jacob Richman
2026-02-09 12:45:55 -08:00
committed by GitHub
parent 08dca3e1d6
commit 07056c8f16
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;
}