TanStack AI supports a number as duration. We then include a per adapter function that validates the duration that is passed. The problem is that duration can be as complex as size is for images. Many models support strings such as "6s", and "auto" for durations. There are some that supply a range.
Problem
It's really hard for the consumer to know what durations are supported. Validating the duration at runtime doesn't help as it implies that all the logic to determine if a duration is supported.
Possible Solutions
The current TanStack AI system relies on typescript for model option validation, and I believe we should do the same for durations. We modify the duration field to be a template type, and allow adapters to define on a per model basis. This would prevent the user from passing an arbitrary number to the adapter. This is the first thing we should do and it would be a breaking change.
We should then provide several functions on the adapter
availableDurations - lists the available durations in some sort of structure
snapDuration - given seconds as input, return the closest matching valid duration
TanStack AI supports a number as duration. We then include a per adapter function that validates the duration that is passed. The problem is that duration can be as complex as size is for images. Many models support strings such as "6s", and "auto" for durations. There are some that supply a range.
Problem
It's really hard for the consumer to know what durations are supported. Validating the duration at runtime doesn't help as it implies that all the logic to determine if a duration is supported.
Possible Solutions
The current TanStack AI system relies on typescript for model option validation, and I believe we should do the same for durations. We modify the duration field to be a template type, and allow adapters to define on a per model basis. This would prevent the user from passing an arbitrary number to the adapter. This is the first thing we should do and it would be a breaking change.
We should then provide several functions on the adapter
availableDurations- lists the available durations in some sort of structuresnapDuration- given seconds as input, return the closest matching valid duration