anyfast 0.0.1
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/LICENSE +189 -0
- package/README.md +281 -0
- package/dist/asset.d.ts +14 -0
- package/dist/asset.js +34 -0
- package/dist/chat.d.ts +35 -0
- package/dist/chat.js +63 -0
- package/dist/client.d.ts +26 -0
- package/dist/client.js +186 -0
- package/dist/file.d.ts +8 -0
- package/dist/file.js +65 -0
- package/dist/image.d.ts +11 -0
- package/dist/image.js +28 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +35 -0
- package/dist/sse-parser.d.ts +2 -0
- package/dist/sse-parser.js +66 -0
- package/dist/task-utils.d.ts +24 -0
- package/dist/task-utils.js +59 -0
- package/dist/types/asset.d.ts +62 -0
- package/dist/types/asset.js +3 -0
- package/dist/types/chat.d.ts +192 -0
- package/dist/types/chat.js +3 -0
- package/dist/types/common.d.ts +40 -0
- package/dist/types/common.js +13 -0
- package/dist/types/file.d.ts +22 -0
- package/dist/types/file.js +2 -0
- package/dist/types/image.d.ts +20 -0
- package/dist/types/image.js +2 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +22 -0
- package/dist/types/video.d.ts +95 -0
- package/dist/types/video.js +3 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.js +18 -0
- package/dist/upload/s3-uploader.d.ts +10 -0
- package/dist/upload/s3-uploader.js +123 -0
- package/dist/video.d.ts +17 -0
- package/dist/video.js +64 -0
- package/package.json +36 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
export interface ChatCompletionRequest {
|
|
2
|
+
model: string;
|
|
3
|
+
messages: Array<{
|
|
4
|
+
role: string;
|
|
5
|
+
content: string | any[];
|
|
6
|
+
}>;
|
|
7
|
+
stream?: boolean;
|
|
8
|
+
temperature?: number;
|
|
9
|
+
max_tokens?: number;
|
|
10
|
+
top_p?: number;
|
|
11
|
+
frequency_penalty?: number;
|
|
12
|
+
presence_penalty?: number;
|
|
13
|
+
stop?: string | string[];
|
|
14
|
+
n?: number;
|
|
15
|
+
response_format?: {
|
|
16
|
+
type: string;
|
|
17
|
+
};
|
|
18
|
+
tools?: any[];
|
|
19
|
+
tool_choice?: any;
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}
|
|
22
|
+
export interface ChatCompletionResponse {
|
|
23
|
+
id: string;
|
|
24
|
+
object: string;
|
|
25
|
+
created: number;
|
|
26
|
+
model: string;
|
|
27
|
+
choices: Array<{
|
|
28
|
+
index: number;
|
|
29
|
+
message: {
|
|
30
|
+
role: string;
|
|
31
|
+
content: string | null;
|
|
32
|
+
tool_calls?: any[];
|
|
33
|
+
};
|
|
34
|
+
finish_reason: string;
|
|
35
|
+
}>;
|
|
36
|
+
usage?: {
|
|
37
|
+
prompt_tokens: number;
|
|
38
|
+
completion_tokens: number;
|
|
39
|
+
total_tokens: number;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface ChatCompletionChunk {
|
|
43
|
+
id: string;
|
|
44
|
+
object: string;
|
|
45
|
+
created: number;
|
|
46
|
+
model: string;
|
|
47
|
+
choices: Array<{
|
|
48
|
+
index: number;
|
|
49
|
+
delta: {
|
|
50
|
+
role?: string;
|
|
51
|
+
content?: string;
|
|
52
|
+
tool_calls?: any[];
|
|
53
|
+
};
|
|
54
|
+
finish_reason: string | null;
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
export interface AnthropicMessagesRequest {
|
|
58
|
+
model: string;
|
|
59
|
+
messages: Array<{
|
|
60
|
+
role: string;
|
|
61
|
+
content: string | any[];
|
|
62
|
+
}>;
|
|
63
|
+
max_tokens: number;
|
|
64
|
+
stream?: boolean;
|
|
65
|
+
system?: string | any[];
|
|
66
|
+
temperature?: number;
|
|
67
|
+
top_p?: number;
|
|
68
|
+
top_k?: number;
|
|
69
|
+
stop_sequences?: string[];
|
|
70
|
+
tools?: any[];
|
|
71
|
+
tool_choice?: any;
|
|
72
|
+
thinking?: {
|
|
73
|
+
type: string;
|
|
74
|
+
budget_tokens?: number;
|
|
75
|
+
};
|
|
76
|
+
metadata?: {
|
|
77
|
+
user_id?: string;
|
|
78
|
+
};
|
|
79
|
+
[key: string]: any;
|
|
80
|
+
}
|
|
81
|
+
export interface AnthropicMessagesResponse {
|
|
82
|
+
id: string;
|
|
83
|
+
type: string;
|
|
84
|
+
role: string;
|
|
85
|
+
content: Array<{
|
|
86
|
+
type: string;
|
|
87
|
+
text?: string;
|
|
88
|
+
[key: string]: any;
|
|
89
|
+
}>;
|
|
90
|
+
model: string;
|
|
91
|
+
stop_reason: string | null;
|
|
92
|
+
stop_sequence: string | null;
|
|
93
|
+
usage: {
|
|
94
|
+
input_tokens: number;
|
|
95
|
+
output_tokens: number;
|
|
96
|
+
cache_creation_input_tokens?: number;
|
|
97
|
+
cache_read_input_tokens?: number;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export interface ResponsesRequest {
|
|
101
|
+
model: string;
|
|
102
|
+
input: string | any[];
|
|
103
|
+
stream?: boolean;
|
|
104
|
+
temperature?: number;
|
|
105
|
+
top_p?: number;
|
|
106
|
+
max_output_tokens?: number;
|
|
107
|
+
reasoning?: {
|
|
108
|
+
effort: string;
|
|
109
|
+
};
|
|
110
|
+
[key: string]: any;
|
|
111
|
+
}
|
|
112
|
+
export interface ResponsesResponse {
|
|
113
|
+
id: string;
|
|
114
|
+
object: string;
|
|
115
|
+
created_at: number;
|
|
116
|
+
completed_at?: number;
|
|
117
|
+
model: string;
|
|
118
|
+
status: string;
|
|
119
|
+
output: Array<{
|
|
120
|
+
type: string;
|
|
121
|
+
role?: string;
|
|
122
|
+
status?: string;
|
|
123
|
+
content?: Array<{
|
|
124
|
+
type: string;
|
|
125
|
+
text: string;
|
|
126
|
+
}>;
|
|
127
|
+
summary?: Array<{
|
|
128
|
+
type: string;
|
|
129
|
+
text: string;
|
|
130
|
+
}>;
|
|
131
|
+
}>;
|
|
132
|
+
usage?: {
|
|
133
|
+
input_tokens: number;
|
|
134
|
+
output_tokens: number;
|
|
135
|
+
total_tokens: number;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
export interface GeminiGenerateContentRequest {
|
|
139
|
+
contents: Array<{
|
|
140
|
+
role?: string;
|
|
141
|
+
parts: Array<{
|
|
142
|
+
text?: string;
|
|
143
|
+
inlineData?: {
|
|
144
|
+
mimeType: string;
|
|
145
|
+
data: string;
|
|
146
|
+
};
|
|
147
|
+
}>;
|
|
148
|
+
}>;
|
|
149
|
+
generationConfig?: {
|
|
150
|
+
temperature?: number;
|
|
151
|
+
topP?: number;
|
|
152
|
+
topK?: number;
|
|
153
|
+
maxOutputTokens?: number;
|
|
154
|
+
stopSequences?: string[];
|
|
155
|
+
responseMimeType?: string;
|
|
156
|
+
responseSchema?: any;
|
|
157
|
+
};
|
|
158
|
+
systemInstruction?: {
|
|
159
|
+
parts: Array<{
|
|
160
|
+
text: string;
|
|
161
|
+
}>;
|
|
162
|
+
};
|
|
163
|
+
tools?: any[];
|
|
164
|
+
toolConfig?: any;
|
|
165
|
+
safetySettings?: any[];
|
|
166
|
+
[key: string]: any;
|
|
167
|
+
}
|
|
168
|
+
export interface GeminiGenerateContentResponse {
|
|
169
|
+
candidates: Array<{
|
|
170
|
+
content: {
|
|
171
|
+
parts: Array<{
|
|
172
|
+
text?: string;
|
|
173
|
+
[key: string]: any;
|
|
174
|
+
}>;
|
|
175
|
+
role: string;
|
|
176
|
+
};
|
|
177
|
+
finishReason: string;
|
|
178
|
+
index: number;
|
|
179
|
+
safetyRatings?: any[];
|
|
180
|
+
}>;
|
|
181
|
+
usageMetadata?: {
|
|
182
|
+
promptTokenCount: number;
|
|
183
|
+
candidatesTokenCount: number;
|
|
184
|
+
totalTokenCount: number;
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
export interface SSEEvent {
|
|
188
|
+
event?: string;
|
|
189
|
+
data: string;
|
|
190
|
+
id?: string;
|
|
191
|
+
retry?: number;
|
|
192
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface AnyFastOptions {
|
|
2
|
+
apiKey?: string;
|
|
3
|
+
baseURL?: string;
|
|
4
|
+
gatewayURL?: string;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class AnyFastError extends Error {
|
|
8
|
+
status?: number;
|
|
9
|
+
code?: string;
|
|
10
|
+
data?: any;
|
|
11
|
+
constructor(message: string, status?: number, code?: string, data?: any);
|
|
12
|
+
}
|
|
13
|
+
export interface GenerationResponse {
|
|
14
|
+
taskId: string | null;
|
|
15
|
+
data: any;
|
|
16
|
+
}
|
|
17
|
+
export interface TaskStatus {
|
|
18
|
+
id: string;
|
|
19
|
+
action: string;
|
|
20
|
+
status: string;
|
|
21
|
+
completion: string;
|
|
22
|
+
created_at: string;
|
|
23
|
+
updated_at: string;
|
|
24
|
+
progress: string;
|
|
25
|
+
fail_reason: string;
|
|
26
|
+
result: any;
|
|
27
|
+
isCompleted(): boolean;
|
|
28
|
+
isFailed(): boolean;
|
|
29
|
+
isProcessing(): boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface BlockingRunOptions {
|
|
32
|
+
pollIntervalMs?: number;
|
|
33
|
+
timeoutMs?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface TaskGenerationOptions {
|
|
36
|
+
model: string;
|
|
37
|
+
prompt: string;
|
|
38
|
+
image?: string;
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnyFastError = void 0;
|
|
4
|
+
class AnyFastError extends Error {
|
|
5
|
+
constructor(message, status, code, data) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'AnyFastError';
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.data = data;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.AnyFastError = AnyFastError;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface FileUploadConfig {
|
|
2
|
+
bucket: string;
|
|
3
|
+
region: string;
|
|
4
|
+
endpoint?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface STSCredentials {
|
|
7
|
+
accessKeyId: string;
|
|
8
|
+
secretAccessKey: string;
|
|
9
|
+
sessionToken: string;
|
|
10
|
+
}
|
|
11
|
+
export interface STSTokenData {
|
|
12
|
+
credentials: STSCredentials;
|
|
13
|
+
bucket: string;
|
|
14
|
+
region: string;
|
|
15
|
+
endpoint?: string;
|
|
16
|
+
prefix: string;
|
|
17
|
+
}
|
|
18
|
+
export interface STSTokenResponse {
|
|
19
|
+
code: number;
|
|
20
|
+
data: STSTokenData;
|
|
21
|
+
message: string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface ImageGenerationOptions {
|
|
2
|
+
model: string;
|
|
3
|
+
prompt: string;
|
|
4
|
+
n?: number;
|
|
5
|
+
size?: string;
|
|
6
|
+
quality?: string;
|
|
7
|
+
response_format?: string;
|
|
8
|
+
output_format?: string;
|
|
9
|
+
seed?: number;
|
|
10
|
+
image?: string | string[];
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}
|
|
13
|
+
export interface ImageGenerationResponse {
|
|
14
|
+
created: number;
|
|
15
|
+
data: Array<{
|
|
16
|
+
url?: string;
|
|
17
|
+
b64_json?: string;
|
|
18
|
+
revised_prompt?: string;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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("./common"), exports);
|
|
18
|
+
__exportStar(require("./chat"), exports);
|
|
19
|
+
__exportStar(require("./image"), exports);
|
|
20
|
+
__exportStar(require("./video"), exports);
|
|
21
|
+
__exportStar(require("./asset"), exports);
|
|
22
|
+
__exportStar(require("./file"), exports);
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export interface SeedanceVideoOptions {
|
|
2
|
+
model: string;
|
|
3
|
+
content: Array<{
|
|
4
|
+
type: string;
|
|
5
|
+
text?: string;
|
|
6
|
+
image_url?: {
|
|
7
|
+
url: string;
|
|
8
|
+
};
|
|
9
|
+
video_url?: {
|
|
10
|
+
url: string;
|
|
11
|
+
};
|
|
12
|
+
audio_url?: {
|
|
13
|
+
url: string;
|
|
14
|
+
};
|
|
15
|
+
role?: string;
|
|
16
|
+
}>;
|
|
17
|
+
generate_audio?: boolean;
|
|
18
|
+
resolution?: string;
|
|
19
|
+
ratio?: string;
|
|
20
|
+
duration?: number;
|
|
21
|
+
watermark?: boolean;
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}
|
|
24
|
+
export interface KlingText2VideoOptions {
|
|
25
|
+
model_name: string;
|
|
26
|
+
prompt: string;
|
|
27
|
+
negative_prompt?: string;
|
|
28
|
+
mode?: 'std' | 'pro';
|
|
29
|
+
duration?: string;
|
|
30
|
+
aspect_ratio?: string;
|
|
31
|
+
cfg_scale?: number;
|
|
32
|
+
multi_shot?: boolean;
|
|
33
|
+
shot_type?: string;
|
|
34
|
+
multi_prompt?: Array<{
|
|
35
|
+
index: number;
|
|
36
|
+
prompt: string;
|
|
37
|
+
duration: string;
|
|
38
|
+
}>;
|
|
39
|
+
sound?: 'on' | 'off';
|
|
40
|
+
camera_control?: any;
|
|
41
|
+
watermark_info?: {
|
|
42
|
+
enabled: boolean;
|
|
43
|
+
};
|
|
44
|
+
callback_url?: string;
|
|
45
|
+
external_task_id?: string;
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
}
|
|
48
|
+
export interface KlingImage2VideoOptions {
|
|
49
|
+
model_name: string;
|
|
50
|
+
image?: string;
|
|
51
|
+
image_tail?: string;
|
|
52
|
+
prompt?: string;
|
|
53
|
+
negative_prompt?: string;
|
|
54
|
+
mode?: 'std' | 'pro';
|
|
55
|
+
duration?: string;
|
|
56
|
+
cfg_scale?: number;
|
|
57
|
+
multi_shot?: boolean;
|
|
58
|
+
shot_type?: string;
|
|
59
|
+
multi_prompt?: Array<{
|
|
60
|
+
index: number;
|
|
61
|
+
prompt: string;
|
|
62
|
+
duration: string;
|
|
63
|
+
}>;
|
|
64
|
+
element_list?: Array<{
|
|
65
|
+
element_id: string;
|
|
66
|
+
}>;
|
|
67
|
+
sound?: 'on' | 'off';
|
|
68
|
+
camera_control?: any;
|
|
69
|
+
static_mask?: string;
|
|
70
|
+
dynamic_masks?: any[];
|
|
71
|
+
watermark_info?: {
|
|
72
|
+
enabled: boolean;
|
|
73
|
+
};
|
|
74
|
+
callback_url?: string;
|
|
75
|
+
external_task_id?: string;
|
|
76
|
+
[key: string]: any;
|
|
77
|
+
}
|
|
78
|
+
export interface KlingMultiImage2VideoOptions {
|
|
79
|
+
model_name: string;
|
|
80
|
+
image_list: Array<{
|
|
81
|
+
image: string;
|
|
82
|
+
}>;
|
|
83
|
+
prompt: string;
|
|
84
|
+
negative_prompt?: string;
|
|
85
|
+
mode?: 'std' | 'pro';
|
|
86
|
+
duration?: string;
|
|
87
|
+
aspect_ratio?: string;
|
|
88
|
+
watermark_info?: {
|
|
89
|
+
enabled: boolean;
|
|
90
|
+
};
|
|
91
|
+
callback_url?: string;
|
|
92
|
+
external_task_id?: string;
|
|
93
|
+
[key: string]: any;
|
|
94
|
+
}
|
|
95
|
+
export type KlingAction = 'text2video' | 'image2video' | 'multi-image2video' | 'omni-video' | 'lip-sync';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/index';
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
// Re-export all types from the types directory for backwards compatibility
|
|
18
|
+
__exportStar(require("./types/index"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { STSCredentials } from '../types/file';
|
|
2
|
+
export declare class S3Uploader {
|
|
3
|
+
private s3Client;
|
|
4
|
+
private bucket;
|
|
5
|
+
constructor(credentials: STSCredentials, bucket: string, region: string, endpoint?: string);
|
|
6
|
+
uploadFile(filePath: string, key: string, contentType: string): Promise<string>;
|
|
7
|
+
private simpleUpload;
|
|
8
|
+
private multipartUpload;
|
|
9
|
+
private getObjectUrl;
|
|
10
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.S3Uploader = void 0;
|
|
37
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const MULTIPART_THRESHOLD = 8 * 1024 * 1024; // 8MB
|
|
40
|
+
class S3Uploader {
|
|
41
|
+
constructor(credentials, bucket, region, endpoint) {
|
|
42
|
+
this.bucket = bucket;
|
|
43
|
+
this.s3Client = new client_s3_1.S3Client({
|
|
44
|
+
region,
|
|
45
|
+
credentials: {
|
|
46
|
+
accessKeyId: credentials.accessKeyId,
|
|
47
|
+
secretAccessKey: credentials.secretAccessKey,
|
|
48
|
+
sessionToken: credentials.sessionToken,
|
|
49
|
+
},
|
|
50
|
+
...(endpoint ? { endpoint } : {}),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async uploadFile(filePath, key, contentType) {
|
|
54
|
+
const stats = fs.statSync(filePath);
|
|
55
|
+
if (stats.size > MULTIPART_THRESHOLD) {
|
|
56
|
+
return this.multipartUpload(filePath, key, contentType);
|
|
57
|
+
}
|
|
58
|
+
return this.simpleUpload(filePath, key, contentType);
|
|
59
|
+
}
|
|
60
|
+
async simpleUpload(filePath, key, contentType) {
|
|
61
|
+
const fileContent = fs.readFileSync(filePath);
|
|
62
|
+
await this.s3Client.send(new client_s3_1.PutObjectCommand({
|
|
63
|
+
Bucket: this.bucket,
|
|
64
|
+
Key: key,
|
|
65
|
+
Body: fileContent,
|
|
66
|
+
ContentType: contentType,
|
|
67
|
+
}));
|
|
68
|
+
return this.getObjectUrl(key);
|
|
69
|
+
}
|
|
70
|
+
async multipartUpload(filePath, key, contentType) {
|
|
71
|
+
const createResponse = await this.s3Client.send(new client_s3_1.CreateMultipartUploadCommand({
|
|
72
|
+
Bucket: this.bucket,
|
|
73
|
+
Key: key,
|
|
74
|
+
ContentType: contentType,
|
|
75
|
+
}));
|
|
76
|
+
const uploadId = createResponse.UploadId;
|
|
77
|
+
const fileSize = fs.statSync(filePath).size;
|
|
78
|
+
const parts = [];
|
|
79
|
+
try {
|
|
80
|
+
let partNumber = 1;
|
|
81
|
+
let offset = 0;
|
|
82
|
+
while (offset < fileSize) {
|
|
83
|
+
const chunkSize = Math.min(MULTIPART_THRESHOLD, fileSize - offset);
|
|
84
|
+
const buffer = Buffer.alloc(chunkSize);
|
|
85
|
+
const fd = fs.openSync(filePath, 'r');
|
|
86
|
+
fs.readSync(fd, buffer, 0, chunkSize, offset);
|
|
87
|
+
fs.closeSync(fd);
|
|
88
|
+
const uploadPartResponse = await this.s3Client.send(new client_s3_1.UploadPartCommand({
|
|
89
|
+
Bucket: this.bucket,
|
|
90
|
+
Key: key,
|
|
91
|
+
UploadId: uploadId,
|
|
92
|
+
PartNumber: partNumber,
|
|
93
|
+
Body: buffer,
|
|
94
|
+
}));
|
|
95
|
+
parts.push({
|
|
96
|
+
ETag: uploadPartResponse.ETag,
|
|
97
|
+
PartNumber: partNumber,
|
|
98
|
+
});
|
|
99
|
+
partNumber++;
|
|
100
|
+
offset += chunkSize;
|
|
101
|
+
}
|
|
102
|
+
await this.s3Client.send(new client_s3_1.CompleteMultipartUploadCommand({
|
|
103
|
+
Bucket: this.bucket,
|
|
104
|
+
Key: key,
|
|
105
|
+
UploadId: uploadId,
|
|
106
|
+
MultipartUpload: { Parts: parts },
|
|
107
|
+
}));
|
|
108
|
+
return this.getObjectUrl(key);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
await this.s3Client.send(new client_s3_1.AbortMultipartUploadCommand({
|
|
112
|
+
Bucket: this.bucket,
|
|
113
|
+
Key: key,
|
|
114
|
+
UploadId: uploadId,
|
|
115
|
+
}));
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
getObjectUrl(key) {
|
|
120
|
+
return `https://${this.bucket}.s3.amazonaws.com/${key}`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.S3Uploader = S3Uploader;
|
package/dist/video.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AnyFast } from './client';
|
|
2
|
+
import { BlockingRunOptions, SeedanceVideoOptions, KlingText2VideoOptions, KlingImage2VideoOptions, KlingMultiImage2VideoOptions, KlingAction } from './types';
|
|
3
|
+
import { GenerationResponseImpl, TaskStatusImpl } from './task-utils';
|
|
4
|
+
export declare class Video {
|
|
5
|
+
private client;
|
|
6
|
+
constructor(client: AnyFast);
|
|
7
|
+
generateAsync(options: SeedanceVideoOptions): Promise<GenerationResponseImpl>;
|
|
8
|
+
queryTask(taskId: string): Promise<TaskStatusImpl>;
|
|
9
|
+
run(options: SeedanceVideoOptions, runOptions?: BlockingRunOptions): Promise<TaskStatusImpl>;
|
|
10
|
+
klingText2Video(options: KlingText2VideoOptions): Promise<GenerationResponseImpl>;
|
|
11
|
+
klingImage2Video(options: KlingImage2VideoOptions): Promise<GenerationResponseImpl>;
|
|
12
|
+
klingMultiImage2Video(options: KlingMultiImage2VideoOptions): Promise<GenerationResponseImpl>;
|
|
13
|
+
klingQueryTask(action: KlingAction, taskId: string): Promise<TaskStatusImpl>;
|
|
14
|
+
runKlingText2Video(options: KlingText2VideoOptions, runOptions?: BlockingRunOptions): Promise<TaskStatusImpl>;
|
|
15
|
+
runKlingImage2Video(options: KlingImage2VideoOptions, runOptions?: BlockingRunOptions): Promise<TaskStatusImpl>;
|
|
16
|
+
runKlingMultiImage2Video(options: KlingMultiImage2VideoOptions, runOptions?: BlockingRunOptions): Promise<TaskStatusImpl>;
|
|
17
|
+
}
|
package/dist/video.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Video = void 0;
|
|
4
|
+
const task_utils_1 = require("./task-utils");
|
|
5
|
+
class Video {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
// ---- Seedance ----
|
|
10
|
+
async generateAsync(options) {
|
|
11
|
+
const data = await this.client.post('/v1/video/generations', options);
|
|
12
|
+
return new task_utils_1.GenerationResponseImpl(data);
|
|
13
|
+
}
|
|
14
|
+
async queryTask(taskId) {
|
|
15
|
+
const data = await this.client.get(`/v1/video/generations/${taskId}`);
|
|
16
|
+
return new task_utils_1.TaskStatusImpl(data);
|
|
17
|
+
}
|
|
18
|
+
async run(options, runOptions = {}) {
|
|
19
|
+
const response = await this.generateAsync(options);
|
|
20
|
+
if (!response.taskId) {
|
|
21
|
+
throw new Error('No task ID returned from generation request');
|
|
22
|
+
}
|
|
23
|
+
return (0, task_utils_1.waitForTaskCompletion)((taskId) => this.queryTask(taskId), response.taskId, runOptions);
|
|
24
|
+
}
|
|
25
|
+
// ---- Kling ----
|
|
26
|
+
async klingText2Video(options) {
|
|
27
|
+
const data = await this.client.post('/kling/v1/videos/text2video', options);
|
|
28
|
+
return new task_utils_1.GenerationResponseImpl(data);
|
|
29
|
+
}
|
|
30
|
+
async klingImage2Video(options) {
|
|
31
|
+
const data = await this.client.post('/kling/v1/videos/image2video', options);
|
|
32
|
+
return new task_utils_1.GenerationResponseImpl(data);
|
|
33
|
+
}
|
|
34
|
+
async klingMultiImage2Video(options) {
|
|
35
|
+
const data = await this.client.post('/kling/v1/videos/multi-image2video', options);
|
|
36
|
+
return new task_utils_1.GenerationResponseImpl(data);
|
|
37
|
+
}
|
|
38
|
+
async klingQueryTask(action, taskId) {
|
|
39
|
+
const data = await this.client.get(`/kling/v1/videos/${action}/${taskId}`);
|
|
40
|
+
return new task_utils_1.TaskStatusImpl(data);
|
|
41
|
+
}
|
|
42
|
+
async runKlingText2Video(options, runOptions = {}) {
|
|
43
|
+
const response = await this.klingText2Video(options);
|
|
44
|
+
if (!response.taskId) {
|
|
45
|
+
throw new Error('No task ID returned from Kling text2video request');
|
|
46
|
+
}
|
|
47
|
+
return (0, task_utils_1.waitForTaskCompletion)((taskId) => this.klingQueryTask('text2video', taskId), response.taskId, runOptions);
|
|
48
|
+
}
|
|
49
|
+
async runKlingImage2Video(options, runOptions = {}) {
|
|
50
|
+
const response = await this.klingImage2Video(options);
|
|
51
|
+
if (!response.taskId) {
|
|
52
|
+
throw new Error('No task ID returned from Kling image2video request');
|
|
53
|
+
}
|
|
54
|
+
return (0, task_utils_1.waitForTaskCompletion)((taskId) => this.klingQueryTask('image2video', taskId), response.taskId, runOptions);
|
|
55
|
+
}
|
|
56
|
+
async runKlingMultiImage2Video(options, runOptions = {}) {
|
|
57
|
+
const response = await this.klingMultiImage2Video(options);
|
|
58
|
+
if (!response.taskId) {
|
|
59
|
+
throw new Error('No task ID returned from Kling multi-image2video request');
|
|
60
|
+
}
|
|
61
|
+
return (0, task_utils_1.waitForTaskCompletion)((taskId) => this.klingQueryTask('multi-image2video', taskId), response.taskId, runOptions);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.Video = Video;
|