@masterbble/dsh-coo-pet 0.0.0-stage → 0.6.29

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 (507) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +112 -2
  3. package/assets/desk-main.cjs +623 -0
  4. package/assets/desk-preload.cjs +116 -0
  5. package/assets/desk-probe.ps1 +213 -0
  6. package/assets/icon-snapshot.json +1 -0
  7. package/assets/pet/desk.html +2734 -0
  8. package/assets/pet/kit/body.js +1053 -0
  9. package/assets/pet/kit/rig.js +242 -0
  10. package/assets/pet/speech/zh.json +1 -0
  11. package/assets/pet/speech/zh.ogg +0 -0
  12. package/assets/pet/whale/feat/dizzy_eyeL.png +0 -0
  13. package/assets/pet/whale/feat/dizzy_eyeR.png +0 -0
  14. package/assets/pet/whale/feat/dizzy_mouth.png +0 -0
  15. package/assets/pet/whale/feat/drag_eyeL.png +0 -0
  16. package/assets/pet/whale/feat/drag_eyeR.png +0 -0
  17. package/assets/pet/whale/feat/drag_mouth.png +0 -0
  18. package/assets/pet/whale/feat/eyeL_ball.png +0 -0
  19. package/assets/pet/whale/feat/eyeL_hl.png +0 -0
  20. package/assets/pet/whale/feat/eyeL_iris.png +0 -0
  21. package/assets/pet/whale/feat/eyeL_lash.png +0 -0
  22. package/assets/pet/whale/feat/eyeR_ball.png +0 -0
  23. package/assets/pet/whale/feat/eyeR_hl.png +0 -0
  24. package/assets/pet/whale/feat/eyeR_iris.png +0 -0
  25. package/assets/pet/whale/feat/eyeR_lash.png +0 -0
  26. package/assets/pet/whale/feat/happy_eyeL.png +0 -0
  27. package/assets/pet/whale/feat/happy_eyeR.png +0 -0
  28. package/assets/pet/whale/feat/happy_mouth.png +0 -0
  29. package/assets/pet/whale/feat/love_eyeL.png +0 -0
  30. package/assets/pet/whale/feat/love_eyeR.png +0 -0
  31. package/assets/pet/whale/feat/love_mouth.png +0 -0
  32. package/assets/pet/whale/feat/neutral_mouth.png +0 -0
  33. package/assets/pet/whale/feat/sleep_eyeL.png +0 -0
  34. package/assets/pet/whale/feat/sleep_eyeR.png +0 -0
  35. package/assets/pet/whale/feat/sleep_mouth.png +0 -0
  36. package/assets/pet/whale/feat/surprised_eyeL.png +0 -0
  37. package/assets/pet/whale/feat/surprised_eyeR.png +0 -0
  38. package/assets/pet/whale/feat/surprised_mouth.png +0 -0
  39. package/assets/pet/whale/figure.js +948 -0
  40. package/assets/pet/whale/figure.json +997 -0
  41. package/assets/pet/whale/model.json +1710 -0
  42. package/assets/pet/whale/outfits/cape/arm_far.png +0 -0
  43. package/assets/pet/whale/outfits/cape/arm_far_end_front.png +0 -0
  44. package/assets/pet/whale/outfits/cape/arm_near.png +0 -0
  45. package/assets/pet/whale/outfits/cape/cloak.png +0 -0
  46. package/assets/pet/whale/outfits/cape/cloak_shoulder_cover.png +0 -0
  47. package/assets/pet/whale/outfits/cape/hood_back.png +0 -0
  48. package/assets/pet/whale/outfits/cape/hood_fin_far.png +0 -0
  49. package/assets/pet/whale/outfits/cape/hood_fin_near.png +0 -0
  50. package/assets/pet/whale/outfits/cape/hood_front.png +0 -0
  51. package/assets/pet/whale/outfits/cape/hood_lining.png +0 -0
  52. package/assets/pet/whale/outfits/cape/hood_tie_far.png +0 -0
  53. package/assets/pet/whale/outfits/cape/hood_tie_near.png +0 -0
  54. package/assets/pet/whale/outfits/cape/leg_back.png +0 -0
  55. package/assets/pet/whale/outfits/cape/leg_front.png +0 -0
  56. package/assets/pet/whale/outfits/cape/scarf_neck.png +0 -0
  57. package/assets/pet/whale/outfits/cape/scarf_tail_back.png +0 -0
  58. package/assets/pet/whale/outfits/cape/scarf_tail_front.png +0 -0
  59. package/assets/pet/whale/outfits/cape/skirt.png +0 -0
  60. package/assets/pet/whale/outfits/cape/skirt_sit.png +0 -0
  61. package/assets/pet/whale/outfits/cape/spout.png +0 -0
  62. package/assets/pet/whale/outfits/crew/arm_far.png +0 -0
  63. package/assets/pet/whale/outfits/crew/arm_near.png +0 -0
  64. package/assets/pet/whale/outfits/crew/bow_near.png +0 -0
  65. package/assets/pet/whale/outfits/crew/headset.png +0 -0
  66. package/assets/pet/whale/outfits/crew/leg_back.png +0 -0
  67. package/assets/pet/whale/outfits/crew/leg_front.png +0 -0
  68. package/assets/pet/whale/outfits/crew/pony_bow.png +0 -0
  69. package/assets/pet/whale/outfits/crew/skirt_shadow.png +0 -0
  70. package/assets/pet/whale/outfits/crew/torso_up.png +0 -0
  71. package/assets/pet/whale/outfits/crew/visor.png +0 -0
  72. package/assets/pet/whale/schemes/chatgpt/feat/dizzy_eyeL.png +0 -0
  73. package/assets/pet/whale/schemes/chatgpt/feat/dizzy_eyeR.png +0 -0
  74. package/assets/pet/whale/schemes/chatgpt/feat/dizzy_mouth.png +0 -0
  75. package/assets/pet/whale/schemes/chatgpt/feat/drag_eyeL.png +0 -0
  76. package/assets/pet/whale/schemes/chatgpt/feat/drag_eyeR.png +0 -0
  77. package/assets/pet/whale/schemes/chatgpt/feat/drag_mouth.png +0 -0
  78. package/assets/pet/whale/schemes/chatgpt/feat/eyeL_ball.png +0 -0
  79. package/assets/pet/whale/schemes/chatgpt/feat/eyeL_iris.png +0 -0
  80. package/assets/pet/whale/schemes/chatgpt/feat/eyeL_lash.png +0 -0
  81. package/assets/pet/whale/schemes/chatgpt/feat/eyeR_ball.png +0 -0
  82. package/assets/pet/whale/schemes/chatgpt/feat/eyeR_iris.png +0 -0
  83. package/assets/pet/whale/schemes/chatgpt/feat/eyeR_lash.png +0 -0
  84. package/assets/pet/whale/schemes/chatgpt/feat/happy_eyeL.png +0 -0
  85. package/assets/pet/whale/schemes/chatgpt/feat/happy_eyeR.png +0 -0
  86. package/assets/pet/whale/schemes/chatgpt/feat/happy_mouth.png +0 -0
  87. package/assets/pet/whale/schemes/chatgpt/feat/love_eyeL.png +0 -0
  88. package/assets/pet/whale/schemes/chatgpt/feat/love_eyeR.png +0 -0
  89. package/assets/pet/whale/schemes/chatgpt/feat/love_mouth.png +0 -0
  90. package/assets/pet/whale/schemes/chatgpt/feat/neutral_mouth.png +0 -0
  91. package/assets/pet/whale/schemes/chatgpt/feat/sleep_eyeL.png +0 -0
  92. package/assets/pet/whale/schemes/chatgpt/feat/sleep_eyeR.png +0 -0
  93. package/assets/pet/whale/schemes/chatgpt/feat/sleep_mouth.png +0 -0
  94. package/assets/pet/whale/schemes/chatgpt/feat/surprised_eyeL.png +0 -0
  95. package/assets/pet/whale/schemes/chatgpt/feat/surprised_eyeR.png +0 -0
  96. package/assets/pet/whale/schemes/chatgpt/feat/surprised_mouth.png +0 -0
  97. package/assets/pet/whale/schemes/chatgpt/tex/ahoge.png +0 -0
  98. package/assets/pet/whale/schemes/chatgpt/tex/arm_far.png +0 -0
  99. package/assets/pet/whale/schemes/chatgpt/tex/arm_far_end_front.png +0 -0
  100. package/assets/pet/whale/schemes/chatgpt/tex/arm_near.png +0 -0
  101. package/assets/pet/whale/schemes/chatgpt/tex/bangs.png +0 -0
  102. package/assets/pet/whale/schemes/chatgpt/tex/bow.png +0 -0
  103. package/assets/pet/whale/schemes/chatgpt/tex/brows.png +0 -0
  104. package/assets/pet/whale/schemes/chatgpt/tex/crew_hair_back.png +0 -0
  105. package/assets/pet/whale/schemes/chatgpt/tex/crew_ponytail.png +0 -0
  106. package/assets/pet/whale/schemes/chatgpt/tex/crew_sidelocks.png +0 -0
  107. package/assets/pet/whale/schemes/chatgpt/tex/crew_skirt.png +0 -0
  108. package/assets/pet/whale/schemes/chatgpt/tex/crew_skirt_sit.png +0 -0
  109. package/assets/pet/whale/schemes/chatgpt/tex/eye_creases.png +0 -0
  110. package/assets/pet/whale/schemes/chatgpt/tex/face.png +0 -0
  111. package/assets/pet/whale/schemes/chatgpt/tex/fin_far.png +0 -0
  112. package/assets/pet/whale/schemes/chatgpt/tex/fin_near.png +0 -0
  113. package/assets/pet/whale/schemes/chatgpt/tex/hair_back.png +0 -0
  114. package/assets/pet/whale/schemes/chatgpt/tex/hair_back_curl.png +0 -0
  115. package/assets/pet/whale/schemes/chatgpt/tex/hair_front_left.png +0 -0
  116. package/assets/pet/whale/schemes/chatgpt/tex/hair_front_right.png +0 -0
  117. package/assets/pet/whale/schemes/chatgpt/tex/headdress.png +0 -0
  118. package/assets/pet/whale/schemes/chatgpt/tex/leg_back.png +0 -0
  119. package/assets/pet/whale/schemes/chatgpt/tex/leg_front.png +0 -0
  120. package/assets/pet/whale/schemes/chatgpt/tex/sidelocks.png +0 -0
  121. package/assets/pet/whale/schemes/chatgpt/tex/skirt.png +0 -0
  122. package/assets/pet/whale/schemes/chatgpt/tex/skirt_sit.png +0 -0
  123. package/assets/pet/whale/schemes/chatgpt/tex/tail.png +0 -0
  124. package/assets/pet/whale/schemes/chatgpt/tex/torso_up.png +0 -0
  125. package/assets/pet/whale/schemes/chatgpt/tex/waist_bow_front.png +0 -0
  126. package/assets/pet/whale/schemes/chatgpt/tex/waist_bow_sit_front.png +0 -0
  127. package/assets/pet/whale/schemes/claude/feat/dizzy_eyeL.png +0 -0
  128. package/assets/pet/whale/schemes/claude/feat/dizzy_eyeR.png +0 -0
  129. package/assets/pet/whale/schemes/claude/feat/dizzy_mouth.png +0 -0
  130. package/assets/pet/whale/schemes/claude/feat/drag_eyeL.png +0 -0
  131. package/assets/pet/whale/schemes/claude/feat/drag_eyeR.png +0 -0
  132. package/assets/pet/whale/schemes/claude/feat/drag_mouth.png +0 -0
  133. package/assets/pet/whale/schemes/claude/feat/eyeL_ball.png +0 -0
  134. package/assets/pet/whale/schemes/claude/feat/eyeL_iris.png +0 -0
  135. package/assets/pet/whale/schemes/claude/feat/eyeL_lash.png +0 -0
  136. package/assets/pet/whale/schemes/claude/feat/eyeR_ball.png +0 -0
  137. package/assets/pet/whale/schemes/claude/feat/eyeR_iris.png +0 -0
  138. package/assets/pet/whale/schemes/claude/feat/eyeR_lash.png +0 -0
  139. package/assets/pet/whale/schemes/claude/feat/happy_eyeL.png +0 -0
  140. package/assets/pet/whale/schemes/claude/feat/happy_eyeR.png +0 -0
  141. package/assets/pet/whale/schemes/claude/feat/happy_mouth.png +0 -0
  142. package/assets/pet/whale/schemes/claude/feat/love_eyeL.png +0 -0
  143. package/assets/pet/whale/schemes/claude/feat/love_eyeR.png +0 -0
  144. package/assets/pet/whale/schemes/claude/feat/love_mouth.png +0 -0
  145. package/assets/pet/whale/schemes/claude/feat/neutral_mouth.png +0 -0
  146. package/assets/pet/whale/schemes/claude/feat/sleep_eyeL.png +0 -0
  147. package/assets/pet/whale/schemes/claude/feat/sleep_eyeR.png +0 -0
  148. package/assets/pet/whale/schemes/claude/feat/sleep_mouth.png +0 -0
  149. package/assets/pet/whale/schemes/claude/feat/surprised_eyeL.png +0 -0
  150. package/assets/pet/whale/schemes/claude/feat/surprised_eyeR.png +0 -0
  151. package/assets/pet/whale/schemes/claude/feat/surprised_mouth.png +0 -0
  152. package/assets/pet/whale/schemes/claude/tex/ahoge.png +0 -0
  153. package/assets/pet/whale/schemes/claude/tex/arm_far.png +0 -0
  154. package/assets/pet/whale/schemes/claude/tex/arm_far_end_front.png +0 -0
  155. package/assets/pet/whale/schemes/claude/tex/arm_near.png +0 -0
  156. package/assets/pet/whale/schemes/claude/tex/bangs.png +0 -0
  157. package/assets/pet/whale/schemes/claude/tex/bow.png +0 -0
  158. package/assets/pet/whale/schemes/claude/tex/brows.png +0 -0
  159. package/assets/pet/whale/schemes/claude/tex/crew_hair_back.png +0 -0
  160. package/assets/pet/whale/schemes/claude/tex/crew_ponytail.png +0 -0
  161. package/assets/pet/whale/schemes/claude/tex/crew_sidelocks.png +0 -0
  162. package/assets/pet/whale/schemes/claude/tex/crew_skirt.png +0 -0
  163. package/assets/pet/whale/schemes/claude/tex/crew_skirt_sit.png +0 -0
  164. package/assets/pet/whale/schemes/claude/tex/eye_creases.png +0 -0
  165. package/assets/pet/whale/schemes/claude/tex/face.png +0 -0
  166. package/assets/pet/whale/schemes/claude/tex/fin_far.png +0 -0
  167. package/assets/pet/whale/schemes/claude/tex/fin_near.png +0 -0
  168. package/assets/pet/whale/schemes/claude/tex/hair_back.png +0 -0
  169. package/assets/pet/whale/schemes/claude/tex/hair_back_curl.png +0 -0
  170. package/assets/pet/whale/schemes/claude/tex/hair_front_left.png +0 -0
  171. package/assets/pet/whale/schemes/claude/tex/hair_front_right.png +0 -0
  172. package/assets/pet/whale/schemes/claude/tex/headdress.png +0 -0
  173. package/assets/pet/whale/schemes/claude/tex/leg_back.png +0 -0
  174. package/assets/pet/whale/schemes/claude/tex/leg_front.png +0 -0
  175. package/assets/pet/whale/schemes/claude/tex/sidelocks.png +0 -0
  176. package/assets/pet/whale/schemes/claude/tex/skirt.png +0 -0
  177. package/assets/pet/whale/schemes/claude/tex/skirt_sit.png +0 -0
  178. package/assets/pet/whale/schemes/claude/tex/tail.png +0 -0
  179. package/assets/pet/whale/schemes/claude/tex/torso_up.png +0 -0
  180. package/assets/pet/whale/schemes/claude/tex/waist_bow_front.png +0 -0
  181. package/assets/pet/whale/schemes/claude/tex/waist_bow_sit_front.png +0 -0
  182. package/assets/pet/whale/schemes/gemini/feat/dizzy_eyeL.png +0 -0
  183. package/assets/pet/whale/schemes/gemini/feat/dizzy_eyeR.png +0 -0
  184. package/assets/pet/whale/schemes/gemini/feat/dizzy_mouth.png +0 -0
  185. package/assets/pet/whale/schemes/gemini/feat/drag_eyeL.png +0 -0
  186. package/assets/pet/whale/schemes/gemini/feat/drag_eyeR.png +0 -0
  187. package/assets/pet/whale/schemes/gemini/feat/drag_mouth.png +0 -0
  188. package/assets/pet/whale/schemes/gemini/feat/eyeL_ball.png +0 -0
  189. package/assets/pet/whale/schemes/gemini/feat/eyeL_iris.png +0 -0
  190. package/assets/pet/whale/schemes/gemini/feat/eyeL_lash.png +0 -0
  191. package/assets/pet/whale/schemes/gemini/feat/eyeR_ball.png +0 -0
  192. package/assets/pet/whale/schemes/gemini/feat/eyeR_iris.png +0 -0
  193. package/assets/pet/whale/schemes/gemini/feat/eyeR_lash.png +0 -0
  194. package/assets/pet/whale/schemes/gemini/feat/happy_eyeL.png +0 -0
  195. package/assets/pet/whale/schemes/gemini/feat/happy_eyeR.png +0 -0
  196. package/assets/pet/whale/schemes/gemini/feat/happy_mouth.png +0 -0
  197. package/assets/pet/whale/schemes/gemini/feat/love_eyeL.png +0 -0
  198. package/assets/pet/whale/schemes/gemini/feat/love_eyeR.png +0 -0
  199. package/assets/pet/whale/schemes/gemini/feat/love_mouth.png +0 -0
  200. package/assets/pet/whale/schemes/gemini/feat/neutral_mouth.png +0 -0
  201. package/assets/pet/whale/schemes/gemini/feat/sleep_eyeL.png +0 -0
  202. package/assets/pet/whale/schemes/gemini/feat/sleep_eyeR.png +0 -0
  203. package/assets/pet/whale/schemes/gemini/feat/sleep_mouth.png +0 -0
  204. package/assets/pet/whale/schemes/gemini/feat/surprised_eyeL.png +0 -0
  205. package/assets/pet/whale/schemes/gemini/feat/surprised_eyeR.png +0 -0
  206. package/assets/pet/whale/schemes/gemini/feat/surprised_mouth.png +0 -0
  207. package/assets/pet/whale/schemes/gemini/tex/ahoge.png +0 -0
  208. package/assets/pet/whale/schemes/gemini/tex/arm_far.png +0 -0
  209. package/assets/pet/whale/schemes/gemini/tex/arm_far_end_front.png +0 -0
  210. package/assets/pet/whale/schemes/gemini/tex/arm_near.png +0 -0
  211. package/assets/pet/whale/schemes/gemini/tex/bangs.png +0 -0
  212. package/assets/pet/whale/schemes/gemini/tex/bow.png +0 -0
  213. package/assets/pet/whale/schemes/gemini/tex/brows.png +0 -0
  214. package/assets/pet/whale/schemes/gemini/tex/crew_hair_back.png +0 -0
  215. package/assets/pet/whale/schemes/gemini/tex/crew_ponytail.png +0 -0
  216. package/assets/pet/whale/schemes/gemini/tex/crew_sidelocks.png +0 -0
  217. package/assets/pet/whale/schemes/gemini/tex/crew_skirt.png +0 -0
  218. package/assets/pet/whale/schemes/gemini/tex/crew_skirt_sit.png +0 -0
  219. package/assets/pet/whale/schemes/gemini/tex/eye_creases.png +0 -0
  220. package/assets/pet/whale/schemes/gemini/tex/face.png +0 -0
  221. package/assets/pet/whale/schemes/gemini/tex/fin_far.png +0 -0
  222. package/assets/pet/whale/schemes/gemini/tex/fin_near.png +0 -0
  223. package/assets/pet/whale/schemes/gemini/tex/hair_back.png +0 -0
  224. package/assets/pet/whale/schemes/gemini/tex/hair_back_curl.png +0 -0
  225. package/assets/pet/whale/schemes/gemini/tex/hair_front_left.png +0 -0
  226. package/assets/pet/whale/schemes/gemini/tex/hair_front_right.png +0 -0
  227. package/assets/pet/whale/schemes/gemini/tex/headdress.png +0 -0
  228. package/assets/pet/whale/schemes/gemini/tex/leg_back.png +0 -0
  229. package/assets/pet/whale/schemes/gemini/tex/leg_front.png +0 -0
  230. package/assets/pet/whale/schemes/gemini/tex/sidelocks.png +0 -0
  231. package/assets/pet/whale/schemes/gemini/tex/skirt.png +0 -0
  232. package/assets/pet/whale/schemes/gemini/tex/skirt_sit.png +0 -0
  233. package/assets/pet/whale/schemes/gemini/tex/tail.png +0 -0
  234. package/assets/pet/whale/schemes/gemini/tex/torso_up.png +0 -0
  235. package/assets/pet/whale/schemes/gemini/tex/waist_bow_front.png +0 -0
  236. package/assets/pet/whale/schemes/gemini/tex/waist_bow_sit_front.png +0 -0
  237. package/assets/pet/whale/schemes/harness/feat/dizzy_eyeL.png +0 -0
  238. package/assets/pet/whale/schemes/harness/feat/dizzy_eyeR.png +0 -0
  239. package/assets/pet/whale/schemes/harness/feat/dizzy_mouth.png +0 -0
  240. package/assets/pet/whale/schemes/harness/feat/drag_eyeL.png +0 -0
  241. package/assets/pet/whale/schemes/harness/feat/drag_eyeR.png +0 -0
  242. package/assets/pet/whale/schemes/harness/feat/drag_mouth.png +0 -0
  243. package/assets/pet/whale/schemes/harness/feat/eyeL_ball.png +0 -0
  244. package/assets/pet/whale/schemes/harness/feat/eyeL_iris.png +0 -0
  245. package/assets/pet/whale/schemes/harness/feat/eyeL_lash.png +0 -0
  246. package/assets/pet/whale/schemes/harness/feat/eyeR_ball.png +0 -0
  247. package/assets/pet/whale/schemes/harness/feat/eyeR_iris.png +0 -0
  248. package/assets/pet/whale/schemes/harness/feat/eyeR_lash.png +0 -0
  249. package/assets/pet/whale/schemes/harness/feat/happy_eyeL.png +0 -0
  250. package/assets/pet/whale/schemes/harness/feat/happy_eyeR.png +0 -0
  251. package/assets/pet/whale/schemes/harness/feat/happy_mouth.png +0 -0
  252. package/assets/pet/whale/schemes/harness/feat/love_eyeL.png +0 -0
  253. package/assets/pet/whale/schemes/harness/feat/love_eyeR.png +0 -0
  254. package/assets/pet/whale/schemes/harness/feat/love_mouth.png +0 -0
  255. package/assets/pet/whale/schemes/harness/feat/neutral_mouth.png +0 -0
  256. package/assets/pet/whale/schemes/harness/feat/sleep_eyeL.png +0 -0
  257. package/assets/pet/whale/schemes/harness/feat/sleep_eyeR.png +0 -0
  258. package/assets/pet/whale/schemes/harness/feat/sleep_mouth.png +0 -0
  259. package/assets/pet/whale/schemes/harness/feat/surprised_eyeL.png +0 -0
  260. package/assets/pet/whale/schemes/harness/feat/surprised_eyeR.png +0 -0
  261. package/assets/pet/whale/schemes/harness/feat/surprised_mouth.png +0 -0
  262. package/assets/pet/whale/schemes/harness/tex/ahoge.png +0 -0
  263. package/assets/pet/whale/schemes/harness/tex/arm_far.png +0 -0
  264. package/assets/pet/whale/schemes/harness/tex/arm_far_end_front.png +0 -0
  265. package/assets/pet/whale/schemes/harness/tex/arm_near.png +0 -0
  266. package/assets/pet/whale/schemes/harness/tex/bangs.png +0 -0
  267. package/assets/pet/whale/schemes/harness/tex/bow.png +0 -0
  268. package/assets/pet/whale/schemes/harness/tex/brows.png +0 -0
  269. package/assets/pet/whale/schemes/harness/tex/crew_hair_back.png +0 -0
  270. package/assets/pet/whale/schemes/harness/tex/crew_ponytail.png +0 -0
  271. package/assets/pet/whale/schemes/harness/tex/crew_sidelocks.png +0 -0
  272. package/assets/pet/whale/schemes/harness/tex/crew_skirt.png +0 -0
  273. package/assets/pet/whale/schemes/harness/tex/crew_skirt_sit.png +0 -0
  274. package/assets/pet/whale/schemes/harness/tex/eye_creases.png +0 -0
  275. package/assets/pet/whale/schemes/harness/tex/face.png +0 -0
  276. package/assets/pet/whale/schemes/harness/tex/fin_far.png +0 -0
  277. package/assets/pet/whale/schemes/harness/tex/fin_near.png +0 -0
  278. package/assets/pet/whale/schemes/harness/tex/hair_back.png +0 -0
  279. package/assets/pet/whale/schemes/harness/tex/hair_back_curl.png +0 -0
  280. package/assets/pet/whale/schemes/harness/tex/hair_front_left.png +0 -0
  281. package/assets/pet/whale/schemes/harness/tex/hair_front_right.png +0 -0
  282. package/assets/pet/whale/schemes/harness/tex/headdress.png +0 -0
  283. package/assets/pet/whale/schemes/harness/tex/leg_back.png +0 -0
  284. package/assets/pet/whale/schemes/harness/tex/leg_front.png +0 -0
  285. package/assets/pet/whale/schemes/harness/tex/sidelocks.png +0 -0
  286. package/assets/pet/whale/schemes/harness/tex/skirt.png +0 -0
  287. package/assets/pet/whale/schemes/harness/tex/skirt_sit.png +0 -0
  288. package/assets/pet/whale/schemes/harness/tex/tail.png +0 -0
  289. package/assets/pet/whale/schemes/harness/tex/torso_up.png +0 -0
  290. package/assets/pet/whale/schemes/harness/tex/waist_bow_front.png +0 -0
  291. package/assets/pet/whale/schemes/harness/tex/waist_bow_sit_front.png +0 -0
  292. package/assets/pet/whale/schemes/kimi/feat/dizzy_eyeL.png +0 -0
  293. package/assets/pet/whale/schemes/kimi/feat/dizzy_eyeR.png +0 -0
  294. package/assets/pet/whale/schemes/kimi/feat/dizzy_mouth.png +0 -0
  295. package/assets/pet/whale/schemes/kimi/feat/drag_eyeL.png +0 -0
  296. package/assets/pet/whale/schemes/kimi/feat/drag_eyeR.png +0 -0
  297. package/assets/pet/whale/schemes/kimi/feat/drag_mouth.png +0 -0
  298. package/assets/pet/whale/schemes/kimi/feat/eyeL_ball.png +0 -0
  299. package/assets/pet/whale/schemes/kimi/feat/eyeL_iris.png +0 -0
  300. package/assets/pet/whale/schemes/kimi/feat/eyeL_lash.png +0 -0
  301. package/assets/pet/whale/schemes/kimi/feat/eyeR_ball.png +0 -0
  302. package/assets/pet/whale/schemes/kimi/feat/eyeR_iris.png +0 -0
  303. package/assets/pet/whale/schemes/kimi/feat/eyeR_lash.png +0 -0
  304. package/assets/pet/whale/schemes/kimi/feat/happy_eyeL.png +0 -0
  305. package/assets/pet/whale/schemes/kimi/feat/happy_eyeR.png +0 -0
  306. package/assets/pet/whale/schemes/kimi/feat/happy_mouth.png +0 -0
  307. package/assets/pet/whale/schemes/kimi/feat/love_eyeL.png +0 -0
  308. package/assets/pet/whale/schemes/kimi/feat/love_eyeR.png +0 -0
  309. package/assets/pet/whale/schemes/kimi/feat/love_mouth.png +0 -0
  310. package/assets/pet/whale/schemes/kimi/feat/neutral_mouth.png +0 -0
  311. package/assets/pet/whale/schemes/kimi/feat/sleep_eyeL.png +0 -0
  312. package/assets/pet/whale/schemes/kimi/feat/sleep_eyeR.png +0 -0
  313. package/assets/pet/whale/schemes/kimi/feat/sleep_mouth.png +0 -0
  314. package/assets/pet/whale/schemes/kimi/feat/surprised_eyeL.png +0 -0
  315. package/assets/pet/whale/schemes/kimi/feat/surprised_eyeR.png +0 -0
  316. package/assets/pet/whale/schemes/kimi/feat/surprised_mouth.png +0 -0
  317. package/assets/pet/whale/schemes/kimi/tex/ahoge.png +0 -0
  318. package/assets/pet/whale/schemes/kimi/tex/arm_far.png +0 -0
  319. package/assets/pet/whale/schemes/kimi/tex/arm_far_end_front.png +0 -0
  320. package/assets/pet/whale/schemes/kimi/tex/arm_near.png +0 -0
  321. package/assets/pet/whale/schemes/kimi/tex/bangs.png +0 -0
  322. package/assets/pet/whale/schemes/kimi/tex/bow.png +0 -0
  323. package/assets/pet/whale/schemes/kimi/tex/brows.png +0 -0
  324. package/assets/pet/whale/schemes/kimi/tex/crew_hair_back.png +0 -0
  325. package/assets/pet/whale/schemes/kimi/tex/crew_ponytail.png +0 -0
  326. package/assets/pet/whale/schemes/kimi/tex/crew_sidelocks.png +0 -0
  327. package/assets/pet/whale/schemes/kimi/tex/crew_skirt.png +0 -0
  328. package/assets/pet/whale/schemes/kimi/tex/crew_skirt_sit.png +0 -0
  329. package/assets/pet/whale/schemes/kimi/tex/eye_creases.png +0 -0
  330. package/assets/pet/whale/schemes/kimi/tex/face.png +0 -0
  331. package/assets/pet/whale/schemes/kimi/tex/fin_far.png +0 -0
  332. package/assets/pet/whale/schemes/kimi/tex/fin_near.png +0 -0
  333. package/assets/pet/whale/schemes/kimi/tex/hair_back.png +0 -0
  334. package/assets/pet/whale/schemes/kimi/tex/hair_back_curl.png +0 -0
  335. package/assets/pet/whale/schemes/kimi/tex/hair_front_left.png +0 -0
  336. package/assets/pet/whale/schemes/kimi/tex/hair_front_right.png +0 -0
  337. package/assets/pet/whale/schemes/kimi/tex/headdress.png +0 -0
  338. package/assets/pet/whale/schemes/kimi/tex/leg_back.png +0 -0
  339. package/assets/pet/whale/schemes/kimi/tex/leg_front.png +0 -0
  340. package/assets/pet/whale/schemes/kimi/tex/sidelocks.png +0 -0
  341. package/assets/pet/whale/schemes/kimi/tex/skirt.png +0 -0
  342. package/assets/pet/whale/schemes/kimi/tex/skirt_sit.png +0 -0
  343. package/assets/pet/whale/schemes/kimi/tex/tail.png +0 -0
  344. package/assets/pet/whale/schemes/kimi/tex/torso_up.png +0 -0
  345. package/assets/pet/whale/schemes/kimi/tex/waist_bow_front.png +0 -0
  346. package/assets/pet/whale/schemes/kimi/tex/waist_bow_sit_front.png +0 -0
  347. package/assets/pet/whale/schemes/minimax/feat/dizzy_eyeL.png +0 -0
  348. package/assets/pet/whale/schemes/minimax/feat/dizzy_eyeR.png +0 -0
  349. package/assets/pet/whale/schemes/minimax/feat/dizzy_mouth.png +0 -0
  350. package/assets/pet/whale/schemes/minimax/feat/drag_eyeL.png +0 -0
  351. package/assets/pet/whale/schemes/minimax/feat/drag_eyeR.png +0 -0
  352. package/assets/pet/whale/schemes/minimax/feat/drag_mouth.png +0 -0
  353. package/assets/pet/whale/schemes/minimax/feat/eyeL_ball.png +0 -0
  354. package/assets/pet/whale/schemes/minimax/feat/eyeL_iris.png +0 -0
  355. package/assets/pet/whale/schemes/minimax/feat/eyeL_lash.png +0 -0
  356. package/assets/pet/whale/schemes/minimax/feat/eyeR_ball.png +0 -0
  357. package/assets/pet/whale/schemes/minimax/feat/eyeR_iris.png +0 -0
  358. package/assets/pet/whale/schemes/minimax/feat/eyeR_lash.png +0 -0
  359. package/assets/pet/whale/schemes/minimax/feat/happy_eyeL.png +0 -0
  360. package/assets/pet/whale/schemes/minimax/feat/happy_eyeR.png +0 -0
  361. package/assets/pet/whale/schemes/minimax/feat/happy_mouth.png +0 -0
  362. package/assets/pet/whale/schemes/minimax/feat/love_eyeL.png +0 -0
  363. package/assets/pet/whale/schemes/minimax/feat/love_eyeR.png +0 -0
  364. package/assets/pet/whale/schemes/minimax/feat/love_mouth.png +0 -0
  365. package/assets/pet/whale/schemes/minimax/feat/neutral_mouth.png +0 -0
  366. package/assets/pet/whale/schemes/minimax/feat/sleep_eyeL.png +0 -0
  367. package/assets/pet/whale/schemes/minimax/feat/sleep_eyeR.png +0 -0
  368. package/assets/pet/whale/schemes/minimax/feat/sleep_mouth.png +0 -0
  369. package/assets/pet/whale/schemes/minimax/feat/surprised_eyeL.png +0 -0
  370. package/assets/pet/whale/schemes/minimax/feat/surprised_eyeR.png +0 -0
  371. package/assets/pet/whale/schemes/minimax/feat/surprised_mouth.png +0 -0
  372. package/assets/pet/whale/schemes/minimax/tex/ahoge.png +0 -0
  373. package/assets/pet/whale/schemes/minimax/tex/arm_far.png +0 -0
  374. package/assets/pet/whale/schemes/minimax/tex/arm_far_end_front.png +0 -0
  375. package/assets/pet/whale/schemes/minimax/tex/arm_near.png +0 -0
  376. package/assets/pet/whale/schemes/minimax/tex/bangs.png +0 -0
  377. package/assets/pet/whale/schemes/minimax/tex/bow.png +0 -0
  378. package/assets/pet/whale/schemes/minimax/tex/brows.png +0 -0
  379. package/assets/pet/whale/schemes/minimax/tex/crew_hair_back.png +0 -0
  380. package/assets/pet/whale/schemes/minimax/tex/crew_ponytail.png +0 -0
  381. package/assets/pet/whale/schemes/minimax/tex/crew_sidelocks.png +0 -0
  382. package/assets/pet/whale/schemes/minimax/tex/crew_skirt.png +0 -0
  383. package/assets/pet/whale/schemes/minimax/tex/crew_skirt_sit.png +0 -0
  384. package/assets/pet/whale/schemes/minimax/tex/eye_creases.png +0 -0
  385. package/assets/pet/whale/schemes/minimax/tex/face.png +0 -0
  386. package/assets/pet/whale/schemes/minimax/tex/fin_far.png +0 -0
  387. package/assets/pet/whale/schemes/minimax/tex/fin_near.png +0 -0
  388. package/assets/pet/whale/schemes/minimax/tex/hair_back.png +0 -0
  389. package/assets/pet/whale/schemes/minimax/tex/hair_back_curl.png +0 -0
  390. package/assets/pet/whale/schemes/minimax/tex/hair_front_left.png +0 -0
  391. package/assets/pet/whale/schemes/minimax/tex/hair_front_right.png +0 -0
  392. package/assets/pet/whale/schemes/minimax/tex/headdress.png +0 -0
  393. package/assets/pet/whale/schemes/minimax/tex/leg_back.png +0 -0
  394. package/assets/pet/whale/schemes/minimax/tex/leg_front.png +0 -0
  395. package/assets/pet/whale/schemes/minimax/tex/sidelocks.png +0 -0
  396. package/assets/pet/whale/schemes/minimax/tex/skirt.png +0 -0
  397. package/assets/pet/whale/schemes/minimax/tex/skirt_sit.png +0 -0
  398. package/assets/pet/whale/schemes/minimax/tex/tail.png +0 -0
  399. package/assets/pet/whale/schemes/minimax/tex/torso_up.png +0 -0
  400. package/assets/pet/whale/schemes/minimax/tex/waist_bow_front.png +0 -0
  401. package/assets/pet/whale/schemes/minimax/tex/waist_bow_sit_front.png +0 -0
  402. package/assets/pet/whale/schemes/qwen/feat/dizzy_eyeL.png +0 -0
  403. package/assets/pet/whale/schemes/qwen/feat/dizzy_eyeR.png +0 -0
  404. package/assets/pet/whale/schemes/qwen/feat/dizzy_mouth.png +0 -0
  405. package/assets/pet/whale/schemes/qwen/feat/drag_eyeL.png +0 -0
  406. package/assets/pet/whale/schemes/qwen/feat/drag_eyeR.png +0 -0
  407. package/assets/pet/whale/schemes/qwen/feat/drag_mouth.png +0 -0
  408. package/assets/pet/whale/schemes/qwen/feat/eyeL_ball.png +0 -0
  409. package/assets/pet/whale/schemes/qwen/feat/eyeL_iris.png +0 -0
  410. package/assets/pet/whale/schemes/qwen/feat/eyeL_lash.png +0 -0
  411. package/assets/pet/whale/schemes/qwen/feat/eyeR_ball.png +0 -0
  412. package/assets/pet/whale/schemes/qwen/feat/eyeR_iris.png +0 -0
  413. package/assets/pet/whale/schemes/qwen/feat/eyeR_lash.png +0 -0
  414. package/assets/pet/whale/schemes/qwen/feat/happy_eyeL.png +0 -0
  415. package/assets/pet/whale/schemes/qwen/feat/happy_eyeR.png +0 -0
  416. package/assets/pet/whale/schemes/qwen/feat/happy_mouth.png +0 -0
  417. package/assets/pet/whale/schemes/qwen/feat/love_eyeL.png +0 -0
  418. package/assets/pet/whale/schemes/qwen/feat/love_eyeR.png +0 -0
  419. package/assets/pet/whale/schemes/qwen/feat/love_mouth.png +0 -0
  420. package/assets/pet/whale/schemes/qwen/feat/neutral_mouth.png +0 -0
  421. package/assets/pet/whale/schemes/qwen/feat/sleep_eyeL.png +0 -0
  422. package/assets/pet/whale/schemes/qwen/feat/sleep_eyeR.png +0 -0
  423. package/assets/pet/whale/schemes/qwen/feat/sleep_mouth.png +0 -0
  424. package/assets/pet/whale/schemes/qwen/feat/surprised_eyeL.png +0 -0
  425. package/assets/pet/whale/schemes/qwen/feat/surprised_eyeR.png +0 -0
  426. package/assets/pet/whale/schemes/qwen/feat/surprised_mouth.png +0 -0
  427. package/assets/pet/whale/schemes/qwen/tex/ahoge.png +0 -0
  428. package/assets/pet/whale/schemes/qwen/tex/arm_far.png +0 -0
  429. package/assets/pet/whale/schemes/qwen/tex/arm_far_end_front.png +0 -0
  430. package/assets/pet/whale/schemes/qwen/tex/arm_near.png +0 -0
  431. package/assets/pet/whale/schemes/qwen/tex/bangs.png +0 -0
  432. package/assets/pet/whale/schemes/qwen/tex/bow.png +0 -0
  433. package/assets/pet/whale/schemes/qwen/tex/brows.png +0 -0
  434. package/assets/pet/whale/schemes/qwen/tex/crew_hair_back.png +0 -0
  435. package/assets/pet/whale/schemes/qwen/tex/crew_ponytail.png +0 -0
  436. package/assets/pet/whale/schemes/qwen/tex/crew_sidelocks.png +0 -0
  437. package/assets/pet/whale/schemes/qwen/tex/crew_skirt.png +0 -0
  438. package/assets/pet/whale/schemes/qwen/tex/crew_skirt_sit.png +0 -0
  439. package/assets/pet/whale/schemes/qwen/tex/eye_creases.png +0 -0
  440. package/assets/pet/whale/schemes/qwen/tex/face.png +0 -0
  441. package/assets/pet/whale/schemes/qwen/tex/fin_far.png +0 -0
  442. package/assets/pet/whale/schemes/qwen/tex/fin_near.png +0 -0
  443. package/assets/pet/whale/schemes/qwen/tex/hair_back.png +0 -0
  444. package/assets/pet/whale/schemes/qwen/tex/hair_back_curl.png +0 -0
  445. package/assets/pet/whale/schemes/qwen/tex/hair_front_left.png +0 -0
  446. package/assets/pet/whale/schemes/qwen/tex/hair_front_right.png +0 -0
  447. package/assets/pet/whale/schemes/qwen/tex/headdress.png +0 -0
  448. package/assets/pet/whale/schemes/qwen/tex/leg_back.png +0 -0
  449. package/assets/pet/whale/schemes/qwen/tex/leg_front.png +0 -0
  450. package/assets/pet/whale/schemes/qwen/tex/sidelocks.png +0 -0
  451. package/assets/pet/whale/schemes/qwen/tex/skirt.png +0 -0
  452. package/assets/pet/whale/schemes/qwen/tex/skirt_sit.png +0 -0
  453. package/assets/pet/whale/schemes/qwen/tex/tail.png +0 -0
  454. package/assets/pet/whale/schemes/qwen/tex/torso_up.png +0 -0
  455. package/assets/pet/whale/schemes/qwen/tex/waist_bow_front.png +0 -0
  456. package/assets/pet/whale/schemes/qwen/tex/waist_bow_sit_front.png +0 -0
  457. package/assets/pet/whale/tex/ahoge.png +0 -0
  458. package/assets/pet/whale/tex/arm_far.png +0 -0
  459. package/assets/pet/whale/tex/arm_far_end_front.png +0 -0
  460. package/assets/pet/whale/tex/arm_near.png +0 -0
  461. package/assets/pet/whale/tex/bangs.png +0 -0
  462. package/assets/pet/whale/tex/bow.png +0 -0
  463. package/assets/pet/whale/tex/brows.png +0 -0
  464. package/assets/pet/whale/tex/crew_hair_back.png +0 -0
  465. package/assets/pet/whale/tex/crew_ponytail.png +0 -0
  466. package/assets/pet/whale/tex/crew_sidelocks.png +0 -0
  467. package/assets/pet/whale/tex/crew_skirt.png +0 -0
  468. package/assets/pet/whale/tex/crew_skirt_sit.png +0 -0
  469. package/assets/pet/whale/tex/eye_creases.png +0 -0
  470. package/assets/pet/whale/tex/face.png +0 -0
  471. package/assets/pet/whale/tex/fin_far.png +0 -0
  472. package/assets/pet/whale/tex/fin_near.png +0 -0
  473. package/assets/pet/whale/tex/hair_back.png +0 -0
  474. package/assets/pet/whale/tex/hair_back_curl.png +0 -0
  475. package/assets/pet/whale/tex/hair_front_left.png +0 -0
  476. package/assets/pet/whale/tex/hair_front_right.png +0 -0
  477. package/assets/pet/whale/tex/headdress.png +0 -0
  478. package/assets/pet/whale/tex/leg_back.png +0 -0
  479. package/assets/pet/whale/tex/leg_front.png +0 -0
  480. package/assets/pet/whale/tex/sidelocks.png +0 -0
  481. package/assets/pet/whale/tex/skirt.png +0 -0
  482. package/assets/pet/whale/tex/skirt_shadow.png +0 -0
  483. package/assets/pet/whale/tex/skirt_sit.png +0 -0
  484. package/assets/pet/whale/tex/tail.png +0 -0
  485. package/assets/pet/whale/tex/torso_up.png +0 -0
  486. package/assets/pet/whale/tex/waist_bow_front.png +0 -0
  487. package/assets/pet/whale/tex/waist_bow_sit_front.png +0 -0
  488. package/assets/pet/whale/thumbs/cape.png +0 -0
  489. package/assets/pet/whale/thumbs/chatgpt.png +0 -0
  490. package/assets/pet/whale/thumbs/claude.png +0 -0
  491. package/assets/pet/whale/thumbs/crew.png +0 -0
  492. package/assets/pet/whale/thumbs/deepseek.png +0 -0
  493. package/assets/pet/whale/thumbs/gemini.png +0 -0
  494. package/assets/pet/whale/thumbs/harness.png +0 -0
  495. package/assets/pet/whale/thumbs/kimi.png +0 -0
  496. package/assets/pet/whale/thumbs/maid.png +0 -0
  497. package/assets/pet/whale/thumbs/minimax.png +0 -0
  498. package/assets/pet/whale/thumbs/qwen.png +0 -0
  499. package/assets/restart-dsh.cmd +16 -0
  500. package/assets/restart-dsh.log +195 -0
  501. package/client.js +1169 -0
  502. package/cordis.patch.yml +3 -0
  503. package/icon.svg +8 -0
  504. package/index.js +1273 -0
  505. package/locale/en.json +6 -0
  506. package/locale/zh.json +6 -0
  507. package/package.json +50 -4
