@blocklet/aigne-hub 0.6.18 → 0.6.20

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.
@@ -5,13 +5,25 @@ const error_1 = require("./error");
5
5
  const createStatusApi = ({ axios, path }) => () => axios.get(path).then((res) => res.data);
6
6
  exports.createStatusApi = createStatusApi;
7
7
  const createTextCompletionApi = ({ fetch, path, timeout, headers = {}, }) => async (options) => {
8
- const promise = options.stream
9
- ? fetch(path, {
10
- method: 'POST',
11
- headers: { 'Content-Type': 'application/json', ...headers },
12
- body: JSON.stringify(options),
13
- }).then(async (res) => {
14
- var _a, _b, _c;
8
+ var _a, _b, _c;
9
+ if (options.stream) {
10
+ const abortController = timeout ? new AbortController() : undefined;
11
+ let timeoutId;
12
+ if (timeout && abortController) {
13
+ timeoutId = setTimeout(() => {
14
+ abortController.abort();
15
+ }, timeout);
16
+ }
17
+ try {
18
+ const res = await fetch(path, {
19
+ method: 'POST',
20
+ headers: { 'Content-Type': 'application/json', ...headers },
21
+ body: JSON.stringify(options),
22
+ signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
23
+ });
24
+ if (timeoutId) {
25
+ clearTimeout(timeoutId);
26
+ }
15
27
  if (res.status !== 200) {
16
28
  const text = await res.text();
17
29
  let json;
@@ -27,15 +39,25 @@ const createTextCompletionApi = ({ fetch, path, timeout, headers = {}, }) => asy
27
39
  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);
28
40
  }
29
41
  return res.body;
30
- })
31
- : fetch(path, {
32
- method: 'POST',
33
- headers: { 'Content-Type': 'application/json', ...headers },
34
- body: JSON.stringify(options),
35
- })
36
- .then((res) => res.json())
37
- .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 }); })
38
- .catch(processResponseError);
42
+ }
43
+ catch (error) {
44
+ if (timeoutId) {
45
+ clearTimeout(timeoutId);
46
+ }
47
+ if (error.name === 'AbortError') {
48
+ throw new Error('Connection timeout');
49
+ }
50
+ throw error;
51
+ }
52
+ }
53
+ const promise = fetch(path, {
54
+ method: 'POST',
55
+ headers: { 'Content-Type': 'application/json', ...headers },
56
+ body: JSON.stringify(options),
57
+ })
58
+ .then((res) => res.json())
59
+ .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 }); })
60
+ .catch(processResponseError);
39
61
  if (!timeout) {
40
62
  return promise;
41
63
  }
@@ -4,12 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  var _a, _b;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.API_TIMEOUT = exports.PREFIX = void 0;
7
+ exports.STREAM_API_TIMEOUT = exports.API_TIMEOUT = exports.PREFIX = void 0;
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  exports.PREFIX = (typeof window !== 'undefined' &&
10
10
  ((_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)) ||
11
11
  '/';
12
12
  exports.API_TIMEOUT = 30 * 1000;
13
+ exports.STREAM_API_TIMEOUT = 10 * 60 * 1000;
13
14
  const api = axios_1.default.create({
14
15
  baseURL: exports.PREFIX,
15
16
  timeout: exports.API_TIMEOUT,
@@ -51,7 +51,7 @@ var CreditErrorType;
51
51
  CreditErrorType["UNKNOWN"] = "UNKNOWN";
52
52
  })(CreditErrorType || (exports.CreditErrorType = CreditErrorType = {}));
53
53
  const CreditErrors = {
54
- [CreditErrorType.NOT_ENOUGH]: 'Hello, in order to continue chatting, please first buy some credits in the link below.',
54
+ [CreditErrorType.NOT_ENOUGH]: 'Hello, in order to continue using AI services, please first buy some credits in the link below.',
55
55
  [CreditErrorType.UNKNOWN]: 'An unknown error occurred',
56
56
  };
57
57
  class CreditError extends Error {
@@ -1,13 +1,25 @@
1
1
  import { SubscriptionError } from './error';
2
2
  export const createStatusApi = ({ axios, path }) => () => axios.get(path).then((res) => res.data);
3
3
  export const createTextCompletionApi = ({ fetch, path, timeout, headers = {}, }) => async (options) => {
4
- const promise = options.stream
5
- ? fetch(path, {
6
- method: 'POST',
7
- headers: { 'Content-Type': 'application/json', ...headers },
8
- body: JSON.stringify(options),
9
- }).then(async (res) => {
10
- var _a, _b, _c;
4
+ var _a, _b, _c;
5
+ if (options.stream) {
6
+ const abortController = timeout ? new AbortController() : undefined;
7
+ let timeoutId;
8
+ if (timeout && abortController) {
9
+ timeoutId = setTimeout(() => {
10
+ abortController.abort();
11
+ }, timeout);
12
+ }
13
+ try {
14
+ const res = await fetch(path, {
15
+ method: 'POST',
16
+ headers: { 'Content-Type': 'application/json', ...headers },
17
+ body: JSON.stringify(options),
18
+ signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
19
+ });
20
+ if (timeoutId) {
21
+ clearTimeout(timeoutId);
22
+ }
11
23
  if (res.status !== 200) {
12
24
  const text = await res.text();
13
25
  let json;
@@ -23,15 +35,25 @@ export const createTextCompletionApi = ({ fetch, path, timeout, headers = {}, })
23
35
  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
36
  }
25
37
  return res.body;
26
- })
27
- : fetch(path, {
28
- method: 'POST',
29
- headers: { 'Content-Type': 'application/json', ...headers },
30
- body: JSON.stringify(options),
31
- })
32
- .then((res) => res.json())
33
- .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 }); })
34
- .catch(processResponseError);
38
+ }
39
+ catch (error) {
40
+ if (timeoutId) {
41
+ clearTimeout(timeoutId);
42
+ }
43
+ if (error.name === 'AbortError') {
44
+ throw new Error('Connection timeout');
45
+ }
46
+ throw error;
47
+ }
48
+ }
49
+ const promise = fetch(path, {
50
+ method: 'POST',
51
+ headers: { 'Content-Type': 'application/json', ...headers },
52
+ body: JSON.stringify(options),
53
+ })
54
+ .then((res) => res.json())
55
+ .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 }); })
56
+ .catch(processResponseError);
35
57
  if (!timeout) {
36
58
  return promise;
37
59
  }
