Skip to content
3 changes: 2 additions & 1 deletion apps/app/.ladle/story-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
ProviderCliStatus,
} from "@bb/host-daemon-contract";
import type { ProjectResponse } from "@bb/server-contract";
import { EMPTY_ORDERED_MENTION_SUGGESTIONS } from "@bb/client-core";
import { getProviderIconInfo } from "../src/lib/provider-icon";
import type { PickerOption } from "../src/components/pickers/OptionPicker";
import type { ModelPickerOption } from "../src/components/pickers/model-picker-option";
Expand Down Expand Up @@ -60,7 +61,7 @@ export function makeTypeaheadConfig(
commandOverrides: Partial<TypeaheadCommandConfig> = {},
): TypeaheadConfig {
const mention: TypeaheadMentionConfig = {
suggestions: [],
results: EMPTY_ORDERED_MENTION_SUGGESTIONS,
isLoading: false,
isError: false,
onQueryChange: noop,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
formatEnvironmentDisplay,
type EnvironmentDisplayHostContext,
} from "@bb/core-ui";
import { EMPTY_ORDERED_MENTION_SUGGESTIONS } from "@bb/client-core";
import type {
SystemExecutionOptionsModelLoadError,
ThreadContextWindowUsage,
Expand Down Expand Up @@ -284,7 +285,7 @@ const usage: ThreadContextWindowUsage = {

const typeaheadBase: TypeaheadConfig = {
mention: {
suggestions: [],
results: EMPTY_ORDERED_MENTION_SUGGESTIONS,
isLoading: false,
isError: false,
onQueryChange: noop,
Expand Down
3 changes: 2 additions & 1 deletion apps/app/src/components/promptbox/FollowUpPromptBox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { Profiler, startTransition, type ReactNode } from "react";
import { flushSync } from "react-dom";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { EMPTY_ORDERED_MENTION_SUGGESTIONS } from "@bb/client-core";
import {
resetPluginSlotStoreForTest,
setPluginSlotRegistrations,
Expand Down Expand Up @@ -243,7 +244,7 @@ function createFollowUpPromptBoxProps(
},
typeahead: {
mention: {
suggestions: [],
results: EMPTY_ORDERED_MENTION_SUGGESTIONS,
isLoading: false,
isError: false,
onQueryChange: vi.fn(),
Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/components/promptbox/NewThreadComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ export function NewThreadComposer({
typeahead={{
mention: {
triggers: promptMentions.triggers,
suggestions: promptMentions.suggestions,
results: promptMentions.results,
isLoading: promptMentions.isLoading,
isError: promptMentions.isError,
onQueryChange: promptMentions.setQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { act, cleanup, render, screen } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { afterEach, describe, expect, it, vi } from "vitest";
import { defaultAppSettings, type AppShortcut } from "@bb/domain";
import { EMPTY_ORDERED_MENTION_SUGGESTIONS } from "@bb/client-core";
import {
AppCommandProvider,
useAppCommandHandler,
Expand Down Expand Up @@ -119,7 +120,7 @@ function renderComposer(extra: React.ReactNode = null) {
mentionMenuPlacement="bottom"
typeahead={{
mention: {
suggestions: [],
results: EMPTY_ORDERED_MENTION_SUGGESTIONS,
isLoading: false,
isError: false,
onQueryChange: vi.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ vi.hoisted(() => {
});

import type { PromptTextMention } from "@bb/domain";
import { EMPTY_ORDERED_MENTION_SUGGESTIONS } from "@bb/client-core";
import { useState } from "react";
import {
act,
Expand Down Expand Up @@ -91,7 +92,7 @@ describe("PromptBoxInternal on a real iPadOS ProseMirror build", () => {
mentionMenuPlacement="bottom"
typeahead={{
mention: {
suggestions: [],
results: EMPTY_ORDERED_MENTION_SUGGESTIONS,
isLoading: false,
isError: false,
onQueryChange: vi.fn(),
Expand Down Expand Up @@ -156,7 +157,7 @@ describe("PromptBoxInternal on a real iPadOS ProseMirror build", () => {
mentionMenuPlacement="bottom"
typeahead={{
mention: {
suggestions: [],
results: EMPTY_ORDERED_MENTION_SUGGESTIONS,
isLoading: false,
isError: false,
onQueryChange: vi.fn(),
Expand Down Expand Up @@ -193,7 +194,7 @@ describe("PromptBoxInternal on a real iPadOS ProseMirror build", () => {
mentionMenuPlacement="bottom"
typeahead={{
mention: {
suggestions: [],
results: EMPTY_ORDERED_MENTION_SUGGESTIONS,
isLoading: false,
isError: false,
onQueryChange: vi.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
makeExecutionControlsProps,
makeTypeaheadConfig as makeTypeahead,
} from "../../../.ladle/story-fixtures";
import { orderPromptMentionSuggestions } from "@/hooks/promptMentionCandidates";

export default {
title: "promptbox/Prompt Box Internal",
Expand Down Expand Up @@ -817,7 +818,10 @@ function WithLiveMentionsRow() {
onSubmit={noop}
placeholder="Type @ to mention a file, folder, section, or thread"
typeahead={makeTypeahead({
suggestions,
results: orderPromptMentionSuggestions({
query: query ?? "",
suggestions,
}),
onQueryChange: setQuery,
})}
mentionMenuPlacement="bottom"
Expand Down
19 changes: 13 additions & 6 deletions apps/app/src/components/promptbox/PromptBoxInternal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import {
} from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { MemoryRouter } from "react-router-dom";
import { emptyPromptDraftState } from "@bb/client-core";
import {
EMPTY_ORDERED_MENTION_SUGGESTIONS,
emptyPromptDraftState,
} from "@bb/client-core";
import {
getComposerInputLock,
useComposer,
Expand Down Expand Up @@ -66,6 +69,7 @@ import {
type TypeaheadConfig,
} from "./PromptBoxInternal";
import { promptMentionClipboardContent } from "./mentions/prompt-mention-clipboard";
import { orderPromptMentionSuggestions } from "@/hooks/promptMentionCandidates";
import type {
PromptMentionSuggestion,
ProviderCommandSuggestion,
Expand Down Expand Up @@ -123,7 +127,7 @@ function createPromptBoxProps(
mentionMenuPlacement: "bottom",
typeahead: {
mention: {
suggestions: [],
results: EMPTY_ORDERED_MENTION_SUGGESTIONS,
isLoading: false,
isError: false,
onQueryChange: vi.fn(),
Expand All @@ -142,15 +146,18 @@ function buildTypeaheadConfig({
onCommandQueryChange = () => {},
}: {
mentionTriggers?: TypeaheadConfig["mention"]["triggers"];
mentionSuggestions?: TypeaheadConfig["mention"]["suggestions"];
mentionSuggestions?: readonly PromptMentionSuggestion[];
onMentionQueryChange?: TypeaheadConfig["mention"]["onQueryChange"];
commandSuggestions?: TypeaheadConfig["command"]["suggestions"];
onCommandQueryChange?: (query: string | null) => void;
} = {}): TypeaheadConfig {
return {
mention: {
triggers: mentionTriggers,
suggestions: mentionSuggestions,
results: orderPromptMentionSuggestions({
query: "",
suggestions: mentionSuggestions,
}),
isLoading: false,
isError: false,
onQueryChange: onMentionQueryChange,
Expand Down Expand Up @@ -269,7 +276,7 @@ function renderPromptBox(
options: {
initialMentionRanges?: PromptTextMention[];
mentionTriggers?: TypeaheadConfig["mention"]["triggers"];
mentionSuggestions?: TypeaheadConfig["mention"]["suggestions"];
mentionSuggestions?: readonly PromptMentionSuggestion[];
commandSuggestions?: TypeaheadConfig["command"]["suggestions"];
} = {},
) {
Expand Down Expand Up @@ -3721,7 +3728,7 @@ describe("PromptBoxInternal command typeahead submit", () => {
onSubmit={onSubmit}
typeahead={{
mention: {
suggestions: [],
results: EMPTY_ORDERED_MENTION_SUGGESTIONS,
isLoading: false,
isError: false,
onQueryChange: () => {},
Expand Down
11 changes: 6 additions & 5 deletions apps/app/src/components/promptbox/PromptBoxInternal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
type CommandMenuState,
type ComposerCommandSuggestion,
type MentionMenuState,
type OrderedMentionSuggestions,
type ProviderCommandSuggestion,
type PromptMentionSuggestion,
type TypeaheadMenuState,
Expand Down Expand Up @@ -278,7 +279,7 @@ function PromptSubmitButton({

export interface TypeaheadMentionConfig {
triggers?: readonly PluginMentionTrigger[];
suggestions: readonly PromptMentionSuggestion[];
results: OrderedMentionSuggestions;
isLoading: boolean;
isError: boolean;
onQueryChange: (
Expand Down Expand Up @@ -1127,7 +1128,7 @@ export function PromptBoxInternal({
} = submission;
const {
triggers: mentionTriggerChars = DEFAULT_TYPEAHEAD_MENTION_TRIGGERS,
suggestions: mentionSuggestions,
results: mentionResults,
isLoading: mentionLoading,
isError: mentionError,
onQueryChange: onMentionQueryChange,
Expand Down Expand Up @@ -2037,9 +2038,9 @@ export function PromptBoxInternal({
activeTriggerKind === "command"
? orderedCommandSuggestions
: activeTriggerKind === "mention"
? mentionSuggestions
? mentionResults.suggestions
: [],
[activeTriggerKind, mentionSuggestions, orderedCommandSuggestions],
[activeTriggerKind, mentionResults.suggestions, orderedCommandSuggestions],
);

const activeMentionQuery =
Expand All @@ -2051,7 +2052,7 @@ export function PromptBoxInternal({
? { kind: "loading" }
: mentionError
? { kind: "error" }
: { kind: "results", suggestions: mentionSuggestions };
: { kind: "results", results: mentionResults };

const commandMenuState: CommandMenuState = commandLoading
? { kind: "loading" }
Expand Down
Loading
Loading