@camstack/addon-admin-ui 1.2.298 → 1.2.299
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.
- package/dist/assets/{AddonCollectionPage-Df7TFa8c.js → AddonCollectionPage-Bgk5av4b.js} +1 -1
- package/dist/assets/{Addons-BL0l83HX.js → Addons-BiAma6AN.js} +1 -1
- package/dist/assets/{AdminTabs-_3rYGvff.js → AdminTabs-C7QmfUqk.js} +1 -1
- package/dist/assets/{AiProfiles-Cb_Zmt2e.js → AiProfiles-B4z9wywC.js} +1 -1
- package/dist/assets/{BrokerForm-O4qx5NOl.js → BrokerForm-lP42jKPi.js} +1 -1
- package/dist/assets/Build-6D08C629.js +32 -0
- package/dist/assets/{Capabilities-BhWA9I3U.js → Capabilities-BSbtmFZi.js} +1 -1
- package/dist/assets/{CapabilityBadges-E822NR6-.js → CapabilityBadges-Ck0Zi6v3.js} +1 -1
- package/dist/assets/{Cluster-CytT6oOR.js → Cluster-D8yFB0Np.js} +2 -2
- package/dist/assets/CompositionEditor-KckU34Rc.js +1 -0
- package/dist/assets/{CompositionEditorPage-D-Pr98e9.js → CompositionEditorPage-CPRkhwhE.js} +1 -1
- package/dist/assets/{Data-C_5nuknP.js → Data-CPY-GSWR.js} +1 -1
- package/dist/assets/{DetectionIntelligence-Ddu_ubPT.js → DetectionIntelligence-Bfo6e0Fm.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-kHgMnzdV.js → DeviceAggregateSection-XoINX6MC.js} +1 -1
- package/dist/assets/DeviceDetail-BkOvR0zE.js +2 -0
- package/dist/assets/{Devices-CkDDnlUY.js → Devices-CBo87XTe.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-4bKTeu-8.js → EmbedPlayerPage-nlk8WGop.js} +1 -1
- package/dist/assets/Events-BTw7o3c3.js +1 -0
- package/dist/assets/{FormBuilder-DFkvqrJD.js → FormBuilder-DCWIHY3A.js} +1 -1
- package/dist/assets/{Identity-Bs0HMUZv.js → Identity-Z0uQisms.js} +1 -1
- package/dist/assets/IntegrationDetail-CxpJItTw.js +1 -0
- package/dist/assets/Integrations-CWQ4Bmhh.js +1 -0
- package/dist/assets/Integrations-CvQ2Qsiu.js +1 -0
- package/dist/assets/Locations-D-vr4FmX.js +3 -0
- package/dist/assets/{Logs-CdSMPoxV.js → Logs-MUeTxUBL.js} +1 -1
- package/dist/assets/{ModelLicenses-GuvIn1gk.js → ModelLicenses-D4ZI-ieb.js} +1 -1
- package/dist/assets/{MotionZonesSettings-C5cymw6R.js → MotionZonesSettings-eZjxA7t2.js} +1 -1
- package/dist/assets/{MyAccess-DKvcVvYi.js → MyAccess-BLNO_4Vb.js} +1 -1
- package/dist/assets/{Network-DO7j65It.js → Network-V-sOJFE3.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-Bj_BK8BK.js → NodeAddonsSettingsPanel-DeYrqSPH.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-DEF7iUIy.js → NodeInferenceDevices-BAdCG-8q.js} +1 -1
- package/dist/assets/Notifications-CVMvqEcL.js +1 -0
- package/dist/assets/{Pipeline-C3rd2o0z.js → Pipeline-Dv9QxF4V.js} +1 -1
- package/dist/assets/{Plates-KK9Jucpy.js → Plates-BxIKSjrx.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-DLWoWKa1.js → PrivacyMaskSettings-1wQ0sX0H.js} +1 -1
- package/dist/assets/{ProviderIcon-B95H0OGs.js → ProviderIcon-BbMyhwcl.js} +1 -1
- package/dist/assets/{Recordings-BIMt47G_.js → Recordings-C7qug-1m.js} +1 -1
- package/dist/assets/{ScanNetworkModal-C745HgYN.js → ScanNetworkModal-DK_tyixc.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DEFeKrQi.js → SceneMonitorEditor-Ds9agOvV.js} +1 -1
- package/dist/assets/{Scenes-31t1OF8h.js → Scenes-Raq-0hCd.js} +1 -1
- package/dist/assets/{Settings-rfP-ZvI0.js → Settings-Ddx30tFk.js} +1 -1
- package/dist/assets/{Showroom-Df8NV8QK.js → Showroom-B8b26pPh.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-DGsk0Ute.js → StorageLocationsPanel-DfOP9cjP.js} +1 -1
- package/dist/assets/{Terminal-CDJOGeqz.js → Terminal-BQlJcagf.js} +1 -1
- package/dist/assets/{Viewer-BjRST1rI.js → Viewer-Dugm0Lyh.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C4tT4btJ.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BGlzIG7f.js} +1 -1
- package/dist/assets/{archive-TrxiLNcl.js → archive-M1NkdyX1.js} +1 -1
- package/dist/assets/{authed-media-CH1U0Z7I.js → authed-media-BbclCn8D.js} +1 -1
- package/dist/assets/{boxes-BAiYOams.js → boxes-3RvvFSDa.js} +1 -1
- package/dist/assets/circle-slash-CSI0dVHX.js +1 -0
- package/dist/assets/{debounced-invalidate-BDeU9yPQ.js → debounced-invalidate-Dg1eT_Y-.js} +1 -1
- package/dist/assets/{device-integration-icon-CHkYoY0a.js → device-integration-icon-CteXz-vc.js} +1 -1
- package/dist/assets/device-picker-model-B29vbIKa.js +1 -0
- package/dist/assets/{dist-a0ex8Xy3.js → dist--LXFk-rO.js} +1 -1
- package/dist/assets/dist-B8s4O5ek.js +349 -0
- package/dist/assets/{face-bbox-BO4f9HS4.js → face-bbox-D0yJXCw6.js} +1 -1
- package/dist/assets/{hard-drive-download-DMTgloj5.js → hard-drive-download-DWkfRg_9.js} +1 -1
- package/dist/assets/{hostInit-DImvGASf.js → hostInit-1ItCQHp9.js} +1 -1
- package/dist/assets/{index-CgXPc-AV.js → index-BZ3TdH1g.js} +3 -3
- package/dist/assets/index-egLHRpbu.css +2 -0
- package/dist/assets/{layers-eROspUmA.js → layers-DkNaQ1QP.js} +1 -1
- package/dist/assets/{location-owned-usage-sOE3xLhc.js → location-owned-usage-BQ0INIT2.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-84890b2e.js → mf-entry-bootstrap-0-e02cda07.js} +2 -2
- package/dist/assets/{player-overlays-o54P23P2.js → player-overlays-B_uiidR6.js} +1 -1
- package/dist/assets/remoteEntry-CqjS7D1o.js +1 -0
- package/dist/assets/{send-D0d5eZ61.js → send-B_CQqzXx.js} +1 -1
- package/dist/assets/{settings-2-Dqj-Whfr.js → settings-2-BYvhRrnI.js} +1 -1
- package/dist/assets/{square-check-big-CC2dU6RF.js → square-check-big-DvgdtLa5.js} +1 -1
- package/dist/assets/{src-f3OJiuN1.js → src-B3pgYpGR.js} +8 -8
- package/dist/assets/src-BH2M3zRW.js +349 -0
- package/dist/assets/{use-scenes-feed-R-GEBDBU.js → use-scenes-feed-C3EryavW.js} +1 -1
- package/dist/assets/{use-stationary-objects-CO4PdIFG.js → use-stationary-objects-BM21l4YT.js} +1 -1
- package/dist/assets/{useDevice-BU0imY9B.js → useDevice-DPvLTx63.js} +1 -1
- package/dist/assets/useEventInvalidation-B0D6f62J.js +1 -0
- package/dist/assets/{useNodeUrlSelection-Dlf0CWPU.js → useNodeUrlSelection-DPB3ldG4.js} +1 -1
- package/dist/assets/user-round-BijBSyFY.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DAaE-Myc.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Bu6krwIe.js} +2 -2
- package/dist/index.html +6 -6
- package/dist/server/addon.js +153 -89
- package/package.json +1 -1
- package/dist/assets/Build-CNQhG6ma.js +0 -32
- package/dist/assets/CompositionEditor-BhWVT7RV.js +0 -1
- package/dist/assets/DeviceDetail-BZJKkllF.js +0 -2
- package/dist/assets/Events-DoN_tLnP.js +0 -1
- package/dist/assets/IntegrationDetail-Cr5-tJiw.js +0 -1
- package/dist/assets/Integrations-D5LYSgWQ.js +0 -1
- package/dist/assets/Integrations-D5hX1u4b.js +0 -1
- package/dist/assets/Locations-NysPu2nw.js +0 -3
- package/dist/assets/Notifications-R4TlE5EH.js +0 -1
- package/dist/assets/circle-slash-Di12V3ul.js +0 -1
- package/dist/assets/dist-3HV5hQQl.js +0 -349
- package/dist/assets/index-DOZUgTMC.css +0 -2
- package/dist/assets/remoteEntry-nDKnWQvr.js +0 -1
- package/dist/assets/src-C36-vO5A.js +0 -349
- package/dist/assets/useEventInvalidation-BxCnrh5u.js +0 -1
- package/dist/assets/user-round-CXdkrmGZ.js +0 -1
package/dist/server/addon.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
|
-
//#region ../types/dist/event-category-
|
|
3
|
+
//#region ../types/dist/event-category-BGmz_oxW.mjs
|
|
4
4
|
var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
5
5
|
EventCategory["SystemBoot"] = "system.boot";
|
|
6
6
|
EventCategory["SystemAddonsReady"] = "system.addons-ready";
|
|
@@ -533,6 +533,15 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
|
533
533
|
*/
|
|
534
534
|
EventCategory["PipelineAudioInferenceResult"] = "pipeline.audio-inference-result";
|
|
535
535
|
EventCategory["DetectionPhaseTransition"] = "detection.phase-transition";
|
|
536
|
+
/**
|
|
537
|
+
* A camera provider's RAW onboard motion push (D673): the `MotionOnMotionChanged`
|
|
538
|
+
* data shape without `triggeredBy`, built by `providerMotionEvent`. Its one
|
|
539
|
+
* consumer is the orchestrator's camera-sensors bridge, which re-emits the
|
|
540
|
+
* camera's EFFECTIVE onboard motion as `MotionOnMotionChanged` (a pass-through
|
|
541
|
+
* for a camera with no attached sensor). Providers must not emit
|
|
542
|
+
* `MotionOnMotionChanged` themselves; `scripts/check-onboard-motion-emitters.ts`
|
|
543
|
+
* keeps it so (camera-grid is a named, deferred exception).
|
|
544
|
+
*/
|
|
536
545
|
EventCategory["ProviderMotion"] = "provider.motion";
|
|
537
546
|
EventCategory["ProviderDetection"] = "provider.detection";
|
|
538
547
|
EventCategory["EnrichmentEmbeddingStored"] = "enrichment.embedding.stored";
|
|
@@ -5371,7 +5380,7 @@ var ZodIssueCode = {
|
|
|
5371
5380
|
var ZodFirstPartyTypeKind;
|
|
5372
5381
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5373
5382
|
//#endregion
|
|
5374
|
-
//#region ../types/dist/sleep-
|
|
5383
|
+
//#region ../types/dist/sleep-CDCONfkt.mjs
|
|
5375
5384
|
/**
|
|
5376
5385
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5377
5386
|
* window to float samples (D455).
|
|
@@ -7418,7 +7427,7 @@ var DeviceRole = /* @__PURE__ */ function(DeviceRole) {
|
|
|
7418
7427
|
return DeviceRole;
|
|
7419
7428
|
}({});
|
|
7420
7429
|
//#endregion
|
|
7421
|
-
//#region ../types/dist/composition-
|
|
7430
|
+
//#region ../types/dist/composition-43aqsZQj.mjs
|
|
7422
7431
|
/**
|
|
7423
7432
|
* The ffmpeg build every CamStack node downloads, per platform and arch.
|
|
7424
7433
|
*
|
|
@@ -7475,13 +7484,12 @@ portable("linux64"), portable("linuxarm64"), portable("macarm64"), portable("mac
|
|
|
7475
7484
|
* LA tabella "quale booleano di questo tipo di device conta come ALTO", e il
|
|
7476
7485
|
* valutatore puro del suo FRONTE.
|
|
7477
7486
|
*
|
|
7478
|
-
*
|
|
7479
|
-
*
|
|
7480
|
-
*
|
|
7481
|
-
*
|
|
7482
|
-
*
|
|
7483
|
-
* fa suonare il campanello ma non registra" — è esattamente D62.
|
|
7484
|
-
* SPOSTA qui e il doorbell la ri-esporta.
|
|
7487
|
+
* UNA tabella per tutti quelli che chiedono "questo device è ALTO?": il
|
|
7488
|
+
* trigger `RecordingTriggers.sensorDeviceIds` del recorder, i marker dei
|
|
7489
|
+
* sensori della post-analysis, il bridge camera-sensors dell'orchestratore e
|
|
7490
|
+
* le sorgenti di un campanello composto (`doorbellFeatureSources`, D671).
|
|
7491
|
+
* Una seconda copia divergerebbe alla prima cap aggiunta, e il sintomo — "il
|
|
7492
|
+
* sensore fa suonare il campanello ma non registra" — è esattamente D62.
|
|
7485
7493
|
*
|
|
7486
7494
|
* ⚠ NON è `DEVICE_STATE_READERS` (`catalogs/device-state-vocabulary.ts`), e le
|
|
7487
7495
|
* due non vanno unificate: quella risponde a "qual è la PAROLA di stato per una
|
|
@@ -9216,7 +9224,7 @@ var RecordingTriggersSchema = object({
|
|
|
9216
9224
|
*
|
|
9217
9225
|
* Cosa vuol dire "alto" dipende dal TIPO di device e non è deciso qui:
|
|
9218
9226
|
* `SOURCE_CAP_ACTIVE_FIELD` (`catalogs/sensor-active-state.ts`) è LA tabella,
|
|
9219
|
-
* la stessa
|
|
9227
|
+
* la stessa del campanello composto (D671). Ed è il FRONTE, non
|
|
9220
9228
|
* il livello: un contatto trovato già aperto al riavvio del runner non fa
|
|
9221
9229
|
* registrare.
|
|
9222
9230
|
*/
|
|
@@ -15302,28 +15310,10 @@ method(object({
|
|
|
15302
15310
|
deviceIds: array(number()).readonly(),
|
|
15303
15311
|
caps: array(string()).readonly().optional()
|
|
15304
15312
|
}), record(string(), record(string(), unknown().nullable())));
|
|
15305
|
-
|
|
15306
|
-
/** Ms epoch of the last press. null = never observed since this provider started. */
|
|
15307
|
-
lastPressedAt: number().nullable(),
|
|
15308
|
-
/** Counter since provider start. Resets on reboot. Useful for metrics/debug. */
|
|
15309
|
-
pressCountSinceStart: number()
|
|
15310
|
-
});
|
|
15311
|
-
object({
|
|
15312
|
-
deviceId: number(),
|
|
15313
|
-
timestamp: number()
|
|
15314
|
-
});
|
|
15315
|
-
/**
|
|
15316
|
-
* The `doorbell-source` extension slot's editable value (D648): the camera's
|
|
15317
|
-
* virtual-doorbell trigger devices, exactly what the wrapper's
|
|
15318
|
-
* `doorbellSources` persists (as `{ deviceId }` records).
|
|
15319
|
-
*/
|
|
15320
|
-
var DoorbellSourceSlotValueSchema = object({ deviceIds: array(number().int().positive()) });
|
|
15313
|
+
var ExtensionSlotIdSchema = _enum(["linked-devices"]);
|
|
15321
15314
|
DeviceType.Camera;
|
|
15322
|
-
DeviceType.Button, DeviceType.Camera;
|
|
15323
|
-
var ExtensionSlotIdSchema = _enum(["doorbell-source", "linked-devices"]);
|
|
15324
|
-
DeviceType.Camera, DeviceType.Camera;
|
|
15325
15315
|
/** A slot's editable value, discriminated on `slot`. */
|
|
15326
|
-
var ExtensionSlotValueSchema = discriminatedUnion("slot", [
|
|
15316
|
+
var ExtensionSlotValueSchema = discriminatedUnion("slot", [LinkedDevicesSlotValueSchema.extend({ slot: literal("linked-devices") })]);
|
|
15327
15317
|
DeviceType.Camera;
|
|
15328
15318
|
var ExtensionSourceAvailabilitySchema = discriminatedUnion("state", [object({ state: literal("ok") }), object({
|
|
15329
15319
|
state: literal("unreachable"),
|
|
@@ -15360,10 +15350,11 @@ var ExtensionSlotSourceSchema = object({
|
|
|
15360
15350
|
});
|
|
15361
15351
|
/**
|
|
15362
15352
|
* A DIFFERENT authority that gates whether the slot's sources do anything —
|
|
15363
|
-
* reported read-only, named, never written through this contract (D62).
|
|
15364
|
-
*
|
|
15365
|
-
*
|
|
15366
|
-
* `unknown` means the gate could
|
|
15353
|
+
* reported read-only, named, never written through this contract (D62) — e.g.
|
|
15354
|
+
* a slot whose sources act only while a wrapper is bound to the host, a
|
|
15355
|
+
* binding that belongs to `deviceManager.setWrapperActive`. No slot reports
|
|
15356
|
+
* one today (`linked-devices` answers `null`). `unknown` means the gate could
|
|
15357
|
+
* not be read; it is not "inactive" (D315).
|
|
15367
15358
|
*/
|
|
15368
15359
|
var ExtensionSlotActivationSchema = object({
|
|
15369
15360
|
state: _enum([
|
|
@@ -15379,7 +15370,7 @@ var ExtensionSlotRowSchema = discriminatedUnion("state", [object({
|
|
|
15379
15370
|
/** `<source>:<slotId>` — the routing key for `listCandidates` / `setSlot`. */
|
|
15380
15371
|
slotRef: string(),
|
|
15381
15372
|
slot: ExtensionSlotIdSchema,
|
|
15382
|
-
/** Names the store written (D62), e.g. `
|
|
15373
|
+
/** Names the store written (D62), e.g. `device-manager:_linkedDeviceIds`. */
|
|
15383
15374
|
authority: string(),
|
|
15384
15375
|
activation: ExtensionSlotActivationSchema.nullable(),
|
|
15385
15376
|
value: ExtensionSlotValueSchema,
|
|
@@ -20463,12 +20454,26 @@ var CameraSensorRefSchema = object({
|
|
|
20463
20454
|
function cameraSensorRefKey(ref) {
|
|
20464
20455
|
return `${ref.addonId}/${ref.stableId}`;
|
|
20465
20456
|
}
|
|
20466
|
-
/**
|
|
20467
|
-
|
|
20468
|
-
|
|
20469
|
-
|
|
20470
|
-
|
|
20471
|
-
|
|
20457
|
+
/**
|
|
20458
|
+
* A sensor's mode (D673). `in-addition`: its motion is the camera's motion too.
|
|
20459
|
+
* `replace`: its motion is the camera's, and while one is READY the camera's
|
|
20460
|
+
* own motion no longer counts on its own. `confirm`: while one is READY the
|
|
20461
|
+
* camera's own motion counts only while a confirm sensor is active — with or
|
|
20462
|
+
* without a replace sensor (spec C2, the controller's ruling on Q1).
|
|
20463
|
+
*/
|
|
20464
|
+
var CameraSensorModeSchema = _enum([
|
|
20465
|
+
"in-addition",
|
|
20466
|
+
"confirm",
|
|
20467
|
+
"replace"
|
|
20468
|
+
]);
|
|
20469
|
+
/** A stored sensor with no mode — every CS-1 row — is in addition. */
|
|
20470
|
+
var DEFAULT_CAMERA_SENSOR_MODE = "in-addition";
|
|
20471
|
+
/**
|
|
20472
|
+
* A camera's attached sensors. A CS-1 row carried an envelope
|
|
20473
|
+
* `mode: 'in-addition'`: `z.object` drops it on parse, and the PARSED value is
|
|
20474
|
+
* what the write stores (D672 rule 3), so it is never written again.
|
|
20475
|
+
*/
|
|
20476
|
+
var CameraSensorsConfigSchema = object({ sensors: array(CameraSensorRefSchema.extend({ mode: CameraSensorModeSchema.default(DEFAULT_CAMERA_SENSOR_MODE) })).min(1).max(8) }).superRefine((value, ctx) => {
|
|
20472
20477
|
const seen = /* @__PURE__ */ new Set();
|
|
20473
20478
|
value.sensors.forEach((ref, index) => {
|
|
20474
20479
|
const key = cameraSensorRefKey(ref);
|
|
@@ -20480,39 +20485,41 @@ var CameraSensorsConfigSchema = object({
|
|
|
20480
20485
|
seen.add(key);
|
|
20481
20486
|
});
|
|
20482
20487
|
});
|
|
20483
|
-
|
|
20488
|
+
/** Every attachment names its mode; an older orchestrator that does not is in addition. */
|
|
20489
|
+
var AttachmentFields = {
|
|
20484
20490
|
addonId: string(),
|
|
20485
|
-
stableId: string()
|
|
20491
|
+
stableId: string(),
|
|
20492
|
+
mode: CameraSensorModeSchema.default(DEFAULT_CAMERA_SENSOR_MODE)
|
|
20486
20493
|
};
|
|
20487
20494
|
var CameraSensorAttachmentSchema = discriminatedUnion("state", [
|
|
20488
20495
|
object({
|
|
20489
|
-
...
|
|
20496
|
+
...AttachmentFields,
|
|
20490
20497
|
state: literal("ready"),
|
|
20491
20498
|
deviceId: number(),
|
|
20492
20499
|
name: string(),
|
|
20493
20500
|
caps: array(string()).readonly()
|
|
20494
20501
|
}),
|
|
20495
20502
|
object({
|
|
20496
|
-
...
|
|
20503
|
+
...AttachmentFields,
|
|
20497
20504
|
state: literal("offline"),
|
|
20498
20505
|
deviceId: number(),
|
|
20499
20506
|
name: string(),
|
|
20500
20507
|
reason: _enum(["offline", "disabled"])
|
|
20501
20508
|
}),
|
|
20502
20509
|
object({
|
|
20503
|
-
...
|
|
20510
|
+
...AttachmentFields,
|
|
20504
20511
|
state: literal("missing"),
|
|
20505
20512
|
reason: string()
|
|
20506
20513
|
}),
|
|
20507
20514
|
object({
|
|
20508
|
-
...
|
|
20515
|
+
...AttachmentFields,
|
|
20509
20516
|
state: literal("unsupported"),
|
|
20510
20517
|
deviceId: number(),
|
|
20511
20518
|
name: string(),
|
|
20512
20519
|
reason: string()
|
|
20513
20520
|
}),
|
|
20514
20521
|
object({
|
|
20515
|
-
...
|
|
20522
|
+
...AttachmentFields,
|
|
20516
20523
|
state: literal("unreadable"),
|
|
20517
20524
|
reason: string()
|
|
20518
20525
|
})
|
|
@@ -20525,17 +20532,49 @@ var CameraSensorAttachmentSchema = discriminatedUnion("state", [
|
|
|
20525
20532
|
* say.
|
|
20526
20533
|
*/
|
|
20527
20534
|
var CameraSensorsNotForwardedSchema = _enum(["onboard-not-listed", "no-active-detection"]);
|
|
20535
|
+
/** Whether the camera's OWN motion counts on its own (D673 C2), from its READY sensors (C3). */
|
|
20536
|
+
var CameraOwnMotionSchema = _enum([
|
|
20537
|
+
"always",
|
|
20538
|
+
"when-confirmed",
|
|
20539
|
+
"never"
|
|
20540
|
+
]);
|
|
20541
|
+
/** Confirm / Replace cannot suppress this camera's motion: its provider still emits it directly (D673 C13). */
|
|
20542
|
+
var CameraSensorsNotEnforcedSchema = _enum(["provider-not-split"]);
|
|
20543
|
+
/**
|
|
20544
|
+
* The camera's OWN onboard motion (D696): the raw input the bridge combines,
|
|
20545
|
+
* never the effective value. The camera's `motion` slice is the effective one,
|
|
20546
|
+
* so a view of the camera's own row reads this.
|
|
20547
|
+
* - `atMs`: when the bridge received the camera's last own edge.
|
|
20548
|
+
* - `detected`: evaluated WHEN THE STATUS IS ASKED — the last edge said `true`
|
|
20549
|
+
* AND it is younger than the window the bridge counts the camera's own motion
|
|
20550
|
+
* for (`motionCooldownMs`, floored at two sustain ticks). A camera that never
|
|
20551
|
+
* sends a clear (heartbeats only) therefore reads `false` once no push came
|
|
20552
|
+
* within the window; a status read is a snapshot, so a live view re-asks.
|
|
20553
|
+
* Absent = this orchestrator has not received the camera's own motion since it
|
|
20554
|
+
* started (unknown, never "quiet"), or an orchestrator older than D696.
|
|
20555
|
+
*/
|
|
20556
|
+
var CameraRawLevelSchema = object({
|
|
20557
|
+
detected: boolean(),
|
|
20558
|
+
atMs: number()
|
|
20559
|
+
});
|
|
20528
20560
|
var CameraSensorsStatusSchema = discriminatedUnion("state", [
|
|
20529
|
-
object({
|
|
20561
|
+
object({
|
|
20562
|
+
state: literal("not-configured"),
|
|
20563
|
+
cameraLevel: CameraRawLevelSchema.optional()
|
|
20564
|
+
}),
|
|
20530
20565
|
object({
|
|
20531
20566
|
state: literal("unreadable"),
|
|
20532
|
-
reason: string()
|
|
20567
|
+
reason: string(),
|
|
20568
|
+
cameraLevel: CameraRawLevelSchema.optional()
|
|
20533
20569
|
}),
|
|
20534
20570
|
object({
|
|
20535
20571
|
state: literal("configured"),
|
|
20536
|
-
|
|
20572
|
+
cameraLevel: CameraRawLevelSchema.optional(),
|
|
20537
20573
|
sensors: array(CameraSensorAttachmentSchema).readonly(),
|
|
20538
|
-
|
|
20574
|
+
/** Absent = an orchestrator older than CS-2: it does not say (D315). */
|
|
20575
|
+
cameraMotion: CameraOwnMotionSchema.optional(),
|
|
20576
|
+
notForwarded: CameraSensorsNotForwardedSchema.optional(),
|
|
20577
|
+
notEnforced: CameraSensorsNotEnforcedSchema.optional()
|
|
20539
20578
|
})
|
|
20540
20579
|
]);
|
|
20541
20580
|
Object.freeze({
|
|
@@ -23726,8 +23765,10 @@ var RunnerCameraConfigSchema = object({
|
|
|
23726
23765
|
* - `analyzer`: ML/frame-diff motion detection (motion-wasm or other
|
|
23727
23766
|
* analyzer providers) running on decoded frames in this runner.
|
|
23728
23767
|
* - `onboard`: camera-native motion pushes (Reolink Baichuan, ONVIF
|
|
23729
|
-
* analytics). The provider emits ProviderMotion
|
|
23730
|
-
*
|
|
23768
|
+
* analytics). The provider emits its raw push as `ProviderMotion`
|
|
23769
|
+
* (D673); the orchestrator's camera-sensors bridge re-emits the camera's
|
|
23770
|
+
* effective motion as `MotionOnMotionChanged`, which is what reaches
|
|
23771
|
+
* `reportMotion`.
|
|
23731
23772
|
*/
|
|
23732
23773
|
motionSources: MotionSourcesSchema.default(["analyzer"]),
|
|
23733
23774
|
/**
|
|
@@ -23904,7 +23945,15 @@ var RunnerLocalLoadSchema = object({
|
|
|
23904
23945
|
hasGpu: boolean(),
|
|
23905
23946
|
inferenceBackend: string().optional(),
|
|
23906
23947
|
cpuCores: number().optional()
|
|
23907
|
-
})
|
|
23948
|
+
}),
|
|
23949
|
+
/**
|
|
23950
|
+
* Who writes a camera's `motion` runtime slice (D696). `'orchestrator'`: this
|
|
23951
|
+
* runner never writes it. ABSENT = a runner older than D696, which still
|
|
23952
|
+
* writes the slice from its phase machine; the orchestrator does not write
|
|
23953
|
+
* while any runner node is absent-or-unanswered, so one slice never has two
|
|
23954
|
+
* writers.
|
|
23955
|
+
*/
|
|
23956
|
+
motionSliceWriter: literal("orchestrator").optional()
|
|
23908
23957
|
});
|
|
23909
23958
|
/**
|
|
23910
23959
|
* Aggregate runtime metrics for the runner's whole local pool. Mirrors the
|
|
@@ -28745,6 +28794,17 @@ object({
|
|
|
28745
28794
|
deviceId: number(),
|
|
28746
28795
|
status: DeviceStatusSchema
|
|
28747
28796
|
});
|
|
28797
|
+
object({
|
|
28798
|
+
/** Ms epoch of the last press. null = never observed since this provider started. */
|
|
28799
|
+
lastPressedAt: number().nullable(),
|
|
28800
|
+
/** Counter since provider start. Resets on reboot. Useful for metrics/debug. */
|
|
28801
|
+
pressCountSinceStart: number()
|
|
28802
|
+
});
|
|
28803
|
+
object({
|
|
28804
|
+
deviceId: number(),
|
|
28805
|
+
timestamp: number()
|
|
28806
|
+
});
|
|
28807
|
+
DeviceType.Button, DeviceType.Camera;
|
|
28748
28808
|
/**
|
|
28749
28809
|
* Enum-state sensor — a string value picked from a finite option set.
|
|
28750
28810
|
* Drives HA `sensor` entries with `state_class: enum` (HVAC action
|
|
@@ -30389,9 +30449,9 @@ object({
|
|
|
30389
30449
|
/** Ms epoch of the last detected-true observation. Null if never detected. */
|
|
30390
30450
|
lastDetectedAt: number().nullable(),
|
|
30391
30451
|
/**
|
|
30392
|
-
* `MOTION_CLOSE_AFTER_MS` while `detected: true` on a `Camera` device
|
|
30393
|
-
* `null` while false and on every `Sensor`
|
|
30394
|
-
* constant's doc for the one-authority rule.
|
|
30452
|
+
* `MOTION_CLOSE_AFTER_MS` while `detected: true` on a `Camera` device (the
|
|
30453
|
+
* orchestrator writes it, D696), `null` while false and on every `Sensor`
|
|
30454
|
+
* device (D475) — see that constant's doc for the one-authority rule.
|
|
30395
30455
|
*
|
|
30396
30456
|
* ## Reading this field still arms nothing
|
|
30397
30457
|
*
|
|
@@ -30409,38 +30469,41 @@ object({
|
|
|
30409
30469
|
* `addon-export-alexa/src/motion-clear-hold.ts` and
|
|
30410
30470
|
* `addon-export-hap`'s `RESET_DEBOUNCE_MS` both do.
|
|
30411
30471
|
*
|
|
30412
|
-
* ## Who writes it
|
|
30413
|
-
*
|
|
30414
|
-
* - **Cameras** — the
|
|
30415
|
-
*
|
|
30416
|
-
* `
|
|
30417
|
-
* `
|
|
30418
|
-
*
|
|
30419
|
-
*
|
|
30420
|
-
* a
|
|
30421
|
-
*
|
|
30422
|
-
*
|
|
30423
|
-
*
|
|
30424
|
-
*
|
|
30425
|
-
*
|
|
30426
|
-
*
|
|
30427
|
-
*
|
|
30428
|
-
*
|
|
30429
|
-
*
|
|
30430
|
-
* `
|
|
30431
|
-
*
|
|
30432
|
-
*
|
|
30433
|
-
*
|
|
30434
|
-
*
|
|
30435
|
-
*
|
|
30436
|
-
*
|
|
30437
|
-
* This predates D475 and is not fixed there: the fix touches every
|
|
30438
|
-
* camera provider. Recorded in D475's Consequences. Do not restore the
|
|
30439
|
-
* "sole writer" wording without also removing the other writers.
|
|
30472
|
+
* ## Who writes it (D696)
|
|
30473
|
+
*
|
|
30474
|
+
* - **Cameras** — the orchestrator, and nothing else. It writes the camera's
|
|
30475
|
+
* EFFECTIVE motion (`addon-pipeline-orchestrator`
|
|
30476
|
+
* `camera-sensors/motion-slice.ts`), alongside the effective
|
|
30477
|
+
* `MotionOnMotionChanged` it emits or receives: the camera-sensors bridge
|
|
30478
|
+
* for a split camera, an unsplit emitter's direct event, the analyzer and
|
|
30479
|
+
* device activity, as the camera's `motionSources` counts them. A source
|
|
30480
|
+
* that never sends a clear falls one window after its last `true`.
|
|
30481
|
+
* `lastDetectedAt` moves only on an effective rise. No camera provider
|
|
30482
|
+
* writes this slice (not even a boot seed), and neither does the runner's
|
|
30483
|
+
* phase machine: its phase is "a session is attached" for every on-motion
|
|
30484
|
+
* session, not motion, and it now has its own `DetectionPhaseTransition`.
|
|
30485
|
+
* A provider's `isDetected` answers from the hub's slice.
|
|
30486
|
+
* - **Sensors** (Home Assistant binary sensors, Homematic, Matter, Alexa
|
|
30487
|
+
* imports) — the provider pushes both edges itself, from the upstream
|
|
30488
|
+
* system's own state change. That is the sensor's own fact.
|
|
30489
|
+
*
|
|
30490
|
+
* `scripts/check-onboard-motion-emitters.ts` refuses any other writer of a
|
|
30491
|
+
* `motion` slice; each sensor writer is a named exemption.
|
|
30492
|
+
*
|
|
30493
|
+
* This replaces the D475 §4 rule ("the phase machine is the sole writer").
|
|
30494
|
+
* That rule was never true: Hikvision and Amcrest wrote the slice raw beside
|
|
30495
|
+
* it, every provider seeded it at boot, and every session left it
|
|
30496
|
+
* `detected: true` after its detach.
|
|
30440
30497
|
*/
|
|
30441
30498
|
autoClearAfterMs: number().nullable()
|
|
30442
30499
|
});
|
|
30443
|
-
|
|
30500
|
+
/**
|
|
30501
|
+
* Payload of `motion.onMotionChanged` event + the corresponding bus
|
|
30502
|
+
* event `EventCategory.MotionOnMotionChanged`. Single source of truth
|
|
30503
|
+
* — both the cap event surface and the bus payload type alias to this
|
|
30504
|
+
* schema.
|
|
30505
|
+
*/
|
|
30506
|
+
var MotionOnMotionChangedDataSchema = object({
|
|
30444
30507
|
deviceId: number(),
|
|
30445
30508
|
detected: boolean(),
|
|
30446
30509
|
timestamp: number(),
|
|
@@ -46917,6 +46980,7 @@ TimelapseRuleInputSchema.extend({
|
|
|
46917
46980
|
createdAt: number(),
|
|
46918
46981
|
updatedAt: number()
|
|
46919
46982
|
});
|
|
46983
|
+
MotionOnMotionChangedDataSchema.omit({ triggeredBy: true });
|
|
46920
46984
|
object({
|
|
46921
46985
|
/**
|
|
46922
46986
|
* Fraction of the box's own size added on EACH side before cutting.
|
|
@@ -47118,7 +47182,7 @@ var AdminUIAddon = class extends BaseAddon {
|
|
|
47118
47182
|
capability: adminUiCapability,
|
|
47119
47183
|
provider: {
|
|
47120
47184
|
getStaticDir: async () => ({ staticDir: resolveAdminUiDistDir() }),
|
|
47121
|
-
getVersion: async () => ({ version: "1.2.
|
|
47185
|
+
getVersion: async () => ({ version: "1.2.299" })
|
|
47122
47186
|
}
|
|
47123
47187
|
}];
|
|
47124
47188
|
}
|
package/package.json
CHANGED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,M as n,Q as r,S as i,T as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as p,at as m,gt as h,st as g,yt as _}from"./player-overlays-o54P23P2.js";import{Al as v,At as y,Bt as b,Fl as x,Hl as S,Iu as C,J as w,Ot as T,St as E,Ul as D,Wl as O,_ as k,an as A,bt as j,cn as M,dt as N,fu as ee,id as P,kt as te,nn as F,nu as ne,ol as re,pt as I,rt as ie,sn as L,td as ae,tn as R,tt as oe,ut as se,vi as ce,xt as le,yn as ue,yt as de,zr as fe,zt as pe}from"./src-f3OJiuN1.js";import{An as me,Dn as he,En as ge,On as _e,ar as ve,bn as z,dt as ye,hn as be,kn as xe,sn as B,xn as Se}from"./src-C36-vO5A.js";import{a as Ce,d as we,i as Te,m as Ee,s as De,y as Oe}from"./index-CgXPc-AV.js";import{t as ke}from"./AdminPage-CiKtOLQm.js";import{r as Ae}from"./useDevice-BU0imY9B.js";var je=_(`braces`,[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]]),Me=_(`ungroup`,[[`rect`,{width:`8`,height:`6`,x:`5`,y:`4`,rx:`1`,key:`nzclkv`}],[`rect`,{width:`8`,height:`6`,x:`11`,y:`14`,rx:`1`,key:`4tytwb`}]]);r();var Ne=6e4;function Pe(){let e=ce({projection:`slim`});return o(()=>(e.data??[]).map(e=>({id:e.id,name:e.name,stableId:e.stableId})).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data])}function Fe(e){let t=m();return s({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:Ne,queryFn:async()=>{let n=await t.trpcClient.deviceManager.getBindings.query({deviceId:e});return[...new Set(n.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}})}function Ie(e){let t=m();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:Ne,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Le(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Re(){let e=new Set;for(let t of Object.values(ye))t.capScope===`device`&&e.add(t.capName);return[...e].sort((e,t)=>e.localeCompare(t))}function ze(e){if(e===``)return[];let t=new Set;for(let[n,r]of Object.entries(ye)){if(r.capName!==e||r.capScope!==`device`||r.access===`view`)continue;let i=n.slice(n.indexOf(`.`)+1);i!==``&&t.add(i)}return[...t].sort((e,t)=>e.localeCompare(t))}function V({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Be(e){let t=Ie(e.deviceId);if(t.data!==void 0)return Le(t.data,e.cap).find(t=>t.path===e.fieldPath)}function Ve({value:e,devices:t,onChange:n}){let r=Ie(e.deviceId),a=r.data??[],o=Le(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(V,{children:`Device`}),d(L,{value:String(e.deviceId),onChange:e=>n({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:`Select a device…`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(V,{children:`Capability`}),d(L,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:He(e.deviceId,a.length,r.isLoading)},...a.map(e=>({value:e.cap,label:e.cap}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(V,{children:`Field`}),d(L,{value:e.fieldPath,disabled:e.cap===``,onChange:t=>n({...e,fieldPath:t.target.value}),options:[{value:``,label:o.length===0?`No readable fields`:`Select a field…`},...o.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function He(e,t,n){return e===0?`Pick a device first`:n?`Reading this device…`:t===0?`This device reports no readable capabilities`:`Select a capability…`}var Ue=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function We(e){switch(e){case`boolean`:return[`eq`,`ne`];case`number`:return[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`];case`string`:case`enum`:return[`eq`,`ne`,`contains`,`in`];default:return Ue}}function Ge(e){switch(e){case`eq`:return`is`;case`ne`:return`is not`;case`gt`:return`is above`;case`gte`:return`is at least`;case`lt`:return`is below`;case`lte`:return`is at most`;case`contains`:return`contains`;default:return`is one of`}}function Ke(e){return We(e).map(e=>({value:e,label:Ge(e)}))}function qe(e){switch(e){case`device-state`:return`A device field changes`;case`device-event`:return`An event happens`;case`schedule`:return`On a schedule`;default:return`Only when run by hand`}}var Je={triggers:[],actions:[]};function Ye(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};default:return{kind:`manual`}}}function Xe(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
|
|
2
|
-
`};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function Ze(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Qe(){return{kind:`expression`,expr:``,bindings:{}}}function $e(e,t,n){return e.map((e,r)=>r===t?n:e)}function et(e,t){return e.filter((e,n)=>n!==t)}function tt(e,t,n){let r=e[t];if(r===void 0)return e;let i=Math.min(Math.max(n,0),e.length-1);if(i===t)return e;let a=et(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function nt(e,t){return{...e,triggers:[...t]}}function rt(e,t){return{...e,actions:[...t]}}var it=`deviceId`,at=`$trigger`,ot=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function st({actions:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((r,a)=>i(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(R,{variant:`default`,children:a+1}),i(`label`,{className:`w-40`,children:[d(V,{children:`Step`}),d(L,{value:r.kind,onChange:t=>n($e(e,a,Xe(ct(t.target.value)))),options:ot.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(M,{variant:`ghost`,disabled:a===0,onClick:()=>n(tt(e,a,a-1)),title:`Run this step earlier`,children:d(ae,{className:`h-3.5 w-3.5`})}),d(M,{variant:`ghost`,disabled:a===e.length-1,onClick:()=>n(tt(e,a,a+1)),title:`Run this step later`,children:d(P,{className:`h-3.5 w-3.5`})}),d(M,{variant:`ghost`,onClick:()=>n(et(e,a)),title:`Remove this step`,children:d(g,{className:`h-3.5 w-3.5`})})]})]}),r.kind===`wait`&&i(`label`,{className:`block w-32`,children:[d(V,{children:`Seconds`}),d(b,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n($e(e,a,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&i(`label`,{className:`block`,children:[d(V,{children:`Code`}),d(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:r.code,spellCheck:!1,onChange:t=>n($e(e,a,{kind:`code`,code:t.target.value}))}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Compiled into this automation's own block by the same compiler as a script — not evaluated at run time. `,d(`code`,{children:`ctx`}),` and `,d(`code`,{children:`vars`}),` are in scope.`]})]}),r.kind===`cap`&&d(lt,{action:r,devices:t,onChange:t=>n($e(e,a,t))})]},`${r.kind}-${String(a)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(M,{variant:`outline`,onClick:()=>n([...e,Xe(`cap`)]),children:[d(S,{className:`h-4 w-4`}),` Step`]}),e.length>1&&d(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function ct(e){return ot.find(t=>t.value===e)?.value??`cap`}function lt({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,a=typeof e.deviceId==`number`?e.deviceId:0,o=Fe(a),s=r?Re():o.data??[],c=ze(e.cap);return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(V,{children:`Device`}),d(L,{value:r?at:String(a),onChange:t=>n({...e,deviceId:t.target.value===at?{$var:it}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:at,label:`The device that triggered this run`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(V,{children:`Capability`}),d(L,{value:e.cap,disabled:s.length===0,onChange:t=>n({...e,cap:t.target.value,method:``}),options:[{value:``,label:s.length===0?`Pick a device first`:`Select a capability…`},...s.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(V,{children:`Method`}),d(L,{value:e.method,disabled:c.length===0,onChange:t=>n({...e,method:t.target.value}),options:[{value:``,label:c.length===0?`Pick a capability first`:`Select a method…`},...c.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(V,{children:`Arguments (JSON)`}),d(b,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(ut(e,t.target.value))})]})]})}function ut(e,t){if(t.trim()===``)return{kind:`cap`,deviceId:e.deviceId,cap:e.cap,method:e.method};try{let n=JSON.parse(t);if(typeof n!=`object`||!n||Array.isArray(n))return e;let r={};for(let[e,t]of Object.entries(n))r[e]=t;return{...e,args:r}}catch{return e}}function dt({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(L,{value:e===!0?`true`:`false`,onChange:e=>n(e.target.value===`true`),options:[{value:`true`,label:`true`},{value:`false`,label:`false`}]}):t?.kind===`enum`&&t.enumValues!==void 0&&t.enumValues.length>0?d(L,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(b,{type:`number`,value:typeof e==`number`?String(e):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&n(t)}}):d(b,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function ft({value:e,field:t,onChange:n}){return d(b,{value:e.join(`, `),placeholder:`one, two, three`,onChange:e=>{let r=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);n(t?.kind===`number`?r.map(e=>Number(e)).filter(e=>!Number.isNaN(e)):r)}})}function pt(e){return typeof e==`object`}function mt(e){return pt(e)?e[0]??``:e}function ht(e){return pt(e)?e:typeof e==`boolean`?[]:[e]}function gt({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Be(r),o=Ke(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=_t(t,o);n({...e,operator:r,value:r===`in`?ht(e.value):mt(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(Ve,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(V,{children:`Comparison`}),d(L,{value:e.operator,onChange:e=>l(e.target.value),options:o.map(e=>({value:e.value,label:e.label}))})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(V,{children:`Value`}),s?d(ft,{value:ht(e.value),field:a,onChange:t=>n({...e,value:t})}):d(dt,{value:mt(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function _t(e,t){return t.find(t=>t.value===e)?.value??`eq`}var vt={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function yt({leaf:e,devices:t,onChange:n}){let r=Object.entries(e.bindings),a=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return i(`div`,{className:`space-y-2`,children:[i(`label`,{className:`block`,children:[d(V,{children:`Expression`}),d(b,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),d(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`})]}),i(`div`,{className:`space-y-1.5`,children:[r.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>d(bt,{alias:n,source:r,devices:t,onRename:t=>a(Et(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(Dt(e.bindings,n))},n)),i(M,{variant:`ghost`,onClick:()=>a({...e.bindings,[Tt(e.bindings)]:vt}),children:[d(S,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function bt({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:Ct(n,St(t)),cap:t.cap,fieldPath:t.fieldPath};return i(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[i(`label`,{className:`w-32`,children:[d(V,{children:`Name`}),d(b,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(V,{children:`Reads`}),d(L,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:vt),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(V,{children:`Constant`}),d(b,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:xt(e.target.value)})})]}):d(Ve,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:wt(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(M,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(g,{className:`h-3.5 w-3.5`})})]})}function xt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function St(e){return e.kind===`global`?e.sourceStableId:``}function Ct(e,t){return e.find(e=>e.stableId===t)?.id??0}function wt(e,t){return e.find(e=>e.id===t)?.stableId??``}function Tt(e){for(let t=0;t<26;t+=1){let n=String.fromCharCode(97+t);if(!(n in e))return n}return`n${String(Object.keys(e).length)}`}function Et(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Dt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function H(e){return e.kind===`all`||e.kind===`any`}function U(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:H(t)?t:{kind:`all`,children:[t]}}function Ot(e,t){return t===null||H(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function kt(e){return Ot(e,U(e))}function W(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?W(e.child,r):null;if(!H(e))return null;let i=e.children[n];return i===void 0?null:W(i,r)}function G(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=G(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!H(e))return e;let a=e.children[r];if(a===void 0)return e;let o=G(a,i,n),s=o===null?[...e.children.slice(0,r),...e.children.slice(r+1)]:[...e.children.slice(0,r),o,...e.children.slice(r+1)];return s.length===0?null:{kind:e.kind,children:s}}function At(e){return e===null?null:me({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function jt(e){let t=U(e);return{depth:t.children.length===0?0:_e(t),leaves:t.children.length===0?0:xe(t),depthLimit:3,leafLimit:32}}function Mt(e,t){let n=At(t);return n===null?{ok:!0,recipe:Ot(e,t)}:{ok:!1,reason:n}}function Nt(e,t){let n=U(e);return Mt(e,{kind:n.kind,children:[...n.children,t]})}function Pt(e,t,n){return Ot(e,G(U(e),t,()=>n))}function Ft(e,t){return Ot(e,G(U(e),t,()=>null))}function It(e,t,n){return Ot(e,G(U(e),t,e=>H(e)?{kind:n,children:e.children}:e))}function Lt(e,t){return W(U(e),t)===null?{ok:!1,reason:`that row is no longer there`}:Mt(e,G(U(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Rt(e){if(e.length===0)return null;let t=e[e.length-1];return t===void 0?null:{path:e.slice(0,-1),index:t}}function zt(e,t,n){if(t.length<2)return{ok:!1,reason:`select at least two rows — a group of one is just the row`};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:`those rows are in different groups — a group can only be made from rows side by side`};let r=Rt(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=U(e),a=W(i,r.path);if(a===null||!H(a))return{ok:!1,reason:`those rows are inside a NOT — remove it before grouping them`};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:`one of the selected rows is no longer there`};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return Mt(e,G(i,r.path,()=>d))}function Bt(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=U(e),r=W(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return Mt(e,G(n,t,()=>r.child));if(!H(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Rt(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=W(n,i.path);if(a===null||!H(a))return{ok:!1,reason:`a group inside a NOT cannot be dissolved in place`};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return Mt(e,G(n,i.path,()=>o))}r();var Vt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function Ht(e){return e.join(`/`)}function Ut(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Wt({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=U(e),f=jt(e),p=o(()=>r.map(Ut),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=zt(e,p,`all`),g=zt(e,p,`any`),_=p.length===1?Lt(e,p[0]??[]):{ok:!1,reason:`select exactly one row to negate`},v={devices:t,selected:new Set(r),onToggleSelect:e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(Pt(e,t,r)),onRemove:t=>{a([]),n(Ft(e,t))},onSetKind:(t,r)=>n(It(e,t,r)),onUngroup:t=>m(Bt(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(R,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(L,{value:u.kind,onChange:t=>n(It(e,[],Gt(t.target.value))),options:Vt})}),i(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,f.depth,`/`,f.depthLimit,` · `,f.leaves,`/`,f.leafLimit,` conditions`]})]}),u.children.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):d(Kt,{container:u,path:[],handlers:v}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(M,{variant:`outline`,onClick:()=>m(Nt(e,Ze())),title:`Compare one device field to a value`,children:[d(S,{className:`h-4 w-4`}),` Condition`]}),i(M,{variant:`outline`,onClick:()=>m(Nt(e,Qe())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(je,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(M,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(M,{variant:`ghost`,disabled:!g.ok,onClick:()=>m(g),title:g.ok?`Any one of the selected rows is enough`:g.reason,children:`Group as ANY`}),d(M,{variant:`ghost`,disabled:!_.ok,onClick:()=>m(_),title:_.ok?`Invert the selected row`:_.reason,children:`NOT`}),r.length>0&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[r.length,` selected`]})]}),s!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:s})]})}function Gt(e){return e===`any`?`any`:`all`}function Kt({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(qt,{node:e,path:[...t,r],handlers:n},Ht([...t,r])))})}function qt({node:e,path:t,handlers:n}){let r=Ht(t),a=d(pe,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return H(e)?i(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(`div`,{className:`w-32`,children:d(L,{value:e.kind,onChange:e=>n.onSetKind(t,Gt(e.target.value)),options:Vt})}),i(M,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(Me,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(M,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:d(g,{className:`h-3.5 w-3.5`})})]}),d(`div`,{className:`pl-4`,children:d(Kt,{container:e,path:t,handlers:n})})]}):e.kind===`not`?i(`div`,{className:`rounded border border-border p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(R,{variant:`warning`,children:`NOT`}),i(M,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(Me,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(qt,{node:e.child,path:[...t,0],handlers:n})})]}):i(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[d(`div`,{className:`pt-6`,children:a}),d(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?d(gt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(yt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(M,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(g,{className:`h-3.5 w-3.5`})})]})}r();function Jt({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=ue(),u=async()=>{await c({title:`Eject to code — this cannot be undone`,message:`The recipe is removed from the block and it becomes an ordinary script. The visual editor will no longer open it, and there is no way back to it except authoring a new automation from scratch. The code itself is kept exactly as it is now.`,confirmLabel:`Eject to code`,cancelLabel:`Keep it visual`,variant:`warning`})&&a()};return i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[i(M,{variant:`ghost`,onClick:()=>s(!o),children:[d(o?p:h,{className:`h-4 w-4`}),`Generated code`]}),d(`span`,{className:`text-xs text-foreground-subtle`,children:`Derived from the recipe above — regenerated on every save, never edited here.`}),i(M,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||r,onClick:()=>void u(),title:n?`Take permanent ownership of this code as a script`:`Save the automation first — there is no stored block to eject yet`,children:[d(Oe,{className:`h-4 w-4`}),` Eject to code`]})]}),o&&d(`div`,{className:`border-t border-border p-3`,children:e===null?d(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):d(I,{maxHeight:420,children:e})})]})}var Yt=[`device-state`,`device-event`,`schedule`,`manual`],Xt=Object.values(ve).sort((e,t)=>e.localeCompare(t));function Zt({triggers:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`}),e.map((r,i)=>d(Qt,{trigger:r,devices:t,position:i,onChange:t=>n($e(e,i,t)),onRemove:()=>n(et(e,i))},`${r.kind}-${String(i)}`)),i(M,{variant:`outline`,onClick:()=>n([...e,Ye(`device-state`)]),title:`Add another way this automation can start`,children:[d(S,{className:`h-4 w-4`}),` Trigger`]})]})}function Qt({trigger:e,devices:t,position:n,onChange:r,onRemove:a}){return i(`div`,{className:`rounded border border-border p-3`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(R,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(V,{children:`Trigger`}),d(L,{value:e.kind,onChange:e=>r(Ye($t(e.target.value))),options:Yt.map(e=>({value:e,label:qe(e)}))})]}),d(M,{variant:`ghost`,onClick:a,title:`Remove this trigger`,children:d(g,{className:`h-4 w-4`})})]}),i(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&d(en,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(nn,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(V,{children:`Cron expression`}),d(b,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,d(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,d(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function $t(e){return Yt.find(t=>t===e)??`manual`}function K(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function en({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Be(r),o={...e.becomes===void 0?{}:{becomes:e.becomes},...e.edge===void 0?{}:{edge:e.edge},...e.forMs===void 0?{}:{forMs:e.forMs},...e.debounceMs===void 0?{}:{debounceMs:e.debounceMs}};return i(c,{children:[d(Ve,{value:r,devices:t,onChange:e=>n(K(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(V,{children:`Becomes`}),i(`div`,{className:`flex items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(pe,{checked:e.becomes===void 0,onChange:e=>n(K(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d(dt,{value:e.becomes,field:a,onChange:e=>n(K(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(pe,{checked:e.edge===!0,onChange:e=>n(K(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(V,{children:`Held for (s)`}),d(b,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(K(r,{...o,forMs:tn(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(V,{children:`Debounce (s)`}),d(b,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(K(r,{...o,debounceMs:tn(e.target.value)}))})]})]})}function tn(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function nn({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(V,{children:`Event category`}),d(L,{value:e.category,onChange:t=>n({kind:`device-event`,category:t.target.value,...e.deviceId===void 0?{}:{deviceId:e.deviceId}}),options:[{value:``,label:`Select an event…`},...Xt.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(V,{children:`From device`}),d(L,{value:e.deviceId===void 0?``:String(e.deviceId),onChange:t=>n({kind:`device-event`,category:e.category,...t.target.value===``?{}:{deviceId:Number(t.target.value)}}),options:[{value:``,label:`Any device`},...t.map(e=>({value:String(e.id),label:e.name}))]})]})]})}r();var rn=`hub`;function an({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:a,onSave:s,onEject:c,onCancel:u}){let[f,p]=l(e?.name??``),[m,h]=l(()=>kt(t)),[g,_]=l(!1),y=Pe(),x=me(m),S=o(()=>sn(m),[m]),C=o(()=>cn(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),w=f.trim()===``,T=w||x!==null||S!==null||C.code===null;return d(F,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New automation`:`Edit ${e.name}`}),d(R,{variant:`info`,children:`runs on the hub`})]}),i(`label`,{className:`block max-w-md text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(b,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(on,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(Zt,{triggers:m.triggers,devices:y,onChange:e=>h(nt(m,e))})}),d(on,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Wt,{recipe:m,devices:y,onChange:h})}),d(on,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(st,{actions:m.actions,devices:y,onChange:e=>h(rt(m,e))})}),d(Jt,{code:C.code,error:C.error,canEject:e!==null,ejecting:a,onEject:c}),g&&e!==null&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:B(e.id)})]}),d(oe,{addonId:B(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),x!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),x===null&&S!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:S}),r!==null&&d(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(M,{onClick:()=>{C.code!==null&&s({name:f.trim(),code:C.code,enabled:e?.enabled??!0,placement:rn})},disabled:n||T,children:[n&&d(ne,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(M,{variant:`ghost`,onClick:()=>_(!g),disabled:e===null,title:e===null?`Logs appear once the automation has been saved and started`:`Show this automation's process logs`,children:[d(v,{className:`h-4 w-4`}),` Logs`]}),d(M,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),w&&d(R,{variant:`warning`,children:`Name required`})]})]})})}function on({step:e,title:t,subtitle:n,children:r}){return i(`section`,{className:`border-l-2 border-border pl-4`,children:[i(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[d(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),d(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),d(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function sn(e){let t=he.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?`this automation is not complete yet`:`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function cn(e,t){try{return{code:ge({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function q(e){if(!e.enabled)return{tone:`idle`,label:`Disabled`,detail:`Not started — the block is turned off.`};switch(e.status){case`running`:return{tone:`ok`,label:`Running`,detail:`One process, supervised.`};case`starting`:return{tone:`pending`,label:`Starting`,detail:e.lastError??`Waiting for the process to report ready.`};case`failed`:return{tone:`error`,label:`Failed`,detail:e.lastError??`Failed with no reason recorded — check the node logs.`};default:return{tone:`error`,label:`Not running`,detail:e.lastError??`Enabled but no process is running. The supervisor reconciles every 15s; if this persists, the node may not be running a block supervisor.`}}}function ln(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function un(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function dn(e){let t=e=>{let t=q(e).tone;return t===`error`?0:t===`pending`?1:t===`ok`?2:3};return[...e].sort((e,n)=>t(e)-t(n)||e.name.localeCompare(n.name))}function fn(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>q(e).tone===`error`).length,n=e.filter(e=>q(e).tone===`ok`).length,r=[`${String(e.length)} block${e.length===1?``:`s`}`];return n>0&&r.push(`${String(n)} running`),t>0&&r.push(`${String(t)} NOT running`),r.join(` · `)}function pn({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=q(e),m=w(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(R,{variant:ln(p.tone),children:p.label}),m!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,m]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:p.detail}),a!==null&&i(`p`,{className:`mt-0.5 text-xs text-warning`,children:[`Its recipe cannot be read (`,a,`), so it cannot be opened visually. The code is intact and still running — edit it as a script.`]})]}),n?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),d(M,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(M,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(M,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(O,{className:`h-4 w-4`})}),i(T,{children:[d(y,{children:d(M,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(D,{className:`h-4 w-4`})})}),d(te,{children:`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`})]}),d(M,{variant:`ghost`,onClick:c,title:`Logs`,children:d(v,{className:`h-4 w-4`})}),d(M,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(M,{variant:`ghost`,onClick:l,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),r&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:B(e.id)})]}),d(oe,{addonId:B(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function mn({onCreate:e}){return d(F,{children:i(`div`,{className:`space-y-2 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),d(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`}),d(M,{onClick:e,children:`New automation`})]})})}var hn=`const AUTOMATION_RECIPE =`,gn=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
3
|
-
// The recipe that produced it was removed with it, on purpose: while it was
|
|
4
|
-
// here the editor could re-open this block and overwrite everything below.`;function _n(e){return e.includes(hn)}function vn(e){let t=e.indexOf(hn);if(t<0)return null;let n=e.indexOf(`{`,t+25);if(n<0)return null;let r=0,i=!1,a=!1;for(let o=n;o<e.length;o+=1){let s=e.charAt(o);if(i){a?a=!1:s===`\\`?a=!0:s===`"`&&(i=!1);continue}if(s===`"`){i=!0;continue}if(s===`{`)r+=1;else if(s===`}`&&(--r,r===0))return{declStart:t,literalEnd:o+1,json:e.slice(n,o+1)}}return null}function yn(e){let t=vn(e);if(t===null)return{ok:!1,reason:`this block carries no AUTOMATION_RECIPE literal`};let n;try{n=JSON.parse(t.json)}catch(e){return{ok:!1,reason:`the embedded recipe is not readable JSON: ${e instanceof Error?e.message:String(e)}`}}let r=he.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:`the embedded recipe does not match the recipe schema${e===void 0?``:` at ${e.path.join(`.`)}: ${e.message}`}`}}return{ok:!0,recipe:r.data}}function bn(e){let t=vn(e);if(t===null)return e;let n=e.slice(t.literalEnd),r=/^\s*as\s+const/.exec(n),i=t.literalEnd+(r===null?0:r[0].length);return`${e.slice(0,t.declStart)}${gn}${e.slice(i)}`}r();var xn=[`coreBlocks`,`list`],Sn=5e3;function J(e){return e instanceof Error?e.message:String(e)}function Cn({onOpenScripts:e}){let t=m(),[n,r]=l({mode:`closed`}),[a,o]=l(null),[c,f]=l(null),p=s({queryKey:xn,refetchInterval:Sn,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}),h=()=>{p.refetch()},g=u({mutationFn:e=>t.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{r({mode:`edit`,block:e.block}),h()}}),_=u({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{r({mode:`edit`,block:e.block}),h()}}),v=u({mutationFn:e=>t.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{o(null),h()}}),y=u({mutationFn:e=>t.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:h}),b=u({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:bn(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{r({mode:`closed`}),h(),e(t.block.id)}}),x=p.data,C=dn((x??[]).filter(e=>_n(e.code))),w=x!==void 0&&C.length===0,T=n.mode===`edit`&&n.block!==null?un(C,n.block):null,E=T===null?null:yn(T.code),D=g.error===null?_.error===null?b.error===null?null:J(b.error):J(_.error):J(g.error);return i(`div`,{className:`space-y-3`,children:[i(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:x===void 0?``:fn(C)}),i(M,{onClick:()=>r({mode:`edit`,block:null}),children:[d(S,{className:`h-4 w-4`}),` New automation`]})]}),p.error!=null&&d(A,{title:`Could not read the automations`,message:J(p.error),onRetry:h}),n.mode===`edit`&&d(an,{existing:T,initialRecipe:E!==null&&E.ok?E.recipe:Je,saving:g.isPending||_.isPending,saveError:D,ejecting:b.isPending,onSave:e=>{T===null?g.mutate(e):_.mutate({blockId:T.id,block:e})},onEject:()=>{T!==null&&b.mutate(T)},onCancel:()=>{g.reset(),_.reset(),b.reset(),r({mode:`closed`})}},T?.id??`new`),w&&d(mn,{onCreate:()=>r({mode:`edit`,block:null})}),C.length>0&&d(F,{children:d(`ul`,{className:`divide-y divide-border`,children:C.map(e=>{let t=yn(e.code);return d(pn,{block:e,busy:y.isPending||v.isPending,confirming:a===e.id,logsOpen:c===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>r({mode:`edit`,block:e}),onToggle:t=>y.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>f(c===e.id?null:e.id),onAskDelete:()=>o(e.id),onCancelDelete:()=>o(null),onConfirmDelete:()=>v.mutate(e.id)},e.id)})})}),v.error!=null&&d(A,{message:J(v.error)}),y.error!=null&&d(A,{message:J(y.error)})]})}function wn(e){return{state:`answered`,byRef:new Map(e.map(e=>[z(e),e]))}}function Tn(e,t){if(e.state!==`unanswered`)return e.byRef.get(z(t))??null}function En(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function Dn(e){return Se(e).map(e=>e.source)}function On(e){let t=e.block.source?.kind===`composition`?e.block.source.composition:null;if(t===null)return[];let n=[];for(let e of t.features){if(e.kind===`passthrough`){n.push(e.source);continue}for(let t of Object.values(e.fields))n.push(...Dn(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...Dn(e))}let r=new Set;return n.filter(e=>{let t=z(e);return r.has(t)?!1:(r.add(t),!0)})}function kn(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function An(e){let t=e.fields.filter(e=>e.state===`unavailable`),n=e.fields.filter(e=>e.state===`stale`);if(t.length===0&&n.length===0)return{tone:`ok`,label:`Running`,reason:null};let r=[...t.length>0?[`${kn(t.length,`field`)} unavailable`]:[],...n.length>0?[`${kn(n.length,`field`)} stale`]:[]].join(`, `),i=t[0]??n[0];return{tone:`pending`,label:`Running`,reason:`${r}${i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??`no reason recorded`}`}`}}function jn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return An(e);case`degraded`:return{tone:`pending`,label:`Degraded`,reason:n??`Running with a field handed back to the device; no reason recorded.`};case`starting`:return{tone:`pending`,label:`Starting`,reason:n};case`failed`:return{tone:`error`,label:`Failed`,reason:n??`Failed with no reason recorded — check the composer logs.`};default:return{tone:`error`,label:`Not running`,reason:n??`Enabled but the composer is not running it.`}}}function Mn(e){let{block:t,state:n}=e;return t.enabled?n.kind===`unreachable`?{tone:`pending`,label:`Unknown`,reason:`The composer could not be asked: ${n.error}`}:n.state===null?{tone:`pending`,label:`Not reported yet`,reason:`The composer holds no record of this block yet (stored status: ${t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`}).`}:jn(n.state,t.lastError):{tone:`idle`,label:`Off`,reason:null}}function Nn(e){return z(e)}function Pn(e,t){let n=Tn(t,e);return{key:z(e),label:n?n.name:Nn(e),presence:En(n),deviceId:n?n.id:null}}function Fn(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function In(e,t){let n=e.block.source?.kind===`composition`?e.block.source.composition:null;if(n===null)return null;let r=n.target,i=r.kind===`existing`?r.device:be(e.block.id),a=z(i),o=On(e).filter(e=>z(e)!==a).map(e=>Pn(e,t)),s=n.features.map(e=>e.enabled===!1?`${e.cap} (off)`:e.cap),c=Tn(t,i),l=Fn(e),u=Mn(e);if(r.kind===`new`)return{blockId:e.block.id,kind:`composed`,name:e.block.name,namePresence:`present`,type:r.role===void 0?r.type:`${r.type} · ${r.role}`,features:s,state:u,sources:o,reportedDeviceId:l};let d=En(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:Nn(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function Ln(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Rn(e,t){return Ln(e)-Ln(t)||e.name.localeCompare(t.name)}function zn(e,t){let n=e.flatMap(e=>{let n=In(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Rn),customizations:n.filter(e=>e.kind===`customization`).toSorted(Rn)}}var Bn=1e4;function Vn(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Hn(){let e=Ae();return e.data===void 0?{state:`unanswered`,reason:e.error==null?`the device list has not answered yet`:`the device list could not be read (${Vn(e.error)})`}:wn(e.data)}function Un(){let e=fe({},{refetchInterval:Bn}),t=Hn(),n=e.data;if(e.error!=null&&n===void 0)return d(A,{title:`Could not read the compositions`,message:Vn(e.error),onRetry:()=>void e.refetch()});if(n===void 0)return d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading compositions…`});if(n.state===`not-loaded`)return d(F,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-warning`,children:`The composition store has not been read yet.`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`This is not the same as having none — the list appears once the hub has read it (`,n.reason,`).`]})]})});let r=e.error==null?null:Vn(e.error);return d(Wn,{lists:zn(n.views,t),fleet:t,refreshError:r})}function Wn({lists:e,fleet:t,refreshError:n}){return i(`div`,{className:`space-y-4`,children:[n!==null&&i(`p`,{className:`text-xs text-warning`,children:[`Showing the last answer — the latest refresh failed: `,n]}),t.state===`unanswered`&&i(`p`,{className:`text-xs text-warning`,children:[`Device names are shown as references: `,t.reason,`. No source is marked missing until it has.`]}),d(Gn,{title:`Composed devices`,hint:`A new device whose state is derived from other devices.`,rows:e.composed,nameHeader:`Name`,emptyMessage:`No composed devices.`,action:d(we,{to:Te,className:`text-xs text-primary hover:underline`,children:`+ New composed device`})}),d(Gn,{title:`Customizations`,hint:`Fields added to or replaced on an existing device — one per device, edited from the device.`,rows:e.customizations,nameHeader:`Device`,emptyMessage:`No customizations.`})]})}function Gn({title:e,hint:t,rows:n,nameHeader:r,emptyMessage:a,action:o}){return i(`section`,{className:`space-y-2`,"aria-label":e,children:[i(`div`,{className:`flex items-start justify-between gap-2`,children:[i(`div`,{children:[d(`h3`,{className:`font-medium`,children:e}),d(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),o!==void 0&&o]}),d(F,{variant:`flat`,className:`p-0`,children:d(se,{columns:Kn(r),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:N,emptyMessage:a})})]})}function Kn(e){return[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>d(qn,{row:e})},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>d(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??`unknown`})},{key:`state`,header:`State`,nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:e=>i(`div`,{className:`space-y-0.5`,children:[d(R,{variant:ln(e.state.tone),children:e.state.label}),e.state.reason!==null&&d(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:e.state.reason})]})},{key:`sources`,header:`Sources`,nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>d(Yn,{sources:e.sources})}]}function qn({row:e}){return i(`div`,{className:`space-y-0.5`,children:[d(Jn,{row:e}),e.namePresence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`device missing`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.features.join(`, `)})]})}function Jn({row:e}){return e.kind===`composed`?d(we,{to:Ce(e.blockId),className:`text-xs text-foreground hover:underline`,children:e.name}):e.reportedDeviceId===null?i(`span`,{className:`text-xs text-foreground-subtle`,children:[e.name,` — device not reported yet`]}):d(we,{to:De(e.reportedDeviceId),className:`text-xs text-foreground hover:underline`,children:e.name})}function Yn({sources:e}){return e.length===0?d(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):d(`ul`,{className:`space-y-0.5`,children:e.map(e=>i(`li`,{className:`text-xs`,children:[e.deviceId===null?d(`span`,{className:e.presence===`missing`?`text-danger`:`text-foreground`,children:e.label}):d(we,{to:`/devices/${String(e.deviceId)}`,className:`hover:underline`,children:e.label}),e.presence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`missing`})]},e.key))})}function Xn(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Zn(e){if(Array.isArray(e))return e}function Qn(e,t,n){return(t=sr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function $n(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function er(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
5
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function tr(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function nr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?tr(Object(n),!0).forEach(function(t){Qn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):tr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function rr(e,t){if(e==null)return{};var n,r,i=ir(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function ir(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function ar(e,t){return Zn(e)||$n(e,t)||cr(e,t)||er()}function or(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function sr(e){var t=or(e,`string`);return typeof t==`symbol`?t:t+``}function cr(e,t){if(e){if(typeof e==`string`)return Xn(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Xn(e,t):void 0}}function lr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ur(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function dr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ur(Object(n),!0).forEach(function(t){lr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ur(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function fr(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function pr(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function mr(e){return{}.toString.call(e).includes(`Object`)}function hr(e){return!Object.keys(e).length}function gr(e){return typeof e==`function`}function _r(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function vr(e,t){return mr(t)||Y(`changeType`),Object.keys(t).some(function(t){return!_r(e,t)})&&Y(`changeField`),t}function yr(e){gr(e)||Y(`selectorType`)}function br(e){gr(e)||mr(e)||Y(`handlerType`),mr(e)&&Object.values(e).some(function(e){return!gr(e)})&&Y(`handlersType`)}function xr(e){e||Y(`initialIsRequired`),mr(e)||Y(`initialType`),hr(e)&&Y(`initialContent`)}function Sr(e,t){throw Error(e[t]||e.default)}var Y=pr(Sr)({initialIsRequired:`initial state is required`,initialType:`initial state should be an object`,initialContent:`initial state shouldn't be an empty object`,handlerType:`handler should be an object or a function`,handlersType:`all handlers should be a functions`,selectorType:`selector should be a function`,changeType:`provided value of changes should be an object`,changeField:`it seams you want to change a field in the state which is not specified in the "initial" state`,default:"an unknown error accured in `state-local` package"}),Cr={changes:vr,selector:yr,handler:br,initial:xr};function wr(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Cr.initial(e),Cr.handler(t);var n={current:e},r=pr(Dr)(n,t),i=pr(Er)(n),a=pr(Cr.changes)(e),o=pr(Tr)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Cr.selector(e),e(n.current)}function c(e){fr(r,i,a,o)(e)}return[s,c]}function Tr(e,t){return gr(t)?t(e.current):t}function Er(e,t){return e.current=dr(dr({},e.current),t),t}function Dr(e,t,n){return gr(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Or={create:wr},kr={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Ar(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function jr(e){return{}.toString.call(e).includes(`Object`)}function Mr(e){return e||Ir(`configIsRequired`),jr(e)||Ir(`configType`),e.urls?(Nr(),{paths:{vs:e.urls.monacoBase}}):e}function Nr(){console.warn(Fr.deprecation)}function Pr(e,t){throw Error(e[t]||e.default)}var Fr={configIsRequired:`the configuration object is required`,configType:`the configuration object should be an object`,default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
|
|
6
|
-
You are using deprecated way of configuration.
|
|
7
|
-
|
|
8
|
-
Instead of using
|
|
9
|
-
monaco.config({ urls: { monacoBase: '...' } })
|
|
10
|
-
use
|
|
11
|
-
monaco.config({ paths: { vs: '...' } })
|
|
12
|
-
|
|
13
|
-
For more please check the link https://github.com/suren-atoyan/monaco-loader#config
|
|
14
|
-
`},Ir=Ar(Pr)(Fr),Lr={config:Mr},Rr=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function zr(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],zr(e[n],t[n]))}),nr(nr({},e),t)}var Br={type:`cancelation`,msg:`operation is manually canceled`};function Vr(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(Br):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var Hr=[`monaco`],Ur=ar(Or.create({config:kr,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),X=Ur[0],Wr=Ur[1];function Gr(e){var t=Lr.config(e),n=t.monaco,r=rr(t,Hr);Wr(function(e){return{config:zr(e.config,r),monaco:n}})}function Kr(){var e=X(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(Wr({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),Vr($r);if(window.monaco&&window.monaco.editor)return Zr(window.monaco),e.resolve(window.monaco),Vr($r);Rr(qr,Yr)(Xr)}return Vr($r)}function qr(e){return document.body.appendChild(e)}function Jr(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function Yr(e){var t=X(function(e){return{config:e.config,reject:e.reject}}),n=Jr(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function Xr(){var e=X(function(e){return{config:e.config,resolve:e.resolve,reject:e.reject}}),t=window.require;t.config(e.config),t([`vs/editor/editor.main`],function(t){var n=t.m||t;Zr(n),e.resolve(n)},function(t){e.reject(t)})}function Zr(e){X().monaco||Wr({monaco:e})}function Qr(){return X(function(e){return e.monaco})}var $r=new Promise(function(e,t){return Wr({resolve:e,reject:t})}),ei={config:Gr,init:Kr,__getMonacoInstance:Qr};r();var ti={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},ni={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function ri({children:e}){return a.createElement(`div`,{style:ni.container},e)}var ii=ri;function ai({width:e,height:t,isEditorReady:n,loading:r,_ref:i,className:o,wrapperProps:s}){return a.createElement(`section`,{style:{...ti.wrapper,width:e,height:t},...s},!n&&a.createElement(ii,null,r),a.createElement(`div`,{ref:i,style:{...ti.fullWidth,...!n&&ti.hide},className:o}))}var oi=n(ai);function si(e){f(e,[])}var ci=si;function li(e,n,r=!0){let i=t(!0);f(i.current||!r?()=>{i.current=!1}:e,n)}var Z=li;function ui(){}function Q(e,t,n,r){return di(e,r)||fi(e,t,n,r)}function di(e,t){return e.editor.getModel(pi(e,t))}function fi(e,t,n,r){return e.editor.createModel(t,n,r?pi(e,r):void 0)}function pi(e,t){return e.Uri.parse(t)}function mi({original:n,modified:r,language:i,originalLanguage:o,modifiedLanguage:s,originalModelPath:c,modifiedModelPath:u,keepCurrentOriginalModel:d=!1,keepCurrentModifiedModel:p=!1,theme:m=`light`,loading:h=`Loading...`,options:g={},height:_=`100%`,width:v=`100%`,className:y,wrapperProps:b={},beforeMount:x=ui,onMount:S=ui}){let[C,w]=l(!1),[T,E]=l(!0),D=t(null),O=t(null),k=t(null),A=t(S),j=t(x),M=t(!1);ci(()=>{let e=ei.init();return e.then(e=>(O.current=e)&&E(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>D.current?P():e.cancel()}),Z(()=>{if(D.current&&O.current){let e=D.current.getOriginalEditor(),t=Q(O.current,n||``,o||i||`text`,c||``);t!==e.getModel()&&e.setModel(t)}},[c],C),Z(()=>{if(D.current&&O.current){let e=D.current.getModifiedEditor(),t=Q(O.current,r||``,s||i||`text`,u||``);t!==e.getModel()&&e.setModel(t)}},[u],C),Z(()=>{let e=D.current.getModifiedEditor();e.getOption(O.current.editor.EditorOption.readOnly)?e.setValue(r||``):r!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:r||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[r],C),Z(()=>{D.current?.getModel()?.original.setValue(n||``)},[n],C),Z(()=>{let{original:e,modified:t}=D.current.getModel();O.current.editor.setModelLanguage(e,o||i||`text`),O.current.editor.setModelLanguage(t,s||i||`text`)},[i,o,s],C),Z(()=>{O.current?.editor.setTheme(m)},[m],C),Z(()=>{D.current?.updateOptions(g)},[g],C);let N=e(()=>{if(!O.current)return;j.current(O.current);let e=Q(O.current,n||``,o||i||`text`,c||``),t=Q(O.current,r||``,s||i||`text`,u||``);D.current?.setModel({original:e,modified:t})},[i,r,s,n,o,c,u]),ee=e(()=>{!M.current&&k.current&&(D.current=O.current.editor.createDiffEditor(k.current,{automaticLayout:!0,...g}),N(),O.current?.editor.setTheme(m),w(!0),M.current=!0)},[g,m,N]);f(()=>{C&&A.current(D.current,O.current)},[C]),f(()=>{!T&&!C&&ee()},[T,C,ee]);function P(){let e=D.current?.getModel();d||e?.original?.dispose(),p||e?.modified?.dispose(),D.current?.dispose()}return a.createElement(oi,{width:v,height:_,isEditorReady:C,loading:h,_ref:k,className:y,wrapperProps:b})}n(mi);function hi(e){let n=t();return f(()=>{n.current=e},[e]),n.current}var gi=hi,_i=new Map;function vi({defaultValue:n,defaultLanguage:r,defaultPath:i,value:o,language:s,path:c,theme:u=`light`,line:d,loading:p=`Loading...`,options:m={},overrideServices:h={},saveViewState:g=!0,keepCurrentModel:_=!1,width:v=`100%`,height:y=`100%`,className:b,wrapperProps:x={},beforeMount:S=ui,onMount:C=ui,onChange:w,onValidate:T=ui}){let[E,D]=l(!1),[O,k]=l(!0),A=t(null),j=t(null),M=t(null),N=t(C),ee=t(S),P=t(),te=t(o),F=gi(c),ne=t(!1),re=t(!1);ci(()=>{let e=ei.init();return e.then(e=>(A.current=e)&&k(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>j.current?ie():e.cancel()}),Z(()=>{let e=Q(A.current,n||o||``,r||s||``,c||i||``);e!==j.current?.getModel()&&(g&&_i.set(F,j.current?.saveViewState()),j.current?.setModel(e),g&&j.current?.restoreViewState(_i.get(c)))},[c],E),Z(()=>{j.current?.updateOptions(m)},[m],E),Z(()=>{!j.current||o===void 0||(j.current.getOption(A.current.editor.EditorOption.readOnly)?j.current.setValue(o):o!==j.current.getValue()&&(re.current=!0,j.current.executeEdits(``,[{range:j.current.getModel().getFullModelRange(),text:o,forceMoveMarkers:!0}]),j.current.pushUndoStop(),re.current=!1))},[o],E),Z(()=>{let e=j.current?.getModel();e&&s&&A.current?.editor.setModelLanguage(e,s)},[s],E),Z(()=>{d!==void 0&&j.current?.revealLine(d)},[d],E),Z(()=>{A.current?.editor.setTheme(u)},[u],E);let I=e(()=>{if(!(!M.current||!A.current)&&!ne.current){ee.current(A.current);let e=c||i,t=Q(A.current,o||n||``,r||s||``,e||``);j.current=A.current?.editor.create(M.current,{model:t,automaticLayout:!0,...m},h),g&&j.current.restoreViewState(_i.get(e)),A.current.editor.setTheme(u),d!==void 0&&j.current.revealLine(d),D(!0),ne.current=!0}},[n,r,i,o,s,c,m,h,g,u,d]);f(()=>{E&&N.current(j.current,A.current)},[E]),f(()=>{!O&&!E&&I()},[O,E,I]),te.current=o,f(()=>{E&&w&&(P.current?.dispose(),P.current=j.current?.onDidChangeModelContent(e=>{re.current||w(j.current.getValue(),e)}))},[E,w]),f(()=>{if(E){let e=A.current.editor.onDidChangeMarkers(e=>{let t=j.current.getModel()?.uri;if(t&&e.find(e=>e.path===t.path)){let e=A.current.editor.getModelMarkers({resource:t});T?.(e)}});return()=>{e?.dispose()}}return()=>{}},[E,T]);function ie(){P.current?.dispose(),_?g&&_i.set(c,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return a.createElement(oi,{width:v,height:y,isEditorReady:E,loading:p,_ref:M,className:b,wrapperProps:x})}var yi=n(vi);r();var bi={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function xi(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...bi}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function Si({value:n,onChange:r,extraLibs:i=[],onDiagnostics:a,readOnly:o=!1,heightPx:s=420,dark:c=!0}){let l=t(null),u=e((e,t)=>{if(l.current=t,xi(t,i),a===void 0)return;let n=e.getModel();if(n===null)return;let r=()=>{a(t.editor.getModelMarkers({resource:n.uri}).map(e=>({line:e.startLineNumber,column:e.startColumn,message:e.message,severity:e.severity})))};t.editor.onDidChangeMarkers(r),r()},[i,a]);return d(yi,{height:s,defaultLanguage:`typescript`,path:`file:///block.ts`,theme:c?`vs-dark`:`vs`,value:n,onChange:e=>r(e??``),onMount:u,options:{readOnly:o,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,renderWhitespace:`selection`}})}function Ci(e){return e.some(e=>e.severity>=8)}var wi=`import type { AddonContext } from '@camstack/types'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A core block. Runs in its own process, with the same \`ctx\` an addon gets.
|
|
18
|
-
* Return a function to release whatever you took (timers, sockets, listeners) —
|
|
19
|
-
* it is awaited on shutdown.
|
|
20
|
-
*/
|
|
21
|
-
export default function block(ctx: AddonContext) {
|
|
22
|
-
ctx.logger.info('hello from a core block')
|
|
23
|
-
|
|
24
|
-
const timer = setInterval(() => {
|
|
25
|
-
ctx.logger.info('tick')
|
|
26
|
-
}, 60_000)
|
|
27
|
-
|
|
28
|
-
return () => {
|
|
29
|
-
clearInterval(timer)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
`;function Ti({existing:e,dirty:t,saving:n,restarting:r}){return e===null?`Save the script first — there is no process to restart yet.`:n?`Saving…`:r?`Restarting…`:t?`Save first — a restart now would run the last SAVED code, not what is on screen.`:e.enabled?null:`This script is disabled. Enable it instead of restarting it.`}r();var Ei=`hub`;function Di({existing:e,typeDefs:t,typeDefsLoading:n,saving:r,saveError:a,restarting:s,restartError:f,onRestart:p,onSave:h,onCancel:g}){let _=m(),{resolvedMode:y}=ie(),[S,w]=l(e?.name??``),[T,E]=l(e?.code??wi),[D,O]=l(e?.placement??Ei),[A,j]=l(e?.integrationId??``),[N,ee]=l([]),[P,te]=l(!1),I=u({mutationFn:e=>_.trpcClient.coreBlocks.compile.mutate({code:e})}),L=o(()=>N.filter(e=>e.severity>=8),[N]),ae=Ci(N),se=S.trim()===``,ce=e===null||T!==e.code||S.trim()!==e.name||D!==e.placement||(A.trim()===``?void 0:A.trim())!==e.integrationId,le=()=>{I.reset(),h({name:S.trim(),code:T,enabled:e?.enabled??!0,placement:D,...A.trim()===``?{}:{integrationId:A.trim()}})},ue=e===null?null:q(e),de=Ti({existing:e,dirty:ce,saving:r,restarting:s});return d(F,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New script`:`Edit ${e.name}`}),ue!==null&&d(R,{variant:ln(ue.tone),children:ue.label})]}),i(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(b,{className:`mt-1`,value:S,onChange:e=>w(e.target.value),placeholder:`What this script does`})]}),i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Integration (optional)`}),d(b,{className:`mt-1`,value:A,onChange:e=>j(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),i(`div`,{children:[d(k,{selectedNodeId:D,onSelect:O,label:`Runs on`,alwaysShow:!0}),D!==Ei&&i(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[d(re,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),i(`span`,{children:[`Block execution is hub-only today. Saved with this placement the block will be stored and compiled, but it will report `,d(`strong`,{children:`Failed`}),` instead of running.`]})]})]}),i(`div`,{className:P?`grid gap-3 lg:grid-cols-2`:``,children:[d(`div`,{className:`rounded border border-border`,children:n?d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading the node's type definitions…`}):d(Si,{value:T,onChange:E,extraLibs:t?.libs??[],onDiagnostics:ee,dark:y===`dark`,heightPx:420})}),P&&i(`div`,{className:`rounded border border-border`,children:[d(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:e===null?`Logs appear once the script has been saved and started.`:i(c,{children:[`Logs — `,d(`code`,{children:B(e.id)})]})}),e!==null&&d(oe,{addonId:B(e.id),maxHeight:`max-h-[420px]`,showFilters:!1})]})]}),t!==void 0&&t.libs.length===0&&d(`p`,{className:`text-xs text-warning`,children:`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`}),L.length>0&&i(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[i(`p`,{className:`font-medium text-danger`,children:[L.length,` error`,L.length===1?``:`s`,` — the block cannot be saved.`]}),L.slice(0,5).map(e=>i(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),L.length>5&&i(`p`,{className:`text-foreground-subtle`,children:[`…and `,L.length-5,` more.`]})]}),I.data!==void 0&&(I.data.ok?i(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[d(C,{className:`h-3.5 w-3.5`}),` The node compiled this code. Nothing was saved.`]}):i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[I.data.line===void 0?``:`line ${String(I.data.line)}: `,I.data.error??`the code does not compile`]})),I.error!==null&&i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[`Could not reach the compiler: `,Oi(I.error)]}),a!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),f!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:f}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(M,{variant:`outline`,onClick:()=>I.mutate(T),disabled:I.isPending||r,title:`Type-check on the node without saving`,children:[I.isPending&&d(ne,{className:`h-4 w-4 animate-spin`}),` Compile`]}),i(M,{onClick:le,disabled:r||ae||se,children:[r&&d(ne,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(M,{variant:`outline`,onClick:()=>p?.(),disabled:de!==null||p===void 0,title:de??`Stop the process and let the supervisor bring it back`,children:[s?d(x,{className:`h-4 w-4 animate-spin`}):d(x,{className:`h-4 w-4`}),` `,`Restart`]}),i(M,{variant:`ghost`,onClick:()=>te(!P),title:`Show this script's process logs`,children:[d(v,{className:`h-4 w-4`}),` Logs `,P?`⇤`:`⇄`]}),d(M,{variant:`ghost`,onClick:g,disabled:r,children:`Close`}),i(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,L.length,ce&&e!==null?` · unsaved changes`:``]}),se&&d(R,{variant:`warning`,children:`Name required`})]})]})})}function Oi(e){return e instanceof Error?e.message:String(e)}r();var ki=[`coreBlocks`,`list`],Ai=[`coreBlocks`,`getTypeDefs`],ji=5e3;function $(e){return e instanceof Error?e.message:String(e)}function Mi({initialBlockId:e}={}){let n=m(),[r,a]=l({mode:`closed`}),[o,c]=l(null),[p,h]=l(null),g=s({queryKey:ki,refetchInterval:ji,queryFn:async()=>(await n.trpcClient.coreBlocks.list.query({})).blocks}),_=s({queryKey:Ai,enabled:r.mode===`edit`,staleTime:1/0,gcTime:1/0,queryFn:()=>n.trpcClient.coreBlocks.getTypeDefs.query({})}),v=()=>{g.refetch()},y=t(null),b=g.data;f(()=>{if(e===void 0||y.current===e)return;let t=b?.find(t=>t.id===e);t!==void 0&&(y.current=e,a({mode:`edit`,block:t}))},[e,b]);let x=u({mutationFn:e=>n.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{a({mode:`edit`,block:e.block}),v()}}),C=u({mutationFn:e=>n.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{a({mode:`edit`,block:e.block}),v()}}),w=u({mutationFn:e=>n.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{c(null),v()}}),T=u({mutationFn:e=>n.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:v}),E=u({mutationFn:e=>n.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:v}),D=dn(g.data??[]),O=g.data!==void 0&&D.length===0,k=x.isPending||C.isPending,j=x.error===null?C.error===null?null:$(C.error):$(x.error),N=r.mode===`edit`&&r.block!==null?un(D,r.block):null;return i(`div`,{className:`space-y-3`,children:[i(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:g.data===void 0?``:fn(D)}),i(M,{onClick:()=>a({mode:`edit`,block:null}),children:[d(S,{className:`h-4 w-4`}),` New script`]})]}),g.error!=null&&d(A,{title:`Could not read the scripts`,message:$(g.error),onRetry:v}),r.mode===`edit`&&d(Di,{existing:N,typeDefs:_.data,typeDefsLoading:_.isLoading,saving:k,saveError:j,restarting:E.isPending,restartError:E.error===null?null:$(E.error),onRestart:N===null?void 0:()=>E.mutate(N.id),onSave:e=>{let t=N;t===null?x.mutate(e):C.mutate({blockId:t.id,block:e})},onCancel:()=>{x.reset(),C.reset(),E.reset(),a({mode:`closed`})}}),O&&d(F,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No scripts yet.`}),d(`p`,{className:`text-xs text-foreground-subtle`,children:`A script is TypeScript the hub runs in its own process, with the same context an addon gets — devices, storage, the event bus. It is supervised: one that throws or hangs is marked failed and shown here, not left silently absent.`})]})}),D.length>0&&d(F,{children:d(`ul`,{className:`divide-y divide-border`,children:D.map(e=>d(Ni,{block:e,busy:T.isPending||w.isPending,restarting:E.isPending&&E.variables===e.id,confirming:o===e.id,logsOpen:p===e.id,onToggle:t=>T.mutate({blockId:e.id,enabled:t}),onRestart:()=>E.mutate(e.id),onToggleLogs:()=>h(p===e.id?null:e.id),onEdit:()=>a({mode:`edit`,block:e}),onAskDelete:()=>c(e.id),onCancelDelete:()=>c(null),onConfirmDelete:()=>w.mutate(e.id)},e.id))})}),w.error!=null&&d(A,{message:$(w.error)}),T.error!=null&&d(A,{message:$(T.error)}),E.error!=null&&d(A,{message:$(E.error)})]})}function Ni({block:e,busy:t,restarting:n,confirming:r,logsOpen:a,onToggle:o,onRestart:s,onToggleLogs:c,onEdit:l,onAskDelete:u,onCancelDelete:f,onConfirmDelete:p}){let m=q(e),h=w(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(R,{variant:ln(m.tone),children:m.label}),d(R,{variant:`info`,children:e.placement}),h!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,h]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:m.detail})]}),r?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this script?`}),d(M,{variant:`danger`,onClick:p,disabled:t,children:`Delete`}),d(M,{variant:`ghost`,onClick:f,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(M,{variant:`ghost`,onClick:l,title:`Edit`,children:d(O,{className:`h-4 w-4`})}),d(M,{variant:`ghost`,onClick:s,disabled:t||n||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:d(x,{className:`h-4 w-4${n?` animate-spin`:``}`})}),d(M,{variant:`ghost`,onClick:c,title:`Logs`,children:d(v,{className:`h-4 w-4`})}),d(M,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(M,{variant:`ghost`,onClick:u,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),a&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:B(e.id)})]}),d(oe,{addonId:B(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var Pi=[`automations`,`scripts`,`custom-device`];function Fi(e){return e!==null&&Pi.some(t=>t===e)}function Ii(){let[e,t]=Ee(),n=e.get(`tab`);return d(ke,{icon:ee,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,children:i(de,{value:Fi(n)?n:`automations`,onValueChange:e=>{t(t=>{let n=new URLSearchParams(t);return n.set(`tab`,e),n.delete(`block`),n},{replace:!0})},children:[i(le,{children:[d(E,{value:`automations`,children:`Automations`}),d(E,{value:`scripts`,children:`Scripts`}),d(E,{value:`custom-device`,children:`Custom Device`})]}),d(j,{value:`automations`,children:d(Cn,{onOpenScripts:e=>{t(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),e===void 0?n.delete(`block`):n.set(`block`,e),n},{replace:!0})}})}),d(j,{value:`scripts`,children:d(Mi,{initialBlockId:e.get(`block`)??void 0})}),d(j,{value:`custom-device`,children:d(Un,{})})]})})}export{Ii as BuildPage};
|