dsh-github-copilot 0.4.0-alpha.34 → 0.4.0-alpha.35

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/index.js CHANGED
@@ -1131,17 +1131,15 @@ function createAccountModelAuth(credentials, renewRejectedCredential) {
1131
1131
  };
1132
1132
  }
1133
1133
  //#endregion
1134
- //#region lib/types/copilot-usage-types.js
1135
- const COPILOT_USAGE_MAX_AMOUNT = 0xe8d4a51000;
1136
- const COPILOT_USAGE_MAX_TIMESTAMP = 0xe677d21fdbff;
1137
- //#endregion
1138
1134
  //#region lib/types/copilot-usage-normalize.js
1139
- const amount = z$1.number().finite().min(0).max(COPILOT_USAGE_MAX_AMOUNT);
1135
+ const amount = z$1.number().finite().min(0).max(0xe8d4a51000);
1140
1136
  const entitlement = z$1.union([
1141
1137
  amount,
1142
1138
  z$1.literal(-1),
1143
1139
  z$1.string().max(32).regex(/^(?:-1|(?:0|[1-9]\d*)(?:\.\d+)?)$/u)
1144
1140
  ]).transform(Number).refine((value) => Number.isFinite(value) && value <= 0xe8d4a51000);
1141
+ const resetSeconds = z$1.unknown().transform((value) => typeof value === "number" && Number.isInteger(value) && value > 0 && value <= Math.floor(0xe677d21fdbff / 1e3) ? value * 1e3 : void 0);
1142
+ const resetCalendar = z$1.unknown().transform(resetDate);
1145
1143
  const snapshot = z$1.object({
1146
1144
  unlimited: z$1.boolean(),
1147
1145
  entitlement: entitlement.optional(),
@@ -1150,14 +1148,14 @@ const snapshot = z$1.object({
1150
1148
  credits_used: amount.optional(),
1151
1149
  has_quota: z$1.boolean().optional(),
1152
1150
  token_based_billing: z$1.boolean().optional(),
1153
- quota_reset_at: z$1.number().int().min(0).max(Math.floor(COPILOT_USAGE_MAX_TIMESTAMP / 1e3)).optional()
1151
+ quota_reset_at: resetSeconds.optional()
1154
1152
  });
1155
1153
  const response = z$1.object({
1156
1154
  token_based_billing: z$1.boolean().optional(),
1157
1155
  access_type_sku: z$1.string().max(128).optional(),
1158
- quota_reset_date: z$1.string().max(64).optional(),
1159
- quota_reset_date_utc: z$1.string().max(64).optional(),
1160
- limited_user_reset_date: z$1.string().max(64).optional(),
1156
+ quota_reset_date: resetCalendar.optional(),
1157
+ quota_reset_date_utc: resetCalendar.optional(),
1158
+ limited_user_reset_date: resetCalendar.optional(),
1161
1159
  quota_snapshots: z$1.object({
1162
1160
  chat: snapshot.optional(),
1163
1161
  premium_interactions: snapshot.optional()
@@ -1174,7 +1172,7 @@ function unavailableCopilotUsage(diagnostic, billing = "unknown", budget = "unkn
1174
1172
  };
1175
1173
  }
1176
1174
  function resetDate(value) {
1177
- if (!/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2}))?$/u.test(value)) return void 0;
1175
+ if (typeof value !== "string" || value.length > 64 || !/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2}))?$/u.test(value)) return void 0;
1178
1176
  const date = value.slice(0, 10);
1179
1177
  const day = Date.parse(`${date}T00:00:00Z`);
1180
1178
  if (!Number.isFinite(day) || new Date(day).toISOString().slice(0, 10) !== date) return void 0;
@@ -1193,10 +1191,12 @@ function normalizeCopilotUsage(input, observedAt) {
1193
1191
  if (data.token_based_billing === void 0) return unavailableCopilotUsage("COPILOT_USAGE_BILLING_UNKNOWN");
1194
1192
  const billing = data.token_based_billing ? "credits" : "requests";
1195
1193
  const quota = data.access_type_sku === "free_limited_copilot" ? data.quota_snapshots?.chat : data.quota_snapshots?.premium_interactions;
1196
- const reset = data.quota_reset_date_utc ?? data.quota_reset_date ?? data.limited_user_reset_date;
1197
- const accountReset = reset === void 0 ? void 0 : resetDate(reset);
1198
- if (reset !== void 0 && accountReset === void 0) return unavailableCopilotUsage("COPILOT_USAGE_INVALID_RESPONSE", billing);
1199
- const resetAt = quota?.quota_reset_at === void 0 ? accountReset : quota.quota_reset_at * 1e3;
1194
+ const resetAt = [
1195
+ quota?.quota_reset_at,
1196
+ data.quota_reset_date_utc,
1197
+ data.quota_reset_date,
1198
+ data.limited_user_reset_date
1199
+ ].find((value) => value !== void 0 && value > observedAt);
1200
1200
  const dates = {
1201
1201
  observedAt,
1202
1202
  ...resetAt === void 0 ? {} : { resetAt }
@@ -1600,7 +1600,7 @@ let GitHubCopilotUsageController = (() => {
1600
1600
  //#endregion
1601
1601
  //#region package.json
1602
1602
  var name$1 = "dsh-github-copilot";
1603
- var version = "0.4.0-alpha.34";
1603
+ var version = "0.4.0-alpha.35";
1604
1604
  //#endregion
1605
1605
  //#region lib/types/probe.js
1606
1606
  /**
@@ -7,7 +7,7 @@ export interface CopilotUsageView {
7
7
  readonly remaining?: number;
8
8
  readonly limit?: number;
9
9
  readonly percentUsed?: number;
10
- /** Unix epoch milliseconds, only when explicitly reported by the supplier. */
10
+ /** Supplier-reported next reset in Unix epoch milliseconds, later than observedAt. */
11
11
  readonly resetAt?: number;
12
12
  readonly observedAt?: number;
13
13
  readonly diagnostic?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-github-copilot",
3
3
  "description": "DSH companion for GitHub Copilot sign-in, account-aware model profiles, tool compatibility, and provider-hosted search.",
4
- "version": "0.4.0-alpha.34",
4
+ "version": "0.4.0-alpha.35",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "registry": "https://registry.npmjs.org/",