create-windy 0.3.2 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -9
- package/dist/cli.js +825 -117
- package/package.json +1 -1
- package/template/.agents/skills/windy-business-module/SKILL.md +16 -3
- package/template/.windy-template.json +2 -2
- package/template/AGENTS.md +4 -0
- package/template/README.md +18 -11
- package/template/_gitignore +1 -0
- package/template/apps/agent-server/README.md +2 -0
- package/template/apps/agent-server/pyproject.toml +8 -0
- package/template/apps/agent-server/src/southwind_agent_server/adk_adapter.py +87 -10
- package/template/apps/agent-server/src/southwind_agent_server/adk_model.py +18 -3
- package/template/apps/agent-server/src/southwind_agent_server/adk_tools.py +78 -11
- package/template/apps/agent-server/src/southwind_agent_server/app.py +120 -115
- package/template/apps/agent-server/src/southwind_agent_server/artifact_input.py +153 -0
- package/template/apps/agent-server/src/southwind_agent_server/config.py +29 -0
- package/template/apps/agent-server/src/southwind_agent_server/contracts.py +81 -1
- package/template/apps/agent-server/src/southwind_agent_server/deterministic.py +8 -0
- package/template/apps/agent-server/src/southwind_agent_server/engine.py +28 -0
- package/template/apps/agent-server/src/southwind_agent_server/fingerprint.py +41 -0
- package/template/apps/agent-server/src/southwind_agent_server/http_helpers.py +62 -0
- package/template/apps/agent-server/src/southwind_agent_server/lease.py +15 -0
- package/template/apps/agent-server/src/southwind_agent_server/multimodal.py +76 -0
- package/template/apps/agent-server/src/southwind_agent_server/openai_engine.py +112 -20
- package/template/apps/agent-server/src/southwind_agent_server/openai_provider.py +14 -1
- package/template/apps/agent-server/src/southwind_agent_server/postgres_store.py +329 -0
- package/template/apps/agent-server/src/southwind_agent_server/postgres_store_backend.py +332 -0
- package/template/apps/agent-server/src/southwind_agent_server/provider_governance.py +64 -3
- package/template/apps/agent-server/src/southwind_agent_server/runtime_factory.py +68 -0
- package/template/apps/agent-server/src/southwind_agent_server/service.py +218 -56
- package/template/apps/agent-server/src/southwind_agent_server/signal_events.py +36 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_catalog.py +107 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_schema.py +65 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_serialization.py +16 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_store.py +89 -57
- package/template/apps/agent-server/src/southwind_agent_server/store.py +105 -2
- package/template/apps/agent-server/src/southwind_agent_server/store_cipher.py +40 -0
- package/template/apps/agent-server/src/southwind_agent_server/telemetry.py +89 -0
- package/template/apps/agent-server/src/southwind_agent_server/tool_host.py +72 -0
- package/template/apps/agent-server/tests/test_adk_adapter.py +6 -2
- package/template/apps/agent-server/tests/test_api.py +24 -1
- package/template/apps/agent-server/tests/test_artifact_input.py +110 -0
- package/template/apps/agent-server/tests/test_config.py +4 -0
- package/template/apps/agent-server/tests/test_fingerprint.py +10 -0
- package/template/apps/agent-server/tests/test_multimodal.py +51 -0
- package/template/apps/agent-server/tests/test_openai_provider.py +6 -2
- package/template/apps/agent-server/tests/test_postgres_store.py +131 -0
- package/template/apps/agent-server/tests/test_provider_governance.py +61 -0
- package/template/apps/agent-server/tests/test_sqlite_store.py +95 -10
- package/template/apps/agent-server/tests/test_telemetry.py +25 -0
- package/template/apps/agent-server/tests/test_tool_approval.py +28 -0
- package/template/apps/agent-server/uv.lock +165 -0
- package/template/apps/document-server/Dockerfile +19 -0
- package/template/apps/document-server/pyproject.toml +43 -0
- package/template/apps/document-server/src/southwind_document_server/__init__.py +1 -0
- package/template/apps/document-server/src/southwind_document_server/adapter.py +337 -0
- package/template/apps/document-server/src/southwind_document_server/app.py +151 -0
- package/template/apps/document-server/src/southwind_document_server/config.py +94 -0
- package/template/apps/document-server/src/southwind_document_server/contracts.py +103 -0
- package/template/apps/document-server/src/southwind_document_server/service.py +149 -0
- package/template/apps/document-server/src/southwind_document_server/store.py +185 -0
- package/template/apps/document-server/tests/__init__.py +1 -0
- package/template/apps/document-server/tests/test_config.py +42 -0
- package/template/apps/document-server/tests/test_service.py +140 -0
- package/template/apps/document-server/uv.lock +430 -0
- package/template/apps/embedding-server/Dockerfile +17 -0
- package/template/apps/embedding-server/pyproject.toml +44 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/__init__.py +1 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/adapter.py +254 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/app.py +119 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/config.py +120 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/contracts.py +106 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/error.py +6 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/image_input.py +87 -0
- package/template/apps/embedding-server/tests/__init__.py +1 -0
- package/template/apps/embedding-server/tests/test_adapter.py +92 -0
- package/template/apps/embedding-server/tests/test_config.py +38 -0
- package/template/apps/embedding-server/uv.lock +449 -0
- package/template/apps/server/src/agent/background-operation-port.ts +37 -0
- package/template/apps/server/src/agent/background-operation.test.ts +231 -0
- package/template/apps/server/src/agent/background-operation.ts +252 -0
- package/template/apps/server/src/agent/drizzle-run-binding-repository.ts +114 -0
- package/template/apps/server/src/agent/execution-grants.ts +7 -1
- package/template/apps/server/src/agent/fake-runtime.test-support.ts +43 -0
- package/template/apps/server/src/agent/idempotency-key.test.ts +28 -0
- package/template/apps/server/src/agent/idempotency-key.ts +11 -0
- package/template/apps/server/src/agent/remote-runtime.test.ts +115 -1
- package/template/apps/server/src/agent/remote-runtime.ts +173 -5
- package/template/apps/server/src/agent/run-authorization.test-support.ts +9 -0
- package/template/apps/server/src/agent/run-authorization.test.ts +126 -0
- package/template/apps/server/src/agent/run-authorization.ts +180 -0
- package/template/apps/server/src/agent/run-binding-repository.ts +93 -0
- package/template/apps/server/src/agent/run-contracts.ts +88 -1
- package/template/apps/server/src/agent/run-definition-support.ts +58 -0
- package/template/apps/server/src/agent/run-errors.ts +25 -0
- package/template/apps/server/src/agent/run-facade.test.ts +57 -46
- package/template/apps/server/src/agent/run-facade.ts +185 -65
- package/template/apps/server/src/agent/run-release.ts +78 -0
- package/template/apps/server/src/agent/run-route-input.ts +169 -0
- package/template/apps/server/src/agent/run-routes.ts +63 -76
- package/template/apps/server/src/agent/runtime-bootstrap.ts +169 -13
- package/template/apps/server/src/agent/sandbox-client.ts +200 -0
- package/template/apps/server/src/agent/sandbox-protocol.ts +76 -0
- package/template/apps/server/src/agent/sandbox-registry.ts +205 -0
- package/template/apps/server/src/agent/sandbox-runtime.test.ts +137 -0
- package/template/apps/server/src/agent/sandbox-worker-server.ts +195 -0
- package/template/apps/server/src/agent/sandbox-worker.ts +12 -0
- package/template/apps/server/src/agent/tool-approval.test.ts +75 -0
- package/template/apps/server/src/agent/tool-approval.ts +115 -0
- package/template/apps/server/src/agent/tool-audit.ts +62 -0
- package/template/apps/server/src/agent/tool-host.test.ts +39 -11
- package/template/apps/server/src/agent/tool-host.ts +184 -17
- package/template/apps/server/src/agent/tool-registry.ts +52 -47
- package/template/apps/server/src/agent/vision-facade.test.ts +256 -0
- package/template/apps/server/src/agent/vision-input.ts +120 -0
- package/template/apps/server/src/ai-artifact/codec.test.ts +44 -0
- package/template/apps/server/src/ai-artifact/codec.ts +137 -0
- package/template/apps/server/src/ai-artifact/routes.ts +37 -0
- package/template/apps/server/src/ai-artifact/runtime.ts +205 -0
- package/template/apps/server/src/application-services.ts +62 -2
- package/template/apps/server/src/auth/reauthentication.test.ts +40 -0
- package/template/apps/server/src/auth/reauthentication.ts +19 -0
- package/template/apps/server/src/auth/runtime.ts +9 -1
- package/template/apps/server/src/data-access/context.ts +6 -4
- package/template/apps/server/src/data-access/scope-snapshot.ts +27 -0
- package/template/apps/server/src/data-governance/export/approval-port.ts +6 -3
- package/template/apps/server/src/data-governance/export/authorization-port.test.ts +23 -4
- package/template/apps/server/src/data-governance/export/authorization-port.ts +89 -25
- package/template/apps/server/src/data-governance/export/drizzle-repository.integration.test.ts +2 -0
- package/template/apps/server/src/data-governance/export/drizzle-repository.ts +1 -0
- package/template/apps/server/src/data-governance/export/job-runtime.test.ts +15 -4
- package/template/apps/server/src/data-governance/export/job-runtime.ts +68 -15
- package/template/apps/server/src/data-governance/export/ndjson-stream.ts +25 -6
- package/template/apps/server/src/data-governance/export/postgres-recovery.integration.test.ts +4 -2
- package/template/apps/server/src/data-governance/export/renderer-job-runtime.test.ts +235 -0
- package/template/apps/server/src/data-governance/export/renderer-runtime.ts +293 -0
- package/template/apps/server/src/data-governance/export/renderer-selection.test.ts +67 -0
- package/template/apps/server/src/data-governance/export/repository.test.ts +2 -0
- package/template/apps/server/src/data-governance/export/request-fingerprint.test.ts +13 -0
- package/template/apps/server/src/data-governance/export/request-fingerprint.ts +2 -0
- package/template/apps/server/src/data-governance/export/routes.ts +11 -1
- package/template/apps/server/src/data-governance/export/scope-snapshot.ts +6 -18
- package/template/apps/server/src/data-governance/export/service-support.ts +188 -0
- package/template/apps/server/src/data-governance/export/service.ts +90 -113
- package/template/apps/server/src/data-governance/export/source.ts +101 -0
- package/template/apps/server/src/data-governance/export/types.ts +27 -0
- package/template/apps/server/src/document/contracts.ts +76 -0
- package/template/apps/server/src/document/facade.ts +339 -0
- package/template/apps/server/src/document/remote-runtime.test.ts +96 -0
- package/template/apps/server/src/document/remote-runtime.ts +223 -0
- package/template/apps/server/src/document/routes.ts +193 -0
- package/template/apps/server/src/embedding/contracts.ts +83 -0
- package/template/apps/server/src/embedding/error.ts +10 -0
- package/template/apps/server/src/embedding/facade.ts +217 -0
- package/template/apps/server/src/embedding/input.ts +172 -0
- package/template/apps/server/src/embedding/remote-runtime.test.ts +66 -0
- package/template/apps/server/src/embedding/remote-runtime.ts +218 -0
- package/template/apps/server/src/embedding/routes.ts +152 -0
- package/template/apps/server/src/index.ts +40 -43
- package/template/apps/server/src/jobs/artifact-service.test.ts +14 -2
- package/template/apps/server/src/jobs/artifact-service.ts +10 -0
- package/template/apps/server/src/jobs/drizzle-execution-repository.ts +17 -18
- package/template/apps/server/src/jobs/drizzle-execution.integration.test.ts +19 -1
- package/template/apps/server/src/jobs/drizzle-mappers.ts +4 -1
- package/template/apps/server/src/jobs/drizzle-recovery-repository.ts +49 -2
- package/template/apps/server/src/jobs/drizzle-repository.ts +1 -0
- package/template/apps/server/src/jobs/execution-repository.ts +17 -0
- package/template/apps/server/src/jobs/execution.test.ts +34 -0
- package/template/apps/server/src/jobs/in-memory-control.ts +135 -0
- package/template/apps/server/src/jobs/in-memory-execution.ts +34 -65
- package/template/apps/server/src/jobs/legacy-service-runtime.ts +5 -2
- package/template/apps/server/src/jobs/repository.ts +3 -0
- package/template/apps/server/src/jobs/worker.ts +80 -41
- package/template/apps/server/src/module-host/ai-operation-port.ts +170 -0
- package/template/apps/server/src/module-host/durable-context.test.ts +312 -0
- package/template/apps/server/src/module-host/durable-context.ts +124 -0
- package/template/apps/server/src/module-host/durable-handler-registration.ts +72 -0
- package/template/apps/server/src/module-host/governed-export-route-support.ts +171 -0
- package/template/apps/server/src/module-host/governed-export-routes.test.ts +327 -0
- package/template/apps/server/src/module-host/governed-export-routes.ts +238 -0
- package/template/apps/server/src/module-host/governed-renderer-registration.test.ts +247 -0
- package/template/apps/server/src/module-host/governed-resource-routes.ts +331 -0
- package/template/apps/server/src/module-host/governed-resources.test.ts +344 -0
- package/template/apps/server/src/module-host/governed-resources.ts +203 -0
- package/template/apps/server/src/module-host/http-runtime.ts +95 -0
- package/template/apps/server/src/module-host/initialize-contracts.ts +14 -0
- package/template/apps/server/src/module-host/initialize.test.ts +49 -1
- package/template/apps/server/src/module-host/initialize.ts +39 -16
- package/template/apps/server/src/module-host/job-port.test.ts +262 -0
- package/template/apps/server/src/module-host/job-port.ts +334 -0
- package/template/apps/server/src/module-host/request-context.test.ts +88 -2
- package/template/apps/server/src/module-host/request-context.ts +56 -22
- package/template/apps/server/src/module-host/route-installer.test.ts +10 -0
- package/template/apps/server/src/module-host/route-installer.ts +36 -1
- package/template/apps/server/src/module-host/sandbox-tool-registration.ts +42 -0
- package/template/apps/server/src/module-host/tool-handlers.ts +67 -31
- package/template/apps/server/src/module-host.ts +1 -0
- package/template/apps/server/src/module-runtime-validation.ts +7 -3
- package/template/apps/server/src/speech/contracts.ts +76 -0
- package/template/apps/server/src/speech/facade.ts +316 -0
- package/template/apps/server/src/speech/remote-runtime.test.ts +88 -0
- package/template/apps/server/src/speech/remote-runtime.ts +227 -0
- package/template/apps/server/src/speech/routes.ts +180 -0
- package/template/apps/server/src/system/actor.ts +39 -0
- package/template/apps/server/src/system/route-helpers.ts +1 -0
- package/template/apps/server/src/workflow/service.ts +2 -1
- package/template/apps/speech-server/Dockerfile +22 -0
- package/template/apps/speech-server/pyproject.toml +43 -0
- package/template/apps/speech-server/src/southwind_speech_server/__init__.py +1 -0
- package/template/apps/speech-server/src/southwind_speech_server/adapter.py +249 -0
- package/template/apps/speech-server/src/southwind_speech_server/app.py +183 -0
- package/template/apps/speech-server/src/southwind_speech_server/config.py +100 -0
- package/template/apps/speech-server/src/southwind_speech_server/contracts.py +103 -0
- package/template/apps/speech-server/src/southwind_speech_server/errors.py +6 -0
- package/template/apps/speech-server/src/southwind_speech_server/normalizer.py +108 -0
- package/template/apps/speech-server/src/southwind_speech_server/output_validation.py +128 -0
- package/template/apps/speech-server/src/southwind_speech_server/service.py +162 -0
- package/template/apps/speech-server/src/southwind_speech_server/store.py +209 -0
- package/template/apps/speech-server/tests/__init__.py +1 -0
- package/template/apps/speech-server/tests/test_config.py +33 -0
- package/template/apps/speech-server/tests/test_service.py +154 -0
- package/template/apps/speech-server/uv.lock +430 -0
- package/template/apps/web/src/app/business-routes.ts +22 -0
- package/template/apps/web/src/components/common/AccessSnapshotBoundary.vue +112 -0
- package/template/apps/web/src/components/common/AccessSnapshotBoundary.webtest.ts +130 -0
- package/template/apps/web/src/components/common/AccessSnapshotNotice.vue +117 -0
- package/template/apps/web/src/components/common/FormDialog.vue +6 -0
- package/template/apps/web/src/components/common/ModalLayout.webtest.ts +13 -0
- package/template/apps/web/src/composables/access-snapshot-change.ts +131 -0
- package/template/apps/web/src/composables/access-snapshot-change.webtest.ts +103 -0
- package/template/apps/web/src/composables/useAccessSnapshot.ts +48 -2
- package/template/apps/web/src/composables/useAccessSnapshot.webtest.ts +54 -0
- package/template/apps/web/src/composables/useAccessSnapshotMonitor.ts +42 -0
- package/template/apps/web/src/layout/AppShell.vue +28 -25
- package/template/apps/web/src/layout/AppShell.webtest.ts +1 -0
- package/template/apps/web/src/router/business-routes.ts +68 -0
- package/template/apps/web/src/router/business-routes.webtest.ts +85 -0
- package/template/apps/web/src/router/index.ts +7 -0
- package/template/apps/web/src/router/shared-scaffold-neutrality.webtest.ts +12 -0
- package/template/apps/web/src/services/access-api.ts +5 -1
- package/template/apps/web/src/services/access-api.webtest.ts +35 -0
- package/template/docker-compose.yml +127 -0
- package/template/docs/architecture/ai-egress.md +12 -9
- package/template/docs/architecture/ai-runtime.md +23 -11
- package/template/docs/architecture/durable-jobs.md +25 -3
- package/template/docs/architecture/foundation-infrastructure.md +163 -0
- package/template/docs/architecture/module-host.md +115 -0
- package/template/docs/architecture/server-module-interface.md +39 -0
- package/template/docs/architecture/web-access-snapshot-resilience.md +60 -0
- package/template/docs/development/business-web-routes.md +66 -0
- package/template/docs/development/custom-login-page.md +3 -3
- package/template/docs/development/module-lifecycle.md +71 -0
- package/template/docs/operations/observability.md +5 -1
- package/template/docs/platform/agent-runtime.md +21 -11
- package/template/docs/platform/agent-tool-sandbox.md +58 -0
- package/template/docs/platform/agent-tools.md +5 -0
- package/template/docs/platform/document-ai-runtime.md +204 -0
- package/template/docs/platform/governed-export-renderers.md +132 -0
- package/template/docs/platform/navigation-registry.md +5 -0
- package/template/docs/platform/organization-membership.md +2 -1
- package/template/docs/platform/speech-ai-runtime.md +156 -0
- package/template/docs/platform/system-crud-api.md +7 -1
- package/template/docs/platform/vision-ai-runtime.md +97 -0
- package/template/docs/platform/web-system-crud.md +6 -0
- package/template/package.json +16 -2
- package/template/packages/ai-client/index.ts +4 -0
- package/template/packages/ai-client/package.json +5 -2
- package/template/packages/ai-client/src/agent/client/artifact.ts +26 -0
- package/template/packages/ai-client/src/agent/client/attach.test.ts +124 -0
- package/template/packages/ai-client/src/agent/client/client.ts +119 -7
- package/template/packages/ai-client/src/agent/client/run.ts +14 -0
- package/template/packages/ai-client/src/agent/client/types.ts +18 -0
- package/template/packages/ai-client/src/agent/client/vision.test.ts +53 -0
- package/template/packages/ai-client/src/agent/contracts/contracts.test.ts +1 -0
- package/template/packages/ai-client/src/agent/contracts/events.ts +33 -0
- package/template/packages/ai-client/src/agent/contracts/runs.ts +71 -0
- package/template/packages/ai-client/src/agent/index.ts +1 -0
- package/template/packages/ai-client/src/artifact-ref.ts +8 -0
- package/template/packages/ai-client/src/document/client.test.ts +114 -0
- package/template/packages/ai-client/src/document/client.ts +134 -0
- package/template/packages/ai-client/src/document/contracts.ts +152 -0
- package/template/packages/ai-client/src/document/error.ts +43 -0
- package/template/packages/ai-client/src/document/index.ts +3 -0
- package/template/packages/ai-client/src/document/run.ts +104 -0
- package/template/packages/ai-client/src/document/validation.ts +115 -0
- package/template/packages/ai-client/src/embedding/client.test.ts +77 -0
- package/template/packages/ai-client/src/embedding/client.ts +96 -0
- package/template/packages/ai-client/src/embedding/contracts.ts +46 -0
- package/template/packages/ai-client/src/embedding/error.ts +61 -0
- package/template/packages/ai-client/src/embedding/index.ts +3 -0
- package/template/packages/ai-client/src/embedding/validation.ts +117 -0
- package/template/packages/ai-client/src/speech/client.test.ts +135 -0
- package/template/packages/ai-client/src/speech/client.ts +104 -0
- package/template/packages/ai-client/src/speech/contracts.ts +129 -0
- package/template/packages/ai-client/src/speech/error.ts +43 -0
- package/template/packages/ai-client/src/speech/index.ts +3 -0
- package/template/packages/ai-client/src/speech/run.ts +133 -0
- package/template/packages/ai-client/src/speech/validation.ts +132 -0
- package/template/packages/config/package.json +2 -2
- package/template/packages/database/drizzle/0039_early_ezekiel_stane.sql +1 -0
- package/template/packages/database/drizzle/0040_colossal_baron_strucker.sql +63 -0
- package/template/packages/database/drizzle/0041_yummy_prowler.sql +21 -0
- package/template/packages/database/drizzle/0042_puzzling_rumiko_fujikawa.sql +27 -0
- package/template/packages/database/drizzle/meta/0039_snapshot.json +7755 -0
- package/template/packages/database/drizzle/meta/0040_snapshot.json +8150 -0
- package/template/packages/database/drizzle/meta/0041_snapshot.json +8323 -0
- package/template/packages/database/drizzle/meta/0042_snapshot.json +8541 -0
- package/template/packages/database/drizzle/meta/_journal.json +28 -0
- package/template/packages/database/package.json +2 -2
- package/template/packages/database/src/agent-runtime-schema.test.ts +54 -0
- package/template/packages/database/src/schema/agent-runtime.ts +149 -0
- package/template/packages/database/src/schema/common.ts +2 -14
- package/template/packages/database/src/schema/durable-jobs.ts +5 -0
- package/template/packages/database/src/schema/governed-exports.ts +17 -5
- package/template/packages/database/src/schema/index.ts +3 -0
- package/template/packages/database/src/schema-durable-recovery.test.ts +31 -0
- package/template/packages/database/src/schema-governed-exports.test.ts +21 -1
- package/template/packages/database/src/schema.test.ts +6 -23
- package/template/packages/jobs/package.json +3 -2
- package/template/packages/jobs/src/handlers.test.ts +13 -0
- package/template/packages/jobs/src/handlers.ts +7 -1
- package/template/packages/jobs/src/types.ts +4 -0
- package/template/packages/modules/package.json +2 -2
- package/template/packages/modules/src/ai-operation-composition.test-support.ts +165 -0
- package/template/packages/modules/src/ai-operation-composition.test.ts +91 -127
- package/template/packages/modules/src/ai-operation-composition.ts +59 -1
- package/template/packages/modules/src/manifest.ts +25 -1
- package/template/packages/modules/src/tool-composition.ts +18 -0
- package/template/packages/server-sdk/index.ts +50 -0
- package/template/packages/server-sdk/package.json +10 -4
- package/template/packages/server-sdk/src/ai-artifact-port.ts +34 -0
- package/template/packages/server-sdk/src/ai-operation-port.ts +65 -0
- package/template/packages/server-sdk/src/ai-operation-registration.ts +42 -1
- package/template/packages/server-sdk/src/background-ai-port.ts +43 -0
- package/template/packages/server-sdk/src/data-governance-registration.ts +116 -0
- package/template/packages/server-sdk/src/durable-handler.ts +29 -0
- package/template/packages/server-sdk/src/jobs-port.ts +69 -0
- package/template/packages/server-sdk/src/module-host.ts +16 -2
- package/template/packages/server-sdk/src/request-context.ts +6 -2
- package/template/packages/server-sdk/src/sandbox-tool.ts +21 -0
- package/template/packages/server-sdk/src/tool-registration.ts +2 -0
- package/template/packages/shared/package.json +1 -1
- package/template/packages/shared/src/rbac.ts +30 -0
|
@@ -7,23 +7,26 @@ import type {
|
|
|
7
7
|
ModuleToolInput,
|
|
8
8
|
ModuleToolResult,
|
|
9
9
|
} from "@southwind-ai/server-sdk";
|
|
10
|
-
import type {
|
|
10
|
+
import type { FeatureFlagDefinition } from "@southwind-ai/shared";
|
|
11
11
|
import Ajv, { type ValidateFunction } from "ajv";
|
|
12
12
|
import { evaluateAccessGuards } from "../access-guards.js";
|
|
13
13
|
import { isServerScopeContext } from "../data-access/context.js";
|
|
14
|
-
import {
|
|
14
|
+
import type { RequestGuardContext } from "../guards.js";
|
|
15
15
|
import { findFeature } from "../route-guards.js";
|
|
16
16
|
import type { createServerRuntime } from "../runtime.js";
|
|
17
|
+
import { sandboxFailureEvent, toolEvent, toolJsonBytes } from "./tool-audit.js";
|
|
17
18
|
|
|
18
19
|
type ServerRuntime = ReturnType<typeof createServerRuntime>;
|
|
19
20
|
|
|
20
21
|
export interface PlatformToolExecutionContext {
|
|
21
22
|
readonly guardContext: RequestGuardContext;
|
|
23
|
+
readonly toolCallId?: string;
|
|
22
24
|
readonly signal: AbortSignal;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
export interface PlatformToolHandlerRegistration {
|
|
26
28
|
readonly scopeMode: "platform" | "request";
|
|
29
|
+
readonly executionMode?: "host" | "sandbox";
|
|
27
30
|
execute(
|
|
28
31
|
input: ModuleToolInput,
|
|
29
32
|
context: PlatformToolExecutionContext,
|
|
@@ -92,6 +95,10 @@ export class GovernedToolRegistry {
|
|
|
92
95
|
return [...this.#tools.values()].map(({ definition }) => definition);
|
|
93
96
|
}
|
|
94
97
|
|
|
98
|
+
definition(key: string): RegisteredTool | undefined {
|
|
99
|
+
return this.#tools.get(key)?.definition;
|
|
100
|
+
}
|
|
101
|
+
|
|
95
102
|
async allowed(key: string, context: RequestGuardContext): Promise<boolean> {
|
|
96
103
|
const tool = this.#tools.get(key);
|
|
97
104
|
if (!tool) return false;
|
|
@@ -112,6 +119,7 @@ export class GovernedToolRegistry {
|
|
|
112
119
|
key: string,
|
|
113
120
|
rawInput: ModuleToolInput,
|
|
114
121
|
context: RequestGuardContext,
|
|
122
|
+
toolCallId = context.requestId,
|
|
115
123
|
): Promise<ModuleToolResult> {
|
|
116
124
|
const tool = this.#tools.get(key);
|
|
117
125
|
if (!tool) {
|
|
@@ -150,25 +158,47 @@ export class GovernedToolRegistry {
|
|
|
150
158
|
validationMessage(tool.validateInput),
|
|
151
159
|
);
|
|
152
160
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
let result: ModuleToolResult;
|
|
162
|
+
try {
|
|
163
|
+
result = await executeWithTimeout(
|
|
164
|
+
tool,
|
|
165
|
+
input,
|
|
166
|
+
{
|
|
167
|
+
guardContext: context,
|
|
168
|
+
toolCallId,
|
|
169
|
+
signal: AbortSignal.timeout(
|
|
170
|
+
tool.definition.limits.maxDurationSeconds * 1_000,
|
|
171
|
+
),
|
|
172
|
+
},
|
|
173
|
+
tool.definition.limits.maxDurationSeconds,
|
|
174
|
+
);
|
|
175
|
+
enforceSize(
|
|
176
|
+
result,
|
|
177
|
+
tool.definition.limits.maxOutputBytes,
|
|
166
178
|
"TOOL_OUTPUT_INVALID",
|
|
167
|
-
validationMessage(tool.validateOutput),
|
|
168
179
|
);
|
|
180
|
+
if (!tool.validateOutput(result)) {
|
|
181
|
+
throw new ToolExecutionError(
|
|
182
|
+
"TOOL_OUTPUT_INVALID",
|
|
183
|
+
validationMessage(tool.validateOutput),
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
} catch (error) {
|
|
187
|
+
if (tool.handler.executionMode === "sandbox") {
|
|
188
|
+
this.runtime.auditSink.recordEvent(
|
|
189
|
+
sandboxFailureEvent(context, tool.definition, input, error),
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
throw error;
|
|
169
193
|
}
|
|
170
194
|
this.runtime.auditSink.recordEvent(
|
|
171
|
-
toolEvent(
|
|
195
|
+
toolEvent(
|
|
196
|
+
context,
|
|
197
|
+
tool.definition,
|
|
198
|
+
input,
|
|
199
|
+
result,
|
|
200
|
+
tool.handler.executionMode ?? "host",
|
|
201
|
+
),
|
|
172
202
|
);
|
|
173
203
|
return result;
|
|
174
204
|
}
|
|
@@ -236,7 +266,7 @@ function validateHandlerContract(
|
|
|
236
266
|
async function executeWithTimeout(
|
|
237
267
|
tool: CompiledTool,
|
|
238
268
|
input: ModuleToolInput,
|
|
239
|
-
context:
|
|
269
|
+
context: PlatformToolExecutionContext,
|
|
240
270
|
seconds: number,
|
|
241
271
|
): Promise<ModuleToolResult> {
|
|
242
272
|
const controller = new AbortController();
|
|
@@ -250,8 +280,9 @@ async function executeWithTimeout(
|
|
|
250
280
|
try {
|
|
251
281
|
return await Promise.race([
|
|
252
282
|
tool.handler.execute(input, {
|
|
253
|
-
guardContext: context,
|
|
254
|
-
|
|
283
|
+
guardContext: context.guardContext,
|
|
284
|
+
toolCallId: context.toolCallId,
|
|
285
|
+
signal: AbortSignal.any([context.signal, controller.signal]),
|
|
255
286
|
}),
|
|
256
287
|
expired,
|
|
257
288
|
]);
|
|
@@ -269,7 +300,7 @@ function enforceSize(
|
|
|
269
300
|
maximum: number,
|
|
270
301
|
code: "TOOL_INPUT_INVALID" | "TOOL_OUTPUT_INVALID",
|
|
271
302
|
): void {
|
|
272
|
-
const bytes =
|
|
303
|
+
const bytes = toolJsonBytes(value);
|
|
273
304
|
if (bytes > maximum) {
|
|
274
305
|
throw new ToolExecutionError(code, `Agent Tool JSON 超过 ${maximum} 字节`);
|
|
275
306
|
}
|
|
@@ -282,33 +313,7 @@ function validationMessage(validate: ValidateFunction<unknown>): string {
|
|
|
282
313
|
return `Agent Tool JSON 不符合 Schema${detail ? `:${detail}` : ""}`;
|
|
283
314
|
}
|
|
284
315
|
|
|
285
|
-
function toolEvent(
|
|
286
|
-
context: RequestGuardContext,
|
|
287
|
-
tool: RegisteredTool,
|
|
288
|
-
input: ModuleToolInput,
|
|
289
|
-
result: ModuleToolResult,
|
|
290
|
-
): AuditEvent {
|
|
291
|
-
return {
|
|
292
|
-
id: crypto.randomUUID(),
|
|
293
|
-
action: tool.auditAction,
|
|
294
|
-
outcome: "success",
|
|
295
|
-
actor: auditActor(context),
|
|
296
|
-
target: { type: "agent-tool", id: tool.key, label: tool.label },
|
|
297
|
-
module: tool.module,
|
|
298
|
-
requestId: context.requestId,
|
|
299
|
-
metadata: {
|
|
300
|
-
inputBytes: jsonBytes(input),
|
|
301
|
-
outputBytes: jsonBytes(result),
|
|
302
|
-
},
|
|
303
|
-
occurredAt: new Date().toISOString(),
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
|
|
307
316
|
function required<T>(value: T | undefined, message: string): T {
|
|
308
317
|
if (value === undefined) throw new Error(message);
|
|
309
318
|
return value;
|
|
310
319
|
}
|
|
311
|
-
|
|
312
|
-
function jsonBytes(value: ModuleToolInput | ModuleToolResult): number {
|
|
313
|
-
return new TextEncoder().encode(JSON.stringify(value)).byteLength;
|
|
314
|
-
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import type { ModuleManifest } from "@southwind-ai/modules";
|
|
3
|
+
import { featureKey } from "@southwind-ai/shared";
|
|
4
|
+
import type { AiArtifactRuntime } from "../ai-artifact/runtime.js";
|
|
5
|
+
import { buildScopeContext } from "../data-access/context.js";
|
|
6
|
+
import { createRequestGuardContext } from "../guards.js";
|
|
7
|
+
import type { InitializedModuleHosts } from "../module-host.js";
|
|
8
|
+
import { createServerRuntime } from "../runtime.js";
|
|
9
|
+
import { createTestRunAuthorizationStore } from "./run-authorization.test-support.js";
|
|
10
|
+
import type {
|
|
11
|
+
AgentRuntimeOperation,
|
|
12
|
+
AgentRuntimePort,
|
|
13
|
+
} from "./run-contracts.js";
|
|
14
|
+
import { AgentRunFacade } from "./run-facade.js";
|
|
15
|
+
|
|
16
|
+
describe("Agent Vision facade", () => {
|
|
17
|
+
test("轮换 Artifact 并传递能力、模态和结构化输出 Schema", async () => {
|
|
18
|
+
const module = visionManifest();
|
|
19
|
+
const remote = new FakeRuntime();
|
|
20
|
+
const runtime = createServerRuntime(
|
|
21
|
+
{},
|
|
22
|
+
{
|
|
23
|
+
featureCatalog: module.features,
|
|
24
|
+
licenseResolver: { resolve: () => ({ status: "valid" }) },
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
const facade = new AgentRunFacade(
|
|
28
|
+
[module],
|
|
29
|
+
{
|
|
30
|
+
aiOperationHandlers: [
|
|
31
|
+
{
|
|
32
|
+
moduleName: "business",
|
|
33
|
+
registration: {
|
|
34
|
+
operationKey: "business.vision",
|
|
35
|
+
prepare() {
|
|
36
|
+
return {
|
|
37
|
+
instructions: "只提取图片可见内容。",
|
|
38
|
+
userPrompt: "提取字段。",
|
|
39
|
+
outputSchema: { type: "object" },
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
} as unknown as InitializedModuleHosts,
|
|
46
|
+
runtime,
|
|
47
|
+
remote,
|
|
48
|
+
createTestRunAuthorizationStore(),
|
|
49
|
+
artifactRuntime(),
|
|
50
|
+
);
|
|
51
|
+
await facade.start(
|
|
52
|
+
"business.vision",
|
|
53
|
+
{ question: "提取字段" },
|
|
54
|
+
"vision-1",
|
|
55
|
+
guardContext(),
|
|
56
|
+
[
|
|
57
|
+
{
|
|
58
|
+
value: "opaque-original",
|
|
59
|
+
mediaType: "image/png",
|
|
60
|
+
byteSize: 128,
|
|
61
|
+
sha256: "a".repeat(64),
|
|
62
|
+
expiresAt: "2030-01-01T00:00:00.000Z",
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
expect(remote.started[0]).toMatchObject({
|
|
68
|
+
kind: "agent",
|
|
69
|
+
operationKey: "business.vision",
|
|
70
|
+
inputModalities: ["text", "image"],
|
|
71
|
+
requiredCapabilities: ["text-generation", "vision"],
|
|
72
|
+
artifacts: [{ value: "opaque-rotated", mediaType: "image/png" }],
|
|
73
|
+
outputSchemaKey: "business.output.v1",
|
|
74
|
+
outputSchema: { type: "object" },
|
|
75
|
+
limits: {
|
|
76
|
+
maxArtifacts: 4,
|
|
77
|
+
maxPixelsPerArtifact: 20_000_000,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
class FakeRuntime implements AgentRuntimePort {
|
|
84
|
+
readonly started: AgentRuntimeOperation[] = [];
|
|
85
|
+
|
|
86
|
+
start(request: AgentRuntimeOperation) {
|
|
87
|
+
this.started.push(request);
|
|
88
|
+
return Promise.resolve({
|
|
89
|
+
runId: "run_vision",
|
|
90
|
+
status: "accepted" as const,
|
|
91
|
+
eventsUrl: "/internal/events",
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
status(runId: string) {
|
|
96
|
+
return Promise.resolve({
|
|
97
|
+
runId,
|
|
98
|
+
status: "running" as const,
|
|
99
|
+
lastSequence: 0,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
events() {
|
|
104
|
+
return Promise.resolve(new Response());
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
result() {
|
|
108
|
+
return Promise.resolve(new Response());
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
cancel() {
|
|
112
|
+
return Promise.resolve(new Response());
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
health() {
|
|
116
|
+
return Promise.resolve(new Response());
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function artifactRuntime() {
|
|
121
|
+
return {
|
|
122
|
+
rotate: async () => ({
|
|
123
|
+
value: "opaque-rotated",
|
|
124
|
+
mediaType: "image/png",
|
|
125
|
+
byteSize: 128,
|
|
126
|
+
sha256: "a".repeat(64),
|
|
127
|
+
expiresAt: "2030-01-01T00:00:00.000Z",
|
|
128
|
+
}),
|
|
129
|
+
} as unknown as AiArtifactRuntime;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function guardContext() {
|
|
133
|
+
return createRequestGuardContext(
|
|
134
|
+
new Request("http://localhost/api/agent/runs"),
|
|
135
|
+
{
|
|
136
|
+
resolveActor: () => ({
|
|
137
|
+
id: "actor-1",
|
|
138
|
+
type: "user",
|
|
139
|
+
name: "测试用户",
|
|
140
|
+
roleCodes: ["user"],
|
|
141
|
+
permissionKeys: ["business.ai.execute"],
|
|
142
|
+
scopeContext: buildScopeContext("actor-1", undefined, [
|
|
143
|
+
{
|
|
144
|
+
id: "role-user",
|
|
145
|
+
code: "user",
|
|
146
|
+
dataScope: "self",
|
|
147
|
+
departmentIds: [],
|
|
148
|
+
},
|
|
149
|
+
]),
|
|
150
|
+
}),
|
|
151
|
+
resolveLicense: () => ({ status: "valid" }),
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function visionManifest(): ModuleManifest {
|
|
157
|
+
return {
|
|
158
|
+
name: "business",
|
|
159
|
+
version: "0.1.0",
|
|
160
|
+
label: "业务",
|
|
161
|
+
description: "业务",
|
|
162
|
+
menus: [],
|
|
163
|
+
adminRoutes: [],
|
|
164
|
+
permissions: [
|
|
165
|
+
{
|
|
166
|
+
key: "business.ai.execute",
|
|
167
|
+
label: "视觉分析",
|
|
168
|
+
module: "business",
|
|
169
|
+
moduleLabel: "业务",
|
|
170
|
+
resource: "ai",
|
|
171
|
+
resourceLabel: "AI",
|
|
172
|
+
action: "manage",
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
apiPermissions: [],
|
|
176
|
+
features: [
|
|
177
|
+
{
|
|
178
|
+
key: featureKey("business.ai"),
|
|
179
|
+
label: "视觉分析",
|
|
180
|
+
module: "business",
|
|
181
|
+
visible: "visible",
|
|
182
|
+
enabled: true,
|
|
183
|
+
stage: "stable",
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
migrations: [],
|
|
187
|
+
schemaExports: [],
|
|
188
|
+
jsonSchemas: [
|
|
189
|
+
{ key: "business.input.v1", schema: { type: "object" } },
|
|
190
|
+
{ key: "business.output.v1", schema: { type: "object" } },
|
|
191
|
+
],
|
|
192
|
+
tasks: [],
|
|
193
|
+
tools: [],
|
|
194
|
+
aiOperations: [
|
|
195
|
+
{
|
|
196
|
+
key: "business.vision",
|
|
197
|
+
kind: "agent",
|
|
198
|
+
featureKey: "business.ai",
|
|
199
|
+
permissionKey: "business.ai.execute",
|
|
200
|
+
auditAction: "business.ai.execute",
|
|
201
|
+
inputSchemaKey: "business.input.v1",
|
|
202
|
+
outputSchemaKey: "business.output.v1",
|
|
203
|
+
inputModalities: ["text", "image"],
|
|
204
|
+
requiredCapabilities: ["text-generation", "vision"],
|
|
205
|
+
allowedToolKeys: [],
|
|
206
|
+
dataClassification: "sensitive",
|
|
207
|
+
execution: "streaming",
|
|
208
|
+
providerEgress: {
|
|
209
|
+
mode: "configured-endpoint",
|
|
210
|
+
deploymentKey: "ai.openai-compatible",
|
|
211
|
+
},
|
|
212
|
+
providerDataPolicy: {
|
|
213
|
+
inputFields: [
|
|
214
|
+
{
|
|
215
|
+
jsonPointer: "/question",
|
|
216
|
+
classification: "internal",
|
|
217
|
+
dlpAction: "redact",
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
envelopeFields: [
|
|
221
|
+
{
|
|
222
|
+
field: "instructions",
|
|
223
|
+
classification: "internal",
|
|
224
|
+
dlpAction: "reject",
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
field: "user-prompt",
|
|
228
|
+
classification: "internal",
|
|
229
|
+
dlpAction: "redact",
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
field: "artifact-content",
|
|
233
|
+
classification: "sensitive",
|
|
234
|
+
dlpAction: "reject",
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
field: "output-schema",
|
|
238
|
+
classification: "internal",
|
|
239
|
+
dlpAction: "reject",
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
},
|
|
243
|
+
toolNetworkPolicy: { mode: "forbidden" },
|
|
244
|
+
limits: {
|
|
245
|
+
maxDurationSeconds: 60,
|
|
246
|
+
maxInputBytes: 4096,
|
|
247
|
+
maxOutputBytes: 4096,
|
|
248
|
+
maxArtifacts: 4,
|
|
249
|
+
maxPixelsPerArtifact: 20_000_000,
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
providers: [],
|
|
254
|
+
auditActions: ["business.ai.execute"],
|
|
255
|
+
};
|
|
256
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { ModuleAiOperationDefinition } from "@southwind-ai/modules";
|
|
2
|
+
import type {
|
|
3
|
+
ModuleAiArtifactRef,
|
|
4
|
+
ModuleAiJsonValue,
|
|
5
|
+
} from "@southwind-ai/server-sdk";
|
|
6
|
+
import type { AiArtifactRuntime } from "../ai-artifact/runtime.js";
|
|
7
|
+
import type { RequestGuardContext } from "../guards.js";
|
|
8
|
+
import { AgentRunFacadeError } from "./run-errors.js";
|
|
9
|
+
|
|
10
|
+
export async function rotateVisionArtifacts(
|
|
11
|
+
artifacts: readonly ModuleAiArtifactRef[],
|
|
12
|
+
definition: ModuleAiOperationDefinition,
|
|
13
|
+
moduleName: string,
|
|
14
|
+
runtime: AiArtifactRuntime | undefined,
|
|
15
|
+
context: RequestGuardContext,
|
|
16
|
+
signal: AbortSignal,
|
|
17
|
+
) {
|
|
18
|
+
validateVisionArtifacts(artifacts, definition);
|
|
19
|
+
return Promise.all(
|
|
20
|
+
artifacts.map(async (artifact) => {
|
|
21
|
+
const rotated = await runtime?.rotate(
|
|
22
|
+
artifact.value,
|
|
23
|
+
context.actor.id,
|
|
24
|
+
moduleName,
|
|
25
|
+
Math.min(definition.limits.maxDurationSeconds + 60, 3_600),
|
|
26
|
+
signal,
|
|
27
|
+
);
|
|
28
|
+
if (!rotated) {
|
|
29
|
+
throw new AgentRunFacadeError(
|
|
30
|
+
"RUNTIME_UNAVAILABLE",
|
|
31
|
+
"AI Artifact Runtime 未配置",
|
|
32
|
+
503,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
if (
|
|
36
|
+
artifact.mediaType !== rotated.mediaType ||
|
|
37
|
+
artifact.byteSize !== rotated.byteSize ||
|
|
38
|
+
artifact.sha256 !== rotated.sha256
|
|
39
|
+
) {
|
|
40
|
+
throw new AgentRunFacadeError(
|
|
41
|
+
"FORBIDDEN",
|
|
42
|
+
"Agent Artifact 元数据不一致",
|
|
43
|
+
403,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
value: rotated.value,
|
|
48
|
+
mediaType: rotated.mediaType,
|
|
49
|
+
byteSize: rotated.byteSize,
|
|
50
|
+
sha256: rotated.sha256,
|
|
51
|
+
};
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function validateOutputSchema(
|
|
57
|
+
schema: ModuleAiJsonValue | undefined,
|
|
58
|
+
definition: ModuleAiOperationDefinition,
|
|
59
|
+
) {
|
|
60
|
+
if (schema === undefined) return;
|
|
61
|
+
if (
|
|
62
|
+
!schema ||
|
|
63
|
+
typeof schema !== "object" ||
|
|
64
|
+
Array.isArray(schema) ||
|
|
65
|
+
new TextEncoder().encode(JSON.stringify(schema)).byteLength > 256 * 1024
|
|
66
|
+
) {
|
|
67
|
+
throw new AgentRunFacadeError(
|
|
68
|
+
"INVALID_INPUT",
|
|
69
|
+
"Agent 结构化输出 Schema 无效",
|
|
70
|
+
400,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
if (
|
|
74
|
+
definition.providerEgress?.mode === "configured-endpoint" &&
|
|
75
|
+
!definition.providerDataPolicy?.envelopeFields.some(
|
|
76
|
+
({ field }) => field === "output-schema",
|
|
77
|
+
)
|
|
78
|
+
) {
|
|
79
|
+
throw new AgentRunFacadeError(
|
|
80
|
+
"FORBIDDEN",
|
|
81
|
+
"Provider 未获授权接收输出 Schema",
|
|
82
|
+
403,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function validateVisionArtifacts(
|
|
88
|
+
artifacts: readonly ModuleAiArtifactRef[],
|
|
89
|
+
definition: ModuleAiOperationDefinition,
|
|
90
|
+
) {
|
|
91
|
+
if (!artifacts.length) return;
|
|
92
|
+
if (!definition.inputModalities?.includes("image")) {
|
|
93
|
+
throw invalid("该 Agent Operation 未声明图片输入");
|
|
94
|
+
}
|
|
95
|
+
if (
|
|
96
|
+
!definition.limits.maxArtifacts ||
|
|
97
|
+
artifacts.length > definition.limits.maxArtifacts
|
|
98
|
+
) {
|
|
99
|
+
throw invalid("Agent Artifact 数量超过上限");
|
|
100
|
+
}
|
|
101
|
+
const total = artifacts.reduce((sum, artifact) => sum + artifact.byteSize, 0);
|
|
102
|
+
if (total > definition.limits.maxInputBytes) {
|
|
103
|
+
throw invalid("Agent Artifact 总大小超过上限");
|
|
104
|
+
}
|
|
105
|
+
if (
|
|
106
|
+
artifacts.some(
|
|
107
|
+
({ mediaType, byteSize }) =>
|
|
108
|
+
byteSize < 1 ||
|
|
109
|
+
!["image/jpeg", "image/png", "image/webp"].includes(
|
|
110
|
+
mediaType.toLowerCase(),
|
|
111
|
+
),
|
|
112
|
+
)
|
|
113
|
+
) {
|
|
114
|
+
throw invalid("Agent Vision 仅接受 JPEG、PNG 或 WebP");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function invalid(message: string) {
|
|
119
|
+
return new AgentRunFacadeError("INVALID_INPUT", message, 400);
|
|
120
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { AiArtifactCodec, AiArtifactCodecError } from "./codec.js";
|
|
3
|
+
|
|
4
|
+
const claims = {
|
|
5
|
+
version: 1 as const,
|
|
6
|
+
moduleName: "evidence",
|
|
7
|
+
actorId: "user-1",
|
|
8
|
+
source: {
|
|
9
|
+
fileId: "file-secret-1",
|
|
10
|
+
purpose: "evidence.transcript-source",
|
|
11
|
+
resourceType: "evidence.transcript",
|
|
12
|
+
resourceId: "transcript-secret-1",
|
|
13
|
+
},
|
|
14
|
+
mediaType: "application/pdf",
|
|
15
|
+
byteSize: 128,
|
|
16
|
+
sha256: "a".repeat(64),
|
|
17
|
+
issuedAt: "2026-07-27T00:00:00.000Z",
|
|
18
|
+
expiresAt: "2026-07-27T00:05:00.000Z",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
describe("AI Artifact Codec", () => {
|
|
22
|
+
test("签发不透明引用且可以完整恢复受保护声明", () => {
|
|
23
|
+
const codec = new AiArtifactCodec("artifact-secret-at-least-32-characters");
|
|
24
|
+
const token = codec.encode(claims);
|
|
25
|
+
|
|
26
|
+
expect(token).toStartWith("v1.");
|
|
27
|
+
expect(token).not.toContain(claims.source.fileId);
|
|
28
|
+
expect(token).not.toContain(claims.source.resourceId);
|
|
29
|
+
expect(codec.decode(token)).toEqual(claims);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("拒绝被篡改或使用其他 Secret 的引用", () => {
|
|
33
|
+
const codec = new AiArtifactCodec("artifact-secret-at-least-32-characters");
|
|
34
|
+
const token = codec.encode(claims);
|
|
35
|
+
const tampered = `${token.slice(0, -1)}${token.endsWith("a") ? "b" : "a"}`;
|
|
36
|
+
|
|
37
|
+
expect(() => codec.decode(tampered)).toThrow(AiArtifactCodecError);
|
|
38
|
+
expect(() =>
|
|
39
|
+
new AiArtifactCodec(
|
|
40
|
+
"different-artifact-secret-at-least-32-characters",
|
|
41
|
+
).decode(token),
|
|
42
|
+
).toThrow(AiArtifactCodecError);
|
|
43
|
+
});
|
|
44
|
+
});
|