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.
|
||||
|
||||
Reference in New Issue
Block a user