mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 12:27:28 +01:00
Three things the widget did wrong on production, found by using it: - A visitor's note about Loki itself got a receipt with no link: only the owner's build had a way to follow. Self-reported notes now carry the same claim link api/feedback hands out, so the person can follow it in their own My feedback. The claim path has one spelling (feedbackClaimPath). - On Loki's own site the header read "LOKI / Loki": the brand line, then document.title. pageLabel drops the brand segment and keeps the page's name, falling back to the path, then Home. - A corner holding the host's own floating button (substrata's ASK, Heidi's pill) was climbed: two assistants stacked as one tower at 390px, and ours floated 300px up the edge at 1280px. That corner is now the host's: the launcher takes the other corner if it is clear, else the edge tab. Tab bars and composers are not floats and are stepped around as before; a side named by the host or the visitor is kept. The install prompt no longer tells builders to add data-fc-bottom to stack them. Browser fixtures 4/4b fail against the current production bundle and pass with this one. Claude-Session: https://claude.ai/code/session_01E1qoQ9syUYXCRNbyrpqPGa Co-authored-by: Claude <noreply@anthropic.com>
54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
/**
|
||
* The one POST to /api/widget/self-report — the widget filing something
|
||
* about ITSELF into Loki's own project (src/lib/widget/self-report.ts).
|
||
* Fields are clamped to the route's caps: it rejects a whole report on one
|
||
* character over, and a person's note would be lost with it.
|
||
*/
|
||
|
||
/** Mirror WIDGET_SELF_KINDS in src/lib/widget/self-report.ts. */
|
||
export type SelfKind = "note" | "error" | "request" | "slow" | "overflow";
|
||
/** Mirror WIDGET_SELF_DETAIL_MAX / WIDGET_SELF_NOTE_MAX. */
|
||
export const SELF_DETAIL_MAX = 600;
|
||
export const SELF_NOTE_MAX = 2000;
|
||
|
||
export async function sendSelfReport(
|
||
apiBase: string,
|
||
fields: {
|
||
token: string;
|
||
kind: SelfKind;
|
||
detail?: string;
|
||
note?: string;
|
||
ownerPass?: string;
|
||
screenshots?: string[];
|
||
},
|
||
): Promise<{ building: boolean; note?: string; followUrl?: string; claimUrl?: string }> {
|
||
const res = await fetch(`${apiBase}/api/widget/self-report`, {
|
||
method: "POST",
|
||
headers: { "Content-Type": "application/json" },
|
||
body: JSON.stringify({
|
||
token: fields.token,
|
||
kind: fields.kind,
|
||
detail: fields.detail?.slice(0, SELF_DETAIL_MAX) || undefined,
|
||
note: fields.note?.trim().slice(0, SELF_NOTE_MAX) || undefined,
|
||
url: location.href.slice(0, 1000),
|
||
viewport: `${window.innerWidth}×${window.innerHeight}`,
|
||
ownerPass: fields.ownerPass,
|
||
screenshots: fields.screenshots?.length ? fields.screenshots : undefined,
|
||
}),
|
||
});
|
||
const body = (await res.json().catch(() => null)) as {
|
||
error?: string;
|
||
building?: boolean;
|
||
buildNote?: string;
|
||
followUrl?: string;
|
||
claimUrl?: string;
|
||
} | null;
|
||
if (!res.ok) throw new Error(body?.error ?? `Request failed (${res.status})`);
|
||
return {
|
||
building: body?.building === true,
|
||
...(body?.buildNote ? { note: body.buildNote.slice(0, 500) } : {}),
|
||
...(body?.followUrl ? { followUrl: body.followUrl.slice(0, 1000) } : {}),
|
||
...(body?.claimUrl ? { claimUrl: body.claimUrl.slice(0, 1000) } : {}),
|
||
};
|
||
}
|