@anthonyhaussman/opencode-agy-auth 1.0.11-alpha.1 → 1.0.11-alpha.3

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/index.js CHANGED
@@ -14161,6 +14161,9 @@ async function fetchTokenRefresh(refreshToken) {
14161
14161
 
14162
14162
  // src/plugin/quota-utils.ts
14163
14163
  function clamp(value, min, max) {
14164
+ if (Number.isNaN(value)) {
14165
+ return min;
14166
+ }
14164
14167
  if (value < min) {
14165
14168
  return min;
14166
14169
  }
@@ -14185,7 +14188,7 @@ function formatRemainingAmount(value) {
14185
14188
  if (!value) {
14186
14189
  return void 0;
14187
14190
  }
14188
- const parsed = Number.parseInt(value, 10);
14191
+ const parsed = Number(value);
14189
14192
  if (!Number.isFinite(parsed)) {
14190
14193
  return value;
14191
14194
  }
@@ -14527,7 +14530,8 @@ function windowLabel(window) {
14527
14530
  }
14528
14531
  function formatSummaryBucket(bucket, indent) {
14529
14532
  if (bucket.disabled) {
14530
- const desc = bucket.description?.trim() || "weekly limit exhausted";
14533
+ const defaultDesc = `${windowLabel(bucket.window).toLowerCase()} exhausted`;
14534
+ const desc = bucket.description?.trim() || defaultDesc;
14531
14535
  return [`${indent}Disabled: ${desc}`];
14532
14536
  }
14533
14537
  const lines = [];
@@ -14552,7 +14556,8 @@ function formatSummaryBucket(bucket, indent) {
14552
14556
  }
14553
14557
  const resetLabel = formatRelativeResetTime(bucket.resetTime);
14554
14558
  if (resetLabel) {
14555
- lines.push(`${indent}${resetLabel.replace("resets in ", "Refreshes in ")}`);
14559
+ const formattedReset = resetLabel.startsWith("resets in ") ? resetLabel.replace("resets in ", "Refreshes in ") : resetLabel.charAt(0).toUpperCase() + resetLabel.slice(1);
14560
+ lines.push(`${indent}${formattedReset}`);
14556
14561
  }
14557
14562
  return lines;
14558
14563
  }
@@ -14601,7 +14606,8 @@ function formatSummaryGroup(group) {
14601
14606
  lines.push("");
14602
14607
  }
14603
14608
  for (const bucket of windowBuckets) {
14604
- const label = windowLabel(bucket.window);
14609
+ const baseLabel = windowLabel(bucket.window);
14610
+ const label = bucket.displayName ? `${baseLabel} (${bucket.displayName})` : baseLabel;
14605
14611
  lines.push(` ${label}`);
14606
14612
  lines.push(...formatSummaryBucket(bucket, " "));
14607
14613
  firstWindow = false;
@@ -14619,7 +14625,8 @@ function formatTopLevelBuckets(buckets) {
14619
14625
  lines.push("");
14620
14626
  }
14621
14627
  for (const bucket of windowBuckets) {
14622
- const label = windowLabel(bucket.window);
14628
+ const baseLabel = windowLabel(bucket.window);
14629
+ const label = bucket.displayName ? `${baseLabel} (${bucket.displayName})` : baseLabel;
14623
14630
  lines.push(label);
14624
14631
  lines.push(...formatSummaryBucket(bucket, " "));
14625
14632
  firstWindow = false;
@@ -14641,7 +14648,6 @@ function formatAgyQuotaSummaryOutput(projectId, summary) {
14641
14648
  }
14642
14649
  if (i > 0) {
14643
14650
  lines.push("");
14644
- lines.push("");
14645
14651
  }
14646
14652
  lines.push(...formatSummaryGroup(group));
14647
14653
  }
@@ -16564,17 +16570,26 @@ function cacheThinkingSignaturesFromResponse(response, signatureSessionKey, sign
16564
16570
  });
16565
16571
  }
16566
16572
  }
16567
- function transformSseLine(line, signatureStore, thoughtBuffer, sentThinkingBuffer, callbacks, options, debugState) {
16568
- if (!line.startsWith("data:")) {
16569
- return line;
16573
+ function transformSseEvent(eventText, signatureStore, thoughtBuffer, sentThinkingBuffer, callbacks, options, debugState) {
16574
+ const dataLines = [];
16575
+ const lines = eventText.split(/\r?\n/);
16576
+ let isDataEvent = false;
16577
+ for (const line of lines) {
16578
+ if (line.startsWith("data:")) {
16579
+ isDataEvent = true;
16580
+ dataLines.push(line.slice(5).trim());
16581
+ }
16582
+ }
16583
+ if (!isDataEvent) {
16584
+ return eventText;
16570
16585
  }
16571
- const json2 = line.slice(5).trim();
16572
- if (!json2) {
16573
- return line;
16586
+ const jsonString = dataLines.join("\n").trim();
16587
+ if (!jsonString) {
16588
+ return eventText;
16574
16589
  }
16575
16590
  try {
16576
- const parsed = JSON.parse(json2);
16577
- if (parsed.response !== void 0) {
16591
+ const parsed = JSON.parse(jsonString);
16592
+ if (parsed && typeof parsed === "object" && parsed.response !== void 0) {
16578
16593
  if (options.cacheSignatures && options.signatureSessionKey) {
16579
16594
  cacheThinkingSignaturesFromResponse(
16580
16595
  parsed.response,
@@ -16598,7 +16613,7 @@ function transformSseLine(line, signatureStore, thoughtBuffer, sentThinkingBuffe
16598
16613
  }
16599
16614
  } catch (_) {
16600
16615
  }
16601
- return line;
16616
+ return eventText;
16602
16617
  }
16603
16618
  function createStreamingTransformer(signatureStore, callbacks, options = {}) {
16604
16619
  const decoder2 = new TextDecoder();
@@ -16613,14 +16628,15 @@ function createStreamingTransformer(signatureStore, callbacks, options = {}) {
16613
16628
  return new TransformStream({
16614
16629
  transform(chunk, controller) {
16615
16630
  buffer += decoder2.decode(chunk, { stream: true });
16616
- const lines = buffer.split("\n");
16617
- buffer = lines.pop() || "";
16618
- for (const line of lines) {
16619
- if (line.includes("usageMetadata")) {
16631
+ const events = buffer.split(/\r?\n\r?\n/);
16632
+ buffer = events.pop() || "";
16633
+ for (const event of events) {
16634
+ if (!event.trim()) continue;
16635
+ if (event.includes("usageMetadata")) {
16620
16636
  hasSeenUsageMetadata = true;
16621
16637
  }
16622
- const transformedLine = transformSseLine(
16623
- line,
16638
+ const transformedEvent = transformSseEvent(
16639
+ event,
16624
16640
  signatureStore,
16625
16641
  thoughtBuffer,
16626
16642
  sentThinkingBuffer,
@@ -16628,16 +16644,16 @@ function createStreamingTransformer(signatureStore, callbacks, options = {}) {
16628
16644
  mergedOptions,
16629
16645
  debugState
16630
16646
  );
16631
- controller.enqueue(encoder2.encode(transformedLine + "\n"));
16647
+ controller.enqueue(encoder2.encode(transformedEvent + "\n\n"));
16632
16648
  }
16633
16649
  },
16634
16650
  flush(controller) {
16635
16651
  buffer += decoder2.decode();
16636
- if (buffer) {
16652
+ if (buffer.trim()) {
16637
16653
  if (buffer.includes("usageMetadata")) {
16638
16654
  hasSeenUsageMetadata = true;
16639
16655
  }
16640
- const transformedLine = transformSseLine(
16656
+ const transformedEvent = transformSseEvent(
16641
16657
  buffer,
16642
16658
  signatureStore,
16643
16659
  thoughtBuffer,
@@ -16646,25 +16662,22 @@ function createStreamingTransformer(signatureStore, callbacks, options = {}) {
16646
16662
  mergedOptions,
16647
16663
  debugState
16648
16664
  );
16649
- controller.enqueue(encoder2.encode(transformedLine));
16665
+ controller.enqueue(encoder2.encode(transformedEvent + "\n\n"));
16650
16666
  }
16651
16667
  if (!hasSeenUsageMetadata) {
16652
16668
  const syntheticUsage = {
16653
- response: {
16654
- candidates: [
16655
- {
16656
- finishReason: "STOP"
16657
- }
16658
- ],
16659
- usageMetadata: {
16660
- promptTokenCount: 0,
16661
- candidatesTokenCount: 0,
16662
- totalTokenCount: 0
16669
+ candidates: [
16670
+ {
16671
+ finishReason: "STOP"
16663
16672
  }
16673
+ ],
16674
+ usageMetadata: {
16675
+ promptTokenCount: 0,
16676
+ candidatesTokenCount: 0,
16677
+ totalTokenCount: 0
16664
16678
  }
16665
16679
  };
16666
- controller.enqueue(encoder2.encode(`
16667
- data: ${JSON.stringify(syntheticUsage)}
16680
+ controller.enqueue(encoder2.encode(`data: ${JSON.stringify(syntheticUsage)}
16668
16681
 
16669
16682
  `));
16670
16683
  }