Skip to content

feat(apollo-wind): add maxRef to slider for dynamic max from another field#707

Merged
Holychung merged 5 commits into
mainfrom
harry/wind-slider-max-from-field
May 18, 2026
Merged

feat(apollo-wind): add maxRef to slider for dynamic max from another field#707
Holychung merged 5 commits into
mainfrom
harry/wind-slider-max-from-field

Conversation

@Holychung
Copy link
Copy Markdown
Contributor

Summary

SliderFieldMetadata.max was a static number — fine for fixed ranges (e.g. temperature: 0..1) but a poor fit when the upper bound depends on another field. The motivating case: an agent's maxTokenPerResponse slider should cap at the selected model's maxTokens, but the available models (and their token caps) only exist at runtime.

This PR adds an additive, back-compat maxRef option that lets the slider read its max from another form field at render time.

Changes

  • form-schema.ts — Adds FieldRef interface and SliderFieldMetadata.maxRef?: FieldRef. Existing static max?: number is untouched, so consumers using the plain numeric form keep working with no migration.
  • field-renderer.tsx — Extracts the case 'slider' body into a SliderField sub-component (slider needs hooks now). It calls useFormContext().watch(maxRef.fromField) and resolves max as: watched value if finite and positive → maxRef.fallback → static max → 100. If the resolved max drops below the current form value (e.g. user switches to a model with a lower cap), the value is clamped via onChange.
  • field-renderer.test.tsx — 6 new tests covering static max, default fallback, maxRef resolution, watched-field-missing fallback, watched-field-non-numeric fallback, and maxRef precedence over static max.

Usage

{
  name: 'inputs.maxTokenPerResponse',
  type: 'slider',
  label: 'Max. tokens per response',
  min: 0,
  step: 1,
  // Watches `inputs.modelMaxTokens` — caller wires this hidden field via
  // setValue() whenever the model picker selection changes.
  maxRef: { fromField: 'inputs.modelMaxTokens', fallback: 16384 },
}

Test plan

  • pnpm exec tsc --noEmit — clean
  • pnpm test (apollo-wind) — 909 passed (was 903; +6 new)
  • pnpm lint — no new diagnostics introduced
  • Reviewer sanity check: static max: 100 slider still renders identically (covered by existing tests but worth a manual eyeball in Storybook)

…field

Slider's `max` was a static number. To support cases where the upper
bound depends on another field (e.g. an LLM model picker selecting a
model with its own token cap), add an optional `maxRef: { fromField,
fallback }` to SliderFieldMetadata.

When `maxRef` is set, the slider watches the referenced field via
useFormContext and uses the watched value as max if it is a finite
positive number; otherwise `fallback`. If the resolved max drops below
the current form value, the value is clamped via onChange. Static
`max` and the historical default of 100 remain unchanged.
@github-actions github-actions Bot added pkg:apollo-wind size:L 100-499 changed lines. labels May 14, 2026
@Holychung Holychung requested a review from snuziale May 15, 2026 17:54
Comment thread packages/apollo-wind/src/components/forms/field-renderer.tsx Outdated
Comment thread packages/apollo-wind/src/components/forms/field-renderer.tsx Outdated
Copy link
Copy Markdown
Contributor

@david-rios-uipath david-rios-uipath left a comment

Choose a reason for hiding this comment

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

a couple nits

@Holychung Holychung merged commit f2144f2 into main May 18, 2026
30 of 31 checks passed
@Holychung Holychung deleted the harry/wind-slider-max-from-field branch May 18, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:apollo-wind size:L 100-499 changed lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants