studiorelay 0.3.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.
Files changed (55) hide show
  1. studiorelay-0.3.0/PKG-INFO +395 -0
  2. studiorelay-0.3.0/README.md +386 -0
  3. studiorelay-0.3.0/kimibridge/__init__.py +1 -0
  4. studiorelay-0.3.0/kimibridge/cli.py +461 -0
  5. studiorelay-0.3.0/kimibridge/compatibility/__init__.py +25 -0
  6. studiorelay-0.3.0/kimibridge/compatibility/errors.py +62 -0
  7. studiorelay-0.3.0/kimibridge/compatibility/model_aliases.py +44 -0
  8. studiorelay-0.3.0/kimibridge/compatibility/models.py +69 -0
  9. studiorelay-0.3.0/kimibridge/compatibility/parameters.py +29 -0
  10. studiorelay-0.3.0/kimibridge/compatibility/pipeline.py +42 -0
  11. studiorelay-0.3.0/kimibridge/compatibility/profiles.py +138 -0
  12. studiorelay-0.3.0/kimibridge/compatibility/responses.py +766 -0
  13. studiorelay-0.3.0/kimibridge/compatibility/roles.py +33 -0
  14. studiorelay-0.3.0/kimibridge/config.py +195 -0
  15. studiorelay-0.3.0/kimibridge/health.py +51 -0
  16. studiorelay-0.3.0/kimibridge/ports.py +255 -0
  17. studiorelay-0.3.0/kimibridge/server.py +309 -0
  18. studiorelay-0.3.0/kimibridge/service.py +182 -0
  19. studiorelay-0.3.0/kimibridge/upstream.py +168 -0
  20. studiorelay-0.3.0/pyproject.toml +20 -0
  21. studiorelay-0.3.0/setup.cfg +4 -0
  22. studiorelay-0.3.0/studiorelay/__init__.py +1 -0
  23. studiorelay-0.3.0/studiorelay/cli.py +514 -0
  24. studiorelay-0.3.0/studiorelay/compatibility/__init__.py +25 -0
  25. studiorelay-0.3.0/studiorelay/compatibility/errors.py +62 -0
  26. studiorelay-0.3.0/studiorelay/compatibility/model_aliases.py +44 -0
  27. studiorelay-0.3.0/studiorelay/compatibility/models.py +69 -0
  28. studiorelay-0.3.0/studiorelay/compatibility/parameters.py +29 -0
  29. studiorelay-0.3.0/studiorelay/compatibility/pipeline.py +42 -0
  30. studiorelay-0.3.0/studiorelay/compatibility/profiles.py +138 -0
  31. studiorelay-0.3.0/studiorelay/compatibility/responses.py +766 -0
  32. studiorelay-0.3.0/studiorelay/compatibility/roles.py +33 -0
  33. studiorelay-0.3.0/studiorelay/config.py +326 -0
  34. studiorelay-0.3.0/studiorelay/health.py +53 -0
  35. studiorelay-0.3.0/studiorelay/ports.py +277 -0
  36. studiorelay-0.3.0/studiorelay/server.py +321 -0
  37. studiorelay-0.3.0/studiorelay/service.py +237 -0
  38. studiorelay-0.3.0/studiorelay/upstream.py +171 -0
  39. studiorelay-0.3.0/studiorelay.egg-info/PKG-INFO +395 -0
  40. studiorelay-0.3.0/studiorelay.egg-info/SOURCES.txt +53 -0
  41. studiorelay-0.3.0/studiorelay.egg-info/dependency_links.txt +1 -0
  42. studiorelay-0.3.0/studiorelay.egg-info/entry_points.txt +4 -0
  43. studiorelay-0.3.0/studiorelay.egg-info/top_level.txt +2 -0
  44. studiorelay-0.3.0/tests/test_build.py +37 -0
  45. studiorelay-0.3.0/tests/test_cli.py +159 -0
  46. studiorelay-0.3.0/tests/test_config.py +89 -0
  47. studiorelay-0.3.0/tests/test_errors.py +66 -0
  48. studiorelay-0.3.0/tests/test_integration.py +940 -0
  49. studiorelay-0.3.0/tests/test_models.py +73 -0
  50. studiorelay-0.3.0/tests/test_pipeline.py +120 -0
  51. studiorelay-0.3.0/tests/test_ports.py +128 -0
  52. studiorelay-0.3.0/tests/test_profiles.py +103 -0
  53. studiorelay-0.3.0/tests/test_roles.py +55 -0
  54. studiorelay-0.3.0/tests/test_service.py +210 -0
  55. studiorelay-0.3.0/tests/test_studiorelay.py +239 -0
