mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-22 06:56:35 +00:00
214984f398
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.
46 lines
2.2 KiB
TypeScript
46 lines
2.2 KiB
TypeScript
/**
|
|
* FE-AI-PROVIDER-001 to FE-AI-PROVIDER-004
|
|
*
|
|
* Pasting a key picks the provider by its prefix, so the most specific prefix
|
|
* has to win; pasting the ChatGPT sign-in address submits it, so only that
|
|
* address may count.
|
|
*/
|
|
import { aiConnectionKindSchema } from '@trek/shared';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { AI_PROVIDERS, detectKeyKind, isChatgptCallback, providerLabel } from './providerCatalog';
|
|
|
|
describe('providerCatalog', () => {
|
|
it('FE-AI-PROVIDER-001: reads the provider from the key prefix, most specific first', () => {
|
|
expect(detectKeyKind('sk-ant-api03-abcdef')).toBe('anthropic');
|
|
expect(detectKeyKind(' sk-or-v1-abcdef\n')).toBe('openrouter');
|
|
expect(detectKeyKind('AIzaSyAbcdef')).toBe('gemini');
|
|
expect(detectKeyKind('AQ.Ab8RN6IVSexample')).toBe('gemini');
|
|
expect(detectKeyKind('sk-proj-abcdef')).toBe('openai');
|
|
expect(detectKeyKind('sk-abcdef')).toBe('openai');
|
|
expect(detectKeyKind('ghp_abcdef')).toBeNull();
|
|
expect(detectKeyKind('')).toBeNull();
|
|
});
|
|
|
|
it('FE-AI-PROVIDER-002: accepts only the loopback sign-in address, any port', () => {
|
|
expect(isChatgptCallback('http://127.0.0.1:1455/auth/callback?code=abc&state=xyz')).toBe(true);
|
|
expect(isChatgptCallback(' http://127.0.0.1:1457/auth/callback?code=abc ')).toBe(true);
|
|
expect(isChatgptCallback('http://localhost:1455/auth/callback?code=abc')).toBe(false);
|
|
expect(isChatgptCallback('https://127.0.0.1:1455/auth/callback?code=abc')).toBe(false);
|
|
expect(isChatgptCallback('http://127.0.0.1:1455/other?code=abc')).toBe(false);
|
|
expect(isChatgptCallback('not a url')).toBe(false);
|
|
});
|
|
|
|
it('FE-AI-PROVIDER-003: fills {provider} with the brand, or an own server with its host', () => {
|
|
expect(providerLabel('anthropic', 'api.anthropic.com')).toBe('Anthropic');
|
|
expect(providerLabel('chatgpt', 'api.openai.com')).toBe('ChatGPT');
|
|
expect(providerLabel('custom', 'ollama.lan')).toBe('ollama.lan');
|
|
});
|
|
|
|
it('FE-AI-PROVIDER-004: every connection kind has an entry with a hint', () => {
|
|
for (const kind of aiConnectionKindSchema.options) {
|
|
expect(AI_PROVIDERS[kind].kind).toBe(kind);
|
|
expect(AI_PROVIDERS[kind].hintKey).toMatch(/^assistant\./);
|
|
}
|
|
});
|
|
});
|