@camstack/system 1.2.6 → 1.2.8

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 (48) hide show
  1. package/dist/addon-runner.js +2 -2
  2. package/dist/addon-runner.mjs +2 -2
  3. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  4. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  5. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  6. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  7. package/dist/builtins/alerts/alerts.addon.js +1 -1
  8. package/dist/builtins/alerts/alerts.addon.mjs +1 -1
  9. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +1 -1
  10. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
  11. package/dist/builtins/console-logging/index.js +1 -1
  12. package/dist/builtins/console-logging/index.mjs +1 -1
  13. package/dist/builtins/device-manager/device-manager.addon.js +1 -1
  14. package/dist/builtins/device-manager/device-manager.addon.mjs +1 -1
  15. package/dist/builtins/doorbell/virtual-doorbell.addon.js +1 -1
  16. package/dist/builtins/doorbell/virtual-doorbell.addon.mjs +1 -1
  17. package/dist/builtins/hub-forwarder/index.js +1 -1
  18. package/dist/builtins/hub-forwarder/index.mjs +1 -1
  19. package/dist/builtins/local-auth/local-auth.addon.js +1 -1
  20. package/dist/builtins/local-auth/local-auth.addon.mjs +1 -1
  21. package/dist/builtins/local-network/local-network.addon.js +1 -1
  22. package/dist/builtins/local-network/local-network.addon.mjs +1 -1
  23. package/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  24. package/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  25. package/dist/builtins/platform-probe/index.js +1 -1
  26. package/dist/builtins/platform-probe/index.mjs +1 -1
  27. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  28. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  29. package/dist/builtins/snapshot/index.js +1 -1
  30. package/dist/builtins/snapshot/index.mjs +1 -1
  31. package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  32. package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  33. package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +1 -1
  34. package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +1 -1
  35. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  36. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  37. package/dist/builtins/system-config/system-config.addon.js +1 -1
  38. package/dist/builtins/system-config/system-config.addon.mjs +1 -1
  39. package/dist/builtins/winston-logging/index.js +1 -1
  40. package/dist/builtins/winston-logging/index.mjs +1 -1
  41. package/dist/{dist-DIlYZWEp.js → dist-CdgScQ3H.js} +328 -3
  42. package/dist/{dist-aTevP3Nh.mjs → dist-CxM20CkF.mjs} +328 -3
  43. package/dist/index.js +56 -6
  44. package/dist/index.mjs +56 -6
  45. package/dist/kernel/cap-router-builder.d.ts +18 -1
  46. package/dist/{manifest-python-deps-BznC09O4.js → manifest-python-deps-CUHn5wqq.js} +1 -1
  47. package/dist/{manifest-python-deps-Czja13st.mjs → manifest-python-deps-CcW0WpfS.mjs} +1 -1
  48. package/package.json +1 -1
@@ -2702,7 +2702,6 @@ function expandCapMethods(def) {
2702
2702
  };
2703
2703
  return out;
2704
2704
  }
2705
- /** Shorthand to define a method schema */
2706
2705
  function method(input, output, options) {
2707
2706
  return {
2708
2707
  input,
@@ -2710,6 +2709,7 @@ function method(input, output, options) {
2710
2709
  kind: options?.kind ?? "query",
2711
2710
  auth: options?.auth ?? "protected",
2712
2711
  ...options?.access !== void 0 ? { access: options.access } : {},
2712
+ ...options?.caller !== void 0 ? { caller: options.caller } : {},
2713
2713
  timeoutMs: options?.timeoutMs
2714
2714
  };
2715
2715
  }
@@ -8365,6 +8365,22 @@ var CameraMetricsSchema = z.object({
8365
8365
  ])
8366
8366
  });
8367
8367
  var CameraMetricsWithDeviceIdSchema = CameraMetricsSchema.extend({ deviceId: z.number() });
8368
+ /**
8369
+ * Reference to the frame's retained NATIVE surface + the parent crop's placement
8370
+ * within the frame, so the executor can re-cut a leaf child ROI at native
8371
+ * resolution on the detail plane. See the `runPipeline` `nativeCropRef` field.
8372
+ */
8373
+ var NativeCropRefSchema = z.object({
8374
+ /** Handle keying the retained native surface (node-pinned to its owner). */
8375
+ handle: FrameHandleSchema,
8376
+ /** The parent crop's padded/clamped rectangle in FRAME-space pixels. */
8377
+ cropFrameSpace: z.object({
8378
+ x: z.number(),
8379
+ y: z.number(),
8380
+ w: z.number(),
8381
+ h: z.number()
8382
+ })
8383
+ });
8368
8384
  var ModelFormatSchema$1 = z.enum([
8369
8385
  "onnx",
8370
8386
  "coreml",
@@ -8739,7 +8755,22 @@ var pipelineExecutorCapability = {
8739
8755
  * Omitted ⇒ the runner's default device (current single-engine
8740
8756
  * behaviour). Selects WHICH device pool of the node runs the call.
8741
8757
  */
8742
- deviceKey: z.string().optional()
8758
+ deviceKey: z.string().optional(),
8759
+ /**
8760
+ * Two-plane NATIVE child-crop reference. Set by `runDetailSubtree` ONLY
8761
+ * when the parent crop was resolved from the frame's retained NATIVE
8762
+ * surface (a frameHandle HIT). Lets the executor re-cut a LEAF crop
8763
+ * child's ROI (plate-ocr, face-embedding, leaf classifiers) at native
8764
+ * resolution from that surface — the SAME quality path faces already
8765
+ * had — instead of the downscaled parent tile. `handle` keys the native
8766
+ * surface (node-pinned to its owner); `cropFrameSpace` is the parent
8767
+ * crop's padded/clamped rectangle in FRAME-space pixels, used to compose
8768
+ * the executor's crop-normalized child ROI back into frame-normalized
8769
+ * coordinates. Auxiliary to the image source (`image`/`frame`/…), NOT one
8770
+ * of the mutually-exclusive image inputs. Absent ⇒ tile-crop children
8771
+ * (today's behaviour on the fallback path).
8772
+ */
8773
+ nativeCropRef: NativeCropRefSchema.optional()
8743
8774
  }), PipelineRunResultBridge, { kind: "mutation" }),
