owui-cli 0.5.0__tar.gz → 0.5.1__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: owui-cli
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: Admin CLI for Open WebUI instances
5
5
  Project-URL: Homepage, https://github.com/rndmcnlly/owui-cli
6
6
  Project-URL: Repository, https://github.com/rndmcnlly/owui-cli
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "owui-cli"
3
- version = "0.5.0"
3
+ version = "0.5.1"
4
4
  description = "Admin CLI for Open WebUI instances"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -0,0 +1 @@
1
+ __version__ = "0.5.1"
@@ -444,6 +444,23 @@ def functions_valves_user_set_field(url, token, item_id, key, value):_valves_set
444
444
  def functions_valves_user_unset_field(url, token, item_id, key): _valves_unset_field(url, token, "functions", item_id, key, "/user")
445
445
 
446
446
 
447
+ # ── functions toggle (activate / deactivate, and global) ─────────────
448
+
449
+ def functions_toggle(url, token, item_id):
450
+ """Toggle a function's is_active flag."""
451
+ with httpx.Client(timeout=TIMEOUT) as c:
452
+ r = _post(c, url, f"/api/v1/functions/id/{item_id}/toggle", token)
453
+ f = r.json()
454
+ out(f"{item_id} {'active' if f.get('is_active') else 'inactive'}")
455
+
456
+ def functions_toggle_global(url, token, item_id):
457
+ """Toggle a function's is_global flag (applies to all models)."""
458
+ with httpx.Client(timeout=TIMEOUT) as c:
459
+ r = _post(c, url, f"/api/v1/functions/id/{item_id}/toggle/global", token)
460
+ f = r.json()
461
+ out(f"{item_id} {'global' if f.get('is_global') else 'not global'}")
462
+
463
+
447
464
  class SkillsResource(Resource):
448
465
  """Skills use frontmatter and have grant/revoke commands."""
449
466
 
@@ -573,17 +590,16 @@ def models_show(url, token, model_id):
573
590
  if JSON_OUTPUT:
574
591
  out(m)
575
592
  return
576
- info = m.get("info") or {}
577
- meta = info.get("meta") or {}
578
- params = info.get("params") or {}
593
+ meta = m.get("meta") or {}
594
+ params = m.get("params") or {}
579
595
  pairs = [("id", m.get("id","")), ("name", m.get("name","")),
580
- ("base", info.get("base_model_id","(none)")),
581
- ("active", str(info.get("is_active","?"))),
596
+ ("base", m.get("base_model_id","(none)") or "(none)"),
597
+ ("active", str(m.get("is_active","?"))),
582
598
  ("tools", ", ".join(meta.get("toolIds") or []) or "(none)"),
583
- ("filters", ", ".join(params.get("filter_ids") or []) or "(none)"),
599
+ ("filters", ", ".join(meta.get("filterIds") or []) or "(none)"),
584
600
  ("knowledge", ", ".join(k.get("name","?") for k in (meta.get("knowledge") or [])) or "(none)"),
585
- ("system", f"{len(params.get('system',''))} chars"),
586
- ("grants", str(len(info.get("access_grants") or [])))]
601
+ ("system", f"{len(params.get('system') or '')} chars"),
602
+ ("grants", str(len(m.get("access_grants") or [])))]
587
603
  out_kv(pairs)
588
604
 
589
605
  def models_create(url, token, json_path):
@@ -607,23 +623,38 @@ def models_delete(url, token, model_id):
607
623
  out(f"deleted {model_id}")
608
624
 
609
625
  def _models_fetch(c, url, token, model_id):
610
- """Fetch a model by ID, returning the parsed JSON."""
626
+ """Fetch a model by ID, returning the parsed JSON (flat ModelModel shape)."""
611
627
  r = _get(c, url, f"/api/v1/models/model?id={model_id}", token)
612
628
  return r.json()
613
629
 
