@duckmind/dm-darwin-x64 0.51.4 → 0.51.7

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/dm CHANGED
Binary file
@@ -261,8 +261,8 @@
261
261
  "src/index.js"
262
262
  ],
263
263
  "file_count": 1,
264
- "before_bytes": 11784,
265
- "after_bytes": 6060,
264
+ "before_bytes": 14990,
265
+ "after_bytes": 7268,
266
266
  "externals": [
267
267
  "@duckmind/dm-agent-core",
268
268
  "@duckmind/dm-ai",
@@ -1,5 +1,5 @@
1
- import{chmodSync as _,existsSync as N,mkdirSync as $,readFileSync as k,writeFileSync as A}from"node:fs";import{homedir as P}from"node:os";import{dirname as S,join as K}from"node:path";import{Type as x}from"typebox";var T="http://localhost:20128",I=process.env.NINE_ROUTER_BASE_URL,M=process.env.NINE_ROUTER_API_KEY,b=K(P(),".dm","agent","9router-config.json"),E="9router-config",B="9router-last-route",L=["x-9router-model","x-routed-model","x-actual-model","x-upstream-model","x-provider-model"];function U(e){return e.replace(/\/$/,"")}function C(e){return{baseUrl:U(I||e.baseUrl),apiKey:M||e.apiKey}}function O(){try{if(!N(b))return null;let e=JSON.parse(k(b,"utf8"));if(!e.baseUrl||typeof e.baseUrl!=="string")return null;return{baseUrl:U(e.baseUrl),apiKey:typeof e.apiKey==="string"&&e.apiKey.trim()?e.apiKey.trim():void 0}}catch(e){return console.error("[dm-9router-ext] Failed to load persisted config:",e),null}}function j(e){try{$(S(b),{recursive:!0}),A(b,`${JSON.stringify({baseUrl:e.baseUrl,apiKey:e.apiKey},null,2)}
2
- `,{mode:384}),_(b,384)}catch(a){console.error("[dm-9router-ext] Failed to persist config:",a)}}function F(e){for(let a of e.sessionManager.getEntries()){if(a.type!=="custom"||a.customType!==E)continue;let i=a.data;if(!i?.baseUrl)continue;return{baseUrl:U(i.baseUrl),apiKey:void 0}}return null}function v(e,a){j(a),e.appendEntry(E,{baseUrl:a.baseUrl})}async function y(e,a){let i={Accept:"application/json"};if(e.apiKey)i.Authorization=`Bearer ${e.apiKey}`;let f=await fetch(`${e.baseUrl}/v1/models`,{method:"GET",headers:i,signal:a});if(!f.ok)throw Error(`9router returned ${f.status}: ${f.statusText}`);let r;try{r=await f.json()}catch{throw Error("9router returned invalid model metadata")}if(typeof r!=="object"||r===null||!Array.isArray(r.data)||r.data.some((o)=>typeof o!=="object"||o===null||typeof o.id!=="string"||!o.id.trim()))throw Error("9router returned invalid model metadata");return r.data}async function w(e,a){try{return await y(e,a),{ok:!0}}catch(i){return{ok:!1,error:i instanceof Error?i.message:String(i)}}}function D(e){return{id:e.id,name:e.owned_by==="combo"?`\uD83D\uDD00 ${e.id}`:e.id,reasoning:!1,input:["text"],cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:128000,maxTokens:4096,compat:{supportsDeveloperRole:!1,supportsReasoningEffort:!1}}}function h(e,a,i){e.registerProvider("9router",{name:"9router",baseUrl:`${a.baseUrl}/v1`,apiKey:a.apiKey||"9router-no-api-key",api:"openai-completions",models:i.map(D)})}function G(e){e.unregisterProvider("9router")}async function Y(e){let a=O(),i=a||{baseUrl:T,apiKey:void 0},f=a!==null,r=C(i),o=[],p,R,m=!1;try{o=await y(r,AbortSignal.timeout(1500)),m=!0,h(e,r,o)}catch{G(e)}e.on("session_start",async(d,n)=>{let t=F(n);if(!f&&t){let l=C(t);try{let u=await y(l,n.signal);h(e,l,u),i=t,f=!0,r=l,o=u,m=!0,v(e,i)}catch{}}if(m&&o.length>0)n.ui.notify(`9router connected — ${o.length} models available`,"info")}),e.on("after_provider_response",(d)=>{if(d.status>=400||R!=="9router")return;for(let n of L){let t=d.headers[n];if(!t||typeof t!=="string")continue;p=t,e.appendEntry(B,{model:t,timestamp:Date.now()});break}}),e.on("model_select",async(d)=>{if(R=d.model.provider,R!=="9router")p=void 0}),e.registerCommand("9router-status",{description:"Show 9router connection status and configuration",handler:async(d,n)=>{let t=await w(r,n.signal),l=["\uD83D\uDD17 9router Status","",`Base URL: ${r.baseUrl}`,`API Key: ${r.apiKey?"set":"not set"}`,`Connection: ${t.ok?"\uD83D\uDFE2 connected":`\uD83D\uDD34 ${t.error||"disconnected"}`}`,`Models: ${o.length} available`];if(p)l.push(`Last routed: ${p}`);n.ui.notify(l.join(`
3
- `),t.ok?"info":"warning")}}),e.registerCommand("9router-models",{description:"Browse 9router available models and combos",handler:async(d,n)=>{if(o.length===0){n.ui.notify("No 9router models discovered. Check connection with /9router-status","warning");return}let t=o.map((s)=>({value:s.id,label:s.owned_by==="combo"?`\uD83D\uDD00 ${s.id}`:s.id})),l=await n.ui.select("Select a 9router model to use:",t.map((s)=>s.label)),u=t.find((s)=>s.label===l)?.value;if(!u)return;e.sendUserMessage(`/model 9router/${u}`,{deliverAs:"followUp"})}}),e.registerCommand("9router-config",{description:"Configure 9router base URL and API key",handler:async(d,n)=>{let t=await w(r,n.signal);n.ui.notify(["Current config:",` Base URL: ${r.baseUrl}`,` API Key: ${r.apiKey?"set":"not set"}`,` Status: ${t.ok?"\uD83D\uDFE2 connected":"\uD83D\uDD34 disconnected"}`,"","Enter new values. Blank keeps the current value."].join(`
4
- `),"info");let l=await n.ui.input("Base URL",r.baseUrl);if(l===void 0)return;let u=await n.ui.input("API key (blank keeps current, '-' clears):","");if(u===void 0)return;let s={baseUrl:U(l.trim()||i.baseUrl),apiKey:u.trim()===""?i.apiKey:u.trim()==="-"?void 0:u.trim()},g=C(s);try{let c=await y(g,n.signal);h(e,g,c),i=s,f=!0,r=g,o=c,m=!0,v(e,i),n.ui.notify(`9router updated — ${o.length} models at ${r.baseUrl}`,"info")}catch(c){n.ui.notify(`Failed to connect: ${c instanceof Error?c.message:String(c)}`,"error")}}}),e.registerCommand("9router-reload",{description:"Reload models from 9router",handler:async(d,n)=>{try{let t=await y(r,n.signal);h(e,r,t),o=t,m=!0,n.ui.notify(`9router reloaded — ${o.length} models`,"info")}catch(t){n.ui.notify(`Reload failed: ${t instanceof Error?t.message:String(t)}`,"error")}}}),e.registerTool({name:"ninerouter_status",label:"9router Status",description:"Check 9router connection status and list available models",parameters:x.Object({}),async execute(d,n,t,l,u){let s=await w(r,u.signal),g=o.filter((c)=>c.owned_by==="combo");return{content:[{type:"text",text:[`9router: ${s.ok?"connected":`disconnected (${s.error})`}`,`Base URL: ${r.baseUrl}`,`Total models: ${o.length}`,` Regular: ${o.length-g.length}`,` Combos: ${g.length}`,p?`Last routed model: ${p}`:""].filter(Boolean).join(`
5
- `)}],details:{connected:s.ok,baseUrl:r.baseUrl,modelCount:o.length,comboCount:g.length,lastRoutedModel:p,models:o.map((c)=>c.id)}}}})}export{y as fetchModels,Y as default};
1
+ import{randomUUID as T}from"node:crypto";import{chmodSync as w,existsSync as S,mkdirSync as M,readFileSync as $,renameSync as x,rmSync as E,statSync as B,writeFileSync as I}from"node:fs";import{homedir as D}from"node:os";import{dirname as L,join as O}from"node:path";import{Type as j}from"typebox";var F="http://localhost:20128",W=process.env.NINE_ROUTER_BASE_URL,G=process.env.NINE_ROUTER_API_KEY,f=O(D(),".dm","agent","9router-config.json"),A="9router-config",Y="9router-last-route",z=["x-9router-model","x-routed-model","x-actual-model","x-upstream-model","x-provider-model"];function C(e){return e.replace(/\/$/,"")}function U(e){return{baseUrl:C(W||e.baseUrl),apiKey:G||e.apiKey}}function H(){try{if(!S(f))return null;let e=JSON.parse($(f,"utf8"));if(typeof e.baseUrl!=="string"||!e.baseUrl.trim())return null;return{baseUrl:C(e.baseUrl.trim()),apiKey:typeof e.apiKey==="string"&&e.apiKey.trim()?e.apiKey.trim():void 0}}catch{return console.error("[dm-9router-ext] Failed to load persisted config"),null}}function J(e){let n={baseUrl:e.baseUrl};if(e.apiKey)n.apiKey=e.apiKey;return Buffer.from(`${JSON.stringify(n,null,2)}
2
+ `)}function V(){if(!S(f))return{existed:!1};let e=B(f);return{existed:!0,contents:$(f),mode:e.mode&511}}function K(e,n=384){let s=`${f}.tmp-${process.pid}-${T()}`;try{return M(L(f),{recursive:!0,mode:448}),I(s,e,{flag:"wx",mode:n}),w(s,n),s}catch(c){throw E(s,{force:!0}),c}}function q(e){let n=V();return{tempPath:K(J(e)),snapshot:n}}function Q(e){x(e.tempPath,f),w(f,384)}function X(e){if(!e.existed){E(f,{force:!0});return}let n=K(e.contents??Buffer.alloc(0),e.mode??384);x(n,f),w(f,e.mode??384)}function Z(e){let n=e.sessionManager,s=typeof n.getBranch==="function"?n.getBranch():n.getEntries();for(let c=s.length-1;c>=0;c-=1){let t=s[c];if(t.type!=="custom"||t.customType!==A)continue;let o=t.data;if(typeof o?.baseUrl!=="string"||!o.baseUrl.trim())continue;return{baseUrl:C(o.baseUrl.trim()),apiKey:void 0}}return null}async function h(e,n){let s={Accept:"application/json"};if(e.apiKey)s.Authorization=`Bearer ${e.apiKey}`;let c=await fetch(`${e.baseUrl}/v1/models`,{method:"GET",headers:s,signal:n});if(!c.ok)throw Error(`9router returned ${c.status}: ${c.statusText}`);let t;try{t=await c.json()}catch{throw Error("9router returned invalid model metadata")}if(typeof t!=="object"||t===null||!Array.isArray(t.data)||t.data.some((o)=>typeof o!=="object"||o===null||typeof o.id!=="string"||!o.id.trim()))throw Error("9router returned invalid model metadata");return t.data}async function R(e,n){try{return await h(e,n),{ok:!0}}catch(s){return{ok:!1,error:s instanceof Error?s.message:String(s)}}}function ee(e){return{id:e.id,name:e.owned_by==="combo"?`\uD83D\uDD00 ${e.id}`:e.id,reasoning:!1,input:["text"],cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:128000,maxTokens:4096,compat:{supportsDeveloperRole:!1,supportsReasoningEffort:!1}}}function b(e,n,s){e.registerProvider("9router",{name:"9router",baseUrl:`${n.baseUrl}/v1`,apiKey:n.apiKey||"9router-no-api-key",api:"openai-completions",models:s.map(ee)})}function P(e){e.unregisterProvider("9router")}async function te(e){let n=H(),s=n||{baseUrl:F,apiKey:void 0},c=n!==null,t=U(s),o=[],m,v,y=!1,_=()=>({persistedConfig:s,hasPersistedConfig:c,config:t,discoveredModels:o,isConnected:y}),k=(u)=>{try{if(u.isConnected)b(e,u.config,u.discoveredModels);else P(e)}catch{console.error("[dm-9router-ext] Failed to restore the previous provider snapshot")}},N=(u,r,i,l)=>{let d=_(),a,p=!1,g=!1;try{if(a=q(u),p=!0,b(e,r,i),g=!0,Q(a),l)e.appendEntry(A,{baseUrl:u.baseUrl});s=u,c=!0,t=r,o=i,y=!0}catch{if(a)E(a.tempPath,{force:!0});if(g&&a)try{X(a.snapshot)}catch{console.error("[dm-9router-ext] Failed to restore the previous config file")}if(p)k(d);throw Error("9router configuration update failed; previous configuration remains active")}};try{o=await h(t,AbortSignal.timeout(1500)),y=!0,b(e,t,o)}catch{P(e)}e.on("session_start",async(u,r)=>{let i=Z(r);if(!c&&i){let l=U(i);try{let d=await h(l,r.signal);N(i,l,d,!1)}catch{}}if(y&&o.length>0)r.ui.notify(`9router connected — ${o.length} models available`,"info")}),e.on("after_provider_response",(u)=>{if(u.status>=400||v!=="9router")return;for(let r of z){let i=u.headers[r];if(!i||typeof i!=="string")continue;m=i,e.appendEntry(Y,{model:i,timestamp:Date.now()});break}}),e.on("model_select",async(u)=>{if(v=u.model.provider,v!=="9router")m=void 0}),e.registerCommand("9router-status",{description:"Show 9router connection status and configuration",handler:async(u,r)=>{let i=await R(t,r.signal),l=["\uD83D\uDD17 9router Status","",`Base URL: ${t.baseUrl}`,`API Key: ${t.apiKey?"set":"not set"}`,`Connection: ${i.ok?"\uD83D\uDFE2 connected":`\uD83D\uDD34 ${i.error||"disconnected"}`}`,`Models: ${o.length} available`];if(m)l.push(`Last routed: ${m}`);r.ui.notify(l.join(`
3
+ `),i.ok?"info":"warning")}}),e.registerCommand("9router-models",{description:"Browse 9router available models and combos",handler:async(u,r)=>{if(o.length===0){r.ui.notify("No 9router models discovered. Check connection with /9router-status","warning");return}let i=o.map((a)=>({value:a.id,label:a.owned_by==="combo"?`\uD83D\uDD00 ${a.id}`:a.id})),l=await r.ui.select("Select a 9router model to use:",i.map((a)=>a.label)),d=i.find((a)=>a.label===l)?.value;if(!d)return;e.sendUserMessage(`/model 9router/${d}`,{deliverAs:"followUp"})}}),e.registerCommand("9router-config",{description:"Configure 9router base URL and API key",handler:async(u,r)=>{let i=await R(t,r.signal);r.ui.notify(["Current config:",` Base URL: ${t.baseUrl}`,` API Key: ${t.apiKey?"set":"not set"}`,` Status: ${i.ok?"\uD83D\uDFE2 connected":"\uD83D\uDD34 disconnected"}`,"","Enter new values. Blank keeps the current value."].join(`
4
+ `),"info");let l=await r.ui.input("Base URL",t.baseUrl);if(l===void 0)return;let d=await r.ui.input("API key (blank keeps current, '-' clears):","");if(d===void 0)return;let a={baseUrl:C(l.trim()||s.baseUrl),apiKey:d.trim()===""?s.apiKey:d.trim()==="-"?void 0:d.trim()},p=U(a);try{let g=await h(p,r.signal);N(a,p,g,!0),r.ui.notify(`9router updated — ${o.length} models at ${t.baseUrl}`,"info")}catch{r.ui.notify("9router update failed; the previous configuration remains active","error")}}}),e.registerCommand("9router-reload",{description:"Reload models from 9router",handler:async(u,r)=>{let i=_(),l=!1;try{let d=await h(t,r.signal);l=!0,b(e,t,d),o=d,y=!0,r.ui.notify(`9router reloaded — ${o.length} models`,"info")}catch{if(l)k(i);r.ui.notify("9router reload failed; the previous provider and model list remain active","error")}}}),e.registerTool({name:"ninerouter_status",label:"9router Status",description:"Check 9router connection status and list available models",parameters:j.Object({}),async execute(u,r,i,l,d){let a=await R(t,d.signal),p=o.filter((g)=>g.owned_by==="combo");return{content:[{type:"text",text:[`9router: ${a.ok?"connected":`disconnected (${a.error})`}`,`Base URL: ${t.baseUrl}`,`Total models: ${o.length}`,` Regular: ${o.length-p.length}`,` Combos: ${p.length}`,m?`Last routed model: ${m}`:""].filter(Boolean).join(`
5
+ `)}],details:{connected:a.ok,baseUrl:t.baseUrl,modelCount:o.length,comboCount:p.length,lastRoutedModel:m,models:o.map((g)=>g.id)}}}})}export{h as fetchModels,te as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duckmind/dm-darwin-x64",
3
- "version": "0.51.4",
3
+ "version": "0.51.7",
4
4
  "description": "DuckMind (dm) binary payload for darwin x64",
5
5
  "license": "MIT",
6
6
  "os": [