@camstack/addon-admin-ui 1.2.247 → 1.2.249
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-BytvreX_.js → AddonCollectionPage-DfFyOIZm.js} +1 -1
- package/dist/assets/{Addons-BLLKlxYv.js → Addons-UKYlvTDl.js} +1 -1
- package/dist/assets/{AdminTabs-VU7kpKyZ.js → AdminTabs-DwyEDqum.js} +1 -1
- package/dist/assets/AiProfiles-DMixMgHO.js +3 -0
- package/dist/assets/{BrokerForm-BHmVYFV6.js → BrokerForm-DXnocqWV.js} +1 -1
- package/dist/assets/Build-Fj8TRbYK.js +32 -0
- package/dist/assets/{Capabilities-DLUgld6f.js → Capabilities-DwIKR55a.js} +1 -1
- package/dist/assets/{CapabilityBadges-CAKIKvn3.js → CapabilityBadges-CbGC3Sr2.js} +1 -1
- package/dist/assets/Cluster-D_X1WjpP.js +11 -0
- package/dist/assets/{Data-Kw9D8vcQ.js → Data-Bl9NY8fx.js} +1 -1
- package/dist/assets/DetectionIntelligence-wPGqnz-d.js +1 -0
- package/dist/assets/{DeviceAggregateSection-PxgaTBaz.js → DeviceAggregateSection-WQgFpelR.js} +1 -1
- package/dist/assets/DeviceDetail-gyx7wwjq.js +2 -0
- package/dist/assets/{Devices-DSloYHYn.js → Devices-BeAJWC2C.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-DWb4Buui.js → EmbedPlayerPage-BDEgeX56.js} +1 -1
- package/dist/assets/Events-3SRJqq6z.js +1 -0
- package/dist/assets/{FormBuilder-BasrKp7g.js → FormBuilder-C6PGd_3I.js} +1 -1
- package/dist/assets/Identity-CIVKfDl8.js +1 -0
- package/dist/assets/IntegrationDetail-BcLo710t.js +1 -0
- package/dist/assets/{Integrations-C6R2fOxF.js → Integrations-DbV9_UGi.js} +1 -1
- package/dist/assets/{Integrations-DDfdNJip.js → Integrations-Li_SSpFr.js} +1 -1
- package/dist/assets/{Locations-B5_b8L6a.js → Locations-DgU3ZXv4.js} +1 -1
- package/dist/assets/{Logs-DHf7E7fA.js → Logs-B9r5O7Pb.js} +1 -1
- package/dist/assets/MotionZonesSettings-Cr2g3lEd.js +1 -0
- package/dist/assets/{MyAccess-28OX6JpZ.js → MyAccess-xT6rf1I3.js} +1 -1
- package/dist/assets/Network-CAWKY3wg.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-DROdwYc4.js → NodeAddonsSettingsPanel--JxZWc4P.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-BspDHTF_.js → NodeInferenceDevices-nFQVWo4O.js} +1 -1
- package/dist/assets/Notifications-CUp2XDcR.js +1 -0
- package/dist/assets/Pipeline-B5XgzVDx.js +1 -0
- package/dist/assets/{Plates-BY-27GRx.js → Plates-PScblaUk.js} +1 -1
- package/dist/assets/PrivacyMaskSettings-jP9zR7LH.js +1 -0
- package/dist/assets/{ProviderIcon-BgcJdMgU.js → ProviderIcon-BDwjI00L.js} +1 -1
- package/dist/assets/Recordings-D19WVRtk.js +1 -0
- package/dist/assets/{ScanNetworkModal-DjV8EbHW.js → ScanNetworkModal-CmYjQ51m.js} +1 -1
- package/dist/assets/SceneMonitorEditor-Cm-t1Wqj.js +1 -0
- package/dist/assets/{Scenes-7d1JrdQZ.js → Scenes-9HfT8fI4.js} +1 -1
- package/dist/assets/{Settings-BxQpBwAT.js → Settings-DEpfr3f9.js} +1 -1
- package/dist/assets/{Showroom-PnMM-dWp.js → Showroom-JnWM7cX5.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-CtAM299r.js → StorageLocationsPanel-B_OwU6dl.js} +1 -1
- package/dist/assets/{Terminal-DclP2HPM.js → Terminal-nirjNxpT.js} +3 -3
- package/dist/assets/{Viewer-DZfaa5de.js → Viewer-CjNwWFgU.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C3XAOfIR.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C2KG6Z5T.js} +1 -1
- package/dist/assets/{archive-CLeQTB6v.js → archive-Bnk_0OoE.js} +1 -1
- package/dist/assets/{authed-media-OKEaMX-U.js → authed-media-B9pRDmze.js} +1 -1
- package/dist/assets/{bell-off-C44Nl3Wz.js → bell-off-By-SN8Vq.js} +1 -1
- package/dist/assets/{boxes-BkyAndMq.js → boxes-CXQsT9kn.js} +1 -1
- package/dist/assets/circle-slash-D0MJZ_l8.js +1 -0
- package/dist/assets/{debounced-invalidate-B8OYRXRy.js → debounced-invalidate-QXfgUrBB.js} +1 -1
- package/dist/assets/dist-KBn-d78g.js +349 -0
- package/dist/assets/{dist-DB1uPDFx.js → dist-tB059TlK.js} +1 -1
- package/dist/assets/{face-bbox-pZ__HI1A.js → face-bbox-DvOlCNAZ.js} +1 -1
- package/dist/assets/{hard-drive-download-BmjiLW0h.js → hard-drive-download-CKemZPpg.js} +1 -1
- package/dist/assets/{hostInit-BvfHFMQy.js → hostInit-Cs0CfGoZ.js} +1 -1
- package/dist/assets/index-BpsfRZRW.js +4 -0
- package/dist/assets/{key-round-KZgC6FBW.js → key-round-CJ7q_Z3W.js} +1 -1
- package/dist/assets/{layers-CPivOZvd.js → layers-DecjUAz-.js} +1 -1
- package/dist/assets/{location-owned-usage-C22Ewo9H.js → location-owned-usage-B8IF-gEF.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-5328e8e1.js → mf-entry-bootstrap-0-aa978784.js} +2 -2
- package/dist/assets/{player-overlays-CDJkdSOF.js → player-overlays-DKYhJMOW.js} +1 -1
- package/dist/assets/remoteEntry-TwZvbZYo.js +1 -0
- package/dist/assets/{send-Bke6v13y.js → send-CIenQgTN.js} +1 -1
- package/dist/assets/{settings-2-vkofm0j7.js → settings-2-Bg2LaTJb.js} +1 -1
- package/dist/assets/{square-check-big-JAuZ6-5W.js → square-check-big-CZ1lZwBZ.js} +1 -1
- package/dist/assets/src-C8qpiQvV.js +349 -0
- package/dist/assets/src-rxUuiOxU.js +67 -0
- package/dist/assets/{use-scenes-feed-O1KQqn15.js → use-scenes-feed-Dq5Rachb.js} +1 -1
- package/dist/assets/{use-stationary-objects-CEVcxn4V.js → use-stationary-objects-Eg-I0VKW.js} +1 -1
- package/dist/assets/useEventInvalidation-BWeT6kzc.js +1 -0
- package/dist/assets/{useNodeUrlSelection-1YsGBmpC.js → useNodeUrlSelection-DF69X0xv.js} +1 -1
- package/dist/assets/user-round-BbbjI6sB.js +1 -0
- package/dist/assets/{video-xdAbvIOI.js → video-8AnFMPJk.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CN7APasg.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BljaJni_.js} +2 -2
- package/dist/index.html +5 -5
- package/dist/server/addon.js +243 -6
- package/package.json +1 -1
- package/dist/assets/AiProfiles-jfD6Nb6U.js +0 -3
- package/dist/assets/Build-DdF1TnpS.js +0 -32
- package/dist/assets/Cluster-vWBCXax8.js +0 -11
- package/dist/assets/DetectionIntelligence-CWIrQn2E.js +0 -1
- package/dist/assets/DeviceDetail-CW8YSnfP.js +0 -2
- package/dist/assets/Events-DPh2FgHd.js +0 -1
- package/dist/assets/Identity-DrjXeQKF.js +0 -1
- package/dist/assets/IntegrationDetail-CLX40K8g.js +0 -1
- package/dist/assets/MotionZonesSettings-CoGHuQle.js +0 -1
- package/dist/assets/Network-CNiSfAR7.js +0 -1
- package/dist/assets/Notifications-D5UFNorh.js +0 -1
- package/dist/assets/Pipeline-DXr4l2GV.js +0 -1
- package/dist/assets/PrivacyMaskSettings-B5p8PxRa.js +0 -1
- package/dist/assets/Recordings-CSHUT-y-.js +0 -1
- package/dist/assets/SceneMonitorEditor-DVTGddzr.js +0 -1
- package/dist/assets/circle-slash-BKSg1nEm.js +0 -1
- package/dist/assets/dist-BYnxz3ld.js +0 -349
- package/dist/assets/index-bDP5F8a8.js +0 -4
- package/dist/assets/remoteEntry-BcyN7W80.js +0 -1
- package/dist/assets/src-BtYlLp9k.js +0 -349
- package/dist/assets/src-XRPUTYTA.js +0 -67
- package/dist/assets/useEventInvalidation-B7MfQMwv.js +0 -1
- package/dist/assets/user-round-BBXckTah.js +0 -1
package/dist/server/addon.js
CHANGED
|
@@ -5361,7 +5361,7 @@ var ZodIssueCode = {
|
|
|
5361
5361
|
var ZodFirstPartyTypeKind;
|
|
5362
5362
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5363
5363
|
//#endregion
|
|
5364
|
-
//#region ../types/dist/sleep-
|
|
5364
|
+
//#region ../types/dist/sleep-BVhJDJka.mjs
|
|
5365
5365
|
/**
|
|
5366
5366
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5367
5367
|
* window to float samples (D455).
|
|
@@ -6932,6 +6932,18 @@ function systemMethod(input, output, options) {
|
|
|
6932
6932
|
systemOnly: true
|
|
6933
6933
|
};
|
|
6934
6934
|
}
|
|
6935
|
+
/**
|
|
6936
|
+
* A method a SOURCE of a collection cap may legitimately not serve — OPTIONAL
|
|
6937
|
+
* on `InferProvider`. The `providerOptional: true` literal is what
|
|
6938
|
+
* `InferProvider` keys on; see {@link CapabilityMethodSchema.providerOptional}
|
|
6939
|
+
* for when this is the honest answer and when it is a soft stub.
|
|
6940
|
+
*/
|
|
6941
|
+
function optionalMethod(input, output, options) {
|
|
6942
|
+
return {
|
|
6943
|
+
...method(input, output, options),
|
|
6944
|
+
providerOptional: true
|
|
6945
|
+
};
|
|
6946
|
+
}
|
|
6935
6947
|
var StaticDirOutputSchema$1 = object({ staticDir: string() });
|
|
6936
6948
|
var VersionOutputSchema$1 = object({ version: string() });
|
|
6937
6949
|
var adminUiCapability = {
|
|
@@ -24194,6 +24206,59 @@ var ClipPlaybackSchema = object({
|
|
|
24194
24206
|
* which days it asked for and got nothing — "no clips" would be a lie about a
|
|
24195
24207
|
* card that is full of them.
|
|
24196
24208
|
*/
|
|
24209
|
+
/**
|
|
24210
|
+
* The operator's authorisation to WAKE a sleeping camera for one clip read.
|
|
24211
|
+
*
|
|
24212
|
+
* ONE value, absent by default, and it is a `force`-shaped operator signal in
|
|
24213
|
+
* exactly the sense `snapshot-wake-gate.ts` uses the word: *"`snapshot.getSnapshot`'s
|
|
24214
|
+
* `force` flag, and nothing else… a background caller must never set it…
|
|
24215
|
+
* Stale but honest beats woken"*. A scheduler, a retry, a reconcile and a
|
|
24216
|
+
* prefetch never set it; a surface sets it only behind the same confirm the
|
|
24217
|
+
* "Wake and refresh" gesture uses, and it is refused below 15 % battery
|
|
24218
|
+
* exactly as that gesture is.
|
|
24219
|
+
*
|
|
24220
|
+
* The gate is decided BEFORE `getApi()`, because on UDP the login IS the wake
|
|
24221
|
+
* (D549) — a read that opened a session and then checked would have woken the
|
|
24222
|
+
* camera to find out it was not allowed to.
|
|
24223
|
+
*
|
|
24224
|
+
* **One authorised yes is one wake.** `next-natural` — take the clip the next
|
|
24225
|
+
* time the camera is awake for its own reasons — is deliberately not a member:
|
|
24226
|
+
* it was proposed, it is free on the battery, and the operator declined it on
|
|
24227
|
+
* 2026-09-20 (*"Quando un export viene richiesto si sveglia la camera."*,
|
|
24228
|
+
* D558 "Considered and not taken").
|
|
24229
|
+
*/
|
|
24230
|
+
var ClipWakeSchema = _enum(["authorised"]);
|
|
24231
|
+
/**
|
|
24232
|
+
* A clip's finished bytes, inline — the twin of `recordingExport.readExportBytes`.
|
|
24233
|
+
*
|
|
24234
|
+
* `bytes` is the DECODED length, so nobody infers it from the base64 length,
|
|
24235
|
+
* and `served` says which twin the caller actually got.
|
|
24236
|
+
*/
|
|
24237
|
+
var ClipBytesSchema = object({
|
|
24238
|
+
base64: string(),
|
|
24239
|
+
contentType: string(),
|
|
24240
|
+
/** Suggested filename, extension included. */
|
|
24241
|
+
name: string(),
|
|
24242
|
+
bytes: number().int().nonnegative(),
|
|
24243
|
+
/**
|
|
24244
|
+
* Which twin was actually served — the same contract
|
|
24245
|
+
* {@link ClipPlaybackSchema.served} carries, and REQUIRED here because the
|
|
24246
|
+
* export record persists it: a row read a week later must say the same thing
|
|
24247
|
+
* the panel said at the moment of the tap. A missing main twin is never
|
|
24248
|
+
* served silently as if it were the asked-for quality (D549 15).
|
|
24249
|
+
*/
|
|
24250
|
+
served: CamProfileSchema,
|
|
24251
|
+
/**
|
|
24252
|
+
* The DECODED duration of the delivered file, when the fetch measured one.
|
|
24253
|
+
*
|
|
24254
|
+
* A clip fetch verifies its own completion against the catalog row and
|
|
24255
|
+
* retries a materially short pass (D568); this is that measurement, carried
|
|
24256
|
+
* so a consumer can say the same thing rather than re-deriving it. Absent
|
|
24257
|
+
* when the producer did not measure — never zero, which would say the file
|
|
24258
|
+
* is empty.
|
|
24259
|
+
*/
|
|
24260
|
+
durationMs: number().positive().optional()
|
|
24261
|
+
});
|
|
24197
24262
|
var ClipSourceAvailabilitySchema = object({
|
|
24198
24263
|
state: _enum([
|
|
24199
24264
|
"ok",
|
|
@@ -24309,6 +24374,33 @@ DeviceType.Camera, method(object({
|
|
|
24309
24374
|
}), ClipPlaybackSchema, {
|
|
24310
24375
|
kind: "query",
|
|
24311
24376
|
auth: "protected"
|
|
24377
|
+
}), optionalMethod(object({
|
|
24378
|
+
deviceId: number(),
|
|
24379
|
+
clipId: string().min(1),
|
|
24380
|
+
/**
|
|
24381
|
+
* Which twin to fetch, on the mapping D549 15 already fixed:
|
|
24382
|
+
* `low | mid` → the sub file, `high` → the main twin. `auto` is not
|
|
24383
|
+
* accepted here for the same reason it is not accepted by
|
|
24384
|
+
* `getClipPlayback` — a stored file has no broker session, so the
|
|
24385
|
+
* adaptive tier cannot be resolved for it.
|
|
24386
|
+
*/
|
|
24387
|
+
profile: CamProfileSchema.optional(),
|
|
24388
|
+
/**
|
|
24389
|
+
* The CALLER's byte bound, so an over-size clip is refused before it is
|
|
24390
|
+
* read and encoded rather than after. Capped by
|
|
24391
|
+
* {@link VIDEOCLIPS_MAX_READ_BYTES} whatever is passed; absent means
|
|
24392
|
+
* that ceiling.
|
|
24393
|
+
*/
|
|
24394
|
+
maxBytes: number().int().positive().optional(),
|
|
24395
|
+
/**
|
|
24396
|
+
* The operator's authorisation to wake a sleeping camera for this
|
|
24397
|
+
* read. Absent — the default — means a sleeping standalone battery
|
|
24398
|
+
* camera is REFUSED by name, before any session is opened.
|
|
24399
|
+
*/
|
|
24400
|
+
wake: ClipWakeSchema.optional()
|
|
24401
|
+
}), ClipBytesSchema, {
|
|
24402
|
+
kind: "query",
|
|
24403
|
+
auth: "protected"
|
|
24312
24404
|
});
|
|
24313
24405
|
/**
|
|
24314
24406
|
* Optional client-side hints sent at session creation to help the provider
|
|
@@ -30241,13 +30333,101 @@ var ExportStateSchema = _enum([
|
|
|
30241
30333
|
"expired",
|
|
30242
30334
|
"deleted"
|
|
30243
30335
|
]);
|
|
30244
|
-
/**
|
|
30336
|
+
/**
|
|
30337
|
+
* WHAT an export is — the authority, as opposed to the four top-level fields
|
|
30338
|
+
* the Library sorts and labels on (D558 § 2.2).
|
|
30339
|
+
*
|
|
30340
|
+
* Read it through {@link exportSubjectOf}, never off the record directly: the
|
|
30341
|
+
* field is optional for the history rows written before it existed, and that
|
|
30342
|
+
* absence has exactly one interpreter.
|
|
30343
|
+
*/
|
|
30344
|
+
var ExportSubjectSchema = discriminatedUnion("kind", [object({
|
|
30345
|
+
kind: literal("footage"),
|
|
30346
|
+
deviceId: number(),
|
|
30347
|
+
profiles: array(string()).min(1),
|
|
30348
|
+
fromMs: number(),
|
|
30349
|
+
toMs: number()
|
|
30350
|
+
}), object({
|
|
30351
|
+
kind: literal("clip"),
|
|
30352
|
+
deviceId: number(),
|
|
30353
|
+
provider: string().min(1),
|
|
30354
|
+
source: string().min(1),
|
|
30355
|
+
sourceLabel: string().min(1),
|
|
30356
|
+
clipId: string().min(1),
|
|
30357
|
+
/**
|
|
30358
|
+
* WHERE IN THE CATALOG to confirm this clip — the day window the surface was
|
|
30359
|
+
* already listing when the operator picked the segment.
|
|
30360
|
+
*
|
|
30361
|
+
* It is **not** a time range control and it never becomes one: the record's
|
|
30362
|
+
* `fromMs`/`toMs` come from the catalog ROW and from nothing a caller
|
|
30363
|
+
* supplied (D558 § 5.4.3), and a window that does not contain the clip is a
|
|
30364
|
+
* `catalog-miss`, not a silently wider search. It exists because
|
|
30365
|
+
* `videoclips.listClips` takes `since`/`until` and has no by-handle twin:
|
|
30366
|
+
* the catalog check D558 asks for is literally that call, and a call needs a
|
|
30367
|
+
* window. The surface has one — `ClipsBrowser`'s `dayWindow`, one local
|
|
30368
|
+
* wall-clock day, which is also the only width measured to be cheap (one
|
|
30369
|
+
* day on 592 lists 171 clips in 712 ms, a busy day 546 in 2.0 s; twenty days
|
|
30370
|
+
* of one child's events took 3.6–5.4 s).
|
|
30371
|
+
*/
|
|
30372
|
+
catalogWindow: object({
|
|
30373
|
+
sinceMs: number(),
|
|
30374
|
+
untilMs: number()
|
|
30375
|
+
}),
|
|
30376
|
+
profile: _enum([
|
|
30377
|
+
"high",
|
|
30378
|
+
"mid",
|
|
30379
|
+
"low"
|
|
30380
|
+
]),
|
|
30381
|
+
/**
|
|
30382
|
+
* The operator's authorisation to wake a sleeping camera for this export.
|
|
30383
|
+
* ONE definition, in the cap that owns the clip read ({@link ClipWakeSchema}),
|
|
30384
|
+
* because the gate that honours it is the clip provider's sleep gate — a
|
|
30385
|
+
* second enum here would be a second contract. Absent by default; never
|
|
30386
|
+
* settable by a scheduler or a retry.
|
|
30387
|
+
*
|
|
30388
|
+
* **One authorised yes is ONE wake.** A failed clip export is retried only by
|
|
30389
|
+
* an operator act that asks again; a queued job that outlived its wake fails
|
|
30390
|
+
* with a reason rather than waking on its turn; and this subject carries
|
|
30391
|
+
* exactly one profile precisely so one tap is never two fetches (D558 § 5.2).
|
|
30392
|
+
*/
|
|
30393
|
+
wake: ClipWakeSchema.optional()
|
|
30394
|
+
})]);
|
|
30395
|
+
/**
|
|
30396
|
+
* One export job / history row.
|
|
30397
|
+
*
|
|
30398
|
+
* **`subject` is the AUTHORITY on what was exported. `deviceId`, `profile`,
|
|
30399
|
+
* `fromMs` and `toMs` are its PROJECTION** — kept top-level because the whole
|
|
30400
|
+
* Library sorts and labels on them (`library-items.ts` orders an export by
|
|
30401
|
+
* `fromMs`; `export-format.ts` draws `rangeLabel` from the pair), and a row
|
|
30402
|
+
* that did not fill them would sort under the epoch and render a blank range.
|
|
30403
|
+
* Write to the subject and read from the projection and the two will disagree;
|
|
30404
|
+
* the projection is derived at creation and never edited afterwards.
|
|
30405
|
+
*
|
|
30406
|
+
* And they mean DIFFERENT FACTS for the two kinds, which is the part a reader
|
|
30407
|
+
* who knows only the recording export will get wrong:
|
|
30408
|
+
*
|
|
30409
|
+
* | field | `kind:'footage'` | `kind:'clip'` |
|
|
30410
|
+
* | --- | --- | --- |
|
|
30411
|
+
* | `fromMs`/`toMs` | the stretch the operator ASKED for | the camera's own boundaries, always `clip.timeRange`, never anything a caller supplied |
|
|
30412
|
+
* | `profile` | the stream rendered | the twin actually SERVED (`subject.profile` is the one asked for) |
|
|
30413
|
+
*
|
|
30414
|
+
* Same type, different fact — the shape this repo keeps getting wrong (D385's
|
|
30415
|
+
* two authorities, D224's second copy).
|
|
30416
|
+
*/
|
|
30245
30417
|
var ExportRecordSchema = object({
|
|
30246
30418
|
id: string(),
|
|
30247
30419
|
deviceId: number(),
|
|
30248
30420
|
profile: string(),
|
|
30249
30421
|
fromMs: number(),
|
|
30250
30422
|
toMs: number(),
|
|
30423
|
+
/**
|
|
30424
|
+
* What this export IS. Optional ONLY for the rows written before D558: the
|
|
30425
|
+
* store parses every row through this schema on every read, so a required
|
|
30426
|
+
* field would make the export AUDIT — which is the whole reason rows survive
|
|
30427
|
+
* file deletion — unreadable in one release. Absence means `footage`, and
|
|
30428
|
+
* {@link exportSubjectOf} is the one place that says so.
|
|
30429
|
+
*/
|
|
30430
|
+
subject: ExportSubjectSchema.optional(),
|
|
30251
30431
|
options: ExportOptionsSchema,
|
|
30252
30432
|
state: ExportStateSchema,
|
|
30253
30433
|
/** 0–100 while rendering; null otherwise. */
|
|
@@ -30264,6 +30444,18 @@ var ExportRecordSchema = object({
|
|
|
30264
30444
|
/** Failure reason when state is 'failed'; null otherwise. */
|
|
30265
30445
|
error: string().nullable()
|
|
30266
30446
|
});
|
|
30447
|
+
_enum([
|
|
30448
|
+
"catalog-miss",
|
|
30449
|
+
"catalog-unreachable",
|
|
30450
|
+
"no-file-for-window",
|
|
30451
|
+
"clip-in-progress",
|
|
30452
|
+
"unsupported-option",
|
|
30453
|
+
"sleeping",
|
|
30454
|
+
"camera-refused",
|
|
30455
|
+
"fetch-failed",
|
|
30456
|
+
"too-large-to-transfer",
|
|
30457
|
+
"wake-expired"
|
|
30458
|
+
]);
|
|
30267
30459
|
/** Candidate download URLs (LAN first, then operator extra hosts). */
|
|
30268
30460
|
var ExportDownloadSchema = object({
|
|
30269
30461
|
url: string(),
|
|
@@ -30282,16 +30474,50 @@ var ExportBytesSchema = object({
|
|
|
30282
30474
|
name: string(),
|
|
30283
30475
|
bytes: number().int().nonnegative()
|
|
30284
30476
|
});
|
|
30477
|
+
/** Canonical `profiles[]`, falling back to the legacy singular `profile`. */
|
|
30478
|
+
function resolveExportProfiles(input) {
|
|
30479
|
+
if (input.profiles !== void 0 && input.profiles.length > 0) return [...input.profiles];
|
|
30480
|
+
if (typeof input.profile === "string" && input.profile.length > 0) return [input.profile];
|
|
30481
|
+
return [];
|
|
30482
|
+
}
|
|
30285
30483
|
method(object({
|
|
30286
30484
|
deviceId: number(),
|
|
30287
30485
|
/** @deprecated Prefer `profiles`. Kept so timelapse/notifiers keep working. */
|
|
30288
30486
|
profile: string().optional(),
|
|
30289
30487
|
profiles: array(string()).min(1).optional(),
|
|
30290
|
-
|
|
30291
|
-
|
|
30488
|
+
/** Footage only — a clip's boundaries are the camera's. */
|
|
30489
|
+
fromMs: number().optional(),
|
|
30490
|
+
toMs: number().optional(),
|
|
30491
|
+
/** What to export. Absent means the legacy flat footage request. */
|
|
30492
|
+
subject: ExportSubjectSchema.optional(),
|
|
30292
30493
|
options: ExportOptionsSchema
|
|
30293
30494
|
}).superRefine((v, ctx) => {
|
|
30294
|
-
if (
|
|
30495
|
+
if (v.subject?.kind === "clip") {
|
|
30496
|
+
if (v.subject.deviceId !== v.deviceId) ctx.addIssue({
|
|
30497
|
+
code: ZodIssueCode.custom,
|
|
30498
|
+
message: `subject.deviceId (${v.subject.deviceId}) must equal deviceId (${v.deviceId}) — the top-level field is what per-device scope enforcement reads`,
|
|
30499
|
+
path: ["subject", "deviceId"]
|
|
30500
|
+
});
|
|
30501
|
+
if (v.fromMs !== void 0 || v.toMs !== void 0) ctx.addIssue({
|
|
30502
|
+
code: ZodIssueCode.custom,
|
|
30503
|
+
message: "a clip export asks for no time range: the camera chose the boundaries and they are read from the catalog row",
|
|
30504
|
+
path: ["fromMs"]
|
|
30505
|
+
});
|
|
30506
|
+
return;
|
|
30507
|
+
}
|
|
30508
|
+
if (v.subject?.kind === "footage" && v.subject.deviceId !== v.deviceId) ctx.addIssue({
|
|
30509
|
+
code: ZodIssueCode.custom,
|
|
30510
|
+
message: `subject.deviceId (${v.subject.deviceId}) must equal deviceId (${v.deviceId})`,
|
|
30511
|
+
path: ["subject", "deviceId"]
|
|
30512
|
+
});
|
|
30513
|
+
const fromMs = v.subject?.kind === "footage" ? v.subject.fromMs : v.fromMs;
|
|
30514
|
+
const toMs = v.subject?.kind === "footage" ? v.subject.toMs : v.toMs;
|
|
30515
|
+
if (typeof fromMs !== "number" || typeof toMs !== "number") ctx.addIssue({
|
|
30516
|
+
code: ZodIssueCode.custom,
|
|
30517
|
+
message: "a footage export needs fromMs and toMs",
|
|
30518
|
+
path: ["fromMs"]
|
|
30519
|
+
});
|
|
30520
|
+
if ((v.subject?.kind === "footage" ? [...v.subject.profiles] : resolveExportProfiles(v)).length < 1) ctx.addIssue({
|
|
30295
30521
|
code: ZodIssueCode.custom,
|
|
30296
30522
|
message: "pass profiles[] (min 1) or legacy profile",
|
|
30297
30523
|
path: ["profiles"]
|
|
@@ -38291,6 +38517,12 @@ Object.freeze({
|
|
|
38291
38517
|
addonId: null,
|
|
38292
38518
|
access: "view"
|
|
38293
38519
|
},
|
|
38520
|
+
"videoclips.readClipBytes": {
|
|
38521
|
+
capName: "videoclips",
|
|
38522
|
+
capScope: "device",
|
|
38523
|
+
addonId: null,
|
|
38524
|
+
access: "view"
|
|
38525
|
+
},
|
|
38294
38526
|
"viewerUi.getStaticDir": {
|
|
38295
38527
|
capName: "viewer-ui",
|
|
38296
38528
|
capScope: "system",
|
|
@@ -40309,6 +40541,11 @@ Object.freeze({
|
|
|
40309
40541
|
form: "single",
|
|
40310
40542
|
optional: false
|
|
40311
40543
|
}],
|
|
40544
|
+
"videoclips.readClipBytes": [{
|
|
40545
|
+
name: "deviceId",
|
|
40546
|
+
form: "single",
|
|
40547
|
+
optional: false
|
|
40548
|
+
}],
|
|
40312
40549
|
"waterHeater.setAway": [{
|
|
40313
40550
|
name: "deviceId",
|
|
40314
40551
|
form: "single",
|
|
@@ -40986,7 +41223,7 @@ var AdminUIAddon = class extends BaseAddon {
|
|
|
40986
41223
|
capability: adminUiCapability,
|
|
40987
41224
|
provider: {
|
|
40988
41225
|
getStaticDir: async () => ({ staticDir: resolveAdminUiDistDir() }),
|
|
40989
|
-
getVersion: async () => ({ version: "1.2.
|
|
41226
|
+
getVersion: async () => ({ version: "1.2.249" })
|
|
40990
41227
|
}
|
|
40991
41228
|
}];
|
|
40992
41229
|
}
|
package/package.json
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{W as d,Z as f,_t as p,at as m,ct as h,gt as g,st as _}from"./player-overlays-CDJkdSOF.js";import{$t as v,Dt as y,Et as b,Gt as x,Ht as S,Jt as C,Lt as w,Ol as T,Qr as E,Qt as D,Rc as O,Rl as k,St as A,Tt as j,Vl as M,Wl as N,Xc as ee,Yc as P,Zt as te,_ as F,al as I,bt as L,cl as R,iu as z,kl as ne,kt as B,ol as V,qt as H,wt as U,xc as re,xt as W,yl as G}from"./src-XRPUTYTA.js";import{t as ie}from"./boxes-BkyAndMq.js";import{t as ae}from"./send-Bke6v13y.js";import{pt as K}from"./src-BtYlLp9k.js";import{n as q}from"./index-bDP5F8a8.js";import{t as J}from"./AdminPage-CiKtOLQm.js";import{t as oe}from"./AdminTabs-VU7kpKyZ.js";var se=p(`message-square-plus`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]);n();var ce=[`llm`,`listProfiles`],le=[`llm`,`listProfileKinds`],ue=[`llm`,`getDefaults`],de=[`llm`,`listRuntimeNodes`],fe=[`llm`,`listModelCatalog`],pe=[`llm`,`getUsage`],me=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],he=new Map(Object.entries({openai:N,anthropic:N,google:N,"openai-compatible":I,"managed-local":M}));function ge(e){return he.get(e)??null}function Y(e){return typeof e==`string`&&e.length>0?e:void 0}function X(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);return Number.isFinite(t)?t:void 0}}function Z(e){return e===!0}function _e(e){return{model:e.model,baseUrl:e.baseUrl,apiKey:e.apiKey,supportsVision:e.supportsVision,temperature:e.temperature,topP:e.topP,topK:e.topK,maxTokens:e.maxTokens,contextLength:e.contextLength,systemPrompt:e.systemPrompt,timeoutMs:e.timeoutMs,connectTimeoutMs:e.connectTimeoutMs,firstTokenTimeoutMs:e.firstTokenTimeoutMs,idleTimeoutMs:e.idleTimeoutMs,retryEnabled:e.retry.enabled,retryMaxAttempts:e.retry.maxAttempts,toolsEnabled:e.toolsEnabled,contextSize:e.runtime?.contextSize,gpuLayers:e.runtime?.gpuLayers,threads:e.runtime?.threads,parallel:e.runtime?.parallel,idleStopMinutes:e.runtime?.idleStopMinutes,batchSize:e.runtime?.batchSize,ubatchSize:e.runtime?.ubatchSize,flashAttention:e.runtime?.flashAttention,mlock:e.runtime?.mlock,noMmap:e.runtime?.noMmap,cacheTypeK:e.runtime?.cacheTypeK,cacheTypeV:e.runtime?.cacheTypeV,extraArgs:xe(e.runtime?.extraArgs??[])}}var ve=[`f32`,`f16`,`q8_0`,`q5_1`,`q5_0`,`q4_1`,`q4_0`];function ye(e){return typeof e==`string`&&ve.includes(e)?e:void 0}function be(e){let t=[],n=``,r=null;for(let i of e){if(r!==null){i===r?r=null:n+=i;continue}if(i===`"`||i===`'`){r=i;continue}if(/\s/.test(i)){n!==``&&t.push(n),n=``;continue}n+=i}return n!==``&&t.push(n),t}function xe(e){return e.map(e=>/\s/.test(e)?`"${e}"`:e).join(` `)}var Se=[`--jinja`,`--cont-batching`];function Ce(e,t,n){let r=X(e.threads),i=X(e.batchSize),a=X(e.ubatchSize),o=ye(e.cacheTypeK),s=ye(e.cacheTypeV);return{nodeId:t,engine:`llama-cpp`,model:n,extraArgs:[...be(Y(e.extraArgs)??``)],contextSize:X(e.contextSize)??4096,gpuLayers:X(e.gpuLayers)??0,...r===void 0?{}:{threads:r},parallel:X(e.parallel)??1,...i===void 0?{}:{batchSize:i},...a===void 0?{}:{ubatchSize:a},flashAttention:Z(e.flashAttention),mlock:Z(e.mlock),noMmap:Z(e.noMmap),...o===void 0?{}:{cacheTypeK:o},...s===void 0?{}:{cacheTypeV:s},autoStart:Z(e.autoStart),idleStopMinutes:X(e.idleStopMinutes)??30}}function we(e,t,n,r,i){let a={id:n?.id??crypto.randomUUID(),name:t,kind:e,addonId:`ai`,enabled:n?.enabled??!0,model:Y(r.model)??n?.model??``,supportsVision:i?.supportsVision??Z(r.supportsVision),timeoutMs:X(r.timeoutMs)??K.totalMs,connectTimeoutMs:X(r.connectTimeoutMs)??K.connectMs,firstTokenTimeoutMs:X(r.firstTokenTimeoutMs)??K.firstTokenMs,idleTimeoutMs:X(r.idleTimeoutMs)??K.idleMs,retry:{enabled:Z(r.retryEnabled),maxAttempts:X(r.retryMaxAttempts)??1},toolsEnabled:Z(r.toolsEnabled)},o=Y(r.baseUrl),s=Y(r.apiKey),c=X(r.temperature),l=X(r.topP),u=X(r.topK),d=X(r.maxTokens),f=X(r.contextLength),p=Y(r.systemPrompt);return{...a,...o===void 0?{}:{baseUrl:o},...s===void 0?{}:{apiKey:s},...c===void 0?{}:{temperature:c},...l===void 0?{}:{topP:l},...u===void 0?{}:{topK:u},...d===void 0?{}:{maxTokens:d},...f===void 0?{}:{contextLength:f},...p===void 0?{}:{systemPrompt:p},...i===void 0?{}:{model:i.modelId,runtime:Ce(r,i.nodeId,i.model)}}}function Te(e){let t=new Map;for(let n of e){let e=t.get(n.addonId)??[];e.push(n),t.set(n.addonId,e)}return[...t.entries()].map(([e,t])=>({addonId:e,kinds:t}))}var Ee=2e3;function Q(e){return`${(e/1e9).toFixed(2)} GB`}function De(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Oe({nodeId:e,value:t,onChange:n}){let{t:o}=q(),u=m(),[d,f]=s(``),[p,h]=s(null),[g,_]=s(!1),y=a({queryKey:fe,queryFn:()=>u.trpcClient.llm.listModelCatalog.query({})}),b=a({queryKey:[`llm`,`listNodeModels`,e],queryFn:()=>u.trpcClient.llm.listNodeModels.query({nodeId:e})}),x=c({mutationFn:e=>u.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{h(e),_(!1),e.ok&&n({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),S=c({mutationFn:t=>u.trpcClient.llm.installModel.mutate({nodeId:e,model:t}),onSuccess:()=>{_(!0),b.refetch()}}),C=a({queryKey:de,enabled:S.isPending,refetchInterval:S.isPending?Ee:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(t=>t.nodeId===e)?.status?.download,w=i(()=>{let t=(y.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${Q(e.sizeBytes)}`})),n=(b.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(t=>({value:`node:${t.file}`,label:o(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:t.file,size:Q(t.sizeBytes),node:e})})),r=p?.ok===!0?[{value:`custom`,label:`${p.label} · ${Q(p.totalBytes)}`}]:[];return[{value:``,label:o(`ai.selectModel`,`Select a model…`)},...t,...n,...r]},[y.data,b.data,p,e,o]),T=e=>{if(e===``){n(null);return}if(e===`custom`){if(p?.ok!==!0)return;n({model:p.model,modelId:p.label,supportsVision:p.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),r=y.data?.find(e=>e.id===t);n({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:r?.purpose===`vision`});return}let t=e.slice(5),r=b.data?.find(e=>e.file===t);r?.path!==void 0&&n({model:{kind:`path`,path:r.path},modelId:t,supportsVision:!1})},E=e=>{d.trim()!==``&&x.mutate({ref:d.trim(),...e===void 0?{}:{maxBytes:e}})};return r(`div`,{className:`space-y-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-model`,children:o(`ai.model`,`Model`)}),l(te,{id:`ai-model`,value:De(t),options:w,onChange:e=>T(e.target.value)})]}),r(`div`,{className:`rounded-md border border-border bg-surface-subtle px-3 py-2.5`,children:[l(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:o(`ai.hfTitle`,`Add a model from Hugging Face`)}),l(`p`,{className:`mb-2 text-[10px] leading-relaxed text-foreground-subtle`,children:o(`ai.hfHint`,`Paste a GGUF file URL, or type org/repo — add :QUANT (e.g. unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M) when the repo publishes more than one quantization.`)}),r(`div`,{className:`flex gap-2`,children:[l(B,{value:d,onChange:e=>f(e.target.value),placeholder:`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),E())}}),r(D,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||x.isPending,onClick:()=>E(),children:[x.isPending?l(G,{className:`h-3.5 w-3.5 animate-spin`}):l(ee,{className:`h-3.5 w-3.5`}),o(`ai.hfCheck`,`Check`)]})]}),x.isError&&l(`p`,{className:`mt-2 text-[11px] text-danger`,children:x.error instanceof Error?x.error.message:o(`common.error`,`Error`)}),p?.ok===!1&&r(`div`,{className:`mt-2 rounded-md border border-danger/40 bg-danger/10 px-2.5 py-2`,children:[l(`p`,{className:`text-[11px] text-danger`,children:p.message}),p.candidates!==void 0&&p.candidates.length>0&&l(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:p.candidates.map(e=>l(`button`,{type:`button`,className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] text-foreground hover:border-primary/50`,onClick:()=>{let t=`${d.trim().split(`:`)[0]??``}:${e}`;f(t),x.mutate({ref:t})},children:e},e))}),p.requiredBytes!==void 0&&l(D,{size:`sm`,variant:`secondary`,type:`button`,className:`mt-2`,onClick:()=>E(p.requiredBytes),children:o(`ai.hfOverride`,`Install anyway ({{size}})`,{size:Q(p.requiredBytes)})})]}),p?.ok===!0&&r(`div`,{className:`mt-2 rounded-md border border-border bg-surface px-2.5 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[l(`span`,{className:`text-[11px] font-medium text-foreground`,children:p.label}),l(v,{variant:p.purpose===`vision`?`info`:`default`,children:p.purpose}),l(v,{variant:`default`,children:Q(p.totalBytes)})]}),p.extraFilenames.length>0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:o(`ai.hfExtras`,`Also downloads: {{files}}`,{files:p.extraFilenames.join(`, `)})}),r(`div`,{className:`mt-2 flex items-center gap-2`,children:[r(D,{size:`sm`,type:`button`,disabled:S.isPending||g,onClick:()=>S.mutate(p.model),children:[S.isPending?l(G,{className:`h-3.5 w-3.5 animate-spin`}):l(k,{className:`h-3.5 w-3.5`}),g?o(`ai.hfInstalled`,`Downloaded`):o(`ai.hfInstall`,`Download to {{node}}`,{node:e})]}),C!==void 0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:C.phase===`verifying`?o(`ai.hfVerifying`,`verifying {{file}}…`,{file:C.file}):o(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:C.file,index:C.fileIndex,count:C.fileCount,done:Q(C.downloadedBytes),total:C.totalBytes===void 0?``:` / ${Q(C.totalBytes)}`})})]}),S.isError&&l(`p`,{className:`mt-1.5 text-[11px] text-danger`,children:S.error instanceof Error?S.error.message:o(`common.error`,`Error`)})]})]})]})}n();function ke({kind:e,className:t}){let n=ge(e.kind);return n===null?l(`span`,{className:t,children:e.icon}):l(n,{className:t})}function Ae({kinds:e,onPick:t,onCancel:n}){let{t:a}=q(),o=i(()=>Te(e),[e]);return l(L,{open:!0,onOpenChange:e=>!e&&n(),children:r(A,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(j,{children:l(b,{children:a(`ai.chooseKind`,`Choose a profile type`)})}),r(W,{className:`space-y-4 pr-1`,children:[o.length===0&&l(`p`,{className:`text-xs text-foreground-subtle`,children:a(`ai.noKinds`,`No AI provider is installed.`)}),o.map(e=>r(`div`,{children:[l(`div`,{className:`mb-1.5 text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:e.addonId}),l(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:e.kinds.map(n=>r(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs transition-colors hover:border-primary/50 hover:bg-surface-hover`,children:[l(ke,{kind:n,className:`h-5 w-5 text-foreground-subtle`}),l(`span`,{className:`font-medium text-foreground`,children:n.label})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]}),l(U,{children:l(D,{size:`sm`,variant:`secondary`,type:`button`,onClick:n,children:a(`common.cancel`,`Cancel`)})})]})})}function je({kind:e,existing:t,onSave:n,onCancel:a,saving:c,error:u}){let{t:d}=q(),f=e.kind===`managed-local`,[p,m]=s(t?.name??e.label),[h,g]=s(()=>t===null?{}:_e(t)),[_,y]=s(t?.runtime?.nodeId??`hub`),[x,S]=s(()=>t?.runtime===void 0?null:{model:t.runtime.model,modelId:t.model,supportsVision:t.supportsVision}),C=i(()=>be(Y(h.extraArgs)??``),[h.extraArgs]),T=()=>{if(!f){n(we(e.kind,p,t,h));return}x!==null&&n(we(e.kind,p,t,h,{nodeId:_,model:x.model,modelId:x.modelId,supportsVision:x.supportsVision}))},E=c||p.trim()===``||f&&x===null;return l(L,{open:!0,onOpenChange:e=>!e&&a(),children:r(A,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(j,{children:r(b,{className:`flex items-center gap-2`,children:[l(ke,{kind:e,className:`h-4 w-4 text-foreground-subtle`}),t===null?d(`ai.newProfile`,`New {{kind}} profile`,{kind:e.label}):d(`ai.editProfile`,`Edit {{name}}`,{name:t.name})]})}),r(W,{className:`space-y-3 pr-1`,children:[u!==null&&l(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:u}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-profile-name`,children:d(`ai.name`,`Name`)}),l(B,{id:`ai-profile-name`,value:p,onChange:e=>m(e.target.value),placeholder:e.label})]}),f&&r(o,{children:[l(F,{selectedNodeId:_,onSelect:y,label:d(`ai.runtimeNode`,`Runtime node`),alwaysShow:!0}),l(Oe,{nodeId:_,value:x,onChange:S}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-extra-args`,children:d(`ai.extraArgs`,`Additional llama-server arguments`)}),l(B,{id:`ai-extra-args`,value:Y(h.extraArgs)??``,onChange:e=>g({...h,extraArgs:e.target.value}),placeholder:Se.join(` `)}),C.length>0&&l(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:C.map((e,t)=>l(v,{variant:`default`,children:e},`${e}-${String(t)}`))}),l(`p`,{className:`mt-1 text-[10px] leading-relaxed text-foreground-subtle`,children:d(`ai.extraArgsHint`,`Flags this form does not already own. Vision models generally need --jinja; some language-only models do not like it. Context size, GPU layers, parallel slots, flash attention and the KV-cache types are set in the fields below — repeating one here is rejected at start.`)})]})]}),l(w,{schema:e.configSchema,values:h,onChange:g}),t!==null&&l(`p`,{className:`text-[10px] text-foreground-subtle`,children:d(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)})]}),r(U,{children:[f&&x===null&&l(v,{variant:`warning`,children:d(`ai.pickModelFirst`,`pick a model`)}),l(D,{size:`sm`,variant:`secondary`,type:`button`,onClick:a,children:d(`common.cancel`,`Cancel`)}),r(D,{size:`sm`,type:`button`,disabled:E,onClick:T,children:[c&&l(G,{className:`h-3.5 w-3.5 animate-spin`}),t===null?d(`ai.createProfile`,`Create profile`):d(`ai.saveChanges`,`Save changes`)]})]})]})})}n();function Me(e){return[{key:`name`,header:e.t(`ai.colProfile`,`Profile`),render:t=>{let n=e.kindByName.get(t.kind);return r(`span`,{className:`flex items-center gap-2`,children:[l(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface`,title:n?.label??t.kind,children:n===void 0?l(`span`,{className:`text-xs text-foreground-subtle`,children:`?`}):l(ke,{kind:n,className:`h-4 w-4 text-foreground-subtle`})}),r(`span`,{className:`min-w-0`,children:[l(`span`,{className:`block truncate text-sm font-medium text-foreground`,children:t.name}),e.testResult?.id===t.id&&l(`span`,{className:`block truncate text-[10px] ${e.testResult.ok?`text-success`:`text-danger`}`,children:e.testResult.text})]})]})}},{key:`kind`,header:e.t(`ai.colKind`,`Kind`),nowrap:!0,render:t=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.kindByName.get(t.kind)?.label??t.kind})},{key:`model`,header:e.t(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.model})},{key:`vision`,header:e.t(`ai.colVision`,`Vision`),align:`center`,nowrap:!0,render:t=>t.supportsVision?l(v,{variant:`info`,style:`outline`,children:e.t(`ai.vision`,`vision`)}):l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`})},{key:`node`,header:e.t(`ai.colNode`,`Node`),nowrap:!0,render:e=>e.runtime===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(v,{variant:`default`,children:e.runtime.nodeId})},{key:`enabled`,header:e.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:t=>l(y,{checked:t.enabled,onCheckedChange:()=>e.onToggle(t),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:t=>r(`span`,{className:`flex items-center justify-end gap-1`,children:[l(D,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onTest(t),title:e.t(`ai.test`,`Test`),children:e.testingId===t.id?l(G,{className:`h-3.5 w-3.5 animate-spin`}):l(ae,{className:`h-3.5 w-3.5`})}),l(D,{size:`sm`,variant:`ghost`,type:`button`,disabled:!e.kindByName.has(t.kind),onClick:()=>e.onEdit(t),title:e.t(`common.edit`,`Edit`),children:l(R,{className:`h-3.5 w-3.5`})}),l(D,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDelete(t),title:e.t(`common.delete`,`Delete`),children:l(_,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function Ne(){let{t:e}=q(),t=m(),[n,o]=s({mode:`closed`}),[u,d]=s(null),[f,p]=s(null),h=a({queryKey:ce,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),g=a({queryKey:le,queryFn:async()=>(await t.trpcClient.llm.listProfileKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),_=()=>{h.refetch()},v=c({mutationFn:e=>t.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{o({mode:`closed`}),p(null),_()},onError:t=>p(t instanceof Error?t.message:e(`ai.saveFailed`,`Save failed`))}),y=c({mutationFn:e=>t.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:_}),b=c({mutationFn:e=>t.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>d({id:t.id,ok:e.ok,text:e.ok?`${e.text} (${String(e.usage.outputTokens)} tok, ${String(e.latencyMs)}ms)`:`${e.code}: ${e.message}`})}),C=h.data??[],w=i(()=>g.data??[],[g.data]),T=i(()=>{let e=new Map;for(let t of w)e.set(t.kind,t);return e},[w]);return r(J,{icon:O,title:e(`ai.profilesTitle`,`AI profiles`),subtitle:e(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),actions:r(D,{size:`sm`,type:`button`,onClick:()=>{p(null),o({mode:`pick-kind`})},children:[l(V,{className:`h-3.5 w-3.5`}),e(`ai.addProfile`,`Add profile`)]}),children:[h.isError&&l(x,{title:e(`ai.loadFailed`,`Failed to load profiles`),message:h.error instanceof Error?h.error.message:e(`common.error`,`Error`),onRetry:()=>void h.refetch()}),l(Pe,{profiles:C}),h.isLoading&&l(`div`,{className:`flex items-center justify-center py-16`,children:l(G,{className:`h-6 w-6 animate-spin text-primary`})}),!h.isLoading&&C.length===0&&l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}),C.length>0&&l(S,{children:l(H,{columns:Me({kindByName:T,testResult:u,testingId:b.isPending?b.variables?.id??null:null,t:e,onToggle:e=>v.mutate({...e,enabled:!e.enabled,apiKey:`__redacted__`}),onTest:e=>b.mutate(e),onEdit:e=>{let t=T.get(e.kind);t!==void 0&&(p(null),o({mode:`form`,kind:t,profile:e}))},onDelete:e=>y.mutate(e)}),rows:C,rowKey:e=>e.id,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:`max-h-[60vh]`})}),n.mode===`pick-kind`&&l(Ae,{kinds:w,onCancel:()=>o({mode:`closed`}),onPick:e=>o({mode:`form`,kind:e,profile:null})}),n.mode===`form`&&l(je,{kind:n.kind,existing:n.profile,saving:v.isPending,error:f,onSave:e=>v.mutate(e),onCancel:()=>o({mode:`closed`})})]})}function Pe({profiles:e}){let{t}=q(),n=m(),i=a({queryKey:ue,queryFn:()=>n.trpcClient.llm.getDefaults.query({})}),o=c({mutationFn:e=>n.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{i.refetch()}}),s=e=>(i.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,u=e=>e===`vision`?t(`ai.defaultVision`,`Default vision profile`):t(`ai.defaultText`,`Default text profile`);return l(S,{children:l(`div`,{className:`grid gap-4 p-4 sm:grid-cols-2`,children:me.map(({purpose:n,visionOnly:i})=>{let a=i?e.filter(e=>e.supportsVision):e,c=s(n),d=e.find(e=>e.id===c);return r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`llm-default-${n}`,children:u(n)}),r(`select`,{id:`llm-default-${n}`,"aria-label":u(n),className:`h-7 w-full rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:c,onChange:e=>o.mutate({purpose:n,profileId:e.target.value===``?null:e.target.value}),children:[l(`option`,{value:``,children:t(`ai.none`,`None`)}),c!==``&&!a.some(e=>e.id===c)&&l(`option`,{value:c,children:d?.name??c}),a.map(e=>r(`option`,{value:e.id,children:[e.name,` · `,e.model]},e.id))]}),c!==``&&d===void 0&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:t(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&l(`p`,{className:`mt-1 text-[10px] text-warning`,children:t(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:String(o.error)})]},n)})})})}n();var Fe=5e3;function Ie(e){return`${(e/1e9).toFixed(1)} GB`}function Le(){let{t:e}=q(),t=m(),n=a({queryKey:de,refetchInterval:Fe,queryFn:()=>t.trpcClient.llm.listRuntimeNodes.query({})}),o=i(()=>[{key:`node`,header:e(`ai.colNode`,`Node`),render:e=>l(`span`,{className:`text-sm font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:e(`ai.colState`,`State`),nowrap:!0,render:t=>r(`span`,{className:`flex items-center gap-1.5`,children:[l(v,{variant:t.reachable?`success`:`danger`,children:t.reachable?t.status?.state??e(`ai.ready`,`ready`):e(`ai.unreachable`,`unreachable`)}),t.status?.downloadProgress!==void 0&&l(v,{variant:`info`,children:`${String(Math.round(t.status.downloadProgress*100))}%`})]})},{key:`model`,header:e(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:e(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.disk===void 0?`—`:Ie(e.disk.modelsBytes)})},{key:`error`,header:e(`ai.colError`,`Error`),render:e=>e.error===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(`span`,{className:`text-[11px] text-danger`,children:e.error})}],[e]),s=n.data??[];return r(J,{icon:P,title:e(`ai.runtimesTitle`,`Managed runtimes`),subtitle:e(`ai.runtimesSubtitle`,`Nodes advertising the llm-runtime capability: what each has loaded, what it is downloading, and how much model data sits on its disk.`),children:[n.isError&&l(x,{title:e(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:n.error instanceof Error?n.error.message:e(`common.error`,`Error`),onRetry:()=>void n.refetch()}),s.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):l(S,{children:l(H,{columns:o,rows:s,rowKey:e=>e.nodeId,minWidthPx:640,bordered:!1,mobileMode:`scroll`,maxBodyHeight:C})})]})}var Re=f(`/addon/ai/test-chat`),ze=f(`/addon/ai/test-chat/chats`),Be=6e5;function Ve(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),Be)}function He(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ue(e){if(!He(e))return null;let t=e.kind;return t!==`snapshot`&&t!==`track`||typeof e.mimeType!=`string`||typeof e.sizeBytes!=`number`?null:{kind:t,mimeType:e.mimeType,sizeBytes:e.sizeBytes,...typeof e.mediaKind==`string`?{mediaKind:e.mediaKind}:{},...typeof e.capturedAt==`number`?{capturedAt:e.capturedAt}:{},...typeof e.thumbnailBase64==`string`?{thumbnailBase64:e.thumbnailBase64}:{}}}var We=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function Ge(e){let t;try{t=JSON.parse(e)}catch{return null}if(!He(t))return null;switch(t.kind){case`status`:{let e=We.find(e=>e===t.phase);return e===void 0?null:{kind:`status`,phase:e}}case`meta`:return typeof t.profileName!=`string`||typeof t.model!=`string`?null:{kind:`meta`,profileName:t.profileName,model:t.model,mediaSent:Ue(t.mediaSent),streamed:t.streamed===!0,firstTokenTimeoutMs:typeof t.firstTokenTimeoutMs==`number`?t.firstTokenTimeoutMs:0};case`token`:return typeof t.text==`string`?{kind:`token`,text:t.text}:null;case`done`:return{kind:`done`,inputTokens:typeof t.inputTokens==`number`?t.inputTokens:0,outputTokens:typeof t.outputTokens==`number`?t.outputTokens:0,latencyMs:typeof t.latencyMs==`number`?t.latencyMs:0,truncated:t.truncated===!0,...typeof t.conversationId==`string`?{conversationId:t.conversationId}:{}};case`error`:return{kind:`error`,code:typeof t.code==`string`?t.code:`adapter-error`,message:typeof t.message==`string`?t.message:`the provider returned an error`};default:return null}}async function*Ke(e){let t=e.getReader(),n=new TextDecoder,r=``;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;r+=n.decode(i,{stream:!0});let a=r.indexOf(`
|
|
2
|
-
`);for(;a>=0;){let e=r.slice(0,a).trim();if(r=r.slice(a+1),e.length>0){let t=Ge(e);t!==null&&(yield t)}a=r.indexOf(`
|
|
3
|
-
`)}}let e=r.trim();if(e.length>0){let t=Ge(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function qe(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function Je(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function Ye(e){return e.messages.map((t,n)=>{let r=t.mediaSent??void 0;return{id:`${e.id}-${String(n)}`,role:t.role,content:t.content,...t.attachment===void 0?{}:{attachmentRef:t.attachment,attachmentKind:t.attachment.kind},...r===void 0?{}:{attachment:r}}})}function Xe(e){let t=e.sizeBytes<1024*1024?`${(e.sizeBytes/1024).toFixed(0)} KB`:`${(e.sizeBytes/(1024*1024)).toFixed(1)} MB`,n=[e.kind===`snapshot`?`camera snapshot`:`track best-shot`,t];return e.mediaKind!==void 0&&n.push(e.mediaKind),e.capturedAt!==void 0&&n.push(new Date(e.capturedAt).toLocaleTimeString()),n.join(` · `)}function Ze(e,t){switch(e){case`resolving-image`:return`fetching the picture…`;case`connecting`:return`connecting to the provider…`;case`first-token-wait`:return t>0?`the model is loading / thinking — a cold load can take minutes (up to ${String(Math.round(t/1e3))}s)`:`the model is loading / thinking — a cold load can take minutes`;case`streaming`:return`answering…`}}n();var Qe=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],$e=360*60*1e3,et=40,tt=160,$={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function nt(){let{t:n}=q(),o=m(),[c,d]=s(``),[f,p]=s(``),[v,y]=s(``),[b,C]=s([]),[w,T]=s(null),[E,O]=s(`none`),[k,A]=s(`throwaway`),[j,M]=s(null),[N,ee]=s([]),[P,F]=s(null),[I,L]=s(null),R=t(null);u(()=>()=>R.current?.abort(),[]);let V=e(async()=>{let e=await fetch(ze,{credentials:`same-origin`});e.ok&&ee((await e.json()).chats??[])},[]);u(()=>{k===`persistent`&&V()},[k,V]);let H=a({queryKey:ce,queryFn:()=>o.trpcClient.llm.listProfiles.query({})}),U=i(()=>(H.data??[]).filter(e=>e.enabled),[H.data]),W=U.find(e=>e.id===c)??null,G=I!==null,ie=e(async(e,t)=>{let r=new AbortController;R.current=r,F(null);let i=Ve(W??{});L({...$,firstTokenTimeoutMs:i??0});let a=``,o=null,s,l=null,u=null,d;try{let n=await fetch(Re,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:r.signal,body:JSON.stringify({profileId:c,messages:e,...f.trim()===``?{}:{system:f.trim()},...t===void 0?{}:{attachment:t},...i===void 0?{}:{firstTokenTimeoutMs:i},...k===`persistent`?{persist:!0,...j===null?{}:{conversationId:j}}:{}})});if(!n.ok||n.body===null){let e=await n.text().catch(()=>``);throw Error(e.length>0?e:`HTTP ${String(n.status)}`)}for await(let e of Ke(n.body))switch(e.kind){case`status`:L(t=>({...t??$,phase:e.phase}));break;case`meta`:o=e.mediaSent,s=e.model,L(t=>({...t??$,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:a+=e.text,L(e=>({...e??$,text:a}));break;case`done`:u={outputTokens:e.outputTokens,latencyMs:e.latencyMs},d=e.conversationId;break;case`error`:l=`${e.code}: ${e.message}`;break}}catch(e){r.signal.aborted||F(e instanceof Error?e.message:n(`common.error`,`Error`))}finally{R.current=null,L(null)}d!==void 0&&(M(d),V());let p=r.signal.aborted&&a.length>0;l===null&&a.length===0&&!p||C(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:l??a,...l===null?{}:{failed:!0},...o===null?{}:{attachment:o},...s!==void 0&&l===null?{model:s}:{},...u===null?{}:u}])},[k,j,W,c,V,f,n]),K=e(()=>{let e=v.trim();if(e===``||c===``||G)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...w===null?{}:{attachmentLabel:w.label,attachmentKind:w.ref.kind}},n=[...b,t];C(n),y(``);let r=w?.ref;T(null),O(`none`),ie(k===`persistent`&&j!==null?[{role:`user`,content:e}]:qe(n),r)},[k,j,v,w,c,ie,G,b]),oe=()=>R.current?.abort(),le=()=>{R.current?.abort(),C([]),T(null),y(``),F(null),L(null),M(null)},ue=async e=>{R.current?.abort();let t=await fetch(`${ze}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();M(e),C(Ye(n)),L(null),F(null)};return r(J,{icon:ne,title:n(`ai.testTitle`,`Test chat`),subtitle:n(k===`persistent`?`ai.testSubtitlePersistent`:`ai.testSubtitle`,k===`persistent`?`Conversations are saved for you and can be reopened. Throwaway mode is still available.`:`A throwaway conversation with one profile. Attach a live camera snapshot or a recent track to check the model can actually read a picture. Nothing is saved — only the usage row.`),actions:r(D,{size:`sm`,variant:`secondary`,type:`button`,disabled:b.length===0&&w===null,onClick:le,children:[l(_,{className:`h-3.5 w-3.5`}),n(`ai.clearChat`,`Clear`)]}),children:[r(S,{className:`space-y-3 p-4`,children:[r(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-profile`,children:n(`ai.profile`,`Profile`)}),l(te,{id:`ai-test-profile`,value:c,onChange:e=>d(e.target.value),options:[{value:``,label:n(`ai.selectProfile`,`Select a profile…`)},...U.map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.supportsVision?` · vision`:``}`}))]}),U.length===0&&!H.isLoading&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:n(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-system`,children:n(`ai.systemPrompt`,`System prompt (optional)`)}),l(B,{id:`ai-test-system`,value:f,onChange:e=>p(e.target.value),placeholder:n(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l(D,{size:`sm`,variant:k===`throwaway`?`primary`:`outline`,type:`button`,onClick:()=>{A(`throwaway`),M(null)},children:n(`ai.throwawayMode`,`Throwaway`)}),l(D,{size:`sm`,variant:k===`persistent`?`primary`:`outline`,type:`button`,onClick:()=>A(`persistent`),children:n(`ai.saveConversation`,`Save conversation`)})]}),k===`persistent`&&r(`div`,{className:`space-y-2`,children:[l(`div`,{className:`flex items-center gap-2`,children:r(D,{size:`sm`,variant:`secondary`,type:`button`,onClick:le,children:[l(se,{className:`h-3.5 w-3.5`}),n(`ai.newChat`,`New chat`)]})}),N.length>0&&l(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:N.map(e=>l(`button`,{type:`button`,onClick:()=>void ue(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover ${e.id===j?`bg-primary/10`:``}`,children:l(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.title})},e.id))})]}),l(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`ai.streamNote`,`The answer streams as the model produces it. A cold model can take a while to load — the status line says which phase it is in.`)}),W!==null&&!W.supportsVision&&l(`p`,{className:`text-[10px] text-warning`,children:n(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]}),P!==null&&l(x,{title:n(`ai.chatFailed`,`The test call failed`),message:P}),l(rt,{turns:b,live:I}),r(S,{className:`space-y-2 p-3`,children:[w!==null&&r(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-surface px-2.5 py-1.5`,children:[w.ref.kind===`snapshot`?l(g,{className:`h-3.5 w-3.5 text-foreground-subtle`}):l(z,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-foreground`,children:w.label}),l(D,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>T(null),children:l(re,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(D,{size:`sm`,variant:E===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>O(E===`snapshot`?`none`:`snapshot`),children:[l(g,{className:`h-3.5 w-3.5`}),n(`ai.attachSnapshot`,`Camera snapshot`)]}),r(D,{size:`sm`,variant:E===`track`?`primary`:`outline`,type:`button`,onClick:()=>O(E===`track`?`none`:`track`),children:[l(z,{className:`h-3.5 w-3.5`}),n(`ai.attachTrack`,`Recent track`)]})]}),E===`snapshot`&&l(ot,{onPick:e=>{T({ref:{kind:`snapshot`,deviceId:e.id},label:n(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:e.name})}),O(`none`)}}),E===`track`&&l(ct,{onPick:(e,t)=>{T({ref:{kind:`track`,trackId:e.trackId,deviceId:e.deviceId},label:n(`ai.trackOf`,`{{class}} on {{name}}`,{class:e.label??e.className,name:t})}),O(`none`)}}),r(`div`,{className:`flex items-center gap-2`,children:[l(B,{value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),K())},placeholder:n(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":n(`ai.message`,`Message`)}),G?r(D,{size:`sm`,variant:`secondary`,type:`button`,onClick:oe,children:[l(h,{className:`h-3.5 w-3.5`}),n(`ai.stop`,`Stop`)]}):r(D,{size:`sm`,type:`button`,disabled:v.trim()===``||c===``,onClick:K,children:[l(ae,{className:`h-3.5 w-3.5`}),n(`ai.send`,`Send`)]})]})]})]})}function rt({turns:e,live:t}){let{t:n}=q();return e.length===0&&t===null?l(`div`,{className:`py-12 text-center text-xs text-foreground-subtle`,children:n(`ai.chatEmpty`,`Pick a profile, optionally attach a camera snapshot or a recent track, and send a message. Nothing here is saved.`)}):l(S,{children:r(`div`,{className:`max-h-[50vh] space-y-2 overflow-y-auto p-3`,children:[e.map(e=>l(it,{turn:e},e.id)),t!==null&&r(`div`,{className:`space-y-1`,children:[t.mediaSent!==null&&l(at,{attachment:t.mediaSent}),t.text.length>0&&l(it,{turn:{id:`live`,role:`assistant`,content:t.text},streaming:!0}),r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[l(G,{className:`h-3.5 w-3.5 animate-spin`}),Ze(t.phase,t.firstTokenTimeoutMs)]})]})]})})}function it({turn:e,streaming:t=!1}){let n=e.role===`user`,i=e.failed===!0?`border-danger/40 bg-danger/10`:`border-border bg-surface`;return l(`div`,{className:`flex ${n?`justify-end`:`justify-start`}`,children:r(`div`,{className:`max-w-[85%] rounded-lg border px-3 py-2 ${n?`border-primary/40 bg-primary/10`:i}`,children:[r(`p`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:[e.content,t&&l(`span`,{className:`ml-0.5 animate-pulse text-primary`,children:`▌`})]}),e.attachment!==void 0&&l(at,{attachment:e.attachment}),e.attachmentLabel!==void 0&&r(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachmentKind===`track`?l(z,{className:`h-3 w-3`}):l(g,{className:`h-3 w-3`}),e.attachmentLabel]}),e.attachment!==void 0&&r(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachment.kind===`snapshot`?l(g,{className:`h-3 w-3`}):l(z,{className:`h-3 w-3`}),Xe(e.attachment)]}),e.model!==void 0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`${e.model} · ${String(e.outputTokens??0)} tok · ${String(e.latencyMs??0)} ms`})]})})}function at({attachment:e}){let t=Je(e);return t===null?null:l(`img`,{src:t,alt:`sent to the model`,className:`mt-1 max-h-32 rounded-md border border-border object-contain`})}function ot({onPick:e}){let{t}=q(),n=E({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?l(G,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):r.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noCameras`,`No camera found.`)}):l(`div`,{className:`grid max-h-56 grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-4`,children:r.map(t=>l(st,{device:t,onPick:e},t.id))})}function st({device:e,onPick:t}){let{src:n}=d(e.id,{width:tt});return r(`button`,{type:`button`,onClick:()=>t(e),className:`overflow-hidden rounded-md border border-border bg-surface text-left transition-colors hover:border-primary/50`,children:[l(`span`,{className:`block aspect-video w-full bg-background-elevated`,children:n!==null&&l(`img`,{src:n,alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),r(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[!e.online&&l(v,{variant:`warning`,children:`off`}),l(`span`,{className:`truncate text-[10px] text-foreground`,children:e.name})]})]})}function ct({onPick:e}){let{t}=q(),n=m(),o=E({isCamera:!0,projection:`slim`}),s=i(()=>(o.data??[]).map(e=>e.id),[o.data]),c=i(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),u=a({queryKey:[...Qe,s.length],enabled:s.length>0,queryFn:()=>n.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...s],since:Date.now()-$e,limit:et,projection:`slim`})});if(o.isLoading||u.isLoading)return l(G,{className:`h-4 w-4 animate-spin text-foreground-subtle`});let d=u.data?.tracks??[];return d.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noTracks`,`No track in the last 6 hours.`)}):l(`div`,{className:`max-h-56 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:d.map(t=>r(`button`,{type:`button`,onClick:()=>e(t,c.get(t.deviceId)??String(t.deviceId)),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover`,children:[l(z,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:t.label??t.className}),l(`span`,{className:`shrink-0 text-foreground-subtle`,children:c.get(t.deviceId)??t.deviceId}),l(`span`,{className:`shrink-0 text-foreground-subtle`,children:new Date(t.lastSeen).toLocaleTimeString()})]},t.trackId))})}n();var lt=1440*60*1e3,ut=[1,7,30,90];function dt(){let{t:e}=q(),t=m(),[n,o]=s(7),c=i(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(n-1)*lt},[n]),u=a({queryKey:ce,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),d=a({queryKey:[...pe,n],queryFn:()=>t.trpcClient.llm.getUsage.query({since:c})}),f=i(()=>{let e=new Map;for(let t of u.data??[])e.set(t.id,t.name);return e},[u.data]),p=i(()=>[{key:`day`,header:e(`ai.colDay`,`Day`),nowrap:!0,render:e=>e.day},{key:`consumer`,header:e(`ai.colConsumer`,`Consumer`),nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.consumer})},{key:`profile`,header:e(`ai.colProfile`,`Profile`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:f.get(e.profileId)??e.profileId})},{key:`calls`,header:e(`ai.colCalls`,`Calls`),align:`right`,nowrap:!0,render:e=>String(e.calls)},{key:`okErr`,header:e(`ai.colOkErr`,`OK / err`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:e.errorCalls>0?`text-danger`:void 0,children:`${String(e.okCalls)} / ${String(e.errorCalls)}`})},{key:`tokens`,header:e(`ai.colTokens`,`In / out tok`),align:`right`,nowrap:!0,render:e=>`${String(e.inputTokens)} / ${String(e.outputTokens)}`},{key:`latency`,header:e(`ai.colAvgMs`,`Avg ms`),align:`right`,nowrap:!0,render:e=>String(Math.round(e.avgLatencyMs))}],[f,e]),h=d.data??[];return r(J,{icon:T,title:e(`ai.usageTitle`,`Usage`),subtitle:e(`ai.usageSubtitle`,`Server-side rollup per day, consumer and profile — never raw call rows. Errors are counted, so a profile that always fails is visible here before a feature reports it.`),actions:l(`div`,{className:`w-40`,children:l(te,{"aria-label":e(`ai.window`,`Window`),value:String(n),options:ut.map(t=>({value:String(t),label:e(`ai.lastDays`,`Last {{days}} days`,{days:t})})),onChange:e=>o(Number(e.target.value))})}),children:[d.isError&&l(x,{title:e(`ai.usageFailed`,`Failed to read usage`),message:d.error instanceof Error?d.error.message:e(`common.error`,`Error`),onRetry:()=>void d.refetch()}),h.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noUsage`,`No AI calls in this window.`)}):l(S,{children:l(H,{columns:p,rows:h,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,mobileMode:`scroll`,maxBodyHeight:C})})]})}function ft(){let{t:e}=q();return l(`div`,{className:`flex flex-col p-4`,children:l(oe,{tabs:[{id:`profiles`,label:e(`ai.tabProfiles`,`Profiles`),icon:ie,content:l(Ne,{})},{id:`runtimes`,label:e(`ai.tabRuntimes`,`Runtimes`),icon:P,content:l(Le,{})},{id:`usage`,label:e(`ai.tabUsage`,`Usage`),icon:T,content:l(dt,{})},{id:`test`,label:e(`ai.tabTest`,`Test`),icon:ne,content:l(nt,{})}]})})}export{ft as AiProfilesPage,ft as default};
|
|
@@ -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,ht as h,mt as g,st as _}from"./player-overlays-CDJkdSOF.js";import{$t as v,Dl as y,Gt as b,Ht as x,Ot as S,Q as C,Qr as w,Qt as T,U as E,X as D,Xl as O,Zc as k,Zt as A,_ as j,_t as M,cl as N,dt as P,el as F,ft as ee,fu as te,hu as I,it as ne,jc as re,kt as L,ol as R,pt as z,sl as ie,un as ae,ut as oe,vt as se,yl as ce,yt as le}from"./src-XRPUTYTA.js";import{t as ue}from"./boxes-BkyAndMq.js";import{$t as de,Dt as fe,Et as pe,G as me,Ot as he,Tt as ge,wt as _e,yt as B}from"./src-BtYlLp9k.js";import{f as ve,s as ye}from"./index-bDP5F8a8.js";import{t as be}from"./AdminPage-CiKtOLQm.js";var xe=p(`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`}]]),Se=p(`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 Ce=6e4;function we(){let e=w({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 Te(e){let t=m();return s({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:Ce,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 Ee(e){let t=m();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:Ce,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function De(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Oe(){let e=new Set;for(let t of Object.values(me))t.capScope===`device`&&e.add(t.capName);return[...e].sort((e,t)=>e.localeCompare(t))}function ke(e){if(e===``)return[];let t=new Set;for(let[n,r]of Object.entries(me)){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 Ae(e){let t=Ee(e.deviceId);if(t.data!==void 0)return De(t.data,e.cap).find(t=>t.path===e.fieldPath)}function je({value:e,devices:t,onChange:n}){let r=Ee(e.deviceId),a=r.data??[],o=De(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(V,{children:`Device`}),d(A,{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(A,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:Me(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(A,{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 Me(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 Ne=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Pe(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 Ne}}function Fe(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 Ie(e){return Pe(e).map(e=>({value:e,label:Fe(e)}))}function Le(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 Re={triggers:[],actions:[]};function ze(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 Be(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 Ve(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function He(){return{kind:`expression`,expr:``,bindings:{}}}function Ue(e,t,n){return e.map((e,r)=>r===t?n:e)}function We(e,t){return e.filter((e,n)=>n!==t)}function Ge(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=We(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function Ke(e,t){return{...e,triggers:[...t]}}function qe(e,t){return{...e,actions:[...t]}}var Je=`deviceId`,Ye=`$trigger`,Xe=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function Ze({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(v,{variant:`default`,children:a+1}),i(`label`,{className:`w-40`,children:[d(V,{children:`Step`}),d(A,{value:r.kind,onChange:t=>n(Ue(e,a,Be(Qe(t.target.value)))),options:Xe.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(T,{variant:`ghost`,disabled:a===0,onClick:()=>n(Ge(e,a,a-1)),title:`Run this step earlier`,children:d(te,{className:`h-3.5 w-3.5`})}),d(T,{variant:`ghost`,disabled:a===e.length-1,onClick:()=>n(Ge(e,a,a+1)),title:`Run this step later`,children:d(I,{className:`h-3.5 w-3.5`})}),d(T,{variant:`ghost`,onClick:()=>n(We(e,a)),title:`Remove this step`,children:d(_,{className:`h-3.5 w-3.5`})})]})]}),r.kind===`wait`&&i(`label`,{className:`block w-32`,children:[d(V,{children:`Seconds`}),d(L,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n(Ue(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(Ue(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($e,{action:r,devices:t,onChange:t=>n(Ue(e,a,t))})]},`${r.kind}-${String(a)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(T,{variant:`outline`,onClick:()=>n([...e,Be(`cap`)]),children:[d(R,{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 Qe(e){return Xe.find(t=>t.value===e)?.value??`cap`}function $e({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,a=typeof e.deviceId==`number`?e.deviceId:0,o=Te(a),s=r?Oe():o.data??[],c=ke(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(A,{value:r?Ye:String(a),onChange:t=>n({...e,deviceId:t.target.value===Ye?{$var:Je}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:Ye,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(A,{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(A,{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(L,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(et(e,t.target.value))})]})]})}function et(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 tt({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(A,{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(A,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(L,{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(L,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function nt({value:e,field:t,onChange:n}){return d(L,{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 rt(e){return typeof e==`object`}function it(e){return rt(e)?e[0]??``:e}function at(e){return rt(e)?e:typeof e==`boolean`?[]:[e]}function ot({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Ae(r),o=Ie(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=st(t,o);n({...e,operator:r,value:r===`in`?at(e.value):it(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(je,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(V,{children:`Comparison`}),d(A,{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(nt,{value:at(e.value),field:a,onChange:t=>n({...e,value:t})}):d(tt,{value:it(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function st(e,t){return t.find(t=>t.value===e)?.value??`eq`}var ct={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function lt({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(L,{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(ut,{alias:n,source:r,devices:t,onRename:t=>a(gt(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(_t(e.bindings,n))},n)),i(T,{variant:`ghost`,onClick:()=>a({...e.bindings,[ht(e.bindings)]:ct}),children:[d(R,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function ut({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:pt(n,ft(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(L,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(V,{children:`Reads`}),d(A,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:ct),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(L,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:dt(e.target.value)})})]}):d(je,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:mt(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(T,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(_,{className:`h-3.5 w-3.5`})})]})}function dt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function ft(e){return e.kind===`global`?e.sourceStableId:``}function pt(e,t){return e.find(e=>e.stableId===t)?.id??0}function mt(e,t){return e.find(e=>e.id===t)?.stableId??``}function ht(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 gt(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function _t(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 vt(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 yt(e){return vt(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 bt(e){return e===null?null:he({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function xt(e){let t=U(e);return{depth:t.children.length===0?0:pe(t),leaves:t.children.length===0?0:fe(t),depthLimit:3,leafLimit:32}}function St(e,t){let n=bt(t);return n===null?{ok:!0,recipe:vt(e,t)}:{ok:!1,reason:n}}function Ct(e,t){let n=U(e);return St(e,{kind:n.kind,children:[...n.children,t]})}function wt(e,t,n){return vt(e,G(U(e),t,()=>n))}function Tt(e,t){return vt(e,G(U(e),t,()=>null))}function Et(e,t,n){return vt(e,G(U(e),t,e=>H(e)?{kind:n,children:e.children}:e))}function Dt(e,t){return W(U(e),t)===null?{ok:!1,reason:`that row is no longer there`}:St(e,G(U(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Ot(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 kt(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=Ot(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 St(e,G(i,r.path,()=>d))}function At(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 St(e,G(n,t,()=>r.child));if(!H(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Ot(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 St(e,G(n,i.path,()=>o))}r();var jt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function Mt(e){return e.join(`/`)}function Nt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Pt({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=U(e),f=xt(e),p=o(()=>r.map(Nt),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=kt(e,p,`all`),g=kt(e,p,`any`),_=p.length===1?Dt(e,p[0]??[]):{ok:!1,reason:`select exactly one row to negate`},y={devices:t,selected:new Set(r),onToggleSelect:e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(wt(e,t,r)),onRemove:t=>{a([]),n(Tt(e,t))},onSetKind:(t,r)=>n(Et(e,t,r)),onUngroup:t=>m(At(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(v,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(A,{value:u.kind,onChange:t=>n(Et(e,[],Ft(t.target.value))),options:jt})}),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(It,{container:u,path:[],handlers:y}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(T,{variant:`outline`,onClick:()=>m(Ct(e,Ve())),title:`Compare one device field to a value`,children:[d(R,{className:`h-4 w-4`}),` Condition`]}),i(T,{variant:`outline`,onClick:()=>m(Ct(e,He())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(xe,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(T,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(T,{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(T,{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 Ft(e){return e===`any`?`any`:`all`}function It({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(Lt,{node:e,path:[...t,r],handlers:n},Mt([...t,r])))})}function Lt({node:e,path:t,handlers:n}){let r=Mt(t),a=d(S,{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(A,{value:e.kind,onChange:e=>n.onSetKind(t,Ft(e.target.value)),options:jt})}),i(T,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(Se,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(T,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:d(_,{className:`h-3.5 w-3.5`})})]}),d(`div`,{className:`pl-4`,children:d(It,{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(v,{variant:`warning`,children:`NOT`}),i(T,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(Se,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(Lt,{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(ot,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(lt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(T,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(_,{className:`h-3.5 w-3.5`})})]})}r();function Rt({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=ae(),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(T,{variant:`ghost`,onClick:()=>s(!o),children:[d(o?h:g,{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(T,{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(ve,{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(ne,{maxHeight:420,children:e})})]})}var zt=[`device-state`,`device-event`,`schedule`,`manual`],Bt=Object.values(de).sort((e,t)=>e.localeCompare(t));function Vt({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(Ht,{trigger:r,devices:t,position:i,onChange:t=>n(Ue(e,i,t)),onRemove:()=>n(We(e,i))},`${r.kind}-${String(i)}`)),i(T,{variant:`outline`,onClick:()=>n([...e,ze(`device-state`)]),title:`Add another way this automation can start`,children:[d(R,{className:`h-4 w-4`}),` Trigger`]})]})}function Ht({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(v,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(V,{children:`Trigger`}),d(A,{value:e.kind,onChange:e=>r(ze(Ut(e.target.value))),options:zt.map(e=>({value:e,label:Le(e)}))})]}),d(T,{variant:`ghost`,onClick:a,title:`Remove this trigger`,children:d(_,{className:`h-4 w-4`})})]}),i(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&d(Wt,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(Kt,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(V,{children:`Cron expression`}),d(L,{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 Ut(e){return zt.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 Wt({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Ae(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(je,{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(S,{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(tt,{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(S,{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(L,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(K(r,{...o,forMs:Gt(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(V,{children:`Debounce (s)`}),d(L,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(K(r,{...o,debounceMs:Gt(e.target.value)}))})]})]})}function Gt(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function Kt({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(A,{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…`},...Bt.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(V,{children:`From device`}),d(A,{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 qt=`hub`;function Jt({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(()=>yt(t)),[g,_]=l(!1),y=we(),b=he(m),S=o(()=>Xt(m),[m]),C=o(()=>Zt(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),w=f.trim()===``,E=w||b!==null||S!==null||C.code===null;return d(x,{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(v,{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(L,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(Yt,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(Vt,{triggers:m.triggers,devices:y,onChange:e=>h(Ke(m,e))})}),d(Yt,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Pt,{recipe:m,devices:y,onChange:h})}),d(Yt,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(Ze,{actions:m.actions,devices:y,onChange:e=>h(qe(m,e))})}),d(Rt,{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(D,{addonId:B(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),b!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),b===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(T,{onClick:()=>{C.code!==null&&s({name:f.trim(),code:C.code,enabled:e?.enabled??!0,placement:qt})},disabled:n||E,children:[n&&d(ce,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(T,{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(k,{className:`h-4 w-4`}),` Logs`]}),d(T,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),w&&d(v,{variant:`warning`,children:`Name required`})]})]})})}function Yt({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 Xt(e){let t=ge.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 Zt(e,t){try{return{code:_e({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 Qt(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function $t(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function en(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 tn(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 nn({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=E(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(v,{variant:Qt(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(T,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(T,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(T,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(N,{className:`h-4 w-4`})}),i(M,{children:[d(le,{children:d(T,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(ie,{className:`h-4 w-4`})})}),d(se,{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(T,{variant:`ghost`,onClick:c,title:`Logs`,children:d(k,{className:`h-4 w-4`})}),d(T,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(T,{variant:`ghost`,onClick:l,title:`Delete`,children:d(_,{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(D,{addonId:B(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function rn({onCreate:e}){return d(x,{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(T,{onClick:e,children:`New automation`})]})})}var an=`const AUTOMATION_RECIPE =`,on=`// 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 sn(e){return e.includes(an)}function cn(e){let t=e.indexOf(an);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 ln(e){let t=cn(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=ge.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 un(e){let t=cn(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)}${on}${e.slice(i)}`}r();var dn=[`coreBlocks`,`list`],fn=5e3;function J(e){return e instanceof Error?e.message:String(e)}function pn({onOpenScripts:e}){let t=m(),[n,r]=l({mode:`closed`}),[a,o]=l(null),[c,f]=l(null),p=s({queryKey:dn,refetchInterval:fn,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}),S=u({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:un(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)}}),C=p.data,w=en((C??[]).filter(e=>sn(e.code))),E=C!==void 0&&w.length===0,D=n.mode===`edit`&&n.block!==null?$t(w,n.block):null,O=D===null?null:ln(D.code),k=g.error===null?_.error===null?S.error===null?null:J(S.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:C===void 0?``:tn(w)}),i(T,{onClick:()=>r({mode:`edit`,block:null}),children:[d(R,{className:`h-4 w-4`}),` New automation`]})]}),p.error!=null&&d(b,{title:`Could not read the automations`,message:J(p.error),onRetry:h}),n.mode===`edit`&&d(Jt,{existing:D,initialRecipe:O!==null&&O.ok?O.recipe:Re,saving:g.isPending||_.isPending,saveError:k,ejecting:S.isPending,onSave:e=>{D===null?g.mutate(e):_.mutate({blockId:D.id,block:e})},onEject:()=>{D!==null&&S.mutate(D)},onCancel:()=>{g.reset(),_.reset(),S.reset(),r({mode:`closed`})}},D?.id??`new`),E&&d(rn,{onCreate:()=>r({mode:`edit`,block:null})}),w.length>0&&d(x,{children:d(`ul`,{className:`divide-y divide-border`,children:w.map(e=>{let t=ln(e.code);return d(nn,{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(b,{message:J(v.error)}),y.error!=null&&d(b,{message:J(y.error)})]})}function mn({onOpenScripts:e}){return d(x,{children:i(`div`,{className:`max-w-2xl space-y-3 p-6`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(ue,{className:`h-5 w-5 text-foreground-subtle`}),d(`h3`,{className:`font-medium`,children:`Composed devices are not built yet`})]}),i(`p`,{className:`text-sm text-foreground-subtle`,children:[`A composed device will be a real device — its own row, its own name, its own on/off — with its state `,d(`strong`,{children:`derived from other devices`}),` and, optionally, methods that forward to them. Because it is a device row and not an overlay, it reaches HomeKit, Alexa, Home Assistant and the notification rules with nothing having to learn about it.`]}),i(`p`,{className:`text-sm text-foreground-subtle`,children:[`Nothing is hidden behind this section: no device can be declared this way yet, so there is no list to show and no form that would work. A `,d(`strong`,{children:`script`}),` is the surface that exists today — it runs in its own supervised process with the full addon context, which is the same context a composed device will be built on.`]}),d(T,{variant:`outline`,onClick:e,children:`Write a script instead`})]})})}function hn(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 gn(e){if(Array.isArray(e))return e}function _n(e,t,n){return(t=En(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function vn(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 yn(){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 bn(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 xn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?bn(Object(n),!0).forEach(function(t){_n(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):bn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Sn(e,t){if(e==null)return{};var n,r,i=Cn(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 Cn(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 wn(e,t){return gn(e)||vn(e,t)||Dn(e,t)||yn()}function Tn(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 En(e){var t=Tn(e,`string`);return typeof t==`symbol`?t:t+``}function Dn(e,t){if(e){if(typeof e==`string`)return hn(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)?hn(e,t):void 0}}function On(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function kn(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 An(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?kn(Object(n),!0).forEach(function(t){On(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):kn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function jn(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function Mn(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 Nn(e){return{}.toString.call(e).includes(`Object`)}function Pn(e){return!Object.keys(e).length}function Fn(e){return typeof e==`function`}function In(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ln(e,t){return Nn(t)||Y(`changeType`),Object.keys(t).some(function(t){return!In(e,t)})&&Y(`changeField`),t}function Rn(e){Fn(e)||Y(`selectorType`)}function zn(e){Fn(e)||Nn(e)||Y(`handlerType`),Nn(e)&&Object.values(e).some(function(e){return!Fn(e)})&&Y(`handlersType`)}function Bn(e){e||Y(`initialIsRequired`),Nn(e)||Y(`initialType`),Pn(e)&&Y(`initialContent`)}function Vn(e,t){throw Error(e[t]||e.default)}var Y=Mn(Vn)({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"}),Hn={changes:Ln,selector:Rn,handler:zn,initial:Bn};function Un(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Hn.initial(e),Hn.handler(t);var n={current:e},r=Mn(Kn)(n,t),i=Mn(Gn)(n),a=Mn(Hn.changes)(e),o=Mn(Wn)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Hn.selector(e),e(n.current)}function c(e){jn(r,i,a,o)(e)}return[s,c]}function Wn(e,t){return Fn(t)?t(e.current):t}function Gn(e,t){return e.current=An(An({},e.current),t),t}function Kn(e,t,n){return Fn(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var qn={create:Un},Jn={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Yn(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 Xn(e){return{}.toString.call(e).includes(`Object`)}function Zn(e){return e||tr(`configIsRequired`),Xn(e)||tr(`configType`),e.urls?(Qn(),{paths:{vs:e.urls.monacoBase}}):e}function Qn(){console.warn(er.deprecation)}function $n(e,t){throw Error(e[t]||e.default)}var er={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
|
-
`},tr=Yn($n)(er),nr={config:Zn},rr=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function ir(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],ir(e[n],t[n]))}),xn(xn({},e),t)}var ar={type:`cancelation`,msg:`operation is manually canceled`};function or(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(ar):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var sr=[`monaco`],cr=wn(qn.create({config:Jn,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),lr=cr[0],ur=cr[1];function dr(e){var t=nr.config(e),n=t.monaco,r=Sn(t,sr);ur(function(e){return{config:ir(e.config,r),monaco:n}})}function fr(){var e=lr(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(ur({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),or(yr);if(window.monaco&&window.monaco.editor)return _r(window.monaco),e.resolve(window.monaco),or(yr);rr(pr,hr)(gr)}return or(yr)}function pr(e){return document.body.appendChild(e)}function mr(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function hr(e){var t=lr(function(e){return{config:e.config,reject:e.reject}}),n=mr(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function gr(){var e=lr(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;_r(n),e.resolve(n)},function(t){e.reject(t)})}function _r(e){lr().monaco||ur({monaco:e})}function vr(){return lr(function(e){return e.monaco})}var yr=new Promise(function(e,t){return ur({resolve:e,reject:t})}),br={config:dr,init:fr,__getMonacoInstance:vr};r();var xr={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},Sr={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function Cr({children:e}){return a.createElement(`div`,{style:Sr.container},e)}var wr=Cr;function Tr({width:e,height:t,isEditorReady:n,loading:r,_ref:i,className:o,wrapperProps:s}){return a.createElement(`section`,{style:{...xr.wrapper,width:e,height:t},...s},!n&&a.createElement(wr,null,r),a.createElement(`div`,{ref:i,style:{...xr.fullWidth,...!n&&xr.hide},className:o}))}var Er=n(Tr);function Dr(e){f(e,[])}var Or=Dr;function kr(e,n,r=!0){let i=t(!0);f(i.current||!r?()=>{i.current=!1}:e,n)}var X=kr;function Z(){}function Q(e,t,n,r){return Ar(e,r)||jr(e,t,n,r)}function Ar(e,t){return e.editor.getModel(Mr(e,t))}function jr(e,t,n,r){return e.editor.createModel(t,n,r?Mr(e,r):void 0)}function Mr(e,t){return e.Uri.parse(t)}function Nr({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=Z,onMount:S=Z}){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);Or(()=>{let e=br.init();return e.then(e=>(O.current=e)&&E(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>D.current?F():e.cancel()}),X(()=>{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),X(()=>{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),X(()=>{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),X(()=>{D.current?.getModel()?.original.setValue(n||``)},[n],C),X(()=>{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),X(()=>{O.current?.editor.setTheme(m)},[m],C),X(()=>{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]),P=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&&P()},[T,C,P]);function F(){let e=D.current?.getModel();d||e?.original?.dispose(),p||e?.modified?.dispose(),D.current?.dispose()}return a.createElement(Er,{width:v,height:_,isEditorReady:C,loading:h,_ref:k,className:y,wrapperProps:b})}n(Nr);function Pr(e){let n=t();return f(()=>{n.current=e},[e]),n.current}var Fr=Pr,Ir=new Map;function Lr({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=Z,onMount:C=Z,onChange:w,onValidate:T=Z}){let[E,D]=l(!1),[O,k]=l(!0),A=t(null),j=t(null),M=t(null),N=t(C),P=t(S),F=t(),ee=t(o),te=Fr(c),I=t(!1),ne=t(!1);Or(()=>{let e=br.init();return e.then(e=>(A.current=e)&&k(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>j.current?L():e.cancel()}),X(()=>{let e=Q(A.current,n||o||``,r||s||``,c||i||``);e!==j.current?.getModel()&&(g&&Ir.set(te,j.current?.saveViewState()),j.current?.setModel(e),g&&j.current?.restoreViewState(Ir.get(c)))},[c],E),X(()=>{j.current?.updateOptions(m)},[m],E),X(()=>{!j.current||o===void 0||(j.current.getOption(A.current.editor.EditorOption.readOnly)?j.current.setValue(o):o!==j.current.getValue()&&(ne.current=!0,j.current.executeEdits(``,[{range:j.current.getModel().getFullModelRange(),text:o,forceMoveMarkers:!0}]),j.current.pushUndoStop(),ne.current=!1))},[o],E),X(()=>{let e=j.current?.getModel();e&&s&&A.current?.editor.setModelLanguage(e,s)},[s],E),X(()=>{d!==void 0&&j.current?.revealLine(d)},[d],E),X(()=>{A.current?.editor.setTheme(u)},[u],E);let re=e(()=>{if(!(!M.current||!A.current)&&!I.current){P.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(Ir.get(e)),A.current.editor.setTheme(u),d!==void 0&&j.current.revealLine(d),D(!0),I.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&&re()},[O,E,re]),ee.current=o,f(()=>{E&&w&&(F.current?.dispose(),F.current=j.current?.onDidChangeModelContent(e=>{ne.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 L(){F.current?.dispose(),_?g&&Ir.set(c,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return a.createElement(Er,{width:v,height:y,isEditorReady:E,loading:p,_ref:M,className:b,wrapperProps:x})}var Rr=n(Lr);r();var zr={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function Br(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...zr}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function Vr({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,Br(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(Rr,{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 Hr(e){return e.some(e=>e.severity>=8)}var Ur=`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 Wr({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 Gr=`hub`;function Kr({existing:e,typeDefs:t,typeDefsLoading:n,saving:r,saveError:a,restarting:s,restartError:f,onRestart:p,onSave:h,onCancel:g}){let _=m(),{resolvedMode:y}=C(),[b,S]=l(e?.name??``),[w,E]=l(e?.code??Ur),[A,M]=l(e?.placement??Gr),[N,P]=l(e?.integrationId??``),[ee,te]=l([]),[I,ne]=l(!1),R=u({mutationFn:e=>_.trpcClient.coreBlocks.compile.mutate({code:e})}),z=o(()=>ee.filter(e=>e.severity>=8),[ee]),ie=Hr(ee),ae=b.trim()===``,oe=e===null||w!==e.code||b.trim()!==e.name||A!==e.placement||(N.trim()===``?void 0:N.trim())!==e.integrationId,se=()=>{R.reset(),h({name:b.trim(),code:w,enabled:e?.enabled??!0,placement:A,...N.trim()===``?{}:{integrationId:N.trim()}})},le=e===null?null:q(e),ue=Wr({existing:e,dirty:oe,saving:r,restarting:s});return d(x,{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}`}),le!==null&&d(v,{variant:Qt(le.tone),children:le.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(L,{className:`mt-1`,value:b,onChange:e=>S(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(L,{className:`mt-1`,value:N,onChange:e=>P(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),i(`div`,{children:[d(j,{selectedNodeId:A,onSelect:M,label:`Runs on`,alwaysShow:!0}),A!==Gr&&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:I?`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(Vr,{value:w,onChange:E,extraLibs:t?.libs??[],onDiagnostics:te,dark:y===`dark`,heightPx:420})}),I&&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(D,{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.`}),z.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:[z.length,` error`,z.length===1?``:`s`,` — the block cannot be saved.`]}),z.slice(0,5).map(e=>i(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),z.length>5&&i(`p`,{className:`text-foreground-subtle`,children:[`…and `,z.length-5,` more.`]})]}),R.data!==void 0&&(R.data.ok?i(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[d(O,{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:[R.data.line===void 0?``:`line ${String(R.data.line)}: `,R.data.error??`the code does not compile`]})),R.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: `,qr(R.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(T,{variant:`outline`,onClick:()=>R.mutate(w),disabled:R.isPending||r,title:`Type-check on the node without saving`,children:[R.isPending&&d(ce,{className:`h-4 w-4 animate-spin`}),` Compile`]}),i(T,{onClick:se,disabled:r||ie||ae,children:[r&&d(ce,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(T,{variant:`outline`,onClick:()=>p?.(),disabled:ue!==null||p===void 0,title:ue??`Stop the process and let the supervisor bring it back`,children:[s?d(F,{className:`h-4 w-4 animate-spin`}):d(F,{className:`h-4 w-4`}),` `,`Restart`]}),i(T,{variant:`ghost`,onClick:()=>ne(!I),title:`Show this script's process logs`,children:[d(k,{className:`h-4 w-4`}),` Logs `,I?`⇤`:`⇄`]}),d(T,{variant:`ghost`,onClick:g,disabled:r,children:`Close`}),i(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,z.length,oe&&e!==null?` · unsaved changes`:``]}),ae&&d(v,{variant:`warning`,children:`Name required`})]})]})})}function qr(e){return e instanceof Error?e.message:String(e)}r();var Jr=[`coreBlocks`,`list`],Yr=[`coreBlocks`,`getTypeDefs`],Xr=5e3;function $(e){return e instanceof Error?e.message:String(e)}function Zr({initialBlockId:e}={}){let n=m(),[r,a]=l({mode:`closed`}),[o,c]=l(null),[p,h]=l(null),g=s({queryKey:Jr,refetchInterval:Xr,queryFn:async()=>(await n.trpcClient.coreBlocks.list.query({})).blocks}),_=s({queryKey:Yr,enabled:r.mode===`edit`,staleTime:1/0,gcTime:1/0,queryFn:()=>n.trpcClient.coreBlocks.getTypeDefs.query({})}),v=()=>{g.refetch()},y=t(null),S=g.data;f(()=>{if(e===void 0||y.current===e)return;let t=S?.find(t=>t.id===e);t!==void 0&&(y.current=e,a({mode:`edit`,block:t}))},[e,S]);let C=u({mutationFn:e=>n.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{a({mode:`edit`,block:e.block}),v()}}),w=u({mutationFn:e=>n.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{a({mode:`edit`,block:e.block}),v()}}),E=u({mutationFn:e=>n.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{c(null),v()}}),D=u({mutationFn:e=>n.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:v}),O=u({mutationFn:e=>n.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:v}),k=en(g.data??[]),A=g.data!==void 0&&k.length===0,j=C.isPending||w.isPending,M=C.error===null?w.error===null?null:$(w.error):$(C.error),N=r.mode===`edit`&&r.block!==null?$t(k,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?``:tn(k)}),i(T,{onClick:()=>a({mode:`edit`,block:null}),children:[d(R,{className:`h-4 w-4`}),` New script`]})]}),g.error!=null&&d(b,{title:`Could not read the scripts`,message:$(g.error),onRetry:v}),r.mode===`edit`&&d(Kr,{existing:N,typeDefs:_.data,typeDefsLoading:_.isLoading,saving:j,saveError:M,restarting:O.isPending,restartError:O.error===null?null:$(O.error),onRestart:N===null?void 0:()=>O.mutate(N.id),onSave:e=>{let t=N;t===null?C.mutate(e):w.mutate({blockId:t.id,block:e})},onCancel:()=>{C.reset(),w.reset(),O.reset(),a({mode:`closed`})}}),A&&d(x,{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.`})]})}),k.length>0&&d(x,{children:d(`ul`,{className:`divide-y divide-border`,children:k.map(e=>d(Qr,{block:e,busy:D.isPending||E.isPending,restarting:O.isPending&&O.variables===e.id,confirming:o===e.id,logsOpen:p===e.id,onToggle:t=>D.mutate({blockId:e.id,enabled:t}),onRestart:()=>O.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:()=>E.mutate(e.id)},e.id))})}),E.error!=null&&d(b,{message:$(E.error)}),D.error!=null&&d(b,{message:$(D.error)}),O.error!=null&&d(b,{message:$(O.error)})]})}function Qr({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=E(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(v,{variant:Qt(m.tone),children:m.label}),d(v,{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(T,{variant:`danger`,onClick:p,disabled:t,children:`Delete`}),d(T,{variant:`ghost`,onClick:f,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(T,{variant:`ghost`,onClick:l,title:`Edit`,children:d(N,{className:`h-4 w-4`})}),d(T,{variant:`ghost`,onClick:s,disabled:t||n||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:d(F,{className:`h-4 w-4${n?` animate-spin`:``}`})}),d(T,{variant:`ghost`,onClick:c,title:`Logs`,children:d(k,{className:`h-4 w-4`})}),d(T,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(T,{variant:`ghost`,onClick:u,title:`Delete`,children:d(_,{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(D,{addonId:B(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var $r=[`automations`,`scripts`,`custom-device`];function ei(e){return e!==null&&$r.some(t=>t===e)}function ti(){let[e,t]=ye(),n=e.get(`tab`),r=ei(n)?n:`automations`,a=e=>{t(t=>{let n=new URLSearchParams(t);return n.set(`tab`,e),n.delete(`block`),n},{replace:!0})};return d(be,{icon:y,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,children:i(oe,{value:r,onValueChange:a,children:[i(ee,{children:[d(z,{value:`automations`,children:`Automations`}),d(z,{value:`scripts`,children:`Scripts`}),d(z,{value:`custom-device`,children:`Custom Device`})]}),d(P,{value:`automations`,children:d(pn,{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(P,{value:`scripts`,children:d(Zr,{initialBlockId:e.get(`block`)??void 0})}),d(P,{value:`custom-device`,children:d(mn,{onOpenScripts:()=>a(`scripts`)})})]})})}export{ti as BuildPage};
|