@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
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { v4 as uuidv4 } from "uuid";
|
|
2
|
-
import { performance } from "perf_hooks";
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
export async function PixelVersePlatform(userId, props) {
|
|
5
|
-
async function uploadImage(image, apiKey) {
|
|
6
|
-
const headers = new Headers();
|
|
7
|
-
headers.append("API-KEY", apiKey);
|
|
8
|
-
headers.append("Ai-trace-id", uuidv4());
|
|
9
|
-
headers.append("Access-Control-Allow-Origin", "*");
|
|
10
|
-
const formData = new FormData();
|
|
11
|
-
if (image instanceof File) {
|
|
12
|
-
formData.append("image", image, "");
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
const blob = await fetch(image.toString()).then((r) => r.blob());
|
|
16
|
-
formData.append("image", blob, "image-from-url");
|
|
17
|
-
}
|
|
18
|
-
// pixelapi is proxied through the vite.config.ts file
|
|
19
|
-
// to avoid CORS issues and to allow for local development
|
|
20
|
-
const response = await fetch("/pixelapi/openapi/v2/image/upload", {
|
|
21
|
-
method: "POST",
|
|
22
|
-
headers,
|
|
23
|
-
body: formData,
|
|
24
|
-
redirect: "follow",
|
|
25
|
-
});
|
|
26
|
-
const data = (await response.json());
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
async function generateVideo(imgId, prompt, apiKey, seed, template_id, negative_prompt) {
|
|
30
|
-
const headers = new Headers();
|
|
31
|
-
headers.append("API-KEY", apiKey);
|
|
32
|
-
headers.append("Ai-trace-id", uuidv4());
|
|
33
|
-
headers.append("Content-Type", "application/json");
|
|
34
|
-
headers.append("Access-Control-Allow-Origin", "*");
|
|
35
|
-
headers.append("Accept", "application/json");
|
|
36
|
-
const values = {
|
|
37
|
-
duration: 5,
|
|
38
|
-
img_id: imgId,
|
|
39
|
-
model: "v3.5",
|
|
40
|
-
motion_mode: "normal",
|
|
41
|
-
prompt: prompt,
|
|
42
|
-
quality: "720p",
|
|
43
|
-
water_mark: false,
|
|
44
|
-
};
|
|
45
|
-
if (seed) {
|
|
46
|
-
values.seed = seed;
|
|
47
|
-
}
|
|
48
|
-
if (template_id) {
|
|
49
|
-
values.template_id = template_id;
|
|
50
|
-
}
|
|
51
|
-
if (negative_prompt) {
|
|
52
|
-
values.negative_prompt = negative_prompt;
|
|
53
|
-
}
|
|
54
|
-
const body = JSON.stringify(values);
|
|
55
|
-
// pixelapi is proxied through the vite.config.ts file
|
|
56
|
-
// to avoid CORS issues and to allow for local development
|
|
57
|
-
const response = await fetch("/pixelapi/openapi/v2/video/img/generate", {
|
|
58
|
-
method: "POST",
|
|
59
|
-
headers: headers,
|
|
60
|
-
referrerPolicy: "no-referrer",
|
|
61
|
-
body,
|
|
62
|
-
});
|
|
63
|
-
const data = (await response.json());
|
|
64
|
-
return data;
|
|
65
|
-
}
|
|
66
|
-
async function checkVideoStatus(id, apiKey) {
|
|
67
|
-
const headers = new Headers();
|
|
68
|
-
headers.append("API-KEY", apiKey);
|
|
69
|
-
headers.append("Ai-trace-id", uuidv4());
|
|
70
|
-
headers.append("Access-Control-Allow-Origin", "*");
|
|
71
|
-
headers.append("Accept", "application/json");
|
|
72
|
-
// pixelapi is proxied through the vite.config.ts file
|
|
73
|
-
// to avoid CORS issues and to allow for local development
|
|
74
|
-
const response = await fetch(`/pixelapi/openapi/v2/video/result/${id}`, {
|
|
75
|
-
method: "GET",
|
|
76
|
-
headers,
|
|
77
|
-
referrerPolicy: "no-referrer",
|
|
78
|
-
});
|
|
79
|
-
const data = (await response.json());
|
|
80
|
-
return data;
|
|
81
|
-
}
|
|
82
|
-
function baseCompletionData(type, model, requestor, duration) {
|
|
83
|
-
return {
|
|
84
|
-
partitionKey: requestor,
|
|
85
|
-
id: crypto.randomUUID(),
|
|
86
|
-
type,
|
|
87
|
-
model,
|
|
88
|
-
createdAt: new Date().toISOString(),
|
|
89
|
-
durationMs: duration,
|
|
90
|
-
usage: {},
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
const chatWithAI = (_userId, _input, _context, _model) => {
|
|
94
|
-
void [_userId, _input, _context, _model];
|
|
95
|
-
return Promise.reject(new Error("Not implemented"));
|
|
96
|
-
};
|
|
97
|
-
const synthesizeSpeech = (_userId, _input, _voice, _context, _model) => {
|
|
98
|
-
void [_userId, _input, _voice, _context, _model];
|
|
99
|
-
return Promise.reject(new Error("Not implemented"));
|
|
100
|
-
};
|
|
101
|
-
const transcribeSpeech = (_userId, _input, _context, _model) => {
|
|
102
|
-
void [_userId, _input, _context, _model];
|
|
103
|
-
return Promise.reject(new Error("Not implemented"));
|
|
104
|
-
};
|
|
105
|
-
const generateImage = (_userId, _input, _context, _model) => {
|
|
106
|
-
void [_userId, _input, _context, _model];
|
|
107
|
-
return Promise.reject(new Error("Not implemented"));
|
|
108
|
-
};
|
|
109
|
-
const produceVideo = (userId, input, image, context, model) => {
|
|
110
|
-
const start = performance.now();
|
|
111
|
-
return uploadImage(image, props.pixelVerseAPIKey)
|
|
112
|
-
.then((uploadResult) => {
|
|
113
|
-
const imageId = uploadResult?.Resp?.id;
|
|
114
|
-
if (!imageId)
|
|
115
|
-
throw new Error("Invalid image upload response.");
|
|
116
|
-
return generateVideo(imageId, input, props.pixelVerseAPIKey);
|
|
117
|
-
})
|
|
118
|
-
.then((generated) => {
|
|
119
|
-
const videoId = generated?.Resp?.id;
|
|
120
|
-
if (!videoId)
|
|
121
|
-
throw new Error("Video generation did not return a valid ID.");
|
|
122
|
-
return waitForVideoCompletion(videoId, props.pixelVerseAPIKey);
|
|
123
|
-
})
|
|
124
|
-
.then((videoUrl) => {
|
|
125
|
-
const duration = performance.now() - start;
|
|
126
|
-
const base = baseCompletionData("video", model, userId, duration);
|
|
127
|
-
return {
|
|
128
|
-
...base,
|
|
129
|
-
url: new URL(videoUrl),
|
|
130
|
-
};
|
|
131
|
-
})
|
|
132
|
-
.catch((err) => {
|
|
133
|
-
// Optional: log or re-throw error for upstream handling
|
|
134
|
-
throw new Error(`produceVideo failed: ${err.message}`);
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
async function waitForVideoCompletion(videoId, apiKey, maxRetries = 20, delayMs = 3000) {
|
|
138
|
-
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
139
|
-
await new Promise((res) => setTimeout(res, delayMs));
|
|
140
|
-
try {
|
|
141
|
-
const videoCheck = await checkVideoStatus(videoId, apiKey);
|
|
142
|
-
if (videoCheck?.Resp?.status === 1) {
|
|
143
|
-
const url = videoCheck?.Resp?.url;
|
|
144
|
-
if (!url)
|
|
145
|
-
throw new Error("Video marked complete but no URL returned.");
|
|
146
|
-
return url;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
catch (err) {
|
|
150
|
-
console.warn(`Attempt ${attempt + 1} failed: ${err.message}`);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
throw new Error("Timed out waiting for video to complete.");
|
|
154
|
-
}
|
|
155
|
-
const checkBalance = (userId) => {
|
|
156
|
-
const start = performance.now();
|
|
157
|
-
const headers = new Headers();
|
|
158
|
-
headers.append("API-KEY", props.pixelVerseAPIKey);
|
|
159
|
-
headers.append("AI-trace-ID", uuidv4());
|
|
160
|
-
headers.append("Access-Control-Allow-Origin", "*");
|
|
161
|
-
headers.append("Accept", "application/json");
|
|
162
|
-
headers.append("Content-Type", "application/json");
|
|
163
|
-
return fetch("/pixelapi/openapi/v2/account/balance", {
|
|
164
|
-
method: "GET",
|
|
165
|
-
headers,
|
|
166
|
-
referrerPolicy: "no-referrer",
|
|
167
|
-
})
|
|
168
|
-
.then(async (res) => (await res.json()))
|
|
169
|
-
.then((data) => {
|
|
170
|
-
if (!data?.Resp) {
|
|
171
|
-
throw new Error("Invalid balance response");
|
|
172
|
-
}
|
|
173
|
-
const duration = performance.now() - start;
|
|
174
|
-
const base = baseCompletionData("balanceCompletion", "", userId, duration);
|
|
175
|
-
const monthly = data.Resp.credit_monthly ?? 0;
|
|
176
|
-
const pkg = data.Resp.credit_package ?? 0;
|
|
177
|
-
return {
|
|
178
|
-
...base,
|
|
179
|
-
balance: monthly + pkg,
|
|
180
|
-
};
|
|
181
|
-
})
|
|
182
|
-
.catch((err) => {
|
|
183
|
-
throw new Error(`checkBalance failed: ${err.message}`);
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
const [currentBalance] = useState((await checkBalance(userId)).balance ?? 0);
|
|
187
|
-
return {
|
|
188
|
-
chatWithAI,
|
|
189
|
-
synthesizeSpeech,
|
|
190
|
-
transcribeSpeech,
|
|
191
|
-
generateImage,
|
|
192
|
-
produceVideo,
|
|
193
|
-
checkBalance,
|
|
194
|
-
currentBalance,
|
|
195
|
-
};
|
|
196
|
-
}
|
|
@@ -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,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PixelverseEditor = PixelverseEditor;
|
|
7
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
-
const react_1 = require("react");
|
|
9
|
-
const balance_js_1 = __importDefault(require("./balance.js"));
|
|
10
|
-
function PixelverseEditor({ apiKey, onVideoGenerated, prompt, negative_prompt, template_id, seed, }) {
|
|
11
|
-
const [videoUrl, setVideoUrl] = (0, react_1.useState)("");
|
|
12
|
-
const [videoId, setVideoId] = (0, react_1.useState)(null);
|
|
13
|
-
const [selectedFile, setSelectedFile] = (0, react_1.useState)(null);
|
|
14
|
-
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
15
|
-
const [videoStatus, setVideoStatus] = (0, react_1.useState)(0);
|
|
16
|
-
const handleFileChange = (e) => {
|
|
17
|
-
if (e.target.files?.[0]) {
|
|
18
|
-
setSelectedFile(e.target.files[0]);
|
|
19
|
-
handleUploadProcess();
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const handleRegenerate = () => {
|
|
23
|
-
};
|
|
24
|
-
const handleUploadProcess = async () => {
|
|
25
|
-
};
|
|
26
|
-
return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(balance_js_1.default, { apiKey: apiKey }), videoStatus === 0 && !selectedFile && ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("p", { children: "Drag/Drop or Click HERE to upload" }), (0, jsx_runtime_1.jsx)("input", { title: "Upload Image", type: "file", accept: ".jpg,.jpeg,.png,.webp", onChange: handleFileChange })] })), loading && (0, jsx_runtime_1.jsx)("div", { children: "Loading..." }), videoStatus === 0 && selectedFile && ((0, jsx_runtime_1.jsx)("button", { onClick: handleUploadProcess, children: "Start Upload" })), videoStatus === 1 && ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("video", { src: videoUrl, controls: true }), (0, jsx_runtime_1.jsx)("button", { onClick: handleRegenerate, children: "Regenerate" })] }))] }));
|
|
27
|
-
}
|
|
@@ -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"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.OpenAIPlatform = OpenAIPlatform;
|
|
7
|
-
const openai_1 = __importDefault(require("openai"));
|
|
8
|
-
const react_1 = require("react");
|
|
9
|
-
async function OpenAIPlatform(userId, props) {
|
|
10
|
-
const openai = new openai_1.default({
|
|
11
|
-
apiKey: props.openaiAPIKey,
|
|
12
|
-
project: props.openaiProjectKey,
|
|
13
|
-
organization: props.openaiOrgID,
|
|
14
|
-
dangerouslyAllowBrowser: false,
|
|
15
|
-
});
|
|
16
|
-
void openai;
|
|
17
|
-
function baseCompletionData(type, model, requestor, duration) {
|
|
18
|
-
return {
|
|
19
|
-
partitionKey: requestor,
|
|
20
|
-
id: crypto.randomUUID(),
|
|
21
|
-
type,
|
|
22
|
-
model,
|
|
23
|
-
createdAt: new Date().toISOString(),
|
|
24
|
-
durationMs: duration,
|
|
25
|
-
usage: {},
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
const chatWithAI = (userId, input, context, model) => {
|
|
29
|
-
void [input, context, model];
|
|
30
|
-
const base = baseCompletionData("chat", "model", userId, 0);
|
|
31
|
-
return Promise.resolve({ ...base, message: "Something", outputUser: "" });
|
|
32
|
-
};
|
|
33
|
-
const synthesizeSpeech = (userId, input, voice, context, model) => {
|
|
34
|
-
void [input, voice, context, model];
|
|
35
|
-
const base = baseCompletionData("chat", "model", userId, 0);
|
|
36
|
-
return Promise.resolve({ ...base, url: new URL("Something") });
|
|
37
|
-
};
|
|
38
|
-
const transcribeSpeech = (userId, input, context, model) => {
|
|
39
|
-
void [input, context, model];
|
|
40
|
-
const base = baseCompletionData("chat", "model", userId, 0);
|
|
41
|
-
return Promise.resolve({ ...base, message: "Something" });
|
|
42
|
-
};
|
|
43
|
-
const generateImage = (userId, input, context, model) => {
|
|
44
|
-
void [input, context, model];
|
|
45
|
-
const base = baseCompletionData("chat", "model", userId, 0);
|
|
46
|
-
return Promise.resolve({ ...base, url: new URL("Something") });
|
|
47
|
-
};
|
|
48
|
-
const produceVideo = (userId, imput, image, context, model) => {
|
|
49
|
-
void [imput, image, context, model];
|
|
50
|
-
const base = baseCompletionData("chat", "model", userId, 0);
|
|
51
|
-
return Promise.resolve({ ...base, url: new URL("Something") });
|
|
52
|
-
};
|
|
53
|
-
const checkBalance = (userId) => {
|
|
54
|
-
const base = baseCompletionData("balanceCompletion", "", userId, 0);
|
|
55
|
-
return Promise.resolve({ ...base, balance: 0.0 });
|
|
56
|
-
};
|
|
57
|
-
const [currentBalance] = (0, react_1.useState)((await checkBalance(userId)).balance);
|
|
58
|
-
return {
|
|
59
|
-
chatWithAI,
|
|
60
|
-
synthesizeSpeech,
|
|
61
|
-
transcribeSpeech,
|
|
62
|
-
generateImage,
|
|
63
|
-
produceVideo,
|
|
64
|
-
checkBalance,
|
|
65
|
-
currentBalance,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
@@ -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"}
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PixelVersePlatform = PixelVersePlatform;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
|
-
const perf_hooks_1 = require("perf_hooks");
|
|
6
|
-
const react_1 = require("react");
|
|
7
|
-
async function PixelVersePlatform(userId, props) {
|
|
8
|
-
async function uploadImage(image, apiKey) {
|
|
9
|
-
const headers = new Headers();
|
|
10
|
-
headers.append("API-KEY", apiKey);
|
|
11
|
-
headers.append("Ai-trace-id", (0, uuid_1.v4)());
|
|
12
|
-
headers.append("Access-Control-Allow-Origin", "*");
|
|
13
|
-
const formData = new FormData();
|
|
14
|
-
if (image instanceof File) {
|
|
15
|
-
formData.append("image", image, "");
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
const blob = await fetch(image.toString()).then((r) => r.blob());
|
|
19
|
-
formData.append("image", blob, "image-from-url");
|
|
20
|
-
}
|
|
21
|
-
// pixelapi is proxied through the vite.config.ts file
|
|
22
|
-
// to avoid CORS issues and to allow for local development
|
|
23
|
-
const response = await fetch("/pixelapi/openapi/v2/image/upload", {
|
|
24
|
-
method: "POST",
|
|
25
|
-
headers,
|
|
26
|
-
body: formData,
|
|
27
|
-
redirect: "follow",
|
|
28
|
-
});
|
|
29
|
-
const data = (await response.json());
|
|
30
|
-
return data;
|
|
31
|
-
}
|
|
32
|
-
async function generateVideo(imgId, prompt, apiKey, seed, template_id, negative_prompt) {
|
|
33
|
-
const headers = new Headers();
|
|
34
|
-
headers.append("API-KEY", apiKey);
|
|
35
|
-
headers.append("Ai-trace-id", (0, uuid_1.v4)());
|
|
36
|
-
headers.append("Content-Type", "application/json");
|
|
37
|
-
headers.append("Access-Control-Allow-Origin", "*");
|
|
38
|
-
headers.append("Accept", "application/json");
|
|
39
|
-
const values = {
|
|
40
|
-
duration: 5,
|
|
41
|
-
img_id: imgId,
|
|
42
|
-
model: "v3.5",
|
|
43
|
-
motion_mode: "normal",
|
|
44
|
-
prompt: prompt,
|
|
45
|
-
quality: "720p",
|
|
46
|
-
water_mark: false,
|
|
47
|
-
};
|
|
48
|
-
if (seed) {
|
|
49
|
-
values.seed = seed;
|
|
50
|
-
}
|
|
51
|
-
if (template_id) {
|
|
52
|
-
values.template_id = template_id;
|
|
53
|
-
}
|
|
54
|
-
if (negative_prompt) {
|
|
55
|
-
values.negative_prompt = negative_prompt;
|
|
56
|
-
}
|
|
57
|
-
const body = JSON.stringify(values);
|
|
58
|
-
// pixelapi is proxied through the vite.config.ts file
|
|
59
|
-
// to avoid CORS issues and to allow for local development
|
|
60
|
-
const response = await fetch("/pixelapi/openapi/v2/video/img/generate", {
|
|
61
|
-
method: "POST",
|
|
62
|
-
headers: headers,
|
|
63
|
-
referrerPolicy: "no-referrer",
|
|
64
|
-
body,
|
|
65
|
-
});
|
|
66
|
-
const data = (await response.json());
|
|
67
|
-
return data;
|
|
68
|
-
}
|
|
69
|
-
async function checkVideoStatus(id, apiKey) {
|
|
70
|
-
const headers = new Headers();
|
|
71
|
-
headers.append("API-KEY", apiKey);
|
|
72
|
-
headers.append("Ai-trace-id", (0, uuid_1.v4)());
|
|
73
|
-
headers.append("Access-Control-Allow-Origin", "*");
|
|
74
|
-
headers.append("Accept", "application/json");
|
|
75
|
-
// pixelapi is proxied through the vite.config.ts file
|
|
76
|
-
// to avoid CORS issues and to allow for local development
|
|
77
|
-
const response = await fetch(`/pixelapi/openapi/v2/video/result/${id}`, {
|
|
78
|
-
method: "GET",
|
|
79
|
-
headers,
|
|
80
|
-
referrerPolicy: "no-referrer",
|
|
81
|
-
});
|
|
82
|
-
const data = (await response.json());
|
|
83
|
-
return data;
|
|
84
|
-
}
|
|
85
|
-
function baseCompletionData(type, model, requestor, duration) {
|
|
86
|
-
return {
|
|
87
|
-
partitionKey: requestor,
|
|
88
|
-
id: crypto.randomUUID(),
|
|
89
|
-
type,
|
|
90
|
-
model,
|
|
91
|
-
createdAt: new Date().toISOString(),
|
|
92
|
-
durationMs: duration,
|
|
93
|
-
usage: {},
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
const chatWithAI = (_userId, _input, _context, _model) => {
|
|
97
|
-
void [_userId, _input, _context, _model];
|
|
98
|
-
return Promise.reject(new Error("Not implemented"));
|
|
99
|
-
};
|
|
100
|
-
const synthesizeSpeech = (_userId, _input, _voice, _context, _model) => {
|
|
101
|
-
void [_userId, _input, _voice, _context, _model];
|
|
102
|
-
return Promise.reject(new Error("Not implemented"));
|
|
103
|
-
};
|
|
104
|
-
const transcribeSpeech = (_userId, _input, _context, _model) => {
|
|
105
|
-
void [_userId, _input, _context, _model];
|
|
106
|
-
return Promise.reject(new Error("Not implemented"));
|
|
107
|
-
};
|
|
108
|
-
const generateImage = (_userId, _input, _context, _model) => {
|
|
109
|
-
void [_userId, _input, _context, _model];
|
|
110
|
-
return Promise.reject(new Error("Not implemented"));
|
|
111
|
-
};
|
|
112
|
-
const produceVideo = (userId, input, image, context, model) => {
|
|
113
|
-
const start = perf_hooks_1.performance.now();
|
|
114
|
-
return uploadImage(image, props.pixelVerseAPIKey)
|
|
115
|
-
.then((uploadResult) => {
|
|
116
|
-
const imageId = uploadResult?.Resp?.id;
|
|
117
|
-
if (!imageId)
|
|
118
|
-
throw new Error("Invalid image upload response.");
|
|
119
|
-
return generateVideo(imageId, input, props.pixelVerseAPIKey);
|
|
120
|
-
})
|
|
121
|
-
.then((generated) => {
|
|
122
|
-
const videoId = generated?.Resp?.id;
|
|
123
|
-
if (!videoId)
|
|
124
|
-
throw new Error("Video generation did not return a valid ID.");
|
|
125
|
-
return waitForVideoCompletion(videoId, props.pixelVerseAPIKey);
|
|
126
|
-
})
|
|
127
|
-
.then((videoUrl) => {
|
|
128
|
-
const duration = perf_hooks_1.performance.now() - start;
|
|
129
|
-
const base = baseCompletionData("video", model, userId, duration);
|
|
130
|
-
return {
|
|
131
|
-
...base,
|
|
132
|
-
url: new URL(videoUrl),
|
|
133
|
-
};
|
|
134
|
-
})
|
|
135
|
-
.catch((err) => {
|
|
136
|
-
// Optional: log or re-throw error for upstream handling
|
|
137
|
-
throw new Error(`produceVideo failed: ${err.message}`);
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
async function waitForVideoCompletion(videoId, apiKey, maxRetries = 20, delayMs = 3000) {
|
|
141
|
-
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
142
|
-
await new Promise((res) => setTimeout(res, delayMs));
|
|
143
|
-
try {
|
|
144
|
-
const videoCheck = await checkVideoStatus(videoId, apiKey);
|
|
145
|
-
if (videoCheck?.Resp?.status === 1) {
|
|
146
|
-
const url = videoCheck?.Resp?.url;
|
|
147
|
-
if (!url)
|
|
148
|
-
throw new Error("Video marked complete but no URL returned.");
|
|
149
|
-
return url;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
catch (err) {
|
|
153
|
-
console.warn(`Attempt ${attempt + 1} failed: ${err.message}`);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
throw new Error("Timed out waiting for video to complete.");
|
|
157
|
-
}
|
|
158
|
-
const checkBalance = (userId) => {
|
|
159
|
-
const start = perf_hooks_1.performance.now();
|
|
160
|
-
const headers = new Headers();
|
|
161
|
-
headers.append("API-KEY", props.pixelVerseAPIKey);
|
|
162
|
-
headers.append("AI-trace-ID", (0, uuid_1.v4)());
|
|
163
|
-
headers.append("Access-Control-Allow-Origin", "*");
|
|
164
|
-
headers.append("Accept", "application/json");
|
|
165
|
-
headers.append("Content-Type", "application/json");
|
|
166
|
-
return fetch("/pixelapi/openapi/v2/account/balance", {
|
|
167
|
-
method: "GET",
|
|
168
|
-
headers,
|
|
169
|
-
referrerPolicy: "no-referrer",
|
|
170
|
-
})
|
|
171
|
-
.then(async (res) => (await res.json()))
|
|
172
|
-
.then((data) => {
|
|
173
|
-
if (!data?.Resp) {
|
|
174
|
-
throw new Error("Invalid balance response");
|
|
175
|
-
}
|
|
176
|
-
const duration = perf_hooks_1.performance.now() - start;
|
|
177
|
-
const base = baseCompletionData("balanceCompletion", "", userId, duration);
|
|
178
|
-
const monthly = data.Resp.credit_monthly ?? 0;
|
|
179
|
-
const pkg = data.Resp.credit_package ?? 0;
|
|
180
|
-
return {
|
|
181
|
-
...base,
|
|
182
|
-
balance: monthly + pkg,
|
|
183
|
-
};
|
|
184
|
-
})
|
|
185
|
-
.catch((err) => {
|
|
186
|
-
throw new Error(`checkBalance failed: ${err.message}`);
|
|
187
|
-
});
|
|
188
|
-
};
|
|
189
|
-
const [currentBalance] = (0, react_1.useState)((await checkBalance(userId)).balance ?? 0);
|
|
190
|
-
return {
|
|
191
|
-
chatWithAI,
|
|
192
|
-
synthesizeSpeech,
|
|
193
|
-
transcribeSpeech,
|
|
194
|
-
generateImage,
|
|
195
|
-
produceVideo,
|
|
196
|
-
checkBalance,
|
|
197
|
-
currentBalance,
|
|
198
|
-
};
|
|
199
|
-
}
|
|
File without changes
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import React, { useState } from "react";
|
|
2
|
-
import Balance from "./balance.js";
|
|
3
|
-
|
|
4
|
-
// --- Pixelverse API Calls ---
|
|
5
|
-
|
|
6
|
-
interface PixelverseEditorProps {
|
|
7
|
-
apiKey: string;
|
|
8
|
-
onVideoGenerated?: (videoUrl: string) => void;
|
|
9
|
-
onImageUpload?: (imageUrl: string) => void;
|
|
10
|
-
prompt?: string;
|
|
11
|
-
onPromptChange?: (prompt: string) => void;
|
|
12
|
-
negative_prompt?: string;
|
|
13
|
-
onNegativePromptChange?: (negative_prompt: string) => void;
|
|
14
|
-
template_id?: string;
|
|
15
|
-
onTemplateIdChange?: (template_id: string) => void;
|
|
16
|
-
seed?: number;
|
|
17
|
-
onSeedChange?: (seed: number) => void;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function PixelverseEditor({
|
|
21
|
-
apiKey,
|
|
22
|
-
onVideoGenerated,
|
|
23
|
-
prompt,
|
|
24
|
-
negative_prompt,
|
|
25
|
-
template_id,
|
|
26
|
-
seed,
|
|
27
|
-
}: PixelverseEditorProps) {
|
|
28
|
-
const [videoUrl, setVideoUrl] = useState("");
|
|
29
|
-
const [videoId, setVideoId] = useState<number | null>(null);
|
|
30
|
-
const [selectedFile, setSelectedFile] = useState<File | null>(null);
|
|
31
|
-
const [loading, setLoading] = useState(false);
|
|
32
|
-
const [videoStatus, setVideoStatus] = useState<number>(0);
|
|
33
|
-
|
|
34
|
-
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
35
|
-
if (e.target.files?.[0]) {
|
|
36
|
-
setSelectedFile(e.target.files[0]);
|
|
37
|
-
handleUploadProcess();
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const handleRegenerate = () => {
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const handleUploadProcess = async () => {
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<div>
|
|
50
|
-
<Balance apiKey={apiKey} />
|
|
51
|
-
{videoStatus === 0 && !selectedFile && (
|
|
52
|
-
<div>
|
|
53
|
-
<p>Drag/Drop or Click HERE to upload</p>
|
|
54
|
-
<input
|
|
55
|
-
title="Upload Image"
|
|
56
|
-
type="file"
|
|
57
|
-
accept=".jpg,.jpeg,.png,.webp"
|
|
58
|
-
onChange={handleFileChange}
|
|
59
|
-
/>
|
|
60
|
-
</div>
|
|
61
|
-
)}
|
|
62
|
-
{loading && <div>Loading...</div>}
|
|
63
|
-
{videoStatus === 0 && selectedFile && (
|
|
64
|
-
<button onClick={handleUploadProcess}>Start Upload</button>
|
|
65
|
-
)}
|
|
66
|
-
{videoStatus === 1 && (
|
|
67
|
-
<div>
|
|
68
|
-
<video src={videoUrl} controls />
|
|
69
|
-
<button onClick={handleRegenerate}>Regenerate</button>
|
|
70
|
-
</div>
|
|
71
|
-
)}
|
|
72
|
-
</div>
|
|
73
|
-
);
|
|
74
|
-
}
|