@hieplp/pi-account-switcher 0.2.0 → 0.2.2

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.
Files changed (56) hide show
  1. package/README.md +53 -21
  2. package/package.json +10 -7
  3. package/src/commands/accounts/add.ts +1 -1
  4. package/src/commands/accounts/edit.ts +1 -1
  5. package/src/commands/accounts/index.ts +3 -1
  6. package/src/commands/accounts/list.ts +1 -1
  7. package/src/commands/accounts/oauth.ts +1 -1
  8. package/src/commands/accounts/remove.ts +1 -1
  9. package/src/commands/accounts/shared/base.ts +34 -3
  10. package/src/commands/accounts/shared/prompts.ts +1 -1
  11. package/src/commands/accounts/switch.ts +6 -3
  12. package/src/commands/accounts/verify.ts +298 -0
  13. package/src/commands/base.ts +6 -6
  14. package/src/commands/index.ts +1 -1
  15. package/src/commands/models/add.ts +1 -1
  16. package/src/commands/models/index.ts +1 -1
  17. package/src/commands/models/list.ts +1 -1
  18. package/src/commands/models/remove.ts +1 -1
  19. package/src/commands/models/shared/base.ts +1 -1
  20. package/src/commands/models/shared/prompts.ts +1 -1
  21. package/src/commands/models/shared/select.ts +1 -1
  22. package/src/commands/providers/add.ts +1 -1
  23. package/src/commands/providers/edit.ts +1 -1
  24. package/src/commands/providers/index.ts +1 -1
  25. package/src/commands/providers/list.ts +5 -2
  26. package/src/commands/providers/remove.ts +1 -1
  27. package/src/commands/providers/shared/base.ts +1 -1
  28. package/src/commands/providers/shared/prompts.ts +1 -1
  29. package/src/commands/providers/shared/select.ts +1 -1
  30. package/src/commands/system/export.ts +51 -0
  31. package/src/commands/system/import.ts +102 -0
  32. package/src/commands/system/index.ts +5 -1
  33. package/src/commands/system/reset.ts +1 -1
  34. package/src/constants/commands.ts +13 -0
  35. package/src/constants/env.ts +1 -0
  36. package/src/constants/index.ts +1 -0
  37. package/src/constants/paths.ts +2 -1
  38. package/src/extension.ts +2 -4
  39. package/src/index.ts +1 -1
  40. package/src/runtime/account-switcher-runtime.ts +6 -2
  41. package/src/runtime/account-switcher.ts +2 -1
  42. package/src/runtime/index.ts +2 -4
  43. package/src/schemas/accounts.ts +1 -2
  44. package/src/schemas/providers.ts +2 -6
  45. package/src/services/models.ts +2 -2
  46. package/src/services/providers.ts +3 -9
  47. package/src/types/context.ts +1 -1
  48. package/src/types/index.ts +1 -1
  49. package/src/utils/accounts.ts +2 -2
  50. package/src/utils/commands.ts +10 -0
  51. package/src/utils/common.ts +15 -0
  52. package/src/utils/errors.ts +1 -3
  53. package/src/utils/filterable-selector.ts +108 -3
  54. package/src/utils/index.ts +1 -0
  55. package/src/utils/models.ts +1 -1
  56. package/src/utils/ui.ts +36 -2
@@ -1,4 +1,4 @@
1
- import type { Api, Model } from "@mariozechner/pi-ai";
1
+ import type { Api, Model } from "@earendil-works/pi-ai";
2
2
  import type { AccountConfig, AccountSwitcherContext, ProviderConfig } from "@/types";
3
3
  import { providerUtil } from "./providers";
4
4
  import { uiUtil } from "./ui";
package/src/utils/ui.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { ExtensionUIContext } from "@mariozechner/pi-coding-agent";
1
+ import type { ExtensionUIContext } from "@earendil-works/pi-coding-agent";
2
2
  import { commonUtil } from "./common.js";
3
- import { FilterableExtensionSelectorComponent } from "./filterable-selector.js";
3
+ import { FilterableExtensionSelectorComponent, FilterableMultiSelectComponent } from "./filterable-selector.js";
4
4
 
5
5
  function deduplicateLabels(labels: string[]): string[] {
6
6
  const seen = new Map<string, number>();
@@ -46,4 +46,38 @@ export const uiUtil = {
46
46
  (_tui, theme, _keybindings, done) => new FilterableExtensionSelectorComponent(title, options, done, theme),
47
47
  );
48
48
  },
49
+
50
+ /** Show a checkbox-style multi-select component. */
51
+ multiSelect: (
52
+ ui: ExtensionUIContext,
53
+ title: string,
54
+ options: string[],
55
+ initialChecked: boolean[] = [],
56
+ disabled: boolean[] = [],
57
+ ): Promise<string[] | undefined> => {
58
+ return ui.custom<string[] | undefined>(
59
+ (_tui, theme, _keybindings, done) =>
60
+ new FilterableMultiSelectComponent(title, options, initialChecked, done, theme, disabled),
61
+ );
62
+ },
63
+
64
+ /** Like multiSelect but skips items where the corresponding value is null (used for group headers). */
65
+ multiGroupedSelect: async <T>(
66
+ ui: ExtensionUIContext,
67
+ title: string,
68
+ labels: string[],
69
+ values: Array<T | null>,
70
+ initialChecked: boolean[] = [],
71
+ ): Promise<T[] | undefined> => {
72
+ const deduped = deduplicateLabels(labels);
73
+ const selected = await uiUtil.multiSelect(
74
+ ui,
75
+ title,
76
+ deduped,
77
+ initialChecked,
78
+ values.map((value) => value === null),
79
+ );
80
+ if (!selected) return undefined;
81
+ return selected.map((label) => values[deduped.indexOf(label)]).filter((value): value is T => value !== null);
82
+ },
49
83
  };