@aippy/runtime 0.2.7-dev.3 → 0.2.7-dev.5

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 CHANGED
@@ -93,13 +93,13 @@ button.onclick = async () => {
93
93
  // Default base URL: https://api.aippy.dev/api/aisdk/v1
94
94
 
95
95
  import { streamText, experimental_generateImage as generateImage } from 'ai';
96
- import { aippy } from '@aippy/runtime/ai';
96
+ import { aippyAIProvider } from '@aippy/runtime/ai';
97
97
 
98
98
  // Create provider (reads from env vars automatically)
99
- const provider = aippy();
99
+ const provider = aippyAIProvider();
100
100
 
101
101
  // Or override with config
102
- // const provider = aippy({ baseUrl: '...', userToken: '...' });
102
+ // const provider = aippyAIProvider({ baseUrl: '...', userToken: '...' });
103
103
 
104
104
  // Streaming text generation (uses Vercel AI SDK)
105
105
  const result = await streamText({
@@ -1,25 +1,6 @@
1
1
  import { AISDKError } from 'ai';
2
2
  /**
3
3
  * Normalizes a backend error response into an AISDKError.
4
- *
5
- * If the backend error response includes container message data (e.g., `appMessage` field),
6
- * it will be automatically sent to the app container for user-facing UI (e.g., payment dialog,
7
- * error popup, success notification).
4
+ * Extracts and sends appMessage to container if present in the error response.
8
5
  */
9
6
  export declare function normalizeError(response: Response, body?: unknown): AISDKError;
10
- /**
11
- * Creates an error for missing user token.
12
- */
13
- export declare function missingTokenError(): AISDKError;
14
- /**
15
- * Creates an error for aborted requests.
16
- */
17
- export declare function abortedError(): AISDKError;
18
- /**
19
- * Creates an error for network failures.
20
- */
21
- export declare function networkError(cause?: unknown): AISDKError;
22
- /**
23
- * Creates an error for parse failures.
24
- */
25
- export declare function parseError(message: string): AISDKError;
@@ -38,9 +38,7 @@
38
38
  */
39
39
  export { aippyAIProvider, type AippyProvider } from './openai';
40
40
  export type { AippyOpenAIConfig } from './openai';
41
- /** @deprecated Use aippyAIProvider() instead */
42
- export { aippyAIProvider as aippy } from './openai';
43
41
  export { aippyChatConfig, type AippyUseChatOptions, type AippyUIConfig, type AippyChatConfig, UI_CHAT_ENDPOINT, } from './ui';
44
42
  export { DEFAULT_BASE_URL, DEFAULT_UI_BASE_URL, DEFAULT_CHAT_MODEL, DEFAULT_CHAT_SYSTEM, } from './shared';
45
- export { normalizeError, missingTokenError, abortedError, networkError, parseError, } from './errors';
43
+ export { normalizeError } from './errors';
46
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';
package/dist/ai/index.js CHANGED
@@ -1,25 +1,20 @@
1
- import { A as i, D as A, d as n, e, c as E, U as C, f as p, a as g, a as t, b as I, j as T, i as _, l as f, m as U, g as d, n as D, h as L, p as l, s as m, v as F } from "../helper-CKiqfKle.js";
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-BENVYOU-.js";
2
2
  import "react";
3
- import "../bridge-N9ELFpfV.js";
3
+ import "../bridge-Ca3H2iN1.js";
4
4
  export {
5
- i as AIConfigValidationError,
6
- A as DEFAULT_BASE_URL,
5
+ A as AIConfigValidationError,
6
+ r as DEFAULT_BASE_URL,
7
7
  n as DEFAULT_CHAT_MODEL,
8
- e as DEFAULT_CHAT_SYSTEM,
9
- E as DEFAULT_UI_BASE_URL,
10
- C as UI_CHAT_ENDPOINT,
11
- p as abortedError,
12
- g as aippy,
13
- t as aippyAIProvider,
14
- I as aippyChatConfig,
15
- T as createAIConfig,
16
- _ as getAIConfigValue,
17
- f as loadAIConfig,
18
- U as missingTokenError,
19
- d as networkError,
20
- D as normalizeError,
21
- L as parseAIConfig,
22
- l as parseError,
23
- m as sendAIConfigToContainer,
24
- F as validateAIConfig
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,
18
+ U as sendAIConfigToContainer,
19
+ D as validateAIConfig
25
20
  };
@@ -4,25 +4,12 @@
4
4
  */
5
5
  /**
6
6
  * Joins a base URL with a path segment.
7
- * Uses native URL API for reliable URL resolution.
8
- *
9
- * @param baseUrl - The base URL (e.g., 'https://api.aippy.dev/api/aisdk/v1/ui/')
10
- * @param path - The path segment to append (e.g., '/chat' or 'chat')
11
- * @returns The joined URL string
12
- *
13
- * @example
14
- * joinUrl('https://api.aippy.dev/api/aisdk/v1/ui/', '/chat')
15
- * // => 'https://api.aippy.dev/api/aisdk/v1/ui/chat'
16
7
  */
17
8
  export declare function joinUrl(baseUrl: string, path: string): string;
18
9
  /**
19
- * Creates a fetch wrapper that injects Authorization header with a fresh token.
20
- * Token is fetched asynchronously on every request to ensure it's always current.
10
+ * Creates a fetch wrapper that injects Authorization header and handles error responses.
11
+ * Error responses are intercepted and normalized errors are thrown immediately.
21
12
  *
22
13
  * @returns A fetch function compatible with globalThis.fetch signature
23
- *
24
- * @example
25
- * const authFetch = createAuthFetch();
26
- * const response = await authFetch('https://api.example.com/endpoint', { method: 'POST' });
27
14
  */
28
15
  export declare function createAuthFetch(): typeof globalThis.fetch;
@@ -8,7 +8,7 @@
8
8
  */
9
9
  export { patchAudioContext } from './patchAudioContext';
10
10
  export type { AudioContextPatchOptions, AutoPauseOptions, MediaElementType, PatchedAudioContext, } from './types';
11
- export { createHiddenMediaElement, createHiddenVideoElement, isMediaStreamAudioSupported, } from './utils';
11
+ export { createHiddenMediaElement, isMediaStreamAudioSupported, } from './utils';
12
12
  export { useAudioContext } from './useAudioContext';
13
13
  export type { UseAudioContextOptions, UseAudioContextReturn } from './useAudioContext';
14
14
  export { isIOSDevice } from './utils';
@@ -1,9 +1,8 @@
1
- import { c as i, a as t, b as d, i as o, p as s, u as n } from "../useAudioContext-CNQQSTab.js";
1
+ import { c as i, a as t, i as d, p as o, u as s } from "../useAudioContext-D9F3x80Y.js";
2
2
  export {
3
3
  i as createHiddenMediaElement,
4
- t as createHiddenVideoElement,
5
- d as isIOSDevice,
6
- o as isMediaStreamAudioSupported,
7
- s as patchAudioContext,
8
- n as useAudioContext
4
+ t as isIOSDevice,
5
+ d as isMediaStreamAudioSupported,
6
+ o as patchAudioContext,
7
+ s as useAudioContext
9
8
  };
@@ -15,10 +15,3 @@ export declare function isMediaStreamAudioSupported(): boolean;
15
15
  * @returns HTMLMediaElement (HTMLVideoElement or HTMLAudioElement)
16
16
  */
17
17
  export declare function createHiddenMediaElement(type?: 'video' | 'audio', debug?: boolean): HTMLVideoElement | HTMLAudioElement;
18
- /**
19
- * @deprecated Use createHiddenMediaElement instead
20
- * Creates a hidden video element for MediaStream playback
21
- * @param debug - If true, makes the video element visible for debugging
22
- * @returns HTMLVideoElement
23
- */
24
- export declare function createHiddenVideoElement(debug?: boolean): HTMLVideoElement;
@@ -0,0 +1,197 @@
1
+ import { a as y } from "./runtime-CmoG3v2m.js";
2
+ import { p as T, s as v, i as f } from "./ui-y5N62DqC.js";
3
+ const m = {
4
+ apiBaseUrl: "https://api.aippy.dev/api",
5
+ authToken: "",
6
+ currentUserId: null
7
+ };
8
+ function b(n) {
9
+ Object.assign(m, n);
10
+ }
11
+ function P(n) {
12
+ m.authToken = n;
13
+ }
14
+ function O(n) {
15
+ m.currentUserId = n;
16
+ }
17
+ const k = { iOS: "1.6.6", Android: "1.1.8" }, E = 3e3, S = 50, l = 500, a = { uid: "", token: "" };
18
+ let d = null, _ = !1, u = null, w = !1, o = null;
19
+ function g(n) {
20
+ if (!n || typeof n != "object") return null;
21
+ let e = n;
22
+ if (e.credentials && typeof e.credentials == "object" && (e = e.credentials), e.user && typeof e.user == "object" && e.token) {
23
+ const c = e.user;
24
+ e = { uid: c.uid || c.userId || c.id, token: e.token, apiBaseUrl: e.apiBaseUrl };
25
+ }
26
+ const s = e.uid || e.userId || e.id || "", t = e.token || e.authToken || "", r = e.apiBaseUrl;
27
+ if (!s || !t) return null;
28
+ const i = { uid: String(s), token: t, apiBaseUrl: r };
29
+ return O(i.uid), P(t), r && b({ apiBaseUrl: r }), d = i, _ = !0, i;
30
+ }
31
+ function h(n) {
32
+ if (!n || typeof n != "object") return null;
33
+ let e = n;
34
+ e.userInfo && typeof e.userInfo == "object" && (e = e.userInfo), e.user && typeof e.user == "object" && (e = e.user);
35
+ const s = e.uid || e.userId || e.id || "";
36
+ if (!s) return null;
37
+ const t = { uid: String(s), ...e };
38
+ return u = t, w = !0, t;
39
+ }
40
+ function p(n) {
41
+ throw console.warn(`[UserSDK] ${n}`), v("Your app version is outdated. Please upgrade to the latest version."), new Error("App version too old");
42
+ }
43
+ function L(n = l) {
44
+ return _ && d ? Promise.resolve(d) : new Promise((e) => {
45
+ const s = window.webkit?.messageHandlers?.aippyListener;
46
+ if (!s) {
47
+ e(a);
48
+ return;
49
+ }
50
+ const t = setTimeout(() => e(a), n);
51
+ y.receiveChannel.once("user.credentials", (r) => {
52
+ clearTimeout(t), e(g(r) || a);
53
+ });
54
+ try {
55
+ s.postMessage({
56
+ command: "user.getCredentials",
57
+ parameters: JSON.stringify({ timestamp: Date.now(), endpoint: "user.credentials" })
58
+ });
59
+ } catch {
60
+ clearTimeout(t), e(a);
61
+ }
62
+ });
63
+ }
64
+ function C(n = l) {
65
+ return new Promise((e) => {
66
+ if (!f()) {
67
+ e(a);
68
+ return;
69
+ }
70
+ const s = setTimeout(() => {
71
+ window.removeEventListener("message", t), e(a);
72
+ }, n), t = (r) => {
73
+ r.data?.type === "user-credentials-response" && (clearTimeout(s), window.removeEventListener("message", t), e(g(r.data) || a));
74
+ };
75
+ window.addEventListener("message", t);
76
+ try {
77
+ window.parent.postMessage({ type: "user-credentials-request", timestamp: Date.now() }, "*");
78
+ } catch {
79
+ clearTimeout(s), window.removeEventListener("message", t), e(a);
80
+ }
81
+ });
82
+ }
83
+ function D(n = !1, e = l) {
84
+ return w && u && !n ? Promise.resolve(u) : o ? new Promise((s) => {
85
+ const t = o.resolve;
86
+ o.resolve = (r) => {
87
+ t(r), s(r);
88
+ };
89
+ }) : new Promise((s) => {
90
+ const t = window.webkit?.messageHandlers?.aippyListener;
91
+ if (!t) {
92
+ s(null);
93
+ return;
94
+ }
95
+ const r = setTimeout(() => {
96
+ o = null, s(null);
97
+ }, e);
98
+ o = { resolve: (i) => {
99
+ clearTimeout(r), o = null, s(i);
100
+ } }, y.receiveChannel.once("user.info", (i) => {
101
+ console.log("[UserSDK] Received user.info via receiveChannel:", i), clearTimeout(r);
102
+ const c = h(i);
103
+ o && o.resolve(c);
104
+ });
105
+ try {
106
+ console.log("[UserSDK] Requesting user info from iOS"), t.postMessage({
107
+ command: "user.getUserInfo",
108
+ parameters: JSON.stringify({ timestamp: Date.now(), endpoint: "user.info" })
109
+ });
110
+ } catch {
111
+ clearTimeout(r), o = null, s(null);
112
+ }
113
+ });
114
+ }
115
+ function A(n = l) {
116
+ return new Promise((e) => {
117
+ if (!f()) {
118
+ e(null);
119
+ return;
120
+ }
121
+ const s = setTimeout(() => {
122
+ window.removeEventListener("message", t), e(null);
123
+ }, n), t = (r) => {
124
+ r.data?.type === "user-info-response" && (clearTimeout(s), window.removeEventListener("message", t), e(h(r.data)));
125
+ };
126
+ window.addEventListener("message", t);
127
+ try {
128
+ window.parent.postMessage({ type: "user-info-request", timestamp: Date.now() }, "*");
129
+ } catch {
130
+ clearTimeout(s), window.removeEventListener("message", t), e(null);
131
+ }
132
+ });
133
+ }
134
+ async function M() {
135
+ const n = T.checkAppEnvironment(k);
136
+ switch (n.type) {
137
+ case "new_app": {
138
+ n.isValid || p(n.message || "App version too old"), await L(E);
139
+ const e = d?.token || "";
140
+ if (!e) throw new Error("Token unavailable in app");
141
+ return e;
142
+ }
143
+ case "old_ios_app":
144
+ case "old_android_app":
145
+ throw p(n.message || "Old app version"), new Error("Token unavailable: Old app version not supported");
146
+ case "iframe": {
147
+ const e = await C(S);
148
+ if (e?.token) return e.token;
149
+ throw v("Please log in to use this feature."), new Error("Token unavailable: User needs to login");
150
+ }
151
+ default:
152
+ return "";
153
+ }
154
+ }
155
+ async function F(n = !1) {
156
+ if (w && u && !n) return u;
157
+ const e = T.checkAppEnvironment(k);
158
+ switch (e.type) {
159
+ case "new_app":
160
+ return e.isValid || p(e.message || "App version too old"), await D(n, E);
161
+ case "old_ios_app":
162
+ case "old_android_app":
163
+ return p(e.message || "Old app version"), u;
164
+ case "iframe":
165
+ return await A(S);
166
+ default:
167
+ return u;
168
+ }
169
+ }
170
+ async function B(n = l) {
171
+ return f() ? await A(n) : null;
172
+ }
173
+ function I(n) {
174
+ g(n);
175
+ }
176
+ function U(n) {
177
+ console.log("[UserSDK] processUserInfo called with:", n);
178
+ const e = h(n);
179
+ o && (o.resolve(e), o = null);
180
+ }
181
+ function j() {
182
+ typeof window > "u" || (window.processUserCredentials = I, window.processUserInfo = U, window.addEventListener("message", (n) => {
183
+ n.data?.type === "user-credentials" && I(n.data), n.data?.type === "user-info" && U(n.data);
184
+ }));
185
+ }
186
+ j();
187
+ M().catch((n) => {
188
+ console.warn("[UserSDK] Auth check on load:", n.message);
189
+ });
190
+ export {
191
+ M as getAuthTokenAsync,
192
+ F as getUserInfoAsync,
193
+ B as getUserInfoFromParent,
194
+ f as isInIframe,
195
+ I as processUserCredentials,
196
+ U as processUserInfo
197
+ };
@@ -24,7 +24,7 @@ function p(e) {
24
24
  }
25
25
  };
26
26
  }
27
- const r = "0.2.7-dev.3", a = {
27
+ const r = "0.2.7-dev.5", a = {
28
28
  version: r
29
29
  }, t = a.version, i = "@aippy/runtime";
30
30
  function c() {
@@ -0,0 +1,247 @@
1
+ import { createOpenAICompatible as l } from "@ai-sdk/openai-compatible";
2
+ import "react";
3
+ import { getAuthTokenAsync as y } from "./bridge-Ca3H2iN1.js";
4
+ import { AISDKError as u, DefaultChatTransport as d } from "ai";
5
+ import { s as f } from "./container-message-DGrno17o.js";
6
+ const c = "https://api.aippy.dev", h = `${c}/aisdk/v1/`, b = `${c}/aisdk/v1/ui/`, A = "gpt-5-nano", w = "";
7
+ function v(n = {}) {
8
+ return {
9
+ baseUrl: n.baseUrl ?? h
10
+ };
11
+ }
12
+ function I(n = {}) {
13
+ return {
14
+ baseUrl: n.baseUrl ?? b
15
+ };
16
+ }
17
+ function C(n, e) {
18
+ const s = n.status;
19
+ if (e && typeof e == "object" && "error" in e) {
20
+ const t = e, o = t.error.code, r = o != null ? `AippyAIError_${o}` : `AippyAIError_${s}`, a = e;
21
+ return "appMessage" in a && a.appMessage !== void 0 && f(a.appMessage), new u({
22
+ name: r,
23
+ message: t.error.message,
24
+ cause: {
25
+ type: t.error.type ?? void 0,
26
+ param: t.error.param ?? void 0,
27
+ status: s
28
+ }
29
+ });
30
+ }
31
+ if (e && typeof e == "object" && e !== null) {
32
+ const t = e;
33
+ "appMessage" in t && t.appMessage !== void 0 && f(t.appMessage);
34
+ }
35
+ return new u({
36
+ name: `AippyAIError_${s}`,
37
+ message: `Request failed with status ${s}`,
38
+ cause: { status: s }
39
+ });
40
+ }
41
+ function E(n, e) {
42
+ const s = n.endsWith("/") ? n : `${n}/`, t = e.startsWith("/") ? e.slice(1) : e;
43
+ return new URL(t, s).href;
44
+ }
45
+ function m() {
46
+ return async (n, e) => {
47
+ const s = await y(), t = new Headers(e?.headers);
48
+ t.set("Aippy-Runtime-Authorization", `Bearer ${s}`);
49
+ const o = await globalThis.fetch(n, { ...e, headers: t });
50
+ if (!o.ok) {
51
+ const r = await o.text().catch(() => null);
52
+ let a = null;
53
+ if (r)
54
+ try {
55
+ a = JSON.parse(r);
56
+ } catch {
57
+ a = { message: r };
58
+ }
59
+ throw C(o, a);
60
+ }
61
+ return o;
62
+ };
63
+ }
64
+ const S = [
65
+ "gpt-image-1",
66
+ "gpt-image-1-mini",
67
+ "gpt-image-1.5"
68
+ ];
69
+ function O(n) {
70
+ try {
71
+ const e = JSON.parse(n);
72
+ if (e.model && S.some((s) => e.model.startsWith(s))) {
73
+ const { response_format: s, ...t } = e;
74
+ return JSON.stringify(t);
75
+ }
76
+ } catch {
77
+ }
78
+ return n;
79
+ }
80
+ function N(n = {}) {
81
+ const { baseUrl: e } = v(n), s = m();
82
+ return l({
83
+ name: "aippy",
84
+ baseURL: e,
85
+ fetch: async (o, r) => o.toString().includes("/images/generations") && r?.method?.toUpperCase() === "POST" && r?.body ? s(o, {
86
+ ...r,
87
+ body: O(r.body)
88
+ }) : s(o, r),
89
+ // Enable structured outputs support (json_schema response format)
90
+ // This is required for Output.object() and Output.array() to work properly
91
+ supportsStructuredOutputs: !0
92
+ });
93
+ }
94
+ const _ = "/chat";
95
+ function D(n = {}) {
96
+ const { baseUrl: e } = I(n), s = n.model ?? A, t = n.system ?? w, o = n.api ?? E(e, _), r = { model: s, system: t }, a = m();
97
+ return {
98
+ transport: new d({
99
+ api: o,
100
+ body: r,
101
+ // Ensure token is fetched fresh for every request
102
+ fetch: a
103
+ })
104
+ };
105
+ }
106
+ class p extends Error {
107
+ constructor(e, s) {
108
+ super(e), this.errors = s, this.name = "AIConfigValidationError";
109
+ }
110
+ }
111
+ function g(n) {
112
+ const e = [];
113
+ if (!n || typeof n != "object")
114
+ throw new p("AIConfig must be an object", []);
115
+ const s = n;
116
+ for (const [t, o] of Object.entries(s)) {
117
+ if (!o || typeof o != "object") {
118
+ e.push({ key: t, message: "Item must be an object" });
119
+ continue;
120
+ }
121
+ const r = o;
122
+ typeof r.index != "number" && e.push({ key: t, message: "index must be a number" }), typeof r.name != "string" && e.push({ key: t, message: "name must be a string" }), typeof r.description != "string" && e.push({ key: t, message: "description must be a string" });
123
+ const a = r.type;
124
+ if (!["number", "boolean", "text", "enum"].includes(a)) {
125
+ e.push({
126
+ key: t,
127
+ message: `type must be one of: number, boolean, text, enum (got: ${a})`
128
+ });
129
+ continue;
130
+ }
131
+ if (a === "number")
132
+ typeof r.value != "number" && e.push({ key: t, message: 'value must be a number for type "number"' }), r.min !== void 0 && typeof r.min != "number" && e.push({ key: t, message: "min must be a number" }), r.max !== void 0 && typeof r.max != "number" && e.push({ key: t, message: "max must be a number" }), r.step !== void 0 && typeof r.step != "number" && e.push({ key: t, message: "step must be a number" });
133
+ else if (a === "boolean")
134
+ typeof r.value != "boolean" && e.push({ key: t, message: 'value must be a boolean for type "boolean"' });
135
+ else if (a === "text")
136
+ typeof r.value != "string" && e.push({ key: t, message: 'value must be a string for type "text"' });
137
+ else if (a === "enum") {
138
+ if (!Array.isArray(r.options))
139
+ e.push({ key: t, message: 'options must be an array for type "enum"' });
140
+ else if (r.options.length === 0)
141
+ e.push({ key: t, message: 'options array cannot be empty for type "enum"' });
142
+ else
143
+ for (let i = 0; i < r.options.length; i++)
144
+ typeof r.options[i] != "string" && e.push({
145
+ key: t,
146
+ message: `options[${i}] must be a string`
147
+ });
148
+ typeof r.value != "string" ? e.push({ key: t, message: 'value must be a string for type "enum"' }) : Array.isArray(r.options) && !r.options.includes(r.value) && e.push({
149
+ key: t,
150
+ message: `value "${r.value}" is not in options: [${r.options.join(", ")}]`
151
+ });
152
+ }
153
+ r.group !== void 0 && typeof r.group != "string" && e.push({ key: t, message: "group must be a string" });
154
+ }
155
+ if (e.length > 0)
156
+ throw new p(
157
+ `AIConfig validation failed with ${e.length} error(s)`,
158
+ e
159
+ );
160
+ }
161
+ function R(n) {
162
+ let e;
163
+ try {
164
+ e = JSON.parse(n);
165
+ } catch (s) {
166
+ throw new p("Invalid JSON", [
167
+ {
168
+ key: "",
169
+ message: `JSON parse error: ${s instanceof Error ? s.message : String(s)}`
170
+ }
171
+ ]);
172
+ }
173
+ return g(e), e;
174
+ }
175
+ function U(n) {
176
+ return g(n), n;
177
+ }
178
+ function T(n, e) {
179
+ const s = n[e];
180
+ if (!s)
181
+ throw new Error(`AIConfig key "${e}" not found`);
182
+ return s.value;
183
+ }
184
+ function $(n) {
185
+ if (!(typeof window > "u"))
186
+ try {
187
+ const e = window.webkit?.messageHandlers?.aippyListener;
188
+ if (e)
189
+ try {
190
+ const s = {
191
+ command: "ai.initialize",
192
+ parameters: JSON.stringify(n)
193
+ };
194
+ e.postMessage(s);
195
+ } catch (s) {
196
+ console.warn("❌ [Aippy AI Config] Failed to send config to iOS app:", s);
197
+ }
198
+ if (window.parent && window.parent !== window)
199
+ try {
200
+ const s = {
201
+ type: "ai.initialize",
202
+ config: JSON.stringify(n)
203
+ };
204
+ window.parent.postMessage(s, "*");
205
+ } catch (s) {
206
+ console.warn("❌ [Aippy AI Config] Failed to send config to parent window:", s);
207
+ }
208
+ } catch (e) {
209
+ console.warn("⚠️ [Aippy AI Config] Failed to send config:", e);
210
+ }
211
+ }
212
+ function B(n) {
213
+ const e = U(n);
214
+ return $(e), new Proxy({}, {
215
+ get(s, t) {
216
+ if (typeof t == "string")
217
+ try {
218
+ return T(e, t);
219
+ } catch {
220
+ return;
221
+ }
222
+ },
223
+ has(s, t) {
224
+ return typeof t != "string" ? !1 : t in e;
225
+ },
226
+ ownKeys(s) {
227
+ return Object.keys(e);
228
+ }
229
+ });
230
+ }
231
+ export {
232
+ p as A,
233
+ h as D,
234
+ _ as U,
235
+ N as a,
236
+ D as b,
237
+ b as c,
238
+ A as d,
239
+ w as e,
240
+ B as f,
241
+ T as g,
242
+ U as l,
243
+ C as n,
244
+ R as p,
245
+ $ as s,
246
+ g as v
247
+ };
@@ -0,0 +1,46 @@
1
+ import { useState as l, useEffect as c } from "react";
2
+ let n = null, r = null;
3
+ function U() {
4
+ const [s, i] = l(n || {
5
+ avatar: "",
6
+ nickName: "用户",
7
+ username: "",
8
+ uid: ""
9
+ });
10
+ return c(() => {
11
+ let t = !0;
12
+ return (async () => {
13
+ try {
14
+ if (n) {
15
+ t && i(n);
16
+ return;
17
+ }
18
+ if (r) {
19
+ await r, t && n && i(n);
20
+ return;
21
+ }
22
+ r = (async () => {
23
+ const { getUserInfoAsync: a, getUserInfoFromParent: o, isInIframe: f } = await import("./bridge-Ca3H2iN1.js"), { hasNativeBridge: u } = await import("./native-bridge-BnvipFJc.js");
24
+ let e = null;
25
+ u() ? e = await a() : f() ? e = await o() : e = await a(), e && (n = {
26
+ avatar: String(e.avatar || e.photoUrl || ""),
27
+ nickName: String(e.nickName || e.displayName || "用户"),
28
+ username: String(e.username || ""),
29
+ uid: String(e.uid || "")
30
+ });
31
+ })(), await r, r = null, t && n && i(n);
32
+ } catch (a) {
33
+ console.error("[useUserInfo] Failed:", a), r = null;
34
+ }
35
+ })(), () => {
36
+ t = !1;
37
+ };
38
+ }, []), s;
39
+ }
40
+ function d() {
41
+ n = null, r = null;
42
+ }
43
+ export {
44
+ d as c,
45
+ U as u
46
+ };