vercel/ai · error · Error

HarnessAgent: toTextStreamResponse is not implemented yet. T

Error message

HarnessAgent: toTextStreamResponse is not implemented yet. Track the foundation review for follow-up.

What it means

toTextStreamResponse on HarnessStreamTextResult throws a notSupportedYet placeholder error because converting the harness agent's text stream into a standard HTTP Response has not been implemented. The library throws immediately to make the missing capability explicit during the foundation review rather than returning a broken response.

Source

Thrown at packages/harness/src/agent/internal/harness-stream-text-result.ts:805

    return createUIMessageStreamResponse({
      stream: this.toUIMessageStream<UI_MESSAGE>({
        originalMessages,
        generateMessageId,
        onEnd,
        onFinish,
        messageMetadata,
        sendReasoning,
        sendSources,
        sendStart,
        sendFinish,
        onError,
      }),
      ...init,
    });
  }

  toTextStreamResponse(): never {
    throw notSupportedYet('toTextStreamResponse');
  }

  // ─── Helpers ────────────────────────────────────────────────────────

  private appendToCurrentStepContent(part: TextStreamPart<TOOLS>): void {
    switch (part.type) {
      case 'text-delta': {
        // Coalesce contiguous text-deltas with the same id into one text part.
        const last =
          this.currentStepContent[this.currentStepContent.length - 1];
        if (last && last.type === 'text') {
          (last as { text: string }).text += part.text;
        } else {
          this.currentStepContent.push({
            type: 'text',
            text: part.text,
          } as ContentPart<TOOLS>);
        }

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Construct the Response yourself from result.textStream: new Response(result.textStream, { headers: { 'content-type': 'text/plain; charset=utf-8', 'x-vercel-ai-ui-stream': undefined } }).
  2. If you need UI message streaming, check whether toUIMessageStreamResponse (which is implemented) fits your use case instead.
  3. Follow the harness foundation review for the upcoming implementation and update calls once available.
  4. Fall back to core `ai` streamText for endpoints that require toTextStreamResponse semantics.

Example fix

// before
const result = await agent.stream({ prompt });
return result.toTextStreamResponse();
// after
const result = await agent.stream({ prompt });
return new Response(result.textStream, {
  headers: { 'content-type': 'text/plain; charset=utf-8' },
});
Defensive patterns

Strategy: fallback

Validate before calling

if (typeof result.toTextStreamResponse !== 'function' || isHarnessResult(result)) {
  return new Response(result.textStream, { headers: { 'content-type': 'text/plain; charset=utf-8' } });
}

Type guard

function supportsToTextStreamResponse(result: unknown): result is { toTextStreamResponse: (init?: ResponseInit) => Response } {
  return typeof result === 'object' && result !== null &&
    typeof (result as { toTextStreamResponse?: unknown }).toTextStreamResponse === 'function';
}

Prevention

When it happens

Trigger: Calling result.toTextStreamResponse() (with or without init options) on the result of a HarnessAgent streaming run; the method signature returns `never` because it always throws.

Common situations: Porting a route handler from `ai`'s streamText (where toTextStreamResponse is supported) to HarnessAgent; framework adapters (Next.js App Router, Remix) that expect a Response object; upgrading to the harness package and reusing old streaming response code.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/a5fd7273a2a94009. Report an issue: GitHub.