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,348 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AiOutputArtifactRecord,
|
|
3
|
+
AiOutputArtifactScope,
|
|
4
|
+
} from "./contracts.js";
|
|
5
|
+
import type {
|
|
6
|
+
AiOutputArtifactRepository,
|
|
7
|
+
NewAiOutputArtifact,
|
|
8
|
+
NewAiOutputScope,
|
|
9
|
+
} from "./repository.js";
|
|
10
|
+
import { AiOutputArtifactRepositoryError } from "./repository.js";
|
|
11
|
+
import {
|
|
12
|
+
prepareMemoryOutputGrant,
|
|
13
|
+
promoteMemoryOutputGrant,
|
|
14
|
+
rollbackMemoryOutputGrant,
|
|
15
|
+
} from "./memory-grants.js";
|
|
16
|
+
import {
|
|
17
|
+
clearExpiredMemoryGrantHashes,
|
|
18
|
+
listMemoryCleanupScopes,
|
|
19
|
+
} from "./memory-cleanup.js";
|
|
20
|
+
import { deleteMemoryOutputReadinessProbe } from "./memory-readiness.js";
|
|
21
|
+
|
|
22
|
+
export class InMemoryAiOutputArtifactRepository implements AiOutputArtifactRepository {
|
|
23
|
+
readonly #scopes = new Map<string, AiOutputArtifactScope>();
|
|
24
|
+
readonly #artifacts = new Map<string, AiOutputArtifactRecord>();
|
|
25
|
+
|
|
26
|
+
async createOrGetScope(input: NewAiOutputScope) {
|
|
27
|
+
const existing = [...this.#scopes.values()].find(
|
|
28
|
+
({ idempotencyHash }) => idempotencyHash === input.idempotencyHash,
|
|
29
|
+
);
|
|
30
|
+
if (existing) return { scope: clone(existing), created: false };
|
|
31
|
+
const sameRunKind = [...this.#scopes.values()].find(
|
|
32
|
+
(scope) =>
|
|
33
|
+
scope.runId === input.runId && scope.outputKind === input.outputKind,
|
|
34
|
+
);
|
|
35
|
+
if (sameRunKind) {
|
|
36
|
+
return { scope: clone(sameRunKind), created: false };
|
|
37
|
+
}
|
|
38
|
+
const scope = { ...clone(input), artifactCount: 0, completedByteSize: 0 };
|
|
39
|
+
this.#scopes.set(scope.scopeId, scope);
|
|
40
|
+
return { scope: clone(scope), created: true };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async getScope(scopeId: string) {
|
|
44
|
+
return cloned(this.#scopes.get(scopeId));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async listScopesByRun(runId: string) {
|
|
48
|
+
return [...this.#scopes.values()]
|
|
49
|
+
.filter((scope) => scope.runId === runId)
|
|
50
|
+
.map(clone);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async prepareGrant(
|
|
54
|
+
scopeId: string,
|
|
55
|
+
expectedRevision: number,
|
|
56
|
+
pendingGrantHash: string,
|
|
57
|
+
pendingGrantExpiresAt: string,
|
|
58
|
+
updatedAt: string,
|
|
59
|
+
) {
|
|
60
|
+
return prepareMemoryOutputGrant(
|
|
61
|
+
this.#scopes,
|
|
62
|
+
scopeId,
|
|
63
|
+
expectedRevision,
|
|
64
|
+
pendingGrantHash,
|
|
65
|
+
pendingGrantExpiresAt,
|
|
66
|
+
updatedAt,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async promoteGrant(
|
|
71
|
+
scopeId: string,
|
|
72
|
+
expectedRevision: number,
|
|
73
|
+
pendingGrantGeneration: number,
|
|
74
|
+
pendingGrantHash: string,
|
|
75
|
+
updatedAt: string,
|
|
76
|
+
) {
|
|
77
|
+
return promoteMemoryOutputGrant(
|
|
78
|
+
this.#scopes,
|
|
79
|
+
scopeId,
|
|
80
|
+
expectedRevision,
|
|
81
|
+
pendingGrantGeneration,
|
|
82
|
+
pendingGrantHash,
|
|
83
|
+
updatedAt,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async rollbackGrant(
|
|
88
|
+
scopeId: string,
|
|
89
|
+
expectedRevision: number,
|
|
90
|
+
pendingGrantGeneration: number,
|
|
91
|
+
pendingGrantHash: string,
|
|
92
|
+
updatedAt: string,
|
|
93
|
+
) {
|
|
94
|
+
return rollbackMemoryOutputGrant(
|
|
95
|
+
this.#scopes,
|
|
96
|
+
scopeId,
|
|
97
|
+
expectedRevision,
|
|
98
|
+
pendingGrantGeneration,
|
|
99
|
+
pendingGrantHash,
|
|
100
|
+
updatedAt,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async transitionScope(
|
|
105
|
+
scopeId: string,
|
|
106
|
+
expectedRevision: number,
|
|
107
|
+
expectedStatuses: readonly AiOutputArtifactScope["status"][],
|
|
108
|
+
status: AiOutputArtifactScope["status"],
|
|
109
|
+
updatedAt: string,
|
|
110
|
+
) {
|
|
111
|
+
const scope = this.#scopes.get(scopeId);
|
|
112
|
+
if (
|
|
113
|
+
!scope ||
|
|
114
|
+
scope.revision !== expectedRevision ||
|
|
115
|
+
!expectedStatuses.includes(scope.status)
|
|
116
|
+
) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
const updated = {
|
|
120
|
+
...scope,
|
|
121
|
+
status,
|
|
122
|
+
grantHash: status === "cleaned" ? undefined : scope.grantHash,
|
|
123
|
+
activeGrantGeneration:
|
|
124
|
+
status === "cleaned" ? undefined : scope.activeGrantGeneration,
|
|
125
|
+
pendingGrantHash: status === "open" ? scope.pendingGrantHash : undefined,
|
|
126
|
+
pendingGrantGeneration:
|
|
127
|
+
status === "open" ? scope.pendingGrantGeneration : undefined,
|
|
128
|
+
pendingGrantExpiresAt:
|
|
129
|
+
status === "open" ? scope.pendingGrantExpiresAt : undefined,
|
|
130
|
+
revision: scope.revision + 1,
|
|
131
|
+
updatedAt,
|
|
132
|
+
};
|
|
133
|
+
this.#scopes.set(scopeId, updated);
|
|
134
|
+
return clone(updated);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async sealScope(
|
|
138
|
+
scopeId: string,
|
|
139
|
+
expectedRevision: number,
|
|
140
|
+
refExpiresAt: string,
|
|
141
|
+
updatedAt: string,
|
|
142
|
+
) {
|
|
143
|
+
const scope = this.#scopes.get(scopeId);
|
|
144
|
+
if (
|
|
145
|
+
!scope ||
|
|
146
|
+
scope.status !== "open" ||
|
|
147
|
+
scope.revision !== expectedRevision ||
|
|
148
|
+
refExpiresAt <= scope.scopeExpiresAt ||
|
|
149
|
+
refExpiresAt > scope.fileExpiresAt ||
|
|
150
|
+
[...this.#artifacts.values()].some(
|
|
151
|
+
(artifact) =>
|
|
152
|
+
artifact.scopeId === scopeId && artifact.status !== "completed",
|
|
153
|
+
)
|
|
154
|
+
) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
const sealed: AiOutputArtifactScope = {
|
|
158
|
+
...scope,
|
|
159
|
+
status: "sealed",
|
|
160
|
+
revision: scope.revision + 1,
|
|
161
|
+
pendingGrantHash: undefined,
|
|
162
|
+
pendingGrantGeneration: undefined,
|
|
163
|
+
pendingGrantExpiresAt: undefined,
|
|
164
|
+
refExpiresAt,
|
|
165
|
+
updatedAt,
|
|
166
|
+
};
|
|
167
|
+
this.#scopes.set(scopeId, sealed);
|
|
168
|
+
return clone(sealed);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async listCleanupScopes(expiredBefore: string, limit: number) {
|
|
172
|
+
return listMemoryCleanupScopes(this.#scopes, expiredBefore, limit);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async clearExpiredGrantHashes(expiredBefore: string, limit: number) {
|
|
176
|
+
return clearExpiredMemoryGrantHashes(this.#scopes, expiredBefore, limit);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async claimArtifact(input: NewAiOutputArtifact) {
|
|
180
|
+
const scope = this.#scopes.get(input.scopeId);
|
|
181
|
+
if (!scope || scope.status !== "open") {
|
|
182
|
+
throw new AiOutputArtifactRepositoryError("CONFLICT");
|
|
183
|
+
}
|
|
184
|
+
const existing = [...this.#artifacts.values()].find(
|
|
185
|
+
(artifact) =>
|
|
186
|
+
artifact.scopeId === input.scopeId &&
|
|
187
|
+
artifact.outputKey === input.outputKey,
|
|
188
|
+
);
|
|
189
|
+
if (existing) {
|
|
190
|
+
if (existing.fingerprint !== input.fingerprint) {
|
|
191
|
+
return { artifact: clone(existing), claimed: false };
|
|
192
|
+
}
|
|
193
|
+
if (existing.status !== "creating") {
|
|
194
|
+
return { artifact: clone(existing), claimed: false };
|
|
195
|
+
}
|
|
196
|
+
const claimed = {
|
|
197
|
+
...existing,
|
|
198
|
+
generation: existing.generation + 1,
|
|
199
|
+
updatedAt: input.createdAt,
|
|
200
|
+
};
|
|
201
|
+
this.#artifacts.set(claimed.artifactId, claimed);
|
|
202
|
+
return { artifact: clone(claimed), claimed: true };
|
|
203
|
+
}
|
|
204
|
+
if (
|
|
205
|
+
scope.artifactCount >= scope.maxArtifacts ||
|
|
206
|
+
this.expectedBytes(scope.scopeId) + input.expectedByteSize >
|
|
207
|
+
scope.maxTotalBytes
|
|
208
|
+
) {
|
|
209
|
+
throw new AiOutputArtifactRepositoryError("LIMIT");
|
|
210
|
+
}
|
|
211
|
+
const artifact: AiOutputArtifactRecord = {
|
|
212
|
+
...clone(input),
|
|
213
|
+
generation: 1,
|
|
214
|
+
status: "creating",
|
|
215
|
+
updatedAt: input.createdAt,
|
|
216
|
+
};
|
|
217
|
+
this.#artifacts.set(artifact.artifactId, artifact);
|
|
218
|
+
this.#scopes.set(scope.scopeId, {
|
|
219
|
+
...scope,
|
|
220
|
+
artifactCount: scope.artifactCount + 1,
|
|
221
|
+
updatedAt: input.createdAt,
|
|
222
|
+
});
|
|
223
|
+
return { artifact: clone(artifact), claimed: true };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async bindUploadSession(
|
|
227
|
+
artifactId: string,
|
|
228
|
+
generation: number,
|
|
229
|
+
uploadSessionId: string,
|
|
230
|
+
updatedAt: string,
|
|
231
|
+
) {
|
|
232
|
+
const artifact = this.#artifacts.get(artifactId);
|
|
233
|
+
if (
|
|
234
|
+
!artifact ||
|
|
235
|
+
artifact.status !== "creating" ||
|
|
236
|
+
artifact.generation !== generation
|
|
237
|
+
) {
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
return this.save({
|
|
241
|
+
...artifact,
|
|
242
|
+
status: "uploading",
|
|
243
|
+
uploadSessionId,
|
|
244
|
+
updatedAt,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async completeArtifact(
|
|
249
|
+
artifactId: string,
|
|
250
|
+
generation: number,
|
|
251
|
+
file: { id: string; byteSize: number; sha256: string },
|
|
252
|
+
updatedAt: string,
|
|
253
|
+
) {
|
|
254
|
+
const artifact = this.#artifacts.get(artifactId);
|
|
255
|
+
if (
|
|
256
|
+
!artifact ||
|
|
257
|
+
artifact.status !== "uploading" ||
|
|
258
|
+
artifact.generation !== generation ||
|
|
259
|
+
artifact.expectedByteSize !== file.byteSize ||
|
|
260
|
+
artifact.expectedSha256 !== file.sha256
|
|
261
|
+
) {
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
const scope = this.#scopes.get(artifact.scopeId);
|
|
265
|
+
if (
|
|
266
|
+
!scope ||
|
|
267
|
+
scope.status !== "open" ||
|
|
268
|
+
scope.completedByteSize + file.byteSize > scope.maxTotalBytes
|
|
269
|
+
) {
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
this.#scopes.set(scope.scopeId, {
|
|
273
|
+
...scope,
|
|
274
|
+
completedByteSize: scope.completedByteSize + file.byteSize,
|
|
275
|
+
updatedAt,
|
|
276
|
+
});
|
|
277
|
+
const completed = this.save({
|
|
278
|
+
...artifact,
|
|
279
|
+
status: "completed",
|
|
280
|
+
fileId: file.id,
|
|
281
|
+
byteSize: file.byteSize,
|
|
282
|
+
sha256: file.sha256,
|
|
283
|
+
updatedAt,
|
|
284
|
+
});
|
|
285
|
+
return completed;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
async transitionArtifact(
|
|
289
|
+
artifactId: string,
|
|
290
|
+
expectedGeneration: number,
|
|
291
|
+
expectedStatuses: readonly AiOutputArtifactRecord["status"][],
|
|
292
|
+
status: AiOutputArtifactRecord["status"],
|
|
293
|
+
updatedAt: string,
|
|
294
|
+
) {
|
|
295
|
+
const artifact = this.#artifacts.get(artifactId);
|
|
296
|
+
if (
|
|
297
|
+
!artifact ||
|
|
298
|
+
artifact.generation !== expectedGeneration ||
|
|
299
|
+
!expectedStatuses.includes(artifact.status)
|
|
300
|
+
) {
|
|
301
|
+
return undefined;
|
|
302
|
+
}
|
|
303
|
+
return this.save({
|
|
304
|
+
...artifact,
|
|
305
|
+
generation: artifact.generation + 1,
|
|
306
|
+
status,
|
|
307
|
+
updatedAt,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async getArtifact(artifactId: string) {
|
|
312
|
+
return cloned(this.#artifacts.get(artifactId));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
async listArtifacts(scopeId: string) {
|
|
316
|
+
return [...this.#artifacts.values()]
|
|
317
|
+
.filter((artifact) => artifact.scopeId === scopeId)
|
|
318
|
+
.map(clone);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async deleteReadinessProbe(scopeId: string, purpose: string) {
|
|
322
|
+
return deleteMemoryOutputReadinessProbe(
|
|
323
|
+
this.#scopes,
|
|
324
|
+
this.#artifacts,
|
|
325
|
+
scopeId,
|
|
326
|
+
purpose,
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private save(artifact: AiOutputArtifactRecord) {
|
|
331
|
+
this.#artifacts.set(artifact.artifactId, artifact);
|
|
332
|
+
return clone(artifact);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
private expectedBytes(scopeId: string) {
|
|
336
|
+
return [...this.#artifacts.values()]
|
|
337
|
+
.filter((artifact) => artifact.scopeId === scopeId)
|
|
338
|
+
.reduce((total, artifact) => total + artifact.expectedByteSize, 0);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function cloned<T>(value: T | undefined): T | undefined {
|
|
343
|
+
return value === undefined ? undefined : clone(value);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function clone<T>(value: T): T {
|
|
347
|
+
return structuredClone(value);
|
|
348
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
AiOutputArtifactPolicyRegistry,
|
|
4
|
+
type AiOutputArtifactLimitSet,
|
|
5
|
+
} from "./policy.js";
|
|
6
|
+
import { createOutputArtifactFixture, outputLimits } from "./test-support.js";
|
|
7
|
+
|
|
8
|
+
describe("AI Output Artifact policy", () => {
|
|
9
|
+
test("Operation/readiness/runtime/Host 四方上限逐项取最小值", () => {
|
|
10
|
+
const policy = new AiOutputArtifactPolicyRegistry().resolve({
|
|
11
|
+
runtimeKind: "document",
|
|
12
|
+
outputKind: "searchable-pdf",
|
|
13
|
+
dataClassification: "internal",
|
|
14
|
+
operationLimits: limits(20_000, 5, 30_000, 900),
|
|
15
|
+
readinessLimits: limits(18_000, 4, 25_000, 800),
|
|
16
|
+
runtimeLimits: limits(16_000, 3, 20_000, 700),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(policy).toMatchObject({
|
|
20
|
+
maxArtifactBytes: 16_000,
|
|
21
|
+
maxArtifacts: 3,
|
|
22
|
+
maxTotalBytes: 20_000,
|
|
23
|
+
scopeTtlMs: 760_000,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test.each([Number.NaN, Number.POSITIVE_INFINITY, 1.5, 0])(
|
|
28
|
+
"非有限、非安全或非正限额 %p fail closed",
|
|
29
|
+
(invalid) => {
|
|
30
|
+
expect(() =>
|
|
31
|
+
new AiOutputArtifactPolicyRegistry().resolve({
|
|
32
|
+
runtimeKind: "document",
|
|
33
|
+
outputKind: "searchable-pdf",
|
|
34
|
+
dataClassification: "internal",
|
|
35
|
+
operationLimits: {
|
|
36
|
+
...outputLimits(),
|
|
37
|
+
maxTotalBytes: invalid,
|
|
38
|
+
},
|
|
39
|
+
readinessLimits: outputLimits(),
|
|
40
|
+
runtimeLimits: outputLimits(),
|
|
41
|
+
}),
|
|
42
|
+
).toThrow("限额无效");
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
test("idempotency key 仅接受有界稳定 token", async () => {
|
|
47
|
+
const fixture = createOutputArtifactFixture();
|
|
48
|
+
await expect(fixture.begin(" has-space")).rejects.toThrow("治理上下文无效");
|
|
49
|
+
await expect(fixture.begin("x".repeat(161))).rejects.toThrow(
|
|
50
|
+
"治理上下文无效",
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
function limits(
|
|
56
|
+
maxArtifactBytes: number,
|
|
57
|
+
maxArtifacts: number,
|
|
58
|
+
maxTotalBytes: number,
|
|
59
|
+
maxDurationSeconds: number,
|
|
60
|
+
): AiOutputArtifactLimitSet {
|
|
61
|
+
return {
|
|
62
|
+
maxArtifactBytes,
|
|
63
|
+
maxArtifacts,
|
|
64
|
+
maxTotalBytes,
|
|
65
|
+
maxDurationSeconds,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import type { AiOutputRuntimeKind } from "./contracts.js";
|
|
3
|
+
|
|
4
|
+
export const aiOutputArtifactReadinessPurpose =
|
|
5
|
+
"ai-runtime-output-readiness" as const;
|
|
6
|
+
|
|
7
|
+
export interface AiOutputArtifactPolicy {
|
|
8
|
+
readonly runtimeKind: AiOutputRuntimeKind;
|
|
9
|
+
readonly outputKind: string;
|
|
10
|
+
readonly dataClassification: "public" | "internal" | "sensitive";
|
|
11
|
+
readonly purpose:
|
|
12
|
+
| "ai-runtime-output"
|
|
13
|
+
| typeof aiOutputArtifactReadinessPurpose;
|
|
14
|
+
readonly allowedMediaTypes: readonly string[];
|
|
15
|
+
readonly maxArtifactBytes: number;
|
|
16
|
+
readonly maxArtifacts: number;
|
|
17
|
+
readonly maxTotalBytes: number;
|
|
18
|
+
readonly scopeTtlMs: number;
|
|
19
|
+
readonly fileRetentionMs: number;
|
|
20
|
+
readonly referenceTtlMs: number;
|
|
21
|
+
readonly digest: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface AiOutputArtifactLimitSet {
|
|
25
|
+
readonly maxArtifactBytes: number;
|
|
26
|
+
readonly maxArtifacts: number;
|
|
27
|
+
readonly maxTotalBytes: number;
|
|
28
|
+
readonly maxDurationSeconds: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class AiOutputArtifactPolicyRegistry {
|
|
32
|
+
resolve(input: {
|
|
33
|
+
runtimeKind: AiOutputRuntimeKind;
|
|
34
|
+
outputKind: string;
|
|
35
|
+
dataClassification: AiOutputArtifactPolicy["dataClassification"];
|
|
36
|
+
operationLimits: AiOutputArtifactLimitSet;
|
|
37
|
+
readinessLimits: AiOutputArtifactLimitSet;
|
|
38
|
+
runtimeLimits: AiOutputArtifactLimitSet;
|
|
39
|
+
}): AiOutputArtifactPolicy {
|
|
40
|
+
const base = basePolicy(input.runtimeKind, input.outputKind);
|
|
41
|
+
const sensitive = input.dataClassification === "sensitive";
|
|
42
|
+
const limits = minimumLimits(
|
|
43
|
+
base,
|
|
44
|
+
input.operationLimits,
|
|
45
|
+
input.readinessLimits,
|
|
46
|
+
input.runtimeLimits,
|
|
47
|
+
);
|
|
48
|
+
const values = {
|
|
49
|
+
runtimeKind: input.runtimeKind,
|
|
50
|
+
outputKind: input.outputKind,
|
|
51
|
+
dataClassification: input.dataClassification,
|
|
52
|
+
purpose: "ai-runtime-output" as const,
|
|
53
|
+
allowedMediaTypes: base.mediaTypes,
|
|
54
|
+
maxArtifactBytes: limits.maxArtifactBytes,
|
|
55
|
+
maxArtifacts: limits.maxArtifacts,
|
|
56
|
+
maxTotalBytes: limits.maxTotalBytes,
|
|
57
|
+
scopeTtlMs: limits.maxDurationSeconds * 1_000 + 60_000,
|
|
58
|
+
fileRetentionMs: sensitive ? 24 * 60 * 60_000 : 7 * 24 * 60 * 60_000,
|
|
59
|
+
referenceTtlMs: sensitive ? 15 * 60_000 : 60 * 60_000,
|
|
60
|
+
};
|
|
61
|
+
return { ...values, digest: policyDigest(values) };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function basePolicy(runtimeKind: AiOutputRuntimeKind, outputKind: string) {
|
|
66
|
+
if (runtimeKind === "document" && outputKind === "searchable-pdf") {
|
|
67
|
+
return {
|
|
68
|
+
mediaTypes: ["application/pdf"] as const,
|
|
69
|
+
maxArtifactBytes: 64 * 1024 * 1024,
|
|
70
|
+
maxArtifacts: 16,
|
|
71
|
+
maxTotalBytes: 64 * 1024 * 1024,
|
|
72
|
+
maxDurationSeconds: 3_600,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (runtimeKind === "speech" && outputKind === "normalized-audio") {
|
|
76
|
+
return {
|
|
77
|
+
mediaTypes: ["audio/wav"] as const,
|
|
78
|
+
maxArtifactBytes: 512 * 1024 * 1024,
|
|
79
|
+
maxArtifacts: 1,
|
|
80
|
+
maxTotalBytes: 512 * 1024 * 1024,
|
|
81
|
+
maxDurationSeconds: 3_600,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
throw new Error(
|
|
85
|
+
`未注册 AI Output Artifact 策略:${runtimeKind}/${outputKind}`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function minimumLimits(
|
|
90
|
+
...sets: readonly AiOutputArtifactLimitSet[]
|
|
91
|
+
): AiOutputArtifactLimitSet {
|
|
92
|
+
sets.forEach(validateLimits);
|
|
93
|
+
return {
|
|
94
|
+
maxArtifactBytes: Math.min(
|
|
95
|
+
...sets.map(({ maxArtifactBytes }) => maxArtifactBytes),
|
|
96
|
+
),
|
|
97
|
+
maxArtifacts: Math.min(...sets.map(({ maxArtifacts }) => maxArtifacts)),
|
|
98
|
+
maxTotalBytes: Math.min(...sets.map(({ maxTotalBytes }) => maxTotalBytes)),
|
|
99
|
+
maxDurationSeconds: Math.min(
|
|
100
|
+
...sets.map(({ maxDurationSeconds }) => maxDurationSeconds),
|
|
101
|
+
),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function validateLimits(value: AiOutputArtifactLimitSet) {
|
|
106
|
+
for (const [field, limit, maximum] of [
|
|
107
|
+
["maxArtifactBytes", value.maxArtifactBytes, 512 * 1024 * 1024],
|
|
108
|
+
["maxArtifacts", value.maxArtifacts, 100],
|
|
109
|
+
["maxTotalBytes", value.maxTotalBytes, 512 * 1024 * 1024],
|
|
110
|
+
["maxDurationSeconds", value.maxDurationSeconds, 3_600],
|
|
111
|
+
] as const) {
|
|
112
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > maximum) {
|
|
113
|
+
throw new Error(`AI Output Artifact ${field} 限额无效`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (value.maxArtifactBytes > value.maxTotalBytes) {
|
|
117
|
+
throw new Error("AI Output Artifact 单件上限超过总量上限");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function policyDigest(value: object) {
|
|
122
|
+
return createHash("sha256")
|
|
123
|
+
.update(JSON.stringify(value, Object.keys(value).sort()))
|
|
124
|
+
.digest("hex");
|
|
125
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { drizzle } from "drizzle-orm/node-postgres";
|
|
2
|
+
import { Pool } from "pg";
|
|
3
|
+
import { buildScopeContext } from "../data-access/context.js";
|
|
4
|
+
import type { RequestGuardContext } from "../guards.js";
|
|
5
|
+
import { createStorageRuntime } from "../storage/runtime.js";
|
|
6
|
+
import { AiOutputArtifactCleanupService } from "./cleanup.js";
|
|
7
|
+
import { DrizzleAiOutputArtifactRepository } from "./drizzle-repository.js";
|
|
8
|
+
import { AiOutputArtifactPolicyRegistry } from "./policy.js";
|
|
9
|
+
import { AiOutputArtifactReferenceCodec } from "./reference-codec.js";
|
|
10
|
+
import { AiOutputArtifactService } from "./service.js";
|
|
11
|
+
import { AiOutputArtifactStorageWriterFactory } from "./storage-writer.js";
|
|
12
|
+
import { outputLimits } from "./test-support.js";
|
|
13
|
+
|
|
14
|
+
export function createPostgresArtifactStack(
|
|
15
|
+
databaseUrl: string,
|
|
16
|
+
root: string,
|
|
17
|
+
now: () => Date = () => new Date(),
|
|
18
|
+
) {
|
|
19
|
+
const pool = new Pool({ connectionString: databaseUrl });
|
|
20
|
+
const database = drizzle(pool);
|
|
21
|
+
const repository = new DrizzleAiOutputArtifactRepository(database);
|
|
22
|
+
const storage = createStorageRuntime(
|
|
23
|
+
{ WINDY_BLOB_DRIVER: "local", WINDY_STORAGE_ROOT: root },
|
|
24
|
+
database,
|
|
25
|
+
[],
|
|
26
|
+
now,
|
|
27
|
+
);
|
|
28
|
+
const writers = new AiOutputArtifactStorageWriterFactory(
|
|
29
|
+
storage,
|
|
30
|
+
{ record: () => undefined },
|
|
31
|
+
now,
|
|
32
|
+
);
|
|
33
|
+
const service = new AiOutputArtifactService({
|
|
34
|
+
repository,
|
|
35
|
+
storage,
|
|
36
|
+
writers,
|
|
37
|
+
references: new AiOutputArtifactReferenceCodec("p".repeat(32)),
|
|
38
|
+
authorizeRead: async (scope) => ({
|
|
39
|
+
actorId: scope.actorId,
|
|
40
|
+
scopeHash: scope.scopeHash,
|
|
41
|
+
requestId: "request-read-postgres",
|
|
42
|
+
}),
|
|
43
|
+
recordRead: () => undefined,
|
|
44
|
+
now,
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
pool,
|
|
48
|
+
repository,
|
|
49
|
+
storage,
|
|
50
|
+
writers,
|
|
51
|
+
service,
|
|
52
|
+
cleanup: new AiOutputArtifactCleanupService(
|
|
53
|
+
repository,
|
|
54
|
+
storage,
|
|
55
|
+
writers,
|
|
56
|
+
now,
|
|
57
|
+
),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function beginPostgresArtifactScope(
|
|
62
|
+
value: ReturnType<typeof createPostgresArtifactStack>,
|
|
63
|
+
idempotencyKey: string,
|
|
64
|
+
runId: string,
|
|
65
|
+
) {
|
|
66
|
+
const prepared = await preparePostgresArtifactScope(
|
|
67
|
+
value,
|
|
68
|
+
idempotencyKey,
|
|
69
|
+
runId,
|
|
70
|
+
);
|
|
71
|
+
if (!prepared.grant || !prepared.descriptor) return prepared;
|
|
72
|
+
const accepted = await value.service.acceptGrant(
|
|
73
|
+
prepared.scope.scopeId,
|
|
74
|
+
prepared.descriptor.grantGeneration,
|
|
75
|
+
prepared.grant,
|
|
76
|
+
);
|
|
77
|
+
return { ...prepared, scope: accepted };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function preparePostgresArtifactScope(
|
|
81
|
+
value: ReturnType<typeof createPostgresArtifactStack>,
|
|
82
|
+
idempotencyKey: string,
|
|
83
|
+
runId: string,
|
|
84
|
+
) {
|
|
85
|
+
const limits = outputLimits();
|
|
86
|
+
const policy = new AiOutputArtifactPolicyRegistry().resolve({
|
|
87
|
+
runtimeKind: "document",
|
|
88
|
+
outputKind: "searchable-pdf",
|
|
89
|
+
dataClassification: "sensitive",
|
|
90
|
+
operationLimits: limits,
|
|
91
|
+
readinessLimits: limits,
|
|
92
|
+
runtimeLimits: limits,
|
|
93
|
+
});
|
|
94
|
+
return value.service.beginScope({
|
|
95
|
+
runId,
|
|
96
|
+
moduleName: "evidence",
|
|
97
|
+
operationKey: "evidence.document.ocr",
|
|
98
|
+
runtimeKind: "document",
|
|
99
|
+
idempotencyKey,
|
|
100
|
+
invocationDigest: "c".repeat(64),
|
|
101
|
+
dataClassification: "sensitive",
|
|
102
|
+
deploymentIdentity:
|
|
103
|
+
"windy-deployment-v1_7db61d8e-e50d-4f8a-9f3f-9b7a1d932e01",
|
|
104
|
+
releaseDigest: `sha256:${"a".repeat(64)}`,
|
|
105
|
+
offersDigest: `sha256:${"b".repeat(64)}`,
|
|
106
|
+
policy,
|
|
107
|
+
context: guardContext(),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export async function clearPostgresArtifactTables(databaseUrl: string) {
|
|
112
|
+
const pool = new Pool({ connectionString: databaseUrl });
|
|
113
|
+
try {
|
|
114
|
+
await pool.query(`
|
|
115
|
+
truncate table
|
|
116
|
+
ai_output_artifacts,
|
|
117
|
+
ai_output_artifact_scopes,
|
|
118
|
+
file_upload_parts,
|
|
119
|
+
file_metadata,
|
|
120
|
+
file_upload_sessions
|
|
121
|
+
`);
|
|
122
|
+
} finally {
|
|
123
|
+
await pool.end();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function guardContext(): RequestGuardContext {
|
|
128
|
+
return {
|
|
129
|
+
requestId: "pg-output-artifact",
|
|
130
|
+
actor: {
|
|
131
|
+
id: "user-1",
|
|
132
|
+
type: "user",
|
|
133
|
+
name: "PG User",
|
|
134
|
+
roleCodes: ["analyst"],
|
|
135
|
+
permissionKeys: ["evidence.document.ocr.execute"],
|
|
136
|
+
scopeContext: buildScopeContext("user-1", undefined, [
|
|
137
|
+
{
|
|
138
|
+
id: "analyst",
|
|
139
|
+
code: "analyst",
|
|
140
|
+
dataScope: "self",
|
|
141
|
+
departmentIds: [],
|
|
142
|
+
},
|
|
143
|
+
]),
|
|
144
|
+
},
|
|
145
|
+
startedAt: new Date().toISOString(),
|
|
146
|
+
};
|
|
147
|
+
}
|