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

Method emitToolCallDeltaIfPresent

src/node/services/streamManager.ts:887–923  ·  view source on GitHub ↗

* Extracts usage and duration metadata from stream result. * * Usage is only available after stream completes naturally. * On abort, the usage promise may hang - we use a timeout to return quickly.

(
    workspaceId: WorkspaceId,
    streamInfo: WorkspaceStreamInfo,
    part: unknown
  )

Source from the content-addressed store, hash-verified

885 * On abort, the usage promise may hang - we use a timeout to return quickly.
886 */
887 private async emitToolCallDeltaIfPresent(
888 workspaceId: WorkspaceId,
889 streamInfo: WorkspaceStreamInfo,
890 part: unknown
891 ): Promise<boolean> {
892 const maybeDelta = part as { type?: string } | undefined;
893 if (maybeDelta?.type !== "tool-call-delta") {
894 return false;
895 }
896
897 const toolDelta = part as {
898 toolCallId: string;
899 toolName: string;
900 argsTextDelta: string;
901 };
902
903 const deltaText = String(toolDelta.argsTextDelta ?? "");
904 if (deltaText.length === 0) {
905 return true;
906 }
907
908 const tokens = await this.tokenTracker.countTokens(deltaText);
909 const timestamp = Date.now();
910
911 this.emit("tool-call-delta", {
912 type: "tool-call-delta",
913 workspaceId: workspaceId as string,
914 messageId: streamInfo.messageId,
915 toolCallId: toolDelta.toolCallId,
916 toolName: toolDelta.toolName,
917 delta: toolDelta.argsTextDelta,
918 tokens,
919 timestamp,
920 });
921
922 return true;
923 }
924
925 private async getStreamMetadata(
926 streamInfo: WorkspaceStreamInfo,

Callers 1

Calls 2

emitMethod · 0.65
countTokensMethod · 0.45

Tested by

no test coverage detected