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:
Maurice
2026-12-01 00:40:57 +01:00
parent 00e98b8711
commit f511fe4fcf
5 changed files with 30 additions and 13 deletions
@@ -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(() => {
+7 -2
View File
@@ -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);
});
});
+8 -8
View File
@@ -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;
}
@@ -24,6 +24,9 @@ const NOT_OPERATOR_SETTINGS: Record<string, string> = {
APP_VERSION: 'set by the image build; the VERSION file wins over it',
TREK_DB_FILE: 'points the Playwright harness at a throwaway database',
TREK_MANAGED: 'managed hosting only, deliberately undocumented for self-hosters',
TREK_MANAGED_ASSISTANT_URL: 'managed hosting only, the operator gateway URL',
TREK_MANAGED_ASSISTANT_TOKEN: 'managed hosting only, the instance credential for the operator gateway',
TREK_MANAGED_ASSISTANT_MODEL: 'managed hosting only, the operator-selected assistant model',
MAPBOX_ACCESS_TOKEN: 'managed hosting only (read with TREK_MANAGED), deliberately undocumented for self-hosters',
CARTO_API_KEY: 'managed hosting only (read with TREK_MANAGED), deliberately undocumented for self-hosters',
PLACES_API_BASE: "managed hosting's egress gateway for the Places calls, deliberately undocumented for self-hosters",
@@ -48,13 +48,16 @@ class FakeResponse extends EventEmitter {
}
}
function make(opts: { addon?: boolean; managed?: boolean; trip?: boolean } = {}) {
function make(opts: { addon?: boolean; managed?: boolean; managedAssistant?: boolean; trip?: boolean } = {}) {
const service = {
attach: vi.fn(async (_u: number, _t: number, _b: unknown, _f: unknown, _c: TurnChannel) => undefined),
};
const trips = { findAccessible: vi.fn(async () => (opts.trip === false ? undefined : { id: 5, user_id: 7 })) };
const addons = { isAddonEnabled: vi.fn(async () => opts.addon !== false) };
const env = { isManaged: () => opts.managed === true };
const env = {
isManaged: () => opts.managed === true,
env: () => ({ managed: { assistant: opts.managedAssistant ? { model: 'test-model' } : undefined } }),
};
const controller = new AssistantAttachmentsController(
service as unknown as AssistantService,
trips as unknown as TripAccessService,
@@ -105,6 +108,10 @@ describe('AssistantAttachmentsController', () => {
});
expect(stranger.trips.findAccessible).toHaveBeenCalledWith('5', 7);
for (const t of [off, managed, stranger]) expect(t.service.attach).not.toHaveBeenCalled();
const managedWithAssistant = make({ managed: true, managedAssistant: true });
await managedWithAssistant.controller.attach(user, '5', file('a.pdf'), BODY, res);
expect(managedWithAssistant.service.attach).toHaveBeenCalledOnce();
});
it('ASTATT-003: a missing, too large or unknown file is refused before the turn', async () => {