MCPcopy Create free account
hub / github.com/dwgx/WindsurfAPI / getUserStatus

Function getUserStatus

src/windsurf-api.js:146–178  ·  view source on GitHub ↗
(apiKey, proxy = null)

Source from the content-addressed store, hash-verified

144 * @returns {Promise<{planName, dailyPercent, weeklyPercent, dailyResetAt, weeklyResetAt, prompt:{used,limit}, flex:{used,limit}, raw}>}
145 */
146export async function getUserStatus(apiKey, proxy = null) {
147 const body = {
148 metadata: {
149 apiKey,
150 ideName: 'windsurf',
151 ideVersion: '1.9600.41',
152 extensionName: 'windsurf',
153 extensionVersion: '1.9600.41',
154 locale: 'en',
155 },
156 };
157
158 // Try with proxy first, then retry direct if proxy itself fails (407 etc.).
159 const proxyModes = proxy ? [proxy, null] : [null];
160 let lastErr = null;
161 for (const px of proxyModes) {
162 for (const host of SERVER_HOSTS) {
163 try {
164 const res = await postJson(host, USER_STATUS_PATH, body, px);
165 if (res.status >= 400) {
166 lastErr = new Error(`GetUserStatus ${host} → ${res.status}: ${res.raw.slice(0, 160)}`);
167 continue;
168 }
169 return normalizeUserStatus(res.data);
170 } catch (e) {
171 lastErr = e;
172 log.debug(`getCreditUsage ${host} failed: ${e.message}`);
173 if (px && isProxyError(e)) break; // skip second host, go straight to direct
174 }
175 }
176 }
177 throw lastErr || new Error('GetUserStatus: all hosts failed');
178}
179
180function normalizeUserStatus(data) {
181 const ps = data?.userStatus?.planStatus || {};

Callers 1

refreshCreditsFunction · 0.85

Calls 3

postJsonFunction · 0.85
normalizeUserStatusFunction · 0.85
isProxyErrorFunction · 0.85

Tested by

no test coverage detected