pi-provider-qoder-cn 0.2.7 → 0.2.8
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/README.md +1 -0
- package/dist/index.js +37 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,6 +74,7 @@ Qoder CN Plan (personal_standard)
|
|
|
74
74
|
Overall [███░░░░░░░░░░░░░░░░░░] 12.5% used
|
|
75
75
|
Plan quota [███░░░░░░░░░░░░░░░░░░] 250 / 2000 credits 12.5% 1750 left
|
|
76
76
|
Add-on [░░░░░░░░░░░░░░░░░░░░░] 0 / 700 credits 0% 700 left
|
|
77
|
+
User someone · someone@example.com
|
|
77
78
|
Expires never
|
|
78
79
|
Manage https://qoder.com.cn/account/usage
|
|
79
80
|
```
|
package/dist/index.js
CHANGED
|
@@ -1100,6 +1100,16 @@ var init_catalog = __esm({
|
|
|
1100
1100
|
});
|
|
1101
1101
|
|
|
1102
1102
|
// src/auth/pat.ts
|
|
1103
|
+
var pat_exports = {};
|
|
1104
|
+
__export(pat_exports, {
|
|
1105
|
+
PAT_REFRESH_PREFIX: () => PAT_REFRESH_PREFIX,
|
|
1106
|
+
credentialsFromPat: () => credentialsFromPat,
|
|
1107
|
+
decodePatRefresh: () => decodePatRefresh,
|
|
1108
|
+
encodePatRefresh: () => encodePatRefresh,
|
|
1109
|
+
exchangeJobToken: () => exchangeJobToken,
|
|
1110
|
+
fetchUserInfo: () => fetchUserInfo,
|
|
1111
|
+
isPatRefresh: () => isPatRefresh
|
|
1112
|
+
});
|
|
1103
1113
|
function isPatRefresh(refresh) {
|
|
1104
1114
|
return refresh.startsWith(`${PAT_REFRESH_PREFIX}|`);
|
|
1105
1115
|
}
|
|
@@ -2017,6 +2027,10 @@ function formatQoderUsage(raw, mode, now = Date.now(), options = {}) {
|
|
|
2017
2027
|
}
|
|
2018
2028
|
if (!showUserQuota && !showAddOnQuota && !showOrg) notes.push({ label: "Buckets", value: "none returned" });
|
|
2019
2029
|
if (raw?.isPlanQuotaProrated) notes.push({ label: "Note", value: "plan quota is prorated" });
|
|
2030
|
+
const user = options.user;
|
|
2031
|
+
if (user && (user.name || user.email)) {
|
|
2032
|
+
notes.push({ label: "User", value: [user.name, user.email].filter(Boolean).join(" \xB7 ") });
|
|
2033
|
+
}
|
|
2020
2034
|
if (isPersonalStandard || !showOrg && formatResetTime(raw?.expiresAt, now) === "never") {
|
|
2021
2035
|
notes.push({ label: "Daily reset", value: formatDailyResetCountdown(now) });
|
|
2022
2036
|
}
|
|
@@ -2054,14 +2068,30 @@ async function fetchQoderQuota(accessToken, mode) {
|
|
|
2054
2068
|
if (!data) throw new Error("Qoder usage response was not JSON.");
|
|
2055
2069
|
return data;
|
|
2056
2070
|
}
|
|
2057
|
-
async function
|
|
2071
|
+
async function resolveUsageIdentity(providerID, mode, ctx, withIdentity = true) {
|
|
2072
|
+
let access;
|
|
2058
2073
|
try {
|
|
2059
|
-
|
|
2060
|
-
if (fromRegistry) return fromRegistry;
|
|
2074
|
+
access = await ctx?.modelRegistry?.getApiKeyForProvider(providerID) || void 0;
|
|
2061
2075
|
} catch {
|
|
2062
2076
|
}
|
|
2063
2077
|
const { getCachedCredentials: getCachedCredentials2 } = await Promise.resolve().then(() => (init_oauth(), oauth_exports));
|
|
2064
|
-
|
|
2078
|
+
const stored = getCachedCredentials2("", providerID);
|
|
2079
|
+
access = access || stored?.access || void 0;
|
|
2080
|
+
if (!access) return void 0;
|
|
2081
|
+
if (!withIdentity) return { access, name: "", email: "" };
|
|
2082
|
+
const storedMatches = stored?.access === access;
|
|
2083
|
+
let name = storedMatches && stored?.name || "";
|
|
2084
|
+
let email = storedMatches && stored?.email || "";
|
|
2085
|
+
if (!name && !email) {
|
|
2086
|
+
try {
|
|
2087
|
+
const { fetchUserInfo: fetchUserInfo2 } = await Promise.resolve().then(() => (init_pat(), pat_exports));
|
|
2088
|
+
const info = await fetchUserInfo2(access, mode);
|
|
2089
|
+
name = info.name || "";
|
|
2090
|
+
email = info.email || "";
|
|
2091
|
+
} catch {
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
return { access, name, email };
|
|
2065
2095
|
}
|
|
2066
2096
|
var FORMAT_ARGS = /* @__PURE__ */ new Set(["json", "raw", "debug"]);
|
|
2067
2097
|
var PLAIN_ARGS = /* @__PURE__ */ new Set(["plain", "no-color", "nocolor"]);
|
|
@@ -2077,14 +2107,15 @@ async function runUsageCommand(mode, args, ctx) {
|
|
|
2077
2107
|
const providerID = region.providerID;
|
|
2078
2108
|
const wantsRaw = FORMAT_ARGS.has((args || "").trim().toLowerCase());
|
|
2079
2109
|
try {
|
|
2080
|
-
const
|
|
2110
|
+
const identity = await resolveUsageIdentity(providerID, mode, ctx, !wantsRaw);
|
|
2111
|
+
const accessToken = identity?.access;
|
|
2081
2112
|
if (!accessToken) {
|
|
2082
2113
|
ctx?.ui?.notify(`No ${providerID} credentials. Run /login ${providerID} first.`, "warning");
|
|
2083
2114
|
return;
|
|
2084
2115
|
}
|
|
2085
2116
|
const raw = await fetchQoderQuota(accessToken, mode);
|
|
2086
2117
|
const color = !wantsRaw && shouldColorize(args, { hasUI: Boolean(ctx?.ui) });
|
|
2087
|
-
const output = wantsRaw ? JSON.stringify(raw, null, 2) : formatQoderUsage(raw, mode, Date.now(), { color }).lines.join("\n");
|
|
2118
|
+
const output = wantsRaw ? JSON.stringify(raw, null, 2) : formatQoderUsage(raw, mode, Date.now(), { color, user: identity }).lines.join("\n");
|
|
2088
2119
|
ctx?.ui?.notify(output, "info");
|
|
2089
2120
|
if (!ctx?.ui) console.log(output);
|
|
2090
2121
|
} catch (error) {
|
package/package.json
CHANGED