mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 07:07:31 +00:00
feat(assistant): trip assistant chat with your own AI connection
Adds an in-app assistant that reads and plans the open trip. Users connect their own provider (Sign in with ChatGPT, or an Anthropic, OpenAI, Gemini or OpenRouter key) or use the one the admin set up, including a custom OpenAI-compatible server. It is an addon and only shows while a connection is usable. The chat runs on the existing MCP tools, pinned to the trip. Every change is held as a change card the user applies or discards, and applied changes can be undone. On the desktop it is a floating window that can be moved and resized; on the phone it is fullscreen. Search results show as place cards that can go onto a day, weather lookups as a strip, proposed places as ghost markers on the map with a before/after switch, and an answer can be shared into the trip chat. Booking files can be dropped in and are read into change cards.
This commit is contained in:
@@ -7,6 +7,8 @@ import {
|
||||
collabLinkUpdateRequestSchema,
|
||||
collabMessageCreateRequestSchema,
|
||||
collabReactionRequestSchema,
|
||||
collabMessageSchema,
|
||||
COLLAB_MESSAGE_ORIGIN_ASSISTANT,
|
||||
} from './collab.schema';
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
@@ -106,3 +108,34 @@ describe('collabReactionRequestSchema', () => {
|
||||
expect(collabReactionRequestSchema.safeParse({ emoji: '' }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('collabMessageSchema', () => {
|
||||
const message = {
|
||||
id: 1,
|
||||
trip_id: 2,
|
||||
user_id: 3,
|
||||
text: 'See you at the station',
|
||||
reply_to: null,
|
||||
created_at: '2026-10-21 08:00:00',
|
||||
deleted: null,
|
||||
username: 'ana',
|
||||
avatar: null,
|
||||
reply_text: null,
|
||||
reply_username: null,
|
||||
user_avatar: null,
|
||||
avatar_url: null,
|
||||
reactions: [],
|
||||
attachments: [],
|
||||
};
|
||||
|
||||
it('reads a message without an origin, with none and with one shared from the assistant', () => {
|
||||
expect(collabMessageSchema.safeParse(message).success).toBe(true);
|
||||
expect(collabMessageSchema.safeParse({ ...message, origin: null }).success).toBe(true);
|
||||
expect(collabMessageSchema.parse({ ...message, origin: COLLAB_MESSAGE_ORIGIN_ASSISTANT }).origin).toBe('assistant');
|
||||
});
|
||||
|
||||
it('takes an origin it does not know yet, but only as text', () => {
|
||||
expect(collabMessageSchema.safeParse({ ...message, origin: 'plugin' }).success).toBe(true);
|
||||
expect(collabMessageSchema.safeParse({ ...message, origin: 1 }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -202,9 +202,15 @@ export const collabMessageSchema = z.object({
|
||||
avatar_url: z.string().nullable(),
|
||||
reactions: z.array(collabReactionSchema),
|
||||
attachments: z.array(collabAttachmentSchema),
|
||||
// Where the text came from when no one typed it. A string rather than an
|
||||
// enum, so a value added later does not break an older parser.
|
||||
origin: z.string().nullable().optional(),
|
||||
});
|
||||
export type CollabMessage = z.infer<typeof collabMessageSchema>;
|
||||
|
||||
/** The `origin` of a message shared from an answer of the trip assistant. */
|
||||
export const COLLAB_MESSAGE_ORIGIN_ASSISTANT = 'assistant';
|
||||
|
||||
export const collabMessagesResponseSchema = z.object({ messages: z.array(collabMessageSchema) });
|
||||
export type CollabMessagesResponse = z.infer<typeof collabMessagesResponseSchema>;
|
||||
export const collabMessageResponseSchema = z.object({ message: collabMessageSchema });
|
||||
|
||||
Reference in New Issue
Block a user