sference-cli 0.2.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sference-cli
3
- Version: 0.2.1
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.1
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.1"
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.1",
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": "Sference (routed via local proxy)",
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 = "moonshotai/Kimi-K2.7-Code"
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, default ``model`` — is preserved;
225
- only ``provider.sference`` is (over)written. If the existing file is not
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 ``moonshotai/Kimi-K2.7-Code`` is passed
233
- as ``--model sference/moonshotai/Kimi-K2.7-Code`` and resolves to provider
234
- ``sference`` + model id ``moonshotai/Kimi-K2.7-Code``.
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
- model: {"name": model},
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
- config_path = _write_opencode_config(base_url=base_url, model=model)
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
File without changes
File without changes
File without changes