dsh-plugin-subscription-oauth 0.16.0 → 0.16.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.
- package/lib/auth/workbuddy-flow.d.ts +2 -1
- package/lib/auth/workbuddy-flow.js +22 -19
- package/lib/client/SubscriptionsSection.js +12 -1
- package/lib/client.js +10 -1
- package/lib/client.js.map +1 -1
- package/lib/providers/workbuddy.js +2 -19
- package/package.json +1 -1
|
@@ -85,7 +85,7 @@ export declare function finishWorkBuddySignIn(start: WorkBuddySignInStart, fetch
|
|
|
85
85
|
}>;
|
|
86
86
|
/** The domain a token names, else the API host. */
|
|
87
87
|
export declare function workbuddyDomain(token: Pick<WorkBuddyTokenSet, 'domain'>): string;
|
|
88
|
-
/** The headers WorkBuddy's
|
|
88
|
+
/** The headers WorkBuddy's chat gateway accepts: its own CLI's, nothing more. */
|
|
89
89
|
export declare function workbuddyHeaders(token: WorkBuddyTokenSet): Record<string, string>;
|
|
90
90
|
/** Whether a token is close enough to its end that a request should refresh it. */
|
|
91
91
|
export declare function workbuddyStale(token: Pick<WorkBuddyTokenSet, 'expiresAt'>): boolean;
|
|
@@ -140,6 +140,7 @@ export declare function claimWorkBuddyCheckin(token: WorkBuddyTokenSet, fetchFn:
|
|
|
140
140
|
/** The account's precise remaining credits, summed across its live packages. */
|
|
141
141
|
export declare function readWorkBuddyCredits(token: WorkBuddyTokenSet, fetchFn: typeof fetch): Promise<{
|
|
142
142
|
remaining: number;
|
|
143
|
+
total: number;
|
|
143
144
|
nearestExpiryMs?: number;
|
|
144
145
|
} | null>;
|
|
145
146
|
/** Read the account's plan and metered credits for the Settings card. */
|
|
@@ -214,26 +214,21 @@ async function workbuddyEnterprise(token, who, fetchFn) {
|
|
|
214
214
|
const pick = same.length === 1 ? same[0] : last.length === 1 ? last[0] : mine.length === 1 ? mine[0] : undefined;
|
|
215
215
|
return pick && typeof pick.enterpriseId === 'string' ? pick.enterpriseId.trim() : '';
|
|
216
216
|
}
|
|
217
|
-
/** The headers WorkBuddy's
|
|
217
|
+
/** The headers WorkBuddy's chat gateway accepts: its own CLI's, nothing more. */
|
|
218
218
|
export function workbuddyHeaders(token) {
|
|
219
219
|
const headers = {
|
|
220
|
+
'Accept': 'application/json, text/plain, */*',
|
|
221
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
222
|
+
'Origin': 'https://copilot.tencent.com',
|
|
223
|
+
'Referer': 'https://copilot.tencent.com/',
|
|
224
|
+
'User-Agent': 'CLI/2.63.2 CodeBuddy/2.63.2',
|
|
225
|
+
'Content-Type': 'application/json',
|
|
220
226
|
'Authorization': `Bearer ${token.accessToken}`,
|
|
221
|
-
'X-User-Id': token.uid
|
|
227
|
+
...token.uid === undefined || token.uid === '' ? { 'X-No-User-Id': '1' } : { 'X-User-Id': token.uid },
|
|
228
|
+
...token.enterpriseId === undefined || token.enterpriseId === '' ? { 'X-No-Enterprise-Id': '1' } : { 'X-Enterprise-Id': token.enterpriseId },
|
|
222
229
|
'X-Domain': workbuddyDomain(token),
|
|
223
230
|
'X-Product': 'SaaS',
|
|
224
|
-
'X-IDE-Type': 'WorkBuddy',
|
|
225
|
-
'User-Agent': `WorkBuddy/${WORKBUDDY_UA_VERSION}`,
|
|
226
|
-
'X-Requested-With': 'XMLHttpRequest',
|
|
227
|
-
'X-Agent-Intent': 'craft',
|
|
228
|
-
'X-Agent-Purpose': 'conversation',
|
|
229
|
-
'X-IDE-Name': 'WorkBuddy',
|
|
230
|
-
'X-IDE-Version': WORKBUDDY_UA_VERSION,
|
|
231
231
|
};
|
|
232
|
-
const enterprise = typeof token.enterpriseId === 'string' ? token.enterpriseId.trim() : '';
|
|
233
|
-
if (enterprise !== '') {
|
|
234
|
-
headers['X-Enterprise-Id'] = enterprise;
|
|
235
|
-
headers['X-Tenant-Id'] = enterprise;
|
|
236
|
-
}
|
|
237
232
|
return headers;
|
|
238
233
|
}
|
|
239
234
|
/** Whether a token is close enough to its end that a request should refresh it. */
|
|
@@ -473,12 +468,14 @@ export async function readWorkBuddyCredits(token, fetchFn) {
|
|
|
473
468
|
return undefined;
|
|
474
469
|
};
|
|
475
470
|
let remaining = 0;
|
|
471
|
+
let totalSize = 0;
|
|
476
472
|
let nearestExpiryMs;
|
|
477
473
|
let livePackages = 0;
|
|
478
474
|
for (const account of accounts) {
|
|
479
475
|
const num = (key) => capacity(account[key]);
|
|
480
476
|
const monthly = num('CapacityType') === 4;
|
|
481
477
|
const remain = monthly ? num('CycleCapacityRemain') : num('CapacityRemain');
|
|
478
|
+
const size = monthly ? num('CycleCapacitySize') : num('CapacitySize');
|
|
482
479
|
const capped = remain < 0 ? 0 : remain;
|
|
483
480
|
const cycleEndMs = parseDate(account.CycleEndTime);
|
|
484
481
|
const expiresAtMs = monthly ? undefined : parseDate(account.ExpiredTime) ?? cycleEndMs;
|
|
@@ -486,6 +483,7 @@ export async function readWorkBuddyCredits(token, fetchFn) {
|
|
|
486
483
|
continue;
|
|
487
484
|
livePackages += 1;
|
|
488
485
|
remaining += capped;
|
|
486
|
+
totalSize += size > 0 ? size : capped;
|
|
489
487
|
if (expiresAtMs !== undefined && (nearestExpiryMs === undefined || expiresAtMs < nearestExpiryMs)) {
|
|
490
488
|
nearestExpiryMs = expiresAtMs;
|
|
491
489
|
}
|
|
@@ -494,7 +492,7 @@ export async function readWorkBuddyCredits(token, fetchFn) {
|
|
|
494
492
|
// account, say — so the caller falls through to its own meter.
|
|
495
493
|
if (livePackages === 0)
|
|
496
494
|
return null;
|
|
497
|
-
return { remaining, ...nearestExpiryMs === undefined ? {} : { nearestExpiryMs } };
|
|
495
|
+
return { remaining, total: totalSize, ...nearestExpiryMs === undefined ? {} : { nearestExpiryMs } };
|
|
498
496
|
}
|
|
499
497
|
/** The account's credits from its resource summary: the plan's used against granted. */
|
|
500
498
|
function usageOfSummary(summary, plan) {
|
|
@@ -542,10 +540,15 @@ export async function readWorkBuddyUsage(token, plan, fetchFn, spend) {
|
|
|
542
540
|
const credits = await readWorkBuddyCredits(token, fetchFn);
|
|
543
541
|
if (credits !== null) {
|
|
544
542
|
const window = { label: 'Credits', used: spend?.spent ?? 0 };
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
window.
|
|
543
|
+
// The bar reads spent against the total the packages grant, not remaining-plus-spent,
|
|
544
|
+
// so a fresh cycle's spend shows small against its full grant.
|
|
545
|
+
if (credits.total > 0) {
|
|
546
|
+
window.limit = credits.total;
|
|
547
|
+
window.usedPercent = (100 * (spend?.spent ?? 0)) / credits.total;
|
|
548
|
+
}
|
|
549
|
+
else if ((spend?.spent ?? 0) > 0) {
|
|
550
|
+
window.limit = spend?.spent ?? 0;
|
|
551
|
+
window.usedPercent = 100;
|
|
549
552
|
}
|
|
550
553
|
if (credits.nearestExpiryMs !== undefined)
|
|
551
554
|
window.resetsAt = credits.nearestExpiryMs;
|
|
@@ -305,8 +305,19 @@ function windowLabel(t, window) {
|
|
|
305
305
|
const key = `usage_${window.label}`;
|
|
306
306
|
return key in en ? t(key) : window.label;
|
|
307
307
|
}
|
|
308
|
-
/**
|
|
308
|
+
/** Credit-like window labels: money, not a share of an allowance. */
|
|
309
|
+
const CREDIT_WINDOW_LABELS = /credit|wallet|balance|token|point|积分|额度/i;
|
|
310
|
+
/**
|
|
311
|
+
* How much of one window is spent, as a display string.
|
|
312
|
+
*
|
|
313
|
+
* A credit balance (WorkBuddy's Credits) reads as the raw used/limit count; a time
|
|
314
|
+
* quota reads as the spent percent. Told apart by the label, since both state the
|
|
315
|
+
* same fields.
|
|
316
|
+
*/
|
|
309
317
|
function windowAmount(window) {
|
|
318
|
+
if (CREDIT_WINDOW_LABELS.test(window.label) && window.used !== undefined && window.limit !== undefined) {
|
|
319
|
+
return `${String(window.used)}/${String(window.limit)}`;
|
|
320
|
+
}
|
|
310
321
|
if (window.usedPercent !== undefined)
|
|
311
322
|
return `${String(Math.round(window.usedPercent))}%`;
|
|
312
323
|
if (window.used !== undefined && window.limit !== undefined)
|
package/lib/client.js
CHANGED
|
@@ -1341,8 +1341,17 @@ function windowLabel(t, window$1) {
|
|
|
1341
1341
|
const key = `usage_${window$1.label}`;
|
|
1342
1342
|
return key in en ? t(key) : window$1.label;
|
|
1343
1343
|
}
|
|
1344
|
-
/**
|
|
1344
|
+
/** Credit-like window labels: money, not a share of an allowance. */
|
|
1345
|
+
const CREDIT_WINDOW_LABELS = /credit|wallet|balance|token|point|积分|额度/i;
|
|
1346
|
+
/**
|
|
1347
|
+
* How much of one window is spent, as a display string.
|
|
1348
|
+
*
|
|
1349
|
+
* A credit balance (WorkBuddy's Credits) reads as the raw used/limit count; a time
|
|
1350
|
+
* quota reads as the spent percent. Told apart by the label, since both state the
|
|
1351
|
+
* same fields.
|
|
1352
|
+
*/
|
|
1345
1353
|
function windowAmount$1(window$1) {
|
|
1354
|
+
if (CREDIT_WINDOW_LABELS.test(window$1.label) && window$1.used !== void 0 && window$1.limit !== void 0) return `${String(window$1.used)}/${String(window$1.limit)}`;
|
|
1346
1355
|
if (window$1.usedPercent !== void 0) return `${String(Math.round(window$1.usedPercent))}%`;
|
|
1347
1356
|
if (window$1.used !== void 0 && window$1.limit !== void 0) return `${String(window$1.used)}/${String(window$1.limit)}`;
|
|
1348
1357
|
return "—";
|