@magpie-community/opencode-qoder-auth 0.2.5 → 0.2.6

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.
Files changed (2) hide show
  1. package/index.mjs +7 -4
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -576,11 +576,14 @@ function qoderMessages(msgs) {
576
576
  // (Qoder: changing the Context "may change the rate"), so it is asked for
577
577
  // only when the conversation needs it. The request's size is counted
578
578
  // generously, a token for every 3 bytes of its UTF-8 JSON, so a window is
579
- // raised a little early rather than late.
580
- function windowFor(chat, m) {
579
+ // raised a little early rather than late, and the reply's max_tokens is
580
+ // counted in it: a window holds the prompt and the reply, so a
581
+ // conversation of 180K asking 32K for the reply is sent 400K, not the 200K
582
+ // it would overflow while magpie says the model takes 1M (yetone/magpie#700).
583
+ function windowFor(chat, m, reply = 0) {
581
584
  const base = m.defaultWindow || (m.config?.max_input_tokens > 0 ? m.config.max_input_tokens : 0) || m.context
582
585
  if (!m.windows?.length) return m.context
583
- const need = Math.ceil(Buffer.byteLength(JSON.stringify({ m: chat.messages ?? [], t: chat.tools ?? [] })) / 3)
586
+ const need = Math.ceil(Buffer.byteLength(JSON.stringify({ m: chat.messages ?? [], t: chat.tools ?? [] })) / 3) + Math.max(0, reply)
584
587
  if (base > 0 && need <= base) return base
585
588
  return m.windows.find((w) => w >= need) ?? m.windows[m.windows.length - 1]
586
589
  }
@@ -596,7 +599,7 @@ function qoderBody(chat, m) {
596
599
  const [thinking, effort] = effortFor(chat.reasoning_effort, m)
597
600
  const params = { enable_thinking: thinking, max_tokens: chat.max_completion_tokens || chat.max_tokens || 32000 }
598
601
  if (effort) params.reasoning_effort = effort
599
- const window = windowFor(chat, m)
602
+ const window = windowFor(chat, m, params.max_tokens)
600
603
  if (window > 0) params.context_length = window
601
604
  const body = {
602
605
  parameters: params,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-qoder-auth",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Qoder subscriptions in OpenCode and magpie: Qoder (qoder.com) and Qoder CN (qoder.cn)",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",