+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
275 lines
8.6 KiB
TypeScript
275 lines
8.6 KiB
TypeScript
import {
|
|
formatProviderSkillDisplayName,
|
|
resolveProviderSkillSourceKind,
|
|
type ProviderSkillSourceKind,
|
|
} from "@t3tools/client-runtime/providerSkills";
|
|
import {
|
|
type ProjectEntry,
|
|
type ProviderDriverKind,
|
|
type PullRequestContextMetadata,
|
|
type ScopedThreadRef,
|
|
type ServerProviderSkill,
|
|
type ServerProviderSlashCommand,
|
|
} from "@t3tools/contracts";
|
|
import {
|
|
BlocksIcon,
|
|
FolderIcon,
|
|
MessagesSquareIcon,
|
|
PackageIcon,
|
|
SettingsIcon,
|
|
UserRoundIcon,
|
|
type LucideIcon,
|
|
} from "lucide-react";
|
|
import { memo, useLayoutEffect, useRef } from "react";
|
|
|
|
import { type ComposerSlashCommand, type ComposerTriggerKind } from "../../composer-logic";
|
|
import { cn } from "~/lib/utils";
|
|
import { Badge } from "../ui/badge";
|
|
import { Command, CommandGroup, CommandItem, CommandList } from "../ui/command";
|
|
import { PierreEntryIcon } from "./PierreEntryIcon";
|
|
import { ComposerBanner } from "./ComposerBanner";
|
|
import { resolvePullRequestState } from "../pullRequest/pullRequestPresentation";
|
|
|
|
export type ComposerCommandItem =
|
|
| {
|
|
id: string;
|
|
type: "path";
|
|
path: string;
|
|
pathKind: ProjectEntry["kind"];
|
|
label: string;
|
|
description: string;
|
|
}
|
|
| {
|
|
id: string;
|
|
type: "slash-command";
|
|
command: ComposerSlashCommand;
|
|
label: string;
|
|
description: string;
|
|
}
|
|
| {
|
|
id: string;
|
|
type: "provider-slash-command";
|
|
provider: ProviderDriverKind;
|
|
command: ServerProviderSlashCommand;
|
|
label: string;
|
|
description: string;
|
|
}
|
|
| {
|
|
id: string;
|
|
type: "skill";
|
|
provider: ProviderDriverKind;
|
|
skill: ServerProviderSkill;
|
|
label: string;
|
|
description: string;
|
|
}
|
|
| {
|
|
id: string;
|
|
type: "pull-request";
|
|
pullRequest: PullRequestContextMetadata;
|
|
label: string;
|
|
description: string;
|
|
}
|
|
| {
|
|
id: string;
|
|
type: "thread";
|
|
thread: ScopedThreadRef;
|
|
label: string;
|
|
description: string;
|
|
};
|
|
|
|
export const ComposerCommandMenu = memo(function ComposerCommandMenu(props: {
|
|
listId: string;
|
|
items: ComposerCommandItem[];
|
|
resolvedTheme: "light" | "dark";
|
|
isLoading: boolean;
|
|
triggerKind: ComposerTriggerKind | null;
|
|
emptyStateText?: string;
|
|
activeItemId: string | null;
|
|
onHighlightedItemChange: (itemId: string | null) => void;
|
|
onSelect: (item: ComposerCommandItem) => void;
|
|
}) {
|
|
const listRef = useRef<HTMLDivElement>(null);
|
|
|
|
useLayoutEffect(() => {
|
|
if (!props.activeItemId || !listRef.current) return;
|
|
const el = listRef.current.querySelector<HTMLElement>(
|
|
`[data-composer-item-id="${CSS.escape(props.activeItemId)}"]`,
|
|
);
|
|
el?.scrollIntoView({ block: "nearest" });
|
|
}, [props.activeItemId]);
|
|
|
|
return (
|
|
<Command
|
|
autoHighlight={false}
|
|
mode="none"
|
|
onItemHighlighted={(highlightedValue) => {
|
|
props.onHighlightedItemChange(
|
|
typeof highlightedValue === "string" ? highlightedValue : null,
|
|
);
|
|
}}
|
|
>
|
|
<ComposerBanner.Surface
|
|
ref={listRef}
|
|
className="flex min-h-0 w-full flex-col overflow-hidden pb-(--chat-composer-attachment-overlap) **:data-[slot=scroll-area-scrollbar]:data-[orientation=vertical]:my-4"
|
|
data-composer-command-drawer="true"
|
|
>
|
|
{props.items.length > 0 ? (
|
|
<CommandList
|
|
id={props.listId}
|
|
aria-label={props.triggerKind ? LISTBOX_LABEL_BY_TRIGGER[props.triggerKind] : undefined}
|
|
className="max-h-72 min-h-0 scroll-pb-6"
|
|
>
|
|
<CommandGroup>
|
|
{props.items.map((item) => (
|
|
<ComposerCommandMenuItem
|
|
key={item.id}
|
|
optionId={composerSuggestionOptionId(props.listId, item.id)}
|
|
item={item}
|
|
triggerKind={props.triggerKind}
|
|
resolvedTheme={props.resolvedTheme}
|
|
isActive={props.activeItemId === item.id}
|
|
onHighlight={props.onHighlightedItemChange}
|
|
onSelect={props.onSelect}
|
|
/>
|
|
))}
|
|
</CommandGroup>
|
|
</CommandList>
|
|
) : (
|
|
<div className="px-5 pt-3.5 pb-7">
|
|
<p className="text-secondary-label text-xs">
|
|
{props.isLoading
|
|
? props.triggerKind === "skill"
|
|
? "Searching workspace skills..."
|
|
: props.triggerKind === "pull-request"
|
|
? "Finding pull request..."
|
|
: "Searching workspace files..."
|
|
: (props.emptyStateText ??
|
|
(props.triggerKind === "skill"
|
|
? "No skills found. Try / to browse provider commands."
|
|
: props.triggerKind === "path"
|
|
? "No matching files or folders."
|
|
: "No matching command."))}
|
|
</p>
|
|
</div>
|
|
)}
|
|
</ComposerBanner.Surface>
|
|
</Command>
|
|
);
|
|
});
|
|
|
|
const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: {
|
|
optionId: string;
|
|
item: ComposerCommandItem;
|
|
triggerKind: ComposerTriggerKind | null;
|
|
resolvedTheme: "light" | "dark";
|
|
isActive: boolean;
|
|
onHighlight: (itemId: string | null) => void;
|
|
onSelect: (item: ComposerCommandItem) => void;
|
|
}) {
|
|
const skillSourceKind =
|
|
props.item.type === "skill" ? resolveProviderSkillSourceKind(props.item.skill) : null;
|
|
const isSlashSkill =
|
|
props.triggerKind === "slash-command" && props.item.type === "skill" ? props.item.skill : null;
|
|
const pullRequestPresentation =
|
|
props.item.type === "pull-request" ? resolvePullRequestState(props.item.pullRequest) : null;
|
|
|
|
return (
|
|
<CommandItem
|
|
render={<div id={props.optionId} />}
|
|
aria-selected={props.isActive}
|
|
value={props.item.id}
|
|
data-composer-item-id={props.item.id}
|
|
active={props.isActive}
|
|
onMouseMove={() => {
|
|
if (!props.isActive) props.onHighlight(props.item.id);
|
|
}}
|
|
onMouseDown={(event) => {
|
|
event.preventDefault();
|
|
}}
|
|
onClick={() => {
|
|
props.onSelect(props.item);
|
|
}}
|
|
>
|
|
{props.item.type === "path" ? (
|
|
<PierreEntryIcon
|
|
pathValue={props.item.path}
|
|
kind={props.item.pathKind}
|
|
theme={props.resolvedTheme}
|
|
/>
|
|
) : null}
|
|
{props.item.type === "thread" ? (
|
|
<MessagesSquareIcon aria-hidden="true" className="size-4 shrink-0 text-secondary-label" />
|
|
) : null}
|
|
{pullRequestPresentation ? (
|
|
<pullRequestPresentation.Icon
|
|
role="img"
|
|
aria-label={pullRequestPresentation.label}
|
|
className={cn("size-4 shrink-0", pullRequestPresentation.toneClassName)}
|
|
/>
|
|
) : null}
|
|
<span className="flex min-w-0 flex-1 items-center gap-2">
|
|
<span className="min-w-0 max-w-[45%] shrink-0 truncate font-sans text-xs font-medium">
|
|
{isSlashSkill ? (
|
|
<>
|
|
<span className="text-secondary-label">/skill:</span>
|
|
{formatProviderSkillDisplayName(isSlashSkill)}
|
|
</>
|
|
) : (
|
|
props.item.label
|
|
)}
|
|
</span>
|
|
<span className="min-w-0 flex-1 truncate text-left text-secondary-label text-xs">
|
|
{props.item.description}
|
|
</span>
|
|
{skillSourceKind ? (
|
|
<SkillSourceBadge
|
|
kind={skillSourceKind}
|
|
showSkillSuffix={props.triggerKind === "skill"}
|
|
/>
|
|
) : null}
|
|
</span>
|
|
</CommandItem>
|
|
);
|
|
});
|
|
|
|
export function composerSuggestionOptionId(listId: string, itemId: string): string {
|
|
// JSON escapes lone UTF-16 surrogates before URI encoding without losing identity.
|
|
return `${listId}-${encodeURIComponent(JSON.stringify(itemId))}`;
|
|
}
|
|
|
|
const LISTBOX_LABEL_BY_TRIGGER: Record<ComposerTriggerKind, string> = {
|
|
path: "Files and folders",
|
|
"pull-request": "Pull requests",
|
|
"slash-command": "Commands",
|
|
skill: "Skills",
|
|
};
|
|
|
|
const SKILL_SOURCE_ICON_BY_KIND: Record<ProviderSkillSourceKind, LucideIcon> = {
|
|
app: BlocksIcon,
|
|
repo: FolderIcon,
|
|
project: FolderIcon,
|
|
personal: UserRoundIcon,
|
|
system: SettingsIcon,
|
|
other: PackageIcon,
|
|
};
|
|
|
|
const SKILL_SOURCE_LABEL_BY_KIND: Record<ProviderSkillSourceKind, string> = {
|
|
app: "App",
|
|
repo: "Repo",
|
|
project: "Project",
|
|
personal: "Personal",
|
|
system: "System",
|
|
other: "Provider",
|
|
};
|
|
|
|
function SkillSourceBadge(props: { kind: ProviderSkillSourceKind; showSkillSuffix: boolean }) {
|
|
const Icon = SKILL_SOURCE_ICON_BY_KIND[props.kind];
|
|
return (
|
|
<Badge className="ms-auto" variant="secondary">
|
|
<Icon aria-hidden="true" className="text-current" />
|
|
{SKILL_SOURCE_LABEL_BY_KIND[props.kind]}
|
|
{props.showSkillSuffix ? " Skill" : null}
|
|
</Badge>
|
|
);
|
|
}
|