fix(chat): stabilize assistant add flow and location routing
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import { createEventDispatcher, onMount } from 'svelte';
|
||||
import { t } from 'svelte-i18n';
|
||||
import { mdiSend, mdiPlus, mdiDelete, mdiMenu, mdiClose } from '@mdi/js';
|
||||
import type { ChatProviderCatalogEntry } from '$lib/types.js';
|
||||
import type { ChatProviderCatalogEntry, CollectionItineraryItem, Location } from '$lib/types.js';
|
||||
import { addToast } from '$lib/toasts';
|
||||
|
||||
type ToolResultEntry = {
|
||||
@@ -82,7 +82,7 @@
|
||||
|
||||
const dispatch = createEventDispatcher<{
|
||||
close: void;
|
||||
itemAdded: { locationId: string; date: string };
|
||||
itemAdded: { location: Location; itineraryItem: CollectionItineraryItem; date: string };
|
||||
}>();
|
||||
|
||||
const MODEL_PREFS_STORAGE_KEY = 'voyage_chat_model_prefs';
|
||||
@@ -620,7 +620,9 @@
|
||||
throw new Error('Failed to add to itinerary');
|
||||
}
|
||||
|
||||
dispatch('itemAdded', { locationId: location.id, date });
|
||||
const itineraryItem = await itineraryResponse.json();
|
||||
|
||||
dispatch('itemAdded', { location, itineraryItem, date });
|
||||
addToast('success', $t('added_successfully'));
|
||||
closeDateSelector();
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
<script lang="ts">
|
||||
import type { Collection, ContentImage, Location, Collaborator, Lodging } from '$lib/types';
|
||||
import type {
|
||||
Collection,
|
||||
ContentImage,
|
||||
Location,
|
||||
Collaborator,
|
||||
Lodging,
|
||||
CollectionItineraryItem
|
||||
} from '$lib/types';
|
||||
import { onMount } from 'svelte';
|
||||
import type { PageData } from './$types';
|
||||
import { goto } from '$app/navigation';
|
||||
@@ -90,6 +97,33 @@
|
||||
collection = { ...collection }; // trigger reactivity so cost summary & UI refresh immediately
|
||||
}
|
||||
|
||||
type AssistantItemAddedDetail = {
|
||||
location: Location;
|
||||
itineraryItem: CollectionItineraryItem;
|
||||
date: string;
|
||||
};
|
||||
|
||||
function handleAssistantItemAdded(event: CustomEvent<AssistantItemAddedDetail>) {
|
||||
const { location, itineraryItem } = event.detail;
|
||||
|
||||
upsertCollectionItem('locations', location);
|
||||
|
||||
if (!itineraryItem || itineraryItem.id === undefined || itineraryItem.id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const items = collection.itinerary || [];
|
||||
const exists = items.some((entry) => String(entry.id) === String(itineraryItem.id));
|
||||
collection = {
|
||||
...collection,
|
||||
itinerary: exists
|
||||
? items.map((entry) =>
|
||||
String(entry.id) === String(itineraryItem.id) ? itineraryItem : entry
|
||||
)
|
||||
: [...items, itineraryItem]
|
||||
};
|
||||
}
|
||||
|
||||
// Helper to upload prefilled images (temp ids starting with 'rec-') sequentially
|
||||
async function importPrefilledImagesForItem(
|
||||
item: any,
|
||||
@@ -1314,6 +1348,7 @@
|
||||
startDate={collection.start_date || undefined}
|
||||
endDate={collection.end_date || undefined}
|
||||
destination={collectionDestination}
|
||||
on:itemAdded={handleAssistantItemAdded}
|
||||
/>
|
||||
<CollectionRecommendationView bind:collection user={data.user} />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user