Class ValueOptions<I>

java.lang.Object
com.vaadin.flow.component.ai.form.ValueOptions<I>
Type Parameters:
I - the per-label item type the converter must produce ? the field's value type for single-value fields, the per-element type for multi-select fields

public final class ValueOptions<I> extends Object
Per-field registration of the labels the LLM may pick from for a given field. The label set is either fixed (options(Collection)) or supplied on demand by a callback (options(BiFunction)); exactly one of the two must be set, with the last call winning. Pass the configured registration to controller.fieldValueOptions(...) to apply it; the labels are then presented to the LLM as the field's choices.

Labels are always String values, regardless of the field's value type. For a non-String field, supply a label-to-value converter through fieldValueOptions(config, toValue) ? the converter resolves a chosen label to the field's value type before the controller writes it.

Author:
Vaadin Ltd
  • Method Details

    • forField

      public static <V> ValueOptions<V> forField(HasValue<?,V> field)
      Starts an options registration for a single-value field. The field's value type V flows through; for any V other than String, the controller's two-argument FormAIController.fieldValueOptions(ValueOptions, Function) overload must be used to supply a label-to-value converter (a compile-time requirement, not a runtime check).
      Type Parameters:
      V - the field's value type
      Parameters:
      field - the single-value field whose options the LLM may pick from, not null
      Returns:
      a fresh registration ready to receive options(Collection) or options(BiFunction)
    • forField

      public static <T, C extends Component> ValueOptions<T> forField(MultiSelect<C,T> field)
      Starts an options registration for a multi-select field. Picked by the compiler over forField(HasValue) whenever the reference is statically typed as MultiSelect. The per-element type T flows through; for any T other than String, the controller's two-argument FormAIController.fieldValueOptions(ValueOptions, Function) overload must be used. The controller aggregates resolved per-label items into a LinkedHashSet before HasValue.setValue(V).
      Type Parameters:
      T - the per-element type
      C - the field's source-component type
      Parameters:
      field - the multi-select field whose options the LLM may pick from, not null
      Returns:
      a fresh registration ready to receive options(Collection) or options(BiFunction)
    • options

      public ValueOptions<I> options(Collection<String> options)
      Sets a fixed label list. A defensive copy is taken so later mutations of the caller's collection have no effect. Use this when the option set is known up front and small enough to enumerate; for large or dynamic sets use options(BiFunction) instead. Mutually exclusive with options(BiFunction) ? calling either clears the other.
      Parameters:
      options - the labels the LLM may pick from, not null and not empty
      Returns:
      this registration, for chaining
      Throws:
      IllegalArgumentException - if options is empty ? registering an empty fixed list leaves the field un-fillable and is always a developer mistake
    • options

      public ValueOptions<I> options(BiFunction<String,Integer,List<String>> query)
      Sets a callback the controller invokes whenever the LLM needs to see the field's options. Use this when the option set is too large or too dynamic for a fixed list via options(Collection) ? for example options that come from a database query or a remote service. The callback returns the labels the LLM may pick from; labels are always String values, regardless of the field's value type. Mutually exclusive with options(Collection) ? calling either clears the other.
      Parameters:
      query - invoked with two arguments: a filter string the LLM picked, and a positive limit on how many labels to return. Returns the matching labels in display order, not null (an empty list signals "no matches" to the LLM)
      Returns:
      this registration, for chaining