@optima-chat/optima-agent 0.8.6 → 0.8.8

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.
@@ -56,12 +56,16 @@ Homepage
56
56
  **images 数组元素**:
57
57
  | 字段 | 必填 | 说明 |
58
58
  |------|------|------|
59
- | url | | 桌面端图片 URL |
59
+ | url | | 桌面端图片 URL(url 或 media_id 至少一个) |
60
+ | media_id | △ | 桌面端已有图片 ID(从 homepage get 获取,用于 update-images 全量替换) |
60
61
  | mobile_url | | 手机端专用图片 URL(3:4 竖向,可选) |
62
+ | mobile_media_id | | 手机端已有图片 ID(从 homepage get 获取,用于 update-images 全量替换) |
61
63
  | alt | ✓ | 图片描述(SEO + 可访问性) |
62
64
  | action_type | ✓ | 点击动作类型(见下方) |
63
65
  | action_value | | 动作目标值 |
64
66
 
67
+ > △ = url 和 media_id 至少提供一个。新上传的图使用 url,已有的图使用 media_id。
68
+
65
69
  **action_type 取值**:
66
70
  | 值 | 说明 | action_value |
67
71
  |----|------|--------------|
@@ -71,13 +75,24 @@ Homepage
71
75
  | `url` | 跳转到 URL | 完整 URL 或相对路径 |
72
76
  | `section` | 滚动到页面区块 | section handle |
73
77
 
74
- **示例**:
78
+ **创建时的示例**(使用 url):
75
79
  ```json
76
80
  {
77
81
  "images": [
78
82
  {"url": "https://cdn.../summer.jpg", "mobile_url": "https://cdn.../summer-mobile.jpg", "alt": "夏日促销", "action_type": "collection", "action_value": "summer-sale"},
79
- {"url": "https://cdn.../promo.jpg", "alt": "活动页面", "action_type": "url", "action_value": "https://promo.example.com/event"},
80
- {"url": "https://cdn.../hero.jpg", "alt": "品牌形象", "action_type": "none", "action_value": null}
83
+ {"url": "https://cdn.../promo.jpg", "alt": "活动页面", "action_type": "url", "action_value": "https://promo.example.com/event"}
84
+ ],
85
+ "autoplay": true,
86
+ "interval": 5000
87
+ }
88
+ ```
89
+
90
+ **`homepage get` 返回的真实格式**(url 已被后端自动转为 media_id):
91
+ ```json
92
+ {
93
+ "images": [
94
+ {"media_id": "med_abc123", "mobile_media_id": "med_def456", "alt": "夏日促销", "action_type": "collection", "action_value": "summer-sale"},
95
+ {"media_id": "med_ghi789", "alt": "活动页面", "action_type": "url", "action_value": "https://promo.example.com/event"}
81
96
  ],
82
97
  "autoplay": true,
83
98
  "interval": 5000
@@ -174,6 +189,9 @@ Homepage
174
189
  - "添加集合商品" → `commerce homepage create-collection-products --title "新品" --lang <识别语言> --slug new-arrivals`
175
190
  - "添加特色推荐" → `commerce homepage create-featured --title "推荐" --lang <识别语言> --target-type collection --target-handle xx --cta "查看" --image-url "..."`
176
191
  - "更新轮播图图片" → `commerce homepage update-images --id xx --images '[...]'`
192
+ - "给第N张 banner 加手机图" → `commerce homepage patch-banner-image --id xx --index N --mobile-url "https://..."`
193
+ - "改第N张图的描述" → `commerce homepage patch-banner-image --id xx --index N --alt "新描述"`
194
+ - "移除第N张图的手机版" → `commerce homepage patch-banner-image --id xx --index N --remove-mobile-url`
177
195
  - "修改区块标题" → `commerce i18n homepage set --section-id xx --lang <识别语言> --title "新标题"`
178
196
  - "给区块添加描述" → `commerce i18n homepage set --section-id xx --lang <识别语言> --description "描述"`
179
197
  - "调整区块顺序" → `commerce homepage reorder --moves '[{"section_id":"id1","new_position":0}]'`
@@ -202,7 +220,8 @@ Homepage
202
220
  - `commerce homepage reorder --moves <json>` - 重新排序(JSON 格式:`[{"section_id":"xx","new_position":0}]`)
203
221
 
204
222
  ### 区块设置
205
- - `commerce homepage update-images --id <id> --images <json>` - 更新 banner 图片
223
+ - `commerce homepage update-images --id <id> --images <json>` - 全量替换 banner 图片(支持 url 或 media_id)
224
+ - `commerce homepage patch-banner-image --id <id> --index <N> [--url <url>] [--mobile-url <url>] [--remove-mobile-url] [--alt <text>] [--action-type <type>] [--action-value <value>]` - 更新单张 banner 图片(index 从 1 开始)
206
225
  - `commerce homepage update-collections --id <id> --slugs <slugs>` - 更新 collections 集合
207
226
  - `commerce homepage update-target --id <id> --type <type> --handle <handle>` - 更新 featured 目标
208
227
  - `commerce homepage patch-settings --id <id> --settings <json>` - 通用设置更新
@@ -316,11 +335,43 @@ commerce i18n homepage set \
316
335
  --description "New description"
317
336
  ```
