@7365admin1/core 3.99.1-staging.405 → 3.99.1-staging.406

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.
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@7365admin1/core": patch
3
+ ---
4
+
5
+ PadBot: Start patrol checks the route against the map the robot is on before sending (the default route on another map was accepted by PadBot and the robot stayed idle); routes take their map from their points; routes on the robot's map are listed first; go to point uses the location read's map.
package/dist/index.js CHANGED
@@ -67064,6 +67064,9 @@ function padbotPatrolPlan(paths, maps, states = {}) {
67064
67064
  const routeMapId = (p) => {
67065
67065
  if (typeof p?.mapId === "string" && p.mapId)
67066
67066
  return p.mapId;
67067
+ const pointMaps = new Set((Array.isArray(p?.points) ? p.points : []).map((pt) => pt?.mapId).filter((id) => typeof id === "string" && id));
67068
+ if (pointMaps.size === 1)
67069
+ return [...pointMaps][0];
67067
67070
  const names = Array.isArray(p?.points) && p.points.length ? p.points.map((pt) => pt?.targetPointName) : Array.isArray(p?.pointNames) ? p.pointNames : [];
67068
67071
  if (!names.length)
67069
67072
  return p?.mapId;
@@ -67098,7 +67101,10 @@ function padbotPatrolPlan(paths, maps, states = {}) {
67098
67101
  const r = candidates[0];
67099
67102
  r.currentCheckpoint = r.checkpoints.findIndex((c) => c.name === next);
67100
67103
  }
67101
- routes.sort((a, b) => Number(b.currentCheckpoint !== null) - Number(a.currentCheckpoint !== null) || Number(b._default) - Number(a._default));
67104
+ const here = (r) => Number(!!currentMap && r.mapId === currentMap);
67105
+ routes.sort(
67106
+ (a, b) => Number(b.currentCheckpoint !== null) - Number(a.currentCheckpoint !== null) || here(b) - here(a) || Number(b._default) - Number(a._default)
67107
+ );
67102
67108
  for (const r of routes)
67103
67109
  delete r._default;
67104
67110
  return { routes, schedule: [], scheduleShared: false };
@@ -67366,6 +67372,39 @@ function createPadbotAdapter(credentials, options = {}) {
67366
67372
  const n = command?.options?.cleanTimes;
67367
67373
  return Number.isInteger(n) && n >= 1 ? Math.min(n, 99) : 1;
67368
67374
  };
67375
+ async function whereIs(robotSn) {
67376
+ const [st, all, loc] = await Promise.all([
67377
+ states(robotSn),
67378
+ maps(robotSn).catch(() => []),
67379
+ call(PADBOT_PATHS.location, { serialNumber: robotSn }).catch(() => null)
67380
+ ]);
67381
+ const ids2 = [loc?.mapId, st?.["1007"]?.mapId];
67382
+ const map = padbotCurrentMap(all, ids2, st?.["1007"]?.floor);
67383
+ const mapId = map?.mapId ?? ids2.find((id) => typeof id === "string" && id) ?? null;
67384
+ return { st: st ?? {}, all: all ?? [], mapId };
67385
+ }
67386
+ const mapName = (all, id) => {
67387
+ const m = all.find((x) => x?.mapId === id);
67388
+ return String(m?.mapDisplayName || m?.mapName || "another");
67389
+ };
67390
+ async function checkedRoute(robotSn, routeId) {
67391
+ const [paths, where] = await Promise.all([call(PADBOT_PATHS.patrolRoutes, { serialNumber: robotSn }).then(asList), whereIs(robotSn)]);
67392
+ const rawRoute = routeId ? paths.find((p) => p?.pathId === routeId) : paths.find((p) => p?.isDefault);
67393
+ if (!rawRoute) {
67394
+ if (routeId)
67395
+ throw new import_node_server_utils162.BadRequestError(padbotErrorText(2002));
67396
+ return null;
67397
+ }
67398
+ const plan = padbotPatrolPlan(paths, where.all, { ...where.st, "1007": { ...where.st["1007"] ?? {}, mapId: where.mapId } });
67399
+ const route = plan.routes.find((r) => r.id === String(rawRoute.pathId));
67400
+ const routeMap = route?.mapId;
67401
+ if (routeMap && where.mapId && !padbotCanReachMap(where.all, where.mapId, routeMap)) {
67402
+ throw new import_node_server_utils162.BadRequestError(
67403
+ `"${rawRoute.pathName || "That route"}" is on the ${mapName(where.all, routeMap)} map, but the robot is on ${mapName(where.all, where.mapId)}. Pick a route on the robot's map.`
67404
+ );
67405
+ }
67406
+ return String(rawRoute.pathId);
67407
+ }
67369
67408
  async function sendCommand2(robotSn, command) {
67370
67409
  const sn = { serialNumber: robotSn };
67371
67410
  const call2 = async (path5, body) => {
@@ -67387,14 +67426,18 @@ function createPadbotAdapter(credentials, options = {}) {
67387
67426
  }
67388
67427
  };
67389
67428
  switch (command.kind) {
67390
- case "full":
67391
- await call2(PADBOT_PATHS.patrolStart, { ...sn, patrolCount: rounds(command) });
67429
+ case "full": {
67430
+ const pathId = await checkedRoute(robotSn, null);
67431
+ await call2(PADBOT_PATHS.patrolStart, { ...sn, ...pathId ? { pathId } : {}, patrolCount: rounds(command) });
67392
67432
  return;
67393
- case "area":
67433
+ }
67434
+ case "area": {
67394
67435
  if (command.areas.length !== 1)
67395
67436
  throw new import_node_server_utils162.BadRequestError("Choose one patrol route to start.");
67396
- await call2(PADBOT_PATHS.patrolStart, { ...sn, pathId: command.areas[0], patrolCount: rounds(command) });
67437
+ const pathId = await checkedRoute(robotSn, command.areas[0]);
67438
+ await call2(PADBOT_PATHS.patrolStart, { ...sn, pathId, patrolCount: rounds(command) });
67397
67439
  return;
67440
+ }
67398
67441
  case "patrol-resume":
67399
67442
  await call2(PADBOT_PATHS.patrolResume, sn);
67400
67443
  return;
@@ -67413,8 +67456,8 @@ function createPadbotAdapter(credentials, options = {}) {
67413
67456
  await call2(PADBOT_PATHS.relocate, { ...sn, worldX: command.x, worldY: command.y });
67414
67457
  return;
67415
67458
  case "go-to-point": {
67416
- const [st, all] = await Promise.all([states(robotSn), maps(robotSn).catch(() => [])]);
67417
- if (!padbotCanReachMap(all, st?.["1007"]?.mapId, command.mapId))
67459
+ const where = await whereIs(robotSn);
67460
+ if (!padbotCanReachMap(where.all, where.mapId, command.mapId))
67418
67461
  throw new import_node_server_utils162.BadRequestError(PADBOT_OTHER_MAP_TEXT);
67419
67462
  await call2(PADBOT_PATHS.navigateTarget, { ...sn, mapId: command.mapId, targetPointId: command.targetPointId });
67420
67463
  return;