mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
fix(assistant): no awaits in loops and no value only used as a type in the journal code
The journal header's tool list was a value read only for its type, so it is a union now. A journey's session reads the entries a call names side by side, the photo announcements go out together, and a photo move links its photos one after another through a promise chain, so each still takes the next place among the target's photos.
This commit is contained in:
@@ -422,15 +422,13 @@ export class AssistantToolSession {
|
||||
*/
|
||||
private async outsideJourney(args: ToolArgs): Promise<string | null> {
|
||||
if (this.pinArg !== JOURNEY_PINNED_ARG) return null;
|
||||
for (const key of JOURNEY_PART_ARGS) {
|
||||
if (args[key] === undefined) continue;
|
||||
const run = await this.callTool(JOURNEY_PART_READ, { entryId: args[key] });
|
||||
const named = JOURNEY_PART_ARGS.filter((key) => args[key] !== undefined);
|
||||
const runs = await Promise.all(named.map((key) => this.callTool(JOURNEY_PART_READ, { entryId: args[key] })));
|
||||
const outside = runs.some((run) => {
|
||||
const journey = (run.value as { journey?: { id?: unknown } } | null)?.journey;
|
||||
if (!run.ok || Number(journey?.id) !== this.pinnedId) {
|
||||
return 'This conversation is about one journey; that entry is not one of its entries.';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return !run.ok || Number(journey?.id) !== this.pinnedId;
|
||||
});
|
||||
return outside ? 'This conversation is about one journey; that entry is not one of its entries.' : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,16 +30,14 @@ export interface JournalHeaderLoaded {
|
||||
}
|
||||
|
||||
/** The tools these cards are for. */
|
||||
const JOURNAL_HEADER_TOOLS = [
|
||||
'create_journey',
|
||||
'update_journey',
|
||||
'delete_journey',
|
||||
'add_journey_trip',
|
||||
'remove_journey_trip',
|
||||
'restore_journey_suggestions',
|
||||
'update_journey_preferences',
|
||||
] as const;
|
||||
type HeaderTool = (typeof JOURNAL_HEADER_TOOLS)[number];
|
||||
type HeaderTool =
|
||||
| 'create_journey'
|
||||
| 'update_journey'
|
||||
| 'delete_journey'
|
||||
| 'add_journey_trip'
|
||||
| 'remove_journey_trip'
|
||||
| 'restore_journey_suggestions'
|
||||
| 'update_journey_preferences';
|
||||
|
||||
/** The journal a call names, or none in a journey's own conversation, where the session pins it. */
|
||||
export function journeyArgs(args: ToolArgs): ToolArgs {
|
||||
|
||||
@@ -64,12 +64,14 @@ export class JourneyPhotoLinksService {
|
||||
const ids = [...new Set(req.photoIds)];
|
||||
if (ids.some((id) => !onSource.has(id))) throw badRequest('Every photo must be one of this entry');
|
||||
const kept = req.keep_in_source === true;
|
||||
await this.uow.transactional(async () => {
|
||||
for (const id of ids) {
|
||||
// One after another: each link takes the next place among the target's photos.
|
||||
await this.uow.transactional(() =>
|
||||
ids.reduce<Promise<void>>(async (previous, id) => {
|
||||
await previous;
|
||||
if (!(await this.journeys.linkPhotoToEntry(req.toEntryId, id, userId))) throw notFound('Entry not found');
|
||||
if (!kept) await this.journeys.unlinkPhotoFromEntry(fromEntryId, id, userId);
|
||||
}
|
||||
});
|
||||
}, Promise.resolve()),
|
||||
);
|
||||
await this.announce([fromEntryId, req.toEntryId], sid);
|
||||
return { moved: ids, fromEntryId, toEntryId: req.toEntryId, kept };
|
||||
}
|
||||
@@ -118,8 +120,10 @@ export class JourneyPhotoLinksService {
|
||||
private async announce(entryIds: number[], sid?: string): Promise<void> {
|
||||
const journeyId = await this.journeys.journeyIdOfEntry(entryIds[0]);
|
||||
if (journeyId === null) return;
|
||||
for (const entryId of new Set(entryIds)) {
|
||||
await this.journeys.broadcastJourneyEvent(journeyId, 'journey:entry:updated', { entryId }, sid);
|
||||
}
|
||||
await Promise.all(
|
||||
[...new Set(entryIds)].map((entryId) =>
|
||||
this.journeys.broadcastJourneyEvent(journeyId, 'journey:entry:updated', { entryId }, sid),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user