YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(chat): name an effort value the dial's steps don't contain
Manas Raghuwanshica217b879ebf
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/composer-effort-slider.test.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/composer-effort-slider.test.tsxindex 27c65900b..ed893c12d 100644--- a/apps/screenpipe-app-tauri/components/chat/standalone/composer-effort-slider.test.tsx+++ b/apps/screenpipe-app-tauri/components/chat/standalone/composer-effort-slider.test.tsx@@ -76,6 +76,7 @@ describe("effort slider", () => {expect(slider).toHaveAttribute("aria-valuemax", "2");// A position alone is not a value: screen readers get the name too.expect(slider).toHaveAttribute("aria-valuetext", "High");+ expect(screen.getByTestId("effort-thumb")).toBeInTheDocument();});it("moves with the keyboard, and stops at both ends", () => {@@ -243,23 +244,19 @@ describe("effort slider", () => {expect(animated.length).toBe(2);});- it("survives a value the steps do not contain", () => {- // An adapter can advertise a current value outside what it listed, or an- // empty one. The dial sits on the first step, and that step is still a- // real choice the user can make.+ it("names a value the steps do not contain, and still takes a step", () => {+ // An adapter can report a value outside what it listed (renamed between+ // versions) or none at all. The dial must not claim it is the first step,+ // and that step must still be a choice the user can make.const onValueChange = vi.fn();- render(- <ComposerEffortSlider- label="effort"- testId="effort"- steps={STEPS}- value=""- onValueChange={onValueChange}- />,- );+ const props = { label: "effort", testId: "effort", steps: STEPS, onValueChange };+ const { rerender } = render(<ComposerEffortSlider {...props} value="xhigh" />);const slider = layOut(screen.getByTestId("effort"));- expect(slider).toHaveAttribute("aria-valuenow", "0");+ expect(screen.getByTestId("effort-value")).toHaveTextContent("xhigh");+ expect(slider).toHaveAttribute("aria-valuetext", "xhigh");+ expect(screen.queryByTestId("effort-thumb")).not.toBeInTheDocument();+ rerender(<ComposerEffortSlider {...props} value="" />);press(slider, 6);release(slider, 6);fireEvent.keyDown(slider, { key: "Home" });diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/composer-effort-slider.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/composer-effort-slider.tsxindex b6f2fa4ba..4ec76bc7a 100644--- a/apps/screenpipe-app-tauri/components/chat/standalone/composer-effort-slider.tsx+++ b/apps/screenpipe-app-tauri/components/chat/standalone/composer-effort-slider.tsx@@ -64,25 +64,23 @@ export function ComposerEffortSlider({const labelId = useId();const trackRef = useRef<HTMLDivElement>(null);const lastIndex = steps.length - 1;- const indexOf = (stepValue: string) =>- Math.max(- 0,- steps.findIndex((step) => step.value === stepValue),- );// The step under the pointer while dragging; committed on release.const [dragIndex, setDragIndex] = useState<number | null>(null);// Glide only for changes made here.const [animate, setAnimate] = useState(false);- const valueIndex = indexOf(value);+ // -1 when the value is none of the steps, e.g. an adapter's renamed or unset+ // value. The dial then names the raw value and shows no thumb, rather than+ // claiming the first step.+ const valueIndex = steps.findIndex((step) => step.value === value);// Disabling the dial drops a drag in progress.const dragging = dragIndex !== null && !disabled;const shownIndex = dragging ? dragIndex : valueIndex;const shown = steps[shownIndex];// Single step would divide by zero and has nothing to slide between.- const percent = lastIndex > 0 ? (shownIndex / lastIndex) * 100 : 0;+ const percent = lastIndex > 0 ? (Math.max(0, shownIndex) / lastIndex) * 100 : 0;// The thumb travels across `track - thumbWidth` so it never overhangs either// end. Ticks use the same interpolation rather than an even spread, or the// thumb would sit beside its own tick everywhere except the two ends.@@ -91,7 +89,7 @@ export function ComposerEffortSlider({// Nearest step to a pointer position, measured on the thumb's travel.const indexAt = (clientX: number) => {const rect = trackRef.current?.getBoundingClientRect();- if (!rect || rect.width <= THUMB_WIDTH_PX || lastIndex <= 0) return shownIndex;+ if (!rect || rect.width <= THUMB_WIDTH_PX || lastIndex <= 0) return Math.max(0, shownIndex);const fraction =(clientX - rect.left - THUMB_WIDTH_PX / 2) / (rect.width - THUMB_WIDTH_PX);return Math.min(lastIndex, Math.max(0, Math.round(fraction * lastIndex)));@@ -136,7 +134,7 @@ export function ComposerEffortSlider({aria-labelledby={labelId}aria-valuemin={0}aria-valuemax={lastIndex}- aria-valuenow={shownIndex}+ aria-valuenow={Math.max(0, shownIndex)}aria-valuetext={shown?.name ?? value}aria-disabled={disabled || undefined}data-testid={testId}@@ -190,6 +188,9 @@ export function ComposerEffortSlider({}}className={cn("group/effort relative mt-1.5 flex h-7 w-full touch-none select-none items-center outline-none",+ // The thumb carries the focus ring; with no thumb the track does.+ !shown &&+ "focus-visible:ring-1 focus-visible:ring-signal focus-visible:ring-offset-1 focus-visible:ring-offset-background",disabled? "cursor-not-allowed opacity-50": dragging@@ -231,18 +232,21 @@ export function ComposerEffortSlider({{/* Thumb. Sharp-cornered on purpose; fills with ink while held, thesame inversion hover uses elsewhere, and carries the focus ring sokeyboard focus shows where the value is. */}- <div- className={cn(- "absolute h-5 border border-foreground",- dragging ? "cursor-grabbing bg-foreground" : "bg-background",- !disabled && !dragging && "cursor-grab",- "group-focus-visible/effort:ring-1 group-focus-visible/effort:ring-signal group-focus-visible/effort:ring-offset-1 group-focus-visible/effort:ring-offset-background",- animate &&- "transition-[left,background-color] duration-150 ease-out motion-reduce:transition-none",- )}- style={{ left: offsetFor(percent), width: THUMB_WIDTH_PX }}- aria-hidden- />+ {shown && (+ <div+ data-testid={testId ? `${testId}-thumb` : undefined}+ className={cn(+ "absolute h-5 border border-foreground",+ dragging ? "cursor-grabbing bg-foreground" : "bg-background",+ !disabled && !dragging && "cursor-grab",+ "group-focus-visible/effort:ring-1 group-focus-visible/effort:ring-signal group-focus-visible/effort:ring-offset-1 group-focus-visible/effort:ring-offset-background",+ animate &&+ "transition-[left,background-color] duration-150 ease-out motion-reduce:transition-none",+ )}+ style={{ left: offsetFor(percent), width: THUMB_WIDTH_PX }}+ aria-hidden+ />+ )}</div></div>);