create-windy 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +288 -154
- package/package.json +2 -1
- package/template/.windy-template.json +2 -2
- package/template/apps/agent-server/README.md +25 -6
- package/template/apps/agent-server/src/southwind_agent_server/adk_adapter.py +15 -2
- package/template/apps/agent-server/src/southwind_agent_server/app.py +13 -34
- package/template/apps/agent-server/src/southwind_agent_server/config.py +49 -0
- package/template/apps/agent-server/src/southwind_agent_server/contracts.py +13 -0
- package/template/apps/agent-server/src/southwind_agent_server/engine_capacity.py +31 -0
- package/template/apps/agent-server/src/southwind_agent_server/fingerprint.py +5 -0
- package/template/apps/agent-server/src/southwind_agent_server/health_routes.py +50 -0
- package/template/apps/agent-server/src/southwind_agent_server/openai_engine.py +11 -2
- package/template/apps/agent-server/src/southwind_agent_server/openai_provider.py +3 -9
- package/template/apps/agent-server/src/southwind_agent_server/postgres_store.py +5 -0
- package/template/apps/agent-server/src/southwind_agent_server/readiness_pin.py +37 -0
- package/template/apps/agent-server/src/southwind_agent_server/run_admission.py +64 -0
- package/template/apps/agent-server/src/southwind_agent_server/run_capacity.py +59 -0
- package/template/apps/agent-server/src/southwind_agent_server/service.py +42 -43
- package/template/apps/agent-server/src/southwind_agent_server/service_errors.py +4 -0
- package/template/apps/agent-server/src/southwind_agent_server/service_execution.py +31 -0
- package/template/apps/agent-server/src/southwind_agent_server/service_tasks.py +34 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_catalog.py +11 -0
- package/template/apps/agent-server/src/southwind_agent_server/store.py +6 -0
- package/template/apps/agent-server/src/southwind_agent_server/vision_probe.py +87 -0
- package/template/apps/agent-server/src/southwind_agent_server/vision_requirement.py +28 -0
- package/template/apps/agent-server/src/southwind_agent_server/vlm_readiness.py +247 -0
- package/template/apps/agent-server/tests/test_api.py +16 -3
- package/template/apps/agent-server/tests/test_openai_provider.py +21 -4
- package/template/apps/agent-server/tests/test_postgres_store.py +3 -0
- package/template/apps/agent-server/tests/test_run_capacity.py +110 -0
- package/template/apps/agent-server/tests/test_runtime_factory_readiness.py +37 -0
- package/template/apps/agent-server/tests/test_sqlite_store.py +3 -0
- package/template/apps/agent-server/tests/test_vision_readiness_enforcement.py +72 -0
- package/template/apps/agent-server/tests/test_vlm_readiness.py +106 -0
- package/template/apps/document-server/src/southwind_document_server/adapter.py +117 -205
- package/template/apps/document-server/src/southwind_document_server/adapter_errors.py +13 -0
- package/template/apps/document-server/src/southwind_document_server/app.py +62 -14
- package/template/apps/document-server/src/southwind_document_server/artifacts.py +27 -0
- package/template/apps/document-server/src/southwind_document_server/config.py +96 -2
- package/template/apps/document-server/src/southwind_document_server/contracts.py +168 -13
- package/template/apps/document-server/src/southwind_document_server/fingerprint.py +128 -0
- package/template/apps/document-server/src/southwind_document_server/grants.py +81 -0
- package/template/apps/document-server/src/southwind_document_server/multipart_output.py +265 -0
- package/template/apps/document-server/src/southwind_document_server/output_validation.py +202 -0
- package/template/apps/document-server/src/southwind_document_server/progress.py +27 -0
- package/template/apps/document-server/src/southwind_document_server/readiness.py +280 -0
- package/template/apps/document-server/src/southwind_document_server/readiness_contracts.py +280 -0
- package/template/apps/document-server/src/southwind_document_server/readiness_http.py +87 -0
- package/template/apps/document-server/src/southwind_document_server/readiness_support.py +120 -0
- package/template/apps/document-server/src/southwind_document_server/request_validation.py +48 -0
- package/template/apps/document-server/src/southwind_document_server/service.py +297 -96
- package/template/apps/document-server/src/southwind_document_server/service_recovery.py +183 -0
- package/template/apps/document-server/src/southwind_document_server/sink.py +316 -0
- package/template/apps/document-server/src/southwind_document_server/store.py +301 -141
- package/template/apps/document-server/src/southwind_document_server/store_events.py +40 -0
- package/template/apps/document-server/src/southwind_document_server/store_models.py +62 -0
- package/template/apps/document-server/src/southwind_document_server/store_recovery.py +247 -0
- package/template/apps/document-server/src/southwind_document_server/store_schema.py +50 -0
- package/template/apps/document-server/tests/recovery_support.py +230 -0
- package/template/apps/document-server/tests/support.py +210 -0
- package/template/apps/document-server/tests/test_adapter.py +251 -0
- package/template/apps/document-server/tests/test_config.py +43 -0
- package/template/apps/document-server/tests/test_contracts.py +80 -0
- package/template/apps/document-server/tests/test_fingerprint.py +125 -0
- package/template/apps/document-server/tests/test_grants.py +46 -0
- package/template/apps/document-server/tests/test_handshake.py +154 -0
- package/template/apps/document-server/tests/test_integration.py +192 -0
- package/template/apps/document-server/tests/test_multipart_security.py +259 -0
- package/template/apps/document-server/tests/test_readiness.py +311 -0
- package/template/apps/document-server/tests/test_readiness_contracts.py +131 -0
- package/template/apps/document-server/tests/test_recovery.py +222 -0
- package/template/apps/document-server/tests/test_recovery_faults.py +101 -0
- package/template/apps/document-server/tests/test_recovery_races.py +283 -0
- package/template/apps/document-server/tests/test_service.py +16 -13
- package/template/apps/document-server/tests/test_service_artifacts.py +296 -0
- package/template/apps/document-server/tests/test_sink.py +253 -0
- package/template/apps/document-server/tests/test_store.py +199 -0
- package/template/apps/embedding-server/pyproject.toml +5 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/adapter.py +38 -2
- package/template/apps/embedding-server/src/southwind_embedding_server/app.py +111 -3
- package/template/apps/embedding-server/src/southwind_embedding_server/config.py +27 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/image_input.py +16 -5
- package/template/apps/embedding-server/src/southwind_embedding_server/run_cipher.py +31 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/run_service.py +130 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/run_store.py +250 -0
- package/template/apps/embedding-server/tests/test_adapter.py +25 -0
- package/template/apps/embedding-server/tests/test_run_http.py +185 -0
- package/template/apps/embedding-server/tests/test_run_service.py +200 -0
- package/template/apps/embedding-server/uv.lock +71 -0
- package/template/apps/server/Dockerfile +13 -0
- package/template/apps/server/package.json +1 -0
- package/template/apps/server/src/agent/drizzle-screenshot-intake-repository.integration.test.ts +283 -0
- package/template/apps/server/src/agent/drizzle-screenshot-intake-repository.ts +175 -0
- package/template/apps/server/src/agent/persistent-screenshot-intake-producer.ts +320 -0
- package/template/apps/server/src/agent/remote-runtime.ts +8 -1
- package/template/apps/server/src/agent/required-environment.ts +5 -0
- package/template/apps/server/src/agent/run-attach.ts +41 -0
- package/template/apps/server/src/agent/run-audit.ts +49 -0
- package/template/apps/server/src/agent/run-contracts.ts +6 -1
- package/template/apps/server/src/agent/run-facade.ts +66 -68
- package/template/apps/server/src/agent/run-route-input.ts +26 -1
- package/template/apps/server/src/agent/run-routes.ts +1 -0
- package/template/apps/server/src/agent/runtime-bootstrap-report.test.ts +1 -1
- package/template/apps/server/src/agent/runtime-bootstrap.ts +110 -60
- package/template/apps/server/src/agent/runtime-readiness-sources.test.ts +27 -0
- package/template/apps/server/src/agent/runtime-readiness-sources.ts +31 -0
- package/template/apps/server/src/agent/runtime-reporting-bootstrap.ts +40 -0
- package/template/apps/server/src/agent/screenshot-intake-authorization.ts +29 -0
- package/template/apps/server/src/agent/screenshot-intake-bootstrap.ts +61 -0
- package/template/apps/server/src/agent/screenshot-intake-durable.ts +53 -0
- package/template/apps/server/src/agent/screenshot-intake-errors.ts +9 -0
- package/template/apps/server/src/agent/screenshot-intake-producer.ts +41 -0
- package/template/apps/server/src/agent/screenshot-intake-record.ts +44 -0
- package/template/apps/server/src/agent/screenshot-intake-recovery.ts +106 -0
- package/template/apps/server/src/agent/screenshot-intake-repository.ts +64 -0
- package/template/apps/server/src/agent/screenshot-intake-reservation.ts +24 -0
- package/template/apps/server/src/agent/screenshot-intake-routes.ts +171 -0
- package/template/apps/server/src/agent/screenshot-intake-runtime-types.ts +6 -0
- package/template/apps/server/src/agent/screenshot-intake-sweep.ts +26 -0
- package/template/apps/server/src/agent/screenshot-intake-test-support.ts +87 -0
- package/template/apps/server/src/agent/screenshot-intake-v2-validation.ts +152 -0
- package/template/apps/server/src/agent/screenshot-intake-v2.test.ts +338 -0
- package/template/apps/server/src/agent/screenshot-intake-v2.ts +350 -0
- package/template/apps/server/src/agent/screenshot-png.ts +15 -0
- package/template/apps/server/src/agent/screenshot-run-binding.ts +34 -0
- package/template/apps/server/src/agent/unavailable-routes.ts +9 -0
- package/template/apps/server/src/agent/vision-facade.test.ts +98 -8
- package/template/apps/server/src/agent/vision-input.ts +5 -2
- package/template/apps/server/src/agent/vision-readiness-pin.ts +74 -0
- package/template/apps/server/src/agent/vision-readiness.ts +58 -0
- package/template/apps/server/src/ai-artifact/runtime-reference.test.ts +135 -0
- package/template/apps/server/src/ai-artifact/runtime.ts +134 -5
- package/template/apps/server/src/ai-output-artifact/cleanup.ts +214 -0
- package/template/apps/server/src/ai-output-artifact/contracts.ts +152 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-cleanup.ts +37 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-complete.ts +71 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-grant-cleanup.ts +45 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-grants.ts +109 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-mapping.ts +77 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-readiness.ts +46 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-repository.ts +350 -0
- package/template/apps/server/src/ai-output-artifact/drizzle-seal.ts +64 -0
- package/template/apps/server/src/ai-output-artifact/grant.ts +30 -0
- package/template/apps/server/src/ai-output-artifact/host-registry.ts +53 -0
- package/template/apps/server/src/ai-output-artifact/memory-cleanup.ts +47 -0
- package/template/apps/server/src/ai-output-artifact/memory-grants.ts +98 -0
- package/template/apps/server/src/ai-output-artifact/memory-readiness.ts +26 -0
- package/template/apps/server/src/ai-output-artifact/memory-repository.ts +348 -0
- package/template/apps/server/src/ai-output-artifact/policy.test.ts +67 -0
- package/template/apps/server/src/ai-output-artifact/policy.ts +125 -0
- package/template/apps/server/src/ai-output-artifact/postgres-test-support.ts +147 -0
- package/template/apps/server/src/ai-output-artifact/postgres.integration.test.ts +349 -0
- package/template/apps/server/src/ai-output-artifact/reference-codec.ts +128 -0
- package/template/apps/server/src/ai-output-artifact/repository-grant-invariants.test-support.ts +165 -0
- package/template/apps/server/src/ai-output-artifact/repository-invariants.test-support.ts +239 -0
- package/template/apps/server/src/ai-output-artifact/repository-invariants.test.ts +18 -0
- package/template/apps/server/src/ai-output-artifact/repository.ts +107 -0
- package/template/apps/server/src/ai-output-artifact/route-input.ts +173 -0
- package/template/apps/server/src/ai-output-artifact/routes-delete.test.ts +287 -0
- package/template/apps/server/src/ai-output-artifact/routes-grant.test.ts +116 -0
- package/template/apps/server/src/ai-output-artifact/routes-nonblocking-body.test.ts +136 -0
- package/template/apps/server/src/ai-output-artifact/routes-security.test.ts +176 -0
- package/template/apps/server/src/ai-output-artifact/routes-storage-error.test.ts +105 -0
- package/template/apps/server/src/ai-output-artifact/routes.test-support.ts +84 -0
- package/template/apps/server/src/ai-output-artifact/routes.test.ts +198 -0
- package/template/apps/server/src/ai-output-artifact/routes.ts +280 -0
- package/template/apps/server/src/ai-output-artifact/service-completion.ts +60 -0
- package/template/apps/server/src/ai-output-artifact/service-grants.test.ts +169 -0
- package/template/apps/server/src/ai-output-artifact/service-grants.ts +217 -0
- package/template/apps/server/src/ai-output-artifact/service-input.ts +175 -0
- package/template/apps/server/src/ai-output-artifact/service-read.ts +89 -0
- package/template/apps/server/src/ai-output-artifact/service-recovery.test.ts +238 -0
- package/template/apps/server/src/ai-output-artifact/service-support.ts +240 -0
- package/template/apps/server/src/ai-output-artifact/service.test.ts +283 -0
- package/template/apps/server/src/ai-output-artifact/service.ts +334 -0
- package/template/apps/server/src/ai-output-artifact/storage-recovery.ts +33 -0
- package/template/apps/server/src/ai-output-artifact/storage-writer.ts +103 -0
- package/template/apps/server/src/ai-output-artifact/test-support.ts +161 -0
- package/template/apps/server/src/ai-runtime-readiness/health-response.ts +92 -0
- package/template/apps/server/src/ai-runtime-readiness/operation-port-trust.test.ts +66 -0
- package/template/apps/server/src/ai-runtime-readiness/operation-port.test-support.ts +143 -0
- package/template/apps/server/src/ai-runtime-readiness/operation-port.test.ts +193 -0
- package/template/apps/server/src/ai-runtime-readiness/operation-port.ts +172 -0
- package/template/apps/server/src/ai-runtime-readiness/trust-store.ts +61 -0
- package/template/apps/server/src/app/ai-screenshot-intake-binding.ts +22 -0
- package/template/apps/server/src/app/document-output-artifact-bindings.ts +5 -0
- package/template/apps/server/src/app/speech-output-artifact-bindings.ts +5 -0
- package/template/apps/server/src/application-services.ts +9 -3
- package/template/apps/server/src/audit/redaction.ts +1 -0
- package/template/apps/server/src/audit/reliable-writer.test.ts +8 -0
- package/template/apps/server/src/auth/password-change-license-restriction.test.ts +156 -0
- package/template/apps/server/src/document/cancel-response.ts +33 -0
- package/template/apps/server/src/document/contracts.ts +6 -0
- package/template/apps/server/src/document/errors.ts +11 -0
- package/template/apps/server/src/document/facade-cancel.test.ts +226 -0
- package/template/apps/server/src/document/facade-cancel.ts +110 -0
- package/template/apps/server/src/document/facade-grant-handoff.test.ts +113 -0
- package/template/apps/server/src/document/facade-idempotency.test.ts +195 -0
- package/template/apps/server/src/document/facade-invocation.ts +46 -0
- package/template/apps/server/src/document/facade-output-artifact.test.ts +310 -0
- package/template/apps/server/src/document/facade-read-response.ts +116 -0
- package/template/apps/server/src/document/facade-readiness.test.ts +95 -0
- package/template/apps/server/src/document/facade-support.ts +297 -0
- package/template/apps/server/src/document/facade.ts +164 -173
- package/template/apps/server/src/document/output-artifact-composition.test.ts +64 -0
- package/template/apps/server/src/document/output-artifact-composition.ts +78 -0
- package/template/apps/server/src/document/output-artifact-fingerprint.contract.test.ts +110 -0
- package/template/apps/server/src/document/output-artifact-fingerprint.ts +150 -0
- package/template/apps/server/src/document/output-artifact-host-registry.ts +44 -0
- package/template/apps/server/src/document/output-artifact-host.test.ts +332 -0
- package/template/apps/server/src/document/output-artifact-host.ts +331 -0
- package/template/apps/server/src/document/output-artifact-manifest.test-support.ts +71 -0
- package/template/apps/server/src/document/output-artifact-publish.test-support.ts +48 -0
- package/template/apps/server/src/document/output-artifact-readiness-probe.ts +347 -0
- package/template/apps/server/src/document/output-artifact-readiness-timeout.ts +30 -0
- package/template/apps/server/src/document/output-artifact-readiness.test.ts +264 -0
- package/template/apps/server/src/document/output-artifact-readiness.ts +87 -0
- package/template/apps/server/src/document/output-artifact-route-composition.test.ts +27 -0
- package/template/apps/server/src/document/output-artifact-route-composition.ts +14 -0
- package/template/apps/server/src/document/output-artifact-runtime.test-support.ts +8 -0
- package/template/apps/server/src/document/output-artifact-runtime.test.ts +124 -0
- package/template/apps/server/src/document/output-artifact-runtime.ts +275 -0
- package/template/apps/server/src/document/output-artifact.test-support.ts +350 -0
- package/template/apps/server/src/document/remote-response.ts +162 -0
- package/template/apps/server/src/document/remote-runtime.test.ts +100 -4
- package/template/apps/server/src/document/remote-runtime.ts +37 -85
- package/template/apps/server/src/document/routes-read-response.test.ts +267 -0
- package/template/apps/server/src/document/routes.test.ts +109 -0
- package/template/apps/server/src/document/routes.ts +23 -14
- package/template/apps/server/src/embedding/audit.ts +46 -0
- package/template/apps/server/src/embedding/contracts.ts +13 -0
- package/template/apps/server/src/embedding/drizzle-run-binding-repository.integration.test.ts +100 -0
- package/template/apps/server/src/embedding/drizzle-run-binding-repository.ts +102 -0
- package/template/apps/server/src/embedding/facade-types.ts +18 -0
- package/template/apps/server/src/embedding/facade.ts +242 -111
- package/template/apps/server/src/embedding/operation-authorization.ts +23 -0
- package/template/apps/server/src/embedding/remote-runtime.test.ts +18 -0
- package/template/apps/server/src/embedding/remote-runtime.ts +77 -0
- package/template/apps/server/src/embedding/routes.test.ts +118 -0
- package/template/apps/server/src/embedding/routes.ts +98 -0
- package/template/apps/server/src/embedding/run-artifact.ts +18 -0
- package/template/apps/server/src/embedding/run-authorization.test.ts +133 -0
- package/template/apps/server/src/embedding/run-authorization.ts +91 -0
- package/template/apps/server/src/embedding/run-binding-repository.ts +75 -0
- package/template/apps/server/src/embedding/run-fingerprint.test.ts +52 -0
- package/template/apps/server/src/embedding/run-fingerprint.ts +39 -0
- package/template/apps/server/src/embedding/terminal-observer.test.ts +26 -0
- package/template/apps/server/src/embedding/terminal-observer.ts +44 -0
- package/template/apps/server/src/index.ts +38 -31
- package/template/apps/server/src/module-host/ai-operation-port.ts +3 -3
- package/template/apps/server/src/module-host/durable-context.ts +194 -16
- package/template/apps/server/src/module-host/durable-handler-registration.ts +1 -0
- package/template/apps/server/src/module-host/durable-storage-filesystem-restart.test.ts +265 -0
- package/template/apps/server/src/module-host/durable-storage-write.test.ts +345 -0
- package/template/apps/server/src/module-host/http-runtime.ts +25 -0
- package/template/apps/server/src/module-host/initialize-contracts.ts +18 -1
- package/template/apps/server/src/module-host/initialize.test.ts +18 -0
- package/template/apps/server/src/module-host/initialize.ts +42 -2
- package/template/apps/server/src/module-host/module-secret-audit-version.test.ts +73 -0
- package/template/apps/server/src/module-host/module-secret-binding-resolution.ts +60 -0
- package/template/apps/server/src/module-host/module-secret-durable.test.ts +206 -0
- package/template/apps/server/src/module-host/module-secret-port.test-support.ts +125 -0
- package/template/apps/server/src/module-host/module-secret-port.test.ts +161 -0
- package/template/apps/server/src/module-host/module-secret-port.ts +249 -0
- package/template/apps/server/src/module-host/module-secret-result.test.ts +324 -0
- package/template/apps/server/src/module-host/module-secret-result.ts +274 -0
- package/template/apps/server/src/module-host/module-secret-tool-boundary.test.ts +143 -0
- package/template/apps/server/src/module-host/project-composition.ts +1 -0
- package/template/apps/server/src/module-host/report-staging-port.ts +55 -0
- package/template/apps/server/src/module-host/report-staging-registration.test.ts +104 -0
- package/template/apps/server/src/module-host/request-context.ts +58 -1
- package/template/apps/server/src/module-host/route-declaration.ts +11 -4
- package/template/apps/server/src/module-host/route-installer.test-fixture.ts +246 -0
- package/template/apps/server/src/module-host/route-installer.test.ts +47 -211
- package/template/apps/server/src/module-host/route-installer.ts +192 -21
- package/template/apps/server/src/module-host/route-registration.test.ts +44 -4
- package/template/apps/server/src/module-host/runtime-composition.ts +2 -0
- package/template/apps/server/src/module-host/scoped-host.ts +84 -0
- package/template/apps/server/src/module-host/screenshot-artifact-ref.ts +91 -0
- package/template/apps/server/src/module-host/screenshot-intake-composition.test.ts +292 -0
- package/template/apps/server/src/module-host/screenshot-intake-deadline.ts +38 -0
- package/template/apps/server/src/module-host/screenshot-intake-plan.ts +75 -0
- package/template/apps/server/src/module-host/screenshot-intake-port.ts +297 -0
- package/template/apps/server/src/module-host/screenshot-intake-security.test.ts +311 -0
- package/template/apps/server/src/module-host/screenshot-intake-store.ts +76 -0
- package/template/apps/server/src/module-host/screenshot-intake-test-support.ts +68 -0
- package/template/apps/server/src/module-host/secret-bindings.test.ts +167 -0
- package/template/apps/server/src/module-host/secret-bindings.ts +184 -0
- package/template/apps/server/src/module-host/storage-authorization-binding.test.ts +242 -0
- package/template/apps/server/src/module-host/storage-port.test.ts +8 -1
- package/template/apps/server/src/module-host/storage-port.ts +84 -8
- package/template/apps/server/src/module-host/storage-restart-fixture.test-support.ts +242 -0
- package/template/apps/server/src/module-host/storage-restart-postgres.integration.test.ts +280 -0
- package/template/apps/server/src/module-host/storage-scope-drift-http.test.ts +68 -0
- package/template/apps/server/src/module-host/storage-scope.ts +52 -1
- package/template/apps/server/src/module-host/storage-stream-route.test.ts +282 -0
- package/template/apps/server/src/module-host/storage-write-error.test.ts +174 -0
- package/template/apps/server/src/module-host/storage-write-error.ts +62 -0
- package/template/apps/server/src/module-host/storage-write-port.test.ts +323 -0
- package/template/apps/server/src/module-host/storage-write-port.ts +320 -0
- package/template/apps/server/src/module-host/storage-write-unavailable.ts +21 -0
- package/template/apps/server/src/module-host/storage-writer-retention.test.ts +109 -0
- package/template/apps/server/src/module-host/user-directory-composition.test.ts +1 -0
- package/template/apps/server/src/module-preflight-secret.test.ts +79 -0
- package/template/apps/server/src/module-preflight.ts +5 -0
- package/template/apps/server/src/platform-http-runtime.ts +16 -4
- package/template/apps/server/src/report-staging/archive-frame-stream.test.ts +209 -0
- package/template/apps/server/src/report-staging/archive-frame-stream.ts +341 -0
- package/template/apps/server/src/report-staging/archive-process.test.ts +302 -0
- package/template/apps/server/src/report-staging/archive-process.ts +257 -0
- package/template/apps/server/src/report-staging/archive-volumes.ts +30 -0
- package/template/apps/server/src/report-staging/cancellation.ts +13 -0
- package/template/apps/server/src/report-staging/contracts.ts +94 -0
- package/template/apps/server/src/report-staging/drizzle-lifecycle.ts +278 -0
- package/template/apps/server/src/report-staging/drizzle-mapping.ts +140 -0
- package/template/apps/server/src/report-staging/drizzle-repository.integration.test.ts +346 -0
- package/template/apps/server/src/report-staging/drizzle-repository.ts +255 -0
- package/template/apps/server/src/report-staging/drizzle-seal.integration.test.ts +267 -0
- package/template/apps/server/src/report-staging/drizzle-seal.ts +177 -0
- package/template/apps/server/src/report-staging/filesystem-cleanup.test.ts +68 -0
- package/template/apps/server/src/report-staging/filesystem-cleanup.ts +102 -0
- package/template/apps/server/src/report-staging/filesystem-errors.ts +15 -0
- package/template/apps/server/src/report-staging/filesystem-identifiers.ts +19 -0
- package/template/apps/server/src/report-staging/filesystem-io.test.ts +85 -0
- package/template/apps/server/src/report-staging/filesystem-io.ts +206 -0
- package/template/apps/server/src/report-staging/filesystem-scan.ts +85 -0
- package/template/apps/server/src/report-staging/filesystem-store.ts +346 -0
- package/template/apps/server/src/report-staging/heartbeat.test.ts +47 -0
- package/template/apps/server/src/report-staging/heartbeat.ts +53 -0
- package/template/apps/server/src/report-staging/manifest-stream.ts +46 -0
- package/template/apps/server/src/report-staging/memory-repository.ts +256 -0
- package/template/apps/server/src/report-staging/metadata-catalog.ts +89 -0
- package/template/apps/server/src/report-staging/metadata-spool-paths.ts +195 -0
- package/template/apps/server/src/report-staging/metadata-spool-schema.ts +54 -0
- package/template/apps/server/src/report-staging/metadata-spool.test.ts +214 -0
- package/template/apps/server/src/report-staging/metadata-spool.ts +305 -0
- package/template/apps/server/src/report-staging/native/archive-frame-helper.c +309 -0
- package/template/apps/server/src/report-staging/path-policy.test.ts +127 -0
- package/template/apps/server/src/report-staging/path-policy.ts +263 -0
- package/template/apps/server/src/report-staging/repository-fence.test.ts +114 -0
- package/template/apps/server/src/report-staging/repository.ts +75 -0
- package/template/apps/server/src/report-staging/runtime.ts +31 -0
- package/template/apps/server/src/report-staging/sealed-file.test.ts +34 -0
- package/template/apps/server/src/report-staging/sealed-file.ts +137 -0
- package/template/apps/server/src/report-staging/service-input-limits.test.ts +62 -0
- package/template/apps/server/src/report-staging/service-input.ts +204 -0
- package/template/apps/server/src/report-staging/service-lifecycle.test.ts +132 -0
- package/template/apps/server/src/report-staging/service-read-fence.test.ts +37 -0
- package/template/apps/server/src/report-staging/service-read.ts +172 -0
- package/template/apps/server/src/report-staging/service-support.ts +149 -0
- package/template/apps/server/src/report-staging/service.test-fixture.ts +226 -0
- package/template/apps/server/src/report-staging/service.test.ts +314 -0
- package/template/apps/server/src/report-staging/service.ts +255 -0
- package/template/apps/server/src/report-staging/supervised-process.ts +194 -0
- package/template/apps/server/src/speech/contracts.ts +8 -0
- package/template/apps/server/src/speech/errors.ts +10 -0
- package/template/apps/server/src/speech/facade-contract.ts +49 -0
- package/template/apps/server/src/speech/facade-output.test.ts +299 -0
- package/template/apps/server/src/speech/facade-output.ts +298 -0
- package/template/apps/server/src/speech/facade-validation.ts +127 -0
- package/template/apps/server/src/speech/facade.ts +185 -151
- package/template/apps/server/src/speech/fingerprint.test.ts +42 -0
- package/template/apps/server/src/speech/fingerprint.ts +28 -0
- package/template/apps/server/src/speech/output-artifact-binding.test.ts +11 -0
- package/template/apps/server/src/speech/output-artifact-binding.ts +30 -0
- package/template/apps/server/src/speech/output-artifact-error.ts +9 -0
- package/template/apps/server/src/speech/output-artifact-host.test-support.ts +73 -0
- package/template/apps/server/src/speech/output-artifact-host.test.ts +302 -0
- package/template/apps/server/src/speech/output-artifact-host.ts +279 -0
- package/template/apps/server/src/speech/output-artifact-policy.ts +114 -0
- package/template/apps/server/src/speech/output-artifact-replay.ts +91 -0
- package/template/apps/server/src/speech/remote-response.ts +158 -0
- package/template/apps/server/src/speech/remote-runtime.test.ts +90 -0
- package/template/apps/server/src/speech/remote-runtime.ts +36 -78
- package/template/apps/server/src/speech/routes.ts +60 -16
- package/template/apps/server/src/startup-finalization.ts +52 -0
- package/template/apps/server/src/startup-preflight.ts +2 -0
- package/template/apps/server/src/startup-shutdown.test.ts +69 -0
- package/template/apps/server/src/startup-shutdown.ts +61 -0
- package/template/apps/server/src/storage/drizzle-upload-purge.ts +61 -0
- package/template/apps/server/src/storage/drizzle-upload-references.ts +23 -0
- package/template/apps/server/src/storage/drizzle-upload-repository.integration.test.ts +103 -0
- package/template/apps/server/src/storage/drizzle-upload-repository.ts +109 -14
- package/template/apps/server/src/storage/host-runtime.ts +15 -0
- package/template/apps/server/src/storage/routes-stream-cancellation.test.ts +154 -0
- package/template/apps/server/src/storage/routes.test.ts +13 -2
- package/template/apps/server/src/storage/routes.ts +57 -18
- package/template/apps/server/src/storage/runtime.ts +17 -4
- package/template/apps/server/src/system/route-types.ts +5 -1
- package/template/apps/server/src/system/system-resource-monitoring.test.ts +47 -0
- package/template/apps/server/src/system/system-resource-monitoring.ts +60 -10
- package/template/apps/server/src/work-order/routes.test.ts +1 -0
- package/template/apps/speech-server/src/southwind_speech_server/adapter.py +58 -17
- package/template/apps/speech-server/src/southwind_speech_server/app.py +24 -17
- package/template/apps/speech-server/src/southwind_speech_server/bounded_json.py +60 -0
- package/template/apps/speech-server/src/southwind_speech_server/config.py +122 -2
- package/template/apps/speech-server/src/southwind_speech_server/contracts.py +58 -0
- package/template/apps/speech-server/src/southwind_speech_server/errors.py +8 -0
- package/template/apps/speech-server/src/southwind_speech_server/normalizer.py +14 -0
- package/template/apps/speech-server/src/southwind_speech_server/output_artifact.py +190 -0
- package/template/apps/speech-server/src/southwind_speech_server/output_validation.py +54 -0
- package/template/apps/speech-server/src/southwind_speech_server/pin_cli.py +83 -0
- package/template/apps/speech-server/src/southwind_speech_server/readiness.py +266 -0
- package/template/apps/speech-server/src/southwind_speech_server/readiness_contracts.py +268 -0
- package/template/apps/speech-server/src/southwind_speech_server/readiness_http.py +91 -0
- package/template/apps/speech-server/src/southwind_speech_server/readiness_local.py +161 -0
- package/template/apps/speech-server/src/southwind_speech_server/readiness_support.py +106 -0
- package/template/apps/speech-server/src/southwind_speech_server/service.py +118 -13
- package/template/apps/speech-server/src/southwind_speech_server/store.py +7 -0
- package/template/apps/speech-server/tests/test_bounded_json.py +55 -0
- package/template/apps/speech-server/tests/test_config.py +22 -0
- package/template/apps/speech-server/tests/test_output_artifact.py +60 -0
- package/template/apps/speech-server/tests/test_output_validation.py +44 -0
- package/template/apps/speech-server/tests/test_readiness.py +315 -0
- package/template/apps/speech-server/tests/test_readiness_http.py +48 -0
- package/template/apps/speech-server/tests/test_readiness_local.py +43 -0
- package/template/apps/speech-server/tests/test_service.py +211 -36
- package/template/apps/web/src/pages/system/components/OperationGpuMonitor.vue +2 -1
- package/template/apps/web/src/pages/system/components/OperationGpuMonitor.webtest.ts +29 -0
- package/template/apps/web/src/pages/system/components/OperationServiceMonitor.vue +2 -1
- package/template/apps/web/src/pages/system/components/OperationServiceMonitor.webtest.ts +4 -1
- package/template/docker-compose.yml +38 -1
- package/template/docs/architecture/ai-runtime-readiness.md +498 -0
- package/template/docs/architecture/ai-runtime.md +20 -4
- package/template/docs/architecture/durable-jobs.md +54 -5
- package/template/docs/architecture/module-host.md +72 -9
- package/template/docs/architecture/module-manifest-composition.md +5 -2
- package/template/docs/architecture/module-secret-resolution.md +250 -0
- package/template/docs/architecture/object-storage.md +144 -3
- package/template/docs/architecture/report-staging.md +158 -0
- package/template/docs/architecture/server-module-interface.md +29 -0
- package/template/docs/architecture/speech-variants.md +45 -0
- package/template/docs/platform/agent-tools.md +16 -0
- package/template/docs/platform/document-ai-runtime.md +199 -17
- package/template/docs/platform/module-configuration.md +5 -0
- package/template/docs/platform/speech-ai-runtime.md +34 -5
- package/template/docs/platform/vision-ai-runtime.md +24 -0
- package/template/package.json +4 -1
- package/template/packages/ai-client/package.json +1 -1
- package/template/packages/ai-client/src/agent/client/client.ts +3 -0
- package/template/packages/ai-client/src/agent/client/index.ts +1 -0
- package/template/packages/ai-client/src/agent/client/screenshot.test.ts +40 -0
- package/template/packages/ai-client/src/agent/client/screenshot.ts +146 -0
- package/template/packages/ai-client/src/agent/client/types.ts +2 -0
- package/template/packages/ai-client/src/agent/contracts/runs.ts +1 -0
- package/template/packages/ai-client/src/embedding/client.test.ts +52 -0
- package/template/packages/ai-client/src/embedding/client.ts +69 -0
- package/template/packages/ai-client/src/embedding/contracts.ts +47 -0
- package/template/packages/ai-client/src/embedding/index.ts +1 -0
- package/template/packages/ai-client/src/embedding/run.ts +130 -0
- package/template/packages/ai-client/src/speech/client.test.ts +26 -0
- package/template/packages/ai-client/src/speech/client.ts +25 -1
- package/template/packages/ai-client/src/speech/contracts.ts +19 -0
- package/template/packages/config/package.json +1 -1
- package/template/packages/database/drizzle/0048_illegal_magneto.sql +11 -0
- package/template/packages/database/drizzle/0049_right_lenny_balinger.sql +79 -0
- package/template/packages/database/drizzle/0050_greedy_sister_grimm.sql +92 -0
- package/template/packages/database/drizzle/0051_lame_shockwave.sql +19 -0
- package/template/packages/database/drizzle/0052_tiresome_komodo.sql +1 -0
- package/template/packages/database/drizzle/0053_calm_victor_mancha.sql +1 -0
- package/template/packages/database/drizzle/0054_tough_thanos.sql +29 -0
- package/template/packages/database/drizzle/meta/0048_snapshot.json +8852 -0
- package/template/packages/database/drizzle/meta/0049_snapshot.json +9410 -0
- package/template/packages/database/drizzle/meta/0050_snapshot.json +10115 -0
- package/template/packages/database/drizzle/meta/0051_snapshot.json +10257 -0
- package/template/packages/database/drizzle/meta/0052_snapshot.json +10263 -0
- package/template/packages/database/drizzle/meta/0053_snapshot.json +10270 -0
- package/template/packages/database/drizzle/meta/0054_snapshot.json +10468 -0
- package/template/packages/database/drizzle/meta/_journal.json +49 -0
- package/template/packages/database/package.json +1 -1
- package/template/packages/database/src/agent-runtime-schema.test.ts +15 -0
- package/template/packages/database/src/ai-output-artifacts.test.ts +57 -0
- package/template/packages/database/src/schema/agent-runtime.ts +43 -0
- package/template/packages/database/src/schema/ai-output-artifacts.ts +182 -0
- package/template/packages/database/src/schema/embedding-runtime.ts +62 -0
- package/template/packages/database/src/schema/file-storage.ts +18 -0
- package/template/packages/database/src/schema/index.ts +3 -0
- package/template/packages/database/src/schema/report-staging.ts +212 -0
- package/template/packages/database/src/schema.test.ts +19 -0
- package/template/packages/jobs/package.json +1 -1
- package/template/packages/modules/index.ts +1 -0
- package/template/packages/modules/package.json +1 -1
- package/template/packages/modules/src/ai-operation-composition.test.ts +37 -0
- package/template/packages/modules/src/ai-operation-composition.ts +2 -0
- package/template/packages/modules/src/ai-operation-readiness-contract.test.ts +38 -0
- package/template/packages/modules/src/ai-operation-readiness-contract.ts +34 -0
- package/template/packages/modules/src/capability-audit-validation.ts +20 -0
- package/template/packages/modules/src/capability-guard-validation.ts +41 -0
- package/template/packages/modules/src/composition.ts +11 -0
- package/template/packages/modules/src/manifest.ts +40 -0
- package/template/packages/modules/src/secret-composition.test.ts +308 -0
- package/template/packages/modules/src/secret-composition.ts +176 -0
- package/template/packages/modules/src/system-api-control-plane.ts +17 -1
- package/template/packages/modules/src/system-module-catalog.test.ts +52 -0
- package/template/packages/modules/src/system-module-catalog.ts +1 -1
- package/template/packages/server-sdk/contracts/ai-runtime-readiness/v1/document-python-parity.json +12 -0
- package/template/packages/server-sdk/contracts/ai-runtime-readiness/v1/document.json +70 -0
- package/template/packages/server-sdk/contracts/ai-runtime-readiness/v1/embedding.json +68 -0
- package/template/packages/server-sdk/contracts/ai-runtime-readiness/v1/speech.json +80 -0
- package/template/packages/server-sdk/contracts/ai-runtime-readiness/v1/vlm.json +70 -0
- package/template/packages/server-sdk/contracts/document-runtime/v1/fingerprint-fixture.json +101 -0
- package/template/packages/server-sdk/index.ts +109 -0
- package/template/packages/server-sdk/package.json +22 -3
- package/template/packages/server-sdk/src/ai-runtime-readiness-capture.ts +168 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-digest.ts +49 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-identity.ts +16 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-keys.ts +23 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-limits.ts +141 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-projection.ts +326 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-requirement.ts +31 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-time.ts +16 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-trust.ts +84 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-validation-values.ts +147 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-validation.ts +299 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness-values.ts +42 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.adversarial-input.contract.test.ts +146 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.contract-support.ts +139 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.contract.test.ts +314 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.digest-safety.contract.test.ts +131 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.fail-closed.contract.test.ts +215 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.identity.contract.test.ts +138 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.input-safety.contract.test.ts +314 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.public-api.test.ts +18 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.python-parity.contract.test.ts +160 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.trust.contract.test.ts +135 -0
- package/template/packages/server-sdk/src/ai-runtime-readiness.ts +198 -0
- package/template/packages/server-sdk/src/ai-screenshot-intake-port.ts +58 -0
- package/template/packages/server-sdk/src/data-governance-registration.ts +1 -3
- package/template/packages/server-sdk/src/durable-handler.ts +12 -0
- package/template/packages/server-sdk/src/module-adapter.test.ts +10 -0
- package/template/packages/server-sdk/src/module-adapter.ts +3 -0
- package/template/packages/server-sdk/src/module-host.ts +8 -0
- package/template/packages/server-sdk/src/report-staging-context-compatibility.test.ts +25 -0
- package/template/packages/server-sdk/src/report-staging-port.ts +190 -0
- package/template/packages/server-sdk/src/request-context.ts +27 -1
- package/template/packages/server-sdk/src/route-definition.ts +6 -0
- package/template/packages/server-sdk/src/secret-binding.test.ts +66 -0
- package/template/packages/server-sdk/src/secret-binding.ts +54 -0
- package/template/packages/server-sdk/src/secret-context-compatibility.test.ts +77 -0
- package/template/packages/server-sdk/src/secret-port.ts +80 -0
- package/template/packages/server-sdk/src/storage-port.ts +129 -9
- package/template/packages/server-sdk/src/storage-v052-source-compatibility.test.ts +61 -0
- package/template/packages/shared/index.ts +2 -0
- package/template/packages/shared/package.json +4 -1
- package/template/packages/shared/src/ai-operation-readiness.test.ts +75 -0
- package/template/packages/shared/src/ai-operation-readiness.ts +170 -0
- package/template/packages/shared/src/license-catalog.ts +14 -9
- package/template/packages/shared/src/stable-key.ts +26 -0
- package/template/packages/shared/tsconfig.json +16 -0
- package/template/packages/storage/index.ts +2 -0
- package/template/packages/storage/package.json +1 -1
- package/template/packages/storage/src/in-memory-upload-repository.ts +105 -2
- package/template/packages/storage/src/local-file-blob-store.test.ts +58 -0
- package/template/packages/storage/src/local-file-blob-store.ts +5 -71
- package/template/packages/storage/src/local-file-blob-writer.ts +96 -0
- package/template/packages/storage/src/upload-abort-recovery.test.ts +234 -0
- package/template/packages/storage/src/upload-abort.ts +130 -0
- package/template/packages/storage/src/upload-cleanup-race.test.ts +207 -0
- package/template/packages/storage/src/upload-cleanup.ts +85 -0
- package/template/packages/storage/src/upload-completion.ts +52 -0
- package/template/packages/storage/src/upload-purge.test.ts +163 -0
- package/template/packages/storage/src/upload-purge.ts +261 -0
- package/template/packages/storage/src/upload-repository-v052-compatibility.test.ts +31 -0
- package/template/packages/storage/src/upload-repository.ts +61 -0
- package/template/packages/storage/src/upload-service-recovery.test.ts +296 -0
- package/template/packages/storage/src/upload-service.ts +138 -150
- package/template/packages/storage/src/upload-streams.ts +126 -30
- package/template/packages/storage/src/upload-types.ts +13 -0
- package/template/packages/storage/src/upload-validation.ts +127 -0
- package/template/scripts/provision-speech-readiness.ts +147 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import type {
|
|
3
|
+
AiRuntimeOfferV1,
|
|
4
|
+
AiRuntimeOffersDigestV1,
|
|
5
|
+
} from "./ai-runtime-readiness.js";
|
|
6
|
+
import { AI_RUNTIME_MAX_OFFERS_V1 } from "./ai-runtime-readiness.js";
|
|
7
|
+
import { captureAiRuntimeInputV1 } from "./ai-runtime-readiness-capture.js";
|
|
8
|
+
import { canonicalizeAiRuntimeOfferLimitsV1 } from "./ai-runtime-readiness-limits.js";
|
|
9
|
+
import { parseAiRuntimeOffersV1 } from "./ai-runtime-readiness-validation-values.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 固定 offers 的语义内容;数组型集合和 offer 顺序不影响摘要。
|
|
13
|
+
* Runtime、Registry 和 Host 必须复用此函数,不能各自发明 canonicalization。
|
|
14
|
+
* 输入必须满足公开 V1 边界;否则在 canonicalization 前抛出固定 TypeError。
|
|
15
|
+
*/
|
|
16
|
+
export function computeAiRuntimeOffersDigestV1(
|
|
17
|
+
offers: unknown,
|
|
18
|
+
): AiRuntimeOffersDigestV1 {
|
|
19
|
+
const captured = captureAiRuntimeInputV1(offers, AI_RUNTIME_MAX_OFFERS_V1);
|
|
20
|
+
const parsed = captured.ok ? parseAiRuntimeOffersV1(captured.value) : null;
|
|
21
|
+
if (!parsed) throw new TypeError("AI Runtime offers contract invalid");
|
|
22
|
+
return digestCanonicalOffers(parsed);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function digestCanonicalOffers(
|
|
26
|
+
offers: readonly AiRuntimeOfferV1[],
|
|
27
|
+
): AiRuntimeOffersDigestV1 {
|
|
28
|
+
const canonical = offers
|
|
29
|
+
.map((offer) => ({
|
|
30
|
+
variant: offer.variant,
|
|
31
|
+
capabilities: sorted(offer.capabilities),
|
|
32
|
+
inputModalities: sorted(offer.inputModalities),
|
|
33
|
+
outputModalities: sorted(offer.outputModalities),
|
|
34
|
+
limits: canonicalizeAiRuntimeOfferLimitsV1(offer.limits),
|
|
35
|
+
}))
|
|
36
|
+
.sort(({ variant: left }, { variant: right }) => compare(left, right));
|
|
37
|
+
const hash = createHash("sha256")
|
|
38
|
+
.update(JSON.stringify(canonical))
|
|
39
|
+
.digest("hex");
|
|
40
|
+
return `sha256:${hash}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function sorted<T extends string>(values: readonly T[]): readonly T[] {
|
|
44
|
+
return [...values].sort(compare);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function compare(left: string, right: string): number {
|
|
48
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
49
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const AI_RUNTIME_DEPLOYMENT_IDENTITY_PREFIX_V1 =
|
|
2
|
+
"windy-deployment-v1_" as const;
|
|
3
|
+
|
|
4
|
+
export type AiRuntimeDeploymentIdentityV1 =
|
|
5
|
+
`${typeof AI_RUNTIME_DEPLOYMENT_IDENTITY_PREFIX_V1}${string}`;
|
|
6
|
+
|
|
7
|
+
const deploymentIdentityPattern =
|
|
8
|
+
/^windy-deployment-v1_[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
9
|
+
|
|
10
|
+
export function parseAiRuntimeDeploymentIdentityV1(
|
|
11
|
+
value: unknown,
|
|
12
|
+
): AiRuntimeDeploymentIdentityV1 | null {
|
|
13
|
+
return typeof value === "string" && deploymentIdentityPattern.test(value)
|
|
14
|
+
? (value as AiRuntimeDeploymentIdentityV1)
|
|
15
|
+
: null;
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const stableKeyPattern = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/;
|
|
2
|
+
|
|
3
|
+
export function parseAiContractStableKeyV1(value: unknown): string | null {
|
|
4
|
+
return typeof value === "string" && stableKeyPattern.test(value)
|
|
5
|
+
? value
|
|
6
|
+
: null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function validAiContractStableKeyV1(value: unknown): value is string {
|
|
10
|
+
return typeof value === "string" && stableKeyPattern.test(value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function validAiContractStableKeyListV1(
|
|
14
|
+
values: unknown,
|
|
15
|
+
requireNonEmpty: boolean,
|
|
16
|
+
): values is readonly string[] {
|
|
17
|
+
return (
|
|
18
|
+
Array.isArray(values) &&
|
|
19
|
+
(!requireNonEmpty || values.length > 0) &&
|
|
20
|
+
values.every(validAiContractStableKeyV1) &&
|
|
21
|
+
new Set(values).size === values.length
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AiOperationRequiredLimitsV1,
|
|
3
|
+
AiOperationRequiredResourcesV1,
|
|
4
|
+
AiRuntimeOfferLimitsV1,
|
|
5
|
+
AiRuntimeOfferV1,
|
|
6
|
+
} from "./ai-runtime-readiness.js";
|
|
7
|
+
import {
|
|
8
|
+
isAiRuntimeRecordV1,
|
|
9
|
+
parseAiRuntimeNonNegativeIntegerV1,
|
|
10
|
+
parseAiRuntimePositiveIntegerV1,
|
|
11
|
+
} from "./ai-runtime-readiness-values.js";
|
|
12
|
+
|
|
13
|
+
interface OfferLimitRule {
|
|
14
|
+
readonly operationLimit: boolean;
|
|
15
|
+
readonly requiredInOffer: boolean;
|
|
16
|
+
readonly parse: (value: unknown) => number | null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const offerLimitRules = {
|
|
20
|
+
maxDurationSeconds: positiveOperationLimit(true),
|
|
21
|
+
maxInputBytes: positiveOperationLimit(true),
|
|
22
|
+
maxOutputBytes: positiveOperationLimit(true),
|
|
23
|
+
maxUnits: positiveOperationLimit(false),
|
|
24
|
+
maxMediaDurationSeconds: positiveOperationLimit(false),
|
|
25
|
+
maxArtifacts: positiveOperationLimit(false),
|
|
26
|
+
maxPixelsPerArtifact: positiveOperationLimit(false),
|
|
27
|
+
maxConcurrentRuns: {
|
|
28
|
+
operationLimit: false,
|
|
29
|
+
requiredInOffer: true,
|
|
30
|
+
parse: parseAiRuntimePositiveIntegerV1,
|
|
31
|
+
},
|
|
32
|
+
maxQueueDepth: {
|
|
33
|
+
operationLimit: false,
|
|
34
|
+
requiredInOffer: true,
|
|
35
|
+
parse: parseAiRuntimeNonNegativeIntegerV1,
|
|
36
|
+
},
|
|
37
|
+
} as const satisfies {
|
|
38
|
+
readonly [Key in keyof AiRuntimeOfferLimitsV1]-?: OfferLimitRule;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const orderedOfferLimitKeys = Object.keys(
|
|
42
|
+
offerLimitRules,
|
|
43
|
+
) as readonly (keyof AiRuntimeOfferLimitsV1)[];
|
|
44
|
+
|
|
45
|
+
const operationLimitKeys = orderedOfferLimitKeys.filter(
|
|
46
|
+
(key) => offerLimitRules[key].operationLimit,
|
|
47
|
+
) as readonly (keyof AiOperationRequiredLimitsV1)[];
|
|
48
|
+
|
|
49
|
+
export function parseAiRuntimeOfferLimitsV1(
|
|
50
|
+
raw: unknown,
|
|
51
|
+
): AiRuntimeOfferLimitsV1 | null {
|
|
52
|
+
if (!isAiRuntimeRecordV1(raw)) return null;
|
|
53
|
+
const parsed: Record<string, number> = {};
|
|
54
|
+
for (const key of orderedOfferLimitKeys) {
|
|
55
|
+
const rule = offerLimitRules[key];
|
|
56
|
+
const rawValue = raw[key];
|
|
57
|
+
if (rawValue === undefined && !rule.requiredInOffer) continue;
|
|
58
|
+
const value = rule.parse(rawValue);
|
|
59
|
+
if (value === null) return null;
|
|
60
|
+
parsed[key] = value;
|
|
61
|
+
}
|
|
62
|
+
return parsed as unknown as AiRuntimeOfferLimitsV1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function canonicalizeAiRuntimeOfferLimitsV1(
|
|
66
|
+
limits: AiRuntimeOfferLimitsV1,
|
|
67
|
+
): Readonly<Record<string, number>> {
|
|
68
|
+
const canonical: Record<string, number> = {};
|
|
69
|
+
for (const key of orderedOfferLimitKeys) {
|
|
70
|
+
const value = limits[key];
|
|
71
|
+
if (value !== undefined) canonical[key] = value;
|
|
72
|
+
}
|
|
73
|
+
return canonical;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function supportsAiOperationLimitsV1(
|
|
77
|
+
offer: AiRuntimeOfferV1,
|
|
78
|
+
required: AiOperationRequiredLimitsV1,
|
|
79
|
+
): boolean {
|
|
80
|
+
return operationLimitKeys.every((key) => {
|
|
81
|
+
const expected = required[key];
|
|
82
|
+
return expected === undefined || (offer.limits[key] ?? -1) >= expected;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function findAiOperationLimitMismatchV1(
|
|
87
|
+
offers: readonly AiRuntimeOfferV1[],
|
|
88
|
+
required: AiOperationRequiredLimitsV1,
|
|
89
|
+
): { key: string; required: number; available: number } {
|
|
90
|
+
for (const key of operationLimitKeys) {
|
|
91
|
+
const expected = required[key];
|
|
92
|
+
if (expected === undefined) continue;
|
|
93
|
+
const available = Math.max(
|
|
94
|
+
...offers.map(({ limits }) => limits[key] ?? -1),
|
|
95
|
+
);
|
|
96
|
+
if (available < expected) return { key, required: expected, available };
|
|
97
|
+
}
|
|
98
|
+
return { key: "combined", required: 1, available: 0 };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function supportsAiOperationResourcesV1(
|
|
102
|
+
offer: AiRuntimeOfferV1,
|
|
103
|
+
required: AiOperationRequiredResourcesV1,
|
|
104
|
+
): boolean {
|
|
105
|
+
return (
|
|
106
|
+
offer.limits.maxConcurrentRuns >= required.minConcurrentRuns &&
|
|
107
|
+
offer.limits.maxQueueDepth >= required.minQueueDepth
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function validAiOperationLimitsV1(
|
|
112
|
+
limits: unknown,
|
|
113
|
+
): limits is AiOperationRequiredLimitsV1 {
|
|
114
|
+
if (!isAiRuntimeRecordV1(limits)) return false;
|
|
115
|
+
return operationLimitKeys.every((key) => {
|
|
116
|
+
const rule = offerLimitRules[key];
|
|
117
|
+
const value = limits[key];
|
|
118
|
+
return (
|
|
119
|
+
(value === undefined && !rule.requiredInOffer) ||
|
|
120
|
+
rule.parse(value) !== null
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function validAiOperationResourcesV1(
|
|
126
|
+
resources: unknown,
|
|
127
|
+
): resources is AiOperationRequiredResourcesV1 {
|
|
128
|
+
return (
|
|
129
|
+
isAiRuntimeRecordV1(resources) &&
|
|
130
|
+
parseAiRuntimePositiveIntegerV1(resources.minConcurrentRuns) !== null &&
|
|
131
|
+
parseAiRuntimeNonNegativeIntegerV1(resources.minQueueDepth) !== null
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function positiveOperationLimit(requiredInOffer: boolean): OfferLimitRule {
|
|
136
|
+
return {
|
|
137
|
+
operationLimit: true,
|
|
138
|
+
requiredInOffer,
|
|
139
|
+
parse: parseAiRuntimePositiveIntegerV1,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AI_RUNTIME_MAX_PROBE_TTL_SECONDS,
|
|
3
|
+
AI_RUNTIME_READINESS_SCHEMA_VERSION,
|
|
4
|
+
type AiOperationReadinessRequirementV1,
|
|
5
|
+
type AiReadinessReasonCodeV1,
|
|
6
|
+
type AiReadinessReasonV1,
|
|
7
|
+
type AiRuntimeDeploymentV1,
|
|
8
|
+
type AiRuntimeOfferV1,
|
|
9
|
+
type ModuleAiOperationReadinessV1,
|
|
10
|
+
} from "./ai-runtime-readiness.js";
|
|
11
|
+
import { computeAiRuntimeOffersDigestV1 } from "./ai-runtime-readiness-digest.js";
|
|
12
|
+
import {
|
|
13
|
+
findAiOperationLimitMismatchV1,
|
|
14
|
+
supportsAiOperationLimitsV1,
|
|
15
|
+
supportsAiOperationResourcesV1,
|
|
16
|
+
} from "./ai-runtime-readiness-limits.js";
|
|
17
|
+
import {
|
|
18
|
+
safeAiOperationIdentityV1,
|
|
19
|
+
validAiOperationReadinessRequirementV1,
|
|
20
|
+
} from "./ai-runtime-readiness-requirement.js";
|
|
21
|
+
import { validCanonicalAiTimestampV1 } from "./ai-runtime-readiness-time.js";
|
|
22
|
+
import { parseAiRuntimeReadinessV1 } from "./ai-runtime-readiness-validation.js";
|
|
23
|
+
import {
|
|
24
|
+
acceptsTrustedRuntimeDegradationV1,
|
|
25
|
+
type AiRuntimeTrustedFullAttestationV1,
|
|
26
|
+
} from "./ai-runtime-readiness-trust.js";
|
|
27
|
+
|
|
28
|
+
export interface ProjectAiOperationReadinessOptionsV1 {
|
|
29
|
+
/** 测试或缓存调用可注入当前时间;省略时使用调用时 UTC。 */
|
|
30
|
+
readonly now?: string;
|
|
31
|
+
/** 只接受 Host 在先前完整匹配 expected deployment 后保存的独立证明。 */
|
|
32
|
+
readonly trustedFullAttestation?: AiRuntimeTrustedFullAttestationV1;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 把一个 deployment 的不受信任 readiness snapshot 收窄为 Operation 能力。
|
|
37
|
+
* 任何无法证明的条件都作为结构化 unavailable 返回,不抛远端错误。
|
|
38
|
+
*/
|
|
39
|
+
export function projectAiOperationReadinessV1(
|
|
40
|
+
requirement: AiOperationReadinessRequirementV1,
|
|
41
|
+
snapshot: unknown,
|
|
42
|
+
options: ProjectAiOperationReadinessOptionsV1 = {},
|
|
43
|
+
): ModuleAiOperationReadinessV1 {
|
|
44
|
+
const fallbackObservedAt = new Date().toISOString();
|
|
45
|
+
try {
|
|
46
|
+
return projectCapturedReadinessV1(
|
|
47
|
+
requirement,
|
|
48
|
+
snapshot,
|
|
49
|
+
options,
|
|
50
|
+
fallbackObservedAt,
|
|
51
|
+
);
|
|
52
|
+
} catch {
|
|
53
|
+
return invalidProjection(fallbackObservedAt);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function projectCapturedReadinessV1(
|
|
58
|
+
requirement: AiOperationReadinessRequirementV1,
|
|
59
|
+
snapshot: unknown,
|
|
60
|
+
options: ProjectAiOperationReadinessOptionsV1,
|
|
61
|
+
fallbackObservedAt: string,
|
|
62
|
+
): ModuleAiOperationReadinessV1 {
|
|
63
|
+
const now = options.now ?? fallbackObservedAt;
|
|
64
|
+
if (
|
|
65
|
+
!validCanonicalAiTimestampV1(now) ||
|
|
66
|
+
!validAiOperationReadinessRequirementV1(requirement)
|
|
67
|
+
) {
|
|
68
|
+
return unavailable(requirement, fallbackObservedAt, [
|
|
69
|
+
reason("CONTRACT_INVALID", false, "operation-requirement"),
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
const parsed = parseAiRuntimeReadinessV1(snapshot, now);
|
|
73
|
+
if (!parsed.ok) {
|
|
74
|
+
return unavailable(requirement, parsed.observedAt, parsed.reasons);
|
|
75
|
+
}
|
|
76
|
+
const runtime = parsed.value;
|
|
77
|
+
if (runtime.runtimeKind !== requirement.runtimeKind) {
|
|
78
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
79
|
+
reason(
|
|
80
|
+
"RUNTIME_KIND_MISMATCH",
|
|
81
|
+
false,
|
|
82
|
+
"runtimeKind",
|
|
83
|
+
requirement.runtimeKind,
|
|
84
|
+
runtime.runtimeKind,
|
|
85
|
+
),
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
if (runtime.status === "unavailable") {
|
|
89
|
+
return unavailable(
|
|
90
|
+
requirement,
|
|
91
|
+
runtime.observedAt,
|
|
92
|
+
runtime.unavailableReasons,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const probe = runtime.downstreamProbe;
|
|
96
|
+
if (
|
|
97
|
+
probe.deploymentIdentity !== runtime.deployment.identity ||
|
|
98
|
+
probe.releaseDigest !== runtime.deployment.releaseDigest ||
|
|
99
|
+
probe.offersDigest !== runtime.deployment.offersDigest
|
|
100
|
+
) {
|
|
101
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
102
|
+
reason("PROBE_ATTESTATION_MISMATCH", false, "downstream"),
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
if (
|
|
106
|
+
computeAiRuntimeOffersDigestV1(runtime.offers) !==
|
|
107
|
+
runtime.deployment.offersDigest
|
|
108
|
+
) {
|
|
109
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
110
|
+
reason("OFFERS_DIGEST_MISMATCH", false, "offers"),
|
|
111
|
+
]);
|
|
112
|
+
}
|
|
113
|
+
const checkedAt = Date.parse(probe.checkedAt);
|
|
114
|
+
const validUntil = Date.parse(probe.validUntil);
|
|
115
|
+
const observedAt = Date.parse(runtime.observedAt);
|
|
116
|
+
const nowValue = Date.parse(now);
|
|
117
|
+
if (checkedAt > nowValue || observedAt > nowValue) {
|
|
118
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
119
|
+
reason("PROBE_NOT_YET_VALID", true, "downstream"),
|
|
120
|
+
]);
|
|
121
|
+
}
|
|
122
|
+
if (observedAt < checkedAt) {
|
|
123
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
124
|
+
reason("CONTRACT_INVALID", false, "probe-chronology"),
|
|
125
|
+
]);
|
|
126
|
+
}
|
|
127
|
+
if (validUntil - checkedAt > AI_RUNTIME_MAX_PROBE_TTL_SECONDS * 1_000) {
|
|
128
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
129
|
+
reason("PROBE_TTL_EXCEEDED", false, "downstream"),
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
if (checkedAt >= validUntil) {
|
|
133
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
134
|
+
reason("CONTRACT_INVALID", false, "probe-chronology"),
|
|
135
|
+
]);
|
|
136
|
+
}
|
|
137
|
+
if (nowValue >= validUntil) {
|
|
138
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
139
|
+
reason("PROBE_STALE", true, "downstream"),
|
|
140
|
+
]);
|
|
141
|
+
}
|
|
142
|
+
const deploymentReason = compareDeployment(
|
|
143
|
+
requirement.expectedDeployment,
|
|
144
|
+
runtime.deployment,
|
|
145
|
+
);
|
|
146
|
+
const trustedDegradation =
|
|
147
|
+
deploymentReason &&
|
|
148
|
+
acceptsTrustedRuntimeDegradationV1(
|
|
149
|
+
requirement,
|
|
150
|
+
runtime.deployment,
|
|
151
|
+
runtime.offers,
|
|
152
|
+
options.trustedFullAttestation,
|
|
153
|
+
);
|
|
154
|
+
if (deploymentReason && !trustedDegradation) {
|
|
155
|
+
return unavailable(requirement, runtime.observedAt, [deploymentReason]);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let offers: readonly AiRuntimeOfferV1[] = runtime.offers;
|
|
159
|
+
if (requirement.variant) {
|
|
160
|
+
offers = offers.filter(({ variant }) => variant === requirement.variant);
|
|
161
|
+
if (!offers.length) {
|
|
162
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
163
|
+
reason("VARIANT_UNSUPPORTED", false, requirement.variant),
|
|
164
|
+
]);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
offers = offers.filter(({ capabilities }) =>
|
|
168
|
+
includesAll(capabilities, requirement.requiredCapabilities),
|
|
169
|
+
);
|
|
170
|
+
if (!offers.length) {
|
|
171
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
172
|
+
reason("CAPABILITY_MISSING", false, "operation.requiredCapabilities"),
|
|
173
|
+
]);
|
|
174
|
+
}
|
|
175
|
+
offers = offers.filter(({ inputModalities }) =>
|
|
176
|
+
includesAll(inputModalities, requirement.inputModalities),
|
|
177
|
+
);
|
|
178
|
+
if (!offers.length) {
|
|
179
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
180
|
+
reason(
|
|
181
|
+
"INPUT_MODALITY_UNSUPPORTED",
|
|
182
|
+
false,
|
|
183
|
+
requirement.inputModalities.join(","),
|
|
184
|
+
),
|
|
185
|
+
]);
|
|
186
|
+
}
|
|
187
|
+
offers = offers.filter(({ outputModalities }) =>
|
|
188
|
+
includesAll(outputModalities, requirement.outputModalities),
|
|
189
|
+
);
|
|
190
|
+
if (!offers.length) {
|
|
191
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
192
|
+
reason(
|
|
193
|
+
"OUTPUT_MODALITY_UNSUPPORTED",
|
|
194
|
+
false,
|
|
195
|
+
requirement.outputModalities.join(","),
|
|
196
|
+
),
|
|
197
|
+
]);
|
|
198
|
+
}
|
|
199
|
+
const beforeLimits = offers;
|
|
200
|
+
offers = offers.filter((offer) =>
|
|
201
|
+
supportsAiOperationLimitsV1(offer, requirement.limits),
|
|
202
|
+
);
|
|
203
|
+
if (!offers.length) {
|
|
204
|
+
const mismatch = findAiOperationLimitMismatchV1(
|
|
205
|
+
beforeLimits,
|
|
206
|
+
requirement.limits,
|
|
207
|
+
);
|
|
208
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
209
|
+
reason(
|
|
210
|
+
"LIMIT_INSUFFICIENT",
|
|
211
|
+
false,
|
|
212
|
+
mismatch.key,
|
|
213
|
+
mismatch.required,
|
|
214
|
+
mismatch.available,
|
|
215
|
+
),
|
|
216
|
+
]);
|
|
217
|
+
}
|
|
218
|
+
offers = offers.filter((offer) =>
|
|
219
|
+
supportsAiOperationResourcesV1(offer, requirement.resources),
|
|
220
|
+
);
|
|
221
|
+
if (!offers.length) {
|
|
222
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
223
|
+
reason("RESOURCE_LIMIT_INSUFFICIENT", false, "resources"),
|
|
224
|
+
]);
|
|
225
|
+
}
|
|
226
|
+
const [first, ...rest] = offers;
|
|
227
|
+
if (!first) {
|
|
228
|
+
return unavailable(requirement, runtime.observedAt, [
|
|
229
|
+
reason("CONTRACT_INVALID", false, "offers"),
|
|
230
|
+
]);
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
schemaVersion: AI_RUNTIME_READINESS_SCHEMA_VERSION,
|
|
234
|
+
operationKey: requirement.operationKey,
|
|
235
|
+
runtimeKind: requirement.runtimeKind,
|
|
236
|
+
observedAt: runtime.observedAt,
|
|
237
|
+
status: "ready",
|
|
238
|
+
validUntil: probe.validUntil,
|
|
239
|
+
deployment: trustedDegradation
|
|
240
|
+
? requirement.expectedDeployment
|
|
241
|
+
: runtime.deployment,
|
|
242
|
+
offers: [first, ...rest],
|
|
243
|
+
unavailableReasons: [],
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function compareDeployment(
|
|
248
|
+
expected: AiRuntimeDeploymentV1,
|
|
249
|
+
actual: AiRuntimeDeploymentV1,
|
|
250
|
+
): AiReadinessReasonV1 | null {
|
|
251
|
+
if (expected.key !== actual.key) {
|
|
252
|
+
return reason("DEPLOYMENT_KEY_MISMATCH", false, "deployment.key");
|
|
253
|
+
}
|
|
254
|
+
if (expected.identity !== actual.identity) {
|
|
255
|
+
return reason("DEPLOYMENT_IDENTITY_MISMATCH", false, "deployment.identity");
|
|
256
|
+
}
|
|
257
|
+
if (expected.releaseDigest !== actual.releaseDigest) {
|
|
258
|
+
return reason(
|
|
259
|
+
"RELEASE_DIGEST_MISMATCH",
|
|
260
|
+
false,
|
|
261
|
+
"deployment.releaseDigest",
|
|
262
|
+
expected.releaseDigest,
|
|
263
|
+
actual.releaseDigest,
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
return expected.offersDigest === actual.offersDigest
|
|
267
|
+
? null
|
|
268
|
+
: reason(
|
|
269
|
+
"OFFERS_DIGEST_MISMATCH",
|
|
270
|
+
false,
|
|
271
|
+
"deployment.offersDigest",
|
|
272
|
+
expected.offersDigest,
|
|
273
|
+
actual.offersDigest,
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function includesAll<T>(available: readonly T[], required: readonly T[]) {
|
|
278
|
+
return required.every((value) => available.includes(value));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function unavailable(
|
|
282
|
+
requirement: unknown,
|
|
283
|
+
observedAt: string,
|
|
284
|
+
reasons: readonly [AiReadinessReasonV1, ...AiReadinessReasonV1[]],
|
|
285
|
+
): ModuleAiOperationReadinessV1 {
|
|
286
|
+
const operation = safeAiOperationIdentityV1(requirement);
|
|
287
|
+
return {
|
|
288
|
+
schemaVersion: AI_RUNTIME_READINESS_SCHEMA_VERSION,
|
|
289
|
+
operationKey: operation.operationKey,
|
|
290
|
+
runtimeKind: operation.runtimeKind,
|
|
291
|
+
observedAt,
|
|
292
|
+
status: "unavailable",
|
|
293
|
+
deployment: null,
|
|
294
|
+
offers: [],
|
|
295
|
+
unavailableReasons: reasons,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function invalidProjection(observedAt: string): ModuleAiOperationReadinessV1 {
|
|
300
|
+
return {
|
|
301
|
+
schemaVersion: AI_RUNTIME_READINESS_SCHEMA_VERSION,
|
|
302
|
+
operationKey: "invalid-operation",
|
|
303
|
+
runtimeKind: "agent",
|
|
304
|
+
observedAt,
|
|
305
|
+
status: "unavailable",
|
|
306
|
+
deployment: null,
|
|
307
|
+
offers: [],
|
|
308
|
+
unavailableReasons: [{ code: "CONTRACT_INVALID", retryable: false }],
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function reason(
|
|
313
|
+
code: AiReadinessReasonCodeV1,
|
|
314
|
+
retryable: boolean,
|
|
315
|
+
subject?: string,
|
|
316
|
+
expected?: string | number,
|
|
317
|
+
actual?: string | number,
|
|
318
|
+
): AiReadinessReasonV1 {
|
|
319
|
+
return {
|
|
320
|
+
code,
|
|
321
|
+
retryable,
|
|
322
|
+
...(subject === undefined ? {} : { subject }),
|
|
323
|
+
...(expected === undefined ? {} : { expected }),
|
|
324
|
+
...(actual === undefined ? {} : { actual }),
|
|
325
|
+
};
|
|
326
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AI_RUNTIME_KINDS_V1,
|
|
3
|
+
type AiRuntimeKindV1,
|
|
4
|
+
} from "@southwind-ai/shared";
|
|
5
|
+
import { validAiContractStableKeyV1 } from "./ai-runtime-readiness-keys.js";
|
|
6
|
+
import { isAiRuntimeRecordV1 } from "./ai-runtime-readiness-values.js";
|
|
7
|
+
|
|
8
|
+
const runtimeKinds = new Set<AiRuntimeKindV1>(AI_RUNTIME_KINDS_V1);
|
|
9
|
+
export { validAiOperationReadinessRequirementV1 } from "@southwind-ai/shared";
|
|
10
|
+
|
|
11
|
+
export function safeAiOperationIdentityV1(requirement: unknown): {
|
|
12
|
+
operationKey: string;
|
|
13
|
+
runtimeKind: AiRuntimeKindV1;
|
|
14
|
+
} {
|
|
15
|
+
if (!isAiRuntimeRecordV1(requirement)) {
|
|
16
|
+
return {
|
|
17
|
+
operationKey: "invalid-operation",
|
|
18
|
+
runtimeKind: AI_RUNTIME_KINDS_V1[0],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
operationKey: validAiContractStableKeyV1(requirement.operationKey)
|
|
23
|
+
? requirement.operationKey
|
|
24
|
+
: "invalid-operation",
|
|
25
|
+
runtimeKind:
|
|
26
|
+
typeof requirement.runtimeKind === "string" &&
|
|
27
|
+
runtimeKinds.has(requirement.runtimeKind as AiRuntimeKindV1)
|
|
28
|
+
? (requirement.runtimeKind as AiRuntimeKindV1)
|
|
29
|
+
: AI_RUNTIME_KINDS_V1[0],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const canonicalUtcTimestampPattern =
|
|
2
|
+
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
3
|
+
|
|
4
|
+
export function parseCanonicalAiTimestampV1(value: unknown): string | null {
|
|
5
|
+
if (typeof value !== "string" || !canonicalUtcTimestampPattern.test(value)) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const parsed = new Date(value);
|
|
9
|
+
return !Number.isNaN(parsed.valueOf()) && parsed.toISOString() === value
|
|
10
|
+
? value
|
|
11
|
+
: null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function validCanonicalAiTimestampV1(value: unknown): boolean {
|
|
15
|
+
return parseCanonicalAiTimestampV1(value) !== null;
|
|
16
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AiOperationReadinessRequirementV1,
|
|
3
|
+
AiRuntimeDeploymentV1,
|
|
4
|
+
AiRuntimeOfferLimitsV1,
|
|
5
|
+
AiRuntimeOfferV1,
|
|
6
|
+
} from "./ai-runtime-readiness.js";
|
|
7
|
+
import { computeAiRuntimeOffersDigestV1 } from "./ai-runtime-readiness-digest.js";
|
|
8
|
+
|
|
9
|
+
export interface AiRuntimeTrustedFullAttestationV1 {
|
|
10
|
+
readonly deployment: AiRuntimeDeploymentV1;
|
|
11
|
+
readonly offers: readonly [AiRuntimeOfferV1, ...AiRuntimeOfferV1[]];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function acceptsTrustedRuntimeDegradationV1(
|
|
15
|
+
requirement: AiOperationReadinessRequirementV1,
|
|
16
|
+
currentDeployment: AiRuntimeDeploymentV1,
|
|
17
|
+
currentOffers: readonly AiRuntimeOfferV1[],
|
|
18
|
+
trusted: AiRuntimeTrustedFullAttestationV1 | undefined,
|
|
19
|
+
) {
|
|
20
|
+
if (
|
|
21
|
+
!trusted ||
|
|
22
|
+
!sameDeployment(trusted.deployment, requirement.expectedDeployment) ||
|
|
23
|
+
currentDeployment.key !== trusted.deployment.key ||
|
|
24
|
+
currentDeployment.identity !== trusted.deployment.identity ||
|
|
25
|
+
computeAiRuntimeOffersDigestV1(trusted.offers) !==
|
|
26
|
+
trusted.deployment.offersDigest
|
|
27
|
+
) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const fullByVariant = new Map(
|
|
31
|
+
trusted.offers.map((offer) => [offer.variant, offer]),
|
|
32
|
+
);
|
|
33
|
+
return currentOffers.every((offer) => {
|
|
34
|
+
const full = fullByVariant.get(offer.variant);
|
|
35
|
+
return Boolean(
|
|
36
|
+
full &&
|
|
37
|
+
subset(offer.capabilities, full.capabilities) &&
|
|
38
|
+
subset(offer.inputModalities, full.inputModalities) &&
|
|
39
|
+
subset(offer.outputModalities, full.outputModalities) &&
|
|
40
|
+
noLimitExpansion(offer.limits, full.limits),
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function sameDeployment(
|
|
46
|
+
left: AiRuntimeDeploymentV1,
|
|
47
|
+
right: AiRuntimeDeploymentV1,
|
|
48
|
+
) {
|
|
49
|
+
return (
|
|
50
|
+
left.key === right.key &&
|
|
51
|
+
left.identity === right.identity &&
|
|
52
|
+
left.releaseDigest === right.releaseDigest &&
|
|
53
|
+
left.offersDigest === right.offersDigest
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function subset<T>(current: readonly T[], full: readonly T[]) {
|
|
58
|
+
return current.every((value) => full.includes(value));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function noLimitExpansion(
|
|
62
|
+
current: AiRuntimeOfferLimitsV1,
|
|
63
|
+
full: AiRuntimeOfferLimitsV1,
|
|
64
|
+
) {
|
|
65
|
+
const keys = [
|
|
66
|
+
"maxDurationSeconds",
|
|
67
|
+
"maxInputBytes",
|
|
68
|
+
"maxOutputBytes",
|
|
69
|
+
"maxUnits",
|
|
70
|
+
"maxMediaDurationSeconds",
|
|
71
|
+
"maxArtifacts",
|
|
72
|
+
"maxPixelsPerArtifact",
|
|
73
|
+
"maxConcurrentRuns",
|
|
74
|
+
"maxQueueDepth",
|
|
75
|
+
] as const;
|
|
76
|
+
return keys.every((key) => {
|
|
77
|
+
const currentValue = current[key];
|
|
78
|
+
const fullValue = full[key];
|
|
79
|
+
return (
|
|
80
|
+
currentValue === undefined ||
|
|
81
|
+
(fullValue !== undefined && currentValue <= fullValue)
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
}
|