@camstack/addon-admin-ui 1.2.343 → 1.2.345

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 (110) hide show
  1. package/dist/assets/{AddonCollectionPage-tKFP5Lwa.js → AddonCollectionPage-DxzFTU90.js} +1 -1
  2. package/dist/assets/Addons-DRMpHsp4.js +1 -0
  3. package/dist/assets/{AdminTabs-D49DFF7T.js → AdminTabs-Bd1950KJ.js} +1 -1
  4. package/dist/assets/AiProfiles-C2nPDM3i.js +3 -0
  5. package/dist/assets/{BrokerForm-DE4STkG6.js → BrokerForm-DGf9yo4j.js} +1 -1
  6. package/dist/assets/Build-BzWFkHjF.js +40 -0
  7. package/dist/assets/{Calendars-lHwkwn_Q.js → Calendars-JBqHHqwt.js} +1 -1
  8. package/dist/assets/{Capabilities-C3a6ifyd.js → Capabilities-DNJjHmDV.js} +1 -1
  9. package/dist/assets/Cluster-DlGhBZIn.js +11 -0
  10. package/dist/assets/CompositionEditor-vKgiATLA.js +1 -0
  11. package/dist/assets/{CompositionEditorPage-BHOuMbtu.js → CompositionEditorPage-DEZ49NcG.js} +1 -1
  12. package/dist/assets/Data-Bds4gE2c.js +1 -0
  13. package/dist/assets/DetectionIntelligence-CTpq1Y6I.js +1 -0
  14. package/dist/assets/DeviceDetail-BW60HW9h.js +2 -0
  15. package/dist/assets/{DeviceDoActionFields-BZAxfdmk.js → DeviceDoActionFields-Dplk9SjD.js} +1 -1
  16. package/dist/assets/{Devices-H-xH_fOc.js → Devices-Bj6CscpP.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-rd7j1pI_.js → EmbedPlayerPage-DZMOEPWR.js} +1 -1
  18. package/dist/assets/Events-DPcNWJss.js +1 -0
  19. package/dist/assets/Identity-Be4gOAIe.js +1 -0
  20. package/dist/assets/IntegrationDetail-DuroxAAE.js +1 -0
  21. package/dist/assets/Integrations-B6oOd-nv.js +1 -0
  22. package/dist/assets/{Integrations-D2owF0PE.js → Integrations-DzdnfEyW.js} +1 -1
  23. package/dist/assets/Locations-CbwsKjt0.js +3 -0
  24. package/dist/assets/{Logs-Cu1x3xDP.js → Logs-B2mIIrxC.js} +1 -1
  25. package/dist/assets/{MotionZonesSettings-BI_ML-IA.js → MotionZonesSettings-MTt6ORez.js} +1 -1
  26. package/dist/assets/MyAccess-Dxp2pgZV.js +2 -0
  27. package/dist/assets/Network-DvRubcMm.js +1 -0
  28. package/dist/assets/{NodeAddonsSettingsPanel-CCzjSPCH.js → NodeAddonsSettingsPanel-DQJQkGit.js} +1 -1
  29. package/dist/assets/NodeInferenceDevices-B6dsiztC.js +1 -0
  30. package/dist/assets/Notifications-Ze3GwOK6.js +1 -0
  31. package/dist/assets/Pipeline-gwJZ7DOT.js +1 -0
  32. package/dist/assets/Plates-DT6xndAE.js +1 -0
  33. package/dist/assets/{PrivacyMaskSettings-DsUfWvYn.js → PrivacyMaskSettings-FZCxSmjS.js} +1 -1
  34. package/dist/assets/Recordings-BnCv_e-x.js +1 -0
  35. package/dist/assets/{ScanNetworkModal-2aKeFiXH.js → ScanNetworkModal-D6Y37vtZ.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-nXoXaKpY.js → SceneMonitorEditor-Dh2nvXgH.js} +1 -1
  37. package/dist/assets/{Scenes-omiebXrA.js → Scenes-De2-tih3.js} +1 -1
  38. package/dist/assets/{Settings-B0eYhaSp.js → Settings-oXKmMjDx.js} +1 -1
  39. package/dist/assets/{Showroom-B3quOoSI.js → Showroom-BxckpAzn.js} +1 -1
  40. package/dist/assets/{StorageLocationsPanel-D6Ig0BwB.js → StorageLocationsPanel-Bw4Hv9Rt.js} +1 -1
  41. package/dist/assets/{Terminal-yD7p878O.js → Terminal-DvpEoxU5.js} +5 -5
  42. package/dist/assets/{Viewer-C7Iutjs_.js → Viewer-Bsb1cIj5.js} +1 -1
  43. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CzYdLxy-.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Cpf2xhdF.js} +1 -1
  44. package/dist/assets/{archive-CwIHc_Ww.js → archive-DQZ5FHxg.js} +1 -1
  45. package/dist/assets/{authed-media-DMMEqds_.js → authed-media-CM12USJq.js} +1 -1
  46. package/dist/assets/{boxes-BTpyboKa.js → boxes-CI1-aWI-.js} +1 -1
  47. package/dist/assets/circle-slash-B43tX-bj.js +1 -0
  48. package/dist/assets/client-Dc_lJW_Z.js +357 -0
  49. package/dist/assets/{debounced-invalidate-C8AHMwDh.js → debounced-invalidate-vJGPGlle.js} +1 -1
  50. package/dist/assets/{device-integration-icon-D1bjIPIV.js → device-integration-icon-D000Gtf3.js} +1 -1
  51. package/dist/assets/device-picker-model-DhESFLV5.js +1 -0
  52. package/dist/assets/dist-BlILRcih.js +357 -0
  53. package/dist/assets/{dist-D1cRlg3k.js → dist-CQ4IkN0R.js} +1 -1
  54. package/dist/assets/{face-bbox-BFnrsYn8.js → face-bbox-BKfPOkK2.js} +1 -1
  55. package/dist/assets/{hard-drive-download-D2tdSqRj.js → hard-drive-download-BZpsY3VN.js} +1 -1
  56. package/dist/assets/{hostInit-D_wBT4ni.js → hostInit-hPe7d63f.js} +1 -1
  57. package/dist/assets/index-DlFwo3E1.js +4 -0
  58. package/dist/assets/index-a-YFw77c.css +2 -0
  59. package/dist/assets/{layers-D1zKyXV5.js → layers-epIRZStd.js} +1 -1
  60. package/dist/assets/{location-owned-usage-H3GZTDrd.js → location-owned-usage-B1G_o9cu.js} +1 -1
  61. package/dist/assets/{mf-entry-bootstrap-0-5fe03ef0.js → mf-entry-bootstrap-0-fdd3f5f7.js} +2 -2
  62. package/dist/assets/mount-DhESFLV5.js +1 -0
  63. package/dist/assets/notification-schedule-field-Dw7iSL3z.js +1 -0
  64. package/dist/assets/{player-overlays-BElx6KR1.js → player-overlays-8C7Chgtp.js} +1 -1
  65. package/dist/assets/remoteEntry-CCqI3Jvb.js +1 -0
  66. package/dist/assets/{send-B6nyL8aN.js → send-DZeFKKhQ.js} +1 -1
  67. package/dist/assets/{settings-2-B1zaQVrp.js → settings-2-B70kPnTR.js} +1 -1
  68. package/dist/assets/{square-check-big-xzhGc_rP.js → square-check-big-D5MuMUSA.js} +1 -1
  69. package/dist/assets/src-CnGTho8r.js +67 -0
  70. package/dist/assets/{use-scenes-feed-pv0_KeWI.js → use-scenes-feed-CX9FNB3x.js} +1 -1
  71. package/dist/assets/{use-stationary-objects-CjF8p_p7.js → use-stationary-objects-CA2kqBy5.js} +1 -1
  72. package/dist/assets/useEventInvalidation-DhESFLV5.js +1 -0
  73. package/dist/assets/{useNodeUrlSelection-C32KGJ5p.js → useNodeUrlSelection-4PSI9SqT.js} +1 -1
  74. package/dist/assets/user-round-CUchN6hz.js +1 -0
  75. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B3KPRT_5.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-j2hvdY7k.js} +2 -2
  76. package/dist/index.html +8 -8
  77. package/dist/server/addon.js +202 -31
  78. package/package.json +1 -1
  79. package/dist/assets/Addons-CGbLyp8a.js +0 -1
  80. package/dist/assets/AiProfiles-ByvyVf4S.js +0 -3
  81. package/dist/assets/Build-CcAMfH-X.js +0 -40
  82. package/dist/assets/Cluster-DXTRgQzx.js +0 -11
  83. package/dist/assets/CompositionEditor-CWYvMou1.js +0 -1
  84. package/dist/assets/Data-DJP48qWx.js +0 -1
  85. package/dist/assets/DetectionIntelligence-BbWnsTU0.js +0 -1
  86. package/dist/assets/DeviceDetail-CcqKE_PI.js +0 -2
  87. package/dist/assets/Events-D_v5uKvS.js +0 -1
  88. package/dist/assets/Identity-QTqu661c.js +0 -1
  89. package/dist/assets/IntegrationDetail-teGC9uQ3.js +0 -1
  90. package/dist/assets/Integrations-B_b1MZeg.js +0 -1
  91. package/dist/assets/Locations-Nnkdufnb.js +0 -3
  92. package/dist/assets/MyAccess-BMOMwFN6.js +0 -2
  93. package/dist/assets/Network-g8u56vjt.js +0 -1
  94. package/dist/assets/NodeInferenceDevices-BA75g0Jb.js +0 -1
  95. package/dist/assets/Notifications-CBpqUyAM.js +0 -1
  96. package/dist/assets/Pipeline-jYp-0uE9.js +0 -1
  97. package/dist/assets/Plates-eS6TvGN2.js +0 -1
  98. package/dist/assets/Recordings-C7ZkqUCP.js +0 -1
  99. package/dist/assets/circle-slash-D8H2cOhG.js +0 -1
  100. package/dist/assets/client-CO0rTXhq.js +0 -357
  101. package/dist/assets/device-picker-model-chIcly0V.js +0 -1
  102. package/dist/assets/dist-D6gIHviK.js +0 -357
  103. package/dist/assets/index-EsRvr_Ii.css +0 -2
  104. package/dist/assets/index-JHVJQCLQ.js +0 -4
  105. package/dist/assets/mount-chIcly0V.js +0 -1
  106. package/dist/assets/notification-schedule-field-DWf74Obl.js +0 -1
  107. package/dist/assets/remoteEntry-6T0NU91Z.js +0 -1
  108. package/dist/assets/src-CUxCUGne.js +0 -67
  109. package/dist/assets/useEventInvalidation-chIcly0V.js +0 -1
  110. package/dist/assets/user-round-CsSrwOpd.js +0 -1
@@ -23659,7 +23659,143 @@ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngi
23659
23659
  settings: record(string(), unknown()).optional()
23660
23660
  }), AudioTestResultSchema, { kind: "mutation" }), method(_void(), ConfigUISchemaNullableBridge);
