Files
ai-setup/home-configs/claude/hooks/logout-account-hook.sh
Виталий Никитенко 083a614940 feat(eltex): add ai-eltex launcher for corporate LLM proxy
ai-eltex runs Claude Code through the Eltex LiteLLM proxy
(http://llm.eltex.loc:4000, team GLM subscription). The personal key
from admins is checked via /v1/models and stored in
~/.config/ai-setup/eltex_key; the model is taken from the key's
allowed list (ELTEX_MODEL / ELTEX_BASE_URL override). The proxy
ignores effort/thinking, so no effort forcing. /logout-eltex and
/logout in ai-eltex drop the key; setup.sh status shows it.

ru-bypass: hosts block now has an end marker and only that block is
rewritten, manual entries outside it survive; llm.eltex.loc/llm2 added
since the VPN DNS does not resolve it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 12:21:02 +07:00

66 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Copyright (c) 2026 Виталий Никитенко. MIT License.
# UserPromptSubmit hook: перехватывает /logout, /logout-glm, /logout-eltex, /logout-deepseek, /logout-kimi.
# Удаляет сохранённый API-ключ провайдера, чтобы при следующем запуске лаунчер
# запросил новый.
# /logout-glm | /logout-eltex | /logout-deepseek | /logout-kimi — явно указанный провайдер.
# /logout (без суффикса) — провайдер по AI_LAUNCHER (glm/eltex/deepseek/kimi).
# Для ai-claude и прочих лаунчеров /logout отступает (exit 0) — пусть работает
# нативный oauth-logout. exit 2 после удаления: LLM не нужна, и нативная
# /logout не пытается сделать бессмысленный oauth-logout для api-key провайдеров.
input=$(cat)
prompt=$(echo "$input" | jq -r '.user_prompt // .prompt // empty' 2>/dev/null)
normalized=$(echo "$prompt" | sed 's|^[[:space:]]*/||; s|[[:space:]]*$||')
cmd=$(echo "$normalized" | awk '{print $1}')
target=""
case "$cmd" in
logout-glm) target=glm ;;
logout-eltex) target=eltex ;;
logout-deepseek) target=deepseek ;;
logout-kimi) target=kimi ;;
logout)
case "${AI_LAUNCHER:-claude}" in
glm|eltex|deepseek|kimi) target="$AI_LAUNCHER" ;;
*) exit 0 ;;
esac
;;
*) exit 0 ;;
esac
CFG="$HOME/.config/ai-setup"
case "$target" in
glm)
rm -f "$CFG/glm_key"
echo "✓ GLM ключ удалён. Перезапусти ai-glm, чтобы ввести новый." >&2
;;
eltex)
rm -f "$CFG/eltex_key"
echo "✓ Eltex ключ удалён. Перезапусти ai-eltex, чтобы ввести новый." >&2
;;
deepseek)
rm -f "$CFG/deepseek_key"
echo "✓ DeepSeek ключ удалён. Перезапусти ai-deepseek, чтобы ввести новый." >&2
;;
kimi)
KEYS_DIR="$CFG/kimi_keys"
current=$(cat "$KEYS_DIR/current" 2>/dev/null || true)
if [ -n "$current" ]; then
rm -f "$KEYS_DIR/${current}.key" "$KEYS_DIR/${current}.meta"
fi
# Пересчёт current: переключаемся на первый оставшийся ключ либо сбрасываем.
mapfile -t keys < <(ls "$KEYS_DIR"/*.key 2>/dev/null | xargs -I{} basename {} .key | sort)
if [ "${#keys[@]}" -gt 0 ]; then
echo "${keys[0]}" > "$KEYS_DIR/current"
echo "✓ Kimi ключ (${current:-нет}) удалён. Активен: ${keys[0]}. Перезапусти ai-kimi." >&2
else
rm -f "$KEYS_DIR/current"
echo "✓ Kimi ключ (${current:-нет}) удалён. Других ключей нет. Перезапусти ai-kimi." >&2
fi
;;
esac
exit 2