@lsddream/platform-cli 0.1.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 +103 -0
- package/dist/chunk-2RAWITF3.js +134 -0
- package/dist/chunk-2RAWITF3.js.map +1 -0
- package/dist/chunk-3SORXO53.js +90 -0
- package/dist/chunk-3SORXO53.js.map +1 -0
- package/dist/cli.js +1255 -0
- package/dist/cli.js.map +1 -0
- package/dist/credentials-2BZZNZFE.js +16 -0
- package/dist/credentials-2BZZNZFE.js.map +1 -0
- package/dist/credentials-H3QSX2O6.js +15 -0
- package/dist/credentials-H3QSX2O6.js.map +1 -0
- package/dist/index.d.ts +133 -0
- package/dist/index.js +253 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -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,103 @@
|
|
|
1
|
+
# AgentScope Platform CLI (asp)
|
|
2
|
+
|
|
3
|
+
AgentScope Platform 命令行工具。**无 `-pre` 后缀 → 生产环境;带 `-pre` 后缀 → 预发环境。**
|
|
4
|
+
|
|
5
|
+
| 环境 | Platform URL |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| **prod**(默认) | https://platform.agentscope.io |
|
|
8
|
+
| **pre** | https://platform-pre.agentscope.io |
|
|
9
|
+
|
|
10
|
+
> 凭证与登录环境绑定。pre 登录后请使用带 `-pre` 的命令;切换环境前先 `asp auth logout` / `asp auth logout-pre`。
|
|
11
|
+
|
|
12
|
+
## 安装
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install -g @lsddream/platform-cli
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 环境变量
|
|
19
|
+
|
|
20
|
+
| 变量 | 说明 |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| `ASP_TOKEN` | 访问令牌 |
|
|
23
|
+
| `ASP_PLATFORM_URL` | 自定义 Platform 地址(高级) |
|
|
24
|
+
| `ASP_CONFIG_DIR` | 凭证目录,默认 `~/.asp` |
|
|
25
|
+
| `QWENPAW_WORKSPACES_DIR` | 本地 QwenPaw workspaces,默认 `~/.qwenpaw/workspaces` |
|
|
26
|
+
|
|
27
|
+
## 全局选项
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
asp --token <token>
|
|
31
|
+
asp --verbose
|
|
32
|
+
asp --json
|
|
33
|
+
asp --version
|
|
34
|
+
asp --help
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 鉴权
|
|
38
|
+
|
|
39
|
+
| 生产 | 预发 |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `asp auth login` | `asp auth login-pre` |
|
|
42
|
+
| `asp auth status` | `asp auth status-pre` |
|
|
43
|
+
| `asp auth refresh` | `asp auth refresh-pre` |
|
|
44
|
+
| `asp auth logout` | `asp auth logout-pre` |
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
asp auth login # 生产:Email → Password
|
|
48
|
+
asp auth login-pre # 预发:Email → Password
|
|
49
|
+
asp auth status-pre
|
|
50
|
+
asp auth refresh-pre
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Remote Agent
|
|
54
|
+
|
|
55
|
+
| 生产 | 预发 |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `asp qwenpaw remote list` | `asp qwenpaw remote list-pre` |
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
asp qwenpaw remote list
|
|
61
|
+
asp qwenpaw remote list-pre -q daily --status ready
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 本地 Agent
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
asp qwenpaw agents list
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Sync
|
|
71
|
+
|
|
72
|
+
| 生产 | 预发 |
|
|
73
|
+
| --- | --- |
|
|
74
|
+
| `asp qwenpaw sync agent <id>` | `asp qwenpaw sync agent-pre <id>` |
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
asp qwenpaw sync agent daily-agent --dry-run
|
|
78
|
+
asp qwenpaw sync agent-pre daily-agent --dry-run
|
|
79
|
+
asp qwenpaw sync agent daily-agent
|
|
80
|
+
asp qwenpaw sync agent-pre daily-agent
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 典型工作流
|
|
84
|
+
|
|
85
|
+
**生产:**
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
asp auth login
|
|
89
|
+
asp auth status
|
|
90
|
+
asp qwenpaw remote list
|
|
91
|
+
asp qwenpaw sync agent my-agent --dry-run
|
|
92
|
+
asp qwenpaw sync agent my-agent
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**预发:**
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
asp auth login-pre
|
|
99
|
+
asp auth status-pre
|
|
100
|
+
asp qwenpaw remote list-pre
|
|
101
|
+
asp qwenpaw sync agent-pre my-agent --dry-run
|
|
102
|
+
asp qwenpaw sync agent-pre my-agent
|
|
103
|
+
```
|
|
@@ -0,0 +1,134 @@
|
|
|
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.0";
|
|
13
|
+
var CLIENT_ID = "agentscope-platform-cli";
|
|
14
|
+
var DEFAULT_SCOPE = "platform:control qwenpaw:sync";
|
|
15
|
+
var PROD_PLATFORM_URL = "https://platform.agentscope.io";
|
|
16
|
+
var PRE_PLATFORM_URL = "https://platform-pre.agentscope.io";
|
|
17
|
+
var DEFAULT_PLATFORM_URL = PROD_PLATFORM_URL;
|
|
18
|
+
var CLI_API_PREFIX = "/api/cli/v1";
|
|
19
|
+
var QWENPAW_API_PREFIX = "/api/qwenpaw/v1";
|
|
20
|
+
var SYNC_DEFAULT_FILES = [
|
|
21
|
+
"agent.json",
|
|
22
|
+
"AGENTS.md",
|
|
23
|
+
"SOUL.md",
|
|
24
|
+
"PROFILE.md",
|
|
25
|
+
"MEMORY.md",
|
|
26
|
+
"skill.json"
|
|
27
|
+
];
|
|
28
|
+
var EXCLUDED_PATTERNS = [
|
|
29
|
+
"browser/",
|
|
30
|
+
"token_usage.json",
|
|
31
|
+
"providers.json",
|
|
32
|
+
"envs.json",
|
|
33
|
+
"cache/",
|
|
34
|
+
"tmp/",
|
|
35
|
+
"logs/",
|
|
36
|
+
".git/",
|
|
37
|
+
"node_modules/"
|
|
38
|
+
];
|
|
39
|
+
var SENSITIVE_REASONS = {
|
|
40
|
+
"browser/": "sensitive_browser_profile",
|
|
41
|
+
"providers.json": "secret",
|
|
42
|
+
"envs.json": "secret",
|
|
43
|
+
"token_usage.json": "cache",
|
|
44
|
+
"cache/": "cache",
|
|
45
|
+
"tmp/": "cache",
|
|
46
|
+
"logs/": "cache",
|
|
47
|
+
".git/": "vcs",
|
|
48
|
+
"node_modules/": "dependencies"
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/config.ts
|
|
52
|
+
function resolveConfig(opts = {}) {
|
|
53
|
+
const platformUrl = opts.platformUrl ?? process.env.ASP_PLATFORM_URL ?? process.env.PLATFORM_URL ?? DEFAULT_PLATFORM_URL;
|
|
54
|
+
const token = opts.token ?? process.env.ASP_TOKEN;
|
|
55
|
+
return {
|
|
56
|
+
platformUrl: platformUrl.replace(/\/$/, ""),
|
|
57
|
+
token,
|
|
58
|
+
verbose: opts.verbose ?? false,
|
|
59
|
+
json: opts.json ?? false
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function getAspConfigDir() {
|
|
63
|
+
return process.env.ASP_CONFIG_DIR ?? join(homedir(), ".asp");
|
|
64
|
+
}
|
|
65
|
+
function getCredentialsPath() {
|
|
66
|
+
return join(getAspConfigDir(), "credentials.json");
|
|
67
|
+
}
|
|
68
|
+
function getQwenpawWorkspacesRoot() {
|
|
69
|
+
const env = process.env.QWENPAW_WORKSPACES_DIR;
|
|
70
|
+
if (env) return env;
|
|
71
|
+
return join(homedir(), ".qwenpaw", "workspaces");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/auth/credentials.ts
|
|
75
|
+
async function loadCredentials() {
|
|
76
|
+
try {
|
|
77
|
+
const raw = await readFile(getCredentialsPath(), "utf8");
|
|
78
|
+
return JSON.parse(raw);
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function saveCredentials(creds) {
|
|
84
|
+
const path = getCredentialsPath();
|
|
85
|
+
await mkdir(dirname(path), { recursive: true, mode: 448 });
|
|
86
|
+
await writeFile(path, JSON.stringify(creds, null, 2), { mode: 384 });
|
|
87
|
+
await chmod(path, 384);
|
|
88
|
+
}
|
|
89
|
+
async function clearCredentials() {
|
|
90
|
+
try {
|
|
91
|
+
const { unlink } = await import("fs/promises");
|
|
92
|
+
await unlink(getCredentialsPath());
|
|
93
|
+
} catch {
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function isTokenExpired(creds) {
|
|
97
|
+
if (!creds.expires_at) return false;
|
|
98
|
+
return Date.now() >= new Date(creds.expires_at).getTime() - 6e4;
|
|
99
|
+
}
|
|
100
|
+
function credentialsFromTokenResponse(platformUrl, response) {
|
|
101
|
+
const creds = {
|
|
102
|
+
access_token: response.access_token,
|
|
103
|
+
refresh_token: response.refresh_token,
|
|
104
|
+
token_type: response.token_type,
|
|
105
|
+
scope: response.scope,
|
|
106
|
+
platform_url: platformUrl,
|
|
107
|
+
user: response.user
|
|
108
|
+
};
|
|
109
|
+
if (response.expires_in) {
|
|
110
|
+
creds.expires_at = new Date(Date.now() + response.expires_in * 1e3).toISOString();
|
|
111
|
+
}
|
|
112
|
+
return creds;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export {
|
|
116
|
+
CLI_VERSION,
|
|
117
|
+
CLIENT_ID,
|
|
118
|
+
DEFAULT_SCOPE,
|
|
119
|
+
PROD_PLATFORM_URL,
|
|
120
|
+
PRE_PLATFORM_URL,
|
|
121
|
+
CLI_API_PREFIX,
|
|
122
|
+
QWENPAW_API_PREFIX,
|
|
123
|
+
SYNC_DEFAULT_FILES,
|
|
124
|
+
EXCLUDED_PATTERNS,
|
|
125
|
+
SENSITIVE_REASONS,
|
|
126
|
+
resolveConfig,
|
|
127
|
+
getQwenpawWorkspacesRoot,
|
|
128
|
+
loadCredentials,
|
|
129
|
+
saveCredentials,
|
|
130
|
+
clearCredentials,
|
|
131
|
+
isTokenExpired,
|
|
132
|
+
credentialsFromTokenResponse
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=chunk-2RAWITF3.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\nexport function getQwenpawWorkspacesRoot(): string {\n const env = process.env.QWENPAW_WORKSPACES_DIR;\n if (env) return env;\n return join(homedir(), \".qwenpaw\", \"workspaces\");\n}\n","export const CLI_VERSION = \"0.1.0\";\nexport const CLIENT_ID = \"agentscope-platform-cli\";\nexport const DEFAULT_SCOPE = \"platform:control qwenpaw:sync\";\n\nexport const PROD_PLATFORM_URL = \"https://platform.agentscope.io\";\nexport const PRE_PLATFORM_URL = \"https://platform-pre.agentscope.io\";\nexport const DEFAULT_PLATFORM_URL = PROD_PLATFORM_URL;\n\nexport const CLI_API_PREFIX = \"/api/cli/v1\";\nexport const QWENPAW_API_PREFIX = \"/api/qwenpaw/v1\";\n\nexport const QWENPAW_WORKSPACES_DIR = \".qwenpaw/workspaces\";\n\nexport const SYNC_DEFAULT_FILES = [\n \"agent.json\",\n \"AGENTS.md\",\n \"SOUL.md\",\n \"PROFILE.md\",\n \"MEMORY.md\",\n \"skill.json\",\n] as const;\n\nexport const EXCLUDED_PATTERNS = [\n \"browser/\",\n \"token_usage.json\",\n \"providers.json\",\n \"envs.json\",\n \"cache/\",\n \"tmp/\",\n \"logs/\",\n \".git/\",\n \"node_modules/\",\n] as const;\n\nexport const SENSITIVE_REASONS: Record<string, string> = {\n \"browser/\": \"sensitive_browser_profile\",\n \"providers.json\": \"secret\",\n \"envs.json\": \"secret\",\n \"token_usage.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/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.0";
|
|
11
|
+
var PROD_PLATFORM_URL = "https://platform.agentscope.io";
|
|
12
|
+
var PRE_PLATFORM_URL = "https://platform-pre.agentscope.io";
|
|
13
|
+
var DEFAULT_PLATFORM_URL = PROD_PLATFORM_URL;
|
|
14
|
+
var CLI_API_PREFIX = "/api/cli/v1";
|
|
15
|
+
var QWENPAW_API_PREFIX = "/api/qwenpaw/v1";
|
|
16
|
+
|
|
17
|
+
// src/config.ts
|
|
18
|
+
function resolveConfig(opts = {}) {
|
|
19
|
+
const platformUrl = opts.platformUrl ?? process.env.ASP_PLATFORM_URL ?? process.env.PLATFORM_URL ?? DEFAULT_PLATFORM_URL;
|
|
20
|
+
const token = opts.token ?? process.env.ASP_TOKEN;
|
|
21
|
+
return {
|
|
22
|
+
platformUrl: platformUrl.replace(/\/$/, ""),
|
|
23
|
+
token,
|
|
24
|
+
verbose: opts.verbose ?? false,
|
|
25
|
+
json: opts.json ?? false
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function getAspConfigDir() {
|
|
29
|
+
return process.env.ASP_CONFIG_DIR ?? join(homedir(), ".asp");
|
|
30
|
+
}
|
|
31
|
+
function getCredentialsPath() {
|
|
32
|
+
return join(getAspConfigDir(), "credentials.json");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/auth/credentials.ts
|
|
36
|
+
async function loadCredentials() {
|
|
37
|
+
try {
|
|
38
|
+
const raw = await readFile(getCredentialsPath(), "utf8");
|
|
39
|
+
return JSON.parse(raw);
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function saveCredentials(creds) {
|
|
45
|
+
const path = getCredentialsPath();
|
|
46
|
+
await mkdir(dirname(path), { recursive: true, mode: 448 });
|
|
47
|
+
await writeFile(path, JSON.stringify(creds, null, 2), { mode: 384 });
|
|
48
|
+
await chmod(path, 384);
|
|
49
|
+
}
|
|
50
|
+
async function clearCredentials() {
|
|
51
|
+
try {
|
|
52
|
+
const { unlink } = await import("fs/promises");
|
|
53
|
+
await unlink(getCredentialsPath());
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function isTokenExpired(creds) {
|
|
58
|
+
if (!creds.expires_at) return false;
|
|
59
|
+
return Date.now() >= new Date(creds.expires_at).getTime() - 6e4;
|
|
60
|
+
}
|
|
61
|
+
function credentialsFromTokenResponse(platformUrl, response) {
|
|
62
|
+
const creds = {
|
|
63
|
+
access_token: response.access_token,
|
|
64
|
+
refresh_token: response.refresh_token,
|
|
65
|
+
token_type: response.token_type,
|
|
66
|
+
scope: response.scope,
|
|
67
|
+
platform_url: platformUrl,
|
|
68
|
+
user: response.user
|
|
69
|
+
};
|
|
70
|
+
if (response.expires_in) {
|
|
71
|
+
creds.expires_at = new Date(Date.now() + response.expires_in * 1e3).toISOString();
|
|
72
|
+
}
|
|
73
|
+
return creds;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
CLI_VERSION,
|
|
78
|
+
PROD_PLATFORM_URL,
|
|
79
|
+
PRE_PLATFORM_URL,
|
|
80
|
+
DEFAULT_PLATFORM_URL,
|
|
81
|
+
CLI_API_PREFIX,
|
|
82
|
+
QWENPAW_API_PREFIX,
|
|
83
|
+
resolveConfig,
|
|
84
|
+
loadCredentials,
|
|
85
|
+
saveCredentials,
|
|
86
|
+
clearCredentials,
|
|
87
|
+
isTokenExpired,
|
|
88
|
+
credentialsFromTokenResponse
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=chunk-3SORXO53.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\nexport function getQwenpawWorkspacesRoot(): string {\n const env = process.env.QWENPAW_WORKSPACES_DIR;\n if (env) return env;\n return join(homedir(), \".qwenpaw\", \"workspaces\");\n}\n","export const CLI_VERSION = \"0.1.0\";\nexport const CLIENT_ID = \"agentscope-platform-cli\";\nexport const DEFAULT_SCOPE = \"platform:control qwenpaw:sync\";\n\nexport const PROD_PLATFORM_URL = \"https://platform.agentscope.io\";\nexport const PRE_PLATFORM_URL = \"https://platform-pre.agentscope.io\";\nexport const DEFAULT_PLATFORM_URL = PROD_PLATFORM_URL;\n\nexport const CLI_API_PREFIX = \"/api/cli/v1\";\nexport const QWENPAW_API_PREFIX = \"/api/qwenpaw/v1\";\n\nexport const QWENPAW_WORKSPACES_DIR = \".qwenpaw/workspaces\";\n\nexport const SYNC_DEFAULT_FILES = [\n \"agent.json\",\n \"AGENTS.md\",\n \"SOUL.md\",\n \"PROFILE.md\",\n \"MEMORY.md\",\n \"skill.json\",\n] as const;\n\nexport const EXCLUDED_PATTERNS = [\n \"browser/\",\n \"token_usage.json\",\n \"providers.json\",\n \"envs.json\",\n \"cache/\",\n \"tmp/\",\n \"logs/\",\n \".git/\",\n \"node_modules/\",\n] as const;\n\nexport const SENSITIVE_REASONS: Record<string, string> = {\n \"browser/\": \"sensitive_browser_profile\",\n \"providers.json\": \"secret\",\n \"envs.json\": \"secret\",\n \"token_usage.json\": \"cache\",\n \"cache/\": \"cache\",\n \"tmp/\": \"cache\",\n \"logs/\": \"cache\",\n \".git/\": \"vcs\",\n \"node_modules/\": \"dependencies\",\n};\n"],"mappings":";AAAA,SAAS,OAAO,OAAO,UAAU,iBAAiB;AAClD,SAAS,eAAe;;;ACDxB,SAAS,eAAe;AACxB,SAAS,YAAY;;;ACDd,IAAM,cAAc;AAIpB,IAAM,oBAAoB;AAC1B,IAAM,mBAAmB;AACzB,IAAM,uBAAuB;AAE7B,IAAM,iBAAiB;AACvB,IAAM,qBAAqB;;;ADS3B,SAAS,cAAc,OAAsB,CAAC,GAAmB;AACtE,QAAM,cACJ,KAAK,eACL,QAAQ,IAAI,oBACZ,QAAQ,IAAI,gBACZ;AAEF,QAAM,QAAQ,KAAK,SAAS,QAAQ,IAAI;AAExC,SAAO;AAAA,IACL,aAAa,YAAY,QAAQ,OAAO,EAAE;AAAA,IAC1C;AAAA,IACA,SAAS,KAAK,WAAW;AAAA,IACzB,MAAM,KAAK,QAAQ;AAAA,EACrB;AACF;AAEO,SAAS,kBAA0B;AACxC,SAAO,QAAQ,IAAI,kBAAkB,KAAK,QAAQ,GAAG,MAAM;AAC7D;AAEO,SAAS,qBAA6B;AAC3C,SAAO,KAAK,gBAAgB,GAAG,kBAAkB;AACnD;;;ADvBA,eAAsB,kBAAqD;AACzE,MAAI;AACF,UAAM,MAAM,MAAM,SAAS,mBAAmB,GAAG,MAAM;AACvD,WAAO,KAAK,MAAM,GAAG;AAAA,EACvB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,eAAsB,gBAAgB,OAAyC;AAC7E,QAAM,OAAO,mBAAmB;AAChC,QAAM,MAAM,QAAQ,IAAI,GAAG,EAAE,WAAW,MAAM,MAAM,IAAM,CAAC;AAC3D,QAAM,UAAU,MAAM,KAAK,UAAU,OAAO,MAAM,CAAC,GAAG,EAAE,MAAM,IA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