create-windy 0.5.2 → 0.6.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/dist/cli.js +288 -154
- package/package.json +2 -1
- package/template/.windy-template.json +2 -2
- package/template/apps/agent-server/README.md +25 -6
- package/template/apps/agent-server/src/southwind_agent_server/adk_adapter.py +15 -2
- package/template/apps/agent-server/src/southwind_agent_server/app.py +13 -34
- package/template/apps/agent-server/src/southwind_agent_server/config.py +49 -0
- package/template/apps/agent-server/src/southwind_agent_server/contracts.py +13 -0
- package/template/apps/agent-server/src/southwind_agent_server/engine_capacity.py +31 -0
- package/template/apps/agent-server/src/southwind_agent_server/fingerprint.py +5 -0
- package/template/apps/agent-server/src/southwind_agent_server/health_routes.py +50 -0
- package/template/apps/agent-server/src/southwind_agent_server/openai_engine.py +11 -2
- package/template/apps/agent-server/src/southwind_agent_server/openai_provider.py +3 -9
- package/template/apps/agent-server/src/southwind_agent_server/postgres_store.py +5 -0
- package/template/apps/agent-server/src/southwind_agent_server/readiness_pin.py +37 -0
- package/template/apps/agent-server/src/southwind_agent_server/run_admission.py +64 -0
- package/template/apps/agent-server/src/southwind_agent_server/run_capacity.py +59 -0
- package/template/apps/agent-server/src/southwind_agent_server/service.py +42 -43
- package/template/apps/agent-server/src/southwind_agent_server/service_errors.py +4 -0
- package/template/apps/agent-server/src/southwind_agent_server/service_execution.py +31 -0
- package/template/apps/agent-server/src/southwind_agent_server/service_tasks.py +34 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_catalog.py +11 -0
- package/template/apps/agent-server/src/southwind_agent_server/store.py +6 -0
- package/template/apps/agent-server/src/southwind_agent_server/vision_probe.py +87 -0
- package/template/apps/agent-server/src/southwind_agent_server/vision_requirement.py +28 -0
- package/template/apps/agent-server/src/southwind_agent_server/vlm_readiness.py +247 -0
- package/template/apps/agent-server/tests/test_api.py +16 -3
- package/template/apps/agent-server/tests/test_openai_provider.py +21 -4
- package/template/apps/agent-server/tests/test_postgres_store.py +3 -0
- package/template/apps/agent-server/tests/test_run_capacity.py +110 -0
- package/template/apps/agent-server/tests/test_runtime_factory_readiness.py +37 -0
- package/template/apps/agent-server/tests/test_sqlite_store.py +3 -0
- package/template/apps/agent-server/tests/test_vision_readiness_enforcement.py +72 -0
- package/template/apps/agent-server/tests/test_vlm_readiness.py +106 -0
- package/template/apps/document-server/src/southwind_document_server/adapter.py +117 -205
- package/template/apps/document-server/src/southwind_document_server/adapter_errors.py +13 -0
- package/template/apps/document-server/src/southwind_document_server/app.py +62 -14
- package/template/apps/document-server/src/southwind_document_server/artifacts.py +27 -0
- package/template/apps/document-server/src/southwind_document_server/config.py +96 -2
- package/template/apps/document-server/src/southwind_document_server/contracts.py +168 -13
- package/template/apps/document-server/src/southwind_document_server/fingerprint.py +128 -0
- package/template/apps/document-server/src/southwind_document_server/grants.py +81 -0
- package/template/apps/document-server/src/southwind_document_server/multipart_output.py +265 -0
- package/template/apps/document-server/src/southwind_document_server/output_validation.py +202 -0
- package/template/apps/document-server/src/southwind_document_server/progress.py +27 -0
- package/template/apps/document-server/src/southwind_document_server/readiness.py +280 -0
- package/template/apps/document-server/src/southwind_document_server/readiness_contracts.py +280 -0
- package/template/apps/document-server/src/southwind_document_server/readiness_http.py +87 -0
- package/template/apps/document-server/src/southwind_document_server/readiness_support.py +120 -0
- package/template/apps/document-server/src/southwind_document_server/request_validation.py +48 -0
- package/template/apps/document-server/src/southwind_document_server/service.py +297 -96
- package/template/apps/document-server/src/southwind_document_server/service_recovery.py +183 -0
- package/template/apps/document-server/src/southwind_document_server/sink.py +316 -0
- package/template/apps/document-server/src/southwind_document_server/store.py +301 -141
- package/template/apps/document-server/src/southwind_document_server/store_events.py +40 -0
- package/template/apps/document-server/src/southwind_document_server/store_models.py +62 -0
- package/template/apps/document-server/src/southwind_document_server/store_recovery.py +247 -0
- package/template/apps/document-server/src/southwind_document_server/store_schema.py +50 -0
- package/template/apps/document-server/tests/recovery_support.py +230 -0
- package/template/apps/document-server/tests/support.py +210 -0
- package/template/apps/document-server/tests/test_adapter.py +251 -0
- package/template/apps/document-server/tests/test_config.py +43 -0
- package/template/apps/document-server/tests/test_contracts.py +80 -0
- package/template/apps/document-server/tests/test_fingerprint.py +125 -0
- package/template/apps/document-server/tests/test_grants.py +46 -0
- package/template/apps/document-server/tests/test_handshake.py +154 -0
- package/template/apps/document-server/tests/test_integration.py +192 -0
- package/template/apps/document-server/tests/test_multipart_security.py +259 -0
- package/template/apps/document-server/tests/test_readiness.py +311 -0
- package/template/apps/document-server/tests/test_readiness_contracts.py +131 -0
- package/template/apps/document-server/tests/test_recovery.py +222 -0
- package/template/apps/document-server/tests/test_recovery_faults.py +101 -0
- package/template/apps/document-server/tests/test_recovery_races.py +283 -0
- package/template/apps/document-server/tests/test_service.py +16 -13
- package/template/apps/document-server/tests/test_service_artifacts.py +296 -0
- package/template/apps/document-server/tests/test_sink.py +253 -0
- package/template/apps/document-server/tests/test_store.py +199 -0
- package/template/apps/embedding-server/pyproject.toml +5 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/adapter.py +38 -2
- package/template/apps/embedding-server/src/southwind_embedding_server/app.py +111 -3
- package/template/apps/embedding-server/src/southwind_embedding_server/config.py +27 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/image_input.py +16 -5
- package/template/apps/embedding-server/src/southwind_embedding_server/run_cipher.py +31 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/run_service.py +130 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/run_store.py +250 -0
- package/template/apps/embedding-server/tests/test_adapter.py +25 -0
- package/template/apps/embedding-server/tests/test_run_http.py +185 -0
- package/template/apps/embedding-server/tests/test_run_service.py +200 -0
- package/template/apps/embedding-server/uv.lock +71 -0
- package/template/apps/server/Dockerfile +13 -0
- package/template/apps/server/package.json +1 -0
- package/template/apps/server/src/agent/drizzle-screenshot-intake-repository.integration.test.ts +283 -0
- package/template/apps/server/src/agent/drizzle-screenshot-intake-repository.ts +175 -0
- package/template/apps/server/src/agent/persistent-screenshot-intake-producer.ts +320 -0
- package/template/apps/server/src/agent/remote-runtime.ts +8 -1
- package/template/apps/server/src/agent/required-environment.ts +5 -0
- package/template/apps/server/src/agent/run-attach.ts +41 -0
- package/template/apps/server/src/agent/run-audit.ts +49 -0
- package/template/apps/server/src/agent/run-contracts.ts +6 -1
- package/template/apps/server/src/agent/run-facade.ts +66 -68
- package/template/apps/server/src/agent/run-route-input.ts +26 -1
- package/template/apps/server/src/agent/run-routes.ts +1 -0
- package/template/apps/server/src/agent/runtime-bootstrap-report.test.ts +1 -1
- package/template/apps/server/src/agent/runtime-bootstrap.ts +110 -60
- package/template/apps/server/src/agent/runtime-readiness-sources.test.ts +27 -0
- package/template/apps/server/src/agent/runtime-readiness-sources.ts +31 -0
- package/template/apps/server/src/agent/runtime-reporting-bootstrap.ts +40 -0
- package/template/apps/server/src/agent/screenshot-intake-authorization.ts +29 -0
- package/template/apps/server/src/agent/screenshot-intake-bootstrap.ts +61 -0
- package/template/apps/server/src/agent/screenshot-intake-durable.ts +53 -0
- package/template/apps/server/src/agent/screenshot-intake-errors.ts +9 -0
- package/template/apps/server/src/agent/screenshot-intake-producer.ts +41 -0
- package/template/apps/server/src/agent/screenshot-intake-record.ts +44 -0
- package/template/apps/server/src/agent/screenshot-intake-recovery.ts +106 -0
- package/template/apps/server/src/agent/screenshot-intake-repository.ts +64 -0
- package/template/apps/server/src/agent/screenshot-intake-reservation.ts +24 -0
- package/template/apps/server/src/agent/screenshot-intake-routes.ts +171 -0
- package/template/apps/server/src/agent/screenshot-intake-runtime-types.ts +6 -0
- package/template/apps/server/src/agent/screenshot-intake-sweep.ts +26 -0
- package/template/apps/server/src/agent/screenshot-intake-test-support.ts +87 -0
- package/template/apps/server/src/agent/screenshot-intake-v2-validation.ts +152 -0
- package/template/apps/server/src/agent/screenshot-intake-v2.test.ts +338 -0
- package/template/apps/server/src/agent/screenshot-intake-v2.ts +350 -0
- package/template/apps/server/src/agent/screenshot-png.ts +15 -0
- package/template/apps/server/src/agent/screenshot-run-binding.ts +34 -0
- package/template/apps/server/src/agent/unavailable-routes.ts +9 -0
- package/template/apps/server/src/agent/vision-facade.test.ts +98 -8
- package/template/apps/server/src/agent/vision-input.ts +5 -2
- package/template/apps/server/src/agent/vision-readiness-pin.ts +74 -0
- package/template/apps/server/src/agent/vision-readiness.ts +58 -0
- package/template/apps/server/src/ai-artifact/runtime-reference.test.ts +135 -0
- package/template/apps/server/src/ai-artifact/runtime.ts +134 -5
- package/template/apps/server/src/ai-output-artifact/cleanup.ts +214 -0
- package/template/apps/server/src/ai-output-artifact/contracts.ts +152 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-cleanup.ts +37 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-complete.ts +71 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-grant-cleanup.ts +45 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-grants.ts +109 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-mapping.ts +77 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-readiness.ts +46 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-repository.ts +350 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-seal.ts +64 -0
- package/template/apps/server/src/ai-output-artifact/grant.ts +30 -0
- package/template/apps/server/src/ai-output-artifact/host-registry.ts +53 -0
- package/template/apps/server/src/ai-output-artifact/memory-cleanup.ts +47 -0
- package/template/apps/server/src/ai-output-artifact/memory-grants.ts +98 -0
- package/template/apps/server/src/ai-output-artifact/memory-readiness.ts +26 -0
- package/template/apps/server/src/ai-output-artifact/memory-repository.ts +348 -0
- package/template/apps/server/src/ai-output-artifact/policy.test.ts +67 -0
- package/template/apps/server/src/ai-output-artifact/policy.ts +125 -0
- package/template/apps/server/src/ai-output-artifact/postgres-test-support.ts +147 -0
- package/template/apps/server/src/ai-output-artifact/postgres.integration.test.ts +349 -0
- package/template/apps/server/src/ai-output-artifact/reference-codec.ts +128 -0
- package/template/apps/server/src/ai-output-artifact/repository-grant-invariants.test-support.ts +165 -0
- package/template/apps/server/src/ai-output-artifact/repository-invariants.test-support.ts +239 -0
- package/template/apps/server/src/ai-output-artifact/repository-invariants.test.ts +18 -0
- package/template/apps/server/src/ai-output-artifact/repository.ts +107 -0
- package/template/apps/server/src/ai-output-artifact/route-input.ts +173 -0
- package/template/apps/server/src/ai-output-artifact/routes-delete.test.ts +287 -0
- package/template/apps/server/src/ai-output-artifact/routes-grant.test.ts +116 -0
- package/template/apps/server/src/ai-output-artifact/routes-nonblocking-body.test.ts +136 -0
- package/template/apps/server/src/ai-output-artifact/routes-security.test.ts +176 -0
- package/template/apps/server/src/ai-output-artifact/routes-storage-error.test.ts +105 -0
- package/template/apps/server/src/ai-output-artifact/routes.test-support.ts +84 -0
- package/template/apps/server/src/ai-output-artifact/routes.test.ts +198 -0
- package/template/apps/server/src/ai-output-artifact/routes.ts +280 -0
- package/template/apps/server/src/ai-output-artifact/service-completion.ts +60 -0
- package/template/apps/server/src/ai-output-artifact/service-grants.test.ts +169 -0
- package/template/apps/server/src/ai-output-artifact/service-grants.ts +217 -0
- package/template/apps/server/src/ai-output-artifact/service-input.ts +175 -0
- package/template/apps/server/src/ai-output-artifact/service-read.ts +89 -0
- package/template/apps/server/src/ai-output-artifact/service-recovery.test.ts +238 -0
- package/template/apps/server/src/ai-output-artifact/service-support.ts +240 -0
- package/template/apps/server/src/ai-output-artifact/service.test.ts +283 -0
- package/template/apps/server/src/ai-output-artifact/service.ts +334 -0
- package/template/apps/server/src/ai-output-artifact/storage-recovery.ts +33 -0
- package/template/apps/server/src/ai-output-artifact/storage-writer.ts +103 -0
- package/template/apps/server/src/ai-output-artifact/test-support.ts +161 -0
- package/template/apps/server/src/ai-runtime-readiness/health-response.ts +92 -0
- package/template/apps/server/src/ai-runtime-readiness/operation-port-trust.test.ts +66 -0
- package/template/apps/server/src/ai-runtime-readiness/operation-port.test-support.ts +143 -0
- package/template/apps/server/src/ai-runtime-readiness/operation-port.test.ts +193 -0
- package/template/apps/server/src/ai-runtime-readiness/operation-port.ts +172 -0
- package/template/apps/server/src/ai-runtime-readiness/trust-store.ts +61 -0
- package/template/apps/server/src/app/ai-screenshot-intake-binding.ts +22 -0
- package/template/apps/server/src/app/document-output-artifact-bindings.ts +5 -0
- package/template/apps/server/src/app/speech-output-artifact-bindings.ts +5 -0
- package/template/apps/server/src/application-services.ts +9 -3
- package/template/apps/server/src/audit/redaction.ts +1 -0
- package/template/apps/server/src/audit/reliable-writer.test.ts +8 -0
- package/template/apps/server/src/auth/password-change-license-restriction.test.ts +156 -0
- package/template/apps/server/src/document/cancel-response.ts +33 -0
- package/template/apps/server/src/document/contracts.ts +6 -0
- package/template/apps/server/src/document/errors.ts +11 -0
- package/template/apps/server/src/document/facade-cancel.test.ts +226 -0
- package/template/apps/server/src/document/facade-cancel.ts +110 -0
- package/template/apps/server/src/document/facade-grant-handoff.test.ts +113 -0
- package/template/apps/server/src/document/facade-idempotency.test.ts +195 -0
- package/template/apps/server/src/document/facade-invocation.ts +46 -0
- package/template/apps/server/src/document/facade-output-artifact.test.ts +310 -0
- package/template/apps/server/src/document/facade-read-response.ts +116 -0
- package/template/apps/server/src/document/facade-readiness.test.ts +95 -0
- package/template/apps/server/src/document/facade-support.ts +297 -0
- package/template/apps/server/src/document/facade.ts +164 -173
- package/template/apps/server/src/document/output-artifact-composition.test.ts +64 -0
- package/template/apps/server/src/document/output-artifact-composition.ts +78 -0
- package/template/apps/server/src/document/output-artifact-fingerprint.contract.test.ts +110 -0
- package/template/apps/server/src/document/output-artifact-fingerprint.ts +150 -0
- package/template/apps/server/src/document/output-artifact-host-registry.ts +44 -0
- package/template/apps/server/src/document/output-artifact-host.test.ts +332 -0
- package/template/apps/server/src/document/output-artifact-host.ts +331 -0
- package/template/apps/server/src/document/output-artifact-manifest.test-support.ts +71 -0
- package/template/apps/server/src/document/output-artifact-publish.test-support.ts +48 -0
- package/template/apps/server/src/document/output-artifact-readiness-probe.ts +347 -0
- package/template/apps/server/src/document/output-artifact-readiness-timeout.ts +30 -0
- package/template/apps/server/src/document/output-artifact-readiness.test.ts +264 -0
- package/template/apps/server/src/document/output-artifact-readiness.ts +87 -0
- package/template/apps/server/src/document/output-artifact-route-composition.test.ts +27 -0
- package/template/apps/server/src/document/output-artifact-route-composition.ts +14 -0
- package/template/apps/server/src/document/output-artifact-runtime.test-support.ts +8 -0
- package/template/apps/server/src/document/output-artifact-runtime.test.ts +124 -0
- package/template/apps/server/src/document/output-artifact-runtime.ts +275 -0
- package/template/apps/server/src/document/output-artifact.test-support.ts +350 -0
- package/template/apps/server/src/document/remote-response.ts +162 -0
- package/template/apps/server/src/document/remote-runtime.test.ts +100 -4
- package/template/apps/server/src/document/remote-runtime.ts +37 -85
- package/template/apps/server/src/document/routes-read-response.test.ts +267 -0
- package/template/apps/server/src/document/routes.test.ts +109 -0
- package/template/apps/server/src/document/routes.ts +23 -14
- package/template/apps/server/src/embedding/audit.ts +46 -0
- package/template/apps/server/src/embedding/contracts.ts +13 -0
- package/template/apps/server/src/embedding/drizzle-run-binding-repository.integration.test.ts +100 -0
- package/template/apps/server/src/embedding/drizzle-run-binding-repository.ts +102 -0
- package/template/apps/server/src/embedding/facade-types.ts +18 -0
- package/template/apps/server/src/embedding/facade.ts +242 -111
- package/template/apps/server/src/embedding/operation-authorization.ts +23 -0
- package/template/apps/server/src/embedding/remote-runtime.test.ts +18 -0
- package/template/apps/server/src/embedding/remote-runtime.ts +77 -0
- package/template/apps/server/src/embedding/routes.test.ts +118 -0
- package/template/apps/server/src/embedding/routes.ts +98 -0
- package/template/apps/server/src/embedding/run-artifact.ts +18 -0
- package/template/apps/server/src/embedding/run-authorization.test.ts +133 -0
- package/template/apps/server/src/embedding/run-authorization.ts +91 -0
- package/template/apps/server/src/embedding/run-binding-repository.ts +75 -0
- package/template/apps/server/src/embedding/run-fingerprint.test.ts +52 -0
- package/template/apps/server/src/embedding/run-fingerprint.ts +39 -0
- package/template/apps/server/src/embedding/terminal-observer.test.ts +26 -0
- package/template/apps/server/src/embedding/terminal-observer.ts +44 -0
- package/template/apps/server/src/index.ts +38 -31
- package/template/apps/server/src/module-host/ai-operation-port.ts +3 -3
- package/template/apps/server/src/module-host/durable-context.ts +194 -16
- package/template/apps/server/src/module-host/durable-handler-registration.ts +1 -0
- package/template/apps/server/src/module-host/durable-storage-filesystem-restart.test.ts +265 -0
- package/template/apps/server/src/module-host/durable-storage-write.test.ts +345 -0
- package/template/apps/server/src/module-host/http-runtime.ts +25 -0
- package/template/apps/server/src/module-host/initialize-contracts.ts +18 -1
- package/template/apps/server/src/module-host/initialize.test.ts +18 -0
- package/template/apps/server/src/module-host/initialize.ts +42 -2
- package/template/apps/server/src/module-host/module-secret-audit-version.test.ts +73 -0
- package/template/apps/server/src/module-host/module-secret-binding-resolution.ts +60 -0
- package/template/apps/server/src/module-host/module-secret-durable.test.ts +206 -0
- package/template/apps/server/src/module-host/module-secret-port.test-support.ts +125 -0
- package/template/apps/server/src/module-host/module-secret-port.test.ts +161 -0
- package/template/apps/server/src/module-host/module-secret-port.ts +249 -0
- package/template/apps/server/src/module-host/module-secret-result.test.ts +324 -0
- package/template/apps/server/src/module-host/module-secret-result.ts +274 -0
- package/template/apps/server/src/module-host/module-secret-tool-boundary.test.ts +143 -0
- package/template/apps/server/src/module-host/project-composition.ts +1 -0
- package/template/apps/server/src/module-host/report-staging-port.ts +55 -0
- package/template/apps/server/src/module-host/report-staging-registration.test.ts +104 -0
- package/template/apps/server/src/module-host/request-context.ts +58 -1
- package/template/apps/server/src/module-host/route-declaration.ts +11 -4
- package/template/apps/server/src/module-host/route-installer.test-fixture.ts +246 -0
- package/template/apps/server/src/module-host/route-installer.test.ts +47 -211
- package/template/apps/server/src/module-host/route-installer.ts +192 -21
- package/template/apps/server/src/module-host/route-registration.test.ts +44 -4
- package/template/apps/server/src/module-host/runtime-composition.ts +2 -0
- package/template/apps/server/src/module-host/scoped-host.ts +84 -0
- package/template/apps/server/src/module-host/screenshot-artifact-ref.ts +91 -0
- package/template/apps/server/src/module-host/screenshot-intake-composition.test.ts +292 -0
- package/template/apps/server/src/module-host/screenshot-intake-deadline.ts +38 -0
- package/template/apps/server/src/module-host/screenshot-intake-plan.ts +75 -0
- package/template/apps/server/src/module-host/screenshot-intake-port.ts +297 -0
- package/template/apps/server/src/module-host/screenshot-intake-security.test.ts +311 -0
- package/template/apps/server/src/module-host/screenshot-intake-store.ts +76 -0
- package/template/apps/server/src/module-host/screenshot-intake-test-support.ts +68 -0
- package/template/apps/server/src/module-host/secret-bindings.test.ts +167 -0
- package/template/apps/server/src/module-host/secret-bindings.ts +184 -0
- package/template/apps/server/src/module-host/storage-authorization-binding.test.ts +242 -0
- package/template/apps/server/src/module-host/storage-port.test.ts +8 -1
- package/template/apps/server/src/module-host/storage-port.ts +84 -8
- package/template/apps/server/src/module-host/storage-restart-fixture.test-support.ts +242 -0
- package/template/apps/server/src/module-host/storage-restart-postgres.integration.test.ts +280 -0
- package/template/apps/server/src/module-host/storage-scope-drift-http.test.ts +68 -0
- package/template/apps/server/src/module-host/storage-scope.ts +52 -1
- package/template/apps/server/src/module-host/storage-stream-route.test.ts +282 -0
- package/template/apps/server/src/module-host/storage-write-error.test.ts +174 -0
- package/template/apps/server/src/module-host/storage-write-error.ts +62 -0
- package/template/apps/server/src/module-host/storage-write-port.test.ts +323 -0
- package/template/apps/server/src/module-host/storage-write-port.ts +320 -0
- package/template/apps/server/src/module-host/storage-write-unavailable.ts +21 -0
- package/template/apps/server/src/module-host/storage-writer-retention.test.ts +109 -0
- package/template/apps/server/src/module-host/user-directory-composition.test.ts +1 -0
- package/template/apps/server/src/module-preflight-secret.test.ts +79 -0
- package/template/apps/server/src/module-preflight.ts +5 -0
- package/template/apps/server/src/platform-http-runtime.ts +16 -4
- package/template/apps/server/src/report-staging/archive-frame-stream.test.ts +209 -0
- package/template/apps/server/src/report-staging/archive-frame-stream.ts +341 -0
- package/template/apps/server/src/report-staging/archive-process.test.ts +302 -0
- package/template/apps/server/src/report-staging/archive-process.ts +257 -0
- package/template/apps/server/src/report-staging/archive-volumes.ts +30 -0
- package/template/apps/server/src/report-staging/cancellation.ts +13 -0
- package/template/apps/server/src/report-staging/contracts.ts +94 -0
- package/template/apps/server/src/report-staging/drizzle-lifecycle.ts +278 -0
- package/template/apps/server/src/report-staging/drizzle-mapping.ts +140 -0
- package/template/apps/server/src/report-staging/drizzle-repository.integration.test.ts +346 -0
- package/template/apps/server/src/report-staging/drizzle-repository.ts +255 -0
- package/template/apps/server/src/report-staging/drizzle-seal.integration.test.ts +267 -0
- package/template/apps/server/src/report-staging/drizzle-seal.ts +177 -0
- package/template/apps/server/src/report-staging/filesystem-cleanup.test.ts +68 -0
- package/template/apps/server/src/report-staging/filesystem-cleanup.ts +102 -0
- package/template/apps/server/src/report-staging/filesystem-errors.ts +15 -0
- package/template/apps/server/src/report-staging/filesystem-identifiers.ts +19 -0
- package/template/apps/server/src/report-staging/filesystem-io.test.ts +85 -0
- package/template/apps/server/src/report-staging/filesystem-io.ts +206 -0
- package/template/apps/server/src/report-staging/filesystem-scan.ts +85 -0
- package/template/apps/server/src/report-staging/filesystem-store.ts +346 -0
- package/template/apps/server/src/report-staging/heartbeat.test.ts +47 -0
- package/template/apps/server/src/report-staging/heartbeat.ts +53 -0
- package/template/apps/server/src/report-staging/manifest-stream.ts +46 -0
- package/template/apps/server/src/report-staging/memory-repository.ts +256 -0
- package/template/apps/server/src/report-staging/metadata-catalog.ts +89 -0
- package/template/apps/server/src/report-staging/metadata-spool-paths.ts +195 -0
- package/template/apps/server/src/report-staging/metadata-spool-schema.ts +54 -0
- package/template/apps/server/src/report-staging/metadata-spool.test.ts +214 -0
- package/template/apps/server/src/report-staging/metadata-spool.ts +305 -0
- package/template/apps/server/src/report-staging/native/archive-frame-helper.c +309 -0
- package/template/apps/server/src/report-staging/path-policy.test.ts +127 -0
- package/template/apps/server/src/report-staging/path-policy.ts +263 -0
- package/template/apps/server/src/report-staging/repository-fence.test.ts +114 -0
- package/template/apps/server/src/report-staging/repository.ts +75 -0
- package/template/apps/server/src/report-staging/runtime.ts +31 -0
- package/template/apps/server/src/report-staging/sealed-file.test.ts +34 -0
- package/template/apps/server/src/report-staging/sealed-file.ts +137 -0
- package/template/apps/server/src/report-staging/service-input-limits.test.ts +62 -0
- package/template/apps/server/src/report-staging/service-input.ts +204 -0
- package/template/apps/server/src/report-staging/service-lifecycle.test.ts +132 -0
- package/template/apps/server/src/report-staging/service-read-fence.test.ts +37 -0
- package/template/apps/server/src/report-staging/service-read.ts +172 -0
- package/template/apps/server/src/report-staging/service-support.ts +149 -0
- package/template/apps/server/src/report-staging/service.test-fixture.ts +226 -0
- package/template/apps/server/src/report-staging/service.test.ts +314 -0
- package/template/apps/server/src/report-staging/service.ts +255 -0
- package/template/apps/server/src/report-staging/supervised-process.ts +194 -0
- package/template/apps/server/src/speech/contracts.ts +8 -0
- package/template/apps/server/src/speech/errors.ts +10 -0
- package/template/apps/server/src/speech/facade-contract.ts +49 -0
- package/template/apps/server/src/speech/facade-output.test.ts +299 -0
- package/template/apps/server/src/speech/facade-output.ts +298 -0
- package/template/apps/server/src/speech/facade-validation.ts +127 -0
- package/template/apps/server/src/speech/facade.ts +185 -151
- package/template/apps/server/src/speech/fingerprint.test.ts +42 -0
- package/template/apps/server/src/speech/fingerprint.ts +28 -0
- package/template/apps/server/src/speech/output-artifact-binding.test.ts +11 -0
- package/template/apps/server/src/speech/output-artifact-binding.ts +30 -0
- package/template/apps/server/src/speech/output-artifact-error.ts +9 -0
- package/template/apps/server/src/speech/output-artifact-host.test-support.ts +73 -0
- package/template/apps/server/src/speech/output-artifact-host.test.ts +302 -0
- package/template/apps/server/src/speech/output-artifact-host.ts +279 -0
- package/template/apps/server/src/speech/output-artifact-policy.ts +114 -0
- package/template/apps/server/src/speech/output-artifact-replay.ts +91 -0
- package/template/apps/server/src/speech/remote-response.ts +158 -0
- package/template/apps/server/src/speech/remote-runtime.test.ts +90 -0
- package/template/apps/server/src/speech/remote-runtime.ts +36 -78
- package/template/apps/server/src/speech/routes.ts +60 -16
- package/template/apps/server/src/startup-finalization.ts +52 -0
- package/template/apps/server/src/startup-preflight.ts +2 -0
- package/template/apps/server/src/startup-shutdown.test.ts +69 -0
- package/template/apps/server/src/startup-shutdown.ts +61 -0
- package/template/apps/server/src/storage/drizzle-upload-purge.ts +61 -0
- package/template/apps/server/src/storage/drizzle-upload-references.ts +23 -0
- package/template/apps/server/src/storage/drizzle-upload-repository.integration.test.ts +103 -0
- package/template/apps/server/src/storage/drizzle-upload-repository.ts +109 -14
- package/template/apps/server/src/storage/host-runtime.ts +15 -0
- package/template/apps/server/src/storage/routes-stream-cancellation.test.ts +154 -0
- package/template/apps/server/src/storage/routes.test.ts +13 -2
- package/template/apps/server/src/storage/routes.ts +57 -18
- package/template/apps/server/src/storage/runtime.ts +17 -4
- package/template/apps/server/src/system/route-types.ts +5 -1
- package/template/apps/server/src/system/system-resource-monitoring.test.ts +47 -0
- package/template/apps/server/src/system/system-resource-monitoring.ts +60 -10
- package/template/apps/server/src/work-order/routes.test.ts +1 -0
- package/template/apps/speech-server/src/southwind_speech_server/adapter.py +58 -17
- package/template/apps/speech-server/src/southwind_speech_server/app.py +24 -17
- package/template/apps/speech-server/src/southwind_speech_server/bounded_json.py +60 -0
- package/template/apps/speech-server/src/southwind_speech_server/config.py +122 -2
- package/template/apps/speech-server/src/southwind_speech_server/contracts.py +58 -0
- package/template/apps/speech-server/src/southwind_speech_server/errors.py +8 -0
- package/template/apps/speech-server/src/southwind_speech_server/normalizer.py +14 -0
- package/template/apps/speech-server/src/southwind_speech_server/output_artifact.py +190 -0
- package/template/apps/speech-server/src/southwind_speech_server/output_validation.py +54 -0
- package/template/apps/speech-server/src/southwind_speech_server/pin_cli.py +83 -0
- package/template/apps/speech-server/src/southwind_speech_server/readiness.py +266 -0
- package/template/apps/speech-server/src/southwind_speech_server/readiness_contracts.py +268 -0
- package/template/apps/speech-server/src/southwind_speech_server/readiness_http.py +91 -0
- package/template/apps/speech-server/src/southwind_speech_server/readiness_local.py +161 -0
- package/template/apps/speech-server/src/southwind_speech_server/readiness_support.py +106 -0
- package/template/apps/speech-server/src/southwind_speech_server/service.py +118 -13
- package/template/apps/speech-server/src/southwind_speech_server/store.py +7 -0
- package/template/apps/speech-server/tests/test_bounded_json.py +55 -0
- package/template/apps/speech-server/tests/test_config.py +22 -0
- package/template/apps/speech-server/tests/test_output_artifact.py +60 -0
- package/template/apps/speech-server/tests/test_output_validation.py +44 -0
- package/template/apps/speech-server/tests/test_readiness.py +315 -0
- package/template/apps/speech-server/tests/test_readiness_http.py +48 -0
- package/template/apps/speech-server/tests/test_readiness_local.py +43 -0
- package/template/apps/speech-server/tests/test_service.py +211 -36
- package/template/apps/web/src/pages/system/components/OperationGpuMonitor.vue +2 -1
- package/template/apps/web/src/pages/system/components/OperationGpuMonitor.webtest.ts +29 -0
- package/template/apps/web/src/pages/system/components/OperationServiceMonitor.vue +2 -1
- package/template/apps/web/src/pages/system/components/OperationServiceMonitor.webtest.ts +4 -1
- package/template/docker-compose.yml +38 -1
- package/template/docs/architecture/ai-runtime-readiness.md +498 -0
- package/template/docs/architecture/ai-runtime.md +20 -4
- package/template/docs/architecture/durable-jobs.md +54 -5
- package/template/docs/architecture/module-host.md +72 -9
- package/template/docs/architecture/module-manifest-composition.md +5 -2
- package/template/docs/architecture/module-secret-resolution.md +250 -0
- package/template/docs/architecture/object-storage.md +144 -3
- package/template/docs/architecture/report-staging.md +158 -0
- package/template/docs/architecture/server-module-interface.md +29 -0
- package/template/docs/architecture/speech-variants.md +45 -0
- package/template/docs/platform/agent-tools.md +16 -0
- package/template/docs/platform/document-ai-runtime.md +199 -17
- package/template/docs/platform/module-configuration.md +5 -0
- package/template/docs/platform/speech-ai-runtime.md +34 -5
- package/template/docs/platform/vision-ai-runtime.md +24 -0
- package/template/package.json +4 -1
- package/template/packages/ai-client/package.json +1 -1
- package/template/packages/ai-client/src/agent/client/client.ts +3 -0
- package/template/packages/ai-client/src/agent/client/index.ts +1 -0
- package/template/packages/ai-client/src/agent/client/screenshot.test.ts +40 -0
- package/template/packages/ai-client/src/agent/client/screenshot.ts +146 -0
- package/template/packages/ai-client/src/agent/client/types.ts +2 -0
- package/template/packages/ai-client/src/agent/contracts/runs.ts +1 -0
- package/template/packages/ai-client/src/embedding/client.test.ts +52 -0
- package/template/packages/ai-client/src/embedding/client.ts +69 -0
- package/template/packages/ai-client/src/embedding/contracts.ts +47 -0
- package/template/packages/ai-client/src/embedding/index.ts +1 -0
- package/template/packages/ai-client/src/embedding/run.ts +130 -0
- package/template/packages/ai-client/src/speech/client.test.ts +26 -0
- package/template/packages/ai-client/src/speech/client.ts +25 -1
- package/template/packages/ai-client/src/speech/contracts.ts +19 -0
- package/template/packages/config/package.json +1 -1
- package/template/packages/database/drizzle/0048_illegal_magneto.sql +11 -0
- package/template/packages/database/drizzle/0049_right_lenny_balinger.sql +79 -0
- package/template/packages/database/drizzle/0050_greedy_sister_grimm.sql +92 -0
- package/template/packages/database/drizzle/0051_lame_shockwave.sql +19 -0
- package/template/packages/database/drizzle/0052_tiresome_komodo.sql +1 -0
- package/template/packages/database/drizzle/0053_calm_victor_mancha.sql +1 -0
- package/template/packages/database/drizzle/0054_tough_thanos.sql +29 -0
- package/template/packages/database/drizzle/meta/0048_snapshot.json +8852 -0
- package/template/packages/database/drizzle/meta/0049_snapshot.json +9410 -0
- package/template/packages/database/drizzle/meta/0050_snapshot.json +10115 -0
- package/template/packages/database/drizzle/meta/0051_snapshot.json +10257 -0
- package/template/packages/database/drizzle/meta/0052_snapshot.json +10263 -0
- package/template/packages/database/drizzle/meta/0053_snapshot.json +10270 -0
- package/template/packages/database/drizzle/meta/0054_snapshot.json +10468 -0
- package/template/packages/database/drizzle/meta/_journal.json +49 -0
- package/template/packages/database/package.json +1 -1
- package/template/packages/database/src/agent-runtime-schema.test.ts +15 -0
- package/template/packages/database/src/ai-output-artifacts.test.ts +57 -0
- package/template/packages/database/src/schema/agent-runtime.ts +43 -0
- package/template/packages/database/src/schema/ai-output-artifacts.ts +182 -0
- package/template/packages/database/src/schema/embedding-runtime.ts +62 -0
- package/template/packages/database/src/schema/file-storage.ts +18 -0
- package/template/packages/database/src/schema/index.ts +3 -0
- package/template/packages/database/src/schema/report-staging.ts +212 -0
- package/template/packages/database/src/schema.test.ts +19 -0
- package/template/packages/jobs/package.json +1 -1
- package/template/packages/modules/index.ts +1 -0
- package/template/packages/modules/package.json +1 -1
- package/template/packages/modules/src/ai-operation-composition.test.ts +37 -0
- package/template/packages/modules/src/ai-operation-composition.ts +2 -0
- package/template/packages/modules/src/ai-operation-readiness-contract.test.ts +38 -0
- package/template/packages/modules/src/ai-operation-readiness-contract.ts +34 -0
- package/template/packages/modules/src/capability-audit-validation.ts +20 -0
- package/template/packages/modules/src/capability-guard-validation.ts +41 -0
- package/template/packages/modules/src/composition.ts +11 -0
- package/template/packages/modules/src/manifest.ts +40 -0
- package/template/packages/modules/src/secret-composition.test.ts +308 -0
- package/template/packages/modules/src/secret-composition.ts +176 -0
- package/template/packages/modules/src/system-api-control-plane.ts +17 -1
- package/template/packages/modules/src/system-module-catalog.test.ts +52 -0
- package/template/packages/modules/src/system-module-catalog.ts +1 -1
- package/template/packages/server-sdk/contracts/ai-runtime-readiness/v1/document-python-parity.json +12 -0
- package/template/packages/server-sdk/contracts/ai-runtime-readiness/v1/document.json +70 -0
- package/template/packages/server-sdk/contracts/ai-runtime-readiness/v1/embedding.json +68 -0
- package/template/packages/server-sdk/contracts/ai-runtime-readiness/v1/speech.json +80 -0
- package/template/packages/server-sdk/contracts/ai-runtime-readiness/v1/vlm.json +70 -0
- package/template/packages/server-sdk/contracts/document-runtime/v1/fingerprint-fixture.json +101 -0
- package/template/packages/server-sdk/index.ts +109 -0
- package/template/packages/server-sdk/package.json +22 -3
- package/template/packages/server-sdk/src/ai-runtime-readiness-capture.ts +168 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-digest.ts +49 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-identity.ts +16 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-keys.ts +23 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-limits.ts +141 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-projection.ts +326 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-requirement.ts +31 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-time.ts +16 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-trust.ts +84 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-validation-values.ts +147 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-validation.ts +299 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-values.ts +42 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.adversarial-input.contract.test.ts +146 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.contract-support.ts +139 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.contract.test.ts +314 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.digest-safety.contract.test.ts +131 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.fail-closed.contract.test.ts +215 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.identity.contract.test.ts +138 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.input-safety.contract.test.ts +314 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.public-api.test.ts +18 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.python-parity.contract.test.ts +160 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.trust.contract.test.ts +135 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.ts +198 -0
- package/template/packages/server-sdk/src/ai-screenshot-intake-port.ts +58 -0
- package/template/packages/server-sdk/src/data-governance-registration.ts +1 -3
- package/template/packages/server-sdk/src/durable-handler.ts +12 -0
- package/template/packages/server-sdk/src/module-adapter.test.ts +10 -0
- package/template/packages/server-sdk/src/module-adapter.ts +3 -0
- package/template/packages/server-sdk/src/module-host.ts +8 -0
- package/template/packages/server-sdk/src/report-staging-context-compatibility.test.ts +25 -0
- package/template/packages/server-sdk/src/report-staging-port.ts +190 -0
- package/template/packages/server-sdk/src/request-context.ts +27 -1
- package/template/packages/server-sdk/src/route-definition.ts +6 -0
- package/template/packages/server-sdk/src/secret-binding.test.ts +66 -0
- package/template/packages/server-sdk/src/secret-binding.ts +54 -0
- package/template/packages/server-sdk/src/secret-context-compatibility.test.ts +77 -0
- package/template/packages/server-sdk/src/secret-port.ts +80 -0
- package/template/packages/server-sdk/src/storage-port.ts +129 -9
- package/template/packages/server-sdk/src/storage-v052-source-compatibility.test.ts +61 -0
- package/template/packages/shared/index.ts +2 -0
- package/template/packages/shared/package.json +4 -1
- package/template/packages/shared/src/ai-operation-readiness.test.ts +75 -0
- package/template/packages/shared/src/ai-operation-readiness.ts +170 -0
- package/template/packages/shared/src/license-catalog.ts +14 -9
- package/template/packages/shared/src/stable-key.ts +26 -0
- package/template/packages/shared/tsconfig.json +16 -0
- package/template/packages/storage/index.ts +2 -0
- package/template/packages/storage/package.json +1 -1
- package/template/packages/storage/src/in-memory-upload-repository.ts +105 -2
- package/template/packages/storage/src/local-file-blob-store.test.ts +58 -0
- package/template/packages/storage/src/local-file-blob-store.ts +5 -71
- package/template/packages/storage/src/local-file-blob-writer.ts +96 -0
- package/template/packages/storage/src/upload-abort-recovery.test.ts +234 -0
- package/template/packages/storage/src/upload-abort.ts +130 -0
- package/template/packages/storage/src/upload-cleanup-race.test.ts +207 -0
- package/template/packages/storage/src/upload-cleanup.ts +85 -0
- package/template/packages/storage/src/upload-completion.ts +52 -0
- package/template/packages/storage/src/upload-purge.test.ts +163 -0
- package/template/packages/storage/src/upload-purge.ts +261 -0
- package/template/packages/storage/src/upload-repository-v052-compatibility.test.ts +31 -0
- package/template/packages/storage/src/upload-repository.ts +61 -0
- package/template/packages/storage/src/upload-service-recovery.test.ts +296 -0
- package/template/packages/storage/src/upload-service.ts +138 -150
- package/template/packages/storage/src/upload-streams.ts +126 -30
- package/template/packages/storage/src/upload-types.ts +13 -0
- package/template/packages/storage/src/upload-validation.ts +127 -0
- package/template/scripts/provision-speech-readiness.ts +147 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ModuleManifest } from "@southwind-ai/modules";
|
|
2
|
+
import { featureKey } from "@southwind-ai/shared";
|
|
3
|
+
import { speechOutputArtifactCapabilityV1 } from "./output-artifact-policy.js";
|
|
4
|
+
|
|
5
|
+
export function speechOutputManifest(operationKey: string): ModuleManifest {
|
|
6
|
+
return {
|
|
7
|
+
name: "evidence",
|
|
8
|
+
version: "0.1.0",
|
|
9
|
+
label: "物证",
|
|
10
|
+
description: "物证",
|
|
11
|
+
menus: [],
|
|
12
|
+
adminRoutes: [],
|
|
13
|
+
permissions: [
|
|
14
|
+
{
|
|
15
|
+
key: `${operationKey}.execute`,
|
|
16
|
+
label: "音频归一化",
|
|
17
|
+
module: "evidence",
|
|
18
|
+
moduleLabel: "物证",
|
|
19
|
+
resource: "audio",
|
|
20
|
+
resourceLabel: "音频",
|
|
21
|
+
action: "manage",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
apiPermissions: [],
|
|
25
|
+
features: [
|
|
26
|
+
{
|
|
27
|
+
key: featureKey(operationKey),
|
|
28
|
+
label: "音频归一化",
|
|
29
|
+
module: "evidence",
|
|
30
|
+
visible: "visible",
|
|
31
|
+
enabled: true,
|
|
32
|
+
stage: "stable",
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
migrations: [],
|
|
36
|
+
schemaExports: [],
|
|
37
|
+
jsonSchemas: [
|
|
38
|
+
{ key: `${operationKey}.input.v1`, schema: { type: "object" } },
|
|
39
|
+
{ key: `${operationKey}.output.v1`, schema: { type: "object" } },
|
|
40
|
+
],
|
|
41
|
+
tasks: [],
|
|
42
|
+
tools: [],
|
|
43
|
+
aiOperations: [
|
|
44
|
+
{
|
|
45
|
+
key: operationKey,
|
|
46
|
+
kind: "speech",
|
|
47
|
+
featureKey: operationKey,
|
|
48
|
+
permissionKey: `${operationKey}.execute`,
|
|
49
|
+
auditAction: `${operationKey}.execute`,
|
|
50
|
+
inputSchemaKey: `${operationKey}.input.v1`,
|
|
51
|
+
outputSchemaKey: `${operationKey}.output.v1`,
|
|
52
|
+
inputModalities: ["audio"],
|
|
53
|
+
requiredCapabilities: [
|
|
54
|
+
"speech.normalize",
|
|
55
|
+
speechOutputArtifactCapabilityV1,
|
|
56
|
+
],
|
|
57
|
+
allowedToolKeys: [],
|
|
58
|
+
dataClassification: "sensitive",
|
|
59
|
+
execution: "background",
|
|
60
|
+
providerEgress: { mode: "forbidden" },
|
|
61
|
+
limits: {
|
|
62
|
+
maxDurationSeconds: 60,
|
|
63
|
+
maxInputBytes: 4_096,
|
|
64
|
+
maxOutputBytes: 4_096,
|
|
65
|
+
maxUnits: 1,
|
|
66
|
+
maxMediaDurationSeconds: 60,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
providers: [],
|
|
71
|
+
auditActions: [`${operationKey}.execute`],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import type { ModuleAiOperationReadinessV1 } from "@southwind-ai/server-sdk";
|
|
3
|
+
import { buildScopeContext } from "../data-access/context.js";
|
|
4
|
+
import type { RequestActor, RequestGuardContext } from "../guards.js";
|
|
5
|
+
import { createServerRuntime } from "../runtime.js";
|
|
6
|
+
import { createStorageRuntime } from "../storage/runtime.js";
|
|
7
|
+
import { createDocumentOutputArtifactRuntime } from "../document/output-artifact-runtime.js";
|
|
8
|
+
import {
|
|
9
|
+
outputByteStream,
|
|
10
|
+
outputHash,
|
|
11
|
+
} from "../ai-output-artifact/test-support.js";
|
|
12
|
+
import type { SpeechRuntimeOperation } from "./contracts.js";
|
|
13
|
+
import {
|
|
14
|
+
SpeechOutputArtifactHostError,
|
|
15
|
+
speechOutputArtifactCapabilityV1,
|
|
16
|
+
} from "./output-artifact-host.js";
|
|
17
|
+
import { speechOutputManifest } from "./output-artifact-host.test-support.js";
|
|
18
|
+
|
|
19
|
+
const operationKey = "evidence.audio.normalize";
|
|
20
|
+
const now = () => new Date("2026-08-06T12:00:00.000Z");
|
|
21
|
+
|
|
22
|
+
describe("Speech Output Artifact Host", () => {
|
|
23
|
+
test("create 前固定 operation-bound scope、grant、TTL,sealed 后由 Host claim", async () => {
|
|
24
|
+
const fixture = createFixture();
|
|
25
|
+
const invocation = speechInvocation();
|
|
26
|
+
const begun = await fixture.host.begin({
|
|
27
|
+
definition: fixture.operation,
|
|
28
|
+
moduleName: "evidence",
|
|
29
|
+
runId: invocation.runId!,
|
|
30
|
+
idempotencyKey: "a".repeat(64),
|
|
31
|
+
context: fixture.context(),
|
|
32
|
+
invocation,
|
|
33
|
+
});
|
|
34
|
+
expect(begun?.grant).toMatch(/^outgrant_v1_/);
|
|
35
|
+
expect(begun?.descriptor).toMatchObject({
|
|
36
|
+
outputKind: "normalized-audio",
|
|
37
|
+
allowedMediaTypes: ["audio/wav"],
|
|
38
|
+
grantGeneration: 1,
|
|
39
|
+
expiresAt: "2026-08-06T12:02:00.000Z",
|
|
40
|
+
});
|
|
41
|
+
const pending = await fixture.output.service.options.repository.getScope(
|
|
42
|
+
begun!.scopeId,
|
|
43
|
+
);
|
|
44
|
+
expect(pending).toMatchObject({
|
|
45
|
+
runId: invocation.runId,
|
|
46
|
+
moduleName: "evidence",
|
|
47
|
+
operationKey,
|
|
48
|
+
runtimeKind: "speech",
|
|
49
|
+
purpose: "ai-runtime-output",
|
|
50
|
+
status: "open",
|
|
51
|
+
pendingGrantGeneration: 1,
|
|
52
|
+
});
|
|
53
|
+
expect(pending).not.toHaveProperty("grantHash");
|
|
54
|
+
|
|
55
|
+
await fixture.output.service.acceptGrant(
|
|
56
|
+
begun!.scopeId,
|
|
57
|
+
begun!.grantGeneration,
|
|
58
|
+
begun!.grant!,
|
|
59
|
+
);
|
|
60
|
+
const activeReplay = await fixture.host.begin({
|
|
61
|
+
definition: fixture.operation,
|
|
62
|
+
moduleName: "evidence",
|
|
63
|
+
runId: invocation.runId!,
|
|
64
|
+
idempotencyKey: "a".repeat(64),
|
|
65
|
+
context: fixture.context(),
|
|
66
|
+
invocation,
|
|
67
|
+
});
|
|
68
|
+
expect(activeReplay).toMatchObject({
|
|
69
|
+
scopeId: begun!.scopeId,
|
|
70
|
+
grantGeneration: 1,
|
|
71
|
+
});
|
|
72
|
+
expect(activeReplay?.grant).toBeUndefined();
|
|
73
|
+
const wav = wavBytes();
|
|
74
|
+
const artifact = await fixture.output.service.beginArtifact(
|
|
75
|
+
begun!.scopeId,
|
|
76
|
+
begun!.grant!,
|
|
77
|
+
{
|
|
78
|
+
contractVersion: 1,
|
|
79
|
+
outputKey: "normalized-audio",
|
|
80
|
+
filename: "normalized.wav",
|
|
81
|
+
mediaType: "audio/wav",
|
|
82
|
+
byteSize: wav.byteLength,
|
|
83
|
+
sha256: outputHash(wav),
|
|
84
|
+
outputKind: "normalized-audio",
|
|
85
|
+
},
|
|
86
|
+
new AbortController().signal,
|
|
87
|
+
);
|
|
88
|
+
await fixture.output.service.appendPart(
|
|
89
|
+
begun!.scopeId,
|
|
90
|
+
begun!.grant!,
|
|
91
|
+
{
|
|
92
|
+
artifactId: artifact.artifactId,
|
|
93
|
+
partNumber: 0,
|
|
94
|
+
byteOffset: 0,
|
|
95
|
+
byteSize: wav.byteLength,
|
|
96
|
+
sha256: outputHash(wav),
|
|
97
|
+
body: outputByteStream(wav),
|
|
98
|
+
},
|
|
99
|
+
new AbortController().signal,
|
|
100
|
+
);
|
|
101
|
+
await fixture.output.service.completeArtifact(
|
|
102
|
+
begun!.scopeId,
|
|
103
|
+
begun!.grant!,
|
|
104
|
+
artifact.artifactId,
|
|
105
|
+
new AbortController().signal,
|
|
106
|
+
);
|
|
107
|
+
await fixture.output.service.sealScope(begun!.scopeId, begun!.grant!);
|
|
108
|
+
|
|
109
|
+
const sealedReplay = await fixture.host.begin({
|
|
110
|
+
definition: fixture.operation,
|
|
111
|
+
moduleName: "evidence",
|
|
112
|
+
runId: invocation.runId!,
|
|
113
|
+
idempotencyKey: "a".repeat(64),
|
|
114
|
+
context: fixture.context(),
|
|
115
|
+
invocation,
|
|
116
|
+
});
|
|
117
|
+
expect(sealedReplay).toMatchObject({
|
|
118
|
+
scopeId: begun!.scopeId,
|
|
119
|
+
grantGeneration: 1,
|
|
120
|
+
});
|
|
121
|
+
expect(sealedReplay?.grant).toBeUndefined();
|
|
122
|
+
expect(sealedReplay?.references).toHaveLength(1);
|
|
123
|
+
|
|
124
|
+
const claimed = await fixture.host.claimSealed(
|
|
125
|
+
invocation.runId!,
|
|
126
|
+
fixture.context(),
|
|
127
|
+
);
|
|
128
|
+
expect(claimed).toHaveLength(1);
|
|
129
|
+
expect(claimed[0]).toMatchObject({
|
|
130
|
+
outputKey: "normalized-audio",
|
|
131
|
+
mediaType: "audio/wav",
|
|
132
|
+
byteSize: wav.byteLength,
|
|
133
|
+
sha256: outputHash(wav),
|
|
134
|
+
});
|
|
135
|
+
expect(claimed[0]?.value).toMatch(/^oa1\./);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("只允许 sealed claim,并复核 Actor、scope 与当前 Permission", async () => {
|
|
139
|
+
const fixture = createFixture();
|
|
140
|
+
const invocation = speechInvocation();
|
|
141
|
+
const begun = await fixture.host.begin({
|
|
142
|
+
definition: fixture.operation,
|
|
143
|
+
moduleName: "evidence",
|
|
144
|
+
runId: invocation.runId!,
|
|
145
|
+
idempotencyKey: "b".repeat(64),
|
|
146
|
+
context: fixture.context(),
|
|
147
|
+
invocation,
|
|
148
|
+
});
|
|
149
|
+
await expect(
|
|
150
|
+
fixture.host.claimSealed(invocation.runId!, fixture.context()),
|
|
151
|
+
).rejects.toBeInstanceOf(SpeechOutputArtifactHostError);
|
|
152
|
+
|
|
153
|
+
fixture.setActor(actor([]));
|
|
154
|
+
await expect(
|
|
155
|
+
fixture.host.claimSealed(invocation.runId!, fixture.context()),
|
|
156
|
+
).rejects.toMatchObject({ code: "FORBIDDEN" });
|
|
157
|
+
expect(await fixture.host.abortOpenRun(invocation.runId!)).toBe(true);
|
|
158
|
+
expect(
|
|
159
|
+
await fixture.output.service.options.repository.getScope(begun!.scopeId),
|
|
160
|
+
).toMatchObject({ status: "aborted" });
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
function createFixture() {
|
|
165
|
+
const module = speechOutputManifest(operationKey);
|
|
166
|
+
let currentActor = actor();
|
|
167
|
+
const runtime = createServerRuntime(
|
|
168
|
+
{},
|
|
169
|
+
{
|
|
170
|
+
featureCatalog: module.features,
|
|
171
|
+
featureResolver: {
|
|
172
|
+
resolve: (key) => ({
|
|
173
|
+
key,
|
|
174
|
+
enabled: true,
|
|
175
|
+
visible: "visible",
|
|
176
|
+
}),
|
|
177
|
+
},
|
|
178
|
+
licenseResolver: {
|
|
179
|
+
resolve: () => ({ status: "valid", restricted: false }),
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
);
|
|
183
|
+
const output = createDocumentOutputArtifactRuntime({
|
|
184
|
+
modules: [module],
|
|
185
|
+
bindings: [],
|
|
186
|
+
speechBindings: [{ operationKey, outputKind: "normalized-audio" }],
|
|
187
|
+
readiness: { inspect: async () => readiness() },
|
|
188
|
+
runtime,
|
|
189
|
+
storage: createStorageRuntime({}, undefined, undefined, now),
|
|
190
|
+
resolveActor: async () => currentActor,
|
|
191
|
+
referenceSecret: "speech-output-test-secret".repeat(2),
|
|
192
|
+
ephemeral: true,
|
|
193
|
+
now,
|
|
194
|
+
});
|
|
195
|
+
return {
|
|
196
|
+
output,
|
|
197
|
+
host: output.speechHost!,
|
|
198
|
+
operation: module.aiOperations![0]!,
|
|
199
|
+
context: () => context(currentActor),
|
|
200
|
+
setActor(value: RequestActor) {
|
|
201
|
+
currentActor = value;
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function speechInvocation(): SpeechRuntimeOperation {
|
|
207
|
+
return {
|
|
208
|
+
kind: "speech",
|
|
209
|
+
runId: `speech_${"c".repeat(64)}`,
|
|
210
|
+
contractVersion: 2,
|
|
211
|
+
variant: "normalize",
|
|
212
|
+
operationKey,
|
|
213
|
+
options: {},
|
|
214
|
+
source: {
|
|
215
|
+
value: "rotated-ref",
|
|
216
|
+
mediaType: "audio/wav",
|
|
217
|
+
byteSize: 128,
|
|
218
|
+
sha256: "d".repeat(64),
|
|
219
|
+
},
|
|
220
|
+
requiredCapabilities: [
|
|
221
|
+
"speech.normalize",
|
|
222
|
+
speechOutputArtifactCapabilityV1,
|
|
223
|
+
],
|
|
224
|
+
dataClassification: "sensitive",
|
|
225
|
+
limits: {
|
|
226
|
+
maxDurationSeconds: 60,
|
|
227
|
+
maxInputBytes: 4_096,
|
|
228
|
+
maxOutputBytes: 4_096,
|
|
229
|
+
maxUnits: 1,
|
|
230
|
+
maxMediaDurationSeconds: 60,
|
|
231
|
+
},
|
|
232
|
+
providerEgress: { mode: "forbidden" },
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function readiness(): ModuleAiOperationReadinessV1 {
|
|
237
|
+
return {
|
|
238
|
+
schemaVersion: 1,
|
|
239
|
+
operationKey,
|
|
240
|
+
runtimeKind: "speech",
|
|
241
|
+
observedAt: now().toISOString(),
|
|
242
|
+
status: "ready",
|
|
243
|
+
validUntil: "2026-08-06T12:05:00.000Z",
|
|
244
|
+
deployment: {
|
|
245
|
+
key: "speech.normalize",
|
|
246
|
+
identity: "windy-deployment-v1_7db61d8e-e50d-4f8a-9f3f-9b7a1d932e01",
|
|
247
|
+
releaseDigest: `sha256:${"a".repeat(64)}`,
|
|
248
|
+
offersDigest: `sha256:${"b".repeat(64)}`,
|
|
249
|
+
},
|
|
250
|
+
offers: [
|
|
251
|
+
{
|
|
252
|
+
variant: "normalize",
|
|
253
|
+
capabilities: ["speech.normalize", speechOutputArtifactCapabilityV1],
|
|
254
|
+
inputModalities: ["audio"],
|
|
255
|
+
outputModalities: ["audio"],
|
|
256
|
+
limits: {
|
|
257
|
+
maxDurationSeconds: 60,
|
|
258
|
+
maxInputBytes: 4_096,
|
|
259
|
+
maxOutputBytes: 2_048,
|
|
260
|
+
maxUnits: 1,
|
|
261
|
+
maxMediaDurationSeconds: 60,
|
|
262
|
+
maxArtifacts: 1,
|
|
263
|
+
maxConcurrentRuns: 1,
|
|
264
|
+
maxQueueDepth: 0,
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
unavailableReasons: [],
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function actor(permissionKeys = [`${operationKey}.execute`]): RequestActor {
|
|
273
|
+
return {
|
|
274
|
+
id: "actor-1",
|
|
275
|
+
type: "user",
|
|
276
|
+
name: "分析员",
|
|
277
|
+
roleCodes: ["analyst"],
|
|
278
|
+
permissionKeys,
|
|
279
|
+
scopeContext: buildScopeContext("actor-1", undefined, [
|
|
280
|
+
{
|
|
281
|
+
id: "analyst",
|
|
282
|
+
code: "analyst",
|
|
283
|
+
dataScope: "self",
|
|
284
|
+
departmentIds: [],
|
|
285
|
+
},
|
|
286
|
+
]),
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function context(value: RequestActor): RequestGuardContext {
|
|
291
|
+
return {
|
|
292
|
+
requestId: "speech-output-request",
|
|
293
|
+
actor: value,
|
|
294
|
+
startedAt: now().toISOString(),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function wavBytes() {
|
|
299
|
+
return new TextEncoder().encode(
|
|
300
|
+
"RIFF\u0024\u0000\u0000\u0000WAVEfmt \u0010\u0000\u0000\u0000",
|
|
301
|
+
);
|
|
302
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ModuleAiOperationDefinition,
|
|
3
|
+
ModuleManifest,
|
|
4
|
+
} from "@southwind-ai/modules";
|
|
5
|
+
import type { ModuleAiOperationReadinessPortV1 } from "@southwind-ai/server-sdk";
|
|
6
|
+
import { evaluateAccessGuards } from "../access-guards.js";
|
|
7
|
+
import type { AiOutputArtifactCleanupService } from "../ai-output-artifact/cleanup.js";
|
|
8
|
+
import type {
|
|
9
|
+
AiOutputArtifactReferenceV1,
|
|
10
|
+
AiOutputArtifactScope,
|
|
11
|
+
} from "../ai-output-artifact/contracts.js";
|
|
12
|
+
import { AiOutputArtifactPolicyRegistry } from "../ai-output-artifact/policy.js";
|
|
13
|
+
import type { AiOutputArtifactService } from "../ai-output-artifact/service.js";
|
|
14
|
+
import { captureAuthorizationScope } from "../data-access/scope-snapshot.js";
|
|
15
|
+
import { isServerScopeContext } from "../data-access/context.js";
|
|
16
|
+
import type { RequestActor, RequestGuardContext } from "../guards.js";
|
|
17
|
+
import type { createServerRuntime } from "../runtime.js";
|
|
18
|
+
import type { SpeechRuntimeOperation } from "./contracts.js";
|
|
19
|
+
import {
|
|
20
|
+
speechOutputArtifactBindings,
|
|
21
|
+
type SpeechOutputArtifactBinding,
|
|
22
|
+
} from "./output-artifact-binding.js";
|
|
23
|
+
import {
|
|
24
|
+
requireSpeechOutputReady,
|
|
25
|
+
speechOutputInvocationDigest,
|
|
26
|
+
speechOutputPolicyLimits,
|
|
27
|
+
validSpeechOutputScopeLimits,
|
|
28
|
+
} from "./output-artifact-policy.js";
|
|
29
|
+
import { SpeechOutputArtifactHostError } from "./output-artifact-error.js";
|
|
30
|
+
import { replaySpeechOutputScope } from "./output-artifact-replay.js";
|
|
31
|
+
|
|
32
|
+
export { SpeechOutputArtifactHostError } from "./output-artifact-error.js";
|
|
33
|
+
|
|
34
|
+
export { speechOutputArtifactCapabilityV1 } from "./output-artifact-policy.js";
|
|
35
|
+
|
|
36
|
+
export interface SpeechOutputArtifactStart {
|
|
37
|
+
readonly runId: string;
|
|
38
|
+
readonly scopeId: string;
|
|
39
|
+
readonly grantGeneration: number;
|
|
40
|
+
readonly descriptor: NonNullable<
|
|
41
|
+
SpeechRuntimeOperation["outputArtifactSink"]
|
|
42
|
+
>;
|
|
43
|
+
readonly grant?: string;
|
|
44
|
+
readonly references?: readonly AiOutputArtifactReferenceV1[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type ServerRuntime = ReturnType<typeof createServerRuntime>;
|
|
48
|
+
|
|
49
|
+
export class SpeechOutputArtifactHost {
|
|
50
|
+
readonly #bindings: Map<string, SpeechOutputArtifactBinding>;
|
|
51
|
+
readonly #operations;
|
|
52
|
+
readonly #policies = new AiOutputArtifactPolicyRegistry();
|
|
53
|
+
|
|
54
|
+
constructor(
|
|
55
|
+
modules: readonly ModuleManifest[],
|
|
56
|
+
bindings: readonly SpeechOutputArtifactBinding[],
|
|
57
|
+
private readonly readiness: ModuleAiOperationReadinessPortV1,
|
|
58
|
+
private readonly service: AiOutputArtifactService,
|
|
59
|
+
private readonly cleanup: AiOutputArtifactCleanupService,
|
|
60
|
+
private readonly runtime: ServerRuntime,
|
|
61
|
+
private readonly resolveActor: (
|
|
62
|
+
actorId: string,
|
|
63
|
+
) => Promise<RequestActor | undefined>,
|
|
64
|
+
private readonly now: () => Date = () => new Date(),
|
|
65
|
+
) {
|
|
66
|
+
this.#bindings = new Map(
|
|
67
|
+
[...speechOutputArtifactBindings(modules, bindings)].map(
|
|
68
|
+
([key, value]) => [
|
|
69
|
+
key,
|
|
70
|
+
{
|
|
71
|
+
operationKey: value.operationKey,
|
|
72
|
+
outputKind: "normalized-audio" as const,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
this.#operations = new Map(
|
|
78
|
+
modules.flatMap((module) =>
|
|
79
|
+
(module.aiOperations ?? [])
|
|
80
|
+
.filter(({ kind }) => kind === "speech")
|
|
81
|
+
.map(
|
|
82
|
+
(definition) => [definition.key, { module, definition }] as const,
|
|
83
|
+
),
|
|
84
|
+
),
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
hasBinding(operationKey: string) {
|
|
89
|
+
return this.#bindings.has(operationKey);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async begin(input: {
|
|
93
|
+
definition: ModuleAiOperationDefinition;
|
|
94
|
+
moduleName: string;
|
|
95
|
+
runId: string;
|
|
96
|
+
idempotencyKey: string;
|
|
97
|
+
context: RequestGuardContext;
|
|
98
|
+
invocation: SpeechRuntimeOperation;
|
|
99
|
+
}): Promise<SpeechOutputArtifactStart | undefined> {
|
|
100
|
+
const binding = this.#bindings.get(input.definition.key);
|
|
101
|
+
if (!binding) return undefined;
|
|
102
|
+
if (
|
|
103
|
+
input.invocation.runId !== input.runId ||
|
|
104
|
+
input.invocation.variant !== "normalize" ||
|
|
105
|
+
input.invocation.operationKey !== input.definition.key
|
|
106
|
+
) {
|
|
107
|
+
throw conflict("Speech Output Artifact 调用语义不匹配");
|
|
108
|
+
}
|
|
109
|
+
const ready = requireSpeechOutputReady(
|
|
110
|
+
await this.readiness.inspect({ operationKey: input.definition.key }),
|
|
111
|
+
input.definition.key,
|
|
112
|
+
this.now(),
|
|
113
|
+
);
|
|
114
|
+
const limits = speechOutputPolicyLimits(input.definition, ready);
|
|
115
|
+
const policy = this.#policies.resolve({
|
|
116
|
+
runtimeKind: "speech",
|
|
117
|
+
outputKind: binding.outputKind,
|
|
118
|
+
dataClassification: input.definition.dataClassification,
|
|
119
|
+
operationLimits: limits.operation,
|
|
120
|
+
readinessLimits: limits.readiness,
|
|
121
|
+
runtimeLimits: limits.runtime,
|
|
122
|
+
});
|
|
123
|
+
const invocationDigest = speechOutputInvocationDigest(
|
|
124
|
+
input.invocation,
|
|
125
|
+
ready,
|
|
126
|
+
policy.digest,
|
|
127
|
+
);
|
|
128
|
+
try {
|
|
129
|
+
const replayed = await replaySpeechOutputScope({
|
|
130
|
+
service: this.service,
|
|
131
|
+
runId: input.runId,
|
|
132
|
+
moduleName: input.moduleName,
|
|
133
|
+
operationKey: input.definition.key,
|
|
134
|
+
idempotencyKey: input.idempotencyKey,
|
|
135
|
+
invocationDigest,
|
|
136
|
+
deployment: ready.deployment,
|
|
137
|
+
policy,
|
|
138
|
+
context: input.context,
|
|
139
|
+
now: this.now(),
|
|
140
|
+
});
|
|
141
|
+
if (replayed) return replayed;
|
|
142
|
+
const begun = await this.service.beginScope({
|
|
143
|
+
runId: input.runId,
|
|
144
|
+
moduleName: input.moduleName,
|
|
145
|
+
operationKey: input.definition.key,
|
|
146
|
+
runtimeKind: "speech",
|
|
147
|
+
idempotencyKey: input.idempotencyKey,
|
|
148
|
+
invocationDigest,
|
|
149
|
+
dataClassification: input.definition.dataClassification,
|
|
150
|
+
deploymentIdentity: ready.deployment.identity,
|
|
151
|
+
releaseDigest: ready.deployment.releaseDigest,
|
|
152
|
+
offersDigest: ready.deployment.offersDigest,
|
|
153
|
+
policy,
|
|
154
|
+
context: input.context,
|
|
155
|
+
});
|
|
156
|
+
if (!begun.descriptor) throw new Error("missing descriptor");
|
|
157
|
+
return {
|
|
158
|
+
runId: begun.scope.runId,
|
|
159
|
+
scopeId: begun.scope.scopeId,
|
|
160
|
+
grantGeneration: begun.descriptor.grantGeneration,
|
|
161
|
+
descriptor: begun.descriptor,
|
|
162
|
+
grant: begun.grant,
|
|
163
|
+
references: begun.references,
|
|
164
|
+
};
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (hasCode(error, "OUTPUT_ARTIFACT_CONFLICT")) {
|
|
167
|
+
throw conflict("Speech Output Artifact 幂等语义冲突");
|
|
168
|
+
}
|
|
169
|
+
throw unavailable();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
confirmGrant(scopeId: string, generation: number, grant: string) {
|
|
174
|
+
return this.service.confirmGrant(scopeId, generation, grant);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
rollbackPendingGrant(scopeId: string, generation: number, grant: string) {
|
|
178
|
+
return this.service.rollbackPendingGrant(scopeId, generation, grant);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
abortOpenRun(runId: string) {
|
|
182
|
+
return this.cleanup.abortOpenRun(runId);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async claimSealed(
|
|
186
|
+
runId: string,
|
|
187
|
+
context: RequestGuardContext,
|
|
188
|
+
): Promise<readonly AiOutputArtifactReferenceV1[]> {
|
|
189
|
+
const scopes = (
|
|
190
|
+
await this.service.options.repository.listScopesByRun(runId)
|
|
191
|
+
).filter(({ runtimeKind }) => runtimeKind === "speech");
|
|
192
|
+
if (scopes.length !== 1) throw unavailable();
|
|
193
|
+
const scope = scopes[0]!;
|
|
194
|
+
if (!(await this.#authorizeClaim(scope, runId, context))) {
|
|
195
|
+
throw new SpeechOutputArtifactHostError(
|
|
196
|
+
"FORBIDDEN",
|
|
197
|
+
"Speech Output Artifact 当前不可访问",
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
return await this.service.claimSealedScope(scope.scopeId);
|
|
202
|
+
} catch {
|
|
203
|
+
throw unavailable();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async authorizeRead(scope: AiOutputArtifactScope, signal: AbortSignal) {
|
|
208
|
+
try {
|
|
209
|
+
const actor = await this.resolveActor(scope.actorId);
|
|
210
|
+
if (!actor) return undefined;
|
|
211
|
+
const context = await this.runtime.createGuardContextForActor(
|
|
212
|
+
new Request("http://ai-output.internal/read", { signal }),
|
|
213
|
+
actor,
|
|
214
|
+
);
|
|
215
|
+
return (await this.#authorizeClaim(scope, scope.runId, context))
|
|
216
|
+
? {
|
|
217
|
+
actorId: actor.id,
|
|
218
|
+
scopeHash: captureAuthorizationScope(actor.scopeContext!).hash,
|
|
219
|
+
requestId: context.requestId,
|
|
220
|
+
}
|
|
221
|
+
: { requestId: context.requestId };
|
|
222
|
+
} catch {
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async #authorizeClaim(
|
|
228
|
+
scope: AiOutputArtifactScope,
|
|
229
|
+
runId: string,
|
|
230
|
+
context: RequestGuardContext,
|
|
231
|
+
) {
|
|
232
|
+
const binding = this.#bindings.get(scope.operationKey);
|
|
233
|
+
const operation = this.#operations.get(scope.operationKey);
|
|
234
|
+
if (
|
|
235
|
+
!binding ||
|
|
236
|
+
!operation ||
|
|
237
|
+
operation.module.name !== scope.moduleName ||
|
|
238
|
+
binding.outputKind !== scope.outputKind ||
|
|
239
|
+
scope.runtimeKind !== "speech" ||
|
|
240
|
+
scope.runId !== runId ||
|
|
241
|
+
scope.purpose !== "ai-runtime-output" ||
|
|
242
|
+
scope.actorId !== context.actor.id ||
|
|
243
|
+
operation.definition.dataClassification !== scope.dataClassification ||
|
|
244
|
+
!validSpeechOutputScopeLimits(scope, operation.definition)
|
|
245
|
+
) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
const actorScope = context.actor.scopeContext;
|
|
249
|
+
if (
|
|
250
|
+
!isServerScopeContext(actorScope) ||
|
|
251
|
+
actorScope.tenantId !== scope.tenantId ||
|
|
252
|
+
captureAuthorizationScope(actorScope).hash !== scope.scopeHash
|
|
253
|
+
) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
const access = await evaluateAccessGuards(this.runtime, context, {
|
|
257
|
+
permission: { permissionKey: operation.definition.permissionKey },
|
|
258
|
+
feature: operation.module.features.find(
|
|
259
|
+
({ key }) => key === operation.definition.featureKey,
|
|
260
|
+
),
|
|
261
|
+
});
|
|
262
|
+
return access.decision.allowed;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function hasCode(error: unknown, code: string) {
|
|
267
|
+
return error instanceof Error && "code" in error && error.code === code;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function conflict(message: string) {
|
|
271
|
+
return new SpeechOutputArtifactHostError("RUN_CONFLICT", message);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function unavailable() {
|
|
275
|
+
return new SpeechOutputArtifactHostError(
|
|
276
|
+
"CAPABILITY_UNAVAILABLE",
|
|
277
|
+
"Speech Output Artifact 暂时不可用",
|
|
278
|
+
);
|
|
279
|
+
}
|