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
@@ -18,7 +18,8 @@ import {
|
||||
import dynamic from 'next/dynamic'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useCapability } from '@/contexts/CompanyContext'
|
||||
import { useTranslations } from 'next-intl'
|
||||
import { useAssistantAvailable, useCapability } from '@/contexts/CompanyContext'
|
||||
import { CAPABILITY } from '@/lib/entitlements/keys'
|
||||
import { UpgradeNote } from '@/components/billing/UpgradeNote'
|
||||
import ApprovalCard from './ApprovalCard'
|
||||
@@ -251,6 +252,11 @@ export default function AgentChat({
|
||||
// though it were the new one.
|
||||
const turnStartRef = useRef(0)
|
||||
const hasAi = useCapability(CAPABILITY.ai)
|
||||
// Whether the deployment can run this runtime at all (#2204). Every entry
|
||||
// point hides itself when it cannot; this is the last line of defense for a
|
||||
// resumed thread or a deep link: never fire an invoke that answers 503.
|
||||
const assistantAvailable = useAssistantAvailable()
|
||||
const tChat = useTranslations('agent_chat')
|
||||
const [input, setInput] = useState('')
|
||||
const [streaming, setStreaming] = useState(false)
|
||||
// Turn boundaries for the status channel are derived from the streaming flag
|
||||
@@ -312,9 +318,10 @@ export default function AgentChat({
|
||||
const hasResumeState = !!initialConversationId
|
||||
if (hasResumeState) return
|
||||
|
||||
// Paywall: never auto-fire the first invoke without the ai capability;
|
||||
// the composer is already replaced by the upgrade note.
|
||||
if (!hasAi) return
|
||||
// Paywall / no runtime: never auto-fire the first invoke without the ai
|
||||
// capability or the tool-loop runtime; the composer is already replaced
|
||||
// by the upgrade note or the unavailable notice.
|
||||
if (!hasAi || !assistantAvailable) return
|
||||
|
||||
// Seed-message path: render the user's pre-baked starter in the timeline
|
||||
// and send it as the first turn's user_message (skips intent.capture +
|
||||
@@ -543,7 +550,7 @@ export default function AgentChat({
|
||||
}
|
||||
|
||||
function handleRegenerate() {
|
||||
if (!hasAi) return
|
||||
if (!hasAi || !assistantAvailable) return
|
||||
// Re-run the last user message and let the agent produce a fresh
|
||||
// response. UI truncates back to the last user message; DB rows are
|
||||
// append-only, so the previous assistant turn stays in agent_messages
|
||||
@@ -611,7 +618,7 @@ export default function AgentChat({
|
||||
// user turn so the agent re-proposes inline: no synthetic user bubble (we
|
||||
// don't add a user row, and the turn is persisted hidden).
|
||||
function handleCorrection(correctionMessage: string) {
|
||||
if (!hasAi) return
|
||||
if (!hasAi || !assistantAvailable) return
|
||||
void startTurn({ conversationId, userMessage: correctionMessage, hidden: true })
|
||||
}
|
||||
|
||||
@@ -865,6 +872,7 @@ export default function AgentChat({
|
||||
showRegenerate={
|
||||
!streaming &&
|
||||
hasAi &&
|
||||
assistantAvailable &&
|
||||
i === lastAssistantIdx &&
|
||||
m.role === 'assistant' &&
|
||||
m.text.length > 0
|
||||
@@ -924,6 +932,15 @@ export default function AgentChat({
|
||||
<div className="border-t border-border px-5 pt-4 pb-[calc(env(safe-area-inset-bottom,0px)+1rem)]">
|
||||
<UpgradeNote>AI-assistenten kräver ett abonnemang.</UpgradeNote>
|
||||
</div>
|
||||
) : !assistantAvailable ? (
|
||||
/* No tool-loop runtime on this deployment (#2204): same swap as the
|
||||
paywall, so a resumed or deep-linked thread never offers a send
|
||||
that answers 503. */
|
||||
<div className="border-t border-border px-5 pt-4 pb-[calc(env(safe-area-inset-bottom,0px)+1rem)]">
|
||||
<p className="text-sm text-muted-foreground" role="status">
|
||||
{tChat('assistant_unavailable')}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<form
|
||||
// padding-bottom = base 1rem + safe-area-inset-bottom on phones so
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Loader2, X } from 'lucide-react'
|
||||
import AgentAvatar from './AgentAvatar'
|
||||
import { collapsedStatusLabel } from './agent-status'
|
||||
import { routeToIntent } from '@/lib/agent/intents/route-mapping'
|
||||
import { useCapability } from '@/contexts/CompanyContext'
|
||||
import { useAssistantAvailable, useCapability } from '@/contexts/CompanyContext'
|
||||
import { CAPABILITY } from '@/lib/entitlements/keys'
|
||||
|
||||
// Floating trigger sits above the page bottom-right, opens the AgentSheet when
|
||||
@@ -48,6 +48,7 @@ export default function AgentTrigger({ hidden = false }: { hidden?: boolean }) {
|
||||
const pathname = usePathname()
|
||||
const router = useRouter()
|
||||
const hasAi = useCapability(CAPABILITY.ai)
|
||||
const assistantAvailable = useAssistantAvailable()
|
||||
|
||||
// Read the dismissal AFTER hydration (effect, not state initializer): the
|
||||
// server always renders the pill, so an initializer that reads
|
||||
@@ -147,7 +148,10 @@ export default function AgentTrigger({ hidden = false }: { hidden?: boolean }) {
|
||||
if (!identity.isVerified) return null
|
||||
|
||||
const name = identity.displayName?.trim() || 'min assistent'
|
||||
const dispatch = routeToIntent(pathname)
|
||||
// Without the tool-loop runtime (OpenAI-compatible or unconfigured AI, #2204)
|
||||
// every route dispatches to general.help: the single-call console runs on
|
||||
// any provider, so the pill stays but never opens a chat that would 503.
|
||||
const dispatch = routeToIntent(pathname, { assistantAvailable })
|
||||
// AI assistant runs on a paid cloud service. Without the capability, opening
|
||||
// the sheet would land the user in a chat whose send is dead. Keep the FAB
|
||||
// visible (it's the conversion surface) but route it to billing instead.
|
||||
|
||||
@@ -61,7 +61,7 @@ import { useReceiptHunt } from '@/components/extensions/general/use-receipt-hunt
|
||||
import { createClient } from '@/lib/supabase/client'
|
||||
import { fetchWithTimeout } from '@/lib/http/fetch-with-timeout'
|
||||
import { copyInboxAddress, type AddressCopyState } from '@/components/extensions/general/inbox-address-copy'
|
||||
import { useCapability, useCompanyOptional } from '@/contexts/CompanyContext'
|
||||
import { useAssistantAvailable, useCapability, useCompanyOptional } from '@/contexts/CompanyContext'
|
||||
import { CAPABILITY } from '@/lib/entitlements/keys'
|
||||
import { useBranding } from '@/lib/branding/brand-context'
|
||||
import type { WorkspaceComponentProps } from '@/lib/extensions/workspace-registry'
|
||||
@@ -440,6 +440,9 @@ export default function InvoiceInboxWorkspace(_props: WorkspaceComponentProps) {
|
||||
// Its own input: sharing the header's would upload without the purchase.
|
||||
const purchaseFileInputRef = useRef<HTMLInputElement | null>(null)
|
||||
const { openAgentSheet, identity } = useAgentSheet()
|
||||
// Both "Fråga assistenten" doors below open the tool-loop runtime
|
||||
// (/api/agent/invoke); hide them where the deployment cannot run it (#2204).
|
||||
const assistantAvailable = useAssistantAvailable()
|
||||
|
||||
const [items, setItems] = useState<InboxItem[]>([])
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
@@ -1869,7 +1872,7 @@ export default function InvoiceInboxWorkspace(_props: WorkspaceComponentProps) {
|
||||
</Button>
|
||||
{/* Secondary actions: outlined, so they read as buttons */}
|
||||
<div className="flex items-center gap-2">
|
||||
{identity.isVerified && (
|
||||
{identity.isVerified && assistantAvailable && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
@@ -2197,7 +2200,7 @@ export default function InvoiceInboxWorkspace(_props: WorkspaceComponentProps) {
|
||||
await Promise.all([fetchItems(), handleSelect(targetId)])
|
||||
}}
|
||||
onAskAssistant={
|
||||
identity.isVerified
|
||||
identity.isVerified && assistantAvailable
|
||||
? (transactionId) => {
|
||||
openAgentSheet({
|
||||
intentId: 'transaction.categorization',
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
type VatDeadlineLine,
|
||||
} from '@/lib/onboarding/checklist'
|
||||
import { ENABLED_EXTENSION_IDS } from '@/lib/extensions/_generated/enabled-extensions'
|
||||
import { useCapability } from '@/contexts/CompanyContext'
|
||||
import { useAssistantAvailable, useCapability } from '@/contexts/CompanyContext'
|
||||
import { CAPABILITY } from '@/lib/entitlements/keys'
|
||||
import type { InitialSetupPath, InitialSetupState } from '@/types'
|
||||
import { useBranding } from '@/lib/branding/brand-context'
|
||||
@@ -97,6 +97,7 @@ export default function NewUserChecklist({
|
||||
const showError = useErrorToast()
|
||||
const { formatDateLong } = useFormat()
|
||||
const hasAi = useCapability(CAPABILITY.ai)
|
||||
const assistantAvailable = useAssistantAvailable()
|
||||
const [state, setState] = useState(initialState)
|
||||
const [saving, setSaving] = useState<InitialSetupPath | 'dismiss' | 'complete' | null>(null)
|
||||
// The completion signature: 'verdict' shows the orb check-morph and the
|
||||
@@ -121,6 +122,21 @@ export default function NewUserChecklist({
|
||||
const hasSkatteverket = ENABLED_EXTENSION_IDS.has('skatteverket')
|
||||
const hasInbox = ENABLED_EXTENSION_IDS.has('invoice-inbox')
|
||||
const hasWhatsApp = ENABLED_EXTENSION_IDS.has('whatsapp-inbox')
|
||||
// The Claude step is a pitch for running the books with Claude over the MCP
|
||||
// server. It goes when either half is missing: no mcp-server extension (the
|
||||
// connector URL would 404) or a deployment whose AI runs on another provider
|
||||
// (getAiStatus().assistantAvailable false, #2204), where steering every new
|
||||
// user to claude.ai contradicts the operator's own choice. Settings → API &
|
||||
// MCP keeps the connector for anyone who wants it anyway.
|
||||
const hasClaudeStep = assistantAvailable && ENABLED_EXTENSION_IDS.has('mcp-server')
|
||||
// Which step closes the thread (carries no spine below it).
|
||||
const lastStep = hasClaudeStep
|
||||
? 'assistant'
|
||||
: hasInbox
|
||||
? 'receipts'
|
||||
: hasSkatteverket
|
||||
? 'skv'
|
||||
: 'bank'
|
||||
|
||||
const persist = async (
|
||||
body: Record<string, unknown>,
|
||||
@@ -150,10 +166,11 @@ export default function NewUserChecklist({
|
||||
|
||||
const step1Done = hasBookkeepingImported || state.path === 'fresh'
|
||||
const step2Done = hasBankConnected
|
||||
// Companies built without the skatteverket/inbox extensions skip those steps.
|
||||
// Companies built without the skatteverket/inbox extensions skip those
|
||||
// steps; so does the Claude step where it does not render.
|
||||
const step3Done = !hasSkatteverket || hasSkatteverketConnected
|
||||
const step4Done = !hasInbox || hasInboxItems
|
||||
const step5Done = hasMcpKey
|
||||
const step5Done = !hasClaudeStep || hasMcpKey
|
||||
|
||||
useEffect(() => {
|
||||
// The block retires itself once every step is done; Dölj remains the
|
||||
@@ -192,7 +209,7 @@ export default function NewUserChecklist({
|
||||
}
|
||||
}, [retiring])
|
||||
|
||||
const numbers = checklistNumbers({ hasSkatteverket, hasInbox })
|
||||
const numbers = checklistNumbers({ hasSkatteverket, hasInbox, hasAssistant: hasClaudeStep })
|
||||
const stepCount = numbers.count
|
||||
|
||||
if (state.dismissedAt) return null
|
||||
@@ -346,6 +363,7 @@ export default function NewUserChecklist({
|
||||
done={step2Done}
|
||||
active={activeStep === 2}
|
||||
title={t('step_bank_title')}
|
||||
last={lastStep === 'bank'}
|
||||
action={(variant) => (
|
||||
<Button
|
||||
size="sm"
|
||||
@@ -387,6 +405,7 @@ export default function NewUserChecklist({
|
||||
done={step3Done}
|
||||
active={activeStep === 3}
|
||||
title={t('step_skv_title')}
|
||||
last={lastStep === 'skv'}
|
||||
action={(variant) => (
|
||||
<Button size="sm" variant={variant} asChild>
|
||||
{/* The authorize endpoint redirects off-site to Skatteverket. */}
|
||||
@@ -430,6 +449,7 @@ export default function NewUserChecklist({
|
||||
done={step4Done}
|
||||
active={activeStep === 4}
|
||||
title={t('step_receipts_title')}
|
||||
last={lastStep === 'receipts'}
|
||||
action={(variant) => (
|
||||
<Button size="sm" variant={variant} onClick={goReceipts}>
|
||||
{t('step_receipts_action')}
|
||||
@@ -445,6 +465,7 @@ export default function NewUserChecklist({
|
||||
</Step>
|
||||
)}
|
||||
|
||||
{hasClaudeStep && (
|
||||
<Step
|
||||
number={numbers.assistant}
|
||||
done={step5Done}
|
||||
@@ -504,6 +525,7 @@ export default function NewUserChecklist({
|
||||
>
|
||||
{t('step_claude_description')}
|
||||
</Step>
|
||||
)}
|
||||
</ol>
|
||||
</section>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user