@aippy/runtime 0.4.2-dev.2 → 0.4.2-dev.4
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 +15 -3
- package/dist/ai/errors.d.ts +1 -1
- package/dist/ai/index.d.ts +0 -1
- package/dist/ai/index.js +18 -21
- package/dist/bridge-D_-7nPNC.js +311 -0
- package/dist/container-message-DmIChz4h.js +56 -0
- package/dist/core/env.d.ts +2 -0
- package/dist/core/index.js +2 -2
- package/dist/core/parent-message.d.ts +5 -0
- package/dist/core/wallet-recharge.d.ts +16 -0
- package/dist/helper-BWszI06u.js +346 -0
- package/dist/{hooks-D5lkty5r.js → hooks-Ct9qEjM6.js} +1 -1
- package/dist/index/index.js +43 -42
- package/dist/index.d.ts +1 -0
- package/dist/ministore/app-authorization.d.ts +9 -0
- package/dist/ministore/authorization.d.ts +6 -0
- package/dist/ministore/consume.d.ts +3 -0
- package/dist/ministore/errors.d.ts +18 -0
- package/dist/ministore/index.d.ts +19 -0
- package/dist/ministore/index.js +915 -0
- package/dist/ministore/order.d.ts +1 -0
- package/dist/ministore/purchase.d.ts +5 -0
- package/dist/ministore/queries.d.ts +13 -0
- package/dist/ministore/recharge.d.ts +12 -0
- package/dist/ministore/transport.d.ts +14 -0
- package/dist/ministore/types.d.ts +166 -0
- package/dist/ministore/update-item.d.ts +3 -0
- package/dist/ministore/validation.d.ts +19 -0
- package/dist/ministore.d.ts +2 -0
- package/dist/user/bridge.d.ts +3 -8
- package/dist/user/config.d.ts +2 -0
- package/dist/user/index.js +2 -2
- package/dist/wallet-recharge-BqOljLWn.js +140 -0
- package/package.json +5 -1
- package/dist/ai/credits.d.ts +0 -12
- package/dist/bridge-CtB9L5kL.js +0 -259
- package/dist/container-message-ChLaG4Ke.js +0 -56
- package/dist/helper-CCuf-R6I.js +0 -405
package/dist/helper-CCuf-R6I.js
DELETED
|
@@ -1,405 +0,0 @@
|
|
|
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
|
-
};
|