twelvelabs-js 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.
Files changed (194) hide show
  1. package/LICENSE +183 -0
  2. package/README.md +278 -0
  3. package/dist/README.md +278 -0
  4. package/dist/constants.d.ts +4 -0
  5. package/dist/constants.d.ts.map +1 -0
  6. package/dist/constants.js +7 -0
  7. package/dist/constants.js.map +1 -0
  8. package/dist/constants.mjs +4 -0
  9. package/dist/constants.mjs.map +1 -0
  10. package/dist/core.d.ts +23 -0
  11. package/dist/core.d.ts.map +1 -0
  12. package/dist/core.js +145 -0
  13. package/dist/core.js.map +1 -0
  14. package/dist/core.mjs +114 -0
  15. package/dist/core.mjs.map +1 -0
  16. package/dist/error.d.ts +34 -0
  17. package/dist/error.d.ts.map +1 -0
  18. package/dist/error.js +55 -0
  19. package/dist/error.js.map +1 -0
  20. package/dist/error.mjs +40 -0
  21. package/dist/error.mjs.map +1 -0
  22. package/dist/index.d.ts +20 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +69 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/index.mjs +23 -0
  27. package/dist/index.mjs.map +1 -0
  28. package/dist/interfaces.d.ts +7 -0
  29. package/dist/interfaces.d.ts.map +1 -0
  30. package/dist/interfaces.js +3 -0
  31. package/dist/interfaces.js.map +1 -0
  32. package/dist/interfaces.mjs +2 -0
  33. package/dist/interfaces.mjs.map +1 -0
  34. package/dist/models/engine/index.d.ts +16 -0
  35. package/dist/models/engine/index.d.ts.map +1 -0
  36. package/dist/models/engine/index.js +14 -0
  37. package/dist/models/engine/index.js.map +1 -0
  38. package/dist/models/engine/index.mjs +10 -0
  39. package/dist/models/engine/index.mjs.map +1 -0
  40. package/dist/models/generate/index.d.ts +29 -0
  41. package/dist/models/generate/index.d.ts.map +1 -0
  42. package/dist/models/generate/index.js +3 -0
  43. package/dist/models/generate/index.js.map +1 -0
  44. package/dist/models/generate/index.mjs +2 -0
  45. package/dist/models/generate/index.mjs.map +1 -0
  46. package/dist/models/index/index.d.ts +57 -0
  47. package/dist/models/index/index.d.ts.map +1 -0
  48. package/dist/models/index/index.js +72 -0
  49. package/dist/models/index/index.js.map +1 -0
  50. package/dist/models/index/index.mjs +67 -0
  51. package/dist/models/index/index.mjs.map +1 -0
  52. package/dist/models/index.d.ts +8 -0
  53. package/dist/models/index.d.ts.map +1 -0
  54. package/dist/models/index.js +24 -0
  55. package/dist/models/index.js.map +1 -0
  56. package/dist/models/index.mjs +8 -0
  57. package/dist/models/index.mjs.map +1 -0
  58. package/dist/models/interfaces.d.ts +7 -0
  59. package/dist/models/interfaces.d.ts.map +1 -0
  60. package/dist/models/interfaces.js +3 -0
  61. package/dist/models/interfaces.js.map +1 -0
  62. package/dist/models/interfaces.mjs +2 -0
  63. package/dist/models/interfaces.mjs.map +1 -0
  64. package/dist/models/search/index.d.ts +47 -0
  65. package/dist/models/search/index.d.ts.map +1 -0
  66. package/dist/models/search/index.js +22 -0
  67. package/dist/models/search/index.js.map +1 -0
  68. package/dist/models/search/index.mjs +18 -0
  69. package/dist/models/search/index.mjs.map +1 -0
  70. package/dist/models/task/index.d.ts +59 -0
  71. package/dist/models/task/index.d.ts.map +1 -0
  72. package/dist/models/task/index.js +67 -0
  73. package/dist/models/task/index.js.map +1 -0
  74. package/dist/models/task/index.mjs +62 -0
  75. package/dist/models/task/index.mjs.map +1 -0
  76. package/dist/models/video/index.d.ts +52 -0
  77. package/dist/models/video/index.d.ts.map +1 -0
  78. package/dist/models/video/index.js +64 -0
  79. package/dist/models/video/index.js.map +1 -0
  80. package/dist/models/video/index.mjs +59 -0
  81. package/dist/models/video/index.mjs.map +1 -0
  82. package/dist/package.json +37 -0
  83. package/dist/resource.d.ts +12 -0
  84. package/dist/resource.d.ts.map +1 -0
  85. package/dist/resource.js +17 -0
  86. package/dist/resource.js.map +1 -0
  87. package/dist/resource.mjs +13 -0
  88. package/dist/resource.mjs.map +1 -0
  89. package/dist/resources/engine/index.d.ts +8 -0
  90. package/dist/resources/engine/index.d.ts.map +1 -0
  91. package/dist/resources/engine/index.js +42 -0
  92. package/dist/resources/engine/index.js.map +1 -0
  93. package/dist/resources/engine/index.mjs +15 -0
  94. package/dist/resources/engine/index.mjs.map +1 -0
  95. package/dist/resources/generate/index.d.ts +10 -0
  96. package/dist/resources/generate/index.d.ts.map +1 -0
  97. package/dist/resources/generate/index.js +36 -0
  98. package/dist/resources/generate/index.js.map +1 -0
  99. package/dist/resources/generate/index.mjs +32 -0
  100. package/dist/resources/generate/index.mjs.map +1 -0
  101. package/dist/resources/generate/interfaces.d.ts +3 -0
  102. package/dist/resources/generate/interfaces.d.ts.map +1 -0
  103. package/dist/resources/generate/interfaces.js +3 -0
  104. package/dist/resources/generate/interfaces.js.map +1 -0
  105. package/dist/resources/generate/interfaces.mjs +2 -0
  106. package/dist/resources/generate/interfaces.mjs.map +1 -0
  107. package/dist/resources/index/index.d.ts +17 -0
  108. package/dist/resources/index/index.d.ts.map +1 -0
  109. package/dist/resources/index/index.js +82 -0
  110. package/dist/resources/index/index.js.map +1 -0
  111. package/dist/resources/index/index.mjs +55 -0
  112. package/dist/resources/index/index.mjs.map +1 -0
  113. package/dist/resources/index/interfaces.d.ts +18 -0
  114. package/dist/resources/index/interfaces.d.ts.map +1 -0
  115. package/dist/resources/index/interfaces.js +3 -0
  116. package/dist/resources/index/interfaces.js.map +1 -0
  117. package/dist/resources/index/interfaces.mjs +2 -0
  118. package/dist/resources/index/interfaces.mjs.map +1 -0
  119. package/dist/resources/index.d.ts +12 -0
  120. package/dist/resources/index.d.ts.map +1 -0
  121. package/dist/resources/index.js +28 -0
  122. package/dist/resources/index.js.map +1 -0
  123. package/dist/resources/index.mjs +12 -0
  124. package/dist/resources/index.mjs.map +1 -0
  125. package/dist/resources/search/index.d.ts +9 -0
  126. package/dist/resources/search/index.d.ts.map +1 -0
  127. package/dist/resources/search/index.js +45 -0
  128. package/dist/resources/search/index.js.map +1 -0
  129. package/dist/resources/search/index.mjs +18 -0
  130. package/dist/resources/search/index.mjs.map +1 -0
  131. package/dist/resources/search/interfaces.d.ts +13 -0
  132. package/dist/resources/search/interfaces.d.ts.map +1 -0
  133. package/dist/resources/search/interfaces.js +3 -0
  134. package/dist/resources/search/interfaces.js.map +1 -0
  135. package/dist/resources/search/interfaces.mjs +2 -0
  136. package/dist/resources/search/interfaces.mjs.map +1 -0
  137. package/dist/resources/task/index.d.ts +23 -0
  138. package/dist/resources/task/index.d.ts.map +1 -0
  139. package/dist/resources/task/index.js +147 -0
  140. package/dist/resources/task/index.js.map +1 -0
  141. package/dist/resources/task/index.mjs +117 -0
  142. package/dist/resources/task/index.mjs.map +1 -0
  143. package/dist/resources/task/interfaces.d.ts +24 -0
  144. package/dist/resources/task/interfaces.d.ts.map +1 -0
  145. package/dist/resources/task/interfaces.js +3 -0
  146. package/dist/resources/task/interfaces.js.map +1 -0
  147. package/dist/resources/task/interfaces.mjs +2 -0
  148. package/dist/resources/task/interfaces.mjs.map +1 -0
  149. package/dist/resources/video/index.d.ts +16 -0
  150. package/dist/resources/video/index.d.ts.map +1 -0
  151. package/dist/resources/video/index.js +92 -0
  152. package/dist/resources/video/index.js.map +1 -0
  153. package/dist/resources/video/index.mjs +65 -0
  154. package/dist/resources/video/index.mjs.map +1 -0
  155. package/dist/resources/video/interfaces.d.ts +23 -0
  156. package/dist/resources/video/interfaces.d.ts.map +1 -0
  157. package/dist/resources/video/interfaces.js +3 -0
  158. package/dist/resources/video/interfaces.js.map +1 -0
  159. package/dist/resources/video/interfaces.mjs +2 -0
  160. package/dist/resources/video/interfaces.mjs.map +1 -0
  161. package/dist/src/constants.ts +3 -0
  162. package/dist/src/core.ts +138 -0
  163. package/dist/src/error.ts +40 -0
  164. package/dist/src/index.ts +86 -0
  165. package/dist/src/interfaces.ts +6 -0
  166. package/dist/src/models/engine/index.ts +23 -0
  167. package/dist/src/models/generate/index.ts +32 -0
  168. package/dist/src/models/index/index.ts +135 -0
  169. package/dist/src/models/index.ts +7 -0
  170. package/dist/src/models/interfaces.ts +6 -0
  171. package/dist/src/models/search/index.ts +66 -0
  172. package/dist/src/models/task/index.ts +132 -0
  173. package/dist/src/models/video/index.ts +135 -0
  174. package/dist/src/resource.ts +21 -0
  175. package/dist/src/resources/engine/index.ts +17 -0
  176. package/dist/src/resources/generate/index.ts +56 -0
  177. package/dist/src/resources/generate/interfaces.ts +2 -0
  178. package/dist/src/resources/index/index.ts +91 -0
  179. package/dist/src/resources/index/interfaces.ts +16 -0
  180. package/dist/src/resources/index.ts +12 -0
  181. package/dist/src/resources/search/index.ts +28 -0
  182. package/dist/src/resources/search/interfaces.ts +12 -0
  183. package/dist/src/resources/task/index.ts +161 -0
  184. package/dist/src/resources/task/interfaces.ts +23 -0
  185. package/dist/src/resources/video/index.ts +157 -0
  186. package/dist/src/resources/video/interfaces.ts +25 -0
  187. package/dist/src/util.ts +94 -0
  188. package/dist/util.d.ts +5 -0
  189. package/dist/util.d.ts.map +1 -0
  190. package/dist/util.js +94 -0
  191. package/dist/util.js.map +1 -0
  192. package/dist/util.mjs +87 -0
  193. package/dist/util.mjs.map +1 -0
  194. package/package.json +37 -0
