@aisa-one/cli 0.1.7 → 0.2.0

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.
@@ -1,14 +1,138 @@
1
- export declare function tweetAction(text: string, options: {
2
- replyTo?: string;
1
+ export declare function twitterUserAction(username: string, options: {
2
+ raw?: boolean;
3
+ }): Promise<void>;
4
+ export declare function twitterUserAboutAction(username: string, options: {
5
+ raw?: boolean;
6
+ }): Promise<void>;
7
+ export declare function twitterBatchUsersAction(ids: string, options: {
8
+ raw?: boolean;
9
+ }): Promise<void>;
10
+ export declare function twitterUserTweetsAction(username: string, options: {
3
11
  raw?: boolean;
12
+ cursor?: string;
13
+ }): Promise<void>;
14
+ export declare function twitterMentionsAction(username: string, options: {
15
+ raw?: boolean;
16
+ cursor?: string;
17
+ }): Promise<void>;
18
+ export declare function twitterFollowersAction(username: string, options: {
19
+ raw?: boolean;
20
+ cursor?: string;
21
+ }): Promise<void>;
22
+ export declare function twitterFollowingAction(username: string, options: {
23
+ raw?: boolean;
24
+ cursor?: string;
25
+ }): Promise<void>;
26
+ export declare function twitterVerifiedFollowersAction(userId: string, options: {
27
+ raw?: boolean;
28
+ cursor?: string;
29
+ }): Promise<void>;
30
+ export declare function twitterCheckFollowAction(source: string, target: string, options: {
31
+ raw?: boolean;
32
+ }): Promise<void>;
33
+ export declare function twitterUserSearchAction(query: string, options: {
34
+ raw?: boolean;
35
+ cursor?: string;
4
36
  }): Promise<void>;
5
37
  export declare function twitterSearchAction(query: string, options: {
6
38
  limit?: string;
39
+ type?: string;
7
40
  raw?: boolean;
41
+ cursor?: string;
8
42
  }): Promise<void>;
9
- export declare function twitterUserAction(username: string, options: {
43
+ export declare function twitterDetailAction(ids: string, options: {
44
+ raw?: boolean;
45
+ }): Promise<void>;
46
+ export declare function twitterRepliesAction(tweetId: string, options: {
47
+ raw?: boolean;
48
+ cursor?: string;
49
+ }): Promise<void>;
50
+ export declare function twitterQuotesAction(tweetId: string, options: {
51
+ raw?: boolean;
52
+ cursor?: string;
53
+ }): Promise<void>;
54
+ export declare function twitterRetweetersAction(tweetId: string, options: {
55
+ raw?: boolean;
56
+ cursor?: string;
57
+ }): Promise<void>;
58
+ export declare function twitterThreadAction(tweetId: string, options: {
59
+ raw?: boolean;
60
+ cursor?: string;
61
+ }): Promise<void>;
62
+ export declare function twitterArticleAction(tweetId: string, options: {
10
63
  raw?: boolean;
11
64
  }): Promise<void>;
12
65
  export declare function twitterTrendsAction(options: {
66
+ woeid?: string;
67
+ count?: string;
68
+ raw?: boolean;
69
+ }): Promise<void>;
70
+ export declare function twitterListMembersAction(listId: string, options: {
71
+ raw?: boolean;
72
+ cursor?: string;
73
+ }): Promise<void>;
74
+ export declare function twitterListFollowersAction(listId: string, options: {
75
+ raw?: boolean;
76
+ cursor?: string;
77
+ }): Promise<void>;
78
+ export declare function twitterCommunityInfoAction(communityId: string, options: {
79
+ raw?: boolean;
80
+ }): Promise<void>;
81
+ export declare function twitterCommunityMembersAction(communityId: string, options: {
82
+ raw?: boolean;
83
+ cursor?: string;
84
+ }): Promise<void>;
85
+ export declare function twitterCommunityModsAction(communityId: string, options: {
86
+ raw?: boolean;
87
+ cursor?: string;
88
+ }): Promise<void>;
89
+ export declare function twitterCommunityTweetsAction(communityId: string, options: {
90
+ raw?: boolean;
91
+ cursor?: string;
92
+ }): Promise<void>;
93
+ export declare function twitterCommunitySearchAction(query: string, options: {
94
+ raw?: boolean;
95
+ cursor?: string;
96
+ }): Promise<void>;
97
+ export declare function twitterSpaceAction(spaceId: string, options: {
98
+ raw?: boolean;
99
+ }): Promise<void>;
100
+ export declare function twitterLoginAction(options: {
101
+ username?: string;
102
+ email?: string;
103
+ password?: string;
104
+ proxy?: string;
105
+ totp?: string;
106
+ cookies?: string;
107
+ raw?: boolean;
108
+ }): Promise<void>;
109
+ export declare function twitterLogoutAction(): void;
110
+ export declare function tweetAction(text: string, options: {
111
+ replyTo?: string;
112
+ mediaIds?: string;
113
+ raw?: boolean;
114
+ }): Promise<void>;
115
+ export declare function twitterLikeAction(tweetId: string, options: {
116
+ raw?: boolean;
117
+ }): Promise<void>;
118
+ export declare function twitterUnlikeAction(tweetId: string, options: {
119
+ raw?: boolean;
120
+ }): Promise<void>;
121
+ export declare function twitterRetweetAction(tweetId: string, options: {
122
+ raw?: boolean;
123
+ }): Promise<void>;
124
+ export declare function twitterDeleteAction(tweetId: string, options: {
125
+ raw?: boolean;
126
+ }): Promise<void>;
127
+ export declare function twitterFollowAction(userId: string, options: {
128
+ raw?: boolean;
129
+ }): Promise<void>;
130
+ export declare function twitterUnfollowAction(userId: string, options: {
131
+ raw?: boolean;
132
+ }): Promise<void>;
133
+ export declare function twitterUploadMediaAction(filePath: string, options: {
134
+ raw?: boolean;
135
+ }): Promise<void>;
136
+ export declare function twitterDmAction(userId: string, text: string, options: {
13
137
  raw?: boolean;
14
138
  }): Promise<void>;
@@ -1,29 +1,34 @@
1
1
  import ora from "ora";
2
2
  import chalk from "chalk";
3
- import { requireApiKey } from "../config.js";
3
+ import fetch from "node-fetch";
4
+ import { requireApiKey, getConfig, setConfig } from "../config.js";
4
5
  import { apiRequest } from "../api.js";
5
- import { error, formatJson } from "../utils/display.js";
6
- export async function tweetAction(text, options) {
6
+ import { APIS_BASE_URL } from "../constants.js";
7
+ import { error, success, formatJson } from "../utils/display.js";
8
+ function requireCookies() {
9
+ const cookies = getConfig("twitterCookies");
10
+ const proxy = getConfig("twitterProxy");
11
+ if (!cookies) {
12
+ error('No Twitter cookies configured. Run "aisa twitter login" or "aisa config set twitterCookies <value>".');
13
+ process.exit(1);
14
+ }
15
+ if (!proxy) {
16
+ error('No Twitter proxy configured. Run "aisa config set twitterProxy <value>".');
17
+ process.exit(1);
18
+ }
19
+ return { login_cookies: cookies, proxy };
20
+ }
21
+ /** Simple GET against a twitter read endpoint. */
22
+ async function twitterGet(endpoint, query, label, options) {
7
23
  const key = requireApiKey();
8
- const spinner = ora("Posting tweet...").start();
9
- const body = { tweet_text: text };
10
- if (options.replyTo)
11
- body.reply_to_tweet_id = options.replyTo;
12
- // Note: create_tweet_v2 requires login_cookies and proxy
13
- // This will fail without those - provide a helpful message
14
- const res = await apiRequest(key, "twitter/create_tweet_v2", {
15
- method: "POST",
16
- body,
24
+ const spinner = ora(label).start();
25
+ const res = await apiRequest(key, endpoint, {
26
+ query,
17
27
  domain: true,
18
28
  });
19
29
  if (!res.success) {
20
- spinner.fail("Failed to post tweet");
21
- if (res.error?.includes("login_cookies")) {
22
- error("Tweet creation requires Twitter login cookies. See: https://docs.aisa.one");
23
- }
24
- else {
25
- error(res.error || "Unknown error");
26
- }
30
+ spinner.fail(label.replace(/\.{3}$/, " failed"));
31
+ error(res.error || "Unknown error");
27
32
  return;
28
33
  }
29
34
  spinner.stop();
@@ -31,22 +36,21 @@ export async function tweetAction(text, options) {
31
36
  console.log(JSON.stringify(res.data));
32
37
  }
33
38
  else {
34
- console.log(chalk.green("Tweet posted!"));
35
39
  console.log(formatJson(res.data));
36
40
  }
37
41
  }
38
- export async function twitterSearchAction(query, options) {
42
+ /** POST against a twitter write endpoint (auto-injects cookies/proxy). */
43
+ async function twitterWrite(endpoint, body, label, options) {
39
44
  const key = requireApiKey();
40
- const spinner = ora(`Searching tweets: "${query}"...`).start();
41
- const q = { query, queryType: "Latest" };
42
- if (options.limit)
43
- q.cursor = "";
44
- const res = await apiRequest(key, "twitter/tweet/advanced_search", {
45
- query: q,
45
+ const auth = requireCookies();
46
+ const spinner = ora(label).start();
47
+ const res = await apiRequest(key, endpoint, {
48
+ method: "POST",
49
+ body: { ...auth, ...body },
46
50
  domain: true,
47
51
  });
48
52
  if (!res.success) {
49
- spinner.fail("Twitter search failed");
53
+ spinner.fail(label.replace(/\.{3}$/, " failed"));
50
54
  error(res.error || "Unknown error");
51
55
  return;
52
56
  }
@@ -58,6 +62,7 @@ export async function twitterSearchAction(query, options) {
58
62
  console.log(formatJson(res.data));
59
63
  }
60
64
  }
65
+ // ── Read: User Endpoints ─────────────────────────────────────────────────────
61
66
  export async function twitterUserAction(username, options) {
62
67
  const key = requireApiKey();
63
68
  const spinner = ora(`Fetching @${username}...`).start();
@@ -92,24 +97,279 @@ export async function twitterUserAction(username, options) {
92
97
  }
93
98
  }
94
99
  }
100
+ export async function twitterUserAboutAction(username, options) {
101
+ return twitterGet("twitter/user_about", { userName: username }, `Fetching about @${username}...`, options);
102
+ }
103
+ export async function twitterBatchUsersAction(ids, options) {
104
+ return twitterGet("twitter/user/batch_info_by_ids", { userIds: ids }, "Fetching users...", options);
105
+ }
106
+ export async function twitterUserTweetsAction(username, options) {
107
+ const q = { userName: username };
108
+ if (options.cursor)
109
+ q.cursor = options.cursor;
110
+ return twitterGet("twitter/user/last_tweets", q, `Fetching tweets by @${username}...`, options);
111
+ }
112
+ export async function twitterMentionsAction(username, options) {
113
+ const q = { userName: username };
114
+ if (options.cursor)
115
+ q.cursor = options.cursor;
116
+ return twitterGet("twitter/user/mentions", q, `Fetching mentions of @${username}...`, options);
117
+ }
118
+ export async function twitterFollowersAction(username, options) {
119
+ const q = { userName: username };
120
+ if (options.cursor)
121
+ q.cursor = options.cursor;
122
+ return twitterGet("twitter/user/followers", q, `Fetching followers of @${username}...`, options);
123
+ }
124
+ export async function twitterFollowingAction(username, options) {
125
+ const q = { userName: username };
126
+ if (options.cursor)
127
+ q.cursor = options.cursor;
128
+ return twitterGet("twitter/user/followings", q, `Fetching following of @${username}...`, options);
129
+ }
130
+ export async function twitterVerifiedFollowersAction(userId, options) {
131
+ const q = { user_id: userId };
132
+ if (options.cursor)
133
+ q.cursor = options.cursor;
134
+ return twitterGet("twitter/user/verifiedFollowers", q, "Fetching verified followers...", options);
135
+ }
136
+ export async function twitterCheckFollowAction(source, target, options) {
137
+ return twitterGet("twitter/user/check_follow_relationship", { source_user_name: source, target_user_name: target }, `Checking follow relationship @${source} → @${target}...`, options);
138
+ }
139
+ export async function twitterUserSearchAction(query, options) {
140
+ const q = { query };
141
+ if (options.cursor)
142
+ q.cursor = options.cursor;
143
+ return twitterGet("twitter/user/search", q, `Searching users: "${query}"...`, options);
144
+ }
145
+ // ── Read: Tweet Endpoints ────────────────────────────────────────────────────
146
+ export async function twitterSearchAction(query, options) {
147
+ const q = {
148
+ query,
149
+ queryType: options.type === "top" ? "Top" : "Latest",
150
+ };
151
+ if (options.cursor)
152
+ q.cursor = options.cursor;
153
+ if (options.limit)
154
+ q.count = options.limit;
155
+ return twitterGet("twitter/tweet/advanced_search", q, `Searching tweets: "${query}"...`, options);
156
+ }
157
+ export async function twitterDetailAction(ids, options) {
158
+ return twitterGet("twitter/tweets", { tweet_ids: ids }, "Fetching tweet details...", options);
159
+ }
160
+ export async function twitterRepliesAction(tweetId, options) {
161
+ const q = { tweetId };
162
+ if (options.cursor)
163
+ q.cursor = options.cursor;
164
+ return twitterGet("twitter/tweet/replies", q, "Fetching replies...", options);
165
+ }
166
+ export async function twitterQuotesAction(tweetId, options) {
167
+ const q = { tweetId };
168
+ if (options.cursor)
169
+ q.cursor = options.cursor;
170
+ return twitterGet("twitter/tweet/quotes", q, "Fetching quotes...", options);
171
+ }
172
+ export async function twitterRetweetersAction(tweetId, options) {
173
+ const q = { tweetId };
174
+ if (options.cursor)
175
+ q.cursor = options.cursor;
176
+ return twitterGet("twitter/tweet/retweeters", q, "Fetching retweeters...", options);
177
+ }
178
+ export async function twitterThreadAction(tweetId, options) {
179
+ const q = { tweetId };
180
+ if (options.cursor)
181
+ q.cursor = options.cursor;
182
+ return twitterGet("twitter/tweet/thread_context", q, "Fetching thread...", options);
183
+ }
184
+ export async function twitterArticleAction(tweetId, options) {
185
+ return twitterGet("twitter/article", { tweet_id: tweetId }, "Fetching article...", options);
186
+ }
187
+ // ── Read: Trends ─────────────────────────────────────────────────────────────
95
188
  export async function twitterTrendsAction(options) {
189
+ const q = {
190
+ woeid: options.woeid || "1",
191
+ count: options.count || "30",
192
+ };
193
+ return twitterGet("twitter/trends", q, "Fetching trends...", options);
194
+ }
195
+ // ── Read: Lists ──────────────────────────────────────────────────────────────
196
+ export async function twitterListMembersAction(listId, options) {
197
+ const q = { list_id: listId };
198
+ if (options.cursor)
199
+ q.cursor = options.cursor;
200
+ return twitterGet("twitter/list/members", q, "Fetching list members...", options);
201
+ }
202
+ export async function twitterListFollowersAction(listId, options) {
203
+ const q = { list_id: listId };
204
+ if (options.cursor)
205
+ q.cursor = options.cursor;
206
+ return twitterGet("twitter/list/followers", q, "Fetching list followers...", options);
207
+ }
208
+ // ── Read: Communities ────────────────────────────────────────────────────────
209
+ export async function twitterCommunityInfoAction(communityId, options) {
210
+ return twitterGet("twitter/community/info", { community_id: communityId }, "Fetching community info...", options);
211
+ }
212
+ export async function twitterCommunityMembersAction(communityId, options) {
213
+ const q = { community_id: communityId };
214
+ if (options.cursor)
215
+ q.cursor = options.cursor;
216
+ return twitterGet("twitter/community/members", q, "Fetching community members...", options);
217
+ }
218
+ export async function twitterCommunityModsAction(communityId, options) {
219
+ const q = { community_id: communityId };
220
+ if (options.cursor)
221
+ q.cursor = options.cursor;
222
+ return twitterGet("twitter/community/moderators", q, "Fetching community moderators...", options);
223
+ }
224
+ export async function twitterCommunityTweetsAction(communityId, options) {
225
+ const q = { community_id: communityId };
226
+ if (options.cursor)
227
+ q.cursor = options.cursor;
228
+ return twitterGet("twitter/community/tweets", q, "Fetching community tweets...", options);
229
+ }
230
+ export async function twitterCommunitySearchAction(query, options) {
231
+ const q = { query };
232
+ if (options.cursor)
233
+ q.cursor = options.cursor;
234
+ return twitterGet("twitter/community/get_tweets_from_all_community", q, `Searching community tweets: "${query}"...`, options);
235
+ }
236
+ // ── Read: Spaces ─────────────────────────────────────────────────────────────
237
+ export async function twitterSpaceAction(spaceId, options) {
238
+ return twitterGet("twitter/spaces/detail", { space_id: spaceId }, "Fetching space details...", options);
239
+ }
240
+ // ── Write: Login / Logout ────────────────────────────────────────────────────
241
+ export async function twitterLoginAction(options) {
242
+ // Direct cookie import mode
243
+ if (options.cookies) {
244
+ if (!options.proxy) {
245
+ error("--proxy is required when setting cookies directly.");
246
+ process.exit(1);
247
+ }
248
+ setConfig("twitterCookies", options.cookies);
249
+ setConfig("twitterProxy", options.proxy);
250
+ success("Twitter cookies and proxy saved.");
251
+ return;
252
+ }
253
+ // Login via API
254
+ if (!options.username || !options.password || !options.proxy) {
255
+ error("Required: --username, --password, --proxy (and optionally --email, --totp)");
256
+ process.exit(1);
257
+ }
96
258
  const key = requireApiKey();
97
- const spinner = ora("Fetching trends...").start();
98
- // woeid 1 = worldwide
99
- const res = await apiRequest(key, "twitter/trends", {
100
- query: { woeid: "1", count: "30" },
101
- domain: true,
102
- });
259
+ const spinner = ora("Logging in to Twitter...").start();
260
+ const body = {
261
+ user_name: options.username,
262
+ password: options.password,
263
+ proxy: options.proxy,
264
+ };
265
+ if (options.email)
266
+ body.email = options.email;
267
+ if (options.totp)
268
+ body.totp_secret = options.totp;
269
+ const res = await apiRequest(key, "twitter/user_login_v2", { method: "POST", body, domain: true });
103
270
  if (!res.success) {
104
- spinner.fail("Failed to fetch trends");
271
+ spinner.fail("Twitter login failed");
105
272
  error(res.error || "Unknown error");
106
273
  return;
107
274
  }
108
275
  spinner.stop();
276
+ // Extract and store cookies
277
+ const data = res.data;
278
+ const cookies = data?.login_cookies ||
279
+ data?.data?.login_cookies;
280
+ if (cookies) {
281
+ setConfig("twitterCookies", cookies);
282
+ setConfig("twitterProxy", options.proxy);
283
+ success("Logged in! Cookies and proxy saved.");
284
+ }
285
+ else {
286
+ console.log(chalk.yellow("Login response did not contain login_cookies. Raw response:"));
287
+ console.log(formatJson(res.data));
288
+ }
109
289
  if (options.raw) {
110
290
  console.log(JSON.stringify(res.data));
111
291
  }
292
+ }
293
+ export function twitterLogoutAction() {
294
+ setConfig("twitterCookies", "");
295
+ setConfig("twitterProxy", "");
296
+ success("Twitter cookies and proxy cleared.");
297
+ }
298
+ // ── Write: Tweet ─────────────────────────────────────────────────────────────
299
+ export async function tweetAction(text, options) {
300
+ const body = { tweet_text: text };
301
+ if (options.replyTo)
302
+ body.reply_to_tweet_id = options.replyTo;
303
+ if (options.mediaIds)
304
+ body.media_ids = options.mediaIds.split(",");
305
+ return twitterWrite("twitter/create_tweet_v2", body, "Posting tweet...", options);
306
+ }
307
+ // ── Write: Like / Unlike ─────────────────────────────────────────────────────
308
+ export async function twitterLikeAction(tweetId, options) {
309
+ return twitterWrite("twitter/like_tweet_v2", { tweet_id: tweetId }, "Liking tweet...", options);
310
+ }
311
+ export async function twitterUnlikeAction(tweetId, options) {
312
+ return twitterWrite("twitter/unlike_tweet_v2", { tweet_id: tweetId }, "Unliking tweet...", options);
313
+ }
314
+ // ── Write: Retweet ───────────────────────────────────────────────────────────
315
+ export async function twitterRetweetAction(tweetId, options) {
316
+ return twitterWrite("twitter/retweet_tweet_v2", { tweet_id: tweetId }, "Retweeting...", options);
317
+ }
318
+ // ── Write: Delete ────────────────────────────────────────────────────────────
319
+ export async function twitterDeleteAction(tweetId, options) {
320
+ return twitterWrite("twitter/delete_tweet_v2", { tweet_id: tweetId }, "Deleting tweet...", options);
321
+ }
322
+ // ── Write: Follow / Unfollow ─────────────────────────────────────────────────
323
+ export async function twitterFollowAction(userId, options) {
324
+ return twitterWrite("twitter/follow_user_v2", { user_id: userId }, "Following user...", options);
325
+ }
326
+ export async function twitterUnfollowAction(userId, options) {
327
+ return twitterWrite("twitter/unfollow_user_v2", { user_id: userId }, "Unfollowing user...", options);
328
+ }
329
+ // ── Write: Upload Media ──────────────────────────────────────────────────────
330
+ export async function twitterUploadMediaAction(filePath, options) {
331
+ const key = requireApiKey();
332
+ const auth = requireCookies();
333
+ const spinner = ora("Uploading media...").start();
334
+ let formData;
335
+ try {
336
+ const { FormData: NFFormData, fileFromSync } = await import("node-fetch");
337
+ formData = new NFFormData();
338
+ formData.append("file", fileFromSync(filePath));
339
+ }
340
+ catch {
341
+ spinner.fail("Failed to read file");
342
+ error(`Could not read file: ${filePath}`);
343
+ return;
344
+ }
345
+ formData.append("login_cookies", auth.login_cookies);
346
+ formData.append("proxy", auth.proxy);
347
+ const url = `${APIS_BASE_URL}/twitter/upload_media_v2`;
348
+ const res = await fetch(url, {
349
+ method: "POST",
350
+ headers: {
351
+ Authorization: `Bearer ${key}`,
352
+ "x-aisa-source": "cli",
353
+ },
354
+ body: formData,
355
+ });
356
+ if (!res.ok) {
357
+ spinner.fail("Upload failed");
358
+ const text = await res.text();
359
+ error(`${res.status}: ${text}`);
360
+ return;
361
+ }
362
+ const data = await res.json();
363
+ spinner.stop();
364
+ if (options.raw) {
365
+ console.log(JSON.stringify(data));
366
+ }
112
367
  else {
113
- console.log(formatJson(res.data));
368
+ success("Media uploaded!");
369
+ console.log(formatJson(data));
114
370
  }
115
371
  }
372
+ // ── Write: Direct Message ────────────────────────────────────────────────────
373
+ export async function twitterDmAction(userId, text, options) {
374
+ return twitterWrite("twitter/send_dm_to_user", { user_id: userId, text }, "Sending DM...", options);
375
+ }
package/dist/config.js CHANGED
@@ -7,6 +7,8 @@ const config = new Conf({
7
7
  defaultModel: { type: "string", default: "gpt-4.1" },
8
8
  baseUrl: { type: "string", default: "https://api.aisa.one/v1" },
9
9
  outputFormat: { type: "string", default: "text" },
10
+ twitterCookies: { type: "string", default: "" },
11
+ twitterProxy: { type: "string", default: "" },
10
12
  },
11
13
  });
12
14
  export function getApiKey() {
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "0.1.7";
1
+ export declare const VERSION = "0.2.0";
2
2
  export declare const BASE_URL = "https://api.aisa.one";
3
3
  export declare const CLI_BASE_URL = "https://api.aisa.one/v1";
4
4
  export declare const APIS_BASE_URL = "https://api.aisa.one/apis/v1";
package/dist/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const VERSION = "0.1.7";
1
+ export const VERSION = "0.2.0";
2
2
  export const BASE_URL = "https://api.aisa.one";
3
3
  export const CLI_BASE_URL = `${BASE_URL}/v1`;
4
4
  export const APIS_BASE_URL = `${BASE_URL}/apis/v1`;