@7365admin1/core 3.122.4 → 3.122.5

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/index.mjs CHANGED
@@ -64755,6 +64755,9 @@ function padbotPatrolPlan(paths, maps, states = {}) {
64755
64755
  const routeMapId = (p) => {
64756
64756
  if (typeof p?.mapId === "string" && p.mapId)
64757
64757
  return p.mapId;
64758
+ const pointMaps = new Set((Array.isArray(p?.points) ? p.points : []).map((pt) => pt?.mapId).filter((id) => typeof id === "string" && id));
64759
+ if (pointMaps.size === 1)
64760
+ return [...pointMaps][0];
64758
64761
  const names = Array.isArray(p?.points) && p.points.length ? p.points.map((pt) => pt?.targetPointName) : Array.isArray(p?.pointNames) ? p.pointNames : [];
64759
64762
  if (!names.length)
64760
64763
  return p?.mapId;
@@ -64789,7 +64792,10 @@ function padbotPatrolPlan(paths, maps, states = {}) {
64789
64792
  const r = candidates[0];
64790
64793
  r.currentCheckpoint = r.checkpoints.findIndex((c) => c.name === next);
64791
64794
  }
64792
- routes.sort((a, b) => Number(b.currentCheckpoint !== null) - Number(a.currentCheckpoint !== null) || Number(b._default) - Number(a._default));
64795
+ const here = (r) => Number(!!currentMap && r.mapId === currentMap);
64796
+ routes.sort(
64797
+ (a, b) => Number(b.currentCheckpoint !== null) - Number(a.currentCheckpoint !== null) || here(b) - here(a) || Number(b._default) - Number(a._default)
64798
+ );
64793
64799
  for (const r of routes)
64794
64800
  delete r._default;
64795
64801
  return { routes, schedule: [], scheduleShared: false };
@@ -65057,6 +65063,39 @@ function createPadbotAdapter(credentials, options = {}) {
65057
65063
  const n = command?.options?.cleanTimes;
65058
65064
  return Number.isInteger(n) && n >= 1 ? Math.min(n, 99) : 1;
65059
65065
  };
65066
+ async function whereIs(robotSn) {
65067
+ const [st, all, loc] = await Promise.all([
65068
+ states(robotSn),
65069
+ maps(robotSn).catch(() => []),
65070
+ call(PADBOT_PATHS.location, { serialNumber: robotSn }).catch(() => null)
65071
+ ]);
65072
+ const ids2 = [loc?.mapId, st?.["1007"]?.mapId];
65073
+ const map = padbotCurrentMap(all, ids2, st?.["1007"]?.floor);
65074
+ const mapId = map?.mapId ?? ids2.find((id) => typeof id === "string" && id) ?? null;
65075
+ return { st: st ?? {}, all: all ?? [], mapId };
65076
+ }
65077
+ const mapName = (all, id) => {
65078
+ const m = all.find((x) => x?.mapId === id);
65079
+ return String(m?.mapDisplayName || m?.mapName || "another");
65080
+ };
65081
+ async function checkedRoute(robotSn, routeId) {
65082
+ const [paths, where] = await Promise.all([call(PADBOT_PATHS.patrolRoutes, { serialNumber: robotSn }).then(asList), whereIs(robotSn)]);
65083
+ const rawRoute = routeId ? paths.find((p) => p?.pathId === routeId) : paths.find((p) => p?.isDefault);
65084
+ if (!rawRoute) {
65085
+ if (routeId)
65086
+ throw new BadRequestError135(padbotErrorText(2002));
65087
+ return null;
65088
+ }
65089
+ const plan = padbotPatrolPlan(paths, where.all, { ...where.st, "1007": { ...where.st["1007"] ?? {}, mapId: where.mapId } });
65090
+ const route = plan.routes.find((r) => r.id === String(rawRoute.pathId));
65091
+ const routeMap = route?.mapId;
65092
+ if (routeMap && where.mapId && !padbotCanReachMap(where.all, where.mapId, routeMap)) {
65093
+ throw new BadRequestError135(
65094
+ `"${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.`
65095
+ );
65096
+ }
65097
+ return String(rawRoute.pathId);
65098
+ }
65060
65099
  async function sendCommand2(robotSn, command) {
65061
65100
  const sn = { serialNumber: robotSn };
65062
65101
  const call2 = async (path5, body) => {
@@ -65078,14 +65117,18 @@ function createPadbotAdapter(credentials, options = {}) {
65078
65117
  }
65079
65118
  };
65080
65119
  switch (command.kind) {
65081
- case "full":
65082
- await call2(PADBOT_PATHS.patrolStart, { ...sn, patrolCount: rounds(command) });
65120
+ case "full": {
65121
+ const pathId = await checkedRoute(robotSn, null);
65122
+ await call2(PADBOT_PATHS.patrolStart, { ...sn, ...pathId ? { pathId } : {}, patrolCount: rounds(command) });
65083
65123
  return;
65084
- case "area":
65124
+ }
65125
+ case "area": {
65085
65126
  if (command.areas.length !== 1)
65086
65127
  throw new BadRequestError135("Choose one patrol route to start.");
65087
- await call2(PADBOT_PATHS.patrolStart, { ...sn, pathId: command.areas[0], patrolCount: rounds(command) });
65128
+ const pathId = await checkedRoute(robotSn, command.areas[0]);
65129
+ await call2(PADBOT_PATHS.patrolStart, { ...sn, pathId, patrolCount: rounds(command) });
65088
65130
  return;
65131
+ }
65089
65132
  case "patrol-resume":
65090
65133
  await call2(PADBOT_PATHS.patrolResume, sn);
65091
65134
  return;
@@ -65104,8 +65147,8 @@ function createPadbotAdapter(credentials, options = {}) {
65104
65147
  await call2(PADBOT_PATHS.relocate, { ...sn, worldX: command.x, worldY: command.y });
65105
65148
  return;
65106
65149
  case "go-to-point": {
65107
- const [st, all] = await Promise.all([states(robotSn), maps(robotSn).catch(() => [])]);
65108
- if (!padbotCanReachMap(all, st?.["1007"]?.mapId, command.mapId))
65150
+ const where = await whereIs(robotSn);
65151
+ if (!padbotCanReachMap(where.all, where.mapId, command.mapId))
65109
65152
  throw new BadRequestError135(PADBOT_OTHER_MAP_TEXT);
65110
65153
  await call2(PADBOT_PATHS.navigateTarget, { ...sn, mapId: command.mapId, targetPointId: command.targetPointId });
65111
65154
  return;