@tencent-rtc/trtc-agent-skills 0.1.3 → 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.
- package/.cursor/rules/main.mdc +12 -0
- package/AGENTS.md +14 -104
- package/CLAUDE.md +15 -127
- package/CODEBUDDY.md +32 -118
- package/README.md +7 -5
- package/README.zh.md +7 -5
- package/bin/cli.js +133 -41
- package/hooks/__pycache__/cursor-adapter.cpython-313.pyc +0 -0
- package/hooks/cursor-adapter.py +45 -18
- package/hooks/hooks-cursor.json +5 -18
- package/hooks/hooks.json +6 -31
- package/knowledge-base/conference/web/index.yaml +143 -0
- package/knowledge-base/platform-slice-template.md +1041 -133
- package/knowledge-base/products.yaml +76 -0
- package/knowledge-base/scenario-spec.md +1316 -115
- package/knowledge-base/scenarios/conference/base/general-conference.md +22 -2
- package/knowledge-base/scenarios/conference/base/webinar-conference.md +14 -0
- package/knowledge-base/scenarios/conference/medical/1v1-video-consultation.md +19 -0
- package/knowledge-base/scenarios/conference/medical/medical-multidoctor-consultation.md +13 -0
- package/knowledge-base/scenarios/live/entertainment-live-room.md +12 -0
- package/knowledge-base/slice-spec.md +2377 -299
- package/knowledge-base/slices/conference/web/integration-audit.md +1 -1
- package/knowledge-base/slices/conference/web/login-auth.md +14 -1
- package/knowledge-base/tooling/aliases.yaml +92 -0
- package/knowledge-base/tooling/intent-signals.yaml +181 -0
- package/knowledge-base/tooling/symptom-keywords.yaml +21 -0
- package/package.json +1 -1
- package/skills/trtc/SKILL.md +202 -245
- package/skills/trtc/hooks/__pycache__/report_prompt.cpython-313.pyc +0 -0
- package/skills/{trtc-topic/guardrails → trtc/hooks}/gate_slice_read.py +12 -8
- package/skills/{trtc-topic/guardrails → trtc/hooks}/gate_slice_write.py +16 -12
- package/skills/{trtc-topic/guardrails → trtc/hooks}/stop_require_apply_evidence.py +22 -14
- package/skills/trtc/hooks/topic_phase_gate.py +161 -0
- package/skills/{trtc-topic → trtc}/runtime/README.md +2 -2
- package/skills/{trtc-onboarding/reference/reporting-protocol.md → trtc/runtime/REPORTING.md} +5 -5
- package/skills/{trtc-topic → trtc}/runtime/RUNTIME.md +5 -5
- package/skills/trtc/runtime/lib/__init__.py +0 -0
- package/skills/{trtc-topic → trtc}/runtime/package-lock.json +2 -2
- package/skills/{trtc-topic → trtc}/runtime/package.json +2 -2
- package/skills/{trtc-topic → trtc}/runtime/telemetry-bridge.mjs +1 -1
- package/skills/{trtc-topic/scripts → trtc/tools}/STATE-MACHINE-GUIDE.md +23 -23
- package/skills/trtc/tools/__init__.py +2 -0
- package/skills/trtc/tools/__pycache__/__init__.cpython-313.pyc +0 -0
- package/skills/trtc/tools/__pycache__/query_classifier.cpython-313.pyc +0 -0
- package/skills/trtc/tools/__pycache__/reporting.cpython-313.pyc +0 -0
- package/skills/trtc/tools/__pycache__/search.cpython-313.pyc +0 -0
- package/skills/trtc/tools/__pycache__/session.cpython-313.pyc +0 -0
- package/skills/trtc/tools/apply.py +540 -0
- package/skills/trtc/tools/docs.py +712 -0
- package/skills/trtc/tools/docsbot.py +182 -0
- package/skills/trtc/tools/entry/render_ai_instructions.py +92 -0
- package/skills/trtc/tools/flow.py +1089 -0
- package/skills/{trtc-topic/scripts → trtc/tools}/init_slice_queue.py +5 -4
- package/skills/{trtc-topic/scripts → trtc/tools}/next_slice.py +5 -4
- package/skills/trtc/tools/query_classifier.py +301 -0
- package/skills/trtc/tools/reporting.py +447 -0
- package/skills/trtc/tools/search.py +817 -0
- package/skills/trtc/tools/session.py +1261 -0
- package/skills/trtc/tools/state_machine.py +690 -0
- package/skills/trtc-ai-service/README.md +195 -0
- package/skills/trtc-ai-service/README.zh-CN.md +193 -0
- package/skills/trtc-ai-service/SKILL.md +945 -0
- package/skills/trtc-ai-service/auto_adapters/README.md +40 -0
- package/skills/trtc-ai-service/auto_adapters/frontend-spa/README.md +27 -0
- package/skills/trtc-ai-service/auto_adapters/frontend-spa/angular/voice-agent.component.ts.tpl +131 -0
- package/skills/trtc-ai-service/auto_adapters/frontend-spa/manifest.yaml +57 -0
- package/skills/trtc-ai-service/auto_adapters/frontend-spa/react/VoiceAgent.tsx.tpl +142 -0
- package/skills/trtc-ai-service/auto_adapters/frontend-spa/vue/VoiceAgent.vue.tpl +121 -0
- package/skills/trtc-ai-service/auto_adapters/integration_templates/generic-backend.md +45 -0
- package/skills/trtc-ai-service/auto_adapters/integration_templates/generic-frontend.md +51 -0
- package/skills/trtc-ai-service/auto_adapters/integration_templates/generic-rest-api.md +93 -0
- package/skills/trtc-ai-service/auto_adapters/java-backend/README.md +25 -0
- package/skills/trtc-ai-service/auto_adapters/java-backend/manifest.yaml +30 -0
- package/skills/trtc-ai-service/auto_adapters/java-backend/quarkus/VoiceAgentFilter.java.tpl +64 -0
- package/skills/trtc-ai-service/auto_adapters/java-backend/springboot/VoiceAgentFilter.java.tpl +91 -0
- package/skills/trtc-ai-service/auto_adapters/manifest.yaml +43 -0
- package/skills/trtc-ai-service/auto_adapters/node-backend/README.md +25 -0
- package/skills/trtc-ai-service/auto_adapters/node-backend/express.js.tpl +40 -0
- package/skills/trtc-ai-service/auto_adapters/node-backend/fastify.js.tpl +27 -0
- package/skills/trtc-ai-service/auto_adapters/node-backend/koa.js.tpl +31 -0
- package/skills/trtc-ai-service/auto_adapters/node-backend/manifest.yaml +47 -0
- package/skills/trtc-ai-service/auto_adapters/python-backend/README.md +22 -0
- package/skills/trtc-ai-service/auto_adapters/python-backend/django.py.tpl +32 -0
- package/skills/trtc-ai-service/auto_adapters/python-backend/fastapi.py.tpl +35 -0
- package/skills/trtc-ai-service/auto_adapters/python-backend/flask.py.tpl +31 -0
- package/skills/trtc-ai-service/auto_adapters/python-backend/manifest.yaml +45 -0
- package/skills/trtc-ai-service/capabilities/__init__.py +43 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/.env.example +29 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/INTEGRATION.md +134 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/INTERFACE_ADAPT.md +111 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/QUICK_START.md +62 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/manifest.yaml +250 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/requirements.txt +6 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/src/__init__.py +10 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/src/_capability_loader.py +218 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/src/agent.py +231 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/src/credentials.py +132 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/src/health.py +355 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/src/log_filter.py +76 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/src/modality.py +109 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/src/server.py +312 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/src/trtc_client.py +315 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/src/usersig.py +90 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/tests/test_skeleton.py +216 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/web-demo/README.md +48 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/web-demo/app.js +415 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/web-demo/index.html +68 -0
- package/skills/trtc-ai-service/capabilities/conversation-core/web-demo/styles.css +136 -0
- package/skills/trtc-ai-service/capabilities/digital-human/README.md +31 -0
- package/skills/trtc-ai-service/capabilities/digital-human/manifest.yaml +64 -0
- package/skills/trtc-ai-service/capabilities/digital-human/src/__init__.py +2 -0
- package/skills/trtc-ai-service/capabilities/digital-human/src/router.py +43 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/INTERFACE_ADAPT.md +353 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/README.md +44 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/manifest.yaml +227 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/__init__.py +2 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/adapters/__init__.py +9 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/adapters/default_rest.py +242 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/adapters/factory.py +89 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/adapters/local_queue.py +258 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/adapters/mock.py +132 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/core/__init__.py +25 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/core/intent_detector.py +75 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/core/models.py +163 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/core/service.py +192 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/feedback_store.py +54 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/ports/__init__.py +4 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/ports/handoff_client.py +86 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/queue.py +62 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/router.py +201 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/summary_link.py +77 -0
- package/skills/trtc-ai-service/capabilities/human-handoff/src/trigger.py +25 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/INTERFACE_ADAPT.md +297 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/README.md +51 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/data/faq.json +20 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/manifest.yaml +211 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/src/__init__.py +8 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/src/adapters/__init__.py +9 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/src/adapters/default_rest.py +209 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/src/adapters/factory.py +86 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/src/adapters/local_json.py +172 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/src/adapters/mock.py +91 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/src/core/__init__.py +12 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/src/core/models.py +77 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/src/core/scoring.py +73 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/src/core/service.py +78 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/src/ports/__init__.py +4 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/src/ports/kb_client.py +61 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/src/retriever.py +56 -0
- package/skills/trtc-ai-service/capabilities/knowledge-base/src/router.py +85 -0
- package/skills/trtc-ai-service/capabilities/session-summary/INTERFACE_ADAPT.md +99 -0
- package/skills/trtc-ai-service/capabilities/session-summary/README.md +47 -0
- package/skills/trtc-ai-service/capabilities/session-summary/data/test_session.json +18 -0
- package/skills/trtc-ai-service/capabilities/session-summary/manifest.yaml +165 -0
- package/skills/trtc-ai-service/capabilities/session-summary/src/__init__.py +2 -0
- package/skills/trtc-ai-service/capabilities/session-summary/src/adapters/__init__.py +5 -0
- package/skills/trtc-ai-service/capabilities/session-summary/src/adapters/base.py +31 -0
- package/skills/trtc-ai-service/capabilities/session-summary/src/adapters/default_rest.py +67 -0
- package/skills/trtc-ai-service/capabilities/session-summary/src/adapters/factory.py +51 -0
- package/skills/trtc-ai-service/capabilities/session-summary/src/adapters/local_json.py +42 -0
- package/skills/trtc-ai-service/capabilities/session-summary/src/adapters/mock.py +22 -0
- package/skills/trtc-ai-service/capabilities/session-summary/src/recorder.py +210 -0
- package/skills/trtc-ai-service/capabilities/session-summary/src/router.py +93 -0
- package/skills/trtc-ai-service/capabilities/session-summary/src/summarizer.py +163 -0
- package/skills/trtc-ai-service/capabilities/tool-calling/INTERFACE_ADAPT.md +158 -0
- package/skills/trtc-ai-service/capabilities/tool-calling/README.md +50 -0
- package/skills/trtc-ai-service/capabilities/tool-calling/data/tools.yaml +58 -0
- package/skills/trtc-ai-service/capabilities/tool-calling/examples/__init__.py +1 -0
- package/skills/trtc-ai-service/capabilities/tool-calling/examples/local_tools.py +101 -0
- package/skills/trtc-ai-service/capabilities/tool-calling/manifest.yaml +146 -0
- package/skills/trtc-ai-service/capabilities/tool-calling/src/__init__.py +8 -0
- package/skills/trtc-ai-service/capabilities/tool-calling/src/dispatcher.py +54 -0
- package/skills/trtc-ai-service/capabilities/tool-calling/src/registry.py +219 -0
- package/skills/trtc-ai-service/capabilities/tool-calling/src/router.py +50 -0
- package/skills/trtc-ai-service/references/business-contract-spec.md +263 -0
- package/skills/trtc-ai-service/scenarios/custom-builder/README.md +86 -0
- package/skills/trtc-ai-service/scenarios/custom-builder/output-templates/recipe.yaml.j2 +194 -0
- package/skills/trtc-ai-service/scenarios/custom-builder/prompts/q1-business-scenario.md +43 -0
- package/skills/trtc-ai-service/scenarios/custom-builder/prompts/q2-io-modality.md +57 -0
- package/skills/trtc-ai-service/scenarios/custom-builder/prompts/q3-ui-form.md +55 -0
- package/skills/trtc-ai-service/scenarios/custom-builder/prompts/q4-capabilities.md +78 -0
- package/skills/trtc-ai-service/scenarios/customer-service/README.md +114 -0
- package/skills/trtc-ai-service/scenarios/customer-service/recipe.yaml +154 -0
- package/skills/trtc-ai-service/scenarios/customer-service/sample-data/README.md +32 -0
- package/skills/trtc-ai-service/scenarios/customer-service/sample-data/faq-sample.json +37 -0
- package/skills/trtc-ai-service/scenarios/customer-service/system-prompt.template.md +94 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/admin-board/app.js +347 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/admin-board/index.html +125 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/admin-board/styles.css +487 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/admin-board/tokens.css +71 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/design-system/DESIGN_GUIDELINES.md +370 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/voice-customer-service/README.md +68 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/voice-customer-service/app.js +1307 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/voice-customer-service/data.js +40 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/voice-customer-service/index.html +233 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/voice-customer-service/mock-shop.json +21 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/voice-customer-service/styles.css +603 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/voice-customer-service/tokens.css +71 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/widget-floating/agent-link.js +323 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/widget-floating/app.js +458 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/widget-floating/index.html +109 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/widget-floating/styles.css +489 -0
- package/skills/trtc-ai-service/scenarios/customer-service/ui/widget-floating/tokens.css +59 -0
- package/skills/trtc-ai-service/scripts/add-capability.py +364 -0
- package/skills/trtc-ai-service/scripts/contract-adapt.py +334 -0
- package/skills/trtc-ai-service/scripts/detect-stack.py +40 -0
- package/skills/trtc-ai-service/scripts/lib/__init__.py +20 -0
- package/skills/trtc-ai-service/scripts/lib/adapter_codegen.py +509 -0
- package/skills/trtc-ai-service/scripts/lib/arbitrator.py +152 -0
- package/skills/trtc-ai-service/scripts/lib/contract_resolver.py +519 -0
- package/skills/trtc-ai-service/scripts/lib/credential_validators.py +253 -0
- package/skills/trtc-ai-service/scripts/lib/curl_parser.py +303 -0
- package/skills/trtc-ai-service/scripts/lib/degrader.py +140 -0
- package/skills/trtc-ai-service/scripts/lib/injector.py +347 -0
- package/skills/trtc-ai-service/scripts/lib/manifest_resolver.py +288 -0
- package/skills/trtc-ai-service/scripts/lib/openapi_parser.py +289 -0
- package/skills/trtc-ai-service/scripts/lib/stack_detector.py +159 -0
- package/skills/trtc-ai-service/scripts/lib/tokens_compile.py +204 -0
- package/skills/trtc-ai-service/scripts/post-install-patch.py +225 -0
- package/skills/trtc-ai-service/scripts/setup-credentials.py +393 -0
- package/skills/trtc-ai-service/scripts/verify-credentials.py +108 -0
- package/skills/trtc-ai-service/start.sh +111 -0
- package/skills/trtc-ai-service/tests/__init__.py +1 -0
- package/skills/trtc-ai-service/tests/test_arbitrator.py +64 -0
- package/skills/trtc-ai-service/tests/test_capability_overlay.py +85 -0
- package/skills/trtc-ai-service/tests/test_contract_resolver.py +190 -0
- package/skills/trtc-ai-service/tests/test_handoff_ports.py +195 -0
- package/skills/trtc-ai-service/tests/test_kb_ports.py +195 -0
- package/skills/trtc-ai-service/tests/test_manifest_resolver.py +95 -0
- package/skills/trtc-ai-service/tests/test_recipe_assembly.py +175 -0
- package/skills/trtc-ai-service/tests/test_stack_and_degrader.py +101 -0
- package/skills/trtc-ai-service/tests/test_verify_credentials.py +285 -0
- package/skills/trtc-ai-service/triggers.yaml +29 -0
- package/skills/trtc-conference/SKILL.md +324 -0
- package/skills/trtc-conference/flows/onboarding.md +205 -0
- package/skills/trtc-conference/flows/topic.md +474 -0
- package/skills/trtc-conference/flows/troubleshoot.md +85 -0
- package/skills/trtc-conference/hooks/pretooluse_require_business_decisions.py +213 -0
- package/skills/trtc-conference/playbooks/medical-quickstart.md +84 -0
- package/skills/trtc-conference/playbooks/official-roomkit.md +97 -0
- package/skills/trtc-conference/references/local-usersig/basic-info-config.ts +39 -0
- package/skills/trtc-conference/references/usersig-handling.md +134 -0
- package/skills/trtc-conference/templates/medical-consultation/src/config/lib-generate-test-usersig-es.min.d.ts +4 -0
- package/skills/trtc-conference/templates/medical-consultation/src/config/lib-generate-test-usersig-es.min.js +2 -0
- package/skills/trtc-conference/tests/__pycache__/test_conference_onboarding_contract.cpython-313-pytest-9.0.2.pyc +0 -0
- package/skills/trtc-conference/tests/__pycache__/test_conference_topic_flow_contract.cpython-313-pytest-9.0.2.pyc +0 -0
- package/skills/trtc-conference/tests/test_conference_index_contract.py +43 -0
- package/skills/trtc-conference/tests/test_conference_onboarding_contract.py +103 -0
- package/skills/trtc-conference/tests/test_conference_template_contract.py +25 -0
- package/skills/trtc-conference/tests/test_conference_topic_flow_contract.py +132 -0
- package/skills/trtc-conference/tools/apply_checks.py +328 -0
- package/skills/trtc-conference/verify_lib/__init__.py +0 -0
- package/skills/{trtc-apply/guardrails/apply_lib → trtc-conference/verify_lib}/rule_parser.py +1 -1
- package/skills/trtc-docs/SKILL.md +91 -119
- package/.cursor/rules/ui-mode.mdc +0 -99
- package/ai-instructions/base.md +0 -13
- package/ai-instructions/ui-mode.md +0 -93
- package/knowledge-base/index.yaml +0 -462
- package/skills/trtc/room-builder/SKILL.md +0 -133
- package/skills/trtc/room-builder/templates/scenarios/medical-consultation/README.md +0 -108
- package/skills/trtc/room-builder/tools/render_ai_instructions.py +0 -226
- package/skills/trtc-apply/SKILL.md +0 -97
- package/skills/trtc-onboarding/SKILL.md +0 -841
- package/skills/trtc-onboarding/reference/path-a1-demo.md +0 -103
- package/skills/trtc-onboarding/reference/path-a2-integrate.md +0 -737
- package/skills/trtc-onboarding/reference/path-b-troubleshoot.md +0 -186
- package/skills/trtc-onboarding/reference/path-c-expand.md +0 -43
- package/skills/trtc-onboarding/reference/supported-matrix.md +0 -100
- package/skills/trtc-search/SKILL.md +0 -228
- package/skills/trtc-topic/SKILL.md +0 -622
- package/skills/trtc-topic/scripts/apply.py +0 -581
- package/skills/trtc-topic/scripts/lib/state_machine.py +0 -328
- package/skills/trtc-topic/tests/README.md +0 -70
- package/skills/trtc-topic/tests/conftest.py +0 -72
- package/skills/trtc-topic/tests/test_apply_cli.py +0 -480
- package/skills/trtc-topic/tests/test_end_to_end.py +0 -305
- package/skills/trtc-topic/tests/test_finalize_session.py +0 -51
- package/skills/trtc-topic/tests/test_gates.py +0 -316
- package/skills/trtc-topic/tests/test_session_resolver.py +0 -260
- package/skills/trtc-topic/tests/test_state_machine.py +0 -414
- package/skills/trtc-topic/tests/test_stop_require_apply.py +0 -99
- package/skills/trtc-topic/tests/test_topic_skill_invariants.py +0 -130
- /package/skills/{trtc-topic → trtc}/runtime/lib/platforms.py +0 -0
- /package/skills/{trtc-topic → trtc}/runtime/telemetry_collector.py +0 -0
- /package/skills/{trtc-onboarding/reference → trtc/runtime}/usersig-handling.md +0 -0
- /package/skills/{trtc-topic/scripts → trtc/tools}/finalize_session.py +0 -0
- /package/skills/{trtc-apply/guardrails/apply_lib → trtc-ai-service/capabilities/conversation-core/tests}/__init__.py +0 -0
- /package/skills/{trtc-topic → trtc-conference}/references/execution-units.yaml +0 -0
- /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
- /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
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/docs/backend-contract.zh-CN.md +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/docs/integration.zh-CN.md +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/docs/theme.zh-CN.md +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/index.html +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/package.json +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/postcss.config.js +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/App.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/ConsultationManagePanel.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/LanguageSwitch.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/LoadingSpinner.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/MedicalAlert.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/MedicalBusinessPanel.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/MedicalButton.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/MedicalConfirmDialog.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/MedicalDataPanel.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/MedicalRecordPanel.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/components/PrescriptionPanel.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/config/basic-info-config.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/config/runtime-config.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/env.d.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/components/ConsultationChatPanel.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/components/ConsultationMembersPanel.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/components/ConsultationTranscriptionPanel.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/components/ConsultationVideoStage.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/components/InviteDoctorDialog.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/components/KickMemberConfirmDialog.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/types.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/useConsultationChat.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/useConsultationDevices.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/useConsultationParticipants.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/useConsultationPermissions.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/features/consultation/utils.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/i18n/en-US/index.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/i18n/index.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/i18n/medicalTranslate.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/i18n/state.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/i18n/zh-CN/index.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/main.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/mock/appointments.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/mock/users.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/router/index.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/index.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/integration/appointmentService.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/integration/authService.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/integration/launchContext.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/integration/userService.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/mock/appointmentService.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/mock/authService.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/mock/userService.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/services/adapters/types.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/shared/icons.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/styles/index.css +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/styles/tailwind.css +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/styles/theme.css +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/utils/auth.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/utils/format.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/utils/navigation.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/utils/session.ts +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/views/DoctorConsultationView.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/views/DoctorDashboardView.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/views/LoginView.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/views/PatientConsultationFinishedView.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/views/PatientConsultationView.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/views/PatientSelectDoctorView.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/src/views/PatientWaitingView.vue +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/tsconfig.json +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/tsconfig.node.json +0 -0
- /package/skills/{trtc/room-builder/templates/scenarios → trtc-conference/templates}/medical-consultation/vite.config.ts +0 -0
- /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
- /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 |
|