Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 62 additions & 35 deletions apps/web/app/api/og/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import ogs from "open-graph-scraper"

export const runtime = "nodejs"

interface OGResponse {
title: string
description: string
Expand All @@ -20,7 +16,6 @@ function isValidUrl(urlString: string): boolean {
function isPrivateHost(hostname: string): boolean {
const lowerHost = hostname.toLowerCase()

// Block localhost variants
if (
lowerHost === "localhost" ||
lowerHost === "127.0.0.1" ||
Expand All @@ -31,7 +26,6 @@ function isPrivateHost(hostname: string): boolean {
return true
}

// Block RFC 1918 private IP ranges
const privateIpPatterns = [
/^10\./,
/^172\.(1[6-9]|2[0-9]|3[01])\./,
Expand Down Expand Up @@ -102,12 +96,23 @@ function extractImageUrl(image: unknown): string | undefined {
return String(first.url)
}
}
return ""
}

if (typeof image === "object" && image !== null && "url" in image) {
return String(image.url)
function extractMetaTag(html: string, patterns: RegExp[]): string {
for (const pattern of patterns) {
const match = html.match(pattern)
if (match?.[1]) {
return match[1]
.replace(/&/g, "&")
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&quot;/g, '"')
.replace(/&#039;/g, "'")
.trim()
}
}

return undefined
return ""
}

function resolveImageUrl(
Expand Down Expand Up @@ -171,46 +176,68 @@ export async function GET(request: Request) {
)
}

const { result, error } = await ogs({
url: trimmedUrl,
timeout: 8000,
fetchOptions: {
headers: {
"User-Agent":
"Mozilla/5.0 (compatible; SuperMemory/1.0; +https://supermemory.ai)",
},
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), 8000)

const response = await fetch(trimmedUrl, {
signal: controller.signal,
headers: {
"User-Agent":
"Mozilla/5.0 (compatible; SuperMemory/1.0; +https://supermemory.ai)",
},
})

if (error || !result) {
console.error("OG scraping error:", error)
clearTimeout(timeoutId)

if (!response.ok) {
return Response.json(
{ error: "Failed to fetch Open Graph data" },
{ status: 500 },
{ error: "Failed to fetch URL" },
{ status: response.status },
)
}

const ogTitle = result.ogTitle || result.twitterTitle || ""
const ogDescription =
result.ogDescription || result.twitterDescription || ""

const ogImageUrl =
extractImageUrl(result.ogImage) || extractImageUrl(result.twitterImage)

const resolvedImageUrl = resolveImageUrl(ogImageUrl, trimmedUrl)

const response: OGResponse = {
title: ogTitle,
description: ogDescription,
const html = await response.text()

const titlePatterns = [
/<meta\s+property=["']og:title["']\s+content=["']([^"']+)["']/i,
/<meta\s+content=["']([^"']+)["']\s+property=["']og:title["']/i,
/<meta\s+name=["']twitter:title["']\s+content=["']([^"']+)["']/i,
/<title>([^<]+)<\/title>/i,
]

const descriptionPatterns = [
/<meta\s+property=["']og:description["']\s+content=["']([^"']+)["']/i,
/<meta\s+content=["']([^"']+)["']\s+property=["']og:description["']/i,
/<meta\s+name=["']twitter:description["']\s+content=["']([^"']+)["']/i,
/<meta\s+name=["']description["']\s+content=["']([^"']+)["']/i,
]

const imagePatterns = [
/<meta\s+property=["']og:image["']\s+content=["']([^"']+)["']/i,
/<meta\s+content=["']([^"']+)["']\s+property=["']og:image["']/i,
/<meta\s+name=["']twitter:image["']\s+content=["']([^"']+)["']/i,
]

const title = extractMetaTag(html, titlePatterns)
const description = extractMetaTag(html, descriptionPatterns)
const imageUrl = extractMetaTag(html, imagePatterns)
const resolvedImageUrl = resolveImageUrl(imageUrl, trimmedUrl)

const ogResponse: OGResponse = {
title,
description,
...(resolvedImageUrl && { image: resolvedImageUrl }),
}

return Response.json(response, {
return Response.json(ogResponse, {
headers: {
"Cache-Control": "public, s-maxage=3600, stale-while-revalidate=86400",
},
})
} catch (error) {
if (error instanceof Error && error.name === "AbortError") {
return Response.json({ error: "Request timeout" }, { status: 504 })
}
console.error("OG route error:", error)
return Response.json({ error: "Internal server error" }, { status: 500 })
}
Expand Down
1 change: 0 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"next": "16.0.9",
"next-themes": "^0.4.6",
"nuqs": "^2.5.2",
"open-graph-scraper": "^6.11.0",
"pdfjs-dist": "5.4.296",
"posthog-js": "^1.257.0",
"random-word-slugs": "^0.1.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/pipecat-sdk-python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "supermemory-pipecat"
version = "0.1.0"
version = "0.1.1"
description = "Supermemory integration for Pipecat - memory-enhanced conversational AI pipelines"
readme = "README.md"
license = "MIT"
Expand Down
10 changes: 5 additions & 5 deletions packages/pipecat-sdk-python/src/supermemory_pipecat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@
```
"""

from .service import SupermemoryPipecatService
from .exceptions import (
SupermemoryPipecatError,
APIError,
ConfigurationError,
MemoryRetrievalError,
MemoryStorageError,
APIError,
NetworkError,
SupermemoryPipecatError,
)
from .service import SupermemoryPipecatService
from .utils import (
get_last_user_message,
deduplicate_memories,
format_memories_to_text,
get_last_user_message,
)

__version__ = "0.1.0"
__version__ = "0.1.1"

__all__ = [
# Main service
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@supermemory/tools",
"type": "module",
"version": "1.3.67",
"version": "1.3.68",
"description": "Memory tools for AI SDK and OpenAI function calling with supermemory",
"scripts": {
"build": "tsdown",
Expand Down
Loading