dp-worker 0.1.23 → 0.1.25
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/dist/bird/ops.js +44 -0
- package/dist/bird/ops.js.map +1 -1
- package/dist/bird/sidecar-entry.js +16 -2
- package/dist/bird/sidecar-entry.js.map +1 -1
- package/dist/chrome-extension/omni-flow/manifest.json +1 -1
- package/node_modules/dp-shared/dist/bird-contracts.d.ts +308 -0
- package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/bird-contracts.js +228 -0
- package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -1
- package/node_modules/dp-shared/dist/post-drafts-contracts.d.ts +3 -3
- package/package.json +2 -2
- package/vendor/bird/LICENSE +21 -0
- package/vendor/bird/README.md +58 -0
- package/vendor/bird/dist/cli/pagination.d.ts +35 -0
- package/vendor/bird/dist/cli/pagination.js +43 -0
- package/vendor/bird/dist/cli/program.d.ts +5 -0
- package/vendor/bird/dist/cli/program.js +113 -0
- package/vendor/bird/dist/cli/shared.d.ts +77 -0
- package/vendor/bird/dist/cli/shared.js +327 -0
- package/vendor/bird/dist/cli.d.ts +12 -0
- package/vendor/bird/dist/cli.js +29 -0
- package/vendor/bird/dist/commands/bookmarks.d.ts +4 -0
- package/vendor/bird/dist/commands/bookmarks.js +189 -0
- package/vendor/bird/dist/commands/check.d.ts +4 -0
- package/vendor/bird/dist/commands/check.js +43 -0
- package/vendor/bird/dist/commands/follow.d.ts +4 -0
- package/vendor/bird/dist/commands/follow.js +91 -0
- package/vendor/bird/dist/commands/help.d.ts +4 -0
- package/vendor/bird/dist/commands/help.js +19 -0
- package/vendor/bird/dist/commands/home.d.ts +4 -0
- package/vendor/bird/dist/commands/home.js +43 -0
- package/vendor/bird/dist/commands/lists.d.ts +4 -0
- package/vendor/bird/dist/commands/lists.js +125 -0
- package/vendor/bird/dist/commands/news.d.ts +4 -0
- package/vendor/bird/dist/commands/news.js +131 -0
- package/vendor/bird/dist/commands/post.d.ts +4 -0
- package/vendor/bird/dist/commands/post.js +101 -0
- package/vendor/bird/dist/commands/query-ids.d.ts +4 -0
- package/vendor/bird/dist/commands/query-ids.js +80 -0
- package/vendor/bird/dist/commands/read.d.ts +4 -0
- package/vendor/bird/dist/commands/read.js +152 -0
- package/vendor/bird/dist/commands/search.d.ts +4 -0
- package/vendor/bird/dist/commands/search.js +115 -0
- package/vendor/bird/dist/commands/unbookmark.d.ts +4 -0
- package/vendor/bird/dist/commands/unbookmark.js +36 -0
- package/vendor/bird/dist/commands/user-tweets.d.ts +4 -0
- package/vendor/bird/dist/commands/user-tweets.js +109 -0
- package/vendor/bird/dist/commands/users.d.ts +4 -0
- package/vendor/bird/dist/commands/users.js +295 -0
- package/vendor/bird/dist/index.d.ts +2 -0
- package/vendor/bird/dist/index.js +2 -0
- package/vendor/bird/dist/lib/cli-args.d.ts +7 -0
- package/vendor/bird/dist/lib/cli-args.js +25 -0
- package/vendor/bird/dist/lib/cookies.d.ts +31 -0
- package/vendor/bird/dist/lib/cookies.js +81 -0
- package/vendor/bird/dist/lib/extract-bookmark-folder-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-bookmark-folder-id.js +20 -0
- package/vendor/bird/dist/lib/extract-list-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-list-id.js +19 -0
- package/vendor/bird/dist/lib/extract-tweet-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-tweet-id.js +14 -0
- package/vendor/bird/dist/lib/features.json +17 -0
- package/vendor/bird/dist/lib/index.d.ts +10 -0
- package/vendor/bird/dist/lib/index.js +4 -0
- package/vendor/bird/dist/lib/normalize-handle.d.ts +6 -0
- package/vendor/bird/dist/lib/normalize-handle.js +31 -0
- package/vendor/bird/dist/lib/output.d.ts +29 -0
- package/vendor/bird/dist/lib/output.js +88 -0
- package/vendor/bird/dist/lib/paginate-cursor.d.ts +27 -0
- package/vendor/bird/dist/lib/paginate-cursor.js +37 -0
- package/vendor/bird/dist/lib/query-ids.json +20 -0
- package/vendor/bird/dist/lib/runtime-features.d.ts +19 -0
- package/vendor/bird/dist/lib/runtime-features.js +151 -0
- package/vendor/bird/dist/lib/runtime-query-ids.d.ts +33 -0
- package/vendor/bird/dist/lib/runtime-query-ids.js +264 -0
- package/vendor/bird/dist/lib/thread-filters.d.ts +8 -0
- package/vendor/bird/dist/lib/thread-filters.js +124 -0
- package/vendor/bird/dist/lib/twitter-client-base.d.ts +38 -0
- package/vendor/bird/dist/lib/twitter-client-base.js +129 -0
- package/vendor/bird/dist/lib/twitter-client-bookmarks.d.ts +7 -0
- package/vendor/bird/dist/lib/twitter-client-bookmarks.js +61 -0
- package/vendor/bird/dist/lib/twitter-client-constants.d.ts +43 -0
- package/vendor/bird/dist/lib/twitter-client-constants.js +50 -0
- package/vendor/bird/dist/lib/twitter-client-engagement.d.ts +16 -0
- package/vendor/bird/dist/lib/twitter-client-engagement.js +81 -0
- package/vendor/bird/dist/lib/twitter-client-features.d.ts +14 -0
- package/vendor/bird/dist/lib/twitter-client-features.js +347 -0
- package/vendor/bird/dist/lib/twitter-client-follow.d.ts +8 -0
- package/vendor/bird/dist/lib/twitter-client-follow.js +178 -0
- package/vendor/bird/dist/lib/twitter-client-home.d.ts +13 -0
- package/vendor/bird/dist/lib/twitter-client-home.js +138 -0
- package/vendor/bird/dist/lib/twitter-client-lists.d.ts +11 -0
- package/vendor/bird/dist/lib/twitter-client-lists.js +321 -0
- package/vendor/bird/dist/lib/twitter-client-media.d.ts +11 -0
- package/vendor/bird/dist/lib/twitter-client-media.js +136 -0
- package/vendor/bird/dist/lib/twitter-client-news.d.ts +47 -0
- package/vendor/bird/dist/lib/twitter-client-news.js +283 -0
- package/vendor/bird/dist/lib/twitter-client-posting.d.ts +8 -0
- package/vendor/bird/dist/lib/twitter-client-posting.js +218 -0
- package/vendor/bird/dist/lib/twitter-client-search.d.ts +19 -0
- package/vendor/bird/dist/lib/twitter-client-search.js +157 -0
- package/vendor/bird/dist/lib/twitter-client-timelines.d.ts +23 -0
- package/vendor/bird/dist/lib/twitter-client-timelines.js +471 -0
- package/vendor/bird/dist/lib/twitter-client-tweet-detail.d.ts +25 -0
- package/vendor/bird/dist/lib/twitter-client-tweet-detail.js +295 -0
- package/vendor/bird/dist/lib/twitter-client-types.d.ts +407 -0
- package/vendor/bird/dist/lib/twitter-client-types.js +2 -0
- package/vendor/bird/dist/lib/twitter-client-user-lookup.d.ts +16 -0
- package/vendor/bird/dist/lib/twitter-client-user-lookup.js +224 -0
- package/vendor/bird/dist/lib/twitter-client-user-tweets.d.ts +22 -0
- package/vendor/bird/dist/lib/twitter-client-user-tweets.js +154 -0
- package/vendor/bird/dist/lib/twitter-client-users.d.ts +9 -0
- package/vendor/bird/dist/lib/twitter-client-users.js +358 -0
- package/vendor/bird/dist/lib/twitter-client-utils.d.ts +173 -0
- package/vendor/bird/dist/lib/twitter-client-utils.js +511 -0
- package/vendor/bird/dist/lib/twitter-client.d.ts +23 -0
- package/vendor/bird/dist/lib/twitter-client.js +21 -0
- package/vendor/bird/dist/lib/version.d.ts +6 -0
- package/vendor/bird/dist/lib/version.js +174 -0
- package/vendor/bird/upstream-package.json +61 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { TwitterClient } from '../lib/twitter-client.js';
|
|
2
|
+
function formatPostCount(count) {
|
|
3
|
+
if (count >= 1_000_000) {
|
|
4
|
+
return `${(count / 1_000_000).toFixed(1)}M`;
|
|
5
|
+
}
|
|
6
|
+
if (count >= 1_000) {
|
|
7
|
+
return `${(count / 1_000).toFixed(1)}K`;
|
|
8
|
+
}
|
|
9
|
+
return String(count);
|
|
10
|
+
}
|
|
11
|
+
function printNewsItems(items, ctx, opts = {}) {
|
|
12
|
+
if (opts.json) {
|
|
13
|
+
console.log(JSON.stringify(items, null, 2));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (items.length === 0) {
|
|
17
|
+
console.log(opts.emptyMessage ?? 'No news items found.');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
for (const item of items) {
|
|
21
|
+
const categoryLabel = item.category ? `[${item.category}]` : '';
|
|
22
|
+
console.log(`\n${ctx.colors.accent(categoryLabel)} ${ctx.colors.command(item.headline)}`);
|
|
23
|
+
if (item.description) {
|
|
24
|
+
console.log(` ${ctx.colors.muted(item.description)}`);
|
|
25
|
+
}
|
|
26
|
+
const meta = [];
|
|
27
|
+
if (item.timeAgo) {
|
|
28
|
+
meta.push(item.timeAgo);
|
|
29
|
+
}
|
|
30
|
+
if (item.postCount) {
|
|
31
|
+
meta.push(`${formatPostCount(item.postCount)} posts`);
|
|
32
|
+
}
|
|
33
|
+
if (meta.length > 0) {
|
|
34
|
+
console.log(` ${ctx.colors.muted(meta.join(' | '))}`);
|
|
35
|
+
}
|
|
36
|
+
if (item.url) {
|
|
37
|
+
console.log(` ${ctx.l('url')}${item.url}`);
|
|
38
|
+
}
|
|
39
|
+
// Print related tweets if available
|
|
40
|
+
if (item.tweets && item.tweets.length > 0) {
|
|
41
|
+
console.log(` ${ctx.colors.section('Related tweets:')}`);
|
|
42
|
+
const tweetLimit = opts.tweetLimit ?? item.tweets.length;
|
|
43
|
+
for (const tweet of item.tweets.slice(0, tweetLimit)) {
|
|
44
|
+
console.log(` @${tweet.author.username}: ${tweet.text.slice(0, 100)}${tweet.text.length > 100 ? '...' : ''}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
console.log(ctx.colors.muted('─'.repeat(50)));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function registerNewsCommand(program, ctx) {
|
|
51
|
+
program
|
|
52
|
+
.command('news')
|
|
53
|
+
.alias('trending')
|
|
54
|
+
.description('Fetch AI-curated news and trending topics from Explore tabs')
|
|
55
|
+
.option('-n, --count <number>', 'Number of items to fetch', '10')
|
|
56
|
+
.option('--ai-only', 'Show only AI-curated news items')
|
|
57
|
+
.option('--with-tweets', 'Also fetch related tweets for each news item')
|
|
58
|
+
.option('--tweets-per-item <number>', 'Number of tweets to fetch per news item (default: 5)', '5')
|
|
59
|
+
.option('--for-you', 'Fetch only from For You tab')
|
|
60
|
+
.option('--news-only', 'Fetch only from News tab')
|
|
61
|
+
.option('--sports', 'Fetch only from Sports tab')
|
|
62
|
+
.option('--entertainment', 'Fetch only from Entertainment tab')
|
|
63
|
+
.option('--trending-only', 'Fetch only from Trending tab')
|
|
64
|
+
.option('--json', 'Output as JSON')
|
|
65
|
+
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
|
66
|
+
.action(async (cmdOpts) => {
|
|
67
|
+
const opts = program.opts();
|
|
68
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
69
|
+
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
|
70
|
+
const count = Number.parseInt(cmdOpts.count || '10', 10);
|
|
71
|
+
const tweetsPerItem = Number.parseInt(cmdOpts.tweetsPerItem || '5', 10);
|
|
72
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
73
|
+
for (const warning of warnings) {
|
|
74
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
75
|
+
}
|
|
76
|
+
if (Number.isNaN(count) || count < 1) {
|
|
77
|
+
console.error(`${ctx.p('err')}--count must be a positive number`);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
if (Number.isNaN(tweetsPerItem) || tweetsPerItem < 1) {
|
|
81
|
+
console.error(`${ctx.p('err')}--tweets-per-item must be a positive number`);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
85
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
// Determine which tabs to fetch from
|
|
89
|
+
const tabs = [];
|
|
90
|
+
if (cmdOpts.forYou) {
|
|
91
|
+
tabs.push('forYou');
|
|
92
|
+
}
|
|
93
|
+
if (cmdOpts.newsOnly) {
|
|
94
|
+
tabs.push('news');
|
|
95
|
+
}
|
|
96
|
+
if (cmdOpts.sports) {
|
|
97
|
+
tabs.push('sports');
|
|
98
|
+
}
|
|
99
|
+
if (cmdOpts.entertainment) {
|
|
100
|
+
tabs.push('entertainment');
|
|
101
|
+
}
|
|
102
|
+
if (cmdOpts.trendingOnly) {
|
|
103
|
+
tabs.push('trending');
|
|
104
|
+
}
|
|
105
|
+
// If no specific tabs selected, use defaults (all tabs except trending)
|
|
106
|
+
const tabsToFetch = tabs.length > 0 ? tabs : undefined;
|
|
107
|
+
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
|
108
|
+
const includeRaw = cmdOpts.jsonFull ?? false;
|
|
109
|
+
const withTweets = cmdOpts.withTweets ?? false;
|
|
110
|
+
const aiOnly = cmdOpts.aiOnly ?? false;
|
|
111
|
+
const result = await client.getNews(count, {
|
|
112
|
+
includeRaw,
|
|
113
|
+
withTweets,
|
|
114
|
+
tweetsPerItem,
|
|
115
|
+
aiOnly,
|
|
116
|
+
tabs: tabsToFetch,
|
|
117
|
+
});
|
|
118
|
+
if (result.success) {
|
|
119
|
+
printNewsItems(result.items, ctx, {
|
|
120
|
+
json: cmdOpts.json || cmdOpts.jsonFull,
|
|
121
|
+
emptyMessage: 'No news items found.',
|
|
122
|
+
tweetLimit: withTweets ? tweetsPerItem : undefined,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
console.error(`${ctx.p('err')}Failed to fetch news: ${result.error}`);
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=news.js.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { formatTweetUrlLine } from '../lib/output.js';
|
|
2
|
+
import { TwitterClient } from '../lib/twitter-client.js';
|
|
3
|
+
async function uploadMediaOrExit(client, media, ctx) {
|
|
4
|
+
if (media.length === 0) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
const uploaded = [];
|
|
8
|
+
for (const item of media) {
|
|
9
|
+
const res = await client.uploadMedia({ data: item.buffer, mimeType: item.mime, alt: item.alt });
|
|
10
|
+
if (!res.success || !res.mediaId) {
|
|
11
|
+
console.error(`${ctx.p('err')}Media upload failed: ${res.error ?? 'Unknown error'}`);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
uploaded.push(res.mediaId);
|
|
15
|
+
}
|
|
16
|
+
return uploaded;
|
|
17
|
+
}
|
|
18
|
+
export function registerPostCommands(program, ctx) {
|
|
19
|
+
program
|
|
20
|
+
.command('tweet')
|
|
21
|
+
.description('Post a new tweet')
|
|
22
|
+
.argument('<text>', 'Tweet text')
|
|
23
|
+
.action(async (text) => {
|
|
24
|
+
const opts = program.opts();
|
|
25
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
26
|
+
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
|
27
|
+
let media = [];
|
|
28
|
+
try {
|
|
29
|
+
media = ctx.loadMedia({ media: opts.media ?? [], alts: opts.alt ?? [] });
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error(`${ctx.p('err')}${error instanceof Error ? error.message : String(error)}`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
36
|
+
for (const warning of warnings) {
|
|
37
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
38
|
+
}
|
|
39
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
40
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
if (cookies.source) {
|
|
44
|
+
console.error(`${ctx.l('source')}${cookies.source}`);
|
|
45
|
+
}
|
|
46
|
+
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
|
47
|
+
const mediaIds = await uploadMediaOrExit(client, media, ctx);
|
|
48
|
+
const result = await client.tweet(text, mediaIds);
|
|
49
|
+
if (result.success) {
|
|
50
|
+
console.log(`${ctx.p('ok')}Tweet posted successfully!`);
|
|
51
|
+
console.log(formatTweetUrlLine(result.tweetId, ctx.getOutput()));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.error(`${ctx.p('err')}Failed to post tweet: ${result.error}`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
program
|
|
59
|
+
.command('reply')
|
|
60
|
+
.description('Reply to an existing tweet')
|
|
61
|
+
.argument('<tweet-id-or-url>', 'Tweet ID or URL to reply to')
|
|
62
|
+
.argument('<text>', 'Reply text')
|
|
63
|
+
.action(async (tweetIdOrUrl, text) => {
|
|
64
|
+
const opts = program.opts();
|
|
65
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
66
|
+
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
|
67
|
+
let media = [];
|
|
68
|
+
try {
|
|
69
|
+
media = ctx.loadMedia({ media: opts.media ?? [], alts: opts.alt ?? [] });
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error(`${ctx.p('err')}${error instanceof Error ? error.message : String(error)}`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
const tweetId = ctx.extractTweetId(tweetIdOrUrl);
|
|
76
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
77
|
+
for (const warning of warnings) {
|
|
78
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
79
|
+
}
|
|
80
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
81
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
if (cookies.source) {
|
|
85
|
+
console.error(`${ctx.l('source')}${cookies.source}`);
|
|
86
|
+
}
|
|
87
|
+
console.error(`${ctx.p('info')}Replying to tweet: ${tweetId}`);
|
|
88
|
+
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
|
89
|
+
const mediaIds = await uploadMediaOrExit(client, media, ctx);
|
|
90
|
+
const result = await client.reply(text, tweetId, mediaIds);
|
|
91
|
+
if (result.success) {
|
|
92
|
+
console.log(`${ctx.p('ok')}Reply posted successfully!`);
|
|
93
|
+
console.log(formatTweetUrlLine(result.tweetId, ctx.getOutput()));
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
console.error(`${ctx.p('err')}Failed to post reply: ${result.error}`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=post.js.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { getFeatureOverridesSnapshot, refreshFeatureOverridesCache, } from '../lib/runtime-features.js';
|
|
2
|
+
import { runtimeQueryIds } from '../lib/runtime-query-ids.js';
|
|
3
|
+
function countFeatureOverrides(overrides) {
|
|
4
|
+
let count = 0;
|
|
5
|
+
if (overrides.global) {
|
|
6
|
+
count += Object.keys(overrides.global).length;
|
|
7
|
+
}
|
|
8
|
+
if (overrides.sets) {
|
|
9
|
+
for (const setOverrides of Object.values(overrides.sets)) {
|
|
10
|
+
count += Object.keys(setOverrides).length;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return count;
|
|
14
|
+
}
|
|
15
|
+
export function registerQueryIdsCommand(program, ctx) {
|
|
16
|
+
program
|
|
17
|
+
.command('query-ids')
|
|
18
|
+
.description('Show or refresh cached Twitter GraphQL query IDs')
|
|
19
|
+
.option('--json', 'Output as JSON')
|
|
20
|
+
.option('--fresh', 'Force refresh (downloads X client bundles)', false)
|
|
21
|
+
.action(async (cmdOpts) => {
|
|
22
|
+
const operations = [
|
|
23
|
+
'CreateTweet',
|
|
24
|
+
'CreateRetweet',
|
|
25
|
+
'FavoriteTweet',
|
|
26
|
+
'TweetDetail',
|
|
27
|
+
'SearchTimeline',
|
|
28
|
+
'UserArticlesTweets',
|
|
29
|
+
'Bookmarks',
|
|
30
|
+
'Following',
|
|
31
|
+
'Followers',
|
|
32
|
+
'Likes',
|
|
33
|
+
];
|
|
34
|
+
if (cmdOpts.fresh) {
|
|
35
|
+
console.error(`${ctx.p('info')}Refreshing GraphQL query IDs…`);
|
|
36
|
+
await runtimeQueryIds.refresh(operations, { force: true });
|
|
37
|
+
console.error(`${ctx.p('info')}Refreshing feature overrides…`);
|
|
38
|
+
await refreshFeatureOverridesCache();
|
|
39
|
+
}
|
|
40
|
+
const featureSnapshot = getFeatureOverridesSnapshot();
|
|
41
|
+
const info = await runtimeQueryIds.getSnapshotInfo();
|
|
42
|
+
if (!info) {
|
|
43
|
+
if (cmdOpts.json) {
|
|
44
|
+
console.log(JSON.stringify({
|
|
45
|
+
cached: false,
|
|
46
|
+
cachePath: runtimeQueryIds.cachePath,
|
|
47
|
+
featuresPath: featureSnapshot.cachePath,
|
|
48
|
+
features: featureSnapshot.overrides,
|
|
49
|
+
}, null, 2));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
console.log(`${ctx.p('warn')}No cached query IDs yet.`);
|
|
53
|
+
console.log(`${ctx.p('info')}Run: bird query-ids --fresh`);
|
|
54
|
+
console.log(`features_path: ${featureSnapshot.cachePath}`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (cmdOpts.json) {
|
|
58
|
+
console.log(JSON.stringify({
|
|
59
|
+
cached: true,
|
|
60
|
+
cachePath: info.cachePath,
|
|
61
|
+
fetchedAt: info.snapshot.fetchedAt,
|
|
62
|
+
isFresh: info.isFresh,
|
|
63
|
+
ageMs: info.ageMs,
|
|
64
|
+
ids: info.snapshot.ids,
|
|
65
|
+
discovery: info.snapshot.discovery,
|
|
66
|
+
featuresPath: featureSnapshot.cachePath,
|
|
67
|
+
features: featureSnapshot.overrides,
|
|
68
|
+
}, null, 2));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
console.log(`${ctx.p('ok')}GraphQL query IDs cached`);
|
|
72
|
+
console.log(`path: ${info.cachePath}`);
|
|
73
|
+
console.log(`fetched_at: ${info.snapshot.fetchedAt}`);
|
|
74
|
+
console.log(`fresh: ${info.isFresh ? 'yes' : 'no'}`);
|
|
75
|
+
console.log(`ops: ${Object.keys(info.snapshot.ids).length}`);
|
|
76
|
+
console.log(`features_path: ${featureSnapshot.cachePath}`);
|
|
77
|
+
console.log(`features: ${countFeatureOverrides(featureSnapshot.overrides)}`);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=query-ids.js.map
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { parsePaginationFlags } from '../cli/pagination.js';
|
|
2
|
+
import { formatStatsLine } from '../lib/output.js';
|
|
3
|
+
import { TwitterClient } from '../lib/twitter-client.js';
|
|
4
|
+
export function registerReadCommands(program, ctx) {
|
|
5
|
+
program
|
|
6
|
+
.command('read')
|
|
7
|
+
.description('Read/fetch a tweet by ID or URL')
|
|
8
|
+
.argument('<tweet-id-or-url>', 'Tweet ID or URL to read')
|
|
9
|
+
.option('--json', 'Output as JSON')
|
|
10
|
+
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
|
11
|
+
.action(async (tweetIdOrUrl, cmdOpts) => {
|
|
12
|
+
const opts = program.opts();
|
|
13
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
14
|
+
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
|
15
|
+
const tweetId = ctx.extractTweetId(tweetIdOrUrl);
|
|
16
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
17
|
+
for (const warning of warnings) {
|
|
18
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
19
|
+
}
|
|
20
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
21
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
|
25
|
+
const includeRaw = cmdOpts.jsonFull ?? false;
|
|
26
|
+
const result = await client.getTweet(tweetId, { includeRaw });
|
|
27
|
+
if (result.success && result.tweet) {
|
|
28
|
+
if (cmdOpts.json || cmdOpts.jsonFull) {
|
|
29
|
+
console.log(JSON.stringify(result.tweet, null, 2));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
ctx.printTweets([result.tweet], { showSeparator: false });
|
|
33
|
+
console.log(formatStatsLine(result.tweet, ctx.getOutput()));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
console.error(`${ctx.p('err')}Failed to read tweet: ${result.error}`);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
program
|
|
42
|
+
.command('replies')
|
|
43
|
+
.description('List replies to a tweet (by ID or URL)')
|
|
44
|
+
.argument('<tweet-id-or-url>', 'Tweet ID or URL')
|
|
45
|
+
.option('--all', 'Fetch all replies (paged)')
|
|
46
|
+
.option('--max-pages <number>', 'Fetch N pages (implies pagination)')
|
|
47
|
+
.option('--delay <ms>', 'Delay in ms between page fetches', '1000')
|
|
48
|
+
.option('--cursor <string>', 'Resume pagination from a cursor')
|
|
49
|
+
.option('--json', 'Output as JSON')
|
|
50
|
+
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
|
51
|
+
.action(async (tweetIdOrUrl, cmdOpts) => {
|
|
52
|
+
const opts = program.opts();
|
|
53
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
54
|
+
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
|
55
|
+
const tweetId = ctx.extractTweetId(tweetIdOrUrl);
|
|
56
|
+
const pagination = parsePaginationFlags(cmdOpts, { maxPagesImpliesPagination: true, includeDelay: true });
|
|
57
|
+
if (!pagination.ok) {
|
|
58
|
+
console.error(`${ctx.p('err')}${pagination.error}`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
62
|
+
for (const warning of warnings) {
|
|
63
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
64
|
+
}
|
|
65
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
66
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
|
70
|
+
const includeRaw = cmdOpts.jsonFull ?? false;
|
|
71
|
+
const result = pagination.usePagination
|
|
72
|
+
? await client.getRepliesPaged(tweetId, {
|
|
73
|
+
includeRaw,
|
|
74
|
+
maxPages: pagination.maxPages,
|
|
75
|
+
cursor: pagination.cursor,
|
|
76
|
+
pageDelayMs: pagination.pageDelayMs,
|
|
77
|
+
})
|
|
78
|
+
: await client.getReplies(tweetId, { includeRaw });
|
|
79
|
+
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
|
80
|
+
if (result.tweets) {
|
|
81
|
+
ctx.printTweetsResult(result, {
|
|
82
|
+
json: isJson,
|
|
83
|
+
usePagination: pagination.usePagination,
|
|
84
|
+
emptyMessage: 'No replies found.',
|
|
85
|
+
});
|
|
86
|
+
// Show pagination hint if there's more
|
|
87
|
+
if (result.nextCursor && !isJson) {
|
|
88
|
+
console.error(`${ctx.p('info')}More replies available. Use --cursor "${result.nextCursor}" to continue.`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (!result.success) {
|
|
92
|
+
console.error(`${ctx.p('err')}Failed to fetch replies: ${result.error}`);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
program
|
|
97
|
+
.command('thread')
|
|
98
|
+
.description('Show the full conversation thread containing the tweet')
|
|
99
|
+
.argument('<tweet-id-or-url>', 'Tweet ID or URL')
|
|
100
|
+
.option('--all', 'Fetch all thread tweets (paged)')
|
|
101
|
+
.option('--max-pages <number>', 'Fetch N pages (implies pagination)')
|
|
102
|
+
.option('--delay <ms>', 'Delay in ms between page fetches', '1000')
|
|
103
|
+
.option('--cursor <string>', 'Resume pagination from a cursor')
|
|
104
|
+
.option('--json', 'Output as JSON')
|
|
105
|
+
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
|
106
|
+
.action(async (tweetIdOrUrl, cmdOpts) => {
|
|
107
|
+
const opts = program.opts();
|
|
108
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
109
|
+
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
|
110
|
+
const tweetId = ctx.extractTweetId(tweetIdOrUrl);
|
|
111
|
+
const pagination = parsePaginationFlags(cmdOpts, { maxPagesImpliesPagination: true, includeDelay: true });
|
|
112
|
+
if (!pagination.ok) {
|
|
113
|
+
console.error(`${ctx.p('err')}${pagination.error}`);
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
117
|
+
for (const warning of warnings) {
|
|
118
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
119
|
+
}
|
|
120
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
121
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
|
125
|
+
const includeRaw = cmdOpts.jsonFull ?? false;
|
|
126
|
+
const result = pagination.usePagination
|
|
127
|
+
? await client.getThreadPaged(tweetId, {
|
|
128
|
+
includeRaw,
|
|
129
|
+
maxPages: pagination.maxPages,
|
|
130
|
+
cursor: pagination.cursor,
|
|
131
|
+
pageDelayMs: pagination.pageDelayMs,
|
|
132
|
+
})
|
|
133
|
+
: await client.getThread(tweetId, { includeRaw });
|
|
134
|
+
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
|
135
|
+
if (result.tweets) {
|
|
136
|
+
ctx.printTweetsResult(result, {
|
|
137
|
+
json: isJson,
|
|
138
|
+
usePagination: pagination.usePagination,
|
|
139
|
+
emptyMessage: 'No thread tweets found.',
|
|
140
|
+
});
|
|
141
|
+
// Show pagination hint if there's more
|
|
142
|
+
if (result.nextCursor && !isJson) {
|
|
143
|
+
console.error(`${ctx.p('info')}More thread tweets available. Use --cursor "${result.nextCursor}" to continue.`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (!result.success) {
|
|
147
|
+
console.error(`${ctx.p('err')}Failed to fetch thread: ${result.error}`);
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=read.js.map
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { parsePaginationFlags } from '../cli/pagination.js';
|
|
2
|
+
import { mentionsQueryFromUserOption, normalizeHandle } from '../lib/normalize-handle.js';
|
|
3
|
+
import { TwitterClient } from '../lib/twitter-client.js';
|
|
4
|
+
export function registerSearchCommands(program, ctx) {
|
|
5
|
+
program
|
|
6
|
+
.command('search')
|
|
7
|
+
.description('Search for tweets')
|
|
8
|
+
.argument('<query>', 'Search query (e.g., "@clawdbot" or "from:clawdbot")')
|
|
9
|
+
.option('-n, --count <number>', 'Number of tweets to fetch', '10')
|
|
10
|
+
.option('--all', 'Fetch all search results (paged)')
|
|
11
|
+
.option('--max-pages <number>', 'Stop after N pages when using --all')
|
|
12
|
+
.option('--cursor <string>', 'Resume pagination from a cursor')
|
|
13
|
+
.option('--json', 'Output as JSON')
|
|
14
|
+
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
|
15
|
+
.action(async (query, cmdOpts) => {
|
|
16
|
+
const opts = program.opts();
|
|
17
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
18
|
+
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
|
19
|
+
const count = Number.parseInt(cmdOpts.count || '10', 10);
|
|
20
|
+
const pagination = parsePaginationFlags(cmdOpts);
|
|
21
|
+
if (!pagination.ok) {
|
|
22
|
+
console.error(`${ctx.p('err')}${pagination.error}`);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
const maxPages = pagination.maxPages;
|
|
26
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
27
|
+
for (const warning of warnings) {
|
|
28
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
29
|
+
}
|
|
30
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
31
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
const usePagination = pagination.usePagination;
|
|
35
|
+
if (maxPages !== undefined && !usePagination) {
|
|
36
|
+
console.error(`${ctx.p('err')}--max-pages requires --all or --cursor.`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
if (!usePagination && (!Number.isFinite(count) || count <= 0)) {
|
|
40
|
+
console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
|
44
|
+
const includeRaw = cmdOpts.jsonFull ?? false;
|
|
45
|
+
const searchOptions = { includeRaw };
|
|
46
|
+
const paginationOptions = { includeRaw, maxPages, cursor: pagination.cursor };
|
|
47
|
+
const result = usePagination
|
|
48
|
+
? await client.getAllSearchResults(query, paginationOptions)
|
|
49
|
+
: await client.search(query, count, searchOptions);
|
|
50
|
+
if (result.success) {
|
|
51
|
+
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
|
52
|
+
ctx.printTweetsResult(result, {
|
|
53
|
+
json: isJson,
|
|
54
|
+
usePagination: Boolean(usePagination),
|
|
55
|
+
emptyMessage: 'No tweets found.',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
console.error(`${ctx.p('err')}Search failed: ${result.error}`);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
program
|
|
64
|
+
.command('mentions')
|
|
65
|
+
.description('Find tweets mentioning a user (defaults to current user)')
|
|
66
|
+
.option('-u, --user <handle>', 'User handle (e.g. @steipete)')
|
|
67
|
+
.option('-n, --count <number>', 'Number of tweets to fetch', '10')
|
|
68
|
+
.option('--json', 'Output as JSON')
|
|
69
|
+
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
|
70
|
+
.action(async (cmdOpts) => {
|
|
71
|
+
const opts = program.opts();
|
|
72
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
73
|
+
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
|
74
|
+
const count = Number.parseInt(cmdOpts.count || '10', 10);
|
|
75
|
+
const fromUserOpt = mentionsQueryFromUserOption(cmdOpts.user);
|
|
76
|
+
if (fromUserOpt.error) {
|
|
77
|
+
console.error(`${ctx.p('err')}${fromUserOpt.error}`);
|
|
78
|
+
process.exit(2);
|
|
79
|
+
}
|
|
80
|
+
let query = fromUserOpt.query;
|
|
81
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
82
|
+
for (const warning of warnings) {
|
|
83
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
84
|
+
}
|
|
85
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
86
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
|
90
|
+
if (!query) {
|
|
91
|
+
const who = await client.getCurrentUser();
|
|
92
|
+
const handle = normalizeHandle(who.user?.username);
|
|
93
|
+
if (handle) {
|
|
94
|
+
query = `@${handle}`;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
console.error(`${ctx.p('err')}Could not determine current user (${who.error ?? 'Unknown error'}). Use --user <handle>.`);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const includeRaw = cmdOpts.jsonFull ?? false;
|
|
102
|
+
const result = await client.search(query, count, { includeRaw });
|
|
103
|
+
if (result.success) {
|
|
104
|
+
ctx.printTweets(result.tweets, {
|
|
105
|
+
json: cmdOpts.json || cmdOpts.jsonFull,
|
|
106
|
+
emptyMessage: 'No mentions found.',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
console.error(`${ctx.p('err')}Failed to fetch mentions: ${result.error}`);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { TwitterClient } from '../lib/twitter-client.js';
|
|
2
|
+
export function registerUnbookmarkCommand(program, ctx) {
|
|
3
|
+
program
|
|
4
|
+
.command('unbookmark')
|
|
5
|
+
.description('Remove bookmarked tweets')
|
|
6
|
+
.argument('<tweet-id-or-url...>', 'Tweet IDs or URLs to remove from bookmarks')
|
|
7
|
+
.action(async (tweetIdOrUrls) => {
|
|
8
|
+
const opts = program.opts();
|
|
9
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
10
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
11
|
+
for (const warning of warnings) {
|
|
12
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
13
|
+
}
|
|
14
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
15
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
const client = new TwitterClient({ cookies, timeoutMs });
|
|
19
|
+
let failures = 0;
|
|
20
|
+
for (const input of tweetIdOrUrls) {
|
|
21
|
+
const tweetId = ctx.extractTweetId(input);
|
|
22
|
+
const result = await client.unbookmark(tweetId);
|
|
23
|
+
if (result.success) {
|
|
24
|
+
console.log(`${ctx.p('ok')}Removed bookmark for ${tweetId}`);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
failures += 1;
|
|
28
|
+
console.error(`${ctx.p('err')}Failed to remove bookmark for ${tweetId}: ${result.error}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (failures > 0) {
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=unbookmark.js.map
|