coderoute 0.1.0__tar.gz → 0.2.0__tar.gz

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.
File without changes
@@ -1,55 +1,61 @@
1
- Metadata-Version: 2.4
2
- Name: coderoute
3
- Version: 0.1.0
4
- Summary: CodeRoute - AI coding agent on cheap Chinese models (DeepSeek/GLM/Kimi), billed in RMB. Built on aider.
5
- Author: CodeRoute
6
- License: Apache-2.0
7
- Project-URL: Homepage, https://www.bbfps.cloud
8
- Keywords: ai,coding-agent,aider,deepseek,glm,kimi,llm,cli
9
- Classifier: Development Status :: 4 - Beta
10
- Classifier: Environment :: Console
11
- Classifier: Intended Audience :: Developers
12
- Classifier: License :: OSI Approved :: Apache Software License
13
- Classifier: Programming Language :: Python :: 3
14
- Classifier: Topic :: Software Development :: Code Generators
15
- Requires-Python: >=3.9
16
- Description-Content-Type: text/markdown
17
- License-File: NOTICE
18
- Requires-Dist: aider-chat>=0.86
19
- Dynamic: license-file
20
-
21
- # CodeRoute CLI
22
-
23
- 用便宜的国产模型(DeepSeek / GLM / Kimi)写代码的命令行编程助手。基于 [aider](https://aider.chat),默认跑在 CodeRoute 网关上,人民币计费、国内直连。
24
-
25
- ## 安装
26
-
27
- ```bash
28
- pip install coderoute
29
- ```
30
-
31
- ## 使用
32
-
33
- ```bash
34
- coderoute login # 在控制台建一个 API Key,粘贴进来(一次即可)
35
- cd 你的项目
36
- coderoute # 启动,默认 deepseek(最便宜)
37
- coderoute --model openai/glm-4.7 ... # 换强一点的模型
38
- coderoute --model openai/kimi-k2-code ... # 长上下文
39
- ```
40
-
41
- 其余参数原样透传给 aider(`--message`、`--yes-always` 等)。
42
-
43
- ## 它做了什么
44
-
45
- 这是 aider 的一层薄包装,启动时锁定:
46
- - base URL = CodeRoute 网关
47
- - 默认模型 = `deepseek-fast`
48
- - 各模型的兼容性怪癖(如 kimi 强制 `temperature=1`)
49
-
50
- 核心编程能力来自 aider(Apache-2.0)。本包仅做品牌与默认配置。
51
-
52
- ## 配置
53
-
54
- - 本地 key 存于 `~/.config/coderoute/config.json`
55
- - 临时改网关地址(测试用):环境变量 `CODEROUTE_BASE_URL`、`CODEROUTE_API_KEY`
1
+ Metadata-Version: 2.4
2
+ Name: coderoute
3
+ Version: 0.2.0
4
+ Summary: CodeRoute - AI coding agent on cheap Chinese models (DeepSeek/GLM/Kimi), billed in RMB. Built on aider.
5
+ Author: CodeRoute
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://www.bbfps.cloud
8
+ Keywords: ai,coding-agent,aider,deepseek,glm,kimi,llm,cli
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Software Development :: Code Generators
15
+ Requires-Python: >=3.9
16
+ Description-Content-Type: text/markdown
17
+ License-File: NOTICE
18
+ Requires-Dist: aider-chat>=0.86
19
+ Dynamic: license-file
20
+
21
+ # CodeRoute CLI
22
+
23
+ 用便宜的国产模型(DeepSeek / GLM / Kimi)写代码的命令行编程助手。基于 [aider](https://aider.chat),默认跑在 CodeRoute 网关上,人民币计费、国内直连。
24
+
25
+ ## 安装
26
+
27
+ ```bash
28
+ pip install coderoute
29
+ ```
30
+
31
+ 国内推荐用清华源(连同 aider 依赖一起,秒装、免超时):
32
+
33
+ ```bash
34
+ pip install coderoute -i https://pypi.tuna.tsinghua.edu.cn/simple
35
+ ```
36
+
37
+ ## 使用
38
+
39
+ ```bash
40
+ coderoute login # 在控制台建一个 API Key,粘贴进来(一次即可)
41
+ cd 你的项目
42
+ coderoute # 启动,默认 deepseek(最便宜)
43
+ coderoute --model openai/glm-4.7 ... # 换强一点的模型
44
+ coderoute --model openai/kimi-k2-code ... # 长上下文
45
+ ```
46
+
47
+ 其余参数原样透传给 aider(`--message`、`--yes-always` 等)。
48
+
49
+ ## 它做了什么
50
+
51
+ 这是 aider 的一层薄包装,启动时锁定:
52
+ - base URL = CodeRoute 网关
53
+ - 默认模型 = `deepseek-fast`
54
+ - 各模型的兼容性怪癖(如 kimi 强制 `temperature=1`)
55
+
56
+ 核心编程能力来自 aider(Apache-2.0)。本包仅做品牌与默认配置。
57
+
58
+ ## 配置
59
+
60
+ - 本地 key 存于 `~/.config/coderoute/config.json`
61
+ - 临时改网关地址(测试用):环境变量 `CODEROUTE_BASE_URL`、`CODEROUTE_API_KEY`
@@ -8,6 +8,12 @@
8
8
  pip install coderoute
9
9
  ```
10
10
 
11
+ 国内推荐用清华源(连同 aider 依赖一起,秒装、免超时):
12
+
13
+ ```bash
14
+ pip install coderoute -i https://pypi.tuna.tsinghua.edu.cn/simple
15
+ ```
16
+
11
17
  ## 使用
12
18
 
13
19
  ```bash
@@ -1,55 +1,61 @@
1
- Metadata-Version: 2.4
2
- Name: coderoute
3
- Version: 0.1.0
4
- Summary: CodeRoute - AI coding agent on cheap Chinese models (DeepSeek/GLM/Kimi), billed in RMB. Built on aider.
5
- Author: CodeRoute
6
- License: Apache-2.0
7
- Project-URL: Homepage, https://www.bbfps.cloud
8
- Keywords: ai,coding-agent,aider,deepseek,glm,kimi,llm,cli
9
- Classifier: Development Status :: 4 - Beta
10
- Classifier: Environment :: Console
11
- Classifier: Intended Audience :: Developers
12
- Classifier: License :: OSI Approved :: Apache Software License
13
- Classifier: Programming Language :: Python :: 3
14
- Classifier: Topic :: Software Development :: Code Generators
15
- Requires-Python: >=3.9
16
- Description-Content-Type: text/markdown
17
- License-File: NOTICE
18
- Requires-Dist: aider-chat>=0.86
19
- Dynamic: license-file
20
-
21
- # CodeRoute CLI
22
-
23
- 用便宜的国产模型(DeepSeek / GLM / Kimi)写代码的命令行编程助手。基于 [aider](https://aider.chat),默认跑在 CodeRoute 网关上,人民币计费、国内直连。
24
-
25
- ## 安装
26
-
27
- ```bash
28
- pip install coderoute
29
- ```
30
-
31
- ## 使用
32
-
33
- ```bash
34
- coderoute login # 在控制台建一个 API Key,粘贴进来(一次即可)
35
- cd 你的项目
36
- coderoute # 启动,默认 deepseek(最便宜)
37
- coderoute --model openai/glm-4.7 ... # 换强一点的模型
38
- coderoute --model openai/kimi-k2-code ... # 长上下文
39
- ```
40
-
41
- 其余参数原样透传给 aider(`--message`、`--yes-always` 等)。
42
-
43
- ## 它做了什么
44
-
45
- 这是 aider 的一层薄包装,启动时锁定:
46
- - base URL = CodeRoute 网关
47
- - 默认模型 = `deepseek-fast`
48
- - 各模型的兼容性怪癖(如 kimi 强制 `temperature=1`)
49
-
50
- 核心编程能力来自 aider(Apache-2.0)。本包仅做品牌与默认配置。
51
-
52
- ## 配置
53
-
54
- - 本地 key 存于 `~/.config/coderoute/config.json`
55
- - 临时改网关地址(测试用):环境变量 `CODEROUTE_BASE_URL`、`CODEROUTE_API_KEY`
1
+ Metadata-Version: 2.4
2
+ Name: coderoute
3
+ Version: 0.2.0
4
+ Summary: CodeRoute - AI coding agent on cheap Chinese models (DeepSeek/GLM/Kimi), billed in RMB. Built on aider.
5
+ Author: CodeRoute
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://www.bbfps.cloud
8
+ Keywords: ai,coding-agent,aider,deepseek,glm,kimi,llm,cli
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Software Development :: Code Generators
15
+ Requires-Python: >=3.9
16
+ Description-Content-Type: text/markdown
17
+ License-File: NOTICE
18
+ Requires-Dist: aider-chat>=0.86
19
+ Dynamic: license-file
20
+
21
+ # CodeRoute CLI
22
+
23
+ 用便宜的国产模型(DeepSeek / GLM / Kimi)写代码的命令行编程助手。基于 [aider](https://aider.chat),默认跑在 CodeRoute 网关上,人民币计费、国内直连。
24
+
25
+ ## 安装
26
+
27
+ ```bash
28
+ pip install coderoute
29
+ ```
30
+
31
+ 国内推荐用清华源(连同 aider 依赖一起,秒装、免超时):
32
+
33
+ ```bash
34
+ pip install coderoute -i https://pypi.tuna.tsinghua.edu.cn/simple
35
+ ```
36
+
37
+ ## 使用
38
+
39
+ ```bash
40
+ coderoute login # 在控制台建一个 API Key,粘贴进来(一次即可)
41
+ cd 你的项目
42
+ coderoute # 启动,默认 deepseek(最便宜)
43
+ coderoute --model openai/glm-4.7 ... # 换强一点的模型
44
+ coderoute --model openai/kimi-k2-code ... # 长上下文
45
+ ```
46
+
47
+ 其余参数原样透传给 aider(`--message`、`--yes-always` 等)。
48
+
49
+ ## 它做了什么
50
+
51
+ 这是 aider 的一层薄包装,启动时锁定:
52
+ - base URL = CodeRoute 网关
53
+ - 默认模型 = `deepseek-fast`
54
+ - 各模型的兼容性怪癖(如 kimi 强制 `temperature=1`)
55
+
56
+ 核心编程能力来自 aider(Apache-2.0)。本包仅做品牌与默认配置。
57
+
58
+ ## 配置
59
+
60
+ - 本地 key 存于 `~/.config/coderoute/config.json`
61
+ - 临时改网关地址(测试用):环境变量 `CODEROUTE_BASE_URL`、`CODEROUTE_API_KEY`
@@ -0,0 +1 @@
1
+ __version__ = "0.2.0"
@@ -3,7 +3,9 @@ CodeRoute gateway with locked defaults (base URL, default model, model quirks)."
3
3
  import os
4
4
  import sys
5
5
  import json
6
- import getpass
6
+ import time
7
+ import urllib.request
8
+ import urllib.error
7
9
  from pathlib import Path
8
10
 
9
11
  from . import __version__
@@ -35,6 +37,73 @@ def save_config(cfg):
35
37
  pass
36
38
 
37
39
 
40
+ def _origin_of(base_url):
41
+ """从 /v1 接口地址推出站点根,用于拼 device 登录接口与浏览器授权页。"""
42
+ b = base_url.rstrip("/")
43
+ if b.endswith("/v1"):
44
+ b = b[:-3].rstrip("/")
45
+ return b
46
+
47
+
48
+ def _post_json(url, payload):
49
+ data = json.dumps(payload).encode("utf-8")
50
+ req = urllib.request.Request(
51
+ url, data=data, headers={"Content-Type": "application/json"}, method="POST"
52
+ )
53
+ try:
54
+ with urllib.request.urlopen(req, timeout=30) as resp:
55
+ return resp.status, json.loads(resp.read().decode("utf-8") or "{}")
56
+ except urllib.error.HTTPError as e:
57
+ try:
58
+ return e.code, json.loads(e.read().decode("utf-8") or "{}")
59
+ except Exception:
60
+ return e.code, {}
61
+ except urllib.error.URLError as e:
62
+ return 0, {"error": str(e.reason)}
63
+
64
+
65
+ def device_login(origin, cfg):
66
+ st, data = _post_json(origin + "/api/device/code", {})
67
+ if st != 200:
68
+ print(f"无法连接网关({origin}):{data.get('error') or ('HTTP ' + str(st))}")
69
+ return 1
70
+ user_code = data["user_code"]
71
+ device_code = data["device_code"]
72
+ interval = int(data.get("interval", 5))
73
+ deadline = time.time() + int(data.get("expires_in", 900))
74
+ verify = origin + "/console/device?code=" + user_code
75
+
76
+ print()
77
+ print(" 在浏览器中打开并登录授权:")
78
+ print(" " + verify)
79
+ print()
80
+ print(" 设备码: " + user_code)
81
+ print()
82
+ try:
83
+ import webbrowser
84
+ webbrowser.open(verify)
85
+ except Exception:
86
+ pass
87
+ print("等待浏览器授权…(完成后自动继续,Ctrl+C 取消)")
88
+
89
+ while time.time() < deadline:
90
+ time.sleep(interval)
91
+ st, data = _post_json(origin + "/api/device/token", {"device_code": device_code})
92
+ if st == 200 and data.get("status") == "approved":
93
+ cfg["api_key"] = data["api_key"]
94
+ cfg["base_url"] = data.get("base_url") or cfg.get("base_url") or DEFAULT_BASE_URL
95
+ save_config(cfg)
96
+ print(f"\n登录成功!base_url={cfg['base_url']}")
97
+ print("现在直接运行 `coderoute` 即可开始。")
98
+ return 0
99
+ if st == 400: # expired_token:停止轮询
100
+ print("\n设备码已过期,请重新运行 coderoute login。")
101
+ return 1
102
+ # 其余为 pending,继续轮询
103
+ print("\n等待超时,请重新运行 coderoute login。")
104
+ return 1
105
+
106
+
38
107
  def cmd_login(args):
39
108
  cfg = load_config()
40
109
  key = None
@@ -46,24 +115,24 @@ def cmd_login(args):
46
115
  base = rest.pop(0) if rest else None
47
116
  elif not a.startswith("-"):
48
117
  key = a
49
- target = base or cfg.get("base_url") or DEFAULT_BASE_URL
50
- if not key:
51
- print(f"在控制台创建 API Key 后粘贴到这里(来源 {target}):")
52
- try:
53
- key = getpass.getpass("API Key: ").strip()
54
- except (EOFError, KeyboardInterrupt):
55
- print("\n已取消。")
56
- return 1
57
- if not key:
58
- print("未输入 key,已取消。")
59
- return 1
60
- cfg["api_key"] = key
61
118
  if base:
62
119
  cfg["base_url"] = base
63
- save_config(cfg)
64
- print(f"已保存。base_url={cfg.get('base_url', DEFAULT_BASE_URL)} key={key[:6]}…")
65
- print("现在直接运行 `coderoute` 即可开始。")
66
- return 0
120
+ target_base = base or cfg.get("base_url") or DEFAULT_BASE_URL
121
+
122
+ # 高级/离线:直接粘贴已有 key -> coderoute login sk-xxxx
123
+ if key:
124
+ cfg["api_key"] = key
125
+ save_config(cfg)
126
+ print(f"已保存。base_url={cfg.get('base_url', DEFAULT_BASE_URL)} key={key[:6]}…")
127
+ print("现在直接运行 `coderoute` 即可开始。")
128
+ return 0
129
+
130
+ # 默认:浏览器一键授权(device-code),无需手动建 Key/复制粘贴
131
+ try:
132
+ return device_login(_origin_of(target_base), cfg)
133
+ except KeyboardInterrupt:
134
+ print("\n已取消。")
135
+ return 1
67
136
 
68
137
 
69
138
  def cmd_logout(_args):
@@ -77,7 +146,8 @@ def print_help():
77
146
  print(BANNER)
78
147
  print()
79
148
  print("用法:")
80
- print(" coderoute login 保存网关 API key(一次即可)")
149
+ print(" coderoute login 浏览器一键登录授权(一次即可)")
150
+ print(" coderoute login sk-xxxx 直接粘贴已有 key(离线/高级)")
81
151
  print(" coderoute [文件...] [aider参数...] 启动编程助手(默认模型 deepseek)")
82
152
  print(" coderoute --model openai/glm-4.7 ... 指定其它模型")
83
153
  print(" coderoute --model openai/kimi-k2-code ...")
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "coderoute"
3
- version = "0.1.0"
3
+ version = "0.2.0"
4
4
  description = "CodeRoute - AI coding agent on cheap Chinese models (DeepSeek/GLM/Kimi), billed in RMB. Built on aider."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.9"
@@ -1,4 +1,4 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -1 +0,0 @@
1
- __version__ = "0.1.0"