krnell 0.0.0-stage → 3.0.2
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.
- package/Iniciar_Linux.sh +129 -0
- package/Instalar_Atalho_Windows.cmd +40 -0
- package/Instalar_Ubuntu.sh +95 -0
- package/Painel.cmd +138 -0
- package/README.md +82 -2
- package/atualizador.py +148 -0
- package/bin/krnell.mjs +159 -0
- package/bridge.py +5280 -0
- package/config.example.json +57 -0
- package/contexto.py +204 -0
- package/dashboard_web.py +308 -0
- package/dns_duck.py +227 -0
- package/ferramentas/Liberar_Firewall.ps1 +96 -0
- package/ferramentas/firewall_linux.sh +67 -0
- package/ferramentas/install_windows.py +482 -0
- package/ferramentas/selecionar_provedor.py +76 -0
- package/iniciar.sh +255 -0
- package/keys.example.env +3 -0
- package/kimi.py +567 -0
- package/opencode_sync.py +265 -0
- package/package.json +68 -4
- package/painel.py +5612 -0
- package/painel_web.py +367 -0
- package/plugins/system-prompt/index.ts +409 -0
- package/provedores/kimi/bridge.mjs +4349 -0
- package/provedores/kimi/package.json +10 -0
- package/provedores_catalogo.py +27 -0
- package/tls_proxy.py +205 -0
- package/tui_core.py +604 -0
- package/web/dist/.vite/manifest.json +84 -0
- package/web/dist/assets/LogsPage-DkXN-I7o.js +2 -0
- package/web/dist/assets/LogsPage-OsSvuqxQ.js +2 -0
- package/web/dist/assets/TerminalPage-CZTPxVyx.js +1 -0
- package/web/dist/assets/TerminalPage-D208X99P.js +1 -0
- package/web/dist/assets/TerminalPage-DYGPu4ux.css +1 -0
- package/web/dist/assets/index-B5rIwous.js +1 -0
- package/web/dist/assets/index-CJE_a_Tn.js +27 -0
- package/web/dist/assets/index-COlDAcsY.js +1 -0
- package/web/dist/assets/index-Dzc8Obwp.css +1 -0
- package/web/dist/assets/index-LZadV7rx.js +27 -0
- package/web/dist/assets/index-o8xT03ZV.css +1 -0
- package/web/dist/assets/press-start-2p-2BZhbCiP.ttf +0 -0
- package/web/dist/assets/react-vendor-C475ILlI.js +49 -0
- package/web/dist/assets/terminal-vendor-DOrYoP_4.css +32 -0
- package/web/dist/assets/terminal-vendor-Dp03d74L.js +38 -0
- package/web/dist/assets/terminal-webgl-BRBWwLY7.js +75 -0
- package/web/dist/favicon.svg +1 -0
- package/web/dist/fonts/OFL.txt +93 -0
- package/web/dist/fonts/press-start-2p.ttf +0 -0
- package/web/dist/index.html +18 -0
- package/workbuddy.py +1965 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Catálogo minimalista de provedores (estilo /connect do OpenCode)."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
PROVEDORES_API_PRESETS: list[dict[str, str]] = [
|
|
5
|
+
{'slug': 'openai', 'nome': 'OpenAI', 'base_url': 'https://api.openai.com/v1', 'modelo_padrao': 'gpt-5', 'detalhe': 'API key'},
|
|
6
|
+
{'slug': 'anthropic', 'nome': 'Anthropic', 'base_url': 'https://api.anthropic.com/v1', 'modelo_padrao': 'claude-sonnet-4-5', 'detalhe': 'API key'},
|
|
7
|
+
{'slug': 'openrouter', 'nome': 'OpenRouter', 'base_url': 'https://openrouter.ai/api/v1', 'modelo_padrao': 'deepseek/deepseek-r1:free', 'detalhe': 'API key'},
|
|
8
|
+
{'slug': 'google', 'nome': 'Google Gemini', 'base_url': 'https://generativelanguage.googleapis.com/v1beta/openai', 'modelo_padrao': 'gemini-2.5-pro', 'detalhe': 'API key'},
|
|
9
|
+
{'slug': 'deepseek', 'nome': 'DeepSeek', 'base_url': 'https://api.deepseek.com/v1', 'modelo_padrao': 'deepseek-reasoner', 'detalhe': 'API key'},
|
|
10
|
+
{'slug': 'xai', 'nome': 'xAI', 'base_url': 'https://api.x.ai/v1', 'modelo_padrao': 'grok-3', 'detalhe': 'API key'},
|
|
11
|
+
{'slug': 'groq', 'nome': 'Groq', 'base_url': 'https://api.groq.com/openai/v1', 'modelo_padrao': 'llama-3.3-70b-versatile', 'detalhe': 'API key'},
|
|
12
|
+
{'slug': 'mistral', 'nome': 'Mistral', 'base_url': 'https://api.mistral.ai/v1', 'modelo_padrao': 'mistral-large-latest', 'detalhe': 'API key'},
|
|
13
|
+
{'slug': 'nvidia_api', 'nome': 'NVIDIA NIM', 'base_url': 'https://integrate.api.nvidia.com/v1', 'modelo_padrao': 'moonshotai/kimi-k3.1-pro', 'detalhe': 'API key'},
|
|
14
|
+
{'slug': 'moonshot', 'nome': 'Moonshot', 'base_url': 'https://api.moonshot.ai/v1', 'modelo_padrao': 'kimi-k2-thinking', 'detalhe': 'API key'},
|
|
15
|
+
{'slug': 'cerebras', 'nome': 'Cerebras', 'base_url': 'https://api.cerebras.ai/v1', 'modelo_padrao': 'llama-3.3-70b', 'detalhe': 'API key'},
|
|
16
|
+
{'slug': 'together', 'nome': 'Together', 'base_url': 'https://api.together.xyz/v1', 'modelo_padrao': 'deepseek-ai/DeepSeek-R1', 'detalhe': 'API key'},
|
|
17
|
+
{'slug': 'fireworks', 'nome': 'Fireworks', 'base_url': 'https://api.fireworks.ai/inference/v1', 'modelo_padrao': 'accounts/fireworks/models/deepseek-r1', 'detalhe': 'API key'},
|
|
18
|
+
{'slug': 'perplexity', 'nome': 'Perplexity', 'base_url': 'https://api.perplexity.ai', 'modelo_padrao': 'sonar-pro', 'detalhe': 'API key'},
|
|
19
|
+
{'slug': 'siliconflow', 'nome': 'SiliconFlow', 'base_url': 'https://api.siliconflow.cn/v1', 'modelo_padrao': 'deepseek-ai/DeepSeek-R1', 'detalhe': 'API key'},
|
|
20
|
+
{'slug': 'zhipuai', 'nome': 'Zhipu AI', 'base_url': 'https://open.bigmodel.cn/api/paas/v4', 'modelo_padrao': 'glm-4-plus', 'detalhe': 'API key'},
|
|
21
|
+
{'slug': 'minimax_api', 'nome': 'MiniMax', 'base_url': 'https://api.minimax.io/v1', 'modelo_padrao': 'MiniMax-M1', 'detalhe': 'API key'},
|
|
22
|
+
{'slug': 'cometapi', 'nome': 'CometAPI', 'base_url': 'https://api.cometapi.com/v1', 'modelo_padrao': 'gpt-4o', 'detalhe': 'API key'},
|
|
23
|
+
{'slug': 'venice', 'nome': 'Venice', 'base_url': 'https://api.venice.ai/api/v1', 'modelo_padrao': 'llama-3.3-70b', 'detalhe': 'API key'},
|
|
24
|
+
{'slug': 'ollama', 'nome': 'Ollama', 'base_url': 'http://127.0.0.1:11434/v1', 'modelo_padrao': 'llama3.2', 'detalhe': 'Local'},
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
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('krnell_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())
|