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.
- package/CHANGELOG.md +33 -0
- package/README.md +10 -8
- package/bin/birdclaw.mjs +4 -66
- package/dist/cli/birdclaw.js +28165 -0
- package/dist/client/assets/AvatarChip-DLoqM5xD.js +1 -0
- package/dist/client/assets/ProfilePreview-BejAuYsJ.js +1 -0
- package/dist/client/assets/SavedTimelineView-BIS7HKpp.js +1 -0
- package/dist/client/assets/SmartTimestamp-BR0-9se2.js +1 -0
- package/dist/client/assets/TimelineRouteFrame-CyGPj0eM.js +1 -0
- package/dist/client/assets/blocks-7UDKQp8H.js +1 -0
- package/dist/client/assets/bookmarks-CbBkMvXk.js +1 -0
- package/dist/client/assets/chunk-C0phanGV.js +1 -0
- package/dist/client/assets/circle-check-C_Vq3ElD.js +1 -0
- package/dist/client/assets/client-stream-contracts-ys3XhWG4.js +5 -0
- package/dist/client/assets/createLucideIcon-JV8isFFR.js +1 -0
- package/dist/client/assets/data-sources-Cm2bpNvg.js +1 -0
- package/dist/client/assets/discuss-DTjaOugw.js +1 -0
- package/dist/client/assets/dms-CGd6Eogq.js +1 -0
- package/dist/client/assets/inbox-BHlGuOy2.js +1 -0
- package/dist/client/assets/index-CEIG7S6s.js +31 -0
- package/dist/client/assets/index-bpFrQ5yG.css +1 -0
- package/dist/client/assets/likes-cLrcAQem.js +1 -0
- package/dist/client/assets/links-CM9QO1LC.js +1 -0
- package/dist/client/assets/mapbox-BxTlqXt9.js +2 -0
- package/dist/client/assets/mapbox-gl-dgf_hX3a.js +3215 -0
- package/dist/client/assets/mentions-CxKCgzIf.js +1 -0
- package/dist/client/assets/network-map-B5a3whqj.js +2 -0
- package/dist/client/assets/profile-analyze-CRtNEwlb.js +1 -0
- package/dist/client/assets/profile-hydration-client-YEtJsNTv.js +1 -0
- package/dist/client/assets/profiles._handle-C82_HoKX.js +1 -0
- package/dist/client/assets/query-client-fYu2rzRC.js +17 -0
- package/dist/client/assets/rate-limits-ScaEwdVK.js +1 -0
- package/dist/client/assets/react-dom-DHl6Ug7F.js +1 -0
- package/dist/client/assets/react-nBylq1U5.js +1 -0
- package/dist/client/assets/repeat-2-xCwHM9hD.js +1 -0
- package/dist/client/assets/routes-q7ZaW4En.js +1 -0
- package/dist/client/assets/schemas-I9r6F6ya.js +64 -0
- package/dist/client/assets/search-Dq5kYsxA.js +1 -0
- package/dist/client/assets/sparkles-CQVlvHsZ.js +1 -0
- package/dist/client/assets/styles-B8s3tt3r.css +2 -0
- package/dist/client/assets/today-CeG1O7Py.js +1 -0
- package/dist/client/assets/triangle-alert-CBL7s2pf.js +1 -0
- package/dist/client/assets/useTimelineRouteData-1HsqgvUi.js +1 -0
- package/dist/client/assets/users-CHbKlqUr.js +1 -0
- package/dist/server/assets/AvatarChip-zUDAEmjL.js +105 -0
- package/dist/server/assets/FeedState-ntW0Q2GB.js +214 -0
- package/dist/server/assets/ProfileAnalysisStream-BFvhVdhn.js +198 -0
- package/dist/server/assets/ProfilePreview-C6gAor_j.js +752 -0
- package/dist/server/assets/SavedTimelineView-BG1jnBp1.js +64 -0
- package/dist/server/assets/SmartTimestamp-DfwE1NGf.js +45 -0
- package/dist/server/assets/SyncNowButton-BOn_IBXS.js +76 -0
- package/dist/server/assets/TimelineRouteFrame-CU7ilM7U.js +85 -0
- package/dist/server/assets/TweetRichText-DhCVv1-6.js +74 -0
- package/dist/server/assets/_tanstack-start-manifest_v-C-ZRnG_n.js +148 -0
- package/dist/server/assets/account-selection-CTdFGWRk.js +44 -0
- package/dist/server/assets/blocks-C1mgGTB3.js +299 -0
- package/dist/server/assets/blocks-DSgQghqP.js +17 -0
- package/dist/server/assets/bookmarks-BJN8tykY.js +14 -0
- package/dist/server/assets/client-stream-contracts-C2xbWVjm.js +769 -0
- package/dist/server/assets/data-sources-BnA1Q94p.js +180 -0
- package/dist/server/assets/discuss-CJ1dau1j.js +15 -0
- package/dist/server/assets/discuss-QTo08NCN.js +338 -0
- package/dist/server/assets/dms-BuLj4bp8.js +368 -0
- package/dist/server/assets/dms-DAyQrVM2.js +240 -0
- package/dist/server/assets/empty-plugin-adapters-DzrEkdBF.js +5 -0
- package/dist/server/assets/inbox-CkGOaW1q.js +214 -0
- package/dist/server/assets/inbox-DpWd1EzC.js +146 -0
- package/dist/server/assets/likes-DBOAtsJU.js +14 -0
- package/dist/server/assets/links-DAhSjynu.js +240 -0
- package/dist/server/assets/links-DmH5lxHO.js +468 -0
- package/dist/server/assets/mentions-BH2MzKtB.js +26 -0
- package/dist/server/assets/network-map-D3CzRcC4.js +224 -0
- package/dist/server/assets/network-map-D5DoLOwR.js +582 -0
- package/dist/server/assets/profile-analyze-BP65PED0.js +90 -0
- package/dist/server/assets/profile-analyze-C1NoM0tV.js +9 -0
- package/dist/server/assets/profile-hydration-client-GJ4kwJS8.js +133 -0
- package/dist/server/assets/profiles._handle-DjwlN_ac.js +184 -0
- package/dist/server/assets/profiles._handle-DsLNj2Ca.js +12 -0
- package/dist/server/assets/query-client-BdauHBgd.js +923 -0
- package/dist/server/assets/rate-limits-VAr2qzYD.js +262 -0
- package/dist/server/assets/route-search-BUlQ5lGM.js +117 -0
- package/dist/server/assets/router-DqkwSPiM.js +17026 -0
- package/dist/server/assets/routes-A9c9ZhwN.js +26 -0
- package/dist/server/assets/start-FaDOTmto.js +4 -0
- package/dist/server/assets/today-B5hVM57Z.js +17 -0
- package/dist/server/assets/today-fvGiZ7ud.js +303 -0
- package/dist/server/assets/ui-qbmcMSSX.js +137 -0
- package/{src/components/useDebouncedValue.ts → dist/server/assets/useDebouncedValue-DOnA6Xcy.js} +4 -4
- package/dist/server/assets/useTimelineRouteData-27cxynxa.js +1101 -0
- package/dist/server/server.js +5520 -0
- package/package.json +27 -34
- package/playwright.config.ts +0 -35
- package/scripts/browser-perf.mjs +0 -427
- package/scripts/build-docs-site.mjs +0 -967
- package/scripts/docs-site-assets.mjs +0 -311
- package/scripts/run-vitest.mjs +0 -21
- package/scripts/sanitize-node-options.mjs +0 -23
- package/scripts/start-test-server.mjs +0 -42
- package/src/cli-moderation.ts +0 -210
- package/src/cli.ts +0 -2336
- package/src/components/AccountSwitcher.tsx +0 -186
- package/src/components/AppNav.tsx +0 -118
- package/src/components/AvatarChip.tsx +0 -58
- package/src/components/BrandMark.tsx +0 -67
- package/src/components/ConversationThread.tsx +0 -131
- package/src/components/DmWorkspace.tsx +0 -286
- package/src/components/EmbeddedTweetCard.tsx +0 -55
- package/src/components/FeedState.tsx +0 -147
- package/src/components/FloatingPreview.tsx +0 -382
- package/src/components/InboxCard.tsx +0 -152
- package/src/components/LinkPreviewCard.tsx +0 -292
- package/src/components/MarkdownViewer.tsx +0 -777
- package/src/components/ProfileAnalysisStream.tsx +0 -428
- package/src/components/ProfilePreview.tsx +0 -129
- package/src/components/SavedTimelineView.tsx +0 -155
- package/src/components/SmartTimestamp.tsx +0 -72
- package/src/components/SyncNowButton.tsx +0 -140
- package/src/components/ThemeSlider.tsx +0 -80
- package/src/components/TimelineCard.tsx +0 -533
- package/src/components/TimelineRouteFrame.tsx +0 -186
- package/src/components/TweetArticleCard.tsx +0 -66
- package/src/components/TweetMediaGrid.tsx +0 -185
- package/src/components/TweetRichText.tsx +0 -159
- package/src/components/account-selection.ts +0 -64
- package/src/components/useTimelineRouteData.ts +0 -323
- package/src/lib/account-sync-job.ts +0 -666
- package/src/lib/actions-transport.ts +0 -300
- package/src/lib/api-client.ts +0 -419
- package/src/lib/archive-finder.ts +0 -185
- package/src/lib/archive-import.ts +0 -2764
- package/src/lib/authored-live.ts +0 -1072
- package/src/lib/avatar-cache.ts +0 -349
- package/src/lib/backup.ts +0 -2741
- package/src/lib/bird-actions.ts +0 -294
- package/src/lib/bird-command.ts +0 -130
- package/src/lib/bird.ts +0 -1140
- package/src/lib/blocklist.ts +0 -136
- package/src/lib/blocks-write.ts +0 -167
- package/src/lib/blocks.ts +0 -389
- package/src/lib/bookmark-sync-job.ts +0 -536
- package/src/lib/client-cache.ts +0 -109
- package/src/lib/config.ts +0 -224
- package/src/lib/conversation-surface.ts +0 -205
- package/src/lib/data-sources.ts +0 -219
- package/src/lib/db.ts +0 -1135
- package/src/lib/dms-live.ts +0 -933
- package/src/lib/effect-runtime.ts +0 -45
- package/src/lib/follow-graph.ts +0 -1097
- package/src/lib/geocoding.ts +0 -296
- package/src/lib/http-effect.ts +0 -222
- package/src/lib/identity-search-index.ts +0 -369
- package/src/lib/inbox.ts +0 -241
- package/src/lib/link-index.ts +0 -641
- package/src/lib/link-insights.ts +0 -860
- package/src/lib/link-preview-metadata.ts +0 -754
- package/src/lib/location.ts +0 -137
- package/src/lib/media-fetch.ts +0 -860
- package/src/lib/media-includes.ts +0 -165
- package/src/lib/mention-threads-live.ts +0 -917
- package/src/lib/mentions-export.ts +0 -147
- package/src/lib/mentions-live.ts +0 -1238
- package/src/lib/moderation-target.ts +0 -216
- package/src/lib/moderation-write.ts +0 -131
- package/src/lib/mutes-write.ts +0 -167
- package/src/lib/mutes.ts +0 -84
- package/src/lib/ndjson-stream.ts +0 -106
- package/src/lib/network-map.ts +0 -382
- package/src/lib/openai.ts +0 -117
- package/src/lib/period-digest.ts +0 -1552
- package/src/lib/present.ts +0 -118
- package/src/lib/profile-affiliation-hydration.ts +0 -228
- package/src/lib/profile-affiliations.ts +0 -262
- package/src/lib/profile-analysis.ts +0 -1272
- package/src/lib/profile-bio-entities.ts +0 -318
- package/src/lib/profile-history.ts +0 -164
- package/src/lib/profile-hydration.ts +0 -180
- package/src/lib/profile-replies.ts +0 -77
- package/src/lib/profile-resolver.ts +0 -650
- package/src/lib/queries.ts +0 -2381
- package/src/lib/research.ts +0 -652
- package/src/lib/search-discussion.ts +0 -1016
- package/src/lib/seed.ts +0 -613
- package/src/lib/sqlite.ts +0 -147
- package/src/lib/sync-cache.ts +0 -65
- package/src/lib/theme-transition.ts +0 -113
- package/src/lib/theme.tsx +0 -165
- package/src/lib/timeline-collections-live.ts +0 -581
- package/src/lib/timeline-live.ts +0 -452
- package/src/lib/tweet-account-edges.ts +0 -48
- package/src/lib/tweet-lookup.ts +0 -46
- package/src/lib/tweet-render.ts +0 -430
- package/src/lib/tweet-search-live.ts +0 -566
- package/src/lib/types.ts +0 -723
- package/src/lib/ui.ts +0 -529
- package/src/lib/url-expansion-store.ts +0 -110
- package/src/lib/url-expansion.ts +0 -343
- package/src/lib/url-safety.ts +0 -220
- package/src/lib/web-sync.ts +0 -516
- package/src/lib/whois.ts +0 -1079
- package/src/lib/x-profile.ts +0 -365
- package/src/lib/x-web.ts +0 -199
- package/src/lib/xurl-rate-limits.ts +0 -267
- package/src/lib/xurl.ts +0 -1677
- package/src/routeTree.gen.ts +0 -723
- package/src/router.tsx +0 -20
- package/src/routes/__root.tsx +0 -79
- package/src/routes/api/action.tsx +0 -147
- package/src/routes/api/avatar.tsx +0 -50
- package/src/routes/api/blocks.tsx +0 -35
- package/src/routes/api/conversation.tsx +0 -45
- package/src/routes/api/data-sources.tsx +0 -24
- package/src/routes/api/inbox.tsx +0 -43
- package/src/routes/api/link-insights.tsx +0 -85
- package/src/routes/api/link-preview.tsx +0 -47
- package/src/routes/api/network-map.tsx +0 -55
- package/src/routes/api/period-digest.tsx +0 -101
- package/src/routes/api/profile-analysis.tsx +0 -97
- package/src/routes/api/profile-hydrate.tsx +0 -54
- package/src/routes/api/query.tsx +0 -115
- package/src/routes/api/search-discussion.tsx +0 -113
- package/src/routes/api/status.tsx +0 -28
- package/src/routes/api/sync.tsx +0 -105
- package/src/routes/api/xurl-rate-limits.tsx +0 -24
- package/src/routes/blocks.tsx +0 -377
- package/src/routes/bookmarks.tsx +0 -18
- package/src/routes/data-sources.tsx +0 -257
- package/src/routes/discuss.tsx +0 -419
- package/src/routes/dms.tsx +0 -432
- package/src/routes/inbox.tsx +0 -226
- package/src/routes/index.tsx +0 -32
- package/src/routes/likes.tsx +0 -18
- package/src/routes/links.tsx +0 -994
- package/src/routes/mentions.tsx +0 -32
- package/src/routes/network-map.tsx +0 -1035
- package/src/routes/profile-analyze.tsx +0 -112
- package/src/routes/profiles.$handle.tsx +0 -228
- package/src/routes/rate-limits.tsx +0 -309
- package/src/routes/today.tsx +0 -511
- package/src/styles.css +0 -257
- package/tsconfig.json +0 -29
- package/vite.config.ts +0 -29
- /package/{public → dist/client}/birdclaw-mark.png +0 -0
- /package/{public → dist/client}/favicon.ico +0 -0
- /package/{public → dist/client}/logo192.png +0 -0
- /package/{public → dist/client}/logo512.png +0 -0
- /package/{public → dist/client}/manifest.json +0 -0
- /package/{public → dist/client}/robots.txt +0 -0
package/src/lib/web-sync.ts
DELETED
|
@@ -1,516 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { Effect } from "effect";
|
|
3
|
-
import { maybeAutoSyncBackupEffect } from "./backup";
|
|
4
|
-
import { getBirdclawPaths } from "./config";
|
|
5
|
-
import { syncDirectMessagesViaCachedBirdEffect } from "./dms-live";
|
|
6
|
-
import { runEffectBackground, runEffectPromise } from "./effect-runtime";
|
|
7
|
-
import { syncMentionThreadsEffect } from "./mention-threads-live";
|
|
8
|
-
import { syncMentionsEffect } from "./mentions-live";
|
|
9
|
-
import NativeSqliteDatabase from "./sqlite";
|
|
10
|
-
import { syncTimelineCollectionEffect } from "./timeline-collections-live";
|
|
11
|
-
import { syncHomeTimelineEffect } from "./timeline-live";
|
|
12
|
-
|
|
13
|
-
export type WebSyncKind =
|
|
14
|
-
| "timeline"
|
|
15
|
-
| "mentions"
|
|
16
|
-
| "likes"
|
|
17
|
-
| "bookmarks"
|
|
18
|
-
| "dms";
|
|
19
|
-
|
|
20
|
-
export interface WebSyncStep {
|
|
21
|
-
kind: WebSyncKind | "mention-threads";
|
|
22
|
-
label: string;
|
|
23
|
-
count: number;
|
|
24
|
-
source?: string;
|
|
25
|
-
partial?: boolean;
|
|
26
|
-
warnings?: string[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface WebSyncResponse {
|
|
30
|
-
ok: boolean;
|
|
31
|
-
kind: WebSyncKind;
|
|
32
|
-
accountId?: string;
|
|
33
|
-
startedAt: string;
|
|
34
|
-
finishedAt?: string;
|
|
35
|
-
summary: string;
|
|
36
|
-
steps: WebSyncStep[];
|
|
37
|
-
inProgress?: boolean;
|
|
38
|
-
backup?: Effect.Effect.Success<ReturnType<typeof maybeAutoSyncBackupEffect>>;
|
|
39
|
-
error?: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export type WebSyncJobStatus = "running" | "succeeded" | "failed";
|
|
43
|
-
|
|
44
|
-
export interface WebSyncJobSnapshot {
|
|
45
|
-
id: string;
|
|
46
|
-
kind: WebSyncKind;
|
|
47
|
-
accountId?: string;
|
|
48
|
-
status: WebSyncJobStatus;
|
|
49
|
-
startedAt: string;
|
|
50
|
-
finishedAt?: string;
|
|
51
|
-
summary: string;
|
|
52
|
-
inProgress: boolean;
|
|
53
|
-
result?: WebSyncResponse;
|
|
54
|
-
error?: string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export type WebSyncDmInbox = "all" | "accepted" | "requests";
|
|
58
|
-
|
|
59
|
-
export interface WebSyncOptions {
|
|
60
|
-
inbox?: WebSyncDmInbox;
|
|
61
|
-
limit?: number;
|
|
62
|
-
maxPages?: number;
|
|
63
|
-
allPages?: boolean;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
interface WebSyncPlan {
|
|
67
|
-
label: string;
|
|
68
|
-
accountAware: boolean;
|
|
69
|
-
run: (
|
|
70
|
-
accountId: string | undefined,
|
|
71
|
-
options: WebSyncOptions,
|
|
72
|
-
) => Effect.Effect<WebSyncStep[], unknown>;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const runningSyncs = new Map<string, WebSyncJobSnapshot>();
|
|
76
|
-
const webSyncJobs = new Map<string, WebSyncJobSnapshot>();
|
|
77
|
-
const webSyncJobKeys = new Map<string, string>();
|
|
78
|
-
const completedJobCleanupTimers = new Map<
|
|
79
|
-
string,
|
|
80
|
-
ReturnType<typeof setTimeout>
|
|
81
|
-
>();
|
|
82
|
-
const COMPLETED_JOB_TTL_MS = 5 * 60 * 1000;
|
|
83
|
-
|
|
84
|
-
function assertRecord(
|
|
85
|
-
value: unknown,
|
|
86
|
-
): asserts value is Record<string, unknown> {
|
|
87
|
-
if (!value || typeof value !== "object") {
|
|
88
|
-
throw new Error("Expected sync result object");
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function readNumber(value: unknown, key: string): number {
|
|
93
|
-
assertRecord(value);
|
|
94
|
-
const raw = value[key];
|
|
95
|
-
return typeof raw === "number" && Number.isFinite(raw) ? raw : 0;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function readString(value: unknown, key: string) {
|
|
99
|
-
assertRecord(value);
|
|
100
|
-
const raw = value[key];
|
|
101
|
-
return typeof raw === "string" ? raw : undefined;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function readBoolean(value: unknown, key: string) {
|
|
105
|
-
assertRecord(value);
|
|
106
|
-
const raw = value[key];
|
|
107
|
-
return typeof raw === "boolean" ? raw : undefined;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function messageFromError(error: unknown) {
|
|
111
|
-
return error instanceof Error ? error.message : String(error);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function parseWebSyncKind(value: unknown): WebSyncKind | null {
|
|
115
|
-
return value === "timeline" ||
|
|
116
|
-
value === "mentions" ||
|
|
117
|
-
value === "likes" ||
|
|
118
|
-
value === "bookmarks" ||
|
|
119
|
-
value === "dms"
|
|
120
|
-
? value
|
|
121
|
-
: null;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function summarizeSteps(steps: WebSyncStep[]) {
|
|
125
|
-
const total = steps.reduce((sum, step) => sum + step.count, 0);
|
|
126
|
-
const partial = steps.some((step) => step.partial);
|
|
127
|
-
const suffix = partial ? " (partial)" : "";
|
|
128
|
-
return `Synced ${String(total)} items${suffix}`;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const WEB_SYNC_PLANS: Record<WebSyncKind, WebSyncPlan> = {
|
|
132
|
-
timeline: {
|
|
133
|
-
label: "Home timeline",
|
|
134
|
-
accountAware: true,
|
|
135
|
-
run: (account) =>
|
|
136
|
-
Effect.gen(function* () {
|
|
137
|
-
const result = yield* syncHomeTimelineEffect({
|
|
138
|
-
account,
|
|
139
|
-
mode:
|
|
140
|
-
!account || account === resolveDefaultSyncAccountId()
|
|
141
|
-
? "auto"
|
|
142
|
-
: "xurl",
|
|
143
|
-
limit: 100,
|
|
144
|
-
maxPages: 3,
|
|
145
|
-
following: true,
|
|
146
|
-
refresh: true,
|
|
147
|
-
});
|
|
148
|
-
return [
|
|
149
|
-
{
|
|
150
|
-
kind: "timeline",
|
|
151
|
-
label: "Home timeline",
|
|
152
|
-
count: readNumber(result, "count"),
|
|
153
|
-
source: readString(result, "source"),
|
|
154
|
-
},
|
|
155
|
-
];
|
|
156
|
-
}),
|
|
157
|
-
},
|
|
158
|
-
mentions: {
|
|
159
|
-
label: "Mentions",
|
|
160
|
-
accountAware: true,
|
|
161
|
-
run: (account) =>
|
|
162
|
-
Effect.gen(function* () {
|
|
163
|
-
const mentions = yield* syncMentionsEffect({
|
|
164
|
-
account,
|
|
165
|
-
mode: "auto",
|
|
166
|
-
limit: 100,
|
|
167
|
-
maxPages: 3,
|
|
168
|
-
refresh: true,
|
|
169
|
-
});
|
|
170
|
-
const steps: WebSyncStep[] = [
|
|
171
|
-
{
|
|
172
|
-
kind: "mentions",
|
|
173
|
-
label: "Mentions",
|
|
174
|
-
count: readNumber(mentions, "count"),
|
|
175
|
-
source: readString(mentions, "source"),
|
|
176
|
-
partial: readBoolean(mentions, "partial"),
|
|
177
|
-
},
|
|
178
|
-
];
|
|
179
|
-
|
|
180
|
-
const threads = yield* syncMentionThreadsEffect({
|
|
181
|
-
account,
|
|
182
|
-
mode: "xurl",
|
|
183
|
-
limit: 30,
|
|
184
|
-
delayMs: 1500,
|
|
185
|
-
timeoutMs: 15000,
|
|
186
|
-
});
|
|
187
|
-
steps.push({
|
|
188
|
-
kind: "mention-threads",
|
|
189
|
-
label: "Mention threads",
|
|
190
|
-
count: readNumber(threads, "mergedTweets"),
|
|
191
|
-
source: readString(threads, "source"),
|
|
192
|
-
partial: readBoolean(threads, "partial"),
|
|
193
|
-
warnings:
|
|
194
|
-
Array.isArray(threads.warnings) && threads.warnings.length > 0
|
|
195
|
-
? threads.warnings.map(String)
|
|
196
|
-
: undefined,
|
|
197
|
-
});
|
|
198
|
-
return steps;
|
|
199
|
-
}),
|
|
200
|
-
},
|
|
201
|
-
likes: {
|
|
202
|
-
label: "Likes",
|
|
203
|
-
accountAware: true,
|
|
204
|
-
run: (account) => syncSavedCollection("likes", account),
|
|
205
|
-
},
|
|
206
|
-
bookmarks: {
|
|
207
|
-
label: "Bookmarks",
|
|
208
|
-
accountAware: true,
|
|
209
|
-
run: (account) => syncSavedCollection("bookmarks", account),
|
|
210
|
-
},
|
|
211
|
-
dms: {
|
|
212
|
-
label: "Direct messages",
|
|
213
|
-
accountAware: false,
|
|
214
|
-
run: (account, options) =>
|
|
215
|
-
Effect.gen(function* () {
|
|
216
|
-
const inbox = options.inbox ?? "all";
|
|
217
|
-
const result = yield* syncDirectMessagesViaCachedBirdEffect({
|
|
218
|
-
account,
|
|
219
|
-
inbox,
|
|
220
|
-
limit: options.limit ?? (inbox === "requests" ? 200 : 50),
|
|
221
|
-
...(options.maxPages !== undefined
|
|
222
|
-
? { maxPages: options.maxPages }
|
|
223
|
-
: {}),
|
|
224
|
-
...(options.allPages !== undefined
|
|
225
|
-
? { allPages: options.allPages }
|
|
226
|
-
: {}),
|
|
227
|
-
pageDelayMs: inbox === "requests" ? 750 : 0,
|
|
228
|
-
refresh: true,
|
|
229
|
-
});
|
|
230
|
-
return [
|
|
231
|
-
{
|
|
232
|
-
kind: "dms",
|
|
233
|
-
label: "Direct messages",
|
|
234
|
-
count: readNumber(result, "messages"),
|
|
235
|
-
source: readString(result, "source"),
|
|
236
|
-
},
|
|
237
|
-
];
|
|
238
|
-
}),
|
|
239
|
-
},
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
function syncSavedCollection(
|
|
243
|
-
kind: "likes" | "bookmarks",
|
|
244
|
-
account: string | undefined,
|
|
245
|
-
): Effect.Effect<WebSyncStep[], unknown> {
|
|
246
|
-
return Effect.gen(function* () {
|
|
247
|
-
const isNonDefaultAccount =
|
|
248
|
-
account !== undefined && account !== resolveDefaultSyncAccountId();
|
|
249
|
-
const result = yield* syncTimelineCollectionEffect({
|
|
250
|
-
kind,
|
|
251
|
-
account,
|
|
252
|
-
mode: isNonDefaultAccount ? "xurl" : "auto",
|
|
253
|
-
limit: 100,
|
|
254
|
-
maxPages: 5,
|
|
255
|
-
refresh: true,
|
|
256
|
-
earlyStop: true,
|
|
257
|
-
});
|
|
258
|
-
return [
|
|
259
|
-
{
|
|
260
|
-
kind,
|
|
261
|
-
label: kind === "likes" ? "Likes" : "Bookmarks",
|
|
262
|
-
count: readNumber(result, "count"),
|
|
263
|
-
source: readString(result, "source"),
|
|
264
|
-
},
|
|
265
|
-
];
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export function performWebSyncEffect(
|
|
270
|
-
kind: WebSyncKind,
|
|
271
|
-
accountId?: string,
|
|
272
|
-
options: WebSyncOptions = {},
|
|
273
|
-
) {
|
|
274
|
-
return Effect.gen(function* () {
|
|
275
|
-
const startedAt = new Date().toISOString();
|
|
276
|
-
const steps = yield* WEB_SYNC_PLANS[kind].run(accountId, options);
|
|
277
|
-
|
|
278
|
-
const backup = yield* maybeAutoSyncBackupEffect();
|
|
279
|
-
const finishedAt = new Date().toISOString();
|
|
280
|
-
return {
|
|
281
|
-
ok: true,
|
|
282
|
-
kind,
|
|
283
|
-
...(accountId ? { accountId } : {}),
|
|
284
|
-
startedAt,
|
|
285
|
-
finishedAt,
|
|
286
|
-
summary: summarizeSteps(steps),
|
|
287
|
-
steps,
|
|
288
|
-
backup,
|
|
289
|
-
} satisfies WebSyncResponse;
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
function createWebSyncJobId(kind: WebSyncKind) {
|
|
294
|
-
return `sync_${kind}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
function resolveDefaultSyncAccountId() {
|
|
298
|
-
const dbPath = getBirdclawPaths().dbPath;
|
|
299
|
-
if (!existsSync(dbPath)) {
|
|
300
|
-
return "acct_primary";
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
let db: NativeSqliteDatabase | undefined;
|
|
304
|
-
try {
|
|
305
|
-
db = new NativeSqliteDatabase(dbPath, { readonly: true });
|
|
306
|
-
const row = db
|
|
307
|
-
.prepare(
|
|
308
|
-
`
|
|
309
|
-
select id
|
|
310
|
-
from accounts
|
|
311
|
-
order by is_default desc, created_at asc
|
|
312
|
-
limit 1
|
|
313
|
-
`,
|
|
314
|
-
)
|
|
315
|
-
.get() as { id: string } | undefined;
|
|
316
|
-
return row?.id ?? "acct_primary";
|
|
317
|
-
} catch {
|
|
318
|
-
return "acct_primary";
|
|
319
|
-
} finally {
|
|
320
|
-
db?.close();
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
function serializeSyncOptions(kind: WebSyncKind, options: WebSyncOptions) {
|
|
325
|
-
if (kind !== "dms") return "";
|
|
326
|
-
const parts = [
|
|
327
|
-
options.inbox ?? "all",
|
|
328
|
-
options.limit ?? "",
|
|
329
|
-
options.maxPages ?? "",
|
|
330
|
-
options.allPages === undefined ? "" : String(options.allPages),
|
|
331
|
-
];
|
|
332
|
-
return parts.join(":");
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function getRunningSyncKey(
|
|
336
|
-
kind: WebSyncKind,
|
|
337
|
-
accountId: string | undefined,
|
|
338
|
-
options: WebSyncOptions = {},
|
|
339
|
-
) {
|
|
340
|
-
if (!WEB_SYNC_PLANS[kind].accountAware) {
|
|
341
|
-
const optionKey = serializeSyncOptions(kind, options);
|
|
342
|
-
return optionKey ? `${kind}:${optionKey}` : kind;
|
|
343
|
-
}
|
|
344
|
-
return `${kind}:${accountId ?? resolveDefaultSyncAccountId()}`;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function getEffectiveAccountId(
|
|
348
|
-
kind: WebSyncKind,
|
|
349
|
-
accountId: string | undefined,
|
|
350
|
-
) {
|
|
351
|
-
return WEB_SYNC_PLANS[kind].accountAware ? accountId : undefined;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
function setJobSnapshot(snapshot: WebSyncJobSnapshot) {
|
|
355
|
-
webSyncJobs.set(snapshot.id, snapshot);
|
|
356
|
-
const syncKey =
|
|
357
|
-
webSyncJobKeys.get(snapshot.id) ??
|
|
358
|
-
getRunningSyncKey(snapshot.kind, snapshot.accountId);
|
|
359
|
-
const cleanupTimer = completedJobCleanupTimers.get(snapshot.id);
|
|
360
|
-
if (cleanupTimer) {
|
|
361
|
-
clearTimeout(cleanupTimer);
|
|
362
|
-
completedJobCleanupTimers.delete(snapshot.id);
|
|
363
|
-
}
|
|
364
|
-
if (snapshot.inProgress) {
|
|
365
|
-
runningSyncs.set(syncKey, snapshot);
|
|
366
|
-
} else if (runningSyncs.get(syncKey)?.id === snapshot.id) {
|
|
367
|
-
runningSyncs.delete(syncKey);
|
|
368
|
-
const timer = setTimeout(() => {
|
|
369
|
-
webSyncJobs.delete(snapshot.id);
|
|
370
|
-
webSyncJobKeys.delete(snapshot.id);
|
|
371
|
-
completedJobCleanupTimers.delete(snapshot.id);
|
|
372
|
-
}, COMPLETED_JOB_TTL_MS);
|
|
373
|
-
timer.unref?.();
|
|
374
|
-
completedJobCleanupTimers.set(snapshot.id, timer);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
function toFailedResponse(
|
|
379
|
-
kind: WebSyncKind,
|
|
380
|
-
startedAt: string,
|
|
381
|
-
error: unknown,
|
|
382
|
-
accountId?: string,
|
|
383
|
-
): WebSyncResponse {
|
|
384
|
-
const finishedAt = new Date().toISOString();
|
|
385
|
-
const message = messageFromError(error);
|
|
386
|
-
return {
|
|
387
|
-
ok: false,
|
|
388
|
-
kind,
|
|
389
|
-
...(accountId ? { accountId } : {}),
|
|
390
|
-
startedAt,
|
|
391
|
-
finishedAt,
|
|
392
|
-
summary: message,
|
|
393
|
-
steps: [],
|
|
394
|
-
error: message,
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
export function startWebSync(
|
|
399
|
-
kind: WebSyncKind,
|
|
400
|
-
accountId?: string,
|
|
401
|
-
options: WebSyncOptions = {},
|
|
402
|
-
): WebSyncJobSnapshot {
|
|
403
|
-
const effectiveAccountId = getEffectiveAccountId(kind, accountId);
|
|
404
|
-
const syncKey = getRunningSyncKey(kind, effectiveAccountId, options);
|
|
405
|
-
const current = runningSyncs.get(syncKey);
|
|
406
|
-
if (current) {
|
|
407
|
-
return current;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
const startedAt = new Date().toISOString();
|
|
411
|
-
const job: WebSyncJobSnapshot = {
|
|
412
|
-
id: createWebSyncJobId(kind),
|
|
413
|
-
kind,
|
|
414
|
-
...(effectiveAccountId ? { accountId: effectiveAccountId } : {}),
|
|
415
|
-
status: "running",
|
|
416
|
-
startedAt,
|
|
417
|
-
summary: `Syncing ${WEB_SYNC_PLANS[kind].label}`,
|
|
418
|
-
inProgress: true,
|
|
419
|
-
};
|
|
420
|
-
webSyncJobKeys.set(job.id, syncKey);
|
|
421
|
-
setJobSnapshot(job);
|
|
422
|
-
|
|
423
|
-
runEffectBackground(performWebSyncEffect(kind, effectiveAccountId, options), {
|
|
424
|
-
onSuccess: (result) => {
|
|
425
|
-
setJobSnapshot({
|
|
426
|
-
...job,
|
|
427
|
-
status: "succeeded",
|
|
428
|
-
finishedAt: result.finishedAt,
|
|
429
|
-
summary: result.summary,
|
|
430
|
-
inProgress: false,
|
|
431
|
-
result,
|
|
432
|
-
});
|
|
433
|
-
},
|
|
434
|
-
onFailure: (error) => {
|
|
435
|
-
const result = toFailedResponse(
|
|
436
|
-
kind,
|
|
437
|
-
startedAt,
|
|
438
|
-
error,
|
|
439
|
-
effectiveAccountId,
|
|
440
|
-
);
|
|
441
|
-
setJobSnapshot({
|
|
442
|
-
...job,
|
|
443
|
-
status: "failed",
|
|
444
|
-
finishedAt: result.finishedAt,
|
|
445
|
-
summary: result.summary,
|
|
446
|
-
inProgress: false,
|
|
447
|
-
result,
|
|
448
|
-
error: result.error,
|
|
449
|
-
});
|
|
450
|
-
},
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
return job;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
export function getWebSyncJob(id: string): WebSyncJobSnapshot | null {
|
|
457
|
-
return webSyncJobs.get(id) ?? null;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
export function runWebSyncEffect(
|
|
461
|
-
kind: WebSyncKind,
|
|
462
|
-
accountId?: string,
|
|
463
|
-
options: WebSyncOptions = {},
|
|
464
|
-
): Effect.Effect<WebSyncResponse, Error> {
|
|
465
|
-
return Effect.gen(function* () {
|
|
466
|
-
const effectiveAccountId = getEffectiveAccountId(kind, accountId);
|
|
467
|
-
const current = runningSyncs.get(
|
|
468
|
-
getRunningSyncKey(kind, effectiveAccountId, options),
|
|
469
|
-
);
|
|
470
|
-
const startedAt = new Date().toISOString();
|
|
471
|
-
if (current) {
|
|
472
|
-
return {
|
|
473
|
-
ok: false,
|
|
474
|
-
kind,
|
|
475
|
-
...(effectiveAccountId ? { accountId: effectiveAccountId } : {}),
|
|
476
|
-
startedAt,
|
|
477
|
-
summary: "Sync already running",
|
|
478
|
-
steps: [],
|
|
479
|
-
inProgress: true,
|
|
480
|
-
} satisfies WebSyncResponse;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
const job = startWebSync(kind, effectiveAccountId, options);
|
|
484
|
-
while (job.inProgress) {
|
|
485
|
-
yield* Effect.sleep(25);
|
|
486
|
-
const latest = getWebSyncJob(job.id);
|
|
487
|
-
if (!latest?.inProgress) {
|
|
488
|
-
if (!latest?.result)
|
|
489
|
-
return yield* Effect.fail(new Error("Sync job disappeared"));
|
|
490
|
-
return latest.result;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
if (!job.result)
|
|
495
|
-
return yield* Effect.fail(new Error("Sync job did not finish"));
|
|
496
|
-
return job.result;
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
export function runWebSync(
|
|
501
|
-
kind: WebSyncKind,
|
|
502
|
-
accountId?: string,
|
|
503
|
-
options: WebSyncOptions = {},
|
|
504
|
-
): Promise<WebSyncResponse> {
|
|
505
|
-
return runEffectPromise(runWebSyncEffect(kind, accountId, options));
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
export function clearWebSyncLocksForTests() {
|
|
509
|
-
runningSyncs.clear();
|
|
510
|
-
webSyncJobs.clear();
|
|
511
|
-
webSyncJobKeys.clear();
|
|
512
|
-
for (const timer of completedJobCleanupTimers.values()) {
|
|
513
|
-
clearTimeout(timer);
|
|
514
|
-
}
|
|
515
|
-
completedJobCleanupTimers.clear();
|
|
516
|
-
}
|