318
337
 
338
+ ## Banner 图片更新:命令选择指南
339
+
340
+ | 我要做什么 | 用哪个命令 | 说明 |
341
+ |-----------|-----------|------|
342
+ | 给第 N 张图加/换手机版 | `patch-banner-image --index N --mobile-url "https://..."` | 最简单,无需读取现有数据 |
343
+ | 改第 N 张图的 alt/action | `patch-banner-image --index N --alt "..."` | 同上 |
344
+ | 换第 N 张桌面图(新 URL) | `patch-banner-image --index N --url "https://..."` | 后端自动转 media_id |
345
+ | 移除第 N 张图的手机版 | `patch-banner-image --index N --remove-mobile-url` | 设为 null |
346
+ | 添加/删除图片 | `update-images --images '[完整数组]'` | 全量替换,需透传所有现有字段 |
347
+ | 重新排列图片顺序 | `update-images --images '[新顺序数组]'` | 同上 |
348
+
349
+ **关键区别**:
350
+ - `patch-banner-image` 只接受 URL(`--url`, `--mobile-url`),不接受 `media_id`。后端自动将 URL 转为 media_id
351
+ - `update-images` 接受 `url` 和 `media_id`。已有的图用 `media_id` 透传,新图用 `url`
352
+
353
+ ### update-images 全量替换示例(含 media_id 透传)
354
+
355
+ **场景**:给已有的 2 张 banner 增加第 3 张图
356
+
357
+ 1. 先 `commerce homepage get --id section_xxx` 获取现有图片(含 media_id)
358
+ 2. 构建完整数组,已有图原样透传 media_id,新图用 url:
359
+
360
+ ```bash
361
+ commerce homepage update-images --id section_xxx --images '[
362
+ {"media_id":"med_abc123","mobile_media_id":"med_def456","alt":"夏日促销","action_type":"collection","action_value":"summer-sale"},
363
+ {"media_id":"med_ghi789","alt":"活动页面","action_type":"url","action_value":"https://promo.example.com/event"},
364
+ {"url":"https://new-upload-url.../img3.jpg","alt":"新图片","action_type":"none"}
365
+ ]'
366
+ ```
367
+
368
+ **注意:全量替换会覆盖整个 images 数组。漏传的字段(如 `mobile_media_id`)会导致手机图丢失。务必从 `homepage get` 完整复制现有图片的所有字段。**
369
+
319
370
  ## 注意事项
320
371
 
321
372
  - **区块顺序**:使用 `reorder` 调整,position 从 0 开始
322
373
  - **模板切换**:会创建新区块并停用旧区块,谨慎操作
323
- - **图片格式**:banner images 需要完整的 JSON 数组,每个元素必须有 url alt
374
+ - **media_id 生命周期**:上传图片(`upload file`)→ 返回临时 URL(无 media_id)→ 传给 banner API 后端自动转为 media_id 后续 `homepage get` 返回 media_id
324
375
  - **手机端图片**:可选提供 mobile_url(3:4 竖向),有 mobile_url 时手机端显示竖向大图,无则保持 16:9 横向
325
376
  - **集合引用**:确保引用的 collection slug 存在,否则前端可能显示空
326
377
  - **删除确认**:删除操作需要 `--yes` 参数
@@ -17,7 +17,7 @@ commerce upload image --path ./tshirt-main.jpg # 获得 media_123
17
17
 
18
18
  # 2. 创建商品
19
19
  commerce product create \
20
- --title "纯棉T恤" \
20
+ --name "纯棉T恤" \
21
21
  --price 99 \
22
22
  --stock 20 \
23
23
  --description "100% 纯棉,舒适透气" \
@@ -28,7 +28,7 @@ commerce product create \
28
28
  **流程**: 创建主商品 → 创建所有变体 → 关联图片
29
29
  ```bash
30
30
  # 1. 创建主商品
31
- commerce product create --title "T恤" --price 99
31
+ commerce product create --name "T恤" --price 99
32
32
  # 获得 product_id: prod_123
33
33
 
34
34
  # 2. 创建所有变体
@@ -48,7 +48,7 @@ commerce upload image --path ./brand-logo.jpg # 获得 media_shared
48
48
 
49
49
  # 2. 批量创建商品(复用media_id)
50
50
  for product in "T恤" "衬衫" "卫衣"; do
51
- commerce product create --title "$product" --price 99 --media-id media_shared
51
+ commerce product create --name "$product" --price 99 --media-id media_shared
52
52
  done
53
53
  ```
