artdam-cli 0.4.2__tar.gz → 0.5.0__tar.gz

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.
Files changed (39) hide show
  1. {artdam_cli-0.4.2/artdam_cli.egg-info → artdam_cli-0.5.0}/PKG-INFO +31 -7
  2. artdam_cli-0.4.2/PKG-INFO → artdam_cli-0.5.0/README.md +258 -246
  3. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/client.py +15 -8
  4. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/engine.py +2 -2
  5. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/get.py +4 -2
  6. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/login.py +74 -13
  7. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/update.py +12 -4
  8. artdam_cli-0.5.0/artdam_cli/config.py +143 -0
  9. artdam_cli-0.4.2/README.md → artdam_cli-0.5.0/artdam_cli.egg-info/PKG-INFO +270 -234
  10. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli.egg-info/SOURCES.txt +1 -0
  11. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/pyproject.toml +1 -1
  12. artdam_cli-0.5.0/tests/test_login.py +279 -0
  13. artdam_cli-0.4.2/artdam_cli/config.py +0 -39
  14. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/__init__.py +0 -0
  15. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/__init__.py +0 -0
  16. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/comment.py +0 -0
  17. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/delete_cmd.py +0 -0
  18. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/download.py +0 -0
  19. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/favorite.py +0 -0
  20. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/folder_cmd.py +0 -0
  21. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/folders.py +0 -0
  22. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/project.py +0 -0
  23. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/projects.py +0 -0
  24. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/rate.py +0 -0
  25. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/restore.py +0 -0
  26. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/search.py +0 -0
  27. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/tag_cmd.py +0 -0
  28. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/tags.py +0 -0
  29. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/commands/upload.py +0 -0
  30. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/main.py +0 -0
  31. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/update_check.py +0 -0
  32. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli/uploader.py +0 -0
  33. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli.egg-info/dependency_links.txt +0 -0
  34. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli.egg-info/entry_points.txt +0 -0
  35. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli.egg-info/requires.txt +0 -0
  36. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/artdam_cli.egg-info/top_level.txt +0 -0
  37. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/setup.cfg +0 -0
  38. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/tests/test_search_pagination.py +0 -0
  39. {artdam_cli-0.4.2 → artdam_cli-0.5.0}/tests/test_uploader.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: artdam-cli
3
- Version: 0.4.2
3
+ Version: 0.5.0
4
4
  Summary: ArtDAM 数字资产管理平台命令行工具
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -32,6 +32,9 @@ uv tool install artdam-cli@latest
32
32
  # 登录(首次使用,浏览器 SSO 授权)
33
33
  artdam login
34
34
 
35
+ # 个人 API Key 登录(隐藏输入,适合本机长期使用)
36
+ artdam login --api-key
37
+
35
38
  # 搜索资产
36
39
  artdam search "关键词" --project 1
37
40
 
@@ -48,12 +51,29 @@ artdam download 123 --out ./downloads
48
51
 
49
52
  #### `artdam login`
50
53
 
51
- 登录 ArtDAM,保存 token 到本地 `~/.artdam/config.json`。
54
+ 登录 ArtDAM。默认使用浏览器 SSO,也可使用个人 API Key 或账号密码。
52
55
 
53
56
  ```bash
54
- artdam login
57
+ artdam login # 浏览器 SSO
58
+ artdam login --api-key # 隐藏输入个人 ab_ API Key
59
+ artdam login --password # 账号密码(仅 admin / 服务账号)
55
60
  ```
56
61
 
62
+ `--api-key` 会通过只读的 `GET /api/auth/me` 验证密钥,再保存到
63
+ `~/.artdam/config.json`(Linux/macOS 为 `0600`,Windows 收紧为仅当前用户 ACL)。
64
+ 命令行参数和输出都不会显示密钥。
65
+
66
+ 无人值守脚本和 Agent 可直接使用环境变量,无需执行登录,也不会把密钥写入配置文件:
67
+
68
+ ```bash
69
+ export ARTDAM_API_KEY='ab_...'
70
+ export ARTDAM_BASE_URL='https://artdam.xindong.com' # 可选
71
+ artdam search "头盔" --project 1 --json
72
+ ```
73
+
74
+ 个人 API Key 代表创建它的用户,最终能力始终是**用户在项目中的角色权限 ∩ Key 的权限范围
75
+ (scope)**。例如 viewer 用户即使 Key 含 `write` 也不能上传;只有 `read` 的 Key 不能执行写操作。
76
+
57
77
  #### `artdam search`
