@alipay/alipay-aipay 1.7.0 → 1.7.2

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 (169) hide show
  1. package/README.md +30 -0
  2. package/dist/commands/install-current.js +15 -7
  3. package/dist/commands/install.js +20 -16
  4. package/dist/commands/uninstall.js +8 -3
  5. package/dist/commands/update.js +34 -16
  6. package/dist/index.js +10 -4
  7. package/dist/utils/channels.js +67 -0
  8. package/dist/utils/config.js +15 -11
  9. package/dist/utils/file.js +23 -10
  10. package/dist/utils/npm.js +19 -33
  11. package/package.json +8 -3
  12. package/skill/SKILL.md +2 -0
  13. package/skill/references/normal/json/release-channel.json +1 -0
  14. package/skill/references/normal/scripts/self_update.mjs +62 -17
  15. package/skill/references/normal/self-update.md +3 -1
  16. package/skill-pre/SKILL.md +65 -0
  17. package/skill-pre/VERSION +1 -0
  18. package/skill-pre/references/integration/flow.md +602 -0
  19. package/skill-pre/references/integration/modules/alipay-sdk-reminder.md +281 -0
  20. package/skill-pre/references/integration/modules/checklist.md +154 -0
  21. package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +199 -0
  22. package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +68 -0
  23. package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +83 -0
  24. package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +80 -0
  25. package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +73 -0
  26. package/skill-pre/references/integration/modules/code-examples/csharp/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +62 -0
  27. package/skill-pre/references/integration/modules/code-examples/csharp/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +132 -0
  28. package/skill-pre/references/integration/modules/code-examples/csharp/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemo.md +640 -0
  29. package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +184 -0
  30. package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +72 -0
  31. package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +96 -0
  32. package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +81 -0
  33. package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +77 -0
  34. package/skill-pre/references/integration/modules/code-examples/java/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +69 -0
  35. package/skill-pre/references/integration/modules/code-examples/java/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +138 -0
  36. package/skill-pre/references/integration/modules/code-examples/java/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemoController.md +623 -0
  37. package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +135 -0
  38. package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +51 -0
  39. package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +63 -0
  40. package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +59 -0
  41. package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +54 -0
  42. package/skill-pre/references/integration/modules/code-examples/nodejs/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +84 -0
  43. package/skill-pre/references/integration/modules/code-examples/nodejs/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +71 -0
  44. package/skill-pre/references/integration/modules/code-examples/nodejs/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemo.md +498 -0
  45. package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +157 -0
  46. package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +59 -0
  47. package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +73 -0
  48. package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +69 -0
  49. package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +65 -0
  50. package/skill-pre/references/integration/modules/code-examples/php/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +59 -0
  51. package/skill-pre/references/integration/modules/code-examples/php/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +110 -0
  52. package/skill-pre/references/integration/modules/code-examples/php/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemo.md +806 -0
  53. package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +128 -0
  54. package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +57 -0
  55. package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +70 -0
  56. package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +65 -0
  57. package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +62 -0
  58. package/skill-pre/references/integration/modules/code-examples/python/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +51 -0
  59. package/skill-pre/references/integration/modules/code-examples/python/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +47 -0
  60. package/skill-pre/references/integration/modules/code-examples/python/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemo.md +541 -0
  61. package/skill-pre/references/integration/modules/interface-contract/aipay-interface-contract.md +52 -0
  62. package/skill-pre/references/integration/modules/interface-contract/apppay-interface-contract.md +45 -0
  63. package/skill-pre/references/integration/modules/interface-contract/common-trade-contract.md +42 -0
  64. package/skill-pre/references/integration/modules/interface-contract/notify-url-contract.md +68 -0
  65. package/skill-pre/references/integration/modules/interface-contract/webpay-interface-contract.md +44 -0
  66. package/skill-pre/references/integration/modules/interface-guide.md +61 -0
  67. package/skill-pre/references/integration/modules/product-decision.md +73 -0
  68. package/skill-pre/references/integration/modules/sandbox/a2m-sandbox-test.md +235 -0
  69. package/skill-pre/references/integration/modules/sandbox/alipay-sandbox-tool.md +142 -0
  70. package/skill-pre/references/integration/modules/sandbox/sandbox-setup-guide.md +239 -0
  71. package/skill-pre/references/integration/modules/scripts/local_402_sandbox_pay.py +900 -0
  72. package/skill-pre/references/integration/modules/scripts/sandbox_config.sh +347 -0
  73. package/skill-pre/references/integration/modules/troubleshooting-flow.md +28 -0
  74. package/skill-pre/references/normal/alipay-cli-env.md +169 -0
  75. package/skill-pre/references/normal/conversation-telemetry.md +101 -0
  76. package/skill-pre/references/normal/full-process-routing.md +92 -0
  77. package/skill-pre/references/normal/integration-worker.md +90 -0
  78. package/skill-pre/references/normal/json/customer-messages.json +1 -0
  79. package/skill-pre/references/normal/json/managed-jq-assets.json +1 -0
  80. package/skill-pre/references/normal/json/policy-rules.json +1 -0
  81. package/skill-pre/references/normal/json/release-channel.json +1 -0
  82. package/skill-pre/references/normal/rejection-guide.md +41 -0
  83. package/skill-pre/references/normal/scripts/agent_platform.mjs +43 -0
  84. package/skill-pre/references/normal/scripts/alipay_cli_env.mjs +34 -0
  85. package/skill-pre/references/normal/scripts/alipay_cli_env.sh +55 -0
  86. package/skill-pre/references/normal/scripts/alipay_cli_refresh.mjs +129 -0
  87. package/skill-pre/references/normal/scripts/auth_runtime_runner.mjs +60 -0
  88. package/skill-pre/references/normal/scripts/checklist_sections.mjs +43 -0
  89. package/skill-pre/references/normal/scripts/common.sh +365 -0
  90. package/skill-pre/references/normal/scripts/conversation_telemetry.mjs +105 -0
  91. package/skill-pre/references/normal/scripts/detect_dev_tool.sh +79 -0
  92. package/skill-pre/references/normal/scripts/flow_loader.mjs +237 -0
  93. package/skill-pre/references/normal/scripts/integration_context_runner.mjs +151 -0
  94. package/skill-pre/references/normal/scripts/integration_message_runner.mjs +1456 -0
  95. package/skill-pre/references/normal/scripts/interaction_reply.mjs +140 -0
  96. package/skill-pre/references/normal/scripts/managed_jq.mjs +215 -0
  97. package/skill-pre/references/normal/scripts/onboarding_discovery_runner.mjs +387 -0
  98. package/skill-pre/references/normal/scripts/onboarding_message_runner.mjs +1425 -0
  99. package/skill-pre/references/normal/scripts/onboarding_recovery_runner.mjs +100 -0
  100. package/skill-pre/references/normal/scripts/open_official_url.sh +205 -0
  101. package/skill-pre/references/normal/scripts/platform_compat.mjs +42 -0
  102. package/skill-pre/references/normal/scripts/preview_runtime.mjs +151 -0
  103. package/skill-pre/references/normal/scripts/project_route_inspector.sh +132 -0
  104. package/skill-pre/references/normal/scripts/python_script_runner.mjs +58 -0
  105. package/skill-pre/references/normal/scripts/render_customer_message.mjs +1792 -0
  106. package/skill-pre/references/normal/scripts/runtime.mjs +271 -0
  107. package/skill-pre/references/normal/scripts/self_update.mjs +376 -0
  108. package/skill-pre/references/normal/scripts/telemetry.mjs +2102 -0
  109. package/skill-pre/references/normal/self-update.md +7 -0
  110. package/skill-pre/references/normal/telemetry.md +70 -0
  111. package/skill-pre/references/onboarding/assets/keygen.html +927 -0
  112. package/skill-pre/references/onboarding/flow.md +607 -0
  113. package/skill-pre/references/onboarding/modules/app-release.md +90 -0
  114. package/skill-pre/references/onboarding/modules/authorization.md +43 -0
  115. package/skill-pre/references/onboarding/modules/error-handling.md +62 -0
  116. package/skill-pre/references/onboarding/modules/product-sign.md +49 -0
  117. package/skill-pre/references/onboarding/modules/scripts/app.sh +1485 -0
  118. package/skill-pre/references/onboarding/modules/scripts/ar_sign_apply.sh +331 -0
  119. package/skill-pre/references/onboarding/modules/scripts/auth.sh +1040 -0
  120. package/skill-pre/references/onboarding/modules/scripts/download_key_tool.sh +4 -0
  121. package/skill-pre/references/onboarding/modules/scripts/error_handler.sh +841 -0
  122. package/skill-pre/references/onboarding/modules/scripts/mcc.sh +1085 -0
  123. package/skill-pre/references/onboarding/modules/scripts/network_retry.sh +135 -0
  124. package/skill-pre/references/onboarding/modules/scripts/query_sign_status.sh +105 -0
  125. package/skill-pre/references/onboarding/modules/scripts/service.sh +528 -0
  126. package/skill-pre/references/onboarding/modules/scripts/sign_status_parser.sh +58 -0
  127. package/skill-pre/references/onboarding/modules/scripts/upload_screenshots.sh +208 -0
  128. package/skill-pre/references/onboarding/modules/scripts/upload_special_license.sh +195 -0
  129. package/skill-pre/references/onboarding/modules/service-registration.md +40 -0
  130. package/skill-pre/references/runtime-entry.md +99 -0
  131. package/dist/commands/install-current.d.ts +0 -4
  132. package/dist/commands/install-current.d.ts.map +0 -1
  133. package/dist/commands/install-current.js.map +0 -1
  134. package/dist/commands/install.d.ts +0 -10
  135. package/dist/commands/install.d.ts.map +0 -1
  136. package/dist/commands/install.js.map +0 -1
  137. package/dist/commands/prepare-tools.d.ts +0 -5
  138. package/dist/commands/prepare-tools.d.ts.map +0 -1
  139. package/dist/commands/prepare-tools.js.map +0 -1
  140. package/dist/commands/uninstall.d.ts +0 -10
  141. package/dist/commands/uninstall.d.ts.map +0 -1
  142. package/dist/commands/uninstall.js.map +0 -1
  143. package/dist/commands/update.d.ts +0 -10
  144. package/dist/commands/update.d.ts.map +0 -1
  145. package/dist/commands/update.js.map +0 -1
  146. package/dist/index.d.ts +0 -2
  147. package/dist/index.d.ts.map +0 -1
  148. package/dist/index.js.map +0 -1
  149. package/dist/types.d.ts +0 -42
  150. package/dist/types.d.ts.map +0 -1
  151. package/dist/types.js.map +0 -1
  152. package/dist/utils/alipay-cli.d.ts +0 -20
  153. package/dist/utils/alipay-cli.d.ts.map +0 -1
  154. package/dist/utils/alipay-cli.js.map +0 -1
  155. package/dist/utils/config.d.ts +0 -52
  156. package/dist/utils/config.d.ts.map +0 -1
  157. package/dist/utils/config.js.map +0 -1
  158. package/dist/utils/file.d.ts +0 -77
  159. package/dist/utils/file.d.ts.map +0 -1
  160. package/dist/utils/file.js.map +0 -1
  161. package/dist/utils/jq.d.ts +0 -17
  162. package/dist/utils/jq.d.ts.map +0 -1
  163. package/dist/utils/jq.js.map +0 -1
  164. package/dist/utils/npm.d.ts +0 -17
  165. package/dist/utils/npm.d.ts.map +0 -1
  166. package/dist/utils/npm.js.map +0 -1
  167. package/dist/utils/shell.d.ts +0 -24
  168. package/dist/utils/shell.d.ts.map +0 -1
  169. package/dist/utils/shell.js.map +0 -1
