Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { Button } from '@ggml-org/llama-ui/ui/button';
import { SkipForward, Square } from '@lucide/svelte';
import {
ChatFormActionReasoning,
ChatFormActionRecord,
ChatFormActionsAdd,
ChatFormActionSubmit,
Expand Down Expand Up @@ -149,12 +148,12 @@
{/if}

{#if showModelSelector}
<ChatFormActionReasoning />

<!-- the reasoning effort sits in the model picker, under the models -->
<ModelsSelector
bind:this={selectorModelRef}
{disabled}
forceForegroundText
showReasoning
useGlobalSelection
/>
{/if}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<script lang="ts">
import ModelLoadHighlight from '../ModelLoadHighlight.svelte';
import ModelsSelectorReasoning from './ModelsSelectorReasoning.svelte';
import ModelsSelectorReasoningBadge from './ModelsSelectorReasoningBadge.svelte';
import * as Tooltip from '@ggml-org/llama-ui/ui/tooltip';
import { ChevronDown, Loader2 } from '@lucide/svelte';
import {
ChatFormActionReasoning,
ModelId,
ModelsSelectorDrawer,
ModelsSelectorDropdown,
Expand Down Expand Up @@ -34,6 +37,8 @@
disabled?: boolean;
forceForegroundText?: boolean;
onModelChange?: (modelId: string, modelName: string) => Promise<boolean> | boolean | void;
/** The chat's reasoning effort at the foot of the picker (the chat form's selector). */
showReasoning?: boolean;
useGlobalSelection?: boolean;
}

Expand All @@ -42,6 +47,7 @@
disabled = false,
forceForegroundText = false,
onModelChange,
showReasoning = false,
useGlobalSelection = false
}: Props = $props();

Expand Down Expand Up @@ -229,6 +235,11 @@
hideQuantization
modelId={selectedOption.model}
/>

<!-- in the model's column: the trigger is a grid of icon, model and chevron -->
{#if showReasoning}
<ModelsSelectorReasoningBadge />
{/if}
{:else}
<span class="min-w-0 font-medium">Select model</span>
{/if}
Expand Down Expand Up @@ -268,6 +279,10 @@
/>
{/snippet}

{#snippet reasoningFooter()}
<ModelsSelectorReasoning variant="list" />
{/snippet}

{#snippet pickerList(listClass: string)}
<div class={['models-list', listClass]}>
{#if !ms.isCurrentModelInCache && displayModel}
Expand Down Expand Up @@ -341,6 +356,7 @@
<ModelsSelectorDrawer
bind:open={isOpen}
emptyMessage={ms.emptyMessage}
footer={showReasoning ? reasoningFooter : undefined}
isEmpty={ms.isEmpty && ms.isCurrentModelInCache}
onOpenChange={ms.handleOpenChange}
onSearchChange={(v) => ms.setSearchTerm(v)}
Expand All @@ -360,6 +376,7 @@
onModelKeyAction={(id, unload) => void handleModelKeyAction(id, unload)}
onSearchKeyDown={handleSearchKeyDown}
{showOrgName}
{showReasoning}
/>
{/if}
{:else if isMobile}
Expand All @@ -378,6 +395,7 @@
<ModelsSelectorDrawer
bind:open={isOpen}
emptyMessage={ms.emptyMessage}
footer={showReasoning ? reasoningFooter : undefined}
isEmpty={ms.isEmpty && ms.isCurrentModelInCache}
onOpenChange={ms.handleOpenChange}
onSearchChange={(v) => ms.setSearchTerm(v)}
Expand Down Expand Up @@ -434,4 +452,9 @@
{/snippet}
</Tooltip.Trigger>
</Tooltip.Root>

<!-- a lone model has no picker to hold the reasoning effort: it keeps its own button -->
{#if showReasoning}
<ChatFormActionReasoning />
{/if}
{/if}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script lang="ts">
import ModelLoadHighlight from '../ModelLoadHighlight.svelte';
import ModelsSelectorReasoning from './ModelsSelectorReasoning.svelte';
import ModelsSelectorReasoningBadge from './ModelsSelectorReasoningBadge.svelte';
import * as DropdownMenu from '@ggml-org/llama-ui/ui/dropdown-menu';
import * as Tooltip from '@ggml-org/llama-ui/ui/tooltip';
import { ChevronDown, Loader2 } from '@lucide/svelte';
Expand Down Expand Up @@ -33,6 +35,8 @@
onManageModels?: () => void;
onModelKeyAction?: (modelId: string, unload: boolean) => void;
onSearchKeyDown?: (event: KeyboardEvent) => void;
/** The chat's reasoning effort in place of the manager entry at the foot. */
showReasoning?: boolean;
}

let {
Expand All @@ -45,7 +49,8 @@
onModelKeyAction,
onSearchKeyDown,
open = $bindable(false),
showOrgName = true
showOrgName = true,
showReasoning = false
}: Props = $props();

const selectedOption = $derived(ms.getDisplayOption());
Expand Down Expand Up @@ -107,6 +112,11 @@
hideQuantization
modelId={selectedOption.model}
/>

<!-- in the model's column: the trigger is a grid of icon, model and chevron -->
{#if showReasoning}
<ModelsSelectorReasoningBadge />
{/if}
{:else}
<span class="min-w-0 font-medium">Select model</span>
{/if}
Expand Down Expand Up @@ -178,7 +188,7 @@
<!-- the details drawer opens over the menu: the menu stays open under its backdrop -->
<DropdownMenu.Content
align="end"
class="w-full md:min-w-80 md:w-md max-w-[calc(100vw-2rem)] p-0! max-h-[min(40rem,calc(var(--bits-dropdown-menu-content-available-height)-1rem))]"
class="flex w-full flex-col overflow-hidden md:min-w-80 md:w-md max-w-[calc(100vw-2rem)] p-0! max-h-[min(40rem,calc(var(--bits-dropdown-menu-content-available-height)-1rem))]"
data-under-details={uiStore.isModelDetailsOpen || undefined}
onCloseAutoFocus={(event) => {
// bits-ui re-mounts the focus scope when the drawer opens or closes, so this runs with the menu still open; trigger focus would show its tooltip
Expand All @@ -194,30 +204,36 @@
>
<DropdownMenuSearchable
emptyMessage={ms.emptyMessage}
footer={uiStore.isModelsManagerShown ? manageModelsFooter : undefined}
footer={showReasoning || uiStore.isModelsManagerShown ? pickerFooter : undefined}
isEmpty={ms.isEmpty && ms.isCurrentModelInCache}
onSearchChange={(v) => ms.setSearchTerm(v)}
{onSearchKeyDown}
placeholder="Search models..."
scrollport
searchClass="bg-transparent"
searchValue={ms.searchTerm}
>
<!-- Option list; the search header sticks to the top and the actions
footer to the bottom of the content scrollport. -->
<!-- Option list; the search header sticks to the top of the list's scrollport, and
the footer stays under it. -->
{@render pickerContent('px-1.5')}
</DropdownMenuSearchable>
</DropdownMenu.Content>
</DropdownMenu.Root>

<!-- the way into the full manager, so it hides with the manager's other entry points -->
{#snippet manageModelsFooter()}
<DropdownMenu.Group class="px-2">
<DropdownMenu.Item class="gap-2" onSelect={handleManageModels}>
<MODEL_ICON class="size-icon-md shrink-0 text-muted-foreground" />
<!-- the reasoning effort when the model has one; otherwise the way into the full manager, which hides with the
manager's other entry points -->
{#snippet pickerFooter()}
{#if showReasoning}
<ModelsSelectorReasoning />
{:else}
<DropdownMenu.Group class="px-2">
<DropdownMenu.Item class="gap-2" onSelect={handleManageModels}>
<MODEL_ICON class="size-icon-md shrink-0 text-muted-foreground" />

Manage models
</DropdownMenu.Item>
</DropdownMenu.Group>
Manage models
</DropdownMenu.Item>
</DropdownMenu.Group>
{/if}
{/snippet}

{#snippet pickerContent(listClass: string)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!--
The chat's reasoning effort, at the foot of the model picker: one row with the level in use, which opens the levels
under it, sliding open and shut (CollapsibleSection). `menu` is the desktop dropdown's (its rows are menu items),
`list` the phone drawer's.
-->
<script lang="ts">
import * as DropdownMenu from '@ggml-org/llama-ui/ui/dropdown-menu';
import { Check, Lightbulb, LightbulbOff } from '@lucide/svelte';
import { CollapsibleSection } from '#lib/components/app/index.ts';
import { ICON_CLASS_DEFAULT, REASONING_EFFORT_LABELS } from '#lib/constants/index.ts';
import { useReasoningMenu } from '#lib/hooks/use-reasoning-menu.svelte.ts';
import type { ReasoningEffortLevel } from '#lib/types/index.ts';

interface Props {
variant?: 'menu' | 'list';
}

let { variant = 'menu' }: Props = $props();

const reasoning = useReasoningMenu();

let current = $derived(REASONING_EFFORT_LABELS[reasoning.currentEffort]);
</script>

{#snippet header()}
{#if reasoning.isOff}
<LightbulbOff class="size-icon-md shrink-0 text-muted-foreground" />
{:else}
<Lightbulb class="size-icon-md shrink-0 text-muted-foreground" />
{/if}

<span class="flex-1">Reasoning</span>

<span class="text-xs text-muted-foreground">{current}</span>
{/snippet}

{#snippet levelLabel(level: ReasoningEffortLevel)}
{@const tokenLabel = reasoning.tokenLabel(level)}

{#if reasoning.isSelected(level)}
<Check class="{ICON_CLASS_DEFAULT} shrink-0 text-foreground" />
{:else}
<div class="{ICON_CLASS_DEFAULT} shrink-0"></div>
{/if}

<span class="min-w-0 flex-1 truncate">{level.label}</span>

{#if tokenLabel}
<span class="shrink-0 text-[11px] text-muted-foreground opacity-60">{tokenLabel}</span>
{/if}
{/snippet}

{#if variant === 'menu'}
<DropdownMenu.Group class="px-2" data-slot="models-selector-reasoning">
<!-- its row is a menu item that opens the levels without closing the menu -->
<CollapsibleSection defaultOpen={false} inMenu trigger={header}>
<div class="flex flex-col">
{#each reasoning.levels as level (level.value)}
<DropdownMenu.Item class="gap-3 pl-4" onSelect={() => reasoning.select(level)}>
{@render levelLabel(level)}
</DropdownMenu.Item>
{/each}
</div>
</CollapsibleSection>
</DropdownMenu.Group>
{:else}
<div class="flex flex-col px-2 pt-1" data-slot="models-selector-reasoning">
<CollapsibleSection
defaultOpen={false}
trigger={header}
triggerClass="flex min-h-11 w-full cursor-pointer items-center gap-2 rounded-md px-3 text-left text-sm transition-colors hover:bg-accent"
>
<div class="flex flex-col">
{#each reasoning.levels as level (level.value)}
<button
aria-pressed={reasoning.isSelected(level)}
class="flex min-h-11 w-full cursor-pointer items-center gap-3 rounded-md pr-3 pl-6 text-left text-sm transition-colors hover:bg-accent"
onclick={() => reasoning.select(level)}
type="button"
>
{@render levelLabel(level)}
</button>
{/each}
</div>
</CollapsibleSection>
</div>
{/if}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--
The chat's reasoning effort on the closed model selector, next to the model: the level as a word when it is set to
one, a crossed-out lightbulb when reasoning is off, and nothing at the default, which leaves it to the model.
-->
<script lang="ts">
import { LightbulbOff } from '@lucide/svelte';
import { REASONING_EFFORT_LABELS } from '#lib/constants/index.ts';
import { ReasoningEffort } from '#lib/enums/index.ts';
import { useReasoningMenu } from '#lib/hooks/use-reasoning-menu.svelte.ts';

const reasoning = useReasoningMenu();
</script>

{#if reasoning.isOff}
<span
class="ml-1 flex shrink-0 items-center text-muted-foreground"
data-slot="models-selector-reasoning-badge"
title="Reasoning: Off"
>
<LightbulbOff aria-hidden="true" class="size-icon-xs max-md:size-icon-sm shrink-0" />

<span class="sr-only">Reasoning off</span>
</span>
{:else if reasoning.currentEffort !== ReasoningEffort.DEFAULT}
<span
class="ml-1 shrink-0 text-muted-foreground"
data-slot="models-selector-reasoning-badge"
title="Reasoning: {REASONING_EFFORT_LABELS[reasoning.currentEffort]}"
>
<span aria-hidden="true">{REASONING_EFFORT_LABELS[reasoning.currentEffort]}</span>

<span class="sr-only">Reasoning {REASONING_EFFORT_LABELS[reasoning.currentEffort]}</span>
</span>
{/if}
Loading
Loading