workbuddy2api 2.0.4__tar.gz → 2.0.6__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.
Files changed (22) hide show
  1. {workbuddy2api-2.0.4/src/workbuddy2api.egg-info → workbuddy2api-2.0.6}/PKG-INFO +115 -7
  2. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/README.md +114 -6
  3. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/pyproject.toml +8 -5
  4. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/src/codebuddy_proxy/__main__.py +256 -138
  5. workbuddy2api-2.0.6/src/codebuddy_proxy/backend_profile.py +198 -0
  6. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/src/codebuddy_proxy/codebuddy_client_demo.py +229 -109
  7. workbuddy2api-2.0.6/src/codebuddy_proxy/models_config.domestic.json +464 -0
  8. workbuddy2api-2.0.6/src/codebuddy_proxy/models_config.global.json +150 -0
  9. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6/src/workbuddy2api.egg-info}/PKG-INFO +115 -7
  10. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/src/workbuddy2api.egg-info/SOURCES.txt +3 -0
  11. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/LICENSE +0 -0
  12. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/setup.cfg +0 -0
  13. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/src/codebuddy_proxy/anthropic_adapter.py +0 -0
  14. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/src/codebuddy_proxy/desensitize.py +0 -0
  15. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/src/codebuddy_proxy/dsml_parser.py +0 -0
  16. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/src/codebuddy_proxy/projection_metadata.py +0 -0
  17. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/src/codebuddy_proxy/responses_adapter.py +0 -0
  18. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/src/codebuddy_proxy/responses_projection.py +0 -0
  19. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/src/workbuddy2api.egg-info/dependency_links.txt +0 -0
  20. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/src/workbuddy2api.egg-info/entry_points.txt +0 -0
  21. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/src/workbuddy2api.egg-info/requires.txt +0 -0
  22. {workbuddy2api-2.0.4 → workbuddy2api-2.0.6}/src/workbuddy2api.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: workbuddy2api
3
- Version: 2.0.4
3
+ Version: 2.0.6
4
4
  Summary: Local OpenAI/Responses/Anthropic compatible proxy for CodeBuddy
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -27,6 +27,7 @@ Dynamic: license-file
27
27
  - **Tool call support** - Full support for function calling and tool use, with automatic filtering of invalid tool definitions
28
28
  - **DSML parsing** - Automatically detects and converts DeepSeek Markup Language (DSML) tool calls
29
29
  - **Streaming responses** - SSE streaming output, returning generated content in real time, with built-in 60-second timeout protection
30
+ - **Domestic and international backends** - Uses domestic CodeBuddy by default and switches to the international CodeBuddy service with `--global`, with isolated sessions and model catalogs
30
31
  - **Multi-account management** - Supports isolation of multiple login states for easy switching between work/personal accounts
31
32
 
32
33
  ---
@@ -79,10 +80,72 @@ uv run --with workbuddy2api python -m codebuddy_proxy --desensitize
79
80
 
80
81
  # First use: log in and start
81
82
  uv run --with workbuddy2api python -m codebuddy_proxy --login --desensitize
83
+
84
+ # International service: first login and start
85
+ uv run --with workbuddy2api python -m codebuddy_proxy --global --login --desensitize
86
+
87
+ # International service: later starts
88
+ uv run --with workbuddy2api python -m codebuddy_proxy --global --desensitize
82
89
  ```
83
90
 
84
91
  Listens on `http://127.0.0.1:8787` by default.
85
92
 
