Skip to content

Commit 33ed68f

Browse files
committed
refactor: address review follow-ups for local protocol
1 parent cd70571 commit 33ed68f

4 files changed

Lines changed: 21 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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import type { Part } from '@google/genai';
88
import type { ContentPart } from './types.js';
9+
import { debugLogger } from '../utils/debugLogger.js';
910

1011
/**
1112
* Converts Gemini API Part objects to framework-agnostic ContentPart objects.
@@ -92,12 +93,13 @@ export function contentPartsToGeminiParts(content: ContentPart[]): Part[] {
9293
// References are converted to text for the model
9394
result.push({ text: part.text });
9495
break;
95-
default: {
96-
((x: never) => {
97-
throw new Error(`Unhandled ContentPart type: ${JSON.stringify(x)}`);
98-
})(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) });
99102
break;
100-
}
101103
}
102104
}
103105
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
@@ -239,10 +239,11 @@ describe('LegacyAgentSession', () => {
239239
);
240240
});
241241

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

248249
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)