@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,40 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""Tech stack detection CLI.
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
python scripts/detect-stack.py /path/to/user/project
|
|
7
|
+
python scripts/detect-stack.py /path/to/user/project --json
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import json
|
|
13
|
+
import sys
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
_HERE = Path(__file__).resolve().parent
|
|
17
|
+
sys.path.insert(0, str(_HERE.parent))
|
|
18
|
+
|
|
19
|
+
from scripts.lib import stack_detector as sd
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def main() -> None:
|
|
23
|
+
parser = argparse.ArgumentParser(description="Tech stack detection CLI")
|
|
24
|
+
parser.add_argument("project", type=Path, help="Target project root directory")
|
|
25
|
+
parser.add_argument("--json", action="store_true")
|
|
26
|
+
args = parser.parse_args()
|
|
27
|
+
|
|
28
|
+
if not args.project.exists():
|
|
29
|
+
raise SystemExit(f"path not found: {args.project}")
|
|
30
|
+
res = sd.detect(args.project)
|
|
31
|
+
if args.json:
|
|
32
|
+
print(json.dumps(res.to_dict(), ensure_ascii=False, indent=2))
|
|
33
|
+
else:
|
|
34
|
+
print(f"primary : {res.primary}")
|
|
35
|
+
print(f"candidates : {', '.join(res.candidates) or '-'}")
|
|
36
|
+
print(f"signals : {', '.join(res.signals) or '-'}")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
main()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Phase 2 shared infrastructure (no business logic).
|
|
2
|
+
|
|
3
|
+
This package exposes reusable modules to CLI tools like add-capability / detect-stack:
|
|
4
|
+
|
|
5
|
+
- manifest_resolver Capability manifest loading / dependency graph / topological sort / circular dependency detection
|
|
6
|
+
- stack_detector Tech stack detection (package.json / pom.xml / requirements.txt, etc.)
|
|
7
|
+
- degrader Three-tier fallback decision engine (L1 auto / L2 semi-auto / L3 manual)
|
|
8
|
+
- injector Code injection based on manifest.injection_points position descriptions
|
|
9
|
+
- arbitrator α/β dual-track tool-call arbitration (for internal use by the tool-calling capability)
|
|
10
|
+
|
|
11
|
+
Design principle: this package has no business logic dependencies; protocol parsing and policy decisions only.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"manifest_resolver",
|
|
16
|
+
"stack_detector",
|
|
17
|
+
"degrader",
|
|
18
|
+
"injector",
|
|
19
|
+
"arbitrator",
|
|
20
|
+
]
|
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
"""Three-tier fallback adapter code generator (Phase 3 Stage 4).
|
|
2
|
+
|
|
3
|
+
Input: set of ``ContractDiff`` + user's original ParsedApi set + capability directory.
|
|
4
|
+
Output: ``capabilities/<name>/src/adapters/user_custom.py`` (L1/L2) or
|
|
5
|
+
section path pointing to ``INTERFACE_ADAPT.md`` (L3).
|
|
6
|
+
|
|
7
|
+
Design principles:
|
|
8
|
+
- Both L1 and L2 generate the same ``user_custom.py``; L2 just includes ``# TODO`` comments for the user to fill in
|
|
9
|
+
- L1 / L2 preferentially inherit from ``DefaultRest*Client`` to reuse HTTP / auth / security validation
|
|
10
|
+
- L3 generates no code — only outputs the section path from INTERFACE_ADAPT.md at the corresponding level
|
|
11
|
+
- Generated artifacts are **idempotent**: old ``user_custom.py`` is backed up as ``.bak`` before each rewrite
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import time
|
|
16
|
+
from dataclasses import dataclass, field
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any, Dict, List, Optional
|
|
19
|
+
|
|
20
|
+
from .contract_resolver import (
|
|
21
|
+
BusinessContract,
|
|
22
|
+
ContractDiff,
|
|
23
|
+
DegradeLevel,
|
|
24
|
+
ExternalApi,
|
|
25
|
+
FieldDiff,
|
|
26
|
+
)
|
|
27
|
+
from .curl_parser import ParsedApi
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# ---------------------------------------------------------------------------
|
|
31
|
+
# Input aggregation
|
|
32
|
+
# ---------------------------------------------------------------------------
|
|
33
|
+
@dataclass
|
|
34
|
+
class ApiAdaptation:
|
|
35
|
+
"""单条契约的适配结果。"""
|
|
36
|
+
|
|
37
|
+
default: ExternalApi
|
|
38
|
+
user: Optional[ParsedApi]
|
|
39
|
+
diff: Optional[ContractDiff]
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def level(self) -> DegradeLevel:
|
|
43
|
+
if self.diff is None:
|
|
44
|
+
return DegradeLevel.L1 # user did not provide → use default contract
|
|
45
|
+
return self.diff.level
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@dataclass
|
|
49
|
+
class CodegenResult:
|
|
50
|
+
level: DegradeLevel
|
|
51
|
+
capability: str
|
|
52
|
+
artifact: str = "" # relative path of generated file or doc path
|
|
53
|
+
todos: List[str] = field(default_factory=list)
|
|
54
|
+
notes: List[str] = field(default_factory=list)
|
|
55
|
+
enable_env: Dict[str, str] = field(default_factory=dict) # env vars needed to enable
|
|
56
|
+
|
|
57
|
+
def to_dict(self) -> Dict:
|
|
58
|
+
return {
|
|
59
|
+
"level": self.level.value,
|
|
60
|
+
"capability": self.capability,
|
|
61
|
+
"artifact": self.artifact,
|
|
62
|
+
"todos": self.todos,
|
|
63
|
+
"notes": self.notes,
|
|
64
|
+
"enable_env": self.enable_env,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# ---------------------------------------------------------------------------
|
|
69
|
+
# Code generation templates for known capability packages
|
|
70
|
+
# ---------------------------------------------------------------------------
|
|
71
|
+
_KNOWN_CAPABILITIES = {
|
|
72
|
+
"human-handoff": {
|
|
73
|
+
"default_adapter_class": "DefaultRestHandoffClient",
|
|
74
|
+
"import_default": "from .default_rest import DefaultRestHandoffClient",
|
|
75
|
+
"from_env_factory": "user_custom_from_env",
|
|
76
|
+
"env_prefix": "HH_REST",
|
|
77
|
+
"adapter_env": "HH_ADAPTER",
|
|
78
|
+
},
|
|
79
|
+
"knowledge-base": {
|
|
80
|
+
"default_adapter_class": "DefaultRestKbClient",
|
|
81
|
+
"import_default": "from .default_rest import DefaultRestKbClient",
|
|
82
|
+
"from_env_factory": "user_custom_from_env",
|
|
83
|
+
"env_prefix": "KB_REST",
|
|
84
|
+
"adapter_env": "KB_ADAPTER",
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# ---------------------------------------------------------------------------
|
|
90
|
+
# Main entry
|
|
91
|
+
# ---------------------------------------------------------------------------
|
|
92
|
+
def generate_user_custom(
|
|
93
|
+
contract: BusinessContract,
|
|
94
|
+
adaptations: List[ApiAdaptation],
|
|
95
|
+
capability_dir: Path,
|
|
96
|
+
*,
|
|
97
|
+
base_url: str = "",
|
|
98
|
+
auth_header: str = "",
|
|
99
|
+
dry_run: bool = False,
|
|
100
|
+
) -> CodegenResult:
|
|
101
|
+
"""Infer overall level from adaptations → generate user_custom.py or return L3 guidance path."""
|
|
102
|
+
|
|
103
|
+
levels = [a.level for a in adaptations]
|
|
104
|
+
overall = max(levels, key=lambda lv: ["L1", "L2", "L3"].index(lv.value)) if levels else DegradeLevel.L1
|
|
105
|
+
cap_name = contract.capability
|
|
106
|
+
known = _KNOWN_CAPABILITIES.get(cap_name)
|
|
107
|
+
result = CodegenResult(level=overall, capability=cap_name)
|
|
108
|
+
|
|
109
|
+
if overall == DegradeLevel.L3 or known is None:
|
|
110
|
+
sop = capability_dir / contract.customization_sop
|
|
111
|
+
result.level = DegradeLevel.L3 if known is None else overall
|
|
112
|
+
try:
|
|
113
|
+
result.artifact = str(sop.relative_to(capability_dir.parent.parent))
|
|
114
|
+
except ValueError:
|
|
115
|
+
result.artifact = str(sop)
|
|
116
|
+
if known is None:
|
|
117
|
+
result.notes.append(
|
|
118
|
+
f"Capability {cap_name} has no codegen template; implement manually per INTERFACE_ADAPT.md"
|
|
119
|
+
)
|
|
120
|
+
else:
|
|
121
|
+
result.notes.append("Protocol-level differences; implement manually per INTERFACE_ADAPT.md §5 L3 template")
|
|
122
|
+
return result
|
|
123
|
+
|
|
124
|
+
# Render code
|
|
125
|
+
code = _render_user_custom(contract, adaptations, known, base_url, auth_header)
|
|
126
|
+
todos = _collect_todos(adaptations)
|
|
127
|
+
|
|
128
|
+
target = capability_dir / "src" / "adapters" / "user_custom.py"
|
|
129
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
130
|
+
|
|
131
|
+
if not dry_run:
|
|
132
|
+
if target.exists():
|
|
133
|
+
backup = target.with_suffix(".py.bak")
|
|
134
|
+
backup.write_text(target.read_text(encoding="utf-8"), encoding="utf-8")
|
|
135
|
+
target.write_text(code, encoding="utf-8")
|
|
136
|
+
|
|
137
|
+
mapping_path = capability_dir / "src" / "adapters" / "user_custom_mapping.yaml"
|
|
138
|
+
mapping_path.write_text(_render_mapping_yaml(adaptations), encoding="utf-8")
|
|
139
|
+
|
|
140
|
+
try:
|
|
141
|
+
result.artifact = str(target.relative_to(capability_dir.parent.parent))
|
|
142
|
+
except ValueError:
|
|
143
|
+
result.artifact = str(target)
|
|
144
|
+
result.todos = todos
|
|
145
|
+
result.enable_env = {
|
|
146
|
+
known["adapter_env"]: "user_custom",
|
|
147
|
+
f"{known['env_prefix']}_BASE_URL": base_url or "<请填写你的 API 基础 URL>",
|
|
148
|
+
}
|
|
149
|
+
if auth_header and auth_header.lower() != "authorization":
|
|
150
|
+
result.notes.append(
|
|
151
|
+
f"鉴权头 '{auth_header}' 非默认 Bearer,已在生成的 _headers() 中覆写"
|
|
152
|
+
)
|
|
153
|
+
if overall == DegradeLevel.L2:
|
|
154
|
+
result.notes.append("生成文件包含 TODO 标注,请按 todos[] 列表逐项补完")
|
|
155
|
+
return result
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
# ---------------------------------------------------------------------------
|
|
159
|
+
# Code block utilities: assemble code by "line + indent level", avoiding textwrap.dedent / f-string indent traps
|
|
160
|
+
# ---------------------------------------------------------------------------
|
|
161
|
+
INDENT = " " # 4 spaces
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _join_lines(lines: List[str]) -> str:
|
|
165
|
+
return "\n".join(lines)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def _indent_block(text: str, level: int) -> str:
|
|
169
|
+
pad = INDENT * level
|
|
170
|
+
return "\n".join((pad + line) if line else "" for line in text.splitlines())
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
# ---------------------------------------------------------------------------
|
|
174
|
+
# user_custom.py full render
|
|
175
|
+
# ---------------------------------------------------------------------------
|
|
176
|
+
def _render_user_custom(
|
|
177
|
+
contract: BusinessContract,
|
|
178
|
+
adaptations: List[ApiAdaptation],
|
|
179
|
+
known: Dict[str, str],
|
|
180
|
+
base_url: str,
|
|
181
|
+
auth_header: str,
|
|
182
|
+
) -> str:
|
|
183
|
+
cap = contract.capability
|
|
184
|
+
adapter_class = "UserCustomHandoffClient" if cap == "human-handoff" else "UserCustomKbClient"
|
|
185
|
+
base_class = known["default_adapter_class"]
|
|
186
|
+
factory_name = known["from_env_factory"]
|
|
187
|
+
env_prefix = known["env_prefix"]
|
|
188
|
+
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
|
189
|
+
|
|
190
|
+
summary_lines = [f" - {ap.default.name}: {ap.level.value}" for ap in adaptations]
|
|
191
|
+
summary = "\n".join(summary_lines) if summary_lines else " (none)"
|
|
192
|
+
|
|
193
|
+
lines: List[str] = []
|
|
194
|
+
lines.append(f'"""user_custom adapter for {cap} (auto-generated by contract-adapt.py).')
|
|
195
|
+
lines.append("")
|
|
196
|
+
lines.append(f"Generated at : {timestamp}")
|
|
197
|
+
lines.append(f"Base URL : {base_url or '<unset>'}")
|
|
198
|
+
lines.append(f"Auth header : {auth_header or 'Authorization (Bearer)'}")
|
|
199
|
+
lines.append("")
|
|
200
|
+
lines.append("Coverage summary:")
|
|
201
|
+
lines.append(summary)
|
|
202
|
+
lines.append("")
|
|
203
|
+
lines.append("Automatically generated by ``scripts/contract-adapt.py``. Do not edit by hand; re-running creates a .bak backup.")
|
|
204
|
+
lines.append('"""')
|
|
205
|
+
lines.append("from __future__ import annotations")
|
|
206
|
+
lines.append("")
|
|
207
|
+
lines.append("import os")
|
|
208
|
+
lines.append("from typing import List, Optional")
|
|
209
|
+
lines.append("")
|
|
210
|
+
lines.append(known["import_default"])
|
|
211
|
+
lines.append("")
|
|
212
|
+
lines.append("")
|
|
213
|
+
lines.append(f"class {adapter_class}({base_class}):")
|
|
214
|
+
lines.append(f' """L1/L2 field-mapping adapter ({cap})."""')
|
|
215
|
+
lines.append("")
|
|
216
|
+
|
|
217
|
+
# 鉴权头覆写(如有)
|
|
218
|
+
if auth_header and auth_header.lower() != "authorization":
|
|
219
|
+
for ln in _render_header_override(auth_header).splitlines():
|
|
220
|
+
lines.append(INDENT + ln if ln else "")
|
|
221
|
+
lines.append("")
|
|
222
|
+
|
|
223
|
+
# 各方法体
|
|
224
|
+
for ap in adaptations:
|
|
225
|
+
method_block = (
|
|
226
|
+
_render_hh_method(ap, auth_header) if cap == "human-handoff" else _render_kb_method(ap, auth_header)
|
|
227
|
+
)
|
|
228
|
+
if not method_block.strip():
|
|
229
|
+
continue
|
|
230
|
+
for ln in method_block.splitlines():
|
|
231
|
+
lines.append(INDENT + ln if ln else "")
|
|
232
|
+
lines.append("")
|
|
233
|
+
|
|
234
|
+
# 工厂函数(模块级)
|
|
235
|
+
lines.append("")
|
|
236
|
+
lines.append(f'def {factory_name}() -> Optional["{adapter_class}"]:')
|
|
237
|
+
lines.append(f' base = os.getenv("{env_prefix}_BASE_URL")')
|
|
238
|
+
lines.append(" if not base:")
|
|
239
|
+
lines.append(" return None")
|
|
240
|
+
lines.append(f" return {adapter_class}(")
|
|
241
|
+
lines.append(" base_url=base,")
|
|
242
|
+
lines.append(f' token=os.getenv("{env_prefix}_TOKEN"),')
|
|
243
|
+
lines.append(f' timeout_ms=int(os.getenv("{env_prefix}_TIMEOUT_MS", "5000")),')
|
|
244
|
+
lines.append(" )")
|
|
245
|
+
lines.append("")
|
|
246
|
+
|
|
247
|
+
return _join_lines(lines)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _render_header_override(auth_header: str) -> str:
|
|
251
|
+
return _join_lines([
|
|
252
|
+
"def _headers(self) -> dict:",
|
|
253
|
+
' h = {"Content-Type": "application/json"}',
|
|
254
|
+
" if self._token:",
|
|
255
|
+
f' h["{auth_header}"] = self._token # 自定义鉴权头(contract-adapt 解析)',
|
|
256
|
+
" return h",
|
|
257
|
+
])
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
# ---------------------------------------------------------------------------
|
|
261
|
+
# diff → 字段映射工具
|
|
262
|
+
# ---------------------------------------------------------------------------
|
|
263
|
+
def _mapping(diff: Optional[ContractDiff], section: str) -> Dict[str, str]:
|
|
264
|
+
if diff is None:
|
|
265
|
+
return {}
|
|
266
|
+
out: Dict[str, str] = {}
|
|
267
|
+
for f in diff.fields:
|
|
268
|
+
if f.kind == "rename" and f.path.startswith(section + "."):
|
|
269
|
+
out[f.path.split(".", 1)[1]] = f.user
|
|
270
|
+
return out
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
# ---------------------------------------------------------------------------
|
|
274
|
+
# human-handoff: 各方法渲染
|
|
275
|
+
# ---------------------------------------------------------------------------
|
|
276
|
+
def _render_hh_method(ap: ApiAdaptation, auth_header: str) -> str:
|
|
277
|
+
name = ap.default.name
|
|
278
|
+
if name == "ticket.create":
|
|
279
|
+
return _render_hh_create(ap)
|
|
280
|
+
if name == "ticket.status_query":
|
|
281
|
+
return _render_hh_status(ap)
|
|
282
|
+
if name == "ticket.cancel":
|
|
283
|
+
return _render_hh_cancel(ap)
|
|
284
|
+
return ""
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def _render_hh_create(ap: ApiAdaptation) -> str:
|
|
288
|
+
req_map = _mapping(ap.diff, "request") or {}
|
|
289
|
+
resp_map = _mapping(ap.diff, "response") or {}
|
|
290
|
+
user_path = ap.user.path if ap.user else "/tickets"
|
|
291
|
+
todo_marker = "# TODO" if ap.level == DegradeLevel.L2 else "# auto-mapped"
|
|
292
|
+
|
|
293
|
+
rid = resp_map.get("ticket_id", "ticket_id")
|
|
294
|
+
rqp = resp_map.get("queue_position", "queue_position")
|
|
295
|
+
reta = resp_map.get("eta_seconds", "eta_seconds")
|
|
296
|
+
|
|
297
|
+
payload_kv: List[str] = []
|
|
298
|
+
for default_field, value_expr in (
|
|
299
|
+
("user_id", "user_id"),
|
|
300
|
+
("subject", "subject"),
|
|
301
|
+
("description", "description"),
|
|
302
|
+
("priority", "priority"),
|
|
303
|
+
("transcript", "list(transcript or [])"),
|
|
304
|
+
):
|
|
305
|
+
user_field = req_map.get(default_field, default_field)
|
|
306
|
+
payload_kv.append(f' "{user_field}": {value_expr},')
|
|
307
|
+
|
|
308
|
+
return _join_lines([
|
|
309
|
+
"def create_ticket(",
|
|
310
|
+
" self,",
|
|
311
|
+
" *,",
|
|
312
|
+
" user_id: str,",
|
|
313
|
+
' subject: str = "",',
|
|
314
|
+
' description: str = "",',
|
|
315
|
+
' priority: str = "normal",',
|
|
316
|
+
" transcript: Optional[List[str]] = None,",
|
|
317
|
+
"):",
|
|
318
|
+
" from ..core.models import Ticket, TicketStatusEnum, now_ts",
|
|
319
|
+
f" payload = {{ {todo_marker}: 字段映射由 contract-adapt 推断",
|
|
320
|
+
*payload_kv,
|
|
321
|
+
" }",
|
|
322
|
+
f' data = self._post("{user_path}", payload)',
|
|
323
|
+
f' ticket_id = str(data.get("{rid}") or "").strip()',
|
|
324
|
+
" if not ticket_id:",
|
|
325
|
+
f' raise RuntimeError("remote did not return id field {rid!r}")',
|
|
326
|
+
" return Ticket(",
|
|
327
|
+
" ticket_id=ticket_id,",
|
|
328
|
+
" user_id=user_id,",
|
|
329
|
+
" subject=subject,",
|
|
330
|
+
" description=description,",
|
|
331
|
+
' priority=priority or "normal",',
|
|
332
|
+
" status=TicketStatusEnum.PENDING.value,",
|
|
333
|
+
f' queue_position=int(data.get("{rqp}") or 0),',
|
|
334
|
+
f' eta_seconds=int(data.get("{reta}") or 0),',
|
|
335
|
+
" transcript=list(transcript or []),",
|
|
336
|
+
' reason=description[:128] if description else "",',
|
|
337
|
+
" created_at=now_ts(),",
|
|
338
|
+
" updated_at=now_ts(),",
|
|
339
|
+
" )",
|
|
340
|
+
])
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def _render_hh_status(ap: ApiAdaptation) -> str:
|
|
344
|
+
resp_map = _mapping(ap.diff, "response") or {}
|
|
345
|
+
user_path = ap.user.path if ap.user else "/tickets/{ticket_id}"
|
|
346
|
+
rid = resp_map.get("ticket_id", "ticket_id")
|
|
347
|
+
rstatus = resp_map.get("status", "status")
|
|
348
|
+
ragent = resp_map.get("agent_id", "agent_id")
|
|
349
|
+
todo_marker = "# TODO" if ap.level == DegradeLevel.L2 else "# auto-mapped"
|
|
350
|
+
|
|
351
|
+
# 用户路径中如果有 {ticket_id} 占位需要保留 f-string
|
|
352
|
+
return _join_lines([
|
|
353
|
+
"def query_status(self, ticket_id: str):",
|
|
354
|
+
" from ..core.models import TicketStatus, TicketStatusEnum",
|
|
355
|
+
f' data = self._get(f"{user_path}", optional=True) {todo_marker}',
|
|
356
|
+
" if data is None:",
|
|
357
|
+
" return None",
|
|
358
|
+
f' status = str(data.get("{rstatus}") or TicketStatusEnum.PENDING.value)',
|
|
359
|
+
" return TicketStatus(",
|
|
360
|
+
f' ticket_id=str(data.get("{rid}") or ticket_id),',
|
|
361
|
+
" status=status,",
|
|
362
|
+
f' agent_id=data.get("{ragent}"),',
|
|
363
|
+
' updated_at=float(data.get("updated_at") or 0.0) or None,',
|
|
364
|
+
" )",
|
|
365
|
+
])
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def _render_hh_cancel(ap: ApiAdaptation) -> str:
|
|
369
|
+
req_map = _mapping(ap.diff, "request") or {}
|
|
370
|
+
user_path = ap.user.path if ap.user else "/tickets/{ticket_id}/cancel"
|
|
371
|
+
rid_field = req_map.get("ticket_id", "ticket_id")
|
|
372
|
+
reason_field = req_map.get("reason", "reason")
|
|
373
|
+
todo_marker = "# TODO" if ap.level == DegradeLevel.L2 else "# auto-mapped"
|
|
374
|
+
|
|
375
|
+
return _join_lines([
|
|
376
|
+
'def cancel_ticket(self, ticket_id: str, reason: str = ""):',
|
|
377
|
+
" from ..core.models import Ticket, TicketStatusEnum, now_ts",
|
|
378
|
+
f" data = self._post( {todo_marker}",
|
|
379
|
+
f' f"{user_path}",',
|
|
380
|
+
f' {{"{rid_field}": ticket_id, "{reason_field}": reason}},',
|
|
381
|
+
" optional=True,",
|
|
382
|
+
" )",
|
|
383
|
+
" if data is None:",
|
|
384
|
+
" return None",
|
|
385
|
+
" return Ticket(",
|
|
386
|
+
" ticket_id=ticket_id,",
|
|
387
|
+
' user_id="",',
|
|
388
|
+
" status=TicketStatusEnum.CANCELED.value,",
|
|
389
|
+
" reason=reason,",
|
|
390
|
+
" updated_at=now_ts(),",
|
|
391
|
+
" closed_at=now_ts(),",
|
|
392
|
+
" )",
|
|
393
|
+
])
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
# ---------------------------------------------------------------------------
|
|
397
|
+
# knowledge-base: 各方法渲染
|
|
398
|
+
# ---------------------------------------------------------------------------
|
|
399
|
+
def _render_kb_method(ap: ApiAdaptation, auth_header: str) -> str:
|
|
400
|
+
name = ap.default.name
|
|
401
|
+
todo_marker = "# TODO" if ap.level == DegradeLevel.L2 else "# auto-mapped"
|
|
402
|
+
if name == "faq.search":
|
|
403
|
+
req_map = _mapping(ap.diff, "request") or {}
|
|
404
|
+
q = req_map.get("query", "query")
|
|
405
|
+
topk = req_map.get("top_k", "top_k")
|
|
406
|
+
path = ap.user.path if ap.user else "/faq/search"
|
|
407
|
+
return _join_lines([
|
|
408
|
+
"def search(self, query: str, *, top_k: Optional[int] = None, min_score: Optional[float] = None):",
|
|
409
|
+
" from ..core.models import SearchHit, FaqEntry",
|
|
410
|
+
f' payload = {{"{q}": query, "{topk}": top_k or 3}} {todo_marker}',
|
|
411
|
+
f' data = self._post("{path}", payload)',
|
|
412
|
+
' hits = data.get("hits") or [] if isinstance(data, dict) else (data or [])',
|
|
413
|
+
" out: List[SearchHit] = []",
|
|
414
|
+
" for h in hits:",
|
|
415
|
+
' entry_data = h.get("entry") if isinstance(h, dict) else None',
|
|
416
|
+
" if not isinstance(entry_data, dict):",
|
|
417
|
+
" continue",
|
|
418
|
+
" out.append(SearchHit(",
|
|
419
|
+
" entry=FaqEntry(",
|
|
420
|
+
' id=str(entry_data.get("id", "")),',
|
|
421
|
+
' question=str(entry_data.get("question", "")),',
|
|
422
|
+
' answer=str(entry_data.get("answer", "")),',
|
|
423
|
+
' keywords=list(entry_data.get("keywords") or []),',
|
|
424
|
+
" ),",
|
|
425
|
+
' score=float(h.get("score") or 0.0),',
|
|
426
|
+
" ))",
|
|
427
|
+
" return out",
|
|
428
|
+
])
|
|
429
|
+
if name == "faq.list":
|
|
430
|
+
path = ap.user.path if ap.user else "/faq"
|
|
431
|
+
return _join_lines([
|
|
432
|
+
"def list_all(self):",
|
|
433
|
+
" from ..core.models import FaqEntry",
|
|
434
|
+
f' data = self._get("{path}") {todo_marker}',
|
|
435
|
+
' items = data.get("items") if isinstance(data, dict) else data',
|
|
436
|
+
" return [FaqEntry(",
|
|
437
|
+
' id=str(it.get("id", "")),',
|
|
438
|
+
' question=str(it.get("question", "")),',
|
|
439
|
+
' answer=str(it.get("answer", "")),',
|
|
440
|
+
' keywords=list(it.get("keywords") or []),',
|
|
441
|
+
" ) for it in (items or [])]",
|
|
442
|
+
])
|
|
443
|
+
if name == "faq.upsert":
|
|
444
|
+
path = ap.user.path if ap.user else "/faq"
|
|
445
|
+
return _join_lines([
|
|
446
|
+
"def upsert(self, entry):",
|
|
447
|
+
" from ..core.models import FaqEntry",
|
|
448
|
+
f" payload = {{ {todo_marker}",
|
|
449
|
+
' "id": entry.id,',
|
|
450
|
+
' "question": entry.question,',
|
|
451
|
+
' "answer": entry.answer,',
|
|
452
|
+
' "keywords": list(entry.keywords or []),',
|
|
453
|
+
" }",
|
|
454
|
+
f' data = self._post("{path}", payload)',
|
|
455
|
+
" return FaqEntry(",
|
|
456
|
+
' id=str(data.get("id", entry.id)),',
|
|
457
|
+
' question=str(data.get("question", entry.question)),',
|
|
458
|
+
' answer=str(data.get("answer", entry.answer)),',
|
|
459
|
+
' keywords=list(data.get("keywords") or entry.keywords or []),',
|
|
460
|
+
" )",
|
|
461
|
+
])
|
|
462
|
+
if name == "faq.delete":
|
|
463
|
+
path = ap.user.path if ap.user else "/faq/{entry_id}"
|
|
464
|
+
return _join_lines([
|
|
465
|
+
"def delete(self, entry_id: str) -> bool:",
|
|
466
|
+
f' url = self._base + f"{path}" {todo_marker}',
|
|
467
|
+
" resp = self._session.delete(url, headers=self._headers(), timeout=self._timeout)",
|
|
468
|
+
" if resp.status_code == 404:",
|
|
469
|
+
" return False",
|
|
470
|
+
" if resp.status_code >= 400:",
|
|
471
|
+
' raise RuntimeError(f"remote kb service returned HTTP {resp.status_code}")',
|
|
472
|
+
" return True",
|
|
473
|
+
])
|
|
474
|
+
return ""
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
# ---------------------------------------------------------------------------
|
|
478
|
+
# mapping.yaml & todos
|
|
479
|
+
# ---------------------------------------------------------------------------
|
|
480
|
+
def _render_mapping_yaml(adaptations: List[ApiAdaptation]) -> str:
|
|
481
|
+
out = ["# 由 scripts/contract-adapt.py 自动生成;左 = 默认契约字段,右 = 用户实际字段", ""]
|
|
482
|
+
for ap in adaptations:
|
|
483
|
+
out.append(f"{ap.default.name}:")
|
|
484
|
+
if ap.diff is None:
|
|
485
|
+
out.append(" # 用户未提供;使用默认契约")
|
|
486
|
+
continue
|
|
487
|
+
for section in ("request", "response"):
|
|
488
|
+
section_map = _mapping(ap.diff, section)
|
|
489
|
+
if section_map:
|
|
490
|
+
out.append(f" {section}:")
|
|
491
|
+
for d, u in section_map.items():
|
|
492
|
+
out.append(f" {d}: {u}")
|
|
493
|
+
out.append(f" level: {ap.level.value}")
|
|
494
|
+
return "\n".join(out) + "\n"
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
def _collect_todos(adaptations: List[ApiAdaptation]) -> List[str]:
|
|
498
|
+
todos: List[str] = []
|
|
499
|
+
for ap in adaptations:
|
|
500
|
+
if ap.level != DegradeLevel.L2 or ap.diff is None:
|
|
501
|
+
continue
|
|
502
|
+
for f in ap.diff.fields:
|
|
503
|
+
if not f.in_slot and f.kind in ("rename", "type_mismatch", "missing_in_user"):
|
|
504
|
+
todos.append(
|
|
505
|
+
f"[{ap.default.name}] {f.path}: {f.kind} default={f.default!r} user={f.user!r}"
|
|
506
|
+
)
|
|
507
|
+
if ap.diff.protocol_mismatch:
|
|
508
|
+
todos.append(f"[{ap.default.name}] protocol: {ap.diff.protocol_reason}")
|
|
509
|
+
return todos
|