From 29555323441137d4efecd8989cb91fd4a24bd156 Mon Sep 17 00:00:00 2001 From: liangmouse <122550407+liangmouse@users.noreply.github.com> Date: Wed, 4 Nov 2026 14:48:43 +0800 Subject: [PATCH] joycode 0.2.5: verified Astra and DeepSeek context windows from the account catalogue (#707) GPT-6 Astra and DeepSeek-V4.1-Flash take a larger limit.context when the account's own catalogue offers one in extJson.contextWindowByPlatform["JoyCode Desktop"]: the smaller of that and a measured cap (900,000 / 1,000,000), floored to 100k, never below the catalogue's maxTotalTokens. Output limits, other models, malformed or missing metadata and the static fallback are unchanged. The caps come from the author's real probes (Astra ok at 921,497 input, context_length_exceeded near 922k; DeepSeek ok at 1,000,073, its error names 1,048,576). Claude-Opus-5-hq stays at 200k (its 900k probe was refused). Review: no new host, credential, dependency or workflow change; version 0.2.5 is free (main 0.2.4, dist has up to 0.2.4). Run at bdfb41d8 on mote: packages/joycode bun test 76 pass 0 fail; bun scripts/check.mjs ok. Broken by hand: context back to the catalogue's maxTotalTokens turns the two new context tests red (2 fail). Not tried: no JoyCode account here, so the catalogue's contextWindowByPlatform field and the probes were not re-run by the reviewer. --- packages/joycode/CHANGELOG.md | 5 +++ packages/joycode/README.md | 13 +++++++ packages/joycode/index.mjs | 27 ++++++++++++-- packages/joycode/models.test.mjs | 64 ++++++++++++++++++++++++++++++++ packages/joycode/package.json | 2 +- 5 files changed, 107 insertions(+), 4 deletions(-) diff --git a/packages/joycode/CHANGELOG.md b/packages/joycode/CHANGELOG.md index 8dbda71..a9ed757 100644 --- a/packages/joycode/CHANGELOG.md +++ b/packages/joycode/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新记录 +## 0.2.5 + +- 对账号目录声明长窗口且真实请求成功的 GPT-6 Astra 和 DeepSeek-V4.1-Flash,分别采用最高 900k / 1,000k 的保守上下文声明;按 100k 向下取整,输出上限不变。未知模型和静态回退不变。 +- 验证:Astra 实际输入 921,497 Token、DeepSeek 实际输入 1,000,073 Token 均正常结束并找回三个标记。Claude 900k 请求返回拒绝,未作为通过证据,暂不提高。未重跑原 Codex 长会话压缩。 + ## 0.2.4 - 从额度接口的有效期文字解析套餐到期时间。账号卡片悬停用量时显示「N 积分 将于 … 过期」(中国时区当天 23:59:59),并写入 magpie 的 `until`。套餐行优先,否则取最早的一份。不写成「重置于」,也不当成额度窗口的重置时间。 diff --git a/packages/joycode/README.md b/packages/joycode/README.md index 7ac2a70..49da55f 100644 --- a/packages/joycode/README.md +++ b/packages/joycode/README.md @@ -41,6 +41,19 @@ magpie plugin login joycode **视觉(image_url)为实验性**:按接口 `features` 声明能力,实际图片请求尚未验收。 +## 已验证的长上下文 + +只有账号目录 `extJson.contextWindowByPlatform["JoyCode Desktop"]` 明确提供有效的更大窗口时,插件才对已验证的精确模型 ID 提高 `limit.context`。取目录窗口和验证上限的较小值,向下取整到 100,000 Token;其他模型和离线回退不变,也不覆盖原本更大的目录声明。输出上限仍使用 `respMaxTokens`。 + +| 模型 ID | 保守的 context 声明 | 真实网关验证 | +|---|---:|---| +| `GPT-6 Astra` | 900,000 | 最大成功输入 921,497 Token;约 922,008 Token 填充加指令返回 `context_length_exceeded` | +| `DeepSeek-V4.1-Flash` | 1,000,000 | 输入 1,000,073 Token,输出 150 Token,正常结束;更大请求明确报总窗口 1,048,576 Token | + +2026-11-04 经本机 magpie 的 `/v1/responses` / `/v1/chat/completions` 请求 JoyCode,用合成文本中三个分散的随机标记验证返回内容。两者均返回全部正确标记和正常终止事件。GPT 使用 `low`,两者输出预算为 256 Token。这是当前账号、通道和请求参数下的输入能力实测,不是所有账号的保证,也没有验证最大输出预算下的边界或复杂长上下文推理质量。`limit.context` 使用不高于成功输入长度的保守值,并非声称测得模型精确总窗口;宿主仍需为输出和额外提示预留空间。 + +`Claude-Opus-5-hq` 接收并计量约 900k 输入,但返回 `stop_reason: refusal`、没有文本,不能视为功能验证通过,暂不提高其窗口。其他 GPT、Claude、DeepSeek 别名不能继承上述实测结论。长上下文会增加实际 Token 用量,且缓存命中也可能计入账号额度。 + ## 消息转发策略 根据 2026-10-30 的 JoyCode 实测,仅对 Responses 协议做以下兼容:GPT-6 Astra、GPT-6.1 Sol 的显式 `none` / `minimal` 转为 `low`;GPT-6 Sol、GPT-5.6 Sol 仅将 `minimal` 转为 `low`,保留上游接受的 `none`。其他 reasoning 参数、有效或未指定的强度、未知模型和其他协议均不变。启用低档推理可能增加用量。此表基于当前账号目录,不自动覆盖未来新增模型。 diff --git a/packages/joycode/index.mjs b/packages/joycode/index.mjs index c1282ee..718bd28 100644 --- a/packages/joycode/index.mjs +++ b/packages/joycode/index.mjs @@ -49,6 +49,12 @@ const LOW_EFFORT_FALLBACKS = new Map([ ['GPT-5.6 Sol', ['minimal']], ]) +// Input lengths verified against JoyCode; conservative context claims, not exact model limits. +const VERIFIED_CONTEXT_LIMITS = new Map([ + ['GPT-6 Astra', 900000], + ['DeepSeek-V4.1-Flash', 1000000], +]) + // HMAC signing key, extracted from the JoyCode IDE's bundled extension.js. // // This is a PUBLIC PROTOCOL CONSTANT, not a secret: it is baked into every @@ -139,12 +145,17 @@ function buildGatewayHeaders(ptKey, tenant, loginType = LOGIN_TYPE) { } } -/** JoyCode's model catalogue names the wire protocol in extJson.adapterType. */ -function adapterProtocol(model) { +function modelExtJson(model) { let ext = model?.extJson if (typeof ext === 'string') { try { ext = JSON.parse(ext) } catch { ext = undefined } } + return ext +} + +/** JoyCode's model catalogue names the wire protocol in extJson.adapterType. */ +function adapterProtocol(model) { + const ext = modelExtJson(model) const type = ext?.adapterType ?? model?.adapterType if (typeof type !== 'string') return 'chat' if (type === 'anthropic') return 'anthropic' @@ -152,6 +163,15 @@ function adapterProtocol(model) { return 'chat' } +function accountContext(model, baseContext) { + const verifiedLimit = VERIFIED_CONTEXT_LIMITS.get(model?.chatApiModel) + const directoryContext = modelExtJson(model)?.contextWindowByPlatform?.['JoyCode Desktop'] + if (verifiedLimit === undefined || !Number.isFinite(directoryContext) || directoryContext <= 0 || + !Number.isFinite(baseContext) || baseContext <= 0 || directoryContext <= baseContext) return baseContext + const conservativeLimit = Math.floor(Math.min(directoryContext, verifiedLimit) / 100000) * 100000 + return Math.max(baseContext, conservativeLimit) +} + function requestPath(input) { try { return input instanceof Request ? new URL(input.url).pathname : new URL(String(input)).pathname @@ -751,6 +771,7 @@ async function accountModels(provider, { auth } = {}) { const image = features.includes('vision') const rate = multiplier(model.billingRate) ?? rates.get(id) const protocol = adapterProtocol(model) + const baseContext = Number.isFinite(model.maxTotalTokens) ? model.maxTotalTokens : base.limit?.context ?? 200000 // Remove old rate fields so unavailable pricing never becomes fake free usage. const { rate: oldRate, rateWas, free, ...rest } = base models[id] = { @@ -760,7 +781,7 @@ async function accountModels(provider, { auth } = {}) { api: { id, url: `${BASE}/v1`, npm: SDK[protocol] }, limit: { ...base.limit, - context: Number.isFinite(model.maxTotalTokens) ? model.maxTotalTokens : base.limit?.context ?? 200000, + context: accountContext(model, baseContext), output: Number.isFinite(model.respMaxTokens) ? model.respMaxTokens : base.limit?.output ?? 64000, }, capabilities: { diff --git a/packages/joycode/models.test.mjs b/packages/joycode/models.test.mjs index 1510e04..56ae335 100644 --- a/packages/joycode/models.test.mjs +++ b/packages/joycode/models.test.mjs @@ -50,6 +50,70 @@ test('model adapter chooses the SDK that speaks its upstream protocol', async t assert.equal(models['Claude-Opus-5-hq'].api.npm, '@ai-sdk/anthropic') for (const model of Object.values(models)) assert.equal(model.api.url, 'https://api-ai.jd.com/v1') }) +test('raises context only for exact input-verified models and preserves output limits', async t => { + const { models } = await load(t, { list: [ + { + chatApiModel: 'GPT-6 Astra', maxTotalTokens: 200000, respMaxTokens: 17000, + extJson: { contextWindowByPlatform: { 'JoyCode Desktop': 1500000 } }, + }, + { + chatApiModel: 'DeepSeek-V4.1-Flash', maxTotalTokens: 200000, respMaxTokens: 18000, + extJson: JSON.stringify({ + adapterType: 'openai-response', + contextWindowByPlatform: { 'JoyCode Desktop': 1500000 }, + }), + }, + { + chatApiModel: 'GPT-6 Astra-preview', maxTotalTokens: 200000, respMaxTokens: 19000, + extJson: { contextWindowByPlatform: { 'JoyCode Desktop': 2000000 } }, + }, + { + chatApiModel: 'Claude-Opus-5-hq', maxTotalTokens: 200000, respMaxTokens: 20000, + extJson: { adapterType: 'anthropic', contextWindowByPlatform: { 'JoyCode Desktop': 2000000 } }, + }, + ] }) + assert.equal(models['GPT-6 Astra'].limit.context, 900000) + assert.equal(models['DeepSeek-V4.1-Flash'].limit.context, 1000000) + assert.equal(models['GPT-6 Astra-preview'].limit.context, 200000) + assert.equal(models['Claude-Opus-5-hq'].limit.context, 200000) + assert.equal(models['GPT-6 Astra'].limit.output, 17000) + assert.equal(models['DeepSeek-V4.1-Flash'].limit.output, 18000) + assert.equal(models['DeepSeek-V4.1-Flash'].api.npm, '@ai-sdk/openai') +}) +test('floors smaller directory limits and preserves larger base contexts', async t => { + const { models } = await load(t, { list: [ + { + chatApiModel: 'GPT-6 Astra', maxTotalTokens: 200000, respMaxTokens: 17000, + extJson: { contextWindowByPlatform: { 'JoyCode Desktop': 850000 } }, + }, + { + chatApiModel: 'DeepSeek-V4.1-Flash', maxTotalTokens: 1200000, respMaxTokens: 18000, + extJson: { contextWindowByPlatform: { 'JoyCode Desktop': 1300000 } }, + }, + ] }) + assert.equal(models['GPT-6 Astra'].limit.context, 800000) + assert.equal(models['DeepSeek-V4.1-Flash'].limit.context, 1200000) + assert.equal(models['GPT-6 Astra'].limit.output, 17000) + assert.equal(models['DeepSeek-V4.1-Flash'].limit.output, 18000) +}) +test('requires a valid numeric JoyCode Desktop directory context', async t => { + const cases = [ + { name: 'missing extJson', id: 'GPT-6 Astra' }, + { name: 'malformed extJson JSON', id: 'DeepSeek-V4.1-Flash', extJson: '{' }, + { name: 'missing platform entry', id: 'GPT-6 Astra', extJson: {} }, + { name: 'numeric string', id: 'DeepSeek-V4.1-Flash', extJson: { contextWindowByPlatform: { 'JoyCode Desktop': '1000000' } } }, + { name: 'nonpositive context', id: 'GPT-6 Astra', extJson: { contextWindowByPlatform: { 'JoyCode Desktop': 0 } } }, + ] + for (const scenario of cases) { + await t.test(scenario.name, async t => { + const model = { chatApiModel: scenario.id, maxTotalTokens: 200000, respMaxTokens: 12000 } + if (Object.hasOwn(scenario, 'extJson')) model.extJson = scenario.extJson + const { models } = await load(t, { list: [model] }) + assert.equal(models[scenario.id].limit.context, 200000) + assert.equal(models[scenario.id].limit.output, 12000) + }) + } +}) test('excluded tenants do not inherit public pricing', async t => { const { models } = await load(t, { tenant: 'JD' }) assert.equal(models['GLM-5.3-agent'].rate, undefined) diff --git a/packages/joycode/package.json b/packages/joycode/package.json index af363b8..61f007c 100644 --- a/packages/joycode/package.json +++ b/packages/joycode/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-joycode-auth", - "version": "0.2.4", + "version": "0.2.5", "description": "OpenCode provider plugin: JoyCode (JD Cloud JoyCoder IDE credits)", "type": "module", "main": "./opencode.mjs",