@camstack/types 1.2.118 → 1.2.120

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.
@@ -790,6 +790,17 @@ export interface ICamstackAddon {
790
790
  * persisted store. */
791
791
  getGlobalSettings?(overlay?: Record<string, unknown>, cap?: string, nodeId?: string): Promise<ConfigUISchemaWithValues | null>;
792
792
  updateGlobalSettings?(patch: Record<string, unknown>, nodeId?: string): Promise<void>;
793
+ /**
794
+ * Integration-level settings — the subset of the global schema the addon
795
+ * declared as its INTEGRATION's configuration (`BaseAddon.
796
+ * integrationSettingSections`). `null` ⇒ none declared, so the surface is
797
+ * not offered.
798
+ *
799
+ * There is no matching updater on purpose: the payload is a subset of the
800
+ * global schema, so `updateGlobalSettings` is the writer and the store key
801
+ * stays the one bare key. See `addon-settings.cap.ts`.
802
+ */
803
+ getIntegrationSettings?(nodeId?: string): Promise<ConfigUISchemaWithValues | null>;
793
804
  /** Level 2 — per-device settings (schema + values). Appears in
794
805
  * Device Overrides. */
795
806
  getDeviceSettings?(deviceId: number): Promise<ConfigUISchemaWithValues>;
@@ -0,0 +1,173 @@
1
+ /**
2
+ * `FailureCounters` — the per-camera counter every "how often does this camera
3
+ * lose work, and why" question is answered from.
4
+ *
5
+ * ## Why a primitive and not four counters
6
+ *
7
+ * Four open failure modes were being triaged on 2026-08-28 and every one of
8
+ * them was measured the same way: grep a log line, count it, and then guess at
9
+ * the denominator. The guess is the defect. `enrichment crop native miss` read
10
+ * as "35x worse than yesterday" and turned out to be **flat all day** the
11
+ * moment it was divided by the successes on the same path — 0.25 misses per
12
+ * landed capture, 0.08–0.33 across twelve hours, no trend. The count moved
13
+ * because the traffic moved.
14
+ *
15
+ * So the unit here is not a counter. It is a **ratio with its denominator
16
+ * attached**: {@link FailureCounterSample.attempts} is incremented on every
17
+ * try, {@link FailureCounterSample.succeeded} on the ones that landed, and the
18
+ * reasons partition the rest. A consumer can always divide; it can never
19
+ * un-divide a bare count.
20
+ *
21
+ * ## Per camera, always
22
+ *
23
+ * The key is the numeric `deviceId` — the same value every log line in this
24
+ * repo carries as `tags.deviceId`. There is no fleet-total mode and no
25
+ * device-less bucket, because the question is always "why is 617 worse than
26
+ * 615?" and a fleet total cannot answer it. A caller that cannot name the
27
+ * camera must not note anything: an unnamed per-camera count is
28
+ * indistinguishable from a shared one, which is how one camera's failures
29
+ * quietly become everybody's.
30
+ *
31
+ * ## Cumulative, never drained
32
+ *
33
+ * A read NEVER resets anything. `load-contribution.cap.ts` already argued this
34
+ * for CPU seconds and the argument carries over verbatim: *"a rate needs a
35
+ * window, a window needs a sampler, and a new per-node sampler is the defect
36
+ * half of `docs/architecture/load-ledger.md` documents. A counter can be
37
+ * differenced by whoever already keeps a history; a rate cannot be
38
+ * un-averaged."* A draining read has a second failure this surface cannot
39
+ * afford — two consumers polling it would each destroy half of the other's
40
+ * numbers, silently.
41
+ *
42
+ * {@link FailureCounterSample.sinceMs} is the incarnation marker: it is when
43
+ * this counter started, and a consumer differencing two reads must drop the
44
+ * interval when it changes, because the counter restarted from zero in a new
45
+ * process.
46
+ *
47
+ * ## Bounded, and the bound is the point
48
+ *
49
+ * This lives in the memory of a process that is already the subject of an RSS
50
+ * budget, so both dimensions are capped: {@link MAX_KEYS} counters and
51
+ * {@link MAX_REASONS_PER_KEY} distinct reasons within one. Past the reason cap
52
+ * the counts are folded into {@link OVERFLOW_REASON} rather than dropped —
53
+ * losing them would make `attempts - succeeded` stop equalling the reason
54
+ * total, and the ratio the whole surface exists to publish would quietly stop
55
+ * adding up. Past the key cap a new key is refused and
56
+ * {@link FailureCounters.keysRefused} says so, so the omission is visible
57
+ * instead of silent.
58
+ *
59
+ * ## No timers, no IO, no logging
60
+ *
61
+ * Pure. It is read on whatever beat the caller already has. A telemetry
62
+ * primitive that schedules its own work is a second sampler, and this repo has
63
+ * paid for one of those already (`docs/architecture/load-ledger.md`).
64
+ */
65
+ /** Distinct reason strings kept per counter before folding. */
66
+ export declare const MAX_REASONS_PER_KEY = 16;
67
+ /**
68
+ * Distinct (device, family, variant) counters one instance will hold.
69
+ *
70
+ * A large fleet x the handful of families any single addon reports, with
71
+ * slack. At ~200 B per counter this is a ~100 KB ceiling on a process that
72
+ * already declares an RSS budget in the gigabytes.
73
+ */
74
+ export declare const MAX_KEYS = 1024;
75
+ /**
76
+ * Where reasons past {@link MAX_REASONS_PER_KEY} go.
77
+ *
78
+ * They are FOLDED, never dropped: `attempts - succeeded` must always equal the
79
+ * sum of the reason counts, or the ratio stops adding up.
80
+ */
81
+ export declare const OVERFLOW_REASON = "other";
82
+ /** One reason and how many times it was the reason. */
83
+ export interface FailureReasonCount {
84
+ readonly reason: string;
85
+ readonly count: number;
86
+ }
87
+ /** One (device, family[, variant]) counter, read. */
88
+ export interface FailureCounterSample {
89
+ readonly deviceId: number;
90
+ /**
91
+ * The failing path, in the contributor's own vocabulary — `enrichment-crop`,
92
+ * `inference`, `plate-ocr`. Free-form because the families are owned by
93
+ * different addons and a shared enum would be a central list that rots
94
+ * invisibly the first time somebody adds a path (the argument
95
+ * `load-contribution.cap.ts` makes about pid maps, applied to reasons).
96
+ */
97
+ readonly family: string;
98
+ /**
99
+ * An optional second dimension WITHIN the family — the model or step id for
100
+ * an inference timeout, so "which camera AND which model" is answerable
101
+ * without a second surface. Absent when the family has only one variant.
102
+ */
103
+ readonly variant?: string;
104
+ /**
105
+ * Epoch ms this counter started — the incarnation marker. A consumer
106
+ * differencing two reads drops the interval when it changes, because the
107
+ * counter restarted from zero in a new process.
108
+ */
109
+ readonly sinceMs: number;
110
+ /** Epoch ms it was read. `atMs - sinceMs` is the interval it covers. */
111
+ readonly atMs: number;
112
+ /** THE DENOMINATOR. Every try, landed or not. */
113
+ readonly attempts: number;
114
+ /** Tries that landed. `attempts - succeeded` is the loss. */
115
+ readonly succeeded: number;
116
+ /** Why the rest did not, partitioned. Sums to `attempts - succeeded`. */
117
+ readonly reasons: readonly FailureReasonCount[];
118
+ }
119
+ /** What one observation says. */
120
+ export interface FailureObservation {
121
+ readonly deviceId: number;
122
+ readonly family: string;
123
+ readonly variant?: string;
124
+ /**
125
+ * `undefined` = the attempt LANDED. A string = it did not, and this is why.
126
+ * There is no third state: a call that cannot say which it was must not be
127
+ * noted, because an attempt with no outcome moves the denominator without
128
+ * moving anything else and silently improves the ratio.
129
+ */
130
+ readonly reason?: string;
131
+ }
132
+ /**
133
+ * A bounded set of per-camera, cumulative failure counters.
134
+ *
135
+ * One instance per contributing subsystem. `note` is O(1) and allocation-free
136
+ * on the steady path; `snapshot` reads without mutating anything.
137
+ */
138
+ export declare class FailureCounters {
139
+ private readonly maxKeys;
140
+ private readonly maxReasons;
141
+ private readonly counters;
142
+ private refused;
143
+ constructor(maxKeys?: number, maxReasons?: number);
144
+ /**
145
+ * Counters refused because {@link MAX_KEYS} was already held.
146
+ *
147
+ * Cumulative for the life of the instance: a bound that bit is a fact about
148
+ * the deployment, and a surface that hid it would under-report a fleet
149
+ * precisely when the fleet got large enough to matter.
150
+ */
151
+ get keysRefused(): number;
152
+ /** Counters currently held. */
153
+ get size(): number;
154
+ /**
155
+ * Fold one observation in.
156
+ *
157
+ * A non-positive or non-integer `deviceId` is REFUSED rather than bucketed:
158
+ * see the module docblock — an entry that cannot name its camera is worse
159
+ * than no entry.
160
+ */
161
+ note(observation: FailureObservation, nowMs: number): void;
162
+ /** Read every counter. Never mutates — see the module docblock. */
163
+ snapshot(nowMs: number): readonly FailureCounterSample[];
164
+ /** Drop everything (host disposal). */
165
+ clear(): void;
166
+ }
167
+ /**
168
+ * Losses per attempt, as a ratio — the number the operator actually reads.
169
+ *
170
+ * `null` when there were no attempts: a camera nobody asked anything of has no
171
+ * failure rate, and reporting 0 would say it was perfect.
172
+ */
173
+ export declare function failureRate(sample: FailureCounterSample): number | null;
@@ -685,6 +685,40 @@ var BaseAddon = class {
685
685
  deviceSettingsSchema() {
686
686
  return null;
687
687
  }
688
+ /**
689
+ * INTEGRATION-LEVEL SETTINGS — declare which of this addon's global sections
690
+ * ARE the configuration of its integration.
691
+ *
692
+ * Return the `ConfigSection.id`s, from {@link globalSettingsSchema}, that an
693
+ * operator should find on the addon's integration page (System →
694
+ * Integrations → <name>) rather than only in the cluster-wide list of every
695
+ * addon. Empty (the default) means the addon has no integration-level
696
+ * settings and no such surface is offered — this is opt-in, because whether
697
+ * an addon's configuration IS its integration's configuration depends on the
698
+ * nature of the integration.
699
+ *
700
+ * WHAT THIS IS NOT. It is not a scope. The selected sections keep living in
701
+ * the ONE global schema, in the ONE addon store, written by the ONE
702
+ * `updateGlobalSettings` path. There is deliberately no
703
+ * `updateIntegrationSettings`: a second write path is how a surface acquires
704
+ * a second store key, and this repo has shipped that twice (`btmPath@hub`,
705
+ * D266). Selecting sections cannot introduce a key that selecting cannot.
706
+ *
707
+ * WHY IT IS A LIST OF SECTION IDS AND NOT A MARKER ON THE SECTION.
708
+ * `ConfigFieldBase` used to carry `scope?: 'device' | 'global'` and it was
709
+ * removed with the reason recorded at
710
+ * `packages/types/src/interfaces/config-ui.ts:249` — *"a field's scope is
711
+ * determined by WHICH schema it lives in, not by a field-level marker."* A
712
+ * marker sprinkled across sections also has to borrow a field that already
713
+ * means something else; borrowing `section.tab` put the literal word
714
+ * "integration" into an operator-facing tab bar, because `tab` means "how to
715
+ * GROUP this visually" and cannot also mean "where this lives" (D269
716
+ * supersedes D268). One declaration, in one place, next to the schema whose
717
+ * ids it names.
718
+ */
719
+ integrationSettingSections() {
720
+ return [];
721
+ }
688
722
  async getGlobalSettings(overlay, cap, nodeId) {
689
723
  const schema = this.globalSettingsSchema(cap);
690
724
  if (!schema) return { sections: [] };
@@ -695,6 +729,55 @@ var BaseAddon = class {
695
729
  } : projected);
696
730
  }
697
731
  /**
732
+ * The integration-level view of this addon's settings: exactly the sections
733
+ * named by {@link integrationSettingSections}, hydrated from the SAME store
734
+ * `getGlobalSettings` reads, and narrowed to cluster-scoped fields.
735
+ *
736
+ * Returns `null` when the addon declared nothing — an addon that opts out has
737
+ * no integration settings surface at all, rather than an empty one that reads
738
+ * as a failed load.
739
+ *
740
+ * Three properties hold BY CONSTRUCTION, which is why they are here in core
741
+ * and not in whichever UI happens to render this:
742
+ *
743
+ * 1. **One key.** The payload is a SUBSET of the global schema, so a field
744
+ * shown here is the same field, with the same bare key, that the addon's
745
+ * own page shows. There is no integration-specific writer — callers save
746
+ * through `updateGlobalSettings` — so a second store key is unreachable,
747
+ * not merely discouraged.
748
+ * 2. **No node scope.** `perNode: true` fields are DROPPED. Their store key
749
+ * is `<key>@<nodeId>` and an integration is not a node; whichever node
750
+ * such a field silently picked would be a wrong answer for the operator
751
+ * who opened the page (D266).
752
+ * 3. **No silent typo.** A declared id that names no section throws. The
753
+ * alternative — skip it — turns a rename into a surface that quietly
754
+ * empties, which looks exactly like an addon with nothing to configure.
755
+ */
756
+ async getIntegrationSettings(nodeId) {
757
+ const declared = this.integrationSettingSections();
758
+ if (declared.length === 0) return null;
759
+ const schema = this.globalSettingsSchema();
760
+ if (!schema) throw new Error(`${this.constructor.name}: integrationSettingSections() names [${declared.join(", ")}] but globalSettingsSchema() returns null.`);
761
+ const byId = new Map(schema.sections.map((section) => [section.id, section]));
762
+ const sections = [];
763
+ for (const id of declared) {
764
+ const section = byId.get(id);
765
+ if (!section) throw new Error(`${this.constructor.name}: integrationSettingSections() names unknown section "${id}". Known sections: [${[...byId.keys()].join(", ")}].`);
766
+ const fields = dropPerNodeFields(section.fields);
767
+ if (fields.length === 0) continue;
768
+ sections.push({
769
+ ...section,
770
+ fields
771
+ });
772
+ }
773
+ if (sections.length === 0) return null;
774
+ const projected = await this.resolveGlobalStore(nodeId);
775
+ return hydrateSchema({
776
+ ...schema,
777
+ sections
778
+ }, projected);
779
+ }
780
+ /**
698
781
  * The raw addon store PROJECTED onto the target node's bare per-node keys:
699
782
  * every `perNode: true` field carries THAT node's scoped value on its bare
700
783
  * key (absent scoped key ⇒ key absent, so the schema `default` wins — no
@@ -998,6 +1081,41 @@ var BaseAddon = class {
998
1081
  * `hydrateSchema` does. Valueless structural fields (separator/info/…)
999
1082
  * don't declare `perNode` and are excluded by the `in` narrowing.
1000
1083
  */
1084
+ /**
1085
+ * The same fields with every `perNode: true` one removed, recursing into layout
1086
+ * containers exactly as {@link collectPerNodeFieldKeys} does. A container left
1087
+ * with no child is dropped rather than rendered empty.
1088
+ *
1089
+ * Used by `getIntegrationSettings`: an integration is not a node, so a field
1090
+ * whose store key is `<key>@<nodeId>` has no node to belong to there.
1091
+ */
1092
+ function dropPerNodeFields(fields) {
1093
+ const kept = [];
1094
+ for (const field of fields) {
1095
+ if (field.type === "group") {
1096
+ const inner = dropPerNodeFields(field.fields);
1097
+ if (inner.length > 0) kept.push({
1098
+ ...field,
1099
+ fields: inner
1100
+ });
1101
+ continue;
1102
+ }
1103
+ if (field.type === "sub-tabs") {
1104
+ const tabs = field.tabs.map((tab) => ({
1105
+ ...tab,
1106
+ fields: dropPerNodeFields(tab.fields)
1107
+ })).filter((tab) => tab.fields.length > 0);
1108
+ if (tabs.length > 0) kept.push({
1109
+ ...field,
1110
+ tabs
1111
+ });
1112
+ continue;
1113
+ }
1114
+ if ("perNode" in field && field.perNode === true) continue;
1115
+ kept.push(field);
1116
+ }
1117
+ return kept;
1118
+ }
1001
1119
  function collectPerNodeFieldKeys(fields) {
1002
1120
  const collected = [];
1003
1121
  for (const field of fields) {
@@ -685,6 +685,40 @@ var BaseAddon = class {
685
685
  deviceSettingsSchema() {
686
686
  return null;
687
687
  }
688
+ /**
689
+ * INTEGRATION-LEVEL SETTINGS — declare which of this addon's global sections
690
+ * ARE the configuration of its integration.
691
+ *
692
+ * Return the `ConfigSection.id`s, from {@link globalSettingsSchema}, that an
693
+ * operator should find on the addon's integration page (System →
694
+ * Integrations → <name>) rather than only in the cluster-wide list of every
695
+ * addon. Empty (the default) means the addon has no integration-level
696
+ * settings and no such surface is offered — this is opt-in, because whether
697
+ * an addon's configuration IS its integration's configuration depends on the
698
+ * nature of the integration.
699
+ *
700
+ * WHAT THIS IS NOT. It is not a scope. The selected sections keep living in
701
+ * the ONE global schema, in the ONE addon store, written by the ONE
702
+ * `updateGlobalSettings` path. There is deliberately no
703
+ * `updateIntegrationSettings`: a second write path is how a surface acquires
704
+ * a second store key, and this repo has shipped that twice (`btmPath@hub`,
705
+ * D266). Selecting sections cannot introduce a key that selecting cannot.
706
+ *
707
+ * WHY IT IS A LIST OF SECTION IDS AND NOT A MARKER ON THE SECTION.
708
+ * `ConfigFieldBase` used to carry `scope?: 'device' | 'global'` and it was
709
+ * removed with the reason recorded at
710
+ * `packages/types/src/interfaces/config-ui.ts:249` — *"a field's scope is
711
+ * determined by WHICH schema it lives in, not by a field-level marker."* A
712
+ * marker sprinkled across sections also has to borrow a field that already
713
+ * means something else; borrowing `section.tab` put the literal word
714
+ * "integration" into an operator-facing tab bar, because `tab` means "how to
715
+ * GROUP this visually" and cannot also mean "where this lives" (D269
716
+ * supersedes D268). One declaration, in one place, next to the schema whose
717
+ * ids it names.
718
+ */
719
+ integrationSettingSections() {
720
+ return [];
721
+ }
688
722
  async getGlobalSettings(overlay, cap, nodeId) {
689
723
  const schema = this.globalSettingsSchema(cap);
690
724
  if (!schema) return { sections: [] };
@@ -695,6 +729,55 @@ var BaseAddon = class {
695
729
  } : projected);
696
730
  }
697
731
  /**
732
+ * The integration-level view of this addon's settings: exactly the sections
733
+ * named by {@link integrationSettingSections}, hydrated from the SAME store
734
+ * `getGlobalSettings` reads, and narrowed to cluster-scoped fields.
735
+ *
736
+ * Returns `null` when the addon declared nothing — an addon that opts out has
737
+ * no integration settings surface at all, rather than an empty one that reads
738
+ * as a failed load.
739
+ *
740
+ * Three properties hold BY CONSTRUCTION, which is why they are here in core
741
+ * and not in whichever UI happens to render this:
742
+ *
743
+ * 1. **One key.** The payload is a SUBSET of the global schema, so a field
744
+ * shown here is the same field, with the same bare key, that the addon's
745
+ * own page shows. There is no integration-specific writer — callers save
746
+ * through `updateGlobalSettings` — so a second store key is unreachable,
747
+ * not merely discouraged.
748
+ * 2. **No node scope.** `perNode: true` fields are DROPPED. Their store key
749
+ * is `<key>@<nodeId>` and an integration is not a node; whichever node
750
+ * such a field silently picked would be a wrong answer for the operator
751
+ * who opened the page (D266).
752
+ * 3. **No silent typo.** A declared id that names no section throws. The
753
+ * alternative — skip it — turns a rename into a surface that quietly
754
+ * empties, which looks exactly like an addon with nothing to configure.
755
+ */
756
+ async getIntegrationSettings(nodeId) {
757
+ const declared = this.integrationSettingSections();
758
+ if (declared.length === 0) return null;
759
+ const schema = this.globalSettingsSchema();
760
+ if (!schema) throw new Error(`${this.constructor.name}: integrationSettingSections() names [${declared.join(", ")}] but globalSettingsSchema() returns null.`);
761
+ const byId = new Map(schema.sections.map((section) => [section.id, section]));
762
+ const sections = [];
763
+ for (const id of declared) {
764
+ const section = byId.get(id);
765
+ if (!section) throw new Error(`${this.constructor.name}: integrationSettingSections() names unknown section "${id}". Known sections: [${[...byId.keys()].join(", ")}].`);
766
+ const fields = dropPerNodeFields(section.fields);
767
+ if (fields.length === 0) continue;
768
+ sections.push({
769
+ ...section,
770
+ fields
771
+ });
772
+ }
773
+ if (sections.length === 0) return null;
774
+ const projected = await this.resolveGlobalStore(nodeId);
775
+ return hydrateSchema({
776
+ ...schema,
777
+ sections
778
+ }, projected);
779
+ }
780
+ /**
698
781
  * The raw addon store PROJECTED onto the target node's bare per-node keys:
699
782
  * every `perNode: true` field carries THAT node's scoped value on its bare
700
783
  * key (absent scoped key ⇒ key absent, so the schema `default` wins — no
@@ -998,6 +1081,41 @@ var BaseAddon = class {
998
1081
  * `hydrateSchema` does. Valueless structural fields (separator/info/…)
999
1082
  * don't declare `perNode` and are excluded by the `in` narrowing.
1000
1083
  */
1084
+ /**
1085
+ * The same fields with every `perNode: true` one removed, recursing into layout
1086
+ * containers exactly as {@link collectPerNodeFieldKeys} does. A container left
1087
+ * with no child is dropped rather than rendered empty.
1088
+ *
1089
+ * Used by `getIntegrationSettings`: an integration is not a node, so a field
1090
+ * whose store key is `<key>@<nodeId>` has no node to belong to there.
1091
+ */
1092
+ function dropPerNodeFields(fields) {
1093
+ const kept = [];
1094
+ for (const field of fields) {
1095
+ if (field.type === "group") {
1096
+ const inner = dropPerNodeFields(field.fields);
1097
+ if (inner.length > 0) kept.push({
1098
+ ...field,
1099
+ fields: inner
1100
+ });
1101
+ continue;
1102
+ }
1103
+ if (field.type === "sub-tabs") {
1104
+ const tabs = field.tabs.map((tab) => ({
1105
+ ...tab,
1106
+ fields: dropPerNodeFields(tab.fields)
1107
+ })).filter((tab) => tab.fields.length > 0);
1108
+ if (tabs.length > 0) kept.push({
1109
+ ...field,
1110
+ tabs
1111
+ });
1112
+ continue;
1113
+ }
1114
+ if ("perNode" in field && field.perNode === true) continue;
1115
+ kept.push(field);
1116
+ }
1117
+ return kept;
1118
+ }
1001
1119
  function collectPerNodeFieldKeys(fields) {
1002
1120
  const collected = [];
1003
1121
  for (const field of fields) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/types",
3
- "version": "1.2.118",
3
+ "version": "1.2.120",
4
4
  "description": "Shared types, interfaces, and model catalogs for the CamStack detection ecosystem",
5
5
  "keywords": [
6
6
  "camstack",