Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Production build (`pnpm run build`) runs these steps sequentially:
- Use `make clean` before building if encountering issues
- Electron app requires special build process with `make dep`
- React components use Relay; ensure GraphQL schema in `/data/` is up to date
- Backend.AI client library (`src/lib/backend.ai-client-esm.ts`) is aliased in Craco config
- Backend.AI client library is a workspace package at `packages/backend.ai-client/` (built with tsup)

## Core Guidelines

Expand Down
5 changes: 5 additions & 0 deletions backend.ai-webui.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"path": "packages/backend.ai-ui",
"name": "backend.ai-ui",
},
{
"path": "packages/backend.ai-client",
"name": "backend.ai-client",
},
{
"path": "packages/eslint-config-bai",
"name": "eslint-config-bai",
Expand Down Expand Up @@ -38,6 +42,7 @@
"i18n-ally.translate.openai.apiModel": "gpt-5-mini",
"files.exclude": {
"packages/backend.ai-ui": true,
"packages/backend.ai-client": true,
"packages/eslint-config-bai": true,
"packages/backend.ai-webui-docs": true,
},
Expand Down
12 changes: 12 additions & 0 deletions packages/backend.ai-client/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"importOrderSeparation": true,
"importOrderParserPlugins": ["typescript", "jsx"],
"printWidth": 80,
"bracketSpacing": true,
"trailingComma": "all",
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"singleAttributePerLine": false
}
51 changes: 51 additions & 0 deletions packages/backend.ai-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "backend.ai-client",
"version": "26.4.0-alpha.0",
"description": "Backend.AI API client library for JavaScript/TypeScript",
"repository": {
"type": "git",
"url": "https://github.com/lablup/backend.ai-webui/tree/main/packages/backend.ai-client"
},
"bugs": {
"url": "https://github.com/lablup/backend.ai-webui/issues"
},
"author": "Lablup Inc. <contact@lablup.com>",
"license": "LGPL-3.0-or-later",
"keywords": [
"backend.ai",
"client",
"sdk",
"api"
],
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"sideEffects": false,
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
}
},
"files": [
"dist"
],
"scripts": {
"dev": "tsup --watch",
"build": "tsup",
"test": "vitest run",
"vitest": "vitest run",
"vitest:watch": "vitest",
"lint": "eslint ./src --max-warnings=0",
"prepublishOnly": "pnpm lint && pnpm test && pnpm build"
Comment thread
yomybaby marked this conversation as resolved.
},
"dependencies": {
"crypto-es": "^2.1.0"
},
"devDependencies": {
"tsup": "^8.5.0",
"typescript": "^5.9.3",
"vitest": "^4.1.4"
},
"type": "module"
}
140 changes: 140 additions & 0 deletions packages/backend.ai-client/src/client-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// @ts-nocheck
class ClientConfig {
public _apiVersionMajor: string;
public _apiVersion: string;
public _hashType: string;
public _endpoint: string;
public _endpointHost: string;
public _accessKey: string;
public _secretKey: string;
public _userId: string;
public _password: string;
public _proxyURL: any;
public _proxyToken: any;
public _connectionMode: string;

/**
* The client Configuration object.
*
* @param {string} accessKey - access key to connect Backend.AI manager
* @param {string} secretKey - secret key to connect Backend.AI manager
* @param {string} endpoint - endpoint of Backend.AI manager
* @param {string} connectionMode - connection mode. 'API', 'SESSION' is supported. `SESSION` mode requires webserver.
*/
constructor(
accessKey?: string,
secretKey?: string,
endpoint?: string,
connectionMode: string = 'API',
) {
// default configs.
this._apiVersionMajor = '8';
this._apiVersion = 'v8.20240915'; // For compatibility with 24.09.
this._hashType = 'sha256';
if (endpoint === undefined || endpoint === null) {
endpoint = 'https://api.backend.ai';
}
endpoint = endpoint.replace(/\/+$/, '');
Comment thread
yomybaby marked this conversation as resolved.
this._endpoint = endpoint;
this._endpointHost = endpoint.replace(/^[^:]+:\/\//, '');
if (connectionMode === 'API') {
// API mode
// dynamic configs
if (accessKey === undefined || accessKey === null) {
throw new Error(
'You must set accessKey! (either as argument or environment variable)',
);
}
if (secretKey === undefined || secretKey === null) {
throw new Error(
'You must set secretKey! (either as argument or environment variable)',
);
}
this._accessKey = accessKey;
this._secretKey = secretKey;
this._userId = '';
this._password = '';
} else {
// Session mode
// dynamic configs
if (accessKey === undefined || accessKey === null) {
throw new Error(
'You must set user id! (either as argument or environment variable)',
);
}
if (secretKey === undefined || secretKey === null) {
throw new Error(
'You must set password! (either as argument or environment variable)',
);
}
this._accessKey = '';
this._secretKey = '';
this._userId = accessKey;
this._password = secretKey;
}
this._proxyURL = null;
this._proxyToken = null;
this._connectionMode = connectionMode;
}

get accessKey() {
return this._accessKey;
}

get secretKey() {
return this._secretKey;
}

get userId() {
return this._userId;
}

get password() {
return this._password;
}

get endpoint() {
return this._endpoint;
}

get proxyURL() {
return this._proxyURL;
}

get proxyToken() {
return this._proxyToken;
}

get endpointHost() {
return this._endpointHost;
}

get apiVersion() {
return this._apiVersion;
}

get apiVersionMajor() {
return this._apiVersionMajor;
}

get hashType() {
return this._hashType;
}

get connectionMode() {
return this._connectionMode;
}

/**
* Create a ClientConfig object from environment variables.
*/
static createFromEnv() {
return new this(
process.env.BACKEND_ACCESS_KEY,
process.env.BACKEND_SECRET_KEY,
process.env.BACKEND_ENDPOINT,
);
}
}

export { ClientConfig };
Loading
Loading