Fork Horse repository, listed by its owner. Publisher snapshot.
packages/forkhorse-gatekeeper/src/configuration-form.ts
Snapshot at 34e3175
1import type { ConnectionDraft, DraftStatus } from "./configuration.ts";
2import { CONNECTION_HELD } from "./configuration.ts";
3
4/** Fixture preparation only. The connection button cannot become enabled from format checks. */
5export function mountConfiguration(root: HTMLElement, check: (draft: ConnectionDraft) => Promise<DraftStatus>) {
6 root.innerHTML = `<h1>Prepare an agent connection</h1>
7 <p>LOCAL FIXTURE ONLY 路 enter synthetic values. No credentials are verified or saved.</p>
8 <form><label>Core origin<input name="coreOrigin" type="url" placeholder="https://core.fixture.idiot.tax" required></label>
9 <label>Project ID<input name="project" required maxlength="48" autocomplete="off"></label>
10 <label>Enrolled agent credential (fixture only)<input name="agentCredential" type="password" autocomplete="off" required maxlength="256"></label>
11 <button type="button">Check format locally</button>
12 </form><p role="status"></p><button data-create type="button" disabled>Create connection</button>`;
13 const form = root.querySelector("form")!;
14 const status = root.querySelector<HTMLElement>('[role="status"]')!;
15 status.textContent = CONNECTION_HELD;
16 const submit = form.querySelector("button")!;
17 const field = (name: string) => form.querySelector<HTMLInputElement>(`input[name="${name}"]`)!;
18 let closed = false;
19 const onSubmit = async (event: Event) => {
20 event.preventDefault();
21 if (submit.disabled) return;
22 submit.disabled = true;
23 try {
24 const result = await check({ coreOrigin: field("coreOrigin").value,
25 project: field("project").value, agentCredential: field("agentCredential").value });
26 if (!closed) status.textContent = `Format checked for ${result.project}. ${CONNECTION_HELD}`;
27 } catch {
28 if (!closed) status.textContent = "Draft format check failed. Check the fields; no connection was created.";
29 } finally {
30 field("agentCredential").value = "";
31 if (!closed) submit.disabled = false;
32 }
33 };
34 form.addEventListener("submit", onSubmit);
35 // The OS frame permits scripts, not form submissions. Use a local button event.
36 submit.addEventListener("click", onSubmit);
37 return { dispose() {
38 closed = true;
39 field("agentCredential").value = "";
40 form.removeEventListener("submit", onSubmit);
41 submit.removeEventListener("click", onSubmit);
42 } };
43}
44