@aippy/runtime 0.2.7-dev.0 → 0.2.7-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.
@@ -1,28 +1,38 @@
1
- import { f as r, b as a, h as t, l as n, j as u, g as i, k as o, e as d, i as C, c as f, d as l, r as g, s as U, a as h, t as c } from "../bridge-DdAH4txB.js";
2
- import { e as k, f as y, g as P, a as m, u as A, b as S, d as G, c as T, h as q } from "../userSessionInfo-CBk9ywXi.js";
1
+ import { f as r, q as a, b as t, h as n, l as o, o as u, j as i, n as f, w as U, g as d, k as I, p as C, e as g, i as l, c, d as h, r as m, u as P, m as y, s as k, a as A, t as F, v as S } from "../bridge-D2d8hnO_.js";
2
+ import { i as G, f as T, h as p, g as Q, a as b, u as j, b as x, d as B, c as O, e as v, j as w } from "../userSessionInfo-SbuNZ7JR.js";
3
3
  export {
4
4
  r as autoRequestCredentials,
5
- k as clearProfileCache,
6
- y as fetchUserProfile,
7
- a as getAuthToken,
8
- t as getAuthTokenAsync,
9
- n as getCachedCredentials,
10
- P as getCurrentUserId,
11
- u as getCurrentUserIdAsync,
12
- i as getUserSdkConfig,
13
- o as hasCredentials,
14
- d as initUserBridge,
15
- C as initUserSdk,
16
- f as isInIframe,
17
- l as requestCredentialsFromParent,
18
- g as requestCredentialsFromiOS,
19
- U as setAuthToken,
20
- h as setCurrentUserId,
21
- c as tryGetCredentialsFromParentStorage,
22
- m as useAuthToken,
23
- A as useCurrentUserId,
24
- S as useGetCurrentUserProfileQuery,
25
- G as useGetJoinedUserProfilesQuery,
26
- T as useGetUserProfileByIdQuery,
27
- q as userSessionInfo
5
+ a as clearCachedUserInfo,
6
+ G as clearProfileCache,
7
+ T as clearUserInfoCache,
8
+ p as fetchUserProfile,
9
+ t as getAuthToken,
10
+ n as getAuthTokenAsync,
11
+ o as getCachedCredentials,
12
+ u as getCachedUserInfo,
13
+ Q as getCurrentUserId,
14
+ i as getCurrentUserIdAsync,
15
+ f as getUserInfoAsync,
16
+ U as getUserInfoFromParent,
17
+ d as getUserSdkConfig,
18
+ I as hasCredentials,
19
+ C as hasUserInfo,
20
+ g as initUserBridge,
21
+ l as initUserSdk,
22
+ c as isInIframe,
23
+ h as requestCredentialsFromParent,
24
+ m as requestCredentialsFromiOS,
25
+ P as requestUserInfoFromParent,
26
+ y as requestUserInfoFromiOS,
27
+ k as setAuthToken,
28
+ A as setCurrentUserId,
29
+ F as tryGetCredentialsFromParentStorage,
30
+ S as tryGetUserInfoFromParentStorage,
31
+ b as useAuthToken,
32
+ j as useCurrentUserId,
33
+ x as useGetCurrentUserProfileQuery,
34
+ B as useGetJoinedUserProfilesQuery,
35
+ O as useGetUserProfileByIdQuery,
36
+ v as useUserInfo,
37
+ w as userSessionInfo
28
38
  };
@@ -9,6 +9,8 @@ declare global {
9
9
  interface Window {
10
10
  /** User credentials callback from iOS */
11
11
  processUserCredentials?: (data: unknown) => void;
12
+ /** User info callback from iOS */
13
+ processUserInfo?: (data: unknown) => void;
12
14
  }
13
15
  }
