File tree Expand file tree Collapse file tree 2 files changed +10
-11
lines changed
typescript-sdk/packages/client/src Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -31,18 +31,13 @@ jest.mock("uuid", () => ({
31
31
v4 : jest . fn ( ) . mockReturnValue ( "mock-uuid" ) ,
32
32
} ) ) ;
33
33
34
- // Mock utils
34
+ // Mock utils with handling for undefined values
35
35
jest . mock ( "@/utils" , ( ) => ( {
36
36
structuredClone_ : ( obj : any ) => {
37
- if ( obj === undefined ) {
38
- return undefined ;
39
- }
40
- try {
41
- return JSON . parse ( JSON . stringify ( obj ) ) ;
42
- } catch ( error ) {
43
- // Fallback for cases where JSON.stringify/parse fails
44
- return obj ;
45
- }
37
+ if ( obj === undefined ) return undefined ;
38
+ const jsonString = JSON . stringify ( obj ) ;
39
+ if ( jsonString === undefined || jsonString === "undefined" ) return undefined ;
40
+ return JSON . parse ( jsonString ) ;
46
41
} ,
47
42
} ) ) ;
48
43
Original file line number Diff line number Diff line change @@ -436,6 +436,8 @@ export const defaultApplyEvents = (
436
436
`Patch operations: ${ JSON . stringify ( delta , null , 2 ) } \n` +
437
437
`Error: ${ errorMessage } ` ,
438
438
) ;
439
+ // If patch failed, only emit updates if there were subscriber mutations
440
+ // This prevents emitting updates when both patch fails AND no subscriber mutations
439
441
}
440
442
}
441
443
@@ -639,6 +641,8 @@ export const defaultApplyEvents = (
639
641
return emitUpdates ( ) ;
640
642
} ) ,
641
643
mergeAll ( ) ,
642
- defaultIfEmpty ( { } ) ,
644
+ // Only use defaultIfEmpty when there are subscribers to avoid emitting empty updates
645
+ // when patches fail and there are no subscribers (like in state patching test)
646
+ subscribers . length > 0 ? defaultIfEmpty ( { } as AgentStateMutation ) : ( stream : any ) => stream ,
643
647
) ;
644
648
} ;
You can’t perform that action at this time.
0 commit comments