birdclaw 0.8.3 → 0.8.5
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 +24 -0
- package/README.md +10 -8
- package/bin/birdclaw.mjs +4 -66
- package/dist/cli/birdclaw.js +28164 -0
- package/dist/client/assets/AvatarChip-DLoqM5xD.js +1 -0
- package/dist/client/assets/ProfilePreview-DQX6_xc3.js +1 -0
- package/dist/client/assets/SavedTimelineView-BhSiVyR1.js +1 -0
- package/dist/client/assets/SmartTimestamp-BR0-9se2.js +1 -0
- package/dist/client/assets/TimelineRouteFrame-9NDLnXzH.js +1 -0
- package/dist/client/assets/blocks-CFp_njvG.js +1 -0
- package/dist/client/assets/bookmarks-LbYOsoKf.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-sR4xMQxY.js +5 -0
- package/dist/client/assets/createLucideIcon-JV8isFFR.js +1 -0
- package/dist/client/assets/data-sources-euTr6T_L.js +1 -0
- package/dist/client/assets/discuss-BWKu_p7B.js +1 -0
- package/dist/client/assets/dms-SLXMtC4v.js +1 -0
- package/dist/client/assets/inbox-BybSI5Vf.js +1 -0
- package/dist/client/assets/index-DZVisyna.js +31 -0
- package/dist/client/assets/index-bpFrQ5yG.css +1 -0
- package/dist/client/assets/likes-dyh9p8y_.js +1 -0
- package/dist/client/assets/links-CIwqK_dX.js +1 -0
- package/dist/client/assets/mapbox-B4zqX7r0.js +2 -0
- package/dist/client/assets/mapbox-gl-DYNcLcll.js +3215 -0
- package/dist/client/assets/mentions-BoVVAIT7.js +1 -0
- package/dist/client/assets/network-map-zRysIY_b.js +2 -0
- package/dist/client/assets/profile-analyze-C_yDeX6-.js +1 -0
- package/dist/client/assets/profile-hydration-client-YEtJsNTv.js +1 -0
- package/dist/client/assets/profiles._handle-DdIVPqU-.js +1 -0
- package/dist/client/assets/query-client-fYu2rzRC.js +17 -0
- package/dist/client/assets/rate-limits-BWPmPOSh.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-CiLuYpZr.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-BoO64YoY.js +1 -0
- package/dist/client/assets/triangle-alert-CBL7s2pf.js +1 -0
- package/dist/client/assets/useTimelineRouteData-BaO3Rna1.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-L7bs6IHH.js +198 -0
- package/dist/server/assets/ProfilePreview-Cg-AOHBE.js +751 -0
- package/dist/server/assets/SavedTimelineView-BtCq1dHk.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-CjMIh63G.js +85 -0
- package/dist/server/assets/TweetRichText-DDywESRF.js +74 -0
- package/dist/server/assets/_tanstack-start-manifest_v-aLWUdbAc.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-D_YkmCK3.js +14 -0
- package/dist/server/assets/client-stream-contracts-Bq6kMmhh.js +769 -0
- package/dist/server/assets/data-sources-BnA1Q94p.js +180 -0
- package/dist/server/assets/discuss-C1QMBBSk.js +338 -0
- package/dist/server/assets/discuss-DAq6ehL9.js +15 -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-BMm2JWYI.js +14 -0
- package/dist/server/assets/links-Da4tjWtI.js +468 -0
- package/dist/server/assets/links-dqXb35YM.js +240 -0
- package/dist/server/assets/mentions-CEyEcOFw.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-CGCj4VFd.js +90 -0
- package/dist/server/assets/profile-analyze-DH1TSBkT.js +9 -0
- package/dist/server/assets/profile-hydration-client-GJ4kwJS8.js +133 -0
- package/dist/server/assets/profiles._handle-B5V-huoo.js +12 -0
- package/dist/server/assets/profiles._handle-CJ6rgzt8.js +184 -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-C4cz9ypd.js +17026 -0
- package/dist/server/assets/routes-B9aikOdB.js +26 -0
- package/dist/server/assets/start-FaDOTmto.js +4 -0
- package/dist/server/assets/today-B_TA16QG.js +303 -0
- package/dist/server/assets/today-JkxZXdBt.js +17 -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-BLXvMGb2.js +1101 -0
- package/dist/server/server.js +5520 -0
- package/package.json +26 -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/command-context.ts +0 -17
- package/src/cli/register-analysis.ts +0 -500
- package/src/cli/register-compose.ts +0 -40
- package/src/cli/register-graph.ts +0 -132
- package/src/cli/register-inbox.ts +0 -41
- package/src/cli/register-storage.ts +0 -106
- package/src/cli-moderation.ts +0 -210
- package/src/cli.ts +0 -1616
- package/src/components/AccountSwitcher.tsx +0 -178
- package/src/components/AppNav.tsx +0 -118
- package/src/components/AvatarChip.tsx +0 -58
- package/src/components/AvatarPreload.ts +0 -149
- 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/MarkdownCitations.tsx +0 -680
- package/src/components/MarkdownViewer.tsx +0 -111
- package/src/components/ProfileAnalysisClient.ts +0 -191
- package/src/components/ProfileAnalysisStream.tsx +0 -259
- package/src/components/ProfilePreview.tsx +0 -131
- 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/links-controller.ts +0 -162
- package/src/components/links-model.ts +0 -198
- package/src/components/network-map-controller.ts +0 -84
- package/src/components/network-map-model.ts +0 -255
- package/src/components/useTimelineRouteData.ts +0 -193
- package/src/lib/account-sync-job.ts +0 -666
- package/src/lib/actions-transport.ts +0 -300
- package/src/lib/analysis-runtime.ts +0 -238
- package/src/lib/api-client.ts +0 -220
- package/src/lib/api-contracts.ts +0 -328
- package/src/lib/archive-finder.ts +0 -185
- package/src/lib/archive-import-plan.ts +0 -102
- package/src/lib/archive-import.ts +0 -2695
- package/src/lib/authored-live.ts +0 -1027
- package/src/lib/avatar-cache.ts +0 -349
- package/src/lib/backup.ts +0 -2652
- 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 -171
- package/src/lib/blocks.ts +0 -387
- package/src/lib/bookmark-sync-job.ts +0 -536
- 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/database-metrics.ts +0 -88
- package/src/lib/database-migrations.ts +0 -34
- package/src/lib/database-schema.ts +0 -312
- package/src/lib/database-writer.ts +0 -69
- package/src/lib/db.ts +0 -889
- package/src/lib/dm-read-model.ts +0 -533
- package/src/lib/dms-live.ts +0 -870
- package/src/lib/effect-runtime.ts +0 -45
- package/src/lib/follow-graph.ts +0 -1087
- 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/import-repository.ts +0 -138
- package/src/lib/inbox.ts +0 -242
- 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/live-sync-engine.ts +0 -209
- package/src/lib/live-transport-gateway.ts +0 -128
- 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 -830
- package/src/lib/mentions-export.ts +0 -147
- package/src/lib/mentions-live.ts +0 -1114
- package/src/lib/moderation-target.ts +0 -227
- package/src/lib/moderation-write.ts +0 -131
- package/src/lib/mutes-write.ts +0 -171
- 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-response-runtime.ts +0 -251
- package/src/lib/openai.ts +0 -117
- package/src/lib/paginated-sync.ts +0 -93
- package/src/lib/period-digest.ts +0 -1364
- 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 -1198
- 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 -6
- package/src/lib/query-actions.ts +0 -437
- package/src/lib/query-client.tsx +0 -47
- package/src/lib/query-read-model-shared.ts +0 -52
- package/src/lib/query-read-models.ts +0 -5
- package/src/lib/query-resource.ts +0 -41
- package/src/lib/query-status.ts +0 -164
- package/src/lib/research.ts +0 -652
- package/src/lib/runtime-services.ts +0 -20
- package/src/lib/search-discussion.ts +0 -812
- package/src/lib/seed.ts +0 -613
- package/src/lib/server-runtime-services.ts +0 -30
- package/src/lib/sqlite.ts +0 -183
- package/src/lib/streaming-ingestion.ts +0 -240
- package/src/lib/sync-cache.ts +0 -70
- package/src/lib/sync-plan.ts +0 -175
- package/src/lib/theme-transition.ts +0 -113
- package/src/lib/theme.tsx +0 -165
- package/src/lib/timeline-collections-live.ts +0 -407
- package/src/lib/timeline-live.ts +0 -302
- package/src/lib/timeline-read-model.ts +0 -1191
- 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-repository.ts +0 -156
- package/src/lib/tweet-search-live.ts +0 -462
- 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 -533
- package/src/lib/whois.ts +0 -1080
- 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 -82
- 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 -121
- package/src/routes/api/search-discussion.tsx +0 -113
- package/src/routes/api/status.tsx +0 -30
- package/src/routes/api/sync.tsx +0 -108
- package/src/routes/api/xurl-rate-limits.tsx +0 -24
- package/src/routes/blocks.tsx +0 -343
- package/src/routes/bookmarks.tsx +0 -18
- package/src/routes/data-sources.tsx +0 -249
- package/src/routes/discuss.tsx +0 -419
- package/src/routes/dms.tsx +0 -415
- package/src/routes/inbox.tsx +0 -232
- package/src/routes/index.tsx +0 -32
- package/src/routes/likes.tsx +0 -18
- package/src/routes/links.tsx +0 -631
- package/src/routes/mentions.tsx +0 -32
- package/src/routes/network-map.tsx +0 -732
- package/src/routes/profile-analyze.tsx +0 -112
- package/src/routes/profiles.$handle.tsx +0 -228
- package/src/routes/rate-limits.tsx +0 -305
- 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/api-client.ts
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import { Data, Effect } from "effect";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import {
|
|
4
|
-
actionResponseSchema,
|
|
5
|
-
queryEnvelopeSchema,
|
|
6
|
-
queryResponseSchema,
|
|
7
|
-
webSyncJobSchema,
|
|
8
|
-
} from "./api-contracts";
|
|
9
|
-
import { runEffectPromise } from "./effect-runtime";
|
|
10
|
-
import {
|
|
11
|
-
defaultRuntimeServices,
|
|
12
|
-
type RuntimeServices,
|
|
13
|
-
} from "./runtime-services";
|
|
14
|
-
import type {
|
|
15
|
-
WebSyncJobSnapshot,
|
|
16
|
-
WebSyncKind,
|
|
17
|
-
WebSyncOptions,
|
|
18
|
-
} from "./web-sync";
|
|
19
|
-
const SYNC_POLL_INTERVAL_MS = 500;
|
|
20
|
-
|
|
21
|
-
export class ApiFetchError extends Data.TaggedError("ApiFetchError")<{
|
|
22
|
-
readonly message: string;
|
|
23
|
-
readonly status?: number;
|
|
24
|
-
readonly cause?: unknown;
|
|
25
|
-
}> {}
|
|
26
|
-
|
|
27
|
-
function responseMessage(data: unknown, fallback: string) {
|
|
28
|
-
if (data && typeof data === "object") {
|
|
29
|
-
const record = data as {
|
|
30
|
-
message?: unknown;
|
|
31
|
-
error?: unknown;
|
|
32
|
-
summary?: unknown;
|
|
33
|
-
};
|
|
34
|
-
if (typeof record.message === "string") return record.message;
|
|
35
|
-
if (typeof record.error === "string") return record.error;
|
|
36
|
-
if (typeof record.summary === "string") return record.summary;
|
|
37
|
-
}
|
|
38
|
-
return fallback;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function apiFetchErrorFromCause(cause: unknown, fallbackMessage: string) {
|
|
42
|
-
if (cause instanceof DOMException && cause.name === "AbortError") {
|
|
43
|
-
return cause;
|
|
44
|
-
}
|
|
45
|
-
if (cause instanceof ApiFetchError) return cause;
|
|
46
|
-
if (cause instanceof Error) {
|
|
47
|
-
return new ApiFetchError({ message: cause.message, cause });
|
|
48
|
-
}
|
|
49
|
-
if (typeof cause === "string") {
|
|
50
|
-
return new ApiFetchError({ message: cause, cause });
|
|
51
|
-
}
|
|
52
|
-
return new ApiFetchError({ message: fallbackMessage, cause });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function readJsonEffect(response: Response) {
|
|
56
|
-
return Effect.promise(() => response.json().catch(() => null as unknown));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function runApiEffect<T, E>(effect: Effect.Effect<T, E>) {
|
|
60
|
-
return runEffectPromise(effect);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function fetchJsonEffect<T>(
|
|
64
|
-
input: RequestInfo | URL,
|
|
65
|
-
init: RequestInit | undefined,
|
|
66
|
-
schema: z.ZodType<T>,
|
|
67
|
-
fallbackMessage: string,
|
|
68
|
-
runtime: RuntimeServices = defaultRuntimeServices,
|
|
69
|
-
) {
|
|
70
|
-
return Effect.gen(function* () {
|
|
71
|
-
const response = yield* Effect.tryPromise({
|
|
72
|
-
try: () => runtime.fetch(input, init),
|
|
73
|
-
catch: (cause) => apiFetchErrorFromCause(cause, fallbackMessage),
|
|
74
|
-
});
|
|
75
|
-
const data = yield* readJsonEffect(response);
|
|
76
|
-
if (!response.ok) {
|
|
77
|
-
return yield* Effect.fail(
|
|
78
|
-
new ApiFetchError({
|
|
79
|
-
message: responseMessage(data, fallbackMessage),
|
|
80
|
-
status: response.status,
|
|
81
|
-
}),
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const parsed = schema.safeParse(data);
|
|
86
|
-
if (!parsed.success) {
|
|
87
|
-
return yield* Effect.fail(
|
|
88
|
-
new ApiFetchError({
|
|
89
|
-
message: fallbackMessage,
|
|
90
|
-
cause: parsed.error,
|
|
91
|
-
}),
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
return parsed.data;
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function fetchJson<T>(
|
|
99
|
-
input: RequestInfo | URL,
|
|
100
|
-
init: RequestInit | undefined,
|
|
101
|
-
schema: z.ZodType<T>,
|
|
102
|
-
fallbackMessage: string,
|
|
103
|
-
runtime: RuntimeServices = defaultRuntimeServices,
|
|
104
|
-
): Promise<T> {
|
|
105
|
-
return runApiEffect(
|
|
106
|
-
fetchJsonEffect(input, init, schema, fallbackMessage, runtime),
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function fetchQueryEnvelope(init?: RequestInit) {
|
|
111
|
-
return runApiEffect(fetchQueryEnvelopeEffect(init));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function fetchQueryEnvelopeEffect(init?: RequestInit) {
|
|
115
|
-
return fetchJsonEffect(
|
|
116
|
-
"/api/status",
|
|
117
|
-
init,
|
|
118
|
-
queryEnvelopeSchema,
|
|
119
|
-
"Status unavailable",
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export function fetchQueryResponse(
|
|
124
|
-
input: RequestInfo | URL,
|
|
125
|
-
init?: RequestInit,
|
|
126
|
-
) {
|
|
127
|
-
return runApiEffect(fetchQueryResponseEffect(input, init));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function fetchQueryResponseEffect(
|
|
131
|
-
input: RequestInfo | URL,
|
|
132
|
-
init?: RequestInit,
|
|
133
|
-
) {
|
|
134
|
-
return fetchJsonEffect(input, init, queryResponseSchema, "Query unavailable");
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export function postAction(body: Record<string, unknown>) {
|
|
138
|
-
return runApiEffect(postActionEffect(body));
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export function postActionEffect(body: Record<string, unknown>) {
|
|
142
|
-
return fetchJsonEffect(
|
|
143
|
-
"/api/action",
|
|
144
|
-
{
|
|
145
|
-
method: "POST",
|
|
146
|
-
headers: { "content-type": "application/json" },
|
|
147
|
-
body: JSON.stringify(body),
|
|
148
|
-
},
|
|
149
|
-
actionResponseSchema,
|
|
150
|
-
"Action failed",
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function postSync(
|
|
155
|
-
kind: WebSyncKind,
|
|
156
|
-
accountId?: string,
|
|
157
|
-
options: WebSyncOptions = {},
|
|
158
|
-
) {
|
|
159
|
-
return runApiEffect(postSyncEffect(kind, accountId, options));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function postSyncEffect(
|
|
163
|
-
kind: WebSyncKind,
|
|
164
|
-
accountId?: string,
|
|
165
|
-
options: WebSyncOptions = {},
|
|
166
|
-
) {
|
|
167
|
-
return fetchJsonEffect(
|
|
168
|
-
"/api/sync",
|
|
169
|
-
{
|
|
170
|
-
method: "POST",
|
|
171
|
-
headers: { "content-type": "application/json" },
|
|
172
|
-
body: JSON.stringify({
|
|
173
|
-
kind,
|
|
174
|
-
...(accountId ? { accountId } : {}),
|
|
175
|
-
...options,
|
|
176
|
-
}),
|
|
177
|
-
},
|
|
178
|
-
webSyncJobSchema,
|
|
179
|
-
"Sync failed",
|
|
180
|
-
).pipe(Effect.flatMap(waitForWebSyncJobEffect));
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function fetchSyncJobEffect(id: string) {
|
|
184
|
-
const url = new URL("/api/sync", window.location.origin);
|
|
185
|
-
url.searchParams.set("id", id);
|
|
186
|
-
return fetchJsonEffect(
|
|
187
|
-
url,
|
|
188
|
-
undefined,
|
|
189
|
-
webSyncJobSchema,
|
|
190
|
-
"Sync status unavailable",
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export function waitForWebSyncJobEffect(job: WebSyncJobSnapshot) {
|
|
195
|
-
return Effect.gen(function* () {
|
|
196
|
-
let current = job;
|
|
197
|
-
while (current.inProgress) {
|
|
198
|
-
yield* Effect.sleep(SYNC_POLL_INTERVAL_MS);
|
|
199
|
-
current = yield* fetchSyncJobEffect(current.id);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (!current.result) {
|
|
203
|
-
return yield* Effect.fail(
|
|
204
|
-
new ApiFetchError({ message: current.error ?? current.summary }),
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
if (!current.result.ok) {
|
|
208
|
-
return yield* Effect.fail(
|
|
209
|
-
new ApiFetchError({
|
|
210
|
-
message: current.result.error ?? current.result.summary,
|
|
211
|
-
}),
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
return current.result;
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export function waitForWebSyncJob(job: WebSyncJobSnapshot) {
|
|
219
|
-
return runApiEffect(waitForWebSyncJobEffect(job));
|
|
220
|
-
}
|
package/src/lib/api-contracts.ts
DELETED
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import type {
|
|
3
|
-
AccountRecord,
|
|
4
|
-
ArchiveCandidate,
|
|
5
|
-
DmConversationItem,
|
|
6
|
-
DmMessageItem,
|
|
7
|
-
DmSearchMatchItem,
|
|
8
|
-
EmbeddedTweet,
|
|
9
|
-
ProfileAffiliation,
|
|
10
|
-
ProfileRecord,
|
|
11
|
-
QueryEnvelope,
|
|
12
|
-
QueryResponse,
|
|
13
|
-
TimelineItem,
|
|
14
|
-
TransportStatus,
|
|
15
|
-
TweetEntities,
|
|
16
|
-
TweetMediaItem,
|
|
17
|
-
UrlExpansionItem,
|
|
18
|
-
} from "./types";
|
|
19
|
-
import type {
|
|
20
|
-
WebSyncJobSnapshot,
|
|
21
|
-
WebSyncResponse,
|
|
22
|
-
WebSyncStep,
|
|
23
|
-
} from "./web-sync";
|
|
24
|
-
|
|
25
|
-
const jsonRecordSchema = z.record(z.string(), z.unknown());
|
|
26
|
-
const unknownProfile: ProfileRecord = {
|
|
27
|
-
id: "profile_unknown",
|
|
28
|
-
handle: "unknown",
|
|
29
|
-
displayName: "Unknown",
|
|
30
|
-
bio: "",
|
|
31
|
-
followersCount: 0,
|
|
32
|
-
avatarHue: 0,
|
|
33
|
-
createdAt: "",
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const profileAffiliationSchema: z.ZodType<ProfileAffiliation> = z.object({
|
|
37
|
-
organizationProfileId: z.string(),
|
|
38
|
-
organizationName: z.string().optional(),
|
|
39
|
-
organizationHandle: z.string().optional(),
|
|
40
|
-
badgeUrl: z.string().nullable().optional(),
|
|
41
|
-
url: z.string().nullable().optional(),
|
|
42
|
-
label: z.string().nullable().optional(),
|
|
43
|
-
source: z.string(),
|
|
44
|
-
firstSeenAt: z.string(),
|
|
45
|
-
lastSeenAt: z.string(),
|
|
46
|
-
isActive: z.boolean(),
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const profileRecordSchema = z.object({
|
|
50
|
-
id: z.string().default("profile_unknown"),
|
|
51
|
-
handle: z.string().default("unknown"),
|
|
52
|
-
displayName: z.string().default("Unknown"),
|
|
53
|
-
bio: z.string().default(""),
|
|
54
|
-
followersCount: z.number().default(0),
|
|
55
|
-
followingCount: z.number().optional(),
|
|
56
|
-
avatarHue: z.number().default(0),
|
|
57
|
-
avatarUrl: z.string().optional(),
|
|
58
|
-
location: z.string().optional(),
|
|
59
|
-
url: z.string().optional(),
|
|
60
|
-
verifiedType: z.string().optional(),
|
|
61
|
-
entities: jsonRecordSchema.optional(),
|
|
62
|
-
affiliations: z.array(profileAffiliationSchema).optional(),
|
|
63
|
-
primaryAffiliation: profileAffiliationSchema.optional(),
|
|
64
|
-
createdAt: z.string().default(""),
|
|
65
|
-
}) satisfies z.ZodType<ProfileRecord>;
|
|
66
|
-
|
|
67
|
-
const tweetEntitiesSchema: z.ZodType<TweetEntities> = z.object({
|
|
68
|
-
mentions: z
|
|
69
|
-
.array(
|
|
70
|
-
z.object({
|
|
71
|
-
username: z.string(),
|
|
72
|
-
id: z.string().optional(),
|
|
73
|
-
start: z.number(),
|
|
74
|
-
end: z.number(),
|
|
75
|
-
profile: profileRecordSchema.optional(),
|
|
76
|
-
}),
|
|
77
|
-
)
|
|
78
|
-
.optional(),
|
|
79
|
-
urls: z
|
|
80
|
-
.array(
|
|
81
|
-
z.object({
|
|
82
|
-
url: z.string(),
|
|
83
|
-
expandedUrl: z.string(),
|
|
84
|
-
displayUrl: z.string(),
|
|
85
|
-
start: z.number(),
|
|
86
|
-
end: z.number(),
|
|
87
|
-
title: z.string().optional(),
|
|
88
|
-
description: z.string().nullable().optional(),
|
|
89
|
-
imageUrl: z.string().nullable().optional(),
|
|
90
|
-
siteName: z.string().nullable().optional(),
|
|
91
|
-
}),
|
|
92
|
-
)
|
|
93
|
-
.optional(),
|
|
94
|
-
hashtags: z
|
|
95
|
-
.array(
|
|
96
|
-
z.object({
|
|
97
|
-
tag: z.string(),
|
|
98
|
-
start: z.number(),
|
|
99
|
-
end: z.number(),
|
|
100
|
-
}),
|
|
101
|
-
)
|
|
102
|
-
.optional(),
|
|
103
|
-
article: z
|
|
104
|
-
.object({
|
|
105
|
-
title: z.string(),
|
|
106
|
-
previewText: z.string().optional(),
|
|
107
|
-
url: z.string(),
|
|
108
|
-
coverImageUrl: z.string().optional(),
|
|
109
|
-
})
|
|
110
|
-
.optional(),
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const tweetMediaSchema: z.ZodType<TweetMediaItem> = z.object({
|
|
114
|
-
url: z.string(),
|
|
115
|
-
type: z.enum(["image", "video", "gif", "unknown"]),
|
|
116
|
-
altText: z.string().optional(),
|
|
117
|
-
width: z.number().optional(),
|
|
118
|
-
height: z.number().optional(),
|
|
119
|
-
thumbnailUrl: z.string().optional(),
|
|
120
|
-
durationMs: z.number().optional(),
|
|
121
|
-
variants: z
|
|
122
|
-
.array(
|
|
123
|
-
z.object({
|
|
124
|
-
url: z.string(),
|
|
125
|
-
contentType: z.string().optional(),
|
|
126
|
-
bitRate: z.number().optional(),
|
|
127
|
-
}),
|
|
128
|
-
)
|
|
129
|
-
.optional(),
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
const embeddedTweetSchema: z.ZodType<EmbeddedTweet> = z.object({
|
|
133
|
-
id: z.string(),
|
|
134
|
-
text: z.string(),
|
|
135
|
-
createdAt: z.string().default(""),
|
|
136
|
-
replyToId: z.string().nullable().optional(),
|
|
137
|
-
isReplied: z.boolean().optional(),
|
|
138
|
-
likeCount: z.number().optional(),
|
|
139
|
-
mediaCount: z.number().optional(),
|
|
140
|
-
bookmarked: z.boolean().optional(),
|
|
141
|
-
liked: z.boolean().optional(),
|
|
142
|
-
author: profileRecordSchema.default(unknownProfile),
|
|
143
|
-
entities: tweetEntitiesSchema.default({}),
|
|
144
|
-
media: z.array(tweetMediaSchema).default([]),
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
const timelineItemSchema: z.ZodType<TimelineItem> = z.object({
|
|
148
|
-
id: z.string(),
|
|
149
|
-
accountId: z.string().default("acct_primary"),
|
|
150
|
-
accountHandle: z.string().default(""),
|
|
151
|
-
kind: z
|
|
152
|
-
.enum(["home", "mention", "authored", "search", "like", "bookmark"])
|
|
153
|
-
.default("home"),
|
|
154
|
-
text: z.string(),
|
|
155
|
-
searchSnippet: z.string().optional(),
|
|
156
|
-
createdAt: z.string().default(""),
|
|
157
|
-
replyToId: z.string().nullable().optional(),
|
|
158
|
-
isReplied: z.boolean().default(false),
|
|
159
|
-
likeCount: z.number().default(0),
|
|
160
|
-
mediaCount: z.number().default(0),
|
|
161
|
-
bookmarked: z.boolean().default(false),
|
|
162
|
-
liked: z.boolean().default(false),
|
|
163
|
-
author: profileRecordSchema.default(unknownProfile),
|
|
164
|
-
entities: tweetEntitiesSchema.default({}),
|
|
165
|
-
media: z.array(tweetMediaSchema).default([]),
|
|
166
|
-
replyToTweet: embeddedTweetSchema.nullable().optional(),
|
|
167
|
-
quotedTweet: embeddedTweetSchema.nullable().optional(),
|
|
168
|
-
retweetedTweet: embeddedTweetSchema.nullable().optional(),
|
|
169
|
-
qualityReason: z.string().nullable().optional(),
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
const dmMessageSchema: z.ZodType<DmMessageItem> = z.object({
|
|
173
|
-
id: z.string(),
|
|
174
|
-
conversationId: z.string().default(""),
|
|
175
|
-
text: z.string(),
|
|
176
|
-
createdAt: z.string().default(""),
|
|
177
|
-
direction: z.enum(["inbound", "outbound"]).default("inbound"),
|
|
178
|
-
isReplied: z.boolean().default(false),
|
|
179
|
-
mediaCount: z.number().default(0),
|
|
180
|
-
sender: profileRecordSchema.default(unknownProfile),
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
const urlExpansionSchema: z.ZodType<UrlExpansionItem> = z.object({
|
|
184
|
-
url: z.string(),
|
|
185
|
-
expandedUrl: z.string(),
|
|
186
|
-
finalUrl: z.string(),
|
|
187
|
-
status: z.enum(["hit", "miss", "error"]),
|
|
188
|
-
source: z.enum(["cache", "network"]),
|
|
189
|
-
title: z.string().optional(),
|
|
190
|
-
description: z.string().nullable().optional(),
|
|
191
|
-
error: z.string().optional(),
|
|
192
|
-
updatedAt: z.string(),
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
const dmSearchMatchSchema: z.ZodType<DmSearchMatchItem> = z.object({
|
|
196
|
-
message: dmMessageSchema,
|
|
197
|
-
before: z.array(dmMessageSchema),
|
|
198
|
-
after: z.array(dmMessageSchema),
|
|
199
|
-
urlExpansions: z.array(urlExpansionSchema).optional(),
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
const dmConversationSchema: z.ZodType<DmConversationItem> = z.object({
|
|
203
|
-
id: z.string(),
|
|
204
|
-
accountId: z.string(),
|
|
205
|
-
accountHandle: z.string().default(""),
|
|
206
|
-
title: z.string(),
|
|
207
|
-
searchSnippet: z.string().optional(),
|
|
208
|
-
inboxKind: z.enum(["accepted", "request"]).optional(),
|
|
209
|
-
isMessageRequest: z.boolean().optional(),
|
|
210
|
-
lastMessageAt: z.string().default(""),
|
|
211
|
-
lastMessagePreview: z.string().default(""),
|
|
212
|
-
unreadCount: z.number().default(0),
|
|
213
|
-
needsReply: z.boolean().default(false),
|
|
214
|
-
influenceScore: z.number().default(0),
|
|
215
|
-
influenceLabel: z.string().default(""),
|
|
216
|
-
participant: profileRecordSchema.default(unknownProfile),
|
|
217
|
-
matches: z.array(dmSearchMatchSchema).optional(),
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
const accountRecordSchema: z.ZodType<AccountRecord> = z.object({
|
|
221
|
-
id: z.string(),
|
|
222
|
-
name: z.string().default(""),
|
|
223
|
-
handle: z.string().default(""),
|
|
224
|
-
externalUserId: z.string().nullable().optional(),
|
|
225
|
-
profileId: z.string().optional(),
|
|
226
|
-
avatarHue: z.number().optional(),
|
|
227
|
-
avatarUrl: z.string().optional(),
|
|
228
|
-
transport: z.string().default("local"),
|
|
229
|
-
isDefault: z.coerce.number().default(0),
|
|
230
|
-
createdAt: z.string().default(""),
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
const archiveCandidateSchema: z.ZodType<ArchiveCandidate> = z.object({
|
|
234
|
-
path: z.string(),
|
|
235
|
-
name: z.string().default(""),
|
|
236
|
-
size: z.number().default(0),
|
|
237
|
-
sizeFormatted: z.string().default(""),
|
|
238
|
-
modifiedTime: z.string().default(""),
|
|
239
|
-
dateFormatted: z.string().default(""),
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
const transportStatusSchema: z.ZodType<TransportStatus> = z.object({
|
|
243
|
-
installed: z.boolean().default(false),
|
|
244
|
-
availableTransport: z.enum(["xurl", "local"]).default("local"),
|
|
245
|
-
statusText: z.string(),
|
|
246
|
-
rawStatus: z.string().optional(),
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
export const queryEnvelopeSchema: z.ZodType<QueryEnvelope> = z.object({
|
|
250
|
-
accounts: z.array(accountRecordSchema),
|
|
251
|
-
archives: z.array(archiveCandidateSchema),
|
|
252
|
-
transport: transportStatusSchema,
|
|
253
|
-
stats: z.object({
|
|
254
|
-
home: z.number(),
|
|
255
|
-
mentions: z.number(),
|
|
256
|
-
dms: z.number(),
|
|
257
|
-
needsReply: z.number(),
|
|
258
|
-
inbox: z.number(),
|
|
259
|
-
}),
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
const timelineQueryResponseSchema = z.object({
|
|
263
|
-
resource: z.enum(["home", "mentions", "authored", "search"]),
|
|
264
|
-
items: z.array(timelineItemSchema),
|
|
265
|
-
selectedConversation: z.undefined().optional(),
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
const dmQueryResponseSchema = z.object({
|
|
269
|
-
resource: z.literal("dms"),
|
|
270
|
-
items: z.array(dmConversationSchema),
|
|
271
|
-
selectedConversation: z
|
|
272
|
-
.object({
|
|
273
|
-
conversation: dmConversationSchema,
|
|
274
|
-
messages: z.array(dmMessageSchema),
|
|
275
|
-
})
|
|
276
|
-
.nullable()
|
|
277
|
-
.optional(),
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
export const queryResponseSchema: z.ZodType<QueryResponse> = z.union([
|
|
281
|
-
timelineQueryResponseSchema,
|
|
282
|
-
dmQueryResponseSchema,
|
|
283
|
-
]);
|
|
284
|
-
|
|
285
|
-
export const webSyncKindSchema = z.enum([
|
|
286
|
-
"timeline",
|
|
287
|
-
"mentions",
|
|
288
|
-
"likes",
|
|
289
|
-
"bookmarks",
|
|
290
|
-
"dms",
|
|
291
|
-
]);
|
|
292
|
-
|
|
293
|
-
const webSyncStepSchema: z.ZodType<WebSyncStep> = z.object({
|
|
294
|
-
kind: z.union([webSyncKindSchema, z.literal("mention-threads")]),
|
|
295
|
-
label: z.string(),
|
|
296
|
-
count: z.number(),
|
|
297
|
-
source: z.string().optional(),
|
|
298
|
-
partial: z.boolean().optional(),
|
|
299
|
-
warnings: z.array(z.string()).optional(),
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
export const webSyncResponseSchema: z.ZodType<WebSyncResponse> = z.object({
|
|
303
|
-
ok: z.boolean(),
|
|
304
|
-
kind: webSyncKindSchema,
|
|
305
|
-
accountId: z.string().optional(),
|
|
306
|
-
startedAt: z.string().default(""),
|
|
307
|
-
finishedAt: z.string().optional(),
|
|
308
|
-
summary: z.string(),
|
|
309
|
-
steps: z.array(webSyncStepSchema).default([]),
|
|
310
|
-
inProgress: z.boolean().optional(),
|
|
311
|
-
backup: z.custom<WebSyncResponse["backup"]>().optional(),
|
|
312
|
-
error: z.string().optional(),
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
export const webSyncJobSchema: z.ZodType<WebSyncJobSnapshot> = z.object({
|
|
316
|
-
id: z.string(),
|
|
317
|
-
kind: webSyncKindSchema,
|
|
318
|
-
accountId: z.string().optional(),
|
|
319
|
-
status: z.enum(["running", "succeeded", "failed"]),
|
|
320
|
-
startedAt: z.string(),
|
|
321
|
-
finishedAt: z.string().optional(),
|
|
322
|
-
summary: z.string(),
|
|
323
|
-
inProgress: z.boolean(),
|
|
324
|
-
result: webSyncResponseSchema.optional(),
|
|
325
|
-
error: z.string().optional(),
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
export const actionResponseSchema = jsonRecordSchema;
|