@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.
Files changed (128) hide show
  1. package/README.md +29 -0
  2. package/lib/cjs/api/ai-kit.js +60 -0
  3. package/lib/cjs/api/api.js +17 -0
  4. package/lib/cjs/api/app.js +57 -0
  5. package/lib/cjs/api/call/api.js +51 -0
  6. package/lib/cjs/api/call/app.js +74 -0
  7. package/lib/cjs/api/call/index.js +19 -0
  8. package/lib/cjs/api/call/proxy.js +64 -0
  9. package/lib/cjs/api/call/v1.js +166 -0
  10. package/lib/cjs/api/call/v2.js +101 -0
  11. package/lib/cjs/api/config.js +46 -0
  12. package/lib/cjs/api/constants.js +4 -0
  13. package/lib/cjs/api/error.js +42 -0
  14. package/lib/cjs/api/index.js +19 -0
  15. package/lib/cjs/api/types/audio.js +2 -0
  16. package/lib/cjs/api/types/chat.js +14 -0
  17. package/lib/cjs/api/types/embedding.js +2 -0
  18. package/lib/cjs/api/types/image.js +2 -0
  19. package/lib/cjs/api/types/index.js +19 -0
  20. package/lib/cjs/api/types/status.js +2 -0
  21. package/lib/cjs/api/utils/auth.js +90 -0
  22. package/lib/cjs/api/utils/event-stream.js +59 -0
  23. package/lib/cjs/components/conversation/conversation.js +71 -0
  24. package/lib/cjs/components/conversation/index.js +25 -0
  25. package/lib/cjs/components/conversation/message.js +120 -0
  26. package/lib/cjs/components/conversation/prompt.js +43 -0
  27. package/lib/cjs/components/conversation/use-conversation.js +100 -0
  28. package/lib/cjs/components/credit/alert.js +40 -0
  29. package/lib/cjs/components/credit/balance.js +95 -0
  30. package/lib/cjs/components/credit/button.js +69 -0
  31. package/lib/cjs/components/credit/index.js +12 -0
  32. package/lib/cjs/components/form-label.js +27 -0
  33. package/lib/cjs/components/image-preview.js +116 -0
  34. package/lib/cjs/components/index.js +45 -0
  35. package/lib/cjs/components/loading-image.js +37 -0
  36. package/lib/cjs/components/subscribe/alert.js +53 -0
  37. package/lib/cjs/components/subscribe/button.js +92 -0
  38. package/lib/cjs/components/subscribe/state.js +42 -0
  39. package/lib/cjs/components/switch-button.js +48 -0
  40. package/lib/cjs/components/table.js +203 -0
  41. package/lib/cjs/index.js +2 -0
  42. package/lib/cjs/libs/logger.js +8 -0
  43. package/lib/cjs/utils/withLocaleProvider.js +11 -0
  44. package/lib/esm/api/ai-kit.js +54 -0
  45. package/lib/esm/api/api.js +11 -0
  46. package/lib/esm/api/app.js +42 -0
  47. package/lib/esm/api/call/api.js +24 -0
  48. package/lib/esm/api/call/app.js +68 -0
  49. package/lib/esm/api/call/index.js +3 -0
  50. package/lib/esm/api/call/proxy.js +58 -0
  51. package/lib/esm/api/call/v1.js +155 -0
  52. package/lib/esm/api/call/v2.js +93 -0
  53. package/lib/esm/api/config.js +41 -0
  54. package/lib/esm/api/constants.js +1 -0
  55. package/lib/esm/api/error.js +37 -0
  56. package/lib/esm/api/index.js +3 -0
  57. package/lib/esm/api/types/audio.js +1 -0
  58. package/lib/esm/api/types/chat.js +9 -0
  59. package/lib/esm/api/types/embedding.js +1 -0
  60. package/lib/esm/api/types/image.js +1 -0
  61. package/lib/esm/api/types/index.js +3 -0
  62. package/lib/esm/api/types/status.js +1 -0
  63. package/lib/esm/api/utils/auth.js +79 -0
  64. package/lib/esm/api/utils/event-stream.js +50 -0
  65. package/lib/esm/components/conversation/conversation.js +65 -0
  66. package/lib/esm/components/conversation/index.js +4 -0
  67. package/lib/esm/components/conversation/message.js +114 -0
  68. package/lib/esm/components/conversation/prompt.js +40 -0
  69. package/lib/esm/components/conversation/use-conversation.js +97 -0
  70. package/lib/esm/components/credit/alert.js +35 -0
  71. package/lib/esm/components/credit/balance.js +90 -0
  72. package/lib/esm/components/credit/button.js +64 -0
  73. package/lib/esm/components/credit/index.js +3 -0
  74. package/lib/esm/components/form-label.js +24 -0
  75. package/lib/esm/components/image-preview.js +110 -0
  76. package/lib/esm/components/index.js +14 -0
  77. package/lib/esm/components/loading-image.js +35 -0
  78. package/lib/esm/components/subscribe/alert.js +48 -0
  79. package/lib/esm/components/subscribe/button.js +87 -0
  80. package/lib/esm/components/subscribe/state.js +39 -0
  81. package/lib/esm/components/switch-button.js +46 -0
  82. package/lib/esm/components/table.js +198 -0
  83. package/lib/esm/index.js +1 -0
  84. package/lib/esm/libs/logger.js +3 -0
  85. package/lib/esm/utils/withLocaleProvider.js +8 -0
  86. package/lib/types/api/ai-kit.d.ts +70 -0
  87. package/lib/types/api/api.d.ts +4 -0
  88. package/lib/types/api/app.d.ts +113 -0
  89. package/lib/types/api/call/api.d.ts +2 -0
  90. package/lib/types/api/call/app.d.ts +50 -0
  91. package/lib/types/api/call/index.d.ts +3 -0
  92. package/lib/types/api/call/proxy.d.ts +6 -0
  93. package/lib/types/api/call/v1.d.ts +51 -0
  94. package/lib/types/api/call/v2.d.ts +30 -0
  95. package/lib/types/api/config.d.ts +14 -0
  96. package/lib/types/api/constants.d.ts +1 -0
  97. package/lib/types/api/error.d.ts +18 -0
  98. package/lib/types/api/index.d.ts +3 -0
  99. package/lib/types/api/types/audio.d.ts +18 -0
  100. package/lib/types/api/types/chat.d.ts +97 -0
  101. package/lib/types/api/types/embedding.d.ts +9 -0
  102. package/lib/types/api/types/image.d.ts +23 -0
  103. package/lib/types/api/types/index.d.ts +3 -0
  104. package/lib/types/api/types/status.d.ts +3 -0
  105. package/lib/types/api/utils/auth.d.ts +33 -0
  106. package/lib/types/api/utils/event-stream.d.ts +7 -0
  107. package/lib/types/components/conversation/conversation.d.ts +30 -0
  108. package/lib/types/components/conversation/index.d.ts +4 -0
  109. package/lib/types/components/conversation/message.d.ts +10 -0
  110. package/lib/types/components/conversation/prompt.d.ts +10 -0
  111. package/lib/types/components/conversation/use-conversation.d.ts +44 -0
  112. package/lib/types/components/credit/alert.d.ts +10 -0
  113. package/lib/types/components/credit/balance.d.ts +7 -0
  114. package/lib/types/components/credit/button.d.ts +11 -0
  115. package/lib/types/components/credit/index.d.ts +3 -0
  116. package/lib/types/components/form-label.d.ts +7 -0
  117. package/lib/types/components/image-preview.d.ts +17 -0
  118. package/lib/types/components/index.d.ts +12 -0
  119. package/lib/types/components/loading-image.d.ts +6 -0
  120. package/lib/types/components/subscribe/alert.d.ts +5 -0
  121. package/lib/types/components/subscribe/button.d.ts +5 -0
  122. package/lib/types/components/subscribe/state.d.ts +14 -0
  123. package/lib/types/components/switch-button.d.ts +7 -0
  124. package/lib/types/components/table.d.ts +3 -0
  125. package/lib/types/index.d.ts +1 -0
  126. package/lib/types/libs/logger.d.ts +2 -0
  127. package/lib/types/utils/withLocaleProvider.d.ts +9 -0
  128. package/package.json +158 -0
