Compare commits

..
Author SHA1 Message Date
yilsemandClaude Opus 5.5 ac0fdcf355 fix(codex-link): show added models as provider/model, drop the 9R mark
ci / mobile-link-windows (push) Successful in 33s
ci / approval-gate-windows (push) Successful in 2m40s
User decision (10 Oct 2026): combos keep their own name; single models
read as short provider/model with the version kept (cc/opus-5-5,
agy/gemini-3.8-flash-high, bekci/kurnaz). No-think copies show their
real provider with a "(no-think)" suffix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 17:52:55 +03:00
yilsemandClaude Opus 5.5 9a54705ed5 fix(codex-link): label cx models as Codex, matching the 9Router alias
ci / mobile-link-windows (push) Successful in 37s
ci / approval-gate-windows (push) Successful in 2m39s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 15:55:04 +03:00
yilsemandClaude Opus 5.5 9739222919 fix(codex-link): only reject degenerate summaries, not short correct ones
ci / mobile-link-windows (push) Successful in 36s
ci / approval-gate-windows (push) Successful in 2m54s
The size-proportional minimum (input/250, cap 4000) rejected a correct summary:
a 646,955 byte thread (225k tokens, five labelled facts in a long log) was
summarized by the subscription model in 1501-1701 characters, the bridge demanded
2587, and Codex could not continue the thread on the selected model. The floor now
only catches broken output (input/2000, cap 300). Memory loss is prevented by who
writes the summary, not by its length.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 15:52:44 +03:00
yilsemandClaude Opus 5.5 94e4aa2a74 release: AITURK IDE 1.0.0-beta.25 (subscription models kept, summary by subscription model)
ci / mobile-link-windows (push) Successful in 59s
ci / approval-gate-windows (push) Successful in 2m42s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 15:32:54 +03:00
yilsemandClaude Opus 5.5 adf73eeedd fix(codex-link): summarize with a subscription model, reject tiny summaries, describe added models
Model switch lost the conversation: on 10 Oct a 1 MB thread was compacted by the
newly selected small model into 2201 characters. The compaction summary for a bridge
model is now written by a subscription model (ozet_kopru.ozet_modeli, default
gpt-6.1-sol); if that request is refused before it starts, the target model is used
as before. A summary far shorter than the conversation warrants is not accepted:
Codex gets response.failed and keeps the history.

The line under each added model no longer repeats its name. Teams show their
members, fallback chains their order, single models their provider and the traits
readable from the name; the text fits one phone row (30 characters).

