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,376 @@
|
|
|
1
|
+
package com.bailing.connect;
|
|
2
|
+
|
|
3
|
+
import java.io.IOException;
|
|
4
|
+
import java.net.URI;
|
|
5
|
+
import java.net.URLEncoder;
|
|
6
|
+
import java.net.http.HttpClient;
|
|
7
|
+
import java.net.http.HttpRequest;
|
|
8
|
+
import java.net.http.HttpResponse;
|
|
9
|
+
import java.nio.charset.StandardCharsets;
|
|
10
|
+
import java.security.MessageDigest;
|
|
11
|
+
import java.time.Duration;
|
|
12
|
+
import java.time.Instant;
|
|
13
|
+
import java.util.ArrayList;
|
|
14
|
+
import java.util.Base64;
|
|
15
|
+
import java.util.LinkedHashMap;
|
|
16
|
+
import java.util.List;
|
|
17
|
+
import java.util.Map;
|
|
18
|
+
import java.util.Objects;
|
|
19
|
+
import java.util.function.Predicate;
|
|
20
|
+
import javax.crypto.Mac;
|
|
21
|
+
import javax.crypto.spec.SecretKeySpec;
|
|
22
|
+
|
|
23
|
+
public final class BailingConnect {
|
|
24
|
+
private BailingConnect() {}
|
|
25
|
+
|
|
26
|
+
public static String signTicket(String clientToken, String uid) {
|
|
27
|
+
return signTicket(clientToken, uid, 7200);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public static String signTicket(String clientToken, String uid, long ttlSeconds) {
|
|
31
|
+
return signTicketExpiresAt(clientToken, uid, Instant.now().getEpochSecond() + ttlSeconds);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public static String signTicketExpiresAt(String clientToken, String uid, long expiresAt) {
|
|
35
|
+
if (uid == null || uid.isEmpty() || uid.getBytes(StandardCharsets.UTF_8).length > 64) {
|
|
36
|
+
throw new IllegalArgumentException("uid must be 1..64 bytes");
|
|
37
|
+
}
|
|
38
|
+
String payload = base64Url(toJson(mapOf("uid", uid, "exp", expiresAt)));
|
|
39
|
+
return "v1." + payload + "." + hmacHex(clientToken, payload);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public static String signToolCall(String secret, long ts, String method, String pathWithQuery, String body, String onBehalfOf, String jobId) {
|
|
43
|
+
String msg = ts + "." + method.toUpperCase() + "." + pathWithQuery + "." + sha256Hex(body == null ? "" : body) + "." + safe(onBehalfOf) + "." + safe(jobId);
|
|
44
|
+
return "sha256=" + hmacHex(secret, msg);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public static boolean verifyToolCall(String secret, String method, String pathWithQuery, String body, long timestamp, String signature,
|
|
48
|
+
String onBehalfOf, String jobId, long windowSec) {
|
|
49
|
+
if (signature == null || Math.abs(Instant.now().getEpochSecond() - timestamp) >= windowSec) return false;
|
|
50
|
+
return MessageDigest.isEqual(
|
|
51
|
+
signToolCall(secret, timestamp, method, pathWithQuery, body, onBehalfOf, jobId).getBytes(StandardCharsets.UTF_8),
|
|
52
|
+
signature.getBytes(StandardCharsets.UTF_8)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public static boolean verifyCallback(String secret, String rawBody, long timestampMs, String signature, long windowMs) {
|
|
57
|
+
if (signature == null || Math.abs(System.currentTimeMillis() - timestampMs) >= windowMs) return false;
|
|
58
|
+
String expected = "sha256=" + hmacHex(secret, timestampMs + "." + safe(rawBody));
|
|
59
|
+
return MessageDigest.isEqual(expected.getBytes(StandardCharsets.UTF_8), signature.getBytes(StandardCharsets.UTF_8));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public static ProbeResult authzProbeResponse(String secret, String method, String pathWithQuery, String body, long timestamp,
|
|
63
|
+
String signature, String onBehalfOf, String jobId, Predicate<String> authorize) {
|
|
64
|
+
boolean ok = verifyToolCall(secret, method, pathWithQuery, body, timestamp, signature, onBehalfOf, jobId, 300);
|
|
65
|
+
if (!ok) return new ProbeResult(401, mapOf("authorized", false, "error", "bad_signature"));
|
|
66
|
+
String subject = firstJsonString(body, "subject", safe(onBehalfOf));
|
|
67
|
+
boolean authorized = false;
|
|
68
|
+
try { authorized = authorize.test(subject); } catch (RuntimeException ignored) { authorized = false; }
|
|
69
|
+
return new ProbeResult(200, mapOf("authorized", authorized));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private static Map<String, Object> normalizeRateLimit(String value) {
|
|
73
|
+
if (value == null || value.isBlank()) return null;
|
|
74
|
+
String text = value.replaceAll("\\s+", "").toLowerCase();
|
|
75
|
+
String[] parts = text.split("/", 2);
|
|
76
|
+
if (parts.length != 2) return null;
|
|
77
|
+
int count;
|
|
78
|
+
try { count = Integer.parseInt(parts[0]); } catch (NumberFormatException e) { return null; }
|
|
79
|
+
String unit = parts[1];
|
|
80
|
+
String window;
|
|
81
|
+
if ("s".equals(unit) || "sec".equals(unit) || "second".equals(unit)) window = "1s";
|
|
82
|
+
else if ("h".equals(unit) || "hour".equals(unit)) window = "1h";
|
|
83
|
+
else if ("d".equals(unit) || "day".equals(unit)) window = "1d";
|
|
84
|
+
else if ("m".equals(unit) || "min".equals(unit) || "minute".equals(unit)) window = "1m";
|
|
85
|
+
else return null;
|
|
86
|
+
return mapOf("count", count, "window", window);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private static Map<String, Object> buildCapability(Tool t, String method) {
|
|
90
|
+
Map<String, Object> capability = mapOf("version", 1, "enabled", true, "scope", t.scope);
|
|
91
|
+
if (t.risk != null && !"low".equals(t.risk)) capability.put("risk", mapOf("level", t.risk));
|
|
92
|
+
if (t.confirm || !t.confirmWhen.isEmpty() || t.confirmPrompt != null) {
|
|
93
|
+
Map<String, Object> approval = new LinkedHashMap<>();
|
|
94
|
+
if (t.confirm) approval.put("required", true);
|
|
95
|
+
if (!t.confirmWhen.isEmpty()) approval.put("when", t.confirmWhen);
|
|
96
|
+
if (t.confirmPrompt != null) approval.put("prompt", t.confirmPrompt);
|
|
97
|
+
capability.put("approval", approval);
|
|
98
|
+
}
|
|
99
|
+
if (t.requiresSubject) capability.put("subject", mapOf("required", true));
|
|
100
|
+
Map<String, Object> execution = new LinkedHashMap<>();
|
|
101
|
+
if (Boolean.TRUE.equals(t.readonly) && !"GET".equals(method)) execution.put("readonly", true);
|
|
102
|
+
if (Boolean.TRUE.equals(t.idempotent) && !"GET".equals(method)) execution.put("idempotent", true);
|
|
103
|
+
Map<String, Object> rateLimit = normalizeRateLimit(t.rateLimit);
|
|
104
|
+
if (rateLimit != null) execution.put("rate_limit", rateLimit);
|
|
105
|
+
if (t.timeoutMs != null) execution.put("timeout_ms", t.timeoutMs);
|
|
106
|
+
if (!execution.isEmpty()) capability.put("execution", execution);
|
|
107
|
+
if (t.sensitive) capability.put("audit", mapOf("sensitive", true));
|
|
108
|
+
Map<String, Object> guidance = new LinkedHashMap<>();
|
|
109
|
+
if (t.whenToUse != null) guidance.put("when_to_use", t.whenToUse);
|
|
110
|
+
if (t.returns != null) guidance.put("returns", t.returns);
|
|
111
|
+
if (!t.examples.isEmpty()) guidance.put("examples", t.examples);
|
|
112
|
+
if (!t.context.isEmpty()) guidance.put("context", t.context);
|
|
113
|
+
if (!guidance.isEmpty()) capability.put("guidance", guidance);
|
|
114
|
+
return capability;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public static Map<String, Object> buildOpenApiSpec(String title, String version, List<Tool> tools, Map<String, String> authzProbe) {
|
|
118
|
+
Map<String, Object> paths = new LinkedHashMap<>();
|
|
119
|
+
for (Tool t : tools) {
|
|
120
|
+
String method = t.method.toUpperCase();
|
|
121
|
+
String operationId = t.name != null && !t.name.isEmpty() ? t.name : defaultName(method, t.path);
|
|
122
|
+
Map<String, Object> op = mapOf("operationId", operationId, "summary", t.description, "x-agent-capability", buildCapability(t, method));
|
|
123
|
+
if (!t.tags.isEmpty()) op.put("tags", t.tags);
|
|
124
|
+
if (t.deprecated) op.put("deprecated", true);
|
|
125
|
+
|
|
126
|
+
List<Object> queryParams = new ArrayList<>();
|
|
127
|
+
Map<String, Object> bodyProps = new LinkedHashMap<>();
|
|
128
|
+
List<String> bodyRequired = new ArrayList<>();
|
|
129
|
+
for (Param p : t.params) {
|
|
130
|
+
Map<String, Object> schema = new LinkedHashMap<>();
|
|
131
|
+
schema.put("type", p.type);
|
|
132
|
+
if (p.description != null) schema.put("description", p.description);
|
|
133
|
+
if (!p.enums.isEmpty()) schema.put("enum", p.enums);
|
|
134
|
+
if (p.format != null) schema.put("format", p.format);
|
|
135
|
+
if ("array".equals(p.type)) schema.put("items", mapOf("type", p.itemsType));
|
|
136
|
+
String loc = p.in != null ? p.in : ("GET".equals(method) ? "query" : "body");
|
|
137
|
+
if ("query".equals(loc) || "path".equals(loc)) {
|
|
138
|
+
queryParams.add(mapOf("name", p.name, "in", loc, "required", p.required, "schema", schema));
|
|
139
|
+
} else {
|
|
140
|
+
bodyProps.put(p.name, schema);
|
|
141
|
+
if (p.required) bodyRequired.add(p.name);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (!queryParams.isEmpty()) op.put("parameters", queryParams);
|
|
145
|
+
if (!bodyProps.isEmpty()) {
|
|
146
|
+
Map<String, Object> schema = mapOf("type", "object", "properties", bodyProps);
|
|
147
|
+
if (!bodyRequired.isEmpty()) schema.put("required", bodyRequired);
|
|
148
|
+
op.put("requestBody", mapOf("content", mapOf("application/json", mapOf("schema", schema))));
|
|
149
|
+
}
|
|
150
|
+
@SuppressWarnings("unchecked")
|
|
151
|
+
Map<String, Object> pathItem = (Map<String, Object>) paths.computeIfAbsent(t.path, k -> new LinkedHashMap<String, Object>());
|
|
152
|
+
pathItem.put(method.toLowerCase(), op);
|
|
153
|
+
}
|
|
154
|
+
Map<String, Object> spec = mapOf("openapi", "3.0.0", "info", mapOf("title", title, "version", version), "paths", paths);
|
|
155
|
+
if (authzProbe != null) spec.put("x-bailing-authz-probe", authzProbe);
|
|
156
|
+
return spec;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public static String toJson(Object value) {
|
|
160
|
+
if (value == null) return "null";
|
|
161
|
+
if (value instanceof String) return quote((String) value);
|
|
162
|
+
if (value instanceof Number || value instanceof Boolean) return String.valueOf(value);
|
|
163
|
+
if (value instanceof Map<?, ?>) {
|
|
164
|
+
StringBuilder sb = new StringBuilder("{");
|
|
165
|
+
boolean first = true;
|
|
166
|
+
for (Map.Entry<?, ?> e : ((Map<?, ?>) value).entrySet()) {
|
|
167
|
+
if (!first) sb.append(',');
|
|
168
|
+
first = false;
|
|
169
|
+
sb.append(quote(String.valueOf(e.getKey()))).append(':').append(toJson(e.getValue()));
|
|
170
|
+
}
|
|
171
|
+
return sb.append('}').toString();
|
|
172
|
+
}
|
|
173
|
+
if (value instanceof Iterable<?>) {
|
|
174
|
+
StringBuilder sb = new StringBuilder("[");
|
|
175
|
+
boolean first = true;
|
|
176
|
+
for (Object item : (Iterable<?>) value) {
|
|
177
|
+
if (!first) sb.append(',');
|
|
178
|
+
first = false;
|
|
179
|
+
sb.append(toJson(item));
|
|
180
|
+
}
|
|
181
|
+
return sb.append(']').toString();
|
|
182
|
+
}
|
|
183
|
+
return quote(String.valueOf(value));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public static Map<String, Object> mapOf(Object... kv) {
|
|
187
|
+
Map<String, Object> out = new LinkedHashMap<>();
|
|
188
|
+
for (int i = 0; i + 1 < kv.length; i += 2) out.put(String.valueOf(kv[i]), kv[i + 1]);
|
|
189
|
+
return out;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private static String sha256Hex(String text) {
|
|
193
|
+
try {
|
|
194
|
+
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
|
195
|
+
return hex(md.digest(text.getBytes(StandardCharsets.UTF_8)));
|
|
196
|
+
} catch (Exception e) {
|
|
197
|
+
throw new RuntimeException(e);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private static String hmacHex(String secret, String msg) {
|
|
202
|
+
try {
|
|
203
|
+
Mac mac = Mac.getInstance("HmacSHA256");
|
|
204
|
+
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
|
|
205
|
+
return hex(mac.doFinal(msg.getBytes(StandardCharsets.UTF_8)));
|
|
206
|
+
} catch (Exception e) {
|
|
207
|
+
throw new RuntimeException(e);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private static String hex(byte[] bytes) {
|
|
212
|
+
StringBuilder sb = new StringBuilder(bytes.length * 2);
|
|
213
|
+
for (byte b : bytes) sb.append(String.format("%02x", b));
|
|
214
|
+
return sb.toString();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private static String base64Url(String text) {
|
|
218
|
+
return Base64.getUrlEncoder().withoutPadding().encodeToString(text.getBytes(StandardCharsets.UTF_8));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private static String quote(String s) {
|
|
222
|
+
StringBuilder sb = new StringBuilder("\"");
|
|
223
|
+
for (int i = 0; i < s.length(); i++) {
|
|
224
|
+
char c = s.charAt(i);
|
|
225
|
+
switch (c) {
|
|
226
|
+
case '"': sb.append("\\\""); break;
|
|
227
|
+
case '\\': sb.append("\\\\"); break;
|
|
228
|
+
case '\n': sb.append("\\n"); break;
|
|
229
|
+
case '\r': sb.append("\\r"); break;
|
|
230
|
+
case '\t': sb.append("\\t"); break;
|
|
231
|
+
default: sb.append(c < 0x20 ? String.format("\\u%04x", (int) c) : c);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return sb.append('"').toString();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private static String defaultName(String method, String path) {
|
|
238
|
+
return (method.toLowerCase() + "_" + path).replaceAll("[^a-zA-Z0-9]+", "_").replaceAll("^_+|_+$", "");
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
private static String safe(String s) { return s == null ? "" : s; }
|
|
242
|
+
|
|
243
|
+
private static String firstJsonString(String json, String key, String fallback) {
|
|
244
|
+
if (json == null) return fallback;
|
|
245
|
+
String needle = "\"" + key + "\"";
|
|
246
|
+
int p = json.indexOf(needle);
|
|
247
|
+
if (p < 0) return fallback;
|
|
248
|
+
int colon = json.indexOf(':', p + needle.length());
|
|
249
|
+
int start = colon < 0 ? -1 : json.indexOf('"', colon);
|
|
250
|
+
int end = start < 0 ? -1 : json.indexOf('"', start + 1);
|
|
251
|
+
return start >= 0 && end > start ? json.substring(start + 1, end) : fallback;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
public static final class ProbeResult {
|
|
255
|
+
public final int status;
|
|
256
|
+
public final Map<String, Object> body;
|
|
257
|
+
public ProbeResult(int status, Map<String, Object> body) {
|
|
258
|
+
this.status = status;
|
|
259
|
+
this.body = body;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
public static final class Param {
|
|
264
|
+
public final String name;
|
|
265
|
+
public String in;
|
|
266
|
+
public String type = "string";
|
|
267
|
+
public String itemsType = "string";
|
|
268
|
+
public String description;
|
|
269
|
+
public boolean required;
|
|
270
|
+
public String format;
|
|
271
|
+
public final List<String> enums = new ArrayList<>();
|
|
272
|
+
public Param(String name) { this.name = Objects.requireNonNull(name); }
|
|
273
|
+
public Param in(String v) { this.in = v; return this; }
|
|
274
|
+
public Param type(String v) { this.type = v; return this; }
|
|
275
|
+
public Param itemsType(String v) { this.itemsType = v; return this; }
|
|
276
|
+
public Param description(String v) { this.description = v; return this; }
|
|
277
|
+
public Param required(boolean v) { this.required = v; return this; }
|
|
278
|
+
public Param format(String v) { this.format = v; return this; }
|
|
279
|
+
public Param enums(String... values) { this.enums.addAll(List.of(values)); return this; }
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
public static final class Tool {
|
|
283
|
+
public final String description;
|
|
284
|
+
public final String scope;
|
|
285
|
+
public final String path;
|
|
286
|
+
public String method = "GET";
|
|
287
|
+
public String name;
|
|
288
|
+
public String risk = "low";
|
|
289
|
+
public boolean confirm;
|
|
290
|
+
public Boolean readonly;
|
|
291
|
+
public boolean requiresSubject;
|
|
292
|
+
public Boolean idempotent;
|
|
293
|
+
public boolean sensitive;
|
|
294
|
+
public String rateLimit;
|
|
295
|
+
public Integer timeoutMs;
|
|
296
|
+
public String whenToUse;
|
|
297
|
+
public String returns;
|
|
298
|
+
public String confirmPrompt;
|
|
299
|
+
public boolean deprecated;
|
|
300
|
+
public final List<Param> params = new ArrayList<>();
|
|
301
|
+
public final List<Object> confirmWhen = new ArrayList<>();
|
|
302
|
+
public final List<Object> examples = new ArrayList<>();
|
|
303
|
+
public final List<Object> context = new ArrayList<>();
|
|
304
|
+
public final List<String> tags = new ArrayList<>();
|
|
305
|
+
public Tool(String description, String scope, String path) {
|
|
306
|
+
this.description = Objects.requireNonNull(description);
|
|
307
|
+
this.scope = Objects.requireNonNull(scope);
|
|
308
|
+
this.path = Objects.requireNonNull(path);
|
|
309
|
+
}
|
|
310
|
+
public Tool method(String v) { this.method = v; return this; }
|
|
311
|
+
public Tool name(String v) { this.name = v; return this; }
|
|
312
|
+
public Tool risk(String v) { this.risk = v; return this; }
|
|
313
|
+
public Tool confirm(boolean v) { this.confirm = v; return this; }
|
|
314
|
+
public Tool readonly(boolean v) { this.readonly = v; return this; }
|
|
315
|
+
public Tool requiresSubject(boolean v) { this.requiresSubject = v; return this; }
|
|
316
|
+
public Tool idempotent(boolean v) { this.idempotent = v; return this; }
|
|
317
|
+
public Tool sensitive(boolean v) { this.sensitive = v; return this; }
|
|
318
|
+
public Tool rateLimit(String v) { this.rateLimit = v; return this; }
|
|
319
|
+
public Tool timeoutMs(int v) { this.timeoutMs = v; return this; }
|
|
320
|
+
public Tool whenToUse(String v) { this.whenToUse = v; return this; }
|
|
321
|
+
public Tool returns(String v) { this.returns = v; return this; }
|
|
322
|
+
public Tool confirmPrompt(String v) { this.confirmPrompt = v; return this; }
|
|
323
|
+
public Tool deprecated(boolean v) { this.deprecated = v; return this; }
|
|
324
|
+
public Tool param(Param p) { this.params.add(p); return this; }
|
|
325
|
+
public Tool tag(String v) { this.tags.add(v); return this; }
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
public static final class HubClient {
|
|
329
|
+
private final String baseUrl;
|
|
330
|
+
private final String token;
|
|
331
|
+
private final Duration timeout;
|
|
332
|
+
private final HttpClient client;
|
|
333
|
+
|
|
334
|
+
public HubClient(String baseUrl, String token) {
|
|
335
|
+
this(baseUrl, token, Duration.ofSeconds(8));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
public HubClient(String baseUrl, String token, Duration timeout) {
|
|
339
|
+
this.baseUrl = baseUrl.replaceAll("/+$", "");
|
|
340
|
+
this.token = token;
|
|
341
|
+
this.timeout = timeout;
|
|
342
|
+
this.client = HttpClient.newHttpClient();
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
public String run(String requestId, String route, String input, Map<String, Object> metadata) throws IOException, InterruptedException {
|
|
346
|
+
return post("/run", mapOf("request_id", requestId, "route", route, "input", input, "metadata", metadata == null ? Map.of() : metadata));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
public String getJob(String jobId) throws IOException, InterruptedException {
|
|
350
|
+
return get("/jobs/" + URLEncoder.encode(jobId, StandardCharsets.UTF_8));
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
public String send(String requestId, String channel, Object to, String text) throws IOException, InterruptedException {
|
|
354
|
+
return post("/send", mapOf("request_id", requestId, "channel", channel, "to", to, "text", text));
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
public String get(String path) throws IOException, InterruptedException {
|
|
358
|
+
return request("GET", path, null);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
public String post(String path, Map<String, Object> body) throws IOException, InterruptedException {
|
|
362
|
+
return request("POST", path, toJson(body));
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
public String request(String method, String path, String body) throws IOException, InterruptedException {
|
|
366
|
+
HttpRequest.Builder b = HttpRequest.newBuilder(URI.create(baseUrl + path))
|
|
367
|
+
.timeout(timeout)
|
|
368
|
+
.header("Authorization", "Bearer " + token);
|
|
369
|
+
if (body != null) b.header("Content-Type", "application/json").method(method, HttpRequest.BodyPublishers.ofString(body));
|
|
370
|
+
else b.method(method, HttpRequest.BodyPublishers.noBody());
|
|
371
|
+
HttpResponse<String> res = client.send(b.build(), HttpResponse.BodyHandlers.ofString());
|
|
372
|
+
if (res.statusCode() < 200 || res.statusCode() >= 300) throw new IOException("HTTP " + res.statusCode() + ": " + res.body());
|
|
373
|
+
return res.body();
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# 百灵中枢 Node SDK
|
|
2
|
+
|
|
3
|
+
业务系统侧 SDK,用来生成工具源 OpenAPI、签发聊天访客票据、校验中枢工具调用签名、校验 callback 签名、实现 authorize 探针,并调用中枢 `/run`、`/jobs/{id}`、`/send`。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @bailinghub/connect
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
仓库内本地验证:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
node sdk/node/examples/build-spec.mjs > tools.json
|
|
15
|
+
node sdk/node/examples/build-spec.mjs | npm run sdk:test-node
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 生成工具源
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
import { buildOpenApiSpec, param, tool } from '@bailinghub/connect';
|
|
22
|
+
|
|
23
|
+
const spec = buildOpenApiSpec({
|
|
24
|
+
title: 'CRM 工具源',
|
|
25
|
+
version: '1.0.0',
|
|
26
|
+
authzProbe: { method: 'POST', path: '/.well-known/bailing/authz-probe' },
|
|
27
|
+
tools: [
|
|
28
|
+
tool({
|
|
29
|
+
name: 'member_query',
|
|
30
|
+
method: 'GET',
|
|
31
|
+
path: '/api/members/{id}',
|
|
32
|
+
description: '查询会员基础资料',
|
|
33
|
+
scope: 'member.read',
|
|
34
|
+
requiresSubject: true,
|
|
35
|
+
params: [
|
|
36
|
+
param('id', { in: 'path', required: true, description: '会员 ID' })
|
|
37
|
+
]
|
|
38
|
+
}),
|
|
39
|
+
tool({
|
|
40
|
+
name: 'refund_request_create',
|
|
41
|
+
method: 'POST',
|
|
42
|
+
path: '/api/refunds/requests',
|
|
43
|
+
description: '创建退款申请',
|
|
44
|
+
scope: 'refund.request',
|
|
45
|
+
risk: 'medium',
|
|
46
|
+
requiresSubject: true,
|
|
47
|
+
confirmWhen: [{ param: 'amount', op: '>', value: 500, label: '超过 500 元退款需人工确认' }],
|
|
48
|
+
params: [
|
|
49
|
+
param('order_id', { required: true, description: '订单 ID' }),
|
|
50
|
+
param('amount', { type: 'number', required: true, description: '退款金额,单位元' }),
|
|
51
|
+
param('reason', { required: true, description: '退款原因' })
|
|
52
|
+
]
|
|
53
|
+
})
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
console.log(JSON.stringify(spec, null, 2));
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 验签与授权
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import { verifyToolCall } from '@bailinghub/connect';
|
|
64
|
+
|
|
65
|
+
const rawBody = await request.text();
|
|
66
|
+
const pathWithQuery = new URL(request.url).pathname + new URL(request.url).search;
|
|
67
|
+
const onBehalfOf = request.headers.get('x-bailing-on-behalf-of') || '';
|
|
68
|
+
const jobId = request.headers.get('x-bailing-job-id') || '';
|
|
69
|
+
|
|
70
|
+
const ok = verifyToolCall(process.env.BAILING_TOOL_SECRET, {
|
|
71
|
+
method: request.method,
|
|
72
|
+
pathWithQuery,
|
|
73
|
+
body: rawBody,
|
|
74
|
+
timestamp: request.headers.get('x-bailing-timestamp'),
|
|
75
|
+
signature: request.headers.get('x-bailing-signature'),
|
|
76
|
+
onBehalfOf,
|
|
77
|
+
jobId
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
if (!ok) return new Response('bad signature', { status: 401 });
|
|
81
|
+
if (!await canUserReadMember(onBehalfOf)) return new Response('forbidden', { status: 403 });
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
验签只证明请求来自中枢,不代表这个主体有权限执行该动作。业务工具端点必须先验签,再按 `X-Bailing-On-Behalf-Of` 走自身权限表做授权裁决。
|
|
85
|
+
|
|
86
|
+
## 访客票据与 HubClient
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
import { HubClient, signTicket } from '@bailinghub/connect';
|
|
90
|
+
|
|
91
|
+
const ticket = signTicket(process.env.BAILING_CLIENT_TOKEN, `${tenantId}:${userId}`);
|
|
92
|
+
|
|
93
|
+
const hub = new HubClient({
|
|
94
|
+
baseUrl: 'https://hub.example.com',
|
|
95
|
+
token: process.env.BAILING_CLIENT_TOKEN,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const job = await hub.run({
|
|
99
|
+
requestId: `crm_${orderId}`,
|
|
100
|
+
route: 'order-support',
|
|
101
|
+
input: '查询订单处理建议',
|
|
102
|
+
metadata: { principal: { id: String(userId), tenant: String(tenantId) } },
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const result = await hub.getJob(job.job_id);
|
|
106
|
+
await hub.send({ requestId: `notice_${orderId}`, channel: 'team-im', to: 'user_001', text: '任务已完成' });
|
|
107
|
+
```
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { buildOpenApiSpec, param, tool } from '../src/index.mjs';
|
|
3
|
+
|
|
4
|
+
const spec = buildOpenApiSpec({
|
|
5
|
+
title: '演示业务系统',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
authzProbe: { method: 'POST', path: '/.well-known/bailing/authz-probe' },
|
|
8
|
+
tools: [
|
|
9
|
+
tool({
|
|
10
|
+
description: '查询门店员工列表',
|
|
11
|
+
name: 'staff_list',
|
|
12
|
+
scope: 'tenant.staff.read',
|
|
13
|
+
path: '/opentenantapi/staff/list',
|
|
14
|
+
whenToUse: '用户问员工、排班、人事相关问题时用;问工资明细别用本工具',
|
|
15
|
+
returns: '{code:1, data:[{id,name,role,dept}]}',
|
|
16
|
+
examples: [{ dept: '前厅' }],
|
|
17
|
+
rateLimit: '60/min',
|
|
18
|
+
tags: ['门店管理'],
|
|
19
|
+
params: [param('dept', { description: '按部门过滤,如 前厅、后仓', enum: ['前厅', '后仓'] })],
|
|
20
|
+
}),
|
|
21
|
+
tool({
|
|
22
|
+
description: '按手机号查询会员资料',
|
|
23
|
+
name: 'member_query',
|
|
24
|
+
scope: 'tenant.member.read',
|
|
25
|
+
path: '/opentenantapi/member/query',
|
|
26
|
+
method: 'POST',
|
|
27
|
+
readonly: true,
|
|
28
|
+
idempotent: true,
|
|
29
|
+
sensitive: true,
|
|
30
|
+
requiresSubject: true,
|
|
31
|
+
whenToUse: '门店员工核实会员身份时',
|
|
32
|
+
returns: '{code:1, data:{member_id, name, level, points}}',
|
|
33
|
+
params: [param('mobile', { description: '会员手机号', required: true, format: 'phone' })],
|
|
34
|
+
}),
|
|
35
|
+
tool({
|
|
36
|
+
description: '删除门店员工',
|
|
37
|
+
name: 'staff_delete',
|
|
38
|
+
scope: 'tenant.staff.delete',
|
|
39
|
+
path: '/opentenantapi/staff/delete',
|
|
40
|
+
method: 'POST',
|
|
41
|
+
risk: 'high',
|
|
42
|
+
confirm: true,
|
|
43
|
+
requiresSubject: true,
|
|
44
|
+
confirmPrompt: 'AI 申请删除员工 #{id}',
|
|
45
|
+
context: ['audit:hr'],
|
|
46
|
+
params: [param('id', { description: '员工 ID', type: 'integer', required: true })],
|
|
47
|
+
}),
|
|
48
|
+
tool({
|
|
49
|
+
description: '创建退款申请',
|
|
50
|
+
name: 'refund_request_create',
|
|
51
|
+
scope: 'tenant.refund.request',
|
|
52
|
+
path: '/opentenantapi/refund/request',
|
|
53
|
+
method: 'POST',
|
|
54
|
+
risk: 'medium',
|
|
55
|
+
requiresSubject: true,
|
|
56
|
+
whenToUse: '用户要发起退款但不要求立即打款时用;本工具只创建业务审批单',
|
|
57
|
+
returns: '{code:1, data:{request_id,status,message,url}}',
|
|
58
|
+
confirmWhen: [{ param: 'amount', op: '>', value: 500, label: '超过 500 元退款需人工确认' }],
|
|
59
|
+
params: [
|
|
60
|
+
param('order_id', { description: '订单 ID', required: true }),
|
|
61
|
+
param('amount', { description: '退款金额,单位元', type: 'number', required: true }),
|
|
62
|
+
param('reason', { description: '退款原因', required: true }),
|
|
63
|
+
],
|
|
64
|
+
}),
|
|
65
|
+
tool({
|
|
66
|
+
description: '生成月度经营报表(慢接口)',
|
|
67
|
+
name: 'demo_staff_monthly_report',
|
|
68
|
+
scope: 'tenant.report.read',
|
|
69
|
+
path: '/opentenantapi/report/monthly',
|
|
70
|
+
timeoutMs: 30000,
|
|
71
|
+
returns: '{code:1, data:{url: 报表下载地址}}',
|
|
72
|
+
params: [param('month', { description: '月份,如 2026-05', required: true, format: 'date' })],
|
|
73
|
+
}),
|
|
74
|
+
tool({
|
|
75
|
+
description: '示例:deprecated 员工查询接口',
|
|
76
|
+
name: 'staff_list_v1',
|
|
77
|
+
scope: 'tenant.staff.read',
|
|
78
|
+
path: '/opentenantapi/staff/list_v1',
|
|
79
|
+
deprecated: true,
|
|
80
|
+
}),
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
console.log(JSON.stringify(spec, null, 2));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bailinghub/connect",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "BailingHub hub business-side SDK for tool specs, HMAC verification, callbacks and authz probes.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.mjs"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"examples",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build:spec": "node examples/build-spec.mjs"
|
|
21
|
+
}
|
|
22
|
+
}
|