@vellumai/credential-executor 0.10.6-dev.202607070525.69af9c2 → 0.10.6-dev.202607070801.a5f625d
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.
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-metadata analytics headers.
|
|
3
|
+
*
|
|
4
|
+
* The web client attaches these to every daemon request via
|
|
5
|
+
* `getClientRegistrationHeaders()` (`clients/web/src/lib/telemetry/
|
|
6
|
+
* client-identity.ts`), the gateway allows them through webview CORS
|
|
7
|
+
* (`gateway/src/http/middleware/cors.ts`) and forwards them to the daemon
|
|
8
|
+
* by `x-vellum-*` prefix, and the daemon persists them under
|
|
9
|
+
* `metadata.client` on user messages (`handleSendMessage`), where
|
|
10
|
+
* `turn-events-store` projects them onto `TurnTelemetryEvent.client` for
|
|
11
|
+
* downstream analytics.
|
|
12
|
+
*
|
|
13
|
+
* Keys are the persisted `metadata.client` field names; values are the
|
|
14
|
+
* lowercase HTTP header names (HTTP header matching is case-insensitive).
|
|
15
|
+
*/
|
|
16
|
+
export const CLIENT_METADATA_HEADERS = {
|
|
17
|
+
browser_family: "x-vellum-browser-family",
|
|
18
|
+
browser_version: "x-vellum-browser-version",
|
|
19
|
+
os: "x-vellum-client-os",
|
|
20
|
+
interface_version: "x-vellum-interface-version",
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
export type ClientMetadataField = keyof typeof CLIENT_METADATA_HEADERS;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Bound on client-metadata header values: lowercase alphanumerics plus
|
|
27
|
+
* dot / underscore / dash, at most 64 chars. Enforced identically by the
|
|
28
|
+
* sender (web client) and the reader (daemon) so malformed or oversized
|
|
29
|
+
* values are dropped rather than transmitted or persisted.
|
|
30
|
+
*/
|
|
31
|
+
const CLIENT_METADATA_VALUE_RE = /^[a-z0-9._-]{1,64}$/;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Normalize a candidate client-metadata value (trim + lowercase) and
|
|
35
|
+
* validate it against {@link CLIENT_METADATA_VALUE_RE}. Returns `undefined`
|
|
36
|
+
* for empty or out-of-bounds values.
|
|
37
|
+
*/
|
|
38
|
+
export function sanitizeClientMetadataValue(
|
|
39
|
+
value: string | undefined | null,
|
|
40
|
+
): string | undefined {
|
|
41
|
+
const normalized = value?.trim().toLowerCase();
|
|
42
|
+
if (!normalized) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return CLIENT_METADATA_VALUE_RE.test(normalized) ? normalized : undefined;
|
|
46
|
+
}
|