a tool to help your Letta AI agents navigate bluesky

cleaned up typescript errors in getCleanThread

Changed files
+28 -27
utils
+28 -27
utils/getCleanThread.ts
··· 19 20 const postsThread: threadPost[] = []; 21 22 - if (thread) { 23 postsThread.push({ 24 - // @TODO fix the type errors here 25 authorHandle: `@${thread.post.author.handle}`, 26 - message: thread.post.record.text, 27 uri: thread.post.uri, 28 authorDID: thread.post.author.did, 29 - postedDateTime: thread.post.record.createdAt, 30 - bookmarks: thread.post.bookmarkCount, 31 - replies: thread.post.replyCount, 32 - reposts: thread.post.repostCount, 33 - likes: thread.post.likeCount, 34 - quotes: thread.post.quoteCount, 35 }); 36 - } 37 38 - if (thread.parent) { 39 - let current = thread.parent; 40 41 - while (current) { 42 - postsThread.push({ 43 - authorHandle: `@${current.post.author.handle}`, 44 - message: current.post.record.text, 45 - uri: current.post.uri, 46 - authorDID: current.post.author.did, 47 - postedDateTime: current.post.record.createdAt, 48 - bookmarks: current.post.bookmarkCount, 49 - replies: current.post.replyCount, 50 - reposts: current.post.repostCount, 51 - likes: current.post.likeCount, 52 - quotes: current.post.quoteCount, 53 - }); 54 - current = current.parent; 55 } 56 - postsThread.reverse(); 57 } 58 59 return postsThread;
··· 19 20 const postsThread: threadPost[] = []; 21 22 + // Type guard to check if thread is a ThreadViewPost 23 + if (thread && "post" in thread) { 24 postsThread.push({ 25 authorHandle: `@${thread.post.author.handle}`, 26 + message: (thread.post.record as { text: string }).text, 27 uri: thread.post.uri, 28 authorDID: thread.post.author.did, 29 + postedDateTime: (thread.post.record as { createdAt: string }).createdAt, 30 + bookmarks: thread.post.bookmarkCount ?? 0, 31 + replies: thread.post.replyCount ?? 0, 32 + reposts: thread.post.repostCount ?? 0, 33 + likes: thread.post.likeCount ?? 0, 34 + quotes: thread.post.quoteCount ?? 0, 35 }); 36 37 + // Now traverse the parent chain 38 + if ("parent" in thread) { 39 + let current = thread.parent; 40 41 + while (current && "post" in current) { 42 + postsThread.push({ 43 + authorHandle: `@${current.post.author.handle}`, 44 + message: (current.post.record as { text: string }).text, 45 + uri: current.post.uri, 46 + authorDID: current.post.author.did, 47 + postedDateTime: (current.post.record as { createdAt: string }).createdAt, 48 + bookmarks: current.post.bookmarkCount ?? 0, 49 + replies: current.post.replyCount ?? 0, 50 + reposts: current.post.repostCount ?? 0, 51 + likes: current.post.likeCount ?? 0, 52 + quotes: current.post.quoteCount ?? 0, 53 + }); 54 + current = "parent" in current ? current.parent : undefined; 55 + } 56 + postsThread.reverse(); 57 } 58 } 59 60 return postsThread;