GitHub 37
Skip to content
ViteHub is still experimental. Expect bugs and breaking changes.

Choices

Turn what people type into choices from your options, for filters, search, and command palettes.

server/utils/forecast-choices.ts
import { defineChoices, toOptions } from 'vite-hub/choices'
import { typesafe } from 'vite-hub/gateways'

// Bridge in: your data becomes options
export const forecast = defineChoices({
  gateway: typesafe(), // reads TYPESAFE_API_KEY
  groups: {
    supplier: {
      label: 'Supplier',
      options: toOptions(suppliers, {
        value: s => s.id,
        label: s => s.name,
      }),
    },
  },
})
server/utils/forecast-choices.ts

Declare options, get typed choices

defineChoices() types the selection from your options.

Include and exclude

"nord parts except vak supply" includes one supplier and excludes one.

The model cannot invent a value

Each selected value is one of your options.

You own the route and the state

Auth, limits, and filters stay in your code. useChoices() connects them.

Try it with no API key

The tutorial runs offline. The last step adds a real model.

Know the limits

100 options, 300 characters of text, and one error code per failure.