()
| 940 | }; |
| 941 | |
| 942 | const pump = async () => { |
| 943 | if (!active) { |
| 944 | return; |
| 945 | } |
| 946 | |
| 947 | try { |
| 948 | const { events, cursor } = await this.traceService.listSince(runId, lastSequence, auth); |
| 949 | if (events.length > 0) { |
| 950 | const lastId = events[events.length - 1]?.id; |
| 951 | if (lastId) { |
| 952 | const parsed = Number.parseInt(lastId, 10); |
| 953 | if (!Number.isNaN(parsed)) { |
| 954 | lastSequence = parsed; |
| 955 | } |
| 956 | } |
| 957 | send('trace', { events, cursor: cursor ?? lastSequence.toString() }); |
| 958 | |
| 959 | const timestamps = events |
| 960 | .map((event) => Date.parse(event.timestamp)) |
| 961 | .filter((value) => !Number.isNaN(value)); |
| 962 | if (timestamps.length > 0) { |
| 963 | const first = Math.min(...timestamps); |
| 964 | const last = Math.max(...timestamps); |
| 965 | if (earliestEventTimestamp === null || first < earliestEventTimestamp) { |
| 966 | earliestEventTimestamp = first; |
| 967 | } |
| 968 | if (latestEventTimestamp === null || last > latestEventTimestamp) { |
| 969 | latestEventTimestamp = last; |
| 970 | } |
| 971 | |
| 972 | const packets = await this.workflowsService.buildDataFlows(runId, events, { |
| 973 | baseTimestamp: earliestEventTimestamp ?? first, |
| 974 | latestTimestamp: latestEventTimestamp ?? last, |
| 975 | }); |
| 976 | |
| 977 | if (packets.length > 0) { |
| 978 | send('dataflow', { packets }); |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | const terminal = await this.terminalStreamService.fetchChunks(runId, { |
| 984 | cursor: terminalCursor, |
| 985 | }); |
| 986 | if (terminal.chunks.length > 0) { |
| 987 | terminalCursor = terminal.cursor; |
| 988 | send('terminal', { runId, ...terminal }); |
| 989 | } |
| 990 | |
| 991 | const { logs: newLogs, cursor: nextCursor } = await this.logStreamService.fetchRecentLogs( |
| 992 | runId, |
| 993 | auth?.organizationId ?? null, |
| 994 | lastLogCursor, |
| 995 | ); |
| 996 | if (newLogs.length > 0) { |
| 997 | lastLogCursor = nextCursor ?? lastLogCursor; |
| 998 | send('logs', { logs: newLogs, cursor: lastLogCursor }); |
| 999 | } |
nothing calls this directly
no test coverage detected