@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 +3 -3
- package/dist/ai/errors.d.ts +1 -20
- package/dist/ai/index.d.ts +1 -3
- package/dist/ai/index.js +16 -21
- package/dist/ai/shared/fetch.d.ts +2 -15
- package/dist/audio/index.d.ts +1 -1
- package/dist/audio/index.js +5 -6
- package/dist/audio/utils.d.ts +0 -7
- package/dist/bridge-Ca3H2iN1.js +197 -0
- package/dist/core/index.js +1 -1
- package/dist/helper-BENVYOU-.js +247 -0
- package/dist/hooks-CE9cjXHP.js +46 -0
- package/dist/index/index.js +72 -107
- package/dist/{ui-D6IZ1jrR.js → ui-y5N62DqC.js} +81 -25
- package/dist/{useAudioContext-CNQQSTab.js → useAudioContext-D9F3x80Y.js} +38 -42
- package/dist/user/bridge.d.ts +10 -141
- package/dist/user/config.d.ts +8 -17
- package/dist/user/hooks.d.ts +3 -65
- package/dist/user/index.d.ts +3 -9
- package/dist/user/index.js +7 -36
- package/dist/user/types.d.ts +2 -105
- package/dist/utils/index.js +11 -9
- package/dist/utils/platform.d.ts +42 -1
- package/package.json +1 -1
- package/dist/bridge-N9ELFpfV.js +0 -430
- package/dist/helper-CKiqfKle.js +0 -264
- package/dist/user/api.d.ts +0 -9
- package/dist/user/userSessionInfo.d.ts +0 -6
- package/dist/userSessionInfo-DFvsuELU.js +0 -229
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import { useState as o, useEffect as y, useCallback as U } from "react";
|
|
2
|
-
import { g as I, b as k } from "./bridge-N9ELFpfV.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-N9ELFpfV.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
|
-
};
|