@openclaw/gateway-protocol 2026.9.5 → 2026.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/dist/client-info.d.mts +3 -1
- package/dist/client-info.mjs +4 -2
- package/dist/connect-error-details.d.mts +4 -3
- package/dist/connect-error-details.mjs +13 -16
- package/dist/frame-guards.d.mts +2 -2
- package/dist/frame-guards.mjs +4 -4
- package/dist/{frames-X2k-UkK8.d.mts → frames-ICrB58JF.d.mts} +54 -11
- package/dist/{gateway-error-details-Djlwga0B.d.mts → gateway-error-details-BH1DM8mu.d.mts} +467 -384
- package/dist/gateway-error-details.d.mts +2 -2
- package/dist/gateway-error-details.mjs +7 -6
- package/dist/index.d.mts +3774 -2694
- package/dist/index.mjs +191 -114
- package/dist/{protocol-value-normalization-DfM01tqg.mjs → protocol-value-normalization-Oati9UF1.mjs} +1 -1
- package/dist/{record-coerce-BVp8Dr-B.mjs → record-coerce-DVQGe6I0.mjs} +1 -1
- package/dist/restart-unavailable.d.mts +3 -1
- package/dist/restart-unavailable.mjs +4 -2
- package/dist/{schema-modules-CsQIRdwb.d.mts → schema-modules-CRgBq9O3.d.mts} +10619 -8499
- package/dist/schema.d.mts +10 -9
- package/dist/schema.mjs +97 -28
- package/dist/{server-capabilities-Gfkxm7Ho.mjs → server-capabilities-BnyAklc1.mjs} +7 -1
- package/dist/startup-unavailable.d.mts +1 -1
- package/dist/startup-unavailable.mjs +1 -1
- package/dist/{string-coerce-BJ6bjzdv.mjs → string-coerce-BSD-wsXs.mjs} +1 -1
- package/dist/system-agent-context.d.mts +8 -1
- package/dist/system-agent-context.mjs +56 -6
- package/dist/theme-_hQKgfH-.mjs +278 -0
- package/dist/theme-s6T9Ck6Z.d.mts +86 -0
- package/dist/theme.d.mts +2 -0
- package/dist/theme.mjs +2 -0
- package/dist/{tools-catalog-CF4aqT9l.mjs → tools-catalog-pKZZLiUu.mjs} +2810 -1982
- package/dist/{version-COV9CEyr.d.mts → version-BL42XeI-.d.mts} +1 -1
- package/dist/version.d.mts +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +8 -3
- package/protocol.schema.json +28424 -17074
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
//#region src/server-capabilities.ts
|
|
1
|
+
//#region packages/gateway-protocol/src/server-capabilities.ts
|
|
2
2
|
/** Stable feature names advertised in Gateway hello responses. */
|
|
3
3
|
const GATEWAY_SERVER_CAPS = {
|
|
4
4
|
BOARD_WIDGET_PUT_CANVAS_DOC: "board-widget-put-canvas-doc",
|
|
5
5
|
CHAT_SEND_ROUTING_CONTRACT: "chat-send-routing-contract",
|
|
6
|
+
CONTROL_UI_BROWSER_FOCUS: "control-ui-browser-focus",
|
|
6
7
|
GATEWAY_RESTART_TARGET_SAFE: "gateway-restart-target-safe-v1",
|
|
7
8
|
MODEL_CATALOG_SNAPSHOT: "model-catalog-snapshot",
|
|
8
9
|
NODE_WORKER_BUNDLE_RETENTION: "node-worker-bundle-retention-v1",
|
|
9
10
|
NODE_WORKER_BUNDLE_STATUS: "node-worker-bundle-status-v1",
|
|
11
|
+
NODE_WORKER_CAPTURED_EXEC_POLICY: "node-worker-captured-exec-policy",
|
|
10
12
|
NODE_WORKER_ENVIRONMENT_SESSION: "node-worker-environment-session-v1",
|
|
13
|
+
NODE_WORKER_HOST_DIAGNOSTICS: "node-worker-host-diagnostics-v1",
|
|
14
|
+
NODE_WORKER_IDLE_RETENTION: "node-worker-idle-retention-v1",
|
|
15
|
+
NODE_WORKER_LAUNCH_TOOL_NAMES: "node-worker-launch-tool-names-v1",
|
|
11
16
|
NODE_WORKER_PORTAL_STREAM: "node-worker-portal-stream-v1",
|
|
17
|
+
NODE_WORKER_STATUS_WAIT: "node-worker-status-wait-v1",
|
|
12
18
|
PUBLISHED_MODEL_CATALOG: "published-model-catalog",
|
|
13
19
|
PROFILE_BINDING: "profile-binding-v1",
|
|
14
20
|
PROGRESS_CARD_AGENT_SCOPE: "progress-card-agent-scope-v1",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/startup-unavailable.d.ts
|
|
1
|
+
//#region packages/gateway-protocol/src/startup-unavailable.d.ts
|
|
2
2
|
/** Structured error reason used while gateway startup sidecars are still initializing. */
|
|
3
3
|
export declare const GATEWAY_STARTUP_UNAVAILABLE_REASON = "startup-sidecars";
|
|
4
4
|
/** Internal close cause that distinguishes startup retry closes from generic disconnects. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/startup-unavailable.ts
|
|
1
|
+
//#region packages/gateway-protocol/src/startup-unavailable.ts
|
|
2
2
|
/** Structured error reason used while gateway startup sidecars are still initializing. */
|
|
3
3
|
const GATEWAY_STARTUP_UNAVAILABLE_REASON = "startup-sidecars";
|
|
4
4
|
/** Internal close cause that distinguishes startup retry closes from generic disconnects. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region packages/normalization-core/src/string-coerce.ts
|
|
2
2
|
/** Trims string input and returns null for non-strings or empty strings. */
|
|
3
3
|
function normalizeNullableString(value) {
|
|
4
4
|
if (typeof value !== "string") return null;
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
//#region src/system-agent-context.d.ts
|
|
1
|
+
//#region packages/gateway-protocol/src/system-agent-context.d.ts
|
|
2
2
|
/** Ephemeral, quoted UI references. These fields never carry configuration values. */
|
|
3
3
|
export declare const SYSTEM_AGENT_PLUGIN_REFERENCE_MAX_CHARS = 1024;
|
|
4
4
|
export declare const SYSTEM_AGENT_PLUGIN_ID_MAX_CHARS = 128;
|
|
5
5
|
export declare const SYSTEM_AGENT_PLUGIN_NAME_MAX_CHARS = 96;
|
|
6
6
|
export declare const SYSTEM_AGENT_SETTING_PATH_MAX_SEGMENTS = 16;
|
|
7
7
|
export declare const SYSTEM_AGENT_SETTING_SEGMENT_MAX_CHARS = 64;
|
|
8
|
+
export declare const SYSTEM_AGENT_PLUGIN_CAPABILITY_MAX_ITEMS = 8;
|
|
9
|
+
export declare const SYSTEM_AGENT_PLUGIN_CAPABILITY_MAX_CHARS = 128;
|
|
10
|
+
declare const CAPABILITY_GROUPS: readonly ["tools", "providers", "channels", "contracts", "skills", "mcpServers"];
|
|
11
|
+
type PluginDeclaredCapabilities = Partial<Record<(typeof CAPABILITY_GROUPS)[number], string[]>> & {
|
|
12
|
+
incomplete?: boolean;
|
|
13
|
+
};
|
|
8
14
|
export type SystemAgentPluginReference = {
|
|
9
15
|
id: string;
|
|
10
16
|
name: string;
|
|
@@ -13,6 +19,7 @@ export type SystemAgentPluginReference = {
|
|
|
13
19
|
path: string[];
|
|
14
20
|
label: string;
|
|
15
21
|
};
|
|
22
|
+
declared?: PluginDeclaredCapabilities;
|
|
16
23
|
};
|
|
17
24
|
export declare function normalizeSystemAgentPluginReference(value: unknown): SystemAgentPluginReference | undefined;
|
|
18
25
|
//#endregion
|
|
@@ -1,13 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
import { t as asNullableRecord } from "./record-coerce-DVQGe6I0.mjs";
|
|
2
|
+
//#region packages/gateway-protocol/src/system-agent-context.ts
|
|
2
3
|
/** Ephemeral, quoted UI references. These fields never carry configuration values. */
|
|
3
4
|
const SYSTEM_AGENT_PLUGIN_REFERENCE_MAX_CHARS = 1024;
|
|
4
5
|
const SYSTEM_AGENT_PLUGIN_ID_MAX_CHARS = 128;
|
|
5
6
|
const SYSTEM_AGENT_PLUGIN_NAME_MAX_CHARS = 96;
|
|
6
7
|
const SYSTEM_AGENT_SETTING_PATH_MAX_SEGMENTS = 16;
|
|
7
8
|
const SYSTEM_AGENT_SETTING_SEGMENT_MAX_CHARS = 64;
|
|
9
|
+
const SYSTEM_AGENT_PLUGIN_CAPABILITY_MAX_ITEMS = 8;
|
|
10
|
+
const SYSTEM_AGENT_PLUGIN_CAPABILITY_MAX_CHARS = 128;
|
|
11
|
+
const CAPABILITY_GROUPS = [
|
|
12
|
+
"tools",
|
|
13
|
+
"providers",
|
|
14
|
+
"channels",
|
|
15
|
+
"contracts",
|
|
16
|
+
"skills",
|
|
17
|
+
"mcpServers"
|
|
18
|
+
];
|
|
19
|
+
function addDeclaredCapabilities(reference, value) {
|
|
20
|
+
const raw = asNullableRecord(value);
|
|
21
|
+
if (!raw) return;
|
|
22
|
+
const declared = { incomplete: true };
|
|
23
|
+
reference.declared = declared;
|
|
24
|
+
const fits = () => JSON.stringify(reference).length <= SYSTEM_AGENT_PLUGIN_REFERENCE_MAX_CHARS;
|
|
25
|
+
if (!fits()) {
|
|
26
|
+
delete reference.declared;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let incomplete = raw.incomplete === true;
|
|
30
|
+
for (const group of CAPABILITY_GROUPS) {
|
|
31
|
+
const items = raw[group];
|
|
32
|
+
if (items === void 0) continue;
|
|
33
|
+
if (!Array.isArray(items)) {
|
|
34
|
+
incomplete = true;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const accepted = [];
|
|
38
|
+
declared[group] = accepted;
|
|
39
|
+
if (!fits()) {
|
|
40
|
+
delete declared[group];
|
|
41
|
+
incomplete = true;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const valid = items.filter((item) => typeof item === "string" && item.length > 0 && item.length <= 128);
|
|
45
|
+
const names = [...new Set(valid)].toSorted();
|
|
46
|
+
incomplete ||= valid.length !== items.length || names.length > 8;
|
|
47
|
+
for (const item of names.slice(0, 8)) {
|
|
48
|
+
accepted.push(item);
|
|
49
|
+
if (!fits()) {
|
|
50
|
+
accepted.pop();
|
|
51
|
+
incomplete = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!incomplete) delete declared.incomplete;
|
|
56
|
+
}
|
|
8
57
|
function normalizeSystemAgentPluginReference(value) {
|
|
9
|
-
|
|
10
|
-
|
|
58
|
+
const raw = asNullableRecord(value);
|
|
59
|
+
if (!raw) return;
|
|
11
60
|
if (typeof raw.id !== "string" || !/^[A-Za-z0-9@][A-Za-z0-9@._/-]{0,127}$/u.test(raw.id)) return;
|
|
12
61
|
if (typeof raw.name !== "string" || !raw.name.trim() || raw.name.length > 96) return;
|
|
13
62
|
const reference = {
|
|
@@ -15,15 +64,16 @@ function normalizeSystemAgentPluginReference(value) {
|
|
|
15
64
|
name: raw.name.trim()
|
|
16
65
|
};
|
|
17
66
|
if (typeof raw.installed === "boolean") reference.installed = raw.installed;
|
|
18
|
-
|
|
19
|
-
|
|
67
|
+
const setting = asNullableRecord(raw.setting);
|
|
68
|
+
if (setting) {
|
|
20
69
|
if (Array.isArray(setting.path) && setting.path.length > 0 && setting.path.length <= 16 && setting.path.every((part) => typeof part === "string" && part.length > 0 && part.length <= 64) && typeof setting.label === "string" && setting.label.trim() && setting.label.length <= 96) reference.setting = {
|
|
21
70
|
path: [...setting.path],
|
|
22
71
|
label: setting.label.trim()
|
|
23
72
|
};
|
|
24
73
|
}
|
|
25
74
|
if (JSON.stringify(reference).length > 1024) delete reference.setting;
|
|
75
|
+
addDeclaredCapabilities(reference, raw.declared);
|
|
26
76
|
return JSON.stringify(reference).length <= 1024 ? reference : void 0;
|
|
27
77
|
}
|
|
28
78
|
//#endregion
|
|
29
|
-
export { SYSTEM_AGENT_PLUGIN_ID_MAX_CHARS, SYSTEM_AGENT_PLUGIN_NAME_MAX_CHARS, SYSTEM_AGENT_PLUGIN_REFERENCE_MAX_CHARS, SYSTEM_AGENT_SETTING_PATH_MAX_SEGMENTS, SYSTEM_AGENT_SETTING_SEGMENT_MAX_CHARS, normalizeSystemAgentPluginReference };
|
|
79
|
+
export { SYSTEM_AGENT_PLUGIN_CAPABILITY_MAX_CHARS, SYSTEM_AGENT_PLUGIN_CAPABILITY_MAX_ITEMS, SYSTEM_AGENT_PLUGIN_ID_MAX_CHARS, SYSTEM_AGENT_PLUGIN_NAME_MAX_CHARS, SYSTEM_AGENT_PLUGIN_REFERENCE_MAX_CHARS, SYSTEM_AGENT_SETTING_PATH_MAX_SEGMENTS, SYSTEM_AGENT_SETTING_SEGMENT_MAX_CHARS, normalizeSystemAgentPluginReference };
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
//#region packages/gateway-protocol/src/theme-ids.ts
|
|
2
|
+
/** Lightweight theme identifiers used while browser preferences boot. */
|
|
3
|
+
const BUILTIN_THEME_IDS = [
|
|
4
|
+
"claw",
|
|
5
|
+
"knot",
|
|
6
|
+
"dash",
|
|
7
|
+
"absolutely",
|
|
8
|
+
"tide",
|
|
9
|
+
"beacon",
|
|
10
|
+
"phosphor",
|
|
11
|
+
"crt",
|
|
12
|
+
"manuscript",
|
|
13
|
+
"rose",
|
|
14
|
+
"miami"
|
|
15
|
+
];
|
|
16
|
+
const THEME_LOCAL_ID_MAX_LENGTH = 64;
|
|
17
|
+
const THEME_LOCAL_ID_PATTERN = new RegExp(`^[a-z0-9][a-z0-9_-]{0,63}$`);
|
|
18
|
+
function isBuiltinThemeId(value) {
|
|
19
|
+
return BUILTIN_THEME_IDS.some((id) => id === value);
|
|
20
|
+
}
|
|
21
|
+
function isThemeId(value) {
|
|
22
|
+
if (isBuiltinThemeId(value)) return true;
|
|
23
|
+
if (typeof value !== "string" || value.length > 256) return false;
|
|
24
|
+
const separator = value.lastIndexOf("/");
|
|
25
|
+
const owner = value.slice(0, separator);
|
|
26
|
+
return separator > 0 && !owner.startsWith("user/") && /^@?[a-z0-9][a-z0-9._-]*(?:\/[a-z0-9][a-z0-9._-]*)*$/i.test(owner) && THEME_LOCAL_ID_PATTERN.test(value.slice(separator + 1));
|
|
27
|
+
}
|
|
28
|
+
function normalizeThemeMode(value) {
|
|
29
|
+
return value === "system" || value === "light" || value === "dark" ? value : void 0;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region packages/gateway-protocol/src/theme.ts
|
|
33
|
+
const THEME_COLOR_KEYS = [
|
|
34
|
+
"background",
|
|
35
|
+
"foreground",
|
|
36
|
+
"card",
|
|
37
|
+
"card-foreground",
|
|
38
|
+
"popover",
|
|
39
|
+
"popover-foreground",
|
|
40
|
+
"primary",
|
|
41
|
+
"primary-foreground",
|
|
42
|
+
"secondary",
|
|
43
|
+
"secondary-foreground",
|
|
44
|
+
"muted",
|
|
45
|
+
"muted-foreground",
|
|
46
|
+
"accent",
|
|
47
|
+
"accent-foreground",
|
|
48
|
+
"destructive",
|
|
49
|
+
"destructive-foreground",
|
|
50
|
+
"border",
|
|
51
|
+
"input",
|
|
52
|
+
"ring"
|
|
53
|
+
];
|
|
54
|
+
const THEME_FONT_KEYS = ["font-sans", "font-mono"];
|
|
55
|
+
const THEME_MASCOT_VALUES = ["claw", "none"];
|
|
56
|
+
const THEME_CRITTER_IDS = ["penguin", "fedora"];
|
|
57
|
+
function isThemeCritterId(value) {
|
|
58
|
+
return THEME_CRITTER_IDS.some((id) => id === value);
|
|
59
|
+
}
|
|
60
|
+
const THEME_AVATAR_HAT_IDS = [
|
|
61
|
+
"fedora",
|
|
62
|
+
"crown",
|
|
63
|
+
"santa",
|
|
64
|
+
"party",
|
|
65
|
+
"pumpkin"
|
|
66
|
+
];
|
|
67
|
+
function isThemeAvatarHatId(value) {
|
|
68
|
+
return THEME_AVATAR_HAT_IDS.some((id) => id === value);
|
|
69
|
+
}
|
|
70
|
+
const THEME_ARTWORK_ID_PATTERN = /^[a-z0-9][a-z0-9_-]{0,31}$/;
|
|
71
|
+
const THEME_WORKING_PHRASES_MAX = 24;
|
|
72
|
+
const THEME_WORKING_PHRASE_MAX_LENGTH = 24;
|
|
73
|
+
const MAX_THEME_DEFINITION_BYTES = 4096;
|
|
74
|
+
const THEME_NAME_MAX_LENGTH = 80;
|
|
75
|
+
const THEME_DESCRIPTION_MAX_LENGTH = 320;
|
|
76
|
+
const THEME_TOKEN_MAX_LENGTH = 120;
|
|
77
|
+
const DEFAULT_THEME_CRITTERS = [];
|
|
78
|
+
function resolveThemeBranding(source) {
|
|
79
|
+
return {
|
|
80
|
+
mascot: source?.mascot ?? "claw",
|
|
81
|
+
workingPhrases: source?.workingPhrases,
|
|
82
|
+
critters: source?.critters ?? DEFAULT_THEME_CRITTERS,
|
|
83
|
+
avatarHat: source?.avatarHat,
|
|
84
|
+
...source?.artwork ? { artwork: source.artwork } : {}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const BUILTIN_THEMES = [
|
|
88
|
+
{
|
|
89
|
+
id: "claw",
|
|
90
|
+
name: "Claw",
|
|
91
|
+
description: "Signature coral red and teal on charcoal or pale surfaces, with Instrument Sans throughout. A balanced everyday workspace."
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "knot",
|
|
95
|
+
name: "Knot",
|
|
96
|
+
description: "Crimson accents on true black or clean white, with Geist typography. Sharp, minimal, and high contrast."
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: "dash",
|
|
100
|
+
name: "Dash",
|
|
101
|
+
description: "Toasted caramel on deep cocoa or warm cream, with DM Sans controls and Fraunces serif chat. Warm and bookish."
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: "absolutely",
|
|
105
|
+
name: "Absolutely",
|
|
106
|
+
description: "Terracotta clay on warm graphite or soft cream, with Space Grotesk controls and Lora serif chat. Quiet editorial character."
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: "tide",
|
|
110
|
+
name: "Tide",
|
|
111
|
+
description: "Steel cyan on cool slate or pale blue-gray, with IBM Plex Sans throughout. Calm, technical, and understated."
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: "beacon",
|
|
115
|
+
name: "Beacon",
|
|
116
|
+
description: "High-visibility amber on black or white, bold focus rings, and Atkinson Hyperlegible typography. Designed for maximum readability."
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: "phosphor",
|
|
120
|
+
name: "Phosphor",
|
|
121
|
+
description: "Luminous green on green-tinted black or pale green, with JetBrains Mono throughout. A classic green terminal atmosphere."
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: "crt",
|
|
125
|
+
name: "CRT",
|
|
126
|
+
description: "White phosphor and amber on tube black, with a light counterpart, JetBrains Mono, and nearly square corners. A retro computer console."
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: "manuscript",
|
|
130
|
+
name: "Manuscript",
|
|
131
|
+
description: "Lapis blue and gold on aged paper, with a dark reading-room variant and Lora serif throughout. A quiet illuminated manuscript."
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
id: "rose",
|
|
135
|
+
name: "Rosé",
|
|
136
|
+
description: "Dried rose and gold on deep plum-gray or soft rose-tinted cream, with DM Sans. Gentle, muted, and warm."
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: "miami",
|
|
140
|
+
name: "Miami",
|
|
141
|
+
description: "Hot magenta and cyan on violet-black or pale lavender, with Space Grotesk. Bright neon energy and a synthwave character."
|
|
142
|
+
}
|
|
143
|
+
].map((theme) => ({
|
|
144
|
+
id: theme.id,
|
|
145
|
+
name: theme.name,
|
|
146
|
+
description: theme.description,
|
|
147
|
+
source: "builtin",
|
|
148
|
+
modes: ["light", "dark"]
|
|
149
|
+
}));
|
|
150
|
+
function requireRecord(value, label) {
|
|
151
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${label} must be an object`);
|
|
152
|
+
return value;
|
|
153
|
+
}
|
|
154
|
+
function requireKeys(value, allowed, label) {
|
|
155
|
+
const unknown = Object.keys(value).find((key) => !allowed.includes(key));
|
|
156
|
+
if (unknown) throw new Error(`${label} has unsupported field ${unknown}`);
|
|
157
|
+
}
|
|
158
|
+
function requireText(value, label, maxLength) {
|
|
159
|
+
if (typeof value !== "string" || !value.trim() || value.trim().length > maxLength || Array.from(value).some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127)) throw new Error(`${label} must be nonempty text of at most ${maxLength} characters`);
|
|
160
|
+
return value.trim();
|
|
161
|
+
}
|
|
162
|
+
const NUMBER = "[+-]?(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:e[+-]?\\d+)?";
|
|
163
|
+
const COMPONENT = `${NUMBER}%?`;
|
|
164
|
+
const HUE = `${NUMBER}(?:deg|grad|rad|turn)?`;
|
|
165
|
+
const LEGACY_COLOR_FUNCTION = new RegExp(`^(?:(?:rgb|rgba)\\( *(?:${NUMBER} *, *${NUMBER} *, *${NUMBER}|${NUMBER}% *, *${NUMBER}% *, *${NUMBER}%)|(?:hsl|hsla)\\( *${HUE} *, *${NUMBER}% *, *${NUMBER}%)(?: *, *${COMPONENT})? *\\)$`, "i");
|
|
166
|
+
const COLOR_FUNCTION = new RegExp(`^(?:(?:rgb|rgba|oklab|lab)\\( *${COMPONENT} +${COMPONENT} +${COMPONENT}|(?:hsl|hsla)\\( *${HUE} +${COMPONENT} +${COMPONENT}|(?:oklch|lch)\\( *${COMPONENT} +${COMPONENT} +${HUE})(?: */ *${COMPONENT})? *\\)$`, "i");
|
|
167
|
+
const COLOR_SPACE_FUNCTION = new RegExp(`^color\\( *(?:srgb|srgb-linear|display-p3|a98-rgb|prophoto-rgb|rec2020|xyz|xyz-d50|xyz-d65) +${COMPONENT} +${COMPONENT} +${COMPONENT}(?: */ *${COMPONENT})? *\\)$`, "i");
|
|
168
|
+
const FONT_IDENTIFIER = "(?:--[a-z0-9_-]*|-?[a-z_][a-z0-9_-]*)";
|
|
169
|
+
const FONT_FAMILY = `(?:"[a-z0-9 ,'._-]*"|'[a-z0-9 ,"._-]*'|${FONT_IDENTIFIER}(?: +${FONT_IDENTIFIER})*)`;
|
|
170
|
+
const FONT_FAMILY_LIST = new RegExp(`^${FONT_FAMILY}(?: *, *${FONT_FAMILY})*$`, "i");
|
|
171
|
+
const CSS_WIDE_KEYWORDS = /* @__PURE__ */ new Set([
|
|
172
|
+
"inherit",
|
|
173
|
+
"initial",
|
|
174
|
+
"unset",
|
|
175
|
+
"revert",
|
|
176
|
+
"revert-layer"
|
|
177
|
+
]);
|
|
178
|
+
const GENERIC_FONT_FAMILIES = /* @__PURE__ */ new Set([
|
|
179
|
+
"serif",
|
|
180
|
+
"sans-serif",
|
|
181
|
+
"monospace",
|
|
182
|
+
"cursive",
|
|
183
|
+
"fantasy",
|
|
184
|
+
"system-ui",
|
|
185
|
+
"ui-serif",
|
|
186
|
+
"ui-sans-serif",
|
|
187
|
+
"ui-monospace",
|
|
188
|
+
"ui-rounded",
|
|
189
|
+
"emoji",
|
|
190
|
+
"math",
|
|
191
|
+
"fangsong",
|
|
192
|
+
"-webkit-body"
|
|
193
|
+
]);
|
|
194
|
+
function isFontFamilyList(value) {
|
|
195
|
+
if (!FONT_FAMILY_LIST.test(value)) return false;
|
|
196
|
+
return value.replace(/"[^"]*"|'[^']*'/g, "").split(",").every((family) => {
|
|
197
|
+
const words = family.trim().toLowerCase().split(/ +/);
|
|
198
|
+
return words.every((word) => !CSS_WIDE_KEYWORDS.has(word) && word !== "default" && (words.length === 1 || !GENERIC_FONT_FAMILIES.has(word)));
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
function requireColor(value, label) {
|
|
202
|
+
const color = requireText(value, label, 120);
|
|
203
|
+
if (!/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color) && !/^(?:transparent|black|white)$/i.test(color) && !LEGACY_COLOR_FUNCTION.test(color) && !COLOR_FUNCTION.test(color) && !COLOR_SPACE_FUNCTION.test(color)) throw new Error(`${label} must be a hex, rgb, hsl, lab, lch, oklab, oklch, or color() color`);
|
|
204
|
+
return color;
|
|
205
|
+
}
|
|
206
|
+
function normalizePalette(value, mode) {
|
|
207
|
+
const palette = requireRecord(value, `theme.${mode}`);
|
|
208
|
+
requireKeys(palette, [...THEME_COLOR_KEYS, ...THEME_FONT_KEYS], `theme.${mode}`);
|
|
209
|
+
const entries = THEME_COLOR_KEYS.map((key) => [key, requireColor(palette[key], `theme.${mode}.${key}`)]);
|
|
210
|
+
const result = { ...Object.fromEntries(entries) };
|
|
211
|
+
for (const key of THEME_FONT_KEYS) {
|
|
212
|
+
if (palette[key] === void 0) continue;
|
|
213
|
+
const font = requireText(palette[key], `theme.${mode}.${key}`, 120);
|
|
214
|
+
if (!isFontFamilyList(font)) throw new Error(`theme.${mode}.${key} must contain only font family names`);
|
|
215
|
+
result[key] = font;
|
|
216
|
+
}
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
/** Rejects executable CSS and incomplete palettes before they reach storage or a stylesheet. */
|
|
220
|
+
function normalizeThemeDefinition(input, options) {
|
|
221
|
+
const record = requireRecord(input, "theme");
|
|
222
|
+
requireKeys(record, [
|
|
223
|
+
"name",
|
|
224
|
+
"description",
|
|
225
|
+
"mascot",
|
|
226
|
+
"workingPhrases",
|
|
227
|
+
"critters",
|
|
228
|
+
"avatarHat",
|
|
229
|
+
"light",
|
|
230
|
+
"dark"
|
|
231
|
+
], "theme");
|
|
232
|
+
const definition = {
|
|
233
|
+
name: requireText(record.name, "theme.name", 80),
|
|
234
|
+
description: requireText(record.description, "theme.description", 320),
|
|
235
|
+
...record.light !== void 0 ? { light: normalizePalette(record.light, "light") } : {},
|
|
236
|
+
...record.dark !== void 0 ? { dark: normalizePalette(record.dark, "dark") } : {}
|
|
237
|
+
};
|
|
238
|
+
if (record.mascot !== void 0) {
|
|
239
|
+
const mascot = THEME_MASCOT_VALUES.find((candidate) => candidate === record.mascot);
|
|
240
|
+
if (!mascot) throw new Error(`theme.mascot must be one of ${THEME_MASCOT_VALUES.join(", ")}`);
|
|
241
|
+
definition.mascot = mascot;
|
|
242
|
+
}
|
|
243
|
+
if (record.workingPhrases !== void 0) {
|
|
244
|
+
if (!Array.isArray(record.workingPhrases) || record.workingPhrases.length > 24) throw new Error(`theme.workingPhrases must be an array of at most 24 entries`);
|
|
245
|
+
const phrases = Array.from(record.workingPhrases, (phrase, index) => requireText(phrase, `theme.workingPhrases[${index}]`, 24));
|
|
246
|
+
if (new Set(phrases).size !== phrases.length) throw new Error("theme.workingPhrases must not contain duplicate entries after trimming");
|
|
247
|
+
definition.workingPhrases = phrases;
|
|
248
|
+
}
|
|
249
|
+
if (record.critters !== void 0) {
|
|
250
|
+
if (!Array.isArray(record.critters) || record.critters.length > 8) throw new Error("theme.critters must be an array of at most 8 entries");
|
|
251
|
+
const allowedIds = [...THEME_CRITTER_IDS, ...options?.critterIds ?? []];
|
|
252
|
+
const critters = Array.from(record.critters, (entry, index) => {
|
|
253
|
+
const critter = allowedIds.find((id) => id === entry);
|
|
254
|
+
if (!critter) throw new Error(`theme.critters[${index}] must be one of ${allowedIds.join(", ")}`);
|
|
255
|
+
return critter;
|
|
256
|
+
});
|
|
257
|
+
if (new Set(critters).size !== critters.length) throw new Error("theme.critters must not contain duplicate entries");
|
|
258
|
+
definition.critters = critters;
|
|
259
|
+
}
|
|
260
|
+
if (record.avatarHat !== void 0) {
|
|
261
|
+
const allowedIds = [...THEME_AVATAR_HAT_IDS, ...options?.hatIds ?? []];
|
|
262
|
+
const avatarHat = allowedIds.find((id) => id === record.avatarHat);
|
|
263
|
+
if (!avatarHat) throw new Error(`theme.avatarHat must be one of ${allowedIds.join(", ")}`);
|
|
264
|
+
definition.avatarHat = avatarHat;
|
|
265
|
+
}
|
|
266
|
+
if (!definition.light && !definition.dark) throw new Error("theme must provide at least one light or dark palette");
|
|
267
|
+
if (new TextEncoder().encode(JSON.stringify(definition)).length > 4096) throw new Error(`theme definition exceeds ${MAX_THEME_DEFINITION_BYTES} bytes`);
|
|
268
|
+
return definition;
|
|
269
|
+
}
|
|
270
|
+
function parseThemeDefinition(value) {
|
|
271
|
+
try {
|
|
272
|
+
return normalizeThemeDefinition(value);
|
|
273
|
+
} catch {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
//#endregion
|
|
278
|
+
export { isThemeId as C, isBuiltinThemeId as S, parseThemeDefinition as _, THEME_COLOR_KEYS as a, THEME_LOCAL_ID_MAX_LENGTH as b, THEME_FONT_KEYS as c, THEME_TOKEN_MAX_LENGTH as d, THEME_WORKING_PHRASES_MAX as f, normalizeThemeDefinition as g, isThemeCritterId as h, THEME_AVATAR_HAT_IDS as i, THEME_MASCOT_VALUES as l, isThemeAvatarHatId as m, MAX_THEME_DEFINITION_BYTES as n, THEME_CRITTER_IDS as o, THEME_WORKING_PHRASE_MAX_LENGTH as p, THEME_ARTWORK_ID_PATTERN as r, THEME_DESCRIPTION_MAX_LENGTH as s, BUILTIN_THEMES as t, THEME_NAME_MAX_LENGTH as u, resolveThemeBranding as v, normalizeThemeMode as w, THEME_LOCAL_ID_PATTERN as x, BUILTIN_THEME_IDS as y };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
//#region packages/gateway-protocol/src/theme-ids.d.ts
|
|
2
|
+
/** Lightweight theme identifiers used while browser preferences boot. */
|
|
3
|
+
declare const BUILTIN_THEME_IDS: readonly ["claw", "knot", "dash", "absolutely", "tide", "beacon", "phosphor", "crt", "manuscript", "rose", "miami"];
|
|
4
|
+
type BuiltinThemeId = (typeof BUILTIN_THEME_IDS)[number];
|
|
5
|
+
type ThemeId = BuiltinThemeId | `${string}/${string}`;
|
|
6
|
+
type ThemeMode = "system" | "light" | "dark";
|
|
7
|
+
declare const THEME_LOCAL_ID_MAX_LENGTH = 64;
|
|
8
|
+
declare const THEME_LOCAL_ID_PATTERN: RegExp;
|
|
9
|
+
declare function isBuiltinThemeId(value: unknown): value is BuiltinThemeId;
|
|
10
|
+
declare function isThemeId(value: unknown): value is ThemeId;
|
|
11
|
+
declare function normalizeThemeMode(value: unknown): ThemeMode | undefined;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region packages/gateway-protocol/src/theme.d.ts
|
|
14
|
+
/** Portable theme data shared by profile preferences, plugins, and the Control UI. */
|
|
15
|
+
type ThemeColorMode = "light" | "dark";
|
|
16
|
+
declare const THEME_COLOR_KEYS: readonly ["background", "foreground", "card", "card-foreground", "popover", "popover-foreground", "primary", "primary-foreground", "secondary", "secondary-foreground", "muted", "muted-foreground", "accent", "accent-foreground", "destructive", "destructive-foreground", "border", "input", "ring"];
|
|
17
|
+
declare const THEME_FONT_KEYS: readonly ["font-sans", "font-mono"];
|
|
18
|
+
declare const THEME_MASCOT_VALUES: readonly ["claw", "none"];
|
|
19
|
+
type ThemeMascot = (typeof THEME_MASCOT_VALUES)[number];
|
|
20
|
+
declare const THEME_CRITTER_IDS: readonly ["penguin", "fedora"];
|
|
21
|
+
type ThemeCritterId = (typeof THEME_CRITTER_IDS)[number];
|
|
22
|
+
declare function isThemeCritterId(value: unknown): value is ThemeCritterId;
|
|
23
|
+
declare const THEME_AVATAR_HAT_IDS: readonly ["fedora", "crown", "santa", "party", "pumpkin"];
|
|
24
|
+
type ThemeAvatarHatId = (typeof THEME_AVATAR_HAT_IDS)[number];
|
|
25
|
+
declare function isThemeAvatarHatId(value: unknown): value is ThemeAvatarHatId;
|
|
26
|
+
declare const THEME_ARTWORK_ID_PATTERN: RegExp;
|
|
27
|
+
declare const THEME_WORKING_PHRASES_MAX = 24;
|
|
28
|
+
declare const THEME_WORKING_PHRASE_MAX_LENGTH = 24;
|
|
29
|
+
declare const MAX_THEME_DEFINITION_BYTES = 4096;
|
|
30
|
+
declare const THEME_NAME_MAX_LENGTH = 80;
|
|
31
|
+
declare const THEME_DESCRIPTION_MAX_LENGTH = 320;
|
|
32
|
+
declare const THEME_TOKEN_MAX_LENGTH = 120;
|
|
33
|
+
type ThemePalette = Record<(typeof THEME_COLOR_KEYS)[number], string> & Partial<Record<(typeof THEME_FONT_KEYS)[number], string>>;
|
|
34
|
+
type ThemeDefinition = {
|
|
35
|
+
name: string;
|
|
36
|
+
description: string;
|
|
37
|
+
mascot?: ThemeMascot;
|
|
38
|
+
workingPhrases?: string[];
|
|
39
|
+
critters?: string[];
|
|
40
|
+
avatarHat?: string;
|
|
41
|
+
light?: ThemePalette;
|
|
42
|
+
dark?: ThemePalette;
|
|
43
|
+
};
|
|
44
|
+
type ThemeArtwork = {
|
|
45
|
+
hats?: Record<string, {
|
|
46
|
+
url: string;
|
|
47
|
+
}>;
|
|
48
|
+
critters?: Record<string, {
|
|
49
|
+
url: string;
|
|
50
|
+
title?: string;
|
|
51
|
+
crossMs?: number;
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
54
|
+
type ThemeDescriptor = {
|
|
55
|
+
id: ThemeId;
|
|
56
|
+
name: string;
|
|
57
|
+
description: string;
|
|
58
|
+
source: "builtin" | "plugin" | "user";
|
|
59
|
+
modes: ThemeColorMode[];
|
|
60
|
+
pluginId?: string;
|
|
61
|
+
mascot?: ThemeMascot;
|
|
62
|
+
workingPhrases?: readonly string[];
|
|
63
|
+
critters?: readonly string[];
|
|
64
|
+
avatarHat?: string;
|
|
65
|
+
artwork?: ThemeArtwork;
|
|
66
|
+
};
|
|
67
|
+
type ThemeCatalogEntry = ThemeDescriptor & {
|
|
68
|
+
definition?: ThemeDefinition;
|
|
69
|
+
};
|
|
70
|
+
type ThemeBranding = {
|
|
71
|
+
mascot: ThemeMascot;
|
|
72
|
+
workingPhrases?: readonly string[];
|
|
73
|
+
critters: readonly string[];
|
|
74
|
+
avatarHat?: string;
|
|
75
|
+
artwork?: ThemeArtwork;
|
|
76
|
+
};
|
|
77
|
+
declare function resolveThemeBranding(source: Pick<ThemeDescriptor, "mascot" | "workingPhrases" | "critters" | "avatarHat" | "artwork"> | undefined): ThemeBranding;
|
|
78
|
+
declare const BUILTIN_THEMES: readonly ThemeDescriptor[];
|
|
79
|
+
/** Rejects executable CSS and incomplete palettes before they reach storage or a stylesheet. */
|
|
80
|
+
declare function normalizeThemeDefinition(input: unknown, options?: {
|
|
81
|
+
hatIds?: readonly string[];
|
|
82
|
+
critterIds?: readonly string[];
|
|
83
|
+
}): ThemeDefinition;
|
|
84
|
+
declare function parseThemeDefinition(value: unknown): ThemeDefinition | null;
|
|
85
|
+
//#endregion
|
|
86
|
+
export { BuiltinThemeId as A, ThemePalette as C, parseThemeDefinition as D, normalizeThemeDefinition as E, isBuiltinThemeId as F, isThemeId as I, normalizeThemeMode as L, THEME_LOCAL_ID_PATTERN as M, ThemeId as N, resolveThemeBranding as O, ThemeMode as P, ThemeMascot as S, isThemeCritterId as T, ThemeCatalogEntry as _, THEME_COLOR_KEYS as a, ThemeDefinition as b, THEME_FONT_KEYS as c, THEME_TOKEN_MAX_LENGTH as d, THEME_WORKING_PHRASES_MAX as f, ThemeBranding as g, ThemeAvatarHatId as h, THEME_AVATAR_HAT_IDS as i, THEME_LOCAL_ID_MAX_LENGTH as j, BUILTIN_THEME_IDS as k, THEME_MASCOT_VALUES as l, ThemeArtwork as m, MAX_THEME_DEFINITION_BYTES as n, THEME_CRITTER_IDS as o, THEME_WORKING_PHRASE_MAX_LENGTH as p, THEME_ARTWORK_ID_PATTERN as r, THEME_DESCRIPTION_MAX_LENGTH as s, BUILTIN_THEMES as t, THEME_NAME_MAX_LENGTH as u, ThemeColorMode as v, isThemeAvatarHatId as w, ThemeDescriptor as x, ThemeCritterId as y };
|
package/dist/theme.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { A as BuiltinThemeId, C as ThemePalette, D as parseThemeDefinition, E as normalizeThemeDefinition, F as isBuiltinThemeId, I as isThemeId, L as normalizeThemeMode, M as THEME_LOCAL_ID_PATTERN, N as ThemeId, O as resolveThemeBranding, P as ThemeMode, S as ThemeMascot, T as isThemeCritterId, _ as ThemeCatalogEntry, a as THEME_COLOR_KEYS, b as ThemeDefinition, c as THEME_FONT_KEYS, d as THEME_TOKEN_MAX_LENGTH, f as THEME_WORKING_PHRASES_MAX, g as ThemeBranding, h as ThemeAvatarHatId, i as THEME_AVATAR_HAT_IDS, j as THEME_LOCAL_ID_MAX_LENGTH, k as BUILTIN_THEME_IDS, l as THEME_MASCOT_VALUES, m as ThemeArtwork, n as MAX_THEME_DEFINITION_BYTES, o as THEME_CRITTER_IDS, p as THEME_WORKING_PHRASE_MAX_LENGTH, r as THEME_ARTWORK_ID_PATTERN, s as THEME_DESCRIPTION_MAX_LENGTH, t as BUILTIN_THEMES, u as THEME_NAME_MAX_LENGTH, v as ThemeColorMode, w as isThemeAvatarHatId, x as ThemeDescriptor, y as ThemeCritterId } from "./theme-s6T9Ck6Z.mjs";
|
|
2
|
+
export { BUILTIN_THEMES, BUILTIN_THEME_IDS, type BuiltinThemeId, MAX_THEME_DEFINITION_BYTES, THEME_ARTWORK_ID_PATTERN, THEME_AVATAR_HAT_IDS, THEME_COLOR_KEYS, THEME_CRITTER_IDS, THEME_DESCRIPTION_MAX_LENGTH, THEME_FONT_KEYS, THEME_LOCAL_ID_MAX_LENGTH, THEME_LOCAL_ID_PATTERN, THEME_MASCOT_VALUES, THEME_NAME_MAX_LENGTH, THEME_TOKEN_MAX_LENGTH, THEME_WORKING_PHRASES_MAX, THEME_WORKING_PHRASE_MAX_LENGTH, ThemeArtwork, ThemeAvatarHatId, ThemeBranding, ThemeCatalogEntry, ThemeColorMode, ThemeCritterId, ThemeDefinition, ThemeDescriptor, type ThemeId, ThemeMascot, type ThemeMode, ThemePalette, isBuiltinThemeId, isThemeAvatarHatId, isThemeCritterId, isThemeId, normalizeThemeDefinition, normalizeThemeMode, parseThemeDefinition, resolveThemeBranding };
|
package/dist/theme.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { C as isThemeId, S as isBuiltinThemeId, _ as parseThemeDefinition, a as THEME_COLOR_KEYS, b as THEME_LOCAL_ID_MAX_LENGTH, c as THEME_FONT_KEYS, d as THEME_TOKEN_MAX_LENGTH, f as THEME_WORKING_PHRASES_MAX, g as normalizeThemeDefinition, h as isThemeCritterId, i as THEME_AVATAR_HAT_IDS, l as THEME_MASCOT_VALUES, m as isThemeAvatarHatId, n as MAX_THEME_DEFINITION_BYTES, o as THEME_CRITTER_IDS, p as THEME_WORKING_PHRASE_MAX_LENGTH, r as THEME_ARTWORK_ID_PATTERN, s as THEME_DESCRIPTION_MAX_LENGTH, t as BUILTIN_THEMES, u as THEME_NAME_MAX_LENGTH, v as resolveThemeBranding, w as normalizeThemeMode, x as THEME_LOCAL_ID_PATTERN, y as BUILTIN_THEME_IDS } from "./theme-_hQKgfH-.mjs";
|
|
2
|
+
export { BUILTIN_THEMES, BUILTIN_THEME_IDS, MAX_THEME_DEFINITION_BYTES, THEME_ARTWORK_ID_PATTERN, THEME_AVATAR_HAT_IDS, THEME_COLOR_KEYS, THEME_CRITTER_IDS, THEME_DESCRIPTION_MAX_LENGTH, THEME_FONT_KEYS, THEME_LOCAL_ID_MAX_LENGTH, THEME_LOCAL_ID_PATTERN, THEME_MASCOT_VALUES, THEME_NAME_MAX_LENGTH, THEME_TOKEN_MAX_LENGTH, THEME_WORKING_PHRASES_MAX, THEME_WORKING_PHRASE_MAX_LENGTH, isBuiltinThemeId, isThemeAvatarHatId, isThemeCritterId, isThemeId, normalizeThemeDefinition, normalizeThemeMode, parseThemeDefinition, resolveThemeBranding };
|