create-windy 0.3.2 → 0.3.5
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/README.md +27 -9
- package/dist/cli.js +825 -117
- package/package.json +1 -1
- package/template/.agents/skills/windy-business-module/SKILL.md +16 -3
- package/template/.windy-template.json +2 -2
- package/template/AGENTS.md +4 -0
- package/template/README.md +18 -11
- package/template/_gitignore +1 -0
- package/template/apps/agent-server/README.md +2 -0
- package/template/apps/agent-server/pyproject.toml +8 -0
- package/template/apps/agent-server/src/southwind_agent_server/adk_adapter.py +87 -10
- package/template/apps/agent-server/src/southwind_agent_server/adk_model.py +18 -3
- package/template/apps/agent-server/src/southwind_agent_server/adk_tools.py +78 -11
- package/template/apps/agent-server/src/southwind_agent_server/app.py +120 -115
- package/template/apps/agent-server/src/southwind_agent_server/artifact_input.py +153 -0
- package/template/apps/agent-server/src/southwind_agent_server/config.py +29 -0
- package/template/apps/agent-server/src/southwind_agent_server/contracts.py +81 -1
- package/template/apps/agent-server/src/southwind_agent_server/deterministic.py +8 -0
- package/template/apps/agent-server/src/southwind_agent_server/engine.py +28 -0
- package/template/apps/agent-server/src/southwind_agent_server/fingerprint.py +41 -0
- package/template/apps/agent-server/src/southwind_agent_server/http_helpers.py +62 -0
- package/template/apps/agent-server/src/southwind_agent_server/lease.py +15 -0
- package/template/apps/agent-server/src/southwind_agent_server/multimodal.py +76 -0
- package/template/apps/agent-server/src/southwind_agent_server/openai_engine.py +112 -20
- package/template/apps/agent-server/src/southwind_agent_server/openai_provider.py +14 -1
- package/template/apps/agent-server/src/southwind_agent_server/postgres_store.py +329 -0
- package/template/apps/agent-server/src/southwind_agent_server/postgres_store_backend.py +332 -0
- package/template/apps/agent-server/src/southwind_agent_server/provider_governance.py +64 -3
- package/template/apps/agent-server/src/southwind_agent_server/runtime_factory.py +68 -0
- package/template/apps/agent-server/src/southwind_agent_server/service.py +218 -56
- package/template/apps/agent-server/src/southwind_agent_server/signal_events.py +36 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_catalog.py +107 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_schema.py +65 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_serialization.py +16 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_store.py +89 -57
- package/template/apps/agent-server/src/southwind_agent_server/store.py +105 -2
- package/template/apps/agent-server/src/southwind_agent_server/store_cipher.py +40 -0
- package/template/apps/agent-server/src/southwind_agent_server/telemetry.py +89 -0
- package/template/apps/agent-server/src/southwind_agent_server/tool_host.py +72 -0
- package/template/apps/agent-server/tests/test_adk_adapter.py +6 -2
- package/template/apps/agent-server/tests/test_api.py +24 -1
- package/template/apps/agent-server/tests/test_artifact_input.py +110 -0
- package/template/apps/agent-server/tests/test_config.py +4 -0
- package/template/apps/agent-server/tests/test_fingerprint.py +10 -0
- package/template/apps/agent-server/tests/test_multimodal.py +51 -0
- package/template/apps/agent-server/tests/test_openai_provider.py +6 -2
- package/template/apps/agent-server/tests/test_postgres_store.py +131 -0
- package/template/apps/agent-server/tests/test_provider_governance.py +61 -0
- package/template/apps/agent-server/tests/test_sqlite_store.py +95 -10
- package/template/apps/agent-server/tests/test_telemetry.py +25 -0
- package/template/apps/agent-server/tests/test_tool_approval.py +28 -0
- package/template/apps/agent-server/uv.lock +165 -0
- package/template/apps/document-server/Dockerfile +19 -0
- package/template/apps/document-server/pyproject.toml +43 -0
- package/template/apps/document-server/src/southwind_document_server/__init__.py +1 -0
- package/template/apps/document-server/src/southwind_document_server/adapter.py +337 -0
- package/template/apps/document-server/src/southwind_document_server/app.py +151 -0
- package/template/apps/document-server/src/southwind_document_server/config.py +94 -0
- package/template/apps/document-server/src/southwind_document_server/contracts.py +103 -0
- package/template/apps/document-server/src/southwind_document_server/service.py +149 -0
- package/template/apps/document-server/src/southwind_document_server/store.py +185 -0
- package/template/apps/document-server/tests/__init__.py +1 -0
- package/template/apps/document-server/tests/test_config.py +42 -0
- package/template/apps/document-server/tests/test_service.py +140 -0
- package/template/apps/document-server/uv.lock +430 -0
- package/template/apps/embedding-server/Dockerfile +17 -0
- package/template/apps/embedding-server/pyproject.toml +44 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/__init__.py +1 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/adapter.py +254 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/app.py +119 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/config.py +120 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/contracts.py +106 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/error.py +6 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/image_input.py +87 -0
- package/template/apps/embedding-server/tests/__init__.py +1 -0
- package/template/apps/embedding-server/tests/test_adapter.py +92 -0
- package/template/apps/embedding-server/tests/test_config.py +38 -0
- package/template/apps/embedding-server/uv.lock +449 -0
- package/template/apps/server/src/agent/background-operation-port.ts +37 -0
- package/template/apps/server/src/agent/background-operation.test.ts +231 -0
- package/template/apps/server/src/agent/background-operation.ts +252 -0
- package/template/apps/server/src/agent/drizzle-run-binding-repository.ts +114 -0
- package/template/apps/server/src/agent/execution-grants.ts +7 -1
- package/template/apps/server/src/agent/fake-runtime.test-support.ts +43 -0
- package/template/apps/server/src/agent/idempotency-key.test.ts +28 -0
- package/template/apps/server/src/agent/idempotency-key.ts +11 -0
- package/template/apps/server/src/agent/remote-runtime.test.ts +115 -1
- package/template/apps/server/src/agent/remote-runtime.ts +173 -5
- package/template/apps/server/src/agent/run-authorization.test-support.ts +9 -0
- package/template/apps/server/src/agent/run-authorization.test.ts +126 -0
- package/template/apps/server/src/agent/run-authorization.ts +180 -0
- package/template/apps/server/src/agent/run-binding-repository.ts +93 -0
- package/template/apps/server/src/agent/run-contracts.ts +88 -1
- package/template/apps/server/src/agent/run-definition-support.ts +58 -0
- package/template/apps/server/src/agent/run-errors.ts +25 -0
- package/template/apps/server/src/agent/run-facade.test.ts +57 -46
- package/template/apps/server/src/agent/run-facade.ts +185 -65
- package/template/apps/server/src/agent/run-release.ts +78 -0
- package/template/apps/server/src/agent/run-route-input.ts +169 -0
- package/template/apps/server/src/agent/run-routes.ts +63 -76
- package/template/apps/server/src/agent/runtime-bootstrap.ts +169 -13
- package/template/apps/server/src/agent/sandbox-client.ts +200 -0
- package/template/apps/server/src/agent/sandbox-protocol.ts +76 -0
- package/template/apps/server/src/agent/sandbox-registry.ts +205 -0
- package/template/apps/server/src/agent/sandbox-runtime.test.ts +137 -0
- package/template/apps/server/src/agent/sandbox-worker-server.ts +195 -0
- package/template/apps/server/src/agent/sandbox-worker.ts +12 -0
- package/template/apps/server/src/agent/tool-approval.test.ts +75 -0
- package/template/apps/server/src/agent/tool-approval.ts +115 -0
- package/template/apps/server/src/agent/tool-audit.ts +62 -0
- package/template/apps/server/src/agent/tool-host.test.ts +39 -11
- package/template/apps/server/src/agent/tool-host.ts +184 -17
- package/template/apps/server/src/agent/tool-registry.ts +52 -47
- package/template/apps/server/src/agent/vision-facade.test.ts +256 -0
- package/template/apps/server/src/agent/vision-input.ts +120 -0
- package/template/apps/server/src/ai-artifact/codec.test.ts +44 -0
- package/template/apps/server/src/ai-artifact/codec.ts +137 -0
- package/template/apps/server/src/ai-artifact/routes.ts +37 -0
- package/template/apps/server/src/ai-artifact/runtime.ts +205 -0
- package/template/apps/server/src/application-services.ts +62 -2
- package/template/apps/server/src/auth/reauthentication.test.ts +40 -0
- package/template/apps/server/src/auth/reauthentication.ts +19 -0
- package/template/apps/server/src/auth/runtime.ts +9 -1
- package/template/apps/server/src/data-access/context.ts +6 -4
- package/template/apps/server/src/data-access/scope-snapshot.ts +27 -0
- package/template/apps/server/src/data-governance/export/approval-port.ts +6 -3
- package/template/apps/server/src/data-governance/export/authorization-port.test.ts +23 -4
- package/template/apps/server/src/data-governance/export/authorization-port.ts +89 -25
- package/template/apps/server/src/data-governance/export/drizzle-repository.integration.test.ts +2 -0
- package/template/apps/server/src/data-governance/export/drizzle-repository.ts +1 -0
- package/template/apps/server/src/data-governance/export/job-runtime.test.ts +15 -4
- package/template/apps/server/src/data-governance/export/job-runtime.ts +68 -15
- package/template/apps/server/src/data-governance/export/ndjson-stream.ts +25 -6
- package/template/apps/server/src/data-governance/export/postgres-recovery.integration.test.ts +4 -2
- package/template/apps/server/src/data-governance/export/renderer-job-runtime.test.ts +235 -0
- package/template/apps/server/src/data-governance/export/renderer-runtime.ts +293 -0
- package/template/apps/server/src/data-governance/export/renderer-selection.test.ts +67 -0
- package/template/apps/server/src/data-governance/export/repository.test.ts +2 -0
- package/template/apps/server/src/data-governance/export/request-fingerprint.test.ts +13 -0
- package/template/apps/server/src/data-governance/export/request-fingerprint.ts +2 -0
- package/template/apps/server/src/data-governance/export/routes.ts +11 -1
- package/template/apps/server/src/data-governance/export/scope-snapshot.ts +6 -18
- package/template/apps/server/src/data-governance/export/service-support.ts +188 -0
- package/template/apps/server/src/data-governance/export/service.ts +90 -113
- package/template/apps/server/src/data-governance/export/source.ts +101 -0
- package/template/apps/server/src/data-governance/export/types.ts +27 -0
- package/template/apps/server/src/document/contracts.ts +76 -0
- package/template/apps/server/src/document/facade.ts +339 -0
- package/template/apps/server/src/document/remote-runtime.test.ts +96 -0
- package/template/apps/server/src/document/remote-runtime.ts +223 -0
- package/template/apps/server/src/document/routes.ts +193 -0
- package/template/apps/server/src/embedding/contracts.ts +83 -0
- package/template/apps/server/src/embedding/error.ts +10 -0
- package/template/apps/server/src/embedding/facade.ts +217 -0
- package/template/apps/server/src/embedding/input.ts +172 -0
- package/template/apps/server/src/embedding/remote-runtime.test.ts +66 -0
- package/template/apps/server/src/embedding/remote-runtime.ts +218 -0
- package/template/apps/server/src/embedding/routes.ts +152 -0
- package/template/apps/server/src/index.ts +40 -43
- package/template/apps/server/src/jobs/artifact-service.test.ts +14 -2
- package/template/apps/server/src/jobs/artifact-service.ts +10 -0
- package/template/apps/server/src/jobs/drizzle-execution-repository.ts +17 -18
- package/template/apps/server/src/jobs/drizzle-execution.integration.test.ts +19 -1
- package/template/apps/server/src/jobs/drizzle-mappers.ts +4 -1
- package/template/apps/server/src/jobs/drizzle-recovery-repository.ts +49 -2
- package/template/apps/server/src/jobs/drizzle-repository.ts +1 -0
- package/template/apps/server/src/jobs/execution-repository.ts +17 -0
- package/template/apps/server/src/jobs/execution.test.ts +34 -0
- package/template/apps/server/src/jobs/in-memory-control.ts +135 -0
- package/template/apps/server/src/jobs/in-memory-execution.ts +34 -65
- package/template/apps/server/src/jobs/legacy-service-runtime.ts +5 -2
- package/template/apps/server/src/jobs/repository.ts +3 -0
- package/template/apps/server/src/jobs/worker.ts +80 -41
- package/template/apps/server/src/module-host/ai-operation-port.ts +170 -0
- package/template/apps/server/src/module-host/durable-context.test.ts +312 -0
- package/template/apps/server/src/module-host/durable-context.ts +124 -0
- package/template/apps/server/src/module-host/durable-handler-registration.ts +72 -0
- package/template/apps/server/src/module-host/governed-export-route-support.ts +171 -0
- package/template/apps/server/src/module-host/governed-export-routes.test.ts +327 -0
- package/template/apps/server/src/module-host/governed-export-routes.ts +238 -0
- package/template/apps/server/src/module-host/governed-renderer-registration.test.ts +247 -0
- package/template/apps/server/src/module-host/governed-resource-routes.ts +331 -0
- package/template/apps/server/src/module-host/governed-resources.test.ts +344 -0
- package/template/apps/server/src/module-host/governed-resources.ts +203 -0
- package/template/apps/server/src/module-host/http-runtime.ts +95 -0
- package/template/apps/server/src/module-host/initialize-contracts.ts +14 -0
- package/template/apps/server/src/module-host/initialize.test.ts +49 -1
- package/template/apps/server/src/module-host/initialize.ts +39 -16
- package/template/apps/server/src/module-host/job-port.test.ts +262 -0
- package/template/apps/server/src/module-host/job-port.ts +334 -0
- package/template/apps/server/src/module-host/request-context.test.ts +88 -2
- package/template/apps/server/src/module-host/request-context.ts +56 -22
- package/template/apps/server/src/module-host/route-installer.test.ts +10 -0
- package/template/apps/server/src/module-host/route-installer.ts +36 -1
- package/template/apps/server/src/module-host/sandbox-tool-registration.ts +42 -0
- package/template/apps/server/src/module-host/tool-handlers.ts +67 -31
- package/template/apps/server/src/module-host.ts +1 -0
- package/template/apps/server/src/module-runtime-validation.ts +7 -3
- package/template/apps/server/src/speech/contracts.ts +76 -0
- package/template/apps/server/src/speech/facade.ts +316 -0
- package/template/apps/server/src/speech/remote-runtime.test.ts +88 -0
- package/template/apps/server/src/speech/remote-runtime.ts +227 -0
- package/template/apps/server/src/speech/routes.ts +180 -0
- package/template/apps/server/src/system/actor.ts +39 -0
- package/template/apps/server/src/system/route-helpers.ts +1 -0
- package/template/apps/server/src/workflow/service.ts +2 -1
- package/template/apps/speech-server/Dockerfile +22 -0
- package/template/apps/speech-server/pyproject.toml +43 -0
- package/template/apps/speech-server/src/southwind_speech_server/__init__.py +1 -0
- package/template/apps/speech-server/src/southwind_speech_server/adapter.py +249 -0
- package/template/apps/speech-server/src/southwind_speech_server/app.py +183 -0
- package/template/apps/speech-server/src/southwind_speech_server/config.py +100 -0
- package/template/apps/speech-server/src/southwind_speech_server/contracts.py +103 -0
- package/template/apps/speech-server/src/southwind_speech_server/errors.py +6 -0
- package/template/apps/speech-server/src/southwind_speech_server/normalizer.py +108 -0
- package/template/apps/speech-server/src/southwind_speech_server/output_validation.py +128 -0
- package/template/apps/speech-server/src/southwind_speech_server/service.py +162 -0
- package/template/apps/speech-server/src/southwind_speech_server/store.py +209 -0
- package/template/apps/speech-server/tests/__init__.py +1 -0
- package/template/apps/speech-server/tests/test_config.py +33 -0
- package/template/apps/speech-server/tests/test_service.py +154 -0
- package/template/apps/speech-server/uv.lock +430 -0
- package/template/apps/web/src/app/business-routes.ts +22 -0
- package/template/apps/web/src/components/common/AccessSnapshotBoundary.vue +112 -0
- package/template/apps/web/src/components/common/AccessSnapshotBoundary.webtest.ts +130 -0
- package/template/apps/web/src/components/common/AccessSnapshotNotice.vue +117 -0
- package/template/apps/web/src/components/common/FormDialog.vue +6 -0
- package/template/apps/web/src/components/common/ModalLayout.webtest.ts +13 -0
- package/template/apps/web/src/composables/access-snapshot-change.ts +131 -0
- package/template/apps/web/src/composables/access-snapshot-change.webtest.ts +103 -0
- package/template/apps/web/src/composables/useAccessSnapshot.ts +48 -2
- package/template/apps/web/src/composables/useAccessSnapshot.webtest.ts +54 -0
- package/template/apps/web/src/composables/useAccessSnapshotMonitor.ts +42 -0
- package/template/apps/web/src/layout/AppShell.vue +28 -25
- package/template/apps/web/src/layout/AppShell.webtest.ts +1 -0
- package/template/apps/web/src/router/business-routes.ts +68 -0
- package/template/apps/web/src/router/business-routes.webtest.ts +85 -0
- package/template/apps/web/src/router/index.ts +7 -0
- package/template/apps/web/src/router/shared-scaffold-neutrality.webtest.ts +12 -0
- package/template/apps/web/src/services/access-api.ts +5 -1
- package/template/apps/web/src/services/access-api.webtest.ts +35 -0
- package/template/docker-compose.yml +127 -0
- package/template/docs/architecture/ai-egress.md +12 -9
- package/template/docs/architecture/ai-runtime.md +23 -11
- package/template/docs/architecture/durable-jobs.md +25 -3
- package/template/docs/architecture/foundation-infrastructure.md +163 -0
- package/template/docs/architecture/module-host.md +115 -0
- package/template/docs/architecture/server-module-interface.md +39 -0
- package/template/docs/architecture/web-access-snapshot-resilience.md +60 -0
- package/template/docs/development/business-web-routes.md +66 -0
- package/template/docs/development/custom-login-page.md +3 -3
- package/template/docs/development/module-lifecycle.md +71 -0
- package/template/docs/operations/observability.md +5 -1
- package/template/docs/platform/agent-runtime.md +21 -11
- package/template/docs/platform/agent-tool-sandbox.md +58 -0
- package/template/docs/platform/agent-tools.md +5 -0
- package/template/docs/platform/document-ai-runtime.md +204 -0
- package/template/docs/platform/governed-export-renderers.md +132 -0
- package/template/docs/platform/navigation-registry.md +5 -0
- package/template/docs/platform/organization-membership.md +2 -1
- package/template/docs/platform/speech-ai-runtime.md +156 -0
- package/template/docs/platform/system-crud-api.md +7 -1
- package/template/docs/platform/vision-ai-runtime.md +97 -0
- package/template/docs/platform/web-system-crud.md +6 -0
- package/template/package.json +16 -2
- package/template/packages/ai-client/index.ts +4 -0
- package/template/packages/ai-client/package.json +5 -2
- package/template/packages/ai-client/src/agent/client/artifact.ts +26 -0
- package/template/packages/ai-client/src/agent/client/attach.test.ts +124 -0
- package/template/packages/ai-client/src/agent/client/client.ts +119 -7
- package/template/packages/ai-client/src/agent/client/run.ts +14 -0
- package/template/packages/ai-client/src/agent/client/types.ts +18 -0
- package/template/packages/ai-client/src/agent/client/vision.test.ts +53 -0
- package/template/packages/ai-client/src/agent/contracts/contracts.test.ts +1 -0
- package/template/packages/ai-client/src/agent/contracts/events.ts +33 -0
- package/template/packages/ai-client/src/agent/contracts/runs.ts +71 -0
- package/template/packages/ai-client/src/agent/index.ts +1 -0
- package/template/packages/ai-client/src/artifact-ref.ts +8 -0
- package/template/packages/ai-client/src/document/client.test.ts +114 -0
- package/template/packages/ai-client/src/document/client.ts +134 -0
- package/template/packages/ai-client/src/document/contracts.ts +152 -0
- package/template/packages/ai-client/src/document/error.ts +43 -0
- package/template/packages/ai-client/src/document/index.ts +3 -0
- package/template/packages/ai-client/src/document/run.ts +104 -0
- package/template/packages/ai-client/src/document/validation.ts +115 -0
- package/template/packages/ai-client/src/embedding/client.test.ts +77 -0
- package/template/packages/ai-client/src/embedding/client.ts +96 -0
- package/template/packages/ai-client/src/embedding/contracts.ts +46 -0
- package/template/packages/ai-client/src/embedding/error.ts +61 -0
- package/template/packages/ai-client/src/embedding/index.ts +3 -0
- package/template/packages/ai-client/src/embedding/validation.ts +117 -0
- package/template/packages/ai-client/src/speech/client.test.ts +135 -0
- package/template/packages/ai-client/src/speech/client.ts +104 -0
- package/template/packages/ai-client/src/speech/contracts.ts +129 -0
- package/template/packages/ai-client/src/speech/error.ts +43 -0
- package/template/packages/ai-client/src/speech/index.ts +3 -0
- package/template/packages/ai-client/src/speech/run.ts +133 -0
- package/template/packages/ai-client/src/speech/validation.ts +132 -0
- package/template/packages/config/package.json +2 -2
- package/template/packages/database/drizzle/0039_early_ezekiel_stane.sql +1 -0
- package/template/packages/database/drizzle/0040_colossal_baron_strucker.sql +63 -0
- package/template/packages/database/drizzle/0041_yummy_prowler.sql +21 -0
- package/template/packages/database/drizzle/0042_puzzling_rumiko_fujikawa.sql +27 -0
- package/template/packages/database/drizzle/meta/0039_snapshot.json +7755 -0
- package/template/packages/database/drizzle/meta/0040_snapshot.json +8150 -0
- package/template/packages/database/drizzle/meta/0041_snapshot.json +8323 -0
- package/template/packages/database/drizzle/meta/0042_snapshot.json +8541 -0
- package/template/packages/database/drizzle/meta/_journal.json +28 -0
- package/template/packages/database/package.json +2 -2
- package/template/packages/database/src/agent-runtime-schema.test.ts +54 -0
- package/template/packages/database/src/schema/agent-runtime.ts +149 -0
- package/template/packages/database/src/schema/common.ts +2 -14
- package/template/packages/database/src/schema/durable-jobs.ts +5 -0
- package/template/packages/database/src/schema/governed-exports.ts +17 -5
- package/template/packages/database/src/schema/index.ts +3 -0
- package/template/packages/database/src/schema-durable-recovery.test.ts +31 -0
- package/template/packages/database/src/schema-governed-exports.test.ts +21 -1
- package/template/packages/database/src/schema.test.ts +6 -23
- package/template/packages/jobs/package.json +3 -2
- package/template/packages/jobs/src/handlers.test.ts +13 -0
- package/template/packages/jobs/src/handlers.ts +7 -1
- package/template/packages/jobs/src/types.ts +4 -0
- package/template/packages/modules/package.json +2 -2
- package/template/packages/modules/src/ai-operation-composition.test-support.ts +165 -0
- package/template/packages/modules/src/ai-operation-composition.test.ts +91 -127
- package/template/packages/modules/src/ai-operation-composition.ts +59 -1
- package/template/packages/modules/src/manifest.ts +25 -1
- package/template/packages/modules/src/tool-composition.ts +18 -0
- package/template/packages/server-sdk/index.ts +50 -0
- package/template/packages/server-sdk/package.json +10 -4
- package/template/packages/server-sdk/src/ai-artifact-port.ts +34 -0
- package/template/packages/server-sdk/src/ai-operation-port.ts +65 -0
- package/template/packages/server-sdk/src/ai-operation-registration.ts +42 -1
- package/template/packages/server-sdk/src/background-ai-port.ts +43 -0
- package/template/packages/server-sdk/src/data-governance-registration.ts +116 -0
- package/template/packages/server-sdk/src/durable-handler.ts +29 -0
- package/template/packages/server-sdk/src/jobs-port.ts +69 -0
- package/template/packages/server-sdk/src/module-host.ts +16 -2
- package/template/packages/server-sdk/src/request-context.ts +6 -2
- package/template/packages/server-sdk/src/sandbox-tool.ts +21 -0
- package/template/packages/server-sdk/src/tool-registration.ts +2 -0
- package/template/packages/shared/package.json +1 -1
- package/template/packages/shared/src/rbac.ts +30 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { scopedRuntimeIdempotencyKey } from "./idempotency-key.js";
|
|
3
|
+
|
|
4
|
+
describe("Runtime 幂等键作用域", () => {
|
|
5
|
+
test("相同客户端键按 Actor 和 Operation 隔离", () => {
|
|
6
|
+
const base = scopedRuntimeIdempotencyKey(
|
|
7
|
+
"actor-1",
|
|
8
|
+
"business.answer",
|
|
9
|
+
"shared-request",
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
expect(base).toMatch(/^[a-f0-9]{64}$/);
|
|
13
|
+
expect(
|
|
14
|
+
scopedRuntimeIdempotencyKey(
|
|
15
|
+
"actor-2",
|
|
16
|
+
"business.answer",
|
|
17
|
+
"shared-request",
|
|
18
|
+
),
|
|
19
|
+
).not.toBe(base);
|
|
20
|
+
expect(
|
|
21
|
+
scopedRuntimeIdempotencyKey(
|
|
22
|
+
"actor-1",
|
|
23
|
+
"business.summarize",
|
|
24
|
+
"shared-request",
|
|
25
|
+
),
|
|
26
|
+
).not.toBe(base);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
export function scopedRuntimeIdempotencyKey(
|
|
4
|
+
actorId: string,
|
|
5
|
+
operationKey: string,
|
|
6
|
+
idempotencyKey: string,
|
|
7
|
+
) {
|
|
8
|
+
return createHash("sha256")
|
|
9
|
+
.update(`${actorId}\u0000${operationKey}\u0000${idempotencyKey}`)
|
|
10
|
+
.digest("hex");
|
|
11
|
+
}
|
|
@@ -9,6 +9,41 @@ afterEach(() => {
|
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
describe("RemoteAgentRuntime", () => {
|
|
12
|
+
test("读取可恢复 Run 状态和终态事件", async () => {
|
|
13
|
+
const server = Bun.serve({
|
|
14
|
+
port: 0,
|
|
15
|
+
fetch() {
|
|
16
|
+
return Response.json({
|
|
17
|
+
runId: "run_done",
|
|
18
|
+
status: "completed",
|
|
19
|
+
lastSequence: 4,
|
|
20
|
+
terminalEvent: {
|
|
21
|
+
type: "run.completed",
|
|
22
|
+
runId: "run_done",
|
|
23
|
+
sequence: 4,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
servers.push(server);
|
|
29
|
+
const runtime = new RemoteAgentRuntime({
|
|
30
|
+
baseUrl: server.url.toString(),
|
|
31
|
+
internalToken: "test-token",
|
|
32
|
+
toolHostUrl: "http://server.internal/api/agent/tools",
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
await expect(runtime.status("run_done")).resolves.toEqual({
|
|
36
|
+
runId: "run_done",
|
|
37
|
+
status: "completed",
|
|
38
|
+
lastSequence: 4,
|
|
39
|
+
terminalEvent: {
|
|
40
|
+
type: "run.completed",
|
|
41
|
+
runId: "run_done",
|
|
42
|
+
sequence: 4,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
12
47
|
test("只向 Agent Server 序列化远端支持的运行限制", async () => {
|
|
13
48
|
let received: unknown;
|
|
14
49
|
const server = Bun.serve({
|
|
@@ -30,10 +65,15 @@ describe("RemoteAgentRuntime", () => {
|
|
|
30
65
|
maxOutputBytes: 8_192,
|
|
31
66
|
};
|
|
32
67
|
const operation: AgentRuntimeOperation = {
|
|
68
|
+
kind: "agent",
|
|
33
69
|
operationKey: "business.answer",
|
|
34
70
|
input: { question: "你好" },
|
|
71
|
+
inputModalities: ["text"],
|
|
72
|
+
requiredCapabilities: ["text-generation"],
|
|
73
|
+
artifacts: [],
|
|
35
74
|
instructions: "只回答当前业务问题。",
|
|
36
75
|
userPrompt: "你好",
|
|
76
|
+
outputSchemaKey: "business.output.v1",
|
|
37
77
|
allowedTools: [],
|
|
38
78
|
limits: manifestLimits,
|
|
39
79
|
providerEgress: {
|
|
@@ -63,6 +103,8 @@ describe("RemoteAgentRuntime", () => {
|
|
|
63
103
|
},
|
|
64
104
|
toolNetworkPolicy: { mode: "forbidden" },
|
|
65
105
|
executionGrant: "grant_1",
|
|
106
|
+
release: runtimeRelease(),
|
|
107
|
+
traceId: "trace_request_1",
|
|
66
108
|
};
|
|
67
109
|
const runtime = new RemoteAgentRuntime({
|
|
68
110
|
baseUrl: server.url.toString(),
|
|
@@ -75,6 +117,7 @@ describe("RemoteAgentRuntime", () => {
|
|
|
75
117
|
expect(received).toMatchObject({
|
|
76
118
|
limits: {
|
|
77
119
|
maxDurationSeconds: 60,
|
|
120
|
+
maxInputBytes: 4_096,
|
|
78
121
|
maxOutputBytes: 8_192,
|
|
79
122
|
},
|
|
80
123
|
providerEgress: {
|
|
@@ -83,13 +126,84 @@ describe("RemoteAgentRuntime", () => {
|
|
|
83
126
|
},
|
|
84
127
|
providerDataPolicy: operation.providerDataPolicy,
|
|
85
128
|
toolNetworkPolicy: { mode: "forbidden" },
|
|
129
|
+
release: operation.release,
|
|
130
|
+
traceId: operation.traceId,
|
|
86
131
|
});
|
|
87
132
|
expect(
|
|
88
133
|
(received as { limits: Record<string, unknown> }).limits,
|
|
89
|
-
).
|
|
134
|
+
).toHaveProperty("maxInputBytes", 4_096);
|
|
90
135
|
const serialized = JSON.stringify(received);
|
|
91
136
|
expect(serialized).not.toContain("QWEN_");
|
|
92
137
|
expect(serialized).not.toContain("apiKey");
|
|
93
138
|
expect(serialized).not.toContain("baseUrl");
|
|
94
139
|
});
|
|
140
|
+
|
|
141
|
+
test("保留 Runtime 的能力拒绝错误码", async () => {
|
|
142
|
+
const server = Bun.serve({
|
|
143
|
+
port: 0,
|
|
144
|
+
fetch() {
|
|
145
|
+
return Response.json(
|
|
146
|
+
{
|
|
147
|
+
code: "MODEL_ROUTE_UNAVAILABLE",
|
|
148
|
+
message: "模型 Deployment 缺少 Operation 所需能力",
|
|
149
|
+
retryable: true,
|
|
150
|
+
},
|
|
151
|
+
{ status: 503 },
|
|
152
|
+
);
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
servers.push(server);
|
|
156
|
+
const runtime = new RemoteAgentRuntime({
|
|
157
|
+
baseUrl: server.url.toString(),
|
|
158
|
+
internalToken: "test-token",
|
|
159
|
+
toolHostUrl: "http://server.internal/api/agent/tools",
|
|
160
|
+
});
|
|
161
|
+
const request: AgentRuntimeOperation = {
|
|
162
|
+
kind: "agent",
|
|
163
|
+
operationKey: "business.vision",
|
|
164
|
+
input: { question: "分析" },
|
|
165
|
+
inputModalities: ["text", "image"],
|
|
166
|
+
requiredCapabilities: ["vision"],
|
|
167
|
+
artifacts: [],
|
|
168
|
+
instructions: "分析图片",
|
|
169
|
+
userPrompt: "分析",
|
|
170
|
+
outputSchemaKey: "business.output.v1",
|
|
171
|
+
allowedTools: [],
|
|
172
|
+
limits: {
|
|
173
|
+
maxDurationSeconds: 60,
|
|
174
|
+
maxInputBytes: 4096,
|
|
175
|
+
maxOutputBytes: 4096,
|
|
176
|
+
maxArtifacts: 1,
|
|
177
|
+
maxPixelsPerArtifact: 1_000_000,
|
|
178
|
+
},
|
|
179
|
+
providerEgress: {
|
|
180
|
+
mode: "configured-endpoint",
|
|
181
|
+
deploymentKey: "ai.openai-compatible",
|
|
182
|
+
},
|
|
183
|
+
providerDataPolicy: { inputFields: [], envelopeFields: [] },
|
|
184
|
+
toolNetworkPolicy: { mode: "forbidden" },
|
|
185
|
+
executionGrant: "grant_1",
|
|
186
|
+
release: runtimeRelease(),
|
|
187
|
+
traceId: "trace_request_vision",
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
await expect(
|
|
191
|
+
runtime.start(request, "request-vision"),
|
|
192
|
+
).rejects.toMatchObject({
|
|
193
|
+
code: "MODEL_ROUTE_UNAVAILABLE",
|
|
194
|
+
retryable: true,
|
|
195
|
+
});
|
|
196
|
+
});
|
|
95
197
|
});
|
|
198
|
+
|
|
199
|
+
function runtimeRelease(): AgentRuntimeOperation["release"] {
|
|
200
|
+
return {
|
|
201
|
+
releaseId: "release_test",
|
|
202
|
+
operationVersion: "1.0.0",
|
|
203
|
+
workflowVersion: "workflow-1",
|
|
204
|
+
promptVersion: "prompt-1",
|
|
205
|
+
routeVersion: "route-1",
|
|
206
|
+
toolSchemaVersion: "schema-1",
|
|
207
|
+
manifestDigest: "0".repeat(64),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AgentRuntimeOperation,
|
|
3
3
|
AgentRuntimePort,
|
|
4
|
+
AgentRuntimeRunStatus,
|
|
4
5
|
AgentRuntimeStartResponse,
|
|
6
|
+
AgentRuntimeStatusResponse,
|
|
7
|
+
AgentRuntimeTerminalEvent,
|
|
5
8
|
} from "./run-contracts.js";
|
|
9
|
+
import { AgentRuntimeError } from "./run-contracts.js";
|
|
6
10
|
|
|
7
11
|
export interface RemoteAgentRuntimeOptions {
|
|
8
12
|
baseUrl: string;
|
|
@@ -28,19 +32,38 @@ export class RemoteAgentRuntime implements AgentRuntimePort {
|
|
|
28
32
|
idempotencyKey: string,
|
|
29
33
|
): Promise<AgentRuntimeStartResponse> {
|
|
30
34
|
const remoteRequest: RemoteStartRunRequest = {
|
|
35
|
+
kind: request.kind,
|
|
31
36
|
operationKey: request.operationKey,
|
|
32
37
|
input: request.input,
|
|
38
|
+
inputModalities: request.inputModalities,
|
|
39
|
+
requiredCapabilities: request.requiredCapabilities,
|
|
40
|
+
artifacts: request.artifacts,
|
|
33
41
|
instructions: request.instructions,
|
|
34
42
|
userPrompt: request.userPrompt,
|
|
43
|
+
outputSchemaKey: request.outputSchemaKey,
|
|
44
|
+
...(request.outputSchema === undefined
|
|
45
|
+
? {}
|
|
46
|
+
: { outputSchema: request.outputSchema }),
|
|
35
47
|
allowedTools: request.allowedTools,
|
|
36
48
|
limits: {
|
|
37
49
|
maxDurationSeconds: request.limits.maxDurationSeconds,
|
|
50
|
+
maxInputBytes: request.limits.maxInputBytes,
|
|
38
51
|
maxOutputBytes: request.limits.maxOutputBytes,
|
|
52
|
+
...(request.limits.maxArtifacts === undefined
|
|
53
|
+
? {}
|
|
54
|
+
: { maxArtifacts: request.limits.maxArtifacts }),
|
|
55
|
+
...(request.limits.maxPixelsPerArtifact === undefined
|
|
56
|
+
? {}
|
|
57
|
+
: {
|
|
58
|
+
maxPixelsPerArtifact: request.limits.maxPixelsPerArtifact,
|
|
59
|
+
}),
|
|
39
60
|
},
|
|
40
61
|
providerEgress: request.providerEgress,
|
|
41
62
|
providerDataPolicy: request.providerDataPolicy,
|
|
42
63
|
toolNetworkPolicy: request.toolNetworkPolicy,
|
|
43
64
|
executionGrant: request.executionGrant,
|
|
65
|
+
release: request.release,
|
|
66
|
+
traceId: request.traceId,
|
|
44
67
|
toolHostUrl: this.options.toolHostUrl,
|
|
45
68
|
};
|
|
46
69
|
const response = await this.request("/api/agent/runs", {
|
|
@@ -52,7 +75,7 @@ export class RemoteAgentRuntime implements AgentRuntimePort {
|
|
|
52
75
|
body: JSON.stringify(remoteRequest),
|
|
53
76
|
});
|
|
54
77
|
if (!response.ok) throw await remoteError(response);
|
|
55
|
-
return (await response.json())
|
|
78
|
+
return parseStart(await response.json());
|
|
56
79
|
}
|
|
57
80
|
|
|
58
81
|
events(runId: string, cursor: number, signal?: AbortSignal) {
|
|
@@ -63,6 +86,15 @@ export class RemoteAgentRuntime implements AgentRuntimePort {
|
|
|
63
86
|
);
|
|
64
87
|
}
|
|
65
88
|
|
|
89
|
+
async status(runId: string, signal?: AbortSignal) {
|
|
90
|
+
const response = await this.request(
|
|
91
|
+
`/api/agent/runs/${encodeURIComponent(runId)}`,
|
|
92
|
+
{ signal },
|
|
93
|
+
);
|
|
94
|
+
if (!response.ok) throw await remoteError(response);
|
|
95
|
+
return parseStatus(await response.json());
|
|
96
|
+
}
|
|
97
|
+
|
|
66
98
|
result(runId: string, signal?: AbortSignal) {
|
|
67
99
|
return this.request(`/api/agent/runs/${encodeURIComponent(runId)}/result`, {
|
|
68
100
|
signal,
|
|
@@ -109,10 +141,122 @@ export class RemoteAgentRuntime implements AgentRuntimePort {
|
|
|
109
141
|
}
|
|
110
142
|
}
|
|
111
143
|
|
|
144
|
+
function parseStart(value: unknown): AgentRuntimeStartResponse {
|
|
145
|
+
if (!isRecord(value)) throw new Error("Agent Runtime 创建响应无效");
|
|
146
|
+
const runId = text(value.runId);
|
|
147
|
+
const status = text(value.status);
|
|
148
|
+
const eventsUrl = text(value.eventsUrl);
|
|
149
|
+
if (!runId || !status || !runStatuses.has(status) || !eventsUrl) {
|
|
150
|
+
throw new Error("Agent Runtime 创建响应字段无效");
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
runId,
|
|
154
|
+
status: status as AgentRuntimeRunStatus,
|
|
155
|
+
eventsUrl,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function parseStatus(value: unknown): AgentRuntimeStatusResponse {
|
|
160
|
+
if (!isRecord(value)) throw new Error("Agent Runtime 状态响应无效");
|
|
161
|
+
const runId = text(value.runId);
|
|
162
|
+
const status = text(value.status);
|
|
163
|
+
const lastSequence = value.lastSequence;
|
|
164
|
+
if (
|
|
165
|
+
!runId ||
|
|
166
|
+
!status ||
|
|
167
|
+
!runStatuses.has(status) ||
|
|
168
|
+
!Number.isSafeInteger(lastSequence) ||
|
|
169
|
+
Number(lastSequence) < 0
|
|
170
|
+
) {
|
|
171
|
+
throw new Error("Agent Runtime 状态字段无效");
|
|
172
|
+
}
|
|
173
|
+
const terminalEvent =
|
|
174
|
+
value.terminalEvent === undefined
|
|
175
|
+
? undefined
|
|
176
|
+
: parseTerminalEvent(value.terminalEvent, runId);
|
|
177
|
+
const terminalStatus = ["completed", "failed", "cancelled"].includes(status);
|
|
178
|
+
if (
|
|
179
|
+
terminalStatus !== Boolean(terminalEvent) ||
|
|
180
|
+
(terminalEvent && terminalEvent.sequence !== Number(lastSequence)) ||
|
|
181
|
+
(terminalEvent && terminalEvent.type !== `run.${status}`)
|
|
182
|
+
) {
|
|
183
|
+
throw new Error("Agent Runtime 状态与终态事件不一致");
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
runId,
|
|
187
|
+
status: status as AgentRuntimeRunStatus,
|
|
188
|
+
lastSequence: Number(lastSequence),
|
|
189
|
+
...(terminalEvent ? { terminalEvent } : {}),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const runStatuses: ReadonlySet<string> = new Set<AgentRuntimeRunStatus>([
|
|
194
|
+
"accepted",
|
|
195
|
+
"running",
|
|
196
|
+
"awaiting-approval",
|
|
197
|
+
"completed",
|
|
198
|
+
"failed",
|
|
199
|
+
"cancelled",
|
|
200
|
+
]);
|
|
201
|
+
|
|
202
|
+
function parseTerminalEvent(
|
|
203
|
+
value: unknown,
|
|
204
|
+
expectedRunId: string,
|
|
205
|
+
): AgentRuntimeTerminalEvent {
|
|
206
|
+
if (!isRecord(value)) throw new Error("Agent Runtime 终态事件无效");
|
|
207
|
+
const type = value.type;
|
|
208
|
+
const runId = text(value.runId);
|
|
209
|
+
const sequence = value.sequence;
|
|
210
|
+
if (
|
|
211
|
+
!["run.completed", "run.failed", "run.cancelled"].includes(String(type)) ||
|
|
212
|
+
runId !== expectedRunId ||
|
|
213
|
+
!Number.isSafeInteger(sequence) ||
|
|
214
|
+
Number(sequence) <= 0
|
|
215
|
+
) {
|
|
216
|
+
throw new Error("Agent Runtime 终态事件字段无效");
|
|
217
|
+
}
|
|
218
|
+
if (type !== "run.failed") {
|
|
219
|
+
return {
|
|
220
|
+
type: type as "run.completed" | "run.cancelled",
|
|
221
|
+
runId,
|
|
222
|
+
sequence: Number(sequence),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
if (!isRecord(value.error)) throw new Error("Agent Runtime 失败事件无效");
|
|
226
|
+
const code = text(value.error.code);
|
|
227
|
+
const message = text(value.error.message);
|
|
228
|
+
const requestId = text(value.error.requestId);
|
|
229
|
+
if (
|
|
230
|
+
!code ||
|
|
231
|
+
!message ||
|
|
232
|
+
!requestId ||
|
|
233
|
+
typeof value.error.retryable !== "boolean"
|
|
234
|
+
) {
|
|
235
|
+
throw new Error("Agent Runtime 失败字段无效");
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
type,
|
|
239
|
+
runId,
|
|
240
|
+
sequence: Number(sequence),
|
|
241
|
+
error: { code, message, requestId, retryable: value.error.retryable },
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
246
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function text(value: unknown): string | undefined {
|
|
250
|
+
return typeof value === "string" && value.trim() ? value : undefined;
|
|
251
|
+
}
|
|
252
|
+
|
|
112
253
|
interface RemoteStartRunRequest extends Omit<AgentRuntimeOperation, "limits"> {
|
|
113
254
|
limits: {
|
|
114
255
|
maxDurationSeconds: number;
|
|
256
|
+
maxInputBytes: number;
|
|
115
257
|
maxOutputBytes: number;
|
|
258
|
+
maxArtifacts?: number;
|
|
259
|
+
maxPixelsPerArtifact?: number;
|
|
116
260
|
};
|
|
117
261
|
toolHostUrl: string;
|
|
118
262
|
}
|
|
@@ -128,22 +272,46 @@ function normalizeInternalUrl(raw: string): string {
|
|
|
128
272
|
return url.toString().replace(/\/$/, "");
|
|
129
273
|
}
|
|
130
274
|
|
|
131
|
-
async function remoteError(response: Response): Promise<
|
|
132
|
-
const safe = `Agent Runtime 请求失败(HTTP ${response.status})`;
|
|
275
|
+
async function remoteError(response: Response): Promise<AgentRuntimeError> {
|
|
133
276
|
try {
|
|
134
277
|
const value = (await response.json()) as {
|
|
135
278
|
code?: unknown;
|
|
136
279
|
message?: unknown;
|
|
280
|
+
retryable?: unknown;
|
|
137
281
|
};
|
|
138
282
|
if (
|
|
139
283
|
typeof value.code === "string" &&
|
|
140
284
|
typeof value.message === "string" &&
|
|
285
|
+
typeof value.retryable === "boolean" &&
|
|
141
286
|
value.message.length <= 200
|
|
142
287
|
) {
|
|
143
|
-
return new
|
|
288
|
+
return new AgentRuntimeError(
|
|
289
|
+
knownRemoteCode(value.code),
|
|
290
|
+
value.message,
|
|
291
|
+
value.retryable,
|
|
292
|
+
);
|
|
144
293
|
}
|
|
145
294
|
} catch {
|
|
146
295
|
// Provider 或代理正文不可透传。
|
|
147
296
|
}
|
|
148
|
-
return new
|
|
297
|
+
return new AgentRuntimeError(
|
|
298
|
+
"RUNTIME_UNAVAILABLE",
|
|
299
|
+
`Agent Runtime 请求失败(HTTP ${response.status})`,
|
|
300
|
+
response.status >= 500,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function knownRemoteCode(
|
|
305
|
+
code: string,
|
|
306
|
+
): ConstructorParameters<typeof AgentRuntimeError>[0] {
|
|
307
|
+
return [
|
|
308
|
+
"CAPABILITY_UNAVAILABLE",
|
|
309
|
+
"MODEL_ROUTE_UNAVAILABLE",
|
|
310
|
+
"RUN_CONFLICT",
|
|
311
|
+
"FORBIDDEN",
|
|
312
|
+
"BUDGET_EXCEEDED",
|
|
313
|
+
"INVALID_INPUT",
|
|
314
|
+
].includes(code)
|
|
315
|
+
? (code as ConstructorParameters<typeof AgentRuntimeError>[0])
|
|
316
|
+
: "RUNTIME_UNAVAILABLE";
|
|
149
317
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AgentRunAuthorizationStore } from "./run-authorization.js";
|
|
2
|
+
import { InMemoryAgentRunBindingRepository } from "./run-binding-repository.js";
|
|
3
|
+
|
|
4
|
+
export function createTestRunAuthorizationStore() {
|
|
5
|
+
return new AgentRunAuthorizationStore(
|
|
6
|
+
new InMemoryAgentRunBindingRepository(),
|
|
7
|
+
"test-agent-run-authorization-secret-32-bytes",
|
|
8
|
+
);
|
|
9
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { buildScopeContext } from "../data-access/context.js";
|
|
3
|
+
import { createRequestGuardContext } from "../guards.js";
|
|
4
|
+
import { AgentRunAuthorizationStore } from "./run-authorization.js";
|
|
5
|
+
import { InMemoryAgentRunBindingRepository } from "./run-binding-repository.js";
|
|
6
|
+
|
|
7
|
+
const secret = "agent-run-authorization-test-secret-32-bytes";
|
|
8
|
+
const snapshot = {
|
|
9
|
+
permissionKey: "business.ai.execute",
|
|
10
|
+
featureKey: "business.ai",
|
|
11
|
+
allowedToolKeys: ["business.records.list"],
|
|
12
|
+
toolNetworkMode: "forbidden" as const,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe("Agent Run 持久授权绑定", () => {
|
|
16
|
+
test("幂等重试和平台重启复用同一 Grant 与 Run", async () => {
|
|
17
|
+
const repository = new InMemoryAgentRunBindingRepository();
|
|
18
|
+
const firstStore = new AgentRunAuthorizationStore(repository, secret);
|
|
19
|
+
const first = await firstStore.issue({
|
|
20
|
+
operationKey: "business.answer",
|
|
21
|
+
releaseId: "release-1",
|
|
22
|
+
idempotencyKey: "request-1",
|
|
23
|
+
authorizationSnapshot: snapshot,
|
|
24
|
+
context: context("actor-1", "role-1"),
|
|
25
|
+
});
|
|
26
|
+
await firstStore.bind(first, "run-1");
|
|
27
|
+
|
|
28
|
+
const restartedStore = new AgentRunAuthorizationStore(repository, secret);
|
|
29
|
+
const retried = await restartedStore.issue({
|
|
30
|
+
operationKey: "business.answer",
|
|
31
|
+
releaseId: "release-1",
|
|
32
|
+
idempotencyKey: "request-1",
|
|
33
|
+
authorizationSnapshot: snapshot,
|
|
34
|
+
context: context("actor-1", "role-1"),
|
|
35
|
+
});
|
|
36
|
+
const toolBinding = await restartedStore.authorizeTool(
|
|
37
|
+
retried.token,
|
|
38
|
+
"run-1",
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
expect(retried.token).toBe(first.token);
|
|
42
|
+
expect(retried.binding.bindingId).toBe(first.binding.bindingId);
|
|
43
|
+
expect(toolBinding.runId).toBe("run-1");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("Tool 可先于 Start 响应绑定 provisional Run", async () => {
|
|
47
|
+
const store = new AgentRunAuthorizationStore(
|
|
48
|
+
new InMemoryAgentRunBindingRepository(),
|
|
49
|
+
secret,
|
|
50
|
+
);
|
|
51
|
+
const issued = await store.issue({
|
|
52
|
+
operationKey: "business.answer",
|
|
53
|
+
releaseId: "release-1",
|
|
54
|
+
idempotencyKey: "request-fast-tool",
|
|
55
|
+
authorizationSnapshot: snapshot,
|
|
56
|
+
context: context("actor-1", "role-1"),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const toolBinding = await store.authorizeTool(issued.token, "run-fast");
|
|
60
|
+
const facadeBinding = await store.bind(issued, "run-fast");
|
|
61
|
+
|
|
62
|
+
expect(toolBinding.runId).toBe("run-fast");
|
|
63
|
+
expect(facadeBinding.runId).toBe("run-fast");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("Actor、Operation、Scope 和过期绑定使用同一种拒绝", async () => {
|
|
67
|
+
let now = 1_000;
|
|
68
|
+
const store = new AgentRunAuthorizationStore(
|
|
69
|
+
new InMemoryAgentRunBindingRepository(),
|
|
70
|
+
secret,
|
|
71
|
+
() => now,
|
|
72
|
+
100,
|
|
73
|
+
);
|
|
74
|
+
const issued = await store.issue({
|
|
75
|
+
operationKey: "business.answer",
|
|
76
|
+
releaseId: "release-1",
|
|
77
|
+
idempotencyKey: "request-denied",
|
|
78
|
+
authorizationSnapshot: snapshot,
|
|
79
|
+
context: context("actor-1", "role-1"),
|
|
80
|
+
});
|
|
81
|
+
await store.bind(issued, "run-denied");
|
|
82
|
+
|
|
83
|
+
const attempts: Array<[string, ReturnType<typeof context>]> = [
|
|
84
|
+
["business.answer", context("actor-2", "role-1")],
|
|
85
|
+
["business.other", context("actor-1", "role-1")],
|
|
86
|
+
["business.answer", context("actor-1", "role-2")],
|
|
87
|
+
];
|
|
88
|
+
for (const [operationKey, deniedContext] of attempts) {
|
|
89
|
+
await expect(
|
|
90
|
+
store.authorizeBrowser(operationKey, "run-denied", deniedContext),
|
|
91
|
+
).rejects.toMatchObject({ message: "Agent Run 不存在或不可访问" });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
now = 1_101;
|
|
95
|
+
await expect(
|
|
96
|
+
store.authorizeBrowser(
|
|
97
|
+
"business.answer",
|
|
98
|
+
"run-denied",
|
|
99
|
+
context("actor-1", "role-1"),
|
|
100
|
+
),
|
|
101
|
+
).rejects.toMatchObject({
|
|
102
|
+
message: "Agent Run 不存在或不可访问",
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function context(actorId: string, roleId: string) {
|
|
108
|
+
return createRequestGuardContext(new Request("http://localhost"), {
|
|
109
|
+
resolveActor: () => ({
|
|
110
|
+
id: actorId,
|
|
111
|
+
type: "user",
|
|
112
|
+
name: actorId,
|
|
113
|
+
roleCodes: ["user"],
|
|
114
|
+
permissionKeys: ["business.ai.execute"],
|
|
115
|
+
scopeContext: buildScopeContext(actorId, undefined, [
|
|
116
|
+
{
|
|
117
|
+
id: roleId,
|
|
118
|
+
code: roleId,
|
|
119
|
+
dataScope: "self",
|
|
120
|
+
departmentIds: [],
|
|
121
|
+
},
|
|
122
|
+
]),
|
|
123
|
+
}),
|
|
124
|
+
resolveLicense: () => ({ status: "valid" }),
|
|
125
|
+
});
|
|
126
|
+
}
|