@7365admin1/layer-common 4.160.0 → 4.161.1

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.
@@ -308,8 +308,7 @@ const {
308
308
  getWorkOrders: _getWorkOrders,
309
309
  createWorkOrder,
310
310
  getWorkOrderById,
311
- updateWorkOrder,
312
- deleteWorkOrder,
311
+ // updateWorkOrder, deleteWorkOrder, (retired: PUT / DELETE /api/work-orders/:id are turned off)
313
312
  } = useWorkOrder();
314
313
 
315
314
  const page = ref(1);
@@ -479,7 +478,9 @@ async function submitWorkOrder() {
479
478
  let res: Record<string, any> = {};
480
479
 
481
480
  if (isEditMode.value) {
482
- res = await updateWorkOrder(_workOrderId.value as string, payload);
481
+ // RETIRED 2026-10-29: the old /api/feedbacks and /api/work-orders routes are turned off in API-core; use /api/feedbacks2 and /api/work-orders2.
482
+ // res = await updateWorkOrder(_workOrderId.value as string, payload);
483
+ res = await Promise.reject(new Error("Editing a work order is no longer available here."));
483
484
  } else {
484
485
  res = await createWorkOrder(payload);
485
486
  }
@@ -540,7 +541,9 @@ async function submitDelete() {
540
541
  if (!workOrderToDelete.value) return;
541
542
  submitting.value = true;
542
543
  try {
543
- const response = await deleteWorkOrder(workOrderToDelete.value._id);
544
+ // RETIRED 2026-10-29: the old /api/feedbacks and /api/work-orders routes are turned off in API-core; use /api/feedbacks2 and /api/work-orders2.
545
+ // const response = await deleteWorkOrder(workOrderToDelete.value._id);
546
+ const response: Record<string, any> = await Promise.reject(new Error("Deleting a work order is no longer available here."));
544
547
  showMessage(response.message, "success");
545
548
  await getAllReqRefresh();
546
549
  } catch (error) {
@@ -68,6 +68,27 @@ export default function useCctvEngine() {
68
68
  const eventSnapshot = (id: string) => blobUrl(`/api/cctv-events/${id}/snapshot.jpg`);
69
69
  const eventClip = (id: string) => blobUrl(`/api/cctv-events/${id}/clip.mp4`);
70
70
 
71
+ // ---- smart search (same event rows as listEvents, best match first)
72
+ const searchEvents = (engineId: string, query: Record<string, string | number>) =>
73
+ api(`/api/cctv-engines/${engineId}/search`, { method: "GET", query });
74
+
75
+ // ---- smart detection (custom training). Photos are read as blobs like snapshots.
76
+ const cls = (engineId: string, name?: string) =>
77
+ `/api/cctv-engines/${engineId}/classifiers${name ? "/" + enc(name) : ""}`;
78
+ const listClassifiers = (engineId: string) => api(cls(engineId), { method: "GET" });
79
+ const createClassifier = (engineId: string, body: Record<string, any>) => api(cls(engineId), { method: "POST", body });
80
+ const updateClassifier = (engineId: string, name: string, body: { alertStates: string[] }) =>
81
+ api(cls(engineId, name), { method: "PATCH", body });
82
+ const deleteClassifier = (engineId: string, name: string) => api(cls(engineId, name), { method: "DELETE" });
83
+ const classifierPhotos = (engineId: string, name: string) => api(`${cls(engineId, name)}/photos`, { method: "GET" });
84
+ const classifierPhoto = (engineId: string, name: string, file: string, state?: string) =>
85
+ blobUrl(`${cls(engineId, name)}/photo`, state ? { file, state } : { file });
86
+ const sortClassifierPhoto = (engineId: string, name: string, file: string, state: string) =>
87
+ api(`${cls(engineId, name)}/sort`, { method: "POST", body: { file, state } });
88
+ const discardClassifierPhotos = (engineId: string, name: string, files: string[], state?: string) =>
89
+ api(`${cls(engineId, name)}/discard`, { method: "POST", body: state ? { files, state } : { files } });
90
+ const trainClassifier = (engineId: string, name: string) => api(`${cls(engineId, name)}/train`, { method: "POST" });
91
+
71
92
  // ---- zones & wrong-way rules
72
93
  const getZones = (engineId: string, camera: string) => api(`${cam(engineId, camera)}/zones`, { method: "GET" });
73
94
  const saveZones = (engineId: string, camera: string, body: TZonesBody) =>
@@ -111,6 +132,9 @@ export default function useCctvEngine() {
111
132
  webrtcAnswer, blobUrl, latestImage,
112
133
  listRecordings, cameraClip, createExport, listExports, downloadExport,
113
134
  listEvents, getEvent, eventSnapshot, eventClip,
135
+ searchEvents,
136
+ listClassifiers, createClassifier, updateClassifier, deleteClassifier, classifierPhotos, classifierPhoto,
137
+ sortClassifierPhoto, discardClassifierPhotos, trainClassifier,
114
138
  getZones, saveZones, listWrongWayRules, createWrongWayRule, updateWrongWayRule, deleteWrongWayRule,
115
139
  listPlates, createPlate, updatePlate, deletePlate,
116
140
  listFaces, enrolFace, deleteFace,
@@ -197,11 +197,13 @@ export default function useFeedback() {
197
197
  );
198
198
  }
199
199
 
200
- function deleteFeedback(id: string) {
201
- return useNuxtApp().$api<Record<string, any>>(`/api/feedbacks/${id}`, {
202
- method: "DELETE",
203
- });
204
- }
200
+ // RETIRED 2026-10-29: the old /api/feedbacks and /api/work-orders routes are turned off in API-core; use /api/feedbacks2 and /api/work-orders2.
201
+ // A feedback is deleted with POST /api/feedbacks2/status-update, status "Deleted".
202
+ // function deleteFeedback(id: string) {
203
+ // return useNuxtApp().$api<Record<string, any>>(`/api/feedbacks/${id}`, {
204
+ // method: "DELETE",
205
+ // });
206
+ // }
205
207
 
206
208
  return {
207
209
  feedbacks,
@@ -214,7 +216,7 @@ export default function useFeedback() {
214
216
  getFeedbackById,
215
217
  createFeedback,
216
218
  updateFeedback,
217
- deleteFeedback,
219
+ // deleteFeedback, (retired, see above)
218
220
  updateFeedbackServiceProvider,
219
221
  updateStatusComplete,
220
222
  addFeedBackWorkOrder,
@@ -143,18 +143,20 @@ export default function useWorkOrder() {
143
143
  });
144
144
  }
145
145
 
146
- function updateWorkOrder(id: string, payload: object) {
147
- return useNuxtApp().$api<Record<string, any>>(`/api/work-orders/${id}`, {
148
- method: "PUT",
149
- body: payload,
150
- });
151
- }
152
-
153
- function deleteWorkOrder(id: string) {
154
- return useNuxtApp().$api<Record<string, any>>(`/api/work-orders/${id}`, {
155
- method: "DELETE",
156
- });
157
- }
146
+ // RETIRED 2026-10-29: the old /api/feedbacks and /api/work-orders routes are turned off in API-core; use /api/feedbacks2 and /api/work-orders2.
147
+ // A work order is deleted with POST /api/work-orders2/status-update, status "Deleted".
148
+ // function updateWorkOrder(id: string, payload: object) {
149
+ // return useNuxtApp().$api<Record<string, any>>(`/api/work-orders/${id}`, {
150
+ // method: "PUT",
151
+ // body: payload,
152
+ // });
153
+ // }
154
+ //
155
+ // function deleteWorkOrder(id: string) {
156
+ // return useNuxtApp().$api<Record<string, any>>(`/api/work-orders/${id}`, {
157
+ // method: "DELETE",
158
+ // });
159
+ // }
158
160
 
159
161
  // function deleteWorkOrder(id: string) {
160
162
  // return useNuxtApp().$api<Record<string, any>>(
@@ -194,8 +196,7 @@ export default function useWorkOrder() {
194
196
  updateStatusWorkOrder,
195
197
  getWorkOrders,
196
198
  getWorkOrderById,
197
- updateWorkOrder,
198
- deleteWorkOrder,
199
+ // updateWorkOrder, deleteWorkOrder (retired, see above)
199
200
  getWorkOrderSettings,
200
201
  createWorkOrderSettings,
201
202
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "4.160.0",
5
+ "version": "4.161.1",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
@@ -29,7 +29,9 @@ export type TCctvSection =
29
29
  | "plates"
30
30
  | "faces"
31
31
  | "alerts"
32
- | "engines";
32
+ | "engines"
33
+ | "search"
34
+ | "detections";
33
35
 
34
36
  /** The menu, in the order people use it. `needs` is the permission the server enforces on that screen's routes. */
35
37
  export const CCTV_SECTIONS: { key: TCctvSection; title: string; icon: string; needs: TCctvPermission; face?: boolean }[] = [
@@ -37,7 +39,9 @@ export const CCTV_SECTIONS: { key: TCctvSection; title: string; icon: string; ne
37
39
  { key: "events", title: "Events", icon: "mdi-timeline-clock-outline", needs: CCTV_PERMISSIONS.viewEvents },
38
40
  { key: "playback", title: "Playback & export", icon: "mdi-play-box-outline", needs: CCTV_PERMISSIONS.viewEvents },
39
41
  { key: "zones", title: "Zones & wrong-way", icon: "mdi-vector-polygon", needs: CCTV_PERMISSIONS.manageZones },
42
+ { key: "search", title: "Smart search", icon: "mdi-text-search", needs: CCTV_PERMISSIONS.viewEvents },
40
43
  { key: "plates", title: "Known plates", icon: "mdi-car-info", needs: CCTV_PERMISSIONS.managePlates },
44
+ { key: "detections", title: "Smart detection", icon: "mdi-shape-plus-outline", needs: CCTV_PERMISSIONS.manageZones },
41
45
  { key: "faces", title: "Face library", icon: "mdi-face-recognition", needs: CCTV_PERMISSIONS.manageFaces, face: true },
42
46
  { key: "alerts", title: "Alerts", icon: "mdi-bell-ring-outline", needs: CCTV_PERMISSIONS.manageAlerts },
43
47
  { key: "engines", title: "Engines & health", icon: "mdi-server-network", needs: CCTV_PERMISSIONS.manageEngine },
@@ -84,6 +88,7 @@ export const EVENT_KINDS = [
84
88
  { value: "audio", title: "Sound heard" },
85
89
  { value: "wrong-way", title: "Wrong way" },
86
90
  { value: "review", title: "Review item" },
91
+ { value: "classification", title: "Smart detection" },
87
92
  ];
88
93
  export const EVENT_SEVERITIES = [
89
94
  { value: "alert", title: "Alert" },
@@ -328,3 +333,119 @@ export function summariseHealth(stats: THealthStats | null | undefined): THealth
328
333
  cameras: stats?.cameras ?? [],
329
334
  };
330
335
  }
336
+
337
+ // --------------------------------------------------------------------------- smart search
338
+
339
+ export const SEARCH_MIN = 2;
340
+ export const SEARCH_MAX = 200;
341
+
342
+ /** The words typed in the search box -> what the API takes, or the plain-words problem. */
343
+ export function buildSearchQuery(
344
+ text: string,
345
+ camera?: string | null,
346
+ limit = 24,
347
+ ): { ok: true; query: Record<string, string | number> } | { ok: false; problem: string } {
348
+ const q = (text ?? "").trim().replace(/\s+/g, " ");
349
+ if (q.length < SEARCH_MIN) return { ok: false, problem: `Type at least ${SEARCH_MIN} letters describing what you are looking for.` };
350
+ if (q.length > SEARCH_MAX) return { ok: false, problem: `Keep it under ${SEARCH_MAX} characters.` };
351
+ const query: Record<string, string | number> = { q, limit: Math.min(50, Math.max(1, Math.floor(limit) || 24)) };
352
+ if (camera) query.camera = camera;
353
+ return { ok: true, query };
354
+ }
355
+
356
+ /** Event heading: smart detections read "rubbish (bin_area)", everything else is the object name. */
357
+ export function classificationTitle(e: { kind?: string; label?: string; subLabel?: string }) {
358
+ return e.kind === "classification" && e.subLabel ? `${e.label} (${e.subLabel})` : String(e.label ?? "");
359
+ }
360
+
361
+ // --------------------------------------------------------------------------- smart detection (custom training)
362
+
363
+ export const MIN_PHOTOS_PER_RESULT = 5;
364
+ export const MAX_RESULTS = 10;
365
+ export const DEFAULT_RESULTS = ["clean", "rubbish"];
366
+ const WORD = /^[a-z0-9_]{1,40}$/;
367
+
368
+ /** What a person types ("Bin Area", "Rubbish!") -> the lowercase word the engine takes ("bin_area", "rubbish"). */
369
+ export const toWord = (v: string) =>
370
+ (v ?? "").toString().trim().toLowerCase().replace(/\s+/g, "_").replace(/[^a-z0-9_]/g, "").slice(0, 40);
371
+
372
+ /** Plain-words problem with a detection name, or "". */
373
+ export function detectionNameProblem(name: string): string {
374
+ const w = toWord(name);
375
+ if (!w) return "Give the detection a short name, for example bin_area.";
376
+ if (!WORD.test(w)) return "Use letters, numbers and underscores only (up to 40).";
377
+ return "";
378
+ }
379
+
380
+ /** Plain-words problem with the list of results, or "". "none" is reserved by the engine. */
381
+ export function resultsProblem(states: readonly string[], alertStates: readonly string[] = []): string {
382
+ if (states.length < 2) return "Add at least two results, for example clean and rubbish.";
383
+ if (states.length > MAX_RESULTS) return `Use at most ${MAX_RESULTS} results.`;
384
+ if (new Set(states).size !== states.length) return "Each result must be different.";
385
+ if (states.some((s) => !WORD.test(s) || s === "none")) return 'Results use letters, numbers and underscores only, and "none" is not allowed.';
386
+ if (alertStates.some((a) => !states.includes(a))) return "An alert result must be one of the results.";
387
+ return "";
388
+ }
389
+
390
+ export type TCrop = [number, number, number, number];
391
+ export const MIN_CROP_SIDE = 0.03;
392
+
393
+ /** Mouse drag inside the picture box (pixels) -> [left, top, right, bottom] as 0..1 fractions, clamped and ordered. */
394
+ export function cropFromDrag(
395
+ box: { left: number; top: number; width: number; height: number },
396
+ from: { x: number; y: number },
397
+ to: { x: number; y: number },
398
+ ): TCrop {
399
+ const a = pointFromClick(box, from.x, from.y);
400
+ const b = pointFromClick(box, to.x, to.y);
401
+ return [Math.min(a[0], b[0]), Math.min(a[1], b[1]), Math.max(a[0], b[0]), Math.max(a[1], b[1])];
402
+ }
403
+
404
+ /** Big enough to teach from (each side at least 3% of the picture). */
405
+ export const cropIsUsable = (c: readonly number[] | null | undefined) =>
406
+ !!c && c.length === 4 && c[2] - c[0] >= MIN_CROP_SIDE && c[3] - c[1] >= MIN_CROP_SIDE;
407
+
408
+ export type TClassifier = {
409
+ name: string;
410
+ camera?: string;
411
+ alertStates?: string[];
412
+ states?: string[];
413
+ counts?: Record<string, number>;
414
+ waiting?: number;
415
+ training?: { trained: boolean; lastTrainedAt: string | null; changedSinceTraining: boolean } | null;
416
+ engineUnreachable?: boolean;
417
+ };
418
+
419
+ /** Results that still need more sorted photos. */
420
+ export function shortResults(c: Pick<TClassifier, "states" | "counts">, min = MIN_PHOTOS_PER_RESULT) {
421
+ return (c.states ?? [])
422
+ .map((state) => ({ state, have: c.counts?.[state] ?? 0 }))
423
+ .filter((r) => r.have < min)
424
+ .map((r) => ({ ...r, need: min - r.have }));
425
+ }
426
+
427
+ /** Why Teach is not available yet, in plain words ("" = go ahead). */
428
+ export function teachProblem(c: Pick<TClassifier, "states" | "counts">, min = MIN_PHOTOS_PER_RESULT): string {
429
+ if (!(c.states ?? []).length) return "This detection has no results yet.";
430
+ const short = shortResults(c, min);
431
+ if (!short.length) return "";
432
+ return `Sort at least ${min} photos into each result first. Still needed: ${short.map((r) => `${r.state} (${r.have} of ${min})`).join(", ")}.`;
433
+ }
434
+
435
+ /** One chip for the list: what stage this detection is at. `teaching` = Teach was pressed on this screen and is running. */
436
+ export function classifierStatus(
437
+ c: TClassifier,
438
+ opts: { teaching?: boolean; date?: (iso: string) => string } = {},
439
+ ): { key: "teaching" | "collecting" | "sorting" | "ready" | "trained" | "changed"; title: string; color: string } {
440
+ const date = opts.date ?? ((iso: string) => new Date(iso).toLocaleDateString());
441
+ if (opts.teaching) return { key: "teaching", title: "Teaching...", color: "info" };
442
+ const t = c.training;
443
+ if (t?.trained) {
444
+ if (t.changedSinceTraining) return { key: "changed", title: "Changed since last teaching", color: "warning" };
445
+ return { key: "trained", title: t.lastTrainedAt ? `Trained on ${date(t.lastTrainedAt)}` : "Trained", color: "success" };
446
+ }
447
+ if (!teachProblem(c)) return { key: "ready", title: "Ready to teach", color: "primary" };
448
+ const waiting = c.waiting ?? 0;
449
+ if (waiting > 0) return { key: "sorting", title: `Needs sorting (${waiting} waiting)`, color: "warning" };
450
+ return { key: "collecting", title: "Collecting photos", color: "default" };
451
+ }