Merge origin/main into t3code/mobile-remote-connect

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-05-07 21:48:25 -07:00
commit b357476e71
216 files changed
+18189 -9661

No files matched your search

+18 -1
View File
@@ -1,5 +1,6 @@
import { DiffsHighlighter, getSharedHighlighter, SupportedLanguages } from "@pierre/diffs";
import { CheckIcon, CopyIcon } from "lucide-react";
import type { ServerProviderSkill } from "@t3tools/contracts";
import React, {
Children,
Suspense,
@@ -19,6 +20,7 @@ import ReactMarkdown from "react-markdown";
import { defaultUrlTransform } from "react-markdown";
import remarkGfm from "remark-gfm";
import { VscodeEntryIcon } from "./chat/VscodeEntryIcon";
import { renderSkillInlineMarkdownChildren } from "./chat/SkillInlineText";
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
import { stackedThreadToast, toastManager } from "./ui/toast";
import { openInPreferredEditor } from "../editorPreferences";
@@ -59,8 +61,11 @@ interface ChatMarkdownProps {
text: string;
cwd: string | undefined;
isStreaming?: boolean;
skills?: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
}
const EMPTY_MARKDOWN_SKILLS: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">> = [];
const CODE_FENCE_LANGUAGE_REGEX = /(?:^|\s)language-([^\s]+)/;
const MAX_HIGHLIGHT_CACHE_ENTRIES = 500;
const MAX_HIGHLIGHT_CACHE_MEMORY_BYTES = 50 * 1024 * 1024;
@@ -507,7 +512,12 @@ function areMarkdownFileLinkPropsEqual(
);
}
function ChatMarkdown({ text, cwd, isStreaming = false }: ChatMarkdownProps) {
function ChatMarkdown({
text,
cwd,
isStreaming = false,
skills = EMPTY_MARKDOWN_SKILLS,
}: ChatMarkdownProps) {
const { resolvedTheme } = useTheme();
const diffThemeName = resolveDiffThemeName(resolvedTheme);
const markdownFileLinkMetaByHref = useMemo(() => {
@@ -534,6 +544,12 @@ function ChatMarkdown({ text, cwd, isStreaming = false }: ChatMarkdownProps) {
}, []);
const markdownComponents = useMemo<Components>(
() => ({
p({ node: _node, children, ...props }) {
return <p {...props}>{renderSkillInlineMarkdownChildren(children, skills)}</p>;
},
li({ node: _node, children, ...props }) {
return <li {...props}>{renderSkillInlineMarkdownChildren(children, skills)}</li>;
},
a({ node: _node, href, ...props }) {
const normalizedHref = href ? normalizeMarkdownLinkHrefKey(href) : "";
const fileLinkMeta = normalizedHref ? markdownFileLinkMetaByHref.get(normalizedHref) : null;
@@ -592,6 +608,7 @@ function ChatMarkdown({ text, cwd, isStreaming = false }: ChatMarkdownProps) {
isStreaming,
markdownFileLinkMetaByHref,
resolvedTheme,
skills,
],
);
+2
View File
@@ -197,6 +197,7 @@ const IMAGE_ONLY_BOOTSTRAP_PROMPT =
const EMPTY_ACTIVITIES: OrchestrationThreadActivity[] = [];
const EMPTY_PROPOSED_PLANS: Thread["proposedPlans"] = [];
const EMPTY_PROVIDERS: ServerProvider[] = [];
const EMPTY_PROVIDER_SKILLS: ServerProvider["skills"] = [];
const EMPTY_PENDING_USER_INPUT_ANSWERS: Record<string, PendingUserInputDraftAnswer> = {};
type EnvironmentUnavailableState = {
readonly environmentId: EnvironmentId;
@@ -3801,6 +3802,7 @@ export default function ChatView(props: ChatViewProps) {
resolvedTheme={resolvedTheme}
timestampFormat={timestampFormat}
workspaceRoot={activeWorkspaceRoot}
skills={activeProviderStatus?.skills ?? EMPTY_PROVIDER_SKILLS}
onIsAtEndChange={onIsAtEndChange}
/>
@@ -72,6 +72,7 @@ import {
COMPOSER_INLINE_CHIP_ICON_CLASS_NAME,
COMPOSER_INLINE_CHIP_LABEL_CLASS_NAME,
COMPOSER_INLINE_SKILL_CHIP_CLASS_NAME,
SKILL_CHIP_ICON_SVG,
} from "./composerInlineChip";
import { ComposerPendingTerminalContextChip } from "./chat/ComposerPendingTerminalContexts";
import { formatProviderSkillDisplayName } from "~/providerSkillPresentation";
@@ -216,8 +217,6 @@ function $createComposerMentionNode(path: string): ComposerMentionNode {
return $applyNodeReplacement(new ComposerMentionNode(path));
}
const SKILL_CHIP_ICON_SVG = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.85" stroke-linecap="round" stroke-linejoin="round"><path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"/><path d="m3.3 7 8.7 5 8.7-5"/><path d="M12 22V12"/></svg>`;
function resolveSkillDescription(
skill: Pick<ServerProviderSkill, "shortDescription" | "description">,
): string | null {
+94 -7
View File
@@ -54,7 +54,10 @@ import {
} from "@t3tools/client-runtime";
import { Link, useLocation, useNavigate, useParams, useRouter } from "@tanstack/react-router";
import {
MAX_SIDEBAR_THREAD_PREVIEW_COUNT,
MIN_SIDEBAR_THREAD_PREVIEW_COUNT,
type SidebarProjectSortOrder,
type SidebarThreadPreviewCount,
type SidebarThreadSortOrder,
} from "@t3tools/contracts/settings";
import { usePrimaryEnvironmentId } from "../environments/primary";
@@ -129,6 +132,13 @@ import {
MenuSeparator,
MenuTrigger,
} from "./ui/menu";
import {
NumberField,
NumberFieldDecrement,
NumberFieldGroup,
NumberFieldIncrement,
NumberFieldInput,
} from "./ui/number-field";
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "./ui/select";
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
import {
@@ -187,7 +197,6 @@ import {
type SidebarProjectSnapshot,
} from "../sidebarProjectGrouping";
import { SidebarProviderUpdatePill } from "./sidebar/SidebarProviderUpdatePill";
const THREAD_PREVIEW_LIMIT = 6;
const SIDEBAR_SORT_LABELS: Record<SidebarProjectSortOrder, string> = {
updated_at: "Last user message",
created_at: "Created at",
@@ -208,6 +217,13 @@ const PROJECT_GROUPING_MODE_LABELS: Record<SidebarProjectGroupingMode, string> =
separate: "Keep separate",
};
function clampSidebarThreadPreviewCount(value: number): SidebarThreadPreviewCount {
return Math.min(
MAX_SIDEBAR_THREAD_PREVIEW_COUNT,
Math.max(MIN_SIDEBAR_THREAD_PREVIEW_COUNT, value),
) as SidebarThreadPreviewCount;
}
function formatProjectMemberActionLabel(
member: SidebarProjectGroupMember,
groupedProjectCount: number,
@@ -937,6 +953,9 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
sidebarProjectGroupingOverrides: settings.sidebarProjectGroupingOverrides,
}));
const { updateSettings } = useUpdateSettings();
const sidebarThreadPreviewCount = useSettings<SidebarThreadPreviewCount>(
(settings) => settings.sidebarThreadPreviewCount,
);
const router = useRouter();
const { isMobile, setOpenMobile } = useSidebar();
const markThreadUnread = useUiStateStore((state) => state.markThreadUnread);
@@ -1160,11 +1179,11 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
},
});
};
const hasOverflowingThreads = visibleProjectThreads.length > THREAD_PREVIEW_LIMIT;
const hasOverflowingThreads = visibleProjectThreads.length > sidebarThreadPreviewCount;
const previewThreads =
isThreadListExpanded || !hasOverflowingThreads
? visibleProjectThreads
: visibleProjectThreads.slice(0, THREAD_PREVIEW_LIMIT);
: visibleProjectThreads.slice(0, sidebarThreadPreviewCount);
const visibleThreadKeys = new Set(
[...previewThreads, ...(pinnedCollapsedThread ? [pinnedCollapsedThread] : [])].map((thread) =>
scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
@@ -1193,6 +1212,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
pinnedCollapsedThread,
projectExpanded,
projectThreads,
sidebarThreadPreviewCount,
threadLastVisitedAts,
visibleProjectThreads,
]);
@@ -2254,17 +2274,35 @@ function ProjectSortMenu({
projectSortOrder,
threadSortOrder,
projectGroupingMode,
threadPreviewCount,
onProjectSortOrderChange,
onThreadSortOrderChange,
onProjectGroupingModeChange,
onThreadPreviewCountChange,
}: {
projectSortOrder: SidebarProjectSortOrder;
threadSortOrder: SidebarThreadSortOrder;
projectGroupingMode: SidebarProjectGroupingMode;
threadPreviewCount: SidebarThreadPreviewCount;
onProjectSortOrderChange: (sortOrder: SidebarProjectSortOrder) => void;
onThreadSortOrderChange: (sortOrder: SidebarThreadSortOrder) => void;
onProjectGroupingModeChange: (mode: SidebarProjectGroupingMode) => void;
onThreadPreviewCountChange: (count: SidebarThreadPreviewCount) => void;
}) {
const handleThreadPreviewCountChange = useCallback(
(nextValue: number | null) => {
if (nextValue === null) {
return;
}
const clampedValue = clampSidebarThreadPreviewCount(nextValue);
if (clampedValue !== threadPreviewCount) {
onThreadPreviewCountChange(clampedValue);
}
},
[onThreadPreviewCountChange, threadPreviewCount],
);
return (
<Menu>
<Tooltip>
@@ -2275,9 +2313,9 @@ function ProjectSortMenu({
>
<ArrowUpDownIcon className="size-3.5" />
</TooltipTrigger>
<TooltipPopup side="right">Sort projects</TooltipPopup>
<TooltipPopup side="right">Sidebar options</TooltipPopup>
</Tooltip>
<MenuPopup align="end" side="bottom" className="min-w-44">
<MenuPopup align="end" side="bottom" className="min-w-52">
<MenuGroup>
<div className="px-2 py-1 sm:text-xs font-medium text-muted-foreground">
Sort projects
@@ -2316,6 +2354,42 @@ function ProjectSortMenu({
))}
</MenuRadioGroup>
</MenuGroup>
<MenuGroup>
<div className="px-2 pt-2 pb-1 text-muted-foreground sm:text-xs font-medium">
Visible threads
</div>
<div className="px-2 py-1">
<NumberField
aria-label="Visible thread count"
className="w-28 gap-0"
max={MAX_SIDEBAR_THREAD_PREVIEW_COUNT}
min={MIN_SIDEBAR_THREAD_PREVIEW_COUNT}
onValueChange={handleThreadPreviewCountChange}
size="sm"
step={1}
value={threadPreviewCount}
>
<NumberFieldGroup className="h-7 rounded-md sm:h-6.5">
<NumberFieldDecrement
aria-label="Decrease visible thread count"
className="px-2 sm:px-2 [&_svg]:size-3.5"
/>
<NumberFieldInput
aria-label="Visible thread count"
className="h-7 w-9 grow-0 px-0 text-xs leading-7 sm:h-6.5 sm:leading-6.5"
inputMode="numeric"
onKeyDownCapture={(event) => {
event.stopPropagation();
}}
/>
<NumberFieldIncrement
aria-label="Increase visible thread count"
className="px-2 sm:px-2 [&_svg]:size-3.5"
/>
</NumberFieldGroup>
</NumberField>
</div>
</MenuGroup>
<MenuSeparator />
<MenuGroup>
<div className="px-2 pt-2 pb-1 font-medium text-muted-foreground sm:text-xs">
@@ -2463,6 +2537,7 @@ interface SidebarProjectsContentProps {
projectSortOrder: SidebarProjectSortOrder;
threadSortOrder: SidebarThreadSortOrder;
projectGroupingMode: SidebarProjectGroupingMode;
threadPreviewCount: SidebarThreadPreviewCount;
updateSettings: ReturnType<typeof useUpdateSettings>["updateSettings"];
openAddProject: () => void;
isManualProjectSorting: boolean;
@@ -2503,6 +2578,7 @@ const SidebarProjectsContent = memo(function SidebarProjectsContent(
projectSortOrder,
threadSortOrder,
projectGroupingMode,
threadPreviewCount,
updateSettings,
openAddProject,
isManualProjectSorting,
@@ -2549,6 +2625,12 @@ const SidebarProjectsContent = memo(function SidebarProjectsContent(
},
[updateSettings],
);
const handleThreadPreviewCountChange = useCallback(
(count: SidebarThreadPreviewCount) => {
updateSettings({ sidebarThreadPreviewCount: count });
},
[updateSettings],
);
return (
<SidebarContent className="gap-0">
@@ -2608,9 +2690,11 @@ const SidebarProjectsContent = memo(function SidebarProjectsContent(
projectSortOrder={projectSortOrder}
threadSortOrder={threadSortOrder}
projectGroupingMode={projectGroupingMode}
threadPreviewCount={threadPreviewCount}
onProjectSortOrderChange={handleProjectSortOrderChange}
onThreadSortOrderChange={handleThreadSortOrderChange}
onProjectGroupingModeChange={handleProjectGroupingModeChange}
onThreadPreviewCountChange={handleThreadPreviewCountChange}
/>
<Tooltip>
<TooltipTrigger
@@ -2730,6 +2814,7 @@ export default function Sidebar() {
sidebarProjectGroupingMode: settings.sidebarProjectGroupingMode,
sidebarProjectGroupingOverrides: settings.sidebarProjectGroupingOverrides,
}));
const sidebarThreadPreviewCount = useSettings((s) => s.sidebarThreadPreviewCount);
const { updateSettings } = useUpdateSettings();
const { handleNewThread } = useNewThreadHandler();
const { archiveThread, deleteThread } = useThreadActions();
@@ -3025,11 +3110,11 @@ export default function Sidebar() {
return [];
}
const isThreadListExpanded = expandedThreadListsByProject.has(project.projectKey);
const hasOverflowingThreads = projectThreads.length > THREAD_PREVIEW_LIMIT;
const hasOverflowingThreads = projectThreads.length > sidebarThreadPreviewCount;
const previewThreads =
isThreadListExpanded || !hasOverflowingThreads
? projectThreads
: projectThreads.slice(0, THREAD_PREVIEW_LIMIT);
: projectThreads.slice(0, sidebarThreadPreviewCount);
const renderedThreads = pinnedCollapsedThread ? [pinnedCollapsedThread] : previewThreads;
return renderedThreads.map((thread) =>
scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
@@ -3037,6 +3122,7 @@ export default function Sidebar() {
}),
[
sidebarThreadSortOrder,
sidebarThreadPreviewCount,
expandedThreadListsByProject,
projectExpandedById,
routeThreadKey,
@@ -3359,6 +3445,7 @@ export default function Sidebar() {
projectSortOrder={sidebarProjectSortOrder}
threadSortOrder={sidebarThreadSortOrder}
projectGroupingMode={sidebarProjectGroupingMode}
threadPreviewCount={sidebarThreadPreviewCount}
updateSettings={updateSettings}
openAddProject={openAddProjectCommandPalette}
isManualProjectSorting={isManualProjectSorting}
@@ -2267,7 +2267,7 @@ export const ChatComposer = memo(
}`
: phase === "disconnected"
? "Ask for follow-up changes or attach images"
: "Ask anything, @tag files/folders, or use / to show available commands"
: "Ask anything, @tag files/folders, $use skills, or / for commands"
}
disabled={
isConnecting ||
@@ -1,4 +1,9 @@
import { type EnvironmentId, type MessageId, type TurnId } from "@t3tools/contracts";
import {
type EnvironmentId,
type MessageId,
type ServerProviderSkill,
type TurnId,
} from "@t3tools/contracts";
import {
createContext,
memo,
@@ -61,6 +66,7 @@ import {
formatInlineTerminalContextLabel,
textContainsInlineTerminalContextLabels,
} from "./userMessageTerminalContexts";
import { SkillInlineText } from "./SkillInlineText";
import { formatWorkspaceRelativePath } from "../../filePathDisplay";
import {
buildFileDiffRenderKey,
@@ -88,6 +94,7 @@ interface TimelineRowSharedState {
markdownCwd: string | undefined;
resolvedTheme: "light" | "dark";
workspaceRoot: string | undefined;
skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
activeThreadEnvironmentId: EnvironmentId;
onRevertUserMessage: (messageId: MessageId) => void;
onImageExpand: (preview: ExpandedImagePreview) => void;
@@ -128,6 +135,7 @@ const REVIEW_COMMENT_DIFF_UNSAFE_CSS = `
color: var(--foreground) !important;
}
`;
const EMPTY_TIMELINE_SKILLS: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">> = [];
// ---------------------------------------------------------------------------
// Props (public API)
@@ -154,6 +162,7 @@ interface MessagesTimelineProps {
resolvedTheme: "light" | "dark";
timestampFormat: TimestampFormat;
workspaceRoot: string | undefined;
skills?: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
onIsAtEndChange: (isAtEnd: boolean) => void;
}
@@ -182,6 +191,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
resolvedTheme,
timestampFormat,
workspaceRoot,
skills = EMPTY_TIMELINE_SKILLS,
onIsAtEndChange,
}: MessagesTimelineProps) {
const rawRows = useMemo(
@@ -237,6 +247,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
markdownCwd,
resolvedTheme,
workspaceRoot,
skills,
activeThreadEnvironmentId,
onRevertUserMessage,
onImageExpand,
@@ -248,6 +259,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
markdownCwd,
resolvedTheme,
workspaceRoot,
skills,
activeThreadEnvironmentId,
onRevertUserMessage,
onImageExpand,
@@ -399,6 +411,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
text={displayedUserMessage.visibleText}
terminalContexts={terminalContexts}
resolvedTheme={ctx.resolvedTheme}
skills={ctx.skills}
/>
)}
<div className="mt-1.5 flex items-center justify-end gap-2">
@@ -447,6 +460,7 @@ function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "mess
text={messageText}
cwd={ctx.markdownCwd}
isStreaming={Boolean(row.message.streaming)}
skills={ctx.skills}
/>
<AssistantChangedFilesSection
turnSummary={row.assistantTurnDiffSummary}
@@ -562,19 +576,27 @@ function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "workin
}
// ---------------------------------------------------------------------------
// Self-ticking components — bypass LegendList memoisation entirely.
// Each owns a `nowMs` state value consumed in the render output so the
// React Compiler cannot elide the re-render as a no-op.
// Self-ticking labels — update their own text nodes so elapsed-time display
// does not create a React commit every second while a response is streaming.
// ---------------------------------------------------------------------------
/** Live "Working for Xs" label. */
function WorkingTimer({ createdAt }: { createdAt: string }) {
const [nowMs, setNowMs] = useState(() => Date.now());
const textRef = useRef<HTMLSpanElement>(null);
const initialText = formatWorkingTimerNow(createdAt);
useEffect(() => {
const id = setInterval(() => setNowMs(Date.now()), 1000);
const updateText = () => {
if (textRef.current) {
textRef.current.textContent = formatWorkingTimerNow(createdAt);
}
};
updateText();
const id = setInterval(updateText, 1000);
return () => clearInterval(id);
}, [createdAt]);
return <>{formatWorkingTimer(createdAt, new Date(nowMs).toISOString()) ?? "0s"}</>;
return <span ref={textRef}>{initialText}</span>;
}
/** Live timestamp + elapsed duration for a streaming assistant message. */
@@ -587,15 +609,28 @@ function LiveMessageMeta({
durationStart: string | null | undefined;
timestampFormat: TimestampFormat;
}) {
const [nowMs, setNowMs] = useState(() => Date.now());
const textRef = useRef<HTMLSpanElement>(null);
const initialText = formatLiveMessageMetaNow(createdAt, durationStart, timestampFormat);
useEffect(() => {
const id = setInterval(() => setNowMs(Date.now()), 1000);
const updateText = () => {
if (textRef.current) {
textRef.current.textContent = formatLiveMessageMetaNow(
createdAt,
durationStart,
timestampFormat,
);
}
};
updateText();
if (!durationStart) {
return;
}
const id = setInterval(updateText, 1000);
return () => clearInterval(id);
}, [durationStart]);
const elapsed = durationStart
? formatElapsed(durationStart, new Date(nowMs).toISOString())
: null;
return <>{formatMessageMeta(createdAt, elapsed, timestampFormat)}</>;
}, [createdAt, durationStart, timestampFormat]);
return <span ref={textRef}>{initialText}</span>;
}
// ---------------------------------------------------------------------------
@@ -766,6 +801,7 @@ const UserMessageBody = memo(function UserMessageBody(props: {
text: string;
terminalContexts: ParsedTerminalContextEntry[];
resolvedTheme: "light" | "dark";
skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
}) {
const reviewCommentSegments = parseReviewCommentMessageSegments(props.text);
const hasReviewCommentSegments = reviewCommentSegments.some(
@@ -833,7 +869,7 @@ const UserMessageBody = memo(function UserMessageBody(props: {
if (matchIndex > cursor) {
inlineNodes.push(
<span key={`user-terminal-context-inline-before:${context.header}:${cursor}`}>
{props.text.slice(cursor, matchIndex)}
<SkillInlineText text={props.text.slice(cursor, matchIndex)} skills={props.skills} />
</span>,
);
}
@@ -850,7 +886,7 @@ const UserMessageBody = memo(function UserMessageBody(props: {
if (cursor < props.text.length) {
inlineNodes.push(
<span key={`user-message-terminal-context-inline-rest:${cursor}`}>
{props.text.slice(cursor)}
<SkillInlineText text={props.text.slice(cursor)} skills={props.skills} />
</span>,
);
}
@@ -878,7 +914,11 @@ const UserMessageBody = memo(function UserMessageBody(props: {
}
if (props.text.length > 0) {
inlineNodes.push(<span key="user-message-terminal-context-inline-text">{props.text}</span>);
inlineNodes.push(
<span key="user-message-terminal-context-inline-text">
<SkillInlineText text={props.text} skills={props.skills} />
</span>,
);
} else if (inlinePrefix.length === 0) {
return null;
}
@@ -896,7 +936,7 @@ const UserMessageBody = memo(function UserMessageBody(props: {
return (
<div className="whitespace-pre-wrap wrap-break-word text-sm leading-relaxed text-foreground">
{props.text}
<SkillInlineText text={props.text} skills={props.skills} />
</div>
);
});
@@ -1040,6 +1080,19 @@ function formatWorkingTimer(startIso: string, endIso: string): string | null {
return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
}
function formatWorkingTimerNow(startIso: string): string {
return formatWorkingTimer(startIso, new Date().toISOString()) ?? "0s";
}
function formatLiveMessageMetaNow(
createdAt: string,
durationStart: string | null | undefined,
timestampFormat: TimestampFormat,
): string {
const elapsed = durationStart ? formatElapsed(durationStart, new Date().toISOString()) : null;
return formatMessageMeta(createdAt, elapsed, timestampFormat);
}
function formatMessageMeta(
createdAt: string,
duration: string | null,
@@ -0,0 +1,87 @@
import { Children, cloneElement, isValidElement, type ReactNode } from "react";
import type { ServerProviderSkill } from "@t3tools/contracts";
import { formatProviderSkillDisplayName } from "../../providerSkillPresentation";
import {
COMPOSER_INLINE_CHIP_ICON_CLASS_NAME,
COMPOSER_INLINE_CHIP_LABEL_CLASS_NAME,
COMPOSER_INLINE_SKILL_CHIP_CLASS_NAME,
SKILL_CHIP_ICON_SVG,
} from "../composerInlineChip";
const SKILL_TOKEN_REGEX = /(^|\s)\$([a-zA-Z][a-zA-Z0-9:_-]*)(?=\s|$)/g;
type InlineSkill = Pick<ServerProviderSkill, "name" | "displayName">;
export function SkillInlineText(props: { text: string; skills: ReadonlyArray<InlineSkill> }) {
const nodes: ReactNode[] = [];
let cursor = 0;
for (const match of props.text.matchAll(SKILL_TOKEN_REGEX)) {
const prefix = match[1] ?? "";
const name = match[2] ?? "";
const start = (match.index ?? 0) + prefix.length;
const rawText = `$${name}`;
const skill = props.skills.find((candidate) => candidate.name === name);
if (!skill) {
continue;
}
if (start > cursor) {
nodes.push(props.text.slice(cursor, start));
}
nodes.push(<SkillChip key={`${start}:${name}`} skill={skill} rawText={rawText} />);
cursor = start + rawText.length;
}
if (cursor === 0) {
return <>{props.text}</>;
}
if (cursor < props.text.length) {
nodes.push(props.text.slice(cursor));
}
return <>{nodes}</>;
}
export function renderSkillInlineMarkdownChildren(
children: ReactNode,
skills: ReadonlyArray<InlineSkill>,
): ReactNode {
return Children.map(children, (child) => {
if (typeof child === "string") {
return <SkillInlineText text={child} skills={skills} />;
}
if (!isValidElement<{ children?: ReactNode }>(child)) {
return child;
}
if (child.type === "code" || child.type === "a") {
return child;
}
if (!("children" in child.props)) {
return child;
}
return cloneElement(
child,
undefined,
renderSkillInlineMarkdownChildren(child.props.children, skills),
);
});
}
function SkillChip(props: { skill: InlineSkill; rawText: string }) {
return (
<span className="inline-flex align-middle leading-none">
<span className="sr-only">{props.rawText}</span>
<span aria-hidden="true" className={COMPOSER_INLINE_SKILL_CHIP_CLASS_NAME}>
<span
aria-hidden="true"
className={COMPOSER_INLINE_CHIP_ICON_CLASS_NAME}
dangerouslySetInnerHTML={{ __html: SKILL_CHIP_ICON_SVG }}
/>
<span className={COMPOSER_INLINE_CHIP_LABEL_CLASS_NAME}>
{formatProviderSkillDisplayName(props.skill)}
</span>
</span>
</span>
);
}
@@ -8,5 +8,7 @@ export const COMPOSER_INLINE_CHIP_LABEL_CLASS_NAME = "truncate select-none leadi
export const COMPOSER_INLINE_SKILL_CHIP_CLASS_NAME =
"inline-flex max-w-full select-none items-center gap-1 rounded-md border border-fuchsia-500/25 bg-fuchsia-500/12 px-1.5 py-px font-medium text-[12px] leading-[1.1] text-fuchsia-700 align-middle dark:text-fuchsia-300";
export const SKILL_CHIP_ICON_SVG = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.85" stroke-linecap="round" stroke-linejoin="round"><path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"/><path d="m3.3 7 8.7 5 8.7-5"/><path d="M12 22V12"/></svg>`;
export const COMPOSER_INLINE_CHIP_DISMISS_BUTTON_CLASS_NAME =
"ml-0.5 inline-flex size-3.5 shrink-0 cursor-pointer items-center justify-center rounded-sm text-muted-foreground/72 transition-colors hover:bg-foreground/6 hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring";
@@ -364,6 +364,9 @@ export function useSettingsRestore(onRestored?: () => void) {
...(settings.timestampFormat !== DEFAULT_UNIFIED_SETTINGS.timestampFormat
? ["Time format"]
: []),
...(settings.sidebarThreadPreviewCount !== DEFAULT_UNIFIED_SETTINGS.sidebarThreadPreviewCount
? ["Visible threads"]
: []),
...(settings.diffWordWrap !== DEFAULT_UNIFIED_SETTINGS.diffWordWrap
? ["Diff line wrapping"]
: []),
@@ -400,6 +403,7 @@ export function useSettingsRestore(onRestored?: () => void) {
settings.diffIgnoreWhitespace,
settings.diffWordWrap,
settings.enableAssistantStreaming,
settings.sidebarThreadPreviewCount,
settings.timestampFormat,
theme,
],
@@ -420,6 +424,7 @@ export function useSettingsRestore(onRestored?: () => void) {
timestampFormat: DEFAULT_UNIFIED_SETTINGS.timestampFormat,
diffWordWrap: DEFAULT_UNIFIED_SETTINGS.diffWordWrap,
diffIgnoreWhitespace: DEFAULT_UNIFIED_SETTINGS.diffIgnoreWhitespace,
sidebarThreadPreviewCount: DEFAULT_UNIFIED_SETTINGS.sidebarThreadPreviewCount,
autoOpenPlanSidebar: DEFAULT_UNIFIED_SETTINGS.autoOpenPlanSidebar,
enableAssistantStreaming: DEFAULT_UNIFIED_SETTINGS.enableAssistantStreaming,
defaultThreadEnvMode: DEFAULT_UNIFIED_SETTINGS.defaultThreadEnvMode,
+26 -15
View File
@@ -27,6 +27,31 @@ function Input({
props.type === "file" &&
"text-muted-foreground file:me-3 file:bg-transparent file:font-medium file:text-foreground file:text-sm",
);
let inputElement: React.ReactElement;
if (nativeInput) {
const { style, onValueChange: _onValueChange, ...nativeInputProps } = props;
const nativeStyle = typeof style === "function" ? undefined : style;
inputElement = (
<input
className={inputClassName}
data-slot="input"
size={typeof size === "number" ? size : undefined}
style={nativeStyle}
{...(nativeInputProps as React.ComponentProps<"input">)}
/>
);
} else {
inputElement = (
<InputPrimitive
className={inputClassName}
data-slot="input"
size={typeof size === "number" ? size : undefined}
{...props}
/>
);
}
return (
<span
@@ -40,21 +65,7 @@ function Input({
data-size={size}
data-slot="input-control"
>
{nativeInput ? (
<input
className={inputClassName}
data-slot="input"
size={typeof size === "number" ? size : undefined}
{...props}
/>
) : (
<InputPrimitive
className={inputClassName}
data-slot="input"
size={typeof size === "number" ? size : undefined}
{...props}
/>
)}
{inputElement}
</span>
);
}
+156
View File
@@ -0,0 +1,156 @@
"use client";
import { NumberField as NumberFieldPrimitive } from "@base-ui/react/number-field";
import { MinusIcon, PlusIcon } from "lucide-react";
import * as React from "react";
import { cn } from "~/lib/utils";
import { Label } from "~/components/ui/label";
export const NumberFieldContext: React.Context<{
fieldId: string;
} | null> = React.createContext<{
fieldId: string;
} | null>(null);
export function NumberField({
id,
className,
size = "default",
...props
}: NumberFieldPrimitive.Root.Props & {
size?: "sm" | "default" | "lg";
}): React.ReactElement {
const generatedId = React.useId();
const fieldId = id ?? generatedId;
const contextValue = React.useMemo(() => ({ fieldId }), [fieldId]);
return (
<NumberFieldContext.Provider value={contextValue}>
<NumberFieldPrimitive.Root
className={cn("flex w-full flex-col items-start gap-2", className)}
data-size={size}
data-slot="number-field"
id={fieldId}
{...props}
/>
</NumberFieldContext.Provider>
);
}
export function NumberFieldGroup({
className,
...props
}: NumberFieldPrimitive.Group.Props): React.ReactElement {
return (
<NumberFieldPrimitive.Group
className={cn(
"relative flex w-full justify-between rounded-lg border border-input bg-background not-dark:bg-clip-padding text-base text-foreground shadow-xs/5 ring-ring/24 transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] not-data-disabled:not-focus-within:not-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] focus-within:border-ring focus-within:ring-[3px] has-aria-invalid:border-destructive/36 has-autofill:bg-foreground/4 focus-within:has-aria-invalid:border-destructive/64 focus-within:has-aria-invalid:ring-destructive/48 data-disabled:pointer-events-none data-disabled:opacity-64 sm:text-sm dark:bg-input/32 dark:has-autofill:bg-foreground/8 dark:has-aria-invalid:ring-destructive/24 dark:not-data-disabled:not-focus-within:not-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/6%)] [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0 [[data-disabled],:focus-within,[aria-invalid]]:shadow-none",
className,
)}
data-slot="number-field-group"
{...props}
/>
);
}
export function NumberFieldDecrement({
className,
...props
}: NumberFieldPrimitive.Decrement.Props): React.ReactElement {
return (
<NumberFieldPrimitive.Decrement
className={cn(
"relative flex shrink-0 cursor-pointer items-center justify-center rounded-s-[calc(var(--radius-lg)-1px)] in-data-[size=sm]:px-[calc(--spacing(2.5)-1px)] px-[calc(--spacing(3)-1px)] transition-colors pointer-coarse:after:absolute pointer-coarse:after:size-full pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:bg-accent",
className,
)}
data-slot="number-field-decrement"
{...props}
>
<MinusIcon />
</NumberFieldPrimitive.Decrement>
);
}
export function NumberFieldIncrement({
className,
...props
}: NumberFieldPrimitive.Increment.Props): React.ReactElement {
return (
<NumberFieldPrimitive.Increment
className={cn(
"relative flex shrink-0 cursor-pointer items-center justify-center rounded-e-[calc(var(--radius-lg)-1px)] in-data-[size=sm]:px-[calc(--spacing(2.5)-1px)] px-[calc(--spacing(3)-1px)] transition-colors pointer-coarse:after:absolute pointer-coarse:after:size-full pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:bg-accent",
className,
)}
data-slot="number-field-increment"
{...props}
>
<PlusIcon />
</NumberFieldPrimitive.Increment>
);
}
export function NumberFieldInput({
className,
...props
}: NumberFieldPrimitive.Input.Props): React.ReactElement {
return (
<NumberFieldPrimitive.Input
className={cn(
"h-8.5 in-data-[size=lg]:h-9.5 in-data-[size=sm]:h-7.5 w-full min-w-0 grow bg-transparent in-data-[size=sm]:px-[calc(--spacing(2.5)-1px)] px-[calc(--spacing(3)-1px)] text-center tabular-nums in-data-[size=lg]:leading-9.5 in-data-[size=sm]:leading-7.5 leading-8.5 outline-none [transition:background-color_5000000s_ease-in-out_0s] sm:h-7.5 sm:in-data-[size=lg]:h-8.5 sm:in-data-[size=sm]:h-6.5 sm:in-data-[size=lg]:leading-8.5 sm:in-data-[size=sm]:leading-8.5 sm:leading-7.5",
className,
)}
data-slot="number-field-input"
{...props}
/>
);
}
export function NumberFieldScrubArea({
className,
label,
...props
}: NumberFieldPrimitive.ScrubArea.Props & {
label: string;
}): React.ReactElement {
const context = React.useContext(NumberFieldContext);
if (!context) {
throw new Error(
"NumberFieldScrubArea must be used within a NumberField component for accessibility.",
);
}
return (
<NumberFieldPrimitive.ScrubArea
className={cn("flex cursor-ew-resize", className)}
data-slot="number-field-scrub-area"
{...props}
>
<Label className="cursor-ew-resize" htmlFor={context.fieldId}>
{label}
</Label>
<NumberFieldPrimitive.ScrubAreaCursor className="drop-shadow-[0_1px_1px_#0008] filter">
<CursorGrowIcon />
</NumberFieldPrimitive.ScrubAreaCursor>
</NumberFieldPrimitive.ScrubArea>
);
}
export function CursorGrowIcon(props: React.ComponentProps<"svg">): React.ReactElement {
return (
<svg
aria-hidden="true"
fill="black"
height="14"
stroke="white"
viewBox="0 0 24 14"
width="26"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path d="M19.5 5.5L6.49737 5.51844V2L1 6.9999L6.5 12L6.49737 8.5L19.5 8.5V12L25 6.9999L19.5 2V5.5Z" />
</svg>
);
}
export { NumberFieldPrimitive };