diff --git a/components/chat/artifact.tsx b/components/chat/artifact.tsx index b37c9cc..e233eff 100644 --- a/components/chat/artifact.tsx +++ b/components/chat/artifact.tsx @@ -162,7 +162,7 @@ function PureArtifact({ const currentDocument = currentDocuments.at(-1); - if (!currentDocument || !currentDocument.content) { + if (!currentDocument?.content) { setIsContentDirty(false); return currentDocuments; } diff --git a/lib/ai/providers.ts b/lib/ai/providers.ts index 46f3185..afe224b 100644 --- a/lib/ai/providers.ts +++ b/lib/ai/providers.ts @@ -1,6 +1,10 @@ -import { customProvider, gateway } from "ai"; +import { createAnthropic } from "@ai-sdk/anthropic"; +import { customProvider } from "ai"; import { isTestEnvironment } from "../constants"; -import { titleModel } from "./models"; + +const anthropic = createAnthropic({ + apiKey: process.env.ANTHROPIC_API_KEY, +}); export const myProvider = isTestEnvironment ? (() => { @@ -19,12 +23,16 @@ export function getLanguageModel(modelId: string) { return myProvider.languageModel(modelId); } - return gateway.languageModel(modelId); + // Strip provider prefix (e.g. "anthropic/claude-sonnet-4-6" -> "claude-sonnet-4-6") + const id = modelId.includes("/") + ? modelId.split("/").slice(1).join("/") + : modelId; + return anthropic(id); } export function getTitleModel() { if (isTestEnvironment && myProvider) { return myProvider.languageModel("title-model"); } - return gateway.languageModel(titleModel.id); + return anthropic("claude-haiku-4-5-20251001"); } diff --git a/lib/ai/tools/request-suggestions.ts b/lib/ai/tools/request-suggestions.ts index 36ac13d..2c6c3cd 100644 --- a/lib/ai/tools/request-suggestions.ts +++ b/lib/ai/tools/request-suggestions.ts @@ -31,7 +31,7 @@ export const requestSuggestions = ({ execute: async ({ documentId }) => { const document = await getDocumentById({ id: documentId }); - if (!document || !document.content) { + if (!document?.content) { return { error: "Document not found", }; diff --git a/lib/editor/config.ts b/lib/editor/config.ts index 1d73e85..6e30fe3 100644 --- a/lib/editor/config.ts +++ b/lib/editor/config.ts @@ -30,7 +30,7 @@ export const handleTransaction = ({ editorRef: MutableRefObject; onSaveContent: (updatedContent: string, debounce: boolean) => void; }) => { - if (!editorRef || !editorRef.current) { + if (!editorRef?.current) { return; } diff --git a/package.json b/package.json index 220a564..6ca59d4 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "test": "export PLAYWRIGHT=True && pnpm exec playwright test" }, "dependencies": { + "@ai-sdk/anthropic": "^3.0.66", "@ai-sdk/provider": "^3.0.3", "@ai-sdk/react": "3.0.118", "@codemirror/lang-python": "^6.1.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b58ffa4..79aac94 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + '@ai-sdk/anthropic': + specifier: ^3.0.66 + version: 3.0.66(zod@3.25.76) '@ai-sdk/provider': specifier: ^3.0.3 version: 3.0.3 @@ -258,6 +261,12 @@ importers: packages: + '@ai-sdk/anthropic@3.0.66': + resolution: {integrity: sha512-yJpQ2x6ACwbXo5D6HsVWd2FFnnWcetfGx4oxkG66P8FawusvrY2vL2qMiiNTruWrxEYDy+YHc3ctv8C769MMJA==} + engines: {node: '>=18'} + peerDependencies: + zod: ^3.25.76 || ^4.1.8 + '@ai-sdk/gateway@3.0.66': resolution: {integrity: sha512-SIQ0YY0iMuv+07HLsZ+bB990zUJ6S4ujORAh+Jv1V2KGNn73qQKnGO0JBk+w+Res8YqOFSycwDoWcFlQrVxS4A==} engines: {node: '>=18'} @@ -270,6 +279,12 @@ packages: peerDependencies: zod: ^3.25.76 || ^4.1.8 + '@ai-sdk/provider-utils@4.0.22': + resolution: {integrity: sha512-B2OTFcRw/Pdka9ZTjpXv6T6qZ6RruRuLokyb8HwW+aoW9ndJ3YasA3/mVswyJw7VMBF8ofXgqvcrCt9KYvFifg==} + engines: {node: '>=18'} + peerDependencies: + zod: ^3.25.76 || ^4.1.8 + '@ai-sdk/provider@3.0.3': resolution: {integrity: sha512-qGPYdoAuECaUXPrrz0BPX1SacZQuJ6zky0aakxpW89QW1hrY0eF4gcFm/3L9Pk8C5Fwe+RvBf2z7ZjDhaPjnlg==} engines: {node: '>=18'} @@ -4071,6 +4086,12 @@ packages: snapshots: + '@ai-sdk/anthropic@3.0.66(zod@3.25.76)': + dependencies: + '@ai-sdk/provider': 3.0.8 + '@ai-sdk/provider-utils': 4.0.22(zod@3.25.76) + zod: 3.25.76 + '@ai-sdk/gateway@3.0.66(zod@3.25.76)': dependencies: '@ai-sdk/provider': 3.0.8 @@ -4085,6 +4106,13 @@ snapshots: eventsource-parser: 3.0.6 zod: 3.25.76 + '@ai-sdk/provider-utils@4.0.22(zod@3.25.76)': + dependencies: + '@ai-sdk/provider': 3.0.8 + '@standard-schema/spec': 1.1.0 + eventsource-parser: 3.0.6 + zod: 3.25.76 + '@ai-sdk/provider@3.0.3': dependencies: json-schema: 0.4.0