mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
Harded code assist converter. (#18656)
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user