deepseen-sdk 1.0.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,54 @@
1
+ # deepseen-sdk
2
+
3
+ Deepseen Open API 官方 TypeScript SDK。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ pnpm add deepseen-sdk
9
+ # 或安装本地打包:pnpm add ./deepseen-sdk-1.0.0.tgz
10
+ ```
11
+
12
+ ## 快速开始
13
+
14
+ 默认连接生产环境 `https://deepseen.ai/v1`,只需提供 API Key:
15
+
16
+ ```typescript
17
+ import { DeepseenClient } from 'deepseen-sdk';
18
+
19
+ const client = new DeepseenClient({
20
+ apiKey: process.env.DEEPSEEN_API_KEY!, // sk_xxx
21
+ });
22
+
23
+ const file = await client.files.upload('./product.jpg');
24
+ const job = await client.smartImage.recreations.create({
25
+ region: '美国',
26
+ keywords: 'Men cotton t-shirt',
27
+ productImages: [file.url],
28
+ });
29
+
30
+ const result = await job.wait({
31
+ timeoutMs: 1_800_000,
32
+ onProgress: (j) => console.log(j.status, j.progress),
33
+ });
34
+ ```
35
+
36
+ ## 环境变量
37
+
38
+ | 变量 | 说明 |
39
+ |------|------|
40
+ | `DEEPSEEN_API_KEY` | 必填,`sk_xxx` |
41
+ | `DEEPSEEN_BASE_URL` | 可选,默认 `https://deepseen.ai/v1` |
42
+
43
+ ```typescript
44
+ import { clientFromEnv } from 'deepseen-sdk';
45
+ const client = clientFromEnv();
46
+ ```
47
+
48
+ ## 能力
49
+
50
+ - `client.files` — 上传产品图 / 参考视频
51
+ - `client.smartImage.recreations` — 图片智创
52
+ - `client.image.recreations` — 图片二创
53
+ - `client.smartVideo.recreations` — 视频智创
54
+ - `client.video.recreations` — 视频二创
@@ -0,0 +1,263 @@
1
+ interface HttpClientOptions {
2
+ apiKey: string;
3
+ baseURL: string;
4
+ timeoutMs: number;
5
+ }
6
+ declare class HttpClient {
7
+ private readonly options;
8
+ constructor(options: HttpClientOptions);
9
+ get baseURL(): string;
10
+ request<T>(method: string, path: string, init?: {
11
+ body?: unknown;
12
+ formData?: FormData;
13
+ idempotencyKey?: string;
14
+ }): Promise<T>;
15
+ get<T>(path: string): Promise<T>;
16
+ post<T>(path: string, body?: unknown, idempotencyKey?: string): Promise<T>;
17
+ postForm<T>(path: string, formData: FormData): Promise<T>;
18
+ }
19
+
20
+ type MediaJobStatus = 'queued' | 'analyzing' | 'awaiting_confirmation' | 'generating' | 'completed' | 'failed' | 'cancelled';
21
+ /** @deprecated 使用 MediaJobStatus */
22
+ type ImageJobStatus = MediaJobStatus;
23
+ type MediaJobType = 'image.recreation' | 'smart_image.recreation' | 'video.recreation' | 'smart_video.recreation';
24
+ type SmartVideoModel = 'Veo8s' | 'Veo8s_official' | 'Veo8s*2' | 'Grok10s' | 'SeeDance15s';
25
+ interface MediaOutput {
26
+ index: number;
27
+ url: string;
28
+ variant_id: string;
29
+ kind?: 'image' | 'video';
30
+ revised_prompt?: string;
31
+ }
32
+ /** @deprecated 使用 MediaOutput */
33
+ type ImageOutput = MediaOutput;
34
+ interface MediaJobAnalysis {
35
+ variants: Array<{
36
+ variant_id: string;
37
+ strategy?: string;
38
+ prompt?: string;
39
+ }>;
40
+ reference_images?: string[];
41
+ }
42
+ interface MediaJob {
43
+ id: string;
44
+ object: 'image.job' | 'video.job';
45
+ type: MediaJobType;
46
+ status: MediaJobStatus;
47
+ progress: number;
48
+ created_at: number;
49
+ completed_at?: number;
50
+ metadata?: Record<string, string>;
51
+ error?: {
52
+ code: string;
53
+ message: string;
54
+ };
55
+ analysis?: MediaJobAnalysis;
56
+ outputs?: MediaOutput[];
57
+ }
58
+ /** @deprecated 使用 MediaJob */
59
+ type ImageJob = MediaJob;
60
+ interface ApiFile {
61
+ id: string;
62
+ object: 'file';
63
+ purpose: string;
64
+ filename: string;
65
+ bytes: number;
66
+ content_type: string;
67
+ url: string;
68
+ created_at: number;
69
+ }
70
+ interface DeepseenClientOptions {
71
+ apiKey: string;
72
+ baseURL?: string;
73
+ timeoutMs?: number;
74
+ }
75
+ interface SmartImageCreateParams {
76
+ region?: string;
77
+ keywords: string;
78
+ productImages?: string[];
79
+ productFileIds?: string[];
80
+ productDetails?: string;
81
+ includePrompts?: boolean;
82
+ metadata?: Record<string, string>;
83
+ webhookUrl?: string;
84
+ idempotencyKey?: string;
85
+ }
86
+ interface SmartVideoCreateParams {
87
+ region?: string;
88
+ productTitle: string;
89
+ productImages?: string[];
90
+ productFileIds?: string[];
91
+ count?: number;
92
+ model?: SmartVideoModel;
93
+ includePrompts?: boolean;
94
+ metadata?: Record<string, string>;
95
+ webhookUrl?: string;
96
+ idempotencyKey?: string;
97
+ }
98
+ interface ImageRecreationCreateParams {
99
+ competitorProductUrl: string;
100
+ productImages?: string[];
101
+ productFileIds?: string[];
102
+ model?: string;
103
+ aspectRatio?: string;
104
+ autoGenerate?: boolean;
105
+ includePrompts?: boolean;
106
+ metadata?: Record<string, string>;
107
+ webhookUrl?: string;
108
+ idempotencyKey?: string;
109
+ }
110
+ interface VideoRecreationCreateParams {
111
+ competitorVideoUrl: string;
112
+ productImages?: string[];
113
+ productFileIds?: string[];
114
+ model?: string;
115
+ groupCount?: number;
116
+ autoGenerate?: boolean;
117
+ includePrompts?: boolean;
118
+ metadata?: Record<string, string>;
119
+ webhookUrl?: string;
120
+ idempotencyKey?: string;
121
+ }
122
+ interface RecreationConfirmParams {
123
+ model?: string;
124
+ variants?: Array<{
125
+ variant_id: string;
126
+ prompt?: string;
127
+ }>;
128
+ }
129
+ /** @deprecated 使用 RecreationConfirmParams */
130
+ type ImageRecreationConfirmParams = RecreationConfirmParams;
131
+ interface WaitOptions {
132
+ pollIntervalMs?: number;
133
+ timeoutMs?: number;
134
+ onProgress?: (job: MediaJob) => void;
135
+ }
136
+
137
+ declare class FilesAPI {
138
+ private readonly http;
139
+ constructor(http: HttpClient);
140
+ /** 上传本地文件(图片或视频),返回可填入 product_images / competitor_video_url 的 url */
141
+ upload(filePath: string, purpose?: string): Promise<ApiFile>;
142
+ /** 上传 Buffer / Blob(浏览器或 Node 均可用) */
143
+ uploadBlob(blob: Blob, filename: string, purpose?: string): Promise<ApiFile>;
144
+ retrieve(fileId: string): Promise<ApiFile>;
145
+ }
146
+
147
+ type JobResource = 'smart-image' | 'image' | 'smart-video' | 'video';
148
+ declare class MediaJobHandle {
149
+ private readonly http;
150
+ private readonly resource;
151
+ data: MediaJob;
152
+ constructor(http: HttpClient, resource: JobResource, data: MediaJob);
153
+ get id(): string;
154
+ get status(): MediaJobStatus;
155
+ refresh(): Promise<MediaJobHandle>;
156
+ wait(options?: WaitOptions): Promise<MediaJob>;
157
+ cancel(): Promise<MediaJob>;
158
+ confirm(body?: RecreationConfirmParams): Promise<MediaJobHandle>;
159
+ }
160
+ /** @deprecated 使用 MediaJobHandle */
161
+ type ImageJobHandle = MediaJobHandle;
162
+
163
+ declare class SmartImageRecreationsAPI {
164
+ private readonly http;
165
+ constructor(http: HttpClient);
166
+ create(params: SmartImageCreateParams): Promise<MediaJobHandle>;
167
+ retrieve(jobId: string): Promise<MediaJobHandle>;
168
+ }
169
+ declare class SmartImageAPI {
170
+ readonly recreations: SmartImageRecreationsAPI;
171
+ constructor(http: HttpClient);
172
+ }
173
+
174
+ declare class ImageRecreationsAPI {
175
+ private readonly http;
176
+ constructor(http: HttpClient);
177
+ create(params: ImageRecreationCreateParams): Promise<MediaJobHandle>;
178
+ retrieve(jobId: string): Promise<MediaJobHandle>;
179
+ confirm(jobId: string, params?: ImageRecreationConfirmParams): Promise<MediaJobHandle>;
180
+ }
181
+ declare class ImageAPI {
182
+ readonly recreations: ImageRecreationsAPI;
183
+ constructor(http: HttpClient);
184
+ }
185
+
186
+ declare class SmartVideoRecreationsAPI {
187
+ private readonly http;
188
+ constructor(http: HttpClient);
189
+ create(params: SmartVideoCreateParams): Promise<MediaJobHandle>;
190
+ retrieve(jobId: string): Promise<MediaJobHandle>;
191
+ }
192
+ declare class SmartVideoAPI {
193
+ readonly recreations: SmartVideoRecreationsAPI;
194
+ constructor(http: HttpClient);
195
+ }
196
+
197
+ declare class VideoRecreationsAPI {
198
+ private readonly http;
199
+ constructor(http: HttpClient);
200
+ create(params: VideoRecreationCreateParams): Promise<MediaJobHandle>;
201
+ retrieve(jobId: string): Promise<MediaJobHandle>;
202
+ confirm(jobId: string, params?: RecreationConfirmParams): Promise<MediaJobHandle>;
203
+ }
204
+ declare class VideoAPI {
205
+ readonly recreations: VideoRecreationsAPI;
206
+ constructor(http: HttpClient);
207
+ }
208
+
209
+ /**
210
+ * Deepseen Open API 客户端
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * const client = new DeepseenClient({
215
+ * apiKey: 'sk_xxx',
216
+ * // baseURL 可选,默认 https://deepseen.ai/v1
217
+ * });
218
+ *
219
+ * const file = await client.files.upload('./product.jpg');
220
+ * const job = await client.smartImage.recreations.create({
221
+ * keywords: 'Men cotton t-shirt',
222
+ * productImages: [file.url],
223
+ * });
224
+ * const result = await job.wait({ timeoutMs: 600_000 });
225
+ * console.log(result.outputs);
226
+ * ```
227
+ */
228
+ declare class DeepseenClient {
229
+ readonly files: FilesAPI;
230
+ readonly smartImage: SmartImageAPI;
231
+ readonly image: ImageAPI;
232
+ readonly smartVideo: SmartVideoAPI;
233
+ readonly video: VideoAPI;
234
+ private readonly http;
235
+ constructor(options: DeepseenClientOptions);
236
+ /** 健康检查 / 列出可用端点 */
237
+ ping(): Promise<{
238
+ object: string;
239
+ openapi_enabled?: boolean;
240
+ }>;
241
+ }
242
+ declare function createClient(options: DeepseenClientOptions): DeepseenClient;
243
+ /** 从环境变量 DEEPSEEN_API_KEY + DEEPSEEN_BASE_URL 创建客户端 */
244
+ declare function clientFromEnv(): DeepseenClient;
245
+
246
+ /** Deepseen Open API 生产环境默认地址 */
247
+ declare const DEFAULT_BASE_URL = "https://deepseen.ai/v1";
248
+
249
+ declare class DeepseenError extends Error {
250
+ readonly code: string;
251
+ readonly status?: number;
252
+ readonly param?: string | null;
253
+ constructor(message: string, code?: string, status?: number, param?: string | null);
254
+ }
255
+ declare class DeepseenTimeoutError extends DeepseenError {
256
+ constructor(message?: string);
257
+ }
258
+ declare class DeepseenJobFailedError extends DeepseenError {
259
+ readonly jobId: string;
260
+ constructor(jobId: string, message: string, code?: string);
261
+ }
262
+
263
+ export { type ApiFile, DEFAULT_BASE_URL, DeepseenClient, type DeepseenClientOptions, DeepseenError, DeepseenJobFailedError, DeepseenTimeoutError, type ImageJob, type ImageJobHandle, type ImageJobStatus, type ImageOutput, type ImageRecreationConfirmParams, type ImageRecreationCreateParams, type MediaJob, MediaJobHandle, type MediaJobStatus, type MediaOutput, type RecreationConfirmParams, type SmartImageCreateParams, type SmartVideoCreateParams, type SmartVideoModel, type VideoRecreationCreateParams, type WaitOptions, clientFromEnv, createClient };
package/dist/index.js ADDED
@@ -0,0 +1,410 @@
1
+ // src/errors.ts
2
+ var DeepseenError = class extends Error {
3
+ code;
4
+ status;
5
+ param;
6
+ constructor(message, code = "deepseen_error", status, param) {
7
+ super(message);
8
+ this.name = "DeepseenError";
9
+ this.code = code;
10
+ this.status = status;
11
+ this.param = param;
12
+ }
13
+ };
14
+ var DeepseenTimeoutError = class extends DeepseenError {
15
+ constructor(message = "Job wait timeout") {
16
+ super(message, "timeout");
17
+ this.name = "DeepseenTimeoutError";
18
+ }
19
+ };
20
+ var DeepseenJobFailedError = class extends DeepseenError {
21
+ jobId;
22
+ constructor(jobId, message, code = "job_failed") {
23
+ super(message, code);
24
+ this.name = "DeepseenJobFailedError";
25
+ this.jobId = jobId;
26
+ }
27
+ };
28
+
29
+ // src/http.ts
30
+ var HttpClient = class {
31
+ constructor(options) {
32
+ this.options = options;
33
+ }
34
+ get baseURL() {
35
+ return this.options.baseURL;
36
+ }
37
+ async request(method, path2, init) {
38
+ const url = `${this.options.baseURL}${path2.startsWith("/") ? path2 : `/${path2}`}`;
39
+ const controller = new AbortController();
40
+ const timer = setTimeout(() => controller.abort(), this.options.timeoutMs);
41
+ try {
42
+ const headers = {
43
+ Authorization: `Bearer ${this.options.apiKey}`
44
+ };
45
+ if (init?.idempotencyKey) {
46
+ headers["Idempotency-Key"] = init.idempotencyKey;
47
+ }
48
+ if (!init?.formData) {
49
+ headers["Content-Type"] = "application/json";
50
+ }
51
+ const res = await fetch(url, {
52
+ method,
53
+ headers,
54
+ body: init?.formData ?? (init?.body != null ? JSON.stringify(init.body) : void 0),
55
+ signal: controller.signal
56
+ });
57
+ const text = await res.text();
58
+ let data = null;
59
+ if (text) {
60
+ try {
61
+ data = JSON.parse(text);
62
+ } catch {
63
+ data = text;
64
+ }
65
+ }
66
+ if (!res.ok) {
67
+ const err = data ?? {};
68
+ throw new DeepseenError(
69
+ err.error?.message || `HTTP ${res.status}`,
70
+ err.error?.code || err.error?.type || "http_error",
71
+ res.status,
72
+ err.error?.param ?? null
73
+ );
74
+ }
75
+ return data;
76
+ } catch (err) {
77
+ if (err instanceof DeepseenError) throw err;
78
+ if (err instanceof Error && err.name === "AbortError") {
79
+ throw new DeepseenError("Request timeout", "timeout");
80
+ }
81
+ throw err;
82
+ } finally {
83
+ clearTimeout(timer);
84
+ }
85
+ }
86
+ get(path2) {
87
+ return this.request("GET", path2);
88
+ }
89
+ post(path2, body, idempotencyKey) {
90
+ return this.request("POST", path2, { body, idempotencyKey });
91
+ }
92
+ postForm(path2, formData) {
93
+ return this.request("POST", path2, { formData });
94
+ }
95
+ };
96
+
97
+ // src/resources/files.ts
98
+ import fs from "fs";
99
+ import path from "path";
100
+ var FilesAPI = class {
101
+ constructor(http) {
102
+ this.http = http;
103
+ }
104
+ /** 上传本地文件(图片或视频),返回可填入 product_images / competitor_video_url 的 url */
105
+ async upload(filePath, purpose = "product_image") {
106
+ const buffer = fs.readFileSync(filePath);
107
+ const filename = path.basename(filePath);
108
+ const ext = path.extname(filename).toLowerCase();
109
+ const mime = ext === ".png" ? "image/png" : ext === ".webp" ? "image/webp" : ext === ".mp4" ? "video/mp4" : ext === ".webm" ? "video/webm" : ext === ".mov" ? "video/quicktime" : "image/jpeg";
110
+ const form = new FormData();
111
+ form.append("purpose", purpose);
112
+ form.append("file", new Blob([buffer], { type: mime }), filename);
113
+ return this.http.postForm("/files", form);
114
+ }
115
+ /** 上传 Buffer / Blob(浏览器或 Node 均可用) */
116
+ async uploadBlob(blob, filename, purpose = "product_image") {
117
+ const form = new FormData();
118
+ form.append("purpose", purpose);
119
+ form.append("file", blob, filename);
120
+ return this.http.postForm("/files", form);
121
+ }
122
+ async retrieve(fileId) {
123
+ return this.http.get(`/files/${fileId}`);
124
+ }
125
+ };
126
+
127
+ // src/imageJob.ts
128
+ var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
129
+ function jobPath(resource, jobId, action) {
130
+ const baseMap = {
131
+ "smart-image": `/smart-image/recreations/${jobId}`,
132
+ image: `/image/recreations/${jobId}`,
133
+ "smart-video": `/smart-video/recreations/${jobId}`,
134
+ video: `/video/recreations/${jobId}`
135
+ };
136
+ const base = baseMap[resource];
137
+ if (action === "cancel") return `${base}/cancel`;
138
+ if (action === "confirm") return `${base}/confirm`;
139
+ return base;
140
+ }
141
+ var MediaJobHandle = class {
142
+ constructor(http, resource, data) {
143
+ this.http = http;
144
+ this.resource = resource;
145
+ this.data = data;
146
+ }
147
+ get id() {
148
+ return this.data.id;
149
+ }
150
+ get status() {
151
+ return this.data.status;
152
+ }
153
+ async refresh() {
154
+ this.data = await this.http.get(jobPath(this.resource, this.data.id));
155
+ return this;
156
+ }
157
+ async wait(options = {}) {
158
+ const pollIntervalMs = options.pollIntervalMs ?? 8e3;
159
+ const timeoutMs = options.timeoutMs ?? 6e5;
160
+ const start = Date.now();
161
+ while (true) {
162
+ await this.refresh();
163
+ options.onProgress?.(this.data);
164
+ if (TERMINAL.has(this.data.status)) {
165
+ if (this.data.status === "failed") {
166
+ throw new DeepseenJobFailedError(
167
+ this.data.id,
168
+ this.data.error?.message ?? "Job failed",
169
+ this.data.error?.code ?? "job_failed"
170
+ );
171
+ }
172
+ return this.data;
173
+ }
174
+ if (Date.now() - start > timeoutMs) {
175
+ throw new DeepseenTimeoutError();
176
+ }
177
+ await new Promise((r) => setTimeout(r, pollIntervalMs));
178
+ }
179
+ }
180
+ async cancel() {
181
+ this.data = await this.http.post(jobPath(this.resource, this.data.id, "cancel"));
182
+ return this.data;
183
+ }
184
+ async confirm(body) {
185
+ if (this.resource !== "image" && this.resource !== "video") {
186
+ throw new Error("confirm() \u4EC5\u9002\u7528\u4E8E\u56FE\u7247/\u89C6\u9891\u4E8C\u521B Job");
187
+ }
188
+ this.data = await this.http.post(
189
+ jobPath(this.resource, this.data.id, "confirm"),
190
+ body
191
+ );
192
+ return this;
193
+ }
194
+ };
195
+ function wrapJob(http, resource, data) {
196
+ return new MediaJobHandle(http, resource, data);
197
+ }
198
+
199
+ // src/resources/smartImage.ts
200
+ var SmartImageRecreationsAPI = class {
201
+ constructor(http) {
202
+ this.http = http;
203
+ }
204
+ async create(params) {
205
+ const body = {
206
+ region: params.region,
207
+ keywords: params.keywords,
208
+ product_images: params.productImages,
209
+ product_file_ids: params.productFileIds,
210
+ product_details: params.productDetails,
211
+ include_prompts: params.includePrompts,
212
+ metadata: params.metadata,
213
+ webhook_url: params.webhookUrl
214
+ };
215
+ const job = await this.http.post(
216
+ "/smart-image/recreations",
217
+ body,
218
+ params.idempotencyKey
219
+ );
220
+ return wrapJob(this.http, "smart-image", job);
221
+ }
222
+ async retrieve(jobId) {
223
+ const job = await this.http.get(`/smart-image/recreations/${jobId}`);
224
+ return wrapJob(this.http, "smart-image", job);
225
+ }
226
+ };
227
+ var SmartImageAPI = class {
228
+ recreations;
229
+ constructor(http) {
230
+ this.recreations = new SmartImageRecreationsAPI(http);
231
+ }
232
+ };
233
+
234
+ // src/resources/imageRecreation.ts
235
+ var ImageRecreationsAPI = class {
236
+ constructor(http) {
237
+ this.http = http;
238
+ }
239
+ async create(params) {
240
+ const body = {
241
+ competitor_product_url: params.competitorProductUrl,
242
+ product_images: params.productImages,
243
+ product_file_ids: params.productFileIds,
244
+ model: params.model,
245
+ aspect_ratio: params.aspectRatio,
246
+ auto_generate: params.autoGenerate,
247
+ include_prompts: params.includePrompts,
248
+ metadata: params.metadata,
249
+ webhook_url: params.webhookUrl
250
+ };
251
+ const job = await this.http.post(
252
+ "/image/recreations",
253
+ body,
254
+ params.idempotencyKey
255
+ );
256
+ return wrapJob(this.http, "image", job);
257
+ }
258
+ async retrieve(jobId) {
259
+ const job = await this.http.get(`/image/recreations/${jobId}`);
260
+ return wrapJob(this.http, "image", job);
261
+ }
262
+ async confirm(jobId, params = {}) {
263
+ const job = await this.http.post(`/image/recreations/${jobId}/confirm`, {
264
+ model: params.model,
265
+ variants: params.variants
266
+ });
267
+ return wrapJob(this.http, "image", job);
268
+ }
269
+ };
270
+ var ImageAPI = class {
271
+ recreations;
272
+ constructor(http) {
273
+ this.recreations = new ImageRecreationsAPI(http);
274
+ }
275
+ };
276
+
277
+ // src/resources/smartVideo.ts
278
+ var SmartVideoRecreationsAPI = class {
279
+ constructor(http) {
280
+ this.http = http;
281
+ }
282
+ async create(params) {
283
+ const body = {
284
+ region: params.region,
285
+ product_title: params.productTitle,
286
+ product_images: params.productImages,
287
+ product_file_ids: params.productFileIds,
288
+ count: params.count,
289
+ model: params.model,
290
+ include_prompts: params.includePrompts,
291
+ metadata: params.metadata,
292
+ webhook_url: params.webhookUrl
293
+ };
294
+ const job = await this.http.post(
295
+ "/smart-video/recreations",
296
+ body,
297
+ params.idempotencyKey
298
+ );
299
+ return wrapJob(this.http, "smart-video", job);
300
+ }
301
+ async retrieve(jobId) {
302
+ const job = await this.http.get(`/smart-video/recreations/${jobId}`);
303
+ return wrapJob(this.http, "smart-video", job);
304
+ }
305
+ };
306
+ var SmartVideoAPI = class {
307
+ recreations;
308
+ constructor(http) {
309
+ this.recreations = new SmartVideoRecreationsAPI(http);
310
+ }
311
+ };
312
+
313
+ // src/resources/videoRecreation.ts
314
+ var VideoRecreationsAPI = class {
315
+ constructor(http) {
316
+ this.http = http;
317
+ }
318
+ async create(params) {
319
+ const body = {
320
+ competitor_video_url: params.competitorVideoUrl,
321
+ product_images: params.productImages,
322
+ product_file_ids: params.productFileIds,
323
+ model: params.model,
324
+ group_count: params.groupCount,
325
+ auto_generate: params.autoGenerate,
326
+ include_prompts: params.includePrompts,
327
+ metadata: params.metadata,
328
+ webhook_url: params.webhookUrl
329
+ };
330
+ const job = await this.http.post(
331
+ "/video/recreations",
332
+ body,
333
+ params.idempotencyKey
334
+ );
335
+ return wrapJob(this.http, "video", job);
336
+ }
337
+ async retrieve(jobId) {
338
+ const job = await this.http.get(`/video/recreations/${jobId}`);
339
+ return wrapJob(this.http, "video", job);
340
+ }
341
+ async confirm(jobId, params = {}) {
342
+ const job = await this.http.post(`/video/recreations/${jobId}/confirm`, {
343
+ model: params.model,
344
+ variants: params.variants
345
+ });
346
+ return wrapJob(this.http, "video", job);
347
+ }
348
+ };
349
+ var VideoAPI = class {
350
+ recreations;
351
+ constructor(http) {
352
+ this.recreations = new VideoRecreationsAPI(http);
353
+ }
354
+ };
355
+
356
+ // src/constants.ts
357
+ var DEFAULT_BASE_URL = "https://deepseen.ai/v1";
358
+
359
+ // src/client.ts
360
+ var DeepseenClient = class {
361
+ files;
362
+ smartImage;
363
+ image;
364
+ smartVideo;
365
+ video;
366
+ http;
367
+ constructor(options) {
368
+ if (!options.apiKey?.trim()) {
369
+ throw new Error("apiKey \u5FC5\u586B");
370
+ }
371
+ const baseURL = (options.baseURL ?? process.env.DEEPSEEN_BASE_URL ?? DEFAULT_BASE_URL).replace(/\/$/, "");
372
+ this.http = new HttpClient({
373
+ apiKey: options.apiKey.trim(),
374
+ baseURL,
375
+ timeoutMs: options.timeoutMs ?? 12e4
376
+ });
377
+ this.files = new FilesAPI(this.http);
378
+ this.smartImage = new SmartImageAPI(this.http);
379
+ this.image = new ImageAPI(this.http);
380
+ this.smartVideo = new SmartVideoAPI(this.http);
381
+ this.video = new VideoAPI(this.http);
382
+ }
383
+ /** 健康检查 / 列出可用端点 */
384
+ async ping() {
385
+ return this.http.get("/");
386
+ }
387
+ };
388
+ function createClient(options) {
389
+ return new DeepseenClient(options);
390
+ }
391
+ function clientFromEnv() {
392
+ const apiKey = process.env.DEEPSEEN_API_KEY;
393
+ if (!apiKey) {
394
+ throw new Error("\u8BF7\u8BBE\u7F6E\u73AF\u5883\u53D8\u91CF DEEPSEEN_API_KEY");
395
+ }
396
+ return new DeepseenClient({
397
+ apiKey,
398
+ baseURL: process.env.DEEPSEEN_BASE_URL
399
+ });
400
+ }
401
+ export {
402
+ DEFAULT_BASE_URL,
403
+ DeepseenClient,
404
+ DeepseenError,
405
+ DeepseenJobFailedError,
406
+ DeepseenTimeoutError,
407
+ MediaJobHandle,
408
+ clientFromEnv,
409
+ createClient
410
+ };
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "deepseen-sdk",
3
+ "version": "1.0.0",
4
+ "description": "Deepseen Open API SDK — 图片/视频智创与二创",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup src/index.ts --format esm --dts",
20
+ "dev": "tsup src/index.ts --format esm --dts --watch",
21
+ "test": "vitest run",
22
+ "prepack": "pnpm run build",
23
+ "publish:npm": "powershell -ExecutionPolicy Bypass -File ./scripts/publish.ps1"
24
+ },
25
+ "keywords": [
26
+ "deepseen",
27
+ "openapi",
28
+ "tiktok",
29
+ "ai",
30
+ "image-generation",
31
+ "video-generation"
32
+ ],
33
+ "license": "MIT",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/kanehuang168/deepseen.git",
37
+ "directory": "packages/sdk"
38
+ },
39
+ "publishConfig": {
40
+ "registry": "https://registry.npmjs.org/"
41
+ },
42
+ "engines": {
43
+ "node": ">=18"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^25.1.0",
47
+ "tsup": "^8.5.1",
48
+ "typescript": "^5.9.3",
49
+ "vitest": "^4.0.18"
50
+ }
51
+ }