@agentscope-ai/platform-cli 1.0.2 → 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 CHANGED
@@ -1,12 +1,13 @@
1
1
  # AgentScope Platform CLI (asp)
2
2
 
3
- AgentScope Platform 命令行工具。当前**仅对接预发环境**:`https://platform-pre.agentscope.io`。
3
+ AgentScope Platform 命令行工具。默认对接生产环境:`https://platform.agentscope.io`。
4
4
 
5
- | 环境 | Platform URL |
6
- | --- | --- |
7
- | **pre**(默认且唯一可用) | https://platform-pre.agentscope.io |
5
+ | 环境 | Platform URL | 命令标识 |
6
+ | --- | --- | --- |
7
+ | **prod**(默认) | https://platform.agentscope.io | (无需标识) |
8
+ | **pre**(预发) | https://platform-pre.agentscope.io | 命令末尾加 `pre`,或使用 `--pre` |
8
9
 
9
- > 线上环境 https://platform.agentscope.io 尚未开放。若环境变量或参数指向线上地址,CLI 会自动改用预发 `https://platform-pre.agentscope.io`。
10
+ 生产与预发凭证分开存储(`~/.asp/credentials.json` `~/.asp/credentials.pre.json`),互不影响。
10
11
 
11
12
  ## 安装
12
13
 
@@ -19,30 +20,22 @@ npm install -g @agentscope-ai/platform-cli
19
20
  | 变量 | 说明 |
20
21
  | --- | --- |
21
22
  | `ASP_TOKEN` | 访问令牌 |
22
- | `ASP_PLATFORM_URL` | 自定义 Platform 地址(指向线上时会自动回落到预发) |
23
+ | `ASP_PLATFORM_URL` | 自定义 Platform 地址 |
23
24
  | `ASP_CONFIG_DIR` | 凭证目录,默认 `~/.asp` |
24
25
 
25
26
  ## 全局选项
26
27
 
27
28
  ```bash
28
29
  asp --token <token>
30
+ asp --pre # 等价于命令末尾的 pre 标识
31
+ asp --platform-url <url> # 高级:自定义 Platform 地址
29
32
  asp --verbose
30
33
  asp --json
31
34
  asp --version
32
35
  asp --help
33
36
  ```
34
37
 
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
- ### 登录方式
38
+ ## 登录方式
46
39
 
47
40
  支持两种登录方式(与后端 `/api/cli/v1` 联调文档一致):
48
41
 
@@ -51,26 +44,27 @@ asp --help
51
44
  | **浏览器授权**(推荐) | `asp auth login` → 选 `1` 或 `--browser` | 打开 `{platform_url}/cli/login`,OAuth PKCE 授权后回调本机 |
52
45
  | **账号密码** | `asp auth login` → 选 `2` 或 `--password` | `POST /auth/login` |
53
46
 
54
- ```bash
55
- # 交互式选择登录方式(浏览器 / 账号密码)
56
- asp auth login
47
+ ---
57
48
 
58
- # 浏览器授权登录(类似 gh auth login --web)
59
- asp auth login --browser
49
+ ## 生产环境(默认)
60
50
 
61
- # 账号密码登录
62
- asp auth login --password
63
- asp auth login --password --account user@example.com --pass 'your-password'
64
- ```
51
+ 命令不加 `pre`,默认对接 `https://platform.agentscope.io`。
65
52
 
66
- ## 典型工作流
53
+ ### 鉴权
67
54
 
68
55
  ```bash
69
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
+
70
61
  asp auth status
62
+ asp auth refresh
63
+ asp auth logout
64
+ asp auth logs
71
65
  ```
72
66
 
73
- ## Plugin 命令
67
+ ### Plugin
74
68
 
75
69
  ```bash
76
70
  # 搜索 / 查看
@@ -92,7 +86,7 @@ asp plugin publish status plugin_id --watch
92
86
  asp plugin publish logs plugin_id
93
87
  ```
94
88
 
95
- ## Skill 命令
89
+ ### Skill
96
90
 
97
91
  ```bash
98
92
  # 搜索 / 查看
@@ -104,12 +98,76 @@ asp skill versions <skill_id>
104
98
  asp skill install <skill_id>
105
99
 
106
100
  # 发布:本地 zip(未传 --category 会交互选择)
107
- asp skill publish ./my-skill.zip --category document
101
+ asp skill publish ./my-skill.zip --category 'document office'
108
102
 
109
103
  # 发布:URL(未传 --category 会交互选择)
110
- 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'
111
105
 
112
106
  # 查询发布进度 / 日志
113
107
  asp skill publish status <skill_id> --watch
114
108
  asp skill publish logs <skill_id>
115
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
+ ```
@@ -15,14 +15,14 @@ var pkg = require2("../package.json");
15
15
  var CLI_VERSION = pkg.version;
