Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dotenv": "^16.4.5"
},
"devDependencies": {
"@types/node": "^22.10.5",
"@types/node": "^22.19.10",
"typescript": "^5.7.2"
}
}
9 changes: 5 additions & 4 deletions src/services/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ export class AutonomousAgent {

console.log(`\n📬 [${new Date().toLocaleTimeString()}] Found ${newMentions.length} new mention(s)!\n`);

// Process each mention
for (const mention of newMentions) {
await this.processMention(mention);
this.processedMentions.add(mention.post.id);
// Process each mention in reverse (oldest first) to maintain chronological Set insertion order
// X API returns mentions newest-first, so we reverse to process oldest→newest
for (let i = newMentions.length - 1; i >= 0; i--) {
await this.processMention(newMentions[i]);
this.processedMentions.add(newMentions[i].post.id);
}

// Prune oldest entries to prevent unbounded memory growth
Expand Down
5 changes: 5 additions & 0 deletions src/services/xapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export class XAPIClient {
return null;
}

if (!Array.isArray(response.data)) {
console.warn('Unexpected response shape from X API (thread): data is not an array');
return null;
}

return this.parseThread(response.data);
} catch (error) {
console.error('Error fetching thread:', error);
Expand Down