58
78
 
59
79
  搜索资产,返回匹配列表。默认只取首页(`--limit` 条);加 `--all` 自动翻页取全部结果
@@ -209,8 +229,8 @@ artdam folders --project 1 --json
209
229
  ### 典型 Agent 工作流
210
230
 
211
231
  ```bash
212
- # 1. 登录(浏览器 SSO 授权)
213
- artdam login
232
+ # 1. 登录(本机可用 SSO;无人值守 Agent 推荐 ARTDAM_API_KEY)
233
+ export ARTDAM_API_KEY='ab_...'
214
234
 
215
235
  # 2. 搜索 → 确认 → 下载
216
236
  artdam search "头盔" --project 1 --json
@@ -231,7 +251,9 @@ artdam update <asset_id> --description "AI 生成的场景描述"
231
251
 
232
252
  - `--project` 参数为**数字 ID**,不是项目名称
233
253
  - `--json` 返回原始 JSON,适合程序解析
234
- - token 保存在 `~/.artdam/config.json`,登录一次长期有效
254
+ - SSO/JWT 或手动输入的 API Key 保存在 `~/.artdam/config.json`,仅当前用户可读写
255
+ - `ARTDAM_API_KEY` 优先于配置文件中的登录凭据,且不会被写入配置或输出
256
+ - API Key 能力受用户项目角色和 Key scope 双重限制
235
257
  - `artdam delete` 是软删除,可用 `artdam restore` 恢复
236
258
 
237
259
  ## 配置文件
@@ -241,6 +263,8 @@ artdam update <asset_id> --description "AI 生成的场景描述"
241
263
  ```json
242
264
  {
243
265
  "base_url": "https://artdam.xindong.com",
244
- "token": "eyJ..."
266
+ "api_key": "ab_..."
245
267
  }
