From c1e68571f8d3bbce664db233cc9827b77daa3395 Mon Sep 17 00:00:00 2001 From: vitaly Date: Sat, 6 Jun 2026 11:14:57 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=BF=D0=BE=D0=BA=D0=B0=D0=B7=D1=8B?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D1=8C=20=D0=B1=D0=B0=D0=BB=D0=B0=D0=BD=D1=81?= =?UTF-8?q?=20DeepSeek=20=D0=BF=D1=80=D0=B8=20=D0=B7=D0=B0=D0=BF=D1=83?= =?UTF-8?q?=D1=81=D0=BA=D0=B5=20=D0=B8=20=D0=B2=20=D1=81=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D1=83=D1=81=D0=BD=D0=BE=D0=B9=20=D1=81=D1=82=D1=80=D0=BE=D0=BA?= =?UTF-8?q?=D0=B5=20Claude=20Code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Функция _deepseek_balance в ai-api-helpers: запрос к GET /user/balance - Вывод баланса при проверке сохранённого и нового ключа в ai-deepseek - Кеширование баланса в ~/.cache/ai-setup/deepseek_balance для статусной строки - statusline-command.sh: если модель содержит deepseek — показывать вместо usage Co-Authored-By: Claude Opus 4.8 --- ai-setup.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/ai-setup.sh b/ai-setup.sh index c949407..2086965 100755 --- a/ai-setup.sh +++ b/ai-setup.sh @@ -787,6 +787,51 @@ _claude_test_openai_api() { _CLAUDE_TEST_BODY=$(echo "$response" | sed '$d') } +# _deepseek_balance: Query DeepSeek balance API and print info +_deepseek_balance() { + local api_key="$1" + local response + response=$(curl -s --max-time 10 "https://api.deepseek.com/user/balance" \ + -H "Authorization: Bearer $api_key" \ + -H "Accept: application/json" \ + 2>/dev/null || echo "") + if [ -z "$response" ]; then + echo -e " \033[0;33m[БАЛАНС]\033[0m Не удалось получить баланс (сеть?)" + return 1 + fi + echo "$response" | python3 -c " +import sys, json, os +try: + d = json.load(sys.stdin) + available = d.get('is_available', False) + infos = d.get('balance_infos', []) + if not infos: + print(' \033[0;33m[БАЛАНС]\033[0m Нет данных о балансе') + sys.exit(0) + first = True + for info in infos: + curr = info.get('currency', '???') + total = info.get('total_balance', '0') + granted = info.get('granted_balance', '0') + topped_up = info.get('topped_up_balance', '0') + status = '✅ доступен' if available else '❌ не активен' + print(f' \033[1;36m💰 Баланс DeepSeek:\033[0m {total} {curr} {status}') + if float(granted) > 0: + print(f' └─ Начислено: {granted} {curr}') + if float(topped_up) > 0: + print(f' └─ Пополнено: {topped_up} {curr}') + # Cache first currency entry for statusline + if first: + cache_dir = os.path.expanduser('~/.cache/ai-setup') + os.makedirs(cache_dir, exist_ok=True) + with open(os.path.join(cache_dir, 'deepseek_balance'), 'w') as f: + f.write(f'{total} {curr}\n') + first = False +except Exception as e: + print(f' ⚠️ Не удалось разобрать баланс: {e}') +" 2>/dev/null || echo -e " \033[0;33m[БАЛАНС]\033[0m Ошибка парсинга ответа" +} + _handle_openai_api_response() { local provider="$1" local code="$2" @@ -1019,6 +1064,7 @@ if [ -n "$api_key" ]; then elif [ $ret -ne 0 ]; then exit 1 fi + _deepseek_balance "$api_key" fi if [ -z "$api_key" ] && [ "$reauth" -eq 1 ]; then @@ -1040,6 +1086,7 @@ if [ -z "$api_key" ]; then echo "$api_key" > "$key_file" chmod 600 "$key_file" echo "Ключ сохранён." + _deepseek_balance "$api_key" if [ $ret -eq 429 ]; then echo -n "Продолжить всё равно? (запросы могут не проходить) [y/N] " read -r _ans; case "${_ans:-N}" in [Yy]*) ;; *) exit 1 ;; esac