birdclaw 0.8.2 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +10 -8
  3. package/bin/birdclaw.mjs +4 -66
  4. package/dist/cli/birdclaw.js +28165 -0
  5. package/dist/client/assets/AvatarChip-DLoqM5xD.js +1 -0
  6. package/dist/client/assets/ProfilePreview-BejAuYsJ.js +1 -0
  7. package/dist/client/assets/SavedTimelineView-BIS7HKpp.js +1 -0
  8. package/dist/client/assets/SmartTimestamp-BR0-9se2.js +1 -0
  9. package/dist/client/assets/TimelineRouteFrame-CyGPj0eM.js +1 -0
  10. package/dist/client/assets/blocks-7UDKQp8H.js +1 -0
  11. package/dist/client/assets/bookmarks-CbBkMvXk.js +1 -0
  12. package/dist/client/assets/chunk-C0phanGV.js +1 -0
  13. package/dist/client/assets/circle-check-C_Vq3ElD.js +1 -0
  14. package/dist/client/assets/client-stream-contracts-ys3XhWG4.js +5 -0
  15. package/dist/client/assets/createLucideIcon-JV8isFFR.js +1 -0
  16. package/dist/client/assets/data-sources-Cm2bpNvg.js +1 -0
  17. package/dist/client/assets/discuss-DTjaOugw.js +1 -0
  18. package/dist/client/assets/dms-CGd6Eogq.js +1 -0
  19. package/dist/client/assets/inbox-BHlGuOy2.js +1 -0
  20. package/dist/client/assets/index-CEIG7S6s.js +31 -0
  21. package/dist/client/assets/index-bpFrQ5yG.css +1 -0
  22. package/dist/client/assets/likes-cLrcAQem.js +1 -0
  23. package/dist/client/assets/links-CM9QO1LC.js +1 -0
  24. package/dist/client/assets/mapbox-BxTlqXt9.js +2 -0
  25. package/dist/client/assets/mapbox-gl-dgf_hX3a.js +3215 -0
  26. package/dist/client/assets/mentions-CxKCgzIf.js +1 -0
  27. package/dist/client/assets/network-map-B5a3whqj.js +2 -0
  28. package/dist/client/assets/profile-analyze-CRtNEwlb.js +1 -0
  29. package/dist/client/assets/profile-hydration-client-YEtJsNTv.js +1 -0
  30. package/dist/client/assets/profiles._handle-C82_HoKX.js +1 -0
  31. package/dist/client/assets/query-client-fYu2rzRC.js +17 -0
  32. package/dist/client/assets/rate-limits-ScaEwdVK.js +1 -0
  33. package/dist/client/assets/react-dom-DHl6Ug7F.js +1 -0
  34. package/dist/client/assets/react-nBylq1U5.js +1 -0
  35. package/dist/client/assets/repeat-2-xCwHM9hD.js +1 -0
  36. package/dist/client/assets/routes-q7ZaW4En.js +1 -0
  37. package/dist/client/assets/schemas-I9r6F6ya.js +64 -0
  38. package/dist/client/assets/search-Dq5kYsxA.js +1 -0
  39. package/dist/client/assets/sparkles-CQVlvHsZ.js +1 -0
  40. package/dist/client/assets/styles-B8s3tt3r.css +2 -0
  41. package/dist/client/assets/today-CeG1O7Py.js +1 -0
  42. package/dist/client/assets/triangle-alert-CBL7s2pf.js +1 -0
  43. package/dist/client/assets/useTimelineRouteData-1HsqgvUi.js +1 -0
  44. package/dist/client/assets/users-CHbKlqUr.js +1 -0
  45. package/dist/server/assets/AvatarChip-zUDAEmjL.js +105 -0
  46. package/dist/server/assets/FeedState-ntW0Q2GB.js +214 -0
  47. package/dist/server/assets/ProfileAnalysisStream-BFvhVdhn.js +198 -0
  48. package/dist/server/assets/ProfilePreview-C6gAor_j.js +752 -0
  49. package/dist/server/assets/SavedTimelineView-BG1jnBp1.js +64 -0
  50. package/dist/server/assets/SmartTimestamp-DfwE1NGf.js +45 -0
  51. package/dist/server/assets/SyncNowButton-BOn_IBXS.js +76 -0
  52. package/dist/server/assets/TimelineRouteFrame-CU7ilM7U.js +85 -0
  53. package/dist/server/assets/TweetRichText-DhCVv1-6.js +74 -0
  54. package/dist/server/assets/_tanstack-start-manifest_v-C-ZRnG_n.js +148 -0
  55. package/dist/server/assets/account-selection-CTdFGWRk.js +44 -0
  56. package/dist/server/assets/blocks-C1mgGTB3.js +299 -0
  57. package/dist/server/assets/blocks-DSgQghqP.js +17 -0
  58. package/dist/server/assets/bookmarks-BJN8tykY.js +14 -0
  59. package/dist/server/assets/client-stream-contracts-C2xbWVjm.js +769 -0
  60. package/dist/server/assets/data-sources-BnA1Q94p.js +180 -0
  61. package/dist/server/assets/discuss-CJ1dau1j.js +15 -0
  62. package/dist/server/assets/discuss-QTo08NCN.js +338 -0
  63. package/dist/server/assets/dms-BuLj4bp8.js +368 -0
  64. package/dist/server/assets/dms-DAyQrVM2.js +240 -0
  65. package/dist/server/assets/empty-plugin-adapters-DzrEkdBF.js +5 -0
  66. package/dist/server/assets/inbox-CkGOaW1q.js +214 -0
  67. package/dist/server/assets/inbox-DpWd1EzC.js +146 -0
  68. package/dist/server/assets/likes-DBOAtsJU.js +14 -0
  69. package/dist/server/assets/links-DAhSjynu.js +240 -0
  70. package/dist/server/assets/links-DmH5lxHO.js +468 -0
  71. package/dist/server/assets/mentions-BH2MzKtB.js +26 -0
  72. package/dist/server/assets/network-map-D3CzRcC4.js +224 -0
  73. package/dist/server/assets/network-map-D5DoLOwR.js +582 -0
  74. package/dist/server/assets/profile-analyze-BP65PED0.js +90 -0
  75. package/dist/server/assets/profile-analyze-C1NoM0tV.js +9 -0
  76. package/dist/server/assets/profile-hydration-client-GJ4kwJS8.js +133 -0
  77. package/dist/server/assets/profiles._handle-DjwlN_ac.js +184 -0
  78. package/dist/server/assets/profiles._handle-DsLNj2Ca.js +12 -0
  79. package/dist/server/assets/query-client-BdauHBgd.js +923 -0
  80. package/dist/server/assets/rate-limits-VAr2qzYD.js +262 -0
  81. package/dist/server/assets/route-search-BUlQ5lGM.js +117 -0
  82. package/dist/server/assets/router-DqkwSPiM.js +17026 -0
  83. package/dist/server/assets/routes-A9c9ZhwN.js +26 -0
  84. package/dist/server/assets/start-FaDOTmto.js +4 -0
  85. package/dist/server/assets/today-B5hVM57Z.js +17 -0
  86. package/dist/server/assets/today-fvGiZ7ud.js +303 -0
  87. package/dist/server/assets/ui-qbmcMSSX.js +137 -0
  88. package/{src/components/useDebouncedValue.ts → dist/server/assets/useDebouncedValue-DOnA6Xcy.js} +4 -4
  89. package/dist/server/assets/useTimelineRouteData-27cxynxa.js +1101 -0
  90. package/dist/server/server.js +5520 -0
  91. package/package.json +27 -34
  92. package/playwright.config.ts +0 -35
  93. package/scripts/browser-perf.mjs +0 -427
  94. package/scripts/build-docs-site.mjs +0 -967
  95. package/scripts/docs-site-assets.mjs +0 -311
  96. package/scripts/run-vitest.mjs +0 -21
  97. package/scripts/sanitize-node-options.mjs +0 -23
  98. package/scripts/start-test-server.mjs +0 -42
  99. package/src/cli-moderation.ts +0 -210
  100. package/src/cli.ts +0 -2336
  101. package/src/components/AccountSwitcher.tsx +0 -186
  102. package/src/components/AppNav.tsx +0 -118
  103. package/src/components/AvatarChip.tsx +0 -58
  104. package/src/components/BrandMark.tsx +0 -67
  105. package/src/components/ConversationThread.tsx +0 -131
  106. package/src/components/DmWorkspace.tsx +0 -286
  107. package/src/components/EmbeddedTweetCard.tsx +0 -55
  108. package/src/components/FeedState.tsx +0 -147
  109. package/src/components/FloatingPreview.tsx +0 -382
  110. package/src/components/InboxCard.tsx +0 -152
  111. package/src/components/LinkPreviewCard.tsx +0 -292
  112. package/src/components/MarkdownViewer.tsx +0 -777
  113. package/src/components/ProfileAnalysisStream.tsx +0 -428
  114. package/src/components/ProfilePreview.tsx +0 -129
  115. package/src/components/SavedTimelineView.tsx +0 -155
  116. package/src/components/SmartTimestamp.tsx +0 -72
  117. package/src/components/SyncNowButton.tsx +0 -140
  118. package/src/components/ThemeSlider.tsx +0 -80
  119. package/src/components/TimelineCard.tsx +0 -533
  120. package/src/components/TimelineRouteFrame.tsx +0 -186
  121. package/src/components/TweetArticleCard.tsx +0 -66
  122. package/src/components/TweetMediaGrid.tsx +0 -185
  123. package/src/components/TweetRichText.tsx +0 -159
  124. package/src/components/account-selection.ts +0 -64
  125. package/src/components/useTimelineRouteData.ts +0 -323
  126. package/src/lib/account-sync-job.ts +0 -666
  127. package/src/lib/actions-transport.ts +0 -300
  128. package/src/lib/api-client.ts +0 -419
  129. package/src/lib/archive-finder.ts +0 -185
  130. package/src/lib/archive-import.ts +0 -2764
  131. package/src/lib/authored-live.ts +0 -1072
  132. package/src/lib/avatar-cache.ts +0 -349
  133. package/src/lib/backup.ts +0 -2741
  134. package/src/lib/bird-actions.ts +0 -294
  135. package/src/lib/bird-command.ts +0 -130
  136. package/src/lib/bird.ts +0 -1140
  137. package/src/lib/blocklist.ts +0 -136
  138. package/src/lib/blocks-write.ts +0 -167
  139. package/src/lib/blocks.ts +0 -389
  140. package/src/lib/bookmark-sync-job.ts +0 -536
  141. package/src/lib/client-cache.ts +0 -109
  142. package/src/lib/config.ts +0 -224
  143. package/src/lib/conversation-surface.ts +0 -205
  144. package/src/lib/data-sources.ts +0 -219
  145. package/src/lib/db.ts +0 -1135
  146. package/src/lib/dms-live.ts +0 -933
  147. package/src/lib/effect-runtime.ts +0 -45
  148. package/src/lib/follow-graph.ts +0 -1097
  149. package/src/lib/geocoding.ts +0 -296
  150. package/src/lib/http-effect.ts +0 -222
  151. package/src/lib/identity-search-index.ts +0 -369
  152. package/src/lib/inbox.ts +0 -241
  153. package/src/lib/link-index.ts +0 -641
  154. package/src/lib/link-insights.ts +0 -860
  155. package/src/lib/link-preview-metadata.ts +0 -754
  156. package/src/lib/location.ts +0 -137
  157. package/src/lib/media-fetch.ts +0 -860
  158. package/src/lib/media-includes.ts +0 -165
  159. package/src/lib/mention-threads-live.ts +0 -917
  160. package/src/lib/mentions-export.ts +0 -147
  161. package/src/lib/mentions-live.ts +0 -1238
  162. package/src/lib/moderation-target.ts +0 -216
  163. package/src/lib/moderation-write.ts +0 -131
  164. package/src/lib/mutes-write.ts +0 -167
  165. package/src/lib/mutes.ts +0 -84
  166. package/src/lib/ndjson-stream.ts +0 -106
  167. package/src/lib/network-map.ts +0 -382
  168. package/src/lib/openai.ts +0 -117
  169. package/src/lib/period-digest.ts +0 -1552
  170. package/src/lib/present.ts +0 -118
  171. package/src/lib/profile-affiliation-hydration.ts +0 -228
  172. package/src/lib/profile-affiliations.ts +0 -262
  173. package/src/lib/profile-analysis.ts +0 -1272
  174. package/src/lib/profile-bio-entities.ts +0 -318
  175. package/src/lib/profile-history.ts +0 -164
  176. package/src/lib/profile-hydration.ts +0 -180
  177. package/src/lib/profile-replies.ts +0 -77
  178. package/src/lib/profile-resolver.ts +0 -650
  179. package/src/lib/queries.ts +0 -2381
  180. package/src/lib/research.ts +0 -652
  181. package/src/lib/search-discussion.ts +0 -1016
  182. package/src/lib/seed.ts +0 -613
  183. package/src/lib/sqlite.ts +0 -147
  184. package/src/lib/sync-cache.ts +0 -65
  185. package/src/lib/theme-transition.ts +0 -113
  186. package/src/lib/theme.tsx +0 -165
  187. package/src/lib/timeline-collections-live.ts +0 -581
  188. package/src/lib/timeline-live.ts +0 -452
  189. package/src/lib/tweet-account-edges.ts +0 -48
  190. package/src/lib/tweet-lookup.ts +0 -46
  191. package/src/lib/tweet-render.ts +0 -430
  192. package/src/lib/tweet-search-live.ts +0 -566
  193. package/src/lib/types.ts +0 -723
  194. package/src/lib/ui.ts +0 -529
  195. package/src/lib/url-expansion-store.ts +0 -110
  196. package/src/lib/url-expansion.ts +0 -343
  197. package/src/lib/url-safety.ts +0 -220
  198. package/src/lib/web-sync.ts +0 -516
  199. package/src/lib/whois.ts +0 -1079
  200. package/src/lib/x-profile.ts +0 -365
  201. package/src/lib/x-web.ts +0 -199
  202. package/src/lib/xurl-rate-limits.ts +0 -267
  203. package/src/lib/xurl.ts +0 -1677
  204. package/src/routeTree.gen.ts +0 -723
  205. package/src/router.tsx +0 -20
  206. package/src/routes/__root.tsx +0 -79
  207. package/src/routes/api/action.tsx +0 -147
  208. package/src/routes/api/avatar.tsx +0 -50
  209. package/src/routes/api/blocks.tsx +0 -35
  210. package/src/routes/api/conversation.tsx +0 -45
  211. package/src/routes/api/data-sources.tsx +0 -24
  212. package/src/routes/api/inbox.tsx +0 -43
  213. package/src/routes/api/link-insights.tsx +0 -85
  214. package/src/routes/api/link-preview.tsx +0 -47
  215. package/src/routes/api/network-map.tsx +0 -55
  216. package/src/routes/api/period-digest.tsx +0 -101
  217. package/src/routes/api/profile-analysis.tsx +0 -97
  218. package/src/routes/api/profile-hydrate.tsx +0 -54
  219. package/src/routes/api/query.tsx +0 -115
  220. package/src/routes/api/search-discussion.tsx +0 -113
  221. package/src/routes/api/status.tsx +0 -28
  222. package/src/routes/api/sync.tsx +0 -105
  223. package/src/routes/api/xurl-rate-limits.tsx +0 -24
  224. package/src/routes/blocks.tsx +0 -377
  225. package/src/routes/bookmarks.tsx +0 -18
  226. package/src/routes/data-sources.tsx +0 -257
  227. package/src/routes/discuss.tsx +0 -419
  228. package/src/routes/dms.tsx +0 -432
  229. package/src/routes/inbox.tsx +0 -226
  230. package/src/routes/index.tsx +0 -32
  231. package/src/routes/likes.tsx +0 -18
  232. package/src/routes/links.tsx +0 -994
  233. package/src/routes/mentions.tsx +0 -32
  234. package/src/routes/network-map.tsx +0 -1035
  235. package/src/routes/profile-analyze.tsx +0 -112
  236. package/src/routes/profiles.$handle.tsx +0 -228
  237. package/src/routes/rate-limits.tsx +0 -309
  238. package/src/routes/today.tsx +0 -511
  239. package/src/styles.css +0 -257
  240. package/tsconfig.json +0 -29
  241. package/vite.config.ts +0 -29
  242. /package/{public → dist/client}/birdclaw-mark.png +0 -0
  243. /package/{public → dist/client}/favicon.ico +0 -0
  244. /package/{public → dist/client}/logo192.png +0 -0
  245. /package/{public → dist/client}/logo512.png +0 -0
  246. /package/{public → dist/client}/manifest.json +0 -0
  247. /package/{public → dist/client}/robots.txt +0 -0
