@camstack/addon-agent-ui 1.2.215 → 1.2.217
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/addon.js +53 -7
- package/dist/assets/{MotionZonesSettings-CP3WEwfU.js → MotionZonesSettings-CF7N4Lwu.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-CA6JzJZP.js → PrivacyMaskSettings-AEiLEFlv.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-BtJZmD6t.js → SceneMonitorEditor-M6gtzFDs.js} +1 -1
- package/dist/assets/index-yffMGpE_.js +112 -0
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/dist/assets/index-CwoBHRjV.js +0 -112
package/dist/addon.js
CHANGED
|
@@ -18074,14 +18074,14 @@ var LlmProfileSchema = object({
|
|
|
18074
18074
|
/** ConfigUISchema tree passed through untyped on the wire (the
|
|
18075
18075
|
* notification-output `ConfigSchemaPassthrough` precedent at
|
|
18076
18076
|
* notification-output.cap.ts:151); the exported TS type re-tightens it. */
|
|
18077
|
-
var ConfigSchemaPassthrough$
|
|
18077
|
+
var ConfigSchemaPassthrough$2 = unknown();
|
|
18078
18078
|
var LlmProfileKindDescriptorSchema = object({
|
|
18079
18079
|
kind: LlmProfileKindSchema,
|
|
18080
18080
|
label: string(),
|
|
18081
18081
|
icon: string(),
|
|
18082
18082
|
/** Stamped by each provider so the concat-fanned catalog stays routable. */
|
|
18083
18083
|
addonId: string(),
|
|
18084
|
-
configSchema: ConfigSchemaPassthrough$
|
|
18084
|
+
configSchema: ConfigSchemaPassthrough$2
|
|
18085
18085
|
});
|
|
18086
18086
|
var LlmDefaultSelectorSchema = union([object({ consumer: string() }), object({ purpose: _enum(["text", "vision"]) })]);
|
|
18087
18087
|
var LlmDefaultSchema = object({
|
|
@@ -19202,7 +19202,7 @@ var TargetKindCapsSchema = object({
|
|
|
19202
19202
|
* the union is large and not meant for runtime validation here; the exported
|
|
19203
19203
|
* `TargetKind` type re-tightens `configSchema` to `ConfigUISchema`.
|
|
19204
19204
|
*/
|
|
19205
|
-
var ConfigSchemaPassthrough = unknown();
|
|
19205
|
+
var ConfigSchemaPassthrough$1 = unknown();
|
|
19206
19206
|
var TargetKindSchema = object({
|
|
19207
19207
|
kind: string(),
|
|
19208
19208
|
label: string(),
|
|
@@ -19239,7 +19239,7 @@ var TargetKindSchema = object({
|
|
|
19239
19239
|
* its raster path, which is the safe default for an unknown image.
|
|
19240
19240
|
*/
|
|
19241
19241
|
iconMediaType: string().optional(),
|
|
19242
|
-
configSchema: ConfigSchemaPassthrough,
|
|
19242
|
+
configSchema: ConfigSchemaPassthrough$1,
|
|
19243
19243
|
/**
|
|
19244
19244
|
* The config keys that decide WHERE this kind's secrets are sent (server,
|
|
19245
19245
|
* base URL, instance, chat, recipient). A save that changes any of them
|
|
@@ -35034,6 +35034,7 @@ var OsdNamedTemplateSchema = object({
|
|
|
35034
35034
|
});
|
|
35035
35035
|
/** Where a slot's value comes from. */
|
|
35036
35036
|
var OsdSourceSchema = discriminatedUnion("kind", [
|
|
35037
|
+
object({ kind: literal("none") }),
|
|
35037
35038
|
object({
|
|
35038
35039
|
kind: literal("static"),
|
|
35039
35040
|
text: string().max(64)
|
|
@@ -39357,6 +39358,12 @@ var TrainingProviderDefaultsSchema = object({
|
|
|
39357
39358
|
/** Hours a FAILED job's cloud dataset is kept for debugging; 0 = delete at once. */
|
|
39358
39359
|
failedDatasetGraceHours: number().nonnegative()
|
|
39359
39360
|
});
|
|
39361
|
+
/**
|
|
39362
|
+
* Entry form schema for a provider type — same seam as notification
|
|
39363
|
+
* `TargetKind.configSchema` (`z.unknown()` at the wire; callers tighten to
|
|
39364
|
+
* {@link ConfigUISchema}). Drives `ConfigFormBuilder` on Training → Providers.
|
|
39365
|
+
*/
|
|
39366
|
+
var ConfigSchemaPassthrough = unknown();
|
|
39360
39367
|
/** One creatable provider type, for the Add-entry dialog. */
|
|
39361
39368
|
var TrainingProviderTypeSchema = object({
|
|
39362
39369
|
typeId: string(),
|
|
@@ -39364,7 +39371,13 @@ var TrainingProviderTypeSchema = object({
|
|
|
39364
39371
|
/** Path under the addon package (e.g. `assets/training-modal/icon.svg`). */
|
|
39365
39372
|
iconAsset: string(),
|
|
39366
39373
|
/** Owning `training-provider` addon — collection selector for createEntry. */
|
|
39367
|
-
addonId: string()
|
|
39374
|
+
addonId: string(),
|
|
39375
|
+
/**
|
|
39376
|
+
* Fields for one entry of this type (credentials + defaults). Absent on a
|
|
39377
|
+
* type that only needs a name. Password fields are keychain-backed on the
|
|
39378
|
+
* provider addon (`secretStatePaths`), not D634 plaintext.
|
|
39379
|
+
*/
|
|
39380
|
+
configSchema: ConfigSchemaPassthrough.optional()
|
|
39368
39381
|
});
|
|
39369
39382
|
/** One configured account / workspace under a provider type. */
|
|
39370
39383
|
var TrainingProviderEntrySchema = object({
|
|
@@ -39394,7 +39407,30 @@ var TrainingProviderDescriptorSchema = object({
|
|
|
39394
39407
|
dataResidencyNote: string(),
|
|
39395
39408
|
/** Credentials are present — never the values. */
|
|
39396
39409
|
configured: boolean(),
|
|
39397
|
-
defaults: TrainingProviderDefaultsSchema
|
|
39410
|
+
defaults: TrainingProviderDefaultsSchema,
|
|
39411
|
+
/**
|
|
39412
|
+
* Values for {@link TrainingProviderTypeSchema}'s `configSchema` — password
|
|
39413
|
+
* fields are keychain {@link SecretFieldView} or `null` / `''` (create),
|
|
39414
|
+
* never plaintext. Same hydrate contract as settings forms (D789).
|
|
39415
|
+
*/
|
|
39416
|
+
formValues: record(string(), unknown()).optional()
|
|
39417
|
+
});
|
|
39418
|
+
/**
|
|
39419
|
+
* Patch one entry's name, credentials and defaults. Pin with owning `{ addonId }`.
|
|
39420
|
+
* An omitted or empty `tokenSecret` means KEEP the stored secret (D787).
|
|
39421
|
+
* `{ $secretClear: true }` clears it.
|
|
39422
|
+
*/
|
|
39423
|
+
var TrainingProviderUpdateEntryInputSchema = object({
|
|
39424
|
+
entryId: string().min(1),
|
|
39425
|
+
name: string().min(1),
|
|
39426
|
+
tokenId: string().optional(),
|
|
39427
|
+
tokenSecret: union([string(), object({ $secretClear: literal(true) })]).optional(),
|
|
39428
|
+
environment: string().optional(),
|
|
39429
|
+
gpuType: string().optional(),
|
|
39430
|
+
region: string().optional(),
|
|
39431
|
+
costCapUsd: number().nonnegative().optional(),
|
|
39432
|
+
maxRuntimeSec: number().int().positive().optional(),
|
|
39433
|
+
failedDatasetGraceHours: number().nonnegative().optional()
|
|
39398
39434
|
});
|
|
39399
39435
|
var TrainingCredentialCheckSchema = object({
|
|
39400
39436
|
ok: boolean(),
|
|
@@ -39464,6 +39500,9 @@ method(object({}), array(TrainingProviderDescriptorSchema).readonly(), { auth: "
|
|
|
39464
39500
|
}), method(object({ entryId: string().min(1) }), object({ ok: literal(true) }), {
|
|
39465
39501
|
kind: "mutation",
|
|
39466
39502
|
auth: "admin"
|
|
39503
|
+
}), method(TrainingProviderUpdateEntryInputSchema, object({ ok: literal(true) }), {
|
|
39504
|
+
kind: "mutation",
|
|
39505
|
+
auth: "admin"
|
|
39467
39506
|
}), method(object({ entryId: string().min(1) }), TrainingCredentialCheckSchema, {
|
|
39468
39507
|
kind: "mutation",
|
|
39469
39508
|
auth: "admin",
|
|
@@ -47025,6 +47064,12 @@ Object.freeze({
|
|
|
47025
47064
|
addonId: null,
|
|
47026
47065
|
access: "create"
|
|
47027
47066
|
},
|
|
47067
|
+
"trainingProvider.updateEntry": {
|
|
47068
|
+
capName: "training-provider",
|
|
47069
|
+
capScope: "system",
|
|
47070
|
+
addonId: null,
|
|
47071
|
+
access: "create"
|
|
47072
|
+
},
|
|
47028
47073
|
"trainingProvider.uploadDataset": {
|
|
47029
47074
|
capName: "training-provider",
|
|
47030
47075
|
capScope: "system",
|
|
@@ -51570,6 +51615,7 @@ Object.freeze({
|
|
|
51570
51615
|
});
|
|
51571
51616
|
Object.freeze({
|
|
51572
51617
|
"broker": "broker",
|
|
51618
|
+
"calendar-source": "calendar",
|
|
51573
51619
|
"device-export": "device-export",
|
|
51574
51620
|
"llm": "ai",
|
|
51575
51621
|
"mesh-network": "mesh",
|
|
@@ -52629,7 +52675,7 @@ var AgentUIAddon = class extends BaseAddon {
|
|
|
52629
52675
|
capability: adminUiCapability,
|
|
52630
52676
|
provider: {
|
|
52631
52677
|
getStaticDir: async () => ({ staticDir: path.resolve(__dirname) }),
|
|
52632
|
-
getVersion: async () => ({ version: "1.2.
|
|
52678
|
+
getVersion: async () => ({ version: "1.2.217" })
|
|
52633
52679
|
}
|
|
52634
52680
|
}];
|
|
52635
52681
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,o as t,r as n}from"./scheduler-mSeF_D00.js";import{C as r,c as i,d as a,h as o,l as s,p as c,t as l}from"./index-
|
|
1
|
+
import{n as e,o as t,r as n}from"./scheduler-mSeF_D00.js";import{C as r,c as i,d as a,h as o,l as s,p as c,t as l}from"./index-yffMGpE_.js";import{MaskShapeCanvas as u}from"./MaskShapeCanvas-u4Ka7P5T.js";var d=r(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]),f=t(n(),1),p=t(e(),1),m=110,h=`motion-zones`,g=0,_=[1,2,3],v=1,y=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,b=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function x(e,t,n){let r=t*n,i=Array.from({length:r});for(let t=0;t<r;t+=1)i[t]=e[t]===!0;return i}function S(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function C(e,t){return Math.ceil(e/t)}function w(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function T(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:i*a},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)e[r*t+n]===!0&&(o[s*i+w(n,t,i)]=!0)}return o}function E(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:t*n},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)o[r*t+n]=e[s*i+w(n,t,i)]===!0}return o}function D({deviceId:e}){let t=a(o().trpcClient,e),[n,r]=(0,f.useState)(null),[w,D]=(0,f.useState)(!1),[O,k]=(0,f.useState)(null),[A,j]=(0,f.useState)(null),[M,N]=(0,f.useState)(v),[P,F]=(0,f.useState)(!1),[I,L]=(0,f.useState)(!1),R=(0,f.useRef)(!1);(0,f.useEffect)(()=>{if(!t)return;let e=!1;return R.current=!1,r(null),D(!1),k(null),j(null),N(v),L(!1),(async()=>{try{let n=await t.motionZones?.getOptions({});if(e)return;if(!n)throw Error(`device proxy not ready`);if(r(n),R.current)return;let i=await t.motionZones?.getStatus({});if(e)return;if(!i)throw Error(`device proxy not ready`);R.current=!0;let a=i.regions.find(e=>e.shape.kind===`grid`),o=x(a?a.shape.cells:[],n.grid.width,n.grid.height);j(o),k(T(o,n.grid.width,n.grid.height,v))}catch(t){if(e)return;s(t)?D(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[t]);let z=n?n.grid.width:0,B=n?n.grid.height:0,V=C(z,M),H=C(B,M),U=(0,f.useMemo)(()=>O&&n?E(O,z,B,M):null,[O,n,z,B,M]),W=(0,f.useMemo)(()=>U!==null&&A!==null&&!S(U,A),[U,A]),G=(0,f.useMemo)(()=>U?U.reduce((e,t)=>t?e+1:e,0):0,[U]),K=z*B,q=V*H,J=(0,f.useCallback)(e=>{q>0&&k(Array.from({length:q},()=>e))},[q]),Y=(0,f.useCallback)(()=>{k(e=>e&&e.map(e=>!e))},[]),X=(0,f.useCallback)(()=>{A&&n&&k(T(A,z,B,M))},[A,n,z,B,M]),Z=(0,f.useCallback)(e=>{e===M||!n||k(t=>{if(!t)return N(e),t;let n=T(E(t,z,B,M),z,B,e);return N(e),n})},[M,n,z,B]),Q=(0,f.useMemo)(()=>n&&O?[{id:g,shape:{kind:`grid`,gridWidth:V,gridHeight:H,cells:[...O]}}]:[],[n,O,V,H]),$=(0,f.useCallback)((e,t)=>{t.kind===`grid`&&k(t.cells)},[]),ee=(0,f.useCallback)(async()=>{if(!(!t||!O||!n)){F(!0);try{let e=E(O,n.grid.width,n.grid.height,M),r={kind:`grid`,gridWidth:n.grid.width,gridHeight:n.grid.height,cells:e};await t.motionZones?.setZone({patch:{regions:[{id:g,enabled:!0,shape:r}]}});let i=await t.motionZones?.getStatus({});if(i){let e=i.regions.find(e=>e.shape.kind===`grid`),t=x(e?e.shape.cells:[],n.grid.width,n.grid.height);j(t),k(T(t,n.grid.width,n.grid.height,M))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{F(!1)}}},[t,O,n,M]);l((0,f.useMemo)(()=>I&&!w&&n&&O?{id:h,order:m,node:(0,p.jsx)(u,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:V,height:H},selectedId:g,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[I,w,n,O,Q,$,V,H]));let te=!w&&n!==null&&O!==null;return t?(0,p.jsx)(c,{title:`Motion Zones`,icon:(0,p.jsx)(d,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:(0,p.jsx)(`div`,{className:`flex flex-col gap-3`,children:w?(0,p.jsx)(`p`,{className:`${i} leading-relaxed`,children:`This camera doesn't expose an on-board motion zones grid.`}):te?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`p`,{className:`${i} leading-relaxed`,children:[`Toggle `,(0,p.jsx)(`strong`,{className:`text-foreground`,children:`Edit grid`}),` to paint the region directly on the live frame, then `,(0,p.jsx)(`strong`,{className:`text-foreground`,children:`Save`}),` to push the mask to the camera. Pick a bigger`,` `,(0,p.jsx)(`strong`,{className:`text-foreground`,children:`Cell size`}),` for quicker, broad-stroke painting — it's resampled to the camera's native `,n.grid.width,`×`,n.grid.height,` grid on save (×1 is the finest).`]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,p.jsx)(`button`,{type:`button`,onClick:()=>L(e=>!e),disabled:P,"aria-pressed":I,className:I?b:y,children:I?`Done editing`:`Edit grid`}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>J(!0),disabled:P,className:y,children:`All on`}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>J(!1),disabled:P,className:y,children:`All off`}),(0,p.jsx)(`button`,{type:`button`,onClick:Y,disabled:P,className:y,children:`Invert`}),(0,p.jsxs)(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":`Cell size`,children:[(0,p.jsx)(`span`,{className:`${i} mr-0.5`,children:`Cell size`}),_.map(e=>(0,p.jsxs)(`button`,{type:`button`,onClick:()=>Z(e),disabled:P,"aria-pressed":M===e,title:e===1?`Camera grid ${z}×${B} (finest)`:`${C(z,e)}×${C(B,e)} painting grid · cells ×${e} bigger`,className:M===e?b:y,children:[`×`,e]},e))]}),(0,p.jsxs)(`span`,{className:`${i} ml-1 tabular-nums`,children:[G,` / `,K,` cells · `,n.grid.width,`×`,n.grid.height,M===1?``:` · paint ${V}×${H}`]}),(0,p.jsx)(`span`,{className:`flex-1`}),(0,p.jsx)(`button`,{type:`button`,onClick:X,disabled:P||!W,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>void ee(),disabled:P||!W,className:b,children:P?`Saving…`:`Save`})]})]}):(0,p.jsx)(`p`,{className:`${i} leading-relaxed`,children:`Loading the camera's grid…`})})}):null}export{D as MotionZonesSettings};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,o as t,r as n}from"./scheduler-mSeF_D00.js";import{C as r,_ as i,c as a,d as o,g as ee,h as te,l as s,p as c,t as l,x as ne,y as u}from"./index-
|
|
1
|
+
import{n as e,o as t,r as n}from"./scheduler-mSeF_D00.js";import{C as r,_ as i,c as a,d as o,g as ee,h as te,l as s,p as c,t as l,x as ne,y as u}from"./index-yffMGpE_.js";import{MaskShapeCanvas as re}from"./MaskShapeCanvas-u4Ka7P5T.js";var ie=r(`hexagon`,[[`path`,{d:`M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z`,key:`yt0hxn`}]]),d=r(`mic-off`,[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]),f=t(n(),1),p=`Microphone`,m=`The camera encodes no audio at all — live view, recordings, exports and the audio analyzer are all silent.`;function h(e){let t=e.supportsAudioMute===!0,n=t?e.audioEnabled:null,r=e.pendingOn??null;return{label:p,supported:t,on:n===null?null:r??n,available:t&&n!==null,costWhenOff:m}}function ae(e){return!e.available||e.on===null?null:{enabled:!e.on}}var g=t(e(),1),oe=120,_=`privacy-mask`,v=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,y=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function b(e){return e.kind===`rect`||e.kind===`polygon`?e:null}function se(e){let t=new Set(e.map(e=>e.id)),n=0;for(;t.has(n);)n+=1;return n}function ce(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(JSON.stringify(e[n])!==JSON.stringify(t[n]))return!1;return!0}function x({deviceId:e}){let t=o(te().trpcClient,e),[n,r]=(0,f.useState)(null),[p,m]=(0,f.useState)(!1),[x,S]=(0,f.useState)(!1),[C,w]=(0,f.useState)(null),[T,E]=(0,f.useState)(null),[D,O]=(0,f.useState)(!1),[k,A]=(0,f.useState)(!1),[j,M]=(0,f.useState)(null),[N,P]=(0,f.useState)(null),[le,F]=(0,f.useState)(null),[I,L]=(0,f.useState)(null),[R,z]=(0,f.useState)(null),B=(0,f.useRef)(!1);(0,f.useEffect)(()=>{if(!t)return;let e=!1;return B.current=!1,r(null),m(!1),S(!1),w(null),E(null),A(!1),M(null),P(null),F(null),L(null),z(null),(async()=>{try{let n=await t.privacyMask?.getOptions({});if(e)return;if(!n)throw Error(`device proxy not ready`);if(r(n),B.current)return;let i=await t.privacyMask?.getStatus({});if(e)return;if(!i)throw Error(`device proxy not ready`);if(i.regions===null){S(!0),F(i.audioEnabled);return}B.current=!0;let a={enabled:i.enabled,regions:i.regions};E(a),w(a),F(i.audioEnabled)}catch(t){if(e)return;s(t)?m(!0):console.error(`Privacy Mask load failed`,t)}})(),()=>{e=!0}},[t]);let V=(0,f.useMemo)(()=>C!==null&&T!==null&&(C.enabled!==T.enabled||!ce(C.regions,T.regions)),[C,T]),H=C?C.regions.length:0,U=n?n.maxRegions:0,W=(0,f.useRef)(0);(0,f.useEffect)(()=>{W.current=U},[U]);let G=U>0&&H>=U,ue=(0,f.useCallback)(()=>{w(e=>e&&{...e,enabled:!e.enabled})},[]),K=(0,f.useCallback)(e=>{M(typeof e==`number`?e:null)},[]),q=(0,f.useMemo)(()=>C?C.regions.map(e=>({id:e.id,shape:e.shape,enabled:e.enabled,label:`Zone ${String(e.id)}`})):[],[C]),J=(0,f.useCallback)((e,t)=>{let n=b(t);n&&w(t=>t&&{...t,regions:t.regions.map(t=>t.id===e?{...t,shape:n}:t)})},[]),Y=(0,f.useCallback)(e=>{let t=b(e);t&&(P(null),w(e=>{if(!e)return e;let n=W.current;if(n>0&&e.regions.length>=n)return e;let r=se(e.regions),i={id:r,enabled:!0,shape:t};return M(r),{...e,regions:[...e.regions,i]}}))},[]),X=(0,f.useCallback)(e=>{A(!0),M(null),P(e)},[]),de=(0,f.useCallback)(e=>{A(!0),P(null),M(e)},[]),fe=(0,f.useCallback)(e=>{M(t=>t===e?null:t),w(t=>t&&{...t,regions:t.regions.filter(t=>t.id!==e)})},[]),pe=(0,f.useCallback)(()=>{P(null),M(null),T&&w({enabled:T.enabled,regions:T.regions})},[T]),me=(0,f.useCallback)(async()=>{if(!(!t||!C)){O(!0);try{await t.privacyMask?.setMask({patch:{enabled:C.enabled,regions:[...C.regions]}});let e=await t.privacyMask?.getStatus({});if(e&&e.regions!==null){let t={enabled:e.enabled,regions:e.regions};E(t),w(t)}}catch(e){console.error(`Privacy Mask save failed`,e)}finally{O(!1)}}},[t,C]),Z=h({supportsAudioMute:n===null?null:n.supportsAudioMute,audioEnabled:le,pendingOn:I}),he=(0,f.useCallback)(async()=>{let e=ae(Z);if(!(!t||e===null)){L(e.enabled),z(null);try{await t.privacyMask?.setAudioEnabled(e);let n=await t.privacyMask?.getStatus({});n&&F(n.audioEnabled)}catch(e){console.error(`Privacy microphone write failed — reverting`,e),z(e instanceof Error?e.message:String(e))}finally{L(null)}}},[t,Z]),ge=(0,f.useCallback)(()=>{A(e=>(e&&(P(null),M(null)),!e))},[]),Q=n?.supportedShapes??[];l((0,f.useMemo)(()=>k&&!p&&n&&C?{id:_,order:oe,node:(0,g.jsx)(re,{transparent:!0,items:q,supportedShapes:Q,polygonVertices:n.polygonVertices,selectedId:j,onSelect:K,onShapeChange:J,onDrawComplete:Y,drawingKind:N})}:null,[k,p,n,C,q,Q,j,K,J,Y,N]));let _e=n?.supportedShapes.includes(`rect`)??!1,ve=n?.supportedShapes.includes(`polygon`)??!1,$=n!==null&&(n.maxRegions<=0||n.supportedShapes.length===0),ye=!p&&!$&&!x&&n!==null&&C!==null;return t?(0,g.jsx)(c,{title:`Privacy Mask`,icon:(0,g.jsx)(ne,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:(0,g.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[p||$?(0,g.jsx)(`p`,{className:`${a} leading-relaxed`,children:`This camera doesn't support an on-board privacy mask.`}):x?(0,g.jsx)(`p`,{className:`${a} leading-relaxed`,children:`This camera hasn't answered, so what it currently masks is unknown — the editor stays closed rather than showing an empty frame you could save over. A battery camera answers once it wakes; otherwise check that it is reachable.`}):ye?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`p`,{className:`${a} leading-relaxed`,children:[`Toggle `,(0,g.jsx)(`strong`,{className:`text-foreground`,children:`Edit mask`}),` to draw blanked-out zones on the live frame, then `,(0,g.jsx)(`strong`,{className:`text-foreground`,children:`Save`}),` to push them to the camera. Drag a rectangle to move, its corner to resize; drag polygon vertices, click an edge midpoint to add one, or right-click a vertex to remove it.`]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,g.jsx)(`button`,{type:`button`,onClick:ge,disabled:D,"aria-pressed":k,className:k?y:v,children:k?`Done editing`:`Edit mask`}),(0,g.jsx)(`button`,{type:`button`,onClick:ue,disabled:D,"aria-pressed":C.enabled,className:C.enabled?y:v,children:C.enabled?`Mask on`:`Mask off`}),_e&&(0,g.jsx)(`button`,{type:`button`,onClick:()=>X(`rect`),disabled:D||G,"aria-pressed":N===`rect`,className:N===`rect`?y:v,title:G?`Maximum zones reached`:`Add a rectangle zone`,children:`+ Rect`}),ve&&(0,g.jsx)(`button`,{type:`button`,onClick:()=>X(`polygon`),disabled:D||G,"aria-pressed":N===`polygon`,className:N===`polygon`?y:v,title:G?`Maximum zones reached`:`Add a polygon zone`,children:`+ Polygon`}),(0,g.jsxs)(`span`,{className:`${a} ml-1 tabular-nums`,children:[H,` / `,U,` zones`]}),(0,g.jsx)(`span`,{className:`flex-1`}),(0,g.jsx)(`button`,{type:`button`,onClick:pe,disabled:D||!V,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>void me(),disabled:D||!V,className:y,children:D?`Saving…`:`Save`})]}),H>0?(0,g.jsx)(`div`,{className:`flex flex-col gap-1`,children:C.regions.map(e=>{let t=j===e.id,n=e.shape.kind===`polygon`?ie:i;return(0,g.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border px-2 py-1 transition-colors ${t?`border-primary/50 bg-primary/10`:`border-border bg-surface`}`,children:[(0,g.jsxs)(`button`,{type:`button`,onClick:()=>de(e.id),disabled:D,className:`flex flex-1 items-center gap-2 text-left text-[11px] font-medium text-foreground-subtle hover:text-foreground disabled:opacity-40 transition-colors`,children:[(0,g.jsx)(n,{className:`h-3.5 w-3.5 shrink-0`}),(0,g.jsxs)(`span`,{children:[`Zone `,e.id]}),(0,g.jsx)(`span`,{className:`text-foreground-faint capitalize`,children:e.shape.kind})]}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>fe(e.id),disabled:D,"aria-label":`Delete zone ${String(e.id)}`,title:`Delete zone`,className:`inline-flex h-6 w-6 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:border-red-400/40 hover:bg-red-500/10 hover:text-red-400 disabled:opacity-40 transition-colors`,children:(0,g.jsx)(ee,{className:`h-3.5 w-3.5`})})]},e.id)})}):null]}):(0,g.jsx)(`p`,{className:`${a} leading-relaxed`,children:`Loading the camera's privacy mask…`}),Z.supported&&(0,g.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md border border-border bg-surface px-2 py-2`,children:[(0,g.jsx)(`button`,{type:`button`,role:`switch`,"aria-label":Z.label,"aria-checked":Z.on===!0,disabled:!Z.available||I!==null,onClick:()=>void he(),title:Z.on===null?`Microphone — state unknown; the camera did not answer.`:Z.on?`The camera is capturing sound. Turning it off: ${Z.costWhenOff}`:`The camera is silent. ${Z.costWhenOff}`,className:Z.on===!1||Z.on===null?v:y,children:(0,g.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[Z.on===!1?(0,g.jsx)(d,{className:`h-3.5 w-3.5`}):(0,g.jsx)(u,{className:`h-3.5 w-3.5`}),Z.on===null?`Microphone unknown`:Z.on?`Microphone on`:`Microphone off`]})}),(0,g.jsx)(`p`,{className:`text-[10px] text-foreground-subtle flex-1 leading-relaxed`,children:R===null?Z.on===null?`The camera did not report its microphone, so this state is unknown.`:Z.costWhenOff:`Write failed: ${R}`})]})]})}):null}export{x as PrivacyMaskSettings};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,o as t,r as n}from"./scheduler-mSeF_D00.js";import{C as r,S as i,a,b as o,c as s,d as c,f as l,g as u,h as d,i as f,l as p,m,n as h,o as g,r as _,s as v,u as y,v as b}from"./index-CwoBHRjV.js";import{MaskShapeCanvas as x}from"./MaskShapeCanvas-u4Ka7P5T.js";var S=r(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),C=t(n(),1),w=t(e(),1),T=m(`/addon/pipeline-analytics/event-media`);function E(e){return`${T}/m/${e}`}function D(e){let t=new Map;for(let n of e.states)n.references.forEach((e,r)=>{let i=t.get(e.condition)??[];i.push({stateId:n.id,index:r,reference:e}),t.set(e.condition,i)});return[...t.entries()].map(([e,t])=>({condition:e,tiles:[...t].sort((e,t)=>t.reference.capturedAt-e.reference.capturedAt)})).sort((e,t)=>e.condition.localeCompare(t.condition))}function O(e){return e.states.reduce((e,t)=>e+t.references.length,0)}var k=`rounded border border-danger/50 bg-danger/10 px-1 py-0.5 text-[10px] font-medium text-danger hover:bg-danger/20 disabled:opacity-40 transition-colors`;function A({monitor:e,disabled:t,onDelete:n}){let r=D(e),i=O(e),[a,o]=(0,C.useState)(null);return r.length===0?(0,w.jsx)(`p`,{className:`${s} leading-relaxed`,children:`No photographs captured yet. Press “Capture daylight” to take the one this scene will judge everything against.`}):(0,w.jsx)(`div`,{className:`flex flex-col gap-2`,children:r.map(e=>(0,w.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,w.jsxs)(`p`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:[v(e.condition),` · `,e.tiles.length]}),(0,w.jsx)(`ul`,{className:`flex flex-wrap gap-1.5`,children:e.tiles.map(r=>{let c=`${r.stateId}:${String(r.index)}`,l=i===1,d=a===c;return(0,w.jsxs)(`li`,{className:`flex w-24 flex-col gap-1 rounded-md border border-border p-1`,children:[(0,w.jsx)(j,{reference:r.reference}),(0,w.jsx)(`span`,{className:`${s} tabular-nums`,children:M(r.reference.capturedAt)}),(0,w.jsxs)(`button`,{type:`button`,className:k,disabled:t,"aria-label":`Delete the ${v(e.condition).toLowerCase()} photograph from ${M(r.reference.capturedAt)}`,onClick:()=>{if(l&&!d){o(c);return}o(null),n({stateId:r.stateId,index:r.index})},children:[(0,w.jsx)(u,{className:`mr-1 inline h-3 w-3`}),d?`Confirm`:`Delete`]}),d&&(0,w.jsx)(`p`,{className:`text-[10px] leading-snug text-warning`,children:`This is the only photograph this scene has. Delete it and the scene no longer knows what normal looks like — it stops judging until you capture again.`})]},c)})})]},e.condition))})}function j({reference:e}){let[t,n]=(0,C.useState)(!1),r=e.thumbnailMediaId;return r===void 0||t?(0,w.jsxs)(`div`,{className:`flex h-16 w-full flex-col items-center justify-center gap-0.5 rounded bg-surface text-foreground-subtle`,title:`The picture for this reference is no longer stored. The reference itself is intact and still being scored against.`,children:[(0,w.jsx)(o,{className:`h-4 w-4`}),(0,w.jsx)(`span`,{className:`text-[9px]`,children:`no picture`})]}):(0,w.jsx)(`img`,{src:E(r),alt:``,loading:`lazy`,className:`h-16 w-full rounded object-cover`,onError:()=>n(!0)})}function M(e){let t=new Date(e);return`${t.toLocaleDateString()} ${t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}`}var N=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,P=`text-[10px] font-medium text-foreground-subtle`,F=`flex flex-col gap-2 rounded-md border border-border bg-surface/40 p-2`,I=`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle`,L=5,R=3600,z={periodic:`Only on the clock. Predictable, and it notices a change even on a camera nothing ever moves in front of.`,"on-motion":`Only after the camera has been still again for the quiet window below. Cheapest, but a change nobody walks past is never seen.`,both:`Both — the clock is the safety net that lets the motion path miss. This is the right answer for almost every scene.`},B={skip:`Sit that light out. No verdict, no alarm, no flag touched — it picks itself back up when a light it knows returns. This is why the night capture is optional.`,"judge-anyway":`Compare against the references you do have. Only correct when the two lights genuinely look alike (a floodlit driveway, an indoor lamp) — against a real infrared frame it will report a change that did not happen.`};function V(e){return{label:e.label,checkIntervalSec:e.checkIntervalSec??60,threshold:e.check.mode===`similarity`?e.check.threshold:.8,hysteresisCount:e.check.hysteresisCount,quietSeconds:e.quietSeconds,minObservationSpacingSec:e.minObservationSpacingSec,confirmPrompt:e.confirm?.prompt??``}}function H({monitor:e,disabled:t,onPatch:n}){let[r,i]=(0,C.useState)(()=>V(e)),[a,o]=(0,C.useState)(!1);(0,C.useEffect)(()=>{a||i(V(e))},[e,a]);let c=e=>{o(!1),n(e)},l=t=>e.check.mode===`similarity`?{mode:`similarity`,threshold:t.threshold??e.check.threshold,hysteresisCount:t.hysteresisCount??e.check.hysteresisCount}:{...e.check,hysteresisCount:t.hysteresisCount??e.check.hysteresisCount},u=e.confirm?.enabled===!0,d=e.check.mode===`similarity`?e.check.threshold:null;return(0,w.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,w.jsxs)(`div`,{className:F,children:[(0,w.jsx)(`p`,{className:I,children:`What it watches`}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`Name`}),(0,w.jsx)(`input`,{type:`text`,value:r.label,disabled:t,className:N,onFocus:()=>o(!0),onChange:e=>i(t=>({...t,label:e.target.value})),onBlur:()=>{let t=r.label.trim();t.length>0&&t!==e.label?c({label:t}):o(!1)}})]}),(0,w.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.enabled,disabled:t,onChange:e=>c({enabled:e.target.checked})}),(0,w.jsx)(`span`,{className:P,children:`Watching`})]}),(0,w.jsx)(`p`,{className:s,children:`Turned off, the scene keeps its region, its references and its flag — it simply stops checking. Nothing is lost by pausing one for a while.`}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`When to look`}),(0,w.jsxs)(`select`,{value:e.triggerMode,disabled:t,className:N,onChange:e=>{let t=e.target.value;(t===`periodic`||t===`on-motion`||t===`both`)&&c({triggerMode:t})},children:[(0,w.jsx)(`option`,{value:`both`,children:`On the clock and after motion settles`}),(0,w.jsx)(`option`,{value:`periodic`,children:`On the clock only`}),(0,w.jsx)(`option`,{value:`on-motion`,children:`After motion settles only`})]})]}),(0,w.jsx)(`p`,{className:s,children:z[e.triggerMode]}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`Check every (seconds)`}),(0,w.jsx)(`input`,{type:`number`,min:L,max:R,value:r.checkIntervalSec,disabled:t,className:N,onFocus:()=>o(!0),onChange:e=>i(t=>({...t,checkIntervalSec:Number(e.target.value)||0})),onBlur:()=>{let t=U(r.checkIntervalSec,L,R);t===e.checkIntervalSec?o(!1):c({checkIntervalSec:t})}})]}),(0,w.jsx)(`p`,{className:s,children:`60 s suits “is the bin still out”. Every check costs one photograph and one encode, so going below about 30 s buys latency you almost never need and multiplies the cost by the number of scenes you own.`})]}),(0,w.jsxs)(`div`,{className:F,children:[(0,w.jsx)(`p`,{className:I,children:`How sure it has to be`}),e.check.mode===`similarity`&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsxs)(`span`,{className:P,children:[`Match threshold — `,(0,w.jsx)(`span`,{className:`tabular-nums`,children:r.threshold.toFixed(2)})]}),(0,w.jsx)(`input`,{type:`range`,min:.3,max:.99,step:.01,value:r.threshold,disabled:t,onFocus:()=>o(!0),onChange:e=>i(t=>({...t,threshold:Number(e.target.value)})),onMouseUp:()=>{r.threshold===d?o(!1):c({check:l({threshold:r.threshold})})},onBlur:()=>{r.threshold===d?o(!1):c({check:l({threshold:r.threshold})})}})]}),(0,w.jsx)(`p`,{className:`text-[10px] text-foreground-subtle`,children:`How closely the region still has to resemble the photograph to count as unchanged. Higher means fussier: at 0.95 a passing cloud can read as a change; at 0.60 the bin can be taken and the scene will shrug. 0.80 is a sensible start — if it cries wolf, lower it; if it misses the thing you care about, raise it.`})]}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`Agreeing checks before it changes its mind`}),(0,w.jsx)(`input`,{type:`number`,min:1,max:10,value:r.hysteresisCount,disabled:t,className:N,onFocus:()=>o(!0),onChange:e=>i(t=>({...t,hysteresisCount:Number(e.target.value)||1})),onBlur:()=>{let t=U(r.hysteresisCount,1,10);t===e.check.hysteresisCount?o(!1):c({check:l({hysteresisCount:t})})}})]}),(0,w.jsx)(`p`,{className:s,children:`One bad photograph must never be able to flip a scene. 3 agreeing checks at 60 s is about four minutes of latency and is what makes the answer trustworthy — leaving a state costs exactly the same as entering one.`}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`Quiet for (seconds) before a check counts`}),(0,w.jsx)(`input`,{type:`number`,min:0,max:3600,value:r.quietSeconds,disabled:t,className:N,onFocus:()=>o(!0),onChange:e=>i(t=>({...t,quietSeconds:Number(e.target.value)||0})),onBlur:()=>{let t=U(r.quietSeconds,0,3600);t===e.quietSeconds?o(!1):c({quietSeconds:t})}})]}),(0,w.jsx)(`p`,{className:s,children:`A check taken while something is moving is a photograph of the van parked in front of the bin, so it is discarded rather than merely delayed. 0 disables the gate.`}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`Minimum gap between counted checks (seconds)`}),(0,w.jsx)(`input`,{type:`number`,min:0,max:3600,value:r.minObservationSpacingSec,disabled:t,className:N,onFocus:()=>o(!0),onChange:e=>i(t=>({...t,minObservationSpacingSec:Number(e.target.value)||0})),onBlur:()=>{let t=U(r.minObservationSpacingSec,0,3600);t===e.minObservationSpacingSec?o(!1):c({minObservationSpacingSec:t})}})]}),(0,w.jsx)(`p`,{className:s,children:`Spreads the agreeing checks over real time instead of letting three adjacent polls inside one long occlusion be mistaken for three independent opinions.`})]}),(0,w.jsxs)(`div`,{className:F,children:[(0,w.jsx)(`p`,{className:I,children:`Lighting`}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`When a light has no reference of its own`}),(0,w.jsxs)(`select`,{value:e.onUncoveredCondition,disabled:t,className:N,onChange:e=>{let t=e.target.value;(t===`skip`||t===`judge-anyway`)&&c({onUncoveredCondition:t})},children:[(0,w.jsx)(`option`,{value:`skip`,children:`Skip the check (recommended)`}),(0,w.jsx)(`option`,{value:`judge-anyway`,children:`Judge against the other light anyway`})]})]}),(0,w.jsx)(`p`,{className:s,children:B[e.onUncoveredCondition]})]}),(0,w.jsxs)(`div`,{className:F,children:[(0,w.jsx)(`p`,{className:I,children:`What you get told`}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`Notifications follow`}),(0,w.jsxs)(`select`,{value:e.emit,disabled:t,className:N,onChange:e=>{let t=e.target.value;(t===`latched`||t===`live`)&&c({emit:t})},children:[(0,w.jsx)(`option`,{value:`latched`,children:`The flag — told once, still visible at breakfast`}),(0,w.jsx)(`option`,{value:`live`,children:`The live state — follows the region as it changes`})]})]}),(0,w.jsx)(`p`,{className:s,children:`“Is the bin gone” is a flag: you want to be told once and still see it later. “Is the gate open” is a live state.`}),(0,w.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.autoRestore,disabled:t,onChange:e=>c({autoRestore:e.target.checked})}),(0,w.jsx)(`span`,{className:P,children:`Clear the flag by itself when things look normal again`})]}),(0,w.jsx)(`p`,{className:s,children:`Off by default, so an alarm never silently clears itself. The “back to normal” moment is recorded either way, so an automation can still react to it.`})]}),(0,w.jsxs)(`div`,{className:F,children:[(0,w.jsx)(`p`,{className:I,children:`AI double-check`}),(0,w.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:u,disabled:t||r.confirmPrompt.trim().length===0,onChange:e=>c(e.target.checked?{confirm:{...W(r.confirmPrompt.trim()),enabled:!0}}:{confirm:null})}),(0,w.jsx)(`span`,{className:P,children:`Ask a vision model before changing the answer`})]}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`The question to ask`}),(0,w.jsx)(`input`,{type:`text`,value:r.confirmPrompt,placeholder:`e.g. Is the wheelie bin still there?`,disabled:t,className:N,onFocus:()=>o(!0),onChange:e=>i(t=>({...t,confirmPrompt:e.target.value})),onBlur:()=>{let t=r.confirmPrompt.trim();t.length>0&&t!==e.confirm?.prompt?c({confirm:{...W(t),enabled:u}}):o(!1)}})]}),(0,w.jsxs)(`p`,{className:s,children:[`The model is asked `,(0,w.jsx)(`strong`,{children:`only`}),` when the region has already changed enough to flip the answer — roughly twice a week for a bin, not once a minute. It reasons about the object rather than the pixels, so rain, shadows and a repositioned bin stop counting as the thing being taken. If it cannot be reached, the change is held rather than announced.`]})]})]})}function U(e,t,n){return Math.min(n,Math.max(t,e))}function W(e){return{enabled:!1,prompt:e,timeoutMs:8e3,maxImagePx:448,onTimeout:`hold`}}var G=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,K=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`,q=`rounded-md border border-danger/50 bg-danger/10 px-2 py-1 text-[11px] font-medium text-danger hover:bg-danger/20 disabled:opacity-40 transition-colors`,J={alarm:`border-danger/50 bg-danger/15 text-danger`,ok:`border-success/50 bg-success/15 text-success`,unknown:`border-border bg-surface text-foreground-subtle`},Y=.8,X=3;function Z({deviceId:e}){let t=c(d().trpcClient,e),n=l(t?.state.sceneMonitor),r=y(e,{width:640}),[o,m]=(0,C.useState)(null),[T,E]=(0,C.useState)(!1),[D,O]=(0,C.useState)(null),[k,j]=(0,C.useState)(null),[M,N]=(0,C.useState)(null),[P,F]=(0,C.useState)(null),[I,L]=(0,C.useState)(!1),[R,z]=(0,C.useState)(null),[B,V]=(0,C.useState)(``),U=(0,C.useRef)(!0);(0,C.useEffect)(()=>(U.current=!0,()=>{U.current=!1}),[]);let W=(0,C.useCallback)(async()=>{if(t)try{let e=await t.sceneMonitor?.listScenes({});if(!U.current)return;e&&m(e)}catch(e){if(!U.current)return;p(e)?E(!0):j(e instanceof Error?e.message:String(e))}},[t]);(0,C.useEffect)(()=>{m(null),E(!1),j(null),W()},[W]);let Z=n?.monitors??o?.monitors??[],Q=Date.now(),$=(0,C.useCallback)(async(e,t)=>{O(e),j(null);try{await t(),await W()}catch(e){U.current&&j(e instanceof Error?e.message:String(e))}finally{U.current&&O(null)}},[W]),ee=(0,C.useMemo)(()=>{let e=Z.map(e=>({id:e.id,shape:e.roi,label:e.label,enabled:e.enabled}));return R===null?e:[...e,{id:`__draft__`,shape:R,label:`New scene`}]},[Z,R]),te=(0,C.useCallback)((e,n)=>{if(n.kind===`rect`){if(e===`__draft__`){z(n);return}$(`roi-${String(e)}`,async()=>t?.sceneMonitor?.updateScene({monitorId:String(e),patch:{roi:n}}))}},[t,$]),ne=(0,C.useCallback)(e=>{e.kind===`rect`&&z(e)},[]),re=(0,C.useCallback)(async()=>{R===null||B.trim().length===0||(await $(`create`,async()=>{await t?.sceneMonitor?.createScene({label:B.trim(),roi:R,check:{mode:`similarity`,threshold:Y,hysteresisCount:X}})}),z(null),V(``),L(!1))},[t,R,B,$]);return t?(0,w.jsx)(`div`,{className:`flex flex-col gap-3`,children:T?(0,w.jsx)(`p`,{className:`${s} leading-relaxed`,children:`Scene monitoring is not available for this camera.`}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`${s} leading-relaxed`,children:`A scene watches one region of this camera and tells you when it stops looking like the picture you captured. Draw a box around the thing you care about — a wheelie bin, a gate, a parking space — then capture what “normal” looks like. Daylight is enough to start: the night reference is optional, and without it the scene simply sits the infrared hours out instead of reporting a problem.`}),(0,w.jsx)(`div`,{className:`relative overflow-hidden rounded-md border border-border`,children:(0,w.jsx)(x,{items:ee,supportedShapes:[`rect`],selectedId:M??(R===null?null:`__draft__`),onSelect:e=>N(e===null?null:String(e)),onShapeChange:te,onDrawComplete:ne,drawingKind:I&&R===null?`rect`:null,backdrop:r.src===null?null:(0,w.jsx)(`img`,{src:r.src,alt:``,className:`h-full w-full object-contain`,draggable:!1})})}),(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,w.jsx)(`button`,{type:`button`,className:I?K:G,"aria-pressed":I,onClick:()=>{L(e=>!e),z(null)},disabled:D!==null,children:I?`Cancel`:`+ New scene`}),(0,w.jsx)(`button`,{type:`button`,className:G,onClick:r.refresh,disabled:D!==null,children:`Refresh frame`})]}),I&&(0,w.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-2`,children:[(0,w.jsx)(`p`,{className:`text-[10px] text-foreground-subtle`,children:R===null?`Click on the frame to drop a box, then drag its corner to fit it around the thing you want watched.`:`Name it, then create. You capture what “normal” looks like next.`}),R!==null&&a(R)&&(0,w.jsx)(`p`,{className:`text-[11px] leading-relaxed text-warning`,children:`That box covers most of the frame. A scene that big is dominated by the weather, the sky and passing cars — it will quietly stop noticing the thing you actually care about. Draw it tighter.`}),(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`input`,{type:`text`,value:B,onChange:e=>V(e.target.value),placeholder:`e.g. Immondizia prelevata`,className:`flex-1 rounded-md border border-border bg-surface px-2 py-1 text-[12px] text-foreground`}),(0,w.jsx)(`button`,{type:`button`,className:K,onClick:()=>void re(),disabled:R===null||B.trim().length===0||D!==null,children:`Create`})]})]}),k!==null&&(0,w.jsx)(`p`,{className:`text-[11px] leading-relaxed text-danger`,children:k}),Z.length===0?(0,w.jsx)(`p`,{className:`${s} leading-relaxed`,children:`No scenes on this camera yet.`}):(0,w.jsx)(`ul`,{className:`flex flex-col gap-2`,children:Z.map(e=>{let n=_(e);return(0,w.jsxs)(`li`,{className:`flex flex-col gap-1.5 rounded-md border p-2 ${M===e.id?`border-primary/50`:`border-border`}`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`button`,{type:`button`,className:`flex-1 text-left text-[12px] font-medium text-foreground`,onClick:()=>N(e.id),children:e.label}),(0,w.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] font-medium ${J[n.tone]}`,children:n.text})]}),(0,w.jsx)(`p`,{className:`${s} leading-relaxed`,children:g(e,Q)}),(0,w.jsx)(`p`,{className:`${s} tabular-nums`,children:f(e)}),(0,w.jsx)(A,{monitor:e,disabled:D!==null,onDelete:({stateId:n,index:r})=>void $(`refdel-${e.id}-${n}-${String(r)}`,async()=>t.sceneMonitor?.deleteReference({monitorId:e.id,stateId:n,index:r}))}),(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[h.map(n=>{let r=n===`ir`;return(0,w.jsxs)(`button`,{type:`button`,className:G,disabled:D!==null,title:r?`Optional. Without a night reference the checks in infrared are simply skipped — the scene keeps working in daylight and nothing is reported as broken.`:`Take a fresh photo now and store it as the ${v(n).toLowerCase()} reference`,onClick:()=>void $(`cap-${e.id}-${n}`,async()=>t.sceneMonitor?.captureReference({monitorId:e.id,condition:n})),children:[(0,w.jsx)(i,{className:`mr-1 inline h-3 w-3`}),`Capture `,v(n).toLowerCase(),r&&(0,w.jsx)(`span`,{className:`ml-1 text-foreground-subtle/70`,children:`(optional)`})]},n)}),(0,w.jsxs)(`button`,{type:`button`,className:K,disabled:D!==null||e.states.length===0,title:`Clear the flag and re-photograph what normal looks like right now`,onClick:()=>void $(`reset-${e.id}`,async()=>t.sceneMonitor?.resetScene({monitorId:e.id})),children:[(0,w.jsx)(b,{className:`mr-1 inline h-3 w-3`}),`Reset`]}),(0,w.jsx)(`button`,{type:`button`,className:G,disabled:D!==null,onClick:()=>void $(`check-${e.id}`,async()=>t.sceneMonitor?.recheckNow({monitorId:e.id})),children:`Check now`}),(0,w.jsxs)(`button`,{type:`button`,className:P===e.id?K:G,"aria-pressed":P===e.id,"aria-label":`Settings for ${e.label}`,disabled:D!==null,onClick:()=>F(t=>t===e.id?null:e.id),children:[(0,w.jsx)(S,{className:`mr-1 inline h-3 w-3`}),`Settings`]}),(0,w.jsx)(`button`,{type:`button`,className:q,disabled:D!==null,onClick:()=>void $(`del-${e.id}`,async()=>t.sceneMonitor?.deleteScene({monitorId:e.id})),children:(0,w.jsx)(u,{className:`h-3 w-3`})})]}),P===e.id&&(0,w.jsx)(H,{monitor:e,disabled:D!==null,onPatch:n=>void $(`tune-${e.id}`,async()=>t.sceneMonitor?.updateScene({monitorId:e.id,patch:n}))})]},e.id)})})]})}):null}export{Z as SceneMonitorEditor};
|
|
1
|
+
import{n as e,o as t,r as n}from"./scheduler-mSeF_D00.js";import{C as r,S as i,a,b as o,c as s,d as c,f as l,g as u,h as d,i as f,l as p,m,n as h,o as g,r as _,s as v,u as y,v as b}from"./index-yffMGpE_.js";import{MaskShapeCanvas as x}from"./MaskShapeCanvas-u4Ka7P5T.js";var S=r(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),C=t(n(),1),w=t(e(),1),T=m(`/addon/pipeline-analytics/event-media`);function E(e){return`${T}/m/${e}`}function D(e){let t=new Map;for(let n of e.states)n.references.forEach((e,r)=>{let i=t.get(e.condition)??[];i.push({stateId:n.id,index:r,reference:e}),t.set(e.condition,i)});return[...t.entries()].map(([e,t])=>({condition:e,tiles:[...t].sort((e,t)=>t.reference.capturedAt-e.reference.capturedAt)})).sort((e,t)=>e.condition.localeCompare(t.condition))}function O(e){return e.states.reduce((e,t)=>e+t.references.length,0)}var k=`rounded border border-danger/50 bg-danger/10 px-1 py-0.5 text-[10px] font-medium text-danger hover:bg-danger/20 disabled:opacity-40 transition-colors`;function A({monitor:e,disabled:t,onDelete:n}){let r=D(e),i=O(e),[a,o]=(0,C.useState)(null);return r.length===0?(0,w.jsx)(`p`,{className:`${s} leading-relaxed`,children:`No photographs captured yet. Press “Capture daylight” to take the one this scene will judge everything against.`}):(0,w.jsx)(`div`,{className:`flex flex-col gap-2`,children:r.map(e=>(0,w.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,w.jsxs)(`p`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:[v(e.condition),` · `,e.tiles.length]}),(0,w.jsx)(`ul`,{className:`flex flex-wrap gap-1.5`,children:e.tiles.map(r=>{let c=`${r.stateId}:${String(r.index)}`,l=i===1,d=a===c;return(0,w.jsxs)(`li`,{className:`flex w-24 flex-col gap-1 rounded-md border border-border p-1`,children:[(0,w.jsx)(j,{reference:r.reference}),(0,w.jsx)(`span`,{className:`${s} tabular-nums`,children:M(r.reference.capturedAt)}),(0,w.jsxs)(`button`,{type:`button`,className:k,disabled:t,"aria-label":`Delete the ${v(e.condition).toLowerCase()} photograph from ${M(r.reference.capturedAt)}`,onClick:()=>{if(l&&!d){o(c);return}o(null),n({stateId:r.stateId,index:r.index})},children:[(0,w.jsx)(u,{className:`mr-1 inline h-3 w-3`}),d?`Confirm`:`Delete`]}),d&&(0,w.jsx)(`p`,{className:`text-[10px] leading-snug text-warning`,children:`This is the only photograph this scene has. Delete it and the scene no longer knows what normal looks like — it stops judging until you capture again.`})]},c)})})]},e.condition))})}function j({reference:e}){let[t,n]=(0,C.useState)(!1),r=e.thumbnailMediaId;return r===void 0||t?(0,w.jsxs)(`div`,{className:`flex h-16 w-full flex-col items-center justify-center gap-0.5 rounded bg-surface text-foreground-subtle`,title:`The picture for this reference is no longer stored. The reference itself is intact and still being scored against.`,children:[(0,w.jsx)(o,{className:`h-4 w-4`}),(0,w.jsx)(`span`,{className:`text-[9px]`,children:`no picture`})]}):(0,w.jsx)(`img`,{src:E(r),alt:``,loading:`lazy`,className:`h-16 w-full rounded object-cover`,onError:()=>n(!0)})}function M(e){let t=new Date(e);return`${t.toLocaleDateString()} ${t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}`}var N=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,P=`text-[10px] font-medium text-foreground-subtle`,F=`flex flex-col gap-2 rounded-md border border-border bg-surface/40 p-2`,I=`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle`,L=5,R=3600,z={periodic:`Only on the clock. Predictable, and it notices a change even on a camera nothing ever moves in front of.`,"on-motion":`Only after the camera has been still again for the quiet window below. Cheapest, but a change nobody walks past is never seen.`,both:`Both — the clock is the safety net that lets the motion path miss. This is the right answer for almost every scene.`},B={skip:`Sit that light out. No verdict, no alarm, no flag touched — it picks itself back up when a light it knows returns. This is why the night capture is optional.`,"judge-anyway":`Compare against the references you do have. Only correct when the two lights genuinely look alike (a floodlit driveway, an indoor lamp) — against a real infrared frame it will report a change that did not happen.`};function V(e){return{label:e.label,checkIntervalSec:e.checkIntervalSec??60,threshold:e.check.mode===`similarity`?e.check.threshold:.8,hysteresisCount:e.check.hysteresisCount,quietSeconds:e.quietSeconds,minObservationSpacingSec:e.minObservationSpacingSec,confirmPrompt:e.confirm?.prompt??``}}function H({monitor:e,disabled:t,onPatch:n}){let[r,i]=(0,C.useState)(()=>V(e)),[a,o]=(0,C.useState)(!1);(0,C.useEffect)(()=>{a||i(V(e))},[e,a]);let c=e=>{o(!1),n(e)},l=t=>e.check.mode===`similarity`?{mode:`similarity`,threshold:t.threshold??e.check.threshold,hysteresisCount:t.hysteresisCount??e.check.hysteresisCount}:{...e.check,hysteresisCount:t.hysteresisCount??e.check.hysteresisCount},u=e.confirm?.enabled===!0,d=e.check.mode===`similarity`?e.check.threshold:null;return(0,w.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,w.jsxs)(`div`,{className:F,children:[(0,w.jsx)(`p`,{className:I,children:`What it watches`}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`Name`}),(0,w.jsx)(`input`,{type:`text`,value:r.label,disabled:t,className:N,onFocus:()=>o(!0),onChange:e=>i(t=>({...t,label:e.target.value})),onBlur:()=>{let t=r.label.trim();t.length>0&&t!==e.label?c({label:t}):o(!1)}})]}),(0,w.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.enabled,disabled:t,onChange:e=>c({enabled:e.target.checked})}),(0,w.jsx)(`span`,{className:P,children:`Watching`})]}),(0,w.jsx)(`p`,{className:s,children:`Turned off, the scene keeps its region, its references and its flag — it simply stops checking. Nothing is lost by pausing one for a while.`}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`When to look`}),(0,w.jsxs)(`select`,{value:e.triggerMode,disabled:t,className:N,onChange:e=>{let t=e.target.value;(t===`periodic`||t===`on-motion`||t===`both`)&&c({triggerMode:t})},children:[(0,w.jsx)(`option`,{value:`both`,children:`On the clock and after motion settles`}),(0,w.jsx)(`option`,{value:`periodic`,children:`On the clock only`}),(0,w.jsx)(`option`,{value:`on-motion`,children:`After motion settles only`})]})]}),(0,w.jsx)(`p`,{className:s,children:z[e.triggerMode]}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`Check every (seconds)`}),(0,w.jsx)(`input`,{type:`number`,min:L,max:R,value:r.checkIntervalSec,disabled:t,className:N,onFocus:()=>o(!0),onChange:e=>i(t=>({...t,checkIntervalSec:Number(e.target.value)||0})),onBlur:()=>{let t=U(r.checkIntervalSec,L,R);t===e.checkIntervalSec?o(!1):c({checkIntervalSec:t})}})]}),(0,w.jsx)(`p`,{className:s,children:`60 s suits “is the bin still out”. Every check costs one photograph and one encode, so going below about 30 s buys latency you almost never need and multiplies the cost by the number of scenes you own.`})]}),(0,w.jsxs)(`div`,{className:F,children:[(0,w.jsx)(`p`,{className:I,children:`How sure it has to be`}),e.check.mode===`similarity`&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsxs)(`span`,{className:P,children:[`Match threshold — `,(0,w.jsx)(`span`,{className:`tabular-nums`,children:r.threshold.toFixed(2)})]}),(0,w.jsx)(`input`,{type:`range`,min:.3,max:.99,step:.01,value:r.threshold,disabled:t,onFocus:()=>o(!0),onChange:e=>i(t=>({...t,threshold:Number(e.target.value)})),onMouseUp:()=>{r.threshold===d?o(!1):c({check:l({threshold:r.threshold})})},onBlur:()=>{r.threshold===d?o(!1):c({check:l({threshold:r.threshold})})}})]}),(0,w.jsx)(`p`,{className:`text-[10px] text-foreground-subtle`,children:`How closely the region still has to resemble the photograph to count as unchanged. Higher means fussier: at 0.95 a passing cloud can read as a change; at 0.60 the bin can be taken and the scene will shrug. 0.80 is a sensible start — if it cries wolf, lower it; if it misses the thing you care about, raise it.`})]}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`Agreeing checks before it changes its mind`}),(0,w.jsx)(`input`,{type:`number`,min:1,max:10,value:r.hysteresisCount,disabled:t,className:N,onFocus:()=>o(!0),onChange:e=>i(t=>({...t,hysteresisCount:Number(e.target.value)||1})),onBlur:()=>{let t=U(r.hysteresisCount,1,10);t===e.check.hysteresisCount?o(!1):c({check:l({hysteresisCount:t})})}})]}),(0,w.jsx)(`p`,{className:s,children:`One bad photograph must never be able to flip a scene. 3 agreeing checks at 60 s is about four minutes of latency and is what makes the answer trustworthy — leaving a state costs exactly the same as entering one.`}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`Quiet for (seconds) before a check counts`}),(0,w.jsx)(`input`,{type:`number`,min:0,max:3600,value:r.quietSeconds,disabled:t,className:N,onFocus:()=>o(!0),onChange:e=>i(t=>({...t,quietSeconds:Number(e.target.value)||0})),onBlur:()=>{let t=U(r.quietSeconds,0,3600);t===e.quietSeconds?o(!1):c({quietSeconds:t})}})]}),(0,w.jsx)(`p`,{className:s,children:`A check taken while something is moving is a photograph of the van parked in front of the bin, so it is discarded rather than merely delayed. 0 disables the gate.`}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`Minimum gap between counted checks (seconds)`}),(0,w.jsx)(`input`,{type:`number`,min:0,max:3600,value:r.minObservationSpacingSec,disabled:t,className:N,onFocus:()=>o(!0),onChange:e=>i(t=>({...t,minObservationSpacingSec:Number(e.target.value)||0})),onBlur:()=>{let t=U(r.minObservationSpacingSec,0,3600);t===e.minObservationSpacingSec?o(!1):c({minObservationSpacingSec:t})}})]}),(0,w.jsx)(`p`,{className:s,children:`Spreads the agreeing checks over real time instead of letting three adjacent polls inside one long occlusion be mistaken for three independent opinions.`})]}),(0,w.jsxs)(`div`,{className:F,children:[(0,w.jsx)(`p`,{className:I,children:`Lighting`}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`When a light has no reference of its own`}),(0,w.jsxs)(`select`,{value:e.onUncoveredCondition,disabled:t,className:N,onChange:e=>{let t=e.target.value;(t===`skip`||t===`judge-anyway`)&&c({onUncoveredCondition:t})},children:[(0,w.jsx)(`option`,{value:`skip`,children:`Skip the check (recommended)`}),(0,w.jsx)(`option`,{value:`judge-anyway`,children:`Judge against the other light anyway`})]})]}),(0,w.jsx)(`p`,{className:s,children:B[e.onUncoveredCondition]})]}),(0,w.jsxs)(`div`,{className:F,children:[(0,w.jsx)(`p`,{className:I,children:`What you get told`}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`Notifications follow`}),(0,w.jsxs)(`select`,{value:e.emit,disabled:t,className:N,onChange:e=>{let t=e.target.value;(t===`latched`||t===`live`)&&c({emit:t})},children:[(0,w.jsx)(`option`,{value:`latched`,children:`The flag — told once, still visible at breakfast`}),(0,w.jsx)(`option`,{value:`live`,children:`The live state — follows the region as it changes`})]})]}),(0,w.jsx)(`p`,{className:s,children:`“Is the bin gone” is a flag: you want to be told once and still see it later. “Is the gate open” is a live state.`}),(0,w.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.autoRestore,disabled:t,onChange:e=>c({autoRestore:e.target.checked})}),(0,w.jsx)(`span`,{className:P,children:`Clear the flag by itself when things look normal again`})]}),(0,w.jsx)(`p`,{className:s,children:`Off by default, so an alarm never silently clears itself. The “back to normal” moment is recorded either way, so an automation can still react to it.`})]}),(0,w.jsxs)(`div`,{className:F,children:[(0,w.jsx)(`p`,{className:I,children:`AI double-check`}),(0,w.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:u,disabled:t||r.confirmPrompt.trim().length===0,onChange:e=>c(e.target.checked?{confirm:{...W(r.confirmPrompt.trim()),enabled:!0}}:{confirm:null})}),(0,w.jsx)(`span`,{className:P,children:`Ask a vision model before changing the answer`})]}),(0,w.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,w.jsx)(`span`,{className:P,children:`The question to ask`}),(0,w.jsx)(`input`,{type:`text`,value:r.confirmPrompt,placeholder:`e.g. Is the wheelie bin still there?`,disabled:t,className:N,onFocus:()=>o(!0),onChange:e=>i(t=>({...t,confirmPrompt:e.target.value})),onBlur:()=>{let t=r.confirmPrompt.trim();t.length>0&&t!==e.confirm?.prompt?c({confirm:{...W(t),enabled:u}}):o(!1)}})]}),(0,w.jsxs)(`p`,{className:s,children:[`The model is asked `,(0,w.jsx)(`strong`,{children:`only`}),` when the region has already changed enough to flip the answer — roughly twice a week for a bin, not once a minute. It reasons about the object rather than the pixels, so rain, shadows and a repositioned bin stop counting as the thing being taken. If it cannot be reached, the change is held rather than announced.`]})]})]})}function U(e,t,n){return Math.min(n,Math.max(t,e))}function W(e){return{enabled:!1,prompt:e,timeoutMs:8e3,maxImagePx:448,onTimeout:`hold`}}var G=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,K=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`,q=`rounded-md border border-danger/50 bg-danger/10 px-2 py-1 text-[11px] font-medium text-danger hover:bg-danger/20 disabled:opacity-40 transition-colors`,J={alarm:`border-danger/50 bg-danger/15 text-danger`,ok:`border-success/50 bg-success/15 text-success`,unknown:`border-border bg-surface text-foreground-subtle`},Y=.8,X=3;function Z({deviceId:e}){let t=c(d().trpcClient,e),n=l(t?.state.sceneMonitor),r=y(e,{width:640}),[o,m]=(0,C.useState)(null),[T,E]=(0,C.useState)(!1),[D,O]=(0,C.useState)(null),[k,j]=(0,C.useState)(null),[M,N]=(0,C.useState)(null),[P,F]=(0,C.useState)(null),[I,L]=(0,C.useState)(!1),[R,z]=(0,C.useState)(null),[B,V]=(0,C.useState)(``),U=(0,C.useRef)(!0);(0,C.useEffect)(()=>(U.current=!0,()=>{U.current=!1}),[]);let W=(0,C.useCallback)(async()=>{if(t)try{let e=await t.sceneMonitor?.listScenes({});if(!U.current)return;e&&m(e)}catch(e){if(!U.current)return;p(e)?E(!0):j(e instanceof Error?e.message:String(e))}},[t]);(0,C.useEffect)(()=>{m(null),E(!1),j(null),W()},[W]);let Z=n?.monitors??o?.monitors??[],Q=Date.now(),$=(0,C.useCallback)(async(e,t)=>{O(e),j(null);try{await t(),await W()}catch(e){U.current&&j(e instanceof Error?e.message:String(e))}finally{U.current&&O(null)}},[W]),ee=(0,C.useMemo)(()=>{let e=Z.map(e=>({id:e.id,shape:e.roi,label:e.label,enabled:e.enabled}));return R===null?e:[...e,{id:`__draft__`,shape:R,label:`New scene`}]},[Z,R]),te=(0,C.useCallback)((e,n)=>{if(n.kind===`rect`){if(e===`__draft__`){z(n);return}$(`roi-${String(e)}`,async()=>t?.sceneMonitor?.updateScene({monitorId:String(e),patch:{roi:n}}))}},[t,$]),ne=(0,C.useCallback)(e=>{e.kind===`rect`&&z(e)},[]),re=(0,C.useCallback)(async()=>{R===null||B.trim().length===0||(await $(`create`,async()=>{await t?.sceneMonitor?.createScene({label:B.trim(),roi:R,check:{mode:`similarity`,threshold:Y,hysteresisCount:X}})}),z(null),V(``),L(!1))},[t,R,B,$]);return t?(0,w.jsx)(`div`,{className:`flex flex-col gap-3`,children:T?(0,w.jsx)(`p`,{className:`${s} leading-relaxed`,children:`Scene monitoring is not available for this camera.`}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`${s} leading-relaxed`,children:`A scene watches one region of this camera and tells you when it stops looking like the picture you captured. Draw a box around the thing you care about — a wheelie bin, a gate, a parking space — then capture what “normal” looks like. Daylight is enough to start: the night reference is optional, and without it the scene simply sits the infrared hours out instead of reporting a problem.`}),(0,w.jsx)(`div`,{className:`relative overflow-hidden rounded-md border border-border`,children:(0,w.jsx)(x,{items:ee,supportedShapes:[`rect`],selectedId:M??(R===null?null:`__draft__`),onSelect:e=>N(e===null?null:String(e)),onShapeChange:te,onDrawComplete:ne,drawingKind:I&&R===null?`rect`:null,backdrop:r.src===null?null:(0,w.jsx)(`img`,{src:r.src,alt:``,className:`h-full w-full object-contain`,draggable:!1})})}),(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,w.jsx)(`button`,{type:`button`,className:I?K:G,"aria-pressed":I,onClick:()=>{L(e=>!e),z(null)},disabled:D!==null,children:I?`Cancel`:`+ New scene`}),(0,w.jsx)(`button`,{type:`button`,className:G,onClick:r.refresh,disabled:D!==null,children:`Refresh frame`})]}),I&&(0,w.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-2`,children:[(0,w.jsx)(`p`,{className:`text-[10px] text-foreground-subtle`,children:R===null?`Click on the frame to drop a box, then drag its corner to fit it around the thing you want watched.`:`Name it, then create. You capture what “normal” looks like next.`}),R!==null&&a(R)&&(0,w.jsx)(`p`,{className:`text-[11px] leading-relaxed text-warning`,children:`That box covers most of the frame. A scene that big is dominated by the weather, the sky and passing cars — it will quietly stop noticing the thing you actually care about. Draw it tighter.`}),(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`input`,{type:`text`,value:B,onChange:e=>V(e.target.value),placeholder:`e.g. Immondizia prelevata`,className:`flex-1 rounded-md border border-border bg-surface px-2 py-1 text-[12px] text-foreground`}),(0,w.jsx)(`button`,{type:`button`,className:K,onClick:()=>void re(),disabled:R===null||B.trim().length===0||D!==null,children:`Create`})]})]}),k!==null&&(0,w.jsx)(`p`,{className:`text-[11px] leading-relaxed text-danger`,children:k}),Z.length===0?(0,w.jsx)(`p`,{className:`${s} leading-relaxed`,children:`No scenes on this camera yet.`}):(0,w.jsx)(`ul`,{className:`flex flex-col gap-2`,children:Z.map(e=>{let n=_(e);return(0,w.jsxs)(`li`,{className:`flex flex-col gap-1.5 rounded-md border p-2 ${M===e.id?`border-primary/50`:`border-border`}`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`button`,{type:`button`,className:`flex-1 text-left text-[12px] font-medium text-foreground`,onClick:()=>N(e.id),children:e.label}),(0,w.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] font-medium ${J[n.tone]}`,children:n.text})]}),(0,w.jsx)(`p`,{className:`${s} leading-relaxed`,children:g(e,Q)}),(0,w.jsx)(`p`,{className:`${s} tabular-nums`,children:f(e)}),(0,w.jsx)(A,{monitor:e,disabled:D!==null,onDelete:({stateId:n,index:r})=>void $(`refdel-${e.id}-${n}-${String(r)}`,async()=>t.sceneMonitor?.deleteReference({monitorId:e.id,stateId:n,index:r}))}),(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[h.map(n=>{let r=n===`ir`;return(0,w.jsxs)(`button`,{type:`button`,className:G,disabled:D!==null,title:r?`Optional. Without a night reference the checks in infrared are simply skipped — the scene keeps working in daylight and nothing is reported as broken.`:`Take a fresh photo now and store it as the ${v(n).toLowerCase()} reference`,onClick:()=>void $(`cap-${e.id}-${n}`,async()=>t.sceneMonitor?.captureReference({monitorId:e.id,condition:n})),children:[(0,w.jsx)(i,{className:`mr-1 inline h-3 w-3`}),`Capture `,v(n).toLowerCase(),r&&(0,w.jsx)(`span`,{className:`ml-1 text-foreground-subtle/70`,children:`(optional)`})]},n)}),(0,w.jsxs)(`button`,{type:`button`,className:K,disabled:D!==null||e.states.length===0,title:`Clear the flag and re-photograph what normal looks like right now`,onClick:()=>void $(`reset-${e.id}`,async()=>t.sceneMonitor?.resetScene({monitorId:e.id})),children:[(0,w.jsx)(b,{className:`mr-1 inline h-3 w-3`}),`Reset`]}),(0,w.jsx)(`button`,{type:`button`,className:G,disabled:D!==null,onClick:()=>void $(`check-${e.id}`,async()=>t.sceneMonitor?.recheckNow({monitorId:e.id})),children:`Check now`}),(0,w.jsxs)(`button`,{type:`button`,className:P===e.id?K:G,"aria-pressed":P===e.id,"aria-label":`Settings for ${e.label}`,disabled:D!==null,onClick:()=>F(t=>t===e.id?null:e.id),children:[(0,w.jsx)(S,{className:`mr-1 inline h-3 w-3`}),`Settings`]}),(0,w.jsx)(`button`,{type:`button`,className:q,disabled:D!==null,onClick:()=>void $(`del-${e.id}`,async()=>t.sceneMonitor?.deleteScene({monitorId:e.id})),children:(0,w.jsx)(u,{className:`h-3 w-3`})})]}),P===e.id&&(0,w.jsx)(H,{monitor:e,disabled:D!==null,onPatch:n=>void $(`tune-${e.id}`,async()=>t.sceneMonitor?.updateScene({monitorId:e.id,patch:n}))})]},e.id)})})]})}):null}export{Z as SceneMonitorEditor};
|