@aippy/runtime 0.2.7-dev.6 → 0.2.7-dev.7

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.
@@ -6,6 +6,6 @@
6
6
  */
7
7
  export type { AIConfig, AIConfigValue, AIConfigItem, NumberAIConfigItem, BooleanAIConfigItem, TextAIConfigItem, EnumAIConfigItem, AIConfigError, } from './types';
8
8
  export type { AIConfigValues } from './helper';
9
- export { AIConfigValidationError, validateAIConfig, parseAIConfig, loadAIConfig, getAIConfigValue, } from './parser';
9
+ export { validateAIConfig, parseAIConfig, loadAIConfig, getAIConfigValue, } from './parser';
10
10
  export { sendAIConfigToContainer } from './bridge';
11
11
  export { createAIConfig } from './helper';
@@ -1,16 +1,9 @@
1
- import { AIConfig, AIConfigError } from './types';
2
- /**
3
- * Custom error class for AI configuration validation failures
4
- */
5
- export declare class AIConfigValidationError extends Error {
6
- readonly errors: AIConfigError[];
7
- constructor(message: string, errors: AIConfigError[]);
8
- }
1
+ import { AIConfig } from './types';
9
2
  /**
10
3
  * Validates an AI configuration object
11
4
  *
12
5
  * @param config - The configuration object to validate
13
- * @throws {AIConfigValidationError} If validation fails
6
+ * @throws {AippyRuntimeError} If validation fails
14
7
  */
15
8
  export declare function validateAIConfig(config: unknown): asserts config is AIConfig;
16
9
  /**
@@ -18,7 +11,7 @@ export declare function validateAIConfig(config: unknown): asserts config is AIC
18
11
  *
19
12
  * @param json - JSON string to parse
20
13
  * @returns Validated AIConfig object
21
- * @throws {AIConfigValidationError} If JSON is invalid or validation fails
14
+ * @throws {AippyRuntimeError} If JSON is invalid or validation fails
22
15
  *
23
16
  * @example
24
17
  * ```ts
@@ -34,7 +27,7 @@ export declare function parseAIConfig(json: string): AIConfig;
34
27
  *
35
28
  * @param config - Configuration object (usually from JSON import)
36
29
  * @returns Validated AIConfig object
37
- * @throws {AIConfigValidationError} If validation fails
30
+ * @throws {AippyRuntimeError} If validation fails
38
31
  *
39
32
  * @example
40
33
  * ```ts
@@ -49,7 +42,7 @@ export declare function loadAIConfig(config: unknown): AIConfig;
49
42
  * @param config - The AIConfig object
50
43
  * @param key - Configuration key to retrieve
51
44
  * @returns The value of the configuration item
52
- * @throws {Error} If the key is not found
45
+ * @throws {AippyRuntimeError} If the key is not found
53
46
  *
54
47
  * @example
55
48
  * ```ts
@@ -2,5 +2,6 @@ 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
+ * Uses [Aippy Runtime] prefix - these errors are NOT reported to LLM.
5
6
  */
6
7
  export declare function normalizeError(response: Response, body?: unknown): AISDKError;
@@ -41,4 +41,4 @@ 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, } from './shared';
43
43
  export { normalizeError } from './errors';
44
- export { type AIConfig, type AIConfigValue, type AIConfigItem, type NumberAIConfigItem, type BooleanAIConfigItem, type TextAIConfigItem, type EnumAIConfigItem, type AIConfigError, type AIConfigValues, AIConfigValidationError, validateAIConfig, parseAIConfig, loadAIConfig, getAIConfigValue, sendAIConfigToContainer, createAIConfig, } from './config';
44
+ 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,20 +1,19 @@
1
- import { A, D as r, d as n, e as C, c as e, U as E, a as I, b as _, f, g, l as T, n as p, p as t, s as U, v as D } from "../helper-yKJ_6uB-.js";
1
+ import { D as i, d as r, e, c as n, U as C, a as _, b as E, f as I, g as T, l as f, n as g, p, s as U, v as t } from "../helper-BjRhidue.js";
2
2
  import "react";
