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,78 @@
|
|
|
1
|
+
# Embedded Chat Streaming Protocol
|
|
2
|
+
|
|
3
|
+
> Protocol identifier: `bailing.chat.stream.v1`
|
|
4
|
+
|
|
5
|
+
This document defines incremental output, reconnect replay, fallback, and persistence boundaries for the BailingHub embedded chat widget. A `delta` is a text fragment emitted by the model provider. It is not guaranteed to correspond to exactly one tokenizer token.
|
|
6
|
+
|
|
7
|
+
## 1. Boundaries
|
|
8
|
+
|
|
9
|
+
- Incremental text is provisional UI transport data.
|
|
10
|
+
- The terminal job record is the single source of truth, and `done` is always built from that record.
|
|
11
|
+
- Conversation history, webhook callbacks, channel delivery, references, and attachments consume the terminal result, not fragments.
|
|
12
|
+
- Audit may record chunk count, character count, first-fragment latency, and finish reason, but never writes every fragment body.
|
|
13
|
+
- Tool calls, retries, and provider fallback may start a new model round. Clients must honor `reset` and must not concatenate provisional text from different rounds.
|
|
14
|
+
|
|
15
|
+
## 2. Connection Flow
|
|
16
|
+
|
|
17
|
+
1. Create a job with `POST /chat/:entry_key` and read `job_id`.
|
|
18
|
+
2. Connect to `GET /chat/:entry_key/events/:job_id` with `EventSource`.
|
|
19
|
+
3. Consume base status events and any incremental events.
|
|
20
|
+
4. On `done`, replace provisional output with `reply`, then persist local history and render references or attachments.
|
|
21
|
+
5. On a transient disconnect, standard `EventSource` reconnects with `Last-Event-ID`.
|
|
22
|
+
|
|
23
|
+
## 3. Events
|
|
24
|
+
|
|
25
|
+
| Event | Key fields | Client behavior |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| `open` | `job_id`, `status`, `protocol`, `streaming` | Confirms the connection. `streaming:true` means this replica has an incremental relay; it does not guarantee the provider will emit fragments. |
|
|
28
|
+
| `status` | `job_id`, `status` | Optionally show `queued`, `running`, or `dispatched`. |
|
|
29
|
+
| `phase` | `seq`, `ts`, `name`, `round` | `name` is `model` or `tool`. This is informative, not terminal evidence. |
|
|
30
|
+
| `reset` | `seq?`, `reason`, `round?`, `latest_seq?` | Immediately discard provisional text. |
|
|
31
|
+
| `delta` | `seq`, `ts`, `text`, `round` | Append `text` to the current provisional answer. |
|
|
32
|
+
| `ping` | `ts`, `job_id` | Keepalive only. |
|
|
33
|
+
| `done` | `done`, `reply`, `job_id`, `visitor_id`, `references?`, `attachments?`, `error?` | Canonical terminal result. Replace provisional text and close. |
|
|
34
|
+
| `failed` | `done`, `error`, `reply` | The connection can no longer read the job. |
|
|
35
|
+
| `timeout` | `done:false`, `job_id` | This connection window ended; the job may still complete and can be recovered from history. |
|
|
36
|
+
|
|
37
|
+
Current `reset.reason` values are `model_round`, `tool_call`, `retry`, `fallback`, `protocol_violation`, and `replay_gap`. `protocol_violation` means internal model tool-protocol markup was intercepted; clients must discard the current provisional text, which is neither displayed nor parsed for execution.
|
|
38
|
+
|
|
39
|
+
## 4. Event IDs And Replay
|
|
40
|
+
|
|
41
|
+
- `phase`, broker-backed `reset`, and `delta` use a monotonic per-job `seq` starting at 1. SSE `id` equals `seq`.
|
|
42
|
+
- Ignore duplicate events where `seq <= last_seq`.
|
|
43
|
+
- Replay is bounded and short-lived; it is not a durable event log.
|
|
44
|
+
- If the cursor predates the replay window, the server sends `reset` with `reason: replay_gap` and continues from the earliest available event.
|
|
45
|
+
|
|
46
|
+
## 5. Provider Fallback
|
|
47
|
+
|
|
48
|
+
- The `llm` adapter sends `stream:true` only when the current invocation has an incremental consumer.
|
|
49
|
+
- Set `target_config.streaming` to `false` to opt out.
|
|
50
|
+
- If a provider ignores `stream:true` and returns JSON, BailingHub consumes it as a normal non-streaming completion.
|
|
51
|
+
- BailingHub retries once with `stream:false` only for HTTP 400, 404, 415, 422, or 501 responses that explicitly say streaming is unsupported.
|
|
52
|
+
- Timeouts, rate limits, 5xx responses, and ambiguous 4xx responses are not replayed merely to attempt fallback. This avoids duplicate work and tool side effects.
|
|
53
|
+
|
|
54
|
+
## 6. Multi-Replica Operations
|
|
55
|
+
|
|
56
|
+
The default `InMemoryJobStreamBroker` is process-local. A multi-replica deployment must either use sticky routing for the same `job_id` or inject a shared `JobStreamBroker` at composition time. The canonical final job remains in MySQL, so `done` does not depend on fragment replay.
|
|
57
|
+
|
|
58
|
+
Reverse proxies and CDNs must disable response buffering, preserve `text/event-stream`, keep read timeouts above the chat window, and allow `Last-Event-ID`.
|
|
59
|
+
|
|
60
|
+
## 7. Compatibility
|
|
61
|
+
|
|
62
|
+
- This is an optional event extension under Widget API v1. The `done` payload is unchanged.
|
|
63
|
+
- Existing clients may ignore `phase`, `reset`, and `delta` and wait for `done`.
|
|
64
|
+
- New clients must treat `done`, not accumulated fragments, as the final authoritative value.
|
|
65
|
+
|
|
66
|
+
## 8. Validation
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm run typecheck
|
|
70
|
+
node --import tsx --test \
|
|
71
|
+
src/adapters/llm/openai-chat-stream.test.ts \
|
|
72
|
+
src/adapters/targets/llm.test.ts \
|
|
73
|
+
src/core/runtime/job-stream.test.ts \
|
|
74
|
+
src/routes/chat.test.ts \
|
|
75
|
+
src/routes/public.test.ts
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Before release, also run `npm test`, the admin console build, and `npm run docs:check`.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# 网页聊天增量输出协议
|
|
2
|
+
|
|
3
|
+
> 协议标识:`bailing.chat.stream.v1`
|
|
4
|
+
|
|
5
|
+
本文定义百灵中枢网页聊天组件的增量输出、断线重放、降级和持久化边界。这里的 `delta` 是模型提供商返回的文本片段,不承诺每个片段恰好对应一个 tokenizer token。
|
|
6
|
+
|
|
7
|
+
## 1. 设计边界
|
|
8
|
+
|
|
9
|
+
- 增量文本只用于当前界面的临时展示。
|
|
10
|
+
- 任务库中的终态结果是单一真值源;`done` 始终从该结果生成。
|
|
11
|
+
- 对话总账、Webhook 回调、渠道送达和最终附件/引用只消费终态结果,不消费中间片段。
|
|
12
|
+
- 审计可记录分片数、字符数、首段延迟和结束原因,不记录每个 `delta` 的正文。
|
|
13
|
+
- 工具调用、重试或降级可以使模型重新生成。客户端必须支持 `reset`,不得把两轮临时文本拼成一条最终回答。
|
|
14
|
+
|
|
15
|
+
## 2. 连接流程
|
|
16
|
+
|
|
17
|
+
1. 组件调用 `POST /chat/:entry_key` 创建任务,获取 `job_id`。
|
|
18
|
+
2. 组件连接 `GET /chat/:entry_key/events/:job_id`。
|
|
19
|
+
3. 服务端发送 `open`,然后持续发送任务状态和可用的增量事件。
|
|
20
|
+
4. 组件收到 `done` 后,用其 `reply` 替换临时气泡,再写入本地历史和附件/引用 UI。
|
|
21
|
+
5. 连接在窗口内中断时,标准 `EventSource` 使用 `Last-Event-ID` 自动重连。
|
|
22
|
+
|
|
23
|
+
## 3. SSE 事件
|
|
24
|
+
|
|
25
|
+
| 事件 | 关键字段 | 客户端行为 |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| `open` | `job_id`, `status`, `protocol`, `streaming` | 确认连接。`streaming:true` 表示当前实例具备增量转发通道,不保证上游一定返回片段。 |
|
|
28
|
+
| `status` | `job_id`, `status` | 可选展示 `queued/running/dispatched`。 |
|
|
29
|
+
| `phase` | `seq`, `ts`, `name`, `round` | `name` 为 `model` 或 `tool`;可选展示阶段,不得据此判定任务终态。 |
|
|
30
|
+
| `reset` | `seq?`, `reason`, `round?`, `latest_seq?` | 立即丢弃尚未完成的临时文本。 |
|
|
31
|
+
| `delta` | `seq`, `ts`, `text`, `round` | 把 `text` 追加到当前临时回答。 |
|
|
32
|
+
| `ping` | `ts`, `job_id` | 保活;无业务语义。 |
|
|
33
|
+
| `done` | `done`, `reply`, `job_id`, `visitor_id`, `references?`, `attachments?`, `error?` | 权威终态。用 `reply` 替换临时文本并关闭连接。 |
|
|
34
|
+
| `failed` | `done`, `error`, `reply` | 连接层无法继续读取该任务。 |
|
|
35
|
+
| `timeout` | `done:false`, `job_id` | 本次连接窗口结束;任务不一定失败,可通过历史回灌恢复。 |
|
|
36
|
+
|
|
37
|
+
`reset.reason` 当前可为:
|
|
38
|
+
|
|
39
|
+
- `model_round`:新的模型轮次开始;
|
|
40
|
+
- `tool_call`:模型改为调用工具,已生成的临时文本不是最终答案;
|
|
41
|
+
- `retry`:任务将重试;
|
|
42
|
+
- `fallback`:提供商明确不支持 streaming,本轮改为非流式;
|
|
43
|
+
- `protocol_violation`:检测到模型内部工具协议,必须清空本轮临时文本;该文本不会展示或解析执行;
|
|
44
|
+
- `replay_gap`:客户端游标早于服务端当前回放窗口,旧临时文本必须清空。
|
|
45
|
+
|
|
46
|
+
## 4. 序号与断线重放
|
|
47
|
+
|
|
48
|
+
- `phase/reset/delta` 在每个 `job_id` 内使用从 1 开始的单调 `seq`,SSE `id` 与 `seq` 一致。
|
|
49
|
+
- 客户端应忽略 `seq <= last_seq` 的重复事件。
|
|
50
|
+
- 服务端使用有界、有 TTL 的短期回放窗口,不把增量事件当作持久化日志。
|
|
51
|
+
- 游标已经落后于回放窗口时,服务端发送 `reset: replay_gap`,然后从尚可用的最早事件继续。
|
|
52
|
+
|
|
53
|
+
## 5. 模型提供商与降级
|
|
54
|
+
|
|
55
|
+
- 只有当当前调用有增量消费者时,`llm` 适配器才会向 OpenAI-compatible `/chat/completions` 发送 `stream:true`。
|
|
56
|
+
- 路由可通过 `target_config.streaming: false` 显式关闭。
|
|
57
|
+
- 如果提供商忽略 `stream:true` 并返回普通 JSON,中枢直接按非流式结果处理。
|
|
58
|
+
- 只有提供商以 400/404/415/422/501 且错误文本明确指出 streaming 不支持时,中枢才重试一次 `stream:false`。
|
|
59
|
+
- 超时、限流、5xx 或不明确的 4xx 不会因为“尝试降级”而额外重发,避免重复工具或业务操作。
|
|
60
|
+
|
|
61
|
+
## 6. 多副本与反向代理
|
|
62
|
+
|
|
63
|
+
默认 `InMemoryJobStreamBroker` 是单进程短期传输实现。多副本时二选一:
|
|
64
|
+
|
|
65
|
+
1. 对同一 `job_id` 使用粘性路由,让任务执行副本和 SSE 连接一致;
|
|
66
|
+
2. 通过组合根注入共享 `JobStreamBroker` 实现。
|
|
67
|
+
|
|
68
|
+
无论增量 broker 是否可用,终态任务仍在 MySQL 中,`done` 不依赖进程内片段。
|
|
69
|
+
|
|
70
|
+
反向代理/CDN 需要:
|
|
71
|
+
|
|
72
|
+
- 关闭响应缓冲和转码;
|
|
73
|
+
- 保留 `text/event-stream`;
|
|
74
|
+
- 读取超时大于聊天连接窗口;
|
|
75
|
+
- 允许标准 `Last-Event-ID` 请求头。
|
|
76
|
+
|
|
77
|
+
## 7. 兼容性
|
|
78
|
+
|
|
79
|
+
- 这是 Widget API v1 下的可选事件扩展,不改变 `done` 结构。
|
|
80
|
+
- 旧客户端可以忽略 `phase/reset/delta`,继续只等待 `done`。
|
|
81
|
+
- 新客户端必须把 `done` 视为最终权威值,不得仅凭已收到的 `delta` 宣称任务完成。
|
|
82
|
+
|
|
83
|
+
### 7.1 展示能力协商
|
|
84
|
+
|
|
85
|
+
自建客户端如需接收声明式图表等富内容,可在创建任务时附带:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"client_capabilities": {
|
|
90
|
+
"renderers": ["bailing-chart"]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
该字段只影响模型收到的可选展示提示,不进入 SSE 事件,不构成身份、授权、审批或工具权限。富内容仍属于 `done.reply` 的一部分;客户端不得在 `delta` 阶段挂载图表,应在 `done` 后按 [`WIDGET_RENDERERS.md`](WIDGET_RENDERERS.md) 的白名单与失败降级规则处理完整 fenced code block。
|
|
96
|
+
|
|
97
|
+
## 8. 验证
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm run typecheck
|
|
101
|
+
node --import tsx --test \
|
|
102
|
+
src/adapters/llm/openai-chat-stream.test.ts \
|
|
103
|
+
src/adapters/targets/llm.test.ts \
|
|
104
|
+
src/core/runtime/job-stream.test.ts \
|
|
105
|
+
src/routes/chat.test.ts \
|
|
106
|
+
src/routes/public.test.ts
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
完整发布前还应运行 `npm test`、控制台构建和 `npm run docs:check`。
|
package/docs/TOOLS.en.md
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# Business Tools
|
|
2
|
+
|
|
3
|
+
BailingHub lets an existing business system expose selected APIs to AI agents as governed tools.
|
|
4
|
+
|
|
5
|
+
The goal is not to give the agent direct database access. The goal is to let the agent call the same business actions that a real user could perform, while keeping signatures, permission checks, approvals, audit trails, and traceability in place.
|
|
6
|
+
|
|
7
|
+
## Core Principle
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
BailingHub controls reach.
|
|
11
|
+
Your business system controls authority.
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The hub decides which tools the agent can see and call. Your backend still decides whether the current user can actually perform the action.
|
|
15
|
+
|
|
16
|
+
## How Tool Providers Work
|
|
17
|
+
|
|
18
|
+
A tool provider is a business API catalog.
|
|
19
|
+
|
|
20
|
+
Common input forms:
|
|
21
|
+
|
|
22
|
+
- OpenAPI with `x-agent-capability` extensions
|
|
23
|
+
- PHP 8 annotations
|
|
24
|
+
- PHP 7 builder SDK
|
|
25
|
+
- Node SDK
|
|
26
|
+
- Python SDK
|
|
27
|
+
- future MCP adapters
|
|
28
|
+
|
|
29
|
+
Recommended path:
|
|
30
|
+
|
|
31
|
+
```text
|
|
32
|
+
/.well-known/bailing/tools.json
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The hub imports the spec, validates it, and compiles it into internal `ToolDefinition` records.
|
|
36
|
+
|
|
37
|
+
For a URL-backed provider, access posture is explicit rather than inferred:
|
|
38
|
+
|
|
39
|
+
| Policy | Meaning |
|
|
40
|
+
|---|---|
|
|
41
|
+
| `signed_required` | Default. Only a correctly signed hub request may read the spec. |
|
|
42
|
+
| `public_allowed` | The operator intentionally permits public catalog reads. Tool calls remain signed and business-authorized. |
|
|
43
|
+
|
|
44
|
+
For `signed_required`, refresh reads with a valid signature and then checks
|
|
45
|
+
unsigned and invalid-signature requests. It writes a new cache only when the
|
|
46
|
+
signed request succeeds and both negative probes return 401/403/404; otherwise
|
|
47
|
+
the old cache is kept. `public_allowed` uses only an unsigned primary request
|
|
48
|
+
and never silently retries with a signature. These are the only configurable
|
|
49
|
+
policies. The configured policy is an expectation; the observed `protected`,
|
|
50
|
+
`public`, or `inconclusive` status is evidence. A protected response must include
|
|
51
|
+
`Cache-Control: private, no-store` to prevent
|
|
52
|
+
intermediary caches from turning a valid signed fetch into a public copy.
|
|
53
|
+
For providers created before this policy existed, follow the read-only migration
|
|
54
|
+
procedure in [COMPATIBILITY.en.md](COMPATIBILITY.en.md#url-tool-catalog-access-policy-upgrade).
|
|
55
|
+
|
|
56
|
+
Attach one or more providers to a route through `tools.sources[]`:
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"sources": [
|
|
61
|
+
{ "provider": "order-tools", "allow": ["order.*"] },
|
|
62
|
+
{ "provider": "shipping-tools", "allow": ["shipment.read"] }
|
|
63
|
+
],
|
|
64
|
+
"max_calls": 6
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The allowlist is evaluated per provider. Provider credentials and business identities are not merged; only the Agent-facing tool catalog is composed. Tool names must therefore be unique within the route.
|
|
69
|
+
|
|
70
|
+
## Minimal Tool
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
import { buildOpenApiSpec, param, tool } from '@bailinghub/connect';
|
|
74
|
+
|
|
75
|
+
export default buildOpenApiSpec({
|
|
76
|
+
title: 'Order Tools',
|
|
77
|
+
version: '1.0.0',
|
|
78
|
+
authzProbe: { method: 'POST', path: '/.well-known/bailing/authz-probe' },
|
|
79
|
+
tools: [
|
|
80
|
+
tool({
|
|
81
|
+
name: 'order_get',
|
|
82
|
+
method: 'GET',
|
|
83
|
+
path: '/api/orders/{id}',
|
|
84
|
+
description: 'Query order detail',
|
|
85
|
+
scope: 'order.read',
|
|
86
|
+
requiresSubject: true,
|
|
87
|
+
params: [param('id', { in: 'path', required: true, description: 'Order ID' })],
|
|
88
|
+
}),
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Tool Shapes
|
|
94
|
+
|
|
95
|
+
Do not expose every CRUD endpoint blindly. Start with AI-friendly business actions:
|
|
96
|
+
|
|
97
|
+
| Shape | Example | Typical governance |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| Query | `order.get`, `staff.search` | `low`, read-only |
|
|
100
|
+
| Preview | `refund.preview`, `staff_remove.impact` | `low` or `medium` |
|
|
101
|
+
| Request/draft | `refund.request.create` | `medium`, business workflow handles approval |
|
|
102
|
+
| Execute | `refund.execute`, `staff.delete` | `high` or approval required |
|
|
103
|
+
| Batch execute | `coupon.batch_send`, `price.batch_update` | `high`, parameter-level confirmation |
|
|
104
|
+
|
|
105
|
+
## Risk and Approval
|
|
106
|
+
|
|
107
|
+
Use `risk` / `x-agent-capability.risk.level` to describe how the hub should treat AI-triggered calls:
|
|
108
|
+
|
|
109
|
+
- `low`: normally safe, usually read-only
|
|
110
|
+
- `medium`: allowed with audit trail, often creates workflow records or drafts
|
|
111
|
+
- `high`: requires explicit approval before execution
|
|
112
|
+
|
|
113
|
+
Use parameter-level confirmation when only some calls are risky:
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
tool({
|
|
117
|
+
name: 'refund_execute',
|
|
118
|
+
method: 'POST',
|
|
119
|
+
path: '/api/refunds/execute',
|
|
120
|
+
description: 'Execute refund',
|
|
121
|
+
scope: 'refund.execute',
|
|
122
|
+
risk: 'medium',
|
|
123
|
+
requiresSubject: true,
|
|
124
|
+
confirmWhen: [
|
|
125
|
+
{ param: 'amount', op: '>', value: 500, label: 'Refunds above 500 require human confirmation' }
|
|
126
|
+
],
|
|
127
|
+
params: [
|
|
128
|
+
param('order_id', { required: true, description: 'Order ID' }),
|
|
129
|
+
param('amount', { type: 'number', required: true, description: 'Refund amount' })
|
|
130
|
+
],
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Signed Tool Calls
|
|
135
|
+
|
|
136
|
+
The hub calls your business API with HMAC signature headers:
|
|
137
|
+
|
|
138
|
+
```text
|
|
139
|
+
X-Bailing-Signature: sha256=<hmac>
|
|
140
|
+
X-Bailing-Timestamp: 1782912000
|
|
141
|
+
X-Bailing-Tool: order_get
|
|
142
|
+
X-Bailing-Job-Id: job_...
|
|
143
|
+
X-Bailing-On-Behalf-Of: u_42
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Your backend must:
|
|
147
|
+
|
|
148
|
+
1. verify the signature
|
|
149
|
+
2. verify the timestamp window
|
|
150
|
+
3. read `X-Bailing-On-Behalf-Of`
|
|
151
|
+
4. check your own permission table
|
|
152
|
+
5. execute only if the user is allowed
|
|
153
|
+
|
|
154
|
+
Never treat a valid signature as business authorization.
|
|
155
|
+
|
|
156
|
+
## Recommended Response Shape
|
|
157
|
+
|
|
158
|
+
For workflow-like tools, return clear status:
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"ok": true,
|
|
163
|
+
"status": "pending_approval",
|
|
164
|
+
"message": "Refund request created and waiting for manager approval.",
|
|
165
|
+
"business_id": "refund_req_1001",
|
|
166
|
+
"url": "https://business.example.com/refunds/refund_req_1001"
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
This helps the agent explain whether an action was executed, submitted, drafted, or rejected.
|
|
171
|
+
|
|
172
|
+
## Industry Templates
|
|
173
|
+
|
|
174
|
+
E-commerce:
|
|
175
|
+
|
|
176
|
+
- `order.get`
|
|
177
|
+
- `refund.preview`
|
|
178
|
+
- `refund.request.create`
|
|
179
|
+
- `refund.execute`
|
|
180
|
+
|
|
181
|
+
HR/OA:
|
|
182
|
+
|
|
183
|
+
- `staff.search`
|
|
184
|
+
- `staff_remove.impact`
|
|
185
|
+
- `staff_remove.request.create`
|
|
186
|
+
- `staff.delete`
|
|
187
|
+
|
|
188
|
+
CRM:
|
|
189
|
+
|
|
190
|
+
- `customer.search`
|
|
191
|
+
- `followup.create`
|
|
192
|
+
- `deal.stage.update`
|
|
193
|
+
|
|
194
|
+
Operations:
|
|
195
|
+
|
|
196
|
+
- `service.health`
|
|
197
|
+
- `deploy.preview`
|
|
198
|
+
- `deploy.request.create`
|
|
199
|
+
- `deploy.execute`
|
|
200
|
+
|
|
201
|
+
Finance:
|
|
202
|
+
|
|
203
|
+
- `invoice.query`
|
|
204
|
+
- `payment.request.create`
|
|
205
|
+
- `payment.execute`
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Tool Governance Design
|
|
2
|
+
|
|
3
|
+
Tool governance is the core runtime value of BailingHub. It lets agents call business tools without bypassing business-side permissions, audit, approval, or rate limits.
|
|
4
|
+
|
|
5
|
+
## Governance Layers
|
|
6
|
+
|
|
7
|
+
| Layer | Purpose |
|
|
8
|
+
|---|---|
|
|
9
|
+
| Route allowlist | The route decides which tool scopes are visible to the agent. |
|
|
10
|
+
| Risk level | Tools declare runtime risk such as low, medium, or high. |
|
|
11
|
+
| Rate limit | Tool provider and tool-level limits protect business systems. |
|
|
12
|
+
| Approval intent | High-risk or confirmation-required calls are frozen for approval. |
|
|
13
|
+
| Signature | Tool calls are signed by the hub and verified by the business system. |
|
|
14
|
+
| Business authorization | The business backend checks the on-behalf-of subject against its own permissions. |
|
|
15
|
+
| Audit and trace | Every important decision and call is recorded. |
|
|
16
|
+
|
|
17
|
+
## URL Spec Access Posture
|
|
18
|
+
|
|
19
|
+
A URL-backed provider stores two different kinds of state:
|
|
20
|
+
|
|
21
|
+
- `spec_access_policy` is the operator's expectation: `signed_required`
|
|
22
|
+
(default) or `public_allowed`. These are the only configurable values;
|
|
23
|
+
- `spec_access_probe` is refresh-time evidence with status `protected`,
|
|
24
|
+
`public`, or `inconclusive`, plus whichever signed, unsigned, and
|
|
25
|
+
invalid-signature HTTP observations apply to that policy.
|
|
26
|
+
|
|
27
|
+
The console must display expectation and evidence separately. Read-only state
|
|
28
|
+
for providers created before the policy existed is documented only in
|
|
29
|
+
[COMPATIBILITY.en.md](COMPATIBILITY.en.md#url-tool-catalog-access-policy-upgrade)
|
|
30
|
+
and is not a third Schema, API, or console choice. Choosing `public_allowed`
|
|
31
|
+
requires a clear warning because paths,
|
|
32
|
+
parameters, scopes, and risk metadata become readable to anyone who can reach
|
|
33
|
+
the URL. This choice does not weaken tool-call verification or business-side
|
|
34
|
+
authorization.
|
|
35
|
+
|
|
36
|
+
Protected spec responses send `Cache-Control: private, no-store`. PHP/PHP7
|
|
37
|
+
`SpecServer::respond()` adds it when a secret is present, and framework
|
|
38
|
+
integrations can use `SpecServer::responseHeaders($secret)`. Explicitly public
|
|
39
|
+
endpoints use `handlePublic()` / `respondPublic()`; the older null-secret form
|
|
40
|
+
remains wire-compatible but is no longer the recommended spelling.
|
|
41
|
+
|
|
42
|
+
For `signed_required`, a refresh may replace the cache only when the correctly
|
|
43
|
+
signed request succeeds and both unsigned and invalid-signature probes return
|
|
44
|
+
401/403/404. Public or inconclusive observations fail the refresh and preserve
|
|
45
|
+
the previous cache. `public_allowed` uses an unsigned primary request and never
|
|
46
|
+
falls back to a signed fetch when the endpoint is actually protected.
|
|
47
|
+
|
|
48
|
+
## Multiple Tool Providers Per Route
|
|
49
|
+
|
|
50
|
+
A route may combine capabilities from several business systems without weakening provider boundaries:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"sources": [
|
|
55
|
+
{ "provider": "orders", "allow": ["order.*"], "subject_field": "operator_uid" },
|
|
56
|
+
{ "provider": "shipping", "allow": ["shipment.read"] }
|
|
57
|
+
],
|
|
58
|
+
"max_calls": 8
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Each source keeps its own scope allowlist, subject mapping, signature secret, rate limits, approval records, and audit identity. The runtime presents one combined tool surface to the Agent, but dispatches every call back through the governance chain of its owning provider. Operation IDs must be unique across all sources attached to the same route; a collision is rejected before execution.
|
|
63
|
+
|
|
64
|
+
`max_calls` is a route-wide budget shared by all sources and configured independently per route. It prevents an Agent from multiplying the call budget simply by crossing provider boundaries. After each business-tool round, the runtime supplies trusted used and remaining counts; it guides the model to converge with one call left and removes all tools at exhaustion so the model must form a final answer.
|
|
65
|
+
|
|
66
|
+
Internal DSML-like tool-protocol markup in a final answer is intercepted, never displayed or parsed for execution, and receives at most one tool-free safe rewrite. A repeated violation fails closed. Streaming clients must discard provisional text when they receive `reset.reason=protocol_violation`.
|
|
67
|
+
|
|
68
|
+
## Risk Levels
|
|
69
|
+
|
|
70
|
+
| Risk | Typical use |
|
|
71
|
+
|---|---|
|
|
72
|
+
| `low` | Read-only query or deterministic preview. |
|
|
73
|
+
| `medium` | Create draft, submit request, or start a business workflow. |
|
|
74
|
+
| `high` | Immediate sensitive side effect such as refund execution, staff deletion, permission change, or batch outbound action. |
|
|
75
|
+
|
|
76
|
+
Risk level is guidance for the hub runtime. It does not replace business authorization.
|
|
77
|
+
|
|
78
|
+
## Approval Intent
|
|
79
|
+
|
|
80
|
+
The hub should not assume the approver is a hub administrator. In many real systems, the approver is a manager, finance operator, tenant admin, or business-side role.
|
|
81
|
+
|
|
82
|
+
The hub records the approval intent and frozen argument snapshot. The business system should usually own the approval UI and final decision.
|
|
83
|
+
|
|
84
|
+
## Signature Contract
|
|
85
|
+
|
|
86
|
+
Tool calls carry:
|
|
87
|
+
|
|
88
|
+
- `X-Bailing-Signature`;
|
|
89
|
+
- `X-Bailing-Timestamp`;
|
|
90
|
+
- `X-Bailing-Tool-Scope`;
|
|
91
|
+
- `X-Bailing-Job-Id`;
|
|
92
|
+
- `X-Bailing-On-Behalf-Of`;
|
|
93
|
+
- `X-Bailing-Idempotency-Key` for side-effecting calls.
|
|
94
|
+
|
|
95
|
+
The business system must verify the signature and timestamp before applying its own permission checks.
|
|
96
|
+
|
|
97
|
+
## Side-Effect Execution Journal
|
|
98
|
+
|
|
99
|
+
For a non-read-only, non-idempotent business tool, BailingHub persists a `dispatching` journal entry before sending the request. It records `response_recorded` after receiving an HTTP response and moves the entry to `completed` only after the result audit and terminal ledger update succeed.
|
|
100
|
+
|
|
101
|
+
If the durable execution journal is unavailable, BailingHub rejects a side-effecting tool before dispatch. It never falls back to sending first and recording only after success.
|
|
102
|
+
|
|
103
|
+
If a timeout, network interruption, process restart, result-audit failure, or terminal-ledger failure leaves the outcome uncertain, the journal remains in `dispatching`, `uncertain`, `response_recorded`, or `evidence_degraded`. Recovery checks unresolved journal entries before invoking the model, so protection does not depend on the model selecting the same tool again. A recovered runtime does not send the business request again. It returns:
|
|
104
|
+
|
|
105
|
+
```json
|
|
106
|
+
{
|
|
107
|
+
"governance_state": "reconciliation_required",
|
|
108
|
+
"auto_retry_allowed": false
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
This is deliberately not an exactly-once claim. Fail-closed behavior can freeze a request that never reached the business system. Operators must reconcile the durable job, subject, tool, canonical argument hash, and `X-Bailing-Idempotency-Key` against business-side records.
|
|
113
|
+
|
|
114
|
+
The business system should deduplicate side effects using `X-Bailing-Idempotency-Key` as defense in depth. The key is stable for the job, subject, tool, and canonical arguments. It does not replace signature verification, business authorization, or domain-specific idempotency rules.
|
|
115
|
+
|
|
116
|
+
The built-in `send_message` capability uses the same journal and recovery boundary. If any text chunk, card, or attachment may already have been delivered, a later failure is treated as an uncertain external effect. The runtime freezes the send for reconciliation instead of replaying the whole message.
|
|
117
|
+
|
|
118
|
+
## Multimodal Input Layer
|
|
119
|
+
|
|
120
|
+
Uploaded images, audio, video, and files are treated as untrusted input. They do not grant tool authority and must not be interpreted as approval evidence.
|
|
121
|
+
|
|
122
|
+
Audio handling is an explicit route policy:
|
|
123
|
+
|
|
124
|
+
- `transcribe` uses a dedicated speech model and sends only the resulting text to the main model;
|
|
125
|
+
- `inline` forwards audio only when the operator explicitly configures a main model that supports it;
|
|
126
|
+
- `off` rejects audio with deterministic user guidance.
|
|
127
|
+
|
|
128
|
+
Missing audio configuration defaults to `off`. If `transcribe` is selected but its credential, model, or endpoint cannot be resolved, the runtime fails closed. It does not forward the audio to the main model, infer content from file metadata, or silently switch protocols.
|
|
129
|
+
|
|
130
|
+
Dedicated speech models may use either the OpenAI-compatible `/audio/transcriptions` multipart protocol or the `/chat/completions` Data URL `input_audio` protocol. The selected protocol is part of route configuration and audit metadata.
|
|
131
|
+
|
|
132
|
+
Speech audit events may record the selected mode, protocol, model, MIME type, byte count, and outcome. They must not retain the audio body, Data URL, credential, or complete provider request.
|
|
133
|
+
|
|
134
|
+
## Parameter-Level Confirmation
|
|
135
|
+
|
|
136
|
+
Some tools are safe for small values but risky for large values. Use parameter-level confirmation rules for thresholds such as:
|
|
137
|
+
|
|
138
|
+
- amount;
|
|
139
|
+
- affected count;
|
|
140
|
+
- cross-tenant access;
|
|
141
|
+
- sensitive field access;
|
|
142
|
+
- external message delivery.
|