246
268
  ```
269
+
270
+ SSO 或密码登录时凭据字段为 `"token": "eyJ..."`。请勿提交此配置文件或在日志中打印其内容。
@@ -1,246 +1,258 @@
1
- Metadata-Version: 2.4
2
- Name: artdam-cli
3
- Version: 0.4.2
4
- Summary: ArtDAM 数字资产管理平台命令行工具
5
- Requires-Python: >=3.10
6
- Description-Content-Type: text/markdown
7
- Requires-Dist: click>=8.1
8
- Requires-Dist: httpx>=0.27
9
- Requires-Dist: rich>=13.0
10
- Provides-Extra: dev
11
- Requires-Dist: pytest>=8.0; extra == "dev"
12
-
13
- # artdam-cli
14
-
15
- ArtDAM 数字资产管理平台命令行工具,支持所有主流 AI Agent工具接入
16
-
17
- ## 安装
18
-
19
- ```bash
20
- uv tool install artdam-cli
21
- ```
22
-
23
- ## 更新
24
-
25
- ```bash
26
- uv tool install artdam-cli@latest
27
- ```
28
-
29
- ## 快速开始
30
-
31
- ```bash
32
- # 登录(首次使用,浏览器 SSO 授权)
33
- artdam login
34
-
35
- # 搜索资产
36
- artdam search "关键词" --project 1
37
-
38
- # 查看资产详情
39
- artdam get 123
40
-
41
- # 下载资产
42
- artdam download 123 --out ./downloads
43
- ```
44
-
45
- ## 命令说明
46
-
47
- ### 查询命令(viewer 及以上)
48
-
49
- #### `artdam login`
50
-
51
- 登录 ArtDAM,保存 token 到本地 `~/.artdam/config.json`。
52
-
53
- ```bash
54
- artdam login
55
- ```
56
-
57
- #### `artdam search`
58
-
59
- 搜索资产,返回匹配列表。默认只取首页(`--limit` 条);加 `--all` 自动翻页取全部结果
60
- (Agent 场景推荐,避免结果被截断)。`--all` 最多返回 1000 条,超出会提示用更精确的关键词或
61
- `--ext` / `--folder` 收窄,避免在几万条资产上卡死。
62
-
63
- ```bash
64
- artdam search "头盔" --project 1
65
- artdam search "头盔" --project 1 --limit 50
66
- artdam search "头盔" --project 1 --all # 自动翻页,取全部匹配
67
- artdam search "头盔" --project 1 --all --json # 全量 JSON 输出(AI Agent 用)
68
- artdam search "头盔" --project 1 --ext jpg # 按扩展名过滤
69
- artdam search "头盔" --project 1 --ext jpg,png # 多个扩展名
70
- artdam search "头盔" --project 1 --folder 10
71
- ```
72
-
73
- | 参数 | 说明 |
74
- |---|---|
75
- | `KEYWORD` | 搜索关键词 |
76
- | `-p, --project` | 项目 ID(必填) |
77
- | `-n, --limit` | 返回数量上限,默认 20(不与 `--all` 共用) |
78
- | `--all` | 自动翻页取全部匹配结果(最多 1000 条) |
79
- | `-e, --ext` | 按文件扩展名过滤,逗号分隔,如 `jpg,png` |
80
- | `--folder` | 限定文件夹 ID |
81
- | `--json` | 输出原始 JSON |
82
-
83
- #### `artdam get`
84
-
85
- 查看单个资产详情(含预览链接)。
86
-
87
- ```bash
88
- artdam get 123
89
- artdam get 123 --json # 输出原始 JSON(AI Agent 用)
90
- ```
91
-
92
- #### `artdam download`
93
-
94
- 下载资产文件到本地。
95
-
96
- ```bash
97
- artdam download 123
98
- artdam download 123 --out ./downloads
99
- ```
100
-
101
- #### `artdam tags`
102
-
103
- 列出项目标签。
104
-
105
- ```bash
106
- artdam tags --project 1
107
- artdam tags --project 1 --search "角色"
108
- artdam tags --project 1 --json
109
- ```
110
-
111
- #### `artdam folders`
112
-
113
- 查看文件夹结构。
114
-
115
- ```bash
116
- artdam folders --project 1
117
- artdam folders --project 1 --json
118
- ```
119
-
120
- ### 资产管理(member 及以上)
121
-
122
- #### `artdam upload`
123
-
124
- 上传文件到指定项目和文件夹。采用分块上传,支持大文件(最大 10GB),带进度条;
125
- 上传前按内容计算 SHA-256,库中已有相同文件则**秒传**(直接复用,不重复传输)。
126
- 单个分块遇到网络抖动(超时 / 5xx)会自动重试,中断时清理服务端会话。
127
-
128
- ```bash
129
- artdam upload ./image.jpg --project 1
130
- artdam upload ./image.jpg --project 1 --folder 10
131
- artdam upload ./big_scene.zip --project 1 # 大文件分块 + 进度条
132
- ```
133
-
134
- #### `artdam update`
135
-
136
- 更新资产信息(可同时传多个选项)。
137
-
138
- ```bash
139
- artdam update 123 --name "新文件名"
140
- artdam update 123 --description "新描述"
141
- artdam update 123 --folder 10
142
- ```
143
-
144
- #### `artdam delete`
145
-
146
- 软删除资产(可通过 `restore` 恢复)。
147
-
148
- ```bash
149
- artdam delete 123
150
- ```
151
-
152
- #### `artdam restore`
153
-
154
- 恢复已删除的资产。
155
-
156
- ```bash
157
- artdam restore 123
158
- ```
159
-
160
- ### 标签管理(member 及以上)
161
-
162
- ```bash
163
- # 给资产添加标签
164
- artdam tag add 123 5
165
-
166
- # 从资产移除标签
167
- artdam tag remove 123 5
168
-
169
- # 创建新标签
170
- artdam tag create "标签名" --project 1
171
- ```
172
-
173
- ### 文件夹管理(member 及以上)
174
-
175
- ```bash
176
- # 创建文件夹
177
- artdam folder create "文件夹名" --project 1
178
- artdam folder create "子文件夹" --project 1 --parent 10
179
-
180
- # 删除文件夹
181
- artdam folder delete 10
182
- ```
183
-
184
- ### 互动操作(member 及以上)
185
-
186
- ```bash
187
- # 评论
188
- artdam comment 123 "评论内容"
189
-
190
- # 评分(1-5 星)
191
- artdam rate 123 4
192
-
193
- # 收藏 / 取消收藏
194
- artdam favorite 123
195
- artdam favorite 123 --remove
196
- ```
197
-
198
- ## AI Agent 使用指南
199
-
200
- 所有查询命令支持 `--json` 输出原始 JSON,适合 Agent 解析:
201
-
202
- ```bash
203
- artdam search "安妮" --project 1 --json
204
- artdam get 123 --json
205
- artdam tags --project 1 --json
206
- artdam folders --project 1 --json
207
- ```
208
-
209
- ### 典型 Agent 工作流
210
-
211
- ```bash
212
- # 1. 登录(浏览器 SSO 授权)
213
- artdam login
214
-
215
- # 2. 搜索 → 确认 → 下载
216
- artdam search "头盔" --project 1 --json
217
- artdam get 50707 --json
218
- artdam download 50707 --out ./assets
219
-
220
- # 3. 搜索 → 批量打标签
221
- artdam search "安妮" --project 1 --json
222
- artdam tag add 50707 5
223
- artdam tag add 50708 5
224
-
225
- # 4. 上传并更新描述
226
- artdam upload ./new_asset.jpg --project 1 --folder 10
227
- artdam update <asset_id> --description "AI 生成的场景描述"
228
- ```
229
-
230
- ## 注意事项
231
-
232
- - `--project` 参数为**数字 ID**,不是项目名称
233
- - `--json` 返回原始 JSON,适合程序解析
234
- - token 保存在 `~/.artdam/config.json`,登录一次长期有效
235
- - `artdam delete` 是软删除,可用 `artdam restore` 恢复
236
-
237
- ## 配置文件
238
-
239
- 登录信息保存在 `~/.artdam/config.json`:
240
-
241
- ```json
242
- {
243
- "base_url": "https://artdam.xindong.com",
244
- "token": "eyJ..."
245
- }
246
- ```
1
+ # artdam-cli
2
+
3
+ ArtDAM 数字资产管理平台命令行工具,支持所有主流 AI Agent工具接入
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ uv tool install artdam-cli
9
+ ```
10
+
11
+ ## 更新
12
+
13
+ ```bash
14
+ uv tool install artdam-cli@latest
15
+ ```
16
+
17
+ ## 快速开始
18
+
19
+ ```bash
20
+ # 登录(首次使用,浏览器 SSO 授权)
21
+ artdam login
22
+
23
+ # 个人 API Key 登录(隐藏输入,适合本机长期使用)
24
+ artdam login --api-key
25
+
26
+ # 搜索资产
27
+ artdam search "关键词" --project 1
28
+
29
+ # 查看资产详情
30
+ artdam get 123
31
+
32
+ # 下载资产
33
+ artdam download 123 --out ./downloads
34
+ ```
35
+
36
+ ## 命令说明
37
+
38
+ ### 查询命令(viewer 及以上)
39
+
40
+ #### `artdam login`
41
+
42
+ 登录 ArtDAM。默认使用浏览器 SSO,也可使用个人 API Key 或账号密码。
43
+
44
+ ```bash
45
+ artdam login # 浏览器 SSO
46
+ artdam login --api-key # 隐藏输入个人 ab_ API Key
47
+ artdam login --password # 账号密码(仅 admin / 服务账号)
48
+ ```
49
+
50
+ `--api-key` 会通过只读的 `GET /api/auth/me` 验证密钥,再保存到
51
+ `~/.artdam/config.json`(Linux/macOS 为 `0600`,Windows 收紧为仅当前用户 ACL)。
52
+ 命令行参数和输出都不会显示密钥。
53
+
54
+ 无人值守脚本和 Agent 可直接使用环境变量,无需执行登录,也不会把密钥写入配置文件:
55
+
56
+ ```bash
57
+ export ARTDAM_API_KEY='ab_...'
58
+ export ARTDAM_BASE_URL='https://artdam.xindong.com' # 可选
59
+ artdam search "头盔" --project 1 --json
60
+ ```
61
+
62
+ 个人 API Key 代表创建它的用户,最终能力始终是**用户在项目中的角色权限 ∩ Key 的权限范围
63
+ (scope)**。例如 viewer 用户即使 Key 含 `write` 也不能上传;只有 `read` 的 Key 不能执行写操作。
64
+
65
+ #### `artdam search`
66
+
67
+ 搜索资产,返回匹配列表。默认只取首页(`--limit` 条);加 `--all` 自动翻页取全部结果
68
+ (Agent 场景推荐,避免结果被截断)。`--all` 最多返回 1000 条,超出会提示用更精确的关键词或
69
+ `--ext` / `--folder` 收窄,避免在几万条资产上卡死。
70
+
71
+ ```bash
72
+ artdam search "头盔" --project 1
73
+ artdam search "头盔" --project 1 --limit 50
74
+ artdam search "头盔" --project 1 --all # 自动翻页,取全部匹配
75
+ artdam search "头盔" --project 1 --all --json # 全量 JSON 输出(AI Agent 用)
76
+ artdam search "头盔" --project 1 --ext jpg # 按扩展名过滤
77
+ artdam search "头盔" --project 1 --ext jpg,png # 多个扩展名
78
+ artdam search "头盔" --project 1 --folder 10
79
+ ```
80
+
81
+ | 参数 | 说明 |
82
+ |---|---|
83
+ | `KEYWORD` | 搜索关键词 |
84
+ | `-p, --project` | 项目 ID(必填) |
85
+ | `-n, --limit` | 返回数量上限,默认 20(不与 `--all` 共用) |
86
+ | `--all` | 自动翻页取全部匹配结果(最多 1000 条) |
87
+ | `-e, --ext` | 按文件扩展名过滤,逗号分隔,如 `jpg,png` |
88
+ | `--folder` | 限定文件夹 ID |
89
+ | `--json` | 输出原始 JSON |
90
+
91
+ #### `artdam get`
92
+
93
+ 查看单个资产详情(含预览链接)。
94
+
95
+ ```bash
96
+ artdam get 123
97
+ artdam get 123 --json # 输出原始 JSON(AI Agent 用)
98
+ ```
99
+
100
+ #### `artdam download`
101
+
102
+ 下载资产文件到本地。
103
+
104
+ ```bash
105
+ artdam download 123
106
+ artdam download 123 --out ./downloads
107
+ ```
108
+
109
+ #### `artdam tags`
110
+
111
+ 列出项目标签。
112
+
113
+ ```bash
114
+ artdam tags --project 1
115
+ artdam tags --project 1 --search "角色"
116
+ artdam tags --project 1 --json
117
+ ```
118
+
119
+ #### `artdam folders`
120
+
121
+ 查看文件夹结构。
122
+
123
+ ```bash
124
+ artdam folders --project 1
125
+ artdam folders --project 1 --json
126
+ ```
127
+
128
+ ### 资产管理(member 及以上)
129
+
130
+ #### `artdam upload`
131
+
132
+ 上传文件到指定项目和文件夹。采用分块上传,支持大文件(最大 10GB),带进度条;
133
+ 上传前按内容计算 SHA-256,库中已有相同文件则**秒传**(直接复用,不重复传输)。
134
+ 单个分块遇到网络抖动(超时 / 5xx)会自动重试,中断时清理服务端会话。
135
+
136
+ ```bash
137
+ artdam upload ./image.jpg --project 1
138
+ artdam upload ./image.jpg --project 1 --folder 10
139
+ artdam upload ./big_scene.zip --project 1 # 大文件分块 + 进度条
140
+ ```
141
+
142
+ #### `artdam update`
143
+
144
+ 更新资产信息(可同时传多个选项)。
145
+
146
+ ```bash
147
+ artdam update 123 --name "新文件名"
148
+ artdam update 123 --description "新描述"
149
+ artdam update 123 --folder 10
150
+ ```
151
+
152
+ #### `artdam delete`
153
+
154
+ 软删除资产(可通过 `restore` 恢复)。
155
+
156
+ ```bash
157
+ artdam delete 123
158
+ ```
159
+
160
+ #### `artdam restore`
161
+
162
+ 恢复已删除的资产。
163
+
164
+ ```bash
165
+ artdam restore 123
166
+ ```
167
+
168
+ ### 标签管理(member 及以上)
169
+
170
+ ```bash
171
+ # 给资产添加标签
172
+ artdam tag add 123 5
173
+
174
+ # 从资产移除标签
175
+ artdam tag remove 123 5
176
+
177
+ # 创建新标签
178
+ artdam tag create "标签名" --project 1
179
+ ```
180
+
181
+ ### 文件夹管理(member 及以上)
182
+
183
+ ```bash
184
+ # 创建文件夹
185
+ artdam folder create "文件夹名" --project 1
186
+ artdam folder create "子文件夹" --project 1 --parent 10
187
+
188
+ # 删除文件夹
189
+ artdam folder delete 10
190
+ ```
191
+
192
+ ### 互动操作(member 及以上)
193
+
194
+ ```bash
195
+ # 评论
196
+ artdam comment 123 "评论内容"
197
+
198
+ # 评分(1-5 星)
199
+ artdam rate 123 4
200
+
201
+ # 收藏 / 取消收藏
202
+ artdam favorite 123
203
+ artdam favorite 123 --remove
204
+ ```
205
+
206
+ ## AI Agent 使用指南
207
+
208
+ 所有查询命令支持 `--json` 输出原始 JSON,适合 Agent 解析:
209
+
210
+ ```bash
211
+ artdam search "安妮" --project 1 --json
212
+ artdam get 123 --json
213
+ artdam tags --project 1 --json
214
+ artdam folders --project 1 --json
215
+ ```
216
+
217
+ ### 典型 Agent 工作流
218
+
219
+ ```bash
220
+ # 1. 登录(本机可用 SSO;无人值守 Agent 推荐 ARTDAM_API_KEY)
221
+ export ARTDAM_API_KEY='ab_...'
222
+
223
+ # 2. 搜索 → 确认 → 下载
224
+ artdam search "头盔" --project 1 --json
225
+ artdam get 50707 --json
226
+ artdam download 50707 --out ./assets
227
+
228
+ # 3. 搜索 → 批量打标签
229
+ artdam search "安妮" --project 1 --json
230
+ artdam tag add 50707 5
231
+ artdam tag add 50708 5
232
+
233
+ # 4. 上传并更新描述
234
+ artdam upload ./new_asset.jpg --project 1 --folder 10
235
+ artdam update <asset_id> --description "AI 生成的场景描述"
236
+ ```
237
+
238
+ ## 注意事项
239
+
240
+ - `--project` 参数为**数字 ID**,不是项目名称
241
+ - `--json` 返回原始 JSON,适合程序解析
242
+ - SSO/JWT 或手动输入的 API Key 保存在 `~/.artdam/config.json`,仅当前用户可读写
243
+ - `ARTDAM_API_KEY` 优先于配置文件中的登录凭据,且不会被写入配置或输出
244
+ - API Key 能力受用户项目角色和 Key scope 双重限制
245
+ - `artdam delete` 是软删除,可用 `artdam restore` 恢复
246
+
247
+ ## 配置文件
248
+
249
+ 登录信息保存在 `~/.artdam/config.json`:
250
+
251
+ ```json
252
+ {
253
+ "base_url": "https://artdam.xindong.com",
254
+ "api_key": "ab_..."
255
+ }
256
+ ```
257
+
258
+ SSO 或密码登录时凭据字段为 `"token": "eyJ..."`。请勿提交此配置文件或在日志中打印其内容。
@@ -12,11 +12,11 @@ _RETRY_BACKOFF = (1, 2, 4)
12
12
 
