@victor-software-house/pi-multicodex 2.1.2 → 2.1.3

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.
@@ -153,6 +153,7 @@ export class AccountManager {
153
153
  creds: OAuthCredentials,
154
154
  options?: {
155
155
  importSource?: "pi-openai-codex";
156
+ importMode?: "linked" | "synthetic";
156
157
  importFingerprint?: string;
157
158
  },
158
159
  ): boolean {
@@ -182,6 +183,10 @@ export class AccountManager {
182
183
  account.importSource = options.importSource;
183
184
  changed = true;
184
185
  }
186
+ if (options?.importMode && account.importMode !== options.importMode) {
187
+ account.importMode = options.importMode;
188
+ changed = true;
189
+ }
185
190
  if (
186
191
  options?.importFingerprint &&
187
192
  account.importFingerprint !== options.importFingerprint
@@ -202,6 +207,7 @@ export class AccountManager {
202
207
  creds: OAuthCredentials,
203
208
  options?: {
204
209
  importSource?: "pi-openai-codex";
210
+ importMode?: "linked" | "synthetic";
205
211
  importFingerprint?: string;
206
212
  preserveActive?: boolean;
207
213
  },
@@ -221,7 +227,13 @@ export class AccountManager {
221
227
  ) {
222
228
  changed = this.updateAccountEmail(duplicate, email) || changed;
223
229
  }
224
- changed = this.applyCredentials(target, creds, options) || changed;
230
+ changed =
231
+ this.applyCredentials(target, creds, {
232
+ ...options,
233
+ importMode:
234
+ options?.importMode ??
235
+ (duplicate?.importMode === "synthetic" ? "linked" : undefined),
236
+ }) || changed;
225
237
  } else {
226
238
  target = {
227
239
  email,
@@ -231,6 +243,7 @@ export class AccountManager {
231
243
  accountId:
232
244
  typeof creds.accountId === "string" ? creds.accountId : undefined,
233
245
  importSource: options?.importSource,
246
+ importMode: options?.importMode,
234
247
  importFingerprint: options?.importFingerprint,
235
248
  };
236
249
  this.data.accounts.push(target);
@@ -300,6 +313,23 @@ export class AccountManager {
300
313
  );
301
314
  }
302
315
 
316
+ private clearImportedLink(account: Account): boolean {
317
+ let changed = false;
318
+ if (account.importSource) {
319
+ account.importSource = undefined;
320
+ changed = true;
321
+ }
322
+ if (account.importMode) {
323
+ account.importMode = undefined;
324
+ changed = true;
325
+ }
326
+ if (account.importFingerprint) {
327
+ account.importFingerprint = undefined;
328
+ changed = true;
329
+ }
330
+ return changed;
331
+ }
332
+
303
333
  async syncImportedOpenAICodexAuth(): Promise<boolean> {
304
334
  const imported = await loadImportedOpenAICodexAuth();
305
335
  if (!imported) return false;
@@ -314,25 +344,20 @@ export class AccountManager {
314
344
  existingImported?.email,
315
345
  );
316
346
  if (matchingAccount) {
317
- const wasActiveImported =
318
- existingImported && this.data.activeEmail === existingImported.email;
319
- const wasManualImported =
320
- existingImported && this.manualEmail === existingImported.email;
321
347
  let changed = this.applyCredentials(
322
348
  matchingAccount,
323
349
  imported.credentials,
324
350
  {
325
351
  importSource: "pi-openai-codex",
352
+ importMode: "linked",
326
353
  importFingerprint: imported.fingerprint,
327
354
  },
328
355
  );
329
356
  if (existingImported && existingImported !== matchingAccount) {
330
- changed = this.removeAccountRecord(existingImported) || changed;
331
- if (wasActiveImported) {
332
- this.data.activeEmail = matchingAccount.email;
333
- }
334
- if (wasManualImported) {
335
- this.manualEmail = matchingAccount.email;
357
+ if (existingImported.importMode === "synthetic") {
358
+ changed = this.removeAccountRecord(existingImported) || changed;
359
+ } else {
360
+ changed = this.clearImportedLink(existingImported) || changed;
336
361
  }
337
362
  }
338
363
  if (changed) {
@@ -342,7 +367,7 @@ export class AccountManager {
342
367
  return changed;
343
368
  }
344
369
 
345
- if (existingImported) {
370
+ if (existingImported?.importMode === "synthetic") {
346
371
  const target = this.getAccount(imported.identifier);
347
372
  let changed = false;
348
373
  if (!target && existingImported.email !== imported.identifier) {
@@ -354,6 +379,7 @@ export class AccountManager {
354
379
  changed =
355
380
  this.applyCredentials(existingImported, imported.credentials, {
356
381
  importSource: "pi-openai-codex",
382
+ importMode: "synthetic",
357
383
  importFingerprint: imported.fingerprint,
358
384
  }) || changed;
359
385
  if (changed) {
@@ -363,8 +389,17 @@ export class AccountManager {
363
389
  return changed;
364
390
  }
365
391
 
392
+ if (existingImported) {
393
+ const changed = this.clearImportedLink(existingImported);
394
+ if (changed) {
395
+ this.save();
396
+ this.notifyStateChanged();
397
+ }
398
+ }
399
+
366
400
  this.addOrUpdateAccount(imported.identifier, imported.credentials, {
367
401
  importSource: "pi-openai-codex",
402
+ importMode: "synthetic",
368
403
  importFingerprint: imported.fingerprint,
369
404
  preserveActive: true,
370
405
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@victor-software-house/pi-multicodex",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "Codex account rotation extension for pi",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/storage.ts CHANGED
@@ -11,6 +11,7 @@ export interface Account {
11
11
  lastUsed?: number;
12
12
  quotaExhaustedUntil?: number;
13
13
  importSource?: "pi-openai-codex";
14
+ importMode?: "linked" | "synthetic";
14
15
  importFingerprint?: string;
15
16
  needsReauth?: boolean;
16
17
  }