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,131 @@
|
|
|
1
|
+
# Dify + BailingHub Minimal Integration Recipe
|
|
2
|
+
|
|
3
|
+
> Status: maintainer-verified with a real Dify Cloud import and a harmless end-to-end request on 2026-07-18. Independent community reproduction is still pending. This document does not imply an official Dify partnership or certification.
|
|
4
|
+
|
|
5
|
+
[中文](README.md)
|
|
6
|
+
|
|
7
|
+
## When To Use This Recipe
|
|
8
|
+
|
|
9
|
+
When a Dify Agent or Workflow needs to operate an existing business system, do not import governed business APIs and business credentials directly into Dify. Expose only the BailingHub control plane:
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
Dify Agent / Workflow
|
|
13
|
+
-> POST /run create a governed job
|
|
14
|
+
-> GET /jobs/{job_id} read job status and result
|
|
15
|
+
-> BailingHub route, subject, risk, approval, and audit
|
|
16
|
+
-> business API final authorization remains in the business system
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This shape preserves three important boundaries:
|
|
20
|
+
|
|
21
|
+
1. Dify does not hold business-system credentials or call governed business APIs directly.
|
|
22
|
+
2. The dedicated Dify client can use only explicitly allowed BailingHub routes and cannot override `project` or `profile`.
|
|
23
|
+
3. Retries for the same business request reuse `request_id`, allowing BailingHub to enforce client-scoped idempotency.
|
|
24
|
+
|
|
25
|
+
## Prerequisites
|
|
26
|
+
|
|
27
|
+
Create a dedicated client in your self-hosted BailingHub instance:
|
|
28
|
+
|
|
29
|
+
- generate a dedicated Client Token; do not use an admin or executor token;
|
|
30
|
+
- allow only the routes Dify needs;
|
|
31
|
+
- configure an appropriate per-minute rate limit;
|
|
32
|
+
- do not provide business API keys, subject credentials, or production management credentials to Dify.
|
|
33
|
+
|
|
34
|
+
This recipe requires the BailingHub MySQL backend because client route allowlists and route resolution use persistent configuration.
|
|
35
|
+
|
|
36
|
+
## Import Into Dify
|
|
37
|
+
|
|
38
|
+
1. Open [bailinghub-control-plane.openapi.json](bailinghub-control-plane.openapi.json).
|
|
39
|
+
2. Replace `servers[0].url` with the HTTPS origin of your BailingHub instance, without a trailing slash.
|
|
40
|
+
3. In Dify, open `Tools -> Swagger API Tool -> Add Swagger API Tool`.
|
|
41
|
+
4. Paste the OpenAPI JSON.
|
|
42
|
+
5. Configure request-header authentication:
|
|
43
|
+
- header prefix: `Bearer`
|
|
44
|
+
- key: `Authorization`
|
|
45
|
+
- value: the raw BailingHub Client Token, without another `Bearer ` prefix
|
|
46
|
+
6. Save the tool. Dify should create:
|
|
47
|
+
- `bailinghub_start_job`
|
|
48
|
+
- `bailinghub_get_job`
|
|
49
|
+
|
|
50
|
+
## Agent Or Workflow Rules
|
|
51
|
+
|
|
52
|
+
Use the following as tool guidance:
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
To operate a business system, call bailinghub_start_job first. Never call the business API directly.
|
|
56
|
+
request_id must be unique for the business request. Reuse it only when retrying the same request.
|
|
57
|
+
Save the returned job_id and query it with bailinghub_get_job.
|
|
58
|
+
queued, running, and dispatched are non-terminal. done is success. error or rejected is terminal failure.
|
|
59
|
+
Do not change route arbitrarily. Never put BailingHub tokens, business credentials, or subject credentials in input.
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Generate `request_id` in a deterministic Workflow node rather than letting the model invent it. For example:
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
dify:<conversation-id>:<workflow-run-id>:<step-id>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Status Handling
|
|
69
|
+
|
|
70
|
+
| Status | Meaning | Next Dify Action |
|
|
71
|
+
| --- | --- | --- |
|
|
72
|
+
| `queued` | Accepted by the hub | Poll the same `job_id` later |
|
|
73
|
+
| `running` | Running in the hub | Poll later |
|
|
74
|
+
| `dispatched` | Claimed by an external executor | Poll later |
|
|
75
|
+
| `done` | Completed | Use `result` |
|
|
76
|
+
| `error` | Failed | Surface `error`; do not mutate arguments and retry automatically |
|
|
77
|
+
| `rejected` | Rejected by governance or a business boundary | Surface `error` and hand control to a user or administrator |
|
|
78
|
+
|
|
79
|
+
## Verified And Not Claimed
|
|
80
|
+
|
|
81
|
+
Verified:
|
|
82
|
+
|
|
83
|
+
- the OpenAPI document exposes only `/run` and `/jobs/{job_id}`;
|
|
84
|
+
- the start request exposes only `request_id`, `route`, and `input`;
|
|
85
|
+
- Dify Cloud creates both tools and sends a custom `Authorization` header;
|
|
86
|
+
- a real network request completed `queued -> done`;
|
|
87
|
+
- BailingHub enforces the client route allowlist, rate limit, job ownership, and idempotency key.
|
|
88
|
+
|
|
89
|
+
Not claimed:
|
|
90
|
+
|
|
91
|
+
- this does not prove that every model can reliably select both tools and poll to completion autonomously;
|
|
92
|
+
- Dify's Swagger API Tool does not provide bounded polling by itself; the Agent or Workflow must handle status explicitly;
|
|
93
|
+
- using Dify as a BailingHub external executor requires separate claim, heartbeat, tool-proxy, and result adapters.
|
|
94
|
+
|
|
95
|
+
## Verification
|
|
96
|
+
|
|
97
|
+
Run the dependency-free structural check without network access:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
python3 verify_contract.py
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Expected output:
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
PASS: Dify -> BailingHub minimal integration contract is structurally valid.
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
With a dedicated Client Token and a harmless test route, verify the real request path:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
BAILINGHUB_TOKEN='<dedicated client token>' \
|
|
113
|
+
python3 verify_e2e.py \
|
|
114
|
+
--base-url 'https://hub.example.com' \
|
|
115
|
+
--route 'dify-e2e'
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The verifier never prints the token. Do not run the default probe against a production write route, and do not use an admin token.
|
|
119
|
+
|
|
120
|
+
## Feedback
|
|
121
|
+
|
|
122
|
+
If you reproduce this integration independently, use the [independent validation report](https://github.com/bailinghub/bailinghub/issues/new?template=independent_validation.yml) and include the Dify shape you used (Agent or Workflow), the BailingHub version, the sanitized status sequence, and any friction you found. See the [Independent Validation Task](../../INDEPENDENT_VALIDATION.en.md) for the evidence rules and safety boundary. Never include tokens, business credentials, or production data.
|
|
123
|
+
|
|
124
|
+
## Primary References
|
|
125
|
+
|
|
126
|
+
- [Dify Tool Plugin](https://docs.dify.ai/en/develop-plugin/dev-guides-and-walkthroughs/tool-plugin)
|
|
127
|
+
- [Dify plugin type selection](https://docs.dify.ai/en/develop-plugin/getting-started/choose-plugin-type)
|
|
128
|
+
- [Dify Tool return values](https://docs.dify.ai/en/develop-plugin/features-and-specs/plugin-types/tool)
|
|
129
|
+
- [BailingHub HTTP contract](../../CONTRACT.en.md)
|
|
130
|
+
- BailingHub `src/routes/run.ts`
|
|
131
|
+
- BailingHub `src/routes/private.ts`
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Dify + BailingHub 最小接入配方
|
|
2
|
+
|
|
3
|
+
> 状态:维护者已于 2026-07-18 完成 Dify Cloud 真实导入和无副作用 E2E;外部独立复现仍待社区反馈。本文不代表 Dify 官方合作或认证。
|
|
4
|
+
|
|
5
|
+
[English](README.en.md)
|
|
6
|
+
|
|
7
|
+
## 适用场景
|
|
8
|
+
|
|
9
|
+
当 Dify Agent 或 Workflow 需要操作已有业务系统时,不要把受治理的业务 OpenAPI 和业务密钥直接交给 Dify。更小且边界清晰的接入方式是只向 Dify 暴露 BailingHub 控制面:
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
Dify Agent / Workflow
|
|
13
|
+
-> POST /run 创建受治理任务
|
|
14
|
+
-> GET /jobs/{job_id} 查询任务状态与结果
|
|
15
|
+
-> BailingHub 路由、主体、风险、审批、审计
|
|
16
|
+
-> business API 业务系统保留最终授权
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
这个配方具有三个重要性质:
|
|
20
|
+
|
|
21
|
+
1. Dify 不持有业务系统密钥,也不绕过 BailingHub 直接调用业务 API;
|
|
22
|
+
2. Dify 只能使用专用接入方被允许的 `route`,不能覆盖 `project` 或 `profile`;
|
|
23
|
+
3. 同一次业务请求重试时复用 `request_id`,由中枢在接入方范围内保证幂等。
|
|
24
|
+
|
|
25
|
+
## 前置准备
|
|
26
|
+
|
|
27
|
+
在自部署 BailingHub 中创建专用于 Dify 的接入方:
|
|
28
|
+
|
|
29
|
+
- 生成独立 Client Token,不使用管理员 Token 或执行器 Token;
|
|
30
|
+
- 只开放 Dify 实际需要的 route;
|
|
31
|
+
- 设置合理的每分钟限速;
|
|
32
|
+
- 不向 Dify 提供业务 API 密钥、主体凭据或生产管理凭据。
|
|
33
|
+
|
|
34
|
+
本配方要求 BailingHub 使用 MySQL 后端,因为接入方 route 白名单和 route 解析依赖持久化配置。
|
|
35
|
+
|
|
36
|
+
## 导入 Dify
|
|
37
|
+
|
|
38
|
+
1. 打开 [bailinghub-control-plane.openapi.json](bailinghub-control-plane.openapi.json)。
|
|
39
|
+
2. 将 `servers[0].url` 改为自部署 BailingHub 的 HTTPS 地址,不带末尾 `/`。
|
|
40
|
+
3. 在 Dify 工作区进入 `集成 -> 工具 -> Swagger API 作为工具 -> 添加 Swagger API 作为工具`。
|
|
41
|
+
4. 粘贴 OpenAPI JSON。
|
|
42
|
+
5. 鉴权方法选择 `请求头`:
|
|
43
|
+
- 鉴权头部前缀:`Bearer`
|
|
44
|
+
- 键:`Authorization`
|
|
45
|
+
- 值:只填写 BailingHub Client Token,不重复填写 `Bearer ` 前缀
|
|
46
|
+
6. 保存后应出现两个工具:
|
|
47
|
+
- `bailinghub_start_job`
|
|
48
|
+
- `bailinghub_get_job`
|
|
49
|
+
|
|
50
|
+
## Agent / Workflow 使用约束
|
|
51
|
+
|
|
52
|
+
可以把下面这段作为 Dify Agent 的工具说明:
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
需要操作业务系统时,只能先调用 bailinghub_start_job,不能直接调用业务 API。
|
|
56
|
+
request_id 必须对当前业务请求唯一;同一次请求重试时必须复用原 request_id。
|
|
57
|
+
保存返回的 job_id,并用 bailinghub_get_job 查询结果。
|
|
58
|
+
queued、running、dispatched 表示仍在执行;done 表示成功;error 或 rejected 表示失败并停止。
|
|
59
|
+
不得自行改变 route,不得把 BailingHub Token、业务密钥或主体凭据写入 input。
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
推荐由 Workflow 的确定性节点生成 `request_id`,不要让模型自由编写。例如:
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
dify:<conversation-id>:<workflow-run-id>:<step-id>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 状态处理
|
|
69
|
+
|
|
70
|
+
| 状态 | 含义 | Dify 下一步 |
|
|
71
|
+
| --- | --- | --- |
|
|
72
|
+
| `queued` | 已进入中枢队列 | 稍后查询同一 `job_id` |
|
|
73
|
+
| `running` | 中枢正在执行 | 稍后查询 |
|
|
74
|
+
| `dispatched` | 已派发给外部执行器 | 稍后查询 |
|
|
75
|
+
| `done` | 已完成 | 使用 `result` |
|
|
76
|
+
| `error` | 执行失败 | 展示 `error`,不要自动换参数重试 |
|
|
77
|
+
| `rejected` | 被治理或业务边界拒绝 | 展示 `error`,交由用户或管理员处理 |
|
|
78
|
+
|
|
79
|
+
## 已验证与未声称
|
|
80
|
+
|
|
81
|
+
已验证:
|
|
82
|
+
|
|
83
|
+
- OpenAPI 文件只暴露 BailingHub 的 `/run` 与 `/jobs/{job_id}`;
|
|
84
|
+
- 请求只包含 `request_id`、`route`、`input`,不暴露管理字段或业务凭据;
|
|
85
|
+
- Dify Cloud 的 Swagger API Tool 能创建两个工具并使用自定义 `Authorization` Header;
|
|
86
|
+
- 真实网络调用已完成 `queued -> done`;
|
|
87
|
+
- BailingHub 会校验接入方 route 白名单、限速、任务归属和幂等键。
|
|
88
|
+
|
|
89
|
+
未声称:
|
|
90
|
+
|
|
91
|
+
- 尚未证明任意模型都能稳定自主选工具并完成轮询;
|
|
92
|
+
- Dify Swagger API Tool 不会自动替使用者完成有界轮询,Agent 或 Workflow 需要显式处理状态;
|
|
93
|
+
- Dify 作为 BailingHub 外部执行器需要另一套 claim、heartbeat、tool proxy 和 result 适配,不属于本配方。
|
|
94
|
+
|
|
95
|
+
## 校验
|
|
96
|
+
|
|
97
|
+
结构校验不发起网络请求:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
python3 verify_contract.py
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
成功输出:
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
PASS: Dify -> BailingHub minimal integration contract is structurally valid.
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
在专用 Client Token 和无副作用测试 route 准备好后,可以复测真实链路:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
BAILINGHUB_TOKEN='<dedicated client token>' \
|
|
113
|
+
python3 verify_e2e.py \
|
|
114
|
+
--base-url 'https://hub.example.com' \
|
|
115
|
+
--route 'dify-e2e'
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
校验器不会打印 Token。请勿对生产写操作 route 运行默认测试,也不要使用管理员 Token。
|
|
119
|
+
|
|
120
|
+
## 反馈
|
|
121
|
+
|
|
122
|
+
如果你完成了独立复现,请使用 [独立验证报告模板](https://github.com/bailinghub/bailinghub/issues/new?template=independent_validation.yml),并附上 Dify 形态(Agent 或 Workflow)、BailingHub 版本、脱敏后的状态序列和遇到的问题。完整的证据口径与安全边界见 [独立验证任务卡](../../INDEPENDENT_VALIDATION.md)。不要提交 Token、业务密钥或生产数据。
|
|
123
|
+
|
|
124
|
+
## 一手依据
|
|
125
|
+
|
|
126
|
+
- [Dify Tool Plugin](https://docs.dify.ai/en/develop-plugin/dev-guides-and-walkthroughs/tool-plugin)
|
|
127
|
+
- [Dify plugin type selection](https://docs.dify.ai/en/develop-plugin/getting-started/choose-plugin-type)
|
|
128
|
+
- [Dify Tool return values](https://docs.dify.ai/en/develop-plugin/features-and-specs/plugin-types/tool)
|
|
129
|
+
- [BailingHub HTTP contract](../../CONTRACT.md)
|
|
130
|
+
- BailingHub `src/routes/run.ts`
|
|
131
|
+
- BailingHub `src/routes/private.ts`
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.0.3",
|
|
3
|
+
"info": {
|
|
4
|
+
"title": "BailingHub Control Plane for Dify",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"description": "Submit governed jobs to BailingHub and read their status. This tool does not expose business APIs directly."
|
|
7
|
+
},
|
|
8
|
+
"servers": [{ "url": "https://YOUR-BAILINGHUB-HOST" }],
|
|
9
|
+
"components": {
|
|
10
|
+
"securitySchemes": {
|
|
11
|
+
"bailinghubClientToken": {
|
|
12
|
+
"type": "http",
|
|
13
|
+
"scheme": "bearer",
|
|
14
|
+
"bearerFormat": "BailingHub Client Token"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"security": [{ "bailinghubClientToken": [] }],
|
|
19
|
+
"paths": {
|
|
20
|
+
"/run": {
|
|
21
|
+
"post": {
|
|
22
|
+
"operationId": "bailinghub_start_job",
|
|
23
|
+
"summary": "Start a governed BailingHub job",
|
|
24
|
+
"description": "Create one idempotent job through an allowed BailingHub route. Reuse request_id only when retrying the same business request.",
|
|
25
|
+
"requestBody": {
|
|
26
|
+
"required": true,
|
|
27
|
+
"content": {
|
|
28
|
+
"application/json": {
|
|
29
|
+
"schema": {
|
|
30
|
+
"type": "object",
|
|
31
|
+
"additionalProperties": false,
|
|
32
|
+
"required": ["request_id", "route", "input"],
|
|
33
|
+
"properties": {
|
|
34
|
+
"request_id": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"minLength": 1,
|
|
37
|
+
"maxLength": 128,
|
|
38
|
+
"description": "Stable idempotency key for this business request."
|
|
39
|
+
},
|
|
40
|
+
"route": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"pattern": "^[a-z0-9][a-z0-9_-]{1,63}$",
|
|
43
|
+
"description": "A route explicitly allowed for the Dify client in BailingHub."
|
|
44
|
+
},
|
|
45
|
+
"input": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"minLength": 1,
|
|
48
|
+
"description": "The business task or user instruction. Do not include credentials."
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"responses": {
|
|
56
|
+
"202": {
|
|
57
|
+
"description": "Job accepted or an existing idempotent job returned.",
|
|
58
|
+
"content": {
|
|
59
|
+
"application/json": {
|
|
60
|
+
"schema": {
|
|
61
|
+
"type": "object",
|
|
62
|
+
"required": ["job_id", "status", "request_id"],
|
|
63
|
+
"properties": {
|
|
64
|
+
"job_id": { "type": "string", "description": "Job identifier used for status polling." },
|
|
65
|
+
"status": {
|
|
66
|
+
"type": "string",
|
|
67
|
+
"enum": ["queued", "running", "dispatched", "done", "error", "rejected"]
|
|
68
|
+
},
|
|
69
|
+
"request_id": { "type": "string" },
|
|
70
|
+
"route": { "type": "string" },
|
|
71
|
+
"target": { "type": "string" }
|
|
72
|
+
},
|
|
73
|
+
"additionalProperties": true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"400": { "description": "Invalid request or unavailable route." },
|
|
79
|
+
"401": { "description": "Missing or invalid BailingHub client token." },
|
|
80
|
+
"403": { "description": "The client is not allowed to use the requested route." },
|
|
81
|
+
"409": { "description": "Idempotency conflict or ambiguous automatic route." },
|
|
82
|
+
"429": { "description": "Client rate limit exceeded." }
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"/jobs/{job_id}": {
|
|
87
|
+
"get": {
|
|
88
|
+
"operationId": "bailinghub_get_job",
|
|
89
|
+
"summary": "Read one BailingHub job",
|
|
90
|
+
"description": "Read a job created by the same BailingHub client. Poll only while the job is queued, running, or dispatched.",
|
|
91
|
+
"parameters": [
|
|
92
|
+
{
|
|
93
|
+
"name": "job_id",
|
|
94
|
+
"in": "path",
|
|
95
|
+
"required": true,
|
|
96
|
+
"schema": { "type": "string" },
|
|
97
|
+
"description": "The job_id returned by bailinghub_start_job."
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
"responses": {
|
|
101
|
+
"200": {
|
|
102
|
+
"description": "Current job state and, when terminal, result or error.",
|
|
103
|
+
"content": {
|
|
104
|
+
"application/json": {
|
|
105
|
+
"schema": {
|
|
106
|
+
"type": "object",
|
|
107
|
+
"required": ["job_id", "request_id", "status"],
|
|
108
|
+
"properties": {
|
|
109
|
+
"job_id": { "type": "string" },
|
|
110
|
+
"request_id": { "type": "string" },
|
|
111
|
+
"status": {
|
|
112
|
+
"type": "string",
|
|
113
|
+
"enum": ["queued", "running", "dispatched", "done", "error", "rejected"]
|
|
114
|
+
},
|
|
115
|
+
"result": { "description": "Final result when status is done." },
|
|
116
|
+
"error": { "type": "string", "description": "Failure or rejection reason when present." }
|
|
117
|
+
},
|
|
118
|
+
"additionalProperties": true
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"401": { "description": "Missing or invalid BailingHub client token." },
|
|
124
|
+
"404": { "description": "Job not found or not owned by this client." }
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Static, dependency-free checks for the Dify -> BailingHub OpenAPI recipe."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import copy
|
|
7
|
+
import json
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
SPEC_PATH = Path(__file__).with_name("bailinghub-control-plane.openapi.json")
|
|
13
|
+
ALLOWED_OPERATIONS = {
|
|
14
|
+
("/run", "post", "bailinghub_start_job"),
|
|
15
|
+
("/jobs/{job_id}", "get", "bailinghub_get_job"),
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def require(condition: bool, message: str) -> None:
|
|
20
|
+
if not condition:
|
|
21
|
+
raise AssertionError(message)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def validate(spec: dict[str, Any]) -> None:
|
|
25
|
+
require(spec.get("openapi") == "3.0.3", "OpenAPI version must be 3.0.3")
|
|
26
|
+
servers = spec.get("servers")
|
|
27
|
+
require(isinstance(servers, list) and len(servers) == 1, "exactly one server URL is required")
|
|
28
|
+
require(isinstance(servers[0].get("url"), str) and servers[0]["url"].startswith("https://"), "server URL must use HTTPS")
|
|
29
|
+
|
|
30
|
+
operations: set[tuple[str, str, str]] = set()
|
|
31
|
+
for path, path_item in spec.get("paths", {}).items():
|
|
32
|
+
require(path in {"/run", "/jobs/{job_id}"}, f"direct business path is forbidden: {path}")
|
|
33
|
+
for method in ("get", "post", "put", "patch", "delete"):
|
|
34
|
+
operation = path_item.get(method)
|
|
35
|
+
if operation is not None:
|
|
36
|
+
operation_id = operation.get("operationId")
|
|
37
|
+
require(isinstance(operation_id, str) and operation_id, f"missing operationId for {method.upper()} {path}")
|
|
38
|
+
operations.add((path, method, operation_id))
|
|
39
|
+
require(operations == ALLOWED_OPERATIONS, f"unexpected operations: {operations!r}")
|
|
40
|
+
|
|
41
|
+
start = spec["paths"]["/run"]["post"]
|
|
42
|
+
schema = start["requestBody"]["content"]["application/json"]["schema"]
|
|
43
|
+
required = set(schema.get("required", []))
|
|
44
|
+
require(required == {"request_id", "route", "input"}, "start request must require request_id, route, and input")
|
|
45
|
+
require(schema.get("additionalProperties") is False, "start request must reject undeclared control-plane fields")
|
|
46
|
+
require(set(schema.get("properties", {})) == required, "minimal recipe must not expose project, profile, tokens, or business credentials")
|
|
47
|
+
for name in required:
|
|
48
|
+
require(schema["properties"][name].get("type") == "string", f"{name} must be a string for Dify Swagger API Tool")
|
|
49
|
+
|
|
50
|
+
status = spec["paths"]["/jobs/{job_id}"]["get"]
|
|
51
|
+
path_params = [parameter for parameter in status.get("parameters", []) if parameter.get("in") == "path"]
|
|
52
|
+
require(len(path_params) == 1 and path_params[0].get("name") == "job_id", "status tool must require job_id as its only path parameter")
|
|
53
|
+
require(path_params[0].get("required") is True, "job_id path parameter must be required")
|
|
54
|
+
|
|
55
|
+
scheme = spec["components"]["securitySchemes"]["bailinghubClientToken"]
|
|
56
|
+
require(scheme.get("type") == "http" and scheme.get("scheme") == "bearer", "client authentication must use a bearer token")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def verify_negative_cases(spec: dict[str, Any]) -> None:
|
|
60
|
+
missing_id = copy.deepcopy(spec)
|
|
61
|
+
missing_id["paths"]["/run"]["post"]["requestBody"]["content"]["application/json"]["schema"]["required"].remove("request_id")
|
|
62
|
+
try:
|
|
63
|
+
validate(missing_id)
|
|
64
|
+
except AssertionError:
|
|
65
|
+
pass
|
|
66
|
+
else:
|
|
67
|
+
raise AssertionError("negative case failed: missing request_id was accepted")
|
|
68
|
+
|
|
69
|
+
bypass = copy.deepcopy(spec)
|
|
70
|
+
bypass["paths"]["/orders/refund"] = {"post": {"operationId": "refund_directly"}}
|
|
71
|
+
try:
|
|
72
|
+
validate(bypass)
|
|
73
|
+
except AssertionError:
|
|
74
|
+
pass
|
|
75
|
+
else:
|
|
76
|
+
raise AssertionError("negative case failed: direct business API path was accepted")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def main() -> None:
|
|
80
|
+
with SPEC_PATH.open("r", encoding="utf-8") as handle:
|
|
81
|
+
spec = json.load(handle)
|
|
82
|
+
validate(spec)
|
|
83
|
+
verify_negative_cases(spec)
|
|
84
|
+
print("PASS: Dify -> BailingHub minimal integration contract is structurally valid.")
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if __name__ == "__main__":
|
|
88
|
+
main()
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Run a minimal BailingHub /run -> /jobs/{id} integration check.
|
|
3
|
+
|
|
4
|
+
The client token is read from BAILINGHUB_TOKEN and is never printed.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import argparse
|
|
10
|
+
import json
|
|
11
|
+
import os
|
|
12
|
+
import sys
|
|
13
|
+
import time
|
|
14
|
+
import uuid
|
|
15
|
+
from typing import Any
|
|
16
|
+
from urllib.error import HTTPError, URLError
|
|
17
|
+
from urllib.request import Request, urlopen
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
TERMINAL_STATUSES = {"done", "error", "rejected"}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def fail(message: str) -> None:
|
|
24
|
+
print(f"FAIL: {message}", file=sys.stderr)
|
|
25
|
+
raise SystemExit(1)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def request_json(method: str, url: str, token: str, body: dict[str, Any] | None = None) -> dict[str, Any]:
|
|
29
|
+
payload = None if body is None else json.dumps(body, ensure_ascii=False).encode("utf-8")
|
|
30
|
+
request = Request(
|
|
31
|
+
url,
|
|
32
|
+
data=payload,
|
|
33
|
+
method=method,
|
|
34
|
+
headers={
|
|
35
|
+
"Accept": "application/json",
|
|
36
|
+
"Authorization": f"Bearer {token}",
|
|
37
|
+
**({"Content-Type": "application/json"} if payload is not None else {}),
|
|
38
|
+
},
|
|
39
|
+
)
|
|
40
|
+
try:
|
|
41
|
+
with urlopen(request, timeout=30) as response:
|
|
42
|
+
raw = response.read().decode("utf-8")
|
|
43
|
+
except HTTPError as exc:
|
|
44
|
+
detail = exc.read().decode("utf-8", errors="replace")
|
|
45
|
+
fail(f"{method} {url} returned HTTP {exc.code}: {detail[:500]}")
|
|
46
|
+
except URLError as exc:
|
|
47
|
+
fail(f"{method} {url} failed: {exc.reason}")
|
|
48
|
+
|
|
49
|
+
try:
|
|
50
|
+
decoded = json.loads(raw)
|
|
51
|
+
except json.JSONDecodeError:
|
|
52
|
+
fail(f"{method} {url} did not return JSON: {raw[:500]}")
|
|
53
|
+
if not isinstance(decoded, dict):
|
|
54
|
+
fail(f"{method} {url} returned a non-object JSON value")
|
|
55
|
+
return decoded
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def parse_args() -> argparse.Namespace:
|
|
59
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
60
|
+
parser.add_argument("--base-url", required=True, help="BailingHub HTTPS origin, without a trailing slash")
|
|
61
|
+
parser.add_argument("--route", required=True, help="A harmless route allowed for the dedicated Dify client")
|
|
62
|
+
parser.add_argument(
|
|
63
|
+
"--input",
|
|
64
|
+
default="Return exactly DIFY_BAILINGHUB_E2E_OK. Do not call any business tool.",
|
|
65
|
+
help="Harmless input sent through the selected route",
|
|
66
|
+
)
|
|
67
|
+
parser.add_argument("--timeout", type=int, default=180, help="Maximum polling time in seconds")
|
|
68
|
+
parser.add_argument("--interval", type=float, default=2.0, help="Polling interval in seconds")
|
|
69
|
+
return parser.parse_args()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def main() -> None:
|
|
73
|
+
args = parse_args()
|
|
74
|
+
token = os.environ.get("BAILINGHUB_TOKEN", "").strip()
|
|
75
|
+
if not token:
|
|
76
|
+
fail("set BAILINGHUB_TOKEN to a dedicated BailingHub client token")
|
|
77
|
+
|
|
78
|
+
base_url = args.base_url.rstrip("/")
|
|
79
|
+
request_id = f"dify-e2e:{int(time.time())}:{uuid.uuid4().hex[:12]}"
|
|
80
|
+
created = request_json(
|
|
81
|
+
"POST",
|
|
82
|
+
f"{base_url}/run",
|
|
83
|
+
token,
|
|
84
|
+
{"request_id": request_id, "route": args.route, "input": args.input},
|
|
85
|
+
)
|
|
86
|
+
job_id = str(created.get("job_id", "")).strip()
|
|
87
|
+
if not job_id:
|
|
88
|
+
fail(f"/run response has no job_id: {json.dumps(created, ensure_ascii=False)}")
|
|
89
|
+
if created.get("request_id") != request_id:
|
|
90
|
+
fail("/run response request_id does not match the submitted idempotency key")
|
|
91
|
+
|
|
92
|
+
print(f"created job_id={job_id} status={created.get('status', 'unknown')} route={created.get('route', args.route)}")
|
|
93
|
+
deadline = time.monotonic() + max(1, args.timeout)
|
|
94
|
+
last_status = ""
|
|
95
|
+
job: dict[str, Any] = {}
|
|
96
|
+
while time.monotonic() < deadline:
|
|
97
|
+
job = request_json("GET", f"{base_url}/jobs/{job_id}", token)
|
|
98
|
+
status = str(job.get("status", "")).strip()
|
|
99
|
+
if status != last_status:
|
|
100
|
+
print(f"status={status or 'unknown'}")
|
|
101
|
+
last_status = status
|
|
102
|
+
if status in TERMINAL_STATUSES:
|
|
103
|
+
break
|
|
104
|
+
time.sleep(max(0.2, args.interval))
|
|
105
|
+
else:
|
|
106
|
+
fail(f"job {job_id} did not reach a terminal status within {args.timeout}s")
|
|
107
|
+
|
|
108
|
+
status = str(job.get("status", ""))
|
|
109
|
+
if status != "done":
|
|
110
|
+
detail = job.get("error") or job.get("result") or "no error detail"
|
|
111
|
+
fail(f"job {job_id} ended with status={status}: {str(detail)[:500]}")
|
|
112
|
+
|
|
113
|
+
print(f"PASS: BailingHub E2E completed for request_id={request_id} job_id={job_id}")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
if __name__ == "__main__":
|
|
117
|
+
main()
|