forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlicense-watermark.ts
More file actions
51 lines (44 loc) · 1.76 KB
/
Copy pathlicense-watermark.ts
File metadata and controls
51 lines (44 loc) · 1.76 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
// The license watermark is currently disabled. The implementation below is
// kept intact so it can be re-enabled by flipping this flag back to `true`.
export const LICENSE_WATERMARK_ENABLED = false;
const WATERMARK_ID = "copilotkit-license-watermark";
const HEADER_NAME = "X-CopilotCloud-Public-Api-Key";
const LICENSE_KEY_REGEX = /^ck_pub_[0-9a-f]{32}$/i;
function hasValidLicenseHeader(headers?: Record<string, string>): boolean {
if (!headers) return false;
const key = headers[HEADER_NAME];
return Boolean(key && LICENSE_KEY_REGEX.test(key));
}
export function ensureLicenseWatermark(headers?: Record<string, string>): void {
if (!LICENSE_WATERMARK_ENABLED) {
return;
}
if (typeof document === "undefined" || hasValidLicenseHeader(headers)) {
return;
}
if (document.getElementById(WATERMARK_ID)) {
return;
}
const watermark = document.createElement("div");
watermark.id = WATERMARK_ID;
watermark.setAttribute("aria-hidden", "true");
watermark.textContent = "CopilotKit Unlicensed";
watermark.style.position = "fixed";
watermark.style.right = "12px";
watermark.style.bottom = "12px";
watermark.style.zIndex = "2147483647";
watermark.style.pointerEvents = "none";
watermark.style.userSelect = "none";
watermark.style.padding = "6px 10px";
watermark.style.borderRadius = "8px";
watermark.style.background = "rgba(17, 24, 39, 0.88)";
watermark.style.color = "#ffffff";
watermark.style.fontFamily =
"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace";
watermark.style.fontSize = "11px";
watermark.style.fontWeight = "600";
watermark.style.letterSpacing = "0.02em";
watermark.style.opacity = "0.9";
watermark.style.boxShadow = "0 6px 18px rgba(0, 0, 0, 0.25)";
document.body.appendChild(watermark);
}