@agentscope-ai/platform-cli 1.0.0
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/LICENSE +19 -0
- package/README.md +115 -0
- package/dist/chunk-L5UHVBIK.js +88 -0
- package/dist/chunk-L5UHVBIK.js.map +1 -0
- package/dist/chunk-YKR5C7LX.js +92 -0
- package/dist/chunk-YKR5C7LX.js.map +1 -0
- package/dist/cli.js +2380 -0
- package/dist/cli.js.map +1 -0
- package/dist/credentials-LRYJ2DCU.js +16 -0
- package/dist/credentials-LRYJ2DCU.js.map +1 -0
- package/dist/credentials-OMJIFVFF.js +15 -0
- package/dist/credentials-OMJIFVFF.js.map +1 -0
- package/dist/index.d.ts +276 -0
- package/dist/index.js +321 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
Copyright 2026 AgentScope Platform Contributors
|
|
8
|
+
|
|
9
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
you may not use this file except in compliance with the License.
|
|
11
|
+
You may obtain a copy of the License at
|
|
12
|
+
|
|
13
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
|
|
15
|
+
Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
See the License for the specific language governing permissions and
|
|
19
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# AgentScope Platform CLI (asp)
|
|
2
|
+
|
|
3
|
+
AgentScope Platform 命令行工具。当前默认对接 **pre**:`https://platform-pre.agentscope.io`。
|
|
4
|
+
|
|
5
|
+
| 环境 | Platform URL |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| **pre**(默认) | https://platform-pre.agentscope.io |
|
|
8
|
+
|
|
9
|
+
> 后续线上环境就绪后,可通过 `ASP_PLATFORM_URL` 或 `--platform-url` 切换到目标地址,无需改命令名。
|
|
10
|
+
|
|
11
|
+
## 安装
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install -g @agentscope-ai/platform-cli
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 环境变量
|
|
18
|
+
|
|
19
|
+
| 变量 | 说明 |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| `ASP_TOKEN` | 访问令牌 |
|
|
22
|
+
| `ASP_PLATFORM_URL` | 自定义 Platform 地址(高级) |
|
|
23
|
+
| `ASP_CONFIG_DIR` | 凭证目录,默认 `~/.asp` |
|
|
24
|
+
|
|
25
|
+
## 全局选项
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
asp --token <token>
|
|
29
|
+
asp --verbose
|
|
30
|
+
asp --json
|
|
31
|
+
asp --version
|
|
32
|
+
asp --help
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 鉴权
|
|
36
|
+
|
|
37
|
+
| 命令 | 说明 |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| `asp auth login` | 登录 |
|
|
40
|
+
| `asp auth status` | 查看状态 |
|
|
41
|
+
| `asp auth refresh` | 刷新 token |
|
|
42
|
+
| `asp auth logout` | 退出 |
|
|
43
|
+
| `asp auth logs` | 查看 CLI 请求留痕 |
|
|
44
|
+
|
|
45
|
+
### 登录方式
|
|
46
|
+
|
|
47
|
+
支持两种登录方式(与后端 `/api/cli/v1` 联调文档一致):
|
|
48
|
+
|
|
49
|
+
| 方式 | 命令 | 说明 |
|
|
50
|
+
| --- | --- | --- |
|
|
51
|
+
| **浏览器授权**(推荐) | `asp auth login` → 选 `1` 或 `--browser` | 打开 `{platform_url}/cli/login`,OAuth PKCE 授权后回调本机 |
|
|
52
|
+
| **账号密码** | `asp auth login` → 选 `2` 或 `--password` | `POST /auth/login` |
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# 交互式选择登录方式(浏览器 / 账号密码)
|
|
56
|
+
asp auth login
|
|
57
|
+
|
|
58
|
+
# 浏览器授权登录(类似 gh auth login --web)
|
|
59
|
+
asp auth login --browser
|
|
60
|
+
|
|
61
|
+
# 账号密码登录
|
|
62
|
+
asp auth login --password
|
|
63
|
+
asp auth login --password --account user@example.com --pass 'your-password'
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## 典型工作流
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
asp auth login
|
|
70
|
+
asp auth status
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Plugin 命令
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# 搜索 / 查看
|
|
77
|
+
asp plugin search qwen
|
|
78
|
+
asp plugin info <plugin_id>
|
|
79
|
+
asp plugin versions <plugin_id>
|
|
80
|
+
|
|
81
|
+
# 安装(通过 qwenpaw)
|
|
82
|
+
asp plugin install <plugin_id>
|
|
83
|
+
|
|
84
|
+
# 发布:本地 zip(zip 模式下 artifact_id/version 由 complete 阶段从包内解析)
|
|
85
|
+
asp plugin publish ./my-plugin.zip
|
|
86
|
+
|
|
87
|
+
# 发布:URL(会优先从 URL 自动识别 category,识别不到再交互选择)
|
|
88
|
+
asp plugin publish --url "https://github.com/org/repo/releases/download/v1.0.0/plugin.zip" --category tool
|
|
89
|
+
|
|
90
|
+
# 查询发布进度 / 日志(支持 plugin_id;已发布插件会走 GET /plugins/{id})
|
|
91
|
+
asp plugin publish status plugin_id --watch
|
|
92
|
+
asp plugin publish logs plugin_id
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Skill 命令
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# 搜索 / 查看
|
|
99
|
+
asp skill search web
|
|
100
|
+
asp skill info <skill_id>
|
|
101
|
+
asp skill versions <skill_id>
|
|
102
|
+
|
|
103
|
+
# 安装(通过 qwenpaw)
|
|
104
|
+
asp skill install <skill_id>
|
|
105
|
+
|
|
106
|
+
# 发布:本地 zip(未传 --category 会交互选择)
|
|
107
|
+
asp skill publish ./my-skill.zip --category document
|
|
108
|
+
|
|
109
|
+
# 发布:URL(未传 --category 会交互选择)
|
|
110
|
+
asp skill publish --url "https://github.com/org/repo/releases/download/v1.0.0/skill.zip" --category document
|
|
111
|
+
|
|
112
|
+
# 查询发布进度 / 日志
|
|
113
|
+
asp skill publish status <skill_id> --watch
|
|
114
|
+
asp skill publish logs <skill_id>
|
|
115
|
+
```
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// src/auth/credentials.ts
|
|
2
|
+
import { chmod, mkdir, readFile, writeFile } from "fs/promises";
|
|
3
|
+
import { dirname } from "path";
|
|
4
|
+
|
|
5
|
+
// src/config.ts
|
|
6
|
+
import { homedir } from "os";
|
|
7
|
+
import { join } from "path";
|
|
8
|
+
|
|
9
|
+
// src/constants.ts
|
|
10
|
+
var CLI_VERSION = "0.1.8";
|
|
11
|
+
var PLATFORM_URL = "https://platform-pre.agentscope.io";
|
|
12
|
+
var DEFAULT_PLATFORM_URL = PLATFORM_URL;
|
|
13
|
+
var PRE_PLATFORM_URL = PLATFORM_URL;
|
|
14
|
+
var CLI_API_PREFIX = "/api/cli/v1";
|
|
15
|
+
|
|
16
|
+
// src/config.ts
|
|
17
|
+
function resolveConfig(opts = {}) {
|
|
18
|
+
const platformUrl = opts.platformUrl ?? process.env.ASP_PLATFORM_URL ?? process.env.PLATFORM_URL ?? DEFAULT_PLATFORM_URL;
|
|
19
|
+
const token = opts.token ?? process.env.ASP_TOKEN;
|
|
20
|
+
return {
|
|
21
|
+
platformUrl: platformUrl.replace(/\/$/, ""),
|
|
22
|
+
token,
|
|
23
|
+
verbose: opts.verbose ?? false,
|
|
24
|
+
json: opts.json ?? false
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function getAspConfigDir() {
|
|
28
|
+
return process.env.ASP_CONFIG_DIR ?? join(homedir(), ".asp");
|
|
29
|
+
}
|
|
30
|
+
function getCredentialsPath() {
|
|
31
|
+
return join(getAspConfigDir(), "credentials.json");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/auth/credentials.ts
|
|
35
|
+
async function loadCredentials() {
|
|
36
|
+
try {
|
|
37
|
+
const raw = await readFile(getCredentialsPath(), "utf8");
|
|
38
|
+
return JSON.parse(raw);
|
|
39
|
+
} catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function saveCredentials(creds) {
|
|
44
|
+
const path = getCredentialsPath();
|
|
45
|
+
await mkdir(dirname(path), { recursive: true, mode: 448 });
|
|
46
|
+
await writeFile(path, JSON.stringify(creds, null, 2), { mode: 384 });
|
|
47
|
+
await chmod(path, 384);
|
|
48
|
+
}
|
|
49
|
+
async function clearCredentials() {
|
|
50
|
+
try {
|
|
51
|
+
const { unlink } = await import("fs/promises");
|
|
52
|
+
await unlink(getCredentialsPath());
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function isTokenExpired(creds) {
|
|
57
|
+
if (!creds.expires_at) return false;
|
|
58
|
+
return Date.now() >= new Date(creds.expires_at).getTime() - 6e4;
|
|
59
|
+
}
|
|
60
|
+
function credentialsFromTokenResponse(platformUrl, response) {
|
|
61
|
+
const creds = {
|
|
62
|
+
access_token: response.access_token,
|
|
63
|
+
refresh_token: response.refresh_token,
|
|
64
|
+
token_type: response.token_type,
|
|
65
|
+
scope: response.scope,
|
|
66
|
+
platform_url: platformUrl,
|
|
67
|
+
user: response.user
|
|
68
|
+
};
|
|
69
|
+
if (response.expires_in) {
|
|
70
|
+
creds.expires_at = new Date(Date.now() + response.expires_in * 1e3).toISOString();
|
|
71
|
+
}
|
|
72
|
+
return creds;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
CLI_VERSION,
|
|
77
|
+
PLATFORM_URL,
|
|
78
|
+
DEFAULT_PLATFORM_URL,
|
|
79
|
+
PRE_PLATFORM_URL,
|
|
80
|
+
CLI_API_PREFIX,
|
|
81
|
+
resolveConfig,
|
|
82
|
+
loadCredentials,
|
|
83
|
+
saveCredentials,
|
|
84
|
+
clearCredentials,
|
|
85
|
+
isTokenExpired,
|
|
86
|
+
credentialsFromTokenResponse
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=chunk-L5UHVBIK.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(): Promise<StoredCredentials | null> {\n try {\n const raw = await readFile(getCredentialsPath(), \"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();\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(): Promise<void> {\n try {\n const { unlink } = await import(\"node:fs/promises\");\n await unlink(getCredentialsPath());\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 } from \"./constants.js\";\n\nexport interface GlobalOptions {\n platformUrl?: string;\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 =\n opts.platformUrl ??\n process.env.ASP_PLATFORM_URL ??\n process.env.PLATFORM_URL ??\n DEFAULT_PLATFORM_URL;\n\n const token = opts.token ?? process.env.ASP_TOKEN;\n\n return {\n platformUrl: platformUrl.replace(/\\/$/, \"\"),\n token,\n verbose: opts.verbose ?? false,\n json: opts.json ?? false,\n };\n}\n\nexport function getAspConfigDir(): string {\n return process.env.ASP_CONFIG_DIR ?? join(homedir(), \".asp\");\n}\n\nexport function getCredentialsPath(): string {\n return join(getAspConfigDir(), \"credentials.json\");\n}\n","export const CLI_VERSION = \"0.1.8\";\nexport const CLIENT_ID = \"agentscope-platform-cli\";\nexport const DEFAULT_SCOPE = \"platform:control\";\n\nexport const PLATFORM_URL = \"https://platform-pre.agentscope.io\";\nexport const DEFAULT_PLATFORM_URL = PLATFORM_URL;\n/** @deprecated Use {@link PLATFORM_URL} */\nexport const PRE_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,YAA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AM,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":[]}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/auth/credentials.ts
|
|
4
|
+
import { chmod, mkdir, readFile, writeFile } from "fs/promises";
|
|
5
|
+
import { dirname } from "path";
|
|
6
|
+
|
|
7
|
+
// src/config.ts
|
|
8
|
+
import { homedir } from "os";
|
|
9
|
+
import { join } from "path";
|
|
10
|
+
|
|
11
|
+
// src/constants.ts
|
|
12
|
+
var CLI_VERSION = "0.1.8";
|
|
13
|
+
var CLIENT_ID = "agentscope-platform-cli";
|
|
14
|
+
var DEFAULT_SCOPE = "platform:control";
|
|
15
|
+
var PLATFORM_URL = "https://platform-pre.agentscope.io";
|
|
16
|
+
var DEFAULT_PLATFORM_URL = PLATFORM_URL;
|
|
17
|
+
var CLI_API_PREFIX = "/api/cli/v1";
|
|
18
|
+
|
|
19
|
+
// src/config.ts
|
|
20
|
+
function resolveConfig(opts = {}) {
|
|
21
|
+
const platformUrl = opts.platformUrl ?? process.env.ASP_PLATFORM_URL ?? process.env.PLATFORM_URL ?? DEFAULT_PLATFORM_URL;
|
|
22
|
+
const token = opts.token ?? process.env.ASP_TOKEN;
|
|
23
|
+
return {
|
|
24
|
+
platformUrl: platformUrl.replace(/\/$/, ""),
|
|
25
|
+
token,
|
|
26
|
+
verbose: opts.verbose ?? false,
|
|
27
|
+
json: opts.json ?? false
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function getAspConfigDir() {
|
|
31
|
+
return process.env.ASP_CONFIG_DIR ?? join(homedir(), ".asp");
|
|
32
|
+
}
|
|
33
|
+
function getCredentialsPath() {
|
|
34
|
+
return join(getAspConfigDir(), "credentials.json");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/auth/credentials.ts
|
|
38
|
+
async function loadCredentials() {
|
|
39
|
+
try {
|
|
40
|
+
const raw = await readFile(getCredentialsPath(), "utf8");
|
|
41
|
+
return JSON.parse(raw);
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function saveCredentials(creds) {
|
|
47
|
+
const path = getCredentialsPath();
|
|
48
|
+
await mkdir(dirname(path), { recursive: true, mode: 448 });
|
|
49
|
+
await writeFile(path, JSON.stringify(creds, null, 2), { mode: 384 });
|
|
50
|
+
await chmod(path, 384);
|
|
51
|
+
}
|
|
52
|
+
async function clearCredentials() {
|
|
53
|
+
try {
|
|
54
|
+
const { unlink } = await import("fs/promises");
|
|
55
|
+
await unlink(getCredentialsPath());
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function isTokenExpired(creds) {
|
|
60
|
+
if (!creds.expires_at) return false;
|
|
61
|
+
return Date.now() >= new Date(creds.expires_at).getTime() - 6e4;
|
|
62
|
+
}
|
|
63
|
+
function credentialsFromTokenResponse(platformUrl, response) {
|
|
64
|
+
const creds = {
|
|
65
|
+
access_token: response.access_token,
|
|
66
|
+
refresh_token: response.refresh_token,
|
|
67
|
+
token_type: response.token_type,
|
|
68
|
+
scope: response.scope,
|
|
69
|
+
platform_url: platformUrl,
|
|
70
|
+
user: response.user
|
|
71
|
+
};
|
|
72
|
+
if (response.expires_in) {
|
|
73
|
+
creds.expires_at = new Date(Date.now() + response.expires_in * 1e3).toISOString();
|
|
74
|
+
}
|
|
75
|
+
return creds;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export {
|
|
79
|
+
CLI_VERSION,
|
|
80
|
+
CLIENT_ID,
|
|
81
|
+
DEFAULT_SCOPE,
|
|
82
|
+
PLATFORM_URL,
|
|
83
|
+
CLI_API_PREFIX,
|
|
84
|
+
resolveConfig,
|
|
85
|
+
getAspConfigDir,
|
|
86
|
+
loadCredentials,
|
|
87
|
+
saveCredentials,
|
|
88
|
+
clearCredentials,
|
|
89
|
+
isTokenExpired,
|
|
90
|
+
credentialsFromTokenResponse
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=chunk-YKR5C7LX.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(): Promise<StoredCredentials | null> {\n try {\n const raw = await readFile(getCredentialsPath(), \"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();\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(): Promise<void> {\n try {\n const { unlink } = await import(\"node:fs/promises\");\n await unlink(getCredentialsPath());\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 } from \"./constants.js\";\n\nexport interface GlobalOptions {\n platformUrl?: string;\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 =\n opts.platformUrl ??\n process.env.ASP_PLATFORM_URL ??\n process.env.PLATFORM_URL ??\n DEFAULT_PLATFORM_URL;\n\n const token = opts.token ?? process.env.ASP_TOKEN;\n\n return {\n platformUrl: platformUrl.replace(/\\/$/, \"\"),\n token,\n verbose: opts.verbose ?? false,\n json: opts.json ?? false,\n };\n}\n\nexport function getAspConfigDir(): string {\n return process.env.ASP_CONFIG_DIR ?? join(homedir(), \".asp\");\n}\n\nexport function getCredentialsPath(): string {\n return join(getAspConfigDir(), \"credentials.json\");\n}\n","export const CLI_VERSION = \"0.1.8\";\nexport const CLIENT_ID = \"agentscope-platform-cli\";\nexport const DEFAULT_SCOPE = \"platform:control\";\n\nexport const PLATFORM_URL = \"https://platform-pre.agentscope.io\";\nexport const DEFAULT_PLATFORM_URL = PLATFORM_URL;\n/** @deprecated Use {@link PLATFORM_URL} */\nexport const PRE_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,YA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