@aippy/runtime 0.4.2-dev.5 → 0.4.2-dev.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/ai/index.d.ts +2 -1
- package/dist/ai/index.js +17 -13
- package/dist/ai/viggle/generate.d.ts +54 -13
- package/dist/ai/viggle/models.d.ts +46 -0
- package/dist/ai/viggle/recovery.d.ts +12 -0
- package/dist/{container-message-D4RX93q2.js → container-message-D_fZlguH.js} +1 -1
- package/dist/core/index.js +1 -1
- package/dist/helper-CQZmdyi3.js +752 -0
- package/dist/index/index.js +60 -55
- package/dist/ministore/index.js +64 -886
- package/dist/ministore/types.d.ts +5 -0
- package/dist/recharge-DSMMSwg8.js +993 -0
- package/package.json +1 -1
- package/dist/helper-CSe2sxu6.js +0 -346
- package/dist/wallet-recharge-xSzcD6QS.js +0 -140
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
var F = Object.defineProperty;
|
|
2
|
+
var z = (e, t, n) => t in e ? F(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var l = (e, t, n) => z(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { createOpenAICompatible as G } from "@ai-sdk/openai-compatible";
|
|
5
|
+
import { s as U, a as E } from "./container-message-D_fZlguH.js";
|
|
6
|
+
import { AISDKError as m, DefaultChatTransport as P } from "ai";
|
|
7
|
+
import { E as h, b as w, a as v } from "./errors-B3bDbQbD.js";
|
|
8
|
+
import { x as J, M as O, R as B, q as K, r as H, w as W } from "./recharge-DSMMSwg8.js";
|
|
9
|
+
import { j as Q } from "./url-c26cuIpu.js";
|
|
10
|
+
import { r as j, c as q } from "./bridge-K3HqQwdj.js";
|
|
11
|
+
const T = `${j()}/aisdk/v1/`, Ue = `${j()}/aisdk/v1/ui/`, Y = "gpt-5-nano", X = "";
|
|
12
|
+
function Z(e = {}) {
|
|
13
|
+
return {
|
|
14
|
+
baseUrl: e.baseUrl ?? `${j()}/aisdk/v1/`
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function ee(e = {}) {
|
|
18
|
+
return {
|
|
19
|
+
baseUrl: e.baseUrl ?? `${j()}/aisdk/v1/ui/`
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const te = 100003, re = "insufficient_quota";
|
|
23
|
+
function ne(e, t) {
|
|
24
|
+
const n = e.status;
|
|
25
|
+
if (t && typeof t == "object" && "error" in t) {
|
|
26
|
+
const r = t, s = r.error.code, i = s != null ? `AippyAIError_${s}` : `AippyAIError_${n}`, a = t;
|
|
27
|
+
return "appMessage" in a && a.appMessage !== void 0 && U(a.appMessage), se(r.error) && J(), new m({
|
|
28
|
+
name: i,
|
|
29
|
+
message: `${h.RUNTIME} ${r.error.message}`,
|
|
30
|
+
cause: {
|
|
31
|
+
type: r.error.type ?? void 0,
|
|
32
|
+
param: r.error.param ?? void 0,
|
|
33
|
+
status: n
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (t && typeof t == "object" && t !== null) {
|
|
38
|
+
const r = t;
|
|
39
|
+
"appMessage" in r && r.appMessage !== void 0 && U(r.appMessage);
|
|
40
|
+
}
|
|
41
|
+
return new m({
|
|
42
|
+
name: `AippyAIError_${n}`,
|
|
43
|
+
message: `${h.RUNTIME} Request failed with status ${n}`,
|
|
44
|
+
cause: { status: n }
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function se(e) {
|
|
48
|
+
return e.code === te || e.type === re;
|
|
49
|
+
}
|
|
50
|
+
function k() {
|
|
51
|
+
return async (e, t) => {
|
|
52
|
+
const n = await E(t?.headers), r = await globalThis.fetch(e, { ...t, headers: n });
|
|
53
|
+
if (!r.ok) {
|
|
54
|
+
const s = await r.text().catch(() => null);
|
|
55
|
+
let i = null;
|
|
56
|
+
if (s)
|
|
57
|
+
try {
|
|
58
|
+
i = JSON.parse(s);
|
|
59
|
+
} catch {
|
|
60
|
+
i = { message: s };
|
|
61
|
+
}
|
|
62
|
+
throw ne(r, i);
|
|
63
|
+
}
|
|
64
|
+
return r;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const ie = [
|
|
68
|
+
"gpt-image-1",
|
|
69
|
+
"gpt-image-1-mini",
|
|
70
|
+
"gpt-image-1.5"
|
|
71
|
+
];
|
|
72
|
+
function ae(e) {
|
|
73
|
+
try {
|
|
74
|
+
const t = JSON.parse(e);
|
|
75
|
+
if (t.model && ie.some((n) => t.model.startsWith(n))) {
|
|
76
|
+
const { response_format: n, ...r } = t;
|
|
77
|
+
return JSON.stringify(r);
|
|
78
|
+
}
|
|
79
|
+
} catch {
|
|
80
|
+
}
|
|
81
|
+
return e;
|
|
82
|
+
}
|
|
83
|
+
function Ne(e = {}) {
|
|
84
|
+
const { baseUrl: t } = Z(e), n = k();
|
|
85
|
+
return G({
|
|
86
|
+
name: "aippy",
|
|
87
|
+
baseURL: t,
|
|
88
|
+
fetch: async (s, i) => s.toString().includes("/images/generations") && i?.method?.toUpperCase() === "POST" && i?.body ? n(s, {
|
|
89
|
+
...i,
|
|
90
|
+
body: ae(i.body)
|
|
91
|
+
}) : n(s, i),
|
|
92
|
+
// Enable structured outputs support (json_schema response format)
|
|
93
|
+
// This is required for Output.object() and Output.array() to work properly
|
|
94
|
+
supportsStructuredOutputs: !0
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const oe = "/chat";
|
|
98
|
+
function ke(e = {}) {
|
|
99
|
+
const { baseUrl: t } = ee(e), n = e.model ?? Y, r = e.system ?? X, s = e.api ?? Q(t, oe), i = { model: n, system: r }, a = k();
|
|
100
|
+
return {
|
|
101
|
+
transport: new P({
|
|
102
|
+
api: s,
|
|
103
|
+
body: i,
|
|
104
|
+
// Ensure token is fetched fresh for every request
|
|
105
|
+
fetch: a
|
|
106
|
+
})
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const b = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Map(), ce = /^vg1_[0-9]{10}_[0-9a-f]{32}$/;
|
|
110
|
+
async function S(e) {
|
|
111
|
+
const t = e instanceof Blob ? await e.arrayBuffer() : new TextEncoder().encode(JSON.stringify(e)), n = await globalThis.crypto.subtle.digest("SHA-256", t);
|
|
112
|
+
return Array.from(
|
|
113
|
+
new Uint8Array(n),
|
|
114
|
+
(r) => r.toString(16).padStart(2, "0")
|
|
115
|
+
).join("");
|
|
116
|
+
}
|
|
117
|
+
function ue(e, t) {
|
|
118
|
+
const n = q();
|
|
119
|
+
if (!n || typeof window > "u") return;
|
|
120
|
+
const r = new URL(window.location.href).origin;
|
|
121
|
+
return `aippy:viggle:${JSON.stringify([T, r, n, e, t])}`;
|
|
122
|
+
}
|
|
123
|
+
function de(e) {
|
|
124
|
+
if (!e) return;
|
|
125
|
+
const t = b.get(e);
|
|
126
|
+
let n = t?.value;
|
|
127
|
+
try {
|
|
128
|
+
if (!t || t.stored) {
|
|
129
|
+
const r = window.localStorage.getItem(e);
|
|
130
|
+
if (r) n = JSON.parse(r);
|
|
131
|
+
else {
|
|
132
|
+
b.delete(e);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
} catch {
|
|
137
|
+
}
|
|
138
|
+
if (!(!n || !ce.test(n.requestId) || n.jobId !== void 0 && !/^job_[0-9a-f]{32}$/.test(n.jobId)))
|
|
139
|
+
return n;
|
|
140
|
+
}
|
|
141
|
+
function le(e, t) {
|
|
142
|
+
if (!e) return;
|
|
143
|
+
const n = { value: { ...t }, stored: !1 };
|
|
144
|
+
b.set(e, n);
|
|
145
|
+
try {
|
|
146
|
+
window.localStorage.setItem(e, JSON.stringify(t)), n.stored = !0;
|
|
147
|
+
} catch {
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function fe(e, t) {
|
|
151
|
+
if (e) {
|
|
152
|
+
b.get(e)?.value.requestId === t && b.delete(e);
|
|
153
|
+
try {
|
|
154
|
+
const n = window.localStorage.getItem(e);
|
|
155
|
+
n && JSON.parse(n)?.requestId === t && window.localStorage.removeItem(e);
|
|
156
|
+
} catch {
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function ge(e, t, n) {
|
|
161
|
+
if (!e) return t();
|
|
162
|
+
const r = I.get(e);
|
|
163
|
+
if (r) return he(r, n);
|
|
164
|
+
const s = t().finally(() => {
|
|
165
|
+
I.get(e) === s && I.delete(e);
|
|
166
|
+
});
|
|
167
|
+
return I.set(e, s), s;
|
|
168
|
+
}
|
|
169
|
+
function he(e, t) {
|
|
170
|
+
return new Promise((n, r) => {
|
|
171
|
+
const s = () => r(t.reason);
|
|
172
|
+
t.addEventListener("abort", s, { once: !0 }), e.then(
|
|
173
|
+
(i) => {
|
|
174
|
+
t.removeEventListener("abort", s), n(i);
|
|
175
|
+
},
|
|
176
|
+
(i) => {
|
|
177
|
+
t.removeEventListener("abort", s), r(i);
|
|
178
|
+
}
|
|
179
|
+
), t.aborted && s();
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
class g extends m {
|
|
183
|
+
constructor(n, r, s, i, a, o) {
|
|
184
|
+
super({
|
|
185
|
+
name: "AippyAIError_viggle",
|
|
186
|
+
message: `${h.RUNTIME} ${n}`,
|
|
187
|
+
cause: i
|
|
188
|
+
});
|
|
189
|
+
l(this, "requestId");
|
|
190
|
+
l(this, "jobId");
|
|
191
|
+
/** True only after the backend confirmed that this job was persisted. */
|
|
192
|
+
l(this, "jobConfirmed");
|
|
193
|
+
l(this, "kind");
|
|
194
|
+
l(this, "stage");
|
|
195
|
+
l(this, "reason");
|
|
196
|
+
l(this, "httpStatus");
|
|
197
|
+
l(this, "activeJob");
|
|
198
|
+
this.requestId = r.requestId, this.jobId = r.jobId, this.jobConfirmed = r.jobConfirmed === !0, this.kind = r.kind, this.stage = r.stage, this.reason = s, this.httpStatus = a, this.activeJob = o;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function pe() {
|
|
202
|
+
const e = new Uint8Array(16);
|
|
203
|
+
return globalThis.crypto.getRandomValues(e), `vg1_${Math.floor(Date.now() / 1e3)}_${Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("")}`;
|
|
204
|
+
}
|
|
205
|
+
const A = /^vg1_[0-9]{10}_[0-9a-f]{32}$/, me = 900 * 1e3, $ = (e) => [...e].length;
|
|
206
|
+
async function Me(e) {
|
|
207
|
+
const t = e.prompt?.trim() ?? "", n = e.imageUrl?.trim() ?? "", r = e.image;
|
|
208
|
+
return $(t) > 1e3 && f("generateCharacter3D prompt must be at most 1000 characters"), r != null && !(r instanceof Blob) && f("generateCharacter3D image must be a file"), r instanceof Blob && r.size === 0 && f("generateCharacter3D image is empty"), !r && !t && !n && f(
|
|
209
|
+
"generateCharacter3D requires an image, an https imageUrl, or a prompt"
|
|
210
|
+
), !r && n && !n.startsWith("https://") && f("generateCharacter3D imageUrl must be an https URL"), M(
|
|
211
|
+
"character",
|
|
212
|
+
async () => S([
|
|
213
|
+
"character",
|
|
214
|
+
t,
|
|
215
|
+
r ? "" : n,
|
|
216
|
+
r ? await S(r) : ""
|
|
217
|
+
]),
|
|
218
|
+
(s) => {
|
|
219
|
+
let i;
|
|
220
|
+
if (r instanceof Blob) {
|
|
221
|
+
const a = new FormData();
|
|
222
|
+
a.append("requestId", s), a.append(
|
|
223
|
+
"image",
|
|
224
|
+
r,
|
|
225
|
+
typeof File < "u" && r instanceof File && r.name ? r.name : "image.png"
|
|
226
|
+
), t && a.append("prompt", t), i = { body: a };
|
|
227
|
+
} else
|
|
228
|
+
i = V({
|
|
229
|
+
requestId: s,
|
|
230
|
+
...n ? { imageUrl: n } : {},
|
|
231
|
+
...t ? { prompt: t } : {}
|
|
232
|
+
});
|
|
233
|
+
return i;
|
|
234
|
+
},
|
|
235
|
+
e
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
async function De(e) {
|
|
239
|
+
const t = e.text?.trim() ?? "", n = e.durationSeconds;
|
|
240
|
+
return ($(t) < 1 || $(t) > 400) && f("generateMotion text must be 1 to 400 characters"), n != null && (!Number.isInteger(n) || n < 3 || n > 60) && f("generateMotion durationSeconds must be an integer from 3 to 60"), M(
|
|
241
|
+
"motion",
|
|
242
|
+
() => S(["motion", t, n ?? 5]),
|
|
243
|
+
(r) => V({
|
|
244
|
+
requestId: r,
|
|
245
|
+
text: t,
|
|
246
|
+
...n != null ? { durationSeconds: n } : {}
|
|
247
|
+
}),
|
|
248
|
+
e
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
async function M(e, t, n, r) {
|
|
252
|
+
r = { ...r };
|
|
253
|
+
const s = { kind: e, stage: "create" };
|
|
254
|
+
return x(s, r, async (i) => {
|
|
255
|
+
const a = await t();
|
|
256
|
+
i.check(), await E(), i.check();
|
|
257
|
+
const o = r.requestId ? void 0 : ue(e, a), c = await ge(
|
|
258
|
+
o,
|
|
259
|
+
async () => {
|
|
260
|
+
const u = de(o);
|
|
261
|
+
s.requestId = r.requestId ?? u?.requestId ?? pe(), A.test(s.requestId) || f("Invalid Viggle requestId"), s.jobId = u?.jobId, s.jobConfirmed = !!u?.jobId, s.persist = () => le(o, {
|
|
262
|
+
requestId: s.requestId,
|
|
263
|
+
...s.jobId ? { jobId: s.jobId } : {}
|
|
264
|
+
}), s.clear = () => fe(o, s.requestId), s.persist();
|
|
265
|
+
try {
|
|
266
|
+
let d;
|
|
267
|
+
if (s.jobId)
|
|
268
|
+
s.stage = "resume", d = await i.get(!0);
|
|
269
|
+
else
|
|
270
|
+
try {
|
|
271
|
+
d = await i.job(D(e), {
|
|
272
|
+
method: "POST",
|
|
273
|
+
...n(s.requestId)
|
|
274
|
+
});
|
|
275
|
+
} catch (_) {
|
|
276
|
+
const p = _ instanceof g ? _.activeJob : void 0;
|
|
277
|
+
if (!p || !p.sameInput || p.kind !== e) throw _;
|
|
278
|
+
s.requestId = p.requestId, s.jobId = p.jobId, s.jobConfirmed = !0, s.stage = "resume", s.persist(), d = await i.get(!0);
|
|
279
|
+
}
|
|
280
|
+
s.stage = "poll";
|
|
281
|
+
const y = await i.wait(d, !0);
|
|
282
|
+
return s.clear?.(), y;
|
|
283
|
+
} catch (d) {
|
|
284
|
+
throw d instanceof g && (["generation_failed", "request_expired"].includes(d.reason) || d.httpStatus === 404) && s.clear?.(), d;
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
i.signal
|
|
288
|
+
);
|
|
289
|
+
return i.check(), c;
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
async function Ve(e) {
|
|
293
|
+
(!e || !["character", "motion"].includes(e.kind) || !/^job_[0-9a-f]{32}$/.test(e.jobId)) && f("Invalid Viggle jobId or kind"), e.requestId != null && !A.test(e.requestId) && f("Invalid Viggle requestId");
|
|
294
|
+
const t = {
|
|
295
|
+
requestId: e.requestId,
|
|
296
|
+
jobId: e.jobId,
|
|
297
|
+
kind: e.kind,
|
|
298
|
+
stage: "resume"
|
|
299
|
+
};
|
|
300
|
+
return x(
|
|
301
|
+
t,
|
|
302
|
+
e,
|
|
303
|
+
async (n) => n.wait(await n.get(!0), !0)
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
function D(e) {
|
|
307
|
+
return `viggle/${e === "character" ? "characters" : "motions"}`;
|
|
308
|
+
}
|
|
309
|
+
function V(e) {
|
|
310
|
+
return {
|
|
311
|
+
headers: { "Content-Type": "application/json" },
|
|
312
|
+
body: JSON.stringify(e)
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function N(e) {
|
|
316
|
+
return typeof e.benefitKey == "string" && !!e.benefitKey && typeof e.bizOrderNo == "string" && e.bizOrderNo.startsWith("aisdk:managed:") && e.bizOrderNo.length <= 64 && e.quantity === 1 && Number.isSafeInteger(e.priceGEM) && e.priceGEM > 0;
|
|
317
|
+
}
|
|
318
|
+
function R(e) {
|
|
319
|
+
const t = typeof window > "u" ? void 0 : window, n = t?.location?.href;
|
|
320
|
+
let r = q();
|
|
321
|
+
return () => {
|
|
322
|
+
if (e.aborted) throw e.reason;
|
|
323
|
+
if ((typeof window > "u" ? void 0 : window) !== t || t?.location?.href !== n)
|
|
324
|
+
throw new DOMException("Generation page changed", "AbortError");
|
|
325
|
+
const s = q();
|
|
326
|
+
if (r === null)
|
|
327
|
+
r = s;
|
|
328
|
+
else if (s !== r)
|
|
329
|
+
throw new DOMException("Generation account changed", "AbortError");
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
async function x(e, t, n) {
|
|
333
|
+
t = { ...t };
|
|
334
|
+
const r = new AbortController(), s = () => r.abort(t.signal?.reason);
|
|
335
|
+
t.signal?.addEventListener("abort", s, { once: !0 }), t.signal?.aborted && s();
|
|
336
|
+
const i = t, a = setTimeout(
|
|
337
|
+
() => r.abort(
|
|
338
|
+
new DOMException("Viggle generation timed out", "TimeoutError")
|
|
339
|
+
),
|
|
340
|
+
i.timeoutMs ?? me
|
|
341
|
+
), o = new be(
|
|
342
|
+
e,
|
|
343
|
+
r.signal,
|
|
344
|
+
i.pollIntervalMs ?? (e.kind === "character" ? 3e3 : 5e3)
|
|
345
|
+
);
|
|
346
|
+
try {
|
|
347
|
+
return await n(o);
|
|
348
|
+
} catch (c) {
|
|
349
|
+
if (c instanceof g) throw c;
|
|
350
|
+
const u = r.signal.aborted ? r.signal.reason : c, d = u instanceof Error && u.name === "TimeoutError" ? "timeout" : r.signal.aborted || u instanceof Error && u.name === "AbortError" || c instanceof O && (c.kind === "abort" || c.type === "closed" || c.type === "cancelled") ? "cancelled" : c instanceof O ? c.type === "timeout" || c.type === "balance_timeout" ? "timeout" : c.reason || (c.kind === "unsupported" ? "authorization_unavailable" : "request_failed") : "request_failed";
|
|
351
|
+
throw new g(
|
|
352
|
+
u instanceof Error ? u.message : "Viggle request failed",
|
|
353
|
+
e,
|
|
354
|
+
d,
|
|
355
|
+
c
|
|
356
|
+
);
|
|
357
|
+
} finally {
|
|
358
|
+
clearTimeout(a), t.signal?.removeEventListener("abort", s);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
class be {
|
|
362
|
+
constructor(t, n, r) {
|
|
363
|
+
l(this, "check");
|
|
364
|
+
this.handle = t, this.signal = n, this.interval = r, this.check = R(n);
|
|
365
|
+
}
|
|
366
|
+
miniOptions() {
|
|
367
|
+
return { signal: this.signal, [B]: this.check };
|
|
368
|
+
}
|
|
369
|
+
async send(t, n, r, s = this.signal) {
|
|
370
|
+
this.check(), r?.();
|
|
371
|
+
const i = await E(n.headers);
|
|
372
|
+
if (this.check(), r?.(), s.aborted) throw s.reason;
|
|
373
|
+
const a = await globalThis.fetch(
|
|
374
|
+
`${T.replace(/\/$/, "")}/${t}`,
|
|
375
|
+
{
|
|
376
|
+
...n,
|
|
377
|
+
headers: i,
|
|
378
|
+
signal: s,
|
|
379
|
+
cache: "no-store",
|
|
380
|
+
credentials: "omit",
|
|
381
|
+
redirect: "error"
|
|
382
|
+
}
|
|
383
|
+
), o = await a.json().catch(() => {
|
|
384
|
+
});
|
|
385
|
+
if (this.check(), r?.(), a.status !== 200) {
|
|
386
|
+
const c = o?.error;
|
|
387
|
+
throw new g(
|
|
388
|
+
typeof c?.message == "string" ? c.message : `Viggle request failed (${a.status})`,
|
|
389
|
+
this.handle,
|
|
390
|
+
typeof c?.param?.reason == "string" ? c.param.reason : "http_error",
|
|
391
|
+
void 0,
|
|
392
|
+
a.status,
|
|
393
|
+
Ie(c?.param)
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
return o;
|
|
397
|
+
}
|
|
398
|
+
async job(t, n, r) {
|
|
399
|
+
const s = await this.send(t, n, r);
|
|
400
|
+
if (!s || s.billingVersion !== 2 || typeof s.id != "string" || !/^job_[0-9a-f]{32}$/.test(s.id) || this.handle.jobId && s.id !== this.handle.jobId || typeof s.requestId != "string" || !A.test(s.requestId) || this.handle.requestId && s.requestId !== this.handle.requestId || !["queued", "processing", "ready", "failed"].includes(s.status))
|
|
401
|
+
throw new Error("Invalid Viggle job response");
|
|
402
|
+
return this.handle.jobId = s.id, this.handle.requestId = s.requestId, this.handle.jobConfirmed = !0, this.handle.persist?.(), s;
|
|
403
|
+
}
|
|
404
|
+
get(t = !1, n) {
|
|
405
|
+
return this.job(
|
|
406
|
+
`${D(this.handle.kind)}/${encodeURIComponent(this.handle.jobId)}${t ? "?resume=1" : ""}`,
|
|
407
|
+
{ method: "GET" },
|
|
408
|
+
n
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
async authorize(t) {
|
|
412
|
+
if (!N(t))
|
|
413
|
+
throw new Error("Invalid Viggle purchase offer");
|
|
414
|
+
this.check();
|
|
415
|
+
const n = this.handle.stage;
|
|
416
|
+
this.handle.stage = "authorize";
|
|
417
|
+
let r;
|
|
418
|
+
try {
|
|
419
|
+
r = await K(
|
|
420
|
+
{
|
|
421
|
+
operation: "purchase",
|
|
422
|
+
benefitKey: t.benefitKey,
|
|
423
|
+
bizOrderNo: t.bizOrderNo,
|
|
424
|
+
quantity: 1,
|
|
425
|
+
title: t.title || "Viggle 3D",
|
|
426
|
+
buttonText: "确认",
|
|
427
|
+
content: `购买扣除 ${t.priceGEM} GEM;生成失败保留生成券`
|
|
428
|
+
},
|
|
429
|
+
this.miniOptions()
|
|
430
|
+
);
|
|
431
|
+
} catch (s) {
|
|
432
|
+
if (s instanceof O && ["closed", "cancelled"].includes(s.type ?? "")) {
|
|
433
|
+
const i = new g(
|
|
434
|
+
"Viggle purchase authorization was cancelled",
|
|
435
|
+
this.handle,
|
|
436
|
+
"cancelled",
|
|
437
|
+
s
|
|
438
|
+
);
|
|
439
|
+
throw await this.cancelDraft(), i;
|
|
440
|
+
}
|
|
441
|
+
throw s;
|
|
442
|
+
}
|
|
443
|
+
if (this.check(), !r.ok)
|
|
444
|
+
throw await this.cancelDraft(), new g(
|
|
445
|
+
"Viggle purchase authorization was not confirmed",
|
|
446
|
+
this.handle,
|
|
447
|
+
r.reason
|
|
448
|
+
);
|
|
449
|
+
this.handle.stage = n;
|
|
450
|
+
}
|
|
451
|
+
async cancelDraft() {
|
|
452
|
+
if (!this.handle.jobConfirmed || !this.handle.jobId) return;
|
|
453
|
+
const t = new AbortController();
|
|
454
|
+
let n;
|
|
455
|
+
const r = new Promise((a) => {
|
|
456
|
+
n = a;
|
|
457
|
+
}), s = () => {
|
|
458
|
+
t.abort(), n();
|
|
459
|
+
}, i = setTimeout(s, 1e3);
|
|
460
|
+
this.signal.addEventListener("abort", s, { once: !0 }), this.signal.aborted && s();
|
|
461
|
+
try {
|
|
462
|
+
await Promise.race([
|
|
463
|
+
this.send(
|
|
464
|
+
`viggle/jobs/${encodeURIComponent(this.handle.jobId)}/cancel`,
|
|
465
|
+
{ method: "POST" },
|
|
466
|
+
void 0,
|
|
467
|
+
t.signal
|
|
468
|
+
).then((a) => {
|
|
469
|
+
const o = a;
|
|
470
|
+
o && o.id === this.handle.jobId && o.requestId === this.handle.requestId && o.billingVersion === 2 && o.status === "failed" && this.handle.clear?.();
|
|
471
|
+
}),
|
|
472
|
+
r
|
|
473
|
+
]);
|
|
474
|
+
} catch {
|
|
475
|
+
} finally {
|
|
476
|
+
clearTimeout(i), this.signal.removeEventListener("abort", s), t.abort();
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
async wait(t, n) {
|
|
480
|
+
let r = t, s = !1, i = !1;
|
|
481
|
+
for (; ; ) {
|
|
482
|
+
if (this.check(), r.status === "ready") {
|
|
483
|
+
if (r.billing?.state !== "consumed")
|
|
484
|
+
throw new Error("Viggle coupon consumption is not confirmed");
|
|
485
|
+
if (typeof r.url != "string" || !r.url.startsWith("https://"))
|
|
486
|
+
throw new Error("Viggle generation finished without a file URL");
|
|
487
|
+
return {
|
|
488
|
+
url: r.url,
|
|
489
|
+
thumbnailUrl: r.thumbnailUrl,
|
|
490
|
+
jobId: r.id,
|
|
491
|
+
requestId: r.requestId,
|
|
492
|
+
kind: this.handle.kind,
|
|
493
|
+
billingState: r.billing?.state
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
if (r.status === "failed")
|
|
497
|
+
throw new g(
|
|
498
|
+
r.error || "Viggle generation failed",
|
|
499
|
+
this.handle,
|
|
500
|
+
"generation_failed"
|
|
501
|
+
);
|
|
502
|
+
const a = r.billing, o = a?.reason, c = [
|
|
503
|
+
"awaiting_authorization",
|
|
504
|
+
"insufficient_balance",
|
|
505
|
+
"purchase_refused"
|
|
506
|
+
].includes(a?.state ?? "");
|
|
507
|
+
if (o && ![
|
|
508
|
+
"purchase_pending",
|
|
509
|
+
"consume_pending",
|
|
510
|
+
"creation_unknown",
|
|
511
|
+
"service_unavailable"
|
|
512
|
+
].includes(o)) {
|
|
513
|
+
if (n && c && o === "authorization_required" && !s && a) {
|
|
514
|
+
s = !0, await this.authorize(a), r = await this.get(!0);
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
if (n && c && o === "insufficient_balance" && !i && a && N(a)) {
|
|
518
|
+
i = !0;
|
|
519
|
+
const u = H(this.miniOptions());
|
|
520
|
+
u.check();
|
|
521
|
+
let d = !0;
|
|
522
|
+
const y = await W(
|
|
523
|
+
async () => (this.check(), d || (r = await this.get(!0, u.check)), d = !1, r.billing?.reason === "insufficient_balance" ? {
|
|
524
|
+
ok: !1,
|
|
525
|
+
reason: "insufficient_balance",
|
|
526
|
+
data: r
|
|
527
|
+
} : { ok: !0, data: r }),
|
|
528
|
+
u,
|
|
529
|
+
a.bizOrderNo
|
|
530
|
+
);
|
|
531
|
+
if (this.check(), r = y.data, y.ok) continue;
|
|
532
|
+
}
|
|
533
|
+
throw new g(
|
|
534
|
+
`Viggle purchase needs attention: ${o}`,
|
|
535
|
+
this.handle,
|
|
536
|
+
o
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
await ye(this.interval, this.signal), r = await this.get();
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
function ye(e, t) {
|
|
544
|
+
return t.aborted ? Promise.reject(t.reason) : new Promise((n, r) => {
|
|
545
|
+
const s = () => {
|
|
546
|
+
clearTimeout(i), r(t.reason);
|
|
547
|
+
}, i = setTimeout(() => {
|
|
548
|
+
t.removeEventListener("abort", s), n();
|
|
549
|
+
}, e);
|
|
550
|
+
t.addEventListener("abort", s, { once: !0 });
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
function f(e) {
|
|
554
|
+
throw new m({
|
|
555
|
+
name: "AippyAIError_viggle_input",
|
|
556
|
+
message: `${h.CODE} ${e}`
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
function Ie(e) {
|
|
560
|
+
if (!e || typeof e != "object") return;
|
|
561
|
+
const t = e;
|
|
562
|
+
if (!(t.reason !== "generation_busy" || typeof t.jobId != "string" || !/^job_[0-9a-f]{32}$/.test(t.jobId) || t.kind !== "motion" && t.kind !== "character" || typeof t.requestId != "string" || !A.test(t.requestId) || typeof t.sameInput != "boolean"))
|
|
563
|
+
return {
|
|
564
|
+
jobId: t.jobId,
|
|
565
|
+
kind: t.kind,
|
|
566
|
+
requestId: t.requestId,
|
|
567
|
+
sameInput: t.sameInput
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
async function Re(e = {}) {
|
|
571
|
+
if (e.kind != null && !["character", "motion"].includes(e.kind) || e.limit != null && (!Number.isInteger(e.limit) || e.limit < 1 || e.limit > 50) || e.cursor != null && e.cursor !== "" && !/^[1-9][0-9]*$/.test(e.cursor))
|
|
572
|
+
throw C("Invalid Viggle model-list query", !0);
|
|
573
|
+
const t = e.signal ?? new AbortController().signal, n = R(t);
|
|
574
|
+
n();
|
|
575
|
+
const r = new URLSearchParams();
|
|
576
|
+
e.limit != null && r.set("limit", String(e.limit)), e.kind && r.set("kind", e.kind), e.cursor && r.set("cursor", e.cursor);
|
|
577
|
+
const s = await E();
|
|
578
|
+
n();
|
|
579
|
+
const i = r.size ? `?${r.toString()}` : "", a = await globalThis.fetch(
|
|
580
|
+
`${T.replace(/\/$/, "")}/viggle/models${i}`,
|
|
581
|
+
{
|
|
582
|
+
method: "GET",
|
|
583
|
+
headers: s,
|
|
584
|
+
signal: t,
|
|
585
|
+
cache: "no-store",
|
|
586
|
+
credentials: "omit",
|
|
587
|
+
redirect: "error"
|
|
588
|
+
}
|
|
589
|
+
), o = await a.json().catch(() => {
|
|
590
|
+
});
|
|
591
|
+
if (n(), a.status !== 200)
|
|
592
|
+
throw C(`Viggle models request failed (${a.status})`);
|
|
593
|
+
if (!o || !Array.isArray(o.models) || o.models.length > 50 || typeof o.nextCursor != "string" || o.nextCursor !== "" && !/^[1-9][0-9]*$/.test(o.nextCursor) || !o.models.every(we))
|
|
594
|
+
throw C("Invalid Viggle model-list response");
|
|
595
|
+
return o;
|
|
596
|
+
}
|
|
597
|
+
function we(e) {
|
|
598
|
+
return !!e && typeof e.recordId == "string" && /^[1-9][0-9]*$/.test(e.recordId) && typeof e.benefitKey == "string" && !!e.benefitKey && typeof e.bizOrderNo == "string" && typeof e.jobId == "string" && /^job_[0-9a-f]{32}$/.test(e.jobId) && ["character", "motion"].includes(e.kind) && typeof e.url == "string" && e.url.startsWith("https://") && typeof e.generatedAt == "string" && typeof e.consumedAt == "string" && !!e.value && e.value.schemaVersion === 1 && e.value.source === "aisdk.viggle" && e.value.provider === "viggle" && e.value.kind === e.kind && e.value.jobId === e.jobId && e.value.asset?.url === e.url;
|
|
599
|
+
}
|
|
600
|
+
function C(e, t = !1) {
|
|
601
|
+
return new m({
|
|
602
|
+
name: "AippyAIError_viggle_models",
|
|
603
|
+
message: `${t ? h.CODE : h.RUNTIME} ${e}`
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
function L(e) {
|
|
607
|
+
const t = [];
|
|
608
|
+
if (!e || typeof e != "object")
|
|
609
|
+
throw w("AIConfig must be an object", v.INVALID_CONFIG);
|
|
610
|
+
const n = e;
|
|
611
|
+
for (const [r, s] of Object.entries(n)) {
|
|
612
|
+
if (!s || typeof s != "object") {
|
|
613
|
+
t.push({ key: r, message: "Item must be an object" });
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
const i = s;
|
|
617
|
+
typeof i.index != "number" && t.push({ key: r, message: "index must be a number" }), typeof i.name != "string" && t.push({ key: r, message: "name must be a string" }), typeof i.description != "string" && t.push({ key: r, message: "description must be a string" });
|
|
618
|
+
const a = i.type;
|
|
619
|
+
if (!["number", "boolean", "text", "enum"].includes(a)) {
|
|
620
|
+
t.push({
|
|
621
|
+
key: r,
|
|
622
|
+
message: `type must be one of: number, boolean, text, enum (got: ${a})`
|
|
623
|
+
});
|
|
624
|
+
continue;
|
|
625
|
+
}
|
|
626
|
+
if (a === "number")
|
|
627
|
+
typeof i.value != "number" && t.push({ key: r, message: 'value must be a number for type "number"' }), i.min !== void 0 && typeof i.min != "number" && t.push({ key: r, message: "min must be a number" }), i.max !== void 0 && typeof i.max != "number" && t.push({ key: r, message: "max must be a number" }), i.step !== void 0 && typeof i.step != "number" && t.push({ key: r, message: "step must be a number" });
|
|
628
|
+
else if (a === "boolean")
|
|
629
|
+
typeof i.value != "boolean" && t.push({ key: r, message: 'value must be a boolean for type "boolean"' });
|
|
630
|
+
else if (a === "text")
|
|
631
|
+
typeof i.value != "string" && t.push({ key: r, message: 'value must be a string for type "text"' });
|
|
632
|
+
else if (a === "enum") {
|
|
633
|
+
if (!Array.isArray(i.options))
|
|
634
|
+
t.push({ key: r, message: 'options must be an array for type "enum"' });
|
|
635
|
+
else if (i.options.length === 0)
|
|
636
|
+
t.push({ key: r, message: 'options array cannot be empty for type "enum"' });
|
|
637
|
+
else
|
|
638
|
+
for (let o = 0; o < i.options.length; o++)
|
|
639
|
+
typeof i.options[o] != "string" && t.push({
|
|
640
|
+
key: r,
|
|
641
|
+
message: `options[${o}] must be a string`
|
|
642
|
+
});
|
|
643
|
+
typeof i.value != "string" ? t.push({ key: r, message: 'value must be a string for type "enum"' }) : Array.isArray(i.options) && !i.options.includes(i.value) && t.push({
|
|
644
|
+
key: r,
|
|
645
|
+
message: `value "${i.value}" is not in options: [${i.options.join(", ")}]`
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
i.group !== void 0 && typeof i.group != "string" && t.push({ key: r, message: "group must be a string" });
|
|
649
|
+
}
|
|
650
|
+
if (t.length > 0)
|
|
651
|
+
throw w(
|
|
652
|
+
`AIConfig validation failed with ${t.length} error(s)`,
|
|
653
|
+
v.INVALID_CONFIG,
|
|
654
|
+
{ errors: t }
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
function xe(e) {
|
|
658
|
+
let t;
|
|
659
|
+
try {
|
|
660
|
+
t = JSON.parse(e);
|
|
661
|
+
} catch (n) {
|
|
662
|
+
throw w(
|
|
663
|
+
`Invalid JSON: ${n instanceof Error ? n.message : String(n)}`,
|
|
664
|
+
v.INVALID_CONFIG
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
return L(t), t;
|
|
668
|
+
}
|
|
669
|
+
function ve(e) {
|
|
670
|
+
return L(e), e;
|
|
671
|
+
}
|
|
672
|
+
function Ee(e, t) {
|
|
673
|
+
const n = e[t];
|
|
674
|
+
if (!n)
|
|
675
|
+
throw w(
|
|
676
|
+
`AIConfig key "${t}" not found`,
|
|
677
|
+
v.INVALID_CONFIG,
|
|
678
|
+
{ key: t }
|
|
679
|
+
);
|
|
680
|
+
return n.value;
|
|
681
|
+
}
|
|
682
|
+
function je(e) {
|
|
683
|
+
if (!(typeof window > "u"))
|
|
684
|
+
try {
|
|
685
|
+
const t = window.webkit?.messageHandlers?.aippyListener;
|
|
686
|
+
if (t)
|
|
687
|
+
try {
|
|
688
|
+
const n = {
|
|
689
|
+
command: "ai.initialize",
|
|
690
|
+
parameters: JSON.stringify(e)
|
|
691
|
+
};
|
|
692
|
+
t.postMessage(n);
|
|
693
|
+
} catch (n) {
|
|
694
|
+
console.warn("❌ [Aippy AI Config] Failed to send config to iOS app:", n);
|
|
695
|
+
}
|
|
696
|
+
if (window.parent && window.parent !== window)
|
|
697
|
+
try {
|
|
698
|
+
const n = {
|
|
699
|
+
type: "ai.initialize",
|
|
700
|
+
config: JSON.stringify(e)
|
|
701
|
+
};
|
|
702
|
+
window.parent.postMessage(n, "*");
|
|
703
|
+
} catch (n) {
|
|
704
|
+
console.warn("❌ [Aippy AI Config] Failed to send config to parent window:", n);
|
|
705
|
+
}
|
|
706
|
+
} catch (t) {
|
|
707
|
+
console.warn("⚠️ [Aippy AI Config] Failed to send config:", t);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
function Le(e) {
|
|
711
|
+
const t = ve(e);
|
|
712
|
+
return je(t), new Proxy({}, {
|
|
713
|
+
get(n, r) {
|
|
714
|
+
if (typeof r == "string")
|
|
715
|
+
try {
|
|
716
|
+
return Ee(t, r);
|
|
717
|
+
} catch {
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
has(n, r) {
|
|
722
|
+
return typeof r != "string" ? !1 : r in t;
|
|
723
|
+
},
|
|
724
|
+
ownKeys(n) {
|
|
725
|
+
return Object.keys(t);
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
export {
|
|
730
|
+
T as D,
|
|
731
|
+
oe as U,
|
|
732
|
+
g as V,
|
|
733
|
+
Ne as a,
|
|
734
|
+
ke as b,
|
|
735
|
+
Ue as c,
|
|
736
|
+
Y as d,
|
|
737
|
+
X as e,
|
|
738
|
+
ee as f,
|
|
739
|
+
Me as g,
|
|
740
|
+
De as h,
|
|
741
|
+
pe as i,
|
|
742
|
+
Ve as j,
|
|
743
|
+
ve as k,
|
|
744
|
+
Re as l,
|
|
745
|
+
Ee as m,
|
|
746
|
+
ne as n,
|
|
747
|
+
Le as o,
|
|
748
|
+
xe as p,
|
|
749
|
+
Z as r,
|
|
750
|
+
je as s,
|
|
751
|
+
L as v
|
|
752
|
+
};
|