@magpie-community/opencode-qoder-auth 0.2.3 → 0.2.4
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/index.mjs +15 -7
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -726,6 +726,7 @@ async function* events(body) {
|
|
|
726
726
|
yield { error: failure(Number(env.statusCodeValue), inner || payload) }
|
|
727
727
|
return
|
|
728
728
|
}
|
|
729
|
+
if (inner.trim() === "[DONE]") break
|
|
729
730
|
let chunk
|
|
730
731
|
try {
|
|
731
732
|
chunk = JSON.parse(inner)
|
|
@@ -749,12 +750,19 @@ async function* events(body) {
|
|
|
749
750
|
yield { tool: { index: ++index, id: tc.id || "call_" + hexID(), name: tc.function?.name ?? "", args: tc.function?.arguments ?? "" } }
|
|
750
751
|
} else if (tc.function?.arguments) yield { args: { index, text: tc.function.arguments } }
|
|
751
752
|
}
|
|
752
|
-
fr = chunk?.choices?.[0]?.finish_reason
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
753
|
+
fr = chunk?.choices?.[0]?.finish_reason || fr
|
|
754
|
+
// the usage comes in a chunk of its own after the finish, with no
|
|
755
|
+
// choices, as the built-in read it (qoder.go): every request was
|
|
756
|
+
// counted as 0 tokens when the finish ended the reading
|
|
757
|
+
const u = chunk?.usage
|
|
758
|
+
if (u)
|
|
759
|
+
usage = {
|
|
760
|
+
prompt_tokens: u.prompt_tokens ?? 0,
|
|
761
|
+
completion_tokens: u.completion_tokens ?? 0,
|
|
762
|
+
total_tokens: (u.prompt_tokens ?? 0) + (u.completion_tokens ?? 0),
|
|
763
|
+
...(u.prompt_tokens_details?.cached_tokens ? { prompt_tokens_details: { cached_tokens: u.prompt_tokens_details.cached_tokens } } : {}),
|
|
764
|
+
...(u.completion_tokens_details?.reasoning_tokens ? { completion_tokens_details: { reasoning_tokens: u.completion_tokens_details.reasoning_tokens } } : {}),
|
|
765
|
+
}
|
|
758
766
|
}
|
|
759
767
|
yield* flushed()
|
|
760
768
|
yield { stop: a.sawTool ? "tool_calls" : fr === "length" ? "length" : "stop", usage }
|
|
@@ -1245,4 +1253,4 @@ export const QoderAuthPlugin = makePlugin(SITES.qoder)
|
|
|
1245
1253
|
export const QoderCNAuthPlugin = makePlugin(SITES["qoder-cn"])
|
|
1246
1254
|
|
|
1247
1255
|
// for tests
|
|
1248
|
-
export const _internal = { parseUsage, gfmt, when, failure, modelInfo, SITES, decodeBody }
|
|
1256
|
+
export const _internal = { parseUsage, gfmt, when, failure, modelInfo, SITES, decodeBody, events }
|
package/package.json
CHANGED