3
- import "../bridge-BKcAlLAd.js";
3
+ import "../bridge-BQQ3PfSO.js";
4
4
  export {
5
- A as AIConfigValidationError,
6
- r as DEFAULT_BASE_URL,
7
- n as DEFAULT_CHAT_MODEL,
8
- C as DEFAULT_CHAT_SYSTEM,
9
- e as DEFAULT_UI_BASE_URL,
10
- E as UI_CHAT_ENDPOINT,
11
- I as aippyAIProvider,
12
- _ as aippyChatConfig,
13
- f as createAIConfig,
14
- g as getAIConfigValue,
15
- T as loadAIConfig,
16
- p as normalizeError,
17
- t as parseAIConfig,
5
+ i as DEFAULT_BASE_URL,
6
+ r as DEFAULT_CHAT_MODEL,
7
+ e as DEFAULT_CHAT_SYSTEM,
8
+ n as DEFAULT_UI_BASE_URL,
9
+ C as UI_CHAT_ENDPOINT,
10
+ _ as aippyAIProvider,
11
+ E as aippyChatConfig,
12
+ I as createAIConfig,
13
+ T as getAIConfigValue,
14
+ f as loadAIConfig,
15
+ g as normalizeError,
16
+ p as parseAIConfig,
18
17
  U as sendAIConfigToContainer,
19
- D as validateAIConfig
18
+ t as validateAIConfig
20
19
  };
