The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update dub ai
Steven Teyd62065e4e0e8
diff --git a/apps/web/app/api/ai/completion/route.ts b/apps/web/app/api/ai/completion/route.tsindex a080cde6a1..761eabbbcd 100644--- a/apps/web/app/api/ai/completion/route.ts+++ b/apps/web/app/api/ai/completion/route.ts@@ -1,10 +1,10 @@-import { anthropic } from "@/lib/anthropic";-import { DubApiError, handleAndReturnErrorResponse } from "@/lib/api/errors";+import { handleAndReturnErrorResponse } from "@/lib/api/errors";import { withWorkspaceEdge } from "@/lib/auth/workspace-edge";import { prismaEdge } from "@/lib/prisma/edge";import z from "@/lib/zod";+import { anthropic } from "@ai-sdk/anthropic";import { waitUntil } from "@vercel/functions";-import { AnthropicStream, StreamingTextResponse } from "ai";+import { streamText } from "ai";export const runtime = "edge";@@ -19,14 +19,6 @@ const completionSchema = z.object({// POST /api/ai/completion – Generate AI completionexport const POST = withWorkspaceEdge(async ({ req, workspace }) => {- if (!anthropic) {- console.error("Anthropic is not configured. Skipping the request.");- throw new DubApiError({- code: "bad_request",- message: "Anthropic API key is not configured.",- });- }-try {const {// comment for better diff@@ -34,20 +26,18 @@ export const POST = withWorkspaceEdge(model,} = completionSchema.parse(await req.json());- const response = await anthropic.messages.create({+ console.log({ prompt });++ const result = await streamText({+ model: anthropic(model),messages: [{role: "user",content: prompt,},],- model,- stream: true,- max_tokens: 300,+ maxTokens: 300,});-- const stream = AnthropicStream(response);-// only count usage for the sonnet modelif (model === "claude-3-sonnet-20240229") {waitUntil(@@ -62,7 +52,7 @@ export const POST = withWorkspaceEdge();}- return new StreamingTextResponse(stream);+ return result.toDataStreamResponse();} catch (error) {return handleAndReturnErrorResponse(error);}diff --git a/apps/web/lib/anthropic.ts b/apps/web/lib/anthropic.tsdeleted file mode 100644index 555edf5f15..0000000000--- a/apps/web/lib/anthropic.ts+++ /dev/null@@ -1,5 +0,0 @@-import Anthropic from "@anthropic-ai/sdk";--const apiKey = process.env.ANTHROPIC_API_KEY;--export const anthropic = apiKey ? new Anthropic({ apiKey }) : null;diff --git a/apps/web/package.json b/apps/web/package.jsonindex 19e3906d6f..6cf79eab50 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -13,7 +13,6 @@},"dependencies": {"@ai-sdk/anthropic": "^0.0.17",- "@anthropic-ai/sdk": "^0.20.4","@boxyhq/saml-jackson": "1.23.9","@chronark/zod-bird": "^0.3.9","@dub/analytics": "^0.0.21",@@ -53,7 +52,7 @@"@visx/shape": "^2.12.2","@visx/text": "^3.3.0","@visx/tooltip": "^2.16.0",- "ai": "^3.2.38",+ "ai": "^3.4.8","aws4fetch": "^1.0.19","bcryptjs": "^2.4.3","bottleneck": "^2.19.5",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 550102f412..ee0643ce60 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -35,9 +35,6 @@ importers:'@ai-sdk/anthropic':specifier: ^0.0.17version: 0.0.17([email protected])- '@anthropic-ai/sdk':- specifier: ^0.20.4- version: 0.20.4'@boxyhq/saml-jackson':specifier: 1.23.9version: 1.23.9(@aws-sdk/[email protected])@@ -156,8 +153,8 @@ importers:specifier: ^2.16.0version: 2.16.0([email protected])([email protected])ai:- specifier: ^3.2.38+ specifier: ^3.4.8aws4fetch:specifier: ^1.0.19version: 1.0.19@@ -743,8 +740,8 @@ packages:zod: 3.22.4dev: false- /@ai-sdk/[email protected]([email protected]):- resolution: {integrity: sha512-XfOawxk95X3S43arn2iQIFyWGMi0DTxsf9ETc6t7bh91RPWOOPYN1tsmS5MTKD33OGJeaDQ/gnVRzXUCRBrckQ==}+ /@ai-sdk/[email protected]([email protected]):+ resolution: {integrity: sha512-ngg/RGpnA00eNOWEtXHenpX1MsM2QshQh4QJFjUfwcqHpM5kTfG7je7Rc3HcEDP+OkRVv2GF+X4fC1Vfcnl8Ow==}engines: {node: '>=18'}peerDependencies:zod: ^3.0.0@@ -752,15 +749,15 @@ packages:zod:optional: truedependencies:- '@ai-sdk/provider': 0.0.14+ '@ai-sdk/provider': 0.0.24eventsource-parser: 1.1.2nanoid: 3.3.6secure-json-parse: 2.7.0zod: 3.22.4dev: false- /@ai-sdk/[email protected]:- resolution: {integrity: sha512-gaQ5Y033nro9iX1YUjEDFDRhmMcEiCk56LJdIUbX5ozEiCNCfpiBpEqrjSp/Gp5RzBS2W0BVxfG7UGW6Ezcrzg==}+ /@ai-sdk/[email protected]:+ resolution: {integrity: sha512-XMsNGJdGO+L0cxhhegtqZ8+T6nn4EoShS819OvCgI2kLbYTIvk0GWFGD0AXJmxkxs3DrpsJxKAFukFR7bvTkgQ==}engines: {node: '>=18'}dependencies:json-schema: 0.4.0@@ -773,8 +770,8 @@ packages:json-schema: 0.4.0dev: false- resolution: {integrity: sha512-d9rgf3XfFVFtpisteoCkYPX8TqaruHXdb5maZP1udj0jEhS9gGxUGmsZ+U8lG4WgJu/6TuAykNtQ8bPJZqQauA==}+ resolution: {integrity: sha512-1asDpxgmeHWL0/EZPCLENxfOHT+0jce0z/zasRhascodm2S6f6/KZn5doLG9jdmarcb+GjMjFmmwyOVXz3W1xg==}engines: {node: '>=18'}peerDependencies:react: ^18 || ^19@@ -785,15 +782,15 @@ packages:zod:optional: truedependencies:- '@ai-sdk/provider-utils': 1.0.5([email protected])- '@ai-sdk/ui-utils': 0.0.21([email protected])+ '@ai-sdk/provider-utils': 1.0.20([email protected])+ '@ai-sdk/ui-utils': 0.0.46([email protected])react: 18.2.0swr: 2.2.5([email protected])zod: 3.22.4dev: false- /@ai-sdk/[email protected]([email protected]):- resolution: {integrity: sha512-QO2kE5mTXxJa0Vel0z9cVInfEIHKgeen6QJxhdQXCK/8Etcel7DRKvfQWcJf50PLVGmzVRqnGcRqjr6raaYePw==}+ /@ai-sdk/[email protected]([email protected]):+ resolution: {integrity: sha512-KnfWTt640cS1hM2fFIba8KHSPLpOIWXtEm28pNCHTvqasVKlh2y/zMQANTwE18pF2nuXL9P9F5/dKWaPsaEzQw==}engines: {node: '>=18'}peerDependencies:solid-js: ^1.7.7@@ -801,14 +798,14 @@ packages:solid-js:optional: truedependencies:- '@ai-sdk/provider-utils': 1.0.5([email protected])- '@ai-sdk/ui-utils': 0.0.21([email protected])+ '@ai-sdk/provider-utils': 1.0.20([email protected])+ '@ai-sdk/ui-utils': 0.0.46([email protected])transitivePeerDependencies:- zoddev: false- resolution: {integrity: sha512-uNPc7KNy+6/FY436Jys4rP2LnouxNTTPqZp4jLg5s9i4+D8n2ImuKTrrHlJjTB8UiMsWmkRWU+Tqh8BptEExbw==}+ resolution: {integrity: sha512-aIZJaIds+KpCt19yUDCRDWebzF/17GCY7gN9KkcA2QM6IKRO5UmMcqEYja0ZmwFQPm1kBZkF2njhr8VXis2mAw==}engines: {node: '>=18'}peerDependencies:svelte: ^3.0.0 || ^4.0.0@@ -816,16 +813,16 @@ packages:svelte:optional: truedependencies:- '@ai-sdk/provider-utils': 1.0.5([email protected])- '@ai-sdk/ui-utils': 0.0.21([email protected])+ '@ai-sdk/provider-utils': 1.0.20([email protected])+ '@ai-sdk/ui-utils': 0.0.46([email protected])sswr: 2.1.0([email protected])svelte: 4.2.14transitivePeerDependencies:- zoddev: false- /@ai-sdk/[email protected]([email protected]):- resolution: {integrity: sha512-qZ4ScEhNVpVqfg/2KcKYKKQcUpmfVyMD3P06OVDqXpzMaWvw95lUSYkJO/TDI49MhyVyK4eAI35pRU5B7bhrTQ==}+ /@ai-sdk/[email protected]([email protected]):+ resolution: {integrity: sha512-ZG/wneyJG+6w5Nm/hy1AKMuRgjPQToAxBsTk61c9sVPUTaxo+NNjM2MhXQMtmsja2N5evs8NmHie+ExEgpL3cA==}engines: {node: '>=18'}peerDependencies:zod: ^3.0.0@@ -833,14 +830,16 @@ packages:zod:optional: truedependencies:- '@ai-sdk/provider': 0.0.14- '@ai-sdk/provider-utils': 1.0.5([email protected])+ '@ai-sdk/provider': 0.0.24+ '@ai-sdk/provider-utils': 1.0.20([email protected])+ json-schema: 0.4.0secure-json-parse: 2.7.0zod: 3.22.4+ zod-to-json-schema: 3.23.2([email protected])dev: false- resolution: {integrity: sha512-qdlcWH4mrTq93V3b6c/5GwECLBBSUMV4m1F4SYUV5q+YfZjc8NiNcTYGes4pQoSRJBsDvB1Ch0fTam0hM3Gr7w==}+ resolution: {integrity: sha512-Ltu6gbuii8Qlp3gg7zdwdnHdS4M8nqKDij2VVO1223VOtIFwORFJzKqpfx44U11FW8z2TPVBYN+FjkyVIcN2hg==}engines: {node: '>=18'}peerDependencies:vue: ^3.3.4@@ -848,8 +847,8 @@ packages:vue:optional: truedependencies:- '@ai-sdk/provider-utils': 1.0.5([email protected])- '@ai-sdk/ui-utils': 0.0.21([email protected])+ '@ai-sdk/provider-utils': 1.0.20([email protected])+ '@ai-sdk/ui-utils': 0.0.46([email protected])swrv: 1.0.4([email protected])vue: 3.4.21([email protected])transitivePeerDependencies:@@ -867,21 +866,6 @@ packages:'@jridgewell/gen-mapping': 0.3.3'@jridgewell/trace-mapping': 0.3.22- /@anthropic-ai/[email protected]:- resolution: {integrity: sha512-ULzz+0Smk9SNkAi1tcjJByxbt4taBhnQkRAB75iH0ku5dRwiPxGxN0WOWHoNIq22dGWBXJByrQRhVf80V4xAPA==}- dependencies:- '@types/node': 18.19.31- '@types/node-fetch': 2.6.11- abort-controller: 3.0.0- agentkeepalive: 4.5.0- form-data-encoder: 1.7.2- formdata-node: 4.4.1- node-fetch: 2.7.0([email protected])- web-streams-polyfill: 3.3.3- transitivePeerDependencies:- - encoding- dev: false-/@aws-crypto/[email protected]:resolution: {integrity: sha512-341lBBkiY1DfDNKai/wXM3aujNBkXR7tq1URPQDL9wi3AUbI80NR74uF1TXHMm7po1AcnFk8iu2S2IeU/+/A+Q==}dependencies:@@ -5131,7 +5115,7 @@ packages:resolution: {integrity: sha512-m/jtfBPEIXS1asltl8fPQtO3Sb1qMpuL61unQajUmM8zIxeMF1AlqzWXM3QedcYgTTFiJCew5uJjyhpmqhc0+g==}engines: {node: '>=14'}dependencies:- '@opentelemetry/api': 1.8.0+ '@opentelemetry/api': 1.9.0dev: false/@opentelemetry/[email protected]:@@ -9346,22 +9330,9 @@ packages:/@types/[email protected]:resolution: {integrity: sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==}- /@types/[email protected]:- resolution: {integrity: sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==}- dependencies:- '@types/node': 18.11.9- form-data: 4.0.0- dev: false-/@types/[email protected]:resolution: {integrity: sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==}- /@types/[email protected]:- resolution: {integrity: sha512-ArgCD39YpyyrtFKIqMDvjz79jto5fcI/SVUs2HwB+f0dAzq68yqOdyaSivLiLugSziTpNXLQrVb7RZFmdZzbhA==}- dependencies:- undici-types: 5.26.5- dev: false-/@types/[email protected]:resolution: {integrity: sha512-+68kP9yzs4LMp7VNh8gdzMSPZFL44MLGqiHWvttYJe+6qnuVr4Ek9wSBQoveqY/r+LwjCcU29kNVkidwim+kYA==}dev: true@@ -10256,15 +10227,8 @@ packages:- supports-colordev: false- resolution: {integrity: sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==}- engines: {node: '>= 8.0.0'}- dependencies:- humanize-ms: 1.2.1- dev: false-- resolution: {integrity: sha512-FxDgUG/3pKri2GMS+l24Bhk1M01B2LYXNW8nh8R+Ssf+CUnrh2kuThHmWbM2slOs/EBTWFbQ9Z53bC6TWY1yZg==}+ resolution: {integrity: sha512-UEk+TvUsQjqO6auQtwEaJdQ+eAjEErWkbH13rFqUqJl+NkfL9kCwRkLOtsf3/VyrIv0CsHJNvEzWWh9Vld/B3g==}engines: {node: '>=18'}peerDependencies:openai: ^4.42.0@@ -10284,13 +10248,13 @@ packages:zod:optional: truedependencies:- '@ai-sdk/provider': 0.0.14- '@ai-sdk/provider-utils': 1.0.5([email protected])- '@ai-sdk/react': 0.0.31([email protected])([email protected])- '@ai-sdk/solid': 0.0.24([email protected])- '@ai-sdk/svelte': 0.0.25([email protected])([email protected])- '@ai-sdk/ui-utils': 0.0.21([email protected])- '@ai-sdk/vue': 0.0.25([email protected])([email protected])+ '@ai-sdk/provider': 0.0.24+ '@ai-sdk/provider-utils': 1.0.20([email protected])+ '@ai-sdk/react': 0.0.62([email protected])([email protected])+ '@ai-sdk/solid': 0.0.49([email protected])+ '@ai-sdk/svelte': 0.0.51([email protected])([email protected])+ '@ai-sdk/ui-utils': 0.0.46([email protected])+ '@ai-sdk/vue': 0.0.54([email protected])([email protected])'@opentelemetry/api': 1.9.0eventsource-parser: 1.1.2json-schema: 0.4.0@@ -10300,7 +10264,7 @@ packages:secure-json-parse: 2.7.0svelte: 4.2.14zod: 3.22.4- zod-to-json-schema: 3.22.5([email protected])+ zod-to-json-schema: 3.23.2([email protected])transitivePeerDependencies:- solid-js- vue@@ -13160,10 +13124,6 @@ packages:signal-exit: 4.1.0dev: false- resolution: {integrity: sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==}- dev: false-resolution: {integrity: sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==}engines: {node: '>= 6'}@@ -13182,14 +13142,6 @@ packages:mime-types: 2.1.35dev: false- resolution: {integrity: sha512-0iirZp3uVDjVGt9p49aTaqjk84TrglENEDuqfdlZQ1roC9CWlPk6Avf8EEnZNcAqPonwkG35x4n3ww/1THYAeQ==}- engines: {node: '>= 12.20'}- dependencies:- node-domexception: 1.0.0- web-streams-polyfill: 4.0.0-beta.3- dev: false-resolution: {integrity: sha512-n2aZ9tNfYDwaHhvFTkhFErqOMIb8uyzSQ+vGJBjZyanAKZVbGUQ1sngfk9FdkBw7G26O7AgNjLcecLffD1c7eg==}@@ -13818,12 +13770,6 @@ packages:resolution: {integrity: sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==}engines: {node: '>=16.17.0'}- resolution: {integrity: sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==}- dependencies:- ms: 2.1.3- dev: false-resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==}engines: {node: '>=0.10.0'}@@ -16978,11 +16924,6 @@ packages:minimatch: 3.1.2dev: false- resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}- engines: {node: '>=10.5.0'}- dev: false-resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==}engines: {node: 4.x || >=6.0.0}@@ -20614,10 +20555,6 @@ packages:has-symbols: 1.0.3which-boxed-primitive: 1.0.2- resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==}- dev: false-resolution: {integrity: sha512-yY5PpDlfVIU5+y/BSCxAJRBIS1Zc2dDG3Ujq+sR0U+JjUevW2JhocOF+soROYDSaAezOzOKuyyixhD6mBknSmQ==}engines: {node: '>=4'}@@ -21199,16 +21136,6 @@ packages:defaults: 1.0.4dev: false- resolution: {integrity: sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==}- engines: {node: '>= 8'}- dev: false-- resolution: {integrity: sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==}- engines: {node: '>= 14'}- dev: false-resolution: {integrity: sha512-nYfoOqb4EmElljyXU2qdeE76KsvoHdftQKY4DzA9Aw8DervCg2bG634pHLrJ/d6+B4mE3nWTSJv8Mo7B2mbZkw==}dev: false@@ -21667,10 +21594,10 @@ packages:zod: 3.22.4dev: false- resolution: {integrity: sha512-+akaPo6a0zpVCCseDed504KBJUQpEW5QZw7RMneNmKw+fGaML1Z9tUNLnHHAC8x6dzVRO1eB2oEMyZRnuBZg7Q==}+ resolution: {integrity: sha512-uSt90Gzc/tUfyNqxnjlfBs8W6WSGpNBv0rVsNxP/BVSMHMKGdthPYff4xtCHYloJGM0CFxFsb3NbC0eqPhfImw==}peerDependencies:- zod: ^3.22.4+ zod: ^3.23.3dependencies:zod: 3.22.4dev: false