@camstack/system 1.2.7 → 1.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/addon-runner.js +6 -6
  2. package/dist/addon-runner.mjs +6 -6
  3. package/dist/addon-utils.js +1 -1
  4. package/dist/addon-utils.mjs +1 -1
  5. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  6. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  7. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  8. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  9. package/dist/builtins/alerts/alerts.addon.js +1 -1
  10. package/dist/builtins/alerts/alerts.addon.mjs +1 -1
  11. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +1 -1
  12. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
  13. package/dist/builtins/console-logging/index.js +1 -1
  14. package/dist/builtins/console-logging/index.mjs +1 -1
  15. package/dist/builtins/device-manager/device-manager.addon.js +1 -1
  16. package/dist/builtins/device-manager/device-manager.addon.mjs +1 -1
  17. package/dist/builtins/doorbell/virtual-doorbell.addon.js +1 -1
  18. package/dist/builtins/doorbell/virtual-doorbell.addon.mjs +1 -1
  19. package/dist/builtins/hub-forwarder/index.js +1 -1
  20. package/dist/builtins/hub-forwarder/index.mjs +1 -1
  21. package/dist/builtins/local-auth/local-auth.addon.js +1 -1
  22. package/dist/builtins/local-auth/local-auth.addon.mjs +1 -1
  23. package/dist/builtins/local-network/local-network.addon.js +1 -1
  24. package/dist/builtins/local-network/local-network.addon.mjs +1 -1
  25. package/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  26. package/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  27. package/dist/builtins/platform-probe/index.js +1 -1
  28. package/dist/builtins/platform-probe/index.mjs +1 -1
  29. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  30. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  31. package/dist/builtins/snapshot/index.js +1 -1
  32. package/dist/builtins/snapshot/index.mjs +1 -1
  33. package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  34. package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  35. package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +1 -1
  36. package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +1 -1
  37. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.d.ts +12 -0
  38. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +48 -7
  39. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +48 -7
  40. package/dist/builtins/storage-orchestrator/storage-pressure-manager.d.ts +27 -0
  41. package/dist/builtins/system-config/system-config.addon.js +1 -1
  42. package/dist/builtins/system-config/system-config.addon.mjs +1 -1
  43. package/dist/builtins/winston-logging/index.js +1 -1
  44. package/dist/builtins/winston-logging/index.mjs +1 -1
  45. package/dist/{custom-action-registry-BEXwC-oo.mjs → custom-action-registry-F__gp_VX.mjs} +1 -1
  46. package/dist/{custom-action-registry-vLYEFTtv.js → custom-action-registry-jY0NOZK8.js} +1 -1
  47. package/dist/{dist-CfcmjXSI.mjs → dist-CVCNYn7D.mjs} +1246 -732
  48. package/dist/{dist-DEkwmyIj.js → dist-SI-yNpKE.js} +1246 -732
  49. package/dist/index.js +57 -7
  50. package/dist/index.mjs +57 -7
  51. package/dist/kernel/cap-router-builder.d.ts +18 -1
  52. package/dist/kernel/custom-action-registry.d.ts +3 -3
  53. package/dist/kernel/transport/child-cap-protocol.d.ts +11 -1
  54. package/dist/{manifest-python-deps-DIrBiAMS.js → manifest-python-deps-CEwMAaKZ.js} +5 -3
  55. package/dist/{manifest-python-deps-QqIGHGMJ.mjs → manifest-python-deps-DyEweBkB.mjs} +5 -3
  56. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  let zod = require("zod");
2
- //#region ../types/dist/event-category-D4HJq7Mw.mjs
2
+ //#region ../types/dist/event-category-BLcNejAE.mjs
3
3
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
4
4
  EventCategory["SystemBoot"] = "system.boot";
5
5
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -149,9 +149,6 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
149
149
  EventCategory["RecordingSegmentWritten"] = "recording.segment.written";
150
150
  EventCategory["RecordingPolicyFallback"] = "recording.policy.fallback";
151
151
  EventCategory["RecordingRetentionCompleted"] = "recording.retention.completed";
152
- /** Runner-sampled scrub thumbnail (~1/5 s/camera). Telemetry (D8): a lost
153
- * thumb is a scrub gap the recorder's keyframe backfill covers. */
154
- EventCategory["RecordingThumbSampled"] = "recording.thumb-sampled";
155
152
  /** Export render progress (0–100). Telemetry (D8): a lost tick is a stale
156
153
  * progress bar the client reconciles via `recordingExport.getExport`. */
157
154
  EventCategory["RecordingExportProgress"] = "recording.export.progress";
@@ -2702,7 +2699,6 @@ function expandCapMethods(def) {
2702
2699
  };
2703
2700
  return out;
2704
2701
  }
2705
- /** Shorthand to define a method schema */
2706
2702
  function method(input, output, options) {
2707
2703
  return {
2708
2704
  input,
@@ -2710,6 +2706,7 @@ function method(input, output, options) {
2710
2706
  kind: options?.kind ?? "query",
2711
2707
  auth: options?.auth ?? "protected",
2712
2708
  ...options?.access !== void 0 ? { access: options.access } : {},
2709
+ ...options?.caller !== void 0 ? { caller: options.caller } : {},
2713
2710
  timeoutMs: options?.timeoutMs
2714
2711
  };
2715
2712
  }
@@ -4292,6 +4289,59 @@ for (const l of AUDIO_MACRO_LABELS) {
4292
4289
  /** The complete taxonomy dictionary, keyed by kind. */
4293
4290
  var EVENT_TAXONOMY = Object.freeze(Object.fromEntries(entries));
4294
4291
  /**
4292
+ * Notification-Center taxonomy — the fixed vocabulary the NC rule editor
4293
+ * offers as pickers instead of free text. Derived (never hand-listed) from the
4294
+ * single `EVENT_TAXONOMY` dictionary so it stays in lockstep with every other
4295
+ * taxonomy surface (timeline, filters, event page).
4296
+ *
4297
+ * Three buckets, mapped onto the rule editor's `stringList` conditions:
4298
+ * - `videoClasses` → detection classes (person / vehicle / animal + subs)
4299
+ * for the `classes` / `classesExclude` conditions.
4300
+ * - `audioKinds` → audio-analyzer sub kinds (`audio-scream`, …) shown in
4301
+ * the same class picker, grouped under an Audio header.
4302
+ * - `labels` → sensor + control taxonomy kinds (doorbell / contact /
4303
+ * lock / …) for the `sensorKinds` device-event condition.
4304
+ *
4305
+ * Each entry carries `parentKind` so the client can group video subs under
4306
+ * their macro and sensor/control kinds under their category. This surface is
4307
+ * served ADDITIVELY on the `nc.getConditionCatalog` bridge response — no cap
4308
+ * method, no codegen — so it ships train-free with an addon deploy.
4309
+ */
4310
+ /** One selectable taxonomy value: a stable kind id + display label + parent. */
4311
+ var NcTaxonomyEntrySchema = zod.z.object({
4312
+ /** Stable kind id (e.g. 'person', 'car', 'audio-scream', 'doorbell'). */
4313
+ kind: zod.z.string(),
4314
+ /** English fallback label (the UI translates via the event-kind i18n key). */
4315
+ label: zod.z.string(),
4316
+ /** Macro/category parent for grouping ('car' → 'vehicle'); null for a top. */
4317
+ parentKind: zod.z.string().nullable()
4318
+ });
4319
+ zod.z.object({
4320
+ videoClasses: zod.z.array(NcTaxonomyEntrySchema),
4321
+ audioKinds: zod.z.array(NcTaxonomyEntrySchema),
4322
+ labels: zod.z.array(NcTaxonomyEntrySchema)
4323
+ });
4324
+ function toEntry(kind, label, parentKind) {
4325
+ return {
4326
+ kind,
4327
+ label,
4328
+ parentKind
4329
+ };
4330
+ }
4331
+ /**
4332
+ * Build the NC taxonomy from `EVENT_TAXONOMY`. Insertion order is preserved
4333
+ * (macros before their subs), which the client relies on for stable grouping.
4334
+ */
4335
+ function buildNcTaxonomy() {
4336
+ const all = Object.values(EVENT_TAXONOMY);
4337
+ return {
4338
+ videoClasses: all.filter((e) => e.category === "detection").map((e) => toEntry(e.kind, e.label, e.parentKind)),
4339
+ audioKinds: all.filter((e) => e.category === "audio" && e.level === "sub").map((e) => toEntry(e.kind, e.label, e.parentKind)),
4340
+ labels: all.filter((e) => e.category === "sensor" || e.category === "control").map((e) => toEntry(e.kind, e.label, e.parentKind))
4341
+ };
4342
+ }
4343
+ Object.freeze(buildNcTaxonomy());
4344
+ /**
4295
4345
  * Error types for the safe expression engine. Two distinct classes so callers
4296
4346
  * can tell a compile-time (grammar) failure from a runtime (evaluation)
4297
4347
  * failure — both are non-fatal to the host: read paths degrade to "skip link".
@@ -12427,106 +12477,6 @@ var addonWidgetsCapability = {
12427
12477
  mode: "singleton",
12428
12478
  methods: { listWidgets: method(zod.z.void(), zod.z.array(EnrichedWidgetMetadataSchema).readonly()) }
12429
12479
  };
12430
- var NotificationRuleConditionsSchema = zod.z.object({
12431
- deviceIds: zod.z.array(zod.z.number()).readonly().optional(),
12432
- classNames: zod.z.array(zod.z.string()).readonly().optional(),
12433
- zoneIds: zod.z.array(zod.z.string()).readonly().optional(),
12434
- minConfidence: zod.z.number().optional(),
12435
- source: zod.z.enum([
12436
- "pipeline",
12437
- "onboard",
12438
- "any"
12439
- ]).optional(),
12440
- schedule: zod.z.object({
12441
- days: zod.z.array(zod.z.number()).readonly(),
12442
- startHour: zod.z.number(),
12443
- endHour: zod.z.number()
12444
- }).optional(),
12445
- cooldownSeconds: zod.z.number().optional(),
12446
- minDwellSeconds: zod.z.number().optional(),
12447
- /** Match against `event.data.eventType` token (e.g. `'press_long'`). When non-empty, only events
12448
- * carrying a matching `data.eventType` string pass this condition. Rules without this field are
12449
- * unaffected (back-compat). Distinct from `rule.eventTypes` which holds EventCategory strings. */
12450
- eventTypeTokens: zod.z.array(zod.z.string()).readonly().optional(),
12451
- /** Match detections whose CLIP image embedding is semantically similar to this free-text
12452
- * description. Requires the embedding-encoder cap to have pre-warmed the text vector.
12453
- * `minSimilarity` is the cosine similarity threshold in [0, 1]. */
12454
- clipDescription: zod.z.object({
12455
- text: zod.z.string().min(1),
12456
- minSimilarity: zod.z.number().min(0).max(1)
12457
- }).optional(),
12458
- /** Match events whose recognized-entity label (face identity name or plate
12459
- * vehicle name, propagated onto `event.data.label`) is one of these values.
12460
- * Empty/absent → unaffected (back-compat). Enables "notify me when <named
12461
- * vehicle/person> is seen". */
12462
- labels: zod.z.array(zod.z.string()).readonly().optional()
12463
- });
12464
- var NotificationRuleTemplateSchema = zod.z.object({
12465
- title: zod.z.string(),
12466
- body: zod.z.string(),
12467
- imageMode: zod.z.enum([
12468
- "crop",
12469
- "annotated",
12470
- "full",
12471
- "none"
12472
- ])
12473
- });
12474
- var NotificationRuleSchema = zod.z.object({
12475
- id: zod.z.string(),
12476
- name: zod.z.string(),
12477
- enabled: zod.z.boolean(),
12478
- eventTypes: zod.z.array(zod.z.string()).readonly(),
12479
- conditions: NotificationRuleConditionsSchema,
12480
- outputs: zod.z.array(zod.z.string()).readonly(),
12481
- template: NotificationRuleTemplateSchema.optional(),
12482
- priority: zod.z.enum([
12483
- "low",
12484
- "normal",
12485
- "high",
12486
- "critical"
12487
- ])
12488
- });
12489
- var NotificationTestResultSchema = zod.z.object({
12490
- ruleId: zod.z.string(),
12491
- eventId: zod.z.string(),
12492
- timestamp: zod.z.number(),
12493
- wouldFire: zod.z.boolean(),
12494
- reason: zod.z.string().optional()
12495
- });
12496
- var NotificationHistoryEntrySchema = zod.z.object({
12497
- id: zod.z.string(),
12498
- ruleId: zod.z.string(),
12499
- ruleName: zod.z.string(),
12500
- eventId: zod.z.string(),
12501
- timestamp: zod.z.number(),
12502
- outputs: zod.z.array(zod.z.string()).readonly(),
12503
- success: zod.z.boolean(),
12504
- error: zod.z.string().optional(),
12505
- deviceId: zod.z.number().optional()
12506
- });
12507
- var NotificationHistoryFilterSchema = zod.z.object({
12508
- ruleId: zod.z.string().optional(),
12509
- deviceId: zod.z.number().optional(),
12510
- from: zod.z.number().optional(),
12511
- to: zod.z.number().optional(),
12512
- limit: zod.z.number().optional()
12513
- });
12514
- var advancedNotifierCapability = {
12515
- name: "advanced-notifier",
12516
- scope: "system",
12517
- mode: "singleton",
12518
- internal: true,
12519
- methods: {
12520
- getRules: method(zod.z.void(), zod.z.object({ rules: zod.z.array(NotificationRuleSchema).readonly() })),
12521
- upsertRule: method(zod.z.object({ rule: NotificationRuleSchema }), zod.z.object({ success: zod.z.literal(true) }), { kind: "mutation" }),
12522
- deleteRule: method(zod.z.object({ ruleId: zod.z.string() }), zod.z.object({ success: zod.z.literal(true) }), { kind: "mutation" }),
12523
- testRule: method(zod.z.object({
12524
- ruleId: zod.z.string(),
12525
- lookbackMinutes: zod.z.number()
12526
- }), zod.z.object({ results: zod.z.array(NotificationTestResultSchema).readonly() }), { kind: "mutation" }),
12527
- getHistory: method(zod.z.object({ filter: NotificationHistoryFilterSchema.optional() }), zod.z.object({ entries: zod.z.array(NotificationHistoryEntrySchema).readonly() }))
12528
- }
12529
- };
12530
12480
  /**
12531
12481
  * Alerts capability — collection-based internal alert system.
12532
12482
  *
@@ -12827,117 +12777,6 @@ var authProviderCapability = {
12827
12777
  mount: { kind: "skip" }
12828
12778
  };
12829
12779
  /**
12830
- * `login-method` — collection cap through which auth addons contribute
12831
- * their pre-auth login surfaces to the login page. This is the SINGLE,
12832
- * generic mechanism that supersedes the dead `auth.listProviders` reader:
12833
- * every auth addon (OIDC, magic-link, WebAuthn/passkey) registers a
12834
- * `login-method` provider and the PUBLIC `auth.listLoginMethods`
12835
- * procedure aggregates them for the unauthenticated login page.
12836
- *
12837
- * A contribution is a discriminated union on `kind`:
12838
- *
12839
- * - `redirect` — a declarative button. The login page renders a generic
12840
- * button that navigates to `startUrl` (an addon-owned HTTP route).
12841
- * Covers OIDC (`/addon/auth-oidc/<id>/start`) and magic-link with
12842
- * ZERO shell-side JS. A future SSO addon plugs in the same way — the
12843
- * login page needs NO change.
12844
- *
12845
- * - `widget` — a Module-Federation widget the login page mounts (via
12846
- * `loadRemoteBundle`) for an in-page ceremony. `auth.listLoginMethods`
12847
- * stamps a public `bundleUrl` from `addonId` + `bundle`. Generic
12848
- * mechanism kept for future use; no shipped addon uses it on the login
12849
- * page (the passkey ceremony below runs natively in the shell instead).
12850
- *
12851
- * - `passkey` — a declarative WebAuthn ceremony the shell renders
12852
- * natively (`@simplewebauthn/browser` lives in `addon-admin-ui`, not in
12853
- * a remotely-loaded bundle). Carries the addon's effective `rpId` /
12854
- * `origin` (from its `resolveRpID()` / `resolveOrigin()`) so the shell
12855
- * can gate visibility (IP-literal origin, hostname/rpId mismatch) WITHOUT
12856
- * fetching any remote code pre-auth. Contribution stays unconditional —
12857
- * enrollment state is never leaked pre-auth; visibility is a shell
12858
- * decision.
12859
- *
12860
- * Every contribution carries a `stage`:
12861
- * - `primary` — shown on the first credentials screen (OIDC /
12862
- * magic-link buttons; a future usernameless passkey).
12863
- * - `second-factor` — shown AFTER the password leg, gated on the
12864
- * returned `factors` (passkey-as-2FA today).
12865
- *
12866
- * `mount: skip` — the cap is read server-side by the core auth router
12867
- * (`registry.getCollection('login-method')`), never mounted as its own
12868
- * tRPC router.
12869
- */
12870
- /** When a login method renders in the two-phase login flow. */
12871
- var LoginStageEnum = zod.z.enum(["primary", "second-factor"]);
12872
- /**
12873
- * A declarative redirect button — the login page navigates to `startUrl`.
12874
- * OIDC and magic-link contribute this; a future SSO addon does too.
12875
- */
12876
- var RedirectLoginMethodSchema = zod.z.object({
12877
- kind: zod.z.literal("redirect"),
12878
- /** Stable id within the login-method set (e.g. `auth-oidc/google`). */
12879
- id: zod.z.string(),
12880
- /** Operator-facing button label. */
12881
- label: zod.z.string(),
12882
- /** lucide-react icon name. */
12883
- icon: zod.z.string().optional(),
12884
- /** Addon-owned HTTP route the button navigates to (GET). */
12885
- startUrl: zod.z.string(),
12886
- stage: LoginStageEnum
12887
- });
12888
- /**
12889
- * A Module-Federation widget the login page mounts for an in-page
12890
- * ceremony. `bundle` + `addonId` let `auth.listLoginMethods` stamp a
12891
- * public `bundleUrl`; `remote` is the MF descriptor `loadRemoteBundle`
12892
- * consumes. No `bundleUrl` here — it is server-stamped on the public
12893
- * output so the addon never encodes the static-route scheme.
12894
- */
12895
- var WidgetLoginMethodSchema = zod.z.object({
12896
- kind: zod.z.literal("widget"),
12897
- /** Stable id within the login-method set (e.g. `auth-webauthn/passkey-login`). */
12898
- id: zod.z.string(),
12899
- /** Owning addon id — drives the public bundle URL + the MF namespace. */
12900
- addonId: zod.z.string(),
12901
- /** Bundle filename inside the addon's dist dir (`remoteEntry.js`). */
12902
- bundle: zod.z.string(),
12903
- /** MF remote descriptor — `{ remoteName, exposedModule, componentKey }`. */
12904
- remote: WidgetRemoteSchema,
12905
- stage: LoginStageEnum
12906
- });
12907
- /**
12908
- * A declarative WebAuthn ceremony the shell renders natively (no remote
12909
- * code). Carries the addon's EFFECTIVE `rpId`/`origin` so the shell can
12910
- * gate visibility (IP-literal origin, hostname/rpId mismatch) before ever
12911
- * showing the button — the contribution itself stays unconditional.
12912
- */
12913
- var PasskeyLoginMethodSchema = zod.z.object({
12914
- kind: zod.z.literal("passkey"),
12915
- /** Stable id within the login-method set (e.g. `auth-webauthn/passkey-direct-login`). */
12916
- id: zod.z.string(),
12917
- /** Operator-facing button label. */
12918
- label: zod.z.string(),
12919
- stage: LoginStageEnum,
12920
- /** Effective WebAuthn RP ID (`resolveRpID()`) — the shell gates visibility on it. */
12921
- rpId: zod.z.string(),
12922
- /** Effective expected origin (`resolveOrigin()`), null when unconfigured. */
12923
- origin: zod.z.string().nullable()
12924
- });
12925
- /** One login-method contribution — redirect button, pre-auth widget, or native passkey ceremony. */
12926
- var LoginMethodContributionSchema = zod.z.discriminatedUnion("kind", [
12927
- RedirectLoginMethodSchema,
12928
- WidgetLoginMethodSchema,
12929
- PasskeyLoginMethodSchema
12930
- ]);
12931
- var loginMethodCapability = {
12932
- name: "login-method",
12933
- scope: "system",
12934
- mode: "collection",
12935
- internal: true,
12936
- methods: { getLoginMethods: method(zod.z.void(), zod.z.array(LoginMethodContributionSchema).readonly()) },
12937
- /** BIG PLAN 2: declarative mount hint — read by `@camstack/system` `buildCapRouters`. */
12938
- mount: { kind: "skip" }
12939
- };
12940
- /**
12941
12780
  * Orchestrator-side destination metadata. The orchestrator computes
12942
12781
  * `id = <addonId>:<subId>` from its provider lookup so consumers
12943
12782
  * (admin UI, restore flow) see one canonical key.
@@ -15077,59 +14916,509 @@ var filesystemBrowseCapability = {
15077
14916
  })
15078
14917
  }
15079
14918
  };
15080
- var LogLevelSchema = zod.z.enum([
15081
- "debug",
15082
- "info",
15083
- "warn",
15084
- "error"
14919
+ /**
14920
+ * Shared LLM generate contracts — imported by BOTH `llm.cap.ts` (consumer
14921
+ * surface) and `llm-runtime.cap.ts` (node-side managed executor) so the two
14922
+ * caps stay wire-compatible without a circular cap→cap import.
14923
+ *
14924
+ * Errors are a discriminated-union RESULT, never thrown: the shape survives
14925
+ * every transport tier structurally, and failed calls still write usage rows.
14926
+ * Token counts only in v1 — no costUsd (operator decision, 2026-07-15).
14927
+ */
14928
+ var LlmUsageSchema = zod.z.object({
14929
+ inputTokens: zod.z.number(),
14930
+ outputTokens: zod.z.number()
14931
+ });
14932
+ var LlmErrorCodeSchema = zod.z.enum([
14933
+ "timeout",
14934
+ "rate-limited",
14935
+ "auth",
14936
+ "refusal",
14937
+ "bad-request",
14938
+ "unavailable",
14939
+ "no-profile",
14940
+ "budget-exceeded",
14941
+ "adapter-error"
15085
14942
  ]);
