|
| 1 | +// Agent profile — full parity with surfaces/webview/src/market/AgentProfileView.tsx: |
| 2 | +// tier tag + gauge + ladder, earned SOL, verified GitHub repos, blog carousel, full |
| 3 | +// comment stack, buy-all with count feedback, self-only "write a blog post" entry. |
| 4 | +import React from "react"; |
| 5 | +import { Box, Text } from "ink"; |
| 6 | +import type { AgentProfile, SkillCard, Note } from "@iqlabs-official/agent-sdk"; |
| 7 | +import { colors, glyph } from "../../theme.js"; |
| 8 | +import { tierInfo, tierGauge, repoGauge, STAR_TIERS } from "./tiers.js"; |
| 9 | +import { ScrollView } from "./ScrollView.js"; |
| 10 | + |
| 11 | +const short = (w: string) => `${w.slice(0, 4)}…${w.slice(-4)}`; |
| 12 | + |
| 13 | +function earnedSol(totalEarned?: string): string { |
| 14 | + const lamports = totalEarned ? Number(totalEarned) : 0; |
| 15 | + const solVal = lamports / 1e9; |
| 16 | + return (solVal >= 100 ? solVal.toFixed(0) : solVal.toFixed(2)) + "◎"; |
| 17 | +} |
| 18 | + |
| 19 | +function noteDate(ts: number): string { |
| 20 | + return new Date(ts).toLocaleDateString(); |
| 21 | +} |
| 22 | + |
| 23 | +export type ProfileSub = "main" | "repos" | "comments" | "blog"; |
| 24 | + |
| 25 | +export function AgentProfileView({ |
| 26 | + profile, |
| 27 | + owned, |
| 28 | + buyAllResult, |
| 29 | + busy, |
| 30 | + sub, |
| 31 | + scrollOffset, |
| 32 | + self, |
| 33 | +}: { |
| 34 | + profile: AgentProfile; |
| 35 | + owned: Set<string>; |
| 36 | + buyAllResult: string | null; |
| 37 | + busy: boolean; |
| 38 | + sub: ProfileSub; |
| 39 | + scrollOffset: number; |
| 40 | + self: boolean; |
| 41 | +}) { |
| 42 | + const r = profile.reputation; |
| 43 | + const stars = r.stars ?? 0; |
| 44 | + const { cur, next } = tierInfo(stars); |
| 45 | + const blogNotes = (profile.notes ?? []).filter((n) => n.isSelfNote); |
| 46 | + const comments = (profile.notes ?? []).filter((n) => !n.isSelfNote); |
| 47 | + const allSkills = profile.createdSkills ?? []; |
| 48 | + const unowned = allSkills.filter((s) => !owned.has(s.name)); |
| 49 | + |
| 50 | + if (sub === "repos") { |
| 51 | + const repos = [...(profile.verifiedRepos ?? [])].sort((a, b) => (b.stars ?? 0) - (a.stars ?? 0)); |
| 52 | + const lines = repos.map((repo) => ( |
| 53 | + <Box key={repo.url} flexDirection="column"> |
| 54 | + <Text> |
| 55 | + <Text color={colors.iqCyan}>{repo.owner}/{repo.name}</Text> |
| 56 | + <Text dimColor> {repo.skillMints.length} skill{repo.skillMints.length !== 1 ? "s" : ""} linked</Text> |
| 57 | + </Text> |
| 58 | + <Text dimColor> ★{repo.stars} {repoGauge(repo.stars)}</Text> |
| 59 | + </Box> |
| 60 | + )); |
| 61 | + return ( |
| 62 | + <Box flexDirection="column" paddingX={1} borderStyle="round" borderColor={colors.iqViolet}> |
| 63 | + <Text bold color={colors.iqMagenta}>❖ verified repos ({repos.length})</Text> |
| 64 | + <Box flexDirection="column" marginTop={1}> |
| 65 | + {repos.length === 0 ? <Text dimColor>no verified repos</Text> : <ScrollView lines={lines} height={10} offset={scrollOffset} />} |
| 66 | + </Box> |
| 67 | + <Box marginTop={1}><Text dimColor>↑/↓/PgUp/PgDn scroll · esc back</Text></Box> |
| 68 | + </Box> |
| 69 | + ); |
| 70 | + } |
| 71 | + |
| 72 | + if (sub === "comments") { |
| 73 | + const lines = comments.map((n: Note) => ( |
| 74 | + <Box key={n.id} flexDirection="column"> |
| 75 | + <Text> |
| 76 | + <Text color={colors.iqCyan}>{short(n.author)}</Text> |
| 77 | + <Text dimColor> {noteDate(n.timestamp)}</Text> |
| 78 | + </Text> |
| 79 | + {n.title ? <Text bold>{n.title}</Text> : null} |
| 80 | + <Text> {n.text}</Text> |
| 81 | + {n.gitLink ? <Text dimColor> {glyph.sparkle} {n.gitLink}</Text> : null} |
| 82 | + </Box> |
| 83 | + )); |
| 84 | + return ( |
| 85 | + <Box flexDirection="column" paddingX={1} borderStyle="round" borderColor={colors.iqViolet}> |
| 86 | + <Text bold color={colors.iqMagenta}>❖ comments ({comments.length})</Text> |
| 87 | + <Box flexDirection="column" marginTop={1}> |
| 88 | + {comments.length === 0 ? <Text dimColor>no comments yet</Text> : <ScrollView lines={lines} height={12} offset={scrollOffset} />} |
| 89 | + </Box> |
| 90 | + <Box marginTop={1}><Text dimColor>↑/↓/PgUp/PgDn scroll · esc back</Text></Box> |
| 91 | + </Box> |
| 92 | + ); |
| 93 | + } |
| 94 | + |
| 95 | + if (sub === "blog") { |
| 96 | + const lines = blogNotes.map((n: Note) => ( |
| 97 | + <Box key={n.id} flexDirection="column" marginBottom={1}> |
| 98 | + {n.title ? <Text bold color={colors.iqCyan}>{n.title}</Text> : null} |
| 99 | + {n.text ? <Text> {n.text}</Text> : null} |
| 100 | + {n.image ? <Text dimColor> [image: {n.image}]</Text> : null} |
| 101 | + {n.gitLink ? <Text dimColor> {glyph.sparkle} {n.gitLink}</Text> : null} |
| 102 | + <Text dimColor> {noteDate(n.timestamp)}</Text> |
| 103 | + </Box> |
| 104 | + )); |
| 105 | + return ( |
| 106 | + <Box flexDirection="column" paddingX={1} borderStyle="round" borderColor={colors.iqViolet}> |
| 107 | + <Text bold color={colors.iqMagenta}>❖ blog ({blogNotes.length})</Text> |
| 108 | + <Box flexDirection="column" marginTop={1}> |
| 109 | + {blogNotes.length === 0 ? <Text dimColor>no posts yet</Text> : <ScrollView lines={lines} height={12} offset={scrollOffset} />} |
| 110 | + </Box> |
| 111 | + <Box marginTop={1}> |
| 112 | + <Text dimColor>{self ? "[n] new post · " : ""}↑/↓/PgUp/PgDn scroll · esc back</Text> |
| 113 | + </Box> |
| 114 | + </Box> |
| 115 | + ); |
| 116 | + } |
| 117 | + |
| 118 | + // main |
| 119 | + return ( |
| 120 | + <Box flexDirection="column" paddingX={1} borderStyle="round" borderColor={colors.iqViolet}> |
| 121 | + <Box> |
| 122 | + <Text bold color={colors.iqCyan}>{short(r.wallet)}</Text> |
| 123 | + {cur ? <Text color={colors.warn}> [{cur.name}]</Text> : null} |
| 124 | + <Text dimColor> {r.skillsPublished} skills · ×{r.totalSupply} supply · {r.notesReceived} notes</Text> |
| 125 | + </Box> |
| 126 | + <Box marginTop={1}> |
| 127 | + <Text dimColor>tier </Text><Text>{tierGauge(stars)}</Text> |
| 128 | + </Box> |
| 129 | + <Box> |
| 130 | + <Text dimColor>ladder</Text> |
| 131 | + {STAR_TIERS.map((t) => ( |
| 132 | + <Text key={t.name} color={stars >= t.min ? colors.ok : colors.dim}> {t.name}({t.min})</Text> |
| 133 | + ))} |
| 134 | + </Box> |
| 135 | + <Box marginTop={1}> |
| 136 | + <Text dimColor>earned </Text><Text color={colors.ok}>{earnedSol(r.totalEarned)}</Text> |
| 137 | + </Box> |
| 138 | + |
| 139 | + <Box marginTop={1}> |
| 140 | + <Text dimColor> |
| 141 | + [r] verified repos ({(profile.verifiedRepos ?? []).length}) · [k] comments ({comments.length}) · [g] blog ({blogNotes.length}) |
| 142 | + </Text> |
| 143 | + </Box> |
| 144 | + |
| 145 | + {allSkills.length ? ( |
| 146 | + <Box flexDirection="column" marginTop={1}> |
| 147 | + <Text dimColor>skills:</Text> |
| 148 | + {allSkills.slice(0, 8).map((s: SkillCard) => ( |
| 149 | + <Box key={s.id}> |
| 150 | + <Text> · </Text> |
| 151 | + <Text color={owned.has(s.name) ? colors.ok : undefined}>{s.name}</Text> |
| 152 | + {owned.has(s.name) ? <Text color={colors.ok}> owned</Text> : null} |
| 153 | + </Box> |
| 154 | + ))} |
| 155 | + </Box> |
| 156 | + ) : null} |
| 157 | + |
| 158 | + {buyAllResult ? ( |
| 159 | + <Box marginTop={1}><Text color={colors.ok}>{glyph.sparkle} {buyAllResult}</Text></Box> |
| 160 | + ) : null} |
| 161 | + |
| 162 | + <Box marginTop={1}> |
| 163 | + <Text dimColor> |
| 164 | + {busy |
| 165 | + ? "buying…" |
| 166 | + : unowned.length === 0 |
| 167 | + ? "all skills owned · " |
| 168 | + : unowned.length === allSkills.length |
| 169 | + ? `[b] buy all ${unowned.length} skill${unowned.length !== 1 ? "s" : ""} · ` |
| 170 | + : `[b] buy ${unowned.length} more skill${unowned.length !== 1 ? "s" : ""} · `} |
| 171 | + {self ? "[n] new post · " : ""}esc back |
| 172 | + </Text> |
| 173 | + </Box> |
| 174 | + </Box> |
| 175 | + ); |
| 176 | +} |
0 commit comments