@blocklet/aigne-hub 0.7.11 → 0.7.13

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.
@@ -8,6 +8,7 @@ exports.chatCompletionsV2 = chatCompletionsV2;
8
8
  exports.imageGenerationsV2 = imageGenerationsV2;
9
9
  exports.embeddingsV2 = embeddingsV2;
10
10
  exports.getUserCreditInfo = getUserCreditInfo;
11
+ exports.checkStatus = checkStatus;
11
12
  const web_1 = require("stream/web");
12
13
  const axios_1 = __importDefault(require("axios"));
13
14
  const ufo_1 = require("ufo");
@@ -131,3 +132,7 @@ async function getUserCreditInfo() {
131
132
  const response = await callRemoteApi({}, { endpoint: 'api/user/info', method: 'GET' });
132
133
  return response.data;
133
134
  }
135
+ async function checkStatus({ model } = {}) {
136
+ const response = await callRemoteApi(model ? { model } : {}, { endpoint: 'api/v2/status', method: 'GET' });
137
+ return response.data;
138
+ }
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getUserInfo = getUserInfo;
7
+ exports.checkConnection = checkConnection;
7
8
  const error_1 = require("@blocklet/error");
8
9
  const axios_1 = __importDefault(require("axios"));
9
10
  const ufo_1 = require("ufo");
@@ -34,3 +35,29 @@ async function getUserInfo({ baseUrl = '', accessKey = '', }) {
34
35
  })
35
36
  .then((res) => res.data);
36
37
  }
38
+ async function checkConnection({ baseUrl, accessKey, model, }) {
39
+ let finalBaseUrl = (0, util_1.getPrefix)();
40
+ const windowExist = typeof window !== 'undefined';
41
+ try {
42
+ if (baseUrl) {
43
+ const tmp = new URL(baseUrl);
44
+ if (!windowExist || (windowExist && tmp.origin !== window.location.origin)) {
45
+ finalBaseUrl = await (0, util_1.getRemoteBaseUrl)(baseUrl);
46
+ }
47
+ }
48
+ }
49
+ catch (err) {
50
+ console.warn('Failed to parse baseUrl:', err);
51
+ throw new Error(`Failed to parse baseUrl: ${(0, error_1.formatError)(err)}`);
52
+ }
53
+ if (!finalBaseUrl || !accessKey) {
54
+ throw new Error('baseUrl or accessKey is not set');
55
+ }
56
+ const response = await axios_1.default.get((0, ufo_1.joinURL)(finalBaseUrl, '/api/v2/status'), {
57
+ params: model ? { model } : {},
58
+ headers: {
59
+ Authorization: `Bearer ${accessKey}`,
60
+ },
61
+ });
62
+ return response.data;
63
+ }
@@ -121,3 +121,7 @@ export async function getUserCreditInfo() {
121
121
  const response = await callRemoteApi({}, { endpoint: 'api/user/info', method: 'GET' });
122
122
  return response.data;
123
123
  }
124
+ export async function checkStatus({ model } = {}) {
125
+ const response = await callRemoteApi(model ? { model } : {}, { endpoint: 'api/v2/status', method: 'GET' });
126
+ return response.data;
127
+ }
@@ -28,3 +28,29 @@ export async function getUserInfo({ baseUrl = '', accessKey = '', }) {
28
28
  })
29
29
  .then((res) => res.data);
30
30
  }
31
+ export async function checkConnection({ baseUrl, accessKey, model, }) {
32
+ let finalBaseUrl = getPrefix();
33
+ const windowExist = typeof window !== 'undefined';
34
+ try {
35
+ if (baseUrl) {
36
+ const tmp = new URL(baseUrl);
37
+ if (!windowExist || (windowExist && tmp.origin !== window.location.origin)) {
38
+ finalBaseUrl = await getRemoteBaseUrl(baseUrl);
39
+ }
40
+ }
41
+ }
42
+ catch (err) {
43
+ console.warn('Failed to parse baseUrl:', err);
44
+ throw new Error(`Failed to parse baseUrl: ${formatError(err)}`);
45
+ }
46
+ if (!finalBaseUrl || !accessKey) {
47
+ throw new Error('baseUrl or accessKey is not set');
48
+ }
49
+ const response = await axios.get(joinURL(finalBaseUrl, '/api/v2/status'), {
50
+ params: model ? { model } : {},
51
+ headers: {
52
+ Authorization: `Bearer ${accessKey}`,
53
+ },
54
+ });
55
+ return response.data;
56
+ }
@@ -2,6 +2,7 @@ import type { IncomingMessage } from 'http';
2
2
  import { ReadableStream } from 'stream/web';
3
3
  import { AxiosResponse } from 'axios';
4
4
  import { ChatCompletionError, ChatCompletionInput, ChatCompletionResponse, EmbeddingInput, EmbeddingResponse, ImageGenerationInput, ImageGenerationResponse } from '../types';
5
+ import { StatusResponse } from '../types/status';
5
6
  import { UserInfoResult } from '../types/user';
6
7
  interface RemoteApiOptions {
7
8
  responseType?: 'stream';
@@ -39,4 +40,7 @@ export declare function embeddingsV2(input: EmbeddingInput, options: {
39
40
  timeout?: number;
40
41
  }): Promise<AxiosResponse<IncomingMessage, any>>;
41
42
  export declare function getUserCreditInfo(): Promise<UserInfoResult>;
43
+ export declare function checkStatus({ model }?: {
44
+ model?: string;
45
+ }): Promise<StatusResponse>;
42
46
  export {};
@@ -1,3 +1,4 @@
1
1
  export interface StatusResponse {
2
2
  available: boolean;
3
+ error?: string;
3
4
  }
@@ -1,5 +1,11 @@
1
+ import { StatusResponse } from './types/status';
1
2
  import { UserInfoResult } from './types/user';
2
3
  export declare function getUserInfo({ baseUrl, accessKey, }: {
3
4
  baseUrl: string;
4
5
  accessKey: string;
5
6
  }): Promise<UserInfoResult>;
7
+ export declare function checkConnection({ baseUrl, accessKey, model, }: {
8
+ baseUrl: string;
9
+ accessKey: string;
10
+ model?: string;
11
+ }): Promise<StatusResponse>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/aigne-hub",
3
- "version": "0.7.11",
3
+ "version": "0.7.13",
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.16",
104
- "@arcblock/ux": "^3.2.19",
103
+ "@arcblock/did": "^1.28.0",
104
+ "@arcblock/ux": "^3.3.10",
105
105
  "@blocklet/error": "0.3.5",
106
- "@blocklet/logger": "^1.17.6",
106
+ "@blocklet/logger": "^1.17.7",
107
107
  "@blocklet/payment-js": "^1.23.7",
108
- "@blocklet/sdk": "^1.17.6",
108
+ "@blocklet/sdk": "^1.17.7",
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.16",
117
- "@ocap/util": "^1.27.16",
116
+ "@ocap/mcrypto": "^1.28.0",
117
+ "@ocap/util": "^1.28.0",
118
118
  "@types/express": "^5.0.3",
119
119
  "ahooks": "^3.8.1",
120
120
  "axios": "^1.7.4",