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,231 @@
|
|
|
1
|
+
# 生产运维指南
|
|
2
|
+
|
|
3
|
+
本文面向自托管百灵中枢的运维与平台团队,说明单实例、多副本、健康检查、容量、备份和故障恢复的稳定做法。快速体验请先看 [DEMO.md](DEMO.md),首次部署请看 [QUICKSTART.md](QUICKSTART.md)。
|
|
4
|
+
|
|
5
|
+
## 1. 推荐拓扑
|
|
6
|
+
|
|
7
|
+
### 单实例
|
|
8
|
+
|
|
9
|
+
适合开发、试点和低流量内部场景:
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
业务系统 / 渠道
|
|
13
|
+
|
|
|
14
|
+
HTTPS 反向代理
|
|
15
|
+
|
|
|
16
|
+
BailingHub x 1
|
|
17
|
+
|
|
|
18
|
+
MySQL
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
任务、租约、审批、限流和审计均落 MySQL。进程内 `Queue` 只限制当前实例的并发数,不承担持久化排队。
|
|
22
|
+
|
|
23
|
+
### 多副本
|
|
24
|
+
|
|
25
|
+
适合需要滚动发布或实例故障自动接管的部署:
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
业务系统 / 渠道
|
|
29
|
+
|
|
|
30
|
+
负载均衡 / Ingress
|
|
31
|
+
|
|
|
32
|
+
+----+----+
|
|
33
|
+
| |
|
|
34
|
+
Hub A Hub B
|
|
35
|
+
| |
|
|
36
|
+
+----+----+
|
|
37
|
+
|
|
|
38
|
+
共享 MySQL
|
|
39
|
+
|
|
|
40
|
+
共享对象存储(推荐)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
所有副本必须:
|
|
44
|
+
|
|
45
|
+
- 使用同一套 MySQL 数据库和服务端安全配置。
|
|
46
|
+
- 使用一致的构建版本和数据库迁移版本。
|
|
47
|
+
- 通过数据库 claim/lease 认领任务;同一任务只会被一个副本成功认领。
|
|
48
|
+
- 多副本时使用共享对象存储。服务器本地媒体存储只适合单实例,因为另一个副本无法读取本机文件。
|
|
49
|
+
- 网页聊天的增量事件默认使用进程内短期回放窗口。多副本时应让同一 `job_id` 的创建请求和 SSE 连接命中同一副本,或注入共享 `JobStreamBroker`;否则最终 `done` 仍可从 MySQL 返回,但可能看不到逐段文本。
|
|
50
|
+
- 由负载均衡检查 `/health/ready`,滚动发布前先摘流量,再等待优雅停机完成。
|
|
51
|
+
|
|
52
|
+
## 2. 健康检查
|
|
53
|
+
|
|
54
|
+
| 端点 | 用途 | 失败意味着什么 |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| `GET /health` | liveness,确认进程仍在响应 | 进程应重启 |
|
|
57
|
+
| `GET /health/ready` | readiness,确认 MySQL 可达且迁移齐全 | 暂时不要把新流量发给该实例 |
|
|
58
|
+
|
|
59
|
+
readiness 不检查模型、工具源、渠道等外部业务依赖。某个模型服务波动不应导致整个中枢实例被负载均衡摘除;这些依赖由控制台“系统体检”和告警规则持续检查。
|
|
60
|
+
|
|
61
|
+
`/health` 的 `observability.audit_write_failures` 是当前进程累计的审计写入失败数,`last_audit_failure_at` 是最后失败时间。数值大于 0 时应立即检索运行日志中的结构化事件 `audit_write_failed` 并检查数据库;该计数随进程重启归零,不替代外部监控。安全关键审计仍然 fail-closed,允许 best-effort 的运行事件即使被调用方降级,也会先经过该统一观测层。
|
|
62
|
+
|
|
63
|
+
Kubernetes 建议:
|
|
64
|
+
|
|
65
|
+
```yaml
|
|
66
|
+
livenessProbe:
|
|
67
|
+
httpGet: { path: /health, port: 18900 }
|
|
68
|
+
readinessProbe:
|
|
69
|
+
httpGet: { path: /health/ready, port: 18900 }
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 3. OpenMetrics 运维指标
|
|
73
|
+
|
|
74
|
+
`GET /metrics` 提供适合 Prometheus 等监控系统抓取的低基数 OpenMetrics 文本。该端点默认关闭;关闭时返回 404,避免未配置的部署意外暴露运行状态。
|
|
75
|
+
|
|
76
|
+
启用方式:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
BAILING_METRICS_ENABLED=true
|
|
80
|
+
BAILING_METRICS_TOKEN="$(openssl rand -hex 32)"
|
|
81
|
+
BAILING_METRICS_SCRAPE_TIMEOUT_MS=5000
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`BAILING_METRICS_TOKEN` 必须是至少 24 个字符的独立强随机 Token,不能与 `BAILING_TOKEN` 相同。Token 只通过 `Authorization: Bearer ...` 请求头传递,不支持 query 参数。建议只允许监控网络访问 `/metrics`,并继续使用 HTTPS 或集群内受控网络。
|
|
85
|
+
|
|
86
|
+
验证抓取:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
curl -fsS \
|
|
90
|
+
-H "Authorization: Bearer ${BAILING_METRICS_TOKEN}" \
|
|
91
|
+
https://hub.example.com/metrics
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Prometheus 示例:
|
|
95
|
+
|
|
96
|
+
```yaml
|
|
97
|
+
scrape_configs:
|
|
98
|
+
- job_name: bailinghub
|
|
99
|
+
metrics_path: /metrics
|
|
100
|
+
authorization:
|
|
101
|
+
type: Bearer
|
|
102
|
+
credentials_file: /etc/prometheus/secrets/bailinghub_metrics_token
|
|
103
|
+
static_configs:
|
|
104
|
+
- targets: ["bailinghub:18900"]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
主要指标:
|
|
108
|
+
|
|
109
|
+
| 指标 | 含义 |
|
|
110
|
+
|---|---|
|
|
111
|
+
| `bailinghub_info` | 当前版本与构建提交 |
|
|
112
|
+
| `bailinghub_up` | 指标端点本次是否正常响应 |
|
|
113
|
+
| `bailinghub_runtime_paused` | 全局暂停开关是否生效 |
|
|
114
|
+
| `bailinghub_runtime_queue` | 当前进程内 running / waiting 数 |
|
|
115
|
+
| `bailinghub_job_records` | 按固定生命周期状态统计的任务存量 |
|
|
116
|
+
| `bailinghub_jobs_terminal_15m` | 最近 15 分钟进入终态的任务数 |
|
|
117
|
+
| `bailinghub_queue_oldest_queued_age_seconds` | 最老非 monitor 排队任务的等待秒数 |
|
|
118
|
+
| `bailinghub_queue_delayed_jobs` | `run_after` 尚未到期的延迟任务数 |
|
|
119
|
+
| `bailinghub_jobs_expired_leases` | 已明确过期的运行/派发租约数 |
|
|
120
|
+
| `bailinghub_threads_blocked` | 被同线程在途任务阻塞的会话线程数 |
|
|
121
|
+
| `bailinghub_approvals_pending` | 待决策的工具审批数 |
|
|
122
|
+
| `bailinghub_executors` | 按 online / offline 统计的执行器数 |
|
|
123
|
+
| `bailinghub_audit_write_failures_total` | 当前进程累计审计写入失败数 |
|
|
124
|
+
| `bailinghub_metrics_collector_available` | 状态库/控制面采集器是否实现 |
|
|
125
|
+
| `bailinghub_metrics_collector_success` | 对应采集器在本次抓取中是否成功 |
|
|
126
|
+
| `bailinghub_metrics_scrape_duration_seconds` | 本次聚合和渲染耗时 |
|
|
127
|
+
|
|
128
|
+
指标标签是固定、低基数集合,不包含 `job_id`、租户、主体、路由参数或业务载荷。单个可选采集器超时或失败时,端点仍返回其余指标,并把对应 `bailinghub_metrics_collector_success` 置为 0;日志只记录采集器类别和失败类型,不记录异常正文或业务数据。JSONL 状态后端可提供任务指标,但没有 MySQL 控制面聚合时,`control_plane` 会标记为不可用。
|
|
129
|
+
|
|
130
|
+
建议至少告警:
|
|
131
|
+
|
|
132
|
+
- 任一已启用采集器的 `bailinghub_metrics_collector_success == 0`。
|
|
133
|
+
- `bailinghub_jobs_expired_leases > 0`。
|
|
134
|
+
- `bailinghub_queue_oldest_queued_age_seconds` 持续超过本业务的最大等待目标。
|
|
135
|
+
- `bailinghub_audit_write_failures_total` 增长。
|
|
136
|
+
- 预期在线的执行器进入 `offline`,或近期错误/拒绝终态占比异常升高。
|
|
137
|
+
|
|
138
|
+
指标是外部监控输入,不替代 `/health/ready`、业务系统最终授权、审计账本或控制台诊断。
|
|
139
|
+
|
|
140
|
+
## 4. 并发与连接池
|
|
141
|
+
|
|
142
|
+
- `concurrency` 控制单实例同时执行的任务数。
|
|
143
|
+
- `BAILING_MYSQL_CONNECTION_LIMIT` 控制每个实例的 MySQL 连接池上限,默认 15。
|
|
144
|
+
- 总连接预算约为:`中枢副本数 × 每副本连接池上限 + 运维/迁移连接`。
|
|
145
|
+
- 不要直接用“HTTP QPS”估算容量。任务时长、模型延迟、工具调用次数和 SSE 连接时长都会改变容量。
|
|
146
|
+
- 反向代理必须禁止 SSE 响应缓冲,并将读取超时设为大于单次聊天最长等待时间。中枢会返回 `X-Accel-Buffering: no`,但 CDN/Ingress 仍需独立核对。
|
|
147
|
+
|
|
148
|
+
扩容前先记录:
|
|
149
|
+
|
|
150
|
+
- 排队任务数和最老任务等待时间。
|
|
151
|
+
- 任务成功率、P95/P99 总耗时。
|
|
152
|
+
- 工具调用失败率和耗时。
|
|
153
|
+
- MySQL 活跃连接、慢查询和锁等待。
|
|
154
|
+
- CPU、内存和事件循环延迟。
|
|
155
|
+
|
|
156
|
+
当 CPU 仍有余量但任务持续排队,可增加副本或并发;当 MySQL 已成为瓶颈,应先处理索引、慢查询和连接预算,盲目加副本会让数据库更慢。
|
|
157
|
+
|
|
158
|
+
项目不会宣称未经目标机器、模型和业务接口实测的固定 QPS。发布容量承诺前,应使用自己的任务分布进行压测。
|
|
159
|
+
|
|
160
|
+
### 工具语义检索运行保护
|
|
161
|
+
|
|
162
|
+
工具语义检索是一项可选的上下文增强。索引存储或查询向量服务超时时,本轮会改用渐进式工具发现,而不是让会话无限等待召回结果。可通过部署环境变量调整两个独立时限:
|
|
163
|
+
|
|
164
|
+
进程启动后会在后台按工具源顺序预热已持久化索引,HTTP 就绪不等待预热。内存缓存过期时仍继续服务旧快照,并在后台单飞刷新;只有真正的冷缓存才会在下述索引时限内等待。
|
|
165
|
+
|
|
166
|
+
| 变量 | 默认值 | 允许范围 | 用途 |
|
|
167
|
+
|---|---:|---:|---|
|
|
168
|
+
| `BAILING_TOOL_INDEX_LOAD_TIMEOUT_MS` | 5000 ms | 100–60000 ms | 限制读取工具向量及其 embedding 凭证元数据的单次数据库等待时间 |
|
|
169
|
+
| `BAILING_TOOL_QUERY_EMBEDDING_TIMEOUT_MS` | 15000 ms | 250–120000 ms | 限制为当前查询生成向量的等待时间 |
|
|
170
|
+
|
|
171
|
+
这些是单个中枢部署的基础设施保护,不是路由或工具提供方的业务策略,因此对当前进程的所有工具语义检索生效。改小前应根据本部署的正常延迟分布验证;改大会延长外部依赖异常时的会话等待。
|
|
172
|
+
|
|
173
|
+
新增的分阶段诊断事件会记录缓存状态、索引/凭证/查询向量耗时及稳定原因码,但不携带用户查询、服务地址或凭证。诊断写入是 best-effort,不会反过来阻塞检索降级。
|
|
174
|
+
|
|
175
|
+
## 5. 发布与升级
|
|
176
|
+
|
|
177
|
+
1. 备份数据库。
|
|
178
|
+
2. 在一个非生产环境运行 `npm run release:check`。
|
|
179
|
+
3. 运行数据库迁移;迁移脚本只向前执行,账本位于 `bz_schema_migrations`。
|
|
180
|
+
4. 启动新实例并等待 `/health/ready` 返回 200。
|
|
181
|
+
5. 逐个替换旧实例,观察队列、错误率和租约恢复。
|
|
182
|
+
6. 确认无异常后再清理旧镜像。
|
|
183
|
+
|
|
184
|
+
不要在多副本上同时并发运行迁移。数据库迁移应由一个部署步骤负责,应用副本只负责启动和 readiness 检查。
|
|
185
|
+
|
|
186
|
+
## 6. 备份与恢复
|
|
187
|
+
|
|
188
|
+
至少备份:
|
|
189
|
+
|
|
190
|
+
- MySQL 全库,包括配置、任务、审批、审计和迁移账本。
|
|
191
|
+
- 对象存储中的聊天媒体和知识库原文件。
|
|
192
|
+
- 部署环境变量和外部密钥的安全副本。
|
|
193
|
+
|
|
194
|
+
推荐使用 MySQL 一致性快照或 `mysqldump --single-transaction`,并定期做恢复演练。没有验证过恢复流程的备份不能视为可用备份。
|
|
195
|
+
|
|
196
|
+
恢复顺序:
|
|
197
|
+
|
|
198
|
+
1. 停止所有中枢副本接收流量。
|
|
199
|
+
2. 恢复 MySQL 与共享对象存储。
|
|
200
|
+
3. 使用与备份迁移版本兼容的中枢镜像启动一个实例。
|
|
201
|
+
4. 检查 `/health/ready`、系统体检和关键任务 trace。
|
|
202
|
+
5. 再逐步恢复其余副本和流量。
|
|
203
|
+
|
|
204
|
+
## 7. 故障语义
|
|
205
|
+
|
|
206
|
+
- 实例在任务执行中崩溃:数据库 lease 到期后由 reaper 恢复,任务不会依赖进程内队列保存。
|
|
207
|
+
- executor 回报暂时失败:执行器重试;最终未回报的任务由 lease 恢复。
|
|
208
|
+
- 审批等待:审批意图在数据库中持久化,不依赖实例内存。
|
|
209
|
+
- 外部工具或模型失败:任务记录错误与 trace,是否重试由路由和错误类型决定。
|
|
210
|
+
- 审计写入失败:安全关键工具调用按 fail-closed 处理;非关键运行事件不阻塞业务,但应进入运维告警与指标。
|
|
211
|
+
|
|
212
|
+
## 8. 安全基线
|
|
213
|
+
|
|
214
|
+
- 仅通过 HTTPS 暴露公网入口。
|
|
215
|
+
- 管理端、接入方、执行器和工具源使用不同凭证,不复用密钥。
|
|
216
|
+
- 指标端点使用独立 `BAILING_METRICS_TOKEN`,不得与管理根密钥复用。
|
|
217
|
+
- MySQL 不直接暴露公网。
|
|
218
|
+
- 无人值守部署应成对设置 `BAILING_BOOTSTRAP_ADMIN_USERNAME` 与 `BAILING_BOOTSTRAP_ADMIN_PASSWORD`。它们只负责空管理员表的首次创建,不是持续同步配置;修改或轮换密码应走控制台或显式 `admin:create`,不要依赖重启。
|
|
219
|
+
- 定期轮换管理员、接入方、执行器和工具签名密钥。
|
|
220
|
+
- 生产关闭 demo 默认凭证,限制控制台来源和数据库账号权限。
|
|
221
|
+
- 日志、错误响应和监控标签不得包含 API key、数据库密码或完整业务敏感载荷。
|
|
222
|
+
|
|
223
|
+
## 9. 上线检查单
|
|
224
|
+
|
|
225
|
+
- `/health` 返回 200。
|
|
226
|
+
- `/health/ready` 返回 200,迁移 pending 为 0。
|
|
227
|
+
- 如启用运维指标,使用监控专用 Token 抓取 `/metrics` 成功,两个采集器状态符合部署后端预期。
|
|
228
|
+
- 控制台系统体检没有配置错误或过期租约。
|
|
229
|
+
- 至少跑通一次真实 `/run`、工具调用、trace 和结果回传。
|
|
230
|
+
- 已验证备份可恢复。
|
|
231
|
+
- 已设置队列积压、错误率、executor 离线和送达死信告警。
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Runtime Pipeline
|
|
2
|
+
|
|
3
|
+
The runtime pipeline explains how one job moves through BailingHub from trigger to result delivery.
|
|
4
|
+
|
|
5
|
+
## 1. Trigger
|
|
6
|
+
|
|
7
|
+
A job can enter through:
|
|
8
|
+
|
|
9
|
+
- `POST /run`;
|
|
10
|
+
- web chat widget;
|
|
11
|
+
- inbound channel adapter;
|
|
12
|
+
- controlled internal APIs.
|
|
13
|
+
|
|
14
|
+
The entry layer authenticates the client or channel, validates payload shape, applies idempotency, and resolves the route.
|
|
15
|
+
|
|
16
|
+
## 2. Route Resolution
|
|
17
|
+
|
|
18
|
+
The route determines:
|
|
19
|
+
|
|
20
|
+
- target model or executor;
|
|
21
|
+
- model credential;
|
|
22
|
+
- memory and session policy;
|
|
23
|
+
- knowledge base and retrieval settings;
|
|
24
|
+
- allowed tool providers and scopes;
|
|
25
|
+
- budget and rate limits;
|
|
26
|
+
- callback or delivery policy.
|
|
27
|
+
|
|
28
|
+
`route=auto` can be used when the client is allowed to let the hub select a route from configured audience and keyword rules.
|
|
29
|
+
|
|
30
|
+
## 3. Context Assembly
|
|
31
|
+
|
|
32
|
+
The hub assembles:
|
|
33
|
+
|
|
34
|
+
- current input;
|
|
35
|
+
- message ledger;
|
|
36
|
+
- optional rolling summary;
|
|
37
|
+
- route-level knowledge retrieval;
|
|
38
|
+
- page context;
|
|
39
|
+
- principal and metadata;
|
|
40
|
+
- tool definitions visible to the route.
|
|
41
|
+
|
|
42
|
+
Untrusted user input and page context are wrapped as data, not executed as instructions.
|
|
43
|
+
|
|
44
|
+
## 4. Dispatch
|
|
45
|
+
|
|
46
|
+
The job is dispatched to a target:
|
|
47
|
+
|
|
48
|
+
- in-hub OpenAI-compatible model target;
|
|
49
|
+
- external executor target;
|
|
50
|
+
- future adapters that implement the same target contract.
|
|
51
|
+
|
|
52
|
+
Jobs are claimed through the persistent queue and lease model so multi-process deployments can recover abandoned work.
|
|
53
|
+
|
|
54
|
+
## 5. Tool Invocation
|
|
55
|
+
|
|
56
|
+
When the model requests a tool call, the tool runtime checks:
|
|
57
|
+
|
|
58
|
+
- route allowlist;
|
|
59
|
+
- tool scope;
|
|
60
|
+
- subject requirement;
|
|
61
|
+
- risk level;
|
|
62
|
+
- rate limits;
|
|
63
|
+
- approval or confirmation rules;
|
|
64
|
+
- authorization probe result when configured.
|
|
65
|
+
|
|
66
|
+
Allowed tool calls are signed and sent to the business system. The business system verifies the signature and performs final authorization.
|
|
67
|
+
|
|
68
|
+
## 6. Approval
|
|
69
|
+
|
|
70
|
+
High-risk or confirmation-required calls are frozen as approval intents. In production, the business-side workflow should usually own the actual approval decision. The hub records the approval intent and only replays the exact approved argument snapshot.
|
|
71
|
+
|
|
72
|
+
## 7. Audit, Trace, And Delivery
|
|
73
|
+
|
|
74
|
+
The hub records trace events, audit records, approvals, messages, delivery attempts, and final result. The business system can poll job status or receive signed callbacks.
|
package/docs/PIPELINE.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# CI Pipeline Integration Example
|
|
2
|
+
|
|
3
|
+
> This is an optional integration example. The generic setup flow is in `QUICKSTART.md`; the wire contract is in `CONTRACT.md`.
|
|
4
|
+
|
|
5
|
+
Scenario: a developer pushes code, CI triggers a `code-review` route, an executor or inhub target performs read-only review, and the hub delivers the result to the developer through a configured delivery channel.
|
|
6
|
+
|
|
7
|
+
## CI Step
|
|
8
|
+
|
|
9
|
+
Add a command step after build/test:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Decoupling rule: short timeout, never fail the CI job because the hub is unavailable.
|
|
13
|
+
curl -s -m 2 -X POST 'https://hub.example.com/run' \
|
|
14
|
+
-H 'Content-Type: application/json' \
|
|
15
|
+
-H 'Authorization: Bearer <client token from the console>' \
|
|
16
|
+
-d "{
|
|
17
|
+
\"request_id\": \"ci_review_${CI_COMMIT_SHA}\",
|
|
18
|
+
\"route\": \"code-review\",
|
|
19
|
+
\"input\": \"Review commit ${CI_COMMIT_SHA} on branch ${CI_COMMIT_BRANCH} by ${CI_COMMIT_AUTHOR}.\",
|
|
20
|
+
\"source\": \"ci-pipeline\",
|
|
21
|
+
\"metadata\": {
|
|
22
|
+
\"committer\": \"${COMMITTER_USER_ID}\",
|
|
23
|
+
\"commit\": \"${CI_COMMIT_SHA}\",
|
|
24
|
+
\"branch\": \"${CI_COMMIT_BRANCH}\"
|
|
25
|
+
}
|
|
26
|
+
}" || true
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Key points:
|
|
30
|
+
|
|
31
|
+
- `request_id` is the idempotency key. Re-running the same commit should not create duplicate review jobs.
|
|
32
|
+
- `-m 2` and `|| true` keep CI independent from the hub.
|
|
33
|
+
- `metadata.committer` should be the delivery-channel user id, not necessarily the Git author name. Maintain that mapping in your CI system.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
case "${CI_COMMIT_AUTHOR}" in
|
|
37
|
+
alice) COMMITTER_USER_ID="alice" ;;
|
|
38
|
+
bob) COMMITTER_USER_ID="bob" ;;
|
|
39
|
+
*) COMMITTER_USER_ID="" ;;
|
|
40
|
+
esac
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Adjust environment variable names to your CI provider.
|
|
44
|
+
|
|
45
|
+
## Hub Route Configuration
|
|
46
|
+
|
|
47
|
+
Example `delivery` config for the `code-review` route:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{ "type": "channel", "channel": "team-im", "to_field": "committer", "to": "fallback-user" }
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- `to_field`: read the recipient from request metadata;
|
|
54
|
+
- `to`: fallback recipient if metadata is missing.
|
|
55
|
+
|
|
56
|
+
## Sequence
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
push → CI curl returns quickly → hub creates review job → target executes review
|
|
60
|
+
→ report returns to hub → delivery sends result → follow-up messages can continue on the same route/session
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Notes
|
|
64
|
+
|
|
65
|
+
- Use a dedicated client token for CI.
|
|
66
|
+
- Limit that client to the `code-review` route.
|
|
67
|
+
- Keep review delivery optional; the source of truth remains the CI result and the hub audit trail.
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# Quickstart
|
|
2
|
+
|
|
3
|
+
This guide gets you from a fresh checkout to the first working BailingHub hub.
|
|
4
|
+
|
|
5
|
+
BailingHub is designed around one idea:
|
|
6
|
+
|
|
7
|
+
> Your business system triggers work. The hub routes, assembles context, governs tools, records audit trails, and sends results back.
|
|
8
|
+
|
|
9
|
+
## Mental Model
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
Business system --POST /run--> BailingHub route --> model / executor --> result delivery
|
|
13
|
+
|
|
|
14
|
+
+-- knowledge
|
|
15
|
+
+-- memory
|
|
16
|
+
+-- OpenAPI/SDK tools
|
|
17
|
+
+-- approval and audit
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Key objects:
|
|
21
|
+
|
|
22
|
+
| Object | Meaning |
|
|
23
|
+
|---|---|
|
|
24
|
+
| Route | A business scenario. It chooses the model/executor, memory policy, knowledge, tools, retry, and delivery behavior. |
|
|
25
|
+
| Client | A business system credential with route allowlists and rate limits. |
|
|
26
|
+
| Target | A model or executor slot. Start with the built-in `llm` target. |
|
|
27
|
+
| Tool provider | A business system's agent-callable API catalog, usually OpenAPI with ACC `x-agent-capability` metadata or an SDK-generated spec. |
|
|
28
|
+
| Runtime ledger | Jobs, messages, audit records, approvals, and trace events stored by the hub. |
|
|
29
|
+
|
|
30
|
+
## Option A: Docker Demo
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
export BAILING_TOKEN="${BAILING_TOKEN:-$(openssl rand -hex 32)}"
|
|
34
|
+
docker compose up --build
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Keep the same `BAILING_TOKEN` for later `docker compose` commands, or save it in a local `.env` file. Only loopback-bound development mode may run without a token. Production and non-loopback listeners reject missing, short, or known placeholder values.
|
|
38
|
+
|
|
39
|
+
Open:
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
http://localhost:18900/console/
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Login:
|
|
46
|
+
|
|
47
|
+
```text
|
|
48
|
+
admin / bailing-demo-admin
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The demo creates:
|
|
52
|
+
|
|
53
|
+
- hub service
|
|
54
|
+
- MySQL
|
|
55
|
+
- demo business app
|
|
56
|
+
- `demo_support` route
|
|
57
|
+
- `demo-business` tool provider
|
|
58
|
+
- `demo-app` integration client
|
|
59
|
+
|
|
60
|
+
Run smoke checks inside the container:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
docker compose exec bailinghub npm run smoke
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Run the full demo flow:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
docker compose exec bailinghub npm run demo:e2e
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Option B: One-Line Install
|
|
73
|
+
|
|
74
|
+
For a fresh Ubuntu/Debian server:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
curl -fsSL https://www.bailinghub.com/install.sh | sh
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Use official prebuilt images:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
curl -fsSL https://www.bailinghub.com/install.sh | env BAILING_INSTALL_MODE=image sh
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Use source mode for audit or development:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
curl -fsSL https://www.bailinghub.com/install.sh | env BAILING_INSTALL_MODE=source sh
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Use the public GHCR images outside China:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
curl -fsSL https://www.bailinghub.com/install.sh | env \
|
|
96
|
+
BAILING_INSTALL_MODE=image \
|
|
97
|
+
BAILING_IMAGE_REGISTRY=ghcr.io \
|
|
98
|
+
BAILING_IMAGE_NAMESPACE=bailinghub \
|
|
99
|
+
BAILING_MYSQL_IMAGE=mysql:8.4 \
|
|
100
|
+
sh
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The default image registry is the Aliyun ACR mirror for networks in China. Both registries publish the same versioned BailingHub and demo application images.
|
|
104
|
+
|
|
105
|
+
## Option C: Local Development
|
|
106
|
+
|
|
107
|
+
Requirements:
|
|
108
|
+
|
|
109
|
+
- Node.js 22+
|
|
110
|
+
- MySQL for full runtime features
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npm install
|
|
114
|
+
npm run doctor
|
|
115
|
+
npm run typecheck
|
|
116
|
+
npm run db:init
|
|
117
|
+
npm start
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
For unattended deployments, set both `BAILING_BOOTSTRAP_ADMIN_USERNAME` and
|
|
121
|
+
`BAILING_BOOTSTRAP_ADMIN_PASSWORD` before starting the service. BailingHub
|
|
122
|
+
creates that account only when the admin table is empty. Restarts, upgrades,
|
|
123
|
+
and container recreation with the same database never update an existing
|
|
124
|
+
account or password. For an explicit create or password reset, use
|
|
125
|
+
`npm run admin:create -- <username> [password] [role]`; the startup path never
|
|
126
|
+
invokes that command automatically.
|
|
127
|
+
|
|
128
|
+
Health check:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
curl http://localhost:18900/health
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Create the First Real Integration
|
|
135
|
+
|
|
136
|
+
### 1. Create a Model Credential
|
|
137
|
+
|
|
138
|
+
In the console, open **Credentials** and add an OpenAI-compatible endpoint and API key.
|
|
139
|
+
|
|
140
|
+
The built-in `llm` target can use OpenAI-compatible providers, self-hosted model gateways, or other compatible endpoints.
|
|
141
|
+
|
|
142
|
+
### 2. Create a Route
|
|
143
|
+
|
|
144
|
+
Open **Routes** and create a business scenario.
|
|
145
|
+
|
|
146
|
+
A route controls:
|
|
147
|
+
|
|
148
|
+
- model or executor target
|
|
149
|
+
- system prompt
|
|
150
|
+
- session policy
|
|
151
|
+
- knowledge retrieval
|
|
152
|
+
- tool providers and allowed scopes
|
|
153
|
+
- delivery behavior
|
|
154
|
+
- budget and retry settings
|
|
155
|
+
|
|
156
|
+
### 3. Create a Client
|
|
157
|
+
|
|
158
|
+
Open **Clients** and create a token for your business system.
|
|
159
|
+
|
|
160
|
+
The client controls:
|
|
161
|
+
|
|
162
|
+
- which routes the business system can call
|
|
163
|
+
- rate limits
|
|
164
|
+
- budget policies
|
|
165
|
+
- channel restrictions
|
|
166
|
+
|
|
167
|
+
### 4. Trigger a Job
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
curl -X POST http://localhost:18900/run \
|
|
171
|
+
-H 'content-type: application/json' \
|
|
172
|
+
-H 'authorization: Bearer <client-token>' \
|
|
173
|
+
-d '{
|
|
174
|
+
"request_id": "demo-001",
|
|
175
|
+
"route": "demo_support",
|
|
176
|
+
"input": "Help me check this order",
|
|
177
|
+
"metadata": {
|
|
178
|
+
"operator_uid": "u_1001",
|
|
179
|
+
"order_id": "SO20260701001"
|
|
180
|
+
}
|
|
181
|
+
}'
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The response contains a `job_id`.
|
|
185
|
+
|
|
186
|
+
Query the result:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
curl http://localhost:18900/jobs/<job_id> \
|
|
190
|
+
-H 'authorization: Bearer <client-token>'
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Expose Business Tools
|
|
194
|
+
|
|
195
|
+
To let AI agents query or operate your system, expose a tool spec:
|
|
196
|
+
|
|
197
|
+
```text
|
|
198
|
+
/.well-known/bailing/tools.json
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
URL providers expose exactly two configurable policies and default to
|
|
202
|
+
`spec_access_policy: signed_required`. Choose `public_allowed` only when you
|
|
203
|
+
intentionally accept exposing paths, parameters,
|
|
204
|
+
scopes, and risk declarations to anyone who can reach the URL. A
|
|
205
|
+
`signed_required` refresh reads with a valid signature and then runs unsigned
|
|
206
|
+
and invalid-signature negative probes; it updates the cache only after the
|
|
207
|
+
protected posture is proven. `public_allowed` reads unsigned and never silently
|
|
208
|
+
falls back to a signed fetch. The console keeps the configured expectation
|
|
209
|
+
separate from the observed `protected`, `public`, or `inconclusive` status.
|
|
210
|
+
Signed-only responses must send
|
|
211
|
+
`Cache-Control: private, no-store`.
|
|
212
|
+
|
|
213
|
+
The preferred paths:
|
|
214
|
+
|
|
215
|
+
- PHP 8+ SDK annotations
|
|
216
|
+
- PHP 7 builder SDK
|
|
217
|
+
- Node SDK
|
|
218
|
+
- Python SDK
|
|
219
|
+
- OpenAPI with `x-agent-capability` extensions
|
|
220
|
+
|
|
221
|
+
Minimal Node example:
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
import { buildOpenApiSpec, param, tool } from '@bailinghub/connect';
|
|
225
|
+
|
|
226
|
+
export default buildOpenApiSpec({
|
|
227
|
+
title: 'Order System Tools',
|
|
228
|
+
version: '1.0.0',
|
|
229
|
+
authzProbe: { method: 'POST', path: '/.well-known/bailing/authz-probe' },
|
|
230
|
+
tools: [
|
|
231
|
+
tool({
|
|
232
|
+
name: 'order_get',
|
|
233
|
+
method: 'GET',
|
|
234
|
+
path: '/api/orders/{id}',
|
|
235
|
+
description: 'Query order detail',
|
|
236
|
+
scope: 'order.read',
|
|
237
|
+
requiresSubject: true,
|
|
238
|
+
params: [param('id', { in: 'path', required: true, description: 'Order ID' })],
|
|
239
|
+
}),
|
|
240
|
+
],
|
|
241
|
+
});
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Register the tool provider in the console, then attach it to a route with an allowlist:
|
|
245
|
+
|
|
246
|
+
```json
|
|
247
|
+
{
|
|
248
|
+
"sources": [{
|
|
249
|
+
"provider": "order-tools",
|
|
250
|
+
"allow": ["order.*"],
|
|
251
|
+
"subject_field": "operator_uid"
|
|
252
|
+
}],
|
|
253
|
+
"max_calls": 5
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Security Rule
|
|
258
|
+
|
|
259
|
+
Tool authorization is two-step:
|
|
260
|
+
|
|
261
|
+
```text
|
|
262
|
+
BailingHub controls reach.
|
|
263
|
+
Your business system controls authority.
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
The hub decides which tools the agent can see and call. The business system still verifies:
|
|
267
|
+
|
|
268
|
+
- HMAC signature
|
|
269
|
+
- timestamp window
|
|
270
|
+
- `X-Bailing-On-Behalf-Of`
|
|
271
|
+
- its own permission table
|
|
272
|
+
|
|
273
|
+
Never treat a valid signature as business authorization.
|
|
274
|
+
|
|
275
|
+
## Before Production
|
|
276
|
+
|
|
277
|
+
Check at least:
|
|
278
|
+
|
|
279
|
+
- `BAILING_ENV=production`
|
|
280
|
+
- all secrets come from environment variables or a secret manager
|
|
281
|
+
- MySQL is used instead of local jsonl state
|
|
282
|
+
- each business system has its own client token
|
|
283
|
+
- route allowlists are minimal
|
|
284
|
+
- tool providers only expose selected APIs
|
|
285
|
+
- write tools have risk/approval policies
|
|
286
|
+
- business APIs verify signatures and run their own authorization
|
|
287
|
+
- audit retention is configured according to your compliance requirements
|
|
288
|
+
- admin tokens and model keys are rotated before going live
|
|
289
|
+
|
|
290
|
+
## More
|
|
291
|
+
|
|
292
|
+
- [Chinese Quickstart](QUICKSTART.md)
|
|
293
|
+
- [Docker Demo](DEMO.en.md)
|
|
294
|
+
- [Contract](CONTRACT.en.md)
|
|
295
|
+
- [Tool Model](TOOLS_MODEL.en.md)
|
|
296
|
+
- [Tool Governance](TOOLS_DESIGN.en.md)
|
|
297
|
+
- [AI-Friendly Tool Design](AI_FRIENDLY_TOOLS.en.md)
|