Repository navigation
Expand file tree
/
Copy pathoptions.js
More file actions
79 lines (71 loc) · 2.88 KB
/
Copy pathoptions.js
File metadata and controls
79 lines (71 loc) · 2.88 KB
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
import { store } from "./lib/platform.js";
import { bridgeStatus } from "./lib/bridge.js";
const MODELS = {
claude: [
["claude-opus-5-5", "Claude Opus 5.5 (best reading)"],
["claude-opus-5", "Claude Opus 5"],
["claude-sonnet-5", "Claude Sonnet 5 (faster)"],
["claude-haiku-4-5", "Claude Haiku 4.5 (fastest)"],
],
codex: [["", "Your Codex default"]],
};
const $ = (id) => document.getElementById(id);
const msg = $("msg");
const saved = await store.get(["provider", "model", "s2Key", "bridgeUrl", "webResearch"]);
$("provider").value = saved.provider || "claude";
$("s2Key").value = saved.s2Key || "";
$("bridgeUrl").value = saved.bridgeUrl || "";
$("webResearch").checked = saved.webResearch !== false;
$("ext-id").textContent = globalThis.chrome?.runtime?.id || "(shown when loaded as an extension)";
function fillModels(keep) {
const list = MODELS[$("provider").value];
$("model").innerHTML = list.map(([v, label]) => `<option value="${v}">${label}</option>`).join("");
$("model").value = list.some(([v]) => v === keep) ? keep : list[0][0];
$("model-hint").textContent = $("provider").value === "codex"
? "Codex uses the model from your Codex setup."
: "";
}
fillModels(saved.model);
$("provider").onchange = () => { fillModels(); syncStatus(); };
async function syncStatus() {
const status = $("bridge-status");
status.textContent = "checking…";
const st = await bridgeStatus($("bridgeUrl").value.trim());
const provider = $("provider").value;
const name = provider === "codex" ? "Codex" : "Claude Code";
if (st.mode === "none") {
status.textContent = "not set up yet";
} else if (!st[provider]) {
status.textContent = `connected, but ${name} wasn't found. Install and sign in to it, then re-run the setup command.`;
} else {
status.textContent = `connected ✓ ${st.mode === "native" ? "(starts automatically)" : "(HTTP bridge)"}, using ${name}`;
}
$("setup").hidden = st.mode !== "none";
}
syncStatus();
// Re-check when you come back from running the command.
addEventListener("focus", syncStatus);
$("bridgeUrl").onchange = syncStatus;
$("copy-cmd").onclick = async (e) => {
await navigator.clipboard.writeText($("setup-cmd").textContent);
e.target.textContent = "Copied ✓";
};
$("save").onclick = async () => {
await store.set({
provider: $("provider").value,
model: $("model").value,
s2Key: $("s2Key").value.trim(),
bridgeUrl: $("bridgeUrl").value.trim(),
webResearch: $("webResearch").checked,
});
msg.textContent = "Saved.";
};
$("clear").onclick = async () => {
if (globalThis.chrome?.storage) {
const all = await chrome.storage.local.get(null);
await chrome.storage.local.remove(Object.keys(all).filter((k) => k.startsWith("cache:")));
} else {
Object.keys(localStorage).filter((k) => k.startsWith("margin:cache:")).forEach((k) => localStorage.removeItem(k));
}
msg.textContent = "Cache cleared.";
};