vyra-code 0.2.43__tar.gz → 0.2.46__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.
- {vyra_code-0.2.43 → vyra_code-0.2.46}/PKG-INFO +1 -1
- {vyra_code-0.2.43 → vyra_code-0.2.46}/pyproject.toml +1 -1
- {vyra_code-0.2.43 → vyra_code-0.2.46}/vyra.py +136 -21
- {vyra_code-0.2.43 → vyra_code-0.2.46}/vyra_code.egg-info/PKG-INFO +1 -1
- {vyra_code-0.2.43 → vyra_code-0.2.46}/README.md +0 -0
- {vyra_code-0.2.43 → vyra_code-0.2.46}/setup.cfg +0 -0
- {vyra_code-0.2.43 → vyra_code-0.2.46}/vyra_code.egg-info/SOURCES.txt +0 -0
- {vyra_code-0.2.43 → vyra_code-0.2.46}/vyra_code.egg-info/dependency_links.txt +0 -0
- {vyra_code-0.2.43 → vyra_code-0.2.46}/vyra_code.egg-info/entry_points.txt +0 -0
- {vyra_code-0.2.43 → vyra_code-0.2.46}/vyra_code.egg-info/requires.txt +0 -0
- {vyra_code-0.2.43 → vyra_code-0.2.46}/vyra_code.egg-info/top_level.txt +0 -0
- {vyra_code-0.2.43 → vyra_code-0.2.46}/vyra_i18n.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vyra-code
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.46
|
|
4
4
|
Summary: Vyra Code: assistente de IA no terminal (Termux, Linux, macOS e Windows) (chat em streaming, tarefas, memória, projetos e terminal remoto)
|
|
5
5
|
License: Proprietary
|
|
6
6
|
Keywords: termux,ai,assistant,cli,android,llm
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "vyra-code"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.46"
|
|
8
8
|
description = "Vyra Code: assistente de IA no terminal (Termux, Linux, macOS e Windows) (chat em streaming, tarefas, memória, projetos e terminal remoto)"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -74,9 +74,12 @@ def default_home(env: dict | None = None, win: bool | None = None) -> str:
|
|
|
74
74
|
return new
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
VERSION = "0.2.
|
|
77
|
+
VERSION = "0.2.46"
|
|
78
78
|
DEFAULT_BACKEND = "https://aihub-api.vyntrica.com"
|
|
79
79
|
CHANGELOG = {
|
|
80
|
+
"0.2.46": ["corrige o spinner que virava spam no Termux: a barra de status embaixo da resposta (0.2.44) desenhava uma linha com \\n abaixo do cursor e, no terminal curto do celular, cada tick rolava a tela e congelava a linha — centenas de \"Consultando modelos…\" empilhadas. Agora os tokens ao vivo aparecem no próprio spinner (uma linha in-place que nunca passa da largura, então não quebra nem rola); a resposta continua saindo normalmente e a caixa de digitar continua embaixo"],
|
|
81
|
+
"0.2.45": ["corrige o vyra-browse com 400 invalid url: a IA às vezes escreve a URL entre < > (autolink do Markdown) e o Worker só aceita a URL nua; o cliente agora tira os colchetes (e extrai a URL se vier dentro de um link) antes de mandar"],
|
|
82
|
+
"0.2.44": ["update sem cache: a leitura do PyPI fura o cache do CDN (cache-buster + no-cache) e, se aparecer versão mais nova no meio da instalação, uma só execução converge para ela — não precisa rodar o comando duas vezes", "tokens ao vivo: a barra embaixo da resposta mostra a contagem de tokens crescendo enquanto a IA responde (estimativa, com ~; o valor exato continua no rodapé depois)", "caixa de mensagem permanente: a barra fica sempre embaixo e a resposta sai acima dela, inclusive enquanto a IA responde; o editor redesenha do zero quando o terminal muda de tamanho (teclado abrindo/fechando no Termux), sem região de rolagem fixa"],
|
|
80
83
|
"0.2.43": ["a busca na web e o navegador ficam sempre ligados para a IA (o comando /web on|off foi removido); as fontes continuam aparecendo na resposta"],
|
|
81
84
|
"0.2.42": ["caixa de entrada fixa removida: quebrava de verdade no Termux sempre que o teclado abria/fechava (o terminal muda de tamanho e a região fixa saía do lugar, com trechos da conversa sumindo); volta ao campo de digitação simples de antes da 0.2.40"],
|
|
82
85
|
"0.2.41": ["cores da interface agora seguem a paleta da logo (prata e grafite-azulado), em vez do laranja do AI Hub Code; sucesso/aviso/falha continuam verde/amarelo/vermelho"],
|
|
@@ -985,8 +988,28 @@ SANDBOX_COOLDOWN = 300.0
|
|
|
985
988
|
SANDBOX_INFRA = ("504", "503", "502", "sandbox_timeout", "executor_offline")
|
|
986
989
|
|
|
987
990
|
|
|
991
|
+
def _clean_browse_url(text: str) -> str:
|
|
992
|
+
"""Limpa a URL do bloco aihub-browse antes de mandar ao servidor.
|
|
993
|
+
|
|
994
|
+
A IA às vezes escreve a URL no formato de autolink do Markdown (`<https://…>`) ou
|
|
995
|
+
dentro de um link (`[texto](https://…)`); o Worker só aceita a URL nua e devolve
|
|
996
|
+
400 "invalid url" com os colchetes. Tira os espaços, os `< >` e, se sobrar texto
|
|
997
|
+
em volta, extrai a primeira URL.
|
|
998
|
+
"""
|
|
999
|
+
t = (text or "").strip()
|
|
1000
|
+
if t.startswith("<") and t.endswith(">") and len(t) > 2:
|
|
1001
|
+
t = t[1:-1].strip()
|
|
1002
|
+
if not re.fullmatch(r"https?://\S+", t, re.I):
|
|
1003
|
+
m = re.search(r"https?://[^\s<>\]\)]+", t, re.I)
|
|
1004
|
+
if m:
|
|
1005
|
+
t = m.group(0).rstrip(".,;")
|
|
1006
|
+
return t
|
|
1007
|
+
|
|
1008
|
+
|
|
988
1009
|
def run_tool(c: "Client", kind: str, text: str, now: Callable[[], float] = time.time) -> tuple[int, str]:
|
|
989
1010
|
"""Executa a ferramenta no sandbox do usuário (servidor). Nunca roda nada neste aparelho."""
|
|
1011
|
+
if kind == "browse":
|
|
1012
|
+
text = _clean_browse_url(text)
|
|
990
1013
|
if now() < SANDBOX_DOWN["until"]:
|
|
991
1014
|
return 125, "ferramenta indisponível: o sandbox falhou há pouco; não tente de novo agora. Responda com o que sabe ou pesquise na web (já está sempre ligada)."
|
|
992
1015
|
try:
|
|
@@ -1874,8 +1897,17 @@ PYPI_DIST = "vyra-code"
|
|
|
1874
1897
|
|
|
1875
1898
|
|
|
1876
1899
|
def pypi_latest(opener: Callable[..., Any] = urllib.request.urlopen) -> str | None:
|
|
1900
|
+
"""Versão mais recente no PyPI, sem cache.
|
|
1901
|
+
|
|
1902
|
+
O JSON do PyPI passa por CDN e pode vir desatualizado: sem o cache-buster a
|
|
1903
|
+
primeira execução do `vyra update` via a versão velha (e só atualizava de
|
|
1904
|
+
verdade na segunda execução). O `?_=<epoch>` muda a chave do cache e os
|
|
1905
|
+
cabeçalhos pedem para não usar cópia guardada.
|
|
1906
|
+
"""
|
|
1907
|
+
url = "https://pypi.org/pypi/" + PYPI_DIST + "/json?_=" + str(int(time.time()))
|
|
1908
|
+
req = urllib.request.Request(url, headers={"Cache-Control": "no-cache", "Pragma": "no-cache"})
|
|
1877
1909
|
try:
|
|
1878
|
-
with opener(
|
|
1910
|
+
with opener(req, timeout=10) as r:
|
|
1879
1911
|
v = json.loads(r.read().decode()).get("info", {}).get("version", "")
|
|
1880
1912
|
except (OSError, ValueError, urllib.error.URLError):
|
|
1881
1913
|
return None
|
|
@@ -1951,27 +1983,47 @@ def cmd_update(c: Client, a: argparse.Namespace, out: Callable[[str], None], tty
|
|
|
1951
1983
|
out("")
|
|
1952
1984
|
out(f" Versão instalada: {VERSION}" + (f" · disponível: {paint(latest, BOLD, color=color)}" if latest else " · não consegui consultar o PyPI"))
|
|
1953
1985
|
return 0 if latest else 1
|
|
1954
|
-
|
|
1986
|
+
verified: list[str] = [] # versão instalada confirmada por install(), sem nova leitura
|
|
1987
|
+
|
|
1988
|
+
def install(target: str | None) -> tuple[bool, str]:
|
|
1955
1989
|
"""O índice do PyPI pode demorar um pouco para enxergar uma versão recém-publicada: tenta de novo."""
|
|
1956
1990
|
res: tuple[bool, str] = (False, "")
|
|
1957
1991
|
for i in range(4):
|
|
1958
|
-
res = pip_upgrade(
|
|
1992
|
+
res = pip_upgrade(target)
|
|
1959
1993
|
info = installed_info() if res[0] else None
|
|
1960
|
-
if res[0] and (not
|
|
1994
|
+
if res[0] and (not target or (info and vtuple(info["v"]) >= vtuple(target))):
|
|
1995
|
+
if info:
|
|
1996
|
+
verified.append(info["v"])
|
|
1961
1997
|
return True, ""
|
|
1962
|
-
if res[0] and
|
|
1998
|
+
if res[0] and target:
|
|
1963
1999
|
res = (False, "O PyPI ainda não liberou a versão nova. Tente de novo em 1 minuto.")
|
|
1964
2000
|
if i < 3:
|
|
1965
2001
|
sleep(8)
|
|
1966
2002
|
return res
|
|
1967
2003
|
|
|
1968
|
-
ok, res, _ = run_step(f"Instalando {latest}" if latest else "Instalando a versão mais recente", install, out, tty, color, lambda r: bool(r[0]))
|
|
2004
|
+
ok, res, _ = run_step(f"Instalando {latest}" if latest else "Instalando a versão mais recente", lambda: install(latest), out, tty, color, lambda r: bool(r[0]))
|
|
1969
2005
|
if not ok:
|
|
1970
2006
|
out("")
|
|
1971
2007
|
for ln in (res[1] or "erro desconhecido").splitlines():
|
|
1972
2008
|
out(" " + paint(ln, DIM, color=color))
|
|
1973
2009
|
out(" Tente manualmente: pip install -U " + PYPI_DIST)
|
|
1974
2010
|
return 1
|
|
2011
|
+
# Sem cache, uma só execução converge para a versão mais recente: a primeira
|
|
2012
|
+
# leitura do PyPI pode ter vindo de um espelho/CDN desatualizado, então confere
|
|
2013
|
+
# de novo (sem cache) e, se apareceu versão mais nova nesse meio-tempo, instala
|
|
2014
|
+
# também — em vez de o dono ter de rodar o comando uma segunda vez.
|
|
2015
|
+
for _ in range(2):
|
|
2016
|
+
fresh = pypi_latest()
|
|
2017
|
+
cur = verified[-1] if verified else ""
|
|
2018
|
+
if not fresh or not cur or vtuple(fresh) <= vtuple(cur):
|
|
2019
|
+
break
|
|
2020
|
+
ok, res, _ = run_step(f"Instalando {fresh}", lambda: install(fresh), out, tty, color, lambda r: bool(r[0]))
|
|
2021
|
+
if not ok:
|
|
2022
|
+
out("")
|
|
2023
|
+
for ln in (res[1] or "erro desconhecido").splitlines():
|
|
2024
|
+
out(" " + paint(ln, DIM, color=color))
|
|
2025
|
+
out(" Tente manualmente: pip install -U " + PYPI_DIST)
|
|
2026
|
+
return 1
|
|
1975
2027
|
info = installed_info()
|
|
1976
2028
|
new_v = (info or {}).get("v") or latest or "?"
|
|
1977
2029
|
out("")
|
|
@@ -2326,20 +2378,24 @@ class LivePanel:
|
|
|
2326
2378
|
|
|
2327
2379
|
Fica abaixo do cursor e é redesenhado a cada ~80 ms; o texto da resposta continua saindo acima dele.
|
|
2328
2380
|
`think` = anel prateado girando (respondendo/pesquisando). `run` = arco-íris girando (executando comandos).
|
|
2381
|
+
`compact` = só uma linha de status (sem o avatar grande): é a barra ao vivo do chat normal,
|
|
2382
|
+
com o verbo, o tempo e a contagem de tokens (ao vivo, via `tok_fn`).
|
|
2329
2383
|
"""
|
|
2330
2384
|
|
|
2331
2385
|
HEIGHT = 7
|
|
2332
2386
|
|
|
2333
2387
|
def __init__(self, enabled: bool, color: bool = True, tc: bool | None = None, col_fn: Callable[[], int] = lambda: 0,
|
|
2334
|
-
write: Callable[[str], Any] | None = None
|
|
2388
|
+
write: Callable[[str], Any] | None = None, compact: bool = False,
|
|
2389
|
+
tok_fn: Callable[[], str] | None = None):
|
|
2335
2390
|
self.enabled, self.color, self.tc, self.col_fn = enabled, color, tc, col_fn
|
|
2336
2391
|
self.write = write or (lambda s: (sys.stdout.write(s), sys.stdout.flush()))
|
|
2337
2392
|
self.lock = threading.RLock()
|
|
2338
2393
|
self.mode = "think"
|
|
2394
|
+
self.compact, self.tok_fn = compact, tok_fn
|
|
2339
2395
|
self._stop, self._t, self._t0, self._i = threading.Event(), None, 0.0, 0
|
|
2340
2396
|
|
|
2341
2397
|
@staticmethod
|
|
2342
|
-
def status_lines(mode: str, i: int, elapsed: float, color: bool = True) -> list[str]:
|
|
2398
|
+
def status_lines(mode: str, i: int, elapsed: float, color: bool = True, tok: str = "") -> list[str]:
|
|
2343
2399
|
verbs = RUN_VERBS if mode == "run" else VERBS
|
|
2344
2400
|
label = verbs[int(elapsed // 3) % len(verbs)] + "…"
|
|
2345
2401
|
star = STARS[i % len(STARS)]
|
|
@@ -2350,9 +2406,15 @@ class LivePanel:
|
|
|
2350
2406
|
hot = (i // 2) % (len(label) + 6)
|
|
2351
2407
|
text = "".join(paint(ch, BOLD, color=color) if abs(j - hot) <= 1 else paint(ch, ACCENT_SOFT, color=color) for j, ch in enumerate(label))
|
|
2352
2408
|
head = paint(star, ACCENT, color=color)
|
|
2353
|
-
|
|
2409
|
+
first = f"{head} {text}"
|
|
2410
|
+
if tok:
|
|
2411
|
+
first += " " + paint("· " + tok, DIM, color=color)
|
|
2412
|
+
return [first, paint(t("spin_hint", s=int(elapsed)), DIM, color=color)]
|
|
2354
2413
|
|
|
2355
2414
|
def draw_string(self, i: int, elapsed: float, col: int) -> str:
|
|
2415
|
+
if self.compact:
|
|
2416
|
+
st = self.status_lines(self.mode, i, elapsed, self.color, self.tok_fn() if self.tok_fn else "")
|
|
2417
|
+
return "\n\r " + st[0] + " " + st[1] + "\x1b[K" + f"\x1b[1A\x1b[{col + 1}G"
|
|
2356
2418
|
av = render_mini(self.mode, (i * 0.045) % 1.0, self.color, self.tc)
|
|
2357
2419
|
st = self.status_lines(self.mode, i, elapsed, self.color)
|
|
2358
2420
|
w = len(MINI_BASE[0])
|
|
@@ -3120,8 +3182,15 @@ HISTORY: list[str] = []
|
|
|
3120
3182
|
|
|
3121
3183
|
|
|
3122
3184
|
def read_menu(prompt: str, left: str, right: str, width: int, color: bool = True) -> str:
|
|
3123
|
-
"""Leitura com menu de comandos. Requer terminal real (termios).
|
|
3185
|
+
"""Leitura com menu de comandos. Requer terminal real (termios).
|
|
3186
|
+
|
|
3187
|
+
No Termux o terminal muda de tamanho quando o teclado abre/fecha: um SIGWINCH
|
|
3188
|
+
marca o redimensionamento e o editor redesenha do zero com a largura nova, em
|
|
3189
|
+
vez de continuar com a contagem de linhas antiga (que deixava a conversa
|
|
3190
|
+
desalinhada e sumindo). Sem região de rolagem fixa: só movimentos relativos.
|
|
3191
|
+
"""
|
|
3124
3192
|
import codecs
|
|
3193
|
+
import signal
|
|
3125
3194
|
import termios
|
|
3126
3195
|
import tty as _tty
|
|
3127
3196
|
fd = sys.stdin.fileno()
|
|
@@ -3130,6 +3199,12 @@ def read_menu(prompt: str, left: str, right: str, width: int, color: bool = True
|
|
|
3130
3199
|
ed = LineEditor(HISTORY)
|
|
3131
3200
|
rule = paint("─" * width, DIM, color=color)
|
|
3132
3201
|
reserve = LineEditor.MENU_ROWS + 3
|
|
3202
|
+
resized: list[bool] = [False]
|
|
3203
|
+
old_winch = None
|
|
3204
|
+
try:
|
|
3205
|
+
old_winch = signal.signal(signal.SIGWINCH, lambda *_: resized.__setitem__(0, True))
|
|
3206
|
+
except (ValueError, OSError, AttributeError):
|
|
3207
|
+
old_winch = None
|
|
3133
3208
|
sys.stdout.write("\n" * reserve + "\x1b[%dA" % reserve + rule + "\n")
|
|
3134
3209
|
sys.stdout.flush()
|
|
3135
3210
|
prev = 0
|
|
@@ -3140,6 +3215,13 @@ def read_menu(prompt: str, left: str, right: str, width: int, color: bool = True
|
|
|
3140
3215
|
sys.stdout.flush()
|
|
3141
3216
|
while True:
|
|
3142
3217
|
data = dec.decode(os.read(fd, 1024))
|
|
3218
|
+
if resized[0]:
|
|
3219
|
+
resized[0] = False
|
|
3220
|
+
width = term_width()
|
|
3221
|
+
rule = paint("─" * width, DIM, color=color)
|
|
3222
|
+
sys.stdout.write("\r\x1b[J") # limpa daqui para baixo e redesenha do zero
|
|
3223
|
+
sys.stdout.flush()
|
|
3224
|
+
prev = 0
|
|
3143
3225
|
for key in split_keys(data):
|
|
3144
3226
|
done = ed.feed(key)
|
|
3145
3227
|
if done is not None:
|
|
@@ -3151,6 +3233,11 @@ def read_menu(prompt: str, left: str, right: str, width: int, color: bool = True
|
|
|
3151
3233
|
sys.stdout.flush()
|
|
3152
3234
|
finally:
|
|
3153
3235
|
termios.tcsetattr(fd, termios.TCSADRAIN, saved)
|
|
3236
|
+
if old_winch is not None:
|
|
3237
|
+
try:
|
|
3238
|
+
signal.signal(signal.SIGWINCH, old_winch)
|
|
3239
|
+
except (ValueError, OSError):
|
|
3240
|
+
pass
|
|
3154
3241
|
|
|
3155
3242
|
|
|
3156
3243
|
def render_help(color: bool = True) -> list[str]:
|
|
@@ -3186,8 +3273,8 @@ def mini_logo(i: int, color: bool = True, mode: str = "think", tc: bool | None =
|
|
|
3186
3273
|
class Spinner:
|
|
3187
3274
|
"""✻ Pensando… (3s) com brilho que percorre o texto. Só anima em terminal interativo."""
|
|
3188
3275
|
|
|
3189
|
-
def __init__(self, enabled: bool, color: bool = True):
|
|
3190
|
-
self.enabled, self.color = enabled, color
|
|
3276
|
+
def __init__(self, enabled: bool, color: bool = True, tok_fn: Callable[[], str] | None = None):
|
|
3277
|
+
self.enabled, self.color, self.tok_fn = enabled, color, tok_fn
|
|
3191
3278
|
self._stop, self._t, self._t0 = threading.Event(), None, 0.0
|
|
3192
3279
|
|
|
3193
3280
|
def start(self) -> "Spinner":
|
|
@@ -3199,17 +3286,33 @@ class Spinner:
|
|
|
3199
3286
|
return self
|
|
3200
3287
|
|
|
3201
3288
|
@staticmethod
|
|
3202
|
-
def frame(i: int, elapsed: float, color: bool = True, rb: bool = False) -> str:
|
|
3203
|
-
"""Uma linha sóbria: giro braille na cor de destaque, verbo em negrito
|
|
3204
|
-
|
|
3289
|
+
def frame(i: int, elapsed: float, color: bool = True, rb: bool = False, tok: str = "", width: int = 0) -> str:
|
|
3290
|
+
"""Uma linha sóbria: giro braille na cor de destaque, verbo em negrito, tokens ao vivo e o
|
|
3291
|
+
tempo em cinza. NUNCA passa da largura do terminal: se passasse, a linha quebraria e, com o
|
|
3292
|
+
cursor perto da base (Termux), cada tick viraria uma linha nova (spam). `rb` é aceito por
|
|
3293
|
+
compatibilidade, mas não muda as cores."""
|
|
3205
3294
|
label = VERBS[int(elapsed // 3) % len(VERBS)] + "…"
|
|
3206
3295
|
glyph = SPIN_FRAMES[i % len(SPIN_FRAMES)]
|
|
3207
|
-
|
|
3296
|
+
room = (width or 10 ** 6) - 1 # 1 coluna de folga para o cursor não quebrar a linha
|
|
3297
|
+
tok_v = f" · {tok}" if tok else ""
|
|
3298
|
+
if 2 + len(label) + len(tok_v) > room: # tira os tokens antes de deixar quebrar
|
|
3299
|
+
tok_v = ""
|
|
3300
|
+
hint_v = ""
|
|
3301
|
+
for h in (t("spin_hint", s=int(elapsed)), "(%ss)" % int(elapsed)):
|
|
3302
|
+
if 2 + len(label) + len(tok_v) + 1 + len(h) <= room:
|
|
3303
|
+
hint_v = " " + h
|
|
3304
|
+
break
|
|
3305
|
+
if 2 + len(label) + len(hint_v) > room: # nem o rótulo sozinho cabe: trunca
|
|
3306
|
+
label = fit(label, max(1, room - 2))
|
|
3307
|
+
return (paint(glyph, ACCENT, color=color) + " " + paint(label, BOLD, color=color)
|
|
3308
|
+
+ paint(tok_v, DIM, color=color) + paint(hint_v, DIM, color=color))
|
|
3208
3309
|
|
|
3209
3310
|
def _run(self) -> None:
|
|
3210
3311
|
i = 0
|
|
3211
3312
|
while not self._stop.wait(0.1):
|
|
3212
|
-
|
|
3313
|
+
cols = shutil.get_terminal_size((80, 24)).columns
|
|
3314
|
+
tok = self.tok_fn() if self.tok_fn else ""
|
|
3315
|
+
sys.stdout.write("\r" + self.frame(i, time.time() - self._t0, self.color, getattr(self, "rb", False), tok, cols) + "\x1b[K")
|
|
3213
3316
|
sys.stdout.flush()
|
|
3214
3317
|
i += 1
|
|
3215
3318
|
|
|
@@ -3252,7 +3355,8 @@ def read_boxed(prompt: str, left: str, right: str, width: int, tty: bool, color:
|
|
|
3252
3355
|
|
|
3253
3356
|
def _stream_turn(c: Client, text: str, history: list[dict], model: str | None, project: str | None,
|
|
3254
3357
|
printer: "StreamPrinter", spinner: Spinner, web: bool = False, skill: str | None = None, context: str | None = None, tools: bool = True, effort: str | None = None,
|
|
3255
|
-
files: list[dict] | None = None, images: list[dict] | None = None
|
|
3358
|
+
files: list[dict] | None = None, images: list[dict] | None = None,
|
|
3359
|
+
live_tok: dict | None = None) -> dict:
|
|
3256
3360
|
"""Uma rodada de chat em streaming. Devolve {answer, model, fallback_event, error}."""
|
|
3257
3361
|
body: dict = {"message": text, "history": history[-MAX_HISTORY:]}
|
|
3258
3362
|
att_body(body, files, images)
|
|
@@ -3277,6 +3381,8 @@ def _stream_turn(c: Client, text: str, history: list[dict], model: str | None, p
|
|
|
3277
3381
|
r = _chat_once(c, text, history, model, project, web, skill, context, tools, effort, files, images)
|
|
3278
3382
|
spinner.stop()
|
|
3279
3383
|
printer.feed(r.get("answer", ""))
|
|
3384
|
+
if live_tok is not None:
|
|
3385
|
+
live_tok["comp"] = len(r.get("answer", "")) // 4
|
|
3280
3386
|
return {"answer": r.get("answer", ""), "model": r.get("model"), "fallback_event": r.get("fallback_event"), "error": None, "web": r.get("web"), "sources": r.get("sources"),
|
|
3281
3387
|
"usage": r.get("usage"), "skill": r.get("skill"), "skill_auto": r.get("skill_auto")}
|
|
3282
3388
|
if resp.status != 200:
|
|
@@ -3293,6 +3399,8 @@ def _stream_turn(c: Client, text: str, history: list[dict], model: str | None, p
|
|
|
3293
3399
|
spinner.stop()
|
|
3294
3400
|
printer.feed(d["t"])
|
|
3295
3401
|
res["answer"] += d["t"]
|
|
3402
|
+
if live_tok is not None:
|
|
3403
|
+
live_tok["comp"] = len(res["answer"]) // 4
|
|
3296
3404
|
elif name == "error":
|
|
3297
3405
|
res["error"] = d.get("error", "erro")
|
|
3298
3406
|
return res
|
|
@@ -3675,6 +3783,7 @@ def cmd_tui(c: Client, a: argparse.Namespace, out: Callable[[str], None] = print
|
|
|
3675
3783
|
|
|
3676
3784
|
reader = read or (lambda prompt: read_boxed(prompt, t("foot_left"), footer_right(), width, tty, color))
|
|
3677
3785
|
while True:
|
|
3786
|
+
width = term_width() # o terminal muda de tamanho no Termux quando o teclado abre/fecha: relê a cada volta
|
|
3678
3787
|
if pending is not None:
|
|
3679
3788
|
line, pending = pending, None
|
|
3680
3789
|
else:
|
|
@@ -3949,12 +4058,18 @@ def cmd_tui(c: Client, a: argparse.Namespace, out: Callable[[str], None] = print
|
|
|
3949
4058
|
buf: list[str] = []
|
|
3950
4059
|
state: dict = {}
|
|
3951
4060
|
panel = LivePanel(live, color, col_fn=lambda: state["p"].col if "p" in state else 0)
|
|
4061
|
+
# Tokens ao vivo (item 2): a estimativa cresce e aparece ao lado do verbo, no próprio
|
|
4062
|
+
# spinner (uma linha in-place que nunca passa da largura). Nada de barra fixada embaixo
|
|
4063
|
+
# do cursor: no Termux o terminal é curto e rola a cada tick, virando spam.
|
|
4064
|
+
live_tok = {"prompt": 0, "comp": 0} # tokens ao vivo da rodada (estimativa; o valor exato chega no `done`)
|
|
3952
4065
|
base_printer = StreamPrinter((lambda s: (sys.stdout.write("\x1b[J" + s), sys.stdout.flush())) if live else (lambda s: (sys.stdout.write(s), sys.stdout.flush())) if tty else buf.append, width - 1, color)
|
|
3953
4066
|
printer = LockedPrinter(base_printer, panel.lock) if live else base_printer
|
|
3954
4067
|
state["p"] = base_printer
|
|
3955
|
-
sp = NoStop() if live else Spinner(tty, color)
|
|
4068
|
+
sp = NoStop() if live else Spinner(tty, color, tok_fn=lambda: (fmt_tok(live_tok["prompt"] + live_tok["comp"]) + " tok~") if live_tok["prompt"] + live_tok["comp"] else "")
|
|
3956
4069
|
sp.rb = effort == "max"
|
|
3957
4070
|
t0 = time.time()
|
|
4071
|
+
live_tok["prompt"] = ctx_tokens(history, summary, sticky) + len(line) // 4
|
|
4072
|
+
live_tok["comp"] = 0
|
|
3958
4073
|
r: dict | None = None
|
|
3959
4074
|
is_step = line.startswith("[Resultado") or line.startswith("[Skill ")
|
|
3960
4075
|
turn_images: list[dict] = []
|
|
@@ -3965,7 +4080,7 @@ def cmd_tui(c: Client, a: argparse.Namespace, out: Callable[[str], None] = print
|
|
|
3965
4080
|
try:
|
|
3966
4081
|
with quiet_input(tty):
|
|
3967
4082
|
panel.start("think") if live else sp.start()
|
|
3968
|
-
r = _stream_turn(c, line, history, model, None, printer, sp, web or once_web or fb_web, skill or (auto_name if is_step else None), summary, True, effort, sticky, turn_images)
|
|
4083
|
+
r = _stream_turn(c, line, history, model, None, printer, sp, web or once_web or fb_web, skill or (auto_name if is_step else None), summary, True, effort, sticky, turn_images, live_tok=live_tok)
|
|
3969
4084
|
fb_web = False
|
|
3970
4085
|
except KeyboardInterrupt:
|
|
3971
4086
|
printer.finish()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vyra-code
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.46
|
|
4
4
|
Summary: Vyra Code: assistente de IA no terminal (Termux, Linux, macOS e Windows) (chat em streaming, tarefas, memória, projetos e terminal remoto)
|
|
5
5
|
License: Proprietary
|
|
6
6
|
Keywords: termux,ai,assistant,cli,android,llm
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|