mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 13:23:04 +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.
41 lines
1.7 KiB
TypeScript
41 lines
1.7 KiB
TypeScript
/**
|
|
* The assistant turns running right now, one per user, as an injectable port.
|
|
* A second window asking while one turn streams is refused (`busy`) instead of
|
|
* running two turns over the same conversation; "continue here" stops the
|
|
* running one (`abort`) and asks again. In memory today; a registry shared
|
|
* between processes replaces InMemoryAssistantStreamRegistry in
|
|
* AssistantModule.
|
|
*/
|
|
export abstract class AssistantStreamRegistry {
|
|
/** Registers the turn's controller; false when the user already has one running. */
|
|
abstract claim(userId: number, controller: AbortController): Promise<boolean>;
|
|
/** Forgets the turn, if it is still the one registered. */
|
|
abstract release(userId: number, controller: AbortController): Promise<void>;
|
|
/** Stops the user's running turn; false when none was running. */
|
|
abstract abort(userId: number): Promise<boolean>;
|
|
}
|
|
|
|
export class InMemoryAssistantStreamRegistry extends AssistantStreamRegistry {
|
|
private readonly running = new Map<number, AbortController>();
|
|
|
|
claim(userId: number, controller: AbortController): Promise<boolean> {
|
|
const current = this.running.get(userId);
|
|
if (current && !current.signal.aborted) return Promise.resolve(false);
|
|
this.running.set(userId, controller);
|
|
return Promise.resolve(true);
|
|
}
|
|
|
|
release(userId: number, controller: AbortController): Promise<void> {
|
|
if (this.running.get(userId) === controller) this.running.delete(userId);
|
|
return Promise.resolve();
|
|
}
|
|
|
|
abort(userId: number): Promise<boolean> {
|
|
const current = this.running.get(userId);
|
|
if (!current) return Promise.resolve(false);
|
|
this.running.delete(userId);
|
|
current.abort();
|
|
return Promise.resolve(true);
|
|
}
|
|
}
|