@camstack/server 1.2.826 → 1.2.828
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 +14 -0
- package/dist/api/trpc/generated-cap-routers.js +257 -40
- package/dist/core/addon/addon-registry.service.js +3 -0
- package/package.json +10 -12
- package/system/dist/addon-runner.js +19 -2
- package/system/dist/addon-runner.mjs +19 -2
- package/system/dist/addon-utils.mjs +1 -1
- package/system/dist/{agent-https-BBO2OtNH.mjs → agent-https-BSxTUzKT.mjs} +1 -1
- package/system/dist/{agent-https-B2nqARmj.js → agent-https-BlLVD9hG.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 +4 -4
- 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 +5 -5
- package/system/dist/builtins/alerts/alerts.addon.js +1 -1
- package/system/dist/builtins/alerts/alerts.addon.mjs +3 -3
- 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 +5 -5
- 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 +17 -6
- package/system/dist/builtins/composer/composer.addon.mjs +17 -6
- package/system/dist/builtins/composer/graft-host.d.ts +2 -0
- 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.js +3 -3
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +3 -3
- package/system/dist/builtins/device-history/device-history.addon.js +2 -2
- package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
- package/system/dist/builtins/device-manager/device-bindings-store.d.ts +7 -4
- package/system/dist/builtins/device-manager/device-manager.addon.d.ts +2 -0
- package/system/dist/builtins/device-manager/device-manager.addon.js +269 -25
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +269 -25
- package/system/dist/builtins/device-manager/device-meta-actions.d.ts +11 -1
- package/system/dist/builtins/device-manager/device-projection.d.ts +7 -0
- package/system/dist/builtins/device-manager/device-template/mirror-resolver.d.ts +2 -0
- package/system/dist/builtins/device-manager/device-template/template-filters.d.ts +13 -0
- package/system/dist/builtins/device-manager/device-template/template-host.d.ts +11 -3
- package/system/dist/builtins/device-manager/device-template-actions.d.ts +1 -0
- package/system/dist/builtins/device-manager/feature-deriver.d.ts +61 -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 +5 -5
- 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 +1 -1
- package/system/dist/builtins/loki-logging/index.mjs +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +10 -10
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +10 -10
- 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 +20 -20
- 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/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 +115 -115
- 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-DP4HbT3W.js → capture-engine-1A7HAX3x.js} +1 -1
- package/system/dist/{capture-engine-C-rHYVFq.mjs → capture-engine-B0yQx6hA.mjs} +1 -1
- package/system/dist/{composition-sources-CM9c_jAj.js → composition-sources-BzM19ASO.js} +1 -1
- package/system/dist/{composition-sources-CL9JFN4y.mjs → composition-sources-CyJ0d6Sc.mjs} +1 -1
- package/system/dist/{constants-DzGFnCKZ.mjs → constants-B_FLEjP_.mjs} +1 -1
- package/system/dist/{constants-jk7JccZ0.js → constants-DSO4ZEO3.js} +1 -1
- package/system/dist/{coral-accelerators-BW3OcrLD.mjs → coral-accelerators-DBlgWB8k.mjs} +6 -6
- package/system/dist/{custom-action-registry-N7flBDwT.mjs → custom-action-registry-B9zFBNVa.mjs} +37 -37
- package/system/dist/{device-ca-DZ_OQiCc.mjs → device-ca-CveuNCHp.mjs} +1 -1
- package/system/dist/{device-ca-B7_R5WJh.js → device-ca-DLTDsonl.js} +1 -1
- package/system/dist/device-template-worker.js +61 -1
- package/system/dist/device-template-worker.mjs +61 -1
- package/system/dist/{dist-BgRMQHuL.mjs → dist-CIyyHwVx.mjs} +373 -175
- package/system/dist/{dist-BpTL3uNe.js → dist-DhbzVygm.js} +408 -174
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-mdns-ciao-DIcBingB.mjs → hub-mdns-ciao-CQdCUsrI.mjs} +2 -2
- package/system/dist/{hub-mdns-ciao-DPUaYAD3.js → hub-mdns-ciao-C_ITDs0-.js} +2 -2
- package/system/dist/index.js +26 -9
- package/system/dist/index.mjs +238 -221
- package/system/dist/kernel/moleculer/migration-api-facade.d.ts +3 -1
- package/system/dist/{legacy-integration-rows-door-DYNePgj4.js → legacy-integration-rows-door-D_tfRhsx.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-1GnkpMgH.mjs → legacy-integration-rows-door-tX6Qktxd.mjs} +1 -1
- package/system/dist/{rename-composition-block-Cp0_nwAI.mjs → rename-composition-block-COaMxshT.mjs} +1 -1
- package/system/dist/{rename-composition-block-Dn2z4fnA.js → rename-composition-block-DNhbAonr.js} +1 -1
- package/system/dist/{restore-archive-DasubaYH.mjs → restore-archive-BMqp_hMT.mjs} +94 -94
- package/system/dist/{restore-archive-BGa5pdp9.js → restore-archive-Dbzuv5hK.js} +1 -1
- package/system/dist/{template-protocol-CTP4eAo_.js → template-protocol-DRZ4cm95.js} +4 -1
- package/system/dist/{template-protocol-BmMM5VBf.mjs → template-protocol-D_6uVHKs.mjs} +4 -1
- package/system/dist/{wal-maintenance-GWFxnSnE.js → wal-maintenance-CWODOTsa.js} +0 -0
- package/system/dist/{wal-maintenance-BLWLlVfF.mjs → wal-maintenance-ITsLGvFA.mjs} +0 -0
- package/system/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ar as enumerateSchemaFields, Bn as canonicalIconKey, Ec as isDeviceConfigCap, Er as deviceStatusCapability, Fa as resolveTemplateRef, Fr as expandContainer, J as DEVICE_TEMPLATE_MAX_LENGTH, Jc as resolveSecretMarkers, Jr as generateDeviceAlias, Js as WELL_KNOWN_TAB_MAP, Ka as settleDeviceFeatures, Kr as formatMinutes, Ln as buildStreamParamsConfigSchema, Nc as isSecretMarker, Pc as isSecretMarkerLike, Qa as siteZoneKey, R as DAY_NAMES, Ra as runtimeFieldUnit, Si as locationIconKey, Sr as deviceManagerCapability, Tr as deviceStateCapability, Un as checkDeviceAlias, Us as SECRET_CLEAR, Wi as normalizeUnit, Y as DEVICE_TEMPLATE_MAX_OUTPUT, Z as DEVICE_TEMPLATE_VALUES_CAP, Zc as secretTreeFromPaths, Zi as parseStreamParamsFormPatch, _i as legacyAutoLinkIds, b as CAP_NAMES_WITH_STATUS, br as deviceExtensionCapability, cl as DeviceFeature, cr as createDeviceExtensionProvider, dl as errMsg$1, el as sleep$2, en as STREAM_PROFILE_META, hr as defineExtensionSlotProvider, il as userError, it as DiscoveryProposalBodySchema, jc as isSecretClear, k as ConditionMirror, kc as isKeychainStoredField, kr as enumerateItemArrayFields, kt as MINUTES_PER_DAY, li as isKernelDerivedFeature, ll as DeviceRole, mc as defineRecordKinds, mt as FieldClaimSchema, nl as toSecretFieldView, nt as DeviceStatusSchema, oc as collectZodSecretPaths$1, pa as reconcileReportedFeatures, pl as EventCategory$1, ps as BaseAddon, pt as FieldClaimModeSchema, q as DEVICE_TEMPLATE_FILTERS, rl as transformSecretWrite, rt as DeviceTombstoneSchema, s as ALL_CAPABILITY_DEFINITIONS, sc as commandEffect, tc as auditedFields, ts as implementedMethodsOf$1, ul as DeviceType$1, v as CAMERA_SWITCH_ORDER, vc as expandCapMethods$1, wc as isCommand$1, za as runtimeStatePolicyFor } from "../../dist-CIyyHwVx.mjs";
|
|
2
2
|
import { t as require_read_all_rows } from "../../read-all-rows-TaPqdWNF.mjs";
|
|
3
3
|
import { a as redactLogText, i as redactLogMeta, n as isSecretArgumentKey } from "../../log-redactor-XLDrPzOi.mjs";
|
|
4
|
-
import { n as renameCompositionBlock, t as composedBlockIdOf } from "../../rename-composition-block-
|
|
4
|
+
import { n as renameCompositionBlock, t as composedBlockIdOf } from "../../rename-composition-block-COaMxshT.mjs";
|
|
5
5
|
import { t as prefixRange } from "../../prefix-range-Dl0znowN.mjs";
|
|
6
6
|
import { t as loadPrefixed } from "../../prefix-walk-DAOBSyH1.mjs";
|
|
7
7
|
import { n as purgeRetiredSettingsRows } from "../../retired-settings-keys-u6xQA6r7.mjs";
|
|
8
|
-
import { n as isRenderResponse, r as analyzeTemplate } from "../../template-protocol-
|
|
8
|
+
import { n as isRenderResponse, r as analyzeTemplate } from "../../template-protocol-D_6uVHKs.mjs";
|
|
9
9
|
import { s as normalizeServiceType } from "../../dns-wire-Dm3H_7ST.mjs";
|
|
10
10
|
import { createRequire } from "node:module";
|
|
11
11
|
import { z } from "zod";
|
|
@@ -352,6 +352,18 @@ function persistedFeatures(features) {
|
|
|
352
352
|
return out;
|
|
353
353
|
}
|
|
354
354
|
/**
|
|
355
|
+
* The features a device is shown with (#459). The kernel owns the `derived`
|
|
356
|
+
* ones, and the row is where it keeps them, so they come from the row; a
|
|
357
|
+
* driver's own list (the live array, or the row when the live one is empty)
|
|
358
|
+
* decides only the rest. Without a row the live list is all there is.
|
|
359
|
+
*/
|
|
360
|
+
function projectedFeatures(live, persisted) {
|
|
361
|
+
if (persisted === void 0) return persistedFeatures(live);
|
|
362
|
+
const driverOwned = (live.length > 0 ? live : persisted).filter((value) => !isKernelDerivedFeature(value));
|
|
363
|
+
const kernelOwned = persisted.filter((value) => isKernelDerivedFeature(value));
|
|
364
|
+
return persistedFeatures([...new Set([...driverOwned, ...kernelOwned])]);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
355
367
|
* Infer `isCamera` from a persisted DeviceType.
|
|
356
368
|
*
|
|
357
369
|
* Live projection uses method presence (`getStreamSources` via
|
|
@@ -429,7 +441,7 @@ function toDeviceInfo(addonId, device, metadata = null, metaRow = null) {
|
|
|
429
441
|
role: device.role ?? null,
|
|
430
442
|
online: device.online,
|
|
431
443
|
probed,
|
|
432
|
-
features: device.features
|
|
444
|
+
features: projectedFeatures(device.features, metaRow?.features),
|
|
433
445
|
isCamera: isCameraDevice(device),
|
|
434
446
|
config: configValues,
|
|
435
447
|
...liveSecretConfigPaths(device),
|
|
@@ -1322,7 +1334,7 @@ var StaleWrapperActivations = class {
|
|
|
1322
1334
|
function wireRemoteNativeCapSync(ctx, remoteNativeCaps) {
|
|
1323
1335
|
const localNodeId = ctx.kernel.localNodeId ?? "hub";
|
|
1324
1336
|
ctx.eventBus.subscribe({ category: EventCategory$1.DeviceBindingsChanged }, (event) => {
|
|
1325
|
-
const { deviceId, capName, reason, addonId, nodeId } = event.data;
|
|
1337
|
+
const { deviceId, capName, reason, addonId, nodeId, implementedMethods } = event.data;
|
|
1326
1338
|
if (nodeId === localNodeId) return;
|
|
1327
1339
|
if (reason === "native-registered") {
|
|
1328
1340
|
let perDevice = remoteNativeCaps.get(deviceId);
|
|
@@ -1344,7 +1356,8 @@ function wireRemoteNativeCapSync(ctx, remoteNativeCaps) {
|
|
|
1344
1356
|
}
|
|
1345
1357
|
perDevice.set(capName, {
|
|
1346
1358
|
addonId,
|
|
1347
|
-
nodeId
|
|
1359
|
+
nodeId,
|
|
1360
|
+
...implementedMethods !== void 0 ? { implementedMethods } : {}
|
|
1348
1361
|
});
|
|
1349
1362
|
} else if (reason === "native-unregistered") {
|
|
1350
1363
|
const perDevice = remoteNativeCaps.get(deviceId);
|
|
@@ -1644,12 +1657,14 @@ async function resolveBindingsForDevice(deps, deviceId, row, pass) {
|
|
|
1644
1657
|
if (deps.capabilityRegistry) for (const capName of deps.capabilityRegistry.getNativeCapsForDevice(deviceId)) {
|
|
1645
1658
|
if (seenCaps.has(capName)) continue;
|
|
1646
1659
|
const nativeAddonId = deps.capabilityRegistry.getNativeAddonId(capName, deviceId) ?? "";
|
|
1660
|
+
const implementedMethods = localImplementedMethods(deps, capName, deviceId);
|
|
1647
1661
|
entries.push({
|
|
1648
1662
|
capName,
|
|
1649
1663
|
kind: "native",
|
|
1650
1664
|
providerAddonId: nativeAddonId,
|
|
1651
1665
|
providerNodeId: deps.ctx.kernel.localNodeId ?? "hub",
|
|
1652
|
-
nativeAddonId
|
|
1666
|
+
nativeAddonId,
|
|
1667
|
+
...implementedMethods !== void 0 ? { implementedMethods } : {}
|
|
1653
1668
|
});
|
|
1654
1669
|
seenCaps.add(capName);
|
|
1655
1670
|
}
|
|
@@ -1661,7 +1676,8 @@ async function resolveBindingsForDevice(deps, deviceId, row, pass) {
|
|
|
1661
1676
|
kind: "native",
|
|
1662
1677
|
providerAddonId: info.addonId,
|
|
1663
1678
|
providerNodeId: toRoutableProviderNodeId(info.nodeId),
|
|
1664
|
-
nativeAddonId: info.addonId
|
|
1679
|
+
nativeAddonId: info.addonId,
|
|
1680
|
+
...info.implementedMethods !== void 0 ? { implementedMethods: info.implementedMethods } : {}
|
|
1665
1681
|
});
|
|
1666
1682
|
seenCaps.add(capName);
|
|
1667
1683
|
}
|
|
@@ -1773,6 +1789,19 @@ async function listDeviceIdsByCaps(deps, input) {
|
|
|
1773
1789
|
const wanted = new Set(input.capNames);
|
|
1774
1790
|
return (await getAllBindings(deps)).filter((row) => row.entries.some((entry) => wanted.has(entry.capName))).map((row) => row.deviceId);
|
|
1775
1791
|
}
|
|
1792
|
+
/**
|
|
1793
|
+
* The methods a HUB-LOCAL native provider object implements, read off the
|
|
1794
|
+
* object registered for `(cap, device)`; `undefined` when it cannot be said
|
|
1795
|
+
* (no definition, no provider), which the derivation reads as "all".
|
|
1796
|
+
*/
|
|
1797
|
+
function localImplementedMethods(deps, capName, deviceId) {
|
|
1798
|
+
const registry = deps.capabilityRegistry;
|
|
1799
|
+
if (registry === void 0) return void 0;
|
|
1800
|
+
const definition = registry.getDefinition(capName);
|
|
1801
|
+
const provider = registry.getNativeProvider(capName, deviceId);
|
|
1802
|
+
if (definition === void 0 || provider === null) return void 0;
|
|
1803
|
+
return implementedMethodsOf$1(Object.keys(definition.methods), provider);
|
|
1804
|
+
}
|
|
1776
1805
|
//#endregion
|
|
1777
1806
|
//#region src/builtins/device-manager/day-night-config-schema.ts
|
|
1778
1807
|
var MODE_LABELS = {
|
|
@@ -4837,6 +4866,114 @@ var DeviceEventPropagator = class {
|
|
|
4837
4866
|
}
|
|
4838
4867
|
};
|
|
4839
4868
|
//#endregion
|
|
4869
|
+
//#region src/builtins/device-manager/feature-deriver.ts
|
|
4870
|
+
/**
|
|
4871
|
+
* Keeps each device's persisted features equal to what its bindings imply (#459).
|
|
4872
|
+
*
|
|
4873
|
+
* Event-driven AND reconciled: `DeviceBindingsChanged` is telemetry and may be
|
|
4874
|
+
* dropped (D8/D49), so {@link reconcileAll} runs at boot and a missed event
|
|
4875
|
+
* costs only until the next one. There are no timers and no retries. A read
|
|
4876
|
+
* that fails changes nothing: the stored features stay as they were, because a
|
|
4877
|
+
* feature set derived from an empty answer would strip every feature of a
|
|
4878
|
+
* device the registry merely could not describe yet (D49). The same holds for
|
|
4879
|
+
* an answer that does not carry the device's own provider ONLINE: wrapper
|
|
4880
|
+
* entries alone, or natives cached for an agent that went offline, mean
|
|
4881
|
+
* "unknown", never "absent" (D315, {@link nativeProviderOnline}).
|
|
4882
|
+
*
|
|
4883
|
+
* Writes for one device run one after another and a burst collapses into the
|
|
4884
|
+
* run already waiting, so a worker registering twenty caps costs two settles.
|
|
4885
|
+
*/
|
|
4886
|
+
var FeatureDeriver = class {
|
|
4887
|
+
deps;
|
|
4888
|
+
tails = /* @__PURE__ */ new Map();
|
|
4889
|
+
queued = /* @__PURE__ */ new Set();
|
|
4890
|
+
constructor(deps) {
|
|
4891
|
+
this.deps = deps;
|
|
4892
|
+
}
|
|
4893
|
+
/** A binding of `deviceId` changed (or may have): settle it after the settles already queued. */
|
|
4894
|
+
onBindingsChanged(deviceId) {
|
|
4895
|
+
if (this.queued.has(deviceId)) return this.tails.get(deviceId) ?? Promise.resolve();
|
|
4896
|
+
this.queued.add(deviceId);
|
|
4897
|
+
const next = (this.tails.get(deviceId) ?? Promise.resolve()).then(async () => {
|
|
4898
|
+
this.queued.delete(deviceId);
|
|
4899
|
+
await this.settleOne(deviceId);
|
|
4900
|
+
});
|
|
4901
|
+
this.tails.set(deviceId, next);
|
|
4902
|
+
next.finally(() => {
|
|
4903
|
+
if (this.tails.get(deviceId) === next) this.tails.delete(deviceId);
|
|
4904
|
+
});
|
|
4905
|
+
return next;
|
|
4906
|
+
}
|
|
4907
|
+
/** Boot reconcile: settle every device from one fleet read. Returns how many moved. */
|
|
4908
|
+
async reconcileAll() {
|
|
4909
|
+
let all;
|
|
4910
|
+
try {
|
|
4911
|
+
all = await this.deps.allBindings();
|
|
4912
|
+
} catch (err) {
|
|
4913
|
+
this.deps.logger.warn("feature reconcile skipped — the fleet bindings could not be read", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
4914
|
+
return 0;
|
|
4915
|
+
}
|
|
4916
|
+
let moved = 0;
|
|
4917
|
+
for (const { deviceId, entries } of all) if (await this.applyOne(deviceId, entries)) moved += 1;
|
|
4918
|
+
this.deps.logger.info("feature reconcile done", { meta: {
|
|
4919
|
+
devices: all.length,
|
|
4920
|
+
moved
|
|
4921
|
+
} });
|
|
4922
|
+
return moved;
|
|
4923
|
+
}
|
|
4924
|
+
async settleOne(deviceId) {
|
|
4925
|
+
let entries;
|
|
4926
|
+
try {
|
|
4927
|
+
entries = await this.deps.bindingsOf(deviceId);
|
|
4928
|
+
} catch (err) {
|
|
4929
|
+
this.deps.logger.warn("feature derive skipped — bindings could not be read", {
|
|
4930
|
+
tags: { deviceId },
|
|
4931
|
+
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
4932
|
+
});
|
|
4933
|
+
return;
|
|
4934
|
+
}
|
|
4935
|
+
await this.applyOne(deviceId, entries);
|
|
4936
|
+
}
|
|
4937
|
+
async applyOne(deviceId, entries) {
|
|
4938
|
+
if (!nativeProviderOnline(entries, this.deps.nodeOnline)) {
|
|
4939
|
+
this.deps.logger.debug("feature derive deferred — the device provider is not online", {
|
|
4940
|
+
tags: { deviceId },
|
|
4941
|
+
meta: { entries: entries.length }
|
|
4942
|
+
});
|
|
4943
|
+
return false;
|
|
4944
|
+
}
|
|
4945
|
+
try {
|
|
4946
|
+
return await this.deps.apply(deviceId, entries);
|
|
4947
|
+
} catch (err) {
|
|
4948
|
+
this.deps.logger.warn("feature derive failed — stored features left as they were", {
|
|
4949
|
+
tags: { deviceId },
|
|
4950
|
+
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
4951
|
+
});
|
|
4952
|
+
return false;
|
|
4953
|
+
}
|
|
4954
|
+
}
|
|
4955
|
+
};
|
|
4956
|
+
/**
|
|
4957
|
+
* True when the device's own provider serves at least one of its caps and
|
|
4958
|
+
* every node it serves them from is online. A native cap is registered only
|
|
4959
|
+
* by the process the device lives in, so its `providerNodeId` is where the
|
|
4960
|
+
* device runs. This is a liveness question, not routing (D13 untouched).
|
|
4961
|
+
*
|
|
4962
|
+
* A device whose own provider serves NO cap (wrapper-only, or a native it
|
|
4963
|
+
* only decorates) never derives, on purpose: with no native of its own,
|
|
4964
|
+
* nothing can say a feature is absent, so its declared features stay.
|
|
4965
|
+
*/
|
|
4966
|
+
function nativeProviderOnline(entries, nodeOnline) {
|
|
4967
|
+
const served = entries.filter((entry) => entry.nativeAddonId.length > 0 && entry.providerAddonId === entry.nativeAddonId);
|
|
4968
|
+
return served.length > 0 && served.every((entry) => nodeOnline(entry.providerNodeId));
|
|
4969
|
+
}
|
|
4970
|
+
/** Feed the deriver from the bus; returns the unsubscribe. */
|
|
4971
|
+
function subscribeFeatureDeriver(eventBus, deriver) {
|
|
4972
|
+
return eventBus.subscribe({ category: EventCategory$1.DeviceBindingsChanged }, (event) => {
|
|
4973
|
+
deriver.onBindingsChanged(event.data.deviceId);
|
|
4974
|
+
});
|
|
4975
|
+
}
|
|
4976
|
+
//#endregion
|
|
4840
4977
|
//#region src/builtins/device-manager/device-extension-linked-slot.ts
|
|
4841
4978
|
/** The routing prefix of this owner's `slotRef`s. */
|
|
4842
4979
|
var DEVICE_MANAGER_EXTENSION_SOURCE = "device-manager";
|
|
@@ -6576,17 +6713,18 @@ async function registerDevice(pctx, input) {
|
|
|
6576
6713
|
throw new Error(`[device-manager] registerDevice: device ${id} (${addonId}/${stableId}) was removed — refusing to resurrect it`);
|
|
6577
6714
|
}
|
|
6578
6715
|
if (Array.isArray(input.secretConfigPaths)) pctx.secretConfigPaths.set(id, input.secretConfigPaths);
|
|
6579
|
-
const { isFirstRegistration, exportFingerprint, fingerprintChanged, inheritedLocation, inheritedDescendantIds, inheritFailed } = await pctx.metaStore.withMetaWriteLock(async () => {
|
|
6716
|
+
const { isFirstRegistration, exportFingerprint, fingerprintChanged, storedFeatures, inheritedLocation, inheritedDescendantIds, inheritFailed } = await pctx.metaStore.withMetaWriteLock(async () => {
|
|
6580
6717
|
const existingRow = await pctx.metaStore.rows.get(id);
|
|
6581
6718
|
const existingMeta = existingRow?.meta;
|
|
6582
6719
|
const wasRegistered = existingRow?.registered ?? false;
|
|
6583
6720
|
const wasUserNamed = existingMeta?.userNamed ?? (existingMeta !== void 0 && existingMeta.name !== stableId);
|
|
6584
6721
|
const resolvedName = wasUserNamed && existingMeta !== void 0 ? existingMeta.name : name;
|
|
6585
6722
|
const isFirst = !existingMeta || !wasRegistered;
|
|
6723
|
+
const settledFeatures = reconcileReportedFeatures(existingMeta?.features, featuresArr);
|
|
6586
6724
|
const fingerprint = canonicalDeviceFingerprint({
|
|
6587
6725
|
deviceId: id,
|
|
6588
6726
|
deviceType: type,
|
|
6589
|
-
features:
|
|
6727
|
+
features: settledFeatures
|
|
6590
6728
|
});
|
|
6591
6729
|
const priorLocation = existingMeta?.location ?? null;
|
|
6592
6730
|
const resolvedParentId = parentDeviceId ?? null;
|
|
@@ -6603,7 +6741,7 @@ async function registerDevice(pctx, input) {
|
|
|
6603
6741
|
disabled: existingMeta?.disabled ?? false,
|
|
6604
6742
|
parentDeviceId: resolvedParentId,
|
|
6605
6743
|
registered: true,
|
|
6606
|
-
features:
|
|
6744
|
+
features: settledFeatures,
|
|
6607
6745
|
exportFingerprint: fingerprint
|
|
6608
6746
|
});
|
|
6609
6747
|
if (existingMeta?.alias === void 0) await pctx.metaStore.rows.patch(id, { alias: await freeAliasFor(pctx.metaStore.rows, resolvedName, id, await readReservedAliases(pctx)) });
|
|
@@ -6623,6 +6761,7 @@ async function registerDevice(pctx, input) {
|
|
|
6623
6761
|
}
|
|
6624
6762
|
return {
|
|
6625
6763
|
isFirstRegistration: isFirst,
|
|
6764
|
+
storedFeatures: settledFeatures,
|
|
6626
6765
|
exportFingerprint: fingerprint,
|
|
6627
6766
|
fingerprintChanged: existingMeta?.exportFingerprint !== fingerprint,
|
|
6628
6767
|
inheritedLocation: inherited,
|
|
@@ -6691,7 +6830,7 @@ async function registerDevice(pctx, input) {
|
|
|
6691
6830
|
name: name.length > 0 ? name : stableId,
|
|
6692
6831
|
providerId: addonId,
|
|
6693
6832
|
parentDeviceId: parentDeviceId ?? null,
|
|
6694
|
-
features:
|
|
6833
|
+
features: storedFeatures
|
|
6695
6834
|
}
|
|
6696
6835
|
});
|
|
6697
6836
|
if (isFirstRegistration || fingerprintChanged) pctx.host.ctx.eventBus.emit({
|
|
@@ -6710,6 +6849,61 @@ async function registerDevice(pctx, input) {
|
|
|
6710
6849
|
});
|
|
6711
6850
|
}
|
|
6712
6851
|
/**
|
|
6852
|
+
* Re-derive a device's features from its bindings and persist them when they
|
|
6853
|
+
* moved (#459). The settle runs INSIDE the meta write lock against the row as
|
|
6854
|
+
* it is there, so a concurrent `registerDevice` cannot land between the read
|
|
6855
|
+
* and the write. A row that does not exist is left alone (a binding event can
|
|
6856
|
+
* outlive the device), and an unchanged set writes nothing and announces
|
|
6857
|
+
* nothing. A changed one stamps the new fingerprint and, like `registerDevice`,
|
|
6858
|
+
* emits `DeviceProvisioned` so exporters reconcile with one delta.
|
|
6859
|
+
*/
|
|
6860
|
+
async function applyDerivedFeatures(pctx, deviceId, entries) {
|
|
6861
|
+
const outcome = await pctx.metaStore.withMetaWriteLock(async () => {
|
|
6862
|
+
const row = await pctx.metaStore.rows.get(deviceId);
|
|
6863
|
+
if (row === null || !row.registered) return null;
|
|
6864
|
+
const settled = settleDeviceFeatures(entries, row.meta.features ?? []);
|
|
6865
|
+
const stored = row.meta.features ?? [];
|
|
6866
|
+
if (settled.length === stored.length && settled.every((value, i) => value === stored[i])) return null;
|
|
6867
|
+
const fingerprint = canonicalDeviceFingerprint({
|
|
6868
|
+
deviceId,
|
|
6869
|
+
deviceType: row.meta.type,
|
|
6870
|
+
features: settled
|
|
6871
|
+
});
|
|
6872
|
+
await pctx.metaStore.rows.patch(deviceId, {
|
|
6873
|
+
features: settled,
|
|
6874
|
+
exportFingerprint: fingerprint
|
|
6875
|
+
});
|
|
6876
|
+
return {
|
|
6877
|
+
fingerprint,
|
|
6878
|
+
features: settled,
|
|
6879
|
+
previous: stored
|
|
6880
|
+
};
|
|
6881
|
+
});
|
|
6882
|
+
if (outcome === null) return false;
|
|
6883
|
+
pctx.host.ctx.logger.info("device features re-derived from bindings", {
|
|
6884
|
+
tags: { deviceId },
|
|
6885
|
+
meta: {
|
|
6886
|
+
from: outcome.previous,
|
|
6887
|
+
to: outcome.features
|
|
6888
|
+
}
|
|
6889
|
+
});
|
|
6890
|
+
pctx.host.ctx.eventBus.emit({
|
|
6891
|
+
id: randomUUID(),
|
|
6892
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
6893
|
+
source: {
|
|
6894
|
+
type: "device",
|
|
6895
|
+
id: deviceId
|
|
6896
|
+
},
|
|
6897
|
+
category: EventCategory$1.DeviceProvisioned,
|
|
6898
|
+
data: {
|
|
6899
|
+
deviceId,
|
|
6900
|
+
fingerprint: outcome.fingerprint,
|
|
6901
|
+
generation: Date.now()
|
|
6902
|
+
}
|
|
6903
|
+
});
|
|
6904
|
+
return true;
|
|
6905
|
+
}
|
|
6906
|
+
/**
|
|
6713
6907
|
* The stores device-manager (or the keychain, for secrets) keeps for a device.
|
|
6714
6908
|
* Another addon's own per-device data is cleaned by that addon, off
|
|
6715
6909
|
* `DeviceUnregistered` — the kernel never reaches into its tables (D864).
|
|
@@ -8058,7 +8252,7 @@ function mirrorTemplateResolver(mirror, devices, unitOf) {
|
|
|
8058
8252
|
return { viewOf(alias) {
|
|
8059
8253
|
const device = byAlias.get(alias);
|
|
8060
8254
|
if (device === void 0) return void 0;
|
|
8061
|
-
const slices = {};
|
|
8255
|
+
const slices = { ...device.values };
|
|
8062
8256
|
for (const cap of device.caps) {
|
|
8063
8257
|
const slice = mirror.sliceOf(device.deviceId, cap);
|
|
8064
8258
|
if (slice !== void 0) slices[cap] = slice;
|
|
@@ -8095,7 +8289,7 @@ var DeviceTemplateHost = class {
|
|
|
8095
8289
|
* restriction (an admin, a system run). A restricted caller gets the same
|
|
8096
8290
|
* answer for an alias that does not exist and one it may not see.
|
|
8097
8291
|
*/
|
|
8098
|
-
async check(source, allowed) {
|
|
8292
|
+
async check(source, allowed, thisDevice) {
|
|
8099
8293
|
const analysis = this.deps.renderer.validate(source);
|
|
8100
8294
|
if (!analysis.ok) return {
|
|
8101
8295
|
ok: false,
|
|
@@ -8103,31 +8297,47 @@ var DeviceTemplateHost = class {
|
|
|
8103
8297
|
message: analysis.refusal.message
|
|
8104
8298
|
};
|
|
8105
8299
|
const aliases = [];
|
|
8106
|
-
|
|
8107
|
-
|
|
8300
|
+
const named = analysis.refs.filter((ref) => ref.alias !== "now");
|
|
8301
|
+
for (const alias of new Set(named.map((ref) => ref.alias))) {
|
|
8302
|
+
const row = await this.rowOf(alias, thisDevice);
|
|
8108
8303
|
aliases.push({
|
|
8109
8304
|
alias,
|
|
8110
8305
|
deviceId: row === null ? null : row.deviceId,
|
|
8111
8306
|
allowed: allowed === void 0 || row !== null && allowed.has(row.deviceId),
|
|
8112
|
-
row
|
|
8307
|
+
row,
|
|
8308
|
+
reads: [...new Set(named.filter((ref) => ref.alias === alias).map((ref) => ref.path.map(String).join(".")))].filter((read) => read !== "")
|
|
8113
8309
|
});
|
|
8114
8310
|
}
|
|
8115
8311
|
return {
|
|
8116
8312
|
ok: true,
|
|
8117
|
-
aliases
|
|
8313
|
+
aliases,
|
|
8314
|
+
readsClock: analysis.refs.some((ref) => ref.alias === "now")
|
|
8118
8315
|
};
|
|
8119
8316
|
}
|
|
8317
|
+
/** `camera` is the device the render is for when the call names one; every other alias is a device's own. */
|
|
8318
|
+
async rowOf(alias, thisDevice) {
|
|
8319
|
+
if (alias === "camera" && thisDevice !== void 0) {
|
|
8320
|
+
const row = await this.deps.findById(thisDevice.deviceId);
|
|
8321
|
+
return row === null ? null : {
|
|
8322
|
+
...row,
|
|
8323
|
+
alias
|
|
8324
|
+
};
|
|
8325
|
+
}
|
|
8326
|
+
return this.deps.findByAlias(alias);
|
|
8327
|
+
}
|
|
8120
8328
|
/** Render every template; answers are index-aligned with the questions. */
|
|
8121
|
-
async render(sources, allowed) {
|
|
8122
|
-
const checks = await Promise.all(sources.map((source) => this.check(source, allowed)));
|
|
8329
|
+
async render(sources, allowed, thisDevice) {
|
|
8330
|
+
const checks = await Promise.all(sources.map((source) => this.check(source, allowed, thisDevice)));
|
|
8123
8331
|
const rows = /* @__PURE__ */ new Map();
|
|
8124
8332
|
for (const check of checks) {
|
|
8125
8333
|
if (!check.ok) continue;
|
|
8126
8334
|
for (const use of check.aliases) {
|
|
8127
8335
|
if (!use.allowed || use.row === null || rows.has(use.alias)) continue;
|
|
8336
|
+
const caps = await this.deps.capsOf(use.row.deviceId);
|
|
8128
8337
|
rows.set(use.alias, {
|
|
8129
8338
|
...use.row,
|
|
8130
|
-
caps
|
|
8339
|
+
caps,
|
|
8340
|
+
...use.alias === "camera" && thisDevice?.values !== void 0 ? { values: { [DEVICE_TEMPLATE_VALUES_CAP]: thisDevice.values } } : {}
|
|
8131
8341
|
});
|
|
8132
8342
|
}
|
|
8133
8343
|
}
|
|
@@ -8405,6 +8615,14 @@ var DeviceTemplateRenderer = class {
|
|
|
8405
8615
|
const tree = new ContextTree();
|
|
8406
8616
|
const resolvedFor = /* @__PURE__ */ new Map();
|
|
8407
8617
|
for (const ref of analysis.refs) {
|
|
8618
|
+
if (ref.alias === "now") {
|
|
8619
|
+
if (ref.path.length === 0) tree.place(ref.alias, [], this.now());
|
|
8620
|
+
else trace.push({
|
|
8621
|
+
ref: refText(ref),
|
|
8622
|
+
reason: "unknown-field"
|
|
8623
|
+
});
|
|
8624
|
+
continue;
|
|
8625
|
+
}
|
|
8408
8626
|
const view = resolver.viewOf(ref.alias);
|
|
8409
8627
|
if (view === void 0) {
|
|
8410
8628
|
trace.push({
|
|
@@ -8612,6 +8830,7 @@ var DeviceTemplateActions = class {
|
|
|
8612
8830
|
this.host = new DeviceTemplateHost({
|
|
8613
8831
|
renderer: this.renderer,
|
|
8614
8832
|
findByAlias: this.deps.findByAlias,
|
|
8833
|
+
findById: this.deps.findById,
|
|
8615
8834
|
capsOf: this.deps.capsOf,
|
|
8616
8835
|
fetchSlice: this.deps.fetchSlice,
|
|
8617
8836
|
unitOf: baseUnitOfRuntimeField,
|
|
@@ -8622,21 +8841,23 @@ var DeviceTemplateActions = class {
|
|
|
8622
8841
|
}
|
|
8623
8842
|
async render(input) {
|
|
8624
8843
|
const allowed = input.allowedDeviceIds === void 0 ? void 0 : new Set(input.allowedDeviceIds);
|
|
8625
|
-
return { results: await this.hostOf().render(input.templates, allowed) };
|
|
8844
|
+
return { results: await this.hostOf().render(input.templates, allowed, input.thisDevice) };
|
|
8626
8845
|
}
|
|
8627
8846
|
async check(input) {
|
|
8628
8847
|
const allowed = input.allowedDeviceIds === void 0 ? void 0 : new Set(input.allowedDeviceIds);
|
|
8629
8848
|
const host = this.hostOf();
|
|
8630
8849
|
const results = [];
|
|
8631
8850
|
for (const source of input.templates) {
|
|
8632
|
-
const check = await host.check(source, allowed);
|
|
8851
|
+
const check = await host.check(source, allowed, input.thisDevice);
|
|
8633
8852
|
results.push(check.ok ? {
|
|
8634
8853
|
ok: true,
|
|
8635
8854
|
aliases: check.aliases.map((use) => ({
|
|
8636
8855
|
alias: use.alias,
|
|
8637
8856
|
deviceId: use.deviceId,
|
|
8638
|
-
allowed: use.allowed
|
|
8639
|
-
|
|
8857
|
+
allowed: use.allowed,
|
|
8858
|
+
reads: [...use.reads]
|
|
8859
|
+
})),
|
|
8860
|
+
readsClock: check.readsClock
|
|
8640
8861
|
} : {
|
|
8641
8862
|
ok: false,
|
|
8642
8863
|
refusal: {
|
|
@@ -12547,6 +12768,8 @@ var DeviceManagerAddon = class extends BaseAddon {
|
|
|
12547
12768
|
* populated. Stopped in `onShutdown`.
|
|
12548
12769
|
*/
|
|
12549
12770
|
propagator = null;
|
|
12771
|
+
/** Stops the bindings → features subscription; run in `onShutdown`. */
|
|
12772
|
+
unsubscribeFeatureDeriver = null;
|
|
12550
12773
|
/**
|
|
12551
12774
|
* Hub-side mirror of every device's cap-keyed runtime state.
|
|
12552
12775
|
* Populated whenever any caller writes via `deviceState.setCapSlice`
|
|
@@ -13170,6 +13393,15 @@ var DeviceManagerAddon = class extends BaseAddon {
|
|
|
13170
13393
|
migrationInFlight: (deviceId) => pctx.migrationGuard.isInFlight(deviceId)
|
|
13171
13394
|
})
|
|
13172
13395
|
};
|
|
13396
|
+
const featureDeriver = new FeatureDeriver({
|
|
13397
|
+
bindingsOf: async (deviceId) => (await getBindings(this.bindingsDeps, { deviceId })).entries,
|
|
13398
|
+
allBindings: () => getAllBindings(this.bindingsDeps),
|
|
13399
|
+
apply: (deviceId, entries) => applyDerivedFeatures(pctx, deviceId, entries),
|
|
13400
|
+
nodeOnline: (nodeId) => nodeId === (this.ctx.kernel.localNodeId ?? "hub") || (this.ctx.kernel.isNodeRegistered?.(nodeId) ?? false),
|
|
13401
|
+
logger: this.ctx.logger.child("features")
|
|
13402
|
+
});
|
|
13403
|
+
this.unsubscribeFeatureDeriver = subscribeFeatureDeriver(this.ctx.eventBus, featureDeriver);
|
|
13404
|
+
featureDeriver.reconcileAll();
|
|
13173
13405
|
return [
|
|
13174
13406
|
{
|
|
13175
13407
|
capability: deviceManagerCapability,
|
|
@@ -13214,6 +13446,16 @@ var DeviceManagerAddon = class extends BaseAddon {
|
|
|
13214
13446
|
alias
|
|
13215
13447
|
};
|
|
13216
13448
|
},
|
|
13449
|
+
findById: async (deviceId) => {
|
|
13450
|
+
const row = await this.deviceRows?.get(deviceId);
|
|
13451
|
+
if (row === void 0 || row === null) return null;
|
|
13452
|
+
return {
|
|
13453
|
+
deviceId: row.meta.id,
|
|
13454
|
+
addonId: row.meta.addonId,
|
|
13455
|
+
stableId: row.meta.stableId,
|
|
13456
|
+
alias: row.meta.alias ?? ""
|
|
13457
|
+
};
|
|
13458
|
+
},
|
|
13217
13459
|
capsOf: async (deviceId) => (await this.getBindings({ deviceId })).entries.map((entry) => entry.capName),
|
|
13218
13460
|
fetchSlice: async (deviceId, cap) => {
|
|
13219
13461
|
const api = this.ctx.api;
|
|
@@ -13238,6 +13480,8 @@ var DeviceManagerAddon = class extends BaseAddon {
|
|
|
13238
13480
|
this.removalHooksCleanupImpl = null;
|
|
13239
13481
|
this.propagator?.stop();
|
|
13240
13482
|
this.propagator = null;
|
|
13483
|
+
this.unsubscribeFeatureDeriver?.();
|
|
13484
|
+
this.unsubscribeFeatureDeriver = null;
|
|
13241
13485
|
this.uninstallStatusOverlay?.();
|
|
13242
13486
|
this.uninstallStatusOverlay = null;
|
|
13243
13487
|
await this.stateMirrorImpl?.flushPendingWrites(this.ctx.settings);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AddonContext } from "@camstack/types";
|
|
2
|
-
import { deviceManagerCapability, InferProvider } from "@camstack/types";
|
|
2
|
+
import { type DeviceBindingEntry, deviceManagerCapability, InferProvider } from "@camstack/types";
|
|
3
3
|
import type { DeviceMetaStore } from "./device-meta-store.js";
|
|
4
4
|
import type { ProviderContext } from "./device-provider-context.js";
|
|
5
5
|
type IDeviceManagerProvider = InferProvider<typeof deviceManagerCapability>;
|
|
@@ -35,6 +35,16 @@ export declare function allocateDeviceId(pctx: ProviderContext, input: Parameter
|
|
|
35
35
|
*/
|
|
36
36
|
export declare function migrateDevice(pctx: ProviderContext, input: Parameters<IDeviceManagerProvider["migrateDevice"]>[0]): ReturnType<IDeviceManagerProvider["migrateDevice"]>;
|
|
37
37
|
export declare function registerDevice(pctx: ProviderContext, input: Parameters<IDeviceManagerProvider["registerDevice"]>[0]): ReturnType<IDeviceManagerProvider["registerDevice"]>;
|
|
38
|
+
/**
|
|
39
|
+
* Re-derive a device's features from its bindings and persist them when they
|
|
40
|
+
* moved (#459). The settle runs INSIDE the meta write lock against the row as
|
|
41
|
+
* it is there, so a concurrent `registerDevice` cannot land between the read
|
|
42
|
+
* and the write. A row that does not exist is left alone (a binding event can
|
|
43
|
+
* outlive the device), and an unchanged set writes nothing and announces
|
|
44
|
+
* nothing. A changed one stamps the new fingerprint and, like `registerDevice`,
|
|
45
|
+
* emits `DeviceProvisioned` so exporters reconcile with one delta.
|
|
46
|
+
*/
|
|
47
|
+
export declare function applyDerivedFeatures(pctx: ProviderContext, deviceId: number, entries: readonly DeviceBindingEntry[]): Promise<boolean>;
|
|
38
48
|
export declare function removeDevice(pctx: ProviderContext, input: Parameters<IDeviceManagerProvider["removeDevice"]>[0]): ReturnType<IDeviceManagerProvider["removeDevice"]>;
|
|
39
49
|
export declare function persistConfig(pctx: ProviderContext, input: Parameters<IDeviceManagerProvider["persistConfig"]>[0]): ReturnType<IDeviceManagerProvider["persistConfig"]>;
|
|
40
50
|
export declare function loadConfig(pctx: ProviderContext, input: Parameters<IDeviceManagerProvider["loadConfig"]>[0]): ReturnType<IDeviceManagerProvider["loadConfig"]>;
|
|
@@ -31,6 +31,13 @@ export declare function isCameraDevice(device: IDevice): device is ICameraDevice
|
|
|
31
31
|
*/
|
|
32
32
|
export declare function persistedFeatures(features: readonly string[] | undefined): DeviceFeature[];
|
|
33
33
|
/**
|
|
34
|
+
* The features a device is shown with (#459). The kernel owns the `derived`
|
|
35
|
+
* ones, and the row is where it keeps them, so they come from the row; a
|
|
36
|
+
* driver's own list (the live array, or the row when the live one is empty)
|
|
37
|
+
* decides only the rest. Without a row the live list is all there is.
|
|
38
|
+
*/
|
|
39
|
+
export declare function projectedFeatures(live: readonly string[], persisted: readonly string[] | undefined): DeviceFeature[];
|
|
40
|
+
/**
|
|
34
41
|
* Infer `isCamera` from a persisted DeviceType.
|
|
35
42
|
*
|
|
36
43
|
* Live projection uses method presence (`getStreamSources` via
|
|
@@ -13,6 +13,8 @@ export interface TemplateDeviceEntry {
|
|
|
13
13
|
readonly stableId: string;
|
|
14
14
|
readonly alias: string;
|
|
15
15
|
readonly caps: readonly string[];
|
|
16
|
+
/** Slices the caller supplies itself (`camera.values`), beside the ones the mirror holds. */
|
|
17
|
+
readonly values?: Readonly<Record<string, unknown>>;
|
|
16
18
|
}
|
|
17
19
|
/** The slices the mirror must hold so these devices' templates can render. */
|
|
18
20
|
export declare function templateMirrorSources(devices: readonly TemplateDeviceEntry[]): readonly MirrorSource[];
|
|
@@ -12,11 +12,24 @@ export declare const RANGE_MAX = 1e3;
|
|
|
12
12
|
export declare function rangeGlobal(...args: readonly unknown[]): readonly number[];
|
|
13
13
|
export declare function unitFilter(input: unknown, from: unknown, to: unknown): unknown;
|
|
14
14
|
export declare function roundFilter(input: unknown, digits: unknown): unknown;
|
|
15
|
+
/**
|
|
16
|
+
* `trunc(n)`: cut to `n` decimals toward zero, never round (19.99 at one decimal is 19.9).
|
|
17
|
+
* The same arithmetic as the OSD's old formatter, so a migrated text prints what it did.
|
|
18
|
+
*/
|
|
19
|
+
export declare function truncFilter(input: unknown, digits: unknown): unknown;
|
|
20
|
+
/** `onoff`: a boolean reads `ON` / `OFF`; anything else passes through untouched (a number stays a number). */
|
|
21
|
+
export declare function onoffFilter(input: unknown): unknown;
|
|
15
22
|
export declare function defaultFilter(input: unknown, fallback: unknown): unknown;
|
|
16
23
|
/** `since`: how long ago a timestamp was, as `5 min`. `nowMs` comes with the request, never from a clock in the worker. */
|
|
17
24
|
export declare function makeSinceFilter(nowMs: number): (input: unknown) => unknown;
|
|
18
25
|
/** `ago`: `5 min ago`. */
|
|
19
26
|
export declare function makeAgoFilter(nowMs: number): (input: unknown) => unknown;
|
|
27
|
+
/**
|
|
28
|
+
* `time('HH:mm')`: an epoch timestamp as clock text, in the zone of the process
|
|
29
|
+
* (the server's). Tokens `YYYY MM DD HH mm ss`; everything else is literal and a
|
|
30
|
+
* source character is consumed once, so a substituted digit is never re-read.
|
|
31
|
+
*/
|
|
32
|
+
export declare function timeFilter(input: unknown, pattern: unknown): unknown;
|
|
20
33
|
/** `format('%.1f')`, `format('%d items')`, `format('%s')`: one value, one placeholder. */
|
|
21
34
|
export declare function formatFilter(input: unknown, pattern: unknown): unknown;
|
|
22
35
|
/** What `{{ … }}` prints. Unknown values read as `unavailable`; objects never print their shape. */
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* it only through `device-manager.renderDeviceTemplates`; there is no second
|
|
9
9
|
* renderer and no second copy of the state.
|
|
10
10
|
*/
|
|
11
|
-
import { type DeviceTemplateRefusalReason, type DeviceTemplateRender, type DeviceTemplateView, type IScopedLogger } from "@camstack/types";
|
|
11
|
+
import { type DeviceTemplateRefusalReason, type DeviceTemplateRender, type DeviceTemplateThisDevice, type DeviceTemplateView, type IScopedLogger } from "@camstack/types";
|
|
12
12
|
import type { DeviceTemplateRenderer } from "./template-renderer.js";
|
|
13
13
|
/** What the host needs to know about a device a template names. */
|
|
14
14
|
export interface TemplateDeviceRow {
|
|
@@ -21,6 +21,8 @@ export interface DeviceTemplateHostDeps {
|
|
|
21
21
|
readonly renderer: Pick<DeviceTemplateRenderer, "render" | "validate">;
|
|
22
22
|
/** The device that owns an alias, from the persisted rows. */
|
|
23
23
|
findByAlias(alias: string): Promise<TemplateDeviceRow | null>;
|
|
24
|
+
/** The device row behind an id, for the device a render is FOR (`camera`). */
|
|
25
|
+
findById(deviceId: number): Promise<TemplateDeviceRow | null>;
|
|
24
26
|
/** The capabilities a device is bound to (its template namespace). */
|
|
25
27
|
capsOf(deviceId: number): Promise<readonly string[]>;
|
|
26
28
|
/** One runtime-state slice, as the effective merge every consumer sees. */
|
|
@@ -36,10 +38,14 @@ export interface TemplateAliasUse {
|
|
|
36
38
|
readonly allowed: boolean;
|
|
37
39
|
/** The persisted row, resolved once here and reused by the render. */
|
|
38
40
|
readonly row: TemplateDeviceRow | null;
|
|
41
|
+
/** The fields the text reads on this alias, as written (`temperature`, `cap.field`). */
|
|
42
|
+
readonly reads: readonly string[];
|
|
39
43
|
}
|
|
40
44
|
export type TemplateCheck = {
|
|
41
45
|
readonly ok: true;
|
|
42
46
|
readonly aliases: readonly TemplateAliasUse[];
|
|
47
|
+
/** The text reads `now`: its output moves with the clock. */
|
|
48
|
+
readonly readsClock: boolean;
|
|
43
49
|
} | {
|
|
44
50
|
readonly ok: false;
|
|
45
51
|
readonly reason: DeviceTemplateRefusalReason;
|
|
@@ -54,7 +60,9 @@ export declare class DeviceTemplateHost {
|
|
|
54
60
|
* restriction (an admin, a system run). A restricted caller gets the same
|
|
55
61
|
* answer for an alias that does not exist and one it may not see.
|
|
56
62
|
*/
|
|
57
|
-
check(source: string, allowed: ReadonlySet<number> | undefined): Promise<TemplateCheck>;
|
|
63
|
+
check(source: string, allowed: ReadonlySet<number> | undefined, thisDevice?: DeviceTemplateThisDevice): Promise<TemplateCheck>;
|
|
64
|
+
/** `camera` is the device the render is for when the call names one; every other alias is a device's own. */
|
|
65
|
+
private rowOf;
|
|
58
66
|
/** Render every template; answers are index-aligned with the questions. */
|
|
59
|
-
render(sources: readonly string[], allowed: ReadonlySet<number> | undefined): Promise<DeviceTemplateRender[]>;
|
|
67
|
+
render(sources: readonly string[], allowed: ReadonlySet<number> | undefined, thisDevice?: DeviceTemplateThisDevice): Promise<DeviceTemplateRender[]>;
|
|
60
68
|
}
|
|
@@ -13,6 +13,7 @@ type CheckOutput = Awaited<ReturnType<IDeviceManagerProvider["checkDeviceTemplat
|
|
|
13
13
|
/** What the actions need from the device-manager addon, beyond the provider context. */
|
|
14
14
|
export interface TemplateActionDeps {
|
|
15
15
|
findByAlias(alias: string): Promise<TemplateDeviceRow | null>;
|
|
16
|
+
findById(deviceId: number): Promise<TemplateDeviceRow | null>;
|
|
16
17
|
capsOf(deviceId: number): Promise<readonly string[]>;
|
|
17
18
|
fetchSlice(deviceId: number, cap: string): Promise<unknown>;
|
|
18
19
|
}
|