Skip to content

Commit 6bd12e9

Browse files
committed
refactor: address review follow-ups for local protocol
1 parent 818074b commit 6bd12e9

4 files changed

Lines changed: 20 additions & 14 deletions

File tree

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

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

190-
it('throws on unknown ContentPart variants', () => {
190+
it('serializes 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-
expect(() => contentPartsToGeminiParts(content)).toThrow(
196-
'Unhandled ContentPart type: {"type":"custom_widget","payload":123}',
197-
);
195+
const result = contentPartsToGeminiParts(content);
196+
expect(result).toHaveLength(1);
197+
expect(result[0]).toEqual({
198+
text: JSON.stringify({ type: 'custom_widget', payload: 123 }),
199+
});
198200
});
199201
});
200202

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ 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-
((x: never) => {
98-
throw new Error(`Unhandled ContentPart type: ${JSON.stringify(x)}`);
99-
})(part);
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) });
100102
break;
101-
}
102103
}
103104
}
104105
return result;

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

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

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

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

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

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

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

114116
if (this._activeStreamId) {

0 commit comments

Comments
 (0)