@agentscope-ai/platform-cli 1.0.3 → 1.0.4
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/README.md +88 -28
- package/dist/{chunk-IWWTP4LN.js → chunk-IHANUO75.js} +22 -10
- package/dist/chunk-IHANUO75.js.map +1 -0
- package/dist/{chunk-4I5YYR2G.js → chunk-OKVCMNGY.js} +22 -12
- package/dist/chunk-OKVCMNGY.js.map +1 -0
- package/dist/cli.js +111 -81
- package/dist/cli.js.map +1 -1
- package/dist/{credentials-LIUOYT7K.js → credentials-J4V4LBC5.js} +2 -2
- package/dist/{credentials-TT7CW3HF.js → credentials-KIOZKCTT.js} +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-4I5YYR2G.js.map +0 -1
- package/dist/chunk-IWWTP4LN.js.map +0 -1
- /package/dist/{credentials-LIUOYT7K.js.map → credentials-J4V4LBC5.js.map} +0 -0
- /package/dist/{credentials-TT7CW3HF.js.map → credentials-KIOZKCTT.js.map} +0 -0
package/README.md
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
AgentScope Platform 命令行工具。默认对接生产环境:`https://platform.agentscope.io`。
|
|
4
4
|
|
|
5
|
-
| 环境 | Platform URL |
|
|
6
|
-
| --- | --- |
|
|
7
|
-
| **prod**(默认) | https://platform.agentscope.io |
|
|
5
|
+
| 环境 | Platform URL | 命令标识 |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| **prod**(默认) | https://platform.agentscope.io | (无需标识) |
|
|
8
|
+
| **pre**(预发) | https://platform-pre.agentscope.io | 命令末尾加 `pre`,或使用 `--pre` |
|
|
9
|
+
|
|
10
|
+
生产与预发凭证分开存储(`~/.asp/credentials.json` 与 `~/.asp/credentials.pre.json`),互不影响。
|
|
8
11
|
|
|
9
12
|
## 安装
|
|
10
13
|
|
|
@@ -24,23 +27,15 @@ npm install -g @agentscope-ai/platform-cli
|
|
|
24
27
|
|
|
25
28
|
```bash
|
|
26
29
|
asp --token <token>
|
|
30
|
+
asp --pre # 等价于命令末尾的 pre 标识
|
|
31
|
+
asp --platform-url <url> # 高级:自定义 Platform 地址
|
|
27
32
|
asp --verbose
|
|
28
33
|
asp --json
|
|
29
34
|
asp --version
|
|
30
35
|
asp --help
|
|
31
36
|
```
|
|
32
37
|
|
|
33
|
-
##
|
|
34
|
-
|
|
35
|
-
| 命令 | 说明 |
|
|
36
|
-
| --- | --- |
|
|
37
|
-
| `asp auth login` | 登录 |
|
|
38
|
-
| `asp auth status` | 查看状态 |
|
|
39
|
-
| `asp auth refresh` | 刷新 token |
|
|
40
|
-
| `asp auth logout` | 退出 |
|
|
41
|
-
| `asp auth logs` | 查看 CLI 请求留痕 |
|
|
42
|
-
|
|
43
|
-
### 登录方式
|
|
38
|
+
## 登录方式
|
|
44
39
|
|
|
45
40
|
支持两种登录方式(与后端 `/api/cli/v1` 联调文档一致):
|
|
46
41
|
|
|
@@ -49,26 +44,27 @@ asp --help
|
|
|
49
44
|
| **浏览器授权**(推荐) | `asp auth login` → 选 `1` 或 `--browser` | 打开 `{platform_url}/cli/login`,OAuth PKCE 授权后回调本机 |
|
|
50
45
|
| **账号密码** | `asp auth login` → 选 `2` 或 `--password` | `POST /auth/login` |
|
|
51
46
|
|
|
52
|
-
|
|
53
|
-
# 交互式选择登录方式(浏览器 / 账号密码)
|
|
54
|
-
asp auth login
|
|
47
|
+
---
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
asp auth login --browser
|
|
49
|
+
## 生产环境(默认)
|
|
58
50
|
|
|
59
|
-
|
|
60
|
-
asp auth login --password
|
|
61
|
-
asp auth login --password --account user@example.com --pass 'your-password'
|
|
62
|
-
```
|
|
51
|
+
命令不加 `pre`,默认对接 `https://platform.agentscope.io`。
|
|
63
52
|
|
|
64
|
-
|
|
53
|
+
### 鉴权
|
|
65
54
|
|
|
66
55
|
```bash
|
|
67
56
|
asp auth login
|
|
57
|
+
asp auth login --browser
|
|
58
|
+
asp auth login --password
|
|
59
|
+
asp auth login --password --account user@example.com --pass 'your-password'
|
|
60
|
+
|
|
68
61
|
asp auth status
|
|
62
|
+
asp auth refresh
|
|
63
|
+
asp auth logout
|
|
64
|
+
asp auth logs
|
|
69
65
|
```
|
|
70
66
|
|
|
71
|
-
|
|
67
|
+
### Plugin
|
|
72
68
|
|
|
73
69
|
```bash
|
|
74
70
|
# 搜索 / 查看
|
|
@@ -90,7 +86,7 @@ asp plugin publish status plugin_id --watch
|
|
|
90
86
|
asp plugin publish logs plugin_id
|
|
91
87
|
```
|
|
92
88
|
|
|
93
|
-
|
|
89
|
+
### Skill
|
|
94
90
|
|
|
95
91
|
```bash
|
|
96
92
|
# 搜索 / 查看
|
|
@@ -102,12 +98,76 @@ asp skill versions <skill_id>
|
|
|
102
98
|
asp skill install <skill_id>
|
|
103
99
|
|
|
104
100
|
# 发布:本地 zip(未传 --category 会交互选择)
|
|
105
|
-
asp skill publish ./my-skill.zip --category document
|
|
101
|
+
asp skill publish ./my-skill.zip --category 'document office'
|
|
106
102
|
|
|
107
103
|
# 发布:URL(未传 --category 会交互选择)
|
|
108
|
-
asp skill publish --url "https://github.com/org/repo/releases/download/v1.0.0/skill.zip" --category document
|
|
104
|
+
asp skill publish --url "https://github.com/org/repo/releases/download/v1.0.0/skill.zip" --category 'document office'
|
|
109
105
|
|
|
110
106
|
# 查询发布进度 / 日志
|
|
111
107
|
asp skill publish status <skill_id> --watch
|
|
112
108
|
asp skill publish logs <skill_id>
|
|
113
109
|
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 预发环境
|
|
114
|
+
|
|
115
|
+
所有命令末尾加 `pre`(或使用 `--pre`),对接 `https://platform-pre.agentscope.io`。
|
|
116
|
+
|
|
117
|
+
### 鉴权
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
asp auth login pre
|
|
121
|
+
asp auth login --browser pre
|
|
122
|
+
asp auth login --password pre
|
|
123
|
+
asp auth login --password --account user@example.com --pass 'your-password' pre
|
|
124
|
+
|
|
125
|
+
asp auth status pre
|
|
126
|
+
asp auth refresh pre
|
|
127
|
+
asp auth logout pre
|
|
128
|
+
asp auth logs pre
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Plugin
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
# 搜索 / 查看
|
|
135
|
+
asp plugin search qwen pre
|
|
136
|
+
asp plugin info <plugin_id> pre
|
|
137
|
+
asp plugin versions <plugin_id> pre
|
|
138
|
+
|
|
139
|
+
# 安装(通过 qwenpaw)
|
|
140
|
+
asp plugin install <plugin_id> pre
|
|
141
|
+
|
|
142
|
+
# 发布:本地 zip
|
|
143
|
+
asp plugin publish ./my-plugin.zip pre
|
|
144
|
+
|
|
145
|
+
# 发布:URL
|
|
146
|
+
asp plugin publish --url "https://github.com/org/repo/releases/download/v1.0.0/plugin.zip" --category tool pre
|
|
147
|
+
|
|
148
|
+
# 查询发布进度 / 日志
|
|
149
|
+
asp plugin publish status plugin_id --watch pre
|
|
150
|
+
asp plugin publish logs plugin_id pre
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Skill
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# 搜索 / 查看
|
|
157
|
+
asp skill search web pre
|
|
158
|
+
asp skill info <skill_id> pre
|
|
159
|
+
asp skill versions <skill_id> pre
|
|
160
|
+
|
|
161
|
+
# 安装(通过 qwenpaw)
|
|
162
|
+
asp skill install <skill_id> pre
|
|
163
|
+
|
|
164
|
+
# 发布:本地 zip
|
|
165
|
+
asp skill publish ./my-skill.zip --category 'document office' pre
|
|
166
|
+
|
|
167
|
+
# 发布:URL
|
|
168
|
+
asp skill publish --url "https://github.com/org/repo/releases/download/v1.0.0/skill.zip" --category 'document office' pre
|
|
169
|
+
|
|
170
|
+
# 查询发布进度 / 日志
|
|
171
|
+
asp skill publish status <skill_id> --watch pre
|
|
172
|
+
asp skill publish logs <skill_id> pre
|
|
173
|
+
```
|
|
@@ -16,12 +16,13 @@ var CLI_VERSION = pkg.version;
|
|
|
16
16
|
var CLIENT_ID = "agentscope-platform-cli";
|
|
17
17
|
var DEFAULT_SCOPE = "platform:control";
|
|
18
18
|
var PLATFORM_URL = "https://platform.agentscope.io";
|
|
19
|
+
var PRE_PLATFORM_URL = "https://platform-pre.agentscope.io";
|
|
19
20
|
var DEFAULT_PLATFORM_URL = PLATFORM_URL;
|
|
20
21
|
var CLI_API_PREFIX = "/api/cli/v1";
|
|
21
22
|
|
|
22
23
|
// src/config.ts
|
|
23
24
|
function resolveConfig(opts = {}) {
|
|
24
|
-
const platformUrl = resolvePlatformUrl(opts.platformUrl);
|
|
25
|
+
const platformUrl = resolvePlatformUrl(opts.platformUrl, opts.pre);
|
|
25
26
|
const token = opts.token ?? process.env.ASP_TOKEN;
|
|
26
27
|
return {
|
|
27
28
|
platformUrl,
|
|
@@ -30,35 +31,45 @@ function resolveConfig(opts = {}) {
|
|
|
30
31
|
json: opts.json ?? false
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
|
-
function resolvePlatformUrl(explicitUrl) {
|
|
34
|
-
|
|
34
|
+
function resolvePlatformUrl(explicitUrl, pre) {
|
|
35
|
+
if (explicitUrl) {
|
|
36
|
+
return explicitUrl.replace(/\/$/, "");
|
|
37
|
+
}
|
|
38
|
+
if (pre) {
|
|
39
|
+
return PRE_PLATFORM_URL;
|
|
40
|
+
}
|
|
41
|
+
return (process.env.ASP_PLATFORM_URL ?? process.env.PLATFORM_URL ?? DEFAULT_PLATFORM_URL).replace(/\/$/, "");
|
|
35
42
|
}
|
|
36
43
|
function getAspConfigDir() {
|
|
37
44
|
return process.env.ASP_CONFIG_DIR ?? join(homedir(), ".asp");
|
|
38
45
|
}
|
|
39
|
-
function getCredentialsPath() {
|
|
46
|
+
function getCredentialsPath(platformUrl) {
|
|
47
|
+
const normalized = (platformUrl ?? DEFAULT_PLATFORM_URL).replace(/\/$/, "");
|
|
48
|
+
if (normalized === PRE_PLATFORM_URL) {
|
|
49
|
+
return join(getAspConfigDir(), "credentials.pre.json");
|
|
50
|
+
}
|
|
40
51
|
return join(getAspConfigDir(), "credentials.json");
|
|
41
52
|
}
|
|
42
53
|
|
|
43
54
|
// src/auth/credentials.ts
|
|
44
|
-
async function loadCredentials() {
|
|
55
|
+
async function loadCredentials(platformUrl) {
|
|
45
56
|
try {
|
|
46
|
-
const raw = await readFile(getCredentialsPath(), "utf8");
|
|
57
|
+
const raw = await readFile(getCredentialsPath(platformUrl), "utf8");
|
|
47
58
|
return JSON.parse(raw);
|
|
48
59
|
} catch {
|
|
49
60
|
return null;
|
|
50
61
|
}
|
|
51
62
|
}
|
|
52
63
|
async function saveCredentials(creds) {
|
|
53
|
-
const path = getCredentialsPath();
|
|
64
|
+
const path = getCredentialsPath(creds.platform_url);
|
|
54
65
|
await mkdir(dirname(path), { recursive: true, mode: 448 });
|
|
55
66
|
await writeFile(path, JSON.stringify(creds, null, 2), { mode: 384 });
|
|
56
67
|
await chmod(path, 384);
|
|
57
68
|
}
|
|
58
|
-
async function clearCredentials() {
|
|
69
|
+
async function clearCredentials(platformUrl) {
|
|
59
70
|
try {
|
|
60
71
|
const { unlink } = await import("fs/promises");
|
|
61
|
-
await unlink(getCredentialsPath());
|
|
72
|
+
await unlink(getCredentialsPath(platformUrl));
|
|
62
73
|
} catch {
|
|
63
74
|
}
|
|
64
75
|
}
|
|
@@ -86,6 +97,7 @@ export {
|
|
|
86
97
|
CLIENT_ID,
|
|
87
98
|
DEFAULT_SCOPE,
|
|
88
99
|
PLATFORM_URL,
|
|
100
|
+
PRE_PLATFORM_URL,
|
|
89
101
|
CLI_API_PREFIX,
|
|
90
102
|
resolveConfig,
|
|
91
103
|
getAspConfigDir,
|
|
@@ -95,4 +107,4 @@ export {
|
|
|
95
107
|
isTokenExpired,
|
|
96
108
|
credentialsFromTokenResponse
|
|
97
109
|
};
|
|
98
|
-
//# sourceMappingURL=chunk-
|
|
110
|
+
//# sourceMappingURL=chunk-IHANUO75.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/auth/credentials.ts","../src/config.ts","../src/constants.ts"],"sourcesContent":["import { chmod, mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport { getCredentialsPath } from \"../config.js\";\n\nexport interface StoredCredentials {\n access_token: string;\n refresh_token?: string;\n token_type: string;\n expires_at?: string;\n scope?: string;\n platform_url: string;\n user?: {\n id: string;\n display_name?: string;\n email?: string;\n };\n}\n\nexport async function loadCredentials(platformUrl?: string): Promise<StoredCredentials | null> {\n try {\n const raw = await readFile(getCredentialsPath(platformUrl), \"utf8\");\n return JSON.parse(raw) as StoredCredentials;\n } catch {\n return null;\n }\n}\n\nexport async function saveCredentials(creds: StoredCredentials): Promise<void> {\n const path = getCredentialsPath(creds.platform_url);\n await mkdir(dirname(path), { recursive: true, mode: 0o700 });\n await writeFile(path, JSON.stringify(creds, null, 2), { mode: 0o600 });\n await chmod(path, 0o600);\n}\n\nexport async function clearCredentials(platformUrl?: string): Promise<void> {\n try {\n const { unlink } = await import(\"node:fs/promises\");\n await unlink(getCredentialsPath(platformUrl));\n } catch {\n // ignore\n }\n}\n\nexport function isTokenExpired(creds: StoredCredentials): boolean {\n if (!creds.expires_at) return false;\n return Date.now() >= new Date(creds.expires_at).getTime() - 60_000;\n}\n\nexport function credentialsFromTokenResponse(\n platformUrl: string,\n response: {\n access_token: string;\n refresh_token?: string;\n token_type: string;\n expires_in?: number;\n scope?: string;\n user?: StoredCredentials[\"user\"];\n },\n): StoredCredentials {\n const creds: StoredCredentials = {\n access_token: response.access_token,\n refresh_token: response.refresh_token,\n token_type: response.token_type,\n scope: response.scope,\n platform_url: platformUrl,\n user: response.user,\n };\n if (response.expires_in) {\n creds.expires_at = new Date(Date.now() + response.expires_in * 1000).toISOString();\n }\n return creds;\n}\n","import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { DEFAULT_PLATFORM_URL, PRE_PLATFORM_URL } from \"./constants.js\";\n\nexport interface GlobalOptions {\n platformUrl?: string;\n pre?: boolean;\n token?: string;\n verbose?: boolean;\n json?: boolean;\n}\n\nexport interface ResolvedConfig {\n platformUrl: string;\n token?: string;\n verbose: boolean;\n json: boolean;\n}\n\nexport function resolveConfig(opts: GlobalOptions = {}): ResolvedConfig {\n const platformUrl = resolvePlatformUrl(opts.platformUrl, opts.pre);\n\n const token = opts.token ?? process.env.ASP_TOKEN;\n\n return {\n platformUrl,\n token,\n verbose: opts.verbose ?? false,\n json: opts.json ?? false,\n };\n}\n\nfunction resolvePlatformUrl(explicitUrl?: string, pre?: boolean): string {\n if (explicitUrl) {\n return explicitUrl.replace(/\\/$/, \"\");\n }\n if (pre) {\n return PRE_PLATFORM_URL;\n }\n return (\n process.env.ASP_PLATFORM_URL ??\n process.env.PLATFORM_URL ??\n DEFAULT_PLATFORM_URL\n ).replace(/\\/$/, \"\");\n}\n\nexport function getAspConfigDir(): string {\n return process.env.ASP_CONFIG_DIR ?? join(homedir(), \".asp\");\n}\n\nexport function getCredentialsPath(platformUrl?: string): string {\n const normalized = (platformUrl ?? DEFAULT_PLATFORM_URL).replace(/\\/$/, \"\");\n if (normalized === PRE_PLATFORM_URL) {\n return join(getAspConfigDir(), \"credentials.pre.json\");\n }\n return join(getAspConfigDir(), \"credentials.json\");\n}\n","import { createRequire } from \"node:module\";\n\nconst require = createRequire(import.meta.url);\nconst pkg = require(\"../package.json\") as { version: string };\n\nexport const CLI_VERSION = pkg.version;\nexport const CLIENT_ID = \"agentscope-platform-cli\";\nexport const DEFAULT_SCOPE = \"platform:control\";\n\nexport const PLATFORM_URL = \"https://platform.agentscope.io\";\nexport const PRE_PLATFORM_URL = \"https://platform-pre.agentscope.io\";\nexport const DEFAULT_PLATFORM_URL = PLATFORM_URL;\n\nexport const CLI_API_PREFIX = \"/api/cli/v1\";\n"],"mappings":";;;AAAA,SAA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EACvB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,eAAsB,gBAAgB,OAAyC;AAC7E,QAAM,OAAO,mBAAmB,MAAM,YAAY;AAClD,QAAM,MAAM,QAAQ,IAAI,GAAG,EAAE,WAAW,MAAM,MAAM,IAAM,CAAC;AAC3D,QAAM,UAAU,MAAM,KAAK,UAAU,OAAO,MAAM,CAAC,GAAG,EAAE,MAAM,IAAM,CAAC;AACrE,QAAM,MAAM,MAAM,GAAK;AACzB;AAEA,eAAsB,iBAAiB,aAAqC;AAC1E,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,aAAkB;AAClD,UAAM,OAAO,mBAAmB,WAAW,CAAC;AAAA,EAC9C,QAAQ;AAAA,EAER;AACF;AAEO,SAAS,eAAe,OAAmC;AAChE,MAAI,CAAC,MAAM,WAAY,QAAO;AAC9B,SAAO,KAAK,IAAI,KAAK,IAAI,KAAK,MAAM,UAAU,EAAE,QAAQ,IAAI;AAC9D;AAEO,SAAS,6BACd,aACA,UAQmB;AACnB,QAAM,QAA2B;AAAA,IAC/B,cAAc,SAAS;AAAA,IACvB,eAAe,SAAS;AAAA,IACxB,YAAY,SAAS;AAAA,IACrB,OAAO,SAAS;AAAA,IAChB,cAAc;AAAA,IACd,MAAM,SAAS;AAAA,EACjB;AACA,MAAI,SAAS,YAAY;AACvB,UAAM,aAAa,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,aAAa,GAAI,EAAE,YAAY;AAAA,EACnF;AACA,SAAO;AACT;","names":["require"]}
|
|
@@ -12,13 +12,13 @@ var require2 = createRequire(import.meta.url);
|
|
|
12
12
|
var pkg = require2("../package.json");
|
|
13
13
|
var CLI_VERSION = pkg.version;
|
|
14
14
|
var PLATFORM_URL = "https://platform.agentscope.io";
|
|
15
|
+
var PRE_PLATFORM_URL = "https://platform-pre.agentscope.io";
|
|
15
16
|
var DEFAULT_PLATFORM_URL = PLATFORM_URL;
|
|
16
|
-
var PRE_PLATFORM_URL = PLATFORM_URL;
|
|
17
17
|
var CLI_API_PREFIX = "/api/cli/v1";
|
|
18
18
|
|
|
19
19
|
// src/config.ts
|
|
20
20
|
function resolveConfig(opts = {}) {
|
|
21
|
-
const platformUrl = resolvePlatformUrl(opts.platformUrl);
|
|
21
|
+
const platformUrl = resolvePlatformUrl(opts.platformUrl, opts.pre);
|
|
22
22
|
const token = opts.token ?? process.env.ASP_TOKEN;
|
|
23
23
|
return {
|
|
24
24
|
platformUrl,
|
|
@@ -27,35 +27,45 @@ function resolveConfig(opts = {}) {
|
|
|
27
27
|
json: opts.json ?? false
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
function resolvePlatformUrl(explicitUrl) {
|
|
31
|
-
|
|
30
|
+
function resolvePlatformUrl(explicitUrl, pre) {
|
|
31
|
+
if (explicitUrl) {
|
|
32
|
+
return explicitUrl.replace(/\/$/, "");
|
|
33
|
+
}
|
|
34
|
+
if (pre) {
|
|
35
|
+
return PRE_PLATFORM_URL;
|
|
36
|
+
}
|
|
37
|
+
return (process.env.ASP_PLATFORM_URL ?? process.env.PLATFORM_URL ?? DEFAULT_PLATFORM_URL).replace(/\/$/, "");
|
|
32
38
|
}
|
|
33
39
|
function getAspConfigDir() {
|
|
34
40
|
return process.env.ASP_CONFIG_DIR ?? join(homedir(), ".asp");
|
|
35
41
|
}
|
|
36
|
-
function getCredentialsPath() {
|
|
42
|
+
function getCredentialsPath(platformUrl) {
|
|
43
|
+
const normalized = (platformUrl ?? DEFAULT_PLATFORM_URL).replace(/\/$/, "");
|
|
44
|
+
if (normalized === PRE_PLATFORM_URL) {
|
|
45
|
+
return join(getAspConfigDir(), "credentials.pre.json");
|
|
46
|
+
}
|
|
37
47
|
return join(getAspConfigDir(), "credentials.json");
|
|
38
48
|
}
|
|
39
49
|
|
|
40
50
|
// src/auth/credentials.ts
|
|
41
|
-
async function loadCredentials() {
|
|
51
|
+
async function loadCredentials(platformUrl) {
|
|
42
52
|
try {
|
|
43
|
-
const raw = await readFile(getCredentialsPath(), "utf8");
|
|
53
|
+
const raw = await readFile(getCredentialsPath(platformUrl), "utf8");
|
|
44
54
|
return JSON.parse(raw);
|
|
45
55
|
} catch {
|
|
46
56
|
return null;
|
|
47
57
|
}
|
|
48
58
|
}
|
|
49
59
|
async function saveCredentials(creds) {
|
|
50
|
-
const path = getCredentialsPath();
|
|
60
|
+
const path = getCredentialsPath(creds.platform_url);
|
|
51
61
|
await mkdir(dirname(path), { recursive: true, mode: 448 });
|
|
52
62
|
await writeFile(path, JSON.stringify(creds, null, 2), { mode: 384 });
|
|
53
63
|
await chmod(path, 384);
|
|
54
64
|
}
|
|
55
|
-
async function clearCredentials() {
|
|
65
|
+
async function clearCredentials(platformUrl) {
|
|
56
66
|
try {
|
|
57
67
|
const { unlink } = await import("fs/promises");
|
|
58
|
-
await unlink(getCredentialsPath());
|
|
68
|
+
await unlink(getCredentialsPath(platformUrl));
|
|
59
69
|
} catch {
|
|
60
70
|
}
|
|
61
71
|
}
|
|
@@ -81,8 +91,8 @@ function credentialsFromTokenResponse(platformUrl, response) {
|
|
|
81
91
|
export {
|
|
82
92
|
CLI_VERSION,
|
|
83
93
|
PLATFORM_URL,
|
|
84
|
-
DEFAULT_PLATFORM_URL,
|
|
85
94
|
PRE_PLATFORM_URL,
|
|
95
|
+
DEFAULT_PLATFORM_URL,
|
|
86
96
|
CLI_API_PREFIX,
|
|
87
97
|
resolveConfig,
|
|
88
98
|
loadCredentials,
|
|
@@ -91,4 +101,4 @@ export {
|
|
|
91
101
|
isTokenExpired,
|
|
92
102
|
credentialsFromTokenResponse
|
|
93
103
|
};
|
|
94
|
-
//# sourceMappingURL=chunk-
|
|
104
|
+
//# sourceMappingURL=chunk-OKVCMNGY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/auth/credentials.ts","../src/config.ts","../src/constants.ts"],"sourcesContent":["import { chmod, mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport { getCredentialsPath } from \"../config.js\";\n\nexport interface StoredCredentials {\n access_token: string;\n refresh_token?: string;\n token_type: string;\n expires_at?: string;\n scope?: string;\n platform_url: string;\n user?: {\n id: string;\n display_name?: string;\n email?: string;\n };\n}\n\nexport async function loadCredentials(platformUrl?: string): Promise<StoredCredentials | null> {\n try {\n const raw = await readFile(getCredentialsPath(platformUrl), \"utf8\");\n return JSON.parse(raw) as StoredCredentials;\n } catch {\n return null;\n }\n}\n\nexport async function saveCredentials(creds: StoredCredentials): Promise<void> {\n const path = getCredentialsPath(creds.platform_url);\n await mkdir(dirname(path), { recursive: true, mode: 0o700 });\n await writeFile(path, JSON.stringify(creds, null, 2), { mode: 0o600 });\n await chmod(path, 0o600);\n}\n\nexport async function clearCredentials(platformUrl?: string): Promise<void> {\n try {\n const { unlink } = await import(\"node:fs/promises\");\n await unlink(getCredentialsPath(platformUrl));\n } catch {\n // ignore\n }\n}\n\nexport function isTokenExpired(creds: StoredCredentials): boolean {\n if (!creds.expires_at) return false;\n return Date.now() >= new Date(creds.expires_at).getTime() - 60_000;\n}\n\nexport function credentialsFromTokenResponse(\n platformUrl: string,\n response: {\n access_token: string;\n refresh_token?: string;\n token_type: string;\n expires_in?: number;\n scope?: string;\n user?: StoredCredentials[\"user\"];\n },\n): StoredCredentials {\n const creds: StoredCredentials = {\n access_token: response.access_token,\n refresh_token: response.refresh_token,\n token_type: response.token_type,\n scope: response.scope,\n platform_url: platformUrl,\n user: response.user,\n };\n if (response.expires_in) {\n creds.expires_at = new Date(Date.now() + response.expires_in * 1000).toISOString();\n }\n return creds;\n}\n","import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { DEFAULT_PLATFORM_URL, PRE_PLATFORM_URL } from \"./constants.js\";\n\nexport interface GlobalOptions {\n platformUrl?: string;\n pre?: boolean;\n token?: string;\n verbose?: boolean;\n json?: boolean;\n}\n\nexport interface ResolvedConfig {\n platformUrl: string;\n token?: string;\n verbose: boolean;\n json: boolean;\n}\n\nexport function resolveConfig(opts: GlobalOptions = {}): ResolvedConfig {\n const platformUrl = resolvePlatformUrl(opts.platformUrl, opts.pre);\n\n const token = opts.token ?? process.env.ASP_TOKEN;\n\n return {\n platformUrl,\n token,\n verbose: opts.verbose ?? false,\n json: opts.json ?? false,\n };\n}\n\nfunction resolvePlatformUrl(explicitUrl?: string, pre?: boolean): string {\n if (explicitUrl) {\n return explicitUrl.replace(/\\/$/, \"\");\n }\n if (pre) {\n return PRE_PLATFORM_URL;\n }\n return (\n process.env.ASP_PLATFORM_URL ??\n process.env.PLATFORM_URL ??\n DEFAULT_PLATFORM_URL\n ).replace(/\\/$/, \"\");\n}\n\nexport function getAspConfigDir(): string {\n return process.env.ASP_CONFIG_DIR ?? join(homedir(), \".asp\");\n}\n\nexport function getCredentialsPath(platformUrl?: string): string {\n const normalized = (platformUrl ?? DEFAULT_PLATFORM_URL).replace(/\\/$/, \"\");\n if (normalized === PRE_PLATFORM_URL) {\n return join(getAspConfigDir(), \"credentials.pre.json\");\n }\n return join(getAspConfigDir(), \"credentials.json\");\n}\n","import { createRequire } from \"node:module\";\n\nconst require = createRequire(import.meta.url);\nconst pkg = require(\"../package.json\") as { version: string };\n\nexport const CLI_VERSION = pkg.version;\nexport const CLIENT_ID = \"agentscope-platform-cli\";\nexport const DEFAULT_SCOPE = \"platform:control\";\n\nexport const PLATFORM_URL = \"https://platform.agentscope.io\";\nexport const PRE_PLATFORM_URL = \"https://platform-pre.agentscope.io\";\nexport const DEFAULT_PLATFORM_URL = PLATFORM_URL;\n\nexport const CLI_API_PREFIX = \"/api/cli/v1\";\n"],"mappings":";AAAA,SAAS,OAAO,OAAO,UAAU,iBAAiB;AAClD,SAAS,eAAe;;;ACDxB,SAAS,eAAe;AACxB,SAAS,YAAY;;;ACDrB,SAAS,qBAAqB;AAE9B,IAAMA,WAAU,cAAc,YAAY,GAAG;AAC7C,IAAM,MAAMA,SAAQ,iBAAiB;AAE9B,IAAM,cAAc,IAAI;AAIxB,IAAM,eAAe;AAC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