15086
- var LogEntrySchema = zod.z.object({
15087
- timestamp: zod.z.date(),
15088
- level: LogLevelSchema,
15089
- scope: zod.z.array(zod.z.string()),
15090
- message: zod.z.string(),
15091
- meta: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
15092
- tags: zod.z.record(zod.z.string(), zod.z.string()).optional()
14943
+ var LlmGenerateOkSchema = zod.z.object({
14944
+ ok: zod.z.literal(true),
14945
+ text: zod.z.string(),
14946
+ model: zod.z.string(),
14947
+ usage: LlmUsageSchema,
14948
+ truncated: zod.z.boolean(),
14949
+ latencyMs: zod.z.number()
15093
14950
  });
15094
- var logDestinationCapability = {
15095
- name: "log-destination",
15096
- scope: "system",
15097
- mode: "collection",
15098
- internal: true,
15099
- methods: {
15100
- write: method(LogEntrySchema, zod.z.void(), { kind: "mutation" }),
15101
- query: method(zod.z.object({
15102
- scope: zod.z.array(zod.z.string()).optional(),
15103
- level: LogLevelSchema.optional(),
15104
- since: zod.z.date().optional(),
15105
- until: zod.z.date().optional(),
15106
- limit: zod.z.number().optional(),
15107
- tags: zod.z.record(zod.z.string(), zod.z.string()).optional()
15108
- }), zod.z.array(LogEntrySchema).readonly())
15109
- },
15110
- /** BIG PLAN 2: declarative mount hint — read by `@camstack/system` `buildCapRouters`. */
15111
- mount: { kind: "skip" }
15112
- };
15113
- var CpuBreakdownSchema = zod.z.object({
15114
- total: zod.z.number(),
15115
- user: zod.z.number(),
15116
- system: zod.z.number(),
15117
- irq: zod.z.number(),
15118
- nice: zod.z.number(),
15119
- loadAvg: zod.z.tuple([
15120
- zod.z.number(),
15121
- zod.z.number(),
15122
- zod.z.number()
15123
- ]),
15124
- cores: zod.z.number()
14951
+ var LlmGenerateErrSchema = zod.z.object({
14952
+ ok: zod.z.literal(false),
14953
+ code: LlmErrorCodeSchema,
14954
+ message: zod.z.string(),
14955
+ retryAfterMs: zod.z.number().optional()
15125
14956
  });
15126
- var MemoryInfoSchema = zod.z.object({
15127
- percent: zod.z.number(),
15128
- totalBytes: zod.z.number(),
15129
- usedBytes: zod.z.number(),
15130
- availableBytes: zod.z.number(),
15131
- swapUsedBytes: zod.z.number(),
15132
- swapTotalBytes: zod.z.number()
14957
+ var LlmGenerateResultSchema = zod.z.discriminatedUnion("ok", [LlmGenerateOkSchema, LlmGenerateErrSchema]);
14958
+ /**
14959
+ * `Uint8Array` is the sanctioned binary convention — superjson + the UDS
14960
+ * MsgPack channel round-trip typed arrays (embedding-encoder.cap.ts:29,
14961
+ * notification-output.cap.ts:27-31 precedents).
14962
+ */
14963
+ var LlmImageSchema = zod.z.object({
14964
+ bytes: zod.z.instanceof(Uint8Array),
14965
+ mimeType: zod.z.string()
14966
+ });
14967
+ var LlmGenerateBaseInputSchema = zod.z.object({
14968
+ /** Collection routing (the notification-output posture). */
14969
+ addonId: zod.z.string().optional(),
14970
+ /** Explicit profile; else the resolution chain (spec §3). */
14971
+ profileId: zod.z.string().optional(),
14972
+ /** MANDATORY usage tag: 'ai-summary', 'notifier-rules', 'adhoc-ui', … */
14973
+ consumer: zod.z.string(),
14974
+ system: zod.z.string().optional(),
14975
+ /** v1: single-turn. `messages[]` is a v2 additive field. */
14976
+ prompt: zod.z.string(),
14977
+ /** Structured output — adapter-mapped (response_format / forced tool / responseSchema). */
14978
+ jsonSchema: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
14979
+ /** Per-call override of the profile default. */
14980
+ maxTokens: zod.z.number().int().positive().optional(),
14981
+ temperature: zod.z.number().optional()
14982
+ });
14983
+ /**
14984
+ * `llm-runtime` — node-side managed llama.cpp executor (spec §4). Registered
14985
+ * on EVERY node where `addon-ai` is installed; the hub `llm` provider reaches
14986
+ * a specific node's runtime with `nodePin(profile.runtime.nodeId)` — normal
14987
+ * cap routing, zero bespoke plumbing. `internal: true`: the operator reaches
14988
+ * this only through the `llm` cap's methods.
14989
+ *
14990
+ * One running llama-server child per node in v1 (models are RAM-heavy).
14991
+ * Resource ceiling = llama-server flags + idleStopMinutes ONLY (no RSS
14992
+ * watchdog — operator decision #3).
14993
+ */
14994
+ var ManagedModelRefSchema = zod.z.discriminatedUnion("kind", [
14995
+ zod.z.object({
14996
+ kind: zod.z.literal("catalog"),
14997
+ catalogId: zod.z.string()
14998
+ }),
14999
+ zod.z.object({
15000
+ kind: zod.z.literal("url"),
15001
+ url: zod.z.string(),
15002
+ sha256: zod.z.string().optional()
15003
+ }),
15004
+ zod.z.object({
15005
+ kind: zod.z.literal("path"),
15006
+ path: zod.z.string()
15007
+ })
15008
+ ]);
15009
+ var ManagedRuntimeConfigSchema = zod.z.object({
15010
+ /** WHERE the runtime lives — hub or any agent. */
15011
+ nodeId: zod.z.string(),
15012
+ /** Closed for v1; 'ollama' is a v2 candidate. */
15013
+ engine: zod.z.enum(["llama-cpp"]),
15014
+ model: ManagedModelRefSchema,
15015
+ contextSize: zod.z.number().int().default(4096),
15016
+ /** 0 = CPU-only. */
15017
+ gpuLayers: zod.z.number().int().default(0),
15018
+ /** Default: cpus-2, clamped ≥1 (resolved node-side). */
15019
+ threads: zod.z.number().int().optional(),
15020
+ /** Concurrent slots. */
15021
+ parallel: zod.z.number().int().default(1),
15022
+ /** Else lazy: first generate boots it. */
15023
+ autoStart: zod.z.boolean().default(false),
15024
+ /** 0 = never; frees RAM after quiet periods. */
15025
+ idleStopMinutes: zod.z.number().int().default(30)
15026
+ });
15027
+ var LlmRuntimeStatusSchema = zod.z.object({
15028
+ /** Status is ALWAYS node-qualified. */
15029
+ nodeId: zod.z.string(),
15030
+ state: zod.z.enum([
15031
+ "stopped",
15032
+ "downloading",
15033
+ "starting",
15034
+ "ready",
15035
+ "crashed",
15036
+ "failed"
15037
+ ]),
15038
+ pid: zod.z.number().optional(),
15039
+ port: zod.z.number().optional(),
15040
+ modelPath: zod.z.string().optional(),
15041
+ modelId: zod.z.string().optional(),
15042
+ downloadProgress: zod.z.number().min(0).max(1).optional(),
15043
+ lastError: zod.z.string().optional(),
15044
+ crashesInWindow: zod.z.number(),
15045
+ /** Child RSS (sampled best-effort). */
15046
+ memoryBytes: zod.z.number().optional(),
15047
+ vramBytes: zod.z.number().optional()
15048
+ });
15049
+ var LlmNodeModelSchema = zod.z.object({
15050
+ file: zod.z.string(),
15051
+ sizeBytes: zod.z.number(),
15052
+ catalogId: zod.z.string().optional(),
15053
+ installedAt: zod.z.number().optional()
15054
+ });
15055
+ var LlmRuntimeDiskUsageSchema = zod.z.object({
15056
+ nodeId: zod.z.string(),
15057
+ modelsBytes: zod.z.number(),
15058
+ freeBytes: zod.z.number().optional()
15059
+ });
15060
+ var llmRuntimeCapability = {
15061
+ name: "llm-runtime",
15062
+ scope: "system",
15063
+ mode: "singleton",
15064
+ internal: true,
15065
+ methods: {
15066
+ complete: method(LlmGenerateBaseInputSchema.extend({
15067
+ images: zod.z.array(LlmImageSchema).optional(),
15068
+ runtime: ManagedRuntimeConfigSchema,
15069
+ /** The managed profile's timeout, threaded by the hub provider. */
15070
+ timeoutMs: zod.z.number().int().positive().optional()
15071
+ }), LlmGenerateResultSchema, { kind: "mutation" }),
15072
+ ensureStarted: method(zod.z.object({ runtime: ManagedRuntimeConfigSchema }), LlmRuntimeStatusSchema, {
15073
+ kind: "mutation",
15074
+ auth: "admin"
15075
+ }),
15076
+ stop: method(zod.z.object({}), zod.z.void(), {
15077
+ kind: "mutation",
15078
+ auth: "admin"
15079
+ }),
15080
+ status: method(zod.z.object({}), LlmRuntimeStatusSchema),
15081
+ installModel: method(zod.z.object({ model: ManagedModelRefSchema }), zod.z.void(), {
15082
+ kind: "mutation",
15083
+ auth: "admin"
15084
+ }),
15085
+ deleteModel: method(zod.z.object({ file: zod.z.string() }), zod.z.void(), {
15086
+ kind: "mutation",
15087
+ auth: "admin"
15088
+ }),
15089
+ listLocalModels: method(zod.z.object({}), zod.z.array(LlmNodeModelSchema)),
15090
+ getDiskUsage: method(zod.z.object({}), LlmRuntimeDiskUsageSchema)
15091
+ }
15092
+ };
15093
+ /**
15094
+ * `llm` — consumer-facing LLM surface (spec §1-§3). Collection-mode: array
15095
+ * methods concat-fan across providers; single-row methods route to ONE
15096
+ * provider by the `addonId` in the call input (the notification-output
15097
+ * posture, notification-output.cap.ts:215-250). Provided by `addon-ai`
15098
+ * (hub-placed); the cap stays open for future providers.
15099
+ *
15100
+ * Profiles are ROWS (data), not addons: one row = one usable model endpoint.
15101
+ * `apiKey` is a password field — providers REDACT it on read and merge on
15102
+ * write; a stored key NEVER round-trips to a client.
15103
+ */
15104
+ var LlmProfileKindSchema = zod.z.enum([
15105
+ "openai-compatible",
15106
+ "openai",
15107
+ "anthropic",
15108
+ "google",
15109
+ "managed-local"
15110
+ ]);
15111
+ var LlmProfileSchema = zod.z.object({
15112
+ id: zod.z.string(),
15113
+ name: zod.z.string(),
15114
+ kind: LlmProfileKindSchema,
15115
+ /** Stamped by the provider — keeps the fanned catalog routable. */
15116
+ addonId: zod.z.string(),
15117
+ enabled: zod.z.boolean(),
15118
+ /** Vendor model id, or the managed runtime's loaded model. */
15119
+ model: zod.z.string(),
15120
+ /** Required for openai-compatible; override for cloud kinds. */
15121
+ baseUrl: zod.z.string().optional(),
15122
+ /** ConfigUISchema type:'password' — never round-trips (spec §5). */
15123
+ apiKey: zod.z.string().optional(),
15124
+ supportsVision: zod.z.boolean(),
15125
+ temperature: zod.z.number().min(0).max(2).optional(),
15126
+ maxTokens: zod.z.number().int().positive().optional(),
15127
+ timeoutMs: zod.z.number().int().positive().default(6e4),
15128
+ extraHeaders: zod.z.record(zod.z.string(), zod.z.string()).optional(),
15129
+ /** kind === 'managed-local' only (spec §4). */
15130
+ runtime: ManagedRuntimeConfigSchema.optional()
15131
+ });
15132
+ /** ConfigUISchema tree passed through untyped on the wire (the
15133
+ * notification-output `ConfigSchemaPassthrough` precedent at
15134
+ * notification-output.cap.ts:151); the exported TS type re-tightens it. */
15135
+ var ConfigSchemaPassthrough$1 = zod.z.unknown();
15136
+ var LlmProfileKindDescriptorSchema = zod.z.object({
15137
+ kind: LlmProfileKindSchema,
15138
+ label: zod.z.string(),
15139
+ icon: zod.z.string(),
15140
+ /** Stamped by each provider so the concat-fanned catalog stays routable. */
15141
+ addonId: zod.z.string(),
15142
+ configSchema: ConfigSchemaPassthrough$1
15143
+ });
15144
+ var LlmDefaultSelectorSchema = zod.z.union([zod.z.object({ consumer: zod.z.string() }), zod.z.object({ purpose: zod.z.enum(["text", "vision"]) })]);
15145
+ var LlmDefaultSchema = zod.z.object({
15146
+ selector: LlmDefaultSelectorSchema,
15147
+ profileId: zod.z.string()
15148
+ });
15149
+ /** Server-side rollup row — getUsage never dumps raw call rows (spec §6). */
15150
+ var LlmUsageRollupSchema = zod.z.object({
15151
+ day: zod.z.string(),
15152
+ consumer: zod.z.string(),
15153
+ profileId: zod.z.string(),
15154
+ calls: zod.z.number(),
15155
+ okCalls: zod.z.number(),
15156
+ errorCalls: zod.z.number(),
15157
+ inputTokens: zod.z.number(),
15158
+ outputTokens: zod.z.number(),
15159
+ avgLatencyMs: zod.z.number()
15160
+ });
15161
+ /** LLM-facing view over the reused ModelCatalogEntry mechanism (spec §4.2). */
15162
+ var ManagedModelCatalogEntrySchema = zod.z.object({
15163
+ id: zod.z.string(),
15164
+ label: zod.z.string(),
15165
+ family: zod.z.string(),
15166
+ purpose: zod.z.enum(["text", "vision"]),
15167
+ url: zod.z.string(),
15168
+ sha256: zod.z.string(),
15169
+ sizeBytes: zod.z.number(),
15170
+ quantization: zod.z.string(),
15171
+ /** Load-time guidance shown in the picker. */
15172
+ minRamBytes: zod.z.number(),
15173
+ contextSizeDefault: zod.z.number().int(),
15174
+ /** Vision models: companion projector file. */
15175
+ mmprojUrl: zod.z.string().optional()
15176
+ });
15177
+ var LlmRuntimeNodeSchema = zod.z.object({
15178
+ nodeId: zod.z.string(),
15179
+ reachable: zod.z.boolean(),
15180
+ status: LlmRuntimeStatusSchema.optional(),
15181
+ disk: LlmRuntimeDiskUsageSchema.optional(),
15182
+ error: zod.z.string().optional()
15183
+ });
15184
+ var GenerateVisionInputSchema = LlmGenerateBaseInputSchema.extend({ images: zod.z.array(LlmImageSchema).min(1) });
15185
+ var ProfileRefInputSchema = zod.z.object({
15186
+ addonId: zod.z.string(),
15187
+ profileId: zod.z.string()
15188
+ });
15189
+ var llmCapability = {
15190
+ name: "llm",
15191
+ scope: "system",
15192
+ mode: "collection",
15193
+ internal: false,
15194
+ providerKind: "ai",
15195
+ /** `nodeId` inputs below are DATA (the hub provider pins itself), never routing. */
15196
+ nodeIdMode: "data",
15197
+ methods: {
15198
+ generate: method(LlmGenerateBaseInputSchema, LlmGenerateResultSchema, { kind: "mutation" }),
15199
+ generateVision: method(GenerateVisionInputSchema, LlmGenerateResultSchema, { kind: "mutation" }),
15200
+ listProfileKinds: method(zod.z.object({}), zod.z.array(LlmProfileKindDescriptorSchema)),
15201
+ listProfiles: method(zod.z.object({}), zod.z.array(LlmProfileSchema)),
15202
+ upsertProfile: method(zod.z.object({ profile: LlmProfileSchema }), LlmProfileSchema, {
15203
+ kind: "mutation",
15204
+ auth: "admin"
15205
+ }),
15206
+ deleteProfile: method(ProfileRefInputSchema, zod.z.void(), {
15207
+ kind: "mutation",
15208
+ auth: "admin"
15209
+ }),
15210
+ testProfile: method(ProfileRefInputSchema, LlmGenerateResultSchema, {
15211
+ kind: "mutation",
15212
+ auth: "admin"
15213
+ }),
15214
+ /** Live vendor enumeration (GET /models etc.). */
15215
+ listModels: method(ProfileRefInputSchema, zod.z.array(zod.z.string())),
15216
+ getDefaults: method(zod.z.object({}), zod.z.array(LlmDefaultSchema)),
15217
+ setDefault: method(zod.z.object({
15218
+ selector: LlmDefaultSelectorSchema,
15219
+ profileId: zod.z.string().nullable()
15220
+ }), zod.z.void(), {
15221
+ kind: "mutation",
15222
+ auth: "admin"
15223
+ }),
15224
+ getUsage: method(zod.z.object({
15225
+ since: zod.z.number().optional(),
15226
+ until: zod.z.number().optional(),
15227
+ consumer: zod.z.string().optional(),
15228
+ profileId: zod.z.string().optional()
15229
+ }), zod.z.array(LlmUsageRollupSchema)),
15230
+ listModelCatalog: method(zod.z.object({}), zod.z.array(ManagedModelCatalogEntrySchema)),
15231
+ listRuntimeNodes: method(zod.z.object({}), zod.z.array(LlmRuntimeNodeSchema)),
15232
+ listNodeModels: method(zod.z.object({ nodeId: zod.z.string() }), zod.z.array(LlmNodeModelSchema)),
15233
+ installModel: method(zod.z.object({
15234
+ nodeId: zod.z.string(),
15235
+ model: ManagedModelRefSchema
15236
+ }), zod.z.void(), {
15237
+ kind: "mutation",
15238
+ auth: "admin"
15239
+ }),
15240
+ deleteModel: method(zod.z.object({
15241
+ nodeId: zod.z.string(),
15242
+ file: zod.z.string()
15243
+ }), zod.z.void(), {
15244
+ kind: "mutation",
15245
+ auth: "admin"
15246
+ }),
15247
+ getRuntimeStatus: method(ProfileRefInputSchema, LlmRuntimeStatusSchema),
15248
+ startRuntime: method(ProfileRefInputSchema, LlmRuntimeStatusSchema, {
15249
+ kind: "mutation",
15250
+ auth: "admin"
15251
+ }),
15252
+ stopRuntime: method(ProfileRefInputSchema, zod.z.void(), {
15253
+ kind: "mutation",
15254
+ auth: "admin"
15255
+ })
15256
+ }
15257
+ };
15258
+ var LogLevelSchema = zod.z.enum([
15259
+ "debug",
15260
+ "info",
15261
+ "warn",
15262
+ "error"
15263
+ ]);
15264
+ var LogEntrySchema = zod.z.object({
15265
+ timestamp: zod.z.date(),
15266
+ level: LogLevelSchema,
15267
+ scope: zod.z.array(zod.z.string()),
15268
+ message: zod.z.string(),
15269
+ meta: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
15270
+ tags: zod.z.record(zod.z.string(), zod.z.string()).optional()
15271
+ });
15272
+ var logDestinationCapability = {
15273
+ name: "log-destination",
15274
+ scope: "system",
15275
+ mode: "collection",
15276
+ internal: true,
15277
+ methods: {
15278
+ write: method(LogEntrySchema, zod.z.void(), { kind: "mutation" }),
15279
+ query: method(zod.z.object({
15280
+ scope: zod.z.array(zod.z.string()).optional(),
15281
+ level: LogLevelSchema.optional(),
15282
+ since: zod.z.date().optional(),
15283
+ until: zod.z.date().optional(),
15284
+ limit: zod.z.number().optional(),
15285
+ tags: zod.z.record(zod.z.string(), zod.z.string()).optional()
15286
+ }), zod.z.array(LogEntrySchema).readonly())
15287
+ },
15288
+ /** BIG PLAN 2: declarative mount hint — read by `@camstack/system` `buildCapRouters`. */
15289
+ mount: { kind: "skip" }
15290
+ };
15291
+ /**
15292
+ * `login-method` — collection cap through which auth addons contribute
15293
+ * their pre-auth login surfaces to the login page. This is the SINGLE,
15294
+ * generic mechanism that supersedes the dead `auth.listProviders` reader:
15295
+ * every auth addon (OIDC, magic-link, WebAuthn/passkey) registers a
15296
+ * `login-method` provider and the PUBLIC `auth.listLoginMethods`
15297
+ * procedure aggregates them for the unauthenticated login page.
15298
+ *
15299
+ * A contribution is a discriminated union on `kind`:
15300
+ *
15301
+ * - `redirect` — a declarative button. The login page renders a generic
15302
+ * button that navigates to `startUrl` (an addon-owned HTTP route).
15303
+ * Covers OIDC (`/addon/auth-oidc/<id>/start`) and magic-link with
15304
+ * ZERO shell-side JS. A future SSO addon plugs in the same way — the
15305
+ * login page needs NO change.
15306
+ *
15307
+ * - `widget` — a Module-Federation widget the login page mounts (via
15308
+ * `loadRemoteBundle`) for an in-page ceremony. `auth.listLoginMethods`
15309
+ * stamps a public `bundleUrl` from `addonId` + `bundle`. Generic
15310
+ * mechanism kept for future use; no shipped addon uses it on the login
15311
+ * page (the passkey ceremony below runs natively in the shell instead).
15312
+ *
15313
+ * - `passkey` — a declarative WebAuthn ceremony the shell renders
15314
+ * natively (`@simplewebauthn/browser` lives in `addon-admin-ui`, not in
15315
+ * a remotely-loaded bundle). Carries the addon's effective `rpId` /
15316
+ * `origin` (from its `resolveRpID()` / `resolveOrigin()`) so the shell
15317
+ * can gate visibility (IP-literal origin, hostname/rpId mismatch) WITHOUT
15318
+ * fetching any remote code pre-auth. Contribution stays unconditional —
15319
+ * enrollment state is never leaked pre-auth; visibility is a shell
15320
+ * decision.
15321
+ *
15322
+ * Every contribution carries a `stage`:
15323
+ * - `primary` — shown on the first credentials screen (OIDC /
15324
+ * magic-link buttons; a future usernameless passkey).
15325
+ * - `second-factor` — shown AFTER the password leg, gated on the
15326
+ * returned `factors` (passkey-as-2FA today).
15327
+ *
15328
+ * `mount: skip` — the cap is read server-side by the core auth router
15329
+ * (`registry.getCollection('login-method')`), never mounted as its own
15330
+ * tRPC router.
15331
+ */
15332
+ /** When a login method renders in the two-phase login flow. */
15333
+ var LoginStageEnum = zod.z.enum(["primary", "second-factor"]);
15334
+ /**
15335
+ * A declarative redirect button — the login page navigates to `startUrl`.
15336
+ * OIDC and magic-link contribute this; a future SSO addon does too.
15337
+ */
15338
+ var RedirectLoginMethodSchema = zod.z.object({
15339
+ kind: zod.z.literal("redirect"),
15340
+ /** Stable id within the login-method set (e.g. `auth-oidc/google`). */
15341
+ id: zod.z.string(),
15342
+ /** Operator-facing button label. */
15343
+ label: zod.z.string(),
15344
+ /** lucide-react icon name. */
15345
+ icon: zod.z.string().optional(),
15346
+ /** Addon-owned HTTP route the button navigates to (GET). */
15347
+ startUrl: zod.z.string(),
15348
+ stage: LoginStageEnum
15349
+ });
15350
+ /**
15351
+ * A Module-Federation widget the login page mounts for an in-page
15352
+ * ceremony. `bundle` + `addonId` let `auth.listLoginMethods` stamp a
15353
+ * public `bundleUrl`; `remote` is the MF descriptor `loadRemoteBundle`
15354
+ * consumes. No `bundleUrl` here — it is server-stamped on the public
15355
+ * output so the addon never encodes the static-route scheme.
15356
+ */
15357
+ var WidgetLoginMethodSchema = zod.z.object({
15358
+ kind: zod.z.literal("widget"),
15359
+ /** Stable id within the login-method set (e.g. `auth-webauthn/passkey-login`). */
15360
+ id: zod.z.string(),
15361
+ /** Owning addon id — drives the public bundle URL + the MF namespace. */
15362
+ addonId: zod.z.string(),
15363
+ /** Bundle filename inside the addon's dist dir (`remoteEntry.js`). */
15364
+ bundle: zod.z.string(),
15365
+ /** MF remote descriptor — `{ remoteName, exposedModule, componentKey }`. */
15366
+ remote: WidgetRemoteSchema,
15367
+ stage: LoginStageEnum
15368
+ });
15369
+ /**
15370
+ * A declarative WebAuthn ceremony the shell renders natively (no remote
15371
+ * code). Carries the addon's EFFECTIVE `rpId`/`origin` so the shell can
15372
+ * gate visibility (IP-literal origin, hostname/rpId mismatch) before ever
15373
+ * showing the button — the contribution itself stays unconditional.
15374
+ */
15375
+ var PasskeyLoginMethodSchema = zod.z.object({
15376
+ kind: zod.z.literal("passkey"),
15377
+ /** Stable id within the login-method set (e.g. `auth-webauthn/passkey-direct-login`). */
15378
+ id: zod.z.string(),
15379
+ /** Operator-facing button label. */
15380
+ label: zod.z.string(),
15381
+ stage: LoginStageEnum,
15382
+ /** Effective WebAuthn RP ID (`resolveRpID()`) — the shell gates visibility on it. */
15383
+ rpId: zod.z.string(),
15384
+ /** Effective expected origin (`resolveOrigin()`), null when unconfigured. */
15385
+ origin: zod.z.string().nullable()
15386
+ });
15387
+ /** One login-method contribution — redirect button, pre-auth widget, or native passkey ceremony. */
15388
+ var LoginMethodContributionSchema = zod.z.discriminatedUnion("kind", [
15389
+ RedirectLoginMethodSchema,
15390
+ WidgetLoginMethodSchema,
15391
+ PasskeyLoginMethodSchema
15392
+ ]);
15393
+ var loginMethodCapability = {
15394
+ name: "login-method",
15395
+ scope: "system",
15396
+ mode: "collection",
15397
+ internal: true,
15398
+ methods: { getLoginMethods: method(zod.z.void(), zod.z.array(LoginMethodContributionSchema).readonly()) },
15399
+ /** BIG PLAN 2: declarative mount hint — read by `@camstack/system` `buildCapRouters`. */
15400
+ mount: { kind: "skip" }
15401
+ };
15402
+ var CpuBreakdownSchema = zod.z.object({
15403
+ total: zod.z.number(),
15404
+ user: zod.z.number(),
15405
+ system: zod.z.number(),
15406
+ irq: zod.z.number(),
15407
+ nice: zod.z.number(),
15408
+ loadAvg: zod.z.tuple([
15409
+ zod.z.number(),
15410
+ zod.z.number(),
15411
+ zod.z.number()
15412
+ ]),
15413
+ cores: zod.z.number()
15414
+ });
15415
+ var MemoryInfoSchema = zod.z.object({
15416
+ percent: zod.z.number(),
15417
+ totalBytes: zod.z.number(),
15418
+ usedBytes: zod.z.number(),
15419
+ availableBytes: zod.z.number(),
15420
+ swapUsedBytes: zod.z.number(),
15421
+ swapTotalBytes: zod.z.number()
15133
15422
  });
15134
15423
  var DiskIoSnapshotSchema = zod.z.object({
15135
15424
  readBytes: zod.z.number(),
@@ -15689,14 +15978,14 @@ var TargetKindCapsSchema = zod.z.object({
15689
15978
  * the union is large and not meant for runtime validation here; the exported
15690
15979
  * `TargetKind` type re-tightens `configSchema` to `ConfigUISchema`.
15691
15980
  */
15692
- var ConfigSchemaPassthrough$1 = zod.z.unknown();
15981
+ var ConfigSchemaPassthrough = zod.z.unknown();
15693
15982
  var TargetKindSchema = zod.z.object({
15694
15983
  kind: zod.z.string(),
15695
15984
  label: zod.z.string(),
15696
15985
  icon: zod.z.string(),
15697
15986
  /** Stamped by each provider so the concat-fanned catalog stays routable. */
15698
15987
  addonId: zod.z.string(),
15699
- configSchema: ConfigSchemaPassthrough$1,
15988
+ configSchema: ConfigSchemaPassthrough,
15700
15989
  supportsDiscovery: zod.z.boolean(),
15701
15990
  caps: TargetKindCapsSchema
15702
15991
  });
@@ -15705,400 +15994,580 @@ var TargetKindSchema = zod.z.object({
15705
15994
  * (return a presence marker only) when serving `listTargets` — never
15706
15995
  * round-trip a stored secret to the UI.
15707
15996
  */
15708
- var TargetSchema = zod.z.object({
15709
- id: zod.z.string(),
15710
- name: zod.z.string(),
15711
- kind: zod.z.string(),
15712
- addonId: zod.z.string(),
15713
- enabled: zod.z.boolean(),
15714
- config: zod.z.record(zod.z.string(), zod.z.unknown())
15715
- });
15716
- /** A discovery-surfaced candidate (config is partial + non-secret). */
15717
- var DiscoveredTargetSchema = zod.z.object({
15718
- kind: zod.z.string(),
15719
- suggestedName: zod.z.string(),
15720
- config: zod.z.record(zod.z.string(), zod.z.unknown())
15721
- });
15722
- /** The degrade engine's report — what was resolved / dropped / degraded. */
15723
- var RenderedAsSchema = zod.z.object({
15724
- level: zod.z.string(),
15725
- format: NotificationFormatSchema,
15726
- attachmentsSent: zod.z.number().int().nonnegative(),
15727
- actionsSent: zod.z.number().int().nonnegative(),
15728
- truncated: zod.z.boolean(),
15729
- dropped: zod.z.array(zod.z.string())
15730
- });
15731
- var SendResultSchema = zod.z.object({
15732
- success: zod.z.boolean(),
15733
- error: zod.z.string().optional(),
15734
- renderedAs: RenderedAsSchema.optional()
15735
- });
15736
- /** Same shape as SendResult — kept as a distinct name for the test panel. */
15737
- var TestResultSchema = SendResultSchema;
15738
- var notificationOutputCapability = {
15739
- name: "notification-output",
15740
- scope: "system",
15741
- mode: "collection",
15742
- methods: {
15743
- listTargetKinds: method(zod.z.object({}), zod.z.array(TargetKindSchema)),
15744
- listTargets: method(zod.z.object({}), zod.z.array(TargetSchema)),
15745
- discoverTargets: method(zod.z.object({
15746
- kind: zod.z.string(),
15747
- config: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
15748
- }), zod.z.array(DiscoveredTargetSchema)),
15749
- send: method(zod.z.object({
15750
- targetId: zod.z.string(),
15751
- notification: NotificationSchema
15752
- }), SendResultSchema, { kind: "mutation" }),
15753
- testTarget: method(zod.z.object({
15754
- targetId: zod.z.string(),
15755
- sample: NotificationSchema.optional()
15756
- }), TestResultSchema, { kind: "mutation" }),
15757
- upsertTarget: method(zod.z.object({ target: TargetSchema }), TargetSchema, { kind: "mutation" }),
15758
- deleteTarget: method(zod.z.object({ targetId: zod.z.string() }), zod.z.void(), { kind: "mutation" }),
15759
- setTargetEnabled: method(zod.z.object({
15760
- targetId: zod.z.string(),
15761
- enabled: zod.z.boolean()
15762
- }), zod.z.void(), { kind: "mutation" })
15763
- }
15764
- };
15765
- /**
15766
- * Shared LLM generate contracts — imported by BOTH `llm.cap.ts` (consumer
15767
- * surface) and `llm-runtime.cap.ts` (node-side managed executor) so the two
15768
- * caps stay wire-compatible without a circular cap→cap import.
15769
- *
15770
- * Errors are a discriminated-union RESULT, never thrown: the shape survives
15771
- * every transport tier structurally, and failed calls still write usage rows.
15772
- * Token counts only in v1 — no costUsd (operator decision, 2026-07-15).
15773
- */
15774
- var LlmUsageSchema = zod.z.object({
15775
- inputTokens: zod.z.number(),
15776
- outputTokens: zod.z.number()
15777
- });
15778
- var LlmErrorCodeSchema = zod.z.enum([
15779
- "timeout",
15780
- "rate-limited",
15781
- "auth",
15782
- "refusal",
15783
- "bad-request",
15784
- "unavailable",
15785
- "no-profile",
15786
- "budget-exceeded",
15787
- "adapter-error"
15788
- ]);
15789
- var LlmGenerateOkSchema = zod.z.object({
15790
- ok: zod.z.literal(true),
15791
- text: zod.z.string(),
15792
- model: zod.z.string(),
15793
- usage: LlmUsageSchema,
15794
- truncated: zod.z.boolean(),
15795
- latencyMs: zod.z.number()
15796
- });
15797
- var LlmGenerateErrSchema = zod.z.object({
15798
- ok: zod.z.literal(false),
15799
- code: LlmErrorCodeSchema,
15800
- message: zod.z.string(),
15801
- retryAfterMs: zod.z.number().optional()
15802
- });
15803
- var LlmGenerateResultSchema = zod.z.discriminatedUnion("ok", [LlmGenerateOkSchema, LlmGenerateErrSchema]);
15804
- /**
15805
- * `Uint8Array` is the sanctioned binary convention — superjson + the UDS
15806
- * MsgPack channel round-trip typed arrays (embedding-encoder.cap.ts:29,
15807
- * notification-output.cap.ts:27-31 precedents).
15808
- */
15809
- var LlmImageSchema = zod.z.object({
15810
- bytes: zod.z.instanceof(Uint8Array),
15811
- mimeType: zod.z.string()
15812
- });
15813
- var LlmGenerateBaseInputSchema = zod.z.object({
15814
- /** Collection routing (the notification-output posture). */
15815
- addonId: zod.z.string().optional(),
15816
- /** Explicit profile; else the resolution chain (spec §3). */
15817
- profileId: zod.z.string().optional(),
15818
- /** MANDATORY usage tag: 'ai-summary', 'notifier-rules', 'adhoc-ui', … */
15819
- consumer: zod.z.string(),
15820
- system: zod.z.string().optional(),
15821
- /** v1: single-turn. `messages[]` is a v2 additive field. */
15822
- prompt: zod.z.string(),
15823
- /** Structured output — adapter-mapped (response_format / forced tool / responseSchema). */
15824
- jsonSchema: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
15825
- /** Per-call override of the profile default. */
15826
- maxTokens: zod.z.number().int().positive().optional(),
15827
- temperature: zod.z.number().optional()
15828
- });
15829
- /**
15830
- * `llm-runtime` — node-side managed llama.cpp executor (spec §4). Registered
15831
- * on EVERY node where `addon-ai` is installed; the hub `llm` provider reaches
15832
- * a specific node's runtime with `nodePin(profile.runtime.nodeId)` — normal
15833
- * cap routing, zero bespoke plumbing. `internal: true`: the operator reaches
15834
- * this only through the `llm` cap's methods.
15835
- *
15836
- * One running llama-server child per node in v1 (models are RAM-heavy).
15837
- * Resource ceiling = llama-server flags + idleStopMinutes ONLY (no RSS
15838
- * watchdog — operator decision #3).
15839
- */
15840
- var ManagedModelRefSchema = zod.z.discriminatedUnion("kind", [
15841
- zod.z.object({
15842
- kind: zod.z.literal("catalog"),
15843
- catalogId: zod.z.string()
15844
- }),
15845
- zod.z.object({
15846
- kind: zod.z.literal("url"),
15847
- url: zod.z.string(),
15848
- sha256: zod.z.string().optional()
15849
- }),
15850
- zod.z.object({
15851
- kind: zod.z.literal("path"),
15852
- path: zod.z.string()
15853
- })
15854
- ]);
15855
- var ManagedRuntimeConfigSchema = zod.z.object({
15856
- /** WHERE the runtime lives — hub or any agent. */
15857
- nodeId: zod.z.string(),
15858
- /** Closed for v1; 'ollama' is a v2 candidate. */
15859
- engine: zod.z.enum(["llama-cpp"]),
15860
- model: ManagedModelRefSchema,
15861
- contextSize: zod.z.number().int().default(4096),
15862
- /** 0 = CPU-only. */
15863
- gpuLayers: zod.z.number().int().default(0),
15864
- /** Default: cpus-2, clamped ≥1 (resolved node-side). */
15865
- threads: zod.z.number().int().optional(),
15866
- /** Concurrent slots. */
15867
- parallel: zod.z.number().int().default(1),
15868
- /** Else lazy: first generate boots it. */
15869
- autoStart: zod.z.boolean().default(false),
15870
- /** 0 = never; frees RAM after quiet periods. */
15871
- idleStopMinutes: zod.z.number().int().default(30)
15872
- });
15873
- var LlmRuntimeStatusSchema = zod.z.object({
15874
- /** Status is ALWAYS node-qualified. */
15875
- nodeId: zod.z.string(),
15876
- state: zod.z.enum([
15877
- "stopped",
15878
- "downloading",
15879
- "starting",
15880
- "ready",
15881
- "crashed",
15882
- "failed"
15883
- ]),
15884
- pid: zod.z.number().optional(),
15885
- port: zod.z.number().optional(),
15886
- modelPath: zod.z.string().optional(),
15887
- modelId: zod.z.string().optional(),
15888
- downloadProgress: zod.z.number().min(0).max(1).optional(),
15889
- lastError: zod.z.string().optional(),
15890
- crashesInWindow: zod.z.number(),
15891
- /** Child RSS (sampled best-effort). */
15892
- memoryBytes: zod.z.number().optional(),
15893
- vramBytes: zod.z.number().optional()
15997
+ var TargetSchema = zod.z.object({
15998
+ id: zod.z.string(),
15999
+ name: zod.z.string(),
16000
+ kind: zod.z.string(),
16001
+ addonId: zod.z.string(),
16002
+ enabled: zod.z.boolean(),
16003
+ config: zod.z.record(zod.z.string(), zod.z.unknown())
15894
16004
  });
15895
- var LlmNodeModelSchema = zod.z.object({
15896
- file: zod.z.string(),
15897
- sizeBytes: zod.z.number(),
15898
- catalogId: zod.z.string().optional(),
15899
- installedAt: zod.z.number().optional()
16005
+ /** A discovery-surfaced candidate (config is partial + non-secret). */
16006
+ var DiscoveredTargetSchema = zod.z.object({
16007
+ kind: zod.z.string(),
16008
+ suggestedName: zod.z.string(),
16009
+ config: zod.z.record(zod.z.string(), zod.z.unknown())
15900
16010
  });
15901
- var LlmRuntimeDiskUsageSchema = zod.z.object({
15902
- nodeId: zod.z.string(),
15903
- modelsBytes: zod.z.number(),
15904
- freeBytes: zod.z.number().optional()
16011
+ /** The degrade engine's report — what was resolved / dropped / degraded. */
16012
+ var RenderedAsSchema = zod.z.object({
16013
+ level: zod.z.string(),
16014
+ format: NotificationFormatSchema,
16015
+ attachmentsSent: zod.z.number().int().nonnegative(),
16016
+ actionsSent: zod.z.number().int().nonnegative(),
16017
+ truncated: zod.z.boolean(),
16018
+ dropped: zod.z.array(zod.z.string())
15905
16019
  });
15906
- var llmRuntimeCapability = {
15907
- name: "llm-runtime",
16020
+ var SendResultSchema = zod.z.object({
16021
+ success: zod.z.boolean(),
16022
+ error: zod.z.string().optional(),
16023
+ renderedAs: RenderedAsSchema.optional()
16024
+ });
16025
+ /** Same shape as SendResult — kept as a distinct name for the test panel. */
16026
+ var TestResultSchema = SendResultSchema;
16027
+ var notificationOutputCapability = {
16028
+ name: "notification-output",
15908
16029
  scope: "system",
15909
- mode: "singleton",
15910
- internal: true,
16030
+ mode: "collection",
15911
16031
  methods: {
15912
- complete: method(LlmGenerateBaseInputSchema.extend({
15913
- images: zod.z.array(LlmImageSchema).optional(),
15914
- runtime: ManagedRuntimeConfigSchema,
15915
- /** The managed profile's timeout, threaded by the hub provider. */
15916
- timeoutMs: zod.z.number().int().positive().optional()
15917
- }), LlmGenerateResultSchema, { kind: "mutation" }),
15918
- ensureStarted: method(zod.z.object({ runtime: ManagedRuntimeConfigSchema }), LlmRuntimeStatusSchema, {
15919
- kind: "mutation",
15920
- auth: "admin"
15921
- }),
15922
- stop: method(zod.z.object({}), zod.z.void(), {
15923
- kind: "mutation",
15924
- auth: "admin"
15925
- }),
15926
- status: method(zod.z.object({}), LlmRuntimeStatusSchema),
15927
- installModel: method(zod.z.object({ model: ManagedModelRefSchema }), zod.z.void(), {
15928
- kind: "mutation",
15929
- auth: "admin"
15930
- }),
15931
- deleteModel: method(zod.z.object({ file: zod.z.string() }), zod.z.void(), {
15932
- kind: "mutation",
15933
- auth: "admin"
15934
- }),
15935
- listLocalModels: method(zod.z.object({}), zod.z.array(LlmNodeModelSchema)),
15936
- getDiskUsage: method(zod.z.object({}), LlmRuntimeDiskUsageSchema)
16032
+ listTargetKinds: method(zod.z.object({}), zod.z.array(TargetKindSchema)),
16033
+ listTargets: method(zod.z.object({}), zod.z.array(TargetSchema)),
16034
+ discoverTargets: method(zod.z.object({
16035
+ kind: zod.z.string(),
16036
+ config: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
16037
+ }), zod.z.array(DiscoveredTargetSchema)),
16038
+ send: method(zod.z.object({
16039
+ targetId: zod.z.string(),
16040
+ notification: NotificationSchema
16041
+ }), SendResultSchema, { kind: "mutation" }),
16042
+ testTarget: method(zod.z.object({
16043
+ targetId: zod.z.string(),
16044
+ sample: NotificationSchema.optional()
16045
+ }), TestResultSchema, { kind: "mutation" }),
16046
+ upsertTarget: method(zod.z.object({ target: TargetSchema }), TargetSchema, { kind: "mutation" }),
16047
+ deleteTarget: method(zod.z.object({ targetId: zod.z.string() }), zod.z.void(), { kind: "mutation" }),
16048
+ setTargetEnabled: method(zod.z.object({
16049
+ targetId: zod.z.string(),
16050
+ enabled: zod.z.boolean()
16051
+ }), zod.z.void(), { kind: "mutation" })
15937
16052
  }
15938
16053
  };
15939
16054
  /**
15940
- * `llm`consumer-facing LLM surface (spec §1-§3). Collection-mode: array
15941
- * methods concat-fan across providers; single-row methods route to ONE
15942
- * provider by the `addonId` in the call input (the notification-output
15943
- * posture, notification-output.cap.ts:215-250). Provided by `addon-ai`
15944
- * (hub-placed); the cap stays open for future providers.
15945
- *
15946
- * Profiles are ROWS (data), not addons: one row = one usable model endpoint.
15947
- * `apiKey` is a password field — providers REDACT it on read and merge on
15948
- * write; a stored key NEVER round-trips to a client.
15949
- */
15950
- var LlmProfileKindSchema = zod.z.enum([
15951
- "openai-compatible",
15952
- "openai",
15953
- "anthropic",
15954
- "google",
15955
- "managed-local"
16055
+ * notification-rulesthe Notification Center rule surface (P1 core).
16056
+ *
16057
+ * Spec: `docs/superpowers/specs/2026-07-22-notification-center-requirements.md`
16058
+ * (operator decisions D-1/D-2/D-3 are binding):
16059
+ *
16060
+ * - D-2: rule EVALUATION lives in `addon-post-analysis` (the
16061
+ * `notification-center` module), hooked on the durable persistence
16062
+ * moments (object-event insert, TrackCloser.closeExpired) with a
16063
+ * persisted outbox + retry never the lossy telemetry bus (D8).
16064
+ * - D-3: urgency belongs to the RULE. `delivery: 'immediate'` fires on the
16065
+ * FIRST persisted detection matching the conditions (per-track dedup,
16066
+ * `maxPerTrack` fixed at 1 — see {@link NC_MAX_PER_TRACK_IMMEDIATE});
16067
+ * `delivery: 'track-end'` evaluates the finalized track record at close.
16068
+ * - DISPATCH stays behind `notification-output` (rules reference targets
16069
+ * by id; per-backend params are a passthrough blob capped by the
16070
+ * target kind's own caps/degrade engine).
16071
+ *
16072
+ * P1 scope: admin-authored rules only (`createdBy` stamped from the
16073
+ * server-injected caller identity — the first `caller: 'required'`
16074
+ * adopter). The P1 condition subset is: devices, classes(+exclude),
16075
+ * minConfidence, admin zones (any/all + exclude), weekly schedule
16076
+ * windows, and the optional label/identity/plate matchers. User rules,
16077
+ * private zones, per-recipient fan-out and the wider condition table are
16078
+ * P2+ (see spec §7).
16079
+ *
16080
+ * All schemas here are the single source of truth — `NcRule` etc. are
16081
+ * `z.infer` exports; no duplicate interfaces (the advanced-notifier
16082
+ * schema/interface drift is explicitly not repeated).
16083
+ */
16084
+ /**
16085
+ * D-3: the trigger/urgency of a rule — which persistence moment evaluates it.
16086
+ * The value maps 1:1 onto the evaluated record kind:
16087
+ * - `immediate` ↔ object-event persist (lowest-latency detection burst)
16088
+ * - `track-end` ↔ TrackCloser.closeExpired (finalized track record)
16089
+ * - `device-event` ↔ SensorEventStore insert (doorbell press / sensor state
16090
+ * change of a LINKED device, one row per linked camera)
16091
+ * - `package-event` ↔ PackageDropDetector object-event insert (a `package`
16092
+ * delivery / pick-up)
16093
+ *
16094
+ * `immediate`/`track-end` carry the D-3 urgency semantics; `device-event`/
16095
+ * `package-event` are pure trigger kinds (no urgency dimension). Extending
16096
+ * this one field keeps the schema additive — a rule still declares exactly
16097
+ * one trigger.
16098
+ */
16099
+ var NcDeliverySchema = zod.z.enum([
16100
+ "immediate",
16101
+ "track-end",
16102
+ "device-event",
16103
+ "package-event"
15956
16104
  ]);
15957
- var LlmProfileSchema = zod.z.object({
15958
- id: zod.z.string(),
15959
- name: zod.z.string(),
15960
- kind: LlmProfileKindSchema,
15961
- /** Stamped by the provider — keeps the fanned catalog routable. */
15962
- addonId: zod.z.string(),
15963
- enabled: zod.z.boolean(),
15964
- /** Vendor model id, or the managed runtime's loaded model. */
15965
- model: zod.z.string(),
15966
- /** Required for openai-compatible; override for cloud kinds. */
15967
- baseUrl: zod.z.string().optional(),
15968
- /** ConfigUISchema type:'password' — never round-trips (spec §5). */
15969
- apiKey: zod.z.string().optional(),
15970
- supportsVision: zod.z.boolean(),
15971
- temperature: zod.z.number().min(0).max(2).optional(),
15972
- maxTokens: zod.z.number().int().positive().optional(),
15973
- timeoutMs: zod.z.number().int().positive().default(6e4),
15974
- extraHeaders: zod.z.record(zod.z.string(), zod.z.string()).optional(),
15975
- /** kind === 'managed-local' only (spec §4). */
15976
- runtime: ManagedRuntimeConfigSchema.optional()
16105
+ /** One weekly activation window. `startMinute > endMinute` crosses midnight. */
16106
+ var NcScheduleWindowSchema = zod.z.object({
16107
+ /** Days of week the window STARTS on (0 = Sunday … 6 = Saturday). */
16108
+ days: zod.z.array(zod.z.number().int().min(0).max(6)).min(1),
16109
+ startMinute: zod.z.number().int().min(0).max(1439),
16110
+ endMinute: zod.z.number().int().min(0).max(1439)
16111
+ });
16112
+ /** Weekly schedule OR of windows; absence on the rule = always active. */
16113
+ var NcScheduleSchema = zod.z.object({
16114
+ windows: zod.z.array(NcScheduleWindowSchema).min(1),
16115
+ /** IANA timezone; default = hub host timezone. */
16116
+ timezone: zod.z.string().optional(),
16117
+ /** Active OUTSIDE the windows (e.g. "only outside business hours"). */
16118
+ invert: zod.z.boolean().optional()
16119
+ });
16120
+ /** Fuzzy plate matcher — OCR noise makes exact match useless (spec row 12/13). */
16121
+ var NcPlateMatcherSchema = zod.z.object({
16122
+ values: zod.z.array(zod.z.string().min(1)).min(1),
16123
+ /** Max Levenshtein distance after normalization (uppercase alphanumeric). */
16124
+ maxDistance: zod.z.number().int().min(0).max(3).default(1)
16125
+ });
16126
+ /**
16127
+ * Occupancy condition (DEVICE-EVENT trigger). Fires on a ZoneAnalytics
16128
+ * occupancy edge for a device — optionally narrowed to a single admin
16129
+ * `zoneId` and/or object `className`. `op` selects the edge/threshold:
16130
+ * - `became-occupied` (default) — count crossed 0 → ≥ `count`
16131
+ * - `became-free` — count crossed ≥ `count` → below it
16132
+ * - `>=` / `<=` — count is at/over or at/under `count`
16133
+ * `sustainSeconds` requires the condition hold continuously that long
16134
+ * before firing (debounces flicker; 0 = fire on the first matching edge).
16135
+ * Fail-closed: no ZoneAnalytics snapshot / missing zone / null snapshot ⇒
16136
+ * the condition never matches. Confirmed edge-state survives addon restarts
16137
+ * (declared SQLite collection, reseeded on boot).
16138
+ */
16139
+ var NcOccupancyConditionSchema = zod.z.object({
16140
+ /** Admin zone id to scope the count to; absent = whole-frame occupancy. */
16141
+ zoneId: zod.z.string().optional(),
16142
+ /** Object class to count; absent = any class. */
16143
+ className: zod.z.string().optional(),
16144
+ op: zod.z.enum([
16145
+ "became-occupied",
16146
+ "became-free",
16147
+ ">=",
16148
+ "<="
16149
+ ]).default("became-occupied"),
16150
+ count: zod.z.number().int().min(0).default(1),
16151
+ sustainSeconds: zod.z.number().int().min(0).max(3600).default(15)
16152
+ });
16153
+ /** Admin-zone membership condition (zone IDs as stamped by the ZoneEngine). */
16154
+ var NcZoneConditionSchema = zod.z.object({
16155
+ ids: zod.z.array(zod.z.string().min(1)).min(1),
16156
+ /** Quantifier over `ids` — at least one / every one visited. */
16157
+ match: zod.z.enum(["any", "all"]).default("any")
16158
+ });
16159
+ /**
16160
+ * The P1 condition set — a flat AND of groups; absent group = pass;
16161
+ * membership lists are OR within the list (spec §2.3).
16162
+ */
16163
+ var NcConditionsSchema = zod.z.object({
16164
+ /** Device scope — absent = all devices. */
16165
+ devices: zod.z.array(zod.z.number()).optional(),
16166
+ /** Detector class names (any overlap with the record's class set). */
16167
+ classes: zod.z.array(zod.z.string().min(1)).optional(),
16168
+ /** Veto classes — any overlap fails the rule. */
16169
+ classesExclude: zod.z.array(zod.z.string().min(1)).optional(),
16170
+ /** Minimum detection confidence 0–1 (fails when the record has none). */
16171
+ minConfidence: zod.z.number().min(0).max(1).optional(),
16172
+ /** Admin zone membership over event `zones` / track `zonesVisited`. */
16173
+ zones: NcZoneConditionSchema.optional(),
16174
+ /** Veto zones — any hit fails the rule. */
16175
+ zonesExclude: zod.z.array(zod.z.string().min(1)).optional(),
16176
+ /**
16177
+ * Exact (case-insensitive) match on the record's collapsed `label`
16178
+ * (identity name / plate text / subclass).
16179
+ */
16180
+ labelEquals: zod.z.array(zod.z.string().min(1)).optional(),
16181
+ /**
16182
+ * Identity matcher. P1 boundary: matched against the record's collapsed
16183
+ * `label` (the identity display name propagated by the face pipeline) —
16184
+ * identity-ID matching rides in P2 when identity ids reach the record.
16185
+ */
16186
+ identities: zod.z.array(zod.z.string().min(1)).optional(),
16187
+ /** Fuzzy plate matcher against the record's `label` (plate text). */
16188
+ plates: NcPlateMatcherSchema.optional(),
16189
+ /**
16190
+ * Identity EXCLUDE — mirror of {@link identities} with `notIn` semantics.
16191
+ * Same P1 boundary: matched against the record's collapsed `label` (the
16192
+ * identity display name). A record with NO label passes (nothing to
16193
+ * exclude), unlike the include variant which fails on an absent label.
16194
+ */
16195
+ identitiesExclude: zod.z.array(zod.z.string().min(1)).optional(),
16196
+ /**
16197
+ * Minimum server-computed key-event importance in [0,1] (`Track.importance`).
16198
+ * TRACK-END only: importance is scored at track close, so it does not exist
16199
+ * at immediate / object-event evaluation time (see catalog `appliesTo`). At
16200
+ * close the value is threaded via the close-time info (the `Track` clone is
16201
+ * captured before the DB row is updated, so it would otherwise read stale).
16202
+ * Fails when the record carries no importance (never guess quality — the
16203
+ * `minConfidence` precedent). MVP cut: a single scalar threshold.
16204
+ */
16205
+ minImportance: zod.z.number().min(0).max(1).optional(),
16206
+ /**
16207
+ * Minimum track dwell in SECONDS — `(lastSeen − firstSeen) / 1000`.
16208
+ * TRACK-END only: an `immediate` / object-event subject has no closed
16209
+ * lifespan, so a dwell condition never matches immediate delivery
16210
+ * (documented choice — the object-event record carries no `firstSeen`,
16211
+ * so dwell cannot be computed from what the subject actually carries).
16212
+ */
16213
+ minDwellSeconds: zod.z.number().min(0).optional(),
16214
+ /**
16215
+ * Detection provenance filter. `any` (default / absent) matches every
16216
+ * source; otherwise the subject's source must equal it. Legacy records
16217
+ * with no stamped source are treated as `pipeline`. The union spans both
16218
+ * record kinds — object events carry `pipeline` | `onboard`, synthetic
16219
+ * tracks carry `sensor`.
16220
+ */
16221
+ source: zod.z.enum([
16222
+ "pipeline",
16223
+ "onboard",
16224
+ "sensor",
16225
+ "any"
16226
+ ]).optional(),
16227
+ /**
16228
+ * Minimum identity / plate MATCH confidence in [0,1] — DISTINCT from the
16229
+ * detector `minConfidence` (that gates the object-detection score; this
16230
+ * gates the recognition/OCR match score). Fails when the subject carries
16231
+ * no label-match confidence (never guess). TRACK-END only: the confidence
16232
+ * lives on the recognition result and reaches the subject at track close.
16233
+ *
16234
+ * What it measures precisely (plumbed at track close — the closer threads
16235
+ * the value into `NcTrackClosedInfo.labelConfidence`, the same seam as
16236
+ * `importance`): the BEST recognition match confidence observed for the
16237
+ * label the track carries at close — for a face, the peak cosine similarity
16238
+ * of the ASSIGNED identity (`FaceMatch.score`, reset on an identity switch);
16239
+ * for a plate, the peak OCR read score of the best-held plate
16240
+ * (`plateText.confidence`). When BOTH a face and a plate were recognized on
16241
+ * one track the higher of the two is used. A track that ended with no
16242
+ * confident identity/plate match carries no value, so the condition fails
16243
+ * closed for it (an un-recognized subject).
16244
+ */
16245
+ minLabelConfidence: zod.z.number().min(0).max(1).optional(),
16246
+ /**
16247
+ * DEVICE-EVENT only. Raw device event-type tokens (`EventFire.eventType`,
16248
+ * e.g. a doorbell `press` / `press_long`) — matched case-insensitively
16249
+ * against the token carried on the device-event subject (extracted from the
16250
+ * event-emitter runtime slice's `lastEvent.eventType`). Fails when the
16251
+ * subject carries no token. Doorbell-pulse / passive-sensor kinds emit no
16252
+ * eventType, so gate those with {@link sensorKinds} instead.
16253
+ */
16254
+ eventTypeTokens: zod.z.array(zod.z.string().min(1)).optional(),
16255
+ /**
16256
+ * DEVICE-EVENT only. Sensor/control taxonomy kinds (e.g. `doorbell`,
16257
+ * `contact`, `button`, `device-event`) — matched against the persisted
16258
+ * `SensorEvent.kind` (see `sensor-event-kinds.ts`). Membership is OR.
16259
+ */
16260
+ sensorKinds: zod.z.array(zod.z.string().min(1)).optional(),
16261
+ /**
16262
+ * PACKAGE-EVENT only. Which package phase fires the rule — `delivered`
16263
+ * (a parked parcel appeared), `picked-up` (it departed), or `both`. Fails
16264
+ * when the subject's phase does not match (a subject always carries a phase
16265
+ * on the package-event trigger).
16266
+ */
16267
+ packagePhase: zod.z.enum([
16268
+ "delivered",
16269
+ "picked-up",
16270
+ "both"
16271
+ ]).optional(),
16272
+ /**
16273
+ * PERSONAL-RULE custom zones (viewer-drawn). Inline normalized polygons
16274
+ * (MaskShape vocabulary). A record passes when its bbox overlaps ANY
16275
+ * listed polygon (ZoneEngine membership semantics). Evaluated only when
16276
+ * the subject carries a bbox; absent bbox ⇒ the condition FAILS.
16277
+ */
16278
+ customZones: zod.z.array(MaskPolygonShapeSchema).optional(),
16279
+ /**
16280
+ * DEVICE-EVENT only. ZoneAnalytics occupancy edge — fires when a device's
16281
+ * (optionally zone/class-scoped) occupancy count crosses the configured
16282
+ * threshold and holds for `sustainSeconds`. Fail-closed on missing
16283
+ * substrate (no snapshot / missing zone). See {@link NcOccupancyCondition}.
16284
+ */
16285
+ occupancy: NcOccupancyConditionSchema.optional()
15977
16286
  });
15978
- /** ConfigUISchema tree passed through untyped on the wire (the
15979
- * notification-output `ConfigSchemaPassthrough` precedent at
15980
- * notification-output.cap.ts:151); the exported TS type re-tightens it. */
15981
- var ConfigSchemaPassthrough = zod.z.unknown();
15982
- var LlmProfileKindDescriptorSchema = zod.z.object({
15983
- kind: LlmProfileKindSchema,
15984
- label: zod.z.string(),
15985
- icon: zod.z.string(),
15986
- /** Stamped by each provider so the concat-fanned catalog stays routable. */
15987
- addonId: zod.z.string(),
15988
- configSchema: ConfigSchemaPassthrough
16287
+ /** One delivery target: a `notification-output` Target ref + passthrough params. */
16288
+ var NcRuleTargetSchema = zod.z.object({
16289
+ /** `notification-output` Target id. */
16290
+ targetId: zod.z.string().min(1),
16291
+ /**
16292
+ * Per-backend passthrough. Recognized keys are mapped onto the canonical
16293
+ * Notification (`priority`, `level`, `sound`, `clickUrl`, `ttl`); the
16294
+ * degrade engine drops what the backend can't render.
16295
+ */
16296
+ params: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
15989
16297
  });
15990
- var LlmDefaultSelectorSchema = zod.z.union([zod.z.object({ consumer: zod.z.string() }), zod.z.object({ purpose: zod.z.enum(["text", "vision"]) })]);
15991
- var LlmDefaultSchema = zod.z.object({
15992
- selector: LlmDefaultSelectorSchema,
15993
- profileId: zod.z.string()
16298
+ /**
16299
+ * Media attachment policy (P1 still-image subset).
16300
+ * - `best` — the best AVAILABLE subject image at dispatch time (D-3).
16301
+ * - `best-matching` — the media that explains WHY the rule fired: a rule
16302
+ * matched on identities attaches the subject's `faceCrop`, one matched on
16303
+ * plates attaches the `plateCrop`; a rule with no identity/plate condition
16304
+ * (or when the specific crop is missing) degrades to `best`, then
16305
+ * `keyFrame`, then no attachment — never delaying the send. The matched
16306
+ * condition summary is frozen on the outbox row at enqueue (like the rule
16307
+ * name), so the choice never drifts from the record that fired it.
16308
+ * - `keyFrame` — the clean scene frame (no subject box).
16309
+ * - `none` — no attachment.
16310
+ */
16311
+ var NcMediaPolicySchema = zod.z.object({ attach: zod.z.enum([
16312
+ "best",
16313
+ "best-matching",
16314
+ "keyFrame",
16315
+ "none"
16316
+ ]).default("best") });
16317
+ /** Throttle — cooldown survives restarts (rebuilt from the outbox on boot). */
16318
+ var NcThrottleSchema = zod.z.object({
16319
+ cooldownSec: zod.z.number().int().min(0).max(86400).default(60),
16320
+ /** `rule` = one shared cooldown; `rule-device` = per-camera cooldown. */
16321
+ scope: zod.z.enum(["rule", "rule-device"]).default("rule-device")
16322
+ });
16323
+ /** Client-supplied rule fields (server stamps id/createdBy/createdAt/updatedAt). */
16324
+ var NcRuleInputSchema = zod.z.object({
16325
+ name: zod.z.string().min(1).max(200),
16326
+ enabled: zod.z.boolean().default(true),
16327
+ delivery: NcDeliverySchema,
16328
+ conditions: NcConditionsSchema.default({}),
16329
+ schedule: NcScheduleSchema.optional(),
16330
+ targets: zod.z.array(NcRuleTargetSchema).min(1),
16331
+ media: NcMediaPolicySchema.default({ attach: "best" }),
16332
+ throttle: NcThrottleSchema.default({
16333
+ cooldownSec: 60,
16334
+ scope: "rule-device"
16335
+ }),
16336
+ /** `{{var}}` templating over camera/class/label/zones/confidence/time. */
16337
+ template: zod.z.object({
16338
+ title: zod.z.string().max(500).optional(),
16339
+ body: zod.z.string().max(2e3).optional()
16340
+ }).optional(),
16341
+ /** Canonical notification priority ordinal (1..5); per-target overridable. */
16342
+ priority: zod.z.number().int().min(1).max(5).default(3),
16343
+ /**
16344
+ * Ownership/visibility key. Absent = admin/global rule (unchanged legacy
16345
+ * behaviour, visible to all, read-only in the viewer). Present = personal
16346
+ * rule owned by this userId. Server-stamped; never trusted from a client.
16347
+ */
16348
+ ownerUserId: zod.z.string().optional()
15994
16349
  });
15995
- /** Server-side rollup row — getUsage never dumps raw call rows (spec §6). */
15996
- var LlmUsageRollupSchema = zod.z.object({
15997
- day: zod.z.string(),
15998
- consumer: zod.z.string(),
15999
- profileId: zod.z.string(),
16000
- calls: zod.z.number(),
16001
- okCalls: zod.z.number(),
16002
- errorCalls: zod.z.number(),
16003
- inputTokens: zod.z.number(),
16004
- outputTokens: zod.z.number(),
16005
- avgLatencyMs: zod.z.number()
16350
+ /**
16351
+ * Partial patch for `updateRule` — any subset of the input fields, plus the
16352
+ * persisted-only {@link NcRuleSchema} `disabledTargetIds` set. The latter is
16353
+ * NOT a client-authored input field (it lives on the persisted rule, not the
16354
+ * input), so it is added here explicitly to let the store's per-target opt-out
16355
+ * toggle round-trip through the shared `update` path. Viewer opt-out mutations
16356
+ * still flow through `nc.setRuleTargetEnabled` (owner-checked), never a raw
16357
+ * `updateRule` patch.
16358
+ */
16359
+ var NcRulePatchSchema = NcRuleInputSchema.partial().extend({ disabledTargetIds: zod.z.array(zod.z.string()).optional() });
16360
+ /** A persisted rule. */
16361
+ var NcRuleSchema = NcRuleInputSchema.extend({
16362
+ id: zod.z.string(),
16363
+ /** userId of the admin who created the rule (server-stamped caller). */
16364
+ createdBy: zod.z.string(),
16365
+ createdAt: zod.z.number(),
16366
+ updatedAt: zod.z.number(),
16367
+ /**
16368
+ * Per-target opt-out set. A targetId here is suppressed for THIS rule at
16369
+ * send time. Only a target's OWNER may add/remove its id (server-checked
16370
+ * in `nc.setRuleTargetEnabled`). Defaults to empty.
16371
+ */
16372
+ disabledTargetIds: zod.z.array(zod.z.string()).default([])
16006
16373
  });
16007
- /** LLM-facing view over the reused ModelCatalogEntry mechanism (spec §4.2). */
16008
- var ManagedModelCatalogEntrySchema = zod.z.object({
16374
+ var NcTestResultSchema = zod.z.object({
16375
+ recordId: zod.z.string(),
16376
+ recordKind: zod.z.enum([
16377
+ "object-event",
16378
+ "track",
16379
+ "device-event",
16380
+ "package-event"
16381
+ ]),
16382
+ deviceId: zod.z.number(),
16383
+ timestamp: zod.z.number(),
16384
+ wouldFire: zod.z.boolean(),
16385
+ /** Condition id that failed (first failing group), when `wouldFire` is false. */
16386
+ failedCondition: zod.z.string().optional(),
16387
+ className: zod.z.string().optional(),
16388
+ label: zod.z.string().optional()
16389
+ });
16390
+ var NcConditionDescriptorSchema = zod.z.object({
16391
+ /** Field id inside `NcConditions` (or `'schedule'` for the rule-level group). */
16009
16392
  id: zod.z.string(),
16393
+ group: zod.z.enum([
16394
+ "scope",
16395
+ "class",
16396
+ "zones",
16397
+ "quality",
16398
+ "label",
16399
+ "schedule",
16400
+ "device",
16401
+ "package",
16402
+ "occupancy"
16403
+ ]),
16010
16404
  label: zod.z.string(),
16011
- family: zod.z.string(),
16012
- purpose: zod.z.enum(["text", "vision"]),
16013
- url: zod.z.string(),
16014
- sha256: zod.z.string(),
16015
- sizeBytes: zod.z.number(),
16016
- quantization: zod.z.string(),
16017
- /** Load-time guidance shown in the picker. */
16018
- minRamBytes: zod.z.number(),
16019
- contextSizeDefault: zod.z.number().int(),
16020
- /** Vision models: companion projector file. */
16021
- mmprojUrl: zod.z.string().optional()
16405
+ /** Editor widget the UI renders — never hardcode per-condition forms. */
16406
+ valueType: zod.z.enum([
16407
+ "deviceIdList",
16408
+ "stringList",
16409
+ "number01",
16410
+ "number",
16411
+ "sourceSelect",
16412
+ "zoneSelection",
16413
+ "zoneIdList",
16414
+ "schedule",
16415
+ "plateMatcher",
16416
+ "packagePhase",
16417
+ "polygonDraw",
16418
+ "occupancy"
16419
+ ]),
16420
+ operator: zod.z.enum([
16421
+ "in",
16422
+ "notIn",
16423
+ "anyOf",
16424
+ "allOf",
16425
+ "gte",
16426
+ "fuzzyIn",
16427
+ "withinSchedule"
16428
+ ]),
16429
+ /** Which delivery kinds the condition applies to. */
16430
+ appliesTo: zod.z.array(NcDeliverySchema),
16431
+ phase: zod.z.string(),
16432
+ description: zod.z.string().optional()
16022
16433
  });
16023
- var LlmRuntimeNodeSchema = zod.z.object({
16024
- nodeId: zod.z.string(),
16025
- reachable: zod.z.boolean(),
16026
- status: LlmRuntimeStatusSchema.optional(),
16027
- disk: LlmRuntimeDiskUsageSchema.optional(),
16028
- error: zod.z.string().optional()
16434
+ /**
16435
+ * The delivery lifecycle status of a history row — a straight read of the
16436
+ * durable outbox row's own status (single source of truth):
16437
+ * - `pending` — enqueued, in-flight or retrying with backoff
16438
+ * - `sent` — delivered (terminal)
16439
+ * - `dead` — dead-lettered after exhausting retries / a permanent
16440
+ * backend rejection / a deleted target (terminal; carries
16441
+ * the failure `error`)
16442
+ *
16443
+ * P1 has no `suppressed-quiet-hours` / `snoozed` states — those ride the P2
16444
+ * user dimension (quiet hours / snooze) and are additive when they land.
16445
+ */
16446
+ var NcHistoryStatusSchema = zod.z.enum([
16447
+ "pending",
16448
+ "sent",
16449
+ "dead"
16450
+ ]);
16451
+ /** The evaluated record kind a history row descends from (one per trigger). */
16452
+ var NcHistoryRecordKindSchema = zod.z.enum([
16453
+ "object-event",
16454
+ "track-end",
16455
+ "device-event",
16456
+ "package-event"
16457
+ ]);
16458
+ /** Subject summary frozen on the row at fire time (survives rule/record edits). */
16459
+ var NcHistorySubjectSchema = zod.z.object({
16460
+ className: zod.z.string(),
16461
+ label: zod.z.string().optional(),
16462
+ confidence: zod.z.number().optional(),
16463
+ zones: zod.z.array(zod.z.string()),
16464
+ timestamp: zod.z.number()
16029
16465
  });
16030
- var GenerateVisionInputSchema = LlmGenerateBaseInputSchema.extend({ images: zod.z.array(LlmImageSchema).min(1) });
16031
- var ProfileRefInputSchema = zod.z.object({
16032
- addonId: zod.z.string(),
16033
- profileId: zod.z.string()
16466
+ /**
16467
+ * One delivery-history row. This is a read-only VIEW over the durable
16468
+ * outbox row (single source of truth — the same row the drain loop drives;
16469
+ * NO second write path, so history can never drift from delivery state).
16470
+ * The §3.2 fields map directly: `ruleId`/`targetId`/`deviceId` are columns,
16471
+ * `eventRef` is `recordKind`+`recordId`, `timestamps` are `createdAt`
16472
+ * (fire) / `updatedAt` (last transition), `status` + `error` are the
16473
+ * lifecycle. `ruleName` + `subject` are the intent snapshot frozen at
16474
+ * enqueue. `userId?` (per-recipient history) is P2 — no user dimension in
16475
+ * P1 (admin scope only).
16476
+ */
16477
+ var NcHistoryEntrySchema = zod.z.object({
16478
+ /** Outbox row id — the stable dedup id `ruleId:dedupRef:targetId`. */
16479
+ id: zod.z.string(),
16480
+ ruleId: zod.z.string(),
16481
+ /** Rule name frozen at fire time (outlives a later rename / delete). */
16482
+ ruleName: zod.z.string(),
16483
+ /** The rule urgency/trigger that produced this delivery. */
16484
+ delivery: NcDeliverySchema,
16485
+ targetId: zod.z.string(),
16486
+ deviceId: zod.z.number(),
16487
+ recordKind: NcHistoryRecordKindSchema,
16488
+ /** Event / track ref of the evaluated record (§3.2 `eventRef`). */
16489
+ recordId: zod.z.string(),
16490
+ /** Present for track-scoped deliveries (object-event / track-end). */
16491
+ trackId: zod.z.string().optional(),
16492
+ status: NcHistoryStatusSchema,
16493
+ /** Delivery attempts made so far. */
16494
+ attempts: zod.z.number().int(),
16495
+ /** Fire time (outbox enqueue). */
16496
+ createdAt: zod.z.number(),
16497
+ /** Last transition time (terminal for sent / dead). */
16498
+ updatedAt: zod.z.number(),
16499
+ /** Failure detail — present on a `dead` row. */
16500
+ error: zod.z.string().optional(),
16501
+ subject: NcHistorySubjectSchema
16034
16502
  });
16035
- var llmCapability = {
16036
- name: "llm",
16037
- scope: "system",
16038
- mode: "collection",
16039
- internal: false,
16040
- providerKind: "ai",
16041
- /** `nodeId` inputs below are DATA (the hub provider pins itself), never routing. */
16042
- nodeIdMode: "data",
16503
+ /**
16504
+ * Query filter for `getHistory` (spec §4.2). Every field is a narrowing
16505
+ * AND; absent = unbounded on that axis. `since`/`until` bound the fire time
16506
+ * (`createdAt`, epoch ms, inclusive). `limit` is clamped to
16507
+ * {@link NC_HISTORY_LIMIT_MAX}. `userId` (per-recipient filtering) is P2.
16508
+ */
16509
+ var NcHistoryFilterSchema = zod.z.object({
16510
+ ruleId: zod.z.string().optional(),
16511
+ deviceId: zod.z.number().optional(),
16512
+ status: NcHistoryStatusSchema.optional(),
16513
+ since: zod.z.number().optional(),
16514
+ until: zod.z.number().optional(),
16515
+ limit: zod.z.number().int().min(1).max(500).default(100)
16516
+ });
16517
+ var notificationRulesCapability = {
16518
+ name: "notification-rules",
16519
+ scope: "system",
16520
+ mode: "singleton",
16043
16521
  methods: {
16044
- generate: method(LlmGenerateBaseInputSchema, LlmGenerateResultSchema, { kind: "mutation" }),
16045
- generateVision: method(GenerateVisionInputSchema, LlmGenerateResultSchema, { kind: "mutation" }),
16046
- listProfileKinds: method(zod.z.object({}), zod.z.array(LlmProfileKindDescriptorSchema)),
16047
- listProfiles: method(zod.z.object({}), zod.z.array(LlmProfileSchema)),
16048
- upsertProfile: method(zod.z.object({ profile: LlmProfileSchema }), LlmProfileSchema, {
16049
- kind: "mutation",
16050
- auth: "admin"
16051
- }),
16052
- deleteProfile: method(ProfileRefInputSchema, zod.z.void(), {
16053
- kind: "mutation",
16054
- auth: "admin"
16055
- }),
16056
- testProfile: method(ProfileRefInputSchema, LlmGenerateResultSchema, {
16522
+ listRules: method(zod.z.object({}), zod.z.object({ rules: zod.z.array(NcRuleSchema) }), { auth: "admin" }),
16523
+ getRule: method(zod.z.object({ ruleId: zod.z.string() }), zod.z.object({ rule: NcRuleSchema.nullable() }), { auth: "admin" }),
16524
+ createRule: method(zod.z.object({ rule: NcRuleInputSchema }), zod.z.object({ rule: NcRuleSchema }), {
16057
16525
  kind: "mutation",
16058
- auth: "admin"
16526
+ auth: "admin",
16527
+ caller: "required"
16059
16528
  }),
16060
- /** Live vendor enumeration (GET /models etc.). */
16061
- listModels: method(ProfileRefInputSchema, zod.z.array(zod.z.string())),
16062
- getDefaults: method(zod.z.object({}), zod.z.array(LlmDefaultSchema)),
16063
- setDefault: method(zod.z.object({
16064
- selector: LlmDefaultSelectorSchema,
16065
- profileId: zod.z.string().nullable()
16066
- }), zod.z.void(), {
16529
+ updateRule: method(zod.z.object({
16530
+ ruleId: zod.z.string(),
16531
+ patch: NcRulePatchSchema
16532
+ }), zod.z.object({ rule: NcRuleSchema }), {
16067
16533
  kind: "mutation",
16068
- auth: "admin"
16534
+ auth: "admin",
16535
+ caller: "required"
16069
16536
  }),
16070
- getUsage: method(zod.z.object({
16071
- since: zod.z.number().optional(),
16072
- until: zod.z.number().optional(),
16073
- consumer: zod.z.string().optional(),
16074
- profileId: zod.z.string().optional()
16075
- }), zod.z.array(LlmUsageRollupSchema)),
16076
- listModelCatalog: method(zod.z.object({}), zod.z.array(ManagedModelCatalogEntrySchema)),
16077
- listRuntimeNodes: method(zod.z.object({}), zod.z.array(LlmRuntimeNodeSchema)),
16078
- listNodeModels: method(zod.z.object({ nodeId: zod.z.string() }), zod.z.array(LlmNodeModelSchema)),
16079
- installModel: method(zod.z.object({
16080
- nodeId: zod.z.string(),
16081
- model: ManagedModelRefSchema
16082
- }), zod.z.void(), {
16537
+ deleteRule: method(zod.z.object({ ruleId: zod.z.string() }), zod.z.object({ success: zod.z.literal(true) }), {
16083
16538
  kind: "mutation",
16084
16539
  auth: "admin"
16085
16540
  }),
16086
- deleteModel: method(zod.z.object({
16087
- nodeId: zod.z.string(),
16088
- file: zod.z.string()
16089
- }), zod.z.void(), {
16541
+ setRuleEnabled: method(zod.z.object({
16542
+ ruleId: zod.z.string(),
16543
+ enabled: zod.z.boolean()
16544
+ }), zod.z.object({ success: zod.z.literal(true) }), {
16090
16545
  kind: "mutation",
16091
16546
  auth: "admin"
16092
16547
  }),
16093
- getRuntimeStatus: method(ProfileRefInputSchema, LlmRuntimeStatusSchema),
16094
- startRuntime: method(ProfileRefInputSchema, LlmRuntimeStatusSchema, {
16548
+ /**
16549
+ * Dry-run a rule against recently persisted records (object events for
16550
+ * `immediate`, closed tracks for `track-end`). Mutation kind only to
16551
+ * carry the full rule object safely; no side effects.
16552
+ */
16553
+ testRule: method(zod.z.object({
16554
+ rule: NcRuleInputSchema,
16555
+ lookbackMinutes: zod.z.number().int().min(1).max(1440).default(60)
16556
+ }), zod.z.object({ results: zod.z.array(NcTestResultSchema) }), {
16095
16557
  kind: "mutation",
16096
16558
  auth: "admin"
16097
16559
  }),
16098
- stopRuntime: method(ProfileRefInputSchema, zod.z.void(), {
16099
- kind: "mutation",
16100
- auth: "admin"
16101
- })
16560
+ getConditionCatalog: method(zod.z.object({}), zod.z.object({ catalog: zod.z.array(NcConditionDescriptorSchema) })),
16561
+ /**
16562
+ * Queryable delivery history — a read-only view over the durable outbox
16563
+ * (fired rule, subject summary, target, status, timestamps, error on a
16564
+ * dead row). Newest-first, bounded by `filter.limit`. Retention follows
16565
+ * the outbox's own terminal-row prune horizon (no separate history
16566
+ * horizon — single collection, single source of truth). Admin-only in
16567
+ * P1 (no user dimension); the P2 viewer History screen adds per-caller
16568
+ * scoping on the same method.
16569
+ */
16570
+ getHistory: method(zod.z.object({ filter: NcHistoryFilterSchema.default({ limit: 100 }) }), zod.z.object({ entries: zod.z.array(NcHistoryEntrySchema) }), { auth: "admin" })
16102
16571
  }
16103
16572
  };
16104
16573
  /**
@@ -16971,76 +17440,6 @@ var pipelineAnalyticsCapability = {
16971
17440
  }) }
16972
17441
  }
16973
17442
  };
16974
- /**
16975
- * Cap → event-kind mapping for the SENSOR / CONTROL cap families — the table
16976
- * `pipeline-analytics.listEventKinds` uses to turn a linked device's bound
16977
- * caps into per-camera event-kind descriptors.
16978
- *
16979
- * The descriptor DATA (color / iconId / labelKey / parentKind / category)
16980
- * is NOT duplicated here — every entry is derived from the single
16981
- * `EVENT_TAXONOMY` dictionary (`catalogs/event-taxonomy.ts`). This file owns
16982
- * ONLY the cap-name → taxonomy-kind mapping. Adding a new eventful sensor /
16983
- * control cap means adding one line here (and a taxonomy entry); the anti-
16984
- * drift guard `scripts/check-event-kind-coverage.ts` fails the build if an
16985
- * eventful cap is missing.
16986
- */
16987
- /** Map a taxonomy `iconId` onto the legacy closed `EventKindIcon` enum. */
16988
- var LEGACY_ICON = {
16989
- motion: "motion",
16990
- audio: "audio",
16991
- person: "person",
16992
- vehicle: "vehicle",
16993
- animal: "animal",
16994
- package: "package",
16995
- door: "door",
16996
- pir: "pir",
16997
- smoke: "smoke",
16998
- water: "water",
16999
- button: "button",
17000
- generic: "generic",
17001
- gas: "smoke",
17002
- vibration: "generic",
17003
- tamper: "generic",
17004
- presence: "person",
17005
- lock: "generic",
17006
- siren: "generic",
17007
- switch: "generic",
17008
- doorbell: "button"
17009
- };
17010
- function legacyIcon(iconId) {
17011
- return LEGACY_ICON[iconId] ?? "generic";
17012
- }
17013
- /**
17014
- * Cap name → taxonomy kind id. Covers EVERY eventful sensor / control cap.
17015
- * The anti-drift guard cross-checks this against the eventful caps declared
17016
- * in `packages/types/src/capabilities/*.cap.ts`.
17017
- */
17018
- var CAP_TO_KIND = {
17019
- contact: "contact",
17020
- motion: "motion-sensor",
17021
- smoke: "smoke",
17022
- flood: "flood",
17023
- gas: "gas",
17024
- "carbon-monoxide": "carbon-monoxide",
17025
- vibration: "vibration",
17026
- tamper: "tamper",
17027
- presence: "presence",
17028
- "enum-sensor": "enum-sensor",
17029
- "event-emitter": "device-event",
17030
- "lock-control": "lock",
17031
- switch: "switch",
17032
- button: "button",
17033
- doorbell: "doorbell"
17034
- };
17035
- function buildDescriptor(capName, kind) {
17036
- const t = EVENT_TAXONOMY[kind];
17037
- if (t === void 0) throw new Error(`EVENT_KIND_BY_CAP: cap '${capName}' maps to unknown taxonomy kind '${kind}'`);
17038
- return {
17039
- ...t,
17040
- icon: legacyIcon(t.iconId)
17041
- };
17042
- }
17043
- Object.freeze(Object.fromEntries(Object.entries(CAP_TO_KIND).map(([capName, kind]) => [capName, buildDescriptor(capName, kind)])));
17044
17443
  var CameraPipelineConfigSchema = zod.z.object({
17045
17444
  engine: PipelineEngineChoiceSchema.optional(),
17046
17445
  steps: zod.z.array(PipelineStepInputSchema).readonly(),
@@ -17796,6 +18195,76 @@ var pipelineOrchestratorCapability = {
17796
18195
  }
17797
18196
  };
17798
18197
  /**
18198
+ * Cap → event-kind mapping for the SENSOR / CONTROL cap families — the table
18199
+ * `pipeline-analytics.listEventKinds` uses to turn a linked device's bound
18200
+ * caps into per-camera event-kind descriptors.
18201
+ *
18202
+ * The descriptor DATA (color / iconId / labelKey / parentKind / category)
18203
+ * is NOT duplicated here — every entry is derived from the single
18204
+ * `EVENT_TAXONOMY` dictionary (`catalogs/event-taxonomy.ts`). This file owns
18205
+ * ONLY the cap-name → taxonomy-kind mapping. Adding a new eventful sensor /
18206
+ * control cap means adding one line here (and a taxonomy entry); the anti-
18207
+ * drift guard `scripts/check-event-kind-coverage.ts` fails the build if an
18208
+ * eventful cap is missing.
18209
+ */
18210
+ /** Map a taxonomy `iconId` onto the legacy closed `EventKindIcon` enum. */
18211
+ var LEGACY_ICON = {
18212
+ motion: "motion",
18213
+ audio: "audio",
18214
+ person: "person",
18215
+ vehicle: "vehicle",
18216
+ animal: "animal",
18217
+ package: "package",
18218
+ door: "door",
18219
+ pir: "pir",
18220
+ smoke: "smoke",
18221
+ water: "water",
18222
+ button: "button",
18223
+ generic: "generic",
18224
+ gas: "smoke",
18225
+ vibration: "generic",
18226
+ tamper: "generic",
18227
+ presence: "person",
18228
+ lock: "generic",
18229
+ siren: "generic",
18230
+ switch: "generic",
18231
+ doorbell: "button"
18232
+ };
18233
+ function legacyIcon(iconId) {
18234
+ return LEGACY_ICON[iconId] ?? "generic";
18235
+ }
18236
+ /**
18237
+ * Cap name → taxonomy kind id. Covers EVERY eventful sensor / control cap.
18238
+ * The anti-drift guard cross-checks this against the eventful caps declared
18239
+ * in `packages/types/src/capabilities/*.cap.ts`.
18240
+ */
18241
+ var CAP_TO_KIND = {
18242
+ contact: "contact",
18243
+ motion: "motion-sensor",
18244
+ smoke: "smoke",
18245
+ flood: "flood",
18246
+ gas: "gas",
18247
+ "carbon-monoxide": "carbon-monoxide",
18248
+ vibration: "vibration",
18249
+ tamper: "tamper",
18250
+ presence: "presence",
18251
+ "enum-sensor": "enum-sensor",
18252
+ "event-emitter": "device-event",
18253
+ "lock-control": "lock",
18254
+ switch: "switch",
18255
+ button: "button",
18256
+ doorbell: "doorbell"
18257
+ };
18258
+ function buildDescriptor(capName, kind) {
18259
+ const t = EVENT_TAXONOMY[kind];
18260
+ if (t === void 0) throw new Error(`EVENT_KIND_BY_CAP: cap '${capName}' maps to unknown taxonomy kind '${kind}'`);
18261
+ return {
18262
+ ...t,
18263
+ icon: legacyIcon(t.iconId)
18264
+ };
18265
+ }
18266
+ Object.freeze(Object.fromEntries(Object.entries(CAP_TO_KIND).map(([capName, kind]) => [capName, buildDescriptor(capName, kind)])));
18267
+ /**
17799
18268
  * server-management — per-NODE singleton capability for a node's ROOT
17800
18269
  * package lifecycle (runtime-updatable node packages).
17801
18270
  *
@@ -19923,7 +20392,28 @@ var FaceInfoSchema = zod.z.object({
19923
20392
  * (`/addon/<addonId>/event-media/<keyFrameMediaKey>`). Absent when the
19924
20393
  * track produced no key frame (e.g. native/onboard source) — the UI falls
19925
20394
  * back to the inline `base64` face crop. */
19926
- keyFrameMediaKey: zod.z.string().optional()
20395
+ keyFrameMediaKey: zod.z.string().optional(),
20396
+ /** Winning identity-match cosine (0..1) for this face's track, when an
20397
+ * identity was auto-confirmed. Lets the UI surface WHY a face was assigned
20398
+ * (confidence badge / low-confidence audit). Absent on legacy rows and on
20399
+ * faces that were never auto-recognized. */
20400
+ bestMatchScore: zod.z.number().optional(),
20401
+ /** Native-scale face short side (px) at recognition time, when the runner
20402
+ * measured it. Lets the UI flag low-resolution auto-assignments. Absent on
20403
+ * legacy rows / runners that reported no native measure. */
20404
+ nativeFaceShortSidePx: zod.z.number().optional(),
20405
+ /** SUGGESTED identity for this face — a plausible-but-not-confident match that
20406
+ * MISSED auto-assignment (cosine in the suggestion band, or above threshold
20407
+ * but blocked only by the recognition size floor). Mutually exclusive with
20408
+ * `recognizedIdentityId` (a suggestion is NEVER an assignment): the face stays
20409
+ * UNASSIGNED and everything else keeps treating it as unrecognized — the UI
20410
+ * merely offers a one-tap "is this <name>?" confirm. Absent on legacy rows and
20411
+ * on faces that were auto-assigned or below the suggestion band. (2026-07-24) */
20412
+ suggestedIdentityId: zod.z.string().optional(),
20413
+ /** Peak identity-match cosine (0..1) for `suggestedIdentityId`, captured at the
20414
+ * same moment as `bestMatchScore` (track peak, at close). Lets the UI rank /
20415
+ * badge suggestion confidence. Present iff `suggestedIdentityId` is. (2026-07-24) */
20416
+ suggestedMatchScore: zod.z.number().optional()
19927
20417
  });
19928
20418
  var FaceFilterEnum = zod.z.enum([
19929
20419
  "unassigned",
@@ -22529,7 +23019,6 @@ var ALL_CAPABILITY_DEFINITIONS = [
22529
23019
  addonWidgetsSourceCapability,
22530
23020
  addonsCapability,
22531
23021
  adminUiCapability,
22532
- advancedNotifierCapability,
22533
23022
  airQualitySensorCapability,
22534
23023
  alarmPanelCapability,
22535
23024
  alertsCapability,
@@ -22608,6 +23097,7 @@ var ALL_CAPABILITY_DEFINITIONS = [
22608
23097
  networkQualityCapability,
22609
23098
  nodesCapability,
22610
23099
  notificationOutputCapability,
23100
+ notificationRulesCapability,
22611
23101
  notifierCapability,
22612
23102
  numericSensorCapability,
22613
23103
  oauthIntegrationCapability,
@@ -23015,36 +23505,6 @@ var METHOD_ACCESS_MAP = Object.freeze({
23015
23505
  addonId: null,
23016
23506
  access: "view"
23017
23507
  },
23018
- "advancedNotifier.deleteRule": {
23019
- capName: "advanced-notifier",
23020
- capScope: "system",
23021
- addonId: null,
23022
- access: "delete"
23023
- },
23024
- "advancedNotifier.getHistory": {
23025
- capName: "advanced-notifier",
23026
- capScope: "system",
23027
- addonId: null,
23028
- access: "view"
23029
- },
23030
- "advancedNotifier.getRules": {
23031
- capName: "advanced-notifier",
23032
- capScope: "system",
23033
- addonId: null,
23034
- access: "view"
23035
- },
23036
- "advancedNotifier.testRule": {
23037
- capName: "advanced-notifier",
23038
- capScope: "system",
23039
- addonId: null,
23040
- access: "create"
23041
- },
23042
- "advancedNotifier.upsertRule": {
23043
- capName: "advanced-notifier",
23044
- capScope: "system",
23045
- addonId: null,
23046
- access: "create"
23047
- },
23048
23508
  "alarmPanel.arm": {
23049
23509
  capName: "alarm-panel",
23050
23510
  capScope: "device",
@@ -25349,6 +25809,60 @@ var METHOD_ACCESS_MAP = Object.freeze({
25349
25809
  addonId: null,
25350
25810
  access: "create"
25351
25811
  },
25812
+ "notificationRules.createRule": {
25813
+ capName: "notification-rules",
25814
+ capScope: "system",
25815
+ addonId: null,
25816
+ access: "create"
25817
+ },
25818
+ "notificationRules.deleteRule": {
25819
+ capName: "notification-rules",
25820
+ capScope: "system",
25821
+ addonId: null,
25822
+ access: "delete"
25823
+ },
25824
+ "notificationRules.getConditionCatalog": {
25825
+ capName: "notification-rules",
25826
+ capScope: "system",
25827
+ addonId: null,
25828
+ access: "view"
25829
+ },
25830
+ "notificationRules.getHistory": {
25831
+ capName: "notification-rules",
25832
+ capScope: "system",
25833
+ addonId: null,
25834
+ access: "view"
25835
+ },
25836
+ "notificationRules.getRule": {
25837
+ capName: "notification-rules",
25838
+ capScope: "system",
25839
+ addonId: null,
25840
+ access: "view"
25841
+ },
25842
+ "notificationRules.listRules": {
25843
+ capName: "notification-rules",
25844
+ capScope: "system",
25845
+ addonId: null,
25846
+ access: "view"
25847
+ },
25848
+ "notificationRules.setRuleEnabled": {
25849
+ capName: "notification-rules",
25850
+ capScope: "system",
25851
+ addonId: null,
25852
+ access: "create"
25853
+ },
25854
+ "notificationRules.testRule": {
25855
+ capName: "notification-rules",
25856
+ capScope: "system",
25857
+ addonId: null,
25858
+ access: "create"
25859
+ },
25860
+ "notificationRules.updateRule": {
25861
+ capName: "notification-rules",
25862
+ capScope: "system",
25863
+ addonId: null,
25864
+ access: "create"
25865
+ },
25352
25866
  "notifier.cancel": {
25353
25867
  capName: "notifier",
25354
25868
  capScope: "device",