bailinghub 0.3.0
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/.dockerignore +42 -0
- package/.env.example +83 -0
- package/.gitignore +44 -0
- package/.npmignore +56 -0
- package/CODE_OF_CONDUCT.md +24 -0
- package/CONTRIBUTING.md +74 -0
- package/Dockerfile +16 -0
- package/LICENSE +176 -0
- package/LICENSING.md +9 -0
- package/NOTICE +23 -0
- package/README.en.md +264 -0
- package/README.md +279 -0
- package/SECURITY.md +30 -0
- package/THIRD_PARTY_NOTICES.md +254 -0
- package/VISION.md +41 -0
- package/assets/architecture-overview.en-dark.png +0 -0
- package/assets/architecture-overview.en-dark.svg +57 -0
- package/assets/architecture-overview.en.png +0 -0
- package/assets/architecture-overview.en.svg +57 -0
- package/assets/architecture-overview.zh-CN-dark.png +0 -0
- package/assets/architecture-overview.zh-CN-dark.svg +57 -0
- package/assets/architecture-overview.zh-CN.png +0 -0
- package/assets/architecture-overview.zh-CN.svg +57 -0
- package/assets/bailinghub-lockup-dark.png +0 -0
- package/assets/bailinghub-lockup-dark.svg +8 -0
- package/assets/bailinghub-lockup.png +0 -0
- package/assets/bailinghub-lockup.svg +8 -0
- package/brain/README.en.md +23 -0
- package/brain/README.md +45 -0
- package/brain/agents/code-review.md +41 -0
- package/brain/agents/triage.md +37 -0
- package/brain/profiles.json +114 -0
- package/brain/runbooks/ticket-triage.md +24 -0
- package/config.example.json +58 -0
- package/contracts/client-api/consumers.json +28 -0
- package/contracts/client-api/v1/error-response.schema.json +21 -0
- package/contracts/client-api/v1/health-response.schema.json +13 -0
- package/contracts/client-api/v1/job-response.schema.json +49 -0
- package/contracts/client-api/v1/manifest.json +63 -0
- package/contracts/client-api/v1/run-request.schema.json +42 -0
- package/contracts/client-api/v1/submit-response.schema.json +35 -0
- package/contracts/client-api/v1/vectors.json +153 -0
- package/demo/business/Dockerfile +8 -0
- package/demo/business/server.mjs +483 -0
- package/docker-compose.images.yml +67 -0
- package/docker-compose.yml +79 -0
- package/docs/AI_FRIENDLY_TOOLS.en.md +69 -0
- package/docs/AI/345/217/213/345/245/275/345/267/245/345/205/267/350/256/276/350/256/241/346/214/207/345/215/227.md +198 -0
- package/docs/ARCHITECTURE.en.md +81 -0
- package/docs/ARCHITECTURE.md +795 -0
- package/docs/CHANGELOG.en.md +275 -0
- package/docs/CHANGELOG.md +279 -0
- package/docs/CHANNELS.en.md +35 -0
- package/docs/CHANNELS.md +72 -0
- package/docs/CLIENT_API.md +89 -0
- package/docs/COMPATIBILITY.en.md +103 -0
- package/docs/CONTRACT.en.md +254 -0
- package/docs/CONTRACT.md +653 -0
- package/docs/DEMO.en.md +90 -0
- package/docs/DEMO.md +297 -0
- package/docs/ECOSYSTEM.en.md +39 -0
- package/docs/ECOSYSTEM.md +39 -0
- package/docs/INDEPENDENT_VALIDATION.en.md +184 -0
- package/docs/INDEPENDENT_VALIDATION.md +184 -0
- package/docs/INTEGRATION.en.md +120 -0
- package/docs/KERNEL_HOST_API.en.md +59 -0
- package/docs/KERNEL_HOST_API.md +59 -0
- package/docs/OPERATIONS.en.md +182 -0
- package/docs/OPERATIONS.md +231 -0
- package/docs/PIPELINE.en.md +74 -0
- package/docs/PIPELINE.md +67 -0
- package/docs/QUICKSTART.en.md +297 -0
- package/docs/QUICKSTART.md +152 -0
- package/docs/README.en.md +103 -0
- package/docs/README.md +119 -0
- package/docs/RELEASE_NOTES_v0.1.0.en.md +46 -0
- package/docs/RELEASE_NOTES_v0.1.0.md +66 -0
- package/docs/RELEASE_NOTES_v0.1.1.en.md +38 -0
- package/docs/RELEASE_NOTES_v0.1.1.md +38 -0
- package/docs/RELEASE_NOTES_v0.1.10.en.md +102 -0
- package/docs/RELEASE_NOTES_v0.1.10.md +102 -0
- package/docs/RELEASE_NOTES_v0.1.11.en.md +99 -0
- package/docs/RELEASE_NOTES_v0.1.11.md +99 -0
- package/docs/RELEASE_NOTES_v0.1.12.en.md +64 -0
- package/docs/RELEASE_NOTES_v0.1.12.md +64 -0
- package/docs/RELEASE_NOTES_v0.1.13.en.md +46 -0
- package/docs/RELEASE_NOTES_v0.1.13.md +46 -0
- package/docs/RELEASE_NOTES_v0.1.14.en.md +55 -0
- package/docs/RELEASE_NOTES_v0.1.14.md +55 -0
- package/docs/RELEASE_NOTES_v0.1.15.en.md +50 -0
- package/docs/RELEASE_NOTES_v0.1.15.md +50 -0
- package/docs/RELEASE_NOTES_v0.1.16.en.md +106 -0
- package/docs/RELEASE_NOTES_v0.1.16.md +105 -0
- package/docs/RELEASE_NOTES_v0.1.2.en.md +39 -0
- package/docs/RELEASE_NOTES_v0.1.2.md +39 -0
- package/docs/RELEASE_NOTES_v0.1.3.en.md +55 -0
- package/docs/RELEASE_NOTES_v0.1.3.md +55 -0
- package/docs/RELEASE_NOTES_v0.1.4.en.md +55 -0
- package/docs/RELEASE_NOTES_v0.1.4.md +55 -0
- package/docs/RELEASE_NOTES_v0.1.5.en.md +49 -0
- package/docs/RELEASE_NOTES_v0.1.5.md +49 -0
- package/docs/RELEASE_NOTES_v0.1.6.en.md +41 -0
- package/docs/RELEASE_NOTES_v0.1.6.md +41 -0
- package/docs/RELEASE_NOTES_v0.1.7.en.md +39 -0
- package/docs/RELEASE_NOTES_v0.1.7.md +39 -0
- package/docs/RELEASE_NOTES_v0.1.8.en.md +88 -0
- package/docs/RELEASE_NOTES_v0.1.8.md +88 -0
- package/docs/RELEASE_NOTES_v0.1.9.en.md +127 -0
- package/docs/RELEASE_NOTES_v0.1.9.md +127 -0
- package/docs/RELEASE_NOTES_v0.2.0.en.md +95 -0
- package/docs/RELEASE_NOTES_v0.2.0.md +96 -0
- package/docs/RELEASE_NOTES_v0.3.0.en.md +77 -0
- package/docs/RELEASE_NOTES_v0.3.0.md +77 -0
- package/docs/SDK.en.md +177 -0
- package/docs/STREAMING.en.md +78 -0
- package/docs/STREAMING.md +109 -0
- package/docs/TOOLS.en.md +205 -0
- package/docs/TOOLS_DESIGN.en.md +142 -0
- package/docs/TOOLS_DESIGN.md +466 -0
- package/docs/TOOLS_MODEL.en.md +56 -0
- package/docs/TOOLS_MODEL.md +903 -0
- package/docs/WIDGET_RENDERERS.en.md +133 -0
- package/docs/WIDGET_RENDERERS.md +139 -0
- package/docs/examples/bailing-tool-verify.mjs +94 -0
- package/docs/examples/bailing-tool-verify.php +154 -0
- package/docs/examples/bailing-tool-verify.py +107 -0
- package/docs/examples/custom-streaming-chat-client.mjs +108 -0
- package/docs/examples/widget-chart-renderer-adapter.mjs +44 -0
- package/docs/integrations/bailian/README.en.md +181 -0
- package/docs/integrations/bailian/README.md +165 -0
- package/docs/integrations/bailian/bailian-mcp-config.json +17 -0
- package/docs/integrations/bailian/verify_recipe.py +97 -0
- package/docs/integrations/deepseek/README.en.md +225 -0
- package/docs/integrations/deepseek/README.md +225 -0
- package/docs/integrations/deepseek/verify_e2e.py +131 -0
- package/docs/integrations/dify/README.en.md +131 -0
- package/docs/integrations/dify/README.md +131 -0
- package/docs/integrations/dify/bailinghub-control-plane.openapi.json +129 -0
- package/docs/integrations/dify/verify_contract.py +88 -0
- package/docs/integrations/dify/verify_e2e.py +117 -0
- package/docs/integrations/jeecgboot/README.en.md +193 -0
- package/docs/integrations/jeecgboot/README.md +161 -0
- package/docs/integrations/jeecgboot/adapter-contract.v1.json +94 -0
- package/docs/integrations/jeecgboot/jeecgboot-user-adapter.openapi.json +183 -0
- package/docs/integrations/jeecgboot/verify_recipe.mjs +97 -0
- package/docs/integrations/ruoyi-vue-pro/README.en.md +91 -0
- package/docs/integrations/ruoyi-vue-pro/README.md +155 -0
- package/docs/integrations/ruoyi-vue-pro/adapter-contract.v1.json +71 -0
- package/docs/integrations/ruoyi-vue-pro/ruoyi-vue-pro-trade-adapter.openapi.json +148 -0
- package/docs/integrations/ruoyi-vue-pro/verify_recipe.mjs +71 -0
- package/docs/user-guide/README.en.md +39 -0
- package/docs/user-guide/README.md +40 -0
- package/docs/user-guide/concepts.en.md +69 -0
- package/docs/user-guide/concepts.md +225 -0
- package/docs/user-guide/console-map.en.md +58 -0
- package/docs/user-guide/console-map.md +473 -0
- package/docs/user-guide/overview.en.md +61 -0
- package/docs/user-guide/overview.md +156 -0
- package/docs/user-guide/scenarios.en.md +70 -0
- package/docs/user-guide/scenarios.md +398 -0
- package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +134 -0
- package/docs//347/254/254/344/270/211/346/226/271/345/257/271/346/216/245/346/214/207/345/215/227.md +625 -0
- package/package.json +119 -0
- package/schemas/agent-capability-contract.schema.json +104 -0
- package/schemas/api/approval-decision.schema.json +28 -0
- package/schemas/api/approval-request.schema.json +31 -0
- package/schemas/api/delivery-callback.schema.json +28 -0
- package/schemas/api/job-response.schema.json +6 -0
- package/schemas/api/kb-doc-upsert.schema.json +21 -0
- package/schemas/api/run-request.schema.json +6 -0
- package/schemas/api/run-response.schema.json +6 -0
- package/schemas/api/tool-spec.schema.json +38 -0
- package/schemas/config/alert-rule.schema.json +22 -0
- package/schemas/config/channel.schema.json +91 -0
- package/schemas/config/chat-entry.schema.json +47 -0
- package/schemas/config/client.schema.json +56 -0
- package/schemas/config/common.schema.json +215 -0
- package/schemas/config/credential.schema.json +48 -0
- package/schemas/config/executor-token.schema.json +20 -0
- package/schemas/config/page-context.schema.json +21 -0
- package/schemas/config/route.schema.json +152 -0
- package/schemas/config/storage-bucket.schema.json +31 -0
- package/schemas/config/target.schema.json +17 -0
- package/schemas/config/tool-provider.schema.json +60 -0
- package/schemas/tool-definition.schema.json +188 -0
- package/scripts/check-client-api-ecosystem.mjs +69 -0
- package/scripts/check-doc-links.mjs +136 -0
- package/scripts/check-image-tags.sh +43 -0
- package/scripts/check-package-artifact.mjs +185 -0
- package/scripts/check-release-consistency.mjs +199 -0
- package/scripts/check-release-consistency.test.mjs +63 -0
- package/scripts/client-api-contract-test.ts +127 -0
- package/scripts/create-admin.ts +27 -0
- package/scripts/demo-e2e.ts +133 -0
- package/scripts/docker-entrypoint.sh +33 -0
- package/scripts/doctor.ts +107 -0
- package/scripts/e2e-console.mjs +214 -0
- package/scripts/export-oss.mjs +204 -0
- package/scripts/generate-readme-assets.mjs +181 -0
- package/scripts/generate-third-party-notices.mjs +93 -0
- package/scripts/image-release-policy.mjs +75 -0
- package/scripts/image-release-policy.test.mjs +58 -0
- package/scripts/init-db.ts +21 -0
- package/scripts/install.sh +461 -0
- package/scripts/oss-boundary-check.mjs +183 -0
- package/scripts/publish-images.sh +63 -0
- package/scripts/publish-mysql-image.sh +41 -0
- package/scripts/release-audit.mjs +348 -0
- package/scripts/sdk-contract-test.ts +62 -0
- package/scripts/sdk-p1-check.mjs +58 -0
- package/scripts/sdk-runtime-test.mjs +106 -0
- package/scripts/security-scan.mjs +110 -0
- package/scripts/seed-demo.ts +116 -0
- package/scripts/selftest.ts +226 -0
- package/scripts/smoke.ts +31 -0
- package/scripts/validate-examples.mjs +93 -0
- package/scripts/verify-bootstrap-admin-restart.ts +66 -0
- package/scripts/verify-github-repo.mjs +195 -0
- package/scripts/verify-oss-export.mjs +192 -0
- package/scripts/verify-routing.ts +29 -0
- package/scripts/widget-renderer-test.mjs +206 -0
- package/scripts/write-build-info.mjs +29 -0
- package/sdk/dotnet/Bailing.Connect/Bailing.Connect.csproj +12 -0
- package/sdk/dotnet/Bailing.Connect/BailingConnect.cs +260 -0
- package/sdk/dotnet/README.md +32 -0
- package/sdk/dotnet/examples/BuildSpec/BuildSpec.csproj +11 -0
- package/sdk/dotnet/examples/BuildSpec/Program.cs +36 -0
- package/sdk/go/README.md +33 -0
- package/sdk/go/bailingconnect/connect.go +367 -0
- package/sdk/go/examples/build-spec/main.go +39 -0
- package/sdk/go/go.mod +3 -0
- package/sdk/java/README.md +43 -0
- package/sdk/java/examples/BuildSpec.java +31 -0
- package/sdk/java/src/main/java/com/bailing/connect/BailingConnect.java +376 -0
- package/sdk/node/README.md +107 -0
- package/sdk/node/examples/build-spec.mjs +84 -0
- package/sdk/node/package.json +22 -0
- package/sdk/node/src/index.mjs +250 -0
- package/sdk/php/README.md +204 -0
- package/sdk/php/composer.json +18 -0
- package/sdk/php/examples/DemoStaffController.php +108 -0
- package/sdk/php/examples/build-spec.php +27 -0
- package/sdk/php/examples/thinkphp-integration.php +81 -0
- package/sdk/php/src/Attributes/AiParam.php +40 -0
- package/sdk/php/src/Attributes/AiTool.php +75 -0
- package/sdk/php/src/HubClient.php +122 -0
- package/sdk/php/src/SpecBuilder.php +328 -0
- package/sdk/php/src/SpecServer.php +209 -0
- package/sdk/php/src/Ticket.php +37 -0
- package/sdk/php/src/Verify.php +178 -0
- package/sdk/php7/README.md +191 -0
- package/sdk/php7/composer.json +18 -0
- package/sdk/php7/examples/build-spec.php +68 -0
- package/sdk/php7/examples/well-known.php +33 -0
- package/sdk/php7/src/HubClient.php +111 -0
- package/sdk/php7/src/SpecServer.php +203 -0
- package/sdk/php7/src/Ticket.php +33 -0
- package/sdk/php7/src/ToolDef.php +169 -0
- package/sdk/php7/src/ToolSpec.php +334 -0
- package/sdk/php7/src/Verify.php +165 -0
- package/sdk/python/README.md +107 -0
- package/sdk/python/bailing_connect/__init__.py +307 -0
- package/sdk/python/examples/build_spec.py +90 -0
- package/sdk/python/pyproject.toml +24 -0
- package/sql/001_init_state.sql +66 -0
- package/sql/002_routes.sql +44 -0
- package/sql/003_executor.sql +15 -0
- package/sql/004_clients.sql +22 -0
- package/sql/005_admins.sql +25 -0
- package/sql/006_ledger.sql +57 -0
- package/sql/007_delivery.sql +8 -0
- package/sql/008_kb.sql +66 -0
- package/sql/009_rbac.sql +5 -0
- package/sql/010_targets.sql +28 -0
- package/sql/011_observability.sql +11 -0
- package/sql/012_generic.sql +5 -0
- package/sql/013_tools.sql +24 -0
- package/sql/014_approvals.sql +27 -0
- package/sql/015_chat.sql +21 -0
- package/sql/016_chat_feedback.sql +19 -0
- package/sql/017_provider_autorefresh.sql +6 -0
- package/sql/018_kb_ingest.sql +11 -0
- package/sql/019_kb_datasources.sql +32 -0
- package/sql/022_storage_buckets.sql +25 -0
- package/sql/024_channels.sql +15 -0
- package/sql/025_chat_appearance.sql +7 -0
- package/sql/026_thread_memory.sql +10 -0
- package/sql/027_page_contexts.sql +23 -0
- package/sql/028_executor_capabilities.sql +4 -0
- package/sql/029_executor_tokens.sql +13 -0
- package/sql/030_route_permission.sql +5 -0
- package/sql/031_tool_embeddings.sql +20 -0
- package/sql/032_tool_provider_embed.sql +7 -0
- package/sql/033_alert_rules.sql +21 -0
- package/sql/034_client_allowed_channels.sql +6 -0
- package/sql/035_tool_idempotency.sql +15 -0
- package/sql/036_delivery_dlq.sql +15 -0
- package/sql/038_audit_trace_shape.sql +15 -0
- package/sql/039_runtime_locks.sql +9 -0
- package/sql/040_budget_policy.sql +3 -0
- package/sql/041_approval_intent.sql +14 -0
- package/sql/042_approval_decision_contract.sql +11 -0
- package/sql/043_rate_limits.sql +7 -0
- package/sql/044_job_run_after.sql +3 -0
- package/sql/045_job_claim_lease.sql +7 -0
- package/sql/046_tool_authz_probe.sql +5 -0
- package/sql/047_route_audience.sql +4 -0
- package/sql/048_llm_target.sql +17 -0
- package/sql/049_llm_input_shape.sql +11 -0
- package/sql/050_operational_metrics_indexes.sql +8 -0
- package/sql/051_instance_branding.sql +17 -0
- package/sql/052_tool_execution_journal.sql +19 -0
- package/sql/053_tool_spec_access_policy.sql +9 -0
- package/sql/README.en.md +41 -0
- package/sql/README.md +40 -0
- package/src/adapters/channels/wecom-api.test.ts +77 -0
- package/src/adapters/channels/wecom-api.ts +224 -0
- package/src/adapters/channels/wecom-crypto.test.ts +85 -0
- package/src/adapters/channels/wecom-crypto.ts +77 -0
- package/src/adapters/executors/claudecode.ts +39 -0
- package/src/adapters/executors/profiles.ts +86 -0
- package/src/adapters/executors/report.ts +35 -0
- package/src/adapters/executors/runner.ts +114 -0
- package/src/adapters/executors/wecomnotify.ts +63 -0
- package/src/adapters/llm/file.test.ts +81 -0
- package/src/adapters/llm/file.ts +250 -0
- package/src/adapters/llm/openai-chat-stream.test.ts +74 -0
- package/src/adapters/llm/openai-chat-stream.ts +154 -0
- package/src/adapters/llm/perception.ts +159 -0
- package/src/adapters/llm/speech.test.ts +75 -0
- package/src/adapters/llm/speech.ts +146 -0
- package/src/adapters/storage/object-storage.test.ts +38 -0
- package/src/adapters/storage/object-storage.ts +140 -0
- package/src/adapters/targets/demo-agent.ts +88 -0
- package/src/adapters/targets/llm.test.ts +733 -0
- package/src/adapters/targets/llm.ts +862 -0
- package/src/app/admin-bootstrap.test.ts +112 -0
- package/src/app/admin-bootstrap.ts +48 -0
- package/src/app/auth-default.ts +26 -0
- package/src/app/auth.test.ts +57 -0
- package/src/app/auth.ts +207 -0
- package/src/app/builtin-tools-default.ts +17 -0
- package/src/app/builtin-tools.test.ts +202 -0
- package/src/app/builtin-tools.ts +380 -0
- package/src/app/channels-default.ts +8 -0
- package/src/app/channels.ts +141 -0
- package/src/app/delivery-default.ts +14 -0
- package/src/app/delivery.test.ts +46 -0
- package/src/app/delivery.ts +215 -0
- package/src/app/engine-default.ts +54 -0
- package/src/app/engine.ts +427 -0
- package/src/app/http-mount.test.ts +27 -0
- package/src/app/http-server.test.ts +114 -0
- package/src/app/http-server.ts +127 -0
- package/src/app/http.test.ts +27 -0
- package/src/app/http.ts +118 -0
- package/src/app/kernel.test.ts +191 -0
- package/src/app/kernel.ts +544 -0
- package/src/app/monitor-default.ts +9 -0
- package/src/app/monitor.ts +46 -0
- package/src/app/operational-metrics.test.ts +73 -0
- package/src/app/operational-metrics.ts +124 -0
- package/src/app/oss-edition.test.ts +71 -0
- package/src/app/oss-edition.ts +108 -0
- package/src/app/outbound-default.ts +57 -0
- package/src/app/outbound.ts +133 -0
- package/src/app/readiness.test.ts +37 -0
- package/src/app/readiness.ts +39 -0
- package/src/app/runtime-composition.test.ts +51 -0
- package/src/app/runtime-composition.ts +73 -0
- package/src/app/runtime-context-default.ts +30 -0
- package/src/app/runtime-context.test.ts +60 -0
- package/src/app/runtime-context.ts +79 -0
- package/src/app/runtime-lifecycle-default.ts +48 -0
- package/src/app/runtime-lifecycle.test.ts +322 -0
- package/src/app/runtime-lifecycle.ts +440 -0
- package/src/app/runtime.ts +36 -0
- package/src/app/tool-approvals-default.ts +16 -0
- package/src/app/tool-approvals.ts +214 -0
- package/src/app/tool-assembly-default.ts +11 -0
- package/src/app/tool-assembly.test.ts +112 -0
- package/src/app/tool-assembly.ts +83 -0
- package/src/app/tool-context-default.ts +7 -0
- package/src/app/tool-context.test.ts +82 -0
- package/src/app/tool-context.ts +109 -0
- package/src/app/tool-debug.test.ts +111 -0
- package/src/app/tool-debug.ts +152 -0
- package/src/app/tool-proxy-default.ts +35 -0
- package/src/app/tool-proxy.ts +173 -0
- package/src/app/tool-specs-default.ts +33 -0
- package/src/app/tool-specs.test.ts +322 -0
- package/src/app/tool-specs.ts +555 -0
- package/src/app/tools-runtime-default.ts +14 -0
- package/src/app/tools-runtime.ts +23 -0
- package/src/architecture-boundary.test.ts +119 -0
- package/src/core/config/config-codec.test.ts +105 -0
- package/src/core/config/config-codec.ts +231 -0
- package/src/core/config/config-diagnostics.test.ts +285 -0
- package/src/core/config/config-diagnostics.ts +436 -0
- package/src/core/config/config-models.test.ts +584 -0
- package/src/core/config/config-models.ts +392 -0
- package/src/core/config/config-schema.test.ts +153 -0
- package/src/core/config/config.test.ts +314 -0
- package/src/core/config/config.ts +324 -0
- package/src/core/config/route-config.test.ts +232 -0
- package/src/core/config/route-config.ts +246 -0
- package/src/core/config/target-config.test.ts +139 -0
- package/src/core/config/target-config.ts +219 -0
- package/src/core/config/tools-config.test.ts +124 -0
- package/src/core/config/tools-config.ts +126 -0
- package/src/core/contracts/approval-decision.test.ts +67 -0
- package/src/core/contracts/approval-decision.ts +93 -0
- package/src/core/contracts/openapi-tools.ts +201 -0
- package/src/core/contracts/tool-annotations.ts +121 -0
- package/src/core/contracts/tool-definition.test.ts +147 -0
- package/src/core/contracts/tool-definition.ts +304 -0
- package/src/core/contracts/tools-idempotency.test.ts +435 -0
- package/src/core/contracts/tools.test.ts +487 -0
- package/src/core/contracts/tools.ts +831 -0
- package/src/core/contracts/types.ts +408 -0
- package/src/core/edition/capabilities.ts +6 -0
- package/src/core/edition/context.test.ts +20 -0
- package/src/core/edition/context.ts +78 -0
- package/src/core/edition/index.ts +4 -0
- package/src/core/edition/scope-resolver.ts +24 -0
- package/src/core/edition/store-factory.ts +6 -0
- package/src/core/observability/openmetrics.test.ts +57 -0
- package/src/core/observability/openmetrics.ts +103 -0
- package/src/core/platform/content.test.ts +46 -0
- package/src/core/platform/content.ts +90 -0
- package/src/core/platform/fence.test.ts +31 -0
- package/src/core/platform/fence.ts +11 -0
- package/src/core/platform/instance-branding.test.ts +65 -0
- package/src/core/platform/instance-branding.ts +202 -0
- package/src/core/platform/metrics-token.test.ts +31 -0
- package/src/core/platform/metrics-token.ts +42 -0
- package/src/core/platform/pagecontext.ts +0 -0
- package/src/core/platform/password.test.ts +13 -0
- package/src/core/platform/password.ts +38 -0
- package/src/core/platform/queue.test.ts +59 -0
- package/src/core/platform/queue.ts +75 -0
- package/src/core/platform/serial.test.ts +73 -0
- package/src/core/platform/serial.ts +64 -0
- package/src/core/platform/server-token.test.ts +46 -0
- package/src/core/platform/server-token.ts +60 -0
- package/src/core/platform/signing.test.ts +24 -0
- package/src/core/platform/signing.ts +22 -0
- package/src/core/platform/time.ts +73 -0
- package/src/core/platform/version.test.ts +19 -0
- package/src/core/platform/version.ts +90 -0
- package/src/core/runtime/budget-runtime.test.ts +93 -0
- package/src/core/runtime/budget-runtime.ts +110 -0
- package/src/core/runtime/context-runtime.test.ts +106 -0
- package/src/core/runtime/context-runtime.ts +95 -0
- package/src/core/runtime/credential-resolver.test.ts +129 -0
- package/src/core/runtime/credential-resolver.ts +93 -0
- package/src/core/runtime/credential-verify.test.ts +76 -0
- package/src/core/runtime/credential-verify.ts +161 -0
- package/src/core/runtime/debug-report.test.ts +20 -0
- package/src/core/runtime/debug-report.ts +100 -0
- package/src/core/runtime/execution-runtime.test.ts +350 -0
- package/src/core/runtime/execution-runtime.ts +197 -0
- package/src/core/runtime/finish-runtime.test.ts +168 -0
- package/src/core/runtime/finish-runtime.ts +83 -0
- package/src/core/runtime/identity-runtime.test.ts +38 -0
- package/src/core/runtime/identity-runtime.ts +104 -0
- package/src/core/runtime/inhub-runtime.test.ts +297 -0
- package/src/core/runtime/inhub-runtime.ts +198 -0
- package/src/core/runtime/job-stream.test.ts +55 -0
- package/src/core/runtime/job-stream.ts +187 -0
- package/src/core/runtime/knowledge-runtime.test.ts +120 -0
- package/src/core/runtime/knowledge-runtime.ts +98 -0
- package/src/core/runtime/launch-runtime.test.ts +187 -0
- package/src/core/runtime/launch-runtime.ts +182 -0
- package/src/core/runtime/memory-runtime.test.ts +85 -0
- package/src/core/runtime/memory-runtime.ts +32 -0
- package/src/core/runtime/memory.ts +141 -0
- package/src/core/runtime/redaction-runtime.test.ts +35 -0
- package/src/core/runtime/redaction-runtime.ts +60 -0
- package/src/core/runtime/routing-runtime.test.ts +89 -0
- package/src/core/runtime/routing-runtime.ts +146 -0
- package/src/core/runtime/smoke-runtime.test.ts +65 -0
- package/src/core/runtime/smoke-runtime.ts +237 -0
- package/src/core/runtime/summary-runtime.test.ts +234 -0
- package/src/core/runtime/summary-runtime.ts +153 -0
- package/src/core/runtime/trace-runtime.test.ts +234 -0
- package/src/core/runtime/trace-runtime.ts +330 -0
- package/src/core/state/audit-observability.test.ts +51 -0
- package/src/core/state/audit-observability.ts +74 -0
- package/src/core/state/state-codec.ts +44 -0
- package/src/core/state/state-contracts.ts +59 -0
- package/src/core/targets/adapter.ts +69 -0
- package/src/core/targets/registry.test.ts +65 -0
- package/src/core/targets/registry.ts +153 -0
- package/src/core/targets/resolve.ts +21 -0
- package/src/executor.ts +201 -0
- package/src/extension-api.test.ts +84 -0
- package/src/extension-api.ts +194 -0
- package/src/infrastructure/config/config-admin-repository.test.ts +193 -0
- package/src/infrastructure/config/config-admin-repository.ts +175 -0
- package/src/infrastructure/config/config-alert-rule-repository.ts +38 -0
- package/src/infrastructure/config/config-approval-ledger.ts +74 -0
- package/src/infrastructure/config/config-channel-repository.ts +31 -0
- package/src/infrastructure/config/config-chat-repository.ts +83 -0
- package/src/infrastructure/config/config-client-repository.ts +46 -0
- package/src/infrastructure/config/config-conversation-ledger.ts +222 -0
- package/src/infrastructure/config/config-credential-repository.test.ts +32 -0
- package/src/infrastructure/config/config-credential-repository.ts +47 -0
- package/src/infrastructure/config/config-delivery-dlq-ledger.ts +49 -0
- package/src/infrastructure/config/config-executor-ledger.ts +30 -0
- package/src/infrastructure/config/config-executor-token-repository.ts +44 -0
- package/src/infrastructure/config/config-instance-branding-repository.ts +75 -0
- package/src/infrastructure/config/config-knowledge-repository.ts +249 -0
- package/src/infrastructure/config/config-observability-ledger.ts +262 -0
- package/src/infrastructure/config/config-project-repository.ts +30 -0
- package/src/infrastructure/config/config-rate-limit-ledger.ts +56 -0
- package/src/infrastructure/config/config-route-repository.ts +41 -0
- package/src/infrastructure/config/config-storage-bucket-repository.ts +43 -0
- package/src/infrastructure/config/config-target-repository.ts +25 -0
- package/src/infrastructure/config/config-tool-call-ledger.ts +142 -0
- package/src/infrastructure/config/config-tool-embedding-repository.test.ts +124 -0
- package/src/infrastructure/config/config-tool-embedding-repository.ts +78 -0
- package/src/infrastructure/config/config-tool-provider-repository.test.ts +71 -0
- package/src/infrastructure/config/config-tool-provider-repository.ts +50 -0
- package/src/infrastructure/config/configstore.ts +130 -0
- package/src/infrastructure/config/local-instance-branding-provider.test.ts +94 -0
- package/src/infrastructure/config/local-instance-branding-provider.ts +79 -0
- package/src/infrastructure/mysql/pool-owner.test.ts +36 -0
- package/src/infrastructure/mysql/pool-owner.ts +56 -0
- package/src/infrastructure/schema/core-schema-migrator.test.ts +340 -0
- package/src/infrastructure/schema/core-schema-migrator.ts +461 -0
- package/src/infrastructure/schema/migration-files.test.ts +18 -0
- package/src/infrastructure/schema/migration-files.ts +27 -0
- package/src/infrastructure/schema/retired-migrations.ts +35 -0
- package/src/infrastructure/state/operational-metrics-storage.test.ts +107 -0
- package/src/infrastructure/state/state-jsonl.ts +268 -0
- package/src/infrastructure/state/state-mysql-update-plan.test.ts +54 -0
- package/src/infrastructure/state/state-mysql-update-plan.ts +63 -0
- package/src/infrastructure/state/state-mysql.ts +359 -0
- package/src/infrastructure/state/state.test.ts +319 -0
- package/src/infrastructure/state/state.ts +11 -0
- package/src/kernel-api/v1/artifact.test.ts +46 -0
- package/src/kernel-api/v1/artifact.ts +71 -0
- package/src/kernel-api/v1/contracts.ts +168 -0
- package/src/kernel-api/v1/execution-gate.test.ts +25 -0
- package/src/kernel-api/v1/execution-gate.ts +18 -0
- package/src/kernel-api/v1/index.ts +51 -0
- package/src/openclaw-stdio.test.ts +60 -0
- package/src/routes/admin-access-default.ts +20 -0
- package/src/routes/admin-access.ts +94 -0
- package/src/routes/admin-branding.test.ts +116 -0
- package/src/routes/admin-branding.ts +48 -0
- package/src/routes/admin-chat-default.ts +12 -0
- package/src/routes/admin-chat.ts +84 -0
- package/src/routes/admin-default.ts +35 -0
- package/src/routes/admin-dispatch-config-default.ts +13 -0
- package/src/routes/admin-dispatch-config.ts +121 -0
- package/src/routes/admin-format.ts +12 -0
- package/src/routes/admin-host.test.ts +56 -0
- package/src/routes/admin-infra-default.ts +12 -0
- package/src/routes/admin-infra.ts +142 -0
- package/src/routes/admin-kb-default.ts +13 -0
- package/src/routes/admin-kb.ts +160 -0
- package/src/routes/admin-runtime-default.ts +31 -0
- package/src/routes/admin-runtime.ts +444 -0
- package/src/routes/admin-tool-providers-default.ts +20 -0
- package/src/routes/admin-tool-providers.test.ts +114 -0
- package/src/routes/admin-tool-providers.ts +186 -0
- package/src/routes/admin.ts +246 -0
- package/src/routes/approvals-default.ts +32 -0
- package/src/routes/approvals.ts +120 -0
- package/src/routes/chat-default.ts +61 -0
- package/src/routes/chat-mount.test.ts +58 -0
- package/src/routes/chat.test.ts +222 -0
- package/src/routes/chat.ts +478 -0
- package/src/routes/critical-routes.test.ts +292 -0
- package/src/routes/executor-default.ts +45 -0
- package/src/routes/executor.ts +226 -0
- package/src/routes/kb-default.ts +23 -0
- package/src/routes/kb.ts +92 -0
- package/src/routes/private-default.ts +38 -0
- package/src/routes/private-host-auth.test.ts +84 -0
- package/src/routes/private.ts +210 -0
- package/src/routes/public-default.ts +46 -0
- package/src/routes/public.test.ts +504 -0
- package/src/routes/public.ts +313 -0
- package/src/routes/run-default.ts +25 -0
- package/src/routes/run.ts +188 -0
- package/src/routes/send-default.ts +24 -0
- package/src/routes/send.ts +143 -0
- package/src/routes/wecom-default.ts +27 -0
- package/src/routes/wecom.ts +307 -0
- package/src/server.ts +13 -0
- package/src/services/embedding.test.ts +185 -0
- package/src/services/embedding.ts +138 -0
- package/src/services/kb-repository.ts +79 -0
- package/src/services/kb.ts +328 -0
- package/src/services/kbsync.ts +166 -0
- package/src/services/tool-index-repository.ts +50 -0
- package/src/services/tools-index.test.ts +756 -0
- package/src/services/tools-index.ts +427 -0
- package/tsconfig.json +17 -0
- package/web/connect/bailing-connect-php.tgz +0 -0
- package/web/connect/bailing-connect-php7.tgz +0 -0
- package/web/connect/executor.mjs +152 -0
- package/web/connect/openclaw-stdio.mjs +145 -0
- package/web/connect/skills/connect-bailinghub-executor/SKILL.md +97 -0
- package/web/connect/skills/connect-bailinghub-executor/agents/openai.yaml +4 -0
- package/web/connect/skills/connect-bailinghub-executor/references/direct-protocol.md +99 -0
- package/web/connect/skills/connect-bailinghub-executor/references/openclaw.md +39 -0
- package/web/console/assets/Accounts-B4ePH5jp.css +1 -0
- package/web/console/assets/Accounts-Dwzm4D_V.js +3 -0
- package/web/console/assets/Approvals-BxhuI0ku.js +1 -0
- package/web/console/assets/Approvals-DlTSHl_7.css +1 -0
- package/web/console/assets/Audit-CSu6_3oD.css +1 -0
- package/web/console/assets/Audit-dFAbGynl.js +1 -0
- package/web/console/assets/BrandLockup-BtZyvkM5.js +1 -0
- package/web/console/assets/BrandLockup-DKYBYzKU.css +1 -0
- package/web/console/assets/Channels-CCn0L1jg.css +1 -0
- package/web/console/assets/Channels-Dqg4-_yr.js +105 -0
- package/web/console/assets/ChatEntries-BweMx_CU.css +1 -0
- package/web/console/assets/ChatEntries-CEGZ3NnJ.js +7 -0
- package/web/console/assets/Clients-C0QD1x7g.js +3 -0
- package/web/console/assets/Clients-DcTYN-Js.css +1 -0
- package/web/console/assets/Cost-BAJqLhpK.js +1 -0
- package/web/console/assets/Cost-CjT39DSZ.css +1 -0
- package/web/console/assets/Credentials-D_GDRgWi.js +1 -0
- package/web/console/assets/Credentials-ioLP0qYN.css +1 -0
- package/web/console/assets/Diagnostics-BWYnDxRj.js +1 -0
- package/web/console/assets/Diagnostics-Ya05PTDp.css +1 -0
- package/web/console/assets/Executors-CjhEM54c.css +1 -0
- package/web/console/assets/Executors-Cmryk4Vk.js +1 -0
- package/web/console/assets/HelpTip-CA6Bm7Nx.css +1 -0
- package/web/console/assets/HelpTip-CT07o3kB.js +1 -0
- package/web/console/assets/Kb-BSXQE0Fa.js +5 -0
- package/web/console/assets/Kb-CzIzd9xr.css +1 -0
- package/web/console/assets/Login-BnBPqC8Z.js +1 -0
- package/web/console/assets/Login-xtPwDB5_.css +1 -0
- package/web/console/assets/Projects-Bm8AjsNx.css +1 -0
- package/web/console/assets/Projects-CNHx4L_7.js +1 -0
- package/web/console/assets/Routes-DWGQN5Pv.css +1 -0
- package/web/console/assets/Routes-u5cEAEXQ.js +124 -0
- package/web/console/assets/Runs-BeFUR77_.js +3 -0
- package/web/console/assets/Runs-CUtSsPW-.css +1 -0
- package/web/console/assets/Setup-BjZfrmfN.js +1 -0
- package/web/console/assets/Setup-QjlHZKdB.css +1 -0
- package/web/console/assets/Shell-CbGNTN91.css +1 -0
- package/web/console/assets/Shell-EJuYf3OO.js +1 -0
- package/web/console/assets/StorageBuckets-DMXRJxUA.js +1 -0
- package/web/console/assets/StorageBuckets-GnXnVvF0.css +1 -0
- package/web/console/assets/SystemSettings-B72F-loY.js +1 -0
- package/web/console/assets/SystemSettings-BjiHyrXO.css +1 -0
- package/web/console/assets/SystemStatus-I11I67rw.css +1 -0
- package/web/console/assets/SystemStatus-hOj_TPYE.js +1 -0
- package/web/console/assets/Targets-DTb5tn6z.css +1 -0
- package/web/console/assets/Targets-UVVf7twC.js +1 -0
- package/web/console/assets/Tools-A20oaMaQ.css +1 -0
- package/web/console/assets/Tools-ihkr9R9x.js +2 -0
- package/web/console/assets/_plugin-vue_export-helper-DlAUqK2U.js +1 -0
- package/web/console/assets/docs-DPUOCa7R.js +1 -0
- package/web/console/assets/index-DZEQL_yy.js +1 -0
- package/web/console/assets/index-DxvruykG.js +2 -0
- package/web/console/assets/index-Fi9gkGxV.css +1 -0
- package/web/console/assets/llm-catalog-HwRIrS94.js +1 -0
- package/web/console/assets/request-BisL2T9B.js +1 -0
- package/web/console/assets/schema-CzpUpoLk.js +1 -0
- package/web/console/assets/util-SiQC2MJh.js +1 -0
- package/web/console/assets/vendor-element-D7WRzHhy.js +37 -0
- package/web/console/assets/vendor-mammoth-DvgsHdlx.js +231 -0
- package/web/console/assets/vendor-turndown-kLzRgxYD.js +61 -0
- package/web/console/assets/vendor-vue-B2uhHUfE.js +29 -0
- package/web/console/index.html +16 -0
- package/web/widget/widget.js +1490 -0
- package/web-admin/index.html +13 -0
- package/web-admin/package-lock.json +1854 -0
- package/web-admin/package.json +25 -0
- package/web-admin/src/App.vue +9 -0
- package/web-admin/src/branding.ts +90 -0
- package/web-admin/src/components/BrandLockup.vue +40 -0
- package/web-admin/src/components/HelpTip.vue +51 -0
- package/web-admin/src/components/RichText.vue +35 -0
- package/web-admin/src/docs.ts +16 -0
- package/web-admin/src/layout/Shell.vue +356 -0
- package/web-admin/src/llm-catalog.ts +129 -0
- package/web-admin/src/main.ts +116 -0
- package/web-admin/src/pages/Accounts.vue +162 -0
- package/web-admin/src/pages/Approvals.vue +179 -0
- package/web-admin/src/pages/Audit.vue +110 -0
- package/web-admin/src/pages/Channels.vue +738 -0
- package/web-admin/src/pages/ChatEntries.vue +778 -0
- package/web-admin/src/pages/Clients.vue +353 -0
- package/web-admin/src/pages/Cost.vue +314 -0
- package/web-admin/src/pages/Credentials.vue +418 -0
- package/web-admin/src/pages/Diagnostics.vue +440 -0
- package/web-admin/src/pages/Executors.vue +398 -0
- package/web-admin/src/pages/Kb.vue +698 -0
- package/web-admin/src/pages/Login.vue +314 -0
- package/web-admin/src/pages/Projects.vue +106 -0
- package/web-admin/src/pages/Routes.vue +1661 -0
- package/web-admin/src/pages/Runs.vue +1113 -0
- package/web-admin/src/pages/Setup.vue +354 -0
- package/web-admin/src/pages/StorageBuckets.vue +182 -0
- package/web-admin/src/pages/SystemSettings.vue +281 -0
- package/web-admin/src/pages/SystemStatus.vue +185 -0
- package/web-admin/src/pages/Targets.vue +193 -0
- package/web-admin/src/pages/Tools.vue +1051 -0
- package/web-admin/src/request.ts +18 -0
- package/web-admin/src/router.ts +142 -0
- package/web-admin/src/runtime-path.ts +27 -0
- package/web-admin/src/schema.ts +52 -0
- package/web-admin/src/store.ts +35 -0
- package/web-admin/src/styles/base.css +272 -0
- package/web-admin/src/table-widths.ts +603 -0
- package/web-admin/src/util.ts +16 -0
- package/web-admin/tsconfig.json +15 -0
- package/web-admin/vite.config.ts +35 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal transport lifecycle for a custom BailingHub streaming client.
|
|
3
|
+
*
|
|
4
|
+
* This example intentionally leaves Markdown parsing and chart rendering to the
|
|
5
|
+
* host application. Only advertise renderer types that the host has installed
|
|
6
|
+
* and secured.
|
|
7
|
+
*/
|
|
8
|
+
export async function runBailingChat({
|
|
9
|
+
hub,
|
|
10
|
+
entryKey,
|
|
11
|
+
message,
|
|
12
|
+
visitorId,
|
|
13
|
+
ticket,
|
|
14
|
+
threadId,
|
|
15
|
+
supportedRenderers = [],
|
|
16
|
+
maxWaitMs = 5 * 60 * 1000,
|
|
17
|
+
onProvisional = () => {},
|
|
18
|
+
onReset = () => {},
|
|
19
|
+
onFinal = () => {},
|
|
20
|
+
onIncomplete = () => {},
|
|
21
|
+
onFailure = () => {},
|
|
22
|
+
}) {
|
|
23
|
+
const base = String(hub).replace(/\/+$/, '');
|
|
24
|
+
const renderers = Array.from(new Set(supportedRenderers
|
|
25
|
+
.filter((item) => typeof item === 'string')
|
|
26
|
+
.map((item) => item.trim().toLowerCase())
|
|
27
|
+
.filter((item) => /^[a-z][a-z0-9._+-]{0,63}$/.test(item))))
|
|
28
|
+
.slice(0, 16);
|
|
29
|
+
|
|
30
|
+
const response = await fetch(`${base}/chat/${encodeURIComponent(entryKey)}`, {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
headers: { 'content-type': 'application/json' },
|
|
33
|
+
body: JSON.stringify({
|
|
34
|
+
message,
|
|
35
|
+
visitor_id: visitorId,
|
|
36
|
+
...(renderers.length ? { client_capabilities: { renderers } } : {}),
|
|
37
|
+
...(ticket ? { ticket } : {}),
|
|
38
|
+
...(threadId ? { thread_id: threadId } : {}),
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
const submitted = await response.json();
|
|
42
|
+
if (!response.ok || !submitted.job_id) {
|
|
43
|
+
throw new Error(submitted.error || submitted.reply || `chat submit failed (${response.status})`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return await new Promise((resolve, reject) => {
|
|
47
|
+
let provisional = '';
|
|
48
|
+
let lastSeq = 0;
|
|
49
|
+
let settled = false;
|
|
50
|
+
const events = new EventSource(
|
|
51
|
+
`${base}/chat/${encodeURIComponent(entryKey)}/events/${encodeURIComponent(submitted.job_id)}?max_wait=${maxWaitMs}`,
|
|
52
|
+
);
|
|
53
|
+
const parse = (event) => JSON.parse(event.data);
|
|
54
|
+
const finish = (value) => {
|
|
55
|
+
if (settled) return;
|
|
56
|
+
settled = true;
|
|
57
|
+
clearTimeout(deadline);
|
|
58
|
+
events.close();
|
|
59
|
+
resolve(value);
|
|
60
|
+
};
|
|
61
|
+
const deadline = setTimeout(() => {
|
|
62
|
+
if (settled) return;
|
|
63
|
+
settled = true;
|
|
64
|
+
events.close();
|
|
65
|
+
reject(new Error('chat event stream exceeded the client wait deadline'));
|
|
66
|
+
}, maxWaitMs + 10_000);
|
|
67
|
+
|
|
68
|
+
events.addEventListener('delta', (event) => {
|
|
69
|
+
const data = parse(event);
|
|
70
|
+
const seq = Number(data.seq) || 0;
|
|
71
|
+
if (seq && seq <= lastSeq) return;
|
|
72
|
+
if (seq) lastSeq = seq;
|
|
73
|
+
provisional += typeof data.text === 'string' ? data.text : '';
|
|
74
|
+
onProvisional(provisional, data);
|
|
75
|
+
});
|
|
76
|
+
events.addEventListener('reset', (event) => {
|
|
77
|
+
const data = parse(event);
|
|
78
|
+
provisional = '';
|
|
79
|
+
onReset(data);
|
|
80
|
+
});
|
|
81
|
+
events.addEventListener('done', (event) => {
|
|
82
|
+
const data = parse(event);
|
|
83
|
+
// done.reply replaces provisional output and is the only final truth.
|
|
84
|
+
onFinal(data.reply || '', data);
|
|
85
|
+
finish(data);
|
|
86
|
+
});
|
|
87
|
+
events.addEventListener('failed', (event) => {
|
|
88
|
+
const data = parse(event);
|
|
89
|
+
onFailure(data);
|
|
90
|
+
finish(data);
|
|
91
|
+
});
|
|
92
|
+
events.addEventListener('timeout', (event) => {
|
|
93
|
+
const data = parse(event);
|
|
94
|
+
// The bounded SSE wait ended, but the job may still be running. Query
|
|
95
|
+
// task history/status before deciding whether to reconnect or surface it.
|
|
96
|
+
onIncomplete(data);
|
|
97
|
+
finish(data);
|
|
98
|
+
});
|
|
99
|
+
events.onerror = () => {
|
|
100
|
+
// Native EventSource reconnects automatically and resumes from the
|
|
101
|
+
// server-provided event id. Only fail when the browser marks it closed.
|
|
102
|
+
if (events.readyState !== EventSource.CLOSED || settled) return;
|
|
103
|
+
settled = true;
|
|
104
|
+
clearTimeout(deadline);
|
|
105
|
+
reject(new Error('chat event stream closed before a terminal event'));
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library-neutral adapter for BailingHub's trusted widget renderer registry.
|
|
3
|
+
*
|
|
4
|
+
* `createChart` is supplied by the host application. It can wrap ECharts,
|
|
5
|
+
* GPT-Vis, another chart library, or an internal reporting component.
|
|
6
|
+
*/
|
|
7
|
+
export function registerBailingChartRenderer(createChart) {
|
|
8
|
+
if (typeof createChart !== 'function') {
|
|
9
|
+
throw new TypeError('createChart must be a function');
|
|
10
|
+
}
|
|
11
|
+
if (!window.BailingChat || typeof window.BailingChat.registerRenderer !== 'function') {
|
|
12
|
+
throw new Error('BailingHub widget renderer API is not available');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return window.BailingChat.registerRenderer({
|
|
16
|
+
type: 'bailing-chart',
|
|
17
|
+
version: 1,
|
|
18
|
+
label: 'Business chart',
|
|
19
|
+
contentType: 'application/json',
|
|
20
|
+
maxPayloadBytes: 64 * 1024,
|
|
21
|
+
mount({ container, payload, theme, signal }) {
|
|
22
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
|
|
23
|
+
throw new TypeError('chart payload must be an object');
|
|
24
|
+
}
|
|
25
|
+
if (typeof payload.kind !== 'string' || !Array.isArray(payload.data)) {
|
|
26
|
+
throw new TypeError('chart payload requires kind and data');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const chart = createChart(container, {
|
|
30
|
+
spec: payload,
|
|
31
|
+
accent: theme.accent,
|
|
32
|
+
});
|
|
33
|
+
let disposed = false;
|
|
34
|
+
const destroy = () => {
|
|
35
|
+
if (disposed) return;
|
|
36
|
+
disposed = true;
|
|
37
|
+
if (chart && typeof chart.destroy === 'function') chart.destroy();
|
|
38
|
+
container.replaceChildren();
|
|
39
|
+
};
|
|
40
|
+
signal.addEventListener('abort', destroy, { once: true });
|
|
41
|
+
return destroy;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# Connect Alibaba Cloud Model Studio To BailingHub
|
|
2
|
+
|
|
3
|
+
This recipe lets an Alibaba Cloud Model Studio agent or workflow submit real business
|
|
4
|
+
actions to a self-hosted BailingHub governance control plane through a custom MCP service.
|
|
5
|
+
The model does not receive business credentials or unrestricted access to business APIs.
|
|
6
|
+
|
|
7
|
+
This is a custom MCP recipe installed inside a user's Model Studio workspace. It is not a
|
|
8
|
+
Model Studio Marketplace listing and does not imply Alibaba Cloud certification,
|
|
9
|
+
recommendation, adoption, or partnership.
|
|
10
|
+
|
|
11
|
+
## Architecture And Boundary
|
|
12
|
+
|
|
13
|
+
```text
|
|
14
|
+
Model Studio agent / workflow
|
|
15
|
+
|
|
|
16
|
+
| MCP arguments: request_id, input, job_id
|
|
17
|
+
v
|
|
18
|
+
Model Studio-hosted bailinghub-mcp-server
|
|
19
|
+
|
|
|
20
|
+
| fixed route + route-scoped Client Token
|
|
21
|
+
v
|
|
22
|
+
self-hosted BailingHub
|
|
23
|
+
|
|
|
24
|
+
| allowlists, risk, approval, idempotency, audit, job state
|
|
25
|
+
v
|
|
26
|
+
business system
|
|
27
|
+
|
|
|
28
|
+
+-- resolves the trusted subject and performs final authorization
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`BAILINGHUB_BASE_URL`, `BAILINGHUB_CLIENT_TOKEN`, and `BAILINGHUB_ROUTE` are deployment
|
|
32
|
+
configuration. They are not model-selectable MCP tool arguments. The adapter uses only the
|
|
33
|
+
stable public Client API:
|
|
34
|
+
|
|
35
|
+
- `POST /run`
|
|
36
|
+
- `GET /jobs/{job_id}`
|
|
37
|
+
|
|
38
|
+
It does not call administrator, executor, approval-decision, tool-proxy, or direct
|
|
39
|
+
business-credential APIs.
|
|
40
|
+
|
|
41
|
+
## Prerequisites
|
|
42
|
+
|
|
43
|
+
1. An HTTPS BailingHub deployment reachable from Alibaba Cloud Function Compute.
|
|
44
|
+
2. A dedicated BailingHub route such as `bailian_assistant`.
|
|
45
|
+
3. A BailingHub Client Token restricted to that route.
|
|
46
|
+
4. A no-side-effect route for the first validation.
|
|
47
|
+
|
|
48
|
+
Use separate routes, Client Tokens, and MCP service instances when Model Studio
|
|
49
|
+
applications need different governance boundaries. Never reuse an administrator token,
|
|
50
|
+
executor token, business-system credential, or another ecosystem integration token.
|
|
51
|
+
|
|
52
|
+
## 1. Validate The Public Recipe
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
python3 docs/integrations/bailian/verify_recipe.py
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Expected output:
|
|
59
|
+
|
|
60
|
+
```text
|
|
61
|
+
PASS: Bailian to BailingHub MCP recipe is structurally valid.
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 2. Create A Custom MCP Service
|
|
65
|
+
|
|
66
|
+
Open Model Studio MCP service management and choose **Create MCP service** and **Script
|
|
67
|
+
deployment**. The official script-deployment path supports `npx` for Node.js STDIO MCP
|
|
68
|
+
servers and hosts the process on Function Compute.
|
|
69
|
+
|
|
70
|
+
Copy [`bailian-mcp-config.json`](bailian-mcp-config.json) and replace only:
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"BAILINGHUB_BASE_URL": "https://your-bailinghub.example.com",
|
|
75
|
+
"BAILINGHUB_CLIENT_TOKEN": "your-dedicated-route-scoped-client-token",
|
|
76
|
+
"BAILINGHUB_ROUTE": "bailian_assistant"
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Keep the reproducible launch settings unchanged:
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"type": "stdio",
|
|
85
|
+
"command": "npx",
|
|
86
|
+
"args": ["-y", "bailinghub-mcp-server@0.1.0"]
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Choose Model Studio basic or turbo mode according to latency goals and budget, and select
|
|
91
|
+
a region near the BailingHub deployment. Script deployment may incur Function Compute
|
|
92
|
+
charges. Treat the current console and official documentation as authoritative for
|
|
93
|
+
pricing and runtime modes.
|
|
94
|
+
|
|
95
|
+
The completed configuration contains a Client Token. Never commit it to Git, paste it into
|
|
96
|
+
a public issue, or expose it in screenshots or articles. Rotate it in BailingHub if it
|
|
97
|
+
enters an untrusted environment.
|
|
98
|
+
|
|
99
|
+
## 3. Test The Three MCP Tools
|
|
100
|
+
|
|
101
|
+
After deployment, Model Studio should discover:
|
|
102
|
+
|
|
103
|
+
| Tool | Purpose |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| `submit_governed_job` | Submit through the operator-fixed BailingHub route |
|
|
106
|
+
| `get_governed_job` | Read the current public state of a client-owned job |
|
|
107
|
+
| `wait_for_governed_job` | Wait for at most 60 seconds without resubmitting |
|
|
108
|
+
|
|
109
|
+
Use a no-side-effect first request:
|
|
110
|
+
|
|
111
|
+
```text
|
|
112
|
+
request_id: bailian-e2e-<a new stable identifier>
|
|
113
|
+
input: Return exactly BAILIAN_BAILINGHUB_E2E_OK. Do not call business tools.
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Preserve the real `job_id` returned by `submit_governed_job`, then call:
|
|
117
|
+
|
|
118
|
+
```text
|
|
119
|
+
wait_for_governed_job(job_id=<real job_id>, max_wait_seconds=20)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Never invent a `job_id`. Reuse the original `request_id` and task meaning when retrying the
|
|
123
|
+
same business request. A wait timeout means the job is not terminal yet; it must not cause
|
|
124
|
+
a replacement submission.
|
|
125
|
+
|
|
126
|
+
## 4. Attach It To An Agent Or Workflow
|
|
127
|
+
|
|
128
|
+
Attach the deployed MCP service and give the model this sequence:
|
|
129
|
+
|
|
130
|
+
```text
|
|
131
|
+
When a real business action is required:
|
|
132
|
+
1. Create and preserve one stable request_id for the business request.
|
|
133
|
+
2. Call submit_governed_job without subject credentials, tokens, or approval decisions.
|
|
134
|
+
3. Preserve the returned job_id.
|
|
135
|
+
4. Use wait_for_governed_job for a bounded wait, then get_governed_job if needed.
|
|
136
|
+
5. queued, running, and dispatched are not failures; done, error, and rejected are terminal.
|
|
137
|
+
6. Never treat an MCP result as the business system's final authorization.
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Acceptance Criteria
|
|
141
|
+
|
|
142
|
+
The minimal validation passes only when:
|
|
143
|
+
|
|
144
|
+
- Model Studio discovers and invokes all three MCP tools;
|
|
145
|
+
- submission can reach only the operator-fixed BailingHub route;
|
|
146
|
+
- an identical `request_id` does not create a duplicate job;
|
|
147
|
+
- the same `job_id` reaches a terminal state or remains queryable after a bounded wait;
|
|
148
|
+
- BailingHub preserves the approval and audit state actually produced by the selected
|
|
149
|
+
route; a no-side-effect route may require no approval;
|
|
150
|
+
- Model Studio and the model receive no administrator, executor, or business credential;
|
|
151
|
+
- the business system still resolves the trusted subject and performs final authorization.
|
|
152
|
+
|
|
153
|
+
Report a result through the
|
|
154
|
+
[independent validation issue template](https://github.com/bailinghub/bailinghub/issues/new?template=independent_validation.yml)
|
|
155
|
+
and select the MCP track. Never include tokens, model keys, personal data, or production
|
|
156
|
+
business data.
|
|
157
|
+
|
|
158
|
+
## Current Validation Status
|
|
159
|
+
|
|
160
|
+
- The recipe JSON, pinned package version, and credential boundary are checked by the
|
|
161
|
+
repository verifier.
|
|
162
|
+
- `bailinghub-mcp-server@0.1.0` is an independent open-source adapter and does not modify
|
|
163
|
+
BailingHub Core.
|
|
164
|
+
- On 2026-07-27, the maintainer completed a live no-side-effect E2E in the Beijing region
|
|
165
|
+
using Model Studio custom MCP script deployment and the paid turbo mode. Model Studio
|
|
166
|
+
discovered all three tools, `submit_governed_job` returned `queued`, and
|
|
167
|
+
`wait_for_governed_job` took the same `job_id` to `done` with
|
|
168
|
+
`BAILIAN_BAILINGHUB_E2E_OK`.
|
|
169
|
+
- The corresponding BailingHub dispatch flow recorded the fixed `bailian-e2e` route, the
|
|
170
|
+
`llm` target, and terminal state `done`. No business tools were exposed and no business
|
|
171
|
+
credentials were given to the model or Model Studio.
|
|
172
|
+
- This is maintainer-workspace compatibility evidence. It does not imply Alibaba Cloud
|
|
173
|
+
certification, recommendation, adoption, partnership, or a public Marketplace listing.
|
|
174
|
+
Each deployment should still validate its own isolated route with no-side-effect input.
|
|
175
|
+
|
|
176
|
+
## Official References
|
|
177
|
+
|
|
178
|
+
- [Model Studio custom MCP](https://help.aliyun.com/zh/model-studio/custom-mcp)
|
|
179
|
+
- [Model Studio MCP introduction](https://help.aliyun.com/zh/model-studio/mcp-introduction/)
|
|
180
|
+
- [BailingHub MCP Server](https://github.com/bailinghub/bailinghub-mcp-server)
|
|
181
|
+
- [BailingHub MCP integration](https://www.bailinghub.com/en/integrations#mcp)
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# 阿里云百炼接入 BailingHub
|
|
2
|
+
|
|
3
|
+
本配方让阿里云百炼 Agent 或工作流通过自定义 MCP,把真实业务动作提交到自托管
|
|
4
|
+
BailingHub 治理控制面,而不是让模型直接持有业务凭证或自由调用业务 API。
|
|
5
|
+
|
|
6
|
+
这是一份用户工作空间内的自定义 MCP 接入配方,不是百炼 Marketplace 商品,也不表示
|
|
7
|
+
阿里云对 BailingHub 的认证、推荐、采用或合作。
|
|
8
|
+
|
|
9
|
+
## 架构与边界
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
百炼 Agent / 工作流
|
|
13
|
+
|
|
|
14
|
+
| MCP 工具参数:request_id、input、job_id
|
|
15
|
+
v
|
|
16
|
+
百炼托管的 bailinghub-mcp-server
|
|
17
|
+
|
|
|
18
|
+
| 固定 route + 路由级 Client Token
|
|
19
|
+
v
|
|
20
|
+
自托管 BailingHub
|
|
21
|
+
|
|
|
22
|
+
| 白名单、风险、审批、幂等、审计、任务状态
|
|
23
|
+
v
|
|
24
|
+
业务系统
|
|
25
|
+
|
|
|
26
|
+
+-- 解析可信主体并执行最终授权
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`BAILINGHUB_BASE_URL`、`BAILINGHUB_CLIENT_TOKEN` 和 `BAILINGHUB_ROUTE`
|
|
30
|
+
是部署配置,不是模型可选择的 MCP 工具参数。适配器只使用稳定的公开 Client API:
|
|
31
|
+
|
|
32
|
+
- `POST /run`
|
|
33
|
+
- `GET /jobs/{job_id}`
|
|
34
|
+
|
|
35
|
+
它不会调用管理员、执行器、审批决策、工具代理或业务系统凭据接口。
|
|
36
|
+
|
|
37
|
+
## 前置条件
|
|
38
|
+
|
|
39
|
+
1. 一个可从阿里云函数计算访问的 HTTPS BailingHub 部署。
|
|
40
|
+
2. 一条专用于百炼的 BailingHub 路由,例如 `bailian_assistant`。
|
|
41
|
+
3. 一个只允许访问该路由的 BailingHub Client Token。
|
|
42
|
+
4. 首次验证时使用无副作用路由,不开放真实写操作。
|
|
43
|
+
|
|
44
|
+
不同百炼应用需要不同治理边界时,应使用不同路由、Client Token 和 MCP 服务实例。
|
|
45
|
+
不要复用管理员 token、执行器 token、业务系统凭据或其他生态入口的 Client Token。
|
|
46
|
+
|
|
47
|
+
## 1. 校验公开配方
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
python3 docs/integrations/bailian/verify_recipe.py
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
通过时输出:
|
|
54
|
+
|
|
55
|
+
```text
|
|
56
|
+
PASS: Bailian to BailingHub MCP recipe is structurally valid.
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## 2. 创建百炼自定义 MCP
|
|
60
|
+
|
|
61
|
+
进入百炼 MCP 服务管理,选择“创建 MCP 服务”与“脚本部署”。百炼官方脚本部署支持
|
|
62
|
+
`npx` 启动 Node.js STDIO MCP,并由函数计算托管进程。
|
|
63
|
+
|
|
64
|
+
复制 [`bailian-mcp-config.json`](bailian-mcp-config.json),只替换三个值:
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"BAILINGHUB_BASE_URL": "https://your-bailinghub.example.com",
|
|
69
|
+
"BAILINGHUB_CLIENT_TOKEN": "your-dedicated-route-scoped-client-token",
|
|
70
|
+
"BAILINGHUB_ROUTE": "bailian_assistant"
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
保留以下启动参数不变,以便部署可复现:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"type": "stdio",
|
|
79
|
+
"command": "npx",
|
|
80
|
+
"args": ["-y", "bailinghub-mcp-server@0.1.0"]
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
根据延迟目标和成本预算选择百炼“基本模式”或“极速模式”,并选择靠近 BailingHub
|
|
85
|
+
部署的地域。脚本部署可能产生函数计算费用;费用和运行模式以百炼当前控制台与官方
|
|
86
|
+
文档为准。
|
|
87
|
+
|
|
88
|
+
配置中包含 Client Token。不要把已填写凭据的 JSON 提交到 Git、粘贴到公开 Issue、
|
|
89
|
+
截图或文章中。若凭据进入非受信环境,应立即在 BailingHub 轮换。
|
|
90
|
+
|
|
91
|
+
## 3. 测试三个 MCP 工具
|
|
92
|
+
|
|
93
|
+
部署完成后,百炼应发现:
|
|
94
|
+
|
|
95
|
+
| 工具 | 用途 |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| `submit_governed_job` | 通过运维固定的路由提交一个受治理任务 |
|
|
98
|
+
| `get_governed_job` | 查询该 Client 所属任务的当前公开状态 |
|
|
99
|
+
| `wait_for_governed_job` | 最多等待 60 秒,不重新提交业务动作 |
|
|
100
|
+
|
|
101
|
+
首次测试使用无副作用输入:
|
|
102
|
+
|
|
103
|
+
```text
|
|
104
|
+
request_id: bailian-e2e-<一个新的稳定标识>
|
|
105
|
+
input: Return exactly BAILIAN_BAILINGHUB_E2E_OK. Do not call business tools.
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
保存 `submit_governed_job` 返回的真实 `job_id`,再调用:
|
|
109
|
+
|
|
110
|
+
```text
|
|
111
|
+
wait_for_governed_job(job_id=<真实 job_id>, max_wait_seconds=20)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
不要编造 `job_id`。同一个业务请求需要重试时,复用原始 `request_id` 和相同任务语义;
|
|
115
|
+
等待超时只表示当前未到终态,不应创建替代任务。
|
|
116
|
+
|
|
117
|
+
## 4. 接入百炼 Agent 或工作流
|
|
118
|
+
|
|
119
|
+
把已部署的 MCP 服务添加到 Agent 或工作流,并给模型明确的调用顺序:
|
|
120
|
+
|
|
121
|
+
```text
|
|
122
|
+
需要执行真实业务动作时:
|
|
123
|
+
1. 为同一业务请求生成并保留稳定 request_id。
|
|
124
|
+
2. 调用 submit_governed_job,不要传入主体凭据、token 或审批结论。
|
|
125
|
+
3. 保存返回的 job_id。
|
|
126
|
+
4. 使用 wait_for_governed_job 做有界等待;超时后用 get_governed_job 查询。
|
|
127
|
+
5. queued、running、dispatched 不是失败;done、error、rejected 是终态。
|
|
128
|
+
6. 不得把工具返回当作业务系统最终授权。
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## 验收标准
|
|
132
|
+
|
|
133
|
+
一次最小验证只有同时满足以下条件才算通过:
|
|
134
|
+
|
|
135
|
+
- 百炼发现并调用三个 MCP 工具;
|
|
136
|
+
- 提交请求只能进入运维固定的 BailingHub 路由;
|
|
137
|
+
- 相同 `request_id` 不产生重复任务;
|
|
138
|
+
- 返回的同一 `job_id` 到达终态,或在有界等待后保留可继续查询的状态;
|
|
139
|
+
- BailingHub 保留所选路由实际产生的审批与审计状态;无副作用路由可以不触发审批;
|
|
140
|
+
- 百炼和模型没有获得管理员、执行器或业务系统凭据;
|
|
141
|
+
- 业务系统仍执行最终主体解析和授权。
|
|
142
|
+
|
|
143
|
+
发现问题时可使用
|
|
144
|
+
[独立验证 Issue 模板](https://github.com/bailinghub/bailinghub/issues/new?template=independent_validation.yml)
|
|
145
|
+
并选择 MCP 路径。不要提交 token、模型密钥、个人信息或生产业务数据。
|
|
146
|
+
|
|
147
|
+
## 当前验证状态
|
|
148
|
+
|
|
149
|
+
- 配方 JSON、固定包版本和凭据边界已由仓库校验器验证。
|
|
150
|
+
- `bailinghub-mcp-server@0.1.0` 是独立开源适配器,不修改 BailingHub Core。
|
|
151
|
+
- 2026-07-27,维护者在北京地域使用百炼自定义 MCP 脚本部署与付费极速模式完成了真实
|
|
152
|
+
无副作用 E2E:平台发现全部三个工具,`submit_governed_job` 返回 `queued`,同一
|
|
153
|
+
`job_id` 经 `wait_for_governed_job` 到达 `done`,结果为
|
|
154
|
+
`BAILIAN_BAILINGHUB_E2E_OK`。
|
|
155
|
+
- 对应 BailingHub 调度流记录了固定路由 `bailian-e2e`、目标 `llm` 与终态 `done`;
|
|
156
|
+
测试没有开放业务工具,也没有把业务凭据交给模型或百炼。
|
|
157
|
+
- 以上是维护者工作空间中的兼容性证据,不代表阿里云认证、推荐、采用、合作或公开市场
|
|
158
|
+
收录。不同部署仍应使用自己的隔离路由和无副作用输入完成验证。
|
|
159
|
+
|
|
160
|
+
## 官方参考
|
|
161
|
+
|
|
162
|
+
- [百炼自定义 MCP](https://help.aliyun.com/zh/model-studio/custom-mcp)
|
|
163
|
+
- [百炼 MCP 介绍](https://help.aliyun.com/zh/model-studio/mcp-introduction/)
|
|
164
|
+
- [BailingHub MCP Server](https://github.com/bailinghub/bailinghub-mcp-server)
|
|
165
|
+
- [BailingHub MCP 集成入口](https://www.bailinghub.com/en/integrations#mcp)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mcpServers": {
|
|
3
|
+
"bailinghub": {
|
|
4
|
+
"type": "stdio",
|
|
5
|
+
"command": "npx",
|
|
6
|
+
"args": [
|
|
7
|
+
"-y",
|
|
8
|
+
"bailinghub-mcp-server@0.1.0"
|
|
9
|
+
],
|
|
10
|
+
"env": {
|
|
11
|
+
"BAILINGHUB_BASE_URL": "https://hub.example.com",
|
|
12
|
+
"BAILINGHUB_CLIENT_TOKEN": "replace-with-a-route-scoped-client-token",
|
|
13
|
+
"BAILINGHUB_ROUTE": "bailian_assistant"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from urllib.parse import urlparse
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
RECIPE_DIR = Path(__file__).resolve().parent
|
|
11
|
+
CONFIG_PATH = RECIPE_DIR / "bailian-mcp-config.json"
|
|
12
|
+
EXPECTED_PACKAGE = "bailinghub-mcp-server@0.1.0"
|
|
13
|
+
EXPECTED_ENV_KEYS = {
|
|
14
|
+
"BAILINGHUB_BASE_URL",
|
|
15
|
+
"BAILINGHUB_CLIENT_TOKEN",
|
|
16
|
+
"BAILINGHUB_ROUTE",
|
|
17
|
+
}
|
|
18
|
+
FORBIDDEN_ENV_MARKERS = {
|
|
19
|
+
"ADMIN",
|
|
20
|
+
"APPROVAL",
|
|
21
|
+
"BUSINESS",
|
|
22
|
+
"EXECUTOR",
|
|
23
|
+
"MODEL",
|
|
24
|
+
"SERVER_TOKEN",
|
|
25
|
+
"TOOL_TOKEN",
|
|
26
|
+
}
|
|
27
|
+
ROUTE_PATTERN = re.compile(r"^[a-z][a-z0-9_-]{1,63}$")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def fail(message: str) -> None:
|
|
31
|
+
print(f"FAIL: {message}", file=sys.stderr)
|
|
32
|
+
raise SystemExit(1)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def require(condition: bool, message: str) -> None:
|
|
36
|
+
if not condition:
|
|
37
|
+
fail(message)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def main() -> None:
|
|
41
|
+
try:
|
|
42
|
+
config = json.loads(CONFIG_PATH.read_text(encoding="utf-8"))
|
|
43
|
+
except (OSError, json.JSONDecodeError) as error:
|
|
44
|
+
fail(f"cannot read {CONFIG_PATH.name}: {error}")
|
|
45
|
+
|
|
46
|
+
require(set(config) == {"mcpServers"}, "top level must contain only mcpServers")
|
|
47
|
+
servers = config["mcpServers"]
|
|
48
|
+
require(isinstance(servers, dict), "mcpServers must be an object")
|
|
49
|
+
require(set(servers) == {"bailinghub"}, "recipe must define exactly one bailinghub server")
|
|
50
|
+
|
|
51
|
+
server = servers["bailinghub"]
|
|
52
|
+
require(isinstance(server, dict), "bailinghub server must be an object")
|
|
53
|
+
require(
|
|
54
|
+
set(server) == {"type", "command", "args", "env"},
|
|
55
|
+
"bailinghub server must contain only type, command, args, and env",
|
|
56
|
+
)
|
|
57
|
+
require(server["type"] == "stdio", "Bailian npx deployment must use stdio")
|
|
58
|
+
require(server["command"] == "npx", "command must be npx")
|
|
59
|
+
require(
|
|
60
|
+
server["args"] == ["-y", EXPECTED_PACKAGE],
|
|
61
|
+
f"args must pin the public package to {EXPECTED_PACKAGE}",
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
env = server["env"]
|
|
65
|
+
require(isinstance(env, dict), "env must be an object")
|
|
66
|
+
require(set(env) == EXPECTED_ENV_KEYS, "env must contain only the three client settings")
|
|
67
|
+
|
|
68
|
+
base_url = env["BAILINGHUB_BASE_URL"]
|
|
69
|
+
require(isinstance(base_url, str), "BAILINGHUB_BASE_URL must be a string")
|
|
70
|
+
parsed = urlparse(base_url)
|
|
71
|
+
require(parsed.scheme == "https", "cloud recipe must use an HTTPS BailingHub URL")
|
|
72
|
+
require(bool(parsed.netloc), "BAILINGHUB_BASE_URL must include a host")
|
|
73
|
+
require(not parsed.username and not parsed.password, "base URL must not embed credentials")
|
|
74
|
+
require(not parsed.query and not parsed.fragment, "base URL must not include query or fragment")
|
|
75
|
+
|
|
76
|
+
token = env["BAILINGHUB_CLIENT_TOKEN"]
|
|
77
|
+
require(
|
|
78
|
+
token == "replace-with-a-route-scoped-client-token",
|
|
79
|
+
"public recipe must contain the documented token placeholder, never a real token",
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
route = env["BAILINGHUB_ROUTE"]
|
|
83
|
+
require(isinstance(route, str) and bool(ROUTE_PATTERN.fullmatch(route)), "route is invalid")
|
|
84
|
+
require(route == "bailian_assistant", "public recipe route must remain bailian_assistant")
|
|
85
|
+
|
|
86
|
+
for key in env:
|
|
87
|
+
upper_key = key.upper()
|
|
88
|
+
require(
|
|
89
|
+
not any(marker in upper_key for marker in FORBIDDEN_ENV_MARKERS),
|
|
90
|
+
f"privileged credential setting is forbidden: {key}",
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
print("PASS: Bailian to BailingHub MCP recipe is structurally valid.")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
if __name__ == "__main__":
|
|
97
|
+
main()
|