@@ -1,41 +1,42 @@
1
- var u = Object.defineProperty;
2
- var l = (t, e, n) => e in t ? u(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var c = (t, e, n) => l(t, typeof e != "symbol" ? e + "" : e, n);
4
- import { UAParser as m } from "ua-parser-js";
5
- import { hasNativeBridge as f } from "./native-bridge-BnvipFJc.js";
6
- function w() {
1
+ var l = Object.defineProperty;
2
+ var m = (r, e, n) => e in r ? l(r, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[e] = n;
3
+ var c = (r, e, n) => m(r, typeof e != "symbol" ? e + "" : e, n);
4
+ import { UAParser as f } from "ua-parser-js";
5
+ import { hasNativeBridge as w } from "./native-bridge-BnvipFJc.js";
6
+ import { c as h, a as g } from "./errors-B3bDbQbD.js";
7
+ function b() {
7
8
  try {
8
9
  return typeof window < "u" && window.parent !== window;
9
10
  } catch {
10
11
  return !0;
11
12
  }
12
13
  }
13
- function h(t, e) {
14
- const n = t.split(".").map(Number), r = e.split(".").map(Number), o = Math.max(n.length, r.length);
15
- for (let i = 0; i < o; i++) {
16
- const s = n[i] || 0, a = r[i] || 0;
17
- if (s < a) return -1;
18
- if (s > a) return 1;
14
+ function v(r, e) {
15
+ const n = r.split(".").map(Number), t = e.split(".").map(Number), i = Math.max(n.length, t.length);
16
+ for (let o = 0; o < i; o++) {
17
+ const p = n[o] || 0, s = t[o] || 0;
18
+ if (p < s) return -1;
19
+ if (p > s) return 1;
19
20
  }
20
21
  return 0;
21
22
  }
22
- class g {
23
+ class x {
23
24
  constructor() {
24
25
  c(this, "parser");
25
- this.parser = new m();
26
+ this.parser = new f();
26
27
  }
27
28
  /**
28
29
  * Get platform information
29
30
  */
30
31
  getPlatformInfo() {
31
- const e = this.parser.getResult(), n = this.normalizePlatformName(e.os.name), r = this.normalizeBrowserName(e.browser.name), o = this.isMobileDevice(), i = !o;
32
+ const e = this.parser.getResult(), n = this.normalizePlatformName(e.os.name), t = this.normalizeBrowserName(e.browser.name), i = this.isMobileDevice(), o = !i;
32
33
  return {
33
34
  name: n,
34
35
  version: e.os.version,
35
- browser: r,
36
+ browser: t,
36
37
  browserVersion: e.browser.version,
37
- isMobile: o,
38
- isDesktop: i
38
+ isMobile: i,
39
+ isDesktop: o
39
40
  };
40
41
  }
41
42
  /**
@@ -104,15 +105,15 @@ class g {
104
105
  checkAppEnvironment(e) {
105
106
  const n = this.parseAippyInfo();
106
107
  if (n) {
107
- const r = e[n.platform], o = h(n.version, r) >= 0;
108
+ const t = e[n.platform], i = v(n.version, t) >= 0;
108
109
  return {
109
110
  type: "new_app",
110
- isValid: o,
111
+ isValid: i,
111
112
  aippyInfo: n,
112
- message: o ? void 0 : `App version ${n.version} < ${r}`
113
+ message: i ? void 0 : `App version ${n.version} < ${t}`
113
114
  };
114
115
  }
115
- return f() ? {
116
+ return w() ? {
116
117
  type: "old_ios_app",
117
118
  isValid: !1,
118
119
  message: "Native bridge exists but no Aippy info (old iOS version)"
@@ -120,18 +121,18 @@ class g {
120
121
  type: "old_android_app",
121
122
  isValid: !1,
122
123
  message: "Android WebView detected but no Aippy info (old Android version)"
123
- } : w() ? { type: "iframe", isValid: !0 } : { type: "web", isValid: !0 };
124
+ } : b() ? { type: "iframe", isValid: !0 } : { type: "web", isValid: !0 };
124
125
  }
125
126
  /**
126
127
  * Parse Aippy App info from User-Agent
127
128
  */
128
129
  parseAippyInfo() {
129
- const e = navigator.userAgent, n = /Aippy\/([^/]+)\/[^/]+\/(iOS|Android)/i, r = e.match(n);
130
- if (r) {
131
- const o = r[1];
130
+ const e = navigator.userAgent, n = /Aippy\/([^/]+)\/[^/]+\/(iOS|Android)/i, t = e.match(n);
131
+ if (t) {
132
+ const i = t[1];
132
133
  return {
133
- platform: r[2],
134
- version: o
134
+ platform: t[2],
135
+ version: i
135
136
  };
136
137
  }
137
138
  return null;
@@ -155,50 +156,60 @@ class g {
155
156
  }
156
157
  }
157
158
  }
158
- const b = new g(), p = "https://cdn.aippy.ai/asset/fd292077086044ee9565bd36ac3a8b78.svg";
159
- async function v(t) {
160
- const e = document.createElement("div");
161
- e.style.cssText = "position:fixed;top:0;left:0;right:0;bottom:12px;display:flex;align-items:flex-end;justify-content:center;z-index:999999;pointer-events:none";
159
+ const y = new x(), d = "https://cdn.aippy.ai/asset/fd292077086044ee9565bd36ac3a8b78.svg";
160
+ async function A(r, e = "update") {
162
161
  const n = document.createElement("div");
163
- n.style.cssText = "background:#323232;border-radius:32px;padding:12px 30px 12px 24px;max-width:85%;display:flex;align-items:center;gap:12px;pointer-events:auto";
164
- let r = !1;
162
+ n.style.cssText = "position:fixed;top:0;left:0;right:0;bottom:12px;display:flex;align-items:flex-end;justify-content:center;z-index:999999;pointer-events:none";
163
+ const t = document.createElement("div");
164
+ t.style.cssText = "background:#323232;border-radius:32px;padding:12px 12px 12px 12px;width:370px;max-width:90%;display:flex;align-items:center;gap:8px;pointer-events:auto";
165
+ let i = !1;
165
166
  try {
166
- r = (await fetch(p, { method: "HEAD" })).ok;
167
+ i = (await fetch(d, { method: "HEAD" })).ok;
167
168
  } catch {
168
- r = !1;
169
+ i = !1;
169
170
  }
170
- if (r) {
171
- const i = document.createElement("img");
172
- i.src = p, i.style.cssText = "width:36px;height:36px;flex-shrink:0", n.appendChild(i);
171
+ if (i) {
172
+ const a = document.createElement("img");
173
+ a.src = d, a.style.cssText = "width:36px;height:36px;flex-shrink:0", t.appendChild(a);
173
174
  }
174
175
  const o = document.createElement("span");
175
- o.style.cssText = "font-size:16px;color:#fff;line-height:1.4;white-space:pre-line", o.textContent = t, n.appendChild(o), e.appendChild(n), document.body.appendChild(e);
176
+ o.style.cssText = "font-size:14px;font-weight:600;color:#fff;line-height:1.4;white-space:pre-line", o.textContent = r;
177
+ const p = e === "signin" ? "Sign in" : "Update", s = document.createElement("button");
178
+ s.style.cssText = "background:#fff;color:#000;font-size:14px;font-weight:600;border:none;border-radius:32px;height:36px;min-width:80px;padding:0 16px;cursor:pointer;flex-shrink:0;white-space:nowrap", s.textContent = p, s.onclick = () => {
179
+ if (e === "signin")
180
+ try {
181
+ window.parent.postMessage({ type: "navigator.appstore" }, "*");
182
+ } catch {
183
+ }
184
+ else
185
+ window.webkit?.messageHandlers?.aippyListener?.postMessage({ command: "navigator.appstore" });
186
+ }, t.appendChild(o), t.appendChild(s), n.appendChild(t), document.body.appendChild(n);
176
187
  }
177
- const x = { iOS: "1.6.7", Android: "1.1.8" }, y = { iOS: "1.6.7", Android: "1.1.8" }, d = {
178
- userCredentials: x,
179
- userInfo: y
188
+ const C = { iOS: "1.6.7", Android: "1.1.8" }, k = { iOS: "1.6.7", Android: "1.1.8" }, u = {
189
+ userCredentials: C,
190
+ userInfo: k
180
191
  };
181
- function A(t) {
182
- const e = d[t];
183
- return e || (console.warn(`[AppVersionChecker] Unknown feature: ${t}`), { iOS: "999.0.0", Android: "999.0.0" });
192
+ function P(r) {
193
+ const e = u[r];
194
+ return e || (console.warn(`[AppVersionChecker] Unknown feature: ${r}`), { iOS: "999.0.0", Android: "999.0.0" });
184
195
  }
185
- function C(t) {
186
- const e = A(t), n = b.checkAppEnvironment(e), r = n.aippyInfo?.version, o = n.aippyInfo ? e[n.aippyInfo.platform] : void 0;
196
+ function _(r) {
197
+ const e = P(r), n = y.checkAppEnvironment(e), t = n.aippyInfo?.version, i = n.aippyInfo ? e[n.aippyInfo.platform] : void 0;
187
198
  switch (n.type) {
188
199
  case "new_app":
189
200
  return {
190
201
  supported: n.isValid,
191
202
  envCheck: n,
192
- currentVersion: r,
193
- requiredVersion: o,
194
- message: n.isValid ? void 0 : `App version ${r} does not support ${t}. Minimum required: ${o}`
203
+ currentVersion: t,
204
+ requiredVersion: i,
205
+ message: n.isValid ? void 0 : `App version ${t} does not support ${r}. Minimum required: ${i}`
195
206
  };
196
207
  case "old_ios_app":
197
208
  case "old_android_app":
198
209
  return {
199
210
  supported: !1,
200
211
  envCheck: n,
201
- message: `Old app version detected. Please upgrade to use ${t}.`
212
+ message: `Old app version detected. Please upgrade to use ${r}.`
202
213
  };
203
214
  default:
204
215
  return {
@@ -207,24 +218,23 @@ function C(t) {
207
218
  };
208
219
  }
209
220
  }
210
- function _(t) {
211
- const e = C(t);
221
+ function E(r) {
222
+ const e = _(r);
212
223
  if (!e.supported && (e.envCheck.type === "new_app" || e.envCheck.type === "old_ios_app" || e.envCheck.type === "old_android_app"))
213
- throw console.warn(`[AppVersionChecker] ${e.message}`), v(`This project needs a newer version.
214
- Update to view it.`), new Error(`App version too old: ${e.message}`);
224
+ throw console.warn(`[AppVersionChecker] ${e.message}`), A("This project needs a newer version.Update to view it.", "update"), h(`App version too old: ${e.message}`, g.NOT_SUPPORTED);
215
225
  return e;
216
226
  }
217
227
  function I() {
218
- return Object.keys(d);
228
+ return Object.keys(u);
219
229
  }
220
230
  export {
221
- g as P,
222
- C as a,
231
+ x as P,
232
+ _ as a,
223
233
  I as b,
224
- h as c,
225
- A as g,
226
- w as i,
227
- b as p,
228
- _ as r,
229
- v as s
234
+ v as c,
235
+ P as g,
236
+ b as i,
237
+ y as p,
238
+ E as r,
239
+ A as s
230
240
  };
@@ -1,21 +1,22 @@
1
- import { a as y } from "./runtime-CmoG3v2m.js";
2
- import { r as h, s as b, i as p } from "./app-version-checker-GLONqMxq.js";
1
+ import { a as U } from "./runtime-CmoG3v2m.js";
2
+ import { r as v, s as L, i as p } from "./app-version-checker-B1UXEcy9.js";
3
+ import { c as B, a as I } from "./errors-B3bDbQbD.js";
3
4
  const f = {
4
5
  apiBaseUrl: "https://api.aippy.dev/api",
5
6
  authToken: "",
6
7
  currentUserId: null
7
8
  };
8
- function L(n) {
9
+ function E(n) {
9
10
  Object.assign(f, n);
10
11
  }
11
- function C(n) {
12
+ function R(n) {
12
13
  f.authToken = n;
13
14
  }
14
15
  function q(n) {
15
16
  f.currentUserId = n;
16
17
  }
17
- const U = 3e3, v = 50, g = 500, c = { uid: "", token: "" };
18
- let a = null, u = !1, l = null, t = null;
18
+ const k = 3e3, T = 50, g = 500, c = { uid: "", token: "" };
19
+ let l = null, u = !1, a = null, t = null;
19
20
  function w(n) {
20
21
  if (!n || typeof n != "object") return null;
21
22
  let e = n;
@@ -26,7 +27,7 @@ function w(n) {
26
27
  const r = e.uid || e.userId || e.id || "", o = e.token || e.authToken || "", s = e.apiBaseUrl;
27
28
  if (!r || !o) return null;
28
29
  const i = { uid: String(r), token: o, apiBaseUrl: s };
29
- return q(i.uid), C(o), s && L({ apiBaseUrl: s }), i;
30
+ return q(i.uid), R(o), s && E({ apiBaseUrl: s }), i;
30
31
  }
31
32
  function m(n) {
32
33
  if (console.log("🔄 [Bridge] processUserInfoData called with:", n), !n || typeof n != "object")
@@ -37,12 +38,12 @@ function m(n) {
37
38
  if (!r)
38
39
  return console.warn("⚠️ [Bridge] No uid found in data"), null;
39
40
  const o = { uid: String(r), ...e };
40
- return console.log("✅ [Bridge] Created userInfo:", o), a = o, u = !0, console.log("✅ [Bridge] Cached userInfo, userInfoReceived = true"), o;
41
+ return console.log("✅ [Bridge] Created userInfo:", o), l = o, u = !0, console.log("✅ [Bridge] Cached userInfo, userInfoReceived = true"), o;
41
42
  }
42
43
  function A(n = g) {
43
- return console.log("📱 [Bridge] requestCredentialsFromiOS called, timeout:", n), l ? (console.log("⏳ [Bridge] Pending credentials request exists, waiting..."), new Promise((e) => {
44
- const r = l.resolve;
45
- l.resolve = (o) => {
44
+ return console.log("📱 [Bridge] requestCredentialsFromiOS called, timeout:", n), a ? (console.log("⏳ [Bridge] Pending credentials request exists, waiting..."), new Promise((e) => {
45
+ const r = a.resolve;
46
+ a.resolve = (o) => {
46
47
  r(o), e(o);
47
48
  };
48
49
  })) : new Promise((e) => {
@@ -52,21 +53,21 @@ function A(n = g) {
52
53
  hasWebkit: !!window.webkit,
53
54
  hasMessageHandlers: !!window.webkit?.messageHandlers,
54
55
  hasAippyListener: !!r
55
- }), r || (console.log("⏳ [Bridge] aippyListener not found, waiting for injection..."), r = await k(1500)), !r) {
56
+ }), r || (console.log("⏳ [Bridge] aippyListener not found, waiting for injection..."), r = await b(1500)), !r) {
56
57
  console.warn("⚠️ [Bridge] No aippyListener found after waiting, returning empty credentials"), e(c);
57
58
  return;
58
59
  }
59
60
  const o = setTimeout(() => {
60
- console.warn("⏰ [Bridge] Credentials request TIMEOUT after", n, "ms"), l = null, e(c);
61
+ console.warn("⏰ [Bridge] Credentials request TIMEOUT after", n, "ms"), a = null, e(c);
61
62
  }, n);
62
- l = {
63
+ a = {
63
64
  resolve: (s) => {
64
- console.log("✅ [Bridge] pendingCredentialsRequest.resolve called with:", s), clearTimeout(o), l = null, e(s);
65
+ console.log("✅ [Bridge] pendingCredentialsRequest.resolve called with:", s), clearTimeout(o), a = null, e(s);
65
66
  }
66
- }, console.log("📱 [Bridge] pendingCredentialsRequest set"), y.receiveChannel.once("user.credentials", (s) => {
67
+ }, console.log("📱 [Bridge] pendingCredentialsRequest set"), U.receiveChannel.once("user.credentials", (s) => {
67
68
  console.log("📩 [Bridge] Received user.credentials via receiveChannel:", s), clearTimeout(o);
68
69
  const i = w(s) || c;
69
- l && l.resolve(i);
70
+ a && a.resolve(i);
70
71
  });
71
72
  try {
72
73
  const s = {
@@ -75,12 +76,12 @@ function A(n = g) {
75
76
  };
76
77
  console.log("📤 [Bridge] Sending credentials request:", s), r.postMessage(s), console.log("📤 [Bridge] Credentials postMessage sent successfully");
77
78
  } catch (s) {
78
- console.error("❌ [Bridge] Failed to send credentials postMessage:", s), clearTimeout(o), l = null, e(c);
79
+ console.error("❌ [Bridge] Failed to send credentials postMessage:", s), clearTimeout(o), a = null, e(c);
79
80
  }
80
81
  })();
81
82
  });
82
83
  }
83
- function E(n = g) {
84
+ function S(n = g) {
84
85
  return new Promise((e) => {
85
86
  if (!p()) {
86
87
  e(c);
@@ -99,9 +100,9 @@ function E(n = g) {
99
100
  }
100
101
  });
101
102
  }
102
- const R = () => /Aippy\/[\d.]+\/\d+\/Android/i.test(navigator.userAgent);
103
- async function k(n = 1500) {
104
- if (!R())
103
+ const D = () => /Aippy\/[\d.]+\/\d+\/Android/i.test(navigator.userAgent);
104
+ async function b(n = 1500) {
105
+ if (!D())
105
106
  return console.log("📱 [Bridge] Not Android, skipping waitForAippyListener"), window.webkit?.messageHandlers?.aippyListener || null;
106
107
  const e = Date.now(), r = 50;
107
108
  for (console.log("🤖 [Bridge] Android: Waiting for aippyListener (max", n, "ms)..."); Date.now() - e < n; ) {
@@ -112,8 +113,8 @@ async function k(n = 1500) {
112
113
  }
113
114
  return console.warn("⏰ [Bridge] aippyListener not available after", n, "ms"), null;
114
115
  }
115
- function S(n = !1, e = g) {
116
- return console.log("📱 [Bridge] requestUserInfoFromiOS called:", { forceRefresh: n, timeoutMs: e }), console.log("📱 [Bridge] Cache state:", { userInfoReceived: u, cachedUserInfo: a ? "(cached)" : null }), u && a && !n ? (console.log("✅ [Bridge] Returning cached userInfo from requestUserInfoFromiOS"), Promise.resolve(a)) : t ? (console.log("⏳ [Bridge] Pending userInfo request exists, waiting..."), new Promise((r) => {
116
+ function O(n = !1, e = g) {
117
+ return console.log("📱 [Bridge] requestUserInfoFromiOS called:", { forceRefresh: n, timeoutMs: e }), console.log("📱 [Bridge] Cache state:", { userInfoReceived: u, cachedUserInfo: l ? "(cached)" : null }), u && l && !n ? (console.log("✅ [Bridge] Returning cached userInfo from requestUserInfoFromiOS"), Promise.resolve(l)) : t ? (console.log("⏳ [Bridge] Pending userInfo request exists, waiting..."), new Promise((r) => {
117
118
  const o = t.resolve;
118
119
  t.resolve = (s) => {
119
120
  console.log("⏳ [Bridge] Pending request resolved:", s), o(s), r(s);
@@ -125,7 +126,7 @@ function S(n = !1, e = g) {
125
126
  hasWebkit: !!window.webkit,
126
127
  hasMessageHandlers: !!window.webkit?.messageHandlers,
127
128
  hasAippyListener: !!o
128
- }), o || (console.log("⏳ [Bridge] aippyListener not found, waiting for injection..."), o = await k(1500)), !o) {
129
+ }), o || (console.log("⏳ [Bridge] aippyListener not found, waiting for injection..."), o = await b(1500)), !o) {
129
130
  console.warn("⚠️ [Bridge] No aippyListener found after waiting, returning null"), r(null);
130
131
  return;
131
132
  }
@@ -135,7 +136,7 @@ function S(n = !1, e = g) {
135
136
  }, e);
136
137
  t = { resolve: (i) => {
137
138
  console.log("✅ [Bridge] pendingUserInfoRequest.resolve called with:", i), clearTimeout(s), t = null, r(i);
138
- } }, console.log("📱 [Bridge] pendingUserInfoRequest set"), y.receiveChannel.once("user.info", (i) => {
139
+ } }, console.log("📱 [Bridge] pendingUserInfoRequest set"), U.receiveChannel.once("user.info", (i) => {
139
140
  console.log("📩 [Bridge] Received user.info via receiveChannel:", i), clearTimeout(s);
140
141
  const d = m(i);
141
142
  console.log("📩 [Bridge] Processed userInfo:", d), t ? t.resolve(d) : console.warn("⚠️ [Bridge] No pendingUserInfoRequest when receiveChannel fired");
@@ -152,7 +153,7 @@ function S(n = !1, e = g) {
152
153
  })();
153
154
  });
154
155
  }
155
- function T(n = g) {
156
+ function C(n = g) {
156
157
  return new Promise((e) => {
157
158
  if (!p()) {
158
159
  e(null);
@@ -172,44 +173,43 @@ function T(n = g) {
172
173
  });
173
174
  }
174
175
  async function P() {
175
- const { envCheck: n } = h("userCredentials");
176
+ const { envCheck: n } = v("userCredentials");
176
177
  switch (n.type) {
177
178
  case "new_app": {
178
- const e = await A(U);
179
- if (!e?.token) throw new Error("Token unavailable in app");
179
+ const e = await A(k);
180
+ if (!e?.token) throw B("Token unavailable in app", I.PERMISSION_DENIED);
180
181
  return e.token;
181
182
  }
182
183
  case "iframe": {
183
- const e = await E(v);
184
+ const e = await S(T);
184
185
  if (e?.token) return e.token;
185
- throw b(`Sign in to continue.
186
- Open this project in the app.`), new Error("Token unavailable: User needs to login");
186
+ throw L("Sign in to continue.Open this project in the app.", "signin"), B("Token unavailable: User needs to login", I.PERMISSION_DENIED);
187
187
  }
188
188
  default:
189
189
  return "";
190
190
  }
191
191
  }
192
- async function F(n = !1) {
193
- if (console.log("🔍 [Bridge] getUserInfoAsync called, forceRefresh:", n), console.log("🔍 [Bridge] Current cache state:", { userInfoReceived: u, cachedUserInfo: a }), u && a && !n)
194
- return console.log("✅ [Bridge] Returning cached userInfo"), a;
195
- const { envCheck: e } = h("userInfo");
192
+ async function _(n = !1) {
193
+ if (console.log("🔍 [Bridge] getUserInfoAsync called, forceRefresh:", n), console.log("🔍 [Bridge] Current cache state:", { userInfoReceived: u, cachedUserInfo: l }), u && l && !n)
194
+ return console.log("✅ [Bridge] Returning cached userInfo"), l;
195
+ const { envCheck: e } = v("userInfo");
196
196
  switch (console.log("🔍 [Bridge] Environment check result:", e), e.type) {
197
197
  case "new_app":
198
- return console.log("📱 [Bridge] Detected new_app environment"), await S(n, U);
198
+ return console.log("📱 [Bridge] Detected new_app environment"), await O(n, k);
199
199
  case "iframe":
200
- return console.log("🖼️ [Bridge] Detected iframe environment"), await T(v);
200
+ return console.log("🖼️ [Bridge] Detected iframe environment"), await C(T);
201
201
  default:
202
- return console.log("🌐 [Bridge] Detected web environment, returning cached:", a), a;
202
+ return console.log("🌐 [Bridge] Detected web environment, returning cached:", l), l;
203
203
  }
204
204
  }
205
- async function M(n = g) {
206
- return p() ? await T(n) : null;
205
+ async function H(n = g) {
206
+ return p() ? await C(n) : null;
207
207
  }
208
- function B(n) {
208
+ function y(n) {
209
209
  const e = w(n);
210
- e && l && (l.resolve(e), l = null);
210
+ e && a && (a.resolve(e), a = null);
211
211
  }
212
- function I(n) {
212
+ function h(n) {
213
213
  console.log("📩 [Bridge] window.processUserInfo called with:", n), console.log("📩 [Bridge] pendingUserInfoRequest exists:", !!t);
214
214
  const e = m(n);
215
215
  t ? (console.log("✅ [Bridge] Resolving pendingUserInfoRequest with:", e), t.resolve(e), t = null) : (console.warn("⚠️ [Bridge] No pendingUserInfoRequest when processUserInfo called!"), console.warn("⚠️ [Bridge] UserInfo was processed but no one is waiting for it"));
@@ -219,8 +219,8 @@ function j() {
219
219
  console.log("🔧 [Bridge] initUserBridge: window is undefined, skipping");
220
220
  return;
221
221
  }
222
- console.log("🔧 [Bridge] initUserBridge: Initializing..."), console.log("🔧 [Bridge] UserAgent:", navigator.userAgent), window.processUserCredentials = B, window.processUserInfo = I, console.log("🔧 [Bridge] Exposed window.processUserCredentials and window.processUserInfo"), window.addEventListener("message", (n) => {
223
- n.data?.type === "user-credentials" && (console.log("📩 [Bridge] Received postMessage user-credentials:", n.data), B(n.data)), n.data?.type === "user-info" && (console.log("📩 [Bridge] Received postMessage user-info:", n.data), I(n.data));
222
+ console.log("🔧 [Bridge] initUserBridge: Initializing..."), console.log("🔧 [Bridge] UserAgent:", navigator.userAgent), window.processUserCredentials = y, window.processUserInfo = h, console.log("🔧 [Bridge] Exposed window.processUserCredentials and window.processUserInfo"), window.addEventListener("message", (n) => {
223
+ n.data?.type === "user-credentials" && (console.log("📩 [Bridge] Received postMessage user-credentials:", n.data), y(n.data)), n.data?.type === "user-info" && (console.log("📩 [Bridge] Received postMessage user-info:", n.data), h(n.data));
224
224
  }), console.log("🔧 [Bridge] Added message event listener"), console.log("✅ [Bridge] initUserBridge complete");
225
225
  }
226
226
  j();
@@ -229,9 +229,9 @@ P().catch((n) => {
229
229
  });
230
230
  export {
231
231
  P as getAuthTokenAsync,
232
- F as getUserInfoAsync,
233
- M as getUserInfoFromParent,
232
+ _ as getUserInfoAsync,
233
+ H as getUserInfoFromParent,
234
234
  p as isInIframe,
235
- B as processUserCredentials,
236
- I as processUserInfo
235
+ y as processUserCredentials,
236
+ h as processUserInfo
237
237
  };
@@ -1,6 +1,6 @@
1
1
  import "react";
2
- import { getAuthTokenAsync as a } from "./bridge-BKcAlLAd.js";
3
- const r = "0.2.7-dev.6", i = {
2
+ import { getAuthTokenAsync as a } from "./bridge-BQQ3PfSO.js";
3
+ const r = "0.2.7-dev.7", i = {
4
4
  version: r
5
5
  }, o = i.version, c = "@aippy/runtime";
6
6
  function w() {
@@ -1,11 +1,22 @@
1
1
  import { AippyError } from './types';
2
2
  /**
3
- * Custom error class
3
+ * Error prefix constants
4
+ * - RUNTIME: SDK internal errors (network, auth, permissions), NOT reported to LLM
5
+ * - CODE: Code-related errors (config validation, type errors), WILL be reported to LLM
6
+ */
7
+ export declare const ERROR_PREFIX: {
8
+ readonly RUNTIME: "[Aippy Runtime]";
9
+ readonly CODE: "[Aippy Error]";
10
+ };
11
+ export type ErrorPrefix = typeof ERROR_PREFIX[keyof typeof ERROR_PREFIX];
12
+ /**
13
+ * Custom error class for Aippy Runtime SDK
4
14
  */
5
15
  export declare class AippyRuntimeError extends Error implements AippyError {
6
16
  readonly code: string;
7
17
  readonly context?: Record<string, unknown>;
8
- constructor(message: string, code?: string, context?: Record<string, unknown>);
18
+ readonly prefix: ErrorPrefix;
19
+ constructor(message: string, code?: string, context?: Record<string, unknown>, prefix?: ErrorPrefix);
9
20
  }
10
21
  /**
11
22
  * Common error codes
@@ -15,9 +26,17 @@ export declare const ERROR_CODES: {
15
26
  readonly PERMISSION_DENIED: "PERMISSION_DENIED";
16
27
  readonly INVALID_CONFIG: "INVALID_CONFIG";
17
28
  readonly NETWORK_ERROR: "NETWORK_ERROR";
29
+ readonly TIMEOUT: "TIMEOUT";
30
+ readonly OPERATION_FAILED: "OPERATION_FAILED";
18
31
  readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
19
32
  };
20
33
  /**
21
- * Create a standardized error
34
+ * Create a runtime error (NOT reported to LLM)
35
+ * Use for: network errors, auth errors, permission denied, API not supported
22
36
  */
23
37
  export declare function createError(message: string, code?: keyof typeof ERROR_CODES, context?: Record<string, unknown>): AippyRuntimeError;
38
+ /**
39
+ * Create a code-related error (WILL be reported to LLM)
40
+ * Use for: config validation errors, type errors, missing keys
41
+ */
42
+ export declare function createCodeError(message: string, code?: keyof typeof ERROR_CODES, context?: Record<string, unknown>): AippyRuntimeError;