opencode-copilot-account-switcher 0.11.1 → 0.12.0
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/dist/codex-auth-source.d.ts +16 -0
- package/dist/codex-auth-source.js +63 -0
- package/dist/codex-status-command.d.ts +53 -0
- package/dist/codex-status-command.js +215 -0
- package/dist/codex-status-fetcher.d.ts +66 -0
- package/dist/codex-status-fetcher.js +232 -0
- package/dist/codex-store.d.ts +25 -0
- package/dist/codex-store.js +70 -0
- package/dist/copilot-network-retry.d.ts +2 -17
- package/dist/copilot-network-retry.js +236 -322
- package/dist/copilot-retry-policy.d.ts +1 -0
- package/dist/copilot-retry-policy.js +1 -0
- package/dist/network-retry-engine.d.ts +33 -0
- package/dist/network-retry-engine.js +62 -0
- package/dist/plugin-hooks.d.ts +3 -0
- package/dist/plugin-hooks.js +67 -5
- package/dist/provider-descriptor.d.ts +2 -0
- package/dist/provider-descriptor.js +1 -0
- package/dist/provider-registry.d.ts +1 -0
- package/dist/provider-registry.js +1 -0
- package/dist/providers/descriptor.d.ts +28 -0
- package/dist/providers/descriptor.js +66 -0
- package/dist/providers/registry.d.ts +18 -0
- package/dist/providers/registry.js +27 -0
- package/dist/retry/copilot-policy.d.ts +61 -0
- package/dist/retry/copilot-policy.js +240 -0
- package/dist/retry/shared-engine.d.ts +50 -0
- package/dist/retry/shared-engine.js +56 -0
- package/dist/routing-state.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import { promises as fs } from "node:fs";
|
|
4
|
+
import { xdgConfig } from "xdg-basedir";
|
|
5
|
+
const filename = "codex-store.json";
|
|
6
|
+
function pickCodexStore(input) {
|
|
7
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
8
|
+
return {};
|
|
9
|
+
const source = input;
|
|
10
|
+
const store = {};
|
|
11
|
+
if (typeof source.activeProvider === "string")
|
|
12
|
+
store.activeProvider = source.activeProvider;
|
|
13
|
+
if (typeof source.activeAccountId === "string")
|
|
14
|
+
store.activeAccountId = source.activeAccountId;
|
|
15
|
+
if (typeof source.activeEmail === "string")
|
|
16
|
+
store.activeEmail = source.activeEmail;
|
|
17
|
+
if (typeof source.lastStatusRefresh === "number" && !Number.isNaN(source.lastStatusRefresh)) {
|
|
18
|
+
store.lastStatusRefresh = source.lastStatusRefresh;
|
|
19
|
+
}
|
|
20
|
+
if (source.account && typeof source.account === "object" && !Array.isArray(source.account)) {
|
|
21
|
+
const account = source.account;
|
|
22
|
+
const next = {};
|
|
23
|
+
if (typeof account.id === "string")
|
|
24
|
+
next.id = account.id;
|
|
25
|
+
if (typeof account.email === "string")
|
|
26
|
+
next.email = account.email;
|
|
27
|
+
if (typeof account.plan === "string")
|
|
28
|
+
next.plan = account.plan;
|
|
29
|
+
if (Object.keys(next).length > 0)
|
|
30
|
+
store.account = next;
|
|
31
|
+
}
|
|
32
|
+
if (source.status && typeof source.status === "object" && !Array.isArray(source.status)) {
|
|
33
|
+
const status = source.status;
|
|
34
|
+
if (status.premium && typeof status.premium === "object" && !Array.isArray(status.premium)) {
|
|
35
|
+
const premium = status.premium;
|
|
36
|
+
const nextPremium = {};
|
|
37
|
+
if (typeof premium.entitlement === "number" && !Number.isNaN(premium.entitlement)) {
|
|
38
|
+
nextPremium.entitlement = premium.entitlement;
|
|
39
|
+
}
|
|
40
|
+
if (typeof premium.remaining === "number" && !Number.isNaN(premium.remaining)) {
|
|
41
|
+
nextPremium.remaining = premium.remaining;
|
|
42
|
+
}
|
|
43
|
+
if (Object.keys(nextPremium).length > 0)
|
|
44
|
+
store.status = { premium: nextPremium };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return store;
|
|
48
|
+
}
|
|
49
|
+
export function parseCodexStore(raw) {
|
|
50
|
+
const parsed = raw ? JSON.parse(raw) : {};
|
|
51
|
+
return pickCodexStore(parsed);
|
|
52
|
+
}
|
|
53
|
+
export function codexStorePath() {
|
|
54
|
+
const base = xdgConfig ?? path.join(os.homedir(), ".config");
|
|
55
|
+
return path.join(base, "opencode", filename);
|
|
56
|
+
}
|
|
57
|
+
export async function readCodexStore(filePath = codexStorePath()) {
|
|
58
|
+
const raw = await fs.readFile(filePath, "utf8").catch((error) => {
|
|
59
|
+
if (error.code === "ENOENT")
|
|
60
|
+
return "";
|
|
61
|
+
throw error;
|
|
62
|
+
});
|
|
63
|
+
return parseCodexStore(raw);
|
|
64
|
+
}
|
|
65
|
+
export async function writeCodexStore(store, options) {
|
|
66
|
+
const file = options?.filePath ?? codexStorePath();
|
|
67
|
+
const next = pickCodexStore(store);
|
|
68
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
69
|
+
await fs.writeFile(file, JSON.stringify(next, null, 2), { mode: 0o600 });
|
|
70
|
+
}
|
|
@@ -1,21 +1,6 @@
|
|
|
1
|
+
import { type SharedRetryNotifier } from "./retry/shared-engine.js";
|
|
1
2
|
export type FetchLike = (request: Request | URL | string, init?: RequestInit) => Promise<Response>;
|
|
2
|
-
export type CopilotRetryNotifier =
|
|
3
|
-
started: (state: {
|
|
4
|
-
remaining: number;
|
|
5
|
-
}) => Promise<void>;
|
|
6
|
-
progress: (state: {
|
|
7
|
-
remaining: number;
|
|
8
|
-
}) => Promise<void>;
|
|
9
|
-
repairWarning: (state: {
|
|
10
|
-
remaining: number;
|
|
11
|
-
}) => Promise<void>;
|
|
12
|
-
completed: (state: {
|
|
13
|
-
remaining: number;
|
|
14
|
-
}) => Promise<void>;
|
|
15
|
-
stopped: (state: {
|
|
16
|
-
remaining: number;
|
|
17
|
-
}) => Promise<void>;
|
|
18
|
-
};
|
|
3
|
+
export type CopilotRetryNotifier = SharedRetryNotifier;
|
|
19
4
|
type JsonRecord = Record<string, unknown>;
|
|
20
5
|
export type AccountSwitchCleanupResult = {
|
|
21
6
|
payload: JsonRecord;
|