File size: 3,860 Bytes
dc7c214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""Patch frontend ChatInput.tsx: add apodex-1.1-mini:free, ling-3.1-flash and
the BeatAPI space-bunny-alpha entry to the model picker.

  - apodex/apodex-1.1-mini:free        path: openai/apodex/apodex-1.1-mini:free
  - inclusionai/ling-3.1-flash         path: openai/inclusionai/ling-3.1-flash
  - BeatAPI space-bunny-alpha          path: beatapi/space-bunny-alpha

The first two follow the same OpenRouter `openai/` convention as the existing
models (including stealth/space-bunny-alpha). The third is a BEATAPI model:
its path starts with `beatapi/`, NOT `openai/`, so the backend routes it to
https://api.beatapi.io/v1 with BEATAPI_API_KEY instead of OpenRouter. The name
is prefixed "BeatAPI" so the picker makes the provider difference visible.

Runs AFTER patch_frontend.py and patch_frontend_new_models.py (which already
replaced DEFAULT_MODEL_OPTIONS). Idempotent.
"""

import os
import re

FILE = "/source/frontend/src/components/Chat/ChatInput.tsx"

NEW_ENTRIES = """  {
    id: 'apodex-1.1-mini-free',
    name: 'apodex/apodex-1.1-mini:free',
    modelPath: 'openai/apodex/apodex-1.1-mini:free',
    avatarUrl: 'https://huggingface.co/api/avatars/apodex',
    recommended: true,
  },
  {
    id: 'ling-3.1-flash',
    name: 'inclusionai/ling-3.1-flash',
    modelPath: 'openai/inclusionai/ling-3.1-flash',
    avatarUrl: 'https://huggingface.co/api/avatars/inclusionai',
    recommended: true,
  },
  {
    id: 'beatapi-space-bunny-alpha',
    name: 'BeatAPI space-bunny-alpha',
    modelPath: 'beatapi/space-bunny-alpha',
    avatarUrl: 'https://beatapi.io/favicon.ico',
    recommended: true,
  },
"""


def patch():
    if not os.path.exists(FILE):
        print(f"SKIP: {FILE} not found")
        return

    with open(FILE, "r", encoding="utf-8") as f:
        content = f.read()

    if (
        "apodex/apodex-1.1-mini:free" in content
        and "beatapi/space-bunny-alpha" in content
    ):
        print("OK: new models already present in ChatInput.tsx")
        return

    # Insert right before the stealth/space-bunny-alpha entry so the three new
    # models sit next to the existing free OpenRouter models.
    anchor = "  {\n    id: 'space-bunny-alpha',\n"
    if anchor in content:
        content = content.replace(anchor, NEW_ENTRIES + anchor, 1)
        print("OK: added 3 models before the stealth/space-bunny-alpha entry")
    else:
        # Fallback: insert before deepseek-v4-flash-latest, the other stable anchor.
        alt = "  {\n    id: 'deepseek-v4-flash-latest',\n"
        if alt in content:
            content = content.replace(alt, NEW_ENTRIES + alt, 1)
            print("OK: added 3 models before deepseek-v4-flash-latest (fallback)")
        else:
            m = re.search(
                r"const DEFAULT_MODEL_OPTIONS: ModelOption\[\] = \[.*?\];",
                content,
                re.DOTALL,
            )
            if not m:
                print("FAIL: could not find any model-list anchor")
                return
            head = m.group(0)[: m.group(0).rindex("[") + 1]
            content = (
                content[: m.start()]
                + head
                + "\n"
                + NEW_ENTRIES
                + content[m.start() + len(head) :]
            )
            print("OK: added 3 models at top of DEFAULT_MODEL_OPTIONS (fallback)")

    with open(FILE, "w", encoding="utf-8") as f:
        f.write(content)
    print("OK: ChatInput.tsx patched")

    # Verification: all three paths must be present.
    for needle in (
        "openai/apodex/apodex-1.1-mini:free",
        "openai/inclusionai/ling-3.1-flash",
        "beatapi/space-bunny-alpha",
    ):
        if needle not in content:
            print(f"FAIL: missing {needle}")
            raise SystemExit(1)
    print("OK: verified all 3 new model paths present")


if __name__ == "__main__":
    patch()