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,314 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import test from 'node:test';
|
|
6
|
+
import { loadConfig } from './config';
|
|
7
|
+
|
|
8
|
+
const ENV_KEYS = [
|
|
9
|
+
'BAILING_ENV',
|
|
10
|
+
'NODE_ENV',
|
|
11
|
+
'BAILING_HOST',
|
|
12
|
+
'BAILING_PORT',
|
|
13
|
+
'BAILING_TOKEN',
|
|
14
|
+
'BAILING_STATE_BACKEND',
|
|
15
|
+
'BAILING_MYSQL_HOST',
|
|
16
|
+
'BAILING_MYSQL_PORT',
|
|
17
|
+
'BAILING_MYSQL_DATABASE',
|
|
18
|
+
'BAILING_MYSQL_USER',
|
|
19
|
+
'BAILING_MYSQL_PASSWORD',
|
|
20
|
+
'BAILING_LLM_CREDENTIALS_JSON',
|
|
21
|
+
'BAILING_ALERTS_TYPE',
|
|
22
|
+
'BAILING_ALERTS_TO',
|
|
23
|
+
'BAILING_ALERTS_URL',
|
|
24
|
+
'BAILING_ALERTS_COOLDOWN_MIN',
|
|
25
|
+
'BAILING_METRICS_ENABLED',
|
|
26
|
+
'BAILING_METRICS_TOKEN',
|
|
27
|
+
'BAILING_METRICS_SCRAPE_TIMEOUT_MS',
|
|
28
|
+
'BAILING_TOOL_INDEX_LOAD_TIMEOUT_MS',
|
|
29
|
+
'BAILING_TOOL_QUERY_EMBEDDING_TIMEOUT_MS',
|
|
30
|
+
'BAILING_BOOTSTRAP_ADMIN_USERNAME',
|
|
31
|
+
'BAILING_BOOTSTRAP_ADMIN_PASSWORD',
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
function withTempConfig(config: Record<string, unknown>, env: Record<string, string | undefined>, fn: () => void): void {
|
|
35
|
+
const cwd = process.cwd();
|
|
36
|
+
const saved: Record<string, string | undefined> = {};
|
|
37
|
+
for (const key of ENV_KEYS) {
|
|
38
|
+
saved[key] = process.env[key];
|
|
39
|
+
delete process.env[key];
|
|
40
|
+
}
|
|
41
|
+
const dir = mkdtempSync(join(tmpdir(), 'bailing-config-'));
|
|
42
|
+
try {
|
|
43
|
+
writeFileSync(join(dir, 'config.json'), JSON.stringify(config, null, 2));
|
|
44
|
+
for (const [key, value] of Object.entries(env)) {
|
|
45
|
+
if (value === undefined) delete process.env[key];
|
|
46
|
+
else process.env[key] = value;
|
|
47
|
+
}
|
|
48
|
+
process.chdir(dir);
|
|
49
|
+
fn();
|
|
50
|
+
} finally {
|
|
51
|
+
process.chdir(cwd);
|
|
52
|
+
for (const key of ENV_KEYS) {
|
|
53
|
+
if (saved[key] === undefined) delete process.env[key];
|
|
54
|
+
else process.env[key] = saved[key];
|
|
55
|
+
}
|
|
56
|
+
rmSync(dir, { recursive: true, force: true });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
test('loadConfig: 生产模式拒绝 config.json 中的明文敏感项', () => {
|
|
61
|
+
withTempConfig({
|
|
62
|
+
server: { token: 'plain-token' },
|
|
63
|
+
state: {
|
|
64
|
+
backend: 'mysql',
|
|
65
|
+
mysql: { host: 'db.example.com', database: 'bailing', user: 'root', password: 'plain-password' },
|
|
66
|
+
},
|
|
67
|
+
}, { BAILING_ENV: 'production' }, () => {
|
|
68
|
+
assert.throws(
|
|
69
|
+
() => loadConfig(),
|
|
70
|
+
/生产模式禁止在 config\.json 写入敏感配置/,
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('loadConfig: 生产敏感项可完全由环境变量注入', () => {
|
|
76
|
+
withTempConfig({
|
|
77
|
+
server: { token: 'REPLACE_ME' },
|
|
78
|
+
state: {
|
|
79
|
+
backend: 'mysql',
|
|
80
|
+
mysql: { host: 'REPLACE_ME', database: 'REPLACE_ME', user: 'REPLACE_ME', password: 'REPLACE_ME' },
|
|
81
|
+
},
|
|
82
|
+
llm_credentials: {
|
|
83
|
+
main: { base_url: 'https://example.invalid', api_key: 'REPLACE_ME' },
|
|
84
|
+
},
|
|
85
|
+
}, {
|
|
86
|
+
BAILING_ENV: 'production',
|
|
87
|
+
BAILING_TOKEN: 'env-token-that-is-long-and-random-123',
|
|
88
|
+
BAILING_STATE_BACKEND: 'mysql',
|
|
89
|
+
BAILING_MYSQL_HOST: '127.0.0.1',
|
|
90
|
+
BAILING_MYSQL_PORT: '3307',
|
|
91
|
+
BAILING_MYSQL_DATABASE: 'bailinghub',
|
|
92
|
+
BAILING_MYSQL_USER: 'bailing',
|
|
93
|
+
BAILING_MYSQL_PASSWORD: 'secret',
|
|
94
|
+
BAILING_LLM_CREDENTIALS_JSON: '{"main":{"base_url":"https://llm.example.com","api_key":"sk-env"}}',
|
|
95
|
+
BAILING_ALERTS_TYPE: 'webhook',
|
|
96
|
+
BAILING_ALERTS_URL: 'https://alert.example.com/hook',
|
|
97
|
+
BAILING_ALERTS_COOLDOWN_MIN: '5',
|
|
98
|
+
}, () => {
|
|
99
|
+
const cfg = loadConfig();
|
|
100
|
+
assert.equal(cfg.env, 'production');
|
|
101
|
+
assert.equal(cfg.server.token, 'env-token-that-is-long-and-random-123');
|
|
102
|
+
assert.equal(cfg.state.mysql.host, '127.0.0.1');
|
|
103
|
+
assert.equal(cfg.state.mysql.port, 3307);
|
|
104
|
+
assert.equal(cfg.state.mysql.database, 'bailinghub');
|
|
105
|
+
assert.deepEqual(cfg.llmCredentials.main, { base_url: 'https://llm.example.com', api_key: 'sk-env' });
|
|
106
|
+
assert.equal(cfg.alerts?.type, 'webhook');
|
|
107
|
+
assert.equal(cfg.alerts?.url, 'https://alert.example.com/hook');
|
|
108
|
+
assert.equal(cfg.alerts?.cooldown_min, 5);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('loadConfig: NODE_ENV 不会隐式开启生产密钥闸', () => {
|
|
113
|
+
withTempConfig({
|
|
114
|
+
server: { token: 'local-token' },
|
|
115
|
+
state: { backend: 'jsonl' },
|
|
116
|
+
}, { NODE_ENV: 'production' }, () => {
|
|
117
|
+
const cfg = loadConfig();
|
|
118
|
+
assert.equal(cfg.env, 'development');
|
|
119
|
+
assert.equal(cfg.server.token, 'local-token');
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('loadConfig: 本地回环开发允许不配置 token', () => {
|
|
124
|
+
withTempConfig({
|
|
125
|
+
server: { host: '127.0.0.1', token: '' },
|
|
126
|
+
state: { backend: 'jsonl' },
|
|
127
|
+
}, { BAILING_ENV: 'development' }, () => {
|
|
128
|
+
const cfg = loadConfig();
|
|
129
|
+
assert.equal(cfg.server.token, '');
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('loadConfig: Kernel Host 从已安装 Core 制品加载默认值,不依赖或信任 consumer cwd', () => {
|
|
134
|
+
withTempConfig({
|
|
135
|
+
brand: { name: 'consumer-cwd-must-not-be-read' },
|
|
136
|
+
server: { host: '0.0.0.0', token: 'consumer-secret' },
|
|
137
|
+
state: { backend: 'mysql', mysql: { host: 'consumer-db', password: 'consumer-password' } },
|
|
138
|
+
}, {}, () => {
|
|
139
|
+
const consumerCwd = process.cwd();
|
|
140
|
+
const cfg = loadConfig({ mode: 'kernel-host' });
|
|
141
|
+
assert.notEqual(cfg.root, consumerCwd);
|
|
142
|
+
assert.notEqual(cfg.brand.name, 'consumer-cwd-must-not-be-read');
|
|
143
|
+
assert.equal(cfg.server.token, '');
|
|
144
|
+
assert.deepEqual(cfg.state.mysql, {
|
|
145
|
+
host: '', port: 3306, database: '', user: '', password: '', connectionLimit: 1,
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('loadConfig: 非回环开发监听缺少 token 时拒绝启动', () => {
|
|
151
|
+
withTempConfig({
|
|
152
|
+
server: { host: '0.0.0.0', token: '' },
|
|
153
|
+
state: { backend: 'jsonl' },
|
|
154
|
+
}, { BAILING_ENV: 'development' }, () => {
|
|
155
|
+
assert.throws(() => loadConfig(), /BAILING_TOKEN 未配置/);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('loadConfig: 生产模式拒绝公开示例 token', () => {
|
|
160
|
+
withTempConfig({
|
|
161
|
+
server: { token: 'REPLACE_ME' },
|
|
162
|
+
state: { backend: 'jsonl' },
|
|
163
|
+
}, {
|
|
164
|
+
BAILING_ENV: 'production',
|
|
165
|
+
BAILING_TOKEN: 'bailing-dev-admin-token-change-me',
|
|
166
|
+
}, () => {
|
|
167
|
+
assert.throws(() => loadConfig(), /BAILING_TOKEN 不安全/);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('loadConfig: 首次管理员变量缺失时保持禁用', () => {
|
|
172
|
+
withTempConfig({
|
|
173
|
+
server: { host: '127.0.0.1', token: '' },
|
|
174
|
+
state: { backend: 'jsonl' },
|
|
175
|
+
}, { BAILING_ENV: 'development' }, () => {
|
|
176
|
+
const cfg = loadConfig();
|
|
177
|
+
assert.equal(cfg.bootstrapAdmin, null);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('loadConfig: metrics 默认关闭且启用时要求独立强令牌', () => {
|
|
182
|
+
const config = {
|
|
183
|
+
server: { host: '127.0.0.1', token: 'server-only-token-with-enough-entropy-2026' },
|
|
184
|
+
state: { backend: 'jsonl' },
|
|
185
|
+
};
|
|
186
|
+
withTempConfig(config, {}, () => {
|
|
187
|
+
assert.deepEqual(loadConfig().metrics, {
|
|
188
|
+
enabled: false,
|
|
189
|
+
token: '',
|
|
190
|
+
scrapeTimeoutMs: 5000,
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
withTempConfig(config, { BAILING_METRICS_ENABLED: 'true' }, () => {
|
|
194
|
+
assert.throws(() => loadConfig(), /BAILING_METRICS_TOKEN 不安全/);
|
|
195
|
+
});
|
|
196
|
+
withTempConfig(config, {
|
|
197
|
+
BAILING_METRICS_ENABLED: 'true',
|
|
198
|
+
BAILING_METRICS_TOKEN: 'server-only-token-with-enough-entropy-2026',
|
|
199
|
+
}, () => {
|
|
200
|
+
assert.throws(() => loadConfig(), /必须与 BAILING_TOKEN 分离/);
|
|
201
|
+
});
|
|
202
|
+
withTempConfig(config, {
|
|
203
|
+
BAILING_METRICS_ENABLED: 'true',
|
|
204
|
+
BAILING_METRICS_TOKEN: 'metrics-only-token-with-enough-entropy-2026',
|
|
205
|
+
BAILING_METRICS_SCRAPE_TIMEOUT_MS: '750',
|
|
206
|
+
}, () => {
|
|
207
|
+
assert.deepEqual(loadConfig().metrics, {
|
|
208
|
+
enabled: true,
|
|
209
|
+
token: 'metrics-only-token-with-enough-entropy-2026',
|
|
210
|
+
scrapeTimeoutMs: 750,
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test('loadConfig: metrics 配置拒绝模糊布尔值和越界超时', () => {
|
|
216
|
+
const config = { server: { host: '127.0.0.1', token: '' }, state: { backend: 'jsonl' } };
|
|
217
|
+
withTempConfig(config, { BAILING_METRICS_ENABLED: 'sometimes' }, () => {
|
|
218
|
+
assert.throws(() => loadConfig(), /BAILING_METRICS_ENABLED 必须是/);
|
|
219
|
+
});
|
|
220
|
+
withTempConfig(config, { BAILING_METRICS_SCRAPE_TIMEOUT_MS: '100' }, () => {
|
|
221
|
+
assert.throws(() => loadConfig(), /必须是 250~30000 的整数/);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('loadConfig: 工具检索运行保护使用安全默认值并允许部署覆盖', () => {
|
|
226
|
+
const config = { server: { host: '127.0.0.1', token: '' }, state: { backend: 'jsonl' } };
|
|
227
|
+
withTempConfig(config, {}, () => {
|
|
228
|
+
assert.deepEqual(loadConfig().toolRetrieval, {
|
|
229
|
+
indexLoadTimeoutMs: 5000,
|
|
230
|
+
embeddingTimeoutMs: 15_000,
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
withTempConfig(config, {
|
|
234
|
+
BAILING_TOOL_INDEX_LOAD_TIMEOUT_MS: '1200',
|
|
235
|
+
BAILING_TOOL_QUERY_EMBEDDING_TIMEOUT_MS: '8000',
|
|
236
|
+
}, () => {
|
|
237
|
+
assert.deepEqual(loadConfig().toolRetrieval, {
|
|
238
|
+
indexLoadTimeoutMs: 1200,
|
|
239
|
+
embeddingTimeoutMs: 8000,
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('loadConfig: 工具检索运行保护拒绝非整数与越界超时', () => {
|
|
245
|
+
const config = { server: { host: '127.0.0.1', token: '' }, state: { backend: 'jsonl' } };
|
|
246
|
+
withTempConfig(config, { BAILING_TOOL_INDEX_LOAD_TIMEOUT_MS: '99' }, () => {
|
|
247
|
+
assert.throws(() => loadConfig(), /BAILING_TOOL_INDEX_LOAD_TIMEOUT_MS 必须是 100~60000 的整数/);
|
|
248
|
+
});
|
|
249
|
+
withTempConfig(config, { BAILING_TOOL_QUERY_EMBEDDING_TIMEOUT_MS: '120000.5' }, () => {
|
|
250
|
+
assert.throws(() => loadConfig(), /BAILING_TOOL_QUERY_EMBEDDING_TIMEOUT_MS 必须是 250~120000 的整数/);
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('loadConfig: 首次管理员变量必须成对配置且不回显密码', () => {
|
|
255
|
+
const password = 'bootstrap-secret-123';
|
|
256
|
+
withTempConfig({
|
|
257
|
+
server: { host: '127.0.0.1', token: '' },
|
|
258
|
+
state: { backend: 'mysql', mysql: {} },
|
|
259
|
+
}, {
|
|
260
|
+
BAILING_ENV: 'development',
|
|
261
|
+
BAILING_BOOTSTRAP_ADMIN_USERNAME: 'initial_admin',
|
|
262
|
+
}, () => {
|
|
263
|
+
assert.throws(
|
|
264
|
+
() => loadConfig(),
|
|
265
|
+
(error: unknown) => {
|
|
266
|
+
assert.match(String(error), /必须同时配置/);
|
|
267
|
+
assert.doesNotMatch(String(error), new RegExp(password));
|
|
268
|
+
return true;
|
|
269
|
+
},
|
|
270
|
+
);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
withTempConfig({
|
|
274
|
+
server: { host: '127.0.0.1', token: '' },
|
|
275
|
+
state: { backend: 'mysql', mysql: {} },
|
|
276
|
+
}, {
|
|
277
|
+
BAILING_ENV: 'development',
|
|
278
|
+
BAILING_BOOTSTRAP_ADMIN_USERNAME: 'initial_admin',
|
|
279
|
+
BAILING_BOOTSTRAP_ADMIN_PASSWORD: password,
|
|
280
|
+
}, () => {
|
|
281
|
+
assert.deepEqual(loadConfig().bootstrapAdmin, {
|
|
282
|
+
username: 'initial_admin',
|
|
283
|
+
password,
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
test('loadConfig: 首次管理员拒绝非法用户名、短密码和非 mysql 后端', () => {
|
|
289
|
+
const base = {
|
|
290
|
+
server: { host: '127.0.0.1', token: '' },
|
|
291
|
+
state: { backend: 'mysql', mysql: {} },
|
|
292
|
+
};
|
|
293
|
+
withTempConfig(base, {
|
|
294
|
+
BAILING_BOOTSTRAP_ADMIN_USERNAME: 'invalid username',
|
|
295
|
+
BAILING_BOOTSTRAP_ADMIN_PASSWORD: 'long-enough-password',
|
|
296
|
+
}, () => {
|
|
297
|
+
assert.throws(() => loadConfig(), /仅允许 2~64 位/);
|
|
298
|
+
});
|
|
299
|
+
withTempConfig(base, {
|
|
300
|
+
BAILING_BOOTSTRAP_ADMIN_USERNAME: 'admin',
|
|
301
|
+
BAILING_BOOTSTRAP_ADMIN_PASSWORD: 'short',
|
|
302
|
+
}, () => {
|
|
303
|
+
assert.throws(() => loadConfig(), /至少 8 位/);
|
|
304
|
+
});
|
|
305
|
+
withTempConfig({
|
|
306
|
+
server: { host: '127.0.0.1', token: '' },
|
|
307
|
+
state: { backend: 'jsonl' },
|
|
308
|
+
}, {
|
|
309
|
+
BAILING_BOOTSTRAP_ADMIN_USERNAME: 'admin',
|
|
310
|
+
BAILING_BOOTSTRAP_ADMIN_PASSWORD: 'long-enough-password',
|
|
311
|
+
}, () => {
|
|
312
|
+
assert.throws(() => loadConfig(), /需要 mysql 状态后端/);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { hostname } from 'node:os';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { assertServerTokenPolicy } from '../platform/server-token';
|
|
6
|
+
import { assertMetricsTokenPolicy } from '../platform/metrics-token';
|
|
7
|
+
|
|
8
|
+
export interface MysqlConfig {
|
|
9
|
+
host: string;
|
|
10
|
+
port: number;
|
|
11
|
+
database: string;
|
|
12
|
+
user: string;
|
|
13
|
+
password: string;
|
|
14
|
+
connectionLimit: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface StateConfig {
|
|
18
|
+
backend: 'jsonl' | 'mysql';
|
|
19
|
+
jsonlPath: string;
|
|
20
|
+
mysql: MysqlConfig;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface BootstrapAdminConfig {
|
|
24
|
+
username: string;
|
|
25
|
+
password: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface MetricsConfig {
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
token: string;
|
|
31
|
+
scrapeTimeoutMs: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 工具语义检索的运行保护。这些是部署级时限,不是路由或工具提供方的业务策略。 */
|
|
35
|
+
export interface ToolRetrievalConfig {
|
|
36
|
+
indexLoadTimeoutMs: number;
|
|
37
|
+
embeddingTimeoutMs: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const DEFAULT_TOOL_RETRIEVAL_CONFIG: Readonly<ToolRetrievalConfig> = Object.freeze({
|
|
41
|
+
indexLoadTimeoutMs: 5000,
|
|
42
|
+
embeddingTimeoutMs: 15_000,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export interface LlmCredential {
|
|
46
|
+
base_url: string;
|
|
47
|
+
api_key: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 参考执行器配置:出站连到中枢,长轮询认领 targets 声明的任务。仅执行器进程用。 */
|
|
51
|
+
export interface ExecutorConfig {
|
|
52
|
+
hubUrl: string; // 中枢地址
|
|
53
|
+
token: string; // 与中枢 server.token 一致
|
|
54
|
+
executorId: string; // 执行器标识(控制台「执行器」里显示的身份)
|
|
55
|
+
targets: string[]; // 本执行器能干的 target(须先在控制台「调度目标」注册)
|
|
56
|
+
waitMs: number; // 单次长轮询挂起时长上限
|
|
57
|
+
concurrency: number; // 本参考执行器本地并发 worker 数;默认 1
|
|
58
|
+
labels: string[]; // 可选自定义标签(上报给中枢,便于在「执行器」页识别这台机器的角色)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 中枢自监控告警出口:复用送达插座(type=webhook 直发 / 其余类型 X 走注册的 X-notify 执行器)。不配 = 只记审计不外发。 */
|
|
62
|
+
export interface AlertsConfig {
|
|
63
|
+
type: string; // 'webhook' | 自定义渠道 X(由 X-notify 执行器目标承接)
|
|
64
|
+
to?: string; // 渠道收件人标识
|
|
65
|
+
url?: string; // type=webhook 时的地址
|
|
66
|
+
cooldown_min: number; // 同一告警去重冷却
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface AppConfig {
|
|
70
|
+
root: string;
|
|
71
|
+
/**
|
|
72
|
+
* 可写运行数据的根目录。缺省时与历史版本一样使用 root;嵌入式多 Kernel
|
|
73
|
+
* 宿主必须为每个租户注入不同目录,避免本地上传、暂停文件等运行数据共用。
|
|
74
|
+
* Kernel 会把历史默认 root/.paused 自动重定位到 runtimeRoot/.paused;
|
|
75
|
+
* 宿主显式传入的其他 killSwitchFile 仍保持不变。
|
|
76
|
+
*/
|
|
77
|
+
runtimeRoot?: string;
|
|
78
|
+
env: 'development' | 'production';
|
|
79
|
+
server: { host: string; port: number; token: string };
|
|
80
|
+
brand: { name: string }; // 对外产出署名(送达消息落款等),部署方可改
|
|
81
|
+
displayTz: string; // 展示时区 IANA 名(喂大脑/给人看时把 UTC 转成它),默认 Asia/Shanghai;详见 time.ts
|
|
82
|
+
displayTzLabel: string; // 展示时区友好名(如「北京时间」),仅用于标注文案;偏移 UTC±N 由 time.ts 动态算
|
|
83
|
+
auditRetentionDays: number; // bz_audit 保留天数;0=不自动删除
|
|
84
|
+
alerts: AlertsConfig | null;
|
|
85
|
+
metrics: MetricsConfig;
|
|
86
|
+
/** loadConfig 始终补齐;保留 optional 让旧版扩展注入的 AppConfig 继续兼容。 */
|
|
87
|
+
toolRetrieval?: ToolRetrievalConfig;
|
|
88
|
+
bootstrapAdmin: BootstrapAdminConfig | null;
|
|
89
|
+
concurrency: number;
|
|
90
|
+
killSwitchFile: string;
|
|
91
|
+
claudeBin: string;
|
|
92
|
+
defaultProfile: string;
|
|
93
|
+
brainDir: string;
|
|
94
|
+
state: StateConfig;
|
|
95
|
+
projects: Record<string, string>;
|
|
96
|
+
llmCredentials: Record<string, LlmCredential>; // llm 凭据,按名引用,不落 DB/admin
|
|
97
|
+
executor: ExecutorConfig; // Mac 执行器进程用(server 进程忽略)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface LoadConfigOptions {
|
|
101
|
+
/** Embedded hosts receive only process-level defaults; each Kernel injects its own state identity. */
|
|
102
|
+
mode?: 'standalone' | 'kernel-host';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const CORE_ARTIFACT_ROOT = fileURLToPath(new URL('../../../', import.meta.url));
|
|
106
|
+
|
|
107
|
+
function envName(v: unknown): 'development' | 'production' {
|
|
108
|
+
return String(v ?? '').toLowerCase() === 'production' ? 'production' : 'development';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function envJson(name: string): Record<string, any> {
|
|
112
|
+
const raw = process.env[name];
|
|
113
|
+
if (!raw) return {};
|
|
114
|
+
try {
|
|
115
|
+
const parsed = JSON.parse(raw);
|
|
116
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed as Record<string, any> : {};
|
|
117
|
+
} catch (e) {
|
|
118
|
+
throw new Error(`${name} 必须是 JSON 对象`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function isPlaceholder(v: unknown): boolean {
|
|
123
|
+
const s = String(v ?? '').trim();
|
|
124
|
+
return !s || s === 'REPLACE_ME' || s.includes('REPLACE_ME') || s.startsWith('_example_');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function rawSensitive(raw: Record<string, any>, path: string): unknown {
|
|
128
|
+
let cur: any = raw;
|
|
129
|
+
for (const part of path.split('.')) cur = cur?.[part];
|
|
130
|
+
return cur;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function assertNoRawSecrets(raw: Record<string, any>, sourceFile: string, paths: string[]): void {
|
|
134
|
+
const bad = paths.filter((p) => !isPlaceholder(rawSensitive(raw, p)));
|
|
135
|
+
if (bad.length) {
|
|
136
|
+
throw new Error(`生产模式禁止在 ${sourceFile} 写入敏感配置:${bad.join(', ')}。请改用环境变量或密钥管理器。`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function requiredEnv(name: string): string {
|
|
141
|
+
const v = String(process.env[name] ?? '').trim();
|
|
142
|
+
if (!v) throw new Error(`生产模式缺少环境变量 ${name}`);
|
|
143
|
+
return v;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function booleanEnv(name: string, fallback = false): boolean {
|
|
147
|
+
const raw = process.env[name];
|
|
148
|
+
if (raw === undefined || raw.trim() === '') return fallback;
|
|
149
|
+
const value = raw.trim().toLowerCase();
|
|
150
|
+
if (['1', 'true', 'yes', 'on'].includes(value)) return true;
|
|
151
|
+
if (['0', 'false', 'no', 'off'].includes(value)) return false;
|
|
152
|
+
throw new Error(`${name} 必须是 true/false、1/0、yes/no 或 on/off`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function boundedIntegerEnv(name: string, fallback: number, min: number, max: number): number {
|
|
156
|
+
const raw = process.env[name];
|
|
157
|
+
if (raw === undefined || raw.trim() === '') return fallback;
|
|
158
|
+
const value = Number(raw);
|
|
159
|
+
if (!Number.isInteger(value) || value < min || value > max) {
|
|
160
|
+
throw new Error(`${name} 必须是 ${min}~${max} 的整数`);
|
|
161
|
+
}
|
|
162
|
+
return value;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function bootstrapAdminFromEnv(env: NodeJS.ProcessEnv): BootstrapAdminConfig | null {
|
|
166
|
+
const username = String(env['BAILING_BOOTSTRAP_ADMIN_USERNAME'] ?? '').trim();
|
|
167
|
+
const password = String(env['BAILING_BOOTSTRAP_ADMIN_PASSWORD'] ?? '');
|
|
168
|
+
const hasUsername = username.length > 0;
|
|
169
|
+
const hasPassword = password.length > 0;
|
|
170
|
+
if (!hasUsername && !hasPassword) return null;
|
|
171
|
+
if (!hasUsername || !hasPassword) {
|
|
172
|
+
throw new Error('BAILING_BOOTSTRAP_ADMIN_USERNAME 与 BAILING_BOOTSTRAP_ADMIN_PASSWORD 必须同时配置');
|
|
173
|
+
}
|
|
174
|
+
if (!/^[a-z0-9][a-z0-9_-]{1,63}$/i.test(username)) {
|
|
175
|
+
throw new Error('BAILING_BOOTSTRAP_ADMIN_USERNAME 仅允许 2~64 位字母、数字、中划线或下划线,且必须以字母或数字开头');
|
|
176
|
+
}
|
|
177
|
+
if (password.length < 8) {
|
|
178
|
+
throw new Error('BAILING_BOOTSTRAP_ADMIN_PASSWORD 至少 8 位');
|
|
179
|
+
}
|
|
180
|
+
return { username, password };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Standalone 模式从当前部署目录读取 config.json;Kernel Host 模式只读已安装
|
|
185
|
+
* Core 制品内的安全默认。这样宿主 cwd 不会被误当成 Core 制品根或配置根。
|
|
186
|
+
*/
|
|
187
|
+
export function loadConfig(options: LoadConfigOptions = {}): AppConfig {
|
|
188
|
+
const root = options.mode === 'kernel-host' ? CORE_ARTIFACT_ROOT : process.cwd();
|
|
189
|
+
const file = options.mode === 'kernel-host'
|
|
190
|
+
? 'config.example.json'
|
|
191
|
+
: existsSync(resolve(root, 'config.json')) ? 'config.json' : 'config.example.json';
|
|
192
|
+
const raw = JSON.parse(readFileSync(resolve(root, file), 'utf8')) as Record<string, any>;
|
|
193
|
+
const env = process.env;
|
|
194
|
+
const runtimeEnv = envName(env['BAILING_ENV']);
|
|
195
|
+
const llmEnv = envJson('BAILING_LLM_CREDENTIALS_JSON');
|
|
196
|
+
const rawAlerts = (raw['alerts'] ?? {}) as Record<string, any>;
|
|
197
|
+
const alertType = env['BAILING_ALERTS_TYPE'] ?? rawAlerts.type;
|
|
198
|
+
const productionRawSecrets = [
|
|
199
|
+
'server.token',
|
|
200
|
+
'state.mysql.host',
|
|
201
|
+
'state.mysql.database',
|
|
202
|
+
'state.mysql.user',
|
|
203
|
+
'state.mysql.password',
|
|
204
|
+
'executor.token',
|
|
205
|
+
'alerts.url',
|
|
206
|
+
];
|
|
207
|
+
for (const name of Object.keys(raw['llm_credentials'] ?? {})) {
|
|
208
|
+
productionRawSecrets.push(`llm_credentials.${name}.api_key`);
|
|
209
|
+
}
|
|
210
|
+
if (runtimeEnv === 'production' && file === 'config.json') {
|
|
211
|
+
assertNoRawSecrets(raw, file, productionRawSecrets);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const cfg: AppConfig = {
|
|
215
|
+
root,
|
|
216
|
+
env: runtimeEnv,
|
|
217
|
+
server: {
|
|
218
|
+
host: env['BAILING_HOST'] ?? raw['server']?.host ?? '127.0.0.1',
|
|
219
|
+
port: Number(env['BAILING_PORT'] ?? raw['server']?.port ?? 18900),
|
|
220
|
+
token: String(env['BAILING_TOKEN'] ?? raw['server']?.token ?? '').trim(),
|
|
221
|
+
},
|
|
222
|
+
brand: { name: String(raw['brand']?.name ?? '百灵中枢') },
|
|
223
|
+
displayTz: String(env['BAILING_DISPLAY_TZ'] ?? raw['display_tz'] ?? 'Asia/Shanghai'),
|
|
224
|
+
displayTzLabel: String(env['BAILING_DISPLAY_TZ_LABEL'] ?? raw['display_tz_label'] ?? '北京时间'),
|
|
225
|
+
auditRetentionDays: Math.max(0, Number(env['BAILING_AUDIT_RETENTION_DAYS'] ?? raw['audit_retention_days'] ?? 0) || 0),
|
|
226
|
+
alerts: alertType
|
|
227
|
+
? {
|
|
228
|
+
type: String(alertType),
|
|
229
|
+
to: env['BAILING_ALERTS_TO'] ? String(env['BAILING_ALERTS_TO']) : rawAlerts.to ? String(rawAlerts.to) : undefined,
|
|
230
|
+
url: env['BAILING_ALERTS_URL'] ? String(env['BAILING_ALERTS_URL']) : rawAlerts.url ? String(rawAlerts.url) : undefined,
|
|
231
|
+
cooldown_min: Number(env['BAILING_ALERTS_COOLDOWN_MIN'] ?? rawAlerts.cooldown_min ?? 60) || 60,
|
|
232
|
+
}
|
|
233
|
+
: null,
|
|
234
|
+
metrics: {
|
|
235
|
+
enabled: booleanEnv('BAILING_METRICS_ENABLED'),
|
|
236
|
+
token: String(env['BAILING_METRICS_TOKEN'] ?? '').trim(),
|
|
237
|
+
scrapeTimeoutMs: boundedIntegerEnv('BAILING_METRICS_SCRAPE_TIMEOUT_MS', 5000, 250, 30_000),
|
|
238
|
+
},
|
|
239
|
+
toolRetrieval: {
|
|
240
|
+
indexLoadTimeoutMs: boundedIntegerEnv('BAILING_TOOL_INDEX_LOAD_TIMEOUT_MS', DEFAULT_TOOL_RETRIEVAL_CONFIG.indexLoadTimeoutMs, 100, 60_000),
|
|
241
|
+
embeddingTimeoutMs: boundedIntegerEnv('BAILING_TOOL_QUERY_EMBEDDING_TIMEOUT_MS', DEFAULT_TOOL_RETRIEVAL_CONFIG.embeddingTimeoutMs, 250, 120_000),
|
|
242
|
+
},
|
|
243
|
+
bootstrapAdmin: bootstrapAdminFromEnv(env),
|
|
244
|
+
concurrency: Number(raw['concurrency'] ?? 2),
|
|
245
|
+
killSwitchFile: resolve(root, raw['killSwitchFile'] ?? '.paused'),
|
|
246
|
+
claudeBin: raw['claudeBin'] ?? 'claude',
|
|
247
|
+
defaultProfile: raw['defaultProfile'] ?? 'readonly',
|
|
248
|
+
brainDir: resolve(root, raw['brainDir'] ?? 'brain'),
|
|
249
|
+
state: {
|
|
250
|
+
backend: (env['BAILING_STATE_BACKEND'] ?? raw['state']?.backend ?? 'jsonl') as 'jsonl' | 'mysql',
|
|
251
|
+
jsonlPath: resolve(root, raw['state']?.jsonlPath ?? 'data/jobs.jsonl'),
|
|
252
|
+
mysql: {
|
|
253
|
+
host: env['BAILING_MYSQL_HOST'] ?? raw['state']?.mysql?.host ?? '',
|
|
254
|
+
port: Number(env['BAILING_MYSQL_PORT'] ?? raw['state']?.mysql?.port ?? 3306),
|
|
255
|
+
database: env['BAILING_MYSQL_DATABASE'] ?? raw['state']?.mysql?.database ?? 'bailing_zhongshu',
|
|
256
|
+
user: env['BAILING_MYSQL_USER'] ?? raw['state']?.mysql?.user ?? '',
|
|
257
|
+
password: env['BAILING_MYSQL_PASSWORD'] ?? raw['state']?.mysql?.password ?? '',
|
|
258
|
+
connectionLimit: Number(env['BAILING_MYSQL_CONNECTION_LIMIT'] ?? raw['state']?.mysql?.connection_limit ?? 15) || 15,
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
projects: {},
|
|
262
|
+
llmCredentials: {},
|
|
263
|
+
executor: {
|
|
264
|
+
hubUrl: env['BAILING_HUB_URL'] ?? raw['executor']?.hub_url ?? '',
|
|
265
|
+
token: env['BAILING_EXECUTOR_TOKEN'] ?? raw['executor']?.token ?? raw['server']?.token ?? '',
|
|
266
|
+
executorId: env['BAILING_EXECUTOR_ID'] ?? raw['executor']?.executor_id ?? hostname(),
|
|
267
|
+
targets: Array.isArray(raw['executor']?.targets) ? raw['executor'].targets.map(String) : [],
|
|
268
|
+
waitMs: Number(raw['executor']?.wait_ms ?? 25000),
|
|
269
|
+
concurrency: Math.max(1, Number(env['BAILING_EXECUTOR_CONCURRENCY'] ?? raw['executor']?.concurrency ?? 1) || 1),
|
|
270
|
+
labels: Array.isArray(raw['executor']?.labels) ? raw['executor'].labels.map(String) : [],
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const projects = (raw['projects'] ?? {}) as Record<string, string>;
|
|
275
|
+
for (const name of Object.keys(projects)) {
|
|
276
|
+
if (name.startsWith('_')) continue; // 下划线开头为示例占位
|
|
277
|
+
cfg.projects[name] = resolve(root, String(projects[name]));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const creds = { ...((raw['llm_credentials'] ?? {}) as Record<string, any>), ...llmEnv };
|
|
281
|
+
for (const name of Object.keys(creds)) {
|
|
282
|
+
if (name.startsWith('_')) continue;
|
|
283
|
+
cfg.llmCredentials[name] = {
|
|
284
|
+
base_url: String(creds[name]?.base_url ?? ''),
|
|
285
|
+
api_key: String(creds[name]?.api_key ?? ''),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
if (options.mode === 'kernel-host') {
|
|
289
|
+
// A multi-Kernel host must not accidentally retain the standalone Core
|
|
290
|
+
// database identity, local admin bootstrap, project paths or LLM secrets.
|
|
291
|
+
cfg.state = {
|
|
292
|
+
backend: 'jsonl',
|
|
293
|
+
jsonlPath: resolve(root, 'data', 'kernel-host-unused.jsonl'),
|
|
294
|
+
mysql: { host: '', port: 3306, database: '', user: '', password: '', connectionLimit: 1 },
|
|
295
|
+
};
|
|
296
|
+
cfg.server = { ...cfg.server, token: '' };
|
|
297
|
+
cfg.bootstrapAdmin = null;
|
|
298
|
+
cfg.projects = {};
|
|
299
|
+
cfg.llmCredentials = {};
|
|
300
|
+
cfg.alerts = null;
|
|
301
|
+
cfg.metrics = { ...cfg.metrics, enabled: false, token: '' };
|
|
302
|
+
cfg.executor = { ...cfg.executor, hubUrl: '', token: '', executorId: '', targets: [], labels: [] };
|
|
303
|
+
}
|
|
304
|
+
if (options.mode !== 'kernel-host') {
|
|
305
|
+
assertServerTokenPolicy({ env: cfg.env, host: cfg.server.host, token: cfg.server.token });
|
|
306
|
+
}
|
|
307
|
+
assertMetricsTokenPolicy({
|
|
308
|
+
enabled: cfg.metrics.enabled,
|
|
309
|
+
token: cfg.metrics.token,
|
|
310
|
+
serverToken: cfg.server.token,
|
|
311
|
+
});
|
|
312
|
+
if (cfg.bootstrapAdmin && cfg.state.backend !== 'mysql') {
|
|
313
|
+
throw new Error('首次管理员初始化需要 mysql 状态后端');
|
|
314
|
+
}
|
|
315
|
+
if (cfg.env === 'production' && options.mode !== 'kernel-host') {
|
|
316
|
+
if (cfg.state.backend === 'mysql') {
|
|
317
|
+
requiredEnv('BAILING_MYSQL_HOST');
|
|
318
|
+
requiredEnv('BAILING_MYSQL_DATABASE');
|
|
319
|
+
requiredEnv('BAILING_MYSQL_USER');
|
|
320
|
+
requiredEnv('BAILING_MYSQL_PASSWORD');
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return cfg;
|
|
324
|
+
}
|