@deepdream314/remodex 1.3.8 → 1.3.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepdream314/remodex",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "description": "Local bridge between Codex and the Remodex mobile app. Run `remodex up` to start.",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -24,8 +24,11 @@ function composeAccountStatus({
24
24
  ]) || null;
25
25
  const tokenReady = Boolean(authToken);
26
26
  const requiresOpenaiAuth = Boolean(accountRead?.requiresOpenaiAuth || authStatus?.requiresOpenaiAuth);
27
- const hasPriorLoginContext = hasAccountLogin || Boolean(authMethod);
28
- const needsReauth = !loginInFlight && requiresOpenaiAuth && hasPriorLoginContext;
27
+ const needsReauth = !loginInFlight
28
+ && requiresOpenaiAuth
29
+ && !tokenReady
30
+ && !hasAccountLogin
31
+ && Boolean(authMethod);
29
32
  const isAuthenticated = !needsReauth && (tokenReady || hasAccountLogin);
30
33
  const status = isAuthenticated
31
34
  ? "authenticated"
package/src/bridge.js CHANGED
@@ -543,7 +543,7 @@ function startBridge({
543
543
  }),
544
544
  sendCodexRequest("getAuthStatus", {
545
545
  includeToken: true,
546
- refreshToken: true,
546
+ refreshToken: false,
547
547
  }),
548
548
  readBridgePackageVersionStatus(),
549
549
  ]);
@@ -171,14 +171,7 @@ async function requestTranscription({
171
171
 
172
172
  // Reads the current bridge-owned auth state from the local codex app-server and refreshes if needed.
173
173
  async function loadAuthContext(sendCodexRequest) {
174
- const authStatus = await sendCodexRequest("getAuthStatus", {
175
- includeToken: true,
176
- refreshToken: true,
177
- });
178
-
179
- const authMethod = readString(authStatus?.authMethod);
180
- const token = readString(authStatus?.authToken);
181
- const isChatGPT = authMethod === "chatgpt" || authMethod === "chatgptAuthTokens";
174
+ const { authMethod, token, isChatGPT } = await resolveCurrentOrRefreshedAuthStatus(sendCodexRequest);
182
175
 
183
176
  if (!token) {
184
177
  throw voiceError("not_authenticated", "Sign in with ChatGPT before using voice transcription.");
@@ -285,20 +278,10 @@ function voiceError(errorCode, userMessage) {
285
278
  // Returns an ephemeral ChatGPT token so the phone can call the transcription API directly.
286
279
  // Uses its own token resolution instead of loadAuthContext so errors are specific and actionable.
287
280
  async function resolveVoiceAuth(sendCodexRequest) {
288
- let authStatus;
289
- try {
290
- authStatus = await sendCodexRequest("getAuthStatus", {
291
- includeToken: true,
292
- refreshToken: true,
293
- });
294
- } catch (err) {
295
- console.error(`[remodex] voice/resolveAuth: getAuthStatus RPC failed: ${err.message}`);
296
- throw voiceError("auth_unavailable", "Could not read ChatGPT session from the Mac runtime. Is the bridge running?");
297
- }
298
-
299
- const authMethod = readString(authStatus?.authMethod);
300
- const token = readString(authStatus?.authToken);
301
- const isChatGPT = authMethod === "chatgpt" || authMethod === "chatgptAuthTokens";
281
+ const { authMethod, token, isChatGPT, requiresOpenaiAuth } = await resolveCurrentOrRefreshedAuthStatus(sendCodexRequest, {
282
+ rpcErrorCode: "auth_unavailable",
283
+ rpcErrorMessage: "Could not read ChatGPT session from the Mac runtime. Is the bridge running?",
284
+ });
302
285
 
303
286
  // Check for a usable ChatGPT token first. The runtime may set requiresOpenaiAuth
304
287
  // even when a valid ChatGPT session is present (the flag is about the runtime's
@@ -308,13 +291,61 @@ async function resolveVoiceAuth(sendCodexRequest) {
308
291
  }
309
292
 
310
293
  if (!token) {
311
- console.error(`[remodex] voice/resolveAuth: no token. authMethod=${authMethod || "none"} requiresOpenaiAuth=${authStatus?.requiresOpenaiAuth}`);
294
+ console.error(`[remodex] voice/resolveAuth: no token. authMethod=${authMethod || "none"} requiresOpenaiAuth=${requiresOpenaiAuth}`);
312
295
  throw voiceError("token_missing", "No ChatGPT session token available. Sign in to ChatGPT on the Mac.");
313
296
  }
314
297
 
315
298
  throw voiceError("not_chatgpt", "Voice transcription requires a ChatGPT account.");
316
299
  }
317
300
 
301
+ async function resolveCurrentOrRefreshedAuthStatus(
302
+ sendCodexRequest,
303
+ {
304
+ rpcErrorCode = "not_authenticated",
305
+ rpcErrorMessage = "Sign in with ChatGPT before using voice transcription.",
306
+ } = {}
307
+ ) {
308
+ const currentStatus = await readAuthStatus(sendCodexRequest, {
309
+ refreshToken: false,
310
+ rpcErrorCode,
311
+ rpcErrorMessage,
312
+ });
313
+
314
+ if (currentStatus.token) {
315
+ return currentStatus;
316
+ }
317
+
318
+ return readAuthStatus(sendCodexRequest, {
319
+ refreshToken: true,
320
+ rpcErrorCode,
321
+ rpcErrorMessage,
322
+ });
323
+ }
324
+
325
+ async function readAuthStatus(
326
+ sendCodexRequest,
327
+ { refreshToken, rpcErrorCode, rpcErrorMessage }
328
+ ) {
329
+ let authStatus;
330
+ try {
331
+ authStatus = await sendCodexRequest("getAuthStatus", {
332
+ includeToken: true,
333
+ refreshToken,
334
+ });
335
+ } catch (err) {
336
+ throw voiceError(rpcErrorCode, rpcErrorMessage);
337
+ }
338
+
339
+ const authMethod = readString(authStatus?.authMethod);
340
+ const token = readString(authStatus?.authToken);
341
+ return {
342
+ authMethod,
343
+ token,
344
+ isChatGPT: authMethod === "chatgpt" || authMethod === "chatgptAuthTokens",
345
+ requiresOpenaiAuth: Boolean(authStatus?.requiresOpenaiAuth),
346
+ };
347
+ }
348
+
318
349
  module.exports = {
319
350
  createVoiceHandler,
320
351
  resolveVoiceAuth,