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

Method dispatchEvent

src/node/services/mock/mockAiStreamPlayer.ts:643–847  ·  view source on GitHub ↗
(
    workspaceId: string,
    event: MockAssistantEvent,
    messageId: string,
    historySequence: number
  )

Source from the content-addressed store, hash-verified

641 }
642
643 private async dispatchEvent(
644 workspaceId: string,
645 event: MockAssistantEvent,
646 messageId: string,
647 historySequence: number
648 ): Promise<void> {
649 const active = this.activeStreams.get(workspaceId);
650 if (!active || active.cancelled || active.messageId !== messageId) {
651 return;
652 }
653
654 switch (event.kind) {
655 case "stream-start": {
656 const payload: StreamStartEvent = {
657 type: "stream-start",
658 workspaceId,
659 messageId,
660 model: event.model,
661 historySequence,
662 startTime: Date.now(),
663 ...(event.mode && { mode: event.mode }),
664 ...(event.thinkingLevel && { thinkingLevel: event.thinkingLevel }),
665 };
666 active.model = event.model;
667 active.startTime = payload.startTime;
668 this.deps.aiService.emit("stream-start", payload);
669 break;
670 }
671 case "reasoning-delta": {
672 // Mock streams use the same tokenization logic as real streams for consistency
673 const tokens = await tokenizeWithMockModel(event.text, "reasoning-delta text");
674 if (active.cancelled) return;
675 const payload: ReasoningDeltaEvent = {
676 type: "reasoning-delta",
677 workspaceId,
678 messageId,
679 delta: event.text,
680 tokens,
681 timestamp: Date.now(),
682 };
683 this.appendReasoningPart(active, event.text, payload.timestamp);
684 this.schedulePartialWrite(workspaceId, active);
685 this.deps.aiService.emit("reasoning-delta", payload);
686 break;
687 }
688 case "tool-start": {
689 // Mock streams use the same tokenization logic as real streams for consistency
690 const inputText = JSON.stringify(event.args);
691 const tokens = await tokenizeWithMockModel(inputText, "tool-call args");
692 if (active.cancelled) return;
693 const payload: ToolCallStartEvent = {
694 type: "tool-call-start",
695 workspaceId,
696 messageId,
697 toolCallId: event.toolCallId,
698 toolName: event.toolName,
699 args: event.args,
700 tokens,

Callers 15

scheduleEventsMethod · 0.95
AppInnerFunction · 0.80
CommandPaletteFunction · 0.80
WorkspaceMenuBarFunction · 0.80
processSlashCommandFunction · 0.80
handleGoalCommandFunction · 0.80
dispatchWorkspaceSwitchFunction · 0.80
showCommandFeedbackToastFunction · 0.80
openGoalPanelFunction · 0.80
buildCoreSourcesFunction · 0.80

Calls 15

appendReasoningPartMethod · 0.95
schedulePartialWriteMethod · 0.95
setToolPartInputMethod · 0.95
setToolPartOutputMethod · 0.95
appendTextPartMethod · 0.95
isCurrentActiveStreamMethod · 0.95
cleanupMethod · 0.95
buildCompletedPartsMethod · 0.95
createErrorEventFunction · 0.90
tokenizeWithMockModelFunction · 0.85
deletePartialMethod · 0.80

Tested by 1

openModelSelectorFunction · 0.64