From a37263a755311fda7f35acba1e27c381595c3438 Mon Sep 17 00:00:00 2001 From: Mohit Varikuti Date: Thu, 25 Jun 2026 01:44:04 -0700 Subject: [PATCH] feat: add TwelveLabs Pegasus for full-video summaries Add an opt-in summary source that analyzes the full video (visual + audio) with TwelveLabs' Pegasus model instead of the Supadata caption transcript. Useful for demos, on-screen-text tutorials, sports, music videos, or any video where captions don't capture everything. - lib/twelvelabs.ts: client factory + index/upload/analyze flow (mirrors lib/glm.ts) - POST /api/summarize: opt-in source: "video" path; default transcript path unchanged - Setup/Settings: "twelvelabs" provider wired into key validation, save, delete, and listing - llmChain: surface Pegasus in getAvailableModels; text fallback chain unchanged - Tests: no-network unit test for the Pegasus flow (mocks the SDK) - Docs: README, docs/configuration.md, docs/api.md --- README.md | 5 + __tests__/lib/twelvelabs.test.ts | 144 +++++++++++++++++ app/api/settings/api-keys/route.ts | 6 +- app/api/setup/save-key/route.ts | 5 +- app/api/setup/test-key/route.ts | 30 ++++ app/api/summarize/route.ts | 130 +++++++++++++++- app/settings/page.tsx | 7 +- docs/api.md | 2 + docs/configuration.md | 19 +++ lib/llmChain.ts | 50 ++++-- lib/twelvelabs.ts | 218 ++++++++++++++++++++++++++ lib/userConfig.ts | 2 + package-lock.json | 242 +++++++++++++++++++++++++---- package.json | 1 + 14 files changed, 813 insertions(+), 48 deletions(-) create mode 100644 __tests__/lib/twelvelabs.test.ts create mode 100644 lib/twelvelabs.ts diff --git a/README.md b/README.md index b8c60ab..f0c2175 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Transform lengthy YouTube videos into structured, digestible summaries. YouTube ## Features - **Smart Chapter Detection** - Automatically identifies chapters and topics with precise timestamps +- **Full-Video Summaries (optional)** - Summarize the whole video (visual *and* audio) with [TwelveLabs Pegasus](https://twelvelabs.io), not just the caption transcript - great for demos, tutorials with on-screen text, or videos with sparse captions - **Multi-Language Support** - Generate summaries in English, German, French, Spanish, or Italian - **Clickable Timestamps** - Jump directly to any video position from the summary - **Visual Chapter Timeline** - See video structure at a glance with an interactive timeline @@ -31,6 +32,9 @@ Transform lengthy YouTube videos into structured, digestible summaries. YouTube - **Z.AI Account** - For AI summarization (GLM-4.7) - Sign up at [z.ai](https://z.ai/subscribe?ic=D7NHC27OHD) (referral link) - Pricing: Coding Plan from $3/month or API on-demand +- **TwelveLabs Account** (optional) - For full-video summaries with Pegasus + - Sign up at [twelvelabs.io](https://twelvelabs.io) - generous free tier + - Only needed if you want to summarize from the video itself instead of the transcript > **Disclosure**: The links above are referral links. Using them helps support this project at no extra cost to you. @@ -142,6 +146,7 @@ Update your API keys anytime from the Settings page. - **Database**: [Prisma](https://www.prisma.io/) + SQLite - **Animations**: [Framer Motion](https://www.framer.com/motion/) - **LLM**: [Z.AI GLM-4.7](https://z.ai/subscribe?ic=D7NHC27OHD) +- **Video Understanding** (optional): [TwelveLabs Pegasus](https://twelvelabs.io) - **Transcripts**: [Supadata API](https://supadata.ai/?ref=devrico003) ## Cloud Deployment diff --git a/__tests__/lib/twelvelabs.test.ts b/__tests__/lib/twelvelabs.test.ts new file mode 100644 index 0000000..3ef81e1 --- /dev/null +++ b/__tests__/lib/twelvelabs.test.ts @@ -0,0 +1,144 @@ +import { + summarizeVideoWithPegasus, + isTwelveLabsConfigured, + clearTwelveLabsClient, + TwelveLabsError, +} from '@/lib/twelvelabs'; +import { getUserApiKey } from '@/lib/userConfig'; + +// Mock the user API key lookup so no database/encryption is required. +jest.mock('@/lib/userConfig', () => ({ + getUserApiKey: jest.fn(), +})); + +// Mock the TwelveLabs SDK so the unit test makes no network calls. +const mockIndexesList = jest.fn(); +const mockIndexesCreate = jest.fn(); +const mockTasksCreate = jest.fn(); +const mockTasksWaitForDone = jest.fn(); +const mockAnalyze = jest.fn(); + +jest.mock('twelvelabs-js', () => ({ + TwelveLabs: jest.fn().mockImplementation(() => ({ + indexes: { list: mockIndexesList, create: mockIndexesCreate }, + tasks: { create: mockTasksCreate, waitForDone: mockTasksWaitForDone }, + analyze: mockAnalyze, + })), +})); + +const mockedGetUserApiKey = getUserApiKey as jest.MockedFunction< + typeof getUserApiKey +>; + +const USER_ID = 'test-user'; +const VIDEO_URL = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'; + +describe('lib/twelvelabs', () => { + beforeEach(() => { + jest.clearAllMocks(); + clearTwelveLabsClient(USER_ID); + // Default: an existing index is available (async-iterable list). + mockIndexesList.mockReturnValue({ + async *[Symbol.asyncIterator]() { + yield { id: 'index-123' }; + }, + }); + mockTasksCreate.mockResolvedValue({ id: 'task-1' }); + mockTasksWaitForDone.mockResolvedValue({ + status: 'ready', + videoId: 'video-1', + }); + mockAnalyze.mockResolvedValue({ + data: '# Summary\n\nA full-video summary.', + usage: { outputTokens: 42 }, + }); + }); + + describe('isTwelveLabsConfigured', () => { + it('returns true when an API key is set', async () => { + mockedGetUserApiKey.mockResolvedValue('tlk_secret'); + await expect(isTwelveLabsConfigured(USER_ID)).resolves.toBe(true); + }); + + it('returns false when no API key is set', async () => { + mockedGetUserApiKey.mockResolvedValue(null); + await expect(isTwelveLabsConfigured(USER_ID)).resolves.toBe(false); + }); + }); + + describe('summarizeVideoWithPegasus', () => { + it('throws when TwelveLabs is not configured', async () => { + mockedGetUserApiKey.mockResolvedValue(null); + await expect( + summarizeVideoWithPegasus(VIDEO_URL, 'Summarize', USER_ID) + ).rejects.toThrow(TwelveLabsError); + }); + + it('indexes the video and returns the Pegasus summary', async () => { + mockedGetUserApiKey.mockResolvedValue('tlk_secret'); + + const result = await summarizeVideoWithPegasus( + VIDEO_URL, + 'Summarize this video', + USER_ID + ); + + expect(result.summary).toContain('full-video summary'); + expect(result.tokensUsed).toBe(42); + + // Uploaded the video by URL into the existing index... + expect(mockTasksCreate).toHaveBeenCalledWith({ + indexId: 'index-123', + videoUrl: VIDEO_URL, + }); + // ...waited for indexing... + expect(mockTasksWaitForDone).toHaveBeenCalledWith( + 'task-1', + expect.any(Object) + ); + // ...and analyzed the indexed video with Pegasus. + expect(mockAnalyze).toHaveBeenCalledWith( + expect.objectContaining({ + videoId: 'video-1', + modelName: 'pegasus1.2', + prompt: 'Summarize this video', + }) + ); + // No index was created since one already existed. + expect(mockIndexesCreate).not.toHaveBeenCalled(); + }); + + it('creates an index when none exists', async () => { + mockedGetUserApiKey.mockResolvedValue('tlk_secret'); + mockIndexesList.mockReturnValue({ + async *[Symbol.asyncIterator]() { + // no existing indexes + }, + }); + mockIndexesCreate.mockResolvedValue({ id: 'new-index' }); + + await summarizeVideoWithPegasus(VIDEO_URL, 'Summarize', USER_ID); + + expect(mockIndexesCreate).toHaveBeenCalledWith( + expect.objectContaining({ + models: [ + { modelName: 'pegasus1.2', modelOptions: ['visual', 'audio'] }, + ], + }) + ); + expect(mockTasksCreate).toHaveBeenCalledWith({ + indexId: 'new-index', + videoUrl: VIDEO_URL, + }); + }); + + it('throws when indexing does not complete successfully', async () => { + mockedGetUserApiKey.mockResolvedValue('tlk_secret'); + mockTasksWaitForDone.mockResolvedValue({ status: 'failed' }); + + await expect( + summarizeVideoWithPegasus(VIDEO_URL, 'Summarize', USER_ID) + ).rejects.toThrow(/indexing did not complete/i); + }); + }); +}); diff --git a/app/api/settings/api-keys/route.ts b/app/api/settings/api-keys/route.ts index 5a3db40..9cac033 100644 --- a/app/api/settings/api-keys/route.ts +++ b/app/api/settings/api-keys/route.ts @@ -2,13 +2,15 @@ import { NextRequest, NextResponse } from "next/server"; import { authenticateRequest } from "@/lib/apiAuth"; import { getUserApiKeysWithMasked, deleteUserApiKey } from "@/lib/userConfig"; import { clearGlmClient } from "@/lib/glm"; +import { clearTwelveLabsClient } from "@/lib/twelvelabs"; const SERVICE_NAMES: Record = { supadata: "Supadata", zai: "Z.AI (GLM-4.7)", + twelvelabs: "TwelveLabs (Pegasus)", }; -const VALID_SERVICES = ["supadata", "zai"]; +const VALID_SERVICES = ["supadata", "zai", "twelvelabs"]; /** * GET - Retrieve status of all API keys (masked) for the user @@ -76,6 +78,8 @@ export async function DELETE(request: NextRequest) { // Clear cached clients so they pick up the removal if (service === "zai") { clearGlmClient(auth.userId); + } else if (service === "twelvelabs") { + clearTwelveLabsClient(auth.userId); } return NextResponse.json({ diff --git a/app/api/setup/save-key/route.ts b/app/api/setup/save-key/route.ts index e3bcb32..e421388 100644 --- a/app/api/setup/save-key/route.ts +++ b/app/api/setup/save-key/route.ts @@ -4,9 +4,10 @@ import { authenticateRequest } from "@/lib/apiAuth"; import { setUserApiKey } from "@/lib/userConfig"; import { clearGlmClient } from "@/lib/glm"; import { clearSupadataClient } from "@/lib/supadata"; +import { clearTwelveLabsClient } from "@/lib/twelvelabs"; // Valid service names -const VALID_SERVICES = ["supadata", "zai"]; +const VALID_SERVICES = ["supadata", "zai", "twelvelabs"]; export async function POST(request: NextRequest) { try { @@ -58,6 +59,8 @@ export async function POST(request: NextRequest) { clearSupadataClient(auth.userId); } else if (service === "zai") { clearGlmClient(auth.userId); + } else if (service === "twelvelabs") { + clearTwelveLabsClient(auth.userId); } return NextResponse.json({ diff --git a/app/api/setup/test-key/route.ts b/app/api/setup/test-key/route.ts index 0cb4ab1..98dd43f 100644 --- a/app/api/setup/test-key/route.ts +++ b/app/api/setup/test-key/route.ts @@ -1,6 +1,7 @@ import { NextRequest, NextResponse } from "next/server"; import { Supadata } from "@supadata/js"; import OpenAI from "openai"; +import { TwelveLabs } from "twelvelabs-js"; import { authenticateRequest } from "@/lib/apiAuth"; export async function POST(request: NextRequest) { @@ -93,6 +94,35 @@ export async function POST(request: NextRequest) { } } + if (service === "twelvelabs") { + // Test TwelveLabs API key by listing indexes (a lightweight authed call) + const client = new TwelveLabs({ apiKey }); + + try { + await client.indexes.list({ pageLimit: 1 }); + + // If we get here without error, the key is valid + return NextResponse.json({ + success: true, + message: "TwelveLabs API key is valid", + }); + } catch (apiError: unknown) { + const errorMessage = apiError instanceof Error ? apiError.message : "Unknown error"; + // Check if it's an auth error + if (errorMessage.includes("401") || errorMessage.includes("unauthorized") || errorMessage.includes("invalid") || errorMessage.includes("api_key")) { + return NextResponse.json( + { success: false, error: "Invalid API key" }, + { status: 401 } + ); + } + // Other errors might be network issues but key could still be valid + return NextResponse.json( + { success: false, error: `API test failed: ${errorMessage}` }, + { status: 400 } + ); + } + } + return NextResponse.json( { error: `Unsupported service: ${service}` }, { status: 400 } diff --git a/app/api/summarize/route.ts b/app/api/summarize/route.ts index f21a511..4df02f1 100644 --- a/app/api/summarize/route.ts +++ b/app/api/summarize/route.ts @@ -4,6 +4,10 @@ import { extractVideoId } from "@/lib/youtube"; import { fetchTranscript, TranscriptError } from "@/lib/transcript"; import { chunkTranscript, type TranscriptChunk } from "@/lib/chunking"; import { callWithFallback, getAvailableModels, type ModelId } from "@/lib/llmChain"; +import { + summarizeVideoWithPegasus, + TwelveLabsError, +} from "@/lib/twelvelabs"; import { extractTopics, type ExtractedTopic } from "@/lib/topicExtraction"; import { logApiUsage } from "@/lib/usageLogger"; import { authenticateRequest } from "@/lib/apiAuth"; @@ -128,10 +132,11 @@ export async function POST(req: NextRequest) { (async () => { try { const body = await req.json(); - const { url, detailLevel = 3, language = "en" } = body as { + const { url, detailLevel = 3, language = "en", source = "transcript" } = body as { url: string; detailLevel?: number; language?: OutputLanguage; + source?: "transcript" | "video"; }; if (!url) { @@ -207,6 +212,22 @@ export async function POST(req: NextRequest) { return; } + // Opt-in path: summarize the full video (visual + audio) with TwelveLabs + // Pegasus instead of the caption transcript. Non-breaking — only runs when + // the client explicitly requests source: "video". + if (source === "video") { + await summarizeWithPegasus({ + url, + videoId, + detailLevel, + language: language as OutputLanguage, + userId, + writeProgress, + }); + await writer.close(); + return; + } + // Stage 1: Fetch Transcript await writeProgress({ type: "progress", @@ -389,6 +410,20 @@ export async function POST(req: NextRequest) { errorMessage = error.message; } errorDetails = `Error code: ${error.code}`; + } else if (error instanceof TwelveLabsError) { + switch (error.code) { + case "TWELVELABS_NOT_CONFIGURED": + errorMessage = + "TwelveLabs is not configured. Please add your API key in settings."; + break; + case "INDEXING_FAILED": + errorMessage = + "TwelveLabs could not index this video. Make sure the URL is publicly accessible."; + break; + default: + errorMessage = error.message; + } + errorDetails = `Error code: ${error.code}`; } else if (error instanceof Error) { errorMessage = error.message; errorDetails = error.stack; @@ -461,6 +496,99 @@ const DETAIL_CONFIGS: Record = { }, }; +/** + * Generate a summary from the full video (visual + audio) using TwelveLabs + * Pegasus, then persist and stream the result. This is the opt-in + * `source: "video"` path; it does not use the Supadata transcript pipeline. + * + * Pegasus returns prose without structured timestamps, so the resulting + * summary has `hasTimestamps: false` and no timeline topics — the same shape + * the transcript path already uses when timestamps are unavailable. + */ +async function summarizeWithPegasus(params: { + url: string; + videoId: string; + detailLevel: number; + language: OutputLanguage; + userId: string; + writeProgress: (event: ProgressEvent) => Promise; +}): Promise { + const { url, videoId, detailLevel, language, userId, writeProgress } = params; + + const config = DETAIL_CONFIGS[detailLevel] || DETAIL_CONFIGS[3]; + const languageName = LANGUAGE_NAMES[language] || "English"; + + await writeProgress({ + type: "progress", + stage: "fetching_transcript", + message: "Uploading video to TwelveLabs and indexing (this can take a few minutes)...", + }); + + await writeProgress({ + type: "progress", + stage: "generating_summary", + message: "Analyzing full video with Pegasus (visual + audio)...", + }); + + // Reuse the existing chapter-based prompt; Pegasus reads the video directly + // rather than a transcript, so we pass an instruction in place of transcript text. + const prompt = buildChapterBasedPrompt( + "Analyze the full video directly (visual content and audio), not a transcript.", + videoId, + config, + languageName + ); + + const { summary, tokensUsed } = await summarizeVideoWithPegasus( + url, + prompt, + userId, + { + maxTokens: 4096, + onProgress: () => { + // Indexing status updates are intentionally not streamed per-tick to + // avoid noisy progress events; the initial message covers the wait. + }, + } + ); + + const modelUsed: ModelId = "pegasus1.2"; + await logApiUsage(userId, modelUsed, "summary", 0, tokensUsed || 0); + + const title = extractTitleFromSummary(summary) || `Video Summary - ${videoId}`; + + const savedSummary = await prisma.summary.create({ + data: { + videoId, + userId, + title, + content: summary, + transcript: "", + hasTimestamps: false, + }, + include: { + topics: { orderBy: { order: "asc" } }, + transcriptSegments: { orderBy: { order: "asc" } }, + }, + }); + + await writeProgress({ + type: "complete", + summary: { + id: savedSummary.id, + videoId: savedSummary.videoId, + title: savedSummary.title, + content: savedSummary.content, + hasTimestamps: savedSummary.hasTimestamps, + topics: [], + transcriptSegments: [], + modelUsed, + source: "generated", + }, + status: "completed", + }); +} + /** * Generate chapter-based summary from transcript chunks */ diff --git a/app/settings/page.tsx b/app/settings/page.tsx index b1adadf..6ccf553 100644 --- a/app/settings/page.tsx +++ b/app/settings/page.tsx @@ -26,7 +26,7 @@ interface ApiKeyState { deleting: boolean } -const API_KEY_SERVICES = ["supadata", "zai"] as const +const API_KEY_SERVICES = ["supadata", "zai", "twelvelabs"] as const type ApiKeyService = typeof API_KEY_SERVICES[number] export default function SettingsPage() { @@ -228,6 +228,11 @@ export default function SettingsPage() { description: "GLM-4.7 model - Coding Plan or API Credit Mode", url: "https://z.ai/subscribe?ic=D7NHC27OHD", urlLabel: "z.ai" + }, + twelvelabs: { + description: "Optional - full-video summaries (visual + audio) with Pegasus", + url: "https://twelvelabs.io", + urlLabel: "twelvelabs.io" } } return info[service] diff --git a/docs/api.md b/docs/api.md index f8df26d..6a41d39 100644 --- a/docs/api.md +++ b/docs/api.md @@ -143,6 +143,8 @@ Generate a video summary. Returns a streaming response with progress events. |-------|------|----------|-------------| | url | string | Yes | YouTube video URL | | detailLevel | number | No | 1-5, default 3 (Balanced) | +| language | string | No | Output language: `en` (default), `de`, `fr`, `es`, `it` | +| source | string | No | `transcript` (default) or `video`. `video` uses TwelveLabs Pegasus to summarize the full video (visual + audio) instead of the caption transcript; requires a configured `twelvelabs` API key. Pegasus summaries have `hasTimestamps: false` and no timeline topics. | **Response (Streaming):** diff --git a/docs/configuration.md b/docs/configuration.md index 305546d..bd9feca 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -43,6 +43,25 @@ Z.AI provides access to the GLM-4.7 model, which supports "thinking mode" for en - Thinking mode for complex analysis - Primary model in the fallback chain +### TwelveLabs / Pegasus (Optional, full-video summaries) + +TwelveLabs' Pegasus model analyzes the **full video** — visual frames *and* +audio — instead of only the caption transcript. This is useful for videos +where the spoken words don't capture everything: demos, tutorials with +on-screen text, sports, music videos, or silent footage. + +1. Visit [TwelveLabs](https://twelvelabs.io) and grab a free API key (there's a + generous free tier) +2. Add it via Setup Wizard or Settings > API Keys (service name: `twelvelabs`) + +**Features:** +- Visual + audio video understanding (not just captions) +- Opt-in and non-breaking — the default transcript pipeline is unchanged +- Selected per request with `source: "video"` (see [API](api.md)) + +> Note: Pegasus uploads and indexes the video server-side before analysis, +> which can take a few minutes for longer videos. + ### Gemini (Fallback) Google's Gemini is a fast and efficient model. diff --git a/lib/llmChain.ts b/lib/llmChain.ts index c2d52d4..4c608a9 100644 --- a/lib/llmChain.ts +++ b/lib/llmChain.ts @@ -4,21 +4,32 @@ import { getGlmPaasClient, isGlmConfigured, } from "./glm"; +import { isTwelveLabsConfigured } from "./twelvelabs"; /** - * Model identifiers for the fallback chain + * Model identifiers. + * + * Text models ("glm-4.7") participate in the {@link callWithFallback} chain. + * "pegasus1.2" is TwelveLabs' video understanding model; it summarizes the full + * video (visual + audio) via lib/twelvelabs and is NOT part of the text + * fallback chain — it is selected by the request's `source: "video"` option. + */ +export type ModelId = "glm-4.7" | "pegasus1.2"; + +/** + * Text model identifiers eligible for the fallback chain. */ -export type ModelId = "glm-4.7"; +type TextModelId = "glm-4.7"; /** * Provider group type */ -export type ProviderGroup = "zai"; +export type ProviderGroup = "zai" | "twelvelabs"; /** - * Model to provider group mapping + * Text model to provider group mapping (used by the fallback chain). */ -const MODEL_GROUPS: Record = { +const MODEL_GROUPS: Record = { "glm-4.7": "zai", }; @@ -59,10 +70,19 @@ export interface LlmCallOptions { * @returns Promise - Array of model info with availability */ export async function getAvailableModels(userId: string): Promise { - const glmAvailable = await isGlmConfigured(userId); + const [glmAvailable, pegasusAvailable] = await Promise.all([ + isGlmConfigured(userId), + isTwelveLabsConfigured(userId), + ]); return [ { id: "glm-4.7", name: "GLM-4.7", available: glmAvailable, group: "zai" as ProviderGroup }, + { + id: "pegasus1.2", + name: "Pegasus (full-video, visual + audio)", + available: pegasusAvailable, + group: "twelvelabs" as ProviderGroup, + }, ]; } @@ -84,19 +104,25 @@ export async function callWithFallback( throw new Error("userId is required for LLM calls"); } - const errors: { model: ModelId; error: string }[] = []; + const errors: { model: TextModelId; error: string }[] = []; - // Build the model order - only GLM-4.7 available - const preferredModel = options.preferredModel || "glm-4.7"; + // Build the model order - only text models participate in the fallback chain. + // If a non-text model (e.g. Pegasus) is requested, fall back to the default + // text model; video summaries are handled separately via lib/twelvelabs. + const requested = options.preferredModel; + const preferredModel: TextModelId = + requested && requested in MODEL_GROUPS + ? (requested as TextModelId) + : "glm-4.7"; const group = MODEL_GROUPS[preferredModel]; // Get all models in the same group for fallback const groupModels = Object.entries(MODEL_GROUPS) .filter(([, g]) => g === group) - .map(([id]) => id as ModelId); + .map(([id]) => id as TextModelId); // Build order: preferred first, then other models in same group - const modelOrder: ModelId[] = [ + const modelOrder: TextModelId[] = [ preferredModel, ...groupModels.filter((m) => m !== preferredModel), ]; @@ -134,7 +160,7 @@ export async function callWithFallback( * Returns null if model is not configured. */ async function callModel( - modelId: ModelId, + modelId: TextModelId, prompt: string, options: { maxTokens: number; temperature: number; systemPrompt?: string; userId: string } ): Promise { diff --git a/lib/twelvelabs.ts b/lib/twelvelabs.ts new file mode 100644 index 0000000..decffb8 --- /dev/null +++ b/lib/twelvelabs.ts @@ -0,0 +1,218 @@ +import { TwelveLabs } from "twelvelabs-js"; +import { getUserApiKey } from "./userConfig"; + +/** + * TwelveLabs Pegasus integration. + * + * Pegasus is a video understanding model that analyzes the *full* video + * (visual frames + audio), not just a caption transcript. This is an opt-in + * alternative to the default Supadata transcript -> LLM pipeline and is useful + * for videos where the spoken words don't capture everything (demos, tutorials + * with on-screen text, sports, music videos, silent footage, etc.). + * + * Workflow: + * 1. Reuse (or create) a Pegasus-enabled index for the user. + * 2. Upload the YouTube video by URL and wait for indexing to finish. + * 3. Analyze the indexed video with a summary prompt and return the text. + */ + +/** Pegasus model used for analysis. */ +const PEGASUS_MODEL = "pegasus1.2"; + +/** Name of the index this app creates and reuses for Pegasus analysis. */ +const INDEX_NAME = "youtube-summarizer-pegasus"; + +/** + * Per-user client cache to avoid recreating clients (mirrors lib/glm.ts). + */ +const twelveLabsClients: Map = new Map(); + +/** + * Per-user index id cache so we don't list/create the index on every request. + */ +const indexIdCache: Map = new Map(); + +/** + * Error thrown when TwelveLabs analysis fails. + */ +export class TwelveLabsError extends Error { + constructor( + message: string, + public readonly code: string + ) { + super(message); + this.name = "TwelveLabsError"; + } +} + +/** + * Gets or creates a TwelveLabs client for a user. + * + * @param userId - The user's ID to fetch their API key + * @returns Promise - The client, or null if no API key is configured + */ +export async function getTwelveLabsClient( + userId: string +): Promise { + const cached = twelveLabsClients.get(userId); + if (cached) { + return cached; + } + + const apiKey = await getUserApiKey(userId, "twelvelabs"); + if (!apiKey) { + return null; + } + + const client = new TwelveLabs({ apiKey }); + twelveLabsClients.set(userId, client); + return client; +} + +/** + * Clears the cached TwelveLabs client for a user. Call when the API key changes. + * + * @param userId - The user's ID + */ +export function clearTwelveLabsClient(userId: string): void { + twelveLabsClients.delete(userId); + indexIdCache.delete(userId); +} + +/** + * Checks if TwelveLabs is configured for a user. + * + * @param userId - The user's ID + * @returns Promise - true if a TwelveLabs API key is configured + */ +export async function isTwelveLabsConfigured(userId: string): Promise { + const apiKey = await getUserApiKey(userId, "twelvelabs"); + return apiKey !== null && apiKey.length > 0; +} + +/** + * Finds an existing Pegasus index for the user, or creates one. + */ +async function getOrCreateIndex( + client: TwelveLabs, + userId: string +): Promise { + const cached = indexIdCache.get(userId); + if (cached) { + return cached; + } + + // Reuse an existing index with our name if one is available. + const indexes = await client.indexes.list({ indexName: INDEX_NAME }); + for await (const index of indexes) { + if (index.id) { + indexIdCache.set(userId, index.id); + return index.id; + } + } + + // Otherwise create a new Pegasus-enabled index (visual + audio). + const created = await client.indexes.create({ + indexName: INDEX_NAME, + models: [{ modelName: PEGASUS_MODEL, modelOptions: ["visual", "audio"] }], + }); + + if (!created.id) { + throw new TwelveLabsError( + "Failed to create TwelveLabs index", + "INDEX_CREATE_FAILED" + ); + } + + indexIdCache.set(userId, created.id); + return created.id; +} + +/** + * Response from a Pegasus video summary. + */ +export interface PegasusSummaryResult { + /** The generated summary text (Markdown). */ + summary: string; + /** Number of output tokens used, if reported. */ + tokensUsed?: number; +} + +/** + * Summarizes a YouTube video with Pegasus by analyzing the full video + * (visual + audio) rather than only the caption transcript. + * + * Note: indexing a video is asynchronous and can take a few minutes depending + * on the video length. The caller should surface progress to the user. + * + * @param videoUrl - A publicly accessible video URL (e.g. a YouTube URL) + * @param prompt - The analysis prompt that guides the summary format + * @param userId - The user's ID (required for API key lookup) + * @param options - Optional configuration + * @param options.maxTokens - Maximum response length in tokens (default 4096) + * @param options.onProgress - Callback invoked with the indexing status string + * @returns The generated summary text + * @throws TwelveLabsError if TwelveLabs is not configured or analysis fails + */ +export async function summarizeVideoWithPegasus( + videoUrl: string, + prompt: string, + userId: string, + options: { + maxTokens?: number; + onProgress?: (status: string) => void; + } = {} +): Promise { + const client = await getTwelveLabsClient(userId); + if (!client) { + throw new TwelveLabsError( + "TwelveLabs is not configured. Please add your TwelveLabs API key in settings.", + "TWELVELABS_NOT_CONFIGURED" + ); + } + + const { maxTokens = 4096, onProgress } = options; + + const indexId = await getOrCreateIndex(client, userId); + + // Upload the video by URL and wait for indexing to finish. + const task = await client.tasks.create({ indexId, videoUrl }); + if (!task.id) { + throw new TwelveLabsError( + "Failed to create TwelveLabs indexing task", + "TASK_CREATE_FAILED" + ); + } + + const completed = await client.tasks.waitForDone(task.id, { + sleepInterval: 5, + callback: (t) => onProgress?.(t.status ?? "processing"), + }); + + if (completed.status !== "ready" || !completed.videoId) { + throw new TwelveLabsError( + `Video indexing did not complete successfully (status: ${completed.status ?? "unknown"})`, + "INDEXING_FAILED" + ); + } + + // Analyze the indexed video with Pegasus. + const analysis = await client.analyze({ + videoId: completed.videoId, + modelName: PEGASUS_MODEL, + prompt, + maxTokens, + }); + + if (!analysis.data) { + throw new TwelveLabsError( + "TwelveLabs returned an empty analysis", + "EMPTY_ANALYSIS" + ); + } + + return { + summary: analysis.data, + tokensUsed: analysis.usage?.outputTokens, + }; +} diff --git a/lib/userConfig.ts b/lib/userConfig.ts index efd91da..a23f5b0 100644 --- a/lib/userConfig.ts +++ b/lib/userConfig.ts @@ -119,6 +119,7 @@ export async function getUserApiKeys( const result: Record = { supadata: false, zai: false, + twelvelabs: false, }; for (const key of apiKeys) { @@ -146,6 +147,7 @@ export async function getUserApiKeysWithMasked( const result: Record = { supadata: { configured: false, masked: null }, zai: { configured: false, masked: null }, + twelvelabs: { configured: false, masked: null }, }; for (const apiKey of apiKeys) { diff --git a/package-lock.json b/package-lock.json index e509386..bf08bb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -47,6 +47,7 @@ "sonner": "^2.0.7", "tailwind-merge": "^3.0.1", "tailwindcss-animate": "^1.0.7", + "twelvelabs-js": "^1.2.8", "youtube-transcript": "^1.2.1" }, "devDependencies": { @@ -6619,6 +6620,18 @@ } } }, + "node_modules/abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "license": "MIT", + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, "node_modules/acorn": { "version": "8.15.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", @@ -6935,6 +6948,12 @@ "node": ">= 0.4" } }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, "node_modules/available-typed-arrays": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", @@ -7510,7 +7529,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -7524,7 +7542,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", - "dev": true, "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.2", @@ -7929,6 +7946,18 @@ "dev": true, "license": "MIT" }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/comma-separated-tokens": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz", @@ -8218,6 +8247,15 @@ "integrity": "sha512-mEQCMmwJu317oSz8CwdIOdwf3xMif1ttiM8LTufzc3g6kR+9Pe236twL8j3IYT1F7GfRgGcW6MWxzZjLIkuHIg==", "license": "MIT" }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/denque": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", @@ -8398,7 +8436,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", - "dev": true, "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.1", @@ -8582,7 +8619,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -8592,7 +8628,6 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -8630,7 +8665,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0" @@ -8643,7 +8677,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -9313,6 +9346,24 @@ "node": ">=0.10.0" } }, + "node_modules/event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/events": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", + "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", + "license": "MIT", + "engines": { + "node": ">=0.8.x" + } + }, "node_modules/exit-x": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/exit-x/-/exit-x-0.2.2.tgz", @@ -9571,6 +9622,40 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/form-data": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.6.tgz", + "integrity": "sha512-vKatAh4SlVfgbv+YtmhiRjhEMJsYpsG1Y2rMQtR+SVSbytsSD1YGzDIcrAJmdFec88u/+VoGmxnl+80gL1tRCQ==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.4", + "mime-types": "^2.1.35" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/form-data-encoder": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-4.1.0.tgz", + "integrity": "sha512-G6NsmEW15s0Uw9XnCg+33H3ViYRyiM0hMrMhhqQOR8NFc5GhYrI+6I3u7OTw7b91J2g8rtvMBZJDbcGb2YUniw==", + "license": "MIT", + "engines": { + "node": ">= 18" + } + }, + "node_modules/formdata-node": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-6.0.3.tgz", + "integrity": "sha512-8e1++BCiTzUno9v5IZ2J6bv4RU+3UKDmqWUQD0MIMVCd9AdhWkO1gw57oo1mNEX1dMq2EGI+FbWz4B92pscSQg==", + "license": "MIT", + "engines": { + "node": ">= 18" + } + }, "node_modules/framer-motion": { "version": "12.29.2", "resolved": "https://registry.npmjs.org/framer-motion/-/framer-motion-12.29.2.tgz", @@ -9630,7 +9715,6 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", - "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -9710,7 +9794,6 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", - "dev": true, "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.2", @@ -9760,7 +9843,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", - "dev": true, "license": "MIT", "dependencies": { "dunder-proto": "^1.0.1", @@ -9892,7 +9974,6 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -9996,7 +10077,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -10009,7 +10089,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", - "dev": true, "license": "MIT", "dependencies": { "has-symbols": "^1.0.3" @@ -10022,10 +10101,9 @@ } }, "node_modules/hasown": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", - "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", - "dev": true, + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", + "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", "license": "MIT", "dependencies": { "function-bind": "^1.1.2" @@ -12115,7 +12193,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -12745,6 +12822,27 @@ "node": ">=8.6" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/mimic-response": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", @@ -13150,7 +13248,6 @@ "version": "1.13.4", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -13990,6 +14087,15 @@ "node": ">=6" } }, + "node_modules/process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", + "license": "MIT", + "engines": { + "node": ">= 0.6.0" + } + }, "node_modules/prop-types": { "version": "15.8.1", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", @@ -14071,6 +14177,22 @@ "integrity": "sha512-c4iYnWb+k2E+vYpRimHqSu575b1/wKl4XFeJGpFmrJQz5I88v9aY2czh7s0w36srfCM1sXgC/xpoJz5dJfq+OQ==", "license": "MIT" }, + "node_modules/qs": { + "version": "6.15.3", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.3.tgz", + "integrity": "sha512-O9gl3zCl5h5blw1KGUzQKhA5oUXSl8rwUIM5o0S3nCXMliSvy5Dzx7/DJcI+SwgICv+IneSZwhBh1oSyEHA71A==", + "license": "BSD-3-Clause", + "dependencies": { + "es-define-property": "^1.0.1", + "side-channel": "^1.1.1" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -14791,15 +14913,14 @@ } }, "node_modules/side-channel": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", - "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", - "dev": true, + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz", + "integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==", "license": "MIT", "dependencies": { "es-errors": "^1.3.0", - "object-inspect": "^1.13.3", - "side-channel-list": "^1.0.0", + "object-inspect": "^1.13.4", + "side-channel-list": "^1.0.1", "side-channel-map": "^1.0.1", "side-channel-weakmap": "^1.0.2" }, @@ -14811,14 +14932,13 @@ } }, "node_modules/side-channel-list": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", - "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", - "dev": true, + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz", + "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==", "license": "MIT", "dependencies": { "es-errors": "^1.3.0", - "object-inspect": "^1.13.3" + "object-inspect": "^1.13.4" }, "engines": { "node": ">= 0.4" @@ -14831,7 +14951,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", - "dev": true, "license": "MIT", "dependencies": { "call-bound": "^1.0.2", @@ -14850,7 +14969,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", - "dev": true, "license": "MIT", "dependencies": { "call-bound": "^1.0.2", @@ -15853,6 +15971,60 @@ "node": "*" } }, + "node_modules/twelvelabs-js": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/twelvelabs-js/-/twelvelabs-js-1.2.8.tgz", + "integrity": "sha512-LFOIp0zUA1YmOGW2Q8ugav81ln0XTsyPpLki4iCGiJFfsnWx9by47FUbLf2g08EfNwZp8n0G44cTtqjPGn5mSw==", + "dependencies": { + "form-data": "^4.0.0", + "form-data-encoder": "^4.0.2", + "formdata-node": "^6.0.3", + "node-fetch": "^2.7.0", + "qs": "^6.13.1", + "readable-stream": "^4.5.2", + "url-join": "4.0.1" + } + }, + "node_modules/twelvelabs-js/node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/twelvelabs-js/node_modules/readable-stream": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.7.0.tgz", + "integrity": "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg==", + "license": "MIT", + "dependencies": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10", + "string_decoder": "^1.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -16259,6 +16431,12 @@ "punycode": "^2.1.0" } }, + "node_modules/url-join": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", + "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==", + "license": "MIT" + }, "node_modules/use-callback-ref": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/use-callback-ref/-/use-callback-ref-1.3.3.tgz", diff --git a/package.json b/package.json index 64e436e..d0fa87a 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "sonner": "^2.0.7", "tailwind-merge": "^3.0.1", "tailwindcss-animate": "^1.0.7", + "twelvelabs-js": "^1.2.8", "youtube-transcript": "^1.2.1" }, "devDependencies": {