diff --git a/packages/kimi-work/README.md b/packages/kimi-work/README.md index 08eb7ef..60d8463 100644 --- a/packages/kimi-work/README.md +++ b/packages/kimi-work/README.md @@ -17,7 +17,7 @@ Version 0.1.4 preserves the calling agent's shared instructions, prompts, histor An inference HTTP 401 marks the provider sign-in as expired (`kimi_work_login_expired`). Sign in to desktop Work if needed, then **reconnect Kimi Work in Magpie** (or run `magpie plugin login kimi-work`); signing in to the desktop alone does not reconnect the provider. Other HTTP errors, including 429 and 5xx, pass through unchanged with Kimi's status, headers, body and Retry-After. This preserves the distinction between concurrency limits and exhausted allowance, including any upstream reset details. Network failures use `kimi_work_connection_failed` and retain the underlying cause code or fetch error message for diagnosis. Rate limits and service failures do not invalidate the desktop sign-in. Cancellation stays cancellation. No automatic retry sends a conversation twice or falls back to Code. -Models use standard context, capped at 262,144 tokens, rather than silently enabling the higher-priced XL context. The fallback model is `kimi-work/k3-agent`; the signed-in account's live catalog replaces it. +Models use standard context, capped at 262,144 tokens, rather than silently enabling the higher-priced XL context. Until the signed-in account's live catalog is read, and when it can't be, the models offered are `kimi-work/k3-agent` and `kimi-work/k2d8-preview`, the two ids Work's `/models` has listed; the live catalog replaces them, so a model Kimi adds to the account (such as K3.1 Pro) shows under its own id. Since 0.1.6 a model whose reasoning levels come in a shape not seen before keeps the levels that can be read, rather than the whole catalog failing over to the fallback. Usage comes from Kimi's membership `GetSubscriptionStats` endpoint and is labelled **shared membership allowance**, not a separate free Work allowance. No reset time is reported: `subscriptionBalance.expireTime` and `upcomingExpiration.timestamp` are expiration fields, and have not been verified to describe allowance resets. An observed Windows request was classified by Kimi as `FEATURE_WORK` while the Code five-hour and weekly ratios stayed unchanged. This is an observation, not a promise about future quota accounting: Kimi controls billing, shared allowances, access and rate limits. diff --git a/packages/kimi-work/index.mjs b/packages/kimi-work/index.mjs index 889f5cf..71803a5 100644 --- a/packages/kimi-work/index.mjs +++ b/packages/kimi-work/index.mjs @@ -200,13 +200,15 @@ function modelRows(payload) { if(!Array.isArray(payload?.data)||payload.has_more||payload.data.length>100) throw Error('Kimi Work 模型目录暂不可用。'); const out={}; for(const m of payload.data) { - if(typeof m.id!=='string'||!m.id||m.id.length>256||/[\x00-\x20/]/.test(m.id)) continue; + if(!isObj(m)||typeof m.id!=='string'||!m.id||m.id.length>256||/[\x00-\x20/]/.test(m.id)) continue; + // One model's effort list in a shape not seen before costs that model + // its unreadable levels, not the account its whole catalog: a throw + // here left only the fallback k3-agent listed. Only levels Kimi lists + // are kept, so none is guessed. const variants=Object.create(null); - if(m.reasoningEffortOptions!==undefined&&!Array.isArray(m.reasoningEffortOptions))throw Error('Kimi Work 思考档位格式无效。'); - for(const x of m.reasoningEffortOptions||[]) { - const effort=String(x.effort||'').replace(/^REASONING_EFFORT_/,'').toLowerCase(); - if(!/^[a-z][a-z0-9_-]{0,63}$/.test(effort))throw Error('Kimi Work 思考档位格式无效。'); - variants[effort]={reasoningEffort:effort}; + for(const x of Array.isArray(m.reasoningEffortOptions)?m.reasoningEffortOptions:[]) { + const effort=String(isObj(x)&&typeof x.effort==='string'?x.effort:'').replace(/^REASONING_EFFORT_/,'').toLowerCase(); + if(/^[a-z][a-z0-9_-]{0,63}$/.test(effort))variants[effort]={reasoningEffort:effort}; } out[m.id]={id:m.id,name:m.display_name||m.id, api:{id:m.id,url:BASE,npm:'@ai-sdk/openai-compatible'}, @@ -243,7 +245,10 @@ function createPlugin({readSession=readDesktop,fetchImpl=globalThis.fetch}={}) { config:async cfg=>{ cfg.provider??={}; cfg.provider[ID]??={name:'Kimi Work',npm:'@ai-sdk/openai-compatible',api:BASE, - models:{'k3-agent':{name:'K3 · Work',limit:{context:262144,output:32768},tool_call:true,reasoning:true}}}; + // Shown until the account's own list is read, and kept when it can't + // be: the two ids Work's /models has listed (tests/fixtures). + models:{'k3-agent':{name:'K3 · Work',limit:{context:262144,output:32768},tool_call:true,reasoning:true}, + 'k2d8-preview':{name:'K2.8 Preview · Work',limit:{context:262144,output:32768},tool_call:true,reasoning:true}}}; }, auth:{ provider:ID, diff --git a/packages/kimi-work/package.json b/packages/kimi-work/package.json index a144635..eedeec6 100644 --- a/packages/kimi-work/package.json +++ b/packages/kimi-work/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-kimi-work-auth", - "version": "0.1.5", + "version": "0.1.6", "type": "module", "main": "./index.mjs", "files": [ diff --git a/packages/kimi-work/tests/provider.test.mjs b/packages/kimi-work/tests/provider.test.mjs index 0e8ab8f..949d4cf 100644 --- a/packages/kimi-work/tests/provider.test.mjs +++ b/packages/kimi-work/tests/provider.test.mjs @@ -112,3 +112,25 @@ test('Request inputs preserve body, safe headers and cancellation while replacin await expect(loader.fetch(new Request(I.BASE+'/chat/completions',{method:'GET'}))).rejects.toThrow(); expect(calls).toHaveLength(1); }); + +test('one model with effort levels in an unseen shape does not cost the account its catalog',()=>{ + const payload=JSON.parse(fs.readFileSync(new URL('./fixtures/work-models.redacted.json',import.meta.url),'utf8')); + const odd=[ + {...payload.data[0],id:'synthetic-no-effort',reasoningEffortOptions:[{displayName:'Max'},null,{effort:'REASONING_EFFORT_MAX'}]}, + {...payload.data[0],id:'synthetic-object-efforts',reasoningEffortOptions:{low:true}}, + null,'k3-agent', + ]; + const rows=I.modelRows({data:[...payload.data,...odd]}); + expect(Object.keys(rows)).toEqual(['k3-agent','k2d8-preview','synthetic-no-effort','synthetic-object-efforts']); + expect(rows['synthetic-no-effort'].variants).toEqual({max:{reasoningEffort:'max'}}); + expect(rows['synthetic-object-efforts'].variants).toEqual({}); + expect(Object.keys(rows['k2d8-preview'].variants)).toEqual(['low','high','max']); +}); + +test('before the account list is read, both models Work has listed are offered',async()=>{ + const p=I.createPlugin({readSession:()=>session,fetchImpl:async()=>{throw Error('no network in tests');}}); + const cfg={};await p.config(cfg); + expect(Object.keys(cfg.provider['kimi-work'].models)).toEqual(['k3-agent','k2d8-preview']); + const payload=JSON.parse(fs.readFileSync(new URL('./fixtures/work-models.redacted.json',import.meta.url),'utf8')); + expect(Object.keys(cfg.provider['kimi-work'].models)).toEqual(payload.data.map(m=>m.id)); +});