@camstack/addon-admin-ui 1.2.449 → 1.2.451

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 (117) hide show
  1. package/dist/assets/{AddonAssetIcon-Rj3wnYY_.js → AddonAssetIcon-tSDKYL0K.js} +1 -1
  2. package/dist/assets/{Addons-WsKSFif5.js → Addons-ofsCoJ4Y.js} +1 -1
  3. package/dist/assets/{AdminPage-C-diJ3HN.js → AdminPage-Bc7EcIQy.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-B7UrSrns.js → AdminSectionedPage-DorUtSBh.js} +1 -1
  5. package/dist/assets/AiProfiles-BdYyzFcG.js +3 -0
  6. package/dist/assets/{BrokerForm-DGyoc2rs.js → BrokerForm-Deefp6zP.js} +1 -1
  7. package/dist/assets/{Build-CWbm1ri9.js → Build-D_QB0Yce.js} +4 -4
  8. package/dist/assets/{Calendars-DuG_m8wt.js → Calendars-BTBqj3kw.js} +1 -1
  9. package/dist/assets/{Cluster-Cxo9fb5E.js → Cluster-qRWUra5C.js} +1 -1
  10. package/dist/assets/{ClusterStepModel-D7FHDo3b.js → ClusterStepModel-CYnyPKcf.js} +1 -1
  11. package/dist/assets/CompositionEditor-sCKYBpl2.js +1 -0
  12. package/dist/assets/{CompositionEditorPage-C4wgJDTS.js → CompositionEditorPage-DzUj_31l.js} +1 -1
  13. package/dist/assets/{Data-DrUKAnew.js → Data-BJuJfR0P.js} +1 -1
  14. package/dist/assets/DeviceDetail-BLnowNRs.js +2 -0
  15. package/dist/assets/{DeviceDoActionFields-J1qr8JLD.js → DeviceDoActionFields-Bffr6IHD.js} +1 -1
  16. package/dist/assets/{Devices-dusaAUzl.js → Devices-IJKvm0BP.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-BuFLE2BZ.js → EmbedPlayerPage-B1o6udpz.js} +1 -1
  18. package/dist/assets/{History-D-IwtcW5.js → History-su2kJ1JJ.js} +1 -1
  19. package/dist/assets/{Identity-D-M8PFe5.js → Identity-8srCiX2b.js} +1 -1
  20. package/dist/assets/{IntegrationDetail-Cm6nS6Dd.js → IntegrationDetail-CHtQ-0tZ.js} +1 -1
  21. package/dist/assets/{IntegrationHub-jG5pe50x.js → IntegrationHub-Bf4b3i_q.js} +1 -1
  22. package/dist/assets/{Integrations-CIjceDno.js → Integrations-Cnq7Q1qn.js} +1 -1
  23. package/dist/assets/{Integrations-CuQ5m9xg.js → Integrations-nFhMQF34.js} +1 -1
  24. package/dist/assets/{Library-B6dY6kqg.js → Library-A6WfMhER.js} +1 -1
  25. package/dist/assets/{Locations-DcVyPbjW.js → Locations-Dl_YxXoD.js} +2 -2
  26. package/dist/assets/{Logs-CrcdhSoT.js → Logs-C9J8k6c9.js} +1 -1
  27. package/dist/assets/{MaskShapeCanvas-D7B1a_d6.js → MaskShapeCanvas-v8FP28QJ.js} +1 -1
  28. package/dist/assets/{MotionZonesSettings-Dv0SmFTj.js → MotionZonesSettings-Bqg-ZAEs.js} +1 -1
  29. package/dist/assets/{MyAccess-B1M-TD_l.js → MyAccess-uX46IK3F.js} +1 -1
  30. package/dist/assets/{Network-CNloyJcw.js → Network-BR-HvAds.js} +1 -1
  31. package/dist/assets/{NodeAddonsSettingsPanel-CGnlyS6W.js → NodeAddonsSettingsPanel-BNTQVCjk.js} +1 -1
  32. package/dist/assets/Notifications-BtCeEFJT.js +1 -0
  33. package/dist/assets/{PrivacyMaskSettings-ChKQKD1z.js → PrivacyMaskSettings-DqyBAWCW.js} +1 -1
  34. package/dist/assets/{Recordings-Bz4wjb-a.js → Recordings-arOpg17X.js} +1 -1
  35. package/dist/assets/{ScanNetworkModal-CLxLy0Jx.js → ScanNetworkModal-DzMITtJ8.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-Dc0QrZZd.js → SceneMonitorEditor-365WT-vj.js} +1 -1
  37. package/dist/assets/{SessionsList-D9f2zkon.js → SessionsList-CAYqZ393.js} +1 -1
  38. package/dist/assets/{Showroom-lbpS7Xdx.js → Showroom-Ch7an15I.js} +1 -1
  39. package/dist/assets/{System-DLjh08cE.js → System-XW10dOJr.js} +1 -1
  40. package/dist/assets/{Terminal-BKjM6jgI.js → Terminal-CmDRhqrR.js} +1 -1
  41. package/dist/assets/{Viewer-CykE8wsK.js → Viewer-2oJvYupj.js} +1 -1
  42. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DJhucDeE.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BvyGb9Bo.js} +1 -1
  43. package/dist/assets/{addon-icons-context-BCJdR2as.js → addon-icons-context-Nt5kiIqp.js} +1 -1
  44. package/dist/assets/{archive-CnyG155u.js → archive-BpVlUMGc.js} +1 -1
  45. package/dist/assets/{authed-media-C0Di1-mt.js → authed-media-CRjjClqw.js} +1 -1
  46. package/dist/assets/{bell-off-BCgckLrg.js → bell-off-DFWiqigj.js} +1 -1
  47. package/dist/assets/{board-model-BEF98n5Q.js → board-model-CbfKyLZU.js} +1 -1
  48. package/dist/assets/{boxes-uA3JVB9e.js → boxes-DEZFxpEo.js} +1 -1
  49. package/dist/assets/circle-slash-BvDvmSoU.js +1 -0
  50. package/dist/assets/client-C7mYZlqO.js +358 -0
  51. package/dist/assets/{cloud-upload-C1akQpc4.js → cloud-upload-DJX2vjB1.js} +1 -1
  52. package/dist/assets/crop-BLfw1NQy.js +1 -0
  53. package/dist/assets/{device-integration-icon-BwPIgj71.js → device-integration-icon-eQMV6gf2.js} +1 -1
  54. package/dist/assets/device-picker-model-B7n7uzAw.js +1 -0
  55. package/dist/assets/dist-4Z3hLAqT.js +358 -0
  56. package/dist/assets/{dist-DICOq93r.js → dist-C44xoxcH.js} +1 -1
  57. package/dist/assets/{eraser-C_0A9Hjb.js → eraser-BJtJIM79.js} +1 -1
  58. package/dist/assets/{hard-drive-download-B-DH1PV-.js → hard-drive-download-BgY0ewC_.js} +1 -1
  59. package/dist/assets/{hostInit-BEZmxPgL.js → hostInit-BxKKf6O5.js} +1 -1
  60. package/dist/assets/i18n-CiEPJn04.js +1 -0
  61. package/dist/assets/{icons-DprpVmeV.js → icons-B7PsYODJ.js} +1 -1
  62. package/dist/assets/{index-DM2PlJTq.js → index-B-H1mfMz.js} +3 -3
  63. package/dist/assets/{key-CL8Jmw2S.js → key-Rj556V_5.js} +1 -1
  64. package/dist/assets/{key-round-C-Aw6TmA.js → key-round-JtuAp3H5.js} +1 -1
  65. package/dist/assets/{layers-DSNZIEzf.js → layers-arFC7gbL.js} +1 -1
  66. package/dist/assets/{linked-devices-model-DzL0krEK.js → linked-devices-model-Bwz1L9wp.js} +1 -1
  67. package/dist/assets/{list-ordered-C1bZw0BL.js → list-ordered-Dam1ZKMc.js} +1 -1
  68. package/dist/assets/{location-owned-usage-dAl9CTze.js → location-owned-usage-DwnxDZWp.js} +1 -1
  69. package/dist/assets/{log-in-Ce7WBmUI.js → log-in-lVU3BPjL.js} +1 -1
  70. package/dist/assets/{memory-stick-DRGsvLsv.js → memory-stick-Cttq5WM5.js} +1 -1
  71. package/dist/assets/{message-square-plus-Cjk8neRy.js → message-square-plus-CaNw_hMf.js} +1 -1
  72. package/dist/assets/{mf-entry-bootstrap-0-2f4164ab.js → mf-entry-bootstrap-0-ab6954b6.js} +2 -2
  73. package/dist/assets/{mic-off-CraNg8N9.js → mic-off-it4ki4Jh.js} +1 -1
  74. package/dist/assets/{monitor-off-CgatD4nF.js → monitor-off-oHRvN7aD.js} +1 -1
  75. package/dist/assets/{monitor-smartphone-Ct9M1imf.js → monitor-smartphone-CjCMg9jw.js} +1 -1
  76. package/dist/assets/mount-B7n7uzAw.js +1 -0
  77. package/dist/assets/notification-schedule-field-DkO0-1Tm.js +1 -0
  78. package/dist/assets/{player-overlays-B32sNiuW.js → player-overlays-BQ-CPD3k.js} +1 -1
  79. package/dist/assets/{recycle-YQKD8v3i.js → recycle-DLgVUrk1.js} +1 -1
  80. package/dist/assets/remoteEntry-5tiapUFy.js +1 -0
  81. package/dist/assets/{scan-eye-DkWYA8Qn.js → scan-eye-D3WSpR2M.js} +1 -1
  82. package/dist/assets/{scissors-d-Q62-mJ.js → scissors-CfXjajAo.js} +1 -1
  83. package/dist/assets/{search-x-Dh-cGhc7.js → search-x-DrZuvHV8.js} +1 -1
  84. package/dist/assets/{send-CUvOOMzH.js → send-BGZ680If.js} +1 -1
  85. package/dist/assets/{settings-2-DOLBKbT-.js → settings-2-WgIC2cEC.js} +1 -1
  86. package/dist/assets/{speaker-GR-Ncblv.js → speaker-DIrTXPXW.js} +1 -1
  87. package/dist/assets/{src-wMLlETeo.js → src-DP8JO4HZ.js} +7 -7
  88. package/dist/assets/{timer-reset-BSlB8Uty.js → timer-reset-Ba4-n5gG.js} +1 -1
  89. package/dist/assets/{ungroup-DlVR3lck.js → ungroup-DjxNnRiT.js} +1 -1
  90. package/dist/assets/{unlink-CNQUhGTn.js → unlink-Cy4eOOGb.js} +1 -1
  91. package/dist/assets/{usb-Bek6n_7R.js → usb-Crnw8Rqe.js} +1 -1
  92. package/dist/assets/{use-scenes-feed-v_NBqxW2.js → use-scenes-feed-CqavtElt.js} +1 -1
  93. package/dist/assets/{use-stationary-objects-CuK9Ramz.js → use-stationary-objects-CuD-UCH8.js} +1 -1
  94. package/dist/assets/useEventInvalidation-B7n7uzAw.js +1 -0
  95. package/dist/assets/{useNodeUrlSelection-WhpPPOny.js → useNodeUrlSelection-ChFCBb4B.js} +1 -1
  96. package/dist/assets/user-round-7xIjUD30.js +1 -0
  97. package/dist/assets/{user-x-B4ynO2HW.js → user-x-BDmcZv0z.js} +1 -1
  98. package/dist/assets/{video-JAYMKNkG.js → video-JjHo3xW3.js} +1 -1
  99. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DHtR5Duv.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-3LGiNBfi.js} +2 -2
  100. package/dist/index.html +10 -10
  101. package/dist/server/addon.js +126 -3
  102. package/package.json +1 -1
  103. package/dist/assets/AiProfiles-BxHwvLTC.js +0 -3
  104. package/dist/assets/CompositionEditor-CW5KG78s.js +0 -1
  105. package/dist/assets/DeviceDetail-CgxNDsue.js +0 -2
  106. package/dist/assets/Notifications-DSQJwH9f.js +0 -1
  107. package/dist/assets/circle-slash-CXSKoFJ3.js +0 -1
  108. package/dist/assets/client-CBY2Ai10.js +0 -358
  109. package/dist/assets/crop-CZVwalbq.js +0 -1
  110. package/dist/assets/device-picker-model-DspKRUOC.js +0 -1
  111. package/dist/assets/dist-ucVPOol3.js +0 -358
  112. package/dist/assets/i18n-DBncQ6jl.js +0 -1
  113. package/dist/assets/mount-DspKRUOC.js +0 -1
  114. package/dist/assets/notification-schedule-field-BJxF3SRn.js +0 -1
  115. package/dist/assets/remoteEntry-Ba2ucEqQ.js +0 -1
  116. package/dist/assets/useEventInvalidation-DspKRUOC.js +0 -1
  117. package/dist/assets/user-round-CtzL736C.js +0 -1
@@ -1,6 +1,6 @@
1
1
  import path from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
- //#region ../types/dist/event-category-DOl51-Ij.mjs
3
+ //#region ../types/dist/event-category-7pZEBmVg.mjs
4
4
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
5
5
  EventCategory["SystemBoot"] = "system.boot";
