@lzg14/deepseek-cli 0.1.0

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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +168 -0
  3. package/dist/ds.js +86 -0
  4. package/package.json +38 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,168 @@
1
+ # ds-cli - DeepSeek CLI
2
+
3
+ Command-line tool for DeepSeek API. Chat with models, manage API keys, and more.
4
+
5
+ ## Features
6
+
7
+ - **Chat** - Interactive text chat with DeepSeek models
8
+ - **Models** - List available models and their capabilities
9
+ - **Balance** - Check your account balance and usage
10
+ - **Complete** - FIM (Fill-in-the-Middle) code completion
11
+ - **Streaming** - Real-time streaming responses
12
+ - **JSON Output** - Machine-readable output format
13
+
14
+ ## Requirements
15
+
16
+ - Node.js >= 18
17
+ - DeepSeek API key
18
+
19
+ ## Installation
20
+
21
+ ### npm
22
+
23
+ ```bash
24
+ npm install -g ds-cli
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ```bash
30
+ # Login with API key (interactive)
31
+ ds auth login
32
+
33
+ # Or set via environment variable
34
+ export DEEPSEEK_API_KEY=sk-xxxxx
35
+
36
+ # Chat with DeepSeek
37
+ ds chat "Hello, who are you?"
38
+
39
+ # List available models
40
+ ds models
41
+
42
+ # Check account balance
43
+ ds balance
44
+
45
+ # Code completion (Beta)
46
+ ds complete --prompt "fn main()"
47
+ ```
48
+
49
+ ## Commands
50
+
51
+ | Command | Description |
52
+ |---------|-------------|
53
+ | `ds chat [options] [message]` | Chat with DeepSeek models |
54
+ | `ds models` | List available models |
55
+ | `ds balance` | Check account balance |
56
+ | `ds complete [options]` | FIM code completion (Beta) |
57
+ | `ds auth login` | Login with API key |
58
+ | `ds auth logout` | Logout and remove credentials |
59
+ | `ds config` | Show configuration |
60
+ | `ds config set <key> <value>` | Set a configuration value |
61
+
62
+ ## Options
63
+
64
+ ### Global Flags
65
+
66
+ | Flag | Description |
67
+ |------|-------------|
68
+ | `--api-key <key>` | DeepSeek API key |
69
+ | `--base-url <url>` | API base URL (default: https://api.deepseek.com) |
70
+ | `--output <format>` | Output format: text, json |
71
+ | `--timeout <seconds>` | Request timeout |
72
+ | `--quiet` | Suppress non-essential output |
73
+ | `--verbose` | Print HTTP request/response details |
74
+ | `--dry-run` | Print request without sending |
75
+ | `--help` | Show help |
76
+ | `--version` | Show version |
77
+
78
+ ### Chat Options
79
+
80
+ | Flag | Description |
81
+ |------|-------------|
82
+ | `--model <model>` | Model to use (deepseek-chat, deepseek-v4-flash) |
83
+ | `--system <text>` | System prompt |
84
+ | `--stream` | Enable streaming (default) |
85
+ | `--no-stream` | Disable streaming |
86
+ | `--temperature <number>` | Temperature (0-2) |
87
+ | `--max-tokens <n>` | Max output tokens |
88
+ | `--json` | Request JSON mode |
89
+
90
+ ### Complete Options
91
+
92
+ | Flag | Description |
93
+ |------|-------------|
94
+ | `--model <model>` | Model to use (deepseek-coder) |
95
+ | `--prompt <text>` | Prefix text (required) |
96
+ | `--suffix <text>` | Suffix text |
97
+ | `--max-tokens <n>` | Max output tokens |
98
+ | `--temperature <number>` | Temperature (0-2) |
99
+
100
+ ## Configuration
101
+
102
+ Config file: `~/.seek/config.json`
103
+
104
+ ```json
105
+ {
106
+ "apiKey": "sk-xxxxx",
107
+ "baseUrl": "https://api.deepseek.com",
108
+ "model": "deepseek-chat"
109
+ }
110
+ ```
111
+
112
+ Or use CLI commands:
113
+
114
+ ```bash
115
+ ds config set model deepseek-v4-flash
116
+ ds config
117
+ ```
118
+
119
+ ## Environment Variables
120
+
121
+ | Variable | Description |
122
+ |----------|-------------|
123
+ | `DEEPSEEK_API_KEY` | API key |
124
+ | `HTTPS_PROXY` | HTTPS proxy URL |
125
+ | `HTTP_PROXY` | HTTP proxy URL |
126
+
127
+ ## Models
128
+
129
+ | Model | Context | Description |
130
+ |-------|---------|-------------|
131
+ | `deepseek-chat` | 64K | General chat model |
132
+ | `deepseek-v4-flash` | 1M | Fast, low-cost |
133
+ | `deepseek-v4-pro` | 1M | High performance |
134
+
135
+ ## Pricing
136
+
137
+ | Model | Input (cached) | Input | Output |
138
+ |-------|----------------|-------|--------|
139
+ | deepseek-v4-flash | ¥0.02/M | ¥1/M | ¥2/M |
140
+ | deepseek-v4-pro | ¥0.025/M | ¥3/M | ¥6/M |
141
+
142
+ ## Development
143
+
144
+ ```bash
145
+ # Install dependencies
146
+ npm install
147
+
148
+ # Build
149
+ npm run build
150
+
151
+ # Run tests
152
+ npm test
153
+
154
+ # Type check
155
+ npm run typecheck
156
+ ```
157
+
158
+ ## License
159
+
160
+ MIT
161
+
162
+ ## Contributing
163
+
164
+ 1. Fork the repository
165
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
166
+ 3. Commit your changes (`git commit -m 'feat: add amazing feature'`)
167
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
168
+ 5. Open a Pull Request
package/dist/ds.js ADDED
@@ -0,0 +1,86 @@
1
+ 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,T=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,I=f(()=>{"use strict";w={SUCCESS:0,USAGE:1,CONFIG:2,AUTH:3,NETWORK:4,API:5,TIMEOUT:6,ABORT:7,UNKNOWN:99}});var N,P=f(()=>{"use strict";N="0.1.0"});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(`
2
+ `);l=k.pop()||"";for(let E of k)if(E.startsWith("data: ")){let v=E.slice(6);if(v==="[DONE]")continue;try{let _=JSON.parse(v).choices?.[0]?.delta?.content;_&&process.stdout.write(_)}catch{}}}process.stdout.write(`
3
+ `)}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]:
4
+ `+c.reasoning_content+`
5
+ `),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>
6
+ `),process.exit(1));let i=e.stream!==!1&&e.no_stream===void 0,m=e.think!==void 0?!!e.think:t.thinking,c={model:r,messages:s,stream:i};e.temperature!==void 0&&(c.temperature=parseFloat(e.temperature)),e.max_tokens!==void 0&&(c.max_tokens=parseInt(e.max_tokens)),e.json&&(c.response_format={type:"json_object"});let l=e.timeout||t.timeout||120;if(e.dry_run){console.log(`[Dry run] POST ${o}/chat/completions`),console.log(JSON.stringify(c,null,2));return}i?await ue(o,n,c,l,e):await he(o,n,c,l,e)}})});var B,Y=f(()=>{"use strict";u();b();B=d({name:"models",description:"List available DeepSeek models",usage:"ds models [flags]",examples:["ds models","ds models --json"],options:[{flag:"--json",description:"Output in JSON format"}],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");if(e.dry_run){console.log(`[Dry run] GET ${o}/models`);return}let r=new AbortController,s=e.timeout||t.timeout||30,a=setTimeout(()=>r.abort(),s*1e3);try{let i=await fetch(`${o}/models`,{method:"GET",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},signal:r.signal});if(clearTimeout(a),!i.ok){let l=await i.text();throw new Error(`API error ${i.status}: ${l}`)}let m=await i.json();if(e.json){console.log(JSON.stringify(m,null,2));return}let c=m.data||[];console.log(`
7
+ Available ds Models:
8
+ `);for(let l of c){let p=l.created?new Date(l.created*1e3).toLocaleDateString():"";console.log(` ${l.id} ${l.object} ${p}`),l.owned_by&&console.log(` Owned by: ${l.owned_by}`)}console.log("")}finally{clearTimeout(a)}}})});var q,z=f(()=>{"use strict";u();b();q=d({name:"balance",description:"Check ds account balance",usage:"ds balance [flags]",examples:["ds balance","ds balance --json"],options:[{flag:"--json",description:"Output in JSON format"}],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");if(e.dry_run){console.log(`[Dry run] GET ${o}/user/balance`);return}let r=new AbortController,s=e.timeout||t.timeout||30,a=setTimeout(()=>r.abort(),s*1e3);try{let i=await fetch(`${o}/user/balance`,{method:"GET",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},signal:r.signal});if(clearTimeout(a),!i.ok){let l=await i.text();throw new Error(`API error ${i.status}: ${l}`)}let m=await i.json();if(e.json){console.log(JSON.stringify(m,null,2));return}let c=m.balance_infos||[];if(c.length===0){console.log(`
9
+ No balance information available.
10
+ `);return}console.log(`
11
+ ds Account Balance:
12
+ `);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
13
+ `),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:E}=await p.read();if(k)break;let j=g.decode(E,{stream:!0}).split(`
14
+ `);for(let _ of j)if(_.startsWith("data: ")){let D=_.slice(6);if(D==="[DONE]")continue;try{let L=JSON.parse(D),J=L.choices?.[0]?.delta?.content||L.choices?.[0]?.text;J&&process.stdout.write(J)}catch{}}}process.stdout.write(`
15
+ `)}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 R(t){let e=y();return{apiKey:t.api_key||e.apiKey||process.env.ds_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
16
+ `),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.
17
+ `)}})});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.
18
+ `);return}C({}),console.log(`[OK] Logged out successfully.
19
+ `)}})});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(o,null,2));return}console.log(`
20
+ ds configuration:
21
+ `),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(" ds_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>
22
+ `),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}
23
+ `)}})});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(()=>(G(),pe));n.printHelp(o,process.stdout)}})});var pe={};ge(pe,{registry:()=>S});var K,S,G=f(()=>{"use strict";T();I();P();M();Y();z();V();te();re();ie();le();me();K=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(`
24
+ `);throw new x(`Unknown command: ds ${e.join(" ")}
25
+
26
+ Available commands:
27
+ ${r}`,w.USAGE,`ds ${n.join(" ")} --help`)}throw new x(`Unknown command: ds ${e.join(" ")}`,w.USAGE,"ds --help")}bold=(e,o)=>o.isTTY?`\x1B[1m${e}\x1B[0m`:e;accent=(e,o)=>o.isTTY?`\x1B[38;2;103;58m${e}\x1B[0m`:e;dim=(e,o)=>o.isTTY?`\x1B[2m${e}\x1B[0m`:e;printHelp(e,o=process.stdout){if(e.length===0){this.printRootHelp(o);return}let n=this.root;for(let s of e){let a=n.children.get(s);if(!a){this.printRootHelp(o);return}n=a}if(n.command){this.printCommandHelp(n.command,o);return}let r=e.join(" ");o.write(`
28
+ ${this.bold("Usage:",o)} ds ${r} <command> [flags]
29
+
30
+ `),o.write(`${this.bold("Commands:",o)}
31
+ `),this.printChildren(n,r,o),o.write(`
32
+ `)}printRootHelp(e){let o=s=>this.bold(s,e),n=s=>this.accent(s,e),r=s=>this.dim(s,e);e.write(`
33
+ ${o("ds")} ${n("v"+N)} Deepseek CLI
34
+
35
+ ${o("Usage:")} ds <command> [flags]
36
+
37
+ ${o("Commands:")}
38
+ ${n("chat")} ${r("Text chat with DeepSeek models")}
39
+ ${n("models")} ${r("List available models")}
40
+ ${n("balance")} ${r("Check account balance")}
41
+ ${n("complete")} ${r("FIM code completion (Beta)")}
42
+ ${n("auth")} ${r("Authentication (login, logout)")}
43
+ ${n("config")} ${r("CLI configuration (show, set)")}
44
+
45
+ ${o("Global Flags:")}
46
+ ${n("--api-key <key>")} ${r("API key (overrides env var)")}
47
+ ${n("--base-url <url>")} ${r("API base URL")}
48
+ ${n("--output <format>")} ${r("Output format: text, json")}
49
+ ${n("--quiet")} ${r("Suppress non-essential output")}
50
+ ${n("--verbose")} ${r("Print HTTP details")}
51
+ ${n("--help")} ${r("Show help")}
52
+
53
+ ${o("Getting Help:")}
54
+ ${r("Add --help after any command.")}
55
+ ${r("Example:")} ds chat --help
56
+ `)}printCommandHelp(e,o){let n=a=>this.bold(a,o),r=a=>this.accent(a,o),s=a=>this.dim(a,o);if(o.write(`
57
+ ${e.description}
58
+ `),e.usage&&o.write(`${n("Usage:")} ${e.usage}
59
+ `),e.options&&e.options.length>0){let a=Math.max(...e.options.map(i=>i.flag.length));o.write(`
60
+ ${n("Options:")}
61
+ `);for(let i of e.options)o.write(` ${r(i.flag.padEnd(a+2))} ${s(i.description)}
62
+ `)}if(e.examples&&e.examples.length>0){o.write(`
63
+ ${n("Examples:")}
64
+ `);for(let a of e.examples)o.write(` ${s(a)}
65
+ `)}o.write(`
66
+ `)}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)}
67
+ `)}},S=new K({chat:H,models:B,balance:q,complete:X,"auth login":oe,"auth logout":ne,"config show":se,"config set":ae,help:ce})});b();G();u();T();I();function de(t){t instanceof x&&(t.suggestion?process.stderr.write(`
68
+ \x1B[1merror:\x1B[0m ${t.message}
69
+
70
+ -> ${t.suggestion}
71
+
72
+ `):process.stderr.write(`
73
+ \x1B[1merror:\x1B[0m ${t.message}
74
+
75
+ `),(t.code==="ENOTFOUND"||t.code==="ECONNREFUSED")&&(process.stderr.write(`
76
+ -> Check your network connection or proxy settings.
77
+ `),process.stderr.write(` -> Or set a proxy: ds config set proxy http://localhost:7890
78
+ `),process.exit(w.NETWORK)),process.exit(w.UNKNOWN)),process.stderr.write(`
79
+ \x1B[1merror:\x1B[0m ${String(t)}
80
+ `),process.exit(w.UNKNOWN)}$();P();process.on("SIGINT",()=>{process.stderr.write(`
81
+ Interrupted. Exiting.
82
+ `),process.exit(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);(t.includes("--version")||t.includes("-v"))&&(console.log(`ds ${N}`),process.exit(0));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"))&&(S.printHelp(e,process.stderr),process.exit(0)),e.length===0){if(S.printHelp([],process.stderr),!!o.apiKey){let{command:p}=S.resolve(["balance"]),g=O(t,[...A]),k=R(g);await p.execute(k,g)}else process.stderr.write(` Not logged in.
83
+ `),process.stderr.write(` ds auth login Login with your ds API key
84
+
85
+ `);process.exit(0)}let{command:r,extra:s}=S.resolve(e),a=t.slice(e.length),i=O(a,[...A,...r.options??[]]);s.length>0&&(i._positional=s);let m=R(i);if(!Ce.some(l=>l.every((p,g)=>e[g]===p))&&!m.apiKey){let l=process.env.ds_API_KEY;l||(process.stderr.write(`Error: No API key found. Run "ds auth login" or set ds_API_KEY env var.
86
+ `),process.exit(1)),m.apiKey=l}await r.execute(m,i)}ke().catch(de);
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@lzg14/deepseek-cli",
3
+ "version": "0.1.0",
4
+ "description": "Command-line tool for DeepSeek API",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=18"
8
+ },
9
+ "bin": {
10
+ "ds": "dist/ds.js"
11
+ },
12
+ "files": [
13
+ "dist/ds.js"
14
+ ],
15
+ "scripts": {
16
+ "dev": "node --experimental-strip-types src/main.ts",
17
+ "build": "node scripts/build.js",
18
+ "build:watch": "node scripts/build.js --watch",
19
+ "typecheck": "tsc --noEmit",
20
+ "test": "node --test test/**/*.test.ts"
21
+ },
22
+ "keywords": [
23
+ "deepseek",
24
+ "cli",
25
+ "ai"
26
+ ],
27
+ "author": "",
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/lzg14/DeepSeek-cli.git"
32
+ },
33
+ "dependencies": {},
34
+ "devDependencies": {
35
+ "typescript": "^5.8.3",
36
+ "esbuild": "^0.25.3"
37
+ }
38
+ }