mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 05:21:15 +00:00
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:
@@ -37,8 +37,10 @@ export default function IntegrationsTab(): React.ReactElement {
|
||||
own key, and there nobody does. */}
|
||||
{/* The assistant in TREK, with the same managed rule as AI parsing: there the
|
||||
operator decides which model the install talks to. */}
|
||||
{S.aiAssistantEnabled && !managed && <AiConnectionSection />}
|
||||
{S.llmEnabled && !managed && <LlmConnectionSection />}
|
||||
{S.aiConnectionEnabled && !managed && (
|
||||
<AiConnectionSection assistant={S.aiAssistantEnabled} parsing={S.llmEnabled} />
|
||||
)}
|
||||
{S.llmEnabled && S.ownParsing && !managed && <LlmConnectionSection />}
|
||||
{/* Above MCP on purpose: an API key needs no addon, and someone looking for
|
||||
one should not have to read past a section about AI assistants. */}
|
||||
<ApiKeysSection />
|
||||
@@ -54,11 +56,11 @@ export default function IntegrationsTab(): React.ReactElement {
|
||||
function useIntegrations() {
|
||||
const { t, locale } = useTranslation()
|
||||
const toast = useToast()
|
||||
const { mcpEnabled, airtrailEnabled, llmEnabled, aiAssistantEnabled, dawarichEnabled, wandererEnabled, managed } = useIntegrationGates({ reloadAddons: true })
|
||||
const { mcpEnabled, airtrailEnabled, llmEnabled, aiAssistantEnabled, aiConnectionEnabled, ownParsing, dawarichEnabled, wandererEnabled, managed } = useIntegrationGates({ reloadAddons: true })
|
||||
|
||||
const mcp = useMcpIntegration({ enabled: mcpEnabled, reloadClientsAfterWrite: false })
|
||||
|
||||
return { t, locale, toast, mcpEnabled, airtrailEnabled, llmEnabled, aiAssistantEnabled, dawarichEnabled,
|
||||
return { t, locale, toast, mcpEnabled, airtrailEnabled, llmEnabled, aiAssistantEnabled, aiConnectionEnabled, ownParsing, dawarichEnabled,
|
||||
wandererEnabled,
|
||||
managed, ...mcp,
|
||||
}
|
||||
|
||||
@@ -2,23 +2,23 @@ import type { AiConnectionKind, AiConnectionView } from '@trek/shared';
|
||||
import { Loader2, LogOut, MessageCircle, Sparkles, Unplug } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import { useTranslation } from '../../../i18n';
|
||||
import { useAssistantCostEstimates, useAssistantMapFollow } from '../../Assistant/useAssistantMapFollow';
|
||||
import ConfirmDialog from '../../shared/ConfirmDialog';
|
||||
import CustomSelect from '../../shared/CustomSelect';
|
||||
import { fs } from '../../shared/DialogShell';
|
||||
import { useAssistantMapFollow } from '../../Assistant/useAssistantMapFollow';
|
||||
import Section from '../Section';
|
||||
import {
|
||||
SettingRow,
|
||||
SettingRows,
|
||||
SETTINGS_BUTTON,
|
||||
SETTINGS_BUTTON_DANGER,
|
||||
SETTINGS_BUTTON_PRIMARY,
|
||||
SettingRow,
|
||||
SettingRows,
|
||||
SettingsHint,
|
||||
StatusPill,
|
||||
} from '../settingsKit';
|
||||
import ToggleSwitch from '../ToggleSwitch';
|
||||
import { aiSectionText, CONNECTION_STATUS } from './aiConnectModel';
|
||||
import AiConnectPanel, { ProviderMark } from './AiConnectPanel';
|
||||
import { CONNECTION_STATUS } from './aiConnectModel';
|
||||
import { useAiConnections } from './useAiConnections';
|
||||
|
||||
type AiConnections = ReturnType<typeof useAiConnections>;
|
||||
@@ -173,6 +173,7 @@ function InstanceConnection({ S }: { S: AiConnections }) {
|
||||
function AssistantBehaviour() {
|
||||
const { t } = useTranslation();
|
||||
const follow = useAssistantMapFollow();
|
||||
const costs = useAssistantCostEstimates();
|
||||
return (
|
||||
<SettingRows>
|
||||
<SettingRow
|
||||
@@ -186,26 +187,45 @@ function AssistantBehaviour() {
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<SettingRow
|
||||
label={t('assistant.settings.costEstimates')}
|
||||
hint={t('assistant.settings.costEstimatesHint')}
|
||||
control={
|
||||
<ToggleSwitch
|
||||
on={costs.on}
|
||||
onToggle={() => void costs.set(!costs.on)}
|
||||
label={t('assistant.settings.costEstimates')}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</SettingRows>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings → Integrations → AI assistant: connect a provider, see which one
|
||||
* answers, pick its model, leave again. The only place a user sets the
|
||||
* assistant up; once it works, one button takes them to it.
|
||||
* Settings → Integrations → the user's AI connection: connect a provider, see
|
||||
* which one answers, pick its model, leave again. The assistant runs on it and
|
||||
* AI parsing reads bookings with it, so it shows while either addon is on and
|
||||
* says which it serves.
|
||||
*/
|
||||
export default function AiConnectionSection(): React.ReactElement | null {
|
||||
export default function AiConnectionSection({
|
||||
assistant = true,
|
||||
parsing = false,
|
||||
}: {
|
||||
assistant?: boolean;
|
||||
parsing?: boolean;
|
||||
}): React.ReactElement | null {
|
||||
const { t } = useTranslation();
|
||||
const S = useAiConnections();
|
||||
const text = aiSectionText(assistant, parsing);
|
||||
if (S.view === 'hidden') return null;
|
||||
const own = S.own;
|
||||
|
||||
return (
|
||||
<Section
|
||||
title={t('assistant.connect.title')}
|
||||
title={t(text.titleKey)}
|
||||
icon={Sparkles}
|
||||
hint={t('assistant.connect.description')}
|
||||
hint={t(text.hintKey)}
|
||||
badge={
|
||||
own ? (
|
||||
<StatusPill tone={CONNECTION_STATUS[own.status].tone}>{t(CONNECTION_STATUS[own.status].labelKey)}</StatusPill>
|
||||
@@ -219,7 +239,7 @@ export default function AiConnectionSection(): React.ReactElement | null {
|
||||
)}
|
||||
{S.view === 'own' && own && <OwnConnection S={S} own={own} />}
|
||||
{S.view === 'instance' && <InstanceConnection S={S} />}
|
||||
{(S.view === 'own' || S.view === 'instance') && <AssistantBehaviour />}
|
||||
{assistant && (S.view === 'own' || S.view === 'instance') && <AssistantBehaviour />}
|
||||
{S.view === 'adminOnly' && <SettingsHint>{t('assistant.setup.adminOnly')}</SettingsHint>}
|
||||
|
||||
{S.panel && (
|
||||
|
||||
@@ -121,3 +121,15 @@ export function httpHostOf(raw: string): string {
|
||||
export function svgDataUrl(svg: string): string {
|
||||
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* What a user's AI connection serves, as its section's title and line: the
|
||||
* assistant, AI parsing (booking import reads with the same connection), or both.
|
||||
*/
|
||||
export function aiSectionText(assistant: boolean, parsing: boolean): { titleKey: string; hintKey: string } {
|
||||
if (!assistant) return { titleKey: 'settings.aiParsing.title', hintKey: 'assistant.connect.descriptionParsingOnly' };
|
||||
return {
|
||||
titleKey: 'assistant.connect.title',
|
||||
hintKey: parsing ? 'assistant.connect.descriptionWithParsing' : 'assistant.connect.description',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useAddonStore } from '../../store/addonStore';
|
||||
import { useAuthStore } from '../../store/authStore';
|
||||
import { useSettingsStore } from '../../store/settingsStore';
|
||||
|
||||
/**
|
||||
* Which integrations the settings shells offer: the addon flags behind each
|
||||
@@ -22,6 +23,11 @@ export function useIntegrationGates({ reloadAddons }: { reloadAddons: boolean })
|
||||
const dawarichEnabled = addonEnabled('dawarich');
|
||||
// The wanderer connection feeds the Tours workspace, while the admin allows it there.
|
||||
const wandererEnabled = useAddonStore((s) => s.toursWanderer);
|
||||
// The AI connection serves the assistant and AI parsing alike.
|
||||
const aiConnectionEnabled = aiAssistantEnabled || llmEnabled;
|
||||
// A personal parsing model saved before parsing read with the AI connection;
|
||||
// its form stays for whoever has one, and is no longer offered to anyone else.
|
||||
const ownParsing = useSettingsStore((s) => !!(s.settings.llm_provider && s.settings.llm_model));
|
||||
const hasIntegrations =
|
||||
memoriesEnabled || mcpEnabled || airtrailEnabled || llmEnabled || aiAssistantEnabled || dawarichEnabled;
|
||||
|
||||
@@ -35,6 +41,8 @@ export function useIntegrationGates({ reloadAddons }: { reloadAddons: boolean })
|
||||
airtrailEnabled,
|
||||
llmEnabled,
|
||||
aiAssistantEnabled,
|
||||
aiConnectionEnabled,
|
||||
ownParsing,
|
||||
dawarichEnabled,
|
||||
wandererEnabled,
|
||||
hasIntegrations,
|
||||
|
||||
Reference in New Issue
Block a user