@meowtrix/atproto-mcp 0.1.1

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.
@@ -0,0 +1,199 @@
1
+ import type {
2
+ AppBskyFeedDefs,
3
+ AppBskyFeedPost,
4
+ AppBskyActorDefs,
5
+ AppBskyNotificationListNotifications,
6
+ } from "@atcute/bluesky";
7
+
8
+ export function slimEmbed(
9
+ embed: AppBskyFeedDefs.PostView["embed"],
10
+ ): unknown {
11
+ if (!embed) return undefined;
12
+
13
+ if (embed.$type === "app.bsky.embed.images#view") {
14
+ return {
15
+ $type: embed.$type,
16
+ images: embed.images?.map((img) => ({
17
+ alt: img.alt,
18
+ })),
19
+ };
20
+ }
21
+ if (embed.$type === "app.bsky.embed.external#view") {
22
+ return {
23
+ $type: embed.$type,
24
+ external: {
25
+ uri: embed.external?.uri,
26
+ title: embed.external?.title,
27
+ },
28
+ };
29
+ }
30
+ if (embed.$type === "app.bsky.embed.record#view") {
31
+ const rec = embed.record;
32
+ if (rec?.$type === "app.bsky.embed.record#viewRecord") {
33
+ return {
34
+ $type: embed.$type,
35
+ record: {
36
+ uri: rec.uri,
37
+ cid: rec.cid,
38
+ author: {
39
+ handle: rec.author?.handle,
40
+ displayName: rec.author?.displayName,
41
+ },
42
+ value: { text: (rec.value as any)?.text },
43
+ embeds: rec.embeds?.map(slimEmbed).filter(Boolean),
44
+ },
45
+ };
46
+ }
47
+ return { $type: embed.$type, record: { $type: rec?.$type } };
48
+ }
49
+ if (embed.$type === "app.bsky.embed.video#view") {
50
+ return {
51
+ $type: embed.$type,
52
+ alt: embed.alt,
53
+ };
54
+ }
55
+ if (embed.$type === "app.bsky.embed.recordWithMedia#view") {
56
+ return {
57
+ $type: embed.$type,
58
+ record: slimEmbed(
59
+ embed.record as AppBskyFeedDefs.PostView["embed"],
60
+ ),
61
+ media: slimEmbed(embed.media as AppBskyFeedDefs.PostView["embed"]),
62
+ };
63
+ }
64
+ return { $type: (embed as { $type?: string }).$type };
65
+ }
66
+
67
+ export function slimPost(post: AppBskyFeedDefs.PostView) {
68
+ const record = post.record as AppBskyFeedPost.Main;
69
+ return {
70
+ uri: post.uri,
71
+ cid: post.cid,
72
+ author: {
73
+ handle: post.author?.handle,
74
+ displayName: post.author?.displayName,
75
+ },
76
+ record: {
77
+ text: record?.text,
78
+ createdAt: record?.createdAt,
79
+ ...(record?.facets?.length && { facets: record.facets }),
80
+ },
81
+ embed: slimEmbed(post.embed),
82
+ likeCount: post.likeCount,
83
+ repostCount: post.repostCount,
84
+ replyCount: post.replyCount,
85
+ quoteCount: post.quoteCount,
86
+ ...((post.viewer?.like || post.viewer?.repost) && {
87
+ viewer: {
88
+ ...(post.viewer.like && { like: post.viewer.like }),
89
+ ...(post.viewer.repost && { repost: post.viewer.repost }),
90
+ },
91
+ }),
92
+ };
93
+ }
94
+
95
+ export function slimFeedItem(item: AppBskyFeedDefs.FeedViewPost) {
96
+ return {
97
+ post: slimPost(item.post),
98
+ ...(item.reason && {
99
+ reason: "repost",
100
+ reasonBy: "by" in item.reason ? item.reason.by?.handle : undefined,
101
+ }),
102
+ ...(item.reply && {
103
+ reply: {
104
+ ...(item.reply.parent?.$type === "app.bsky.feed.defs#postView" && {
105
+ parentUri: item.reply.parent.uri,
106
+ parentAuthor: item.reply.parent.author?.handle,
107
+ parentText: (item.reply.parent.record as AppBskyFeedPost.Main)?.text,
108
+ }),
109
+ ...(item.reply.root?.$type === "app.bsky.feed.defs#postView" && {
110
+ rootUri: item.reply.root.uri,
111
+ rootAuthor: item.reply.root.author?.handle,
112
+ rootText: (item.reply.root.record as AppBskyFeedPost.Main)?.text,
113
+ }),
114
+ },
115
+ }),
116
+ };
117
+ }
118
+
119
+ export function slimActor(actor: AppBskyActorDefs.ProfileView) {
120
+ return {
121
+ did: actor.did,
122
+ handle: actor.handle,
123
+ displayName: actor.displayName,
124
+ description: actor.description,
125
+ viewer: {
126
+ following: actor.viewer?.following,
127
+ followedBy: actor.viewer?.followedBy,
128
+ },
129
+ ...(actor.verification && { verification: actor.verification }),
130
+ };
131
+ }
132
+
133
+ export function slimProfile(actor: AppBskyActorDefs.ProfileViewDetailed) {
134
+ return {
135
+ did: actor.did,
136
+ handle: actor.handle,
137
+ displayName: actor.displayName,
138
+ description: actor.description,
139
+ followersCount: actor.followersCount,
140
+ followsCount: actor.followsCount,
141
+ postsCount: actor.postsCount,
142
+ createdAt: actor.createdAt,
143
+ viewer: {
144
+ following: actor.viewer?.following,
145
+ followedBy: actor.viewer?.followedBy,
146
+ muted: actor.viewer?.muted,
147
+ blocking: actor.viewer?.blocking,
148
+ blockedBy: actor.viewer?.blockedBy,
149
+ },
150
+ ...(actor.verification && { verification: actor.verification }),
151
+ ...(actor.pinnedPost && { pinnedPost: actor.pinnedPost }),
152
+ ...("website" in actor && actor.website && { website: actor.website }),
153
+ };
154
+ }
155
+
156
+ export function slimNotification(
157
+ notif: AppBskyNotificationListNotifications.Notification,
158
+ ) {
159
+ return {
160
+ uri: notif.uri,
161
+ author: notif.author?.handle,
162
+ reason: notif.reason,
163
+ reasonSubject: notif.reasonSubject,
164
+ isRead: notif.isRead,
165
+ indexedAt: notif.indexedAt,
166
+ record: { text: (notif.record as AppBskyFeedPost.Main)?.text },
167
+ };
168
+ }
169
+
170
+ export function isThreadViewPost(
171
+ v:
172
+ | AppBskyFeedDefs.BlockedPost
173
+ | AppBskyFeedDefs.NotFoundPost
174
+ | AppBskyFeedDefs.ThreadViewPost,
175
+ ): v is AppBskyFeedDefs.ThreadViewPost {
176
+ return "post" in v;
177
+ }
178
+
179
+ export type ThreadUnion =
180
+ | AppBskyFeedDefs.ThreadViewPost
181
+ | AppBskyFeedDefs.NotFoundPost
182
+ | AppBskyFeedDefs.BlockedPost;
183
+
184
+ export function slimThreadPost(thread: ThreadUnion): unknown {
185
+ if (!isThreadViewPost(thread)) return thread;
186
+ const result: Record<string, unknown> = {
187
+ $type: thread.$type,
188
+ post: slimPost(thread.post),
189
+ };
190
+ if (thread.parent && isThreadViewPost(thread.parent)) {
191
+ result.parent = slimThreadPost(thread.parent);
192
+ }
193
+ if (thread.replies?.length) {
194
+ result.replies = thread.replies
195
+ .filter(isThreadViewPost)
196
+ .map(slimThreadPost);
197
+ }
198
+ return result;
199
+ }