mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 00:43:15 +00:00
fix(assistant): preserve managed status gating
Only request managed status for the assistant addon. Cover the configured attachment path and keep operator-only gateway configuration out of the self-hosted environment reference.
This commit is contained in:
@@ -2,6 +2,7 @@ import { useEffect } from 'react';
|
||||
|
||||
import { useAddonStore } from '../../store/addonStore';
|
||||
import { aiRoutesOpen, useAssistantStore } from '../../store/assistantStore';
|
||||
import { useAuthStore } from '../../store/authStore';
|
||||
|
||||
/**
|
||||
* Asks for the assistant's status when a view of it mounts, and again when
|
||||
@@ -13,7 +14,8 @@ import { aiRoutesOpen, useAssistantStore } from '../../store/assistantStore';
|
||||
*/
|
||||
export function useAssistantStatus(): void {
|
||||
const loadStatus = useAssistantStore((s) => s.loadStatus);
|
||||
const routesOpen = useAddonStore(aiRoutesOpen);
|
||||
const managed = useAuthStore((s) => s.managed);
|
||||
const routesOpen = useAddonStore((s) => aiRoutesOpen(s, managed));
|
||||
const assistantOn = useAddonStore((s) => s.isEnabled('ai_assistant'));
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -363,13 +363,18 @@ describe('assistantStore: threads, window and status', () => {
|
||||
expect(store().status).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-AI-STORE-014: a managed install, which refuses /api/ai, is not asked whatever its addons say', async () => {
|
||||
it('FE-AI-STORE-014: a managed install only asks for status when its assistant addon is on', async () => {
|
||||
const status = vi.spyOn(aiConnectionsRepo, 'status').mockResolvedValue(STATUS);
|
||||
useAssistantStore.setState({ status: STATUS });
|
||||
useAuthStore.setState({ managed: true });
|
||||
addonsOn('ai_assistant', 'llm_parsing');
|
||||
addonsOn('llm_parsing');
|
||||
await store().loadStatus();
|
||||
expect(status).not.toHaveBeenCalled();
|
||||
expect(store().status).toBeNull();
|
||||
|
||||
addonsOn('ai_assistant', 'llm_parsing');
|
||||
await store().loadStatus();
|
||||
expect(status).toHaveBeenCalledOnce();
|
||||
expect(store().status).toEqual(STATUS);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
type WindowRect,
|
||||
} from './assistantMapModel';
|
||||
import { applyChunk, closeUndo, markDecisions } from './assistantMessages';
|
||||
import { useAuthStore } from './authStore';
|
||||
import { useSettingsStore } from './settingsStore';
|
||||
import { useTripStore } from './tripStore';
|
||||
|
||||
@@ -324,13 +325,13 @@ export function chatOf(state: Pick<AssistantState, 'byTrip'>, key: AssistantChat
|
||||
* Whether the addons open /api/ai: the server opens it while the assistant or
|
||||
* AI parsing is on, the two sharing one connection, and answers 404 while
|
||||
* both are off. Closed until the addon list is in. A selector on the addon
|
||||
* store. The server's status response decides availability on managed installs.
|
||||
* store. On managed installs only the assistant addon opens the status route.
|
||||
*/
|
||||
export function aiRoutesOpen({
|
||||
loaded,
|
||||
isEnabled,
|
||||
}: Pick<ReturnType<typeof useAddonStore.getState>, 'loaded' | 'isEnabled'>): boolean {
|
||||
return loaded && (isEnabled('ai_assistant') || isEnabled('llm_parsing'));
|
||||
export function aiRoutesOpen(
|
||||
{ loaded, isEnabled }: Pick<ReturnType<typeof useAddonStore.getState>, 'loaded' | 'isEnabled'>,
|
||||
managed: boolean,
|
||||
): boolean {
|
||||
return loaded && (isEnabled('ai_assistant') || (!managed && isEnabled('llm_parsing')));
|
||||
}
|
||||
|
||||
function httpStatus(err: unknown): number | undefined {
|
||||
@@ -585,8 +586,7 @@ function backToAfter(byTrip: Record<number, AssistantTripChat>): Record<number,
|
||||
function shellActions(ctx: Ctx) {
|
||||
return {
|
||||
loadStatus: async () => {
|
||||
// When both addons are off the status route is closed.
|
||||
if (!aiRoutesOpen(useAddonStore.getState())) {
|
||||
if (!aiRoutesOpen(useAddonStore.getState(), useAuthStore.getState().managed)) {
|
||||
ctx.set({ status: null });
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user