93
+ ### Domestic and international CodeBuddy backends
94
+
95
+ The proxy supports both CodeBuddy regions. Domestic mode remains the default,
96
+ so existing startup commands continue to work unchanged.
97
+
98
+ | Mode | Startup option | Upstream endpoint | Default session file |
99
+ | --- | --- | --- | --- |
100
+ | Domestic (default) | none | `https://copilot.tencent.com` | `~/.codebuddy-session.json` |
101
+ | International | `--global` | `https://www.codebuddy.ai` | `~/.codebuddy-global-session.json` |
102
+
103
+ First login and daily startup for the international service:
104
+
105
+ ```bash
106
+ # First login
107
+ uv run --with workbuddy2api python -m codebuddy_proxy \
108
+ --global --login --desensitize
109
+
110
+ # Later starts reuse the international session
111
+ uv run --with workbuddy2api python -m codebuddy_proxy \
112
+ --global --desensitize
113
+ ```
114
+
115
+ If the package is installed as a command, the equivalent short form is
116
+ `workbuddy2api --global --login`. When running from source, use
117
+ `uv run python -m codebuddy_proxy --global --login`.
118
+
119
+ `--global` changes only the upstream service. Codex CLI, Claude Code/CC Switch,
120
+ OpenCode, and other clients continue to use the same local proxy URLs. The
121
+ selected profile also controls the model catalog returned by `/v1/models`.
122
+
123
+ Domestic and international sessions are intentionally isolated. An explicit
124
+ `--session-file` takes precedence, but its saved backend and endpoint must match
125
+ the current startup options. The proxy refuses mismatched credentials and does
126
+ not modify the original file.
127
+
128
+ For a custom international endpoint, always use a dedicated session file:
129
+
130
+ ```bash
131
+ uv run --with workbuddy2api python -m codebuddy_proxy \
132
+ --global \
133
+ --endpoint https://staging-codebuddy.tencent.com \
134
+ --session-file "$HOME/.codebuddy-global-staging-session.json" \
135
+ --login
136
+ ```
137
+
138
+ Endpoint precedence is: explicit `--endpoint` > the `--global` profile default
139
+ > `CODEBUDDY_ENDPOINT` in non-global mode > the domestic default endpoint.
140
+ Therefore `--global` without `--endpoint` cannot be redirected to the domestic
141
+ host by `CODEBUDDY_ENDPOINT`.
142
+
143
+ Runtime model catalogs are loaded from the packaged profile resources
144
+ `src/codebuddy_proxy/models_config.domestic.json` and
145
+ `src/codebuddy_proxy/models_config.global.json`. The root
146
+ `models_config.json` is retained only as a development-compatibility copy of
147
+ the domestic catalog and is not a runtime data source.
148
+
86
149
  ### 2. Verify
87
150
 
88
151
  ```bash
@@ -90,6 +153,10 @@ curl http://127.0.0.1:8787/health
90
153
  curl http://127.0.0.1:8787/v1/models
91
154
  ```
92
155
 
156
+ The health response reports the active `backend` (`domestic` or `global`) and
157
+ `upstream_endpoint`, which makes it easy to confirm the selected region before
158
+ connecting a client.
159
+
93
160
  ### 3. Connect clients
94
161
 
95
162
  #### Codex CLI