16
16
  var CLIENT_ID = "agentscope-platform-cli";
17
17
  var DEFAULT_SCOPE = "platform:control";
18
- var PLATFORM_URL = "https://platform-pre.agentscope.io";
19
- var PROD_PLATFORM_URL = "https://platform.agentscope.io";
18
+ var PLATFORM_URL = "https://platform.agentscope.io";
19
+ var PRE_PLATFORM_URL = "https://platform-pre.agentscope.io";
20
20
  var DEFAULT_PLATFORM_URL = PLATFORM_URL;
21
21
  var CLI_API_PREFIX = "/api/cli/v1";
22
22
 
23
23
  // src/config.ts
24
24
  function resolveConfig(opts = {}) {
25
- const platformUrl = resolvePlatformUrl(opts.platformUrl);
25
+ const platformUrl = resolvePlatformUrl(opts.platformUrl, opts.pre);
26
26
  const token = opts.token ?? process.env.ASP_TOKEN;
27
27
  return {
28
28
  platformUrl,
@@ -31,39 +31,45 @@ function resolveConfig(opts = {}) {
31
31
  json: opts.json ?? false
32
32
  };
33
33
  }
34
- function resolvePlatformUrl(explicitUrl) {
35
- const platformUrl = (explicitUrl ?? process.env.ASP_PLATFORM_URL ?? process.env.PLATFORM_URL ?? DEFAULT_PLATFORM_URL).replace(/\/$/, "");
36
- if (platformUrl === PROD_PLATFORM_URL) {
37
- return DEFAULT_PLATFORM_URL;
34
+ function resolvePlatformUrl(explicitUrl, pre) {
35
+ if (explicitUrl) {
36
+ return explicitUrl.replace(/\/$/, "");
38
37
  }
39
- return platformUrl;
38
+ if (pre) {
39
+ return PRE_PLATFORM_URL;
40
+ }
41
+ return (process.env.ASP_PLATFORM_URL ?? process.env.PLATFORM_URL ?? DEFAULT_PLATFORM_URL).replace(/\/$/, "");
40
42
  }
41
43
  function getAspConfigDir() {
42
44
  return process.env.ASP_CONFIG_DIR ?? join(homedir(), ".asp");
43
45
  }
44
- 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
+ }
45
51
  return join(getAspConfigDir(), "credentials.json");
46
52
  }
47
53
 
48
54
  // src/auth/credentials.ts
49
- async function loadCredentials() {
55
+ async function loadCredentials(platformUrl) {
50
56
  try {
51
- const raw = await readFile(getCredentialsPath(), "utf8");
57
+ const raw = await readFile(getCredentialsPath(platformUrl), "utf8");
52
58
  return JSON.parse(raw);
53
59
  } catch {
54
60
  return null;
55
61
  }
56
62
  }
57
63
  async function saveCredentials(creds) {
58
- const path = getCredentialsPath();
64
+ const path = getCredentialsPath(creds.platform_url);
59
65
  await mkdir(dirname(path), { recursive: true, mode: 448 });
60
66
  await writeFile(path, JSON.stringify(creds, null, 2), { mode: 384 });
61
67
  await chmod(path, 384);
62
68
  }
63
- async function clearCredentials() {
69
+ async function clearCredentials(platformUrl) {
64
70
  try {
65
71
  const { unlink } = await import("fs/promises");
66
- await unlink(getCredentialsPath());
72
+ await unlink(getCredentialsPath(platformUrl));
67
73
  } catch {
68
74
  }
69
75
  }
@@ -91,6 +97,7 @@ export {
91
97
  CLIENT_ID,
92
98
  DEFAULT_SCOPE,
93
99
  PLATFORM_URL,
100
+ PRE_PLATFORM_URL,
94
101
  CLI_API_PREFIX,
95
102
  resolveConfig,
96
103
  getAspConfigDir,
@@ -100,4 +107,4 @@ export {
100
107
  isTokenExpired,
101
108
  credentialsFromTokenResponse
102
109
  };
103
- //# sourceMappingURL=chunk-YN3EQLE2.js.map
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,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;AACxB,IAAM,YAAY;AAClB,IAAM,gBAAgB;AAEtB,IAAM,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AAC;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"]}
@@ -11,15 +11,14 @@ import { createRequire } from "module";
11
11
  var require2 = createRequire(import.meta.url);
12
12
  var pkg = require2("../package.json");
13
13
  var CLI_VERSION = pkg.version;
14
- var PLATFORM_URL = "https://platform-pre.agentscope.io";
15
- var PROD_PLATFORM_URL = "https://platform.agentscope.io";
14
+ var PLATFORM_URL = "https://platform.agentscope.io";
15
+ var PRE_PLATFORM_URL = "https://platform-pre.agentscope.io";
16
16
  var DEFAULT_PLATFORM_URL = PLATFORM_URL;
17
- var PRE_PLATFORM_URL = PLATFORM_URL;
18
17
  var CLI_API_PREFIX = "/api/cli/v1";
19
18
 
20
19
  // src/config.ts
21
20
  function resolveConfig(opts = {}) {
22
- const platformUrl = resolvePlatformUrl(opts.platformUrl);
21
+ const platformUrl = resolvePlatformUrl(opts.platformUrl, opts.pre);
23
22
  const token = opts.token ?? process.env.ASP_TOKEN;
24
23
  return {
25
24
  platformUrl,
@@ -28,39 +27,45 @@ function resolveConfig(opts = {}) {
28
27
  json: opts.json ?? false
29
28
  };
30
29
  }
31
- function resolvePlatformUrl(explicitUrl) {
32
- const platformUrl = (explicitUrl ?? process.env.ASP_PLATFORM_URL ?? process.env.PLATFORM_URL ?? DEFAULT_PLATFORM_URL).replace(/\/$/, "");
33
- if (platformUrl === PROD_PLATFORM_URL) {
34
- return DEFAULT_PLATFORM_URL;
30
+ function resolvePlatformUrl(explicitUrl, pre) {
31
+ if (explicitUrl) {
32
+ return explicitUrl.replace(/\/$/, "");
35
33
  }
36
- return platformUrl;
34
+ if (pre) {
35
+ return PRE_PLATFORM_URL;
36
+ }
37
+ return (process.env.ASP_PLATFORM_URL ?? process.env.PLATFORM_URL ?? DEFAULT_PLATFORM_URL).replace(/\/$/, "");
37
38
  }
38
39
  function getAspConfigDir() {
39
40
  return process.env.ASP_CONFIG_DIR ?? join(homedir(), ".asp");
40
41
  }
41
- 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
+ }
42
47
  return join(getAspConfigDir(), "credentials.json");
43
48
  }
44
49
 
45
50
  // src/auth/credentials.ts
46
- async function loadCredentials() {
51
+ async function loadCredentials(platformUrl) {
47
52
  try {
48
- const raw = await readFile(getCredentialsPath(), "utf8");
53
+ const raw = await readFile(getCredentialsPath(platformUrl), "utf8");
49
54
  return JSON.parse(raw);
50
55
  } catch {
51
56
  return null;
52
57
  }
53
58
  }
54
59
  async function saveCredentials(creds) {
55
- const path = getCredentialsPath();
60
+ const path = getCredentialsPath(creds.platform_url);
56
61
  await mkdir(dirname(path), { recursive: true, mode: 448 });
57
62
  await writeFile(path, JSON.stringify(creds, null, 2), { mode: 384 });
58
63
  await chmod(path, 384);
59
64
  }
60
- async function clearCredentials() {
65
+ async function clearCredentials(platformUrl) {
61
66
  try {
62
67
  const { unlink } = await import("fs/promises");
63
- await unlink(getCredentialsPath());
68
+ await unlink(getCredentialsPath(platformUrl));
64
69
  } catch {
65
70
  }
66
71
  }
@@ -86,8 +91,8 @@ function credentialsFromTokenResponse(platformUrl, response) {
86
91
  export {
87
92
  CLI_VERSION,
88
93
  PLATFORM_URL,
89
- DEFAULT_PLATFORM_URL,
90
94
  PRE_PLATFORM_URL,
95
+ DEFAULT_PLATFORM_URL,
91
96
  CLI_API_PREFIX,
92
97
  resolveConfig,
93
98
  loadCredentials,
@@ -96,4 +101,4 @@ export {
96
101
  isTokenExpired,
97
102
  credentialsFromTokenResponse
98
103
  };
99
- //# sourceMappingURL=chunk-GWGNF3I7.js.map
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;AACrB,IAAM,mBAAmB;AACzB,IAAM,uBAAuB;AAE7B,IAAM,iBAAiB;;;ADMvB,SAAS,cAAc,OAAsB,CAAC,GAAmB;AACtE,QAAM,cAAc,mBAAmB,KAAK,aAAa,KAAK,GAAG;AAEjE,QAAM,QAAQ,KAAK,SAAS,QAAQ,IAAI;AAExC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,SAAS,KAAK,WAAW;AAAA,IACzB,MAAM,KAAK,QAAQ;AAAA,EACrB;AACF;AAEA,SAAS,mBAAmB,aAAsB,KAAuB;AACvE,MAAI,aAAa;AACf,WAAO,YAAY,QAAQ,OAAO,EAAE;AAAA,EACtC;AACA,MAAI,KAAK;AACP,WAAO;AAAA,EACT;AACA,UACE,QAAQ,IAAI,oBACZ,QAAQ,IAAI,gBACZ,sBACA,QAAQ,OAAO,EAAE;AACrB;AAEO,SAAS,kBAA0B;AACxC,SAAO,QAAQ,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