-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathtypes.ts
138 lines (117 loc) · 3.27 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { type Role } from 'chatgpt'
import { type Client as TwitterClient } from 'twitter-api-sdk'
import { type DirectMessageCreateV1, type TwitterApiv1 } from 'twitter-api-v2'
import { type AsyncReturnType } from 'type-fest'
export { TwitterClient }
export { TwitterApiv1 as TwitterClientV1 }
export { DirectMessageCreateV1 as TwitterDMV1 }
export interface Config {
accessToken?: string
refreshToken?: string
sinceMentionId?: string
}
export type ChatGPTInteractionType = 'tweet' | 'dm'
export interface ChatGPTInteraction {
role?: Role
type?: ChatGPTInteractionType
prompt: string
promptTweetId: string
promptUserId: string
promptUsername: string
promptUrl?: string
promptLikes?: number
promptRetweets?: number
promptReplies?: number
promptDate?: string
promptLanguage?: string
promptLanguageScore?: number
response?: string
responseTweetIds?: string[]
responseMediaId?: string
responseUrl?: string
responseLikes?: number
responseRetweets?: number
responseReplies?: number
responseDate?: string
chatgptConversationId?: string
chatgptParentMessageId?: string
chatgptMessageId?: string
chatgptAccountId?: string
error?: string
isErrorFinal?: boolean
priorityScore?: number
numFollowers?: number
isReply?: boolean
}
export interface ChatGPTSession {
interactions: ChatGPTInteraction[]
isRateLimited: boolean
isRateLimitedTwitter: boolean
isExpiredAuth: boolean
isExpiredAuthTwitter: boolean
sinceMentionId?: string
hasAllOpenAIAccountsExpired?: boolean
}
export interface ChatGPTResponse {
response: string
conversationId?: string
messageId?: string
accountId?: string
}
type Unpacked<T> = T extends (infer U)[] ? U : T
export type Tweet = Unpacked<
AsyncReturnType<TwitterClient['tweets']['findTweetsById']>['data']
>
export type TwitterUser = AsyncReturnType<
TwitterClient['users']['findMyUser']
>['data']
export type CreatedTweet = AsyncReturnType<
TwitterClient['tweets']['createTweet']
>['data']
export type TweetsQueryOptions = Pick<
Parameters<TwitterClient['tweets']['findTweetsById']>[0],
'expansions' | 'tweet.fields' | 'user.fields'
>
export type TwitterUserIdMentionsQueryOptions = Parameters<
TwitterClient['tweets']['usersIdMentions']
>[1]
export type TweetMention = Partial<Tweet> & {
prompt?: string
numMentions?: number
priorityScore?: number
numFollowers?: number
promptUrl?: string
isReply?: boolean
}
export type TweetMentionBatch = {
mentions: TweetMention[]
users: Record<string, Partial<TwitterUser>>
tweets: Record<string, TweetMention>
minSinceMentionId: string
sinceMentionId: string
numMentionsPostponed: number
}
export type TweetMentionResult = {
mentions: TweetMention[]
users: Record<string, Partial<TwitterUser>>
tweets: Record<string, TweetMention>
sinceMentionId: string
}
export type ChatErrorType =
| 'unknown'
| 'timeout'
| 'twitter:auth'
| 'twitter:forbidden'
| 'twitter:rate-limit'
| 'chatgpt:pool:timeout'
| 'chatgpt:pool:rate-limit'
| 'chatgpt:pool:unavailable'
| 'chatgpt:pool:account-not-found'
| 'chatgpt:pool:account-on-cooldown'
| 'chatgpt:pool:no-accounts'
export class ChatError extends Error {
isFinal: boolean = false
type?: ChatErrorType = 'unknown'
accountId?: string
}
export type TweetMode = 'image' | 'thread'