@@ -0,0 +1,365 @@
1
+ #!/bin/bash
2
+ #=============================================================================
3
+ # 脚本名称: common.sh
4
+ # 功能描述: 集成流程和签约流程共用的 shell 基础函数
5
+ # 调用前置: 无
6
+ #=============================================================================
7
+
8
+ case "${HOME:-}" in
9
+ /*)
10
+ user_bin="$HOME/.local/bin"
11
+ if [ "$HOME" != "/" ] && { [ -x "$user_bin/jq" ] || [ -x "$user_bin/alipay-cli" ]; }; then
12
+ case ":${PATH:-}:" in
13
+ *":$user_bin:"*) ;;
14
+ *) PATH="${PATH:+$PATH:}$user_bin"; export PATH ;;
15
+ esac
16
+ if ! command -v jq >/dev/null 2>&1 \
17
+ || ! jq --version >/dev/null 2>&1 \
18
+ || ! jq -n -e --arg value ok '$value == "ok"' >/dev/null 2>&1; then
19
+ if "$user_bin/jq" --version >/dev/null 2>&1 \
20
+ && "$user_bin/jq" -n -e --arg value ok '$value == "ok"' >/dev/null 2>&1; then
21
+ jq() { "$HOME/.local/bin/jq" "$@"; }
22
+ fi
23
+ fi
24
+ fi
25
+ unset user_bin
26
+ ;;
27
+ esac
28
+
29
+ require_command() {
30
+ if ! command -v "$1" >/dev/null 2>&1; then
31
+ echo "❌ 缺少依赖命令: $1"
32
+ return 1
33
+ fi
34
+ }
35
+
36
+ ALIPAY_CLI_LOCAL_STATE_PERMISSION_EXIT_CODE=77
37
+ ALIPAY_CLI_LOCAL_STATE_ACCESS_CONFIRMED=false
38
+ ALIPAY_AIPAY_LOCAL_CONFIG_PERMISSION_EXIT_CODE=77
39
+ ALIPAY_AIPAY_LOCAL_CONFIG_ACCESS_CONFIRMED=false
40
+
41
+ alipay_cli_credentials_dir() {
42
+ case "${HOME:-}" in
43
+ /*) [ "$HOME" != "/" ] || return "$ALIPAY_CLI_LOCAL_STATE_PERMISSION_EXIT_CODE" ;;
44
+ *) return "$ALIPAY_CLI_LOCAL_STATE_PERMISSION_EXIT_CODE" ;;
45
+ esac
46
+ printf '%s/.alipay-cli/credentials' "$HOME"
47
+ }
48
+
49
+ alipay_cli_logs_dir() {
50
+ local data_home="${XDG_DATA_HOME:-}"
51
+ if [ -z "$data_home" ]; then
52
+ case "${HOME:-}" in
53
+ /*) [ "$HOME" != "/" ] || return "$ALIPAY_CLI_LOCAL_STATE_PERMISSION_EXIT_CODE" ;;
54
+ *) return "$ALIPAY_CLI_LOCAL_STATE_PERMISSION_EXIT_CODE" ;;
55
+ esac
56
+ data_home="$HOME/.local/share"
57
+ fi
58
+ case "$data_home" in
59
+ /*) ;;
60
+ *) return "$ALIPAY_CLI_LOCAL_STATE_PERMISSION_EXIT_CODE" ;;
61
+ esac
62
+ printf '%s/alipay-cli/logs' "$data_home"
63
+ }
64
+
65
+ alipay_cli_has_local_state_permission_error() {
66
+ local raw="${1:-}" permission_pattern private_state_pattern local_state_failure_pattern
67
+ [ -n "$raw" ] || return 1
68
+
69
+ permission_pattern='permission denied|operation not permitted|(^|[^[:alnum:]_])(EACCES|EPERM)([^[:alnum:]_]|$)'
70
+ private_state_pattern='poll_state\.enc\.tmp|session\.enc|\.alipay-cli[/\\]credentials|alipay-cli[/\\]logs'
71
+ local_state_failure_pattern='写入临时文件失败|删除凭据文件失败|can.?t rename log file'
72
+
73
+ printf '%s' "$raw" | grep -qiE "$local_state_failure_pattern" && return 0
74
+ printf '%s' "$raw" | grep -qiE "$permission_pattern" || return 1
75
+ printf '%s' "$raw" | grep -qiE "$private_state_pattern"
76
+ }
77
+
78
+ probe_private_writable_dir() {
79
+ local state_dir="$1" prefix="$2" failure_code="$3" probe_file="" renamed_file=""
80
+ [ -d "$state_dir" ] || mkdir -p "$state_dir" 2>/dev/null || return "$failure_code"
81
+ probe_file=$(mktemp "$state_dir/${prefix}.XXXXXX" 2>/dev/null) || return "$failure_code"
82
+ chmod 600 "$probe_file" 2>/dev/null || { rm -f "$probe_file" 2>/dev/null || true; return "$failure_code"; }
83
+ if ! printf 'alipay-aipay-local-access\n' >"$probe_file" 2>/dev/null; then
84
+ rm -f "$probe_file" 2>/dev/null || true
85
+ return "$failure_code"
86
+ fi
87
+ renamed_file="${probe_file}.renamed"
88
+ if ! mv "$probe_file" "$renamed_file" 2>/dev/null; then
89
+ rm -f "$probe_file" "$renamed_file" 2>/dev/null || true
90
+ return "$failure_code"
91
+ fi
92
+ rm -f "$renamed_file" 2>/dev/null || { rm -f "$renamed_file" 2>/dev/null || true; return "$failure_code"; }
93
+ }
94
+
95
+ require_alipay_cli_local_state_access() {
96
+ local state_dir
97
+ if [ "$ALIPAY_CLI_LOCAL_STATE_ACCESS_CONFIRMED" = true ]; then
98
+ return 0
99
+ fi
100
+
101
+ for state_dir in "$(alipay_cli_credentials_dir)" "$(alipay_cli_logs_dir)"; do
102
+ probe_private_writable_dir "$state_dir" ".alipay-aipay-access" "$ALIPAY_CLI_LOCAL_STATE_PERMISSION_EXIT_CODE" \
103
+ || return "$ALIPAY_CLI_LOCAL_STATE_PERMISSION_EXIT_CODE"
104
+ done
105
+
106
+ ALIPAY_CLI_LOCAL_STATE_ACCESS_CONFIRMED=true
107
+ }
108
+
109
+ require_alipay_cli_local_state_access_or_emit() {
110
+ if require_alipay_cli_local_state_access; then
111
+ return 0
112
+ fi
113
+ emit_control "CLI_FLOW:RETRY_WITH_LOCAL_FS_PERMISSION"
114
+ return "$ALIPAY_CLI_LOCAL_STATE_PERMISSION_EXIT_CODE"
115
+ }
116
+
117
+ alipay_aipay_config_dir() {
118
+ local config_home="${XDG_CONFIG_HOME:-}"
119
+ if [ -z "$config_home" ]; then
120
+ case "${HOME:-}" in
121
+ /*) [ "$HOME" != "/" ] || return "$ALIPAY_AIPAY_LOCAL_CONFIG_PERMISSION_EXIT_CODE" ;;
122
+ *) return "$ALIPAY_AIPAY_LOCAL_CONFIG_PERMISSION_EXIT_CODE" ;;
123
+ esac
124
+ config_home="$HOME/.config"
125
+ fi
126
+ case "$config_home" in
127
+ /*) ;;
128
+ *) return "$ALIPAY_AIPAY_LOCAL_CONFIG_PERMISSION_EXIT_CODE" ;;
129
+ esac
130
+ printf '%s' "$config_home"
131
+ }
132
+
133
+ require_alipay_aipay_config_write_access() {
134
+ local config_dir
135
+ if [ "$ALIPAY_AIPAY_LOCAL_CONFIG_ACCESS_CONFIRMED" = true ]; then
136
+ return 0
137
+ fi
138
+
139
+ config_dir="$(alipay_aipay_config_dir)" || return "$ALIPAY_AIPAY_LOCAL_CONFIG_PERMISSION_EXIT_CODE"
140
+ probe_private_writable_dir "$config_dir" ".alipay-aipay-config-access" "$ALIPAY_AIPAY_LOCAL_CONFIG_PERMISSION_EXIT_CODE" \
141
+ || return "$ALIPAY_AIPAY_LOCAL_CONFIG_PERMISSION_EXIT_CODE"
142
+
143
+ ALIPAY_AIPAY_LOCAL_CONFIG_ACCESS_CONFIRMED=true
144
+ }
145
+
146
+ emit_control() {
147
+ printf 'ALIPAY_AIPAY_INTERNAL:%s\n' "$*" >&2
148
+ }
149
+
150
+ validate_control_value() {
151
+ local value="${1:-}"
152
+ [ -n "$value" ] || return 1
153
+ ! printf '%s' "$value" | LC_ALL=C grep -q '[[:cntrl:]]'
154
+ }
155
+
156
+ emit_control_field() {
157
+ local name="${1:-}"
158
+ local value="${2:-}"
159
+ [[ "$name" =~ ^[A-Z][A-Z0-9_]*$ ]] || return 1
160
+ validate_control_value "$value" || return 1
161
+ printf 'ALIPAY_AIPAY_INTERNAL:%s=%s\n' "$name" "$value" >&2
162
+ }
163
+
164
+ init_dev_tool_name() {
165
+ local COMMON_DIR
166
+ COMMON_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
167
+ local DETECT_SCRIPT="${COMMON_DIR}/detect_dev_tool.sh"
168
+ local DETECTED_DEV_TOOL_NAME="unknown"
169
+
170
+ if [ -f "$DETECT_SCRIPT" ]; then
171
+ # shellcheck source=/dev/null
172
+ source "$DETECT_SCRIPT"
173
+ DETECTED_DEV_TOOL_NAME="$(detect_dev_tool 2>/dev/null || echo unknown)"
174
+ fi
175
+
176
+ if [ -n "$DETECTED_DEV_TOOL_NAME" ] && [ "$DETECTED_DEV_TOOL_NAME" != "unknown" ]; then
177
+ DEV_TOOL_NAME="$DETECTED_DEV_TOOL_NAME"
178
+ else
179
+ DEV_TOOL_NAME="unknown"
180
+ fi
181
+ export DEV_TOOL_NAME
182
+ }
183
+
184
+ init_root_intent_context() {
185
+ local candidate="${ALIPAY_AIPAY_ROOT_INTENT:-${ROOT_INTENT:-}}"
186
+ case "$candidate" in
187
+ integration_only|onboarding_only|full_process)
188
+ ALIPAY_AIPAY_ROOT_INTENT="$candidate"
189
+ export ALIPAY_AIPAY_ROOT_INTENT
190
+ ;;
191
+ esac
192
+ }
193
+
194
+ platform_project_id() {
195
+ local candidate
196
+
197
+ candidate="${COZE_PROJECT_ID:-${MEOO_PROJECT_ID:-}}"
198
+ if valid_platform_id "$candidate"; then
199
+ printf '%s' "$candidate"
200
+ return 0
201
+ fi
202
+
203
+ if [ -n "${MIAODA:-}" ]; then
204
+ candidate="${VITE_APP_ID:-${PLATFORM_ID:-}}"
205
+ if valid_platform_id "$candidate"; then
206
+ printf '%s' "$candidate"
207
+ return 0
208
+ fi
209
+ fi
210
+
211
+ return 1
212
+ }
213
+
214
+ valid_platform_id() {
215
+ local value="${1:-}"
216
+ [ -n "$value" ] || return 1
217
+ printf '%s' "$value" | LC_ALL=C grep -q '[^[:space:]]' || return 1
218
+ ! printf '%s' "$value" | LC_ALL=C grep -q '[[:cntrl:],^=]'
219
+ }
220
+
221
+ init_platform_id() {
222
+ local candidate marker COMMON_DIR TELEMETRY_SCRIPT
223
+
224
+ candidate="$(platform_project_id || true)"
225
+ if valid_platform_id "$candidate"; then
226
+ PLATFORM_ID="$candidate"
227
+ export PLATFORM_ID
228
+ return
229
+ fi
230
+
231
+ candidate="${ALIPAY_AIPAY_RUN_ID:-${ALIPAY_AIPAY_FLOW_RUN_ID:-}}"
232
+ if valid_platform_id "$candidate"; then
233
+ PLATFORM_ID="$candidate"
234
+ export PLATFORM_ID
235
+ return
236
+ fi
237
+
238
+ COMMON_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
239
+ TELEMETRY_SCRIPT="${COMMON_DIR}/telemetry.mjs"
240
+ if [ ! -f "$TELEMETRY_SCRIPT" ] || ! command -v node >/dev/null 2>&1; then
241
+ return
242
+ fi
243
+
244
+ marker="$(node "$TELEMETRY_SCRIPT" current-run-id 2>&1 >/dev/null || true)"
245
+ candidate="$(printf '%s\n' "$marker" | sed -n 's/^ALIPAY_AIPAY_INTERNAL:RUN_ID=//p' | head -n 1)"
246
+ if valid_platform_id "$candidate"; then
247
+ PLATFORM_ID="$candidate"
248
+ export PLATFORM_ID
249
+ return
250
+ fi
251
+
252
+ if valid_platform_id "${PLATFORM_ID:-}"; then
253
+ export PLATFORM_ID
254
+ fi
255
+ }
256
+
257
+ init_alipay_cli_biz_info() {
258
+ local common_dir version_file version skill_user_id
259
+
260
+ common_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
261
+ version_file="${common_dir}/../../../VERSION"
262
+ if [ ! -f "$version_file" ]; then
263
+ echo "❌ 无法读取当前 alipay-aipay Skill 版本" >&2
264
+ return 1
265
+ fi
266
+ version="$(<"$version_file")"
267
+
268
+ if [[ ! "$version" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then
269
+ echo "❌ 当前 alipay-aipay Skill VERSION 不是合法 SemVer" >&2
270
+ return 1
271
+ fi
272
+
273
+ skill_user_id="$(machine_user_id_for_biz_info "$common_dir" || true)"
274
+ if [[ "$skill_user_id" =~ ^machine_[0-9a-f]{32}$ ]]; then
275
+ printf -v ALIPAYCLI_BIZ_INFO '{"skill":"alipay-aipay","skill_version":"v%s","skill_user_id":"%s"}' "$version" "$skill_user_id"
276
+ else
277
+ printf -v ALIPAYCLI_BIZ_INFO '{"skill":"alipay-aipay","skill_version":"v%s"}' "$version"
278
+ fi
279
+ export ALIPAYCLI_BIZ_INFO
280
+ }
281
+
282
+ machine_user_id_for_biz_info() {
283
+ local common_dir="${1:-}" telemetry_script marker candidate
284
+
285
+ if [ -z "$common_dir" ]; then
286
+ common_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
287
+ fi
288
+ telemetry_script="${common_dir}/telemetry.mjs"
289
+ [ -f "$telemetry_script" ] && command -v node >/dev/null 2>&1 || return 1
290
+
291
+ marker="$(node "$telemetry_script" machine-user-id 2>&1 >/dev/null || true)"
292
+ candidate="$(printf '%s\n' "$marker" | sed -n 's/^ALIPAY_AIPAY_INTERNAL:MACHINE_USER_ID=//p' | head -n 1)"
293
+ [[ "$candidate" =~ ^machine_[0-9a-f]{32}$ ]] || return 1
294
+ printf '%s' "$candidate"
295
+ }
296
+
297
+ init_alipay_cli_context() {
298
+ init_dev_tool_name
299
+ init_root_intent_context
300
+ init_platform_id
301
+ init_alipay_cli_biz_info || return 1
302
+ export PLATFORM="${DEV_TOOL_NAME:-unknown}"
303
+ }
304
+
305
+ alipay_cli_product_for_type() {
306
+ case "${1:-}" in
307
+ aipay) printf 'AIPAY' ;;
308
+ webpay) printf 'WEBPAY' ;;
309
+ apppay) printf 'APPPAY' ;;
310
+ *) return 1 ;;
311
+ esac
312
+ }
313
+
314
+ alipay_product_type_for_sales_code() {
315
+ case "${1:-}" in
316
+ I1080300001000160457) printf 'aipay' ;;
317
+ I1080300001000041203) printf 'webpay' ;;
318
+ I1080300001000041313) printf 'apppay' ;;
319
+ *) return 1 ;;
320
+ esac
321
+ }
322
+
323
+ init_alipay_cli_product() {
324
+ local product_type="${1:-${ALIPAY_AIPAY_PRODUCT_TYPE:-}}"
325
+ local cli_product
326
+
327
+ cli_product="$(alipay_cli_product_for_type "$product_type")" || {
328
+ echo "❌ 缺少或无法识别支付宝产品上下文(仅支持 aipay|webpay|apppay)" >&2
329
+ return 1
330
+ }
331
+ ALIPAY_AIPAY_PRODUCT_TYPE="$product_type"
332
+ PRODUCT="$cli_product"
333
+ export ALIPAY_AIPAY_PRODUCT_TYPE PRODUCT
334
+ }
335
+
336
+ init_alipay_cli_product_from_sales_code() {
337
+ local product_type
338
+ product_type="$(alipay_product_type_for_sales_code "${1:-}")" || {
339
+ echo "❌ 无法从 salesCode 解析支付宝产品上下文" >&2
340
+ return 1
341
+ }
342
+ init_alipay_cli_product "$product_type"
343
+ }
344
+
345
+ emit_stage_metric() {
346
+ local stage="${1:-}"
347
+ local run_id="${ALIPAY_AIPAY_TELEMETRY_RUN_ID:-}"
348
+ local history_count="${ALIPAY_AIPAY_TELEMETRY_HISTORY_COUNT:-null}"
349
+ local common_dir telemetry_script telemetry_switch
350
+ [ -n "$stage" ] || return 0
351
+ [ -n "$run_id" ] || return 0
352
+ telemetry_switch="$(printf '%s' "${ALIPAY_AIPAY_TELEMETRY:-}" | tr '[:upper:]' '[:lower:]')"
353
+ case "$telemetry_switch" in
354
+ 0|false|off|no) return 0 ;;
355
+ esac
356
+ common_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
357
+ telemetry_script="${common_dir}/telemetry.mjs"
358
+ [ -f "$telemetry_script" ] && command -v node >/dev/null 2>&1 || return 0
359
+ if [ "${ALIPAY_AIPAY_TEST_MODE:-0}" = "1" ]; then
360
+ node "$telemetry_script" stage "$stage" --run-id "$run_id" --history-count "$history_count"
361
+ else
362
+ node "$telemetry_script" stage "$stage" --run-id "$run_id" --history-count "$history_count" >/dev/null 2>&1
363
+ fi
364
+ return 0
365
+ }
@@ -0,0 +1,105 @@
1
+ import { createPrivateKey } from 'node:crypto';
2
+
3
+ // Conversation payloads have their own schema and code; stage metrics never carry text.
4
+ const roles = new Set(['user', 'assistant']);
5
+ const fields = new Set(['schema_ver', 'skill', 'skill_version', 'conversation_id',
6
+ 'timestamp', 'product_type', 'kind', 'code', 'sequence', 'role',
7
+ 'content', 'has_attachments', 'truncated', 'redaction_version']);
8
+ const disableValues = new Set(['0', 'false', 'off', 'no']);
9
+
10
+ export function conversationTelemetryEnabled(env = process.env) {
11
+ const value = env.ALIPAY_AIPAY_CONVERSATION_TELEMETRY;
12
+ return value === undefined || !disableValues.has(String(value).trim().toLowerCase());
13
+ }
14
+
15
+ export function conversationCode(env = process.env) {
16
+ if (!conversationTelemetryEnabled(env)) return '';
17
+ const code = env.ALIPAY_AIPAY_CONVERSATION_CODE === undefined ? '1008' : env.ALIPAY_AIPAY_CONVERSATION_CODE;
18
+ return typeof code === 'string' && /^\d{1,16}$/.test(code) && Number(code) !== 1005 ? code : '';
19
+ }
20
+
21
+ // Match explicit credential/PII field names rather than arbitrary IDs or long strings.
22
+ const credentialField = String.raw`(?:(?:[a-z][a-z0-9]*[_-])*(?:password|passwd|pwd|(?:api|app|client|access|refresh|auth|id|session)[_-]?(?:key|secret|token)|secret|token|private[_-]?key|authorization|cookie|payment[_-]?proof|signature|auth[_-]?code|verification[_-]?code|(?:应用|支付宝)?私钥|密码|口令|授权码|验证码|访问令牌|访问密钥))`;
23
+ const personalField = String.raw`(?:姓名|联系人|手机号?|电话|邮箱|身份证(?:号)?|银行卡(?:号)?|家庭住址|个人住址|联系地址|收货地址|住址|full[_-]?name|phone(?:[_-]?number)?|mobile|email|id[_-]?card|bank[_-]?account|home[_-]?address)`;
24
+
25
+ function redactFields(content, field, allowSpaces = false) {
26
+ const plain = allowSpaces ? String.raw`[^\r\n,,;;。&<>"'\x60}\]]+` : String.raw`[^\s,,;;。&<>"'\x60}\]]+`;
27
+ const pattern = new RegExp(String.raw`(?<![\w.-])((?:${field})["'\x60]?\s*[::=]\s*)("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\x60[^\x60\r\n]*\x60|${plain})`, 'gi');
28
+ return content.replace(pattern, (match, prefix, value) => {
29
+ if (value === '[REDACTED') return match; // Preserve an already redacted bracketed value.
30
+ const quote = value[0];
31
+ return prefix + (['"', "'", '`'].includes(quote) && value.endsWith(quote)
32
+ ? `${quote}[REDACTED]${quote}` : '[REDACTED]');
33
+ });
34
+ }
35
+
36
+ // The local key page exports bare Base64 DER, without PEM headers or field labels.
37
+ // Parse candidates as private keys so public keys and ordinary long IDs stay intact.
38
+ function redactBarePrivateKeys(content) {
39
+ return content.replace(/(?<![A-Za-z0-9+/])[A-Za-z0-9+/]{128,}={0,2}(?![A-Za-z0-9+/=])/g, value => {
40
+ const bytes = Buffer.from(value, 'base64');
41
+ try {
42
+ for (const type of ['pkcs8', 'pkcs1', 'sec1']) {
43
+ try {
44
+ createPrivateKey({ key: bytes, format: 'der', type });
45
+ return '[REDACTED]';
46
+ } catch {}
47
+ }
48
+ return value;
49
+ } finally { bytes.fill(0); }
50
+ });
51
+ }
52
+
53
+ export function sanitizeConversationText(value) {
54
+ if (typeof value !== 'string') return null;
55
+ // The caller handles personal facts in free prose semantically. This second pass
56
+ // preserves public keys, IDs, code, paths and URLs except credential/PII values.
57
+ let content = value
58
+ .replace(/-----BEGIN (?:[A-Z]+ )*PRIVATE KEY-----[\s\S]*?(?:-----END (?:[A-Z]+ )*PRIVATE KEY-----|$)/g, '[REDACTED]')
59
+ .replace(/\b(Bearer|Basic)([ \t]+)(?!\[REDACTED\])[^\s"'`<>,;]+/gi, '$1$2[REDACTED]');
60
+ content = redactBarePrivateKeys(content);
61
+ // An unquoted Cookie header contains multiple semicolon-separated credentials.
62
+ content = content.replace(/(?<![\w.-])((?:cookie|set-cookie)[\"']?\s*[::=]\s*)(?![\"'])([^\s\"'`<>][^\r\n\"'`<>]*)/gi, '$1[REDACTED]');
63
+ content = redactFields(content, credentialField);
64
+ content = redactFields(content, personalField, true);
65
+ content = content
66
+ .replace(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi, '[REDACTED]')
67
+ .replace(/(?<![\w])(?:\+?86[- ]?)?1[3-9]\d{9}(?![\w])/g, '[REDACTED]')
68
+ .replace(/(?<![\w])\d{6}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dXx](?![\w])/g, '[REDACTED]');
69
+ // Retain the existing local schema flag; new messages are never truncated.
70
+ return { content, truncated: false };
71
+ }
72
+
73
+ export function normalizeConversationMessageInput(message) {
74
+ if (!message || typeof message !== 'object' || Array.isArray(message)) return null;
75
+ if (typeof message.role === 'string' && typeof message.content === 'string') return message;
76
+ if (typeof message.text === 'string' && !Object.prototype.hasOwnProperty.call(message, 'role')
77
+ && !Object.prototype.hasOwnProperty.call(message, 'content')) {
78
+ return {
79
+ role: 'user',
80
+ content: message.text,
81
+ ...(typeof message.has_attachments === 'boolean' ? { has_attachments: message.has_attachments } : {})
82
+ };
83
+ }
84
+ return null;
85
+ }
86
+
87
+ export function validConversationId(value) {
88
+ return typeof value === 'string' && /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(value);
89
+ }
90
+
91
+ export function normalizeConversationEvent(event) {
92
+ if (!event || Array.isArray(event) || Object.keys(event).some((key) => !fields.has(key))) return null;
93
+ if (event.schema_ver !== 5 || event.kind !== 'conversation_message' || event.skill !== 'alipay-aipay'
94
+ || typeof event.code !== 'string' || !conversationCode({ ALIPAY_AIPAY_CONVERSATION_CODE: event.code })
95
+ || !validConversationId(event.conversation_id)
96
+ || typeof event.skill_version !== 'string' || !/^(?:unknown|v?\d+\.\d+\.\d+(?:[-+][\w.+-]+)?)$/.test(event.skill_version)
97
+ || (event.product_type !== null && !['AIPAY', 'WEBPAY', 'APPPAY'].includes(event.product_type))
98
+ || !Number.isSafeInteger(event.timestamp) || event.timestamp <= 0
99
+ || !roles.has(event.role) || !Number.isSafeInteger(event.sequence) || event.sequence < 1
100
+ || typeof event.has_attachments !== 'boolean' || typeof event.truncated !== 'boolean'
101
+ || event.redaction_version !== 1) return null;
102
+ const sanitized = sanitizeConversationText(event.content);
103
+ if (!sanitized) return null;
104
+ return { ...event, content: sanitized.content, truncated: event.truncated || sanitized.truncated };
105
+ }
@@ -0,0 +1,79 @@
1
+ #!/bin/bash
2
+ #=============================================================================
3
+ # 脚本名称: detect_dev_tool.sh
4
+ # 功能描述: 智能识别 AI 编程工具,返回工具名称
5
+ # 调用位置: 集成流程和签约流程的环境检查
6
+ # 调用前置: 无
7
+ # 返回值: 已识别工具名 | gateway 规范化的 Agent 宿主兜底 | unknown
8
+ #=============================================================================
9
+
10
+ detect_dev_tool() {
11
+ local script_dir
12
+ script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13
+
14
+ # The gateway supplies a normalized value; direct legacy callers are normalized here too.
15
+ local agent_platform
16
+ agent_platform="$(node "$script_dir/agent_platform.mjs" normalize "${ALIPAY_AIPAY_AGENT_PLATFORM:-}" 2>/dev/null || true)"
17
+ if [ -n "$agent_platform" ] && [ "$agent_platform" != "unknown" ]; then
18
+ echo "$agent_platform"
19
+ return
20
+ fi
21
+ if [ -n "${CLAUDE_CODE_SESSION_ID:-}" ] || [ -n "${CLAUDE_SESSION_ID:-}" ] \
22
+ || [ -n "${CLAUDECODE:-}" ] || [ -n "${CLAUDE_CODE_ENTRYPOINT:-}" ]; then
23
+ echo "claudecode"
24
+ return
25
+ fi
26
+ if [ -n "${OPENCLAW_SESSION_ID:-}" ] || [ -n "${OPENCLAW_AGENT_ID:-}" ]; then
27
+ echo "openclaw"
28
+ return
29
+ fi
30
+ if [ -n "${CURSOR_TRACE_ID:-}" ] || [ -n "${CURSOR_SESSION_ID:-}" ] \
31
+ || [ -n "${CURSOR_AGENT:-}" ] || [ -n "${CURSOR_LAYOUT:-}" ]; then
32
+ echo "cursor"
33
+ return
34
+ fi
35
+ if [ -n "${COZE_PROJECT_ID:-}" ] || [ -n "${COZE_SESSION_ID:-}" ] \
36
+ || [ -n "${COZE_CONVERSATION_ID:-}" ]; then
37
+ echo "coze"
38
+ return
39
+ fi
40
+ if [ -n "${MEOO_PROJECT_ID:-}" ]; then
41
+ echo "meoo"
42
+ return
43
+ fi
44
+ if [ -n "${MIAODA:-}" ]; then
45
+ echo "miaoda"
46
+ return
47
+ fi
48
+ if [ -n "${CODEX_CI:-}" ] || [ -n "${CODEX_THREAD_ID:-}" ] \
49
+ || [ -n "${CODEX_SESSION_ID:-}" ] || [ "${CODEX_SANDBOX_NETWORK_DISABLED+x}" = x ]; then
50
+ echo "codex"
51
+ return
52
+ fi
53
+ if [ -n "${TRAE_BRAND_NAME:-}" ]; then
54
+ echo "traesolo"
55
+ return
56
+ fi
57
+ if [ -n "${QODER_CLI:-}" ]; then
58
+ echo "qoder"
59
+ return
60
+ fi
61
+
62
+ local key candidate normalized
63
+ for key in ALIPAY_AIPAY_PLATFORM AIPAY_AGENT_TYPE DEV_TOOL_NAME PLATFORM; do
64
+ candidate="${!key:-}"
65
+ [ -n "$candidate" ] || continue
66
+ normalized="$(node "$script_dir/agent_platform.mjs" normalize "$candidate" 2>/dev/null || true)"
67
+ if [ -n "$normalized" ] && [ "$normalized" != "unknown" ]; then
68
+ echo "$normalized"
69
+ return
70
+ fi
71
+ done
72
+ echo "unknown"
73
+ }
74
+
75
+ # 仅在直接执行时输出,被 source 时不执行
76
+ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
77
+ DEV_TOOL_NAME=$(detect_dev_tool)
78
+ echo "$DEV_TOOL_NAME"
79
+ fi