From b1cd867fa3cc24ec84d3cabb79665a50e50abc57 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Tue, 28 Nov 2023 13:24:06 +0900 Subject: [PATCH 01/10] fix: remove root path rule --- src/constants.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 9921d87..a91ba69 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -31,14 +31,6 @@ export const Path = { export const defaultAppRules = (appName: string): { [type: string]: { ref: string, value: object } } => { const rootRef = Path.app(appName).root(); return { - root: { - ref: rootRef, - value: { - ".rule": { - write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true" - }, - }, - }, deposit: { ref: `${Path.app(appName).depositOfUser("$userAddress")}/$transferKey`, value: { @@ -56,7 +48,7 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin }, }, balanceHistory: { - ref: `${rootRef}/balance/$userAddress/history/$timestamp_and_type`, + ref: `${rootRef}/balance/$userAddress/history/$timestamp`, value: { ".rule": { write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && util.isDict(newData) && util.isNumber(newData.amount) && (newData.type === 'DEPOSIT' || newData.type === 'USAGE')" From 8d902a2e3f6a014bb8f8086a0b1f8a3a802e78ab Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Tue, 28 Nov 2023 13:32:32 +0900 Subject: [PATCH 02/10] fix: request without charge when minCost is 0 --- src/constants.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/constants.ts b/src/constants.ts index a91ba69..2c22618 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -60,7 +60,8 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin value: { ".rule": { write: - "auth.addr === $userAddress && getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) !== null && " + + "auth.addr === $userAddress && " + + "(getValue(`/apps/" + `${appName}` + "/billingConfig/minCost`) === 0 || " + "(getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) >= getValue(`/apps/" + `${appName}` + "/billingConfig/minCost`))" }, }, From 309bf00ecb540ff71315cb91e80ae77ac8efbb5a Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Tue, 28 Nov 2023 13:33:47 +0900 Subject: [PATCH 03/10] fix: limit minCost to positive numbers --- src/constants.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 2c22618..1f9c9ca 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -78,9 +78,12 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin ref: Path.app(appName).billingConfig(), value: { ".rule": { - write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && util.isDict(newData) && util.isString(newData.depositAddress) && " + - "util.isDict(newData) && util.isNumber(newData.costPerToken) && util.isNumber(newData.minCost) && " + - "util.isEmpty(newData.maxCost) || (util.isNumber(newData.maxCost) && newData.maxCost >= newData.minCost)", + write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && " + + "util.isDict(newData) && " + + "util.isString(newData.depositAddress) && " + + "util.isNumber(newData.costPerToken) && " + + "util.isNumber(newData.minCost) && newData.minCost >= 0" + + "(util.isEmpty(newData.maxCost) || (util.isNumber(newData.maxCost) && newData.maxCost >= newData.minCost))", }, }, }, From d874493fe5cbd2d6bb010f93277be6fbac3cfa88 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Tue, 28 Nov 2023 13:34:29 +0900 Subject: [PATCH 04/10] docs: readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d7d0a8..8348bf1 100644 --- a/README.md +++ b/README.md @@ -62,5 +62,5 @@ const balance = await service.getCreditBalance(); If you have enough credit, you can use the service. ```typescript -const result = await service.use(); +const result = await service.request(); ``` From b5d7c601e953d563ff52c19376dd5ad15771722d Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 6 Dec 2023 12:20:40 +0900 Subject: [PATCH 05/10] fix: get requestData to any --- src/controllers/serviceController.ts | 2 +- src/service.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/serviceController.ts b/src/controllers/serviceController.ts index 64c580b..fc735ab 100644 --- a/src/controllers/serviceController.ts +++ b/src/controllers/serviceController.ts @@ -71,7 +71,7 @@ export default class ServiceController { return await this.ain.getValue(creditHistoryPath) as creditHistories; } - async request(serviceName: string, requestData: string) : Promise { + async request(serviceName: string, requestData: any) : Promise { this.isRunning(serviceName); const result = await new Promise(async (resolve, reject) => { const requestKey = Date.now(); diff --git a/src/service.ts b/src/service.ts index 6caae0b..216fae7 100644 --- a/src/service.ts +++ b/src/service.ts @@ -76,7 +76,7 @@ export default class Service { * @param {string} requestData String data for request to service. * @returns {string} Response data from service. */ - async request(requestData: string) { + async request(requestData: any) { this.isLoggedIn(); return await this.serviceController.request(this.serviceName, requestData); } From e798c29c4e5d1b78762623f0b9178ec78b2ab1bf Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 6 Dec 2023 12:21:44 +0900 Subject: [PATCH 06/10] fix: deprecated calculate cost --- src/controllers/serviceController.ts | 3 ++- src/service.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/controllers/serviceController.ts b/src/controllers/serviceController.ts index fc735ab..1c97646 100644 --- a/src/controllers/serviceController.ts +++ b/src/controllers/serviceController.ts @@ -29,7 +29,8 @@ export default class ServiceController { return await 'information of service'; } - async calculateCost(serviceName: string, requestData: string): Promise { + // FIXME(yoojin): Temporary deprecated. Need new pricing rules. + private async calculateCost(serviceName: string, requestData: string): Promise { const billingConfig = await this.ain.getValue(Path.app(serviceName).billingConfig()); const token = requestData.split(' ').length; let cost = token * billingConfig.costPerToken; diff --git a/src/service.ts b/src/service.ts index 216fae7..1c86ecf 100644 --- a/src/service.ts +++ b/src/service.ts @@ -30,7 +30,9 @@ export default class Service { * @returns {number} Estimated cost. */ async calculateCost (requestData: string) { - return await this.serviceController.calculateCost(this.serviceName, requestData); + // FIXME(yoojin): Temporary deprecated. Need new pricing rules. + // return await this.serviceController.calculateCost(this.serviceName, requestData); + return 0; } /** From 0117f234af1cbe02175643846346feb26c404cd1 Mon Sep 17 00:00:00 2001 From: akaster99 Date: Mon, 11 Dec 2023 16:45:58 +0900 Subject: [PATCH 07/10] modified: package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 124a460..5c95387 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@ainize-team/ainize-sdk", + "name": "@ainize-team/ainize-js", "version": "1.0.3", "main": "dist/ainize.js", "types": "dist/ainize.d.ts", @@ -14,7 +14,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/ainize-team/ainize-sdk.git" + "url": "git+https://github.com/ainize-team/ainize-js.git" }, "keywords": [ "ainize", From a9a7bb12466e5a848c31e5e57ef6befd588d20f1 Mon Sep 17 00:00:00 2001 From: akaster99 Date: Mon, 11 Dec 2023 16:52:42 +0900 Subject: [PATCH 08/10] update readme --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8348bf1..8373db3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# ainize-sdk +# ainize-js -A Typescript SDK for the Ainize, a system for running AI services on the AI Network. +A Typescript JS for the Ainize, a system for running AI services on the AI Network. ## Requirements node >= 16 @@ -8,14 +8,14 @@ node >= 16 ## usage ### Install ```bash -npm install @ainize-team/ainize-sdk +npm install @ainize-team/ainize-js -yarn install @ainize-team/ainize-sdk +yarn install @ainize-team/ainize-js ``` ### Import ```typescript -import Ainize from '@ainize-team/ainize-sdk' +import Ainize from '@ainize-team/ainize-js' const ainize = new Ainize(); ``` @@ -49,9 +49,9 @@ service.run(); ``` ### Using Service -You can use a service using `ainize.service()`. +You can use a service using `ainize.getService()`. ```typescript -const service = await ainize.service(); +const service = await ainize.getService(); ``` You should deposit AIN to credit before using service. From d197480be5170efb18a24c466ca9dd342bc3ead1 Mon Sep 17 00:00:00 2001 From: akastercomcom Date: Mon, 11 Dec 2023 08:34:08 +0000 Subject: [PATCH 09/10] Upgrade version to 1.0.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5c95387..bb1727b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ainize-team/ainize-js", - "version": "1.0.3", + "version": "1.0.4", "main": "dist/ainize.js", "types": "dist/ainize.d.ts", "scripts": { From d62ae5865bffc654604d40aeafb930371e9f703e Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Mon, 11 Dec 2023 17:54:55 +0900 Subject: [PATCH 10/10] fix: write rule typo --- src/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants.ts b/src/constants.ts index 1f9c9ca..7552df4 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -82,7 +82,7 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin "util.isDict(newData) && " + "util.isString(newData.depositAddress) && " + "util.isNumber(newData.costPerToken) && " + - "util.isNumber(newData.minCost) && newData.minCost >= 0" + + "util.isNumber(newData.minCost) && newData.minCost >= 0 &&" + "(util.isEmpty(newData.maxCost) || (util.isNumber(newData.maxCost) && newData.maxCost >= newData.minCost))", }, },