diff --git a/scripts/podx-tools.sh b/scripts/podx-tools.sh index 798b155..680339a 100755 --- a/scripts/podx-tools.sh +++ b/scripts/podx-tools.sh @@ -129,7 +129,7 @@ _kb_id_by_name() { local kb_name="$1" local json; json="$(_owui_get_kb_list)" # Robust KB name resolver: Unicode/space-insensitive, prefers most recently updated - python3 - "$kb_name" <<'PY' || true + printf '%s' "$json" | python3 - "$kb_name" <<'PY' || true import sys, json, unicodedata as ud def norm(s: str) -> str: @@ -378,6 +378,23 @@ else: print('', end='') PY <<<"$json")" + # Fallback: if the list contains exactly one KB, use its id + if [ -z "$id" ]; then + id="$(printf '%s' "$json" | python3 - <<'PY' || true +import sys, json +raw=sys.stdin.read().strip() +try: + d=json.loads(raw) +except Exception: + print('', end=''); raise SystemExit(0) +items = d.get('data') if isinstance(d, dict) and isinstance(d.get('data'), list) else (d if isinstance(d, list) else []) +if isinstance(items, list) and len(items)==1: + print(items[0].get('id',''), end='') +else: + print('', end='') +PY +)" + fi if [ -n "$id" ]; then echo "[owui] resolved id for \"$name\": $id" else