@@ -0,0 +1,92 @@
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
+ const state_1 = require("./state");
16
+ function SubscribeButton({ shouldOpenInNewTab = false, showUseAIServiceButton = false, }) {
17
+ const { t } = (0, context_1.useLocaleContext)();
18
+ const fetch = (0, state_1.useAIKitServiceStatus)((i) => i.fetch);
19
+ const isSubscriptionAvailable = (0, state_1.useAIKitServiceStatus)((i) => { var _a; return (_a = i.computed) === null || _a === void 0 ? void 0 : _a.isSubscriptionAvailable; });
20
+ const loading = (0, state_1.useAIKitServiceStatus)((i) => i.loading);
21
+ const setConfig = (0, state_1.useAIKitServiceStatus)((i) => i.setConfig);
22
+ const subscription = (0, state_1.useAIKitServiceStatus)((i) => { var _a; return (_a = i.app) === null || _a === void 0 ? void 0 : _a.subscription; });
23
+ 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; });
24
+ const subscriptionDetailUrl = (0, state_1.useAIKitServiceStatus)((i) => { var _a; return (_a = i.app) === null || _a === void 0 ? void 0 : _a.subscriptionDetailUrl; });
25
+ const isPastDue = (subscription === null || subscription === void 0 ? void 0 : subscription.status) === 'past_due';
26
+ const [submitting, setSubmitting] = (0, react_1.useState)(false);
27
+ const linkToAiKit = (0, react_1.useCallback)(async () => {
28
+ var _a, _b;
29
+ setSubmitting(true);
30
+ try {
31
+ const res = await (0, app_1.appServiceRegister)();
32
+ if (res.paymentLink) {
33
+ const { origin, href } = window.location;
34
+ const prefix = ((_b = (_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.componentMountPoints.find((i) => i.name === 'ai-kit')) === null || _b === void 0 ? void 0 : _b.mountPoint) || '/';
35
+ const payLink = (0, ufo_1.withQuery)(res.paymentLink, {
36
+ redirect: (0, ufo_1.withQuery)((0, ufo_1.joinURL)(origin, prefix, '/api/app/client/subscription/success'), { redirect: href }),
37
+ });
38
+ if (shouldOpenInNewTab) {
39
+ const win = window.open(payLink, '_blank');
40
+ win === null || win === void 0 ? void 0 : win.focus();
41
+ }
42
+ else {
43
+ window.location.href = payLink;
44
+ }
45
+ }
46
+ }
47
+ catch (error) {
48
+ Toast_1.default.error(error.message);
49
+ throw error;
50
+ }
51
+ finally {
52
+ setSubmitting(false);
53
+ }
54
+ }, [shouldOpenInNewTab]);
55
+ (0, react_1.useEffect)(() => {
56
+ fetch();
57
+ }, [fetch]);
58
+ if (!loading && !isSubscriptionAvailable) {
59
+ return ((0, jsx_runtime_1.jsx)(lab_1.LoadingButton, { onClick: isPastDue && subscriptionDetailUrl ? undefined : linkToAiKit, href: subscriptionDetailUrl, size: "small", variant: "outlined", color: isPastDue ? 'error' : 'primary', type: "button", sx: { mx: 0.5, minWidth: 0 }, loading: submitting, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { noWrap: true, children: t(isPastDue ? 'aiServicePastDue' : 'subscribeAIService') }) }, "button"));
60
+ }
61
+ if (showUseAIServiceButton && isSubscriptionAvailable && !useAIKitService) {
62
+ return ((0, jsx_runtime_1.jsx)(lab_1.LoadingButton, { loading: submitting, onClick: async () => {
63
+ setSubmitting(true);
64
+ try {
65
+ await setConfig({ useAIKitService: true });
66
+ Toast_1.default.success('Successfully changed to AI service!');
67
+ }
68
+ catch (error) {
69
+ Toast_1.default.error(error.message);
70
+ throw error;
71
+ }
72
+ finally {
73
+ setSubmitting(false);
74
+ }
75
+ }, children: t('useAIService') }));
76
+ }
77
+ return null;
78
+ }
79
+ exports.default = (0, withLocaleProvider_1.default)(SubscribeButton, {
80
+ translations: {
81
+ en: {
82
+ subscribeAIService: 'Subscribe AI Service',
83
+ aiServicePastDue: 'Pay for overdue AI service',
84
+ useAIService: 'Enable AI Service',
85
+ },
86
+ zh: {
87
+ subscribeAIService: '订阅 AI 服务',
88
+ aiServicePastDue: '支付 AI 服务欠费',
89
+ useAIService: '启用 AI 服务',
90
+ },
91
+ },
92
+ });
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAIKitServiceStatus = void 0;
4
+ const zustand_1 = require("zustand");
5
+ const immer_1 = require("zustand/middleware/immer");
6
+ const app_1 = require("../../api/app");
7
+ exports.useAIKitServiceStatus = (0, zustand_1.create)()((0, immer_1.immer)((set, get) => ({
8
+ loading: true,
9
+ fetch: async () => {
10
+ set((state) => {
11
+ state.loading = true;
12
+ });
13
+ try {
14
+ const app = await (0, app_1.appStatus)();
15
+ set((state) => {
16
+ state.app = app;
17
+ state.error = undefined;
18
+ state.loading = false;
19
+ });
20
+ }
21
+ catch (error) {
22
+ set((state) => {
23
+ state.error = error;
24
+ state.loading = false;
25
+ });
26
+ }
27
+ },
28
+ setConfig: async (config) => {
29
+ const result = await (0, app_1.setAppConfig)(config);
30
+ set((state) => {
31
+ if (state.app)
32
+ state.app.config = result;
33
+ });
34
+ },
35
+ computed: {
36
+ get isSubscriptionAvailable() {
37
+ var _a;
38
+ const subscription = (_a = get().app) === null || _a === void 0 ? void 0 : _a.subscription;
39
+ return subscription && ['active', 'trialing'].includes(subscription.status);
40
+ },
41
+ },
42
+ })));
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const material_1 = require("@mui/material");
4
+ const system_1 = require("@mui/system");
5
+ const SwitchButton = (0, system_1.styled)(material_1.Switch)(({ variant = 'success', theme }) => {
6
+ var _a, _b;
7
+ return ({
8
+ width: 28,
9
+ height: 16,
10
+ padding: 0,
11
+ display: 'inline-flex',
12
+ '&:active': {
13
+ '& .MuiSwitch-thumb': {
14
+ width: 15,
15
+ },
16
+ '& .MuiSwitch-switchBase.Mui-checked': {
17
+ transform: 'translateX(9px)',
18
+ },
19
+ },
20
+ '& .MuiSwitch-switchBase': {
21
+ padding: 2,
22
+ '&.Mui-checked': {
23
+ transform: 'translateX(12px)',
24
+ color: '#fff',
25
+ '& + .MuiSwitch-track': {
26
+ opacity: 1,
27
+ backgroundColor: (_a = theme.palette[variant]) === null || _a === void 0 ? void 0 : _a.light,
28
+ },
29
+ },
30
+ },
31
+ '& .MuiSwitch-thumb': {
32
+ boxShadow: '0 2px 4px 0 rgb(0 35 11 / 20%)',
33
+ width: 12,
34
+ height: 12,
35
+ borderRadius: 6,
36
+ transition: (_b = theme.transitions) === null || _b === void 0 ? void 0 : _b.create(['width'], {
37
+ duration: 200,
38
+ }),
39
+ },
40
+ '& .MuiSwitch-track': {
41
+ borderRadius: 16 / 2,
42
+ opacity: 1,
43
+ backgroundColor: theme.palette.mode === 'dark' ? 'rgba(255,255,255,.35)' : 'rgba(0,0,0,.25)',
44
+ boxSizing: 'border-box',
45
+ },
46
+ });
47
+ });
48
+ exports.default = SwitchButton;
@@ -0,0 +1,203 @@
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 Datatable_1 = __importDefault(require("@arcblock/ux/lib/Datatable"));
8
+ const Empty_1 = __importDefault(require("@arcblock/ux/lib/Empty"));
9
+ const context_1 = require("@arcblock/ux/lib/Locale/context");
10
+ const material_1 = require("@mui/material");
11
+ // eslint-disable-next-line import/no-extraneous-dependencies
12
+ const system_1 = require("@mui/system");
13
+ /* eslint-disable @typescript-eslint/indent */
14
+ const react_1 = __importDefault(require("react"));
15
+ const withLocaleProvider_1 = __importDefault(require("../utils/withLocaleProvider"));
16
+ function EmptyStub() {
17
+ return null;
18
+ }
19
+ const Table = react_1.default.memo(({ options, columns, toolbar = true, footer = true, hasRowLink = false, emptyNodeText = '', ...rest }) => {
20
+ const { locale, t } = (0, context_1.useLocaleContext)();
21
+ const theme = (0, material_1.useTheme)();
22
+ const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('md'));
23
+ const defaultOptions = {
24
+ print: false,
25
+ download: false,
26
+ filter: false,
27
+ selectableRows: 'none',
28
+ rowsPerPage: isMobile ? 5 : 10,
29
+ rowsPerPageOptions: [5, 10, 20, 50, 100],
30
+ searchDebounceTime: 300,
31
+ tableBodyHeight: '100%',
32
+ loading: true,
33
+ };
34
+ const components = {};
35
+ if (!toolbar) {
36
+ components.TableToolbar = EmptyStub;
37
+ }
38
+ if (!footer) {
39
+ components.TableFooter = EmptyStub;
40
+ }
41
+ // components.TableHead = EmptyStub2
42
+ return ((0, jsx_runtime_1.jsx)(Wrapped, { locale: locale, options: { ...defaultOptions, ...options }, columns: columns.map((x) => {
43
+ x.options = x.options || {};
44
+ x.options.filter = x.options.filter || false;
45
+ x.options.sort = x.options.sort || false;
46
+ return x;
47
+ }), emptyNode: (0, jsx_runtime_1.jsx)(Empty_1.default, { children: emptyNodeText || t('empty') }), ...rest, components: components, hasRowLink: hasRowLink, isMobile: isMobile }));
48
+ });
49
+ const Wrapped = (0, system_1.styled)(Datatable_1.default) `
50
+ ${(props) => (props === null || props === void 0 ? void 0 : props.hasRowLink)
51
+ ? `.MuiTableCell-root {
52
+ font-size: 0.875rem !important;
53
+ }`
54
+ : ''}
55
+ .MuiPaper-root {
56
+ border-radius: 8px;
57
+ overflow: hidden;
58
+ }
59
+ table.MuiTable-root {
60
+ outline: 1px solid;
61
+ outline-color: ${({ theme }) => theme.palette.grey[100]};
62
+ border-radius: ${({ theme }) => `${2 * theme.shape.borderRadius}px`};
63
+ overflow: hidden;
64
+ }
65
+ [class*='MUIDataTable-responsiveBase'] {
66
+ outline: 1px solid;
67
+ outline-color: ${({ theme }) => theme.palette.grey[100]};
68
+ border-radius: ${({ theme }) => `${2 * theme.shape.borderRadius}px`};
69
+ }
70
+
71
+ th.MuiTableCell-head {
72
+ padding: 8px 16px 8px 16px;
73
+ text-transform: inherit;
74
+ background: ${({ theme }) => theme.palette.grey[50]};
75
+ border-bottom: none;
76
+ &:first-of-type {
77
+ border-top-left-radius: 8px;
78
+ padding-left: 20px;
79
+ }
80
+ &:last-of-type {
81
+ border-top-right-radius: 8px;
82
+ }
83
+ }
84
+
85
+ tr.MuiTableRow-root:not(.MuiTableRow-footer):hover {
86
+ background: ${({ theme }) => theme.palette.grey[100]};
87
+ }
88
+ tr.MuiTableRow-root:last-of-type td:first-of-type {
89
+ border-bottom-left-radius: 8px;
90
+ }
91
+
92
+ tr.MuiTableRow-root:last-of-type td:last-of-type {
93
+ border-bottom-right-radius: 8px;
94
+ }
95
+
96
+ tr.MuiTableRow-root:nth-of-type(even) {
97
+ background: ${({ theme }) => theme.palette.grey[50]};
98
+ }
99
+ td.MuiTableCell-root {
100
+ border-bottom: none;
101
+ padding-top: 12px;
102
+ padding-bottom: 12px;
103
+ padding-left: 16px;
104
+ padding-right: 16px;
105
+ &:first-of-type {
106
+ padding-left: 20px;
107
+ }
108
+ &.MuiTableCell-footer {
109
+ border: none;
110
+ }
111
+ }
112
+
113
+ .datatable-footer {
114
+ .MuiTableRow-root.MuiTableRow-footer {
115
+ border: none;
116
+ }
117
+ table.MuiTable-root {
118
+ outline: none;
119
+ overflow: hidden;
120
+ }
121
+ .MuiTablePagination-input {
122
+ background: none;
123
+ }
124
+ div.MuiSelect-select {
125
+ padding: 0 24px 0 0;
126
+ }
127
+ }
128
+
129
+ th a,
130
+ td a {
131
+ text-decoration: none;
132
+ display: block;
133
+ color: inherit;
134
+ &:first-of-type {
135
+ padding-left: 0;
136
+ }
137
+ }
138
+
139
+ > div {
140
+ overflow: auto;
141
+ }
142
+ .custom-toobar-title-inner {
143
+ display: flex;
144
+ align-items: center;
145
+ }
146
+ @media (max-width: ${({ theme }) => theme.breakpoints.values.md}px) {
147
+ th a,
148
+ td a {
149
+ text-decoration: none;
150
+ display: block;
151
+ color: inherit;
152
+ padding-top: 0;
153
+ padding-bottom: 0;
154
+ padding-right: 0;
155
+ }
156
+ tr.MuiTableRow-root {
157
+ border: none;
158
+ padding: 20px;
159
+ display: block;
160
+ }
161
+ td.MuiTableCell-root:first-of-type {
162
+ padding-left: 0;
163
+ margin-top: 0;
164
+ }
165
+ td.MuiTableCell-root {
166
+ margin: 0;
167
+ margin-top: 8px;
168
+ align-items: center;
169
+ padding: 0;
170
+ flex-wrap: wrap;
171
+ flex-direction: ${({ mobileTDFlexDirection = 'column' }) => mobileTDFlexDirection || 'row'};
172
+ align-items: ${({ mobileTDFlexDirection = 'column' }) => mobileTDFlexDirection === 'column' ? 'flex-start' : 'center'};
173
+ justify-content: ${({ mobileTDFlexDirection = 'column' }) => mobileTDFlexDirection === 'column' ? 'flex-start' : 'space-between'};
174
+ }
175
+ td.MuiTableCell-root > div {
176
+ margin-bottom: 4px;
177
+ }
178
+ .MuiTable-root > .MuiTableBody-root > .MuiTableRow-root > td.MuiTableCell-root {
179
+ display: flex;
180
+ flex-direction: ${({ mobileTDFlexDirection = 'column' }) => mobileTDFlexDirection || 'row'};
181
+ align-items: flex-start;
182
+ justify-content: ${({ mobileTDFlexDirection = 'column' }) => mobileTDFlexDirection === 'row' ? 'space-between' : 'flex-start'};
183
+ flex-wrap: ${({ mobileTDFlexDirection = 'column' }) => (mobileTDFlexDirection === 'row' ? 'nowrap' : 'wrap')};
184
+ word-break: break-all;
185
+ &.datatables-noprint {
186
+ justify-content: center;
187
+ }
188
+ }
189
+ [class*='MUIDataTable-responsiveBase'] tr:not([class*='responsiveSimple']) td.MuiTableCell-body > div {
190
+ width: inherit;
191
+ }
192
+ }
193
+ `;
194
+ exports.default = (0, withLocaleProvider_1.default)(Table, {
195
+ translations: {
196
+ en: {
197
+ empty: 'No data',
198
+ },
199
+ zh: {
200
+ empty: '暂无数据',
201
+ },
202
+ },
203
+ });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
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 logger_1 = __importDefault(require("@blocklet/logger"));
7
+ const logger = (0, logger_1.default)('aigne-hub:sdk');
8
+ exports.default = logger;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = withLocaleProvider;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const context_1 = require("@arcblock/ux/lib/Locale/context");
6
+ function withLocaleProvider(C, { translations, fallbackLocale = 'en', }) {
7
+ return ((args) => {
8
+ const { locale } = (0, context_1.useLocaleContext)();
9
+ return ((0, jsx_runtime_1.jsx)(context_1.LocaleProvider, { translations: translations, fallbackLocale: fallbackLocale, locale: locale, onLoadingTranslation: undefined, languages: undefined, children: (0, jsx_runtime_1.jsx)(C, { ...args }) }));
10
+ });
11
+ }
@@ -0,0 +1,54 @@
1
+ import { SubscriptionError } from './error';
2
+ export const createStatusApi = ({ axios, path }) => () => axios.get(path).then((res) => res.data);
3
+ export const createTextCompletionApi = ({ fetch, path, timeout, }) => async (options) => {
4
+ const promise = options.stream
5
+ ? fetch(path, {
6
+ method: 'POST',
7
+ headers: { 'Content-Type': 'application/json' },
8
+ body: JSON.stringify(options),
9
+ }).then(async (res) => {
10
+ var _a, _b, _c;
11
+ if (res.status !== 200) {
12
+ const text = await res.text();
13
+ let json;
14
+ try {
15
+ json = JSON.parse(text);
16
+ }
17
+ catch (_d) {
18
+ // eslint-disable-next-line no-empty
19
+ }
20
+ if ((_a = json === null || json === void 0 ? void 0 : json.error) === null || _a === void 0 ? void 0 : _a.type) {
21
+ throw new SubscriptionError((_b = json === null || json === void 0 ? void 0 : json.error) === null || _b === void 0 ? void 0 : _b.type);
22
+ }
23
+ throw new Error(((_c = json === null || json === void 0 ? void 0 : json.error) === null || _c === void 0 ? void 0 : _c.message) || (json === null || json === void 0 ? void 0 : json.message) || text || res.status);
24
+ }
25
+ return res.body;
26
+ })
27
+ : fetch(path, options)
28
+ .then((res) => res.json())
29
+ .then((data) => { var _a, _b, _c, _d, _e, _f, _g; return ({ text: (_d = (_a = data.text) !== null && _a !== void 0 ? _a : (_c = (_b = data.choices) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : (_g = (_f = (_e = data.choices) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.message) === null || _g === void 0 ? void 0 : _g.content }); })
30
+ .catch(processResponseError);
31
+ if (!timeout) {
32
+ return promise;
33
+ }
34
+ return Promise.race([
35
+ promise,
36
+ new Promise((_, reject) => {
37
+ setTimeout(() => reject(new Error('Timeout')), timeout);
38
+ }),
39
+ ]);
40
+ };
41
+ export const createImageGenerationApi = ({ axios, path, }) => async (options) => {
42
+ return axios
43
+ .post(path, options)
44
+ .then((res) => res.data)
45
+ .catch(processResponseError);
46
+ };
47
+ function processResponseError(error) {
48
+ var _a, _b, _c, _d, _e;
49
+ const msg = ((_c = (_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.message) || ((_e = (_d = error.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.message);
50
+ if (msg) {
51
+ throw new Error(msg);
52
+ }
53
+ throw error;
54
+ }
@@ -0,0 +1,11 @@
1
+ var _a, _b;
2
+ import axios from 'axios';
3
+ export const PREFIX = (typeof window !== 'undefined' &&
4
+ ((_b = (_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.componentMountPoints.find((i) => i.name === 'ai-kit')) === null || _b === void 0 ? void 0 : _b.mountPoint)) ||
5
+ '/';
6
+ export const API_TIMEOUT = 30 * 1000;
7
+ const api = axios.create({
8
+ baseURL: PREFIX,
9
+ timeout: API_TIMEOUT,
10
+ });
11
+ export default api;
@@ -0,0 +1,42 @@
1
+ import api from './api';
2
+ export async function appStatus() {
3
+ return Promise.all([api.get('/api/app/service/status'), appConfig()]).then(([res, config]) => ({
4
+ ...res.data,
5
+ config,
6
+ }));
7
+ }
8
+ export async function appConfig() {
9
+ return api.get('/api/app/config').then((res) => res.data);
10
+ }
11
+ export async function setAppConfig(payload) {
12
+ return api.patch('/api/app/config', payload).then((res) => res.data);
13
+ }
14
+ export async function appServiceRegister() {
15
+ return api.post('/api/app/service/register').then((res) => res.data);
16
+ }
17
+ export async function appUsedCredits(query, options) {
18
+ return api
19
+ .get((options === null || options === void 0 ? void 0 : options.useAIKitService) ? '/api/app/service/usage' : '/api/app/usage', { params: query })
20
+ .then((res) => res.data);
21
+ }
22
+ export async function unsubscribe() {
23
+ return api.post('/api/app/service/unsubscribe');
24
+ }
25
+ export async function getCreditPaymentLink(options) {
26
+ const endpoint = (options === null || options === void 0 ? void 0 : options.useAIKitService) ? '/api/user/service/credit/payment-link' : '/api/user/credit/payment-link';
27
+ return api.get(endpoint).then((res) => res.data);
28
+ }
29
+ // Get credit balance
30
+ export async function getCreditBalance(options) {
31
+ const endpoint = (options === null || options === void 0 ? void 0 : options.useAIKitService) ? '/api/user/service/credit/balance' : '/api/user/credit/balance';
32
+ return api.get(endpoint).then((res) => res.data);
33
+ }
34
+ // Get credit grants
35
+ export async function getCreditGrants(params, options) {
36
+ const endpoint = (options === null || options === void 0 ? void 0 : options.useAIKitService) ? '/api/user/service/credit/grants' : '/api/user/credit/grants';
37
+ return api.get(endpoint, { params }).then((res) => res.data);
38
+ }
39
+ export async function getCreditTransactions(params, options) {
40
+ const endpoint = (options === null || options === void 0 ? void 0 : options.useAIKitService) ? '/api/user/service/credit/transactions' : '/api/user/credit/transactions';
41
+ return api.get(endpoint, { params }).then((res) => res.data);
42
+ }
@@ -0,0 +1,24 @@
1
+ import axios, { isAxiosError } from 'axios';
2
+ import { AI_KIT_BASE_URL } from '../constants';
3
+ import { tryParseJsonFromResponseStream } from '../utils/event-stream';
4
+ export const aiKitApi = axios.create({
5
+ baseURL: AI_KIT_BASE_URL,
6
+ });
7
+ export async function catchAndRethrowUpstreamError(response) {
8
+ return response.catch(async (error) => {
9
+ var _a, _b, _c;
10
+ if (isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data)) {
11
+ const { data } = error.response;
12
+ const json = typeof data[Symbol.iterator] === 'function'
13
+ ? await tryParseJsonFromResponseStream(data)
14
+ : data;
15
+ const message = (_b = json === null || json === void 0 ? void 0 : json.error) === null || _b === void 0 ? void 0 : _b.message;
16
+ if (typeof message === 'string') {
17
+ const error = new Error(message);
18
+ error.type = (_c = json === null || json === void 0 ? void 0 : json.error) === null || _c === void 0 ? void 0 : _c.type;
19
+ throw error;
20
+ }
21
+ }
22
+ throw error;
23
+ });
24
+ }
@@ -0,0 +1,68 @@
1
+ import { call } from '@blocklet/sdk/lib/component';
2
+ import { getRemoteComponentCallHeaders } from '../utils/auth';
3
+ import { aiKitApi, catchAndRethrowUpstreamError } from './api';
4
+ export async function appStatus({ description }, { useAIKitService, ...options } = {}) {
5
+ const response = await catchAndRethrowUpstreamError(useAIKitService
6
+ ? aiKitApi.get('/api/app/status', {
7
+ params: { description },
8
+ responseType: options.responseType,
9
+ headers: { ...getRemoteComponentCallHeaders({}) },
10
+ })
11
+ : call({
12
+ name: 'ai-kit',
13
+ method: 'GET',
14
+ path: '/api/app/status',
15
+ params: { description },
16
+ data: {},
17
+ responseType: options === null || options === void 0 ? void 0 : options.responseType,
18
+ }));
19
+ if ((options === null || options === void 0 ? void 0 : options.responseType) === 'stream')
20
+ return response;
21
+ return response.data;
22
+ }
23
+ export async function appRegister(payload, { useAIKitService, ...options } = {}) {
24
+ const response = await catchAndRethrowUpstreamError(useAIKitService
25
+ ? aiKitApi.post('/api/app/register', payload, { responseType: options.responseType })
26
+ : call({
27
+ name: 'ai-kit',
28
+ method: 'GET',
29
+ path: '/api/app/register',
30
+ data: payload,
31
+ responseType: options === null || options === void 0 ? void 0 : options.responseType,
32
+ }));
33
+ if ((options === null || options === void 0 ? void 0 : options.responseType) === 'stream')
34
+ return response;
35
+ return response.data;
36
+ }
37
+ export async function cancelSubscription({ useAIKitService, ...options } = {}) {
38
+ const response = await catchAndRethrowUpstreamError(useAIKitService
39
+ ? aiKitApi.post('/api/app/subscription/cancel', {}, {
40
+ responseType: options.responseType,
41
+ headers: { ...getRemoteComponentCallHeaders({}) },
42
+ })
43
+ : call({
44
+ name: 'ai-kit',
45
+ path: '/api/app/subscription/cancel',
46
+ data: {},
47
+ responseType: options === null || options === void 0 ? void 0 : options.responseType,
48
+ }));
49
+ if ((options === null || options === void 0 ? void 0 : options.responseType) === 'stream')
50
+ return response;
51
+ return response.data;
52
+ }
53
+ export async function recoverSubscription({ useAIKitService, ...options } = {}) {
54
+ const response = await catchAndRethrowUpstreamError(useAIKitService
55
+ ? aiKitApi.post('/api/app/subscription/recover', {}, {
56
+ responseType: options.responseType,
57
+ headers: { ...getRemoteComponentCallHeaders({}) },
58
+ })
59
+ : call({
60
+ name: 'ai-kit',
61
+ path: '/api/app/subscription/recover',
62
+ data: {},
63
+ responseType: options === null || options === void 0 ? void 0 : options.responseType,
64
+ }));
65
+ if ((options === null || options === void 0 ? void 0 : options.responseType) === 'stream')
66
+ return response;
67
+ return response.data;
68
+ }
@@ -0,0 +1,3 @@
1
+ export * from './v1';
2
+ export * from './v2';
3
+ export * from './proxy';