sference-cli 0.2.0__tar.gz → 0.2.2__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.
- {sference_cli-0.2.0 → sference_cli-0.2.2}/PKG-INFO +2 -2
- {sference_cli-0.2.0 → sference_cli-0.2.2}/pyproject.toml +2 -2
- {sference_cli-0.2.0 → sference_cli-0.2.2}/sference_cli/_proxy_routing.py +12 -1
- {sference_cli-0.2.0 → sference_cli-0.2.2}/sference_cli/launch.py +29 -10
- {sference_cli-0.2.0 → sference_cli-0.2.2}/sference_cli/proxy.py +2 -4
- {sference_cli-0.2.0 → sference_cli-0.2.2}/.gitignore +0 -0
- {sference_cli-0.2.0 → sference_cli-0.2.2}/LICENSE +0 -0
- {sference_cli-0.2.0 → sference_cli-0.2.2}/README.md +0 -0
- {sference_cli-0.2.0 → sference_cli-0.2.2}/sference_cli/__init__.py +0 -0
- {sference_cli-0.2.0 → sference_cli-0.2.2}/sference_cli/_proxy_addon.py +0 -0
- {sference_cli-0.2.0 → sference_cli-0.2.2}/sference_cli/main.py +0 -0
- {sference_cli-0.2.0 → sference_cli-0.2.2}/sference_cli/stream_cache.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sference-cli
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: sference command-line interface
|
|
5
5
|
Project-URL: Homepage, https://sference.com
|
|
6
6
|
Project-URL: Repository, https://github.com/s-ference/sference
|
|
@@ -21,7 +21,7 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.13
|
|
22
22
|
Classifier: Topic :: Utilities
|
|
23
23
|
Requires-Python: >=3.10
|
|
24
|
-
Requires-Dist: sference-sdk>=0.2.
|
|
24
|
+
Requires-Dist: sference-sdk>=0.2.2
|
|
25
25
|
Requires-Dist: typer>=0.24.1
|
|
26
26
|
Description-Content-Type: text/markdown
|
|
27
27
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sference-cli"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.2"
|
|
4
4
|
description = "sference command-line interface"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
@@ -23,7 +23,7 @@ classifiers = [
|
|
|
23
23
|
]
|
|
24
24
|
dependencies = [
|
|
25
25
|
"typer>=0.24.1",
|
|
26
|
-
"sference-sdk>=0.2.
|
|
26
|
+
"sference-sdk>=0.2.2",
|
|
27
27
|
]
|
|
28
28
|
|
|
29
29
|
[project.urls]
|
|
@@ -181,6 +181,17 @@ def rewrite_request_for_sference(
|
|
|
181
181
|
return new_url, headers_to_set, headers_to_remove
|
|
182
182
|
|
|
183
183
|
|
|
184
|
+
# Claude-family display names for the models we route. The picker shows this
|
|
185
|
+
# instead of the raw catalog id so the entries read like first-party Claude
|
|
186
|
+
# models. Keyed by exact catalog id; unknown ids get the generic fallback.
|
|
187
|
+
MODEL_DESCRIPTIONS: dict[str, str] = {
|
|
188
|
+
"moonshotai/Kimi-K3": "Fable",
|
|
189
|
+
"zai-org/GLM-5.2": "Opus",
|
|
190
|
+
"deepseek-ai/DeepSeek-V4-Flash": "Sonnet",
|
|
191
|
+
}
|
|
192
|
+
DEFAULT_MODEL_DESCRIPTION = "Sference (routed via local proxy)"
|
|
193
|
+
|
|
194
|
+
|
|
184
195
|
def inject_models_into_bootstrap(body: Any, sference_models: set[str]) -> Any:
|
|
185
196
|
"""Append Sference models to a bootstrap response's ``additional_model_options``.
|
|
186
197
|
|
|
@@ -202,7 +213,7 @@ def inject_models_into_bootstrap(body: Any, sference_models: set[str]) -> Any:
|
|
|
202
213
|
{
|
|
203
214
|
"model": model,
|
|
204
215
|
"name": f"[Sference] {model}",
|
|
205
|
-
"description":
|
|
216
|
+
"description": MODEL_DESCRIPTIONS.get(model, DEFAULT_MODEL_DESCRIPTION),
|
|
206
217
|
"disabled_reason": None,
|
|
207
218
|
}
|
|
208
219
|
)
|
|
@@ -15,7 +15,7 @@ import typer
|
|
|
15
15
|
|
|
16
16
|
from .proxy import fetch_sference_models, launch_claude_via_proxy
|
|
17
17
|
|
|
18
|
-
DEFAULT_LAUNCH_MODEL = "
|
|
18
|
+
DEFAULT_LAUNCH_MODEL = "zai-org/GLM-5.2"
|
|
19
19
|
DEFAULT_API_BASE_URL = "https://api.sference.com"
|
|
20
20
|
|
|
21
21
|
|
|
@@ -215,23 +215,27 @@ def _opencode_config_path() -> Path:
|
|
|
215
215
|
return Path.home() / ".config" / "opencode" / "opencode.json"
|
|
216
216
|
|
|
217
217
|
|
|
218
|
-
def _write_opencode_config(*, base_url: str, model: str) -> Path:
|
|
218
|
+
def _write_opencode_config(*, base_url: str, model: str, models: set[str]) -> Path:
|
|
219
219
|
"""Merge a ``sference`` OpenAI-compatible provider into the opencode config.
|
|
220
220
|
|
|
221
221
|
Reads ``~/.config/opencode/opencode.json`` (creating it if absent), sets
|
|
222
222
|
``provider.sference`` to a block pointing at the Sference OpenAI-compatible
|
|
223
223
|
endpoint (``/v1/chat/completions``), and writes it back. The user's existing
|
|
224
|
-
config — other providers, keybinds, theme
|
|
225
|
-
|
|
224
|
+
config — other providers, keybinds, theme — is preserved; only
|
|
225
|
+
``provider.sference`` is (over)written. If the existing file is not
|
|
226
226
|
valid JSON, we refuse to clobber it rather than silently destroying the
|
|
227
227
|
user's opencode config.
|
|
228
228
|
|
|
229
|
+
All models in ``models`` are written to the provider's ``models`` block so
|
|
230
|
+
they appear in opencode's model picker. ``model`` is the default — set as
|
|
231
|
+
the top-level ``model`` key so opencode uses Sference by default on startup.
|
|
232
|
+
|
|
229
233
|
The API key is referenced as ``{env:SFERENCE_API_KEY}`` so no secret is
|
|
230
234
|
stored on disk; ``launch_opencode`` injects the resolved key into the
|
|
231
235
|
opencode process env at exec time. opencode splits ``provider/model`` on
|
|
232
|
-
the first slash, so a model id like ``
|
|
233
|
-
as ``--model sference/
|
|
234
|
-
``sference`` + model id ``
|
|
236
|
+
the first slash, so a model id like ``zai-org/GLM-5.2`` is passed
|
|
237
|
+
as ``--model sference/zai-org/GLM-5.2`` and resolves to provider
|
|
238
|
+
``sference`` + model id ``zai-org/GLM-5.2``.
|
|
235
239
|
"""
|
|
236
240
|
path = _opencode_config_path()
|
|
237
241
|
if path.exists():
|
|
@@ -250,6 +254,7 @@ def _write_opencode_config(*, base_url: str, model: str) -> Path:
|
|
|
250
254
|
data = {}
|
|
251
255
|
|
|
252
256
|
data.setdefault("provider", {})
|
|
257
|
+
all_models = models | {model}
|
|
253
258
|
data["provider"]["sference"] = {
|
|
254
259
|
"npm": "@ai-sdk/openai-compatible",
|
|
255
260
|
"name": "Sference",
|
|
@@ -258,9 +263,13 @@ def _write_opencode_config(*, base_url: str, model: str) -> Path:
|
|
|
258
263
|
"apiKey": "{env:SFERENCE_API_KEY}",
|
|
259
264
|
},
|
|
260
265
|
"models": {
|
|
261
|
-
|
|
266
|
+
m: {"name": m}
|
|
267
|
+
for m in sorted(all_models)
|
|
262
268
|
},
|
|
263
269
|
}
|
|
270
|
+
# Set Sference as the default model so opencode uses it on startup without
|
|
271
|
+
# the user having to select it in the picker.
|
|
272
|
+
data["model"] = f"sference/{model}"
|
|
264
273
|
|
|
265
274
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
266
275
|
with path.open("w", encoding="utf-8") as fh:
|
|
@@ -291,7 +300,17 @@ def launch_opencode(
|
|
|
291
300
|
)
|
|
292
301
|
raise typer.Exit(code=1)
|
|
293
302
|
|
|
294
|
-
|
|
303
|
+
# Fetch all available text-generation models from /v1/models so they all
|
|
304
|
+
# appear in opencode's model picker, not just the default. Falls back to
|
|
305
|
+
# just the chosen model if the fetch fails (e.g. offline) so the launch
|
|
306
|
+
# still works.
|
|
307
|
+
try:
|
|
308
|
+
fetched = fetch_sference_models(base_url, api_key)
|
|
309
|
+
except Exception:
|
|
310
|
+
fetched = set()
|
|
311
|
+
models = fetched if fetched else set()
|
|
312
|
+
|
|
313
|
+
config_path = _write_opencode_config(base_url=base_url, model=model, models=models)
|
|
295
314
|
env = os.environ.copy()
|
|
296
315
|
# The config references {env:SFERENCE_API_KEY}; inject the resolved key so
|
|
297
316
|
# no secret is persisted to disk.
|
|
@@ -302,6 +321,7 @@ def launch_opencode(
|
|
|
302
321
|
typer.echo(f"Wrote provider 'sference' to {config_path}")
|
|
303
322
|
typer.echo(f"baseURL: {base_url}")
|
|
304
323
|
typer.echo(f"model: {model}")
|
|
324
|
+
typer.echo(f"models in picker: {len(models) + 1}")
|
|
305
325
|
typer.echo("apiKey: {env:SFERENCE_API_KEY} (injected at launch)")
|
|
306
326
|
typer.echo(f"command: {' '.join(cmd)}")
|
|
307
327
|
return
|
|
@@ -417,7 +437,6 @@ def register_launch_commands(app: typer.Typer) -> None:
|
|
|
417
437
|
elif model:
|
|
418
438
|
model_set = {model}
|
|
419
439
|
else:
|
|
420
|
-
typer.echo(f"Fetching routable models from {resolved_base}/v1/models ...")
|
|
421
440
|
try:
|
|
422
441
|
model_set = fetch_sference_models(resolved_base, api_key)
|
|
423
442
|
except (urllib.error.URLError, urllib.error.HTTPError, json.JSONDecodeError, KeyError) as e:
|
|
@@ -228,7 +228,6 @@ def launch_claude_via_proxy(
|
|
|
228
228
|
signal.signal(sig, lambda *_a: (_cleanup(), sys.exit(130))[1])
|
|
229
229
|
|
|
230
230
|
try:
|
|
231
|
-
typer.echo(f"Starting mitmproxy on 127.0.0.1:{port} (log: {log_path})...")
|
|
232
231
|
if not _wait_for_mitmproxy(mitm_proc, port, log_path):
|
|
233
232
|
raise typer.Exit(code=1)
|
|
234
233
|
|
|
@@ -240,9 +239,8 @@ def launch_claude_via_proxy(
|
|
|
240
239
|
)
|
|
241
240
|
raise typer.Exit(code=1)
|
|
242
241
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
typer.echo(f" NODE_EXTRA_CA_CERTS={MITM_CA_CERT}")
|
|
242
|
+
# Quiet by default: one line. The full config (ports, proxy env, models)
|
|
243
|
+
# is available via --dry-run; the proxy detail is in the log file.
|
|
246
244
|
typer.echo("Launching Claude Code...")
|
|
247
245
|
|
|
248
246
|
claude_env = os.environ.copy()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|