Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions web/packages/teleport/src/Assist/context/AssistContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,7 @@ export function AssistContextProvider(props: PropsWithChildren<unknown>) {
executeCommandWebSocket.current = new WebSocket(url);
executeCommandWebSocket.current.binaryType = 'arraybuffer';

executeCommandWebSocket.current.onclose = () => {
for (const nodeId of nodeIdToResultId.keys()) {
dispatch({
type: AssistStateActionType.FinishCommandResult,
conversationId: state.conversations.selectedId,
commandResultId: nodeIdToResultId.get(nodeId),
});
}
};
let sessionsEnded = 0;

executeCommandWebSocket.current.onmessage = event => {
const uintArray = new Uint8Array(event.data);
Expand Down Expand Up @@ -457,16 +449,26 @@ export function AssistContextProvider(props: PropsWithChildren<unknown>) {
break;

case MessageTypeEnum.SESSION_END:
for (const nodeId of nodeIdToResultId.keys()) {
dispatch({
type: AssistStateActionType.FinishCommandResult,
conversationId: state.conversations.selectedId,
commandResultId: nodeIdToResultId.get(nodeId),
});
// we don't know the nodeId of the session that ended, so we have to
// count the finished sessions and then mark them all as done once
// they've all finished
sessionsEnded += 1;

if (sessionsEnded === nodeIdToResultId.size) {
for (const nodeId of nodeIdToResultId.keys()) {
dispatch({
type: AssistStateActionType.FinishCommandResult,
conversationId: state.conversations.selectedId,
commandResultId: nodeIdToResultId.get(nodeId),
});
}

nodeIdToResultId.clear();

// TODO(ryan): move this to after the summary is sent once it's implemented
executeCommandWebSocket.current.close();
}

nodeIdToResultId.clear();

break;
}
};
Expand Down