fix(agent): hide Anthropic-only assistant surfaces where the provider cannot run them (#2204) (#2343)
* fix(agent): hide Anthropic-only assistant surfaces where the provider cannot run them Self-hosted deployments on an OpenAI-compatible provider (or with no AI configured) still showed every entry point into the tool-loop runtime behind /api/agent/invoke, which answers 503 there. The capability lived server-side only (getAiStatus().assistantAvailable); no UI could read it. Hand the flag to the client through CompanyContext (useAssistantAvailable, beside the paid-capability gate) and gate each entry point that opens AgentChat: the bookkeeping page's "Skapa med assistent" and "Med assistenten", the inbox workspace's "Fråga assistenten" doors, /chat/intake and /chat/new?intent=. The floating trigger falls back to general help (the single-call console runs on any provider) instead of hiding, and AgentChat itself never fires an invoke without the runtime, so a resumed thread or a forgotten entry point shows a notice instead of a 503. The Hem checklist's "Anslut till Claude" step renders only where the assistant runs on Claude and the mcp-server extension is on. Provider-agnostic AI (ask console, categorization, extraction) and the server-side 503 are unchanged; on hosted the flag is true and nothing changes. Closes #2204 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019SaJfqNi4VmsG8FMKq99G6 * test(ai): use a placeholder that cannot match an Anthropic key shape The new direct-Anthropic status test assigned a string in the exact format of a live API key, which trips secret scanners on every run. The config only reads presence, so any non-empty string exercises the path. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
Jakob Wennberg
parent
272d19b287
commit
9cb1d105e3
@@ -1,6 +1,33 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { routeToIntent, contextRefToTarget } from '../route-mapping'
|
||||
|
||||
describe('routeToIntent without the tool-loop runtime', () => {
|
||||
// getAiStatus().assistantAvailable is false on an OpenAI-compatible or
|
||||
// unconfigured deployment (#2204): the trigger keeps working on the
|
||||
// single-call console, so every route collapses onto general.help.
|
||||
it('dispatches every specialized route to general.help', () => {
|
||||
for (const route of [
|
||||
'/invoices/new',
|
||||
'/invoices/abc-123',
|
||||
'/supplier-invoices/sup-1',
|
||||
'/bookkeeping/year-end',
|
||||
'/kpi',
|
||||
'/settings/invoicing',
|
||||
]) {
|
||||
const out = routeToIntent(route, { assistantAvailable: false })
|
||||
expect(out.intentId).toBe('general.help')
|
||||
expect(out.intentArgs).toEqual({ route })
|
||||
expect(out.contextRef).toBeUndefined()
|
||||
expect(out.labelSuffix).toBeNull()
|
||||
}
|
||||
})
|
||||
|
||||
it('leaves the specialized dispatch alone when the option is omitted or true', () => {
|
||||
expect(routeToIntent('/kpi').intentId).toBe('kpi.explain')
|
||||
expect(routeToIntent('/kpi', { assistantAvailable: true }).intentId).toBe('kpi.explain')
|
||||
})
|
||||
})
|
||||
|
||||
describe('routeToIntent', () => {
|
||||
it('falls back to general.help when pathname is null/undefined/empty', () => {
|
||||
for (const input of [null, undefined, '']) {
|
||||
|
||||
@@ -29,8 +29,23 @@ const GENERAL_HELP = (route: string | null): RouteIntent => ({
|
||||
labelSuffix: null,
|
||||
})
|
||||
|
||||
export function routeToIntent(pathname: string | null | undefined): RouteIntent {
|
||||
export interface RouteIntentOptions {
|
||||
/**
|
||||
* Whether the deployment can run the tool-loop runtime (/api/agent/invoke,
|
||||
* getAiStatus().assistantAvailable). Every specialized intent below runs on
|
||||
* it; general.help runs on the single-call console, which any provider can
|
||||
* serve. When false, every route dispatches to general.help so the trigger
|
||||
* keeps working instead of opening a chat that 503s (#2204). Omitted = true.
|
||||
*/
|
||||
assistantAvailable?: boolean
|
||||
}
|
||||
|
||||
export function routeToIntent(
|
||||
pathname: string | null | undefined,
|
||||
options: RouteIntentOptions = {},
|
||||
): RouteIntent {
|
||||
if (!pathname) return GENERAL_HELP(null)
|
||||
if (options.assistantAvailable === false) return GENERAL_HELP(pathname)
|
||||
|
||||
const segments = pathname.split('/').filter(Boolean)
|
||||
const [first, second] = segments
|
||||
|
||||
@@ -199,6 +199,16 @@ describe('getAiStatus', () => {
|
||||
expect(s.models.extraction).toBe('eu.anthropic.claude-sonnet-5')
|
||||
})
|
||||
|
||||
it('is configured and assistant-capable on a direct Anthropic key', () => {
|
||||
// Presence is all the config reads (no format check), so the placeholder
|
||||
// deliberately cannot match a real key's shape and trip secret scanners.
|
||||
process.env.ANTHROPIC_API_KEY = 'test-not-a-real-key'
|
||||
const s = getAiStatus()
|
||||
expect(s.provider).toBe('anthropic')
|
||||
expect(s.configured).toBe(true)
|
||||
expect(s.assistantAvailable).toBe(true)
|
||||
})
|
||||
|
||||
it('needs a model id on an OpenAI-compatible endpoint before it counts as configured', () => {
|
||||
byo('')
|
||||
const s = getAiStatus()
|
||||
|
||||
@@ -45,7 +45,7 @@ describe('vatDeadlineLine', () => {
|
||||
|
||||
describe('checklistNumbers', () => {
|
||||
it('numbers all five steps when both extensions are on', () => {
|
||||
expect(checklistNumbers({ hasSkatteverket: true, hasInbox: true })).toEqual({
|
||||
expect(checklistNumbers({ hasSkatteverket: true, hasInbox: true, hasAssistant: true })).toEqual({
|
||||
count: 5,
|
||||
skv: 3,
|
||||
receipts: 4,
|
||||
@@ -54,7 +54,7 @@ describe('checklistNumbers', () => {
|
||||
})
|
||||
|
||||
it('collapses to four steps without the inbox extension', () => {
|
||||
expect(checklistNumbers({ hasSkatteverket: true, hasInbox: false })).toEqual({
|
||||
expect(checklistNumbers({ hasSkatteverket: true, hasInbox: false, hasAssistant: true })).toEqual({
|
||||
count: 4,
|
||||
skv: 3,
|
||||
receipts: 4,
|
||||
@@ -63,7 +63,7 @@ describe('checklistNumbers', () => {
|
||||
})
|
||||
|
||||
it('collapses to four steps without the skatteverket extension', () => {
|
||||
expect(checklistNumbers({ hasSkatteverket: false, hasInbox: true })).toEqual({
|
||||
expect(checklistNumbers({ hasSkatteverket: false, hasInbox: true, hasAssistant: true })).toEqual({
|
||||
count: 4,
|
||||
skv: 3,
|
||||
receipts: 3,
|
||||
@@ -72,13 +72,30 @@ describe('checklistNumbers', () => {
|
||||
})
|
||||
|
||||
it('collapses to three steps with neither extension', () => {
|
||||
expect(checklistNumbers({ hasSkatteverket: false, hasInbox: false })).toEqual({
|
||||
expect(checklistNumbers({ hasSkatteverket: false, hasInbox: false, hasAssistant: true })).toEqual({
|
||||
count: 3,
|
||||
skv: 3,
|
||||
receipts: 3,
|
||||
assistant: 3,
|
||||
})
|
||||
})
|
||||
|
||||
// A deployment that cannot run the assistant (#2204) drops the Claude step:
|
||||
// the title counts one step fewer, the other ordinals stay put.
|
||||
it('drops the assistant step from the count without moving the other ordinals', () => {
|
||||
expect(checklistNumbers({ hasSkatteverket: true, hasInbox: true, hasAssistant: false })).toEqual({
|
||||
count: 4,
|
||||
skv: 3,
|
||||
receipts: 4,
|
||||
assistant: 5,
|
||||
})
|
||||
expect(checklistNumbers({ hasSkatteverket: false, hasInbox: false, hasAssistant: false })).toEqual({
|
||||
count: 2,
|
||||
skv: 3,
|
||||
receipts: 3,
|
||||
assistant: 3,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('completionPatchBody', () => {
|
||||
|
||||
@@ -33,10 +33,15 @@ export function vatDeadlineLine(input: {
|
||||
/**
|
||||
* Display ordinals for the setup checklist steps. Books and bank are always
|
||||
* present; Skatteverket and the receipts/inbox step render only when their
|
||||
* extensions are enabled; the assistant step is always last. `count` drives
|
||||
* extensions are enabled; the assistant (Claude) step renders only where the
|
||||
* deployment can run the assistant and, when it does, is last. `count` drives
|
||||
* the "{count} steg så är bokföringen igång" title.
|
||||
*/
|
||||
export function checklistNumbers(gates: { hasSkatteverket: boolean; hasInbox: boolean }): {
|
||||
export function checklistNumbers(gates: {
|
||||
hasSkatteverket: boolean
|
||||
hasInbox: boolean
|
||||
hasAssistant: boolean
|
||||
}): {
|
||||
count: number
|
||||
skv: number
|
||||
receipts: number
|
||||
@@ -45,7 +50,10 @@ export function checklistNumbers(gates: { hasSkatteverket: boolean; hasInbox: bo
|
||||
const skv = 3
|
||||
const receipts = 3 + (gates.hasSkatteverket ? 1 : 0)
|
||||
const assistant = receipts + (gates.hasInbox ? 1 : 0)
|
||||
return { count: assistant, skv, receipts, assistant }
|
||||
// Without the assistant step the thread ends one step earlier; the other
|
||||
// ordinals do not move.
|
||||
const count = gates.hasAssistant ? assistant : assistant - 1
|
||||
return { count, skv, receipts, assistant }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user