@aippy/runtime 0.4.2-dev.0 → 0.4.2-dev.2
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 +1 -1
- package/dist/ai/errors.d.ts +1 -0
- package/dist/ai/index.js +1 -1
- package/dist/ai/viggle/generate.d.ts +2 -0
- package/dist/{container-message-yZltTPi4.js → container-message-ChLaG4Ke.js} +1 -1
- package/dist/core/index.js +1 -1
- package/dist/helper-CCuf-R6I.js +405 -0
- package/dist/index/index.js +2 -2
- package/package.json +1 -1
- package/dist/helper-7v3LLvbl.js +0 -373
package/README.md
CHANGED
|
@@ -129,7 +129,7 @@ console.log(image.image?.base64);
|
|
|
129
129
|
|
|
130
130
|
The AI module adds `getCredits` and `deductCredits` in the unreleased source; published `@aippy/runtime@0.4.1` does not include them. Use them only after installing a published release containing both exports (`>= 0.4.2`), and verify the installed module declarations before importing.
|
|
131
131
|
|
|
132
|
-
The server checks the balance atomically and prevents duplicate charges for the same event and amount; changed charge details return HTTP 409. Insufficient balance uses the existing runtime error
|
|
132
|
+
The server checks the balance atomically and prevents duplicate charges for the same event and amount; changed charge details return HTTP 409. Insufficient balance uses the existing runtime error, the host `container.message` notification, and a native `wallet.showRecharge` command on the shared iOS/Android `aippyListener`. Call credits functions from UI handlers with error handling. Use explicit deductions for custom actions; model generation already charges credits. See the [AI module](./src/ai/README.md) and `aippy-ai-sdk` skill for usage.
|
|
133
133
|
|
|
134
134
|
## Packages
|
|
135
135
|
|
package/dist/ai/errors.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AISDKError } from 'ai';
|
|
|
2
2
|
/**
|
|
3
3
|
* Normalizes a backend error response into an AISDKError.
|
|
4
4
|
* Extracts and sends appMessage to container if present in the error response.
|
|
5
|
+
* Insufficient credits also asks the native host to open the recharge sheet.
|
|
5
6
|
* Uses [Aippy Runtime] prefix - these errors are NOT reported to LLM.
|
|
6
7
|
*/
|
|
7
8
|
export declare function normalizeError(response: Response, body?: unknown): AISDKError;
|
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-CCuf-R6I.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-ChLaG4Ke.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,405 @@
|
|
|
1
|
+
import { createOpenAICompatible as S } from "@ai-sdk/openai-compatible";
|
|
2
|
+
import { j as C } 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-ChLaG4Ke.js";
|
|
7
|
+
const M = `${g()}/aisdk/v1/`, oe = `${g()}/aisdk/v1/ui/`, N = "gpt-5-nano", D = "";
|
|
8
|
+
function v(t = {}) {
|
|
9
|
+
return {
|
|
10
|
+
baseUrl: t.baseUrl ?? `${g()}/aisdk/v1/`
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function R(t = {}) {
|
|
14
|
+
return {
|
|
15
|
+
baseUrl: t.baseUrl ?? `${g()}/aisdk/v1/ui/`
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const $ = 100003, F = "insufficient_quota";
|
|
19
|
+
function L(t, e) {
|
|
20
|
+
const r = t.status;
|
|
21
|
+
if (e && typeof e == "object" && "error" in e) {
|
|
22
|
+
const n = e, o = n.error.code, s = o != null ? `AippyAIError_${o}` : `AippyAIError_${r}`, a = e;
|
|
23
|
+
return "appMessage" in a && a.appMessage !== void 0 && I(a.appMessage), j(n.error) && x(), new u({
|
|
24
|
+
name: s,
|
|
25
|
+
message: `${p.RUNTIME} ${n.error.message}`,
|
|
26
|
+
cause: {
|
|
27
|
+
type: n.error.type ?? void 0,
|
|
28
|
+
param: n.error.param ?? void 0,
|
|
29
|
+
status: r
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (e && typeof e == "object" && e !== null) {
|
|
34
|
+
const n = e;
|
|
35
|
+
"appMessage" in n && n.appMessage !== void 0 && I(n.appMessage);
|
|
36
|
+
}
|
|
37
|
+
return new u({
|
|
38
|
+
name: `AippyAIError_${r}`,
|
|
39
|
+
message: `${p.RUNTIME} Request failed with status ${r}`,
|
|
40
|
+
cause: { status: r }
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function j(t) {
|
|
44
|
+
return t.code === $ || t.type === F;
|
|
45
|
+
}
|
|
46
|
+
function x() {
|
|
47
|
+
if (!(typeof window > "u"))
|
|
48
|
+
try {
|
|
49
|
+
const t = window.webkit?.messageHandlers?.aippyListener;
|
|
50
|
+
if (!t)
|
|
51
|
+
return;
|
|
52
|
+
t.postMessage({ command: "wallet.showRecharge" });
|
|
53
|
+
} catch (t) {
|
|
54
|
+
console.warn(
|
|
55
|
+
"⚠️ [Container Message] Failed to request native recharge:",
|
|
56
|
+
t
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function l() {
|
|
61
|
+
return async (t, e) => {
|
|
62
|
+
const r = await U(e?.headers), n = await globalThis.fetch(t, { ...e, headers: r });
|
|
63
|
+
if (!n.ok) {
|
|
64
|
+
const o = await n.text().catch(() => null);
|
|
65
|
+
let s = null;
|
|
66
|
+
if (o)
|
|
67
|
+
try {
|
|
68
|
+
s = JSON.parse(o);
|
|
69
|
+
} catch {
|
|
70
|
+
s = { message: o };
|
|
71
|
+
}
|
|
72
|
+
throw L(n, s);
|
|
73
|
+
}
|
|
74
|
+
return n;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const P = [
|
|
78
|
+
"gpt-image-1",
|
|
79
|
+
"gpt-image-1-mini",
|
|
80
|
+
"gpt-image-1.5"
|
|
81
|
+
];
|
|
82
|
+
function B(t) {
|
|
83
|
+
try {
|
|
84
|
+
const e = JSON.parse(t);
|
|
85
|
+
if (e.model && P.some((r) => e.model.startsWith(r))) {
|
|
86
|
+
const { response_format: r, ...n } = e;
|
|
87
|
+
return JSON.stringify(n);
|
|
88
|
+
}
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
return t;
|
|
92
|
+
}
|
|
93
|
+
function ae(t = {}) {
|
|
94
|
+
const { baseUrl: e } = v(t), r = l();
|
|
95
|
+
return S({
|
|
96
|
+
name: "aippy",
|
|
97
|
+
baseURL: e,
|
|
98
|
+
fetch: async (o, s) => o.toString().includes("/images/generations") && s?.method?.toUpperCase() === "POST" && s?.body ? r(o, {
|
|
99
|
+
...s,
|
|
100
|
+
body: B(s.body)
|
|
101
|
+
}) : r(o, s),
|
|
102
|
+
// Enable structured outputs support (json_schema response format)
|
|
103
|
+
// This is required for Output.object() and Output.array() to work properly
|
|
104
|
+
supportsStructuredOutputs: !0
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const J = "/chat";
|
|
108
|
+
function ie(t = {}) {
|
|
109
|
+
const { baseUrl: e } = R(t), r = t.model ?? N, n = t.system ?? D, o = t.api ?? C(e, J), s = { model: r, system: n }, a = l();
|
|
110
|
+
return {
|
|
111
|
+
transport: new T({
|
|
112
|
+
api: o,
|
|
113
|
+
body: s,
|
|
114
|
+
// Ensure token is fetched fresh for every request
|
|
115
|
+
fetch: a
|
|
116
|
+
})
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async function ce(t = {}) {
|
|
120
|
+
const e = await E("GET", "credits", t);
|
|
121
|
+
return (!e || typeof e != "object" || !("credits" in e) || !Number.isSafeInteger(e.credits)) && b(), e.credits;
|
|
122
|
+
}
|
|
123
|
+
async function ue(t, e) {
|
|
124
|
+
(!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(
|
|
125
|
+
e.eventId
|
|
126
|
+
)) && w("deductCredits eventId must be a UUID");
|
|
127
|
+
const r = await E("POST", "credits/deduct", e, {
|
|
128
|
+
amount: t,
|
|
129
|
+
eventId: e.eventId.toLowerCase()
|
|
130
|
+
});
|
|
131
|
+
(!r || typeof r != "object" || !("success" in r) || r.success !== !0) && b();
|
|
132
|
+
}
|
|
133
|
+
async function E(t, e, r, n) {
|
|
134
|
+
const { baseUrl: o } = v(r), s = await l()(C(o, e), {
|
|
135
|
+
method: t,
|
|
136
|
+
cache: "no-store",
|
|
137
|
+
signal: r.signal,
|
|
138
|
+
headers: n === void 0 ? void 0 : { "Content-Type": "application/json" },
|
|
139
|
+
body: n === void 0 ? void 0 : JSON.stringify(n)
|
|
140
|
+
});
|
|
141
|
+
try {
|
|
142
|
+
return await s.json();
|
|
143
|
+
} catch (a) {
|
|
144
|
+
if (r.signal?.aborted)
|
|
145
|
+
throw r.signal.reason ?? a;
|
|
146
|
+
if (a instanceof Error && a.name === "AbortError")
|
|
147
|
+
throw a;
|
|
148
|
+
b();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function w(t) {
|
|
152
|
+
throw new u({
|
|
153
|
+
name: "AippyAIError_credits_input",
|
|
154
|
+
message: `${p.CODE} ${t}`
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function b() {
|
|
158
|
+
throw new u({
|
|
159
|
+
name: "AippyAIError_credits_response",
|
|
160
|
+
message: `${p.RUNTIME} Invalid credits response`
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function y(t) {
|
|
164
|
+
return [...t].length;
|
|
165
|
+
}
|
|
166
|
+
const H = 3e3, V = 5e3, k = 300 * 1e3, q = 360 * 1e3;
|
|
167
|
+
async function pe(t) {
|
|
168
|
+
const e = t.prompt?.trim() ?? "", r = t.imageUrl?.trim() ?? "", n = t.image;
|
|
169
|
+
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");
|
|
170
|
+
const o = t;
|
|
171
|
+
return O(
|
|
172
|
+
"viggle/characters",
|
|
173
|
+
n instanceof Blob ? G(n, e) : z(r, e),
|
|
174
|
+
o.pollIntervalMs ?? H,
|
|
175
|
+
o.timeoutMs ?? k,
|
|
176
|
+
t.signal
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
function G(t, e) {
|
|
180
|
+
const r = new FormData(), n = t instanceof File && t.name ? t.name : "image.png";
|
|
181
|
+
return r.append("image", t, n), e && r.append("prompt", e), { body: r };
|
|
182
|
+
}
|
|
183
|
+
function z(t, e) {
|
|
184
|
+
!e && !t && c(
|
|
185
|
+
"generateCharacter3D requires an image, an https imageUrl, or a prompt"
|
|
186
|
+
), t && !t.startsWith("https://") && c("generateCharacter3D imageUrl must be an https URL");
|
|
187
|
+
const r = {};
|
|
188
|
+
return t && (r.imageUrl = t), e && (r.prompt = e), {
|
|
189
|
+
headers: { "Content-Type": "application/json" },
|
|
190
|
+
body: JSON.stringify(r)
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
async function fe(t) {
|
|
194
|
+
const e = t.text?.trim() ?? "";
|
|
195
|
+
(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");
|
|
196
|
+
const r = { text: e };
|
|
197
|
+
t.durationSeconds != null && (r.durationSeconds = t.durationSeconds);
|
|
198
|
+
const n = t;
|
|
199
|
+
return O(
|
|
200
|
+
"viggle/motions",
|
|
201
|
+
{
|
|
202
|
+
headers: { "Content-Type": "application/json" },
|
|
203
|
+
body: JSON.stringify(r)
|
|
204
|
+
},
|
|
205
|
+
n.pollIntervalMs ?? V,
|
|
206
|
+
n.timeoutMs ?? q,
|
|
207
|
+
t.signal
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
async function O(t, e, r, n, o) {
|
|
211
|
+
const s = l(), a = Date.now();
|
|
212
|
+
let i = await A(s, t, {
|
|
213
|
+
method: "POST",
|
|
214
|
+
...e,
|
|
215
|
+
signal: o
|
|
216
|
+
});
|
|
217
|
+
for (; i.status !== "ready"; )
|
|
218
|
+
i.status === "failed" && h(i.error || "Viggle generation failed"), Date.now() - a > n && h("Viggle generation timed out"), await K(r, o), i = await A(s, `${t}/${i.id}`, {
|
|
219
|
+
method: "GET",
|
|
220
|
+
signal: o
|
|
221
|
+
});
|
|
222
|
+
return i.url || h("Viggle generation finished without a file URL"), { url: i.url, thumbnailUrl: i.thumbnailUrl };
|
|
223
|
+
}
|
|
224
|
+
async function A(t, e, r) {
|
|
225
|
+
return await (await t(W(M, e), {
|
|
226
|
+
...r,
|
|
227
|
+
cache: "no-store"
|
|
228
|
+
})).json();
|
|
229
|
+
}
|
|
230
|
+
function W(t, e) {
|
|
231
|
+
return `${t.replace(/\/$/, "")}/${e.replace(/^\//, "")}`;
|
|
232
|
+
}
|
|
233
|
+
function K(t, e) {
|
|
234
|
+
if (e?.aborted)
|
|
235
|
+
throw e.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
236
|
+
return new Promise((r, n) => {
|
|
237
|
+
const o = setTimeout(r, t);
|
|
238
|
+
e?.addEventListener(
|
|
239
|
+
"abort",
|
|
240
|
+
() => {
|
|
241
|
+
clearTimeout(o), n(
|
|
242
|
+
e.reason ?? new DOMException("The operation was aborted", "AbortError")
|
|
243
|
+
);
|
|
244
|
+
},
|
|
245
|
+
{ once: !0 }
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
function c(t) {
|
|
250
|
+
throw new u({
|
|
251
|
+
name: "AippyAIError_viggle_input",
|
|
252
|
+
message: `${p.CODE} ${t}`
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
function h(t) {
|
|
256
|
+
throw new u({
|
|
257
|
+
name: "AippyAIError_viggle",
|
|
258
|
+
message: `${p.RUNTIME} ${t}`
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
function _(t) {
|
|
262
|
+
const e = [];
|
|
263
|
+
if (!t || typeof t != "object")
|
|
264
|
+
throw m("AIConfig must be an object", d.INVALID_CONFIG);
|
|
265
|
+
const r = t;
|
|
266
|
+
for (const [n, o] of Object.entries(r)) {
|
|
267
|
+
if (!o || typeof o != "object") {
|
|
268
|
+
e.push({ key: n, message: "Item must be an object" });
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const s = o;
|
|
272
|
+
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" });
|
|
273
|
+
const a = s.type;
|
|
274
|
+
if (!["number", "boolean", "text", "enum"].includes(a)) {
|
|
275
|
+
e.push({
|
|
276
|
+
key: n,
|
|
277
|
+
message: `type must be one of: number, boolean, text, enum (got: ${a})`
|
|
278
|
+
});
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (a === "number")
|
|
282
|
+
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" });
|
|
283
|
+
else if (a === "boolean")
|
|
284
|
+
typeof s.value != "boolean" && e.push({ key: n, message: 'value must be a boolean for type "boolean"' });
|
|
285
|
+
else if (a === "text")
|
|
286
|
+
typeof s.value != "string" && e.push({ key: n, message: 'value must be a string for type "text"' });
|
|
287
|
+
else if (a === "enum") {
|
|
288
|
+
if (!Array.isArray(s.options))
|
|
289
|
+
e.push({ key: n, message: 'options must be an array for type "enum"' });
|
|
290
|
+
else if (s.options.length === 0)
|
|
291
|
+
e.push({ key: n, message: 'options array cannot be empty for type "enum"' });
|
|
292
|
+
else
|
|
293
|
+
for (let f = 0; f < s.options.length; f++)
|
|
294
|
+
typeof s.options[f] != "string" && e.push({
|
|
295
|
+
key: n,
|
|
296
|
+
message: `options[${f}] must be a string`
|
|
297
|
+
});
|
|
298
|
+
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({
|
|
299
|
+
key: n,
|
|
300
|
+
message: `value "${s.value}" is not in options: [${s.options.join(", ")}]`
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
s.group !== void 0 && typeof s.group != "string" && e.push({ key: n, message: "group must be a string" });
|
|
304
|
+
}
|
|
305
|
+
if (e.length > 0)
|
|
306
|
+
throw m(
|
|
307
|
+
`AIConfig validation failed with ${e.length} error(s)`,
|
|
308
|
+
d.INVALID_CONFIG,
|
|
309
|
+
{ errors: e }
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
function me(t) {
|
|
313
|
+
let e;
|
|
314
|
+
try {
|
|
315
|
+
e = JSON.parse(t);
|
|
316
|
+
} catch (r) {
|
|
317
|
+
throw m(
|
|
318
|
+
`Invalid JSON: ${r instanceof Error ? r.message : String(r)}`,
|
|
319
|
+
d.INVALID_CONFIG
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
return _(e), e;
|
|
323
|
+
}
|
|
324
|
+
function Y(t) {
|
|
325
|
+
return _(t), t;
|
|
326
|
+
}
|
|
327
|
+
function X(t, e) {
|
|
328
|
+
const r = t[e];
|
|
329
|
+
if (!r)
|
|
330
|
+
throw m(
|
|
331
|
+
`AIConfig key "${e}" not found`,
|
|
332
|
+
d.INVALID_CONFIG,
|
|
333
|
+
{ key: e }
|
|
334
|
+
);
|
|
335
|
+
return r.value;
|
|
336
|
+
}
|
|
337
|
+
function Q(t) {
|
|
338
|
+
if (!(typeof window > "u"))
|
|
339
|
+
try {
|
|
340
|
+
const e = window.webkit?.messageHandlers?.aippyListener;
|
|
341
|
+
if (e)
|
|
342
|
+
try {
|
|
343
|
+
const r = {
|
|
344
|
+
command: "ai.initialize",
|
|
345
|
+
parameters: JSON.stringify(t)
|
|
346
|
+
};
|
|
347
|
+
e.postMessage(r);
|
|
348
|
+
} catch (r) {
|
|
349
|
+
console.warn("❌ [Aippy AI Config] Failed to send config to iOS app:", r);
|
|
350
|
+
}
|
|
351
|
+
if (window.parent && window.parent !== window)
|
|
352
|
+
try {
|
|
353
|
+
const r = {
|
|
354
|
+
type: "ai.initialize",
|
|
355
|
+
config: JSON.stringify(t)
|
|
356
|
+
};
|
|
357
|
+
window.parent.postMessage(r, "*");
|
|
358
|
+
} catch (r) {
|
|
359
|
+
console.warn("❌ [Aippy AI Config] Failed to send config to parent window:", r);
|
|
360
|
+
}
|
|
361
|
+
} catch (e) {
|
|
362
|
+
console.warn("⚠️ [Aippy AI Config] Failed to send config:", e);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function de(t) {
|
|
366
|
+
const e = Y(t);
|
|
367
|
+
return Q(e), new Proxy({}, {
|
|
368
|
+
get(r, n) {
|
|
369
|
+
if (typeof n == "string")
|
|
370
|
+
try {
|
|
371
|
+
return X(e, n);
|
|
372
|
+
} catch {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
has(r, n) {
|
|
377
|
+
return typeof n != "string" ? !1 : n in e;
|
|
378
|
+
},
|
|
379
|
+
ownKeys(r) {
|
|
380
|
+
return Object.keys(e);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
export {
|
|
385
|
+
M as D,
|
|
386
|
+
J as U,
|
|
387
|
+
ae as a,
|
|
388
|
+
ie as b,
|
|
389
|
+
oe as c,
|
|
390
|
+
N as d,
|
|
391
|
+
D as e,
|
|
392
|
+
R as f,
|
|
393
|
+
ce as g,
|
|
394
|
+
ue as h,
|
|
395
|
+
pe as i,
|
|
396
|
+
fe as j,
|
|
397
|
+
X as k,
|
|
398
|
+
Y as l,
|
|
399
|
+
de as m,
|
|
400
|
+
L as n,
|
|
401
|
+
me as p,
|
|
402
|
+
v as r,
|
|
403
|
+
Q as s,
|
|
404
|
+
_ as v
|
|
405
|
+
};
|
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-ChLaG4Ke.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-CCuf-R6I.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
|
-
};
|