@avantics/node-red-home-automation 2.2.1 → 3.0.0

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.
Files changed (85) hide show
  1. package/README.md +76 -89
  2. package/contract-examples/room-lighting.mjs +12 -9
  3. package/dist/lib/activity-lighting-controller.d.ts +13 -25
  4. package/dist/lib/activity-lighting-controller.js +15 -11
  5. package/dist/lib/avr-controller.d.ts +17 -28
  6. package/dist/lib/avr-controller.js +165 -116
  7. package/dist/lib/backlighting-controller.d.ts +12 -25
  8. package/dist/lib/backlighting-controller.js +11 -18
  9. package/dist/lib/bounded-trace.d.ts +6 -0
  10. package/dist/lib/circadian-schedule.d.ts +11 -0
  11. package/dist/lib/circadian-schedule.js +63 -0
  12. package/dist/lib/circadian.d.ts +6 -0
  13. package/dist/lib/circadian.js +15 -0
  14. package/dist/lib/command-echo.d.ts +20 -0
  15. package/dist/lib/command-echo.js +82 -0
  16. package/dist/lib/cover-controller.d.ts +15 -28
  17. package/dist/lib/cover-controller.js +6 -8
  18. package/dist/lib/denon-protocol.d.ts +29 -0
  19. package/dist/lib/denon-protocol.js +76 -0
  20. package/dist/lib/display-mode-controller.d.ts +11 -6
  21. package/dist/lib/display-mode-controller.js +90 -39
  22. package/dist/lib/light-styling.d.ts +11 -0
  23. package/dist/lib/light-styling.js +15 -0
  24. package/dist/lib/motion-policy.d.ts +12 -22
  25. package/dist/lib/motion-policy.js +53 -56
  26. package/dist/lib/occupancy-fusion.d.ts +8 -12
  27. package/dist/lib/occupancy-fusion.js +3 -2
  28. package/dist/lib/room-controller.d.ts +13 -38
  29. package/dist/lib/room-controller.js +85 -180
  30. package/dist/lib/room-lighting-discovery.d.ts +9 -0
  31. package/dist/lib/room-lighting-discovery.js +45 -0
  32. package/dist/lib/settings.d.ts +5 -0
  33. package/dist/lib/settings.js +68 -0
  34. package/dist/lib/source-capability-controller.d.ts +32 -35
  35. package/dist/lib/source-capability-controller.js +51 -35
  36. package/dist/lib/switch-policy.d.ts +2 -7
  37. package/dist/lib/target-state.d.ts +24 -0
  38. package/dist/lib/target-state.js +38 -0
  39. package/dist/lib/theatre-activity-controller.d.ts +6 -108
  40. package/dist/lib/theatre-activity-controller.js +67 -318
  41. package/dist/lib/theatre-ha-discovery.d.ts +14 -0
  42. package/dist/lib/theatre-ha-discovery.js +163 -0
  43. package/dist/lib/theatre-metrics.d.ts +4 -0
  44. package/dist/lib/theatre-metrics.js +66 -0
  45. package/dist/lib/theatre-profiles.d.ts +23 -0
  46. package/dist/lib/theatre-profiles.js +73 -0
  47. package/dist/lib/theatre-refresh.d.ts +20 -0
  48. package/dist/lib/theatre-refresh.js +46 -0
  49. package/dist/lib/theatre-slo.js +7 -9
  50. package/dist/lib/theatre-state-contract.d.ts +7 -19
  51. package/dist/lib/theatre-state-contract.js +33 -169
  52. package/dist/lib/theatre-state.d.ts +110 -0
  53. package/dist/lib/theatre-state.js +139 -0
  54. package/dist/lib/wall-input.d.ts +2 -7
  55. package/dist/lib/z2m-light.d.ts +16 -0
  56. package/dist/lib/z2m-light.js +36 -0
  57. package/dist/nodes/activity-lighting-controller.html +5 -3
  58. package/dist/nodes/activity-lighting-controller.js +21 -52
  59. package/dist/nodes/adapter.d.ts +15 -0
  60. package/dist/nodes/adapter.js +60 -0
  61. package/dist/nodes/avr-controller.html +13 -4
  62. package/dist/nodes/avr-controller.js +23 -62
  63. package/dist/nodes/backlighting-controller.html +1 -1
  64. package/dist/nodes/backlighting-controller.js +25 -47
  65. package/dist/nodes/display-mode-controller.html +4 -4
  66. package/dist/nodes/display-mode-controller.js +22 -59
  67. package/dist/nodes/motion-policy.html +23 -10
  68. package/dist/nodes/motion-policy.js +14 -135
  69. package/dist/nodes/occupancy-fusion.html +2 -2
  70. package/dist/nodes/occupancy-fusion.js +23 -29
  71. package/dist/nodes/room-controller.html +92 -34
  72. package/dist/nodes/room-controller.js +46 -64
  73. package/dist/nodes/source-capability-controller.html +4 -13
  74. package/dist/nodes/source-capability-controller.js +17 -52
  75. package/dist/nodes/switch-policy.html +3 -3
  76. package/dist/nodes/switch-policy.js +23 -42
  77. package/dist/nodes/theatre-activity-controller.html +5 -3
  78. package/dist/nodes/theatre-activity-controller.js +23 -43
  79. package/dist/nodes/theatre-state-contract.html +55 -22
  80. package/dist/nodes/theatre-state-contract.js +30 -41
  81. package/examples/Home theatre activity.json +307 -43
  82. package/examples/Home theatre equipment.json +4 -4
  83. package/examples/Room lighting.json +15 -17
  84. package/package.json +3 -7
  85. package/THIRD-PARTY-NOTICES.md +0 -218
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.theatreTopic = theatreTopic;
4
+ exports.theatreDiscovery = theatreDiscovery;
5
+ // The theatre's Home Assistant view: the topic names its state is published
6
+ // on, and the discovery entries that describe them. Home Assistant may send
7
+ // a request on the request topic, which the state contract acts on.
8
+ const theatre_profiles_1 = require("./theatre-profiles");
9
+ // The one place a theatre topic is named, for discovery and state alike.
10
+ function theatreTopic(baseTopic, name) {
11
+ return `${baseTopic}/${name}`;
12
+ }
13
+ function device(config) {
14
+ return {
15
+ identifiers: [`nodered_${config.area}_theatre`],
16
+ name: `${config.displayName} Theatre Controller`,
17
+ manufacturer: "Node-RED",
18
+ model: "Deterministic theatre activity controller"
19
+ };
20
+ }
21
+ function theatreDiscovery(config) {
22
+ const { area, baseTopic, discoveryPrefix } = config;
23
+ const controllerDevice = device(config);
24
+ const entries = [
25
+ {
26
+ component: "select",
27
+ objectId: `${area}_theatre_activity`,
28
+ payload: {
29
+ name: "Requested activity",
30
+ unique_id: `${area}_theatre_activity`,
31
+ default_entity_id: `select.${area}_theatre_activity`,
32
+ icon: "mdi:theater",
33
+ command_topic: theatreTopic(baseTopic, "request"),
34
+ state_topic: theatreTopic(baseTopic, "desired"),
35
+ value_template: "{{ value_json.activity if value_json else none }}",
36
+ command_template: "{\"requestId\":\"ha-{{ now().strftime('%Y%m%d%H%M%S%f') }}\",\"activity\":\"{{ value }}\"}",
37
+ options: config.activities,
38
+ optimistic: false,
39
+ device: controllerDevice
40
+ }
41
+ },
42
+ {
43
+ component: "sensor",
44
+ objectId: `${area}_theatre_current`,
45
+ payload: {
46
+ name: "Current activity",
47
+ unique_id: `${area}_theatre_current`,
48
+ default_entity_id: `sensor.${area}_theatre_current`,
49
+ icon: "mdi:play-circle-outline",
50
+ state_topic: theatreTopic(baseTopic, "current"),
51
+ device: controllerDevice
52
+ }
53
+ },
54
+ {
55
+ component: "sensor",
56
+ objectId: `${area}_theatre_phase`,
57
+ payload: {
58
+ name: "Phase",
59
+ unique_id: `${area}_theatre_phase`,
60
+ default_entity_id: `sensor.${area}_theatre_phase`,
61
+ icon: "mdi:state-machine",
62
+ state_topic: theatreTopic(baseTopic, "phase"),
63
+ device: controllerDevice
64
+ }
65
+ },
66
+ {
67
+ component: "sensor",
68
+ objectId: `${area}_theatre_availability`,
69
+ payload: {
70
+ name: "Availability",
71
+ unique_id: `${area}_theatre_availability`,
72
+ default_entity_id: `sensor.${area}_theatre_availability`,
73
+ icon: "mdi:check-network-outline",
74
+ state_topic: theatreTopic(baseTopic, "availability"),
75
+ entity_category: "diagnostic",
76
+ device: controllerDevice
77
+ }
78
+ },
79
+ {
80
+ component: "sensor",
81
+ objectId: `${area}_theatre_failure`,
82
+ payload: {
83
+ name: "Failure",
84
+ unique_id: `${area}_theatre_failure`,
85
+ default_entity_id: `sensor.${area}_theatre_failure`,
86
+ icon: "mdi:alert-circle-outline",
87
+ state_topic: theatreTopic(baseTopic, "failure"),
88
+ value_template: "{{ value_json.reason if value_json else '' }}",
89
+ entity_category: "diagnostic",
90
+ device: controllerDevice
91
+ }
92
+ },
93
+ {
94
+ component: "sensor",
95
+ objectId: `${area}_theatre_transition_metrics`,
96
+ payload: {
97
+ name: "Transition latency",
98
+ unique_id: `${area}_theatre_transition_metrics`,
99
+ default_entity_id: `sensor.${area}_theatre_transition_metrics`,
100
+ icon: "mdi:timer-check-outline",
101
+ state_topic: theatreTopic(baseTopic, "metrics"),
102
+ value_template: "{{ value_json.lastTransitionMs if value_json.lastTransitionMs is not none else 'unknown' }}",
103
+ json_attributes_topic: theatreTopic(baseTopic, "metrics"),
104
+ unit_of_measurement: "ms",
105
+ entity_category: "diagnostic",
106
+ device: controllerDevice
107
+ }
108
+ },
109
+ {
110
+ component: "sensor",
111
+ objectId: `${area}_theatre_slo_status`,
112
+ payload: {
113
+ name: "Operational SLO",
114
+ unique_id: `${area}_theatre_slo_status`,
115
+ default_entity_id: `sensor.${area}_theatre_slo_status`,
116
+ icon: "mdi:target-account",
117
+ state_topic: theatreTopic(baseTopic, "slo"),
118
+ value_template: "{{ value_json.status }}",
119
+ json_attributes_topic: theatreTopic(baseTopic, "slo"),
120
+ entity_category: "diagnostic",
121
+ device: controllerDevice
122
+ }
123
+ },
124
+ {
125
+ component: "binary_sensor",
126
+ objectId: `${area}_theatre_slo_breach`,
127
+ payload: {
128
+ name: "Operational SLO breach",
129
+ unique_id: `${area}_theatre_slo_breach`,
130
+ default_entity_id: `binary_sensor.${area}_theatre_slo_breach`,
131
+ icon: "mdi:alert-decagram-outline",
132
+ state_topic: theatreTopic(baseTopic, "slo/breach"),
133
+ payload_on: "ON",
134
+ payload_off: "OFF",
135
+ device_class: "problem",
136
+ entity_category: "diagnostic",
137
+ device: controllerDevice
138
+ }
139
+ }
140
+ ];
141
+ for (const target of theatre_profiles_1.TARGETS) {
142
+ entries.push({
143
+ component: "sensor",
144
+ objectId: `${area}_theatre_${target}_health`,
145
+ payload: {
146
+ name: `${target[0]?.toUpperCase()}${target.slice(1)} health`,
147
+ unique_id: `${area}_theatre_${target}_health`,
148
+ default_entity_id: `sensor.${area}_theatre_${target}_health`,
149
+ icon: "mdi:heart-pulse",
150
+ state_topic: theatreTopic(baseTopic, `health/${target}`),
151
+ value_template: "{{ value_json.status }}",
152
+ json_attributes_topic: theatreTopic(baseTopic, `health/${target}`),
153
+ entity_category: "diagnostic",
154
+ device: controllerDevice
155
+ }
156
+ });
157
+ }
158
+ return entries.map(({ component, objectId, payload }) => ({
159
+ topic: `${discoveryPrefix}/${component}/${objectId}/config`,
160
+ payload
161
+ }));
162
+ }
163
+ //# sourceMappingURL=theatre-ha-discovery.js.map
@@ -0,0 +1,4 @@
1
+ import { type TargetState, type TheatreMetrics, type TheatreTargetMetrics } from "./theatre-state";
2
+ export declare function recordOutcome(metrics: TheatreMetrics, outcome: "ready" | "failed" | "manual_override", transitionMs: number | null): void;
3
+ export declare function resetTransitionMetrics(metrics: TheatreMetrics): void;
4
+ export declare function recordTargetReport(metric: TheatreTargetMetrics, report: TargetState, previous: TargetState | null, observedAt: number | null, transitionStartedAt: string | null, nowMs: number): void;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.recordOutcome = recordOutcome;
4
+ exports.resetTransitionMetrics = resetTransitionMetrics;
5
+ exports.recordTargetReport = recordTargetReport;
6
+ // Recording the theatre's metrics. Each function updates the metrics record
7
+ // it is given, which belongs to the controller's state for this event.
8
+ const theatre_profiles_1 = require("./theatre-profiles");
9
+ const theatre_state_1 = require("./theatre-state");
10
+ // An outcome; a finished transition's duration, when timed, as well.
11
+ function recordOutcome(metrics, outcome, transitionMs) {
12
+ if (transitionMs !== null) {
13
+ metrics.lastTransitionMs = transitionMs;
14
+ metrics.maxTransitionMs = Math.max(metrics.maxTransitionMs || 0, transitionMs);
15
+ }
16
+ metrics.lastOutcome = outcome;
17
+ if (outcome === "ready")
18
+ metrics.ready += 1;
19
+ if (outcome === "failed")
20
+ metrics.failed += 1;
21
+ }
22
+ // Per-target figures that describe one transition start again at the next.
23
+ function resetTransitionMetrics(metrics) {
24
+ for (const target of theatre_profiles_1.TARGETS) {
25
+ const metric = metrics.targets[target];
26
+ metric.attempts = 0;
27
+ metric.retries = 0;
28
+ metric.fallbackUsed = false;
29
+ metric.lastConfirmationMs = null;
30
+ metric.observationAgeMs = null;
31
+ metric.availability = "unknown";
32
+ }
33
+ }
34
+ // A target's report: its attempts, fallback use, how old its observation is
35
+ // and, once ready, how long after the transition started it confirmed.
36
+ function recordTargetReport(metric, report, previous, observedAt, transitionStartedAt, nowMs) {
37
+ const details = report.details && typeof report.details === "object" ? report.details : {};
38
+ const detailMetrics = details.metrics && typeof details.metrics === "object" &&
39
+ !Array.isArray(details.metrics)
40
+ ? details.metrics
41
+ : {};
42
+ const attempts = (0, theatre_state_1.count)(detailMetrics.attempts ?? details.attempt);
43
+ metric.attempts = Math.max(metric.attempts, attempts);
44
+ metric.retries = Math.max(metric.retries, Math.max(0, attempts - 1));
45
+ const fallbackUsed = detailMetrics.fallbackUsed === true;
46
+ if (fallbackUsed && !metric.fallbackUsed)
47
+ metric.fallbackUses += 1;
48
+ metric.fallbackUsed ||= fallbackUsed;
49
+ metric.observationAgeMs = observedAt === null ? null : Math.max(0, nowMs - observedAt);
50
+ if (report.status === "ready") {
51
+ const startedAt = Date.parse(transitionStartedAt || "");
52
+ metric.lastConfirmationMs = Number.isFinite(startedAt) && observedAt !== null
53
+ ? Math.max(0, observedAt - startedAt)
54
+ : null;
55
+ metric.availability = "available";
56
+ }
57
+ else if (report.status === "failed" || report.status === "unavailable") {
58
+ metric.availability = "unavailable";
59
+ if (previous?.status !== report.status)
60
+ metric.failures += 1;
61
+ }
62
+ else {
63
+ metric.availability = "degraded";
64
+ }
65
+ }
66
+ //# sourceMappingURL=theatre-metrics.js.map
@@ -0,0 +1,23 @@
1
+ export declare const TARGETS: readonly ["display", "avr", "source", "lighting", "backlighting"];
2
+ export declare const REQUIRED_TARGETS: readonly ["display", "avr", "backlighting"];
3
+ export declare const OPTIONAL_TARGETS: readonly ["lighting"];
4
+ export type TheatreTarget = typeof TARGETS[number];
5
+ export interface ActivitySourceProfile extends Record<string, unknown> {
6
+ action: "activate" | "deactivate";
7
+ readiness: "required" | "optional";
8
+ sourceId?: string | null;
9
+ }
10
+ export interface ActivityLightingProfile extends Record<string, unknown> {
11
+ profile: string;
12
+ }
13
+ export interface ActivityBacklightingProfile extends Record<string, unknown> {
14
+ power: "on" | "off";
15
+ }
16
+ export type ActivityProfile = Record<TheatreTarget, Record<string, unknown>> & {
17
+ source: ActivitySourceProfile;
18
+ lighting: ActivityLightingProfile;
19
+ backlighting: ActivityBacklightingProfile;
20
+ };
21
+ export type ActivityProfiles = Record<string, ActivityProfile>;
22
+ export declare function normaliseActivityProfiles(value: unknown): ActivityProfiles;
23
+ export declare function matchesExpected(expected: unknown, observed: unknown): boolean;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OPTIONAL_TARGETS = exports.REQUIRED_TARGETS = exports.TARGETS = void 0;
4
+ exports.normaliseActivityProfiles = normaliseActivityProfiles;
5
+ exports.matchesExpected = matchesExpected;
6
+ // The theatre's activities as configured: which targets an activity drives,
7
+ // what each target should do, and the checks on that configuration.
8
+ exports.TARGETS = ["display", "avr", "source", "lighting", "backlighting"];
9
+ exports.REQUIRED_TARGETS = ["display", "avr", "backlighting"];
10
+ exports.OPTIONAL_TARGETS = ["lighting"];
11
+ const PROFILE_NAME = /^[a-z][a-z0-9_-]*$/;
12
+ const SOURCE_ACTIONS = { activate: true, deactivate: true };
13
+ const SOURCE_READINESS = { required: true, optional: true };
14
+ const BACKLIGHTING_POWER = {
15
+ on: true,
16
+ off: true
17
+ };
18
+ function normaliseActivityProfiles(value) {
19
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
20
+ throw new Error("activityProfiles must be an object");
21
+ }
22
+ const entries = Object.entries(value);
23
+ if (entries.length === 0)
24
+ throw new Error("activityProfiles must not be empty");
25
+ const profiles = {};
26
+ for (const [name, profileValue] of entries) {
27
+ if (!PROFILE_NAME.test(name))
28
+ throw new Error(`invalid activity profile name: ${name}`);
29
+ if (!profileValue || typeof profileValue !== "object" || Array.isArray(profileValue)) {
30
+ throw new Error(`activity profile ${name} must be an object`);
31
+ }
32
+ const profile = profileValue;
33
+ const targets = {};
34
+ for (const target of exports.TARGETS) {
35
+ const desired = profile[target];
36
+ if (!desired || typeof desired !== "object" || Array.isArray(desired)) {
37
+ throw new Error(`activity profile ${name} must define ${target}`);
38
+ }
39
+ targets[target] = { ...desired };
40
+ }
41
+ const source = targets.source;
42
+ if (!Object.hasOwn(SOURCE_ACTIONS, source.action)) {
43
+ throw new Error(`activity profile ${name} has an invalid source action`);
44
+ }
45
+ if (!Object.hasOwn(SOURCE_READINESS, source.readiness)) {
46
+ throw new Error(`activity profile ${name} has invalid source readiness`);
47
+ }
48
+ if (source.action === "activate" &&
49
+ (typeof source.sourceId !== "string" || !source.sourceId)) {
50
+ throw new Error(`activity profile ${name} must define sourceId`);
51
+ }
52
+ const lighting = targets.lighting;
53
+ if (typeof lighting.profile !== "string" || !PROFILE_NAME.test(lighting.profile)) {
54
+ throw new Error(`activity profile ${name} has invalid lighting profile`);
55
+ }
56
+ const backlighting = targets.backlighting;
57
+ if (!Object.hasOwn(BACKLIGHTING_POWER, backlighting.power)) {
58
+ throw new Error(`activity profile ${name} has invalid backlighting power`);
59
+ }
60
+ profiles[name] = targets;
61
+ }
62
+ return profiles;
63
+ }
64
+ // Whether an observation shows every value a profile expects.
65
+ function matchesExpected(expected, observed) {
66
+ if (!expected || typeof expected !== "object" || Array.isArray(expected)) {
67
+ return Object.is(expected, observed);
68
+ }
69
+ if (!observed || typeof observed !== "object" || Array.isArray(observed))
70
+ return false;
71
+ return Object.entries(expected).every(([key, value]) => matchesExpected(value, observed[key]));
72
+ }
73
+ //# sourceMappingURL=theatre-profiles.js.map
@@ -0,0 +1,20 @@
1
+ import { type TheatreTarget } from "./theatre-profiles";
2
+ import { type RefreshPending } from "./theatre-state";
3
+ export type RefreshAction = {
4
+ target: TheatreTarget;
5
+ kind: "send";
6
+ } | {
7
+ target: TheatreTarget;
8
+ kind: "retry";
9
+ attempt: number;
10
+ } | {
11
+ target: TheatreTarget;
12
+ kind: "re-ask";
13
+ } | {
14
+ target: TheatreTarget;
15
+ kind: "give-up";
16
+ };
17
+ export declare function planRefreshes(pending: Record<TheatreTarget, RefreshPending | null>, lastObserved: (target: TheatreTarget) => number | null, hasRequest: boolean, freshnessMs: number, nowMs: number): {
18
+ pending: Record<TheatreTarget, RefreshPending | null>;
19
+ actions: RefreshAction[];
20
+ };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.planRefreshes = planRefreshes;
4
+ // When the theatre refreshes each target. A confirmed target is refreshed at
5
+ // half its freshness window, so a settled activity stays fresh; an
6
+ // unanswered refresh is re-sent a bounded number of times, then the target is
7
+ // reported as not responding, and it is still asked once per freshness
8
+ // window so it recovers when it answers again. Pure: it plans, the
9
+ // controller sends.
10
+ const theatre_profiles_1 = require("./theatre-profiles");
11
+ const theatre_state_1 = require("./theatre-state");
12
+ function planRefreshes(pending, lastObserved, hasRequest, freshnessMs, nowMs) {
13
+ const intervalMs = freshnessMs / 2;
14
+ const next = { ...pending };
15
+ const actions = [];
16
+ for (const target of theatre_profiles_1.TARGETS) {
17
+ const entry = pending[target];
18
+ if (entry) {
19
+ if (entry.exhausted) {
20
+ if (nowMs - entry.sentAt >= freshnessMs) {
21
+ next[target] = { ...entry, sentAt: nowMs };
22
+ actions.push({ target, kind: "re-ask" });
23
+ }
24
+ continue;
25
+ }
26
+ if (nowMs - entry.sentAt < intervalMs)
27
+ continue;
28
+ if (entry.attempts < theatre_state_1.REFRESH_ATTEMPTS) {
29
+ next[target] = { sentAt: nowMs, attempts: entry.attempts + 1, exhausted: false };
30
+ actions.push({ target, kind: "retry", attempt: entry.attempts + 1 });
31
+ }
32
+ else {
33
+ next[target] = { ...entry, exhausted: true, sentAt: nowMs };
34
+ actions.push({ target, kind: "give-up" });
35
+ }
36
+ continue;
37
+ }
38
+ const observedAt = lastObserved(target);
39
+ if (hasRequest && observedAt !== null && nowMs - observedAt >= intervalMs) {
40
+ next[target] = { sentAt: nowMs, attempts: 1, exhausted: false };
41
+ actions.push({ target, kind: "send" });
42
+ }
43
+ }
44
+ return { pending: next, actions };
45
+ }
46
+ //# sourceMappingURL=theatre-refresh.js.map
@@ -2,19 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normaliseTheatreSloConfig = normaliseTheatreSloConfig;
4
4
  exports.evaluateTheatreSlo = evaluateTheatreSlo;
