create-windy 0.5.1 → 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 +486 -156
- 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 +23 -3
- 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,350 @@
|
|
|
1
|
+
import {
|
|
2
|
+
aiOutputArtifacts,
|
|
3
|
+
aiOutputArtifactScopes,
|
|
4
|
+
} from "@southwind-ai/database";
|
|
5
|
+
import { and, asc, eq, inArray, sql } from "drizzle-orm";
|
|
6
|
+
import type { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
7
|
+
import type {
|
|
8
|
+
AiOutputArtifactRecord,
|
|
9
|
+
AiOutputArtifactScope,
|
|
10
|
+
} from "./contracts.js";
|
|
11
|
+
import type {
|
|
12
|
+
AiOutputArtifactRepository,
|
|
13
|
+
NewAiOutputArtifact,
|
|
14
|
+
NewAiOutputScope,
|
|
15
|
+
} from "./repository.js";
|
|
16
|
+
import { AiOutputArtifactRepositoryError as RepositoryError } from "./repository.js";
|
|
17
|
+
import {
|
|
18
|
+
aiOutputArtifactValues,
|
|
19
|
+
aiOutputScopeValues,
|
|
20
|
+
mapAiOutputArtifact,
|
|
21
|
+
mapAiOutputScope,
|
|
22
|
+
} from "./drizzle-mapping.js";
|
|
23
|
+
import { completeDrizzleAiOutputArtifact } from "./drizzle-complete.js";
|
|
24
|
+
import { sealDrizzleAiOutputScope } from "./drizzle-seal.js";
|
|
25
|
+
import { listDrizzleAiOutputCleanupScopes } from "./drizzle-cleanup.js";
|
|
26
|
+
import { clearExpiredDrizzleOutputGrantHashes } from "./drizzle-grant-cleanup.js";
|
|
27
|
+
import {
|
|
28
|
+
prepareDrizzleOutputGrant,
|
|
29
|
+
promoteDrizzleOutputGrant,
|
|
30
|
+
rollbackDrizzleOutputGrant,
|
|
31
|
+
} from "./drizzle-grants.js";
|
|
32
|
+
import { deleteDrizzleOutputReadinessProbe } from "./drizzle-readiness.js";
|
|
33
|
+
|
|
34
|
+
export class DrizzleAiOutputArtifactRepository implements AiOutputArtifactRepository {
|
|
35
|
+
constructor(private readonly db: NodePgDatabase) {}
|
|
36
|
+
|
|
37
|
+
async createOrGetScope(input: NewAiOutputScope) {
|
|
38
|
+
const [created] = await this.db
|
|
39
|
+
.insert(aiOutputArtifactScopes)
|
|
40
|
+
.values(aiOutputScopeValues(input))
|
|
41
|
+
.onConflictDoNothing()
|
|
42
|
+
.returning();
|
|
43
|
+
if (created) return { scope: mapAiOutputScope(created), created: true };
|
|
44
|
+
const [existing] = await this.db
|
|
45
|
+
.select()
|
|
46
|
+
.from(aiOutputArtifactScopes)
|
|
47
|
+
.where(eq(aiOutputArtifactScopes.idempotencyHash, input.idempotencyHash))
|
|
48
|
+
.limit(1);
|
|
49
|
+
if (existing) {
|
|
50
|
+
return { scope: mapAiOutputScope(existing), created: false };
|
|
51
|
+
}
|
|
52
|
+
const [sameRunKind] = await this.db
|
|
53
|
+
.select()
|
|
54
|
+
.from(aiOutputArtifactScopes)
|
|
55
|
+
.where(
|
|
56
|
+
and(
|
|
57
|
+
eq(aiOutputArtifactScopes.runId, input.runId),
|
|
58
|
+
eq(aiOutputArtifactScopes.outputKind, input.outputKind),
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
.limit(1);
|
|
62
|
+
if (!sameRunKind) {
|
|
63
|
+
throw new Error("AI Output Scope 并发创建后无法读取");
|
|
64
|
+
}
|
|
65
|
+
return { scope: mapAiOutputScope(sameRunKind), created: false };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async getScope(scopeId: string) {
|
|
69
|
+
const [row] = await this.db
|
|
70
|
+
.select()
|
|
71
|
+
.from(aiOutputArtifactScopes)
|
|
72
|
+
.where(eq(aiOutputArtifactScopes.scopeId, scopeId))
|
|
73
|
+
.limit(1);
|
|
74
|
+
return row ? mapAiOutputScope(row) : undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async listScopesByRun(runId: string) {
|
|
78
|
+
return (
|
|
79
|
+
await this.db
|
|
80
|
+
.select()
|
|
81
|
+
.from(aiOutputArtifactScopes)
|
|
82
|
+
.where(eq(aiOutputArtifactScopes.runId, runId))
|
|
83
|
+
).map(mapAiOutputScope);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async prepareGrant(
|
|
87
|
+
scopeId: string,
|
|
88
|
+
expectedRevision: number,
|
|
89
|
+
pendingGrantHash: string,
|
|
90
|
+
pendingGrantExpiresAt: string,
|
|
91
|
+
updatedAt: string,
|
|
92
|
+
) {
|
|
93
|
+
return prepareDrizzleOutputGrant(
|
|
94
|
+
this.db,
|
|
95
|
+
scopeId,
|
|
96
|
+
expectedRevision,
|
|
97
|
+
pendingGrantHash,
|
|
98
|
+
pendingGrantExpiresAt,
|
|
99
|
+
updatedAt,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async promoteGrant(
|
|
104
|
+
scopeId: string,
|
|
105
|
+
expectedRevision: number,
|
|
106
|
+
pendingGrantGeneration: number,
|
|
107
|
+
pendingGrantHash: string,
|
|
108
|
+
updatedAt: string,
|
|
109
|
+
) {
|
|
110
|
+
return promoteDrizzleOutputGrant(
|
|
111
|
+
this.db,
|
|
112
|
+
scopeId,
|
|
113
|
+
expectedRevision,
|
|
114
|
+
pendingGrantGeneration,
|
|
115
|
+
pendingGrantHash,
|
|
116
|
+
updatedAt,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async rollbackGrant(
|
|
121
|
+
scopeId: string,
|
|
122
|
+
expectedRevision: number,
|
|
123
|
+
pendingGrantGeneration: number,
|
|
124
|
+
pendingGrantHash: string,
|
|
125
|
+
updatedAt: string,
|
|
126
|
+
) {
|
|
127
|
+
return rollbackDrizzleOutputGrant(
|
|
128
|
+
this.db,
|
|
129
|
+
scopeId,
|
|
130
|
+
expectedRevision,
|
|
131
|
+
pendingGrantGeneration,
|
|
132
|
+
pendingGrantHash,
|
|
133
|
+
updatedAt,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async transitionScope(
|
|
138
|
+
scopeId: string,
|
|
139
|
+
expectedRevision: number,
|
|
140
|
+
expectedStatuses: readonly AiOutputArtifactScope["status"][],
|
|
141
|
+
status: AiOutputArtifactScope["status"],
|
|
142
|
+
updatedAt: string,
|
|
143
|
+
) {
|
|
144
|
+
const [row] = await this.db
|
|
145
|
+
.update(aiOutputArtifactScopes)
|
|
146
|
+
.set({
|
|
147
|
+
status,
|
|
148
|
+
grantHash: status === "cleaned" ? null : undefined,
|
|
149
|
+
activeGrantGeneration: status === "cleaned" ? null : undefined,
|
|
150
|
+
pendingGrantHash: status === "open" ? undefined : null,
|
|
151
|
+
pendingGrantGeneration: status === "open" ? undefined : null,
|
|
152
|
+
pendingGrantExpiresAt: status === "open" ? undefined : null,
|
|
153
|
+
revision: sql`${aiOutputArtifactScopes.revision} + 1`,
|
|
154
|
+
updatedAt: new Date(updatedAt),
|
|
155
|
+
})
|
|
156
|
+
.where(
|
|
157
|
+
and(
|
|
158
|
+
eq(aiOutputArtifactScopes.scopeId, scopeId),
|
|
159
|
+
eq(aiOutputArtifactScopes.revision, expectedRevision),
|
|
160
|
+
inArray(aiOutputArtifactScopes.status, [...expectedStatuses]),
|
|
161
|
+
),
|
|
162
|
+
)
|
|
163
|
+
.returning();
|
|
164
|
+
return row ? mapAiOutputScope(row) : undefined;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
sealScope(
|
|
168
|
+
scopeId: string,
|
|
169
|
+
expectedRevision: number,
|
|
170
|
+
refExpiresAt: string,
|
|
171
|
+
updatedAt: string,
|
|
172
|
+
) {
|
|
173
|
+
return sealDrizzleAiOutputScope(
|
|
174
|
+
this.db,
|
|
175
|
+
scopeId,
|
|
176
|
+
expectedRevision,
|
|
177
|
+
refExpiresAt,
|
|
178
|
+
updatedAt,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async listCleanupScopes(expiredBefore: string, limit: number) {
|
|
183
|
+
return listDrizzleAiOutputCleanupScopes(this.db, expiredBefore, limit);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async clearExpiredGrantHashes(expiredBefore: string, limit: number) {
|
|
187
|
+
return clearExpiredDrizzleOutputGrantHashes(this.db, expiredBefore, limit);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async claimArtifact(input: NewAiOutputArtifact) {
|
|
191
|
+
return this.db.transaction(async (tx) => {
|
|
192
|
+
const [scope] = await tx
|
|
193
|
+
.select()
|
|
194
|
+
.from(aiOutputArtifactScopes)
|
|
195
|
+
.where(eq(aiOutputArtifactScopes.scopeId, input.scopeId))
|
|
196
|
+
.limit(1)
|
|
197
|
+
.for("update");
|
|
198
|
+
if (!scope || scope.status !== "open") {
|
|
199
|
+
throw new RepositoryError("CONFLICT");
|
|
200
|
+
}
|
|
201
|
+
const [existing] = await tx
|
|
202
|
+
.select()
|
|
203
|
+
.from(aiOutputArtifacts)
|
|
204
|
+
.where(
|
|
205
|
+
and(
|
|
206
|
+
eq(aiOutputArtifacts.scopeId, input.scopeId),
|
|
207
|
+
eq(aiOutputArtifacts.outputKey, input.outputKey),
|
|
208
|
+
),
|
|
209
|
+
)
|
|
210
|
+
.limit(1)
|
|
211
|
+
.for("update");
|
|
212
|
+
if (existing) {
|
|
213
|
+
if (
|
|
214
|
+
existing.fingerprint !== input.fingerprint ||
|
|
215
|
+
existing.status !== "creating"
|
|
216
|
+
) {
|
|
217
|
+
return { artifact: mapAiOutputArtifact(existing), claimed: false };
|
|
218
|
+
}
|
|
219
|
+
const [claimed] = await tx
|
|
220
|
+
.update(aiOutputArtifacts)
|
|
221
|
+
.set({
|
|
222
|
+
generation: sql`${aiOutputArtifacts.generation} + 1`,
|
|
223
|
+
updatedAt: new Date(input.createdAt),
|
|
224
|
+
})
|
|
225
|
+
.where(eq(aiOutputArtifacts.artifactId, existing.artifactId))
|
|
226
|
+
.returning();
|
|
227
|
+
return { artifact: mapAiOutputArtifact(claimed!), claimed: true };
|
|
228
|
+
}
|
|
229
|
+
const [totals] = await tx
|
|
230
|
+
.select({
|
|
231
|
+
expectedBytes:
|
|
232
|
+
sql<number>`coalesce(sum(${aiOutputArtifacts.expectedByteSize}), 0)`.mapWith(
|
|
233
|
+
Number,
|
|
234
|
+
),
|
|
235
|
+
})
|
|
236
|
+
.from(aiOutputArtifacts)
|
|
237
|
+
.where(eq(aiOutputArtifacts.scopeId, input.scopeId));
|
|
238
|
+
if (
|
|
239
|
+
scope.artifactCount >= scope.maxArtifacts ||
|
|
240
|
+
(totals?.expectedBytes ?? 0) + input.expectedByteSize >
|
|
241
|
+
scope.maxTotalBytes
|
|
242
|
+
) {
|
|
243
|
+
throw new RepositoryError("LIMIT");
|
|
244
|
+
}
|
|
245
|
+
const [created] = await tx
|
|
246
|
+
.insert(aiOutputArtifacts)
|
|
247
|
+
.values(aiOutputArtifactValues(input))
|
|
248
|
+
.onConflictDoNothing({
|
|
249
|
+
target: [aiOutputArtifacts.scopeId, aiOutputArtifacts.outputKey],
|
|
250
|
+
})
|
|
251
|
+
.returning();
|
|
252
|
+
if (!created) throw new RepositoryError("CONFLICT");
|
|
253
|
+
await tx
|
|
254
|
+
.update(aiOutputArtifactScopes)
|
|
255
|
+
.set({
|
|
256
|
+
artifactCount: scope.artifactCount + 1,
|
|
257
|
+
updatedAt: new Date(input.createdAt),
|
|
258
|
+
})
|
|
259
|
+
.where(eq(aiOutputArtifactScopes.scopeId, input.scopeId));
|
|
260
|
+
return { artifact: mapAiOutputArtifact(created!), claimed: true };
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
async bindUploadSession(
|
|
265
|
+
artifactId: string,
|
|
266
|
+
generation: number,
|
|
267
|
+
uploadSessionId: string,
|
|
268
|
+
updatedAt: string,
|
|
269
|
+
) {
|
|
270
|
+
const [row] = await this.db
|
|
271
|
+
.update(aiOutputArtifacts)
|
|
272
|
+
.set({
|
|
273
|
+
status: "uploading",
|
|
274
|
+
uploadSessionId,
|
|
275
|
+
updatedAt: new Date(updatedAt),
|
|
276
|
+
})
|
|
277
|
+
.where(
|
|
278
|
+
and(
|
|
279
|
+
eq(aiOutputArtifacts.artifactId, artifactId),
|
|
280
|
+
eq(aiOutputArtifacts.generation, generation),
|
|
281
|
+
eq(aiOutputArtifacts.status, "creating"),
|
|
282
|
+
),
|
|
283
|
+
)
|
|
284
|
+
.returning();
|
|
285
|
+
return row ? mapAiOutputArtifact(row) : undefined;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
async completeArtifact(
|
|
289
|
+
artifactId: string,
|
|
290
|
+
generation: number,
|
|
291
|
+
file: { id: string; byteSize: number; sha256: string },
|
|
292
|
+
updatedAt: string,
|
|
293
|
+
) {
|
|
294
|
+
return completeDrizzleAiOutputArtifact(
|
|
295
|
+
this.db,
|
|
296
|
+
artifactId,
|
|
297
|
+
generation,
|
|
298
|
+
file,
|
|
299
|
+
updatedAt,
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async transitionArtifact(
|
|
304
|
+
artifactId: string,
|
|
305
|
+
expectedGeneration: number,
|
|
306
|
+
expectedStatuses: readonly AiOutputArtifactRecord["status"][],
|
|
307
|
+
status: AiOutputArtifactRecord["status"],
|
|
308
|
+
updatedAt: string,
|
|
309
|
+
) {
|
|
310
|
+
const [row] = await this.db
|
|
311
|
+
.update(aiOutputArtifacts)
|
|
312
|
+
.set({
|
|
313
|
+
status,
|
|
314
|
+
generation: sql`${aiOutputArtifacts.generation} + 1`,
|
|
315
|
+
updatedAt: new Date(updatedAt),
|
|
316
|
+
})
|
|
317
|
+
.where(
|
|
318
|
+
and(
|
|
319
|
+
eq(aiOutputArtifacts.artifactId, artifactId),
|
|
320
|
+
eq(aiOutputArtifacts.generation, expectedGeneration),
|
|
321
|
+
inArray(aiOutputArtifacts.status, [...expectedStatuses]),
|
|
322
|
+
),
|
|
323
|
+
)
|
|
324
|
+
.returning();
|
|
325
|
+
return row ? mapAiOutputArtifact(row) : undefined;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async getArtifact(artifactId: string) {
|
|
329
|
+
const [row] = await this.db
|
|
330
|
+
.select()
|
|
331
|
+
.from(aiOutputArtifacts)
|
|
332
|
+
.where(eq(aiOutputArtifacts.artifactId, artifactId))
|
|
333
|
+
.limit(1);
|
|
334
|
+
return row ? mapAiOutputArtifact(row) : undefined;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
async listArtifacts(scopeId: string) {
|
|
338
|
+
return (
|
|
339
|
+
await this.db
|
|
340
|
+
.select()
|
|
341
|
+
.from(aiOutputArtifacts)
|
|
342
|
+
.where(eq(aiOutputArtifacts.scopeId, scopeId))
|
|
343
|
+
.orderBy(asc(aiOutputArtifacts.createdAt))
|
|
344
|
+
).map(mapAiOutputArtifact);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async deleteReadinessProbe(scopeId: string, purpose: string) {
|
|
348
|
+
return deleteDrizzleOutputReadinessProbe(this.db, scopeId, purpose);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
aiOutputArtifacts,
|
|
3
|
+
aiOutputArtifactScopes,
|
|
4
|
+
} from "@southwind-ai/database";
|
|
5
|
+
import { and, eq, ne } from "drizzle-orm";
|
|
6
|
+
import type { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
7
|
+
import { mapAiOutputScope } from "./drizzle-mapping.js";
|
|
8
|
+
|
|
9
|
+
export async function sealDrizzleAiOutputScope(
|
|
10
|
+
db: NodePgDatabase,
|
|
11
|
+
scopeId: string,
|
|
12
|
+
expectedRevision: number,
|
|
13
|
+
refExpiresAt: string,
|
|
14
|
+
updatedAt: string,
|
|
15
|
+
) {
|
|
16
|
+
return db.transaction(async (tx) => {
|
|
17
|
+
const [scope] = await tx
|
|
18
|
+
.select()
|
|
19
|
+
.from(aiOutputArtifactScopes)
|
|
20
|
+
.where(eq(aiOutputArtifactScopes.scopeId, scopeId))
|
|
21
|
+
.limit(1)
|
|
22
|
+
.for("update");
|
|
23
|
+
if (
|
|
24
|
+
!scope ||
|
|
25
|
+
scope.status !== "open" ||
|
|
26
|
+
scope.revision !== expectedRevision ||
|
|
27
|
+
Date.parse(refExpiresAt) <= scope.scopeExpiresAt.getTime() ||
|
|
28
|
+
Date.parse(refExpiresAt) > scope.fileExpiresAt.getTime()
|
|
29
|
+
) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const [incomplete] = await tx
|
|
33
|
+
.select({ artifactId: aiOutputArtifacts.artifactId })
|
|
34
|
+
.from(aiOutputArtifacts)
|
|
35
|
+
.where(
|
|
36
|
+
and(
|
|
37
|
+
eq(aiOutputArtifacts.scopeId, scopeId),
|
|
38
|
+
ne(aiOutputArtifacts.status, "completed"),
|
|
39
|
+
),
|
|
40
|
+
)
|
|
41
|
+
.limit(1);
|
|
42
|
+
if (incomplete) return undefined;
|
|
43
|
+
const [sealed] = await tx
|
|
44
|
+
.update(aiOutputArtifactScopes)
|
|
45
|
+
.set({
|
|
46
|
+
status: "sealed",
|
|
47
|
+
revision: scope.revision + 1,
|
|
48
|
+
pendingGrantHash: null,
|
|
49
|
+
pendingGrantGeneration: null,
|
|
50
|
+
pendingGrantExpiresAt: null,
|
|
51
|
+
refExpiresAt: new Date(refExpiresAt),
|
|
52
|
+
updatedAt: new Date(updatedAt),
|
|
53
|
+
})
|
|
54
|
+
.where(
|
|
55
|
+
and(
|
|
56
|
+
eq(aiOutputArtifactScopes.scopeId, scopeId),
|
|
57
|
+
eq(aiOutputArtifactScopes.status, "open"),
|
|
58
|
+
eq(aiOutputArtifactScopes.revision, expectedRevision),
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
.returning();
|
|
62
|
+
return sealed ? mapAiOutputScope(sealed) : undefined;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
const grantPattern = /^outgrant_v1_[A-Za-z0-9_-]{43}$/;
|
|
4
|
+
|
|
5
|
+
export function createAiOutputArtifactGrant(): {
|
|
6
|
+
readonly token: string;
|
|
7
|
+
readonly hash: string;
|
|
8
|
+
} {
|
|
9
|
+
const token = `outgrant_v1_${randomBytes(32).toString("base64url")}`;
|
|
10
|
+
return { token, hash: hashAiOutputArtifactGrant(token) };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function matchesAiOutputArtifactGrant(
|
|
14
|
+
token: string,
|
|
15
|
+
expectedHash: string,
|
|
16
|
+
): boolean {
|
|
17
|
+
if (!grantPattern.test(token) || !/^[0-9a-f]{64}$/.test(expectedHash)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const actual = Buffer.from(hashAiOutputArtifactGrant(token), "hex");
|
|
21
|
+
const expected = Buffer.from(expectedHash, "hex");
|
|
22
|
+
return (
|
|
23
|
+
actual.byteLength === expected.byteLength &&
|
|
24
|
+
timingSafeEqual(actual, expected)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function hashAiOutputArtifactGrant(token: string): string {
|
|
29
|
+
return createHash("sha256").update(token).digest("hex");
|
|
30
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ModuleAiOperationDefinition,
|
|
3
|
+
ModuleManifest,
|
|
4
|
+
} from "@southwind-ai/modules";
|
|
5
|
+
import type { FeatureFlagDefinition } from "@southwind-ai/shared";
|
|
6
|
+
import { findFeature } from "../route-guards.js";
|
|
7
|
+
import type { AiOutputRuntimeKind } from "./contracts.js";
|
|
8
|
+
|
|
9
|
+
export interface OutputArtifactBinding {
|
|
10
|
+
readonly operationKey: string;
|
|
11
|
+
readonly runtimeKind: AiOutputRuntimeKind;
|
|
12
|
+
readonly outputKind: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface RegisteredOutputArtifactOperation {
|
|
16
|
+
readonly moduleName: string;
|
|
17
|
+
readonly definition: ModuleAiOperationDefinition;
|
|
18
|
+
readonly feature: FeatureFlagDefinition | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function outputArtifactOperations(
|
|
22
|
+
modules: readonly ModuleManifest[],
|
|
23
|
+
features: readonly FeatureFlagDefinition[],
|
|
24
|
+
runtimeKind: AiOutputRuntimeKind,
|
|
25
|
+
): Map<string, RegisteredOutputArtifactOperation> {
|
|
26
|
+
const result = new Map<string, RegisteredOutputArtifactOperation>();
|
|
27
|
+
for (const module of modules)
|
|
28
|
+
for (const definition of module.aiOperations ?? []) {
|
|
29
|
+
if (definition.kind !== runtimeKind) continue;
|
|
30
|
+
if (result.has(definition.key))
|
|
31
|
+
throw new Error(`AI Output Artifact Operation 重复:${definition.key}`);
|
|
32
|
+
result.set(definition.key, {
|
|
33
|
+
moduleName: module.name,
|
|
34
|
+
definition,
|
|
35
|
+
feature: findFeature([...features], definition.featureKey),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function uniqueOutputArtifactBindings(
|
|
42
|
+
bindings: readonly OutputArtifactBinding[],
|
|
43
|
+
): Map<string, OutputArtifactBinding> {
|
|
44
|
+
const result = new Map<string, OutputArtifactBinding>();
|
|
45
|
+
for (const binding of bindings) {
|
|
46
|
+
if (result.has(binding.operationKey))
|
|
47
|
+
throw new Error(
|
|
48
|
+
`AI Output Artifact Binding 重复:${binding.operationKey}`,
|
|
49
|
+
);
|
|
50
|
+
result.set(binding.operationKey, binding);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AiOutputArtifactScope } from "./contracts.js";
|
|
2
|
+
|
|
3
|
+
export function listMemoryCleanupScopes(
|
|
4
|
+
scopes: ReadonlyMap<string, AiOutputArtifactScope>,
|
|
5
|
+
expiredBefore: string,
|
|
6
|
+
limit: number,
|
|
7
|
+
): AiOutputArtifactScope[] {
|
|
8
|
+
const staleBefore = new Date(
|
|
9
|
+
Date.parse(expiredBefore) - 60_000,
|
|
10
|
+
).toISOString();
|
|
11
|
+
return [...scopes.values()]
|
|
12
|
+
.filter(
|
|
13
|
+
(scope) =>
|
|
14
|
+
scope.status === "cleanup-pending" ||
|
|
15
|
+
((scope.status === "open" || scope.status === "aborted") &&
|
|
16
|
+
scope.scopeExpiresAt <= expiredBefore) ||
|
|
17
|
+
(scope.status === "sealed" && scope.fileExpiresAt <= expiredBefore) ||
|
|
18
|
+
(scope.status === "aborting" && scope.updatedAt <= staleBefore),
|
|
19
|
+
)
|
|
20
|
+
.slice(0, limit)
|
|
21
|
+
.map((scope) => structuredClone(scope));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function clearExpiredMemoryGrantHashes(
|
|
25
|
+
scopes: Map<string, AiOutputArtifactScope>,
|
|
26
|
+
expiredBefore: string,
|
|
27
|
+
limit: number,
|
|
28
|
+
): number {
|
|
29
|
+
const candidates = [...scopes.values()]
|
|
30
|
+
.filter(
|
|
31
|
+
(scope) =>
|
|
32
|
+
["sealed", "aborted"].includes(scope.status) &&
|
|
33
|
+
scope.grantHash !== undefined &&
|
|
34
|
+
scope.refExpiresAt <= expiredBefore,
|
|
35
|
+
)
|
|
36
|
+
.slice(0, limit);
|
|
37
|
+
for (const scope of candidates) {
|
|
38
|
+
scopes.set(scope.scopeId, {
|
|
39
|
+
...scope,
|
|
40
|
+
grantHash: undefined,
|
|
41
|
+
activeGrantGeneration: undefined,
|
|
42
|
+
revision: scope.revision + 1,
|
|
43
|
+
updatedAt: expiredBefore,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return candidates.length;
|
|
47
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { AiOutputArtifactScope } from "./contracts.js";
|
|
2
|
+
|
|
3
|
+
export function prepareMemoryOutputGrant(
|
|
4
|
+
scopes: Map<string, AiOutputArtifactScope>,
|
|
5
|
+
scopeId: string,
|
|
6
|
+
expectedRevision: number,
|
|
7
|
+
pendingGrantHash: string,
|
|
8
|
+
pendingGrantExpiresAt: string,
|
|
9
|
+
updatedAt: string,
|
|
10
|
+
): AiOutputArtifactScope | undefined {
|
|
11
|
+
const scope = scopes.get(scopeId);
|
|
12
|
+
if (
|
|
13
|
+
!scope ||
|
|
14
|
+
scope.status !== "open" ||
|
|
15
|
+
scope.revision !== expectedRevision ||
|
|
16
|
+
(scope.pendingGrantExpiresAt && scope.pendingGrantExpiresAt > updatedAt)
|
|
17
|
+
) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const pendingGrantGeneration = scope.grantSequence + 1;
|
|
21
|
+
return save(scopes, {
|
|
22
|
+
...scope,
|
|
23
|
+
revision: scope.revision + 1,
|
|
24
|
+
grantSequence: pendingGrantGeneration,
|
|
25
|
+
pendingGrantHash,
|
|
26
|
+
pendingGrantGeneration,
|
|
27
|
+
pendingGrantExpiresAt,
|
|
28
|
+
updatedAt,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function promoteMemoryOutputGrant(
|
|
33
|
+
scopes: Map<string, AiOutputArtifactScope>,
|
|
34
|
+
scopeId: string,
|
|
35
|
+
expectedRevision: number,
|
|
36
|
+
pendingGrantGeneration: number,
|
|
37
|
+
pendingGrantHash: string,
|
|
38
|
+
updatedAt: string,
|
|
39
|
+
): AiOutputArtifactScope | undefined {
|
|
40
|
+
const scope = scopes.get(scopeId);
|
|
41
|
+
if (
|
|
42
|
+
!scope ||
|
|
43
|
+
scope.status !== "open" ||
|
|
44
|
+
scope.revision !== expectedRevision ||
|
|
45
|
+
scope.pendingGrantGeneration !== pendingGrantGeneration ||
|
|
46
|
+
scope.pendingGrantHash !== pendingGrantHash ||
|
|
47
|
+
!scope.pendingGrantExpiresAt ||
|
|
48
|
+
scope.pendingGrantExpiresAt <= updatedAt
|
|
49
|
+
) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
return save(scopes, {
|
|
53
|
+
...scope,
|
|
54
|
+
revision: scope.revision + 1,
|
|
55
|
+
grantHash: scope.pendingGrantHash,
|
|
56
|
+
activeGrantGeneration: scope.pendingGrantGeneration,
|
|
57
|
+
pendingGrantHash: undefined,
|
|
58
|
+
pendingGrantGeneration: undefined,
|
|
59
|
+
pendingGrantExpiresAt: undefined,
|
|
60
|
+
updatedAt,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function rollbackMemoryOutputGrant(
|
|
65
|
+
scopes: Map<string, AiOutputArtifactScope>,
|
|
66
|
+
scopeId: string,
|
|
67
|
+
expectedRevision: number,
|
|
68
|
+
pendingGrantGeneration: number,
|
|
69
|
+
pendingGrantHash: string,
|
|
70
|
+
updatedAt: string,
|
|
71
|
+
): AiOutputArtifactScope | undefined {
|
|
72
|
+
const scope = scopes.get(scopeId);
|
|
73
|
+
if (
|
|
74
|
+
!scope ||
|
|
75
|
+
scope.status !== "open" ||
|
|
76
|
+
scope.revision !== expectedRevision ||
|
|
77
|
+
scope.pendingGrantGeneration !== pendingGrantGeneration ||
|
|
78
|
+
scope.pendingGrantHash !== pendingGrantHash
|
|
79
|
+
) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
return save(scopes, {
|
|
83
|
+
...scope,
|
|
84
|
+
revision: scope.revision + 1,
|
|
85
|
+
pendingGrantHash: undefined,
|
|
86
|
+
pendingGrantGeneration: undefined,
|
|
87
|
+
pendingGrantExpiresAt: undefined,
|
|
88
|
+
updatedAt,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function save(
|
|
93
|
+
scopes: Map<string, AiOutputArtifactScope>,
|
|
94
|
+
scope: AiOutputArtifactScope,
|
|
95
|
+
) {
|
|
96
|
+
scopes.set(scope.scopeId, scope);
|
|
97
|
+
return structuredClone(scope);
|
|
98
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AiOutputArtifactRecord,
|
|
3
|
+
AiOutputArtifactScope,
|
|
4
|
+
} from "./contracts.js";
|
|
5
|
+
|
|
6
|
+
export function deleteMemoryOutputReadinessProbe(
|
|
7
|
+
scopes: Map<string, AiOutputArtifactScope>,
|
|
8
|
+
artifacts: Map<string, AiOutputArtifactRecord>,
|
|
9
|
+
scopeId: string,
|
|
10
|
+
purpose: string,
|
|
11
|
+
) {
|
|
12
|
+
const scope = scopes.get(scopeId);
|
|
13
|
+
if (!scope) return true;
|
|
14
|
+
if (
|
|
15
|
+
purpose !== "ai-runtime-output-readiness" ||
|
|
16
|
+
scope.purpose !== purpose ||
|
|
17
|
+
!["aborted", "cleaned"].includes(scope.status)
|
|
18
|
+
) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
for (const [artifactId, artifact] of artifacts) {
|
|
22
|
+
if (artifact.scopeId === scopeId) artifacts.delete(artifactId);
|
|
23
|
+
}
|
|
24
|
+
scopes.delete(scopeId);
|
|
25
|
+
return true;
|
|
26
|
+
}
|