14
16
  /**
@@ -0,0 +1,229 @@
1
+ import { useState as o, useEffect as y, useCallback as U } from "react";
2
+ import { g as I, b as k } from "./bridge-D2d8hnO_.js";
3
+ const w = /* @__PURE__ */ new Map();
4
+ async function S(e) {
5
+ const t = I(), n = w.get(e);
6
+ if (n && Date.now() - n.timestamp < (t.cacheTime || 3e5))
7
+ return n.data;
8
+ try {
9
+ const r = await fetch(
10
+ `${t.apiBaseUrl}/user/profile?targetUid=${e}`,
11
+ {
12
+ method: "GET",
13
+ headers: {
14
+ Authorization: `Bearer ${t.authToken}`,
15
+ "Content-Type": "application/json"
16
+ }
17
+ }
18
+ );
19
+ if (!r.ok)
20
+ throw new Error(`Failed to fetch user profile: ${r.status}`);
21
+ const a = await r.json(), i = C(a, e);
22
+ return w.set(e, { data: i, timestamp: Date.now() }), i;
23
+ } catch (r) {
24
+ return console.error("[UserSDK] Failed to fetch user profile:", r), null;
25
+ }
26
+ }
27
+ function C(e, t) {
28
+ const n = typeof e == "object" && e !== null ? e : {}, r = n.data || n.user || n;
29
+ return {
30
+ id: r.id || r.uid || t,
31
+ displayName: r.displayName || r.nickname || r.name || "Unknown User",
32
+ username: r.username || r.id || t,
33
+ photoUrl: r.photoUrl || r.avatar || r.avatarUrl,
34
+ online: r.online ?? !1,
35
+ bio: r.bio,
36
+ coverImageUrl: r.coverImageUrl,
37
+ ...r
38
+ };
39
+ }
40
+ function D(e) {
41
+ e ? w.delete(e) : w.clear();
42
+ }
43
+ function M() {
44
+ const [e, t] = o(
45
+ I().currentUserId
46
+ );
47
+ return y(() => {
48
+ t(I().currentUserId);
49
+ }, []), e;
50
+ }
51
+ function N() {
52
+ const [e, t] = o(k());
53
+ return y(() => {
54
+ t(k());
55
+ }, []), e;
56
+ }
57
+ function T() {
58
+ const e = M(), [t, n] = o(null), [r, a] = o(!0), [i, u] = o(!1), [h, s] = o(null), l = U(async () => {
59
+ if (!e) {
60
+ n(null), a(!1);
61
+ return;
62
+ }
63
+ a(!0), u(!1), s(null);
64
+ try {
65
+ const c = await S(e);
66
+ n(c);
67
+ } catch (c) {
68
+ u(!0), s(c instanceof Error ? c : new Error(String(c)));
69
+ } finally {
70
+ a(!1);
71
+ }
72
+ }, [e]);
73
+ y(() => {
74
+ l();
75
+ }, [l]);
76
+ const f = U(async () => {
77
+ e && D(e), await l();
78
+ }, [e, l]);
79
+ return { data: t, isLoading: r, isError: i, error: h, refetch: f };
80
+ }
81
+ function b(e) {
82
+ const { id: t } = e, [n, r] = o(null), [a, i] = o(!0), [u, h] = o(!1), [s, l] = o(null), f = U(async () => {
83
+ if (!t) {
84
+ r(null), i(!1);
85
+ return;
86
+ }
87
+ i(!0), h(!1), l(null);
88
+ try {
89
+ const d = await S(t);
90
+ r(d);
91
+ } catch (d) {
92
+ h(!0), l(d instanceof Error ? d : new Error(String(d)));
93
+ } finally {
94
+ i(!1);
95
+ }
96
+ }, [t]);
97
+ y(() => {
98
+ f();
99
+ }, [f]);
100
+ const c = U(async () => {
101
+ D(t), await f();
102
+ }, [t, f]);
103
+ return { data: n, isLoading: a, isError: u, error: s, refetch: c };
104
+ }
105
+ function A(e = {}) {
106
+ const { includeSelf: t = !0 } = e, n = M(), [r, a] = o([]), [i, u] = o(!0), [h, s] = o(!1), [l, f] = o(null), c = U(async () => {
107
+ u(!0), s(!1), f(null);
108
+ try {
109
+ const m = [];
110
+ if (t && n) {
111
+ const E = await S(n);
112
+ E && m.push(E);
113
+ }
114
+ a(m);
115
+ } catch (m) {
116
+ s(!0), f(m instanceof Error ? m : new Error(String(m)));
117
+ } finally {
118
+ u(!1);
119
+ }
120
+ }, [t, n]);
121
+ y(() => {
122
+ c();
123
+ }, [c]);
124
+ const d = U(async () => {
125
+ D(), await c();
126
+ }, [c]);
127
+ return { data: r, isLoading: i, isError: h, error: l, refetch: d };
128
+ }
129
+ function L() {
130
+ return I().currentUserId;
131
+ }
132
+ let g = null, p = null;
133
+ function j() {
134
+ const [e, t] = o(g || {
135
+ avatar: "",
136
+ nickName: "用户",
137
+ username: "",
138
+ uid: ""
139
+ });
140
+ return y(() => {
141
+ let n = !0;
142
+ return (async () => {
143
+ try {
144
+ if (g) {
145
+ console.log("[useUserInfo] Using cached user info"), n && t(g);
146
+ return;
147
+ }
148
+ if (p) {
149
+ console.log("[useUserInfo] Waiting for existing request"), await p, n && g && t(g);
150
+ return;
151
+ }
152
+ console.log("[useUserInfo] Fetching user info"), p = (async () => {
153
+ const { getUserInfoAsync: a, getUserInfoFromParent: i, isInIframe: u } = await import("./bridge-D2d8hnO_.js").then((l) => l.x), { hasNativeBridge: h } = await import("./native-bridge-BnvipFJc.js");
154
+ let s = null;
155
+ h() ? s = await a() : u() ? s = await i() : s = await a(), s && (g = {
156
+ avatar: String(s.avatar || s.photoUrl || ""),
157
+ nickName: String(s.nickName || s.displayName || "用户"),
158
+ username: String(s.username || ""),
159
+ uid: String(s.uid || "")
160
+ });
161
+ })(), await p, p = null, n && g && t(g);
162
+ } catch (a) {
163
+ console.error("[useUserInfo] Failed to fetch user info:", a), p = null;
164
+ }
165
+ })(), () => {
166
+ n = !1;
167
+ };
168
+ }, []), e;
169
+ }
170
+ function B() {
171
+ g = null, p = null, console.log("[useUserInfo] Cache cleared");
172
+ }
173
+ function P(e, t) {
174
+ const n = [
175
+ "Jan",
176
+ "Feb",
177
+ "Mar",
178
+ "Apr",
179
+ "May",
180
+ "Jun",
181
+ "Jul",
182
+ "Aug",
183
+ "Sep",
184
+ "Oct",
185
+ "Nov",
186
+ "Dec"
187
+ ], r = e.getHours(), a = r % 12 || 12, i = r >= 12 ? "PM" : "AM";
188
+ return t.replace("MMM", n[e.getMonth()]).replace("dd", String(e.getDate()).padStart(2, "0")).replace("d", String(e.getDate())).replace("hh", String(a).padStart(2, "0")).replace("h", String(a)).replace("mm", String(e.getMinutes()).padStart(2, "0")).replace("a", i).replace("yyyy", String(e.getFullYear())).replace("yy", String(e.getFullYear()).slice(-2));
189
+ }
190
+ const G = {
191
+ /**
192
+ * Get current user ID synchronously
193
+ */
194
+ getCurrentUserId() {
195
+ return I().currentUserId;
196
+ },
197
+ /**
198
+ * Get current timestamp in milliseconds
199
+ */
200
+ getTimestampInMs() {
201
+ return Date.now();
202
+ },
203
+ /**
204
+ * Format date with given format string
205
+ * @param options - Format options with timestamp and format string
206
+ * @returns Formatted date string
207
+ *
208
+ * @example
209
+ * userSessionInfo.formatDate({ timestampMs: Date.now(), formatString: 'MMM d, h:mm a' })
210
+ * // Returns: "Jan 7, 10:30 PM"
211
+ */
212
+ formatDate(e) {
213
+ const { timestampMs: t, formatString: n } = e, r = new Date(t);
214
+ return P(r, n);
215
+ }
216
+ };
217
+ export {
218
+ N as a,
219
+ T as b,
220
+ b as c,
221
+ A as d,
222
+ j as e,
223
+ B as f,
224
+ L as g,
225
+ S as h,
226
+ D as i,
227
+ G as j,
228
+ M as u
229
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aippy/runtime",
3
- "version": "0.2.7-dev.0",
3
+ "version": "0.2.7-dev.1",
4
4
  "description": "Aippy Runtime SDK - Runtime SDK for Aippy projects",
5
5
  "private": false,
6
6
  "type": "module",
@@ -115,7 +115,9 @@
115
115
  "security:check": "pnpm audit && pnpm outdated",
116
116
  "prerelease": "pnpm run audit && pnpm run type-check && pnpm run lint && pnpm run build",
117
117
  "release:dry": "npm publish --dry-run",
118
- "test": "pnpm run build && node --test tests/*.test.mjs",
118
+ "test": "pnpm run build && node --test 'tests/**/*.test.mjs'",
119
+ "test:openai": "pnpm run build && node --test 'tests/ai/openai/*.test.mjs'",
120
+ "test:ui": "pnpm run build && node --test 'tests/ai/ui/*.test.mjs'",
119
121
  "test:file": "pnpm run build && node --test",
120
122
  "test:build": "node -c dist/index.js"
121
123
  }
