Skip to content

Commit e15dc75

Browse files
committed
refactor: use optional chaining instead of try-catch for broadcaster push
Addresses review feedback from louisgv. The push() method doesn't throw, so the try-catch was unnecessary. Using optional chaining (?.) instead of non-null assertion (!) is safer and more idiomatic TypeScript.
1 parent d38b5c7 commit e15dc75

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/lib/model-result.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,11 @@ export class ModelResult<TTools extends readonly Tool[]> {
347347
// Create callback for real-time preliminary results
348348
const onPreliminaryResult = this.toolEventBroadcaster
349349
? (callId: string, resultValue: unknown) => {
350-
try {
351-
this.toolEventBroadcaster!.push({
352-
type: 'preliminary_result' as const,
353-
toolCallId: callId,
354-
result: resultValue as InferToolEventsUnion<TTools>,
355-
});
356-
} catch {
357-
// Don't crash tool execution if broadcasting fails
358-
}
350+
this.toolEventBroadcaster?.push({
351+
type: 'preliminary_result' as const,
352+
toolCallId: callId,
353+
result: resultValue as InferToolEventsUnion<TTools>,
354+
});
359355
}
360356
: undefined;
361357

0 commit comments

Comments
 (0)