@lzg14/deepseek-cli 0.1.3 → 0.1.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/README.md +1 -1
- package/dist/ds.js +12 -12
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/ds.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var fe=Object.defineProperty;var f=(t,e)=>()=>(t&&(e=t(t=0)),e);var ge=(t,e)=>{for(var o in e)fe(t,o,{get:e[o],enumerable:!0})};function O(t,e){let o={};for(let n=0;n<t.length;n++){let r=t[n];if(r==="--"){o._positional=t.slice(n+1);break}if(!r.startsWith("-")){o._positional||(o._positional=[]),o._positional.push(r);continue}let s=r.indexOf("=");if(s!==-1){let l=r.slice(0,s),p=r.slice(s+1);o[l.replace(/^--/,"").replace(/-/g,"_")]=p;continue}let a=r.replace(/^--/,"").replace(/-/g,"_"),i=e.find(l=>{let p=l.flag.split(" ")[0];return p===r||p===`--${a.replace(/_/g,"-")}`}),m=i?.flag.includes(" <")||i?.flag.includes(" ["),c=t[n+1];m&&c&&!c.startsWith("-")?(o[a]=c,n++):o[a]=!0}return o}function W(t,e){let o=[];for(let n of t){if(n.startsWith("-")||n==="--")break;o.push(n)}return o}function h(t){return t.base_url||t.baseUrl||"https://api.ds.com"}var b=f(()=>{"use strict"});var x,
|
|
3
|
-
`);l=k.pop()||"";for(let
|
|
2
|
+
var fe=Object.defineProperty;var f=(t,e)=>()=>(t&&(e=t(t=0)),e);var ge=(t,e)=>{for(var o in e)fe(t,o,{get:e[o],enumerable:!0})};function O(t,e){let o={};for(let n=0;n<t.length;n++){let r=t[n];if(r==="--"){o._positional=t.slice(n+1);break}if(!r.startsWith("-")){o._positional||(o._positional=[]),o._positional.push(r);continue}let s=r.indexOf("=");if(s!==-1){let l=r.slice(0,s),p=r.slice(s+1);o[l.replace(/^--/,"").replace(/-/g,"_")]=p;continue}let a=r.replace(/^--/,"").replace(/-/g,"_"),i=e.find(l=>{let p=l.flag.split(" ")[0];return p===r||p===`--${a.replace(/_/g,"-")}`}),m=i?.flag.includes(" <")||i?.flag.includes(" ["),c=t[n+1];m&&c&&!c.startsWith("-")?(o[a]=c,n++):o[a]=!0}return o}function W(t,e){let o=[];for(let n of t){if(n.startsWith("-")||n==="--")break;o.push(n)}return o}function h(t){return t.base_url||t.baseUrl||"https://api.ds.com"}var b=f(()=>{"use strict"});var x,P=f(()=>{"use strict";x=class extends Error{code;suggestion;fields;constructor(e,o=1,n,r){super(e),this.name="CLIError",this.code=o,this.suggestion=n,this.fields=r}}});var w,T=f(()=>{"use strict";w={SUCCESS:0,USAGE:1,CONFIG:2,AUTH:3,NETWORK:4,API:5,TIMEOUT:6,ABORT:7,UNKNOWN:99}});var N,I=f(()=>{"use strict";N="0.1.4"});function d(t){return{name:t.name,description:t.description,usage:t.usage,options:t.options,examples:t.examples,apiDocs:t.apiDocs,execute:t.run}}var A,u=f(()=>{"use strict";A=[{flag:"--api-key <key>",description:"ds API key"},{flag:"--base-url <url>",description:"API base URL"},{flag:"--output <format>",description:"Output format: text, json"},{flag:"--timeout <seconds>",description:"Request timeout",type:"number"},{flag:"--quiet",description:"Suppress non-essential output"},{flag:"--verbose",description:"Print HTTP request/response details"},{flag:"--no-color",description:"Disable ANSI colors"},{flag:"--dry-run",description:"Dry run mode"},{flag:"--non-interactive",description:"Disable interactive prompts"},{flag:"--help",description:"Show help"},{flag:"--version",description:"Print version"}]});async function ue(t,e,o,n,r){let s=new AbortController,a=setTimeout(()=>s.abort(),n*1e3);try{let i=await fetch(`${t}/chat/completions`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(o),signal:s.signal});if(clearTimeout(a),!i.ok){let p=await i.text();throw new Error(`API error ${i.status}: ${p}`)}if(!i.body)throw new Error("No response body");let m=i.body.getReader(),c=new TextDecoder,l="";for(;;){let{done:p,value:g}=await m.read();if(p)break;l+=c.decode(g,{stream:!0});let k=l.split(`
|
|
3
|
+
`);l=k.pop()||"";for(let _ of k)if(_.startsWith("data: ")){let v=_.slice(6);if(v==="[DONE]")continue;try{let S=JSON.parse(v).choices?.[0]?.delta?.content;S&&process.stdout.write(S)}catch{}}}process.stdout.write(`
|
|
4
4
|
`)}finally{clearTimeout(a)}}async function he(t,e,o,n,r){let s=new AbortController,a=setTimeout(()=>s.abort(),n*1e3);try{let i=await fetch(`${t}/chat/completions`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify({...o,stream:!1}),signal:s.signal});if(clearTimeout(a),!i.ok){let l=await i.text();throw new Error(`API error ${i.status}: ${l}`)}let c=(await i.json()).choices?.[0]?.message;c?.reasoning_content&&r.verbose&&console.log(`[Reasoning]:
|
|
5
5
|
`+c.reasoning_content+`
|
|
6
6
|
`),c?.content&&console.log(c.content)}finally{clearTimeout(a)}}var H,M=f(()=>{"use strict";u();b();H=d({name:"chat",description:"Chat with DeepSeek models",usage:"ds chat [options] [message]",examples:['ds chat "Hello, who are you?"','ds chat --model deepseek-v4-flash "Explain quantum computing"',"ds chat --no-stream"],options:[{flag:"--model <model>",description:"Model to use (deepseek-chat, deepseek-v4-flash)"},{flag:"--system <text>",description:"System prompt"},{flag:"--think",description:"Enable reasoning mode"},{flag:"--no-think",description:"Disable reasoning mode"},{flag:"--thinking-effort <0-10>",description:"Reasoning effort level"},{flag:"--stream",description:"Enable streaming (default)"},{flag:"--no-stream",description:"Disable streaming"},{flag:"--temperature <number>",description:"Temperature (0-2)"},{flag:"--max-tokens <n>",description:"Max output tokens"},{flag:"--json",description:"Request JSON mode"},{flag:"--timeout <seconds>",description:"Request timeout"}],run:async(t,e)=>{let o=h(t),n=t.apiKey;if(!n)throw new Error("No API key. Set ds_API_KEY or run ds auth login");let r=e.model||t.model||"deepseek-chat",s=[];e.system&&s.push({role:"system",content:e.system});let a=e._positional||[];a.length>0&&s.push({role:"user",content:a.join(" ")}),s.length===0&&(process.stderr.write(`Error: No message provided. Usage: ds chat <message>
|
|
@@ -11,17 +11,17 @@ Available ds Models:
|
|
|
11
11
|
`);return}console.log(`
|
|
12
12
|
ds Account Balance:
|
|
13
13
|
`);for(let l of c){let p=l.currency||"CNY",g=l.total_balance??l.balance??"N/A";console.log(` ${l.model||"Account"}: ${g} ${p}`)}console.log("")}finally{clearTimeout(a)}}})});var X,V=f(()=>{"use strict";u();b();X=d({name:"complete",description:"FIM code completion (Beta)",usage:"ds complete [flags] [--prompt <prefix>] [--suffix <suffix>]",examples:['ds complete --prompt "fn main()"','ds complete --prompt "class MyClass" --suffix "}"','ds complete --model deepseek-coder --prompt "import"'],options:[{flag:"--model <model>",description:"Model to use (default: deepseek-coder)"},{flag:"--prompt <text>",description:"Prefix text"},{flag:"--suffix <text>",description:"Suffix text"},{flag:"--max-tokens <n>",description:"Max output tokens"},{flag:"--temperature <number>",description:"Temperature (0-2)"},{flag:"--stream",description:"Enable streaming"},{flag:"--no-stream",description:"Disable streaming"}],run:async(t,e)=>{let o=h(t),n=t.apiKey;if(!n)throw new Error("No API key. Set ds_API_KEY or run ds auth login");let r=e.model||"deepseek-coder";if(e.dry_run){console.log(`[Dry run] POST ${o}/completions`);return}let s={model:r,stream:e.stream!==!1&&e.no_stream===void 0};e.prompt&&(s.prompt=e.prompt),e.suffix&&(s.suffix=e.suffix),e.max_tokens!==void 0&&(s.max_tokens=parseInt(e.max_tokens)),e.temperature!==void 0&&(s.temperature=parseFloat(e.temperature)),s.prompt||(process.stderr.write(`Error: --prompt is required for FIM completion
|
|
14
|
-
`),process.exit(1));let a=new AbortController,i=e.timeout||t.timeout||60,m=setTimeout(()=>a.abort(),i*1e3);try{let c=await fetch(`${o}/completions`,{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify(s),signal:a.signal});if(clearTimeout(m),!c.ok){let p=await c.text();throw new Error(`API error ${c.status}: ${p}`)}if(s.stream){if(!c.body)throw new Error("No response body");let p=c.body.getReader(),g=new TextDecoder;for(;;){let{done:k,value:
|
|
15
|
-
`);for(let
|
|
16
|
-
`)}else{let p=await c.json(),g=p.choices?.[0]?.text||p.choices?.[0]?.message?.content;g&&console.log(g)}}finally{clearTimeout(m)}}})});import{readFileSync as ye,writeFileSync as be,existsSync as Q,mkdirSync as xe}from"fs";import{homedir as we}from"os";import{join as Z}from"path";function y(){if(!Q(U))return{};try{let t=ye(U,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}catch{return{}}}function C(t){Q(F)||xe(F,{recursive:!0}),be(U,JSON.stringify(t,null,2),"utf-8")}function
|
|
14
|
+
`),process.exit(1));let a=new AbortController,i=e.timeout||t.timeout||60,m=setTimeout(()=>a.abort(),i*1e3);try{let c=await fetch(`${o}/completions`,{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify(s),signal:a.signal});if(clearTimeout(m),!c.ok){let p=await c.text();throw new Error(`API error ${c.status}: ${p}`)}if(s.stream){if(!c.body)throw new Error("No response body");let p=c.body.getReader(),g=new TextDecoder;for(;;){let{done:k,value:_}=await p.read();if(k)break;let G=g.decode(_,{stream:!0}).split(`
|
|
15
|
+
`);for(let S of G)if(S.startsWith("data: ")){let j=S.slice(6);if(j==="[DONE]")continue;try{let L=JSON.parse(j),J=L.choices?.[0]?.delta?.content||L.choices?.[0]?.text;J&&process.stdout.write(J)}catch{}}}process.stdout.write(`
|
|
16
|
+
`)}else{let p=await c.json(),g=p.choices?.[0]?.text||p.choices?.[0]?.message?.content;g&&console.log(g)}}finally{clearTimeout(m)}}})});import{readFileSync as ye,writeFileSync as be,existsSync as Q,mkdirSync as xe}from"fs";import{homedir as we}from"os";import{join as Z}from"path";function y(){if(!Q(U))return{};try{let t=ye(U,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}catch{return{}}}function C(t){Q(F)||xe(F,{recursive:!0}),be(U,JSON.stringify(t,null,2),"utf-8")}function K(t){let e=y();return{apiKey:t.api_key||e.apiKey||process.env.DEEPSEEK_API_KEY,baseUrl:t.base_url||e.baseUrl||"https://api.ds.com",model:t.model||e.model||"deepseek-chat",output:t.output||e.output||"text",timeout:t.timeout||e.timeout,proxy:e.proxy||process.env.HTTPS_PROXY||process.env.HTTP_PROXY,thinking:t.thinking!==void 0?!!t.thinking:e.thinking,thinkingEffort:t.thinking_effort||e.thinkingEffort||3,stream:t.stream!==void 0?!!t.stream:!0}}var F,U,$=f(()=>{"use strict";F=Z(we(),".seek"),U=Z(F,"config.json")});import*as ee from"readline";var oe,te=f(()=>{"use strict";u();$();b();oe=d({name:"auth login",description:"Login with ds API key",usage:"ds auth login [flags]",examples:["ds auth login","ds auth login --key sk-xxxxx"],options:[{flag:"--key <api-key>",description:"API key (or enter interactively)"},{flag:"--base-url <url>",description:"API base URL"}],run:async(t,e)=>{let o=e.key;if(!o){let n=ee.createInterface({input:process.stdin,output:process.stderr});o=await new Promise(r=>{n.question("Enter your ds API key: ",s=>{n.close(),r(s.trim())})})}if(o||(process.stderr.write(`Error: API key is required
|
|
17
17
|
`),process.exit(1)),e.dry_run){console.log(`[Dry run] Would save API key: ${o.slice(0,8)}...`);return}e.base_url?C({...t,apiKey:o,baseUrl:e.base_url}):C({...t,apiKey:o,baseUrl:h(t)}),console.log("[OK] API key saved successfully"),e.base_url&&console.log(` Base URL: ${e.base_url}`),console.log(` Run "ds models" to verify your credentials.
|
|
18
18
|
`)}})});var ne,re=f(()=>{"use strict";u();$();ne=d({name:"auth logout",description:"Logout and remove stored credentials",usage:"ds auth logout",examples:["ds auth logout"],run:async(t,e)=>{if(e.dry_run){console.log("[Dry run] Would remove stored API key");return}let o=y();if(!o.apiKey&&!o.baseUrl){console.log(`No credentials stored.
|
|
19
19
|
`);return}C({}),console.log(`[OK] Logged out successfully.
|
|
20
|
-
`)}})});var se,ie=f(()=>{"use strict";u();$();se=d({name:"config show",description:"Show current configuration",usage:"ds config show [flags]",examples:["ds config show","ds config show --json"],options:[{flag:"--json",description:"Output in JSON format"}],run:async(t,e)=>{let o=y();if(e.json){console.log(JSON.stringify(
|
|
20
|
+
`)}})});var se,ie=f(()=>{"use strict";u();$();se=d({name:"config show",description:"Show current configuration",usage:"ds config show [flags]",examples:["ds config show","ds config show --json"],options:[{flag:"--json",description:"Output in JSON format"}],run:async(t,e)=>{let o=y();if(e.json){let n={...o};n.apiKey&&(n.apiKey=n.apiKey.slice(0,8)+"..."),console.log(JSON.stringify(n,null,2));return}console.log(`
|
|
21
21
|
ds configuration:
|
|
22
|
-
`),console.log(` API Key: ${o.apiKey?o.apiKey.slice(0,8)+"...":"(not set)"}`),console.log(` Base URL: ${o.baseUrl||"https://api.ds.com (default)"}`),console.log(` Model: ${o.model||"deepseek-chat (default)"}`),console.log(` Proxy: ${o.proxy||"(not set)"}`),console.log(""),console.log(" Environment variables:"),console.log("
|
|
22
|
+
`),console.log(` API Key: ${o.apiKey?o.apiKey.slice(0,8)+"...":"(not set)"}`),console.log(` Base URL: ${o.baseUrl||"https://api.ds.com (default)"}`),console.log(` Model: ${o.model||"deepseek-chat (default)"}`),console.log(` Proxy: ${o.proxy||"(not set)"}`),console.log(""),console.log(" Environment variables:"),console.log(" DEEPSEEK_API_KEY -> API key"),console.log(" HTTPS_PROXY -> Proxy URL"),console.log(" HTTP_PROXY -> Proxy URL"),console.log("")}})});var ae,le=f(()=>{"use strict";u();$();ae=d({name:"config set",description:"Set a configuration value",usage:"ds config set <key> <value>",examples:["ds config set model deepseek-chat","ds config set proxy http://localhost:7890"],run:async(t,e)=>{let o=e._positional||[],[n,...r]=o;(!n||r.length===0)&&(process.stderr.write(`Error: Usage: ds config set <key> <value>
|
|
23
23
|
`),process.exit(1));let s=r.join(" "),a=y(),m={model:"model","base-url":"baseUrl",base_url:"baseUrl",proxy:"proxy",timeout:"timeout",thinking:"thinking","thinking-effort":"thinkingEffort",thinking_effort:"thinkingEffort"}[n]||n;if(e.dry_run){console.log(`[Dry run] Would set ${m} = ${s}`);return}a[m]=s,C(a),console.log(`[OK] Set ${n} = ${s}
|
|
24
|
-
`)}})});var ce,me=f(()=>{"use strict";u();ce=d({name:"help",description:"Show help information",usage:"ds help [command]",examples:["ds help","ds help chat","ds help models"],run:async(t,e)=>{let o=e._positional||[],{registry:n}=await Promise.resolve().then(()=>(
|
|
24
|
+
`)}})});var ce,me=f(()=>{"use strict";u();ce=d({name:"help",description:"Show help information",usage:"ds help [command]",examples:["ds help","ds help chat","ds help models"],run:async(t,e)=>{let o=e._positional||[],{registry:n}=await Promise.resolve().then(()=>(R(),pe));n.printHelp(o,process.stdout)}})});var pe={};ge(pe,{registry:()=>E});var D,E,R=f(()=>{"use strict";P();T();I();M();Y();z();V();te();re();ie();le();me();D=class{root={children:new Map};constructor(e){for(let[o,n]of Object.entries(e))this.register(o,n)}register(e,o){let n=e.split(" "),r=this.root;for(let s of n)r.children.has(s)||r.children.set(s,{children:new Map}),r=r.children.get(s);r.command=o}resolve(e){let o=this.root,n=[];for(let r of e){let s=o.children.get(r);if(!s)break;o=s,n.push(r)}if(o.command)return{command:o.command,extra:e.slice(n.length)};if(n.length>0&&o.children.size>0&&o.children.has("show")){let r=o.children.get("show");if(r.command)return{command:r.command,extra:e.slice(n.length+1)}}if(n.length>0&&o.children.size===1){let[,r]=o.children.entries().next().value;if(r.command)return{command:r.command,extra:e.slice(n.length)}}if(n.length>0&&o.children.size>0){let r=Array.from(o.children.entries()).map(([s,a])=>{if(a.command)return` ${n.join(" ")} ${s} ${a.command.description}`;let i=Array.from(a.children.keys()).join(", ");return` ${n.join(" ")} ${s} [${i}]`}).join(`
|
|
25
25
|
`);throw new x(`Unknown command: ds ${e.join(" ")}
|
|
26
26
|
|
|
27
27
|
Available commands:
|
|
@@ -65,7 +65,7 @@ ${n("Examples:")}
|
|
|
65
65
|
`);for(let a of e.examples)o.write(` ${s(a)}
|
|
66
66
|
`)}o.write(`
|
|
67
67
|
`)}printChildren(e,o,n){let r=[],s=(i,m)=>{for(let[c,l]of i.children)l.command&&r.push({fullName:`${m} ${c}`,description:l.command.description}),l.children.size>0&&s(l,`${m} ${c}`)};s(e,o);let a=Math.max(...r.map(i=>i.fullName.length));for(let{fullName:i,description:m}of r)n.write(` ${this.accent(i.padEnd(a),n)} ${this.dim(m,n)}
|
|
68
|
-
`)}},
|
|
68
|
+
`)}},E=new D({chat:H,models:B,balance:q,complete:X,"auth login":oe,"auth logout":ne,"config show":se,"config set":ae,help:ce})});b();R();u();P();T();function de(t){t instanceof x&&(t.suggestion?process.stderr.write(`
|
|
69
69
|
\x1B[1merror:\x1B[0m ${t.message}
|
|
70
70
|
|
|
71
71
|
-> ${t.suggestion}
|
|
@@ -78,10 +78,10 @@ ${n("Examples:")}
|
|
|
78
78
|
`),process.stderr.write(` -> Or set a proxy: ds config set proxy http://localhost:7890
|
|
79
79
|
`),process.exit(w.NETWORK)),process.exit(w.UNKNOWN)),process.stderr.write(`
|
|
80
80
|
\x1B[1merror:\x1B[0m ${String(t)}
|
|
81
|
-
`),process.exit(w.UNKNOWN)}$();
|
|
81
|
+
`),process.exit(w.UNKNOWN)}$();I();process.on("SIGINT",()=>{process.stderr.write(`
|
|
82
82
|
Interrupted. Exiting.
|
|
83
|
-
`),process.exitCode=130});process.stdout.on("error",()=>{});process.stderr.on("error",()=>{});var Ce=[["auth","logout"],["config","show"],["config","set"],["models"]];async function ke(){let t=process.argv.slice(2);if(t.includes("--version")||t.includes("-v")){console.log(`ds ${N}`),process.exitCode=0;return}let e=W(t,A),o=y(),n=process.env.HTTPS_PROXY||process.env.https_proxy||process.env.HTTP_PROXY||process.env.http_proxy||o.proxy;if(t.includes("--help")||t.includes("-h")){
|
|
83
|
+
`),process.exitCode=130});process.stdout.on("error",()=>{});process.stderr.on("error",()=>{});var Ce=[["help"],["auth","logout"],["config","show"],["config","set"],["models"]];async function ke(){let t=process.argv.slice(2);if(t.includes("--version")||t.includes("-v")){console.log(`ds ${N}`),process.exitCode=0;return}let e=W(t,A),o=y(),n=process.env.HTTPS_PROXY||process.env.https_proxy||process.env.HTTP_PROXY||process.env.http_proxy||o.proxy;if(t.includes("--help")||t.includes("-h")){E.printHelp(e,process.stderr),process.exitCode=0;return}if(e.length===0){if(E.printHelp([],process.stderr),!!o.apiKey){let{command:p}=E.resolve(["balance"]),g=O(t,[...A]),k=K(g);await p.execute(k,g)}else process.stderr.write(` Not logged in.
|
|
84
84
|
`),process.stderr.write(` ds auth login Login with your ds API key
|
|
85
85
|
|
|
86
|
-
`);process.exitCode=0;return}let{command:r,extra:s}=
|
|
86
|
+
`);process.exitCode=0;return}let{command:r,extra:s}=E.resolve(e),a=t.slice(e.length),i=O(a,[...A,...r.options??[]]);s.length>0&&(i._positional=s);let m=K(i);if(!Ce.some(l=>l.every((p,g)=>e[g]===p))&&!m.apiKey){let l=process.env.DEEPSEEK_API_KEY;if(!l){process.stderr.write(`Error: No API key found. Run "ds auth login" or set DEEPSEEK_API_KEY env var.
|
|
87
87
|
`),process.exitCode=1;return}m.apiKey=l}await r.execute(m,i)}ke().catch(de);
|