5
- function boundedInteger(value, fallback, minimum, maximum) {
6
- const parsed = Number(value);
7
- if (!Number.isFinite(parsed))
8
- return fallback;
9
- return Math.max(minimum, Math.min(maximum, Math.round(parsed)));
5
+ const settings_1 = require("./settings");
6
+ function boundedInteger(value, label, fallback, minimum, maximum) {
7
+ return Math.max(minimum, Math.min(maximum, Math.round((0, settings_1.numberSetting)(value, label, fallback))));
10
8
  }
11
9
  function normaliseTheatreSloConfig(config = {}) {
12
- const windowSize = boundedInteger(config.windowSize, 20, 5, 100);
10
+ const windowSize = boundedInteger(config.windowSize, "SLO window", 20, 5, 100);
13
11
  return {
14
12
  windowSize,
15
- minimumSamples: boundedInteger(config.minimumSamples, 5, 1, windowSize),
16
- latencyBudgetMs: boundedInteger(config.latencyBudgetMs, 60000, 1000, 3600000),
17
- successObjectivePct: boundedInteger(config.successObjectivePct, 95, 50, 100)
13
+ minimumSamples: boundedInteger(config.minimumSamples, "minimum samples", 5, 1, windowSize),
14
+ latencyBudgetMs: boundedInteger(config.latencyBudgetMs, "latency budget", 60000, 1000, 3600000),
15
+ successObjectivePct: boundedInteger(config.successObjectivePct, "success objective", 95, 50, 100)
18
16
  };
19
17
  }
20
18
  function duration(value) {
@@ -1,5 +1,7 @@
1
- import { type TheatreMetrics, type TheatreTarget } from "./theatre-activity-controller";
1
+ import { type TheatreTarget } from "./theatre-profiles";
2
+ import type { TheatreMetrics, TheatreSnapshot } from "./theatre-state";
2
3
  import { type TheatreSloConfig, type TheatreSloState } from "./theatre-slo";
4
+ import type { TraceEntry } from "./bounded-trace";
3
5
  export interface TheatreStateContractConfig {
4
6
  area: string;
5
7
  displayName: string;
@@ -7,6 +9,7 @@ export interface TheatreStateContractConfig {
7
9
  discoveryPrefix: string;
8
10
  activities: string[];
9
11
  slo: TheatreSloConfig;
12
+ discovery?: boolean;
10
13
  }
11
14
  export interface ContractRequest {
12
15
  requestId: string;
@@ -19,23 +22,13 @@ export interface TheatreStateContractState {
19
22
  lastRequest: ContractRequest | null;
20
23
  slo: TheatreSloState;
21
24
  }
22
- export interface TheatreStateSnapshot {
23
- kind: "state";
24
- area: string;
25
- requestId: string | null;
26
- generation: number;
27
- desiredActivity: string | null;
28
- requestedAt: string | null;
29
- currentActivity: string;
30
- phase: string;
25
+ export type TheatreStateSnapshot = Omit<TheatreSnapshot, "availability" | "targets" | "failure" | "degraded" | "metrics"> & {
31
26
  availability: string;
32
- transitionStartedAt: string | null;
33
- transitionCompletedAt: string | null;
34
27
  targets: Partial<Record<TheatreTarget, Record<string, unknown> | null>>;
35
28
  failure: Record<string, unknown> | null;
36
29
  degraded: Array<Record<string, unknown>>;
37
30
  metrics?: TheatreMetrics;
38
- }
31
+ };
39
32
  export interface TheatreStateContractMessage {
40
33
  topic?: string;
41
34
  payload?: unknown;
@@ -64,12 +57,7 @@ export declare function transitionTheatreStateContract(saved: Partial<TheatreSta
64
57
  state: TheatreStateContractState;
65
58
  requests: ContractRequestOutput[];
66
59
  publications: ContractPublication[];
67
- traces: {
68
- event: string;
69
- outcome: string;
70
- reason: string | null;
71
- details: Record<string, unknown>;
72
- }[];
60
+ traces: TraceEntry<Record<string, unknown>>[];
73
61
  status: {
74
62
  phase: string;
75
63
  text: string;