8744
8775
  /**
8745
8776
  * Batched run — N raw frames packed into one cap call. The provider
@@ -9042,7 +9073,11 @@ var DetailResultSchema = z.object({
9042
9073
  bbox: NativeCropBboxSchema.optional(),
9043
9074
  embedding: z.string().optional(),
9044
9075
  label: z.string().optional(),
9045
- alignedCropJpeg: z.string().optional()
9076
+ alignedCropJpeg: z.string().optional(),
9077
+ /** Face short side (px) measured on the NATIVE crop surface. The `bbox`
9078
+ * above is detection-frame px (≈6× smaller on a 4K camera) — min-face-size
9079
+ * consumers MUST prefer this when present (2026-07-22 native-gate fix). */
9080
+ nativeFaceShortSidePx: z.number().optional()
9046
9081
  });
9047
9082
  /**
9048
9083
  * Per-camera tunable ranges + defaults. Single source of truth used
@@ -15728,6 +15763,247 @@ var notificationOutputCapability = {
15728
15763
  }
15729
15764
  };
15730
15765
  /**
15766
+ * notification-rules — the Notification Center rule surface (P1 core).
15767
+ *
15768
+ * Spec: `docs/superpowers/specs/2026-07-22-notification-center-requirements.md`
15769
+ * (operator decisions D-1/D-2/D-3 are binding):
15770
+ *
15771
+ * - D-2: rule EVALUATION lives in `addon-post-analysis` (the
15772
+ * `notification-center` module), hooked on the durable persistence
15773
+ * moments (object-event insert, TrackCloser.closeExpired) with a
15774
+ * persisted outbox + retry — never the lossy telemetry bus (D8).
15775
+ * - D-3: urgency belongs to the RULE. `delivery: 'immediate'` fires on the
15776
+ * FIRST persisted detection matching the conditions (per-track dedup,
15777
+ * `maxPerTrack` fixed at 1 — see {@link NC_MAX_PER_TRACK_IMMEDIATE});
15778
+ * `delivery: 'track-end'` evaluates the finalized track record at close.
15779
+ * - DISPATCH stays behind `notification-output` (rules reference targets
15780
+ * by id; per-backend params are a passthrough blob capped by the
15781
+ * target kind's own caps/degrade engine).
15782
+ *
15783
+ * P1 scope: admin-authored rules only (`createdBy` stamped from the
15784
+ * server-injected caller identity — the first `caller: 'required'`
15785
+ * adopter). The P1 condition subset is: devices, classes(+exclude),
15786
+ * minConfidence, admin zones (any/all + exclude), weekly schedule
15787
+ * windows, and the optional label/identity/plate matchers. User rules,
15788
+ * private zones, per-recipient fan-out and the wider condition table are
15789
+ * P2+ (see spec §7).
15790
+ *
15791
+ * All schemas here are the single source of truth — `NcRule` etc. are
15792
+ * `z.infer` exports; no duplicate interfaces (the advanced-notifier
15793
+ * schema/interface drift is explicitly not repeated).
15794
+ */
15795
+ /** D-3: the urgency of a rule — which persistence moment evaluates it. */
15796
+ var NcDeliverySchema = z.enum(["immediate", "track-end"]);
15797
+ /** One weekly activation window. `startMinute > endMinute` crosses midnight. */
15798
+ var NcScheduleWindowSchema = z.object({
15799
+ /** Days of week the window STARTS on (0 = Sunday … 6 = Saturday). */
15800
+ days: z.array(z.number().int().min(0).max(6)).min(1),
15801
+ startMinute: z.number().int().min(0).max(1439),
15802
+ endMinute: z.number().int().min(0).max(1439)
15803
+ });
15804
+ /** Weekly schedule — OR of windows; absence on the rule = always active. */
15805
+ var NcScheduleSchema = z.object({
15806
+ windows: z.array(NcScheduleWindowSchema).min(1),
15807
+ /** IANA timezone; default = hub host timezone. */
15808
+ timezone: z.string().optional(),
15809
+ /** Active OUTSIDE the windows (e.g. "only outside business hours"). */
15810
+ invert: z.boolean().optional()
15811
+ });
15812
+ /** Fuzzy plate matcher — OCR noise makes exact match useless (spec row 12/13). */
15813
+ var NcPlateMatcherSchema = z.object({
15814
+ values: z.array(z.string().min(1)).min(1),
15815
+ /** Max Levenshtein distance after normalization (uppercase alphanumeric). */
15816
+ maxDistance: z.number().int().min(0).max(3).default(1)
15817
+ });
15818
+ /** Admin-zone membership condition (zone IDs as stamped by the ZoneEngine). */
15819
+ var NcZoneConditionSchema = z.object({
15820
+ ids: z.array(z.string().min(1)).min(1),
15821
+ /** Quantifier over `ids` — at least one / every one visited. */
15822
+ match: z.enum(["any", "all"]).default("any")
15823
+ });
15824
+ /**
15825
+ * The P1 condition set — a flat AND of groups; absent group = pass;
15826
+ * membership lists are OR within the list (spec §2.3).
15827
+ */
15828
+ var NcConditionsSchema = z.object({
15829
+ /** Device scope — absent = all devices. */
15830
+ devices: z.array(z.number()).optional(),
15831
+ /** Detector class names (any overlap with the record's class set). */
15832
+ classes: z.array(z.string().min(1)).optional(),
15833
+ /** Veto classes — any overlap fails the rule. */
15834
+ classesExclude: z.array(z.string().min(1)).optional(),
15835
+ /** Minimum detection confidence 0–1 (fails when the record has none). */
15836
+ minConfidence: z.number().min(0).max(1).optional(),
15837
+ /** Admin zone membership over event `zones` / track `zonesVisited`. */
15838
+ zones: NcZoneConditionSchema.optional(),
15839
+ /** Veto zones — any hit fails the rule. */
15840
+ zonesExclude: z.array(z.string().min(1)).optional(),
15841
+ /**
15842
+ * Exact (case-insensitive) match on the record's collapsed `label`
15843
+ * (identity name / plate text / subclass).
15844
+ */
15845
+ labelEquals: z.array(z.string().min(1)).optional(),
15846
+ /**
15847
+ * Identity matcher. P1 boundary: matched against the record's collapsed
15848
+ * `label` (the identity display name propagated by the face pipeline) —
15849
+ * identity-ID matching rides in P2 when identity ids reach the record.
15850
+ */
15851
+ identities: z.array(z.string().min(1)).optional(),
15852
+ /** Fuzzy plate matcher against the record's `label` (plate text). */
15853
+ plates: NcPlateMatcherSchema.optional()
15854
+ });
15855
+ /** One delivery target: a `notification-output` Target ref + passthrough params. */
15856
+ var NcRuleTargetSchema = z.object({
15857
+ /** `notification-output` Target id. */
15858
+ targetId: z.string().min(1),
15859
+ /**
15860
+ * Per-backend passthrough. Recognized keys are mapped onto the canonical
15861
+ * Notification (`priority`, `level`, `sound`, `clickUrl`, `ttl`); the
15862
+ * degrade engine drops what the backend can't render.
15863
+ */
15864
+ params: z.record(z.string(), z.unknown()).optional()
15865
+ });
15866
+ /**
15867
+ * Media attachment policy (P1 still-image subset). `best` = the best
15868
+ * AVAILABLE media at dispatch time (D-3); `best-matching` (track-end
15869
+ * condition-best) is deferred — operator open point.
15870
+ */
15871
+ var NcMediaPolicySchema = z.object({ attach: z.enum([
15872
+ "best",
15873
+ "keyFrame",
15874
+ "none"
15875
+ ]).default("best") });
15876
+ /** Throttle — cooldown survives restarts (rebuilt from the outbox on boot). */
15877
+ var NcThrottleSchema = z.object({
15878
+ cooldownSec: z.number().int().min(0).max(86400).default(60),
15879
+ /** `rule` = one shared cooldown; `rule-device` = per-camera cooldown. */
15880
+ scope: z.enum(["rule", "rule-device"]).default("rule-device")
15881
+ });
15882
+ /** Client-supplied rule fields (server stamps id/createdBy/createdAt/updatedAt). */
15883
+ var NcRuleInputSchema = z.object({
15884
+ name: z.string().min(1).max(200),
15885
+ enabled: z.boolean().default(true),
15886
+ delivery: NcDeliverySchema,
15887
+ conditions: NcConditionsSchema.default({}),
15888
+ schedule: NcScheduleSchema.optional(),
15889
+ targets: z.array(NcRuleTargetSchema).min(1),
15890
+ media: NcMediaPolicySchema.default({ attach: "best" }),
15891
+ throttle: NcThrottleSchema.default({
15892
+ cooldownSec: 60,
15893
+ scope: "rule-device"
15894
+ }),
15895
+ /** `{{var}}` templating over camera/class/label/zones/confidence/time. */
15896
+ template: z.object({
15897
+ title: z.string().max(500).optional(),
15898
+ body: z.string().max(2e3).optional()
15899
+ }).optional(),
15900
+ /** Canonical notification priority ordinal (1..5); per-target overridable. */
15901
+ priority: z.number().int().min(1).max(5).default(3)
15902
+ });
15903
+ /** Partial patch for `updateRule` — any subset of the input fields. */
15904
+ var NcRulePatchSchema = NcRuleInputSchema.partial();
15905
+ /** A persisted rule. */
15906
+ var NcRuleSchema = NcRuleInputSchema.extend({
15907
+ id: z.string(),
15908
+ /** userId of the admin who created the rule (server-stamped caller). */
15909
+ createdBy: z.string(),
15910
+ createdAt: z.number(),
15911
+ updatedAt: z.number()
15912
+ });
15913
+ var NcTestResultSchema = z.object({
15914
+ recordId: z.string(),
15915
+ recordKind: z.enum(["object-event", "track"]),
15916
+ deviceId: z.number(),
15917
+ timestamp: z.number(),
15918
+ wouldFire: z.boolean(),
15919
+ /** Condition id that failed (first failing group), when `wouldFire` is false. */
15920
+ failedCondition: z.string().optional(),
15921
+ className: z.string().optional(),
15922
+ label: z.string().optional()
15923
+ });
15924
+ var NcConditionDescriptorSchema = z.object({
15925
+ /** Field id inside `NcConditions` (or `'schedule'` for the rule-level group). */
15926
+ id: z.string(),
15927
+ group: z.enum([
15928
+ "scope",
15929
+ "class",
15930
+ "zones",
15931
+ "quality",
15932
+ "label",
15933
+ "schedule"
15934
+ ]),
15935
+ label: z.string(),
15936
+ /** Editor widget the UI renders — never hardcode per-condition forms. */
15937
+ valueType: z.enum([
15938
+ "deviceIdList",
15939
+ "stringList",
15940
+ "number01",
15941
+ "zoneSelection",
15942
+ "zoneIdList",
15943
+ "schedule",
15944
+ "plateMatcher"
15945
+ ]),
15946
+ operator: z.enum([
15947
+ "in",
15948
+ "notIn",
15949
+ "anyOf",
15950
+ "allOf",
15951
+ "gte",
15952
+ "fuzzyIn",
15953
+ "withinSchedule"
15954
+ ]),
15955
+ /** Which delivery kinds the condition applies to. */
15956
+ appliesTo: z.array(NcDeliverySchema),
15957
+ phase: z.string(),
15958
+ description: z.string().optional()
15959
+ });
15960
+ var notificationRulesCapability = {
15961
+ name: "notification-rules",
15962
+ scope: "system",
15963
+ mode: "singleton",
15964
+ methods: {
15965
+ listRules: method(z.object({}), z.object({ rules: z.array(NcRuleSchema) }), { auth: "admin" }),
15966
+ getRule: method(z.object({ ruleId: z.string() }), z.object({ rule: NcRuleSchema.nullable() }), { auth: "admin" }),
15967
+ createRule: method(z.object({ rule: NcRuleInputSchema }), z.object({ rule: NcRuleSchema }), {
15968
+ kind: "mutation",
15969
+ auth: "admin",
15970
+ caller: "required"
15971
+ }),
15972
+ updateRule: method(z.object({
15973
+ ruleId: z.string(),
15974
+ patch: NcRulePatchSchema
15975
+ }), z.object({ rule: NcRuleSchema }), {
15976
+ kind: "mutation",
15977
+ auth: "admin",
15978
+ caller: "required"
15979
+ }),
15980
+ deleteRule: method(z.object({ ruleId: z.string() }), z.object({ success: z.literal(true) }), {
15981
+ kind: "mutation",
15982
+ auth: "admin"
15983
+ }),
15984
+ setRuleEnabled: method(z.object({
15985
+ ruleId: z.string(),
15986
+ enabled: z.boolean()
15987
+ }), z.object({ success: z.literal(true) }), {
15988
+ kind: "mutation",
15989
+ auth: "admin"
15990
+ }),
15991
+ /**
15992
+ * Dry-run a rule against recently persisted records (object events for
15993
+ * `immediate`, closed tracks for `track-end`). Mutation kind only to
15994
+ * carry the full rule object safely; no side effects.
15995
+ */
15996
+ testRule: method(z.object({
15997
+ rule: NcRuleInputSchema,
15998
+ lookbackMinutes: z.number().int().min(1).max(1440).default(60)
15999
+ }), z.object({ results: z.array(NcTestResultSchema) }), {
16000
+ kind: "mutation",
16001
+ auth: "admin"
16002
+ }),
16003
+ getConditionCatalog: method(z.object({}), z.object({ catalog: z.array(NcConditionDescriptorSchema) }))
16004
+ }
16005
+ };
16006
+ /**
15731
16007
  * Shared LLM generate contracts — imported by BOTH `llm.cap.ts` (consumer
15732
16008
  * surface) and `llm-runtime.cap.ts` (node-side managed executor) so the two
15733
16009
  * caps stay wire-compatible without a circular cap→cap import.
@@ -22573,6 +22849,7 @@ var ALL_CAPABILITY_DEFINITIONS = [
22573
22849
  networkQualityCapability,
22574
22850
  nodesCapability,
22575
22851
  notificationOutputCapability,
22852
+ notificationRulesCapability,
22576
22853
  notifierCapability,
22577
22854
  numericSensorCapability,
22578
22855
  oauthIntegrationCapability,
@@ -25314,6 +25591,54 @@ var METHOD_ACCESS_MAP = Object.freeze({
25314
25591
  addonId: null,
25315
25592
  access: "create"
25316
25593
  },
25594
+ "notificationRules.createRule": {
25595
+ capName: "notification-rules",
25596
+ capScope: "system",
25597
+ addonId: null,
25598
+ access: "create"
25599
+ },
25600
+ "notificationRules.deleteRule": {
25601
+ capName: "notification-rules",
25602
+ capScope: "system",
25603
+ addonId: null,
25604
+ access: "delete"
25605
+ },
25606
+ "notificationRules.getConditionCatalog": {
25607
+ capName: "notification-rules",
25608
+ capScope: "system",
25609
+ addonId: null,
25610
+ access: "view"
25611
+ },
25612
+ "notificationRules.getRule": {
25613
+ capName: "notification-rules",
25614
+ capScope: "system",
25615
+ addonId: null,
25616
+ access: "view"
25617
+ },
25618
+ "notificationRules.listRules": {
25619
+ capName: "notification-rules",
25620
+ capScope: "system",
25621
+ addonId: null,
25622
+ access: "view"
25623
+ },
25624
+ "notificationRules.setRuleEnabled": {
25625
+ capName: "notification-rules",
25626
+ capScope: "system",
25627
+ addonId: null,
25628
+ access: "create"
25629
+ },
25630
+ "notificationRules.testRule": {
25631
+ capName: "notification-rules",
25632
+ capScope: "system",
25633
+ addonId: null,
25634
+ access: "create"
25635
+ },
25636
+ "notificationRules.updateRule": {
25637
+ capName: "notification-rules",
25638
+ capScope: "system",
25639
+ addonId: null,
25640
+ access: "create"
25641
+ },
25317
25642
  "notifier.cancel": {
25318
25643
  capName: "notifier",
25319
25644
  capScope: "device",
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("./chunk-Cek0wNdY.js");
3
- const require_dist = require("./dist-DIlYZWEp.js");
3
+ const require_dist = require("./dist-CdgScQ3H.js");
4
4
  const require_model_download_service = require("./model-download-service-hf0ookyy.js");
5
- const require_manifest_python_deps = require("./manifest-python-deps-BznC09O4.js");
5
+ const require_manifest_python_deps = require("./manifest-python-deps-CUHn5wqq.js");
6
6
  const require_resource_monitor = require("./resource-monitor-DNNomR-i.js");
7
7
  const require_builtins_sqlite_storage_filesystem_storage_addon = require("./builtins/sqlite-storage/filesystem-storage.addon.js");
8
8
  const require_builtins_sqlite_storage_sqlite_settings_addon = require("./builtins/sqlite-storage/sqlite-settings.addon.js");
@@ -5378,10 +5378,48 @@ function methodsFor(def) {
5378
5378
  auth: m.auth ?? "protected",
5379
5379
  schema: m,
5380
5380
  isVoid: require_dist.isVoidInput(m.input),
5381
- isObject: require_dist.isObjectInput(m.input)
5381
+ isObject: require_dist.isObjectInput(m.input),
5382
+ callerRequired: m.caller === "required"
5382
5383
  };
5383
5384
  });
5384
5385
  }
5386
+ /**
5387
+ * Extract the authenticated caller identity from the (structurally
5388
+ * unknown) tRPC context. The builder cannot import the server's
5389
+ * `TrpcContext`, so the read is narrowing-based: `ctx.user.id` (string)
5390
+ * + `ctx.user.isAdmin` (boolean) — the stable `AuthenticatedUser` core
5391
+ * every context factory produces. Returns null when no authenticated
5392
+ * user is present (the caller then fails the call — a fabricated
5393
+ * identity is never injected).
5394
+ */
5395
+ function extractCallerIdentity(ctx) {
5396
+ if (ctx === null || typeof ctx !== "object" || !("user" in ctx)) return null;
5397
+ const user = ctx.user;
5398
+ if (user === null || typeof user !== "object") return null;
5399
+ if (!("id" in user) || !("isAdmin" in user)) return null;
5400
+ const id = user.id;
5401
+ const isAdmin = user.isAdmin;
5402
+ if (typeof id !== "string" || id.length === 0 || typeof isAdmin !== "boolean") return null;
5403
+ return {
5404
+ userId: id,
5405
+ isAdmin
5406
+ };
5407
+ }
5408
+ /**
5409
+ * Return a NEW input object carrying the server-derived `caller`. The
5410
+ * spread-then-set ordering guarantees any client-supplied `caller` key
5411
+ * (which survives the `.loose()` wire parse) is overwritten. Raises
5412
+ * UNAUTHORIZED (or `badRequest` on a skewed services object without the
5413
+ * `unauthorized` raiser) when the context has no authenticated user.
5414
+ */
5415
+ function injectCaller(rest, ctx, capName, methodName, services) {
5416
+ const caller = extractCallerIdentity(ctx);
5417
+ if (caller === null) return (services.unauthorized ?? services.badRequest)(`Capability "${capName}.${methodName}" requires an authenticated caller`);
5418
+ return {
5419
+ ...rest,
5420
+ caller
5421
+ };
5422
+ }
5385
5423
  /** Strip a set of selector keys from an input object, returning a NEW object. */
