agent-toolkit-cli 1.0.0 → 1.0.1

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 (2) hide show
  1. package/deploy-cli/bin/demo +130 -0
  2. package/package.json +1 -1
@@ -45,6 +45,16 @@ ensure_vercel() {
45
45
  fi
46
46
  }
47
47
 
48
+ ensure_command() {
49
+ local cmd="${1:-}"
50
+ local install_hint="${2:-}"
51
+ if ! command -v "$cmd" &>/dev/null; then
52
+ print_error "缺少命令: $cmd"
53
+ [[ -n "$install_hint" ]] && echo "$install_hint"
54
+ exit 1
55
+ fi
56
+ }
57
+
48
58
  mask_secret() {
49
59
  local value="${1:-}"
50
60
  local prefix_len="${2:-8}"
@@ -88,6 +98,7 @@ ${BOLD}Agent Toolkit CLI${RESET} v${VERSION}
88
98
 
89
99
  ${BOLD}用法:${RESET}
90
100
  ${CLI_NAME} deploy [目录] [选项] 部署项目
101
+ ${CLI_NAME} storage upload <文件> 上传文件到对象存储并返回 URL
91
102
  ${CLI_NAME} env 查看当前部署环境配置
92
103
  ${CLI_NAME} help 显示帮助信息
93
104
  ${CLI_NAME} version 显示版本
@@ -101,6 +112,8 @@ ${BOLD}示例:${RESET}
101
112
  ${CLI_NAME} deploy 部署当前目录
102
113
  ${CLI_NAME} deploy ./my-app --prod 部署 my-app 到生产环境
103
114
  ${CLI_NAME} deploy . --prod --yes 部署到生产环境并跳过确认
115
+ ${CLI_NAME} storage upload ./a.png --bucket images
116
+ ${CLI_NAME} storage upload ./a.png --bucket images --path demo/a.png
104
117
 
105
118
  EOF
106
119
  }
@@ -206,6 +219,122 @@ cmd_env() {
206
219
  fi
207
220
  }
208
221
 
222
+ # ─── storage upload 命令 ───
223
+ cmd_storage_upload() {
224
+ local file_path=""
225
+ local bucket=""
226
+ local object_path=""
227
+ local upsert="true"
228
+
229
+ while [[ $# -gt 0 ]]; do
230
+ case "$1" in
231
+ --bucket)
232
+ bucket="${2:-}"
233
+ shift 2
234
+ ;;
235
+ --path)
236
+ object_path="${2:-}"
237
+ shift 2
238
+ ;;
239
+ --upsert)
240
+ upsert="${2:-true}"
241
+ shift 2
242
+ ;;
243
+ --help|-h)
244
+ echo "用法: ${CLI_NAME} storage upload <文件> --bucket <bucket> [--path <对象路径>] [--upsert true|false]"
245
+ exit 0
246
+ ;;
247
+ -*)
248
+ print_error "未知选项: $1"
249
+ exit 1
250
+ ;;
251
+ *)
252
+ if [[ -z "$file_path" ]]; then
253
+ file_path="$1"
254
+ else
255
+ print_error "参数过多: $1"
256
+ exit 1
257
+ fi
258
+ shift
259
+ ;;
260
+ esac
261
+ done
262
+
263
+ if [[ -z "$file_path" ]]; then
264
+ print_error "请传入文件路径"
265
+ exit 1
266
+ fi
267
+ if [[ ! -f "$file_path" ]]; then
268
+ print_error "文件不存在: $file_path"
269
+ exit 1
270
+ fi
271
+ if [[ -z "$bucket" ]]; then
272
+ print_error "请通过 --bucket 指定 bucket 名称"
273
+ exit 1
274
+ fi
275
+
276
+ load_env ".env"
277
+ load_builtin_credentials
278
+
279
+ if [[ -z "${SUPABASE_URL:-}" || -z "${SUPABASE_SERVICE_ROLE_KEY:-}" ]]; then
280
+ print_error "缺少对象存储凭证,请检查 SUPABASE_URL 和 SUPABASE_SERVICE_ROLE_KEY"
281
+ exit 1
282
+ fi
283
+
284
+ ensure_command "curl" "请先安装 curl 后重试。"
285
+
286
+ local filename
287
+ filename="$(basename "$file_path")"
288
+ if [[ -z "$object_path" ]]; then
289
+ object_path="$(date +%s)-${filename}"
290
+ fi
291
+
292
+ local upload_url="${SUPABASE_URL%/}/storage/v1/object/${bucket}/${object_path}"
293
+ local response http_code body
294
+
295
+ print_info "正在上传文件到 ${bucket}/${object_path} ..."
296
+ response="$(curl --silent --show-error \
297
+ --request POST \
298
+ --url "$upload_url" \
299
+ --header "Authorization: Bearer ${SUPABASE_SERVICE_ROLE_KEY}" \
300
+ --header "apikey: ${SUPABASE_SERVICE_ROLE_KEY}" \
301
+ --header "x-upsert: ${upsert}" \
302
+ --header "Content-Type: application/octet-stream" \
303
+ --data-binary "@${file_path}" \
304
+ --write-out $'\n%{http_code}')" || {
305
+ print_error "上传请求失败"
306
+ exit 1
307
+ }
308
+
309
+ http_code="${response##*$'\n'}"
310
+ body="${response%$'\n'*}"
311
+ if [[ ! "$http_code" =~ ^2 ]]; then
312
+ print_error "上传失败(HTTP ${http_code})"
313
+ [[ -n "$body" ]] && echo "$body" >&2
314
+ exit 1
315
+ fi
316
+
317
+ local public_url="${SUPABASE_URL%/}/storage/v1/object/public/${bucket}/${object_path}"
318
+ print_success "上传成功"
319
+ echo "URL: ${public_url}"
320
+ }
321
+
322
+ cmd_storage() {
323
+ local subcommand="${1:-}"
324
+ shift || true
325
+
326
+ case "$subcommand" in
327
+ upload) cmd_storage_upload "$@" ;;
328
+ ""|--help|-h)
329
+ echo "用法: ${CLI_NAME} storage upload <文件> --bucket <bucket> [--path <对象路径>] [--upsert true|false]"
330
+ ;;
331
+ *)
332
+ print_error "未知 storage 子命令: $subcommand"
333
+ exit 1
334
+ ;;
335
+ esac
336
+ }
337
+
209
338
  # ─── 主入口 ───
210
339
  main() {
211
340
  if [[ $# -eq 0 ]]; then
@@ -218,6 +347,7 @@ main() {
218
347
 
219
348
  case "$command" in
220
349
  deploy) cmd_deploy "$@" ;;
350
+ storage) cmd_storage "$@" ;;
221
351
  env) cmd_env ;;
222
352
  help) show_help ;;
223
353
  version) show_version ;;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-toolkit-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "一键部署你的项目",
5
5
  "bin": {
6
6
  "agent-toolkit-cli": "deploy-cli/bin/demo",