@camstack/addon-remote-storage 1.2.3 → 1.2.5

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.
@@ -1,6 +1,6 @@
1
1
  import * as path from "node:path";
2
2
  import { randomUUID } from "node:crypto";
3
- //#region ../types/dist/event-category-D4HJq7Mw.mjs
3
+ //#region ../types/dist/event-category-BLcNejAE.mjs
4
4
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
5
5
  EventCategory["SystemBoot"] = "system.boot";
6
6
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -150,9 +150,6 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
150
150
  EventCategory["RecordingSegmentWritten"] = "recording.segment.written";
151
151
  EventCategory["RecordingPolicyFallback"] = "recording.policy.fallback";
152
152
  EventCategory["RecordingRetentionCompleted"] = "recording.retention.completed";
153
- /** Runner-sampled scrub thumbnail (~1/5 s/camera). Telemetry (D8): a lost
154
- * thumb is a scrub gap the recorder's keyframe backfill covers. */
155
- EventCategory["RecordingThumbSampled"] = "recording.thumb-sampled";
156
153
  /** Export render progress (0–100). Telemetry (D8): a lost tick is a stale
157
154
  * progress bar the client reconciles via `recordingExport.getExport`. */
158
155
  EventCategory["RecordingExportProgress"] = "recording.export.progress";
@@ -6817,7 +6814,6 @@ object({ deviceId: number() }), object({ deviceId: number() }), object({
6817
6814
  patch: record(string(), unknown())
6818
6815
  }), object({ success: literal(true) });
6819
6816
  object({ deviceId: number() }), unknown().nullable();