@@ -0,0 +1,395 @@
1
+ Metadata-Version: 2.4
2
+ Name: studiorelay
3
+ Version: 0.3.0
4
+ Summary: An OpenAI-compatible gateway that bridges Android Studio's AI agent with multiple LLM providers, handling API compatibility, request translation, streaming, and response normalization.
5
+ Author: StudioRelay contributors
6
+ License: MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+
10
+ # StudioRelay
11
+
12
+ ### Connect Android Studio's AI Agent to the AI Models You Choose.
13
+
14
+ > **Tagline:** One IDE Agent. Multiple AI Models. Zero Vendor Lock-in.
15
+
16
+ ---
17
+
18
+ ## Overview
19
+
20
+ Android Studio's AI agent is powerful, but connecting it to alternative AI providers can involve compatibility challenges.
21
+
22
+ StudioRelay is an open-source compatibility gateway designed to bridge that gap.
23
+
24
+ It translates API requests and responses between Android Studio's AI agent and supported LLM providers, helping different models work within the same agentic development workflow.
25
+
26
+ Use Kimi. Use DeepSeek. Add more providers. Keep your IDE agent.
27
+
28
+ Android Studio's AI agent remains responsible for its agentic workflow, including understanding coding tasks, using project context, interacting with tools, and coordinating development operations. StudioRelay provides the local compatibility infrastructure between that IDE agent and your selected LLM provider, handling the protocol adaptation necessary for supported providers to work with the IDE's expected API behavior.
29
+
30
+ ---
31
+
32
+ ## Problem Statement
33
+
34
+ When connecting Android Studio's AI agent to alternative LLM providers (such as DeepSeek or Kimi / Moonshot AI), developers frequently encounter API protocol divergences:
35
+
36
+ 1. **Unsupported Message Roles (`HTTP 422: unknown variant developer`)**: Android Studio sends system/developer prompts with `role: "developer"`. Strict upstream APIs (such as DeepSeek's deserializer) reject this role before inference begins.
37
+ 2. **Missing Endpoint (`POST /v1/responses 404`)**: Android Studio AI Assistant calls the newer OpenAI Responses API (`/v1/responses`). Most alternative LLM providers only expose `/v1/chat/completions`.
38
+ 3. **Incompatible Request Parameters**: Parameters like `store`, `metadata`, or `parallel_tool_calls` trigger deserialization errors on alternative providers.
39
+ 4. **Blank Thinking Output**: Models like DeepSeek Reasoner emit thinking in `reasoning_content` while leaving final `content` empty, causing standard OpenAI clients to display blank answers.
40
+ 5. **Port and Service Conflicts**: Running multiple alternative providers simultaneously typically causes port collisions and model dropdown confusion.
41
+
42
+ ---
43
+
44
+ ## How StudioRelay Works
45
+
46
+ StudioRelay acts as a transparent, high-performance local proxy:
47
+
48
+ 1. **Local Gateway**: Binds locally (`127.0.0.1:5001` for DeepSeek, `127.0.0.1:5002` for Kimi) with zero external exposure.
49
+ 2. **Protocol Adaptation**: Intercepts `/v1/chat/completions` and `/v1/responses`, maps `developer` messages to `system`, filters unsupported parameters, and translates Responses API schemas into Chat Completions.
50
+ 3. **Reasoning Fallback**: When thinking models return `reasoning_content` with empty final `content`, StudioRelay surfaces the reasoning as visible text so answers are never blank.
51
+ 4. **Zero-Latency Streaming**: Translates Server-Sent Events (SSE) line-by-line in real time.
52
+ 5. **Dual Service Isolation**: Runs dedicated background service daemons on separate ports so both DeepSeek and Kimi can be active in Android Studio simultaneously.
53
+
54
+ ---
55
+
56
+ ## Architecture Overview
57
+
58
+ ```text
59
+ Android Studio AI Agent
60
+ (or Cursor, VS Code, Aider, Open WebUI)
61
+ │
62
+ ▼
63
+ ┌──────────────────┐
64
+ │ StudioRelay │
65
+ │ Local Gateway │
66
+ │ (127.0.0.1) │
67
+ └────────┬─────────┘
68
+ │
69
+ ▼
70
+ ┌──────────────────┐
71
+ │ Compatibility │
72
+ │ Engine │
73
+ │ - Role Adapter │
74
+ │ - Param Filter │
75
+ │ - Responses API │
76
+ │ - Reasoning Map │
77
+ └────────┬─────────┘
78
+ │
79
+ ┌──────────────┴──────────────┐
80
+ ▼ ▼
81
+ DeepSeek Profile Kimi/Moonshot Profile
82
+ (Port 5001 / v1) (Port 5002 / v1)
83
+ │ │
84
+ ▼ ▼
85
+ api.deepseek.com api.moonshot.ai
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Supported Providers
91
+
92
+ - **DeepSeek** (`https://api.deepseek.com`):
93
+ - Supported models: `deepseek-chat`, `deepseek-reasoner`, `deepseek-v3-pro`, `deepseek-flash`, `deepseek-v3`, `deepseek-r1`
94
+ - Automatic alias rewriting: `deepseek-chat` ➔ `deepseek-flash`, `deepseek-reasoner` ➔ `deepseek-flash` with `reasoning_effort=high`, `deepseek-v3-pro` ➔ `deepseek-v4-pro`
95
+ - Normalizes `developer` role to `system` to prevent HTTP 422 errors
96
+ - Normalizes `reasoning_content` fallback when `content` is empty
97
+ - **Kimi / Moonshot AI** (`https://api.moonshot.ai`):
98
+ - Supported models: `kimi-k3`, `moonshot-v1-8k`, `moonshot-v1-32k`, `moonshot-v1-128k`
99
+ - Normalizes `developer` role to `system`
100
+ - Strips unsupported parameters (`store`, `metadata`, `parallel_tool_calls`)
101
+ - **OpenAI / Generic Passthrough**:
102
+ - Preserves standard schema for native OpenAI endpoints or generic proxies
103
+
104
+ ---
105
+
106
+ ## Features
107
+
108
+ - ⚡ **Zero-Latency Streaming**: Line-by-line SSE chunk forwarding.
109
+ - 🔄 **Responses API Bridge**: Seamless support for Android Studio's `/v1/responses` queries.
110
+ - 🧠 **Reasoning Fallback**: Always displays reasoning content if final content is empty.
111
+ - 🛡️ **Zero Secret Logging**: Never logs `Authorization` headers, API keys, or tokens.
112
+ - 🔌 **Intelligent Port Allocation**: Automatically detects port availability and avoids conflicts (`--auto-port`).
113
+ - 🖥️ **Background Service Daemons**: Native `systemd` user units on Linux, `launchd` LaunchAgents on macOS, and `Task Scheduler` on Windows.
114
+ - 📦 **Zero Runtime Dependencies**: Built entirely on the Python Standard Library (`http.server`, `urllib`, `dataclasses`, `argparse`).
115
+ - 🔙 **Full Backward Compatibility**: Seamlessly supports existing `kimibridge` commands, imports, configurations, and service files.
116
+
117
+ ---
118
+
119
+ ## Prerequisites
120
+
121
+ - **Python**: `3.10+` (3.10, 3.11, or 3.12)
122
+ - **Operating System**:
123
+ - **Linux**: `systemd` with user session support (`systemctl --user`), `procps`
124
+ - **macOS**: macOS 11.0 (Big Sur) or newer with `launchd`
125
+ - **Windows**: Windows 10/11 with PowerShell 5.1+ and Task Scheduler
126
+ - **Git**: `2.20+`
127
+
128
+ ---
129
+
130
+ ## Installation
131
+
132
+ ### Recommended: 1-Step Setup for DeepSeek
133
+
134
+ **Linux / macOS:**
135
+ ```bash
136
+ git clone https://github.com/SubhankarCodeGeek/studio-relay.git
137
+ cd studio-relay
138
+ ./installers/install-deepseek.sh
139
+ ```
140
+
141
+ **Windows (PowerShell):**
142
+ ```powershell
143
+ git clone https://github.com/SubhankarCodeGeek/studio-relay.git
144
+ cd studio-relay
145
+ .\installers\install-deepseek.ps1
146
+ ```
147
+
148
+ ### 1-Step Setup for Kimi / Moonshot AI
149
+
150
+ **Linux / macOS:**
151
+ ```bash
152
+ ./installers/install-kimi.sh
153
+ ```
154
+
155
+ **Windows (PowerShell):**
156
+ ```powershell
157
+ .\installers\install.ps1 -Kimi
158
+ ```
159
+
160
+ ### Interactive Installation (Choose or Run Multiple Providers)
161
+
162
+ - **Linux / macOS:** `./installers/install.sh`
163
+ - **Windows (PowerShell):** `.\installers\install.ps1`
164
+
165
+ The installer sets up application files in `~/.studiorelay/app` and registers your background service.
166
+
167
+ ---
168
+
169
+ ## Upgrade from KimiBridge
170
+
171
+ StudioRelay provides a safe, non-destructive upgrade path for existing KimiBridge installations:
172
+
173
+ 1. **Step 1: Migrate Configuration (Optional, installer also handles this)**
174
+ ```bash
175
+ studiorelay migrate --dry-run
176
+ studiorelay migrate
177
+ ```
178
+ This safely copies configs from `~/.kimibridge/` to `~/.studiorelay/` with an automated timestamped backup in `~/.kimibridge/backups/`. Secrets are never logged.
179
+
180
+ 2. **Step 2: Update Application & Services**
181
+ ```bash
182
+ cd studio-relay && git pull origin main
183
+ ./installers/install.sh
184
+ ```
185
+ The installer automatically detects active legacy `kimibridge-*.service` units, stops and disables them to prevent port collisions, and enables the new `studiorelay-*.service`.
186
+
187
+ 3. **Step 3: Verify Upgrade**
188
+ ```bash
189
+ studiorelay doctor
190
+ ```
191
+
192
+ *(Note: Legacy `kimibridge` commands and `~/.kimibridge` configuration files remain fully functional via backward-compatibility aliases).*
193
+
194
+ ---
195
+
196
+ ## Android Studio Configuration
197
+
198
+ Configure supported providers in Android Studio without touching IDE internals:
199
+
200
+ ### 1. Configure DeepSeek
201
+ 1. Open **Android Studio** ➔ **Settings** (or **Preferences** on macOS) ➔ **Tools** ➔ **AI Assistant**.
202
+ 2. Select **Custom OpenAI Provider** (or OpenAI-compatible).
203
+ 3. Set **Base URL**: `http://127.0.0.1:5001/v1`
204
+ 4. Set **API Key**: *Your DeepSeek API Key*
205
+ 5. Click **Refresh** to populate models (`deepseek-chat`, `deepseek-reasoner`, `deepseek-v3-pro`, `deepseek-flash`).
206
+ 6. Click **Apply**.
207
+
208
+ ### 2. Configure Kimi / Moonshot AI
209
+ 1. Add a second OpenAI-compatible provider entry in Android Studio.
210
+ 2. Set **Base URL**: `http://127.0.0.1:5002/v1`
211
+ 3. Set **API Key**: *Your Moonshot / Kimi API Key*
212
+ 4. Click **Refresh** to populate models (`kimi-k3`, `moonshot-v1-8k`, etc.).
213
+ 5. Click **Apply**.
214
+
215
+ Both providers run concurrently in the background with zero port collisions and zero dropdown interference!
216
+
217
+ ---
218
+
219
+ ## Provider Configuration
220
+
221
+ Switch or reconfigure target providers anytime:
222
+
223
+ ```bash
224
+ # Switch to DeepSeek
225
+ studiorelay setup deepseek
226
+
227
+ # Switch to Kimi / Moonshot
228
+ studiorelay setup kimi
229
+
230
+ # Expose both provider model lists concurrently
231
+ studiorelay setup all
232
+ ```
233
+
234
+ ---
235
+
236
+ ## CLI Usage
237
+
238
+ StudioRelay provides a complete management CLI:
239
+
240
+ ```bash
241
+ # Check version
242
+ studiorelay --version
243
+
244
+ # Show help
245
+ studiorelay --help
246
+
247
+ # Run comprehensive system diagnostics
248
+ studiorelay doctor
249
+
250
+ # Inspect running provider endpoints
251
+ studiorelay status
252
+
253
+ # View recent service logs
254
+ studiorelay logs
255
+ studiorelay logs --provider deepseek
256
+
257
+ # Start server in foreground (development mode)
258
+ studiorelay start --auto-port
259
+
260
+ # Migrate legacy configurations
261
+ studiorelay migrate
262
+ ```
263
+
264
+ *(The `kimibridge` CLI executable is also installed as an alias to `studiorelay`).*
265
+
266
+ ---
267
+
268
+ ## Configuration Management
269
+
270
+ Configuration precedence is strictly deterministic:
271
+
272
+ 1. **Explicit path argument** (`--config /path/to/config.json`)
273
+ 2. **`STUDIORELAY_CONFIG`** environment variable
274
+ 3. **`KIMIBRIDGE_CONFIG`** environment variable (legacy)
275
+ 4. **StudioRelay directory** (`~/.studiorelay/config-<provider>.json` or `config.json`)
276
+ 5. **Legacy KimiBridge directory** (`~/.kimibridge/config-<provider>.json` or `config.json`)
277
+
278
+ To inspect or update settings:
279
+
280
+ ```bash
281
+ # View active configuration (secrets masked)
282
+ studiorelay config show
283
+
284
+ # Set custom port
285
+ studiorelay config set port 5003
286
+
287
+ # Set custom upstream base URL
288
+ studiorelay config set base-url https://api.deepseek.com
289
+
290
+ # Change compatibility mode
291
+ studiorelay config set compatibility-mode compatible
292
+ ```
293
+
294
+ ---
295
+
296
+ ## Service Management
297
+
298
+ ### Linux (`systemd --user`)
299
+ ```bash
300
+ # Check service status
301
+ systemctl --user status studiorelay-deepseek
302
+
303
+ # View journal logs
304
+ journalctl --user -u studiorelay-deepseek -n 50 --no-pager
305
+
306
+ # Restart service via CLI
307
+ studiorelay restart --provider deepseek
308
+ ```
309
+
310
+ ### macOS (`launchd`)
311
+ ```bash
312
+ studiorelay restart
313
+ studiorelay logs
314
+ ```
315
+
316
+ ### Windows (Task Scheduler)
317
+ ```powershell
318
+ studiorelay restart
319
+ studiorelay status
320
+ ```
321
+
322
+ ---
323
+
324
+ ## Health Checks
325
+
326
+ StudioRelay provides local health diagnostic endpoints:
327
+
328
+ ```bash
329
+ # Check JSON health endpoint
330
+ curl http://127.0.0.1:5001/health
331
+
332
+ # Output:
333
+ # {"status": "ok", "service": "kimibridge", "gateway": "studiorelay", "provider": "deepseek", "port": 5001}
334
+ ```
335
+
336
+ Or run `studiorelay doctor` for complete endpoint validation.
337
+
338
+ ---
339
+
340
+ ## Troubleshooting
341
+
342
+ - **Port in Use**: If port 5001 is already taken by another application, run `studiorelay start --auto-port` or `studiorelay setup deepseek --port 5003`.
343
+ - **422 Unknown Variant Developer**: Ensure Android Studio base URL points to `http://127.0.0.1:5001/v1` so StudioRelay normalizes the message role.
344
+ - **Empty Thinking Output**: Ensure you are running StudioRelay 0.3.0+, which automatically extracts `reasoning_content` into visible output.
345
+ - **For more solutions**, see [Troubleshooting Guide](docs/troubleshooting.md).
346
+
347
+ ---
348
+
349
+ ## Security
350
+
351
+ - **Localhost Loopback Only**: The server binds exclusively to `127.0.0.1`.
352
+ - **Credential Safety**: StudioRelay never logs, saves, or prints `Authorization` headers or API keys.
353
+ - **Client Header Forwarding**: API keys entered in Android Studio are forwarded directly to upstream providers via secure HTTPS.
354
+ - For complete details, see [Security Policy](SECURITY.md).
355
+
356
+ ---
357
+
358
+ ## Development Setup
359
+
360
+ ```bash
361
+ # Clone the repository
362
+ git clone https://github.com/SubhankarCodeGeek/studio-relay.git
363
+ cd studio-relay
364
+
365
+ # (Optional) Create virtual environment
366
+ python3 -m venv .venv
367
+ source .venv/bin/activate
368
+
369
+ # Verify bytecode compilation
370
+ python3 -m compileall studiorelay kimibridge tests
371
+ ```
372
+
373
+ ---
374
+
375
+ ## Running Tests
376
+
377
+ Run the full automated unit and integration test suite:
378
+
379
+ ```bash
380
+ python3 -m unittest discover -s tests
381
+ ```
382
+
383
+ All tests execute with local mocks and require zero external API credits or credentials.
384
+
385
+ ---
386
+
387
+ ## Contributing
388
+
389
+ We welcome contributions! Please review our [Contributing Guide](CONTRIBUTING.md) for architecture details, testing conventions, and pull request guidelines.
390
+
391
+ ---
392
+
393
+ ## License
394
+
395
+ [MIT](LICENSE) © StudioRelay contributors.