@tencent-rtc/trtc-agent-skills 0.1.1 → 0.1.4

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 (366) hide show
  1. package/.cursor/rules/main.mdc +12 -0
  2. package/AGENTS.md +14 -97
  3. package/CLAUDE.md +15 -120
  4. package/CODEBUDDY.md +32 -118
  5. package/README.md +7 -5
  6. package/README.zh.md +7 -5
  7. package/bin/cli.js +133 -41
  8. package/hooks/__pycache__/cursor-adapter.cpython-313.pyc +0 -0
  9. package/hooks/cursor-adapter.py +45 -18
  10. package/hooks/hooks-cursor.json +5 -18
  11. package/hooks/hooks.json +6 -31
  12. package/knowledge-base/conference/web/index.yaml +143 -0
  13. package/knowledge-base/platform-slice-template.md +1041 -133
  14. package/knowledge-base/products.yaml +76 -0
  15. package/knowledge-base/scenario-spec.md +1316 -115
  16. package/knowledge-base/scenarios/conference/base/general-conference.md +26 -3
  17. package/knowledge-base/scenarios/conference/base/webinar-conference.md +14 -0
  18. package/knowledge-base/scenarios/conference/medical/1v1-video-consultation.md +19 -0
  19. package/knowledge-base/scenarios/conference/medical/medical-multidoctor-consultation.md +13 -0
  20. package/knowledge-base/scenarios/live/entertainment-live-room.md +12 -0
  21. package/knowledge-base/slice-spec.md +2377 -299
  22. package/knowledge-base/slices/conference/web/integration-audit.md +155 -0
  23. package/knowledge-base/slices/conference/web/login-auth.md +16 -2
  24. package/knowledge-base/slices/conference/web/official-roomkit-login-ui.md +41 -13
  25. package/knowledge-base/slices/conference/web/prejoin-check.md +8 -5
  26. package/knowledge-base/tooling/aliases.yaml +92 -0
  27. package/knowledge-base/tooling/intent-signals.yaml +181 -0
  28. package/knowledge-base/tooling/symptom-keywords.yaml +21 -0
  29. package/package.json +1 -1
  30. package/skills/trtc/SKILL.md +202 -244
  31. package/skills/trtc/hooks/__pycache__/report_prompt.cpython-313.pyc +0 -0
  32. package/skills/{trtc-topic/guardrails → trtc/hooks}/gate_slice_read.py +12 -8
  33. package/skills/{trtc-topic/guardrails → trtc/hooks}/gate_slice_write.py +16 -12
  34. package/skills/{trtc-topic/guardrails → trtc/hooks}/stop_require_apply_evidence.py +22 -14
  35. package/skills/trtc/hooks/topic_phase_gate.py +161 -0
  36. package/skills/trtc/room-builder/assets/local-usersig/basic-info-config.ts +39 -0
  37. package/skills/trtc/room-builder/assets/local-usersig/lib-generate-test-usersig-es.min.d.ts +4 -0
  38. package/skills/trtc/room-builder/assets/local-usersig/lib-generate-test-usersig-es.min.js +2 -0
  39. package/skills/{trtc-topic → trtc}/runtime/README.md +2 -2
  40. package/skills/{trtc-onboarding/reference/reporting-protocol.md → trtc/runtime/REPORTING.md} +5 -3
  41. package/skills/{trtc-topic → trtc}/runtime/RUNTIME.md +5 -5
  42. package/skills/trtc/runtime/lib/__init__.py +0 -0
  43. package/skills/{trtc-topic → trtc}/runtime/package-lock.json +2 -2
  44. package/skills/{trtc-topic → trtc}/runtime/package.json +2 -2
  45. package/skills/{trtc-topic → trtc}/runtime/telemetry-bridge.mjs +1 -1
  46. package/skills/trtc/runtime/usersig-handling.md +134 -0
  47. package/skills/{trtc-topic/scripts → trtc/tools}/STATE-MACHINE-GUIDE.md +23 -23
  48. package/skills/trtc/tools/__init__.py +2 -0
  49. package/skills/trtc/tools/__pycache__/__init__.cpython-313.pyc +0 -0
  50. package/skills/trtc/tools/__pycache__/query_classifier.cpython-313.pyc +0 -0
  51. package/skills/trtc/tools/__pycache__/reporting.cpython-313.pyc +0 -0
  52. package/skills/trtc/tools/__pycache__/search.cpython-313.pyc +0 -0
  53. package/skills/trtc/tools/__pycache__/session.cpython-313.pyc +0 -0
  54. package/skills/trtc/tools/apply.py +540 -0
  55. package/skills/trtc/tools/docs.py +712 -0
  56. package/skills/trtc/tools/docsbot.py +182 -0
  57. package/skills/trtc/tools/entry/render_ai_instructions.py +92 -0
  58. package/skills/trtc/tools/flow.py +1089 -0
  59. package/skills/{trtc-topic/scripts → trtc/tools}/init_slice_queue.py +5 -4
  60. package/skills/{trtc-topic/scripts → trtc/tools}/next_slice.py +5 -4
  61. package/skills/trtc/tools/query_classifier.py +301 -0
  62. package/skills/trtc/tools/reporting.py +447 -0
  63. package/skills/trtc/tools/search.py +817 -0
  64. package/skills/trtc/tools/session.py +1261 -0
  65. package/skills/trtc/tools/state_machine.py +690 -0
  66. package/skills/trtc-ai-service/README.md +195 -0
  67. package/skills/trtc-ai-service/README.zh-CN.md +193 -0
  68. package/skills/trtc-ai-service/SKILL.md +945 -0
  69. package/skills/trtc-ai-service/auto_adapters/README.md +40 -0
  70. package/skills/trtc-ai-service/auto_adapters/frontend-spa/README.md +27 -0
  71. package/skills/trtc-ai-service/auto_adapters/frontend-spa/angular/voice-agent.component.ts.tpl +131 -0
  72. package/skills/trtc-ai-service/auto_adapters/frontend-spa/manifest.yaml +57 -0
  73. package/skills/trtc-ai-service/auto_adapters/frontend-spa/react/VoiceAgent.tsx.tpl +142 -0
  74. package/skills/trtc-ai-service/auto_adapters/frontend-spa/vue/VoiceAgent.vue.tpl +121 -0
  75. package/skills/trtc-ai-service/auto_adapters/integration_templates/generic-backend.md +45 -0
  76. package/skills/trtc-ai-service/auto_adapters/integration_templates/generic-frontend.md +51 -0
  77. package/skills/trtc-ai-service/auto_adapters/integration_templates/generic-rest-api.md +93 -0
  78. package/skills/trtc-ai-service/auto_adapters/java-backend/README.md +25 -0
  79. package/skills/trtc-ai-service/auto_adapters/java-backend/manifest.yaml +30 -0
  80. package/skills/trtc-ai-service/auto_adapters/java-backend/quarkus/VoiceAgentFilter.java.tpl +64 -0
  81. package/skills/trtc-ai-service/auto_adapters/java-backend/springboot/VoiceAgentFilter.java.tpl +91 -0
  82. package/skills/trtc-ai-service/auto_adapters/manifest.yaml +43 -0
  83. package/skills/trtc-ai-service/auto_adapters/node-backend/README.md +25 -0
  84. package/skills/trtc-ai-service/auto_adapters/node-backend/express.js.tpl +40 -0
  85. package/skills/trtc-ai-service/auto_adapters/node-backend/fastify.js.tpl +27 -0
  86. package/skills/trtc-ai-service/auto_adapters/node-backend/koa.js.tpl +31 -0
  87. package/skills/trtc-ai-service/auto_adapters/node-backend/manifest.yaml +47 -0
  88. package/skills/trtc-ai-service/auto_adapters/python-backend/README.md +22 -0
  89. package/skills/trtc-ai-service/auto_adapters/python-backend/django.py.tpl +32 -0
  90. package/skills/trtc-ai-service/auto_adapters/python-backend/fastapi.py.tpl +35 -0
  91. package/skills/trtc-ai-service/auto_adapters/python-backend/flask.py.tpl +31 -0
  92. package/skills/trtc-ai-service/auto_adapters/python-backend/manifest.yaml +45 -0
  93. package/skills/trtc-ai-service/capabilities/__init__.py +43 -0
  94. package/skills/trtc-ai-service/capabilities/conversation-core/.env.example +29 -0
  95. package/skills/trtc-ai-service/capabilities/conversation-core/INTEGRATION.md +134 -0
  96. package/skills/trtc-ai-service/capabilities/conversation-core/INTERFACE_ADAPT.md +111 -0
  97. package/skills/trtc-ai-service/capabilities/conversation-core/QUICK_START.md +62 -0
  98. package/skills/trtc-ai-service/capabilities/conversation-core/manifest.yaml +250 -0
  99. package/skills/trtc-ai-service/capabilities/conversation-core/requirements.txt +6 -0
  100. package/skills/trtc-ai-service/capabilities/conversation-core/src/__init__.py +10 -0
  101. package/skills/trtc-ai-service/capabilities/conversation-core/src/_capability_loader.py +218 -0
  102. package/skills/trtc-ai-service/capabilities/conversation-core/src/agent.py +231 -0
  103. package/skills/trtc-ai-service/capabilities/conversation-core/src/credentials.py +132 -0
  104. package/skills/trtc-ai-service/capabilities/conversation-core/src/health.py +355 -0
  105. package/skills/trtc-ai-service/capabilities/conversation-core/src/log_filter.py +76 -0
  106. package/skills/trtc-ai-service/capabilities/conversation-core/src/modality.py +109 -0
  107. package/skills/trtc-ai-service/capabilities/conversation-core/src/server.py +312 -0
  108. package/skills/trtc-ai-service/capabilities/conversation-core/src/trtc_client.py +315 -0
  109. package/skills/trtc-ai-service/capabilities/conversation-core/src/usersig.py +90 -0
  110. package/skills/trtc-ai-service/capabilities/conversation-core/tests/test_skeleton.py +216 -0
  111. package/skills/trtc-ai-service/capabilities/conversation-core/web-demo/README.md +48 -0
  112. package/skills/trtc-ai-service/capabilities/conversation-core/web-demo/app.js +415 -0
  113. package/skills/trtc-ai-service/capabilities/conversation-core/web-demo/index.html +68 -0
  114. package/skills/trtc-ai-service/capabilities/conversation-core/web-demo/styles.css +136 -0
  115. package/skills/trtc-ai-service/capabilities/digital-human/README.md +31 -0
  116. package/skills/trtc-ai-service/capabilities/digital-human/manifest.yaml +64 -0
  117. package/skills/trtc-ai-service/capabilities/digital-human/src/__init__.py +2 -0
  118. package/skills/trtc-ai-service/capabilities/digital-human/src/router.py +43 -0
  119. package/skills/trtc-ai-service/capabilities/human-handoff/INTERFACE_ADAPT.md +353 -0
  120. package/skills/trtc-ai-service/capabilities/human-handoff/README.md +44 -0
  121. package/skills/trtc-ai-service/capabilities/human-handoff/manifest.yaml +227 -0
  122. package/skills/trtc-ai-service/capabilities/human-handoff/src/__init__.py +2 -0
  123. package/skills/trtc-ai-service/capabilities/human-handoff/src/adapters/__init__.py +9 -0
  124. package/skills/trtc-ai-service/capabilities/human-handoff/src/adapters/default_rest.py +242 -0
  125. package/skills/trtc-ai-service/capabilities/human-handoff/src/adapters/factory.py +89 -0
  126. package/skills/trtc-ai-service/capabilities/human-handoff/src/adapters/local_queue.py +258 -0
  127. package/skills/trtc-ai-service/capabilities/human-handoff/src/adapters/mock.py +132 -0
  128. package/skills/trtc-ai-service/capabilities/human-handoff/src/core/__init__.py +25 -0
  129. package/skills/trtc-ai-service/capabilities/human-handoff/src/core/intent_detector.py +75 -0
  130. package/skills/trtc-ai-service/capabilities/human-handoff/src/core/models.py +163 -0
  131. package/skills/trtc-ai-service/capabilities/human-handoff/src/core/service.py +192 -0
  132. package/skills/trtc-ai-service/capabilities/human-handoff/src/feedback_store.py +54 -0
  133. package/skills/trtc-ai-service/capabilities/human-handoff/src/ports/__init__.py +4 -0
  134. package/skills/trtc-ai-service/capabilities/human-handoff/src/ports/handoff_client.py +86 -0
  135. package/skills/trtc-ai-service/capabilities/human-handoff/src/queue.py +62 -0
  136. package/skills/trtc-ai-service/capabilities/human-handoff/src/router.py +201 -0
  137. package/skills/trtc-ai-service/capabilities/human-handoff/src/summary_link.py +77 -0
  138. package/skills/trtc-ai-service/capabilities/human-handoff/src/trigger.py +25 -0
  139. package/skills/trtc-ai-service/capabilities/knowledge-base/INTERFACE_ADAPT.md +297 -0
  140. package/skills/trtc-ai-service/capabilities/knowledge-base/README.md +51 -0
  141. package/skills/trtc-ai-service/capabilities/knowledge-base/data/faq.json +20 -0
  142. package/skills/trtc-ai-service/capabilities/knowledge-base/manifest.yaml +211 -0
  143. package/skills/trtc-ai-service/capabilities/knowledge-base/src/__init__.py +8 -0
  144. package/skills/trtc-ai-service/capabilities/knowledge-base/src/adapters/__init__.py +9 -0
  145. package/skills/trtc-ai-service/capabilities/knowledge-base/src/adapters/default_rest.py +209 -0
  146. package/skills/trtc-ai-service/capabilities/knowledge-base/src/adapters/factory.py +86 -0
  147. package/skills/trtc-ai-service/capabilities/knowledge-base/src/adapters/local_json.py +172 -0
  148. package/skills/trtc-ai-service/capabilities/knowledge-base/src/adapters/mock.py +91 -0
  149. package/skills/trtc-ai-service/capabilities/knowledge-base/src/core/__init__.py +12 -0
  150. package/skills/trtc-ai-service/capabilities/knowledge-base/src/core/models.py +77 -0
  151. package/skills/trtc-ai-service/capabilities/knowledge-base/src/core/scoring.py +73 -0
  152. package/skills/trtc-ai-service/capabilities/knowledge-base/src/core/service.py +78 -0
  153. package/skills/trtc-ai-service/capabilities/knowledge-base/src/ports/__init__.py +4 -0
  154. package/skills/trtc-ai-service/capabilities/knowledge-base/src/ports/kb_client.py +61 -0
  155. package/skills/trtc-ai-service/capabilities/knowledge-base/src/retriever.py +56 -0
  156. package/skills/trtc-ai-service/capabilities/knowledge-base/src/router.py +85 -0
  157. package/skills/trtc-ai-service/capabilities/session-summary/INTERFACE_ADAPT.md +99 -0
  158. package/skills/trtc-ai-service/capabilities/session-summary/README.md +47 -0
  159. package/skills/trtc-ai-service/capabilities/session-summary/data/test_session.json +18 -0
  160. package/skills/trtc-ai-service/capabilities/session-summary/manifest.yaml +165 -0
  161. package/skills/trtc-ai-service/capabilities/session-summary/src/__init__.py +2 -0
  162. package/skills/trtc-ai-service/capabilities/session-summary/src/adapters/__init__.py +5 -0
  163. package/skills/trtc-ai-service/capabilities/session-summary/src/adapters/base.py +31 -0
  164. package/skills/trtc-ai-service/capabilities/session-summary/src/adapters/default_rest.py +67 -0
  165. package/skills/trtc-ai-service/capabilities/session-summary/src/adapters/factory.py +51 -0
  166. package/skills/trtc-ai-service/capabilities/session-summary/src/adapters/local_json.py +42 -0
  167. package/skills/trtc-ai-service/capabilities/session-summary/src/adapters/mock.py +22 -0
  168. package/skills/trtc-ai-service/capabilities/session-summary/src/recorder.py +210 -0
  169. package/skills/trtc-ai-service/capabilities/session-summary/src/router.py +93 -0
  170. package/skills/trtc-ai-service/capabilities/session-summary/src/summarizer.py +163 -0
  171. package/skills/trtc-ai-service/capabilities/tool-calling/INTERFACE_ADAPT.md +158 -0
  172. package/skills/trtc-ai-service/capabilities/tool-calling/README.md +50 -0
  173. package/skills/trtc-ai-service/capabilities/tool-calling/data/tools.yaml +58 -0
  174. package/skills/trtc-ai-service/capabilities/tool-calling/examples/__init__.py +1 -0
  175. package/skills/trtc-ai-service/capabilities/tool-calling/examples/local_tools.py +101 -0
  176. package/skills/trtc-ai-service/capabilities/tool-calling/manifest.yaml +146 -0
  177. package/skills/trtc-ai-service/capabilities/tool-calling/src/__init__.py +8 -0
  178. package/skills/trtc-ai-service/capabilities/tool-calling/src/dispatcher.py +54 -0
  179. package/skills/trtc-ai-service/capabilities/tool-calling/src/registry.py +219 -0
  180. package/skills/trtc-ai-service/capabilities/tool-calling/src/router.py +50 -0
  181. package/skills/trtc-ai-service/references/business-contract-spec.md +263 -0
  182. package/skills/trtc-ai-service/scenarios/custom-builder/README.md +86 -0
  183. package/skills/trtc-ai-service/scenarios/custom-builder/output-templates/recipe.yaml.j2 +194 -0
  184. package/skills/trtc-ai-service/scenarios/custom-builder/prompts/q1-business-scenario.md +43 -0
  185. package/skills/trtc-ai-service/scenarios/custom-builder/prompts/q2-io-modality.md +57 -0
  186. package/skills/trtc-ai-service/scenarios/custom-builder/prompts/q3-ui-form.md +55 -0
  187. package/skills/trtc-ai-service/scenarios/custom-builder/prompts/q4-capabilities.md +78 -0
  188. package/skills/trtc-ai-service/scenarios/customer-service/README.md +114 -0
  189. package/skills/trtc-ai-service/scenarios/customer-service/recipe.yaml +154 -0
  190. package/skills/trtc-ai-service/scenarios/customer-service/sample-data/README.md +32 -0
  191. package/skills/trtc-ai-service/scenarios/customer-service/sample-data/faq-sample.json +37 -0
  192. package/skills/trtc-ai-service/scenarios/customer-service/system-prompt.template.md +94 -0
  193. package/skills/trtc-ai-service/scenarios/customer-service/ui/admin-board/app.js +347 -0
  194. package/skills/trtc-ai-service/scenarios/customer-service/ui/admin-board/index.html +125 -0
  195. package/skills/trtc-ai-service/scenarios/customer-service/ui/admin-board/styles.css +487 -0
  196. package/skills/trtc-ai-service/scenarios/customer-service/ui/admin-board/tokens.css +71 -0
  197. package/skills/trtc-ai-service/scenarios/customer-service/ui/design-system/DESIGN_GUIDELINES.md +370 -0
  198. package/skills/trtc-ai-service/scenarios/customer-service/ui/voice-customer-service/README.md +68 -0
  199. package/skills/trtc-ai-service/scenarios/customer-service/ui/voice-customer-service/app.js +1307 -0
  200. package/skills/trtc-ai-service/scenarios/customer-service/ui/voice-customer-service/data.js +40 -0
  201. package/skills/trtc-ai-service/scenarios/customer-service/ui/voice-customer-service/index.html +233 -0
  202. package/skills/trtc-ai-service/scenarios/customer-service/ui/voice-customer-service/mock-shop.json +21 -0
  203. package/skills/trtc-ai-service/scenarios/customer-service/ui/voice-customer-service/styles.css +603 -0
  204. package/skills/trtc-ai-service/scenarios/customer-service/ui/voice-customer-service/tokens.css +71 -0
  205. package/skills/trtc-ai-service/scenarios/customer-service/ui/widget-floating/agent-link.js +323 -0
  206. package/skills/trtc-ai-service/scenarios/customer-service/ui/widget-floating/app.js +458 -0
  207. package/skills/trtc-ai-service/scenarios/customer-service/ui/widget-floating/index.html +109 -0
  208. package/skills/trtc-ai-service/scenarios/customer-service/ui/widget-floating/styles.css +489 -0
  209. package/skills/trtc-ai-service/scenarios/customer-service/ui/widget-floating/tokens.css +59 -0
  210. package/skills/trtc-ai-service/scripts/add-capability.py +364 -0
  211. package/skills/trtc-ai-service/scripts/contract-adapt.py +334 -0
  212. package/skills/trtc-ai-service/scripts/detect-stack.py +40 -0
  213. package/skills/trtc-ai-service/scripts/lib/__init__.py +20 -0
  214. package/skills/trtc-ai-service/scripts/lib/adapter_codegen.py +509 -0
  215. package/skills/trtc-ai-service/scripts/lib/arbitrator.py +152 -0
  216. package/skills/trtc-ai-service/scripts/lib/contract_resolver.py +519 -0
  217. package/skills/trtc-ai-service/scripts/lib/credential_validators.py +253 -0
  218. package/skills/trtc-ai-service/scripts/lib/curl_parser.py +303 -0
  219. package/skills/trtc-ai-service/scripts/lib/degrader.py +140 -0
  220. package/skills/trtc-ai-service/scripts/lib/injector.py +347 -0
  221. package/skills/trtc-ai-service/scripts/lib/manifest_resolver.py +288 -0
  222. package/skills/trtc-ai-service/scripts/lib/openapi_parser.py +289 -0
  223. package/skills/trtc-ai-service/scripts/lib/stack_detector.py +159 -0
  224. package/skills/trtc-ai-service/scripts/lib/tokens_compile.py +204 -0
  225. package/skills/trtc-ai-service/scripts/post-install-patch.py +225 -0
  226. package/skills/trtc-ai-service/scripts/setup-credentials.py +393 -0
  227. package/skills/trtc-ai-service/scripts/verify-credentials.py +108 -0
  228. package/skills/trtc-ai-service/start.sh +111 -0
  229. package/skills/trtc-ai-service/tests/__init__.py +1 -0
  230. package/skills/trtc-ai-service/tests/test_arbitrator.py +64 -0
  231. package/skills/trtc-ai-service/tests/test_capability_overlay.py +85 -0
  232. package/skills/trtc-ai-service/tests/test_contract_resolver.py +190 -0
  233. package/skills/trtc-ai-service/tests/test_handoff_ports.py +195 -0
  234. package/skills/trtc-ai-service/tests/test_kb_ports.py +195 -0
  235. package/skills/trtc-ai-service/tests/test_manifest_resolver.py +95 -0
  236. package/skills/trtc-ai-service/tests/test_recipe_assembly.py +175 -0
  237. package/skills/trtc-ai-service/tests/test_stack_and_degrader.py +101 -0
  238. package/skills/trtc-ai-service/tests/test_verify_credentials.py +285 -0
  239. package/skills/trtc-ai-service/triggers.yaml +29 -0
  240. package/skills/trtc-conference/SKILL.md +324 -0
  241. package/skills/trtc-conference/flows/onboarding.md +205 -0
  242. package/skills/trtc-conference/flows/topic.md +474 -0
  243. package/skills/trtc-conference/flows/troubleshoot.md +85 -0
  244. package/skills/trtc-conference/hooks/pretooluse_require_business_decisions.py +213 -0
  245. package/skills/trtc-conference/playbooks/medical-quickstart.md +84 -0
  246. package/skills/trtc-conference/playbooks/official-roomkit.md +97 -0
  247. package/skills/trtc-conference/references/local-usersig/basic-info-config.ts +39 -0
  248. package/skills/trtc-conference/references/usersig-handling.md +134 -0
  249. package/skills/trtc-conference/templates/medical-consultation/src/config/lib-generate-test-usersig-es.min.d.ts +4 -0
  250. package/skills/trtc-conference/templates/medical-consultation/src/config/lib-generate-test-usersig-es.min.js +2 -0
  251. package/skills/trtc-conference/tests/__pycache__/test_conference_onboarding_contract.cpython-313-pytest-9.0.2.pyc +0 -0
  252. package/skills/trtc-conference/tests/__pycache__/test_conference_topic_flow_contract.cpython-313-pytest-9.0.2.pyc +0 -0
  253. package/skills/trtc-conference/tests/test_conference_index_contract.py +43 -0
  254. package/skills/trtc-conference/tests/test_conference_onboarding_contract.py +103 -0
  255. package/skills/trtc-conference/tests/test_conference_template_contract.py +25 -0
  256. package/skills/trtc-conference/tests/test_conference_topic_flow_contract.py +132 -0
  257. package/skills/trtc-conference/tools/apply_checks.py +328 -0
  258. package/skills/trtc-conference/verify_lib/__init__.py +0 -0
  259. package/skills/{trtc-apply/guardrails/apply_lib → trtc-conference/verify_lib}/rule_parser.py +1 -1
  260. package/skills/trtc-docs/SKILL.md +91 -119
  261. package/.cursor/rules/ui-mode.mdc +0 -92
  262. package/ai-instructions/base.md +0 -13
  263. package/ai-instructions/ui-mode.md +0 -86
  264. package/knowledge-base/index.yaml +0 -454
  265. package/skills/trtc/room-builder/SKILL.md +0 -138
  266. package/skills/trtc/room-builder/templates/scenarios/medical-consultation/README.md +0 -108
  267. package/skills/trtc/room-builder/tools/render_ai_instructions.py +0 -226
  268. package/skills/trtc-apply/SKILL.md +0 -97
  269. package/skills/trtc-onboarding/SKILL.md +0 -839
  270. package/skills/trtc-onboarding/reference/path-a1-demo.md +0 -103
  271. package/skills/trtc-onboarding/reference/path-a2-integrate.md +0 -693
  272. package/skills/trtc-onboarding/reference/path-b-troubleshoot.md +0 -115
  273. package/skills/trtc-onboarding/reference/path-c-expand.md +0 -43
  274. package/skills/trtc-onboarding/reference/supported-matrix.md +0 -100
  275. package/skills/trtc-onboarding/reference/usersig-handling.md +0 -140
  276. package/skills/trtc-search/SKILL.md +0 -221
  277. package/skills/trtc-topic/SKILL.md +0 -638
  278. package/skills/trtc-topic/scripts/apply.py +0 -581
  279. package/skills/trtc-topic/scripts/lib/state_machine.py +0 -328
  280. package/skills/trtc-topic/tests/README.md +0 -70
  281. package/skills/trtc-topic/tests/conftest.py +0 -72
  282. package/skills/trtc-topic/tests/test_apply_cli.py +0 -480
  283. package/skills/trtc-topic/tests/test_end_to_end.py +0 -305
  284. package/skills/trtc-topic/tests/test_finalize_session.py +0 -51
  285. package/skills/trtc-topic/tests/test_gates.py +0 -316
  286. package/skills/trtc-topic/tests/test_session_resolver.py +0 -260
  287. package/skills/trtc-topic/tests/test_state_machine.py +0 -414
  288. package/skills/trtc-topic/tests/test_stop_require_apply.py +0 -99
  289. package/skills/trtc-topic/tests/test_topic_skill_invariants.py +0 -130
  290. /package/skills/{trtc-topic → trtc}/runtime/lib/platforms.py +0 -0
  291. /package/skills/{trtc-topic → trtc}/runtime/telemetry_collector.py +0 -0
  292. /package/skills/{trtc-topic/scripts → trtc/tools}/finalize_session.py +0 -0
  293. /package/skills/{trtc-apply/guardrails/apply_lib → trtc-ai-service/capabilities/conversation-core/tests}/__init__.py +0 -0
  294. /package/skills/{trtc-topic → trtc-conference}/references/execution-units.yaml +0 -0
  295. /package/skills/{trtc/room-builder/templates/scenarios/medical-consultation/src/config → trtc-conference/references/local-usersig}/lib-generate-test-usersig-es.min.d.ts +0 -0
  296. /package/skills/{trtc/room-builder/templates/scenarios/medical-consultation/src/config → trtc-conference/references/local-usersig}/lib-generate-test-usersig-es.min.js +0 -0
  297. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/docs/backend-contract.zh-CN.md +0 -0
  298. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/docs/integration.zh-CN.md +0 -0
  299. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/docs/theme.zh-CN.md +0 -0
  300. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/index.html +0 -0
  301. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/package.json +0 -0
  302. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/postcss.config.js +0 -0
  303. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/App.vue +0 -0
  304. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/ConsultationManagePanel.vue +0 -0
  305. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/LanguageSwitch.vue +0 -0
  306. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/LoadingSpinner.vue +0 -0
  307. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/MedicalAlert.vue +0 -0
  308. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/MedicalBusinessPanel.vue +0 -0
  309. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/MedicalButton.vue +0 -0
  310. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/MedicalConfirmDialog.vue +0 -0
  311. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/MedicalDataPanel.vue +0 -0
  312. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/MedicalRecordPanel.vue +0 -0
  313. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/PrescriptionPanel.vue +0 -0
  314. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/config/basic-info-config.ts +0 -0
  315. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/config/runtime-config.ts +0 -0
  316. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/env.d.ts +0 -0
  317. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/components/ConsultationChatPanel.vue +0 -0
  318. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/components/ConsultationMembersPanel.vue +0 -0
  319. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/components/ConsultationTranscriptionPanel.vue +0 -0
  320. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/components/ConsultationVideoStage.vue +0 -0
  321. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/components/InviteDoctorDialog.vue +0 -0
  322. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/components/KickMemberConfirmDialog.vue +0 -0
  323. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/types.ts +0 -0
  324. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/useConsultationChat.ts +0 -0
  325. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/useConsultationDevices.ts +0 -0
  326. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/useConsultationParticipants.ts +0 -0
  327. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/useConsultationPermissions.ts +0 -0
  328. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/utils.ts +0 -0
  329. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/i18n/en-US/index.ts +0 -0
  330. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/i18n/index.ts +0 -0
  331. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/i18n/medicalTranslate.ts +0 -0
  332. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/i18n/state.ts +0 -0
  333. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/i18n/zh-CN/index.ts +0 -0
  334. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/main.ts +0 -0
  335. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/mock/appointments.ts +0 -0
  336. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/mock/users.ts +0 -0
  337. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/router/index.ts +0 -0
  338. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/index.ts +0 -0
  339. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/integration/appointmentService.ts +0 -0
  340. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/integration/authService.ts +0 -0
  341. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/integration/launchContext.ts +0 -0
  342. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/integration/userService.ts +0 -0
  343. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/mock/appointmentService.ts +0 -0
  344. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/mock/authService.ts +0 -0
  345. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/mock/userService.ts +0 -0
  346. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/types.ts +0 -0
  347. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/shared/icons.ts +0 -0
  348. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/styles/index.css +0 -0
  349. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/styles/tailwind.css +0 -0
  350. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/styles/theme.css +0 -0
  351. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/utils/auth.ts +0 -0
  352. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/utils/format.ts +0 -0
  353. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/utils/navigation.ts +0 -0
  354. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/utils/session.ts +0 -0
  355. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/views/DoctorConsultationView.vue +0 -0
  356. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/views/DoctorDashboardView.vue +0 -0
  357. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/views/LoginView.vue +0 -0
  358. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/views/PatientConsultationFinishedView.vue +0 -0
  359. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/views/PatientConsultationView.vue +0 -0
  360. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/views/PatientSelectDoctorView.vue +0 -0
  361. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/views/PatientWaitingView.vue +0 -0
  362. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/tsconfig.json +0 -0
  363. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/tsconfig.node.json +0 -0
  364. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/vite.config.ts +0 -0
  365. /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation//346/216/245/345/205/245/350/257/264/346/230/216.md" +0 -0
  366. /package/skills/{trtc-topic/runtime/lib → trtc-conference/tools}/__init__.py +0 -0
