@blocklet/aigne-hub 0.2.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.
- package/README.md +29 -0
- package/lib/cjs/api/ai-kit.js +60 -0
- package/lib/cjs/api/api.js +17 -0
- package/lib/cjs/api/app.js +57 -0
- package/lib/cjs/api/call/api.js +51 -0
- package/lib/cjs/api/call/app.js +74 -0
- package/lib/cjs/api/call/index.js +19 -0
- package/lib/cjs/api/call/proxy.js +64 -0
- package/lib/cjs/api/call/v1.js +166 -0
- package/lib/cjs/api/call/v2.js +101 -0
- package/lib/cjs/api/config.js +46 -0
- package/lib/cjs/api/constants.js +4 -0
- package/lib/cjs/api/error.js +42 -0
- package/lib/cjs/api/index.js +19 -0
- package/lib/cjs/api/types/audio.js +2 -0
- package/lib/cjs/api/types/chat.js +14 -0
- package/lib/cjs/api/types/embedding.js +2 -0
- package/lib/cjs/api/types/image.js +2 -0
- package/lib/cjs/api/types/index.js +19 -0
- package/lib/cjs/api/types/status.js +2 -0
- package/lib/cjs/api/utils/auth.js +90 -0
- package/lib/cjs/api/utils/event-stream.js +59 -0
- package/lib/cjs/components/conversation/conversation.js +71 -0
- package/lib/cjs/components/conversation/index.js +25 -0
- package/lib/cjs/components/conversation/message.js +120 -0
- package/lib/cjs/components/conversation/prompt.js +43 -0
- package/lib/cjs/components/conversation/use-conversation.js +100 -0
- package/lib/cjs/components/credit/alert.js +40 -0
- package/lib/cjs/components/credit/balance.js +95 -0
- package/lib/cjs/components/credit/button.js +69 -0
- package/lib/cjs/components/credit/index.js +12 -0
- package/lib/cjs/components/form-label.js +27 -0
- package/lib/cjs/components/image-preview.js +116 -0
- package/lib/cjs/components/index.js +45 -0
- package/lib/cjs/components/loading-image.js +37 -0
- package/lib/cjs/components/subscribe/alert.js +53 -0
- package/lib/cjs/components/subscribe/button.js +92 -0
- package/lib/cjs/components/subscribe/state.js +42 -0
- package/lib/cjs/components/switch-button.js +48 -0
- package/lib/cjs/components/table.js +203 -0
- package/lib/cjs/index.js +2 -0
- package/lib/cjs/libs/logger.js +8 -0
- package/lib/cjs/utils/withLocaleProvider.js +11 -0
- package/lib/esm/api/ai-kit.js +54 -0
- package/lib/esm/api/api.js +11 -0
- package/lib/esm/api/app.js +42 -0
- package/lib/esm/api/call/api.js +24 -0
- package/lib/esm/api/call/app.js +68 -0
- package/lib/esm/api/call/index.js +3 -0
- package/lib/esm/api/call/proxy.js +58 -0
- package/lib/esm/api/call/v1.js +155 -0
- package/lib/esm/api/call/v2.js +93 -0
- package/lib/esm/api/config.js +41 -0
- package/lib/esm/api/constants.js +1 -0
- package/lib/esm/api/error.js +37 -0
- package/lib/esm/api/index.js +3 -0
- package/lib/esm/api/types/audio.js +1 -0
- package/lib/esm/api/types/chat.js +9 -0
- package/lib/esm/api/types/embedding.js +1 -0
- package/lib/esm/api/types/image.js +1 -0
- package/lib/esm/api/types/index.js +3 -0
- package/lib/esm/api/types/status.js +1 -0
- package/lib/esm/api/utils/auth.js +79 -0
- package/lib/esm/api/utils/event-stream.js +50 -0
- package/lib/esm/components/conversation/conversation.js +65 -0
- package/lib/esm/components/conversation/index.js +4 -0
- package/lib/esm/components/conversation/message.js +114 -0
- package/lib/esm/components/conversation/prompt.js +40 -0
- package/lib/esm/components/conversation/use-conversation.js +97 -0
- package/lib/esm/components/credit/alert.js +35 -0
- package/lib/esm/components/credit/balance.js +90 -0
- package/lib/esm/components/credit/button.js +64 -0
- package/lib/esm/components/credit/index.js +3 -0
- package/lib/esm/components/form-label.js +24 -0
- package/lib/esm/components/image-preview.js +110 -0
- package/lib/esm/components/index.js +14 -0
- package/lib/esm/components/loading-image.js +35 -0
- package/lib/esm/components/subscribe/alert.js +48 -0
- package/lib/esm/components/subscribe/button.js +87 -0
- package/lib/esm/components/subscribe/state.js +39 -0
- package/lib/esm/components/switch-button.js +46 -0
- package/lib/esm/components/table.js +198 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/libs/logger.js +3 -0
- package/lib/esm/utils/withLocaleProvider.js +8 -0
- package/lib/types/api/ai-kit.d.ts +70 -0
- package/lib/types/api/api.d.ts +4 -0
- package/lib/types/api/app.d.ts +113 -0
- package/lib/types/api/call/api.d.ts +2 -0
- package/lib/types/api/call/app.d.ts +50 -0
- package/lib/types/api/call/index.d.ts +3 -0
- package/lib/types/api/call/proxy.d.ts +6 -0
- package/lib/types/api/call/v1.d.ts +51 -0
- package/lib/types/api/call/v2.d.ts +30 -0
- package/lib/types/api/config.d.ts +14 -0
- package/lib/types/api/constants.d.ts +1 -0
- package/lib/types/api/error.d.ts +18 -0
- package/lib/types/api/index.d.ts +3 -0
- package/lib/types/api/types/audio.d.ts +18 -0
- package/lib/types/api/types/chat.d.ts +97 -0
- package/lib/types/api/types/embedding.d.ts +9 -0
- package/lib/types/api/types/image.d.ts +23 -0
- package/lib/types/api/types/index.d.ts +3 -0
- package/lib/types/api/types/status.d.ts +3 -0
- package/lib/types/api/utils/auth.d.ts +33 -0
- package/lib/types/api/utils/event-stream.d.ts +7 -0
- package/lib/types/components/conversation/conversation.d.ts +30 -0
- package/lib/types/components/conversation/index.d.ts +4 -0
- package/lib/types/components/conversation/message.d.ts +10 -0
- package/lib/types/components/conversation/prompt.d.ts +10 -0
- package/lib/types/components/conversation/use-conversation.d.ts +44 -0
- package/lib/types/components/credit/alert.d.ts +10 -0
- package/lib/types/components/credit/balance.d.ts +7 -0
- package/lib/types/components/credit/button.d.ts +11 -0
- package/lib/types/components/credit/index.d.ts +3 -0
- package/lib/types/components/form-label.d.ts +7 -0
- package/lib/types/components/image-preview.d.ts +17 -0
- package/lib/types/components/index.d.ts +12 -0
- package/lib/types/components/loading-image.d.ts +6 -0
- package/lib/types/components/subscribe/alert.d.ts +5 -0
- package/lib/types/components/subscribe/button.d.ts +5 -0
- package/lib/types/components/subscribe/state.d.ts +14 -0
- package/lib/types/components/switch-button.d.ts +7 -0
- package/lib/types/components/table.d.ts +3 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/libs/logger.d.ts +2 -0
- package/lib/types/utils/withLocaleProvider.d.ts +9 -0
- package/package.json +158 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = useConversation;
|
|
4
|
+
const immer_1 = require("immer");
|
|
5
|
+
const nanoid_1 = require("nanoid");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const nextId = () => (0, nanoid_1.nanoid)(16);
|
|
8
|
+
function useConversation({ scrollToBottom, textCompletions, imageGenerations, }) {
|
|
9
|
+
const [messages, setMessages] = (0, react_1.useState)(() => [
|
|
10
|
+
{ id: nextId(), response: 'Hi, I am AIGNE Hub! How can I assist you today?' },
|
|
11
|
+
]);
|
|
12
|
+
const add = (0, react_1.useCallback)(async (prompt, meta) => {
|
|
13
|
+
const id = nextId();
|
|
14
|
+
setMessages((v) => v.concat({ id, prompt, loading: true, meta }));
|
|
15
|
+
scrollToBottom === null || scrollToBottom === void 0 ? void 0 : scrollToBottom({ force: true });
|
|
16
|
+
try {
|
|
17
|
+
if (imageGenerations && typeof prompt === 'string') {
|
|
18
|
+
const m = prompt.match(/^\/image(\s+(?<size>256|512|1024))?(\s+(?<n>[1-9]|10))?\s+(?<prompt>[\s\S]+)/);
|
|
19
|
+
if (m === null || m === void 0 ? void 0 : m.groups) {
|
|
20
|
+
const { size = '256', n = '1', prompt, } = m.groups;
|
|
21
|
+
const response = await imageGenerations({
|
|
22
|
+
prompt,
|
|
23
|
+
n: parseInt(n, 10),
|
|
24
|
+
size: `${size}x${size}`,
|
|
25
|
+
}, { meta });
|
|
26
|
+
setMessages((v) => (0, immer_1.produce)(v, (draft) => {
|
|
27
|
+
const item = draft.find((i) => i.id === id);
|
|
28
|
+
if (item)
|
|
29
|
+
item.response = response;
|
|
30
|
+
}));
|
|
31
|
+
return { id, data: response };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const result = await textCompletions(prompt, { meta });
|
|
35
|
+
const isText = (i) => i.type === 'text';
|
|
36
|
+
const isImages = (i) => i.type === 'images';
|
|
37
|
+
const reader = result.getReader();
|
|
38
|
+
const decoder = new TextDecoder();
|
|
39
|
+
let response = '';
|
|
40
|
+
for (;;) {
|
|
41
|
+
// eslint-disable-next-line no-await-in-loop
|
|
42
|
+
const { value, done } = await reader.read();
|
|
43
|
+
if (value) {
|
|
44
|
+
let delta = '';
|
|
45
|
+
if (typeof value === 'string') {
|
|
46
|
+
delta = value;
|
|
47
|
+
}
|
|
48
|
+
else if (isText(value)) {
|
|
49
|
+
response = value.text;
|
|
50
|
+
}
|
|
51
|
+
else if (isImages(value)) {
|
|
52
|
+
response = value.images;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
delta = decoder.decode(value);
|
|
56
|
+
}
|
|
57
|
+
if (typeof response === 'string' && delta) {
|
|
58
|
+
response += delta;
|
|
59
|
+
}
|
|
60
|
+
setMessages((v) => (0, immer_1.produce)(v, (draft) => {
|
|
61
|
+
const item = draft.find((i) => i.id === id);
|
|
62
|
+
if (!item || item.loading === false) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
item.response = response;
|
|
66
|
+
item.loading = !done;
|
|
67
|
+
}));
|
|
68
|
+
scrollToBottom === null || scrollToBottom === void 0 ? void 0 : scrollToBottom();
|
|
69
|
+
}
|
|
70
|
+
if (done) {
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return { id, text: response };
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
setMessages((v) => (0, immer_1.produce)(v, (draft) => {
|
|
78
|
+
const item = draft.find((i) => i.id === id);
|
|
79
|
+
if (item)
|
|
80
|
+
item.error = error;
|
|
81
|
+
}));
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
setMessages((v) => (0, immer_1.produce)(v, (draft) => {
|
|
86
|
+
const item = draft.find((i) => i.id === id);
|
|
87
|
+
if (item)
|
|
88
|
+
item.loading = false;
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
}, [imageGenerations, scrollToBottom, textCompletions]);
|
|
92
|
+
const cancel = (0, react_1.useCallback)(({ id }) => {
|
|
93
|
+
setMessages((v) => (0, immer_1.produce)(v, (draft) => {
|
|
94
|
+
const i = draft.find((i) => i.id === id);
|
|
95
|
+
if (i)
|
|
96
|
+
i.loading = false;
|
|
97
|
+
}));
|
|
98
|
+
}, []);
|
|
99
|
+
return { messages, add, cancel, setMessages };
|
|
100
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const context_1 = require("@arcblock/ux/lib/Locale/context");
|
|
8
|
+
const material_1 = require("@mui/material");
|
|
9
|
+
const error_1 = require("../../api/error");
|
|
10
|
+
const withLocaleProvider_1 = __importDefault(require("../../utils/withLocaleProvider"));
|
|
11
|
+
const button_1 = __importDefault(require("./button"));
|
|
12
|
+
function CreditErrorAlert({ error, ...props }) {
|
|
13
|
+
const { t } = (0, context_1.useLocaleContext)();
|
|
14
|
+
const isCreditError = (error === null || error === void 0 ? void 0 : error.type) === error_1.CreditErrorType.NOT_ENOUGH;
|
|
15
|
+
if (!isCreditError) {
|
|
16
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", ...props, children: (error === null || error === void 0 ? void 0 : error.message) || t('unknownError') }));
|
|
17
|
+
}
|
|
18
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Alert, { severity: "warning", ...props, sx: {
|
|
19
|
+
px: 1,
|
|
20
|
+
py: 0,
|
|
21
|
+
'& .MuiAlert-message': {
|
|
22
|
+
width: '100%',
|
|
23
|
+
},
|
|
24
|
+
...props.sx,
|
|
25
|
+
}, children: [t('creditNotEnoughTip'), (0, jsx_runtime_1.jsx)(material_1.Stack, { direction: "row", sx: { justifyContent: 'flex-end' }, children: (0, jsx_runtime_1.jsx)(button_1.default, { shouldOpenInNewTab: true, size: "small", variant: "outlined", color: "warning", children: t('buyCreditsNow') }) })] }));
|
|
26
|
+
}
|
|
27
|
+
exports.default = (0, withLocaleProvider_1.default)(CreditErrorAlert, {
|
|
28
|
+
translations: {
|
|
29
|
+
en: {
|
|
30
|
+
unknownError: 'An unknown error occurred',
|
|
31
|
+
creditNotEnoughTip: 'Your credit balance is insufficient. Please buy more credits to continue using AI services.',
|
|
32
|
+
buyCreditsNow: 'Buy Credits Now',
|
|
33
|
+
},
|
|
34
|
+
zh: {
|
|
35
|
+
unknownError: '发生了未知错误',
|
|
36
|
+
creditNotEnoughTip: '您的额度不足。请购买更多额度以继续使用AI服务。',
|
|
37
|
+
buyCreditsNow: '立即购买额度',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const context_1 = require("@arcblock/ux/lib/Locale/context");
|
|
8
|
+
const icons_material_1 = require("@mui/icons-material");
|
|
9
|
+
const material_1 = require("@mui/material");
|
|
10
|
+
const colors_1 = require("@mui/material/colors");
|
|
11
|
+
const react_1 = require("react");
|
|
12
|
+
const app_1 = require("../../api/app");
|
|
13
|
+
const withLocaleProvider_1 = __importDefault(require("../../utils/withLocaleProvider"));
|
|
14
|
+
function CreditBalance({ balance = undefined, currency = undefined, useAIKitService = false }) {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const { t } = (0, context_1.useLocaleContext)();
|
|
17
|
+
const [creditData, setCreditData] = (0, react_1.useState)(null);
|
|
18
|
+
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
19
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
20
|
+
const fetchBalance = (0, react_1.useCallback)(async () => {
|
|
21
|
+
try {
|
|
22
|
+
setLoading(true);
|
|
23
|
+
setError(null);
|
|
24
|
+
const result = await (0, app_1.getCreditBalance)({ useAIKitService });
|
|
25
|
+
// Safely access response data
|
|
26
|
+
setCreditData(result);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
console.error('Failed to fetch balance:', err);
|
|
30
|
+
setError(err instanceof Error ? err.message : t('failedToLoadBalance'));
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
setLoading(false);
|
|
34
|
+
}
|
|
35
|
+
}, [t, useAIKitService]);
|
|
36
|
+
(0, react_1.useEffect)(() => {
|
|
37
|
+
fetchBalance();
|
|
38
|
+
}, [fetchBalance]);
|
|
39
|
+
if (loading) {
|
|
40
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Card, { children: (0, jsx_runtime_1.jsx)(material_1.CardContent, { children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
41
|
+
display: 'flex',
|
|
42
|
+
justifyContent: 'center',
|
|
43
|
+
alignItems: 'center',
|
|
44
|
+
minHeight: '120px',
|
|
45
|
+
}, children: (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { size: 32 }) }) }) }));
|
|
46
|
+
}
|
|
47
|
+
if (error) {
|
|
48
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Card, { children: (0, jsx_runtime_1.jsx)(material_1.CardContent, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, { color: "error", variant: "body2", sx: {
|
|
49
|
+
textAlign: 'center',
|
|
50
|
+
}, children: error }) }) }));
|
|
51
|
+
}
|
|
52
|
+
// Use props or API data
|
|
53
|
+
const displayBalance = (_a = balance !== null && balance !== void 0 ? balance : creditData === null || creditData === void 0 ? void 0 : creditData.balance) !== null && _a !== void 0 ? _a : '0';
|
|
54
|
+
const displayCurrency = (_b = currency !== null && currency !== void 0 ? currency : creditData === null || creditData === void 0 ? void 0 : creditData.currency) !== null && _b !== void 0 ? _b : 'USD';
|
|
55
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Card, { sx: {
|
|
56
|
+
background: `linear-gradient(135deg, ${colors_1.blue[500]} 0%, ${colors_1.blue[700]} 100%)`,
|
|
57
|
+
color: 'white',
|
|
58
|
+
position: 'relative',
|
|
59
|
+
overflow: 'hidden',
|
|
60
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.CardContent, { sx: { position: 'relative', zIndex: 1 }, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { spacing: 2, children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 1, sx: {
|
|
61
|
+
alignItems: 'center',
|
|
62
|
+
}, children: [(0, jsx_runtime_1.jsx)(icons_material_1.AccountBalanceWalletRounded, { sx: { fontSize: 28 } }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", sx: { fontWeight: 'bold' }, children: t('creditBalance') })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h3", sx: { fontWeight: 'bold', lineHeight: 1 }, children: displayBalance }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body1", sx: { opacity: 0.9, mt: 0.5 }, children: displayCurrency })] }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", sx: { opacity: 0.8 }, children: t('availableForUse') })] }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
63
|
+
position: 'absolute',
|
|
64
|
+
top: -20,
|
|
65
|
+
right: -20,
|
|
66
|
+
width: 80,
|
|
67
|
+
height: 80,
|
|
68
|
+
borderRadius: '50%',
|
|
69
|
+
backgroundColor: 'rgba(255, 255, 255, 0.1)',
|
|
70
|
+
zIndex: 0,
|
|
71
|
+
} }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
72
|
+
position: 'absolute',
|
|
73
|
+
bottom: -30,
|
|
74
|
+
left: -30,
|
|
75
|
+
width: 100,
|
|
76
|
+
height: 100,
|
|
77
|
+
borderRadius: '50%',
|
|
78
|
+
backgroundColor: 'rgba(255, 255, 255, 0.05)',
|
|
79
|
+
zIndex: 0,
|
|
80
|
+
} })] }));
|
|
81
|
+
}
|
|
82
|
+
exports.default = (0, withLocaleProvider_1.default)(CreditBalance, {
|
|
83
|
+
translations: {
|
|
84
|
+
en: {
|
|
85
|
+
creditBalance: 'Credit Balance',
|
|
86
|
+
availableForUse: 'Available for use',
|
|
87
|
+
failedToLoadBalance: 'Failed to load balance',
|
|
88
|
+
},
|
|
89
|
+
zh: {
|
|
90
|
+
creditBalance: '信用额度余额',
|
|
91
|
+
availableForUse: '可用余额',
|
|
92
|
+
failedToLoadBalance: '加载余额失败',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const context_1 = require("@arcblock/ux/lib/Locale/context");
|
|
8
|
+
const Toast_1 = __importDefault(require("@arcblock/ux/lib/Toast"));
|
|
9
|
+
const lab_1 = require("@mui/lab");
|
|
10
|
+
const material_1 = require("@mui/material");
|
|
11
|
+
const react_1 = require("react");
|
|
12
|
+
const ufo_1 = require("ufo");
|
|
13
|
+
const app_1 = require("../../api/app");
|
|
14
|
+
const withLocaleProvider_1 = __importDefault(require("../../utils/withLocaleProvider"));
|
|
15
|
+
function CreditButton({ shouldOpenInNewTab = true, size = 'small', variant = 'outlined', color = 'primary', children = null, useAIKitService = false, ...props }) {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const { t } = (0, context_1.useLocaleContext)();
|
|
18
|
+
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
19
|
+
const buyCredits = (0, react_1.useCallback)(async () => {
|
|
20
|
+
setSubmitting(true);
|
|
21
|
+
try {
|
|
22
|
+
const link = await (0, app_1.getCreditPaymentLink)({
|
|
23
|
+
useAIKitService,
|
|
24
|
+
});
|
|
25
|
+
if (link) {
|
|
26
|
+
const { href } = window.location;
|
|
27
|
+
const payLink = (0, ufo_1.withQuery)(link, {
|
|
28
|
+
redirect: href,
|
|
29
|
+
cancel_url: href,
|
|
30
|
+
});
|
|
31
|
+
if (shouldOpenInNewTab) {
|
|
32
|
+
const win = window.open(payLink, '_blank');
|
|
33
|
+
win === null || win === void 0 ? void 0 : win.focus();
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
window.location.href = payLink;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
Toast_1.default.error(t('creditPaymentLinkNotAvailable'));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
Toast_1.default.error(error.message || t('failedToGetCreditPaymentLink'));
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
setSubmitting(false);
|
|
48
|
+
}
|
|
49
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
50
|
+
}, [shouldOpenInNewTab]);
|
|
51
|
+
if (!((_b = (_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.preferences) === null || _b === void 0 ? void 0 : _b.creditBasedBillingEnabled)) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return ((0, jsx_runtime_1.jsx)(lab_1.LoadingButton, { onClick: buyCredits, size: size, variant: variant, color: color, type: "button", loading: submitting, ...props, children: children || (0, jsx_runtime_1.jsx)(material_1.Typography, { noWrap: true, children: t('buyCredits') }) }));
|
|
55
|
+
}
|
|
56
|
+
exports.default = (0, withLocaleProvider_1.default)(CreditButton, {
|
|
57
|
+
translations: {
|
|
58
|
+
en: {
|
|
59
|
+
buyCredits: 'Buy Credits',
|
|
60
|
+
creditPaymentLinkNotAvailable: 'Credit payment link is not available',
|
|
61
|
+
failedToGetCreditPaymentLink: 'Failed to get credit payment link',
|
|
62
|
+
},
|
|
63
|
+
zh: {
|
|
64
|
+
buyCredits: '购买额度',
|
|
65
|
+
creditPaymentLinkNotAvailable: '额度付款链接不可用',
|
|
66
|
+
failedToGetCreditPaymentLink: '获取额度付款链接失败',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CreditErrorAlert = exports.CreditBalance = exports.CreditButton = void 0;
|
|
7
|
+
var button_1 = require("./button");
|
|
8
|
+
Object.defineProperty(exports, "CreditButton", { enumerable: true, get: function () { return __importDefault(button_1).default; } });
|
|
9
|
+
var balance_1 = require("./balance");
|
|
10
|
+
Object.defineProperty(exports, "CreditBalance", { enumerable: true, get: function () { return __importDefault(balance_1).default; } });
|
|
11
|
+
var alert_1 = require("./alert");
|
|
12
|
+
Object.defineProperty(exports, "CreditErrorAlert", { enumerable: true, get: function () { return __importDefault(alert_1).default; } });
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = CustomFormLabel;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const icons_material_1 = require("@mui/icons-material");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
function CustomFormLabel({ children, required = false, tooltip = '', description = '', ...props }) {
|
|
8
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { mb: 1, width: '100%' }, children: [(0, jsx_runtime_1.jsxs)(material_1.FormLabel, { ...props, sx: {
|
|
9
|
+
display: 'flex',
|
|
10
|
+
alignItems: 'center',
|
|
11
|
+
gap: 0.5,
|
|
12
|
+
fontSize: '0.875rem',
|
|
13
|
+
fontWeight: 500,
|
|
14
|
+
color: 'text.primary',
|
|
15
|
+
'&.MuiFormLabel-root': {
|
|
16
|
+
display: 'flex',
|
|
17
|
+
alignItems: 'center',
|
|
18
|
+
gap: 0.5,
|
|
19
|
+
fontWeight: 500,
|
|
20
|
+
color: 'text.primary',
|
|
21
|
+
},
|
|
22
|
+
...(props.sx || {}),
|
|
23
|
+
}, children: [children, required && ((0, jsx_runtime_1.jsx)(material_1.Typography, { component: "span", color: "error", children: "*" })), tooltip &&
|
|
24
|
+
(typeof tooltip === 'string' ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: tooltip, children: (0, jsx_runtime_1.jsx)(icons_material_1.InfoOutlined, { fontSize: "small", sx: { opacity: 0.7, fontSize: '1rem' } }) })) : (tooltip))] }), description && ((0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "caption", sx: {
|
|
25
|
+
color: 'text.secondary',
|
|
26
|
+
}, children: description }))] }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = ImagePreview;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const CloudDownloadOutlined_1 = __importDefault(require("@mui/icons-material/CloudDownloadOutlined"));
|
|
9
|
+
const RotateRightOutlined_1 = __importDefault(require("@mui/icons-material/RotateRightOutlined"));
|
|
10
|
+
const ZoomInOutlined_1 = __importDefault(require("@mui/icons-material/ZoomInOutlined"));
|
|
11
|
+
const ZoomOutOutlined_1 = __importDefault(require("@mui/icons-material/ZoomOutOutlined"));
|
|
12
|
+
const material_1 = require("@mui/material");
|
|
13
|
+
const ahooks_1 = require("ahooks");
|
|
14
|
+
const file_saver_1 = require("file-saver");
|
|
15
|
+
const react_photo_view_1 = require("react-photo-view");
|
|
16
|
+
const ufo_1 = require("ufo");
|
|
17
|
+
const loading_image_1 = __importDefault(require("./loading-image"));
|
|
18
|
+
const renderIconButton = (children, onClick, { key, ...extraProps } = {}) => {
|
|
19
|
+
return ((0, jsx_runtime_1.jsx)(material_1.IconButton, { sx: {
|
|
20
|
+
transition: 'all 0.3s',
|
|
21
|
+
color: 'rgba(255,255,255,0.75)',
|
|
22
|
+
'&:hover': {
|
|
23
|
+
color: 'rgba(255,255,255,1)',
|
|
24
|
+
},
|
|
25
|
+
}, onClick: onClick, ...extraProps, children: children }, key));
|
|
26
|
+
};
|
|
27
|
+
function getExtFromBase64(base64) {
|
|
28
|
+
var _a;
|
|
29
|
+
// eslint-disable-next-line prefer-regex-literals
|
|
30
|
+
const re = new RegExp('data:image/([a-z]+);base64,.+');
|
|
31
|
+
const res = re.exec(base64);
|
|
32
|
+
if ((_a = res === null || res === void 0 ? void 0 : res.groups) === null || _a === void 0 ? void 0 : _a.ext) {
|
|
33
|
+
return res.groups.ext;
|
|
34
|
+
}
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
function ImagePreview({ dataSource = [], itemWidth = undefined, itemHeight = undefined, spacing = 1, transition = 'all 0.3s', borderRadius = 0, formatDownloadSrc = (value) => value, showDownloadButton = true, }) {
|
|
38
|
+
const state = (0, ahooks_1.useReactive)({
|
|
39
|
+
downloadingIndexMap: {},
|
|
40
|
+
});
|
|
41
|
+
const getDownloadButton = (currentIndex, extraProps = {}) => renderIconButton((0, jsx_runtime_1.jsx)(CloudDownloadOutlined_1.default, { fontSize: "inherit" }), async () => {
|
|
42
|
+
const { src } = (dataSource === null || dataSource === void 0 ? void 0 : dataSource[currentIndex]) || {};
|
|
43
|
+
state.downloadingIndexMap = {
|
|
44
|
+
...state.downloadingIndexMap,
|
|
45
|
+
[currentIndex]: true,
|
|
46
|
+
};
|
|
47
|
+
if (src) {
|
|
48
|
+
// download base64 image
|
|
49
|
+
if (src === null || src === void 0 ? void 0 : src.startsWith('data:image/')) {
|
|
50
|
+
const link = document.createElement('a');
|
|
51
|
+
link.href = src;
|
|
52
|
+
link.download = `image-${currentIndex}.${getExtFromBase64(src) || 'png'}`;
|
|
53
|
+
link.click();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// use file saver to download image, will slow down the performance
|
|
57
|
+
await (0, file_saver_1.saveAs)(formatDownloadSrc(src));
|
|
58
|
+
}
|
|
59
|
+
state.downloadingIndexMap = {
|
|
60
|
+
...state.downloadingIndexMap,
|
|
61
|
+
[currentIndex]: false,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}, {
|
|
65
|
+
key: 'download',
|
|
66
|
+
disabled: !!state.downloadingIndexMap[currentIndex],
|
|
67
|
+
...extraProps,
|
|
68
|
+
});
|
|
69
|
+
return ((0, jsx_runtime_1.jsxs)(react_photo_view_1.PhotoProvider, { toolbarRender: ({ index, scale, onScale, rotate, onRotate }) => {
|
|
70
|
+
return [
|
|
71
|
+
renderIconButton((0, jsx_runtime_1.jsx)(ZoomInOutlined_1.default, {}), () => onScale(scale + 0.25), {
|
|
72
|
+
key: 'scale-down',
|
|
73
|
+
}),
|
|
74
|
+
renderIconButton((0, jsx_runtime_1.jsx)(ZoomOutOutlined_1.default, {}), () => onScale(scale - 0.25), {
|
|
75
|
+
key: 'scale-up',
|
|
76
|
+
}),
|
|
77
|
+
renderIconButton((0, jsx_runtime_1.jsx)(RotateRightOutlined_1.default, {}), () => onRotate(rotate + 90), {
|
|
78
|
+
key: 'rotate',
|
|
79
|
+
}),
|
|
80
|
+
getDownloadButton(index),
|
|
81
|
+
];
|
|
82
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.GlobalStyles, { styles: ".PhotoView-Portal{height:100%;left:0;overflow:hidden;position:fixed;top:0;touch-action:none;width:100%;z-index:2000}@-webkit-keyframes PhotoView__rotate{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}@keyframes PhotoView__rotate{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}@-webkit-keyframes PhotoView__delayIn{0%,50%{opacity:0}to{opacity:1}}@keyframes PhotoView__delayIn{0%,50%{opacity:0}to{opacity:1}}.PhotoView__Spinner{-webkit-animation:PhotoView__delayIn .4s linear both;animation:PhotoView__delayIn .4s linear both}.PhotoView__Spinner svg{-webkit-animation:PhotoView__rotate .6s linear infinite;animation:PhotoView__rotate .6s linear infinite}.PhotoView__Photo{cursor:-webkit-grab;cursor:grab;max-width:none}.PhotoView__Photo:active{cursor:-webkit-grabbing;cursor:grabbing}.PhotoView__icon{display:inline-block;left:0;position:absolute;top:0;transform:translate(-50%,-50%)}.PhotoView__PhotoBox,.PhotoView__PhotoWrap{bottom:0;direction:ltr;left:0;position:absolute;right:0;top:0;touch-action:none;width:100%}.PhotoView__PhotoWrap{overflow:hidden;z-index:10}.PhotoView__PhotoBox{transform-origin:left top}@-webkit-keyframes PhotoView__fade{0%{opacity:0}to{opacity:1}}@keyframes PhotoView__fade{0%{opacity:0}to{opacity:1}}.PhotoView-Slider__clean .PhotoView-Slider__ArrowLeft,.PhotoView-Slider__clean .PhotoView-Slider__ArrowRight,.PhotoView-Slider__clean .PhotoView-Slider__BannerWrap,.PhotoView-Slider__clean .PhotoView-Slider__Overlay,.PhotoView-Slider__willClose .PhotoView-Slider__BannerWrap:hover{opacity:0}.PhotoView-Slider__Backdrop{background:#000;height:100%;left:0;position:absolute;top:0;transition-property:background-color;width:100%;z-index:-1}.PhotoView-Slider__fadeIn{-webkit-animation:PhotoView__fade linear both;animation:PhotoView__fade linear both;opacity:0}.PhotoView-Slider__fadeOut{animation:PhotoView__fade linear reverse both;opacity:0}.PhotoView-Slider__BannerWrap{align-items:center;background-color:rgba(0,0,0,.5);color:#fff;display:flex;height:44px;justify-content:space-between;left:0;position:absolute;top:0;transition:opacity .2s ease-out;width:100%;z-index:20}.PhotoView-Slider__BannerWrap:hover{opacity:1}.PhotoView-Slider__Counter{font-size:14px;opacity:.75;padding:0 10px}.PhotoView-Slider__BannerRight{align-items:center;display:flex;height:100%}.PhotoView-Slider__toolbarIcon{fill:#fff;box-sizing:border-box;cursor:pointer;opacity:.75;padding:10px;transition:opacity .2s linear}.PhotoView-Slider__toolbarIcon:hover{opacity:1}.PhotoView-Slider__ArrowLeft,.PhotoView-Slider__ArrowRight{align-items:center;bottom:0;cursor:pointer;display:flex;height:100px;justify-content:center;margin:auto;opacity:.75;position:absolute;top:0;transition:opacity .2s linear;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:70px;z-index:20}.PhotoView-Slider__ArrowLeft:hover,.PhotoView-Slider__ArrowRight:hover{opacity:1}.PhotoView-Slider__ArrowLeft svg,.PhotoView-Slider__ArrowRight svg{fill:#fff;background:rgba(0,0,0,.3);box-sizing:content-box;height:24px;padding:10px;width:24px}.PhotoView-Slider__ArrowLeft{left:0}.PhotoView-Slider__ArrowRight{right:0}" }), (0, jsx_runtime_1.jsx)(material_1.Grid, { spacing: spacing, container: true, className: "photo-wrapper", children: dataSource === null || dataSource === void 0 ? void 0 : dataSource.map((item, index) => {
|
|
83
|
+
const { width, height } = item;
|
|
84
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Grid
|
|
85
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
86
|
+
, { className: "photo-item", sx: {
|
|
87
|
+
transition,
|
|
88
|
+
'&:hover': {
|
|
89
|
+
cursor: 'pointer',
|
|
90
|
+
'& .photo-toolbar': {
|
|
91
|
+
transition,
|
|
92
|
+
opacity: 1,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
}, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { position: 'relative' }, children: [(0, jsx_runtime_1.jsx)(react_photo_view_1.PhotoView, { ...item, children: (0, jsx_runtime_1.jsx)(loading_image_1.default, { ...item, src: (0, ufo_1.withQuery)(item.src, {
|
|
96
|
+
imageFilter: 'resize',
|
|
97
|
+
f: 'webp',
|
|
98
|
+
w: typeof itemWidth === 'number' ? Math.min(itemWidth * 2, 1200) : undefined,
|
|
99
|
+
}), style: {
|
|
100
|
+
transition,
|
|
101
|
+
borderRadius,
|
|
102
|
+
objectFit: 'cover',
|
|
103
|
+
width: width || itemWidth || '100%',
|
|
104
|
+
height: height || itemHeight || '100%',
|
|
105
|
+
} }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { className: "photo-toolbar", sx: {
|
|
106
|
+
position: 'absolute',
|
|
107
|
+
right: 0,
|
|
108
|
+
top: 0,
|
|
109
|
+
opacity: 0,
|
|
110
|
+
background: 'rgba(0,0,0,0.7)',
|
|
111
|
+
}, children: showDownloadButton &&
|
|
112
|
+
getDownloadButton(index, {
|
|
113
|
+
size: 'small',
|
|
114
|
+
}) })] }) }, index));
|
|
115
|
+
}) })] }));
|
|
116
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/// <reference path="../env.d.ts" />
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.FormLabel = exports.Table = exports.Switch = exports.CreditErrorAlert = exports.CreditBalance = exports.CreditButton = exports.SubscribeErrorAlert = exports.SubscribeButton = exports.Conversation = exports.ImagePreview = exports.LoadingImage = void 0;
|
|
22
|
+
var loading_image_1 = require("./loading-image");
|
|
23
|
+
Object.defineProperty(exports, "LoadingImage", { enumerable: true, get: function () { return __importDefault(loading_image_1).default; } });
|
|
24
|
+
var image_preview_1 = require("./image-preview");
|
|
25
|
+
Object.defineProperty(exports, "ImagePreview", { enumerable: true, get: function () { return __importDefault(image_preview_1).default; } });
|
|
26
|
+
var conversation_1 = require("./conversation");
|
|
27
|
+
Object.defineProperty(exports, "Conversation", { enumerable: true, get: function () { return __importDefault(conversation_1).default; } });
|
|
28
|
+
__exportStar(require("./conversation"), exports);
|
|
29
|
+
var button_1 = require("./subscribe/button");
|
|
30
|
+
Object.defineProperty(exports, "SubscribeButton", { enumerable: true, get: function () { return __importDefault(button_1).default; } });
|
|
31
|
+
var alert_1 = require("./subscribe/alert");
|
|
32
|
+
Object.defineProperty(exports, "SubscribeErrorAlert", { enumerable: true, get: function () { return __importDefault(alert_1).default; } });
|
|
33
|
+
// Credit components
|
|
34
|
+
var button_2 = require("./credit/button");
|
|
35
|
+
Object.defineProperty(exports, "CreditButton", { enumerable: true, get: function () { return __importDefault(button_2).default; } });
|
|
36
|
+
var balance_1 = require("./credit/balance");
|
|
37
|
+
Object.defineProperty(exports, "CreditBalance", { enumerable: true, get: function () { return __importDefault(balance_1).default; } });
|
|
38
|
+
var alert_2 = require("./credit/alert");
|
|
39
|
+
Object.defineProperty(exports, "CreditErrorAlert", { enumerable: true, get: function () { return __importDefault(alert_2).default; } });
|
|
40
|
+
var switch_button_1 = require("./switch-button");
|
|
41
|
+
Object.defineProperty(exports, "Switch", { enumerable: true, get: function () { return __importDefault(switch_button_1).default; } });
|
|
42
|
+
var table_1 = require("./table");
|
|
43
|
+
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return __importDefault(table_1).default; } });
|
|
44
|
+
var form_label_1 = require("./form-label");
|
|
45
|
+
Object.defineProperty(exports, "FormLabel", { enumerable: true, get: function () { return __importDefault(form_label_1).default; } });
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const ahooks_1 = require("ahooks");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
function LoadingImage({ ref = undefined, onLoad = () => { }, ...props }) {
|
|
9
|
+
const imageRef = (0, react_1.useRef)(null);
|
|
10
|
+
const state = (0, ahooks_1.useReactive)({
|
|
11
|
+
loading: true,
|
|
12
|
+
});
|
|
13
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: { position: 'relative' }, ref: ref || imageRef, children: [(0, jsx_runtime_1.jsx)("div", { className: "lazy-image-wrapper", style: {
|
|
14
|
+
visibility: state.loading ? 'hidden' : 'visible',
|
|
15
|
+
background: '#f4f4f4',
|
|
16
|
+
width: '100%',
|
|
17
|
+
height: '100%',
|
|
18
|
+
display: 'flex',
|
|
19
|
+
alignItems: 'center',
|
|
20
|
+
justifyContent: 'center',
|
|
21
|
+
}, children: (0, jsx_runtime_1.jsx)("img", { alt: "", ...props, onLoad: () => {
|
|
22
|
+
state.loading = false;
|
|
23
|
+
try {
|
|
24
|
+
onLoad();
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.error('image onLoad error: ', error);
|
|
28
|
+
}
|
|
29
|
+
}, loading: "eager" // must be eager to make sure the image is loaded
|
|
30
|
+
}) }), state.loading && ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { className: "lazy-image-skeleton", animation: "wave", variant: "rectangular", style: {
|
|
31
|
+
width: '100%',
|
|
32
|
+
height: '100%',
|
|
33
|
+
position: 'absolute',
|
|
34
|
+
top: 0,
|
|
35
|
+
} }))] }));
|
|
36
|
+
}
|
|
37
|
+
exports.default = LoadingImage;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const context_1 = require("@arcblock/ux/lib/Locale/context");
|
|
8
|
+
const material_1 = require("@mui/material");
|
|
9
|
+
const error_1 = require("../../api/error");
|
|
10
|
+
const withLocaleProvider_1 = __importDefault(require("../../utils/withLocaleProvider"));
|
|
11
|
+
const button_1 = __importDefault(require("./button"));
|
|
12
|
+
const state_1 = require("./state");
|
|
13
|
+
function SubscribeErrorAlert({ error, ...props }) {
|
|
14
|
+
const { t } = (0, context_1.useLocaleContext)();
|
|
15
|
+
const isUnsubscribeError = (error === null || error === void 0 ? void 0 : error.type) === error_1.SubscriptionErrorType.UNSUBSCRIBED;
|
|
16
|
+
const loading = (0, state_1.useAIKitServiceStatus)((i) => i.loading);
|
|
17
|
+
const subscription = (0, state_1.useAIKitServiceStatus)((i) => { var _a; return (_a = i.app) === null || _a === void 0 ? void 0 : _a.subscription; });
|
|
18
|
+
const useAIKitService = (0, state_1.useAIKitServiceStatus)((i) => { var _a, _b; return (_b = (_a = i.app) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.useAIKitService; });
|
|
19
|
+
const isPastDue = (subscription === null || subscription === void 0 ? void 0 : subscription.status) === 'past_due';
|
|
20
|
+
const message = !isUnsubscribeError
|
|
21
|
+
? error.message
|
|
22
|
+
: !subscription
|
|
23
|
+
? t('notSubscribeTip')
|
|
24
|
+
: isPastDue
|
|
25
|
+
? t('pastDueTip')
|
|
26
|
+
: !useAIKitService
|
|
27
|
+
? t('notEnableAIServiceTip')
|
|
28
|
+
: t('successTip');
|
|
29
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Alert, { severity: isUnsubscribeError && subscription && useAIKitService ? 'info' : 'warning', ...props, sx: {
|
|
30
|
+
px: 1,
|
|
31
|
+
py: 0,
|
|
32
|
+
'& .MuiAlert-message': {
|
|
33
|
+
width: '100%',
|
|
34
|
+
},
|
|
35
|
+
...props.sx,
|
|
36
|
+
}, children: [isUnsubscribeError && loading ? (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { size: 18 }) : message, isUnsubscribeError && ((0, jsx_runtime_1.jsx)(material_1.Stack, { direction: "row", sx: { justifyContent: 'flex-end' }, children: (0, jsx_runtime_1.jsx)(button_1.default, { shouldOpenInNewTab: true, showUseAIServiceButton: true }) }))] }));
|
|
37
|
+
}
|
|
38
|
+
exports.default = (0, withLocaleProvider_1.default)(SubscribeErrorAlert, {
|
|
39
|
+
translations: {
|
|
40
|
+
en: {
|
|
41
|
+
notSubscribeTip: 'Hello, please subscribe to AI service first!',
|
|
42
|
+
pastDueTip: 'Your AI service has expired, please renew it first!',
|
|
43
|
+
notEnableAIServiceTip: 'You have not enabled AI service, please enable AI service first!',
|
|
44
|
+
successTip: 'Congratulations, your subscription is successful!',
|
|
45
|
+
},
|
|
46
|
+
zh: {
|
|
47
|
+
notSubscribeTip: '你好,请订阅 AI 服务后继续!',
|
|
48
|
+
pastDueTip: '您的 AI 服务已过期,请续订后继续!',
|
|
49
|
+
notEnableAIServiceTip: '您尚未启用AI服务,请启用 AI 服务后继续!',
|
|
50
|
+
successTip: '恭喜,您的订阅已生效!',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|