@camstack/addon-admin-ui 1.2.246 → 1.2.248
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-C8r7lcPE.js → AddonCollectionPage-CCSWOYHb.js} +1 -1
- package/dist/assets/Addons-BrTxHZqL.js +1 -0
- package/dist/assets/{AdminTabs-CwIF_SRE.js → AdminTabs-B3yEsEkm.js} +1 -1
- package/dist/assets/AiProfiles-DnwEixy6.js +3 -0
- package/dist/assets/{BrokerForm-SNBruNI8.js → BrokerForm-8Z5frwS6.js} +1 -1
- package/dist/assets/Build-BJ4It2E7.js +32 -0
- package/dist/assets/{Capabilities-BF24isfh.js → Capabilities-CWBpijhn.js} +1 -1
- package/dist/assets/{CapabilityBadges-D_MO92Kt.js → CapabilityBadges-j-1sknmV.js} +1 -1
- package/dist/assets/Cluster-BsFVtcZw.js +11 -0
- package/dist/assets/Data-DmU6Vgo6.js +1 -0
- package/dist/assets/DetectionIntelligence-j5lsEGYk.js +1 -0
- package/dist/assets/{DeviceAggregateSection-Cm60EtBE.js → DeviceAggregateSection-_lyVm1FD.js} +1 -1
- package/dist/assets/DeviceDetail-kBq86xPk.js +2 -0
- package/dist/assets/{Devices-C3WFOtgx.js → Devices-4oS505Xf.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-D416EYpW.js → EmbedPlayerPage-CIHx1htX.js} +1 -1
- package/dist/assets/Events-CE8BgV-M.js +1 -0
- package/dist/assets/{FormBuilder-BpHnOcVm.js → FormBuilder-BMhbeJ_c.js} +1 -1
- package/dist/assets/Identity-BqRM7sII.js +1 -0
- package/dist/assets/IntegrationDetail-DEw4uCOK.js +1 -0
- package/dist/assets/{Integrations-BVeTqaEx.js → Integrations-CjlcmWeW.js} +1 -1
- package/dist/assets/Integrations-fRw4lFvJ.js +1 -0
- package/dist/assets/Locations-CeDPDRgM.js +1 -0
- package/dist/assets/{Logs-T7NkTWYq.js → Logs-CelHQlP5.js} +1 -1
- package/dist/assets/{MotionZonesSettings-DL7MujfS.js → MotionZonesSettings-DnKj27kb.js} +1 -1
- package/dist/assets/{MyAccess-BTC-2gS3.js → MyAccess-D3M-BGfI.js} +1 -1
- package/dist/assets/Network-Dd8L3Q9M.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-B2mruGGB.js → NodeAddonsSettingsPanel-B7cFUvqA.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-D9tZGgQJ.js → NodeInferenceDevices-Dlny-Q8F.js} +1 -1
- package/dist/assets/Notifications-XTXAk--T.js +1 -0
- package/dist/assets/Pipeline-D-x_GQDk.js +1 -0
- package/dist/assets/{Plates-B6ISp5iS.js → Plates-Z-CArlgU.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-BgLqDbbn.js → PrivacyMaskSettings-BzEReq6F.js} +1 -1
- package/dist/assets/{ProviderIcon-BdgRLv19.js → ProviderIcon-6Lz8Sl94.js} +1 -1
- package/dist/assets/Recordings-DV6KTVtN.js +1 -0
- package/dist/assets/{ScanNetworkModal-cS22a5_B.js → ScanNetworkModal-CZnSSWBj.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DIwy6aUu.js → SceneMonitorEditor-BzYvGfOg.js} +1 -1
- package/dist/assets/{Scenes-XxUDipyp.js → Scenes-CfFSX5WM.js} +1 -1
- package/dist/assets/{Settings-CeDJ6XdC.js → Settings-DuRQrhrD.js} +1 -1
- package/dist/assets/{Showroom-B01dDDdq.js → Showroom-DRKHGc43.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-DAiWJOe4.js → StorageLocationsPanel-DauEqgPR.js} +1 -1
- package/dist/assets/{Terminal-D9S6a6oI.js → Terminal-CNZVAhPn.js} +5 -5
- package/dist/assets/{Viewer-IoTcf-Ab.js → Viewer-QlTgxiye.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-UH0SZbxV.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CXjuykuY.js} +1 -1
- package/dist/assets/{archive-CRwkyU0l.js → archive-cSxKZlr8.js} +1 -1
- package/dist/assets/{authed-media-BL04dE4A.js → authed-media-DU4od2bc.js} +1 -1
- package/dist/assets/{bell-off-Ww_cVn2q.js → bell-off-CVoBimV-.js} +1 -1
- package/dist/assets/{boxes-wlW-4tW0.js → boxes-_kGLZsPc.js} +1 -1
- package/dist/assets/circle-slash-DoQc9kEg.js +1 -0
- package/dist/assets/{debounced-invalidate-SALyi3a9.js → debounced-invalidate-VNgBC9kY.js} +1 -1
- package/dist/assets/dist-KBn-d78g.js +349 -0
- package/dist/assets/{dist-CVKl4Cca.js → dist-tB059TlK.js} +1 -1
- package/dist/assets/{face-bbox-SP1tGqfN.js → face-bbox-CaYCVQDn.js} +1 -1
- package/dist/assets/{hard-drive-download-BacJDpjZ.js → hard-drive-download-RcMhGbcg.js} +1 -1
- package/dist/assets/{hostInit-DW13Ptnl.js → hostInit-Dk-h3oh3.js} +1 -1
- package/dist/assets/index-DS5p-Knt.js +4 -0
- package/dist/assets/{key-round-DAh7CGZY.js → key-round-VJcBulI5.js} +1 -1
- package/dist/assets/{layers-CpGRPrTo.js → layers-BgohK_Iy.js} +1 -1
- package/dist/assets/{location-owned-usage-BgD32Imy.js → location-owned-usage-CKx5nWbA.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-50b716db.js → mf-entry-bootstrap-0-6ec38dcf.js} +2 -2
- package/dist/assets/{player-overlays-CnN4y6rz.js → player-overlays-CtMMv0sv.js} +1 -1
- package/dist/assets/remoteEntry-uX4q2Nj1.js +1 -0
- package/dist/assets/{send-DD2HpdhT.js → send-2LIk4RRU.js} +1 -1
- package/dist/assets/{settings-2-DUuf_QUn.js → settings-2-B_ZmTkQ5.js} +1 -1
- package/dist/assets/{square-check-big-BVX5OkWn.js → square-check-big-YKhMS3Tb.js} +1 -1
- package/dist/assets/src-C8qpiQvV.js +349 -0
- package/dist/assets/{src-B1ko2zFV.js → src-iA6sUV3v.js} +17 -17
- package/dist/assets/{use-scenes-feed-llWRf19G.js → use-scenes-feed-ZFnXCMhr.js} +1 -1
- package/dist/assets/{use-stationary-objects-Btid4hkI.js → use-stationary-objects-TZtRichc.js} +1 -1
- package/dist/assets/useEventInvalidation-RrLino_T.js +1 -0
- package/dist/assets/{useNodeUrlSelection-Bi7c3aCd.js → useNodeUrlSelection-B_GgUF8l.js} +1 -1
- package/dist/assets/user-round-BBeRwdyO.js +1 -0
- package/dist/assets/{video-D9hdj6wj.js → video-CtttCzbi.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CQBu7s1n.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D2ubyVSA.js} +2 -2
- package/dist/index.html +5 -5
- package/dist/server/addon.js +273 -18
- package/package.json +1 -1
- package/dist/assets/Addons-A6_scXbJ.js +0 -1
- package/dist/assets/AiProfiles-CMDvTohT.js +0 -3
- package/dist/assets/Build-COH74HQu.js +0 -32
- package/dist/assets/Cluster-lx-711zl.js +0 -11
- package/dist/assets/Data-CsVP8Iig.js +0 -1
- package/dist/assets/DetectionIntelligence-CtvfDxjJ.js +0 -1
- package/dist/assets/DeviceDetail-DoknxiP5.js +0 -2
- package/dist/assets/Events-Ch3Dl7Tt.js +0 -1
- package/dist/assets/Identity-Cxyjw8U1.js +0 -1
- package/dist/assets/IntegrationDetail-7_968zY2.js +0 -1
- package/dist/assets/Integrations-K7x10USO.js +0 -1
- package/dist/assets/Locations-D0rcUwPa.js +0 -1
- package/dist/assets/Network-Dl6OgvAz.js +0 -1
- package/dist/assets/Notifications--Rrs71w5.js +0 -1
- package/dist/assets/Pipeline-CMraPbUh.js +0 -1
- package/dist/assets/Recordings-eflFL-2V.js +0 -1
- package/dist/assets/circle-slash-CCKcICx3.js +0 -1
- package/dist/assets/dist-BZagffTo.js +0 -349
- package/dist/assets/index-Bj6ZEbIP.js +0 -4
- package/dist/assets/remoteEntry-BRfYFR-d.js +0 -1
- package/dist/assets/src-DoVhwUVA.js +0 -349
- package/dist/assets/useEventInvalidation-CMIiFTJL.js +0 -1
- package/dist/assets/user-round-qAdsl7ST.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",
|
|
@@ -24250,22 +24315,40 @@ DeviceType.Camera, method(object({
|
|
|
24250
24315
|
limit: number().int().positive().optional(),
|
|
24251
24316
|
/**
|
|
24252
24317
|
* WHICH provider to ask — the `addonId` a {@link ClipSourceSchema} row
|
|
24253
|
-
* carries, never a source id and never a list.
|
|
24254
|
-
*
|
|
24255
|
-
*
|
|
24256
|
-
*
|
|
24257
|
-
*
|
|
24258
|
-
*
|
|
24259
|
-
*
|
|
24318
|
+
* carries, never a source id and never a list. **Required** (D554 amended).
|
|
24319
|
+
*
|
|
24320
|
+
* A provider the device is not bound to is refused by name rather than
|
|
24321
|
+
* answered by another one (D552's `rejectUnresolvedAddonPin` rule).
|
|
24322
|
+
*
|
|
24323
|
+
* It was optional, documented as "absent means the device's BOUND
|
|
24324
|
+
* provider, which is CamStack on every camera". No code implemented
|
|
24325
|
+
* that. Measured on the live hub 2026-09-20 — device 592, bound to
|
|
24326
|
+
* `recorder` AND `provider-reolink` — a bare call with `limit: 3`
|
|
24327
|
+
* answered SIX rows, three from each source, merged newest-first:
|
|
24328
|
+
* `device-collection-dispatch.ts` simply left the fan-out un-narrowed,
|
|
24329
|
+
* so absence bought the union this method exists not to be, and
|
|
24330
|
+
* `limit` meant `limit × sources`.
|
|
24331
|
+
*
|
|
24332
|
+
* There is nothing to restore the default to. `getBindings` answers a
|
|
24333
|
+
* collection cap with a DERIVED, PLURAL set (D554 amended, step 0);
|
|
24334
|
+
* `setWrapperActive` — the singleton authority that could name one —
|
|
24335
|
+
* throws for a collection cap by design. Naming CamStack here instead
|
|
24336
|
+
* would privilege one addon by id inside a surface whose premise is
|
|
24337
|
+
* that sources are peers, and would be wrong on the first camera with
|
|
24338
|
+
* no recorder binding. So absence is REFUSED, in the schema, where the
|
|
24339
|
+
* generated types make it unomittable rather than merely discouraged.
|
|
24340
|
+
*
|
|
24341
|
+
* The default belongs to the SURFACE, which has the `listSources` rows
|
|
24342
|
+
* and can say which one it picked (D569 § 1–3; the viewer already
|
|
24343
|
+
* always sends this).
|
|
24260
24344
|
*
|
|
24261
24345
|
* It replaced `sources?: string[]`, a VIEW filter over source ids that
|
|
24262
24346
|
* assumed the answer was a fan-out over everything a camera has. The
|
|
24263
|
-
* operator settled otherwise on 2026-09-20 — *"
|
|
24264
|
-
*
|
|
24265
|
-
*
|
|
24266
|
-
* at a time and there is nothing to filter out of it.
|
|
24347
|
+
* operator settled otherwise on 2026-09-20 — *"l'utilizzatore è uno
|
|
24348
|
+
* solo"* — so the list is asked of one provider at a time and there is
|
|
24349
|
+
* nothing to filter out of it.
|
|
24267
24350
|
*/
|
|
24268
|
-
provider: string().
|
|
24351
|
+
provider: string().min(1)
|
|
24269
24352
|
}), array(ClipSchema).readonly(), {
|
|
24270
24353
|
kind: "query",
|
|
24271
24354
|
auth: "protected"
|
|
@@ -24291,6 +24374,33 @@ DeviceType.Camera, method(object({
|
|
|
24291
24374
|
}), ClipPlaybackSchema, {
|
|
24292
24375
|
kind: "query",
|
|
24293
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"
|
|
24294
24404
|
});
|
|
24295
24405
|
/**
|
|
24296
24406
|
* Optional client-side hints sent at session creation to help the provider
|
|
@@ -30223,13 +30333,101 @@ var ExportStateSchema = _enum([
|
|
|
30223
30333
|
"expired",
|
|
30224
30334
|
"deleted"
|
|
30225
30335
|
]);
|
|
30226
|
-
/**
|
|
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
|
+
*/
|
|
30227
30417
|
var ExportRecordSchema = object({
|
|
30228
30418
|
id: string(),
|
|
30229
30419
|
deviceId: number(),
|
|
30230
30420
|
profile: string(),
|
|
30231
30421
|
fromMs: number(),
|
|
30232
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(),
|
|
30233
30431
|
options: ExportOptionsSchema,
|
|
30234
30432
|
state: ExportStateSchema,
|
|
30235
30433
|
/** 0–100 while rendering; null otherwise. */
|
|
@@ -30246,6 +30444,18 @@ var ExportRecordSchema = object({
|
|
|
30246
30444
|
/** Failure reason when state is 'failed'; null otherwise. */
|
|
30247
30445
|
error: string().nullable()
|
|
30248
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
|
+
]);
|
|
30249
30459
|
/** Candidate download URLs (LAN first, then operator extra hosts). */
|
|
30250
30460
|
var ExportDownloadSchema = object({
|
|
30251
30461
|
url: string(),
|
|
@@ -30264,16 +30474,50 @@ var ExportBytesSchema = object({
|
|
|
30264
30474
|
name: string(),
|
|
30265
30475
|
bytes: number().int().nonnegative()
|
|
30266
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
|
+
}
|
|
30267
30483
|
method(object({
|
|
30268
30484
|
deviceId: number(),
|
|
30269
30485
|
/** @deprecated Prefer `profiles`. Kept so timelapse/notifiers keep working. */
|
|
30270
30486
|
profile: string().optional(),
|
|
30271
30487
|
profiles: array(string()).min(1).optional(),
|
|
30272
|
-
|
|
30273
|
-
|
|
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(),
|
|
30274
30493
|
options: ExportOptionsSchema
|
|
30275
30494
|
}).superRefine((v, ctx) => {
|
|
30276
|
-
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({
|
|
30277
30521
|
code: ZodIssueCode.custom,
|
|
30278
30522
|
message: "pass profiles[] (min 1) or legacy profile",
|
|
30279
30523
|
path: ["profiles"]
|
|
@@ -38273,6 +38517,12 @@ Object.freeze({
|
|
|
38273
38517
|
addonId: null,
|
|
38274
38518
|
access: "view"
|
|
38275
38519
|
},
|
|
38520
|
+
"videoclips.readClipBytes": {
|
|
38521
|
+
capName: "videoclips",
|
|
38522
|
+
capScope: "device",
|
|
38523
|
+
addonId: null,
|
|
38524
|
+
access: "view"
|
|
38525
|
+
},
|
|
38276
38526
|
"viewerUi.getStaticDir": {
|
|
38277
38527
|
capName: "viewer-ui",
|
|
38278
38528
|
capScope: "system",
|
|
@@ -40291,6 +40541,11 @@ Object.freeze({
|
|
|
40291
40541
|
form: "single",
|
|
40292
40542
|
optional: false
|
|
40293
40543
|
}],
|
|
40544
|
+
"videoclips.readClipBytes": [{
|
|
40545
|
+
name: "deviceId",
|
|
40546
|
+
form: "single",
|
|
40547
|
+
optional: false
|
|
40548
|
+
}],
|
|
40294
40549
|
"waterHeater.setAway": [{
|
|
40295
40550
|
name: "deviceId",
|
|
40296
40551
|
form: "single",
|
|
@@ -40968,7 +41223,7 @@ var AdminUIAddon = class extends BaseAddon {
|
|
|
40968
41223
|
capability: adminUiCapability,
|
|
40969
41224
|
provider: {
|
|
40970
41225
|
getStaticDir: async () => ({ staticDir: resolveAdminUiDistDir() }),
|
|
40971
|
-
getVersion: async () => ({ version: "1.2.
|
|
41226
|
+
getVersion: async () => ({ version: "1.2.248" })
|
|
40972
41227
|
}
|
|
40973
41228
|
}];
|
|
40974
41229
|
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,R as r,S as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as d,_t as f,ht as p,st as m}from"./player-overlays-CnN4y6rz.js";import{An as h,Bc as g,Bn as _,Dn as v,Fn as y,Gl as b,Gn as x,Hn as S,Jn as C,Ll as w,Ln as ee,Mn as te,Nn as T,Oc as E,Pn as ne,Ql as re,Rn as ie,Un as ae,Wn as D,X as oe,Xc as se,Y as ce,Yc as le,Yl as ue,Yn as de,_ as O,al as fe,bc as k,cl as A,el as j,eu as M,gc as N,jn as P,kn as F,pc as I,qc as L,qn as R,un as pe,vl as z,w as B,xa as me,zn as V}from"./src-B1ko2zFV.js";import{$t as H}from"./src-DoVhwUVA.js";import{a as he,d as U,s as ge}from"./index-Bj6ZEbIP.js";import{t as W}from"./AdminPage-CiKtOLQm.js";import{t as _e}from"./NodeAddonsSettingsPanel-B2mruGGB.js";import{r as G,t as K}from"./useNodeUrlSelection-Bi7c3aCd.js";var q=f(`octagon-alert`,[[`path`,{d:`M12 16h.01`,key:`1drbdi`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z`,key:`1fd625`}]]);n();var J=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),ve=new Set([`done`,`failed`,`skipped`]);function Y(e){return!ve.has(e.phase)&&!J.has(e.jobState)}function X(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=J.has(e.state);for(let i of e.tasks)r&&i.finishedAtMs!==null&&t-i.finishedAtMs>6e4||n.set(i.packageName,{jobId:e.jobId,packageName:i.packageName,phase:i.phase,fromVersion:i.fromVersion,toVersion:i.toVersion,error:i.error,jobState:e.state,finishedAtMs:i.finishedAtMs})}return n}function Z(){let{data:e}=ee({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=N(H.AddonsJobProgress,e=>e.job.jobId);return a(()=>{let n=new Map;for(let t of e??[])n.set(t.jobId,t);for(let[e,r]of t)n.set(e,r.job);return X([...n.values()],Date.now())},[e,t])}var ye={queued:{icon:b,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:z,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:z,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:z,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:z,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:z,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:z,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:M,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:q,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:g,cls:`bg-muted text-foreground-subtle`,label:`skipped`}};function be({progress:e}){let t=ye[e.phase],n=t.icon,r=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return i(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${t.cls}`,title:r,children:[l(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label,i(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function xe({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:a,onSelect:s,selectedVersion:c}){let u=n===`upload`||n===`local`,{data:d,isLoading:f}=T({name:e});return i(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[i(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[l(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),l(`button`,{type:`button`,onClick:a,className:`text-foreground-subtle hover:text-foreground`,children:l(k,{className:`h-3 w-3`})})]}),u&&i(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[l(E,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),i(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[i(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,l(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),f&&i(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[l(z,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),d&&l(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:d.map(e=>{let n=e.version===t,a=s!==void 0&&e.version===c,d=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),f=i(o,{children:[l(`span`,{className:`font-mono flex-1 text-left ${n?`text-primary font-semibold`:d?`text-amber-400`:`text-foreground`}`,children:e.version}),n&&l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:`current`}),e.distTags.map(e=>l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),e.deprecated&&l(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),l(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return s?i(`button`,{type:`button`,"aria-label":`Select ${e.version}`,onClick:()=>s(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${a?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,a?l(M,{className:`h-3 w-3 text-primary shrink-0`}):l(`span`,{className:`w-3 shrink-0`})]},e.version):i(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,n&&!u?l(M,{className:`h-3 w-3 text-primary shrink-0`}):l(`button`,{type:`button`,onClick:()=>r(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:n?`Re-install ${e.version} from npm`:`Install ${e.version}`,children:l(w,{className:`h-3 w-3`})})]},e.version)})}),d&&d.length===0&&l(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var Se={queued:{icon:b,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:z,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:j,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:M,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:q,bg:`bg-danger/10 text-danger`,label:`failed`}};function Q({item:e}){let t=Se[e.status],n=t.icon;return i(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[l(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}n();var Ce=`device-export`;function we(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===Ce)}function Te({isBundle:e,installSource:t,addonId:n,iconPath:r,color:a}){let[o,s]=c(!1),u=a?{backgroundColor:`${a.startsWith(`#`)?a:`#${a}`}26`}:void 0,f=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,p=n&&r?d(`/api/addon-assets/${n}/${r}`):null,m=!!p&&!o;return i(`div`,{className:`relative flex-shrink-0`,children:[l(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${u?``:f}`,style:u,children:m?l(`img`,{src:p,alt:n,className:`h-5 w-5`,onError:()=>s(!0)}):l(e?A:U,{className:`h-4 w-4`})}),t===`local`&&l(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),t===`npm`&&l(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:l(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:l(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&l(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:l(E,{className:`h-2.5 w-2.5 text-white`})})]})}function Ee({version:e,availableUpdate:t,selectedVersion:n,isUpdating:r,installSource:a,disabled:o,onUpdate:s,onOpenPicker:c,children:u}){if(r)return i(`span`,{className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[l(z,{className:`h-3 w-3 animate-spin`}),`Updating…`]});if(t){let r=n??t;return i(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[s&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:o,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-semibold border border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:`Update to ${r}`,children:[l(w,{className:`h-3 w-3`}),`Update`]}),i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:o,"aria-label":`Select version to install`,title:`Installed ${e} — update available. Selected ${r}; tap to choose another version.`,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border border-amber-500/40 bg-amber-500/15 text-amber-500 hover:bg-amber-500/25 animate-pulse disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[l(`span`,{className:`font-normal opacity-70`,children:e}),l(`span`,{className:`font-normal opacity-70`,children:`→`}),r,l(p,{className:`h-3 w-3`})]}),u]})}return i(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:o,className:[`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,a===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:`Version ${e} — tap to view all versions`,children:[e,l(p,{className:`h-3 w-3 opacity-50`})]}),u]})}function De({addonId:e}){let t=s(),{data:n=`inherit`}=h({addonId:e}),r=D({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return l(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>l(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}function Oe({addon:e,agents:t=[],clusterStatus:n,hideVersion:r,availableUpdate:a,onUpdate:d,isUpdating:f,jobProgress:h,bundle:g,bulkItem:v,disabledByBulk:y,isSystem:b}){let[x,w]=c(!1),[ee,te]=c(!1),[T,E]=c(!1),[ie,ae]=c(null);u(()=>{ae(null)},[a]);let D=ie??a,[le,ue]=c(!1),[de,O]=c(!1),[M,N]=c(`logs`),P=s(),F=he(),I=pe(),{manifest:R}=e,z=e.installedOn??[],me=!g&&!R.protected&&R.removable!==!1,V=!!g,H=g?.displayName??R.name,U=g?.packageName??R.packageName,ge=g?.version??R.packageVersion??R.version,W=g?.installSource??e.installSource,G=g?g.bundle?.description??g.addons[0]?.manifest.description:R.description,K=C({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`addonPages`]]}),P.invalidateQueries({queryKey:[[`capabilities`]]})}}),J=_({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]})}}),ve=ne({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`addonPages`]]}),P.invalidateQueries({queryKey:[[`capabilities`]]}),P.invalidateQueries({queryKey:[[`integrations`]]})}}),Y=S({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`alerts`]]})}}),X=e.health,Z=X?.phase===`failed`&&!X.inGracePeriod,ye=Z&&X?.nextRetryAt&&!X.retrying;return i(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${Z?`border-red-500/50`:`border-border`}`,children:[Z&&X&&i(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[l(q,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,X.retryCount,`)`]}),l(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:X.lastError?.message??`Unknown error`}),ye&&X.nextRetryAt&&i(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(X.nextRetryAt).toLocaleTimeString()]})]}),i(`button`,{type:`button`,disabled:Y.isPending||X.retrying,onClick:e=>{e.stopPropagation(),Y.mutate({packageName:U})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:`Reset retry counter and force immediate reload`,children:[l(j,{className:`h-3 w-3 ${Y.isPending||X.retrying?`animate-spin`:``}`}),`Retry now`]})]}),i(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[l(Te,{isBundle:V||!!R.components&&R.components.length>1,installSource:W,addonId:V?g.addons[0]?.manifest.id:R.id,iconPath:V?g.bundle?.icon??g.addons[0]?.manifest.icon:R.icon,color:V?g.addons[0]?.manifest.color:R.color}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`flex items-start justify-between gap-2`,children:[l(`span`,{className:`text-sm font-semibold text-foreground truncate min-w-0`,children:H}),!r&&l(Ee,{version:ge,availableUpdate:a,...D===void 0?{}:{selectedVersion:D},isUpdating:f,installSource:W,disabled:y,...d&&D!==void 0?{onUpdate:()=>d(D)}:{},onOpenPicker:()=>E(e=>!e),children:T&&l(xe,{packageName:U,currentVersion:ge,...W?{installSource:W}:{},...a!==void 0&&D!==void 0?{selectedVersion:D,onSelect:e=>{ae(e),E(!1)}}:{},onInstall:e=>{E(!1),ve.mutate({packageName:U,version:e})},onClose:()=>E(!1)})})]}),i(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[U!==H&&l(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:U}),V&&i(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[l(A,{className:`h-3 w-3`}),g.addons.length]}),b&&i(`span`,{className:`text-[10px] rounded-full bg-amber-500/15 text-amber-700 dark:text-amber-300 px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,title:`System package — updating restarts the hub`,children:[l(j,{className:`h-3 w-3`}),`System`]}),v!=null&&l(Q,{item:v}),h!=null&&l(be,{progress:h})]}),G&&l(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:G}),!V&&e.process&&i(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?`forked`:`in-process`}),e.process.pid!=null&&i(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:e.process.state===`crashed`||e.process.state===`failed`?`bg-red-500/15 text-red-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.state})]})]})]}),!V&&i(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),J.mutate({addonId:R.id})},disabled:J.isPending||y,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors`,children:[l(j,{className:`h-3 w-3 ${J.isPending?`animate-spin`:``}`}),`Restart`]}),i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ue(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${le?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[l(se,{className:`h-3 w-3`}),`Logs`]}),!V&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),O(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${de?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[l(L,{className:`h-3 w-3`}),`Settings`]}),l(`div`,{className:`flex-1`}),me&&i(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await I({title:`Uninstall ${R.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&K.mutate({packageName:R.packageName})},disabled:K.isPending||y,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors`,children:[l(m,{className:`h-3 w-3`}),K.isPending?`Removing...`:`Uninstall`]})]}),n&&n.nodes.length>1&&!V&&i(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),l(`div`,{className:`space-y-1`,children:n.nodes.map(e=>i(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),l(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),l(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:`outdated`}),e.status===`offline`&&l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&l(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),le&&!V&&i(`div`,{className:`border-t border-border`,children:[i(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[i(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[l(`button`,{type:`button`,onClick:()=>N(`logs`),className:`px-2 py-0.5 transition-colors ${M===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),l(`button`,{type:`button`,onClick:()=>N(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${M===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),l(`div`,{className:`flex-1`}),l(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ue(!1)},className:`text-foreground-subtle hover:text-foreground`,children:l(k,{className:`h-3.5 w-3.5`})})]}),M===`logs`&&l(oe,{addonId:R.id,maxHeight:`max-h-64`,showFilters:!1}),M===`events`&&l(ce,{addonId:R.id,category:`addon.*`,maxHeight:`max-h-64`})]}),V&&i(o,{children:[l(`button`,{type:`button`,onClick:()=>w(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:l(x?re:p,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),x&&l(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:g.addons.map(e=>l(Oe,{addon:e,agents:t,hideVersion:!0},e.manifest.id))})]}),de&&!V&&l(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>O(!1),children:i(`div`,{className:`w-full max-w-lg max-h-[80vh] rounded-xl border border-border bg-surface shadow-2xl flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[i(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[i(`div`,{className:`flex items-center gap-2`,children:[l(L,{className:`h-4 w-4 text-primary`}),i(`h2`,{className:`text-sm font-semibold text-foreground`,children:[H,` Settings`]})]}),l(`button`,{onClick:()=>O(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:l(k,{className:`h-4 w-4`})})]}),i(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[l(`div`,{className:`text-[10px] text-foreground-subtle mb-2`,children:`Cluster-wide settings — one value for every node. Per-node settings live under Cluster → the node → Settings.`}),l(_e,{nodeId:null,addonIds:[R.id],level:`global`,fieldScope:`cluster`,emptyMessage:`This addon exposes no cluster-wide settings. Anything it can configure is per-node — open it from Cluster → the node → Settings.`}),we(R)&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),l(B,{addonId:R.id,onOpenDevice:e=>F(`/devices/${e}`)})]}),W===`npm`&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),l(De,{addonId:R.id})]}),R.components&&R.components.length>0&&i(`div`,{children:[i(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,R.components.length,`)`]}),l(`div`,{className:`flex flex-wrap gap-1`,children:R.components.map(e=>l(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),t.length>=2&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),i(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[z.length===0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),z.map(e=>l(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),i(`div`,{className:`relative`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),te(e=>!e)},className:`inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:border-primary transition-colors`,title:`Install on more agents`,children:[l(fe,{className:`h-3 w-3`}),`Add agent`]}),ee&&i(`div`,{className:`absolute left-0 top-full mt-1 z-10 min-w-[160px] rounded-md border border-border bg-surface shadow-lg overflow-hidden`,children:[t.filter(e=>!e.isHub&&!z.includes(e.name)).map(e=>l(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),te(!1)},className:`w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors`,children:e.name},e.id)),t.filter(e=>!e.isHub&&!z.includes(e.name)).length===0&&l(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),l(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:l(`button`,{type:`button`,onClick:()=>O(!1),className:`rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:`Close`})})]})})]})}n();var ke=`.tgz,.tar.gz,.zip`;function Ae({onUploadSuccess:n}){let[r,a]=c(!1),s=t(null),u=e(async e=>{a(!0);let t=new FormData;t.append(`file`,e);let r=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(d(`/api/addons/upload`),{method:`POST`,headers:{Authorization:`Bearer ${r}`},body:t})).json()).success&&n()}finally{a(!1)}},[n]);return i(o,{children:[l(`input`,{ref:s,type:`file`,accept:ke,onChange:e(e=>{let t=e.target.files?.[0];t&&u(t),e.target.value=``},[u]),className:`hidden`}),i(`button`,{type:`button`,onClick:()=>s.current?.click(),disabled:r,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[r?l(z,{className:`w-3.5 h-3.5 animate-spin`}):l(E,{className:`w-3.5 h-3.5`}),r?`Uploading...`:`Upload`]})]})}n();var je=[{seconds:900,label:`15m`},{seconds:3600,label:`1h`},{seconds:21600,label:`6h`},{seconds:43200,label:`12h`},{seconds:86400,label:`24h`}],Me=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function Ne(e){return e!==void 0&&Me.has(e)}var Pe={id:`hub`,name:`Hub`,isHub:!0,isOnline:!0};function Fe(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function Ie(e){let t=e;if(!t?.manifest)return null;let n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??`0.0.0`,capabilities:t.manifest.capabilities??[]},r=t.process,i=r?{pid:r.pid,mode:r.mode===`forked`?`forked`:`in-process`,state:r.state??`unknown`}:void 0,a=t.health,o=t.declaration?.execution,s=t.manifest.execution,c=o?.placement??s?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...i?{process:i}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function Le(e){let t=new Map,n=[];for(let r of e){let e=r.manifest.packageName;if(!e){n.push(r);continue}let i=t.get(e);if(i)i.addons.push(r);else{let n=r.manifest.bundle,i={packageName:e,displayName:n?.displayName??r.manifest.packageDisplayName??r.manifest.name,version:r.manifest.packageVersion,addons:[r],...r.installSource===void 0?{}:{installSource:r.installSource},...n===void 0?{}:{bundle:n}};t.set(e,i)}}let r=[];for(let e of t.values())e.bundle!==void 0||e.addons.length>=2?r.push({bundle:e,representative:e.addons[0]}):r.push(e.addons[0]);return r.push(...n),r}function $(e){return`bundle`in e}function Re({addons:n,clusterStatus:o,selectedNode:d,onRefresh:f,isRefreshing:p}){let m=s(),[h,g]=c(``),_=r(h),[y,b]=c(!1),S=t(null);u(()=>{if(!y)return;let e=e=>{S.current&&!S.current.contains(e.target)&&b(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[y]);let{data:C}=ie({nodeId:d.id}),ee=a(()=>{let e=new Map;for(let t of C??[])e.set(t.name,t.latestVersion);return e},[C]),T=a(()=>(C??[]).filter(e=>!e.isSystem).length,[C]),[E,re]=c(()=>new Set),[D,oe]=c(()=>new Map),se=e(e=>{re(t=>new Set(t).add(e))},[]),ce=e(e=>{re(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),O=e((e,t)=>{oe(n=>new Map(n).set(e,t))},[]),fe=e(e=>{oe(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),k=de({onMutate:e=>{se(e.name),fe(e.name)},onSuccess:(e,t)=>{ce(t.name);let n=e;if(n&&n.success===!1){O(t.name,n.error??`Update failed (no error message returned by server)`);return}m.invalidateQueries({queryKey:[[`addons`]]}),m.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{ce(t.name),O(t.name,e instanceof Error?e.message:String(e))}}),A=Z(),N=t(new Set);u(()=>{let e=new Set;for(let[t,n]of A)Y(n)&&e.add(t);let t=[...N.current].some(t=>!e.has(t));N.current=e,t&&(m.invalidateQueries({queryKey:[[`addons`]]}),m.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[A,m]);let{data:F}=P(void 0),I=v({onSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),L=x({onSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:B,isFetching:me}=ae({query:_||void 0},{enabled:y}),V=R(),{data:H}=te(void 0),he=H?.requestedAt,[U,W]=c(null),[_e,G]=c(!1);u(()=>{if(H?.kind===`framework-bulk-update`&&H.requestedAt!==U){W(H.requestedAt),G(!0);let e=window.setTimeout(()=>G(!1),6e3);return()=>window.clearTimeout(e)}},[he,U,H]),pe();let K=e(async()=>{let e=(C??[]).filter(e=>!e.isSystem);if(e.length!==0){if(!d.isHub){for(let t of e)await k.mutateAsync({name:t.name,version:t.latestVersion,nodeId:d.id});return}await V.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[d.id]})}},[C,d.id,d.isHub,V,k]),q=ne({onSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`]]}),m.invalidateQueries({queryKey:[[`addonPages`]]}),m.invalidateQueries({queryKey:[[`capabilities`]]}),m.invalidateQueries({queryKey:[[`integrations`]]})}}),[J,ve]=c(`type`),[X,ye]=c(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),be=e=>{ye(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[xe,Se]=ge(),Q=xe.get(`capability`),Ce=a(()=>{let e=n.filter(e=>!Ne(e.manifest.packageName));return d.isHub||(e=e.filter(e=>Fe(e.placement,d.isHub))),Q&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===Q))),e},[n,d.isHub,Q]),we=()=>{let e=new URLSearchParams(xe);e.delete(`capability`),Se(e,{replace:!0})},Te=X===`flat`?Ce:Le(Ce),Ee=a(()=>{let e=[...Te];switch(J){case`type`:e.sort((e,t)=>{let n=+!$(e),r=+!$(t);if(n!==r)return n-r;let i=$(e)?e.bundle.displayName:e.manifest.name,a=$(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=$(e)?e.bundle.displayName:e.manifest.name,r=$(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=$(e)?e.bundle.installSource??``:e.installSource??``,r=$(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[Te,J]);return i(`div`,{className:`space-y-4`,children:[[...D.entries()].map(([e,t])=>l(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:i(`div`,{className:`flex items-start justify-between gap-3`,children:[i(`div`,{className:`space-y-0.5`,children:[i(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,e]}),l(`div`,{className:`text-foreground-subtle font-mono`,children:t})]}),l(`button`,{type:`button`,onClick:()=>fe(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})},e)),i(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),i(`select`,{value:J,onChange:e=>ve(e.target.value),className:`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground focus:outline-none focus:border-primary/50`,children:[l(`option`,{value:`type`,children:`Bundles first`}),l(`option`,{value:`name`,children:`Name`}),l(`option`,{value:`source`,children:`Install source`})]})]}),i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),l(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>l(`button`,{type:`button`,onClick:()=>be(e),className:`px-2.5 py-1.5 transition-colors capitalize ${X===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?`Group multi-addon packages into a bundle card`:`Show every addon as its own card`,children:e},e))})]}),d.isHub&&i(`div`,{className:`flex items-center gap-1.5`,children:[l(j,{className:`h-3 w-3 text-foreground-subtle`}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),l(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>l(`button`,{type:`button`,onClick:()=>I.mutate({channel:e}),disabled:I.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${F?.channel===e?e===`off`?`bg-gray-700 text-gray-200`:e===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${e===`off`?``:`border-l border-border`}`,children:e},e))})]}),d.isHub&&i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Check every:`}),l(`select`,{className:`rounded-md border border-border bg-transparent px-1.5 py-1 text-[10px] font-medium text-foreground-subtle`,value:F?.updateCheckIntervalSeconds??21600,disabled:L.isPending||F===void 0,onChange:e=>{F!==void 0&&L.mutate({channel:F.channel,updateCheckIntervalSeconds:Number(e.target.value)})},children:je.map(e=>l(`option`,{value:e.seconds,children:e.label},e.seconds))})]}),T>0&&i(`button`,{type:`button`,onClick:()=>void K(),disabled:V.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium`,children:[V.isPending?l(z,{className:`w-3 h-3 animate-spin`}):l(w,{className:`w-3 h-3`}),V.isPending?`Updating…`:`Update All (${T})`]}),i(`button`,{type:`button`,onClick:f,disabled:p||V.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[l(j,{className:`w-3 h-3 ${p?`animate-spin`:``}`}),`Refresh`]})]}),i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:S,children:[l(le,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),l(`input`,{type:`text`,value:h,onChange:e=>{g(e.target.value),b(!0)},onFocus:()=>b(!0),placeholder:`Search addons on npm...`,disabled:V.isPending,className:`w-full rounded-lg border border-border bg-background pl-9 pr-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-50 disabled:cursor-not-allowed`}),me&&l(z,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),y&&B&&B.length>0&&i(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,children:[B.length>0&&i(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,B.length,`)`]}),B&&B.length>0&&l(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:B.map(e=>i(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[l(`div`,{className:`w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0`,children:e.name.replace(`@camstack/addon-`,``).charAt(0).toUpperCase()}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[l(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),l(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&l(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?i(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md border border-emerald-500/30 bg-emerald-500/10 text-emerald-400 shrink-0`,children:[l(M,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):i(`button`,{type:`button`,onClick:()=>q.mutate({packageName:e.name}),disabled:q.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[q.isPending?l(z,{className:`h-3 w-3 animate-spin`}):l(w,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),l(Ae,{onUploadSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`]]}),f()}})]}),Q&&i(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[l(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),l(`span`,{className:`font-mono text-primary font-semibold`,children:Q}),l(`button`,{type:`button`,onClick:we,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),_e&&i(`div`,{className:`fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm max-w-sm pointer-events-auto`,children:[l(ue,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),i(`div`,{children:[l(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),l(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),Ce.length===0&&l(`div`,{className:`text-xs text-foreground-subtle`,children:n.length===0?`No addons installed`:Q?`No installed addons declare the "${Q}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${d.name} (placement filter active)`}),l(`div`,{className:`space-y-2`,children:Ee.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,n=ee.get(t),r=$(e)?e.representative:e,i=n?e=>k.mutate({name:t,version:e,nodeId:d.id}):void 0,a=A.get(t)??null,s=a!==null&&Y(a);return l(Oe,{addon:r,clusterStatus:o?.[r.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:n,isUpdating:E.has(t)||s,jobProgress:a,onUpdate:i,disabledByBulk:V.isPending},$(e)?t:e.manifest.id)})})]})}function ze(){let e=s(),{data:n,isLoading:r,isError:a}=y(),{data:o}=me(void 0),{nodes:c}=I(),{selection:d,selectNode:f,requestedNodeId:p}=K(c.length>0?c:[Pe]),m=d.node??Pe,h=m.id,g=c.length>0?d.staleNodeId:null,_=F(),v=V(),b=_.isPending||v.isPending,x=async()=>{await _.mutateAsync({nodeId:h}),await v.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},S=t(_);S.current=_;let C=t(p??`hub`);u(()=>{S.current.mutate({nodeId:C.current})},[]);let w=(n??[]).map(Ie).filter(e=>e!==null);return i(W,{children:[i(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[l(O,{selectedNodeId:h,onSelect:f}),i(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!r&&!a&&i(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[w.length,` installed`]}),i(`button`,{type:`button`,onClick:()=>void x(),disabled:b,className:`inline-flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:`Re-fetch addons + check npm for new versions`,children:[l(j,{className:`w-3 h-3 ${b?`animate-spin`:``}`}),`Check for updates`]})]})]}),l(G,{staleNodeId:g,shownNodeName:m.name}),!m.isHub&&i(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[`Showing only addons compatible with`,` `,l(`span`,{className:`font-medium text-foreground`,children:m.name}),` — agents only run`,` `,l(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,l(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),r&&l(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),a&&l(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!r&&!a&&l(Re,{addons:w,clusterStatus:o,selectedNode:m,onRefresh:()=>void x(),isRefreshing:b})]})}export{ze as AddonsPage};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{W as d,Z as f,_t as p,at as m,ct as h,gt as g,st as _}from"./player-overlays-CnN4y6rz.js";import{$t as v,Bl as y,Dl as b,Dt as x,Et as S,Gt as C,Ht as w,Jc as T,Jt as E,Lc as D,Ll as O,Lt as ee,Ol as te,Qr as k,Qt as A,St as j,Tt as M,Ul as N,Yc as ne,Zt as P,_ as F,al as I,bc as re,bt as L,il as R,kt as z,qt as B,ru as V,sl as H,vl as U,wt as W,xt as G}from"./src-B1ko2zFV.js";import{t as ie}from"./boxes-wlW-4tW0.js";import{t as ae}from"./send-DD2HpdhT.js";import{pt as K}from"./src-DoVhwUVA.js";import{n as q}from"./index-Bj6ZEbIP.js";import{t as J}from"./AdminPage-CiKtOLQm.js";import{t as oe}from"./AdminTabs-CwIF_SRE.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":R,"managed-local":y}));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(P,{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(z,{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(A,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||x.isPending,onClick:()=>E(),children:[x.isPending?l(U,{className:`h-3.5 w-3.5 animate-spin`}):l(ne,{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(A,{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(A,{size:`sm`,type:`button`,disabled:S.isPending||g,onClick:()=>S.mutate(p.model),children:[S.isPending?l(U,{className:`h-3.5 w-3.5 animate-spin`}):l(O,{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(j,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(M,{children:l(S,{children:a(`ai.chooseKind`,`Choose a profile type`)})}),r(G,{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(W,{children:l(A,{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`),[b,x]=s(()=>t?.runtime===void 0?null:{model:t.runtime.model,modelId:t.model,supportsVision:t.supportsVision}),C=i(()=>be(Y(h.extraArgs)??``),[h.extraArgs]),w=()=>{if(!f){n(we(e.kind,p,t,h));return}b!==null&&n(we(e.kind,p,t,h,{nodeId:_,model:b.model,modelId:b.modelId,supportsVision:b.supportsVision}))},T=c||p.trim()===``||f&&b===null;return l(L,{open:!0,onOpenChange:e=>!e&&a(),children:r(j,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(M,{children:r(S,{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(G,{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(z,{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:b,onChange:x}),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(z,{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(ee,{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(W,{children:[f&&b===null&&l(v,{variant:`warning`,children:d(`ai.pickModelFirst`,`pick a model`)}),l(A,{size:`sm`,variant:`secondary`,type:`button`,onClick:a,children:d(`common.cancel`,`Cancel`)}),r(A,{size:`sm`,type:`button`,disabled:T,onClick:w,children:[c&&l(U,{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(x,{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(A,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onTest(t),title:e.t(`ai.test`,`Test`),children:e.testingId===t.id?l(U,{className:`h-3.5 w-3.5 animate-spin`}):l(ae,{className:`h-3.5 w-3.5`})}),l(A,{size:`sm`,variant:`ghost`,type:`button`,disabled:!e.kindByName.has(t.kind),onClick:()=>e.onEdit(t),title:e.t(`common.edit`,`Edit`),children:l(H,{className:`h-3.5 w-3.5`})}),l(A,{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}`})}),x=h.data??[],S=i(()=>g.data??[],[g.data]),T=i(()=>{let e=new Map;for(let t of S)e.set(t.kind,t);return e},[S]);return r(J,{icon:D,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(A,{size:`sm`,type:`button`,onClick:()=>{p(null),o({mode:`pick-kind`})},children:[l(I,{className:`h-3.5 w-3.5`}),e(`ai.addProfile`,`Add profile`)]}),children:[h.isError&&l(C,{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:x}),h.isLoading&&l(`div`,{className:`flex items-center justify-center py-16`,children:l(U,{className:`h-6 w-6 animate-spin text-primary`})}),!h.isLoading&&x.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.`)}),x.length>0&&l(w,{children:l(B,{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:x,rowKey:e=>e.id,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:`max-h-[60vh]`})}),n.mode===`pick-kind`&&l(Ae,{kinds:S,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(w,{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:T,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(C,{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(w,{children:l(B,{columns:o,rows:s,rowKey:e=>e.nodeId,minWidthPx:640,bordered:!1,mobileMode:`scroll`,maxBodyHeight:E})})]})}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,x]=s([]),[S,T]=s(null),[E,D]=s(`none`),[O,ee]=s(`throwaway`),[k,j]=s(null),[M,N]=s([]),[ne,F]=s(null),[I,L]=s(null),R=t(null);u(()=>()=>R.current?.abort(),[]);let B=e(async()=>{let e=await fetch(ze,{credentials:`same-origin`});e.ok&&N((await e.json()).chats??[])},[]);u(()=>{O===`persistent`&&B()},[O,B]);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},...O===`persistent`?{persist:!0,...k===null?{}:{conversationId:k}}:{}})});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&&(j(d),B());let p=r.signal.aborted&&a.length>0;l===null&&a.length===0&&!p||x(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:l??a,...l===null?{}:{failed:!0},...o===null?{}:{attachment:o},...s!==void 0&&l===null?{model:s}:{},...u===null?{}:u}])},[O,k,W,c,B,f,n]),K=e(()=>{let e=v.trim();if(e===``||c===``||G)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...S===null?{}:{attachmentLabel:S.label,attachmentKind:S.ref.kind}},n=[...b,t];x(n),y(``);let r=S?.ref;T(null),D(`none`),ie(O===`persistent`&&k!==null?[{role:`user`,content:e}]:qe(n),r)},[O,k,v,S,c,ie,G,b]),oe=()=>R.current?.abort(),le=()=>{R.current?.abort(),x([]),T(null),y(``),F(null),L(null),j(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();j(e),x(Ye(n)),L(null),F(null)};return r(J,{icon:te,title:n(`ai.testTitle`,`Test chat`),subtitle:n(O===`persistent`?`ai.testSubtitlePersistent`:`ai.testSubtitle`,O===`persistent`?`Conversations are saved for you and can be reopened. Throwaway mode is still available.`:`A throwaway conversation with one profile. Attach a live camera snapshot or a recent track to check the model can actually read a picture. Nothing is saved — only the usage row.`),actions:r(A,{size:`sm`,variant:`secondary`,type:`button`,disabled:b.length===0&&S===null,onClick:le,children:[l(_,{className:`h-3.5 w-3.5`}),n(`ai.clearChat`,`Clear`)]}),children:[r(w,{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(P,{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(z,{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(A,{size:`sm`,variant:O===`throwaway`?`primary`:`outline`,type:`button`,onClick:()=>{ee(`throwaway`),j(null)},children:n(`ai.throwawayMode`,`Throwaway`)}),l(A,{size:`sm`,variant:O===`persistent`?`primary`:`outline`,type:`button`,onClick:()=>ee(`persistent`),children:n(`ai.saveConversation`,`Save conversation`)})]}),O===`persistent`&&r(`div`,{className:`space-y-2`,children:[l(`div`,{className:`flex items-center gap-2`,children:r(A,{size:`sm`,variant:`secondary`,type:`button`,onClick:le,children:[l(se,{className:`h-3.5 w-3.5`}),n(`ai.newChat`,`New chat`)]})}),M.length>0&&l(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:M.map(e=>l(`button`,{type:`button`,onClick:()=>void ue(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover ${e.id===k?`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.`)})]}),ne!==null&&l(C,{title:n(`ai.chatFailed`,`The test call failed`),message:ne}),l(rt,{turns:b,live:I}),r(w,{className:`space-y-2 p-3`,children:[S!==null&&r(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-surface px-2.5 py-1.5`,children:[S.ref.kind===`snapshot`?l(g,{className:`h-3.5 w-3.5 text-foreground-subtle`}):l(V,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-foreground`,children:S.label}),l(A,{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(A,{size:`sm`,variant:E===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>D(E===`snapshot`?`none`:`snapshot`),children:[l(g,{className:`h-3.5 w-3.5`}),n(`ai.attachSnapshot`,`Camera snapshot`)]}),r(A,{size:`sm`,variant:E===`track`?`primary`:`outline`,type:`button`,onClick:()=>D(E===`track`?`none`:`track`),children:[l(V,{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})}),D(`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})}),D(`none`)}}),r(`div`,{className:`flex items-center gap-2`,children:[l(z,{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(A,{size:`sm`,variant:`secondary`,type:`button`,onClick:oe,children:[l(h,{className:`h-3.5 w-3.5`}),n(`ai.stop`,`Stop`)]}):r(A,{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(w,{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(U,{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(V,{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(V,{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=k({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?l(U,{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=k({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(U,{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(V,{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:b,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(P,{"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(C,{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(w,{children:l(B,{columns:p,rows:h,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,mobileMode:`scroll`,maxBodyHeight:E})})]})}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:T,content:l(Le,{})},{id:`usage`,label:e(`ai.tabUsage`,`Usage`),icon:b,content:l(dt,{})},{id:`test`,label:e(`ai.tabTest`,`Test`),icon:te,content:l(nt,{})}]})})}export{ft as AiProfilesPage,ft as default};
|