|
| 1 | +import svg from "./icon.svg"; |
| 2 | +import styles from "./styles.css"; |
| 3 | + |
| 4 | +declare global { |
| 5 | + interface Window { |
| 6 | + _rivetkit_devtools_configs?: Array< |
| 7 | + Parameters<typeof import("rivetkit/client")["createClient"]>[0] |
| 8 | + >; |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +const root = document.createElement("div"); |
| 13 | + |
| 14 | +root.id = "rivetkit-devtools"; |
| 15 | +const shadow = root.attachShadow({ mode: "open" }); |
| 16 | + |
| 17 | +const img = document.createElement("img"); |
| 18 | +img.src = svg; |
| 19 | + |
| 20 | +const btn = document.createElement("button"); |
| 21 | +btn.appendChild(img); |
| 22 | + |
| 23 | +const style = document.createElement("style"); |
| 24 | +style.textContent = styles; |
| 25 | +shadow.appendChild(style); |
| 26 | +shadow.appendChild(btn); |
| 27 | + |
| 28 | +btn.addEventListener("click", () => { |
| 29 | + const config = window._rivetkit_devtools_configs?.[0]; |
| 30 | + if (!config || typeof config !== "object") { |
| 31 | + console.error("RivetKit Devtools: No client config found"); |
| 32 | + return; |
| 33 | + } |
| 34 | + const url = new URL("https://inspect.rivet.dev/"); |
| 35 | + if (!config.endpoint) { |
| 36 | + console.error("RivetKit Devtools: No endpoint found in client config"); |
| 37 | + return; |
| 38 | + } |
| 39 | + url.searchParams.set("u", config.endpoint); |
| 40 | + if (config.token) { |
| 41 | + url.searchParams.set("t", config.token); |
| 42 | + } |
| 43 | + if (config.namespace) { |
| 44 | + url.searchParams.set("ns", config.namespace); |
| 45 | + } |
| 46 | + if (config.runnerName) { |
| 47 | + url.searchParams.set("r", config.runnerName); |
| 48 | + } |
| 49 | + window.open(url.toString(), "_blank"); |
| 50 | +}); |
| 51 | + |
| 52 | +document.body.appendChild(root); |
0 commit comments