@aippy/runtime 0.2.7-dev.0 → 0.2.7-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.
Files changed (40) hide show
  1. package/dist/ai/config/bridge.d.ts +23 -0
  2. package/dist/ai/config/helper.d.ts +43 -0
  3. package/dist/ai/config/index.d.ts +11 -0
  4. package/dist/ai/config/parser.d.ts +60 -0
  5. package/dist/ai/config/types.d.ts +80 -0
  6. package/dist/ai/errors.d.ts +4 -0
  7. package/dist/ai/index.d.ts +8 -7
  8. package/dist/ai/index.js +22 -19
  9. package/dist/ai/openai/index.d.ts +2 -2
  10. package/dist/ai/openai/provider.d.ts +3 -3
  11. package/dist/ai/ui/config.d.ts +2 -58
  12. package/dist/ai/ui/endpoints.d.ts +0 -4
  13. package/dist/ai/ui/index.d.ts +3 -5
  14. package/dist/ai/ui/types.d.ts +0 -25
  15. package/dist/bridge-N9ELFpfV.js +430 -0
  16. package/dist/container-message-DGrno17o.js +31 -0
  17. package/dist/core/container-message.d.ts +81 -0
  18. package/dist/core/index.d.ts +1 -0
  19. package/dist/core/index.js +18 -16
  20. package/dist/device/index.js +1 -1
  21. package/dist/helper-CsFko67T.js +264 -0
  22. package/dist/index/index.js +110 -93
  23. package/dist/{native-bridge-JAmH-zTN.js → native-bridge-BnvipFJc.js} +1 -1
  24. package/dist/pwa-CilSlaik.js +249 -0
  25. package/dist/ui-D6IZ1jrR.js +119 -0
  26. package/dist/user/bridge.d.ts +83 -3
  27. package/dist/user/hooks.d.ts +36 -0
  28. package/dist/user/index.d.ts +4 -3
  29. package/dist/user/index.js +35 -25
  30. package/dist/user/types.d.ts +2 -0
  31. package/dist/userSessionInfo-DFvsuELU.js +229 -0
  32. package/dist/utils/index.d.ts +1 -0
  33. package/dist/utils/index.js +9 -7
  34. package/dist/utils/platform.d.ts +7 -0
  35. package/dist/utils/ui.d.ts +11 -0
  36. package/package.json +4 -2
  37. package/dist/bridge-DdAH4txB.js +0 -222
  38. package/dist/errors-DWRVLkVz.js +0 -152
  39. package/dist/pwa-8DGmPqLV.js +0 -341
  40. package/dist/userSessionInfo-CBk9ywXi.js +0 -186
