Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Fix invalid json in AI doc SSE stream (#20706)

Greg Richardson0417b8d96e22
diff --git a/apps/database-new/types/sse.d.ts b/apps/database-new/types/sse.d.ts
deleted file mode 100644
index dbf97ac0836..00000000000
--- a/apps/database-new/types/sse.d.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-declare module 'sse.js' {
- export type SSEOptions = EventSourceInit & {
- headers?: Record<string, string>
- payload?: string
- method?: string
- }
-
- export class SSE extends EventSource {
- constructor(url: string | URL, sseOptions?: SSEOptions)
- stream(): void
- }
-}
diff --git a/apps/studio/types/sse.d.ts b/apps/studio/types/sse.d.ts
deleted file mode 100644
index dbf97ac0836..00000000000
--- a/apps/studio/types/sse.d.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-declare module 'sse.js' {
- export type SSEOptions = EventSourceInit & {
- headers?: Record<string, string>
- payload?: string
- method?: string
- }
-
- export class SSE extends EventSource {
- constructor(url: string | URL, sseOptions?: SSEOptions)
- stream(): void
- }
-}
diff --git a/apps/www/types/sse.d.ts b/apps/www/types/sse.d.ts
deleted file mode 100644
index dbf97ac0836..00000000000
--- a/apps/www/types/sse.d.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-declare module 'sse.js' {
- export type SSEOptions = EventSourceInit & {
- headers?: Record<string, string>
- payload?: string
- method?: string
- }
-
- export class SSE extends EventSource {
- constructor(url: string | URL, sseOptions?: SSEOptions)
- stream(): void
- }
-}
diff --git a/package-lock.json b/package-lock.json
index ab9aa8aa315..99345bbea33 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -32964,8 +32964,9 @@
}
},
"node_modules/sse.js": {
- "version": "0.6.1",
- "license": "Apache-2.0"
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/sse.js/-/sse.js-2.2.0.tgz",
+ "integrity": "sha512-v1ciaikunC99FKS23rS973HYU0DnnvugtX13UggNvrgRUSungaGeLmKlm57t0dI2E1TcCqzc2Pj2njBDXFIpKQ=="
},
"node_modules/ssr-window": {
"version": "3.0.0",
@@ -37217,7 +37218,7 @@
"react-tooltip": "^4.2.17",
"reactflow": "^11.10.1",
"remark-gfm": "^3.0.1",
- "sse.js": "^0.6.1",
+ "sse.js": "^2.2.0",
"tailwind-merge": "^1.13.2",
"tailwindcss": "^3.4.1",
"tailwindcss-animate": "^1.0.6",
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 43d28390614..d3bd3e0612e 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -77,7 +77,7 @@
"react-tooltip": "^4.2.17",
"reactflow": "^11.10.1",
"remark-gfm": "^3.0.1",
- "sse.js": "^0.6.1",
+ "sse.js": "^2.2.0",
"tailwind-merge": "^1.13.2",
"tailwindcss": "^3.4.1",
"tailwindcss-animate": "^1.0.6",
diff --git a/packages/ui/src/components/Command/AiCommand.tsx b/packages/ui/src/components/Command/AiCommand.tsx
index f1836208c75..743ffd950af 100644
--- a/packages/ui/src/components/Command/AiCommand.tsx
+++ b/packages/ui/src/components/Command/AiCommand.tsx
@@ -198,7 +198,7 @@ export function useAiChat({
}
eventSource.addEventListener('error', handleError)
- eventSource.addEventListener('message', (e) => {
+ eventSource.addEventListener('message', (e: MessageEvent) => {
try {
setIsLoading?.(false)
@@ -307,7 +307,7 @@ export function queryAi(messages: Message[], timeout = 0) {
let answer = ''
eventSource.addEventListener('error', handleError)
- eventSource.addEventListener('message', (e) => {
+ eventSource.addEventListener('message', (e: MessageEvent) => {
try {
if (e.data === '[DONE]') {
if (timeoutId) {
diff --git a/packages/ui/src/types/sse.d.ts b/packages/ui/src/types/sse.d.ts
deleted file mode 100644
index dbf97ac0836..00000000000
--- a/packages/ui/src/types/sse.d.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-declare module 'sse.js' {
- export type SSEOptions = EventSourceInit & {
- headers?: Record<string, string>
- payload?: string
- method?: string
- }
-
- export class SSE extends EventSource {
- constructor(url: string | URL, sseOptions?: SSEOptions)
- stream(): void
- }
-}