6
6
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -688,6 +688,14 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
688
688
  EventCategory["BackupRestored"] = "backup.restored";
689
689
  EventCategory["NotificationDispatched"] = "notification.dispatched";
690
690
  EventCategory["NotificationFailed"] = "notification.failed";
691
+ /**
692
+ * A notification rule that cannot work (D905): its stored row does not load,
693
+ * or it still names a device / delivery target the prune CONFIRMED deleted.
694
+ * One edge per rule per distinct set of reasons; never on an unanswered read.
695
+ */
696
+ EventCategory["NotificationRuleBroken"] = "notification.rule-broken";
697
+ /** The clear of {@link NotificationRuleBroken}: the rule loads and names nothing deleted. */
698
+ EventCategory["NotificationRuleRepaired"] = "notification.rule-repaired";
691
699
  EventCategory["DeviceUpdated"] = "device.updated";
692
700
  /**
693
701
  * Transport-level connectivity. Emitted by the device driver when
@@ -5415,7 +5423,7 @@ var ZodIssueCode = {
5415
5423
  var ZodFirstPartyTypeKind;
5416
5424
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5417
5425
  //#endregion
5418
- //#region ../types/dist/sleep-_sV1BE2f.mjs
5426
+ //#region ../types/dist/sleep-CueztlR1.mjs
5419
5427
  /**
5420
5428
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5421
5429
  * window to float samples (D455).
@@ -41971,6 +41979,8 @@ var NcSystemEventKindSchema = _enum([
41971
41979
  "alert-critical",
41972
41980
  "alert-error",
41973
41981
  "alert-critical-resolved",
41982
+ "rule-broken",
41983
+ "rule-repaired",
41974
41984
  "camera-online",
41975
41985
  "camera-offline",
41976
41986
  "camera-disabled",
@@ -73404,6 +73414,8 @@ new Map(Object.entries({
73404
73414
  "alert-critical": "system",
73405
73415
  "alert-error": "system",
73406
73416
  "alert-critical-resolved": "system",
73417
+ "rule-broken": "system",
73418
+ "rule-repaired": "system",
73407
73419
  "storage-location-low": "system",
73408
73420
  "storage-location-critical": "system",
73409
73421
  "storage-location-ok": "system",
@@ -73538,6 +73550,12 @@ var NC_SYSTEM_EVENT_KIND_GROUP_SPECS = [
73538
73550
  "alert-critical-resolved"
73539
73551
  ]
73540
73552
  },
73553
+ {
73554
+ id: "rule-health",
73555
+ family: "system",
73556
+ label: "Notification rules",
73557
+ kinds: ["rule-broken", "rule-repaired"]
73558
+ },
73541
73559
  {
73542
73560
  id: "alarm",
73543
73561
  family: "alarm",
@@ -73815,6 +73833,10 @@ var STATE_SUMMARY_VARS = [
73815
73833
  [...RULE_TEXT],
73816
73834
  [...RULE_TEXT],
73817
73835
  [...RULE_TEXT],
73836
+ [...RULE_TEXT],
73837
+ [...RULE_TEXT],
73838
+ [...RULE_TEXT],
73839
+ [...RULE_TEXT],
73818
73840
  ([...RULE_TEXT], [...UPDATES]),
73819
73841
  ([...RULE_TEXT], [...PACKAGE_UPDATES]),
73820
73842
  ([...RULE_TEXT], [...PACKAGE_UPDATES]),
@@ -73853,6 +73875,107 @@ var STATE_SUMMARY_VARS = [
73853
73875
  [...RULE_TEXT],
73854
73876
  ...STATE_SUMMARY_VARS
73855
73877
  ];
73878
+ new Map([
73879
+ {
73880
+ id: "device-connectivity",
73881
+ family: "device-events",
73882
+ label: "Device connectivity (offline / back online)",
73883
+ bad: ["device-offline"],
73884
+ recovery: ["device-online"],
73885
+ snapshotLabel: "Devices offline now",
73886
+ snapshotSection: "device-state"
73887
+ },
73888
+ {
73889
+ id: "device-switch",
73890
+ family: "device-events",
73891
+ label: "Device switched off / back on",
73892
+ bad: ["device-disabled"],
73893
+ recovery: ["device-enabled"],
73894
+ snapshotLabel: "Devices switched off now",
73895
+ snapshotSection: "device-state"
73896
+ },
73897
+ {
73898
+ id: "stream-connectivity",
73899
+ family: "device-events",
73900
+ label: "Stream connectivity (offline / back online)",
73901
+ bad: ["stream-offline"],
73902
+ recovery: ["stream-online"],
73903
+ snapshotLabel: "Streams offline now",
73904
+ snapshotSection: "streams"
73905
+ },
73906
+ {
73907
+ id: "battery",
73908
+ family: "device-events",
73909
+ label: "Battery (low / back to normal)",
73910
+ bad: ["device-battery-low"],
73911
+ recovery: ["device-battery-normal"],
73912
+ snapshotLabel: "Batteries low now",
73913
+ snapshotSection: "battery"
73914
+ },
73915
+ {
73916
+ id: "consumables",
73917
+ family: "device-events",
73918
+ label: "Consumables (low / replaced)",
73919
+ bad: ["device-consumable-low"],
73920
+ recovery: ["device-consumable-normal"],
73921
+ snapshotLabel: "Consumables low now",
73922
+ snapshotSection: "consumables"
73923
+ },
73924
+ {
73925
+ id: "tanks",
73926
+ family: "device-events",
73927
+ label: "Tanks (low or full / back to normal)",
73928
+ bad: ["device-tank-low", "device-tank-full"],
73929
+ recovery: ["device-tank-normal"],
73930
+ snapshotLabel: "Tanks low or full now",
73931
+ snapshotSection: "tanks"
73932
+ },
73933
+ {
73934
+ id: "recording-health",
73935
+ family: "device-events",
73936
+ label: "Recording health (stalled or degraded / recording again)",
73937
+ bad: ["recording-stalled", "recording-degraded"],
73938
+ recovery: ["recording-healthy"],
73939
+ snapshotLabel: "Recordings stalled now",
73940
+ snapshotSection: null
73941
+ },
73942
+ {
73943
+ id: "node-connectivity",
73944
+ family: "system",
73945
+ label: "Node connectivity (offline / back online)",
73946
+ bad: ["node-offline"],
73947
+ recovery: ["node-online"],
73948
+ snapshotLabel: "Nodes offline now",
73949
+ snapshotSection: "nodes"
73950
+ },
73951
+ {
73952
+ id: "storage-space",
73953
+ family: "system",
73954
+ label: "Storage space (low or critical / ok again)",
73955
+ bad: ["storage-location-low", "storage-location-critical"],
73956
+ recovery: ["storage-location-ok"],
73957
+ snapshotLabel: "Storage locations low now",
73958
+ snapshotSection: null
73959
+ },
73960
+ {
73961
+ id: "critical-alerts",
73962
+ family: "system",
73963
+ label: "Critical alerts (raised / resolved)",
73964
+ bad: ["alert-critical"],
73965
+ recovery: ["alert-critical-resolved"],
73966
+ snapshotLabel: "Critical alerts open now",
73967
+ snapshotSection: null
73968
+ },
73969
+ {
73970
+ id: "rule-health",
73971
+ family: "system",
73972
+ label: "Rule health (broken / repaired)",
73973
+ bad: ["rule-broken"],
73974
+ recovery: ["rule-repaired"],
73975
+ snapshotLabel: "Notification rules broken now",
73976
+ snapshotSection: null
73977
+ }
73978
+ ].flatMap((spec) => [...spec.bad, ...spec.recovery].map((kind) => [kind, spec])));
73856
73979
  new Set([
73857
73980
  "disarmed",
73858
73981
  "armed_home",
@@ -74391,7 +74514,7 @@ var AdminUIAddon = class extends BaseAddon {
74391
74514
  capability: adminUiCapability,
74392
74515
  provider: {
74393
74516
  getStaticDir: async () => ({ staticDir: resolveAdminUiDistDir() }),
74394
- getVersion: async () => ({ version: "1.2.449" })
74517
+ getVersion: async () => ({ version: "1.2.451" })
74395
74518
  }
74396
74519
  }];
74397
74520
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-admin-ui",
3
- "version": "1.2.449",
3
+ "version": "1.2.451",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Admin UI — Vite frontend build and server-side addon",
@@ -1,3 +0,0 @@
1
- import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,q as c,t as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{D as d,Fn as f,G as p,Gr as m,It as h,L as g,Mi as _,Mr as v,Ni as y,Oi as b,On as x,Or as S,Q as C,Yt as w,Zi as T,Zr as E,Zt as D,bn as O,dn as k,dt as A,ei as j,fn as M,kn as N,or as P,ot as F}from"./player-overlays-B32sNiuW.js";import{Gi as ee,cr as I,sr as L}from"./client-CBY2Ai10.js";import{t as te}from"./message-square-plus-Cjk8neRy.js";import{t as ne}from"./send-CUvOOMzH.js";import{$ as re,Ar as R,Du as z,Mu as ie,Nn as B,Nu as ae,Rr as V,Ya as H,_n as U,_t as oe,dt as W,fr as G,gn as K,gr as se,hr as q,jn as ce,lt as le,mn as J,mr as Y,pr as X,qn as ue,vt as de,zn as fe}from"./src-wMLlETeo.js";import{t as Z}from"./i18n-DBncQ6jl.js";import{t as Q}from"./useTranslation-D3Is_4B6.js";import"./mount-DspKRUOC.js";import{T as pe,nt as me}from"./index-DM2PlJTq.js";import{t as he}from"./AdminSectionedPage-B7UrSrns.js";import{t as ge}from"./AdminPage-C-diJ3HN.js";e();var _e=`__redacted__`,ve=[`llm`,`listProfiles`],ye=[`llm`,`listProfileKinds`],be=[`llm`,`getDefaults`],xe=[`llm`,`listRuntimeNodes`],Se=[`llm`,`listModelCatalog`],Ce=[`llm`,`getUsage`],we=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],Te=new Map([[`cloud`,j],[`plug`,x],[`cpu`,E],[`server`,k],[`sparkles`,D]]);function Ee(e){return Te.get(e)??y}function De(e){return typeof e==`string`&&e.length>0?e:void 0}function Oe(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 ke(e){return e===!0}function Ae(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 je={deviceNotEligible:{key:`ai.appleNotEligible`,tone:`default`},appleIntelligenceNotEnabled:{key:`ai.appleIntelligenceOff`,tone:`warning`},modelNotReady:{key:`ai.appleModelNotReady`,tone:`warning`},osTooOld:{key:`ai.appleOsTooOld`,tone:`default`},helperMissing:{key:`ai.appleHelperMissing`,tone:`danger`},helperCrashed:{key:`ai.appleHelperCrashed`,tone:`danger`}};function Me(e){let t=t=>({nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleUnknown`,labelDefault:Z.t(`ai.appleUnknown`),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:Z.t(`ai.appleAvailable`),detail:Z.t(n.imageInput?`helpers.aiPage.appleDetailImages`:`helpers.aiPage.appleDetailText`,{version:n.osVersion}),tone:`success`};case`unavailable`:{let t=je[n.reason];return{nodeId:e.nodeId,selectable:!1,labelKey:t.key,labelDefault:Z.t(t.key),detail:n.detail,tone:t.tone}}case`unsupported-platform`:return{nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleNotMac`,labelDefault:Z.t(`ai.appleNotMac`),detail:n.platform,tone:`default`};case`unknown`:return t(n.error)}}var Ne={temperature:[{type:`slider`,key:`temperature`,label:`Temperature`,min:0,max:2,step:.1,showValue:!0,showStepper:!0,nullable:!0,nullLabel:`Provider default`,description:`The judging gates pin this to 0 per call regardless of the profile.`}],topP:[{type:`slider`,key:`topP`,label:`Top-p`,min:0,max:1,step:.05,showValue:!0,showStepper:!0,nullable:!0,nullLabel:`Provider default`}],topK:[{type:`number`,key:`topK`,label:`Top-k`,min:1}],maxTokens:[{type:`number`,key:`maxTokens`,label:`Max output tokens`,min:1}],contextLength:[{type:`number`,key:`contextLength`,label:`Context length`,min:512,unit:`tokens`,description:`Advisory: the provider enforces its own window.`}],systemPrompt:[{type:`textarea`,key:`systemPrompt`,label:`Default system prompt`,rows:4,maxLength:4e3,span:2,description:`A caller that sends its own system prompt REPLACES this one.`}],timeoutMs:[{type:`number`,key:`timeoutMs`,label:`Total (ms)`,min:1e3,default:I.totalMs,unit:`ms`,description:`The whole generation. The only bound a non-streaming call has.`}],connectTimeoutMs:[{type:`number`,key:`connectTimeoutMs`,label:`Connect (ms)`,min:500,default:I.connectMs,unit:`ms`,description:`The TCP handshake — "is the port even open".`}],firstTokenTimeoutMs:[{type:`number`,key:`firstTokenTimeoutMs`,label:`First token (ms)`,min:1e3,default:I.firstTokenMs,unit:`ms`,description:`Accepted but silent. A cold model load lives here and can take minutes.`}],idleTimeoutMs:[{type:`number`,key:`idleTimeoutMs`,label:`Idle (ms)`,min:1e3,default:I.idleMs,unit:`ms`,description:`Output started, then stopped.`}],retry:[{type:`boolean`,key:`retryEnabled`,label:`Retry on failure`,description:`Per-consumer policy still wins: the notification gates never retry.`},{type:`number`,key:`retryMaxAttempts`,label:`Max attempts`,min:1,max:5,default:1,showWhen:{field:`retryEnabled`,equals:!0}}],toolsEnabled:[{type:`boolean`,key:`toolsEnabled`,label:`Enable tools`,description:`Lets this profile make tool calls. No tools are registered yet.`}]},Pe=[`temperature`,`topP`,`topK`,`maxTokens`,`contextLength`,`systemPrompt`],Fe=[`timeoutMs`,`connectTimeoutMs`,`firstTokenTimeoutMs`,`idleTimeoutMs`,`retry`,`toolsEnabled`];function Ie(e,t){return t.filter(t=>e.includes(t)).flatMap(e=>Ne[e])}function Le(e){let t=Ie(e,Pe);return t.length===0?null:{sections:[{id:`generation`,title:`Generation`,fields:t}]}}function Re(e){let t=Ie(e,Fe);return t.length===0?null:{sections:[{id:`bounds`,title:`Timeouts and policy`,fields:t}]}}function ze(e){return e===null?{}:{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}}function Be(e,t){return{...e.features,...t?.features}}function Ve(e,t){return t===null?e.modelCatalog===`static`?e.staticModels??[]:[]:t}function He(e,t,n){let r=e.profileFields,i=n.common,a=(e,t,n)=>r.includes(e)?Oe(i[e])??t:n??t,o=e=>r.includes(e)?Oe(i[e]):t?.[e],s=o(`temperature`),c=o(`topP`),l=o(`topK`),u=o(`maxTokens`),d=o(`contextLength`),f=r.includes(`systemPrompt`)?De(i.systemPrompt):t?.systemPrompt;return{id:t?.id??crypto.randomUUID(),name:n.name,kind:e.kind,addonId:e.addonId.length>0?e.addonId:`ai`,enabled:t?.enabled??!0,model:n.model,supportsVision:n.supportsVision,timeoutMs:a(`timeoutMs`,I.totalMs,t?.timeoutMs),connectTimeoutMs:a(`connectTimeoutMs`,I.connectMs,t?.connectTimeoutMs),firstTokenTimeoutMs:a(`firstTokenTimeoutMs`,I.firstTokenMs,t?.firstTokenTimeoutMs),idleTimeoutMs:a(`idleTimeoutMs`,I.idleMs,t?.idleTimeoutMs),retry:r.includes(`retry`)?{enabled:ke(i.retryEnabled),maxAttempts:Oe(i.retryMaxAttempts)??1}:t?.retry??{enabled:!1,maxAttempts:1},toolsEnabled:r.includes(`toolsEnabled`)?ke(i.toolsEnabled):t?.toolsEnabled??!1,...s===void 0?{}:{temperature:s},...c===void 0?{}:{topP:c},...l===void 0?{}:{topK:l},...u===void 0?{}:{maxTokens:u},...d===void 0?{}:{contextLength:d},...f===void 0?{}:{systemPrompt:f},providerConfig:n.providerConfig}}var Ue=2e3;function $(e){return Z.t(`system.aiModelPicker.sizeGb`,{value:(e/1e9).toFixed(2)})}function We(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Ge({nodeId:e,value:t,onChange:i}){let{t:s}=Q(),c=F(),[d,f]=r(``),[p,h]=r(null),[g,_]=r(!1),v=o({queryKey:Se,queryFn:()=>c.trpcClient.llm.listModelCatalog.query({})}),y=o({queryKey:[`llm`,`listNodeModels`,e],queryFn:()=>c.trpcClient.llm.listNodeModels.query({nodeId:e})}),b=l({mutationFn:e=>c.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{h(e),_(!1),e.ok&&i({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),x=l({mutationFn:t=>c.trpcClient.llm.installModel.mutate({nodeId:e,model:t}),onSuccess:()=>{_(!0),y.refetch()}}),S=o({queryKey:xe,enabled:x.isPending,refetchInterval:x.isPending?Ue:!1,queryFn:()=>c.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(t=>t.nodeId===e)?.status?.download,C=n(()=>{let t=(v.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${$(e.sizeBytes)}`})),n=(y.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(t=>({value:`node:${t.file}`,label:s(`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:s(`ai.selectModel`,`Select a model…`)},...t,...n,...r]},[v.data,y.data,p,e,s]),w=e=>{if(e===``){i(null);return}if(e===`custom`){if(p?.ok!==!0)return;i({model:p.model,modelId:p.label,supportsVision:p.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),n=v.data?.find(e=>e.id===t);i({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:n?.purpose===`vision`});return}let t=e.slice(5),n=y.data?.find(e=>e.file===t);n?.path!==void 0&&i({model:{kind:`path`,path:n.path},modelId:t,supportsVision:!1})},T=e=>{d.trim()!==``&&b.mutate({ref:d.trim(),...e===void 0?{}:{maxBytes:e}})};return a(`div`,{className:`space-y-3`,children:[u(de,{label:s(`ai.model`,`Model`),required:!0,children:u(z,{id:`ai-model`,"aria-label":s(`ai.model`,`Model`),value:We(t),options:C,onChange:e=>w(e.target.value)})}),u(de,{label:s(`ai.hfTitle`,`Add a model from Hugging Face`),description:s(`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.`),children:a(`div`,{className:`flex gap-2`,children:[u(ie,{"aria-label":s(`ai.hfTitle`,`Add a model from Hugging Face`),value:d,onChange:e=>f(e.target.value),placeholder:s(`system.aiModelPicker.unslothQwen3635bA3b`,`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),T())}}),a(q,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||b.isPending,onClick:()=>T(),children:[b.isPending?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(M,{className:`h-3.5 w-3.5`}),s(`ai.hfCheck`,`Check`)]})]})}),b.isError&&u(G,{message:b.error instanceof Error?b.error.message:s(`common.error`,`Error`)}),p?.ok===!1&&u(G,{message:p.message,action:a(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(p.candidates??[]).map(e=>u(q,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{let t=`${d.trim().split(`:`)[0]??``}:${e}`;f(t),b.mutate({ref:t})},children:e},e)),p.requiredBytes!==void 0&&u(q,{size:`sm`,variant:`secondary`,type:`button`,onClick:()=>T(p.requiredBytes),children:s(`ai.hfOverride`,`Install anyway ({{size}})`,{size:$(p.requiredBytes)})})]})}),p?.ok===!0&&a(`div`,{className:`space-y-2 rounded-md border border-border bg-surface p-2.5`,children:[a(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`span`,{className:`text-[11px] font-medium text-foreground`,children:p.label}),u(V,{variant:p.purpose===`vision`?`info`:`default`,children:p.purpose}),u(V,{variant:`default`,children:$(p.totalBytes)})]}),p.extraFilenames.length>0&&u(`p`,{className:`text-[10px] text-foreground-subtle`,children:s(`ai.hfExtras`,`Also downloads: {{files}}`,{files:p.extraFilenames.join(`, `)})}),a(`div`,{className:`flex items-center gap-2`,children:[a(q,{size:`sm`,type:`button`,disabled:x.isPending||g,onClick:()=>x.mutate(p.model),children:[x.isPending?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(m,{className:`h-3.5 w-3.5`}),g?s(`ai.hfInstalled`,`Downloaded`):s(`ai.hfInstall`,`Download to {{node}}`,{node:e})]}),S!==void 0&&u(`span`,{className:`text-[10px] text-foreground-subtle`,children:S.phase===`verifying`?s(`ai.hfVerifying`,`verifying {{file}}…`,{file:S.file}):s(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:S.file,index:S.fileIndex,count:S.fileCount,done:$(S.downloadedBytes),total:S.totalBytes===void 0?``:` / ${$(S.totalBytes)}`})})]}),x.isError&&u(G,{message:x.error instanceof Error?x.error.message:s(`common.error`,`Error`)})]})]})}function Ke({value:e,onChange:t}){let{t:n}=Q(),r=F(),i=o({queryKey:xe,queryFn:()=>r.trpcClient.llm.listRuntimeNodes.query({})});return a(`div`,{children:[u(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:n(`ai.appleNode`,`Mac that runs it`)}),i.isPending&&a(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(P,{className:`h-3.5 w-3.5 animate-spin`}),n(`ai.appleAsking`,`Asking the nodes…`)]}),i.isError&&u(`p`,{className:`text-[11px] text-danger`,children:i.error instanceof Error?i.error.message:n(`ai.runtimesFailed`,`Failed to read runtime nodes`)}),i.isSuccess&&i.data.length===0&&u(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}),i.isSuccess&&i.data.length>0&&u(`div`,{role:`radiogroup`,className:`space-y-1.5`,children:i.data.map(r=>{let i=Me(r),o=i.nodeId===e;return a(`button`,{type:`button`,role:`radio`,"aria-checked":o,disabled:!i.selectable&&!o,onClick:()=>t(i.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:[a(`span`,{className:`min-w-0`,children:[u(`span`,{className:`block font-medium text-foreground`,children:i.nodeId}),i.detail!==null&&u(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:i.detail})]}),u(V,{variant:i.tone,children:n(i.labelKey,i.labelDefault)})]},i.nodeId)})}),u(`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.`)})]})}function qe(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Je({providerConfig:e,onProviderConfigChange:t}){return u(Ke,{value:qe(e,`nodeId`),onChange:n=>t({...e,nodeId:n})})}function Ye({providerConfig:e,onProviderConfigChange:t,model:n,onModelChange:r}){let i=L.safeParse(e.model),a=i.success?{model:i.data,modelId:n.id,supportsVision:n.supportsVision}:null;return u(Ge,{nodeId:qe(e,`nodeId`)??`hub`,value:a,onChange:n=>{if(n===null){let{model:n,...i}=e;t(i),r({id:``,supportsVision:!1});return}t({...e,model:n.model}),r({id:n.modelId,supportsVision:n.supportsVision})}})}var Xe=new Map([[`ai/apple-node`,Je],[`ai/managed-model`,Ye]]);function Ze(e){return Xe.get(e)??null}e();function Qe({kind:e,className:t}){return u(Ee(e.icon),{className:t,"aria-hidden":!0})}function $e({kinds:e,onPick:t,onCancel:r}){let{t:i}=Q(),a=n(()=>Ae(e),[e]),o=n(()=>new Map(e.map(e=>[`${e.addonId}:${e.kind}`,e])),[e]);return u(W,{open:!0,onClose:r,title:i(`ai.chooseKind`,`Choose a profile type`),width:`lg`,testId:`ai-kind-picker`,children:u(oe,{emptyMessage:i(`ai.noKinds`,`No AI provider is installed.`),onPick:e=>{let n=o.get(e);n!==void 0&&t(n)},groups:a.map(e=>({id:e.addonId,label:e.addonId,tiles:e.kinds.map(t=>({key:`${e.addonId}:${t.kind}`,label:t.label,testId:`ai-kind-${t.kind}`,icon:u(Qe,{kind:t,className:`h-5 w-5 text-foreground-subtle`})}))}))})})}function et(e){return(e?.sections??[]).flatMap(e=>e.fields)}function tt(...e){let t={};for(let n of e)for(let e of et(n))`default`in e&&e.default!==void 0&&(t[e.key]=e.default);return t}function nt(e){return e==null?!1:typeof e==`string`?e.trim().length>0:!0}function rt(e,t){return et(e).filter(e=>`required`in e&&e.required===!0&&!nt(t[e.key])).map(e=>`label`in e&&typeof e.label==`string`?e.label:e.key)}var it={auth:{key:`ai.listAuth`,fallback:`Credentials refused`},network:{key:`ai.listNetwork`,fallback:`Endpoint unreachable`},unsupported:{key:`ai.listUnsupported`,fallback:`No model list`},invalid:{key:`ai.listInvalid`,fallback:`Connection incomplete`}};function at(e,t){if(t!==null)return{id:t.model,supportsVision:t.supportsVision};let n=e.modelCatalog===`static`&&e.staticModels?.length===1?e.staticModels?.[0]:void 0;return{id:n?.id??``,supportsVision:Be(e,n).vision}}function ot({kind:e,existing:t,onSave:i,onCancel:o,onChangeKind:c,saving:f,error:p}){let{t:m}=Q(),h=F(),[_,v]=r(t?.name??e.label),[y,b]=r(()=>t===null?tt(e.connectionSchema,e.advancedSchema):{...t.providerConfig}),[x,S]=r(()=>ze(t)),[C,w]=r(()=>at(e,t)),[E,D]=r(!1),k=e.providerWidgets??[],A=k.filter(e=>e.placement===`connection`),j=k.find(e=>e.placement===`model`)??null,M=n(()=>[...ee(e.connectionSchema)].some(e=>t?.providerConfig[e]===_e),[t,e.connectionSchema]),N=l({mutationFn:()=>h.trpcClient.llm.listModels.mutate({addonId:e.addonId,kind:e.kind,connection:y,...t===null?{}:{profileId:t.id}})}),I=Ve(e,N.data?.ok===!0?N.data.models:null),L=I.find(e=>e.id===C.id),te=Be(e,L),ne=Le(e.profileFields),re=Re(e.profileFields),R=rt(e.connectionSchema,y),B=k.some(e=>(e.requires??[]).some(e=>!nt(y[e]))),ae=e.modelCatalog===`fetch`&&j===null,H=et(e.connectionSchema).length>0||A.length>0,U=t=>{w({id:t,supportsVision:Be(e,I.find(e=>e.id===t)).vision})},oe=f||_.trim()===``||C.id.trim()===``||R.length>0||B,K=()=>{i(He(e,t,{name:_.trim(),model:C.id.trim(),supportsVision:e.visionEditable?C.supportsVision:!1,common:x,providerConfig:y}))},se=t===null?m(`ai.newProfile`,`New {{kind}} profile`,{kind:e.label}):m(`ai.editProfile`,`Edit {{name}}`,{name:t.name}),le=t=>{let n=Ze(t);return n===null?u(G,{variant:`warning`,message:m(`ai.unknownWidget`,`This provider needs an editor part this build does not have ({{id}}).`,{id:t})}):u(n,{descriptor:e,providerConfig:y,onProviderConfigChange:b,model:C,onModelChange:w},t)};return u(W,{open:!0,onClose:o,title:se,error:p,width:`lg`,testId:`ai-profile-editor`,footer:a(s,{children:[R.length>0&&u(V,{variant:`warning`,children:m(`ai.missingRequired`,`required: {{fields}}`,{fields:R.join(`, `)})}),R.length===0&&B&&u(V,{variant:`warning`,children:m(`ai.completeProvider`,`complete the provider settings`)}),R.length===0&&!B&&C.id.trim()===``&&u(V,{variant:`warning`,children:m(`ai.pickModelFirst`,`pick a model`)}),a(q,{size:`sm`,type:`button`,disabled:oe,onClick:K,children:[f&&u(P,{className:`h-3.5 w-3.5 animate-spin`}),t===null?m(`ai.createProfile`,`Create profile`):m(`ai.saveChanges`,`Save changes`)]})]}),children:a(`div`,{className:g,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`ai-editor-provider`,children:[u(Qe,{kind:e,className:`h-4 w-4 text-foreground-subtle`}),u(`span`,{className:`text-xs font-medium text-foreground`,children:e.label}),u(V,{variant:`neutral`,children:e.addonId}),c!==void 0&&a(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:c,children:[u(T,{className:`h-3.5 w-3.5`}),m(`ai.changeKind`,`Change type`)]})]}),u(de,{label:m(`ai.name`,`Name`),required:!0,children:u(ie,{id:`ai-profile-name`,"aria-label":m(`ai.name`,`Name`),value:_,onChange:e=>v(e.target.value),placeholder:e.label})}),H&&u(J,{headingId:`ai-editor-connection`,title:m(`ai.sectionConnection`,`Connection`),actions:ae?a(q,{size:`sm`,variant:`secondary`,type:`button`,disabled:N.isPending,onClick:()=>N.mutate(),"data-testid":`ai-verify-models`,children:[N.isPending?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(O,{className:`h-3.5 w-3.5`}),m(`ai.verifyModels`,`Verify & load models`)]}):void 0,children:a(`div`,{className:`p-2 sm:p-3 lg:p-4 space-y-3`,children:[et(e.connectionSchema).length>0&&u(ue,{bare:!0,schema:e.connectionSchema,values:y,onChange:b}),A.map(e=>le(e.id)),M&&u(`p`,{className:`text-[10px] text-foreground-subtle`,children:m(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)}),N.data?.ok===!0&&u(V,{variant:`success`,"data-testid":`ai-models-found`,children:m(`ai.modelsFound`,`{{count}} models found`,{count:N.data.models.length})}),N.data?.ok===!1&&u(G,{title:m(it[N.data.code]?.key??`ai.listNetwork`,it[N.data.code]?.fallback??`Endpoint unreachable`),message:N.data.message}),N.isError&&u(G,{message:N.error instanceof Error?N.error.message:m(`common.error`,`Error`)})]})}),u(J,{headingId:`ai-editor-model`,title:m(`ai.sectionModel`,`Model`),children:a(`div`,{className:`${d} space-y-3`,children:[j===null?a(s,{children:[I.length>0&&u(z,{id:`ai-model-pick`,"aria-label":m(`ai.selectModel`,`Select a model…`),value:L===void 0?``:L.id,options:[{value:``,label:m(`ai.selectModel`,`Select a model…`)},...I.map(e=>({value:e.id,label:e.label??e.id}))],onChange:e=>{e.target.value!==``&&U(e.target.value)}}),u(de,{label:m(`ai.customModel`,`Model id`),description:m(`ai.customModelHint`,`Pick one from the list, or type any model id the provider accepts.`),required:!0,children:u(ie,{id:`ai-model-id`,"aria-label":m(`ai.customModel`,`Model id`),value:C.id,onChange:e=>w({...C,id:e.target.value}),placeholder:I[0]?.id??`model-id`})})]}):le(j.id),a(`div`,{className:`flex flex-wrap items-center gap-1.5`,"data-testid":`ai-model-features`,children:[(C.supportsVision||!e.visionEditable&&te.vision)&&u(V,{variant:`info`,children:m(`ai.featureVision`,`vision`)}),te.tools&&u(V,{variant:`neutral`,children:m(`ai.featureTools`,`tools`)}),te.streaming&&u(V,{variant:`neutral`,children:m(`ai.featureStreaming`,`streaming`)})]}),e.visionEditable&&u(de,{orientation:`horizontal`,label:m(`ai.supportsVision`,`Supports vision`),description:m(`ai.supportsVisionHint`,`A vision call against a text-only profile is refused, never downgraded.`),children:u(ce,{checked:C.supportsVision,onCheckedChange:e=>w({...C,supportsVision:e}),"aria-label":m(`ai.supportsVision`,`Supports vision`)})})]})}),ne!==null&&u(J,{headingId:`ai-editor-generation`,title:m(`ai.sectionGeneration`,`Generation`),children:u(`div`,{className:`p-2 sm:p-3 lg:p-4`,children:u(ue,{bare:!0,schema:ne,values:x,onChange:S})})}),(re!==null||e.advancedSchema!==void 0)&&u(fe,{expanded:E,onExpandedChange:D,header:u(`span`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:m(`ai.sectionAdvanced`,`Advanced`)}),children:a(`div`,{className:`p-2 sm:p-3 lg:p-4 space-y-3`,children:[re!==null&&u(ue,{bare:!0,schema:re,values:x,onChange:S}),e.advancedSchema!==void 0&&u(ue,{bare:!0,schema:e.advancedSchema,values:y,onChange:b})]})})]})})}e();function st(e){return[{key:`name`,header:e.t(`ai.colProfile`,`Profile`),render:t=>{let n=e.kindByName.get(t.kind);return a(`span`,{className:`flex items-center gap-2`,children:[u(`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?u(`span`,{className:`text-xs text-foreground-subtle`,children:`?`}):u(Qe,{kind:n,className:`h-4 w-4 text-foreground-subtle`})}),a(`span`,{className:`min-w-0`,children:[u(`span`,{className:`block truncate font-medium text-foreground`,children:t.name}),e.testResult?.id===t.id&&u(`span`,{className:`block truncate ${e.testResult.ok?`text-success`:`text-danger`}`,children:e.testResult.text})]})]})}},{key:`kind`,header:e.t(`ai.colKind`,`Kind`),nowrap:!0,render:t=>u(`span`,{className:`text-foreground-muted`,children:e.kindByName.get(t.kind)?.label??t.kind})},{key:`model`,header:e.t(`ai.colModel`,`Model`),render:e=>u(`span`,{className:`text-foreground`,children:e.model})},{key:`vision`,header:e.t(`ai.colVision`,`Vision`),align:`center`,nowrap:!0,render:t=>t.supportsVision?u(V,{variant:`info`,style:`outline`,children:e.t(`ai.vision`,`vision`)}):u(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`node`,header:e.t(`ai.colNode`,`Node`),nowrap:!0,render:e=>typeof e.providerConfig.nodeId==`string`?u(V,{variant:`default`,children:e.providerConfig.nodeId}):u(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`enabled`,header:e.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:t=>u(ce,{checked:t.enabled,onCheckedChange:()=>e.onToggle(t),"aria-label":Z.t(`system.aiProfilesTab.toggle`,`toggle {{name}}`,{name:t.name})})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:t=>a(`span`,{className:`flex items-center justify-end gap-1`,children:[u(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onTest(t),"aria-label":e.t(`ai.test`,`Test`),title:e.t(`ai.test`,`Test`),children:e.testingId===t.id?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(ne,{className:`h-3.5 w-3.5`})}),u(q,{size:`sm`,variant:`ghost`,type:`button`,disabled:!e.kindByName.has(t.kind),onClick:()=>e.onEdit(t),"aria-label":e.t(`common.edit`,`Edit`),title:e.t(`common.edit`,`Edit`),children:u(f,{className:`h-3.5 w-3.5`})}),u(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDelete(t),"aria-label":e.t(`common.delete`,`Delete`),title:e.t(`common.delete`,`Delete`),children:u(h,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function ct(){let{t:e}=Q(),s=F(),{state:c,openEdit:f,close:p}=le(),m=R(),[h,_]=r(null),[v,y]=r(null),[b,x]=r(null),S=o({queryKey:ve,queryFn:()=>s.trpcClient.llm.listProfiles.query({})}),C=o({queryKey:ye,queryFn:async()=>(await s.trpcClient.llm.listProfileKinds.query({})).map(({connectionSchema:e,advancedSchema:t,...n})=>({...n,connectionSchema:e,...t===void 0?{}:{advancedSchema:t}}))}),w=()=>{S.refetch()},T=i(()=>{_(null),x(null),p()},[p]);t(()=>{c.mode===`closed`&&_(null)},[c.mode]);let E=l({mutationFn:e=>s.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{T(),w()},onError:t=>x(t instanceof Error?t.message:e(`ai.saveFailed`,`Save failed`))}),O=l({mutationFn:e=>s.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:w}),k=l({mutationFn:e=>s.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>y({id:t.id,ok:e.ok,text:e.ok?Z.t(`system.aiProfilesTab.testOk`,{text:e.text,tokens:e.usage.outputTokens,ms:e.latencyMs}):`${e.code}: ${e.message}`})}),A=S.data??[],j=n(()=>C.data??[],[C.data]),M=n(()=>{let e=new Map;for(let t of j)e.set(t.kind,t);return e},[j]),N=c.mode===`edit`?A.find(e=>e.id===c.id)??null:null,P=N===null?null:M.get(N.kind)??null,ee=c.mode===`new`&&h===null,I=c.mode===`new`?h:P,L=c.mode===`edit`?N:null,te=I!==null&&(c.mode===`new`||L!==null),ne=async t=>{await m({title:e(`ai.deleteProfileTitle`,`Delete profile?`),message:e(`ai.deleteProfileMessage`,`Delete "{{name}}". Features that name it will no longer get an answer from it.`,{name:t.name}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&O.mutate(t)};return a(`div`,{className:g,children:[u(lt,{profiles:A}),u(J,{headingId:`ai-profiles-list`,title:e(`ai.profilesList`,`Profiles`),children:S.isPending?a(`div`,{className:`${d} space-y-2`,"data-testid":`ai-profiles-loading`,children:[u(Y,{className:`h-8 w-full`}),u(Y,{className:`h-8 w-full`}),u(Y,{className:`h-8 w-full`})]}):S.isError?u(`div`,{className:d,children:u(G,{title:e(`ai.loadFailed`,`Failed to load profiles`),message:S.error instanceof Error?S.error.message:e(`common.error`,`Error`),onRetry:()=>void S.refetch()})}):A.length===0?u(X,{icon:D,title:e(`ai.noProfilesTitle`,`No AI profiles yet`),description:e(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}):u(K,{columns:st({kindByName:M,testResult:v,testingId:k.isPending?k.variables?.id??null:null,t:e,onToggle:e=>E.mutate({...e,enabled:!e.enabled}),onTest:e=>k.mutate(e),onEdit:e=>{M.has(e.kind)&&(x(null),_(null),f(e.id))},onDelete:e=>void ne(e)}),rows:A,rowKey:e=>e.id,minWidthPx:760,bordered:!1,maxBodyHeight:U})}),ee&&u($e,{kinds:j,onCancel:T,onPick:e=>{x(null),_(e)}}),te&&I!==null&&u(ot,{kind:I,existing:L,saving:E.isPending,error:b,onSave:e=>E.mutate(e),onCancel:T,...c.mode===`new`?{onChangeKind:()=>{x(null),_(null)}}:{}})]})}function lt({profiles:e}){let{t}=Q(),n=F(),r=o({queryKey:be,queryFn:()=>n.trpcClient.llm.getDefaults.query({})}),i=l({mutationFn:e=>n.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{r.refetch()}}),s=e=>(r.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,c=e=>e===`vision`?t(`ai.defaultVision`,`Default vision profile`):t(`ai.defaultText`,`Default text profile`);return u(J,{headingId:`ai-profiles-defaults`,title:t(`ai.defaultsTitle`,`Defaults`),children:u(`div`,{className:`${d} grid gap-4 sm:grid-cols-2`,children:we.map(({purpose:n,visionOnly:r})=>{let o=r?e.filter(e=>e.supportsVision):e,l=s(n),d=e.find(e=>e.id===l);return a(`div`,{children:[u(B,{className:`mb-1 block`,htmlFor:`llm-default-${n}`,children:c(n)}),u(z,{id:`llm-default-${n}`,"aria-label":c(n),value:l,onChange:e=>i.mutate({purpose:n,profileId:e.target.value===``?null:e.target.value}),options:[{value:``,label:t(`ai.none`,`None`)},...l!==``&&!o.some(e=>e.id===l)?[{value:l,label:d?.name??l}]:[],...o.map(e=>({value:e.id,label:`${e.name} · ${e.model}`}))]}),l!==``&&d===void 0&&u(`p`,{className:`mt-1 text-xs text-danger`,children:t(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&u(`p`,{className:`mt-1 text-xs text-warning`,children:t(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),i.error!=null&&u(`p`,{className:`mt-1 text-xs text-danger`,children:String(i.error)})]},n)})})})}e();var ut=5e3;function dt(e){return Z.t(`system.aiRuntimes.sizeGb`,{value:(e/1e9).toFixed(1)})}function ft(){let{t:e}=Q(),t=F(),r=o({queryKey:xe,refetchInterval:ut,queryFn:()=>t.trpcClient.llm.listRuntimeNodes.query({})}),i=n(()=>[{key:`node`,header:e(`ai.colNode`,`Node`),render:e=>u(`span`,{className:`font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:e(`ai.colState`,`State`),nowrap:!0,render:t=>a(`span`,{className:`flex items-center gap-1.5`,children:[u(V,{variant:t.reachable?`success`:`danger`,children:t.reachable?t.status?.state??e(`ai.ready`,`ready`):e(`ai.unreachable`,`unreachable`)}),t.status?.downloadProgress!==void 0&&u(V,{variant:`info`,children:`${String(Math.round(t.status.downloadProgress*100))}%`})]})},{key:`model`,header:e(`ai.colModel`,`Model`),render:e=>u(`span`,{className:`text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:e(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>u(`span`,{className:`tabular-nums text-foreground-muted`,children:e.disk===void 0?`—`:dt(e.disk.modelsBytes)})},{key:`apple`,header:e(`ai.colApple`,`Apple on-device`),render:t=>{let n=Me(t);return a(`span`,{className:`flex flex-col items-start gap-0.5`,children:[u(V,{variant:n.tone,children:e(n.labelKey,n.labelDefault)}),n.detail!==null&&u(`span`,{className:`text-foreground-subtle`,children:n.detail})]})}},{key:`error`,header:e(`ai.colError`,`Error`),render:e=>e.error===void 0?u(`span`,{className:`text-foreground-subtle`,children:`—`}):u(`span`,{className:`text-danger`,children:e.error})}],[e]),s=r.data??[];return u(J,{headingId:`ai-runtimes-list`,title:e(`ai.runtimesList`,`Nodes`),children:r.isPending?a(`div`,{className:`${d} space-y-2`,"data-testid":`ai-runtimes-loading`,children:[u(Y,{className:`h-8 w-full`}),u(Y,{className:`h-8 w-full`})]}):r.isError?u(`div`,{className:d,children:u(G,{title:e(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:r.error instanceof Error?r.error.message:e(`common.error`,`Error`),onRetry:()=>void r.refetch()})}):s.length===0?u(X,{icon:k,title:e(`ai.noRuntimesTitle`,`No runtime nodes`),description:e(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):u(K,{columns:i,rows:s,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,maxBodyHeight:U})})}var pt=C(`/addon/ai/test-chat`),mt=C(`/addon/ai/test-chat/chats`),ht=6e5;function gt(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),ht)}function _t(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function vt(e){if(!_t(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 yt=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function bt(e){let t;try{t=JSON.parse(e)}catch{return null}if(!_t(t))return null;switch(t.kind){case`status`:{let e=yt.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:vt(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:Z.t(`helpers.aiTestChat.providerError`)};default:return null}}async function*xt(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=bt(e);t!==null&&(yield t)}a=r.indexOf(`
3
- `)}}let e=r.trim();if(e.length>0){let t=bt(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function St(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function Ct(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function wt(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 Tt(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 Et(e,t){switch(e){case`resolving-image`:return Z.t(`helpers.aiTestChat.phaseImage`);case`connecting`:return Z.t(`helpers.aiTestChat.phaseConnecting`);case`first-token-wait`:return t>0?Z.t(`helpers.aiTestChat.phaseWaitUpTo`,{seconds:Math.round(t/1e3)}):Z.t(`helpers.aiTestChat.phaseWait`);case`streaming`:return Z.t(`helpers.aiTestChat.phaseAnswering`)}}e();var Dt=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],Ot=360*60*1e3,kt=40,At=160,jt={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function Mt(){let{t:e}=Q(),s=F(),[l,f]=r(``),[p,m]=r(``),[v,y]=r(``),[x,S]=r([]),[C,T]=r(null),[E,D]=r(`none`),[O,k]=r(`throwaway`),[j,M]=r(null),[N,P]=r([]),[ee,I]=r(null),[L,R]=r(null),V=c(null);t(()=>()=>V.current?.abort(),[]);let H=i(async()=>{let e=await fetch(mt,{credentials:`same-origin`});e.ok&&P((await e.json()).chats??[])},[]);t(()=>{O===`persistent`&&H()},[O,H]);let U=o({queryKey:ve,queryFn:()=>s.trpcClient.llm.listProfiles.query({})}),oe=n(()=>(U.data??[]).filter(e=>e.enabled),[U.data]),W=oe.find(e=>e.id===l)??null,K=L!==null,se=i(async(t,n)=>{let r=new AbortController;V.current=r,I(null);let i=gt(W??{});R({...jt,firstTokenTimeoutMs:i??0});let a=``,o=null,s,c=null,u=null,d;try{let e=await fetch(pt,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:r.signal,body:JSON.stringify({profileId:l,messages:t,...p.trim()===``?{}:{system:p.trim()},...n===void 0?{}:{attachment:n},...i===void 0?{}:{firstTokenTimeoutMs:i},...O===`persistent`?{persist:!0,...j===null?{}:{conversationId:j}}:{}})});if(!e.ok||e.body===null){let t=await e.text().catch(()=>``);throw Error(t.length>0?t:`HTTP ${String(e.status)}`)}for await(let t of xt(e.body))switch(t.kind){case`status`:R(e=>({...e??jt,phase:t.phase}));break;case`meta`:o=t.mediaSent,s=t.model,R(e=>({...e??jt,firstTokenTimeoutMs:t.firstTokenTimeoutMs,mediaSent:t.mediaSent}));break;case`token`:a+=t.text,R(e=>({...e??jt,text:a}));break;case`done`:u={outputTokens:t.outputTokens,latencyMs:t.latencyMs},d=t.conversationId;break;case`error`:c=`${t.code}: ${t.message}`;break}}catch(t){r.signal.aborted||I(t instanceof Error?t.message:e(`common.error`,`Error`))}finally{V.current=null,R(null)}d!==void 0&&(M(d),H());let f=r.signal.aborted&&a.length>0;c===null&&a.length===0&&!f||S(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:c??a,...c===null?{}:{failed:!0},...o===null?{}:{attachment:o},...s!==void 0&&c===null?{model:s}:{},...u===null?{}:u}])},[O,j,W,l,H,p,e]),ce=i(()=>{let e=v.trim();if(e===``||l===``||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),y(``);let r=C?.ref;T(null),D(`none`),se(O===`persistent`&&j!==null?[{role:`user`,content:e}]:St(n),r)},[O,j,v,C,l,se,K,x]),le=()=>V.current?.abort(),Y=()=>{V.current?.abort(),S([]),T(null),y(``),I(null),R(null),M(null)},X=async e=>{V.current?.abort();let t=await fetch(`${mt}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();M(e),S(wt(n)),R(null),I(null)};return a(`div`,{className:g,children:[u(J,{headingId:`ai-test-setup`,title:e(`ai.testSetup`,`Setup`),children:a(`div`,{className:`${d} space-y-3`,children:[a(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[a(`div`,{children:[u(B,{className:`mb-1 block`,htmlFor:`ai-test-profile`,children:e(`ai.profile`,`Profile`)}),u(z,{id:`ai-test-profile`,value:l,onChange:e=>f(e.target.value),options:[{value:``,label:e(`ai.selectProfile`,`Select a profile…`)},...oe.map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.supportsVision?` · vision`:``}`}))]}),oe.length===0&&!U.isLoading&&u(`p`,{className:`mt-1 text-xs text-foreground-subtle`,children:e(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),a(`div`,{children:[u(B,{className:`mb-1 block`,htmlFor:`ai-test-system`,children:e(`ai.systemPrompt`,`System prompt (optional)`)}),u(ie,{id:`ai-test-system`,value:p,onChange:e=>m(e.target.value),placeholder:e(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),u(re,{label:e(`ai.chatMode`,`Conversation mode`),value:O,options:[{value:`throwaway`,label:e(`ai.throwawayMode`,`Throwaway`)},{value:`persistent`,label:e(`ai.saveConversation`,`Save conversation`)}],onChange:e=>{k(e),e===`throwaway`&&M(null)}}),O===`persistent`&&a(`div`,{className:`space-y-2`,children:[u(`p`,{className:`text-xs text-foreground-subtle`,children:e(`ai.testSubtitlePersistent`,`Conversations are saved for you and can be reopened. Throwaway mode is still available.`)}),a(q,{size:`sm`,variant:`secondary`,type:`button`,onClick:Y,children:[u(te,{className:`h-3.5 w-3.5`}),e(`ai.newChat`,`New chat`)]}),N.length>0&&u(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:N.map(e=>u(`button`,{type:`button`,onClick:()=>void X(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-xs hover:bg-surface-hover ${e.id===j?`bg-primary/10`:``}`,children:u(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.title})},e.id))})]}),u(`p`,{className:`text-xs text-foreground-subtle`,children:e(`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&&u(`p`,{className:`text-xs text-warning`,children:e(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]})}),ee!==null&&u(G,{title:e(`ai.chatFailed`,`The test call failed`),message:ee}),a(J,{headingId:`ai-test-conversation`,title:e(`ai.testConversation`,`Conversation`),actions:a(q,{size:`sm`,variant:`ghost`,type:`button`,disabled:x.length===0&&C===null,onClick:Y,children:[u(h,{className:`h-3.5 w-3.5`}),e(`ai.clearChat`,`Clear`)]}),children:[u(Nt,{turns:x,live:L}),a(`div`,{className:`${d} space-y-2 border-t border-border`,children:[C!==null&&a(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-background px-2.5 py-1.5`,children:[C.ref.kind===`snapshot`?u(b,{className:`h-3.5 w-3.5 text-foreground-subtle`}):u(_,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:C.label}),u(ae,{size:`sm`,variant:`ghost`,type:`button`,icon:A,"aria-label":e(`ai.removeAttachment`,`Remove attachment`),onClick:()=>T(null)})]}),a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a(q,{size:`sm`,variant:E===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>D(E===`snapshot`?`none`:`snapshot`),children:[u(b,{className:`h-3.5 w-3.5`}),e(`ai.attachSnapshot`,`Camera snapshot`)]}),a(q,{size:`sm`,variant:E===`track`?`primary`:`outline`,type:`button`,onClick:()=>D(E===`track`?`none`:`track`),children:[u(_,{className:`h-3.5 w-3.5`}),e(`ai.attachTrack`,`Recent track`)]})]}),E===`snapshot`&&u(It,{onPick:t=>{T({ref:{kind:`snapshot`,deviceId:t.id},label:e(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:t.name})}),D(`none`)}}),E===`track`&&u(Rt,{onPick:(t,n)=>{T({ref:{kind:`track`,trackId:t.trackId,deviceId:t.deviceId},label:e(`ai.trackOf`,`{{class}} on {{name}}`,{class:t.label??t.className,name:n})}),D(`none`)}}),a(`div`,{className:`flex items-center gap-2`,children:[u(ie,{value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),ce())},placeholder:e(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":e(`ai.message`,`Message`)}),K?a(q,{size:`sm`,variant:`secondary`,type:`button`,onClick:le,children:[u(w,{className:`h-3.5 w-3.5`}),e(`ai.stop`,`Stop`)]}):a(q,{size:`sm`,type:`button`,disabled:v.trim()===``||l===``,onClick:ce,children:[u(ne,{className:`h-3.5 w-3.5`}),e(`ai.send`,`Send`)]})]})]})]})]})}function Nt({turns:e,live:t}){let{t:n}=Q();return e.length===0&&t===null?u(X,{icon:v,title:n(`ai.chatEmptyTitle`,`No messages yet`),description:n(`ai.chatEmpty`,`Pick a profile, optionally attach a camera snapshot or a recent track, and send a message. Nothing here is saved.`)}):a(`div`,{className:`max-h-[50vh] space-y-2 overflow-y-auto ${d}`,children:[e.map(e=>u(Pt,{turn:e},e.id)),t!==null&&a(`div`,{className:`space-y-1`,children:[t.mediaSent!==null&&u(Ft,{attachment:t.mediaSent}),t.text.length>0&&u(Pt,{turn:{id:`live`,role:`assistant`,content:t.text},streaming:!0}),a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(P,{className:`h-3.5 w-3.5 animate-spin`}),Et(t.phase,t.firstTokenTimeoutMs)]})]})]})}function Pt({turn:e,streaming:t=!1}){let{t:n}=Q(),r=e.role===`user`,i=e.failed===!0?`border-danger/40 bg-danger/10`:`border-border bg-surface`;return u(`div`,{className:`flex ${r?`justify-end`:`justify-start`}`,children:a(`div`,{className:`max-w-[85%] rounded-lg border px-3 py-2 ${r?`border-primary/40 bg-primary/10`:i}`,children:[a(`p`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:[e.content,t&&u(`span`,{className:`ml-0.5 animate-pulse text-primary`,children:`▌`})]}),e.attachment!==void 0&&u(Ft,{attachment:e.attachment}),e.attachmentLabel!==void 0&&a(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachmentKind===`track`?u(_,{className:`h-3 w-3`}):u(b,{className:`h-3 w-3`}),e.attachmentLabel]}),e.attachment!==void 0&&a(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachment.kind===`snapshot`?u(b,{className:`h-3 w-3`}):u(_,{className:`h-3 w-3`}),Tt(e.attachment)]}),e.model!==void 0&&u(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:n(`system.aiTestChat.tokMs`,`{{model}} · {{value2}} tok · {{value3}} ms`,{model:e.model,value2:String(e.outputTokens??0),value3:String(e.latencyMs??0)})})]})})}function Ft({attachment:e}){let{t}=Q(),n=Ct(e);return n===null?null:u(`img`,{src:n,alt:t(`system.aiTestChat.sentToTheModel`,`sent to the model`),className:`mt-1 max-h-32 rounded-md border border-border object-contain`})}function It({onPick:e}){let{t}=Q(),n=H({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?u(P,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):r.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noCameras`,`No camera found.`)}):u(`div`,{className:`grid max-h-56 grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-4`,children:r.map(t=>u(Lt,{device:t,onPick:e},t.id))})}function Lt({device:e,onPick:t}){let{t:n}=Q(),{src:r}=p(e.id,{width:At});return a(`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:[u(`span`,{className:`block aspect-video w-full bg-background-elevated`,children:r!==null&&u(`img`,{src:r,alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),a(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[!e.online&&u(V,{variant:`warning`,children:n(`common.off`)}),u(`span`,{className:`truncate text-[10px] text-foreground`,children:e.name})]})]})}function Rt({onPick:e}){let{t}=Q(),r=F(),i=H({isCamera:!0,projection:`slim`}),s=n(()=>(i.data??[]).map(e=>e.id),[i.data]),c=n(()=>{let e=new Map;for(let t of i.data??[])e.set(t.id,t.name);return e},[i.data]),l=o({queryKey:[...Dt,s.length],enabled:s.length>0,queryFn:()=>r.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...s],since:Date.now()-Ot,limit:kt,projection:`slim`})});if(i.isLoading||l.isLoading)return u(P,{className:`h-4 w-4 animate-spin text-foreground-subtle`});let d=l.data?.tracks??[];return d.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noTracks`,`No track in the last 6 hours.`)}):u(`div`,{className:`max-h-56 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:d.map(t=>a(`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:[u(_,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),u(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:t.label??t.className}),u(`span`,{className:`shrink-0 text-foreground-subtle`,children:c.get(t.deviceId)??t.deviceId}),u(`span`,{className:`shrink-0 text-foreground-subtle`,children:new Date(t.lastSeen).toLocaleTimeString()})]},t.trackId))})}e();var zt=1440*60*1e3,Bt=[1,7,30,90];function Vt(){let{t:e}=Q(),t=F(),[i,s]=r(7),c=n(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(i-1)*zt},[i]),l=o({queryKey:ve,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),f=o({queryKey:[...Ce,i],queryFn:()=>t.trpcClient.llm.getUsage.query({since:c})}),p=n(()=>{let e=new Map;for(let t of l.data??[])e.set(t.id,t.name);return e},[l.data]),m=n(()=>[{key:`day`,header:e(`ai.colDay`,`Day`),nowrap:!0,render:e=>u(`span`,{className:`tabular-nums`,children:e.day})},{key:`consumer`,header:e(`ai.colConsumer`,`Consumer`),nowrap:!0,render:e=>u(`span`,{className:`text-foreground`,children:e.consumer})},{key:`profile`,header:e(`ai.colProfile`,`Profile`),render:e=>u(`span`,{className:`text-foreground`,children:p.get(e.profileId)??e.profileId})},{key:`calls`,header:e(`ai.colCalls`,`Calls`),align:`right`,nowrap:!0,render:e=>u(`span`,{className:`tabular-nums`,children:String(e.calls)})},{key:`okErr`,header:e(`ai.colOkErr`,`OK / err`),align:`right`,nowrap:!0,render:e=>u(`span`,{className:`tabular-nums ${e.errorCalls>0?`text-danger`:``}`,children:`${String(e.okCalls)} / ${String(e.errorCalls)}`})},{key:`tokens`,header:e(`ai.colTokens`,`In / out tok`),align:`right`,nowrap:!0,render:e=>u(`span`,{className:`tabular-nums`,children:`${String(e.inputTokens)} / ${String(e.outputTokens)}`})},{key:`latency`,header:e(`ai.colAvgMs`,`Avg ms`),align:`right`,nowrap:!0,render:e=>u(`span`,{className:`tabular-nums`,children:String(Math.round(e.avgLatencyMs))})}],[p,e]),h=f.data??[],g=u(`div`,{className:`w-36`,children:u(z,{"aria-label":e(`ai.window`,`Window`),value:String(i),options:Bt.map(t=>({value:String(t),label:e(`ai.lastDays`,`Last {{days}} days`,{days:t})})),onChange:e=>s(Number(e.target.value))})});return u(J,{headingId:`ai-usage-list`,title:e(`ai.usageList`,`Rollup`),actions:g,children:f.isPending?a(`div`,{className:`${d} space-y-2`,"data-testid":`ai-usage-loading`,children:[u(Y,{className:`h-8 w-full`}),u(Y,{className:`h-8 w-full`}),u(Y,{className:`h-8 w-full`})]}):f.isError?u(`div`,{className:d,children:u(G,{title:e(`ai.usageFailed`,`Failed to read usage`),message:f.error instanceof Error?f.error.message:e(`common.error`,`Error`),onRetry:()=>void f.refetch()})}):h.length===0?u(X,{icon:S,title:e(`ai.noUsage`,`No AI calls in this window.`)}):u(K,{columns:m,rows:h,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,maxBodyHeight:U})})}var Ht=`llm`,Ut=[`profiles`,`runtimes`,`usage`,`test`],Wt=[`new`,`edit`];function Gt(e){return Ut.some(t=>t===e)}function Kt(){let{t:e}=Q(),t=se(Ht),[n]=me(),{openNew:r}=le(),i=pe(`/system/ai`,{t:e,isAdmin:!0})??{icon:D,title:e(`system.ai`,`AI`)};if(t!==`present`)return u(ge,{icon:i.icon,title:i.title,children:u(qt,{presence:t})});let o=n.get(`tab`),s=Gt(o)?o:`profiles`,c={profiles:e(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),runtimes: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.`),usage: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.`),test:e(`ai.testSubtitle`,`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.`)},l=s===`profiles`?a(q,{size:`sm`,type:`button`,"data-testid":`ai-add-profile`,onClick:r,children:[u(N,{className:`h-3.5 w-3.5`}),e(`ai.addProfile`,`Add profile`)]}):void 0;return u(he,{icon:i.icon,title:i.title,subtitle:c[s],actions:l,defaultSection:`profiles`,sectionsLabel:`${i.title} sections`,sections:[{id:`profiles`,label:e(`ai.tabProfiles`,`Profiles`),content:u(ct,{}),ownedParams:Wt},{id:`runtimes`,label:e(`ai.tabRuntimes`,`Runtimes`),content:u(ft,{})},{id:`usage`,label:e(`ai.tabUsage`,`Usage`),content:u(Vt,{})},{id:`test`,label:e(`ai.tabTest`,`Test`),content:u(Mt,{})}]})}function qt({presence:e}){let{t}=Q();return e===`pending`?a(`div`,{className:`space-y-3`,"data-testid":`ai-presence-pending`,children:[u(Y,{className:`h-8 w-64`}),u(Y,{className:`h-40 w-full`})]}):e===`unknown`?u(G,{title:t(`ai.presenceUnknownTitle`,`Could not check whether AI is installed`),message:t(`ai.presenceUnknown`,`The hub did not answer the capability check. Reload the page to try again.`)}):u(X,{icon:D,title:t(`ai.absentTitle`,`AI is not installed`),description:t(`ai.absentDescription`,`Install the AI addon from System → Addons to add model profiles.`)})}export{Kt as AiProfilesPage,Kt as default};
@@ -1 +0,0 @@
1
- import{$ as e,B as t,J as n,K as r,L as i,S as a,b as o,q as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{D as l,O as u,V as d,ca as f,ot as p}from"./player-overlays-B32sNiuW.js";import{Br as m,Cn as h,Fr as g,Gr as _,Hr as v,Kr as y,Nn as b,Rr as x,Sn as S,Ur as C,Wr as w,bn as ee,ei as T,oi as E,qr as D,si as O,ti as te,xn as ne,yn as re,zr as ie}from"./client-CBY2Ai10.js";import{Ar as ae,Ja as oe,Ku as se,Mu as ce,Rr as le,Wu as ue,Ya as k,_a as de,da as fe,fr as A,hr as j,s as pe,wo as me}from"./src-wMLlETeo.js";import{t as M}from"./i18n-DBncQ6jl.js";import{t as N}from"./useTranslation-D3Is_4B6.js";e();function he(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function ge(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function P(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function F(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function I(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function _e(e,t){switch(t.type){case`set-new-type`:return e.target.kind===`new`?{...e,target:{...e.target,type:t.deviceType}}:e;case`set-new-role`:{if(e.target.kind!==`new`)return e;let{role:n,...r}=e.target;return{...e,target:t.role===null?r:{...r,role:t.role}}}case`set-name`:return{...e,name:t.name};case`add-feature`:return e.features.some(e=>e.cap===t.cap)?e:{...e,features:[...e.features,{kind:`fields`,cap:t.cap,fields:{}}]};case`remove-feature`:return{...e,features:e.features.filter(e=>e.cap!==t.cap)};case`set-field`:return F(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return F(e,t.cap,e=>({...e,fields:I(e.fields,t.path)}));case`remove-binding`:return F(e,t.cap,e=>{let n=e.fields[t.path];return n?.kind===`expression`?{...e,fields:{...e.fields,[t.path]:{...n,bindings:I(n.bindings,t.bindingName)}}}:e});case`copy-feature`:return F(e,t.cap,e=>({...e,fields:{...e.fields,...Object.fromEntries(t.paths.map(e=>[e,{kind:`from`,source:t.from,cap:t.sourceCap,fieldPath:e}]))}}))}}function ve(e){let t=m.safeParse({target:e.target,features:e.features});return t.success?{ok:!0,composition:t.data}:{ok:!1,problems:t.error.issues.map(e=>`${e.path.join(`.`)||`composition`}: ${e.message}`)}}function ye(e,t){return JSON.stringify(e)!==JSON.stringify(t)}function be(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}var xe=[`room`,`converted-sensor`,`derived-binary`],L={addonId:`provider-homeassistant`,stableId:`sensor.template_source`};function Se(){return P(S({temperatureSources:ee,motionSources:re,occupancyWindowMs:ne}),`Room`)}function Ce(){return P({target:{kind:`new`,type:O.Sensor},features:[{kind:`fields`,cap:`numeric-sensor`,fields:{value:{kind:`expression`,expr:`convert(v, "°C", "°F")`,bindings:{v:{kind:`from`,source:L,cap:`numeric-sensor`,fieldPath:`value`}}},unit:{kind:`expression`,expr:`"°F"`,bindings:{}},lastFetchedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Converted sensor`)}function we(){return P({target:{kind:`new`,type:O.Sensor},features:[{kind:`fields`,cap:`binary`,fields:{on:{kind:`expression`,expr:`v > 20`,bindings:{v:{kind:`from`,source:L,cap:`temperature-sensor`,fieldPath:`celsius`}}},lastChangedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Derived binary`)}function Te(e){switch(e){case`room`:return Se();case`converted-sensor`:return Ce();case`derived-binary`:return we()}}function Ee(e,t){return typeof t==`number`&&Number.isFinite(t)&&t>0?{kind:`device`,path:`/devices/${t}`}:{kind:`editor`,path:`/build/compositions/${encodeURIComponent(e)}`}}var R=`rounded-lg border border-border bg-surface p-4`,De=R;function Oe(e){return{addonId:e.addonId,stableId:e.stableId}}function z(e){return new Map(e.map(e=>[y(Oe(e)),e]))}function ke(e,t,n){let r=e?.features??[],i=r.findIndex(e=>e.cap===n.cap);return{target:e?.target??{kind:`existing`,device:t},features:i===-1?[...r,n]:r.map((e,t)=>t===i?n:e)}}function Ae(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function je(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function B(e){return Array.isArray(e)?e.map(B):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,B(t)]))}function V(e){return JSON.stringify(B(e))}function Me(e,t){return V(e)===V(t)}function H(e,t){return V(e)===V(t)}function Ne(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:M.t(`helpers.customizationSave.notReadYet`)};case`unknown`:return{kind:`refused`,reason:`the customization could not be read: ${e.reason}`};case`not-loaded`:return{kind:`refused`,reason:`the customizations are not loaded yet: ${e.reason}`};case`none`:return t===null?{kind:`noop`}:{kind:`create`,input:{enabled:!0,composition:t}};case`present`:{let n=e.view.block.id;return t===null?{kind:`delete`,blockId:n}:V(t)===V(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function U(e,t){let n=e===`enum`?`string`:e,r=t.kind===`enum`?`string`:t.kind,i={source:t.source,cap:t.cap,fieldPath:t.fieldPath};return r===n?{kind:`from`,...i}:n===`number`&&r===`string`?{kind:`expression`,expr:`number(x)`,bindings:{x:{kind:`from`,...i}}}:null}function W(e){return{kind:`expression`,expr:e,bindings:{}}}function G(e){let t=U(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:W(`"unknown"`),sleeping:W(`false`),lastUpdated:W(`now`)}}}var Pe=[`percent`,...b.options];function K(e,t){return t===`percent`?{level:e}:{"remaining.value":e,"remaining.unit":W(JSON.stringify(t))}}function Fe(e,t){let n=U(`number`,t.remaining);if(n===null||!ie.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:K(n,t.unit)};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:W(`now`),lastFetchedAt:W(`now`)},items:{...e?.items,[t.key]:r}}}function Ie(e){if(e.level!==void 0)return`percent`;let t=e[`remaining.unit`];if(t===void 0||t.kind!==`expression`)return null;try{let e=b.safeParse(JSON.parse(t.expr));return e.success?e.data:null}catch{return null}}function Le(e){return Object.entries(e?.items??{}).map(([e,t])=>{let n=Ie(t.fields),r=q(t.fields.level??t.fields[`remaining.value`]),i=r===null?null:U(`number`,r);return n!==null&&i!==null&&Me(K(i,n),t.fields)?{key:e,label:t.label,unit:n,source:r}:{key:e,label:t.label,unit:null,source:null}})}function Re(e,t){let n=Object.fromEntries(Object.entries(e.items??{}).filter(([e])=>e!==t));return Object.keys(n).length===0?null:{...e,items:n}}function ze(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function Be(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=Object.entries(t.bindings).filter(([e])=>e.startsWith(`active`)).flatMap(([,e])=>e.kind===`from`?[e.source]:[]);return[...new Map(n.map(e=>[y(e),e])).values()]}function Ve(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=t.bindings;return Object.entries(n).flatMap(([e,t])=>{if(!e.startsWith(`active`)||t.kind!==`from`)return[];let r=n[`changed${e.slice(6)}`];return r===void 0||r.kind!==`from`?[]:[{source:t.source,cap:t.cap,activeField:t.fieldPath,changedAtField:r.fieldPath}]})}function q(e){if(e===void 0)return null;if(e.kind===`from`){let{kind:t,...n}=e;return{...n,kind:`number`}}if(e.kind!==`expression`||e.expr!==`number(x)`)return null;let t=e.bindings.x;if(t===void 0||t.kind!==`from`||Object.keys(e.bindings).length!==1)return null;let{kind:n,...r}=t;return{...r,kind:`string`}}function He(e,t){let n=q(e.fields.percentage);if(n===null)return!1;let r=G({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&H(a,r)}function J(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function Ue(e,t,n){let r=t.trim().toLowerCase();return r===``?[]:e.filter(e=>!n.includes(e.id)&&[e.name,e.stableId,e.location??``].some(e=>e.toLowerCase().includes(r))).toSorted((e,t)=>e.name.localeCompare(t.name)).slice(0,20)}function Y(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=Object.getOwnPropertyDescriptor(n,e)?.value}return n}function We(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:U(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function Ge(e,t,n,r){let i={addonId:e.addonId,stableId:e.stableId};return t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,value:n===null?void 0:Y(n[e.cap],t.path),source:We(i,e.cap,t,r)})))}function X(e,t){return t?e===void 0?`—`:e===null?`null`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e):`…`}var Ke=[];function Z({title:e,targetKind:t,excludeDeviceIds:r=Ke,onPick:i,onCancel:o}){let{t:s}=N(),[f,p]=n(null);return a(`aside`,{"aria-label":e,className:`${u} ${l} flex flex-col gap-2`,children:[c(`h3`,{className:d,children:e}),f===null?c(qe,{excludeDeviceIds:r,onSelect:p}):c(Je,{device:f,targetKind:t,onPick:i,onBack:()=>p(null)}),c(`div`,{children:c(j,{variant:`ghost`,size:`sm`,onClick:o,children:s(`customize.picker.cancel`)})})]})}function qe({excludeDeviceIds:e,onSelect:t}){let{t:r}=N(),[i,s]=n(``),l=k({projection:`slim`});return a(o,{children:[a(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground-subtle`,children:[r(`customize.picker.search`),c(ce,{type:`search`,"aria-label":r(`customize.picker.search`),value:i,onChange:e=>s(e.target.value)})]}),l.status===`pending`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:r(`customize.picker.loadingDevices`)}),l.status===`error`&&c(A,{title:r(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&c(`ul`,{className:`flex flex-col gap-1`,children:Ue(J(l.data),i,e).map(e=>c(`li`,{children:a(`button`,{type:`button`,className:`text-left text-[11px] hover:underline`,onClick:()=>t(e),children:[e.name,` `,a(`span`,{className:`text-foreground-subtle`,children:[`· `,e.stableId]})]})},e.id))})]})}function Je({device:e,targetKind:t,selected:n,onPick:r,onBack:i}){let{t:o}=N(),s=oe({deviceId:e.id}),l=me({deviceId:e.id});if(s.status===`pending`)return c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.picker.loadingFields`)});if(s.status===`error`)return c(A,{title:o(`customize.picker.fieldsFailed`),message:s.error?.message??``});let u=Ge(e,s.data,l.status===`success`?l.data:null,t),d=u.filter(e=>e.source===null).length,f={addonId:e.addonId,stableId:e.stableId};return a(`div`,{className:`flex flex-col gap-1`,children:[a(`button`,{type:`button`,className:`text-left text-[11px] text-primary`,onClick:i,children:[`← `,e.name]}),l.status===`error`&&c(`p`,{role:`alert`,className:`text-[10px] text-warning`,children:o(`customize.picker.valuesFailed`,{reason:l.error?.message??``})}),c(`ul`,{role:`listbox`,"aria-label":o(`customize.picker.fields`),className:`flex flex-col gap-1`,children:u.map(t=>{let i=t.source;if(i===null)return null;let o=()=>r({device:e,ref:f,cap:t.cap,path:t.path,kind:t.kind,source:i,value:t.value});return a(`li`,{role:`option`,"aria-selected":n?.cap===t.cap&&n.path===t.path,tabIndex:0,className:`flex justify-between gap-2 text-[11px] cursor-pointer hover:bg-surface-hover rounded px-1`,onClick:o,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&o()},children:[a(`span`,{className:`font-mono`,children:[t.cap,`.`,t.path]}),c(`span`,{children:X(t.value,l.status===`success`)})]},`${t.cap}.${t.path}`)})}),d>0&&t!==null&&c(`p`,{className:`text-[10px] text-foreground-subtle`,children:o(`customize.picker.hidden`,{count:d,kind:o(`customize.kinds.${t}`)})})]})}var Ye=`integration`;function Q(e,t){switch(e.kind){case`from`:{let n=y(e.source);return`${t.get(n)??n} · ${e.cap}.${e.fieldPath}`}case`expression`:return e.expr;case`code`:return`code`}}function Xe(e,t){if(e.kind===`unreachable`)return{kind:`unknown`,reason:e.error};if(e.state===null)return{kind:`unknown`,reason:M.t(`helpers.fieldsTableRows.composerNotReported`)};let n=e.state.fields.find(t);return n===void 0?{kind:`unknown`,reason:M.t(`helpers.fieldsTableRows.noValue`)}:n.state===`unavailable`?{kind:`unavailable`,reason:n.reason??M.t(`common.unavailable`)}:{kind:`value`,value:n.value,staleReason:n.state===`stale`?n.reason??M.t(`common.stale`):null}}function Ze(e,t,n,r){return{key:`${e.feature.cap}.${t}`,cap:e.feature.cap,field:t,origin:`composed`,mode:e.mode,from:Q(n,e.input.sourceNames),value:e.enabled?Xe(e.input.state,r):{kind:`off`}}}function Qe(e){let t=e.feature.cap;return Object.entries(e.feature.fields).map(([n,r])=>Ze(e,n,r,e=>e.cap===t&&e.path===n&&e.item===void 0))}function $e(e){let t=e.feature.cap;return Object.entries(e.feature.items??{}).flatMap(([n,r])=>Object.entries(r.fields).map(([r,i])=>Ze(e,C(x,n,r),i,e=>e.cap===t&&e.path===r&&e.item?.arrayPath===`items`&&e.item.key===n)))}function et(e,t,n){if(e===null)return{kind:`unknown`,reason:M.t(`helpers.fieldsTableRows.stateUnreadable`)};let r=Y(e[t],n),i=r===void 0?void 0:T(r);return i===void 0?{kind:`unknown`,reason:M.t(`helpers.fieldsTableRows.notReported`)}:{kind:`value`,value:i,staleReason:null}}function tt(e){if(e.mode!==`replace`)return[];let t=e.feature.cap,n=new Set(Object.keys(e.feature.fields));return(e.input.nativeFields.get(t)??[]).filter(e=>!n.has(e)).map(n=>({key:`${t}.${n}`,cap:t,field:n,origin:`native`,mode:e.mode,from:Ye,value:et(e.input.snapshot,t,n)}))}function nt(e){return e.composition.features.flatMap(t=>{if(t.kind!==`fields`)return[];let n={feature:t,mode:e.nativeCaps.has(t.cap)?`replace`:`add`,enabled:v(t),input:e};return[...Qe(n),...$e(n),...tt(n)]})}var rt={min:`min(a, b, …)`,max:`max(a, b, …)`,abs:`abs(x)`,floor:`floor(x)`,ceil:`ceil(x)`,sqrt:`sqrt(x)`,round:`round(x, digits?)`,pow:`pow(x, y)`,clamp:`clamp(x, lo, hi)`,avg:`avg(a, b, …)`,sum:`sum(a, b, …)`,coalesce:`coalesce(a, b, …)`,age:`age(now, ts)`,convert:`convert(x, "from", "to")`,any:`any(a, b, …)`,all:`all(a, b, …)`,within:`within(ts, ms)`,number:`number(x)`,latest:`latest(ts, …)`,rose:`rose(level, changedAt, debounceMs?)`,count:`count(x)`},it=/[A-Za-z_][A-Za-z0-9_]*$/;function at(e,t,n){let r=it.exec(e.slice(0,t))?.[0]??``;if(r===``)return[];let i=n.filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`binding`,label:e,insert:e,hintKey:null})),a=`now`.startsWith(r)?[{kind:`now`,label:`now`,insert:`now`,hintKey:`compositionEditor.now`}]:[],o=[...te].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:rt[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function ot(e,t,n){let r=t-(it.exec(e.slice(0,t))?.[0]??``).length;return{text:`${e.slice(0,r)}${n.insert}${e.slice(t)}`,cursor:r+n.insert.length}}e();function st({label:e,value:t,bindings:r,onChange:i}){let{t:o}=N(),l=s(null),[u,d]=n(t.length),f=at(t,u,r);return a(`div`,{className:`flex flex-col gap-1`,children:[a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e,c(`input`,{ref:l,className:`font-mono px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:t,onChange:e=>{i(e.target.value),d(e.target.selectionStart??e.target.value.length)},onSelect:e=>d(e.currentTarget.selectionStart??t.length)})]}),f.length>0&&c(`ul`,{role:`listbox`,"aria-label":o(`compositionEditor.suggestions`),className:`rounded border border-border bg-surface text-[11px]`,children:f.map(e=>a(`li`,{role:`option`,"aria-selected":!1,tabIndex:0,className:`flex justify-between gap-2 px-1 cursor-pointer hover:bg-surface-hover`,onClick:()=>{let n=ot(t,u,e);i(n.text),d(n.cursor),l.current?.focus()},children:[c(`span`,{className:`font-mono`,children:e.label}),e.hintKey!==null&&c(`span`,{className:`text-foreground-subtle`,children:o(e.hintKey)})]},`${e.kind}:${e.label}`))})]})}function ct(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:M.t(`helpers.fieldPreview.codeFields`)};if(e.kind===`expression`&&(g(e.expr,`rose`)||g(e.expr,`count`)))return{kind:`runtime-only`};let r=D(e).filter(e=>t.get(_(e.source,e.cap))?.kind!==`value`).map(w);if(r.length>0)return{kind:`waiting`,missing:r};let i=h({source:e,now:n,read:e=>{let n=t.get(_(e.source,e.cap)),r=n?.kind===`value`?Y(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:T(r);return i===void 0?{state:`unavailable`,reason:M.t(`helpers.fieldPreview.notReported`,{path:`${e.cap}.${e.fieldPath}`}),fatal:!1}:{state:`fresh`,value:i}}});return i.state===`unavailable`?{kind:`unavailable`,reason:i.reason}:{kind:`value`,value:i.value,stale:i.reason}}e();function lt({sliceKey:e,deviceId:n,capName:r,onReading:i}){let a=pe(p().trpcClient,n,r);return t(()=>{i(e,a===void 0?{kind:`pending`}:{kind:`value`,slice:a})},[e,a,i]),null}function ut(e,t){return[...new Map(D(e).map(e=>[_(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(y(n.source))}))}function dt({source:e}){let{t}=N(),r=k({projection:`slim`}),[o,s]=n(new Map),l=i((e,t)=>{s(n=>new Map([...n,[e,t]]))},[]),u=ut(e,z(r.status===`success`?J(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>y(e.read.source)):[];return a(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[u.map(e=>e.device===void 0?null:c(lt,{sliceKey:e.key,deviceId:e.device.id,capName:e.read.cap,onReading:l},e.key)),c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.label`)}),r.status===`error`?c(`span`,{className:`text-warning`,children:t(`compositionEditor.preview.devicesFailed`,{reason:r.error?.message??``})}):d.length>0?c(`span`,{className:`text-warning`,children:t(`compositionEditor.preview.unknownDevice`,{sources:d.join(`, `)})}):c(ft,{preview:ct(e,o,Date.now())})]})}function ft({preview:e}){let{t}=N();switch(e.kind){case`value`:return a(`strong`,{children:[`→ `,X(e.value,!0),e.stale===null?``:` (${e.stale})`]});case`unavailable`:return c(`span`,{className:`text-warning`,children:e.reason});case`waiting`:return c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.waiting`,{sources:e.missing.join(`, `)})});case`runtime-only`:return c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.runtimeOnly`)})}}e();function pt({path:e,kind:t,required:r,source:i,onSet:s,onClear:l,onRemoveBinding:u,sourceNames:d}){let{t:f}=N(),[p,m]=n(`idle`),h=i?.kind===`expression`?i:null;return a(`div`,{className:`flex flex-col gap-1 rounded border border-border p-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono text-[11px]`,children:e}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:[f(`customize.kinds.${t}`),r?` · ${f(`compositionEditor.required`)}`:``]}),c(j,{size:`sm`,variant:`outline`,onClick:()=>m(`take`),children:f(`compositionEditor.takeFrom`)}),c(j,{size:`sm`,variant:`outline`,"aria-pressed":h!==null,onClick:()=>s(h??{kind:`expression`,expr:`null`,bindings:{}}),children:f(`compositionEditor.formula`)}),i!==void 0&&c(j,{size:`sm`,variant:`ghost`,onClick:l,children:f(`compositionEditor.clear`)})]}),i?.kind===`from`&&c(`span`,{className:`text-[11px]`,children:Q(i,d)}),h!==null&&a(o,{children:[c(st,{label:f(`compositionEditor.formulaFor`,{path:e}),value:h.expr,bindings:Object.keys(h.bindings),onChange:e=>s({...h,expr:e})}),c(`ul`,{className:`text-[11px] flex flex-col gap-0.5`,children:Object.entries(h.bindings).map(([e,t])=>a(`li`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono`,children:e}),c(`span`,{children:t.kind===`from`?Q(t,d):JSON.stringify(t.value)}),c(j,{size:`sm`,variant:`ghost`,"aria-label":f(`compositionEditor.removeBinding`,{name:e}),onClick:()=>u(e),children:`×`})]},e))}),c(j,{size:`sm`,variant:`ghost`,onClick:()=>m(`add-binding`),children:f(`compositionEditor.addSource`)})]}),p!==`idle`&&c(Z,{title:f(p===`take`?`compositionEditor.takeFrom`:`compositionEditor.addSource`),targetKind:p===`take`?t:null,onCancel:()=>m(`idle`),onPick:e=>{if(p===`take`)s(e.source);else if(h!==null){let t=be(Object.keys(h.bindings));s({...h,bindings:{...h.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}})}m(`idle`)}}),i!==void 0&&c(dt,{source:i})]})}e();function mt(e){return e===null||e.kind===`known`?null:e}function ht({draft:e,deviceType:t,nativeCaps:r,targetFields:i,dispatch:s}){let{t:l}=N(),u=fe({deviceType:t}),d=k({projection:`slim`}),f=new Map([...z(d.status===`success`?J(d.data):[])].map(([e,t])=>[e,t.name])),[p,m]=n(null),h=mt(r)??mt(i),g=r?.kind===`known`?r.value:new Set,_=new Set(e.features.map(e=>e.cap)),v=u.status===`success`?u.data.caps.filter(e=>!_.has(e.cap)&&!g.has(e.cap)):[],y=[...g].filter(e=>!_.has(e)),b=e=>g.has(e)?((i?.kind===`known`?i.value.caps.find(t=>t.cap===e):void 0)?.fields??[]).filter(e=>e.item!==!0&&!e.path.includes(`.`)).map(e=>({path:e.path,kind:e.kind,required:!1})):((u.status===`success`?u.data.caps.find(t=>t.cap===e):void 0)?.fields??[]).map(e=>({path:e.path,kind:e.kind,required:e.required}));return h===null?a(o,{children:[a(`section`,{"aria-labelledby":`editor-features`,className:`${R} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),u.status===`pending`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.checking`)}),u.status===`error`&&c(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.unknown`,{reason:u.error?.message??``})}),a(`div`,{className:`flex flex-wrap gap-1`,children:[e.features.map(e=>a(`span`,{className:`flex items-center gap-1 rounded border border-border px-1.5 text-[11px]`,children:[e.cap,c(le,{variant:g.has(e.cap)?`default`:`info`,children:g.has(e.cap)?l(`compositionEditor.replaces`):l(`compositionEditor.added`)}),c(`button`,{type:`button`,"aria-label":l(`compositionEditor.removeFeature`,{cap:e.cap}),onClick:()=>s({type:`remove-feature`,cap:e.cap}),children:`×`})]},e.cap)),v.map(e=>a(j,{size:`sm`,variant:`outline`,onClick:()=>s({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),y.map(e=>c(j,{size:`sm`,variant:`ghost`,onClick:()=>s({type:`add-feature`,cap:e}),children:l(`compositionEditor.replaceIn`,{cap:e})},e))]})]}),e.features.map(e=>a(`section`,{"aria-label":l(`compositionEditor.steps.fieldsOf`,{cap:e.cap}),className:`${R} flex flex-col gap-2`,children:[a(`div`,{className:`flex items-center justify-between`,children:[c(`h2`,{className:`text-sm font-semibold`,children:l(`compositionEditor.steps.fieldsOf`,{cap:e.cap})}),c(j,{size:`sm`,variant:`outline`,onClick:()=>m(e.cap),children:l(`compositionEditor.copyFeature`)})]}),p===e.cap&&c(Z,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>m(null),onPick:t=>{s({type:`copy-feature`,cap:e.cap,from:t.ref,sourceCap:t.cap,paths:b(e.cap).map(e=>e.path)}),m(null)}}),b(e.cap).map(t=>c(pt,{path:t.path,kind:t.kind,required:t.required,source:e.fields[t.path],onSet:n=>s({type:`set-field`,cap:e.cap,path:t.path,source:n}),onClear:()=>s({type:`clear-field`,cap:e.cap,path:t.path}),onRemoveBinding:n=>s({type:`remove-binding`,cap:e.cap,path:t.path,bindingName:n}),sourceNames:f},t.path))]},e.cap))]}):a(`section`,{"aria-labelledby":`editor-features`,className:`${R} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:h.kind===`unknown`?h.reason:l(`compositionEditor.reading`)})]})}var $=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function gt({draft:e,targetName:t,dispatch:n}){let r=f(),{t:i}=N(),o=e.target;return a(`section`,{"aria-labelledby":`editor-target`,className:`${R} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-target`,className:`text-sm font-semibold`,children:i(`compositionEditor.steps.target`)}),o.kind===`existing`?c(`p`,{className:`text-[11px]`,children:i(`compositionEditor.existingTarget`,{name:t??`${o.device.addonId}/${o.device.stableId}`})}):a(`div`,{className:`grid grid-cols-3 gap-2`,children:[a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`compositionEditor.targetType`),c(`select`,{className:$,value:o.type,onChange:e=>{let t=Object.values(O).find(t=>t===e.target.value);t!==void 0&&n({type:`set-new-type`,deviceType:t})},children:Object.values(O).map(e=>c(`option`,{value:e,children:se(e,r).label},e))})]}),a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`customize.identity.role`),a(`select`,{className:$,value:o.role??``,onChange:e=>n({type:`set-new-role`,role:Object.values(E).find(t=>t===e.target.value)??null}),children:[c(`option`,{value:``,children:i(`customize.identity.noRole`)}),Object.values(E).map(e=>c(`option`,{value:e,children:ue(e,r).label},e))]})]}),a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`compositionEditor.name`),c(`input`,{className:$,value:e.name,onChange:e=>n({type:`set-name`,name:e.target.value})})]})]})]})}e();function _t({draft:e,blockId:r,saving:i,onSave:o,onCancel:s}){let{t:l}=N(),u=de(),d=ve(e),f=d.ok?JSON.stringify(d.composition):``,[p,m]=n({key:``,state:{kind:`checking`}});t(()=>{if(!d.ok)return;let e=d.composition,t=setTimeout(()=>{u.mutateAsync({composition:e,...r===null?{}:{blockId:r}}).then(e=>m({key:f,state:e.ok?{kind:`ok`}:{kind:`refused`,problems:e.problems}})).catch(e=>m({key:f,state:{kind:`unknown`,reason:e instanceof Error?e.message:String(e)}}))},500);return()=>clearTimeout(t)},[f,r]);let h=d.ok?p.key===f?p.state:{kind:`checking`}:{kind:`invalid-draft`,problems:d.problems};return a(`section`,{"aria-labelledby":`editor-verify`,className:`${R} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-verify`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.verify`)}),h.kind===`checking`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.verify.checking`)}),h.kind===`ok`&&c(`p`,{className:`text-[11px] text-success`,children:l(`compositionEditor.verify.ok`)}),h.kind===`unknown`&&c(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.verify.unknown`,{reason:h.reason})}),(h.kind===`invalid-draft`||h.kind===`refused`)&&c(`ul`,{role:`alert`,className:`flex flex-col gap-1 text-[11px] text-danger`,children:h.kind===`invalid-draft`?h.problems.map(e=>c(`li`,{children:e},e)):h.problems.map(e=>a(`li`,{children:[c(`span`,{className:`font-mono`,children:e.path}),` — `,e.message]},`${e.path}:${e.code}`))}),a(`div`,{className:`flex gap-2`,children:[c(j,{variant:`ghost`,onClick:s,children:l(`compositionEditor.cancel`)}),c(j,{disabled:h.kind!==`ok`||i||!d.ok,onClick:()=>d.ok&&o(d.composition),children:l(`compositionEditor.save`)})]})]})}e();function vt({initial:e,blockId:t,deviceType:r,targetName:i=null,nativeCaps:a,targetFields:o,save:s,onCancel:l,showTemplates:u=!1}){let[d,f]=n(e),p=`${d.name}:${d.features.map(e=>e.cap).join(`,`)}:${d.target.kind===`new`?d.target.type:`existing`}`;return c(yt,{seed:d,blockId:t,deviceType:r,targetName:i,nativeCaps:a,targetFields:o,showTemplates:u,onApplyTemplate:e=>{f(Te(e))},save:s,onCancel:l},p)}function yt({seed:e,blockId:t,deviceType:i,targetName:o,nativeCaps:s,targetFields:l,showTemplates:u,onApplyTemplate:d,save:f,onCancel:p}){let{t:m}=N(),h=ae(),[g,_]=r(_e,e),[v,y]=n(!1),[b,x]=n(null),S=async t=>{ye(e,g)&&!await h({title:m(`compositionEditor.templates.confirmTitle`),message:m(`compositionEditor.templates.confirmMessage`),confirmLabel:m(`compositionEditor.templates.confirmApply`),variant:`danger`})||d(t)},C=g.target.kind===`new`?g.target.type:i,w=async e=>{y(!0);let t=await f(e,g.name);y(!1),x(t.kind===`refused`?t.reason:null)};return a(`div`,{className:`flex flex-col gap-4`,children:[u&&g.target.kind===`new`&&a(`div`,{className:`rounded-lg border border-border bg-surface p-4 flex flex-wrap gap-2`,"data-testid":`composition-templates`,children:[c(`span`,{className:`text-[11px] text-foreground-subtle self-center`,children:m(`compositionEditor.templates.label`)}),xe.map(e=>c(j,{size:`sm`,variant:`outline`,onClick:()=>void S(e),children:m(`compositionEditor.templates.${e}`)},e))]}),c(gt,{draft:g,targetName:o,dispatch:_}),c(ht,{draft:g,deviceType:C,nativeCaps:s,targetFields:l,dispatch:_}),c(_t,{draft:g,blockId:t,saving:v,onSave:e=>void w(e),onCancel:p}),b!==null&&c(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:b})]})}export{Ae as C,ge as D,P as E,he as O,ke as S,Ee as T,q as _,Je as a,Ne as b,J as c,Fe as d,Le as f,ze as g,He as h,nt as i,Pe as l,Ve as m,ct as n,X as o,Be as p,st as r,Y as s,vt as t,G as u,Re as v,De as w,H as x,je as y};