@victor-software-house/pi-multicodex 2.1.4 → 2.1.5
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/account-manager.ts +60 -27
- package/commands.ts +5 -1
- package/package.json +1 -1
package/account-manager.ts
CHANGED
|
@@ -313,6 +313,42 @@ export class AccountManager {
|
|
|
313
313
|
);
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
private getLinkedImportedAccount(): Account | undefined {
|
|
317
|
+
return this.data.accounts.find(
|
|
318
|
+
(account) =>
|
|
319
|
+
account.importSource === "pi-openai-codex" &&
|
|
320
|
+
account.importMode !== "synthetic",
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
private getSyntheticImportedAccount(): Account | undefined {
|
|
325
|
+
return this.data.accounts.find(
|
|
326
|
+
(account) =>
|
|
327
|
+
account.importSource === "pi-openai-codex" &&
|
|
328
|
+
account.importMode === "synthetic",
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
private findManagedImportedTarget(imported: {
|
|
333
|
+
identifier: string;
|
|
334
|
+
credentials: OAuthCredentials;
|
|
335
|
+
}): Account | undefined {
|
|
336
|
+
const byRefreshToken = this.data.accounts.find(
|
|
337
|
+
(account) =>
|
|
338
|
+
account.importMode !== "synthetic" &&
|
|
339
|
+
account.refreshToken === imported.credentials.refresh,
|
|
340
|
+
);
|
|
341
|
+
if (byRefreshToken) {
|
|
342
|
+
return byRefreshToken;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return this.data.accounts.find(
|
|
346
|
+
(account) =>
|
|
347
|
+
account.importMode !== "synthetic" &&
|
|
348
|
+
account.email === imported.identifier,
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
|
|
316
352
|
private clearImportedLink(account: Account): boolean {
|
|
317
353
|
let changed = false;
|
|
318
354
|
if (account.importSource) {
|
|
@@ -334,19 +370,18 @@ export class AccountManager {
|
|
|
334
370
|
const imported = await loadImportedOpenAICodexAuth();
|
|
335
371
|
if (!imported) return false;
|
|
336
372
|
|
|
337
|
-
const
|
|
373
|
+
const linkedImported = this.getLinkedImportedAccount();
|
|
374
|
+
const syntheticImported = this.getSyntheticImportedAccount();
|
|
375
|
+
const currentImported = linkedImported ?? syntheticImported;
|
|
338
376
|
if (
|
|
339
|
-
|
|
340
|
-
(
|
|
341
|
-
|
|
377
|
+
currentImported?.importFingerprint === imported.fingerprint &&
|
|
378
|
+
(currentImported.importMode !== "synthetic" ||
|
|
379
|
+
currentImported.email === imported.identifier)
|
|
342
380
|
) {
|
|
343
381
|
return false;
|
|
344
382
|
}
|
|
345
383
|
|
|
346
|
-
const matchingAccount = this.
|
|
347
|
-
imported.credentials.refresh,
|
|
348
|
-
existingImported?.email,
|
|
349
|
-
);
|
|
384
|
+
const matchingAccount = this.findManagedImportedTarget(imported);
|
|
350
385
|
if (matchingAccount) {
|
|
351
386
|
let changed = this.applyCredentials(
|
|
352
387
|
matchingAccount,
|
|
@@ -357,12 +392,11 @@ export class AccountManager {
|
|
|
357
392
|
importFingerprint: imported.fingerprint,
|
|
358
393
|
},
|
|
359
394
|
);
|
|
360
|
-
if (
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
395
|
+
if (linkedImported && linkedImported !== matchingAccount) {
|
|
396
|
+
changed = this.clearImportedLink(linkedImported) || changed;
|
|
397
|
+
}
|
|
398
|
+
if (syntheticImported) {
|
|
399
|
+
changed = this.removeAccountRecord(syntheticImported) || changed;
|
|
366
400
|
}
|
|
367
401
|
if (changed) {
|
|
368
402
|
this.save();
|
|
@@ -371,17 +405,24 @@ export class AccountManager {
|
|
|
371
405
|
return changed;
|
|
372
406
|
}
|
|
373
407
|
|
|
374
|
-
if (
|
|
375
|
-
const
|
|
408
|
+
if (linkedImported) {
|
|
409
|
+
const changed = this.clearImportedLink(linkedImported);
|
|
410
|
+
if (changed) {
|
|
411
|
+
this.save();
|
|
412
|
+
this.notifyStateChanged();
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (syntheticImported) {
|
|
376
417
|
let changed = false;
|
|
377
|
-
if (
|
|
418
|
+
if (syntheticImported.email !== imported.identifier) {
|
|
378
419
|
changed = this.updateAccountEmail(
|
|
379
|
-
|
|
420
|
+
syntheticImported,
|
|
380
421
|
imported.identifier,
|
|
381
422
|
);
|
|
382
423
|
}
|
|
383
424
|
changed =
|
|
384
|
-
this.applyCredentials(
|
|
425
|
+
this.applyCredentials(syntheticImported, imported.credentials, {
|
|
385
426
|
importSource: "pi-openai-codex",
|
|
386
427
|
importMode: "synthetic",
|
|
387
428
|
importFingerprint: imported.fingerprint,
|
|
@@ -393,14 +434,6 @@ export class AccountManager {
|
|
|
393
434
|
return changed;
|
|
394
435
|
}
|
|
395
436
|
|
|
396
|
-
if (existingImported) {
|
|
397
|
-
const changed = this.clearImportedLink(existingImported);
|
|
398
|
-
if (changed) {
|
|
399
|
-
this.save();
|
|
400
|
-
this.notifyStateChanged();
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
437
|
this.addOrUpdateAccount(imported.identifier, imported.credentials, {
|
|
405
438
|
importSource: "pi-openai-codex",
|
|
406
439
|
importMode: "synthetic",
|
package/commands.ts
CHANGED
|
@@ -99,7 +99,11 @@ function formatAccountStatusLine(
|
|
|
99
99
|
const quotaHit =
|
|
100
100
|
account.quotaExhaustedUntil && account.quotaExhaustedUntil > Date.now();
|
|
101
101
|
const untouched = isUsageUntouched(usage) ? "untouched" : null;
|
|
102
|
-
const imported = account.importSource
|
|
102
|
+
const imported = account.importSource
|
|
103
|
+
? account.importMode === "synthetic"
|
|
104
|
+
? "pi auth only"
|
|
105
|
+
: "pi auth"
|
|
106
|
+
: null;
|
|
103
107
|
const reauth = account.needsReauth ? "needs reauth" : null;
|
|
104
108
|
const tags = [
|
|
105
109
|
active?.email === account.email ? "active" : null,
|