@camstack/server 1.2.809 → 1.2.811
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/CHANGELOG.md +17 -0
- package/dist/api/trpc/cap-router-runtime.js +3 -0
- package/dist/api/trpc/generated-cap-mounts.js +3 -1
- package/dist/api/trpc/generated-cap-routers.js +1869 -1789
- package/dist/core/addon/hub-addon-api.js +8 -1
- package/dist/core/moleculer/moleculer.service.js +3 -0
- package/package.json +10 -8
- package/system/dist/addon-runner.js +4 -1
- package/system/dist/addon-runner.mjs +5 -2
- package/system/dist/{agent-https-DS4b0ucn.mjs → agent-https-CyEBY3RB.mjs} +1 -1
- package/system/dist/{agent-https-CuChFRA2.js → agent-https-a3mE4PW4.js} +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/alerts/alerts.addon.js +3 -101
- package/system/dist/builtins/alerts/alerts.addon.mjs +40 -134
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
- package/system/dist/builtins/backup-orchestrator/destination-policy.d.ts +1 -1
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/index.js +1 -1
- package/system/dist/builtins/camera-grid/index.mjs +1 -1
- package/system/dist/builtins/composer/composer.addon.js +6 -5
- package/system/dist/builtins/composer/composer.addon.mjs +6 -5
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +2 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +358 -32
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +361 -35
- package/system/dist/builtins/core-blocks/hero-layout-service.d.ts +42 -0
- package/system/dist/builtins/core-blocks/remote-call-redirect.d.ts +1 -1
- package/system/dist/builtins/core-blocks/remote-service.d.ts +38 -0
- package/system/dist/builtins/device-history/device-history.addon.d.ts +5 -0
- package/system/dist/builtins/device-history/device-history.addon.js +357 -18
- package/system/dist/builtins/device-history/device-history.addon.mjs +357 -18
- package/system/dist/builtins/device-history/retention/retention.d.ts +14 -1
- package/system/dist/builtins/device-history/transitions/device-transitions-record-kinds.d.ts +14 -0
- package/system/dist/builtins/device-history/transitions/transitions-service.d.ts +80 -0
- package/system/dist/builtins/device-manager/device-manager.addon.d.ts +2 -0
- package/system/dist/builtins/device-manager/device-manager.addon.js +712 -18
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +780 -95
- package/system/dist/builtins/device-manager/device-state-mirror.d.ts +7 -0
- package/system/dist/builtins/device-manager/transitions/command-args.d.ts +4 -0
- package/system/dist/builtins/device-manager/transitions/transition-correlator.d.ts +68 -0
- package/system/dist/builtins/device-manager/transitions/transitions-sender.d.ts +37 -0
- package/system/dist/builtins/device-manager/transitions/transitions-wiring.d.ts +25 -0
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +4 -4
- package/system/dist/builtins/keychain/index.mjs +4 -4
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
- package/system/dist/builtins/local-network/local-network.addon.js +2 -2
- package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
- package/system/dist/builtins/loki-logging/index.js +8 -2
- package/system/dist/builtins/loki-logging/index.mjs +8 -2
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +1 -1
- package/system/dist/builtins/record-entries/index.js +1 -1
- package/system/dist/builtins/record-entries/index.mjs +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +1 -1
- package/system/dist/builtins/snapshot/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
- package/system/dist/builtins/storage-orchestrator/location-store.d.ts +0 -6
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +3 -3
- package/system/dist/builtins/system-config/system-config.addon.mjs +7 -7
- package/system/dist/builtins/winston-logging/index.js +1 -1
- package/system/dist/builtins/winston-logging/index.mjs +1 -1
- package/system/dist/{capture-engine-Byc5Fkp0.js → capture-engine-BO9mSlY-.js} +1 -1
- package/system/dist/{capture-engine-CnVIcnyN.mjs → capture-engine-ByF-6AFH.mjs} +1 -1
- package/system/dist/{composition-sources-BhM6G9QT.mjs → composition-sources-AziMFo7T.mjs} +1 -1
- package/system/dist/{composition-sources-BxK6ttP9.js → composition-sources-BMJUPUh2.js} +1 -1
- package/system/dist/{constants-Bf1PEHRU.mjs → constants-CTikgsC_.mjs} +1 -1
- package/system/dist/{constants--xo6Q-KA.js → constants-CjRlgRlu.js} +1 -1
- package/system/dist/{device-ca-Do0-HV_h.mjs → device-ca-CNRlFqFC.mjs} +1 -1
- package/system/dist/{device-ca-Uq5KGFSq.js → device-ca-Dxl6kVcJ.js} +1 -1
- package/system/dist/{dist-CogtCQxu.mjs → dist-BPq13Y8j.mjs} +17544 -15612
- package/system/dist/{dist-2SHQaxaS.js → dist-CkJnelZr.js} +17615 -15617
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-mdns-ciao-aFHCKrif.mjs → hub-mdns-ciao-CrjItezp.mjs} +2 -2
- package/system/dist/{hub-mdns-ciao-DqPrLiYH.js → hub-mdns-ciao-Cx6yJBl9.js} +2 -2
- package/system/dist/index.js +67 -75
- package/system/dist/index.mjs +53 -68
- package/system/dist/kernel/cap-router-builder.d.ts +9 -0
- package/system/dist/kernel/command-observation.d.ts +76 -0
- package/system/dist/kernel/index.d.ts +2 -0
- package/system/dist/kernel/transport/child-cap-protocol.d.ts +10 -1
- package/system/dist/kernel/transport/local-child-registry.d.ts +15 -0
- package/system/dist/{legacy-integration-rows-door-Bz8rivxI.js → legacy-integration-rows-door-CKM-LxvL.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-CiuxDLoc.mjs → legacy-integration-rows-door-Dxcqwc-w.mjs} +1 -1
- package/system/dist/log-redactor-BhIEMaG9.js +149 -0
- package/system/dist/log-redactor-XLDrPzOi.mjs +120 -0
- package/system/dist/logging/log-redactor.d.ts +2 -0
- package/system/dist/{restore-archive-PlBC2NwT.mjs → restore-archive-BFA-hEhX.mjs} +5 -5
- package/system/dist/{restore-archive-D-3wmHDq.js → restore-archive-BQWOdGAB.js} +1 -1
- package/system/dist/{retention-BNONb5X_.js → retention-BcOSL6b9.js} +33 -2
- package/system/dist/{retention-B9l9TnGE.mjs → retention-CUOVI1p7.mjs} +33 -2
- package/system/dist/{wal-maintenance-BTR55y--.js → wal-maintenance-CiCgL4Hp.js} +0 -0
- package/system/dist/{wal-maintenance-jrhYTCn2.mjs → wal-maintenance-zJ4-ORo6.mjs} +0 -0
- package/system/package.json +7 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ac as resolveSecretMarkers, Cr as enumerateItemArrayFields, Ea as runtimeStatePolicyFor, Es as SECRET_CLEAR, Fc as sleep$2, Fn as canonicalIconKey, Gc as errMsg$1, Hc as DeviceFeature, Ii as normalizeUnit, L as DAY_NAMES, La as siteZoneKey, Lc as toSecretFieldView, Mc as secretTreeFromPaths, Mn as buildStreamParamsConfigSchema, Or as expandContainer, Q as DiscoveryProposalBodySchema, Rc as transformSecretWrite, Rn as checkDeviceAlias, Rs as auditedFields, Uc as DeviceRole, Ui as parseStreamParamsFormPatch, Us as collectZodSecretPaths$1, Vr as generateDeviceAlias, Wc as DeviceType$1, Ws as commandEffect, X as DeviceStatusSchema, Xo as BaseAddon, Yt as STREAM_PROFILE_META, Z as DeviceTombstoneSchema, Zs as defineRecordKinds, _ as CAMERA_SWITCH_ORDER, br as deviceStatusCapability, cc as isDeviceConfigCap, ct as FieldClaimSchema, dc as isKeychainStoredField, ec as expandCapMethods$1, gc as isSecretMarkerLike, gr as deviceManagerCapability, hc as isSecretMarker, js as WELL_KNOWN_TAB_MAP, li as legacyAutoLinkIds, lr as defineExtensionSlotProvider, mi as locationIconKey, mr as deviceExtensionCapability, nr as createDeviceExtensionProvider, oc as isCommand$1, pc as isSecretClear, qc as EventCategory$1, s as ALL_CAPABILITY_DEFINITIONS, st as FieldClaimModeSchema, wr as enumerateSchemaFields, wt as MINUTES_PER_DAY, y as CAP_NAMES_WITH_STATUS, yr as deviceStateCapability, zc as userError, zr as formatMinutes } from "../../dist-BPq13Y8j.mjs";
|
|
2
2
|
import { t as require_read_all_rows } from "../../read-all-rows-TaPqdWNF.mjs";
|
|
3
|
+
import { a as redactLogText, i as redactLogMeta, n as isSecretArgumentKey } from "../../log-redactor-XLDrPzOi.mjs";
|
|
3
4
|
import { t as prefixRange } from "../../prefix-range-Dl0znowN.mjs";
|
|
4
5
|
import { t as loadPrefixed } from "../../prefix-walk-DAOBSyH1.mjs";
|
|
5
6
|
import { n as purgeRetiredSettingsRows } from "../../retired-settings-keys-u6xQA6r7.mjs";
|
|
@@ -7,6 +8,7 @@ import { s as normalizeServiceType } from "../../dns-wire-Dm3H_7ST.mjs";
|
|
|
7
8
|
import { z } from "zod";
|
|
8
9
|
import { randomUUID } from "node:crypto";
|
|
9
10
|
import { canonicalDeviceFingerprint } from "@camstack/types/node";
|
|
11
|
+
import { isCommand, readCommandOrigin } from "@camstack/types/addon";
|
|
10
12
|
//#region src/builtins/device-manager/adoption-job-engine.ts
|
|
11
13
|
/** How many finished jobs are kept per (addonId, integrationId). */
|
|
12
14
|
var JOB_HISTORY = 20;
|
|
@@ -165,7 +167,7 @@ var AdoptionJobEngine = class {
|
|
|
165
167
|
job.state = job.cancelRequested ? "cancelled" : "done";
|
|
166
168
|
} catch (err) {
|
|
167
169
|
job.state = "failed";
|
|
168
|
-
job.error = errMsg(err);
|
|
170
|
+
job.error = errMsg$1(err);
|
|
169
171
|
this.deps.logger.error("adoption job failed", {
|
|
170
172
|
tags: { addonId: job.addonId },
|
|
171
173
|
meta: {
|
|
@@ -218,7 +220,7 @@ var AdoptionJobEngine = class {
|
|
|
218
220
|
meta: {
|
|
219
221
|
jobId: job.jobId,
|
|
220
222
|
integrationId: job.integrationId,
|
|
221
|
-
error: errMsg(err)
|
|
223
|
+
error: errMsg$1(err)
|
|
222
224
|
}
|
|
223
225
|
});
|
|
224
226
|
return /* @__PURE__ */ new Set();
|
|
@@ -281,7 +283,7 @@ var AdoptionJobEngine = class {
|
|
|
281
283
|
outcome: "failed",
|
|
282
284
|
parentDeviceId: null,
|
|
283
285
|
accessoryCount: 0,
|
|
284
|
-
error: errMsg(err)
|
|
286
|
+
error: errMsg$1(err)
|
|
285
287
|
});
|
|
286
288
|
this.deps.logger.warn("adoption job: candidate failed", {
|
|
287
289
|
tags: { addonId: job.addonId },
|
|
@@ -290,7 +292,7 @@ var AdoptionJobEngine = class {
|
|
|
290
292
|
integrationId: job.integrationId,
|
|
291
293
|
childNativeId,
|
|
292
294
|
durationMs: this.now() - startedAt,
|
|
293
|
-
error: errMsg(err)
|
|
295
|
+
error: errMsg$1(err)
|
|
294
296
|
}
|
|
295
297
|
});
|
|
296
298
|
}
|
|
@@ -354,7 +356,7 @@ function persistedFeatures(features) {
|
|
|
354
356
|
* of 2026-08-31: `listAll` said camera, `getDevice` said not).
|
|
355
357
|
*/
|
|
356
358
|
function persistedIsCamera(type) {
|
|
357
|
-
return type === DeviceType.Camera;
|
|
359
|
+
return type === DeviceType$1.Camera;
|
|
358
360
|
}
|
|
359
361
|
/**
|
|
360
362
|
* Build an identity-only `SourceInfo` from the persisted device config blob.
|
|
@@ -399,7 +401,7 @@ function toDeviceRole(value) {
|
|
|
399
401
|
function liveSecretConfigPaths(device) {
|
|
400
402
|
const schema = device.config?.schema;
|
|
401
403
|
if (schema === void 0 || schema === null || typeof schema !== "object") return {};
|
|
402
|
-
const paths = collectZodSecretPaths(schema);
|
|
404
|
+
const paths = collectZodSecretPaths$1(schema);
|
|
403
405
|
return paths.length > 0 ? { secretConfigPaths: [...paths] } : {};
|
|
404
406
|
}
|
|
405
407
|
function toDeviceInfo(addonId, device, metadata = null, metaRow = null) {
|
|
@@ -880,7 +882,7 @@ var ContributionCache = class {
|
|
|
880
882
|
entry.inFlight = null;
|
|
881
883
|
});
|
|
882
884
|
entry.inFlight = refresh;
|
|
883
|
-
await Promise.race([refresh, sleep(afterWrite ? readbackBudgetMs : budgetMs)]);
|
|
885
|
+
await Promise.race([refresh, sleep$1(afterWrite ? readbackBudgetMs : budgetMs)]);
|
|
884
886
|
if (settled && !failed) return {
|
|
885
887
|
kind: "fresh",
|
|
886
888
|
value: answer
|
|
@@ -920,7 +922,7 @@ var ContributionCache = class {
|
|
|
920
922
|
}
|
|
921
923
|
}
|
|
922
924
|
};
|
|
923
|
-
function sleep(ms) {
|
|
925
|
+
function sleep$1(ms) {
|
|
924
926
|
return new Promise((resolve) => {
|
|
925
927
|
setTimeout(resolve, ms).unref?.();
|
|
926
928
|
});
|
|
@@ -1095,11 +1097,11 @@ function mergeAggregates(parts) {
|
|
|
1095
1097
|
* per-row path (`connection.password`, `rows[].pin`) is not mapped onto a form
|
|
1096
1098
|
* field and keeps the driver's hydration.
|
|
1097
1099
|
*/
|
|
1098
|
-
function isRecord$
|
|
1100
|
+
function isRecord$3(value) {
|
|
1099
1101
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1100
1102
|
}
|
|
1101
1103
|
function isConfigFieldWithValue(field) {
|
|
1102
|
-
if (!isRecord$
|
|
1104
|
+
if (!isRecord$3(field)) return false;
|
|
1103
1105
|
return typeof field.type === "string" && typeof field.key === "string" && "value" in field;
|
|
1104
1106
|
}
|
|
1105
1107
|
/** The declared paths that name a top-level config key. */
|
|
@@ -1107,7 +1109,7 @@ function topLevelKeys(paths) {
|
|
|
1107
1109
|
return new Set(paths.filter((p) => p.length > 0 && !p.includes(".") && !p.includes("[")));
|
|
1108
1110
|
}
|
|
1109
1111
|
function viewField(field, stored, declared) {
|
|
1110
|
-
if (!isRecord$
|
|
1112
|
+
if (!isRecord$3(field)) return field;
|
|
1111
1113
|
const nested = field["fields"];
|
|
1112
1114
|
if (Array.isArray(nested)) return {
|
|
1113
1115
|
...field,
|
|
@@ -1116,7 +1118,7 @@ function viewField(field, stored, declared) {
|
|
|
1116
1118
|
const tabs = field["tabs"];
|
|
1117
1119
|
if (Array.isArray(tabs)) return {
|
|
1118
1120
|
...field,
|
|
1119
|
-
tabs: tabs.map((tab) => isRecord$
|
|
1121
|
+
tabs: tabs.map((tab) => isRecord$3(tab) && Array.isArray(tab["fields"]) ? {
|
|
1120
1122
|
...tab,
|
|
1121
1123
|
fields: tab["fields"].map((f) => viewField(f, stored, declared))
|
|
1122
1124
|
} : tab)
|
|
@@ -1225,7 +1227,7 @@ function isDeclaredCollectionCap(capName) {
|
|
|
1225
1227
|
function isDeclaredNonWrapperCap(capName) {
|
|
1226
1228
|
return DECLARED_NON_WRAPPER_CAPS.has(capName);
|
|
1227
1229
|
}
|
|
1228
|
-
function isRecord$
|
|
1230
|
+
function isRecord$2(value) {
|
|
1229
1231
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1230
1232
|
}
|
|
1231
1233
|
/** A persisted activation of a wrapper on a cap that has none (see module docblock). */
|
|
@@ -1268,12 +1270,12 @@ var StaleWrapperActivations = class {
|
|
|
1268
1270
|
if (this.checked) return;
|
|
1269
1271
|
this.checked = true;
|
|
1270
1272
|
const devices = store.deviceBindings;
|
|
1271
|
-
if (!isRecord$
|
|
1273
|
+
if (!isRecord$2(devices)) return;
|
|
1272
1274
|
for (const [deviceKey, perDevice] of Object.entries(devices)) {
|
|
1273
1275
|
const deviceId = Number(deviceKey);
|
|
1274
|
-
if (!Number.isInteger(deviceId) || !isRecord$
|
|
1276
|
+
if (!Number.isInteger(deviceId) || !isRecord$2(perDevice)) continue;
|
|
1275
1277
|
for (const [capName, row] of Object.entries(perDevice)) {
|
|
1276
|
-
const wrapperAddonId = isRecord$
|
|
1278
|
+
const wrapperAddonId = isRecord$2(row) ? row["wrapperAddonId"] : void 0;
|
|
1277
1279
|
if (typeof wrapperAddonId === "string" && isDeclaredNonWrapperCap(capName)) this.report(deviceId, capName, wrapperAddonId);
|
|
1278
1280
|
}
|
|
1279
1281
|
}
|
|
@@ -1314,7 +1316,7 @@ var StaleWrapperActivations = class {
|
|
|
1314
1316
|
*/
|
|
1315
1317
|
function wireRemoteNativeCapSync(ctx, remoteNativeCaps) {
|
|
1316
1318
|
const localNodeId = ctx.kernel.localNodeId ?? "hub";
|
|
1317
|
-
ctx.eventBus.subscribe({ category: EventCategory.DeviceBindingsChanged }, (event) => {
|
|
1319
|
+
ctx.eventBus.subscribe({ category: EventCategory$1.DeviceBindingsChanged }, (event) => {
|
|
1318
1320
|
const { deviceId, capName, reason, addonId, nodeId } = event.data;
|
|
1319
1321
|
if (nodeId === localNodeId) return;
|
|
1320
1322
|
if (reason === "native-registered") {
|
|
@@ -2822,7 +2824,7 @@ async function listAll(pctx, input) {
|
|
|
2822
2824
|
} : info);
|
|
2823
2825
|
}
|
|
2824
2826
|
}
|
|
2825
|
-
const configs = await readDeviceConfigs(pctx, slim ? [] : fleet.filter((row) => !seen.has(String(row.meta.id))).filter((row) => idFilter === null || idFilter.has(row.meta.id)).filter((row) => !camerasOnly || row.meta.type === DeviceType.Camera).map((row) => row.meta.id));
|
|
2827
|
+
const configs = await readDeviceConfigs(pctx, slim ? [] : fleet.filter((row) => !seen.has(String(row.meta.id))).filter((row) => idFilter === null || idFilter.has(row.meta.id)).filter((row) => !camerasOnly || row.meta.type === DeviceType$1.Camera).map((row) => row.meta.id));
|
|
2826
2828
|
for (const row of fleet) {
|
|
2827
2829
|
const m = row.meta;
|
|
2828
2830
|
const aid = m.addonId;
|
|
@@ -2830,7 +2832,7 @@ async function listAll(pctx, input) {
|
|
|
2830
2832
|
if (seen.has(String(m.id))) continue;
|
|
2831
2833
|
if (idFilter !== null && !idFilter.has(m.id)) continue;
|
|
2832
2834
|
const persistedType = m.type;
|
|
2833
|
-
if (camerasOnly && persistedType !== DeviceType.Camera) continue;
|
|
2835
|
+
if (camerasOnly && persistedType !== DeviceType$1.Camera) continue;
|
|
2834
2836
|
const persistedConfig = configs.get(m.id) ?? {};
|
|
2835
2837
|
const metadata = slim ? null : row.metadata;
|
|
2836
2838
|
results.push({
|
|
@@ -3203,7 +3205,7 @@ async function remove(pctx, input) {
|
|
|
3203
3205
|
deviceId: id,
|
|
3204
3206
|
deviceName: persistedMeta.name
|
|
3205
3207
|
},
|
|
3206
|
-
meta: { error: errMsg(err) }
|
|
3208
|
+
meta: { error: errMsg$1(err) }
|
|
3207
3209
|
});
|
|
3208
3210
|
}
|
|
3209
3211
|
await pctx.provider.removeDevice({ deviceId: id });
|
|
@@ -3318,7 +3320,7 @@ async function adoptDevice(pctx, input) {
|
|
|
3318
3320
|
deviceId: summary.id,
|
|
3319
3321
|
integrationId: input.integrationId
|
|
3320
3322
|
},
|
|
3321
|
-
meta: { error: errMsg(err) }
|
|
3323
|
+
meta: { error: errMsg$1(err) }
|
|
3322
3324
|
});
|
|
3323
3325
|
}
|
|
3324
3326
|
return summary;
|
|
@@ -3347,7 +3349,7 @@ async function createDevice(pctx, input) {
|
|
|
3347
3349
|
deviceId: summary.id,
|
|
3348
3350
|
integrationId: input.integrationId
|
|
3349
3351
|
},
|
|
3350
|
-
meta: { error: errMsg(err) }
|
|
3352
|
+
meta: { error: errMsg$1(err) }
|
|
3351
3353
|
});
|
|
3352
3354
|
}
|
|
3353
3355
|
return summary;
|
|
@@ -3440,7 +3442,7 @@ async function testField(pctx, input) {
|
|
|
3440
3442
|
error: void 0
|
|
3441
3443
|
};
|
|
3442
3444
|
return dp.testCreationField({
|
|
3443
|
-
type: DeviceType.Camera,
|
|
3445
|
+
type: DeviceType$1.Camera,
|
|
3444
3446
|
key: input.key,
|
|
3445
3447
|
value: input.value
|
|
3446
3448
|
});
|
|
@@ -3668,7 +3670,7 @@ function refusedLinkedPicks(params) {
|
|
|
3668
3670
|
deviceId,
|
|
3669
3671
|
reason: "unknown"
|
|
3670
3672
|
});
|
|
3671
|
-
else if (device.type === DeviceType.Container) out.push({
|
|
3673
|
+
else if (device.type === DeviceType$1.Container) out.push({
|
|
3672
3674
|
deviceId,
|
|
3673
3675
|
reason: "container"
|
|
3674
3676
|
});
|
|
@@ -3691,7 +3693,7 @@ async function driverSectionsWithSecretViews(deps, deviceId, sections) {
|
|
|
3691
3693
|
} catch (err) {
|
|
3692
3694
|
deps.ctx.logger.warn("device form: stored config unreadable — secret views not applied", {
|
|
3693
3695
|
tags: { deviceId },
|
|
3694
|
-
meta: { error: errMsg(err) }
|
|
3696
|
+
meta: { error: errMsg$1(err) }
|
|
3695
3697
|
});
|
|
3696
3698
|
return sections;
|
|
3697
3699
|
}
|
|
@@ -4082,7 +4084,7 @@ async function getDeviceStatusAggregate(deps, input, options) {
|
|
|
4082
4084
|
tags: { deviceId: input.deviceId },
|
|
4083
4085
|
meta: {
|
|
4084
4086
|
capName,
|
|
4085
|
-
error: errMsg(err)
|
|
4087
|
+
error: errMsg$1(err)
|
|
4086
4088
|
}
|
|
4087
4089
|
});
|
|
4088
4090
|
out[capName] = null;
|
|
@@ -4140,7 +4142,7 @@ async function getDeviceStatusAggregateBatch(deps, input, options) {
|
|
|
4140
4142
|
} catch (err) {
|
|
4141
4143
|
deps.ctx.logger.warn("getDeviceStatusAggregateBatch: device aggregation threw", {
|
|
4142
4144
|
tags: { deviceId },
|
|
4143
|
-
meta: { error: errMsg(err) }
|
|
4145
|
+
meta: { error: errMsg$1(err) }
|
|
4144
4146
|
});
|
|
4145
4147
|
out[String(deviceId)] = {};
|
|
4146
4148
|
}
|
|
@@ -4173,7 +4175,7 @@ async function resolveDriverConfigSchema(deps, deviceId, hubLocal) {
|
|
|
4173
4175
|
const RETRY_DELAY_MS = 750;
|
|
4174
4176
|
let lastErr;
|
|
4175
4177
|
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
4176
|
-
if (attempt > 0) await sleep$
|
|
4178
|
+
if (attempt > 0) await sleep$2(RETRY_DELAY_MS);
|
|
4177
4179
|
try {
|
|
4178
4180
|
const schema = await ops.getSettingsSchema({ deviceId });
|
|
4179
4181
|
if (!schema) return { status: "none" };
|
|
@@ -4190,12 +4192,12 @@ async function resolveDriverConfigSchema(deps, deviceId, hubLocal) {
|
|
|
4190
4192
|
meta: {
|
|
4191
4193
|
attempt: attempt + 1,
|
|
4192
4194
|
maxRetries: MAX_RETRIES,
|
|
4193
|
-
error: errMsg(err)
|
|
4195
|
+
error: errMsg$1(err)
|
|
4194
4196
|
}
|
|
4195
4197
|
});
|
|
4196
4198
|
}
|
|
4197
4199
|
}
|
|
4198
|
-
const msg = errMsg(lastErr);
|
|
4200
|
+
const msg = errMsg$1(lastErr);
|
|
4199
4201
|
deps.ctx.logger.warn("cross-process getSettingsSchema failed after retries — driver settings temporarily unavailable", {
|
|
4200
4202
|
tags: { deviceId },
|
|
4201
4203
|
meta: { error: msg }
|
|
@@ -4499,7 +4501,7 @@ async function ownedOrigins(deps) {
|
|
|
4499
4501
|
try {
|
|
4500
4502
|
return await deps.originStableIds();
|
|
4501
4503
|
} catch (err) {
|
|
4502
|
-
deps.logger.warn("discovery: integration origins unreadable, hiding nothing", { meta: { error: errMsg(err) } });
|
|
4504
|
+
deps.logger.warn("discovery: integration origins unreadable, hiding nothing", { meta: { error: errMsg$1(err) } });
|
|
4503
4505
|
return /* @__PURE__ */ new Set();
|
|
4504
4506
|
}
|
|
4505
4507
|
}
|
|
@@ -4526,7 +4528,7 @@ async function discoverProviders(deps, request) {
|
|
|
4526
4528
|
addonId,
|
|
4527
4529
|
provider: null,
|
|
4528
4530
|
modes: [],
|
|
4529
|
-
error: errMsg(err)
|
|
4531
|
+
error: errMsg$1(err)
|
|
4530
4532
|
};
|
|
4531
4533
|
}
|
|
4532
4534
|
}));
|
|
@@ -4547,7 +4549,7 @@ async function discoverProviders(deps, request) {
|
|
|
4547
4549
|
...request.subnets !== void 0 ? { subnets: request.subnets } : {}
|
|
4548
4550
|
});
|
|
4549
4551
|
} catch (err) {
|
|
4550
|
-
scanError = errMsg(err);
|
|
4552
|
+
scanError = errMsg$1(err);
|
|
4551
4553
|
deps.logger.warn("discovery: network scan failed", { meta: { error: scanError } });
|
|
4552
4554
|
}
|
|
4553
4555
|
const owned = await ownedOrigins(deps);
|
|
@@ -4585,12 +4587,12 @@ async function discoverProviders(deps, request) {
|
|
|
4585
4587
|
} catch (err) {
|
|
4586
4588
|
deps.logger.warn("discovery provider scan failed", { meta: {
|
|
4587
4589
|
addonId,
|
|
4588
|
-
error: errMsg(err)
|
|
4590
|
+
error: errMsg$1(err)
|
|
4589
4591
|
} });
|
|
4590
4592
|
return {
|
|
4591
4593
|
addonId,
|
|
4592
4594
|
candidates: [],
|
|
4593
|
-
error: errMsg(err)
|
|
4595
|
+
error: errMsg$1(err)
|
|
4594
4596
|
};
|
|
4595
4597
|
}
|
|
4596
4598
|
}))).map((o) => withoutOwned(o, owned));
|
|
@@ -4643,7 +4645,7 @@ async function setWrapperActive(deps, input) {
|
|
|
4643
4645
|
type: "addon",
|
|
4644
4646
|
id: deps.ctx.id
|
|
4645
4647
|
},
|
|
4646
|
-
category: EventCategory.DeviceBindingsChanged,
|
|
4648
|
+
category: EventCategory$1.DeviceBindingsChanged,
|
|
4647
4649
|
data: {
|
|
4648
4650
|
deviceId: input.deviceId,
|
|
4649
4651
|
capName: input.capName,
|
|
@@ -4653,7 +4655,7 @@ async function setWrapperActive(deps, input) {
|
|
|
4653
4655
|
}
|
|
4654
4656
|
});
|
|
4655
4657
|
}
|
|
4656
|
-
function isRecord(value) {
|
|
4658
|
+
function isRecord$1(value) {
|
|
4657
4659
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4658
4660
|
}
|
|
4659
4661
|
/** The key of this addon's store that holds every wrapper activation. */
|
|
@@ -4693,19 +4695,19 @@ async function readWrapperActivation(deps, query) {
|
|
|
4693
4695
|
error: "the store holds no deviceBindings row — an empty snapshot is not evidence of an unbind"
|
|
4694
4696
|
};
|
|
4695
4697
|
const deviceBindings = read.value;
|
|
4696
|
-
if (!isRecord(deviceBindings)) return {
|
|
4698
|
+
if (!isRecord$1(deviceBindings)) return {
|
|
4697
4699
|
kind: "failed",
|
|
4698
4700
|
error: "stored deviceBindings is not a map"
|
|
4699
4701
|
};
|
|
4700
4702
|
const perDevice = deviceBindings[String(query.deviceId)];
|
|
4701
4703
|
if (perDevice === void 0) return { kind: "missing" };
|
|
4702
|
-
if (!isRecord(perDevice)) return {
|
|
4704
|
+
if (!isRecord$1(perDevice)) return {
|
|
4703
4705
|
kind: "failed",
|
|
4704
4706
|
error: `stored bindings of device ${query.deviceId} are not a map`
|
|
4705
4707
|
};
|
|
4706
4708
|
const activation = perDevice[query.capName];
|
|
4707
4709
|
if (activation === void 0) return { kind: "missing" };
|
|
4708
|
-
if (!isRecord(activation)) return {
|
|
4710
|
+
if (!isRecord$1(activation)) return {
|
|
4709
4711
|
kind: "failed",
|
|
4710
4712
|
error: `stored "${query.capName}" activation is not a record`
|
|
4711
4713
|
};
|
|
@@ -4857,7 +4859,7 @@ function sourceOf(deviceId, byId) {
|
|
|
4857
4859
|
health: "missing",
|
|
4858
4860
|
detail: "No device has this id any more — it links nothing until removed."
|
|
4859
4861
|
};
|
|
4860
|
-
if (device.type === DeviceType.Container) return {
|
|
4862
|
+
if (device.type === DeviceType$1.Container) return {
|
|
4861
4863
|
deviceId,
|
|
4862
4864
|
name: device.name,
|
|
4863
4865
|
health: "unavailable",
|
|
@@ -4887,7 +4889,7 @@ function refusedTrackedOptIns(params) {
|
|
|
4887
4889
|
}
|
|
4888
4890
|
/** A ledger row as the pure link resolver reads it, or null for an unknown type. */
|
|
4889
4891
|
function toLinkCandidate(row) {
|
|
4890
|
-
const type = Object.values(DeviceType).find((t) => t === row.meta.type);
|
|
4892
|
+
const type = Object.values(DeviceType$1).find((t) => t === row.meta.type);
|
|
4891
4893
|
if (type === void 0) return null;
|
|
4892
4894
|
return {
|
|
4893
4895
|
id: row.meta.id,
|
|
@@ -4911,7 +4913,7 @@ var MAX_CONTAINER_DEPTH = 8;
|
|
|
4911
4913
|
*/
|
|
4912
4914
|
async function impliedLinks(pctx, deviceId, manualIds, pickedRows) {
|
|
4913
4915
|
const rows = new Map(pickedRows);
|
|
4914
|
-
let parents = [deviceId, ...[...pickedRows.values()].filter((r) => r.meta.type === DeviceType.Container).map((r) => r.meta.id)];
|
|
4916
|
+
let parents = [deviceId, ...[...pickedRows.values()].filter((r) => r.meta.type === DeviceType$1.Container).map((r) => r.meta.id)];
|
|
4915
4917
|
const walked = /* @__PURE__ */ new Set();
|
|
4916
4918
|
for (let depth = 0; depth < MAX_CONTAINER_DEPTH && parents.length > 0; depth++) {
|
|
4917
4919
|
for (const id of parents) walked.add(id);
|
|
@@ -4919,7 +4921,7 @@ async function impliedLinks(pctx, deviceId, manualIds, pickedRows) {
|
|
|
4919
4921
|
const next = [];
|
|
4920
4922
|
for (const children of byParent.values()) for (const child of children) {
|
|
4921
4923
|
rows.set(child.meta.id, child);
|
|
4922
|
-
if (child.meta.type === DeviceType.Container && !walked.has(child.meta.id)) next.push(child.meta.id);
|
|
4924
|
+
if (child.meta.type === DeviceType$1.Container && !walked.has(child.meta.id)) next.push(child.meta.id);
|
|
4923
4925
|
}
|
|
4924
4926
|
parents = next;
|
|
4925
4927
|
}
|
|
@@ -4956,7 +4958,7 @@ function candidatesFor(deviceId, byId) {
|
|
|
4956
4958
|
for (const device of byId.values()) {
|
|
4957
4959
|
if (device.id === deviceId) continue;
|
|
4958
4960
|
if (device.parentDeviceId === deviceId) continue;
|
|
4959
|
-
if (device.type === DeviceType.Container) continue;
|
|
4961
|
+
if (device.type === DeviceType$1.Container) continue;
|
|
4960
4962
|
const suggested = location !== null && device.location === location;
|
|
4961
4963
|
const parent = device.parentDeviceId === null ? void 0 : byId.get(device.parentDeviceId);
|
|
4962
4964
|
out.push({
|
|
@@ -5299,7 +5301,7 @@ async function setAlias(pctx, input) {
|
|
|
5299
5301
|
type: "device",
|
|
5300
5302
|
id: deviceId
|
|
5301
5303
|
},
|
|
5302
|
-
category: EventCategory.DeviceMetaChanged,
|
|
5304
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
5303
5305
|
data: {
|
|
5304
5306
|
deviceId,
|
|
5305
5307
|
field: "alias",
|
|
@@ -5485,7 +5487,7 @@ async function checkFleetTwice(reads) {
|
|
|
5485
5487
|
} catch (err) {
|
|
5486
5488
|
return {
|
|
5487
5489
|
ok: false,
|
|
5488
|
-
reason: `device list read ${attempt} failed: ${errMsg(err)}`
|
|
5490
|
+
reason: `device list read ${attempt} failed: ${errMsg$1(err)}`
|
|
5489
5491
|
};
|
|
5490
5492
|
}
|
|
5491
5493
|
if (read.ids.length === 0) return {
|
|
@@ -5546,7 +5548,7 @@ async function cleanupDeletedDevicesData(deps, input) {
|
|
|
5546
5548
|
try {
|
|
5547
5549
|
addonIds = await hookProviders(api);
|
|
5548
5550
|
} catch (err) {
|
|
5549
|
-
return skipped(`implementers could not be listed: ${errMsg(err)}`);
|
|
5551
|
+
return skipped(`implementers could not be listed: ${errMsg$1(err)}`);
|
|
5550
5552
|
}
|
|
5551
5553
|
const unreachable = /* @__PURE__ */ new Set();
|
|
5552
5554
|
const held = [];
|
|
@@ -5556,7 +5558,7 @@ async function cleanupDeletedDevicesData(deps, input) {
|
|
|
5556
5558
|
unreachable.add(addonId);
|
|
5557
5559
|
deps.logger.warn("cleanup of deleted devices data: an implementer did not answer", { meta: {
|
|
5558
5560
|
addonId,
|
|
5559
|
-
error: errMsg(err)
|
|
5561
|
+
error: errMsg$1(err)
|
|
5560
5562
|
} });
|
|
5561
5563
|
}
|
|
5562
5564
|
if (deps.settings !== void 0) try {
|
|
@@ -5566,7 +5568,7 @@ async function cleanupDeletedDevicesData(deps, input) {
|
|
|
5566
5568
|
count: 1
|
|
5567
5569
|
}]);
|
|
5568
5570
|
} catch (err) {
|
|
5569
|
-
return skipped(`device settings could not be listed: ${errMsg(err)}`, [...unreachable]);
|
|
5571
|
+
return skipped(`device settings could not be listed: ${errMsg$1(err)}`, [...unreachable]);
|
|
5570
5572
|
}
|
|
5571
5573
|
const { devices, idSpaceMismatch } = orphanDevices(held, fleet.known);
|
|
5572
5574
|
if (idSpaceMismatch) return skipped("none of the device ids holding data is a known device — the id space looks wrong, refusing", [...unreachable]);
|
|
@@ -5599,7 +5601,7 @@ async function cleanupDeletedDevicesData(deps, input) {
|
|
|
5599
5601
|
tags: { deviceId: device.deviceId },
|
|
5600
5602
|
meta: {
|
|
5601
5603
|
addonId,
|
|
5602
|
-
error: errMsg(err)
|
|
5604
|
+
error: errMsg$1(err)
|
|
5603
5605
|
}
|
|
5604
5606
|
});
|
|
5605
5607
|
}
|
|
@@ -5608,7 +5610,7 @@ async function cleanupDeletedDevicesData(deps, input) {
|
|
|
5608
5610
|
} catch (err) {
|
|
5609
5611
|
deps.logger.warn("cleanup of deleted devices data: settings not cleared", {
|
|
5610
5612
|
tags: { deviceId: device.deviceId },
|
|
5611
|
-
meta: { error: errMsg(err) }
|
|
5613
|
+
meta: { error: errMsg$1(err) }
|
|
5612
5614
|
});
|
|
5613
5615
|
}
|
|
5614
5616
|
deps.logger.info("cleaned data of a device deleted before tombstones", {
|
|
@@ -5733,7 +5735,7 @@ function planNullLocationFills(rows) {
|
|
|
5733
5735
|
if (row.parentDeviceId === null) continue;
|
|
5734
5736
|
const hit = nearestLocatedAncestor(byId, row.parentDeviceId);
|
|
5735
5737
|
if (hit === null) continue;
|
|
5736
|
-
if (hit.type !== DeviceType.Container) continue;
|
|
5738
|
+
if (hit.type !== DeviceType$1.Container) continue;
|
|
5737
5739
|
if (hit.location === null) continue;
|
|
5738
5740
|
plan.push({
|
|
5739
5741
|
id: row.id,
|
|
@@ -5762,7 +5764,7 @@ async function resolveInheritedLocation(rows, parentDeviceId) {
|
|
|
5762
5764
|
visited.add(cursor);
|
|
5763
5765
|
const ancestor = await rows.get(cursor);
|
|
5764
5766
|
if (ancestor === null) return null;
|
|
5765
|
-
if (ancestor.meta.location !== null) return ancestor.meta.type === DeviceType.Container ? ancestor.meta.location : null;
|
|
5767
|
+
if (ancestor.meta.location !== null) return ancestor.meta.type === DeviceType$1.Container ? ancestor.meta.location : null;
|
|
5766
5768
|
cursor = ancestor.meta.parentDeviceId;
|
|
5767
5769
|
}
|
|
5768
5770
|
return null;
|
|
@@ -5816,7 +5818,7 @@ async function runLocationBackfillAtBoot(pctx, bootRows) {
|
|
|
5816
5818
|
type: "device",
|
|
5817
5819
|
id: ancestorId
|
|
5818
5820
|
},
|
|
5819
|
-
category: EventCategory.DeviceMetaChanged,
|
|
5821
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
5820
5822
|
data: {
|
|
5821
5823
|
deviceId: ancestorId,
|
|
5822
5824
|
field: "location",
|
|
@@ -6347,7 +6349,7 @@ async function stampIntegrationId(metaStore, ctx, deviceId, integrationId) {
|
|
|
6347
6349
|
type: "device",
|
|
6348
6350
|
id: deviceId
|
|
6349
6351
|
},
|
|
6350
|
-
category: EventCategory.DeviceMetaChanged,
|
|
6352
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
6351
6353
|
data: {
|
|
6352
6354
|
deviceId,
|
|
6353
6355
|
field: "integrationId",
|
|
@@ -6633,7 +6635,7 @@ async function registerDevice(pctx, input) {
|
|
|
6633
6635
|
type: "device",
|
|
6634
6636
|
id: changedId
|
|
6635
6637
|
},
|
|
6636
|
-
category: EventCategory.DeviceMetaChanged,
|
|
6638
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
6637
6639
|
data: {
|
|
6638
6640
|
deviceId: changedId,
|
|
6639
6641
|
field: "location",
|
|
@@ -6663,7 +6665,7 @@ async function registerDevice(pctx, input) {
|
|
|
6663
6665
|
type: "device",
|
|
6664
6666
|
id
|
|
6665
6667
|
},
|
|
6666
|
-
category: EventCategory.DeviceRegistered,
|
|
6668
|
+
category: EventCategory$1.DeviceRegistered,
|
|
6667
6669
|
data: {
|
|
6668
6670
|
deviceId: id,
|
|
6669
6671
|
name: name.length > 0 ? name : stableId,
|
|
@@ -6678,7 +6680,7 @@ async function registerDevice(pctx, input) {
|
|
|
6678
6680
|
type: "device",
|
|
6679
6681
|
id
|
|
6680
6682
|
},
|
|
6681
|
-
category: EventCategory.DeviceMetaChanged,
|
|
6683
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
6682
6684
|
data: {
|
|
6683
6685
|
deviceId: id,
|
|
6684
6686
|
name: name.length > 0 ? name : stableId,
|
|
@@ -6694,7 +6696,7 @@ async function registerDevice(pctx, input) {
|
|
|
6694
6696
|
type: "device",
|
|
6695
6697
|
id
|
|
6696
6698
|
},
|
|
6697
|
-
category: EventCategory.DeviceProvisioned,
|
|
6699
|
+
category: EventCategory$1.DeviceProvisioned,
|
|
6698
6700
|
data: {
|
|
6699
6701
|
deviceId: id,
|
|
6700
6702
|
fingerprint: exportFingerprint,
|
|
@@ -6814,7 +6816,7 @@ async function removeDevice(pctx, input) {
|
|
|
6814
6816
|
type: "device",
|
|
6815
6817
|
id: deviceId
|
|
6816
6818
|
},
|
|
6817
|
-
category: EventCategory.DeviceUnregistered,
|
|
6819
|
+
category: EventCategory$1.DeviceUnregistered,
|
|
6818
6820
|
data: {
|
|
6819
6821
|
deviceId,
|
|
6820
6822
|
providerId: addonId,
|
|
@@ -6923,7 +6925,7 @@ async function setName(pctx, input) {
|
|
|
6923
6925
|
type: "device",
|
|
6924
6926
|
id: deviceId
|
|
6925
6927
|
},
|
|
6926
|
-
category: EventCategory.DeviceMetaChanged,
|
|
6928
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
6927
6929
|
data: {
|
|
6928
6930
|
deviceId,
|
|
6929
6931
|
field: "name",
|
|
@@ -6937,7 +6939,7 @@ async function setName(pctx, input) {
|
|
|
6937
6939
|
type: "device",
|
|
6938
6940
|
id: child.id
|
|
6939
6941
|
},
|
|
6940
|
-
category: EventCategory.DeviceMetaChanged,
|
|
6942
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
6941
6943
|
data: {
|
|
6942
6944
|
deviceId: child.id,
|
|
6943
6945
|
field: "name",
|
|
@@ -7040,7 +7042,7 @@ async function setLocation(pctx, input) {
|
|
|
7040
7042
|
type: "device",
|
|
7041
7043
|
id: deviceId
|
|
7042
7044
|
},
|
|
7043
|
-
category: EventCategory.DeviceMetaChanged,
|
|
7045
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
7044
7046
|
data: {
|
|
7045
7047
|
deviceId,
|
|
7046
7048
|
field: "location",
|
|
@@ -7054,7 +7056,7 @@ async function setLocation(pctx, input) {
|
|
|
7054
7056
|
type: "device",
|
|
7055
7057
|
id: childId
|
|
7056
7058
|
},
|
|
7057
|
-
category: EventCategory.DeviceMetaChanged,
|
|
7059
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
7058
7060
|
data: {
|
|
7059
7061
|
deviceId: childId,
|
|
7060
7062
|
field: "location",
|
|
@@ -7098,7 +7100,7 @@ async function setType(pctx, input) {
|
|
|
7098
7100
|
type: "device",
|
|
7099
7101
|
id: deviceId
|
|
7100
7102
|
},
|
|
7101
|
-
category: EventCategory.DeviceMetaChanged,
|
|
7103
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
7102
7104
|
data: {
|
|
7103
7105
|
deviceId,
|
|
7104
7106
|
field: "type",
|
|
@@ -7134,7 +7136,7 @@ async function setLinkDeviceId(pctx, input) {
|
|
|
7134
7136
|
type: "device",
|
|
7135
7137
|
id: deviceId
|
|
7136
7138
|
},
|
|
7137
|
-
category: EventCategory.DeviceMetaChanged,
|
|
7139
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
7138
7140
|
data: {
|
|
7139
7141
|
deviceId,
|
|
7140
7142
|
field: "linkDeviceId",
|
|
@@ -7172,7 +7174,7 @@ async function setPrimaryChildEntityId(pctx, input) {
|
|
|
7172
7174
|
type: "device",
|
|
7173
7175
|
id: deviceId
|
|
7174
7176
|
},
|
|
7175
|
-
category: EventCategory.DeviceMetaChanged,
|
|
7177
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
7176
7178
|
data: {
|
|
7177
7179
|
deviceId,
|
|
7178
7180
|
field: "primaryChildEntityId",
|
|
@@ -7199,7 +7201,7 @@ async function setChildLayout(pctx, input) {
|
|
|
7199
7201
|
type: "device",
|
|
7200
7202
|
id: deviceId
|
|
7201
7203
|
},
|
|
7202
|
-
category: EventCategory.DeviceMetaChanged,
|
|
7204
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
7203
7205
|
data: {
|
|
7204
7206
|
deviceId,
|
|
7205
7207
|
field: "childLayout",
|
|
@@ -7226,7 +7228,7 @@ async function setRole(pctx, input) {
|
|
|
7226
7228
|
type: "device",
|
|
7227
7229
|
id: deviceId
|
|
7228
7230
|
},
|
|
7229
|
-
category: EventCategory.DeviceMetaChanged,
|
|
7231
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
7230
7232
|
data: {
|
|
7231
7233
|
deviceId,
|
|
7232
7234
|
field: "role",
|
|
@@ -7272,7 +7274,7 @@ async function setDisplay(pctx, input) {
|
|
|
7272
7274
|
type: "device",
|
|
7273
7275
|
id: deviceId
|
|
7274
7276
|
},
|
|
7275
|
-
category: EventCategory.DeviceMetaChanged,
|
|
7277
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
7276
7278
|
data: {
|
|
7277
7279
|
deviceId,
|
|
7278
7280
|
field: "display",
|
|
@@ -7346,7 +7348,7 @@ async function applyInitialMeta(pctx, input) {
|
|
|
7346
7348
|
type: "device",
|
|
7347
7349
|
id: deviceId
|
|
7348
7350
|
},
|
|
7349
|
-
category: EventCategory.DeviceMetaChanged,
|
|
7351
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
7350
7352
|
data: {
|
|
7351
7353
|
deviceId,
|
|
7352
7354
|
field,
|
|
@@ -7401,7 +7403,7 @@ async function setMetadata(pctx, input) {
|
|
|
7401
7403
|
type: "device",
|
|
7402
7404
|
id: deviceId
|
|
7403
7405
|
},
|
|
7404
|
-
category: EventCategory.DeviceMetaChanged,
|
|
7406
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
7405
7407
|
data: {
|
|
7406
7408
|
deviceId,
|
|
7407
7409
|
field: "metadata",
|
|
@@ -7434,7 +7436,7 @@ function emitDisabledEvents(pctx, deviceId, disabled, moved) {
|
|
|
7434
7436
|
type: "device",
|
|
7435
7437
|
id: deviceId
|
|
7436
7438
|
},
|
|
7437
|
-
category: EventCategory.DeviceMetaChanged,
|
|
7439
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
7438
7440
|
data: {
|
|
7439
7441
|
deviceId,
|
|
7440
7442
|
field: "disabled",
|
|
@@ -7449,7 +7451,7 @@ function emitDisabledEvents(pctx, deviceId, disabled, moved) {
|
|
|
7449
7451
|
type: "device",
|
|
7450
7452
|
id: deviceId
|
|
7451
7453
|
},
|
|
7452
|
-
category: disabled ? EventCategory.DeviceDisabled : EventCategory.DeviceEnabled,
|
|
7454
|
+
category: disabled ? EventCategory$1.DeviceDisabled : EventCategory$1.DeviceEnabled,
|
|
7453
7455
|
data: {
|
|
7454
7456
|
deviceId,
|
|
7455
7457
|
integrationId: moved.integrationId
|
|
@@ -7875,7 +7877,7 @@ async function renameLocation(pctx, input) {
|
|
|
7875
7877
|
type: "device",
|
|
7876
7878
|
id: deviceId
|
|
7877
7879
|
},
|
|
7878
|
-
category: EventCategory.DeviceMetaChanged,
|
|
7880
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
7879
7881
|
data: {
|
|
7880
7882
|
deviceId,
|
|
7881
7883
|
field: "location",
|
|
@@ -7934,7 +7936,7 @@ async function removeLocation(pctx, input) {
|
|
|
7934
7936
|
type: "device",
|
|
7935
7937
|
id: deviceId
|
|
7936
7938
|
},
|
|
7937
|
-
category: EventCategory.DeviceMetaChanged,
|
|
7939
|
+
category: EventCategory$1.DeviceMetaChanged,
|
|
7938
7940
|
data: {
|
|
7939
7941
|
deviceId,
|
|
7940
7942
|
field: "location",
|
|
@@ -7972,7 +7974,7 @@ async function runLinkedDevicesManualBackfillAtBoot(pctx) {
|
|
|
7972
7974
|
let written = 0;
|
|
7973
7975
|
let linked = 0;
|
|
7974
7976
|
for (const cam of all) {
|
|
7975
|
-
if (cam.type !== DeviceType.Camera) continue;
|
|
7977
|
+
if (cam.type !== DeviceType$1.Camera) continue;
|
|
7976
7978
|
const blob = await pctx.settings.readDeviceStore(cam.id);
|
|
7977
7979
|
const plan = planManualBackfill({
|
|
7978
7980
|
selfId: cam.id,
|
|
@@ -8335,7 +8337,7 @@ var DeviceTombstoneStore = class DeviceTombstoneStore {
|
|
|
8335
8337
|
for (const row of rows) await this.kind.delete(row.id);
|
|
8336
8338
|
return rows.length;
|
|
8337
8339
|
} catch (err) {
|
|
8338
|
-
this.logger.warn("device tombstone prune failed — retried on the next write", { meta: { error: errMsg(err) } });
|
|
8340
|
+
this.logger.warn("device tombstone prune failed — retried on the next write", { meta: { error: errMsg$1(err) } });
|
|
8339
8341
|
return 0;
|
|
8340
8342
|
}
|
|
8341
8343
|
}
|
|
@@ -8431,7 +8433,7 @@ var DiscoveryProposalService = class {
|
|
|
8431
8433
|
} catch (err) {
|
|
8432
8434
|
this.deps.logger.warn("passive discovery: provider could not classify", { meta: {
|
|
8433
8435
|
addonId,
|
|
8434
|
-
error: errMsg(err)
|
|
8436
|
+
error: errMsg$1(err)
|
|
8435
8437
|
} });
|
|
8436
8438
|
}
|
|
8437
8439
|
return { proposed };
|
|
@@ -8843,7 +8845,7 @@ function deviceRowBackendOf(client) {
|
|
|
8843
8845
|
count: (input) => client.count.query(input)
|
|
8844
8846
|
};
|
|
8845
8847
|
}
|
|
8846
|
-
function isPlainObject(value) {
|
|
8848
|
+
function isPlainObject$1(value) {
|
|
8847
8849
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
8848
8850
|
}
|
|
8849
8851
|
function readString(value) {
|
|
@@ -8910,9 +8912,9 @@ function decodeDeviceRow(data) {
|
|
|
8910
8912
|
...primaryChildEntityId !== void 0 ? { primaryChildEntityId } : {},
|
|
8911
8913
|
...isChildLayout(rawChildLayout) ? { childLayout: rawChildLayout } : {},
|
|
8912
8914
|
...role !== void 0 ? { role } : {},
|
|
8913
|
-
...isPlainObject(rawDisplay) ? { display: toDisplayOverride(rawDisplay) } : {}
|
|
8915
|
+
...isPlainObject$1(rawDisplay) ? { display: toDisplayOverride(rawDisplay) } : {}
|
|
8914
8916
|
},
|
|
8915
|
-
metadata: isPlainObject(rawMetadata) ? rawMetadata : null,
|
|
8917
|
+
metadata: isPlainObject$1(rawMetadata) ? rawMetadata : null,
|
|
8916
8918
|
registered: readBoolean(data["registered"]) ?? false
|
|
8917
8919
|
};
|
|
8918
8920
|
}
|
|
@@ -9031,7 +9033,7 @@ var DeviceRowStore = class {
|
|
|
9031
9033
|
collection: DEVICE_ROWS_COLLECTION,
|
|
9032
9034
|
key: String(deviceId)
|
|
9033
9035
|
});
|
|
9034
|
-
if (!isPlainObject(raw)) return null;
|
|
9036
|
+
if (!isPlainObject$1(raw)) return null;
|
|
9035
9037
|
const decoded = decodeDeviceRow(raw);
|
|
9036
9038
|
if (decoded === null) {
|
|
9037
9039
|
this.logger.warn("device row skipped — identity fields missing", { tags: { deviceId } });
|
|
@@ -10113,6 +10115,7 @@ function errorMessage$1(err) {
|
|
|
10113
10115
|
var DeviceStateMirror = class {
|
|
10114
10116
|
ctx;
|
|
10115
10117
|
policyFor;
|
|
10118
|
+
transitionTap = null;
|
|
10116
10119
|
/**
|
|
10117
10120
|
* Hub-side mirror of every device's cap-keyed NATIVE runtime state — what the
|
|
10118
10121
|
* provider wrote. Key: deviceId. Value: per-cap slice map. Empty by default —
|
|
@@ -10158,6 +10161,14 @@ var DeviceStateMirror = class {
|
|
|
10158
10161
|
readRowFirst: (deviceId, settings) => this.ensureRowRead(deviceId, settings)
|
|
10159
10162
|
});
|
|
10160
10163
|
}
|
|
10164
|
+
/** Set once by the device-manager: told, after the mirror stored it, of every native slice that actually changed (D1022). */
|
|
10165
|
+
setTransitionTap(tap) {
|
|
10166
|
+
this.transitionTap = tap;
|
|
10167
|
+
}
|
|
10168
|
+
/** The native slice the mirror holds for `capName`, as a read-only view. */
|
|
10169
|
+
currentSlice(deviceId, capName) {
|
|
10170
|
+
return this.stateMirror.get(deviceId)?.get(capName);
|
|
10171
|
+
}
|
|
10161
10172
|
/**
|
|
10162
10173
|
* Single-cap mirror update — diff against the current mirror,
|
|
10163
10174
|
* persist the new slice in-memory, emit `DeviceStateChanged` for
|
|
@@ -10182,6 +10193,7 @@ var DeviceStateMirror = class {
|
|
|
10182
10193
|
const prior = perCap.get(capName);
|
|
10183
10194
|
if (prior && shallowEqual(prior, slice)) return false;
|
|
10184
10195
|
perCap.set(capName, { ...slice });
|
|
10196
|
+
this.transitionTap?.(deviceId, capName, prior, slice);
|
|
10185
10197
|
const claim = this.claims.claim(deviceId, capName);
|
|
10186
10198
|
if (claim) {
|
|
10187
10199
|
if (claim.mode === "replace") this.emitNativeShadow(deviceId, capName, { ...slice });
|
|
@@ -10679,7 +10691,7 @@ var DeviceStateMirror = class {
|
|
|
10679
10691
|
type: "device",
|
|
10680
10692
|
id: deviceId
|
|
10681
10693
|
},
|
|
10682
|
-
category: flip.kind === "started" ? EventCategory.RunningStarted : EventCategory.RunningFinished,
|
|
10694
|
+
category: flip.kind === "started" ? EventCategory$1.RunningStarted : EventCategory$1.RunningFinished,
|
|
10683
10695
|
data: {
|
|
10684
10696
|
deviceId: flip.deviceId,
|
|
10685
10697
|
since: flip.since,
|
|
@@ -10694,7 +10706,7 @@ var DeviceStateMirror = class {
|
|
|
10694
10706
|
type: "device",
|
|
10695
10707
|
id: deviceId
|
|
10696
10708
|
},
|
|
10697
|
-
category: EventCategory.DeviceStateChanged,
|
|
10709
|
+
category: EventCategory$1.DeviceStateChanged,
|
|
10698
10710
|
data: {
|
|
10699
10711
|
deviceId,
|
|
10700
10712
|
capName,
|
|
@@ -10716,7 +10728,7 @@ var DeviceStateMirror = class {
|
|
|
10716
10728
|
type: "device",
|
|
10717
10729
|
id: deviceId
|
|
10718
10730
|
},
|
|
10719
|
-
category: EventCategory.DeviceNativeShadowChanged,
|
|
10731
|
+
category: EventCategory$1.DeviceNativeShadowChanged,
|
|
10720
10732
|
data: {
|
|
10721
10733
|
deviceId,
|
|
10722
10734
|
capName,
|
|
@@ -10726,6 +10738,663 @@ var DeviceStateMirror = class {
|
|
|
10726
10738
|
}
|
|
10727
10739
|
};
|
|
10728
10740
|
//#endregion
|
|
10741
|
+
//#region ../../node_modules/@trpc/server/dist/observable-UMO3vUa_.mjs
|
|
10742
|
+
/** @public */
|
|
10743
|
+
function observable(subscribe) {
|
|
10744
|
+
const self = {
|
|
10745
|
+
subscribe(observer) {
|
|
10746
|
+
let teardownRef = null;
|
|
10747
|
+
let isDone = false;
|
|
10748
|
+
let unsubscribed = false;
|
|
10749
|
+
let teardownImmediately = false;
|
|
10750
|
+
function unsubscribe() {
|
|
10751
|
+
if (teardownRef === null) {
|
|
10752
|
+
teardownImmediately = true;
|
|
10753
|
+
return;
|
|
10754
|
+
}
|
|
10755
|
+
if (unsubscribed) return;
|
|
10756
|
+
unsubscribed = true;
|
|
10757
|
+
if (typeof teardownRef === "function") teardownRef();
|
|
10758
|
+
else if (teardownRef) teardownRef.unsubscribe();
|
|
10759
|
+
}
|
|
10760
|
+
teardownRef = subscribe({
|
|
10761
|
+
next(value) {
|
|
10762
|
+
var _observer$next;
|
|
10763
|
+
if (isDone) return;
|
|
10764
|
+
(_observer$next = observer.next) === null || _observer$next === void 0 || _observer$next.call(observer, value);
|
|
10765
|
+
},
|
|
10766
|
+
error(err) {
|
|
10767
|
+
var _observer$error;
|
|
10768
|
+
if (isDone) return;
|
|
10769
|
+
isDone = true;
|
|
10770
|
+
(_observer$error = observer.error) === null || _observer$error === void 0 || _observer$error.call(observer, err);
|
|
10771
|
+
unsubscribe();
|
|
10772
|
+
},
|
|
10773
|
+
complete() {
|
|
10774
|
+
var _observer$complete;
|
|
10775
|
+
if (isDone) return;
|
|
10776
|
+
isDone = true;
|
|
10777
|
+
(_observer$complete = observer.complete) === null || _observer$complete === void 0 || _observer$complete.call(observer);
|
|
10778
|
+
unsubscribe();
|
|
10779
|
+
}
|
|
10780
|
+
});
|
|
10781
|
+
if (teardownImmediately) unsubscribe();
|
|
10782
|
+
return { unsubscribe };
|
|
10783
|
+
},
|
|
10784
|
+
pipe(...operations) {
|
|
10785
|
+
return operations.reduce(pipeReducer, self);
|
|
10786
|
+
}
|
|
10787
|
+
};
|
|
10788
|
+
return self;
|
|
10789
|
+
}
|
|
10790
|
+
function pipeReducer(prev, fn) {
|
|
10791
|
+
return fn(prev);
|
|
10792
|
+
}
|
|
10793
|
+
//#endregion
|
|
10794
|
+
//#region src/kernel/command-observation.ts
|
|
10795
|
+
/** Fan-out of command observations to the subscribers of this process. */
|
|
10796
|
+
var CommandObserverRegistry = class {
|
|
10797
|
+
observers = /* @__PURE__ */ new Set();
|
|
10798
|
+
subscribe(observer) {
|
|
10799
|
+
this.observers.add(observer);
|
|
10800
|
+
return () => {
|
|
10801
|
+
this.observers.delete(observer);
|
|
10802
|
+
};
|
|
10803
|
+
}
|
|
10804
|
+
/** How many observers are subscribed (a node that audits nothing has none). */
|
|
10805
|
+
observerCount() {
|
|
10806
|
+
return this.observers.size;
|
|
10807
|
+
}
|
|
10808
|
+
observe(obs) {
|
|
10809
|
+
for (const observer of this.observers) try {
|
|
10810
|
+
observer(obs);
|
|
10811
|
+
} catch {}
|
|
10812
|
+
}
|
|
10813
|
+
};
|
|
10814
|
+
var registry;
|
|
10815
|
+
/** The process-wide registry. */
|
|
10816
|
+
function getCommandObserverRegistry() {
|
|
10817
|
+
registry ??= new CommandObserverRegistry();
|
|
10818
|
+
return registry;
|
|
10819
|
+
}
|
|
10820
|
+
/** Test seam: forget every subscriber. */
|
|
10821
|
+
function __resetCommandObserverRegistryForTests() {
|
|
10822
|
+
registry = void 0;
|
|
10823
|
+
}
|
|
10824
|
+
function isRecord(value) {
|
|
10825
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
10826
|
+
}
|
|
10827
|
+
/**
|
|
10828
|
+
* Build the observation for a call, or `null` when it is not a device
|
|
10829
|
+
* command: not a vocabulary action, or its arguments name no device.
|
|
10830
|
+
*/
|
|
10831
|
+
function buildCommandObservation(call, at) {
|
|
10832
|
+
if (!isCommand(call.capName, call.method)) return null;
|
|
10833
|
+
if (!isRecord(call.args)) return null;
|
|
10834
|
+
const deviceId = call.args["deviceId"];
|
|
10835
|
+
if (typeof deviceId !== "number" || !Number.isInteger(deviceId)) return null;
|
|
10836
|
+
return {
|
|
10837
|
+
deviceId,
|
|
10838
|
+
capName: call.capName,
|
|
10839
|
+
method: call.method,
|
|
10840
|
+
args: call.args,
|
|
10841
|
+
actor: call.actor,
|
|
10842
|
+
at,
|
|
10843
|
+
...call.outcome !== void 0 ? { outcome: call.outcome } : {}
|
|
10844
|
+
};
|
|
10845
|
+
}
|
|
10846
|
+
/** Report a call to `sink` when it is a device command. Never throws. */
|
|
10847
|
+
function reportCommand(sink, call, now = Date.now) {
|
|
10848
|
+
if (sink === void 0) return;
|
|
10849
|
+
try {
|
|
10850
|
+
const obs = buildCommandObservation(call, now());
|
|
10851
|
+
if (obs !== null) sink(obs);
|
|
10852
|
+
} catch {}
|
|
10853
|
+
}
|
|
10854
|
+
/**
|
|
10855
|
+
* The actor of a command an ADDON issued. The addon id is the transport stamp.
|
|
10856
|
+
* An origin claim adds the detail of why (an action run, a scheduler); it never
|
|
10857
|
+
* changes who the caller is.
|
|
10858
|
+
*/
|
|
10859
|
+
function addonCommandActor(addonId, origin, nodeId) {
|
|
10860
|
+
if (origin === void 0) return {
|
|
10861
|
+
kind: "addon",
|
|
10862
|
+
addonId,
|
|
10863
|
+
...nodeId !== void 0 ? { nodeId } : {}
|
|
10864
|
+
};
|
|
10865
|
+
if (origin.kind === "action") return {
|
|
10866
|
+
kind: "action",
|
|
10867
|
+
addonId,
|
|
10868
|
+
actionId: origin.actionId,
|
|
10869
|
+
runId: origin.runId,
|
|
10870
|
+
...origin.automationId !== void 0 ? { automationId: origin.automationId } : {}
|
|
10871
|
+
};
|
|
10872
|
+
return {
|
|
10873
|
+
kind: "scheduler",
|
|
10874
|
+
addonId,
|
|
10875
|
+
schedulerId: origin.schedulerId
|
|
10876
|
+
};
|
|
10877
|
+
}
|
|
10878
|
+
function deferred() {
|
|
10879
|
+
let resolve = () => void 0;
|
|
10880
|
+
let reject = () => void 0;
|
|
10881
|
+
return {
|
|
10882
|
+
promise: new Promise((res, rej) => {
|
|
10883
|
+
resolve = () => res();
|
|
10884
|
+
reject = rej;
|
|
10885
|
+
}),
|
|
10886
|
+
resolve,
|
|
10887
|
+
reject
|
|
10888
|
+
};
|
|
10889
|
+
}
|
|
10890
|
+
function kebab(name) {
|
|
10891
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
10892
|
+
}
|
|
10893
|
+
/**
|
|
10894
|
+
* A tRPC link for an in-process hub addon's `ctx.api`: it reports the addon's
|
|
10895
|
+
* device commands (the actor is the addon the client belongs to, with the origin
|
|
10896
|
+
* claim of the call) and passes every call through untouched.
|
|
10897
|
+
*/
|
|
10898
|
+
function commandObserverLink(options) {
|
|
10899
|
+
return () => ({ op, next }) => {
|
|
10900
|
+
if (op.type !== "mutation") return next(op);
|
|
10901
|
+
const dot = op.path.indexOf(".");
|
|
10902
|
+
if (dot < 0) return next(op);
|
|
10903
|
+
const capName = kebab(op.path.slice(0, dot));
|
|
10904
|
+
const method = op.path.slice(dot + 1);
|
|
10905
|
+
if (!isCommand(capName, method)) return next(op);
|
|
10906
|
+
const downstream = next(op);
|
|
10907
|
+
return observable((observer) => {
|
|
10908
|
+
const settled = deferred();
|
|
10909
|
+
const outcome = settled.promise;
|
|
10910
|
+
outcome.catch(() => void 0);
|
|
10911
|
+
reportCommand(options.sink, {
|
|
10912
|
+
capName,
|
|
10913
|
+
method,
|
|
10914
|
+
args: op.input,
|
|
10915
|
+
actor: addonCommandActor(options.callerAddonId, readCommandOrigin(op.context)),
|
|
10916
|
+
outcome
|
|
10917
|
+
});
|
|
10918
|
+
const sub = downstream.subscribe({
|
|
10919
|
+
next: (value) => observer.next(value),
|
|
10920
|
+
error: (err) => {
|
|
10921
|
+
settled.reject(err);
|
|
10922
|
+
observer.error(err);
|
|
10923
|
+
},
|
|
10924
|
+
complete: () => {
|
|
10925
|
+
settled.resolve();
|
|
10926
|
+
observer.complete();
|
|
10927
|
+
}
|
|
10928
|
+
});
|
|
10929
|
+
return () => sub.unsubscribe();
|
|
10930
|
+
});
|
|
10931
|
+
};
|
|
10932
|
+
}
|
|
10933
|
+
function credentialOf(user) {
|
|
10934
|
+
const tag = Reflect.get(user, "auditTag");
|
|
10935
|
+
if (tag === "session" || tag === "token" || tag === "integration") return tag;
|
|
10936
|
+
return Reflect.get(user, "isApiKey") === true ? "token" : "session";
|
|
10937
|
+
}
|
|
10938
|
+
/**
|
|
10939
|
+
* Who a hub tRPC call is from, read from the request context by narrowing (the
|
|
10940
|
+
* kernel cannot import the server's context type). A context with no HTTP
|
|
10941
|
+
* request behind it is a mesh peer: a node. Anything without a principal is
|
|
10942
|
+
* unknown (`null`) and the call is not reported with a made-up actor.
|
|
10943
|
+
*/
|
|
10944
|
+
function commandActorFromContext(ctx) {
|
|
10945
|
+
if (ctx === null || typeof ctx !== "object") return null;
|
|
10946
|
+
const user = Reflect.get(ctx, "user");
|
|
10947
|
+
if (user === null || typeof user !== "object") return null;
|
|
10948
|
+
const id = Reflect.get(user, "id");
|
|
10949
|
+
if (typeof id !== "string" || id.length === 0) return null;
|
|
10950
|
+
if (Reflect.get(ctx, "req") === void 0) return {
|
|
10951
|
+
kind: "node",
|
|
10952
|
+
nodeId: id
|
|
10953
|
+
};
|
|
10954
|
+
const username = Reflect.get(user, "username");
|
|
10955
|
+
const credentialId = Reflect.get(user, "credentialId");
|
|
10956
|
+
return {
|
|
10957
|
+
kind: "user",
|
|
10958
|
+
userId: id,
|
|
10959
|
+
username: typeof username === "string" ? username : id,
|
|
10960
|
+
credential: credentialOf(user),
|
|
10961
|
+
...typeof credentialId === "string" ? { credentialId } : {}
|
|
10962
|
+
};
|
|
10963
|
+
}
|
|
10964
|
+
/**
|
|
10965
|
+
* Report a command BEFORE it runs, with an outcome that settles when the call
|
|
10966
|
+
* does: a provider that writes its slice synchronously must find the command
|
|
10967
|
+
* already pending. `call` is invoked here; its result (or throw) is returned
|
|
10968
|
+
* untouched.
|
|
10969
|
+
*/
|
|
10970
|
+
function runObservedCommand(sink, facts, call) {
|
|
10971
|
+
if (sink === void 0 || !isCommand(facts.capName, facts.method)) return call();
|
|
10972
|
+
const settled = deferred();
|
|
10973
|
+
settled.promise.catch(() => void 0);
|
|
10974
|
+
reportCommand(sink, {
|
|
10975
|
+
...facts,
|
|
10976
|
+
outcome: settled.promise
|
|
10977
|
+
});
|
|
10978
|
+
try {
|
|
10979
|
+
const result = call();
|
|
10980
|
+
Promise.resolve(result).then(() => settled.resolve(), settled.reject);
|
|
10981
|
+
return result;
|
|
10982
|
+
} catch (err) {
|
|
10983
|
+
settled.reject(err);
|
|
10984
|
+
throw err;
|
|
10985
|
+
}
|
|
10986
|
+
}
|
|
10987
|
+
var REDACTED = "***";
|
|
10988
|
+
var ROUTING_KEYS = new Set([
|
|
10989
|
+
"deviceId",
|
|
10990
|
+
"caller",
|
|
10991
|
+
"nodeId"
|
|
10992
|
+
]);
|
|
10993
|
+
/** `rows[].token` -> key rows, each, key token. `applianceSecrets{}` -> key, values. */
|
|
10994
|
+
function parsePath(path) {
|
|
10995
|
+
const tokens = [];
|
|
10996
|
+
for (const m of path.matchAll(/\[\]|\{\}|[^.[\]{}]+/g)) {
|
|
10997
|
+
const t = m[0];
|
|
10998
|
+
tokens.push(t === "[]" ? { kind: "each" } : t === "{}" ? { kind: "values" } : {
|
|
10999
|
+
kind: "key",
|
|
11000
|
+
name: t
|
|
11001
|
+
});
|
|
11002
|
+
}
|
|
11003
|
+
return tokens;
|
|
11004
|
+
}
|
|
11005
|
+
function isPlainObject(value) {
|
|
11006
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
11007
|
+
}
|
|
11008
|
+
/** Replace what `tokens` reaches inside `value`; an object or array declared secret goes whole. */
|
|
11009
|
+
function redactAt(value, tokens) {
|
|
11010
|
+
const [head, ...rest] = tokens;
|
|
11011
|
+
if (head === void 0) return REDACTED;
|
|
11012
|
+
if (head.kind === "each") return Array.isArray(value) ? value.map((item) => redactAt(item, rest)) : value;
|
|
11013
|
+
if (!isPlainObject(value)) return value;
|
|
11014
|
+
if (head.kind === "values") return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, redactAt(v, rest)]));
|
|
11015
|
+
if (!Object.hasOwn(value, head.name)) return value;
|
|
11016
|
+
return {
|
|
11017
|
+
...value,
|
|
11018
|
+
[head.name]: redactAt(value[head.name], rest)
|
|
11019
|
+
};
|
|
11020
|
+
}
|
|
11021
|
+
var WORD_NET_MAX_DEPTH = 8;
|
|
11022
|
+
/** The key-name net for values of ANY type, to a bounded depth. */
|
|
11023
|
+
function redactSecretKeys(value, depth) {
|
|
11024
|
+
if (depth >= WORD_NET_MAX_DEPTH) return value;
|
|
11025
|
+
if (Array.isArray(value)) return value.map((item) => redactSecretKeys(item, depth + 1));
|
|
11026
|
+
if (!isPlainObject(value)) return value;
|
|
11027
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, v !== null && v !== void 0 && isSecretArgumentKey(k) ? REDACTED : redactSecretKeys(v, depth + 1)]));
|
|
11028
|
+
}
|
|
11029
|
+
function createCommandArgsPreparer(inputFor) {
|
|
11030
|
+
const secretPaths = /* @__PURE__ */ new Map();
|
|
11031
|
+
const secretPathsOf = (capName, method) => {
|
|
11032
|
+
const id = `${capName}|${method}`;
|
|
11033
|
+
const known = secretPaths.get(id);
|
|
11034
|
+
if (known !== void 0) return known;
|
|
11035
|
+
const schema = inputFor(capName, method);
|
|
11036
|
+
const paths = schema === void 0 ? [] : collectZodSecretPaths$1(schema).map(parsePath);
|
|
11037
|
+
secretPaths.set(id, paths);
|
|
11038
|
+
return paths;
|
|
11039
|
+
};
|
|
11040
|
+
return (capName, method, args) => {
|
|
11041
|
+
const kept = {};
|
|
11042
|
+
for (const [key, value] of Object.entries(args)) if (!ROUTING_KEYS.has(key)) kept[key] = value;
|
|
11043
|
+
let bag = kept;
|
|
11044
|
+
for (const path of secretPathsOf(capName, method)) bag = redactAt(bag, path);
|
|
11045
|
+
const named = redactSecretKeys(bag, 0);
|
|
11046
|
+
const out = isPlainObject(named) ? redactLogMeta(named) : {};
|
|
11047
|
+
if (JSON.stringify(out).length > 1024) return { _truncated: true };
|
|
11048
|
+
return isPlainObject(out) ? out : {};
|
|
11049
|
+
};
|
|
11050
|
+
}
|
|
11051
|
+
//#endregion
|
|
11052
|
+
//#region src/builtins/device-manager/transitions/transition-correlator.ts
|
|
11053
|
+
/**
|
|
11054
|
+
* The correlator of the device transition audit (D1022).
|
|
11055
|
+
*
|
|
11056
|
+
* A command (what the kernel saw leave its caller) and a slice change (what the
|
|
11057
|
+
* hub mirror saw land) are two facts about one event. This module pairs them:
|
|
11058
|
+
* a change of an audited field is attributed to the newest pending command whose
|
|
11059
|
+
* effect names that field and value, else to a command with no effect (toggle,
|
|
11060
|
+
* press), else to the device itself. A command whose target already held is
|
|
11061
|
+
* `already`; one that produced nothing inside its window is `unconfirmed`; one
|
|
11062
|
+
* the caller saw throw is `failed`.
|
|
11063
|
+
*
|
|
11064
|
+
* Pure and clock-injected. It reads memory only (D49): the pending ring and the
|
|
11065
|
+
* mirror's current slice. Nothing here does I/O, so a state write never waits on
|
|
11066
|
+
* the audit; what it produces is handed to `emit`, whose queue is bounded.
|
|
11067
|
+
*/
|
|
11068
|
+
/** How long a command waits for the change it should cause. */
|
|
11069
|
+
var COMMAND_MATCH_WINDOW_MS = 3e4;
|
|
11070
|
+
/** Longest error text a row keeps. */
|
|
11071
|
+
var ERROR_MAX_CHARS = 300;
|
|
11072
|
+
function sameValue(a, b) {
|
|
11073
|
+
if (Object.is(a, b)) return true;
|
|
11074
|
+
if (a === null || b === null || typeof a !== "object" || typeof b !== "object") return false;
|
|
11075
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
11076
|
+
}
|
|
11077
|
+
/** A status value in the shape a transition stores: unknown is `null` (D393), an array is wrapped. */
|
|
11078
|
+
function toTransitionValue(value) {
|
|
11079
|
+
if (value === void 0 || value === null) return null;
|
|
11080
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
|
|
11081
|
+
if (Array.isArray(value)) return { items: value };
|
|
11082
|
+
if (typeof value === "object") return Object.fromEntries(Object.entries(value));
|
|
11083
|
+
return String(value);
|
|
11084
|
+
}
|
|
11085
|
+
var TransitionCorrelator = class {
|
|
11086
|
+
deps;
|
|
11087
|
+
pending = /* @__PURE__ */ new Map();
|
|
11088
|
+
seq = 0;
|
|
11089
|
+
deviceRows = /* @__PURE__ */ new Map();
|
|
11090
|
+
constructor(deps) {
|
|
11091
|
+
this.deps = deps;
|
|
11092
|
+
}
|
|
11093
|
+
/** A command left its caller. */
|
|
11094
|
+
recordCommand(obs) {
|
|
11095
|
+
const effect = commandEffect(obs.capName, obs.method, obs.args);
|
|
11096
|
+
const current = this.deps.currentSlice(obs.deviceId, obs.capName);
|
|
11097
|
+
const fromAtCommand = effect === null ? null : toTransitionValue(current?.[effect.field]);
|
|
11098
|
+
const entry = {
|
|
11099
|
+
commandId: this.nextCommandId(obs),
|
|
11100
|
+
obs,
|
|
11101
|
+
effect,
|
|
11102
|
+
expiresAt: obs.at + COMMAND_MATCH_WINDOW_MS,
|
|
11103
|
+
fromAtCommand,
|
|
11104
|
+
settled: false
|
|
11105
|
+
};
|
|
11106
|
+
if (effect !== null && current !== void 0 && Object.hasOwn(current, effect.field) && sameValue(current[effect.field], effect.value)) {
|
|
11107
|
+
entry.settled = true;
|
|
11108
|
+
this.emit(entry, "already", effect.field, fromAtCommand, toTransitionValue(effect.value), null);
|
|
11109
|
+
return;
|
|
11110
|
+
}
|
|
11111
|
+
const key = this.keyOf(obs.deviceId, obs.capName);
|
|
11112
|
+
const ring = this.pending.get(key) ?? [];
|
|
11113
|
+
ring.push(entry);
|
|
11114
|
+
while (ring.length > 8) {
|
|
11115
|
+
const oldest = ring.shift();
|
|
11116
|
+
if (oldest !== void 0) this.expire(oldest);
|
|
11117
|
+
}
|
|
11118
|
+
this.pending.set(key, ring);
|
|
11119
|
+
obs.outcome?.catch((err) => this.fail(entry, err));
|
|
11120
|
+
}
|
|
11121
|
+
/** The mirror stored a new native slice for `capName` (the previous one, if any, is `prior`). */
|
|
11122
|
+
onSliceChange(deviceId, capName, prior, slice) {
|
|
11123
|
+
const fields = auditedFields(capName);
|
|
11124
|
+
if (fields.size === 0) return;
|
|
11125
|
+
const now = this.deps.now();
|
|
11126
|
+
let claimed;
|
|
11127
|
+
for (const field of fields) {
|
|
11128
|
+
const hadBefore = prior !== void 0 && Object.hasOwn(prior, field);
|
|
11129
|
+
const has = Object.hasOwn(slice, field);
|
|
11130
|
+
if (!hadBefore && !has) continue;
|
|
11131
|
+
const before = hadBefore ? prior[field] : void 0;
|
|
11132
|
+
const after = has ? slice[field] : void 0;
|
|
11133
|
+
if (sameValue(before, after)) continue;
|
|
11134
|
+
claimed = this.attribute(deviceId, capName, field, toTransitionValue(before), toTransitionValue(after), now, claimed, prior === void 0);
|
|
11135
|
+
}
|
|
11136
|
+
}
|
|
11137
|
+
/** Expire every pending command past its window. Driven by the sender's tick. */
|
|
11138
|
+
sweep() {
|
|
11139
|
+
const now = this.deps.now();
|
|
11140
|
+
this.releaseDeviceRows(now);
|
|
11141
|
+
for (const [key, ring] of this.pending) {
|
|
11142
|
+
const live = [];
|
|
11143
|
+
for (const entry of ring) {
|
|
11144
|
+
if (entry.settled) continue;
|
|
11145
|
+
if (entry.expiresAt <= now) this.expire(entry);
|
|
11146
|
+
else live.push(entry);
|
|
11147
|
+
}
|
|
11148
|
+
if (live.length === 0) this.pending.delete(key);
|
|
11149
|
+
else this.pending.set(key, live);
|
|
11150
|
+
}
|
|
11151
|
+
}
|
|
11152
|
+
/** Commands still waiting, for a status read. */
|
|
11153
|
+
pendingCount() {
|
|
11154
|
+
let n = 0;
|
|
11155
|
+
for (const ring of this.pending.values()) n += ring.filter((e) => !e.settled).length;
|
|
11156
|
+
return n;
|
|
11157
|
+
}
|
|
11158
|
+
/** Forget a removed device's pending commands. */
|
|
11159
|
+
forgetDevice(deviceId) {
|
|
11160
|
+
const prefix = `${deviceId}|`;
|
|
11161
|
+
for (const key of [...this.deviceRows.keys()]) if (key.startsWith(prefix)) this.deviceRows.delete(key);
|
|
11162
|
+
for (const key of [...this.pending.keys()]) if (key.startsWith(prefix)) this.pending.delete(key);
|
|
11163
|
+
}
|
|
11164
|
+
attribute(deviceId, capName, field, from, to, now, claimedByThisWrite, firstSlice) {
|
|
11165
|
+
const key = this.keyOf(deviceId, capName);
|
|
11166
|
+
const ring = this.pending.get(key);
|
|
11167
|
+
const live = (ring ?? []).filter((e) => !e.settled && e.expiresAt > now);
|
|
11168
|
+
const matched = [...live].reverse().find((e) => e.effect !== null && e.effect.field === field && sameValue(e.effect.value, to)) ?? claimedByThisWrite ?? [...live].reverse().find((e) => e.effect === null);
|
|
11169
|
+
if (matched === void 0) {
|
|
11170
|
+
if (firstSlice) return void 0;
|
|
11171
|
+
this.emitDevice(deviceId, capName, field, from, to, now);
|
|
11172
|
+
return;
|
|
11173
|
+
}
|
|
11174
|
+
matched.settled = true;
|
|
11175
|
+
this.emit(matched, "confirmed", field, from, to, now - matched.obs.at);
|
|
11176
|
+
if (ring !== void 0) {
|
|
11177
|
+
const rest = ring.filter((e) => !e.settled);
|
|
11178
|
+
if (rest.length === 0) this.pending.delete(key);
|
|
11179
|
+
else this.pending.set(key, rest);
|
|
11180
|
+
}
|
|
11181
|
+
return matched;
|
|
11182
|
+
}
|
|
11183
|
+
expire(entry) {
|
|
11184
|
+
if (entry.settled) return;
|
|
11185
|
+
entry.settled = true;
|
|
11186
|
+
const field = entry.effect?.field ?? "*";
|
|
11187
|
+
this.emit(entry, "unconfirmed", field, entry.fromAtCommand, entry.fromAtCommand, null);
|
|
11188
|
+
}
|
|
11189
|
+
fail(entry, err) {
|
|
11190
|
+
if (entry.settled) return;
|
|
11191
|
+
entry.settled = true;
|
|
11192
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
11193
|
+
const field = entry.effect?.field ?? "*";
|
|
11194
|
+
this.emit(entry, "failed", field, entry.fromAtCommand, entry.fromAtCommand, null, message);
|
|
11195
|
+
}
|
|
11196
|
+
emit(entry, outcome, field, from, to, matchedAfterMs, error) {
|
|
11197
|
+
const { obs } = entry;
|
|
11198
|
+
const at = this.deps.now();
|
|
11199
|
+
this.deps.emit({
|
|
11200
|
+
id: this.nextId(obs.deviceId, at),
|
|
11201
|
+
deviceId: obs.deviceId,
|
|
11202
|
+
at,
|
|
11203
|
+
capName: obs.capName,
|
|
11204
|
+
field,
|
|
11205
|
+
from,
|
|
11206
|
+
to,
|
|
11207
|
+
outcome,
|
|
11208
|
+
actor: obs.actor,
|
|
11209
|
+
command: {
|
|
11210
|
+
commandId: entry.commandId,
|
|
11211
|
+
method: obs.method,
|
|
11212
|
+
args: this.deps.prepareArgs(obs.capName, obs.method, obs.args),
|
|
11213
|
+
requestedAt: obs.at,
|
|
11214
|
+
matchedAfterMs,
|
|
11215
|
+
...error !== void 0 ? { error: redactLogText(error).slice(0, ERROR_MAX_CHARS) } : {}
|
|
11216
|
+
}
|
|
11217
|
+
});
|
|
11218
|
+
}
|
|
11219
|
+
/** A change nobody asked for, bounded per field (see {@link DEVICE_ROW_WINDOW_MS}). */
|
|
11220
|
+
emitDevice(deviceId, capName, field, from, to, at) {
|
|
11221
|
+
const key = `${deviceId}|${capName}|${field}`;
|
|
11222
|
+
const window = this.deviceRows.get(key);
|
|
11223
|
+
if (window === void 0 || at - window.lastEmitAt >= 1e4) {
|
|
11224
|
+
if (window?.held !== void 0 && !sameValue(window.held.from, window.held.to)) this.writeDevice(deviceId, capName, field, window.held.from, window.held.to, window.held.at);
|
|
11225
|
+
this.writeDevice(deviceId, capName, field, from, to, at);
|
|
11226
|
+
this.deviceRows.set(key, {
|
|
11227
|
+
deviceId,
|
|
11228
|
+
capName,
|
|
11229
|
+
field,
|
|
11230
|
+
lastEmitAt: at
|
|
11231
|
+
});
|
|
11232
|
+
return;
|
|
11233
|
+
}
|
|
11234
|
+
window.held = {
|
|
11235
|
+
from: window.held?.from ?? from,
|
|
11236
|
+
to,
|
|
11237
|
+
at
|
|
11238
|
+
};
|
|
11239
|
+
}
|
|
11240
|
+
writeDevice(deviceId, capName, field, from, to, at) {
|
|
11241
|
+
this.deps.emit({
|
|
11242
|
+
id: this.nextId(deviceId, at),
|
|
11243
|
+
deviceId,
|
|
11244
|
+
at,
|
|
11245
|
+
capName,
|
|
11246
|
+
field,
|
|
11247
|
+
from,
|
|
11248
|
+
to,
|
|
11249
|
+
outcome: "device",
|
|
11250
|
+
actor: { kind: "device" }
|
|
11251
|
+
});
|
|
11252
|
+
}
|
|
11253
|
+
/** Release coalesced device rows whose window has closed; forget windows nothing is held in. */
|
|
11254
|
+
releaseDeviceRows(now) {
|
|
11255
|
+
for (const [key, window] of this.deviceRows) {
|
|
11256
|
+
if (now - window.lastEmitAt < 1e4) continue;
|
|
11257
|
+
const held = window.held;
|
|
11258
|
+
this.deviceRows.delete(key);
|
|
11259
|
+
if (held === void 0 || sameValue(held.from, held.to)) continue;
|
|
11260
|
+
this.writeDevice(window.deviceId, window.capName, window.field, held.from, held.to, held.at);
|
|
11261
|
+
this.deviceRows.set(key, {
|
|
11262
|
+
...window,
|
|
11263
|
+
held: void 0,
|
|
11264
|
+
lastEmitAt: now
|
|
11265
|
+
});
|
|
11266
|
+
}
|
|
11267
|
+
}
|
|
11268
|
+
keyOf(deviceId, capName) {
|
|
11269
|
+
return `${deviceId}|${capName}`;
|
|
11270
|
+
}
|
|
11271
|
+
nextId(deviceId, at) {
|
|
11272
|
+
this.seq += 1;
|
|
11273
|
+
return `${deviceId}:${at}:${this.seq}`;
|
|
11274
|
+
}
|
|
11275
|
+
nextCommandId(obs) {
|
|
11276
|
+
this.seq += 1;
|
|
11277
|
+
return `${obs.deviceId}:${obs.at}:c${this.seq}`;
|
|
11278
|
+
}
|
|
11279
|
+
};
|
|
11280
|
+
var DROP_LOG_DEVICES_MAX = 10;
|
|
11281
|
+
var TransitionSender = class {
|
|
11282
|
+
deps;
|
|
11283
|
+
queue = [];
|
|
11284
|
+
flushing = false;
|
|
11285
|
+
failing = false;
|
|
11286
|
+
max;
|
|
11287
|
+
constructor(deps) {
|
|
11288
|
+
this.deps = deps;
|
|
11289
|
+
this.max = deps.maxQueued ?? 1e4;
|
|
11290
|
+
}
|
|
11291
|
+
queued() {
|
|
11292
|
+
return this.queue.length;
|
|
11293
|
+
}
|
|
11294
|
+
/**
|
|
11295
|
+
* Give up on what is still queued (shutdown): say how much, and for which devices, then clear.
|
|
11296
|
+
* Rows are telemetry (D8), but a hole in the audit is never silent.
|
|
11297
|
+
*/
|
|
11298
|
+
abandon() {
|
|
11299
|
+
if (this.queue.length === 0) return;
|
|
11300
|
+
const dropped = this.queue.splice(0);
|
|
11301
|
+
this.reportDropped(dropped, "abandoned at shutdown");
|
|
11302
|
+
}
|
|
11303
|
+
enqueue(row) {
|
|
11304
|
+
this.queue.push(row);
|
|
11305
|
+
const over = this.queue.length - this.max;
|
|
11306
|
+
if (over <= 0) return;
|
|
11307
|
+
this.reportDropped(this.queue.splice(0, over), `queue over ${this.max}, oldest dropped`);
|
|
11308
|
+
}
|
|
11309
|
+
reportDropped(dropped, why) {
|
|
11310
|
+
const devices = [...new Set(dropped.map((t) => t.deviceId))];
|
|
11311
|
+
this.deps.logger.error(`device-transitions ${why}: ${dropped.length} transition(s) across ${devices.length} device(s) lost`);
|
|
11312
|
+
for (const deviceId of devices.slice(0, DROP_LOG_DEVICES_MAX)) this.deps.logger.error("device-transitions dropped transitions for this device", { tags: { deviceId } });
|
|
11313
|
+
}
|
|
11314
|
+
async flush() {
|
|
11315
|
+
if (this.flushing) return;
|
|
11316
|
+
this.flushing = true;
|
|
11317
|
+
try {
|
|
11318
|
+
while (this.queue.length > 0) {
|
|
11319
|
+
const batch = this.queue.slice(0, 500);
|
|
11320
|
+
try {
|
|
11321
|
+
await this.deps.send(batch);
|
|
11322
|
+
} catch (err) {
|
|
11323
|
+
if (!this.failing) {
|
|
11324
|
+
this.failing = true;
|
|
11325
|
+
this.deps.logger.error(`device-transitions flush failed, ${this.queue.length} queued: ${err instanceof Error ? err.message : String(err)}`);
|
|
11326
|
+
}
|
|
11327
|
+
return;
|
|
11328
|
+
}
|
|
11329
|
+
this.failing = false;
|
|
11330
|
+
this.queue.splice(0, batch.length);
|
|
11331
|
+
}
|
|
11332
|
+
} finally {
|
|
11333
|
+
this.flushing = false;
|
|
11334
|
+
}
|
|
11335
|
+
}
|
|
11336
|
+
};
|
|
11337
|
+
//#endregion
|
|
11338
|
+
//#region src/builtins/device-manager/transitions/transitions-wiring.ts
|
|
11339
|
+
/**
|
|
11340
|
+
* Starts the hub's device-transition audit (D1022): command observations and
|
|
11341
|
+
* mirror slice changes meet in the correlator, its rows ride a bounded queue to
|
|
11342
|
+
* device-history. Everything here is best-effort telemetry (D8): a failure
|
|
11343
|
+
* costs rows, never a command or a mirror write.
|
|
11344
|
+
*/
|
|
11345
|
+
var TRANSITIONS_FLUSH_INTERVAL_MS = 2e3;
|
|
11346
|
+
var realTicker = (fn, ms) => {
|
|
11347
|
+
const handle = setInterval(fn, ms);
|
|
11348
|
+
return () => clearInterval(handle);
|
|
11349
|
+
};
|
|
11350
|
+
function inputFor(capName, method) {
|
|
11351
|
+
const def = ALL_CAPABILITY_DEFINITIONS.find((d) => d.name === capName);
|
|
11352
|
+
return def === void 0 ? void 0 : expandCapMethods$1(def)[method]?.input;
|
|
11353
|
+
}
|
|
11354
|
+
function startDeviceTransitions(deps) {
|
|
11355
|
+
const now = deps.now ?? Date.now;
|
|
11356
|
+
const ticker = deps.ticker ?? realTicker;
|
|
11357
|
+
const sender = new TransitionSender({
|
|
11358
|
+
send: (batch) => deps.record(batch),
|
|
11359
|
+
logger: deps.logger
|
|
11360
|
+
});
|
|
11361
|
+
const correlator = new TransitionCorrelator({
|
|
11362
|
+
now,
|
|
11363
|
+
currentSlice: (deviceId, capName) => deps.mirror.currentSlice(deviceId, capName),
|
|
11364
|
+
emit: (row) => sender.enqueue(row),
|
|
11365
|
+
prepareArgs: createCommandArgsPreparer(inputFor)
|
|
11366
|
+
});
|
|
11367
|
+
deps.mirror.setTransitionTap((deviceId, capName, prior, slice) => {
|
|
11368
|
+
try {
|
|
11369
|
+
correlator.onSliceChange(deviceId, capName, prior, slice);
|
|
11370
|
+
} catch (err) {
|
|
11371
|
+
deps.logger.error(`device-transitions: correlating a ${capName} change failed: ${err instanceof Error ? err.message : String(err)}`, { tags: { deviceId } });
|
|
11372
|
+
}
|
|
11373
|
+
});
|
|
11374
|
+
const unsubscribe = getCommandObserverRegistry().subscribe((obs) => {
|
|
11375
|
+
if (!isCommand$1(obs.capName, obs.method)) return;
|
|
11376
|
+
try {
|
|
11377
|
+
correlator.recordCommand(obs);
|
|
11378
|
+
} catch (err) {
|
|
11379
|
+
deps.logger.error(`device-transitions: recording a ${obs.capName}.${obs.method} command failed: ${err instanceof Error ? err.message : String(err)}`, { tags: { deviceId: obs.deviceId } });
|
|
11380
|
+
}
|
|
11381
|
+
});
|
|
11382
|
+
const stopTicker = ticker(() => {
|
|
11383
|
+
correlator.sweep();
|
|
11384
|
+
sender.flush();
|
|
11385
|
+
}, TRANSITIONS_FLUSH_INTERVAL_MS);
|
|
11386
|
+
return {
|
|
11387
|
+
forgetDevice: (deviceId) => correlator.forgetDevice(deviceId),
|
|
11388
|
+
stop: async () => {
|
|
11389
|
+
unsubscribe();
|
|
11390
|
+
deps.mirror.setTransitionTap(null);
|
|
11391
|
+
stopTicker();
|
|
11392
|
+
await sender.flush();
|
|
11393
|
+
sender.abandon();
|
|
11394
|
+
}
|
|
11395
|
+
};
|
|
11396
|
+
}
|
|
11397
|
+
//#endregion
|
|
10729
11398
|
//#region src/builtins/device-manager/field-claims-index.ts
|
|
10730
11399
|
/** The addon-store key the index lives under. */
|
|
10731
11400
|
var FIELD_CLAIMS_INDEX_KEY = "field-claims-index";
|
|
@@ -11018,7 +11687,7 @@ async function attempt(steps) {
|
|
|
11018
11687
|
counts[step.store] = await step.run();
|
|
11019
11688
|
} catch (err) {
|
|
11020
11689
|
failed.push(step);
|
|
11021
|
-
errors[step.store] = errMsg(err);
|
|
11690
|
+
errors[step.store] = errMsg$1(err);
|
|
11022
11691
|
}
|
|
11023
11692
|
return {
|
|
11024
11693
|
counts,
|
|
@@ -11181,6 +11850,8 @@ var DeviceManagerAddon = class extends BaseAddon {
|
|
|
11181
11850
|
* `ctx`); `null` before initialise / when `ctx.settings` is absent.
|
|
11182
11851
|
*/
|
|
11183
11852
|
stateMirrorImpl = null;
|
|
11853
|
+
/** The transition audit (D1022): command + mirror correlation, shipped to device-history. */
|
|
11854
|
+
transitions = null;
|
|
11184
11855
|
/**
|
|
11185
11856
|
* Removes the claimed-status overlay this addon installed on the capability
|
|
11186
11857
|
* registry (D663, S3): `getStatus` of a claimed cap answers the mirror for
|
|
@@ -11266,7 +11937,10 @@ var DeviceManagerAddon = class extends BaseAddon {
|
|
|
11266
11937
|
},
|
|
11267
11938
|
holdMirrorWrites: (deviceIds, settings) => this.stateMirror.holdDiskWrites(deviceIds, settings),
|
|
11268
11939
|
mirrorOwnedCaps: (deviceId) => this.stateMirror.ownedCaps(deviceId),
|
|
11269
|
-
forgetMirrorDevice: (deviceId) =>
|
|
11940
|
+
forgetMirrorDevice: (deviceId) => {
|
|
11941
|
+
this.transitions?.forgetDevice(deviceId);
|
|
11942
|
+
return this.stateMirror.forgetDevice(deviceId);
|
|
11943
|
+
},
|
|
11270
11944
|
resolveDeviceOnline: (deviceId, fallbackOnline) => this.stateMirror.resolveDeviceOnline(deviceId, fallbackOnline),
|
|
11271
11945
|
resolveDeviceProbed: (deviceId) => this.stateMirror.resolveDeviceProbed(deviceId),
|
|
11272
11946
|
waitDeviceProvider: (addonId, timeoutMs) => this.waitDeviceProvider(addonId, timeoutMs),
|
|
@@ -11476,11 +12150,20 @@ var DeviceManagerAddon = class extends BaseAddon {
|
|
|
11476
12150
|
try {
|
|
11477
12151
|
await purgeRetiredSettingsRows(deviceRows.retiredRowStore(), this.ctx.logger.child("RetiredRows"));
|
|
11478
12152
|
} catch (err) {
|
|
11479
|
-
this.ctx.logger.warn("retired-row purge failed", { meta: { error: errMsg(err) } });
|
|
12153
|
+
this.ctx.logger.warn("retired-row purge failed", { meta: { error: errMsg$1(err) } });
|
|
11480
12154
|
}
|
|
11481
12155
|
const metaStore = new DeviceMetaStore(settings, registry, deviceRows, this.addonStoreWriteLock);
|
|
11482
12156
|
this.stateMirrorImpl = new DeviceStateMirror(this.ctx);
|
|
11483
12157
|
const stateMirror = this.stateMirrorImpl;
|
|
12158
|
+
this.transitions = startDeviceTransitions({
|
|
12159
|
+
mirror: stateMirror,
|
|
12160
|
+
logger: this.ctx.logger.child("transitions"),
|
|
12161
|
+
record: async (transitions) => {
|
|
12162
|
+
const api = this.ctx.api;
|
|
12163
|
+
if (api === void 0) throw new Error("ctx.api not ready");
|
|
12164
|
+
await api.deviceTransitions.record.mutate({ transitions: [...transitions] });
|
|
12165
|
+
}
|
|
12166
|
+
});
|
|
11484
12167
|
this.fieldClaimsImpl = new FieldClaimsIndex({
|
|
11485
12168
|
logger: this.ctx.logger.child("claims-index"),
|
|
11486
12169
|
withAddonStoreWriteLock: this.addonStoreWriteLock
|
|
@@ -11533,17 +12216,17 @@ var DeviceManagerAddon = class extends BaseAddon {
|
|
|
11533
12216
|
try {
|
|
11534
12217
|
await runLocationBackfillAtBoot(pctx, bootRows);
|
|
11535
12218
|
} catch (err) {
|
|
11536
|
-
this.ctx.logger.warn("location backfill failed — fleet boots without it", { meta: { error: errMsg(err) } });
|
|
12219
|
+
this.ctx.logger.warn("location backfill failed — fleet boots without it", { meta: { error: errMsg$1(err) } });
|
|
11537
12220
|
}
|
|
11538
12221
|
try {
|
|
11539
12222
|
await runDeviceAliasBackfillAtBoot(pctx);
|
|
11540
12223
|
} catch (err) {
|
|
11541
|
-
this.ctx.logger.warn("device alias backfill failed — rows without an alias wait for their next registration", { meta: { error: errMsg(err) } });
|
|
12224
|
+
this.ctx.logger.warn("device alias backfill failed — rows without an alias wait for their next registration", { meta: { error: errMsg$1(err) } });
|
|
11542
12225
|
}
|
|
11543
12226
|
try {
|
|
11544
12227
|
await runLinkedDevicesManualBackfillAtBoot(pctx);
|
|
11545
12228
|
} catch (err) {
|
|
11546
|
-
this.ctx.logger.warn("linked-devices manual backfill failed — auto links are NOT materialised", { meta: { error: errMsg(err) } });
|
|
12229
|
+
this.ctx.logger.warn("linked-devices manual backfill failed — auto links are NOT materialised", { meta: { error: errMsg$1(err) } });
|
|
11547
12230
|
}
|
|
11548
12231
|
const provider = {
|
|
11549
12232
|
resolveDeviceOwnerSync: (deviceId) => resolveDeviceOwnerSync(pctx, deviceId),
|
|
@@ -11797,6 +12480,8 @@ var DeviceManagerAddon = class extends BaseAddon {
|
|
|
11797
12480
|
return this.removalHooksCleanupImpl;
|
|
11798
12481
|
}
|
|
11799
12482
|
async onShutdown() {
|
|
12483
|
+
await this.transitions?.stop();
|
|
12484
|
+
this.transitions = null;
|
|
11800
12485
|
this.removalCleanupImpl?.dispose();
|
|
11801
12486
|
this.removalCleanupImpl = null;
|
|
11802
12487
|
this.removalHooksCleanupImpl?.dispose();
|
|
@@ -11809,4 +12494,4 @@ var DeviceManagerAddon = class extends BaseAddon {
|
|
|
11809
12494
|
}
|
|
11810
12495
|
};
|
|
11811
12496
|
//#endregion
|
|
11812
|
-
export { DeviceManagerAddon, DeviceManagerAddon as default,
|
|
12497
|
+
export { DeviceManagerAddon, DeviceManagerAddon as default, commandObserverLink as a, runObservedCommand as c, readDeviceOrThrow as d, setWrapperActive as f, commandActorFromContext as i, observable as l, mergeAggregates, __resetCommandObserverRegistryForTests as n, getCommandObserverRegistry as o, addonCommandActor as r, reportCommand as s, CommandObserverRegistry as t, createDeviceSettingsStore as u };
|