mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
fix(journey): mark only the days a run reaches as prepared, name trips out of reach, show editors their own status in the day review and say when a fetch is already running
This commit is contained in:
@@ -56,7 +56,7 @@ export class JourneyRecordingsMcp {
|
||||
@Tool({
|
||||
name: 'get_journey_recording_prep',
|
||||
description:
|
||||
"Whether a journey prepares its recorded days from Dawarich in the background (its owner's switch, update_journey auto_prepare_recordings) and how the caller's own last runs over its linked trip periods went: when the last one was tried, when one last came through (the stays waiting at the journey's days are as new as that) and why the last one failed, plus whether the caller's connection can prepare anything at all (ready, sync_off, not_connected). Prepared stays are reviewed and taken over with review_journey_day_stays and take_over_journey_day_stays; nothing is ever written into the journey on its own. Needs edit access to the journey.",
|
||||
"Whether a journey prepares its recorded days from Dawarich in the background (its owner's switch, update_journey auto_prepare_recordings) and how the caller's own last runs over its linked trip periods went: when the last one was tried, when one last came through (the stays waiting at the journey's days are as new as that) and why the last one failed, plus whether the caller's connection can prepare anything at all (ready, sync_off, not_connected) and, while the switch is on, the linked trip periods those runs reach (a trip that ended more than 400 days ago is not prepared; review_journey_day_stays still reads its days by hand). Prepared stays are reviewed and taken over with review_journey_day_stays and take_over_journey_day_stays; nothing is ever written into the journey on its own. Needs edit access to the journey.",
|
||||
inputSchema: { journeyId: idSchema },
|
||||
annotations: TOOL_ANNOTATIONS_READONLY,
|
||||
when: bothAddonsOn,
|
||||
|
||||
@@ -137,17 +137,20 @@ export class JourneyRecordingsService {
|
||||
|
||||
/**
|
||||
* Whether the journey prepares its recorded days (JRN-03) and how the
|
||||
* caller's own last runs over it went, with what their connection allows.
|
||||
* caller's own last runs over it went, with what their connection allows
|
||||
* and, while it is on, which linked trips those runs reach.
|
||||
* Only for those who may edit it: a reader has nothing of theirs prepared.
|
||||
*/
|
||||
async prepStatus(userId: number, journeyId: number): Promise<JourneyRecordingPrep> {
|
||||
const journey = await this.requireEditable(journeyId, userId);
|
||||
await this.requireDawarich();
|
||||
const connection = await this.dawarich.getConnection(userId);
|
||||
const enabled = !!journey.auto_prepare_recordings;
|
||||
return {
|
||||
enabled: !!journey.auto_prepare_recordings,
|
||||
enabled,
|
||||
connection: !connection.connected ? 'not_connected' : connection.syncEnabled ? 'ready' : 'sync_off',
|
||||
...(await this.prep.status(journeyId, userId)),
|
||||
...(enabled ? { periods: await this.prep.periodsOf(journeyId, userId) } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,16 +2,10 @@ import { JourneyRecordingPrep } from '../../db/entities/JourneyRecordingPrep.ent
|
||||
import type { JourneyRecordingPrepRepository } from '../../db/repositories/JourneyRecordingPrep.repository';
|
||||
import { InjectRepository } from '@mikro-orm/nestjs';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { JOURNEY_RECORDING_PREP_REACH_DAYS, type JourneyRecordingPrepPeriod } from '@trek/shared';
|
||||
|
||||
const DAY_MS = 86_400_000;
|
||||
|
||||
/**
|
||||
* How far back a finished trip is still read, as `TripsRepository.listTripsToSync`
|
||||
* reads a person's own trips: a journey must not reach further into the past
|
||||
* than the trip sync it rides on.
|
||||
*/
|
||||
const SYNC_REACH_DAYS = 400;
|
||||
|
||||
/** A journey that prepares its recorded days, with the linked trips the next run reads. */
|
||||
export interface PreparedJourney {
|
||||
journeyId: number;
|
||||
@@ -38,7 +32,7 @@ export class JourneyRecordingPrepService {
|
||||
/** The journeys this person prepares now, each with its linked trips within the sync's reach. */
|
||||
async listFor(userId: number, now: Date = new Date()): Promise<PreparedJourney[]> {
|
||||
const rows = await this.prep.listPreparedTrips(userId, {
|
||||
endedAfter: isoDate(now.getTime() - SYNC_REACH_DAYS * DAY_MS),
|
||||
endedAfter: isoDate(now.getTime() - JOURNEY_RECORDING_PREP_REACH_DAYS * DAY_MS),
|
||||
startedBy: isoDate(now.getTime() + DAY_MS),
|
||||
});
|
||||
const byJourney = new Map<number, PreparedJourney>();
|
||||
@@ -53,6 +47,18 @@ export class JourneyRecordingPrepService {
|
||||
return [...byJourney.values()];
|
||||
}
|
||||
|
||||
/**
|
||||
* The linked trips of one journey this person's runs reach, read as
|
||||
* `listFor` reads them for the sync, so a day is only ever shown as
|
||||
* prepared when a run actually reads it.
|
||||
*/
|
||||
async periodsOf(journeyId: number, userId: number, now: Date = new Date()): Promise<JourneyRecordingPrepPeriod[]> {
|
||||
const journey = (await this.listFor(userId, now)).find((j) => j.journeyId === journeyId);
|
||||
return (journey?.trips ?? []).flatMap((trip) =>
|
||||
trip.start_date ? [{ start: trip.start_date, end: trip.end_date }] : [],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* One run's outcome for a journey and person: `error` is Dawarich's reason,
|
||||
* null when every period came through.
|
||||
|
||||
Reference in New Issue
Block a user