Skip to content

Conversation

@thatsKevinJain
Copy link
Contributor

Models like bfl/flux-2-dev accept FormData as inputs, where the user
can pass multiple images as style references. This PR allows AI bindings
to pass FormData as-is to the model.

@thatsKevinJain thatsKevinJain requested a review from a team as a code owner November 26, 2025 02:44
);
}

function isFormData(obj: unknown): obj is FormData {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use something like this?

function isFormData(obj: unknown): obj is FormData {
  return obj instanceof FormData;
}

Copy link
Contributor Author

@thatsKevinJain thatsKevinJain Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"instanceof" depends on how the object was constructed and can fail to work sometimes.

Referring to the SO article here:
https://stackoverflow.com/a/47204039

Screenshot 2025-11-26 at 9 28 31 AM

The approach used in PR above looks verbose, but it is trying to check if some specific functions of FormData object are present as well.

This is similar to how we check for readable streams:
https://github.com/cloudflare/workerd/pull/5590/files#diff-2fe1e717c62f1145cade283ccc2dabf84edd49d4517103ddc75171c17e5e710fR90

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are saying that we accept FormData then the users should build the object as a FormData and not a random object with append and entries methods. This means that the following object will pass the validation

const fakeFormData = {
  append(key: string, value: string) {
    console.log(`Appending ${key}: ${value}`);
  },
  entries() {
    return [['key1', 'value1']];
  }
};

On a side note: I also don't agree how we check for readable streams either

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danlapid Do you have ideas on what can be right approach here?

```
Models like bfl/flux-2-dev accept FormData as inputs, where the user
can pass multiple images as style references. This PR allows AI bindings
to pass FormData as-is to the model.
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants