goofish-cli 0.6.4__tar.gz → 0.6.6__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 (92) hide show
  1. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/.claude-plugin/marketplace.json +1 -1
  2. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/CHANGELOG.md +14 -0
  3. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/PKG-INFO +2 -2
  4. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/README.md +1 -1
  5. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/pyproject.toml +1 -1
  6. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-publish-item/SKILL.md +1 -1
  7. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-publish-item/references/category-selection.md +2 -2
  8. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/category/recommend.py +37 -21
  9. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/item/publish.py +4 -3
  10. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/message/send.py +18 -1
  11. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/ws.py +33 -0
  12. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/.gitignore +0 -0
  13. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/LICENSE +0 -0
  14. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/NOTICE +0 -0
  15. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/examples/README.md +0 -0
  16. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-overview/SKILL.md +0 -0
  17. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-overview/references/accounts.md +0 -0
  18. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-overview/references/mcp-tools-index.md +0 -0
  19. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-overview/references/xianyu-concepts.md +0 -0
  20. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-publish-item/references/common-pitfalls.md +0 -0
  21. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-publish-item/references/image-checklist.md +0 -0
  22. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-publish-item/references/title-formula.md +0 -0
  23. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-reply-buyer/SKILL.md +0 -0
  24. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-reply-buyer/references/bargain-ladder.md +0 -0
  25. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-reply-buyer/references/intent-classification.md +0 -0
  26. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-reply-buyer/references/tone-guide.md +0 -0
  27. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-risk-guard/SKILL.md +0 -0
  28. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-risk-guard/references/external-contact-keywords.md +0 -0
  29. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-risk-guard/references/forbidden-words.md +0 -0
  30. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-risk-guard/references/publish-red-lines.md +0 -0
  31. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-risk-guard/references/x5sec-recovery.md +0 -0
  32. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-shop-diagnosis/SKILL.md +0 -0
  33. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-shop-diagnosis/references/diagnosis-workflow.md +0 -0
  34. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-shop-diagnosis/references/rank-factors.md +0 -0
  35. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/skills/goofish-shop-diagnosis/references/traffic-drop-causes.md +0 -0
  36. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/__init__.py +0 -0
  37. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/cli.py +0 -0
  38. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/__init__.py +0 -0
  39. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/auth/__init__.py +0 -0
  40. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/auth/login.py +0 -0
  41. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/auth/reset_guard.py +0 -0
  42. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/auth/status.py +0 -0
  43. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/category/__init__.py +0 -0
  44. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/item/__init__.py +0 -0
  45. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/item/delete.py +0 -0
  46. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/item/get.py +0 -0
  47. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/item/list.py +0 -0
  48. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/item/view.py +0 -0
  49. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/location/__init__.py +0 -0
  50. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/location/default.py +0 -0
  51. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/media/__init__.py +0 -0
  52. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/media/upload.py +0 -0
  53. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/message/__init__.py +0 -0
  54. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/message/history.py +0 -0
  55. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/message/list_chats.py +0 -0
  56. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/message/watch.py +0 -0
  57. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/search/__init__.py +0 -0
  58. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/search/search.py +0 -0
  59. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/skills/__init__.py +0 -0
  60. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/commands/skills/install.py +0 -0
  61. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/__init__.py +0 -0
  62. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/browser.py +0 -0
  63. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/browser_cookie.py +0 -0
  64. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/cookie_types.py +0 -0
  65. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/crypto.py +0 -0
  66. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/errors.py +0 -0
  67. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/guard.py +0 -0
  68. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/item_data.py +0 -0
  69. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/item_page.py +0 -0
  70. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/limiter.py +0 -0
  71. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/local_state.py +0 -0
  72. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/message_history.py +0 -0
  73. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/mtop.py +0 -0
  74. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/output.py +0 -0
  75. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/qr_login.py +0 -0
  76. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/refresh.py +0 -0
  77. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/registry.py +0 -0
  78. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/sandbox_browser.py +0 -0
  79. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/search_data.py +0 -0
  80. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/session.py +0 -0
  81. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/sign.py +0 -0
  82. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/strategy.py +0 -0
  83. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/token.py +0 -0
  84. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/core/write_operation.py +0 -0
  85. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/mcp_server.py +0 -0
  86. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/sandbox/__init__.py +0 -0
  87. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/sandbox/assets/Dockerfile +0 -0
  88. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/sandbox/assets/entrypoint.sh +0 -0
  89. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/sandbox/cli.py +0 -0
  90. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/sandbox/interactive.py +0 -0
  91. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/sandbox/runtime.py +0 -0
  92. {goofish_cli-0.6.4 → goofish_cli-0.6.6}/src/goofish_cli/static/goofish_js_version_2.js +0 -0
