@aippy/runtime 0.4.2-dev.0 → 0.4.2-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/index.js +1 -1
- package/dist/ai/viggle/generate.d.ts +2 -0
- package/dist/{container-message-yZltTPi4.js → container-message-C2rC9u_k.js} +1 -1
- package/dist/core/index.js +1 -1
- package/dist/helper-CALy6Ol_.js +387 -0
- package/dist/index/index.js +2 -2
- package/package.json +1 -1
- package/dist/helper-7v3LLvbl.js +0 -373
package/dist/ai/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as r, d as i, e as n, c as A, U as C, a as t, b as g, m as I, h as f, i as _, j as p, k as E, g as T, l as U, n as d, p as D, r as l, f as L, s as m, v } from "../helper-
|
|
1
|
+
import { D as r, d as i, e as n, c as A, U as C, a as t, b as g, m as I, h as f, i as _, j as p, k as E, g as T, l as U, n as d, p as D, r as l, f as L, s as m, v } from "../helper-CALy6Ol_.js";
|
|
2
2
|
import "react";
|
|
3
3
|
import "../bridge-CtB9L5kL.js";
|
|
4
4
|
export {
|
package/dist/core/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { D as r, g as s, m as o } from "../config-B0A7gHQM.js";
|
|
2
2
|
import { _ as t, r as i } from "../bridge-CtB9L5kL.js";
|
|
3
3
|
import { A as R, a as E, E as c, b as m, c as A } from "../errors-B3bDbQbD.js";
|
|
4
|
-
import { S as f, V as g, c as l, a as y, g as _, s as d } from "../container-message-
|
|
4
|
+
import { S as f, V as g, c as l, a as y, g as _, s as d } from "../container-message-C2rC9u_k.js";
|
|
5
5
|
import { A as D, C as O, R as F, a as I, p as S } from "../runtime-CmoG3v2m.js";
|
|
6
6
|
export {
|
|
7
7
|
D as AippyRuntime,
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { createOpenAICompatible as _ } from "@ai-sdk/openai-compatible";
|
|
2
|
+
import { j as v } from "./url-c26cuIpu.js";
|
|
3
|
+
import { AISDKError as u, DefaultChatTransport as T } from "ai";
|
|
4
|
+
import { E as p, b as m, a as d } from "./errors-B3bDbQbD.js";
|
|
5
|
+
import { r as g } from "./bridge-CtB9L5kL.js";
|
|
6
|
+
import { s as I, a as U } from "./container-message-C2rC9u_k.js";
|
|
7
|
+
const M = `${g()}/aisdk/v1/`, te = `${g()}/aisdk/v1/ui/`, N = "gpt-5-nano", $ = "";
|
|
8
|
+
function C(t = {}) {
|
|
9
|
+
return {
|
|
10
|
+
baseUrl: t.baseUrl ?? `${g()}/aisdk/v1/`
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function D(t = {}) {
|
|
14
|
+
return {
|
|
15
|
+
baseUrl: t.baseUrl ?? `${g()}/aisdk/v1/ui/`
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function R(t, e) {
|
|
19
|
+
const r = t.status;
|
|
20
|
+
if (e && typeof e == "object" && "error" in e) {
|
|
21
|
+
const n = e, o = n.error.code, s = o != null ? `AippyAIError_${o}` : `AippyAIError_${r}`, a = e;
|
|
22
|
+
return "appMessage" in a && a.appMessage !== void 0 && I(a.appMessage), new u({
|
|
23
|
+
name: s,
|
|
24
|
+
message: `${p.RUNTIME} ${n.error.message}`,
|
|
25
|
+
cause: {
|
|
26
|
+
type: n.error.type ?? void 0,
|
|
27
|
+
param: n.error.param ?? void 0,
|
|
28
|
+
status: r
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (e && typeof e == "object" && e !== null) {
|
|
33
|
+
const n = e;
|
|
34
|
+
"appMessage" in n && n.appMessage !== void 0 && I(n.appMessage);
|
|
35
|
+
}
|
|
36
|
+
return new u({
|
|
37
|
+
name: `AippyAIError_${r}`,
|
|
38
|
+
message: `${p.RUNTIME} Request failed with status ${r}`,
|
|
39
|
+
cause: { status: r }
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function l() {
|
|
43
|
+
return async (t, e) => {
|
|
44
|
+
const r = await U(e?.headers), n = await globalThis.fetch(t, { ...e, headers: r });
|
|
45
|
+
if (!n.ok) {
|
|
46
|
+
const o = await n.text().catch(() => null);
|
|
47
|
+
let s = null;
|
|
48
|
+
if (o)
|
|
49
|
+
try {
|
|
50
|
+
s = JSON.parse(o);
|
|
51
|
+
} catch {
|
|
52
|
+
s = { message: o };
|
|
53
|
+
}
|
|
54
|
+
throw R(n, s);
|
|
55
|
+
}
|
|
56
|
+
return n;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const L = [
|
|
60
|
+
"gpt-image-1",
|
|
61
|
+
"gpt-image-1-mini",
|
|
62
|
+
"gpt-image-1.5"
|
|
63
|
+
];
|
|
64
|
+
function j(t) {
|
|
65
|
+
try {
|
|
66
|
+
const e = JSON.parse(t);
|
|
67
|
+
if (e.model && L.some((r) => e.model.startsWith(r))) {
|
|
68
|
+
const { response_format: r, ...n } = e;
|
|
69
|
+
return JSON.stringify(n);
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
return t;
|
|
74
|
+
}
|
|
75
|
+
function re(t = {}) {
|
|
76
|
+
const { baseUrl: e } = C(t), r = l();
|
|
77
|
+
return _({
|
|
78
|
+
name: "aippy",
|
|
79
|
+
baseURL: e,
|
|
80
|
+
fetch: async (o, s) => o.toString().includes("/images/generations") && s?.method?.toUpperCase() === "POST" && s?.body ? r(o, {
|
|
81
|
+
...s,
|
|
82
|
+
body: j(s.body)
|
|
83
|
+
}) : r(o, s),
|
|
84
|
+
// Enable structured outputs support (json_schema response format)
|
|
85
|
+
// This is required for Output.object() and Output.array() to work properly
|
|
86
|
+
supportsStructuredOutputs: !0
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const F = "/chat";
|
|
90
|
+
function ne(t = {}) {
|
|
91
|
+
const { baseUrl: e } = D(t), r = t.model ?? N, n = t.system ?? $, o = t.api ?? v(e, F), s = { model: r, system: n }, a = l();
|
|
92
|
+
return {
|
|
93
|
+
transport: new T({
|
|
94
|
+
api: o,
|
|
95
|
+
body: s,
|
|
96
|
+
// Ensure token is fetched fresh for every request
|
|
97
|
+
fetch: a
|
|
98
|
+
})
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async function se(t = {}) {
|
|
102
|
+
const e = await E("GET", "credits", t);
|
|
103
|
+
return (!e || typeof e != "object" || !("credits" in e) || !Number.isSafeInteger(e.credits)) && b(), e.credits;
|
|
104
|
+
}
|
|
105
|
+
async function oe(t, e) {
|
|
106
|
+
(!Number.isSafeInteger(t) || t <= 0) && w("deductCredits amount must be a positive safe integer"), (typeof e?.eventId != "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
|
|
107
|
+
e.eventId
|
|
108
|
+
)) && w("deductCredits eventId must be a UUID");
|
|
109
|
+
const r = await E("POST", "credits/deduct", e, {
|
|
110
|
+
amount: t,
|
|
111
|
+
eventId: e.eventId.toLowerCase()
|
|
112
|
+
});
|
|
113
|
+
(!r || typeof r != "object" || !("success" in r) || r.success !== !0) && b();
|
|
114
|
+
}
|
|
115
|
+
async function E(t, e, r, n) {
|
|
116
|
+
const { baseUrl: o } = C(r), s = await l()(v(o, e), {
|
|
117
|
+
method: t,
|
|
118
|
+
cache: "no-store",
|
|
119
|
+
signal: r.signal,
|
|
120
|
+
headers: n === void 0 ? void 0 : { "Content-Type": "application/json" },
|
|
121
|
+
body: n === void 0 ? void 0 : JSON.stringify(n)
|
|
122
|
+
});
|
|
123
|
+
try {
|
|
124
|
+
return await s.json();
|
|
125
|
+
} catch (a) {
|
|
126
|
+
if (r.signal?.aborted)
|
|
127
|
+
throw r.signal.reason ?? a;
|
|
128
|
+
if (a instanceof Error && a.name === "AbortError")
|
|
129
|
+
throw a;
|
|
130
|
+
b();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function w(t) {
|
|
134
|
+
throw new u({
|
|
135
|
+
name: "AippyAIError_credits_input",
|
|
136
|
+
message: `${p.CODE} ${t}`
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function b() {
|
|
140
|
+
throw new u({
|
|
141
|
+
name: "AippyAIError_credits_response",
|
|
142
|
+
message: `${p.RUNTIME} Invalid credits response`
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function y(t) {
|
|
146
|
+
return [...t].length;
|
|
147
|
+
}
|
|
148
|
+
const x = 3e3, B = 5e3, J = 300 * 1e3, P = 360 * 1e3;
|
|
149
|
+
async function ae(t) {
|
|
150
|
+
const e = t.prompt?.trim() ?? "", r = t.imageUrl?.trim() ?? "", n = t.image;
|
|
151
|
+
y(e) > 1e3 && c("generateCharacter3D prompt must be at most 1000 characters"), n != null && !(n instanceof Blob) && c("generateCharacter3D image must be a file"), n instanceof Blob && n.size === 0 && c("generateCharacter3D image is empty");
|
|
152
|
+
const o = t;
|
|
153
|
+
return O(
|
|
154
|
+
"viggle/characters",
|
|
155
|
+
n instanceof Blob ? H(n, e) : V(r, e),
|
|
156
|
+
o.pollIntervalMs ?? x,
|
|
157
|
+
o.timeoutMs ?? J,
|
|
158
|
+
t.signal
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
function H(t, e) {
|
|
162
|
+
const r = new FormData(), n = t instanceof File && t.name ? t.name : "image.png";
|
|
163
|
+
return r.append("image", t, n), e && r.append("prompt", e), { body: r };
|
|
164
|
+
}
|
|
165
|
+
function V(t, e) {
|
|
166
|
+
!e && !t && c(
|
|
167
|
+
"generateCharacter3D requires an image, an https imageUrl, or a prompt"
|
|
168
|
+
), t && !t.startsWith("https://") && c("generateCharacter3D imageUrl must be an https URL");
|
|
169
|
+
const r = {};
|
|
170
|
+
return t && (r.imageUrl = t), e && (r.prompt = e), {
|
|
171
|
+
headers: { "Content-Type": "application/json" },
|
|
172
|
+
body: JSON.stringify(r)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
async function ie(t) {
|
|
176
|
+
const e = t.text?.trim() ?? "";
|
|
177
|
+
(y(e) < 1 || y(e) > 400) && c("generateMotion text must be 1 to 400 characters"), t.durationSeconds != null && (!Number.isInteger(t.durationSeconds) || t.durationSeconds < 3 || t.durationSeconds > 60) && c("generateMotion durationSeconds must be an integer from 3 to 60");
|
|
178
|
+
const r = { text: e };
|
|
179
|
+
t.durationSeconds != null && (r.durationSeconds = t.durationSeconds);
|
|
180
|
+
const n = t;
|
|
181
|
+
return O(
|
|
182
|
+
"viggle/motions",
|
|
183
|
+
{
|
|
184
|
+
headers: { "Content-Type": "application/json" },
|
|
185
|
+
body: JSON.stringify(r)
|
|
186
|
+
},
|
|
187
|
+
n.pollIntervalMs ?? B,
|
|
188
|
+
n.timeoutMs ?? P,
|
|
189
|
+
t.signal
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
async function O(t, e, r, n, o) {
|
|
193
|
+
const s = l(), a = Date.now();
|
|
194
|
+
let i = await A(s, t, {
|
|
195
|
+
method: "POST",
|
|
196
|
+
...e,
|
|
197
|
+
signal: o
|
|
198
|
+
});
|
|
199
|
+
for (; i.status !== "ready"; )
|
|
200
|
+
i.status === "failed" && h(i.error || "Viggle generation failed"), Date.now() - a > n && h("Viggle generation timed out"), await G(r, o), i = await A(s, `${t}/${i.id}`, {
|
|
201
|
+
method: "GET",
|
|
202
|
+
signal: o
|
|
203
|
+
});
|
|
204
|
+
return i.url || h("Viggle generation finished without a file URL"), { url: i.url, thumbnailUrl: i.thumbnailUrl };
|
|
205
|
+
}
|
|
206
|
+
async function A(t, e, r) {
|
|
207
|
+
return await (await t(k(M, e), {
|
|
208
|
+
...r,
|
|
209
|
+
cache: "no-store"
|
|
210
|
+
})).json();
|
|
211
|
+
}
|
|
212
|
+
function k(t, e) {
|
|
213
|
+
return `${t.replace(/\/$/, "")}/${e.replace(/^\//, "")}`;
|
|
214
|
+
}
|
|
215
|
+
function G(t, e) {
|
|
216
|
+
if (e?.aborted)
|
|
217
|
+
throw e.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
218
|
+
return new Promise((r, n) => {
|
|
219
|
+
const o = setTimeout(r, t);
|
|
220
|
+
e?.addEventListener(
|
|
221
|
+
"abort",
|
|
222
|
+
() => {
|
|
223
|
+
clearTimeout(o), n(
|
|
224
|
+
e.reason ?? new DOMException("The operation was aborted", "AbortError")
|
|
225
|
+
);
|
|
226
|
+
},
|
|
227
|
+
{ once: !0 }
|
|
228
|
+
);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
function c(t) {
|
|
232
|
+
throw new u({
|
|
233
|
+
name: "AippyAIError_viggle_input",
|
|
234
|
+
message: `${p.CODE} ${t}`
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function h(t) {
|
|
238
|
+
throw new u({
|
|
239
|
+
name: "AippyAIError_viggle",
|
|
240
|
+
message: `${p.RUNTIME} ${t}`
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
function S(t) {
|
|
244
|
+
const e = [];
|
|
245
|
+
if (!t || typeof t != "object")
|
|
246
|
+
throw m("AIConfig must be an object", d.INVALID_CONFIG);
|
|
247
|
+
const r = t;
|
|
248
|
+
for (const [n, o] of Object.entries(r)) {
|
|
249
|
+
if (!o || typeof o != "object") {
|
|
250
|
+
e.push({ key: n, message: "Item must be an object" });
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
const s = o;
|
|
254
|
+
typeof s.index != "number" && e.push({ key: n, message: "index must be a number" }), typeof s.name != "string" && e.push({ key: n, message: "name must be a string" }), typeof s.description != "string" && e.push({ key: n, message: "description must be a string" });
|
|
255
|
+
const a = s.type;
|
|
256
|
+
if (!["number", "boolean", "text", "enum"].includes(a)) {
|
|
257
|
+
e.push({
|
|
258
|
+
key: n,
|
|
259
|
+
message: `type must be one of: number, boolean, text, enum (got: ${a})`
|
|
260
|
+
});
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (a === "number")
|
|
264
|
+
typeof s.value != "number" && e.push({ key: n, message: 'value must be a number for type "number"' }), s.min !== void 0 && typeof s.min != "number" && e.push({ key: n, message: "min must be a number" }), s.max !== void 0 && typeof s.max != "number" && e.push({ key: n, message: "max must be a number" }), s.step !== void 0 && typeof s.step != "number" && e.push({ key: n, message: "step must be a number" });
|
|
265
|
+
else if (a === "boolean")
|
|
266
|
+
typeof s.value != "boolean" && e.push({ key: n, message: 'value must be a boolean for type "boolean"' });
|
|
267
|
+
else if (a === "text")
|
|
268
|
+
typeof s.value != "string" && e.push({ key: n, message: 'value must be a string for type "text"' });
|
|
269
|
+
else if (a === "enum") {
|
|
270
|
+
if (!Array.isArray(s.options))
|
|
271
|
+
e.push({ key: n, message: 'options must be an array for type "enum"' });
|
|
272
|
+
else if (s.options.length === 0)
|
|
273
|
+
e.push({ key: n, message: 'options array cannot be empty for type "enum"' });
|
|
274
|
+
else
|
|
275
|
+
for (let f = 0; f < s.options.length; f++)
|
|
276
|
+
typeof s.options[f] != "string" && e.push({
|
|
277
|
+
key: n,
|
|
278
|
+
message: `options[${f}] must be a string`
|
|
279
|
+
});
|
|
280
|
+
typeof s.value != "string" ? e.push({ key: n, message: 'value must be a string for type "enum"' }) : Array.isArray(s.options) && !s.options.includes(s.value) && e.push({
|
|
281
|
+
key: n,
|
|
282
|
+
message: `value "${s.value}" is not in options: [${s.options.join(", ")}]`
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
s.group !== void 0 && typeof s.group != "string" && e.push({ key: n, message: "group must be a string" });
|
|
286
|
+
}
|
|
287
|
+
if (e.length > 0)
|
|
288
|
+
throw m(
|
|
289
|
+
`AIConfig validation failed with ${e.length} error(s)`,
|
|
290
|
+
d.INVALID_CONFIG,
|
|
291
|
+
{ errors: e }
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
function ce(t) {
|
|
295
|
+
let e;
|
|
296
|
+
try {
|
|
297
|
+
e = JSON.parse(t);
|
|
298
|
+
} catch (r) {
|
|
299
|
+
throw m(
|
|
300
|
+
`Invalid JSON: ${r instanceof Error ? r.message : String(r)}`,
|
|
301
|
+
d.INVALID_CONFIG
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
return S(e), e;
|
|
305
|
+
}
|
|
306
|
+
function q(t) {
|
|
307
|
+
return S(t), t;
|
|
308
|
+
}
|
|
309
|
+
function z(t, e) {
|
|
310
|
+
const r = t[e];
|
|
311
|
+
if (!r)
|
|
312
|
+
throw m(
|
|
313
|
+
`AIConfig key "${e}" not found`,
|
|
314
|
+
d.INVALID_CONFIG,
|
|
315
|
+
{ key: e }
|
|
316
|
+
);
|
|
317
|
+
return r.value;
|
|
318
|
+
}
|
|
319
|
+
function W(t) {
|
|
320
|
+
if (!(typeof window > "u"))
|
|
321
|
+
try {
|
|
322
|
+
const e = window.webkit?.messageHandlers?.aippyListener;
|
|
323
|
+
if (e)
|
|
324
|
+
try {
|
|
325
|
+
const r = {
|
|
326
|
+
command: "ai.initialize",
|
|
327
|
+
parameters: JSON.stringify(t)
|
|
328
|
+
};
|
|
329
|
+
e.postMessage(r);
|
|
330
|
+
} catch (r) {
|
|
331
|
+
console.warn("❌ [Aippy AI Config] Failed to send config to iOS app:", r);
|
|
332
|
+
}
|
|
333
|
+
if (window.parent && window.parent !== window)
|
|
334
|
+
try {
|
|
335
|
+
const r = {
|
|
336
|
+
type: "ai.initialize",
|
|
337
|
+
config: JSON.stringify(t)
|
|
338
|
+
};
|
|
339
|
+
window.parent.postMessage(r, "*");
|
|
340
|
+
} catch (r) {
|
|
341
|
+
console.warn("❌ [Aippy AI Config] Failed to send config to parent window:", r);
|
|
342
|
+
}
|
|
343
|
+
} catch (e) {
|
|
344
|
+
console.warn("⚠️ [Aippy AI Config] Failed to send config:", e);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
function ue(t) {
|
|
348
|
+
const e = q(t);
|
|
349
|
+
return W(e), new Proxy({}, {
|
|
350
|
+
get(r, n) {
|
|
351
|
+
if (typeof n == "string")
|
|
352
|
+
try {
|
|
353
|
+
return z(e, n);
|
|
354
|
+
} catch {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
has(r, n) {
|
|
359
|
+
return typeof n != "string" ? !1 : n in e;
|
|
360
|
+
},
|
|
361
|
+
ownKeys(r) {
|
|
362
|
+
return Object.keys(e);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
export {
|
|
367
|
+
M as D,
|
|
368
|
+
F as U,
|
|
369
|
+
re as a,
|
|
370
|
+
ne as b,
|
|
371
|
+
te as c,
|
|
372
|
+
N as d,
|
|
373
|
+
$ as e,
|
|
374
|
+
D as f,
|
|
375
|
+
se as g,
|
|
376
|
+
oe as h,
|
|
377
|
+
ae as i,
|
|
378
|
+
ie as j,
|
|
379
|
+
z as k,
|
|
380
|
+
q as l,
|
|
381
|
+
ue as m,
|
|
382
|
+
R as n,
|
|
383
|
+
ce as p,
|
|
384
|
+
C as r,
|
|
385
|
+
W as s,
|
|
386
|
+
S as v
|
|
387
|
+
};
|
package/dist/index/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { D as r, g as s, m as o } from "../config-B0A7gHQM.js";
|
|
2
2
|
import { _ as i, g as n, r as p } from "../bridge-CtB9L5kL.js";
|
|
3
3
|
import { A as m, a as c, E as f, b as C, c as g } from "../errors-B3bDbQbD.js";
|
|
4
|
-
import { S as d, V as l, c as I, a as E, g as S, s as x } from "../container-message-
|
|
4
|
+
import { S as d, V as l, c as I, a as E, g as S, s as x } from "../container-message-C2rC9u_k.js";
|
|
5
5
|
import { A as U, C as _, R as D, a as T, p as h } from "../runtime-CmoG3v2m.js";
|
|
6
6
|
import { CameraAPI as y, FileSystemAPI as F, GeolocationAPI as M, SensorsAPI as P, camera as O, fileSystem as b, geolocation as L, isMotionSupported as w, isOrientationSupported as H, requestMotionPermission as N, sensors as V, vibrate as k, watchMotion as B, watchOrientation as j } from "../device/index.js";
|
|
7
7
|
import { P as G, a as z, c as K, b as W, g as X, i as Y, p as J, r as Q, s as Z } from "../app-version-checker-Bz7FrEZz.js";
|
|
@@ -10,7 +10,7 @@ import { j as te } from "../url-c26cuIpu.js";
|
|
|
10
10
|
import { a as ne, b as pe } from "../useTweaks-C7BEMpV3.js";
|
|
11
11
|
import { c as me, b as ce, i as fe, p as Ce, u as ge, a as ue } from "../useSound-z_eIn0KH.js";
|
|
12
12
|
import { reportScore as le, sendEvent as Ie, updateScore as Ee } from "../leaderboard/index.js";
|
|
13
|
-
import { D as xe, d as Re, e as Ue, c as _e, U as De, a as Te, b as he, m as ve, h as ye, i as Fe, j as Me, k as Pe, g as Oe, l as be, n as Le, p as we, r as He, f as Ne, s as Ve, v as ke } from "../helper-
|
|
13
|
+
import { D as xe, d as Re, e as Ue, c as _e, U as De, a as Te, b as he, m as ve, h as ye, i as Fe, j as Me, k as Pe, g as Oe, l as be, n as Le, p as we, r as He, f as Ne, s as Ve, v as ke } from "../helper-CALy6Ol_.js";
|
|
14
14
|
import { c as je, u as qe } from "../hooks-D5lkty5r.js";
|
|
15
15
|
import { hasNativeBridge as ze } from "../native-bridge-BnvipFJc.js";
|
|
16
16
|
export {
|
package/package.json
CHANGED
package/dist/helper-7v3LLvbl.js
DELETED
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
import { createOpenAICompatible as S } from "@ai-sdk/openai-compatible";
|
|
2
|
-
import { j as v } from "./url-c26cuIpu.js";
|
|
3
|
-
import { AISDKError as c, DefaultChatTransport as U } from "ai";
|
|
4
|
-
import { E as u, b as m, a as g } from "./errors-B3bDbQbD.js";
|
|
5
|
-
import { r as d } from "./bridge-CtB9L5kL.js";
|
|
6
|
-
import { s as I, a as T } from "./container-message-yZltTPi4.js";
|
|
7
|
-
const M = `${d()}/aisdk/v1/`, Z = `${d()}/aisdk/v1/ui/`, $ = "gpt-5-nano", N = "";
|
|
8
|
-
function C(t = {}) {
|
|
9
|
-
return {
|
|
10
|
-
baseUrl: t.baseUrl ?? `${d()}/aisdk/v1/`
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function R(t = {}) {
|
|
14
|
-
return {
|
|
15
|
-
baseUrl: t.baseUrl ?? `${d()}/aisdk/v1/ui/`
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function D(t, e) {
|
|
19
|
-
const r = t.status;
|
|
20
|
-
if (e && typeof e == "object" && "error" in e) {
|
|
21
|
-
const s = e, o = s.error.code, n = o != null ? `AippyAIError_${o}` : `AippyAIError_${r}`, a = e;
|
|
22
|
-
return "appMessage" in a && a.appMessage !== void 0 && I(a.appMessage), new c({
|
|
23
|
-
name: n,
|
|
24
|
-
message: `${u.RUNTIME} ${s.error.message}`,
|
|
25
|
-
cause: {
|
|
26
|
-
type: s.error.type ?? void 0,
|
|
27
|
-
param: s.error.param ?? void 0,
|
|
28
|
-
status: r
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
if (e && typeof e == "object" && e !== null) {
|
|
33
|
-
const s = e;
|
|
34
|
-
"appMessage" in s && s.appMessage !== void 0 && I(s.appMessage);
|
|
35
|
-
}
|
|
36
|
-
return new c({
|
|
37
|
-
name: `AippyAIError_${r}`,
|
|
38
|
-
message: `${u.RUNTIME} Request failed with status ${r}`,
|
|
39
|
-
cause: { status: r }
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function l() {
|
|
43
|
-
return async (t, e) => {
|
|
44
|
-
const r = await T(e?.headers), s = await globalThis.fetch(t, { ...e, headers: r });
|
|
45
|
-
if (!s.ok) {
|
|
46
|
-
const o = await s.text().catch(() => null);
|
|
47
|
-
let n = null;
|
|
48
|
-
if (o)
|
|
49
|
-
try {
|
|
50
|
-
n = JSON.parse(o);
|
|
51
|
-
} catch {
|
|
52
|
-
n = { message: o };
|
|
53
|
-
}
|
|
54
|
-
throw D(s, n);
|
|
55
|
-
}
|
|
56
|
-
return s;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
const L = [
|
|
60
|
-
"gpt-image-1",
|
|
61
|
-
"gpt-image-1-mini",
|
|
62
|
-
"gpt-image-1.5"
|
|
63
|
-
];
|
|
64
|
-
function j(t) {
|
|
65
|
-
try {
|
|
66
|
-
const e = JSON.parse(t);
|
|
67
|
-
if (e.model && L.some((r) => e.model.startsWith(r))) {
|
|
68
|
-
const { response_format: r, ...s } = e;
|
|
69
|
-
return JSON.stringify(s);
|
|
70
|
-
}
|
|
71
|
-
} catch {
|
|
72
|
-
}
|
|
73
|
-
return t;
|
|
74
|
-
}
|
|
75
|
-
function ee(t = {}) {
|
|
76
|
-
const { baseUrl: e } = C(t), r = l();
|
|
77
|
-
return S({
|
|
78
|
-
name: "aippy",
|
|
79
|
-
baseURL: e,
|
|
80
|
-
fetch: async (o, n) => o.toString().includes("/images/generations") && n?.method?.toUpperCase() === "POST" && n?.body ? r(o, {
|
|
81
|
-
...n,
|
|
82
|
-
body: j(n.body)
|
|
83
|
-
}) : r(o, n),
|
|
84
|
-
// Enable structured outputs support (json_schema response format)
|
|
85
|
-
// This is required for Output.object() and Output.array() to work properly
|
|
86
|
-
supportsStructuredOutputs: !0
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
const F = "/chat";
|
|
90
|
-
function te(t = {}) {
|
|
91
|
-
const { baseUrl: e } = R(t), r = t.model ?? $, s = t.system ?? N, o = t.api ?? v(e, F), n = { model: r, system: s }, a = l();
|
|
92
|
-
return {
|
|
93
|
-
transport: new U({
|
|
94
|
-
api: o,
|
|
95
|
-
body: n,
|
|
96
|
-
// Ensure token is fetched fresh for every request
|
|
97
|
-
fetch: a
|
|
98
|
-
})
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
async function re(t = {}) {
|
|
102
|
-
const e = await E("GET", "credits", t);
|
|
103
|
-
return (!e || typeof e != "object" || !("credits" in e) || !Number.isSafeInteger(e.credits)) && b(), e.credits;
|
|
104
|
-
}
|
|
105
|
-
async function se(t, e) {
|
|
106
|
-
(!Number.isSafeInteger(t) || t <= 0) && w("deductCredits amount must be a positive safe integer"), (typeof e?.eventId != "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
|
|
107
|
-
e.eventId
|
|
108
|
-
)) && w("deductCredits eventId must be a UUID");
|
|
109
|
-
const r = await E("POST", "credits/deduct", e, {
|
|
110
|
-
amount: t,
|
|
111
|
-
eventId: e.eventId.toLowerCase()
|
|
112
|
-
});
|
|
113
|
-
(!r || typeof r != "object" || !("success" in r) || r.success !== !0) && b();
|
|
114
|
-
}
|
|
115
|
-
async function E(t, e, r, s) {
|
|
116
|
-
const { baseUrl: o } = C(r), n = await l()(v(o, e), {
|
|
117
|
-
method: t,
|
|
118
|
-
cache: "no-store",
|
|
119
|
-
signal: r.signal,
|
|
120
|
-
headers: s === void 0 ? void 0 : { "Content-Type": "application/json" },
|
|
121
|
-
body: s === void 0 ? void 0 : JSON.stringify(s)
|
|
122
|
-
});
|
|
123
|
-
try {
|
|
124
|
-
return await n.json();
|
|
125
|
-
} catch (a) {
|
|
126
|
-
if (r.signal?.aborted)
|
|
127
|
-
throw r.signal.reason ?? a;
|
|
128
|
-
if (a instanceof Error && a.name === "AbortError")
|
|
129
|
-
throw a;
|
|
130
|
-
b();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
function w(t) {
|
|
134
|
-
throw new c({
|
|
135
|
-
name: "AippyAIError_credits_input",
|
|
136
|
-
message: `${u.CODE} ${t}`
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
function b() {
|
|
140
|
-
throw new c({
|
|
141
|
-
name: "AippyAIError_credits_response",
|
|
142
|
-
message: `${u.RUNTIME} Invalid credits response`
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
function y(t) {
|
|
146
|
-
return [...t].length;
|
|
147
|
-
}
|
|
148
|
-
const x = 3e3, P = 5e3, J = 300 * 1e3, H = 360 * 1e3;
|
|
149
|
-
async function ne(t) {
|
|
150
|
-
const e = t.prompt?.trim() ?? "", r = t.imageUrl?.trim() ?? "";
|
|
151
|
-
!e && !r && f("generateCharacter3D requires an https imageUrl or a prompt"), y(e) > 1e3 && f("generateCharacter3D prompt must be at most 1000 characters"), r && !r.startsWith("https://") && f("generateCharacter3D imageUrl must be an https URL");
|
|
152
|
-
const s = {};
|
|
153
|
-
r && (s.imageUrl = r), e && (s.prompt = e);
|
|
154
|
-
const o = t;
|
|
155
|
-
return O(
|
|
156
|
-
"viggle/characters",
|
|
157
|
-
s,
|
|
158
|
-
o.pollIntervalMs ?? x,
|
|
159
|
-
o.timeoutMs ?? J,
|
|
160
|
-
t.signal
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
async function oe(t) {
|
|
164
|
-
const e = t.text?.trim() ?? "";
|
|
165
|
-
(y(e) < 1 || y(e) > 400) && f("generateMotion text must be 1 to 400 characters"), t.durationSeconds != null && (!Number.isInteger(t.durationSeconds) || t.durationSeconds < 3 || t.durationSeconds > 60) && f("generateMotion durationSeconds must be an integer from 3 to 60");
|
|
166
|
-
const r = { text: e };
|
|
167
|
-
t.durationSeconds != null && (r.durationSeconds = t.durationSeconds);
|
|
168
|
-
const s = t;
|
|
169
|
-
return O(
|
|
170
|
-
"viggle/motions",
|
|
171
|
-
r,
|
|
172
|
-
s.pollIntervalMs ?? P,
|
|
173
|
-
s.timeoutMs ?? H,
|
|
174
|
-
t.signal
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
async function O(t, e, r, s, o) {
|
|
178
|
-
const n = l(), a = Date.now();
|
|
179
|
-
let i = await A(n, t, {
|
|
180
|
-
method: "POST",
|
|
181
|
-
headers: { "Content-Type": "application/json" },
|
|
182
|
-
body: JSON.stringify(e),
|
|
183
|
-
signal: o
|
|
184
|
-
});
|
|
185
|
-
for (; i.status !== "ready"; )
|
|
186
|
-
i.status === "failed" && h(i.error || "Viggle generation failed"), Date.now() - a > s && h("Viggle generation timed out"), await k(r, o), i = await A(n, `${t}/${i.id}`, {
|
|
187
|
-
method: "GET",
|
|
188
|
-
signal: o
|
|
189
|
-
});
|
|
190
|
-
return i.url || h("Viggle generation finished without a file URL"), { url: i.url, thumbnailUrl: i.thumbnailUrl };
|
|
191
|
-
}
|
|
192
|
-
async function A(t, e, r) {
|
|
193
|
-
return await (await t(V(M, e), {
|
|
194
|
-
...r,
|
|
195
|
-
cache: "no-store"
|
|
196
|
-
})).json();
|
|
197
|
-
}
|
|
198
|
-
function V(t, e) {
|
|
199
|
-
return `${t.replace(/\/$/, "")}/${e.replace(/^\//, "")}`;
|
|
200
|
-
}
|
|
201
|
-
function k(t, e) {
|
|
202
|
-
if (e?.aborted)
|
|
203
|
-
throw e.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
204
|
-
return new Promise((r, s) => {
|
|
205
|
-
const o = setTimeout(r, t);
|
|
206
|
-
e?.addEventListener(
|
|
207
|
-
"abort",
|
|
208
|
-
() => {
|
|
209
|
-
clearTimeout(o), s(
|
|
210
|
-
e.reason ?? new DOMException("The operation was aborted", "AbortError")
|
|
211
|
-
);
|
|
212
|
-
},
|
|
213
|
-
{ once: !0 }
|
|
214
|
-
);
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
function f(t) {
|
|
218
|
-
throw new c({
|
|
219
|
-
name: "AippyAIError_viggle_input",
|
|
220
|
-
message: `${u.CODE} ${t}`
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
function h(t) {
|
|
224
|
-
throw new c({
|
|
225
|
-
name: "AippyAIError_viggle",
|
|
226
|
-
message: `${u.RUNTIME} ${t}`
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
function _(t) {
|
|
230
|
-
const e = [];
|
|
231
|
-
if (!t || typeof t != "object")
|
|
232
|
-
throw m("AIConfig must be an object", g.INVALID_CONFIG);
|
|
233
|
-
const r = t;
|
|
234
|
-
for (const [s, o] of Object.entries(r)) {
|
|
235
|
-
if (!o || typeof o != "object") {
|
|
236
|
-
e.push({ key: s, message: "Item must be an object" });
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
const n = o;
|
|
240
|
-
typeof n.index != "number" && e.push({ key: s, message: "index must be a number" }), typeof n.name != "string" && e.push({ key: s, message: "name must be a string" }), typeof n.description != "string" && e.push({ key: s, message: "description must be a string" });
|
|
241
|
-
const a = n.type;
|
|
242
|
-
if (!["number", "boolean", "text", "enum"].includes(a)) {
|
|
243
|
-
e.push({
|
|
244
|
-
key: s,
|
|
245
|
-
message: `type must be one of: number, boolean, text, enum (got: ${a})`
|
|
246
|
-
});
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
if (a === "number")
|
|
250
|
-
typeof n.value != "number" && e.push({ key: s, message: 'value must be a number for type "number"' }), n.min !== void 0 && typeof n.min != "number" && e.push({ key: s, message: "min must be a number" }), n.max !== void 0 && typeof n.max != "number" && e.push({ key: s, message: "max must be a number" }), n.step !== void 0 && typeof n.step != "number" && e.push({ key: s, message: "step must be a number" });
|
|
251
|
-
else if (a === "boolean")
|
|
252
|
-
typeof n.value != "boolean" && e.push({ key: s, message: 'value must be a boolean for type "boolean"' });
|
|
253
|
-
else if (a === "text")
|
|
254
|
-
typeof n.value != "string" && e.push({ key: s, message: 'value must be a string for type "text"' });
|
|
255
|
-
else if (a === "enum") {
|
|
256
|
-
if (!Array.isArray(n.options))
|
|
257
|
-
e.push({ key: s, message: 'options must be an array for type "enum"' });
|
|
258
|
-
else if (n.options.length === 0)
|
|
259
|
-
e.push({ key: s, message: 'options array cannot be empty for type "enum"' });
|
|
260
|
-
else
|
|
261
|
-
for (let p = 0; p < n.options.length; p++)
|
|
262
|
-
typeof n.options[p] != "string" && e.push({
|
|
263
|
-
key: s,
|
|
264
|
-
message: `options[${p}] must be a string`
|
|
265
|
-
});
|
|
266
|
-
typeof n.value != "string" ? e.push({ key: s, message: 'value must be a string for type "enum"' }) : Array.isArray(n.options) && !n.options.includes(n.value) && e.push({
|
|
267
|
-
key: s,
|
|
268
|
-
message: `value "${n.value}" is not in options: [${n.options.join(", ")}]`
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
n.group !== void 0 && typeof n.group != "string" && e.push({ key: s, message: "group must be a string" });
|
|
272
|
-
}
|
|
273
|
-
if (e.length > 0)
|
|
274
|
-
throw m(
|
|
275
|
-
`AIConfig validation failed with ${e.length} error(s)`,
|
|
276
|
-
g.INVALID_CONFIG,
|
|
277
|
-
{ errors: e }
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
function ae(t) {
|
|
281
|
-
let e;
|
|
282
|
-
try {
|
|
283
|
-
e = JSON.parse(t);
|
|
284
|
-
} catch (r) {
|
|
285
|
-
throw m(
|
|
286
|
-
`Invalid JSON: ${r instanceof Error ? r.message : String(r)}`,
|
|
287
|
-
g.INVALID_CONFIG
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
return _(e), e;
|
|
291
|
-
}
|
|
292
|
-
function B(t) {
|
|
293
|
-
return _(t), t;
|
|
294
|
-
}
|
|
295
|
-
function G(t, e) {
|
|
296
|
-
const r = t[e];
|
|
297
|
-
if (!r)
|
|
298
|
-
throw m(
|
|
299
|
-
`AIConfig key "${e}" not found`,
|
|
300
|
-
g.INVALID_CONFIG,
|
|
301
|
-
{ key: e }
|
|
302
|
-
);
|
|
303
|
-
return r.value;
|
|
304
|
-
}
|
|
305
|
-
function q(t) {
|
|
306
|
-
if (!(typeof window > "u"))
|
|
307
|
-
try {
|
|
308
|
-
const e = window.webkit?.messageHandlers?.aippyListener;
|
|
309
|
-
if (e)
|
|
310
|
-
try {
|
|
311
|
-
const r = {
|
|
312
|
-
command: "ai.initialize",
|
|
313
|
-
parameters: JSON.stringify(t)
|
|
314
|
-
};
|
|
315
|
-
e.postMessage(r);
|
|
316
|
-
} catch (r) {
|
|
317
|
-
console.warn("❌ [Aippy AI Config] Failed to send config to iOS app:", r);
|
|
318
|
-
}
|
|
319
|
-
if (window.parent && window.parent !== window)
|
|
320
|
-
try {
|
|
321
|
-
const r = {
|
|
322
|
-
type: "ai.initialize",
|
|
323
|
-
config: JSON.stringify(t)
|
|
324
|
-
};
|
|
325
|
-
window.parent.postMessage(r, "*");
|
|
326
|
-
} catch (r) {
|
|
327
|
-
console.warn("❌ [Aippy AI Config] Failed to send config to parent window:", r);
|
|
328
|
-
}
|
|
329
|
-
} catch (e) {
|
|
330
|
-
console.warn("⚠️ [Aippy AI Config] Failed to send config:", e);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
function ie(t) {
|
|
334
|
-
const e = B(t);
|
|
335
|
-
return q(e), new Proxy({}, {
|
|
336
|
-
get(r, s) {
|
|
337
|
-
if (typeof s == "string")
|
|
338
|
-
try {
|
|
339
|
-
return G(e, s);
|
|
340
|
-
} catch {
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
},
|
|
344
|
-
has(r, s) {
|
|
345
|
-
return typeof s != "string" ? !1 : s in e;
|
|
346
|
-
},
|
|
347
|
-
ownKeys(r) {
|
|
348
|
-
return Object.keys(e);
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
export {
|
|
353
|
-
M as D,
|
|
354
|
-
F as U,
|
|
355
|
-
ee as a,
|
|
356
|
-
te as b,
|
|
357
|
-
Z as c,
|
|
358
|
-
$ as d,
|
|
359
|
-
N as e,
|
|
360
|
-
R as f,
|
|
361
|
-
re as g,
|
|
362
|
-
se as h,
|
|
363
|
-
ne as i,
|
|
364
|
-
oe as j,
|
|
365
|
-
G as k,
|
|
366
|
-
B as l,
|
|
367
|
-
ie as m,
|
|
368
|
-
D as n,
|
|
369
|
-
ae as p,
|
|
370
|
-
C as r,
|
|
371
|
-
q as s,
|
|
372
|
-
_ as v
|
|
373
|
-
};
|