@anthonyhaussman/opencode-agy-auth 1.0.11-alpha.2 → 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 +38 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16570,17 +16570,26 @@ function cacheThinkingSignaturesFromResponse(response, signatureSessionKey, sign
|
|
|
16570
16570
|
});
|
|
16571
16571
|
}
|
|
16572
16572
|
}
|
|
16573
|
-
function
|
|
16574
|
-
|
|
16575
|
-
|
|
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;
|
|
16576
16585
|
}
|
|
16577
|
-
const
|
|
16578
|
-
if (!
|
|
16579
|
-
return
|
|
16586
|
+
const jsonString = dataLines.join("\n").trim();
|
|
16587
|
+
if (!jsonString) {
|
|
16588
|
+
return eventText;
|
|
16580
16589
|
}
|
|
16581
16590
|
try {
|
|
16582
|
-
const parsed = JSON.parse(
|
|
16583
|
-
if (parsed.response !== void 0) {
|
|
16591
|
+
const parsed = JSON.parse(jsonString);
|
|
16592
|
+
if (parsed && typeof parsed === "object" && parsed.response !== void 0) {
|
|
16584
16593
|
if (options.cacheSignatures && options.signatureSessionKey) {
|
|
16585
16594
|
cacheThinkingSignaturesFromResponse(
|
|
16586
16595
|
parsed.response,
|
|
@@ -16604,7 +16613,7 @@ function transformSseLine(line, signatureStore, thoughtBuffer, sentThinkingBuffe
|
|
|
16604
16613
|
}
|
|
16605
16614
|
} catch (_) {
|
|
16606
16615
|
}
|
|
16607
|
-
return
|
|
16616
|
+
return eventText;
|
|
16608
16617
|
}
|
|
16609
16618
|
function createStreamingTransformer(signatureStore, callbacks, options = {}) {
|
|
16610
16619
|
const decoder2 = new TextDecoder();
|
|
@@ -16619,14 +16628,15 @@ function createStreamingTransformer(signatureStore, callbacks, options = {}) {
|
|
|
16619
16628
|
return new TransformStream({
|
|
16620
16629
|
transform(chunk, controller) {
|
|
16621
16630
|
buffer += decoder2.decode(chunk, { stream: true });
|
|
16622
|
-
const
|
|
16623
|
-
buffer =
|
|
16624
|
-
for (const
|
|
16625
|
-
if (
|
|
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")) {
|
|
16626
16636
|
hasSeenUsageMetadata = true;
|
|
16627
16637
|
}
|
|
16628
|
-
const
|
|
16629
|
-
|
|
16638
|
+
const transformedEvent = transformSseEvent(
|
|
16639
|
+
event,
|
|
16630
16640
|
signatureStore,
|
|
16631
16641
|
thoughtBuffer,
|
|
16632
16642
|
sentThinkingBuffer,
|
|
@@ -16634,16 +16644,16 @@ function createStreamingTransformer(signatureStore, callbacks, options = {}) {
|
|
|
16634
16644
|
mergedOptions,
|
|
16635
16645
|
debugState
|
|
16636
16646
|
);
|
|
16637
|
-
controller.enqueue(encoder2.encode(
|
|
16647
|
+
controller.enqueue(encoder2.encode(transformedEvent + "\n\n"));
|
|
16638
16648
|
}
|
|
16639
16649
|
},
|
|
16640
16650
|
flush(controller) {
|
|
16641
16651
|
buffer += decoder2.decode();
|
|
16642
|
-
if (buffer) {
|
|
16652
|
+
if (buffer.trim()) {
|
|
16643
16653
|
if (buffer.includes("usageMetadata")) {
|
|
16644
16654
|
hasSeenUsageMetadata = true;
|
|
16645
16655
|
}
|
|
16646
|
-
const
|
|
16656
|
+
const transformedEvent = transformSseEvent(
|
|
16647
16657
|
buffer,
|
|
16648
16658
|
signatureStore,
|
|
16649
16659
|
thoughtBuffer,
|
|
@@ -16652,25 +16662,22 @@ function createStreamingTransformer(signatureStore, callbacks, options = {}) {
|
|
|
16652
16662
|
mergedOptions,
|
|
16653
16663
|
debugState
|
|
16654
16664
|
);
|
|
16655
|
-
controller.enqueue(encoder2.encode(
|
|
16665
|
+
controller.enqueue(encoder2.encode(transformedEvent + "\n\n"));
|
|
16656
16666
|
}
|
|
16657
16667
|
if (!hasSeenUsageMetadata) {
|
|
16658
16668
|
const syntheticUsage = {
|
|
16659
|
-
|
|
16660
|
-
|
|
16661
|
-
|
|
16662
|
-
finishReason: "STOP"
|
|
16663
|
-
}
|
|
16664
|
-
],
|
|
16665
|
-
usageMetadata: {
|
|
16666
|
-
promptTokenCount: 0,
|
|
16667
|
-
candidatesTokenCount: 0,
|
|
16668
|
-
totalTokenCount: 0
|
|
16669
|
+
candidates: [
|
|
16670
|
+
{
|
|
16671
|
+
finishReason: "STOP"
|
|
16669
16672
|
}
|
|
16673
|
+
],
|
|
16674
|
+
usageMetadata: {
|
|
16675
|
+
promptTokenCount: 0,
|
|
16676
|
+
candidatesTokenCount: 0,
|
|
16677
|
+
totalTokenCount: 0
|
|
16670
16678
|
}
|
|
16671
16679
|
};
|
|
16672
|
-
controller.enqueue(encoder2.encode(`
|
|
16673
|
-
data: ${JSON.stringify(syntheticUsage)}
|
|
16680
|
+
controller.enqueue(encoder2.encode(`data: ${JSON.stringify(syntheticUsage)}
|
|
16674
16681
|
|
|
16675
16682
|
`));
|
|
16676
16683
|
}
|