@umituz/web-ai 1.0.2 → 1.0.3
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/dist/{text-generation.service-CcYQM6Ch.d.ts → cancellation-error-CKcZRhFg.d.ts} +64 -1
- package/dist/{text-generation.service-BQO3Tvz2.d.cts → cancellation-error-DwHrDKBz.d.cts} +64 -1
- package/dist/content/index.cjs +798 -27
- package/dist/content/index.cjs.map +1 -1
- package/dist/content/index.js +798 -27
- package/dist/content/index.js.map +1 -1
- package/dist/hooks/index.cjs +922 -31
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +38 -2
- package/dist/hooks/index.d.ts +38 -2
- package/dist/hooks/index.js +919 -32
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +809 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +800 -28
- package/dist/index.js.map +1 -1
- package/dist/providers/index.cjs +809 -27
- package/dist/providers/index.cjs.map +1 -1
- package/dist/providers/index.d.cts +43 -3
- package/dist/providers/index.d.ts +43 -3
- package/dist/providers/index.js +800 -28
- package/dist/providers/index.js.map +1 -1
- package/package.json +6 -1
package/dist/providers/index.js
CHANGED
|
@@ -2553,39 +2553,811 @@ function createFalProvider(config) {
|
|
|
2553
2553
|
return new FalProvider(config);
|
|
2554
2554
|
}
|
|
2555
2555
|
|
|
2556
|
-
// src/providers/pruna/
|
|
2557
|
-
var
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2556
|
+
// src/providers/pruna/client/core/constants/limits.ts
|
|
2557
|
+
var DEFAULT_ASPECT_RATIO = "16:9";
|
|
2558
|
+
var P_VIDEO_DEFAULTS = {
|
|
2559
|
+
duration: 5,
|
|
2560
|
+
resolution: "720p",
|
|
2561
|
+
fps: 24,
|
|
2562
|
+
draft: false,
|
|
2563
|
+
promptUpsampling: true
|
|
2564
|
+
};
|
|
2565
|
+
var POLL_DEFAULTS = {
|
|
2566
|
+
intervalMs: 3e3,
|
|
2567
|
+
maxAttempts: 120,
|
|
2568
|
+
maxIntervalMs: 1e4,
|
|
2569
|
+
backoffBase: 1.5,
|
|
2570
|
+
jitterPercent: 0.1
|
|
2571
|
+
};
|
|
2572
|
+
var DEFAULT_DEDUPLICATOR_TTL_MS = 3e4;
|
|
2573
|
+
var DEDUPLICATOR_CLEANUP_GRACE_MS = 100;
|
|
2574
|
+
|
|
2575
|
+
// src/providers/pruna/client/core/constants/network.ts
|
|
2576
|
+
var HTTPS_PREFIX = "https://";
|
|
2577
|
+
var HTTP_PREFIX = "http://";
|
|
2578
|
+
var BASE64_MARKER = "base64,";
|
|
2579
|
+
var PRUNA_BASE_URL = "https://api.pruna.ai";
|
|
2580
|
+
var PRUNA_PREDICTIONS_URL = `${PRUNA_BASE_URL}/v1/predictions`;
|
|
2581
|
+
var PRUNA_FILES_URL = `${PRUNA_BASE_URL}/v1/files`;
|
|
2582
|
+
var AUTH_FAILURE_STATUSES = [401, 403];
|
|
2583
|
+
var MIN_API_KEY_LENGTH = 1;
|
|
2584
|
+
var MAX_API_KEY_LENGTH = 256;
|
|
2585
|
+
|
|
2586
|
+
// src/providers/pruna/client/core/constants/mime-types.ts
|
|
2587
|
+
var MIME_PNG = "image/png";
|
|
2588
|
+
var MIME_JPEG = "image/jpeg";
|
|
2589
|
+
var MIME_WEBP = "image/webp";
|
|
2590
|
+
var DEFAULT_IMAGE_MIME = MIME_PNG;
|
|
2591
|
+
var MIME_FILE_EXTENSION = {
|
|
2592
|
+
[MIME_PNG]: "png",
|
|
2593
|
+
[MIME_JPEG]: "jpg",
|
|
2594
|
+
[MIME_WEBP]: "webp"
|
|
2595
|
+
};
|
|
2596
|
+
var IMAGE_SIGNATURES = {
|
|
2597
|
+
PNG: [137, 80],
|
|
2598
|
+
JPEG: [255, 216],
|
|
2599
|
+
WEBP_RIFF: [82, 73]
|
|
2600
|
+
};
|
|
2601
|
+
|
|
2602
|
+
// src/providers/pruna/client/core/errors/cancellation-error.ts
|
|
2603
|
+
var CANCELLATION_MESSAGE = "Request cancelled by user";
|
|
2604
|
+
var CancellationError = class extends Error {
|
|
2605
|
+
constructor(message = CANCELLATION_MESSAGE) {
|
|
2606
|
+
super(message);
|
|
2607
|
+
this.name = "CancellationError";
|
|
2608
|
+
}
|
|
2609
|
+
};
|
|
2610
|
+
|
|
2611
|
+
// src/providers/pruna/client/core/errors/authentication-error.ts
|
|
2612
|
+
var AUTHENTICATION_MESSAGE = "Authentication failed. Please check your API key.";
|
|
2613
|
+
var AuthenticationError = class extends Error {
|
|
2614
|
+
constructor(message = AUTHENTICATION_MESSAGE) {
|
|
2615
|
+
super(message);
|
|
2616
|
+
this.name = "AuthenticationError";
|
|
2617
|
+
}
|
|
2618
|
+
};
|
|
2619
|
+
|
|
2620
|
+
// src/providers/pruna/client/core/errors/timeout-error.ts
|
|
2621
|
+
var TIMEOUT_MESSAGE = "Generation timed out. Maximum polling attempts reached.";
|
|
2622
|
+
var TimeoutError = class extends Error {
|
|
2623
|
+
constructor(message = TIMEOUT_MESSAGE) {
|
|
2624
|
+
super(message);
|
|
2625
|
+
this.name = "TimeoutError";
|
|
2562
2626
|
}
|
|
2563
|
-
|
|
2627
|
+
};
|
|
2628
|
+
|
|
2629
|
+
// src/providers/pruna/client/core/errors/validation-error.ts
|
|
2630
|
+
var ValidationError = class extends Error {
|
|
2631
|
+
field;
|
|
2632
|
+
reason;
|
|
2633
|
+
receivedValue;
|
|
2634
|
+
constructor(context) {
|
|
2635
|
+
super(`Invalid ${context.field}: ${context.reason}`);
|
|
2636
|
+
this.name = "ValidationError";
|
|
2637
|
+
this.field = context.field;
|
|
2638
|
+
this.reason = context.reason;
|
|
2639
|
+
this.receivedValue = context.receivedValue;
|
|
2640
|
+
}
|
|
2641
|
+
};
|
|
2642
|
+
|
|
2643
|
+
// src/providers/pruna/client/core/utils/base64.ts
|
|
2644
|
+
var globalScope = globalThis;
|
|
2645
|
+
var hasBuffer = typeof globalScope.Buffer?.from === "function";
|
|
2646
|
+
function base64ToBytes(raw) {
|
|
2647
|
+
if (hasBuffer) {
|
|
2648
|
+
const bufferFactory = globalScope.Buffer;
|
|
2649
|
+
if (!bufferFactory) {
|
|
2650
|
+
throw new Error("Buffer unavailable despite detection flag");
|
|
2651
|
+
}
|
|
2652
|
+
const buf = bufferFactory.from(raw, "base64");
|
|
2653
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
2654
|
+
}
|
|
2655
|
+
const decoded = atob(raw);
|
|
2656
|
+
return Uint8Array.from(decoded, (char) => char.charCodeAt(0));
|
|
2564
2657
|
}
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
if (
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2658
|
+
|
|
2659
|
+
// src/providers/pruna/client/core/utils/mime-detector.ts
|
|
2660
|
+
var MIN_SIGNATURE_BYTES = 2;
|
|
2661
|
+
function matchesSignature(bytes, signature) {
|
|
2662
|
+
if (bytes.length < signature.length) return false;
|
|
2663
|
+
return signature.every((value, index) => bytes[index] === value);
|
|
2664
|
+
}
|
|
2665
|
+
function detectImageMime(bytes) {
|
|
2666
|
+
if (bytes.length < MIN_SIGNATURE_BYTES) return DEFAULT_IMAGE_MIME;
|
|
2667
|
+
if (matchesSignature(bytes, IMAGE_SIGNATURES.PNG)) return MIME_PNG;
|
|
2668
|
+
if (matchesSignature(bytes, IMAGE_SIGNATURES.JPEG)) return MIME_JPEG;
|
|
2669
|
+
if (matchesSignature(bytes, IMAGE_SIGNATURES.WEBP_RIFF)) return MIME_WEBP;
|
|
2670
|
+
return DEFAULT_IMAGE_MIME;
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
// src/providers/pruna/client/core/utils/api-error-parser.ts
|
|
2674
|
+
async function parseApiError(response, fallback) {
|
|
2675
|
+
const payload = await response.json().catch(() => ({ message: response.statusText }));
|
|
2676
|
+
const message = payload.message ?? `${fallback}: ${response.status}`;
|
|
2677
|
+
const error = new Error(message);
|
|
2678
|
+
error.statusCode = response.status;
|
|
2679
|
+
return error;
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2682
|
+
// src/providers/pruna/client/core/protocol/http-status.ts
|
|
2683
|
+
function isAuthFailureStatus(status) {
|
|
2684
|
+
return AUTH_FAILURE_STATUSES.includes(status);
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
// src/providers/pruna/client/core/protocol/job-status.ts
|
|
2688
|
+
var TERMINAL_SUCCESS_STATUSES = ["succeeded", "completed"];
|
|
2689
|
+
var TERMINAL_FAILURE_STATUSES = ["failed"];
|
|
2690
|
+
function isTerminalSuccessStatus(status) {
|
|
2691
|
+
if (!status) return false;
|
|
2692
|
+
return TERMINAL_SUCCESS_STATUSES.includes(status);
|
|
2693
|
+
}
|
|
2694
|
+
function isTerminalFailureStatus(status) {
|
|
2695
|
+
if (!status) return false;
|
|
2696
|
+
return TERMINAL_FAILURE_STATUSES.includes(status);
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
// src/providers/pruna/client/core/protocol/abort-signal-classifier.ts
|
|
2700
|
+
function isAbortError(err) {
|
|
2701
|
+
if (err instanceof DOMException && err.code === DOMException.ABORT_ERR) return true;
|
|
2702
|
+
if (err instanceof Error && err.name === "AbortError") return true;
|
|
2703
|
+
return false;
|
|
2704
|
+
}
|
|
2705
|
+
|
|
2706
|
+
// src/providers/pruna/client/core/protocol/pruna-url-builder.ts
|
|
2707
|
+
function isAbsoluteHttpUrl(value) {
|
|
2708
|
+
return value.startsWith(HTTPS_PREFIX) || value.startsWith(HTTP_PREFIX);
|
|
2709
|
+
}
|
|
2710
|
+
function isHttpsUrl(value) {
|
|
2711
|
+
return value.startsWith(HTTPS_PREFIX);
|
|
2712
|
+
}
|
|
2713
|
+
function buildPrunaApiUrl(pathOrUrl) {
|
|
2714
|
+
if (isAbsoluteHttpUrl(pathOrUrl)) return pathOrUrl;
|
|
2715
|
+
return `${PRUNA_BASE_URL}${pathOrUrl}`;
|
|
2716
|
+
}
|
|
2717
|
+
function buildFileUrlById(fileId) {
|
|
2718
|
+
return `${PRUNA_FILES_URL}/${fileId}`;
|
|
2719
|
+
}
|
|
2720
|
+
|
|
2721
|
+
// src/providers/pruna/client/core/math/exponential-backoff.ts
|
|
2722
|
+
function calculateExponentialBackoff2(inputs) {
|
|
2723
|
+
const {
|
|
2724
|
+
attempt,
|
|
2725
|
+
baseIntervalMs,
|
|
2726
|
+
maxIntervalMs = POLL_DEFAULTS.maxIntervalMs,
|
|
2727
|
+
jitterPercent = POLL_DEFAULTS.jitterPercent,
|
|
2728
|
+
growthBase = POLL_DEFAULTS.backoffBase
|
|
2729
|
+
} = inputs;
|
|
2730
|
+
const safeAttempt = Math.max(0, attempt);
|
|
2731
|
+
const safeBase = Math.max(0, baseIntervalMs);
|
|
2732
|
+
const exponentialDelay = Math.min(safeBase * Math.pow(growthBase, safeAttempt), maxIntervalMs);
|
|
2733
|
+
const jitter = exponentialDelay * jitterPercent * Math.random();
|
|
2734
|
+
return exponentialDelay + jitter;
|
|
2735
|
+
}
|
|
2736
|
+
|
|
2737
|
+
// src/providers/pruna/client/core/utils/uri-resolver.ts
|
|
2738
|
+
var uriCache = /* @__PURE__ */ new WeakMap();
|
|
2739
|
+
function stripBase64Prefix(image) {
|
|
2740
|
+
if (isHttpsUrl(image)) return image;
|
|
2741
|
+
const base64Index = image.indexOf(BASE64_MARKER);
|
|
2742
|
+
return base64Index !== -1 ? image.slice(base64Index + BASE64_MARKER.length) : image;
|
|
2743
|
+
}
|
|
2744
|
+
function readOutput(output) {
|
|
2745
|
+
if (typeof output === "string") return output;
|
|
2746
|
+
if (Array.isArray(output) && output.length > 0) return output[0] ?? null;
|
|
2747
|
+
if (output !== null && typeof output === "object" && "url" in output) {
|
|
2748
|
+
return output.url;
|
|
2749
|
+
}
|
|
2750
|
+
return null;
|
|
2751
|
+
}
|
|
2752
|
+
function extractUri(data) {
|
|
2753
|
+
const cached = uriCache.get(data);
|
|
2754
|
+
if (cached !== void 0) return cached;
|
|
2755
|
+
if (!isTerminalSuccessStatus(data.status)) {
|
|
2756
|
+
uriCache.set(data, null);
|
|
2757
|
+
return null;
|
|
2758
|
+
}
|
|
2759
|
+
const result = data.generation_url ?? readOutput(data.output) ?? data.video_url ?? data.data ?? null;
|
|
2760
|
+
uriCache.set(data, result);
|
|
2761
|
+
return result;
|
|
2762
|
+
}
|
|
2763
|
+
function resolveUri(uri) {
|
|
2764
|
+
return uri.startsWith("/") ? `${PRUNA_BASE_URL}${uri}` : uri;
|
|
2765
|
+
}
|
|
2766
|
+
|
|
2767
|
+
// src/providers/pruna/client/core/services/pruna-client.service.ts
|
|
2768
|
+
function buildFileExtension(mime) {
|
|
2769
|
+
return MIME_FILE_EXTENSION[mime] ?? "bin";
|
|
2770
|
+
}
|
|
2771
|
+
async function uploadImage(base64OrUrl, apiKey, onProgress) {
|
|
2772
|
+
if (isHttpsUrl(base64OrUrl)) return base64OrUrl;
|
|
2773
|
+
if (base64OrUrl.startsWith(HTTP_PREFIX)) {
|
|
2774
|
+
throw new Error("Only HTTPS URLs are supported for security.");
|
|
2775
|
+
}
|
|
2776
|
+
onProgress?.("uploading");
|
|
2777
|
+
const raw = stripBase64Prefix(base64OrUrl);
|
|
2778
|
+
let bytes;
|
|
2779
|
+
try {
|
|
2780
|
+
bytes = base64ToBytes(raw);
|
|
2781
|
+
} catch {
|
|
2782
|
+
throw new Error("Invalid image format. Provide base64 or a valid HTTPS URL.");
|
|
2783
|
+
}
|
|
2784
|
+
const mime = detectImageMime(bytes);
|
|
2785
|
+
const buffer = bytes.buffer.slice(
|
|
2786
|
+
bytes.byteOffset,
|
|
2787
|
+
bytes.byteOffset + bytes.byteLength
|
|
2788
|
+
);
|
|
2789
|
+
const blob = new Blob([buffer], { type: mime });
|
|
2790
|
+
const formData = new FormData();
|
|
2791
|
+
formData.append("content", blob, `upload.${buildFileExtension(mime)}`);
|
|
2792
|
+
const res = await fetch(PRUNA_FILES_URL, {
|
|
2793
|
+
method: "POST",
|
|
2794
|
+
headers: { apikey: apiKey },
|
|
2795
|
+
body: formData
|
|
2796
|
+
});
|
|
2797
|
+
if (!res.ok) {
|
|
2798
|
+
throw await parseApiError(res, "File upload error");
|
|
2799
|
+
}
|
|
2800
|
+
const data = await res.json();
|
|
2801
|
+
return data.urls?.get ?? buildFileUrlById(data.id ?? "");
|
|
2802
|
+
}
|
|
2803
|
+
async function submitPrediction(model, input, apiKey, signal, onProgress) {
|
|
2804
|
+
onProgress?.("predicting");
|
|
2805
|
+
const res = await fetch(PRUNA_PREDICTIONS_URL, {
|
|
2806
|
+
method: "POST",
|
|
2807
|
+
headers: {
|
|
2808
|
+
apikey: apiKey,
|
|
2809
|
+
Model: model,
|
|
2810
|
+
"Try-Sync": "true",
|
|
2811
|
+
"Content-Type": "application/json"
|
|
2812
|
+
},
|
|
2813
|
+
body: JSON.stringify({ input }),
|
|
2814
|
+
signal
|
|
2815
|
+
});
|
|
2816
|
+
if (!res.ok) {
|
|
2817
|
+
throw await parseApiError(res, "API error");
|
|
2818
|
+
}
|
|
2819
|
+
return res.json();
|
|
2820
|
+
}
|
|
2821
|
+
var GenerationFailedError = class extends Error {
|
|
2822
|
+
constructor(message) {
|
|
2823
|
+
super(message);
|
|
2824
|
+
this.name = "GenerationFailedError";
|
|
2825
|
+
}
|
|
2826
|
+
};
|
|
2827
|
+
async function attemptPoll(fullUrl, apiKey, signal) {
|
|
2828
|
+
let res;
|
|
2829
|
+
try {
|
|
2830
|
+
res = await fetch(fullUrl, { headers: { apikey: apiKey }, signal });
|
|
2831
|
+
} catch (err) {
|
|
2832
|
+
if (isAbortError(err)) throw new CancellationError();
|
|
2833
|
+
return { outcome: "transient-failure" };
|
|
2834
|
+
}
|
|
2835
|
+
if (!res.ok) {
|
|
2836
|
+
if (isAuthFailureStatus(res.status)) throw new AuthenticationError();
|
|
2837
|
+
return { outcome: "transient-failure" };
|
|
2838
|
+
}
|
|
2839
|
+
let data;
|
|
2840
|
+
try {
|
|
2841
|
+
data = await res.json();
|
|
2842
|
+
} catch {
|
|
2843
|
+
return { outcome: "transient-failure" };
|
|
2844
|
+
}
|
|
2845
|
+
if (isTerminalSuccessStatus(data.status)) {
|
|
2846
|
+
const uri = extractUri(data);
|
|
2847
|
+
if (uri) return { outcome: "succeeded", uri: resolveUri(uri) };
|
|
2848
|
+
return { outcome: "transient-failure" };
|
|
2849
|
+
}
|
|
2850
|
+
if (isTerminalFailureStatus(data.status)) {
|
|
2851
|
+
throw new GenerationFailedError(data.error ?? "Generation failed during processing.");
|
|
2852
|
+
}
|
|
2853
|
+
return { outcome: "continue" };
|
|
2854
|
+
}
|
|
2855
|
+
async function pollForResult(pollUrl, apiKey, maxAttempts = POLL_DEFAULTS.maxAttempts, intervalMs = POLL_DEFAULTS.intervalMs, signal, onProgress) {
|
|
2856
|
+
const fullUrl = isAbsoluteHttpUrl(pollUrl) ? pollUrl : buildPrunaApiUrl(pollUrl);
|
|
2857
|
+
const controller = new AbortController();
|
|
2858
|
+
const onExternalAbort = () => controller.abort();
|
|
2859
|
+
signal?.addEventListener("abort", onExternalAbort);
|
|
2860
|
+
try {
|
|
2861
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
2862
|
+
if (signal?.aborted) throw new CancellationError();
|
|
2863
|
+
const delay = calculateExponentialBackoff2({ attempt: i, baseIntervalMs: intervalMs });
|
|
2864
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2865
|
+
if (signal?.aborted) throw new CancellationError();
|
|
2866
|
+
onProgress?.("polling", i + 1);
|
|
2867
|
+
const result = await attemptPoll(fullUrl, apiKey, controller.signal);
|
|
2868
|
+
if (result.outcome === "succeeded" && result.uri) {
|
|
2869
|
+
return result.uri;
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
throw new TimeoutError();
|
|
2873
|
+
} finally {
|
|
2874
|
+
signal?.removeEventListener("abort", onExternalAbort);
|
|
2875
|
+
controller.abort();
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
|
|
2879
|
+
// src/providers/pruna/client/core/math/comparison-hash.ts
|
|
2880
|
+
function sortKeysDeep(value) {
|
|
2881
|
+
if (Array.isArray(value)) {
|
|
2882
|
+
return value.map(sortKeysDeep);
|
|
2883
|
+
}
|
|
2884
|
+
if (value !== null && typeof value === "object") {
|
|
2885
|
+
const record = value;
|
|
2886
|
+
return Object.keys(record).sort().reduce((acc, key) => {
|
|
2887
|
+
acc[key] = sortKeysDeep(record[key]);
|
|
2888
|
+
return acc;
|
|
2889
|
+
}, {});
|
|
2890
|
+
}
|
|
2891
|
+
return value;
|
|
2892
|
+
}
|
|
2893
|
+
function hashValue(value) {
|
|
2894
|
+
if (value === null || typeof value !== "object") {
|
|
2895
|
+
return String(value);
|
|
2896
|
+
}
|
|
2897
|
+
try {
|
|
2898
|
+
return JSON.stringify(sortKeysDeep(value));
|
|
2899
|
+
} catch {
|
|
2900
|
+
return String(value);
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
function compositeHash(...values) {
|
|
2904
|
+
return values.map(hashValue).join("|");
|
|
2905
|
+
}
|
|
2906
|
+
|
|
2907
|
+
// src/providers/pruna/client/core/math/cache-key-derivation.ts
|
|
2908
|
+
function deriveGenerationCacheKey(apiKey, input) {
|
|
2909
|
+
return `${apiKey}:${compositeHash(input)}`;
|
|
2910
|
+
}
|
|
2911
|
+
|
|
2912
|
+
// src/providers/pruna/client/core/validation/api-key-validator.ts
|
|
2913
|
+
function assertValidApiKey(apiKey) {
|
|
2914
|
+
if (typeof apiKey !== "string") {
|
|
2915
|
+
throw new ValidationError({
|
|
2916
|
+
field: "apiKey",
|
|
2917
|
+
reason: "must be a string",
|
|
2918
|
+
receivedValue: typeof apiKey
|
|
2919
|
+
});
|
|
2920
|
+
}
|
|
2921
|
+
if (apiKey.length < MIN_API_KEY_LENGTH) {
|
|
2922
|
+
throw new ValidationError({
|
|
2923
|
+
field: "apiKey",
|
|
2924
|
+
reason: "must not be empty",
|
|
2925
|
+
receivedValue: apiKey
|
|
2926
|
+
});
|
|
2927
|
+
}
|
|
2928
|
+
if (apiKey.length > MAX_API_KEY_LENGTH) {
|
|
2929
|
+
throw new ValidationError({
|
|
2930
|
+
field: "apiKey",
|
|
2931
|
+
reason: `exceeds maximum length of ${MAX_API_KEY_LENGTH}`,
|
|
2932
|
+
receivedValue: apiKey.length
|
|
2933
|
+
});
|
|
2934
|
+
}
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
// src/providers/pruna/client/core/validation/image-source-validator.ts
|
|
2938
|
+
function classifyImageSource(source) {
|
|
2939
|
+
if (source.startsWith(HTTPS_PREFIX)) return "https-url";
|
|
2940
|
+
if (source.startsWith(HTTP_PREFIX)) return "http-url";
|
|
2941
|
+
if (source.includes(BASE64_MARKER) || /^[A-Za-z0-9+/=]+$/.test(source)) return "base64";
|
|
2942
|
+
return "unknown";
|
|
2943
|
+
}
|
|
2944
|
+
function assertSecureImageSource(image, fieldName = "image") {
|
|
2945
|
+
if (typeof image !== "string") {
|
|
2946
|
+
throw new ValidationError({
|
|
2947
|
+
field: fieldName,
|
|
2948
|
+
reason: "must be a string",
|
|
2949
|
+
receivedValue: typeof image
|
|
2950
|
+
});
|
|
2951
|
+
}
|
|
2952
|
+
const kind = classifyImageSource(image);
|
|
2953
|
+
if (kind === "http-url") {
|
|
2954
|
+
throw new ValidationError({
|
|
2955
|
+
field: fieldName,
|
|
2956
|
+
reason: "HTTP URLs are not supported; use HTTPS or a base64 data URI",
|
|
2957
|
+
receivedValue: image
|
|
2958
|
+
});
|
|
2959
|
+
}
|
|
2960
|
+
if (kind === "unknown") {
|
|
2961
|
+
throw new ValidationError({
|
|
2962
|
+
field: fieldName,
|
|
2963
|
+
reason: "must be an HTTPS URL or a base64 data URI",
|
|
2964
|
+
receivedValue: typeof image
|
|
2965
|
+
});
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
|
|
2969
|
+
// src/providers/pruna/client/core/validation/aspect-ratio-validator.ts
|
|
2970
|
+
var SUPPORTED_ASPECT_RATIOS = [
|
|
2971
|
+
"16:9",
|
|
2972
|
+
"9:16",
|
|
2973
|
+
"1:1",
|
|
2974
|
+
"4:3",
|
|
2975
|
+
"3:4",
|
|
2976
|
+
"3:2",
|
|
2977
|
+
"2:3"
|
|
2978
|
+
];
|
|
2979
|
+
function isSupportedAspectRatio(value) {
|
|
2980
|
+
return typeof value === "string" && SUPPORTED_ASPECT_RATIOS.includes(value);
|
|
2981
|
+
}
|
|
2982
|
+
function assertValidAspectRatio(value, fieldName = "aspect_ratio") {
|
|
2983
|
+
if (value === void 0 || value === null) return;
|
|
2984
|
+
if (!isSupportedAspectRatio(value)) {
|
|
2985
|
+
throw new ValidationError({
|
|
2986
|
+
field: fieldName,
|
|
2987
|
+
reason: `must be one of ${SUPPORTED_ASPECT_RATIOS.join(", ")}`,
|
|
2988
|
+
receivedValue: value
|
|
2989
|
+
});
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
|
|
2993
|
+
// src/providers/pruna/client/core/validation/resolution-validator.ts
|
|
2994
|
+
var SUPPORTED_RESOLUTIONS = ["720p", "1080p"];
|
|
2995
|
+
function isSupportedResolution(value) {
|
|
2996
|
+
return typeof value === "string" && SUPPORTED_RESOLUTIONS.includes(value);
|
|
2997
|
+
}
|
|
2998
|
+
function assertValidResolution(value, fieldName = "resolution") {
|
|
2999
|
+
if (value === void 0 || value === null) return;
|
|
3000
|
+
if (!isSupportedResolution(value)) {
|
|
3001
|
+
throw new ValidationError({
|
|
3002
|
+
field: fieldName,
|
|
3003
|
+
reason: `must be one of ${SUPPORTED_RESOLUTIONS.join(", ")}`,
|
|
3004
|
+
receivedValue: value
|
|
3005
|
+
});
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
|
|
3009
|
+
// src/providers/pruna/client/core/validation/duration-validator.ts
|
|
3010
|
+
var MIN_VIDEO_DURATION_SECONDS = 1;
|
|
3011
|
+
var MAX_VIDEO_DURATION_SECONDS = 30;
|
|
3012
|
+
function isValidDuration(value) {
|
|
3013
|
+
return typeof value === "number" && Number.isFinite(value) && value >= MIN_VIDEO_DURATION_SECONDS && value <= MAX_VIDEO_DURATION_SECONDS && Number.isInteger(value);
|
|
3014
|
+
}
|
|
3015
|
+
function assertValidDuration(value, fieldName = "duration") {
|
|
3016
|
+
if (value === void 0 || value === null) return;
|
|
3017
|
+
if (!isValidDuration(value)) {
|
|
3018
|
+
throw new ValidationError({
|
|
3019
|
+
field: fieldName,
|
|
3020
|
+
reason: `must be an integer between ${MIN_VIDEO_DURATION_SECONDS} and ${MAX_VIDEO_DURATION_SECONDS} seconds`,
|
|
3021
|
+
receivedValue: value
|
|
3022
|
+
});
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
// src/providers/pruna/client/core/validation/prompt-validator.ts
|
|
3027
|
+
var MIN_PROMPT_LENGTH = 1;
|
|
3028
|
+
var MAX_PROMPT_LENGTH = 4e3;
|
|
3029
|
+
function assertValidPrompt(value, fieldName = "prompt") {
|
|
3030
|
+
if (typeof value !== "string") {
|
|
3031
|
+
throw new ValidationError({
|
|
3032
|
+
field: fieldName,
|
|
3033
|
+
reason: "must be a string",
|
|
3034
|
+
receivedValue: typeof value
|
|
3035
|
+
});
|
|
3036
|
+
}
|
|
3037
|
+
if (value.trim().length < MIN_PROMPT_LENGTH) {
|
|
3038
|
+
throw new ValidationError({
|
|
3039
|
+
field: fieldName,
|
|
3040
|
+
reason: "must not be empty or whitespace-only",
|
|
3041
|
+
receivedValue: value
|
|
3042
|
+
});
|
|
3043
|
+
}
|
|
3044
|
+
if (value.length > MAX_PROMPT_LENGTH) {
|
|
3045
|
+
throw new ValidationError({
|
|
3046
|
+
field: fieldName,
|
|
3047
|
+
reason: `exceeds maximum length of ${MAX_PROMPT_LENGTH} characters`,
|
|
3048
|
+
receivedValue: value.length
|
|
3049
|
+
});
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
|
|
3053
|
+
// src/providers/pruna/client/core/validation/seed-validator.ts
|
|
3054
|
+
var MIN_SEED = -2147483648;
|
|
3055
|
+
var MAX_SEED = 2147483647;
|
|
3056
|
+
function isValidSeed(value) {
|
|
3057
|
+
return typeof value === "number" && Number.isFinite(value) && Number.isInteger(value) && value >= MIN_SEED && value <= MAX_SEED;
|
|
3058
|
+
}
|
|
3059
|
+
function assertValidSeed(value, fieldName = "seed") {
|
|
3060
|
+
if (value === void 0 || value === null) return;
|
|
3061
|
+
if (!isValidSeed(value)) {
|
|
3062
|
+
throw new ValidationError({
|
|
3063
|
+
field: fieldName,
|
|
3064
|
+
reason: `must be an integer in [${MIN_SEED}, ${MAX_SEED}]`,
|
|
3065
|
+
receivedValue: value
|
|
3066
|
+
});
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
|
|
3070
|
+
// src/providers/pruna/client/core/protocol/input-type-guard.ts
|
|
3071
|
+
function isTextToImageInput(input) {
|
|
3072
|
+
return input.model === "p-image";
|
|
3073
|
+
}
|
|
3074
|
+
function isImageToImageInput(input) {
|
|
3075
|
+
return input.model === "p-image-edit";
|
|
3076
|
+
}
|
|
3077
|
+
function isImageToVideoInput(input) {
|
|
3078
|
+
return input.model === "p-video";
|
|
3079
|
+
}
|
|
3080
|
+
|
|
3081
|
+
// src/providers/pruna/client/core/utils/request-deduplicator.ts
|
|
3082
|
+
var RequestDeduplicator2 = class {
|
|
3083
|
+
pendingRequests = /* @__PURE__ */ new Map();
|
|
3084
|
+
ttl;
|
|
3085
|
+
constructor(ttl = DEFAULT_DEDUPLICATOR_TTL_MS) {
|
|
3086
|
+
this.ttl = ttl;
|
|
3087
|
+
}
|
|
3088
|
+
execute(key, fn) {
|
|
3089
|
+
const existing = this.pendingRequests.get(key);
|
|
3090
|
+
if (existing) {
|
|
3091
|
+
if (Date.now() - existing.timestamp < this.ttl) {
|
|
3092
|
+
return existing.promise;
|
|
3093
|
+
}
|
|
3094
|
+
this.pendingRequests.delete(key);
|
|
3095
|
+
}
|
|
3096
|
+
const promise = fn().finally(() => {
|
|
3097
|
+
setTimeout(() => {
|
|
3098
|
+
this.pendingRequests.delete(key);
|
|
3099
|
+
}, DEDUPLICATOR_CLEANUP_GRACE_MS);
|
|
3100
|
+
});
|
|
3101
|
+
this.pendingRequests.set(key, { promise, timestamp: Date.now() });
|
|
3102
|
+
return promise;
|
|
3103
|
+
}
|
|
3104
|
+
clear() {
|
|
3105
|
+
this.pendingRequests.clear();
|
|
3106
|
+
}
|
|
3107
|
+
size() {
|
|
3108
|
+
this.purgeExpired();
|
|
3109
|
+
return this.pendingRequests.size;
|
|
3110
|
+
}
|
|
3111
|
+
purgeExpired() {
|
|
3112
|
+
const now = Date.now();
|
|
3113
|
+
for (const [key, value] of this.pendingRequests) {
|
|
3114
|
+
if (now - value.timestamp >= this.ttl) {
|
|
3115
|
+
this.pendingRequests.delete(key);
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
};
|
|
3120
|
+
var globalDeduplicator = new RequestDeduplicator2();
|
|
3121
|
+
|
|
3122
|
+
// src/providers/pruna/client/generation/builders/text-to-image.builder.ts
|
|
3123
|
+
var TextToImageInputBuilder = class {
|
|
3124
|
+
model = "p-image";
|
|
3125
|
+
build(input, _context) {
|
|
3126
|
+
const payload = {
|
|
3127
|
+
prompt: input.prompt,
|
|
3128
|
+
aspect_ratio: input.aspect_ratio ?? DEFAULT_ASPECT_RATIO
|
|
3129
|
+
};
|
|
3130
|
+
if (input.seed !== void 0) {
|
|
3131
|
+
payload.seed = input.seed;
|
|
3132
|
+
}
|
|
3133
|
+
return Promise.resolve(payload);
|
|
3134
|
+
}
|
|
3135
|
+
};
|
|
3136
|
+
|
|
3137
|
+
// src/providers/pruna/client/generation/builders/image-to-image.builder.ts
|
|
3138
|
+
var ImageToImageInputBuilder = class {
|
|
3139
|
+
model = "p-image-edit";
|
|
3140
|
+
build(input, _context) {
|
|
3141
|
+
const payload = {
|
|
3142
|
+
images: [stripBase64Prefix(input.image)],
|
|
3143
|
+
prompt: input.prompt,
|
|
3144
|
+
aspect_ratio: input.aspect_ratio ?? DEFAULT_ASPECT_RATIO
|
|
3145
|
+
};
|
|
3146
|
+
if (input.seed !== void 0) {
|
|
3147
|
+
payload.seed = input.seed;
|
|
3148
|
+
}
|
|
3149
|
+
return Promise.resolve(payload);
|
|
3150
|
+
}
|
|
3151
|
+
};
|
|
3152
|
+
|
|
3153
|
+
// src/providers/pruna/client/generation/builders/image-to-video.builder.ts
|
|
3154
|
+
var ImageToVideoInputBuilder = class {
|
|
3155
|
+
model = "p-video";
|
|
3156
|
+
async build(input, context) {
|
|
3157
|
+
if (context.signal?.aborted) {
|
|
3158
|
+
throw new CancellationError();
|
|
3159
|
+
}
|
|
3160
|
+
const fileUrl = await uploadImage(
|
|
3161
|
+
input.image,
|
|
3162
|
+
context.apiKey,
|
|
3163
|
+
context.onProgress
|
|
3164
|
+
);
|
|
3165
|
+
return {
|
|
3166
|
+
image: fileUrl,
|
|
3167
|
+
prompt: input.prompt,
|
|
3168
|
+
duration: input.duration ?? P_VIDEO_DEFAULTS.duration,
|
|
3169
|
+
resolution: input.resolution ?? P_VIDEO_DEFAULTS.resolution,
|
|
3170
|
+
fps: P_VIDEO_DEFAULTS.fps,
|
|
3171
|
+
draft: input.draft ?? P_VIDEO_DEFAULTS.draft,
|
|
3172
|
+
aspect_ratio: input.aspect_ratio ?? DEFAULT_ASPECT_RATIO,
|
|
3173
|
+
prompt_upsampling: P_VIDEO_DEFAULTS.promptUpsampling
|
|
2580
3174
|
};
|
|
2581
|
-
return;
|
|
2582
3175
|
}
|
|
2583
|
-
|
|
3176
|
+
};
|
|
3177
|
+
|
|
3178
|
+
// src/providers/pruna/client/generation/builders/model-input-builder.ts
|
|
3179
|
+
var ModelInputBuilderRegistry = class {
|
|
3180
|
+
builders = /* @__PURE__ */ new Map();
|
|
3181
|
+
register(builder) {
|
|
3182
|
+
this.builders.set(builder.model, builder);
|
|
3183
|
+
return this;
|
|
3184
|
+
}
|
|
3185
|
+
resolve(model) {
|
|
3186
|
+
const builder = this.builders.get(model);
|
|
3187
|
+
if (!builder) {
|
|
3188
|
+
throw new Error(`No input builder registered for model: ${model}`);
|
|
3189
|
+
}
|
|
3190
|
+
return builder;
|
|
3191
|
+
}
|
|
3192
|
+
};
|
|
3193
|
+
|
|
3194
|
+
// src/providers/pruna/client/generation/builders/builder-factory.ts
|
|
3195
|
+
function createDefaultBuilderRegistry() {
|
|
3196
|
+
return new ModelInputBuilderRegistry().register(new TextToImageInputBuilder()).register(new ImageToImageInputBuilder()).register(new ImageToVideoInputBuilder());
|
|
3197
|
+
}
|
|
3198
|
+
|
|
3199
|
+
// src/providers/pruna/client/generation/services/generation.service.ts
|
|
3200
|
+
var builderRegistry = createDefaultBuilderRegistry();
|
|
3201
|
+
function validateGenerateInput(input) {
|
|
3202
|
+
assertValidPrompt(input.prompt, `${input.model}.prompt`);
|
|
3203
|
+
assertValidAspectRatio(input.aspect_ratio, `${input.model}.aspect_ratio`);
|
|
3204
|
+
if (isTextToImageInput(input)) {
|
|
3205
|
+
assertValidSeed(input.seed, `${input.model}.seed`);
|
|
3206
|
+
} else if (isImageToImageInput(input)) {
|
|
3207
|
+
assertSecureImageSource(input.image, `${input.model}.image`);
|
|
3208
|
+
assertValidSeed(input.seed, `${input.model}.seed`);
|
|
3209
|
+
} else if (isImageToVideoInput(input)) {
|
|
3210
|
+
assertSecureImageSource(input.image, `${input.model}.image`);
|
|
3211
|
+
assertValidDuration(input.duration, `${input.model}.duration`);
|
|
3212
|
+
assertValidResolution(input.resolution, `${input.model}.resolution`);
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
async function generate(apiKey, input, options = {}) {
|
|
3216
|
+
assertValidApiKey(apiKey);
|
|
3217
|
+
validateGenerateInput(input);
|
|
3218
|
+
const { signal, onProgress, useCache = true } = options;
|
|
3219
|
+
if (useCache) {
|
|
3220
|
+
const cacheKey = deriveGenerationCacheKey(apiKey, input);
|
|
3221
|
+
return globalDeduplicator.execute(
|
|
3222
|
+
cacheKey,
|
|
3223
|
+
() => generateInternal(apiKey, input, { signal, onProgress })
|
|
3224
|
+
);
|
|
3225
|
+
}
|
|
3226
|
+
return generateInternal(apiKey, input, { signal, onProgress });
|
|
3227
|
+
}
|
|
3228
|
+
async function generateInternal(apiKey, input, options) {
|
|
3229
|
+
const { signal, onProgress } = options;
|
|
3230
|
+
const builder = builderRegistry.resolve(input.model);
|
|
3231
|
+
const modelInput = await builder.build(input, { apiKey, signal, onProgress });
|
|
3232
|
+
const response = await submitPrediction(input.model, modelInput, apiKey, signal, onProgress);
|
|
3233
|
+
const syncUri = extractUri(response);
|
|
3234
|
+
if (syncUri) {
|
|
3235
|
+
return { url: resolveUri(syncUri), model: input.model };
|
|
3236
|
+
}
|
|
3237
|
+
const pollUrl = response.get_url ?? response.status_url;
|
|
2584
3238
|
if (!pollUrl) {
|
|
2585
|
-
throw new Error("Pruna
|
|
3239
|
+
throw new Error("Pruna API returned no result and no polling URL.");
|
|
3240
|
+
}
|
|
3241
|
+
const url = await pollForResult(
|
|
3242
|
+
pollUrl,
|
|
3243
|
+
apiKey,
|
|
3244
|
+
POLL_DEFAULTS.maxAttempts,
|
|
3245
|
+
POLL_DEFAULTS.intervalMs,
|
|
3246
|
+
signal,
|
|
3247
|
+
onProgress
|
|
3248
|
+
);
|
|
3249
|
+
return { url, model: input.model };
|
|
3250
|
+
}
|
|
3251
|
+
async function generateImageThenVideo(apiKey, input, options = {}) {
|
|
3252
|
+
assertValidApiKey(apiKey);
|
|
3253
|
+
assertValidPrompt(input.prompt, "text-to-video.prompt");
|
|
3254
|
+
assertValidAspectRatio(input.aspect_ratio, "text-to-video.aspect_ratio");
|
|
3255
|
+
assertValidDuration(input.duration, "text-to-video.duration");
|
|
3256
|
+
assertValidResolution(input.resolution, "text-to-video.resolution");
|
|
3257
|
+
const { signal, onProgress } = options;
|
|
3258
|
+
const aspectRatio = input.aspect_ratio ?? DEFAULT_ASPECT_RATIO;
|
|
3259
|
+
onProgress?.("predicting", 1);
|
|
3260
|
+
const imageResult = await generate(
|
|
3261
|
+
apiKey,
|
|
3262
|
+
{ model: "p-image", prompt: input.prompt, aspect_ratio: aspectRatio },
|
|
3263
|
+
{ signal }
|
|
3264
|
+
);
|
|
3265
|
+
onProgress?.("predicting", 2);
|
|
3266
|
+
return generate(
|
|
3267
|
+
apiKey,
|
|
3268
|
+
{
|
|
3269
|
+
model: "p-video",
|
|
3270
|
+
prompt: input.prompt,
|
|
3271
|
+
image: imageResult.url,
|
|
3272
|
+
duration: input.duration ?? P_VIDEO_DEFAULTS.duration,
|
|
3273
|
+
resolution: input.resolution ?? P_VIDEO_DEFAULTS.resolution,
|
|
3274
|
+
aspect_ratio: aspectRatio,
|
|
3275
|
+
draft: input.draft ?? P_VIDEO_DEFAULTS.draft
|
|
3276
|
+
},
|
|
3277
|
+
{ signal, onProgress }
|
|
3278
|
+
);
|
|
3279
|
+
}
|
|
3280
|
+
|
|
3281
|
+
// src/providers/pruna/pruna-generate.ts
|
|
3282
|
+
async function* generateWithPruna(request, apiKey, signal, onProgress) {
|
|
3283
|
+
const stages = [];
|
|
3284
|
+
let notify = null;
|
|
3285
|
+
let done = false;
|
|
3286
|
+
const wake = () => {
|
|
3287
|
+
const fn = notify;
|
|
3288
|
+
if (fn) {
|
|
3289
|
+
notify = null;
|
|
3290
|
+
fn();
|
|
3291
|
+
}
|
|
3292
|
+
};
|
|
3293
|
+
const handleProgress = (stage) => {
|
|
3294
|
+
stages.push({ stage });
|
|
3295
|
+
onProgress?.(stage);
|
|
3296
|
+
wake();
|
|
3297
|
+
};
|
|
3298
|
+
const promise = (async () => {
|
|
3299
|
+
try {
|
|
3300
|
+
const model = request.model ?? (request.image ? "p-image-edit" : "p-image");
|
|
3301
|
+
if (model === "p-video" && !request.image && request.prompt) {
|
|
3302
|
+
const videoRes = await generateImageThenVideo(
|
|
3303
|
+
apiKey,
|
|
3304
|
+
{
|
|
3305
|
+
prompt: request.prompt,
|
|
3306
|
+
duration: request.duration ?? 5,
|
|
3307
|
+
aspect_ratio: request.aspectRatio ?? request.aspect_ratio ?? "16:9"
|
|
3308
|
+
},
|
|
3309
|
+
{ signal, onProgress: handleProgress }
|
|
3310
|
+
);
|
|
3311
|
+
stages.push({
|
|
3312
|
+
stage: "polling",
|
|
3313
|
+
result: { url: videoRes.url, model: "p-video" }
|
|
3314
|
+
});
|
|
3315
|
+
return;
|
|
3316
|
+
}
|
|
3317
|
+
const input = {
|
|
3318
|
+
model,
|
|
3319
|
+
prompt: request.prompt ?? "",
|
|
3320
|
+
aspect_ratio: request.aspectRatio ?? request.aspect_ratio ?? "1:1",
|
|
3321
|
+
...request.image ? { image: request.image } : {},
|
|
3322
|
+
...request.duration ? { duration: request.duration } : {},
|
|
3323
|
+
...request.resolution ? { resolution: request.resolution } : {},
|
|
3324
|
+
...request.seed !== void 0 ? { seed: request.seed } : {}
|
|
3325
|
+
};
|
|
3326
|
+
const res = await generate(apiKey, input, {
|
|
3327
|
+
signal,
|
|
3328
|
+
onProgress: handleProgress
|
|
3329
|
+
});
|
|
3330
|
+
stages.push({
|
|
3331
|
+
stage: "polling",
|
|
3332
|
+
result: { url: res.url, model: res.model }
|
|
3333
|
+
});
|
|
3334
|
+
} catch (err) {
|
|
3335
|
+
stages.push({
|
|
3336
|
+
stage: "processing",
|
|
3337
|
+
error: err instanceof Error ? err : new Error(String(err))
|
|
3338
|
+
});
|
|
3339
|
+
} finally {
|
|
3340
|
+
done = true;
|
|
3341
|
+
wake();
|
|
3342
|
+
}
|
|
3343
|
+
})();
|
|
3344
|
+
while (!done || stages.length > 0) {
|
|
3345
|
+
if (stages.length === 0 && !done) {
|
|
3346
|
+
await new Promise((resolve) => {
|
|
3347
|
+
notify = resolve;
|
|
3348
|
+
});
|
|
3349
|
+
notify = null;
|
|
3350
|
+
}
|
|
3351
|
+
while (stages.length > 0) {
|
|
3352
|
+
const nextStage = stages.shift();
|
|
3353
|
+
if (!nextStage) continue;
|
|
3354
|
+
yield nextStage;
|
|
3355
|
+
if (nextStage.error) {
|
|
3356
|
+
throw nextStage.error;
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
2586
3359
|
}
|
|
2587
|
-
|
|
2588
|
-
yield { stage: "polling", result: { url: resultUrl, model: modelId } };
|
|
3360
|
+
await promise;
|
|
2589
3361
|
}
|
|
2590
3362
|
|
|
2591
3363
|
// src/providers/pruna/pruna.provider.ts
|
|
@@ -3196,6 +3968,6 @@ function resetProvider() {
|
|
|
3196
3968
|
container = null;
|
|
3197
3969
|
}
|
|
3198
3970
|
|
|
3199
|
-
export { ANTHROPIC_API_VERSION, ANTHROPIC_DEFAULT_MAX_TOKENS, ANTHROPIC_MODELS, ANTHROPIC_TIERS, API_ENDPOINTS, AnthropicHttpTransport, AnthropicProvider, AnthropicRequestBuilder, BaseProvider, DEFAULT_BASE_URL, DEFAULT_GENERATION_CONFIG, DEFAULT_MODELS, FalProvider, GEMINI_TIERS, GROQ_MODELS, GROQ_TIERS, GeminiProvider, GroqChatRequestBuilder, GroqConfigStore, GroqHttpClient, GroqHttpTransport, GroqProvider, ProviderError, ProviderFactory, PrunaProvider, TIMEOUTS, TextGenerationService, configureProvider, consumeAnthropicStream, consumeGroqStream, createAI, createAssistantMessage, createFalProvider, createGeminiProvider, createMessage, createPrunaProvider, createSystemMessage, createUserMessage, defaultEffortForModel, extractContentFromSsePayload, extractTextFromMessages, formatMessagesForDisplay, generateWithPruna, getProvider, isMediaProvider, isTextProvider, mapAnthropicStopReason, promptToMessages, requestStructuredJson, resetProvider, toGroqMessages };
|
|
3971
|
+
export { ANTHROPIC_API_VERSION, ANTHROPIC_DEFAULT_MAX_TOKENS, ANTHROPIC_MODELS, ANTHROPIC_TIERS, API_ENDPOINTS, AnthropicHttpTransport, AnthropicProvider, AnthropicRequestBuilder, AuthenticationError, BaseProvider, CancellationError, DEFAULT_BASE_URL, DEFAULT_GENERATION_CONFIG, DEFAULT_MODELS, FalProvider, GEMINI_TIERS, GROQ_MODELS, GROQ_TIERS, GeminiProvider, GenerationFailedError, GroqChatRequestBuilder, GroqConfigStore, GroqHttpClient, GroqHttpTransport, GroqProvider, ProviderError, ProviderFactory, PrunaProvider, TIMEOUTS, TextGenerationService, TimeoutError, ValidationError, configureProvider, consumeAnthropicStream, consumeGroqStream, createAI, createAssistantMessage, createFalProvider, createGeminiProvider, createMessage, createPrunaProvider, createSystemMessage, createUserMessage, defaultEffortForModel, extractContentFromSsePayload, extractTextFromMessages, formatMessagesForDisplay, generateImageThenVideo, generate as generatePruna, generateWithPruna, getProvider, isMediaProvider, isTextProvider, mapAnthropicStopReason, pollForResult, promptToMessages, requestStructuredJson, resetProvider, submitPrediction, toGroqMessages, uploadImage };
|
|
3200
3972
|
//# sourceMappingURL=index.js.map
|
|
3201
3973
|
//# sourceMappingURL=index.js.map
|