forked from koshikraj/ottopus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent-icon.tsx
More file actions
61 lines (58 loc) · 1.89 KB
/
Copy pathagent-icon.tsx
File metadata and controls
61 lines (58 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use client'
import { useState } from 'react'
import { cn } from '@/lib/cn'
import { agentBrand, type AgentIconKey } from './agent-brand'
/**
* The agent's own mark, on a tile.
*
* The marks live in public/agents — see the README there for where they came
* from and why the fallback is a generic bot rather than a nearest guess.
*
* The tile is cream in both themes rather than following the surface, which is
* deliberate: these are third-party marks drawn for a light ground, and the
* Anthropic one is #191919 — on the dark palette it would all but vanish.
*/
export function AgentIcon({
name,
redirectUris = [],
iconKey,
size = 34,
className,
}: {
name: string
redirectUris?: readonly string[]
/**
* Skip the guess. The connect dialog already knows which mark each of its
* own pills wants, and re-deriving it from a display label is a round trip
* that can only lose — as it did, drawing the bot for "VS Code".
*/
iconKey?: AgentIconKey
size?: number
className?: string
}) {
const [failed, setFailed] = useState(false)
const key = failed ? 'other' : (iconKey ?? agentBrand(name, redirectUris).icon)
return (
<span
aria-hidden
style={{ width: size, height: size }}
className={cn(
'flex flex-none items-center justify-center overflow-hidden rounded-[10px]',
'bg-[var(--ot-cream)] ring-1 ring-[var(--ot-border)]',
className,
)}
>
{/* A static asset from our own public directory, so next/image would add
an optimiser round trip for a 300-byte SVG it cannot optimise anyway.
onError covers a mark being removed without this map being updated. */}
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={`/agents/${key}.svg`}
alt=""
width={size * 0.66}
height={size * 0.66}
onError={() => setFailed(true)}
/>
</span>
)
}