630
+ def _models_form(model):
631
+ """Build a ModelForm update payload from a fetched flat model.
632
+
633
+ OWUI's Model schema is flat: top-level `meta`, `params`, `base_model_id`,
634
+ `name`, `is_active`, `access_grants`. The /model/update endpoint accepts a
635
+ ModelForm of the same shape (extra keys ignored). Rebuilding explicitly
636
+ avoids leaking response-only fields (user, write_access, timestamps) and
637
+ ensures `meta`/`params` round-trip intact.
638
+ """
639
+ return {
640
+ "id": model.get("id"),
641
+ "base_model_id": model.get("base_model_id"),
642
+ "name": model.get("name", model.get("id", "")),
643
+ "meta": model.get("meta") or {},
644
+ "params": model.get("params") or {},
645
+ "access_grants": model.get("access_grants") or [],
646
+ "is_active": model.get("is_active", True),
647
+ }
648
+
614
649
  def models_set_tools(url, token, model_id, *tool_ids):
615
650
  """Set the tool bindings for a workspace model (pass no IDs to clear)."""
616
651
  with httpx.Client(timeout=TIMEOUT) as c:
617
652
  model = _models_fetch(c, url, token, model_id)
618
- info = model.get("info") or {}
619
- meta = info.setdefault("meta", {})
620
- params = info.setdefault("params", {})
653
+ form = _models_form(model)
621
654
  ids = list(tool_ids)
622
- meta["toolIds"] = ids
623
- # keep params.tool_ids in sync (used by some OWUI versions)
624
- params["tool_ids"] = ids
625
- model["info"] = info
626
- r = _post(c, url, "/api/v1/models/model/update", token, model)
655
+ # OWUI binds per-model tools via meta.toolIds.
656
+ form["meta"]["toolIds"] = ids
657
+ r = _post(c, url, "/api/v1/models/model/update", token, form)
627
658
  label = ", ".join(ids) if ids else "(none)"
628
659
  out(f"tools for {model_id}: {label}")
629
660
 
@@ -631,12 +662,12 @@ def models_set_filters(url, token, model_id, *filter_ids):
631
662
  """Set the filter bindings for a workspace model (pass no IDs to clear)."""
632
663
  with httpx.Client(timeout=TIMEOUT) as c:
633
664
  model = _models_fetch(c, url, token, model_id)
634
- info = model.get("info") or {}
635
- params = info.setdefault("params", {})
665
+ form = _models_form(model)
636
666
  ids = list(filter_ids)
637
- params["filter_ids"] = ids
638
- model["info"] = info
639
- r = _post(c, url, "/api/v1/models/model/update", token, model)
667
+ # OWUI reads per-model filters from meta.filterIds
668
+ # (see backend/open_webui/utils/filter.py).
669
+ form["meta"]["filterIds"] = ids
670
+ r = _post(c, url, "/api/v1/models/model/update", token, form)
640
671
  label = ", ".join(ids) if ids else "(none)"
641
672
  out(f"filters for {model_id}: {label}")
642
673
 
@@ -1156,6 +1187,8 @@ COMMANDS.update({
1156
1187
  ("functions", "valves-user-set"): (functions_valves_user_set, "<id> <valves.json>", (2, 2)),
1157
1188
  ("functions", "valves-user-set-field"): (functions_valves_user_set_field, "<id> <key> <value>", (3, 3)),
1158
1189
  ("functions", "valves-user-unset-field"):(functions_valves_user_unset_field, "<id> <key>", (2, 2)),
1190
+ ("functions", "toggle"): (functions_toggle, "<id>", (1, 1)),
1191
+ ("functions", "toggle-global"): (functions_toggle_global, "<id>", (1, 1)),
1159
1192
  ("models", "list"): (models_list, "", (0, 0)),
1160
1193
  ("models", "show"): (models_show, "<id>", (1, 1)),
1161
1194
  ("models", "create"): (models_create, "<model.json>", (1, 1)),
@@ -1 +0,0 @@
1
- __version__ = "0.5.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes