mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 11:36:05 +00:00
b64da26651
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.
22 lines
886 B
TypeScript
22 lines
886 B
TypeScript
/** The longest title a thread gets from its first message. */
|
|
export const THREAD_TITLE_CHARS = 60;
|
|
|
|
/** What a cut title does not end on before its ellipsis. */
|
|
const TRAILING = new Set([' ', '.', ',', ';', ':', '!', '?', '-']);
|
|
|
|
/**
|
|
* A thread's title: its first message on one line, cut at the last word that
|
|
* fits in 60 characters (or hard at 60 when a single word is longer), with an
|
|
* ellipsis when anything was cut. No model is asked.
|
|
*/
|
|
export function titleFrom(text: string): string {
|
|
const line = text.replace(/\s+/g, ' ').trim();
|
|
if (line.length <= THREAD_TITLE_CHARS) return line;
|
|
const head = line.slice(0, THREAD_TITLE_CHARS);
|
|
const space = head.lastIndexOf(' ');
|
|
const cut = space > THREAD_TITLE_CHARS / 2 ? head.slice(0, space) : head;
|
|
let end = cut.length;
|
|
while (end > 0 && TRAILING.has(cut[end - 1])) end--;
|
|
return `${cut.slice(0, end)}…`;
|
|
}
|