Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web): make isAiConfigured role-aware so docs Ask AI gates on the streaming chain

Richie McIlroy501be9ed85ab
diff --git a/apps/web/__tests__/unit/ai-provider.test.ts b/apps/web/__tests__/unit/ai-provider.test.ts
index c61ef1cff..c3921bbf9 100644
--- a/apps/web/__tests__/unit/ai-provider.test.ts
+++ b/apps/web/__tests__/unit/ai-provider.test.ts
@@ -159,6 +159,29 @@ describe("isAiConfigured", () => {
envWith({ GROQ_API_KEY: "groq-key" });
expect(isAiConfigured()).toBe(true);
});
+
+ it("is role-aware: a non-streaming stream model empties the chat-streaming role", () => {
+ envWith({
+ AI_PROVIDER: "assemblyai",
+ ASSEMBLY_API_KEY: "assembly-key",
+ AI_STREAM_MODEL: "claude-sonnet-5",
+ });
+
+ expect(isAiConfigured()).toBe(true);
+ expect(isAiConfigured("chat")).toBe(true);
+ expect(isAiConfigured("chat-streaming")).toBe(false);
+ });
+
+ it("is true for chat-streaming when a streaming fallback provider exists", () => {
+ envWith({
+ AI_PROVIDER: "assemblyai",
+ ASSEMBLY_API_KEY: "assembly-key",
+ AI_STREAM_MODEL: "claude-sonnet-5",
+ GROQ_API_KEY: "groq-key",
+ });
+
+ expect(isAiConfigured("chat-streaming")).toBe(true);
+ });
});
describe("role model defaults", () => {
diff --git a/apps/web/__tests__/unit/docs-ask-route.test.ts b/apps/web/__tests__/unit/docs-ask-route.test.ts
index faee2d67a..c96c99df2 100644
--- a/apps/web/__tests__/unit/docs-ask-route.test.ts
+++ b/apps/web/__tests__/unit/docs-ask-route.test.ts
@@ -144,6 +144,9 @@ describe("docs ask route", () => {
await expect(response.json()).resolves.toEqual({
error: "Ask AI is not available right now. Try searching instead.",
});
+ // The gate must ask about the streaming role — a generation-only
+ // configuration must not let requests through to an empty chain.
+ expect(isAiConfiguredMock).toHaveBeenCalledWith("chat-streaming");
});
it("returns 502 when every provider fails", async () => {
diff --git a/apps/web/app/api/docs/ask/route.ts b/apps/web/app/api/docs/ask/route.ts
index d632d87cb..b5ceeaa58 100644
--- a/apps/web/app/api/docs/ask/route.ts
+++ b/apps/web/app/api/docs/ask/route.ts
@@ -61,7 +61,7 @@ function toStreamError(error: unknown): Error {
}
export async function POST(request: NextRequest) {
- if (!isAiConfigured()) {
+ if (!isAiConfigured("chat-streaming")) {
return Response.json(
{ error: "Ask AI is not available right now. Try searching instead." },
{ status: 503 },
diff --git a/apps/web/lib/ai/provider.ts b/apps/web/lib/ai/provider.ts
index 334c1ae82..50529554b 100644
--- a/apps/web/lib/ai/provider.ts
+++ b/apps/web/lib/ai/provider.ts
@@ -158,8 +158,12 @@ export function getConfiguredAiProviders(
return providers;
}
-export function isAiConfigured(): boolean {
- return getConfiguredAiProviders().length > 0;
+export function isAiConfigured(role: AiModelRole = "generation"): boolean {
+ // Role-aware on purpose: a provider can be configured yet unusable for a
+ // role (eg. assemblyai with a non-streaming AI_STREAM_MODEL leaves the
+ // chat-streaming chain empty), so count the role's usable chain instead
+ // of the raw provider list.
+ return getAiProviderChain(role).length > 0;
}
function envModelOverride(role: AiModelRole): string | undefined {