icbauggw 1.0.3 → 1.0.5
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.
- package/SETUP.md +7 -8
- package/bin/auggw.js +2 -0
- package/bin/icbauggw.js +1 -2
- package/package.json +1 -1
- package/publish.js +63 -0
- package/src/commands/status.js +13 -14
- package/src/commands/switch.js +9 -10
- package/src/index.js +1 -1
- package/src/utils/api.js +1 -1
- package/src/utils/auth.js +2 -3
- package/src/utils/paths.js +4 -5
package/SETUP.md
CHANGED
|
@@ -7,23 +7,23 @@
|
|
|
7
7
|
## Cài đặt
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install -g
|
|
10
|
+
npm install -g auggw
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Đăng nhập
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
|
|
16
|
+
auggw login
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
Nhập username và password được cấp. Token sẽ lưu tại
|
|
19
|
+
Nhập username và password được cấp. Token sẽ lưu tại `~/gg/token`.
|
|
20
20
|
|
|
21
21
|
## Sử dụng
|
|
22
22
|
|
|
23
23
|
### Chuyển session
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
|
|
26
|
+
auggw switch
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
Lệnh này lấy account tiếp theo từ pool và ghi vào `~/.augment/session.json`. Chạy lại mỗi khi cần đổi account.
|
|
@@ -31,7 +31,7 @@ Lệnh này lấy account tiếp theo từ pool và ghi vào `~/.augment/session
|
|
|
31
31
|
### Xem trạng thái
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
|
-
|
|
34
|
+
auggw status
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
Hiển thị account đang dùng, credit usage và số lượng account trong pool.
|
|
@@ -39,9 +39,8 @@ Hiển thị account đang dùng, credit usage và số lượng account trong p
|
|
|
39
39
|
## Lưu ý
|
|
40
40
|
|
|
41
41
|
- Sau khi `switch`, restart lại Augment extension để nó đọc session mới.
|
|
42
|
-
- Nếu gặp lỗi `Session expired`, chạy lại `
|
|
42
|
+
- Nếu gặp lỗi `Session expired`, chạy lại `auggw login`.
|
|
43
43
|
- Nếu cần trỏ sang server khác (dev/test), set env:
|
|
44
44
|
```bash
|
|
45
|
-
|
|
45
|
+
auggw_API_URL=http://localhost:3000 auggw login
|
|
46
46
|
```
|
|
47
|
-
|
package/bin/auggw.js
ADDED
package/bin/icbauggw.js
CHANGED
package/package.json
CHANGED
package/publish.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { execSync } = require('child_process');
|
|
5
|
+
|
|
6
|
+
const CLI_DIR = path.join(__dirname);
|
|
7
|
+
const PKG_PATH = path.join(CLI_DIR, 'package.json');
|
|
8
|
+
const API_PATH = path.join(CLI_DIR, 'src', 'utils', 'api.js');
|
|
9
|
+
|
|
10
|
+
const packages = [
|
|
11
|
+
{
|
|
12
|
+
name: '@itd2902/auggw',
|
|
13
|
+
bin: { auggw: './bin/auggw.js' },
|
|
14
|
+
access: '--access public',
|
|
15
|
+
apiUrl: 'https://auggw.quangit.site',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'icbauggw',
|
|
19
|
+
bin: { icbauggw: './bin/icbauggw.js' },
|
|
20
|
+
access: '',
|
|
21
|
+
apiUrl: 'https://icbauggw.quangit.site',
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const version = process.argv[2];
|
|
26
|
+
if (!version) {
|
|
27
|
+
console.error('Usage: node publish.js <version>');
|
|
28
|
+
console.error('Example: node publish.js 1.0.2');
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const originalPkg = fs.readFileSync(PKG_PATH, 'utf8');
|
|
33
|
+
const originalApi = fs.readFileSync(API_PATH, 'utf8');
|
|
34
|
+
|
|
35
|
+
for (const pkg of packages) {
|
|
36
|
+
const json = JSON.parse(originalPkg);
|
|
37
|
+
json.name = pkg.name;
|
|
38
|
+
json.version = version;
|
|
39
|
+
json.bin = pkg.bin;
|
|
40
|
+
|
|
41
|
+
fs.writeFileSync(PKG_PATH, JSON.stringify(json, null, 2) + '\n');
|
|
42
|
+
|
|
43
|
+
// Swap DEFAULT_API_URL
|
|
44
|
+
const apiContent = originalApi.replace(
|
|
45
|
+
/const DEFAULT_API_URL = ".*?";/,
|
|
46
|
+
`const DEFAULT_API_URL = "${pkg.apiUrl}";`
|
|
47
|
+
);
|
|
48
|
+
fs.writeFileSync(API_PATH, apiContent);
|
|
49
|
+
|
|
50
|
+
console.log(`\nPublishing ${pkg.name}@${version} → ${pkg.apiUrl}`);
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
execSync(`npm publish ${pkg.access}`.trim(), { cwd: CLI_DIR, stdio: 'inherit' });
|
|
54
|
+
console.log(`${pkg.name}@${version} published.`);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
console.error(`Failed to publish ${pkg.name}:`, err.message);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Restore originals
|
|
61
|
+
fs.writeFileSync(PKG_PATH, originalPkg);
|
|
62
|
+
fs.writeFileSync(API_PATH, originalApi);
|
|
63
|
+
console.log('\nFiles restored.');
|
package/src/commands/status.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
const { apiRequest } = require(
|
|
2
|
-
const { requireAuth } = require(
|
|
1
|
+
const { apiRequest } = require("../utils/api");
|
|
2
|
+
const { requireAuth } = require("../utils/auth");
|
|
3
3
|
|
|
4
4
|
async function statusCommand() {
|
|
5
5
|
requireAuth();
|
|
6
6
|
|
|
7
7
|
try {
|
|
8
|
-
const data = await apiRequest(
|
|
8
|
+
const data = await apiRequest("GET", "/api/session/status");
|
|
9
9
|
|
|
10
10
|
if (!data.current) {
|
|
11
|
-
console.log(
|
|
11
|
+
console.log("ℹ️ No active session. Run: auggw switch");
|
|
12
12
|
console.log();
|
|
13
13
|
} else {
|
|
14
|
-
console.log(
|
|
14
|
+
console.log("📋 Current Account");
|
|
15
15
|
console.log(` Name: ${data.current.name}`);
|
|
16
16
|
console.log(` Tenant: ${data.current.tenantURL}`);
|
|
17
17
|
console.log(` Token: ...${data.current.accessToken}`);
|
|
18
|
-
console.log(
|
|
18
|
+
console.log(
|
|
19
|
+
` Status: ${data.current.isLimited ? "🔴 Limited" : "🟢 Active"}`,
|
|
20
|
+
);
|
|
19
21
|
if (data.current.creditTotal) {
|
|
20
22
|
const used = data.current.creditRemaining || 0;
|
|
21
23
|
const total = data.current.creditTotal;
|
|
22
24
|
const pct = Math.round((used / total) * 100);
|
|
23
|
-
console.log(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const c = data.current.currentClient;
|
|
27
|
-
console.log(` Client: ${c.hostname || '—'} (${c.ip || '—'})`);
|
|
25
|
+
console.log(
|
|
26
|
+
` Credit: ${used.toLocaleString()} / ${total.toLocaleString()} (${pct}%)`,
|
|
27
|
+
);
|
|
28
28
|
}
|
|
29
29
|
console.log();
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
console.log(
|
|
32
|
+
console.log("📊 Pool Status");
|
|
33
33
|
console.log(` Active: ${data.pool.active} accounts`);
|
|
34
34
|
console.log(` Limited: ${data.pool.limited} accounts`);
|
|
35
35
|
console.log(` Total: ${data.pool.total} accounts`);
|
|
36
36
|
} catch (err) {
|
|
37
37
|
if (err.status === 401) {
|
|
38
|
-
console.error(
|
|
38
|
+
console.error("❌ Session expired. Please login again: auggw login");
|
|
39
39
|
} else {
|
|
40
40
|
console.error(`❌ Error: ${err.message}`);
|
|
41
41
|
}
|
|
@@ -44,4 +44,3 @@ async function statusCommand() {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
module.exports = statusCommand;
|
|
47
|
-
|
package/src/commands/switch.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
const fs = require(
|
|
2
|
-
const path = require(
|
|
3
|
-
const { apiRequest } = require(
|
|
4
|
-
const { requireAuth } = require(
|
|
5
|
-
const { getSessionPath } = require(
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const { apiRequest } = require("../utils/api");
|
|
4
|
+
const { requireAuth } = require("../utils/auth");
|
|
5
|
+
const { getSessionPath } = require("../utils/paths");
|
|
6
6
|
|
|
7
7
|
async function switchCommand() {
|
|
8
8
|
requireAuth();
|
|
9
9
|
|
|
10
10
|
try {
|
|
11
|
-
const data = await apiRequest(
|
|
11
|
+
const data = await apiRequest("GET", "/api/session/next");
|
|
12
12
|
|
|
13
13
|
const sessionPath = getSessionPath();
|
|
14
14
|
const sessionDir = path.dirname(sessionPath);
|
|
@@ -24,14 +24,14 @@ async function switchCommand() {
|
|
|
24
24
|
tenantURL: data.tenantURL,
|
|
25
25
|
scopes: data.scopes,
|
|
26
26
|
};
|
|
27
|
-
fs.writeFileSync(sessionPath, JSON.stringify(session, null, 2),
|
|
27
|
+
fs.writeFileSync(sessionPath, JSON.stringify(session, null, 2), "utf8");
|
|
28
28
|
|
|
29
|
-
console.log(
|
|
29
|
+
console.log("✅ Session switched!");
|
|
30
30
|
console.log(` Account: ${data.accountName}`);
|
|
31
31
|
console.log(` Tenant: ${data.tenantURL}`);
|
|
32
32
|
} catch (err) {
|
|
33
33
|
if (err.status === 401) {
|
|
34
|
-
console.error(
|
|
34
|
+
console.error("❌ Session expired. Please login again: auggw login");
|
|
35
35
|
} else if (err.status === 503) {
|
|
36
36
|
console.error(`❌ ${err.message}`);
|
|
37
37
|
} else {
|
|
@@ -42,4 +42,3 @@ async function switchCommand() {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
module.exports = switchCommand;
|
|
45
|
-
|
package/src/index.js
CHANGED
package/src/utils/api.js
CHANGED
|
@@ -5,7 +5,7 @@ const DEFAULT_API_URL = "https://icbauggw.quangit.site";
|
|
|
5
5
|
// const DEFAULT_API_URL = "http://localhost:3000";
|
|
6
6
|
|
|
7
7
|
function getBaseURL() {
|
|
8
|
-
return process.env.
|
|
8
|
+
return process.env.auggw_API_URL || DEFAULT_API_URL;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
function getLocalIP() {
|
package/src/utils/auth.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
const { loadToken } = require(
|
|
1
|
+
const { loadToken } = require("./token");
|
|
2
2
|
|
|
3
3
|
function requireAuth() {
|
|
4
4
|
const token = loadToken();
|
|
5
5
|
if (!token) {
|
|
6
|
-
console.error(
|
|
6
|
+
console.error("❌ Please login first: auggw login");
|
|
7
7
|
process.exit(1);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
module.exports = { requireAuth };
|
|
12
|
-
|
package/src/utils/paths.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
const os = require(
|
|
2
|
-
const path = require(
|
|
1
|
+
const os = require("os");
|
|
2
|
+
const path = require("path");
|
|
3
3
|
|
|
4
4
|
function getTokenPath() {
|
|
5
|
-
return path.join(os.homedir(),
|
|
5
|
+
return path.join(os.homedir(), ".auggw", "token");
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
function getSessionPath() {
|
|
9
|
-
return path.join(os.homedir(),
|
|
9
|
+
return path.join(os.homedir(), ".augment", "session.json");
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
module.exports = { getTokenPath, getSessionPath };
|
|
13
|
-
|