@@ -1,428 +0,0 @@
1
- import { CheckCircle2, Loader2, Sparkles } from "lucide-react";
2
- import { useCallback, useEffect, useRef, useState } from "react";
3
- import { MarkdownViewer } from "#/components/MarkdownViewer";
4
- import type {
5
- ProfileAnalysisContext,
6
- ProfileAnalysisRunResult,
7
- ProfileAnalysisStreamEvent,
8
- } from "#/lib/profile-analysis";
9
- import type { ProfileRecord } from "#/lib/types";
10
- import { errorCopyClass } from "#/lib/ui";
11
-
12
- export interface ProfileAnalysisRequestOptions {
13
- refresh: boolean;
14
- maxTweets: number;
15
- maxPages: number;
16
- maxConversations: number;
17
- maxConversationPages: number;
18
- }
19
-
20
- export interface ProfileAnalysisState {
21
- context: ProfileAnalysisContext | null;
22
- error: string | null;
23
- loading: boolean;
24
- markdown: string;
25
- result: ProfileAnalysisRunResult | null;
26
- run: (refresh?: boolean, overrideHandle?: string) => void;
27
- status: string;
28
- }
29
-
30
- export const DEFAULT_PROFILE_ANALYSIS_LIMITS = {
31
- maxTweets: 10000,
32
- maxPages: 100,
33
- maxConversations: 80,
34
- maxConversationPages: 3,
35
- } as const;
36
-
37
- const PROFILE_HYDRATION_LIMIT = 50;
38
- const PROFILE_MENTION_RE = /(^|[^\w@./])@([A-Za-z0-9_]{1,15})\b/g;
39
-
40
- function normalizeProfileHandle(value: string) {
41
- return value.trim().replace(/^@/, "").toLowerCase();
42
- }
43
-
44
- function handlesFromText(value: string) {
45
- return Array.from(value.matchAll(PROFILE_MENTION_RE)).map(
46
- (match) => match[2],
47
- );
48
- }
49
-
50
- function knownProfileHandles(context: ProfileAnalysisContext) {
51
- const handles = new Set<string>();
52
- handles.add(normalizeProfileHandle(context.profile.handle));
53
- for (const profile of context.profiles ?? []) {
54
- handles.add(normalizeProfileHandle(profile.handle));
55
- }
56
- for (const tweet of context.conversations) {
57
- handles.add(normalizeProfileHandle(tweet.author));
58
- }
59
- return handles;
60
- }
61
-
62
- function collectProfileAnalysisHydrationHandles({
63
- context,
64
- analysis,
65
- markdown,
66
- }: {
67
- context: ProfileAnalysisContext;
68
- analysis?: ProfileAnalysisRunResult["analysis"];
69
- markdown?: string;
70
- }) {
71
- const handles = new Set<string>();
72
- const known = knownProfileHandles(context);
73
- const add = (value: string | undefined) => {
74
- if (!value) return;
75
- const handle = normalizeProfileHandle(value);
76
- if (!/^[a-z0-9_]{1,15}$/.test(handle) || known.has(handle)) return;
77
- handles.add(handle);
78
- };
79
-
80
- for (const handle of analysis?.sourceHandles ?? []) add(handle);
81
- for (const theme of analysis?.themes ?? []) {
82
- for (const handle of theme.handles) add(handle);
83
- }
84
- if (markdown) {
85
- for (const handle of handlesFromText(markdown)) add(handle);
86
- }
87
- for (const handle of handlesFromText(context.profile.bio)) add(handle);
88
- for (const tweet of context.tweets) {
89
- for (const handle of handlesFromText(tweet.text)) add(handle);
90
- }
91
- for (const tweet of context.conversations) {
92
- for (const handle of handlesFromText(tweet.text)) add(handle);
93
- for (const handle of handlesFromText(tweet.bio)) add(handle);
94
- }
95
-
96
- return [...handles].slice(0, PROFILE_HYDRATION_LIMIT);
97
- }
98
-
99
- function applyHydratedProfilesToProfileAnalysisContext(
100
- context: ProfileAnalysisContext,
101
- profiles: ProfileRecord[],
102
- ) {
103
- const existing = new Map<string, ProfileRecord>();
104
- for (const profile of context.profiles ?? []) {
105
- existing.set(normalizeProfileHandle(profile.handle), profile);
106
- }
107
- for (const profile of profiles) {
108
- existing.set(normalizeProfileHandle(profile.handle), profile);
109
- }
110
- return {
111
- ...context,
112
- profiles: [...existing.values()],
113
- };
114
- }
115
-
116
- async function hydrateProfileAnalysisContext({
117
- context,
118
- analysis,
119
- markdown,
120
- requestedHandles,
121
- }: {
122
- context: ProfileAnalysisContext;
123
- analysis?: ProfileAnalysisRunResult["analysis"];
124
- markdown?: string;
125
- requestedHandles?: Set<string>;
126
- }) {
127
- const handles = collectProfileAnalysisHydrationHandles({
128
- context,
129
- analysis,
130
- markdown,
131
- }).filter((handle) => !requestedHandles?.has(handle));
132
- if (handles.length === 0) return context;
133
- for (const handle of handles) {
134
- requestedHandles?.add(handle);
135
- }
136
- const url = new URL("/api/profile-hydrate", window.location.origin);
137
- url.searchParams.set("handles", handles.join(","));
138
- const response = await fetch(url);
139
- if (!response.ok) return context;
140
- const payload = (await response.json()) as {
141
- results?: Array<{ status?: string; profile?: ProfileRecord }>;
142
- };
143
- const profiles = (payload.results ?? [])
144
- .filter((item) => item.status === "hit" && item.profile)
145
- .map((item) => item.profile as ProfileRecord);
146
- return profiles.length > 0
147
- ? applyHydratedProfilesToProfileAnalysisContext(context, profiles)
148
- : context;
149
- }
150
-
151
- export function profileAnalysisUrl(
152
- handle: string,
153
- options: ProfileAnalysisRequestOptions,
154
- ) {
155
- const params = new URLSearchParams();
156
- params.set("handle", handle);
157
- params.set("maxTweets", String(options.maxTweets));
158
- params.set("maxPages", String(options.maxPages));
159
- params.set("maxConversations", String(options.maxConversations));
160
- params.set("maxConversationPages", String(options.maxConversationPages));
161
- if (options.refresh) {
162
- params.set("refresh", "true");
163
- }
164
- return `/api/profile-analysis?${params.toString()}`;
165
- }
166
-
167
- export async function profileAnalysisRequestError(response: Response) {
168
- const status = `${String(response.status)}${response.statusText ? ` ${response.statusText}` : ""}`;
169
- let detail = "";
170
- try {
171
- const contentType = response.headers.get("content-type") ?? "";
172
- if (contentType.includes("application/json")) {
173
- const payload = (await response.json()) as {
174
- error?: unknown;
175
- message?: unknown;
176
- };
177
- if (typeof payload.message === "string") detail = payload.message;
178
- else if (typeof payload.error === "string") detail = payload.error;
179
- } else {
180
- detail = (await response.text()).trim();
181
- }
182
- } catch {
183
- detail = "";
184
- }
185
- return new Error(
186
- detail
187
- ? `Profile analysis failed (${status}): ${detail}`
188
- : `Profile analysis failed (${status})`,
189
- );
190
- }
191
-
192
- export function formatProfileAnalysisCounts(
193
- context: ProfileAnalysisContext | null,
194
- ) {
195
- if (!context) return "xurl profile backfill with cached AI analysis.";
196
- return [
197
- context.fetchCached ? "cached backfill" : "fresh xurl backfill",
198
- `${String(context.counts.tweets)} tweets`,
199
- `${String(context.counts.conversationTweets)} conversation tweets`,
200
- `${String(context.counts.conversationsScanned)} conversations`,
201
- ].join(" · ");
202
- }
203
-
204
- export function cleanProfileHandle(value: string) {
205
- return value.trim().replace(/^@/, "");
206
- }
207
-
208
- export function useProfileAnalysisStream(handle: string): ProfileAnalysisState {
209
- const [markdown, setMarkdown] = useState("");
210
- const [context, setContext] = useState<ProfileAnalysisContext | null>(null);
211
- const [result, setResult] = useState<ProfileAnalysisRunResult | null>(null);
212
- const [status, setStatus] = useState("Ready");
213
- const [error, setError] = useState<string | null>(null);
214
- const [loading, setLoading] = useState(false);
215
- const abortRef = useRef<AbortController | null>(null);
216
- const requestIdRef = useRef(0);
217
-
218
- const run = useCallback(
219
- (refresh = false, overrideHandle?: string) => {
220
- const trimmed = cleanProfileHandle(overrideHandle ?? handle);
221
- if (!trimmed) return;
222
- abortRef.current?.abort();
223
- const controller = new AbortController();
224
- const requestId = requestIdRef.current + 1;
225
- requestIdRef.current = requestId;
226
- abortRef.current = controller;
227
- const isActiveRequest = () =>
228
- abortRef.current === controller &&
229
- requestIdRef.current === requestId &&
230
- !controller.signal.aborted;
231
- const requestedHydrationHandles = new Set<string>();
232
- const hydratedProfilesByHandle = new Map<string, ProfileRecord>();
233
- const rememberHydratedProfiles = (
234
- nextContext: ProfileAnalysisContext,
235
- ) => {
236
- for (const profile of nextContext.profiles ?? []) {
237
- hydratedProfilesByHandle.set(
238
- normalizeProfileHandle(profile.handle),
239
- profile,
240
- );
241
- }
242
- };
243
- const mergeKnownHydratedProfiles = (
244
- nextContext: ProfileAnalysisContext,
245
- ) =>
246
- hydratedProfilesByHandle.size > 0
247
- ? applyHydratedProfilesToProfileAnalysisContext(nextContext, [
248
- ...hydratedProfilesByHandle.values(),
249
- ])
250
- : nextContext;
251
- const hydrateContext = (
252
- nextContext: ProfileAnalysisContext,
253
- nextResult?: ProfileAnalysisRunResult,
254
- ) => {
255
- void hydrateProfileAnalysisContext({
256
- context: nextContext,
257
- analysis: nextResult?.analysis,
258
- markdown: nextResult?.markdown,
259
- requestedHandles: requestedHydrationHandles,
260
- })
261
- .then((hydratedContext) => {
262
- if (!isActiveRequest()) return;
263
- if (hydratedContext === nextContext) return;
264
- rememberHydratedProfiles(hydratedContext);
265
- const mergedContext = mergeKnownHydratedProfiles(hydratedContext);
266
- setContext(mergedContext);
267
- if (nextResult) {
268
- setResult({
269
- ...nextResult,
270
- context: mergedContext,
271
- });
272
- }
273
- })
274
- .catch(() => {
275
- // Profile hover hydration is best-effort; analysis remains usable.
276
- });
277
- };
278
- setMarkdown("");
279
- setContext(null);
280
- setResult(null);
281
- setError(null);
282
- setLoading(true);
283
- setStatus("Starting profile analysis");
284
-
285
- fetch(
286
- profileAnalysisUrl(trimmed, {
287
- refresh,
288
- ...DEFAULT_PROFILE_ANALYSIS_LIMITS,
289
- }),
290
- { signal: controller.signal },
291
- )
292
- .then(async (response) => {
293
- if (!response.ok) {
294
- throw await profileAnalysisRequestError(response);
295
- }
296
- if (!response.body) {
297
- throw new Error("Profile analysis failed: empty response body");
298
- }
299
- const reader = response.body.getReader();
300
- const decoder = new TextDecoder();
301
- let buffer = "";
302
- const pump = (): Promise<void> =>
303
- reader.read().then(({ done, value }) => {
304
- if (!isActiveRequest()) return;
305
- if (done) return;
306
- buffer += decoder.decode(value, { stream: true });
307
- let newline = buffer.indexOf("\n");
308
- while (newline >= 0) {
309
- const line = buffer.slice(0, newline).trim();
310
- buffer = buffer.slice(newline + 1);
311
- if (line) {
312
- const event = JSON.parse(line) as ProfileAnalysisStreamEvent;
313
- if (!isActiveRequest()) return;
314
- if (event.type === "status") {
315
- setStatus(
316
- event.detail
317
- ? `${event.label} · ${event.detail}`
318
- : event.label,
319
- );
320
- } else if (event.type === "start") {
321
- setContext(event.context);
322
- setStatus(
323
- event.cached
324
- ? "Loading cached analysis"
325
- : "Summarizing profile",
326
- );
327
- hydrateContext(event.context);
328
- } else if (event.type === "delta") {
329
- setMarkdown((current) => current + event.delta);
330
- } else if (event.type === "done") {
331
- const mergedContext = mergeKnownHydratedProfiles(
332
- event.result.context,
333
- );
334
- const mergedResult =
335
- mergedContext === event.result.context
336
- ? event.result
337
- : {
338
- ...event.result,
339
- context: mergedContext,
340
- };
341
- setResult(mergedResult);
342
- setContext(mergedContext);
343
- setMarkdown(event.result.markdown);
344
- setStatus(event.result.cached ? "Cached" : "Complete");
345
- hydrateContext(mergedContext, mergedResult);
346
- } else if (event.type === "error") {
347
- setError(event.error);
348
- }
349
- }
350
- newline = buffer.indexOf("\n");
351
- }
352
- return pump();
353
- });
354
- return pump();
355
- })
356
- .catch((cause: unknown) => {
357
- if (!isActiveRequest()) return;
358
- setError(cause instanceof Error ? cause.message : "Analysis failed");
359
- })
360
- .finally(() => {
361
- if (!isActiveRequest()) return;
362
- setLoading(false);
363
- });
364
- },
365
- [handle],
366
- );
367
-
368
- useEffect(
369
- () => () => {
370
- abortRef.current?.abort();
371
- },
372
- [],
373
- );
374
-
375
- return { context, error, loading, markdown, result, run, status };
376
- }
377
-
378
- export function ProfileAnalysisStatusLine({
379
- analysis,
380
- className = "",
381
- }: {
382
- analysis: ProfileAnalysisState;
383
- className?: string;
384
- }) {
385
- return (
386
- <div
387
- className={`flex items-center gap-2 text-[13px] font-medium text-[var(--ink-soft)] ${className}`}
388
- >
389
- {analysis.loading ? (
390
- <Loader2 className="size-4 animate-spin" strokeWidth={1.8} />
391
- ) : analysis.result ? (
392
- <CheckCircle2 className="size-4" strokeWidth={1.8} />
393
- ) : (
394
- <Sparkles className="size-4" strokeWidth={1.8} />
395
- )}
396
- <span>{analysis.status}</span>
397
- </div>
398
- );
399
- }
400
-
401
- export function ProfileAnalysisOutput({
402
- analysis,
403
- emptyLabel = "No profile selected.",
404
- }: {
405
- analysis: ProfileAnalysisState;
406
- emptyLabel?: string;
407
- }) {
408
- return (
409
- <>
410
- {analysis.error ? (
411
- <div className={errorCopyClass}>{analysis.error}</div>
412
- ) : null}
413
-
414
- {analysis.markdown ? (
415
- <div className="max-w-3xl">
416
- <MarkdownViewer
417
- context={analysis.context}
418
- markdown={analysis.markdown}
419
- />
420
- </div>
421
- ) : (
422
- <div className="rounded-[8px] border border-[var(--line)] bg-[var(--panel)] p-6 text-[14px] text-[var(--ink-soft)]">
423
- {emptyLabel}
424
- </div>
425
- )}
426
- </>
427
- );
428
- }
@@ -1,129 +0,0 @@
1
- import { Fragment, type ReactNode } from "react";
2
- import { formatCompactNumber } from "#/lib/present";
3
- import {
4
- collectTweetSegmentsForText,
5
- profileDescriptionEntitiesFromXurl,
6
- } from "#/lib/tweet-render";
7
- import type { ProfileRecord } from "#/lib/types";
8
- import {
9
- cx,
10
- profilePreviewBioClass,
11
- profilePreviewCardClass,
12
- profilePreviewClass,
13
- profilePreviewHandleClass,
14
- profilePreviewHeaderClass,
15
- profilePreviewMetaClass,
16
- profilePreviewNameClass,
17
- profilePreviewTriggerClass,
18
- tweetLinkClass,
19
- } from "#/lib/ui";
20
- import { safeHttpUrl } from "#/lib/url-safety";
21
- import { AvatarChip } from "./AvatarChip";
22
- import { useFloatingPreview } from "./FloatingPreview";
23
-
24
- function ProfilePreviewBio({ profile }: { profile: ProfileRecord }) {
25
- const segments = collectTweetSegmentsForText(
26
- profile.bio,
27
- profileDescriptionEntitiesFromXurl(profile.entities),
28
- );
29
- let cursor = 0;
30
-
31
- return (
32
- <span className={profilePreviewBioClass}>
33
- {segments.map((segment, index) => {
34
- if (
35
- segment.kind !== "url" ||
36
- segment.start < cursor ||
37
- segment.end <= segment.start ||
38
- segment.end > profile.bio.length
39
- ) {
40
- return null;
41
- }
42
- const prefix = profile.bio.slice(cursor, segment.start);
43
- cursor = segment.end;
44
- const href = safeHttpUrl(segment.expandedUrl);
45
- return (
46
- <Fragment key={`${segment.url}-${String(index)}`}>
47
- {prefix}
48
- {href ? (
49
- <a
50
- className={tweetLinkClass}
51
- href={href}
52
- rel="noreferrer"
53
- target="_blank"
54
- >
55
- {segment.expandedUrl}
56
- </a>
57
- ) : (
58
- profile.bio.slice(segment.start, segment.end)
59
- )}
60
- </Fragment>
61
- );
62
- })}
63
- {profile.bio.slice(cursor)}
64
- </span>
65
- );
66
- }
67
-
68
- export function ProfilePreview({
69
- profile,
70
- children,
71
- className = "",
72
- }: {
73
- profile: ProfileRecord;
74
- children: ReactNode;
75
- className?: string;
76
- }) {
77
- const preview = useFloatingPreview();
78
-
79
- return (
80
- <span
81
- ref={preview.referenceRef}
82
- className={cx(profilePreviewClass, className)}
83
- {...preview.referenceProps}
84
- >
85
- <a
86
- aria-controls={preview.open ? preview.floatingId : undefined}
87
- aria-expanded={preview.open}
88
- className={profilePreviewTriggerClass}
89
- href={`/profiles/${encodeURIComponent(profile.handle)}`}
90
- >
91
- {children}
92
- </a>
93
- {preview.open ? (
94
- <span
95
- aria-label={`${profile.displayName} profile preview`}
96
- id={preview.floatingId}
97
- ref={preview.floatingRef}
98
- className={profilePreviewCardClass}
99
- role="group"
100
- style={preview.floatingStyle}
101
- {...preview.floatingProps}
102
- >
103
- <span className="grid gap-2" data-floating-preview-content>
104
- <span className={profilePreviewHeaderClass}>
105
- <AvatarChip
106
- avatarUrl={profile.avatarUrl}
107
- hue={profile.avatarHue}
108
- name={profile.displayName}
109
- profileId={profile.id}
110
- />
111
- <span className="flex min-w-0 flex-col">
112
- <span className={profilePreviewNameClass}>
113
- {profile.displayName}
114
- </span>
115
- <span className={profilePreviewHandleClass}>
116
- @{profile.handle}
117
- </span>
118
- </span>
119
- </span>
120
- {profile.bio ? <ProfilePreviewBio profile={profile} /> : null}
121
- <span className={profilePreviewMetaClass}>
122
- {formatCompactNumber(profile.followersCount)} followers
123
- </span>
124
- </span>
125
- </span>
126
- ) : null}
127
- </span>
128
- );
129
- }
@@ -1,155 +0,0 @@
1
- import { Search } from "lucide-react";
2
- import { useMemo, useState } from "react";
3
- import {
4
- FeedEmpty,
5
- FeedError,
6
- FeedLoading,
7
- TweetSkeletonRows,
8
- } from "#/components/FeedState";
9
- import { SyncNowButton } from "#/components/SyncNowButton";
10
- import { TimelineCard } from "#/components/TimelineCard";
11
- import { useTimelineRouteData } from "#/components/useTimelineRouteData";
12
- import { ConversationSurfaceScope } from "#/lib/conversation-surface";
13
- import {
14
- feedClass,
15
- pageHeaderClass,
16
- pageHeaderRowClass,
17
- pageSubtitleClass,
18
- pageTitleClass,
19
- searchFieldIconClass,
20
- searchFieldInputClass,
21
- searchFieldShellClass,
22
- } from "#/lib/ui";
23
-
24
- interface SavedTimelineViewProps {
25
- filter: "liked" | "bookmarked";
26
- eyebrow: string;
27
- title: string;
28
- loadingLabel: string;
29
- searchPlaceholder: string;
30
- }
31
-
32
- const TITLES: Record<SavedTimelineViewProps["filter"], string> = {
33
- liked: "Likes",
34
- bookmarked: "Bookmarks",
35
- };
36
-
37
- export function SavedTimelineView({
38
- filter,
39
- title,
40
- loadingLabel,
41
- searchPlaceholder,
42
- }: SavedTimelineViewProps) {
43
- const [search, setSearch] = useState("");
44
- const {
45
- meta,
46
- items,
47
- loading,
48
- error,
49
- retry,
50
- refreshLocalView,
51
- replyToTweet,
52
- hasMore,
53
- loadingMore,
54
- loadMore,
55
- } = useTimelineRouteData({
56
- resource: "home",
57
- search,
58
- errorFallback: `${TITLES[filter]} unavailable`,
59
- likedOnly: filter === "liked",
60
- bookmarkedOnly: filter === "bookmarked",
61
- });
62
-
63
- const subtitle = useMemo(() => {
64
- if (!meta) {
65
- return items.length > 0
66
- ? `${String(items.length)} visible`
67
- : loadingLabel;
68
- }
69
- return `${String(items.length)} visible · ${meta.transport.statusText}`;
70
- }, [items.length, loadingLabel, meta]);
71
-
72
- const syncKind = filter === "liked" ? "likes" : "bookmarks";
73
-
74
- return (
75
- <>
76
- <header className={pageHeaderClass}>
77
- <div className={pageHeaderRowClass}>
78
- <div className="flex min-w-0 flex-col">
79
- <h1 className={pageTitleClass}>{TITLES[filter]}</h1>
80
- <p className={pageSubtitleClass}>{title}</p>
81
- <p className={pageSubtitleClass}>{subtitle}</p>
82
- </div>
83
- <SyncNowButton
84
- accounts={meta?.accounts}
85
- kind={syncKind}
86
- label={filter === "liked" ? "Sync likes" : "Sync bookmarks"}
87
- onSynced={refreshLocalView}
88
- />
89
- </div>
90
- <div className="px-4 pb-3">
91
- <label className={searchFieldShellClass}>
92
- <Search className={searchFieldIconClass} strokeWidth={2} />
93
- <input
94
- className={searchFieldInputClass}
95
- onChange={(event) => setSearch(event.target.value)}
96
- placeholder={searchPlaceholder}
97
- value={search}
98
- />
99
- </label>
100
- </div>
101
- </header>
102
- <ConversationSurfaceScope>
103
- <section className={feedClass}>
104
- {loading ? (
105
- <FeedLoading
106
- detail={`Reading local ${TITLES[filter].toLowerCase()}`}
107
- label={loadingLabel}
108
- >
109
- <TweetSkeletonRows />
110
- </FeedLoading>
111
- ) : error ? (
112
- <FeedError
113
- action={
114
- <button
115
- className="rounded-full bg-[var(--accent)] px-4 py-1.5 text-[14px] font-bold text-white"
116
- onClick={retry}
117
- type="button"
118
- >
119
- Retry
120
- </button>
121
- }
122
- message={error}
123
- title={`Could not load ${TITLES[filter].toLowerCase()}`}
124
- />
125
- ) : items.length === 0 ? (
126
- <FeedEmpty
127
- detail="Sync this collection or broaden the search."
128
- label="Nothing saved here yet"
129
- />
130
- ) : null}
131
- {items.map((item) => (
132
- <TimelineCard
133
- key={item.id}
134
- item={item}
135
- onReply={replyToTweet}
136
- showReplyControls={false}
137
- />
138
- ))}
139
- {!loading && !error && hasMore ? (
140
- <div className="flex justify-center py-4">
141
- <button
142
- className="rounded-full bg-[var(--accent)] px-5 py-1.5 text-[14px] font-bold text-white disabled:opacity-60"
143
- disabled={loadingMore}
144
- onClick={loadMore}
145
- type="button"
146
- >
147
- {loadingMore ? "Loading…" : "Load more"}
148
- </button>
149
- </div>
150
- ) : null}
151
- </section>
152
- </ConversationSurfaceScope>
153
- </>
154
- );
155
- }