13
13
 
14
14
  def _make_client(timeout: float = 30) -> httpx.Client:
15
- base_url = config.require("base_url")
16
- token = config.require("token")
15
+ base_url = config.get_base_url()
16
+ credential = config.get_auth_credential()
17
17
  return httpx.Client(
18
18
  base_url=base_url,
19
- headers={"Authorization": f"Bearer {token}"},
19
+ headers={"Authorization": f"Bearer {credential}"},
20
20
  timeout=timeout,
21
21
  )
22
22
 
@@ -39,7 +39,9 @@ def _send_with_retry(do_request: Callable[[], httpx.Response]) -> httpx.Response
39
39
  return r
40
40
 
41
41
 
42
- def get(path: str, params: dict | None = None, not_found_msg: str = "资源不存在") -> dict:
42
+ def get(
43
+ path: str, params: dict | None = None, not_found_msg: str = "资源不存在"
44
+ ) -> dict:
43
45
  with _make_client() as c:
44
46
  r = c.get(path, params=params)
45
47
  _raise(r, not_found_msg=not_found_msg)
@@ -47,12 +49,12 @@ def get(path: str, params: dict | None = None, not_found_msg: str = "资源不
47
49
 
48
50
 
49
51
  def download_file(path: str, dest: str, not_found_msg: str = "资源不存在") -> int:
50
- base_url = config.require("base_url")
51
- token = config.require("token")
52
+ base_url = config.get_base_url()
53
+ credential = config.get_auth_credential()
52
54
  with httpx.stream(
53
55
  "GET",
54
56
  f"{base_url}{path}",
55
- headers={"Authorization": f"Bearer {token}"},
57
+ headers={"Authorization": f"Bearer {credential}"},
56
58
  timeout=120,
57
59
  follow_redirects=True,
58
60
  ) as r:
@@ -165,7 +167,12 @@ def cancel_upload(upload_id: str) -> None:
165
167
 
166
168
  def _raise(r: httpx.Response, not_found_msg: str = "资源不存在") -> None:
167
169
  if r.status_code == 401:
168
- raise SystemExit("Token 无效或已过期,请重新运行 artdam login")
170
+ raise SystemExit("登录凭据无效或已过期,请重新运行 artdam login")
171
+ if r.status_code == 403:
172
+ raise SystemExit(
173
+ "权限不足:请检查当前用户的项目角色;"
174
+ "使用个人 API Key 时还需检查密钥的权限范围"
175
+ )
169
176
  if r.status_code == 404:
170
177
  raise SystemExit(not_found_msg)
171
178
  if r.is_error:
@@ -113,7 +113,7 @@ def _stop_running_agent() -> None:
113
113
 
114
114
  def _write_autostart(install_dir: Path, venv_py: Path, webserver: Path) -> Path:
115
115
  """写 run-agent.ps1 + 开机自启 .vbs(启动文件夹,免管理员),返回 .vbs 路径。"""
116
- base_url = config.require("base_url")
116
+ base_url = config.get_base_url()
117
117
  run_script = install_dir / "run-agent.ps1"
118
118
  lines = [
119
119
  f'$env:ARTDAM_AGENT_WEBSERVER_EXE = "{webserver}"',
@@ -273,7 +273,7 @@ def install(project: str) -> None:
273
273
  f"暂不支持的项目代号:{project}。"
274
274
  f"目前支持:{', '.join(sorted(_SUPPORTED_PROJECTS))}。"
275
275
  )
276
- base_url = config.require("base_url")
276
+ base_url = config.get_base_url()
277
277
  install_dir = _install_dir()
278
278
  uv = _find_uv()
279
279
  console.print(f"[cyan]→[/cyan] 安装目录:{install_dir}")