@@ -0,0 +1,415 @@
1
+ /* TRTC Conversational AI · Web Demo
2
+ * Health check → request room credentials (get_config) → TRTC enterRoom + start AI
3
+ * Subtitles come from TRTC custom messages: type=10000 (subtitle), type=10001 (AI state)
4
+ * User text messages sent to the AI bot: sendCustomMessage(cmdId:2, type:20000)
5
+ * → AI treats it as "user speech" and responds (voice + subtitle)
6
+ */
7
+ (function () {
8
+ 'use strict';
9
+
10
+ const elIndicators = document.querySelectorAll('.indicator');
11
+ const btnRecheck = document.getElementById('btn-recheck');
12
+ const btnStart = document.getElementById('btn-start');
13
+ const btnMic = document.getElementById('btn-mic');
14
+ const btnStop = document.getElementById('btn-stop');
15
+ const btnSend = document.getElementById('btn-send');
16
+ const txt = document.getElementById('text-input');
17
+ const conv = document.getElementById('conversation');
18
+ const micLabel = document.getElementById('mic-label');
19
+ const micIcon = document.getElementById('mic-icon');
20
+ const agentStatusEl = document.getElementById('agent-status');
21
+
22
+ const state = {
23
+ healthy: false,
24
+ sessionId: null,
25
+ sdkAppId: 0,
26
+ roomId: null,
27
+ userId: null,
28
+ userSig: null,
29
+ agentUserId: null,
30
+ taskId: null,
31
+ trtcClient: null,
32
+ micEnabled: false,
33
+ aiRoundText: {}, // roundid -> 累积文本(可能是增量也可能累积)
34
+ aiRoundLast: {}, // roundid -> 上一帧
35
+ aiRoundBubbleId: {}, // roundid -> dom id
36
+ userTurnText: '',
37
+ userBubbleId: null,
38
+ };
39
+
40
+ // ====================== HTTP helpers ======================
41
+ async function api(path, options = {}) {
42
+ const resp = await fetch(path, {
43
+ method: options.method || 'GET',
44
+ headers: { 'Content-Type': 'application/json' },
45
+ body: options.body ? JSON.stringify(options.body) : undefined,
46
+ });
47
+ let data;
48
+ try { data = await resp.json(); } catch { data = {}; }
49
+ if (!resp.ok) {
50
+ const msg = (data && (data.detail?.message || data.detail || data.msg)) || resp.statusText;
51
+ throw new Error(typeof msg === 'string' ? msg : JSON.stringify(msg));
52
+ }
53
+ return data;
54
+ }
55
+
56
+ // ====================== UI helpers ======================
57
+ function setIndicator(key, ok, latency) {
58
+ elIndicators.forEach((el) => {
59
+ if (el.dataset.key !== key) return;
60
+ const led = el.querySelector('.led');
61
+ const lat = el.querySelector('.latency');
62
+ led.classList.remove('led-unknown', 'led-ok', 'led-fail', 'led-pending');
63
+ if (ok === 'pending') {
64
+ led.classList.add('led-pending');
65
+ lat.textContent = '...';
66
+ } else if (ok) {
67
+ led.classList.add('led-ok');
68
+ lat.textContent = latency != null ? `${latency}ms` : 'ok';
69
+ } else {
70
+ led.classList.add('led-fail');
71
+ lat.textContent = latency != null ? `${latency}ms` : 'fail';
72
+ }
73
+ });
74
+ }
75
+
76
+ function clearPlaceholder() {
77
+ const p = conv.querySelector('.placeholder');
78
+ if (p) p.remove();
79
+ }
80
+
81
+ function makeBubble(role, text) {
82
+ clearPlaceholder();
83
+ const div = document.createElement('div');
84
+ div.className = `bubble ${role}`;
85
+ div.textContent = text || '';
86
+ conv.appendChild(div);
87
+ div.scrollIntoView({ behavior: 'smooth', block: 'end' });
88
+ return div;
89
+ }
90
+
91
+ function updateBubble(el, text) {
92
+ if (!el) return;
93
+ el.textContent = text;
94
+ el.scrollIntoView({ behavior: 'smooth', block: 'end' });
95
+ }
96
+
97
+ function setAgentStatus(label, cls = '') {
98
+ agentStatusEl.innerHTML = `<span class="agent-state agent-state-${cls || 'idle'}">${label}</span>`;
99
+ }
100
+
101
+ function updateMicUI() {
102
+ btnMic.classList.toggle('btn-active', state.micEnabled);
103
+ micLabel.textContent = state.micEnabled ? 'Mic on' : 'Mic off';
104
+ micIcon.textContent = state.micEnabled ? '🔴' : '🎙️';
105
+ }
106
+
107
+ // ====================== Health ======================
108
+ async function runHealthCheck() {
109
+ ['tencent_cloud', 'trtc', 'llm'].forEach((k) => setIndicator(k, 'pending'));
110
+ btnStart.disabled = true;
111
+ try {
112
+ const data = await api('/api/v1/health');
113
+ const checks = data.checks || {};
114
+ let allOk = true;
115
+ for (const k of ['tencent_cloud', 'trtc', 'llm']) {
116
+ const c = checks[k] || {};
117
+ const ok = c.status === 'ok';
118
+ if (!ok) allOk = false;
119
+ setIndicator(k, ok, c.latency_ms);
120
+ if (!ok && c.detail) console.warn(`[health] ${k}:`, c.error_code, c.detail);
121
+ }
122
+ state.healthy = allOk;
123
+ btnStart.disabled = !allOk;
124
+ if (!data.configured) {
125
+ clearPlaceholder();
126
+ makeBubble(
127
+ 'agent',
128
+ `Credentials missing: ${(data.missing || []).join(', ')}\nRun: python scripts/setup-credentials.py`
129
+ );
130
+ }
131
+ } catch (err) {
132
+ ['tencent_cloud', 'trtc', 'llm'].forEach((k) => setIndicator(k, false));
133
+ console.error('[health] error', err);
134
+ }
135
+ }
136
+
137
+ // ====================== TRTC custom message handling ======================
138
+ // type:10000 字幕(user / ai),type:10001 AI 状态
139
+ function handleCustomMessage(data, eventUserId) {
140
+ if (!data || typeof data !== 'object') return;
141
+
142
+ if (data.type === 10001) {
143
+ const stateCode = data.payload && data.payload.state;
144
+ const map = {
145
+ 1: ['listening', 'listening'],
146
+ 2: ['thinking', 'thinking'],
147
+ 3: ['speaking', 'speaking'],
148
+ 4: ['interrupted', 'idle'],
149
+ };
150
+ const m = map[stateCode] || ['idle', 'idle'];
151
+ setAgentStatus(m[0], m[1]);
152
+ return;
153
+ }
154
+
155
+ if (data.type !== 10000) return;
156
+ const text = (data.payload && data.payload.text) || '';
157
+ const sender = data.sender || eventUserId || '';
158
+ const end = data.payload && data.payload.end === true;
159
+ const roundid = (data.payload && data.payload.roundid) || '';
160
+ const isUser = sender === state.userId;
161
+
162
+ if (isUser) {
163
+ // 用户语音 ASR:仅 end=true 才落入气泡,避免半句乱码
164
+ if (end && text.trim()) {
165
+ if (!state.userBubbleId) {
166
+ state.userBubbleId = makeBubble('user', text.trim());
167
+ } else {
168
+ const cur = state.userBubbleId.textContent || '';
169
+ updateBubble(state.userBubbleId, cur ? `${cur} ${text.trim()}` : text.trim());
170
+ }
171
+ // 一次 user finalize 后,下一次新 ASR 进入新气泡
172
+ setTimeout(() => { state.userBubbleId = null; }, 1500);
173
+ }
174
+ return;
175
+ }
176
+
177
+ // AI 字幕:增量/累积自适应,按 roundid 聚合到同一气泡
178
+ if (text.trim() && roundid) {
179
+ const last = state.aiRoundLast[roundid] || '';
180
+ const cur = state.aiRoundText[roundid] || '';
181
+ const isAccumulative = last && text.startsWith(last);
182
+ state.aiRoundText[roundid] = isAccumulative ? text : (cur + text);
183
+ state.aiRoundLast[roundid] = text;
184
+
185
+ let bubble = state.aiRoundBubbleId[roundid];
186
+ if (!bubble) {
187
+ bubble = makeBubble('agent', state.aiRoundText[roundid]);
188
+ state.aiRoundBubbleId[roundid] = bubble;
189
+ } else {
190
+ updateBubble(bubble, state.aiRoundText[roundid]);
191
+ }
192
+ }
193
+
194
+ if (end && roundid) {
195
+ const bubble = state.aiRoundBubbleId[roundid];
196
+ const finalText = state.aiRoundText[roundid] || text;
197
+ if (bubble) updateBubble(bubble, finalText);
198
+ delete state.aiRoundText[roundid];
199
+ delete state.aiRoundLast[roundid];
200
+ delete state.aiRoundBubbleId[roundid];
201
+ }
202
+ }
203
+
204
+ // ====================== Start / Stop ======================
205
+ async function startConversation() {
206
+ btnStart.disabled = true;
207
+ setAgentStatus('connecting...', 'thinking');
208
+ try {
209
+ // 1) get_config
210
+ const cfg = await api('/api/v1/get_config', { method: 'POST', body: {} });
211
+ const data = cfg.data || {};
212
+ Object.assign(state, {
213
+ sessionId: data.session_id,
214
+ sdkAppId: data.sdk_app_id,
215
+ roomId: parseInt(data.room_id, 10), // TRTC enterRoom 要求 roomId 是 number(数字房间号)
216
+ userId: data.user_id,
217
+ userSig: data.user_sig,
218
+ agentUserId: data.agent_user_id,
219
+ });
220
+
221
+ // 2) TRTC create + enterRoom
222
+ if (typeof TRTC === 'undefined') throw new Error('TRTC Web SDK not loaded');
223
+ state.trtcClient = TRTC.create();
224
+
225
+ state.trtcClient.on(TRTC.EVENT.CUSTOM_MESSAGE, (event) => {
226
+ try {
227
+ const txt = new TextDecoder().decode(event.data);
228
+ const parsed = JSON.parse(txt);
229
+ handleCustomMessage(parsed, event.userId);
230
+ } catch (e) { console.warn('parse custom msg failed', e); }
231
+ });
232
+
233
+ state.trtcClient.on(TRTC.EVENT.ERROR, (err) => {
234
+ console.error('[trtc] error', err);
235
+ });
236
+
237
+ await state.trtcClient.enterRoom({
238
+ roomId: state.roomId,
239
+ scene: 'rtc',
240
+ sdkAppId: state.sdkAppId,
241
+ userId: state.userId,
242
+ userSig: state.userSig,
243
+ });
244
+
245
+ // 3) start local audio (默认静音;用户点 Mic 后才开)
246
+ try {
247
+ await state.trtcClient.startLocalAudio();
248
+ await state.trtcClient.updateLocalAudio({ mute: true });
249
+ state.micEnabled = false;
250
+ } catch (e) {
251
+ console.warn('mic init failed (continue text-only):', e);
252
+ }
253
+
254
+ // 4) StartAIConversation
255
+ await api('/api/v1/agent/start', {
256
+ method: 'POST',
257
+ body: { session_id: state.sessionId, language: 'en' },
258
+ });
259
+
260
+ btnStop.disabled = false;
261
+ btnSend.disabled = false;
262
+ btnMic.disabled = false;
263
+ txt.disabled = false;
264
+ txt.focus();
265
+ updateMicUI();
266
+ setAgentStatus('ready', 'idle');
267
+ } catch (err) {
268
+ console.error('[start] error', err);
269
+ makeBubble('agent', `Start failed: ${err.message || err}`);
270
+ setAgentStatus('error', 'idle');
271
+ await safeExitRoom();
272
+ btnStart.disabled = !state.healthy;
273
+ }
274
+ }
275
+
276
+ async function stopConversation() {
277
+ btnStop.disabled = true;
278
+ btnMic.disabled = true;
279
+ btnSend.disabled = true;
280
+ txt.disabled = true;
281
+ txt.value = '';
282
+ try {
283
+ if (state.sessionId) {
284
+ await api('/api/v1/agent/stop', {
285
+ method: 'POST',
286
+ body: { session_id: state.sessionId },
287
+ });
288
+ }
289
+ } catch (e) {
290
+ console.warn('[stop] api error', e);
291
+ }
292
+ await safeExitRoom();
293
+ state.sessionId = null;
294
+ state.taskId = null;
295
+ state.micEnabled = false;
296
+ updateMicUI();
297
+ setAgentStatus('idle', 'idle');
298
+ btnStart.disabled = !state.healthy;
299
+ }
300
+
301
+ async function safeExitRoom() {
302
+ try {
303
+ if (state.trtcClient) {
304
+ await state.trtcClient.exitRoom();
305
+ state.trtcClient.destroy();
306
+ }
307
+ } catch (e) {
308
+ console.warn('exitRoom failed', e);
309
+ } finally {
310
+ state.trtcClient = null;
311
+ }
312
+ }
313
+
314
+ // ====================== Mic toggle ======================
315
+ async function toggleMic() {
316
+ if (!state.trtcClient) return;
317
+ state.micEnabled = !state.micEnabled;
318
+ try {
319
+ await state.trtcClient.updateLocalAudio({ mute: !state.micEnabled });
320
+ // 用户刚开 mic 即将说话 → 立刻打断 AI 当前 TTS(智能打断)
321
+ if (state.micEnabled) sendInterrupt();
322
+ } catch (e) {
323
+ console.error('toggleMic failed', e);
324
+ state.micEnabled = !state.micEnabled; // revert
325
+ }
326
+ updateMicUI();
327
+ }
328
+
329
+ // ====================== Text injection (端侧 → AI bot) ======================
330
+ // 协议参考:https://cloud.tencent.com/document/product/647/115412
331
+ // - type:20000 = 把文字当作"用户说的话"喂给 AI bot,触发一轮 LLM → TTS + 字幕
332
+ // payload 字段名必须是 `message`(不是 text)
333
+ // - type:20001 = 立即打断 AI 当前 TTS(用户开始新一轮输入时触发智能打断)
334
+ // 通过 TRTC sendCustomMessage(cmdId:2) 端到端发送。
335
+
336
+ function uuid() {
337
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
338
+ const r = (Math.random() * 16) | 0;
339
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
340
+ return v.toString(16);
341
+ });
342
+ }
343
+
344
+ async function sendCustomToAgent(message) {
345
+ if (!state.trtcClient) return false;
346
+ try {
347
+ await state.trtcClient.sendCustomMessage({
348
+ cmdId: 2,
349
+ data: new TextEncoder().encode(JSON.stringify(message)).buffer,
350
+ });
351
+ return true;
352
+ } catch (e) {
353
+ console.warn('sendCustomMessage failed', e);
354
+ return false;
355
+ }
356
+ }
357
+
358
+ function sendInterrupt() {
359
+ return sendCustomToAgent({
360
+ type: 20001,
361
+ sender: state.userId,
362
+ receiver: [state.agentUserId],
363
+ payload: { id: uuid(), timestamp: Date.now() },
364
+ });
365
+ }
366
+
367
+ async function sendText() {
368
+ const text = (txt.value || '').trim();
369
+ if (!text || !state.trtcClient) return;
370
+ txt.value = '';
371
+ // 立即渲染用户气泡
372
+ makeBubble('user', text);
373
+
374
+ // 1) 先打断 AI 当前 TTS(智能打断)
375
+ sendInterrupt();
376
+
377
+ // 2) 略延后一点点,确保 interrupt 生效,再推用户回合给 AI
378
+ // AI bot 收到 type:20000 后会跳过 ASR、直接走 LLM → TTS + 字幕回放
379
+ setTimeout(() => {
380
+ sendCustomToAgent({
381
+ type: 20000,
382
+ sender: state.userId,
383
+ receiver: [state.agentUserId],
384
+ payload: {
385
+ id: uuid(),
386
+ message: text, // ← 协议规范字段名(不是 text)
387
+ timestamp: Date.now(),
388
+ },
389
+ });
390
+ }, 120);
391
+ }
392
+
393
+ // ====================== Bindings ======================
394
+ btnRecheck.addEventListener('click', runHealthCheck);
395
+ btnStart.addEventListener('click', startConversation);
396
+ btnStop.addEventListener('click', stopConversation);
397
+ btnMic.addEventListener('click', toggleMic);
398
+ btnSend.addEventListener('click', sendText);
399
+
400
+ // IME(中文输入法)兼容:拼音上屏时按空格/回车不应触发发送
401
+ // - compositionstart / compositionend 跟踪输入法是否在编辑中
402
+ // - event.isComposing 是 W3C 标准属性
403
+ // - event.keyCode === 229 是 IME 状态下 Enter 的兜底信号(旧浏览器)
404
+ let imeComposing = false;
405
+ txt.addEventListener('compositionstart', () => { imeComposing = true; });
406
+ txt.addEventListener('compositionend', () => { imeComposing = false; });
407
+ txt.addEventListener('keydown', (e) => {
408
+ if (e.key !== 'Enter') return;
409
+ if (imeComposing || e.isComposing || e.keyCode === 229) return;
410
+ e.preventDefault();
411
+ sendText();
412
+ });
413
+
414
+ runHealthCheck();
415
+ })();
@@ -0,0 +1,68 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>TRTC Conversational AI</title>
7
+ <link rel="stylesheet" href="/static/styles.css" />
8
+ </head>
9
+ <body>
10
+ <header class="status-bar" id="status-bar">
11
+ <div class="brand">
12
+ <span class="dot"></span>
13
+ <strong>TRTC Conversational AI</strong>
14
+ </div>
15
+ <div class="indicators" role="status" aria-live="polite">
16
+ <div class="indicator" data-key="tencent_cloud">
17
+ <span class="led led-unknown"></span>
18
+ <span class="label">Tencent Cloud</span>
19
+ <span class="latency">--</span>
20
+ </div>
21
+ <div class="indicator" data-key="trtc">
22
+ <span class="led led-unknown"></span>
23
+ <span class="label">TRTC</span>
24
+ <span class="latency">--</span>
25
+ </div>
26
+ <div class="indicator" data-key="llm">
27
+ <span class="led led-unknown"></span>
28
+ <span class="label">LLM</span>
29
+ <span class="latency">--</span>
30
+ </div>
31
+ <button id="btn-recheck" class="btn btn-ghost" type="button">Recheck</button>
32
+ </div>
33
+ </header>
34
+
35
+ <main>
36
+ <section class="conversation" id="conversation">
37
+ <div class="placeholder">
38
+ <h1>Voice Agent Demo</h1>
39
+ <p>All three indicators must be green before starting.</p>
40
+ <ul class="hint-list">
41
+ <li>Click <em>Start</em> to join the room and bring up the AI agent.</li>
42
+ <li>Click <em>Mic</em> to talk; the AI will answer with voice + live captions.</li>
43
+ <li>Or type a message — the AI will reply by voice + caption too.</li>
44
+ </ul>
45
+ </div>
46
+ </section>
47
+ </main>
48
+
49
+ <footer class="control-bar">
50
+ <button id="btn-start" class="btn btn-primary" type="button" disabled>Start</button>
51
+ <button id="btn-mic" class="btn btn-ghost" type="button" disabled title="Push-to-talk">
52
+ <span id="mic-icon">🎙️</span> <span id="mic-label">Mic off</span>
53
+ </button>
54
+ <button id="btn-stop" class="btn btn-danger" type="button" disabled>Hang up</button>
55
+ <div class="text-input-group">
56
+ <input id="text-input" type="text" placeholder="Type a message and press Enter..." disabled />
57
+ <button id="btn-send" class="btn btn-ghost" type="button" disabled>Send</button>
58
+ </div>
59
+ <div class="agent-status" id="agent-status" aria-live="polite">
60
+ <span class="agent-state agent-state-idle">idle</span>
61
+ </div>
62
+ </footer>
63
+
64
+ <!-- TRTC Web SDK v5 -->
65
+ <script src="https://web.sdk.qcloud.com/trtc/webrtc/v5/dist/trtc.js"></script>
66
+ <script src="/static/app.js"></script>
67
+ </body>
68
+ </html>
@@ -0,0 +1,136 @@
1
+ :root {
2
+ --bg: #0e1116;
3
+ --panel: #161b22;
4
+ --border: #30363d;
5
+ --text: #e6edf3;
6
+ --muted: #8b949e;
7
+ --green: #3fb950;
8
+ --red: #f85149;
9
+ --yellow: #d29922;
10
+ --accent: #2f81f7;
11
+ }
12
+ * { box-sizing: border-box; }
13
+ html, body { height: 100%; margin: 0; }
14
+ body {
15
+ font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
16
+ background: var(--bg);
17
+ color: var(--text);
18
+ display: flex;
19
+ flex-direction: column;
20
+ }
21
+
22
+ /* ---------------- Status bar ---------------- */
23
+ .status-bar {
24
+ display: flex;
25
+ align-items: center;
26
+ justify-content: space-between;
27
+ padding: 12px 24px;
28
+ background: var(--panel);
29
+ border-bottom: 1px solid var(--border);
30
+ }
31
+ .brand { display: flex; align-items: center; gap: 8px; font-size: 15px; }
32
+ .brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
33
+ .indicators { display: flex; align-items: center; gap: 12px; }
34
+ .indicator {
35
+ display: flex; align-items: center; gap: 6px;
36
+ background: rgba(255,255,255,0.03);
37
+ padding: 6px 10px; border-radius: 999px;
38
+ border: 1px solid var(--border);
39
+ font-size: 13px;
40
+ }
41
+ .led {
42
+ width: 10px; height: 10px; border-radius: 50%;
43
+ display: inline-block;
44
+ box-shadow: 0 0 6px currentColor;
45
+ }
46
+ .led-unknown { background: var(--muted); color: var(--muted); }
47
+ .led-ok { background: var(--green); color: var(--green); }
48
+ .led-fail { background: var(--red); color: var(--red); }
49
+ .led-pending { background: var(--yellow); color: var(--yellow); animation: blink 1s infinite; }
50
+ @keyframes blink { 50% { opacity: .35; } }
51
+ .indicator .latency { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 38px; text-align: right; }
52
+
53
+ /* ---------------- Conversation ---------------- */
54
+ main { flex: 1; overflow: auto; padding: 24px; }
55
+ .conversation { max-width: 880px; margin: 0 auto; }
56
+ .placeholder {
57
+ border: 1px dashed var(--border);
58
+ border-radius: 12px;
59
+ padding: 32px;
60
+ color: var(--muted);
61
+ }
62
+ .placeholder h1 { color: var(--text); margin-top: 0; }
63
+ .hint-list { line-height: 1.8; padding-left: 20px; }
64
+ .hint-list em { color: var(--accent); font-style: normal; }
65
+
66
+ .bubble {
67
+ max-width: 70%;
68
+ padding: 10px 14px;
69
+ border-radius: 14px;
70
+ margin: 8px 0;
71
+ white-space: pre-wrap;
72
+ word-break: break-word;
73
+ line-height: 1.5;
74
+ font-size: 14px;
75
+ }
76
+ .bubble.user {
77
+ background: var(--accent);
78
+ margin-left: auto;
79
+ border-bottom-right-radius: 4px;
80
+ }
81
+ .bubble.agent {
82
+ background: var(--panel);
83
+ border: 1px solid var(--border);
84
+ border-bottom-left-radius: 4px;
85
+ }
86
+
87
+ /* ---------------- Control bar ---------------- */
88
+ .control-bar {
89
+ display: flex;
90
+ flex-wrap: wrap;
91
+ align-items: center;
92
+ gap: 12px;
93
+ padding: 12px 24px;
94
+ border-top: 1px solid var(--border);
95
+ background: var(--panel);
96
+ }
97
+ .btn {
98
+ border: 1px solid var(--border);
99
+ background: transparent;
100
+ color: var(--text);
101
+ padding: 8px 16px;
102
+ border-radius: 8px;
103
+ font-size: 14px;
104
+ cursor: pointer;
105
+ transition: opacity .15s, background .15s;
106
+ display: inline-flex; align-items: center; gap: 6px;
107
+ }
108
+ .btn:disabled { opacity: .4; cursor: not-allowed; }
109
+ .btn-primary { background: var(--accent); border-color: var(--accent); }
110
+ .btn-danger { background: var(--red); border-color: var(--red); }
111
+ .btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,.05); }
112
+ .btn-active { background: var(--red); border-color: var(--red); color: #fff; }
113
+
114
+ .text-input-group { flex: 1; display: flex; gap: 8px; min-width: 240px; }
115
+ .text-input-group input {
116
+ flex: 1;
117
+ padding: 8px 12px;
118
+ border-radius: 8px;
119
+ border: 1px solid var(--border);
120
+ background: var(--bg);
121
+ color: var(--text);
122
+ font-size: 14px;
123
+ }
124
+ .text-input-group input:focus { border-color: var(--accent); outline: none; }
125
+
126
+ .agent-status { font-size: 12px; color: var(--muted); }
127
+ .agent-state {
128
+ padding: 4px 10px;
129
+ border-radius: 999px;
130
+ border: 1px solid var(--border);
131
+ text-transform: lowercase;
132
+ }
133
+ .agent-state-idle { color: var(--muted); }
134
+ .agent-state-listening { color: var(--green); border-color: var(--green); }
135
+ .agent-state-thinking { color: var(--yellow); border-color: var(--yellow); animation: blink 1.2s infinite; }
136
+ .agent-state-speaking { color: var(--accent); border-color: var(--accent); }
@@ -0,0 +1,31 @@
1
+ # digital-human · Digital Human Capability (Placeholder)
2
+
3
+ > Phase 2 only declares the interface contract. Rendering / lip-sync / expression driving
4
+ > and other rendering layer implementations are deferred to future iterations (Phase 3+).
5
+
6
+ ## Current Capabilities
7
+
8
+ - Register placeholder REST endpoints via manifest: `/api/v1/digital-human/*`
9
+ - Does not modify skeleton runtime behavior; only serves as an integration anchor for the future rendering layer
10
+
11
+ ## REST Placeholders
12
+
13
+ | Method | Path | Behavior |
14
+ |:---|:---|:---|
15
+ | GET | `/api/v1/digital-human/status` | Returns current status / roadmap |
16
+ | POST | `/api/v1/digital-human/render` | Always returns `501 Not Implemented` |
17
+
18
+ ## Roadmap
19
+
20
+ 1. Integrate third-party rendering SDKs (Avatar / Lipsync / Expression)
21
+ 2. Push rendering driver data via WebRTC datachannel
22
+ 3. Align frame output with conversation-core TTS
23
+
24
+ ## Configuration
25
+
26
+ | Env Variable | Default | Description |
27
+ |:---|:---|:---|
28
+ | `DH_ENABLED` | `false` | Keep false before real enablement to avoid accidental use |
29
+ | `DH_AVATAR_ID` | _(empty)_ | Avatar ID |
30
+ | `DH_LIPSYNC_PROVIDER` | `tencent-cloud-vmp` | Lip-sync provider |
31
+ | `DH_EXPRESSION_PROVIDER` | `internal-rule` | Expression driver provider |