feat(device-core): add device ownership lifecycle

This commit is contained in:
Codex
2026-08-10 18:03:56 +03:00
parent 72db23c0e9
commit fceaca9546
17 changed files with 2218 additions and 54 deletions
@@ -48,6 +48,9 @@ export function normalizeDiscoverySignal(input) {
}
const sessionRef = normalizeOpaqueRef(input.sessionRef, "session_ref");
const routeRef = input.routeRef == null
? undefined
: normalizeEntityRef(input.routeRef, "route", "route_ref");
const modelProfileRef = normalizeOpaqueRef(
input.modelProfileRef,
"model_profile_ref",
@@ -60,6 +63,7 @@ export function normalizeDiscoverySignal(input) {
return Object.freeze({
schemaVersion: DEVICE_DISCOVERY_SIGNAL_SCHEMA,
sessionRef,
...(routeRef ? { routeRef } : {}),
modelProfileRef,
protocol,
observedAt,
@@ -79,6 +83,7 @@ export function toSafeDiscoveryView(signal, options = {}) {
return Object.freeze({
schemaVersion: DEVICE_DISCOVERY_VIEW_SCHEMA,
...(discoveryRef ? { discoveryRef } : {}),
...(normalized.routeRef ? { routeRef: normalized.routeRef } : {}),
modelProfileRef: normalized.modelProfileRef,
protocol: normalized.protocol,
observedAt: normalized.observedAt,
@@ -216,6 +221,19 @@ function normalizeOpaqueRef(value, label) {
return value;
}
function normalizeEntityRef(value, prefix, label) {
if (
typeof value !== "string"
|| !new RegExp(
`^${prefix}:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`,
"i",
).test(value)
) {
throw new TypeError(`${label}_invalid`);
}
return value.toLowerCase();
}
function normalizeUpperToken(value, label) {
if (typeof value !== "string" || !/^[A-Z][A-Z0-9_]{0,31}$/.test(value)) {
throw new TypeError(`${label}_invalid`);