23661
23661
  /**
23662
- * The wire shapes of the Best settings plan and apply (D745), used by the
23662
+ * Wire shapes of the Load balancing surface (D748): the session placement
23663
+ * policy, the atomic share write, the observed placement statistics, the
23664
+ * hardware share suggestion and the stale device pins.
23665
+ */
23666
+ /**
23667
+ * How a new detection session picks its node and device.
23668
+ * - `least-loaded` — the historical rule: lowest `attached / weight`, a
23669
+ * constant node order at a tie (D37). An idle node always ties at 0, so a
23670
+ * weight only bites once a node already holds a session.
23671
+ * - `share` — the share of PARALLEL sessions is held to the weights, and a
23672
+ * full or drowning node yields to a free one (D748).
23673
+ */
23674
+ var SessionPlacementPolicySchema = _enum(["least-loaded", "share"]);
23675
+ var LoadBalancingSharesInputSchema = object({
23676
+ /** nodeId → share (> 0). A node left out keeps its weight. */
23677
+ nodes: record(string(), number().positive()).default({}),
23678
+ /** nodeId → deviceKey → share (> 0). A device left out keeps its weight. */
23679
+ devices: record(string(), record(string(), number().positive())).default({})
23680
+ });
23681
+ var PlacementStatsInputSchema = object({
23682
+ /** Window the observed shares are averaged over (default 1 h, max 24 h). */
23683
+ windowMs: number().int().min(6e4).max(1440 * 60 * 1e3).default(3600 * 1e3) });
23684
+ var PlacementDeviceStatsSchema = object({
23685
+ deviceKey: string(),
23686
+ /** Sessions running on this device now. */
23687
+ sessionsNow: number(),
23688
+ /** Sessions started on this device inside the window. */
23689
+ sessionsStarted: number(),
23690
+ /** Time-weighted share of the node's parallel sessions over the window (0–1); null = no session ran. */
23691
+ observedShare: number().nullable()
23692
+ });
23693
+ var PlacementNodeStatsSchema = object({
23694
+ nodeId: string(),
23695
+ sessionsNow: number(),
23696
+ sessionsStarted: number(),
23697
+ /** Time-weighted share of the cluster's parallel sessions over the window (0–1); null = none ran. */
23698
+ observedShare: number().nullable(),
23699
+ /** Most sessions this node ran at once inside the window. */
23700
+ peakSessions: number(),
23701
+ /** Sessions a share election handed elsewhere because this node was full or drowning. */
23702
+ yieldsAway: number(),
23703
+ devices: array(PlacementDeviceStatsSchema).readonly()
23704
+ });
23705
+ /** A camera's device pin that the session path cannot honour. */
23706
+ var StaleDevicePinSchema = object({
23707
+ deviceId: number(),
23708
+ deviceKey: string(),
23709
+ /** `disabled` — the key exists on some node but is not enabled anywhere; `absent` — no node has it. */
23710
+ reason: _enum(["disabled", "absent"])
23711
+ });
23712
+ var PlacementStatsSchema = object({
23713
+ policy: SessionPlacementPolicySchema,
23714
+ windowMs: number(),
23715
+ /** How much of the window was actually observed (the hub keeps it in memory). */
23716
+ observedForMs: number(),
23717
+ sessionsNow: number(),
23718
+ /** Most parallel sessions across the cluster inside the window. */
23719
+ clusterPeakSessions: number(),
23720
+ nodes: array(PlacementNodeStatsSchema).readonly(),
23721
+ stalePins: array(StaleDevicePinSchema).readonly()
23722
+ });
23723
+ var SuggestSharesInputSchema = object({ headroom: number().min(.3).max(.5).default(.4) });
23724
+ var SuggestedDeviceShareSchema = object({
23725
+ deviceKey: string(),
23726
+ /** Share of the node (0–100, rounded). */
23727
+ share: number(),
23728
+ modelId: string().nullable(),
23729
+ /** Inferences per second at that model, from the measured table. */
23730
+ fps: number().nullable(),
23731
+ measured: boolean(),
23732
+ /** Advisory session cap: ⌊fps × (1 − headroom) / camera fps⌋. Never enforced. */
23733
+ suggestedMaxSessions: number().nullable()
23734
+ });
23735
+ var SuggestedNodeShareSchema = object({
23736
+ nodeId: string(),
23737
+ /** Share of the cluster (0–100, rounded); null = node skipped (offline, unknown hardware). */
23738
+ share: number().nullable(),
23739
+ /** Parallel sessions the node sustains at the suggested models with the headroom kept free. */
23740
+ capacitySessions: number(),
23741
+ devices: array(SuggestedDeviceShareSchema).readonly(),
23742
+ skippedReason: string().nullable()
23743
+ });
23744
+ var SuggestSharesResultSchema = object({
23745
+ headroom: number(),
23746
+ /** Camera detection rate the capacity is counted in (the fastest camera's fps). */
23747
+ cameraFps: number(),
23748
+ /** How many share → model → capacity rounds ran before the shares stopped moving (≤ 3). */
23749
+ iterations: number(),
23750
+ nodes: array(SuggestedNodeShareSchema).readonly()
23751
+ });
23752
+ /**
23753
+ * Where the node and device shares come from (D750).
23754
+ * - `auto` — computed by the system from the cluster's measured capacity at
23755
+ * the Auto tune models, and recomputed whenever a node or device joins,
23756
+ * leaves, is switched on or off, or changes model.
23757
+ * - `manual` — the operator's stored sliders. A node or device that cannot
23758
+ * take sessions gives its share to the others in proportion; the stored
23759
+ * values are never rewritten for that.
23760
+ */
23761
+ var ShareSourceSchema = _enum(["auto", "manual"]);
23762
+ var SetShareSourceInputSchema = object({ source: ShareSourceSchema });
23763
+ object({
23764
+ nodes: record(string(), number()),
23765
+ devices: record(string(), record(string(), number()))
23766
+ });
23767
+ var EffectiveDeviceShareSchema = object({
23768
+ deviceKey: string(),
23769
+ /** Can take sessions now (enabled, available, can run the root). */
23770
+ eligible: boolean(),
23771
+ /** The share the source assigns, as a percentage of the node's devices. */
23772
+ configuredPct: number(),
23773
+ /** The share actually used, after an ineligible device's share went to the others. */
23774
+ effectivePct: number()
23775
+ });
23776
+ var EffectiveNodeShareSchema = object({
23777
+ nodeId: string(),
23778
+ eligible: boolean(),
23779
+ configuredPct: number(),
23780
+ effectivePct: number(),
23781
+ devices: array(EffectiveDeviceShareSchema).readonly()
23782
+ });
23783
+ var EffectiveSharesSchema = object({
23784
+ source: ShareSourceSchema,
23785
+ policy: SessionPlacementPolicySchema,
23786
+ /** `auto` with no computed answer yet: the stored sliders are used meanwhile. */
23787
+ autoPending: boolean(),
23788
+ /** When the automatic shares were last computed (ms epoch); null = never. */
23789
+ computedAt: number().nullable(),
23790
+ /** What made the system recompute them last. */
23791
+ trigger: string().nullable(),
23792
+ nodes: array(EffectiveNodeShareSchema).readonly(),
23793
+ /** The relative weights the election reads (before eligibility). */
23794
+ nodeWeights: record(string(), number()),
23795
+ deviceWeights: record(string(), record(string(), number()))
23796
+ });
23797
+ /**
23798
+ * The wire shapes of the Auto tune plan and apply (D745), used by the
23663
23799
  * `pipeline-orchestrator` cap. The recommender's own types
23664
23800
  * (`recommend.ts`, `demand.ts`) are the TS face of the same data; these
23665
23801
  * schemas are what crosses the cap boundary.
@@ -23735,7 +23871,9 @@ var DeviceDemandSchema = object({
23735
23871
  "estimate",
23736
23872
  "none"
23737
23873
  ]),
23738
- observedForMs: number().nullable()
23874
+ observedForMs: number().nullable(),
23875
+ /** How on-motion sessions were charged: per-device observation, or split by share (D748). */
23876
+ placement: SessionPlacementPolicySchema
23739
23877
  });
