mythos-code 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/mythos.js +36 -6
- package/package.json +1 -1
package/bin/mythos.js
CHANGED
|
@@ -24,11 +24,41 @@ Du kannst Werkzeuge nutzen. Um ein Werkzeug aufzurufen, antworte mit GENAU EINEM
|
|
|
24
24
|
<tool>{"name":"ls","path":"."}</tool> -> Ordner auflisten
|
|
25
25
|
Nach jedem Werkzeug bekommst du das Ergebnis. Arbeite Schritt für Schritt, bis die Aufgabe erledigt ist, dann antworte normal ohne <tool>. Sei präzise.`;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const SITE = process.env.MYTHOS_SITE_URL || "https://ai-mythos.lovable.app";
|
|
28
|
+
const FN = process.env.MYTHOS_FN_URL || API.replace(/\/v1-messages$/, "");
|
|
29
|
+
const authPost = async (body) => (await fetch(FN + "/cli-auth", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) })).json();
|
|
30
|
+
|
|
31
|
+
function openBrowser(url) {
|
|
32
|
+
const cmd = process.platform === "win32" ? `start "" "${url}"` : process.platform === "darwin" ? `open "${url}"` : `xdg-open "${url}"`;
|
|
33
|
+
exec(cmd, () => {});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function loginWithKey() {
|
|
37
|
+
const k = (await ask("API-Key (sk-ant-mythos-...): ")).trim();
|
|
30
38
|
if (!k.startsWith("sk-ant-mythos-")) { console.log(C.r + "Ungültiger Key." + C.x); process.exit(1); }
|
|
31
|
-
cfg.key = k; save(cfg); console.log(C.g + "✓
|
|
39
|
+
cfg.key = k; save(cfg); console.log(C.g + "✓ Angemeldet" + C.x);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Anmeldung über die Website: Browser öffnet sich, dort auf "Authentifizieren" klicken.
|
|
43
|
+
async function login() {
|
|
44
|
+
if (process.argv.includes("--key")) return loginWithKey();
|
|
45
|
+
let s;
|
|
46
|
+
try { s = await authPost({ action: "start", client: "cli" }); } catch { s = null; }
|
|
47
|
+
if (!s?.code) { console.log(C.r + "Anmeldung gerade nicht möglich – versuch es gleich nochmal." + C.x); process.exit(1); }
|
|
48
|
+
const url = SITE + "/cli-auth?code=" + s.code;
|
|
49
|
+
console.log(C.c + "\n Anmeldung mit MythosAI" + C.x);
|
|
50
|
+
console.log(" Dein Browser öffnet sich. Klicke dort auf " + C.b + "Authentifizieren" + C.x + ".");
|
|
51
|
+
console.log(C.d + " Code: " + s.code + " · Falls sich nichts öffnet: " + url + C.x + "\n");
|
|
52
|
+
openBrowser(url);
|
|
53
|
+
const until = Date.now() + 15 * 60e3;
|
|
54
|
+
process.stdout.write(C.d + " Warte auf Bestätigung…" + C.x);
|
|
55
|
+
while (Date.now() < until) {
|
|
56
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
57
|
+
let p; try { p = await authPost({ action: "poll", code: s.code, poll_secret: s.poll_secret }); } catch { continue; }
|
|
58
|
+
if (p.status === "ok") { cfg.key = p.api_key; cfg.name = p.name; save(cfg); clearLine(); console.log(C.g + " ✓ Angemeldet als " + p.name + C.x + "\n"); return; }
|
|
59
|
+
if (p.status === "expired") break;
|
|
60
|
+
}
|
|
61
|
+
clearLine(); console.log(C.r + " Anmeldung abgelaufen – starte nochmal mit: mythos login" + C.x); process.exit(1);
|
|
32
62
|
}
|
|
33
63
|
|
|
34
64
|
const fmt = (ms) => { const s = Math.floor(ms / 1000); return (s >= 60 ? Math.floor(s / 60) + "m " : "") + (s % 60) + "s"; };
|
|
@@ -80,7 +110,7 @@ async function call(history) {
|
|
|
80
110
|
for (let a = 0; a < 6; a++) {
|
|
81
111
|
try { return await once(compact(history, Math.min(2, Math.floor(a / 2)))); }
|
|
82
112
|
catch (e) {
|
|
83
|
-
if (e.status === 401) throw new Error("
|
|
113
|
+
if (e.status === 401) throw new Error("Anmeldung ungültig – bitte neu anmelden: mythos login");
|
|
84
114
|
if (/Daily limit/i.test(e.message)) throw new Error("Tageslimit erreicht – mit Pro unbegrenzt.");
|
|
85
115
|
await new Promise((r) => setTimeout(r, Math.min(8000, 1500 * (a + 1))));
|
|
86
116
|
}
|
|
@@ -129,7 +159,7 @@ async function turnInner(history, input) {
|
|
|
129
159
|
}
|
|
130
160
|
|
|
131
161
|
async function main() {
|
|
132
|
-
const args = process.argv.slice(2).filter((a) => a !== "--yes");
|
|
162
|
+
const args = process.argv.slice(2).filter((a) => a !== "--yes" && a !== "--key");
|
|
133
163
|
if (args[0] === "login" || !cfg.key) await login();
|
|
134
164
|
if (args[0] === "login") process.exit(0);
|
|
135
165
|
if (args[0] === "logout") { save({}); console.log("Abgemeldet."); process.exit(0); }
|