@plasius/ai 1.1.4 → 1.1.6
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/CHANGELOG.md +22 -2
- package/README.md +101 -2
- package/dist/components/pixelverse/balance.d.ts +6 -2
- package/dist/components/pixelverse/balance.d.ts.map +1 -1
- package/dist/components/pixelverse/balance.js +13 -23
- package/dist/components/pixelverse/index.d.ts +1 -1
- package/dist/components/pixelverse/index.d.ts.map +1 -1
- package/dist/components/pixelverse/index.js +1 -1
- package/dist/components/pixelverse/video-generation-editor.d.ts +10 -0
- package/dist/components/pixelverse/video-generation-editor.d.ts.map +1 -0
- package/dist/components/pixelverse/video-generation-editor.js +79 -0
- package/dist/platform/adapter-platform.d.ts +60 -0
- package/dist/platform/adapter-platform.d.ts.map +1 -0
- package/dist/platform/adapter-platform.js +222 -0
- package/dist/platform/gemini-adapter.d.ts +15 -0
- package/dist/platform/gemini-adapter.d.ts.map +1 -0
- package/dist/platform/gemini-adapter.js +293 -0
- package/dist/platform/http-resilience.d.ts +19 -0
- package/dist/platform/http-resilience.d.ts.map +1 -0
- package/dist/platform/http-resilience.js +126 -0
- package/dist/platform/index.d.ts +22 -1
- package/dist/platform/index.d.ts.map +1 -1
- package/dist/platform/index.js +24 -0
- package/dist/platform/openai-adapter.d.ts +24 -0
- package/dist/platform/openai-adapter.d.ts.map +1 -0
- package/dist/platform/openai-adapter.js +398 -0
- package/dist/platform/video-provider-adapter.d.ts +54 -0
- package/dist/platform/video-provider-adapter.d.ts.map +1 -0
- package/dist/platform/video-provider-adapter.js +165 -0
- package/dist/platform/video-provider-platform.d.ts +13 -0
- package/dist/platform/video-provider-platform.d.ts.map +1 -0
- package/dist/platform/video-provider-platform.js +102 -0
- package/dist-cjs/components/pixelverse/balance.d.ts +6 -2
- package/dist-cjs/components/pixelverse/balance.d.ts.map +1 -1
- package/dist-cjs/components/pixelverse/balance.js +13 -23
- package/dist-cjs/components/pixelverse/index.d.ts +1 -1
- package/dist-cjs/components/pixelverse/index.d.ts.map +1 -1
- package/dist-cjs/components/pixelverse/index.js +1 -1
- package/dist-cjs/components/pixelverse/video-generation-editor.d.ts +10 -0
- package/dist-cjs/components/pixelverse/video-generation-editor.d.ts.map +1 -0
- package/dist-cjs/components/pixelverse/video-generation-editor.js +85 -0
- package/dist-cjs/platform/adapter-platform.d.ts +60 -0
- package/dist-cjs/platform/adapter-platform.d.ts.map +1 -0
- package/dist-cjs/platform/adapter-platform.js +225 -0
- package/dist-cjs/platform/gemini-adapter.d.ts +15 -0
- package/dist-cjs/platform/gemini-adapter.d.ts.map +1 -0
- package/dist-cjs/platform/gemini-adapter.js +296 -0
- package/dist-cjs/platform/http-resilience.d.ts +19 -0
- package/dist-cjs/platform/http-resilience.d.ts.map +1 -0
- package/dist-cjs/platform/http-resilience.js +129 -0
- package/dist-cjs/platform/index.d.ts +22 -1
- package/dist-cjs/platform/index.d.ts.map +1 -1
- package/dist-cjs/platform/index.js +30 -1
- package/dist-cjs/platform/openai-adapter.d.ts +24 -0
- package/dist-cjs/platform/openai-adapter.d.ts.map +1 -0
- package/dist-cjs/platform/openai-adapter.js +401 -0
- package/dist-cjs/platform/video-provider-adapter.d.ts +54 -0
- package/dist-cjs/platform/video-provider-adapter.d.ts.map +1 -0
- package/dist-cjs/platform/video-provider-adapter.js +168 -0
- package/dist-cjs/platform/video-provider-platform.d.ts +13 -0
- package/dist-cjs/platform/video-provider-platform.d.ts.map +1 -0
- package/dist-cjs/platform/video-provider-platform.js +105 -0
- package/docs/api-reference.md +59 -0
- package/docs/architecture.md +5 -1
- package/docs/providers.md +24 -6
- package/package.json +6 -6
- package/src/components/pixelverse/balance.tsx +22 -35
- package/src/components/pixelverse/index.ts +1 -1
- package/src/components/pixelverse/video-generation-editor.tsx +164 -0
- package/src/platform/adapter-platform.ts +440 -0
- package/src/platform/gemini-adapter.ts +391 -0
- package/src/platform/http-resilience.ts +198 -0
- package/src/platform/index.ts +68 -0
- package/src/platform/openai-adapter.ts +552 -0
- package/src/platform/video-provider-adapter.ts +303 -0
- package/src/platform/video-provider-platform.ts +208 -0
- package/dist/components/pixelverse/pixelverseeditor.d.ts +0 -16
- package/dist/components/pixelverse/pixelverseeditor.d.ts.map +0 -1
- package/dist/components/pixelverse/pixelverseeditor.js +0 -21
- package/dist/platform/openai.d.ts +0 -8
- package/dist/platform/openai.d.ts.map +0 -1
- package/dist/platform/openai.js +0 -61
- package/dist/platform/pixelverse.d.ts +0 -6
- package/dist/platform/pixelverse.d.ts.map +0 -1
- package/dist/platform/pixelverse.js +0 -196
- package/dist-cjs/components/pixelverse/pixelverseeditor.d.ts +0 -16
- package/dist-cjs/components/pixelverse/pixelverseeditor.d.ts.map +0 -1
- package/dist-cjs/components/pixelverse/pixelverseeditor.js +0 -27
- package/dist-cjs/platform/openai.d.ts +0 -8
- package/dist-cjs/platform/openai.d.ts.map +0 -1
- package/dist-cjs/platform/openai.js +0 -67
- package/dist-cjs/platform/pixelverse.d.ts +0 -6
- package/dist-cjs/platform/pixelverse.d.ts.map +0 -1
- package/dist-cjs/platform/pixelverse.js +0 -199
- package/src/components/pixelverse/pixelverseeditor.mocule.css +0 -0
- package/src/components/pixelverse/pixelverseeditor.tsx +0 -74
- package/src/platform/openai.ts +0 -123
- package/src/platform/pixelverse.ts +0 -309
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { fetchWithPolicy, type HttpClientPolicy } from "./http-resilience.js";
|
|
2
|
+
|
|
3
|
+
export interface ProviderBalance {
|
|
4
|
+
monthlyCredit: number;
|
|
5
|
+
packageCredit: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface VideoUploadResult {
|
|
9
|
+
imageId: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface VideoGenerationRequest {
|
|
13
|
+
imageId: number;
|
|
14
|
+
prompt: string;
|
|
15
|
+
negativePrompt?: string;
|
|
16
|
+
templateId?: string;
|
|
17
|
+
seed?: number;
|
|
18
|
+
durationSeconds?: number;
|
|
19
|
+
model?: string;
|
|
20
|
+
motionMode?: string;
|
|
21
|
+
quality?: string;
|
|
22
|
+
watermark?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface VideoGenerationResult {
|
|
26
|
+
videoId: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type VideoJobState = "pending" | "completed" | "failed";
|
|
30
|
+
|
|
31
|
+
export interface VideoJobResult {
|
|
32
|
+
state: VideoJobState;
|
|
33
|
+
videoUrl?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface VideoProviderRequestContext {
|
|
37
|
+
apiKey: string;
|
|
38
|
+
traceId?: string;
|
|
39
|
+
fetchFn?: typeof fetch;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface VideoProviderAdapter {
|
|
43
|
+
uploadImage(
|
|
44
|
+
image: File | URL,
|
|
45
|
+
context: VideoProviderRequestContext
|
|
46
|
+
): Promise<VideoUploadResult>;
|
|
47
|
+
generateVideo(
|
|
48
|
+
request: VideoGenerationRequest,
|
|
49
|
+
context: VideoProviderRequestContext
|
|
50
|
+
): Promise<VideoGenerationResult>;
|
|
51
|
+
getVideoResult(
|
|
52
|
+
videoId: number,
|
|
53
|
+
context: VideoProviderRequestContext
|
|
54
|
+
): Promise<VideoJobResult>;
|
|
55
|
+
getBalance?(context: VideoProviderRequestContext): Promise<ProviderBalance>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface HttpVideoProviderAdapterConfig {
|
|
59
|
+
uploadImagePath: string;
|
|
60
|
+
generateVideoPath: string;
|
|
61
|
+
getVideoResultPath: (videoId: number) => string;
|
|
62
|
+
getBalancePath?: string;
|
|
63
|
+
httpPolicy?: HttpClientPolicy;
|
|
64
|
+
mapUploadImageId?: (data: unknown) => number | undefined;
|
|
65
|
+
mapGeneratedVideoId?: (data: unknown) => number | undefined;
|
|
66
|
+
mapVideoResult?: (data: unknown) => VideoJobResult;
|
|
67
|
+
mapBalance?: (data: unknown) => ProviderBalance;
|
|
68
|
+
mapGenerateRequestBody?: (request: VideoGenerationRequest) => unknown;
|
|
69
|
+
additionalHeaders?: Record<string, string>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function asRecord(value: unknown): Record<string, unknown> {
|
|
73
|
+
return value && typeof value === "object" ? (value as Record<string, unknown>) : {};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function asNumber(value: unknown): number | undefined {
|
|
77
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function asString(value: unknown): string | undefined {
|
|
81
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function requireJson(
|
|
85
|
+
value: unknown,
|
|
86
|
+
label: string,
|
|
87
|
+
mapper: (data: unknown) => number | undefined
|
|
88
|
+
): number {
|
|
89
|
+
const id = mapper(value);
|
|
90
|
+
if (!id) {
|
|
91
|
+
throw new Error(`Invalid ${label} response.`);
|
|
92
|
+
}
|
|
93
|
+
return id;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function defaultRequestBody(request: VideoGenerationRequest): Record<string, unknown> {
|
|
97
|
+
const body: Record<string, unknown> = {
|
|
98
|
+
img_id: request.imageId,
|
|
99
|
+
prompt: request.prompt,
|
|
100
|
+
duration: request.durationSeconds ?? 5,
|
|
101
|
+
model: request.model ?? "standard",
|
|
102
|
+
motion_mode: request.motionMode ?? "normal",
|
|
103
|
+
quality: request.quality ?? "720p",
|
|
104
|
+
water_mark: request.watermark ?? false,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
if (request.seed !== undefined) {
|
|
108
|
+
body.seed = request.seed;
|
|
109
|
+
}
|
|
110
|
+
if (request.templateId) {
|
|
111
|
+
body.template_id = request.templateId;
|
|
112
|
+
}
|
|
113
|
+
if (request.negativePrompt) {
|
|
114
|
+
body.negative_prompt = request.negativePrompt;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return body;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function defaultHeaders(context: VideoProviderRequestContext): Record<string, string> {
|
|
121
|
+
const apiKey = context.apiKey.trim();
|
|
122
|
+
if (!apiKey) {
|
|
123
|
+
throw new Error("Provider API key is required.");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
"API-KEY": apiKey,
|
|
128
|
+
"AI-trace-ID": context.traceId ?? crypto.randomUUID(),
|
|
129
|
+
Accept: "application/json",
|
|
130
|
+
"X-Plasius-Client": "@plasius/ai/video-http-adapter",
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function defaultUploadMapper(data: unknown): number | undefined {
|
|
135
|
+
const root = asRecord(data);
|
|
136
|
+
const resp = asRecord(root.Resp);
|
|
137
|
+
return asNumber(resp.id);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function defaultVideoIdMapper(data: unknown): number | undefined {
|
|
141
|
+
const root = asRecord(data);
|
|
142
|
+
const resp = asRecord(root.Resp);
|
|
143
|
+
return asNumber(resp.id);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function defaultResultMapper(data: unknown): VideoJobResult {
|
|
147
|
+
const root = asRecord(data);
|
|
148
|
+
const resp = asRecord(root.Resp);
|
|
149
|
+
const status = asNumber(resp.status);
|
|
150
|
+
const url = asString(resp.url);
|
|
151
|
+
|
|
152
|
+
if (status === 1 && url) {
|
|
153
|
+
return { state: "completed", videoUrl: url };
|
|
154
|
+
}
|
|
155
|
+
if (status === -1) {
|
|
156
|
+
return { state: "failed" };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return { state: "pending" };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function defaultBalanceMapper(data: unknown): ProviderBalance {
|
|
163
|
+
const root = asRecord(data);
|
|
164
|
+
const resp = asRecord(root.Resp);
|
|
165
|
+
return {
|
|
166
|
+
monthlyCredit: asNumber(resp.credit_monthly) ?? 0,
|
|
167
|
+
packageCredit: asNumber(resp.credit_package) ?? 0,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function createHttpVideoProviderAdapter(
|
|
172
|
+
config: HttpVideoProviderAdapterConfig
|
|
173
|
+
): VideoProviderAdapter {
|
|
174
|
+
const fetchJson = async (
|
|
175
|
+
path: string,
|
|
176
|
+
createRequestInit: () => RequestInit | Promise<RequestInit>,
|
|
177
|
+
context: VideoProviderRequestContext
|
|
178
|
+
): Promise<unknown> => {
|
|
179
|
+
const fetchFn = context.fetchFn ?? fetch;
|
|
180
|
+
const response = await fetchWithPolicy({
|
|
181
|
+
url: path,
|
|
182
|
+
operation: "Video provider HTTP request",
|
|
183
|
+
fetchFn,
|
|
184
|
+
policy: config.httpPolicy,
|
|
185
|
+
createRequestInit,
|
|
186
|
+
});
|
|
187
|
+
if (!response.ok) {
|
|
188
|
+
throw new Error(`Provider request failed (${response.status} ${response.statusText}).`);
|
|
189
|
+
}
|
|
190
|
+
return response.json();
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const uploadImage = async (
|
|
194
|
+
image: File | URL,
|
|
195
|
+
context: VideoProviderRequestContext
|
|
196
|
+
): Promise<VideoUploadResult> => {
|
|
197
|
+
const fetchFn = context.fetchFn ?? fetch;
|
|
198
|
+
|
|
199
|
+
const data = await fetchJson(
|
|
200
|
+
config.uploadImagePath,
|
|
201
|
+
async () => {
|
|
202
|
+
const formData = new FormData();
|
|
203
|
+
if (image instanceof File) {
|
|
204
|
+
formData.append("image", image, "upload-image");
|
|
205
|
+
} else {
|
|
206
|
+
const blob = await fetchFn(image.toString()).then((result) => result.blob());
|
|
207
|
+
formData.append("image", blob, "upload-image");
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
method: "POST",
|
|
212
|
+
headers: {
|
|
213
|
+
...defaultHeaders(context),
|
|
214
|
+
...config.additionalHeaders,
|
|
215
|
+
},
|
|
216
|
+
body: formData,
|
|
217
|
+
};
|
|
218
|
+
},
|
|
219
|
+
context
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const imageId = requireJson(data, "image upload", config.mapUploadImageId ?? defaultUploadMapper);
|
|
223
|
+
return { imageId };
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const generateVideo = async (
|
|
227
|
+
request: VideoGenerationRequest,
|
|
228
|
+
context: VideoProviderRequestContext
|
|
229
|
+
): Promise<VideoGenerationResult> => {
|
|
230
|
+
const data = await fetchJson(
|
|
231
|
+
config.generateVideoPath,
|
|
232
|
+
() => {
|
|
233
|
+
const body = JSON.stringify(
|
|
234
|
+
config.mapGenerateRequestBody?.(request) ?? defaultRequestBody(request)
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
return {
|
|
238
|
+
method: "POST",
|
|
239
|
+
headers: {
|
|
240
|
+
...defaultHeaders(context),
|
|
241
|
+
"Content-Type": "application/json",
|
|
242
|
+
...config.additionalHeaders,
|
|
243
|
+
},
|
|
244
|
+
body,
|
|
245
|
+
};
|
|
246
|
+
},
|
|
247
|
+
context
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
const videoId = requireJson(
|
|
251
|
+
data,
|
|
252
|
+
"video generation",
|
|
253
|
+
config.mapGeneratedVideoId ?? defaultVideoIdMapper
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
return { videoId };
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
const getVideoResult = async (
|
|
260
|
+
videoId: number,
|
|
261
|
+
context: VideoProviderRequestContext
|
|
262
|
+
): Promise<VideoJobResult> => {
|
|
263
|
+
const data = await fetchJson(
|
|
264
|
+
config.getVideoResultPath(videoId),
|
|
265
|
+
() => ({
|
|
266
|
+
method: "GET",
|
|
267
|
+
headers: {
|
|
268
|
+
...defaultHeaders(context),
|
|
269
|
+
...config.additionalHeaders,
|
|
270
|
+
},
|
|
271
|
+
}),
|
|
272
|
+
context
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
return (config.mapVideoResult ?? defaultResultMapper)(data);
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const getBalance = config.getBalancePath
|
|
279
|
+
? async (context: VideoProviderRequestContext): Promise<ProviderBalance> => {
|
|
280
|
+
const data = await fetchJson(
|
|
281
|
+
config.getBalancePath as string,
|
|
282
|
+
() => ({
|
|
283
|
+
method: "GET",
|
|
284
|
+
headers: {
|
|
285
|
+
...defaultHeaders(context),
|
|
286
|
+
"Content-Type": "application/json",
|
|
287
|
+
...config.additionalHeaders,
|
|
288
|
+
},
|
|
289
|
+
}),
|
|
290
|
+
context
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
return (config.mapBalance ?? defaultBalanceMapper)(data);
|
|
294
|
+
}
|
|
295
|
+
: undefined;
|
|
296
|
+
|
|
297
|
+
return {
|
|
298
|
+
uploadImage,
|
|
299
|
+
generateVideo,
|
|
300
|
+
getVideoResult,
|
|
301
|
+
getBalance,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { performance } from "node:perf_hooks";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
AIPlatform,
|
|
5
|
+
BalanceCompletion,
|
|
6
|
+
ChatCompletion,
|
|
7
|
+
Completion,
|
|
8
|
+
ImageCompletion,
|
|
9
|
+
ModelCompletion,
|
|
10
|
+
SpeechCompletion,
|
|
11
|
+
TextCompletion,
|
|
12
|
+
VideoCompletion,
|
|
13
|
+
} from "./index.js";
|
|
14
|
+
import type {
|
|
15
|
+
VideoGenerationRequest,
|
|
16
|
+
VideoJobResult,
|
|
17
|
+
VideoProviderAdapter,
|
|
18
|
+
} from "./video-provider-adapter.js";
|
|
19
|
+
|
|
20
|
+
export interface VideoProviderPlatformProps {
|
|
21
|
+
apiKey: string;
|
|
22
|
+
adapter: VideoProviderAdapter;
|
|
23
|
+
polling?: {
|
|
24
|
+
maxRetries?: number;
|
|
25
|
+
delayMs?: number;
|
|
26
|
+
};
|
|
27
|
+
defaultVideoRequest?: Partial<Omit<VideoGenerationRequest, "imageId" | "prompt">>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function createCompletionBase(
|
|
31
|
+
type: string,
|
|
32
|
+
model: string,
|
|
33
|
+
requestor: string,
|
|
34
|
+
durationMs: number
|
|
35
|
+
): Completion {
|
|
36
|
+
return {
|
|
37
|
+
partitionKey: requestor,
|
|
38
|
+
id: crypto.randomUUID(),
|
|
39
|
+
type,
|
|
40
|
+
model,
|
|
41
|
+
createdAt: new Date().toISOString(),
|
|
42
|
+
durationMs,
|
|
43
|
+
usage: {},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function waitForCompletion(
|
|
48
|
+
adapter: VideoProviderAdapter,
|
|
49
|
+
videoId: number,
|
|
50
|
+
apiKey: string,
|
|
51
|
+
maxRetries: number,
|
|
52
|
+
delayMs: number
|
|
53
|
+
): Promise<string> {
|
|
54
|
+
for (let attempt = 0; attempt < maxRetries; attempt += 1) {
|
|
55
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
56
|
+
|
|
57
|
+
const result: VideoJobResult = await adapter.getVideoResult(videoId, {
|
|
58
|
+
apiKey,
|
|
59
|
+
traceId: crypto.randomUUID(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (result.state === "completed" && result.videoUrl) {
|
|
63
|
+
return result.videoUrl;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (result.state === "failed") {
|
|
67
|
+
throw new Error("Video generation failed in provider adapter.");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
throw new Error("Timed out waiting for provider video completion.");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function createVideoProviderPlatform(
|
|
75
|
+
userId: string,
|
|
76
|
+
props: VideoProviderPlatformProps
|
|
77
|
+
): Promise<AIPlatform> {
|
|
78
|
+
const apiKey = props.apiKey.trim();
|
|
79
|
+
if (!apiKey) {
|
|
80
|
+
throw new Error("apiKey is required for createVideoProviderPlatform.");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const maxRetries = props.polling?.maxRetries ?? 20;
|
|
84
|
+
const delayMs = props.polling?.delayMs ?? 3000;
|
|
85
|
+
|
|
86
|
+
const chatWithAI = (
|
|
87
|
+
_userId: string,
|
|
88
|
+
_input: string,
|
|
89
|
+
_context: string,
|
|
90
|
+
_model: string
|
|
91
|
+
): Promise<ChatCompletion> => {
|
|
92
|
+
return Promise.reject(new Error("Not implemented"));
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const synthesizeSpeech = (
|
|
96
|
+
_userId: string,
|
|
97
|
+
_input: string,
|
|
98
|
+
_voice: string,
|
|
99
|
+
_context: string,
|
|
100
|
+
_model: string
|
|
101
|
+
): Promise<SpeechCompletion> => {
|
|
102
|
+
return Promise.reject(new Error("Not implemented"));
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const transcribeSpeech = (
|
|
106
|
+
_userId: string,
|
|
107
|
+
_input: Buffer,
|
|
108
|
+
_context: string,
|
|
109
|
+
_model: string
|
|
110
|
+
): Promise<TextCompletion> => {
|
|
111
|
+
return Promise.reject(new Error("Not implemented"));
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const generateImage = (
|
|
115
|
+
_userId: string,
|
|
116
|
+
_input: string,
|
|
117
|
+
_context: string,
|
|
118
|
+
_model: string
|
|
119
|
+
): Promise<ImageCompletion> => {
|
|
120
|
+
return Promise.reject(new Error("Not implemented"));
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const produceVideo = async (
|
|
124
|
+
requestorId: string,
|
|
125
|
+
prompt: string,
|
|
126
|
+
image: URL,
|
|
127
|
+
_context: string,
|
|
128
|
+
model: string
|
|
129
|
+
): Promise<VideoCompletion> => {
|
|
130
|
+
const startedAt = performance.now();
|
|
131
|
+
|
|
132
|
+
const uploaded = await props.adapter.uploadImage(image, {
|
|
133
|
+
apiKey,
|
|
134
|
+
traceId: crypto.randomUUID(),
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const generated = await props.adapter.generateVideo(
|
|
138
|
+
{
|
|
139
|
+
imageId: uploaded.imageId,
|
|
140
|
+
prompt,
|
|
141
|
+
...props.defaultVideoRequest,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
apiKey,
|
|
145
|
+
traceId: crypto.randomUUID(),
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const videoUrl = await waitForCompletion(
|
|
150
|
+
props.adapter,
|
|
151
|
+
generated.videoId,
|
|
152
|
+
apiKey,
|
|
153
|
+
maxRetries,
|
|
154
|
+
delayMs
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const durationMs = performance.now() - startedAt;
|
|
158
|
+
const base = createCompletionBase("video", model, requestorId, durationMs);
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
...base,
|
|
162
|
+
url: new URL(videoUrl),
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const generateModel = (
|
|
167
|
+
_userId: string,
|
|
168
|
+
_input: string,
|
|
169
|
+
_context: string,
|
|
170
|
+
_model: string
|
|
171
|
+
): Promise<ModelCompletion> => {
|
|
172
|
+
return Promise.reject(new Error("Not implemented"));
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const checkBalance = async (requestorId: string): Promise<BalanceCompletion> => {
|
|
176
|
+
const startedAt = performance.now();
|
|
177
|
+
const providerBalance = props.adapter.getBalance
|
|
178
|
+
? await props.adapter.getBalance({
|
|
179
|
+
apiKey,
|
|
180
|
+
traceId: crypto.randomUUID(),
|
|
181
|
+
})
|
|
182
|
+
: {
|
|
183
|
+
monthlyCredit: 0,
|
|
184
|
+
packageCredit: 0,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const durationMs = performance.now() - startedAt;
|
|
188
|
+
const base = createCompletionBase("balanceCompletion", "", requestorId, durationMs);
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
...base,
|
|
192
|
+
balance: providerBalance.monthlyCredit + providerBalance.packageCredit,
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const currentBalance = (await checkBalance(userId)).balance;
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
chatWithAI,
|
|
200
|
+
synthesizeSpeech,
|
|
201
|
+
transcribeSpeech,
|
|
202
|
+
generateImage,
|
|
203
|
+
produceVideo,
|
|
204
|
+
generateModel,
|
|
205
|
+
checkBalance,
|
|
206
|
+
currentBalance,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
interface PixelverseEditorProps {
|
|
2
|
-
apiKey: string;
|
|
3
|
-
onVideoGenerated?: (videoUrl: string) => void;
|
|
4
|
-
onImageUpload?: (imageUrl: string) => void;
|
|
5
|
-
prompt?: string;
|
|
6
|
-
onPromptChange?: (prompt: string) => void;
|
|
7
|
-
negative_prompt?: string;
|
|
8
|
-
onNegativePromptChange?: (negative_prompt: string) => void;
|
|
9
|
-
template_id?: string;
|
|
10
|
-
onTemplateIdChange?: (template_id: string) => void;
|
|
11
|
-
seed?: number;
|
|
12
|
-
onSeedChange?: (seed: number) => void;
|
|
13
|
-
}
|
|
14
|
-
export declare function PixelverseEditor({ apiKey, onVideoGenerated, prompt, negative_prompt, template_id, seed, }: PixelverseEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=pixelverseeditor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pixelverseeditor.d.ts","sourceRoot":"","sources":["../../../src/components/pixelverse/pixelverseeditor.tsx"],"names":[],"mappings":"AAKA,UAAU,qBAAqB;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,sBAAsB,CAAC,EAAE,CAAC,eAAe,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,MAAM,EACN,gBAAgB,EAChB,MAAM,EACN,eAAe,EACf,WAAW,EACX,IAAI,GACL,EAAE,qBAAqB,2CA+CvB"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import Balance from "./balance.js";
|
|
4
|
-
export function PixelverseEditor({ apiKey, onVideoGenerated, prompt, negative_prompt, template_id, seed, }) {
|
|
5
|
-
const [videoUrl, setVideoUrl] = useState("");
|
|
6
|
-
const [videoId, setVideoId] = useState(null);
|
|
7
|
-
const [selectedFile, setSelectedFile] = useState(null);
|
|
8
|
-
const [loading, setLoading] = useState(false);
|
|
9
|
-
const [videoStatus, setVideoStatus] = useState(0);
|
|
10
|
-
const handleFileChange = (e) => {
|
|
11
|
-
if (e.target.files?.[0]) {
|
|
12
|
-
setSelectedFile(e.target.files[0]);
|
|
13
|
-
handleUploadProcess();
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const handleRegenerate = () => {
|
|
17
|
-
};
|
|
18
|
-
const handleUploadProcess = async () => {
|
|
19
|
-
};
|
|
20
|
-
return (_jsxs("div", { children: [_jsx(Balance, { apiKey: apiKey }), videoStatus === 0 && !selectedFile && (_jsxs("div", { children: [_jsx("p", { children: "Drag/Drop or Click HERE to upload" }), _jsx("input", { title: "Upload Image", type: "file", accept: ".jpg,.jpeg,.png,.webp", onChange: handleFileChange })] })), loading && _jsx("div", { children: "Loading..." }), videoStatus === 0 && selectedFile && (_jsx("button", { onClick: handleUploadProcess, children: "Start Upload" })), videoStatus === 1 && (_jsxs("div", { children: [_jsx("video", { src: videoUrl, controls: true }), _jsx("button", { onClick: handleRegenerate, children: "Regenerate" })] }))] }));
|
|
21
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { AIPlatform } from "./index.js";
|
|
2
|
-
export interface OpenAIPlatformProps {
|
|
3
|
-
openaiAPIKey: string;
|
|
4
|
-
openaiProjectKey: string;
|
|
5
|
-
openaiOrgID: string;
|
|
6
|
-
}
|
|
7
|
-
export declare function OpenAIPlatform(userId: string, props: OpenAIPlatformProps): Promise<AIPlatform>;
|
|
8
|
-
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/platform/openai.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EAQX,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,UAAU,CAAC,CAoGrB"}
|
package/dist/platform/openai.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import OpenAI from "openai";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
export async function OpenAIPlatform(userId, props) {
|
|
4
|
-
const openai = new OpenAI({
|
|
5
|
-
apiKey: props.openaiAPIKey,
|
|
6
|
-
project: props.openaiProjectKey,
|
|
7
|
-
organization: props.openaiOrgID,
|
|
8
|
-
dangerouslyAllowBrowser: false,
|
|
9
|
-
});
|
|
10
|
-
void openai;
|
|
11
|
-
function baseCompletionData(type, model, requestor, duration) {
|
|
12
|
-
return {
|
|
13
|
-
partitionKey: requestor,
|
|
14
|
-
id: crypto.randomUUID(),
|
|
15
|
-
type,
|
|
16
|
-
model,
|
|
17
|
-
createdAt: new Date().toISOString(),
|
|
18
|
-
durationMs: duration,
|
|
19
|
-
usage: {},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
const chatWithAI = (userId, input, context, model) => {
|
|
23
|
-
void [input, context, model];
|
|
24
|
-
const base = baseCompletionData("chat", "model", userId, 0);
|
|
25
|
-
return Promise.resolve({ ...base, message: "Something", outputUser: "" });
|
|
26
|
-
};
|
|
27
|
-
const synthesizeSpeech = (userId, input, voice, context, model) => {
|
|
28
|
-
void [input, voice, context, model];
|
|
29
|
-
const base = baseCompletionData("chat", "model", userId, 0);
|
|
30
|
-
return Promise.resolve({ ...base, url: new URL("Something") });
|
|
31
|
-
};
|
|
32
|
-
const transcribeSpeech = (userId, input, context, model) => {
|
|
33
|
-
void [input, context, model];
|
|
34
|
-
const base = baseCompletionData("chat", "model", userId, 0);
|
|
35
|
-
return Promise.resolve({ ...base, message: "Something" });
|
|
36
|
-
};
|
|
37
|
-
const generateImage = (userId, input, context, model) => {
|
|
38
|
-
void [input, context, model];
|
|
39
|
-
const base = baseCompletionData("chat", "model", userId, 0);
|
|
40
|
-
return Promise.resolve({ ...base, url: new URL("Something") });
|
|
41
|
-
};
|
|
42
|
-
const produceVideo = (userId, imput, image, context, model) => {
|
|
43
|
-
void [imput, image, context, model];
|
|
44
|
-
const base = baseCompletionData("chat", "model", userId, 0);
|
|
45
|
-
return Promise.resolve({ ...base, url: new URL("Something") });
|
|
46
|
-
};
|
|
47
|
-
const checkBalance = (userId) => {
|
|
48
|
-
const base = baseCompletionData("balanceCompletion", "", userId, 0);
|
|
49
|
-
return Promise.resolve({ ...base, balance: 0.0 });
|
|
50
|
-
};
|
|
51
|
-
const [currentBalance] = useState((await checkBalance(userId)).balance);
|
|
52
|
-
return {
|
|
53
|
-
chatWithAI,
|
|
54
|
-
synthesizeSpeech,
|
|
55
|
-
transcribeSpeech,
|
|
56
|
-
generateImage,
|
|
57
|
-
produceVideo,
|
|
58
|
-
checkBalance,
|
|
59
|
-
currentBalance,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { AIPlatform } from "./index.js";
|
|
2
|
-
export interface PixelVersePlatformProps {
|
|
3
|
-
pixelVerseAPIKey: string;
|
|
4
|
-
}
|
|
5
|
-
export declare function PixelVersePlatform(userId: string, props: PixelVersePlatformProps): Promise<AIPlatform>;
|
|
6
|
-
//# sourceMappingURL=pixelverse.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pixelverse.d.ts","sourceRoot":"","sources":["../../src/platform/pixelverse.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,UAAU,EAQX,MAAM,YAAY,CAAC;AAmBpB,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,UAAU,CAAC,CA8QrB"}
|