Skip to content

@flue/runtime: normalize Workers AI assistant content null without hiding malformed content #639

Description

@jairojair

Package

@flue/runtime@2.0.3, Cloudflare Workers AI binding provider.

Reproduction

Use a binding-backed model with an OpenAI-compatible streaming response whose
first assistant delta is a valid tool-call preamble:

{
  "choices": [
    { "delta": { "role": "assistant", "content": null } }
  ]
}

The OpenAI/Workers AI contract permits content: null when an assistant turn
has no text (for example, a tool-call-only turn). Responses with other runtime
values, such as an object or array in delta.content, are malformed.

Expected behavior

  • Treat content: null (and an omitted content field) as no text delta and
    continue processing tool calls.
  • Reject other non-string content values with a clear provider error instead of
    silently dropping the malformed response.

Proposed fix

Normalize the assistant delta at the binding boundary: return an absent text
delta for null/undefined, accept strings, and throw for all other runtime
types. A focused provider test should cover both the valid null shape and an
invalid non-string shape.

This matters because the provider parses binding responses manually rather than
using the upstream OpenAI stream parser. The current main branch
(832ad2ee, published as 2.0.3) ignores null, but also silently ignores
malformed non-string values because the TypeScript type is not a runtime guard.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions