Skip to content

Commit 818074b

Browse files
committed
refactor: address review comments for local protocol
1 parent de3884d commit 818074b

4 files changed

Lines changed: 14 additions & 26 deletions

File tree

packages/core/src/agent/content-utils.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,22 +187,14 @@ describe('contentPartsToGeminiParts', () => {
187187
]);
188188
});
189189

190-
it('serializes unknown ContentPart variants', () => {
190+
it('throws on unknown ContentPart variants', () => {
191191
// Force an unknown variant past the type system
192192
const content = [
193193
{ type: 'custom_widget', payload: 123 },
194194
] as unknown as ContentPart[];
195-
196-
const warnSpy = vi.spyOn(debugLogger, 'warn');
197-
const result = contentPartsToGeminiParts(content);
198-
199-
expect(warnSpy).toHaveBeenCalled();
200-
expect(result).toHaveLength(1);
201-
expect(result[0]).toEqual({
202-
text: JSON.stringify({ type: 'custom_widget', payload: 123 }),
203-
});
204-
205-
warnSpy.mockRestore();
195+
expect(() => contentPartsToGeminiParts(content)).toThrow(
196+
'Unhandled ContentPart type: {"type":"custom_widget","payload":123}',
197+
);
206198
});
207199
});
208200

packages/core/src/agent/content-utils.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,12 @@ export function contentPartsToGeminiParts(content: ContentPart[]): Part[] {
9393
// References are converted to text for the model
9494
result.push({ text: part.text });
9595
break;
96-
default:
97-
debugLogger.warn(
98-
`Unhandled ContentPart type: ${JSON.stringify(part)} fallback to serialization`,
99-
);
100-
// Serialize unknown ContentPart variants instead of dropping them
101-
result.push({ text: JSON.stringify(part) });
96+
default: {
97+
((x: never) => {
98+
throw new Error(`Unhandled ContentPart type: ${JSON.stringify(x)}`);
99+
})(part);
102100
break;
101+
}
103102
}
104103
}
105104
return result;

packages/core/src/agent/legacy-agent-session.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,10 @@ describe('LegacyAgentSession', () => {
241241
);
242242
});
243243

244-
it('throws for non-message payloads', async () => {
244+
it('returns null streamId for non-message payloads', async () => {
245245
const session = new LegacyAgentSession(deps);
246-
await expect(session.send({ update: { title: 'test' } })).rejects.toThrow(
247-
'only supports message sends',
248-
);
246+
const result = await session.send({ update: { title: 'test' } });
247+
expect(result.streamId).toBeNull();
249248
});
250249

251250
it('throws if send is called while a stream is active', async () => {

packages/core/src/agent/legacy-agent-session.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,10 @@ export class LegacyAgentProtocol implements AgentProtocol {
105105
};
106106
}
107107

108-
async send(payload: AgentSend): Promise<{ streamId: string }> {
108+
async send(payload: AgentSend): Promise<{ streamId: string | null }> {
109109
const message = 'message' in payload ? payload.message : undefined;
110110
if (!message) {
111-
throw new Error(
112-
'LegacyAgentSession.send() only supports message sends for the moment.',
113-
);
111+
return { streamId: null };
114112
}
115113

116114
if (this._activeStreamId) {

0 commit comments

Comments
 (0)