@@ -0,0 +1,135 @@
1
+ import { RequestOptions } from '../../core';
2
+ import * as Resources from '../../resources';
3
+ import { GenerateGistResult, GenerateOpenEndedTextResult } from '../generate';
4
+ import { PageInfo } from '../interfaces';
5
+
6
+ export interface VideoResponse {
7
+ id: string;
8
+ metadata: VideoMetadata;
9
+ createdAt: string;
10
+ updatedAt?: string;
11
+ }
12
+
13
+ export class Video {
14
+ private readonly _resource: Resources.Video;
15
+ private readonly _indexId: string;
16
+ id: string;
17
+ metadata: VideoMetadata & Record<string, any>;
18
+ createdAt: string;
19
+ updatedAt?: string;
20
+
21
+ constructor(resource: Resources.Video, indexId: string, data: VideoResponse) {
22
+ this._resource = resource;
23
+ this._indexId = indexId;
24
+ this.id = data.id;
25
+ this.metadata = data.metadata;
26
+ this.createdAt = data.createdAt;
27
+ this.updatedAt = data.updatedAt;
28
+ }
29
+
30
+ // Video related methods
31
+
32
+ async update(params: Resources.UpdateVideoParams, options: RequestOptions = {}): Promise<void> {
33
+ return await this._resource.update(this._indexId, this.id, params, options);
34
+ }
35
+
36
+ async delete(options: RequestOptions = {}): Promise<void> {
37
+ return await this._resource.delete(this._indexId, this.id, options);
38
+ }
39
+
40
+ async transcription(
41
+ filter?: Resources.VideoFilterOptions,
42
+ options: RequestOptions = {},
43
+ ): Promise<VideoValue[]> {
44
+ return await this._resource.transcription(this._indexId, this.id, filter, options);
45
+ }
46
+
47
+ async textInVideo(
48
+ filter: Resources.VideoFilterOptions = {},
49
+ options: RequestOptions = {},
50
+ ): Promise<VideoValue[]> {
51
+ return await this._resource.textInVideo(this._indexId, this.id, filter, options);
52
+ }
53
+
54
+ async logo(filter: Resources.VideoFilterOptions = {}, options: RequestOptions = {}): Promise<VideoValue[]> {
55
+ return await this._resource.logo(this._indexId, this.id, filter, options);
56
+ }
57
+
58
+ async thumbnail(time?: number, options: RequestOptions = {}): Promise<string> {
59
+ return await this._resource.thumbnail(this._indexId, this.id, time, options);
60
+ }
61
+
62
+ // Generate related methods
63
+
64
+ async generateGist(
65
+ types: Resources.GenerateGistType[],
66
+ options: RequestOptions = {},
67
+ ): Promise<GenerateGistResult> {
68
+ return await this._resource._client.generate.gist(this.id, types, options);
69
+ }
70
+
71
+ async generateSummarize(
72
+ type: Resources.GenerateSummarizeType,
73
+ prompt?: string,
74
+ temperature?: number,
75
+ options: RequestOptions = {},
76
+ ): Promise<GenerateGistResult> {
77
+ return await this._resource._client.generate.summarize(this.id, type, prompt, temperature, options);
78
+ }
79
+
80
+ async generateText(
81
+ prompt: string,
82
+ temperature?: number,
83
+ options: RequestOptions = {},
84
+ ): Promise<GenerateOpenEndedTextResult> {
85
+ return await this._resource._client.generate.text(this.id, prompt, temperature, options);
86
+ }
87
+ }
88
+
89
+ export class VideoListWithPagination {
90
+ private readonly _resource: Resources.Video;
91
+ private readonly _originParams: Resources.ListVideoParams;
92
+ private readonly _indexId: string;
93
+ data: Video[];
94
+ pageInfo: PageInfo;
95
+
96
+ constructor(
97
+ resource: Resources.Video,
98
+ originParams: Resources.ListVideoParams,
99
+ indexId: string,
100
+ data: VideoResponse[],
101
+ pageInfo: PageInfo,
102
+ ) {
103
+ this._resource = resource;
104
+ this._originParams = originParams;
105
+ this._indexId = indexId;
106
+ this.data = data.map((v) => new Video(resource, indexId, v));
107
+ this.pageInfo = pageInfo;
108
+ }
109
+
110
+ async next(): Promise<Video[] | null> {
111
+ if (this.pageInfo.page >= this.pageInfo.totalPage) {
112
+ return null;
113
+ }
114
+ const params = { ...this._originParams };
115
+ params.page = this.pageInfo.page + 1;
116
+ const res = await this._resource.listPagination(this._indexId, params);
117
+ this.pageInfo = res.pageInfo;
118
+ return res.data;
119
+ }
120
+ }
121
+
122
+ interface VideoMetadata {
123
+ filename: string;
124
+ duration: number;
125
+ fps: number;
126
+ width: number;
127
+ height: number;
128
+ size: number;
129
+ }
130
+
131
+ export interface VideoValue {
132
+ start: number;
133
+ end: number;
134
+ value: string;
135
+ }
@@ -0,0 +1,21 @@
1
+ import { TwelveLabs } from '.';
2
+ import { APIClient, RequestOptions } from './core';
3
+
4
+ export class APIResource extends APIClient {
5
+ readonly _client: TwelveLabs;
6
+ readonly _get: <T>(endpoint: string, params?: Record<string, any>, options?: RequestOptions) => Promise<T>;
7
+ readonly _post: <T>(endpoint: string, data?: any, options?: RequestOptions) => Promise<T>;
8
+ readonly _patch: <T>(endpoint: string, data?: any, options?: RequestOptions) => Promise<T>;
9
+ readonly _put: <T>(endpoint: string, data?: any, options?: RequestOptions) => Promise<T>;
10
+ readonly _delete: <T>(endpoint: string, options?: RequestOptions) => Promise<T>;
11
+
12
+ constructor(client: TwelveLabs) {
13
+ super(client);
14
+ this._client = client;
15
+ this._get = client._get;
16
+ this._post = client._post;
17
+ this._patch = client._patch;
18
+ this._put = client._put;
19
+ this._delete = client._delete;
20
+ }
21
+ }
@@ -0,0 +1,17 @@
1
+ import { RequestOptions } from '../../core';
2
+ import * as Models from '../../models';
3
+ import { APIResource } from '../../resource';
4
+
5
+ export class Engine extends APIResource {
6
+ async retrieve(id: string, options: RequestOptions = {}): Promise<Models.Engine> {
7
+ const endpoint = `engines/${id}`;
8
+ const res = await this._get<Models.EngineResponse>(endpoint, {}, options);
9
+ return new Models.Engine(res);
10
+ }
11
+
12
+ async list(options: RequestOptions = {}): Promise<Models.Engine[]> {
13
+ const endpoint = 'engines';
14
+ const res = await this._get<{ data: Models.EngineResponse[] }>(endpoint, {}, options);
15
+ return res.data.map((v) => new Models.Engine(v));
16
+ }
17
+ }
@@ -0,0 +1,56 @@
1
+ import { RequestOptions } from '../../core';
2
+ import * as Models from '../../models';
3
+ import { APIResource } from '../../resource';
4
+ import { convertKeysToSnakeCase, removeUndefinedValues } from '../../util';
5
+ import { GenerateGistType, GenerateSummarizeType } from './interfaces';
6
+
7
+ export class Generate extends APIResource {
8
+ async gist(
9
+ videoId: string,
10
+ types: GenerateGistType[],
11
+ options: RequestOptions = {},
12
+ ): Promise<Models.GenerateGistResult> {
13
+ const _body = convertKeysToSnakeCase({
14
+ videoId,
15
+ types,
16
+ });
17
+ const res = await this._post<Models.GenerateGistResult>('gist', _body, options);
18
+ return res;
19
+ }
20
+
21
+ async summarize(
22
+ videoId: string,
23
+ type: GenerateSummarizeType,
24
+ prompt?: string,
25
+ temperature?: number,
26
+ options: RequestOptions = {},
27
+ ): Promise<Models.GenerateSummarizeResult> {
28
+ const _body = convertKeysToSnakeCase({
29
+ videoId,
30
+ type,
31
+ prompt,
32
+ temperature,
33
+ });
34
+ const res = await this._post<Models.GenerateSummarizeResult>(
35
+ 'summarize',
36
+ removeUndefinedValues(_body),
37
+ options,
38
+ );
39
+ return res;
40
+ }
41
+
42
+ async text(
43
+ videoId: string,
44
+ prompt: string,
45
+ temperature?: number,
46
+ options: RequestOptions = {},
47
+ ): Promise<Models.GenerateOpenEndedTextResult> {
48
+ const _body = convertKeysToSnakeCase({
49
+ videoId,
50
+ prompt,
51
+ temperature,
52
+ });
53
+ const res = await this._post<Models.GenerateOpenEndedTextResult>('generate', _body, options);
54
+ return res;
55
+ }
56
+ }
@@ -0,0 +1,2 @@
1
+ export type GenerateGistType = 'topic' | 'hashtag' | 'title';
2
+ export type GenerateSummarizeType = 'summary' | 'chapter' | 'highlight';
@@ -0,0 +1,91 @@
1
+ import { TwelveLabs } from '../..';
2
+ import { RequestOptions } from '../../core';
3
+ import * as Models from '../../models';
4
+ import { APIResource } from '../../resource';
5
+ import { convertKeysToSnakeCase, handleComparisonParams, removeUndefinedValues } from '../../util';
6
+ import { Video as VideoResource } from '../video';
7
+ import { CreateIndexParams, ListIndexParams } from './interfaces';
8
+
9
+ export class Index extends APIResource {
10
+ video: VideoResource;
11
+
12
+ constructor(client: TwelveLabs) {
13
+ super(client);
14
+ this.video = new VideoResource(client);
15
+ }
16
+
17
+ async retrieve(id: string, options: RequestOptions = {}): Promise<Models.Index> {
18
+ const res = await this._get<Models.IndexResponse>(`indexes/${id}`, {}, options);
19
+ return new Models.Index(this, res);
20
+ }
21
+
22
+ async list(
23
+ { id, name, createdAt, updatedAt, ...restParams }: ListIndexParams = {},
24
+ options: RequestOptions = {},
25
+ ): Promise<Models.Index[]> {
26
+ const _params = convertKeysToSnakeCase({
27
+ ...restParams,
28
+ _id: id,
29
+ indexName: name,
30
+ });
31
+ handleComparisonParams(_params, 'createdAt', createdAt);
32
+ handleComparisonParams(_params, 'updatedAt', updatedAt);
33
+ const res = await this._get<{ data: Models.IndexResponse[] }>(
34
+ 'indexes',
35
+ removeUndefinedValues(_params),
36
+ options,
37
+ );
38
+ return res.data.map((v) => new Models.Index(this, v));
39
+ }
40
+
41
+ async listPagination(
42
+ { id, name, createdAt, updatedAt, ...restParams }: ListIndexParams = {},
43
+ options: RequestOptions = {},
44
+ ): Promise<Models.IndexListWithPagination> {
45
+ const originParams = { id, name, ...restParams };
46
+ const _params = convertKeysToSnakeCase({
47
+ ...restParams,
48
+ _id: id,
49
+ indexName: name,
50
+ });
51
+ handleComparisonParams(_params, 'createdAt', createdAt);
52
+ handleComparisonParams(_params, 'updatedAt', updatedAt);
53
+ const res = await this._get<{ data: Models.IndexResponse[]; pageInfo: Models.PageInfo }>(
54
+ 'indexes',
55
+ removeUndefinedValues(_params),
56
+ options,
57
+ );
58
+ return new Models.IndexListWithPagination(this, originParams, res.data, res.pageInfo);
59
+ }
60
+
61
+ async create(
62
+ { name, engines, addons }: CreateIndexParams,
63
+ options: RequestOptions = {},
64
+ ): Promise<Models.Index> {
65
+ const _body = {
66
+ indexName: name,
67
+ engines: engines.map(({ name, options }) => ({ engineName: name, engineOptions: options })),
68
+ addons,
69
+ };
70
+ const res = await this._post<{ id: string }>(
71
+ 'indexes',
72
+ removeUndefinedValues(convertKeysToSnakeCase(_body)),
73
+ options,
74
+ );
75
+ return await this.retrieve(res.id);
76
+ }
77
+
78
+ async update(id: string, name: string, options: RequestOptions = {}): Promise<void> {
79
+ await this._put<void>(
80
+ `indexes/${id}`,
81
+ convertKeysToSnakeCase({
82
+ indexName: name,
83
+ }),
84
+ options,
85
+ );
86
+ }
87
+
88
+ async delete(id: string, options: RequestOptions = {}): Promise<void> {
89
+ await this._delete<void>(`indexes/${id}`, options);
90
+ }
91
+ }
@@ -0,0 +1,16 @@
1
+ import { PageOptions } from '../../interfaces';
2
+
3
+ export interface ListIndexParams extends PageOptions {
4
+ id?: string;
5
+ name?: string;
6
+ engineOptions?: string[];
7
+ engineFamily?: 'marengo' | 'pegasus';
8
+ createdAt?: string | Record<string, string>;
9
+ updatedAt?: string | Record<string, string>;
10
+ }
11
+
12
+ export interface CreateIndexParams {
13
+ name: string;
14
+ engines: { name: string; options: string[] }[];
15
+ addons?: string[];
16
+ }
@@ -0,0 +1,12 @@
1
+ export * from './engine';
2
+ export * from './index/';
3
+ export * from './task';
4
+ export * from './video';
5
+ export * from './search';
6
+ export * from './generate';
7
+
8
+ export * from './index/interfaces';
9
+ export * from './search/interfaces';
10
+ export * from './task/interfaces';
11
+ export * from './video/interfaces';
12
+ export * from './generate/interfaces';
@@ -0,0 +1,28 @@
1
+ import { RequestOptions } from '../../core';
2
+ import * as Models from '../../models';
3
+ import { APIResource } from '../../resource';
4
+ import { convertKeysToSnakeCase, removeUndefinedValues } from '../../util';
5
+ import { SearchOptions } from './interfaces';
6
+
7
+ export class Search extends APIResource {
8
+ async query(
9
+ { options: searchOptions, ...restBody }: SearchOptions,
10
+ options: RequestOptions = {},
11
+ ): Promise<Models.SearchResult> {
12
+ const _body = convertKeysToSnakeCase({
13
+ ...restBody,
14
+ searchOptions,
15
+ });
16
+ const res = await this._post<Models.SearchResultResponse>(
17
+ 'search',
18
+ removeUndefinedValues(_body),
19
+ options,
20
+ );
21
+ return new Models.SearchResult(this, res);
22
+ }
23
+
24
+ async byPageToken(pageToken: string, options: RequestOptions = {}): Promise<Models.SearchResult> {
25
+ const res = await this._get<Models.SearchResultResponse>(`search/${pageToken}`, {}, options);
26
+ return new Models.SearchResult(this, res);
27
+ }
28
+ }
@@ -0,0 +1,12 @@
1
+ export interface SearchOptions {
2
+ indexId: string;
3
+ query: string | Record<string, any>;
4
+ options?: ('visual' | 'conversation' | 'text_in_video' | 'logo')[];
5
+ groupBy?: 'video' | 'clip';
6
+ threshold?: 'high' | 'medium' | 'low';
7
+ operator?: 'or' | 'and';
8
+ conversationOption?: 'semantic' | 'exact_match';
9
+ filter?: Record<string, any>;
10
+ pageLimit?: number;
11
+ sortOption?: 'score' | 'clip_count';
12
+ }
@@ -0,0 +1,161 @@
1
+ import path from 'path';
2
+ import FormData from 'form-data';
3
+ import { RequestOptions } from '../../core';
4
+ import * as Models from '../../models';
5
+ import { convertKeysToSnakeCase, handleComparisonParams, removeUndefinedValues } from '../../util';
6
+ import { CreateTaskParams, ListTaskParams } from './interfaces';
7
+ import { createReadStream } from 'fs';
8
+ import { APIResource } from '../../resource';
9
+
10
+ export class Task extends APIResource {
11
+ async retrieve(id: string, options: RequestOptions = {}): Promise<Models.Task> {
12
+ const res = await this._get<Models.TaskResponse>(`tasks/${id}`, {}, options);
13
+ return new Models.Task(this, res);
14
+ }
15
+
16
+ async list(
17
+ { id, createdAt, updatedAt, ...restParams }: ListTaskParams = {},
18
+ options: RequestOptions = {},
19
+ ): Promise<Models.Task[]> {
20
+ const _params = convertKeysToSnakeCase({
21
+ ...restParams,
22
+ _id: id,
23
+ });
24
+ handleComparisonParams(_params, 'createdAt', createdAt);
25
+ handleComparisonParams(_params, 'updatedAt', updatedAt);
26
+ const res = await this._get<{ data: Models.TaskResponse[] }>(
27
+ 'tasks',
28
+ removeUndefinedValues(_params),
29
+ options,
30
+ );
31
+ return res.data.map((v) => new Models.Task(this, v));
32
+ }
33
+
34
+ async listPagination(
35
+ { id, createdAt, updatedAt, ...restParams }: ListTaskParams = {},
36
+ options: RequestOptions = {},
37
+ ): Promise<Models.TaskListWithPagination> {
38
+ const originParams = { id, ...restParams };
39
+ const _params = convertKeysToSnakeCase({
40
+ ...restParams,
41
+ _id: id,
42
+ });
43
+ handleComparisonParams(_params, 'updatedAt', updatedAt);
44
+ const res = await this._get<{ data: Models.TaskResponse[]; pageInfo: Models.PageInfo }>(
45
+ 'tasks',
46
+ removeUndefinedValues(_params),
47
+ options,
48
+ );
49
+ return new Models.TaskListWithPagination(this, originParams, res.data, res.pageInfo);
50
+ }
51
+
52
+ async create(body: CreateTaskParams, options: RequestOptions = {}): Promise<Models.Task> {
53
+ if (!body.file && !body.url) {
54
+ throw new Error('Either file or url must be provided');
55
+ }
56
+
57
+ const formData = new FormData();
58
+
59
+ formData.append('index_id', body.indexId);
60
+ if (body.url) formData.append('video_url', body.url);
61
+ if (body.transcriptionUrl) formData.append('transcription_url', body.transcriptionUrl);
62
+ if (body.language) formData.append('language', body.language);
63
+ if (body.disableVideoStream) formData.append('disable_video_stream', body.disableVideoStream);
64
+
65
+ if (typeof body.file === 'string') {
66
+ const filePath = path.resolve(body.file);
67
+ const fileStream = createReadStream(filePath);
68
+ const fileName = path.basename(filePath);
69
+ formData.append('video_file', fileStream, fileName);
70
+ } else if (body.file) {
71
+ formData.append('video_file', body.file);
72
+ }
73
+
74
+ if (typeof body.transcriptionFile === 'string') {
75
+ const filePath = path.resolve(body.transcriptionFile);
76
+ const fileStream = createReadStream(filePath);
77
+ const fileName = path.basename(filePath);
78
+ formData.append('transcription_file', fileStream, fileName);
79
+ formData.append('provide_transcription', true);
80
+ } else if (body.transcriptionFile) {
81
+ formData.append('transcription_file', body.transcriptionFile);
82
+ formData.append('provide_transcription', true);
83
+ }
84
+
85
+ const res = await this._post<{ id: string }>('tasks', formData, options);
86
+
87
+ return await this.retrieve(res.id);
88
+ }
89
+
90
+ async createBulk(
91
+ indexId: string,
92
+ {
93
+ files,
94
+ urls,
95
+ language,
96
+ disableVideoStream,
97
+ }: {
98
+ files?: (string | Buffer | null)[];
99
+ urls?: string[];
100
+ language?: string;
101
+ disableVideoStream?: boolean;
102
+ },
103
+ options: RequestOptions = {},
104
+ ): Promise<Models.Task[]> {
105
+ if (!files && !urls) {
106
+ throw new Error('Either files or urls must be provided');
107
+ }
108
+
109
+ const tasks: Models.Task[] = [];
110
+
111
+ if (files) {
112
+ for (const file of files) {
113
+ try {
114
+ const task = await this.create({ indexId, file, language, disableVideoStream }, options);
115
+ tasks.push(task);
116
+ } catch (e) {
117
+ console.error(`Error processing file ${file}:`, e);
118
+ }
119
+ }
120
+ }
121
+
122
+ if (urls) {
123
+ for (const url of urls) {
124
+ try {
125
+ const task = await this.create({ indexId, url, language, disableVideoStream }, options);
126
+ tasks.push(task);
127
+ } catch (e) {
128
+ console.error(`Error processing url ${url}:`, e);
129
+ }
130
+ }
131
+ }
132
+
133
+ return tasks;
134
+ }
135
+
136
+ async delete(id: string, options: RequestOptions = {}): Promise<void> {
137
+ await this._delete<void>(`tasks/${id}`, options);
138
+ }
139
+
140
+ async status(indexId: string, options: RequestOptions = {}): Promise<Models.TaskStatus> {
141
+ const params = { index_id: indexId };
142
+ const res = await this._get<Models.TaskStatus>(`tasks/status`, convertKeysToSnakeCase(params), options);
143
+ return res;
144
+ }
145
+
146
+ async transfer(file: Buffer | NodeJS.ReadableStream, options: RequestOptions = {}): Promise<void> {
147
+ const formData = new FormData();
148
+ formData.append('file', file);
149
+ await this._post<void>(`tasks/transfers`, formData, options);
150
+ }
151
+
152
+ async externalProvider(indexId: string, url: string, options: RequestOptions = {}): Promise<Models.Task> {
153
+ const body = { index_id: indexId, url };
154
+ const res = await this._post<{ id: string }>(
155
+ `tasks/external-provider`,
156
+ convertKeysToSnakeCase(body),
157
+ options,
158
+ );
159
+ return await this.retrieve(res.id);
160
+ }
161
+ }
@@ -0,0 +1,23 @@
1
+ import { PageOptions } from '../../interfaces';
2
+
3
+ export interface ListTaskParams extends PageOptions {
4
+ id?: string;
5
+ indexId?: string;
6
+ filename?: string;
7
+ duration?: number;
8
+ width?: number;
9
+ height?: number;
10
+ createdAt?: string | Record<string, string>;
11
+ updatedAt?: string | Record<string, string>;
12
+ estimatedTime?: number;
13
+ }
14
+
15
+ export interface CreateTaskParams {
16
+ indexId: string;
17
+ file?: Buffer | NodeJS.ReadableStream | string;
18
+ url?: string;
19
+ transcriptionFile?: Buffer | NodeJS.ReadableStream | string;
20
+ transcriptionUrl?: string;
21
+ language?: string;
22
+ disableVideoStream?: boolean;
23
+ }