feat(assistant): one AI tile for assistant, parsing and MCP, a planner-aware chat

The three AI addons share one tile in the integration column; a dialog holds
the connection, the assistant's limits and AI parsing, which now reads with
the assistant's connection unless an install keeps its own. Existing parsing
configs stay where they are and keep winning.

The chat sees the map on screen, offers next questions under an answer,
shows its live step in the window head, previews waiting changes inside the
day list, checks whether a day still works, folds a multi-day plan into a
week grid, keeps per-trip notes and can estimate costs. An empty or cut-off
answer gets one push instead of ending silently, and the assistant's own
step and size limits are raised.
This commit is contained in:
Maurice
2026-10-21 20:55:06 +02:00
parent b64da26651
commit 123e27643d
142 changed files with 5456 additions and 1572 deletions
@@ -40,7 +40,7 @@ describe('assistantChatRequestSchema', () => {
it('refuses blank or overlong text, a bad thread id and unknown keys', () => {
expect(assistantChatRequestSchema.safeParse({ ...ctx, threadId: null, text: ' ' }).success).toBe(false);
expect(assistantChatRequestSchema.safeParse({ ...ctx, threadId: null, text: 'x'.repeat(4001) }).success).toBe(
expect(assistantChatRequestSchema.safeParse({ ...ctx, threadId: null, text: 'x'.repeat(32_001) }).success).toBe(
false,
);
expect(assistantChatRequestSchema.safeParse({ ...ctx, threadId: 0, text: 'hi' }).success).toBe(false);
@@ -84,7 +84,7 @@ describe('assistantDecisionsRequestSchema', () => {
expect(assistantDecisionsRequestSchema.safeParse({ ...ctx, decisions: [decision] }).success).toBe(true);
expect(assistantDecisionsRequestSchema.safeParse({ ...ctx, decisions: [] }).success).toBe(false);
expect(
assistantDecisionsRequestSchema.safeParse({ ...ctx, decisions: Array.from({ length: 13 }, () => decision) })
assistantDecisionsRequestSchema.safeParse({ ...ctx, decisions: Array.from({ length: 51 }, () => decision) })
.success,
).toBe(false);
});
@@ -225,8 +225,8 @@ describe('mentions in a chat request', () => {
{ kind: 'reservation', id: 2 },
];
expect(assistantChatRequestSchema.safeParse({ ...base, mentions }).success).toBe(true);
const eleven = Array.from({ length: 11 }, () => ({ kind: 'place', id: 4 }));
expect(assistantChatRequestSchema.safeParse({ ...base, mentions: eleven }).success).toBe(false);
const tooMany = Array.from({ length: 51 }, () => ({ kind: 'place', id: 4 }));
expect(assistantChatRequestSchema.safeParse({ ...base, mentions: tooMany }).success).toBe(false);
const labelled = [{ kind: 'place', id: 4, label: 'Louvre' }];
expect(assistantChatRequestSchema.safeParse({ ...base, mentions: labelled }).success).toBe(false);
expect(assistantChatRequestSchema.safeParse({ ...base, mentions: [{ kind: 'trip', id: 4 }] }).success).toBe(false);
@@ -325,11 +325,11 @@ describe('assistantFoundPlaceSchema', () => {
expect(withPlace({ kind: 'casino' }).success).toBe(false);
});
it('holds at most eight places to a step and counts the rest', () => {
const places = Array.from({ length: 9 }, (_, i) => ({ ...place, ref: `toolu_01:${i}` }));
it('holds at most twenty places to a step and counts the rest', () => {
const places = Array.from({ length: 21 }, (_, i) => ({ ...place, ref: `toolu_01:${i}` }));
const step = (body: Record<string, unknown>) =>
assistantPlacesSchema.safeParse({ toolCallId: 'toolu_01', ...body });
expect(step({ places: places.slice(0, 8), more: 1 }).success).toBe(true);
expect(step({ places: places.slice(0, 20), more: 1 }).success).toBe(true);
expect(step({ places, more: 0 }).success).toBe(false);
expect(step({ places: [], more: -1 }).success).toBe(false);
});
+26 -8
View File
@@ -32,6 +32,8 @@ export const ASSISTANT_ERROR_CODES = [
'invalid_key',
'provider_unavailable',
'max_steps',
// The model answered with nothing, not even after it was asked to go on.
'empty_answer',
'offline',
'no_bookings_found',
'import_unavailable',
@@ -128,11 +130,21 @@ export const assistantMentionSchema = z
.strict();
export type AssistantMention = z.infer<typeof assistantMentionSchema>;
/** What the user is looking at when they ask: the selected day, or the places they asked about. */
/** The part of the map the planner shows, so "here" and "nearby" mean what is on screen. */
export const assistantMapViewSchema = z
.object({ south: latSchema, west: lngSchema, north: latSchema, east: lngSchema })
.strict();
export type AssistantMapView = z.infer<typeof assistantMapViewSchema>;
/**
* What the user is looking at when they ask: the selected day, or the places
* they asked about, and the part of the map on screen.
*/
export const assistantFocusSchema = z
.object({
dayId: idSchema.optional(),
placeIds: z.array(idSchema).max(20).optional(),
view: assistantMapViewSchema.optional(),
})
.strict();
export type AssistantFocus = z.infer<typeof assistantFocusSchema>;
@@ -148,9 +160,9 @@ export type AssistantClientCtx = z.infer<typeof assistantClientCtxSchema>;
export const assistantChatRequestSchema = assistantClientCtxSchema
.extend({
threadId: idSchema.nullable(),
text: z.string().trim().min(1).max(4000),
text: z.string().trim().min(1).max(32_000),
focus: assistantFocusSchema.optional(),
mentions: z.array(assistantMentionSchema).max(10).optional(),
mentions: z.array(assistantMentionSchema).max(50).optional(),
})
.strict();
export type AssistantChatRequest = z.infer<typeof assistantChatRequestSchema>;
@@ -179,7 +191,7 @@ export type AssistantDecision = z.infer<typeof assistantDecisionSchema>;
/** POST /threads/:threadId/decisions: every change the step holds, applied or discarded. */
export const assistantDecisionsRequestSchema = assistantClientCtxSchema
.extend({
decisions: z.array(assistantDecisionSchema).min(1).max(12),
decisions: z.array(assistantDecisionSchema).min(1).max(50),
})
.strict();
export type AssistantDecisionsRequest = z.infer<typeof assistantDecisionsRequestSchema>;
@@ -299,9 +311,15 @@ export const assistantFoundPlaceSchema = z.object({
kind: z.enum(ASSISTANT_FOUND_PLACE_KINDS).nullable(),
rating: z.number().min(0).max(5).nullable(),
openNow: z.boolean().nullable(),
googlePlaceId: z.string().regex(/^[\w-]{1,200}$/).nullable(),
googlePlaceId: z
.string()
.regex(/^[\w-]{1,200}$/)
.nullable(),
osmId: z.string().max(40).nullable(),
photoKey: z.string().regex(/^([\w-]{1,200}|coords:-?\d{1,3}(\.\d{1,12})?,-?\d{1,3}(\.\d{1,12})?)$/).nullable(),
photoKey: z
.string()
.regex(/^([\w-]{1,200}|coords:-?\d{1,3}(\.\d{1,12})?,-?\d{1,3}(\.\d{1,12})?)$/)
.nullable(),
inTripPlaceId: idSchema.nullable(),
});
export type AssistantFoundPlace = z.infer<typeof assistantFoundPlaceSchema>;
@@ -309,7 +327,7 @@ export type AssistantFoundPlace = z.infer<typeof assistantFoundPlaceSchema>;
/** The places one search step found: at most eight, `more` counts the rest. */
export const assistantPlacesSchema = z.object({
toolCallId: z.string().max(64),
places: z.array(assistantFoundPlaceSchema).max(8),
places: z.array(assistantFoundPlaceSchema).max(20),
more: z.number().int().nonnegative(),
});
export type AssistantPlaces = z.infer<typeof assistantPlacesSchema>;
@@ -375,7 +393,7 @@ export const assistantMentionsSchema = z.object({
label: z.string().max(120),
}),
)
.max(10),
.max(50),
});
export type AssistantMentions = z.infer<typeof assistantMentionsSchema>;