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

Method createStreamResult

src/node/services/streamManager.ts:1515–1550  ·  view source on GitHub ↗
(
    request: StreamRequestConfig,
    abortController: AbortController,
    stepTracker?: StepMessageTracker
  )

Source from the content-addressed store, hash-verified

1513 }
1514
1515 private createStreamResult(
1516 request: StreamRequestConfig,
1517 abortController: AbortController,
1518 stepTracker?: StepMessageTracker
1519 ): Awaited<ReturnType<typeof streamText>> {
1520 return streamText({
1521 model: request.model,
1522 messages: request.messages,
1523 system: request.system,
1524 abortSignal: abortController.signal,
1525 prepareStep: async ({ messages: stepMessages }) => {
1526 // streamText runs multiple internal LLM calls (steps) when tools are enabled.
1527 // Strip workflow run records from same-turn tool results (history-level redaction in
1528 // applyToolOutputRedaction can't see these), then extract supported attachments out of
1529 // tool-result JSON so providers don't treat them as text.
1530 const withoutWorkflowRunRecords = stripWorkflowRunRecordsFromModelMessages(stepMessages);
1531 const rewritten =
1532 await extractToolMediaAsUserMessagesFromModelMessages(withoutWorkflowRunRecords);
1533 const effectiveMessages = rewritten === stepMessages ? stepMessages : rewritten;
1534 if (stepTracker) {
1535 stepTracker.latestMessages = effectiveMessages;
1536 }
1537 request.onStepMessages?.(effectiveMessages);
1538 if (rewritten === stepMessages) return undefined;
1539 return { messages: rewritten };
1540 },
1541 onChunk: request.onChunk,
1542 tools: request.tools,
1543 stopWhen: this.createStopWhenCondition(request),
1544 // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
1545 providerOptions: request.providerOptions as any, // Pass provider-specific options (thinking/reasoning config)
1546 headers: request.headers, // Per-request HTTP headers (e.g., anthropic-beta for 1M context)
1547 maxOutputTokens: request.maxOutputTokens,
1548 ...(request.streamCallSettings ?? {}),
1549 });
1550 }
1551
1552 /**
1553 * Atomically creates a new stream with all necessary setup

Tested by

no test coverage detected