6820
- /** Shorthand to define a method schema */
6821
6817
  function method(input, output, options) {
6822
6818
  return {
6823
6819
  input,
@@ -6825,6 +6821,7 @@ function method(input, output, options) {
6825
6821
  kind: options?.kind ?? "query",
6826
6822
  auth: options?.auth ?? "protected",
6827
6823
  ...options?.access !== void 0 ? { access: options.access } : {},
6824
+ ...options?.caller !== void 0 ? { caller: options.caller } : {},
6828
6825
  timeoutMs: options?.timeoutMs
6829
6826
  };
6830
6827
  }
@@ -8178,6 +8175,59 @@ for (const l of AUDIO_MACRO_LABELS) {
8178
8175
  /** The complete taxonomy dictionary, keyed by kind. */
8179
8176
  var EVENT_TAXONOMY = Object.freeze(Object.fromEntries(entries));
8180
8177
  /**
8178
+ * Notification-Center taxonomy — the fixed vocabulary the NC rule editor
8179
+ * offers as pickers instead of free text. Derived (never hand-listed) from the
8180
+ * single `EVENT_TAXONOMY` dictionary so it stays in lockstep with every other
8181
+ * taxonomy surface (timeline, filters, event page).
8182
+ *
8183
+ * Three buckets, mapped onto the rule editor's `stringList` conditions:
8184
+ * - `videoClasses` → detection classes (person / vehicle / animal + subs)
8185
+ * for the `classes` / `classesExclude` conditions.
8186
+ * - `audioKinds` → audio-analyzer sub kinds (`audio-scream`, …) shown in
8187
+ * the same class picker, grouped under an Audio header.
8188
+ * - `labels` → sensor + control taxonomy kinds (doorbell / contact /
8189
+ * lock / …) for the `sensorKinds` device-event condition.
8190
+ *
8191
+ * Each entry carries `parentKind` so the client can group video subs under
8192
+ * their macro and sensor/control kinds under their category. This surface is
8193
+ * served ADDITIVELY on the `nc.getConditionCatalog` bridge response — no cap
8194
+ * method, no codegen — so it ships train-free with an addon deploy.
8195
+ */
8196
+ /** One selectable taxonomy value: a stable kind id + display label + parent. */
8197
+ var NcTaxonomyEntrySchema = object({
8198
+ /** Stable kind id (e.g. 'person', 'car', 'audio-scream', 'doorbell'). */
8199
+ kind: string(),
8200
+ /** English fallback label (the UI translates via the event-kind i18n key). */
8201
+ label: string(),
8202
+ /** Macro/category parent for grouping ('car' → 'vehicle'); null for a top. */
8203
+ parentKind: string().nullable()
8204
+ });
8205
+ object({
8206
+ videoClasses: array(NcTaxonomyEntrySchema),
8207
+ audioKinds: array(NcTaxonomyEntrySchema),
8208
+ labels: array(NcTaxonomyEntrySchema)
8209
+ });
8210
+ function toEntry(kind, label, parentKind) {
8211
+ return {
8212
+ kind,
8213
+ label,
8214
+ parentKind
8215
+ };
8216
+ }
8217
+ /**
8218
+ * Build the NC taxonomy from `EVENT_TAXONOMY`. Insertion order is preserved
8219
+ * (macros before their subs), which the client relies on for stable grouping.
8220
+ */
8221
+ function buildNcTaxonomy() {
8222
+ const all = Object.values(EVENT_TAXONOMY);
8223
+ return {
8224
+ videoClasses: all.filter((e) => e.category === "detection").map((e) => toEntry(e.kind, e.label, e.parentKind)),
8225
+ audioKinds: all.filter((e) => e.category === "audio" && e.level === "sub").map((e) => toEntry(e.kind, e.label, e.parentKind)),
8226
+ labels: all.filter((e) => e.category === "sensor" || e.category === "control").map((e) => toEntry(e.kind, e.label, e.parentKind))
8227
+ };
8228
+ }
8229
+ Object.freeze(buildNcTaxonomy());
8230
+ /**
8181
8231
  * Error types for the safe expression engine. Two distinct classes so callers
8182
8232
  * can tell a compile-time (grammar) failure from a runtime (evaluation)
8183
8233
  * failure — both are non-fatal to the host: read paths degrade to "skip link".
@@ -10886,6 +10936,22 @@ var CameraMetricsSchema = object({
10886
10936
  ])
10887
10937
  });
10888
10938
  var CameraMetricsWithDeviceIdSchema = CameraMetricsSchema.extend({ deviceId: number() });
10939
+ /**
10940
+ * Reference to the frame's retained NATIVE surface + the parent crop's placement
10941
+ * within the frame, so the executor can re-cut a leaf child ROI at native
10942
+ * resolution on the detail plane. See the `runPipeline` `nativeCropRef` field.
10943
+ */
10944
+ var NativeCropRefSchema = object({
10945
+ /** Handle keying the retained native surface (node-pinned to its owner). */
10946
+ handle: FrameHandleSchema,
10947
+ /** The parent crop's padded/clamped rectangle in FRAME-space pixels. */
10948
+ cropFrameSpace: object({
10949
+ x: number(),
10950
+ y: number(),
10951
+ w: number(),
10952
+ h: number()
10953
+ })
10954
+ });
10889
10955
  var ModelFormatSchema$1 = _enum([
10890
10956
  "onnx",
10891
10957
  "coreml",
@@ -11161,7 +11227,22 @@ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngi
11161
11227
  * Omitted ⇒ the runner's default device (current single-engine
11162
11228
  * behaviour). Selects WHICH device pool of the node runs the call.
11163
11229
  */
11164
- deviceKey: string().optional()
11230
+ deviceKey: string().optional(),
11231
+ /**
11232
+ * Two-plane NATIVE child-crop reference. Set by `runDetailSubtree` ONLY
11233
+ * when the parent crop was resolved from the frame's retained NATIVE
11234
+ * surface (a frameHandle HIT). Lets the executor re-cut a LEAF crop
11235
+ * child's ROI (plate-ocr, face-embedding, leaf classifiers) at native
11236
+ * resolution from that surface — the SAME quality path faces already
11237
+ * had — instead of the downscaled parent tile. `handle` keys the native
11238
+ * surface (node-pinned to its owner); `cropFrameSpace` is the parent
11239
+ * crop's padded/clamped rectangle in FRAME-space pixels, used to compose
11240
+ * the executor's crop-normalized child ROI back into frame-normalized
11241
+ * coordinates. Auxiliary to the image source (`image`/`frame`/…), NOT one
11242
+ * of the mutually-exclusive image inputs. Absent ⇒ tile-crop children
11243
+ * (today's behaviour on the fallback path).
11244
+ */
11245
+ nativeCropRef: NativeCropRefSchema.optional()
11165
11246
  }), PipelineRunResultBridge, { kind: "mutation" }), method(object({
11166
11247
  engine: PipelineEngineChoiceSchema.optional(),
11167
11248
  steps: array(PipelineStepInputSchema).min(1),
@@ -11377,7 +11458,11 @@ var DetailResultSchema = object({
11377
11458
  bbox: NativeCropBboxSchema.optional(),
11378
11459
  embedding: string().optional(),
11379
11460
  label: string().optional(),
11380
- alignedCropJpeg: string().optional()
11461
+ alignedCropJpeg: string().optional(),
11462
+ /** Face short side (px) measured on the NATIVE crop surface. The `bbox`
11463
+ * above is detection-frame px (≈6× smaller on a 4K camera) — min-face-size
11464
+ * consumers MUST prefer this when present (2026-07-22 native-gate fix). */
11465
+ nativeFaceShortSidePx: number().optional()
11381
11466
  });
11382
11467
  /**
11383
11468
  * Per-camera tunable ranges + defaults. Single source of truth used
@@ -11391,6 +11476,12 @@ var motionCooldownMsField = {
11391
11476
  default: 3e4,
11392
11477
  step: 500
11393
11478
  };
11479
+ var maxSessionHoldMsField = {
11480
+ min: 0,
11481
+ max: 6e5,
11482
+ default: 12e4,
11483
+ step: 5e3
11484
+ };
11394
11485
  var motionFpsField = {
11395
11486
  min: 1,
11396
11487
  max: 30,
@@ -11538,6 +11629,19 @@ var RunnerCameraConfigSchema = object({
11538
11629
  "on-motion"
11539
11630
  ]).default("always-on"),
11540
11631
  motionCooldownMs: number().min(motionCooldownMsField.min).default(motionCooldownMsField.default),
11632
+ /**
11633
+ * Orchestrator-side on-motion session-hold cap (ms). While an on-motion
11634
+ * detection session is active and ≥1 confirmed non-stationary track is
11635
+ * still live, the orchestrator keeps the session open past
11636
+ * `motionCooldownMs` (a slowly-moving subject can stop re-triggering the
11637
+ * camera's VMD yet is still being tracked frame-to-frame) — up to this many
11638
+ * ms since the session opened, after which it closes regardless. `0`
11639
+ * disables the hold (legacy cooldown-only teardown). Not consumed by the
11640
+ * runner itself — carried here so it shares the per-camera device-settings
11641
+ * surface with `motionCooldownMs`; the orchestrator reads it off the
11642
+ * resolved `CameraDetectionConfig`.
11643
+ */
11644
+ maxSessionHoldMs: number().min(maxSessionHoldMsField.min).max(maxSessionHoldMsField.max).optional(),
11541
11645
  motionFps: number().min(motionFpsField.min).max(motionFpsField.max).default(motionFpsField.default),
11542
11646
  detectionFps: number().min(detectionFpsField.min).max(detectionFpsField.max).default(detectionFpsField.default),
11543
11647
  motionStreamId: string(),
@@ -11627,7 +11731,7 @@ var RunnerCameraConfigSchema = object({
11627
11731
  */
11628
11732
  inferenceDevices: array(RunnerInferenceDeviceSchema).readonly().optional()
11629
11733
  });
11630
- motionFpsField.min, motionFpsField.max, motionFpsField.step, motionFpsField.default, detectionFpsField.min, detectionFpsField.max, detectionFpsField.step, detectionFpsField.default, motionCooldownMsField.min, motionCooldownMsField.max, motionCooldownMsField.step, motionCooldownMsField.default, occupancyRecheckSecField.min, occupancyRecheckSecField.max, occupancyRecheckSecField.step, occupancyRecheckSecField.default, occupancyRecheckFramesField.min, occupancyRecheckFramesField.max, occupancyRecheckFramesField.step, occupancyRecheckFramesField.default;
11734
+ motionFpsField.min, motionFpsField.max, motionFpsField.step, motionFpsField.default, detectionFpsField.min, detectionFpsField.max, detectionFpsField.step, detectionFpsField.default, motionCooldownMsField.min, motionCooldownMsField.max, motionCooldownMsField.step, motionCooldownMsField.default, maxSessionHoldMsField.min, maxSessionHoldMsField.max, maxSessionHoldMsField.step, maxSessionHoldMsField.default, occupancyRecheckSecField.min, occupancyRecheckSecField.max, occupancyRecheckSecField.step, occupancyRecheckSecField.default, occupancyRecheckFramesField.min, occupancyRecheckFramesField.max, occupancyRecheckFramesField.step, occupancyRecheckFramesField.default;
11631
11735
  /**
11632
11736
  * Runtime load summary returned by `getLocalLoad`. Used by the orchestrator's
11633
11737
  * load-balancing levels (L2 capacity-based, L3 hardware-aware) to decide
@@ -13481,94 +13585,6 @@ var EnrichedWidgetMetadataSchema = WidgetMetadataSchema.extend({
13481
13585
  bundleUrl: string()
13482
13586
  });
13483
13587
  method(_void(), array(EnrichedWidgetMetadataSchema).readonly());
13484
- var NotificationRuleConditionsSchema = object({
13485
- deviceIds: array(number()).readonly().optional(),
13486
- classNames: array(string()).readonly().optional(),
13487
- zoneIds: array(string()).readonly().optional(),
13488
- minConfidence: number().optional(),
13489
- source: _enum([
13490
- "pipeline",
13491
- "onboard",
13492
- "any"
13493
- ]).optional(),
13494
- schedule: object({
13495
- days: array(number()).readonly(),
13496
- startHour: number(),
13497
- endHour: number()
13498
- }).optional(),
13499
- cooldownSeconds: number().optional(),
13500
- minDwellSeconds: number().optional(),
13501
- /** Match against `event.data.eventType` token (e.g. `'press_long'`). When non-empty, only events
13502
- * carrying a matching `data.eventType` string pass this condition. Rules without this field are
13503
- * unaffected (back-compat). Distinct from `rule.eventTypes` which holds EventCategory strings. */
13504
- eventTypeTokens: array(string()).readonly().optional(),
13505
- /** Match detections whose CLIP image embedding is semantically similar to this free-text
13506
- * description. Requires the embedding-encoder cap to have pre-warmed the text vector.
13507
- * `minSimilarity` is the cosine similarity threshold in [0, 1]. */
13508
- clipDescription: object({
13509
- text: string().min(1),
13510
- minSimilarity: number().min(0).max(1)
13511
- }).optional(),
13512
- /** Match events whose recognized-entity label (face identity name or plate
13513
- * vehicle name, propagated onto `event.data.label`) is one of these values.
13514
- * Empty/absent → unaffected (back-compat). Enables "notify me when <named
13515
- * vehicle/person> is seen". */
13516
- labels: array(string()).readonly().optional()
13517
- });
13518
- var NotificationRuleTemplateSchema = object({
13519
- title: string(),
13520
- body: string(),
13521
- imageMode: _enum([
13522
- "crop",
13523
- "annotated",
13524
- "full",
13525
- "none"
13526
- ])
13527
- });
13528
- var NotificationRuleSchema = object({
13529
- id: string(),
13530
- name: string(),
13531
- enabled: boolean(),
13532
- eventTypes: array(string()).readonly(),
13533
- conditions: NotificationRuleConditionsSchema,
13534
- outputs: array(string()).readonly(),
13535
- template: NotificationRuleTemplateSchema.optional(),
13536
- priority: _enum([
13537
- "low",
13538
- "normal",
13539
- "high",
13540
- "critical"
13541
- ])
13542
- });
13543
- var NotificationTestResultSchema = object({
13544
- ruleId: string(),
13545
- eventId: string(),
13546
- timestamp: number(),
13547
- wouldFire: boolean(),
13548
- reason: string().optional()
13549
- });
13550
- var NotificationHistoryEntrySchema = object({
13551
- id: string(),
13552
- ruleId: string(),
13553
- ruleName: string(),
13554
- eventId: string(),
13555
- timestamp: number(),
13556
- outputs: array(string()).readonly(),
13557
- success: boolean(),
13558
- error: string().optional(),
13559
- deviceId: number().optional()
13560
- });
13561
- var NotificationHistoryFilterSchema = object({
13562
- ruleId: string().optional(),
13563
- deviceId: number().optional(),
13564
- from: number().optional(),
13565
- to: number().optional(),
13566
- limit: number().optional()
13567
- });
13568
- method(_void(), object({ rules: array(NotificationRuleSchema).readonly() })), method(object({ rule: NotificationRuleSchema }), object({ success: literal(true) }), { kind: "mutation" }), method(object({ ruleId: string() }), object({ success: literal(true) }), { kind: "mutation" }), method(object({
13569
- ruleId: string(),
13570
- lookbackMinutes: number()
13571
- }), object({ results: array(NotificationTestResultSchema).readonly() }), { kind: "mutation" }), method(object({ filter: NotificationHistoryFilterSchema.optional() }), object({ entries: array(NotificationHistoryEntrySchema).readonly() }));
13572
13588
  /**
13573
13589
  * Alerts capability — collection-based internal alert system.
13574
13590
  *
@@ -13755,89 +13771,6 @@ method(object({
13755
13771
  password: string()
13756
13772
  }), AuthResultSchema.nullable(), { kind: "mutation" }), method(object({ state: string() }), string()), method(record(string(), string()), AuthResultSchema, { kind: "mutation" }), method(object({ token: string() }), AuthResultSchema.nullable());
13757
13773
  /**
13758
- * `login-method` — collection cap through which auth addons contribute
13759
- * their pre-auth login surfaces to the login page. This is the SINGLE,
13760
- * generic mechanism that supersedes the dead `auth.listProviders` reader:
13761
- * every auth addon (OIDC, magic-link, WebAuthn/passkey) registers a
13762
- * `login-method` provider and the PUBLIC `auth.listLoginMethods`
13763
- * procedure aggregates them for the unauthenticated login page.
13764
- *
13765
- * A contribution is a discriminated union on `kind`:
13766
- *
13767
- * - `redirect` — a declarative button. The login page renders a generic
13768
- * button that navigates to `startUrl` (an addon-owned HTTP route).
13769
- * Covers OIDC (`/addon/auth-oidc/<id>/start`) and magic-link with
13770
- * ZERO shell-side JS. A future SSO addon plugs in the same way — the
13771
- * login page needs NO change.
13772
- *
13773
- * - `widget` — a Module-Federation widget the login page mounts (via
13774
- * `loadRemoteBundle`) for an in-page ceremony. `auth.listLoginMethods`
13775
- * stamps a public `bundleUrl` from `addonId` + `bundle`. Generic
13776
- * mechanism kept for future use; no shipped addon uses it on the login
13777
- * page (the passkey ceremony below runs natively in the shell instead).
13778
- *
13779
- * - `passkey` — a declarative WebAuthn ceremony the shell renders
13780
- * natively (`@simplewebauthn/browser` lives in `addon-admin-ui`, not in
13781
- * a remotely-loaded bundle). Carries the addon's effective `rpId` /
13782
- * `origin` (from its `resolveRpID()` / `resolveOrigin()`) so the shell
13783
- * can gate visibility (IP-literal origin, hostname/rpId mismatch) WITHOUT
13784
- * fetching any remote code pre-auth. Contribution stays unconditional —
13785
- * enrollment state is never leaked pre-auth; visibility is a shell
13786
- * decision.
13787
- *
13788
- * Every contribution carries a `stage`:
13789
- * - `primary` — shown on the first credentials screen (OIDC /
13790
- * magic-link buttons; a future usernameless passkey).
13791
- * - `second-factor` — shown AFTER the password leg, gated on the
13792
- * returned `factors` (passkey-as-2FA today).
13793
- *
13794
- * `mount: skip` — the cap is read server-side by the core auth router
13795
- * (`registry.getCollection('login-method')`), never mounted as its own
13796
- * tRPC router.
13797
- */
13798
- /** When a login method renders in the two-phase login flow. */
13799
- var LoginStageEnum = _enum(["primary", "second-factor"]);
13800
- /** One login-method contribution — redirect button, pre-auth widget, or native passkey ceremony. */
13801
- var LoginMethodContributionSchema = discriminatedUnion("kind", [
13802
- object({
13803
- kind: literal("redirect"),
13804
- /** Stable id within the login-method set (e.g. `auth-oidc/google`). */
13805
- id: string(),
13806
- /** Operator-facing button label. */
13807
- label: string(),
13808
- /** lucide-react icon name. */
13809
- icon: string().optional(),
13810
- /** Addon-owned HTTP route the button navigates to (GET). */
13811
- startUrl: string(),
13812
- stage: LoginStageEnum
13813
- }),
13814
- object({
13815
- kind: literal("widget"),
13816
- /** Stable id within the login-method set (e.g. `auth-webauthn/passkey-login`). */
13817
- id: string(),
13818
- /** Owning addon id — drives the public bundle URL + the MF namespace. */
13819
- addonId: string(),
13820
- /** Bundle filename inside the addon's dist dir (`remoteEntry.js`). */
13821
- bundle: string(),
13822
- /** MF remote descriptor — `{ remoteName, exposedModule, componentKey }`. */
13823
- remote: WidgetRemoteSchema,
13824
- stage: LoginStageEnum
13825
- }),
13826
- object({
13827
- kind: literal("passkey"),
13828
- /** Stable id within the login-method set (e.g. `auth-webauthn/passkey-direct-login`). */
13829
- id: string(),
13830
- /** Operator-facing button label. */
13831
- label: string(),
13832
- stage: LoginStageEnum,
13833
- /** Effective WebAuthn RP ID (`resolveRpID()`) — the shell gates visibility on it. */
13834
- rpId: string(),
13835
- /** Effective expected origin (`resolveOrigin()`), null when unconfigured. */
13836
- origin: string().nullable()
13837
- })
13838
- ]);
13839
- method(_void(), array(LoginMethodContributionSchema).readonly());
13840
- /**
13841
13774
  * Orchestrator-side destination metadata. The orchestrator computes
13842
13775
  * `id = <addonId>:<subId>` from its provider lookup so consumers
13843
13776
  * (admin UI, restore flow) see one canonical key.
@@ -15181,236 +15114,611 @@ method(_void(), array(string()).readonly(), { auth: "admin" }), method(object({
15181
15114
  kind: "mutation",
15182
15115
  auth: "admin"
15183
15116
  });
15184
- var LogLevelSchema = _enum([
15185
- "debug",
15186
- "info",
15187
- "warn",
15188
- "error"
15117
+ /**
15118
+ * Shared LLM generate contracts — imported by BOTH `llm.cap.ts` (consumer
15119
+ * surface) and `llm-runtime.cap.ts` (node-side managed executor) so the two
15120
+ * caps stay wire-compatible without a circular cap→cap import.
15121
+ *
15122
+ * Errors are a discriminated-union RESULT, never thrown: the shape survives
15123
+ * every transport tier structurally, and failed calls still write usage rows.
15124
+ * Token counts only in v1 — no costUsd (operator decision, 2026-07-15).
15125
+ */
15126
+ var LlmUsageSchema = object({
15127
+ inputTokens: number(),
15128
+ outputTokens: number()
15129
+ });
15130
+ var LlmErrorCodeSchema = _enum([
15131
+ "timeout",
15132
+ "rate-limited",
15133
+ "auth",
15134
+ "refusal",
15135
+ "bad-request",
15136
+ "unavailable",
15137
+ "no-profile",
15138
+ "budget-exceeded",
15139
+ "adapter-error"
15189
15140
  ]);
15190
- var LogEntrySchema = object({
15191
- timestamp: date(),
15192
- level: LogLevelSchema,
15193
- scope: array(string()),
15141
+ var LlmGenerateResultSchema = discriminatedUnion("ok", [object({
15142
+ ok: literal(true),
15143
+ text: string(),
15144
+ model: string(),
15145
+ usage: LlmUsageSchema,
15146
+ truncated: boolean(),
15147
+ latencyMs: number()
15148
+ }), object({
15149
+ ok: literal(false),
15150
+ code: LlmErrorCodeSchema,
15194
15151
  message: string(),
15195
- meta: record(string(), unknown()).optional(),
15196
- tags: record(string(), string()).optional()
15152
+ retryAfterMs: number().optional()
15153
+ })]);
15154
+ /**
15155
+ * `Uint8Array` is the sanctioned binary convention — superjson + the UDS
15156
+ * MsgPack channel round-trip typed arrays (embedding-encoder.cap.ts:29,
15157
+ * notification-output.cap.ts:27-31 precedents).
15158
+ */
15159
+ var LlmImageSchema = object({
15160
+ bytes: _instanceof(Uint8Array),
15161
+ mimeType: string()
15197
15162
  });
15198
- method(LogEntrySchema, _void(), { kind: "mutation" }), method(object({
15199
- scope: array(string()).optional(),
15200
- level: LogLevelSchema.optional(),
15201
- since: date().optional(),
15202
- until: date().optional(),
15203
- limit: number().optional(),
15204
- tags: record(string(), string()).optional()
15205
- }), array(LogEntrySchema).readonly());
15206
- var CpuBreakdownSchema = object({
15207
- total: number(),
15208
- user: number(),
15209
- system: number(),
15210
- irq: number(),
15211
- nice: number(),
15212
- loadAvg: tuple([
15213
- number(),
15214
- number(),
15215
- number()
15216
- ]),
15217
- cores: number()
15163
+ var LlmGenerateBaseInputSchema = object({
15164
+ /** Collection routing (the notification-output posture). */
15165
+ addonId: string().optional(),
15166
+ /** Explicit profile; else the resolution chain (spec §3). */
15167
+ profileId: string().optional(),
15168
+ /** MANDATORY usage tag: 'ai-summary', 'notifier-rules', 'adhoc-ui', … */
15169
+ consumer: string(),
15170
+ system: string().optional(),
15171
+ /** v1: single-turn. `messages[]` is a v2 additive field. */
15172
+ prompt: string(),
15173
+ /** Structured output — adapter-mapped (response_format / forced tool / responseSchema). */
15174
+ jsonSchema: record(string(), unknown()).optional(),
15175
+ /** Per-call override of the profile default. */
15176
+ maxTokens: number().int().positive().optional(),
15177
+ temperature: number().optional()
15218
15178
  });
15219
- var MemoryInfoSchema = object({
15220
- percent: number(),
15221
- totalBytes: number(),
15222
- usedBytes: number(),
15223
- availableBytes: number(),
15224
- swapUsedBytes: number(),
15225
- swapTotalBytes: number()
15226
- });
15227
- var DiskIoSnapshotSchema = object({
15228
- readBytes: number(),
15229
- writeBytes: number(),
15230
- readOps: number(),
15231
- writeOps: number(),
15232
- timestampMs: number()
15233
- });
15234
- var NetworkIoSnapshotSchema = object({
15235
- rxBytes: number(),
15236
- txBytes: number(),
15237
- rxPackets: number(),
15238
- txPackets: number(),
15239
- rxErrors: number(),
15240
- txErrors: number(),
15241
- timestampMs: number()
15242
- });
15243
- var MetricsGpuInfoSchema = object({
15244
- utilization: number(),
15245
- model: string(),
15246
- memoryUsedBytes: number(),
15247
- memoryTotalBytes: number(),
15248
- temperature: number().nullable()
15249
- });
15250
- var ProcessResourceInfoSchema = object({
15251
- openFds: number(),
15252
- threadCount: number(),
15253
- activeHandles: number(),
15254
- activeRequests: number()
15255
- });
15256
- var PressureAvgsSchema = object({
15257
- avg10: number(),
15258
- avg60: number(),
15259
- avg300: number()
15260
- });
15261
- var PressureInfoSchema = object({
15262
- some: PressureAvgsSchema,
15263
- full: PressureAvgsSchema.nullable()
15264
- });
15265
- var SystemResourceSnapshotSchema = object({
15266
- cpu: CpuBreakdownSchema,
15267
- memory: MemoryInfoSchema,
15268
- gpu: MetricsGpuInfoSchema.nullable(),
15269
- network: NetworkIoSnapshotSchema,
15270
- disk: DiskIoSnapshotSchema,
15271
- pressure: object({
15272
- cpu: PressureInfoSchema.nullable(),
15273
- memory: PressureInfoSchema.nullable(),
15274
- io: PressureInfoSchema.nullable()
15179
+ /**
15180
+ * `llm-runtime` — node-side managed llama.cpp executor (spec §4). Registered
15181
+ * on EVERY node where `addon-ai` is installed; the hub `llm` provider reaches
15182
+ * a specific node's runtime with `nodePin(profile.runtime.nodeId)` — normal
15183
+ * cap routing, zero bespoke plumbing. `internal: true`: the operator reaches
15184
+ * this only through the `llm` cap's methods.
15185
+ *
15186
+ * One running llama-server child per node in v1 (models are RAM-heavy).
15187
+ * Resource ceiling = llama-server flags + idleStopMinutes ONLY (no RSS
15188
+ * watchdog — operator decision #3).
15189
+ */
15190
+ var ManagedModelRefSchema = discriminatedUnion("kind", [
15191
+ object({
15192
+ kind: literal("catalog"),
15193
+ catalogId: string()
15275
15194
  }),
15276
- process: ProcessResourceInfoSchema,
15277
- cpuTemperature: number().nullable(),
15278
- timestampMs: number()
15279
- });
15280
- var DiskSpaceInfoSchema = object({
15281
- path: string(),
15282
- totalBytes: number(),
15283
- usedBytes: number(),
15284
- availableBytes: number(),
15285
- percent: number()
15286
- });
15287
- var PidResourceStatsSchema = object({
15288
- pid: number(),
15289
- cpu: number(),
15290
- memory: number(),
15291
- /**
15292
- * Private (anonymous) resident bytes — the per-process V8 heap + native
15293
- * allocations NOT shared with other processes (Linux RssAnon). This is the
15294
- * "real" per-runner cost; summing it across runners is meaningful, unlike
15295
- * `memory` (RSS), which double-counts the shared mmap'd framework code.
15296
- * Undefined where /proc is unavailable (e.g. macOS).
15297
- */
15298
- privateBytes: number().optional(),
15299
- /**
15300
- * Shared file-backed resident bytes (Linux RssFile) — mmap'd framework/lib
15301
- * code shared copy-on-write across runners. Undefined on macOS.
15302
- */
15303
- sharedBytes: number().optional()
15195
+ object({
15196
+ kind: literal("url"),
15197
+ url: string(),
15198
+ sha256: string().optional()
15199
+ }),
15200
+ object({
15201
+ kind: literal("path"),
15202
+ path: string()
15203
+ })
15204
+ ]);
15205
+ var ManagedRuntimeConfigSchema = object({
15206
+ /** WHERE the runtime lives — hub or any agent. */
15207
+ nodeId: string(),
15208
+ /** Closed for v1; 'ollama' is a v2 candidate. */
15209
+ engine: _enum(["llama-cpp"]),
15210
+ model: ManagedModelRefSchema,
15211
+ contextSize: number().int().default(4096),
15212
+ /** 0 = CPU-only. */
15213
+ gpuLayers: number().int().default(0),
15214
+ /** Default: cpus-2, clamped ≥1 (resolved node-side). */
15215
+ threads: number().int().optional(),
15216
+ /** Concurrent slots. */
15217
+ parallel: number().int().default(1),
15218
+ /** Else lazy: first generate boots it. */
15219
+ autoStart: boolean().default(false),
15220
+ /** 0 = never; frees RAM after quiet periods. */
15221
+ idleStopMinutes: number().int().default(30)
15304
15222
  });
15305
- var AddonInstanceSchema = object({
15306
- addonId: string(),
15223
+ var LlmRuntimeStatusSchema = object({
15224
+ /** Status is ALWAYS node-qualified. */
15307
15225
  nodeId: string(),
15308
- role: _enum(["hub", "worker"]),
15309
- pid: number(),
15310
15226
  state: _enum([
15311
- "starting",
15312
- "running",
15313
- "stopping",
15314
15227
  "stopped",
15315
- "crashed"
15316
- ]),
15317
- uptimeSec: number()
15318
- });
15319
- var NodeProcessSchema = object({
15320
- pid: number(),
15321
- ppid: number(),
15322
- pgid: number(),
15323
- classification: _enum([
15324
- "root",
15325
- "managed",
15326
- "system",
15327
- "ghost"
15228
+ "downloading",
15229
+ "starting",
15230
+ "ready",
15231
+ "crashed",
15232
+ "failed"
15328
15233
  ]),
15329
- /** `$process` addon binding when `managed`, else null. */
15330
- addonId: string().nullable(),
15331
- /** Kernel-reported nodeId when the process is a known agent/worker. */
15332
- nodeId: string().nullable(),
15333
- /** Truncated command line. */
15334
- command: string(),
15335
- cpuPercent: number(),
15336
- memoryRssBytes: number(),
15337
- /** Wall-clock uptime (seconds). Parsed from `ps etime`. */
15338
- uptimeSec: number(),
15339
- /** True when ancestor walk reaches `ppid=1` (reparented to init/launchd). */
15340
- orphaned: boolean()
15341
- });
15342
- var KillProcessInputSchema = object({
15343
- pid: number(),
15344
- /** Force = SIGKILL. Default is SIGTERM. */
15345
- force: boolean().optional()
15346
- });
15347
- var KillProcessResultSchema = object({
15348
- success: boolean(),
15349
- reason: string().optional(),
15350
- signal: _enum(["SIGTERM", "SIGKILL"]).optional()
15351
- });
15352
- var DumpHeapSnapshotInputSchema = object({
15353
- /** The addon whose runner should dump a heap snapshot. */
15354
- addonId: string() });
15355
- var DumpHeapSnapshotResultSchema = object({
15356
- success: boolean(),
15357
- /** Path of the written .heapsnapshot inside the runner's container/host. */
15358
- path: string().optional(),
15359
- /** Process pid that was signalled. */
15360
15234
  pid: number().optional(),
15361
- reason: string().optional()
15235
+ port: number().optional(),
15236
+ modelPath: string().optional(),
15237
+ modelId: string().optional(),
15238
+ downloadProgress: number().min(0).max(1).optional(),
15239
+ lastError: string().optional(),
15240
+ crashesInWindow: number(),
15241
+ /** Child RSS (sampled best-effort). */
15242
+ memoryBytes: number().optional(),
15243
+ vramBytes: number().optional()
15362
15244
  });
15363
- var SystemMetricsSchema = object({
15364
- cpuPercent: number(),
15365
- memoryPercent: number(),
15366
- memoryUsedMB: number(),
15367
- memoryTotalMB: number(),
15368
- diskPercent: number().optional(),
15369
- temperature: number().optional(),
15370
- gpuPercent: number().optional(),
15371
- gpuMemoryPercent: number().optional()
15245
+ var LlmNodeModelSchema = object({
15246
+ file: string(),
15247
+ sizeBytes: number(),
15248
+ catalogId: string().optional(),
15249
+ installedAt: number().optional()
15372
15250
  });
15373
- method(_void(), SystemResourceSnapshotSchema), method(_void(), SystemResourceSnapshotSchema.nullable()), method(_void(), SystemMetricsSchema), method(object({ dirPath: string() }), DiskSpaceInfoSchema), method(_void(), MetricsGpuInfoSchema.nullable()), method(_void(), number().nullable()), method(object({ pids: array(number()) }), array(PidResourceStatsSchema)), method(_void(), array(AddonInstanceSchema).readonly()), method(object({ addonId: string() }), PidResourceStatsSchema.nullable()), method(_void(), array(NodeProcessSchema).readonly()), method(KillProcessInputSchema, KillProcessResultSchema, {
15251
+ var LlmRuntimeDiskUsageSchema = object({
15252
+ nodeId: string(),
15253
+ modelsBytes: number(),
15254
+ freeBytes: number().optional()
15255
+ });
15256
+ method(LlmGenerateBaseInputSchema.extend({
15257
+ images: array(LlmImageSchema).optional(),
15258
+ runtime: ManagedRuntimeConfigSchema,
15259
+ /** The managed profile's timeout, threaded by the hub provider. */
15260
+ timeoutMs: number().int().positive().optional()
15261
+ }), LlmGenerateResultSchema, { kind: "mutation" }), method(object({ runtime: ManagedRuntimeConfigSchema }), LlmRuntimeStatusSchema, {
15374
15262
  kind: "mutation",
15375
15263
  auth: "admin"
15376
- }), method(DumpHeapSnapshotInputSchema, DumpHeapSnapshotResultSchema, {
15264
+ }), method(object({}), _void(), {
15377
15265
  kind: "mutation",
15378
15266
  auth: "admin"
15379
- });
15380
- method(object({
15381
- sourceUrl: string(),
15382
- metadata: ModelConvertMetadataSchema,
15383
- targets: array(ConvertTargetSchema).min(1).readonly(),
15384
- calibrationRef: string().optional(),
15385
- sessionId: string().optional()
15386
- }), ConvertResultSchema, {
15267
+ }), method(object({}), LlmRuntimeStatusSchema), method(object({ model: ManagedModelRefSchema }), _void(), {
15387
15268
  kind: "mutation",
15388
- auth: "admin",
15389
- timeoutMs: 6e5
15390
- });
15391
- method(object({
15392
- nodeId: string(),
15393
- modelId: string(),
15394
- format: _enum(MODEL_FORMATS),
15395
- entry: ModelCatalogEntrySchema
15396
- }), object({
15397
- ok: boolean(),
15398
- /** sha256 of the staged tarball (empty for a hub-local no-op). */
15399
- sha256: string(),
15400
- bytes: number(),
15401
- /** The target node's modelsDir the artifact landed in. */
15402
- path: string()
15403
- }), {
15269
+ auth: "admin"
15270
+ }), method(object({ file: string() }), _void(), {
15404
15271
  kind: "mutation",
15405
15272
  auth: "admin"
15406
- });
15273
+ }), method(object({}), array(LlmNodeModelSchema)), method(object({}), LlmRuntimeDiskUsageSchema);
15407
15274
  /**
15408
- * `mqtt-broker` — broker-registry cap.
15409
- *
15410
- * NOT a pub/sub proxy. The cap exposes (a) a registry of configured
15411
- * MQTT brokers (external + optionally an embedded `aedes`-backed one)
15412
- * and (b) the connection details a consumer addon needs to spin up
15413
- * its OWN `mqtt.js` client.
15275
+ * `llm` — consumer-facing LLM surface (spec §1-§3). Collection-mode: array
15276
+ * methods concat-fan across providers; single-row methods route to ONE
15277
+ * provider by the `addonId` in the call input (the notification-output
15278
+ * posture, notification-output.cap.ts:215-250). Provided by `addon-ai`
15279
+ * (hub-placed); the cap stays open for future providers.
15280
+ *
15281
+ * Profiles are ROWS (data), not addons: one row = one usable model endpoint.
15282
+ * `apiKey` is a password field — providers REDACT it on read and merge on
15283
+ * write; a stored key NEVER round-trips to a client.
15284
+ */
15285
+ var LlmProfileKindSchema = _enum([
15286
+ "openai-compatible",
15287
+ "openai",
15288
+ "anthropic",
15289
+ "google",
15290
+ "managed-local"
15291
+ ]);
15292
+ var LlmProfileSchema = object({
15293
+ id: string(),
15294
+ name: string(),
15295
+ kind: LlmProfileKindSchema,
15296
+ /** Stamped by the provider — keeps the fanned catalog routable. */
15297
+ addonId: string(),
15298
+ enabled: boolean(),
15299
+ /** Vendor model id, or the managed runtime's loaded model. */
15300
+ model: string(),
15301
+ /** Required for openai-compatible; override for cloud kinds. */
15302
+ baseUrl: string().optional(),
15303
+ /** ConfigUISchema type:'password' — never round-trips (spec §5). */
15304
+ apiKey: string().optional(),
15305
+ supportsVision: boolean(),
15306
+ temperature: number().min(0).max(2).optional(),
15307
+ maxTokens: number().int().positive().optional(),
15308
+ timeoutMs: number().int().positive().default(6e4),
15309
+ extraHeaders: record(string(), string()).optional(),
15310
+ /** kind === 'managed-local' only (spec §4). */
15311
+ runtime: ManagedRuntimeConfigSchema.optional()
15312
+ });
15313
+ /** ConfigUISchema tree passed through untyped on the wire (the
15314
+ * notification-output `ConfigSchemaPassthrough` precedent at
15315
+ * notification-output.cap.ts:151); the exported TS type re-tightens it. */
15316
+ var ConfigSchemaPassthrough$1 = unknown();
15317
+ var LlmProfileKindDescriptorSchema = object({
15318
+ kind: LlmProfileKindSchema,
15319
+ label: string(),
15320
+ icon: string(),
15321
+ /** Stamped by each provider so the concat-fanned catalog stays routable. */
15322
+ addonId: string(),
15323
+ configSchema: ConfigSchemaPassthrough$1
15324
+ });
15325
+ var LlmDefaultSelectorSchema = union([object({ consumer: string() }), object({ purpose: _enum(["text", "vision"]) })]);
15326
+ var LlmDefaultSchema = object({
15327
+ selector: LlmDefaultSelectorSchema,
15328
+ profileId: string()
15329
+ });
15330
+ /** Server-side rollup row — getUsage never dumps raw call rows (spec §6). */
15331
+ var LlmUsageRollupSchema = object({
15332
+ day: string(),
15333
+ consumer: string(),
15334
+ profileId: string(),
15335
+ calls: number(),
15336
+ okCalls: number(),
15337
+ errorCalls: number(),
15338
+ inputTokens: number(),
15339
+ outputTokens: number(),
15340
+ avgLatencyMs: number()
15341
+ });
15342
+ /** LLM-facing view over the reused ModelCatalogEntry mechanism (spec §4.2). */
15343
+ var ManagedModelCatalogEntrySchema = object({
15344
+ id: string(),
15345
+ label: string(),
15346
+ family: string(),
15347
+ purpose: _enum(["text", "vision"]),
15348
+ url: string(),
15349
+ sha256: string(),
15350
+ sizeBytes: number(),
15351
+ quantization: string(),
15352
+ /** Load-time guidance shown in the picker. */
15353
+ minRamBytes: number(),
15354
+ contextSizeDefault: number().int(),
15355
+ /** Vision models: companion projector file. */
15356
+ mmprojUrl: string().optional()
15357
+ });
15358
+ var LlmRuntimeNodeSchema = object({
15359
+ nodeId: string(),
15360
+ reachable: boolean(),
15361
+ status: LlmRuntimeStatusSchema.optional(),
15362
+ disk: LlmRuntimeDiskUsageSchema.optional(),
15363
+ error: string().optional()
15364
+ });
15365
+ var GenerateVisionInputSchema = LlmGenerateBaseInputSchema.extend({ images: array(LlmImageSchema).min(1) });
15366
+ var ProfileRefInputSchema = object({
15367
+ addonId: string(),
15368
+ profileId: string()
15369
+ });
15370
+ method(LlmGenerateBaseInputSchema, LlmGenerateResultSchema, { kind: "mutation" }), method(GenerateVisionInputSchema, LlmGenerateResultSchema, { kind: "mutation" }), method(object({}), array(LlmProfileKindDescriptorSchema)), method(object({}), array(LlmProfileSchema)), method(object({ profile: LlmProfileSchema }), LlmProfileSchema, {
15371
+ kind: "mutation",
15372
+ auth: "admin"
15373
+ }), method(ProfileRefInputSchema, _void(), {
15374
+ kind: "mutation",
15375
+ auth: "admin"
15376
+ }), method(ProfileRefInputSchema, LlmGenerateResultSchema, {
15377
+ kind: "mutation",
15378
+ auth: "admin"
15379
+ }), method(ProfileRefInputSchema, array(string())), method(object({}), array(LlmDefaultSchema)), method(object({
15380
+ selector: LlmDefaultSelectorSchema,
15381
+ profileId: string().nullable()
15382
+ }), _void(), {
15383
+ kind: "mutation",
15384
+ auth: "admin"
15385
+ }), method(object({
15386
+ since: number().optional(),
15387
+ until: number().optional(),
15388
+ consumer: string().optional(),
15389
+ profileId: string().optional()
15390
+ }), array(LlmUsageRollupSchema)), method(object({}), array(ManagedModelCatalogEntrySchema)), method(object({}), array(LlmRuntimeNodeSchema)), method(object({ nodeId: string() }), array(LlmNodeModelSchema)), method(object({
15391
+ nodeId: string(),
15392
+ model: ManagedModelRefSchema
15393
+ }), _void(), {
15394
+ kind: "mutation",
15395
+ auth: "admin"
15396
+ }), method(object({
15397
+ nodeId: string(),
15398
+ file: string()
15399
+ }), _void(), {
15400
+ kind: "mutation",
15401
+ auth: "admin"
15402
+ }), method(ProfileRefInputSchema, LlmRuntimeStatusSchema), method(ProfileRefInputSchema, LlmRuntimeStatusSchema, {
15403
+ kind: "mutation",
15404
+ auth: "admin"
15405
+ }), method(ProfileRefInputSchema, _void(), {
15406
+ kind: "mutation",
15407
+ auth: "admin"
15408
+ });
15409
+ var LogLevelSchema = _enum([
15410
+ "debug",
15411
+ "info",
15412
+ "warn",
15413
+ "error"
15414
+ ]);
15415
+ var LogEntrySchema = object({
15416
+ timestamp: date(),
15417
+ level: LogLevelSchema,
15418
+ scope: array(string()),
15419
+ message: string(),
15420
+ meta: record(string(), unknown()).optional(),
15421
+ tags: record(string(), string()).optional()
15422
+ });
15423
+ method(LogEntrySchema, _void(), { kind: "mutation" }), method(object({
15424
+ scope: array(string()).optional(),
15425
+ level: LogLevelSchema.optional(),
15426
+ since: date().optional(),
15427
+ until: date().optional(),
15428
+ limit: number().optional(),
15429
+ tags: record(string(), string()).optional()
15430
+ }), array(LogEntrySchema).readonly());
15431
+ /**
15432
+ * `login-method` — collection cap through which auth addons contribute
15433
+ * their pre-auth login surfaces to the login page. This is the SINGLE,
15434
+ * generic mechanism that supersedes the dead `auth.listProviders` reader:
15435
+ * every auth addon (OIDC, magic-link, WebAuthn/passkey) registers a
15436
+ * `login-method` provider and the PUBLIC `auth.listLoginMethods`
15437
+ * procedure aggregates them for the unauthenticated login page.
15438
+ *
15439
+ * A contribution is a discriminated union on `kind`:
15440
+ *
15441
+ * - `redirect` — a declarative button. The login page renders a generic
15442
+ * button that navigates to `startUrl` (an addon-owned HTTP route).
15443
+ * Covers OIDC (`/addon/auth-oidc/<id>/start`) and magic-link with
15444
+ * ZERO shell-side JS. A future SSO addon plugs in the same way — the
15445
+ * login page needs NO change.
15446
+ *
15447
+ * - `widget` — a Module-Federation widget the login page mounts (via
15448
+ * `loadRemoteBundle`) for an in-page ceremony. `auth.listLoginMethods`
15449
+ * stamps a public `bundleUrl` from `addonId` + `bundle`. Generic
15450
+ * mechanism kept for future use; no shipped addon uses it on the login
15451
+ * page (the passkey ceremony below runs natively in the shell instead).
15452
+ *
15453
+ * - `passkey` — a declarative WebAuthn ceremony the shell renders
15454
+ * natively (`@simplewebauthn/browser` lives in `addon-admin-ui`, not in
15455
+ * a remotely-loaded bundle). Carries the addon's effective `rpId` /
15456
+ * `origin` (from its `resolveRpID()` / `resolveOrigin()`) so the shell
15457
+ * can gate visibility (IP-literal origin, hostname/rpId mismatch) WITHOUT
15458
+ * fetching any remote code pre-auth. Contribution stays unconditional —
15459
+ * enrollment state is never leaked pre-auth; visibility is a shell
15460
+ * decision.
15461
+ *
15462
+ * Every contribution carries a `stage`:
15463
+ * - `primary` — shown on the first credentials screen (OIDC /
15464
+ * magic-link buttons; a future usernameless passkey).
15465
+ * - `second-factor` — shown AFTER the password leg, gated on the
15466
+ * returned `factors` (passkey-as-2FA today).
15467
+ *
15468
+ * `mount: skip` — the cap is read server-side by the core auth router
15469
+ * (`registry.getCollection('login-method')`), never mounted as its own
15470
+ * tRPC router.
15471
+ */
15472
+ /** When a login method renders in the two-phase login flow. */
15473
+ var LoginStageEnum = _enum(["primary", "second-factor"]);
15474
+ /** One login-method contribution — redirect button, pre-auth widget, or native passkey ceremony. */
15475
+ var LoginMethodContributionSchema = discriminatedUnion("kind", [
15476
+ object({
15477
+ kind: literal("redirect"),
15478
+ /** Stable id within the login-method set (e.g. `auth-oidc/google`). */
15479
+ id: string(),
15480
+ /** Operator-facing button label. */
15481
+ label: string(),
15482
+ /** lucide-react icon name. */
15483
+ icon: string().optional(),
15484
+ /** Addon-owned HTTP route the button navigates to (GET). */
15485
+ startUrl: string(),
15486
+ stage: LoginStageEnum
15487
+ }),
15488
+ object({
15489
+ kind: literal("widget"),
15490
+ /** Stable id within the login-method set (e.g. `auth-webauthn/passkey-login`). */
15491
+ id: string(),
15492
+ /** Owning addon id — drives the public bundle URL + the MF namespace. */
15493
+ addonId: string(),
15494
+ /** Bundle filename inside the addon's dist dir (`remoteEntry.js`). */
15495
+ bundle: string(),
15496
+ /** MF remote descriptor — `{ remoteName, exposedModule, componentKey }`. */
15497
+ remote: WidgetRemoteSchema,
15498
+ stage: LoginStageEnum
15499
+ }),
15500
+ object({
15501
+ kind: literal("passkey"),
15502
+ /** Stable id within the login-method set (e.g. `auth-webauthn/passkey-direct-login`). */
15503
+ id: string(),
15504
+ /** Operator-facing button label. */
15505
+ label: string(),
15506
+ stage: LoginStageEnum,
15507
+ /** Effective WebAuthn RP ID (`resolveRpID()`) — the shell gates visibility on it. */
15508
+ rpId: string(),
15509
+ /** Effective expected origin (`resolveOrigin()`), null when unconfigured. */
15510
+ origin: string().nullable()
15511
+ })
15512
+ ]);
15513
+ method(_void(), array(LoginMethodContributionSchema).readonly());
15514
+ var CpuBreakdownSchema = object({
15515
+ total: number(),
15516
+ user: number(),
15517
+ system: number(),
15518
+ irq: number(),
15519
+ nice: number(),
15520
+ loadAvg: tuple([
15521
+ number(),
15522
+ number(),
15523
+ number()
15524
+ ]),
15525
+ cores: number()
15526
+ });
15527
+ var MemoryInfoSchema = object({
15528
+ percent: number(),
15529
+ totalBytes: number(),
15530
+ usedBytes: number(),
15531
+ availableBytes: number(),
15532
+ swapUsedBytes: number(),
15533
+ swapTotalBytes: number()
15534
+ });
15535
+ var DiskIoSnapshotSchema = object({
15536
+ readBytes: number(),
15537
+ writeBytes: number(),
15538
+ readOps: number(),
15539
+ writeOps: number(),
15540
+ timestampMs: number()
15541
+ });
15542
+ var NetworkIoSnapshotSchema = object({
15543
+ rxBytes: number(),
15544
+ txBytes: number(),
15545
+ rxPackets: number(),
15546
+ txPackets: number(),
15547
+ rxErrors: number(),
15548
+ txErrors: number(),
15549
+ timestampMs: number()
15550
+ });
15551
+ var MetricsGpuInfoSchema = object({
15552
+ utilization: number(),
15553
+ model: string(),
15554
+ memoryUsedBytes: number(),
15555
+ memoryTotalBytes: number(),
15556
+ temperature: number().nullable()
15557
+ });
15558
+ var ProcessResourceInfoSchema = object({
15559
+ openFds: number(),
15560
+ threadCount: number(),
15561
+ activeHandles: number(),
15562
+ activeRequests: number()
15563
+ });
15564
+ var PressureAvgsSchema = object({
15565
+ avg10: number(),
15566
+ avg60: number(),
15567
+ avg300: number()
15568
+ });
15569
+ var PressureInfoSchema = object({
15570
+ some: PressureAvgsSchema,
15571
+ full: PressureAvgsSchema.nullable()
15572
+ });
15573
+ var SystemResourceSnapshotSchema = object({
15574
+ cpu: CpuBreakdownSchema,
15575
+ memory: MemoryInfoSchema,
15576
+ gpu: MetricsGpuInfoSchema.nullable(),
15577
+ network: NetworkIoSnapshotSchema,
15578
+ disk: DiskIoSnapshotSchema,
15579
+ pressure: object({
15580
+ cpu: PressureInfoSchema.nullable(),
15581
+ memory: PressureInfoSchema.nullable(),
15582
+ io: PressureInfoSchema.nullable()
15583
+ }),
15584
+ process: ProcessResourceInfoSchema,
15585
+ cpuTemperature: number().nullable(),
15586
+ timestampMs: number()
15587
+ });
15588
+ var DiskSpaceInfoSchema = object({
15589
+ path: string(),
15590
+ totalBytes: number(),
15591
+ usedBytes: number(),
15592
+ availableBytes: number(),
15593
+ percent: number()
15594
+ });
15595
+ var PidResourceStatsSchema = object({
15596
+ pid: number(),
15597
+ cpu: number(),
15598
+ memory: number(),
15599
+ /**
15600
+ * Private (anonymous) resident bytes — the per-process V8 heap + native
15601
+ * allocations NOT shared with other processes (Linux RssAnon). This is the
15602
+ * "real" per-runner cost; summing it across runners is meaningful, unlike
15603
+ * `memory` (RSS), which double-counts the shared mmap'd framework code.
15604
+ * Undefined where /proc is unavailable (e.g. macOS).
15605
+ */
15606
+ privateBytes: number().optional(),
15607
+ /**
15608
+ * Shared file-backed resident bytes (Linux RssFile) — mmap'd framework/lib
15609
+ * code shared copy-on-write across runners. Undefined on macOS.
15610
+ */
15611
+ sharedBytes: number().optional()
15612
+ });
15613
+ var AddonInstanceSchema = object({
15614
+ addonId: string(),
15615
+ nodeId: string(),
15616
+ role: _enum(["hub", "worker"]),
15617
+ pid: number(),
15618
+ state: _enum([
15619
+ "starting",
15620
+ "running",
15621
+ "stopping",
15622
+ "stopped",
15623
+ "crashed"
15624
+ ]),
15625
+ uptimeSec: number()
15626
+ });
15627
+ var NodeProcessSchema = object({
15628
+ pid: number(),
15629
+ ppid: number(),
15630
+ pgid: number(),
15631
+ classification: _enum([
15632
+ "root",
15633
+ "managed",
15634
+ "system",
15635
+ "ghost"
15636
+ ]),
15637
+ /** `$process` addon binding when `managed`, else null. */
15638
+ addonId: string().nullable(),
15639
+ /** Kernel-reported nodeId when the process is a known agent/worker. */
15640
+ nodeId: string().nullable(),
15641
+ /** Truncated command line. */
15642
+ command: string(),
15643
+ cpuPercent: number(),
15644
+ memoryRssBytes: number(),
15645
+ /** Wall-clock uptime (seconds). Parsed from `ps etime`. */
15646
+ uptimeSec: number(),
15647
+ /** True when ancestor walk reaches `ppid=1` (reparented to init/launchd). */
15648
+ orphaned: boolean()
15649
+ });
15650
+ var KillProcessInputSchema = object({
15651
+ pid: number(),
15652
+ /** Force = SIGKILL. Default is SIGTERM. */
15653
+ force: boolean().optional()
15654
+ });
15655
+ var KillProcessResultSchema = object({
15656
+ success: boolean(),
15657
+ reason: string().optional(),
15658
+ signal: _enum(["SIGTERM", "SIGKILL"]).optional()
15659
+ });
15660
+ var DumpHeapSnapshotInputSchema = object({
15661
+ /** The addon whose runner should dump a heap snapshot. */
15662
+ addonId: string() });
15663
+ var DumpHeapSnapshotResultSchema = object({
15664
+ success: boolean(),
15665
+ /** Path of the written .heapsnapshot inside the runner's container/host. */
15666
+ path: string().optional(),
15667
+ /** Process pid that was signalled. */
15668
+ pid: number().optional(),
15669
+ reason: string().optional()
15670
+ });
15671
+ var SystemMetricsSchema = object({
15672
+ cpuPercent: number(),
15673
+ memoryPercent: number(),
15674
+ memoryUsedMB: number(),
15675
+ memoryTotalMB: number(),
15676
+ diskPercent: number().optional(),
15677
+ temperature: number().optional(),
15678
+ gpuPercent: number().optional(),
15679
+ gpuMemoryPercent: number().optional()
15680
+ });
15681
+ method(_void(), SystemResourceSnapshotSchema), method(_void(), SystemResourceSnapshotSchema.nullable()), method(_void(), SystemMetricsSchema), method(object({ dirPath: string() }), DiskSpaceInfoSchema), method(_void(), MetricsGpuInfoSchema.nullable()), method(_void(), number().nullable()), method(object({ pids: array(number()) }), array(PidResourceStatsSchema)), method(_void(), array(AddonInstanceSchema).readonly()), method(object({ addonId: string() }), PidResourceStatsSchema.nullable()), method(_void(), array(NodeProcessSchema).readonly()), method(KillProcessInputSchema, KillProcessResultSchema, {
15682
+ kind: "mutation",
15683
+ auth: "admin"
15684
+ }), method(DumpHeapSnapshotInputSchema, DumpHeapSnapshotResultSchema, {
15685
+ kind: "mutation",
15686
+ auth: "admin"
15687
+ });
15688
+ method(object({
15689
+ sourceUrl: string(),
15690
+ metadata: ModelConvertMetadataSchema,
15691
+ targets: array(ConvertTargetSchema).min(1).readonly(),
15692
+ calibrationRef: string().optional(),
15693
+ sessionId: string().optional()
15694
+ }), ConvertResultSchema, {
15695
+ kind: "mutation",
15696
+ auth: "admin",
15697
+ timeoutMs: 6e5
15698
+ });
15699
+ method(object({
15700
+ nodeId: string(),
15701
+ modelId: string(),
15702
+ format: _enum(MODEL_FORMATS),
15703
+ entry: ModelCatalogEntrySchema
15704
+ }), object({
15705
+ ok: boolean(),
15706
+ /** sha256 of the staged tarball (empty for a hub-local no-op). */
15707
+ sha256: string(),
15708
+ bytes: number(),
15709
+ /** The target node's modelsDir the artifact landed in. */
15710
+ path: string()
15711
+ }), {
15712
+ kind: "mutation",
15713
+ auth: "admin"
15714
+ });
15715
+ /**
15716
+ * `mqtt-broker` — broker-registry cap.
15717
+ *
15718
+ * NOT a pub/sub proxy. The cap exposes (a) a registry of configured
15719
+ * MQTT brokers (external + optionally an embedded `aedes`-backed one)
15720
+ * and (b) the connection details a consumer addon needs to spin up
15721
+ * its OWN `mqtt.js` client.
15414
15722
  *
15415
15723
  * Why: pub/sub routing over the system event-bus loses fidelity
15416
15724
  * (callback shape, QoS guarantees, will/retain semantics) and adds
@@ -15675,14 +15983,14 @@ var TargetKindCapsSchema = object({
15675
15983
  * the union is large and not meant for runtime validation here; the exported
15676
15984
  * `TargetKind` type re-tightens `configSchema` to `ConfigUISchema`.
15677
15985
  */
15678
- var ConfigSchemaPassthrough$1 = unknown();
15986
+ var ConfigSchemaPassthrough = unknown();
15679
15987
  var TargetKindSchema = object({
15680
15988
  kind: string(),
15681
15989
  label: string(),
15682
15990
  icon: string(),
15683
15991
  /** Stamped by each provider so the concat-fanned catalog stays routable. */
15684
15992
  addonId: string(),
15685
- configSchema: ConfigSchemaPassthrough$1,
15993
+ configSchema: ConfigSchemaPassthrough,
15686
15994
  supportsDiscovery: boolean(),
15687
15995
  caps: TargetKindCapsSchema
15688
15996
  });
@@ -15729,303 +16037,499 @@ method(object({}), array(TargetKindSchema)), method(object({}), array(TargetSche
15729
16037
  notification: NotificationSchema
15730
16038
  }), SendResultSchema, { kind: "mutation" }), method(object({
15731
16039
  targetId: string(),
15732
- sample: NotificationSchema.optional()
15733
- }), TestResultSchema, { kind: "mutation" }), method(object({ target: TargetSchema }), TargetSchema, { kind: "mutation" }), method(object({ targetId: string() }), _void(), { kind: "mutation" }), method(object({
15734
- targetId: string(),
15735
- enabled: boolean()
15736
- }), _void(), { kind: "mutation" });
15737
- /**
15738
- * Shared LLM generate contracts — imported by BOTH `llm.cap.ts` (consumer
15739
- * surface) and `llm-runtime.cap.ts` (node-side managed executor) so the two
15740
- * caps stay wire-compatible without a circular cap→cap import.
15741
- *
15742
- * Errors are a discriminated-union RESULT, never thrown: the shape survives
15743
- * every transport tier structurally, and failed calls still write usage rows.
15744
- * Token counts only in v1 — no costUsd (operator decision, 2026-07-15).
15745
- */
15746
- var LlmUsageSchema = object({
15747
- inputTokens: number(),
15748
- outputTokens: number()
15749
- });
15750
- var LlmErrorCodeSchema = _enum([
15751
- "timeout",
15752
- "rate-limited",
15753
- "auth",
15754
- "refusal",
15755
- "bad-request",
15756
- "unavailable",
15757
- "no-profile",
15758
- "budget-exceeded",
15759
- "adapter-error"
15760
- ]);
15761
- var LlmGenerateResultSchema = discriminatedUnion("ok", [object({
15762
- ok: literal(true),
15763
- text: string(),
15764
- model: string(),
15765
- usage: LlmUsageSchema,
15766
- truncated: boolean(),
15767
- latencyMs: number()
15768
- }), object({
15769
- ok: literal(false),
15770
- code: LlmErrorCodeSchema,
15771
- message: string(),
15772
- retryAfterMs: number().optional()
15773
- })]);
15774
- /**
15775
- * `Uint8Array` is the sanctioned binary convention — superjson + the UDS
15776
- * MsgPack channel round-trip typed arrays (embedding-encoder.cap.ts:29,
15777
- * notification-output.cap.ts:27-31 precedents).
15778
- */
15779
- var LlmImageSchema = object({
15780
- bytes: _instanceof(Uint8Array),
15781
- mimeType: string()
15782
- });
15783
- var LlmGenerateBaseInputSchema = object({
15784
- /** Collection routing (the notification-output posture). */
15785
- addonId: string().optional(),
15786
- /** Explicit profile; else the resolution chain (spec §3). */
15787
- profileId: string().optional(),
15788
- /** MANDATORY usage tag: 'ai-summary', 'notifier-rules', 'adhoc-ui', … */
15789
- consumer: string(),
15790
- system: string().optional(),
15791
- /** v1: single-turn. `messages[]` is a v2 additive field. */
15792
- prompt: string(),
15793
- /** Structured output — adapter-mapped (response_format / forced tool / responseSchema). */
15794
- jsonSchema: record(string(), unknown()).optional(),
15795
- /** Per-call override of the profile default. */
15796
- maxTokens: number().int().positive().optional(),
15797
- temperature: number().optional()
15798
- });
16040
+ sample: NotificationSchema.optional()
16041
+ }), TestResultSchema, { kind: "mutation" }), method(object({ target: TargetSchema }), TargetSchema, { kind: "mutation" }), method(object({ targetId: string() }), _void(), { kind: "mutation" }), method(object({
16042
+ targetId: string(),
16043
+ enabled: boolean()
16044
+ }), _void(), { kind: "mutation" });
15799
16045
  /**
15800
- * `llm-runtime`node-side managed llama.cpp executor (spec §4). Registered
15801
- * on EVERY node where `addon-ai` is installed; the hub `llm` provider reaches
15802
- * a specific node's runtime with `nodePin(profile.runtime.nodeId)` — normal
15803
- * cap routing, zero bespoke plumbing. `internal: true`: the operator reaches
15804
- * this only through the `llm` cap's methods.
16046
+ * notification-rulesthe Notification Center rule surface (P1 core).
15805
16047
  *
15806
- * One running llama-server child per node in v1 (models are RAM-heavy).
15807
- * Resource ceiling = llama-server flags + idleStopMinutes ONLY (no RSS
15808
- * watchdog — operator decision #3).
16048
+ * Spec: `docs/superpowers/specs/2026-07-22-notification-center-requirements.md`
16049
+ * (operator decisions D-1/D-2/D-3 are binding):
16050
+ *
16051
+ * - D-2: rule EVALUATION lives in `addon-post-analysis` (the
16052
+ * `notification-center` module), hooked on the durable persistence
16053
+ * moments (object-event insert, TrackCloser.closeExpired) with a
16054
+ * persisted outbox + retry — never the lossy telemetry bus (D8).
16055
+ * - D-3: urgency belongs to the RULE. `delivery: 'immediate'` fires on the
16056
+ * FIRST persisted detection matching the conditions (per-track dedup,
16057
+ * `maxPerTrack` fixed at 1 — see {@link NC_MAX_PER_TRACK_IMMEDIATE});
16058
+ * `delivery: 'track-end'` evaluates the finalized track record at close.
16059
+ * - DISPATCH stays behind `notification-output` (rules reference targets
16060
+ * by id; per-backend params are a passthrough blob capped by the
16061
+ * target kind's own caps/degrade engine).
16062
+ *
16063
+ * P1 scope: admin-authored rules only (`createdBy` stamped from the
16064
+ * server-injected caller identity — the first `caller: 'required'`
16065
+ * adopter). The P1 condition subset is: devices, classes(+exclude),
16066
+ * minConfidence, admin zones (any/all + exclude), weekly schedule
16067
+ * windows, and the optional label/identity/plate matchers. User rules,
16068
+ * private zones, per-recipient fan-out and the wider condition table are
16069
+ * P2+ (see spec §7).
16070
+ *
16071
+ * All schemas here are the single source of truth — `NcRule` etc. are
16072
+ * `z.infer` exports; no duplicate interfaces (the advanced-notifier
16073
+ * schema/interface drift is explicitly not repeated).
15809
16074
  */
15810
- var ManagedModelRefSchema = discriminatedUnion("kind", [
15811
- object({
15812
- kind: literal("catalog"),
15813
- catalogId: string()
15814
- }),
15815
- object({
15816
- kind: literal("url"),
15817
- url: string(),
15818
- sha256: string().optional()
15819
- }),
15820
- object({
15821
- kind: literal("path"),
15822
- path: string()
15823
- })
16075
+ /**
16076
+ * D-3: the trigger/urgency of a rule — which persistence moment evaluates it.
16077
+ * The value maps 1:1 onto the evaluated record kind:
16078
+ * - `immediate` ↔ object-event persist (lowest-latency detection burst)
16079
+ * - `track-end` ↔ TrackCloser.closeExpired (finalized track record)
16080
+ * - `device-event` ↔ SensorEventStore insert (doorbell press / sensor state
16081
+ * change of a LINKED device, one row per linked camera)
16082
+ * - `package-event` ↔ PackageDropDetector object-event insert (a `package`
16083
+ * delivery / pick-up)
16084
+ *
16085
+ * `immediate`/`track-end` carry the D-3 urgency semantics; `device-event`/
16086
+ * `package-event` are pure trigger kinds (no urgency dimension). Extending
16087
+ * this one field keeps the schema additive — a rule still declares exactly
16088
+ * one trigger.
16089
+ */
16090
+ var NcDeliverySchema = _enum([
16091
+ "immediate",
16092
+ "track-end",
16093
+ "device-event",
16094
+ "package-event"
15824
16095
  ]);
15825
- var ManagedRuntimeConfigSchema = object({
15826
- /** WHERE the runtime lives — hub or any agent. */
15827
- nodeId: string(),
15828
- /** Closed for v1; 'ollama' is a v2 candidate. */
15829
- engine: _enum(["llama-cpp"]),
15830
- model: ManagedModelRefSchema,
15831
- contextSize: number().int().default(4096),
15832
- /** 0 = CPU-only. */
15833
- gpuLayers: number().int().default(0),
15834
- /** Default: cpus-2, clamped ≥1 (resolved node-side). */
15835
- threads: number().int().optional(),
15836
- /** Concurrent slots. */
15837
- parallel: number().int().default(1),
15838
- /** Else lazy: first generate boots it. */
15839
- autoStart: boolean().default(false),
15840
- /** 0 = never; frees RAM after quiet periods. */
15841
- idleStopMinutes: number().int().default(30)
15842
- });
15843
- var LlmRuntimeStatusSchema = object({
15844
- /** Status is ALWAYS node-qualified. */
15845
- nodeId: string(),
15846
- state: _enum([
15847
- "stopped",
15848
- "downloading",
15849
- "starting",
15850
- "ready",
15851
- "crashed",
15852
- "failed"
15853
- ]),
15854
- pid: number().optional(),
15855
- port: number().optional(),
15856
- modelPath: string().optional(),
15857
- modelId: string().optional(),
15858
- downloadProgress: number().min(0).max(1).optional(),
15859
- lastError: string().optional(),
15860
- crashesInWindow: number(),
15861
- /** Child RSS (sampled best-effort). */
15862
- memoryBytes: number().optional(),
15863
- vramBytes: number().optional()
16096
+ /** Weekly schedule — OR of windows; absence on the rule = always active. */
16097
+ var NcScheduleSchema = object({
16098
+ windows: array(object({
16099
+ /** Days of week the window STARTS on (0 = Sunday … 6 = Saturday). */
16100
+ days: array(number().int().min(0).max(6)).min(1),
16101
+ startMinute: number().int().min(0).max(1439),
16102
+ endMinute: number().int().min(0).max(1439)
16103
+ })).min(1),
16104
+ /** IANA timezone; default = hub host timezone. */
16105
+ timezone: string().optional(),
16106
+ /** Active OUTSIDE the windows (e.g. "only outside business hours"). */
16107
+ invert: boolean().optional()
15864
16108
  });
15865
- var LlmNodeModelSchema = object({
15866
- file: string(),
15867
- sizeBytes: number(),
15868
- catalogId: string().optional(),
15869
- installedAt: number().optional()
16109
+ /** Fuzzy plate matcher — OCR noise makes exact match useless (spec row 12/13). */
16110
+ var NcPlateMatcherSchema = object({
16111
+ values: array(string().min(1)).min(1),
16112
+ /** Max Levenshtein distance after normalization (uppercase alphanumeric). */
16113
+ maxDistance: number().int().min(0).max(3).default(1)
15870
16114
  });
15871
- var LlmRuntimeDiskUsageSchema = object({
15872
- nodeId: string(),
15873
- modelsBytes: number(),
15874
- freeBytes: number().optional()
16115
+ /**
16116
+ * Occupancy condition (DEVICE-EVENT trigger). Fires on a ZoneAnalytics
16117
+ * occupancy edge for a device — optionally narrowed to a single admin
16118
+ * `zoneId` and/or object `className`. `op` selects the edge/threshold:
16119
+ * - `became-occupied` (default) — count crossed 0 → ≥ `count`
16120
+ * - `became-free` — count crossed ≥ `count` → below it
16121
+ * - `>=` / `<=` — count is at/over or at/under `count`
16122
+ * `sustainSeconds` requires the condition hold continuously that long
16123
+ * before firing (debounces flicker; 0 = fire on the first matching edge).
16124
+ * Fail-closed: no ZoneAnalytics snapshot / missing zone / null snapshot ⇒
16125
+ * the condition never matches. Confirmed edge-state survives addon restarts
16126
+ * (declared SQLite collection, reseeded on boot).
16127
+ */
16128
+ var NcOccupancyConditionSchema = object({
16129
+ /** Admin zone id to scope the count to; absent = whole-frame occupancy. */
16130
+ zoneId: string().optional(),
16131
+ /** Object class to count; absent = any class. */
16132
+ className: string().optional(),
16133
+ op: _enum([
16134
+ "became-occupied",
16135
+ "became-free",
16136
+ ">=",
16137
+ "<="
16138
+ ]).default("became-occupied"),
16139
+ count: number().int().min(0).default(1),
16140
+ sustainSeconds: number().int().min(0).max(3600).default(15)
16141
+ });
16142
+ /** Admin-zone membership condition (zone IDs as stamped by the ZoneEngine). */
16143
+ var NcZoneConditionSchema = object({
16144
+ ids: array(string().min(1)).min(1),
16145
+ /** Quantifier over `ids` — at least one / every one visited. */
16146
+ match: _enum(["any", "all"]).default("any")
15875
16147
  });
15876
- method(LlmGenerateBaseInputSchema.extend({
15877
- images: array(LlmImageSchema).optional(),
15878
- runtime: ManagedRuntimeConfigSchema,
15879
- /** The managed profile's timeout, threaded by the hub provider. */
15880
- timeoutMs: number().int().positive().optional()
15881
- }), LlmGenerateResultSchema, { kind: "mutation" }), method(object({ runtime: ManagedRuntimeConfigSchema }), LlmRuntimeStatusSchema, {
15882
- kind: "mutation",
15883
- auth: "admin"
15884
- }), method(object({}), _void(), {
15885
- kind: "mutation",
15886
- auth: "admin"
15887
- }), method(object({}), LlmRuntimeStatusSchema), method(object({ model: ManagedModelRefSchema }), _void(), {
15888
- kind: "mutation",
15889
- auth: "admin"
15890
- }), method(object({ file: string() }), _void(), {
15891
- kind: "mutation",
15892
- auth: "admin"
15893
- }), method(object({}), array(LlmNodeModelSchema)), method(object({}), LlmRuntimeDiskUsageSchema);
15894
16148
  /**
15895
- * `llm`consumer-facing LLM surface (spec §1-§3). Collection-mode: array
15896
- * methods concat-fan across providers; single-row methods route to ONE
15897
- * provider by the `addonId` in the call input (the notification-output
15898
- * posture, notification-output.cap.ts:215-250). Provided by `addon-ai`
15899
- * (hub-placed); the cap stays open for future providers.
15900
- *
15901
- * Profiles are ROWS (data), not addons: one row = one usable model endpoint.
15902
- * `apiKey` is a password field — providers REDACT it on read and merge on
15903
- * write; a stored key NEVER round-trips to a client.
16149
+ * The P1 condition set a flat AND of groups; absent group = pass;
16150
+ * membership lists are OR within the list (spec §2.3).
15904
16151
  */
15905
- var LlmProfileKindSchema = _enum([
15906
- "openai-compatible",
15907
- "openai",
15908
- "anthropic",
15909
- "google",
15910
- "managed-local"
15911
- ]);
15912
- var LlmProfileSchema = object({
15913
- id: string(),
15914
- name: string(),
15915
- kind: LlmProfileKindSchema,
15916
- /** Stamped by the provider keeps the fanned catalog routable. */
15917
- addonId: string(),
15918
- enabled: boolean(),
15919
- /** Vendor model id, or the managed runtime's loaded model. */
15920
- model: string(),
15921
- /** Required for openai-compatible; override for cloud kinds. */
15922
- baseUrl: string().optional(),
15923
- /** ConfigUISchema type:'password' — never round-trips (spec §5). */
15924
- apiKey: string().optional(),
15925
- supportsVision: boolean(),
15926
- temperature: number().min(0).max(2).optional(),
15927
- maxTokens: number().int().positive().optional(),
15928
- timeoutMs: number().int().positive().default(6e4),
15929
- extraHeaders: record(string(), string()).optional(),
15930
- /** kind === 'managed-local' only (spec §4). */
15931
- runtime: ManagedRuntimeConfigSchema.optional()
16152
+ var NcConditionsSchema = object({
16153
+ /** Device scope — absent = all devices. */
16154
+ devices: array(number()).optional(),
16155
+ /** Detector class names (any overlap with the record's class set). */
16156
+ classes: array(string().min(1)).optional(),
16157
+ /** Veto classes — any overlap fails the rule. */
16158
+ classesExclude: array(string().min(1)).optional(),
16159
+ /** Minimum detection confidence 0–1 (fails when the record has none). */
16160
+ minConfidence: number().min(0).max(1).optional(),
16161
+ /** Admin zone membership over event `zones` / track `zonesVisited`. */
16162
+ zones: NcZoneConditionSchema.optional(),
16163
+ /** Veto zones any hit fails the rule. */
16164
+ zonesExclude: array(string().min(1)).optional(),
16165
+ /**
16166
+ * Exact (case-insensitive) match on the record's collapsed `label`
16167
+ * (identity name / plate text / subclass).
16168
+ */
16169
+ labelEquals: array(string().min(1)).optional(),
16170
+ /**
16171
+ * Identity matcher. P1 boundary: matched against the record's collapsed
16172
+ * `label` (the identity display name propagated by the face pipeline)
16173
+ * identity-ID matching rides in P2 when identity ids reach the record.
16174
+ */
16175
+ identities: array(string().min(1)).optional(),
16176
+ /** Fuzzy plate matcher against the record's `label` (plate text). */
16177
+ plates: NcPlateMatcherSchema.optional(),
16178
+ /**
16179
+ * Identity EXCLUDE — mirror of {@link identities} with `notIn` semantics.
16180
+ * Same P1 boundary: matched against the record's collapsed `label` (the
16181
+ * identity display name). A record with NO label passes (nothing to
16182
+ * exclude), unlike the include variant which fails on an absent label.
16183
+ */
16184
+ identitiesExclude: array(string().min(1)).optional(),
16185
+ /**
16186
+ * Minimum server-computed key-event importance in [0,1] (`Track.importance`).
16187
+ * TRACK-END only: importance is scored at track close, so it does not exist
16188
+ * at immediate / object-event evaluation time (see catalog `appliesTo`). At
16189
+ * close the value is threaded via the close-time info (the `Track` clone is
16190
+ * captured before the DB row is updated, so it would otherwise read stale).
16191
+ * Fails when the record carries no importance (never guess quality — the
16192
+ * `minConfidence` precedent). MVP cut: a single scalar threshold.
16193
+ */
16194
+ minImportance: number().min(0).max(1).optional(),
16195
+ /**
16196
+ * Minimum track dwell in SECONDS — `(lastSeen − firstSeen) / 1000`.
16197
+ * TRACK-END only: an `immediate` / object-event subject has no closed
16198
+ * lifespan, so a dwell condition never matches immediate delivery
16199
+ * (documented choice — the object-event record carries no `firstSeen`,
16200
+ * so dwell cannot be computed from what the subject actually carries).
16201
+ */
16202
+ minDwellSeconds: number().min(0).optional(),
16203
+ /**
16204
+ * Detection provenance filter. `any` (default / absent) matches every
16205
+ * source; otherwise the subject's source must equal it. Legacy records
16206
+ * with no stamped source are treated as `pipeline`. The union spans both
16207
+ * record kinds — object events carry `pipeline` | `onboard`, synthetic
16208
+ * tracks carry `sensor`.
16209
+ */
16210
+ source: _enum([
16211
+ "pipeline",
16212
+ "onboard",
16213
+ "sensor",
16214
+ "any"
16215
+ ]).optional(),
16216
+ /**
16217
+ * Minimum identity / plate MATCH confidence in [0,1] — DISTINCT from the
16218
+ * detector `minConfidence` (that gates the object-detection score; this
16219
+ * gates the recognition/OCR match score). Fails when the subject carries
16220
+ * no label-match confidence (never guess). TRACK-END only: the confidence
16221
+ * lives on the recognition result and reaches the subject at track close.
16222
+ *
16223
+ * What it measures precisely (plumbed at track close — the closer threads
16224
+ * the value into `NcTrackClosedInfo.labelConfidence`, the same seam as
16225
+ * `importance`): the BEST recognition match confidence observed for the
16226
+ * label the track carries at close — for a face, the peak cosine similarity
16227
+ * of the ASSIGNED identity (`FaceMatch.score`, reset on an identity switch);
16228
+ * for a plate, the peak OCR read score of the best-held plate
16229
+ * (`plateText.confidence`). When BOTH a face and a plate were recognized on
16230
+ * one track the higher of the two is used. A track that ended with no
16231
+ * confident identity/plate match carries no value, so the condition fails
16232
+ * closed for it (an un-recognized subject).
16233
+ */
16234
+ minLabelConfidence: number().min(0).max(1).optional(),
16235
+ /**
16236
+ * DEVICE-EVENT only. Raw device event-type tokens (`EventFire.eventType`,
16237
+ * e.g. a doorbell `press` / `press_long`) — matched case-insensitively
16238
+ * against the token carried on the device-event subject (extracted from the
16239
+ * event-emitter runtime slice's `lastEvent.eventType`). Fails when the
16240
+ * subject carries no token. Doorbell-pulse / passive-sensor kinds emit no
16241
+ * eventType, so gate those with {@link sensorKinds} instead.
16242
+ */
16243
+ eventTypeTokens: array(string().min(1)).optional(),
16244
+ /**
16245
+ * DEVICE-EVENT only. Sensor/control taxonomy kinds (e.g. `doorbell`,
16246
+ * `contact`, `button`, `device-event`) — matched against the persisted
16247
+ * `SensorEvent.kind` (see `sensor-event-kinds.ts`). Membership is OR.
16248
+ */
16249
+ sensorKinds: array(string().min(1)).optional(),
16250
+ /**
16251
+ * PACKAGE-EVENT only. Which package phase fires the rule — `delivered`
16252
+ * (a parked parcel appeared), `picked-up` (it departed), or `both`. Fails
16253
+ * when the subject's phase does not match (a subject always carries a phase
16254
+ * on the package-event trigger).
16255
+ */
16256
+ packagePhase: _enum([
16257
+ "delivered",
16258
+ "picked-up",
16259
+ "both"
16260
+ ]).optional(),
16261
+ /**
16262
+ * PERSONAL-RULE custom zones (viewer-drawn). Inline normalized polygons
16263
+ * (MaskShape vocabulary). A record passes when its bbox overlaps ANY
16264
+ * listed polygon (ZoneEngine membership semantics). Evaluated only when
16265
+ * the subject carries a bbox; absent bbox ⇒ the condition FAILS.
16266
+ */
16267
+ customZones: array(MaskPolygonShapeSchema).optional(),
16268
+ /**
16269
+ * DEVICE-EVENT only. ZoneAnalytics occupancy edge — fires when a device's
16270
+ * (optionally zone/class-scoped) occupancy count crosses the configured
16271
+ * threshold and holds for `sustainSeconds`. Fail-closed on missing
16272
+ * substrate (no snapshot / missing zone). See {@link NcOccupancyCondition}.
16273
+ */
16274
+ occupancy: NcOccupancyConditionSchema.optional()
15932
16275
  });
15933
- /** ConfigUISchema tree passed through untyped on the wire (the
15934
- * notification-output `ConfigSchemaPassthrough` precedent at
15935
- * notification-output.cap.ts:151); the exported TS type re-tightens it. */
15936
- var ConfigSchemaPassthrough = unknown();
15937
- var LlmProfileKindDescriptorSchema = object({
15938
- kind: LlmProfileKindSchema,
15939
- label: string(),
15940
- icon: string(),
15941
- /** Stamped by each provider so the concat-fanned catalog stays routable. */
15942
- addonId: string(),
15943
- configSchema: ConfigSchemaPassthrough
16276
+ /** One delivery target: a `notification-output` Target ref + passthrough params. */
16277
+ var NcRuleTargetSchema = object({
16278
+ /** `notification-output` Target id. */
16279
+ targetId: string().min(1),
16280
+ /**
16281
+ * Per-backend passthrough. Recognized keys are mapped onto the canonical
16282
+ * Notification (`priority`, `level`, `sound`, `clickUrl`, `ttl`); the
16283
+ * degrade engine drops what the backend can't render.
16284
+ */
16285
+ params: record(string(), unknown()).optional()
15944
16286
  });
15945
- var LlmDefaultSelectorSchema = union([object({ consumer: string() }), object({ purpose: _enum(["text", "vision"]) })]);
15946
- var LlmDefaultSchema = object({
15947
- selector: LlmDefaultSelectorSchema,
15948
- profileId: string()
16287
+ /**
16288
+ * Media attachment policy (P1 still-image subset).
16289
+ * - `best` — the best AVAILABLE subject image at dispatch time (D-3).
16290
+ * - `best-matching` — the media that explains WHY the rule fired: a rule
16291
+ * matched on identities attaches the subject's `faceCrop`, one matched on
16292
+ * plates attaches the `plateCrop`; a rule with no identity/plate condition
16293
+ * (or when the specific crop is missing) degrades to `best`, then
16294
+ * `keyFrame`, then no attachment — never delaying the send. The matched
16295
+ * condition summary is frozen on the outbox row at enqueue (like the rule
16296
+ * name), so the choice never drifts from the record that fired it.
16297
+ * - `keyFrame` — the clean scene frame (no subject box).
16298
+ * - `none` — no attachment.
16299
+ */
16300
+ var NcMediaPolicySchema = object({ attach: _enum([
16301
+ "best",
16302
+ "best-matching",
16303
+ "keyFrame",
16304
+ "none"
16305
+ ]).default("best") });
16306
+ /** Throttle — cooldown survives restarts (rebuilt from the outbox on boot). */
16307
+ var NcThrottleSchema = object({
16308
+ cooldownSec: number().int().min(0).max(86400).default(60),
16309
+ /** `rule` = one shared cooldown; `rule-device` = per-camera cooldown. */
16310
+ scope: _enum(["rule", "rule-device"]).default("rule-device")
16311
+ });
16312
+ /** Client-supplied rule fields (server stamps id/createdBy/createdAt/updatedAt). */
16313
+ var NcRuleInputSchema = object({
16314
+ name: string().min(1).max(200),
16315
+ enabled: boolean().default(true),
16316
+ delivery: NcDeliverySchema,
16317
+ conditions: NcConditionsSchema.default({}),
16318
+ schedule: NcScheduleSchema.optional(),
16319
+ targets: array(NcRuleTargetSchema).min(1),
16320
+ media: NcMediaPolicySchema.default({ attach: "best" }),
16321
+ throttle: NcThrottleSchema.default({
16322
+ cooldownSec: 60,
16323
+ scope: "rule-device"
16324
+ }),
16325
+ /** `{{var}}` templating over camera/class/label/zones/confidence/time. */
16326
+ template: object({
16327
+ title: string().max(500).optional(),
16328
+ body: string().max(2e3).optional()
16329
+ }).optional(),
16330
+ /** Canonical notification priority ordinal (1..5); per-target overridable. */
16331
+ priority: number().int().min(1).max(5).default(3),
16332
+ /**
16333
+ * Ownership/visibility key. Absent = admin/global rule (unchanged legacy
16334
+ * behaviour, visible to all, read-only in the viewer). Present = personal
16335
+ * rule owned by this userId. Server-stamped; never trusted from a client.
16336
+ */
16337
+ ownerUserId: string().optional()
15949
16338
  });
15950
- /** Server-side rollup row — getUsage never dumps raw call rows (spec §6). */
15951
- var LlmUsageRollupSchema = object({
15952
- day: string(),
15953
- consumer: string(),
15954
- profileId: string(),
15955
- calls: number(),
15956
- okCalls: number(),
15957
- errorCalls: number(),
15958
- inputTokens: number(),
15959
- outputTokens: number(),
15960
- avgLatencyMs: number()
16339
+ /**
16340
+ * Partial patch for `updateRule` — any subset of the input fields, plus the
16341
+ * persisted-only {@link NcRuleSchema} `disabledTargetIds` set. The latter is
16342
+ * NOT a client-authored input field (it lives on the persisted rule, not the
16343
+ * input), so it is added here explicitly to let the store's per-target opt-out
16344
+ * toggle round-trip through the shared `update` path. Viewer opt-out mutations
16345
+ * still flow through `nc.setRuleTargetEnabled` (owner-checked), never a raw
16346
+ * `updateRule` patch.
16347
+ */
16348
+ var NcRulePatchSchema = NcRuleInputSchema.partial().extend({ disabledTargetIds: array(string()).optional() });
16349
+ /** A persisted rule. */
16350
+ var NcRuleSchema = NcRuleInputSchema.extend({
16351
+ id: string(),
16352
+ /** userId of the admin who created the rule (server-stamped caller). */
16353
+ createdBy: string(),
16354
+ createdAt: number(),
16355
+ updatedAt: number(),
16356
+ /**
16357
+ * Per-target opt-out set. A targetId here is suppressed for THIS rule at
16358
+ * send time. Only a target's OWNER may add/remove its id (server-checked
16359
+ * in `nc.setRuleTargetEnabled`). Defaults to empty.
16360
+ */
16361
+ disabledTargetIds: array(string()).default([])
16362
+ });
16363
+ var NcTestResultSchema = object({
16364
+ recordId: string(),
16365
+ recordKind: _enum([
16366
+ "object-event",
16367
+ "track",
16368
+ "device-event",
16369
+ "package-event"
16370
+ ]),
16371
+ deviceId: number(),
16372
+ timestamp: number(),
16373
+ wouldFire: boolean(),
16374
+ /** Condition id that failed (first failing group), when `wouldFire` is false. */
16375
+ failedCondition: string().optional(),
16376
+ className: string().optional(),
16377
+ label: string().optional()
15961
16378
  });
15962
- /** LLM-facing view over the reused ModelCatalogEntry mechanism (spec §4.2). */
15963
- var ManagedModelCatalogEntrySchema = object({
16379
+ var NcConditionDescriptorSchema = object({
16380
+ /** Field id inside `NcConditions` (or `'schedule'` for the rule-level group). */
15964
16381
  id: string(),
16382
+ group: _enum([
16383
+ "scope",
16384
+ "class",
16385
+ "zones",
16386
+ "quality",
16387
+ "label",
16388
+ "schedule",
16389
+ "device",
16390
+ "package",
16391
+ "occupancy"
16392
+ ]),
15965
16393
  label: string(),
15966
- family: string(),
15967
- purpose: _enum(["text", "vision"]),
15968
- url: string(),
15969
- sha256: string(),
15970
- sizeBytes: number(),
15971
- quantization: string(),
15972
- /** Load-time guidance shown in the picker. */
15973
- minRamBytes: number(),
15974
- contextSizeDefault: number().int(),
15975
- /** Vision models: companion projector file. */
15976
- mmprojUrl: string().optional()
16394
+ /** Editor widget the UI renders — never hardcode per-condition forms. */
16395
+ valueType: _enum([
16396
+ "deviceIdList",
16397
+ "stringList",
16398
+ "number01",
16399
+ "number",
16400
+ "sourceSelect",
16401
+ "zoneSelection",
16402
+ "zoneIdList",
16403
+ "schedule",
16404
+ "plateMatcher",
16405
+ "packagePhase",
16406
+ "polygonDraw",
16407
+ "occupancy"
16408
+ ]),
16409
+ operator: _enum([
16410
+ "in",
16411
+ "notIn",
16412
+ "anyOf",
16413
+ "allOf",
16414
+ "gte",
16415
+ "fuzzyIn",
16416
+ "withinSchedule"
16417
+ ]),
16418
+ /** Which delivery kinds the condition applies to. */
16419
+ appliesTo: array(NcDeliverySchema),
16420
+ phase: string(),
16421
+ description: string().optional()
15977
16422
  });
15978
- var LlmRuntimeNodeSchema = object({
15979
- nodeId: string(),
15980
- reachable: boolean(),
15981
- status: LlmRuntimeStatusSchema.optional(),
15982
- disk: LlmRuntimeDiskUsageSchema.optional(),
15983
- error: string().optional()
16423
+ /**
16424
+ * The delivery lifecycle status of a history row — a straight read of the
16425
+ * durable outbox row's own status (single source of truth):
16426
+ * - `pending` — enqueued, in-flight or retrying with backoff
16427
+ * - `sent` — delivered (terminal)
16428
+ * - `dead` — dead-lettered after exhausting retries / a permanent
16429
+ * backend rejection / a deleted target (terminal; carries
16430
+ * the failure `error`)
16431
+ *
16432
+ * P1 has no `suppressed-quiet-hours` / `snoozed` states — those ride the P2
16433
+ * user dimension (quiet hours / snooze) and are additive when they land.
16434
+ */
16435
+ var NcHistoryStatusSchema = _enum([
16436
+ "pending",
16437
+ "sent",
16438
+ "dead"
16439
+ ]);
16440
+ /** The evaluated record kind a history row descends from (one per trigger). */
16441
+ var NcHistoryRecordKindSchema = _enum([
16442
+ "object-event",
16443
+ "track-end",
16444
+ "device-event",
16445
+ "package-event"
16446
+ ]);
16447
+ /** Subject summary frozen on the row at fire time (survives rule/record edits). */
16448
+ var NcHistorySubjectSchema = object({
16449
+ className: string(),
16450
+ label: string().optional(),
16451
+ confidence: number().optional(),
16452
+ zones: array(string()),
16453
+ timestamp: number()
16454
+ });
16455
+ /**
16456
+ * One delivery-history row. This is a read-only VIEW over the durable
16457
+ * outbox row (single source of truth — the same row the drain loop drives;
16458
+ * NO second write path, so history can never drift from delivery state).
16459
+ * The §3.2 fields map directly: `ruleId`/`targetId`/`deviceId` are columns,
16460
+ * `eventRef` is `recordKind`+`recordId`, `timestamps` are `createdAt`
16461
+ * (fire) / `updatedAt` (last transition), `status` + `error` are the
16462
+ * lifecycle. `ruleName` + `subject` are the intent snapshot frozen at
16463
+ * enqueue. `userId?` (per-recipient history) is P2 — no user dimension in
16464
+ * P1 (admin scope only).
16465
+ */
16466
+ var NcHistoryEntrySchema = object({
16467
+ /** Outbox row id — the stable dedup id `ruleId:dedupRef:targetId`. */
16468
+ id: string(),
16469
+ ruleId: string(),
16470
+ /** Rule name frozen at fire time (outlives a later rename / delete). */
16471
+ ruleName: string(),
16472
+ /** The rule urgency/trigger that produced this delivery. */
16473
+ delivery: NcDeliverySchema,
16474
+ targetId: string(),
16475
+ deviceId: number(),
16476
+ recordKind: NcHistoryRecordKindSchema,
16477
+ /** Event / track ref of the evaluated record (§3.2 `eventRef`). */
16478
+ recordId: string(),
16479
+ /** Present for track-scoped deliveries (object-event / track-end). */
16480
+ trackId: string().optional(),
16481
+ status: NcHistoryStatusSchema,
16482
+ /** Delivery attempts made so far. */
16483
+ attempts: number().int(),
16484
+ /** Fire time (outbox enqueue). */
16485
+ createdAt: number(),
16486
+ /** Last transition time (terminal for sent / dead). */
16487
+ updatedAt: number(),
16488
+ /** Failure detail — present on a `dead` row. */
16489
+ error: string().optional(),
16490
+ subject: NcHistorySubjectSchema
15984
16491
  });
15985
- var GenerateVisionInputSchema = LlmGenerateBaseInputSchema.extend({ images: array(LlmImageSchema).min(1) });
15986
- var ProfileRefInputSchema = object({
15987
- addonId: string(),
15988
- profileId: string()
16492
+ /**
16493
+ * Query filter for `getHistory` (spec §4.2). Every field is a narrowing
16494
+ * AND; absent = unbounded on that axis. `since`/`until` bound the fire time
16495
+ * (`createdAt`, epoch ms, inclusive). `limit` is clamped to
16496
+ * {@link NC_HISTORY_LIMIT_MAX}. `userId` (per-recipient filtering) is P2.
16497
+ */
16498
+ var NcHistoryFilterSchema = object({
16499
+ ruleId: string().optional(),
16500
+ deviceId: number().optional(),
16501
+ status: NcHistoryStatusSchema.optional(),
16502
+ since: number().optional(),
16503
+ until: number().optional(),
16504
+ limit: number().int().min(1).max(500).default(100)
15989
16505
  });
15990
- method(LlmGenerateBaseInputSchema, LlmGenerateResultSchema, { kind: "mutation" }), method(GenerateVisionInputSchema, LlmGenerateResultSchema, { kind: "mutation" }), method(object({}), array(LlmProfileKindDescriptorSchema)), method(object({}), array(LlmProfileSchema)), method(object({ profile: LlmProfileSchema }), LlmProfileSchema, {
15991
- kind: "mutation",
15992
- auth: "admin"
15993
- }), method(ProfileRefInputSchema, _void(), {
16506
+ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), method(object({ ruleId: string() }), object({ rule: NcRuleSchema.nullable() }), { auth: "admin" }), method(object({ rule: NcRuleInputSchema }), object({ rule: NcRuleSchema }), {
15994
16507
  kind: "mutation",
15995
- auth: "admin"
15996
- }), method(ProfileRefInputSchema, LlmGenerateResultSchema, {
16508
+ auth: "admin",
16509
+ caller: "required"
16510
+ }), method(object({
16511
+ ruleId: string(),
16512
+ patch: NcRulePatchSchema
16513
+ }), object({ rule: NcRuleSchema }), {
15997
16514
  kind: "mutation",
15998
- auth: "admin"
15999
- }), method(ProfileRefInputSchema, array(string())), method(object({}), array(LlmDefaultSchema)), method(object({
16000
- selector: LlmDefaultSelectorSchema,
16001
- profileId: string().nullable()
16002
- }), _void(), {
16515
+ auth: "admin",
16516
+ caller: "required"
16517
+ }), method(object({ ruleId: string() }), object({ success: literal(true) }), {
16003
16518
  kind: "mutation",
16004
16519
  auth: "admin"
16005
16520
  }), method(object({
16006
- since: number().optional(),
16007
- until: number().optional(),
16008
- consumer: string().optional(),
16009
- profileId: string().optional()
16010
- }), array(LlmUsageRollupSchema)), method(object({}), array(ManagedModelCatalogEntrySchema)), method(object({}), array(LlmRuntimeNodeSchema)), method(object({ nodeId: string() }), array(LlmNodeModelSchema)), method(object({
16011
- nodeId: string(),
16012
- model: ManagedModelRefSchema
16013
- }), _void(), {
16521
+ ruleId: string(),
16522
+ enabled: boolean()
16523
+ }), object({ success: literal(true) }), {
16014
16524
  kind: "mutation",
16015
16525
  auth: "admin"
16016
16526
  }), method(object({
16017
- nodeId: string(),
16018
- file: string()
16019
- }), _void(), {
16020
- kind: "mutation",
16021
- auth: "admin"
16022
- }), method(ProfileRefInputSchema, LlmRuntimeStatusSchema), method(ProfileRefInputSchema, LlmRuntimeStatusSchema, {
16023
- kind: "mutation",
16024
- auth: "admin"
16025
- }), method(ProfileRefInputSchema, _void(), {
16527
+ rule: NcRuleInputSchema,
16528
+ lookbackMinutes: number().int().min(1).max(1440).default(60)
16529
+ }), object({ results: array(NcTestResultSchema) }), {
16026
16530
  kind: "mutation",
16027
16531
  auth: "admin"
16028
- });
16532
+ }), method(object({}), object({ catalog: array(NcConditionDescriptorSchema) })), method(object({ filter: NcHistoryFilterSchema.default({ limit: 100 }) }), object({ entries: array(NcHistoryEntrySchema) }), { auth: "admin" });
16029
16533
  /**
16030
16534
  * Zod schemas for persisted record types.
16031
16535
  *
@@ -16711,7 +17215,10 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
16711
17215
  }), method(object({
16712
17216
  eventId: string(),
16713
17217
  kind: MediaFileKindEnum.optional()
16714
- }), array(MediaFileSchema).readonly()), method(object({ trackId: string() }), array(MediaFileSchema).readonly()), method(SearchObjectEventsInput, array(ScoredObjectEventSchema).readonly()), object({
17218
+ }), array(MediaFileSchema).readonly()), method(object({
17219
+ trackId: string(),
17220
+ kinds: array(MediaFileKindEnum).optional()
17221
+ }), array(MediaFileSchema).readonly()), method(SearchObjectEventsInput, array(ScoredObjectEventSchema).readonly()), object({
16715
17222
  deviceId: number(),
16716
17223
  timestamp: number(),
16717
17224
  frameWidth: number(),
@@ -16732,76 +17239,6 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
16732
17239
  eventId: string(),
16733
17240
  timestamp: number()
16734
17241
  });
16735
- /**
16736
- * Cap → event-kind mapping for the SENSOR / CONTROL cap families — the table
16737
- * `pipeline-analytics.listEventKinds` uses to turn a linked device's bound
16738
- * caps into per-camera event-kind descriptors.
16739
- *
16740
- * The descriptor DATA (color / iconId / labelKey / parentKind / category)
16741
- * is NOT duplicated here — every entry is derived from the single
16742
- * `EVENT_TAXONOMY` dictionary (`catalogs/event-taxonomy.ts`). This file owns
16743
- * ONLY the cap-name → taxonomy-kind mapping. Adding a new eventful sensor /
16744
- * control cap means adding one line here (and a taxonomy entry); the anti-
16745
- * drift guard `scripts/check-event-kind-coverage.ts` fails the build if an
16746
- * eventful cap is missing.
16747
- */
16748
- /** Map a taxonomy `iconId` onto the legacy closed `EventKindIcon` enum. */
16749
- var LEGACY_ICON = {
16750
- motion: "motion",
16751
- audio: "audio",
16752
- person: "person",
16753
- vehicle: "vehicle",
16754
- animal: "animal",
16755
- package: "package",
16756
- door: "door",
16757
- pir: "pir",
16758
- smoke: "smoke",
16759
- water: "water",
16760
- button: "button",
16761
- generic: "generic",
16762
- gas: "smoke",
16763
- vibration: "generic",
16764
- tamper: "generic",
16765
- presence: "person",
16766
- lock: "generic",
16767
- siren: "generic",
16768
- switch: "generic",
16769
- doorbell: "button"
16770
- };
16771
- function legacyIcon(iconId) {
16772
- return LEGACY_ICON[iconId] ?? "generic";
16773
- }
16774
- /**
16775
- * Cap name → taxonomy kind id. Covers EVERY eventful sensor / control cap.
16776
- * The anti-drift guard cross-checks this against the eventful caps declared
16777
- * in `packages/types/src/capabilities/*.cap.ts`.
16778
- */
16779
- var CAP_TO_KIND = {
16780
- contact: "contact",
16781
- motion: "motion-sensor",
16782
- smoke: "smoke",
16783
- flood: "flood",
16784
- gas: "gas",
16785
- "carbon-monoxide": "carbon-monoxide",
16786
- vibration: "vibration",
16787
- tamper: "tamper",
16788
- presence: "presence",
16789
- "enum-sensor": "enum-sensor",
16790
- "event-emitter": "device-event",
16791
- "lock-control": "lock",
16792
- switch: "switch",
16793
- button: "button",
16794
- doorbell: "doorbell"
16795
- };
16796
- function buildDescriptor(capName, kind) {
16797
- const t = EVENT_TAXONOMY[kind];
16798
- if (t === void 0) throw new Error(`EVENT_KIND_BY_CAP: cap '${capName}' maps to unknown taxonomy kind '${kind}'`);
16799
- return {
16800
- ...t,
16801
- icon: legacyIcon(t.iconId)
16802
- };
16803
- }
16804
- Object.freeze(Object.fromEntries(Object.entries(CAP_TO_KIND).map(([capName, kind]) => [capName, buildDescriptor(capName, kind)])));
16805
17242
  var CameraPipelineConfigSchema = object({
16806
17243
  engine: PipelineEngineChoiceSchema.optional(),
16807
17244
  steps: array(PipelineStepInputSchema).readonly(),
@@ -17287,6 +17724,76 @@ method(object({
17287
17724
  auth: "admin"
17288
17725
  });
17289
17726
  /**
17727
+ * Cap → event-kind mapping for the SENSOR / CONTROL cap families — the table
17728
+ * `pipeline-analytics.listEventKinds` uses to turn a linked device's bound
17729
+ * caps into per-camera event-kind descriptors.
17730
+ *
17731
+ * The descriptor DATA (color / iconId / labelKey / parentKind / category)
17732
+ * is NOT duplicated here — every entry is derived from the single
17733
+ * `EVENT_TAXONOMY` dictionary (`catalogs/event-taxonomy.ts`). This file owns
17734
+ * ONLY the cap-name → taxonomy-kind mapping. Adding a new eventful sensor /
17735
+ * control cap means adding one line here (and a taxonomy entry); the anti-
17736
+ * drift guard `scripts/check-event-kind-coverage.ts` fails the build if an
17737
+ * eventful cap is missing.
17738
+ */
17739
+ /** Map a taxonomy `iconId` onto the legacy closed `EventKindIcon` enum. */
17740
+ var LEGACY_ICON = {
17741
+ motion: "motion",
17742
+ audio: "audio",
17743
+ person: "person",
17744
+ vehicle: "vehicle",
17745
+ animal: "animal",
17746
+ package: "package",
17747
+ door: "door",
17748
+ pir: "pir",
17749
+ smoke: "smoke",
17750
+ water: "water",
17751
+ button: "button",
17752
+ generic: "generic",
17753
+ gas: "smoke",
17754
+ vibration: "generic",
17755
+ tamper: "generic",
17756
+ presence: "person",
17757
+ lock: "generic",
17758
+ siren: "generic",
17759
+ switch: "generic",
17760
+ doorbell: "button"
17761
+ };
17762
+ function legacyIcon(iconId) {
17763
+ return LEGACY_ICON[iconId] ?? "generic";
17764
+ }
17765
+ /**
17766
+ * Cap name → taxonomy kind id. Covers EVERY eventful sensor / control cap.
17767
+ * The anti-drift guard cross-checks this against the eventful caps declared
17768
+ * in `packages/types/src/capabilities/*.cap.ts`.
17769
+ */
17770
+ var CAP_TO_KIND = {
17771
+ contact: "contact",
17772
+ motion: "motion-sensor",
17773
+ smoke: "smoke",
17774
+ flood: "flood",
17775
+ gas: "gas",
17776
+ "carbon-monoxide": "carbon-monoxide",
17777
+ vibration: "vibration",
17778
+ tamper: "tamper",
17779
+ presence: "presence",
17780
+ "enum-sensor": "enum-sensor",
17781
+ "event-emitter": "device-event",
17782
+ "lock-control": "lock",
17783
+ switch: "switch",
17784
+ button: "button",
17785
+ doorbell: "doorbell"
17786
+ };
17787
+ function buildDescriptor(capName, kind) {
17788
+ const t = EVENT_TAXONOMY[kind];
17789
+ if (t === void 0) throw new Error(`EVENT_KIND_BY_CAP: cap '${capName}' maps to unknown taxonomy kind '${kind}'`);
17790
+ return {
17791
+ ...t,
17792
+ icon: legacyIcon(t.iconId)
17793
+ };
17794
+ }
17795
+ Object.freeze(Object.fromEntries(Object.entries(CAP_TO_KIND).map(([capName, kind]) => [capName, buildDescriptor(capName, kind)])));
17796
+ /**
17290
17797
  * server-management — per-NODE singleton capability for a node's ROOT
17291
17798
  * package lifecycle (runtime-updatable node packages).
17292
17799
  *
@@ -18786,7 +19293,28 @@ var FaceInfoSchema = object({
18786
19293
  * (`/addon/<addonId>/event-media/<keyFrameMediaKey>`). Absent when the
18787
19294
  * track produced no key frame (e.g. native/onboard source) — the UI falls
18788
19295
  * back to the inline `base64` face crop. */
18789
- keyFrameMediaKey: string().optional()
19296
+ keyFrameMediaKey: string().optional(),
19297
+ /** Winning identity-match cosine (0..1) for this face's track, when an
19298
+ * identity was auto-confirmed. Lets the UI surface WHY a face was assigned
19299
+ * (confidence badge / low-confidence audit). Absent on legacy rows and on
19300
+ * faces that were never auto-recognized. */
19301
+ bestMatchScore: number().optional(),
19302
+ /** Native-scale face short side (px) at recognition time, when the runner
19303
+ * measured it. Lets the UI flag low-resolution auto-assignments. Absent on
19304
+ * legacy rows / runners that reported no native measure. */
19305
+ nativeFaceShortSidePx: number().optional(),
19306
+ /** SUGGESTED identity for this face — a plausible-but-not-confident match that
19307
+ * MISSED auto-assignment (cosine in the suggestion band, or above threshold
19308
+ * but blocked only by the recognition size floor). Mutually exclusive with
19309
+ * `recognizedIdentityId` (a suggestion is NEVER an assignment): the face stays
19310
+ * UNASSIGNED and everything else keeps treating it as unrecognized — the UI
19311
+ * merely offers a one-tap "is this <name>?" confirm. Absent on legacy rows and
19312
+ * on faces that were auto-assigned or below the suggestion band. (2026-07-24) */
19313
+ suggestedIdentityId: string().optional(),
19314
+ /** Peak identity-match cosine (0..1) for `suggestedIdentityId`, captured at the
19315
+ * same moment as `bestMatchScore` (track peak, at close). Lets the UI rank /
19316
+ * badge suggestion confidence. Present iff `suggestedIdentityId` is. (2026-07-24) */
19317
+ suggestedMatchScore: number().optional()
18790
19318
  });
18791
19319
  var FaceFilterEnum = _enum([
18792
19320
  "unassigned",
@@ -20829,36 +21357,6 @@ Object.freeze({
20829
21357
  addonId: null,
20830
21358
  access: "view"
20831
21359
  },
20832
- "advancedNotifier.deleteRule": {
20833
- capName: "advanced-notifier",
20834
- capScope: "system",
20835
- addonId: null,
20836
- access: "delete"
20837
- },
20838
- "advancedNotifier.getHistory": {
20839
- capName: "advanced-notifier",
20840
- capScope: "system",
20841
- addonId: null,
20842
- access: "view"
20843
- },
20844
- "advancedNotifier.getRules": {
20845
- capName: "advanced-notifier",
20846
- capScope: "system",
20847
- addonId: null,
20848
- access: "view"
20849
- },
20850
- "advancedNotifier.testRule": {
20851
- capName: "advanced-notifier",
20852
- capScope: "system",
20853
- addonId: null,
20854
- access: "create"
20855
- },
20856
- "advancedNotifier.upsertRule": {
20857
- capName: "advanced-notifier",
20858
- capScope: "system",
20859
- addonId: null,
20860
- access: "create"
20861
- },
20862
21360
  "alarmPanel.arm": {
20863
21361
  capName: "alarm-panel",
20864
21362
  capScope: "device",
@@ -23163,6 +23661,60 @@ Object.freeze({
23163
23661
  addonId: null,
23164
23662
  access: "create"
23165
23663
  },
23664
+ "notificationRules.createRule": {
23665
+ capName: "notification-rules",
23666
+ capScope: "system",
23667
+ addonId: null,
23668
+ access: "create"
23669
+ },
23670
+ "notificationRules.deleteRule": {
23671
+ capName: "notification-rules",
23672
+ capScope: "system",
23673
+ addonId: null,
23674
+ access: "delete"
23675
+ },
23676
+ "notificationRules.getConditionCatalog": {
23677
+ capName: "notification-rules",
23678
+ capScope: "system",
23679
+ addonId: null,
23680
+ access: "view"
23681
+ },
23682
+ "notificationRules.getHistory": {
23683
+ capName: "notification-rules",
23684
+ capScope: "system",
23685
+ addonId: null,
23686
+ access: "view"
23687
+ },
23688
+ "notificationRules.getRule": {
23689
+ capName: "notification-rules",
23690
+ capScope: "system",
23691
+ addonId: null,
23692
+ access: "view"
23693
+ },
23694
+ "notificationRules.listRules": {
23695
+ capName: "notification-rules",
23696
+ capScope: "system",
23697
+ addonId: null,
23698
+ access: "view"
23699
+ },
23700
+ "notificationRules.setRuleEnabled": {
23701
+ capName: "notification-rules",
23702
+ capScope: "system",
23703
+ addonId: null,
23704
+ access: "create"
23705
+ },
23706
+ "notificationRules.testRule": {
23707
+ capName: "notification-rules",
23708
+ capScope: "system",
23709
+ addonId: null,
23710
+ access: "create"
23711
+ },
23712
+ "notificationRules.updateRule": {
23713
+ capName: "notification-rules",
23714
+ capScope: "system",
23715
+ addonId: null,
23716
+ access: "create"
23717
+ },
23166
23718
  "notifier.cancel": {
23167
23719
  capName: "notifier",
23168
23720
  capScope: "device",