MCPcopy
hub / github.com/coder/mux / emitHistoricalEvents

Method emitHistoricalEvents

src/node/services/agentSession.ts:1854–2210  ·  view source on GitHub ↗
(
    listener: (event: AgentSessionChatEvent) => void,
    mode?: OnChatMode
  )

Source from the content-addressed store, hash-verified

1852 }
1853
1854 private async emitHistoricalEvents(
1855 listener: (event: AgentSessionChatEvent) => void,
1856 mode?: OnChatMode
1857 ): Promise<void> {
1858 let replayMode: "full" | "since" | "live" = "full";
1859 let hasOlderHistory: boolean | undefined;
1860 let serverCursor: OnChatCursor | undefined;
1861 let emittedReplayMessages = false;
1862
1863 const emitReplayMessage = (message: WorkspaceChatMessage): void => {
1864 emittedReplayMessages = true;
1865 listener({ workspaceId: this.workspaceId, message });
1866 };
1867
1868 let replayedTerminalStreamError = false;
1869 let replayedStreamLifecycle: StreamLifecycleSnapshot | null = null;
1870 let replayedRuntimeStatus: RuntimeStatusEvent | null = null;
1871 const emitReplayStatusMessage = (message: WorkspaceChatMessage): void => {
1872 listener({ workspaceId: this.workspaceId, message });
1873 };
1874 const emitCurrentReplayTerminalState = (): void => {
1875 if (!replayedTerminalStreamError && this.terminalStreamError) {
1876 replayedTerminalStreamError = true;
1877 emitReplayStatusMessage({
1878 ...this.terminalStreamError,
1879 replay: true,
1880 });
1881 }
1882
1883 const lifecycle = this.getCurrentStreamLifecycleSnapshot();
1884 if (!this.hasSameStreamLifecycle(replayedStreamLifecycle, lifecycle)) {
1885 replayedStreamLifecycle = copyStreamLifecycleSnapshot(lifecycle);
1886 emitReplayStatusMessage({
1887 type: "stream-lifecycle",
1888 workspaceId: this.workspaceId,
1889 ...lifecycle,
1890 });
1891 }
1892
1893 const runtimeStatus = this.preparingRuntimeStatus;
1894 if (runtimeStatus && !this.hasSameRuntimeStatus(replayedRuntimeStatus, runtimeStatus)) {
1895 replayedRuntimeStatus = { ...runtimeStatus };
1896 emitReplayStatusMessage(runtimeStatus);
1897 }
1898 };
1899
1900 let emittedReplayStreamEvents = false;
1901 const replayStreamEventTracker = (event: AgentSessionChatEvent) => {
1902 if (event.workspaceId !== this.workspaceId) {
1903 return;
1904 }
1905
1906 const message = event.message;
1907 if (typeof message !== "object" || message === null) {
1908 return;
1909 }
1910
1911 if (!("replay" in message) || message.replay !== true) {

Callers 2

subscribeChatMethod · 0.95
replayHistoryMethod · 0.95

Calls 15

onMethod · 0.80
replayInitMethod · 0.80
readPartialMethod · 0.80
getDisplayTextMethod · 0.80
getFilePartsMethod · 0.80
getReviewsMethod · 0.80
getQueueDispatchModeMethod · 0.80
hasCompactionRequestMethod · 0.80

Tested by

no test coverage detected