23740
23878
  var DeviceModelChoiceSchema = object({
23741
23879
  modelId: string(),
@@ -23792,7 +23930,7 @@ var DetectorStoreClearSchema = object({
23792
23930
  deviceId: number(),
23793
23931
  keys: array(string()).readonly()
23794
23932
  });
23795
- var BestSettingsWarningSchema = discriminatedUnion("kind", [
23933
+ var AutoTuneWarningSchema = discriminatedUnion("kind", [
23796
23934
  object({
23797
23935
  kind: literal("detector-store-cluster-wide"),
23798
23936
  skippedNodes: array(string()).readonly()
@@ -23807,26 +23945,36 @@ var BestSettingsWarningSchema = discriminatedUnion("kind", [
23807
23945
  deviceKey: string()
23808
23946
  })
23809
23947
  ]);
23810
- var BestSettingsOptionsSchema = object({
23811
- /** Share of each accelerator's throughput kept free (0.3–0.5). */
23812
- headroom: number().min(.3).max(.5).default(.4) });
23813
- var BestSettingsPlanSchema = object({
23948
+ var AutoTuneOptionsSchema = object({
23949
+ /** Share of each accelerator's throughput kept free (0.3–0.5). */
23950
+ headroom: number().min(.3).max(.5).default(.4),
23951
+ /**
23952
+ * What-if shares (D748): plan as if these node/device shares were stored
23953
+ * and the policy were `share`. Absent = the stored shares under the stored
23954
+ * policy. A what-if plan is for display; apply always re-plans from what
23955
+ * is stored.
23956
+ */
23957
+ shares: LoadBalancingSharesInputSchema.optional()
23958
+ });
23959
+ var AutoTunePlanSchema = object({
23814
23960
  /** Hash of everything the apply will write — the apply refuses a different one. */
23815
23961
  planHash: string(),
23816
23962
  family: literal("yolov9"),
23817
23963
  headroom: number(),
23964
+ /** Planned under what-if shares (D748): for display — apply refuses it as stale. */
23965
+ whatIf: boolean(),
23818
23966
  generatedAt: number(),
23819
23967
  nodes: array(NodeRecommendationSchema).readonly(),
23820
23968
  nodeChanges: array(NodeDeviceChangeSchema).readonly(),
23821
23969
  cameraClears: array(CameraOverrideClearSchema).readonly(),
23822
23970
  detectorStoreClears: array(DetectorStoreClearSchema).readonly(),
23823
- warnings: array(BestSettingsWarningSchema).readonly()
23971
+ warnings: array(AutoTuneWarningSchema).readonly()
23824
23972
  });
23825
- var BestSettingsApplyInputSchema = object({
23973
+ var AutoTuneApplyInputSchema = object({
23826
23974
  planHash: string(),
23827
23975
  headroom: number().min(.3).max(.5).default(.4)
23828
23976
  });
23829
- var BestSettingsPhaseResultSchema = object({
23977
+ var AutoTunePhaseResultSchema = object({
23830
23978
  phase: _enum([
23831
23979
  "download",
23832
23980
  "camera-overrides",
@@ -23837,19 +23985,19 @@ var BestSettingsPhaseResultSchema = object({
23837
23985
  ok: boolean(),
23838
23986
  detail: string()
23839
23987
  });
23840
- var BestSettingsApplyResultSchema = discriminatedUnion("kind", [
23988
+ var AutoTuneApplyResultSchema = discriminatedUnion("kind", [
23841
23989
  object({
23842
23990
  kind: literal("applied"),
23843
23991
  planHash: string(),
23844
- phases: array(BestSettingsPhaseResultSchema).readonly()
23992
+ phases: array(AutoTunePhaseResultSchema).readonly()
23845
23993
  }),
23846
23994
  object({
23847
23995
  kind: literal("aborted"),
23848
- phases: array(BestSettingsPhaseResultSchema).readonly()
23996
+ phases: array(AutoTunePhaseResultSchema).readonly()
23849
23997
  }),
23850
23998
  object({
23851
23999
  kind: literal("stale"),
23852
- plan: BestSettingsPlanSchema
24000
+ plan: AutoTunePlanSchema
23853
24001
  }),
23854
24002
  object({
23855
24003
  kind: literal("refused"),
@@ -25036,7 +25184,6 @@ var CameraStepOverridePatchSchema = object({
25036
25184
  settings: record(string(), unknown()).readonly().optional()
25037
25185
  });
25038
25186
  var CameraPipelineSettingsSchema = object({
25039
- pinnedAgentNodeId: string().optional(),
25040
25187
  stepToggles: record(string(), boolean()).optional(),
25041
25188
  stepOverridesByDevice: record(string(), record(string(), record(string(), CameraStepOverridePatchSchema))).optional(),
25042
25189
  pipelineByAgent: record(string(), CameraPipelineForAgentSchema).optional()
@@ -25535,12 +25682,6 @@ method(object({
25535
25682
  }), object({ success: literal(true) }), {
25536
25683
  kind: "mutation",
25537
25684
  auth: "admin"
25538
- }), method(object({
25539
- agentNodeId: string(),
25540
- detectWeight: number().positive().nullable()
25541
- }), object({ success: literal(true) }), {
25542
- kind: "mutation",
25543
- auth: "admin"
25544
25685
  }), method(object({
25545
25686
  agentNodeId: string(),
25546
25687
  detect: boolean().nullable().optional(),
@@ -25582,7 +25723,13 @@ method(object({
25582
25723
  }), {
25583
25724
  kind: "mutation",
25584
25725
  auth: "admin"
25585
- }), method(BestSettingsOptionsSchema, BestSettingsPlanSchema, { auth: "admin" }), method(BestSettingsApplyInputSchema, BestSettingsApplyResultSchema, {
25726
+ }), method(AutoTuneOptionsSchema, AutoTunePlanSchema, { auth: "admin" }), method(AutoTuneApplyInputSchema, AutoTuneApplyResultSchema, {
25727
+ kind: "mutation",
25728
+ auth: "admin"
25729
+ }), method(LoadBalancingSharesInputSchema, object({ success: literal(true) }), {
25730
+ kind: "mutation",
25731
+ auth: "admin"
25732
+ }), method(PlacementStatsInputSchema, PlacementStatsSchema, { auth: "admin" }), method(SuggestSharesInputSchema, SuggestSharesResultSchema, { auth: "admin" }), method(_void(), EffectiveSharesSchema, { auth: "admin" }), method(SetShareSourceInputSchema, object({ success: literal(true) }), {
25586
25733
  kind: "mutation",
25587
25734
  auth: "admin"
25588
25735
  }), method(object({ deviceId: number() }), CameraPipelineSettingsSchema.nullable()), method(object({
@@ -41382,7 +41529,7 @@ Object.freeze({
41382
41529
  addonId: null,
41383
41530
  access: "view"
41384
41531
  },
41385
- "pipelineOrchestrator.applyBestSettings": {
41532
+ "pipelineOrchestrator.applyAutoTune": {
41386
41533
  capName: "pipeline-orchestrator",
41387
41534
  capScope: "system",
41388
41535
  addonId: null,
@@ -41502,6 +41649,12 @@ Object.freeze({
41502
41649
  addonId: null,
41503
41650
  access: "view"
41504
41651
  },
41652
+ "pipelineOrchestrator.getEffectiveShares": {
41653
+ capName: "pipeline-orchestrator",
41654
+ capScope: "system",
41655
+ addonId: null,
41656
+ access: "view"
41657
+ },
41505
41658
  "pipelineOrchestrator.getGlobalMetrics": {
41506
41659
  capName: "pipeline-orchestrator",
41507
41660
  capScope: "system",
@@ -41538,6 +41691,12 @@ Object.freeze({
41538
41691
  addonId: null,
41539
41692
  access: "view"
41540
41693
  },
41694
+ "pipelineOrchestrator.getPlacementStats": {
41695
+ capName: "pipeline-orchestrator",
41696
+ capScope: "system",
41697
+ addonId: null,
41698
+ access: "view"
41699
+ },
41541
41700
  "pipelineOrchestrator.getReconcileFromDiskStatus": {
41542
41701
  capName: "pipeline-orchestrator",
41543
41702
  capScope: "system",
@@ -41562,7 +41721,7 @@ Object.freeze({
41562
41721
  addonId: null,
41563
41722
  access: "create"
41564
41723
  },
41565
- "pipelineOrchestrator.planBestSettings": {
41724
+ "pipelineOrchestrator.planAutoTune": {
41566
41725
  capName: "pipeline-orchestrator",
41567
41726
  capScope: "system",
41568
41727
  addonId: null,
@@ -41628,12 +41787,6 @@ Object.freeze({
41628
41787
  addonId: null,
41629
41788
  access: "create"
41630
41789
  },
41631
- "pipelineOrchestrator.setAgentDetectWeight": {
41632
- capName: "pipeline-orchestrator",
41633
- capScope: "system",
41634
- addonId: null,
41635
- access: "create"
41636
- },
41637
41790
  "pipelineOrchestrator.setAgentInferenceDevices": {
41638
41791
  capName: "pipeline-orchestrator",
41639
41792
  capScope: "system",
@@ -41688,12 +41841,30 @@ Object.freeze({
41688
41841
  addonId: null,
41689
41842
  access: "create"
41690
41843
  },
41844
+ "pipelineOrchestrator.setLoadBalancingShares": {
41845
+ capName: "pipeline-orchestrator",
41846
+ capScope: "system",
41847
+ addonId: null,
41848
+ access: "create"
41849
+ },
41691
41850
  "pipelineOrchestrator.setPipelineDevicePin": {
41692
41851
  capName: "pipeline-orchestrator",
41693
41852
  capScope: "system",
41694
41853
  addonId: null,
41695
41854
  access: "create"
41696
41855
  },
41856
+ "pipelineOrchestrator.setShareSource": {
41857
+ capName: "pipeline-orchestrator",
41858
+ capScope: "system",
41859
+ addonId: null,
41860
+ access: "create"
41861
+ },
41862
+ "pipelineOrchestrator.suggestShares": {
41863
+ capName: "pipeline-orchestrator",
41864
+ capScope: "system",
41865
+ addonId: null,
41866
+ access: "view"
41867
+ },
41697
41868
  "pipelineOrchestrator.unassignAudio": {
41698
41869
  capName: "pipeline-orchestrator",
41699
41870
  capScope: "system",
@@ -49034,7 +49205,7 @@ var AdminUIAddon = class extends BaseAddon {
49034
49205
  capability: adminUiCapability,
49035
49206
  provider: {
49036
49207
  getStaticDir: async () => ({ staticDir: resolveAdminUiDistDir() }),
49037
- getVersion: async () => ({ version: "1.2.343" })
49208
+ getVersion: async () => ({ version: "1.2.345" })
49038
49209
  }
49039
49210
  }];
49040
49211
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-admin-ui",
3
- "version": "1.2.343",
3
+ "version": "1.2.345",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Admin UI — Vite frontend build and server-side addon",
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,R as r,S as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as d,gt as f,st as p,vt as m}from"./player-overlays-BElx6KR1.js";import{Cd as h,Cr as g,Fn as _,Iu as v,Ll as y,R as b,Sr as x,Su as S,Tl as C,Tu as w,_o as T,_r as ee,ad as E,ar as te,cr as ne,dr as D,eu as O,fr as k,gr as re,gu as A,ht as ie,ir as ae,k as j,lr as M,lu as oe,mr as se,mt as ce,or as le,pd as N,pr as P,rr as F,sr as I,su as L,tr as R,uu as ue,vd as de,vl as z,vr as B,xd as fe,xl as V,xr as pe,yr as H,yu as U}from"./src-CUxCUGne.js";import{Gr as W}from"./client-CO0rTXhq.js";import"./mount-chIcly0V.js";import{F as me,N as he}from"./index-JHVJQCLQ.js";import{t as G}from"./AdminPage-CiKtOLQm.js";import{t as ge}from"./NodeAddonsSettingsPanel-CCzjSPCH.js";import{r as K,t as q}from"./useNodeUrlSelection-C32KGJ5p.js";var J=m(`octagon-alert`,[[`path`,{d:`M12 16h.01`,key:`1drbdi`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z`,key:`1fd625`}]]);n();var Y=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),_e=new Set([`done`,`failed`,`skipped`]);function X(e){return!_e.has(e.phase)&&!Y.has(e.jobState)}function Z(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=Y.has(e.state);for(let i of e.tasks)r&&i.finishedAtMs!==null&&t-i.finishedAtMs>6e4||n.set(i.packageName,{jobId:e.jobId,packageName:i.packageName,phase:i.phase,fromVersion:i.fromVersion,toVersion:i.toVersion,error:i.error,jobState:e.state,finishedAtMs:i.finishedAtMs})}return n}function ve(){let{data:e}=D({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=V(W.AddonsJobProgress,e=>e.job.jobId);return a(()=>{let n=new Map;for(let t of e??[])n.set(t.jobId,t);for(let[e,r]of t)n.set(e,r.job);return Z([...n.values()],Date.now())},[e,t])}var ye={queued:{icon:N,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:v,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:v,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:v,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:v,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:v,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:v,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:h,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:J,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:O,cls:`bg-muted text-foreground-subtle`,label:`skipped`}};function be({progress:e}){let t=ye[e.phase],n=t.icon,r=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return i(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${t.cls}`,title:r,children:[l(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label,i(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function xe({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:a,onSelect:s,selectedVersion:c}){let u=n===`upload`||n===`local`,{data:d,isLoading:f}=I({name:e});return i(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[i(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[l(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),l(`button`,{type:`button`,onClick:a,className:`text-foreground-subtle hover:text-foreground`,children:l(C,{className:`h-3 w-3`})})]}),u&&i(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[l(y,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),i(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[i(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,l(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),f&&i(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[l(v,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),d&&l(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:d.map(e=>{let n=e.version===t,a=s!==void 0&&e.version===c,d=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),f=i(o,{children:[l(`span`,{className:`font-mono flex-1 text-left ${n?`text-primary font-semibold`:d?`text-amber-400`:`text-foreground`}`,children:e.version}),n&&l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:`current`}),e.distTags.map(e=>l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),e.deprecated&&l(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),l(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return s?i(`button`,{type:`button`,"aria-label":`Select ${e.version}`,onClick:()=>s(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${a?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,a?l(h,{className:`h-3 w-3 text-primary shrink-0`}):l(`span`,{className:`w-3 shrink-0`})]},e.version):i(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,n&&!u?l(h,{className:`h-3 w-3 text-primary shrink-0`}):l(`button`,{type:`button`,onClick:()=>r(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:n?`Re-install ${e.version} from npm`:`Install ${e.version}`,children:l(E,{className:`h-3 w-3`})})]},e.version)})}),d&&d.length===0&&l(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var Se={queued:{icon:N,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:v,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:A,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:h,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:J,bg:`bg-danger/10 text-danger`,label:`failed`}};function Q({item:e}){let t=Se[e.status],n=t.icon;return i(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[l(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}n();var Ce=`device-export`;function we(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===Ce)}function Te({isBundle:e,installSource:t,addonId:n,iconPath:r,color:a}){let[o,s]=c(!1),u=a?{backgroundColor:`${a.startsWith(`#`)?a:`#${a}`}26`}:void 0,f=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,p=n&&r?d(`/api/addon-assets/${n}/${r}`):null,m=!!p&&!o;return i(`div`,{className:`relative flex-shrink-0`,children:[l(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${u?``:f}`,style:u,children:m?l(`img`,{src:p,alt:n,className:`h-5 w-5`,onError:()=>s(!0)}):l(e?w:U,{className:`h-4 w-4`})}),t===`local`&&l(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),t===`npm`&&l(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:l(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:l(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&l(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:l(y,{className:`h-2.5 w-2.5 text-white`})})]})}function Ee({version:e,availableUpdate:t,selectedVersion:n,isUpdating:r,installSource:a,disabled:o,onUpdate:s,onOpenPicker:c,children:u}){if(r)return i(`span`,{className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[l(v,{className:`h-3 w-3 animate-spin`}),`Updating…`]});if(t){let r=n??t;return i(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[s&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:o,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-semibold border border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:`Update to ${r}`,children:[l(E,{className:`h-3 w-3`}),`Update`]}),i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:o,"aria-label":`Select version to install`,title:`Installed ${e} — update available. Selected ${r}; tap to choose another version.`,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border border-amber-500/40 bg-amber-500/15 text-amber-500 hover:bg-amber-500/25 animate-pulse disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[l(`span`,{className:`font-normal opacity-70`,children:e}),l(`span`,{className:`font-normal opacity-70`,children:`→`}),r,l(f,{className:`h-3 w-3`})]}),u]})}return i(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:o,className:[`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,a===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:`Version ${e} — tap to view all versions`,children:[e,l(f,{className:`h-3 w-3 opacity-50`})]}),u]})}function De({addonId:e}){let t=s(),{data:n=`inherit`}=ae({addonId:e}),r=B({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return l(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>l(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}function Oe({addon:e,agents:t=[],clusterStatus:n,hideVersion:r,availableUpdate:a,onUpdate:d,isUpdating:m,jobProgress:h,bundle:g,bulkItem:v,disabledByBulk:y,isSystem:T}){let[ee,E]=c(!1),[te,D]=c(!1),[O,k]=c(!1),[ae,j]=c(null);u(()=>{j(null)},[a]);let M=ae??a,[oe,le]=c(!1),[N,P]=c(!1),[F,I]=c(`logs`),R=s(),de=he(),z=_(),{manifest:B}=e,V=e.installedOn??[],pe=!g&&!B.protected&&B.removable!==!1,H=!!g,U=g?.displayName??B.name,W=g?.packageName??B.packageName,me=g?.version??B.packageVersion??B.version,G=g?.installSource??e.installSource,K=g?g.bundle?.description??g.addons[0]?.manifest.description:B.description,q=x({onSuccess:()=>{R.invalidateQueries({queryKey:[[`addons`]]}),R.invalidateQueries({queryKey:[[`addonPages`]]}),R.invalidateQueries({queryKey:[[`capabilities`]]})}}),Y=se({onSuccess:()=>{R.invalidateQueries({queryKey:[[`addons`]]})}}),_e=ne({onSuccess:()=>{R.invalidateQueries({queryKey:[[`addons`]]}),R.invalidateQueries({queryKey:[[`addonPages`]]}),R.invalidateQueries({queryKey:[[`capabilities`]]}),R.invalidateQueries({queryKey:[[`integrations`]]})}}),X=re({onSuccess:()=>{R.invalidateQueries({queryKey:[[`addons`]]}),R.invalidateQueries({queryKey:[[`alerts`]]})}}),Z=e.health,ve=Z?.phase===`failed`&&!Z.inGracePeriod,ye=ve&&Z?.nextRetryAt&&!Z.retrying;return i(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${ve?`border-red-500/50`:`border-border`}`,children:[ve&&Z&&i(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[l(J,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,Z.retryCount,`)`]}),l(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:Z.lastError?.message??`Unknown error`}),ye&&Z.nextRetryAt&&i(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(Z.nextRetryAt).toLocaleTimeString()]})]}),i(`button`,{type:`button`,disabled:X.isPending||Z.retrying,onClick:e=>{e.stopPropagation(),X.mutate({packageName:W})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:`Reset retry counter and force immediate reload`,children:[l(A,{className:`h-3 w-3 ${X.isPending||Z.retrying?`animate-spin`:``}`}),`Retry now`]})]}),i(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[l(Te,{isBundle:H||!!B.components&&B.components.length>1,installSource:G,addonId:H?g.addons[0]?.manifest.id:B.id,iconPath:H?g.bundle?.icon??g.addons[0]?.manifest.icon:B.icon,color:H?g.addons[0]?.manifest.color:B.color}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`flex items-start justify-between gap-2`,children:[l(`span`,{className:`text-sm font-semibold text-foreground truncate min-w-0`,children:U}),!r&&l(Ee,{version:me,availableUpdate:a,...M===void 0?{}:{selectedVersion:M},isUpdating:m,installSource:G,disabled:y,...d&&M!==void 0?{onUpdate:()=>d(M)}:{},onOpenPicker:()=>k(e=>!e),children:O&&l(xe,{packageName:W,currentVersion:me,...G?{installSource:G}:{},...a!==void 0&&M!==void 0?{selectedVersion:M,onSelect:e=>{j(e),k(!1)}}:{},onInstall:e=>{k(!1),_e.mutate({packageName:W,version:e})},onClose:()=>k(!1)})})]}),i(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[W!==U&&l(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:W}),H&&i(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[l(w,{className:`h-3 w-3`}),g.addons.length]}),T&&i(`span`,{className:`text-[10px] rounded-full bg-amber-500/15 text-amber-700 dark:text-amber-300 px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,title:`System package — updating restarts the hub`,children:[l(A,{className:`h-3 w-3`}),`System`]}),v!=null&&l(Q,{item:v}),h!=null&&l(be,{progress:h})]}),K&&l(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:K}),!H&&e.process&&i(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?`forked`:`in-process`}),e.process.pid!=null&&i(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:e.process.state===`crashed`||e.process.state===`failed`?`bg-red-500/15 text-red-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.state})]})]})]}),!H&&i(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),Y.mutate({addonId:B.id})},disabled:Y.isPending||y,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors`,children:[l(A,{className:`h-3 w-3 ${Y.isPending?`animate-spin`:``}`}),`Restart`]}),i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),le(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${oe?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[l(ue,{className:`h-3 w-3`}),`Logs`]}),!H&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),P(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${N?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[l(L,{className:`h-3 w-3`}),`Settings`]}),l(`div`,{className:`flex-1`}),pe&&i(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await z({title:`Uninstall ${B.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&q.mutate({packageName:B.packageName})},disabled:q.isPending||y,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors`,children:[l(p,{className:`h-3 w-3`}),q.isPending?`Removing...`:`Uninstall`]})]}),n&&n.nodes.length>1&&!H&&i(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),l(`div`,{className:`space-y-1`,children:n.nodes.map(e=>i(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),l(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),l(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:`outdated`}),e.status===`offline`&&l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&l(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),oe&&!H&&i(`div`,{className:`border-t border-border`,children:[i(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[i(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[l(`button`,{type:`button`,onClick:()=>I(`logs`),className:`px-2 py-0.5 transition-colors ${F===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),l(`button`,{type:`button`,onClick:()=>I(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${F===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),l(`div`,{className:`flex-1`}),l(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),le(!1)},className:`text-foreground-subtle hover:text-foreground`,children:l(C,{className:`h-3.5 w-3.5`})})]}),F===`logs`&&l(ie,{addonId:B.id,maxHeight:`max-h-64`,showFilters:!1}),F===`events`&&l(ce,{addonId:B.id,category:`addon.*`,maxHeight:`max-h-64`})]}),H&&i(o,{children:[l(`button`,{type:`button`,onClick:()=>E(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:l(ee?fe:f,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),ee&&l(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:g.addons.map(e=>l(Oe,{addon:e,agents:t,hideVersion:!0},e.manifest.id))})]}),N&&!H&&l(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>P(!1),children:i(`div`,{className:`w-full max-w-lg max-h-[80vh] rounded-xl border border-border bg-surface shadow-2xl flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[i(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[i(`div`,{className:`flex items-center gap-2`,children:[l(L,{className:`h-4 w-4 text-primary`}),i(`h2`,{className:`text-sm font-semibold text-foreground`,children:[U,` Settings`]})]}),l(`button`,{onClick:()=>P(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:l(C,{className:`h-4 w-4`})})]}),i(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[l(`div`,{className:`text-[10px] text-foreground-subtle mb-2`,children:`Cluster-wide settings — one value for every node. Per-node settings live under Cluster → the node → Settings.`}),l(ge,{nodeId:null,addonIds:[B.id],level:`global`,fieldScope:`cluster`,emptyMessage:`This addon exposes no cluster-wide settings. Anything it can configure is per-node — open it from Cluster → the node → Settings.`}),we(B)&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),l(b,{addonId:B.id,onOpenDevice:e=>de(`/devices/${e}`)})]}),G===`npm`&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),l(De,{addonId:B.id})]}),B.components&&B.components.length>0&&i(`div`,{children:[i(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,B.components.length,`)`]}),l(`div`,{className:`flex flex-wrap gap-1`,children:B.components.map(e=>l(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),t.length>=2&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),i(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[V.length===0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),V.map(e=>l(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),i(`div`,{className:`relative`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),D(e=>!e)},className:`inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:border-primary transition-colors`,title:`Install on more agents`,children:[l(S,{className:`h-3 w-3`}),`Add agent`]}),te&&i(`div`,{className:`absolute left-0 top-full mt-1 z-10 min-w-[160px] rounded-md border border-border bg-surface shadow-lg overflow-hidden`,children:[t.filter(e=>!e.isHub&&!V.includes(e.name)).map(e=>l(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),D(!1)},className:`w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors`,children:e.name},e.id)),t.filter(e=>!e.isHub&&!V.includes(e.name)).length===0&&l(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),l(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:l(`button`,{type:`button`,onClick:()=>P(!1),className:`rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:`Close`})})]})})]})}n();var ke=`.tgz,.tar.gz,.zip`;function Ae({onUploadSuccess:n}){let[r,a]=c(!1),s=t(null),u=e(async e=>{a(!0);let t=new FormData;t.append(`file`,e);let r=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(d(`/api/addons/upload`),{method:`POST`,headers:{Authorization:`Bearer ${r}`},body:t})).json()).success&&n()}finally{a(!1)}},[n]);return i(o,{children:[l(`input`,{ref:s,type:`file`,accept:ke,onChange:e(e=>{let t=e.target.files?.[0];t&&u(t),e.target.value=``},[u]),className:`hidden`}),i(`button`,{type:`button`,onClick:()=>s.current?.click(),disabled:r,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[r?l(v,{className:`w-3.5 h-3.5 animate-spin`}):l(y,{className:`w-3.5 h-3.5`}),r?`Uploading...`:`Upload`]})]})}n();var je=[{seconds:900,label:`15m`},{seconds:3600,label:`1h`},{seconds:21600,label:`6h`},{seconds:43200,label:`12h`},{seconds:86400,label:`24h`}],Me=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function Ne(e){return e!==void 0&&Me.has(e)}var Pe={id:`hub`,name:`Hub`,isHub:!0,isOnline:!0};function Fe(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function Ie(e){let t=e;if(!t?.manifest)return null;let n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??`0.0.0`,capabilities:t.manifest.capabilities??[]},r=t.process,i=r?{pid:r.pid,mode:r.mode===`forked`?`forked`:`in-process`,state:r.state??`unknown`}:void 0,a=t.health,o=t.declaration?.execution,s=t.manifest.execution,c=o?.placement??s?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...i?{process:i}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function Le(e){let t=new Map,n=[];for(let r of e){let e=r.manifest.packageName;if(!e){n.push(r);continue}let i=t.get(e);if(i)i.addons.push(r);else{let n=r.manifest.bundle,i={packageName:e,displayName:n?.displayName??r.manifest.packageDisplayName??r.manifest.name,version:r.manifest.packageVersion,addons:[r],...r.installSource===void 0?{}:{installSource:r.installSource},...n===void 0?{}:{bundle:n}};t.set(e,i)}}let r=[];for(let e of t.values())e.bundle!==void 0||e.addons.length>=2?r.push({bundle:e,representative:e.addons[0]}):r.push(e.addons[0]);return r.push(...n),r}function $(e){return`bundle`in e}function Re({addons:n,clusterStatus:o,selectedNode:d,onRefresh:f,isRefreshing:p}){let m=s(),[y,b]=c(``),x=r(y),[S,C]=c(!1),w=t(null);u(()=>{if(!S)return;let e=e=>{w.current&&!w.current.contains(e.target)&&C(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[S]);let{data:T}=k({nodeId:d.id}),D=a(()=>{let e=new Map;for(let t of T??[])e.set(t.name,t.latestVersion);return e},[T]),O=a(()=>(T??[]).filter(e=>!e.isSystem).length,[T]),[re,ie]=c(()=>new Set),[ae,j]=c(()=>new Map),M=e(e=>{ie(t=>new Set(t).add(e))},[]),se=e(e=>{ie(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),ce=e((e,t)=>{j(n=>new Map(n).set(e,t))},[]),N=e(e=>{j(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),P=g({onMutate:e=>{M(e.name),N(e.name)},onSuccess:(e,t)=>{se(t.name);let n=e;if(n&&n.success===!1){ce(t.name,n.error??`Update failed (no error message returned by server)`);return}m.invalidateQueries({queryKey:[[`addons`]]}),m.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{se(t.name),ce(t.name,e instanceof Error?e.message:String(e))}}),F=ve(),I=t(new Set);u(()=>{let e=new Set;for(let[t,n]of F)X(n)&&e.add(t);let t=[...I.current].some(t=>!e.has(t));I.current=e,t&&(m.invalidateQueries({queryKey:[[`addons`]]}),m.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[F,m]);let{data:L}=te(void 0),ue=R({onSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),z=H({onSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:B,isFetching:fe}=ee({query:x||void 0},{enabled:S}),V=pe(),{data:U}=le(void 0),W=U?.requestedAt,[he,G]=c(null),[ge,K]=c(!1);u(()=>{if(U?.kind===`framework-bulk-update`&&U.requestedAt!==he){G(U.requestedAt),K(!0);let e=window.setTimeout(()=>K(!1),6e3);return()=>window.clearTimeout(e)}},[W,he,U]),_();let q=e(async()=>{let e=(T??[]).filter(e=>!e.isSystem);if(e.length!==0){if(!d.isHub){for(let t of e)await P.mutateAsync({name:t.name,version:t.latestVersion,nodeId:d.id});return}await V.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[d.id]})}},[T,d.id,d.isHub,V,P]),J=ne({onSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`]]}),m.invalidateQueries({queryKey:[[`addonPages`]]}),m.invalidateQueries({queryKey:[[`capabilities`]]}),m.invalidateQueries({queryKey:[[`integrations`]]})}}),[Y,_e]=c(`type`),[Z,ye]=c(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),be=e=>{ye(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[xe,Se]=me(),Q=xe.get(`capability`),Ce=a(()=>{let e=n.filter(e=>!Ne(e.manifest.packageName));return d.isHub||(e=e.filter(e=>Fe(e.placement,d.isHub))),Q&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===Q))),e},[n,d.isHub,Q]),we=()=>{let e=new URLSearchParams(xe);e.delete(`capability`),Se(e,{replace:!0})},Te=Z===`flat`?Ce:Le(Ce),Ee=a(()=>{let e=[...Te];switch(Y){case`type`:e.sort((e,t)=>{let n=+!$(e),r=+!$(t);if(n!==r)return n-r;let i=$(e)?e.bundle.displayName:e.manifest.name,a=$(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=$(e)?e.bundle.displayName:e.manifest.name,r=$(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=$(e)?e.bundle.installSource??``:e.installSource??``,r=$(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[Te,Y]);return i(`div`,{className:`space-y-4`,children:[[...ae.entries()].map(([e,t])=>l(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:i(`div`,{className:`flex items-start justify-between gap-3`,children:[i(`div`,{className:`space-y-0.5`,children:[i(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,e]}),l(`div`,{className:`text-foreground-subtle font-mono`,children:t})]}),l(`button`,{type:`button`,onClick:()=>N(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})},e)),i(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),i(`select`,{value:Y,onChange:e=>_e(e.target.value),className:`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground focus:outline-none focus:border-primary/50`,children:[l(`option`,{value:`type`,children:`Bundles first`}),l(`option`,{value:`name`,children:`Name`}),l(`option`,{value:`source`,children:`Install source`})]})]}),i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),l(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>l(`button`,{type:`button`,onClick:()=>be(e),className:`px-2.5 py-1.5 transition-colors capitalize ${Z===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?`Group multi-addon packages into a bundle card`:`Show every addon as its own card`,children:e},e))})]}),d.isHub&&i(`div`,{className:`flex items-center gap-1.5`,children:[l(A,{className:`h-3 w-3 text-foreground-subtle`}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),l(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>l(`button`,{type:`button`,onClick:()=>ue.mutate({channel:e}),disabled:ue.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${L?.channel===e?e===`off`?`bg-gray-700 text-gray-200`:e===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${e===`off`?``:`border-l border-border`}`,children:e},e))})]}),d.isHub&&i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Check every:`}),l(`select`,{className:`rounded-md border border-border bg-transparent px-1.5 py-1 text-[10px] font-medium text-foreground-subtle`,value:L?.updateCheckIntervalSeconds??21600,disabled:z.isPending||L===void 0,onChange:e=>{L!==void 0&&z.mutate({channel:L.channel,updateCheckIntervalSeconds:Number(e.target.value)})},children:je.map(e=>l(`option`,{value:e.seconds,children:e.label},e.seconds))})]}),O>0&&i(`button`,{type:`button`,onClick:()=>void q(),disabled:V.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium`,children:[V.isPending?l(v,{className:`w-3 h-3 animate-spin`}):l(E,{className:`w-3 h-3`}),V.isPending?`Updating…`:`Update All (${O})`]}),i(`button`,{type:`button`,onClick:f,disabled:p||V.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[l(A,{className:`w-3 h-3 ${p?`animate-spin`:``}`}),`Refresh`]})]}),i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:w,children:[l(oe,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),l(`input`,{type:`text`,value:y,onChange:e=>{b(e.target.value),C(!0)},onFocus:()=>C(!0),placeholder:`Search addons on npm...`,disabled:V.isPending,className:`w-full rounded-lg border border-border bg-background pl-9 pr-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-50 disabled:cursor-not-allowed`}),fe&&l(v,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),S&&B&&B.length>0&&i(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,children:[B.length>0&&i(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,B.length,`)`]}),B&&B.length>0&&l(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:B.map(e=>i(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[l(`div`,{className:`w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0`,children:e.name.replace(`@camstack/addon-`,``).charAt(0).toUpperCase()}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[l(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),l(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&l(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?i(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md border border-emerald-500/30 bg-emerald-500/10 text-emerald-400 shrink-0`,children:[l(h,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):i(`button`,{type:`button`,onClick:()=>J.mutate({packageName:e.name}),disabled:J.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[J.isPending?l(v,{className:`h-3 w-3 animate-spin`}):l(E,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),l(Ae,{onUploadSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`]]}),f()}})]}),Q&&i(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[l(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),l(`span`,{className:`font-mono text-primary font-semibold`,children:Q}),l(`button`,{type:`button`,onClick:we,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),ge&&i(`div`,{className:`fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm max-w-sm pointer-events-auto`,children:[l(de,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),i(`div`,{children:[l(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),l(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),Ce.length===0&&l(`div`,{className:`text-xs text-foreground-subtle`,children:n.length===0?`No addons installed`:Q?`No installed addons declare the "${Q}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${d.name} (placement filter active)`}),l(`div`,{className:`space-y-2`,children:Ee.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,n=D.get(t),r=$(e)?e.representative:e,i=n?e=>P.mutate({name:t,version:e,nodeId:d.id}):void 0,a=F.get(t)??null,s=a!==null&&X(a);return l(Oe,{addon:r,clusterStatus:o?.[r.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:n,isUpdating:re.has(t)||s,jobProgress:a,onUpdate:i,disabledByBulk:V.isPending},$(e)?t:e.manifest.id)})})]})}function ze(){let e=s(),{data:n,isLoading:r,isError:a}=M(),{data:o}=T(void 0),{nodes:c}=z(),{selection:d,selectNode:f,requestedNodeId:p}=q(c.length>0?c:[Pe]),m=d.node??Pe,h=m.id,g=c.length>0?d.staleNodeId:null,_=F(),v=P(),y=_.isPending||v.isPending,b=async()=>{await _.mutateAsync({nodeId:h}),await v.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},x=t(_);x.current=_;let S=t(p??`hub`);u(()=>{x.current.mutate({nodeId:S.current})},[]);let C=(n??[]).map(Ie).filter(e=>e!==null);return i(G,{children:[i(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[l(j,{selectedNodeId:h,onSelect:f}),i(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!r&&!a&&i(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[C.length,` installed`]}),i(`button`,{type:`button`,onClick:()=>void b(),disabled:y,className:`inline-flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:`Re-fetch addons + check npm for new versions`,children:[l(A,{className:`w-3 h-3 ${y?`animate-spin`:``}`}),`Check for updates`]})]})]}),l(K,{staleNodeId:g,shownNodeName:m.name}),!m.isHub&&i(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[`Showing only addons compatible with`,` `,l(`span`,{className:`font-medium text-foreground`,children:m.name}),` — agents only run`,` `,l(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,l(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),r&&l(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),a&&l(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!r&&!a&&l(Re,{addons:C,clusterStatus:o,selectedNode:m,onRefresh:()=>void b(),isRefreshing:y})]})}export{ze as AddonsPage};
@@ -1,3 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{W as d,Z as f,_t as p,at as m,ct as h,st as g,vt as _}from"./player-overlays-BElx6KR1.js";import{$t as v,Cn as y,Iu as b,Jt as x,Ju as S,Ki as C,Kt as w,Od as T,Qt as E,Su as D,Tl as ee,Tt as O,Un as k,Xt as A,Yl as j,Yu as te,Zt as M,ad as ne,cd as N,cu as P,dd as F,dn as I,k as L,lu as R,qt as z,tn as B,vn as V,wn as H,wt as U,wu as W,xn as G,xu as K}from"./src-CUxCUGne.js";import{t as re}from"./boxes-BTpyboKa.js";import{t as ie}from"./send-B6nyL8aN.js";import{On as q}from"./client-CO0rTXhq.js";import{t as J}from"./useTranslation-Bc5yH9V9.js";import"./mount-chIcly0V.js";import{t as Y}from"./AdminPage-CiKtOLQm.js";import{t as ae}from"./AdminTabs-D49DFF7T.js";var oe=_(`message-square-plus`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]);n();var se=[`llm`,`listProfiles`],ce=[`llm`,`listProfileKinds`],le=[`llm`,`getDefaults`],ue=[`llm`,`listRuntimeNodes`],de=[`llm`,`listModelCatalog`],fe=[`llm`,`getUsage`],pe=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],me=new Map(Object.entries({openai:F,anthropic:F,google:F,"openai-compatible":K,"managed-local":N,"apple-foundation":N}));function he(e){return me.get(e)??null}function X(e){return typeof e==`string`&&e.length>0?e:void 0}function Z(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);return Number.isFinite(t)?t:void 0}}function Q(e){return e===!0}function ge(e){return{model:e.model,baseUrl:e.baseUrl,apiKey:e.apiKey,supportsVision:e.supportsVision,temperature:e.temperature,topP:e.topP,topK:e.topK,maxTokens:e.maxTokens,contextLength:e.contextLength,systemPrompt:e.systemPrompt,timeoutMs:e.timeoutMs,connectTimeoutMs:e.connectTimeoutMs,firstTokenTimeoutMs:e.firstTokenTimeoutMs,idleTimeoutMs:e.idleTimeoutMs,retryEnabled:e.retry.enabled,retryMaxAttempts:e.retry.maxAttempts,toolsEnabled:e.toolsEnabled,contextSize:e.runtime?.contextSize,gpuLayers:e.runtime?.gpuLayers,threads:e.runtime?.threads,parallel:e.runtime?.parallel,idleStopMinutes:e.runtime?.idleStopMinutes,batchSize:e.runtime?.batchSize,ubatchSize:e.runtime?.ubatchSize,flashAttention:e.runtime?.flashAttention,mlock:e.runtime?.mlock,noMmap:e.runtime?.noMmap,cacheTypeK:e.runtime?.cacheTypeK,cacheTypeV:e.runtime?.cacheTypeV,extraArgs:be(e.runtime?.extraArgs??[])}}var _e=[`f32`,`f16`,`q8_0`,`q5_1`,`q5_0`,`q4_1`,`q4_0`];function ve(e){return typeof e==`string`&&_e.includes(e)?e:void 0}function ye(e){let t=[],n=``,r=null;for(let i of e){if(r!==null){i===r?r=null:n+=i;continue}if(i===`"`||i===`'`){r=i;continue}if(/\s/.test(i)){n!==``&&t.push(n),n=``;continue}n+=i}return n!==``&&t.push(n),t}function be(e){return e.map(e=>/\s/.test(e)?`"${e}"`:e).join(` `)}var xe=[`--jinja`,`--cont-batching`];function Se(e,t,n){let r=Z(e.threads),i=Z(e.batchSize),a=Z(e.ubatchSize),o=ve(e.cacheTypeK),s=ve(e.cacheTypeV);return{nodeId:t,engine:`llama-cpp`,model:n,extraArgs:[...ye(X(e.extraArgs)??``)],contextSize:Z(e.contextSize)??4096,gpuLayers:Z(e.gpuLayers)??0,...r===void 0?{}:{threads:r},parallel:Z(e.parallel)??1,...i===void 0?{}:{batchSize:i},...a===void 0?{}:{ubatchSize:a},flashAttention:Q(e.flashAttention),mlock:Q(e.mlock),noMmap:Q(e.noMmap),...o===void 0?{}:{cacheTypeK:o},...s===void 0?{}:{cacheTypeV:s},autoStart:Q(e.autoStart),idleStopMinutes:Z(e.idleStopMinutes)??30}}function Ce(e,t,n,r,i){let a={id:n?.id??crypto.randomUUID(),name:t,kind:e,addonId:`ai`,enabled:n?.enabled??!0,model:X(r.model)??n?.model??``,supportsVision:i?.supportsVision??Q(r.supportsVision),timeoutMs:Z(r.timeoutMs)??q.totalMs,connectTimeoutMs:Z(r.connectTimeoutMs)??q.connectMs,firstTokenTimeoutMs:Z(r.firstTokenTimeoutMs)??q.firstTokenMs,idleTimeoutMs:Z(r.idleTimeoutMs)??q.idleMs,retry:{enabled:Q(r.retryEnabled),maxAttempts:Z(r.retryMaxAttempts)??1},toolsEnabled:Q(r.toolsEnabled)},o=X(r.baseUrl),s=X(r.apiKey),c=Z(r.temperature),l=Z(r.topP),u=Z(r.topK),d=Z(r.maxTokens),f=Z(r.contextLength),p=X(r.systemPrompt);return{...a,...o===void 0?{}:{baseUrl:o},...s===void 0?{}:{apiKey:s},...c===void 0?{}:{temperature:c},...l===void 0?{}:{topP:l},...u===void 0?{}:{topK:u},...d===void 0?{}:{maxTokens:d},...f===void 0?{}:{contextLength:f},...p===void 0?{}:{systemPrompt:p},...i===void 0?{}:{model:i.modelId,runtime:Se(r,i.nodeId,i.model)}}}function we(e){let t=new Map;for(let n of e){let e=t.get(n.addonId)??[];e.push(n),t.set(n.addonId,e)}return[...t.entries()].map(([e,t])=>({addonId:e,kinds:t}))}var Te=`apple-system`;function Ee(e,t,n,r){return{...Ce(`apple-foundation`,e,t,n),model:Te,supportsVision:!1,appleFoundation:{nodeId:r}}}var De={deviceNotEligible:{key:`ai.appleNotEligible`,text:`not eligible`,tone:`default`},appleIntelligenceNotEnabled:{key:`ai.appleIntelligenceOff`,text:`Apple Intelligence off`,tone:`warning`},modelNotReady:{key:`ai.appleModelNotReady`,text:`model downloading`,tone:`warning`},osTooOld:{key:`ai.appleOsTooOld`,text:`macOS too old`,tone:`default`},helperMissing:{key:`ai.appleHelperMissing`,text:`helper missing`,tone:`danger`},helperCrashed:{key:`ai.appleHelperCrashed`,text:`helper crashed`,tone:`danger`}};function Oe(e){let t=t=>({nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleUnknown`,labelDefault:`unknown`,detail:t,tone:`default`});if(!e.reachable)return t(e.error??null);let n=e.apple;if(n===void 0)return t(null);switch(n.state){case`available`:return{nodeId:e.nodeId,selectable:!0,labelKey:`ai.appleAvailable`,labelDefault:`available`,detail:`macOS ${n.osVersion} · ${n.imageInput?`text + images`:`text only`}`,tone:`success`};case`unavailable`:{let t=De[n.reason];return{nodeId:e.nodeId,selectable:!1,labelKey:t.key,labelDefault:t.text,detail:n.detail,tone:t.tone}}case`unsupported-platform`:return{nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleNotMac`,labelDefault:`not a Mac`,detail:n.platform,tone:`default`};case`unknown`:return t(n.error)}}var ke=2e3;function $(e){return`${(e/1e9).toFixed(2)} GB`}function Ae(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function je({nodeId:e,value:t,onChange:n}){let{t:o}=J(),u=m(),[d,f]=s(``),[p,h]=s(null),[g,_]=s(!1),v=a({queryKey:de,queryFn:()=>u.trpcClient.llm.listModelCatalog.query({})}),x=a({queryKey:[`llm`,`listNodeModels`,e],queryFn:()=>u.trpcClient.llm.listNodeModels.query({nodeId:e})}),S=c({mutationFn:e=>u.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{h(e),_(!1),e.ok&&n({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),C=c({mutationFn:t=>u.trpcClient.llm.installModel.mutate({nodeId:e,model:t}),onSuccess:()=>{_(!0),x.refetch()}}),w=a({queryKey:ue,enabled:C.isPending,refetchInterval:C.isPending?ke:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(t=>t.nodeId===e)?.status?.download,T=i(()=>{let t=(v.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${$(e.sizeBytes)}`})),n=(x.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(t=>({value:`node:${t.file}`,label:o(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:t.file,size:$(t.sizeBytes),node:e})})),r=p?.ok===!0?[{value:`custom`,label:`${p.label} · ${$(p.totalBytes)}`}]:[];return[{value:``,label:o(`ai.selectModel`,`Select a model…`)},...t,...n,...r]},[v.data,x.data,p,e,o]),E=e=>{if(e===``){n(null);return}if(e===`custom`){if(p?.ok!==!0)return;n({model:p.model,modelId:p.label,supportsVision:p.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),r=v.data?.find(e=>e.id===t);n({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:r?.purpose===`vision`});return}let t=e.slice(5),r=x.data?.find(e=>e.file===t);r?.path!==void 0&&n({model:{kind:`path`,path:r.path},modelId:t,supportsVision:!1})},D=e=>{d.trim()!==``&&S.mutate({ref:d.trim(),...e===void 0?{}:{maxBytes:e}})};return r(`div`,{className:`space-y-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-model`,children:o(`ai.model`,`Model`)}),l(y,{id:`ai-model`,value:Ae(t),options:T,onChange:e=>E(e.target.value)})]}),r(`div`,{className:`rounded-md border border-border bg-surface-subtle px-3 py-2.5`,children:[l(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:o(`ai.hfTitle`,`Add a model from Hugging Face`)}),l(`p`,{className:`mb-2 text-[10px] leading-relaxed text-foreground-subtle`,children:o(`ai.hfHint`,`Paste a GGUF file URL, or type org/repo — add :QUANT (e.g. unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M) when the repo publishes more than one quantization.`)}),r(`div`,{className:`flex gap-2`,children:[l(B,{value:d,onChange:e=>f(e.target.value),placeholder:`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),D())}}),r(H,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||S.isPending,onClick:()=>D(),children:[S.isPending?l(b,{className:`h-3.5 w-3.5 animate-spin`}):l(R,{className:`h-3.5 w-3.5`}),o(`ai.hfCheck`,`Check`)]})]}),S.isError&&l(`p`,{className:`mt-2 text-[11px] text-danger`,children:S.error instanceof Error?S.error.message:o(`common.error`,`Error`)}),p?.ok===!1&&r(`div`,{className:`mt-2 rounded-md border border-danger/40 bg-danger/10 px-2.5 py-2`,children:[l(`p`,{className:`text-[11px] text-danger`,children:p.message}),p.candidates!==void 0&&p.candidates.length>0&&l(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:p.candidates.map(e=>l(`button`,{type:`button`,className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] text-foreground hover:border-primary/50`,onClick:()=>{let t=`${d.trim().split(`:`)[0]??``}:${e}`;f(t),S.mutate({ref:t})},children:e},e))}),p.requiredBytes!==void 0&&l(H,{size:`sm`,variant:`secondary`,type:`button`,className:`mt-2`,onClick:()=>D(p.requiredBytes),children:o(`ai.hfOverride`,`Install anyway ({{size}})`,{size:$(p.requiredBytes)})})]}),p?.ok===!0&&r(`div`,{className:`mt-2 rounded-md border border-border bg-surface px-2.5 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[l(`span`,{className:`text-[11px] font-medium text-foreground`,children:p.label}),l(k,{variant:p.purpose===`vision`?`info`:`default`,children:p.purpose}),l(k,{variant:`default`,children:$(p.totalBytes)})]}),p.extraFilenames.length>0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:o(`ai.hfExtras`,`Also downloads: {{files}}`,{files:p.extraFilenames.join(`, `)})}),r(`div`,{className:`mt-2 flex items-center gap-2`,children:[r(H,{size:`sm`,type:`button`,disabled:C.isPending||g,onClick:()=>C.mutate(p.model),children:[C.isPending?l(b,{className:`h-3.5 w-3.5 animate-spin`}):l(ne,{className:`h-3.5 w-3.5`}),g?o(`ai.hfInstalled`,`Downloaded`):o(`ai.hfInstall`,`Download to {{node}}`,{node:e})]}),w!==void 0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:w.phase===`verifying`?o(`ai.hfVerifying`,`verifying {{file}}…`,{file:w.file}):o(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:w.file,index:w.fileIndex,count:w.fileCount,done:$(w.downloadedBytes),total:w.totalBytes===void 0?``:` / ${$(w.totalBytes)}`})})]}),C.isError&&l(`p`,{className:`mt-1.5 text-[11px] text-danger`,children:C.error instanceof Error?C.error.message:o(`common.error`,`Error`)})]})]})]})}function Me({value:e,onChange:t}){let{t:n}=J(),i=m(),o=a({queryKey:ue,queryFn:()=>i.trpcClient.llm.listRuntimeNodes.query({})});return r(`div`,{children:[l(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:n(`ai.appleNode`,`Mac that runs it`)}),o.isPending&&r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[l(b,{className:`h-3.5 w-3.5 animate-spin`}),n(`ai.appleAsking`,`Asking the nodes…`)]}),o.isError&&l(`p`,{className:`text-[11px] text-danger`,children:o.error instanceof Error?o.error.message:n(`ai.runtimesFailed`,`Failed to read runtime nodes`)}),o.isSuccess&&o.data.length===0&&l(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}),o.isSuccess&&o.data.length>0&&l(`div`,{role:`radiogroup`,className:`space-y-1.5`,children:o.data.map(i=>{let a=Oe(i),o=a.nodeId===e;return r(`button`,{type:`button`,role:`radio`,"aria-checked":o,disabled:!a.selectable&&!o,onClick:()=>t(a.nodeId),className:`flex w-full items-center justify-between gap-2 rounded-md border px-3 py-2 text-left text-xs transition-colors disabled:cursor-not-allowed disabled:opacity-60 ${o?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[r(`span`,{className:`min-w-0`,children:[l(`span`,{className:`block font-medium text-foreground`,children:a.nodeId}),a.detail!==null&&l(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:a.detail})]}),l(k,{variant:a.tone,children:n(a.labelKey,a.labelDefault)})]},a.nodeId)})}),l(`p`,{className:`mt-1.5 text-[10px] leading-relaxed text-foreground-subtle`,children:n(`ai.appleHint`,`Text only for now — notification titles and summaries. Apple refuses prompts framed as surveillance; when it does, the next profile in the chain answers instead.`)})]})}n();function Ne({kind:e,className:t}){let n=he(e.kind);return n===null?l(`span`,{className:t,children:e.icon}):l(n,{className:t})}function Pe({kinds:e,onPick:t,onCancel:n}){let{t:a}=J(),o=i(()=>we(e),[e]);return l(w,{open:!0,onOpenChange:e=>!e&&n(),children:r(x,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(M,{children:l(E,{children:a(`ai.chooseKind`,`Choose a profile type`)})}),r(z,{className:`space-y-4 pr-1`,children:[o.length===0&&l(`p`,{className:`text-xs text-foreground-subtle`,children:a(`ai.noKinds`,`No AI provider is installed.`)}),o.map(e=>r(`div`,{children:[l(`div`,{className:`mb-1.5 text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:e.addonId}),l(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:e.kinds.map(n=>r(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs transition-colors hover:border-primary/50 hover:bg-surface-hover`,children:[l(Ne,{kind:n,className:`h-5 w-5 text-foreground-subtle`}),l(`span`,{className:`font-medium text-foreground`,children:n.label})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]}),l(A,{children:l(H,{size:`sm`,variant:`secondary`,type:`button`,onClick:n,children:a(`common.cancel`,`Cancel`)})})]})})}function Fe({kind:e,existing:t,onSave:n,onCancel:a,saving:c,error:u}){let{t:d}=J(),f=e.kind===`managed-local`,p=e.kind===`apple-foundation`,[m,h]=s(t?.appleFoundation?.nodeId??null),[g,_]=s(t?.name??e.label),[v,y]=s(()=>t===null?{}:ge(t)),[S,C]=s(t?.runtime?.nodeId??`hub`),[T,D]=s(()=>t?.runtime===void 0?null:{model:t.runtime.model,modelId:t.model,supportsVision:t.supportsVision}),ee=i(()=>ye(X(v.extraArgs)??``),[v.extraArgs]),O=()=>{if(p){if(m===null)return;n(Ee(g,t,v,m));return}if(!f){n(Ce(e.kind,g,t,v));return}T!==null&&n(Ce(e.kind,g,t,v,{nodeId:S,model:T.model,modelId:T.modelId,supportsVision:T.supportsVision}))},j=c||g.trim()===``||f&&T===null||p&&m===null;return l(w,{open:!0,onOpenChange:e=>!e&&a(),children:r(x,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(M,{children:r(E,{className:`flex items-center gap-2`,children:[l(Ne,{kind:e,className:`h-4 w-4 text-foreground-subtle`}),t===null?d(`ai.newProfile`,`New {{kind}} profile`,{kind:e.label}):d(`ai.editProfile`,`Edit {{name}}`,{name:t.name})]})}),r(z,{className:`space-y-3 pr-1`,children:[u!==null&&l(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:u}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-profile-name`,children:d(`ai.name`,`Name`)}),l(B,{id:`ai-profile-name`,value:g,onChange:e=>_(e.target.value),placeholder:e.label})]}),f&&r(o,{children:[l(L,{selectedNodeId:S,onSelect:C,label:d(`ai.runtimeNode`,`Runtime node`),alwaysShow:!0}),l(je,{nodeId:S,value:T,onChange:D}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-extra-args`,children:d(`ai.extraArgs`,`Additional llama-server arguments`)}),l(B,{id:`ai-extra-args`,value:X(v.extraArgs)??``,onChange:e=>y({...v,extraArgs:e.target.value}),placeholder:xe.join(` `)}),ee.length>0&&l(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:ee.map((e,t)=>l(k,{variant:`default`,children:e},`${e}-${String(t)}`))}),l(`p`,{className:`mt-1 text-[10px] leading-relaxed text-foreground-subtle`,children:d(`ai.extraArgsHint`,`Flags this form does not already own. Vision models generally need --jinja; some language-only models do not like it. Context size, GPU layers, parallel slots, flash attention and the KV-cache types are set in the fields below — repeating one here is rejected at start.`)})]})]}),p&&l(Me,{value:m,onChange:h}),l(I,{schema:e.configSchema,values:v,onChange:y}),t!==null&&l(`p`,{className:`text-[10px] text-foreground-subtle`,children:d(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)})]}),r(A,{children:[f&&T===null&&l(k,{variant:`warning`,children:d(`ai.pickModelFirst`,`pick a model`)}),p&&m===null&&l(k,{variant:`warning`,children:d(`ai.pickAppleNodeFirst`,`pick a Mac`)}),l(H,{size:`sm`,variant:`secondary`,type:`button`,onClick:a,children:d(`common.cancel`,`Cancel`)}),r(H,{size:`sm`,type:`button`,disabled:j,onClick:O,children:[c&&l(b,{className:`h-3.5 w-3.5 animate-spin`}),t===null?d(`ai.createProfile`,`Create profile`):d(`ai.saveChanges`,`Save changes`)]})]})]})})}n();function Ie(e){return[{key:`name`,header:e.t(`ai.colProfile`,`Profile`),render:t=>{let n=e.kindByName.get(t.kind);return r(`span`,{className:`flex items-center gap-2`,children:[l(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface`,title:n?.label??t.kind,children:n===void 0?l(`span`,{className:`text-xs text-foreground-subtle`,children:`?`}):l(Ne,{kind:n,className:`h-4 w-4 text-foreground-subtle`})}),r(`span`,{className:`min-w-0`,children:[l(`span`,{className:`block truncate text-sm font-medium text-foreground`,children:t.name}),e.testResult?.id===t.id&&l(`span`,{className:`block truncate text-[10px] ${e.testResult.ok?`text-success`:`text-danger`}`,children:e.testResult.text})]})]})}},{key:`kind`,header:e.t(`ai.colKind`,`Kind`),nowrap:!0,render:t=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.kindByName.get(t.kind)?.label??t.kind})},{key:`model`,header:e.t(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.model})},{key:`vision`,header:e.t(`ai.colVision`,`Vision`),align:`center`,nowrap:!0,render:t=>t.supportsVision?l(k,{variant:`info`,style:`outline`,children:e.t(`ai.vision`,`vision`)}):l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`})},{key:`node`,header:e.t(`ai.colNode`,`Node`),nowrap:!0,render:e=>e.runtime===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(k,{variant:`default`,children:e.runtime.nodeId})},{key:`enabled`,header:e.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:t=>l(v,{checked:t.enabled,onCheckedChange:()=>e.onToggle(t),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:t=>r(`span`,{className:`flex items-center justify-end gap-1`,children:[l(H,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onTest(t),title:e.t(`ai.test`,`Test`),children:e.testingId===t.id?l(b,{className:`h-3.5 w-3.5 animate-spin`}):l(ie,{className:`h-3.5 w-3.5`})}),l(H,{size:`sm`,variant:`ghost`,type:`button`,disabled:!e.kindByName.has(t.kind),onClick:()=>e.onEdit(t),title:e.t(`common.edit`,`Edit`),children:l(W,{className:`h-3.5 w-3.5`})}),l(H,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDelete(t),title:e.t(`common.delete`,`Delete`),children:l(g,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function Le(){let{t:e}=J(),t=m(),[n,o]=s({mode:`closed`}),[u,d]=s(null),[f,p]=s(null),h=a({queryKey:se,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),g=a({queryKey:ce,queryFn:async()=>(await t.trpcClient.llm.listProfileKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),_=()=>{h.refetch()},v=c({mutationFn:e=>t.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{o({mode:`closed`}),p(null),_()},onError:t=>p(t instanceof Error?t.message:e(`ai.saveFailed`,`Save failed`))}),y=c({mutationFn:e=>t.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:_}),x=c({mutationFn:e=>t.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>d({id:t.id,ok:e.ok,text:e.ok?`${e.text} (${String(e.usage.outputTokens)} tok, ${String(e.latencyMs)}ms)`:`${e.code}: ${e.message}`})}),S=h.data??[],C=i(()=>g.data??[],[g.data]),w=i(()=>{let e=new Map;for(let t of C)e.set(t.kind,t);return e},[C]);return r(Y,{icon:j,title:e(`ai.profilesTitle`,`AI profiles`),subtitle:e(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),actions:r(H,{size:`sm`,type:`button`,onClick:()=>{p(null),o({mode:`pick-kind`})},children:[l(D,{className:`h-3.5 w-3.5`}),e(`ai.addProfile`,`Add profile`)]}),children:[h.isError&&l(G,{title:e(`ai.loadFailed`,`Failed to load profiles`),message:h.error instanceof Error?h.error.message:e(`common.error`,`Error`),onRetry:()=>void h.refetch()}),l(Re,{profiles:S}),h.isLoading&&l(`div`,{className:`flex items-center justify-center py-16`,children:l(b,{className:`h-6 w-6 animate-spin text-primary`})}),!h.isLoading&&S.length===0&&l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}),S.length>0&&l(V,{children:l(U,{columns:Ie({kindByName:w,testResult:u,testingId:x.isPending?x.variables?.id??null:null,t:e,onToggle:e=>v.mutate({...e,enabled:!e.enabled,apiKey:`__redacted__`}),onTest:e=>x.mutate(e),onEdit:e=>{let t=w.get(e.kind);t!==void 0&&(p(null),o({mode:`form`,kind:t,profile:e}))},onDelete:e=>y.mutate(e)}),rows:S,rowKey:e=>e.id,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:`max-h-[60vh]`})}),n.mode===`pick-kind`&&l(Pe,{kinds:C,onCancel:()=>o({mode:`closed`}),onPick:e=>o({mode:`form`,kind:e,profile:null})}),n.mode===`form`&&l(Fe,{kind:n.kind,existing:n.profile,saving:v.isPending,error:f,onSave:e=>v.mutate(e),onCancel:()=>o({mode:`closed`})})]})}function Re({profiles:e}){let{t}=J(),n=m(),i=a({queryKey:le,queryFn:()=>n.trpcClient.llm.getDefaults.query({})}),o=c({mutationFn:e=>n.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{i.refetch()}}),s=e=>(i.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,u=e=>e===`vision`?t(`ai.defaultVision`,`Default vision profile`):t(`ai.defaultText`,`Default text profile`);return l(V,{children:l(`div`,{className:`grid gap-4 p-4 sm:grid-cols-2`,children:pe.map(({purpose:n,visionOnly:i})=>{let a=i?e.filter(e=>e.supportsVision):e,c=s(n),d=e.find(e=>e.id===c);return r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`llm-default-${n}`,children:u(n)}),r(`select`,{id:`llm-default-${n}`,"aria-label":u(n),className:`h-7 w-full rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:c,onChange:e=>o.mutate({purpose:n,profileId:e.target.value===``?null:e.target.value}),children:[l(`option`,{value:``,children:t(`ai.none`,`None`)}),c!==``&&!a.some(e=>e.id===c)&&l(`option`,{value:c,children:d?.name??c}),a.map(e=>r(`option`,{value:e.id,children:[e.name,` · `,e.model]},e.id))]}),c!==``&&d===void 0&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:t(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&l(`p`,{className:`mt-1 text-[10px] text-warning`,children:t(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:String(o.error)})]},n)})})})}n();var ze=5e3;function Be(e){return`${(e/1e9).toFixed(1)} GB`}function Ve(){let{t:e}=J(),t=m(),n=a({queryKey:ue,refetchInterval:ze,queryFn:()=>t.trpcClient.llm.listRuntimeNodes.query({})}),o=i(()=>[{key:`node`,header:e(`ai.colNode`,`Node`),render:e=>l(`span`,{className:`text-sm font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:e(`ai.colState`,`State`),nowrap:!0,render:t=>r(`span`,{className:`flex items-center gap-1.5`,children:[l(k,{variant:t.reachable?`success`:`danger`,children:t.reachable?t.status?.state??e(`ai.ready`,`ready`):e(`ai.unreachable`,`unreachable`)}),t.status?.downloadProgress!==void 0&&l(k,{variant:`info`,children:`${String(Math.round(t.status.downloadProgress*100))}%`})]})},{key:`model`,header:e(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:e(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.disk===void 0?`—`:Be(e.disk.modelsBytes)})},{key:`apple`,header:e(`ai.colApple`,`Apple on-device`),render:t=>{let n=Oe(t);return r(`span`,{className:`flex flex-col items-start gap-0.5`,children:[l(k,{variant:n.tone,children:e(n.labelKey,n.labelDefault)}),n.detail!==null&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n.detail})]})}},{key:`error`,header:e(`ai.colError`,`Error`),render:e=>e.error===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(`span`,{className:`text-[11px] text-danger`,children:e.error})}],[e]),s=n.data??[];return r(Y,{icon:P,title:e(`ai.runtimesTitle`,`Managed runtimes`),subtitle:e(`ai.runtimesSubtitle`,`Nodes advertising the llm-runtime capability: what each has loaded, what it is downloading, and how much model data sits on its disk.`),children:[n.isError&&l(G,{title:e(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:n.error instanceof Error?n.error.message:e(`common.error`,`Error`),onRetry:()=>void n.refetch()}),s.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):l(V,{children:l(U,{columns:o,rows:s,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:O})})]})}var He=f(`/addon/ai/test-chat`),Ue=f(`/addon/ai/test-chat/chats`),We=6e5;function Ge(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),We)}function Ke(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function qe(e){if(!Ke(e))return null;let t=e.kind;return t!==`snapshot`&&t!==`track`||typeof e.mimeType!=`string`||typeof e.sizeBytes!=`number`?null:{kind:t,mimeType:e.mimeType,sizeBytes:e.sizeBytes,...typeof e.mediaKind==`string`?{mediaKind:e.mediaKind}:{},...typeof e.capturedAt==`number`?{capturedAt:e.capturedAt}:{},...typeof e.thumbnailBase64==`string`?{thumbnailBase64:e.thumbnailBase64}:{}}}var Je=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function Ye(e){let t;try{t=JSON.parse(e)}catch{return null}if(!Ke(t))return null;switch(t.kind){case`status`:{let e=Je.find(e=>e===t.phase);return e===void 0?null:{kind:`status`,phase:e}}case`meta`:return typeof t.profileName!=`string`||typeof t.model!=`string`?null:{kind:`meta`,profileName:t.profileName,model:t.model,mediaSent:qe(t.mediaSent),streamed:t.streamed===!0,firstTokenTimeoutMs:typeof t.firstTokenTimeoutMs==`number`?t.firstTokenTimeoutMs:0};case`token`:return typeof t.text==`string`?{kind:`token`,text:t.text}:null;case`done`:return{kind:`done`,inputTokens:typeof t.inputTokens==`number`?t.inputTokens:0,outputTokens:typeof t.outputTokens==`number`?t.outputTokens:0,latencyMs:typeof t.latencyMs==`number`?t.latencyMs:0,truncated:t.truncated===!0,...typeof t.conversationId==`string`?{conversationId:t.conversationId}:{}};case`error`:return{kind:`error`,code:typeof t.code==`string`?t.code:`adapter-error`,message:typeof t.message==`string`?t.message:`the provider returned an error`};default:return null}}async function*Xe(e){let t=e.getReader(),n=new TextDecoder,r=``;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;r+=n.decode(i,{stream:!0});let a=r.indexOf(`
2
- `);for(;a>=0;){let e=r.slice(0,a).trim();if(r=r.slice(a+1),e.length>0){let t=Ye(e);t!==null&&(yield t)}a=r.indexOf(`
3
- `)}}let e=r.trim();if(e.length>0){let t=Ye(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function Ze(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function Qe(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function $e(e){return e.messages.map((t,n)=>{let r=t.mediaSent??void 0;return{id:`${e.id}-${String(n)}`,role:t.role,content:t.content,...t.attachment===void 0?{}:{attachmentRef:t.attachment,attachmentKind:t.attachment.kind},...r===void 0?{}:{attachment:r}}})}function et(e){let t=e.sizeBytes<1024*1024?`${(e.sizeBytes/1024).toFixed(0)} KB`:`${(e.sizeBytes/(1024*1024)).toFixed(1)} MB`,n=[e.kind===`snapshot`?`camera snapshot`:`track best-shot`,t];return e.mediaKind!==void 0&&n.push(e.mediaKind),e.capturedAt!==void 0&&n.push(new Date(e.capturedAt).toLocaleTimeString()),n.join(` · `)}function tt(e,t){switch(e){case`resolving-image`:return`fetching the picture…`;case`connecting`:return`connecting to the provider…`;case`first-token-wait`:return t>0?`the model is loading / thinking — a cold load can take minutes (up to ${String(Math.round(t/1e3))}s)`:`the model is loading / thinking — a cold load can take minutes`;case`streaming`:return`answering…`}}n();var nt=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],rt=360*60*1e3,it=40,at=160,ot={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function st(){let{t:n}=J(),o=m(),[c,d]=s(``),[f,_]=s(``),[v,b]=s(``),[x,S]=s([]),[C,w]=s(null),[E,D]=s(`none`),[O,k]=s(`throwaway`),[A,j]=s(null),[M,ne]=s([]),[N,P]=s(null),[F,I]=s(null),L=t(null);u(()=>()=>L.current?.abort(),[]);let R=e(async()=>{let e=await fetch(Ue,{credentials:`same-origin`});e.ok&&ne((await e.json()).chats??[])},[]);u(()=>{O===`persistent`&&R()},[O,R]);let z=a({queryKey:se,queryFn:()=>o.trpcClient.llm.listProfiles.query({})}),U=i(()=>(z.data??[]).filter(e=>e.enabled),[z.data]),W=U.find(e=>e.id===c)??null,K=F!==null,re=e(async(e,t)=>{let r=new AbortController;L.current=r,P(null);let i=Ge(W??{});I({...ot,firstTokenTimeoutMs:i??0});let a=``,o=null,s,l=null,u=null,d;try{let n=await fetch(He,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:r.signal,body:JSON.stringify({profileId:c,messages:e,...f.trim()===``?{}:{system:f.trim()},...t===void 0?{}:{attachment:t},...i===void 0?{}:{firstTokenTimeoutMs:i},...O===`persistent`?{persist:!0,...A===null?{}:{conversationId:A}}:{}})});if(!n.ok||n.body===null){let e=await n.text().catch(()=>``);throw Error(e.length>0?e:`HTTP ${String(n.status)}`)}for await(let e of Xe(n.body))switch(e.kind){case`status`:I(t=>({...t??ot,phase:e.phase}));break;case`meta`:o=e.mediaSent,s=e.model,I(t=>({...t??ot,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:a+=e.text,I(e=>({...e??ot,text:a}));break;case`done`:u={outputTokens:e.outputTokens,latencyMs:e.latencyMs},d=e.conversationId;break;case`error`:l=`${e.code}: ${e.message}`;break}}catch(e){r.signal.aborted||P(e instanceof Error?e.message:n(`common.error`,`Error`))}finally{L.current=null,I(null)}d!==void 0&&(j(d),R());let p=r.signal.aborted&&a.length>0;l===null&&a.length===0&&!p||S(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:l??a,...l===null?{}:{failed:!0},...o===null?{}:{attachment:o},...s!==void 0&&l===null?{model:s}:{},...u===null?{}:u}])},[O,A,W,c,R,f,n]),q=e(()=>{let e=v.trim();if(e===``||c===``||K)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...C===null?{}:{attachmentLabel:C.label,attachmentKind:C.ref.kind}},n=[...x,t];S(n),b(``);let r=C?.ref;w(null),D(`none`),re(O===`persistent`&&A!==null?[{role:`user`,content:e}]:Ze(n),r)},[O,A,v,C,c,re,K,x]),ae=()=>L.current?.abort(),ce=()=>{L.current?.abort(),S([]),w(null),b(``),P(null),I(null),j(null)},le=async e=>{L.current?.abort();let t=await fetch(`${Ue}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();j(e),S($e(n)),I(null),P(null)};return r(Y,{icon:te,title:n(`ai.testTitle`,`Test chat`),subtitle:n(O===`persistent`?`ai.testSubtitlePersistent`:`ai.testSubtitle`,O===`persistent`?`Conversations are saved for you and can be reopened. Throwaway mode is still available.`:`A throwaway conversation with one profile. Attach a live camera snapshot or a recent track to check the model can actually read a picture. Nothing is saved — only the usage row.`),actions:r(H,{size:`sm`,variant:`secondary`,type:`button`,disabled:x.length===0&&C===null,onClick:ce,children:[l(g,{className:`h-3.5 w-3.5`}),n(`ai.clearChat`,`Clear`)]}),children:[r(V,{className:`space-y-3 p-4`,children:[r(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-profile`,children:n(`ai.profile`,`Profile`)}),l(y,{id:`ai-test-profile`,value:c,onChange:e=>d(e.target.value),options:[{value:``,label:n(`ai.selectProfile`,`Select a profile…`)},...U.map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.supportsVision?` · vision`:``}`}))]}),U.length===0&&!z.isLoading&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:n(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-system`,children:n(`ai.systemPrompt`,`System prompt (optional)`)}),l(B,{id:`ai-test-system`,value:f,onChange:e=>_(e.target.value),placeholder:n(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l(H,{size:`sm`,variant:O===`throwaway`?`primary`:`outline`,type:`button`,onClick:()=>{k(`throwaway`),j(null)},children:n(`ai.throwawayMode`,`Throwaway`)}),l(H,{size:`sm`,variant:O===`persistent`?`primary`:`outline`,type:`button`,onClick:()=>k(`persistent`),children:n(`ai.saveConversation`,`Save conversation`)})]}),O===`persistent`&&r(`div`,{className:`space-y-2`,children:[l(`div`,{className:`flex items-center gap-2`,children:r(H,{size:`sm`,variant:`secondary`,type:`button`,onClick:ce,children:[l(oe,{className:`h-3.5 w-3.5`}),n(`ai.newChat`,`New chat`)]})}),M.length>0&&l(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:M.map(e=>l(`button`,{type:`button`,onClick:()=>void le(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover ${e.id===A?`bg-primary/10`:``}`,children:l(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.title})},e.id))})]}),l(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`ai.streamNote`,`The answer streams as the model produces it. A cold model can take a while to load — the status line says which phase it is in.`)}),W!==null&&!W.supportsVision&&l(`p`,{className:`text-[10px] text-warning`,children:n(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]}),N!==null&&l(G,{title:n(`ai.chatFailed`,`The test call failed`),message:N}),l(ct,{turns:x,live:F}),r(V,{className:`space-y-2 p-3`,children:[C!==null&&r(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-surface px-2.5 py-1.5`,children:[C.ref.kind===`snapshot`?l(p,{className:`h-3.5 w-3.5 text-foreground-subtle`}):l(T,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-foreground`,children:C.label}),l(H,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>w(null),children:l(ee,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(H,{size:`sm`,variant:E===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>D(E===`snapshot`?`none`:`snapshot`),children:[l(p,{className:`h-3.5 w-3.5`}),n(`ai.attachSnapshot`,`Camera snapshot`)]}),r(H,{size:`sm`,variant:E===`track`?`primary`:`outline`,type:`button`,onClick:()=>D(E===`track`?`none`:`track`),children:[l(T,{className:`h-3.5 w-3.5`}),n(`ai.attachTrack`,`Recent track`)]})]}),E===`snapshot`&&l(dt,{onPick:e=>{w({ref:{kind:`snapshot`,deviceId:e.id},label:n(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:e.name})}),D(`none`)}}),E===`track`&&l(pt,{onPick:(e,t)=>{w({ref:{kind:`track`,trackId:e.trackId,deviceId:e.deviceId},label:n(`ai.trackOf`,`{{class}} on {{name}}`,{class:e.label??e.className,name:t})}),D(`none`)}}),r(`div`,{className:`flex items-center gap-2`,children:[l(B,{value:v,onChange:e=>b(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),q())},placeholder:n(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":n(`ai.message`,`Message`)}),K?r(H,{size:`sm`,variant:`secondary`,type:`button`,onClick:ae,children:[l(h,{className:`h-3.5 w-3.5`}),n(`ai.stop`,`Stop`)]}):r(H,{size:`sm`,type:`button`,disabled:v.trim()===``||c===``,onClick:q,children:[l(ie,{className:`h-3.5 w-3.5`}),n(`ai.send`,`Send`)]})]})]})]})}function ct({turns:e,live:t}){let{t:n}=J();return e.length===0&&t===null?l(`div`,{className:`py-12 text-center text-xs text-foreground-subtle`,children:n(`ai.chatEmpty`,`Pick a profile, optionally attach a camera snapshot or a recent track, and send a message. Nothing here is saved.`)}):l(V,{children:r(`div`,{className:`max-h-[50vh] space-y-2 overflow-y-auto p-3`,children:[e.map(e=>l(lt,{turn:e},e.id)),t!==null&&r(`div`,{className:`space-y-1`,children:[t.mediaSent!==null&&l(ut,{attachment:t.mediaSent}),t.text.length>0&&l(lt,{turn:{id:`live`,role:`assistant`,content:t.text},streaming:!0}),r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[l(b,{className:`h-3.5 w-3.5 animate-spin`}),tt(t.phase,t.firstTokenTimeoutMs)]})]})]})})}function lt({turn:e,streaming:t=!1}){let n=e.role===`user`,i=e.failed===!0?`border-danger/40 bg-danger/10`:`border-border bg-surface`;return l(`div`,{className:`flex ${n?`justify-end`:`justify-start`}`,children:r(`div`,{className:`max-w-[85%] rounded-lg border px-3 py-2 ${n?`border-primary/40 bg-primary/10`:i}`,children:[r(`p`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:[e.content,t&&l(`span`,{className:`ml-0.5 animate-pulse text-primary`,children:`▌`})]}),e.attachment!==void 0&&l(ut,{attachment:e.attachment}),e.attachmentLabel!==void 0&&r(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachmentKind===`track`?l(T,{className:`h-3 w-3`}):l(p,{className:`h-3 w-3`}),e.attachmentLabel]}),e.attachment!==void 0&&r(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachment.kind===`snapshot`?l(p,{className:`h-3 w-3`}):l(T,{className:`h-3 w-3`}),et(e.attachment)]}),e.model!==void 0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`${e.model} · ${String(e.outputTokens??0)} tok · ${String(e.latencyMs??0)} ms`})]})})}function ut({attachment:e}){let t=Qe(e);return t===null?null:l(`img`,{src:t,alt:`sent to the model`,className:`mt-1 max-h-32 rounded-md border border-border object-contain`})}function dt({onPick:e}){let{t}=J(),n=C({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?l(b,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):r.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noCameras`,`No camera found.`)}):l(`div`,{className:`grid max-h-56 grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-4`,children:r.map(t=>l(ft,{device:t,onPick:e},t.id))})}function ft({device:e,onPick:t}){let{src:n}=d(e.id,{width:at});return r(`button`,{type:`button`,onClick:()=>t(e),className:`overflow-hidden rounded-md border border-border bg-surface text-left transition-colors hover:border-primary/50`,children:[l(`span`,{className:`block aspect-video w-full bg-background-elevated`,children:n!==null&&l(`img`,{src:n,alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),r(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[!e.online&&l(k,{variant:`warning`,children:`off`}),l(`span`,{className:`truncate text-[10px] text-foreground`,children:e.name})]})]})}function pt({onPick:e}){let{t}=J(),n=m(),o=C({isCamera:!0,projection:`slim`}),s=i(()=>(o.data??[]).map(e=>e.id),[o.data]),c=i(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),u=a({queryKey:[...nt,s.length],enabled:s.length>0,queryFn:()=>n.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...s],since:Date.now()-rt,limit:it,projection:`slim`})});if(o.isLoading||u.isLoading)return l(b,{className:`h-4 w-4 animate-spin text-foreground-subtle`});let d=u.data?.tracks??[];return d.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noTracks`,`No track in the last 6 hours.`)}):l(`div`,{className:`max-h-56 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:d.map(t=>r(`button`,{type:`button`,onClick:()=>e(t,c.get(t.deviceId)??String(t.deviceId)),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover`,children:[l(T,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:t.label??t.className}),l(`span`,{className:`shrink-0 text-foreground-subtle`,children:c.get(t.deviceId)??t.deviceId}),l(`span`,{className:`shrink-0 text-foreground-subtle`,children:new Date(t.lastSeen).toLocaleTimeString()})]},t.trackId))})}n();var mt=1440*60*1e3,ht=[1,7,30,90];function gt(){let{t:e}=J(),t=m(),[n,o]=s(7),c=i(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(n-1)*mt},[n]),u=a({queryKey:se,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),d=a({queryKey:[...fe,n],queryFn:()=>t.trpcClient.llm.getUsage.query({since:c})}),f=i(()=>{let e=new Map;for(let t of u.data??[])e.set(t.id,t.name);return e},[u.data]),p=i(()=>[{key:`day`,header:e(`ai.colDay`,`Day`),nowrap:!0,render:e=>e.day},{key:`consumer`,header:e(`ai.colConsumer`,`Consumer`),nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.consumer})},{key:`profile`,header:e(`ai.colProfile`,`Profile`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:f.get(e.profileId)??e.profileId})},{key:`calls`,header:e(`ai.colCalls`,`Calls`),align:`right`,nowrap:!0,render:e=>String(e.calls)},{key:`okErr`,header:e(`ai.colOkErr`,`OK / err`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:e.errorCalls>0?`text-danger`:void 0,children:`${String(e.okCalls)} / ${String(e.errorCalls)}`})},{key:`tokens`,header:e(`ai.colTokens`,`In / out tok`),align:`right`,nowrap:!0,render:e=>`${String(e.inputTokens)} / ${String(e.outputTokens)}`},{key:`latency`,header:e(`ai.colAvgMs`,`Avg ms`),align:`right`,nowrap:!0,render:e=>String(Math.round(e.avgLatencyMs))}],[f,e]),h=d.data??[];return r(Y,{icon:S,title:e(`ai.usageTitle`,`Usage`),subtitle:e(`ai.usageSubtitle`,`Server-side rollup per day, consumer and profile — never raw call rows. Errors are counted, so a profile that always fails is visible here before a feature reports it.`),actions:l(`div`,{className:`w-40`,children:l(y,{"aria-label":e(`ai.window`,`Window`),value:String(n),options:ht.map(t=>({value:String(t),label:e(`ai.lastDays`,`Last {{days}} days`,{days:t})})),onChange:e=>o(Number(e.target.value))})}),children:[d.isError&&l(G,{title:e(`ai.usageFailed`,`Failed to read usage`),message:d.error instanceof Error?d.error.message:e(`common.error`,`Error`),onRetry:()=>void d.refetch()}),h.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noUsage`,`No AI calls in this window.`)}):l(V,{children:l(U,{columns:p,rows:h,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,mobileMode:`scroll`,maxBodyHeight:O})})]})}function _t(){let{t:e}=J();return l(`div`,{className:`flex flex-col p-4`,children:l(ae,{tabs:[{id:`profiles`,label:e(`ai.tabProfiles`,`Profiles`),icon:re,content:l(Le,{})},{id:`runtimes`,label:e(`ai.tabRuntimes`,`Runtimes`),icon:P,content:l(Ve,{})},{id:`usage`,label:e(`ai.tabUsage`,`Usage`),icon:S,content:l(gt,{})},{id:`test`,label:e(`ai.tabTest`,`Test`),icon:te,content:l(st,{})}]})})}export{_t as AiProfilesPage,_t as default};