mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
fix(assistant): lint, types and tests for the CI round
- agent loop and decisions without await in loops: steps as recursion, calls and applied changes in order through one promise chain, the independent reads and claims in parallel; part mapping in its own helpers - place card, header and weather strip without refs or components created in render; long hooks and components split; state reset during render - trip notes only in a turn's tool session, never an undo's; map view reported only while the assistant can run - place strip scrolls through the strip's own smooth scroll, no physical side - tests follow the raised limits and the new card fields; toasts read through a mocked useToast instead of a window global; baselines lowered where the counts fell
This commit is contained in:
@@ -202,6 +202,43 @@ function AssistantBehaviour() {
|
||||
);
|
||||
}
|
||||
|
||||
/** The connect panel, opened on purpose or because nothing is connected yet. */
|
||||
function ConnectPanel({ S }: { S: AiConnections }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className={`flex flex-col gap-3 ${S.view === 'setup' ? '' : 'border-t border-edge-faint pt-4'}`}>
|
||||
<AiConnectPanel key={S.panelMode ?? 'any'} scope="user" onConnected={S.onConnected} initialMode={S.panelMode} />
|
||||
{S.view !== 'setup' && (
|
||||
<button type="button" onClick={S.closePanel} className={`${SETTINGS_BUTTON} self-start`} style={fs(13, 'body')}>
|
||||
{t('common.cancel')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** How long chats are kept, and for an admin the way to the setting for everyone. */
|
||||
function SectionFooter({ S }: { S: AiConnections }) {
|
||||
const { t } = useTranslation();
|
||||
const retention = S.view !== 'setup' && !!S.retentionText;
|
||||
if (!S.isAdmin && !retention) return null;
|
||||
return (
|
||||
<div className="flex flex-wrap items-center justify-between gap-x-4 gap-y-1">
|
||||
{S.view !== 'setup' && <SettingsHint>{S.retentionText}</SettingsHint>}
|
||||
{S.isAdmin && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={S.openAdmin}
|
||||
className="font-medium text-content-muted underline underline-offset-2 hover:text-content"
|
||||
style={fs(12, 'body')}
|
||||
>
|
||||
{t('assistant.setup.forEveryone')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -242,42 +279,8 @@ export default function AiConnectionSection({
|
||||
{assistant && (S.view === 'own' || S.view === 'instance') && <AssistantBehaviour />}
|
||||
{S.view === 'adminOnly' && <SettingsHint>{t('assistant.setup.adminOnly')}</SettingsHint>}
|
||||
|
||||
{S.panel && (
|
||||
<div className={`flex flex-col gap-3 ${S.view === 'setup' ? '' : 'border-t border-edge-faint pt-4'}`}>
|
||||
<AiConnectPanel
|
||||
key={S.panelMode ?? 'any'}
|
||||
scope="user"
|
||||
onConnected={S.onConnected}
|
||||
initialMode={S.panelMode}
|
||||
/>
|
||||
{S.view !== 'setup' && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={S.closePanel}
|
||||
className={`${SETTINGS_BUTTON} self-start`}
|
||||
style={fs(13, 'body')}
|
||||
>
|
||||
{t('common.cancel')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{(S.isAdmin || (S.retentionText && S.view !== 'setup')) && (
|
||||
<div className="flex flex-wrap items-center justify-between gap-x-4 gap-y-1">
|
||||
{S.view !== 'setup' && <SettingsHint>{S.retentionText}</SettingsHint>}
|
||||
{S.isAdmin && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={S.openAdmin}
|
||||
className="font-medium text-content-muted underline underline-offset-2 hover:text-content"
|
||||
style={fs(12, 'body')}
|
||||
>
|
||||
{t('assistant.setup.forEveryone')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{S.panel && <ConnectPanel S={S} />}
|
||||
<SectionFooter S={S} />
|
||||
|
||||
<ConfirmDialog
|
||||
isOpen={S.ownActions.confirmingDisconnect}
|
||||
|
||||
@@ -70,11 +70,7 @@ export function useAiModels(load: (() => Promise<AiModelInfo[]>) | null, connect
|
||||
* The choices of a model picker: what the provider offers, the recommended
|
||||
* one first with its badge, and the current model kept when it is not listed.
|
||||
*/
|
||||
export function modelOptions(
|
||||
models: AiModelInfo[],
|
||||
current: string,
|
||||
labels: { free: string; recommended: string }
|
||||
) {
|
||||
export function modelOptions(models: AiModelInfo[], current: string, labels: { free: string; recommended: string }) {
|
||||
const options = models.map((m) => ({
|
||||
value: m.id,
|
||||
label: m.label,
|
||||
@@ -113,7 +109,10 @@ function useOwnConnection(own: AiConnectionView | null, reload: () => Promise<vo
|
||||
return {
|
||||
provider,
|
||||
models: own
|
||||
? modelOptions(models, own.model, { free: t('assistant.model.free'), recommended: t('assistant.model.recommended') })
|
||||
? modelOptions(models, own.model, {
|
||||
free: t('assistant.model.free'),
|
||||
recommended: t('assistant.model.recommended'),
|
||||
})
|
||||
: [],
|
||||
busy,
|
||||
setModel: (model: string) => run(() => aiConnectionsRepo.setModel(model), 'common.saved'),
|
||||
@@ -148,14 +147,10 @@ export function useAiConnections({ phone = false }: { phone?: boolean } = {}) {
|
||||
/** The panel opened on purpose: to renew a sign-in, replace a key, or connect one's own beside the admin's. */
|
||||
const [connecting, setConnecting] = useState<AiConnectMode | 'any' | null>(null);
|
||||
|
||||
const reload = async () => {
|
||||
await loadStatus();
|
||||
setLoaded(true);
|
||||
};
|
||||
const loadOnMount = useEffectEvent(() => void reload());
|
||||
const reload = () => loadStatus().then(() => setLoaded(true));
|
||||
useEffect(() => {
|
||||
loadOnMount();
|
||||
}, []);
|
||||
void loadStatus().then(() => setLoaded(true));
|
||||
}, [loadStatus]);
|
||||
|
||||
const onConnected = () => {
|
||||
setConnecting(null);
|
||||
@@ -181,10 +176,9 @@ export function useAiConnections({ phone = false }: { phone?: boolean } = {}) {
|
||||
openWindow();
|
||||
void navigate('/dashboard');
|
||||
};
|
||||
tripRepo.active().then(
|
||||
({ trip }) => (trip ? void navigate(`/trips/${trip.id}?assistant=1`) : withoutTrip()),
|
||||
withoutTrip
|
||||
);
|
||||
tripRepo
|
||||
.active()
|
||||
.then(({ trip }) => (trip ? void navigate(`/trips/${trip.id}?assistant=1`) : withoutTrip()), withoutTrip);
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user