refactor: address review follow-ups for local protocol

This commit is contained in:
Adam Weidman
2026-05-07 14:32:22 -04:00
parent dc3c7994d1
commit aa1d1c6524
4 changed files with 14 additions and 11 deletions
@@ -187,14 +187,16 @@ describe('contentPartsToGeminiParts', () => {
]);
});
it('throws on unknown ContentPart variants', () => {
it('serializes unknown ContentPart variants', () => {
// Force an unknown variant past the type system
const content = [
{ type: 'custom_widget', payload: 123 },
] as unknown as ContentPart[];
expect(() => contentPartsToGeminiParts(content)).toThrow(
'Unhandled ContentPart type: {"type":"custom_widget","payload":123}',
);
const result = contentPartsToGeminiParts(content);
expect(result).toHaveLength(1);
expect(result[0]).toEqual({
text: JSON.stringify({ type: 'custom_widget', payload: 123 }),
});
});
});
-2
View File
@@ -99,8 +99,6 @@ export function contentPartsToGeminiParts(content: ContentPart[]): Part[] {
})(part);
break;
}
break;
}
}
}
return result;
@@ -241,10 +241,11 @@ describe('LegacyAgentSession', () => {
);
});
it('returns null streamId for non-message payloads', async () => {
it('throws for non-message payloads', async () => {
const session = new LegacyAgentSession(deps);
const result = await session.send({ update: { title: 'test' } });
expect(result.streamId).toBeNull();
await expect(session.send({ update: { title: 'test' } })).rejects.toThrow(
'only supports message sends',
);
});
it('throws if send is called while a stream is active', async () => {
@@ -105,10 +105,12 @@ export class LegacyAgentProtocol implements AgentProtocol {
};
}
async send(payload: AgentSend): Promise<{ streamId: string | null }> {
async send(payload: AgentSend): Promise<{ streamId: string }> {
const message = 'message' in payload ? payload.message : undefined;
if (!message) {
return { streamId: null };
throw new Error(
'LegacyAgentSession.send() only supports message sends for the moment.',
);
}
if (this._activeStreamId) {