@@ -0,0 +1,264 @@
1
+ import { createOpenAICompatible as l } from "@ai-sdk/openai-compatible";
2
+ import "react";
3
+ import { h as d } from "./bridge-N9ELFpfV.js";
4
+ import { DefaultChatTransport as y, AISDKError as i } from "ai";
5
+ import { s as u } from "./container-message-DGrno17o.js";
6
+ const m = "https://api.aippy.dev", h = `${m}/aisdk/v1/`, A = `${m}/aisdk/v1/ui/`, b = "gpt-5-nano", E = "";
7
+ function w(r = {}) {
8
+ return {
9
+ baseUrl: r.baseUrl ?? h
10
+ };
11
+ }
12
+ function I(r = {}) {
13
+ return {
14
+ baseUrl: r.baseUrl ?? A
15
+ };
16
+ }
17
+ function v(r, e) {
18
+ const n = r.endsWith("/") ? r : `${r}/`, t = e.startsWith("/") ? e.slice(1) : e;
19
+ return new URL(t, n).href;
20
+ }
21
+ function c() {
22
+ return async (r, e) => {
23
+ const n = await d(), t = new Headers(e?.headers);
24
+ return t.set("Authorization", `Bearer ${n}`), globalThis.fetch(r, { ...e, headers: t });
25
+ };
26
+ }
27
+ const _ = [
28
+ "gpt-image-1",
29
+ "gpt-image-1-mini",
30
+ "gpt-image-1.5"
31
+ ];
32
+ function S(r) {
33
+ try {
34
+ const e = JSON.parse(r);
35
+ if (e.model && _.some((n) => e.model.startsWith(n))) {
36
+ const { response_format: n, ...t } = e;
37
+ return JSON.stringify(t);
38
+ }
39
+ } catch {
40
+ }
41
+ return r;
42
+ }
43
+ function j(r = {}) {
44
+ const { baseUrl: e } = w(r), n = c();
45
+ return l({
46
+ name: "aippy",
47
+ baseURL: e,
48
+ fetch: async (a, s) => a.toString().includes("/images/generations") && s?.method?.toUpperCase() === "POST" && s?.body ? n(a, {
49
+ ...s,
50
+ body: S(s.body)
51
+ }) : n(a, s),
52
+ // Enable structured outputs support (json_schema response format)
53
+ // This is required for Output.object() and Output.array() to work properly
54
+ supportsStructuredOutputs: !0
55
+ });
56
+ }
57
+ const C = "/chat";
58
+ function F(r = {}) {
59
+ const { baseUrl: e } = I(r), n = r.model ?? b, t = r.system ?? E, a = r.api ?? v(e, C), s = { model: n, system: t }, o = c();
60
+ return {
61
+ transport: new y({
62
+ api: a,
63
+ body: s,
64
+ // Ensure token is fetched fresh for every request
65
+ fetch: o
66
+ })
67
+ };
68
+ }
69
+ function L(r, e) {
70
+ const n = r.status;
71
+ if (e && typeof e == "object" && "error" in e) {
72
+ const t = e, a = t.error.code, s = a != null ? `AippyAIError_${a}` : `AippyAIError_${n}`, o = e;
73
+ return "appMessage" in o && o.appMessage !== void 0 ? u(o.appMessage) : "containerErrorData" in o && o.containerErrorData !== void 0 && u(o.containerErrorData), new i({
74
+ name: s,
75
+ message: t.error.message,
76
+ cause: {
77
+ type: t.error.type ?? void 0,
78
+ param: t.error.param ?? void 0,
79
+ status: n
80
+ }
81
+ });
82
+ }
83
+ if (e && typeof e == "object" && e !== null) {
84
+ const t = e;
85
+ "appMessage" in t && t.appMessage !== void 0 ? u(t.appMessage) : "containerErrorData" in t && t.containerErrorData !== void 0 && u(t.containerErrorData);
86
+ }
87
+ return new i({
88
+ name: `AippyAIError_${n}`,
89
+ message: `Request failed with status ${n}`,
90
+ cause: { status: n }
91
+ });
92
+ }
93
+ function x() {
94
+ return new i({
95
+ name: "AippyAIError_MISSING_TOKEN",
96
+ message: "User token is required. Ensure user credentials are available via initUserBridge()."
97
+ });
98
+ }
99
+ function k() {
100
+ return new i({
101
+ name: "AippyAIError_REQUEST_ABORTED",
102
+ message: "Request was aborted"
103
+ });
104
+ }
105
+ function B(r) {
106
+ const e = r instanceof Error ? r.message : "Network request failed";
107
+ return new i({
108
+ name: "AippyAIError_NETWORK_ERROR",
109
+ message: e,
110
+ cause: r instanceof Error ? r : String(r)
111
+ });
112
+ }
113
+ function P(r) {
114
+ return new i({
115
+ name: "AippyAIError_PARSE_ERROR",
116
+ message: `Failed to parse response: ${r}`
117
+ });
118
+ }
119
+ class f extends Error {
120
+ constructor(e, n) {
121
+ super(e), this.errors = n, this.name = "AIConfigValidationError";
122
+ }
123
+ }
124
+ function g(r) {
125
+ const e = [];
126
+ if (!r || typeof r != "object")
127
+ throw new f("AIConfig must be an object", []);
128
+ const n = r;
129
+ for (const [t, a] of Object.entries(n)) {
130
+ if (!a || typeof a != "object") {
131
+ e.push({ key: t, message: "Item must be an object" });
132
+ continue;
133
+ }
134
+ const s = a;
135
+ 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" });
136
+ const o = s.type;
137
+ if (!["number", "boolean", "text", "enum"].includes(o)) {
138
+ e.push({
139
+ key: t,
140
+ message: `type must be one of: number, boolean, text, enum (got: ${o})`
141
+ });
142
+ continue;
143
+ }
144
+ if (o === "number")
145
+ 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" });
146
+ else if (o === "boolean")
147
+ typeof s.value != "boolean" && e.push({ key: t, message: 'value must be a boolean for type "boolean"' });
148
+ else if (o === "text")
149
+ typeof s.value != "string" && e.push({ key: t, message: 'value must be a string for type "text"' });
150
+ else if (o === "enum") {
151
+ if (!Array.isArray(s.options))
152
+ e.push({ key: t, message: 'options must be an array for type "enum"' });
153
+ else if (s.options.length === 0)
154
+ e.push({ key: t, message: 'options array cannot be empty for type "enum"' });
155
+ else
156
+ for (let p = 0; p < s.options.length; p++)
157
+ typeof s.options[p] != "string" && e.push({
158
+ key: t,
159
+ message: `options[${p}] must be a string`
160
+ });
161
+ 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({
162
+ key: t,
163
+ message: `value "${s.value}" is not in options: [${s.options.join(", ")}]`
164
+ });
165
+ }
166
+ s.group !== void 0 && typeof s.group != "string" && e.push({ key: t, message: "group must be a string" });
167
+ }
168
+ if (e.length > 0)
169
+ throw new f(
170
+ `AIConfig validation failed with ${e.length} error(s)`,
171
+ e
172
+ );
173
+ }
174
+ function J(r) {
175
+ let e;
176
+ try {
177
+ e = JSON.parse(r);
178
+ } catch (n) {
179
+ throw new f("Invalid JSON", [
180
+ {
181
+ key: "",
182
+ message: `JSON parse error: ${n instanceof Error ? n.message : String(n)}`
183
+ }
184
+ ]);
185
+ }
186
+ return g(e), e;
187
+ }
188
+ function O(r) {
189
+ return g(r), r;
190
+ }
191
+ function T(r, e) {
192
+ const n = r[e];
193
+ if (!n)
194
+ throw new Error(`AIConfig key "${e}" not found`);
195
+ return n.value;
196
+ }
197
+ function U(r) {
198
+ if (!(typeof window > "u"))
199
+ try {
200
+ const e = window.webkit?.messageHandlers?.aippyListener;
201
+ if (e)
202
+ try {
203
+ const n = {
204
+ command: "ai.initialize",
205
+ parameters: JSON.stringify(r)
206
+ };
207
+ e.postMessage(n);
208
+ } catch (n) {
209
+ console.warn("❌ [Aippy AI Config] Failed to send config to iOS app:", n);
210
+ }
211
+ if (window.parent && window.parent !== window)
212
+ try {
213
+ const n = {
214
+ type: "ai.initialize",
215
+ config: JSON.stringify(r)
216
+ };
217
+ window.parent.postMessage(n, "*");
218
+ } catch (n) {
219
+ console.warn("❌ [Aippy AI Config] Failed to send config to parent window:", n);
220
+ }
221
+ } catch (e) {
222
+ console.warn("⚠️ [Aippy AI Config] Failed to send config:", e);
223
+ }
224
+ }
225
+ function z(r) {
226
+ const e = O(r);
227
+ return U(e), new Proxy({}, {
228
+ get(n, t) {
229
+ if (typeof t == "string")
230
+ try {
231
+ return T(e, t);
232
+ } catch {
233
+ return;
234
+ }
235
+ },
236
+ has(n, t) {
237
+ return typeof t != "string" ? !1 : t in e;
238
+ },
239
+ ownKeys(n) {
240
+ return Object.keys(e);
241
+ }
242
+ });
243
+ }
244
+ export {
245
+ f as A,
246
+ h as D,
247
+ C as U,
248
+ j as a,
249
+ F as b,
250
+ A as c,
251
+ b as d,
252
+ E as e,
253
+ k as f,
254
+ B as g,
255
+ J as h,
256
+ T as i,
257
+ z as j,
258
+ O as l,
259
+ x as m,
260
+ L as n,
261
+ P as p,
262
+ U as s,
263
+ g as v
264
+ };
@@ -1,101 +1,118 @@
1
- import { DEFAULT_CONFIG as r, SDK_NAME as s, VERSION as o, getConfigFromEnv as t, getVersionInfo as i, mergeConfig as n } from "../core/index.js";
2
- import { A as m, E as d, c as u } from "../errors-CDEBaBxB.js";
3
- import { A as C, C as c, R as E, a as l, p as A } from "../runtime-CmoG3v2m.js";
4
- import { CameraAPI as I, FileSystemAPI as U, GeolocationAPI as S, SensorsAPI as T, camera as P, fileSystem as y, geolocation as h, isMotionSupported as _, isOrientationSupported as O, requestMotionPermission as D, sensors as x, vibrate as R, watchMotion as k, watchOrientation as M } from "../device/index.js";
5
- import { c as F, a as N, P as L, b as B, p as v, d as w } from "../pwa-8DGmPqLV.js";
6
- import { a as H, b as j } from "../useTweaks-QxMRmg7i.js";
7
- import { c as Q, a as V, b as J, i as z, p as K, u as W } from "../useAudioContext-CNQQSTab.js";
8
- import { reportScore as X, sendEvent as Z, updateScore as $ } from "../leaderboard/index.js";
9
- import { D as ae, i as re, j as se, h as oe, U as te, f as ie, g as ne, k as pe, a as me, b as de, c as ue, e as fe, d as Ce, m as ce, l as Ee, n as le, p as Ae } from "../errors-DWRVLkVz.js";
10
- import { f as Ie, b as Ue, h as Se, l as Te, j as Pe, g as ye, k as he, e as _e, i as Oe, c as De, d as xe, r as Re, s as ke, a as Me, t as be } from "../bridge-DdAH4txB.js";
11
- import { e as Ne, f as Le, g as Be, a as ve, u as we, b as Ge, d as He, c as je, h as qe } from "../userSessionInfo-CBk9ywXi.js";
12
- import { h as Ve } from "../native-bridge-JAmH-zTN.js";
1
+ import { DEFAULT_CONFIG as a, SDK_NAME as s, VERSION as o, getConfigFromEnv as t, getVersionInfo as n, mergeConfig as i } from "../core/index.js";
2
+ import { A as p, E as d, c as m } from "../errors-CDEBaBxB.js";
3
+ import { s as C } from "../container-message-DGrno17o.js";
4
+ import { A as I, C as c, R as l, a as g, p as U } from "../runtime-CmoG3v2m.js";
5
+ import { CameraAPI as S, FileSystemAPI as h, GeolocationAPI as P, SensorsAPI as y, camera as T, fileSystem as x, geolocation as F, isMotionSupported as _, isOrientationSupported as D, requestMotionPermission as R, sensors as M, vibrate as k, watchMotion as O, watchOrientation as v } from "../device/index.js";
6
+ import { P as w, p as L, s as q } from "../ui-D6IZ1jrR.js";
7
+ import { a as N, P as B, p as H, b as V } from "../pwa-CilSlaik.js";
8
+ import { a as Q, b as z } from "../useTweaks-QxMRmg7i.js";
9
+ import { c as K, a as W, b as Y, i as X, p as Z, u as $ } from "../useAudioContext-CNQQSTab.js";
10
+ import { reportScore as re, sendEvent as ae, updateScore as se } from "../leaderboard/index.js";
11
+ import { A as te, D as ne, d as ie, e as fe, c as pe, U as de, f as me, a as ue, a as Ce, b as Ae, j as Ie, i as ce, l as le, m as ge, g as Ue, n as Ee, h as Se, p as he, s as Pe, v as ye } from "../helper-CsFko67T.js";
12
+ import { f as xe, q as Fe, b as _e, h as De, l as Re, o as Me, j as ke, n as Oe, w as ve, g as be, k as we, p as Le, e as qe, i as Ge, c as Ne, d as Be, r as He, u as Ve, m as je, s as Qe, a as ze, t as Je, v as Ke } from "../bridge-N9ELFpfV.js";
13
+ import { i as Ye, f as Xe, h as Ze, g as $e, a as er, u as rr, b as ar, d as sr, c as or, e as tr, j as nr } from "../userSessionInfo-DFvsuELU.js";
14
+ import { hasNativeBridge as fr } from "../native-bridge-BnvipFJc.js";
13
15
  export {
14
- C as AippyRuntime,
15
- m as AippyRuntimeError,
16
- I as CameraAPI,
16
+ te as AIConfigValidationError,
17
+ I as AippyRuntime,
18
+ p as AippyRuntimeError,
19
+ S as CameraAPI,
17
20
  c as Cancellable,
18
- ae as DEFAULT_BASE_URL,
19
- re as DEFAULT_CHAT_MODEL,
20
- se as DEFAULT_CHAT_SYSTEM,
21
- r as DEFAULT_CONFIG,
22
- oe as DEFAULT_UI_BASE_URL,
21
+ ne as DEFAULT_BASE_URL,
22
+ ie as DEFAULT_CHAT_MODEL,
23
+ fe as DEFAULT_CHAT_SYSTEM,
24
+ a as DEFAULT_CONFIG,
25
+ pe as DEFAULT_UI_BASE_URL,
23
26
  d as ERROR_CODES,
24
- U as FileSystemAPI,
25
- S as GeolocationAPI,
26
- F as PWAUtils,
27
- N as PerformanceMonitor,
28
- L as PlatformDetector,
29
- E as ReceiveChannel,
27
+ h as FileSystemAPI,
28
+ P as GeolocationAPI,
29
+ N as PWAUtils,
30
+ B as PerformanceMonitor,
31
+ w as PlatformDetector,
32
+ l as ReceiveChannel,
30
33
  s as SDK_NAME,
31
- T as SensorsAPI,
32
- te as UI_CHAT_ENDPOINT,
33
- ie as UI_COMPLETION_ENDPOINT,
34
- ne as UI_OBJECT_ENDPOINT,
34
+ y as SensorsAPI,
35
+ de as UI_CHAT_ENDPOINT,
35
36
  o as VERSION,
36
- pe as abortedError,
37
- me as aippy,
38
- de as aippyChatConfig,
39
- ue as aippyCompletionConfig,
40
- fe as aippyObjectBaseConfig,
41
- Ce as aippyObjectConfig,
42
- l as aippyRuntime,
43
- H as aippyTweaks,
44
- j as aippyTweaksRuntime,
45
- Ie as autoRequestCredentials,
46
- P as camera,
47
- Ne as clearProfileCache,
48
- u as createError,
49
- Q as createHiddenMediaElement,
50
- V as createHiddenVideoElement,
51
- Le as fetchUserProfile,
52
- y as fileSystem,
53
- h as geolocation,
54
- Ue as getAuthToken,
55
- Se as getAuthTokenAsync,
56
- Te as getCachedCredentials,
37
+ me as abortedError,
38
+ ue as aippy,
39
+ Ce as aippyAIProvider,
40
+ Ae as aippyChatConfig,
41
+ g as aippyRuntime,
42
+ Q as aippyTweaks,
43
+ z as aippyTweaksRuntime,
44
+ xe as autoRequestCredentials,
45
+ T as camera,
46
+ Fe as clearCachedUserInfo,
47
+ Ye as clearProfileCache,
48
+ Xe as clearUserInfoCache,
49
+ Ie as createAIConfig,
50
+ m as createError,
51
+ K as createHiddenMediaElement,
52
+ W as createHiddenVideoElement,
53
+ Ze as fetchUserProfile,
54
+ x as fileSystem,
55
+ F as geolocation,
56
+ ce as getAIConfigValue,
57
+ _e as getAuthToken,
58
+ De as getAuthTokenAsync,
59
+ Re as getCachedCredentials,
60
+ Me as getCachedUserInfo,
57
61
  t as getConfigFromEnv,
58
- Be as getCurrentUserId,
59
- Pe as getCurrentUserIdAsync,
60
- ye as getUserSdkConfig,
61
- i as getVersionInfo,
62
- he as hasCredentials,
63
- Ve as hasNativeBridge,
64
- _e as initUserBridge,
65
- Oe as initUserSdk,
66
- J as isIOSDevice,
67
- De as isInIframe,
68
- z as isMediaStreamAudioSupported,
62
+ $e as getCurrentUserId,
63
+ ke as getCurrentUserIdAsync,
64
+ Oe as getUserInfoAsync,
65
+ ve as getUserInfoFromParent,
66
+ be as getUserSdkConfig,
67
+ n as getVersionInfo,
68
+ we as hasCredentials,
69
+ fr as hasNativeBridge,
70
+ Le as hasUserInfo,
71
+ qe as initUserBridge,
72
+ Ge as initUserSdk,
73
+ Y as isIOSDevice,
74
+ Ne as isInIframe,
75
+ X as isMediaStreamAudioSupported,
69
76
  _ as isMotionSupported,
70
- O as isOrientationSupported,
71
- n as mergeConfig,
72
- ce as missingTokenError,
73
- Ee as networkError,
74
- le as normalizeError,
75
- Ae as parseError,
76
- K as patchAudioContext,
77
- B as performanceMonitor,
78
- v as platform,
79
- A as processMotionData,
80
- w as pwa,
81
- X as reportScore,
82
- xe as requestCredentialsFromParent,
83
- Re as requestCredentialsFromiOS,
84
- D as requestMotionPermission,
85
- Z as sendEvent,
86
- x as sensors,
87
- ke as setAuthToken,
88
- Me as setCurrentUserId,
89
- be as tryGetCredentialsFromParentStorage,
90
- $ as updateScore,
91
- W as useAudioContext,
92
- ve as useAuthToken,
93
- we as useCurrentUserId,
94
- Ge as useGetCurrentUserProfileQuery,
95
- He as useGetJoinedUserProfilesQuery,
96
- je as useGetUserProfileByIdQuery,
97
- qe as userSessionInfo,
98
- R as vibrate,
99
- k as watchMotion,
100
- M as watchOrientation
77
+ D as isOrientationSupported,
78
+ le as loadAIConfig,
79
+ i as mergeConfig,
80
+ ge as missingTokenError,
81
+ Ue as networkError,
82
+ Ee as normalizeError,
83
+ Se as parseAIConfig,
84
+ he as parseError,
85
+ Z as patchAudioContext,
86
+ H as performanceMonitor,
87
+ L as platform,
88
+ U as processMotionData,
89
+ V as pwa,
90
+ re as reportScore,
91
+ Be as requestCredentialsFromParent,
92
+ He as requestCredentialsFromiOS,
93
+ R as requestMotionPermission,
94
+ Ve as requestUserInfoFromParent,
95
+ je as requestUserInfoFromiOS,
96
+ Pe as sendAIConfigToContainer,
97
+ ae as sendEvent,
98
+ C as sendMessageToContainer,
99
+ M as sensors,
100
+ Qe as setAuthToken,
101
+ ze as setCurrentUserId,
102
+ q as showAlert,
103
+ Je as tryGetCredentialsFromParentStorage,
104
+ Ke as tryGetUserInfoFromParentStorage,
105
+ se as updateScore,
106
+ $ as useAudioContext,
107
+ er as useAuthToken,
108
+ rr as useCurrentUserId,
109
+ ar as useGetCurrentUserProfileQuery,
110
+ sr as useGetJoinedUserProfilesQuery,
111
+ or as useGetUserProfileByIdQuery,
112
+ tr as useUserInfo,
113
+ nr as userSessionInfo,
114
+ ye as validateAIConfig,
115
+ k as vibrate,
116
+ O as watchMotion,
117
+ v as watchOrientation
101
118
  };
@@ -2,5 +2,5 @@ function a() {
2
2
  return typeof window < "u" && !!window.webkit && !!window.webkit?.messageHandlers && !!window.webkit?.messageHandlers?.aippyListener;
3
3
  }
4
4
  export {
5
- a as h
5
+ a as hasNativeBridge
6
6
  };