feat(desktop): redesign capabilities catalog
@@ -0,0 +1,38 @@
|
||||
import { type ReactNode, useState } from 'react'
|
||||
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Codicon } from '@/components/ui/codicon'
|
||||
import { useI18n } from '@/i18n'
|
||||
|
||||
/** A load failure above the catalog results that keeps what's already shown. */
|
||||
export function CatalogAlert({
|
||||
title,
|
||||
children,
|
||||
retryLabel,
|
||||
onRetry
|
||||
}: {
|
||||
title: string
|
||||
children?: ReactNode
|
||||
retryLabel: string
|
||||
onRetry: () => void
|
||||
}) {
|
||||
const { t } = useI18n()
|
||||
const [dismissed, setDismissed] = useState(false)
|
||||
|
||||
if (dismissed) {return null}
|
||||
|
||||
return (
|
||||
<Alert className="mx-6 w-auto shrink-0 pr-12" variant="warning">
|
||||
<Codicon name="warning" />
|
||||
<AlertTitle>{title}</AlertTitle>
|
||||
<Button aria-label={t.common.close} className="absolute right-3 top-3" onClick={() => setDismissed(true)} size="icon-xs" variant="ghost"><Codicon name="close" /></Button>
|
||||
<AlertDescription>
|
||||
{children}
|
||||
<Button onClick={onRetry} size="xs" variant="text">
|
||||
{retryLabel}
|
||||
</Button>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import artwork from '../../../../../shared/src/catalog-artwork.json'
|
||||
|
||||
const images = import.meta.glob<string>('../../../../../../website/static/img/catalog/*.jpg', {
|
||||
eager: true,
|
||||
import: 'default',
|
||||
query: '?url'
|
||||
})
|
||||
|
||||
const artworkUrl = (filename: string | undefined) =>
|
||||
filename ? images[`../../../../../../website/static/img/catalog/${filename}`] ?? null : null
|
||||
|
||||
/** Only first-party catalog identities receive editorial artwork. */
|
||||
export function officialCatalogArtwork(kind: 'skills' | 'plugins', row: {
|
||||
name?: string
|
||||
category?: string
|
||||
identifier?: string
|
||||
source?: string
|
||||
tier?: string
|
||||
}): string | null {
|
||||
const source = kind === 'skills' ? row.source : row.tier
|
||||
|
||||
if (kind === 'skills') {
|
||||
if (!['built-in', 'bundled', 'optional', 'official'].includes(source ?? '')) {return null}
|
||||
const key = `${row.category}/${row.name}`
|
||||
|
||||
return artworkUrl((artwork.skills as Record<string, string>)[key])
|
||||
}
|
||||
|
||||
if (source !== 'bundled') {return null}
|
||||
|
||||
return artworkUrl((artwork.plugins as Record<string, string>)[row.identifier ?? ''])
|
||||
}
|
||||
@@ -0,0 +1,434 @@
|
||||
import { useStore } from '@nanostores/react'
|
||||
import { memo, type ReactNode, useDeferredValue, useEffect, useRef, useState } from 'react'
|
||||
|
||||
import { PageLoader } from '@/components/page-loader'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Codicon } from '@/components/ui/codicon'
|
||||
import { ErrorState } from '@/components/ui/error-state'
|
||||
import { Masonry } from '@/components/ui/masonry'
|
||||
import { SearchField } from '@/components/ui/search-field'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { Tip } from '@/components/ui/tooltip'
|
||||
import { useI18n } from '@/i18n'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
import { DetailColumn, ListColumn, MasterDetail } from '../../master-detail'
|
||||
import { PanelEmpty } from '../../overlays/panel'
|
||||
|
||||
import { CatalogAlert } from './catalog-alert'
|
||||
import { CatalogCard, type CatalogCardVariant } from './catalog-card'
|
||||
import { type CatalogEntry, type CatalogKind, useCatalog } from './catalog-data'
|
||||
import { CatalogDetail } from './catalog-detail'
|
||||
import { CatalogDetailDialog } from './catalog-detail-dialog'
|
||||
import { CatalogDiscovery } from './catalog-discovery'
|
||||
import { CatalogFilterBar } from './catalog-filter-bar'
|
||||
import { CatalogInstallSwitch } from './catalog-install-switch'
|
||||
import { CatalogListRow } from './catalog-list-row'
|
||||
import { CATALOG_POINTER_ENABLED, trackCatalogPointer } from './catalog-pointer'
|
||||
import {
|
||||
catalogCategories,
|
||||
type CatalogSort,
|
||||
catalogSortOptions,
|
||||
catalogSources,
|
||||
catalogTags,
|
||||
filterCatalog,
|
||||
relatedEntries,
|
||||
sortCatalog
|
||||
} from './catalog-query'
|
||||
import { $catalogCardView } from './store'
|
||||
import { useCatalogFilters } from './use-catalog-filters'
|
||||
|
||||
interface CatalogBrowserProps {
|
||||
kind: CatalogKind
|
||||
query?: string
|
||||
onQueryChange?: (value: string) => void
|
||||
isInstalled: (entry: CatalogEntry) => boolean
|
||||
onInstall: (entry: CatalogEntry) => void
|
||||
isInstalling?: (entry: CatalogEntry) => boolean
|
||||
/** Feed rows the caller drops from the list entirely (e.g. a community
|
||||
* lookalike whose name is taken by an installed skill). */
|
||||
isSuperseded?: (entry: CatalogEntry) => boolean
|
||||
installedEntries?: CatalogEntry[]
|
||||
matchInstalled?: (entry: CatalogEntry) => CatalogEntry | undefined
|
||||
actions?: ReactNode
|
||||
headerActions?: ReactNode
|
||||
installedPending?: boolean
|
||||
notice?: ReactNode
|
||||
renderInstalledDetail?: (entry: CatalogEntry) => ReactNode
|
||||
renderInstalledAction?: (entry: CatalogEntry) => ReactNode
|
||||
selectedEntryId?: string | null
|
||||
}
|
||||
|
||||
const PAGE_SIZE = 60
|
||||
// The skills hub carries ~10k distinct tags; the rail is for browsing, search covers the tail.
|
||||
const TAG_LIMIT = 16
|
||||
/** On: masonry lanes. Off: fallback grid whose rows share one height (`.catalog-grid`). */
|
||||
const CATALOG_MASONRY = true
|
||||
|
||||
/** Merge the public feed with installed rows: a catalog entry that matches an
|
||||
* installed one takes the installed id (so selection and install state line
|
||||
* up); installed rows with no catalog match are appended. */
|
||||
function mergeInstalled(
|
||||
data: CatalogEntry[],
|
||||
installedEntries: CatalogEntry[],
|
||||
matchInstalled?: (entry: CatalogEntry) => CatalogEntry | undefined
|
||||
) {
|
||||
const remaining = new Map(installedEntries.map(entry => [entry.id, entry]))
|
||||
const seen = new Set<string>()
|
||||
|
||||
const catalog = data.flatMap(entry => {
|
||||
const installed = matchInstalled?.(entry)
|
||||
|
||||
if (!installed) {
|
||||
return [entry]
|
||||
}
|
||||
|
||||
remaining.delete(installed.id)
|
||||
|
||||
if (seen.has(installed.id)) {
|
||||
return []
|
||||
}
|
||||
|
||||
seen.add(installed.id)
|
||||
|
||||
return [
|
||||
{
|
||||
...entry,
|
||||
id: installed.id,
|
||||
version: installed.version || entry.version,
|
||||
search: `${entry.search} ${installed.search}`
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
return [...catalog, ...remaining.values()]
|
||||
}
|
||||
|
||||
// Props take no destructuring defaults: React Compiler 1.0 skips components that have them.
|
||||
export const CatalogBrowser = memo(function CatalogBrowser({
|
||||
kind,
|
||||
isInstalled,
|
||||
onInstall,
|
||||
isInstalling,
|
||||
isSuperseded,
|
||||
installedEntries,
|
||||
matchInstalled,
|
||||
actions,
|
||||
headerActions,
|
||||
installedPending,
|
||||
notice,
|
||||
renderInstalledDetail,
|
||||
renderInstalledAction,
|
||||
selectedEntryId,
|
||||
query,
|
||||
onQueryChange
|
||||
}: CatalogBrowserProps) {
|
||||
const { t } = useI18n()
|
||||
const c = t.catalog
|
||||
const cardView = useStore($catalogCardView)
|
||||
const { data, isPending, error, refetch } = useCatalog(kind)
|
||||
const deferredQuery = useDeferredValue((query ?? '').trim().toLowerCase())
|
||||
const [selectedId, setSelectedId] = useState<string | null>(selectedEntryId ?? null)
|
||||
const [detailOpen, setDetailOpen] = useState(false)
|
||||
const [limit, setLimit] = useState(PAGE_SIZE)
|
||||
|
||||
const resetSelection = () => {
|
||||
setLimit(PAGE_SIZE)
|
||||
setSelectedId(null)
|
||||
setDetailOpen(false)
|
||||
}
|
||||
|
||||
const filters = useCatalogFilters(kind, resetSelection)
|
||||
const { facets, sort } = filters
|
||||
|
||||
// Clearing the query only widens results, and a deep link clears it while selecting its target.
|
||||
useEffect(() => {
|
||||
setLimit(PAGE_SIZE)
|
||||
|
||||
if (deferredQuery) {
|
||||
setSelectedId(null)
|
||||
}
|
||||
}, [deferredQuery])
|
||||
|
||||
// A deep link asks to open one entry; selection stays local afterwards.
|
||||
useEffect(() => {
|
||||
if (!selectedEntryId) {
|
||||
return
|
||||
}
|
||||
|
||||
setSelectedId(selectedEntryId)
|
||||
setDetailOpen(true)
|
||||
}, [selectedEntryId])
|
||||
|
||||
const root = useRef<HTMLDivElement>(null)
|
||||
useEffect(() => (CATALOG_POINTER_ENABLED && root.current ? trackCatalogPointer(root.current) : undefined), [])
|
||||
|
||||
const entries = mergeInstalled(data ?? [], installedEntries ?? [], matchInstalled)
|
||||
const visible = isSuperseded ? entries.filter(entry => !isSuperseded(entry)) : entries
|
||||
const filtered = sortCatalog(filterCatalog(visible, facets, deferredQuery, isInstalled), sort, kind)
|
||||
|
||||
const discover = !facets.sources.length && !facets.categories.length && !facets.tags.length && !deferredQuery && !facets.installedOnly
|
||||
const pageOrder = filtered
|
||||
|
||||
const selected = visible.find(entry => entry.id === selectedId) ?? filtered[0]
|
||||
const related = selected && (!cardView || detailOpen) ? relatedEntries(filtered, selected, 3) : []
|
||||
|
||||
const searchFor = (value: string) => {
|
||||
onQueryChange?.(value)
|
||||
resetSelection()
|
||||
}
|
||||
|
||||
const clearFilters = () => {
|
||||
onQueryChange?.('')
|
||||
filters.clear()
|
||||
}
|
||||
|
||||
const openEntry = (entry: CatalogEntry) => {
|
||||
setSelectedId(entry.id)
|
||||
setDetailOpen(true)
|
||||
}
|
||||
|
||||
// Installed entries get the owner's on/off switch; the rest install one-way.
|
||||
const entryAction = (entry: CatalogEntry) => {
|
||||
const custom = renderInstalledAction?.(entry)
|
||||
|
||||
if (custom) {
|
||||
return custom
|
||||
}
|
||||
|
||||
const installed = isInstalled(entry)
|
||||
|
||||
return (
|
||||
<CatalogInstallSwitch
|
||||
disabled={Boolean(installedPending) || installed || (kind === 'skills' && !entry.installIdentifier)}
|
||||
installed={installed}
|
||||
installing={isInstalling?.(entry) ?? false}
|
||||
name={entry.name}
|
||||
onInstall={() => {
|
||||
if (kind === 'plugins') {
|
||||
setDetailOpen(false)
|
||||
}
|
||||
|
||||
onInstall(entry)
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const card = (entry: CatalogEntry, accentIndex: number, variant: CatalogCardVariant = 'default') => (
|
||||
<CatalogCard
|
||||
accentIndex={accentIndex}
|
||||
action={entryAction(entry)}
|
||||
entry={entry}
|
||||
key={entry.id}
|
||||
onCategory={filters.chooseCategory}
|
||||
onOpen={openEntry}
|
||||
onSearch={searchFor}
|
||||
onTag={filters.toggleTag}
|
||||
variant={variant}
|
||||
/>
|
||||
)
|
||||
|
||||
const details = selected ? (
|
||||
<CatalogDetail
|
||||
action={entryAction(selected)}
|
||||
dialog={cardView}
|
||||
entry={selected}
|
||||
kind={kind}
|
||||
management={renderInstalledDetail?.(selected)}
|
||||
onCategory={filters.chooseCategory}
|
||||
onRelated={entry => setSelectedId(entry.id)}
|
||||
onSearch={searchFor}
|
||||
onTag={filters.toggleTag}
|
||||
related={related}
|
||||
/>
|
||||
) : null
|
||||
|
||||
const sortLabels: Record<CatalogSort, string> = {
|
||||
discover: c.featured,
|
||||
stars: c.mostStarred,
|
||||
newest: c.newest,
|
||||
updated: c.recentlyUpdated,
|
||||
name: c.alphabetical
|
||||
}
|
||||
|
||||
const sortControl = (
|
||||
<Select onValueChange={value => filters.setSort(value as CatalogSort)} value={sort}>
|
||||
<SelectTrigger aria-label={c.sortBy} className="w-full" size="sm">
|
||||
<SelectValue placeholder={c.sortBy} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{catalogSortOptions(visible, kind, sortLabels).map(({ value, label }) => (
|
||||
<SelectItem key={value} value={value}>
|
||||
{label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)
|
||||
|
||||
const viewToggleLabel = cardView ? c.listView : c.cardView
|
||||
const filterKey = [facets.sources, facets.categories, facets.tags].map(list => list.join(',')).join(':')
|
||||
|
||||
return (
|
||||
<div className="@container/catalog flex h-full min-h-0 min-w-0" data-catalog={kind} ref={root}>
|
||||
<div className="flex min-h-0 min-w-0 flex-1 flex-col">
|
||||
<div className="flex min-h-0 min-w-0 flex-1 flex-col" data-catalog-results>
|
||||
{/* Search owns the header; kind-specific setup actions and the view toggle share the end slot. */}
|
||||
<header
|
||||
className="catalog-search-header shrink-0"
|
||||
data-catalog-header
|
||||
>
|
||||
<SearchField
|
||||
containerClassName="w-full min-w-0 rounded-2xl bg-(--dt-card)"
|
||||
leadingContent={<Badge size="xs" variant="muted">{kind === 'plugins' ? t.skills.tabPlugins : t.skills.tabSkills}</Badge>}
|
||||
onChange={value => onQueryChange?.(value)}
|
||||
placeholder={kind === 'plugins' ? c.searchPlugins : c.searchSkills}
|
||||
trailingAction={<div
|
||||
className="flex min-w-0 flex-wrap items-center justify-end gap-3 justify-self-end"
|
||||
data-catalog-actions
|
||||
>
|
||||
{headerActions}
|
||||
<Tip label={viewToggleLabel}>
|
||||
<Button
|
||||
aria-label={viewToggleLabel}
|
||||
onClick={() => {
|
||||
setDetailOpen(false)
|
||||
$catalogCardView.set(!cardView)
|
||||
}}
|
||||
size="icon-xs"
|
||||
variant="ghost"
|
||||
>
|
||||
<Codicon name={cardView ? 'list-unordered' : 'extensions'} />
|
||||
</Button>
|
||||
</Tip>
|
||||
</div>}
|
||||
value={query ?? ''}
|
||||
variant="box"
|
||||
/>
|
||||
</header>
|
||||
<CatalogFilterBar
|
||||
actions={actions}
|
||||
categories={catalogCategories(visible, kind)}
|
||||
facets={facets}
|
||||
onCategory={filters.toggleCategory}
|
||||
onClear={clearFilters}
|
||||
onInstalled={filters.toggleInstalled}
|
||||
onSource={filters.toggleSource}
|
||||
onTag={filters.toggleTag}
|
||||
resultCount={filtered.length}
|
||||
sortControl={sortControl}
|
||||
sources={catalogSources(visible)}
|
||||
tags={catalogTags(visible, facets.tags, TAG_LIMIT)}
|
||||
/>
|
||||
{notice}
|
||||
{error && entries.length > 0 && (
|
||||
<CatalogAlert onRetry={() => void refetch()} retryLabel={c.retry} title={c.loadFailed}>
|
||||
{error.message}
|
||||
</CatalogAlert>
|
||||
)}
|
||||
<div className="min-h-0 flex-1">
|
||||
{isPending && !entries.length ? (
|
||||
<PageLoader label={t.skills.loading} />
|
||||
) : error && !entries.length ? (
|
||||
<div className="grid h-full place-items-center p-5">
|
||||
<ErrorState description={error.message} title={c.loadFailed}>
|
||||
<Button onClick={() => void refetch()} size="sm" variant="secondary">
|
||||
{c.retry}
|
||||
</Button>
|
||||
</ErrorState>
|
||||
</div>
|
||||
) : !selected ? (
|
||||
<PanelEmpty
|
||||
action={
|
||||
<Button onClick={clearFilters} size="sm" variant="secondary">
|
||||
{c.clearFilters}
|
||||
</Button>
|
||||
}
|
||||
description={c.tryAnother}
|
||||
icon="search"
|
||||
title={c.noResults}
|
||||
/>
|
||||
) : cardView ? (
|
||||
<>
|
||||
<div className="flex h-full min-h-0 flex-col" data-catalog-cards={kind}>
|
||||
<div
|
||||
className="min-h-0 flex-1 overflow-y-auto overscroll-contain [scrollbar-gutter:stable]"
|
||||
data-catalog-scroll
|
||||
key={`${filterKey}:${sort}:${deferredQuery}:${facets.installedOnly}`}
|
||||
>
|
||||
{discover ? (
|
||||
<CatalogDiscovery actions={actions} card={card} entries={filtered} kind={kind} onCategory={filters.chooseCategory} />
|
||||
) : (
|
||||
<div className="catalog-filtered-results py-2">
|
||||
{CATALOG_MASONRY ? (
|
||||
<Masonry data-catalog-hover-group>{filtered.slice(0, limit).map((entry, index) => card(entry, index))}</Masonry>
|
||||
) : (
|
||||
<div className="catalog-grid" data-catalog-hover-group>
|
||||
{filtered.slice(0, limit).map((entry, index) => card(entry, index))}
|
||||
</div>
|
||||
)}
|
||||
{filtered.length > limit && (
|
||||
<Button onClick={() => setLimit(value => value + PAGE_SIZE)} size="sm" variant="text">
|
||||
{c.more}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<CatalogDetailDialog
|
||||
onOpenChange={setDetailOpen}
|
||||
onSelect={setSelectedId}
|
||||
open={detailOpen}
|
||||
order={pageOrder}
|
||||
selectedId={selected.id}
|
||||
>
|
||||
{details}
|
||||
</CatalogDetailDialog>
|
||||
</>
|
||||
) : (
|
||||
<div
|
||||
className={cn('h-full min-h-0', detailOpen ? '[&_aside]:max-sm:hidden' : '[&_main]:max-sm:hidden')}
|
||||
data-catalog-list={kind}
|
||||
>
|
||||
<MasterDetail resizeId="capabilities-split" split="wide">
|
||||
<ListColumn key={`${filterKey}:${deferredQuery}`}>
|
||||
{filtered.slice(0, limit).map(entry => (
|
||||
<CatalogListRow
|
||||
entry={entry}
|
||||
installed={isInstalled(entry)}
|
||||
key={entry.id}
|
||||
kind={kind}
|
||||
onCategory={filters.chooseCategory}
|
||||
onOpen={openEntry}
|
||||
onSearch={searchFor}
|
||||
onTag={filters.toggleTag}
|
||||
selected={entry.id === selected.id}
|
||||
/>
|
||||
))}
|
||||
{filtered.length > limit && (
|
||||
<Button onClick={() => setLimit(value => value + PAGE_SIZE)} size="sm" variant="text">
|
||||
{c.more}
|
||||
</Button>
|
||||
)}
|
||||
</ListColumn>
|
||||
<DetailColumn footer={c.snapshotHint}>
|
||||
<div className="sm:hidden">
|
||||
<Button onClick={() => setDetailOpen(false)} size="sm" variant="text">
|
||||
<Codicon name="arrow-left" />
|
||||
{c.back}
|
||||
</Button>
|
||||
</div>
|
||||
{details}
|
||||
</DetailColumn>
|
||||
</MasterDetail>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
@@ -0,0 +1,142 @@
|
||||
import './catalog.css'
|
||||
|
||||
import { type ReactNode, useState } from 'react'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Codicon } from '@/components/ui/codicon'
|
||||
import { RowButton } from '@/components/ui/row-button'
|
||||
import { useI18n } from '@/i18n'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
import { type CatalogEntry, catalogLabel } from './catalog-data'
|
||||
import { CatalogDates, CatalogHeaderMeta, CatalogMetadata } from './catalog-metadata'
|
||||
|
||||
export function catalogIcon(category: string) {
|
||||
const icons: Record<string, string> = {
|
||||
desktop: 'layout',
|
||||
tools: 'tools',
|
||||
memory: 'database',
|
||||
platform: 'plug',
|
||||
models: 'hubot',
|
||||
web: 'globe',
|
||||
automation: 'run-all',
|
||||
voice: 'mic',
|
||||
'software-development': 'code',
|
||||
'autonomous-ai-agents': 'hubot',
|
||||
productivity: 'checklist',
|
||||
creative: 'paintcan',
|
||||
research: 'beaker',
|
||||
science: 'beaker',
|
||||
security: 'shield',
|
||||
media: 'play',
|
||||
apple: 'device-desktop'
|
||||
}
|
||||
|
||||
return icons[category] ?? 'extensions'
|
||||
}
|
||||
|
||||
export function CatalogImage({ src, className }: { src: string; className?: string }) {
|
||||
const [failed, setFailed] = useState(false)
|
||||
|
||||
return failed ? null : (
|
||||
<img
|
||||
alt=""
|
||||
className={cn('block w-full object-contain', className)}
|
||||
decoding="async"
|
||||
loading="lazy"
|
||||
onError={() => setFailed(true)}
|
||||
referrerPolicy="no-referrer"
|
||||
src={src}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
// Shared classes, not per-card inline custom properties: identical declarations
|
||||
// let the style engine reuse computed styles across cards. catalog.css paints them.
|
||||
const CARD_ACCENTS = [
|
||||
'[--catalog-accent:var(--ui-blue)]',
|
||||
'[--catalog-accent:var(--ui-orange)]',
|
||||
'[--catalog-accent:var(--ui-purple)]',
|
||||
'[--catalog-accent:var(--ui-green)]',
|
||||
'[--catalog-accent:var(--ui-red)]',
|
||||
'[--catalog-accent:var(--ui-cyan)]',
|
||||
'[--catalog-accent:var(--ui-yellow)]'
|
||||
]
|
||||
|
||||
export type CatalogCardVariant = 'default' | 'hero' | 'showcase' | 'compact' | 'horizontal'
|
||||
|
||||
interface CatalogCardProps {
|
||||
variant?: CatalogCardVariant
|
||||
entry: CatalogEntry
|
||||
action: ReactNode
|
||||
accentIndex: number
|
||||
onOpen: (entry: CatalogEntry) => void
|
||||
onCategory: (category: string) => void
|
||||
onTag: (tag: string) => void
|
||||
onSearch: (value: string) => void
|
||||
}
|
||||
|
||||
export function CatalogCard({ entry, action, accentIndex, onOpen, onCategory, onTag, onSearch, variant = 'default' }: CatalogCardProps) {
|
||||
const { t } = useI18n()
|
||||
|
||||
return (
|
||||
<article
|
||||
className={cn(
|
||||
'group relative flex min-w-0 flex-col overflow-hidden rounded-lg border',
|
||||
CARD_ACCENTS[accentIndex % CARD_ACCENTS.length]
|
||||
)}
|
||||
data-catalog-card
|
||||
data-catalog-editorial-art={(variant !== 'hero' && entry.imageUrl?.includes("official-art")) || undefined}
|
||||
data-catalog-variant={variant}
|
||||
data-entry-id={entry.id}
|
||||
>
|
||||
{variant !== 'hero' && entry.imageUrl && ((variant !== 'compact' && variant !== 'showcase') || entry.imageUrl.includes('official-art')) && <CatalogImage className="catalog-card-image aspect-[2/1]" key={entry.imageUrl} src={entry.imageUrl} />}
|
||||
{variant !== 'default' && <div className="catalog-card-topline">
|
||||
<span className="min-w-0 truncate" title={entry.author || catalogLabel(entry.source)}>{entry.author || catalogLabel(entry.source)}</span>
|
||||
{variant !== 'hero' && <span className="relative shrink-0">{action}</span>}
|
||||
</div>}
|
||||
<div className="catalog-card-copy flex min-h-0 w-full flex-1 flex-col gap-2 p-3">
|
||||
<div className="flex min-w-0 items-center gap-2.5">
|
||||
{/* Its ::after stretches over the whole card, so any empty spot opens the
|
||||
detail; real controls sit above it (`relative`). One focus stop per card. */}
|
||||
<RowButton
|
||||
aria-haspopup="dialog"
|
||||
aria-label={entry.name}
|
||||
className="min-w-0 flex-1 text-left font-semibold leading-snug after:absolute after:inset-0 after:rounded-[inherit] focus-visible:outline-none focus-visible:after:outline-2 focus-visible:after:outline-primary focus-visible:after:-outline-offset-2"
|
||||
onClick={() => onOpen(entry)}
|
||||
>
|
||||
<span className="catalog-card-title line-clamp-2 min-w-0 break-words text-lg">{variant === 'default' ? entry.name : catalogLabel(entry.name)}</span>
|
||||
</RowButton>
|
||||
{variant === 'default' && action && (
|
||||
<span className="relative shrink-0 opacity-[.66] transition-opacity group-hover:opacity-100 group-focus-within:opacity-100">
|
||||
{action}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{/* In a fixed-height grid cell the description is what gives way. */}
|
||||
<div className="flex min-h-0 min-w-0 flex-col gap-2">
|
||||
{variant === 'default' && <span className="flex w-full items-center gap-2 text-[length:var(--conversation-caption-font-size)] text-(--ui-text-tertiary)">
|
||||
<span className="min-w-0 flex-1 truncate">{entry.author || catalogLabel(entry.source)}</span>
|
||||
<CatalogHeaderMeta entry={entry} />
|
||||
</span>}
|
||||
<span className="catalog-card-description line-clamp-4 min-h-0 text-[length:var(--conversation-caption-font-size)] leading-relaxed text-(--ui-text-secondary)">
|
||||
{entry.description}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{variant === 'default' && <div className="catalog-card-metadata px-3 pb-3 [&_button]:relative">
|
||||
<CatalogMetadata
|
||||
entry={entry}
|
||||
onCategory={onCategory}
|
||||
onOpen={() => onOpen(entry)}
|
||||
onSearch={onSearch}
|
||||
onTag={onTag}
|
||||
/>
|
||||
</div>}
|
||||
{variant !== 'default' && <div className="catalog-card-footer"><CatalogHeaderMeta entry={entry} />{(variant === 'hero' || variant === 'showcase') && <span className="catalog-hero-action relative shrink-0">{variant === 'showcase' ? <><Button onClick={() => onOpen(entry)} size="inline" variant="text">{t.catalog.about}<Codicon name="arrow-up-right" /></Button>{action}</> : action}</span>}</div>}
|
||||
{variant === 'default' && <div className="catalog-card-dates mt-auto px-3 pb-3">
|
||||
<CatalogDates entry={entry} />
|
||||
</div>}
|
||||
</article>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
import { skillCatalogInstallIdentifier } from '@hermes/shared'
|
||||
import { queryOptions, useQuery } from '@tanstack/react-query'
|
||||
|
||||
import { queryClient } from '@/lib/query-client'
|
||||
|
||||
import { officialCatalogArtwork } from './catalog-artwork'
|
||||
|
||||
export type CatalogKind = 'skills' | 'plugins'
|
||||
|
||||
export interface CatalogEntry {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
overview: string
|
||||
category: string
|
||||
categoryLabel: string
|
||||
source: string
|
||||
author: string
|
||||
identifier: string
|
||||
installIdentifier?: string | null
|
||||
repo: string
|
||||
sha: string
|
||||
subdir: string
|
||||
version: string
|
||||
requiresHermes: string
|
||||
tags: string[]
|
||||
platforms: string[]
|
||||
requirements: string[]
|
||||
tools: string[]
|
||||
hooks: string[]
|
||||
middleware?: string[]
|
||||
commands?: string[]
|
||||
license?: string
|
||||
sourceUrl: string | null
|
||||
docsUrl: string | null
|
||||
/** Catalog-provided media, restricted to the same GitHub hosts as the website. */
|
||||
imageUrl: string | null
|
||||
screenshots?: string[]
|
||||
addedAt?: string
|
||||
updatedAt?: string
|
||||
stars: number | null
|
||||
search: string
|
||||
}
|
||||
|
||||
const DOCS_ORIGIN = 'https://hermes-agent.nousresearch.com'
|
||||
// The public domain redirects here without CORS headers on the redirect.
|
||||
// Use the docs' actual static host, not GitHub's API or repository endpoints.
|
||||
const CATALOG_BASE = 'https://nousresearch.github.io/hermes-agent/docs/api'
|
||||
const text = (value: unknown): string => (typeof value === 'string' ? value : '')
|
||||
const strings = (value: unknown): string[] => (Array.isArray(value) ? value.filter(v => typeof v === 'string') : [])
|
||||
|
||||
const IMAGE_HOSTS = new Set(['raw.githubusercontent.com', 'github.com'])
|
||||
|
||||
// URL.parse, not `new URL` in try/catch: most skill rows carry no repo or docs
|
||||
// URL, and 200k thrown TypeErrors cost ~0.7s of main thread per catalog load.
|
||||
const parseUrl = (value: unknown) => URL.parse(text(value))
|
||||
|
||||
/** Mirrors scripts/validate_plugin_catalog.py: https on a GitHub host, else no image. */
|
||||
export function catalogImageUrl(value: unknown): string | null {
|
||||
const url = parseUrl(value)
|
||||
const host = url?.hostname.toLowerCase() ?? ''
|
||||
|
||||
return url?.protocol === 'https:' && (IMAGE_HOSTS.has(host) || host.endsWith('.githubusercontent.com'))
|
||||
? url.href
|
||||
: null
|
||||
}
|
||||
|
||||
function webUrl(value: unknown): string | null {
|
||||
const url = parseUrl(value)
|
||||
|
||||
return url?.protocol === 'https:' || url?.protocol === 'http:' ? url.href : null
|
||||
}
|
||||
|
||||
/** Display form of a source or category id: domains stay verbatim (`browse.sh`),
|
||||
* slugs read as words (`software-development` → `Software Development`). */
|
||||
export const catalogLabel = (value: string) =>
|
||||
value.includes('.') ? value : value.replace(/[-_]+/g, ' ').replace(/\b\w/g, c => c.toUpperCase())
|
||||
|
||||
export function parseCatalog(kind: CatalogKind, data: unknown): CatalogEntry[] {
|
||||
if (!Array.isArray(data)) {
|
||||
throw new Error('Invalid catalog response')
|
||||
}
|
||||
|
||||
const entries = new Map<string, CatalogEntry>()
|
||||
|
||||
for (const row of data) {
|
||||
if (!row || typeof row !== 'object' || !text(row.name)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const name = text(row.name)
|
||||
const source = text(kind === 'plugins' ? row.tier : row.source)
|
||||
const identifier = text(row.identifier) || name
|
||||
const id = `${source}:${identifier}`
|
||||
const caps = row.capabilities ?? {}
|
||||
const category = text(row.category) || 'uncategorized'
|
||||
const categoryLabel = text(row.categoryLabel) || category
|
||||
const tags = strings(row.tags)
|
||||
const tools = strings(caps.providesTools)
|
||||
const hooks = strings(caps.providesHooks)
|
||||
const middleware = strings(caps.providesMiddleware)
|
||||
const commands = strings(row.commands)
|
||||
const platforms = strings(row.platforms)
|
||||
const requirements = strings(kind === 'plugins' ? caps.requiresEnv : row.envVars)
|
||||
const author = text(row.maintainer ?? row.author)
|
||||
const description = text(row.description)
|
||||
|
||||
entries.set(id, {
|
||||
id,
|
||||
name,
|
||||
description,
|
||||
overview: text(row.overview),
|
||||
category,
|
||||
categoryLabel,
|
||||
source,
|
||||
author,
|
||||
identifier,
|
||||
installIdentifier:
|
||||
kind === 'skills'
|
||||
? skillCatalogInstallIdentifier({
|
||||
name,
|
||||
source,
|
||||
identifier: text(row.identifier),
|
||||
installIdentifier: text(row.installIdentifier)
|
||||
})
|
||||
: null,
|
||||
repo: text(row.repo),
|
||||
sha: text(row.sha),
|
||||
subdir: text(row.subdir),
|
||||
version: text(row.version),
|
||||
requiresHermes: text(row.requiresHermes),
|
||||
tags,
|
||||
tools,
|
||||
hooks,
|
||||
middleware,
|
||||
commands,
|
||||
license: text(row.license) || undefined,
|
||||
platforms,
|
||||
requirements,
|
||||
sourceUrl: webUrl(row.repo || row.sourceUrl),
|
||||
docsUrl:
|
||||
webUrl(row.docsUrl) ||
|
||||
(text(row.docsPath) ? `${DOCS_ORIGIN}/docs/user-guide/skills/${text(row.docsPath)}` : null),
|
||||
imageUrl: catalogImageUrl(row.image) ?? officialCatalogArtwork(kind, row),
|
||||
screenshots:
|
||||
kind === 'plugins'
|
||||
? strings(row.screenshots)
|
||||
.map(catalogImageUrl)
|
||||
.filter((url): url is string => url !== null)
|
||||
: [],
|
||||
addedAt: Number.isFinite(Date.parse(text(row.addedAt))) ? text(row.addedAt) : undefined,
|
||||
updatedAt: Number.isFinite(Date.parse(text(row.updatedAt))) ? text(row.updatedAt) : undefined,
|
||||
stars: typeof row.stars === 'number' && Number.isFinite(row.stars) ? row.stars : null,
|
||||
search: [
|
||||
name,
|
||||
description,
|
||||
text(row.overview),
|
||||
author,
|
||||
category,
|
||||
categoryLabel,
|
||||
source,
|
||||
...tags,
|
||||
...tools,
|
||||
...hooks,
|
||||
...platforms,
|
||||
...requirements,
|
||||
...commands,
|
||||
...middleware
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ')
|
||||
.toLowerCase()
|
||||
})
|
||||
}
|
||||
|
||||
return [...entries.values()]
|
||||
}
|
||||
|
||||
export async function fetchCatalog(kind: CatalogKind): Promise<CatalogEntry[]> {
|
||||
// Bound inactivity, not total transfer time: a large skills snapshot can
|
||||
// take minutes on a healthy slow connection. Headers and each body chunk
|
||||
// get the same deadline; an actually stalled download still terminates.
|
||||
const controller = new AbortController()
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
const armDeadline = () => {
|
||||
clearTimeout(timer)
|
||||
timer = setTimeout(() => controller.abort(), 60_000)
|
||||
}
|
||||
|
||||
armDeadline()
|
||||
|
||||
try {
|
||||
// Same published snapshots as the docs galleries; no per-entry fan-out.
|
||||
const response = await fetch(`${CATALOG_BASE}/${kind}.json`, {
|
||||
credentials: 'omit',
|
||||
signal: controller.signal
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Catalog HTTP ${response.status}`)
|
||||
}
|
||||
|
||||
if (!response.body) {
|
||||
return parseCatalog(kind, await response.json())
|
||||
}
|
||||
|
||||
const reader = response.body.getReader()
|
||||
const decoder = new TextDecoder()
|
||||
const chunks: string[] = []
|
||||
armDeadline()
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
const { done, value } = await reader.read()
|
||||
|
||||
if (done) {
|
||||
break
|
||||
}
|
||||
|
||||
if (value.byteLength > 0) {
|
||||
armDeadline()
|
||||
}
|
||||
|
||||
chunks.push(decoder.decode(value, { stream: true }))
|
||||
}
|
||||
} finally {
|
||||
reader.releaseLock()
|
||||
}
|
||||
|
||||
clearTimeout(timer)
|
||||
chunks.push(decoder.decode())
|
||||
|
||||
return parseCatalog(kind, JSON.parse(chunks.join('')))
|
||||
} catch (error) {
|
||||
// Chromium can turn our abort into "The user aborted a request." The
|
||||
// controller, not that browser-dependent exception name, owns the cause.
|
||||
if (controller.signal.aborted) {
|
||||
throw new Error('Catalog download timed out after 60 seconds without progress. Please try again.')
|
||||
}
|
||||
|
||||
throw error
|
||||
} finally {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}
|
||||
|
||||
const catalogQuery = (kind: CatalogKind) =>
|
||||
queryOptions({
|
||||
queryKey: ['public-catalog', kind],
|
||||
queryFn: () => fetchCatalog(kind),
|
||||
staleTime: 30 * 60_000,
|
||||
// The skills snapshot parses to ~100k rows; release it once the page has
|
||||
// been left long enough that a revisit is a fresh browse anyway.
|
||||
gcTime: 30 * 60_000,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
refetchOnMount: false,
|
||||
retryOnMount: false,
|
||||
retry: false
|
||||
})
|
||||
|
||||
export function useCatalog(kind: CatalogKind) {
|
||||
return useQuery({
|
||||
...catalogQuery(kind),
|
||||
// A failed catalog stays parked across remounts (tab switches) until the
|
||||
// user explicitly chooses Try again.
|
||||
enabled: query => query.state.status !== 'error'
|
||||
})
|
||||
}
|
||||
|
||||
/** Warm a catalog while the browser is idle so switching tabs doesn't pay the fetch + parse. */
|
||||
export function prefetchCatalogWhenIdle(kind: CatalogKind) {
|
||||
const id = requestIdleCallback(() => void queryClient.prefetchQuery(catalogQuery(kind)), { timeout: 5_000 })
|
||||
|
||||
return () => cancelIdleCallback(id)
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import type { ReactNode } from 'react'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Codicon } from '@/components/ui/codicon'
|
||||
import { Dialog, DialogContent } from '@/components/ui/dialog'
|
||||
import { useI18n } from '@/i18n'
|
||||
|
||||
import type { CatalogEntry } from './catalog-data'
|
||||
|
||||
interface CatalogDetailDialogProps {
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
/** On-screen order to page through; wraps at both ends. */
|
||||
order: CatalogEntry[]
|
||||
selectedId: string
|
||||
onSelect: (id: string) => void
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
const EDITABLE = 'input, textarea, [contenteditable="true"]'
|
||||
|
||||
export function CatalogDetailDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
order,
|
||||
selectedId,
|
||||
onSelect,
|
||||
children
|
||||
}: CatalogDetailDialogProps) {
|
||||
const { t } = useI18n()
|
||||
const pageable = order.length > 1
|
||||
|
||||
const step = (delta: number) => {
|
||||
if (!pageable) {
|
||||
return
|
||||
}
|
||||
|
||||
const index = order.findIndex(entry => entry.id === selectedId)
|
||||
onSelect(order[(index + delta + order.length) % order.length].id)
|
||||
}
|
||||
|
||||
const pager = (delta: -1 | 1) => (
|
||||
<Button
|
||||
aria-label={delta < 0 ? t.ui.pagination.previous : t.ui.pagination.next}
|
||||
className={
|
||||
delta < 0
|
||||
? 'absolute -left-14 top-1/2 -translate-y-1/2 max-sm:left-2'
|
||||
: 'absolute -right-14 top-1/2 -translate-y-1/2 max-sm:right-2'
|
||||
}
|
||||
onClick={() => step(delta)}
|
||||
size="icon-lg"
|
||||
variant="ghost"
|
||||
>
|
||||
<Codicon name={delta < 0 ? 'chevron-left' : 'chevron-right'} />
|
||||
</Button>
|
||||
)
|
||||
|
||||
return (
|
||||
<Dialog onOpenChange={onOpenChange} open={open}>
|
||||
<DialogContent
|
||||
aria-describedby={undefined}
|
||||
bodyClassName="gap-5 p-0 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
|
||||
chrome={
|
||||
pageable && (
|
||||
<>
|
||||
{pager(-1)}
|
||||
{pager(1)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
className="max-w-2xl"
|
||||
// Focus returns to the card of the entry the user paged to, when it's rendered.
|
||||
onCloseAutoFocus={event => {
|
||||
event.preventDefault()
|
||||
document
|
||||
.querySelector<HTMLElement>(`[data-entry-id="${CSS.escape(selectedId)}"] [aria-haspopup="dialog"]`)
|
||||
?.focus({ preventScroll: true })
|
||||
}}
|
||||
onKeyDown={event => {
|
||||
if (
|
||||
(event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') ||
|
||||
(event.target as HTMLElement).closest(EDITABLE)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
step(event.key === 'ArrowLeft' ? -1 : 1)
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
import { type ReactNode, useLayoutEffect, useRef } from 'react'
|
||||
|
||||
import { ZoomableImage } from '@/components/chat/zoomable-image'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Codicon } from '@/components/ui/codicon'
|
||||
import { DialogTitle } from '@/components/ui/dialog'
|
||||
import { Reel } from '@/components/ui/reel'
|
||||
import { RowButton } from '@/components/ui/row-button'
|
||||
import { useI18n } from '@/i18n'
|
||||
import { ExternalLink } from '@/lib/external-link'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
import { catalogIcon, CatalogImage } from './catalog-card'
|
||||
import { type CatalogEntry, type CatalogKind, catalogLabel } from './catalog-data'
|
||||
import { CatalogDates, CatalogHeaderMeta, CatalogMetadata } from './catalog-metadata'
|
||||
|
||||
interface CatalogDetailProps {
|
||||
entry: CatalogEntry
|
||||
kind: CatalogKind
|
||||
action?: ReactNode
|
||||
management?: ReactNode
|
||||
related: CatalogEntry[]
|
||||
onCategory?: (category: string) => void
|
||||
onTag?: (tag: string) => void
|
||||
onSearch?: (value: string) => void
|
||||
onRelated?: (entry: CatalogEntry) => void
|
||||
/** Inside the modal: the hero bleeds to the edges and paging scrolls back to the top. */
|
||||
dialog: boolean
|
||||
}
|
||||
|
||||
/** The shared catalog inspector used by both Skills and Plugins. No destructuring
|
||||
* defaults: React Compiler 1.0 bails on this component with them. */
|
||||
export function CatalogDetail({
|
||||
entry,
|
||||
kind,
|
||||
action,
|
||||
management,
|
||||
related,
|
||||
onCategory,
|
||||
onTag,
|
||||
onSearch,
|
||||
onRelated,
|
||||
dialog
|
||||
}: CatalogDetailProps) {
|
||||
const { t } = useI18n()
|
||||
const c = t.catalog
|
||||
const root = useRef<HTMLDivElement>(null)
|
||||
const Title = dialog ? DialogTitle : 'h3'
|
||||
|
||||
// In the modal the body (this root's parent) is the scroller; a new entry starts at its top.
|
||||
useLayoutEffect(() => {
|
||||
if (dialog) {
|
||||
root.current?.parentElement?.scrollTo({ top: 0 })
|
||||
}
|
||||
}, [dialog, entry.id])
|
||||
|
||||
const metadata = [
|
||||
[c.platforms, entry.platforms.join(', ')],
|
||||
[c.requires, entry.requiresHermes ? `Hermes ${entry.requiresHermes}` : ''],
|
||||
[c.pinned, entry.sha ? <code>{entry.sha.slice(0, 8)}</code> : '']
|
||||
] as [string, ReactNode][]
|
||||
|
||||
return (
|
||||
<div className={cn('min-w-0 space-y-5', dialog && 'pb-4 [&>:not(img)]:mx-4 [&>:first-child:not(img)]:mt-4')} data-catalog-detail={kind} ref={root}>
|
||||
{entry.imageUrl && (
|
||||
<CatalogImage
|
||||
className={cn(
|
||||
'aspect-[2/1] object-cover',
|
||||
dialog ? 'w-full rounded-t-xl' : 'w-full rounded-md'
|
||||
)}
|
||||
key={entry.imageUrl}
|
||||
src={entry.imageUrl}
|
||||
/>
|
||||
)}
|
||||
<header className="space-y-3">
|
||||
<div className="flex min-w-0 items-start gap-3">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className={cn('flex min-w-0 items-center gap-2', dialog && !entry.imageUrl && 'pr-7')}>
|
||||
<Title className="min-w-0 flex-1 break-words text-lg font-semibold tracking-tight">{entry.name}</Title>
|
||||
{action && <span className="shrink-0">{action}</span>}
|
||||
</div>
|
||||
<div className="mt-1 flex min-w-0 items-center gap-2 text-xs text-(--ui-text-tertiary)">
|
||||
<span className="min-w-0 truncate">{entry.author || catalogLabel(entry.source)}</span>
|
||||
<CatalogHeaderMeta entry={entry} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{(entry.sourceUrl || entry.docsUrl) && (
|
||||
<div className="flex flex-wrap gap-3 text-xs">
|
||||
{entry.sourceUrl && <ExternalLink href={entry.sourceUrl}>{c.repository}</ExternalLink>}
|
||||
{entry.docsUrl && <ExternalLink href={entry.docsUrl}>{c.documentation}</ExternalLink>}
|
||||
</div>
|
||||
)}
|
||||
</header>
|
||||
|
||||
<p className="whitespace-pre-wrap break-words text-[length:var(--conversation-caption-font-size)] leading-relaxed text-(--ui-text-secondary)">
|
||||
{entry.description}
|
||||
</p>
|
||||
{entry.overview && entry.overview !== entry.description && (
|
||||
<p className="whitespace-pre-wrap break-words text-[length:var(--conversation-caption-font-size)] leading-relaxed text-(--ui-text-tertiary)">
|
||||
{entry.overview}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="space-y-3">
|
||||
<CatalogMetadata entry={entry} limit={Infinity} onCategory={onCategory} onSearch={onSearch} onTag={onTag} />
|
||||
<CatalogDates entry={entry} />
|
||||
<dl className="grid grid-cols-[max-content_minmax(0,1fr)] gap-x-4 gap-y-2 text-[length:var(--conversation-caption-font-size)]">
|
||||
{metadata
|
||||
.filter(([, value]) => Boolean(value))
|
||||
.map(([label, value]) => (
|
||||
<div className="contents" key={label}>
|
||||
<dt className="whitespace-nowrap text-(--ui-text-tertiary)">{label}</dt>
|
||||
<dd className="m-0 break-words">{value}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{management}
|
||||
|
||||
{Boolean(entry.screenshots?.length) && (
|
||||
<section className="space-y-2">
|
||||
<h4 className="text-xs font-medium">{c.screenshots}</h4>
|
||||
<Reel className={cn(dialog && '-mx-4 scroll-px-4 px-4')}>
|
||||
{entry.screenshots?.map((url, index) => (
|
||||
<ZoomableImage
|
||||
alt={`${c.screenshots} — ${entry.name} ${index + 1}`}
|
||||
className="h-56 w-auto max-w-none cursor-zoom-in rounded-lg border border-(--ui-stroke-tertiary)"
|
||||
decoding="async"
|
||||
key={url}
|
||||
loading="lazy"
|
||||
referrerPolicy="no-referrer"
|
||||
slot="catalog-screenshot"
|
||||
src={url}
|
||||
/>
|
||||
))}
|
||||
</Reel>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{[
|
||||
[c.tools, entry.tools],
|
||||
[c.hooks, entry.hooks],
|
||||
[c.middleware, entry.middleware ?? []],
|
||||
[c.requires, entry.requirements]
|
||||
].map(([label, values]) =>
|
||||
(values as string[]).length > 0 ? (
|
||||
<section className="space-y-2" key={label as string}>
|
||||
<h4 className="text-xs font-medium">{label as string}</h4>
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{(values as string[]).map(value =>
|
||||
onSearch ? (
|
||||
<Button key={value} onClick={() => onSearch(value)} size="xs" variant="ghost">
|
||||
{value}
|
||||
</Button>
|
||||
) : (
|
||||
<Badge key={value} variant="muted">
|
||||
{value}
|
||||
</Badge>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
) : null
|
||||
)}
|
||||
|
||||
<p className="text-[0.65rem] leading-relaxed text-(--ui-text-quaternary)">{c.installHint}</p>
|
||||
|
||||
{related.length > 0 && (
|
||||
<section className="space-y-2">
|
||||
<h4 className="text-xs font-medium">{c.related}</h4>
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
{related.map(item => (
|
||||
<RowButton
|
||||
className="row-hover flex min-w-0 flex-col gap-1 overflow-hidden rounded-md text-left"
|
||||
key={item.id}
|
||||
onClick={() => onRelated?.(item)}
|
||||
>
|
||||
{item.imageUrl ? (
|
||||
<CatalogImage className="aspect-[2/1] w-full rounded-t-md object-contain" src={item.imageUrl} />
|
||||
) : (
|
||||
<span className="flex aspect-[2/1] w-full items-center justify-center bg-(--ui-bg-quaternary) text-(--ui-text-tertiary)">
|
||||
<Codicon name={catalogIcon(item.category)} size="1.25rem" />
|
||||
</span>
|
||||
)}
|
||||
<span className="w-full truncate px-2 pb-2 text-xs font-medium">{item.name}</span>
|
||||
</RowButton>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/* Figma Frame 330's geometry, with the existing desktop card and theme surfaces. */
|
||||
/* Reference 121:5782: full-card hard-light artwork, no alpha-mask strip. */
|
||||
[data-catalog-card][data-catalog-variant] { background: var(--ui-chat-bubble-background); border-color: var(--ui-stroke-tertiary); }
|
||||
[data-catalog-editorial-art] .catalog-card-description { color: var(--ui-text-primary); }
|
||||
:root:not(.dark) [data-catalog-editorial-art] { --catalog-art-shade: 65%; }
|
||||
[data-catalog-hover-group]:has([data-catalog-card]:hover) [data-catalog-card]:not(:hover) { filter: none; }
|
||||
[data-catalog-card][data-catalog-editorial-art] { isolation: isolate; background: color-mix(in srgb, var(--color-primary) 28%, var(--ui-chat-bubble-background)); }
|
||||
[data-catalog-card][data-catalog-editorial-art] .catalog-card-image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: -2; opacity: 1; filter: grayscale(1); mix-blend-mode: luminosity; }
|
||||
[data-catalog-editorial-art] { --catalog-art-shade: 50%; }
|
||||
:root.dark [data-catalog-editorial-art] { --catalog-art-shade: 72%; }
|
||||
[data-catalog-editorial-art]::before { content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none; background: linear-gradient(to bottom left, color-mix(in srgb, var(--ui-chat-bubble-background) var(--catalog-art-shade), transparent), var(--ui-chat-bubble-background) 78.79%); }
|
||||
[data-catalog-card][data-catalog-editorial-art][data-catalog-variant=default] { height: auto; min-height: 320px; }
|
||||
[data-catalog-card][data-catalog-editorial-art] .catalog-card-copy { flex: none; margin-top: auto; background: none; }
|
||||
[data-catalog-editorial-art] .catalog-card-topline { margin-bottom: 72px; }
|
||||
[data-catalog-card][data-catalog-editorial-art][data-catalog-variant=horizontal] .catalog-card-image { display: none; }
|
||||
[data-catalog-editorial-art][data-catalog-variant=horizontal]::before { display: none; }
|
||||
[data-catalog-editorial-art][data-catalog-variant=horizontal] .catalog-card-copy { margin-top: 0; }
|
||||
[data-catalog-variant=compact] .catalog-card-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 20px; }
|
||||
[data-catalog-variant=compact] .catalog-card-footer > span { width: auto; }
|
||||
[data-catalog-results] { container-type: inline-size; }
|
||||
.catalog-search-header { width: 100%; max-width: 1228px; margin-inline: auto; padding: 20px 24px 0; }
|
||||
.catalog-filter-bar { width: 100%; max-width: 1228px; margin-inline: auto; padding: 16px 24px 8px; }
|
||||
.catalog-filter-row { display: flex; align-items: center; gap: 15px; min-width: 0; }
|
||||
.catalog-filter-chips { display: flex; flex: 1; align-items: center; gap: 10px; min-width: 0; overflow-x: auto; padding-block: 4px; }
|
||||
.catalog-filter-row > :first-child { flex-shrink: 0; }
|
||||
.catalog-filter-chips[data-expanded=true] { flex-wrap: wrap; max-height: 24vh; overflow-y: auto; }
|
||||
.catalog-filter-trigger { display: flex; flex: none; align-items: center; gap: 8px; }
|
||||
.catalog-card-footer { padding: 0 20px 12px; }
|
||||
.catalog-card-footer > span { flex-wrap: wrap; width: 100%; }
|
||||
.catalog-card-footer > span > span:last-child { margin-left: auto; }
|
||||
.catalog-card-footer [data-slot=badge] { max-width: 55%; }
|
||||
.catalog-filtered-results { width: 100%; max-width: 1228px; margin-inline: auto; padding-inline: 24px; }
|
||||
.catalog-discovery { max-width: 1228px; margin-inline: auto; padding: 0 24px 48px; }
|
||||
.catalog-section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; padding: 48px 20px 20px; }
|
||||
.catalog-discovery > section:first-child .catalog-section-heading { padding-top: 16px; }
|
||||
.catalog-section-heading h2 { margin: 0; font-size: 1.4rem; font-weight: 600; letter-spacing: -.025em; }
|
||||
.catalog-section-heading p { margin: 6px 0 0; font-size: .8125rem; color: var(--ui-text-tertiary); }
|
||||
.catalog-collection { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; }
|
||||
.catalog-filtered-results > :is(.masonry, .catalog-grid) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
||||
.catalog-collection.catalog-collection-showcase { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
||||
.catalog-collection-showcase > * { scroll-snap-align: start; }
|
||||
.catalog-collection-horizontal { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
[data-catalog-card]:not([data-catalog-variant=default]) { min-height: 220px; }
|
||||
.catalog-card-topline { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px; font-size: .75rem; color: var(--ui-text-tertiary); }
|
||||
[data-catalog-card]:not([data-catalog-variant=default]) .catalog-card-copy { padding: 0 20px 16px; }
|
||||
[data-catalog-card]:not([data-catalog-variant=default]) .catalog-card-metadata { padding: 0 20px 16px; }
|
||||
[data-catalog-card]:not([data-catalog-variant=default]) .catalog-card-dates { padding: 0 20px 16px; }
|
||||
[data-catalog-variant=hero] { min-height: 240px !important; isolation: isolate; justify-content: flex-start; padding: 20px; gap: 12px; }
|
||||
[data-catalog-variant=hero] .catalog-card-topline { padding: 0; margin: 0; }
|
||||
[data-catalog-card][data-catalog-variant=hero] .catalog-card-copy { padding: 0; }
|
||||
[data-catalog-variant=hero] .catalog-card-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0; margin-top: auto; }
|
||||
[data-catalog-variant=hero] .catalog-card-footer > span:first-child { width: auto; }
|
||||
[data-catalog-variant=hero] .catalog-card-footer > .catalog-hero-action { width: auto; margin-left: auto; }
|
||||
[data-catalog-variant=hero]:not([data-catalog-editorial-art]) .catalog-card-image { position: absolute; inset: 0 0 0 auto; width: 42%; height: 100%; object-fit: contain; z-index: -1; }
|
||||
[data-catalog-variant=hero] .catalog-card-copy { flex: none; max-width: 58%; }
|
||||
[data-catalog-variant=hero] .catalog-card-copy button > span { font-size: 2rem; }
|
||||
[data-catalog-variant=hero] .catalog-card-dates { margin-top: 0; }
|
||||
[data-catalog-card][data-catalog-variant=showcase] { height: 380px; min-height: 380px; display: flex; flex-direction: column; }
|
||||
[data-catalog-card] > * { min-width: 0; max-width: 100%; }
|
||||
[data-catalog-variant=showcase] .catalog-card-topline { padding: 20px; margin-bottom: auto; }
|
||||
[data-catalog-variant=showcase] .catalog-card-copy { flex: none; margin: 0; padding: 0 20px 16px; }
|
||||
[data-catalog-variant=showcase] .catalog-card-description { min-height: 3em; -webkit-line-clamp: 2; }
|
||||
[data-catalog-variant=showcase] .catalog-card-metadata { margin-bottom: auto; }
|
||||
[data-catalog-variant=showcase] [data-catalog-metadata] { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px; }
|
||||
[data-catalog-variant=showcase] .catalog-card-footer { grid-row: 4; align-self: end; }
|
||||
[data-catalog-variant=showcase] .catalog-card-title { font-size: 1.125rem; line-height: 1.4; }
|
||||
[data-catalog-variant=showcase] .catalog-card-metadata { padding-inline: 24px; }
|
||||
[data-catalog-variant=showcase] .catalog-card-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
||||
[data-catalog-variant=showcase] .catalog-hero-action { display: flex; align-items: center; gap: 12px; margin-left: auto; }
|
||||
[data-catalog-card]:not([data-catalog-variant=default]) .catalog-card-description { -webkit-line-clamp: 3; }
|
||||
[data-catalog-card][data-catalog-variant=compact] { height: 220px; min-height: 220px; }
|
||||
[data-catalog-variant=compact] .catalog-card-topline { margin-bottom: 0; }
|
||||
[data-catalog-variant=compact] .catalog-card-copy { margin-top: 0; }
|
||||
.catalog-card-topline { flex-shrink: 0; }
|
||||
[data-catalog-variant=horizontal] { height: 120px; min-height: 120px !important; padding-top: 20px; }
|
||||
[data-catalog-variant=horizontal] .catalog-card-topline { position: absolute; right: 20px; top: 20px; padding: 0; }
|
||||
[data-catalog-variant=horizontal] .catalog-card-topline > span:first-child { display: none; }
|
||||
[data-catalog-variant=horizontal] .catalog-card-copy { padding-right: 40%; }
|
||||
[data-catalog-variant=horizontal] .catalog-card-footer { position: absolute; right: 20px; bottom: 20px; padding: 0; }
|
||||
[data-catalog-variant=horizontal] .catalog-card-footer [data-slot=badge] { display: none; }
|
||||
[data-catalog-variant=horizontal] .catalog-card-image { display: none; }
|
||||
.catalog-developer { position: relative; isolation: isolate; aspect-ratio: 3 / 1; min-height: 280px; overflow: hidden; border-radius: var(--radius-lg); background: var(--ui-chat-bubble-background); padding: 32px; }
|
||||
.catalog-developer-art { position: absolute; width: 42%; height: 225%; right: 13%; top: -58%; transform: rotate(48deg); pointer-events: none; background: color-mix(in srgb, var(--color-primary) 70%, transparent); mask: url('../../../assets/catalog-wing-retro.svg') center / contain no-repeat; mask-mode: luminance; mix-blend-mode: multiply; }
|
||||
:root.dark .catalog-developer-art { mix-blend-mode: screen; }
|
||||
.catalog-developer-content { position: relative; height: 100%; min-height: 216px; display: flex; flex-direction: column; align-items: flex-start; gap: 16px; }
|
||||
.catalog-developer-mark { display: block; width: 30px; height: 18px; background: var(--ui-text-primary); mask: url('../../../assets/catalog-wing-retro.svg') center / contain no-repeat; mask-mode: luminance; transform: rotate(48deg) scale(2); }
|
||||
.catalog-developer h3 { font-size: 2rem; font-weight: 600; letter-spacing: -.025em; line-height: 1.1; }
|
||||
.catalog-developer-content p { max-width: 340px; }
|
||||
.catalog-developer-ctas { display: flex; flex-wrap: wrap; gap: 4px; margin-top: auto; padding-top: 28px; }
|
||||
.catalog-developer-management { display: flex; justify-content: flex-end; gap: 8px; padding-top: 12px; }
|
||||
@container (max-width: 540px) { .catalog-developer { aspect-ratio: auto; padding: 24px; } .catalog-developer-art { right: -15%; background: color-mix(in srgb, var(--color-primary) 30%, transparent); } }
|
||||
@container (max-width: 960px) { .catalog-collection.catalog-collection-showcase, .catalog-filtered-results > :is(.masonry, .catalog-grid), .catalog-collection { grid-template-columns: repeat(3, minmax(0, 1fr)); } .catalog-collection-horizontal { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
||||
@container (max-width: 720px) { .catalog-collection.catalog-collection-showcase, .catalog-filtered-results > :is(.masonry, .catalog-grid), .catalog-collection { grid-template-columns: repeat(2, minmax(0, 1fr)); } .catalog-section-heading { padding-top: 32px; } .catalog-filter-bar > div:first-child { flex-wrap: wrap; } }
|
||||
@container (max-width: 440px) { .catalog-collection.catalog-collection-showcase, .catalog-filtered-results > :is(.masonry, .catalog-grid), .catalog-collection { grid-template-columns: minmax(0, 1fr); } .catalog-discovery { padding-inline: 12px; } .catalog-search-header, .catalog-filter-bar { padding-inline: 12px; } [data-catalog-variant=hero] .catalog-card-copy { max-width: 100%; } }
|
||||
@@ -0,0 +1,87 @@
|
||||
import './catalog-discovery.css'
|
||||
|
||||
import { PLUGIN_CATEGORIES } from '@hermes/shared'
|
||||
import { type ReactNode, useState } from 'react'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Codicon } from '@/components/ui/codicon'
|
||||
import { useI18n } from '@/i18n'
|
||||
import { openExternalLink } from '@/lib/external-link'
|
||||
|
||||
import type { CatalogCardVariant } from './catalog-card'
|
||||
import { type CatalogEntry, type CatalogKind, catalogLabel } from './catalog-data'
|
||||
import { catalogCategories } from './catalog-query'
|
||||
|
||||
// Reviewed catalog identifiers, not an inferred recommendation or download metric.
|
||||
const FEATURED = { plugins: 'hindsight', skills: 'claude-code' } as const
|
||||
|
||||
export function CatalogDiscovery({ entries, kind, card, onCategory, actions }: {
|
||||
entries: CatalogEntry[]
|
||||
kind: CatalogKind
|
||||
card: (entry: CatalogEntry, index: number, variant: CatalogCardVariant) => ReactNode
|
||||
onCategory: (category: string) => void
|
||||
actions?: ReactNode
|
||||
}) {
|
||||
const { t } = useI18n()
|
||||
const [categoryLimit, setCategoryLimit] = useState(8)
|
||||
const title = kind === 'plugins' ? t.skills.tabPlugins : t.skills.tabSkills
|
||||
|
||||
const featured = entries.find(entry => entry.identifier === FEATURED[kind])
|
||||
?? entries.find(entry => entry.name === FEATURED[kind] && ['bundled', 'official', 'builtin'].includes(entry.source))
|
||||
|
||||
const remaining = entries.filter(entry => entry !== featured)
|
||||
const groups = new Map<string, CatalogEntry[]>()
|
||||
|
||||
for (const entry of remaining) {
|
||||
const group = groups.get(entry.category)
|
||||
|
||||
if (group) {group.push(entry)}
|
||||
else {groups.set(entry.category, [entry])}
|
||||
}
|
||||
|
||||
const categories = catalogCategories(remaining, kind)
|
||||
|
||||
return (
|
||||
<div className="catalog-discovery">
|
||||
{featured && <section data-catalog-section="featured">
|
||||
<header className="catalog-section-heading"><h2>{t.catalog.discover} {title}</h2></header>
|
||||
{card(featured, 0, 'hero')}
|
||||
</section>}
|
||||
{categories.slice(0, categoryLimit).map(([category, meta], sectionIndex) => {
|
||||
const items = groups.get(category) ?? []
|
||||
const variant: CatalogCardVariant = items.slice(0, 4).some(entry => entry.imageUrl) || sectionIndex % 3 === 0 ? 'showcase' : sectionIndex % 3 === 2 ? 'horizontal' : 'compact'
|
||||
|
||||
return <section data-catalog-section={category} key={category}>
|
||||
<header className="catalog-section-heading">
|
||||
<div><h2>{catalogLabel(meta.label)}</h2><p>{kind === 'plugins' ? PLUGIN_CATEGORIES[category]?.blurb : `Skills for ${catalogLabel(meta.label).toLowerCase()}.`}</p></div>
|
||||
<Button onClick={() => onCategory(category)} size="inline" variant="text">{t.catalog.seeAll}<Codicon name="arrow-right" /></Button>
|
||||
</header>
|
||||
<div className={`catalog-collection catalog-collection-${variant}`} data-catalog-hover-group>
|
||||
{items.slice(0, variant === 'showcase' ? 4 : variant === 'horizontal' ? 6 : kind === 'plugins' ? 12 : 8).map((entry, index) => card(entry, sectionIndex + index, variant))}
|
||||
</div>
|
||||
</section>
|
||||
})}
|
||||
{categories.length > categoryLimit && <Button onClick={() => setCategoryLimit(value => value + 8)} size="sm" variant="text">{t.catalog.more}</Button>}
|
||||
<section data-catalog-section="developer">
|
||||
<header className="catalog-section-heading"><h2>Developer Mode</h2></header>
|
||||
<div className="catalog-developer">
|
||||
<div aria-hidden className="catalog-developer-art" />
|
||||
<div className="catalog-developer-content">
|
||||
<span aria-hidden className="catalog-developer-mark" />
|
||||
<h3>Build for Hermes</h3>
|
||||
<p className="text-sm text-(--ui-text-secondary)">Built a tool, connector, plugin, or Mod?<br />Want to but don’t know how?</p>
|
||||
<div className="catalog-developer-ctas">
|
||||
<Button onClick={() => void openExternalLink('https://github.com/NousResearch/hermes-agent/compare')} size="sm" variant="default">
|
||||
Submit Mod<Codicon name="arrow-up-right" />
|
||||
</Button>
|
||||
<Button onClick={() => void openExternalLink(kind === 'plugins' ? 'https://hermes-agent.nousresearch.com/docs/user-guide/features/plugin-catalog' : 'https://hermes-agent.nousresearch.com/docs/skills/')} size="sm" variant="secondary">
|
||||
Developer Docs<Codicon name="arrow-up-right" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{actions && <div className="catalog-developer-management">{actions}</div>}
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import { IconCategory, IconDatabase, IconFilter2 } from '@tabler/icons-react'
|
||||
import { type ReactNode, useId, useState } from 'react'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
||||
import { SegmentedControl } from '@/components/ui/segmented-control'
|
||||
import { useI18n } from '@/i18n'
|
||||
|
||||
import { catalogLabel } from './catalog-data'
|
||||
import type { FacetRow } from './catalog-filters'
|
||||
import type { CatalogFacets } from './catalog-query'
|
||||
|
||||
interface CatalogFilterBarProps {
|
||||
sources: string[]
|
||||
categories: ReadonlyArray<readonly [string, { label: string; count: number }]>
|
||||
tags: FacetRow[]
|
||||
facets: CatalogFacets
|
||||
onSource: (value: string | null) => void
|
||||
onCategory: (value: string | null) => void
|
||||
onTag: (value: string | null) => void
|
||||
onInstalled: () => void
|
||||
onClear: () => void
|
||||
sortControl: ReactNode
|
||||
actions: ReactNode
|
||||
resultCount: number
|
||||
}
|
||||
|
||||
export function CatalogFilterBar(props: CatalogFilterBarProps) {
|
||||
const { t } = useI18n()
|
||||
const c = t.catalog
|
||||
const panelId = useId()
|
||||
const [mode, setMode] = useState<'categories' | 'sources'>('categories')
|
||||
const [expanded, setExpanded] = useState(false)
|
||||
const [more, setMore] = useState(false)
|
||||
|
||||
const rows = mode === 'categories'
|
||||
? props.categories.map(([value, meta]) => ({ value, label: catalogLabel(meta.label) }))
|
||||
: props.sources.map(value => ({ value, label: catalogLabel(value) }))
|
||||
|
||||
const selected = props.facets[mode]
|
||||
const onSelect = mode === 'categories' ? props.onCategory : props.onSource
|
||||
const visible = rows.filter((row, index) => index < 3 || selected.includes(row.value))
|
||||
const overflow = rows.filter(row => !visible.includes(row))
|
||||
const activeCount = props.facets.categories.length + props.facets.sources.length + props.facets.tags.length
|
||||
|
||||
return (
|
||||
<div className="catalog-filter-bar" data-catalog-filters>
|
||||
<div className="catalog-filter-row">
|
||||
<SegmentedControl onChange={setMode} options={[{ id: 'categories', label: c.category, icon: IconCategory }, { id: 'sources', label: c.source, icon: IconDatabase }]} value={mode} />
|
||||
<div className="catalog-filter-chips" data-expanded={false}>
|
||||
<Button aria-pressed={!selected.length} onClick={() => onSelect(null)} size="xs" variant={!selected.length ? 'default' : 'outline'}>{t.skills.all}</Button>
|
||||
<span aria-hidden className="px-1 text-(--ui-text-quaternary)">/</span>
|
||||
{visible.map(row => <Button aria-pressed={selected.includes(row.value)} key={row.value} onClick={() => onSelect(row.value)} size="xs" variant={selected.includes(row.value) ? 'default' : 'outline'}>{row.label}</Button>)}
|
||||
{overflow.length > 0 && <Popover onOpenChange={setMore} open={more}>
|
||||
<PopoverTrigger asChild><Button aria-label={c.more} size="xs" variant="secondary">{`+${overflow.length}`}</Button></PopoverTrigger>
|
||||
<PopoverContent align="start" className="w-72 max-h-80 overflow-y-auto p-2" variant="menu">
|
||||
<div className="flex flex-wrap gap-1.5">{overflow.map(row => <Button aria-pressed={selected.includes(row.value)} key={row.value} onClick={() => onSelect(row.value)} size="xs" variant={selected.includes(row.value) ? 'default' : 'outline'}>{row.label}</Button>)}</div>
|
||||
</PopoverContent>
|
||||
</Popover>}
|
||||
</div>
|
||||
<div className="catalog-filter-trigger">
|
||||
<span className="text-[0.625rem] font-medium uppercase tracking-wider text-(--ui-text-tertiary)" id={`${panelId}-label`}>{c.filters}{activeCount > 0 && ` · ${activeCount}`}</span>
|
||||
<Popover onOpenChange={setExpanded} open={expanded}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button aria-labelledby={`${panelId}-label`} size="icon-xs" variant={expanded ? 'default' : 'secondary'}>
|
||||
<IconFilter2 />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="end" aria-label={c.filters} className="w-80 max-w-[calc(100vw-2rem)] p-4" side="bottom" variant="menu">
|
||||
<div className="flex max-h-[min(60vh,28rem)] flex-col gap-4 overflow-y-auto" data-catalog-expanded-filters>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="text-sm font-medium">{c.filters}</span>
|
||||
<Button onClick={props.onClear} size="inline" variant="text">{c.clearFilters}</Button>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-xs text-(--ui-text-tertiary)">{c.sortBy}</span>
|
||||
{props.sortControl}
|
||||
</div>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<Button aria-pressed={props.facets.installedOnly} onClick={props.onInstalled} size="xs" variant={props.facets.installedOnly ? 'default' : 'outline'}>{c.installed}</Button>
|
||||
<span className="text-xs text-(--ui-text-tertiary)">{c.results(props.resultCount)}</span>
|
||||
</div>
|
||||
{props.tags.length > 0 && <div className="flex flex-col gap-2">
|
||||
<span className="text-xs text-(--ui-text-tertiary)">{c.tags}</span>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{props.tags.map(row => <Button aria-pressed={props.facets.tags.includes(row.value)} key={row.value} onClick={() => props.onTag(row.value)} size="xs" variant={props.facets.tags.includes(row.value) ? 'default' : 'outline'}>{row.label}</Button>)}
|
||||
</div>
|
||||
</div>}
|
||||
{props.actions && <div className="flex flex-wrap items-center gap-2">{props.actions}</div>}
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Tip } from '@/components/ui/tooltip'
|
||||
import { useI18n } from '@/i18n'
|
||||
import { Loader2 } from '@/lib/icons'
|
||||
|
||||
interface CatalogInstallSwitchProps {
|
||||
name: string
|
||||
installed: boolean
|
||||
installing: boolean
|
||||
disabled: boolean
|
||||
onInstall: () => void
|
||||
}
|
||||
|
||||
/** Turning it on installs. Installed entries normally show their owner's on/off
|
||||
* switch instead; this one only stays checked (and disabled) as a fallback. */
|
||||
export function CatalogInstallSwitch({ name, installed, installing, disabled, onInstall }: CatalogInstallSwitchProps) {
|
||||
const { t } = useI18n()
|
||||
const label = `${installed ? t.catalog.added : t.catalog.add} ${name}`
|
||||
|
||||
return (
|
||||
<Tip label={label}>
|
||||
<span className="inline-flex items-center gap-2">
|
||||
{installing && <Loader2 className="size-3 animate-spin text-(--ui-text-tertiary)" />}
|
||||
<span className="text-xs text-(--ui-text-secondary)">{installed ? t.catalog.added : t.catalog.add}</span>
|
||||
<Switch
|
||||
aria-busy={installing}
|
||||
aria-label={label}
|
||||
checked={installed}
|
||||
disabled={disabled || installing}
|
||||
onCheckedChange={checked => checked && onInstall()}
|
||||
size="xs"
|
||||
/>
|
||||
</span>
|
||||
</Tip>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { type ComponentProps, useId } from 'react'
|
||||
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { useI18n } from '@/i18n'
|
||||
|
||||
/** Visible action copy stays attached to the actual controlled switch. */
|
||||
export function CatalogSwitch(props: ComponentProps<typeof Switch>) {
|
||||
const id = useId()
|
||||
const { t } = useI18n()
|
||||
|
||||
return <label className="catalog-switch relative inline-flex shrink-0 items-center gap-2 text-xs text-(--ui-text-secondary)" htmlFor={id}>
|
||||
<span>{props.checked ? t.plugins.disable : t.plugins.enable}</span>
|
||||
<Switch {...props} id={id} />
|
||||
</label>
|
||||
}
|
||||
@@ -186,6 +186,7 @@ export function CapabilitiesView({
|
||||
{ id: 'connectors', label: t.connectorsPage.title },
|
||||
{ id: 'plugins', label: t.skills.tabPlugins }
|
||||
]}
|
||||
tabsAlign="start"
|
||||
>
|
||||
<div className="flex h-full flex-col">
|
||||
{mode !== 'plugins' && <CapabilityScopeSelector scope={scope} />}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { PluginSettingField } from '@/store/agent-plugins'
|
||||
|
||||
import { collectChanges, initialDraft, PluginSettingsForm } from './plugin-settings-form'
|
||||
|
||||
const FIELDS: PluginSettingField[] = [
|
||||
{
|
||||
description: 'Service endpoint',
|
||||
key: 'api_url',
|
||||
label: 'API URL',
|
||||
required: true,
|
||||
type: 'string',
|
||||
value: 'https://a'
|
||||
},
|
||||
{ description: '', key: 'retries', label: 'Retries', required: false, type: 'number', value: 3 },
|
||||
{ description: '', key: 'verbose', label: 'Verbose', required: false, type: 'boolean', value: false },
|
||||
{
|
||||
choices: ['fast', 'careful'],
|
||||
description: '',
|
||||
key: 'mode',
|
||||
label: 'Mode',
|
||||
required: false,
|
||||
type: 'enum',
|
||||
value: 'fast'
|
||||
},
|
||||
{
|
||||
description: 'Token',
|
||||
env: 'DEMO_API_KEY',
|
||||
has_value: true,
|
||||
key: 'api_key',
|
||||
label: 'API key',
|
||||
required: false,
|
||||
type: 'secret'
|
||||
},
|
||||
{ description: '', key: 'extra', label: 'Extra', required: false, type: 'json', value: { a: 1 } }
|
||||
]
|
||||
|
||||
describe('PluginSettingsForm (#46600, #87934)', () => {
|
||||
afterEach(cleanup)
|
||||
|
||||
it('renders one control per schema type from the table, secrets masked with no value echoed', () => {
|
||||
render(<PluginSettingsForm disabled={false} fields={FIELDS} idPrefix="p" onSave={vi.fn(async () => true)} />)
|
||||
|
||||
expect((screen.getByLabelText('API URL') as HTMLInputElement).value).toBe('https://a')
|
||||
expect((screen.getByLabelText(/^Retries/) as HTMLInputElement).type).toBe('number')
|
||||
expect(screen.getByRole('switch', { name: 'Verbose' }).getAttribute('aria-checked')).toBe('false')
|
||||
expect(screen.getByRole('combobox', { name: 'Mode' })).toBeTruthy()
|
||||
const secret = screen.getByLabelText(/^API key/) as HTMLInputElement
|
||||
expect(secret.type).toBe('password')
|
||||
expect(secret.value).toBe('')
|
||||
expect(secret.placeholder).toContain('set')
|
||||
expect((screen.getByLabelText(/^Extra/) as HTMLTextAreaElement).value).toBe(JSON.stringify({ a: 1 }, null, 2))
|
||||
// Nothing changed yet → nothing to save.
|
||||
expect((screen.getByRole('button', { name: 'Save settings' }) as HTMLButtonElement).disabled).toBe(true)
|
||||
})
|
||||
|
||||
it('submits only what changed, coerced to wire types, secrets routed by env name; clears secrets after save', async () => {
|
||||
const onSave = vi.fn(async () => true)
|
||||
render(<PluginSettingsForm disabled={false} fields={FIELDS} idPrefix="p" onSave={onSave} />)
|
||||
|
||||
fireEvent.change(screen.getByLabelText(/^Retries/), { target: { value: '9' } })
|
||||
fireEvent.click(screen.getByRole('switch', { name: 'Verbose' }))
|
||||
fireEvent.change(screen.getByLabelText(/^API key/), { target: { value: 'sk-x' } })
|
||||
fireEvent.submit(screen.getByTestId('p-settings-form'))
|
||||
|
||||
await vi.waitFor(() =>
|
||||
expect(onSave).toHaveBeenCalledWith({ secrets: { DEMO_API_KEY: 'sk-x' }, values: { retries: 9, verbose: true } })
|
||||
)
|
||||
await vi.waitFor(() => expect((screen.getByLabelText(/^API key/) as HTMLInputElement).value).toBe(''))
|
||||
|
||||
// A value the plugin cannot accept never reaches the backend.
|
||||
expect(() => collectChanges(FIELDS, { ...initialDraft(FIELDS), mode: 'reckless' })).toThrow(/Mode/)
|
||||
expect(() => collectChanges(FIELDS, { ...initialDraft(FIELDS), retries: 'five' })).toThrow(/number/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,299 @@
|
||||
import { type ReactNode, useMemo, useState } from 'react'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Field, FieldHint } from '@/components/ui/field'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { useI18n } from '@/i18n'
|
||||
import type { PluginSettingField, PluginSettingFieldType } from '@/store/agent-plugins'
|
||||
|
||||
// A plugin manifest's `config_schema` rendered as a form. Every non-secret
|
||||
// value is edited as TEXT (the draft) and coerced to its wire type on save, so a
|
||||
// half-typed number never fights the input; secrets are drafted separately and
|
||||
// only ever sent to the `.env` credential route by the caller.
|
||||
|
||||
export type PluginSettingsDraft = Record<string, string>
|
||||
|
||||
export interface PluginSettingsSave {
|
||||
values: Record<string, unknown>
|
||||
secrets: Record<string, string>
|
||||
}
|
||||
|
||||
interface ControlProps {
|
||||
field: PluginSettingField
|
||||
id: string
|
||||
raw: string
|
||||
disabled: boolean
|
||||
onChange: (raw: string) => void
|
||||
/** Localised hint for a secret that already has a stored value. */
|
||||
secretSetHint: string
|
||||
}
|
||||
|
||||
/** What the input shows before the user touches it. */
|
||||
const INITIAL_TEXT: Record<PluginSettingFieldType, (field: PluginSettingField) => string> = {
|
||||
boolean: field => (field.value === true ? 'true' : 'false'),
|
||||
enum: field => String(field.value ?? field.choices?.[0] ?? ''),
|
||||
json: field => (field.value === undefined || field.value === null ? '' : JSON.stringify(field.value, null, 2)),
|
||||
number: field => (field.value === undefined || field.value === null ? '' : String(field.value)),
|
||||
secret: () => '',
|
||||
string: field => String(field.value ?? '')
|
||||
}
|
||||
|
||||
/** Text → wire value; a thrown Error is the field's validation message. */
|
||||
const COERCE: Record<Exclude<PluginSettingFieldType, 'secret'>, (raw: string, field: PluginSettingField) => unknown> = {
|
||||
boolean: raw => raw === 'true',
|
||||
enum: (raw, field) => {
|
||||
if (!field.choices?.includes(raw)) {
|
||||
throw new Error(`${field.label}: not one of ${field.choices?.join(', ') ?? ''}`)
|
||||
}
|
||||
|
||||
return raw
|
||||
},
|
||||
json: (raw, field) => {
|
||||
const parsed: unknown = JSON.parse(raw || 'null')
|
||||
|
||||
if (parsed === null || typeof parsed !== 'object') {
|
||||
throw new Error(`${field.label}: expected a JSON list or object`)
|
||||
}
|
||||
|
||||
return parsed
|
||||
},
|
||||
number: (raw, field) => {
|
||||
const n = Number(raw)
|
||||
|
||||
if (raw.trim() === '' || Number.isNaN(n)) {
|
||||
throw new Error(`${field.label}: expected a number`)
|
||||
}
|
||||
|
||||
return n
|
||||
},
|
||||
string: raw => raw
|
||||
}
|
||||
|
||||
const TEXT_CLASS = 'h-7 text-xs'
|
||||
|
||||
function StringControl({ disabled, id, onChange, raw }: ControlProps) {
|
||||
return (
|
||||
<Input
|
||||
className={TEXT_CLASS}
|
||||
disabled={disabled}
|
||||
id={id}
|
||||
onChange={e => onChange(e.currentTarget.value)}
|
||||
value={raw}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function NumberControl({ disabled, id, onChange, raw }: ControlProps) {
|
||||
return (
|
||||
<Input
|
||||
className={TEXT_CLASS}
|
||||
disabled={disabled}
|
||||
id={id}
|
||||
inputMode="decimal"
|
||||
onChange={e => onChange(e.currentTarget.value)}
|
||||
type="number"
|
||||
value={raw}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function BooleanControl({ disabled, field, id, onChange, raw }: ControlProps) {
|
||||
return (
|
||||
<Switch
|
||||
aria-label={field.label}
|
||||
checked={raw === 'true'}
|
||||
disabled={disabled}
|
||||
id={id}
|
||||
onCheckedChange={on => onChange(on ? 'true' : 'false')}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function EnumControl({ disabled, field, id, onChange, raw }: ControlProps) {
|
||||
return (
|
||||
<Select disabled={disabled} onValueChange={onChange} value={raw}>
|
||||
<SelectTrigger aria-label={field.label} className={TEXT_CLASS} id={id}>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{(field.choices ?? []).map(choice => (
|
||||
<SelectItem key={choice} value={choice}>
|
||||
{choice}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)
|
||||
}
|
||||
|
||||
function SecretControl({ disabled, field, id, onChange, raw, secretSetHint }: ControlProps) {
|
||||
return (
|
||||
<Input
|
||||
autoComplete="off"
|
||||
className={TEXT_CLASS}
|
||||
data-env={field.env}
|
||||
disabled={disabled}
|
||||
id={id}
|
||||
onChange={e => onChange(e.currentTarget.value)}
|
||||
placeholder={field.has_value ? secretSetHint : ''}
|
||||
type="password"
|
||||
value={raw}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function JsonControl({ disabled, id, onChange, raw }: ControlProps) {
|
||||
return (
|
||||
<Textarea
|
||||
className="min-h-16 font-mono text-xs"
|
||||
disabled={disabled}
|
||||
id={id}
|
||||
onChange={e => onChange(e.currentTarget.value)}
|
||||
spellCheck={false}
|
||||
value={raw}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
/** Field type → control. Adding a manifest type means one row here, one in
|
||||
* INITIAL_TEXT and one in COERCE — never a branch in the renderer. */
|
||||
export const FIELD_CONTROLS: Record<PluginSettingFieldType, (props: ControlProps) => ReactNode> = {
|
||||
boolean: BooleanControl,
|
||||
enum: EnumControl,
|
||||
json: JsonControl,
|
||||
number: NumberControl,
|
||||
secret: SecretControl,
|
||||
string: StringControl
|
||||
}
|
||||
|
||||
export function initialDraft(fields: PluginSettingField[]): PluginSettingsDraft {
|
||||
return Object.fromEntries(fields.map(field => [field.key, INITIAL_TEXT[field.type](field)]))
|
||||
}
|
||||
|
||||
/** Split a draft into the two payloads: coerced non-secret values that
|
||||
* CHANGED, and non-blank secrets keyed by their `.env` name. Throws the first
|
||||
* field's validation error. */
|
||||
export function collectChanges(fields: PluginSettingField[], draft: PluginSettingsDraft): PluginSettingsSave {
|
||||
const initial = initialDraft(fields)
|
||||
const values: Record<string, unknown> = {}
|
||||
const secrets: Record<string, string> = {}
|
||||
|
||||
for (const field of fields) {
|
||||
const raw = draft[field.key] ?? ''
|
||||
|
||||
if (field.type === 'secret') {
|
||||
if (raw && field.env) {
|
||||
secrets[field.env] = raw
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if (raw !== initial[field.key]) {
|
||||
values[field.key] = COERCE[field.type](raw, field)
|
||||
}
|
||||
}
|
||||
|
||||
return { values, secrets }
|
||||
}
|
||||
|
||||
export function PluginSettingsForm({
|
||||
fields,
|
||||
idPrefix,
|
||||
disabled,
|
||||
onSave
|
||||
}: {
|
||||
fields: PluginSettingField[]
|
||||
idPrefix: string
|
||||
disabled: boolean
|
||||
/** Resolves true when everything landed; the form then re-seeds from `fields`. */
|
||||
onSave: (changes: PluginSettingsSave) => Promise<boolean>
|
||||
}) {
|
||||
const { t } = useI18n()
|
||||
const s = t.skills.plugins.settingsForm
|
||||
const seed = useMemo(() => initialDraft(fields), [fields])
|
||||
const [draft, setDraft] = useState<PluginSettingsDraft>(seed)
|
||||
const [seedRef, setSeedRef] = useState(seed)
|
||||
const [error, setError] = useState<null | string>(null)
|
||||
|
||||
// The row's refreshed copy re-seeds the form (a saved value becomes the new baseline).
|
||||
if (seedRef !== seed) {
|
||||
setSeedRef(seed)
|
||||
setDraft(seed)
|
||||
}
|
||||
|
||||
const dirty = fields.some(field => (draft[field.key] ?? '') !== seed[field.key])
|
||||
|
||||
const save = async () => {
|
||||
let changes: PluginSettingsSave
|
||||
|
||||
try {
|
||||
changes = collectChanges(fields, draft)
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : String(e))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
setError(null)
|
||||
|
||||
if (await onSave(changes)) {
|
||||
// Secrets are never echoed back; clear them so the placeholder shows "set".
|
||||
setDraft(current =>
|
||||
Object.fromEntries(fields.map(field => [field.key, field.type === 'secret' ? '' : (current[field.key] ?? '')]))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form
|
||||
className="grid gap-3"
|
||||
data-testid={`${idPrefix}-settings-form`}
|
||||
onSubmit={event => {
|
||||
event.preventDefault()
|
||||
void save()
|
||||
}}
|
||||
>
|
||||
<div className="grid items-start gap-3 sm:grid-cols-2">
|
||||
{fields.map(field => {
|
||||
const id = `${idPrefix}-${field.key}`
|
||||
const Control = FIELD_CONTROLS[field.type]
|
||||
|
||||
return (
|
||||
<Field
|
||||
htmlFor={id}
|
||||
key={field.key}
|
||||
label={field.label}
|
||||
optional={!field.required}
|
||||
optionalLabel={s.optional}
|
||||
>
|
||||
<Control
|
||||
disabled={disabled}
|
||||
field={field}
|
||||
id={id}
|
||||
onChange={raw => setDraft(current => ({ ...current, [field.key]: raw }))}
|
||||
raw={draft[field.key] ?? ''}
|
||||
secretSetHint={s.secretSet}
|
||||
/>
|
||||
{(field.description || field.type === 'secret') && (
|
||||
<FieldHint>
|
||||
{field.description}
|
||||
{field.type === 'secret' && field.env ? ` ${s.secretStoredAs(field.env)}` : ''}
|
||||
</FieldHint>
|
||||
)}
|
||||
</Field>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
{error && <FieldHint error>{error}</FieldHint>}
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<Button disabled={disabled || !dirty} size="xs" type="submit" variant="outline">
|
||||
{s.save}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
@@ -1,30 +1,20 @@
|
||||
import { useStore } from '@nanostores/react'
|
||||
import {
|
||||
memo,
|
||||
type ReactNode,
|
||||
type PointerEvent as ReactPointerEvent,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState
|
||||
} from 'react'
|
||||
import { memo, type ReactNode, useCallback, useEffect, useMemo, useState } from 'react'
|
||||
|
||||
import { setEnvVar } from '@/api/config'
|
||||
import { getToolsets, setToolsetEnabled } from '@/api/toolsets'
|
||||
import { useGatewayRequest } from '@/app/gateway/hooks/use-gateway-request'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Codicon } from '@/components/ui/codicon'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Tip } from '@/components/ui/tooltip'
|
||||
import { $pluginRecords, enablePackageDesktopHalf, type PluginRecord, setPluginEnabled } from '@/contrib/plugins-store'
|
||||
import { useContributions } from '@/contrib/react/use-contributions'
|
||||
import { $pluginRecords, type PluginRecord, setPluginEnabled } from '@/contrib/plugins-store'
|
||||
import { discoverRuntimePlugins, uninstallDiskPlugin } from '@/contrib/runtime-loader'
|
||||
import { pluginSettingsRouteHref, SETTINGS_PLUGINS_AREA } from '@/contrib/settings-pages'
|
||||
import type { ProfileScope } from '@/hermes'
|
||||
import { useI18n } from '@/i18n'
|
||||
import { DESKTOP_PLUGIN_TOOLSETS } from '@/lib/desktop-toolsets'
|
||||
import { triggerHaptic } from '@/lib/haptics'
|
||||
import { FolderOpen, Loader2, Monitor, Package, RefreshCw, Trash2 } from '@/lib/icons'
|
||||
import { CATALOG_ORIGIN, CATALOG_PICKER_URL } from '@/lib/plugin-catalog'
|
||||
import { queryClient } from '@/lib/query-client'
|
||||
import { cn } from '@/lib/utils'
|
||||
import {
|
||||
@@ -39,52 +29,26 @@ import {
|
||||
isDesktopRelevantPlugin,
|
||||
loadAgentPlugins,
|
||||
removeAgentPlugin,
|
||||
saveAgentPluginSettings,
|
||||
toggleAgentPlugin,
|
||||
updateAgentPlugin
|
||||
} from '@/store/agent-plugins'
|
||||
import { confirm } from '@/store/confirm'
|
||||
import { notify, notifyError } from '@/store/notifications'
|
||||
import { $paneHeightOverride, setPaneHeightOverride } from '@/store/panes'
|
||||
import { openCatalogPluginInstall } from '@/store/plugin-catalog-install'
|
||||
import { openPluginInstallRequest } from '@/store/plugin-install-request'
|
||||
import { $connection } from '@/store/session'
|
||||
import { $connection, $gatewayState } from '@/store/session'
|
||||
|
||||
import { PanelEmpty } from '../../overlays/panel'
|
||||
import { Pill } from '../../settings/primitives'
|
||||
import { useDeepLinkHighlight } from '../../settings/use-deep-link-highlight'
|
||||
import { CatalogAlert } from '../catalog/catalog-alert'
|
||||
import { CatalogBrowser } from '../catalog/catalog-browser'
|
||||
import { type CatalogEntry, parseCatalog } from '../catalog/catalog-data'
|
||||
import { CatalogSwitch } from '../catalog/catalog-switch'
|
||||
import { TOOLSETS_QUERY_KEY } from '../toolsets/toolsets-data'
|
||||
|
||||
import { mergePluginPackages, type PackageKind, type PluginPackage } from './plugin-packages'
|
||||
|
||||
// The REAL Plugin Catalog page (docs site) embedded as a one-click picker —
|
||||
// the same pattern as the Skills tab's EmbeddedHubPicker. `?embed=picker`
|
||||
// hides the docs chrome and adds "+ Add to this Agent" per card, which posts
|
||||
// { type: 'hermes-plugin-pick', name, repo, sha, subdir, tier, installCmd }
|
||||
// to the parent window. We validate the origin and open the shared
|
||||
// dual-target install modal (agent half → catalog-pinned install into the
|
||||
// scoped profile; desktop half → this app), so unified packages install both
|
||||
// halves in one flow. URLs live in `@/lib/plugin-catalog` so the
|
||||
// `hermes://plugin/install?catalog=` deep link resolves against the same feed.
|
||||
|
||||
// Catalog viewport: persisted through the shared pane store, dragged from the
|
||||
// section's TOP edge ("pull the catalog up"), clamped so neither the catalog
|
||||
// nor the plugin list above can vanish. Same contract as EmbeddedHubPicker.
|
||||
const CATALOG_PANE_ID = 'capabilities-plugin-catalog'
|
||||
const CATALOG_DEFAULT_PX = 380
|
||||
const CATALOG_MIN_PX = 120
|
||||
const CATALOG_MAX_VH = 0.75
|
||||
const CATALOG_COLLAPSED_PX = 4
|
||||
const CATALOG_LIST_RESERVED_PX = 176
|
||||
|
||||
interface PluginPickMessage {
|
||||
installCmd?: string
|
||||
name?: string
|
||||
repo?: string
|
||||
sha?: string
|
||||
subdir?: string
|
||||
tier?: string
|
||||
type?: string
|
||||
}
|
||||
import { PluginSettingsForm } from './plugin-settings-form'
|
||||
|
||||
/** Deep-link anchor for a package row (`/capabilities?tab=plugins&plugin=<key>`).
|
||||
* Accepts the agent key, the agent name, or the desktop record id. */
|
||||
@@ -161,8 +125,7 @@ const SERVER_TONE = {
|
||||
no_interactive_session: 'warn',
|
||||
unknown: 'warn',
|
||||
version_too_old: 'destructive',
|
||||
missing_app: 'destructive',
|
||||
unsupported_gpu: 'destructive'
|
||||
missing_app: 'destructive'
|
||||
} as const satisfies Record<AgentPluginServerState, 'destructive' | 'success' | 'warn'>
|
||||
|
||||
function KindBadge({ kind }: { kind: PackageKind }) {
|
||||
@@ -216,15 +179,11 @@ function ProvenancePill({ pkg }: { pkg: PluginPackage }) {
|
||||
return null
|
||||
}
|
||||
|
||||
/** Column widths shared by the header and every row so the two control
|
||||
* columns line up down the page like a table. */
|
||||
const HALF_COL = 'flex w-36 shrink-0 items-center gap-1.5'
|
||||
|
||||
/** One control cell; `label` is the accessible name for screen readers only
|
||||
* (the visible column label lives once, in the header). */
|
||||
function HalfCell({ label, children }: { label: string; children: ReactNode }) {
|
||||
/** Controls for one installed plugin half in the detail pane. */
|
||||
function HalfCell({ label, labelContent, children }: { label: string; labelContent?: ReactNode; children: ReactNode }) {
|
||||
return (
|
||||
<div aria-label={label} className={HALF_COL} role="cell">
|
||||
<div aria-label={label} className="flex w-full items-center gap-3" role="cell">
|
||||
<span className="min-w-0 flex-1 text-xs text-(--ui-text-tertiary)">{labelContent ?? label}</span>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
@@ -243,7 +202,9 @@ function PackageRow({
|
||||
scope,
|
||||
profile,
|
||||
scopeLabel,
|
||||
scopeSelector,
|
||||
busy,
|
||||
request,
|
||||
onAgentToggle,
|
||||
onAgentUpdate,
|
||||
onAgentRemove,
|
||||
@@ -253,7 +214,9 @@ function PackageRow({
|
||||
scope: null | string
|
||||
profile: ProfileScope
|
||||
scopeLabel: string
|
||||
scopeSelector?: ReactNode
|
||||
busy: boolean
|
||||
request: GatewayRequest
|
||||
onAgentToggle: (row: AgentPluginRow, enable: boolean) => void
|
||||
onAgentUpdate: (row: AgentPluginRow) => void
|
||||
onAgentRemove: (row: AgentPluginRow) => void
|
||||
@@ -264,24 +227,10 @@ function PackageRow({
|
||||
const d = t.settings.plugins
|
||||
const desktop = pkg.desktop
|
||||
const agent = pkg.agent
|
||||
// Settings live in Settings ▸ Plugins: a manifest `config_schema` gets an
|
||||
// automatic page there, a desktop half may register its own. The gear is
|
||||
// the shortcut to that page (#46600, #87934).
|
||||
const settingsPages = useContributions(SETTINGS_PLUGINS_AREA)
|
||||
const desktopSettings = Boolean(desktop && settingsPages.some(page => page.source === `plugin:${desktop.id}`))
|
||||
const agentSettings = Boolean(agent?.key) && Boolean(agent?.settings_schema?.length)
|
||||
const hasSettings = desktopSettings || agentSettings
|
||||
|
||||
const openSettings = () => {
|
||||
// A desktop page absorbs the package's schema form as a sub-page, so its
|
||||
// plugin id is the one entry that covers both halves. The link carries
|
||||
// the profile THIS page has selected: Settings keeps its own scope, and
|
||||
// without the hand-off the page would open (and save) that one instead.
|
||||
const route = desktopSettings ? { plugin: desktop!.id } : { agent: agent!.key! }
|
||||
|
||||
window.location.hash = `#${pluginSettingsRouteHref(route, scope)}`
|
||||
}
|
||||
|
||||
// Manifest `config_schema` → an inline settings form under the row (#46600, #87934).
|
||||
const settingsFields = agent?.settings_schema ?? []
|
||||
const hasSettings = Boolean(agent?.key) && settingsFields.length > 0
|
||||
const [settingsOpen, setSettingsOpen] = useState(false)
|
||||
const [desktopBusy, setDesktopBusy] = useState(false)
|
||||
const desktopOn = desktop ? desktop.status !== 'disabled' : false
|
||||
const agentOn = agent?.status === 'enabled'
|
||||
@@ -351,12 +300,12 @@ function PackageRow({
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className="flex items-center gap-3 border-b border-(--ui-stroke-tertiary) px-3 py-2.5 last:border-b-0"
|
||||
className="flex flex-col gap-5"
|
||||
data-testid={`plugin-row-${pkg.key}`}
|
||||
id={pluginElementId(agent?.key ?? agent?.name ?? desktop?.id ?? pkg.key)}
|
||||
role="row"
|
||||
>
|
||||
<div className="flex min-w-0 flex-1 items-start gap-2" role="cell">
|
||||
<div className="flex w-full min-w-0 flex-1 items-start gap-2" role="cell">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex flex-wrap items-center gap-2 text-[length:var(--conversation-text-font-size)] font-medium text-foreground">
|
||||
<span>{pkg.name}</span>
|
||||
@@ -403,12 +352,19 @@ function PackageRow({
|
||||
</Tip>
|
||||
)}
|
||||
</span>
|
||||
{/* Fixed slot for the settings gear: only plugins with a page in
|
||||
Settings ▸ Plugins (config_schema or a registered page) get one. */}
|
||||
{/* Fixed slot for the settings gear: only plugins whose manifest declares
|
||||
a config_schema get one. */}
|
||||
<span className="flex size-7 shrink-0 items-center justify-center">
|
||||
{hasSettings && (
|
||||
<Tip label={p.settingsToggle(pkg.name)}>
|
||||
<Button aria-label={p.settingsToggle(pkg.name)} onClick={openSettings} size="icon" variant="ghost">
|
||||
<Button
|
||||
aria-expanded={settingsOpen}
|
||||
aria-label={p.settingsToggle(pkg.name)}
|
||||
className={cn(settingsOpen && 'text-foreground')}
|
||||
onClick={() => setSettingsOpen(open => !open)}
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
>
|
||||
<Codicon name="settings-gear" size="0.85rem" />
|
||||
</Button>
|
||||
</Tip>
|
||||
@@ -473,7 +429,7 @@ function PackageRow({
|
||||
)}
|
||||
</HalfCell>
|
||||
|
||||
<HalfCell label={p.halfAgentIn(scopeLabel)}>
|
||||
<HalfCell label={p.halfAgentIn(scopeLabel)} labelContent={scopeSelector}>
|
||||
{agent ? (
|
||||
<>
|
||||
{agent.update_available && (
|
||||
@@ -522,368 +478,341 @@ function PackageRow({
|
||||
)}
|
||||
</HalfCell>
|
||||
</div>
|
||||
{hasSettings && settingsOpen && agent?.key && (
|
||||
<div className="mt-5">
|
||||
<PluginSettingsForm
|
||||
disabled={busy}
|
||||
fields={settingsFields}
|
||||
idPrefix={`plugin-settings-${agent.key}`}
|
||||
onSave={async changes => {
|
||||
const ok = await saveAgentPluginSettings(request, {
|
||||
key: agent.key!,
|
||||
values: changes.values,
|
||||
secrets: changes.secrets,
|
||||
writeSecret: (env, value) => setEnvVar(env, value, profile),
|
||||
failMessage: p.settingsForm.saveFailed(pkg.name),
|
||||
profile: scope
|
||||
})
|
||||
|
||||
if (ok) {
|
||||
notify({ kind: 'success', message: p.settingsForm.saved(pkg.name) })
|
||||
}
|
||||
|
||||
return ok
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
/** THE plugins surface: one row per package. Each row shows its Desktop half
|
||||
* (this app — the same for every profile, gateway, or machine) and its Agent
|
||||
* half (the selected profile's backend). Discovery sits underneath: the live
|
||||
* catalog picker plus Install from Git for anything not in the catalog. */
|
||||
export function PluginActions({ profile }: { profile: ProfileScope }) {
|
||||
const { t } = useI18n()
|
||||
const d = t.settings.plugins
|
||||
const { requestGateway } = useGatewayRequest()
|
||||
const scope = profileParam(profile)
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button onClick={() => openPluginInstallRequest({ profile: scope, repo: '' })} size="xs" variant="textStrong">
|
||||
{d.installModal.installFromGit}
|
||||
</Button>
|
||||
<Tip label={d.openFolder}>
|
||||
<Button aria-label={d.openFolder} onClick={() => void revealPluginsDir()} size="icon-xs" variant="ghost">
|
||||
<FolderOpen />
|
||||
</Button>
|
||||
</Tip>
|
||||
<Tip label={d.rescan}>
|
||||
<Button
|
||||
aria-label={d.rescan}
|
||||
onClick={() => {
|
||||
triggerHaptic('selection')
|
||||
void rescanAll(requestGateway, scope)
|
||||
}}
|
||||
size="icon-xs"
|
||||
variant="ghost"
|
||||
>
|
||||
<RefreshCw />
|
||||
</Button>
|
||||
</Tip>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
/** Installed packages retain both halves' controls in the native detail pane.
|
||||
* Browse shares the Skills catalog; navigation and search belong to the shell. */
|
||||
export const PluginsTab = memo(function PluginsTab({
|
||||
profile,
|
||||
scopeSelector,
|
||||
scopeLabel
|
||||
scopeLabel,
|
||||
query,
|
||||
onQueryChange
|
||||
}: {
|
||||
profile: ProfileScope
|
||||
/** The Capabilities profile selector; rendered in the Agent column header so
|
||||
* it visibly governs only that column. */
|
||||
query?: string
|
||||
onQueryChange?: (value: string) => void
|
||||
/** The profile selector governs only the Agent half, not the app-level Desktop half. */
|
||||
scopeSelector?: ReactNode
|
||||
/** Display name of the selected profile for the Agent column label. */
|
||||
/** Display name of the selected profile for the Agent half label. */
|
||||
scopeLabel?: string
|
||||
}) {
|
||||
const { t } = useI18n()
|
||||
const p = t.skills.plugins
|
||||
const d = t.settings.plugins
|
||||
const { requestGateway } = useGatewayRequest()
|
||||
|
||||
const desktopRecords = useStore($pluginRecords)
|
||||
const agentRows = useStore($agentPlugins)
|
||||
const status = useStore($agentPluginsStatus)
|
||||
const error = useStore($agentPluginsError)
|
||||
const gatewayState = useStore($gatewayState)
|
||||
const busyKey = useStore($agentPluginBusy)
|
||||
|
||||
const scope = profileParam(profile)
|
||||
const label = scopeLabel ?? scope ?? t.skills.plugins.defaultProfile
|
||||
|
||||
useEffect(() => {
|
||||
void loadAgentPlugins(requestGateway, scope)
|
||||
}, [requestGateway, scope])
|
||||
if (gatewayState === 'open') {
|
||||
void loadAgentPlugins(requestGateway, scope)
|
||||
}
|
||||
}, [requestGateway, scope, gatewayState])
|
||||
|
||||
const packages = useMemo(
|
||||
() => mergePluginPackages(Object.values(desktopRecords), agentRows.filter(isDesktopRelevantPlugin)),
|
||||
[agentRows, desktopRecords]
|
||||
)
|
||||
|
||||
useDeepLinkHighlight({ param: 'plugin', ready: () => true, elementId: pluginElementId })
|
||||
const [selectedEntryId, setSelectedEntryId] = useState<string | null>(null)
|
||||
|
||||
// Catalog picker viewport (persisted height, collapse toggle, top-edge sash).
|
||||
const heightOverride = useStore($paneHeightOverride(CATALOG_PANE_ID))
|
||||
const height = heightOverride ?? CATALOG_DEFAULT_PX
|
||||
const open = height > CATALOG_COLLAPSED_PX
|
||||
const [pickerMounted, setPickerMounted] = useState(open)
|
||||
const [dragging, setDragging] = useState(false)
|
||||
const sectionRef = useRef<HTMLElement>(null)
|
||||
const packageForTarget = useCallback(
|
||||
(target: string) =>
|
||||
packages.find(pkg => [pkg.key, pkg.agent?.key, pkg.agent?.name, pkg.desktop?.id].includes(target)),
|
||||
[packages]
|
||||
)
|
||||
|
||||
if (open && !pickerMounted) {
|
||||
setPickerMounted(true)
|
||||
}
|
||||
useDeepLinkHighlight({
|
||||
param: 'plugin',
|
||||
ready: target => Boolean(packageForTarget(target)),
|
||||
elementId: target => {
|
||||
const pkg = packageForTarget(target)
|
||||
|
||||
const startDrag = (event: ReactPointerEvent<HTMLDivElement>) => {
|
||||
if (event.button !== 0) {
|
||||
return
|
||||
}
|
||||
return pluginElementId(pkg?.agent?.key ?? pkg?.agent?.name ?? pkg?.desktop?.id ?? target)
|
||||
},
|
||||
onResolve: useCallback(
|
||||
(target: string) => {
|
||||
const pkg = packageForTarget(target)
|
||||
|
||||
event.preventDefault()
|
||||
const startY = event.clientY
|
||||
const startHeight = height
|
||||
const column = sectionRef.current?.parentElement
|
||||
const columnMax = column ? column.clientHeight - CATALOG_LIST_RESERVED_PX : Number.POSITIVE_INFINITY
|
||||
const max = Math.max(CATALOG_MIN_PX, Math.round(Math.min(window.innerHeight * CATALOG_MAX_VH, columnMax)))
|
||||
setDragging(true)
|
||||
|
||||
const onMove = (move: globalThis.PointerEvent) => {
|
||||
setPaneHeightOverride(
|
||||
CATALOG_PANE_ID,
|
||||
Math.round(Math.min(max, Math.max(CATALOG_MIN_PX, startHeight + (startY - move.clientY))))
|
||||
)
|
||||
}
|
||||
|
||||
const onUp = () => {
|
||||
window.removeEventListener('pointermove', onMove)
|
||||
setDragging(false)
|
||||
}
|
||||
|
||||
window.addEventListener('pointermove', onMove)
|
||||
window.addEventListener('pointerup', onUp, { once: true })
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const onMessage = (event: MessageEvent) => {
|
||||
if (event.origin !== CATALOG_ORIGIN) {
|
||||
return
|
||||
}
|
||||
|
||||
const data = event.data as null | PluginPickMessage
|
||||
|
||||
if (!data || data.type !== 'hermes-plugin-pick' || !data.name || !data.repo) {
|
||||
return
|
||||
}
|
||||
|
||||
// Already-installed short-circuit + the dialog itself live in the shared
|
||||
// helper so a catalog deep link behaves identically to this pick.
|
||||
openCatalogPluginInstall(
|
||||
{
|
||||
name: String(data.name),
|
||||
repo: String(data.repo),
|
||||
sha: data.sha ? String(data.sha) : undefined,
|
||||
subdir: data.subdir ? String(data.subdir) : undefined
|
||||
},
|
||||
scope
|
||||
)
|
||||
}
|
||||
|
||||
window.addEventListener('message', onMessage)
|
||||
|
||||
return () => window.removeEventListener('message', onMessage)
|
||||
}, [open, p, scope])
|
||||
if (pkg) {
|
||||
onQueryChange?.('')
|
||||
setSelectedEntryId(`installed:${pkg.key}`)
|
||||
}
|
||||
},
|
||||
[onQueryChange, packageForTarget]
|
||||
)
|
||||
})
|
||||
|
||||
const agentBusy = (row: AgentPluginRow) => busyKey === (row.key ?? row.name) || busyKey === row.name
|
||||
|
||||
return (
|
||||
<div className="flex h-full min-h-0 flex-col">
|
||||
<div className="min-h-32 flex-1 overflow-y-auto">
|
||||
{/* Header: what the two columns mean, and the controls that act on
|
||||
the whole page (install, folder, rescan). */}
|
||||
<div className="flex flex-wrap items-start justify-between gap-3 px-3 pt-3 pb-2">
|
||||
<p className="min-w-0 flex-1 text-[length:var(--conversation-caption-font-size)] text-(--ui-text-tertiary)">
|
||||
{p.pageBlurb}
|
||||
</p>
|
||||
<div className="flex shrink-0 items-center gap-1">
|
||||
<Button
|
||||
onClick={() => openPluginInstallRequest({ profile: scope, repo: '' })}
|
||||
size="sm"
|
||||
type="button"
|
||||
variant="secondary"
|
||||
>
|
||||
{d.installModal.installFromGit}
|
||||
</Button>
|
||||
<Tip label={d.openFolder}>
|
||||
<Button
|
||||
aria-label={d.openFolder}
|
||||
onClick={() => void revealPluginsDir()}
|
||||
size="icon"
|
||||
type="button"
|
||||
variant="ghost"
|
||||
>
|
||||
<FolderOpen className="size-3.5" />
|
||||
</Button>
|
||||
</Tip>
|
||||
<Tip label={d.rescan}>
|
||||
<Button
|
||||
aria-label={d.rescan}
|
||||
onClick={() => {
|
||||
triggerHaptic('selection')
|
||||
void rescanAll(requestGateway, scope)
|
||||
}}
|
||||
size="icon"
|
||||
type="button"
|
||||
variant="ghost"
|
||||
>
|
||||
<RefreshCw className="size-3.5" />
|
||||
</Button>
|
||||
</Tip>
|
||||
</div>
|
||||
</div>
|
||||
const installedEntries = useMemo(
|
||||
() =>
|
||||
parseCatalog(
|
||||
'plugins',
|
||||
packages.map(pkg => ({
|
||||
name: pkg.name,
|
||||
identifier: pkg.key,
|
||||
description: pkg.description,
|
||||
category: pkg.kind === 'desktop' ? 'desktop' : 'general',
|
||||
tier: pkg.agent?.catalog_tier ?? pkg.agent?.source ?? pkg.desktop?.kind ?? '',
|
||||
repo: pkg.desktop?.packageOrigin?.repo ?? '',
|
||||
sha: pkg.agent?.installed_sha ?? pkg.desktop?.packageOrigin?.sha ?? '',
|
||||
version: pkg.agent?.version ?? ''
|
||||
}))
|
||||
).map(entry => ({ ...entry, id: `installed:${entry.identifier}` })),
|
||||
[packages]
|
||||
)
|
||||
|
||||
{status === 'error' ? (
|
||||
<PanelEmpty
|
||||
action={
|
||||
<Button onClick={() => void loadAgentPlugins(requestGateway, scope)} size="sm">
|
||||
{t.skills.refresh}
|
||||
</Button>
|
||||
}
|
||||
description={error ?? undefined}
|
||||
icon="error"
|
||||
title={p.loadFailed}
|
||||
/>
|
||||
) : packages.length === 0 && status === 'ready' ? (
|
||||
<p className="px-3 py-3 text-[length:var(--conversation-caption-font-size)] text-(--ui-text-tertiary)">
|
||||
{p.emptyAll} {p.emptyHint}
|
||||
</p>
|
||||
) : (
|
||||
<div className="flex flex-col" role="table">
|
||||
{/* Column header: the visible labels for the two control columns,
|
||||
aligned with the cells below. The profile selector sits INSIDE
|
||||
the Agent header so it visibly governs only that column. */}
|
||||
<div
|
||||
className="flex items-center gap-3 border-y border-(--ui-stroke-tertiary) bg-(--ui-bg-quinary) px-3 py-1.5 text-[0.68rem] text-(--ui-text-tertiary)"
|
||||
role="row"
|
||||
>
|
||||
<div className="min-w-0 flex-1" role="columnheader" />
|
||||
<div className={HALF_COL} role="columnheader">
|
||||
<Monitor aria-hidden className="size-3.5 shrink-0" />
|
||||
<Tip label={p.halfDesktopHint}>
|
||||
<span className="font-medium">{p.halfDesktop}</span>
|
||||
</Tip>
|
||||
</div>
|
||||
<div className={HALF_COL} role="columnheader">
|
||||
<Package aria-hidden className="size-3.5 shrink-0" />
|
||||
{scopeSelector ?? <span className="truncate font-medium">{p.halfAgentIn(label)}</span>}
|
||||
</div>
|
||||
</div>
|
||||
{packages.map(pkg => (
|
||||
<PackageRow
|
||||
busy={pkg.agent ? agentBusy(pkg.agent) : false}
|
||||
key={pkg.key}
|
||||
onAgentRemove={row => {
|
||||
void confirm({
|
||||
confirmLabel: p.uninstall,
|
||||
description: p.uninstallConfirmBody(row.name, label),
|
||||
destructive: true,
|
||||
title: p.uninstallConfirmTitle(row.name)
|
||||
}).then(async ok => {
|
||||
if (!ok) {
|
||||
return
|
||||
}
|
||||
const packageById = useMemo(() => new Map(packages.map(pkg => [`installed:${pkg.key}`, pkg])), [packages])
|
||||
|
||||
if (await removeAgentPlugin(requestGateway, row.name, p.uninstallFailed(row.name), scope)) {
|
||||
notify({ kind: 'success', message: p.uninstalled(row.name) })
|
||||
// Prunes the app-level desktop half whose source package just went away.
|
||||
void rescanAll(requestGateway, scope)
|
||||
}
|
||||
})
|
||||
}}
|
||||
onAgentToggle={(row, enable) => {
|
||||
if (!row.key) {
|
||||
return
|
||||
}
|
||||
const installedByCatalogName = useMemo(() => {
|
||||
const byName = new Map<string, CatalogEntry>()
|
||||
|
||||
void toggleAgentPlugin(requestGateway, row.key, enable, p.toggleFailed(row.name), scope).then(ok => {
|
||||
// Turning a unified package on turns its desktop half on too
|
||||
// (unless the user switched that half off on purpose).
|
||||
// Off stays per half: the desktop half is app-wide, and
|
||||
// another profile may still run the agent half.
|
||||
const half = pkg.desktop?.packageName
|
||||
for (const entry of installedEntries) {
|
||||
const pkg = packageById.get(entry.id)
|
||||
const name = pkg?.agent?.catalog_name ?? pkg?.desktop?.packageOrigin?.catalogName
|
||||
|
||||
if (ok && enable && half) {
|
||||
void enablePackageDesktopHalf(half, { keepUserChoice: true })
|
||||
}
|
||||
})
|
||||
}}
|
||||
onAgentUpdate={row => {
|
||||
const finish = (outcome: AgentPluginUpdateOutcome) => {
|
||||
if (outcome.kind === 'applied') {
|
||||
notify({ kind: 'success', message: p.updated(row.name) })
|
||||
void rescanAll(requestGateway, scope)
|
||||
}
|
||||
}
|
||||
if (name) {
|
||||
byName.set(name, entry)
|
||||
}
|
||||
}
|
||||
|
||||
void updateAgentPlugin(requestGateway, row.name, p.updateFailed(row.name), scope).then(
|
||||
async outcome => {
|
||||
if (outcome.kind !== 'consent') {
|
||||
finish(outcome)
|
||||
return byName
|
||||
}, [installedEntries, packageById])
|
||||
|
||||
return
|
||||
}
|
||||
const matchInstalled = useCallback(
|
||||
(entry: CatalogEntry) => installedByCatalogName.get(entry.name),
|
||||
[installedByCatalogName]
|
||||
)
|
||||
|
||||
// The new pin widens the plugin (tools, hooks, deps, capabilities, a Desktop
|
||||
// half); the backend changed nothing until the user confirms the delta.
|
||||
const ok = await confirm({
|
||||
confirmLabel: p.updateConsentConfirm,
|
||||
description: [p.updateConsentBody(row.name, outcome.sha), ...outcome.deltaLines].join('\n'),
|
||||
title: p.updateConsentTitle(row.name)
|
||||
})
|
||||
const isInstalled = (entry: CatalogEntry) => packageById.has(entry.id)
|
||||
|
||||
if (ok) {
|
||||
finish(await updateAgentPlugin(requestGateway, row.name, p.updateFailed(row.name), scope, true))
|
||||
}
|
||||
}
|
||||
)
|
||||
}}
|
||||
onDesktopRemove={record => {
|
||||
void confirm({
|
||||
confirmLabel: p.uninstall,
|
||||
description: p.uninstallDesktopConfirmBody(record.name),
|
||||
destructive: true,
|
||||
title: p.uninstallConfirmTitle(record.name)
|
||||
}).then(async ok => {
|
||||
if (!ok) {
|
||||
return
|
||||
}
|
||||
const handleAgentRemove = useCallback(
|
||||
(row: AgentPluginRow) => {
|
||||
void confirm({
|
||||
confirmLabel: p.uninstall,
|
||||
description: p.uninstallConfirmBody(row.name, label),
|
||||
destructive: true,
|
||||
title: p.uninstallConfirmTitle(row.name)
|
||||
}).then(async ok => {
|
||||
if (!ok) {
|
||||
return
|
||||
}
|
||||
|
||||
const result = await uninstallDiskPlugin(record.id)
|
||||
if (await removeAgentPlugin(requestGateway, row.name, p.uninstallFailed(row.name), scope)) {
|
||||
notify({ kind: 'success', message: p.uninstalled(row.name) })
|
||||
// Prunes the app-level desktop half whose source package just went away.
|
||||
void rescanAll(requestGateway, scope)
|
||||
}
|
||||
})
|
||||
},
|
||||
[label, p, requestGateway, scope]
|
||||
)
|
||||
|
||||
if (result.ok) {
|
||||
notify({ kind: 'success', message: p.uninstalledDesktop(record.name) })
|
||||
} else {
|
||||
notifyError(result.error, p.uninstallFailed(record.name))
|
||||
}
|
||||
})
|
||||
}}
|
||||
pkg={pkg}
|
||||
profile={profile}
|
||||
scope={scope}
|
||||
scopeLabel={label}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
const handleDesktopRemove = useCallback(
|
||||
(record: PluginRecord) => {
|
||||
void confirm({
|
||||
confirmLabel: p.uninstall,
|
||||
description: p.uninstallDesktopConfirmBody(record.name),
|
||||
destructive: true,
|
||||
title: p.uninstallConfirmTitle(record.name)
|
||||
}).then(async ok => {
|
||||
if (!ok) {
|
||||
return
|
||||
}
|
||||
|
||||
<section
|
||||
className="relative flex min-h-9 flex-col overflow-hidden border-t border-(--ui-stroke-secondary)"
|
||||
ref={sectionRef}
|
||||
const result = await uninstallDiskPlugin(record.id)
|
||||
|
||||
if (result.ok) {
|
||||
notify({ kind: 'success', message: p.uninstalledDesktop(record.name) })
|
||||
} else {
|
||||
notifyError(result.error, p.uninstallFailed(record.name))
|
||||
}
|
||||
})
|
||||
},
|
||||
[p]
|
||||
)
|
||||
|
||||
// The card switch turns the whole package on or off, like a skill's; per-half
|
||||
// switches and uninstall (trash + confirm) live in the detail's PackageRow.
|
||||
const packageSwitch = (pkg: PluginPackage) => {
|
||||
const { agent, desktop } = pkg
|
||||
|
||||
const setEnabled = (enable: boolean) => {
|
||||
if (agent?.key) {
|
||||
void toggleAgentPlugin(requestGateway, agent.key, enable, p.toggleFailed(agent.name), scope)
|
||||
}
|
||||
|
||||
if (desktop) {
|
||||
void setPluginEnabled(desktop.id, enable)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<CatalogSwitch
|
||||
aria-label={pkg.name}
|
||||
checked={agent ? agent.status === 'enabled' : desktop?.status !== 'disabled'}
|
||||
disabled={agent ? !agent.key || agentBusy(agent) : false}
|
||||
onCheckedChange={setEnabled}
|
||||
size="xs"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const notice =
|
||||
status === 'error' ? (
|
||||
<CatalogAlert
|
||||
onRetry={() => void loadAgentPlugins(requestGateway, scope)}
|
||||
retryLabel={t.catalog.retry}
|
||||
title={p.loadFailed}
|
||||
>
|
||||
<div
|
||||
className="group/catsash absolute inset-x-0 top-0 z-10 h-1 -translate-y-1/2 cursor-row-resize"
|
||||
data-testid="plugin-catalog-sash"
|
||||
onDoubleClick={() => setPaneHeightOverride(CATALOG_PANE_ID, undefined)}
|
||||
onPointerDown={startDrag}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
'absolute inset-x-0 top-1/2 h-px -translate-y-1/2 transition-colors',
|
||||
dragging ? 'bg-(--ui-stroke-secondary)' : 'group-hover/catsash:bg-(--ui-stroke-secondary)'
|
||||
)}
|
||||
{error}
|
||||
</CatalogAlert>
|
||||
) : null
|
||||
|
||||
return (
|
||||
<CatalogBrowser
|
||||
headerActions={<PluginActions profile={profile} />}
|
||||
installedEntries={installedEntries}
|
||||
installedPending={status !== 'ready'}
|
||||
isInstalled={isInstalled}
|
||||
kind="plugins"
|
||||
matchInstalled={matchInstalled}
|
||||
notice={notice}
|
||||
onInstall={entry => openCatalogPluginInstall(entry, scope)}
|
||||
onQueryChange={onQueryChange}
|
||||
query={query}
|
||||
renderInstalledAction={entry => {
|
||||
const pkg = packageById.get(entry.id)
|
||||
|
||||
return pkg ? packageSwitch(pkg) : null
|
||||
}}
|
||||
renderInstalledDetail={entry => {
|
||||
const pkg = packageById.get(entry.id)
|
||||
|
||||
if (!pkg) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<PackageRow
|
||||
busy={pkg.agent ? agentBusy(pkg.agent) : false}
|
||||
key={pkg.key}
|
||||
onAgentRemove={handleAgentRemove}
|
||||
onAgentToggle={(row, enable) => {
|
||||
if (!row.key) {
|
||||
return
|
||||
}
|
||||
|
||||
void toggleAgentPlugin(requestGateway, row.key, enable, p.toggleFailed(row.name), scope)
|
||||
}}
|
||||
onAgentUpdate={row => {
|
||||
const finish = (outcome: AgentPluginUpdateOutcome) => {
|
||||
if (outcome.kind === 'applied') {
|
||||
notify({ kind: 'success', message: p.updated(row.name) })
|
||||
void rescanAll(requestGateway, scope)
|
||||
}
|
||||
}
|
||||
|
||||
void updateAgentPlugin(requestGateway, row.name, p.updateFailed(row.name), scope).then(async outcome => {
|
||||
if (outcome.kind !== 'consent') {
|
||||
finish(outcome)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// The new pin widens the plugin (tools, hooks, deps, capabilities, a Desktop
|
||||
// half); the backend changed nothing until the user confirms the delta.
|
||||
const ok = await confirm({
|
||||
confirmLabel: p.updateConsentConfirm,
|
||||
description: [p.updateConsentBody(row.name, outcome.sha), ...outcome.deltaLines].join('\n'),
|
||||
title: p.updateConsentTitle(row.name)
|
||||
})
|
||||
|
||||
if (ok) {
|
||||
finish(await updateAgentPlugin(requestGateway, row.name, p.updateFailed(row.name), scope, true))
|
||||
}
|
||||
})
|
||||
}}
|
||||
onDesktopRemove={handleDesktopRemove}
|
||||
pkg={pkg}
|
||||
profile={profile}
|
||||
request={requestGateway}
|
||||
scope={scope}
|
||||
scopeLabel={label}
|
||||
scopeSelector={scopeSelector}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center justify-between px-3 py-1.5">
|
||||
<span className="text-[0.62rem] font-medium tracking-wide uppercase text-(--ui-text-quaternary)">
|
||||
{p.catalogTitle}
|
||||
</span>
|
||||
<Button onClick={() => setPaneHeightOverride(CATALOG_PANE_ID, open ? 0 : undefined)} size="xs" variant="text">
|
||||
{open ? p.catalogHide : p.catalogBrowse}
|
||||
</Button>
|
||||
</div>
|
||||
{pickerMounted && (
|
||||
<div className={cn('flex min-h-0 flex-col gap-1 px-3 pb-2', !open && 'hidden')}>
|
||||
<div
|
||||
style={{
|
||||
border: '1px solid var(--ui-stroke-secondary)',
|
||||
borderRadius: 8,
|
||||
flex: `0 1 ${height}px`,
|
||||
maxWidth: '100%',
|
||||
minHeight: 0,
|
||||
minWidth: 320,
|
||||
overflow: 'hidden',
|
||||
position: 'relative',
|
||||
width: '100%'
|
||||
}}
|
||||
>
|
||||
<iframe
|
||||
sandbox="allow-scripts allow-same-origin"
|
||||
src={CATALOG_PICKER_URL}
|
||||
style={{
|
||||
background: 'transparent',
|
||||
border: 'none',
|
||||
height: '133.34%',
|
||||
pointerEvents: dragging ? 'none' : 'auto',
|
||||
transform: 'scale(0.75)',
|
||||
transformOrigin: 'top left',
|
||||
width: '133.34%'
|
||||
}}
|
||||
title={p.catalogTitle}
|
||||
/>
|
||||
</div>
|
||||
<p className="shrink-0 px-1 text-[0.65rem] leading-4 text-(--ui-text-quaternary)">{p.catalogHint}</p>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}}
|
||||
selectedEntryId={selectedEntryId}
|
||||
/>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,387 +1,358 @@
|
||||
import { compactNumber } from '@hermes/shared'
|
||||
import { useStore } from '@nanostores/react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { type ReactNode, useCallback, useMemo, useState } from 'react'
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
|
||||
import { ArchiveSkillConfirmDialog } from '@/app/learning/archive-skill-confirm-dialog'
|
||||
import { CodeEditor } from '@/components/chat/code-editor'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
editLearningNode,
|
||||
getLearningNode,
|
||||
getOfficialSkills,
|
||||
type ProfileScope,
|
||||
profileScopeKey,
|
||||
setSkillEnabled
|
||||
} from '@/hermes'
|
||||
import { Loader } from '@/components/ui/loader'
|
||||
import { editLearningNode, getLearningNode, type ProfileScope, profileScopeKey, setSkillEnabled } from '@/hermes'
|
||||
import { useI18n } from '@/i18n'
|
||||
import { Loader2 } from '@/lib/icons'
|
||||
import { Codecs, persistentAtom } from '@/lib/persisted'
|
||||
import { queryClient } from '@/lib/query-client'
|
||||
import { invalidateSlashCompletions } from '@/lib/slash-completion-cache'
|
||||
import { useStoreSelector } from '@/lib/use-session-slice'
|
||||
import { $hubActions, installHubSkill, notifyHubActionFailed, OFFICIAL_SKILLS_KEY } from '@/store/hub-actions'
|
||||
import { notify, notifyError } from '@/store/notifications'
|
||||
import type { OfficialSkillInfo, SkillInfo } from '@/types/hermes'
|
||||
import type { SkillInfo } from '@/types/hermes'
|
||||
|
||||
import {
|
||||
CapRow,
|
||||
DetailColumn,
|
||||
DetailPane,
|
||||
ListColumn,
|
||||
ListStrip,
|
||||
ListStripMenu,
|
||||
type ListStripMenuToggle,
|
||||
MasterDetail
|
||||
} from '../../master-detail'
|
||||
import { prettyName } from '../../settings/helpers'
|
||||
import { CapabilityEmpty, SortButton } from '../primitives'
|
||||
import { DetailPane, ListStripMenu, type ListStripMenuToggle } from '../../master-detail'
|
||||
import { CatalogAlert } from '../catalog/catalog-alert'
|
||||
import { CatalogSwitch } from '../catalog/catalog-switch'
|
||||
import { SkillCatalog } from '../catalog/skill-catalog'
|
||||
import { UpdateSkillsButton } from '../catalog/update-skills-button'
|
||||
|
||||
import { OfficialSkillDetail } from './official-skill-detail'
|
||||
import { SkillDetail } from './skill-detail'
|
||||
import { categoryFor, filteredOfficial, filteredSkills, skillsQueryKey, usageOf } from './skills-data'
|
||||
|
||||
// Sort direction for the Skills list — persisted so the tab remembers
|
||||
// most/least-used across navigations and restarts.
|
||||
const $skillsSortDesc = persistentAtom('hermes.desktop.capabilities.skillsSortDesc', true, Codecs.bool)
|
||||
|
||||
// Row subtitle: category, with non-default origins badged.
|
||||
function skillSubtitle(skill: SkillInfo): ReactNode {
|
||||
const category = prettyName(categoryFor(skill))
|
||||
const provenance = skill.provenance
|
||||
|
||||
return (
|
||||
<>
|
||||
<span className="truncate">{category}</span>
|
||||
{provenance === 'agent' && (
|
||||
<Badge className="shrink-0 normal-case" variant="default">
|
||||
learned
|
||||
</Badge>
|
||||
)}
|
||||
{provenance === 'hub' && (
|
||||
<Badge className="shrink-0 normal-case" variant="muted">
|
||||
hub
|
||||
</Badge>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
import { skillsQueryKey, usageOf } from './skills-data'
|
||||
|
||||
interface SkillsTabProps {
|
||||
/** The scope's skill list, straight from the shell's query. */
|
||||
skills: SkillInfo[]
|
||||
/** The (connection, profile) scope every read and write routes to. */
|
||||
/** Every read and write targets this connection/profile pair. */
|
||||
profile: ProfileScope
|
||||
query: string
|
||||
/** Page-level refresh: a saved skill edit reloads the same way the refresh
|
||||
* hotkey does, counts and slash completions included. */
|
||||
onQueryChange?: (value: string) => void
|
||||
installedPending?: boolean
|
||||
installedError?: unknown
|
||||
onRefresh: () => void
|
||||
}
|
||||
|
||||
/** The Skills tab: installed skills, official optional skills, and learned-skill editing. */
|
||||
export function SkillsTab({ onRefresh, profile, query, skills }: SkillsTabProps) {
|
||||
/** One management controller for the unified catalog, remounted on scope changes
|
||||
* so an old profile's editor, confirmation or pending write cannot enter another. */
|
||||
export function SkillsTab(props: SkillsTabProps) {
|
||||
return <ScopedSkillsTab key={profileScopeKey(props.profile)} {...props} />
|
||||
}
|
||||
|
||||
function ScopedSkillsTab({
|
||||
onRefresh,
|
||||
profile,
|
||||
query,
|
||||
onQueryChange,
|
||||
skills,
|
||||
installedPending = false,
|
||||
installedError
|
||||
}: SkillsTabProps) {
|
||||
const { t } = useI18n()
|
||||
const skillsSortDesc = useStore($skillsSortDesc)
|
||||
const [bulkBusy, setBulkBusy] = useState(false)
|
||||
const [selectedSkill, setSelectedSkill] = useState<string | null>(null)
|
||||
const [selectedOfficial, setSelectedOfficial] = useState<string | null>(null)
|
||||
|
||||
const { data: officialData } = useQuery({
|
||||
queryKey: [...OFFICIAL_SKILLS_KEY, profileScopeKey(profile)],
|
||||
queryFn: () => getOfficialSkills(profile),
|
||||
staleTime: 60_000,
|
||||
retry: false
|
||||
})
|
||||
|
||||
// Learned/local skills are editable + archivable, mirroring the memory
|
||||
// graph (same /api/learning/node endpoints — delete archives, restorable
|
||||
// via `hermes curator restore`).
|
||||
const [skillEditor, setSkillEditor] = useState<null | { content: string; name: string }>(null)
|
||||
const mounted = useRef(true)
|
||||
const mutationBusy = useRef(false)
|
||||
const editorRequest = useRef(0)
|
||||
const saving = useRef(false)
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [skillEditor, setSkillEditor] = useState<null | { name: string }>(null)
|
||||
const [skillDraft, setSkillDraft] = useState('')
|
||||
const [skillSaving, setSkillSaving] = useState(false)
|
||||
const [archiveTarget, setArchiveTarget] = useState<null | string>(null)
|
||||
|
||||
// Optimistic write-through against the scoped Skills key: toggles/bulk/
|
||||
// archive repaint instantly; the next background refetch reconciles.
|
||||
// eslint-disable-next-line no-restricted-syntax -- lifecycle guard drops stale async completions; it does not mirror an atom
|
||||
useEffect(() => {
|
||||
mounted.current = true
|
||||
|
||||
return () => {
|
||||
mounted.current = false
|
||||
editorRequest.current += 1
|
||||
}
|
||||
}, [])
|
||||
|
||||
const setSkills = useCallback(
|
||||
(fn: (cur: SkillInfo[] | undefined) => SkillInfo[] | undefined) =>
|
||||
queryClient.setQueryData<SkillInfo[]>(skillsQueryKey(profile), prev => fn(prev) ?? prev),
|
||||
[profile]
|
||||
)
|
||||
|
||||
const visibleSkills = useMemo(() => filteredSkills(skills, query, skillsSortDesc), [query, skills, skillsSortDesc])
|
||||
|
||||
// Installed-name set stays unfiltered so search cannot make a skill look absent.
|
||||
const installedSkillNames = useMemo(() => new Set(skills.map(s => s.name)), [skills])
|
||||
|
||||
const visibleOfficial = useMemo(() => {
|
||||
const catalog = (officialData?.skills ?? []).filter(
|
||||
skill => !skill.installed && !installedSkillNames.has(skill.name)
|
||||
)
|
||||
|
||||
return filteredOfficial(catalog, query)
|
||||
}, [installedSkillNames, officialData, query])
|
||||
|
||||
const runningInstallKey = useStoreSelector($hubActions, actions =>
|
||||
Object.keys(actions)
|
||||
.filter(key => actions[key]?.running)
|
||||
.sort()
|
||||
.join('|')
|
||||
)
|
||||
|
||||
const runningInstalls = useMemo(() => new Set(runningInstallKey.split('|').filter(Boolean)), [runningInstallKey])
|
||||
|
||||
// Keep a valid selection: fall back to the first visible row when the
|
||||
// current selection is filtered out (or nothing is selected yet).
|
||||
const activeSkill = useMemo(
|
||||
() => visibleSkills.find(s => s.name === selectedSkill) ?? visibleSkills[0] ?? null,
|
||||
[selectedSkill, visibleSkills]
|
||||
)
|
||||
|
||||
const activeOfficial = useMemo(
|
||||
() => visibleOfficial.find(skill => skill.identifier === selectedOfficial) ?? null,
|
||||
[selectedOfficial, visibleOfficial]
|
||||
)
|
||||
|
||||
function handleInstallOfficial(skill: OfficialSkillInfo) {
|
||||
notify({ kind: 'success', title: t.skills.hub.installStarted(skill.name), message: t.skills.hub.actionLog })
|
||||
void installHubSkill(skill.identifier, profile).catch(err =>
|
||||
notifyHubActionFailed(err, t.skills.hub.actionFailed, skill.name, profile)
|
||||
)
|
||||
}
|
||||
|
||||
async function handleToggleSkill(skill: SkillInfo, enabled: boolean) {
|
||||
setSkills(current => current?.map(row => (row.name === skill.name ? { ...row, enabled } : row)) ?? current)
|
||||
|
||||
try {
|
||||
await setSkillEnabled(skill.name, enabled, profile)
|
||||
// A disabled skill loses its `/name` command, so the composer's cached
|
||||
// `/` list has to be dropped along with the row repaint.
|
||||
invalidateSlashCompletions()
|
||||
} catch (err) {
|
||||
setSkills(
|
||||
current => current?.map(row => (row.name === skill.name ? { ...row, enabled: !enabled } : row)) ?? current
|
||||
)
|
||||
notifyError(err, t.skills.failedToUpdate(skill.name))
|
||||
}
|
||||
}
|
||||
|
||||
// Sequential on purpose: each toggle is a config read-modify-write on the
|
||||
// backend; parallel calls would race the disabled-list save.
|
||||
async function bulkApply(targets: SkillInfo[], enabled: boolean) {
|
||||
if (bulkBusy || targets.length === 0) {
|
||||
// The backend saves one disabled-list config value: serialize individual and
|
||||
// bulk changes together, not merely the members of a bulk action.
|
||||
async function applyEnabled(targets: SkillInfo[], enabled: boolean, bulk = false) {
|
||||
if (mutationBusy.current || installedPending || installedError || targets.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
setBulkBusy(true)
|
||||
|
||||
mutationBusy.current = true
|
||||
setBusy(true)
|
||||
let done = 0
|
||||
|
||||
try {
|
||||
await queryClient.cancelQueries({ queryKey: skillsQueryKey(profile), exact: true })
|
||||
|
||||
for (const row of targets) {
|
||||
await setSkillEnabled(row.name, enabled, profile)
|
||||
setSkills(cur => cur?.map(r => (r.name === row.name ? { ...r, enabled } : r)) ?? cur)
|
||||
done += 1
|
||||
if (!mounted.current) {
|
||||
break
|
||||
}
|
||||
|
||||
const previous =
|
||||
queryClient.getQueryData<SkillInfo[]>(skillsQueryKey(profile))?.find(skill => skill.name === row.name) ?? row
|
||||
|
||||
setSkills(current => current?.map(skill => (skill.name === row.name ? { ...skill, enabled } : skill)))
|
||||
|
||||
try {
|
||||
await setSkillEnabled(row.name, enabled, profile)
|
||||
done += 1
|
||||
} catch (err) {
|
||||
if (mounted.current) {
|
||||
setSkills(current =>
|
||||
current?.map(skill =>
|
||||
skill.name === row.name && skill.enabled === enabled ? { ...skill, enabled: previous.enabled } : skill
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
notify({ kind: 'success', title: t.skills.bulkUpdated(done), message: '' })
|
||||
if (bulk && mounted.current) {
|
||||
notify({ kind: 'success', title: t.skills.bulkUpdated(done), message: '' })
|
||||
}
|
||||
} catch (err) {
|
||||
notifyError(err, t.skills.failedToUpdate(t.skills.tabSkills))
|
||||
if (mounted.current) {
|
||||
notifyError(err, t.skills.failedToUpdate(bulk ? t.skills.tabSkills : targets[0].name))
|
||||
}
|
||||
} finally {
|
||||
invalidateSlashCompletions()
|
||||
setBulkBusy(false)
|
||||
void queryClient.invalidateQueries({ queryKey: skillsQueryKey(profile), exact: true })
|
||||
mutationBusy.current = false
|
||||
|
||||
if (mounted.current) {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bulk actions ("All" master switch, "Disable unused") and the master-switch
|
||||
// state target the WHOLE tab, never the search-filtered view — a tab-wide
|
||||
// control that silently scoped to the current query would be a lie.
|
||||
const allEnabled = skills.length > 0 && skills.every(s => s.enabled)
|
||||
const controlsDisabled = busy || installedPending || Boolean(installedError)
|
||||
|
||||
// One switch line covering enable-all/disable-all.
|
||||
// Bulk always means the whole profile, never just a search/filter result.
|
||||
const bulkSwitch: ListStripMenuToggle = {
|
||||
checked: allEnabled,
|
||||
disabled: bulkBusy,
|
||||
checked: skills.length > 0 && skills.every(skill => skill.enabled),
|
||||
disabled: controlsDisabled || skills.length === 0,
|
||||
label: t.skills.all,
|
||||
onToggle: checked =>
|
||||
void bulkApply(
|
||||
skills.filter(row => row.enabled !== checked),
|
||||
checked
|
||||
void applyEnabled(
|
||||
skills.filter(skill => skill.enabled !== checked),
|
||||
checked,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
// "Never used" = zero recorded activity. The pruning move for a 100+ skill
|
||||
// install: keep the workhorses, shed the noise.
|
||||
const disableUnused = () =>
|
||||
bulkApply(
|
||||
skills.filter(skill => skill.enabled && usageOf(skill) === 0),
|
||||
false
|
||||
)
|
||||
|
||||
const openSkillEditor = async (name: string) => {
|
||||
try {
|
||||
const node = await getLearningNode(name, profile)
|
||||
|
||||
setSkillEditor({ content: node.content, name })
|
||||
setSkillDraft(node.content)
|
||||
} catch (err) {
|
||||
notifyError(err, name)
|
||||
}
|
||||
}
|
||||
|
||||
const saveSkillEdit = async () => {
|
||||
if (!skillEditor) {
|
||||
if (saving.current || skillEditor?.name === name) {
|
||||
return
|
||||
}
|
||||
|
||||
setSkillSaving(true)
|
||||
const request = ++editorRequest.current
|
||||
|
||||
try {
|
||||
await editLearningNode(skillEditor.name, skillDraft, profile)
|
||||
notify({
|
||||
kind: 'success',
|
||||
title: t.skills.skillUpdated,
|
||||
message: t.skills.appliesToNewSessions(skillEditor.name)
|
||||
})
|
||||
setSkillEditor(null)
|
||||
onRefresh()
|
||||
const node = await getLearningNode(name, profile)
|
||||
|
||||
if (!mounted.current || request !== editorRequest.current) {
|
||||
return
|
||||
}
|
||||
|
||||
setSkillEditor({ name })
|
||||
setSkillDraft(node.content)
|
||||
} catch (err) {
|
||||
notifyError(err, skillEditor.name)
|
||||
} finally {
|
||||
setSkillSaving(false)
|
||||
if (mounted.current && request === editorRequest.current) {
|
||||
notifyError(err, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const skillEditorPane = skillEditor && (
|
||||
<DetailPane
|
||||
actions={
|
||||
<Button disabled={skillSaving} onClick={() => void saveSkillEdit()} size="xs">
|
||||
{skillSaving ? t.common.saving : t.common.save}
|
||||
</Button>
|
||||
const closeSkillEditor = () => {
|
||||
editorRequest.current += 1
|
||||
setSkillEditor(null)
|
||||
}
|
||||
|
||||
const saveSkillEdit = async () => {
|
||||
if (!skillEditor || saving.current) {
|
||||
return
|
||||
}
|
||||
|
||||
const editor = skillEditor
|
||||
const request = editorRequest.current
|
||||
saving.current = true
|
||||
setSkillSaving(true)
|
||||
|
||||
try {
|
||||
const result = await editLearningNode(editor.name, skillDraft, profile)
|
||||
|
||||
if (!result.ok) {
|
||||
throw new Error(result.message)
|
||||
}
|
||||
id="skill-editor"
|
||||
onClose={() => setSkillEditor(null)}
|
||||
title={<span className="text-[0.68rem] font-normal text-muted-foreground/60">{skillEditor.name}/SKILL.md</span>}
|
||||
>
|
||||
<CodeEditor
|
||||
filePath="SKILL.md"
|
||||
initialValue={skillEditor.content}
|
||||
key={skillEditor.name}
|
||||
onCancel={() => setSkillEditor(null)}
|
||||
onChange={setSkillDraft}
|
||||
onSave={() => void saveSkillEdit()}
|
||||
/>
|
||||
</DetailPane>
|
||||
)
|
||||
|
||||
void queryClient.invalidateQueries({ queryKey: ['skill-content', editor.name, profileScopeKey(profile)] })
|
||||
void queryClient.invalidateQueries({ queryKey: skillsQueryKey(profile), exact: true })
|
||||
invalidateSlashCompletions()
|
||||
|
||||
if (!mounted.current) {
|
||||
return
|
||||
}
|
||||
|
||||
notify({ kind: 'success', title: t.skills.skillUpdated, message: t.skills.appliesToNewSessions(editor.name) })
|
||||
|
||||
if (request === editorRequest.current) {
|
||||
setSkillEditor(null)
|
||||
}
|
||||
|
||||
onRefresh()
|
||||
} catch (err) {
|
||||
if (mounted.current) {
|
||||
notifyError(err, editor.name)
|
||||
}
|
||||
} finally {
|
||||
saving.current = false
|
||||
|
||||
if (mounted.current) {
|
||||
setSkillSaving(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const notice = installedError ? (
|
||||
<CatalogAlert onRetry={onRefresh} retryLabel={t.skills.refresh} title={t.skills.skillsLoadFailed}>
|
||||
{installedError instanceof Error ? installedError.message : null}
|
||||
</CatalogAlert>
|
||||
) : installedPending ? (
|
||||
<Loader className="mx-auto my-2 size-6 text-(--ui-text-tertiary)" label={t.skills.loading} type="rose-curve" />
|
||||
) : null
|
||||
|
||||
return (
|
||||
<>
|
||||
{visibleSkills.length === 0 && visibleOfficial.length === 0 ? (
|
||||
<CapabilityEmpty noun="skills" query={query} />
|
||||
) : (
|
||||
<MasterDetail pane={skillEditorPane} resizeId="capabilities-split" split="wide">
|
||||
<ListColumn
|
||||
header={
|
||||
<ListStrip
|
||||
left={<SortButton desc={skillsSortDesc} onFlip={() => $skillsSortDesc.set(!$skillsSortDesc.get())} />}
|
||||
right={
|
||||
<ListStripMenu
|
||||
items={[
|
||||
{
|
||||
disabled: bulkBusy,
|
||||
label: t.skills.disableUnused,
|
||||
onSelect: () => void disableUnused()
|
||||
}
|
||||
]}
|
||||
label={t.skills.tabSkills}
|
||||
toggle={bulkSwitch}
|
||||
/>
|
||||
<SkillCatalog
|
||||
actions={
|
||||
<>
|
||||
<UpdateSkillsButton profile={profile} />
|
||||
<ListStripMenu
|
||||
items={[
|
||||
{
|
||||
disabled: controlsDisabled || !skills.some(skill => skill.enabled && usageOf(skill) === 0),
|
||||
label: t.skills.disableUnused,
|
||||
onSelect: () =>
|
||||
void applyEnabled(
|
||||
skills.filter(skill => skill.enabled && usageOf(skill) === 0),
|
||||
false,
|
||||
true
|
||||
)
|
||||
}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{visibleSkills.map(skill => (
|
||||
<CapRow
|
||||
active={activeOfficial === null && activeSkill?.name === skill.name}
|
||||
busy={bulkBusy}
|
||||
enabled={skill.enabled}
|
||||
key={skill.name}
|
||||
meta={usageOf(skill) > 0 ? `×${compactNumber(usageOf(skill))}` : undefined}
|
||||
onSelect={() => {
|
||||
setSelectedSkill(skill.name)
|
||||
setSelectedOfficial(null)
|
||||
}}
|
||||
onToggle={enabled => void handleToggleSkill(skill, enabled)}
|
||||
subtitle={skillSubtitle(skill)}
|
||||
title={skill.name}
|
||||
toggleLabel={skill.name}
|
||||
/>
|
||||
))}
|
||||
{visibleOfficial.length > 0 && (
|
||||
<div className="flex h-7 shrink-0 items-end px-2 pb-1 text-[0.62rem] font-medium uppercase tracking-wide text-(--ui-text-quaternary)">
|
||||
{t.skills.officialCatalog}
|
||||
</div>
|
||||
]}
|
||||
label={t.skills.tabSkills}
|
||||
toggle={bulkSwitch}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
installedPending={installedPending || Boolean(installedError)}
|
||||
notice={notice}
|
||||
onQueryChange={onQueryChange}
|
||||
profile={profile}
|
||||
query={query}
|
||||
renderInstalledAction={skill => (
|
||||
<CatalogSwitch
|
||||
aria-label={skill.name}
|
||||
checked={skill.enabled}
|
||||
disabled={controlsDisabled}
|
||||
onCheckedChange={enabled => void applyEnabled([skill], enabled)}
|
||||
size="xs"
|
||||
/>
|
||||
)}
|
||||
renderInstalledDetail={skill => (
|
||||
<>
|
||||
{usageOf(skill) > 0 && (
|
||||
<p className="text-xs text-(--ui-text-tertiary)">{t.skills.usageCount(usageOf(skill))}</p>
|
||||
)}
|
||||
{visibleOfficial.map(skill => {
|
||||
const installing = runningInstalls.has(skill.identifier)
|
||||
|
||||
return (
|
||||
<CapRow
|
||||
action={
|
||||
<Button disabled={installing} onClick={() => handleInstallOfficial(skill)} size="xs" variant="text">
|
||||
{installing && <Loader2 className="size-3 animate-spin" />}
|
||||
{installing ? t.skills.hub.installing : t.skills.hub.install}
|
||||
</Button>
|
||||
}
|
||||
active={activeOfficial?.identifier === skill.identifier}
|
||||
enabled={false}
|
||||
key={skill.identifier}
|
||||
onSelect={() => setSelectedOfficial(skill.identifier)}
|
||||
subtitle={prettyName(skill.category)}
|
||||
title={skill.name}
|
||||
<SkillDetail
|
||||
onArchive={() => {
|
||||
if (!saving.current) {
|
||||
setArchiveTarget(skill.name)
|
||||
}
|
||||
}}
|
||||
onEdit={() => void openSkillEditor(skill.name)}
|
||||
profile={profile}
|
||||
skill={skill}
|
||||
/>
|
||||
<p className="text-xs text-(--ui-text-tertiary)">{t.skills.changesApplyNewSessions}</p>
|
||||
{skillEditor?.name === skill.name && (
|
||||
<DetailPane
|
||||
actions={
|
||||
<Button disabled={skillSaving} onClick={() => void saveSkillEdit()} size="xs">
|
||||
{skillSaving ? t.common.saving : t.common.save}
|
||||
</Button>
|
||||
}
|
||||
id="skill-editor"
|
||||
onClose={closeSkillEditor}
|
||||
title={
|
||||
<span className="text-[0.68rem] font-normal text-muted-foreground/60">
|
||||
{skillEditor.name}/SKILL.md
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<CodeEditor
|
||||
disabled={skillSaving}
|
||||
filePath="SKILL.md"
|
||||
initialValue={skillDraft}
|
||||
key={skillEditor.name}
|
||||
onCancel={closeSkillEditor}
|
||||
onChange={setSkillDraft}
|
||||
onSave={() => void saveSkillEdit()}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</ListColumn>
|
||||
<DetailColumn footer={t.skills.changesApplyNewSessions}>
|
||||
{activeOfficial ? (
|
||||
<OfficialSkillDetail
|
||||
installing={runningInstalls.has(activeOfficial.identifier)}
|
||||
onInstall={() => handleInstallOfficial(activeOfficial)}
|
||||
profile={profile}
|
||||
skill={activeOfficial}
|
||||
/>
|
||||
) : (
|
||||
activeSkill && (
|
||||
<SkillDetail
|
||||
onArchive={() => setArchiveTarget(activeSkill.name)}
|
||||
onEdit={() => void openSkillEditor(activeSkill.name)}
|
||||
profile={profile}
|
||||
skill={activeSkill}
|
||||
/>
|
||||
)
|
||||
</DetailPane>
|
||||
)}
|
||||
</DetailColumn>
|
||||
</MasterDetail>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
skills={skills}
|
||||
/>
|
||||
{archiveTarget && (
|
||||
<ArchiveSkillConfirmDialog
|
||||
onApply={() => {
|
||||
const name = archiveTarget
|
||||
const snapshot = skills
|
||||
|
||||
setSkills(current => current?.filter(skill => skill.name !== name) ?? current)
|
||||
const snapshot =
|
||||
queryClient.getQueryData<SkillInfo[]>(skillsQueryKey(profile))?.find(skill => skill.name === name) ??
|
||||
skills.find(skill => skill.name === name)
|
||||
|
||||
void queryClient.cancelQueries({ queryKey: skillsQueryKey(profile), exact: true })
|
||||
setSkills(current => current?.filter(skill => skill.name !== name))
|
||||
invalidateSlashCompletions()
|
||||
|
||||
if (skillEditor?.name === name) {
|
||||
setSkillEditor(null)
|
||||
closeSkillEditor()
|
||||
}
|
||||
|
||||
return () => setSkills(() => snapshot)
|
||||
// Restore only this row; never clobber intervening toggles or installs.
|
||||
return () => {
|
||||
if (mounted.current) {
|
||||
setSkills(current =>
|
||||
snapshot && current && !current.some(skill => skill.name === name) ? [...current, snapshot] : current
|
||||
)
|
||||
}
|
||||
|
||||
void queryClient.invalidateQueries({ queryKey: skillsQueryKey(profile), exact: true })
|
||||
}
|
||||
}}
|
||||
onClose={() => setArchiveTarget(null)}
|
||||
onFailure={(err, name) => notifyError(err, name)}
|
||||
onFailure={(err, name) => {
|
||||
if (mounted.current) {
|
||||
notifyError(err, name)
|
||||
}
|
||||
}}
|
||||
onSuccess={() => {
|
||||
void queryClient.invalidateQueries({ queryKey: skillsQueryKey(profile), exact: true })
|
||||
|
||||
if (mounted.current) {
|
||||
onRefresh()
|
||||
}
|
||||
}}
|
||||
open
|
||||
profile={profile}
|
||||
skillId={archiveTarget}
|
||||
|
||||
@@ -28,6 +28,7 @@ interface PageSearchShellProps extends React.ComponentProps<'section'> {
|
||||
searchValue: string
|
||||
/** Hide the search field when there's nothing to search (empty dataset). */
|
||||
searchHidden?: boolean
|
||||
tabsAlign?: 'center' | 'start'
|
||||
/** Right-aligned control in the header's trailing cell (e.g. a refresh button)
|
||||
* so mouse users get a visible affordance for the refresh hotkey. */
|
||||
searchTrailingAction?: ReactNode
|
||||
@@ -36,18 +37,20 @@ interface PageSearchShellProps extends React.ComponentProps<'section'> {
|
||||
function ShellTabs({
|
||||
tabs,
|
||||
activeTab,
|
||||
onTabChange
|
||||
onTabChange,
|
||||
align
|
||||
}: {
|
||||
tabs: PageShellTab[]
|
||||
activeTab?: string
|
||||
onTabChange?: (id: string) => void
|
||||
align?: 'center' | 'start'
|
||||
}) {
|
||||
return (
|
||||
<ResponsiveTabs
|
||||
onChange={id => onTabChange?.(id)}
|
||||
tabs={tabs}
|
||||
value={activeTab ?? tabs[0]?.id ?? ''}
|
||||
wideClassName="justify-center"
|
||||
wideClassName={align === 'start' ? 'justify-start' : 'justify-center'}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -64,6 +67,7 @@ export function PageSearchShell({
|
||||
searchHints,
|
||||
searchValue,
|
||||
searchHidden = false,
|
||||
tabsAlign = 'center',
|
||||
searchTrailingAction,
|
||||
...props
|
||||
}: PageSearchShellProps) {
|
||||
@@ -91,8 +95,8 @@ export function PageSearchShell({
|
||||
*/}
|
||||
<div className="shrink-0">
|
||||
{(hasTabs || !searchHidden) && (
|
||||
<div className="grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-3 px-3 pb-2 pt-[calc(var(--titlebar-height)+0.5rem)]">
|
||||
<div className="flex min-w-0 items-center justify-start">
|
||||
<div className={cn('grid items-center gap-3 px-3 pb-2 pt-[calc(var(--titlebar-height)+0.5rem)]', tabsAlign === 'start' ? 'grid-cols-[minmax(0,1fr)_auto] px-6 pt-[calc(var(--titlebar-height)+1.5rem)]' : 'grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)]')}>
|
||||
<div className={cn('flex min-w-0 items-center justify-start', searchHidden && tabsAlign === 'start' && 'hidden')}>
|
||||
{!searchHidden && (
|
||||
<SearchField
|
||||
containerClassName="max-w-[45vw]"
|
||||
@@ -104,8 +108,8 @@ export function PageSearchShell({
|
||||
)}
|
||||
</div>
|
||||
{hasTabs ? (
|
||||
<div className="flex min-w-0 items-center justify-center" data-tour="page-tabs">
|
||||
<ShellTabs activeTab={activeTab} onTabChange={onTabChange} tabs={tabs!} />
|
||||
<div className={cn('flex min-w-0 items-center', tabsAlign === 'start' ? 'justify-start' : 'justify-center')} data-tour="page-tabs">
|
||||
<ShellTabs activeTab={activeTab} align={tabsAlign} onTabChange={onTabChange} tabs={tabs!} />
|
||||
</div>
|
||||
) : (
|
||||
<span />
|
||||
|
||||
|
After Width: | Height: | Size: 546 KiB |
|
After Width: | Height: | Size: 50 KiB |
@@ -0,0 +1,21 @@
|
||||
.masonry {
|
||||
position: relative;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--masonry-min-width, 17rem)), 1fr));
|
||||
align-items: start;
|
||||
gap: calc(var(--spacing) * 3);
|
||||
}
|
||||
|
||||
.masonry > [data-slot='masonry-item'] {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.masonry[data-measured] > [data-slot='masonry-item'] {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
@supports (display: grid-lanes) {
|
||||
.masonry {
|
||||
display: grid-lanes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import './masonry.css'
|
||||
|
||||
import { Children, type ComponentProps, useLayoutEffect, useRef } from 'react'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
/** Native grid lanes when available; measured lanes for older Electron releases.
|
||||
* Children stay in source order and never move between React parents. */
|
||||
export function Masonry({ children, className, ...props }: ComponentProps<'div'>) {
|
||||
const root = useRef<HTMLDivElement>(null)
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const node = root.current
|
||||
|
||||
if (!node || CSS.supports('display', 'grid-lanes')) {
|
||||
return
|
||||
}
|
||||
|
||||
const items = Array.from(node.children) as HTMLElement[]
|
||||
let frame = 0
|
||||
let disposed = false
|
||||
|
||||
const layout = () => {
|
||||
frame = 0
|
||||
|
||||
if (disposed || !node.clientWidth) {
|
||||
return
|
||||
}
|
||||
|
||||
const style = getComputedStyle(node)
|
||||
const tracks = style.gridTemplateColumns.split(' ').map(Number.parseFloat)
|
||||
|
||||
if (!tracks.length || tracks.some(width => !Number.isFinite(width))) {
|
||||
return
|
||||
}
|
||||
|
||||
const gap = Number.parseFloat(style.columnGap) || 0
|
||||
const width = tracks[0]
|
||||
const widthValue = `${width}px`
|
||||
|
||||
// Write widths together before measuring wrapping. No React state updates,
|
||||
// window resize listeners, or per-item read/write alternation.
|
||||
for (const item of items) {
|
||||
if (item.style.width !== widthValue) {
|
||||
item.style.width = widthValue
|
||||
}
|
||||
}
|
||||
|
||||
const heights = items.map(item => item.getBoundingClientRect().height)
|
||||
const lanes = tracks.map(() => 0)
|
||||
|
||||
const placements = heights.map(height => {
|
||||
const lane = lanes.indexOf(Math.min(...lanes))
|
||||
const top = lanes[lane]
|
||||
lanes[lane] += height + gap
|
||||
|
||||
return { top, left: lane * (width + gap) }
|
||||
})
|
||||
|
||||
node.dataset.measured = ''
|
||||
items.forEach((item, index) => {
|
||||
item.style.insetInlineStart = `${placements[index].left}px`
|
||||
item.style.insetBlockStart = `${placements[index].top}px`
|
||||
})
|
||||
const height = `${Math.max(0, ...lanes) - (items.length ? gap : 0)}px`
|
||||
|
||||
if (node.style.height !== height) {
|
||||
node.style.height = height
|
||||
}
|
||||
}
|
||||
|
||||
const schedule = () => {
|
||||
if (!frame) {
|
||||
frame = requestAnimationFrame(layout)
|
||||
}
|
||||
}
|
||||
|
||||
const observer = new ResizeObserver(schedule)
|
||||
observer.observe(node)
|
||||
items.forEach(item => observer.observe(item))
|
||||
layout()
|
||||
|
||||
return () => {
|
||||
disposed = true
|
||||
observer.disconnect()
|
||||
cancelAnimationFrame(frame)
|
||||
delete node.dataset.measured
|
||||
node.style.removeProperty('height')
|
||||
items.forEach(item => {
|
||||
item.style.removeProperty('width')
|
||||
item.style.removeProperty('inset-inline-start')
|
||||
item.style.removeProperty('inset-block-start')
|
||||
})
|
||||
}
|
||||
}, [children])
|
||||
|
||||
return (
|
||||
<div {...props} className={cn('masonry', className)} data-slot="masonry" ref={root}>
|
||||
{Children.map(children, child => child && <div data-slot="masonry-item">{child}</div>)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { ComponentProps } from 'react'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
/** One row that scrolls sideways, snapping each child to the start edge.
|
||||
* Children keep their own width; set it from the caller (`*:w-68`). */
|
||||
export function Reel({ className, ...props }: ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
{...props}
|
||||
className={cn(
|
||||
'flex snap-x snap-mandatory gap-3 overflow-x-auto overscroll-x-contain pb-2 *:shrink-0 *:snap-start',
|
||||
className
|
||||
)}
|
||||
data-slot="reel"
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -24,6 +24,15 @@ interface SearchFieldProps {
|
||||
onKeyDown?: KeyboardEventHandler<HTMLInputElement>
|
||||
inputRef?: RefObject<HTMLInputElement | null>
|
||||
trailingAction?: ReactNode
|
||||
/** Optional scope badge between the search glyph and input. */
|
||||
leadingContent?: ReactNode
|
||||
/**
|
||||
* `underline` (default) recedes into chrome — sidebars, page headers.
|
||||
* `box` is a standalone pill — visible stroke + quinary fill, the recipe
|
||||
* the Appearance theme search uses — for when search IS the page's primary
|
||||
* affordance, e.g. above a catalog grid.
|
||||
*/
|
||||
variant?: 'underline' | 'box'
|
||||
'aria-label'?: string
|
||||
}
|
||||
|
||||
@@ -45,10 +54,13 @@ export function SearchField({
|
||||
onKeyDown,
|
||||
inputRef,
|
||||
trailingAction,
|
||||
leadingContent,
|
||||
variant = 'underline',
|
||||
'aria-label': ariaLabel
|
||||
}: SearchFieldProps) {
|
||||
const { t } = useI18n()
|
||||
const clear = onClear ?? (() => onChange(''))
|
||||
const boxed = variant === 'box'
|
||||
|
||||
// One hint per mount, picked at random — fresh nudge every visit, no
|
||||
// mid-page carousel.
|
||||
@@ -62,13 +74,19 @@ export function SearchField({
|
||||
// min-w-0 is load-bearing: without it the content-sized input sets the
|
||||
// container's flex min-width and the field bulldozes its siblings
|
||||
// instead of shrinking to fit its context.
|
||||
'inline-flex min-w-0 max-w-full items-center gap-1.5 border-b border-transparent px-0.5 transition-[color,border-color,opacity]',
|
||||
// Recede until the user reaches for it.
|
||||
!value && 'opacity-30 focus-within:opacity-100',
|
||||
'inline-flex min-w-0 max-w-full items-center gap-1.5 transition-[color,border-color,opacity]',
|
||||
boxed
|
||||
? 'w-full gap-2 rounded-full border border-(--ui-stroke-tertiary) bg-(--ui-bg-quinary) px-3.5 py-2 hover:border-(--ui-stroke-secondary) focus-within:border-(--ui-stroke-secondary)'
|
||||
: cn(
|
||||
'border-b border-transparent px-0.5',
|
||||
// Recede until the user reaches for it.
|
||||
!value && 'opacity-30 focus-within:opacity-100'
|
||||
),
|
||||
containerClassName
|
||||
)}
|
||||
>
|
||||
<Search className="pointer-events-none size-3.5 shrink-0 text-muted-foreground/70" />
|
||||
<Search className={cn('pointer-events-none shrink-0 text-muted-foreground/70', boxed ? 'size-4' : 'size-3.5')} />
|
||||
{leadingContent}
|
||||
<input
|
||||
aria-label={ariaLabel ?? placeholder}
|
||||
className={cn(
|
||||
@@ -80,6 +98,9 @@ export function SearchField({
|
||||
// text (#119204). Long queries scroll inside the field.
|
||||
// text-xs matches the form controls (Input/Select via controlVariants).
|
||||
'h-7 min-w-0 max-w-full flex-1 bg-transparent text-xs text-foreground [field-sizing:content] placeholder:text-muted-foreground focus:outline-none',
|
||||
// Boxed: the wrapper owns the chrome, the input fills it (same as an
|
||||
// adorned Input).
|
||||
boxed && 'h-auto w-full flex-1 text-sm leading-5 [field-sizing:initial]',
|
||||
inputClassName
|
||||
)}
|
||||
onChange={event => onChange(event.target.value)}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"skills": {
|
||||
"autonomous-ai-agents/computer-use": "official-art-feature.jpg",
|
||||
"autonomous-ai-agents/claude-code": "official-art-card-one.jpg",
|
||||
"autonomous-ai-agents/codex": "official-art.jpg",
|
||||
"autonomous-ai-agents/hermes-agent": "official-art-hermes-hero.jpg"
|
||||
},
|
||||
"plugins": {
|
||||
"desktop:kanban": "official-art.jpg",
|
||||
"desktop:hermes-bots": "official-art-card-two.jpg",
|
||||
"desktop:hermes-radio": "official-art-card-one.jpg"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/** Shared with the docs catalog: taxonomy order is independent of popularity. Keep keys in sync
|
||||
* with CATALOG_CATEGORIES in hermes_cli/plugin_catalog.py and website/scripts/extract-plugins.py. */
|
||||
export const PLUGIN_CATEGORIES: Record<string, { label: string; icon: string; blurb: string }> = {
|
||||
desktop: { label: 'Desktop', icon: '🖥️', blurb: 'Panes, tabs and views for Hermes Desktop' },
|
||||
memory: { label: 'Memory', icon: '🧠', blurb: 'Memory providers and context engines' },
|
||||
platform: { label: 'Platforms', icon: '💬', blurb: 'Messaging and channel adapters' },
|
||||
web: { label: 'Web & Browser', icon: '🌐', blurb: 'Search backends, extraction and browser control' },
|
||||
tools: { label: 'Tools', icon: '🛠️', blurb: 'New tools the agent can call' },
|
||||
voice: { label: 'Voice', icon: '🎙️', blurb: 'Speech, TTS and realtime audio' },
|
||||
automation: { label: 'Automation', icon: '⏱️', blurb: 'Hooks, wake triggers and session automation' },
|
||||
models: { label: 'Models', icon: '✨', blurb: 'Model and inference providers' },
|
||||
general: { label: 'General', icon: '📦', blurb: 'Plugins that span several areas' }
|
||||
}
|
||||
|
||||
export const PLUGIN_CATEGORY_ORDER = Object.keys(PLUGIN_CATEGORIES)
|
||||
export type PluginCatalogSort = 'stars' | 'newest' | 'updated'
|
||||
|
||||
export function sortCatalogPlugins<T extends { name: string; addedAt?: string | null; updatedAt?: string | null }>(entries: T[], sort: PluginCatalogSort): T[] {
|
||||
// The published snapshot already sorts stars descending, then name. Preserve
|
||||
// its order, including ties, rather than reinterpreting missing star counts.
|
||||
if (sort === 'stars') { return entries }
|
||||
const field = sort === 'newest' ? 'addedAt' : 'updatedAt'
|
||||
|
||||
const date = (value?: string | null) => {
|
||||
const ms = value ? Date.parse(value) : NaN
|
||||
|
||||
return Number.isFinite(ms) ? ms : -Infinity
|
||||
}
|
||||
|
||||
return [...entries].sort((a, b) => date(b[field]) - date(a[field]) || a.name.localeCompare(b.name))
|
||||
}
|
||||
|
||||
export function groupCatalogPlugins<T extends { category: string }>(entries: T[]): [string, T[]][] {
|
||||
const buckets = new Map<string, T[]>()
|
||||
|
||||
for (const entry of entries) {
|
||||
const key = Object.hasOwn(PLUGIN_CATEGORIES, entry.category) ? entry.category : 'general'
|
||||
const bucket = buckets.get(key) ?? []
|
||||
bucket.push(entry)
|
||||
buckets.set(key, bucket)
|
||||
}
|
||||
|
||||
return PLUGIN_CATEGORY_ORDER.filter(key => buckets.has(key)).map(key => [key, buckets.get(key)!])
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { type FeaturedCandidate, pickFeatured } from './catalog-featured'
|
||||
|
||||
const WEEK = 7 * 24 * 60 * 60 * 1000
|
||||
const NOW = Date.parse('2026-09-30T12:00:00Z')
|
||||
|
||||
type Row = FeaturedCandidate & { name: string }
|
||||
|
||||
const pick = (rows: Row[], now = NOW) => pickFeatured(rows, row => row, now)?.name
|
||||
|
||||
describe('pickFeatured', () => {
|
||||
it('rotates through curated ranks weekly, in rank order', () => {
|
||||
const rows: Row[] = [
|
||||
{ name: 'third', featured: 3, official: true, pictured: false },
|
||||
{ name: 'first', featured: 1, official: false, pictured: false },
|
||||
{ name: 'uncurated', official: true, pictured: true, stars: 999 },
|
||||
{ name: 'second', featured: 2, official: true, pictured: true }
|
||||
]
|
||||
|
||||
const week = Math.floor(NOW / WEEK)
|
||||
const order = ['first', 'second', 'third']
|
||||
|
||||
expect(pick(rows)).toBe(order[week % 3])
|
||||
expect(pick(rows, NOW + WEEK)).toBe(order[(week + 1) % 3])
|
||||
expect(pick(rows, NOW + 2 * WEEK)).toBe(order[(week + 2) % 3])
|
||||
})
|
||||
|
||||
it('is the same pick anywhere within one week', () => {
|
||||
const rows: Row[] = [1, 2, 3, 4].map(rank => ({ name: `r${rank}`, featured: rank, official: true, pictured: true }))
|
||||
const start = Math.floor(NOW / WEEK) * WEEK
|
||||
|
||||
expect(pick(rows, start)).toBe(pick(rows, start + WEEK - 1))
|
||||
})
|
||||
|
||||
it('falls back to the newest pictured official entry of the last 30 days', () => {
|
||||
const rows: Row[] = [
|
||||
{ name: 'old', official: true, pictured: true, addedAt: '2026-06-01T00:00:00Z', stars: 900 },
|
||||
{ name: 'new-plain', official: true, pictured: false, addedAt: '2026-09-29T00:00:00Z' },
|
||||
{ name: 'new-pictured', official: true, pictured: true, addedAt: '2026-09-20T00:00:00Z' },
|
||||
{ name: 'community', official: false, pictured: true, addedAt: '2026-09-29T00:00:00Z' }
|
||||
]
|
||||
|
||||
expect(pick(rows)).toBe('new-pictured')
|
||||
})
|
||||
|
||||
it('then to an official entry with art, most stars first, never a community one', () => {
|
||||
const rows: Row[] = [
|
||||
{ name: 'popular-community', official: false, pictured: true, stars: 5000 },
|
||||
{ name: 'official-small', official: true, pictured: false, stars: 10 },
|
||||
{ name: 'official-big', official: true, pictured: false, stars: 40 }
|
||||
]
|
||||
|
||||
expect(pick(rows)).toBe('official-big')
|
||||
expect(pick([...rows, { name: 'official-art', official: true, pictured: true, stars: 1 }])).toBe('official-art')
|
||||
expect(pick([{ name: 'community', official: false, pictured: true }])).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,39 @@
|
||||
/** The catalog hero pick, shared by the website and the desktop app so both
|
||||
* feature the same entry at the same time.
|
||||
*
|
||||
* Curated picks come from `catalog-curation.json` → `featured`, stamped into
|
||||
* the published catalog as a 1-based `featured` rank by the extractors. The
|
||||
* hero rotates through them weekly. With no curated pick in the feed it falls
|
||||
* back to the newest pictured official entry of the last 30 days, then the
|
||||
* official entry with art and the most stars. Nothing here reads a download
|
||||
* or install count; the feed has none. */
|
||||
|
||||
export interface FeaturedCandidate {
|
||||
/** 1-based curated rank from the feed; absent for everything uncurated. */
|
||||
featured?: number | null
|
||||
official: boolean
|
||||
pictured: boolean
|
||||
addedAt?: string | null
|
||||
stars?: number | null
|
||||
}
|
||||
|
||||
const DAY_MS = 24 * 60 * 60 * 1000
|
||||
const WEEK_MS = 7 * DAY_MS
|
||||
const FRESH_MS = 30 * DAY_MS
|
||||
|
||||
const rank = (value: FeaturedCandidate) => (typeof value.featured === 'number' && value.featured > 0 ? value.featured : 0)
|
||||
const added = (value: FeaturedCandidate) => Date.parse(value.addedAt ?? '') || 0
|
||||
|
||||
export function pickFeatured<T>(entries: readonly T[], read: (entry: T) => FeaturedCandidate, now = Date.now()): T | undefined {
|
||||
const rows = entries.map(entry => ({ entry, value: read(entry) }))
|
||||
const curated = rows.filter(row => rank(row.value)).sort((a, b) => rank(a.value) - rank(b.value))
|
||||
|
||||
if (curated.length) {
|
||||
return curated[Math.floor(now / WEEK_MS) % curated.length].entry
|
||||
}
|
||||
|
||||
const official = rows.filter(row => row.value.official)
|
||||
const fresh = official.filter(row => row.value.pictured && added(row.value) > now - FRESH_MS).sort((a, b) => added(b.value) - added(a.value))
|
||||
|
||||
return (fresh[0] ?? official.sort((a, b) => Number(b.value.pictured) - Number(a.value.pictured) || (b.value.stars ?? 0) - (a.value.stars ?? 0))[0])?.entry
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/** Skill install targets shared by the public Skills Hub and Desktop's skill deep link. */
|
||||
/** Install targets shared by the public docs galleries and native catalog. */
|
||||
export interface SkillCatalogTarget {
|
||||
name: string
|
||||
source: string
|
||||
@@ -29,3 +29,7 @@ export function skillCatalogInstallUrl(skill: SkillCatalogTarget): string | null
|
||||
|
||||
return identifier ? `hermes://skill/install?${new URLSearchParams({ identifier })}` : null
|
||||
}
|
||||
|
||||
export function pluginCatalogInstallUrl(plugin: { name: string }): string {
|
||||
return `hermes://plugin/install?${new URLSearchParams({ catalog: plugin.name })}`
|
||||
}
|
||||
|
||||
@@ -27,7 +27,9 @@ export type {
|
||||
UsageBarData,
|
||||
UsageModelData
|
||||
} from './billing-types'
|
||||
export { skillCatalogInstallIdentifier, skillCatalogInstallUrl } from './catalog-install'
|
||||
export { groupCatalogPlugins, PLUGIN_CATEGORIES, PLUGIN_CATEGORY_ORDER, sortCatalogPlugins } from './catalog-browse'
|
||||
export { type FeaturedCandidate, pickFeatured } from './catalog-featured'
|
||||
export { pluginCatalogInstallUrl, skillCatalogInstallIdentifier, skillCatalogInstallUrl } from './catalog-install'
|
||||
export {
|
||||
driveChargeSettlement,
|
||||
SETTLEMENT_MAX_RETRY_AFTER_MS,
|
||||
@@ -174,7 +176,6 @@ export {
|
||||
WINDOWS_GLASS_MIN_BUILD,
|
||||
type WindowsBackgroundMaterial
|
||||
} from './translucency'
|
||||
export { type UpdateDebt, updateDebt, type UpdateDebtReceipt, type UpdateDebtStep } from './update-debt'
|
||||
export {
|
||||
buildHermesWebSocketUrl,
|
||||
type GatewayAuthMode,
|
||||
|
||||
@@ -252,6 +252,8 @@ def _source_url(source: str, identifier: str, extra: dict) -> str:
|
||||
|
||||
def extract_local_skills():
|
||||
skills = []
|
||||
with open(os.path.join(REPO_ROOT, "apps/shared/src/catalog-artwork.json"), encoding="utf-8") as artwork_file:
|
||||
artwork = json.load(artwork_file)["skills"]
|
||||
|
||||
for base_dir, source_label in LOCAL_SKILL_DIRS:
|
||||
base_path = os.path.join(REPO_ROOT, base_dir)
|
||||
@@ -333,6 +335,7 @@ def extract_local_skills():
|
||||
"envVars": env_vars,
|
||||
"commands": commands,
|
||||
"docsPath": _docs_page_path(rel, source_label),
|
||||
**({"image": "https://raw.githubusercontent.com/NousResearch/hermes-agent/main/website/static/img/catalog/" + artwork[rel_id]} if rel_id in artwork else {}),
|
||||
"installIdentifier": install_identifier,
|
||||
"installCmd": f"hermes skills install {install_identifier}",
|
||||
})
|
||||
|
||||
@@ -8,6 +8,7 @@ interface Skill {
|
||||
name: string;
|
||||
description: string;
|
||||
overview?: string;
|
||||
image?: string;
|
||||
category: string;
|
||||
categoryLabel: string;
|
||||
source: string;
|
||||
@@ -310,6 +311,7 @@ function SkillCard({
|
||||
onClick={onToggle}
|
||||
style={style}
|
||||
>
|
||||
{skill.image && <img src={skill.image} alt="" loading="lazy" decoding="async" style={{ width: "100%", aspectRatio: "2 / 1", objectFit: "cover", display: "block" }} />}
|
||||
<div className={styles.cardAccent} style={{ background: src.color }} />
|
||||
|
||||
<div className={styles.cardInner}>
|
||||
|
||||
|
After Width: | Height: | Size: 363 KiB |
|
After Width: | Height: | Size: 386 KiB |
|
After Width: | Height: | Size: 236 KiB |
|
After Width: | Height: | Size: 608 KiB |
|
After Width: | Height: | Size: 475 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 570 KiB |