vidnavigator 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # VidNavigator JavaScript SDK
2
+
3
+ The official JavaScript SDK for the [VidNavigator Developer API](https://vidnavigator.com).
4
+
5
+ This SDK provides a convenient, fully-typed wrapper around the VidNavigator REST API, making it easy to integrate video transcription, analysis, and search into your Node.js applications.
6
+
7
+ ## Features
8
+
9
+ - **Modern TypeScript:** Fully written in TypeScript for a great developer experience with autocompletion and type-safety.
10
+ - **Rich Object Models:** API responses are automatically converted into intuitive classes (`VideoInfo`, `FileInfo`, `AnalysisResult`, etc.).
11
+ - **Promise-based:** All asynchronous operations return Promises for easy integration with `async/await`.
12
+ - **Minimal Dependencies:** Lightweight and relies only on `axios` for HTTP requests and `form-data` for uploads.
13
+ - **Node.js Support:** Optimized for server-side use in Node.js 16+.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install vidnavigator
19
+ # or
20
+ yarn add vidnavigator
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ First, initialize the SDK with your API key. It's recommended to store your key in an environment variable.
26
+
27
+ ```ts
28
+ import { VidNavigatorClient } from 'vidnavigator';
29
+
30
+ const vn = new VidNavigatorClient({
31
+ apiKey: process.env.VIDNAVIGATOR_API_KEY!,
32
+ });
33
+ ```
34
+
35
+ Now you can easily call any of the API methods.
36
+
37
+ ### Example: Get a Video Transcript
38
+
39
+ ```ts
40
+ import { VidNavigatorClient, VideoInfo } from 'vidnavigator';
41
+
42
+ const vn = new VidNavigatorClient({ apiKey: 'YOUR_API_KEY' });
43
+
44
+ async function getTranscript() {
45
+ try {
46
+ const { video_info, transcript } = await vn.getTranscript({
47
+ video_url: 'https://youtube.com/watch?v=dQw4w9WgXcQ',
48
+ });
49
+
50
+ console.log(`Title: ${video_info.title}`);
51
+ console.log(`Is this a VideoInfo object?`, video_info instanceof VideoInfo);
52
+ console.log('First 3 transcript segments:');
53
+ transcript.slice(0, 3).forEach(segment => {
54
+ console.log(` [${segment.start.toFixed(2)}s]: ${segment.text}`);
55
+ });
56
+ } catch (error) {
57
+ console.error('Failed to get transcript:', error);
58
+ }
59
+ }
60
+
61
+ getTranscript();
62
+ ```
63
+
64
+ ### Example: Upload and Analyze a File
65
+
66
+ ```ts
67
+ import { VidNavigatorClient } from 'vidnavigator';
68
+
69
+ const vn = new VidNavigatorClient({ apiKey: 'YOUR_API_KEY' });
70
+
71
+ async function uploadAndAnalyze(filePath: string) {
72
+ try {
73
+ // Upload the file and wait for processing to complete
74
+ const { file_info } = await vn.uploadFile({
75
+ filePath,
76
+ wait_for_completion: true
77
+ });
78
+ console.log(`File '${file_info.name}' uploaded successfully.`);
79
+
80
+ // Analyze the uploaded file
81
+ const { transcript_analysis } = await vn.analyzeFile({
82
+ file_id: file_info.id
83
+ });
84
+ console.log('--- Analysis Summary ---');
85
+ console.log(transcript_analysis.summary);
86
+
87
+ } catch (error) {
88
+ console.error('Operation failed:', error);
89
+ }
90
+ }
91
+
92
+ uploadAndAnalyze('./my-meeting.mp4');
93
+ ```
94
+
95
+ ## API Reference
96
+
97
+ All methods return a `Promise` that resolves with an object containing rich data models.
98
+
99
+ ### Transcripts
100
+ - `vn.getTranscript(payload)`
101
+
102
+ ### Files
103
+ - `vn.getFiles([query])`
104
+ - `vn.getFile(file_id)`
105
+ - `vn.uploadFile(options)`
106
+ - `vn.deleteFile(file_id)`
107
+
108
+ ### Analysis
109
+ - `vn.analyzeVideo(payload)`
110
+ - `vn.analyzeFile(payload)`
111
+
112
+ ### Search
113
+ - `vn.searchVideos(payload)`
114
+ - `vn.searchFiles(payload)`
115
+
116
+ ### System
117
+ - `vn.getUsage()`
118
+ - `vn.healthCheck()`
119
+
120
+ Please refer to the inline documentation in your IDE for detailed information on the payloads and return types for each method.
121
+
122
+
123
+ ## More Examples & Documentation
124
+
125
+ For a comprehensive set of usage examples covering more SDK features, please see the [`test.py`](https://github.com/vidnavigator/vidnavigator-js/blob/main/test.js)
126
+
127
+ For full API documentation, visit [docs.vidnavigator.com](https://docs.vidnavigator.com).
128
+
129
+
130
+ ## License
131
+
132
+ [Apache-2.0](./LICENSE)
@@ -0,0 +1,82 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { VideoInfo, TranscriptSegment, FileInfo, AnalysisResult, VideoSearchResult, FileSearchResult } from './models';
3
+ export * from './models';
4
+ export interface SDKConfig {
5
+ apiKey: string;
6
+ baseURL?: string;
7
+ axiosConfig?: AxiosRequestConfig;
8
+ }
9
+ export declare class VidNavigatorClient {
10
+ private client;
11
+ constructor(config: SDKConfig);
12
+ private request;
13
+ getTranscript(payload: {
14
+ video_url: string;
15
+ language?: string;
16
+ }): Promise<{
17
+ video_info: VideoInfo;
18
+ transcript: TranscriptSegment[];
19
+ }>;
20
+ getFiles(query?: {
21
+ limit?: number;
22
+ offset?: number;
23
+ status?: 'processing' | 'completed' | 'failed' | 'cancelled';
24
+ }): Promise<{
25
+ files: FileInfo[];
26
+ total_count: number;
27
+ has_more: boolean;
28
+ }>;
29
+ getFile(file_id: string): Promise<{
30
+ file_info: FileInfo;
31
+ transcript?: TranscriptSegment[];
32
+ }>;
33
+ uploadFile(options: {
34
+ filePath: string;
35
+ wait_for_completion?: boolean;
36
+ }): Promise<{
37
+ file_id: string;
38
+ file_info: FileInfo;
39
+ transcript?: TranscriptSegment[];
40
+ }>;
41
+ deleteFile(file_id: string): Promise<{
42
+ file_id: string;
43
+ message: string;
44
+ }>;
45
+ analyzeVideo(payload: {
46
+ video_url: string;
47
+ query?: string;
48
+ }): Promise<{
49
+ video_info: VideoInfo;
50
+ transcript: TranscriptSegment[];
51
+ transcript_analysis: AnalysisResult;
52
+ }>;
53
+ analyzeFile(payload: {
54
+ file_id: string;
55
+ query?: string;
56
+ }): Promise<{
57
+ file_info: FileInfo;
58
+ transcript: TranscriptSegment[];
59
+ transcript_analysis: AnalysisResult;
60
+ }>;
61
+ searchVideos(payload: {
62
+ query: string;
63
+ use_enhanced_search?: boolean;
64
+ start_year?: number;
65
+ end_year?: number;
66
+ focus?: 'relevance' | 'popularity' | 'brevity';
67
+ duration?: number;
68
+ }): Promise<{
69
+ results: VideoSearchResult[];
70
+ total_found: number;
71
+ explanation?: string;
72
+ }>;
73
+ searchFiles(payload: {
74
+ query: string;
75
+ }): Promise<{
76
+ results: FileSearchResult[];
77
+ total_found: number;
78
+ explanation?: string;
79
+ }>;
80
+ getUsage(): Promise<any>;
81
+ healthCheck(): Promise<any>;
82
+ }
package/dist/index.js ADDED
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.VidNavigatorClient = void 0;
21
+ const axios_1 = __importDefault(require("axios"));
22
+ const form_data_1 = __importDefault(require("form-data"));
23
+ const fs_1 = __importDefault(require("fs"));
24
+ const models_1 = require("./models");
25
+ __exportStar(require("./models"), exports);
26
+ //endregion
27
+ class VidNavigatorClient {
28
+ constructor(config) {
29
+ if (!config?.apiKey) {
30
+ throw new Error('An API key is required to use the VidNavigator SDK.');
31
+ }
32
+ this.client = axios_1.default.create({
33
+ baseURL: config.baseURL ?? 'https://api.vidnavigator.com/v1',
34
+ headers: {
35
+ 'X-API-Key': config.apiKey,
36
+ 'User-Agent': `vidnavigator-js/0.1.0`,
37
+ },
38
+ ...config.axiosConfig,
39
+ });
40
+ }
41
+ async request(method, url, data, params, extraHeaders) {
42
+ const response = await this.client.request({
43
+ method,
44
+ url,
45
+ data,
46
+ params,
47
+ headers: extraHeaders,
48
+ });
49
+ return response.data;
50
+ }
51
+ //region --- Transcripts ---
52
+ async getTranscript(payload) {
53
+ const response = await this.request('POST', '/transcript', payload);
54
+ return {
55
+ video_info: models_1.VideoInfo.fromJSON(response.data.video_info),
56
+ transcript: response.data.transcript.map(models_1.TranscriptSegment.fromJSON),
57
+ };
58
+ }
59
+ //endregion
60
+ //region --- Files ---
61
+ async getFiles(query) {
62
+ const response = await this.request('GET', '/files', undefined, query);
63
+ return {
64
+ files: response.data.files.map(models_1.FileInfo.fromJSON),
65
+ total_count: response.data.total_count,
66
+ has_more: response.data.has_more,
67
+ };
68
+ }
69
+ async getFile(file_id) {
70
+ const response = await this.request('GET', `/file/${file_id}`);
71
+ return {
72
+ file_info: models_1.FileInfo.fromJSON(response.data.file_info),
73
+ transcript: response.data.transcript?.map(models_1.TranscriptSegment.fromJSON),
74
+ };
75
+ }
76
+ async uploadFile(options) {
77
+ const form = new form_data_1.default();
78
+ form.append('file', fs_1.default.createReadStream(options.filePath));
79
+ if (options.wait_for_completion) {
80
+ form.append('wait_for_completion', 'true');
81
+ }
82
+ const response = await this.request('POST', '/upload/file', form, undefined, form.getHeaders());
83
+ return {
84
+ file_id: response.data.file_id,
85
+ file_info: models_1.FileInfo.fromJSON(response.data.file_info),
86
+ transcript: response.data.transcript?.map(models_1.TranscriptSegment.fromJSON),
87
+ };
88
+ }
89
+ async deleteFile(file_id) {
90
+ const response = await this.request('DELETE', `/file/${file_id}/delete`);
91
+ return response.data;
92
+ }
93
+ //endregion
94
+ //region --- Analysis ---
95
+ async analyzeVideo(payload) {
96
+ const response = await this.request('POST', '/analyze/video', payload);
97
+ return {
98
+ video_info: models_1.VideoInfo.fromJSON(response.data.video_info),
99
+ transcript: response.data.transcript.map(models_1.TranscriptSegment.fromJSON),
100
+ transcript_analysis: models_1.AnalysisResult.fromJSON(response.data.transcript_analysis),
101
+ };
102
+ }
103
+ async analyzeFile(payload) {
104
+ const response = await this.request('POST', '/analyze/file', payload);
105
+ return {
106
+ file_info: models_1.FileInfo.fromJSON(response.data.file_info),
107
+ transcript: response.data.transcript.map(models_1.TranscriptSegment.fromJSON),
108
+ transcript_analysis: models_1.AnalysisResult.fromJSON(response.data.transcript_analysis),
109
+ };
110
+ }
111
+ //endregion
112
+ //region --- Search ---
113
+ async searchVideos(payload) {
114
+ const response = await this.request('POST', '/search/video', payload);
115
+ return {
116
+ results: response.data.results.map(models_1.VideoSearchResult.fromJSON),
117
+ total_found: response.data.total_found,
118
+ explanation: response.data.explanation
119
+ };
120
+ }
121
+ async searchFiles(payload) {
122
+ const response = await this.request('POST', '/search/file', payload);
123
+ return {
124
+ results: response.data.results.map(models_1.FileSearchResult.fromJSON),
125
+ total_found: response.data.total_found,
126
+ explanation: response.data.explanation
127
+ };
128
+ }
129
+ //endregion
130
+ //region --- System ---
131
+ async getUsage() {
132
+ const response = await this.request('GET', '/usage');
133
+ return response.data;
134
+ }
135
+ async healthCheck() {
136
+ const response = await this.client.get('/health');
137
+ return response.data;
138
+ }
139
+ }
140
+ exports.VidNavigatorClient = VidNavigatorClient;
@@ -0,0 +1,38 @@
1
+ export interface NamedEntity {
2
+ name?: string;
3
+ context?: string;
4
+ }
5
+ export interface KeySubject {
6
+ name?: string;
7
+ description?: string;
8
+ importance?: string;
9
+ }
10
+ export interface QueryAnswer {
11
+ answer?: string;
12
+ best_segment_index?: number;
13
+ relevant_segments?: string[];
14
+ }
15
+ export interface AnalysisResultJSON {
16
+ summary?: string;
17
+ people?: NamedEntity[];
18
+ places?: NamedEntity[];
19
+ key_subjects?: KeySubject[];
20
+ timestamp?: number;
21
+ relevant_text?: string;
22
+ query_answer?: QueryAnswer;
23
+ }
24
+ /**
25
+ * Represents the result of an AI analysis on a video or file.
26
+ */
27
+ export declare class AnalysisResult {
28
+ summary?: string;
29
+ people?: NamedEntity[];
30
+ places?: NamedEntity[];
31
+ key_subjects?: KeySubject[];
32
+ timestamp?: number;
33
+ relevant_text?: string;
34
+ query_answer?: QueryAnswer;
35
+ constructor(data: Partial<AnalysisResultJSON>);
36
+ static fromJSON(json: AnalysisResultJSON): AnalysisResult;
37
+ toJSON(): AnalysisResultJSON;
38
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnalysisResult = void 0;
4
+ /**
5
+ * Represents the result of an AI analysis on a video or file.
6
+ */
7
+ class AnalysisResult {
8
+ constructor(data) {
9
+ Object.assign(this, data);
10
+ }
11
+ static fromJSON(json) {
12
+ return new AnalysisResult(json);
13
+ }
14
+ toJSON() {
15
+ return { ...this };
16
+ }
17
+ }
18
+ exports.AnalysisResult = AnalysisResult;
@@ -0,0 +1,33 @@
1
+ export type FileStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled';
2
+ export interface FileInfoJSON {
3
+ id: string;
4
+ name: string;
5
+ size?: number;
6
+ type?: string;
7
+ duration?: number;
8
+ status: FileStatus;
9
+ created_at: string;
10
+ updated_at: string;
11
+ original_file_date?: string;
12
+ has_transcript?: boolean;
13
+ error_message?: string;
14
+ }
15
+ /**
16
+ * Represents the complete metadata for a file uploaded to VidNavigator.
17
+ */
18
+ export declare class FileInfo {
19
+ id: string;
20
+ name: string;
21
+ size?: number;
22
+ type?: string;
23
+ duration?: number;
24
+ status: FileStatus;
25
+ created_at: string;
26
+ updated_at: string;
27
+ original_file_date?: string;
28
+ has_transcript?: boolean;
29
+ error_message?: string;
30
+ constructor(data: FileInfoJSON);
31
+ static fromJSON(json: FileInfoJSON): FileInfo;
32
+ toJSON(): FileInfoJSON;
33
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileInfo = void 0;
4
+ /**
5
+ * Represents the complete metadata for a file uploaded to VidNavigator.
6
+ */
7
+ class FileInfo {
8
+ constructor(data) {
9
+ this.id = data.id;
10
+ this.name = data.name;
11
+ this.size = data.size;
12
+ this.type = data.type;
13
+ this.duration = data.duration;
14
+ this.status = data.status;
15
+ this.created_at = data.created_at;
16
+ this.updated_at = data.updated_at;
17
+ this.original_file_date = data.original_file_date;
18
+ this.has_transcript = data.has_transcript;
19
+ this.error_message = data.error_message;
20
+ }
21
+ static fromJSON(json) {
22
+ return new FileInfo(json);
23
+ }
24
+ toJSON() {
25
+ return { ...this };
26
+ }
27
+ }
28
+ exports.FileInfo = FileInfo;
@@ -0,0 +1,30 @@
1
+ import { FileInfo, FileInfoJSON } from './FileInfo';
2
+ import { VideoInfo, VideoInfoJSON } from './VideoInfo';
3
+ export interface BaseSearchResult {
4
+ relevance_score?: number;
5
+ transcript_summary?: string;
6
+ }
7
+ export interface VideoSearchResultJSON extends VideoInfoJSON, BaseSearchResult {
8
+ }
9
+ export interface FileSearchResultJSON extends FileInfoJSON, BaseSearchResult {
10
+ file_url?: string;
11
+ }
12
+ /**
13
+ * Represents a single video result from a search query.
14
+ */
15
+ export declare class VideoSearchResult extends VideoInfo implements BaseSearchResult {
16
+ relevance_score?: number;
17
+ transcript_summary?: string;
18
+ constructor(data: Partial<VideoSearchResultJSON>);
19
+ static fromJSON(json: VideoSearchResultJSON): VideoSearchResult;
20
+ }
21
+ /**
22
+ * Represents a single file result from a search query.
23
+ */
24
+ export declare class FileSearchResult extends FileInfo implements BaseSearchResult {
25
+ relevance_score?: number;
26
+ transcript_summary?: string;
27
+ file_url?: string;
28
+ constructor(data: FileSearchResultJSON);
29
+ static fromJSON(json: FileSearchResultJSON): FileSearchResult;
30
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileSearchResult = exports.VideoSearchResult = void 0;
4
+ const FileInfo_1 = require("./FileInfo");
5
+ const VideoInfo_1 = require("./VideoInfo");
6
+ /**
7
+ * Represents a single video result from a search query.
8
+ */
9
+ class VideoSearchResult extends VideoInfo_1.VideoInfo {
10
+ constructor(data) {
11
+ super(data);
12
+ this.relevance_score = data.relevance_score;
13
+ this.transcript_summary = data.transcript_summary;
14
+ }
15
+ static fromJSON(json) {
16
+ return new VideoSearchResult(json);
17
+ }
18
+ }
19
+ exports.VideoSearchResult = VideoSearchResult;
20
+ /**
21
+ * Represents a single file result from a search query.
22
+ */
23
+ class FileSearchResult extends FileInfo_1.FileInfo {
24
+ constructor(data) {
25
+ super(data);
26
+ this.relevance_score = data.relevance_score;
27
+ this.transcript_summary = data.transcript_summary;
28
+ this.file_url = data.file_url;
29
+ }
30
+ static fromJSON(json) {
31
+ return new FileSearchResult(json);
32
+ }
33
+ }
34
+ exports.FileSearchResult = FileSearchResult;
@@ -0,0 +1,25 @@
1
+ export interface TranscriptSegmentJSON {
2
+ text: string;
3
+ start: number;
4
+ end: number;
5
+ }
6
+ /**
7
+ * Represents a single segment of a video or audio transcript.
8
+ */
9
+ export declare class TranscriptSegment {
10
+ /** The text content of the transcript segment. */
11
+ text: string;
12
+ /** The start time of the segment in seconds. */
13
+ start: number;
14
+ /** The end time of the segment in seconds. */
15
+ end: number;
16
+ constructor(data: TranscriptSegmentJSON);
17
+ /**
18
+ * Creates a TranscriptSegment instance from a JSON object.
19
+ */
20
+ static fromJSON(json: TranscriptSegmentJSON): TranscriptSegment;
21
+ /**
22
+ * Converts the instance to its JSON representation.
23
+ */
24
+ toJSON(): TranscriptSegmentJSON;
25
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TranscriptSegment = void 0;
4
+ /**
5
+ * Represents a single segment of a video or audio transcript.
6
+ */
7
+ class TranscriptSegment {
8
+ constructor(data) {
9
+ this.text = data.text;
10
+ this.start = data.start;
11
+ this.end = data.end;
12
+ }
13
+ /**
14
+ * Creates a TranscriptSegment instance from a JSON object.
15
+ */
16
+ static fromJSON(json) {
17
+ return new TranscriptSegment(json);
18
+ }
19
+ /**
20
+ * Converts the instance to its JSON representation.
21
+ */
22
+ toJSON() {
23
+ return { ...this };
24
+ }
25
+ }
26
+ exports.TranscriptSegment = TranscriptSegment;
@@ -0,0 +1,46 @@
1
+ export interface VideoInfoJSON {
2
+ title?: string;
3
+ description?: string;
4
+ thumbnail?: string;
5
+ url?: string;
6
+ channel?: string;
7
+ channel_url?: string;
8
+ duration?: number;
9
+ views?: number;
10
+ likes?: number;
11
+ published_date?: string;
12
+ keywords?: string[];
13
+ category?: string;
14
+ available_languages?: string[];
15
+ selected_language?: string;
16
+ }
17
+ /**
18
+ * Represents detailed information about a video, typically from an online source like YouTube.
19
+ */
20
+ export declare class VideoInfo {
21
+ title?: string;
22
+ description?: string;
23
+ thumbnail?: string;
24
+ url?: string;
25
+ channel?: string;
26
+ channel_url?: string;
27
+ duration?: number;
28
+ views?: number;
29
+ likes?: number;
30
+ published_date?: string;
31
+ keywords?: string[];
32
+ category?: string;
33
+ available_languages?: string[];
34
+ selected_language?: string;
35
+ constructor(data: Partial<VideoInfoJSON>);
36
+ /**
37
+ * Creates a VideoInfo instance from a JSON object.
38
+ * @param json - The raw JSON object from the API.
39
+ * @returns A new VideoInfo instance.
40
+ */
41
+ static fromJSON(json: VideoInfoJSON): VideoInfo;
42
+ /**
43
+ * Converts the VideoInfo instance to its JSON representation.
44
+ */
45
+ toJSON(): VideoInfoJSON;
46
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VideoInfo = void 0;
4
+ /**
5
+ * Represents detailed information about a video, typically from an online source like YouTube.
6
+ */
7
+ class VideoInfo {
8
+ constructor(data) {
9
+ Object.assign(this, data);
10
+ }
11
+ /**
12
+ * Creates a VideoInfo instance from a JSON object.
13
+ * @param json - The raw JSON object from the API.
14
+ * @returns A new VideoInfo instance.
15
+ */
16
+ static fromJSON(json) {
17
+ return new VideoInfo(json);
18
+ }
19
+ /**
20
+ * Converts the VideoInfo instance to its JSON representation.
21
+ */
22
+ toJSON() {
23
+ return { ...this };
24
+ }
25
+ }
26
+ exports.VideoInfo = VideoInfo;
@@ -0,0 +1,5 @@
1
+ export * from './VideoInfo';
2
+ export * from './TranscriptSegment';
3
+ export * from './FileInfo';
4
+ export * from './AnalysisResult';
5
+ export * from './SearchResult';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./VideoInfo"), exports);
18
+ __exportStar(require("./TranscriptSegment"), exports);
19
+ __exportStar(require("./FileInfo"), exports);
20
+ __exportStar(require("./AnalysisResult"), exports);
21
+ __exportStar(require("./SearchResult"), exports);
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "vidnavigator",
3
+ "version": "0.1.0",
4
+ "description": "Official JavaScript SDK for the VidNavigator Developer API",
5
+ "author": "VidNavigator",
6
+ "license": "Apache-2.0",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "files": [
10
+ "dist",
11
+ "src"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsc",
15
+ "prepublishOnly": "npm run build"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/vidnavigator/vidnavigator-js.git"
20
+ },
21
+ "keywords": [
22
+ "vidnavigator",
23
+ "sdk",
24
+ "api",
25
+ "video",
26
+ "transcription",
27
+ "analysis"
28
+ ],
29
+ "dependencies": {
30
+ "axios": "^1.6.0",
31
+ "form-data": "^4.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^20.4.2",
35
+ "typescript": "^5.1.3",
36
+ "@types/form-data": "^2.5.0"
37
+ }
38
+ }
package/src/index.ts ADDED
@@ -0,0 +1,230 @@
1
+ import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
2
+ import FormData from 'form-data';
3
+ import fs from 'fs';
4
+ import {
5
+ VideoInfo,
6
+ VideoInfoJSON,
7
+ TranscriptSegment,
8
+ TranscriptSegmentJSON,
9
+ FileInfo,
10
+ FileInfoJSON,
11
+ AnalysisResult,
12
+ AnalysisResultJSON,
13
+ VideoSearchResult,
14
+ VideoSearchResultJSON,
15
+ FileSearchResult,
16
+ FileSearchResultJSON,
17
+ } from './models';
18
+
19
+ export * from './models';
20
+
21
+ //region --- Interfaces ---
22
+ export interface SDKConfig {
23
+ apiKey: string;
24
+ baseURL?: string;
25
+ axiosConfig?: AxiosRequestConfig;
26
+ }
27
+
28
+ interface ApiSuccessResponse<T> {
29
+ status: 'success';
30
+ data: T;
31
+ }
32
+ //endregion
33
+
34
+ export class VidNavigatorClient {
35
+ private client: AxiosInstance;
36
+
37
+ constructor(config: SDKConfig) {
38
+ if (!config?.apiKey) {
39
+ throw new Error('An API key is required to use the VidNavigator SDK.');
40
+ }
41
+
42
+ this.client = axios.create({
43
+ baseURL: config.baseURL ?? 'https://api.vidnavigator.com/v1',
44
+ headers: {
45
+ 'X-API-Key': config.apiKey,
46
+ 'User-Agent': `vidnavigator-js/0.1.0`,
47
+ },
48
+ ...config.axiosConfig,
49
+ });
50
+ }
51
+
52
+ private async request<T>(method: 'GET' | 'POST' | 'DELETE' | 'PUT', url: string, data?: any, params?: any, extraHeaders?: any): Promise<T> {
53
+ const response = await this.client.request<T>({
54
+ method,
55
+ url,
56
+ data,
57
+ params,
58
+ headers: extraHeaders,
59
+ });
60
+ return response.data;
61
+ }
62
+
63
+ //region --- Transcripts ---
64
+ async getTranscript(payload: { video_url: string; language?: string }): Promise<{
65
+ video_info: VideoInfo;
66
+ transcript: TranscriptSegment[];
67
+ }> {
68
+ const response = await this.request<ApiSuccessResponse<{
69
+ video_info: VideoInfoJSON;
70
+ transcript: TranscriptSegmentJSON[];
71
+ }>>('POST', '/transcript', payload);
72
+
73
+ return {
74
+ video_info: VideoInfo.fromJSON(response.data.video_info),
75
+ transcript: response.data.transcript.map(TranscriptSegment.fromJSON),
76
+ };
77
+ }
78
+ //endregion
79
+
80
+ //region --- Files ---
81
+ async getFiles(query?: { limit?: number; offset?: number; status?: 'processing'|'completed'|'failed'|'cancelled' }): Promise<{
82
+ files: FileInfo[];
83
+ total_count: number;
84
+ has_more: boolean;
85
+ }> {
86
+ const response = await this.request<ApiSuccessResponse<{
87
+ files: FileInfoJSON[];
88
+ total_count: number;
89
+ has_more: boolean;
90
+ }>>('GET', '/files', undefined, query);
91
+
92
+ return {
93
+ files: response.data.files.map(FileInfo.fromJSON),
94
+ total_count: response.data.total_count,
95
+ has_more: response.data.has_more,
96
+ };
97
+ }
98
+
99
+ async getFile(file_id: string): Promise<{ file_info: FileInfo; transcript?: TranscriptSegment[] }> {
100
+ const response = await this.request<ApiSuccessResponse<{
101
+ file_info: FileInfoJSON;
102
+ transcript?: TranscriptSegmentJSON[];
103
+ }>>('GET', `/file/${file_id}`);
104
+
105
+ return {
106
+ file_info: FileInfo.fromJSON(response.data.file_info),
107
+ transcript: response.data.transcript?.map(TranscriptSegment.fromJSON),
108
+ };
109
+ }
110
+
111
+ async uploadFile(options: { filePath: string; wait_for_completion?: boolean }): Promise<{
112
+ file_id: string;
113
+ file_info: FileInfo;
114
+ transcript?: TranscriptSegment[];
115
+ }> {
116
+ const form = new FormData();
117
+ form.append('file', fs.createReadStream(options.filePath));
118
+ if (options.wait_for_completion) {
119
+ form.append('wait_for_completion', 'true');
120
+ }
121
+
122
+ const response = await this.request<ApiSuccessResponse<{
123
+ file_id: string;
124
+ file_info: FileInfoJSON;
125
+ transcript?: TranscriptSegmentJSON[];
126
+ }>>('POST', '/upload/file', form, undefined, form.getHeaders());
127
+
128
+ return {
129
+ file_id: response.data.file_id,
130
+ file_info: FileInfo.fromJSON(response.data.file_info),
131
+ transcript: response.data.transcript?.map(TranscriptSegment.fromJSON),
132
+ };
133
+ }
134
+
135
+ async deleteFile(file_id: string): Promise<{ file_id: string; message: string }> {
136
+ const response = await this.request<ApiSuccessResponse<{ file_id: string; message: string }>>(
137
+ 'DELETE',
138
+ `/file/${file_id}/delete`
139
+ );
140
+ return response.data;
141
+ }
142
+ //endregion
143
+
144
+ //region --- Analysis ---
145
+ async analyzeVideo(payload: { video_url: string; query?: string }): Promise<{
146
+ video_info: VideoInfo;
147
+ transcript: TranscriptSegment[];
148
+ transcript_analysis: AnalysisResult;
149
+ }> {
150
+ const response = await this.request<ApiSuccessResponse<{
151
+ video_info: VideoInfoJSON;
152
+ transcript: TranscriptSegmentJSON[];
153
+ transcript_analysis: AnalysisResultJSON;
154
+ }>>('POST', '/analyze/video', payload);
155
+
156
+ return {
157
+ video_info: VideoInfo.fromJSON(response.data.video_info),
158
+ transcript: response.data.transcript.map(TranscriptSegment.fromJSON),
159
+ transcript_analysis: AnalysisResult.fromJSON(response.data.transcript_analysis),
160
+ };
161
+ }
162
+
163
+ async analyzeFile(payload: { file_id: string; query?: string }): Promise<{
164
+ file_info: FileInfo;
165
+ transcript: TranscriptSegment[];
166
+ transcript_analysis: AnalysisResult;
167
+ }> {
168
+ const response = await this.request<ApiSuccessResponse<{
169
+ file_info: FileInfoJSON;
170
+ transcript: TranscriptSegmentJSON[];
171
+ transcript_analysis: AnalysisResultJSON;
172
+ }>>('POST', '/analyze/file', payload);
173
+
174
+ return {
175
+ file_info: FileInfo.fromJSON(response.data.file_info),
176
+ transcript: response.data.transcript.map(TranscriptSegment.fromJSON),
177
+ transcript_analysis: AnalysisResult.fromJSON(response.data.transcript_analysis),
178
+ };
179
+ }
180
+ //endregion
181
+
182
+ //region --- Search ---
183
+ async searchVideos(payload: {
184
+ query: string;
185
+ use_enhanced_search?: boolean;
186
+ start_year?: number;
187
+ end_year?: number;
188
+ focus?: 'relevance'|'popularity'|'brevity';
189
+ duration?: number;
190
+ }): Promise<{ results: VideoSearchResult[]; total_found: number; explanation?: string }> {
191
+ const response = await this.request<ApiSuccessResponse<{
192
+ results: VideoSearchResultJSON[];
193
+ total_found: number;
194
+ explanation?: string;
195
+ }>>('POST', '/search/video', payload);
196
+
197
+ return {
198
+ results: response.data.results.map(VideoSearchResult.fromJSON),
199
+ total_found: response.data.total_found,
200
+ explanation: response.data.explanation
201
+ };
202
+ }
203
+
204
+ async searchFiles(payload: { query: string }): Promise<{ results: FileSearchResult[]; total_found: number; explanation?: string }> {
205
+ const response = await this.request<ApiSuccessResponse<{
206
+ results: FileSearchResultJSON[];
207
+ total_found: number;
208
+ explanation?: string;
209
+ }>>('POST', '/search/file', payload);
210
+
211
+ return {
212
+ results: response.data.results.map(FileSearchResult.fromJSON),
213
+ total_found: response.data.total_found,
214
+ explanation: response.data.explanation
215
+ };
216
+ }
217
+ //endregion
218
+
219
+ //region --- System ---
220
+ async getUsage(): Promise<any> {
221
+ const response = await this.request<ApiSuccessResponse<any>>('GET', '/usage');
222
+ return response.data;
223
+ }
224
+
225
+ async healthCheck(): Promise<any> {
226
+ const response = await this.client.get('/health');
227
+ return response.data;
228
+ }
229
+ //endregion
230
+ }
@@ -0,0 +1,51 @@
1
+ export interface NamedEntity {
2
+ name?: string;
3
+ context?: string;
4
+ }
5
+
6
+ export interface KeySubject {
7
+ name?: string;
8
+ description?: string;
9
+ importance?: string;
10
+ }
11
+
12
+ export interface QueryAnswer {
13
+ answer?: string;
14
+ best_segment_index?: number;
15
+ relevant_segments?: string[];
16
+ }
17
+
18
+ export interface AnalysisResultJSON {
19
+ summary?: string;
20
+ people?: NamedEntity[];
21
+ places?: NamedEntity[];
22
+ key_subjects?: KeySubject[];
23
+ timestamp?: number;
24
+ relevant_text?: string;
25
+ query_answer?: QueryAnswer;
26
+ }
27
+
28
+ /**
29
+ * Represents the result of an AI analysis on a video or file.
30
+ */
31
+ export class AnalysisResult {
32
+ summary?: string;
33
+ people?: NamedEntity[];
34
+ places?: NamedEntity[];
35
+ key_subjects?: KeySubject[];
36
+ timestamp?: number;
37
+ relevant_text?: string;
38
+ query_answer?: QueryAnswer;
39
+
40
+ constructor(data: Partial<AnalysisResultJSON>) {
41
+ Object.assign(this, data);
42
+ }
43
+
44
+ static fromJSON(json: AnalysisResultJSON): AnalysisResult {
45
+ return new AnalysisResult(json);
46
+ }
47
+
48
+ toJSON(): AnalysisResultJSON {
49
+ return { ...this };
50
+ }
51
+ }
@@ -0,0 +1,54 @@
1
+ export type FileStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled';
2
+
3
+ export interface FileInfoJSON {
4
+ id: string;
5
+ name: string;
6
+ size?: number;
7
+ type?: string;
8
+ duration?: number;
9
+ status: FileStatus;
10
+ created_at: string;
11
+ updated_at: string;
12
+ original_file_date?: string;
13
+ has_transcript?: boolean;
14
+ error_message?: string;
15
+ }
16
+
17
+ /**
18
+ * Represents the complete metadata for a file uploaded to VidNavigator.
19
+ */
20
+ export class FileInfo {
21
+ id: string;
22
+ name: string;
23
+ size?: number;
24
+ type?: string;
25
+ duration?: number;
26
+ status: FileStatus;
27
+ created_at: string;
28
+ updated_at: string;
29
+ original_file_date?: string;
30
+ has_transcript?: boolean;
31
+ error_message?: string;
32
+
33
+ constructor(data: FileInfoJSON) {
34
+ this.id = data.id;
35
+ this.name = data.name;
36
+ this.size = data.size;
37
+ this.type = data.type;
38
+ this.duration = data.duration;
39
+ this.status = data.status;
40
+ this.created_at = data.created_at;
41
+ this.updated_at = data.updated_at;
42
+ this.original_file_date = data.original_file_date;
43
+ this.has_transcript = data.has_transcript;
44
+ this.error_message = data.error_message;
45
+ }
46
+
47
+ static fromJSON(json: FileInfoJSON): FileInfo {
48
+ return new FileInfo(json);
49
+ }
50
+
51
+ toJSON(): FileInfoJSON {
52
+ return { ...this };
53
+ }
54
+ }
@@ -0,0 +1,50 @@
1
+ import { FileInfo, FileInfoJSON } from './FileInfo';
2
+ import { VideoInfo, VideoInfoJSON } from './VideoInfo';
3
+
4
+ export interface BaseSearchResult {
5
+ relevance_score?: number;
6
+ transcript_summary?: string;
7
+ }
8
+
9
+ export interface VideoSearchResultJSON extends VideoInfoJSON, BaseSearchResult {}
10
+ export interface FileSearchResultJSON extends FileInfoJSON, BaseSearchResult {
11
+ file_url?: string;
12
+ }
13
+
14
+ /**
15
+ * Represents a single video result from a search query.
16
+ */
17
+ export class VideoSearchResult extends VideoInfo implements BaseSearchResult {
18
+ relevance_score?: number;
19
+ transcript_summary?: string;
20
+
21
+ constructor(data: Partial<VideoSearchResultJSON>) {
22
+ super(data);
23
+ this.relevance_score = data.relevance_score;
24
+ this.transcript_summary = data.transcript_summary;
25
+ }
26
+
27
+ static fromJSON(json: VideoSearchResultJSON): VideoSearchResult {
28
+ return new VideoSearchResult(json);
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Represents a single file result from a search query.
34
+ */
35
+ export class FileSearchResult extends FileInfo implements BaseSearchResult {
36
+ relevance_score?: number;
37
+ transcript_summary?: string;
38
+ file_url?: string;
39
+
40
+ constructor(data: FileSearchResultJSON) {
41
+ super(data);
42
+ this.relevance_score = data.relevance_score;
43
+ this.transcript_summary = data.transcript_summary;
44
+ this.file_url = data.file_url;
45
+ }
46
+
47
+ static fromJSON(json: FileSearchResultJSON): FileSearchResult {
48
+ return new FileSearchResult(json);
49
+ }
50
+ }
@@ -0,0 +1,37 @@
1
+ export interface TranscriptSegmentJSON {
2
+ text: string;
3
+ start: number;
4
+ end: number;
5
+ }
6
+
7
+ /**
8
+ * Represents a single segment of a video or audio transcript.
9
+ */
10
+ export class TranscriptSegment {
11
+ /** The text content of the transcript segment. */
12
+ text: string;
13
+ /** The start time of the segment in seconds. */
14
+ start: number;
15
+ /** The end time of the segment in seconds. */
16
+ end: number;
17
+
18
+ constructor(data: TranscriptSegmentJSON) {
19
+ this.text = data.text;
20
+ this.start = data.start;
21
+ this.end = data.end;
22
+ }
23
+
24
+ /**
25
+ * Creates a TranscriptSegment instance from a JSON object.
26
+ */
27
+ static fromJSON(json: TranscriptSegmentJSON): TranscriptSegment {
28
+ return new TranscriptSegment(json);
29
+ }
30
+
31
+ /**
32
+ * Converts the instance to its JSON representation.
33
+ */
34
+ toJSON(): TranscriptSegmentJSON {
35
+ return { ...this };
36
+ }
37
+ }
@@ -0,0 +1,56 @@
1
+ export interface VideoInfoJSON {
2
+ title?: string;
3
+ description?: string;
4
+ thumbnail?: string;
5
+ url?: string;
6
+ channel?: string;
7
+ channel_url?: string;
8
+ duration?: number;
9
+ views?: number;
10
+ likes?: number;
11
+ published_date?: string;
12
+ keywords?: string[];
13
+ category?: string;
14
+ available_languages?: string[];
15
+ selected_language?: string;
16
+ }
17
+
18
+ /**
19
+ * Represents detailed information about a video, typically from an online source like YouTube.
20
+ */
21
+ export class VideoInfo {
22
+ title?: string;
23
+ description?: string;
24
+ thumbnail?: string;
25
+ url?: string;
26
+ channel?: string;
27
+ channel_url?: string;
28
+ duration?: number;
29
+ views?: number;
30
+ likes?: number;
31
+ published_date?: string;
32
+ keywords?: string[];
33
+ category?: string;
34
+ available_languages?: string[];
35
+ selected_language?: string;
36
+
37
+ constructor(data: Partial<VideoInfoJSON>) {
38
+ Object.assign(this, data);
39
+ }
40
+
41
+ /**
42
+ * Creates a VideoInfo instance from a JSON object.
43
+ * @param json - The raw JSON object from the API.
44
+ * @returns A new VideoInfo instance.
45
+ */
46
+ static fromJSON(json: VideoInfoJSON): VideoInfo {
47
+ return new VideoInfo(json);
48
+ }
49
+
50
+ /**
51
+ * Converts the VideoInfo instance to its JSON representation.
52
+ */
53
+ toJSON(): VideoInfoJSON {
54
+ return { ...this };
55
+ }
56
+ }
@@ -0,0 +1,5 @@
1
+ export * from './VideoInfo';
2
+ export * from './TranscriptSegment';
3
+ export * from './FileInfo';
4
+ export * from './AnalysisResult';
5
+ export * from './SearchResult';