@@ -3,10 +3,14 @@ import { z, ZodError } from "zod";
3
3
4
4
export const DEFAULT_MAX_TWEET_LENGTH = 280 ;
5
5
6
- const twitterUsernameSchema = z . string ( )
7
- . min ( 1 , 'An X/Twitter Username must be at least 1 characters long' )
8
- . max ( 15 , 'n X/Twitter Username cannot exceed 15 characters' )
9
- . regex ( / ^ [ A - Z a - z 0 - 9 _ ] * $ / , 'n X Username can only contain letters, numbers, and underscores' ) ;
6
+ const twitterUsernameSchema = z
7
+ . string ( )
8
+ . min ( 1 , "An X/Twitter Username must be at least 1 characters long" )
9
+ . max ( 15 , "An X/Twitter Username cannot exceed 15 characters" )
10
+ . regex (
11
+ / ^ [ A - Z a - z 0 - 9 _ ] * $ / ,
12
+ "An X Username can only contain letters, numbers, and underscores"
13
+ ) ;
10
14
11
15
/**
12
16
* This schema defines all required/optional environment settings,
@@ -75,7 +79,10 @@ function parseTargetUsers(targetUsersStr?: string | null): string[] {
75
79
. filter ( Boolean ) ;
76
80
}
77
81
78
- function safeParseInt ( value : string | undefined | null , defaultValue : number ) : number {
82
+ function safeParseInt (
83
+ value : string | undefined | null ,
84
+ defaultValue : number
85
+ ) : number {
79
86
if ( ! value ) return defaultValue ;
80
87
const parsed = parseInt ( value , 10 ) ;
81
88
return isNaN ( parsed ) ? defaultValue : Math . max ( 1 , parsed ) ;
@@ -90,13 +97,15 @@ function safeParseInt(value: string | undefined | null, defaultValue: number): n
90
97
91
98
// we also do a lot of typing/parsing here
92
99
// so we can do it once and only once per character
93
- export async function validateTwitterConfig ( runtime : IAgentRuntime ) : Promise < TwitterConfig > {
100
+ export async function validateTwitterConfig (
101
+ runtime : IAgentRuntime
102
+ ) : Promise < TwitterConfig > {
94
103
try {
95
104
const twitterConfig = {
96
105
TWITTER_DRY_RUN :
97
106
parseBooleanFromText (
98
107
runtime . getSetting ( "TWITTER_DRY_RUN" ) ||
99
- process . env . TWITTER_DRY_RUN
108
+ process . env . TWITTER_DRY_RUN
100
109
) ?? false , // parseBooleanFromText return null if "", map "" to false
101
110
102
111
TWITTER_USERNAME :
@@ -111,80 +120,84 @@ export async function validateTwitterConfig(runtime: IAgentRuntime): Promise<Twi
111
120
runtime . getSetting ( "TWITTER_EMAIL" ) ||
112
121
process . env . TWITTER_EMAIL ,
113
122
114
- MAX_TWEET_LENGTH : // number as string?
115
- safeParseInt (
116
- runtime . getSetting ( "MAX_TWEET_LENGTH" ) ||
123
+ // number as string?
124
+ MAX_TWEET_LENGTH : safeParseInt (
125
+ runtime . getSetting ( "MAX_TWEET_LENGTH" ) ||
117
126
process . env . MAX_TWEET_LENGTH ,
118
- DEFAULT_MAX_TWEET_LENGTH
119
- ) ,
127
+ DEFAULT_MAX_TWEET_LENGTH
128
+ ) ,
120
129
121
130
TWITTER_SEARCH_ENABLE :
122
131
parseBooleanFromText (
123
132
runtime . getSetting ( "TWITTER_SEARCH_ENABLE" ) ||
124
- process . env . TWITTER_SEARCH_ENABLE
133
+ process . env . TWITTER_SEARCH_ENABLE
125
134
) ?? false ,
126
135
127
- TWITTER_2FA_SECRET : // string passthru
136
+ // string passthru
137
+ TWITTER_2FA_SECRET :
128
138
runtime . getSetting ( "TWITTER_2FA_SECRET" ) ||
129
- process . env . TWITTER_2FA_SECRET || "" ,
139
+ process . env . TWITTER_2FA_SECRET ||
140
+ "" ,
130
141
131
- TWITTER_RETRY_LIMIT : // int
132
- safeParseInt (
133
- runtime . getSetting ( "TWITTER_RETRY_LIMIT" ) ||
142
+ // int
143
+ TWITTER_RETRY_LIMIT : safeParseInt (
144
+ runtime . getSetting ( "TWITTER_RETRY_LIMIT" ) ||
134
145
process . env . TWITTER_RETRY_LIMIT ,
135
- 5
136
- ) ,
146
+ 5
147
+ ) ,
137
148
138
- TWITTER_POLL_INTERVAL : // int in seconds
139
- safeParseInt (
140
- runtime . getSetting ( "TWITTER_POLL_INTERVAL" ) ||
149
+ // int in seconds
150
+ TWITTER_POLL_INTERVAL : safeParseInt (
151
+ runtime . getSetting ( "TWITTER_POLL_INTERVAL" ) ||
141
152
process . env . TWITTER_POLL_INTERVAL ,
142
- 120 // 2m
143
- ) ,
153
+ 120 // 2m
154
+ ) ,
144
155
145
- TWITTER_TARGET_USERS : // comma separated string
146
- parseTargetUsers (
147
- runtime . getSetting ( "TWITTER_TARGET_USERS" ) ||
156
+ // comma separated string
157
+ TWITTER_TARGET_USERS : parseTargetUsers (
158
+ runtime . getSetting ( "TWITTER_TARGET_USERS" ) ||
148
159
process . env . TWITTER_TARGET_USERS
149
- ) ,
160
+ ) ,
150
161
151
- POST_INTERVAL_MIN : // int in minutes
152
- safeParseInt (
153
- runtime . getSetting ( "POST_INTERVAL_MIN" ) ||
162
+ // int in minutes
163
+ POST_INTERVAL_MIN : safeParseInt (
164
+ runtime . getSetting ( "POST_INTERVAL_MIN" ) ||
154
165
process . env . POST_INTERVAL_MIN ,
155
- 90 // 1.5 hours
156
- ) ,
166
+ 90 // 1.5 hours
167
+ ) ,
157
168
158
- POST_INTERVAL_MAX : // int in minutes
159
- safeParseInt (
160
- runtime . getSetting ( "POST_INTERVAL_MAX" ) ||
169
+ // int in minutes
170
+ POST_INTERVAL_MAX : safeParseInt (
171
+ runtime . getSetting ( "POST_INTERVAL_MAX" ) ||
161
172
process . env . POST_INTERVAL_MAX ,
162
- 180 // 3 hours
163
- ) ,
173
+ 180 // 3 hours
174
+ ) ,
164
175
165
- ENABLE_ACTION_PROCESSING : // bool
176
+ // bool
177
+ ENABLE_ACTION_PROCESSING :
166
178
parseBooleanFromText (
167
179
runtime . getSetting ( "ENABLE_ACTION_PROCESSING" ) ||
168
- process . env . ENABLE_ACTION_PROCESSING
180
+ process . env . ENABLE_ACTION_PROCESSING
169
181
) ?? false ,
170
182
171
- ACTION_INTERVAL : // init in minutes (min 1m)
172
- safeParseInt (
173
- runtime . getSetting ( "ACTION_INTERVAL" ) ||
183
+ // init in minutes (min 1m)
184
+ ACTION_INTERVAL : safeParseInt (
185
+ runtime . getSetting ( "ACTION_INTERVAL" ) ||
174
186
process . env . ACTION_INTERVAL ,
175
- 5 // 5 minutes
176
- ) ,
187
+ 5 // 5 minutes
188
+ ) ,
177
189
178
- POST_IMMEDIATELY : // bool
190
+ // bool
191
+ POST_IMMEDIATELY :
179
192
parseBooleanFromText (
180
193
runtime . getSetting ( "POST_IMMEDIATELY" ) ||
181
- process . env . POST_IMMEDIATELY
194
+ process . env . POST_IMMEDIATELY
182
195
) ?? false ,
183
196
184
197
TWITTER_SPACES_ENABLE :
185
198
parseBooleanFromText (
186
199
runtime . getSetting ( "TWITTER_SPACES_ENABLE" ) ||
187
- process . env . TWITTER_SPACES_ENABLE
200
+ process . env . TWITTER_SPACES_ENABLE
188
201
) ?? false ,
189
202
} ;
190
203
0 commit comments