5386
5424
  function stripKeys(input, keys) {
5387
5425
  const src = input ?? {};
@@ -5422,6 +5460,9 @@ function requireLocal(capName, getLocal, services) {
5422
5460
  * Build a single capability's router (the runtime equivalent of one
5423
5461
  * codegen'd `createCapRouter_<Cap>`). Each method becomes a typed
5424
5462
  * procedure with the SAME routing branch the codegen emits.
5463
+ *
5464
+ * Exported for the caller-injection spec (which drives it with synthetic
5465
+ * cap defs) — production callers go through {@link buildCapRouters}.
5425
5466
  */
5426
5467
  function buildOneCapRouter(def, primitives, services) {
5427
5468
  const capName = def.name;
@@ -5430,6 +5471,7 @@ function buildOneCapRouter(def, primitives, services) {
5430
5471
  const nodeIdData = def.nodeIdMode === "data";
5431
5472
  const procedures = {};
5432
5473
  for (const method of methodsFor(def)) {
5474
+ if (method.callerRequired && (method.kind === "subscription" || !method.isObject)) throw new Error(`Cap "${capName}" method "${method.name}": caller: 'required' is only supported on query/mutation methods with an object input schema`);
5433
5475
  const effectiveMountKind = method.schema.systemOnly === true ? systemMountKind : mount.kind;
5434
5476
  const isCollection = effectiveMountKind === "collection";
5435
5477
  const getLocal = (ctx, addonId) => services.getLocalProvider(capName, effectiveMountKind, ctx, addonId);
@@ -5461,17 +5503,25 @@ function buildOneCapRouter(def, primitives, services) {
5461
5503
  if (method.isObject) {
5462
5504
  const schema = nodeIdData ? inputSchema : require_dist.looseSchema(inputSchema);
5463
5505
  procedures[method.name] = base.input(schema)[procKind](({ input, ctx }) => {
5464
- if (nodeIdData) return requireLocal(capName, () => getLocal(ctx), services)[method.name]?.(input);
5506
+ if (nodeIdData) {
5507
+ const provider = requireLocal(capName, () => getLocal(ctx), services);
5508
+ const payload = method.callerRequired ? injectCaller(stripKeys(input, []).rest, ctx, capName, method.name, services) : input;
5509
+ return provider[method.name]?.(payload);
5510
+ }
5465
5511
  if (isCollection) {
5466
5512
  const { rest, picked } = stripKeys(input, ["nodeId", "addonId"]);
5467
5513
  const nodeId = typeof picked.nodeId === "string" ? picked.nodeId : void 0;
5468
5514
  const topLevelAddonId = typeof picked.addonId === "string" ? picked.addonId : void 0;
5469
5515
  const canRecoverNestedAddonId = !require_dist.isArrayOutputSchema(method.schema.output) && !require_dist.objectInputDeclaresAddonId(method.schema.input);
5470
5516
  const addonId = topLevelAddonId ?? (canRecoverNestedAddonId ? require_dist.extractNestedAddonId(rest) : void 0);
5471
- return resolveProviderForCall(capName, nodeId, () => getLocal(ctx, addonId), services)[method.name]?.(rest);
5517
+ const provider = resolveProviderForCall(capName, nodeId, () => getLocal(ctx, addonId), services);
5518
+ const payload = method.callerRequired ? injectCaller(rest, ctx, capName, method.name, services) : rest;
5519
+ return provider[method.name]?.(payload);
5472
5520
  }
5473
5521
  const { rest, picked } = stripKeys(input, ["nodeId"]);
5474
- return resolveProviderForCall(capName, typeof picked.nodeId === "string" ? picked.nodeId : void 0, () => getLocal(ctx), services)[method.name]?.(rest);
5522
+ const provider = resolveProviderForCall(capName, typeof picked.nodeId === "string" ? picked.nodeId : void 0, () => getLocal(ctx), services);
5523
+ const payload = method.callerRequired ? injectCaller(rest, ctx, capName, method.name, services) : rest;
5524
+ return provider[method.name]?.(payload);
5475
5525
  });
5476
5526
  continue;
5477
5527
  }
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { At as EventCategory$1, Dt as resolveCapMount, Et as readinessKey, F as kebabToCamel, I as lifecycleJobSchema, K as procedureAuthKey, M as isCollectionArrayMethod, N as isObjectInput, O as extractNestedAddonId, Ot as scopeKey, P as isVoidInput, Tt as parseJsonUnknown$1, U as objectInputDeclaresAddonId, _t as asString$1, ct as DEVICE_STATUS_METHOD, ft as ReadinessRegistry, gt as asNumber, ht as asJsonObject$1, it as errMsg$1, j as isArrayOutputSchema, o as METHOD_ACCESS_MAP, ot as DATAPLANE_SECRET_HEADER$1, p as addonSettingsCapability, pt as ReadinessTimeoutError, s as RUNTIME_DEFAULTS, st as DEVICE_SETTINGS_CONTRIBUTION_METHODS, t as ALL_CAPABILITY_DEFINITIONS, vt as createEvent, wt as parseJsonObject, xt as expandCapMethods, yt as emitDownForOwnedCaps, z as looseSchema } from "./dist-aTevP3Nh.mjs";
1
+ import { At as EventCategory$1, Dt as resolveCapMount, Et as readinessKey, F as kebabToCamel, I as lifecycleJobSchema, K as procedureAuthKey, M as isCollectionArrayMethod, N as isObjectInput, O as extractNestedAddonId, Ot as scopeKey, P as isVoidInput, Tt as parseJsonUnknown$1, U as objectInputDeclaresAddonId, _t as asString$1, ct as DEVICE_STATUS_METHOD, ft as ReadinessRegistry, gt as asNumber, ht as asJsonObject$1, it as errMsg$1, j as isArrayOutputSchema, o as METHOD_ACCESS_MAP, ot as DATAPLANE_SECRET_HEADER$1, p as addonSettingsCapability, pt as ReadinessTimeoutError, s as RUNTIME_DEFAULTS, st as DEVICE_SETTINGS_CONTRIBUTION_METHODS, t as ALL_CAPABILITY_DEFINITIONS, vt as createEvent, wt as parseJsonObject, xt as expandCapMethods, yt as emitDownForOwnedCaps, z as looseSchema } from "./dist-CxM20CkF.mjs";
2
2
  import { a as downloadModel, c as getModelFilePath, d as contentTypeFor, f as createAuthenticatedFileServer, h as resolveFilePath, i as downloadFile, l as isModelDownloaded, m as parseTokenizedUrl, n as collectModelFiles, o as ensureModel, p as parseRangeHeader, r as deleteModelFromDisk, s as fetchJson, t as ModelDownloadService, u as createFileDataPlaneHandler } from "./model-download-service-Cp9f4dk6.mjs";
3
- import { $ as buildNativeCapProxy, A as createHubCapForwardService, B as AGENT_CAP_FWD_ACTION, C as brokerTransportLink, Ct as resolveAddonClass, D as localProviderLink, E as ipcParentLink, F as createUdsLogger, G as callWithServiceDiscovery, H as CapRouteResolver, I as createUdsLoggerWithControl, J as UdsLocalTransportServer, K as createLocalTransport, L as LocalChildClient, M as createUdsEventBridge, N as createUdsEventBus, O as HUB_CAP_FWD_ACTION, P as udsChildLogToWorkerEntry, Q as encodeFrame, R as LocalChildRegistry, S as brokerCallForCap, St as runNpm, T as ipcChildLink, U as CapRouteError, V as AGENT_CAP_FWD_SERVICE, W as classifyCapRoute, X as localEndpointPath, Y as SocketChannel, Z as FrameDecoder, _ as createKernelHwAccel, _t as CapabilityHandle, a as getWorkerDeviceRegistry, b as __resetCapUsageRegistryForTests, bt as installManifestNativeDeps, c as setHubConnected, ct as NATIVE_PROVIDER_SERVICE_INFIX, d as getBrokerEventBus, dt as capBareAction, et as buildUdsNativeCapProxy, f as getMoleculerEventStats, ft as capServiceName, g as AddonDepsManager, gt as DeviceRegistry, h as subscribePassthrough, ht as serializeTypedArrays, i as createUdsAddonContext, it as mountNativeCapService, j as createParentUnownedCallHandler, k as HUB_CAP_FWD_SERVICE, l as EVENT_TOPIC_PREFIX, lt as capActionName, m as setNodeEventInterest, mt as deserializeTypedArrays, n as adaptBrokerToCluster, o as getOrInitReadinessRegistry, ot as createAddonService, p as registerEventBusService, pt as parseCapAction, q as UdsLocalTransportClient, r as createAddonContext, s as getOrInitReadinessRegistryForClient, st as validateProviderRegistrations, t as installManifestPythonDeps, tt as createBrokerDeviceManagerApi, u as clusterEventTopic, ut as capActionSuffix, v as resolveHwAccel, vt as CapabilityUnavailableError, w as buildLinkChain, wt as createAddonDataPlaneFacility, x as getCapUsageRegistry, xt as resolveNpmInvocation, y as CapUsageRegistry, yt as copyBundledNativeModules, z as UDS_NO_ROUTE_PREFIX } from "./manifest-python-deps-Czja13st.mjs";
3
+ import { $ as buildNativeCapProxy, A as createHubCapForwardService, B as AGENT_CAP_FWD_ACTION, C as brokerTransportLink, Ct as resolveAddonClass, D as localProviderLink, E as ipcParentLink, F as createUdsLogger, G as callWithServiceDiscovery, H as CapRouteResolver, I as createUdsLoggerWithControl, J as UdsLocalTransportServer, K as createLocalTransport, L as LocalChildClient, M as createUdsEventBridge, N as createUdsEventBus, O as HUB_CAP_FWD_ACTION, P as udsChildLogToWorkerEntry, Q as encodeFrame, R as LocalChildRegistry, S as brokerCallForCap, St as runNpm, T as ipcChildLink, U as CapRouteError, V as AGENT_CAP_FWD_SERVICE, W as classifyCapRoute, X as localEndpointPath, Y as SocketChannel, Z as FrameDecoder, _ as createKernelHwAccel, _t as CapabilityHandle, a as getWorkerDeviceRegistry, b as __resetCapUsageRegistryForTests, bt as installManifestNativeDeps, c as setHubConnected, ct as NATIVE_PROVIDER_SERVICE_INFIX, d as getBrokerEventBus, dt as capBareAction, et as buildUdsNativeCapProxy, f as getMoleculerEventStats, ft as capServiceName, g as AddonDepsManager, gt as DeviceRegistry, h as subscribePassthrough, ht as serializeTypedArrays, i as createUdsAddonContext, it as mountNativeCapService, j as createParentUnownedCallHandler, k as HUB_CAP_FWD_SERVICE, l as EVENT_TOPIC_PREFIX, lt as capActionName, m as setNodeEventInterest, mt as deserializeTypedArrays, n as adaptBrokerToCluster, o as getOrInitReadinessRegistry, ot as createAddonService, p as registerEventBusService, pt as parseCapAction, q as UdsLocalTransportClient, r as createAddonContext, s as getOrInitReadinessRegistryForClient, st as validateProviderRegistrations, t as installManifestPythonDeps, tt as createBrokerDeviceManagerApi, u as clusterEventTopic, ut as capActionSuffix, v as resolveHwAccel, vt as CapabilityUnavailableError, w as buildLinkChain, wt as createAddonDataPlaneFacility, x as getCapUsageRegistry, xt as resolveNpmInvocation, y as CapUsageRegistry, yt as copyBundledNativeModules, z as UDS_NO_ROUTE_PREFIX } from "./manifest-python-deps-CcW0WpfS.mjs";
4
4
  import { n as getSinglePidStats, t as getPidStats } from "./resource-monitor-Le3l0qS2.mjs";
5
5
  import { FilesystemStorageAddon, t as FilesystemStorageProvider } from "./builtins/sqlite-storage/filesystem-storage.addon.mjs";
6
6
  import { SqliteSettingsAddon, t as SqliteSettingsBackend } from "./builtins/sqlite-storage/sqlite-settings.addon.mjs";
@@ -5370,10 +5370,48 @@ function methodsFor(def) {
5370
5370
  auth: m.auth ?? "protected",
5371
5371
  schema: m,
5372
5372
  isVoid: isVoidInput(m.input),
5373
- isObject: isObjectInput(m.input)
5373
+ isObject: isObjectInput(m.input),
5374
+ callerRequired: m.caller === "required"
5374
5375
  };
5375
5376
  });
5376
5377
  }
5378
+ /**
5379
+ * Extract the authenticated caller identity from the (structurally
5380
+ * unknown) tRPC context. The builder cannot import the server's
5381
+ * `TrpcContext`, so the read is narrowing-based: `ctx.user.id` (string)
5382
+ * + `ctx.user.isAdmin` (boolean) — the stable `AuthenticatedUser` core
5383
+ * every context factory produces. Returns null when no authenticated
5384
+ * user is present (the caller then fails the call — a fabricated
5385
+ * identity is never injected).
5386
+ */
5387
+ function extractCallerIdentity(ctx) {
5388
+ if (ctx === null || typeof ctx !== "object" || !("user" in ctx)) return null;
5389
+ const user = ctx.user;
5390
+ if (user === null || typeof user !== "object") return null;
5391
+ if (!("id" in user) || !("isAdmin" in user)) return null;
5392
+ const id = user.id;
5393
+ const isAdmin = user.isAdmin;
5394
+ if (typeof id !== "string" || id.length === 0 || typeof isAdmin !== "boolean") return null;
5395
+ return {
5396
+ userId: id,
5397
+ isAdmin
5398
+ };
5399
+ }
5400
+ /**
5401
+ * Return a NEW input object carrying the server-derived `caller`. The
5402
+ * spread-then-set ordering guarantees any client-supplied `caller` key
5403
+ * (which survives the `.loose()` wire parse) is overwritten. Raises
5404
+ * UNAUTHORIZED (or `badRequest` on a skewed services object without the
5405
+ * `unauthorized` raiser) when the context has no authenticated user.
5406
+ */
5407
+ function injectCaller(rest, ctx, capName, methodName, services) {
5408
+ const caller = extractCallerIdentity(ctx);
5409
+ if (caller === null) return (services.unauthorized ?? services.badRequest)(`Capability "${capName}.${methodName}" requires an authenticated caller`);
5410
+ return {
5411
+ ...rest,
5412
+ caller
5413
+ };
5414
+ }
5377
5415
  /** Strip a set of selector keys from an input object, returning a NEW object. */
5378
5416
  function stripKeys(input, keys) {
5379
5417
  const src = input ?? {};
@@ -5414,6 +5452,9 @@ function requireLocal(capName, getLocal, services) {
5414
5452
  * Build a single capability's router (the runtime equivalent of one
5415
5453
  * codegen'd `createCapRouter_<Cap>`). Each method becomes a typed
5416
5454
  * procedure with the SAME routing branch the codegen emits.
5455
+ *
5456
+ * Exported for the caller-injection spec (which drives it with synthetic
5457
+ * cap defs) — production callers go through {@link buildCapRouters}.
5417
5458
  */
5418
5459
  function buildOneCapRouter(def, primitives, services) {
5419
5460
  const capName = def.name;
@@ -5422,6 +5463,7 @@ function buildOneCapRouter(def, primitives, services) {
5422
5463
  const nodeIdData = def.nodeIdMode === "data";
5423
5464
  const procedures = {};
5424
5465
  for (const method of methodsFor(def)) {
5466
+ if (method.callerRequired && (method.kind === "subscription" || !method.isObject)) throw new Error(`Cap "${capName}" method "${method.name}": caller: 'required' is only supported on query/mutation methods with an object input schema`);
5425
5467
  const effectiveMountKind = method.schema.systemOnly === true ? systemMountKind : mount.kind;
5426
5468
  const isCollection = effectiveMountKind === "collection";
5427
5469
  const getLocal = (ctx, addonId) => services.getLocalProvider(capName, effectiveMountKind, ctx, addonId);
@@ -5453,17 +5495,25 @@ function buildOneCapRouter(def, primitives, services) {
5453
5495
  if (method.isObject) {
5454
5496
  const schema = nodeIdData ? inputSchema : looseSchema(inputSchema);
5455
5497
  procedures[method.name] = base.input(schema)[procKind](({ input, ctx }) => {
5456
- if (nodeIdData) return requireLocal(capName, () => getLocal(ctx), services)[method.name]?.(input);
5498
+ if (nodeIdData) {
5499
+ const provider = requireLocal(capName, () => getLocal(ctx), services);
5500
+ const payload = method.callerRequired ? injectCaller(stripKeys(input, []).rest, ctx, capName, method.name, services) : input;
5501
+ return provider[method.name]?.(payload);
5502
+ }
5457
5503
  if (isCollection) {
5458
5504
  const { rest, picked } = stripKeys(input, ["nodeId", "addonId"]);
5459
5505
  const nodeId = typeof picked.nodeId === "string" ? picked.nodeId : void 0;
5460
5506
  const topLevelAddonId = typeof picked.addonId === "string" ? picked.addonId : void 0;
5461
5507
  const canRecoverNestedAddonId = !isArrayOutputSchema(method.schema.output) && !objectInputDeclaresAddonId(method.schema.input);
5462
5508
  const addonId = topLevelAddonId ?? (canRecoverNestedAddonId ? extractNestedAddonId(rest) : void 0);
5463
- return resolveProviderForCall(capName, nodeId, () => getLocal(ctx, addonId), services)[method.name]?.(rest);
5509
+ const provider = resolveProviderForCall(capName, nodeId, () => getLocal(ctx, addonId), services);
5510
+ const payload = method.callerRequired ? injectCaller(rest, ctx, capName, method.name, services) : rest;
5511
+ return provider[method.name]?.(payload);
5464
5512
  }
5465
5513
  const { rest, picked } = stripKeys(input, ["nodeId"]);
5466
- return resolveProviderForCall(capName, typeof picked.nodeId === "string" ? picked.nodeId : void 0, () => getLocal(ctx), services)[method.name]?.(rest);
5514
+ const provider = resolveProviderForCall(capName, typeof picked.nodeId === "string" ? picked.nodeId : void 0, () => getLocal(ctx), services);
5515
+ const payload = method.callerRequired ? injectCaller(rest, ctx, capName, method.name, services) : rest;
5516
+ return provider[method.name]?.(payload);
5467
5517
  });
5468
5518
  continue;
5469
5519
  }
@@ -1,4 +1,4 @@
1
- import { CapabilityMountKind } from '@camstack/types';
1
+ import { CapabilityDefinition, CapabilityMountKind } from '@camstack/types';
2
2
  /**
3
3
  * A tRPC-procedure-like builder. Mirrors the chainable surface the
4
4
  * codegen emits (`procedure.input(...).output(...).query(...)`), kept
@@ -64,7 +64,24 @@ export interface CapRouterServices {
64
64
  readonly noNodeRouting: (capName: string) => never;
65
65
  /** Raise the canonical "bad request: missing field" error. */
66
66
  readonly badRequest: (message: string) => never;
67
+ /**
68
+ * Raise the canonical UNAUTHORIZED error — used by `caller: 'required'`
69
+ * methods when the context carries no authenticated user. OPTIONAL for
70
+ * framework-live-update version skew (an older server may hand a
71
+ * services object without it to a newer builder); the builder falls
72
+ * back to `badRequest` in that case so the call still fails closed.
73
+ */
74
+ readonly unauthorized?: (message: string) => never;
67
75
  }
76
+ /**
77
+ * Build a single capability's router (the runtime equivalent of one
78
+ * codegen'd `createCapRouter_<Cap>`). Each method becomes a typed
79
+ * procedure with the SAME routing branch the codegen emits.
80
+ *
81
+ * Exported for the caller-injection spec (which drives it with synthetic
82
+ * cap defs) — production callers go through {@link buildCapRouters}.
83
+ */
84
+ export declare function buildOneCapRouter(def: CapabilityDefinition, primitives: CapRouterPrimitives, services: CapRouterServices): unknown;
68
85
  /**
69
86
  * Build the runtime cap-router map: `{ <camelCapName>: <router> }` for
70
87
  * every capability the builder owns. Caps with `mount.kind` `custom` /
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require("./chunk-Cek0wNdY.js");
2
- const require_dist = require("./dist-DIlYZWEp.js");
2
+ const require_dist = require("./dist-CdgScQ3H.js");
3
3
  let _camstack_types_node = require("@camstack/types/node");
4
4
  let node_http = require("node:http");
5
5
  let node_fs = require("node:fs");
@@ -1,4 +1,4 @@
1
- import { q as readNodePin } from "./dist-aTevP3Nh.mjs";
1
+ import { q as readNodePin } from "./dist-CxM20CkF.mjs";
2
2
  import { ensureBinary, ensureFfmpeg, ensurePython, installPythonPackages, installPythonRequirements } from "@camstack/types/node";
3
3
  import { createServer } from "node:http";
4
4
  import * as fs from "node:fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/system",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "Core addon for CamStack — builtins, pipeline, process management, auth, logging, events",
5
5
  "keywords": [
6
6
  "camstack",