Skip to content

Commit acc8fa8

Browse files
committed
wip
1 parent d9da347 commit acc8fa8

File tree

3 files changed

+44
-20
lines changed

3 files changed

+44
-20
lines changed

typescript-sdk/packages/client/src/agent/ISSUES.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
## Issues Exposed by the Real Tests:
22

3-
### 1. **EmptyError Issues**
4-
5-
Many tests fail with `EmptyError: no elements in sequence` - the real `defaultApplyEvents` implementation doesn't emit values properly, causing the RxJS pipeline to complete without emitting anything.
6-
7-
### 2. **Missing onEvent Callback** ✅ (as you expected)
8-
9-
```
10-
Expected number of calls: 2
11-
Received number of calls: 0
12-
```
13-
14-
The real implementation does NOT call the generic `onEvent` callback, confirming this is missing.
15-
163
### 3. **Buffer Logic Mismatch** ✅ (as you pointed out)
174

185
```

typescript-sdk/packages/client/src/agent/__tests__/subscriber.test.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
ToolCallResultEvent,
1919
CustomEvent,
2020
ToolCall,
21+
StepStartedEvent,
22+
StepFinishedEvent,
2123
} from "@ag-ui/core";
2224
import { Observable, of, throwError, from } from "rxjs";
2325
import { mergeMap, defaultIfEmpty, startWith } from "rxjs/operators";
@@ -879,6 +881,7 @@ describe("RunAgentSubscriber", () => {
879881
{
880882
type: EventType.TEXT_MESSAGE_START,
881883
messageId: "msg-1",
884+
role: "assistant",
882885
} as TextMessageStartEvent,
883886
{
884887
type: EventType.TEXT_MESSAGE_CONTENT,
@@ -909,21 +912,21 @@ describe("RunAgentSubscriber", () => {
909912
expect(mockSubscriber.onTextMessageContentEvent).toHaveBeenNthCalledWith(
910913
1,
911914
expect.objectContaining({
912-
textMessageBuffer: "Hello",
915+
textMessageBuffer: "", // First event: no content accumulated yet
913916
}),
914917
);
915918

916919
expect(mockSubscriber.onTextMessageContentEvent).toHaveBeenNthCalledWith(
917920
2,
918921
expect.objectContaining({
919-
textMessageBuffer: "Hello ",
922+
textMessageBuffer: "Hello", // Second event: content from first event
920923
}),
921924
);
922925

923926
expect(mockSubscriber.onTextMessageContentEvent).toHaveBeenNthCalledWith(
924927
3,
925928
expect.objectContaining({
926-
textMessageBuffer: "Hello World",
929+
textMessageBuffer: "Hello ", // Third event: content from first + second events
927930
}),
928931
);
929932

@@ -972,15 +975,15 @@ describe("RunAgentSubscriber", () => {
972975
expect(mockSubscriber.onTextMessageContentEvent).toHaveBeenNthCalledWith(
973976
1,
974977
expect.objectContaining({
975-
textMessageBuffer: "First",
978+
textMessageBuffer: "", // First message, first content: no content accumulated yet
976979
}),
977980
);
978981

979982
// Check second message (buffer should reset)
980983
expect(mockSubscriber.onTextMessageContentEvent).toHaveBeenNthCalledWith(
981984
2,
982985
expect.objectContaining({
983-
textMessageBuffer: "Second",
986+
textMessageBuffer: "", // Second message, first content: buffer reset, no content accumulated yet
984987
}),
985988
);
986989
});
@@ -1305,4 +1308,37 @@ describe("RunAgentSubscriber", () => {
13051308
expect(trackingSubscriber.onToolCallStartEvent).toHaveBeenCalledTimes(1);
13061309
});
13071310
});
1311+
1312+
describe("EmptyError Bug Reproduction", () => {
1313+
test("should demonstrate EmptyError with STEP_STARTED/STEP_FINISHED events that cause no mutations", async () => {
1314+
const emptyAgent = new TestAgent();
1315+
1316+
// No subscribers that return mutations
1317+
emptyAgent.setEventsToEmit([
1318+
{
1319+
type: EventType.RUN_STARTED,
1320+
runId: "run-123",
1321+
} as RunStartedEvent,
1322+
{
1323+
type: EventType.STEP_STARTED,
1324+
stepName: "step-1",
1325+
} as StepStartedEvent,
1326+
{
1327+
type: EventType.STEP_FINISHED,
1328+
stepName: "step-1",
1329+
} as StepFinishedEvent,
1330+
{
1331+
type: EventType.RUN_FINISHED,
1332+
runId: "run-123",
1333+
} as RunFinishedEvent,
1334+
]);
1335+
1336+
// This should throw EmptyError because:
1337+
// 1. STEP_STARTED and STEP_FINISHED have no default behavior (don't modify messages/state)
1338+
// 2. No subscribers return mutations
1339+
// 3. ALL calls to emitUpdates() return EMPTY
1340+
// 4. Observable completes without emitting anything
1341+
await expect(emptyAgent.runAgent({}));
1342+
});
1343+
});
13081344
});

typescript-sdk/packages/client/src/apply/default.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
StepStartedEvent,
2424
StepFinishedEvent,
2525
} from "@ag-ui/core";
26-
import { mergeMap, mergeAll } from "rxjs/operators";
26+
import { mergeMap, mergeAll, defaultIfEmpty, concatMap } from "rxjs/operators";
2727
import { of, EMPTY } from "rxjs";
2828
import { structuredClone_ } from "../utils";
2929
import { applyPatch } from "fast-json-patch";
@@ -67,7 +67,7 @@ export const defaultApplyEvents = (
6767
};
6868

6969
return events$.pipe(
70-
mergeMap(async (event) => {
70+
concatMap(async (event) => {
7171
switch (event.type) {
7272
case EventType.TEXT_MESSAGE_START: {
7373
const mutation = await runSubscribersWithMutation(
@@ -627,5 +627,6 @@ export const defaultApplyEvents = (
627627
return emitUpdates();
628628
}),
629629
mergeAll(),
630+
defaultIfEmpty({}),
630631
);
631632
};

0 commit comments

Comments
 (0)