@aippy/runtime 0.4.1 → 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/README.md +17 -6
- package/dist/ai/credits.d.ts +12 -0
- package/dist/ai/index.d.ts +2 -0
- package/dist/ai/index.js +20 -16
- package/dist/ai/viggle/generate.d.ts +26 -0
- package/dist/{container-message-C3YXyTZj.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 +52 -48
- package/package.json +1 -1
- package/dist/helper-WRpB-6MD.js +0 -241
package/README.md
CHANGED
|
@@ -17,14 +17,19 @@ import { AippyConfig, mergeConfig } from '@aippy/runtime/core';
|
|
|
17
17
|
|
|
18
18
|
const config = mergeConfig({
|
|
19
19
|
debug: true,
|
|
20
|
-
apiBaseUrl: 'https://api.example.com'
|
|
20
|
+
apiBaseUrl: 'https://api.example.com',
|
|
21
21
|
});
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
### Device APIs
|
|
25
25
|
|
|
26
26
|
```typescript
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
camera,
|
|
29
|
+
geolocation,
|
|
30
|
+
sensors,
|
|
31
|
+
fileSystem,
|
|
32
|
+
} from '@aippy/runtime/device';
|
|
28
33
|
|
|
29
34
|
// Camera
|
|
30
35
|
const stream = await camera.getStream();
|
|
@@ -32,13 +37,13 @@ const photo = await camera.capturePhoto({ quality: 'high' });
|
|
|
32
37
|
|
|
33
38
|
// Geolocation
|
|
34
39
|
const position = await geolocation.getCurrentPosition();
|
|
35
|
-
const watchId = geolocation.watchPosition(
|
|
40
|
+
const watchId = geolocation.watchPosition(pos => {
|
|
36
41
|
console.log('Position:', pos);
|
|
37
42
|
});
|
|
38
43
|
|
|
39
44
|
// Sensors
|
|
40
45
|
const orientation = await sensors.getOrientation();
|
|
41
|
-
const cleanup = sensors.watchOrientation(
|
|
46
|
+
const cleanup = sensors.watchOrientation(data => {
|
|
42
47
|
console.log('Orientation:', data);
|
|
43
48
|
});
|
|
44
49
|
|
|
@@ -78,7 +83,7 @@ const patchedCtx = patchAudioContext(ctx);
|
|
|
78
83
|
// Unlock audio on user interaction (required on iOS)
|
|
79
84
|
button.onclick = async () => {
|
|
80
85
|
await patchedCtx.unlock();
|
|
81
|
-
|
|
86
|
+
|
|
82
87
|
// Use native Web Audio API as normal
|
|
83
88
|
const osc = patchedCtx.createOscillator();
|
|
84
89
|
osc.connect(patchedCtx.destination);
|
|
@@ -90,7 +95,9 @@ button.onclick = async () => {
|
|
|
90
95
|
### AI (Backend Proxy Adapter)
|
|
91
96
|
|
|
92
97
|
```typescript
|
|
93
|
-
// Default base URL: https://api.aippy.
|
|
98
|
+
// Default base URL: https://api.aippy.ai/aisdk/v1/ (no /api prefix)
|
|
99
|
+
// Resolved by core/env.ts at runtime — api.aippy.dev only when the page host
|
|
100
|
+
// ends in .aippynow.com or is localhost; everything else gets prod.
|
|
94
101
|
|
|
95
102
|
import { streamText, experimental_generateImage as generateImage } from 'ai';
|
|
96
103
|
import { aippyAIProvider } from '@aippy/runtime/ai';
|
|
@@ -120,6 +127,10 @@ const image = await generateImage({
|
|
|
120
127
|
console.log(image.image?.base64);
|
|
121
128
|
```
|
|
122
129
|
|
|
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
|
+
|
|
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 and host notification. 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
|
+
|
|
123
134
|
## Packages
|
|
124
135
|
|
|
125
136
|
- `@aippy/runtime/core` - Core types and configuration
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AippyOpenAIConfig } from './shared';
|
|
2
|
+
export interface CreditsRequestOptions extends AippyOpenAIConfig {
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
}
|
|
5
|
+
export interface DeductCreditsOptions extends CreditsRequestOptions {
|
|
6
|
+
/** One UUID per business action. Retries must reuse both the UUID and amount. */
|
|
7
|
+
eventId: string;
|
|
8
|
+
}
|
|
9
|
+
/** Return the authenticated user's VIP plus regular credit balance. */
|
|
10
|
+
export declare function getCredits(options?: CreditsRequestOptions): Promise<number>;
|
|
11
|
+
/** Deduct a positive integer amount. The server checks the balance atomically. */
|
|
12
|
+
export declare function deductCredits(amount: number, options: DeductCreditsOptions): Promise<void>;
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -41,4 +41,6 @@ export type { AippyOpenAIConfig } from './openai';
|
|
|
41
41
|
export { aippyChatConfig, type AippyUseChatOptions, type AippyUIConfig, type AippyChatConfig, UI_CHAT_ENDPOINT, } from './ui';
|
|
42
42
|
export { DEFAULT_BASE_URL, DEFAULT_UI_BASE_URL, DEFAULT_CHAT_MODEL, DEFAULT_CHAT_SYSTEM, resolveOpenAIConfig, resolveUIConfig, } from './shared';
|
|
43
43
|
export { normalizeError } from './errors';
|
|
44
|
+
export { getCredits, deductCredits, type CreditsRequestOptions, type DeductCreditsOptions, } from './credits';
|
|
45
|
+
export { generateCharacter3D, generateMotion, type GenerateCharacter3DInput, type GenerateMotionInput, type ViggleAsset, } from './viggle/generate';
|
|
44
46
|
export { type AIConfig, type AIConfigValue, type AIConfigItem, type NumberAIConfigItem, type BooleanAIConfigItem, type TextAIConfigItem, type EnumAIConfigItem, type AIConfigError, type AIConfigValues, validateAIConfig, parseAIConfig, loadAIConfig, getAIConfigValue, sendAIConfigToContainer, createAIConfig, } from './config';
|
package/dist/ai/index.js
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import { D as
|
|
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 {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
r as DEFAULT_BASE_URL,
|
|
6
|
+
i as DEFAULT_CHAT_MODEL,
|
|
7
|
+
n as DEFAULT_CHAT_SYSTEM,
|
|
8
|
+
A as DEFAULT_UI_BASE_URL,
|
|
9
9
|
C as UI_CHAT_ENDPOINT,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
D as
|
|
10
|
+
t as aippyAIProvider,
|
|
11
|
+
g as aippyChatConfig,
|
|
12
|
+
I as createAIConfig,
|
|
13
|
+
f as deductCredits,
|
|
14
|
+
_ as generateCharacter3D,
|
|
15
|
+
p as generateMotion,
|
|
16
|
+
E as getAIConfigValue,
|
|
17
|
+
T as getCredits,
|
|
18
|
+
U as loadAIConfig,
|
|
19
|
+
d as normalizeError,
|
|
20
|
+
D as parseAIConfig,
|
|
21
|
+
l as resolveOpenAIConfig,
|
|
22
|
+
L as resolveUIConfig,
|
|
23
|
+
m as sendAIConfigToContainer,
|
|
24
|
+
v as validateAIConfig
|
|
21
25
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface GenerateCharacter3DInput {
|
|
2
|
+
/** File from `<input type="file">`. The backend stores it and calls Viggle. */
|
|
3
|
+
image?: Blob;
|
|
4
|
+
imageUrl?: string;
|
|
5
|
+
prompt?: string;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
export interface GenerateMotionInput {
|
|
9
|
+
text: string;
|
|
10
|
+
durationSeconds?: number;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
export interface ViggleAsset {
|
|
14
|
+
url: string;
|
|
15
|
+
thumbnailUrl?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a rigged `.vsplat` character and wait until its CDN URL is ready.
|
|
19
|
+
* Call this from a user gesture. The request goes to the Aippy backend.
|
|
20
|
+
*/
|
|
21
|
+
export declare function generateCharacter3D(input: GenerateCharacter3DInput): Promise<ViggleAsset>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a 441-joint GLB motion from text and wait until its CDN URL is ready.
|
|
24
|
+
* Call this from a user gesture. The request goes to the Aippy backend.
|
|
25
|
+
*/
|
|
26
|
+
export declare function generateMotion(input: GenerateMotionInput): Promise<ViggleAsset>;
|
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,97 +1,101 @@
|
|
|
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
|
-
import { A as m, a as
|
|
4
|
-
import { S as
|
|
5
|
-
import { A as U, C as _, R as
|
|
6
|
-
import { CameraAPI as
|
|
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-C2rC9u_k.js";
|
|
5
|
+
import { A as U, C as _, R as D, a as T, p as h } from "../runtime-CmoG3v2m.js";
|
|
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";
|
|
8
8
|
import { a as ee, P as ae, p as re, b as se } from "../pwa-C5nXU0DN.js";
|
|
9
9
|
import { j as te } from "../url-c26cuIpu.js";
|
|
10
10
|
import { a as ne, b as pe } from "../useTweaks-C7BEMpV3.js";
|
|
11
|
-
import { c as me, b as
|
|
12
|
-
import { reportScore as
|
|
13
|
-
import { D as xe, d as Re, e as Ue, c as _e, U as
|
|
14
|
-
import { c as
|
|
15
|
-
import { hasNativeBridge as
|
|
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
|
+
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-CALy6Ol_.js";
|
|
14
|
+
import { c as je, u as qe } from "../hooks-D5lkty5r.js";
|
|
15
|
+
import { hasNativeBridge as ze } from "../native-bridge-BnvipFJc.js";
|
|
16
16
|
export {
|
|
17
17
|
U as AippyRuntime,
|
|
18
18
|
m as AippyRuntimeError,
|
|
19
|
-
|
|
19
|
+
y as CameraAPI,
|
|
20
20
|
_ as Cancellable,
|
|
21
21
|
xe as DEFAULT_BASE_URL,
|
|
22
22
|
Re as DEFAULT_CHAT_MODEL,
|
|
23
23
|
Ue as DEFAULT_CHAT_SYSTEM,
|
|
24
24
|
r as DEFAULT_CONFIG,
|
|
25
25
|
_e as DEFAULT_UI_BASE_URL,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
c as ERROR_CODES,
|
|
27
|
+
f as ERROR_PREFIX,
|
|
28
|
+
F as FileSystemAPI,
|
|
29
|
+
M as GeolocationAPI,
|
|
30
30
|
ee as PWAUtils,
|
|
31
31
|
ae as PerformanceMonitor,
|
|
32
32
|
G as PlatformDetector,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
D as ReceiveChannel,
|
|
34
|
+
d as SDK_NAME,
|
|
35
|
+
P as SensorsAPI,
|
|
36
|
+
De as UI_CHAT_ENDPOINT,
|
|
37
|
+
l as VERSION,
|
|
38
38
|
i as _resetCachedApiBaseUrl,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
Te as aippyAIProvider,
|
|
40
|
+
he as aippyChatConfig,
|
|
41
|
+
T as aippyRuntime,
|
|
42
42
|
ne as aippyTweaks,
|
|
43
43
|
pe as aippyTweaksRuntime,
|
|
44
44
|
O as camera,
|
|
45
45
|
z as checkFeatureSupport,
|
|
46
|
-
|
|
46
|
+
je as clearUserInfoCache,
|
|
47
47
|
K as compareVersions,
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
ve as createAIConfig,
|
|
49
|
+
I as createAippyHeaders,
|
|
50
50
|
E as createAippyHeadersAsync,
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
C as createCodeError,
|
|
52
|
+
g as createError,
|
|
53
53
|
me as createHiddenMediaElement,
|
|
54
|
+
ye as deductCredits,
|
|
54
55
|
b as fileSystem,
|
|
56
|
+
Fe as generateCharacter3D,
|
|
57
|
+
Me as generateMotion,
|
|
55
58
|
L as geolocation,
|
|
56
|
-
|
|
59
|
+
Pe as getAIConfigValue,
|
|
57
60
|
n as getAuthTokenAsync,
|
|
58
61
|
W as getAvailableFeatures,
|
|
59
62
|
s as getConfigFromEnv,
|
|
63
|
+
Oe as getCredits,
|
|
60
64
|
X as getFeatureVersionRequirements,
|
|
61
65
|
S as getVersionInfo,
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
ze as hasNativeBridge,
|
|
67
|
+
ce as isIOSDevice,
|
|
64
68
|
Y as isInIframe,
|
|
65
|
-
|
|
69
|
+
fe as isMediaStreamAudioSupported,
|
|
66
70
|
w as isMotionSupported,
|
|
67
71
|
H as isOrientationSupported,
|
|
68
72
|
te as joinUrl,
|
|
69
|
-
|
|
73
|
+
be as loadAIConfig,
|
|
70
74
|
o as mergeConfig,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
Le as normalizeError,
|
|
76
|
+
we as parseAIConfig,
|
|
77
|
+
Ce as patchAudioContext,
|
|
74
78
|
re as performanceMonitor,
|
|
75
79
|
J as platform,
|
|
76
|
-
|
|
80
|
+
h as processMotionData,
|
|
77
81
|
se as pwa,
|
|
78
|
-
|
|
82
|
+
le as reportScore,
|
|
79
83
|
N as requestMotionPermission,
|
|
80
84
|
Q as requireFeatureSupport,
|
|
81
85
|
p as resolveApiBaseUrl,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
He as resolveOpenAIConfig,
|
|
87
|
+
Ne as resolveUIConfig,
|
|
88
|
+
Ve as sendAIConfigToContainer,
|
|
89
|
+
Ie as sendEvent,
|
|
86
90
|
x as sendMessageToContainer,
|
|
87
91
|
V as sensors,
|
|
88
92
|
Z as showAlert,
|
|
89
93
|
Ee as updateScore,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
ge as useAudioContext,
|
|
95
|
+
ue as useSound,
|
|
96
|
+
qe as useUserInfo,
|
|
97
|
+
ke as validateAIConfig,
|
|
98
|
+
k as vibrate,
|
|
99
|
+
B as watchMotion,
|
|
100
|
+
j as watchOrientation
|
|
97
101
|
};
|
package/package.json
CHANGED
package/dist/helper-WRpB-6MD.js
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import { createOpenAICompatible as d } from "@ai-sdk/openai-compatible";
|
|
2
|
-
import { r as f } from "./bridge-CtB9L5kL.js";
|
|
3
|
-
import { s as m, a as b } from "./container-message-C3YXyTZj.js";
|
|
4
|
-
import { AISDKError as c, DefaultChatTransport as h } from "ai";
|
|
5
|
-
import { E as g, b as p, a as u } from "./errors-B3bDbQbD.js";
|
|
6
|
-
import { j as A } from "./url-c26cuIpu.js";
|
|
7
|
-
const j = `${f()}/aisdk/v1/`, x = `${f()}/aisdk/v1/ui/`, I = "gpt-5-nano", v = "";
|
|
8
|
-
function w(o = {}) {
|
|
9
|
-
return {
|
|
10
|
-
baseUrl: o.baseUrl ?? `${f()}/aisdk/v1/`
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function C(o = {}) {
|
|
14
|
-
return {
|
|
15
|
-
baseUrl: o.baseUrl ?? `${f()}/aisdk/v1/ui/`
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function O(o, e) {
|
|
19
|
-
const r = o.status;
|
|
20
|
-
if (e && typeof e == "object" && "error" in e) {
|
|
21
|
-
const t = e, n = t.error.code, s = n != null ? `AippyAIError_${n}` : `AippyAIError_${r}`, a = e;
|
|
22
|
-
return "appMessage" in a && a.appMessage !== void 0 && m(a.appMessage), new c({
|
|
23
|
-
name: s,
|
|
24
|
-
message: `${g.RUNTIME} ${t.error.message}`,
|
|
25
|
-
cause: {
|
|
26
|
-
type: t.error.type ?? void 0,
|
|
27
|
-
param: t.error.param ?? void 0,
|
|
28
|
-
status: r
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
if (e && typeof e == "object" && e !== null) {
|
|
33
|
-
const t = e;
|
|
34
|
-
"appMessage" in t && t.appMessage !== void 0 && m(t.appMessage);
|
|
35
|
-
}
|
|
36
|
-
return new c({
|
|
37
|
-
name: `AippyAIError_${r}`,
|
|
38
|
-
message: `${g.RUNTIME} Request failed with status ${r}`,
|
|
39
|
-
cause: { status: r }
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function l() {
|
|
43
|
-
return async (o, e) => {
|
|
44
|
-
const r = await b(e?.headers), t = await globalThis.fetch(o, { ...e, headers: r });
|
|
45
|
-
if (!t.ok) {
|
|
46
|
-
const n = await t.text().catch(() => null);
|
|
47
|
-
let s = null;
|
|
48
|
-
if (n)
|
|
49
|
-
try {
|
|
50
|
-
s = JSON.parse(n);
|
|
51
|
-
} catch {
|
|
52
|
-
s = { message: n };
|
|
53
|
-
}
|
|
54
|
-
throw O(t, s);
|
|
55
|
-
}
|
|
56
|
-
return t;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
const E = [
|
|
60
|
-
"gpt-image-1",
|
|
61
|
-
"gpt-image-1-mini",
|
|
62
|
-
"gpt-image-1.5"
|
|
63
|
-
];
|
|
64
|
-
function _(o) {
|
|
65
|
-
try {
|
|
66
|
-
const e = JSON.parse(o);
|
|
67
|
-
if (e.model && E.some((r) => e.model.startsWith(r))) {
|
|
68
|
-
const { response_format: r, ...t } = e;
|
|
69
|
-
return JSON.stringify(t);
|
|
70
|
-
}
|
|
71
|
-
} catch {
|
|
72
|
-
}
|
|
73
|
-
return o;
|
|
74
|
-
}
|
|
75
|
-
function J(o = {}) {
|
|
76
|
-
const { baseUrl: e } = w(o), r = l();
|
|
77
|
-
return d({
|
|
78
|
-
name: "aippy",
|
|
79
|
-
baseURL: e,
|
|
80
|
-
fetch: async (n, s) => n.toString().includes("/images/generations") && s?.method?.toUpperCase() === "POST" && s?.body ? r(n, {
|
|
81
|
-
...s,
|
|
82
|
-
body: _(s.body)
|
|
83
|
-
}) : r(n, 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 S = "/chat";
|
|
90
|
-
function B(o = {}) {
|
|
91
|
-
const { baseUrl: e } = C(o), r = o.model ?? I, t = o.system ?? v, n = o.api ?? A(e, S), s = { model: r, system: t }, a = l();
|
|
92
|
-
return {
|
|
93
|
-
transport: new h({
|
|
94
|
-
api: n,
|
|
95
|
-
body: s,
|
|
96
|
-
// Ensure token is fetched fresh for every request
|
|
97
|
-
fetch: a
|
|
98
|
-
})
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
function y(o) {
|
|
102
|
-
const e = [];
|
|
103
|
-
if (!o || typeof o != "object")
|
|
104
|
-
throw p("AIConfig must be an object", u.INVALID_CONFIG);
|
|
105
|
-
const r = o;
|
|
106
|
-
for (const [t, n] of Object.entries(r)) {
|
|
107
|
-
if (!n || typeof n != "object") {
|
|
108
|
-
e.push({ key: t, message: "Item must be an object" });
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
const s = n;
|
|
112
|
-
typeof s.index != "number" && e.push({ key: t, message: "index must be a number" }), typeof s.name != "string" && e.push({ key: t, message: "name must be a string" }), typeof s.description != "string" && e.push({ key: t, message: "description must be a string" });
|
|
113
|
-
const a = s.type;
|
|
114
|
-
if (!["number", "boolean", "text", "enum"].includes(a)) {
|
|
115
|
-
e.push({
|
|
116
|
-
key: t,
|
|
117
|
-
message: `type must be one of: number, boolean, text, enum (got: ${a})`
|
|
118
|
-
});
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
if (a === "number")
|
|
122
|
-
typeof s.value != "number" && e.push({ key: t, message: 'value must be a number for type "number"' }), s.min !== void 0 && typeof s.min != "number" && e.push({ key: t, message: "min must be a number" }), s.max !== void 0 && typeof s.max != "number" && e.push({ key: t, message: "max must be a number" }), s.step !== void 0 && typeof s.step != "number" && e.push({ key: t, message: "step must be a number" });
|
|
123
|
-
else if (a === "boolean")
|
|
124
|
-
typeof s.value != "boolean" && e.push({ key: t, message: 'value must be a boolean for type "boolean"' });
|
|
125
|
-
else if (a === "text")
|
|
126
|
-
typeof s.value != "string" && e.push({ key: t, message: 'value must be a string for type "text"' });
|
|
127
|
-
else if (a === "enum") {
|
|
128
|
-
if (!Array.isArray(s.options))
|
|
129
|
-
e.push({ key: t, message: 'options must be an array for type "enum"' });
|
|
130
|
-
else if (s.options.length === 0)
|
|
131
|
-
e.push({ key: t, message: 'options array cannot be empty for type "enum"' });
|
|
132
|
-
else
|
|
133
|
-
for (let i = 0; i < s.options.length; i++)
|
|
134
|
-
typeof s.options[i] != "string" && e.push({
|
|
135
|
-
key: t,
|
|
136
|
-
message: `options[${i}] must be a string`
|
|
137
|
-
});
|
|
138
|
-
typeof s.value != "string" ? e.push({ key: t, message: 'value must be a string for type "enum"' }) : Array.isArray(s.options) && !s.options.includes(s.value) && e.push({
|
|
139
|
-
key: t,
|
|
140
|
-
message: `value "${s.value}" is not in options: [${s.options.join(", ")}]`
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
s.group !== void 0 && typeof s.group != "string" && e.push({ key: t, message: "group must be a string" });
|
|
144
|
-
}
|
|
145
|
-
if (e.length > 0)
|
|
146
|
-
throw p(
|
|
147
|
-
`AIConfig validation failed with ${e.length} error(s)`,
|
|
148
|
-
u.INVALID_CONFIG,
|
|
149
|
-
{ errors: e }
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
function H(o) {
|
|
153
|
-
let e;
|
|
154
|
-
try {
|
|
155
|
-
e = JSON.parse(o);
|
|
156
|
-
} catch (r) {
|
|
157
|
-
throw p(
|
|
158
|
-
`Invalid JSON: ${r instanceof Error ? r.message : String(r)}`,
|
|
159
|
-
u.INVALID_CONFIG
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
return y(e), e;
|
|
163
|
-
}
|
|
164
|
-
function U(o) {
|
|
165
|
-
return y(o), o;
|
|
166
|
-
}
|
|
167
|
-
function N(o, e) {
|
|
168
|
-
const r = o[e];
|
|
169
|
-
if (!r)
|
|
170
|
-
throw p(
|
|
171
|
-
`AIConfig key "${e}" not found`,
|
|
172
|
-
u.INVALID_CONFIG,
|
|
173
|
-
{ key: e }
|
|
174
|
-
);
|
|
175
|
-
return r.value;
|
|
176
|
-
}
|
|
177
|
-
function T(o) {
|
|
178
|
-
if (!(typeof window > "u"))
|
|
179
|
-
try {
|
|
180
|
-
const e = window.webkit?.messageHandlers?.aippyListener;
|
|
181
|
-
if (e)
|
|
182
|
-
try {
|
|
183
|
-
const r = {
|
|
184
|
-
command: "ai.initialize",
|
|
185
|
-
parameters: JSON.stringify(o)
|
|
186
|
-
};
|
|
187
|
-
e.postMessage(r);
|
|
188
|
-
} catch (r) {
|
|
189
|
-
console.warn("❌ [Aippy AI Config] Failed to send config to iOS app:", r);
|
|
190
|
-
}
|
|
191
|
-
if (window.parent && window.parent !== window)
|
|
192
|
-
try {
|
|
193
|
-
const r = {
|
|
194
|
-
type: "ai.initialize",
|
|
195
|
-
config: JSON.stringify(o)
|
|
196
|
-
};
|
|
197
|
-
window.parent.postMessage(r, "*");
|
|
198
|
-
} catch (r) {
|
|
199
|
-
console.warn("❌ [Aippy AI Config] Failed to send config to parent window:", r);
|
|
200
|
-
}
|
|
201
|
-
} catch (e) {
|
|
202
|
-
console.warn("⚠️ [Aippy AI Config] Failed to send config:", e);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
function P(o) {
|
|
206
|
-
const e = U(o);
|
|
207
|
-
return T(e), new Proxy({}, {
|
|
208
|
-
get(r, t) {
|
|
209
|
-
if (typeof t == "string")
|
|
210
|
-
try {
|
|
211
|
-
return N(e, t);
|
|
212
|
-
} catch {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
has(r, t) {
|
|
217
|
-
return typeof t != "string" ? !1 : t in e;
|
|
218
|
-
},
|
|
219
|
-
ownKeys(r) {
|
|
220
|
-
return Object.keys(e);
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
export {
|
|
225
|
-
j as D,
|
|
226
|
-
S as U,
|
|
227
|
-
J as a,
|
|
228
|
-
B as b,
|
|
229
|
-
x as c,
|
|
230
|
-
I as d,
|
|
231
|
-
v as e,
|
|
232
|
-
C as f,
|
|
233
|
-
N as g,
|
|
234
|
-
P as h,
|
|
235
|
-
U as l,
|
|
236
|
-
O as n,
|
|
237
|
-
H as p,
|
|
238
|
-
w as r,
|
|
239
|
-
T as s,
|
|
240
|
-
y as v
|
|
241
|
-
};
|