@@ -3,7 +3,7 @@
3
3
  "name": "goofish-cli-skills",
4
4
  "displayName": "goofish-cli Skills",
5
5
  "description": "闲鱼(goofish.com)自动化运营的 Claude Skills 套件。配合 goofish-cli MCP server 使用,让 Agent 在发布商品 / 回复买家 / 风控预检 / 店铺诊断这些场景里上手即会。",
6
- "version": "0.6.4",
6
+ "version": "0.6.6",
7
7
  "author": {
8
8
  "name": "fancy",
9
9
  "url": "https://github.com/fancyboi999"
@@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [0.6.6](https://github.com/fancyboi999/goofish-cli/compare/v0.6.5...v0.6.6) (2026-11-18)
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * **message:** use created conversation cid when sending to a new chat ([#61](https://github.com/fancyboi999/goofish-cli/issues/61)) ([399f0b0](https://github.com/fancyboi999/goofish-cli/commit/399f0b046acb2b5ef3316a9bc4c294291d36c8ac))
13
+
14
+ ## [0.6.5](https://github.com/fancyboi999/goofish-cli/compare/v0.6.4...v0.6.5) (2026-11-18)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **category:** allow virtual categories without a Taobao category id ([#62](https://github.com/fancyboi999/goofish-cli/issues/62)) ([7e6a155](https://github.com/fancyboi999/goofish-cli/commit/7e6a1552759d2d0441426c7c72741cc36efcb1d8))
20
+
7
21
  ## [0.6.4](https://github.com/fancyboi999/goofish-cli/compare/v0.6.3...v0.6.4) (2026-11-14)
8
22
 
9
23
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: goofish-cli
3
- Version: 0.6.4
3
+ Version: 0.6.6
4
4
  Summary: 闲鱼 CLI — 支持 MCP,未来支持 Claude Skills。为 AI Agent 提供闲鱼自动化基础能力。
5
5
  Project-URL: Homepage, https://github.com/fancyboi999/goofish-cli
6
6
  Project-URL: Repository, https://github.com/fancyboi999/goofish-cli
@@ -203,7 +203,7 @@ OpenClaw `2026.6.1` 及以上可把本仓库作为 compatible bundle 加载。
203
203
  openclaw plugins install clawhub:openclaw-goofish
204
204
 
205
205
  # 登录态由用户在终端初始化,不交给 Agent 覆盖
206
- uvx --from goofish-cli==0.6.4 goofish auth login --qr
206
+ uvx --from goofish-cli==0.6.6 goofish auth login --qr
207
207
 
208
208
  openclaw plugins inspect goofish --json
209
209
  openclaw gateway restart
@@ -162,7 +162,7 @@ OpenClaw `2026.6.1` 及以上可把本仓库作为 compatible bundle 加载。
162
162
  openclaw plugins install clawhub:openclaw-goofish
163
163
 
164
164
  # 登录态由用户在终端初始化,不交给 Agent 覆盖
165
- uvx --from goofish-cli==0.6.4 goofish auth login --qr
165
+ uvx --from goofish-cli==0.6.6 goofish auth login --qr
166
166
 
167
167
  openclaw plugins inspect goofish --json
168
168
  openclaw gateway restart
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "goofish-cli"
7
- version = "0.6.4"
7
+ version = "0.6.6"
8
8
  description = "闲鱼 CLI — 支持 MCP,未来支持 Claude Skills。为 AI Agent 提供闲鱼自动化基础能力。"
9
9
  readme = "README.md"
10
10
  license = { text = "Apache-2.0" }
@@ -136,7 +136,7 @@ for image in 本地图片路径:
136
136
  )
137
137
  ```
138
138
 
139
- 发布也可用 `images=[本地路径, ...]` 自动上传,不能把 CDN URL 当本地路径。已提前上传时复用 `images_json`,避免重复上传。类目 DTO 必须包含 cat_id/cat_name/channel_cat_id/tb_cat_id,地址采用 selected 字段。缺少身份的类目不能猜补。模型分数不是校准概率,未知值为 null。
139
+ 发布也可用 `images=[本地路径, ...]` 自动上传,不能把 CDN URL 当本地路径。已提前上传时复用 `images_json`,避免重复上传。类目 DTO 必须包含 cat_id/cat_name/channel_cat_id;虚拟/服务类目的 tb_cat_id 可为空字符串,地址采用 selected 字段。缺少身份的类目不能猜补。模型分数不是校准概率,未知值为 null。
140
140
 
141
141
  成功返回 accepted 与 item_id 后,用 item_get 回读确认。失败返回的 images/category/location 可复用;submission_unknown 必须先核对自己的商品列表,禁止盲目重试。发布和下架共用 item.write 默认 1 次/分钟,上传独立 media.write 默认 9 次/分钟。
142
142
 
@@ -13,7 +13,7 @@ category_recommend(
13
13
  )
14
14
  ```
15
15
 
16
- 返回 `{cat_id, cat_name, channel_cat_id, tb_cat_id, confidence, confidence_source}`。confidence 为模型分数,不是校准概率;缺失为 null。
16
+ 返回 `{cat_id, cat_name, channel_cat_id, tb_cat_id, confidence, confidence_source}`。虚拟/服务类目(如「电子资料」)没有淘宝类目,tb_cat_id 为空字符串,网页端发布时也以空值提交。confidence 为模型分数,不是校准概率;缺失为 null。
17
17
 
18
18
  ## 结果处理
19
19
 
@@ -75,4 +75,4 @@ category_recommend(
75
75
 
76
76
  ## 本模块不调其它工具
77
77
 
78
- 只调 `category_recommend`。不需要 `item_get` 也不需要反查——将完整类目 DTO 作为 category_json 传给 item_publish;缺少 cat_id/channel_cat_id/tb_cat_id 时不得猜补。
78
+ 只调 `category_recommend`。不需要 `item_get` 也不需要反查——将完整类目 DTO 作为 category_json 传给 item_publish;缺少 cat_id/cat_name/channel_cat_id 时不得猜补;tb_cat_id 为空是正常情况。
@@ -14,22 +14,24 @@ from goofish_cli.core.errors import GoofishError
14
14
  from goofish_cli.core.mtop import call
15
15
 
16
16
 
17
- def _selected_score(data: dict, predict: dict) -> tuple[float | None, str | None]:
18
- explicit = predict.get("confidence")
19
- if isinstance(explicit, (float, int)) and not isinstance(explicit, bool) and math.isfinite(explicit):
20
- return float(explicit), "categoryPredictResult.confidence"
21
- values = []
17
+ def _finite(value: Any) -> float | None:
18
+ if isinstance(value, (float, int)) and not isinstance(value, bool) and math.isfinite(value):
19
+ return float(value)
20
+ return None
21
+
22
+
23
+ def _clicked_candidate(data: dict) -> dict:
24
+ """分类卡片(propertyId -10000)里被选中的候选。
25
+
26
+ 网页发布页以它为准,categoryPredictResult 只作兜底;虚拟类目(如「电子资料」)
27
+ 的 categoryPredictResult 不带类目字段,选中身份只在候选里。
28
+ """
22
29
  for card in data.get("cardList") or []:
23
30
  body = card.get("cardData") or {}
24
- if str(body.get("propertyId")) != "-10000":
25
- continue
26
- for candidate in body.get("valuesList") or []:
27
- keys = ("channelCatId", "tbCatId", "catId")
28
- if all(str(candidate.get(key)) == str(predict[key]) for key in keys if predict.get(key) is not None):
29
- score = candidate.get("score")
30
- if isinstance(score, (float, int)) and not isinstance(score, bool) and math.isfinite(score):
31
- values.append(float(score))
32
- return (values[0], "classification_card.score") if len(values) == 1 else (None, None)
31
+ if str(body.get("propertyId")) == "-10000":
32
+ values = body.get("valuesList") or []
33
+ return next((v for v in values if str(v.get("isClicked")) == "1"), {})
34
+ return {}
33
35
 
34
36
 
35
37
  @command(
@@ -84,15 +86,29 @@ def recommend(
84
86
  version="2.0",
85
87
  spm_cnt="a21ybx.publish.0.0",
86
88
  )
87
- predict = (raw.get("data", {}) or {}).get("categoryPredictResult", {}) or {}
88
- if not predict.get("catId") or not predict.get("channelCatId") or not predict.get("tbCatId"):
89
+ data = raw.get("data", {}) or {}
90
+ predict = data.get("categoryPredictResult", {}) or {}
91
+ clicked = _clicked_candidate(data)
92
+ selected = {
93
+ key: clicked.get(key) or predict.get(key)
94
+ for key in ("catId", "catName", "channelCatId", "tbCatId")
95
+ }
96
+ # tbCatId 可以为空:虚拟/服务类目没有淘宝类目映射,网页端照常以空值发布。
97
+ if not selected["catId"] or not selected["catName"] or not selected["channelCatId"]:
89
98
  raise GoofishError("类目推荐响应缺少选中分类身份,不能继续自动发布", raw=raw)
90
- score, source = _selected_score(raw.get("data") or {}, predict)
99
+ explicit = _finite(predict.get("confidence"))
100
+ clicked_score = _finite(clicked.get("score"))
101
+ if explicit is not None:
102
+ score, source = explicit, "categoryPredictResult.confidence"
103
+ elif clicked_score is not None:
104
+ score, source = clicked_score, "classification_card.score"
105
+ else:
106
+ score, source = None, None
91
107
  return {
92
- "cat_id": str(predict.get("catId", "")),
93
- "cat_name": predict.get("catName", ""),
94
- "channel_cat_id": str(predict.get("channelCatId", "")),
95
- "tb_cat_id": str(predict.get("tbCatId", "")),
108
+ "cat_id": str(selected["catId"]),
109
+ "cat_name": selected["catName"],
110
+ "channel_cat_id": str(selected["channelCatId"]),
111
+ "tb_cat_id": str(selected["tbCatId"] or ""),
96
112
  "confidence": score,
97
113
  "confidence_source": source,
98
114
  "confidence_kind": "model_score_not_calibrated_probability",
@@ -122,8 +122,9 @@ def _money(value: float) -> str:
122
122
 
123
123
 
124
124
  def _category(value: Any) -> None:
125
- if not isinstance(value, dict) or any(not value.get(k) for k in ("cat_id", "cat_name", "channel_cat_id", "tb_cat_id")):
126
- raise GoofishError("已确认类目必须包含 cat_id/cat_name/channel_cat_id/tb_cat_id")
125
+ # tb_cat_id 可为空:虚拟/服务类目没有淘宝类目映射。
126
+ if not isinstance(value, dict) or any(not value.get(k) for k in ("cat_id", "cat_name", "channel_cat_id")):
127
+ raise GoofishError("已确认类目必须包含 cat_id/cat_name/channel_cat_id")
127
128
 
128
129
 
129
130
  def _address(value: Any) -> dict:
@@ -216,7 +217,7 @@ def _build_publish_data(
216
217
  "catId": cat_info["cat_id"],
217
218
  "catName": cat_info["cat_name"],
218
219
  "channelCatId": cat_info["channel_cat_id"],
219
- "tbCatId": cat_info["tb_cat_id"],
220
+ "tbCatId": cat_info.get("tb_cat_id") or "",
220
221
  },
221
222
  "onlyTakeSelf": can_self_pickup,
222
223
  "uniqueCode": cat_info.get("unique_code") or str(time.time_ns() // 1000),
@@ -17,6 +17,7 @@ from goofish_cli.core.errors import GoofishError
17
17
  from goofish_cli.core.token import get_access_token
18
18
  from goofish_cli.core.write_operation import write_operation
19
19
  from goofish_cli.core.ws import (
20
+ cid_from_create_ack,
20
21
  connect,
21
22
  create_chat,
22
23
  heartbeat_loop,
@@ -88,7 +89,23 @@ async def _send(
88
89
  create_mid = await create_chat(
89
90
  ws, myid=session.unb, toid=toid, item_id=item_id
90
91
  )
91
- await recv_ack(ws, create_mid)
92
+ create_ack = await recv_ack(ws, create_mid)
93
+ create_code = (create_ack or {}).get("code")
94
+ if create_code != 200:
95
+ detail = (
96
+ "无回包(超时)"
97
+ if create_ack is None
98
+ else f"code={create_code}"
99
+ )
100
+ raise GoofishError(f"创建会话失败:{detail},未发送")
101
+ created_cid = cid_from_create_ack(create_ack)
102
+ if not created_cid:
103
+ raise GoofishError("创建会话失败:回包里没有 cid,未发送")
104
+ cid = created_cid
105
+ elif cid in ("", "0"):
106
+ raise GoofishError(
107
+ "未知会话 cid;新会话请传 --item-id 先创建单聊"
108
+ )
92
109
 
93
110
  if kind == "text":
94
111
  if not text:
@@ -308,6 +308,39 @@ async def create_chat(ws: ClientConnection, *, myid: str, toid: str, item_id: st
308
308
  return mid
309
309
 
310
310
 
311
+ def cid_from_create_ack(ack: dict[str, Any] | None) -> str:
312
+ """从 `/r/SingleChatConversation/create` 回包里取出真实会话 cid。
313
+
314
+ 创建成功时服务端把会话放在 body.singleChatConversation.cid(形如
315
+ `<masked-cid>@goofish`)。只发 `cid=0` 直接发送会被服务端以 code=500 拒绝,
316
+ 所以新会话必须先拿到这个 cid 再发消息。
317
+ """
318
+ if not isinstance(ack, dict) or ack.get("code") != 200:
319
+ return ""
320
+ body = ack.get("body") or {}
321
+ if not isinstance(body, dict):
322
+ return ""
323
+ conv = body.get("singleChatConversation") or {}
324
+ candidates = [
325
+ conv.get("cid") if isinstance(conv, dict) else None,
326
+ body.get("cid"),
327
+ body.get("sessionId"),
328
+ body.get("conversationId"),
329
+ ]
330
+ for msgs in (body.get("messages"), body.get("messageList")):
331
+ if isinstance(msgs, list):
332
+ for item in msgs:
333
+ if isinstance(item, dict):
334
+ candidates.append(item.get("cid"))
335
+ if isinstance(body.get("lastMessage"), dict):
336
+ candidates.append(body["lastMessage"].get("cid"))
337
+ for raw in candidates:
338
+ if not raw:
339
+ continue
340
+ return str(raw).split("@")[0]
341
+ return ""
342
+
343
+
311
344
  async def collect_session_cids(session: Session, duration: float = 5.0) -> list[dict[str, Any]]:
312
345
  """连 WS + /reg + ackDiff(pts=0),收 duration 秒,返回所有 push 到的 session cid。
313
346
 
File without changes
File without changes
File without changes