@@ -237,8 +304,9 @@ Select the model inside OMP with `/model codebuddy/hy3` (or set it as the defaul
237
304
  ```bash
238
305
  --host HOST Bind address (default 127.0.0.1)
239
306
  --port PORT Bind port (default 8787)
240
- --endpoint ENDPOINT CodeBuddy backend address
241
- --session-file PATH Session file path (default ~/.codebuddy-session.json)
307
+ --global Use the international CodeBuddy backend (default domestic)
308
+ --endpoint ENDPOINT CodeBuddy backend address (overrides the profile default)
309
+ --session-file PATH Session file path (isolated by profile by default)
242
310
  --log-file PATH JSONL log file (default ~/.workbuddy2api/codebuddy-proxy.jsonl)
243
311
  --desensitize Enable desensitization (recommended)
244
312
  --optimize-context Enable message compression (recommended for Codex CLI)
@@ -254,7 +322,7 @@ Select the model inside OMP with `/model codebuddy/hy3` (or set it as the defaul
254
322
  ```bash
255
323
  CODEBUDDY_PROXY_HOST # Same as --host
256
324
  CODEBUDDY_PROXY_PORT # Same as --port
257
- CODEBUDDY_ENDPOINT # Same as --endpoint
325
+ CODEBUDDY_ENDPOINT # Endpoint fallback in non-global mode
258
326
  CODEBUDDY_PROXY_LOG_FILE # Same as --log-file
259
327
  ```
260
328
 
@@ -269,6 +337,13 @@ uv run --with workbuddy2api python -m codebuddy_proxy --login \
269
337
 
270
338
  After the browser opens and you log in, the proxy starts automatically.
271
339
 
340
+ First login for the international backend:
341
+
342
+ ```bash
343
+ uv run --with workbuddy2api python -m codebuddy_proxy --global --login \
344
+ --log-file "$HOME/.workbuddy2api/codebuddy-proxy.jsonl"
345
+ ```
346
+
272
347
  ### Daily use (automatically reads the login state)
273
348
 
274
349
  ```bash
@@ -276,6 +351,13 @@ uv run --with workbuddy2api python -m codebuddy_proxy --desensitize \
276
351
  --log-file "$HOME/.workbuddy2api/codebuddy-proxy.jsonl"
277
352
  ```
278
353
 
354
+ For the international backend, keep `--global` on every startup:
355
+
356
+ ```bash
357
+ uv run --with workbuddy2api python -m codebuddy_proxy --global --desensitize \
358
+ --log-file "$HOME/.workbuddy2api/codebuddy-proxy.jsonl"
359
+ ```
360
+
279
361
  ### Codex CLI scenario (with compression enabled)
280
362
 
281
363
  ```bash
@@ -325,9 +407,11 @@ Example response:
325
407
  ```json
326
408
  {
327
409
  "status": "ok",
328
- "uptime_seconds": 123.45,
410
+ "uptime_seconds": 123,
329
411
  "authenticated": true,
330
- "token_valid": true
412
+ "token_valid": true,
413
+ "backend": "global",
414
+ "upstream_endpoint": "https://www.codebuddy.ai"
331
415
  }
332
416
  ```
333
417
 
@@ -337,7 +421,9 @@ Example response:
337
421
  curl http://127.0.0.1:8787/v1/models
338
422
  ```
339
423
 
340
- Returns a model list in OpenAI format; `data[].id` is the `model` value used in subsequent requests (e.g. `deepseek-v4-flash`, `glm-5.2`).
424
+ Returns the active backend's model catalog in OpenAI format. `data[].id` is the
425
+ `model` value used in subsequent requests; domestic and international mode may
426
+ expose different model IDs.
341
427
 
342
428
  ### `/v1/chat/completions` - OpenAI Chat
343
429
 
@@ -664,6 +750,28 @@ uv run --with workbuddy2api python -m codebuddy_proxy --login \
664
750
  --log-file "$HOME/.workbuddy2api/codebuddy-proxy.jsonl"
665
751
  ```
666
752
 
753
+ For the international backend, add `--global` to the same command. It creates
754
+ and later reuses `~/.codebuddy-global-session.json`.
755
+
756
+ ### Session backend or endpoint mismatch
757
+
758
+ Do not reuse a domestic session for the international backend, or a production
759
+ session for a custom endpoint. Log in with the same backend options you plan to
760
+ use later:
761
+
762
+ ```bash
763
+ # International default endpoint
764
+ uv run --with workbuddy2api python -m codebuddy_proxy --global --login
765
+
766
+ # Custom international endpoint with an isolated session
767
+ uv run --with workbuddy2api python -m codebuddy_proxy \
768
+ --global --endpoint https://staging-codebuddy.tencent.com \
769
+ --session-file "$HOME/.codebuddy-global-staging-session.json" --login
770
+ ```
771
+
772
+ The proxy intentionally rejects mismatched session metadata instead of sending
773
+ the saved token to another host.
774
+
667
775
  ### 401 authentication failure
668
776
 
669
777
  Token expired; log in again:
@@ -12,6 +12,7 @@
12
12
  - **Tool call support** - Full support for function calling and tool use, with automatic filtering of invalid tool definitions
13
13
  - **DSML parsing** - Automatically detects and converts DeepSeek Markup Language (DSML) tool calls
14
14
  - **Streaming responses** - SSE streaming output, returning generated content in real time, with built-in 60-second timeout protection
15
+ - **Domestic and international backends** - Uses domestic CodeBuddy by default and switches to the international CodeBuddy service with `--global`, with isolated sessions and model catalogs
15
16
  - **Multi-account management** - Supports isolation of multiple login states for easy switching between work/personal accounts
16
17
 
17
18
  ---
@@ -64,10 +65,72 @@ uv run --with workbuddy2api python -m codebuddy_proxy --desensitize
64
65
 
65
66
  # First use: log in and start
66
67
  uv run --with workbuddy2api python -m codebuddy_proxy --login --desensitize
68
+
69
+ # International service: first login and start
70
+ uv run --with workbuddy2api python -m codebuddy_proxy --global --login --desensitize
71
+
72
+ # International service: later starts
73
+ uv run --with workbuddy2api python -m codebuddy_proxy --global --desensitize
67
74
  ```
68
75
 
69
76
  Listens on `http://127.0.0.1:8787` by default.
70
77
 
78
+ ### Domestic and international CodeBuddy backends
79
+
80
+ The proxy supports both CodeBuddy regions. Domestic mode remains the default,
81
+ so existing startup commands continue to work unchanged.
82
+
83
+ | Mode | Startup option | Upstream endpoint | Default session file |
84
+ | --- | --- | --- | --- |
85
+ | Domestic (default) | none | `https://copilot.tencent.com` | `~/.codebuddy-session.json` |
86
+ | International | `--global` | `https://www.codebuddy.ai` | `~/.codebuddy-global-session.json` |
87
+
88
+ First login and daily startup for the international service:
89
+
90
+ ```bash
91
+ # First login
92
+ uv run --with workbuddy2api python -m codebuddy_proxy \
93
+ --global --login --desensitize
94
+
95
+ # Later starts reuse the international session
96
+ uv run --with workbuddy2api python -m codebuddy_proxy \
97
+ --global --desensitize
98
+ ```
99
+
100
+ If the package is installed as a command, the equivalent short form is
101
+ `workbuddy2api --global --login`. When running from source, use
102
+ `uv run python -m codebuddy_proxy --global --login`.
103
+
104
+ `--global` changes only the upstream service. Codex CLI, Claude Code/CC Switch,
105
+ OpenCode, and other clients continue to use the same local proxy URLs. The
106
+ selected profile also controls the model catalog returned by `/v1/models`.
107
+
108
+ Domestic and international sessions are intentionally isolated. An explicit
109
+ `--session-file` takes precedence, but its saved backend and endpoint must match
110
+ the current startup options. The proxy refuses mismatched credentials and does
111
+ not modify the original file.
112
+
113
+ For a custom international endpoint, always use a dedicated session file:
114
+
115
+ ```bash
116
+ uv run --with workbuddy2api python -m codebuddy_proxy \
117
+ --global \
118
+ --endpoint https://staging-codebuddy.tencent.com \
119
+ --session-file "$HOME/.codebuddy-global-staging-session.json" \
120
+ --login
121
+ ```
122
+
123
+ Endpoint precedence is: explicit `--endpoint` > the `--global` profile default
124
+ > `CODEBUDDY_ENDPOINT` in non-global mode > the domestic default endpoint.
125
+ Therefore `--global` without `--endpoint` cannot be redirected to the domestic
126
+ host by `CODEBUDDY_ENDPOINT`.
127
+
128
+ Runtime model catalogs are loaded from the packaged profile resources
129
+ `src/codebuddy_proxy/models_config.domestic.json` and
130
+ `src/codebuddy_proxy/models_config.global.json`. The root
131
+ `models_config.json` is retained only as a development-compatibility copy of
132
+ the domestic catalog and is not a runtime data source.
133
+
71
134
  ### 2. Verify
72
135
 
73
136
  ```bash
@@ -75,6 +138,10 @@ curl http://127.0.0.1:8787/health
75
138
  curl http://127.0.0.1:8787/v1/models
76
139
  ```
77
140
 
141
+ The health response reports the active `backend` (`domestic` or `global`) and
142
+ `upstream_endpoint`, which makes it easy to confirm the selected region before
143
+ connecting a client.
144
+
78
145
  ### 3. Connect clients
79
146
 
80
147
  #### Codex CLI
@@ -222,8 +289,9 @@ Select the model inside OMP with `/model codebuddy/hy3` (or set it as the defaul
222
289
  ```bash
223
290
  --host HOST Bind address (default 127.0.0.1)
224
291
  --port PORT Bind port (default 8787)
225
- --endpoint ENDPOINT CodeBuddy backend address
226
- --session-file PATH Session file path (default ~/.codebuddy-session.json)
292
+ --global Use the international CodeBuddy backend (default domestic)
293
+ --endpoint ENDPOINT CodeBuddy backend address (overrides the profile default)
294
+ --session-file PATH Session file path (isolated by profile by default)
227
295
  --log-file PATH JSONL log file (default ~/.workbuddy2api/codebuddy-proxy.jsonl)
228
296
  --desensitize Enable desensitization (recommended)
229
297
  --optimize-context Enable message compression (recommended for Codex CLI)
@@ -239,7 +307,7 @@ Select the model inside OMP with `/model codebuddy/hy3` (or set it as the defaul
239
307
  ```bash
240
308
  CODEBUDDY_PROXY_HOST # Same as --host
241
309
  CODEBUDDY_PROXY_PORT # Same as --port
242
- CODEBUDDY_ENDPOINT # Same as --endpoint
310
+ CODEBUDDY_ENDPOINT # Endpoint fallback in non-global mode
243
311
  CODEBUDDY_PROXY_LOG_FILE # Same as --log-file
244
312
  ```
245
313
 
@@ -254,6 +322,13 @@ uv run --with workbuddy2api python -m codebuddy_proxy --login \
254
322
 
255
323
  After the browser opens and you log in, the proxy starts automatically.
256
324
 
325
+ First login for the international backend:
326
+
327
+ ```bash
328
+ uv run --with workbuddy2api python -m codebuddy_proxy --global --login \
329
+ --log-file "$HOME/.workbuddy2api/codebuddy-proxy.jsonl"
330
+ ```
331
+
257
332
  ### Daily use (automatically reads the login state)
258
333
 
259
334
  ```bash
@@ -261,6 +336,13 @@ uv run --with workbuddy2api python -m codebuddy_proxy --desensitize \
261
336
  --log-file "$HOME/.workbuddy2api/codebuddy-proxy.jsonl"
262
337
  ```
263
338
 
339
+ For the international backend, keep `--global` on every startup:
340
+
341
+ ```bash
342
+ uv run --with workbuddy2api python -m codebuddy_proxy --global --desensitize \
343
+ --log-file "$HOME/.workbuddy2api/codebuddy-proxy.jsonl"
344
+ ```
345
+
264
346
  ### Codex CLI scenario (with compression enabled)
265
347
 
266
348
  ```bash
@@ -310,9 +392,11 @@ Example response:
310
392
  ```json
311
393
  {
312
394
  "status": "ok",
313
- "uptime_seconds": 123.45,
395
+ "uptime_seconds": 123,
314
396
  "authenticated": true,
315
- "token_valid": true
397
+ "token_valid": true,
398
+ "backend": "global",
399
+ "upstream_endpoint": "https://www.codebuddy.ai"
316
400
  }
317
401
  ```
318
402
 
@@ -322,7 +406,9 @@ Example response:
322
406
  curl http://127.0.0.1:8787/v1/models
323
407
  ```
324
408
 
325
- Returns a model list in OpenAI format; `data[].id` is the `model` value used in subsequent requests (e.g. `deepseek-v4-flash`, `glm-5.2`).
409
+ Returns the active backend's model catalog in OpenAI format. `data[].id` is the
410
+ `model` value used in subsequent requests; domestic and international mode may
411
+ expose different model IDs.
326
412
 
327
413
  ### `/v1/chat/completions` - OpenAI Chat
328
414
 
@@ -649,6 +735,28 @@ uv run --with workbuddy2api python -m codebuddy_proxy --login \
649
735
  --log-file "$HOME/.workbuddy2api/codebuddy-proxy.jsonl"
650
736
  ```
651
737
 
738
+ For the international backend, add `--global` to the same command. It creates
739
+ and later reuses `~/.codebuddy-global-session.json`.
740
+
741
+ ### Session backend or endpoint mismatch
742
+
743
+ Do not reuse a domestic session for the international backend, or a production
744
+ session for a custom endpoint. Log in with the same backend options you plan to
745
+ use later:
746
+
747
+ ```bash
748
+ # International default endpoint
749
+ uv run --with workbuddy2api python -m codebuddy_proxy --global --login
750
+
751
+ # Custom international endpoint with an isolated session
752
+ uv run --with workbuddy2api python -m codebuddy_proxy \
753
+ --global --endpoint https://staging-codebuddy.tencent.com \
754
+ --session-file "$HOME/.codebuddy-global-staging-session.json" --login
755
+ ```
756
+
757
+ The proxy intentionally rejects mismatched session metadata instead of sending
758
+ the saved token to another host.
759
+
652
760
  ### 401 authentication failure
653
761
 
654
762
  Token expired; log in again:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "workbuddy2api"
3
- version = "2.0.4"
3
+ version = "2.0.6"
4
4
  description = "Local OpenAI/Responses/Anthropic compatible proxy for CodeBuddy"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -23,10 +23,13 @@ workbuddy2api = "codebuddy_proxy.__main__:main"
23
23
  requires = ["setuptools>=61", "wheel"]
24
24
  build-backend = "setuptools.build_meta"
25
25
 
26
- [tool.setuptools.packages.find]
27
- where = ["src"]
28
-
29
- [dependency-groups]
26
+ [tool.setuptools.packages.find]
27
+ where = ["src"]
28
+
29
+ [tool.setuptools.package-data]
30
+ codebuddy_proxy = ["models_config.*.json"]
31
+
32
+ [dependency-groups]
30
33
  dev = [
31
34
  "pytest>=7.4.0",
32
35
  ]