Also normalizes tool call ids in the streamed response so Codex persists ids the
subscription backend accepts (fc_ -> ctc_), and bumps the bridge protocol to 6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 15:31:53 +03:00
yilsemandClaude Opus 5.5 ce49d6d1cc fix(codex-link): keep subscription models untouched, append bridge models after them
sirala_codex re-sorted the whole list and rewrote every priority, which pushed the
native subscription models to the bottom and put same-named AITURK copies
(GPT-6-Astra) above them. Native models now keep their own order, priority and
name; bridge models are appended after them and a copy that shares a native name
is shown with an (AITURK) suffix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 03:16:49 +03:00
yilsem 8ee676d7c6 test(codex-link): track the shipped bridge protocol version
ci / mobile-link-windows (push) Successful in 52s
ci / approval-gate-windows (push) Successful in 1m39s
2026-10-09 23:21:17 +03:00
yilsem 68a97b7489 ci: pin checkout through verified Gitea mirror
ci / mobile-link-windows (push) Failing after 1m24s
ci / approval-gate-windows (push) Successful in 2m11s
2026-10-09 23:18:39 +03:00
yilsem 6e91154f15 fix(codex-link): use member OmniRoute catalog and metadata ordering
ci / mobile-link-windows (push) Failing after 22s
ci / approval-gate-windows (push) Failing after 0s
2026-10-09 23:10:29 +03:00
yilsemandClaude Opus 5.5 88e660768c feat(codex-bridge): keep the gateway's short "9R" mark in Codex model names
ci / mobile-link-windows (push) Successful in 1m5s
ci / approval-gate-windows (push) Successful in 4m11s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRDGW1LiKcDUZYUdKBoWYW
2026-10-09 19:27:22 +03:00
yilsemandClaude Opus 5.5 bfd0ff196d feat(codex-bridge): add the models of 9Router's providers to Codex (beta.23)
Codex only received combos and the models named in the IDE config, so none of
the models behind the providers added to 9Router showed up. Those single
models are now always added; 9Router's combos stay hidden. The copy of the
same model that comes through OmniRoute is still added only when the IDE
config names it, so each model is listed once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRDGW1LiKcDUZYUdKBoWYW
2026-10-09 19:26:00 +03:00
yilsemandClaude Opus 5.5 1e0f2f9aea feat(codex-bridge): hide 9Router combos in Codex, drop the config backup (beta.22)
ci / mobile-link-windows (push) Successful in 1m12s
ci / approval-gate-windows (push) Successful in 2m39s
Combos that come from 9Router, directly or through the gateway's 9router
provider, are no longer added to Codex's model list; the gateway's own combos
keep their plain names. The IDE no longer leaves a config.toml backup behind:
turning the setting off already restores the file byte for byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRDGW1LiKcDUZYUdKBoWYW
2026-10-09 17:51:10 +03:00
yilsemandClaude Opus 5.5 b560950f82 fix(codex-bridge): ship zstd for the agent's Python and refuse to link without it
ci / mobile-link-windows (push) Successful in 44s
ci / approval-gate-windows (push) Successful in 2m32s
Codex compresses request bodies with zstd. The agent venv is Python 3.11, which
has no zstd in its standard library, so every Codex request failed on a fresh
install. The matching zstandard build now ships beside the bridge; the status
endpoint reports ok=false when bodies cannot be read, and the IDE then leaves
Codex's config alone. A running bridge from an older build is replaced, and
"Sync now" makes the bridge re-read the IDE session at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRDGW1LiKcDUZYUdKBoWYW
2026-10-09 16:27:55 +03:00
22 changed files with 5850 additions and 85 deletions
+2 -2
View File
@@ -29,7 +29,7 @@ jobs:
runs-on: windows-latest runs-on: windows-latest
timeout-minutes: 15 timeout-minutes: 15
steps: steps:
- uses: actions/checkout@v4 - uses: https://gitea.twinpay.one/yilsem/ci-actions-checkout@11d5960a326750d5838078e36cf38b85af677262 # upstream v4.4.0
with: with:
github-server-url: https://gitea.twinpay.one github-server-url: https://gitea.twinpay.one
- name: Mobil TLS, profil ve baslatma regresyonlari - name: Mobil TLS, profil ve baslatma regresyonlari
@@ -57,7 +57,7 @@ jobs:
timeout-minutes: 40 timeout-minutes: 40
steps: steps:
- name: Kaynagi al - name: Kaynagi al
uses: actions/checkout@v4 uses: https://gitea.twinpay.one/yilsem/ci-actions-checkout@11d5960a326750d5838078e36cf38b85af677262 # upstream v4.4.0
with: with:
github-server-url: https://gitea.twinpay.one github-server-url: https://gitea.twinpay.one
@@ -10,6 +10,13 @@ Codex depends on it while `openai_base_url` points here.
key read from the agent's `.env` on every catalog refresh (never written elsewhere). key read from the agent's `.env` on every catalog refresh (never written elsewhere).
- `ide_catalog.py`: which IDE models and combos are added to Codex's model list and - `ide_catalog.py`: which IDE models and combos are added to Codex's model list and
how they are named (`provider/model`, combos by bare name). how they are named (`provider/model`, combos by bare name).
The public `/models` catalog supplies every OmniRoute chat model; a member does
not need a private local model allowlist. `/router/catalog` supplies only the
`kind` metadata used for sorting, never additional model IDs. Direct 9Router
entries and internal 9Router combos are excluded. Combos sort A–Z first, then
individual models by provider and name, including OpenAI subscription models.
Codex labels the first visible row `isDefault`; a saved model selection remains
unchanged. A failed or empty refresh keeps the last successful catalog.
- `ozet_kopru.py`: conversation summaries are produced as plain text, so a summary made - `ozet_kopru.py`: conversation summaries are produced as plain text, so a summary made
by one provider stays readable after the user switches to another. by one provider stays readable after the user switches to another.
- `gemini_context.py`, `resim_context.py`: request fixes for routed models. - `gemini_context.py`, `resim_context.py`: request fixes for routed models.
+111 -25
View File
@@ -26,9 +26,42 @@ from resim_context import resimleri_sadelestir
import ide_catalog import ide_catalog
import ozet_kopru import ozet_kopru
SURUM = "1" SURUM = "6"
HERE = os.path.dirname(os.path.abspath(__file__)) HERE = os.path.dirname(os.path.abspath(__file__))
# Codex sends request bodies zstd-compressed. Python gained zstd in 3.14; for older
# interpreters the matching `zstandard` build ships next to this file.
_VENDOR = os.path.join(HERE, "vendor", "cp%d%d-win_amd64" % sys.version_info[:2])
if os.path.isdir(_VENDOR):
sys.path.insert(0, _VENDOR)
def _zstd_decompress(body):
try:
from compression import zstd as _z
return _z.decompress(body)
except ImportError:
import zstandard
return zstandard.ZstdDecompressor().decompressobj().decompress(body)
def _zstd_ready():
try:
try:
from compression import zstd as _z
sample = _z.compress(b"aiturk")
except ImportError:
import zstandard
sample = zstandard.ZstdCompressor().compress(b"aiturk")
return _zstd_decompress(sample) == b"aiturk"
except Exception:
return False
# Without zstd every Codex request would fail; the status endpoint then reports
# ok=false so that the IDE never points Codex at this bridge.
ZSTD_OK = _zstd_ready()
def _arg(name, env): def _arg(name, env):
"""--name <value> from the command line, else the environment variable.""" """--name <value> from the command line, else the environment variable."""
@@ -150,22 +183,19 @@ def load_ide_catalog():
ROUTES[IDE_ROUTE] = {"url": base + "/responses", "key": anahtar, "flatten_tools": True} ROUTES[IDE_ROUTE] = {"url": base + "/responses", "key": anahtar, "flatten_tools": True}
clone = (CFG.get("nine_router_catalog") or {}).get("clone_from", "gpt-6-astra") clone = (CFG.get("nine_router_catalog") or {}).get("clone_from", "gpt-6-astra")
levels = (CFG.get("nine_router_catalog") or {}).get("reasoning_levels") levels = (CFG.get("nine_router_catalog") or {}).get("reasoning_levels")
# Secicide yalniz "saglayici/model" gorunur. 9Router listesinde ayni adla zaten duran model # Gorunen adlari ayirt et; farkli kimlikteki modeller adlari benziyor diye silinmez.
# ikinci kez eklenmez (ayni modelin iki satir olmamasi icin).
var_olan = {m.get("display_name", "").lower() for m in extra_models} var_olan = {m.get("display_name", "").lower() for m in extra_models}
for g in girdiler: adlar = ide_catalog.adlandir([(g["id"], g["ad"]) for g in girdiler], dolu=var_olan,
slug = IDE_PREFIX + g["id"] turler={g["id"]: g["kind"] for g in girdiler})
g["kisa"] = ide_catalog.kisa_ad(g["ad"])
# "ad (2)": ayni modelin gecitteki ikinci yolu; taban ad listede varsa o da eklenmez.
girdiler = [g for g in girdiler if re.sub(r" \(\d+\)$", "", g["kisa"]).lower() not in var_olan]
adlar = ide_catalog.adlandir([(g["id"], g["ad"]) for g in girdiler], dolu=var_olan)
for g in girdiler: for g in girdiler:
slug = IDE_PREFIX + g["id"] slug = IDE_PREFIX + g["id"]
if slug in model_map: if slug in model_map:
continue continue
extra_models.append({"slug": slug, "display_name": adlar[g["id"]], extra_models.append({"slug": slug, "display_name": adlar[g["id"]],
"description": f"AITURK IDE: {g['ad']}", "route": IDE_ROUTE, "target": g["id"], "description": g.get("aciklama") or f"AITURK IDE: {g['ad']}",
"clone_from": clone, "priority": 300 + n, "reasoning_levels": levels}) "route": IDE_ROUTE, "target": g["id"],
"clone_from": clone, "priority": 300 + n, "reasoning_levels": levels,
"kind": g["kind"]})
model_map[slug] = (IDE_ROUTE, g["id"], None) model_map[slug] = (IDE_ROUTE, g["id"], None)
n += 1 n += 1
else: else:
@@ -398,6 +428,9 @@ class SseRewriter:
inp = args inp = args
d["item"] = {"type": "custom_tool_call", "id": item.get("id"), "call_id": item.get("call_id"), d["item"] = {"type": "custom_tool_call", "id": item.get("id"), "call_id": item.get("call_id"),
"name": item.get("name"), "input": inp, "status": item.get("status", "completed")} "name": item.get("name"), "input": inp, "status": item.get("status", "completed")}
# Normalize before Codex persists the response. Request-only repair
# cannot help when the user later disables the bridge.
fix_tool_ids({"input": [d["item"]]})
return d return d
if t.startswith("response.function_call_arguments.") and d.get("item_id") in self.custom_ids: if t.startswith("response.function_call_arguments.") and d.get("item_id") in self.custom_ids:
return None # JSON parcalari custom input'a cevrilemez; done olayinda tam metin gidiyor return None # JSON parcalari custom input'a cevrilemez; done olayinda tam metin gidiyor
@@ -409,6 +442,7 @@ class SseRewriter:
except Exception: inp = item.get("arguments", "") except Exception: inp = item.get("arguments", "")
item = {"type": "custom_tool_call", "id": item.get("id"), "call_id": item.get("call_id"), item = {"type": "custom_tool_call", "id": item.get("id"), "call_id": item.get("call_id"),
"name": item.get("name"), "input": inp, "status": "completed"} "name": item.get("name"), "input": inp, "status": "completed"}
fix_tool_ids({"input": [item]})
out.append(item) out.append(item)
d["response"]["output"] = out d["response"]["output"] = out
return d return d
@@ -468,10 +502,7 @@ def decompress(body, enc):
if enc == "deflate": if enc == "deflate":
import zlib; return zlib.decompress(body) import zlib; return zlib.decompress(body)
if enc == "zstd": if enc == "zstd":
try: return _zstd_decompress(body)
from compression import zstd as _z; return _z.decompress(body)
except ImportError:
import zstandard; return zstandard.ZstdDecompressor().decompressobj().decompress(body)
if enc == "br": if enc == "br":
import brotli; return brotli.decompress(body) import brotli; return brotli.decompress(body)
return body return body
@@ -533,9 +564,18 @@ class H(http.server.BaseHTTPRequestHandler):
def _control(self, path): def _control(self, path):
"""Local status/stop for AITURK IDE. Loopback only; carries no secrets.""" """Local status/stop for AITURK IDE. Loopback only; carries no secrets."""
if self.command == "POST" and path.rstrip("/").endswith("/refresh"):
# The IDE asks for this after a sign-in or a settings change, so the model
# list does not wait for the next periodic refresh.
try:
load_ide_catalog()
except Exception as e:
log(f"katalog yenileme hatasi: {e}")
path = "/aiturk/codex-baglama/status"
self.command = "GET"
if self.command == "GET" and path.rstrip("/").endswith("/status"): if self.command == "GET" and path.rstrip("/").endswith("/status"):
durum, _, sayi = (IDE_DURUM[0] or "kapali, 0 model").partition(", ") durum, _, sayi = (IDE_DURUM[0] or "kapali, 0 model").partition(", ")
return self._send_json(200, {"ok": True, "surum": SURUM, "ide_durum": durum, return self._send_json(200, {"ok": ZSTD_OK, "surum": SURUM, "zstd": ZSTD_OK, "ide_durum": durum,
"ide_model": int((sayi.split() or ["0"])[0]), "ide_model": int((sayi.split() or ["0"])[0]),
"ozet": bool((CFG.get("ozet_kopru") or {}).get("enabled", False))}) "ozet": bool((CFG.get("ozet_kopru") or {}).get("enabled", False))})
if self.command == "POST" and path.rstrip("/").endswith("/stop"): if self.command == "POST" and path.rstrip("/").endswith("/stop"):
@@ -644,6 +684,40 @@ class H(http.server.BaseHTTPRequestHandler):
log(f"[{n} ozet kopru] OpenAI ozeti duz metne cevrildi ({len(metin)} karakter, onbellege yazildi)") log(f"[{n} ozet kopru] OpenAI ozeti duz metne cevrildi ({len(metin)} karakter, onbellege yazildi)")
return metin or None return metin or None
def _ozet_openai(self, n, path, req, slug, ozet_cfg, girdi_bayt):
"""Kopru modeline (ide/, 9r/) gelen sikistirma isteginin ozetini abonelik modeline yazdirir.
Donus: True = yanit istemciye gitti; False = abonelik istegi baslamadan basarisiz oldu
(istemciye hicbir sey yazilmadi, cagiran hedef modelle devam eder). req cagiranin kopyasidir."""
model = ozet_cfg.get("ozet_modeli", "gpt-6.1-sol")
tag = f"[{n} CHATGPT {model} <- {slug}]"
try:
req["model"] = model
fix_tool_ids(req)
atilan = drop_foreign_items(req)
ozet_kopru.ozetleri_ac(req, yabanci_hedef=False)
ozet_kopru.ozet_istegi_hazirla(req, ozet_cfg.get("istem"))
body = json.dumps(req, ensure_ascii=False).encode("utf-8")
except Exception as e:
log(f"{tag} ozet kopru: abonelik ozeti hazirlanamadi ({type(e).__name__}: {e}), hedef model deneniyor")
return False
hdrs = {k: v for k, v in self.headers.items() if k.lower() not in REQ_HOP and k.lower() != "content-encoding"}
hdrs["Content-Type"] = "application/json"; hdrs["Accept"] = "text/event-stream"
r = urllib.request.Request(CHATGPT + path, data=body, headers=hdrs, method="POST")
try:
resp = urllib.request.urlopen(r, timeout=UPSTREAM_IDLE_TIMEOUT)
except urllib.error.HTTPError as e:
log(f"{tag} ozet kopru: abonelik ozeti reddedildi (HTTP {e.code} {e.read()[:200]!r}), hedef model deneniyor")
return False
except Exception as e:
log(f"{tag} ozet kopru: abonelik ozeti baslatilamadi ({type(e).__name__}), hedef model deneniyor")
return False
log(f"{tag} ozet kopru: sikistirma ozeti abonelik modeline yazdiriliyor (girdi={len(req.get('input', []))} oge, "
f"{girdi_bayt} bayt, {atilan} yabanci oge atildi)")
akis = ozet_kopru.OzetAkisi(None, tohum=str(n), en_az=ozet_kopru.en_az_karakter(girdi_bayt, ozet_cfg))
self._stream(resp, resp.status, tag, akis)
log(f"{tag} ozet kopru: {akis.sonuc_notu()}")
return True
def _models(self, resp, tag): def _models(self, resp, tag):
raw = resp.read() raw = resp.read()
try: try:
@@ -685,6 +759,8 @@ class H(http.server.BaseHTTPRequestHandler):
if not m.get("base_instructions") and not has_tmpl: if not m.get("base_instructions") and not has_tmpl:
m.update(saved) m.update(saved)
models.append(m); changed += 1 models.append(m); changed += 1
if EXTRA_MODELS:
ide_catalog.sirala_codex(models, EXTRA_MODELS)
out = json.dumps(data, ensure_ascii=False).encode("utf-8") out = json.dumps(data, ensure_ascii=False).encode("utf-8")
except Exception as e: except Exception as e:
log(f"{tag} model listesi degistirilemedi: {e}") log(f"{tag} model listesi degistirilemedi: {e}")
@@ -761,8 +837,9 @@ class H(http.server.BaseHTTPRequestHandler):
log(f"[{n} CHATGPT {slug}] ozet kopru: DONGU FRENI, ozet istegi reddedildi") log(f"[{n} CHATGPT {slug}] ozet kopru: DONGU FRENI, ozet istegi reddedildi")
return self._send_json(400, {"error": {"message": ozet_kopru.DONGU_MESAJI % OZET_FRENI.sinir, return self._send_json(400, {"error": {"message": ozet_kopru.DONGU_MESAJI % OZET_FRENI.sinir,
"type": "invalid_request_error", "code": "astrabridge_ozet_dongusu"}}) "type": "invalid_request_error", "code": "astrabridge_ozet_dongusu"}})
girdi_bayt = len(json.dumps(req.get("input") or [], ensure_ascii=False).encode("utf-8"))
ozet_kopru.ozet_istegi_hazirla(req, ozet_cfg.get("istem")) ozet_kopru.ozet_istegi_hazirla(req, ozet_cfg.get("istem"))
ozet_akisi = ozet_kopru.OzetAkisi(None, tohum=str(n)) ozet_akisi = ozet_kopru.OzetAkisi(None, tohum=str(n), en_az=ozet_kopru.en_az_karakter(girdi_bayt, ozet_cfg))
ob["acilan"] += 1 ob["acilan"] += 1
log(f"[{n} CHATGPT {slug}] ozet kopru: sikistirma istegi duz metin ozet istegine cevrildi (girdi={len(req.get('input', []))} oge)") log(f"[{n} CHATGPT {slug}] ozet kopru: sikistirma istegi duz metin ozet istegine cevrildi (girdi={len(req.get('input', []))} oge)")
except Exception as e: except Exception as e:
@@ -780,7 +857,7 @@ class H(http.server.BaseHTTPRequestHandler):
if parcalar: log(f"[{n} CHATGPT {slug}] " + ", ".join(parcalar)) if parcalar: log(f"[{n} CHATGPT {slug}] " + ", ".join(parcalar))
if ozet_akisi is not None: if ozet_akisi is not None:
sonuc = self._passthrough(n, path, body, tagname=f"CHATGPT {slug}", rewritten=True, rewriter=ozet_akisi) sonuc = self._passthrough(n, path, body, tagname=f"CHATGPT {slug}", rewritten=True, rewriter=ozet_akisi)
log(f"[{n} CHATGPT {slug}] ozet kopru: ozet {'uretildi, ' + str(len(ozet_akisi.metin)) + ' karakter' if ozet_akisi.metin else 'URETILEMEDI'}") log(f"[{n} CHATGPT {slug}] ozet kopru: {ozet_akisi.sonuc_notu()}")
return sonuc return sonuc
return self._passthrough(n, path, body, tagname=f"CHATGPT {slug}", return self._passthrough(n, path, body, tagname=f"CHATGPT {slug}",
rewritten=bool(fixed or atilan or degisti)) rewritten=bool(fixed or atilan or degisti))
@@ -790,11 +867,25 @@ class H(http.server.BaseHTTPRequestHandler):
except Exception as e: except Exception as e:
ozet_tetik = False; ozet_acik = False ozet_tetik = False; ozet_acik = False
log(f"[{n} {slug}] ozet kopru atlandi: {type(e).__name__}: {e}") log(f"[{n} {slug}] ozet kopru atlandi: {type(e).__name__}: {e}")
girdi_bayt = 0
if ozet_tetik:
OZET_FRENI.sinir = int(ozet_cfg.get("dongu_siniri", 3)); OZET_FRENI.pencere = int(ozet_cfg.get("dongu_pencere_sn", 600))
if not OZET_FRENI.izin(str(req.get("prompt_cache_key") or slug), time.time()):
log(f"[{n} {slug}] ozet kopru: DONGU FRENI, ozet istegi reddedildi (ayni sohbette {OZET_FRENI.sinir} ozetten sonra)")
return self._send_json(400, {"error": {"message": ozet_kopru.DONGU_MESAJI % OZET_FRENI.sinir,
"type": "invalid_request_error", "code": "astrabridge_ozet_dongusu"}})
girdi_bayt = len(json.dumps(req.get("input") or [], ensure_ascii=False).encode("utf-8"))
if ozet_tetik and ozet_cfg.get("model"): if ozet_tetik and ozet_cfg.get("model"):
# Ozeti baglami alabilen baska bir modele yazdirmak icin (ornegin kucuk hedef kendi basina ozetleyemiyorsa). # Ozeti baglami alabilen baska bir modele yazdirmak icin (ornegin kucuk hedef kendi basina ozetleyemiyorsa).
alt = MODEL_MAP.get(ozet_cfg["model"]) alt = MODEL_MAP.get(ozet_cfg["model"])
if alt: if alt:
route_name, target, flat = alt route_name, target, flat = alt
elif ozet_tetik and ozet_cfg.get("ozetleyen", "openai") == "openai":
# Ozeti secili kopru modeli degil, abonelikteki guclu model yazar (10 Ekim 2026: 1 MB'lik
# sohbeti kucuk bir model 2201 karaktere indirdi ve model degisince hafiza gitti).
# Abonelik istegi baslamadan reddedilirse asagidaki eski yol (hedef model) calisir.
if self._ozet_openai(n, path, copy.deepcopy(req), slug, ozet_cfg, girdi_bayt):
return
# 9Router cevirisinden gecen hedefler (9Router ve AITURK IDE gecidi): ayni istek duzeltmeleri uygulanir. # 9Router cevirisinden gecen hedefler (9Router ve AITURK IDE gecidi): ayni istek duzeltmeleri uygulanir.
via_router = route_name in (catalog.get("route", "9router"), ide_route) via_router = route_name in (catalog.get("route", "9router"), ide_route)
route = ROUTES[route_name] route = ROUTES[route_name]
@@ -808,11 +899,6 @@ class H(http.server.BaseHTTPRequestHandler):
if ob["acilan"] or ob["cozulen"] or ob["okunamayan"]: if ob["acilan"] or ob["cozulen"] or ob["okunamayan"]:
log(f"{tag} ozet kopru: kopru ozeti={ob['acilan']}, OpenAI ozeti duz metne cevrildi={ob['cozulen']}, okunamayan={ob['okunamayan']}") log(f"{tag} ozet kopru: kopru ozeti={ob['acilan']}, OpenAI ozeti duz metne cevrildi={ob['cozulen']}, okunamayan={ob['okunamayan']}")
if ozet_tetik: if ozet_tetik:
OZET_FRENI.sinir = int(ozet_cfg.get("dongu_siniri", 3)); OZET_FRENI.pencere = int(ozet_cfg.get("dongu_pencere_sn", 600))
if not OZET_FRENI.izin(str(req.get("prompt_cache_key") or slug), time.time()):
log(f"{tag} ozet kopru: DONGU FRENI, ozet istegi reddedildi (ayni sohbette {OZET_FRENI.sinir} ozetten sonra)")
return self._send_json(400, {"error": {"message": ozet_kopru.DONGU_MESAJI % OZET_FRENI.sinir,
"type": "invalid_request_error", "code": "astrabridge_ozet_dongusu"}})
ozet_kopru.ozet_istegi_hazirla(req, ozet_cfg.get("istem")) ozet_kopru.ozet_istegi_hazirla(req, ozet_cfg.get("istem"))
log(f"{tag} ozet kopru: sikistirma istegi duz metin ozet istegine cevrildi (girdi={len(req.get('input', []))} oge)") log(f"{tag} ozet kopru: sikistirma istegi duz metin ozet istegine cevrildi (girdi={len(req.get('input', []))} oge)")
rewriter = None rewriter = None
@@ -883,9 +969,9 @@ class H(http.server.BaseHTTPRequestHandler):
time.sleep(min(2 * attempt, 8)); continue time.sleep(min(2 * attempt, 8)); continue
# Headers go to the client from here on: a cut stream is never resent. # Headers go to the client from here on: a cut stream is never resent.
if ozet_tetik: if ozet_tetik:
akis = ozet_kopru.OzetAkisi(rewriter, tohum=str(n)) akis = ozet_kopru.OzetAkisi(rewriter, tohum=str(n), en_az=ozet_kopru.en_az_karakter(girdi_bayt, ozet_cfg))
sonuc = self._stream(resp, resp.status, tag, akis) sonuc = self._stream(resp, resp.status, tag, akis)
log(f"{tag} ozet kopru: ozet {'uretildi, ' + str(len(akis.metin)) + ' karakter' if akis.metin else 'URETILEMEDI'}") log(f"{tag} ozet kopru: {akis.sonuc_notu()}")
return sonuc return sonuc
return self._stream(resp, resp.status, tag, rewriter) return self._stream(resp, resp.status, tag, rewriter)
self._send_json(503, {"error": {"message": f"bridge: hedef ulasilamadi {last}"}}) self._send_json(503, {"error": {"message": f"bridge: hedef ulasilamadi {last}"}})
+202 -19
View File
@@ -6,8 +6,8 @@ anahtar IDE'nin kendi .env dosyasindan her yenilemede okunur, bridge.json'a yazi
Ac/kapat: %LOCALAPPDATA%\\TurkServis\\AITURK-IDE\\codex-baglama.json Ac/kapat: %LOCALAPPDATA%\\TurkServis\\AITURK-IDE\\codex-baglama.json
{"enabled": true, "kapsam": "ide"} {"enabled": true, "kapsam": "ide"}
Dosya yoksa ACIK sayilir (kullanici karari, 9 Ekim 2026: varsayilan acik). Dosya yoksa ACIK sayilir (kullanici karari, 9 Ekim 2026: varsayilan acik).
kapsam "ide" : IDE ayarinda tanimli modeller + adlandirilmis combolar (varsayilan) kapsam "ide" ve "hepsi": gecidin uye katalogundaki OmniRoute sohbet modelleri.
kapsam "hepsi" : gecitteki butun sohbet modelleri (1000+; Codex listesi cok buyur) Yerel config'teki model adlari uye katalogunu sinirlamaz.
""" """
import json, os, re, urllib.request import json, os, re, urllib.request
@@ -84,11 +84,18 @@ def ide_yapilandirma(agent=AGENT):
return base.rstrip("/"), varsayilan, adlar return base.rstrip("/"), varsayilan, adlar
AITURK_EKI = " (AITURK)"
# Gecidin kisa saglayici kodu -> kullanicinin gormek istedigi kod (10 Ekim 2026: "agy/gemini").
_SAGLAYICI_KISA = {"ag": "agy"}
# Saglayici kodu zaten soyledigi icin model adinin basinda tekrar edilmeyen uretici adi ("cc/opus-5-5").
_TEKRAR = ("claude-",)
DUSUNMESIZ = "no-think-"
def kisa_ad(ad): def kisa_ad(ad):
"""Codex secicisinde gorunecek ad: yalniz kullanicinin ekledigi saglayici + model adi """Gecit onekleri ("OmniRoute · ", "9Router · ", "9R · ") ve aradaki saglayici halkalari atilir:
(kullanici istegi, 9 Ekim 2026). "OmniRoute · " / "9Router · " gibi gecit onekleri ve aradaki "nano/qwen/qwen3.8-27b" -> "nano/qwen3.8-27b", "9R · ag/gemini-3.8-flash" -> "ag/gemini-3.8-flash",
saglayici halkalari gosterilmez: "nano/qwen/qwen3.8-27b" -> "nano/qwen3.8-27b", combo adi oldugu gibi kalir. Kullanici karari (10 Ekim 2026): "9R" yazilmaz."""
"OmniRoute · ag/gemini-3.8-flash" -> "ag/gemini-3.8-flash", combo adi oldugu gibi kalir."""
ad = (ad or "").split(" · ")[-1].strip() ad = (ad or "").split(" · ")[-1].strip()
parcalar = [p for p in ad.split("/") if p] parcalar = [p for p in ad.split("/") if p]
if len(parcalar) <= 2: if len(parcalar) <= 2:
@@ -96,10 +103,41 @@ def kisa_ad(ad):
return parcalar[0] + "/" + parcalar[-1] return parcalar[0] + "/" + parcalar[-1]
def adlandir(girdiler, dolu=()): def gorunen_ad(kimlik, ad, tur="model"):
"""Secicide gorunen ad (kullanici karari, 10 Ekim 2026): combo yalniz kendi adiyla; tek model
"saglayici/model" kalibinda, kisa ve surumlu: "9R · cc/claude-opus-5-5" -> "cc/opus-5-5",
"9R · ag/gemini-3.8-flash-high" -> "agy/gemini-3.8-flash-high", "Agnes 2.0 Flash" (agnes-agnes-2.0-flash)
-> "agnes/agnes-2.0-flash", "kurnaz" (bekci-kurnaz) -> "bekci/kurnaz". Dusunmesiz kopya asil
saglayicisiyla gorunur: "no-think/claude-opus-5-5" -> "cc/opus-5-5 (no-think)"."""
yalin = kisa_ad(ad)
if tur == "combo":
return yalin
kim, ek = kimlik or "", ""
if kim.startswith(DUSUNMESIZ):
kim, ek = kim[len(DUSUNMESIZ):], " (no-think)"
if kim.startswith("9router-"):
kim = kim[len("9router-"):]
saglayici, _, model = yalin.partition("/")
if not model or ek:
kod, _, kalan = kim.partition("-")
if not kod or not kalan:
return yalin
saglayici, model = kod, model or kalan
model = model.replace(" ", "-")
for tekrar in _TEKRAR:
if model.lower().startswith(tekrar) and len(model) > len(tekrar):
model = model[len(tekrar):]
return f"{_SAGLAYICI_KISA.get(saglayici.lower(), saglayici)}/{model}{ek}"
def adlandir(girdiler, dolu=(), turler=None):
"""[(kimlik, tam_ad)] -> {kimlik: gorunen_ad}. Kisa adlar cakisirsa aradaki halkalar geri konur; """[(kimlik, tam_ad)] -> {kimlik: gorunen_ad}. Kisa adlar cakisirsa aradaki halkalar geri konur;
yine cakisirsa kimligin sonu eklenir. `dolu`: baska kaynaktan gelen, zaten kullanilan adlar.""" yine cakisirsa kimligin sonu eklenir. `dolu`: baska kaynaktan gelen, zaten kullanilan adlar.
kisa = {k: kisa_ad(a) for k, a in girdiler} `turler` ({kimlik: "combo"|"model"}) verilirse adlar gorunen_ad kuraliyla yazilir."""
if turler is None:
kisa = {k: kisa_ad(a) for k, a in girdiler}
else:
kisa = {k: gorunen_ad(k, a, turler.get(k, "model")) for k, a in girdiler}
tam = {k: (a or "").split(" · ")[-1].strip() for k, a in girdiler} tam = {k: (a or "").split(" · ")[-1].strip() for k, a in girdiler}
sayac = {} sayac = {}
for v in list(kisa.values()) + list(dolu): for v in list(kisa.values()) + list(dolu):
@@ -114,10 +152,10 @@ def adlandir(girdiler, dolu=()):
return sonuc return sonuc
def sec(data, tanimli, kapsam="ide"): def sec(data, tanimli=(), kapsam="ide", turler=None):
"""Gecit katalogundan Codex'e eklenecek girdiler: [{'id','ad'}], sirali ve tekrarsiz. """Gecidin uye katalogundan girdiler: [{'id','ad','kind'}], sirali ve tekrarsiz.
Yalniz sohbet modelleri; resim/ses/video/embedding uretenler eklenmez.""" Yalniz sohbet modelleri; resim/ses/video/embedding uretenler eklenmez."""
tanimli = {a.lower() for a in tanimli if a} turler = turler or {}
secilen, gorulen = [], set() secilen, gorulen = [], set()
for m in data: for m in data:
mid = m.get("id") or "" mid = m.get("id") or ""
@@ -125,14 +163,142 @@ def sec(data, tanimli, kapsam="ide"):
if not mid or mid in gorulen or "chat" not in (ts.get("capabilities") or ["chat"]): if not mid or mid in gorulen or "chat" not in (ts.get("capabilities") or ["chat"]):
continue continue
gorunen = ts.get("display_name") or mid gorunen = ts.get("display_name") or mid
kisa = gorunen.split(" · ")[-1].strip() kind = turler.get(mid) or ts.get("kind") or "model"
combo = "/" not in kisa # saglayici/model bicimi degil: adlandirilmis combo ya da takma ad # Tek uye yolu: 9Router -> OmniRoute -> TurkServis -> Codex.
if kapsam != "hepsi" and not combo and kisa.lower() not in tanimli and mid.lower() not in tanimli: # Dogrudan 9Router satirlari ayni modelin ikinci kopyasi olarak eklenmez.
if ts.get("source") != "omniroute":
continue
# Combo adi biciminden tahmin edilmez; duz adli Agnes/Bekci modelleri de vardir.
if kind == "combo" and mid.lower().startswith("9router-"):
continue continue
gorulen.add(mid) gorulen.add(mid)
secilen.append({"id": mid, "ad": gorunen, "sira": ts.get("order") or 0}) secilen.append({"id": mid, "ad": gorunen, "kind": kind, "sira": ts.get("order") or 0})
secilen.sort(key=lambda s: (s["sira"], s["id"])) secilen.sort(key=lambda s: (s["sira"], s["id"]))
return [{"id": s["id"], "ad": s["ad"]} for s in secilen] # Gecit ayni adin ikinci yoluna "ad (2)" der; birincisi listede yoksa sayac anlamsizdir.
adlar = {s["ad"].split(" · ")[-1].strip().lower() for s in secilen}
for s in secilen:
taban = re.sub(r" \(\d+\)$", "", s["ad"])
if taban != s["ad"] and taban.split(" · ")[-1].strip().lower() not in adlar:
adlar.add(taban.split(" · ")[-1].strip().lower())
s["ad"] = taban
return [{"id": s["id"], "ad": s["ad"], "kind": s["kind"]} for s in secilen]
def sirala_codex(modeller, ekler):
"""Ozgun abonelik modelleri oldugu gibi kalir: sirasi, priority degeri ve adi degismez,
listenin basinda durur. Ek modeller onlarin ARKASINA eklenir: combo A-Z, sonra
saglayici A-Z / model A-Z. Ozgun bir modelle ayni adi tasiyan ek model " (AITURK)"
ekiyle ayirt edilir; secicide ozgunun yerine gecmis gibi gorunmez.
Kimlik ve yetenek alanlari korunur; kayitli model secimine dokunulmaz."""
bilgiler = {m["slug"]: m for m in ekler}
ozgunler = [m for m in modeller if m.get("slug", "") not in bilgiler]
ek_modeller = [m for m in modeller if m.get("slug", "") in bilgiler]
def yalin(ad): # "GPT-6-1-Sol" ile "GPT-6.1-Sol" ayni ad sayilir
return re.sub(r"[^0-9a-z]+", "", (ad or "").casefold())
ozgun_adlar = {yalin(m.get("display_name") or m.get("slug", "")) for m in ozgunler}
def anahtar(m):
slug = m.get("slug", "")
bilgi = bilgiler.get(slug, {})
ad = kisa_ad(m.get("display_name") or slug)
if bilgi.get("kind") == "combo":
return (0, ad.casefold(), "", slug)
if slug.startswith("ide/"):
mid = slug[len("ide/"):]
if mid.startswith("9router-"):
mid = mid[len("9router-"):]
saglayici, _, model = ad.partition("/")
if not model:
saglayici, _, _ = mid.partition("-")
model = ad
else:
saglayici, model = "OpenAI", ad
return (1, saglayici.casefold(), model.casefold(), slug)
ek_modeller.sort(key=anahtar)
taban = max([m.get("priority") or 0 for m in ozgunler], default=-1) + 1
for n, model in enumerate(ek_modeller):
model["priority"] = taban + n
ad = model.get("display_name") or model.get("slug", "")
if yalin(ad) in ozgun_adlar:
model["display_name"] = f"{ad}{AITURK_EKI}"
modeller[:] = ozgunler + ek_modeller
# ---- Secicide model adinin altindaki satir ----
# Telefonda bu satir tek satirdir ve yaklasik 30 karakterde kesilir (kullanici ekran goruntusu,
# 10 Ekim 2026); en ayirt edici bilgi basa yazilir, ad tekrar edilmez.
ACIKLAMA_SINIRI = 30
_AILE = (("opus", "opus"), ("sonnet", "sonnet"), ("haiku", "haiku"), ("astra", "astra"), ("terra", "terra"),
("luna", "luna"), ("sol", "sol"), ("gemini", "gemini"), ("qwen", "qwen"), ("glm", "glm"),
("abliterated", "abliterated"), ("deepseek", "deepseek"), ("llama", "llama"), ("gemma", "gemma"))
_SAGLAYICI = {"cc": "Claude", "cx": "Codex", "ag": "Antigravity", "agy": "Antigravity", "nano": "NanoGPT", "hf": "HuggingFace",
"huggingface": "HuggingFace", "agnes": "Agnes", "bekci": "Bekçi"}
_SANSURSUZ = re.compile(r"uncensored|abliterat|obliterat|derestrict|heretic|unshackled", re.I)
def kisa_model(ad):
""""cc/claude-opus-5-5" -> "opus", "nano/z-ai/glm-5.3-flash-uncensored" -> "glm"; bilinmeyen ad "?"."""
if not ad:
return "?"
son = ad.split("/")[-1].split(":")[0].lower()
parcalar = [p for p in re.split(r"[^a-z]+", son) if p]
for anahtar, kisa in _AILE:
if anahtar in parcalar:
return kisa
return (parcalar[0] if parcalar else son) or "?"
def _yapraklar(dugum, derinlik=0):
"""Sirali (priority) zinciri duz model listesine acar; ic takim kendi uyeleriyle yer alir."""
if not isinstance(dugum, dict) or derinlik > 6:
return ["?"]
if dugum.get("kind") != "combo":
return [kisa_model(dugum.get("model"))]
cikti = []
for uye in dugum.get("members") or []:
cikti.extend(_yapraklar(uye, derinlik + 1))
return cikti or ["?"]
def _sigdir(onek, adlar, ayrac):
"""Sinira sigdigi kadar ad yazar, kalani "+N" ile sayar."""
tekil = [a for i, a in enumerate(adlar) if i == 0 or a != adlar[i - 1]]
for adet in range(len(tekil), 0, -1):
kalan = len(tekil) - adet
metin = onek + ayrac.join(tekil[:adet]) + (f" +{kalan}" if kalan else "")
if len(metin) <= ACIKLAMA_SINIRI or adet == 1:
return metin
return onek.rstrip(": ")
def aciklama(kimlik, ad, tur, kayit=None):
"""Model adinin altinda gorunecek kisa satir. kayit: gecidin /router/catalog girdisi (yoksa None).
Takim -> uyeleri; sirali yedek -> sirasi; tek model -> saglayicisi ve adindan okunan ozellikleri."""
if tur == "combo":
topoloji = (kayit or {}).get("topology") or {}
uyeler = topoloji.get("members") or []
if topoloji.get("strategy") == "round-robin":
return f"Dönüşümlü: {len(uyeler)} üye"
takim = topoloji if topoloji.get("strategy") == "fusion" else None
if takim is None and uyeler and isinstance(uyeler[0], dict) and uyeler[0].get("strategy") == "fusion":
takim = uyeler[0]
if takim is not None:
return _sigdir("Takım: ", [kisa_model(u.get("model")) for u in takim.get("members") or []], "+")
if uyeler:
return _sigdir("Sıralı: ", _yapraklar(topoloji), ">")
return "Takım"
kisa = gorunen_ad(kimlik, ad, "model")
kod = kisa.split("/")[0].lower() if "/" in kisa else (kimlik or "").split("-")[0].lower()
parcalar = [_SAGLAYICI.get(kod, kod) or "Tek model"]
if _SANSURSUZ.search(kisa) or _SANSURSUZ.search(kimlik or ""):
parcalar.append("sansürsüz")
if "thinking" in (kisa + " " + (kimlik or "")).lower():
parcalar.append("düşünen")
if len(parcalar) == 1:
parcalar.insert(0, "Tek model")
return " · ".join(parcalar)[:ACIKLAMA_SINIRI]
def yukle(ua="AstraBridge/1.0 (codex)", timeout=30): def yukle(ua="AstraBridge/1.0 (codex)", timeout=30):
@@ -146,5 +312,22 @@ def yukle(ua="AstraBridge/1.0 (codex)", timeout=30):
return "anahtar-yok", "", "", [] return "anahtar-yok", "", "", []
base, varsayilan, adlar = ide_yapilandirma() base, varsayilan, adlar = ide_yapilandirma()
req = urllib.request.Request(base + "/models", headers={"Authorization": f"Bearer {anahtar}", "User-Agent": ua}) req = urllib.request.Request(base + "/models", headers={"Authorization": f"Bearer {anahtar}", "User-Agent": ua})
data = json.load(urllib.request.urlopen(req, timeout=timeout)).get("data", []) with urllib.request.urlopen(req, timeout=timeout) as resp:
return "tamam", base, anahtar, sec(data, adlar + [varsayilan], ayar["kapsam"]) data = json.load(resp).get("data")
if not isinstance(data, list) or not data:
raise ValueError("Gecit bos veya gecersiz model katalogu dondurdu")
req = urllib.request.Request(base + "/router/catalog", headers={"Authorization": f"Bearer {anahtar}", "User-Agent": ua})
with urllib.request.urlopen(req, timeout=timeout) as resp:
metadata = json.load(resp).get("models")
if not isinstance(metadata, list) or not metadata:
raise ValueError("Gecit model turlerini dondurmedi")
# Bu ucta uye listesinde olmayan ic kayitlar da bulunur. Yalniz tur bilgisi alinir;
# modele erisim listesi her zaman /models yanitidir.
turler = {m["id"]: m["kind"] for m in metadata if m.get("id") and m.get("kind") in ("combo", "model")}
girdiler = sec(data, adlar + [varsayilan], ayar["kapsam"], turler)
if not girdiler:
raise ValueError("Gecitte kullanilabilir OmniRoute sohbet modeli yok")
kayitlar = {m["id"]: m for m in metadata if m.get("id")}
for g in girdiler:
g["aciklama"] = aciklama(g["id"], g["ad"], g["kind"], kayitlar.get(g["id"]))
return "tamam", base, anahtar, girdiler
+34 -1
View File
@@ -45,6 +45,22 @@ OKUNAMADI_NOTU = ("(Kopru notu: Bu noktadan onceki konusma, onceki modelin sifre
"aktarilamadi. Onceki kararlari bilmiyorsan uydurma; kullaniciya sor.)") "aktarilamadi. Onceki kararlari bilmiyorsan uydurma; kullaniciya sor.)")
KISA_MESAJI = ("AstraBridge: Sohbet ozeti cok kisa cikti (%d karakter, en az %d bekleniyordu) ve gecmisin yerine "
"konmadi; mesajlariniz sohbette duruyor. Tekrar deneyin ya da daha guclu bir model secin.")
def en_az_karakter(girdi_bayt, ayar=None):
"""Bu buyuklukteki bir konusmanin ozeti en az kac karakter olmali.
Yalniz bozuk/bos sayilacak kadar kisa ozeti yakalar; ozetin yeterliligini boyuttan cikarmaz.
Olcum (10 Ekim 2026, 646.955 baytlik gunluk + bes olgu): guclu modelin dogru ozeti 1500-1700
karakterdi; boyuta oranli yuksek esik (2587) bu dogru ozeti reddedip sohbeti kilitledi.
Hafiza kaybinin asil onlemi ozeti guclu modele yazdirmaktir (bridge.py _ozet_openai)."""
ayar = ayar or {}
tavan = int(ayar.get("en_az_tavan", 300))
oran = max(1, int(ayar.get("en_az_oran", 2000))) # her 2000 bayt girdi icin 1 karakter
return max(0, min(tavan, int(girdi_bayt) // oran))
def tetik_mi(req): def tetik_mi(req):
"""Istek bir sikistirma istegi mi (girdinin son ogesi compaction_trigger)?""" """Istek bir sikistirma istegi mi (girdinin son ogesi compaction_trigger)?"""
ogeler = req.get("input") ogeler = req.get("input")
@@ -129,9 +145,11 @@ class OzetAkisi:
"""Ozet isteginin SSE yanitini Codex'in bekledigi tek 'compaction' ogesine cevirir. """Ozet isteginin SSE yanitini Codex'in bekledigi tek 'compaction' ogesine cevirir.
ic: once calisan cevirici (SseRewriter). Metin gelmezse compaction ogesi uretmez (Codex hatayi gosterir).""" ic: once calisan cevirici (SseRewriter). Metin gelmezse compaction ogesi uretmez (Codex hatayi gosterir)."""
def __init__(self, ic=None, tohum=""): def __init__(self, ic=None, tohum="", en_az=0):
self.ic = ic self.ic = ic
self.tohum = tohum self.tohum = tohum
self.en_az = en_az # bundan kisa ozet kabul edilmez (bkz. en_az_karakter)
self.kisa = False
self.buf = b"" self.buf = b""
self.parcalar = {} # item_id -> delta metni self.parcalar = {} # item_id -> delta metni
self.bitenler = [] # tamamlanan mesaj metinleri self.bitenler = [] # tamamlanan mesaj metinleri
@@ -171,6 +189,13 @@ class OzetAkisi:
self.bitti = True self.bitti = True
if not self.metin: if not self.metin:
return _olay(d) # ozet yok: Codex "0 compaction ogesi" hatasini gosterir return _olay(d) # ozet yok: Codex "0 compaction ogesi" hatasini gosterir
if len(self.metin) < self.en_az:
# Anormal kisa ozet gecmisin yerine konmaz: Codex hatayi gosterir, sohbet oldugu gibi kalir.
self.kisa = True
yanit = dict(d.get("response") or {})
yanit["status"] = "failed"; yanit["output"] = []
yanit["error"] = {"code": "astrabridge_ozet_kisa", "message": KISA_MESAJI % (len(self.metin), self.en_az)}
return _olay({"type": "response.failed", "response": yanit})
oge = ozet_ogesi(self.metin, self.tohum) oge = ozet_ogesi(self.metin, self.tohum)
yanit = dict(d.get("response") or {}) yanit = dict(d.get("response") or {})
yanit["output"] = [oge] yanit["output"] = [oge]
@@ -180,6 +205,14 @@ class OzetAkisi:
return _olay(d) return _olay(d)
return b"" return b""
def sonuc_notu(self):
"""Gunluk satiri icin sonuc (icerik yazilmaz)."""
if not self.metin:
return "ozet URETILEMEDI"
if self.kisa:
return f"ozet REDDEDILDI: {len(self.metin)} karakter, en az {self.en_az} bekleniyordu; gecmis korunuyor"
return f"ozet uretildi, {len(self.metin)} karakter"
def feed(self, chunk): def feed(self, chunk):
if self.ic: if self.ic:
chunk = self.ic.feed(chunk) chunk = self.ic.feed(chunk)
@@ -2,8 +2,8 @@ import json, os, tempfile, unittest
import ide_catalog as c import ide_catalog as c
def girdi(mid, ad, yetenek=("chat",), sira=0): def girdi(mid, ad, yetenek=("chat",), sira=0, kaynak="omniroute", kind="model"):
return {"id": mid, "turkservis": {"display_name": ad, "capabilities": list(yetenek), "order": sira}} return {"id": mid, "turkservis": {"display_name": ad, "capabilities": list(yetenek), "order": sira, "source": kaynak, "kind": kind}}
KATALOG = [ KATALOG = [
@@ -11,8 +11,8 @@ KATALOG = [
girdi("9router-cc-opus", "OmniRoute · cc/claude-opus-5-5", sira=2), girdi("9router-cc-opus", "OmniRoute · cc/claude-opus-5-5", sira=2),
girdi("9router-nano-x", "OmniRoute · nano/x", sira=1), girdi("9router-nano-x", "OmniRoute · nano/x", sira=1),
girdi("gorsel", "OmniRoute · gpt-image-1", ("image",)), girdi("gorsel", "OmniRoute · gpt-image-1", ("image",)),
girdi("9router-Takim-Agir", "OmniRoute · Takim-Agir", sira=9), girdi("9router-Takim-Agir", "OmniRoute · Takim-Agir", sira=9, kind="combo"),
girdi("9router-Takim-Agir-6e65dba5", "OmniRoute · Takim-Agir", sira=8), girdi("9router-Takim-Agir-6e65dba5", "OmniRoute · Takim-Agir", sira=8, kind="combo"),
girdi("Ajan-Arac", "OmniRoute · Ajan-Arac (tekrar)"), girdi("Ajan-Arac", "OmniRoute · Ajan-Arac (tekrar)"),
] ]
@@ -52,14 +52,39 @@ class Yapilandirma(unittest.TestCase):
class Secim(unittest.TestCase): class Secim(unittest.TestCase):
def test_ide_kapsami(self): def test_ide_kapsami(self):
s = c.sec(KATALOG, ["cc/claude-opus-5-5"], "ide") s = c.sec(KATALOG, ["cc/claude-opus-5-5"], "ide")
# Tanimli model + adlandirilmis combolar; tanimsiz saglayici modeli ve gorsel modeli yok. # Uye katalogu yerel config'teki adlarla sinirlanmaz.
self.assertEqual([x["id"] for x in s], ["9router-cc-opus", "Ajan-Arac", "9router-Takim-Agir-6e65dba5", "9router-Takim-Agir"]) self.assertEqual([x["id"] for x in s], ["9router-nano-x", "9router-cc-opus", "Ajan-Arac"])
def test_9router_combolari_gosterilmez(self):
katalog = [girdi("9router-Takim-Agir-6e65dba5", "Takim-Agir", kaynak="9router", sira=1),
girdi("9router-Takim-Agir", "Takim-Agir (2)", sira=2, kind="combo"),
girdi("Takim-Agir", "Takim-Agir (3)", sira=3),
girdi("Ajan-Arac", "Ajan-Arac", sira=4),
girdi("9router-nano-x", "nano/x", kaynak="9router", sira=5)]
s = c.sec(katalog, ["nano/x"], "ide")
# 9Router combosu ve gecidin 9router saglayicisindaki kopyasi yok; OmniRoute'un kendi combosu
# sayacsiz adiyla kalir. Dogrudan 9Router tekilleri de eklenmez.
self.assertEqual([(x["id"], x["ad"]) for x in s],
[("Takim-Agir", "Takim-Agir"), ("Ajan-Arac", "Ajan-Arac")])
def test_9router_modelleri_yalniz_omniroute_uzerinden_eklenir(self):
katalog = [girdi("9router-nano-x-aaaa1111", "nano/x", kaynak="9router", sira=1),
girdi("9router-nano-x", "nano/x (2)", sira=2),
girdi("9router-ocg-y-bbbb2222", "ocg/y", kaynak="9router", sira=3),
girdi("vag-z", "vag/z", sira=4),
girdi("9router-ses", "nano/ses", ("tts",), kaynak="9router", sira=5),
girdi("9router-Takim-Agir-6e65dba5", "Takim-Agir", kaynak="9router", sira=6)]
s = c.sec(katalog, [], "ide")
# Yerel model tanimi gerekmez; iki kaynak yerine yalniz OmniRoute yolu gelir.
self.assertEqual([(x["id"], x["ad"]) for x in s],
[("9router-nano-x", "nano/x"), ("vag-z", "vag/z")])
def test_gorunen_ad_yalniz_saglayici_ve_model(self): def test_gorunen_ad_yalniz_saglayici_ve_model(self):
for tam, beklenen in [("OmniRoute · ag/gemini-3.8-flash", "ag/gemini-3.8-flash"), for tam, beklenen in [("OmniRoute · ag/gemini-3.8-flash", "ag/gemini-3.8-flash"),
("nano/qwen/qwen3.8-27b-obliterated:thinking", "nano/qwen3.8-27b-obliterated:thinking"), ("nano/qwen/qwen3.8-27b-obliterated:thinking", "nano/qwen3.8-27b-obliterated:thinking"),
("9Router · Nous-Research/inclusionai/ling-3.1-flash", "Nous-Research/ling-3.1-flash"), ("9Router · Nous-Research/inclusionai/ling-3.1-flash", "Nous-Research/ling-3.1-flash"),
("cf/@cf/qwen/qwq-32b", "cf/qwq-32b"), ("cf/@cf/qwen/qwq-32b", "cf/qwq-32b"),
("9R · nano/qwen/qwen3.8-27b", "nano/qwen3.8-27b"), ("9R · ag/gemini", "ag/gemini"),
("OmniRoute · Ajan-Arac", "Ajan-Arac"), ("cc/claude-opus-5-5", "cc/claude-opus-5-5")]: ("OmniRoute · Ajan-Arac", "Ajan-Arac"), ("cc/claude-opus-5-5", "cc/claude-opus-5-5")]:
self.assertEqual(c.kisa_ad(tam), beklenen, tam) self.assertEqual(c.kisa_ad(tam), beklenen, tam)
@@ -74,7 +99,7 @@ class Secim(unittest.TestCase):
def test_hepsi_kapsami_yalniz_sohbet(self): def test_hepsi_kapsami_yalniz_sohbet(self):
s = c.sec(KATALOG, [], "hepsi") s = c.sec(KATALOG, [], "hepsi")
self.assertEqual(len(s), 5) self.assertEqual(len(s), 3) # iki 9Router combosu hicbir kapsamda gosterilmez
self.assertNotIn("gorsel", [x["id"] for x in s]) self.assertNotIn("gorsel", [x["id"] for x in s])
@@ -0,0 +1,141 @@
"""The shipped IDE must use the same public OmniRoute catalog as every member."""
import io
import json
import unittest
from unittest.mock import patch
import ide_catalog as c
def row(mid, name, source="omniroute", capabilities=("chat",)):
return {"id": mid, "turkservis": {"display_name": name, "source": source,
"capabilities": list(capabilities)}}
class MemberCatalog(unittest.TestCase):
def test_metadata_classifies_only_public_models(self):
public = [row("plain", "Plain"), row("team", "Team")]
metadata = [{"id": "plain", "kind": "model"}, {"id": "team", "kind": "combo"},
{"id": "internal", "kind": "combo"}]
replies = [io.BytesIO(json.dumps({"data": public}).encode()),
io.BytesIO(json.dumps({"models": metadata}).encode())]
with patch.object(c, "ayar_oku", return_value={"enabled": True, "kapsam": "ide"}), \
patch.object(c, "anahtar_oku", return_value="test-key"), \
patch.object(c, "ide_yapilandirma", return_value=("https://example.test/v1", "", [])), \
patch.object(c.urllib.request, "urlopen", side_effect=replies):
status, _, _, selected = c.yukle()
self.assertEqual(status, "tamam")
self.assertEqual({m["id"]: m["kind"] for m in selected}, {"plain": "model", "team": "combo"})
def test_empty_catalog_is_a_refresh_failure(self):
with patch.object(c, "ayar_oku", return_value={"enabled": True, "kapsam": "ide"}), \
patch.object(c, "anahtar_oku", return_value="test-key"), \
patch.object(c, "ide_yapilandirma", return_value=("https://example.test/v1", "", [])), \
patch.object(c.urllib.request, "urlopen", return_value=io.BytesIO(b'{"data": []}')):
with self.assertRaises(ValueError):
c.yukle()
def test_public_omniroute_models_do_not_need_private_local_configuration(self):
rows = [row("9router-nano-x", "9R · nano/x"), row("agnes-flat", "Agnes Flat"),
row("Ajan-Arac", "Ajan-Arac"), row("image", "image", capabilities=("image",))]
self.assertEqual({m["id"] for m in c.sec(rows, [])},
{"9router-nano-x", "agnes-flat", "Ajan-Arac"})
def test_direct_route_is_never_added_beside_omniroute(self):
rows = [row("9router-nano-x-direct", "9R · nano/x", "9router"),
row("9router-nano-x", "9R · nano/x")]
self.assertEqual([m["id"] for m in c.sec(rows, ["nano/x"], "hepsi")], ["9router-nano-x"])
def test_model_order_uses_combo_metadata_and_preserves_every_model(self):
models = [{"slug": "gpt-z", "display_name": "GPT Z", "priority": 1},
{"slug": "ide/bekci-kurnaz", "display_name": "kurnaz", "priority": 2},
{"slug": "ide/Z-Team", "display_name": "Z-Team", "priority": 5},
{"slug": "ide/9router-cc-opus", "display_name": "9R · cc/opus", "priority": 3},
{"slug": "ide/A-Team", "display_name": "A-Team", "priority": 4}]
extras = [{"slug": m["slug"], "kind": "combo" if m["slug"].endswith("Team") else "model"}
for m in models if m["slug"].startswith("ide/")]
c.sirala_codex(models, extras)
self.assertEqual([m["slug"] for m in models],
["gpt-z", "ide/A-Team", "ide/Z-Team", "ide/bekci-kurnaz", "ide/9router-cc-opus"])
self.assertEqual([m["priority"] for m in models], [1, 2, 3, 4, 5])
def test_subscription_models_keep_their_own_order_priority_and_name(self):
models = [{"slug": "ide/GPT-6-Astra", "display_name": "GPT-6-Astra", "priority": 3},
{"slug": "gpt-6-astra", "display_name": "GPT-6-Astra", "priority": 2},
{"slug": "ide/A-Team", "display_name": "A-Team", "priority": 0},
{"slug": "gpt-6.1-sol", "display_name": "GPT-6.1-Sol", "priority": 1},
{"slug": "codex-auto-review", "display_name": "Codex Auto Review", "priority": 43}]
models.append({"slug": "ide/GPT-6-1-Sol", "display_name": "GPT-6-1-Sol", "priority": 2})
extras = [{"slug": "ide/GPT-6-Astra", "kind": "combo"}, {"slug": "ide/A-Team", "kind": "combo"},
{"slug": "ide/GPT-6-1-Sol", "kind": "combo"}]
originals = [dict(m) for m in models if not m["slug"].startswith("ide/")]
c.sirala_codex(models, extras)
self.assertEqual([m for m in models if not m["slug"].startswith("ide/")], originals)
self.assertEqual([m["slug"] for m in models],
["gpt-6-astra", "gpt-6.1-sol", "codex-auto-review", "ide/A-Team", "ide/GPT-6-1-Sol",
"ide/GPT-6-Astra"])
self.assertEqual([m["priority"] for m in models[3:]], [44, 45, 46])
self.assertEqual([m["display_name"] for m in models[4:]], ["GPT-6-1-Sol (AITURK)", "GPT-6-Astra (AITURK)"])
def test_description_line_tells_what_the_entry_is_and_fits_a_phone_row(self):
yedek = {"kind": "combo", "model": "Yedek", "strategy": "priority", "members": [
{"kind": "model", "model": "nano/z-ai/glm-5.3-flash-uncensored"},
{"kind": "model", "model": "nano/abliteration-ai/abliterated-model-large-v2"}]}
takim = {"topology": {"kind": "combo", "strategy": "priority", "members": [
{"kind": "combo", "model": "Takim-Hizli", "strategy": "fusion", "members": [
{"kind": "model", "model": "ag/gemini-3.8-flash-high"}, {"kind": "model", "model": "cc/claude-sonnet-5-5"}]},
yedek]}}
self.assertEqual(c.aciklama("Takim-Hizli", "Takim-Hizli", "combo", takim), "Takım: gemini+sonnet")
sirali = {"topology": {"kind": "combo", "strategy": "priority", "members": [
{"kind": "model", "model": "cx/gpt-6-astra"}, {"kind": "model", "model": "cc/claude-opus-5-5"},
{"kind": "model", "model": "cc/claude-sonnet-5-5"}, {"kind": "model", "model": "ag/gemini-3.8-flash-high"}]}}
self.assertEqual(c.aciklama("Ajan-Arac", "Ajan-Arac", "combo", sirali), "Sıralı: astra>opus>sonnet +1")
# An unresolved first member stays visible instead of being hidden behind the fallback.
eksik = {"topology": {"kind": "combo", "strategy": "priority", "members": [{"kind": "combo", "model": None}, yedek]}}
self.assertEqual(c.aciklama("GPT-6-Sol", "GPT-6-Sol", "combo", eksik), "Sıralı: ?>glm>abliterated")
donen = {"topology": {"kind": "combo", "strategy": "round-robin", "members": [yedek, yedek, yedek]}}
self.assertEqual(c.aciklama("Takim-Sira", "Takim-Sira", "combo", donen), "Dönüşümlü: 3 üye")
self.assertEqual(c.aciklama("X", "X", "combo", None), "Takım")
self.assertEqual(c.aciklama("9router-cc-claude-opus-5-5", "9R · cc/claude-opus-5-5", "model"), "Tek model · Claude")
self.assertEqual(c.aciklama("9router-nano-qwen-qwen3.8-27b-uncensored-thinking",
"9R · nano/qwen3.8-27b-uncensored:thinking", "model"),
"NanoGPT · sansürsüz · düşünen")
self.assertEqual(c.aciklama("bekci-kurnaz", "kurnaz", "model"), "Tek model · Bekçi")
# 9Router aliases: cc = Claude Code, cx = OpenAI Codex, ag = Antigravity.
self.assertEqual(c.aciklama("9router-cx-gpt-6-astra", "9R · cx/gpt-6-astra", "model"), "Tek model · Codex")
self.assertEqual(c.aciklama("9router-ag-gemini-3.8-flash-high", "9R · ag/gemini-3.8-flash-high", "model"), "Tek model · Antigravity")
uzun = {"topology": {"kind": "combo", "strategy": "priority", "members": [
{"kind": "model", "model": f"x/model{chr(97 + i) * 9}"} for i in range(8)]}}
self.assertLessEqual(len(c.aciklama("U", "U", "combo", uzun)), c.ACIKLAMA_SINIRI)
for ad in ("Takim-Hizli", "9R · cc/claude-opus-5-5"):
self.assertNotIn(ad, c.aciklama(ad, ad, "combo" if "Takim" in ad else "model", takim))
def test_picker_names_are_combo_name_or_short_provider_slash_model(self):
# User decision, 10 Oct 2026: no "9R" mark; combos by name; single models as provider/model.
rows = [("Takim-Hizli", "Takim-Hizli", "combo"),
("9router-cc-claude-opus-5-5", "9R · cc/claude-opus-5-5", "model"),
("9router-cc-claude-opus-4-8", "9R · cc/claude-opus-4-8", "model"),
("9router-cx-gpt-6-astra", "9R · cx/gpt-6-astra", "model"),
("9router-ag-gemini-3.8-flash-high", "9R · ag/gemini-3.8-flash-high", "model"),
("9router-nano-z-ai-glm-5.3-flash-uncensored", "9R · nano/glm-5.3-flash-uncensored", "model"),
("agnes-agnes-2.0-flash", "Agnes 2.0 Flash", "model"),
("agnes-agnes-2.0-flash-high", "agnes-2.0-flash-high", "model"),
("bekci-bekci", "bekci", "model"), ("bekci-kurnaz", "kurnaz", "model"),
("hf-deepseek-ai-DeepSeek-V3", "hf/DeepSeek V3", "model"),
("no-think-9router-cc-claude-opus-5-5", "no-think/claude-opus-5-5", "model"),
("no-think-9router-ag-claude-opus-4-6-thinking", "no-think/claude-opus-4-6-thinking", "model")]
adlar = c.adlandir([(k, a) for k, a, _ in rows], turler={k: t for k, _, t in rows})
self.assertEqual([adlar[k] for k, _, _ in rows],
["Takim-Hizli", "cc/opus-5-5", "cc/opus-4-8", "cx/gpt-6-astra", "agy/gemini-3.8-flash-high",
"nano/glm-5.3-flash-uncensored", "agnes/agnes-2.0-flash", "agnes/agnes-2.0-flash-high",
"bekci/bekci", "bekci/kurnaz", "hf/DeepSeek-V3", "cc/opus-5-5 (no-think)",
"agy/opus-4-6-thinking (no-think)"])
self.assertFalse([a for a in adlar.values() if "9R" in a])
# Added models sort after the combos by provider then model.
models = [{"slug": "ide/" + k, "display_name": adlar[k], "priority": 0} for k, _, _ in rows]
c.sirala_codex(models, [{"slug": "ide/" + k, "kind": t} for k, _, t in rows])
gorunen = [m["display_name"] for m in models]
self.assertEqual(gorunen[0], "Takim-Hizli")
self.assertEqual(gorunen[1:], sorted(gorunen[1:], key=lambda a: tuple(p.casefold() for p in a.partition("/")[::2])))
if __name__ == "__main__":
unittest.main()
@@ -62,6 +62,27 @@ class ModelSwitch(unittest.TestCase):
self.assertEqual(rewritten["item"]["type"], "custom_tool_call") self.assertEqual(rewritten["item"]["type"], "custom_tool_call")
self.assertEqual(rewritten["item"]["input"], "remember-4827") self.assertEqual(rewritten["item"]["input"], "remember-4827")
self.assertEqual(rewritten["item"]["call_id"], "call_4827") self.assertEqual(rewritten["item"]["call_id"], "call_4827")
self.assertEqual(rewritten["item"]["id"], "ctc_chatcmpl-probe")
def test_custom_stream_ids_are_valid_before_history_is_saved(self):
# Real failure after disabling the bridge and returning to OpenAI:
# input[32].id fc_call_... was saved as a custom_tool_call by Codex.
item = {"type": "function_call", "id": "fc_call_3f427ecc539d4c779c1252077701216f",
"call_id": "call_original", "name": "probe",
"arguments": json.dumps({"input": "keep this exact tool input"})}
adapter = env["SseRewriter"]({"probe"})
converted = []
for kind in ("response.output_item.added", "response.output_item.done"):
converted.append(adapter._fix({"type": kind, "item": dict(item)})["item"])
final = adapter._fix({"type": "response.completed", "response": {"output": [dict(item)]}})
converted.append(final["response"]["output"][0])
for result in converted:
self.assertEqual(result["type"], "custom_tool_call")
self.assertEqual(result["id"], "ctc_call_3f427ecc539d4c779c1252077701216f")
self.assertEqual(result["call_id"], "call_original")
self.assertEqual(result["input"], "keep this exact tool input")
history = {"input": converted}
self.assertEqual(env["fix_tool_ids"](history), 0)
if __name__ == "__main__": if __name__ == "__main__":
@@ -109,6 +109,35 @@ class Akis(unittest.TestCase):
a = o.OzetAkisi() a = o.OzetAkisi()
self.assertEqual(o.ozet_metni(coz(a.feed(ham))[1]["item"]), "ozet metni") self.assertEqual(o.ozet_metni(coz(a.feed(ham))[1]["item"]), "ozet metni")
def test_anormal_kisa_ozet_gecmisin_yerine_konmaz(self):
# Esik yalniz bozuk sayilacak kadar kisa ozeti yakalar. 10 Ekim 2026 olcumu: 646.955 baytlik
# sohbetin dogru ozeti 1501-1701 karakterdi ve boyuta oranli eski esik onu reddedip sohbeti kilitledi.
self.assertEqual(o.en_az_karakter(1018151), 300)
self.assertEqual(o.en_az_karakter(646955), 300)
self.assertEqual(o.en_az_karakter(100000), 50)
self.assertEqual(o.en_az_karakter(0), 0)
self.assertEqual(o.en_az_karakter(1018151, {"en_az_tavan": 1500, "en_az_oran": 250}), 1500)
for gercek_ozet in (1501, 1648, 1701):
self.assertGreater(gercek_ozet, o.en_az_karakter(646955))
ham = sse({"type": "response.created", "response": {"id": "r1"}},
{"type": "response.output_item.done", "item": self._mesaj("k" * 120)},
{"type": "response.completed", "response": {"id": "r1", "status": "completed"}})
a = o.OzetAkisi(tohum="7", en_az=o.en_az_karakter(1018151))
olaylar = coz(a.feed(ham) + a.flush())
self.assertEqual([e["type"] for e in olaylar], ["response.created", "response.failed"])
self.assertNotIn("compaction", json.dumps(olaylar))
self.assertEqual(olaylar[1]["response"]["error"]["code"], "astrabridge_ozet_kisa")
self.assertTrue(a.kisa)
self.assertIn("REDDEDILDI", a.sonuc_notu())
# Yeterli uzunlukta ozet ayni esikle kabul edilir; kucuk sohbetin kisa ozeti de reddedilmez.
for metin, esik in (("u" * 1501, o.en_az_karakter(646955)), ("kisa ama dogru ozet", o.en_az_karakter(3000))):
b = o.OzetAkisi(tohum="8", en_az=esik)
ham2 = sse({"type": "response.output_item.done", "item": self._mesaj(metin)},
{"type": "response.completed", "response": {"id": "r2"}})
cikti = coz(b.feed(ham2))
self.assertEqual(o.ozet_metni(cikti[0]["item"]), metin)
self.assertFalse(b.kisa)
def test_metin_yoksa_compaction_uretilmez_hata_gorunur(self): def test_metin_yoksa_compaction_uretilmez_hata_gorunur(self):
ham = sse({"type": "response.created", "response": {}}, ham = sse({"type": "response.created", "response": {}},
{"type": "response.output_item.done", "item": {"type": "function_call", "name": "x"}}, {"type": "response.output_item.done", "item": {"type": "function_call", "name": "x"}},
@@ -0,0 +1,35 @@
"""Codex compresses request bodies with zstd; the bridge must be able to read them."""
import ast
import unittest
from pathlib import Path
tree = ast.parse(Path(__file__).with_name("bridge.py").read_text(encoding="utf-8"))
wanted = {"_zstd_decompress", "_zstd_ready", "decompress"}
env = {}
exec(compile(ast.Module(body=[n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name in wanted],
type_ignores=[]), "bridge.py", "exec"), env)
class Zstd(unittest.TestCase):
def test_self_check_matches_reality(self):
try:
try:
from compression import zstd as z
packed = z.compress(b"govde" * 50)
except ImportError:
import zstandard
packed = zstandard.ZstdCompressor().compress(b"govde" * 50)
except ImportError:
self.assertFalse(env["_zstd_ready"]()) # no zstd here: the bridge must say so
return
self.assertTrue(env["_zstd_ready"]())
self.assertEqual(env["decompress"](packed, "zstd"), b"govde" * 50)
def test_other_encodings(self):
import gzip
self.assertEqual(env["decompress"](gzip.compress(b"x"), "gzip"), b"x")
self.assertEqual(env["decompress"](b"duz", None), b"duz")
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,27 @@
Copyright (c) 2016, Gregory Szorc
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,217 @@
# Copyright (c) 2017-present, Gregory Szorc
# All rights reserved.
#
# This software may be modified and distributed under the terms
# of the BSD license. See the LICENSE file for details.
# ruff: noqa: F403, F405
"""Python interface to the Zstandard (zstd) compression library."""
from __future__ import absolute_import, unicode_literals
# This module serves 2 roles:
#
# 1) Export the C or CFFI "backend" through a central module.
# 2) Implement additional functionality built on top of C or CFFI backend.
import builtins
import io
import os
import platform
import sys
if sys.version_info >= (3, 12):
from collections.abc import Buffer
else:
from typing import ByteString as Buffer
# Some Python implementations don't support C extensions. That's why we have
# a CFFI implementation in the first place. The code here import one of our
# "backends" then re-exports the symbols from this module. For convenience,
# we support falling back to the CFFI backend if the C extension can't be
# imported. But for performance reasons, we only do this on unknown Python
# implementation. Notably, for CPython we require the C extension by default.
# Because someone will inevitably want special behavior, the behavior is
# configurable via an environment variable. A potentially better way to handle
# this is to import a special ``__importpolicy__`` module or something
# defining a variable and `setup.py` could write the file with whatever
# policy was specified at build time. Until someone needs it, we go with
# the hacky but simple environment variable approach.
_module_policy = os.environ.get(
"PYTHON_ZSTANDARD_IMPORT_POLICY", "default"
).strip()
if _module_policy == "default":
if platform.python_implementation() in ("CPython",):
from .backend_c import * # type: ignore
backend = "cext"
elif platform.python_implementation() in ("PyPy",):
from .backend_cffi import * # type: ignore
backend = "cffi"
else:
try:
from .backend_c import *
backend = "cext"
except ImportError:
from .backend_cffi import *
backend = "cffi"
elif _module_policy == "cffi_fallback":
try:
from .backend_c import *
backend = "cext"
except ImportError:
from .backend_cffi import *
backend = "cffi"
elif _module_policy == "rust":
from .backend_rust import * # type: ignore
backend = "rust"
elif _module_policy == "cext":
from .backend_c import *
backend = "cext"
elif _module_policy == "cffi":
from .backend_cffi import *
backend = "cffi"
else:
raise ImportError(
"unknown module import policy: %s; use default, cffi_fallback, "
"cext, or cffi" % _module_policy
)
# Keep this in sync with python-zstandard.h, rust-ext/src/lib.rs, and debian/changelog.
__version__ = "0.25.0"
_MODE_CLOSED = 0
_MODE_READ = 1
_MODE_WRITE = 2
def open(
filename,
mode="rb",
cctx=None,
dctx=None,
encoding=None,
errors=None,
newline=None,
closefd=None,
):
"""Create a file object with zstd (de)compression.
The object returned from this function will be a
:py:class:`ZstdDecompressionReader` if opened for reading in binary mode,
a :py:class:`ZstdCompressionWriter` if opened for writing in binary mode,
or an ``io.TextIOWrapper`` if opened for reading or writing in text mode.
:param filename:
``bytes``, ``str``, or ``os.PathLike`` defining a file to open or a
file object (with a ``read()`` or ``write()`` method).
:param mode:
``str`` File open mode. Accepts any of the open modes recognized by
``open()``.
:param cctx:
``ZstdCompressor`` to use for compression. If not specified and file
is opened for writing, the default ``ZstdCompressor`` will be used.
:param dctx:
``ZstdDecompressor`` to use for decompression. If not specified and file
is opened for reading, the default ``ZstdDecompressor`` will be used.
:param encoding:
``str`` that defines text encoding to use when file is opened in text
mode.
:param errors:
``str`` defining text encoding error handling mode.
:param newline:
``str`` defining newline to use in text mode.
:param closefd:
``bool`` whether to close the file when the returned object is closed.
Only used if a file object is passed. If a filename is specified, the
opened file is always closed when the returned object is closed.
"""
normalized_mode = mode.replace("t", "")
if normalized_mode in ("r", "rb"):
dctx = dctx or ZstdDecompressor()
open_mode = "r"
raw_open_mode = "rb"
elif normalized_mode in ("w", "wb", "a", "ab", "x", "xb"):
cctx = cctx or ZstdCompressor()
open_mode = "w"
raw_open_mode = normalized_mode
if not raw_open_mode.endswith("b"):
raw_open_mode = raw_open_mode + "b"
else:
raise ValueError("Invalid mode: {!r}".format(mode))
if hasattr(os, "PathLike"):
types = (str, bytes, os.PathLike)
else:
types = (str, bytes)
if isinstance(filename, types): # type: ignore
inner_fh = builtins.open(filename, raw_open_mode)
closefd = True
elif hasattr(filename, "read") or hasattr(filename, "write"):
inner_fh = filename
closefd = bool(closefd)
else:
raise TypeError(
"filename must be a str, bytes, file or PathLike object"
)
if open_mode == "r":
fh = dctx.stream_reader(inner_fh, closefd=closefd)
elif open_mode == "w":
fh = cctx.stream_writer(inner_fh, closefd=closefd)
else:
raise RuntimeError("logic error in zstandard.open() handling open mode")
if "b" not in normalized_mode:
return io.TextIOWrapper(
fh, encoding=encoding, errors=errors, newline=newline
)
else:
return fh
def compress(data: Buffer, level: int = 3) -> bytes:
"""Compress source data using the zstd compression format.
This performs one-shot compression using basic/default compression
settings.
This method is provided for convenience and is equivalent to calling
``ZstdCompressor(level=level).compress(data)``.
If you find yourself calling this function in a tight loop,
performance will be greater if you construct a single ``ZstdCompressor``
and repeatedly call ``compress()`` on it.
"""
cctx = ZstdCompressor(level=level)
return cctx.compress(data)
def decompress(data: Buffer, max_output_size: int = 0) -> bytes:
"""Decompress a zstd frame into its original data.
This performs one-shot decompression using basic/default compression
settings.
This method is provided for convenience and is equivalent to calling
``ZstdDecompressor().decompress(data, max_output_size=max_output_size)``.
If you find yourself calling this function in a tight loop, performance
will be greater if you construct a single ``ZstdDecompressor`` and
repeatedly call ``decompress()`` on it.
"""
dctx = ZstdDecompressor()
return dctx.decompress(data, max_output_size=max_output_size)
@@ -0,0 +1,481 @@
# Copyright (c) 2016-present, Gregory Szorc
# All rights reserved.
#
# This software may be modified and distributed under the terms
# of the BSD license. See the LICENSE file for details.
import os
from typing import (
IO,
BinaryIO,
ByteString,
Generator,
Iterable,
List,
Optional,
Set,
Tuple,
Union,
)
FLUSH_BLOCK: int
FLUSH_FRAME: int
COMPRESSOBJ_FLUSH_FINISH: int
COMPRESSOBJ_FLUSH_BLOCK: int
CONTENTSIZE_UNKNOWN: int
CONTENTSIZE_ERROR: int
MAX_COMPRESSION_LEVEL: int
COMPRESSION_RECOMMENDED_INPUT_SIZE: int
COMPRESSION_RECOMMENDED_OUTPUT_SIZE: int
DECOMPRESSION_RECOMMENDED_INPUT_SIZE: int
DECOMPRESSION_RECOMMENDED_OUTPUT_SIZE: int
BLOCKSIZELOG_MAX: int
BLOCKSIZE_MAX: int
WINDOWLOG_MIN: int
WINDOWLOG_MAX: int
CHAINLOG_MIN: int
CHAINLOG_MAX: int
HASHLOG_MIN: int
HASHLOG_MAX: int
MINMATCH_MIN: int
MINMATCH_MAX: int
SEARCHLOG_MIN: int
SEARCHLOG_MAX: int
SEARCHLENGTH_MIN: int
SEARCHLENGTH_MAX: int
TARGETLENGTH_MIN: int
TARGETLENGTH_MAX: int
LDM_MINMATCH_MIN: int
LDM_MINMATCH_MAX: int
LDM_BUCKETSIZELOG_MAX: int
STRATEGY_FAST: int
STRATEGY_DFAST: int
STRATEGY_GREEDY: int
STRATEGY_LAZY: int
STRATEGY_LAZY2: int
STRATEGY_BTLAZY2: int
STRATEGY_BTOPT: int
STRATEGY_BTULTRA: int
STRATEGY_BTULTRA2: int
DICT_TYPE_AUTO: int
DICT_TYPE_RAWCONTENT: int
DICT_TYPE_FULLDICT: int
FORMAT_ZSTD1: int
FORMAT_ZSTD1_MAGICLESS: int
ZSTD_VERSION: Tuple[int, int, int]
FRAME_HEADER: bytes
MAGIC_NUMBER: int
backend: str
backend_features: Set[str]
__version__: str
class ZstdError(Exception): ...
class BufferSegment(object):
offset: int
def __len__(self) -> int: ...
def tobytes(self) -> bytes: ...
class BufferSegments(object):
def __len__(self) -> int: ...
def __getitem__(self, i: int) -> BufferSegment: ...
class BufferWithSegments(object):
size: int
def __init__(self, data: ByteString, segments: ByteString): ...
def __len__(self) -> int: ...
def __getitem__(self, i: int) -> BufferSegment: ...
def segments(self): ...
def tobytes(self) -> bytes: ...
class BufferWithSegmentsCollection(object):
def __init__(self, *args): ...
def __len__(self) -> int: ...
def __getitem__(self, i: int) -> BufferSegment: ...
def size(self) -> int: ...
class ZstdCompressionParameters(object):
@staticmethod
def from_level(
level: int, source_size: int = ..., dict_size: int = ..., **kwargs
) -> "ZstdCompressionParameters": ...
def __init__(
self,
format: int = ...,
compression_level: int = ...,
window_log: int = ...,
hash_log: int = ...,
chain_log: int = ...,
search_log: int = ...,
min_match: int = ...,
target_length: int = ...,
strategy: int = ...,
write_content_size: int = ...,
write_checksum: int = ...,
write_dict_id: int = ...,
job_size: int = ...,
overlap_log: int = ...,
force_max_window: int = ...,
enable_ldm: int = ...,
ldm_hash_log: int = ...,
ldm_min_match: int = ...,
ldm_bucket_size_log: int = ...,
ldm_hash_rate_log: int = ...,
threads: int = ...,
): ...
@property
def format(self) -> int: ...
@property
def compression_level(self) -> int: ...
@property
def window_log(self) -> int: ...
@property
def hash_log(self) -> int: ...
@property
def chain_log(self) -> int: ...
@property
def search_log(self) -> int: ...
@property
def min_match(self) -> int: ...
@property
def target_length(self) -> int: ...
@property
def strategy(self) -> int: ...
@property
def write_content_size(self) -> int: ...
@property
def write_checksum(self) -> int: ...
@property
def write_dict_id(self) -> int: ...
@property
def job_size(self) -> int: ...
@property
def overlap_log(self) -> int: ...
@property
def force_max_window(self) -> int: ...
@property
def enable_ldm(self) -> int: ...
@property
def ldm_hash_log(self) -> int: ...
@property
def ldm_min_match(self) -> int: ...
@property
def ldm_bucket_size_log(self) -> int: ...
@property
def ldm_hash_rate_log(self) -> int: ...
@property
def threads(self) -> int: ...
def estimated_compression_context_size(self) -> int: ...
class CompressionParameters(ZstdCompressionParameters): ...
class ZstdCompressionDict(object):
k: int
d: int
def __init__(
self,
data: ByteString,
dict_type: int = ...,
k: int = ...,
d: int = ...,
): ...
def __len__(self) -> int: ...
def dict_id(self) -> int: ...
def as_bytes(self) -> bytes: ...
def precompute_compress(
self,
level: int = ...,
compression_params: ZstdCompressionParameters = ...,
): ...
class ZstdCompressionObj(object):
def compress(self, data: ByteString) -> bytes: ...
def flush(self, flush_mode: int = ...) -> bytes: ...
class ZstdCompressionChunker(object):
def compress(self, data: ByteString): ...
def flush(self): ...
def finish(self): ...
class ZstdCompressionReader(BinaryIO):
def __enter__(self) -> "ZstdCompressionReader": ...
def __exit__(self, exc_type, exc_value, exc_tb): ...
def readable(self) -> bool: ...
def writable(self) -> bool: ...
def seekable(self) -> bool: ...
def readline(self, limit: int = ...) -> bytes: ...
def readlines(self, hint: int = ...) -> List[bytes]: ...
def write(self, data: ByteString): ...
def writelines(self, data: Iterable[bytes]): ...
def isatty(self) -> bool: ...
def flush(self): ...
def close(self): ...
@property
def closed(self) -> bool: ...
def tell(self) -> int: ...
def readall(self) -> bytes: ...
def __iter__(self): ...
def __next__(self): ...
def next(self): ...
def read(self, size: int = ...) -> bytes: ...
def read1(self, size: int = ...) -> bytes: ...
def readinto(self, b) -> int: ...
def readinto1(self, b) -> int: ...
class ZstdCompressionWriter(BinaryIO):
def __enter__(self) -> "ZstdCompressionWriter": ...
def __exit__(self, exc_type, exc_value, exc_tb): ...
def memory_size(self) -> int: ...
def fileno(self) -> int: ...
def close(self): ...
@property
def closed(self) -> bool: ...
def isatty(self) -> bool: ...
def readable(self) -> bool: ...
def readline(self, size: int = ...) -> bytes: ...
def readlines(self, hint: int = ...) -> List[bytes]: ...
def seek(self, offset: int, whence: int = ...): ...
def seekable(self) -> bool: ...
def truncate(self, size: int = ...): ...
def writable(self) -> bool: ...
def writelines(self, lines: Iterable[bytes]): ...
def read(self, size: int = ...) -> bytes: ...
def readall(self) -> bytes: ...
def readinto(self, b): ...
def write(self, data: ByteString) -> int: ...
def flush(self, flush_mode: int = ...) -> int: ...
def tell(self) -> int: ...
class ZstdCompressor(object):
def __init__(
self,
level: int = ...,
dict_data: Optional[ZstdCompressionDict] = ...,
compression_params: Optional[ZstdCompressionParameters] = ...,
write_checksum: Optional[bool] = ...,
write_content_size: Optional[bool] = ...,
write_dict_id: Optional[bool] = ...,
threads: int = ...,
): ...
def memory_size(self) -> int: ...
def compress(self, data: ByteString) -> bytes: ...
def compressobj(self, size: int = ...) -> ZstdCompressionObj: ...
def chunker(
self, size: int = ..., chunk_size: int = ...
) -> ZstdCompressionChunker: ...
def copy_stream(
self,
ifh: IO[bytes],
ofh: IO[bytes],
size: int = ...,
read_size: int = ...,
write_size: int = ...,
) -> Tuple[int, int]: ...
def stream_reader(
self,
source: Union[IO[bytes], ByteString],
size: int = ...,
read_size: int = ...,
*,
closefd: bool = ...,
) -> ZstdCompressionReader: ...
def stream_writer(
self,
writer: IO[bytes],
size: int = ...,
write_size: int = ...,
write_return_read: bool = ...,
*,
closefd: bool = ...,
) -> ZstdCompressionWriter: ...
def read_to_iter(
self,
reader: Union[IO[bytes], ByteString],
size: int = ...,
read_size: int = ...,
write_size: int = ...,
) -> Generator[bytes, None, None]: ...
def frame_progression(self) -> Tuple[int, int, int]: ...
def multi_compress_to_buffer(
self,
data: Union[
BufferWithSegments,
BufferWithSegmentsCollection,
List[ByteString],
],
threads: int = ...,
) -> BufferWithSegmentsCollection: ...
class ZstdDecompressionObj(object):
def decompress(self, data: ByteString) -> bytes: ...
def flush(self, length: int = ...) -> bytes: ...
@property
def unused_data(self) -> bytes: ...
@property
def unconsumed_tail(self) -> bytes: ...
@property
def eof(self) -> bool: ...
class ZstdDecompressionReader(BinaryIO):
def __enter__(self) -> "ZstdDecompressionReader": ...
def __exit__(self, exc_type, exc_value, exc_tb): ...
def readable(self) -> bool: ...
def writable(self) -> bool: ...
def seekable(self) -> bool: ...
def readline(self, size: int = ...): ...
def readlines(self, hint: int = ...): ...
def write(self, data: ByteString): ...
def writelines(self, lines: Iterable[bytes]): ...
def isatty(self) -> bool: ...
def flush(self): ...
def close(self): ...
@property
def closed(self) -> bool: ...
def tell(self) -> int: ...
def readall(self) -> bytes: ...
def __iter__(self): ...
def __next__(self): ...
def next(self): ...
def read(self, size: int = ...) -> bytes: ...
def readinto(self, b) -> int: ...
def read1(self, size: int = ...) -> bytes: ...
def readinto1(self, b) -> int: ...
def seek(self, pos: int, whence: int = ...) -> int: ...
class ZstdDecompressionWriter(BinaryIO):
def __enter__(self) -> "ZstdDecompressionWriter": ...
def __exit__(self, exc_type, exc_value, exc_tb): ...
def memory_size(self) -> int: ...
def close(self): ...
@property
def closed(self) -> bool: ...
def fileno(self) -> int: ...
def flush(self): ...
def isatty(self) -> bool: ...
def readable(self) -> bool: ...
def readline(self, size: int = ...): ...
def readlines(self, hint: int = ...): ...
def seek(self, offset: int, whence: int = ...): ...
def seekable(self) -> bool: ...
def tell(self): ...
def truncate(self, size: int = ...): ...
def writable(self) -> bool: ...
def writelines(self, lines: Iterable[bytes]): ...
def read(self, size: int = ...): ...
def readall(self): ...
def readinto(self, b): ...
def write(self, data: ByteString) -> int: ...
class ZstdDecompressor(object):
def __init__(
self,
dict_data: Optional[ZstdCompressionDict] = ...,
max_window_size: int = ...,
format: int = ...,
): ...
def memory_size(self) -> int: ...
def decompress(
self,
data: ByteString,
max_output_size: int = ...,
read_across_frames: bool = ...,
allow_extra_data: bool = ...,
) -> bytes: ...
def stream_reader(
self,
source: Union[IO[bytes], ByteString],
read_size: int = ...,
read_across_frames: bool = ...,
*,
closefd=False,
) -> ZstdDecompressionReader: ...
def decompressobj(
self, write_size: int = ..., read_across_frames: bool = False
) -> ZstdDecompressionObj: ...
def read_to_iter(
self,
reader: Union[IO[bytes], ByteString],
read_size: int = ...,
write_size: int = ...,
skip_bytes: int = ...,
) -> Generator[bytes, None, None]: ...
def stream_writer(
self,
writer: IO[bytes],
write_size: int = ...,
write_return_read: bool = ...,
*,
closefd: bool = ...,
) -> ZstdDecompressionWriter: ...
def copy_stream(
self,
ifh: IO[bytes],
ofh: IO[bytes],
read_size: int = ...,
write_size: int = ...,
) -> Tuple[int, int]: ...
def decompress_content_dict_chain(
self, frames: list[ByteString]
) -> bytes: ...
def multi_decompress_to_buffer(
self,
frames: Union[
BufferWithSegments,
BufferWithSegmentsCollection,
List[ByteString],
],
decompressed_sizes: ByteString = ...,
threads: int = ...,
) -> BufferWithSegmentsCollection: ...
class FrameParameters(object):
content_size: int
window_size: int
dict_id: int
has_checksum: bool
def estimate_decompression_context_size() -> int: ...
def frame_content_size(data: ByteString) -> int: ...
def frame_header_size(data: ByteString) -> int: ...
def get_frame_parameters(
data: ByteString, format: Optional[int] = None
) -> FrameParameters: ...
def train_dictionary(
dict_size: int,
samples: list[ByteString],
k: int = ...,
d: int = ...,
f: int = ...,
split_point: float = ...,
accel: int = ...,
notifications: int = ...,
dict_id: int = ...,
level: int = ...,
steps: int = ...,
threads: int = ...,
) -> ZstdCompressionDict: ...
def open(
filename: Union[bytes, str, os.PathLike, BinaryIO],
mode: str = ...,
cctx: Optional[ZstdCompressor] = ...,
dctx: Optional[ZstdDecompressor] = ...,
encoding: Optional[str] = ...,
errors: Optional[str] = ...,
newline: Optional[str] = ...,
closefd: bool = ...,
): ...
def compress(data: ByteString, level: int = ...) -> bytes: ...
def decompress(data: ByteString, max_output_size: int = ...) -> bytes: ...
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -21,15 +21,15 @@ export const CODEX_LINK_PORT = 8795
export const CODEX_LINK_ORIGIN = `http://127.0.0.1:${CODEX_LINK_PORT}` export const CODEX_LINK_ORIGIN = `http://127.0.0.1:${CODEX_LINK_PORT}`
export const CODEX_LINK_STATUS_URL = `${CODEX_LINK_ORIGIN}/aiturk/codex-baglama/status` export const CODEX_LINK_STATUS_URL = `${CODEX_LINK_ORIGIN}/aiturk/codex-baglama/status`
export const CODEX_LINK_STOP_URL = `${CODEX_LINK_ORIGIN}/aiturk/codex-baglama/stop` export const CODEX_LINK_STOP_URL = `${CODEX_LINK_ORIGIN}/aiturk/codex-baglama/stop`
export const CODEX_LINK_REFRESH_URL = `${CODEX_LINK_ORIGIN}/aiturk/codex-baglama/refresh`
/** The trailing comment that marks the line as ours. */ /** The trailing comment that marks the line as ours. */
export const CODEX_LINK_MARKER = '# AITURK IDE Codex Baglama' export const CODEX_LINK_MARKER = '# AITURK IDE Codex Baglama'
// Must equal SURUM in assets/codex-bridge/bridge.py; a running bridge that reports // Must equal SURUM in assets/codex-bridge/bridge.py; a running bridge that reports
// another version is restarted so an updated IDE never keeps an old bridge alive. // another version is restarted so an updated IDE never keeps an old bridge alive.
export const CODEX_BRIDGE_VERSION = '1' export const CODEX_BRIDGE_VERSION = '6'
export const CODEX_LINK_LINE = `openai_base_url = "${CODEX_LINK_ORIGIN}/backend-api/codex" ${CODEX_LINK_MARKER}` export const CODEX_LINK_LINE = `openai_base_url = "${CODEX_LINK_ORIGIN}/backend-api/codex" ${CODEX_LINK_MARKER}`
export const CODEX_LINK_BACKUP_SUFFIX = '.aiturk-yedek'
export const CODEX_LINK_RUN_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run' export const CODEX_LINK_RUN_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run'
export const CODEX_LINK_RUN_VALUE = 'AITURK-IDE-Codex-Baglama' export const CODEX_LINK_RUN_VALUE = 'AITURK-IDE-Codex-Baglama'
export const CODEX_LINK_LAUNCHER_NAME = 'baslat.pyw' export const CODEX_LINK_LAUNCHER_NAME = 'baslat.pyw'
+14 -16
View File
@@ -2,7 +2,9 @@ import { describe, expect, it } from 'vitest'
import { CODEX_BRIDGE_START_BUDGET_MS, type CodexLinkDeps, type CodexLinkPaths, createCodexLink } from './codex-link' import { CODEX_BRIDGE_START_BUDGET_MS, type CodexLinkDeps, type CodexLinkPaths, createCodexLink } from './codex-link'
import { import {
CODEX_BRIDGE_VERSION,
CODEX_LINK_LINE, CODEX_LINK_LINE,
CODEX_LINK_REFRESH_URL,
CODEX_LINK_STATUS_URL, CODEX_LINK_STATUS_URL,
CODEX_LINK_STOP_URL, CODEX_LINK_STOP_URL,
codexBridgeArgs, codexBridgeArgs,
@@ -20,8 +22,7 @@ const PATHS: CodexLinkPaths = {
} }
const BRIDGE_JSON = `${PATHS.bridgeHome}\\bridge.json` const BRIDGE_JSON = `${PATHS.bridgeHome}\\bridge.json`
const BACKUP = `${PATHS.codexConfig}.aiturk-yedek` const STATUS_OK = { ok: true, surum: CODEX_BRIDGE_VERSION, ide_durum: 'tamam', ide_model: 7, ozet: true }
const STATUS_OK = { ok: true, surum: '1', ide_durum: 'tamam', ide_model: 7, ozet: true }
const USER_CONFIG = 'model = "gpt-6"\r\n\r\n[features]\r\nweb = true\r\n' const USER_CONFIG = 'model = "gpt-6"\r\n\r\n[features]\r\nweb = true\r\n'
interface World { interface World {
@@ -72,12 +73,6 @@ function createWorld(patch: Partial<World> & { files?: Map<string, string> } = {
world.events.push(`write ${file}`) world.events.push(`write ${file}`)
world.files.set(file, text) world.files.set(file, text)
}, },
backupOnce: (source, target) => {
if (!world.files.has(target)) {
world.events.push(`backup ${target}`)
world.files.set(target, world.files.get(source) ?? '')
}
},
spawnBridge: (command, args, env) => { spawnBridge: (command, args, env) => {
world.events.push(`spawn ${command} ${JSON.stringify(args)} ${JSON.stringify(env)}`) world.events.push(`spawn ${command} ${JSON.stringify(args)} ${JSON.stringify(env)}`)
spawned = true spawned = true
@@ -103,6 +98,12 @@ function createWorld(patch: Partial<World> & { files?: Map<string, string> } = {
return null return null
} }
if (method === 'POST' && url === CODEX_LINK_REFRESH_URL) {
world.events.push('refresh')
return world.listening ? STATUS_OK : null
}
if (method === 'POST' && url === CODEX_LINK_STOP_URL) { if (method === 'POST' && url === CODEX_LINK_STOP_URL) {
world.events.push('stop') world.events.push('stop')
@@ -205,19 +206,17 @@ describe('applyCodexLink', () => {
hermesHome: PATHS.hermesHome hermesHome: PATHS.hermesHome
}) })
// bridge.json → start → verified answer → config.toml (backed up) → login item // bridge.json → start → verified answer → config.toml → login item
expect(world.events).toEqual([ expect(world.events).toEqual([
`write ${BRIDGE_JSON}`, `write ${BRIDGE_JSON}`,
`spawn ${PATHS.pythonw} ${JSON.stringify(args)} ${JSON.stringify(env)}`, `spawn ${PATHS.pythonw} ${JSON.stringify(args)} ${JSON.stringify(env)}`,
'status ok', 'status ok',
`backup ${BACKUP}`,
`write ${PATHS.codexConfig}`, `write ${PATHS.codexConfig}`,
'autostart set' 'autostart set'
]) ])
expect(JSON.parse(world.files.get(BRIDGE_JSON) ?? '')).toEqual(codexBridgeConfig()) expect(JSON.parse(world.files.get(BRIDGE_JSON) ?? '')).toEqual(codexBridgeConfig())
expect(world.files.get(PATHS.codexConfig)).toBe(`${CODEX_LINK_LINE}\r\n${USER_CONFIG}`) expect(world.files.get(PATHS.codexConfig)).toBe(`${CODEX_LINK_LINE}\r\n${USER_CONFIG}`)
expect(world.files.get(BACKUP)).toBe(USER_CONFIG)
expect(world.autostart).toBe( expect(world.autostart).toBe(
`"${PATHS.pythonw}" "${PATHS.bridgeScript}" --home "${PATHS.bridgeHome}" --hermes-home "${PATHS.hermesHome}"` `"${PATHS.pythonw}" "${PATHS.bridgeScript}" --home "${PATHS.bridgeHome}" --hermes-home "${PATHS.hermesHome}"`
) )
@@ -231,7 +230,6 @@ describe('applyCodexLink', () => {
expect(status).toMatchObject({ enabled: true, bridgeRunning: false, lastError: 'bridge-start-failed' }) expect(status).toMatchObject({ enabled: true, bridgeRunning: false, lastError: 'bridge-start-failed' })
expect(spawns(world)).toHaveLength(1) expect(spawns(world)).toHaveLength(1)
expect(world.files.get(PATHS.codexConfig)).toBe(USER_CONFIG) expect(world.files.get(PATHS.codexConfig)).toBe(USER_CONFIG)
expect(world.files.has(BACKUP)).toBe(false)
expect(world.autostart).toBeNull() expect(world.autostart).toBeNull()
expect(writes(world)).toEqual([`write ${BRIDGE_JSON}`]) expect(writes(world)).toEqual([`write ${BRIDGE_JSON}`])
// The start poll is bounded by its one budget. // The start poll is bounded by its one budget.
@@ -273,13 +271,13 @@ describe('applyCodexLink', () => {
expect(world.files.get(PATHS.codexConfig)).toBe(`${CODEX_LINK_LINE}\r\n${USER_CONFIG}`) expect(world.files.get(PATHS.codexConfig)).toBe(`${CODEX_LINK_LINE}\r\n${USER_CONFIG}`)
}) })
it('never overwrites the first backup', async () => { it('asks a running bridge to re-read the IDE session on every apply', async () => {
const { link, world } = createWorld({ listening: true }) const { link, world } = createWorld({ listening: true })
world.files.set(BACKUP, 'the original original')
await link.apply() await link.apply({ sync: true })
expect(world.files.get(BACKUP)).toBe('the original original') expect(world.events).toContain('refresh')
expect(spawns(world)).toEqual([])
}) })
it('falls back to python.exe when pythonw.exe is missing', async () => { it('falls back to python.exe when pythonw.exe is missing', async () => {
+12 -10
View File
@@ -23,8 +23,8 @@ import path from 'node:path'
import { import {
addCodexLinkLine, addCodexLinkLine,
CODEX_BRIDGE_VERSION, CODEX_BRIDGE_VERSION,
CODEX_LINK_BACKUP_SUFFIX,
CODEX_LINK_LAUNCHER_NAME, CODEX_LINK_LAUNCHER_NAME,
CODEX_LINK_REFRESH_URL,
CODEX_LINK_RUN_KEY, CODEX_LINK_RUN_KEY,
CODEX_LINK_RUN_VALUE, CODEX_LINK_RUN_VALUE,
CODEX_LINK_STATUS_URL, CODEX_LINK_STATUS_URL,
@@ -66,8 +66,6 @@ export interface CodexLinkDeps {
readText: (file: string) => null | string readText: (file: string) => null | string
/** tmp + rename; creates the parent folder. */ /** tmp + rename; creates the parent folder. */
writeTextAtomic: (file: string, text: string) => void writeTextAtomic: (file: string, text: string) => void
/** Copy `source` to `target` unless `target` already exists. */
backupOnce: (source: string, target: string) => void
/** Start the bridge detached and hidden; it must outlive the IDE. */ /** Start the bridge detached and hidden; it must outlive the IDE. */
spawnBridge: (command: string, args: string[], env: Record<string, string>) => void spawnBridge: (command: string, args: string[], env: Record<string, string>) => void
/** Parsed JSON body, or null when nothing answered within `budgetMs`. */ /** Parsed JSON body, or null when nothing answered within `budgetMs`. */
@@ -306,7 +304,17 @@ export function createCodexLink(deps: CodexLinkDeps): CodexLink {
bridge = NOT_RUNNING bridge = NOT_RUNNING
} }
if (!bridge.running) { if (bridge.running) {
// Already up: have it re-read the IDE session and model list now (a sign-in
// since its last periodic refresh would otherwise show up minutes later).
try {
const refreshed = readProbe(await deps.request('POST', CODEX_LINK_REFRESH_URL, CODEX_BRIDGE_START_BUDGET_MS))
bridge = refreshed.running ? refreshed : bridge
} catch {
// The status it already gave stays valid.
}
} else {
bridge = await startBridge(python) bridge = await startBridge(python)
} }
@@ -323,7 +331,6 @@ export function createCodexLink(deps: CodexLinkDeps): CodexLink {
if (edit.changed) { if (edit.changed) {
try { try {
deps.backupOnce(paths.codexConfig, `${paths.codexConfig}${CODEX_LINK_BACKUP_SUFFIX}`)
deps.writeTextAtomic(paths.codexConfig, edit.text) deps.writeTextAtomic(paths.codexConfig, edit.text)
} catch (error) { } catch (error) {
fail('config-write-failed', error) fail('config-write-failed', error)
@@ -461,11 +468,6 @@ export function createNodeCodexLinkDeps(paths: CodexLinkPaths, log: (message: st
exists: file => fs.existsSync(file), exists: file => fs.existsSync(file),
readText: readTextLossless, readText: readTextLossless,
writeTextAtomic, writeTextAtomic,
backupOnce: (source, target) => {
if (!fs.existsSync(target)) {
fs.copyFileSync(source, target, fs.constants.COPYFILE_EXCL)
}
},
spawnBridge: (command, args, env) => { spawnBridge: (command, args, env) => {
fs.mkdirSync(paths.bridgeHome, { recursive: true }) fs.mkdirSync(paths.bridgeHome, { recursive: true })
+4 -2
View File
@@ -2,7 +2,7 @@
"name": "aiturk-ide", "name": "aiturk-ide",
"productName": "AITURK IDE", "productName": "AITURK IDE",
"private": true, "private": true,
"version": "1.0.0-beta.21", "version": "1.0.0-beta.25",
"description": "TurkServis resmi yapay zekâ geliştirme ortamı. Hermes Agent tabanlıdır.", "description": "TurkServis resmi yapay zekâ geliştirme ortamı. Hermes Agent tabanlıdır.",
"author": "AITURK / TurkServis", "author": "AITURK / TurkServis",
"repository": { "repository": {
@@ -304,7 +304,9 @@
"from": "assets/codex-bridge", "from": "assets/codex-bridge",
"to": "codex-bridge", "to": "codex-bridge",
"filter": [ "filter": [
"*.py", "**/*.py",
"**/*.pyd",
"**/LICENSE",
"!test_*.py" "!test_*.py"
] ]
} }
+1 -1
View File
@@ -65,7 +65,7 @@
}, },
"apps/desktop": { "apps/desktop": {
"name": "aiturk-ide", "name": "aiturk-ide",
"version": "1.0.0-beta.21", "version": "1.0.0-beta.25",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@assistant-ui/core": "0.2.23", "@assistant-ui/core": "0.2.23",