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,408 @@
|
|
|
1
|
+
// 边界契约的类型定义。改动须与 docs/CONTRACT.md 同步,且按兼容方式演进。
|
|
2
|
+
|
|
3
|
+
/** 会话目标:续聊已有会话(isContinue) 还是用指定 id 开新会话 */
|
|
4
|
+
export interface SessionTarget {
|
|
5
|
+
sessionId: string;
|
|
6
|
+
isContinue: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const JOB_STATUSES = ['queued', 'running', 'dispatched', 'done', 'error', 'rejected'] as const;
|
|
10
|
+
export const TERMINAL_JOB_STATUSES = ['done', 'error', 'rejected'] as const;
|
|
11
|
+
export type JobStatus = (typeof JOB_STATUSES)[number];
|
|
12
|
+
|
|
13
|
+
/** 调查任务(单一真值源) */
|
|
14
|
+
export interface Job {
|
|
15
|
+
job_id: string;
|
|
16
|
+
request_id: string;
|
|
17
|
+
status: JobStatus;
|
|
18
|
+
target?: string;
|
|
19
|
+
profile: string;
|
|
20
|
+
project: string;
|
|
21
|
+
source: string;
|
|
22
|
+
client_app_id?: string; // 触发方 app_id(admin token 触发为空)
|
|
23
|
+
thread_id?: number; // 对话线索(总账),finish 时回写 out 消息
|
|
24
|
+
session_id?: string;
|
|
25
|
+
input_preview: string;
|
|
26
|
+
input?: string; // 完整输入(远端执行器认领时回传给执行器)
|
|
27
|
+
report?: Record<string, unknown>; // 结构化结论(structuredOutput 能力档产出;schema 由该档的提示词约定)
|
|
28
|
+
raw_result?: string;
|
|
29
|
+
result?: Record<string, unknown>; // 适配器统一输出({text} 或 {report})
|
|
30
|
+
usage?: { duration_ms?: number; num_turns?: number; cost_usd?: number; tokens?: number };
|
|
31
|
+
error?: string;
|
|
32
|
+
metadata: Record<string, unknown>;
|
|
33
|
+
callback_url?: string;
|
|
34
|
+
// 远端执行器派活相关(含 route 快照:route 之后可能改/删,故落到 job 上);kb_refs=知识检索命中快照(引用来源回流)
|
|
35
|
+
// user_images/user_audio/user_files=用户原始输入里的媒体 URL 快照(只取用户发的,不含知识库注入资产);多模态适配器据此送模型,rerun 也能复现
|
|
36
|
+
dispatch?: { target_config?: Record<string, unknown>; is_continue?: boolean; delivery?: Record<string, unknown>; route_key?: string; route_name?: string; retry?: Record<string, unknown>; tools?: Record<string, unknown>; memory?: Record<string, unknown>; kb_refs?: Array<{ seq: number; doc_id: number; title: string; score: number; snippet: string }>; user_images?: string[]; user_audio?: string[]; user_files?: Array<{ url: string; name?: string }> };
|
|
37
|
+
attempts?: number; // 已重试次数
|
|
38
|
+
run_after?: string; // queued 可被认领的最早时间(重试退避 / 延迟调度)
|
|
39
|
+
claimed_at?: string; // 最近一次被 worker/executor 原子认领的时间
|
|
40
|
+
lease_until?: string; // 当前认领租约到期时间;到期未续租则可恢复回队列
|
|
41
|
+
executor_id?: string;
|
|
42
|
+
dispatched_at?: string;
|
|
43
|
+
claim_token?: string;
|
|
44
|
+
created_at: string;
|
|
45
|
+
updated_at: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 业务触发请求体 */
|
|
49
|
+
export interface RunRequest {
|
|
50
|
+
request_id: string;
|
|
51
|
+
input: string;
|
|
52
|
+
project?: string; // 显式指定项目(与 route 二选一)
|
|
53
|
+
route?: string; // 触发路由 key(由 bz_routes 配置解析出 project/session/profile)
|
|
54
|
+
profile?: string;
|
|
55
|
+
source?: string;
|
|
56
|
+
metadata?: Record<string, unknown>;
|
|
57
|
+
callback_url?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 中枢标准主体:业务侧声明“代表谁操作”,中枢归一后只认这个形状。 */
|
|
61
|
+
export interface NormalizedPrincipal {
|
|
62
|
+
id: string;
|
|
63
|
+
tenant?: string;
|
|
64
|
+
roles: string[];
|
|
65
|
+
audience?: string;
|
|
66
|
+
channel?: string;
|
|
67
|
+
client_app_id?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 路由受众策略:决定某个主体能否进入该路由,以及 route=auto 是否可把请求分到这里。 */
|
|
71
|
+
export interface AudiencePolicy {
|
|
72
|
+
enabled?: boolean;
|
|
73
|
+
auto?: boolean;
|
|
74
|
+
priority?: number;
|
|
75
|
+
keywords?: string[];
|
|
76
|
+
clients?: string[];
|
|
77
|
+
channels?: string[];
|
|
78
|
+
tenants?: string[];
|
|
79
|
+
roles?: string[];
|
|
80
|
+
principals?: string[];
|
|
81
|
+
audiences?: string[];
|
|
82
|
+
anonymous?: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type TraceStage =
|
|
86
|
+
| 'launch'
|
|
87
|
+
| 'context'
|
|
88
|
+
| 'execution'
|
|
89
|
+
| 'tool'
|
|
90
|
+
| 'approval'
|
|
91
|
+
| 'delivery'
|
|
92
|
+
| 'summary'
|
|
93
|
+
| 'recovery'
|
|
94
|
+
| 'channel'
|
|
95
|
+
| 'config'
|
|
96
|
+
| 'system';
|
|
97
|
+
|
|
98
|
+
export type TraceSeverity = 'info' | 'warning' | 'error';
|
|
99
|
+
|
|
100
|
+
export interface AuditEntry {
|
|
101
|
+
ts: string;
|
|
102
|
+
job_id: string;
|
|
103
|
+
request_id: string;
|
|
104
|
+
event: string;
|
|
105
|
+
stage?: TraceStage;
|
|
106
|
+
severity?: TraceSeverity;
|
|
107
|
+
title?: string;
|
|
108
|
+
summary?: string;
|
|
109
|
+
detail: Record<string, unknown>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ---- web 后台管理的配置(DB 驱动,非文件写死)----
|
|
113
|
+
|
|
114
|
+
/** 项目目录注册(哪个项目名 → Mac 上哪个绝对目录) */
|
|
115
|
+
export interface ProjectReg {
|
|
116
|
+
name: string;
|
|
117
|
+
path: string;
|
|
118
|
+
enabled: boolean;
|
|
119
|
+
description?: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** 接入方:业务系统的凭证与策略(开放接入模型,每方一把可吊销的钥匙) */
|
|
123
|
+
export interface Client {
|
|
124
|
+
app_id: string;
|
|
125
|
+
name: string;
|
|
126
|
+
token: string;
|
|
127
|
+
allowed_routes: string[]; // 路由白名单(触发 /run),['*'] = 全部
|
|
128
|
+
allowed_channels: string[]; // 主动出站渠道白名单(POST /send),['*'] = 全部,空 = 禁止(fail-closed)
|
|
129
|
+
rate_limit_per_min: number; // 0 = 不限
|
|
130
|
+
budget?: Record<string, unknown>; // 成本预算闸:{window/window_hours, hard_cost_usd?, hard_tokens?, ...}
|
|
131
|
+
enabled: boolean;
|
|
132
|
+
description?: string;
|
|
133
|
+
last_used_at?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** 模型凭证(后台可配,不硬编码):llm 对话与知识库 embedding 共用,按名引用。key 入库不回显。 */
|
|
137
|
+
export interface Credential {
|
|
138
|
+
name: string;
|
|
139
|
+
kind: 'chat' | 'embedding' | 'both';
|
|
140
|
+
base_url: string; // OpenAI 兼容接口前缀
|
|
141
|
+
api_key: string;
|
|
142
|
+
default_model?: string;
|
|
143
|
+
enabled: boolean;
|
|
144
|
+
description?: string;
|
|
145
|
+
last_used_at?: string;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** 知识库(图书馆):embedding 模型跟库走——建库定模型,检索必须同模型同坐标系 */
|
|
149
|
+
export interface KbBase {
|
|
150
|
+
kb_id: string;
|
|
151
|
+
name: string;
|
|
152
|
+
credential: string; // embedding 凭证名
|
|
153
|
+
model: string;
|
|
154
|
+
dim: number;
|
|
155
|
+
enabled: boolean;
|
|
156
|
+
description?: string;
|
|
157
|
+
writers?: string[]; // 可写接入方 app_id 白名单(入库插座:空 = 仅控制台可写)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface KbDoc {
|
|
161
|
+
doc_id: number;
|
|
162
|
+
kb_id: string;
|
|
163
|
+
source_key?: string; // 外部源幂等键(接入方推送/连接器同步;控制台手工添加为空)
|
|
164
|
+
title: string;
|
|
165
|
+
status: 'embedding' | 'ready' | 'error';
|
|
166
|
+
error?: string;
|
|
167
|
+
chunk_count: number;
|
|
168
|
+
created_at: string;
|
|
169
|
+
updated_at: string;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** 知识库数据源连接器(拉取式入库):连接 + 取数 SQL + 字段映射,定时拉业务库渲染成文档。 */
|
|
173
|
+
export interface KbDatasource {
|
|
174
|
+
ds_id: number;
|
|
175
|
+
kb_id: string;
|
|
176
|
+
name: string;
|
|
177
|
+
db_host: string;
|
|
178
|
+
db_port: number;
|
|
179
|
+
db_user: string;
|
|
180
|
+
db_password: string;
|
|
181
|
+
db_database: string;
|
|
182
|
+
query_sql: string; // 只读硬校验的单条 SELECT
|
|
183
|
+
key_field: string; // 幂等键字段(source_key = ds{ds_id}:{该字段值})
|
|
184
|
+
title_field: string;
|
|
185
|
+
content_template: string; // ${字段} 占位渲染 markdown
|
|
186
|
+
interval_min: number; // 0 = 仅手动
|
|
187
|
+
enabled: boolean;
|
|
188
|
+
last_sync_at?: string;
|
|
189
|
+
last_status?: string; // running / ok / error
|
|
190
|
+
last_error?: string;
|
|
191
|
+
last_stats?: { rows: number; upserted: number; skipped: number; deleted: number; errors: number; ms: number };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export type SessionPolicy = 'new' | 'fixed' | 'per_key' | 'passthrough';
|
|
195
|
+
|
|
196
|
+
/** 发给哪个 AI/通道(插座化后为开放集合:bz_targets 注册即合法,这里只约束字符串) */
|
|
197
|
+
export type TargetKind = string;
|
|
198
|
+
|
|
199
|
+
/** 调度目标定义(插座板的一个插孔)。inhub=中枢进程内适配器执行;executor=远端执行器拉取认领。 */
|
|
200
|
+
export interface TargetDef {
|
|
201
|
+
name: string;
|
|
202
|
+
kind: 'inhub' | 'executor';
|
|
203
|
+
stateless: boolean; // 无状态大脑:派活时必从总账装配上下文
|
|
204
|
+
needs_project: boolean; // 需要 project(代码目录)
|
|
205
|
+
timeout_ms: number; // inhub 执行超时;0=默认
|
|
206
|
+
enabled: boolean;
|
|
207
|
+
description?: string;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** 执行器接入令牌:执行器通道(claim/result)的专用鉴权凭证,按 target 白名单授权、可吊销、可审计——取代共享管理员 token。 */
|
|
211
|
+
export interface ExecutorToken {
|
|
212
|
+
name: string; // 人可读标识
|
|
213
|
+
token: string; // 实际令牌(出列表时掩码)
|
|
214
|
+
allowed_targets: string[]; // 可认领的 target 白名单(["*"]=全部)
|
|
215
|
+
enabled: boolean;
|
|
216
|
+
last_seen_at?: string | null;
|
|
217
|
+
description?: string;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** 执行器自报能力(随 claim/心跳上报):让中枢看得见每台执行器能跑什么,并校验路由的 (target,profile) 覆盖度。
|
|
221
|
+
* 全部可选——执行器是异构的(CLI agent / workflow / 自研智能体),报多少由各执行器自己决定,中枢只存不强求。 */
|
|
222
|
+
export interface ExecutorCapabilities {
|
|
223
|
+
profiles?: string[]; // 该执行器能处理的「能力档(profile)」名——用于校验路由 profile 覆盖度;无此概念的执行器可省略
|
|
224
|
+
runtime?: string; // 自报「这是什么智能体/引擎」的自由字符串(如 "codex-cli" / "my-agent" / 自研名);可省略
|
|
225
|
+
labels?: string[]; // 部署方自定义标签(可选,便于人识别这台机器的角色)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** 触发路由:某业务场景 → 发给哪个 target / 哪个项目 / 哪个会话策略 / 哪个能力档 */
|
|
229
|
+
export interface Route {
|
|
230
|
+
route_key: string;
|
|
231
|
+
name: string;
|
|
232
|
+
enabled: boolean;
|
|
233
|
+
target: TargetKind; // 发给哪个 AI/通道
|
|
234
|
+
// target 专属参数。llm: { credential, model, system_prompt, temperature?,
|
|
235
|
+
// input?:{ image?, audio?, file?, video? } }
|
|
236
|
+
// —— input 段把图片、语音、文件等素材理解从编排大脑中解耦,见 docs/TOOLS_DESIGN.md「多模态输入层」。
|
|
237
|
+
target_config: Record<string, unknown>;
|
|
238
|
+
project?: string; // 注册表标 needs_project 的目标需要(如本地代码类执行器)
|
|
239
|
+
profile: string;
|
|
240
|
+
// 权限档:'readonly'|'readwrite'|'full'(只读/可写/全开)。派发时中枢据此给任务正文前置一段【权限】提示词
|
|
241
|
+
// 指导执行器——是"提示词指导"非硬沙箱,执行器是否遵守由其自身决定,中枢不保证强制。空/缺省=不加限制。
|
|
242
|
+
// 与 profile(角色/技能档,后续并入云端 skill)正交:profile 管"怎么干活/什么角色",permission 管"允许动多少东西"。
|
|
243
|
+
permission?: string;
|
|
244
|
+
session_policy: SessionPolicy;
|
|
245
|
+
session_fixed_id?: string; // policy=fixed 时固定续聊的会话 id
|
|
246
|
+
session_key_field?: string; // policy=per_key 时取 metadata 的哪个字段做会话键
|
|
247
|
+
default_callback_url?: string;
|
|
248
|
+
delivery?: Record<string, unknown>; // ⑤送达层:{type:'webhook'|'channel'|<自定义X>, ...};webhook 内置签名直发,channel 内置经 channelSend 直推 delivery.channel 的收件人(to_field/to),其余类型 X 由注册的 X-notify 执行器目标承接
|
|
249
|
+
knowledge?: Record<string, unknown>; // 知识注入:{kb_id, top_k?, min_score?},派发前检索注入【知识参考】(故障可降级)
|
|
250
|
+
retry?: Record<string, unknown>; // 重试策略:{max, backoff_ms},只对瞬时失败生效
|
|
251
|
+
tools?: Record<string, unknown>; // 工具治理层:{sources:[{provider,allow[],subject_field?,retrieval?}],max_calls?,builtin:{send_message:{channels[]}},approval:{type,url?}},见 docs/TOOLS_DESIGN.md
|
|
252
|
+
audience?: AudiencePolicy; // 身份/Audience 策略:谁能进本路由,route=auto 如何把意图分到本路由
|
|
253
|
+
memory?: Record<string, unknown>; // 记忆层:{recent_messages, recent_budget_chars, summary_enabled, summary_trigger_chars, summary_keep_recent, summary_model, ...},见 src/core/runtime/memory.ts
|
|
254
|
+
budget?: Record<string, unknown>; // 成本预算闸:{window/window_hours, hard_cost_usd?, hard_tokens?, ...}
|
|
255
|
+
description?: string;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** 聊天入口:网页聊天组件的公开插座。entry_key 可公开(页面源码可见),防滥用靠 Origin 白名单+IP 限速+可停用。绑路由不绑大脑。 */
|
|
259
|
+
export interface ChatEntry {
|
|
260
|
+
entry_key: string;
|
|
261
|
+
name: string;
|
|
262
|
+
route_key: string;
|
|
263
|
+
enabled: boolean;
|
|
264
|
+
allowed_origins: string[]; // 空数组 = 不限
|
|
265
|
+
rate_limit_per_min: number; // 按访客 IP
|
|
266
|
+
ticket_client?: string; // 签发访客票据的接入方 app_id(空=不启用票据,纯匿名)
|
|
267
|
+
bucket?: string; // 关联的媒体存储登记名;留空走内置本地存储;落盘/落桶 URL 永久供追溯、多模态输入和业务接口入参
|
|
268
|
+
title?: string;
|
|
269
|
+
greeting?: string;
|
|
270
|
+
color?: string;
|
|
271
|
+
appearance?: ChatAppearance; // 外观(窗口尺寸/标题对齐/气泡位置偏移/头像/自定义气泡图标/AI 提示);缺省走组件内置默认
|
|
272
|
+
description?: string;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** 聊天组件外观:全可选,缺省走 widget.js 内置默认值。落 bz_chat_entries.appearance(JSON)。 */
|
|
276
|
+
export interface ChatAppearance {
|
|
277
|
+
width?: number; // 展开面板宽度 px(默认 400,受视口封顶)
|
|
278
|
+
height?: number; // 展开面板高度 px(默认 600,受视口封顶)
|
|
279
|
+
title_align?: 'center' | 'left'; // 标题对齐(默认 center)
|
|
280
|
+
position?: 'right' | 'left'; // 气泡/面板贴哪个下角(默认 right)
|
|
281
|
+
offset_x?: number; // 距所贴侧边的水平距离 px(默认 24)
|
|
282
|
+
offset_y?: number; // 距底部的垂直距离 px(默认 24)
|
|
283
|
+
avatar?: string; // 头部 Logo/客服头像 URL(空=不显示)
|
|
284
|
+
launcher_icon?: string; // 自定义气泡图标 URL(空=用内置对话气泡图标)
|
|
285
|
+
resizable?: boolean; // 允许访客拖面板边框改宽高(默认 false;桌面端生效,手机端全屏忽略;尺寸按访客本地持久化,夹到 width/height 同上下限)
|
|
286
|
+
ai_notice?: boolean; // AI 内容提示(默认 true):每条 AI 回复下方展示提示,复制时附带提示;关闭则两处都不加
|
|
287
|
+
powered_by_visible?: boolean; // 底部品牌标识(默认 true);关闭后不保留空白占位
|
|
288
|
+
powered_by_text?: string; // 品牌文案(空=由部署配置生成默认“由 <brand> 驱动”)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** 媒体存储登记:聊天上传的图片/语音/附件落盘或落桶取永久 URL。local 开箱即用;业务桶=业务 CDN、加商品零转存。secret_key 不回显。 */
|
|
292
|
+
export interface StorageBucket {
|
|
293
|
+
name: string;
|
|
294
|
+
kind: 'local' | 'cos' | 'oss' | 's3'; // 当前实现 local/cos
|
|
295
|
+
region: string; // ap-shanghai
|
|
296
|
+
bucket: string; // 桶名(COS 带 appid 后缀)
|
|
297
|
+
endpoint?: string; // 自定义 endpoint;留空按 kind+region 拼
|
|
298
|
+
access_key: string; // SecretId / AccessKeyId
|
|
299
|
+
secret_key: string; // SecretKey(不回显)
|
|
300
|
+
public_base_url: string; // 拼最终 URL 的公开域名前缀(无尾斜杠)
|
|
301
|
+
path_prefix: string; // 写入对象键前缀,如 bailing/chat
|
|
302
|
+
enabled: boolean;
|
|
303
|
+
description?: string;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** 入站消息渠道(通用):外部平台消息进中枢的前门,后台可配。kind 区分平台,config 放平台专属参数,
|
|
307
|
+
* route_key 把"消息进来"与"谁来处理"解耦。name = 回调 URL 路径段(企微回调=/wecom/<name>)。
|
|
308
|
+
* wecom 的 config: { corpid?, token, aes_key, agentid?, secret?, reply_wait_ms? }(corpid 可空,运行时从消息自动识别)。 */
|
|
309
|
+
export interface Channel {
|
|
310
|
+
name: string;
|
|
311
|
+
kind: 'wecom' | string; // 当前实现 wecom;未来 feishu 等加对应 handler
|
|
312
|
+
route_key: string; // 绑定的路由(大脑)
|
|
313
|
+
config: Record<string, unknown>; // 平台专属配置(含密钥,API 层掩码)
|
|
314
|
+
enabled: boolean;
|
|
315
|
+
description?: string;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** 告警通知规则:系统告警(executor_offline/queue_backlog/error_burst/spec_change…)「通知谁/什么事/走哪个渠道」可配,落 bz_alert_rules。
|
|
319
|
+
* 经通用出站原语 channelSend(渠道,收件人,正文) 推送,复用 bz_channels 凭证;event_prefix 按告警 key 前缀匹配(''=全部)。 */
|
|
320
|
+
export interface AlertRule {
|
|
321
|
+
id: number;
|
|
322
|
+
event_prefix: string; // 告警 key 前缀;''=全部
|
|
323
|
+
channel: string; // bz_channels.name(出站渠道)
|
|
324
|
+
recipients: string[]; // 渠道原生收件人 id(如企微 userid)
|
|
325
|
+
cooldown_min: number; // 同一事件 key 冷却分钟
|
|
326
|
+
enabled: boolean;
|
|
327
|
+
description?: string;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** 聊天回答评价(一答一评,重评覆盖):知识库运营的最小反馈闭环。note 表示仅提交文字反馈。 */
|
|
331
|
+
export interface JobRating {
|
|
332
|
+
job_id: string;
|
|
333
|
+
entry_key: string;
|
|
334
|
+
visitor_id: string;
|
|
335
|
+
rating: 'up' | 'down' | 'note';
|
|
336
|
+
comment?: string;
|
|
337
|
+
created_at: string;
|
|
338
|
+
updated_at: string;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** 工具调用审批单(确认车道,B 方案):批准锁定"那个具体调用快照",job+tool+args_hash 精确匹配后一次性消费。 */
|
|
342
|
+
export interface ToolApproval {
|
|
343
|
+
id: number;
|
|
344
|
+
job_id: string;
|
|
345
|
+
request_id: string;
|
|
346
|
+
provider: string;
|
|
347
|
+
tool: string;
|
|
348
|
+
scope: string;
|
|
349
|
+
risk: string;
|
|
350
|
+
policy?: string;
|
|
351
|
+
reason?: string;
|
|
352
|
+
method?: string;
|
|
353
|
+
path?: string;
|
|
354
|
+
summary?: string;
|
|
355
|
+
args_json?: string;
|
|
356
|
+
args_hash: string;
|
|
357
|
+
intent_json?: string;
|
|
358
|
+
intent?: Record<string, unknown>;
|
|
359
|
+
on_behalf_of?: string;
|
|
360
|
+
status: 'pending' | 'approved' | 'denied';
|
|
361
|
+
decision_id?: string;
|
|
362
|
+
decided_by?: string;
|
|
363
|
+
decision_comment?: string;
|
|
364
|
+
decided_at?: string;
|
|
365
|
+
used_at?: string;
|
|
366
|
+
created_at: string;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** 工具源:业务系统的 Agent 可调接口清单(OpenAPI + x-agent-capability 契约)。secret 用于 v2 调用签名,不回显。 */
|
|
370
|
+
export interface ToolProvider {
|
|
371
|
+
name: string;
|
|
372
|
+
base_url: string;
|
|
373
|
+
spec_source: 'url' | 'inline';
|
|
374
|
+
/** URL 工具清单状态;legacy_unverified 仅为历史空值的内部只读兼容映射,不是可写策略。 */
|
|
375
|
+
spec_access_policy?: 'signed_required' | 'public_allowed' | 'legacy_unverified';
|
|
376
|
+
spec_url?: string;
|
|
377
|
+
spec_json?: string;
|
|
378
|
+
spec_refreshed_at?: string;
|
|
379
|
+
spec_access_probe?: {
|
|
380
|
+
status: 'protected' | 'public' | 'inconclusive' | 'skipped';
|
|
381
|
+
signed_http?: number;
|
|
382
|
+
unsigned_http?: number;
|
|
383
|
+
invalid_http?: number;
|
|
384
|
+
reason?: string;
|
|
385
|
+
at: string;
|
|
386
|
+
};
|
|
387
|
+
authz_probe?: {
|
|
388
|
+
status: 'pass' | 'suspect' | 'inconclusive' | 'skipped';
|
|
389
|
+
http?: number;
|
|
390
|
+
tool?: string;
|
|
391
|
+
requires_subject?: boolean;
|
|
392
|
+
reason?: string;
|
|
393
|
+
at: string;
|
|
394
|
+
};
|
|
395
|
+
secret: string;
|
|
396
|
+
log_payload: boolean;
|
|
397
|
+
timeout_ms: number;
|
|
398
|
+
rate_limit_per_min: number;
|
|
399
|
+
auto_refresh_min: number; // 自动刷新间隔(分钟);0=关闭,仅 spec_source=url 生效
|
|
400
|
+
enabled: boolean;
|
|
401
|
+
description?: string;
|
|
402
|
+
// 工具语义检索(工具 RAG)的 embedding 坐标系:按名引用 bz_credentials(kind embedding/both),无硬编码默认。
|
|
403
|
+
// 三者齐备且工具数 > 内联阈值时启用检索(派发时按用户问题召回相关工具内联);空 = 不开检索,退回目录+find_tools。
|
|
404
|
+
// 坐标系(模型/维度)跟索引锁定:改它 = 整源重算(reindexProvider 检测到不一致会整源重建)。
|
|
405
|
+
embed_credential?: string;
|
|
406
|
+
embed_model?: string;
|
|
407
|
+
embed_dim?: number;
|
|
408
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { createRuntimeContext, isSingleScope, SingleScopeResolver, SINGLE_SCOPE_CAPABILITY, SINGLE_SCOPE_ID, SINGLE_SCOPE_KIND } from './index';
|
|
4
|
+
|
|
5
|
+
test('createRuntimeContext defaults to the OSS single scope', () => {
|
|
6
|
+
const ctx = createRuntimeContext({ requestId: 'req-1', source: 'system' });
|
|
7
|
+
assert.equal(ctx.edition, 'oss');
|
|
8
|
+
assert.equal(ctx.scope.kind, SINGLE_SCOPE_KIND);
|
|
9
|
+
assert.equal(ctx.scope.id, SINGLE_SCOPE_ID);
|
|
10
|
+
assert.deepEqual(ctx.scope.capabilities, [SINGLE_SCOPE_CAPABILITY]);
|
|
11
|
+
assert.equal(isSingleScope(ctx.scope), true);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('SingleScopeResolver keeps scope neutral and maps actor when provided', async () => {
|
|
15
|
+
const resolver = new SingleScopeResolver<{ id: string }>((auth) => auth ? { kind: 'client', id: auth.id, roles: ['caller'] } : undefined);
|
|
16
|
+
const ctx = await resolver.resolve({ source: 'run', requestId: 'req-2', auth: { id: 'demo-app' } });
|
|
17
|
+
assert.equal(ctx.scope.kind, 'single');
|
|
18
|
+
assert.equal(ctx.actor.kind, 'client');
|
|
19
|
+
assert.equal(ctx.actor.id, 'demo-app');
|
|
20
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export const OSS_EDITION = 'oss';
|
|
2
|
+
export const SINGLE_SCOPE_KIND = 'single';
|
|
3
|
+
export const SINGLE_SCOPE_ID = 'default';
|
|
4
|
+
export const SINGLE_SCOPE_CAPABILITY = 'single_org';
|
|
5
|
+
|
|
6
|
+
export type RuntimeSource =
|
|
7
|
+
| 'admin'
|
|
8
|
+
| 'run'
|
|
9
|
+
| 'send'
|
|
10
|
+
| 'chat'
|
|
11
|
+
| 'channel'
|
|
12
|
+
| 'executor'
|
|
13
|
+
| 'worker'
|
|
14
|
+
| 'system';
|
|
15
|
+
|
|
16
|
+
export interface RuntimeScope {
|
|
17
|
+
kind: string;
|
|
18
|
+
id: string;
|
|
19
|
+
projectId?: string;
|
|
20
|
+
capabilities: string[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface RuntimeActor {
|
|
24
|
+
kind: string;
|
|
25
|
+
id: string;
|
|
26
|
+
roles: string[];
|
|
27
|
+
displayName?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface RuntimeContext {
|
|
31
|
+
edition: string;
|
|
32
|
+
scope: RuntimeScope;
|
|
33
|
+
actor: RuntimeActor;
|
|
34
|
+
requestId: string;
|
|
35
|
+
source: RuntimeSource;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function singleScope(): RuntimeScope {
|
|
39
|
+
return {
|
|
40
|
+
kind: SINGLE_SCOPE_KIND,
|
|
41
|
+
id: SINGLE_SCOPE_ID,
|
|
42
|
+
capabilities: [SINGLE_SCOPE_CAPABILITY],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function systemActor(id = 'system'): RuntimeActor {
|
|
47
|
+
return {
|
|
48
|
+
kind: 'system',
|
|
49
|
+
id,
|
|
50
|
+
roles: ['system'],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function createRuntimeContext(input: {
|
|
55
|
+
edition?: string;
|
|
56
|
+
scope?: RuntimeScope;
|
|
57
|
+
actor?: RuntimeActor;
|
|
58
|
+
requestId: string;
|
|
59
|
+
source: RuntimeSource;
|
|
60
|
+
}): RuntimeContext {
|
|
61
|
+
return {
|
|
62
|
+
edition: input.edition ?? OSS_EDITION,
|
|
63
|
+
scope: input.scope ?? singleScope(),
|
|
64
|
+
actor: input.actor ?? systemActor(),
|
|
65
|
+
requestId: input.requestId,
|
|
66
|
+
source: input.source,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function isSingleScope(scope: RuntimeScope): boolean {
|
|
71
|
+
return scope.kind === SINGLE_SCOPE_KIND && scope.id === SINGLE_SCOPE_ID;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function assertSingleScope(ctx: RuntimeContext): void {
|
|
75
|
+
if (!isSingleScope(ctx.scope)) {
|
|
76
|
+
throw new Error(`当前开源版只支持 single/default scope,收到 ${ctx.scope.kind}/${ctx.scope.id}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createRuntimeContext, type RuntimeActor, type RuntimeContext, type RuntimeSource } from './context';
|
|
2
|
+
|
|
3
|
+
export interface ScopeResolveInput<AuthResult = unknown> {
|
|
4
|
+
source: RuntimeSource;
|
|
5
|
+
requestId: string;
|
|
6
|
+
auth?: AuthResult;
|
|
7
|
+
actor?: RuntimeActor;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ScopeResolver<AuthResult = unknown> {
|
|
11
|
+
resolve(input: ScopeResolveInput<AuthResult>): Promise<RuntimeContext>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class SingleScopeResolver<AuthResult = unknown> implements ScopeResolver<AuthResult> {
|
|
15
|
+
constructor(private readonly actorOf?: (auth: AuthResult | undefined) => RuntimeActor | undefined) {}
|
|
16
|
+
|
|
17
|
+
async resolve(input: ScopeResolveInput<AuthResult>): Promise<RuntimeContext> {
|
|
18
|
+
return createRuntimeContext({
|
|
19
|
+
source: input.source,
|
|
20
|
+
requestId: input.requestId,
|
|
21
|
+
actor: input.actor ?? this.actorOf?.(input.auth),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { renderOperationalMetrics } from './openmetrics';
|
|
4
|
+
|
|
5
|
+
test('OpenMetrics renderer: emits fixed low-cardinality families and escapes build labels', () => {
|
|
6
|
+
const text = renderOperationalMetrics({
|
|
7
|
+
version: '0.1.8"test',
|
|
8
|
+
commit: 'abc\\def\n',
|
|
9
|
+
paused: false,
|
|
10
|
+
queue: { running: 2, waiting: 3 },
|
|
11
|
+
state: {
|
|
12
|
+
available: true,
|
|
13
|
+
success: true,
|
|
14
|
+
value: {
|
|
15
|
+
byStatus: { queued: 1, running: 2, dispatched: 3, done: 4, error: 5, rejected: 6 },
|
|
16
|
+
terminalLast15m: { done: 4, error: 1, rejected: 0 },
|
|
17
|
+
oldestQueuedAgeSeconds: 12.5,
|
|
18
|
+
delayedQueuedJobs: 1,
|
|
19
|
+
expiredLeases: 2,
|
|
20
|
+
blockedThreads: 3,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
controlPlane: {
|
|
24
|
+
available: true,
|
|
25
|
+
success: true,
|
|
26
|
+
value: { pendingApprovals: 7, executorsOnline: 8, executorsOffline: 9 },
|
|
27
|
+
},
|
|
28
|
+
auditWriteFailuresTotal: 10,
|
|
29
|
+
scrapeDurationSeconds: 0.25,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
assert.match(text, /bailinghub_info\{version="0\.1\.8\\"test",commit="abc\\\\def\\n"\} 1/);
|
|
33
|
+
assert.match(text, /bailinghub_job_records\{status="queued"\} 1/);
|
|
34
|
+
assert.match(text, /bailinghub_jobs_terminal_15m\{status="error"\} 1/);
|
|
35
|
+
assert.match(text, /bailinghub_executors\{state="online"\} 8/);
|
|
36
|
+
assert.match(text, /bailinghub_audit_write_failures_total 10/);
|
|
37
|
+
assert.ok(text.endsWith('# EOF\n'));
|
|
38
|
+
assert.doesNotMatch(text, /job_id|request_id|tenant|principal|args/);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('OpenMetrics renderer: unavailable optional collectors are explicit and do not invent zero business data', () => {
|
|
42
|
+
const text = renderOperationalMetrics({
|
|
43
|
+
version: '0.1.8',
|
|
44
|
+
commit: 'unknown',
|
|
45
|
+
paused: true,
|
|
46
|
+
queue: { running: 0, waiting: 0 },
|
|
47
|
+
state: { available: false, success: false },
|
|
48
|
+
controlPlane: { available: false, success: false },
|
|
49
|
+
auditWriteFailuresTotal: 0,
|
|
50
|
+
scrapeDurationSeconds: 0,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
assert.match(text, /bailinghub_metrics_collector_available\{collector="state"\} 0/);
|
|
54
|
+
assert.match(text, /bailinghub_metrics_collector_success\{collector="control_plane"\} 0/);
|
|
55
|
+
assert.doesNotMatch(text, /bailinghub_job_records/);
|
|
56
|
+
assert.doesNotMatch(text, /bailinghub_approvals_pending/);
|
|
57
|
+
});
|