54
54
 
@@ -78,7 +78,7 @@ commerce product add-images --id prod_123 --media-id media_new
78
78
  ```bash
79
79
  # 创建促销商品:售价79,原价99(显示划线价)
80
80
  commerce product create \
81
- --title "夏日特惠T恤" \
81
+ --name "夏日特惠T恤" \
82
82
  --price 79 \
83
83
  --original-price 99 \
84
84
  --stock 100 \
@@ -143,7 +143,7 @@ commerce product create \
143
143
  # 每个商品都上传相同的logo
144
144
  for product in products; do
145
145
  commerce upload image --path ./logo.jpg
146
- commerce product create --title "$product" --media-id $NEW_ID
146
+ commerce product create --name "$product" --media-id $NEW_ID
147
147
  done
148
148
  ```
149
149
 
@@ -152,7 +152,7 @@ done
152
152
  # 先上传一次,复用media_id
153
153
  commerce upload image --path ./logo.jpg # 获得 media_123
154
154
  for product in products; do
155
- commerce product create --title "$product" --media-id media_123
155
+ commerce product create --name "$product" --media-id media_123
156
156
  done
157
157
  ```
158
158
 
@@ -162,10 +162,10 @@ done
162
162
 
163
163
  ```bash
164
164
  # 错误:只创建主商品
165
- commerce product create --title "T恤" --price 99
165
+ commerce product create --name "T恤" --price 99
166
166
 
167
167
  # 正确:创建主商品 + 所有变体
168
- commerce product create --title "T恤" --price 99 # 获得 prod_123
168
+ commerce product create --name "T恤" --price 99 # 获得 prod_123
169
169
  commerce variant create --product-id prod_123 --sku "TSHIRT-RED-S" ...
170
170
  commerce variant create --product-id prod_123 --sku "TSHIRT-RED-M" ...
171
171
  ```
@@ -203,7 +203,7 @@ commerce product update --id prod_123 --tags "featured,new,sale"
203
203
 
204
204
  ```bash
205
205
  # 先确认真实库存,再创建
206
- commerce product create --title "T恤" --price 99 --stock 50 # 确保真实有50件
206
+ commerce product create --name "T恤" --price 99 --stock 50 # 确保真实有50件
207
207
  ```
208
208
 
209
209
  ## 命令参考
@@ -211,9 +211,9 @@ commerce product create --title "T恤" --price 99 --stock 50 # 确保真实有5
211
211
  ### 自然语言映射
212
212
 
213
213
  当用户说:
214
- - "创建XX商品,价格YY" → `commerce product create --title XX --price YY`
215
- - "创建XX商品,售价YY,原价ZZ" → `commerce product create --title XX --price YY --original-price ZZ`
216
- - "创建促销商品,价格79,划线价99" → `commerce product create --title XX --price 79 --original-price 99`
214
+ - "创建XX商品,价格YY" → `commerce product create --name XX --price YY`
215
+ - "创建XX商品,售价YY,原价ZZ" → `commerce product create --name XX --price YY --original-price ZZ`
216
+ - "创建促销商品,价格79,划线价99" → `commerce product create --name XX --price 79 --original-price 99`
217
217
  - "上传商品图片" → `commerce upload image --path ./photo.jpg`
218
218
  - "添加商品变体" → `commerce variant create --product-id XX --sku YY`
219
219
  - "更新商品价格" → `commerce product update --id XX --price YY`
@@ -249,7 +249,7 @@ commerce product create --title "T恤" --price 99 --stock 50 # 确保真实有5
249
249
  # 用户说:"创建T恤商品,99美元,库存20"
250
250
  # 描述支持 Markdown 格式
251
251
  commerce product create \
252
- --title "T恤" \
252
+ --name "T恤" \
253
253
  --price 99 \
254
254
  --stock 20 \
255
255
  --description "## 产品特点
@@ -314,7 +314,7 @@ commerce upload image --path ./tshirt-red.jpg # media_red
314
314
  commerce upload image --path ./tshirt-blue.jpg # media_blue
315
315
 
316
316
  # 2. 创建主商品
317
- commerce product create --title "纯棉T恤" --price 99
317
+ commerce product create --name "纯棉T恤" --price 99
318
318
  # 获得 product_id: prod_123
319
319
 
320
320
  # 3. 创建变体
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optima-chat/optima-agent",
3
- "version": "0.8.6",
3
+ "version": "0.8.8",
4
4
  "description": "基于 Claude Agent SDK 的电商运营 AI 助手",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",