@@ -4,6 +4,7 @@ export const PREFIX = (typeof window !== 'undefined' &&
4
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
5
  '/';
6
6
  export const API_TIMEOUT = 30 * 1000;
7
+ export const STREAM_API_TIMEOUT = 10 * 60 * 1000;
7
8
  const api = axios.create({
8
9
  baseURL: PREFIX,
9
10
  timeout: API_TIMEOUT,
@@ -46,7 +46,7 @@ export var CreditErrorType;
46
46
  CreditErrorType["UNKNOWN"] = "UNKNOWN";
47
47
  })(CreditErrorType || (CreditErrorType = {}));
48
48
  const CreditErrors = {
49
- [CreditErrorType.NOT_ENOUGH]: 'Hello, in order to continue chatting, please first buy some credits in the link below.',
49
+ [CreditErrorType.NOT_ENOUGH]: 'Hello, in order to continue using AI services, please first buy some credits in the link below.',
50
50
  [CreditErrorType.UNKNOWN]: 'An unknown error occurred',
51
51
  };
52
52
  export class CreditError extends Error {
@@ -1,4 +1,5 @@
1
1
  export declare const PREFIX: string;
2
2
  export declare const API_TIMEOUT: number;
3
+ export declare const STREAM_API_TIMEOUT: number;
3
4
  declare const api: import("axios").AxiosInstance;
4
5
  export default api;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/aigne-hub",
3
- "version": "0.6.18",
3
+ "version": "0.6.20",
4
4
  "description": "The react.js component library for AIGNE Hub",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -100,12 +100,12 @@
100
100
  "react": "^18.2.0"
101
101
  },
102
102
  "dependencies": {
103
- "@arcblock/did": "^1.27.10",
104
- "@arcblock/ux": "^3.2.6",
103
+ "@arcblock/did": "^1.27.12",
104
+ "@arcblock/ux": "^3.2.11",
105
105
  "@blocklet/error": "0.3.2",
106
- "@blocklet/logger": "1.17.3-beta-20251118-061144-335cd35d",
107
- "@blocklet/payment-js": "^1.22.15",
108
- "@blocklet/sdk": "1.17.3-beta-20251118-061144-335cd35d",
106
+ "@blocklet/logger": "^1.17.3",
107
+ "@blocklet/payment-js": "^1.22.25",
108
+ "@blocklet/sdk": "^1.17.3",
109
109
  "@emotion/css": "^11.13.5",
110
110
  "@emotion/react": "^11.14.0",
111
111
  "@emotion/styled": "^11.14.1",
@@ -113,8 +113,8 @@
113
113
  "@mui/lab": "^7.0.0-beta.14",
114
114
  "@mui/material": "^7.2.0",
115
115
  "@mui/system": "^7.2.0",
116
- "@ocap/mcrypto": "^1.27.10",
117
- "@ocap/util": "^1.27.10",
116
+ "@ocap/mcrypto": "^1.27.12",
117
+ "@ocap/util": "^1.27.12",
118
118
  "@types/express": "^5.0.3",
119
119
  "ahooks": "^3.8.1",
120
120
  "axios": "^1.7.4",