krnell 0.0.0-stage → 3.0.0

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.
Files changed (50) hide show
  1. package/Iniciar_Linux.sh +129 -0
  2. package/Instalar_Atalho_Windows.cmd +40 -0
  3. package/Instalar_Ubuntu.sh +95 -0
  4. package/Painel.cmd +138 -0
  5. package/README.md +70 -2
  6. package/bin/nyxo.mjs +138 -0
  7. package/bridge.py +5196 -0
  8. package/config.example.json +57 -0
  9. package/contexto.py +184 -0
  10. package/dashboard_web.py +308 -0
  11. package/dns_duck.py +227 -0
  12. package/ferramentas/Liberar_Firewall.ps1 +96 -0
  13. package/ferramentas/firewall_linux.sh +67 -0
  14. package/ferramentas/install_windows.py +482 -0
  15. package/ferramentas/selecionar_provedor.py +70 -0
  16. package/iniciar.sh +255 -0
  17. package/keys.example.env +3 -0
  18. package/kimi.py +482 -0
  19. package/opencode_sync.py +239 -0
  20. package/package.json +69 -4
  21. package/painel.py +5227 -0
  22. package/painel_web.py +367 -0
  23. package/plugins/system-prompt/index.ts +409 -0
  24. package/provedores/kimi/bridge.mjs +4280 -0
  25. package/provedores/kimi/package.json +10 -0
  26. package/provedores_catalogo.py +155 -0
  27. package/tls_proxy.py +205 -0
  28. package/tui_core.py +600 -0
  29. package/web/dist/.vite/manifest.json +84 -0
  30. package/web/dist/assets/LogsPage-DkXN-I7o.js +2 -0
  31. package/web/dist/assets/LogsPage-OsSvuqxQ.js +2 -0
  32. package/web/dist/assets/TerminalPage-CZTPxVyx.js +1 -0
  33. package/web/dist/assets/TerminalPage-D208X99P.js +1 -0
  34. package/web/dist/assets/TerminalPage-DYGPu4ux.css +1 -0
  35. package/web/dist/assets/index-B5rIwous.js +1 -0
  36. package/web/dist/assets/index-CJE_a_Tn.js +27 -0
  37. package/web/dist/assets/index-COlDAcsY.js +1 -0
  38. package/web/dist/assets/index-Dzc8Obwp.css +1 -0
  39. package/web/dist/assets/index-LZadV7rx.js +27 -0
  40. package/web/dist/assets/index-o8xT03ZV.css +1 -0
  41. package/web/dist/assets/press-start-2p-2BZhbCiP.ttf +0 -0
  42. package/web/dist/assets/react-vendor-C475ILlI.js +49 -0
  43. package/web/dist/assets/terminal-vendor-DOrYoP_4.css +32 -0
  44. package/web/dist/assets/terminal-vendor-Dp03d74L.js +38 -0
  45. package/web/dist/assets/terminal-webgl-BRBWwLY7.js +75 -0
  46. package/web/dist/favicon.svg +1 -0
  47. package/web/dist/fonts/OFL.txt +93 -0
  48. package/web/dist/fonts/press-start-2p.ttf +0 -0
  49. package/web/dist/index.html +18 -0
  50. package/workbuddy.py +1965 -0
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "kimi-bridge",
3
+ "version": "2.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "main": "bridge.mjs",
7
+ "dependencies": {
8
+ "playwright-core": "^1.65.0"
9
+ }
10
+ }
@@ -0,0 +1,155 @@
1
+ """Catálogo de provedores padrão (estilo /connect do OpenCode) para o Nyxo.
2
+
3
+ Cada preset define:
4
+ - slug: identificador interno salvo em config.json ("provedores")
5
+ - nome: rótulo exibido no /connect
6
+ - base_url: endpoint OpenAI-compatible
7
+ - modelo_padrao: sugestão inicial de modelo ao ativar
8
+ - detalhe: resumo curto exibido à direita no diálogo /connect
9
+ """
10
+ from __future__ import annotations
11
+
12
+ PROVEDORES_API_PRESETS: list[dict[str, str]] = [
13
+ {
14
+ 'slug': 'openai',
15
+ 'nome': 'OpenAI (API / ChatGPT)',
16
+ 'base_url': 'https://api.openai.com/v1',
17
+ 'modelo_padrao': 'gpt-5',
18
+ 'detalhe': 'GPT-5, Codex, o3 · cole sua API key',
19
+ },
20
+ {
21
+ 'slug': 'anthropic',
22
+ 'nome': 'Anthropic (Claude API)',
23
+ 'base_url': 'https://api.anthropic.com/v1',
24
+ 'modelo_padrao': 'claude-sonnet-4-5',
25
+ 'detalhe': 'Claude Sonnet / Opus · cole sua API key',
26
+ },
27
+ {
28
+ 'slug': 'openrouter',
29
+ 'nome': 'OpenRouter',
30
+ 'base_url': 'https://openrouter.ai/api/v1',
31
+ 'modelo_padrao': 'deepseek/deepseek-r1:free',
32
+ 'detalhe': '300+ modelos (incluindo free) · API key',
33
+ },
34
+ {
35
+ 'slug': 'google',
36
+ 'nome': 'Google Gemini API',
37
+ 'base_url': 'https://generativelanguage.googleapis.com/v1beta/openai',
38
+ 'modelo_padrao': 'gemini-2.5-pro',
39
+ 'detalhe': 'Gemini 2.5 Pro/Flash · AI Studio key',
40
+ },
41
+ {
42
+ 'slug': 'deepseek',
43
+ 'nome': 'DeepSeek API',
44
+ 'base_url': 'https://api.deepseek.com/v1',
45
+ 'modelo_padrao': 'deepseek-reasoner',
46
+ 'detalhe': 'DeepSeek R1 / V3 · API key',
47
+ },
48
+ {
49
+ 'slug': 'xai',
50
+ 'nome': 'xAI (Grok)',
51
+ 'base_url': 'https://api.x.ai/v1',
52
+ 'modelo_padrao': 'grok-3',
53
+ 'detalhe': 'Grok 3 / Mini · API key',
54
+ },
55
+ {
56
+ 'slug': 'groq',
57
+ 'nome': 'Groq (ultra-rápido)',
58
+ 'base_url': 'https://api.groq.com/openai/v1',
59
+ 'modelo_padrao': 'llama-3.3-70b-versatile',
60
+ 'detalhe': 'Llama / Qwen / DeepSeek · API key',
61
+ },
62
+ {
63
+ 'slug': 'mistral',
64
+ 'nome': 'Mistral AI',
65
+ 'base_url': 'https://api.mistral.ai/v1',
66
+ 'modelo_padrao': 'mistral-large-latest',
67
+ 'detalhe': 'Mistral Large / Codestral · API key',
68
+ },
69
+ {
70
+ 'slug': 'nvidia_api',
71
+ 'nome': 'NVIDIA NIM (API oficial)',
72
+ 'base_url': 'https://integrate.api.nvidia.com/v1',
73
+ 'modelo_padrao': 'moonshotai/kimi-k3.1-pro',
74
+ 'detalhe': 'integrate.api.nvidia.com · API key',
75
+ },
76
+ {
77
+ 'slug': 'moonshot',
78
+ 'nome': 'Moonshot AI (Kimi API)',
79
+ 'base_url': 'https://api.moonshot.ai/v1',
80
+ 'modelo_padrao': 'kimi-k2-thinking',
81
+ 'detalhe': 'Kimi oficial · API key',
82
+ },
83
+ {
84
+ 'slug': 'cerebras',
85
+ 'nome': 'Cerebras',
86
+ 'base_url': 'https://api.cerebras.ai/v1',
87
+ 'modelo_padrao': 'llama-3.3-70b',
88
+ 'detalhe': 'Inferência ultrarrápida · API key',
89
+ },
90
+ {
91
+ 'slug': 'together',
92
+ 'nome': 'Together AI',
93
+ 'base_url': 'https://api.together.xyz/v1',
94
+ 'modelo_padrao': 'deepseek-ai/DeepSeek-R1',
95
+ 'detalhe': 'Modelos open-weights · API key',
96
+ },
97
+ {
98
+ 'slug': 'fireworks',
99
+ 'nome': 'Fireworks AI',
100
+ 'base_url': 'https://api.fireworks.ai/inference/v1',
101
+ 'modelo_padrao': 'accounts/fireworks/models/deepseek-r1',
102
+ 'detalhe': 'Inferência baixa latência · API key',
103
+ },
104
+ {
105
+ 'slug': 'perplexity',
106
+ 'nome': 'Perplexity',
107
+ 'base_url': 'https://api.perplexity.ai',
108
+ 'modelo_padrao': 'sonar-pro',
109
+ 'detalhe': 'Sonar busca web · API key',
110
+ },
111
+ {
112
+ 'slug': 'siliconflow',
113
+ 'nome': 'SiliconFlow',
114
+ 'base_url': 'https://api.siliconflow.cn/v1',
115
+ 'modelo_padrao': 'deepseek-ai/DeepSeek-R1',
116
+ 'detalhe': 'DeepSeek / Qwen · API key',
117
+ },
118
+ {
119
+ 'slug': 'zhipuai',
120
+ 'nome': 'Zhipu AI (GLM)',
121
+ 'base_url': 'https://open.bigmodel.cn/api/paas/v4',
122
+ 'modelo_padrao': 'glm-4-plus',
123
+ 'detalhe': 'GLM-4 / CodeGeeX · API key',
124
+ },
125
+ {
126
+ 'slug': 'minimax_api',
127
+ 'nome': 'MiniMax API',
128
+ 'base_url': 'https://api.minimax.io/v1',
129
+ 'modelo_padrao': 'MiniMax-M1',
130
+ 'detalhe': 'MiniMax oficial · API key',
131
+ },
132
+ {
133
+ 'slug': 'cometapi',
134
+ 'nome': 'CometAPI',
135
+ 'base_url': 'https://api.cometapi.com/v1',
136
+ 'modelo_padrao': 'gpt-4o',
137
+ 'detalhe': 'Agregador multi-modelo · API key',
138
+ },
139
+ {
140
+ 'slug': 'venice',
141
+ 'nome': 'Venice AI',
142
+ 'base_url': 'https://api.venice.ai/api/v1',
143
+ 'modelo_padrao': 'llama-3.3-70b',
144
+ 'detalhe': 'Privacidade / sem filtro · API key',
145
+ },
146
+ {
147
+ 'slug': 'ollama',
148
+ 'nome': 'Ollama (local · sem chave)',
149
+ 'base_url': 'http://127.0.0.1:11434/v1',
150
+ 'modelo_padrao': 'llama3.2',
151
+ 'detalhe': 'Modelos locais em 127.0.0.1:11434',
152
+ },
153
+ ]
154
+
155
+ PRESET_POR_SLUG: dict[str, dict[str, str]] = {p['slug']: p for p in PROVEDORES_API_PRESETS}
package/tls_proxy.py ADDED
@@ -0,0 +1,205 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Terminador TLS do bridge.
5
+
6
+ Escuta em HTTPS usando o certificado correspondente ao domínio configurado
7
+ em `link_publico` no config.json (em certs/certificates/<dominio>.crt/.key)
8
+ e repassa o trafego ja decifrado para o bridge HTTP local.
9
+
10
+ O bridge continua exatamente como era: o HTTP segue funcionando igual.
11
+ Este processo so existe para dar o cadeado (https) aos clientes quando um
12
+ domínio HTTPS estiver configurado em `link_publico`.
13
+ """
14
+
15
+ import errno
16
+ import json
17
+ import logging
18
+ import os
19
+ from pathlib import Path
20
+ import re
21
+ import socket
22
+ from socketserver import BaseRequestHandler, ThreadingTCPServer
23
+ import ssl
24
+ import sys
25
+ import threading
26
+ import time
27
+ from urllib.parse import urlsplit
28
+
29
+ BASE = os.path.dirname(os.path.abspath(__file__))
30
+ CERT = ""
31
+ KEY = ""
32
+
33
+ LISTEN_HOST = "0.0.0.0"
34
+ LISTEN_PORT = 443
35
+ TARGET = ("127.0.0.1", 8765)
36
+ LOG = os.path.join(BASE, "logs", "tls_nyxo.log")
37
+
38
+
39
+ def log(msg):
40
+ try:
41
+ os.makedirs(os.path.dirname(LOG), exist_ok=True)
42
+ with open(LOG, "a", encoding="utf-8") as fh:
43
+ fh.write("%s %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S"), msg))
44
+ except OSError:
45
+ pass
46
+
47
+
48
+ def pipe(src, dst):
49
+ """Copia bytes de src para dst ate um dos lados fechar."""
50
+ try:
51
+ while True:
52
+ chunk = src.recv(65536)
53
+ if not chunk:
54
+ break
55
+ dst.sendall(chunk)
56
+ except (OSError, ssl.SSLError):
57
+ pass
58
+ finally:
59
+ try:
60
+ dst.close()
61
+ except OSError:
62
+ pass
63
+
64
+
65
+ def handle(client, target=TARGET):
66
+ try:
67
+ upstream = socket.create_connection(target, timeout=15)
68
+ except OSError as exc:
69
+ log("upstream falhou: %r" % (exc,))
70
+ try:
71
+ client.close()
72
+ except OSError:
73
+ pass
74
+ return
75
+
76
+ upstream.settimeout(None)
77
+ t1 = threading.Thread(target=pipe, args=(client, upstream), daemon=True)
78
+ t2 = threading.Thread(target=pipe, args=(upstream, client), daemon=True)
79
+ t1.start()
80
+ t2.start()
81
+ t1.join()
82
+ t2.join()
83
+
84
+
85
+ class TLSBridgeHandler(BaseRequestHandler):
86
+ def handle(self):
87
+ # Cada handshake tem sua propria thread: uma conexao incompleta nao
88
+ # bloqueia as chamadas paralelas nem os streams SSE do OpenCode.
89
+ self.request.settimeout(15)
90
+ try:
91
+ with self.server.context.wrap_socket(self.request, server_side=True) as client:
92
+ client.settimeout(None)
93
+ handle(client, self.server.target)
94
+ except (OSError, ssl.SSLError) as exc:
95
+ log('conexao TLS falhou de %s: %r' % (self.client_address[0], exc))
96
+
97
+
98
+ class TLSBridgeServer(ThreadingTCPServer):
99
+ allow_reuse_address = os.name != 'nt'
100
+ daemon_threads = True
101
+
102
+ def __init__(self, address, context, target):
103
+ self.context = context
104
+ self.target = target
105
+ super().__init__(address, TLSBridgeHandler)
106
+
107
+
108
+ def start_for_bridge(cfg, base_path):
109
+ """Liga o HTTPS anunciado pelo bridge, preservando o HTTP e proxies externos.
110
+
111
+ O painel inicia bridge.py, nao Iniciar_Servicos.ps1. Por isso o listener
112
+ TLS precisa acompanhar o core tambem quando ele e aberto pelo painel.
113
+ Retorna apenas o servidor criado aqui, para o core encerrar o que e seu.
114
+ """
115
+ logger = logging.getLogger('deepseek_universal_bridge')
116
+ public = urlsplit(str(cfg.get('link_publico') or ''))
117
+ if public.scheme != 'https':
118
+ return None
119
+ try:
120
+ hostname = public.hostname or ''
121
+ if not re.fullmatch(r'[A-Za-z0-9.-]+', hostname):
122
+ raise ValueError('nome HTTPS invalido para localizar o certificado')
123
+ certificates = Path(base_path) / 'certs' / 'certificates'
124
+ cert = certificates / (hostname + '.crt')
125
+ key = certificates / (hostname + '.key')
126
+ context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
127
+ context.load_cert_chain(str(cert), str(key))
128
+ context.minimum_version = ssl.TLSVersion.TLSv1_2
129
+ try:
130
+ context.set_alpn_protocols(['http/1.1'])
131
+ except NotImplementedError:
132
+ pass
133
+ host = cfg.get('host', '127.0.0.1')
134
+ port = public.port if public.port is not None else LISTEN_PORT
135
+ target = ('127.0.0.1' if host == '0.0.0.0' else host, cfg.get('port', 8765))
136
+ server = TLSBridgeServer((host, port), context, target)
137
+ except (OSError, ValueError) as exc:
138
+ if (isinstance(exc, OSError) and
139
+ (exc.errno == errno.EADDRINUSE or getattr(exc, 'winerror', None) == 10048)):
140
+ logger.warning('tls_porta_ocupada link=%s listener existente preservado',
141
+ cfg.get('link_publico'))
142
+ else:
143
+ logger.warning('tls_indisponivel link=%s erro=%s; HTTP preservado',
144
+ cfg.get('link_publico'), exc)
145
+ return None
146
+ threading.Thread(target=server.serve_forever,
147
+ name='bridge-https', daemon=True).start()
148
+ logger.info('tls_listening url=%s target=%s:%d',
149
+ cfg.get('link_publico'), target[0], target[1])
150
+ return server
151
+
152
+
153
+ def main():
154
+ cfg_path = Path(BASE) / "config.json"
155
+ cfg = {}
156
+ try:
157
+ cfg = json.loads(cfg_path.read_text(encoding="utf-8-sig"))
158
+ except OSError:
159
+ cfg = {}
160
+ public = urlsplit(str(cfg.get("link_publico") or ""))
161
+ hostname = public.hostname or ""
162
+ cert = CERT or (os.path.join(BASE, "certs", "certificates", hostname + ".crt") if hostname else "")
163
+ key = KEY or (os.path.join(BASE, "certs", "certificates", hostname + ".key") if hostname else "")
164
+ if not (cert and key and os.path.isfile(cert) and os.path.isfile(key)):
165
+ print("certificado ausente: configure link_publico HTTPS em config.json e os arquivos em certs/certificates/")
166
+ return 1
167
+
168
+ target = ("127.0.0.1", int(cfg.get("port") or TARGET[1]))
169
+ listen_port = public.port if public.port is not None else LISTEN_PORT
170
+
171
+ ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
172
+ ctx.load_cert_chain(cert, key)
173
+ ctx.minimum_version = ssl.TLSVersion.TLSv1_2
174
+ try:
175
+ ctx.set_alpn_protocols(["http/1.1"])
176
+ except NotImplementedError:
177
+ pass
178
+
179
+ server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
180
+ server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
181
+ server.bind((LISTEN_HOST, listen_port))
182
+ server.listen(128)
183
+
184
+ print("tls_proxy ouvindo em %s:%d -> %s:%d" % (LISTEN_HOST, listen_port, target[0], target[1]))
185
+ log("iniciado em %s:%d" % (LISTEN_HOST, listen_port))
186
+
187
+ while True:
188
+ try:
189
+ raw, addr = server.accept()
190
+ except OSError:
191
+ continue
192
+ try:
193
+ client = ctx.wrap_socket(raw, server_side=True)
194
+ except (ssl.SSLError, OSError) as exc:
195
+ log("handshake falhou de %s: %r" % (addr[0], exc))
196
+ try:
197
+ raw.close()
198
+ except OSError:
199
+ pass
200
+ continue
201
+ threading.Thread(target=handle, args=(client, target), daemon=True).start()
202
+
203
+
204
+ if __name__ == "__main__":
205
+ sys.exit(main())