package/index.js ADDED
@@ -0,0 +1,1273 @@
1
+ /*
2
+ * coo-pet — desktop pet plugin for DeepSeek Harness
3
+ * Copyright (C) 2026 Masterbble
4
+ * Based on the desktop pet Coopanion by Pal-AI-Lab: https://github.com/Pal-AI-Lab/Coopanion
5
+ * SPDX-License-Identifier: AGPL-3.0-or-later (see LICENSE; third-party notices in THIRD_PARTY_NOTICES.md)
6
+ */
7
+ /**
8
+ * Coo pet — Host half.
9
+ *
10
+ * Watches agent status and tool dispatch, keeps a tiny live snapshot in memory,
11
+ * serves it plus its own settings to the Client half over the Harness Web server.
12
+ */
13
+
14
+ import z from '@deepseek-ai/schemastery'
15
+ import { spawn } from 'node:child_process'
16
+ import { existsSync } from 'node:fs'
17
+ import { mkdir, readFile, stat, writeFile } from 'node:fs/promises'
18
+ import { readFileSync } from 'node:fs'
19
+ import { dirname, extname, join, normalize as normalizePath, sep } from 'node:path'
20
+ import { fileURLToPath } from 'node:url'
21
+
22
+ export const name = 'dsh-coo-pet'
23
+
24
+ export const inject = ['webServer']
25
+
26
+ // DSH home 推导:优先 DSH_HOME 环境变量;没设时按 settings.json 实际落点判定——
27
+ // 插件可能装在 home\coo-pet(旧结构)或 home\whale-work\coo-pet(现结构),
28
+ // 简单取插件上一级会少一层、读写到错误的 settings.json(重启后配置"变回默认"的总根源)
29
+ function deriveHome() {
30
+ const pluginDir = normalizePath(fileURLToPath(new URL('..', import.meta.url)))
31
+ const parent = normalizePath(join(pluginDir, '..'))
32
+ if (existsSync(join(parent, 'coo-pet', 'settings.json'))) return parent
33
+ if (existsSync(join(pluginDir, 'coo-pet', 'settings.json'))) return pluginDir
34
+ return parent
35
+ }
36
+ const HOME = process.env.DSH_HOME ?? deriveHome()
37
+ const PLUGIN_DIR = normalizePath(fileURLToPath(new URL('..', import.meta.url)))
38
+ const LEGACY_SETTINGS_FILE = join(HOME, 'coo-pet', 'settings.json')
39
+ const SETTINGS_FILE = join(PLUGIN_DIR, 'settings.json')
40
+ const VERSION = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version
41
+ const PET_ROOT = fileURLToPath(new URL('./assets/pet/', import.meta.url))
42
+
43
+ const DEFAULTS = {
44
+ petName: '你的鱼',
45
+ menuOrder: 'open,input,stay,free,duty,actions,look,outfit,clone,none,reset,resetAll,restart',
46
+ menuOrderV2: true,
47
+ menuOrderV3: true,
48
+ menuOrderV4: true,
49
+ attachSession: '',
50
+ actOff: '',
51
+ look: 'deepseek',
52
+ outfit: 'crew',
53
+ size: 190,
54
+ opacity: 1,
55
+ speed: 1.2,
56
+ wander: false,
57
+ answerBubble: true,
58
+ idleBubble: true,
59
+ greet: true,
60
+ marginBottom: 0,
61
+ voice: true,
62
+ voiceMode: 'babble',
63
+ voiceName: '',
64
+ voiceRate: 1.05,
65
+ voicePitch: 0.9,
66
+ hotkey: 'mouse5',
67
+ hotkeyOn: true,
68
+ sfx: true,
69
+ display: 'desktop',
70
+ idleLines: '',
71
+ idleEvery: 20,
72
+ idleUnit: 'sec',
73
+ actIcons: true,
74
+ actSit: true,
75
+ carryEvery: 5,
76
+ carryUnit: 'sec',
77
+ }
78
+
79
+ // 内置鲸鱼娘形象:8 个配色 × 3 套衣服
80
+ const SCHEMES = {
81
+ deepseek: 'DeepSeek 蓝',
82
+ harness: 'Harness 灰',
83
+ chatgpt: 'ChatGPT 白',
84
+ claude: 'Claude 橙',
85
+ gemini: 'Gemini 彩',
86
+ qwen: 'Qwen 紫',
87
+ kimi: 'Kimi 蓝',
88
+ minimax: 'MiniMax 粉',
89
+ }
90
+
91
+ const OUTFITS = {
92
+ maid: '女仆装',
93
+ cape: '斗篷',
94
+ crew: '制服',
95
+ }
96
+
97
+ export const Config = z.object({
98
+ petName: z.string().default('你的鱼').description('她的名字:碎碎念里的 {name}、右键列表标题都用它'),
99
+ attachSession: z
100
+ .string()
101
+ .default('')
102
+ .description('插入指定会话:填 Session ID 后,桌宠对话框和语音输入都发进这个会话,回答回流到气泡并朗读;留空跟当前会话'),
103
+ menuOrder: z
104
+ .string()
105
+ .default('open,input,stay,free,duty,actions,look,outfit,clone,none,reset,resetAll,restart')
106
+ .description('右键下拉列表的顺序(逗号分隔:open 打开DSH / input 输入 / restart 重启DSH / reset 图标复位 / stay 原地待着 / free 自由活动 / duty 安静模式 / ground 回地面 / actions 来一个 / look 换形象 / outfit 换衣服 / none 藏起来)'),
107
+ actOff: z.string().default('').description('禁止她自动做的动作(逗号分隔:look,sit,sleep,dance,dizzy)'),
108
+ look: z
109
+ .union([
110
+ z.const('deepseek'),
111
+ z.const('harness'),
112
+ z.const('chatgpt'),
113
+ z.const('claude'),
114
+ z.const('gemini'),
115
+ z.const('qwen'),
116
+ z.const('kimi'),
117
+ z.const('minimax'),
118
+ ])
119
+ .default('deepseek')
120
+ .description('桌宠形象:鲸鱼娘配色'),
121
+ outfit: z
122
+ .union([z.const('maid'), z.const('cape'), z.const('crew')])
123
+ .default('crew')
124
+ .description('鲸鱼娘的衣服'),
125
+ size: z.number().min(64).max(420).step(2).default(190).description('桌宠高度(像素)'),
126
+ opacity: z.number().min(0.2).max(1).step(0.05).default(1).description('不透明度'),
127
+ speed: z.number().min(0.2).max(3).step(0.1).default(1.2).description('溜达速度倍率'),
128
+ wander: z.boolean().default(false).description('自己来回溜达'),
129
+ answerBubble: z.boolean().default(true).description('显示回答气泡(插入会话的回答)'),
130
+ idleBubble: z.boolean().default(true).description('显示碎碎念气泡(闲来自言自语)'),
131
+ greet: z.boolean().default(true).description('闲着的时候偶尔自言自语'),
132
+ marginBottom: z.number().min(0).max(400).step(1).default(0).description('离屏幕底部的距离'),
133
+ voice: z.boolean().default(true).description('说话时出声(用系统语音)'),
134
+ voiceMode: z
135
+ .union([z.const('babble'), z.const('tts')])
136
+ .default('babble')
137
+ .description('声音:babble 是内置咿呀音节声,tts 是系统朗读'),
138
+ voiceName: z.string().default('').description('音色(仅 tts 用):系统语音名,留空自动挑一个中文女声'),
139
+ voiceRate: z.number().min(0.5).max(2).step(0.05).default(1.05).description('语速'),
140
+ voicePitch: z.number().min(0.5).max(2).step(0.05).default(0.9).description('音调(越高越像小孩)'),
141
+ hotkey: z.string().default('mouse5').description('语音输入快捷键(Alt+V / Ctrl+Shift+M / mouse5 鼠标侧键 …)'),
142
+ hotkeyOn: z.boolean().default(true).description('启用语音快捷键'),
143
+ sfx: z.boolean().default(true).description('点她、跳起来时的音效'),
144
+ display: z.union([z.const('desktop'), z.const('none')]).default('desktop').description('桌面显示 / 隐藏(网页浮层已下线)'),
145
+ idleLines: z.string().default('').description('碎碎念内容,一行一句(全自定义,留空就不说)'),
146
+ idleEvery: z.number().min(1).max(999).step(1).default(20).description('隔多久说一句碎碎念'),
147
+ idleUnit: z.union([z.const('sec'), z.const('min'), z.const('hour')]).default('sec').description('碎碎念时间单位:秒 / 分钟 / 小时'),
148
+ actIcons: z.boolean().default(true).description('拖动图标:她闲下来会把桌面图标挪一挪(仅桌面模式)'),
149
+ actSit: z.boolean().default(true).description('随便坐:她闲下来会坐在桌面图标或窗口边沿上'),
150
+ carryEvery: z.number().default(5).description('两次搬图标的最小间隔;0 = 不限制'),
151
+ carryUnit: z
152
+ .union([z.const('sec'), z.const('min')])
153
+ .default('sec')
154
+ .description('搬运间隔的单位:sec 秒 / min 分钟'),
155
+ })
156
+
157
+ const TOOL_LABELS = {
158
+ read: '读文件',
159
+ read_file: '读文件',
160
+ read_multiple_files: '读文件',
161
+ write: '写文件',
162
+ write_file: '写文件',
163
+ edit: '改文件',
164
+ edit_file: '改文件',
165
+ multi_edit: '改文件',
166
+ glob: '找文件',
167
+ grep: '搜代码',
168
+ pwsh: '跑命令',
169
+ bash: '跑命令',
170
+ subagent: '派个小弟',
171
+ subagent_fork: '派个小弟',
172
+ web_search: '上网查',
173
+ web_fetch: '看网页',
174
+ generate_image: '画画',
175
+ edit_image: '修图',
176
+ todo_write: '列清单',
177
+ compress: '整理记忆',
178
+ decompress: '翻记忆',
179
+ search_context: '翻记忆',
180
+ skill: '翻手册',
181
+ workflow: '排流程',
182
+ plugin_manager: '装插件',
183
+ cordis_inspect_list: '看插件',
184
+ cordis_inspect_query: '看插件',
185
+ screen_look: '看屏幕',
186
+ screen_act: '动鼠标',
187
+ schedule_create: '定闹钟',
188
+ ask_user_question: '问 master',
189
+ create_goal: '立目标',
190
+ update_goal: '改目标',
191
+ present: '交作业',
192
+ }
193
+
194
+ const MIME = {
195
+ '.html': 'text/html; charset=utf-8',
196
+ '.htm': 'text/html; charset=utf-8',
197
+ '.css': 'text/css; charset=utf-8',
198
+ '.png': 'image/png',
199
+ '.jpg': 'image/jpeg',
200
+ '.jpeg': 'image/jpeg',
201
+ '.gif': 'image/gif',
202
+ '.webp': 'image/webp',
203
+ '.svg': 'image/svg+xml',
204
+ '.js': 'text/javascript; charset=utf-8',
205
+ '.mjs': 'text/javascript; charset=utf-8',
206
+ '.json': 'application/json; charset=utf-8',
207
+ '.ogg': 'audio/ogg',
208
+ }
209
+
210
+ function labelOf(tool) {
211
+ if (typeof tool !== 'string' || tool === '') return '忙别的'
212
+ const bare = tool.includes('__') ? tool.slice(tool.lastIndexOf('__') + 2) : tool
213
+ return TOOL_LABELS[bare] ?? TOOL_LABELS[tool] ?? bare.slice(0, 12)
214
+ }
215
+
216
+ function firstStringArg(args) {
217
+ if (args === null || typeof args !== 'object') return ''
218
+ for (const key of ['path', 'file_path', 'pattern', 'query', 'command', 'text', 'name', 'url', 'description']) {
219
+ const value = args[key]
220
+ if (typeof value === 'string' && value.trim() !== '') return value.trim()
221
+ }
222
+ for (const value of Object.values(args)) {
223
+ if (typeof value === 'string' && value.trim() !== '') return value.trim()
224
+ }
225
+ return ''
226
+ }
227
+
228
+ function clip(text, limit) {
229
+ const flat = String(text).replace(/\s+/g, ' ').trim()
230
+ if (flat.length <= limit) return flat
231
+ return `${flat.slice(0, limit)}…`
232
+ }
233
+
234
+ function sendJson(req, res, code, body) {
235
+ res.statusCode = code
236
+ res.setHeader('Content-Type', 'application/json; charset=utf-8')
237
+ res.setHeader('Cache-Control', 'no-store')
238
+ // 只允许受信任的本地 / DSH 渲染页跨源访问,避免任意网页读取状态或改动设置
239
+ const origin = req?.headers?.origin
240
+ if (origin && /^(?:https?:\/\/(?:127\.0\.0\.1|localhost)(?::\d+)?|dsh-app:\/\/app)$/i.test(origin)) {
241
+ res.setHeader('Access-Control-Allow-Origin', origin)
242
+ res.setHeader('Vary', 'Origin')
243
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type')
244
+ res.setHeader('Access-Control-Allow-Methods', 'GET,POST,OPTIONS')
245
+ }
246
+ res.end(JSON.stringify(body))
247
+ }
248
+
249
+ async function readBody(req) {
250
+ const chunks = []
251
+ for await (const chunk of req) chunks.push(chunk)
252
+ return Buffer.concat(chunks).toString('utf8')
253
+ }
254
+
255
+ // 二进制版:收 WAV 录音用
256
+ async function readBodyRaw(req) {
257
+ const chunks = []
258
+ for await (const chunk of req) chunks.push(chunk)
259
+ return Buffer.concat(chunks)
260
+ }
261
+
262
+ function normalize(raw) {
263
+ const next = { ...DEFAULTS }
264
+ if (raw && typeof raw === 'object') {
265
+ if (Object.hasOwn(SCHEMES, raw.look ?? '')) next.look = raw.look
266
+ if (Object.hasOwn(OUTFITS, raw.outfit ?? '')) next.outfit = raw.outfit
267
+ if (typeof raw.petName === 'string') next.petName = raw.petName.trim().slice(0, 20) || DEFAULTS.petName
268
+ if (typeof raw.menuOrder === 'string') next.menuOrder = raw.menuOrder.trim().slice(0, 200) || DEFAULTS.menuOrder
269
+ if (raw.menuOrderV2 === true) next.menuOrderV2 = true
270
+ // 一次性迁移:旧排序里没有的固定项(复位/原地/自由/来一个/换形象/换衣服)补到末尾,之后用户删了就不再补
271
+ if (next.menuOrderV2 !== true) {
272
+ const ids = next.menuOrder.split(',').map((s) => s.trim()).filter(Boolean)
273
+ for (const id of ['reset', 'stay', 'free', 'actions', 'look', 'outfit']) {
274
+ if (!ids.includes(id)) ids.push(id)
275
+ }
276
+ next.menuOrder = ids.join(',')
277
+ next.menuOrderV2 = true
278
+ }
279
+ // 二次迁移:重启DSH 上线,补进现有排序(close 后面),老用户删了不再补
280
+ if (raw.menuOrderV3 === true) next.menuOrderV3 = true
281
+ if (next.menuOrderV3 !== true) {
282
+ const ids = next.menuOrder.split(',').map((s) => s.trim()).filter(Boolean)
283
+ if (!ids.includes('restart')) {
284
+ const at = ids.indexOf('close')
285
+ ids.splice(at === -1 ? ids.length : at + 1, 0, 'restart')
286
+ }
287
+ next.menuOrder = ids.join(',')
288
+ next.menuOrderV3 = true
289
+ }
290
+ // 三次迁移:菜单全项可排序上线,「下班了」「回地面」补进现有排序(free 后 / 末尾),老用户删了不再补
291
+ if (raw.menuOrderV4 === true) next.menuOrderV4 = true
292
+ if (next.menuOrderV4 !== true) {
293
+ const ids = next.menuOrder.split(',').map((s) => s.trim()).filter(Boolean)
294
+ if (!ids.includes('duty')) {
295
+ const at = ids.indexOf('free')
296
+ ids.splice(at === -1 ? ids.length : at + 1, 0, 'duty')
297
+ }
298
+ if (!ids.includes('ground')) ids.push('ground')
299
+ next.menuOrder = ids.join(',')
300
+ next.menuOrderV4 = true
301
+ }
302
+ if (typeof raw.attachSession === 'string') next.attachSession = raw.attachSession.trim().slice(0, 200)
303
+ if (typeof raw.actOff === 'string') next.actOff = raw.actOff.trim().slice(0, 200)
304
+ if (typeof raw.voiceName === 'string') next.voiceName = raw.voiceName.trim()
305
+ if (typeof raw.hotkey === 'string') next.hotkey = raw.hotkey.trim().slice(0, 40)
306
+ if (typeof raw.hotkeyOn === 'boolean') next.hotkeyOn = raw.hotkeyOn
307
+ if (typeof raw.idleLines === 'string') next.idleLines = raw.idleLines.slice(0, 4000)
308
+ if (typeof raw.idleEvery === 'number' && isFinite(raw.idleEvery)) next.idleEvery = Math.min(999, Math.max(1, Math.round(raw.idleEvery)))
309
+ if (raw.idleUnit === 'sec' || raw.idleUnit === 'min' || raw.idleUnit === 'hour') next.idleUnit = raw.idleUnit
310
+ if (typeof raw.actIcons === 'boolean') next.actIcons = raw.actIcons
311
+ if (typeof raw.actSit === 'boolean') next.actSit = raw.actSit
312
+ if (typeof raw.carryEvery === 'number' && isFinite(raw.carryEvery)) next.carryEvery = Math.min(720, Math.max(0, Math.round(raw.carryEvery)))
313
+ if (raw.carryUnit === 'sec' || raw.carryUnit === 'min') next.carryUnit = raw.carryUnit
314
+ if (typeof raw.sfx === 'boolean') next.sfx = raw.sfx
315
+ if (raw.display === 'desktop' || raw.display === 'none') next.display = raw.display
316
+ // 老配置里的 web / both 一律并入桌面(网页浮层已下线)
317
+ if (raw.display === 'web' || raw.display === 'both') next.display = 'desktop'
318
+ if (raw.voiceMode === 'babble' || raw.voiceMode === 'tts') next.voiceMode = raw.voiceMode
319
+ const num = (value, min, max, fallback) => {
320
+ const n = Number(value)
321
+ return Number.isFinite(n) ? Math.min(max, Math.max(min, n)) : fallback
322
+ }
323
+ next.size = num(raw.size, 64, 420, DEFAULTS.size)
324
+ next.opacity = num(raw.opacity, 0.2, 1, DEFAULTS.opacity)
325
+ next.speed = num(raw.speed, 0.2, 3, DEFAULTS.speed)
326
+ next.marginBottom = num(raw.marginBottom, 0, 400, DEFAULTS.marginBottom)
327
+ next.voiceRate = num(raw.voiceRate, 0.5, 2, DEFAULTS.voiceRate)
328
+ next.voicePitch = num(raw.voicePitch, 0.5, 2, DEFAULTS.voicePitch)
329
+ for (const key of ['wander', 'answerBubble', 'idleBubble', 'greet', 'voice']) {
330
+ if (typeof raw[key] === 'boolean') next[key] = raw[key]
331
+ }
332
+ // 老配置迁移:单一 bubble 开关拆成 回答气泡 / 碎碎念气泡
333
+ if (raw.bubble === false && typeof raw.answerBubble !== 'boolean' && typeof raw.idleBubble !== 'boolean') {
334
+ next.answerBubble = false
335
+ next.idleBubble = false
336
+ }
337
+ }
338
+ return next
339
+ }
340
+
341
+ export function apply(ctx, config = {}) {
342
+ let settings = normalize({ ...config })
343
+ // 上一次应用失败时旧路由可能还挂着,这里兜一层,别把整条插件拖死
344
+ const safeRegister = (route) => {
345
+ try {
346
+ return ctx.webServer.register(route)
347
+ } catch (error) {
348
+ console.warn('[coo-pet] route already registered:', route && route.path, String(error))
349
+ return () => {}
350
+ }
351
+ }
352
+ let report = null
353
+ let lastHost = ''
354
+ let deskBootTimer = null
355
+
356
+ /* ---------- 插入会话:捕获回答流,投回气泡 ---------- */
357
+ let answerSeq = 0
358
+ let answerLast = null
359
+ let answerText = ''
360
+ // 气泡门(回合级配对,同 dsh-onebot-qq 的思路):桌宠对话框/语音问出去的问题(走 /prompt),
361
+ // 会在会话流里看到一条一模一样的 user/message——用内容前缀精确配对到她那一回合,
362
+ // 回合内的回答才进气泡;QQ、后台任务、web 控制台的回答一律不冒泡。
363
+ let petAsk = null // { sid, prefix, at } 桌宠刚问出去的话(等 user/message 配对)
364
+ let petTurnSid = '' // 配对成功的回合所在会话(配对成功→turn/end 之间有效)
365
+ let petTurnAt = 0
366
+ let petAttempt = '' // 这一回合的回答 attemptId(start 帧抓到后精确到流)
367
+ const PET_TURN_MS = 15 * 60 * 1000
368
+ const BUBBLE_START_MS = 20000 // 配对失败时的兑底:问出去 20 秒内出现的第一个新 attempt 算她的
369
+ const wantSession = () => String(settings.attachSession || '').trim()
370
+
371
+ // 插入会话的状态:ok = null 没填/未知,true 在列表里见过,false 确认跟丢了
372
+ const attachState = { ok: null, title: '', checkedAt: 0 }
373
+ let attachChecking = false
374
+ const checkAttach = async (force) => {
375
+ const id = wantSession()
376
+ if (!id) {
377
+ attachState.ok = null
378
+ attachState.title = ''
379
+ return
380
+ }
381
+ if (!force && attachState.ok !== null && Date.now() - attachState.checkedAt < 30000) return
382
+ if (attachChecking) return
383
+ attachChecking = true
384
+ try {
385
+ const controller = ctx.get('sessionController')
386
+ let hit = null
387
+ if (controller && typeof controller.listSessions === 'function') {
388
+ const list = await controller.listSessions()
389
+ const arr = Array.isArray(list) ? list : Array.isArray(list && list.sessions) ? list.sessions : []
390
+ hit = arr.find((item) => item && String(item.sessionId ?? item.id ?? item.sessionID ?? '') === id) || null
391
+ }
392
+ // 列表里见到只作「确认还活着」;查不到不算失败——listSessions 往往只返回最近活跃会话,
393
+ // 启动时列表经常为空,误判会开机就喊「跟丢了」。真正的失败只由 prompt 调用报错判定。
394
+ if (controller && hit) {
395
+ attachState.ok = true
396
+ attachState.title = String(hit.title ?? hit.name ?? hit.label ?? '')
397
+ attachState.checkedAt = Date.now()
398
+ } else {
399
+ attachState.checkedAt = Date.now()
400
+ }
401
+ } catch {
402
+ /* 列表读不到就保持现状 */
403
+ } finally {
404
+ attachChecking = false
405
+ }
406
+ }
407
+
408
+ const extractSession = (frame) => {
409
+ try {
410
+ const raw = JSON.stringify(frame)
411
+ const m = raw && raw.match(/"(?:sessionId|session_id|session)":\s*"([^"]+)"/)
412
+ return m ? m[1] : ''
413
+ } catch { return '' }
414
+ }
415
+
416
+ // 回合配对:监听会话事件,桌宠问出去的那条 user/message 出现时锁定她的回合
417
+ try {
418
+ ctx.on('session/event', (...args) => {
419
+ try {
420
+ const first = args[0]
421
+ const event = args.length > 1 ? args[1] : (first && (first.event || first.payload))
422
+ const type = event && event.type
423
+ if (!type) return
424
+ const holder = args.length > 1 ? first : (event && (event.session || first))
425
+ const sid = String((holder && (holder.id ?? holder.sessionId ?? holder.sessionID)) ?? (event && (event.sessionId ?? event.sessionID)) ?? '')
426
+ const blocksOf = (obj) => {
427
+ const data = (obj && obj.data) || obj || {}
428
+ const message = data.message || data
429
+ const blocks = Array.isArray(message.content) ? message.content : []
430
+ // 只收正文块(type 'text'):思考(thinking/reasoning)等其它块一律不算回答
431
+ return blocks
432
+ .filter((b) => {
433
+ if (typeof b === 'string') return true
434
+ if (!b || typeof b !== 'object') return false
435
+ const t = b.type
436
+ return (t === undefined || t === 'text') && typeof b.text === 'string'
437
+ })
438
+ .map((b) => (typeof b === 'string' ? b : b.text))
439
+ .join('')
440
+ }
441
+ if (type === 'user/message') {
442
+ // 桌宠刚问出去的那条话出现了:锁定这个会话的当前回合
443
+ if (!petAsk || !sid || sid !== petAsk.sid) return
444
+ const text = blocksOf(event).trim()
445
+ if (!text || !text.startsWith(petAsk.prefix)) return
446
+ petTurnSid = sid
447
+ petTurnAt = Date.now()
448
+ petAttempt = ''
449
+ answerText = ''
450
+ return
451
+ }
452
+ if (type === 'assistant/message') {
453
+ // 她这一回合的最终正文(完整版),覆盖流式累积的片段
454
+ if (!petTurnSid || sid !== petTurnSid) return
455
+ if (Date.now() - petTurnAt > PET_TURN_MS) return
456
+ // 带工具调用的消息是「边想边干」的中间段(如「我先查一下……」),不算回答——
457
+ // 最终结果是不带工具调用的那条正文
458
+ const data = (event && event.data) || event || {}
459
+ const message = data.message || data
460
+ const blocks = Array.isArray(message.content) ? message.content : []
461
+ const hasToolCall = blocks.some((b) => {
462
+ if (!b || typeof b !== 'object') return false
463
+ if (b.type === 'tool_use' || b.type === 'tool-call' || b.type === 'toolCall') return true
464
+ return Boolean(b.toolName || b.tool || (Array.isArray(b.toolCalls) && b.toolCalls.length))
465
+ })
466
+ if (hasToolCall) return
467
+ const text = blocksOf(event).trim()
468
+ if (!text) return
469
+ answerText = text.slice(0, 4000)
470
+ answerSeq += 1
471
+ answerLast = { seq: answerSeq, text: answerText.slice(0, 800), session: sid, at: Date.now() }
472
+ return
473
+ }
474
+ if (type === 'turn/end') {
475
+ // 回合结束:配对失效,之后的回答不再进气泡
476
+ if (petTurnSid && (!sid || sid === petTurnSid)) {
477
+ petTurnSid = ''
478
+ petAsk = null
479
+ }
480
+ }
481
+ } catch { /* ignore */ }
482
+ })
483
+ } catch {
484
+ /* 事件源不存在就跳过 */
485
+ }
486
+
487
+ for (const ev of ['agent/assistant-stream']) {
488
+ try {
489
+ ctx.on(ev, (payload) => {
490
+ try {
491
+ // 气泡跟着「她实际问的那个会话」走:对话框/语音问的是谁就接谁的回答,
492
+ // 不再依赖 attachSession——没填绑定会话(跟随控制台当前会话)也能冒泡
493
+ const want = petTurnSid || (petAsk && petAsk.sid) || wantSession()
494
+ if (!want) return
495
+ const turnLive = petTurnSid === want && Date.now() - petTurnAt < PET_TURN_MS
496
+ // 兑底:若回合配对没等到(事件形状变化),退回旧的时间窗判定
497
+ const fallbackLive = !petTurnSid && petAsk && petAsk.sid === want && Date.now() - petAsk.at < BUBBLE_START_MS
498
+ if (!turnLive && !fallbackLive) return
499
+ const frame = payload && payload.frame
500
+ const ftype = frame && frame.type
501
+ const attempt = frame && typeof frame.attemptId === 'string' ? frame.attemptId : ''
502
+ if (ftype === 'start') {
503
+ if (!petAttempt && attempt) {
504
+ petAttempt = attempt
505
+ answerText = ''
506
+ }
507
+ return
508
+ }
509
+ // 工具调用/结果帧:她进入「边想边干」状态——之前累积的中间独白清空,
510
+ // 之后的正文才是给用户的结果
511
+ if (typeof ftype === 'string' && /tool/i.test(ftype)) {
512
+ answerText = ''
513
+ return
514
+ }
515
+ if (ftype !== 'chunk') return
516
+ const sid = extractSession(frame || payload)
517
+ if (sid && sid !== want) return
518
+ // 精确配对:抓到了桌宠的 attempt 就只接它的 chunk;别的 attempt(QQ 等)一律不进气泡
519
+ if (petAttempt && attempt && attempt !== petAttempt) return
520
+ // 只收正文(text-delta),思考流(reasoning-delta)和工具调用一概不进气泡;正文按顺序累积
521
+ const chunk = frame && frame.chunk
522
+ if (!chunk || chunk.type !== 'text-delta') return
523
+ const piece = typeof chunk.text === 'string' ? chunk.text : ''
524
+ if (!piece) return
525
+ answerText = (answerText + piece).slice(0, 4000)
526
+ answerSeq += 1
527
+ answerLast = { seq: answerSeq, text: answerText.slice(0, 800), session: sid || want, at: Date.now() }
528
+ if (sid === want || !sid) attachState.ok = true
529
+ } catch { /* ignore */ }
530
+ })
531
+ } catch {
532
+ /* 事件源不存在就跳过 */
533
+ }
534
+ }
535
+
536
+ // 桌面窗要连的地址:优先问 webServer,其次用最近一次请求的 Host
537
+ function realOrigin() {
538
+ const strip = (v) => String(v).replace(/^https?:\/\//, '').replace(/\/+$/, '')
539
+ try {
540
+ const got = ctx.webServer && (ctx.webServer.getOrigin ? ctx.webServer.getOrigin() : ctx.webServer.origin)
541
+ if (typeof got === 'string' && got) return strip(got)
542
+ } catch {
543
+ /* ignore */
544
+ }
545
+ if (lastHost) return strip(lastHost)
546
+ try {
547
+ const addr = ctx.webServer && ctx.webServer.server && ctx.webServer.server.address ? ctx.webServer.server.address() : null
548
+ if (addr && addr.port) return '127.0.0.1:' + addr.port
549
+ } catch {
550
+ /* ignore */
551
+ }
552
+ return '127.0.0.1:54869'
553
+ }
554
+ let lastSay = null
555
+ let actSeq = 0
556
+ let actLast = null
557
+ let saySeq = 0
558
+ let sayLast = null
559
+ let voiceSeq = 0
560
+ let voiceLast = null
561
+ const reports = {}
562
+
563
+ readFile(SETTINGS_FILE, 'utf8')
564
+ .catch(() => readFile(LEGACY_SETTINGS_FILE, 'utf8'))
565
+ .then((text) => {
566
+ const raw = JSON.parse(text)
567
+ const next = normalize({ ...settings, ...raw })
568
+ const migrated = next.menuOrder !== String(raw.menuOrder ?? '')
569
+ settings = next
570
+ // 菜单迁移只走内存的话,重启会复活用户删掉的项——迁移过就立刻落盘
571
+ if (migrated) persist().catch(() => {})
572
+ })
573
+ .catch(() => {
574
+ /* 第一次跑,没有文件就是对的 */
575
+ })
576
+
577
+ const persist = async () => {
578
+ await mkdir(dirname(SETTINGS_FILE), { recursive: true })
579
+ await writeFile(SETTINGS_FILE, JSON.stringify(settings, null, 2), 'utf8')
580
+ }
581
+
582
+ const state = { seq: 0, mood: 'idle', status: 'idle', note: '', bubble: null, updatedAt: Date.now() }
583
+
584
+ const bump = (patch) => {
585
+ Object.assign(state, patch)
586
+ state.seq += 1
587
+ state.updatedAt = Date.now()
588
+ }
589
+
590
+ ctx.on('agent/status', (payload) => {
591
+ const status = payload && payload.status === 'running' ? 'running' : 'idle'
592
+ if (status === 'running') bump({ status, mood: state.mood === 'oops' ? 'oops' : 'think' })
593
+ else bump({ status, mood: 'idle', note: '' })
594
+ })
595
+
596
+ ctx.on('tools/pre-execute', (exec, next) => {
597
+ try {
598
+ const tool = exec && (exec.name ?? exec.tool ?? exec.toolName)
599
+ const args = exec && (exec.args ?? exec.arguments ?? exec.input)
600
+ const extra = clip(firstStringArg(args), 28)
601
+ const label = labelOf(tool)
602
+ bump({
603
+ status: 'running',
604
+ mood: 'work',
605
+ note: extra === '' ? label : `${label} · ${extra}`,
606
+ bubble: { text: extra === '' ? label : `${label}:${extra}`, at: Date.now() },
607
+ })
608
+ } catch {
609
+ /* never break dispatch */
610
+ }
611
+ return next()
612
+ })
613
+
614
+ ctx.on('tools/result', (exec, result) => {
615
+ try {
616
+ const failed = result && (result.isError === true || result.error !== undefined || result.ok === false)
617
+ if (failed) bump({ mood: 'oops', note: '出错了…' })
618
+ } catch {
619
+ /* ignore */
620
+ }
621
+ })
622
+
623
+ const disposers = []
624
+
625
+ disposers.push(
626
+ safeRegister({
627
+ kind: 'exact',
628
+ path: '/dsh-coo-pet/pulse',
629
+ handler: async (req, res) => {
630
+ const url = new URL(req.url ?? '/dsh-coo-pet/pulse', 'http://localhost')
631
+ const since = Number(url.searchParams.get('since') ?? '0')
632
+ sendJson(req, res, 200, {
633
+ ok: true,
634
+ changed: state.seq !== since,
635
+ seq: state.seq,
636
+ mood: state.mood,
637
+ status: state.status,
638
+ note: state.note,
639
+ bubble: state.bubble,
640
+ updatedAt: state.updatedAt,
641
+ })
642
+ },
643
+ })
644
+ )
645
+
646
+ const describe = (req) => {
647
+ // 插入会话状态懒校验:桌面窗 3 秒一轮 prefs,这里节流 30 秒查一次会话列表
648
+ checkAttach().catch(() => {})
649
+ return {
650
+ ok: true,
651
+ config: settings,
652
+ base: `http://${req?.headers?.host ?? '127.0.0.1'}`,
653
+ looks: Object.keys(SCHEMES).map((id) => ({ id, label: SCHEMES[id], thumb: `/dsh-coo-pet/pet/asset?p=${encodeURIComponent(`whale/thumbs/${id}.png`)}` })),
654
+ outfits: Object.keys(OUTFITS).map((id) => ({ id, label: OUTFITS[id], thumb: `/dsh-coo-pet/pet/asset?p=${encodeURIComponent(`whale/thumbs/${id}.png`)}` })),
655
+ defaults: DEFAULTS,
656
+ settingsFile: SETTINGS_FILE,
657
+ attach: { id: wantSession(), ok: attachState.ok, title: attachState.title, checkedAt: attachState.checkedAt },
658
+ busy: state.status === 'running',
659
+ lastActiveAt: state.updatedAt,
660
+ mood: state.mood,
661
+ }
662
+ }
663
+
664
+ disposers.push(
665
+ safeRegister({
666
+ kind: 'exact',
667
+ path: '/dsh-coo-pet/prefs',
668
+ handler: async (req, res) => {
669
+ if (req.method === 'POST') {
670
+ try {
671
+ lastHost = req.headers.host ?? lastHost
672
+ const body = JSON.parse((await readBody(req)) || '{}')
673
+ settings = normalize({ ...settings, ...body })
674
+ await persist()
675
+ state.seq += 1
676
+ state.updatedAt = Date.now()
677
+ syncDesk(settings.display)
678
+ sendJson(req, res, 200, describe(req))
679
+ } catch (error) {
680
+ sendJson(req, res, 400, { ok: false, error: String(error && error.message ? error.message : error) })
681
+ }
682
+ return
683
+ }
684
+ lastHost = req.headers.host ?? lastHost
685
+ sendJson(req, res, 200, describe(req))
686
+ },
687
+ })
688
+ )
689
+
690
+ disposers.push(
691
+ safeRegister({
692
+ kind: 'exact',
693
+ path: '/dsh-coo-pet/config',
694
+ handler: async (req, res) => {
695
+ sendJson(req, res, 200, describe(req))
696
+ },
697
+ })
698
+ )
699
+
700
+ disposers.push(
701
+ safeRegister({
702
+ kind: 'exact',
703
+ path: '/dsh-coo-pet/bubble',
704
+ handler: async (req, res) => {
705
+ if (req.method !== 'POST') {
706
+ sendJson(req, res, 405, { ok: false, error: 'POST only' })
707
+ return
708
+ }
709
+ try {
710
+ const body = JSON.parse((await readBody(req)) || '{}')
711
+ const text = typeof body.text === 'string' ? body.text.trim() : ''
712
+ if (text === '') {
713
+ sendJson(req, res, 400, { ok: false, error: 'text 必填' })
714
+ return
715
+ }
716
+ bump({ mood: typeof body.mood === 'string' ? body.mood : 'happy', bubble: { text: clip(text, 90), at: Date.now() } })
717
+ sendJson(req, res, 200, { ok: true })
718
+ } catch (error) {
719
+ sendJson(req, res, 400, { ok: false, error: String(error && error.message ? error.message : error) })
720
+ }
721
+ },
722
+ })
723
+ )
724
+
725
+ disposers.push(
726
+ safeRegister({
727
+ kind: 'exact',
728
+ path: '/dsh-coo-pet/build',
729
+ handler: async (req, res) => {
730
+ let version = VERSION
731
+ try {
732
+ version = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version
733
+ } catch {
734
+ /* 读不到就用启动时那份 */
735
+ }
736
+ sendJson(req, res, 200, { ok: true, version })
737
+ },
738
+ })
739
+ )
740
+ disposers.push(
741
+
742
+ safeRegister({
743
+ kind: 'exact',
744
+ path: '/dsh-coo-pet/report',
745
+ handler: async (req, res) => {
746
+ if (req.method === 'POST') {
747
+ try {
748
+ report = { ...JSON.parse((await readBody(req)) || '{}'), at: Date.now() }
749
+ if (report && report.status) {
750
+ reports[report.status] = report
751
+ if (Object.keys(reports).length > 24) delete reports[Object.keys(reports)[0]]
752
+ // 诊断:每条上报都落一份到日志(报告接口只留每类最新一条,时间线会被冲掉)
753
+ try {
754
+ const { appendFile } = await import('node:fs/promises')
755
+ await appendFile(
756
+ new URL('./coo-reports.log', import.meta.url),
757
+ new Date().toISOString() + ' ' + report.status + ' ' + JSON.stringify(report).slice(0, 500) + '\n'
758
+ )
759
+ } catch {
760
+ /* ignore */
761
+ }
762
+ }
763
+ } catch {
764
+ report = { status: 'error', message: 'bad json', at: Date.now() }
765
+ }
766
+ sendJson(req, res, 200, { ok: true })
767
+ return
768
+ }
769
+ sendJson(req, res, 200, { ok: true, report, reports })
770
+ },
771
+ })
772
+ )
773
+
774
+ // 动作口:设置页的「试一下」把动作广播给桌面那只
775
+ disposers.push(
776
+ safeRegister({
777
+ kind: 'exact',
778
+ path: '/dsh-coo-pet/act',
779
+ handler: async (req, res) => {
780
+ if (req.method === 'POST') {
781
+ let body = {}
782
+ try {
783
+ body = JSON.parse((await readBody(req)) || '{}')
784
+ } catch {
785
+ sendJson(req, res, 400, { ok: false, error: 'bad json' })
786
+ return
787
+ }
788
+ const act = String(body.act ?? '').trim().slice(0, 24)
789
+ if (!act) {
790
+ sendJson(req, res, 400, { ok: false, error: 'empty' })
791
+ return
792
+ }
793
+ actSeq += 1
794
+ // launch 带名字:语音「打开XX」经 act 队列传给桌面的那只
795
+ actLast = { seq: actSeq, act, name: String(body.name ?? '').trim().slice(0, 60), at: Date.now() }
796
+ sendJson(req, res, 200, { ok: true, seq: actSeq })
797
+ return
798
+ }
799
+ const since = Number(new URL(req.url ?? '/', 'http://x').searchParams.get('since') ?? 0) || 0
800
+ sendJson(req, res, 200, { ok: true, seq: actSeq, act: actSeq > since ? actLast : null })
801
+ },
802
+ })
803
+ )
804
+
805
+ // 说话口:设置页的「试听」「测试」把一句话送到桌面那只
806
+ disposers.push(
807
+ safeRegister({
808
+ kind: 'exact',
809
+ path: '/dsh-coo-pet/say',
810
+ handler: async (req, res) => {
811
+ if (req.method === 'POST') {
812
+ let body = {}
813
+ try {
814
+ body = JSON.parse((await readBody(req)) || '{}')
815
+ } catch {
816
+ sendJson(req, res, 400, { ok: false, error: 'bad json' })
817
+ return
818
+ }
819
+ const text = String(body.text ?? '').trim().slice(0, 200)
820
+ const mode = body.mode === 'tts' ? 'tts' : body.mode === 'babble' ? 'babble' : ''
821
+ if (!text) {
822
+ sendJson(req, res, 400, { ok: false, error: 'empty' })
823
+ return
824
+ }
825
+ saySeq += 1
826
+ sayLast = { seq: saySeq, text, mode, at: Date.now() }
827
+ sendJson(req, res, 200, { ok: true, seq: saySeq })
828
+ return
829
+ }
830
+ const since = Number(new URL(req.url ?? '/', 'http://x').searchParams.get('since') ?? 0) || 0
831
+ sendJson(req, res, 200, { ok: true, seq: saySeq, say: saySeq > since ? sayLast : null })
832
+ },
833
+ })
834
+ )
835
+
836
+ // 麦克风开关广播:桌面窗口按快捷键 → 网页浮层那边真正开口
837
+ disposers.push(
838
+ safeRegister({
839
+ kind: 'exact',
840
+ path: '/dsh-coo-pet/voice',
841
+ handler: async (req, res) => {
842
+ if (req.method === 'POST') {
843
+ let body = {}
844
+ try {
845
+ body = JSON.parse((await readBody(req)) || '{}')
846
+ } catch {
847
+ sendJson(req, res, 400, { ok: false, error: 'bad json' })
848
+ return
849
+ }
850
+ voiceSeq += 1
851
+ voiceLast = { seq: voiceSeq, on: body.on === true, at: Date.now() }
852
+ sendJson(req, res, 200, { ok: true, seq: voiceSeq })
853
+ return
854
+ }
855
+ const since = Number(new URL(req.url ?? '/', 'http://x').searchParams.get('since') ?? 0) || 0
856
+ sendJson(req, res, 200, { ok: true, seq: voiceSeq, voice: voiceSeq > since ? voiceLast : null })
857
+ },
858
+ })
859
+ )
860
+
861
+ // 语音识别的文字口:识别中(interim)/最终(final)都发这里,
862
+ // 桌面窗轮询拿去填进她的输入框,最终一句由桌面自己走提交流程(含「打开XX」本地指令)
863
+ let voiceTextSeq = 0
864
+ let voiceTextLast = null
865
+ disposers.push(
866
+ safeRegister({
867
+ kind: 'exact',
868
+ path: '/dsh-coo-pet/voicetext',
869
+ handler: async (req, res) => {
870
+ if (req.method === 'POST') {
871
+ try {
872
+ const body = JSON.parse((await readBody(req)) || '{}')
873
+ const text = String(body.text ?? '').slice(0, 2000)
874
+ voiceTextSeq += 1
875
+ voiceTextLast = { seq: voiceTextSeq, text, final: body.final === true, at: Date.now() }
876
+ sendJson(req, res, 200, { ok: true, seq: voiceTextSeq })
877
+ } catch (error) {
878
+ sendJson(req, res, 400, { ok: false, error: String(error && error.message ? error.message : error) })
879
+ }
880
+ return
881
+ }
882
+ const since = Number(new URL(req.url ?? '/', 'http://x').searchParams.get('since') ?? 0) || 0
883
+ sendJson(req, res, 200, { ok: true, seq: voiceTextSeq, text: voiceTextSeq > since ? voiceTextLast : null })
884
+ },
885
+ })
886
+ )
887
+
888
+ // 本地语音识别口:桌面窗把录到的 WAV(16kHz 单声)POST 上来,
889
+ // 用本机 whisper.cpp(whisper-cli)转写——不联网、不吃 Google 服务。
890
+ // 桌面端录音期间每几秒发一次全量录音(partial=1)当"中间结果",
891
+ // 松开后再发一次(final)当最终结果。
892
+ const WHISPER_EXE = process.env.DSH_WHISPER
893
+ ?? join(dirname(HOME), 'tools', 'whisper', 'Release', 'whisper-cli.exe')
894
+ const WHISPER_MODEL_DIR = process.env.DSH_AUDIO_MODELS
895
+ ?? join(HOME, 'audio-models')
896
+ const WHISPER_MODEL = join(WHISPER_MODEL_DIR, 'ggml-base.bin')
897
+ // whisper 单进程:忙时不拒请求,改成排队(中间刷新和松手后的最终转写会
898
+ // 几乎同时到达,拒掉忙的那次会把最终结果弄丢)
899
+ let whisperQueue = Promise.resolve()
900
+ const runWhisperQueued = (wav) => {
901
+ const job = whisperQueue.then(() => runWhisper(wav), () => runWhisper(wav))
902
+ whisperQueue = job.then(() => {}, () => {})
903
+ return job
904
+ }
905
+ const runWhisper = async (wav) => {
906
+ if (!existsSync(WHISPER_EXE)) return { ok: false, error: '没找到 whisper-cli(' + WHISPER_EXE + ')' }
907
+ if (!existsSync(WHISPER_MODEL)) return { ok: false, error: '没找到 whisper 模型(' + WHISPER_MODEL + ')' }
908
+ try {
909
+ const tmp = join(WHISPER_MODEL_DIR, '.coo-utterance.wav')
910
+ await writeFile(tmp, wav)
911
+ return await new Promise((resolve) => {
912
+ const child = spawn(WHISPER_EXE, ['-m', WHISPER_MODEL, '-l', 'zh', '-nt', '-np', '-f', tmp], {
913
+ windowsHide: true,
914
+ timeout: 20000,
915
+ })
916
+ let out = ''
917
+ child.stdout.on('data', (d) => { out += String(d) })
918
+ child.on('error', (error) => resolve({ ok: false, error: String((error && error.message) || error) }))
919
+ child.on('close', (code) => {
920
+ // whisper-cli 文本行:去掉空行和 [00:00:00.000] 之类残留
921
+ const text = out
922
+ .split('\n')
923
+ .map((line) => line.replace(/^\[\d{2}:\d{2}:\d{2}\.\d{3}\]\s*/, '').trim())
924
+ .filter((line) => line && !/^\[/.test(line))
925
+ .join('')
926
+ .trim()
927
+ resolve({ ok: code === 0, text, code })
928
+ })
929
+ })
930
+ } catch (error) {
931
+ return { ok: false, error: String((error && error.message) || error) }
932
+ }
933
+ }
934
+ disposers.push(
935
+ safeRegister({
936
+ kind: 'exact',
937
+ path: '/dsh-coo-pet/voicerec',
938
+ handler: async (req, res) => {
939
+ if (req.method !== 'POST') {
940
+ sendJson(req, res, 405, { ok: false, error: 'POST only' })
941
+ return
942
+ }
943
+ const isFinal = new URL(req.url ?? '/', 'http://x').searchParams.get('final') === '1'
944
+ try {
945
+ const wav = await readBodyRaw(req)
946
+ if (!wav || wav.length < 2000) {
947
+ sendJson(req, res, 200, { ok: false, error: 'empty' })
948
+ return
949
+ }
950
+ const r = await runWhisperQueued(wav)
951
+ sendJson(req, res, 200, { ok: r.ok, text: r.text ?? '', error: r.error, final: isFinal })
952
+ } catch (error) {
953
+ sendJson(req, res, 500, { ok: false, error: String((error && error.message) || error) })
954
+ }
955
+ },
956
+ })
957
+ )
958
+
959
+ // 会话列表:设置页「插入会话」的下拉候选(sessionController 的方法名各版本可能不同,逐个试)
960
+ disposers.push(
961
+ safeRegister({
962
+ kind: 'exact',
963
+ path: '/dsh-coo-pet/sessions',
964
+ handler: async (req, res) => {
965
+ const out = []
966
+ let used = ''
967
+ try {
968
+ const controller = ctx.get('sessionController')
969
+ if (controller) {
970
+ for (const name of ['listSessions', 'list', 'sessions', 'all']) {
971
+ if (typeof controller[name] !== 'function') continue
972
+ used = name
973
+ const got = await controller[name]()
974
+ const arr = Array.isArray(got) ? got : Array.isArray(got && got.sessions) ? got.sessions : []
975
+ for (const item of arr) {
976
+ if (typeof item === 'string') out.push({ id: item })
977
+ else if (item && typeof item === 'object') {
978
+ const id = item.id ?? item.sessionId ?? item.sessionID
979
+ if (id) out.push({ id: String(id), title: String(item.title ?? item.name ?? item.label ?? '') })
980
+ }
981
+ if (out.length >= 50) break
982
+ }
983
+ break
984
+ }
985
+ }
986
+ } catch {
987
+ /* 列表拿不到就算了,返回空 */
988
+ }
989
+ sendJson(req, res, 200, { ok: true, used, sessions: out })
990
+ },
991
+ })
992
+ )
993
+
994
+ // 插入会话的回答口:桌面的那只轮询它,把回答放进气泡并朗读
995
+ disposers.push(
996
+ safeRegister({
997
+ kind: 'exact',
998
+ path: '/dsh-coo-pet/answer',
999
+ handler: async (req, res) => {
1000
+ const since = Number(new URL(req.url ?? '/', 'http://x').searchParams.get('since') ?? 0) || 0
1001
+ sendJson(req, res, 200, { ok: true, seq: answerSeq, answer: answerSeq > since ? answerLast : null })
1002
+ },
1003
+ })
1004
+ )
1005
+
1006
+ // 桌宠说话口 → 把一句话送进当前会话
1007
+ disposers.push(
1008
+ safeRegister({
1009
+ kind: 'exact',
1010
+ path: '/dsh-coo-pet/prompt',
1011
+ handler: async (req, res) => {
1012
+ if (req.method !== 'POST') {
1013
+ sendJson(req, res, 405, { ok: false, error: 'method' })
1014
+ return
1015
+ }
1016
+ let body = {}
1017
+ try {
1018
+ body = JSON.parse((await readBody(req)) || '{}')
1019
+ } catch {
1020
+ sendJson(req, res, 400, { ok: false, error: 'bad json' })
1021
+ return
1022
+ }
1023
+ const text = String(body.text ?? '').trim().slice(0, 4000)
1024
+ const sessionId = String(body.sessionId ?? '').trim()
1025
+ // 只认绑定的会话:填了谁就问谁,不填不说话——绝不猜会话(猜到 IM 专属会话会把回答桥接发走)
1026
+ if (!sessionId) {
1027
+ sendJson(req, res, 400, { ok: false, error: '未绑定会话:先在设置里填 Session ID' })
1028
+ return
1029
+ }
1030
+ if (!text) {
1031
+ sendJson(req, res, 400, { ok: false, error: 'empty' })
1032
+ return
1033
+ }
1034
+ const controller = ctx.get('sessionController')
1035
+ if (!controller) {
1036
+ sendJson(req, res, 503, { ok: false, error: 'sessionController 不可用' })
1037
+ return
1038
+ }
1039
+ try {
1040
+ // 开启气泡门:登记这次提问(目标会话 + 内容前缀),等会话流里出现同样的 user/message 来配对回合
1041
+ petAsk = { sid: sessionId || wantSession(), prefix: text.trim().slice(0, 24), at: Date.now() }
1042
+ petAttempt = ''
1043
+ petTurnSid = ''
1044
+ // 投递模式固定 queue(排队):绝不往正在跑的回合里插话(steer)——
1045
+ // 桌宠的会话和 B站任务/写日记共用的会话是同一个,插话会把桌宠的问题混进
1046
+ // 她手头的活儿里,同一个回合的回答就可能被带着串台。排队让桌宠的
1047
+ // 问题单独成回合、单独被回答;她忙时话先排着,忙完才轮到。
1048
+ const request = () => ({
1049
+ requestId: `coo-pet-${Date.now()}-${Math.floor(Math.random() * 1e6)}`,
1050
+ sessionId,
1051
+ content: [{ type: 'text', text }],
1052
+ clientTimeZone: 'Asia/Shanghai',
1053
+ })
1054
+ try {
1055
+ const list = typeof controller.listSessions === 'function' ? await controller.listSessions() : null
1056
+ const arr = Array.isArray(list) ? list : Array.isArray(list && list.sessions) ? list.sessions : []
1057
+ const items = arr.filter((item) => item && typeof item === 'object')
1058
+ .filter((item) => String(item.sessionId ?? item.id ?? '') === sessionId)
1059
+ const hit = items[0]
1060
+ // 列表没扫到不算失败,真正的失败由下面 prompt 的报错判定
1061
+ if (hit) {
1062
+ attachState.ok = true
1063
+ attachState.title = String(hit.title ?? hit.name ?? hit.label ?? '')
1064
+ attachState.checkedAt = Date.now()
1065
+ }
1066
+ } catch {
1067
+ /* 列表拿不到不影响发送 */
1068
+ }
1069
+ await controller.prompt({ ...request(), mode: 'queue' }, AbortSignal.timeout(15000))
1070
+ lastSay = { text, sessionId, at: Date.now(), ok: true }
1071
+ if (sessionId) {
1072
+ attachState.ok = true
1073
+ attachState.checkedAt = Date.now()
1074
+ }
1075
+ sendJson(req, res, 200, { ok: true })
1076
+ } catch (error) {
1077
+ const message = String(error && error.message ? error.message : error)
1078
+ lastSay = { text, sessionId, at: Date.now(), ok: false, message }
1079
+ if (sessionId) {
1080
+ attachState.ok = false
1081
+ attachState.checkedAt = Date.now()
1082
+ }
1083
+ sendJson(req, res, 502, { ok: false, error: message })
1084
+ }
1085
+ },
1086
+ })
1087
+ )
1088
+
1089
+ const servePetFile = async (req, res, relative) => {
1090
+ const safe = normalizePath(relative).replace(/^([.][.][/\\])+/, '')
1091
+ const abs = join(PET_ROOT, safe)
1092
+ if (!abs.startsWith(PET_ROOT)) {
1093
+ res.statusCode = 403
1094
+ res.end('forbidden')
1095
+ return
1096
+ }
1097
+ try {
1098
+ const info = await stat(abs)
1099
+ if (!info.isFile()) throw new Error('not a file')
1100
+ const data = await readFile(abs)
1101
+ res.setHeader('Content-Type', MIME[extname(abs).toLowerCase()] ?? 'application/octet-stream')
1102
+ res.setHeader('Cache-Control', 'no-store')
1103
+ const origin = req?.headers?.origin
1104
+ if (origin && /^(?:https?:\/\/(?:127\.0\.0\.1|localhost)(?::\d+)?|dsh-app:\/\/app)$/i.test(origin)) {
1105
+ res.setHeader('Access-Control-Allow-Origin', origin)
1106
+ res.setHeader('Vary', 'Origin')
1107
+ }
1108
+ res.end(data)
1109
+ } catch (error) {
1110
+ res.statusCode = 404
1111
+ res.setHeader('Content-Type', 'text/plain; charset=utf-8')
1112
+ res.end(`没有这个文件:${safe}`)
1113
+ }
1114
+ }
1115
+
1116
+ for (const rel of ['kit/body.js', 'kit/rig.js', 'whale/figure.js', 'whale/model.json', 'desk.html']) {
1117
+ disposers.push(
1118
+ safeRegister({
1119
+ kind: 'exact',
1120
+ path: `/dsh-coo-pet/pet/${rel}`,
1121
+ handler: async (req, res) => servePetFile(req, res, rel),
1122
+ })
1123
+ )
1124
+ }
1125
+
1126
+ disposers.push(
1127
+ safeRegister({
1128
+ kind: 'exact',
1129
+ path: '/dsh-coo-pet/pet/asset',
1130
+ handler: async (req, res) => {
1131
+ const url = new URL(req.url ?? '/dsh-coo-pet/pet/asset', 'http://localhost')
1132
+ const rel = url.searchParams.get('p') ?? ''
1133
+ if (rel === '') {
1134
+ res.statusCode = 400
1135
+ res.end('missing p')
1136
+ return
1137
+ }
1138
+ await servePetFile(req, res, rel)
1139
+ },
1140
+ })
1141
+ )
1142
+
1143
+ // ---- 桌面显示:在桌面上开一个透明小窗(Electron),可以和网页浮层并存 ----
1144
+ const DESK_MAIN = fileURLToPath(new URL('./assets/desk-main.cjs', import.meta.url))
1145
+ const ELECTRON_CANDIDATES = [
1146
+ process.env.DSH_ELECTRON,
1147
+ join(HOME, 'electron', 'electron.exe'),
1148
+ join(process.env.USERPROFILE ?? '', '.dsh', 'electron', 'electron.exe'),
1149
+ ]
1150
+ let deskProc = null
1151
+
1152
+ const findElectron = () => {
1153
+ for (const candidate of ELECTRON_CANDIDATES) {
1154
+ try {
1155
+ if (existsSync(candidate)) return candidate
1156
+ } catch {
1157
+ /* ignore */
1158
+ }
1159
+ }
1160
+ return null
1161
+ }
1162
+
1163
+ const spawnDesk = () => {
1164
+ if (deskProc) return deskProc
1165
+ const exe = findElectron()
1166
+ if (!exe) {
1167
+ console.warn('[coo-pet] 没找到 electron,桌面显示开不了')
1168
+ return null
1169
+ }
1170
+ const origin = realOrigin()
1171
+ const url = `http://${origin}/dsh-coo-pet/pet/desk.html`
1172
+ const env = { ...process.env }
1173
+ delete env.ELECTRON_RUN_AS_NODE
1174
+ try {
1175
+ deskProc = spawn(exe, [DESK_MAIN, `--url=${url}`], {
1176
+ env,
1177
+ detached: false,
1178
+ stdio: 'ignore',
1179
+ })
1180
+ deskProc.on('exit', () => {
1181
+ deskProc = null
1182
+ })
1183
+ } catch (error) {
1184
+ console.warn('[coo-pet] 桌面窗口起不来:', String(error))
1185
+ deskProc = null
1186
+ }
1187
+ return deskProc
1188
+ }
1189
+
1190
+ const syncDesk = (display) => {
1191
+ const want = display !== 'none'
1192
+ if (want) spawnDesk()
1193
+ else if (deskProc) {
1194
+ try {
1195
+ deskProc.kill()
1196
+ } catch {
1197
+ /* ignore */
1198
+ }
1199
+ deskProc = null
1200
+ }
1201
+ }
1202
+
1203
+ // 记下来,disposer 里要清掉;否则插件关掉后还会蹦出一个没人管的窗口
1204
+ deskBootTimer = setTimeout(() => {
1205
+ deskBootTimer = null
1206
+ syncDesk(settings.display)
1207
+ }, 2500)
1208
+
1209
+ disposers.push(
1210
+ safeRegister({
1211
+ kind: 'exact',
1212
+ path: '/dsh-coo-pet/open',
1213
+ handler: async (req, res) => {
1214
+ if (req.method !== 'POST') {
1215
+ sendJson(req, res, 405, { ok: false, error: 'POST only' })
1216
+ return
1217
+ }
1218
+ let target = ''
1219
+ try {
1220
+ target = String(JSON.parse((await readBody(req)) || '{}').target ?? '')
1221
+ } catch {
1222
+ target = ''
1223
+ }
1224
+ const launch = (file, args = []) => {
1225
+ const env = { ...process.env }
1226
+ delete env.ELECTRON_RUN_AS_NODE
1227
+ const child = spawn(file, args, { env, detached: true, stdio: 'ignore' })
1228
+ child.unref()
1229
+ return true
1230
+ }
1231
+ try {
1232
+ if (target === 'dsh') {
1233
+ // DSH 本体(DeepSeek Harness):环境变量优先,其次默认安装位置
1234
+ const exe = process.env.DSH_EXE
1235
+ ?? join(process.env.LOCALAPPDATA ?? '', 'Programs', 'DeepSeek Harness', 'DeepSeek Harness.exe')
1236
+ if (!exe || !existsSync(exe)) throw new Error('没找到 DSH(DeepSeek Harness),可用环境变量 DSH_EXE 指定')
1237
+ launch(exe)
1238
+ } else if (target === 'folder') {
1239
+ launch('explorer.exe', [PLUGIN_DIR])
1240
+ } else if (target === 'desktop') {
1241
+ spawnDesk()
1242
+ } else if (target === 'settings') {
1243
+ launch('explorer.exe', [SETTINGS_FILE])
1244
+ } else {
1245
+ throw new Error(`不认识的 target:${target}`)
1246
+ }
1247
+ sendJson(req, res, 200, { ok: true })
1248
+ } catch (error) {
1249
+ sendJson(req, res, 400, { ok: false, error: String(error && error.message ? error.message : error) })
1250
+ }
1251
+ },
1252
+ })
1253
+ )
1254
+
1255
+ ctx.effect(() => () => {
1256
+ if (deskBootTimer) {
1257
+ clearTimeout(deskBootTimer)
1258
+ deskBootTimer = null
1259
+ }
1260
+ try {
1261
+ deskProc?.kill()
1262
+ } catch {
1263
+ /* ignore */
1264
+ }
1265
+ for (const dispose of disposers) {
1266
+ try {
1267
+ dispose()
1268
+ } catch {
1269
+ /* ignore */
1270
+ }
1271
+ }
1272
+ })
1273
+ }