@@ -1,222 +0,0 @@
1
- import { a as K } from "./runtime-CmoG3v2m.js";
2
- import { h as y } from "./native-bridge-JAmH-zTN.js";
3
- const U = {
4
- apiBaseUrl: "https://api.aippy.dev/api",
5
- authToken: "",
6
- // 默认为空,由 iOS 桥接填充
7
- currentUserId: null,
8
- // 默认为空,由 iOS 桥接填充
9
- cacheTime: 300 * 1e3
10
- // 5 minutes
11
- };
12
- let u = { ...U };
13
- function h(r) {
14
- u = {
15
- ...U,
16
- ...r
17
- };
18
- }
19
- function R() {
20
- return u;
21
- }
22
- function w(r) {
23
- u.authToken = r;
24
- }
25
- function B(r) {
26
- u.currentUserId = r;
27
- }
28
- function P() {
29
- return u.authToken;
30
- }
31
- const a = {
32
- uid: "",
33
- token: "",
34
- apiBaseUrl: void 0
35
- }, D = 5e3;
36
- let d = !1, m = !1, l = null, o = null;
37
- function g() {
38
- try {
39
- return typeof window < "u" && window.parent !== window;
40
- } catch {
41
- return !0;
42
- }
43
- }
44
- function k(r = D) {
45
- return new Promise((e) => {
46
- if (!g()) {
47
- console.log("ℹ️ [UserSDK Bridge] Not in iframe, skipping parent request"), e(a);
48
- return;
49
- }
50
- console.log("📤 [UserSDK Bridge] Requesting credentials from parent window");
51
- const i = setTimeout(() => {
52
- console.warn(`⚠️ [UserSDK Bridge] Parent request timeout (${r}ms)`), window.removeEventListener("message", n), e(a);
53
- }, r), n = (t) => {
54
- if (t.data && t.data.type === "user-credentials-response") {
55
- console.log("📩 [UserSDK Bridge] Received credentials from parent:", t.data), clearTimeout(i), window.removeEventListener("message", n);
56
- const s = f(t.data);
57
- e(s || a);
58
- }
59
- };
60
- window.addEventListener("message", n);
61
- try {
62
- window.parent.postMessage({
63
- type: "user-credentials-request",
64
- timestamp: Date.now()
65
- }, "*");
66
- } catch (t) {
67
- console.error("❌ [UserSDK Bridge] Failed to send request to parent:", t), clearTimeout(i), window.removeEventListener("message", n), e(a);
68
- }
69
- });
70
- }
71
- function C() {
72
- if (!g())
73
- return null;
74
- try {
75
- const r = window.parent.localStorage.getItem("token"), e = window.parent.localStorage.getItem("user");
76
- if (!r || !e)
77
- return console.log("ℹ️ [UserSDK Bridge] Parent localStorage credentials not found"), null;
78
- const i = JSON.parse(e), n = i.uid || i.userId || i.id || "";
79
- if (!n)
80
- return console.warn("⚠️ [UserSDK Bridge] Parent user data missing uid"), null;
81
- const t = {
82
- uid: String(n),
83
- token: r,
84
- apiBaseUrl: void 0
85
- };
86
- return B(t.uid), w(t.token), console.log("✅ [UserSDK Bridge] Got credentials from parent localStorage:", t.uid), l = t, d = !0, t;
87
- } catch {
88
- return console.log("ℹ️ [UserSDK Bridge] Cannot access parent localStorage (cross-origin), will use postMessage"), null;
89
- }
90
- }
91
- function v(r = D) {
92
- return d && l ? (console.log("✅ [UserSDK Bridge] Returning cached credentials"), Promise.resolve(l)) : m && !d ? (console.log("ℹ️ [UserSDK Bridge] Previous request failed, returning empty credentials"), Promise.resolve(a)) : o ? (console.log("⏳ [UserSDK Bridge] Request already pending, waiting..."), new Promise((e) => {
93
- const i = o.resolve;
94
- o.resolve = (n) => {
95
- i(n), e(n);
96
- };
97
- })) : new Promise((e) => {
98
- m = !0;
99
- const i = window.webkit?.messageHandlers?.aippyListener;
100
- if (!i) {
101
- console.warn("⚠️ [UserSDK Bridge] Native bridge not available, returning empty credentials"), e(a);
102
- return;
103
- }
104
- const n = setTimeout(() => {
105
- console.warn(`⚠️ [UserSDK Bridge] Request timeout (${r}ms), returning empty credentials`), o = null, e(a);
106
- }, r);
107
- o = { resolve: e, reject: () => {
108
- } };
109
- const t = K.receiveChannel.once("user.credentials", (s) => {
110
- console.log("📩 [UserSDK Bridge] Received credentials via receiveChannel:", s), clearTimeout(n);
111
- const c = f(s);
112
- c ? o?.resolve(c) : o?.resolve(a), o = null;
113
- });
114
- try {
115
- const s = {
116
- command: "user.getCredentials",
117
- parameters: JSON.stringify({
118
- timestamp: Date.now(),
119
- endpoint: "user.credentials"
120
- // Tell iOS which endpoint to respond to
121
- })
122
- };
123
- console.log("📤 [UserSDK Bridge] Requesting credentials from iOS:", s), i.postMessage(s);
124
- } catch (s) {
125
- console.error("❌ [UserSDK Bridge] Failed to send request to iOS:", s), clearTimeout(n), t.cancel(), o = null, e(a);
126
- }
127
- });
128
- }
129
- function f(r) {
130
- if (!r || typeof r != "object")
131
- return console.warn("⚠️ [UserSDK Bridge] Invalid credentials data:", r), null;
132
- let e = r;
133
- if (e.credentials && typeof e.credentials == "object" && (console.log("📦 [UserSDK Bridge] Detected nested credentials format"), e = e.credentials), e.user && typeof e.user == "object" && e.token) {
134
- console.log("📦 [UserSDK Bridge] Detected parent window format");
135
- const c = e.user;
136
- e = {
137
- uid: c.uid || c.userId || c.id,
138
- token: e.token,
139
- apiBaseUrl: e.apiBaseUrl
140
- };
141
- }
142
- const i = e.uid || e.userId || e.id || "", n = e.token || e.authToken || "", t = e.apiBaseUrl || e.baseUrl;
143
- if (!i || !n)
144
- return console.warn("⚠️ [UserSDK Bridge] Missing uid or token in credentials:", r), null;
145
- const s = { uid: String(i), token: n, apiBaseUrl: t };
146
- return B(s.uid), w(n), t && h({ apiBaseUrl: t }), console.log("✅ [UserSDK Bridge] Config updated with credentials:", s.uid), l = s, d = !0, s;
147
- }
148
- function S(r) {
149
- console.log("📩 [UserSDK Bridge] processUserCredentials called with:", r);
150
- const e = f(r);
151
- e && o && (o.resolve(e), o = null);
152
- }
153
- function T() {
154
- typeof window > "u" || (window.processUserCredentials = S, window.addEventListener("message", (r) => {
155
- r.data && r.data.type === "user-credentials" && (console.log("📩 [UserSDK Bridge] Received credentials via postMessage:", r.data), S(r.data));
156
- }), console.log("✅ [UserSDK Bridge] Bridge initialized"));
157
- }
158
- async function p() {
159
- if (d && l) {
160
- console.log("✅ [UserSDK Bridge] Already have cached credentials");
161
- return;
162
- }
163
- if (y()) {
164
- console.log("🔍 [UserSDK Bridge] Detected iOS environment, requesting from native");
165
- try {
166
- if (await v(), d) {
167
- console.log("✅ [UserSDK Bridge] Got credentials from iOS");
168
- return;
169
- }
170
- } catch (r) {
171
- console.warn("⚠️ [UserSDK Bridge] iOS request failed:", r);
172
- }
173
- }
174
- if (g()) {
175
- if (console.log("🔍 [UserSDK Bridge] Detected iframe environment"), C()) {
176
- console.log("✅ [UserSDK Bridge] Got credentials from parent localStorage");
177
- return;
178
- }
179
- console.log("🔍 [UserSDK Bridge] Trying postMessage to parent");
180
- try {
181
- const e = await k();
182
- if (e.uid && e.token) {
183
- console.log("✅ [UserSDK Bridge] Got credentials from parent postMessage");
184
- return;
185
- }
186
- } catch (e) {
187
- console.warn("⚠️ [UserSDK Bridge] Parent postMessage request failed:", e);
188
- }
189
- }
190
- console.log("ℹ️ [UserSDK Bridge] No credentials source available");
191
- }
192
- async function b() {
193
- return await p(), l?.token || "";
194
- }
195
- async function E() {
196
- return await p(), l?.uid || "";
197
- }
198
- function O() {
199
- return d;
200
- }
201
- function A() {
202
- return l;
203
- }
204
- T();
205
- p();
206
- export {
207
- B as a,
208
- P as b,
209
- g as c,
210
- k as d,
211
- T as e,
212
- p as f,
213
- R as g,
214
- b as h,
215
- h as i,
216
- E as j,
217
- O as k,
218
- A as l,
219
- v as r,
220
- w as s,
221
- C as t
222
- };
@@ -1,152 +0,0 @@
1
- import { createOpenAICompatible as A } from "@ai-sdk/openai-compatible";
2
- import "react";
3
- import { h as p } from "./bridge-DdAH4txB.js";
4
- import { DefaultChatTransport as l, AISDKError as a } from "ai";
5
- const E = "https://api.aippy.dev", d = `${E}/api/aisdk/v1/`, h = `${E}/api/aisdk/v1/ui/`, g = "gpt-5-nano", _ = "";
6
- function U(e = {}) {
7
- return {
8
- baseUrl: e.baseUrl ?? d
9
- };
10
- }
11
- function i(e = {}) {
12
- return {
13
- baseUrl: e.baseUrl ?? h
14
- };
15
- }
16
- function c(e, r) {
17
- const t = e.endsWith("/") ? e : `${e}/`, n = r.startsWith("/") ? r.slice(1) : r;
18
- return new URL(n, t).href;
19
- }
20
- function u() {
21
- return async (e, r) => {
22
- const t = await p(), n = new Headers(r?.headers);
23
- return n.set("Authorization", `Bearer ${t}`), globalThis.fetch(e, { ...r, headers: n });
24
- };
25
- }
26
- const y = [
27
- "gpt-image-1",
28
- "gpt-image-1-mini",
29
- "gpt-image-1.5"
30
- ];
31
- function I(e) {
32
- try {
33
- const r = JSON.parse(e);
34
- if (r.model && y.some((t) => r.model.startsWith(t))) {
35
- const { response_format: t, ...n } = r;
36
- return JSON.stringify(n);
37
- }
38
- } catch {
39
- }
40
- return e;
41
- }
42
- function w(e = {}) {
43
- const { baseUrl: r } = U(e), t = u();
44
- return A({
45
- name: "aippy",
46
- baseURL: r,
47
- fetch: async (s, o) => s.toString().includes("/images/generations") && o?.method?.toUpperCase() === "POST" && o?.body ? t(s, {
48
- ...o,
49
- body: I(o.body)
50
- }) : t(s, o)
51
- });
52
- }
53
- const T = "/chat", O = "/completion", f = "/object";
54
- function N(e = {}) {
55
- const { baseUrl: r } = i(e), t = e.model ?? g, n = e.system ?? _, s = e.api ?? c(r, T), o = { model: t, system: n }, m = u();
56
- return {
57
- transport: new l({
58
- api: s,
59
- body: o,
60
- // Ensure token is fetched fresh for every request
61
- fetch: m
62
- })
63
- };
64
- }
65
- function D(e = {}) {
66
- const { baseUrl: r } = i(e), t = u();
67
- return {
68
- api: c(r, O),
69
- // Ensure token is fetched fresh for every request
70
- fetch: t
71
- };
72
- }
73
- async function B(e) {
74
- const { schemaId: r, ...t } = e, { baseUrl: n } = i(t), s = await p();
75
- return {
76
- api: c(n, f),
77
- headers: { Authorization: `Bearer ${s}` },
78
- schemaId: r
79
- };
80
- }
81
- async function L(e = {}) {
82
- const { baseUrl: r } = i(e), t = await p();
83
- return {
84
- api: c(r, f),
85
- headers: { Authorization: `Bearer ${t}` }
86
- };
87
- }
88
- function k(e, r) {
89
- const t = e.status;
90
- if (r && typeof r == "object" && "error" in r) {
91
- const n = r, s = n.error.code, o = s != null ? `AippyAIError_${s}` : `AippyAIError_${t}`;
92
- return new a({
93
- name: o,
94
- message: n.error.message,
95
- cause: {
96
- type: n.error.type ?? void 0,
97
- param: n.error.param ?? void 0,
98
- status: t
99
- }
100
- });
101
- }
102
- return new a({
103
- name: `AippyAIError_${t}`,
104
- message: `Request failed with status ${t}`,
105
- cause: { status: t }
106
- });
107
- }
108
- function $() {
109
- return new a({
110
- name: "AippyAIError_MISSING_TOKEN",
111
- message: "User token is required. Ensure user credentials are available via initUserBridge()."
112
- });
113
- }
114
- function F() {
115
- return new a({
116
- name: "AippyAIError_REQUEST_ABORTED",
117
- message: "Request was aborted"
118
- });
119
- }
120
- function v(e) {
121
- const r = e instanceof Error ? e.message : "Network request failed";
122
- return new a({
123
- name: "AippyAIError_NETWORK_ERROR",
124
- message: r,
125
- cause: e instanceof Error ? e : String(e)
126
- });
127
- }
128
- function P(e) {
129
- return new a({
130
- name: "AippyAIError_PARSE_ERROR",
131
- message: `Failed to parse response: ${e}`
132
- });
133
- }
134
- export {
135
- d as D,
136
- T as U,
137
- w as a,
138
- N as b,
139
- D as c,
140
- B as d,
141
- L as e,
142
- O as f,
143
- f as g,
144
- h,
145
- g as i,
146
- _ as j,
147
- F as k,
148
- v as l,
149
- $ as m,
150
- k as n,
151
- P as p
152
- };