mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-16 00:51:25 -07:00
Harded code assist converter. (#18656)
This commit is contained in:
@@ -331,6 +331,16 @@ describe('converter', () => {
|
|||||||
const genaiRes = fromGenerateContentResponse(codeAssistRes);
|
const genaiRes = fromGenerateContentResponse(codeAssistRes);
|
||||||
expect(genaiRes.responseId).toBeUndefined();
|
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', () => {
|
describe('toContents', () => {
|
||||||
|
|||||||
@@ -133,14 +133,18 @@ export function toGenerateContentRequest(
|
|||||||
export function fromGenerateContentResponse(
|
export function fromGenerateContentResponse(
|
||||||
res: CaGenerateContentResponse,
|
res: CaGenerateContentResponse,
|
||||||
): GenerateContentResponse {
|
): GenerateContentResponse {
|
||||||
const inres = res.response;
|
|
||||||
const out = new GenerateContentResponse();
|
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.automaticFunctionCallingHistory = inres.automaticFunctionCallingHistory;
|
||||||
out.promptFeedback = inres.promptFeedback;
|
out.promptFeedback = inres.promptFeedback;
|
||||||
out.usageMetadata = inres.usageMetadata;
|
out.usageMetadata = inres.usageMetadata;
|
||||||
out.modelVersion = inres.modelVersion;
|
out.modelVersion = inres.modelVersion;
|
||||||
out.responseId = res.traceId;
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user